IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 8, 2009, 5:32:23 PM (17 years ago)
Author:
beaumont
Message:

Cleaned up some memory allocation bugs in pmAstrometryVisual.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branch_20090113/psModules/src/astrom/pmAstrometryVisual.c

    r21208 r21421  
    4141static int kapa2 = -1;
    4242
     43//helper prototypes
     44bool residPlot (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe,
     45                char *title);
     46
    4347
    4448/* Initialization Routines  */
     
    6771
    6872    //set up plot region
    69     if (!pmVisualInitWindow (&kapa, "psastro:plots"))
    70         return false;
     73    if (!pmVisualInitWindow (&kapa, "psastro:plots")){
     74        isVisual = false;
     75        return false;
     76    }
    7177    Graphdata graphdata;
    7278    KapaSection section;
     
    231237
    232238    //set up plotting variables
    233     if (!pmVisualInitWindow (&kapa, "psastro:plots"))
    234         return false;
     239    if (!pmVisualInitWindow (&kapa, "psastro:plots")) {
     240        isVisual = false;
     241        return false;
     242    }
    235243
    236244    Graphdata graphdata;
     
    296304
    297305    //set up plotting variables
    298     if ( !pmVisualInitWindow (&kapa, "psastro:plots"))
    299         return false;
     306    if ( !pmVisualInitWindow (&kapa, "psastro:plots")){
     307        isVisual = false;
     308        return false;
     309    }
    300310
    301311    Graphdata graphdata;
     
    384394
    385395    //set up plot variables
    386     if ( !pmVisualInitWindow (&kapa, "psastro:plots")) return false;
     396    if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
     397        isVisual = false;
     398        return false;
     399    }
    387400
    388401    KapaSection section;
     
    486499        return true;
    487500
     501    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
     502        isVisual = false;
     503        return false;
     504    }
     505
    488506    //plot the residuals
    489     if (!pmVisualResidPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals (Chip Coordinates)", &kapa, &kapa2))
    490         return false;
     507    if (!residPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals (Chip Coordinates)")) {
     508        plotOneChipFit = false;
     509        return false;
     510    }
    491511
    492512    //ask for user input and finish
     
    504524    if(!isVisual || !plotFixChips) return true;
    505525
    506     if(!pmVisualInitWindow(&kapa, "psastro:plots")) return false;
     526    if(!pmVisualInitWindow(&kapa, "psastro:plots")) {
     527        isVisual = false;
     528        return false;
     529    }
    507530
    508531    KapaSection section = {"s1", .05, .05, .9, .9};
     
    586609
    587610    //set up graph window
    588     if ( !pmVisualInitWindow (&kapa, "psastro:plots"))
    589         return false;
     611    if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
     612        isVisual = false;
     613        return false;
     614    }
     615
    590616    Graphdata graphdata;
    591617    KapaSection section;
     
    670696{
    671697    //make sure we want to plot this
    672     if (!isVisual || !plotCommonScale) return false;
    673 
    674     if (!pmVisualInitWindow(&kapa, "psastro:plots")) return false;
     698    if (!isVisual || !plotCommonScale) return true;
     699
     700    if (!pmVisualInitWindow(&kapa, "psastro:plots")){
     701        isVisual = false;
     702        return false;
     703    }
    675704
    676705    KapaSection section = {"s1", .05, .05, .9, .9};
     
    694723        yVec->data.F32[nobj] = ptFP.y;
    695724        nobj++;
     725        if (nobj == oldScale->n) break;
    696726    }
    697727
     
    707737
    708738    pmVisualAskUser (&plotCommonScale, &isVisual);
     739
     740    psFree(xVec);
     741    psFree(yVec);
     742
    709743    return true;
    710744}
     
    716750
    717751    //make sure we want to plot this
    718     if (!isVisual || !plotMosaicOneChip) return false;
     752    if (!isVisual || !plotMosaicOneChip) return true;
     753
     754    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
     755        isVisual = false;
     756        return false;
     757    }
    719758
    720759    //plot the residuals
    721     if (!pmVisualResidPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals - Mosaic Mode", &kapa, &kapa2))
    722         return false;
     760    if (!residPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals - Mosaic Mode")) {
     761        isVisual = false;
     762        return false;
     763    }
    723764
    724765    //ask for user input and finish
     
    739780    sprintf(title, "Matches found during psastroMosaicSetMatch iteration %d", iteration);
    740781
    741     if (!pmVisualResidPlot(rawstars, refstars, match, recipe, title, &kapa, &kapa2))
    742         return false;
     782
     783    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
     784        isVisual = false;
     785        return false;
     786    }
     787
     788    if (!residPlot(rawstars, refstars, match, recipe, title)){
     789        isVisual = false;
     790        return false;
     791    }
    743792
    744793    //ask for user input
     
    759808    //make sure we want to plot this
    760809    if (!isVisual || !plotGridMatch) return true;
    761     if (!pmVisualInitWindow(&kapa, "pmAstrom:plots"))
    762         return false;
     810    if (!pmVisualInitWindow(&kapa, "psastro:plots")){
     811        isVisual = false;
     812        return false;
     813    }
    763814
    764815    KapaSection section = {"s1", 0.05, 0.05, .75, .75};
     
    768819    Graphdata graphdata;
    769820    int nplot = raw->n * ref->n;                      // number of points to plot
    770     float dXplot[nplot];                              // x data points
    771     float dYplot[nplot];                              // y data points
     821    psVector *dXplot = psVectorAlloc (nplot, PS_TYPE_F32); // x data points
     822    psVector *dYplot = psVectorAlloc (nplot, PS_TYPE_F32); // y data points
     823
    772824    pmAstromObj *ob1; pmAstromObj *ob2;               // shortcuts to the data in raw and ref
    773825    psU32 **NP = gridNP->data.U32;                    // shortcut to the gridNP data
     
    812864            dX = ob1->FP->x - ob2->FP->x;
    813865            dY = ob1->FP->y - ob2->FP->y;
    814             dXplot[(i * ref->n) + j] = dX;
    815             dYplot[(i * ref->n) + j] = dY;
     866            dXplot->data.F32[(i * ref->n) + j] = dX;
     867            dYplot->data.F32[(i * ref->n) + j] = dY;
    816868        }
    817869    }
     
    835887    //Plot the offsets
    836888    KapaPrepPlot(kapa, nplot, &graphdata);
    837     KapaPlotVector (kapa, nplot, dXplot, "x");
    838     KapaPlotVector (kapa, nplot, dYplot, "y");
     889    KapaPlotVector (kapa, nplot, dXplot->data.F32, "x");
     890    KapaPlotVector (kapa, nplot, dYplot->data.F32, "y");
    839891
    840892    //Overplot bounding box, peak of distribution
     
    900952
    901953    pmVisualAskUser(&plotGridMatch, &isVisual);
     954    psFree(dXplot);
     955    psFree(dYplot);
    902956    return true;
    903957} // end of pmAstromVisualPlotGridMatch
     
    912966    //make sure we want to plot this
    913967    if (!isVisual || !plotTweak) return true;
    914     if (!pmVisualInitWindow(&kapa, "pmAstrom:plots")) {
     968    if (!pmVisualInitWindow(&kapa, "psastro:plots")) {
     969        isVisual = false;
    915970        return false;
    916971    }
     
    10021057} //end of pmAstromPlotTweak
    10031058
     1059
     1060bool residPlot (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe,
     1061                        char *title) {
     1062
     1063
     1064    //initialize graph information
     1065    Graphdata graphdata;
     1066    KapaSection section;
     1067
     1068    KapaInitGraph (&graphdata);
     1069    KapaClearPlots (kapa);
     1070
     1071    graphdata.color = KapaColorByName ("black");
     1072    graphdata.ptype = 7;
     1073    graphdata.size = 0.5;
     1074    graphdata.style = 2;
     1075
     1076    section.dx = 0.4;
     1077    section.dy = 0.4;
     1078
     1079    //initialize and populate the plotting vectors
     1080    bool status = false;
     1081    float iMagMin = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.INST.MAG.MIN");
     1082    float iMagMax = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.INST.MAG.MAX");
     1083    float rMagMin = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.REF.MAG.MIN");
     1084    float rMagMax = psMetadataLookupF32 (&status, recipe, "PSASTRO.PLOT.REF.MAG.MAX");
     1085
     1086    psVector *xVec = psVectorAlloc (match->n, PS_TYPE_F32);
     1087    psVector *yVec = psVectorAlloc (match->n, PS_TYPE_F32);
     1088    psVector *zVec = psVectorAlloc (match->n, PS_TYPE_F32);
     1089
     1090    // X vs dX
     1091    section.x = 0.0;
     1092    section.y = 0.5;
     1093    section.name = NULL;
     1094    psStringAppend (&section.name, "a0");
     1095    KapaSetSection (kapa, &section);
     1096    psFree (section.name);
     1097
     1098    int n = 0;
     1099    for (int i = 0; i < match->n; i++) {
     1100        pmAstromMatch *pair = match->data[i];
     1101        pmAstromObj *raw = rawstars->data[pair->raw];
     1102        pmAstromObj *ref = refstars->data[pair->ref];
     1103
     1104        if (!isfinite(raw->Mag)) continue;
     1105        if (raw->Mag < iMagMin) continue;
     1106        if (raw->Mag > iMagMax) continue;
     1107        if (ref->Mag < rMagMin) continue;
     1108        if (ref->Mag > rMagMax) continue;
     1109
     1110        xVec->data.F32[n] = raw->chip->x;
     1111        yVec->data.F32[n] = raw->chip->x - ref->chip->x;
     1112        zVec->data.F32[n] = raw->Mag;
     1113        n++;
     1114    }
     1115    xVec->n = yVec->n = zVec->n = n;
     1116
     1117    KapaSendLabel (kapa, "X", KAPA_LABEL_XM);
     1118    KapaSendLabel (kapa, "dX", KAPA_LABEL_YM);
     1119    pmVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
     1120
     1121    // X vs dY
     1122    section.x = 0.5;
     1123    section.y = 0.5;
     1124    section.name = NULL;
     1125    psStringAppend (&section.name, "a1");
     1126    KapaSetSection (kapa, &section);
     1127    psFree (section.name);
     1128
     1129    n = 0;
     1130    for (int i = 0; i < match->n; i++) {
     1131        pmAstromMatch *pair = match->data[i];
     1132        pmAstromObj *raw = rawstars->data[pair->raw];
     1133        pmAstromObj *ref = refstars->data[pair->ref];
     1134
     1135        if (!isfinite(raw->Mag)) continue;
     1136        if (raw->Mag < iMagMin) continue;
     1137        if (raw->Mag > iMagMax) continue;
     1138        if (ref->Mag < rMagMin) continue;
     1139        if (ref->Mag > rMagMax) continue;
     1140
     1141        xVec->data.F32[n] = raw->chip->x;
     1142        yVec->data.F32[n] = raw->chip->y - ref->chip->y;
     1143        zVec->data.F32[n] = raw->Mag;
     1144        n++;
     1145    }
     1146    xVec->n = yVec->n = zVec->n = n;
     1147
     1148    KapaSendLabel (kapa, "X", KAPA_LABEL_XM);
     1149    KapaSendLabel (kapa, "dY", KAPA_LABEL_YM);
     1150    pmVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
     1151
     1152    // Y vs dX
     1153    section.x = 0.0;
     1154    section.y = 0.0;
     1155    section.name = NULL;
     1156    psStringAppend (&section.name, "a2");
     1157    KapaSetSection (kapa, &section);
     1158    psFree (section.name);
     1159
     1160    n = 0;
     1161    for (int i = 0; i < match->n; i++) {
     1162        pmAstromMatch *pair = match->data[i];
     1163        pmAstromObj *raw = rawstars->data[pair->raw];
     1164        pmAstromObj *ref = refstars->data[pair->ref];
     1165
     1166        if (!isfinite(raw->Mag)) continue;
     1167        if (raw->Mag < iMagMin) continue;
     1168        if (raw->Mag > iMagMax) continue;
     1169        if (ref->Mag < rMagMin) continue;
     1170        if (ref->Mag > rMagMax) continue;
     1171
     1172        xVec->data.F32[n] = raw->chip->y;
     1173        yVec->data.F32[n] = raw->chip->x - ref->chip->x;
     1174        zVec->data.F32[n] = raw->Mag;
     1175        n++;
     1176    }
     1177    xVec->n = yVec->n = zVec->n = n;
     1178
     1179    KapaSendLabel (kapa, "Y", KAPA_LABEL_XM);
     1180    KapaSendLabel (kapa, "dX", KAPA_LABEL_YM);
     1181    pmVisualTriplePlot (kapa, &graphdata, xVec, yVec, zVec, false);
     1182
     1183    // Y vs dY
     1184    section.x = 0.5;
     1185    section.y = 0.0;
     1186    section.name = NULL;
     1187    psStringAppend (&section.name, "a3");
     1188    KapaSetSection (kapa, &section);
     1189    psFree (section.name);
     1190
     1191    n = 0;
     1192    for (int i = 0; i < match->n; i++) {
     1193        pmAstromMatch *pair = match->data[i];
     1194        pmAstromObj *raw = rawstars->data[pair->raw];
     1195        pmAstromObj *ref = refstars->data[pair->ref];
     1196
     1197        if (!isfinite(raw->Mag)) continue;
     1198        if (raw->Mag < iMagMin) continue;
     1199        if (raw->Mag > iMagMax) continue;
     1200        if (ref->Mag < rMagMin) continue;
     1201        if (ref->Mag > rMagMax) continue;
     1202
     1203        xVec->data.F32[n] = raw->chip->y;
     1204        yVec->data.F32[n] = raw->chip->y - ref->chip->y;
     1205        zVec->data.F32[n] = raw->Mag;
     1206        n++;
     1207    }
     1208    xVec->n = yVec->n = zVec->n = n;
     1209
     1210    KapaSendLabel (kapa, "Y", KAPA_LABEL_XM);
     1211    KapaSendLabel (kapa, "dY", KAPA_LABEL_YM);
     1212    pmKapaPlotVectorTriple_AutoLimits_OpenGraph (kapa, &graphdata, xVec, yVec, zVec, false);
     1213
     1214    section.x = 0.0;
     1215    section.y = 0.0;
     1216    section.dx = 0.95;
     1217    section.dy = 0.95;
     1218    section.name = NULL;
     1219    psStringAppend (&section.name, "a5");
     1220    KapaSetSection (kapa, &section);
     1221    KapaSendLabel (kapa, title, KAPA_LABEL_XP);
     1222    psFree (section.name);
     1223
     1224    //second window
     1225
     1226    KapaInitGraph (&graphdata);
     1227    KapaClearPlots (kapa2);
     1228
     1229    graphdata.color = KapaColorByName ("black");
     1230    graphdata.ptype = 2;
     1231    graphdata.style = 2;
     1232
     1233    psFree (xVec);
     1234    psFree (yVec);
     1235    psFree (zVec);
     1236
     1237    xVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
     1238    yVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
     1239    zVec = psVectorAlloc (rawstars->n, PS_TYPE_F32);
     1240
     1241    // X vs Y by mag (raw)
     1242    n = 0;
     1243    for (int i = 0; i < rawstars->n; i++) {
     1244        pmAstromObj *raw = rawstars->data[i];
     1245        if (!isfinite(raw->Mag)) continue;
     1246        if (raw->Mag < iMagMin) continue;
     1247        if (raw->Mag > iMagMax) continue;
     1248
     1249        xVec->data.F32[n] = raw->chip->x;
     1250        yVec->data.F32[n] = raw->chip->y;
     1251        zVec->data.F32[n] = raw->Mag;
     1252        n++;
     1253    }
     1254    xVec->n = yVec->n = zVec->n = n;
     1255
     1256    KapaSendLabel (kapa2, "X", KAPA_LABEL_XM);
     1257    KapaSendLabel (kapa2, "Y", KAPA_LABEL_YM);
     1258    KapaSendLabel (kapa2,
     1259                   "Chip Coordinates. Black = Raw Stars. Red = Ref Stars. Blue = Matched Stars"
     1260                   , KAPA_LABEL_XP);
     1261    pmVisualTriplePlot (kapa2, &graphdata, xVec, yVec, zVec, false);
     1262
     1263    // X vs Y by mag (ref)
     1264    psFree (xVec);
     1265    psFree (yVec);
     1266    psFree (zVec);
     1267
     1268    xVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
     1269    yVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
     1270    zVec = psVectorAlloc (refstars->n, PS_TYPE_F32);
     1271
     1272    graphdata.color = KapaColorByName ("red");
     1273    graphdata.ptype = 7;
     1274    graphdata.style = 2;
     1275
     1276    n = 0;
     1277    for (int i = 0; i < refstars->n; i++) {
     1278        pmAstromObj *ref = refstars->data[i];
     1279        if (!isfinite(ref->Mag)) continue;
     1280        if (ref->Mag < rMagMin) continue;
     1281        if (ref->Mag > rMagMax) continue;
     1282
     1283        xVec->data.F32[n] = ref->chip->x;
     1284        yVec->data.F32[n] = ref->chip->y;
     1285        zVec->data.F32[n] = ref->Mag;
     1286        n++;
     1287    }
     1288    xVec->n = yVec->n = zVec->n = n;
     1289    pmVisualTripleOverplot (kapa2, &graphdata, xVec, yVec, zVec, false);
     1290
     1291    //rescale the graph to include all points
     1292    float xmin = graphdata.xmin;
     1293    float ymin = graphdata.ymin;
     1294    float xmax = graphdata.xmax;
     1295    float ymax = graphdata.ymax;
     1296    pmVisualScaleGraphdata(&graphdata, xVec, yVec, true);
     1297    graphdata.xmin = PS_MIN(xmin, graphdata.xmin);
     1298    graphdata.ymin = PS_MIN(ymin, graphdata.ymin);
     1299    graphdata.xmax = PS_MAX(xmax, graphdata.xmax);
     1300    graphdata.ymax = PS_MAX(ymax, graphdata.ymax);
     1301    KapaSetLimits (kapa2, &graphdata);
     1302
     1303    //overplot matched stars in blue
     1304    psFree (xVec);
     1305    psFree (yVec);
     1306    psFree (zVec);
     1307
     1308    xVec = psVectorAlloc (match->n, PS_TYPE_F32);
     1309    yVec = psVectorAlloc (match->n, PS_TYPE_F32);
     1310    zVec = psVectorAlloc (match->n, PS_TYPE_F32);
     1311
     1312    graphdata.color = KapaColorByName ("blue");
     1313    n = 0;
     1314    for (int i = 0; i < match->n; i++) {
     1315        pmAstromMatch *pair = match->data[i];
     1316        pmAstromObj *raw = rawstars->data[pair->raw];
     1317        pmAstromObj *ref = refstars->data[pair->ref];
     1318        if (raw->Mag < iMagMin) continue;
     1319        if (raw->Mag > iMagMax) continue;
     1320        if (ref->Mag < rMagMin) continue;
     1321        if (ref->Mag > rMagMax) continue;
     1322
     1323        xVec->data.F32[n] = raw->chip->x;
     1324        yVec->data.F32[n] = raw->chip->y;
     1325        zVec->data.F32[n] = iMagMin;
     1326        n++;
     1327    }
     1328    xVec->n = yVec->n = zVec->n = n;
     1329    pmVisualTripleOverplot (kapa2, &graphdata, xVec, yVec, zVec, false);
     1330
     1331    psFree (xVec);
     1332    psFree (yVec);
     1333    psFree (zVec);
     1334    return true;
     1335}
     1336
     1337
     1338
     1339
    10041340# else
    10051341
Note: See TracChangeset for help on using the changeset viewer.