Astro/Catalog/IO/FITSTable.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 94.4% 34 / 36 CC 1 SCAR 0.3
CC
1
Cov
93%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Tk/AstroCatalog.pm ↑ Summary Astro/Catalog/IO/LCOGTFITSTable.pm »
1 package Astro::Catalog::IO::FITSTable;
2  
3 =head1 NAME
4  
5 Astro::Catalog::IO::FITSTable - Binary FITS table I/O for Astro::Catalog
6  
7 =head1 SYNOPSIS
8  
9 $cat = Astro::Catalog::IO::FITSTable->_read_catalog($whatever);
10  
11 =cut
12  
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Astro::Catalog::Item::Morphology;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Astro::Coords;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 ▶use Astro::FITS::CFITSIO qw/:longnames :constants/;
Subroutine BEGIN: called CC=1 SCAR=2.6
23 use File::Temp qw/tempfile/;
24  
25 use Astro::Flux;
26 use Astro::FluxColor;
27 use Astro::Fluxes;
28  
29 use DateTime;
30 use DateTime::Format::ISO8601;
31  
32 use base qw/Astro::Catalog::IO::Binary/;
33  
34 our $VERSION = '4.38';
35 our $DEBUG = 0;
36  
37 =begin __PUBLIC_METHODS__
38  
39 =head1 PUBLIC METHODS
40  
41 These methods are usually called automatically from the C<Astro::Catalog>
42 constructor, but are available for public use.
43  
44 =over 4
45  
46 =item B<input_format>
47  
48 Returns the requested input format for the FITSTable class, which is
49 'name', meaning the name of the file to be turned into an C<Astro::Catalog>
50 object.
51  
52 $input_format = Astro::Catalog::IO::FITSTable->input_format;
53  
54 =cut
55  
56 sub input_format {
57 return "name";
58 }
59  
60 =back
61  
62 =begin __PRIVATE_METHODS__
63  
64 =head1 PRIVATE METHODS
65  
66 These methods are usually called automatically from the C<Astro::Catalog>
67 constructor.
68  
69 =item B<_read_catalog>
70  
71 Parses the binary FITS table and returns a new C<Astro::Catalog> object
72 containing the catalog entries.
73  
74 $cat = Astro::Catalog::IO::FITSTable->_read_catalog($whatever);
75  
76 The current translations from FITS table column names to
77 C<Astro::Catalog::Item> properties are:
78  
79 =over 4
80  
81 =item No. - ID
82  
83 =item X_coordinate - X
84  
85 =item Y_coordinate - Y
86  
87 =item RA & DEC - Coords
88  
89 =item Isophotal_flux, Total_flux, Core_flux, Core1_flux, Core2_flux,
90 Core3_flux, Core4_flux, Core5_flux - C<Astro::Flux> objects pushed into
91 the C<Astro::Catalog::Item> fluxes accessor.
92  
93 =item Ellipticity & Position_angle - Morphology
94  
95 =back
96  
97 RA and Dec are assumed to be in J2000 coordinates, and are in units
98 of radians. The isophotal flux is assumed to be in units of counts,
99 and is converted into a magnitude through the formula -2.5 * log10(flux).
100 The position angle is assumed to be the angle measured counter-
101 clockwise from the positive x axis, in degrees.
102  
103 An attempt to read in the DATE-OBS header is made so that flux measurements
104 can be timestamped. If the DATE-OBS header does not exist, then the current
105 date and time will be used for the flux timestamps.
106  
107 =cut
108  
109 sub _read_catalog {
110 my $class = shift;
111 my %args = @_;
112  
113 unless (defined $args{'filename'}) {
114 croak "Must supply a filename to read";
115 }
116 my $filename = $args{'filename'};
117  
118 my $obsid;
119 if (defined $args{'obsid'}) {
120 $obsid = $args{'obsid'};
121 }
122 else {
123 $obsid = [];
124 }
125  
126 # A lookup table for column name mappings.
127 my %column_name = (
128 'ID' => 'No.',
129 'X' => 'X_coordinate',
130 'Y' => 'Y_coordinate',
131 'RA' => 'RA',
132 'Dec' => 'DEC',
133 'isophotal_flux' => 'Isophotal_flux',
134 'total_flux' => 'Total_flux',
135 'core_flux' => 'Core_flux',
136 'core1_flux' => 'Core1_flux',
137 'core2_flux' => 'Core2_flux',
138 'core3_flux' => 'Core3_flux',
139 'core4_flux' => 'Core4_flux',
140 'core5_flux' => 'Core5_flux',
141 'ellipticity' => 'Ellipticity',
142 'position_angle' => 'Position_angle',
143 );
144  
145 # The new Astro::Catalog object.
146 my $catalog = new Astro::Catalog;
147  
148 # CFITSIO status variable.
149 my $status = 0;
150  
151 # Open the file using CFITSIO.
152 my $fptr = Astro::FITS::CFITSIO::open_file($filename,
153 Astro::FITS::CFITSIO::READONLY(),
154 $status);
155 if ($status != 0) {
156 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
157 croak "Error opening FITS file: $status $text";
158 }
159  
160 # Get the number of HDUs in the FITS file.
161 $fptr->get_num_hdus(my $num_hdus, $status);
162 if ($status != 0) {
163 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
164 croak "Error retrieving number of HDUs from FITS file: $status $text";
165 }
166  
167 $fptr->get_hdu_num(my $hdu_pos);
168  
169 while ($hdu_pos <= $num_hdus) {
170 # Get the type of HDU for the one we're at.
171 $fptr->get_hdu_type(my $hdutype, $status);
172 if ($status != 0) {
173 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
174 croak "Error retrieving HDU type from FITS file: $status $text";
175 }
176  
177 if ($hdutype == BINARY_TBL) {
178 # Try to retrieve the DATE-OBS header. This will be used
179 # to give each flux measurement a datetime stamp. If DATE-OBS
180 # cannot be determined, then set the datetime to the current
181 # time.
182 my $datetime;
183 $fptr->read_keyword('DATE-OBS', my $dateobs, my $comment, $status);
184 if ($status != 0) {
185 if ($status == KEY_NO_EXIST) {
186 # We can deal with this, just take the current time and set
187 # the status back to 0 (good).
188 $datetime = DateTime->now;
189 $status = 0;
190 }
191 else {
192 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
193 croak "Error retrieving DATE-OBS header from FITS file: $status $text";
194 }
195 }
196 else {
197 # Strip out any characters that aren't meant to be there.
198 # read_keyword() puts single quotes around strings, so we need
199 # to get rid of those, along with any trailing Zs.
200 $dateobs =~ s/['Z]//g;
201 $datetime = DateTime::Format::ISO8601->parse_datetime($dateobs);
202 }
203  
204 my $waveband;
205 $fptr->read_keyword('FILTER', my $filter, my $filtercomment, $status);
206 if ($status != 0) {
207 if ($status == KEY_NO_EXIST) {
208 # We can deal with this, just set the filter to be 'unknown'.
209 $filter = 'unknown';
210 $status = 0;
211 }
212 else {
213 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
214 croak "Error retrieving FILTER header from FITS file: $status $text";
215 }
216 }
217 else {
218 # Strip out any characters that aren't meant to be there.
219 $filter =~ s/'//g;
220 $filter =~ s/^\s+//;
221 $filter =~ s/\s+$//;
222 }
223 $waveband = new Astro::WaveBand(Filter => $filter);
224  
225 # Get the number of rows in this table.
226 $fptr->get_num_rows(my $nrows, $status);
227 if ($status != 0) {
228 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
229 croak "Error retrieving number of rows from HDU $hdu_pos from FITS file: $status $text";
230 }
231  
232 # Grab all the information we can from this HDU.
233 # First, get the column numbers for the ID, RA, Dec, flux,
234 # ellipticity, position angle, and x and y position.
235 $fptr->get_colnum(CASEINSEN, $column_name{'ID'}, my $id_column, $status);
236 if ($status == COL_NOT_FOUND) {
237 $status = 0;
238 $id_column = -1;
239 }
240 elsif ($status != 0) {
241 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
242 croak "Error in finding ID column: $status $text";
243 }
244 if ($id_column == 0) {
245 $id_column = -1;
246 }
247 print "ID column: $id_column\n" if $DEBUG;
248  
249 $fptr->get_colnum(CASEINSEN, $column_name{'RA'}, my $ra_column, $status);
250 if ($status == COL_NOT_FOUND) {
251 $status = 0;
252 $ra_column = -1;
253 }
254 elsif ($status != 0) {
255 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
256 croak "Error in finding RA column: $status $text";
257 }
258 if ($ra_column == 0) {
259 $ra_column = -1;
260 }
261 print "RA column: $ra_column\n" if $DEBUG;
262  
263 $fptr->get_colnum(CASEINSEN, $column_name{'Dec'}, my $dec_column, $status);
264 if ($status == COL_NOT_FOUND) {
265 $status = 0;
266 $dec_column = -1;
267 }
268 elsif ($status != 0) {
269 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
270 croak "Error in finding Dec column: $status $text";
271 }
272 if ($dec_column == 0) {
273 $dec_column = -1;
274 }
275 print "Dec column: $dec_column\n" if $DEBUG;
276  
277 $fptr->get_colnum(CASEINSEN, $column_name{'isophotal_flux'}, my $iso_flux_column, $status);
278 if ($status == COL_NOT_FOUND) {
279 $status = 0;
280 $iso_flux_column = -1;
281 }
282 elsif ($status != 0) {
283 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
284 croak "Error in finding isophotal flux column: $status $text";
285 }
286 if ($iso_flux_column == 0) {
287 $iso_flux_column = -1;
288 }
289 print "Isophotal flux column: $iso_flux_column\n" if $DEBUG;
290  
291 $fptr->get_colnum(CASEINSEN, $column_name{'total_flux'}, my $total_flux_column, $status);
292 if ($status == COL_NOT_FOUND) {
293 $status = 0;
294 $total_flux_column = -1;
295 }
296 elsif ($status != 0 ) {
297 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
298 croak "Error in finding total flux column: $status $text";
299 }
300 if ($total_flux_column == 0) {
301 $total_flux_column = -1;
302 }
303 print "Total flux column: $total_flux_column\n" if $DEBUG;
304  
305 $fptr->get_colnum(CASEINSEN, $column_name{'core_flux'}, my $core_flux_column, $status);
306 if ($status == COL_NOT_FOUND) {
307 $status = 0;
308 $core_flux_column = -1;
309 }
310 elsif ($status != 0) {
311 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
312 croak "Error in finding core flux column: $status $text";
313 }
314 if ($core_flux_column == 0) {
315 $core_flux_column = -1;
316 }
317 print "Core flux column: $core_flux_column\n" if $DEBUG;
318  
319 $fptr->get_colnum(CASEINSEN, $column_name{'core1_flux'}, my $core1_flux_column, $status);
320 if ($status == COL_NOT_FOUND) {
321 $status = 0;
322 $core1_flux_column = -1;
323 }
324 elsif ($status != 0) {
325 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
326 croak "Error in finding core1 flux column: $status $text";
327 }
328 if ($core1_flux_column == 0) {
329 $core1_flux_column = -1;
330 }
331 print "Core1 flux column: $core1_flux_column\n" if $DEBUG;
332  
333 $fptr->get_colnum(CASEINSEN, $column_name{'core2_flux'}, my $core2_flux_column, $status);
334 if ($status == COL_NOT_FOUND) {
335 $status = 0;
336 $core2_flux_column = -1;
337 }
338 elsif ($status != 0) {
339 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
340 croak "Error in finding core2 flux column: $status $text";
341 }
342 if ($core2_flux_column == 0) {
343 $core2_flux_column = -1;
344 }
345 print "Core2 flux column: $core2_flux_column\n" if $DEBUG;
346  
347 $fptr->get_colnum(CASEINSEN, $column_name{'core3_flux'}, my $core3_flux_column, $status);
348 if ($status == COL_NOT_FOUND) {
349 $status = 0;
350 $core3_flux_column = -1;
351 }
352 elsif ($status != 0) {
353 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
354 croak "Error in finding core3 flux column: $status $text";
355 }
356 if ($core3_flux_column == 0) {
357 $core3_flux_column = -1;
358 }
359 print "Core3 flux column: $core3_flux_column\n" if $DEBUG;
360  
361 $fptr->get_colnum(CASEINSEN, $column_name{'core4_flux'}, my $core4_flux_column, $status);
362 if ($status == COL_NOT_FOUND) {
363 $status = 0;
364 $core4_flux_column = -1;
365 }
366 elsif ($status != 0) {
367 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
368 croak "Error in finding core4 flux column: $status $text";
369 }
370 if ($core4_flux_column == 0) {
371 $core4_flux_column = -1;
372 }
373 print "Core4 flux column: $core4_flux_column\n" if $DEBUG;
374  
375 $fptr->get_colnum(CASEINSEN, $column_name{'core5_flux'}, my $core5_flux_column, $status);
376 if ($status == COL_NOT_FOUND) {
377 $status = 0;
378 $core5_flux_column = -1;
379 }
380 elsif ($status != 0) {
381 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
382 croak "Error in finding core5 flux column: $status $text";
383 }
384 if ($core5_flux_column == 0) {
385 $core5_flux_column = -1;
386 }
387 print "Core5 flux column: $core5_flux_column\n" if $DEBUG;
388  
389 $fptr->get_colnum(CASEINSEN, $column_name{'ellipticity'}, my $ell_column, $status);
390 if ($status == COL_NOT_FOUND) {
391 $status = 0;
392 $id_column = -1;
393 }
394 elsif ($status != 0) {
395 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
396 croak "Error in finding ellipticity column: $status $text";
397 }
398 if ($ell_column == 0) {
399 $ell_column = -1;
400 }
401 print "Ellipticity column: $ell_column\n" if $DEBUG;
402  
403 $fptr->get_colnum(CASEINSEN, $column_name{'position_angle'}, my $posang_column, $status);
404 if ($status == COL_NOT_FOUND) {
405 $status = 0;
406 $id_column = -1;
407 }
408 elsif ($status != 0) {
409 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
410 croak "Error in finding position angle column: $status $text";
411 }
412 if ($posang_column == 0) {
413 $posang_column = -1;
414 }
415 print "Position angle column: $posang_column\n" if $DEBUG;
416  
417 $fptr->get_colnum(CASEINSEN, $column_name{'X'}, my $x_column, $status);
418 if ($status == COL_NOT_FOUND) {
419 $status = 0;
420 $id_column = -1;
421 }
422 elsif ($status != 0) {
423 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
424 croak "Error in finding x-coordinate column: $status $text";
425 }
426 if ($x_column == 0) {
427 $x_column = -1;
428 }
429 print "X-coordinate column: $x_column\n" if $DEBUG;
430  
431 $fptr->get_colnum(CASEINSEN, $column_name{'Y'}, my $y_column, $status);
432 if ($status == COL_NOT_FOUND) {
433 $status = 0;
434 $id_column = -1;
435 }
436 elsif ($status != 0) {
437 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
438 croak "Error in finding y-coordinate column: $status $text";
439 }
440 if ($y_column == 0) {
441 $y_column = -1;
442 }
443 print "Y-coordinate column: $y_column\n" if $DEBUG;
444  
445 # Now that we've got all the columns defined, we need to grab each column
446 # in one big array, then take those arrays and stuff the information into
447 # Astro::Catalog::Item objects
448 my $id;
449 my $ra;
450 my $dec;
451 my ($iso_flux, $total_flux, $core_flux, $core1_flux, $core2_flux, $core3_flux);
452 my ($core4_flux, $core5_flux);
453 my $ell;
454 my $posang;
455 my $x_pos;
456 my $y_pos;
457 if ($id_column != -1) {
458 $fptr->read_col(TFLOAT, $id_column, 1, 1, $nrows, undef, $id, undef, $status);
459 if ($status != 0) {
460 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
461 croak "Error in retrieving data for ID column: $status $text";
462 }
463 }
464 if ($ra_column != -1) {
465 $fptr->read_col(TFLOAT, $ra_column, 1, 1, $nrows, undef, $ra, undef, $status);
466 if ($status != 0) {
467 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
468 croak "Error in retrieving data for RA column: $status $text";
469 }
470 }
471 if ($dec_column != -1) {
472 $fptr->read_col(TFLOAT, $dec_column, 1, 1, $nrows, undef, $dec, undef, $status);
473 if ($status != 0) {
474 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
475 croak "Error in retrieving data for Dec column: $status $text";
476 }
477 }
478 if ($iso_flux_column != -1) {
479 $fptr->read_col(TFLOAT, $iso_flux_column, 1, 1, $nrows, undef, $iso_flux, undef, $status);
480 if ($status != 0) {
481 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
482 croak "Error in retrieving data for isophotal flux column: $status $text";
483 }
484 }
485 if ($total_flux_column != -1) {
486 $fptr->read_col(TFLOAT, $total_flux_column, 1, 1, $nrows, undef, $total_flux, undef, $status);
487 if ($status != 0) {
488 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
489 croak "Error in retrieving data for tottal flux column: $status $text";
490 }
491 }
492 if ($core_flux_column != -1) {
493 $fptr->read_col(TFLOAT, $core_flux_column, 1, 1, $nrows, undef, $core_flux, undef, $status);
494 if ($status != 0) {
495 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
496 croak "Error in retrieving data for core flux column: $status $text";
497 }
498 }
499 if ($core1_flux_column != -1) {
500 $fptr->read_col(TFLOAT, $core1_flux_column, 1, 1, $nrows, undef, $core1_flux, undef, $status);
501 if ($status != 0) {
502 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
503 croak "Error in retrieving data for core1 flux column: $status $text";
504 }
505 }
506 if ($core2_flux_column != -1) {
507 $fptr->read_col(TFLOAT, $core2_flux_column, 1, 1, $nrows, undef, $core2_flux, undef, $status);
508 if ($status != 0) {
509 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
510 croak "Error in retrieving data for core2 flux column: $status $text";
511 }
512 }
513 if ($core3_flux_column != -1) {
514 $fptr->read_col(TFLOAT, $core3_flux_column, 1, 1, $nrows, undef, $core3_flux, undef, $status);
515 if ($status != 0) {
516 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
517 croak "Error in retrieving data for core3 flux column: $status $text";
518 }
519 }
520 if ($core4_flux_column != -1) {
521 $fptr->read_col(TFLOAT, $core4_flux_column, 1, 1, $nrows, undef, $core4_flux, undef, $status);
522 if ($status != 0) {
523 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
524 croak "Error in retrieving data for core4 flux column: $status $text";
525 }
526 }
527 if ($core5_flux_column != -1) {
528 $fptr->read_col(TFLOAT, $core5_flux_column, 1, 1, $nrows, undef, $core5_flux, undef, $status);
529 if ($status != 0) {
530 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
531 croak "Error in retrieving data for core5 flux column: $status $text";
532 }
533 }
534 if ($ell_column != -1) {
535 $fptr->read_col(TFLOAT, $ell_column, 1, 1, $nrows, undef, $ell, undef, $status);
536 if ($status != 0) {
537 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
538 croak "Error in retrieving data for ellipticity column: $status $text";
539 }
540 }
541 if ($posang_column != -1) {
542 $fptr->read_col(TFLOAT, $posang_column, 1, 1, $nrows, undef, $posang, undef, $status);
543 if ($status != 0) {
544 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
545 croak "Error in retrieving data for position angle column: $status $text";
546 }
547 }
548 if ($x_column != -1) {
549 $fptr->read_col(TFLOAT, $x_column, 1, 1, $nrows, undef, $x_pos, undef, $status);
550 if ($status != 0) {
551 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
552 croak "Error in retrieving data for x-coordinate column: $status $text";
553 }
554 }
555 if ($y_column != -1) {
556 $fptr->read_col(TFLOAT, $y_column, 1, 1, $nrows, undef, $y_pos, undef, $status);
557 if ($status != 0) {
558 Astro::FITS::CFITSIO::fits_get_errstatus($status, my $text);
559 croak "Error in retrieving data for y-coordinate column: $status $text";
560 }
561 }
562  
563 # Go through each array, grabbing the information and creating a
564 # new Astro::Catalog::Item object each time through.
565 for (my $i = 0; $i < $nrows; $i ++) {
566 my $id_value;
567 if (defined $id) {
568 $id_value = $id->[$i];
569 }
570 my $ra_value;
571 if (defined $ra) {
572 $ra_value = $ra->[$i];
573 }
574 my $dec_value;
575 if (defined $dec) {
576 $dec_value = $dec->[$i];
577 }
578 my $iso_flux_value;
579 if (defined $iso_flux) {
580 $iso_flux_value = $iso_flux->[$i];
581 }
582 my $total_flux_value;
583 if (defined $total_flux) {
584 $total_flux_value = $total_flux->[$i];
585 }
586 my $core_flux_value;
587 if (defined $core_flux) {
588 $core_flux_value = $core_flux->[$i];
589 }
590 my $core1_flux_value;
591 if (defined $core1_flux) {
592 $core1_flux_value = $core1_flux->[$i];
593 }
594 my $core2_flux_value;
595 if (defined $core2_flux) {
596 $core2_flux_value = $core2_flux->[$i];
597 }
598 my $core3_flux_value;
599 if (defined $core3_flux) {
600 $core3_flux_value = $core3_flux->[$i];
601 }
602 my $core4_flux_value;
603 if (defined $core4_flux) {
604 $core4_flux_value = $core4_flux->[$i];
605 }
606 my $core5_flux_value;
607 if (defined $core5_flux) {
608 $core5_flux_value = $core5_flux->[$i];
609 }
610 my $ell_value;
611 if (defined $ell) {
612 $ell_value = $ell->[$i];
613 }
614 my $posang_value;
615 if (defined $posang) {
616 $posang_value = $posang->[$i];
617 }
618 my $x_pos_value;
619 if (defined $x_pos) {
620 $x_pos_value = $x_pos->[$i];
621 }
622 my $y_pos_value;
623 if (defined $y_pos) {
624 $y_pos_value = $y_pos->[$i];
625 }
626  
627 # Set up the Astro::Coords object, assuming our RA and Dec are in units
628 # of radians.
629 my $coords;
630 if (defined($ra_value) && defined($dec_value)) {
631 $coords = new Astro::Coords(
632 ra => $ra_value,
633 dec => $dec_value,
634 units => 'radians',
635 type => 'J2000',
636 );
637 }
638  
639 # Set up the Astro::Flux objects.
640 my $iso_flux_obj = new Astro::Flux(
641 $iso_flux_value, 'isophotal_flux', $waveband, datetime => $datetime, obsid => $obsid);
642 my $total_flux_obj = new Astro::Flux(
643 $total_flux_value, 'total_flux', $waveband, datetime => $datetime, obsid => $obsid);
644 my $core_flux_obj = new Astro::Flux(
645 $core_flux_value, 'core_flux', $waveband, datetime => $datetime, obsid => $obsid);
646 my $core1_flux_obj = new Astro::Flux(
647 $core1_flux_value, 'core1_flux', $waveband, datetime => $datetime, obsid => $obsid);
648 my $core2_flux_obj = new Astro::Flux(
649 $core2_flux_value, 'core2_flux', $waveband, datetime => $datetime, obsid => $obsid);
650 my $core3_flux_obj = new Astro::Flux(
651 $core3_flux_value, 'core3_flux', $waveband, datetime => $datetime, obsid => $obsid);
652 my $core4_flux_obj = new Astro::Flux(
653 $core4_flux_value, 'core4_flux', $waveband, datetime => $datetime, obsid => $obsid);
654 my $core5_flux_obj = new Astro::Flux(
655 $core5_flux_value, 'core5_flux', $waveband, datetime => $datetime, obsid => $obsid);
656  
657 # And set up the Astro::Catalog::Item::Morphology object.
658 my $morphology = new Astro::Catalog::Item::Morphology(
659 ellipticity => $ell_value,
660 position_angle_pixel => $posang_value,
661 );
662  
663 # And create the Astro::Catalog::Item object from this conglomoration of data.
664 my $star = new Astro::Catalog::Item(ID => $id_value,
665 Fluxes => new Astro::Fluxes($iso_flux_obj,
666 $total_flux_obj,
667 $core_flux_obj,
668 $core1_flux_obj,
669 $core2_flux_obj,
670 $core3_flux_obj,
671 $core4_flux_obj,
672 $core5_flux_obj),
673 Coords => $coords,
674 X => $x_pos_value,
675 Y => $y_pos_value,
676 Morphology => $morphology);
677  
678 # Push it onto the Astro::Catalog object.
679 $catalog->pushstar($star);
680 }
681  
682 }
683 $status = 0;
684  
685 # Move to the next one.
686 $fptr->movrel_hdu(1, $hdutype, $status);
687 last if $status == END_OF_FILE;
688  
689 # And set $hdu_pos.
690 $fptr->get_hdu_num($hdu_pos);
691 }
692  
693 # Set the origin.
694 $catalog->origin('IO::FITSTable');
695  
696 # And return.
697 return $catalog;
698 }
699  
700 =item B<_write_catalog>
701  
702 Create an output catalog as a binary FITS table.
703  
704 $ref = Astro::Catalog::IO::FITSTable->_write_catalog($catalog);
705  
706 Argument is an C<Astro::Catalog> object.
707  
708 This method is not yet implemented.
709  
710 =cut
711  
712 sub _write_catalog {
713 croak "Not yet implemented.";
714 }
715  
716 1;
717  
718 __END__
« Tk/AstroCatalog.pm ↑ Summary Astro/Catalog/IO/LCOGTFITSTable.pm »