IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 24, 2011, 10:09:38 PM (15 years ago)
Author:
eugene
Message:

determine the min kron radius = radius for bright PSF stars; mask interpolation used index instead of pixel coordinates in psImageInterpolate; add minKronRadius to pmSource; change errMag to psfMagErr; in growth curve, avoid perfect int radii (they can be inconsistent on + and - due to float precision; add pmGrowthCurveForSources; psfMagErr is always calculated from psfModel; apply ApTrend to all source psf mags and fluxes (not just psf sources); always use the psfModel for PSF_QF,_PERFECT; use BILINEAR to interpolate for aperture mags (BIQUAD implementation is wrong; apply growth curve to apMag & apFlux for all sources; save GrowthCurve with PSF model and read from PSF model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110404/psModules/src/objects/pmPSF_IO.c

    r31339 r31361  
    6565bool pmPSFmodelRead_ApTrend (pmPSF *psf, pmFPAfile *file);
    6666bool pmPSFmodelWrite_ApTrend (pmFPAfile *file, pmPSF *psf);
     67
     68bool pmPSFmodelRead_GrowthCurve (pmPSF *psf, pmFPAfile *file);
     69bool pmPSFmodelWrite_GrowthCurve (pmFPAfile *file, pmPSF *psf);
    6770
    6871bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
     
    600603    if (!pmPSFmodelWrite_ApTrend(file, psf)) {
    601604        psError(psErrorCodeLast(), false, "Unable to write PSF ApTrend");
     605        return false;
     606    }
     607
     608    if (!pmPSFmodelWrite_GrowthCurve(file, psf)) {
     609        psError(psErrorCodeLast(), false, "Unable to write PSF Growth Curve");
    602610        return false;
    603611    }
     
    11041112    }
    11051113
     1114    if (!pmPSFmodelRead_GrowthCurve(psf, file)) {
     1115        psError(psErrorCodeLast(), false, "Unable to read PSF Growth Curve");
     1116        return false;
     1117    }
     1118
    11061119    psMetadataAdd (chipAnalysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
    11071120    psFree (psf);
     
    12301243}
    12311244
     1245// write aperture trend to a FITS table
     1246bool pmPSFmodelWrite_GrowthCurve (pmFPAfile *file, pmPSF *psf) {
     1247
     1248    pmGrowthCurve *growth = psf->growth;
     1249    if (growth == NULL) {
     1250        psWarning ("no PSF Growth Curve to write out, skipping");
     1251        return true;
     1252    }
     1253
     1254    // we need to write a header for the table,
     1255    psMetadata *header = psMetadataAlloc();
     1256
     1257    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_MIN_RAD", 0, "", growth->radius->data.F32[0]);
     1258    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_MAX_RAD", 0, "", growth->maxRadius);
     1259    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_REF_RAD", 0, "", growth->refRadius);
     1260    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_AP_LOSS", 0, "", growth->apLoss);
     1261    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_AP_REF",  0, "", growth->apRef);
     1262    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_FIT_MAG", 0, "", growth->fitMag);
     1263
     1264    // build a FITS table of the ApTrend (only 1)
     1265    psArray *table = psArrayAllocEmpty (100);
     1266    for (int i = 0; i < growth->apMag->n; i++) {
     1267        psMetadata *row = psMetadataAlloc ();
     1268        psMetadataAddF32 (row, PS_LIST_TAIL, "RADIUS", 0, "", growth->radius->data.F32[i]);
     1269        psMetadataAddF32 (row, PS_LIST_TAIL, "AP_MAG", 0, "", growth->apMag->data.F32[i]);
     1270        psArrayAdd (table, 100, row);
     1271        psFree (row);
     1272    }
     1273
     1274    // write an empty FITS segment if we have no PSF information
     1275    if (table->n == 0) {
     1276        psError(PM_ERR_PROG, true, "No PSF data to write.");
     1277        psFree(table);
     1278        psFree(header);
     1279        return false;
     1280    }
     1281
     1282    psTrace ("pmFPAfile", 5, "writing psf Growth Curve data %s\n", "GROWTH_CURVE");
     1283    if (!psFitsWriteTable(file->fits, header, table, "GROWTH_CURVE")) {
     1284        psError(psErrorCodeLast(), false, "Error writing psf table data %s\n", "GROWTH_CURVE");
     1285        psFree(table);
     1286        psFree(header);
     1287        return false;
     1288    }
     1289
     1290    psFree (table);
     1291    psFree (header);
     1292    return true;
     1293}
     1294
     1295// read aperture trend to a FITS table
     1296bool pmPSFmodelRead_GrowthCurve (pmPSF *psf, pmFPAfile *file) {
     1297
     1298    bool status;
     1299
     1300    // move fits pointer to AP_TREND section
     1301    // advance to the table data extension
     1302    if (!psFitsMoveExtNameClean (file->fits, "GROWTH_CURVE")) {
     1303        psWarning ("no Growth Curve data in PSF file, skipping");
     1304        return true;
     1305    }
     1306
     1307    psMetadata *header = psFitsReadHeader (NULL, file->fits);
     1308    if (!header) {
     1309        psError(psErrorCodeLast(), false, "Unable to read GROWTH_CURVE header.");
     1310        return false;
     1311    }
     1312       
     1313    // read the raw table data
     1314    psArray *table = psFitsReadTable (file->fits);
     1315    if (!table) {
     1316        psError(psErrorCodeLast(), false, "Unable to read GROWTH_CURVE table.");
     1317        psFree(header);
     1318        return false;
     1319    }
     1320
     1321    float minRadius = psMetadataLookupF32 (&status, header, "GROWTH_MIN_RAD"); if (!status) return false;
     1322    float maxRadius = psMetadataLookupF32 (&status, header, "GROWTH_MAX_RAD"); if (!status) return false;
     1323    float refRadius = psMetadataLookupF32 (&status, header, "GROWTH_REF_RAD"); if (!status) return false;
     1324
     1325    psf->growth = pmGrowthCurveAlloc(minRadius, maxRadius, refRadius);
     1326
     1327    psf->growth->apLoss = psMetadataLookupF32 (&status, header, "GROWTH_AP_LOSS"); if (!status) return false;
     1328    psf->growth->apRef  = psMetadataLookupF32 (&status, header, "GROWTH_AP_REF"); if (!status) return false;
     1329    psf->growth->fitMag = psMetadataLookupF32 (&status, header, "GROWTH_FIT_MAG"); if (!status) return false;
     1330
     1331    // fill in the matching psf->params entries
     1332    for (int i = 0; i < table->n; i++) {
     1333        psMetadata *row = table->data[i];
     1334        psf->growth->apMag->data.F32[i] = psMetadataLookupF32 (&status, row, "AP_MAG"); if (!status) return false;
     1335    }
     1336
     1337    psFree (header);
     1338    psFree (table);
     1339    return true;
     1340}
     1341
    12321342bool pmPSFmodelReadPSFClump (psMetadata *analysis, psMetadata *header) {
    12331343
Note: See TracChangeset for help on using the changeset viewer.