IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 2, 2005, 3:30:32 PM (21 years ago)
Author:
Paul Price
Message:

Working with release 8. Overscan, bias, flat-fielding all working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/phase2/papPhase2.c

    r5371 r5462  
    250250            overscanFitType = PM_FIT_SPLINE;
    251251            int order = psMetadataLookupS32(NULL, recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
    252 //          overscanFit = psSpline1DAlloc(order, PS_POLYNOMIAL_ORD);
     252            overscanFit = NULL;
     253//          overscanFit = psSpline1DAlloc();
    253254        } else if (strcasecmp(fit, "NONE") != 0) {
    254255            psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
     
    292293
    293294    // Read in the input pixels
     295    psLogMsg("phase2", PS_LOG_INFO, "Opening input image: %s\n", inputName);
    294296    if (! pmFPARead(input, inputFile, header, database)) {
    295297        psErrorStackPrint(stderr, "Unable to populate camera from FITS file: %s\n", inputName);
     
    316318            exit(EXIT_FAILURE);
    317319        }
     320        psLogMsg("phase2", PS_LOG_INFO, "Opening bias image: %s\n", biasName);
     321        if (! pmFPARead(bias, biasFile, biasHeader, database)) {
     322            psErrorStackPrint(stderr, "Unable to populate bias camera from fits FITS: %s\n", biasName);
     323            exit(EXIT_FAILURE);
     324        }
    318325        psFree(biasHeader);
    319         if (! pmFPARead(bias, biasFile, NULL, database)) {
    320             psErrorStackPrint(stderr, "Unable to populate bias camera from fits FITS: %s\n", biasName);
    321             exit(EXIT_FAILURE);
    322         }
    323326#ifdef PRODUCTION
    324327        psFitsClose(biasFile);
     
    339342            exit(EXIT_FAILURE);
    340343        }
     344        psLogMsg("phase2", PS_LOG_INFO, "Opening dark image: %s\n", darkName);
     345        if (! pmFPARead(dark, darkFile, darkHeader, database)) {
     346            psErrorStackPrint(stderr, "Unable to populate dark camera from fits FITS: %s\n", darkName);
     347            exit(EXIT_FAILURE);
     348        }
    341349        psFree(darkHeader);
    342         if (! pmFPARead(dark, darkFile, NULL, database)) {
    343             psErrorStackPrint(stderr, "Unable to populate dark camera from fits FITS: %s\n", darkName);
    344             exit(EXIT_FAILURE);
    345         }
    346350#ifdef PRODUCTION
    347351        psFitsClose(darkFile);
     
    362366            exit(EXIT_FAILURE);
    363367        }
     368        psLogMsg("phase2", PS_LOG_INFO, "Opening mask image: %s\n", maskName);
     369        if (! pmFPARead(mask, maskFile, maskHeader, database)) {
     370            psErrorStackPrint(stderr, "Unable to populate mask camera from fits FITS: %s\n", maskName);
     371            exit(EXIT_FAILURE);
     372        }
    364373        psFree(maskHeader);
    365         if (! pmFPARead(mask, maskFile, NULL, database)) {
    366             psErrorStackPrint(stderr, "Unable to populate mask camera from fits FITS: %s\n", maskName);
    367             exit(EXIT_FAILURE);
    368         }
     374
    369375#ifdef PRODUCTION
    370376        psFitsClose(maskFile);
     
    380386        psFits *flatFile = psFitsAlloc(flatName);
    381387#endif
     388        if (! flatFile) {
     389            psErrorStackPrint(stderr, "Can't open flat image: %s\n", flatName);
     390            exit(EXIT_FAILURE);
     391        }
    382392        psMetadata *flatHeader = psFitsReadHeader(NULL, flatFile); // FITS header for flat
    383393        if (! pmConfigValidateCamera(camera, flatHeader)) {
     
    385395            exit(EXIT_FAILURE);
    386396        }
     397        psLogMsg("phase2", PS_LOG_INFO, "Opening flat image: %s\n", flatName);
     398        if (! pmFPARead(flat, flatFile, flatHeader, database)) {
     399            psErrorStackPrint(stderr, "Unable to populate flat camera from fits FITS: %s\n", flatName);
     400            exit(EXIT_FAILURE);
     401        }
    387402        psFree(flatHeader);
    388         if (! pmFPARead(flat, flatFile, NULL, database)) {
    389             psErrorStackPrint(stderr, "Unable to populate flat camera from fits FITS: %s\n", flatName);
    390             exit(EXIT_FAILURE);
    391         }
    392403#ifdef PRODUCTION
    393404        psFitsClose(flatFile);
     
    499510                    } else {
    500511                        switch (dataItem->type) {
    501                           case PS_META_VEC:
     512                          case PS_DATA_VECTOR:
    502513                            {
    503514                                // These are the polynomial coefficients
     
    518529                            }
    519530                            break;
    520                           case PS_META_STR:
     531                          case PS_DATA_STRING:
    521532                            {
    522533                                // This is a filename
     
    536547                            }
    537548                            break;
    538                           case PS_META_META:
     549                          case PS_DATA_METADATA:
    539550                            {
    540551                                // This is a menu
     
    550561                                        psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
    551562                                                 "for non-linearity correction --- ignored.\n", concept);
    552                                     } else if (conceptValueItem->type != PS_META_STR) {
     563                                    } else if (conceptValueItem->type != PS_DATA_STRING) {
    553564                                        psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as"
    554565                                                 " expected for non-linearity correction --- ignored.\n",
     
    561572                                            psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
    562573                                                     " --- ignored.\n", conceptValue);
    563                                         } else if (optionItem->type == PS_META_VEC) {
     574                                        } else if (optionItem->type == PS_DATA_VECTOR) {
    564575                                            // These are the polynomial coefficients
    565576                                            psVector *coeff = optionItem->data.V; // The coefficient vector
     
    578589                                            psFree(coeff);
    579590                                            psFree(correction);
    580                                         } else if (optionItem->type == PS_META_STR) {
     591                                        } else if (optionItem->type == PS_DATA_STRING) {
    581592                                            // This is a filename
    582593                                            psString tableName = optionItem->data.V; // The filename
     
    673684                    // Output overscan fit results, if required
    674685                    if (doOverscan) {
    675                         switch (overscanFitType) {
    676                           case PM_FIT_POLYNOMIAL:
    677                             {
    678                                 psPolynomial1D *poly = (psPolynomial1D*)overscanFit;    // The polynomial
    679                                 psString coeffs = NULL; // String containing the coefficients
    680                                 for (int i = 0; i < poly->n; i++) {
    681                                     psStringAppend(&coeffs, "%e ", poly->coeff[i]);
    682                                 }
    683                                 psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n",
    684                                          coeffs);
    685                                 psFree(coeffs);
    686                             }
    687                             break;
    688                           case PM_FIT_SPLINE:
    689                             {
    690                                 psSpline1D *spline = (psSpline1D*)overscanFit; // The spline
    691                                 psString coeffs = NULL; // String containing the coefficients
    692                                 for (int i = 0; i < spline->n; i++) {
    693                                     psPolynomial1D *poly = spline->spline[i]; // i-th polynomial
    694                                     psStringAppend(&coeffs, "%d: ", i);
    695                                     for (int j = 0; j < poly->n; j++) {
     686                        if (! overscanFit) {
     687                            psLogMsg("phase2", PS_LOG_WARN, "No fit generated!\n");
     688                        } else {
     689                            switch (overscanFitType) {
     690                              case PM_FIT_POLYNOMIAL:
     691                                {
     692                                    psPolynomial1D *poly = (psPolynomial1D*)overscanFit; // The polynomial
     693                                    psString coeffs = NULL;     // String containing the coefficients
     694                                    for (int i = 0; i < poly->nX; i++) {
    696695                                        psStringAppend(&coeffs, "%e ", poly->coeff[i]);
    697696                                    }
    698                                     psStringAppend(&coeffs, "\n");
     697                                    psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n",
     698                                             coeffs);
     699                                    psFree(coeffs);
    699700                                }
    700                                 psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n",
    701                                          coeffs);
    702                                 psFree(coeffs);
     701                                break;
     702                              case PM_FIT_SPLINE:
     703                                {
     704                                    psSpline1D *spline = (psSpline1D*)overscanFit; // The spline
     705                                    psString coeffs = NULL;     // String containing the coefficients
     706                                    for (int i = 0; i < spline->n; i++) {
     707                                        psPolynomial1D *poly = spline->spline[i]; // i-th polynomial
     708                                        psStringAppend(&coeffs, "%d: ", i);
     709                                        for (int j = 0; j < poly->nX; j++) {
     710                                            psStringAppend(&coeffs, "%e ", poly->coeff[i]);
     711                                        }
     712                                        psStringAppend(&coeffs, "\n");
     713                                    }
     714                                    psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n",
     715                                             coeffs);
     716                                    psFree(coeffs);
     717                                }
     718                                break;
     719                              case PM_FIT_NONE:
     720                                break;
     721                              default:
     722                                psAbort(__func__, "Should never get here!!!\n");
    703723                            }
    704                             break;
    705                           case PM_FIT_NONE:
    706                             break;
    707                           default:
    708                             psAbort(__func__, "Should never get here!!!\n");
    709724                        }
    710725                    }
    711726                }
    712727
     728                // Trim, so that flat, fringe etc computations are faster.
     729                psRegion *trimRegion = psMetadataLookupPtr(NULL, inputCell->concepts, "CELL.TRIMSEC");
     730                psImage *trimmed = psImageSubset(inputReadout->image, *trimRegion);
     731                psFree(inputReadout->image);
     732                inputReadout->image = trimmed;
     733
    713734                // Flat-field correction
    714735                if (doFlat) {
    715                     (void)pmFlatField(inputReadout, flatReadout);
     736                    psLogMsg("phase2", PS_LOG_INFO, "Performing flat field.\n");
     737#ifndef PRODUCTION
     738                    psImage *dummyImage = psImageAlloc(inputReadout->image->numCols,
     739                                                       inputReadout->image->numRows,
     740                                                       PS_TYPE_U8);
     741                    pmReadout *dummyMask = pmReadoutAlloc(NULL, dummyImage, NULL, 0, 0, 1, 1, 1, 1);
     742                    (void)pmFlatField(inputReadout, dummyMask, flatReadout);
     743                    psFree(dummyMask);
     744                    psFree(dummyImage);
     745#endif
    716746                }
    717747
Note: See TracChangeset for help on using the changeset viewer.