- Timestamp:
- Mar 15, 2009, 4:56:07 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/eam_branch_20090312/psastro/src/psastroExtractAnalysis.c
r23322 r23335 20 20 21 21 # define TEST_OUTPUT 1 22 static pmFits *outStars = NULL; 22 23 psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY); 23 24 24 25 /** … … 32 33 pmReadout *readout = NULL; 33 34 float zeropt, exptime; 35 char extname[81]; 34 36 35 37 // select the current recipe … … 40 42 } 41 43 44 // force this recipe value to be false (would cause an error in psastroChooseRefstars -- no rawstars!) 45 psMetadataAddBool (recipe, PS_LIST_TAIL, "PSASTRO.MATCH.LUMFUNC", PS_META_REPLACE, "do not match luminosity functions", false); 46 42 47 psLogMsg ("psastro", PS_LOG_INFO, "extracting bright-star subrasters"); 48 49 // load the reference stars overlapping the data stars 50 psArray *refs = psastroLoadRefstars(config, "PSASTRO.EXTRACT.ASTROM"); 51 if (!refs) { 52 psError (PSASTRO_ERR_UNKNOWN, false, "failed to load reference data\n"); 53 return false; 54 } 55 if (refs->n == 0) { 56 psError(PSASTRO_ERR_REFSTARS, true, "no reference stars found"); 57 psFree(refs); 58 return false; 59 } 60 61 if (!psastroChooseRefstars (config, refs, "PSASTRO.EXTRACT.ASTROM")) { 62 psError (PSASTRO_ERR_UNKNOWN, false, "failed to select reference data for chips\n"); 63 psFree(refs); 64 return false; 65 } 66 psFree(refs); 43 67 44 68 double EXTRACT_MAX_MAG = psMetadataLookupF32 (&status, recipe, "EXTRACT_MAX_MAG"); … … 46 70 // we have two input pmFPAfiles: PSASTRO.EXTRACT.INPUT and PSASTRO.EXTRACT.ASTROM. both are in chip-mosaic or fpa format 47 71 // we have already loaded the headers from PSASTRO.EXTRACT.ASTROM and determined the astrometry terms 72 73 // select the input astrometry data (also carries the refstars) 74 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.EXTRACT.ASTROM"); 75 if (!astrom) { 76 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 77 return false; 78 } 79 pmFPA *fpa = astrom->fpa; 48 80 49 81 // select the input data sources … … 53 85 return false; 54 86 } 55 pmFPA *fpa = input->fpa;56 57 // select the input data sources58 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.EXTRACT.ASTROM");59 if (!input) {60 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");61 return false;62 }63 87 64 88 // only load data from INPUT … … 77 101 EXTRACT_MAX_MAG += MagOffset; 78 102 103 int nExt = 0; 104 79 105 // open the output file handle: we are just saving a series of extensions to this file 106 char *filename = psMetadataLookupStr (&status, config->arguments, "OUTPUT"); 107 if (!filename) { 108 psLogMsg ("psastro", PS_LOG_INFO, "output filename not supplieda"); 109 return false; 110 } 111 psFits *outStars = psFitsOpen (filename, "w"); 80 112 if (!outStars) { 81 char *filename = psMetadataLookupStr (&stats, config->arguments, "OUTPUT"); 82 if (!filename) { 83 psLogMsg ("psastro", PS_LOG_INFO, "output filename not supplieda"); 84 return false; 85 } 86 outStars = psFitsOpen (filename, "w"); 87 if (!outStars) { 88 psError(PS_ERR_IO, false, "error opening file %s\n", filename); 89 return false; 90 } 91 // call: psFitsWriteImage (fits, NULL, subraster, 0, "extname.NN"); 92 } 113 psError(PS_ERR_IO, false, "error opening file %s\n", filename); 114 return false; 115 } 116 117 pmFPAview *view = pmFPAviewAlloc (0); 93 118 94 119 // open/load files as needed … … 109 134 char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME"); 110 135 psStringAppend (&filename, "bright.%s.dat", chipname); 111 FILE *f = fopen (filename, "w");136 f = fopen (filename, "w"); 112 137 if (!f) { 113 138 psWarning ("cannot create test output file %s\n", filename); … … 132 157 for (int i = 0; i < refstars->n; i++) { 133 158 pmAstromObj *ref = refstars->data[i]; 134 if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;159 if (ref->Mag > EXTRACT_MAX_MAG) continue; 135 160 136 161 if (TEST_OUTPUT) { … … 138 163 } 139 164 140 // XXX for now, assume cell binning is 1x1 relative to chip 141 psImage *subraster = psastroExtractStar (input->image, ref->chip->x, ref->chip->y, DX, DY); 165 pmReadout *inReadout = pmFPAviewThisReadout (view, input->fpa); 166 psImage *subraster = psastroExtractStar (inReadout->image, ref->chip->x, ref->chip->y, 100.0, 100.0); 167 if (!subraster) continue; 168 169 snprintf (extname, 80, "extname.%05d", nExt); 170 psFitsWriteImage (outStars, NULL, subraster, 0, extname); 171 nExt ++; 172 173 psFree (subraster); 142 174 } 143 if (!pmFPAfileIOChecks (config, view Mask, PM_FPA_AFTER)) ESCAPE;175 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 144 176 } 145 if (!pmFPAfileIOChecks (config, view Mask, PM_FPA_AFTER)) ESCAPE;177 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 146 178 } 147 179 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 148 180 181 fclose (f); 149 182 } 150 183 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 151 184 152 // need to close the output fits file on some basis.. 153 fclose (f); 154 185 psFitsClose (outStars); 155 186 psFree (view); 156 187 return true; 157 188 } 158 189 190 psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY) { 191 192 // skip if no pixels are on the image 193 // skip if center is not on the image 194 // if bounds fall off image, paste into a full-size image. 195 196 if (x < 0) return NULL; 197 if (y < 0) return NULL; 198 if (x >= input->numCols) return NULL; 199 if (y >= input->numRows) return NULL; 200 201 psRegion fullRegion = psRegionSet (x - dX, x + dX, y - dY, y + dY); 202 psRegion realRegion = psRegionForImage (input, fullRegion); 203 psImage *subset = psImageSubset (input, realRegion); 204 205 // if ((subset->numCols < dX) || (subset->numRows < dY)) { 206 // psImage *fullsize = psImageAlloc (dX, dY, PS_TYPE_F32); 207 // // fill in the fullsize image with the values from the subset 208 // // I must already have done this elsewhere... 209 // } 210 return subset; 211 }
Note:
See TracChangeset
for help on using the changeset viewer.
