Changeset 24694 for trunk/psModules/src/objects/pmSourceIO_MatchedRefs.c
- Timestamp:
- Jul 7, 2009, 10:31:49 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceIO_MatchedRefs.c
r24489 r24694 43 43 #include "pmAstrometryWCS.h" 44 44 45 bool pmSource WriteMatchedRefs (psFits *fits, pmFPA *fpa, pmConfig *config) {45 bool pmSourceIO_WriteMatchedRefs (psFits *fits, pmFPA *fpa, pmConfig *config) { 46 46 47 47 bool status = true; … … 63 63 if (!REFS_OUTPUT) return true; 64 64 65 psArray *table = ps ArrayAllocEmpty (0x1000);66 p mFPAview *view = pmFPAviewAlloc (0);65 psArray *table = psMetadataLookupPtr (&status, fpa->analysis, "MATCHED_REFS"); 66 psMemIncrRefCounter (table); 67 67 68 // this loop selects the matched stars for all chips 69 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 70 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 71 if (!chip->process || !chip->file_exists) continue; 68 if (!table) { 69 table = psArrayAllocEmpty (0x1000); 70 pmFPAview *view = pmFPAviewAlloc (0); 72 71 73 char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 72 // this loop selects the matched stars for all chips 73 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 74 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 75 if (!chip->process || !chip->file_exists) continue; 74 76 75 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 76 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 77 if (!cell->process || !cell->file_exists) continue; 77 char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 78 78 79 // process each of the readouts 80 // XXX there can only be one readout per chip, right? 81 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 82 if (! readout->data_exists) continue; 79 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 80 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 81 if (!cell->process || !cell->file_exists) continue; 83 82 84 // select the raw objects for this readout 85 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS"); 86 if (rawstars == NULL) continue; 83 // process each of the readouts 84 // XXX there can only be one readout per chip, right? 85 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 86 if (! readout->data_exists) continue; 87 87 88 // select the raw objects for this readout 89 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS"); 90 if (refstars == NULL) continue; 91 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n); 88 // select the raw objects for this readout 89 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS"); 90 if (rawstars == NULL) continue; 92 91 93 psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH"); 94 if (matches == NULL) continue; 92 // select the raw objects for this readout 93 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS"); 94 if (refstars == NULL) continue; 95 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n); 95 96 96 for (int i = 0; i < matches->n; i++) { 97 pmAstromMatch *match = matches->data[i];97 psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH"); 98 if (matches == NULL) continue; 98 99 99 pmAstromObj *raw = rawstars->data[match->raw]; 100 pmAstromObj *ref = refstars->data[match->ref];100 for (int i = 0; i < matches->n; i++) { 101 pmAstromMatch *match = matches->data[i]; 101 102 102 psMetadata *row = psMetadataAlloc (); 103 psMetadataAdd (row, PS_LIST_TAIL, "RA", PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r); 104 psMetadataAdd (row, PS_LIST_TAIL, "DEC", PS_DATA_F64, "declination (deg, J2000)", PM_DEG_RAD*ref->sky->d); 105 psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP", PS_DATA_F32, "x coord on chip", raw->chip->x); 106 psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP", PS_DATA_F32, "y coord on chip", raw->chip->y); 107 psMetadataAdd (row, PS_LIST_TAIL, "X_FPA", PS_DATA_F32, "x coord on focal plane", raw->FP->x); 108 psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA", PS_DATA_F32, "y coord on focal plane", raw->FP->y); 109 psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude", raw->Mag); 110 psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF", PS_DATA_F32, "reference star magnitude", ref->Mag); 111 psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color", ref->Color); 112 psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID", PS_DATA_STRING, "chip identifier", chipName); 113 // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined. 103 pmAstromObj *raw = rawstars->data[match->raw]; 104 pmAstromObj *ref = refstars->data[match->ref]; 114 105 115 psArrayAdd (table, 100, row); 116 psFree (row); 117 } 118 } 119 } 120 } 121 psFree (view); 106 psMetadata *row = psMetadataAlloc (); 107 psMetadataAdd (row, PS_LIST_TAIL, "RA", PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r); 108 psMetadataAdd (row, PS_LIST_TAIL, "DEC", PS_DATA_F64, "declination (deg, J2000)", PM_DEG_RAD*ref->sky->d); 109 psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP", PS_DATA_F32, "x coord on chip", raw->chip->x); 110 psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP", PS_DATA_F32, "y coord on chip", raw->chip->y); 111 psMetadataAdd (row, PS_LIST_TAIL, "X_FPA", PS_DATA_F32, "x coord on focal plane", raw->FP->x); 112 psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA", PS_DATA_F32, "y coord on focal plane", raw->FP->y); 113 psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude", raw->Mag); 114 psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF", PS_DATA_F32, "reference star magnitude", ref->Mag); 115 psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color", ref->Color); 116 psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID", PS_DATA_STRING, "chip identifier", chipName); 117 // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined. 122 118 123 if (table->n == 0) { 124 psFree(table); 125 return true; 119 psArrayAdd (table, 100, row); 120 psFree (row); 121 } 122 } 123 } 124 } 125 psFree (view); 126 127 if (table->n == 0) { 128 psFree(table); 129 return true; 130 } 126 131 } 127 132 … … 135 140 return true; 136 141 } 142 143 bool pmSourceIO_ReadMatchedRefs (psFits *fits, pmFPA *fpa, const pmConfig *config) { 144 145 bool status = true; 146 147 // check if we've already read (attempted to read) REFMATCH 148 bool readMatchedRefs = psMetadataLookupBool (&status, fpa->analysis, "READ.REFMATCH"); 149 if (readMatchedRefs) return true; 150 151 // try find the MATCHED_REFS extension. if non-existent, note that we tried, and move on. 152 if (!psFitsMoveExtName (fits, "MATCHED_REFS")) { 153 psMetadataAddBool (fpa->analysis, PS_LIST_TAIL, "READ.REFMATCH", PS_META_REPLACE, "attempted to read MATCHED_REFS", true); 154 return true; 155 } 156 157 // We get the size of the table, and allocate the array of sources first because the table 158 // is large and ephemeral --- when the table gets blown away, whatever is allocated after 159 // the table is read blocks the free. In fact, it's better to read the table row by row. 160 long numRows = psFitsTableSize(fits); // Number of sources in table 161 psArray *rows = psArrayAlloc(numRows); // Array of sources, to return 162 163 // first, check if there are any matches to be written 164 for (int i = 0; i < numRows; i++) { 165 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 166 rows->data[i] = row; 167 } 168 169 psMetadataAddArray (fpa->analysis, PS_LIST_TAIL, "MATCHED_REFS", PS_META_REPLACE, "MATCHED_REFS", rows); 170 psFree (rows); 171 172 return true; 173 }
Note:
See TracChangeset
for help on using the changeset viewer.
