Changeset 41434 for trunk/psastro/src/psastroLoadGhosts.c
- Timestamp:
- Nov 13, 2020, 2:48:11 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroLoadGhosts.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroLoadGhosts.c
r41367 r41434 41 41 } 42 42 43 // To select good stars, I want them to have a PSFmodel fit (PM_SOURCE_MODE_PSFMODEL & PM_SOURCE_MODE_FITTED) and exlcude things that are CR, EXT, FAIL, POOR 44 // Stars are allowed to be saturated, as long as the PSF model fits 45 # define PHOT_SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_BLEND | PM_SOURCE_MODE_BADPSF | \ 46 PM_SOURCE_MODE_DEFECT | PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT | \ 47 PM_SOURCE_MODE_POOR) // Mask to apply to sources for rejection 48 43 49 /** 44 50 * calculate ghost FPA and Chip positions for the stars loaded on the FPA … … 101 107 pmCell *cell = NULL; 102 108 pmReadout *readout = NULL; 103 float zeropt, exptime, MAX_MAG;109 float zeropt, exptime,MAX_MAG, INSTR_MAX_MAG; 104 110 psMetadata *md = NULL; 105 111 psPolynomial2D *centerX = NULL; … … 139 145 140 146 // raise an error if the config is broken 141 if (!psastroZeroPointFromRecipe (&zeropt, &exptime, & MAX_MAG, NULL, fpa, recipe)) {147 if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &INSTR_MAX_MAG, NULL, fpa, recipe)) { 142 148 psError(PSASTRO_ERR_CONFIG, true, "failed to load zeropt data from recipe"); 143 149 goto escape; … … 147 153 // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime) 148 154 float MagOffset = zeropt + 2.5*log10(exptime); 149 MAX_MAG +=MagOffset;155 MAX_MAG = INSTR_MAX_MAG + MagOffset; 150 156 151 157 // this loop selects the matched stars for all chips … … 163 169 if (! readout->data_exists) { continue; } 164 170 171 //First, select bright sources for ghosts from the detections. Later on, do the same using the refcat 172 // That way we can include things like movers creating crosstalk features. 173 psArray *calstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.CALSTARS"); 174 if (calstars == NULL) { continue; } 175 176 // identify the bright stars of interest 177 for (int i = 0; i < calstars->n; i++) { 178 pmAstromObj *cal = calstars->data[i]; 179 psTrace("psastro.ghost",5,"Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g)",i,calstars->n,INSTR_MAX_MAG,cal->Mag,cal->sky->r * 180 / M_PI,cal->sky->d * 180.0 / M_PI); 180 181 if (cal->Mag > INSTR_MAX_MAG) { 182 continue; 183 } 184 185 psastroGhost *ghost = psastroGhostAlloc (); 186 ghost->srcFP->x = cal->FP->x; 187 ghost->srcFP->y = cal->FP->y; 188 189 double rSrc = hypot (cal->FP->x, cal->FP->y); 190 double theta0 = atan2(cal->FP->x,cal->FP->y); 191 192 if(mirCheck) { 193 //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle 194 double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc); 195 double ghost_x_fpa_mirror = cal->FP->x + ((cal->FP->x*-1.)/abs(cal->FP->x)*abs(cos(theta0)*ghost_offset_rad)); 196 double ghost_y_fpa_mirror = cal->FP->y + ((cal->FP->y*-1.)/abs(cal->FP->y)*abs(sin(theta0)*ghost_offset_rad)); 197 198 // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords 199 ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror); 200 ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror); 201 } 202 if(!mirCheck) { 203 //Use the old-style ghost position determination 204 ghost->FP->x = -cal->FP->x + psPolynomial2DEval(centerX, -cal->FP->x, -cal->FP->y); 205 ghost->FP->y = -cal->FP->y + psPolynomial2DEval(centerY, -cal->FP->x, -cal->FP->y); 206 } 207 208 ghost->inner.major = psPolynomial1DEval (innerMajor, rSrc); 209 ghost->inner.minor = psPolynomial1DEval (innerMinor, rSrc); 210 ghost->inner.theta = atan2(cal->FP->y, cal->FP->x); 211 212 ghost->outer.major = psPolynomial1DEval (outerMajor, rSrc); 213 ghost->outer.minor = psPolynomial1DEval (outerMinor, rSrc); 214 ghost->outer.theta = atan2(cal->FP->y, cal->FP->x); 215 216 // report instrumental ghost star mags 217 ghost->Mag = cal->Mag; 218 219 // XXX this code yields a single chip: we need to provide results for any chips 220 // which encompass the full size of the ghost 221 pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, -ghost->srcFP->x, -ghost->srcFP->y); 222 /* float star_chip_x = ghost->chip->x; */ 223 /* float star_chip_y = ghost->chip->y; */ 224 ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y); 225 //psLogMsg ("psastro", PS_LOG_INFO, "-> DETEC model chip position: %f, %f %f, %f %g\n", ghost->chip->x, ghost->chip->y,ghost->srcFP->x, ghost->srcFP->y,cal->Mag+MagOffset); 226 227 if (ghostChip) { 228 psTrace("psastro.ghost",5," in ghost: %d/%ld: ref: (%f,%f) or (%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)", 229 i,calstars->n, 230 cal->FP->x,cal->FP->y, 231 psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"), 232 ghost->FP->x,ghost->FP->y, 233 ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"), 234 rSrc, 235 ghost->inner.major,ghost->inner.minor,ghost->inner.theta, 236 ghost->outer.major,ghost->outer.minor,ghost->outer.theta); 237 /* psWarning(" GHOST_DATA: %d/%ld: ref: (%f,%f) or (%f,%f,%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)", */ 238 /* i,calstars->n, */ 239 /* cal->FP->x,cal->FP->y, */ 240 /* ref_chip_x,ref_chip_y,psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"), */ 241 /* ghost->FP->x,ghost->FP->y, */ 242 /* ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"), */ 243 /* rSrc, */ 244 /* ghost->inner.major,ghost->inner.minor,ghost->inner.theta, */ 245 /* ghost->outer.major,ghost->outer.minor,ghost->outer.theta); */ 246 } 247 else { 248 psTrace("psastro.ghost",5," in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)", 249 i,calstars->n, 250 cal->FP->x,cal->FP->y, 251 ghost->FP->x,ghost->FP->y, 252 ghost->chip->x,ghost->chip->y,"NONE", 253 ghost->inner.major,ghost->inner.minor,ghost->inner.theta, 254 ghost->outer.major,ghost->outer.minor,ghost->outer.theta); 255 } 256 257 if (!ghostChip) goto skip; 258 if (!ghostChip->cells) goto skip; 259 if (!ghostChip->cells->n) goto skip; 260 261 262 pmCell *ghostCell = ghostChip->cells->data[0]; 263 if (!ghostCell) goto skip; 264 if (!ghostCell->readouts) goto skip; 265 if (!ghostCell->readouts->n) goto skip; 266 pmReadout *ghostReadout = ghostCell->readouts->data[0]; 267 if (!ghostReadout) goto skip; 268 269 psArray *ghosts = psMetadataLookupPtr (&status, ghostReadout->analysis, "PSASTRO.GHOSTS"); 270 if (ghosts == NULL) { 271 ghosts = psArrayAllocEmpty (100); 272 if (!psMetadataAdd (ghostReadout->analysis, PS_LIST_TAIL, "PSASTRO.GHOSTS", PS_DATA_ARRAY, "astrometry matches", ghosts)) { 273 psError(PSASTRO_ERR_CONFIG, false, "failure to add ghosts to readout"); 274 goto escape; 275 } 276 psFree (ghosts); 277 } 278 279 psArrayAdd (ghosts, 100, ghost); 280 281 skip: 282 283 psFree (ghost); 284 } 285 165 286 // select the raw objects for this readout (loaded in psastroChooseRefstars.c) 166 287 // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c: … … 173 294 pmAstromObj *ref = refstars->data[i]; 174 295 psTrace("psastro.ghost",5,"Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g)",i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI); 296 175 297 if (ref->Mag > MAX_MAG) continue; 176 298 … … 224 346 /* float ref_chip_y = ghost->chip->y; */ 225 347 ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y); 226 // fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y); 227 348 //psLogMsg ("psastro", PS_LOG_INFO, "-> model chip position: %f, %f %f, %f %g\n", ghost->chip->x, ghost->chip->y,ghost->srcFP->x, ghost->srcFP->y,ref->Mag); 228 349 229 350 if (ghostChip) { … … 257 378 } 258 379 259 if (!ghostChip) goto skip ;260 if (!ghostChip->cells) goto skip ;261 if (!ghostChip->cells->n) goto skip ;380 if (!ghostChip) goto skipref; 381 if (!ghostChip->cells) goto skipref; 382 if (!ghostChip->cells->n) goto skipref; 262 383 263 384 264 385 pmCell *ghostCell = ghostChip->cells->data[0]; 265 if (!ghostCell) goto skip ;266 if (!ghostCell->readouts) goto skip ;267 if (!ghostCell->readouts->n) goto skip ;386 if (!ghostCell) goto skipref; 387 if (!ghostCell->readouts) goto skipref; 388 if (!ghostCell->readouts->n) goto skipref; 268 389 pmReadout *ghostReadout = ghostCell->readouts->data[0]; 269 if (!ghostReadout) goto skip ;390 if (!ghostReadout) goto skipref; 270 391 271 392 psArray *ghosts = psMetadataLookupPtr (&status, ghostReadout->analysis, "PSASTRO.GHOSTS"); … … 281 402 psArrayAdd (ghosts, 100, ghost); 282 403 283 skip :404 skipref: 284 405 285 406 psFree (ghost); 286 407 } 408 287 409 } 288 410 }
Note:
See TracChangeset
for help on using the changeset viewer.
