IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20033


Ignore:
Timestamp:
Oct 9, 2008, 2:39:01 PM (18 years ago)
Author:
beaumont
Message:

merged mainline into branch. resolved conflicts. added plots.

Location:
branches/cnb_branch_20080830/psastro/src
Files:
4 added
2 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branch_20080830/psastro/src

    • Property svn:ignore
      •  

        old new  
        1515psastroModel
        1616gpcModel
         17psastroModelFit
  • branches/cnb_branch_20080830/psastro/src/.cvsignore

    r15892 r20033  
    1515psastroModel
    1616gpcModel
     17psastroModelFit
  • branches/cnb_branch_20080830/psastro/src/Makefile.am

    r19300 r20033  
    11
    22lib_LTLIBRARIES = libpsastro.la
    3 libpsastro_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS)
     3libpsastro_la_CFLAGS = $(PSASTRO_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     4libpsastro_la_LDFLAGS = $(PSASTRO_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
    45
    5 bin_PROGRAMS = psastro psastroModel gpcModel
     6bin_PROGRAMS = psastro psastroModel psastroModelFit gpcModel
    67
    7 psastro_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PPSTATS_CFLAGS) $(PSASTRO_CFLAGS)
    8 psastro_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PPSTATS_LIBS) $(PSASTRO_LIBS)
     8psastro_CFLAGS = $(PSASTRO_CFLAGS) $(PPSTATS_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     9psastro_LDFLAGS = $(PSASTRO_LIBS) $(PPSTATS_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
    910psastro_LDADD = libpsastro.la
    1011
    11 psastroModel_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS)
    12 psastroModel_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSASTRO_LIBS)
     12psastroModel_CFLAGS = $(PSASTRO_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     13psastroModel_LDFLAGS = $(PSASTRO_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
    1314psastroModel_LDADD = libpsastro.la
    1415
    15 gpcModel_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS)
    16 gpcModel_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSASTRO_LIBS)
     16psastroModelFit_CFLAGS = $(PSASTRO_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     17psastroModelFit_LDFLAGS = $(PSASTRO_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
     18psastroModelFit_LDADD = libpsastro.la
     19
     20gpcModel_CFLAGS = $(PSASTRO_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     21gpcModel_LDFLAGS = $(PSASTRO_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS)
    1722gpcModel_LDADD = libpsastro.la
    1823
     
    3843        psastroCleanup.c
    3944
     45psastroModelFit_SOURCES = \
     46        psastroModelFit.c \
     47        psastroModelBoresite.c      \
     48        psastroModelFitBoresite.c
     49
    4050gpcModel_SOURCES = gpcModel.c
    4151
     
    5060        psastroConvert.c            \
    5161        psastroChipAstrom.c         \
    52         psastroOneChip.c            \
    5362        psastroOneChipGrid.c        \
    5463        psastroOneChipFit.c         \
     
    5766        psastroTestFuncs.c          \
    5867        psastroLuminosityFunction.c \
     68        psastroLuminosityFunctionPlot.c \
    5969        psastroRefstarSubset.c      \
    6070        psastroFixChips.c           \
     
    6272        psastroUseModel.c           \
    6373        psastroMosaicAstrom.c       \
     74        psastroMosaicDistortion.c   \
     75        psastroMosaicFPtoTP.c       \
    6476        psastroMosaicGradients.c    \
     77        psastroMosaicCorrectDistortion.c   \
    6578        psastroMosaicChipAstrom.c   \
    6679        psastroMosaicOneChip.c      \
  • branches/cnb_branch_20080830/psastro/src/psastro.c

    r17934 r20033  
    99
    1010    pmConfig *config = NULL;
    11 
    1211    psTimerStart ("complete");
    1312
     
    2423    // load identify the data sources
    2524    if (!psastroParseCamera (config)) {
    26         psErrorStackPrint(stderr, "error setting up the camera\n");
    27         exit (1);
     25        psErrorStackPrint(stderr, "error setting up the camera\n");
     26        exit (1);
    2827    }
    2928
     
    3130    // select subset of stars for astrometry
    3231    if (!psastroDataLoad (config)) {
    33         psErrorStackPrint(stderr, "error loading input data\n");
    34         exit (1);
     32        psErrorStackPrint(stderr, "error loading input data\n");
     33        exit (1);
    3534    }
    3635
    3736    // run the full astrometry analysis (chip and/or mosaic)
    3837    if (!psastroAnalysis (config)) {
    39         psErrorStackPrint(stderr, "failure in psastro analysis\n");
    40         exit (1);
     38        psErrorStackPrint(stderr, "failure in psastro analysis\n");
     39        exit (1);
    4140    }
    42    
     41
    4342    // write out the results
    4443    if (!psastroDataSave (config)) {
    45         psErrorStackPrint(stderr, "failed to write out data\n");
    46         exit (1);
     44        psErrorStackPrint(stderr, "failed to write out data\n");
     45        exit (1);
    4746    }
    4847
  • branches/cnb_branch_20080830/psastro/src/psastro.h

    r19300 r20033  
    1717// logN = offset + slope * logS
    1818typedef struct {
    19     double mMin;                        // minimum magnitude bin with data
    20     double mMax;                        // maximum magnitude bin with data
    21     double offset;                      // fitted line offset
    22     double slope;                       // fitted line slope
    23     double mPeak;                       // mag of peak bin
    24     int nPeak;                          // # of stars in peak bin
    25     int sPeak;                          // sum of stars to peak bin
     19    double mMin;                        // minimum magnitude bin with data
     20    double mMax;                        // maximum magnitude bin with data
     21    double offset;                      // fitted line offset
     22    double slope;                       // fitted line slope
     23    double mPeak;                       // mag of peak bin
     24    int nPeak;                          // # of stars in peak bin
     25    int sPeak;                          // sum of stars to peak bin
    2626} pmLumFunc;
    2727
     
    3535psArray          *pmSourceToAstromObj (psArray *sources);
    3636bool              psastroAstromGuess (int *nStars, pmConfig *config);
     37bool              psastroAstromGuessCheck (pmConfig *config);
    3738
    3839psPlaneDistort   *psPlaneDistortIdentity ();
     
    4647bool              psastroChooseRefstars (pmConfig *config, psArray *refs);
    4748bool              psastroRefstarSubset (pmReadout *readout);
    48 pmLumFunc        *psastroLuminosityFunction (psArray *stars);
     49pmLumFunc        *psastroLuminosityFunction (psArray *stars, pmLumFunc *rawFunc);
     50bool              psastroLuminosityFunctionPlot(psVector *lnMag, psVector *Mag, pmLumFunc *lumFunc, pmLumFunc *rawFunc);
    4951psArray          *psastroRemoveClumps (psArray *input, int scale);
    5052
     
    5557
    5658// mosaic fitting functions
    57 bool              psastroMosaicGradients (pmFPA *fpa, psMetadata *recipe);
    58 bool              psastroMosaicCommonScale (pmFPA *fpa, psMetadata *recipe);
    59 bool              psastroMosaicAstrom (pmConfig *config);
    60 bool              psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, int iteration);
    61 bool              psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe, int iteration);
    62 bool              psastroMosaicSetAstrom (pmFPA *fpa);
    63 bool              psastroMosaicHeaders (pmConfig *config);
    64 bool              psastroMosaicRescaleChips (pmFPA *fpa);
    65 bool              psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration);
     59bool              psastroMosaicDistortion (pmFPA *fpa, psMetadata *recipe, int pass);
     60psPlaneTransform *psastroMosaicFitRotAndScale (pmFPA *fpa);
     61bool              psastroMosaicApplyRotAndScale (pmFPA *fpa, psPlaneTransform *TPtoFP);
     62bool              psastroMosaicDistortionFromGradients (pmFPA *fpa, psMetadata *recipe);
     63bool              psastroMosaicCorrectDistortion (pmFPA *fpa, psPlaneTransform *TPtoFP);
     64bool              psastroMosaicCommonScale (pmFPA *fpa, psMetadata *recipe);
     65bool              psastroMosaicAstrom (pmConfig *config);
     66bool              psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe, int iteration);
     67bool              psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe, int iteration);
     68bool              psastroMosaicSetAstrom (pmFPA *fpa);
     69bool              psastroMosaicHeaders (pmConfig *config);
     70bool              psastroMosaicRescaleChips (pmFPA *fpa);
     71bool              psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration);
    6672
    6773// Return version strings.
    68 psString          psastroVersion(void);
    69 psString          psastroVersionLong(void);
     74psString          psastroVersion(void);
     75psString          psastroVersionLong(void);
    7076
    7177// demo plots
    72 bool              psastroPlotRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe);
    73 bool              psastroPlotRefstars (psArray *refstars, psMetadata *recipe);
    74 bool              psastroPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);
     78bool              psastroPlotRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe);
     79bool              psastroPlotRefstars (psArray *refstars, psMetadata *recipe);
     80bool              psastroPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);
    7581
    76 bool              psastroDumpRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip);
    77 bool              psastroDumpRefstars (psArray *refstars, char *filename);
    78 bool              psastroDumpMatches (pmFPA *fpa, char *filename);
    79 bool              psastroDumpStars (psArray *stars, char *filename);
     82bool              psastroDumpRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip);
     83bool              psastroDumpRefstars (psArray *refstars, char *filename);
     84bool              psastroDumpMatches (pmFPA *fpa, char *filename);
     85bool              psastroDumpStars (psArray *stars, char *filename);
    8086bool              psastroDumpMatchedStars (char *filename, psArray *rawstars, psArray *refstars, psArray *match);
    8187bool              psastroDumpGradients (psArray *gradients, char *filename);
    8288
    83 bool              psastroMosaicSetAstrom_tmp (pmFPA *fpa);
    84 int               psastroSortByMag (const void *a, const void *b);
     89bool              psastroMosaicSetAstrom_tmp (pmFPA *fpa);
     90int               psastroSortByMag (const void *a, const void *b);
    8591
    8692bool              psastroFixChips (pmConfig *config, psMetadata *recipe);
    8793bool              psastroFixChipsTest (pmConfig *config, psMetadata *recipe);
    8894bool              psastroUseModel (pmConfig *config, psMetadata *recipe);
    89 bool              psastroDumpCorners (char *filename, pmFPA *fpa);
     95bool              psastroDumpCorners (char *filenameU, char *filenameD, pmFPA *fpa);
    9096
    9197
  • branches/cnb_branch_20080830/psastro/src/psastroAnalysis.c

    r19300 r20033  
    6363        chipastro = true;
    6464    }
    65 
    6665    if (chipastro) {
    6766        if (!psastroChipAstrom (config)) {
     
    8180    // psastroZeroPoint (config);
    8281
     82    psastroAstromGuessCheck (config);
     83
    8384    // XXX how do we specify stack astrometry?
    8485    // psastroStackAstrom (config, refs);
  • branches/cnb_branch_20080830/psastro/src/psastroArguments.c

    r18007 r20033  
    8181    }
    8282
     83    // dump the configuration to a file?
     84    if ((N = psArgumentGet (argc, argv, "-dumpconfig"))) {
     85        psArgumentRemove (N, &argc, argv);
     86        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "DUMP_CONFIG", PS_META_REPLACE, "", argv[N]);
     87        psArgumentRemove (N, &argc, argv);
     88    }
     89
    8390    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
    8491    if (!status) {
  • branches/cnb_branch_20080830/psastro/src/psastroAstromGuess.c

    r17933 r20033  
    11# include "psastroInternal.h"
     2# define DEBUG 0
    23
    34// this function loads the header WCS astrometry terms into the fpa terms and applies the
     
    2829    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);
    2930    if (!recipe) {
    30         psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!");
    31         return false;
     31        psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!");
     32        return false;
    3233    }
    3334
     
    3536    bool useModel = psMetadataLookupBool (&status, config->arguments, "PSASTRO.USE.MODEL");
    3637    if (!status) {
    37         useModel = psMetadataLookupBool (&status, recipe, "PSASTRO.USE.MODEL");
     38        useModel = psMetadataLookupBool (&status, recipe, "PSASTRO.USE.MODEL");
    3839    }
    3940
     
    4142    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
    4243    if (!input) {
    43         psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
    44         return false;
     44        psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
     45        return false;
    4546    }
    4647
     
    4849    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
    4950    if (!status) {
    50         psError(PS_ERR_IO, true, "Failed to lookup pixel scale");
    51         return false;
    52     }
     51        psError(PS_ERR_IO, true, "Failed to lookup pixel scale");
     52        return false;
     53    }
     54
     55    psVector *cornerL = psVectorAllocEmpty (100, PS_TYPE_F32);
     56    psVector *cornerM = psVectorAllocEmpty (100, PS_TYPE_F32);
     57    psVector *cornerP = psVectorAllocEmpty (100, PS_TYPE_F32);
     58    psVector *cornerQ = psVectorAllocEmpty (100, PS_TYPE_F32);
     59    psVector *cornerR = psVectorAllocEmpty (100, PS_TYPE_F32);
     60    psVector *cornerD = psVectorAllocEmpty (100, PS_TYPE_F32);
    5361
    5462    pmFPA *fpa = input->fpa;
     63
     64    if (DEBUG) psastroDumpCorners ("corners.up.guess1.dat", "corners.dn.guess1.dat", fpa);
    5565
    5666    // load mosaic-level astrometry?
    5767    bool bilevelAstrometry = false;
    5868    if (!useModel) {
    59         psastroAstromGuessSetFPA (fpa, &bilevelAstrometry);
     69        psastroAstromGuessSetFPA (fpa, &bilevelAstrometry);
    6070    }
    6171
     
    6575        if (!chip->process || !chip->file_exists || !chip->data_exists) { continue; }
    6676
    67         if (!useModel) {
    68             if (!psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry)) continue;
    69         }
     77        if (!useModel) {
     78            if (!psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry)) continue;
     79        }
    7080
    7181        if (newFPA) {
    7282            newFPA = false;
    73             while (fpa->toSky->R <        0) fpa->toSky->R += 2.0*M_PI;
    74             while (fpa->toSky->R > 2.0*M_PI) fpa->toSky->R -= 2.0*M_PI;
     83            while (fpa->toSky->R <        0) fpa->toSky->R += 2.0*M_PI;
     84            while (fpa->toSky->R > 2.0*M_PI) fpa->toSky->R -= 2.0*M_PI;
    7585            RAminSky = fpa->toSky->R - M_PI;
    7686            RAmaxSky = fpa->toSky->R + M_PI;
     87        }
     88
     89        // report and save the current best guess for the chip 0,0 pixel coordinates
     90        {
     91            psPlane ptCH, ptFP, ptTP;
     92            psSphere ptSky;
     93
     94            ptCH.x = 0;
     95            ptCH.y = 0;
     96            psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
     97            psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
     98            psDeproject (&ptSky, &ptTP, fpa->toSky);
     99            psLogMsg ("psastro", 3, "0,0 pix for chip %3d = %f,%f\n", view->chip, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d);
     100
     101            psVectorAppend (cornerL, ptFP.x);
     102            psVectorAppend (cornerM, ptFP.y);
     103            psVectorAppend (cornerP, ptTP.x);
     104            psVectorAppend (cornerQ, ptTP.y);
     105            psVectorAppend (cornerR, ptSky.r);
     106            psVectorAppend (cornerD, ptSky.d);
    77107        }
    78108
     
    86116                if (! readout->data_exists) { continue; }
    87117
    88                 // report the current best guess for the cell 0,0 pixel coordinate
    89                 {
    90                   psPlane ptCH, ptFP, ptTP;
    91                   psSphere ptSky;
    92 
    93                   ptCH.x = 0;
    94                   ptCH.y = 0;
    95                   psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
    96                   psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    97                   psDeproject (&ptSky, &ptTP, fpa->toSky);
    98                   psLogMsg ("psastro", 2, "0,0 pix for chip,cell %d,%d = %f,%f\n", view->chip, view->cell, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d);
    99                 }
    100 
    101118                psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
    102119                if (rawstars == NULL) { continue; }
    103120
    104                 *nStars += rawstars->n;
     121                *nStars += rawstars->n;
    105122                for (int i = 0; i < rawstars->n; i++) {
    106123                    pmAstromObj *raw = rawstars->data[i];
     
    121138                }
    122139
    123                 // dump or plot the resulting projected positions
    124                 if (psTraceGetLevel("psastro.dump") > 0) {
    125                     psastroDumpRawstars (rawstars, fpa, chip);
    126                 }
    127 
    128                 if (psTraceGetLevel("psastro.plot") > 0) {
    129                     psastroPlotRawstars (rawstars, fpa, chip, recipe);
    130                 }
     140                // dump or plot the resulting projected positions
     141                if (psTraceGetLevel("psastro.dump") > 0) {
     142                    psastroDumpRawstars (rawstars, fpa, chip);
     143                }
     144
     145                if (psTraceGetLevel("psastro.plot") > 0) {
     146                    psastroPlotRawstars (rawstars, fpa, chip, recipe);
     147                }
    131148            }
    132149        }
    133150    }
     151
     152    if (DEBUG) psastroDumpCorners ("corners.up.guess2.dat", "corners.dn.guess2.dat", fpa);
    134153
    135154    // how many total sources are available to us?
    136155    psMetadataAddS32 (recipe, PS_LIST_TAIL, "NTOTSTAR",  PS_META_REPLACE, "", *nStars);
    137156    if (*nStars == 0) {
    138         psLogMsg ("psastro", 2, "no sources available for astrometry\n");
    139         psFree (view);
    140         return true;
    141     }
    142 
    143     psLogMsg ("psastro", 2, "loaded raw data from %f,%f to %f,%f\n", 
    144               DEG_RAD*RAmin, DEG_RAD*DECmin,
    145               DEG_RAD*RAmax, DEG_RAD*DECmax);
     157        psLogMsg ("psastro", 2, "no sources available for astrometry\n");
     158        psFree (view);
     159        return true;
     160    }
     161
     162    psLogMsg ("psastro", 2, "loaded raw data from %f,%f to %f,%f\n",
     163              DEG_RAD*RAmin, DEG_RAD*DECmin,
     164              DEG_RAD*RAmax, DEG_RAD*DECmax);
    146165
    147166    psMetadataAddF32 (recipe, PS_LIST_TAIL, "RA_MIN",  PS_META_REPLACE, "", RAmin);
     
    149168    psMetadataAddF32 (recipe, PS_LIST_TAIL, "DEC_MIN", PS_META_REPLACE, "", DECmin);
    150169    psMetadataAddF32 (recipe, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", DECmax);
     170
     171    psMetadataAddVector (input->fpa->analysis, PS_LIST_TAIL, "CORNER.L", PS_META_REPLACE, "corner pixel", cornerL);
     172    psMetadataAddVector (input->fpa->analysis, PS_LIST_TAIL, "CORNER.M", PS_META_REPLACE, "corner pixel", cornerM);
     173    psMetadataAddVector (input->fpa->analysis, PS_LIST_TAIL, "CORNER.P", PS_META_REPLACE, "corner pixel", cornerP);
     174    psMetadataAddVector (input->fpa->analysis, PS_LIST_TAIL, "CORNER.Q", PS_META_REPLACE, "corner pixel", cornerQ);
     175    psMetadataAddVector (input->fpa->analysis, PS_LIST_TAIL, "CORNER.R", PS_META_REPLACE, "corner pixel", cornerR);
     176    psMetadataAddVector (input->fpa->analysis, PS_LIST_TAIL, "CORNER.D", PS_META_REPLACE, "corner pixel", cornerD);
     177
     178    psFree (cornerL);
     179    psFree (cornerM);
     180    psFree (cornerP);
     181    psFree (cornerQ);
     182    psFree (cornerR);
     183    psFree (cornerD);
    151184
    152185    psFree (view);
     
    168201    pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
    169202    if (bilevelAstrometry) {
    170         if (!pmAstromReadBilevelChip (chip, hdu->header)) {
    171             psWarning("Could not get WCS information from header for chip %d, skipping", view->chip);
    172             return false;
    173         }
     203        if (!pmAstromReadBilevelChip (chip, hdu->header)) {
     204            psWarning("Could not get WCS information from header for chip %d, skipping", view->chip);
     205            return false;
     206        }
    174207    } else {
    175         if (!pmAstromReadWCS (fpa, chip, hdu->header, pixelScale)) {
    176             psWarning("Could not get WCS information from header for chip %d, skipping", view->chip);
    177             return false;
    178         }
     208        if (!pmAstromReadWCS (fpa, chip, hdu->header, pixelScale)) {
     209            psWarning("Could not get WCS information from header for chip %d, skipping", view->chip);
     210            return false;
     211        }
    179212    }
    180213    return true;
     
    190223    // load mosaic-level astrometry?
    191224    if (phu) {
    192         char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
    193         if (ctype) {
    194             *bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
    195         }
     225        char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
     226        if (ctype) {
     227            *bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
     228        }
    196229    }
    197230    if (*bilevelAstrometry) {
    198         pmAstromReadBilevelMosaic (fpa, phu->header);
    199     } 
     231        pmAstromReadBilevelMosaic (fpa, phu->header);
     232    }
    200233    psFree (view);
    201234    return true;
    202235}
     236
     237// we made a guess at the beginning; how does the guess compare with the result?
     238bool psastroAstromGuessCheck (pmConfig *config) {
     239
     240    bool status;
     241
     242    // select the input data sources
     243    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     244    if (!input) {
     245        psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
     246        return false;
     247    }
     248
     249    pmFPA *fpa = input->fpa;
     250
     251    psVector *cornerLo = psMetadataLookupPtr (&status, input->fpa->analysis, "CORNER.L");
     252    psVector *cornerMo = psMetadataLookupPtr (&status, input->fpa->analysis, "CORNER.M");
     253    psVector *cornerPo = psMetadataLookupPtr (&status, input->fpa->analysis, "CORNER.P");
     254    psVector *cornerQo = psMetadataLookupPtr (&status, input->fpa->analysis, "CORNER.Q");
     255    psVector *cornerRo = psMetadataLookupPtr (&status, input->fpa->analysis, "CORNER.R");
     256    psVector *cornerDo = psMetadataLookupPtr (&status, input->fpa->analysis, "CORNER.D");
     257
     258    if (cornerLo->n < 3) return true;
     259
     260    psVector *cornerLn = psVectorAllocEmpty (100, PS_TYPE_F32);
     261    psVector *cornerMn = psVectorAllocEmpty (100, PS_TYPE_F32);
     262    psVector *cornerPn = psVectorAllocEmpty (100, PS_TYPE_F32);
     263    psVector *cornerQn = psVectorAllocEmpty (100, PS_TYPE_F32);
     264    psVector *cornerRn = psVectorAllocEmpty (100, PS_TYPE_F32);
     265    psVector *cornerDn = psVectorAllocEmpty (100, PS_TYPE_F32);
     266
     267    if (DEBUG) psastroDumpCorners ("corners.up.guess3.dat", "corners.dn.guess3.dat", fpa);
     268
     269    pmChip *chip = NULL;
     270    pmFPAview *view = pmFPAviewAlloc (0);
     271
     272    while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
     273        if (!chip->process || !chip->file_exists || !chip->data_exists) { continue; }
     274
     275        psPlane ptCH, ptFP, ptTP;
     276        psSphere ptSky;
     277
     278        ptCH.x = 0;
     279        ptCH.y = 0;
     280        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
     281        psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
     282        psDeproject (&ptSky, &ptTP, fpa->toSky);
     283        psLogMsg ("psastro", 3, "0,0 pix for chip %3d = %f,%f\n", view->chip, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d);
     284
     285        // new corner locations based on the calibrated astrometry
     286        psVectorAppend (cornerLn, ptFP.x);
     287        psVectorAppend (cornerMn, ptFP.y);
     288        psVectorAppend (cornerPn, ptTP.x);
     289        psVectorAppend (cornerQn, ptTP.y);
     290        psVectorAppend (cornerRn, ptSky.r);
     291        psVectorAppend (cornerDn, ptSky.d);
     292    }
     293
     294    // compare the old R,D values projected to the same tangent plane as the new R,D values:
     295
     296    psVector *cornerPs = psVectorAllocEmpty (100, PS_TYPE_F32);
     297    psVector *cornerQs = psVectorAllocEmpty (100, PS_TYPE_F32);
     298
     299    for (int i = 0; i < cornerRo->n; i++) {
     300
     301        psPlane ptTP;
     302        psSphere ptSky;
     303
     304        ptSky.r = cornerRo->data.F32[i];
     305        ptSky.d = cornerDo->data.F32[i];
     306
     307        psProject (&ptTP, &ptSky, fpa->toSky);
     308        psVectorAppend (cornerPs, ptTP.x);
     309        psVectorAppend (cornerQs, ptTP.y);
     310    }
     311
     312    psPlaneTransform *map = psPlaneTransformAlloc (1, 1);
     313    map->x->coeffMask[1][1] = PS_POLY_MASK_SET;
     314    map->y->coeffMask[1][1] = PS_POLY_MASK_SET;
     315
     316    psVectorFitPolynomial2D (map->x, NULL, 0, cornerPn, NULL, cornerPs, cornerQs);
     317    psVectorFitPolynomial2D (map->y, NULL, 0, cornerQn, NULL, cornerPs, cornerQs);
     318
     319    // apply the linear fit...
     320    psVector *cornerPf = psPolynomial2DEvalVector (map->x, cornerPs, cornerQs);
     321    psVector *cornerQf = psPolynomial2DEvalVector (map->y, cornerPs, cornerQs);
     322
     323    // ...and calculate the residual between Pn,Qn and Pf,Qf
     324    psVector *cornerPd = (psVector *) psBinaryOp (NULL, cornerPn, "-", cornerPf);
     325    psVector *cornerQd = (psVector *) psBinaryOp (NULL, cornerQn, "-", cornerQf);
     326
     327    psStats *statsP = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
     328    psStats *statsQ = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
     329
     330    psVectorStats (statsP, cornerPd, NULL, NULL, 0);
     331    psVectorStats (statsQ, cornerQd, NULL, NULL, 0);
     332
     333    float angle = atan2 (map->y->coeff[1][0], map->x->coeff[1][0]);
     334    float scale = hypot (map->y->coeff[1][0], map->x->coeff[1][0]);
     335
     336    psLogMsg ("psastro", 3, "boresite offset  : %f,%f\n", map->x->coeff[0][0], map->y->coeff[0][0]);
     337    psLogMsg ("psastro", 3, "boresite angle   : %f, scale: %f", angle*PS_DEG_RAD, scale);
     338    psLogMsg ("psastro", 3, "boresite scatter : %f,%f\n", statsP->sampleStdev, statsQ->sampleStdev);
     339
     340    // write the elapsed time here; this will be updated in psastroMosaicAstrometry, if called
     341    psMetadata *header = psMetadataLookupMetadata (&status, input->fpa->analysis, "PSASTRO.HEADER");
     342    if (!header) {
     343        header = psMetadataAlloc();
     344        psMetadataAddMetadata (input->fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER",  PS_META_REPLACE, "psastro header stats", header);
     345        psFree (header);  // drop this reference
     346    }
     347
     348    psMetadataAddF32 (header, PS_LIST_TAIL, "AST_R0", PS_META_REPLACE, "boresite offset in RA (TP units)", map->x->coeff[0][0]);
     349    psMetadataAddF32 (header, PS_LIST_TAIL, "AST_D0", PS_META_REPLACE, "boresite offset in DEC (TP units)", map->y->coeff[0][0]);
     350    psMetadataAddF32 (header, PS_LIST_TAIL, "AST_T0", PS_META_REPLACE, "boresite angle (degrees)", angle*PS_DEG_RAD);
     351    psMetadataAddF32 (header, PS_LIST_TAIL, "AST_S0", PS_META_REPLACE, "boresite scale correction", scale);
     352    psMetadataAddF32 (header, PS_LIST_TAIL, "AST_RS", PS_META_REPLACE, "boresite scatter in RA (TP units)", statsP->sampleStdev);
     353    psMetadataAddF32 (header, PS_LIST_TAIL, "AST_DS", PS_META_REPLACE, "boresite scatter in DEC (TP units)", statsQ->sampleStdev);
     354
     355    if (0) {
     356        FILE *f = fopen ("corners.dat", "w");
     357        for (int i = 0; i < cornerRo->n; i++) {
     358            fprintf (f, "%10.6f %10.6f  %9.2f %9.2f  %9.2f %9.2f  |  %10.6f %10.6f  %9.2f %9.2f  %9.2f %9.2f\n",
     359                     cornerRn->data.F32[i], cornerDn->data.F32[i], cornerPn->data.F32[i], cornerQn->data.F32[i], cornerLn->data.F32[i], cornerMn->data.F32[i],
     360                     cornerRo->data.F32[i], cornerDo->data.F32[i], cornerPo->data.F32[i], cornerQo->data.F32[i], cornerLo->data.F32[i], cornerMo->data.F32[i]);
     361        }
     362        fclose (f);
     363    }
     364
     365    psFree (cornerPf);
     366    psFree (cornerQf);
     367    psFree (cornerPd);
     368    psFree (cornerQd);
     369
     370    psFree (statsP);
     371    psFree (statsQ);
     372
     373    psFree (cornerLn);
     374    psFree (cornerMn);
     375    psFree (cornerPn);
     376    psFree (cornerQn);
     377    psFree (cornerRn);
     378    psFree (cornerDn);
     379    psFree (cornerPs);
     380    psFree (cornerQs);
     381    psFree (map);
     382    psFree (view);
     383
     384
     385    return true;
     386}
  • branches/cnb_branch_20080830/psastro/src/psastroChipAstrom.c

    r19300 r20033  
    115115    }
    116116
    117     // psastroDumpCorners ("corners.chipAstrom.dat", input->fpa);
    118 
    119 # if (0)
    120     if (!psastroFixChipsTest (config, recipe)) {
    121         psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips");
    122         return false;
    123     }
    124 # endif
    125 
    126117    if (!psastroFixChips (config, recipe)) {
    127118        psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips");
    128119        return false;
    129120    }
    130 
    131     // psastroDumpCorners ("corners.fixChips.dat", input->fpa);
    132121
    133122    psFree (view);
  • branches/cnb_branch_20080830/psastro/src/psastroChooseRefstars.c

    r19300 r20033  
    5151        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    5252        if (!chip->process || !chip->file_exists) { continue; }
    53         if (!chip->fromFPA) { continue; }
     53        if (!chip->fromFPA) { continue; }
    5454
    5555        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
     
    6262                if (! readout->data_exists) { continue; }
    6363
    64                 psRegion *extent = pmReadoutExtent (readout);
    65                 if (!extent) {
    66                     psError(PSASTRO_ERR_CONFIG, true, "Can't find readout size!\n");
    67                     return NULL;
    68                 }
     64                psRegion *extent = pmReadoutExtent (readout);
     65                if (!extent) {
     66                    psError(PSASTRO_ERR_CONFIG, true, "Can't find readout size!\n");
     67                    return NULL;
     68                }
    6969
    70                 int Nx = abs(extent->x1 - extent->x0);
    71                 int Ny = abs(extent->y1 - extent->y0);
     70                int Nx = abs(extent->x1 - extent->x0);
     71                int Ny = abs(extent->y1 - extent->y0);
    7272
    7373                float minX = -fieldPadding*Nx;
     
    9898                    psFree (ref);
    9999
    100                     if (nMax && (refstars->n >= nMax)) break;
     100                    if (nMax && (refstars->n >= nMax)) break;
    101101                }
    102102                psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);
    103103
    104                 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars);
    105                 psFree (refstars);
    106                 psFree (extent);
     104                psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars);
     105                psFree (refstars);
     106                psFree (extent);
    107107
    108                 if (matchLumFunc) {
    109                     // in this case, no PSASTRO.REFSTARS is added to readout->analysis
    110                     if (!psastroRefstarSubset (readout)) {
    111                         psError(PSASTRO_ERR_DATA, false, "Can't determine an appropriate refstar subset\n");
    112                         psFree (index);
    113                         psFree (view);
    114                         return false;
    115                     }
    116                 }
     108                if (matchLumFunc) {
     109                    // in this case, no PSASTRO.REFSTARS is added to readout->analysis
     110                    if (!psastroRefstarSubset (readout)) {
     111                        psError(PSASTRO_ERR_DATA, false, "Can't determine an appropriate refstar subset\n");
     112                        psFree (index);
     113                        psFree (view);
     114                        return false;
     115                    }
     116                }
    117117            }
    118118        }
    119         if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
     119        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
    120120    }
    121121    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
  • branches/cnb_branch_20080830/psastro/src/psastroDemoDump.c

    r16073 r20033  
    128128        if (!chip->process || !chip->file_exists) continue;
    129129       
     130        char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");
     131
    130132        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    131133            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     
    153155
    154156                    pmAstromObj *raw = rawstars->data[match->raw];
    155                     fprintf (f, "%f %f  %f %f  %f %f  %f %f  %f   |   ", 
    156                              DEG_RAD*raw->sky->r, DEG_RAD*raw->sky->d,
     157                    fprintf (f, "%s  %f %f  %f %f  %f %f  %f %f  %f   |   ", 
     158                             chipName, DEG_RAD*raw->sky->r, DEG_RAD*raw->sky->d,
    157159                             raw->TP->x, raw->TP->y,
    158160                             raw->FP->x, raw->FP->y,
     
    193195}
    194196
    195 bool psastroDumpCorners (char *filename, pmFPA *fpa) {
     197bool psastroDumpCorners (char *filenameU, char *filenameD, pmFPA *fpa) {
    196198
    197199  // XXX test output of chip corners based on model
    198   FILE *f = fopen (filename, "w");
     200  FILE *fu = fopen (filenameU, "w");
     201  FILE *fd = fopen (filenameD, "w");
    199202
    200203  pmFPAview *view = pmFPAviewAlloc (0);
     204
     205  float fpaAngle = PM_DEG_RAD * atan2 (fpa->toTPA->y->coeff[1][0], fpa->toTPA->x->coeff[1][0]);
     206
     207  fprintf (fu, "# boresite: %f, %f @ %f\n", fpa->toSky->R*PS_DEG_RAD, fpa->toSky->D*PS_DEG_RAD, fpaAngle);
     208  fprintf (fd, "# boresite: %f, %f @ %f\n", fpa->toSky->R*PS_DEG_RAD, fpa->toSky->D*PS_DEG_RAD, fpaAngle);
    201209
    202210  pmChip *chip = NULL;
     
    209217        psSphere ptSky;
    210218
     219        // UP 0,0
    211220        ptCP.x = region->x0; ptCP.y = region->y0;
    212221        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCP);
    213222        psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    214223        psDeproject (&ptSky, &ptTP, fpa->toSky);
    215         fprintf (f, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
    216 
     224        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     225
     226        // DOWN 0,0
     227        psProject (&ptTP, &ptSky, fpa->toSky);
     228        psPlaneTransformApply (&ptFP, fpa->fromTPA, &ptTP);
     229        psPlaneTransformApply (&ptCP, chip->fromFPA, &ptFP);
     230        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     231
     232        // UP 1,0
    217233        ptCP.x = region->x1; ptCP.y = region->y0;
    218234        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCP);
    219235        psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    220236        psDeproject (&ptSky, &ptTP, fpa->toSky);
    221         fprintf (f, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
    222 
     237        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     238        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     239
     240        // DOWN 1,0
     241        psProject (&ptTP, &ptSky, fpa->toSky);
     242        psPlaneTransformApply (&ptFP, fpa->fromTPA, &ptTP);
     243        psPlaneTransformApply (&ptCP, chip->fromFPA, &ptFP);
     244        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     245        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     246
     247        // UP 1,1
    223248        ptCP.x = region->x1; ptCP.y = region->y1;
    224249        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCP);
    225250        psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    226251        psDeproject (&ptSky, &ptTP, fpa->toSky);
    227         fprintf (f, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
    228 
     252        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     253        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     254
     255        // DOWN 1,1
     256        psProject (&ptTP, &ptSky, fpa->toSky);
     257        psPlaneTransformApply (&ptFP, fpa->fromTPA, &ptTP);
     258        psPlaneTransformApply (&ptCP, chip->fromFPA, &ptFP);
     259        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     260        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     261
     262        // UP 0,1
    229263        ptCP.x = region->x0; ptCP.y = region->y1;
    230264        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCP);
    231265        psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    232266        psDeproject (&ptSky, &ptTP, fpa->toSky);
    233         fprintf (f, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
    234 
     267        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     268        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     269
     270        // DOWN 0,1
     271        psProject (&ptTP, &ptSky, fpa->toSky);
     272        psPlaneTransformApply (&ptFP, fpa->fromTPA, &ptTP);
     273        psPlaneTransformApply (&ptCP, chip->fromFPA, &ptFP);
     274        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     275        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     276
     277        // UP 0,0
    235278        ptCP.x = region->x0; ptCP.y = region->y0;
    236279        psPlaneTransformApply (&ptFP, chip->toFPA, &ptCP);
    237280        psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    238281        psDeproject (&ptSky, &ptTP, fpa->toSky);
    239         fprintf (f, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     282        fprintf (fu, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
     283
     284        // DOWN 0,0
     285        psProject (&ptTP, &ptSky, fpa->toSky);
     286        psPlaneTransformApply (&ptFP, fpa->fromTPA, &ptTP);
     287        psPlaneTransformApply (&ptCP, chip->fromFPA, &ptFP);
     288        fprintf (fd, "%10.6f %10.6f  %8.1f %8.1f  %8.1f %8.1f  %8.1f %8.1f\n", ptSky.r, ptSky.d, ptTP.x, ptTP.y, ptFP.x, ptFP.y, ptCP.x, ptCP.y);
    240289
    241290        psFree (region);
    242291  }
    243292
    244   fclose (f);
     293  fclose (fu);
     294  fclose (fd);
    245295  psFree (view);
    246296  return true;
  • branches/cnb_branch_20080830/psastro/src/psastroDemoPlot.c

    r19300 r20033  
    101101    }
    102102    xVec->n = yVec->n = zVec->n = n;
     103
    103104    pmKapaPlotVectorTriple_AutoLimits_OpenGraph (kapa, &graphdata, xVec, yVec, zVec, false);
    104105
     
    124125    xVec->n = yVec->n = zVec->n = n;
    125126    pmKapaPlotVectorTriple_AutoLimits_OpenGraph (kapa, &graphdata, xVec, yVec, zVec, false);
     127
     128    // flip x (East increase to left)
     129    SWAP (graphdata.xmin, graphdata.xmax);
     130    KapaSetLimits (kapa, &graphdata);
    126131
    127132    // pause and wait for user input:
     
    189194    pmKapaPlotVectorTriple_AutoLimits_OpenGraph (kapa, &graphdata, xVec, yVec, zVec, false);
    190195
     196    // flip x (East increase to left)
     197    SWAP (graphdata.xmin, graphdata.xmax);
     198    KapaSetLimits (kapa, &graphdata);
     199
    191200    // pause and wait for user input:
    192201    // continue, save (provide name), ??
  • branches/cnb_branch_20080830/psastro/src/psastroModelAdjust.c

    r15891 r20033  
    11# include "psastroStandAlone.h"
    22# define NONLIN_TOL 0.001 /* tolerance in pixels */
     3# define DEBUG 0
     4
     5bool psastroModelAdjustBoresite (pmFPAfile *output, pmChip *refChip);
    36
    47bool psastroModelAdjust (pmConfig *config) {
     
    1316    }
    1417
     18    // if we have not measured the boresite position, no adjustment is needed
     19    bool fitBoresite = psMetadataLookupBool (&status, recipe, "PSASTRO.MODEL.FIT.BORESITE");
     20    if (!status) psAbort ("Can't find recipe option PSASTRO.MODEL.FIT.BORESITE");
     21
     22    // as an alternative to fit the boresite from a rotation sequence, we can set the boresite
     23    // relative to the reference chip coordinates
     24    bool setBoresite = psMetadataLookupBool (&status, recipe, "PSASTRO.MODEL.SET.BORESITE");
     25    if (!status) psAbort ("Can't find recipe option PSASTRO.MODEL.SET.BORESITE");
     26
     27    if (fitBoresite && setBoresite) {
     28        psError(PS_ERR_IO, true, "invalid to choose both FIT.BORESITE and SET.BORESITE");
     29        return false;
     30    }
     31       
    1532    pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSASTRO.OUT.MODEL");
    1633    if (!status) psAbort ("Can't find output pmFPAfile PSASTRO.OUT.MODEL");
     
    2946    if (!refChip->toFPA) psAbort ("invalid astrometry for reference chip");
    3047
    31     psPlane *boreCH = psPlaneAlloc();
    32     psPlane *boreFP = psPlaneAlloc();   
    33     psPlane *boreTP = psPlaneAlloc();   
     48    // save the TPA region for tranformation inversions below
     49    // psRegion *tpaRegion = pmAstromFPInTP (output->fpa);
     50    psRegion *fpaRegion = pmAstromFPAExtent (output->fpa);
     51
     52    if (DEBUG) psastroDumpCorners ("corners.up.raw.dat", "corners.dn.raw.dat", output->fpa);
     53
     54    if (setBoresite) {
     55        float boreXchip = psMetadataLookupF32 (&status, recipe, "PSASTRO.MODEL.BORESITE.X");
     56        float boreYchip = psMetadataLookupF32 (&status, recipe, "PSASTRO.MODEL.BORESITE.Y");
     57        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", boreXchip);
     58        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.Y0", PS_META_REPLACE, "boresite parameter", boreYchip);
     59    }
     60
     61    if (fitBoresite || setBoresite) {
     62        psastroModelAdjustBoresite (output, refChip);
     63    } else {
     64        // FPA.BORE.X0,Y0 should be 0,0 in the focal plane, not the chip.  Ask for the
     65        // coordinates which make refChip->toFPA(x,y) = (0,0)
     66        psPlane *PT = psPlaneTransformGetCenter (refChip->toFPA, NONLIN_TOL);
     67        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", PT->x);
     68        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.Y0", PS_META_REPLACE, "boresite parameter", PT->y);
     69        psFree (PT);
     70    }
     71
     72    // rotate the chip-to-FPA transforms to have 0.0 posangle for refChip;
     73    // compensate by rotating fpa to TPA transform
     74
     75    // get the current posangle of the ref chip
     76    float chipAngle = atan2 (refChip->toFPA->y->coeff[1][0], refChip->toFPA->x->coeff[1][0]);
     77    fprintf (stderr, "chipAngle: %f\n", chipAngle*PS_DEG_RAD);
     78    // psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POSANGLE", PS_META_REPLACE, "boresite parameter", posangle);
     79
     80    // rotate the chip transforms
     81    for (int i = 0; i < output->fpa->chips->n; i++) {
     82        pmChip *chip = output->fpa->chips->data[i];
     83        if (!chip->toFPA) continue;
     84        // skip chips without astrometry
     85
     86        // save the region of this chip for the inversion below
     87        psRegion *region = pmChipPixels (chip);
     88
     89        psPlaneTransform *toFPA = psPlaneTransformRotate (NULL, chip->toFPA, chipAngle);
     90        psFree (chip->toFPA);
     91        chip->toFPA = toFPA;
     92
     93        // invert the new fromFPA transform to get the new toFPA transform
     94        psPlaneTransform *fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
     95        psFree (chip->fromFPA);
     96        chip->fromFPA = fromFPA;
     97
     98        psFree (region);
     99
     100        // save the transformation in the header
     101        pmAstromWriteBilevelChip (chip->hdu->header, chip, NONLIN_TOL);
     102    }
     103
     104    // get the current posangle of the fpa
     105    float fpaAngle = atan2 (output->fpa->toTPA->y->coeff[1][0], output->fpa->toTPA->x->coeff[1][0]);
     106    fprintf (stderr, "fpaAngle: %f\n", fpaAngle*PS_DEG_RAD);
     107    // psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POSANGLE", PS_META_REPLACE, "boresite parameter", posangle);
     108
     109    // remove the fpa rotation to generate a rotation-free model
     110    psPlaneTransform *toTPA = psPlaneTransformRotate (NULL, output->fpa->toTPA, fpaAngle);
     111    psFree (output->fpa->toTPA);
     112    output->fpa->toTPA = toTPA;
     113
     114    psFree (output->fpa->fromTPA);
     115    output->fpa->fromTPA = psPlaneTransformInvert(NULL, output->fpa->toTPA, *fpaRegion, 50);
     116
     117    // the model now describes the unrotated focal-plane
     118    if (DEBUG) psastroDumpCorners ("corners.up.rot.dat", "corners.dn.rot.dat", output->fpa);
     119
     120    psMetadata *header = output->fpa->hdu->header;
     121    pmAstromWriteBilevelMosaic (header, output->fpa, NONLIN_TOL);
     122
     123    psFree (fpaRegion);
     124
     125    return true;
     126}
     127
     128bool psastroModelAdjustBoresite (pmFPAfile *output, pmChip *refChip) {
     129
     130    bool status;
     131
     132    psPlane  *boreCH  = psPlaneAlloc();
     133    psPlane  *boreFP  = psPlaneAlloc();   
     134    psPlane  *boreTP  = psPlaneAlloc();   
    34135    psSphere *boreSky = psSphereAlloc();   
    35136
     
    46147        // skip the chips without astrometry
    47148
    48         psPlaneTransform *fromFPA = psPlaneTransformSetCenter (NULL, chip->fromFPA, boreFP->x, boreFP->y);
     149        // save the FPA region of this chip for the inversion below
     150        psRegion *region = pmChipPixels (chip);
     151
     152        // the current toFPA returns boreFP->x,y for the boresite; subtract this from the transformations
     153        chip->toFPA->x->coeff[0][0] -= boreFP->x;
     154        chip->toFPA->y->coeff[0][0] -= boreFP->y;
     155
     156        // psPlaneTransform *toFPA = psPlaneTransformSetCenter (NULL, chip->toFPA, -boreFP->x, -boreFP->y);
     157        // psFree (chip->toFPA);
     158        // chip->toFPA = toFPA;
     159
     160        // invert the new fromFPA transform to get the new toFPA transform
     161        // the region used here is the region covered by the chip in the FPA
     162        psPlaneTransform *fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
    49163        psFree (chip->fromFPA);
    50164        chip->fromFPA = fromFPA;
    51165
    52         // invert the new fromFPA transform to get the new toFPA transform
    53         psRegion *region = pmChipPixels (chip);
    54         psFree (chip->toFPA);
    55         chip->toFPA = psPlaneTransformInvert(NULL, chip->fromFPA, *region, 50);
    56166        psFree (region);
    57167    }
    58168
    59     // XXX we have now shifted the (0,0) pixel of the focal plane to the true boresite from the
    60     // reported boresite.  At this point, we need to shift the tangent plane to use the new
    61     // center as well.  if the toTPA transform were not linear, we would need to modify fromFPA
    62     // to yield 0,0 at the new boresite location (ie, find Po,Qo = toTPA(Lo,Mo), probably could modify the
    63     // toTPA/fromTPA transforms to use the new ref pixel, but this would only give us a tranf
    64 
    65     // save the old (L,M) = (0,0) TP coordinate
    66     float Po = output->fpa->toTPA->x->coeff[0][0];
    67     float Qo = output->fpa->toTPA->y->coeff[0][0];
    68 
    69     // the new toTPA yields the same TP coordinates for FP coordinates offset by Lo,Mo
    70     psPlaneTransform *toTPA = psPlaneTransformSetCenter (NULL, output->fpa->toTPA, boreFP->x, boreFP->y);
    71     psFree (output->fpa->toTPA);
    72     output->fpa->toTPA = toTPA;
    73    
    74     // we are going to shift P,Q to have toTPA(0,0) = Po, Qo. 
    75     // find the sky coordinates of the 0,0 pixel for the new frame
    76     boreTP->x = output->fpa->toTPA->x->coeff[0][0] - Po;
    77     boreTP->y = output->fpa->toTPA->y->coeff[0][0] - Qo;
     169    if (DEBUG) psastroDumpCorners ("corners.up.shf.dat", "corners.dn.shf.dat", output->fpa);
     170
     171    // we have now adjusted the chips to use the correct boresite position as the center of the focal-plane system.
     172    // we now need to reconstruct the TP to FP transformation, starting from stars projected about this new boresite position.
     173
     174    // find the R,D of the new boresite (boreFP -> 0,0; 0,0 -> -boreFP)
     175    boreFP->x = -boreFP->x;
     176    boreFP->y = -boreFP->y;
     177    psPlaneTransformApply (boreTP, output->fpa->toTPA, boreFP);
    78178    psDeproject (boreSky, boreTP, output->fpa->toSky); // find the RA,DEC coord of the focal-plane coordinate
    79179
    80     // adjust the new TP frame to yield the same old (L,M) = 0,0 TP coordinate:
    81     output->fpa->toTPA->x->coeff[0][0] = Po;
    82     output->fpa->toTPA->y->coeff[0][0] = Qo;
    83 
    84     // set the projection to use the new (P,Q) = (0,0) position
    85     output->fpa->toSky->R = boreSky->r;
    86     output->fpa->toSky->D = boreSky->d;
    87 
     180    psProjection *newSky = psProjectionAlloc (boreSky->r, boreSky->d, output->fpa->toSky->Xs, output->fpa->toSky->Ys, output->fpa->toSky->type);
     181
     182    // generate a collection of points on the sky using the old toTPA transformation and toSky projection, projected with the newSky projection
     183    // this is the FPA coordinate range covered by the FP:
    88184    psRegion *fpaRegion = pmAstromFPAExtent (output->fpa);
    89 
    90     psFree (output->fpa->fromTPA);
    91     output->fpa->fromTPA = psPlaneTransformInvert(NULL, output->fpa->toTPA, *fpaRegion, 50);
    92 
    93     // rotate the chip to FPA transforms to have 0.0 posangle;
    94     // compensate by rotating fpa to TPA transforms
    95 
    96     // get the current posangle of the ref chip
    97     float posangle = atan2 (refChip->toFPA->y->coeff[1][0], refChip->toFPA->x->coeff[1][0]);
    98     psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POSANGLE", PS_META_REPLACE, "boresite parameter", posangle);
    99 
    100     // rotate the chip transforms
    101     for (int i = 0; i < output->fpa->chips->n; i++) {
    102         pmChip *chip = output->fpa->chips->data[i];
    103         if (!chip->toFPA) continue;
    104         // skip chips without astrometry
    105 
    106         psPlaneTransform *toFPA = psPlaneTransformRotate (NULL, chip->toFPA, posangle);
    107         psFree (chip->toFPA);
    108         chip->toFPA = toFPA;
    109 
    110         // invert the new fromFPA transform to get the new toFPA transform
    111         psRegion *region = pmChipPixels (chip);
    112         psFree (chip->fromFPA);
    113         chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
    114         psFree (region);
    115 
    116         // XXX temporary output dump
    117         psMetadata *header = chip->hdu->header;
    118         // XXX to make the output single-level, this needs to be in a loop *after* the fromTPA rotation below
    119         // pmAstromWriteWCS (header, output->fpa, chip, NONLIN_TOL);
    120         pmAstromWriteBilevelChip (header, chip, NONLIN_TOL);
    121     }
    122 
    123     psPlaneTransform *fromTPA = psPlaneTransformRotate (NULL, output->fpa->fromTPA, posangle);
    124     psFree (output->fpa->fromTPA);
    125     output->fpa->fromTPA = fromTPA;
    126 
    127     psFree (output->fpa->toTPA);
    128     output->fpa->toTPA = psPlaneTransformInvert(NULL, output->fpa->fromTPA, *fpaRegion, 50);
    129 
    130     psMetadata *header = output->fpa->hdu->header;
    131     pmAstromWriteBilevelMosaic (header, output->fpa, NONLIN_TOL);
    132 
     185    float dx = (fpaRegion->x1 - fpaRegion->x0) / 50.0;
     186    float dy = (fpaRegion->y1 - fpaRegion->y0) / 50.0;
     187
     188    psPlane fp, tp;
     189    psSphere sky;
     190
     191    psVector *FPx = psVectorAllocEmpty (100, PS_TYPE_F32);
     192    psVector *FPy = psVectorAllocEmpty (100, PS_TYPE_F32);
     193    psVector *TPx = psVectorAllocEmpty (100, PS_TYPE_F32);
     194    psVector *TPy = psVectorAllocEmpty (100, PS_TYPE_F32);
     195
     196    // XXX a test: boreFP->x,y, should transform to tp.x,y = 0,0
     197    fp.x = boreFP->x;
     198    fp.y = boreFP->y;
     199    psPlaneTransformApply (&tp, output->fpa->toTPA, &fp);
     200    psDeproject (&sky, &tp, output->fpa->toSky); // find the RA,DEC coord of the focal-plane coordinate
     201    psProject (&tp, &sky, newSky); // find the RA,DEC coord of the focal-plane coordinate
     202
     203    int Npts = 0;
     204    for (fp.x = fpaRegion->x0; fp.x <= fpaRegion->x1; fp.x += dx) {
     205        for (fp.y = fpaRegion->y0; fp.y <= fpaRegion->y1; fp.y += dy) {
     206            psPlaneTransformApply (&tp, output->fpa->toTPA, &fp);
     207            psDeproject (&sky, &tp, output->fpa->toSky); // find the RA,DEC coord of the focal-plane coordinate
     208            psProject (&tp, &sky, newSky); // find the RA,DEC coord of the focal-plane coordinate
     209
     210            // we are fitting points in the NEW FP system to points in the NEW TP system
     211            FPx->data.F32[Npts] = fp.x - boreFP->x;
     212            FPy->data.F32[Npts] = fp.y - boreFP->y;
     213            TPx->data.F32[Npts] = tp.x;
     214            TPy->data.F32[Npts] = tp.y;
     215            psVectorExtend (FPx, 100, 1);
     216            psVectorExtend (FPy, 100, 1);
     217            psVectorExtend (TPx, 100, 1);
     218            psVectorExtend (TPy, 100, 1);
     219            Npts ++;
     220        }
     221    }
    133222    psFree (fpaRegion);
    134223
     224    // fit both up and down transformations to the same points
     225    psVectorFitPolynomial2D (output->fpa->toTPA->x, NULL, 0, TPx, NULL, FPx, FPy);
     226    psVectorFitPolynomial2D (output->fpa->toTPA->y, NULL, 0, TPy, NULL, FPx, FPy);
     227    psVectorFitPolynomial2D (output->fpa->fromTPA->x, NULL, 0, FPx, NULL, TPx, TPy);
     228    psVectorFitPolynomial2D (output->fpa->fromTPA->y, NULL, 0, FPy, NULL, TPx, TPy);
     229
     230    psFree (output->fpa->toSky);
     231    output->fpa->toSky = newSky;
     232
     233    if (DEBUG) psastroDumpCorners ("corners.up.bore.dat", "corners.dn.bore.dat", output->fpa);
     234
     235    psFree (FPx);
     236    psFree (FPy);
     237    psFree (TPx);
     238    psFree (TPy);
     239
     240    psFree (boreCH);
     241    psFree (boreFP);
     242    psFree (boreTP);
     243    psFree (boreSky);
    135244    return true;
    136245}
  • branches/cnb_branch_20080830/psastro/src/psastroModelAnalysis.c

    r15891 r20033  
    11# include "psastroStandAlone.h"
     2# define NONLIN_TOL 0.001
    23
    34bool psastroModelAnalysis (pmConfig *config) {
     
    1213    }
    1314
    14     pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSASTRO.OUT.MODEL");
    15     if (!status) psAbort ("Can't find output pmFPAfile PSASTRO.OUT.MODEL");
    16 
    17     // physical pixel scale in microns per pixel
     15    // reference chip for boresite parameters
    1816    char *refChip = psMetadataLookupStr (&status, recipe, "PSASTRO.MODEL.REF.CHIP");
    1917    if (!refChip) {
     
    2119        return false;
    2220    }
     21
     22    pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSASTRO.OUT.MODEL");
     23    if (!status) psAbort ("Can't find output pmFPAfile PSASTRO.OUT.MODEL");
     24
     25    // measure the boresite position from a rotation sequence?
     26    bool fitBoresite = psMetadataLookupBool (&status, recipe, "PSASTRO.MODEL.FIT.BORESITE");
     27    if (!fitBoresite) {
     28        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", 0.0);
     29        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.Y0", PS_META_REPLACE, "boresite parameter", 0.0);
     30        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.RX", PS_META_REPLACE, "boresite parameter", 0.0);
     31        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.RY", PS_META_REPLACE, "boresite parameter", 0.0);
     32        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.T0", PS_META_REPLACE, "boresite parameter", 0.0);
     33        psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.P0", PS_META_REPLACE, "boresite parameter", 0.0);
     34        psMetadataAddStr (output->fpa->concepts, PS_LIST_TAIL, "FPA.REF.CHIP", PS_META_REPLACE, "boresite parameter", refChip);
     35        return true;
     36    }
     37
     38    char *outroot = psMetadataLookupStr (&status, config->arguments, "OUTPUT");
     39    if (!status || !outroot) psAbort ("Can't find outroot on config->arguments");
    2340
    2441    /* model analysis:
     
    3552     * T_0 : reference angle for rotator
    3653     * P_0 : orientation of boresite ellipse
     54     *
    3755     */
    3856
     
    5876    output->fpa = NULL;
    5977
     78    char filename[256];
     79    snprintf (filename, 256, "%s.bore", outroot);
     80    FILE *outfile = fopen (filename, "w");
     81    if (!outfile) {
     82        psError(PSASTRO_ERR_ARGUMENTS, true, "cannot open %s for output", filename);
     83        return false;
     84    }
     85
     86    float posBoundary = 0.0;
     87
    6088    // extract the relevant measured and reported values from the reference chip
    6189    for (int i = 0; i < files->n; i++) {
     
    6391        pmFPAfile *input = file->data.V;
    6492
    65         // reported rotator position angle (this should perhaps be ROT, not POS)
     93        // reported rotator position angle
    6694        double POSANGLE = psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.POSANGLE");
    6795        if (!status) psAbort ("missing FPA.POSANGLE");
     
    7199        if (!chip) psAbort ("invalid chip name for reference");
    72100
    73         fprintf (stderr, "input %d : %zx : %zx : %zx\n", i, (size_t) input, (size_t) chip, (size_t) chip->toFPA);
    74101        if (!chip->toFPA) continue;
    75102
     
    80107
    81108        // we have two measurements of the posangle (may be parity flipped to different quadrants)
    82         float posangle = PM_DEG_RAD * atan2 (chip->toFPA->y->coeff[1][0], chip->toFPA->x->coeff[1][0]);
    83         posZero->data.F32[n] = POSANGLE - posangle;
    84         while (posZero->data.F32[n] > 360.0) posZero->data.F32[n] -= 360.0;
    85         while (posZero->data.F32[n] <   0.0) posZero->data.F32[n] += 360.0;
     109        // atan2 returns values in the range 0-2pi
     110        // all posZero values should be clustered in some region, but we need to flip over the 0,360 boundary correctly.
     111        // push all to one side or the other
     112        float chipAngle = PM_DEG_RAD * atan2 (chip->toFPA->y->coeff[1][0], chip->toFPA->x->coeff[1][0]);
     113        float fpaAngle = PM_DEG_RAD * atan2 (input->fpa->toTPA->y->coeff[1][0], input->fpa->toTPA->x->coeff[1][0]);
     114
     115        posZero->data.F32[n] = POSANGLE - chipAngle - fpaAngle;
     116        if (n == 0) {
     117            posBoundary = posZero->data.F32[n] + 180.0;
     118        } else {
     119            while (posZero->data.F32[n] > posBoundary) posZero->data.F32[n] -= 360.0;
     120            while (posZero->data.F32[n] < posBoundary - 360.0) posZero->data.F32[n] += 360.0;
     121        }
    86122
    87123        Po->data.F32[n] = POSANGLE * PM_RAD_DEG; // reported position angle
    88         Xo->data.F32[n] = chip->fromFPA->x->coeff[0][0]; // reported boresite x position in ref chip coordinates
    89         Yo->data.F32[n] = chip->fromFPA->y->coeff[0][0]; // reported boresite y position in ref chip coordinates
    90         fprintf (stderr, "%d : %f %f : %f = %f - %f\n", i, Xo->data.F32[n], Yo->data.F32[n], posZero->data.F32[n], POSANGLE, posangle);
     124        float xc = chip->fromFPA->x->coeff[0][0]; // reported boresite x position in ref chip coordinates
     125        float yc = chip->fromFPA->y->coeff[0][0]; // reported boresite y position in ref chip coordinates
     126        // XXX this can also be derived from toFPA via GetCenter....
     127       
     128        psPlane *PT = psPlaneTransformGetCenter (chip->toFPA, NONLIN_TOL);
     129        Xo->data.F32[n] = PT->x; // reported boresite x position in ref chip coordinates
     130        Yo->data.F32[n] = PT->y; // reported boresite y position in ref chip coordinates
     131        psFree (PT);
     132
     133        fprintf (outfile, "%d : %f %f : %f = %f - %f - %f | %f %f\n", i, Xo->data.F32[n], Yo->data.F32[n], posZero->data.F32[n], POSANGLE, chipAngle, fpaAngle, xc, yc);
    91134        n ++;
    92135    }
     
    100143    psVectorStats (stats, posZero, NULL, NULL, 0);
    101144
    102     fprintf (stderr, "pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
     145    fprintf (outfile, "# pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
    103146    psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POS_ZERO", PS_META_REPLACE, "offset between obs and meas posangle", stats->sampleMedian);
     147    fclose (outfile);
    104148
    105     psVector *params = psastroModelFitBoresite (Xo, Yo, Po);
     149    psVector *params = psastroModelFitBoresite (Xo, Yo, Po, outroot);
    106150    if (params->n != 6) psAbort ("error");
     151
    107152
    108153    psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_X0]);
  • branches/cnb_branch_20080830/psastro/src/psastroModelBoresite.c

    r15891 r20033  
    4545            dPAR[PAR_RY]  = +sntht*csphi;
    4646            dPAR[PAR_P0]  = -PAR[PAR_RY]*sntht*snphi - PAR[PAR_RX]*cstht*csphi;
    47             dPAR[PAR_T0]  = -PAR[PAR_RY]*sntht*csphi - PAR[PAR_RX]*cstht*snphi;
     47            dPAR[PAR_T0]  = -PAR[PAR_RY]*cstht*csphi - PAR[PAR_RX]*sntht*snphi;
    4848        }
    4949        return (value);
  • branches/cnb_branch_20080830/psastro/src/psastroModelDataSave.c

    r15891 r20033  
    11# include "psastroStandAlone.h"
     2# define NONLIN_TOL 0.001 /* tolerance in pixels */
    23
    34# define ESCAPE { \
     
    2223
    2324    pmFPAview *view = pmFPAviewAlloc (0);
     25    pmChip *chip = NULL;
    2426
    25     pmChip *chip = NULL;
    2627    while ((chip = pmFPAviewNextChip (view, output->fpa, 1)) != NULL) {
    2728        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     
    3536    return true;
    3637}
     38
     39
     40
  • branches/cnb_branch_20080830/psastro/src/psastroModelFitBoresite.c

    r15891 r20033  
    22
    33// we now have a set of observed L,M values.  fit these to the boresite model
    4 psVector *psastroModelFitBoresite (psVector *Xo, psVector *Yo, psVector *Po) {
     4psVector *psastroModelFitBoresite (psVector *Xo, psVector *Yo, psVector *Po, char *outroot) {
    55
    66    assert (Xo->n > 2);
     
    6060    params->data.F32[PAR_T0] = 0.0;
    6161
    62     psMinimization *myMin = psMinimizationAlloc (15, 0.001);
     62    psMinimization *myMin = psMinimizationAlloc (25, 0.001);
    6363    psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);
    6464   
     
    7474    psMinimizeLMChi2(myMin, covar, params, constraint, x, y, NULL, psastroModelBoresite);
    7575
    76     fprintf (stderr, "fitted values:\n");
    77     fprintf (stderr, "Xo:  %f\n", params->data.F32[PAR_X0]);
    78     fprintf (stderr, "Yo:  %f\n", params->data.F32[PAR_Y0]);
    79     fprintf (stderr, "RX:  %f\n", params->data.F32[PAR_RX]);
    80     fprintf (stderr, "RY:  %f\n", params->data.F32[PAR_RY]);
    81     fprintf (stderr, "P0:  %f\n", params->data.F32[PAR_P0]);
    82     fprintf (stderr, "T0:  %f\n", params->data.F32[PAR_T0]);
     76    char filename[256];
     77    snprintf (filename, 256, "%s.pars", outroot);
     78    FILE *outfile = fopen (filename, "w");
     79    if (!outfile) {
     80        psAbort("cannot open %s for output", filename);
     81    }
     82
     83    fprintf (outfile, "# fitted values:\n");
     84    fprintf (outfile, "Xo:  %f\n", params->data.F32[PAR_X0]);
     85    fprintf (outfile, "Yo:  %f\n", params->data.F32[PAR_Y0]);
     86    fprintf (outfile, "RX:  %f\n", params->data.F32[PAR_RX]);
     87    fprintf (outfile, "RY:  %f\n", params->data.F32[PAR_RY]);
     88    fprintf (outfile, "P0:  %f\n", params->data.F32[PAR_P0]);
     89    fprintf (outfile, "T0:  %f\n", params->data.F32[PAR_T0]);
     90    fclose (outfile);
    8391
    8492    return params;
  • branches/cnb_branch_20080830/psastro/src/psastroMosaicAstrom.c

    r16251 r20033  
    11# include "psastroInternal.h"
    22# define NONLIN_TOL 0.001 /* tolerance in pixels */
     3
     4bool psastroMosaicFit (pmFPA *fpa, psMetadata *recipe, const char *rootname, int pass);
    35
    46// XXX require this fpa to have multiple chip extensions and a PHU?
    57bool psastroMosaicAstrom (pmConfig *config) {
    68
     9    bool status;
     10    char filename[256];
     11
    712    // select the current recipe
    8     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);
     13    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
    914    if (!recipe) {
    1015        psError(PSASTRO_ERR_CONFIG, false, "Can't find PSASTRO recipe!\n");
     
    3439    # endif
    3540
    36     // given the existing per-chip astrometry, determine matches between raw and ref stars
    37     // is this needed? yes, if we didn't do SingleChip astrometry first
    38     if (!psastroMosaicSetMatch (fpa, recipe, 0)) {
    39         psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic");
    40         return false;
    41     }
    42     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.0.dat"); }
     41    char *outroot = psMetadataLookupStr (&status, config->arguments, "OUTPUT");
     42    if (!status || !outroot) psAbort ("Can't find outroot on config->arguments");
    4343
    44     // fitted chips will follow the local plate-scale, hiding the distortion
    45     // modify the chip->toFPA scaling to match knowledge about pixel scale,
    46     // then recalculate raw and ref positions
    47     if (!psastroMosaicCommonScale (fpa, recipe)) {
    48         psError(PSASTRO_ERR_UNKNOWN, false, "failed to set a common scale for the chips");
    49         return false;
    50     }
    51     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.1.dat"); }
    52 
    53     // fit the distortion by fitting its gradient
    54     // apply the new distortion terms up and down
    55     // refit the per-chip terms with linear fits only
    56     if (!psastroMosaicGradients (fpa, recipe)) {
    57         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure mosaic gradients");
    58         return false;
    59     }
    60     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.2.dat"); }
    61 
    62     // measure the astrometry for the chips under the distortion term
    63     if (!psastroMosaicChipAstrom (fpa, recipe, 0)) {
    64         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode");
    65         return false;
    66     }
    67     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.3.dat"); }
    68 
    69     // do a second pass on the distortion with improved chip positions and rotations
    70     // first, re-perform the match with a slightly tighter circle
    71     if (!psastroMosaicSetMatch (fpa, recipe, 1)) {
    72         psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (2nd pass)");
    73         return false;
    74     }
    75     if (!psastroMosaicCommonScale (fpa, recipe)) {
    76         psError(PSASTRO_ERR_UNKNOWN, false, "failed to set a common scale for the chips (2nd pass)");
    77         return false;
    78     }
    79     if (!psastroMosaicGradients (fpa, recipe)) {
    80         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure mosaic gradients (2nd pass)");
    81         return false;
    82     }
    83     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.4.dat"); }
    84 
    85     if (!psastroMosaicChipAstrom (fpa, recipe, 1)) {
    86         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (2nd pass)");
    87         return false;
    88     }
    89     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.5.dat"); }
    90 
    91     // do a third pass on the distortion with improved chip positions and rotations
    92     // first, re-perform the match with a slightly tighter circle
    93     if (!psastroMosaicSetMatch (fpa, recipe, 2)) {
    94         psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (3rd pass)");
    95         return false;
    96     }
    97     if (!psastroMosaicCommonScale (fpa, recipe)) {
    98         psError(PSASTRO_ERR_UNKNOWN, false, "failed to set a common scale for the chips (3rd pass)");
    99         return false;
    100     }
    101     if (!psastroMosaicGradients (fpa, recipe)) {
    102         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure mosaic gradients (3rd pass)");
    103         return false;
    104     }
    105     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.6.dat"); }
    106 
    107     if (!psastroMosaicChipAstrom (fpa, recipe, 2)) {
    108         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (3rd pass)");
    109         return false;
    110     }
    111     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.7.dat"); }
     44    if (!psastroMosaicFit (fpa, recipe, outroot, 0)) return false;
     45    if (!psastroMosaicFit (fpa, recipe, outroot, 1)) return false;
     46    if (!psastroMosaicFit (fpa, recipe, outroot, 2)) return false;
     47    if (!psastroMosaicFit (fpa, recipe, outroot, 3)) return false;
    11248
    11349    // now fit the chips under the common distortion with higher-order terms
    11450    // first, re-perform the match with a slightly tighter circle
    115     if (!psastroMosaicSetMatch (fpa, recipe, 3)) {
    116         psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (3rd pass)");
     51    if (!psastroMosaicSetMatch (fpa, recipe, 4)) {
     52        psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (4th pass)");
    11753        return false;
    11854    }
    119     if (!psastroMosaicChipAstrom (fpa, recipe, 3)) {
    120         psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (3rd pass)");
     55    if (!psastroMosaicChipAstrom (fpa, recipe, 4)) {
     56        psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (4th pass)");
    12157        return false;
    12258    }
    123     if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.8.dat"); }
     59    if (psTraceGetLevel("psastro.dump") > 0) {
     60        snprintf (filename, 256, "%s.10.dat", outroot);
     61        psastroDumpMatches (fpa, filename);
     62    }
    12463
    12564    // save WCS and analysis metadata in update header.
     
    15089 * sky (ra, dec)
    15190 */
     91
     92// 1: match 4,5
     93// 2: match 6,7
     94// 3: match 8,9
     95bool psastroMosaicFit (pmFPA *fpa, psMetadata *recipe, const char *rootname, int pass) {
     96
     97    char filename[256];
     98
     99    // given the existing per-chip astrometry, determine matches between raw and ref stars
     100    // is this needed? yes, if we didn't do SingleChip astrometry first
     101    if (!psastroMosaicSetMatch (fpa, recipe, pass)) {
     102        psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (pass %d)", pass);
     103        return false;
     104    }
     105
     106    if ((pass == 0) && (psTraceGetLevel("psastro.dump.psastroMosaicAstrom") > 1)) {
     107        snprintf (filename, 256, "%s.0.dat", rootname);
     108        psastroDumpMatches (fpa, filename);
     109    }
     110
     111    // fitted chips will follow the local plate-scale, hiding the distortion
     112    // modify the chip->toFPA scaling to match knowledge about pixel scale,
     113    // then recalculate raw and ref positions
     114    if (!psastroMosaicCommonScale (fpa, recipe)) {
     115        psError(PSASTRO_ERR_UNKNOWN, false, "failed to set a common scale for the chips (pass %d)", pass);
     116        return false;
     117    }
     118
     119    if ((pass == 0) && (psTraceGetLevel("psastro.dump.psastroMosaicAstrom") > 1)) {
     120        snprintf (filename, 256, "%s.1.dat", rootname);
     121        psastroDumpMatches (fpa, filename);
     122    }
     123
     124    // fit the distortion by fitting its gradient
     125    // apply the new distortion terms up and down
     126    // refit the per-chip terms with linear fits only
     127    if (!psastroMosaicDistortion (fpa, recipe, pass)) {
     128        psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure mosaic gradients (pass %d)", pass);
     129        return false;
     130    }
     131
     132    snprintf (filename, 256, "%s.%d.dat", rootname, 2*pass + 2);
     133    if (psTraceGetLevel("psastro.dump.psastroMosaicAstrom") > 1) { psastroDumpMatches (fpa, filename); }
     134   
     135    // measure the astrometry for the chips under the distortion term
     136    if (!psastroMosaicChipAstrom (fpa, recipe, pass)) {
     137        psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (pass %d)", pass);
     138        return false;
     139    }
     140
     141    int traceLevel = psTraceGetLevel("psastro.dump.psastroMosaicAstrom");
     142    if (traceLevel > 1) {
     143        snprintf (filename, 256, "%s.%d.dat", rootname, 2*pass + 3);
     144        psastroDumpMatches (fpa, filename);
     145    } else {
     146        snprintf (filename, 256, "%s.dat", rootname);
     147        psastroDumpMatches (fpa, filename);
     148    }
     149
     150    return true;
     151}
  • branches/cnb_branch_20080830/psastro/src/psastroMosaicGradients.c

    r15671 r20033  
    22static int nPass = 0;
    33
    4 bool psastroMosaicGradients (pmFPA *fpa, psMetadata *recipe) {
     4bool psastroMosaicDistortionFromGradients (pmFPA *fpa, psMetadata *recipe) {
    55
    66    bool status;
     
    99    pmReadout *readout = NULL;
    1010    psArray *gradients = NULL;
     11
     12    // Measure the gradient as a function of position.  This must be performed between the
     13    // corrected ref->TP and the observed raw->FP, for which the distortion is a perturbation.
    1114
    1215    pmFPAview *view = pmFPAviewAlloc (0);
     
    5962    }
    6063
     64    // Fit the gradient field and convert to the distortion terms.
     65
    6166    // allocate mosaic-level polynomial transformation and set masks needed by DVO
    6267    int order = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.ORDER");
     
    95100    }
    96101       
    97     if (!psastroMosaicSetAstrom (fpa)) {
    98         psError(PSASTRO_ERR_UNKNOWN, false, "failed to apply mosaic distortion terms\n");
    99         psFree (gradients);
    100         psFree (view);
    101         return false;
    102     }
    103 
    104102    psFree (gradients);
    105103    psFree (view);
    106104    return true;
    107105}
     106
  • branches/cnb_branch_20080830/psastro/src/psastroMosaicOneChip.c

    r15562 r20033  
    1212    char errorWord[64];
    1313    char orderWord[64];
    14 
    15     assert (iteration < 4);
    1614
    1715    PS_ASSERT_PTR_NON_NULL(chip,    false);
     
    8684
    8785    // XXX allow statitic to be set by the user
    88     psStats *fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    89     fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NSIGMA");
    90     fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NITER");
     86    // only clip if we are fitting the chip parameters.
     87    psStats *fitStats = NULL;
     88//    if (order == 0) {
     89//      fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     90//      fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NSIGMA");
     91//      fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NITER");
     92//    } else {
     93        fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     94        fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NSIGMA");
     95        fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.NITER");
     96//    }
    9197
    9298    // need to pass in an update header, sent in from above
     
    117123    // XXX should these result in errors or be handled another way?
    118124    psLogMsg ("psastro", PS_LOG_INFO, "astrometry solution: error: %f arcsec, Nstars: %d", astError, astNstar);
    119     if (astError > maxError) {
     125    if ((maxError > 0) && (astError > maxError)) {
    120126        psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError);
    121127        validSolution = false;
  • branches/cnb_branch_20080830/psastro/src/psastroOneChipGrid.c

    r16070 r20033  
    2121    psArray *subset = psArrayAlloc (PS_MIN (maxNstar, rawstars->n));
    2222    for (int i = 0; (i < maxNstar) && (i < rawstars->n); i++) {
    23         subset->data[i] = psMemIncrRefCounter (rawstars->data[i]);
     23        subset->data[i] = psMemIncrRefCounter (rawstars->data[i]);
    2424    }
    2525
     
    3535    pmAstromStats *gridStats = pmAstromGridMatch (gridStars, refSubset, recipe);
    3636    if (gridStats == NULL) {
    37         psLogMsg ("psastro", 3, "failed to find a grid match solution\n");
    38         psFree (gridStars);
    39         psFree (refSubset);
    40         return false;
     37        psLogMsg ("psastro", 3, "failed to find a grid match solution\n");
     38        psFree (gridStars);
     39        psFree (refSubset);
     40        return false;
    4141    }
    4242    psLogMsg ("psastro", 3, "basic grid search result - offset: %f,%f pixels, rotation: %f deg\n", gridStats->offset.x, gridStats->offset.y, DEG_RAD*gridStats->angle);
     
    4545    stats = pmAstromGridTweak (gridStars, refSubset, recipe, gridStats);
    4646    if (stats == NULL) {
    47         psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n");
    48         psFree (gridStats);
    49         psFree (gridStars);
    50         psFree (refSubset);
    51         return false;
     47        psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n");
     48        psFree (gridStats);
     49        psFree (gridStars);
     50        psFree (refSubset);
     51        return false;
    5252    }
    5353    psLogMsg ("psastro", 3, "tweak grid search result - offset: %f,%f pixels, rotation: %f deg\n", stats->offset.x, stats->offset.y, DEG_RAD*stats->angle);
  • branches/cnb_branch_20080830/psastro/src/psastroParseCamera.c

    r15121 r20033  
    3333    psFree (chips);
    3434
     35    psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");
     36    if (dump_file) {
     37        pmConfigCamerasCull(config, NULL);
     38        pmConfigRecipesCull(config, "PPIMAGE,PPSTATS,PSPHOT,MASKS,PSASTRO");
     39
     40        pmConfigDump(config, input->fpa, dump_file);
     41    }
     42
     43
    3544    psTrace("psastro", 1, "Done with psastroParseCamera...\n");
    3645    return true;
  • branches/cnb_branch_20080830/psastro/src/psastroRefstarSubset.c

    r14165 r20033  
    2121  // is needed...
    2222  psLogMsg ("psastro", 4, "measuring luminosity function for rawstars\n");
    23   pmLumFunc *rawfunc = psastroLuminosityFunction (rawstars);
     23  pmLumFunc *rawfunc = psastroLuminosityFunction (rawstars, NULL);
    2424  if (rawfunc == NULL) {
    2525    psLogMsg ("psastro", 4, "giving up on rawstars for this readout\n");
     
    2727  }
    2828  psLogMsg ("psastro", 4, "measuring luminosity function for refstars\n");
    29   pmLumFunc *reffunc = psastroLuminosityFunction (refstars);
     29  pmLumFunc *reffunc = psastroLuminosityFunction (refstars, rawfunc);
    3030  if (reffunc == NULL) {
    3131    psLogMsg ("psastro", 4, "giving up on refstars for this readout\n");
     
    8484/* this test is a bit sensitive to the total number of refstars or rawstars available
    8585   watch out if:
    86    - the fitted slopes are extremely different 
     86   - the fitted slopes are extremely different
    8787   - the average number of stars per bin is ~1
    88    
     88
    8989   skip the cut in these cases?
    9090*/
  • branches/cnb_branch_20080830/psastro/src/psastroStandAlone.h

    r17322 r20033  
    2525bool              psastroModelDataSave (pmConfig *config);
    2626
    27 psVector         *psastroModelFitBoresite (psVector *Xo, psVector *Yo, psVector *Po);
     27psVector         *psastroModelFitBoresite (psVector *Xo, psVector *Yo, psVector *Po, char *outroot);
    2828psF32             psastroModelBoresite (psVector *deriv, const psVector *params, const psVector *coord);
    2929
  • branches/cnb_branch_20080830/psastro/src/psastroUseModel.c

    r17040 r20033  
    11# include "psastroInternal.h"
    22# define NONLIN_TOL 0.001 /* tolerance in pixels */
     3# define DEBUG 0
    34
    45// apply the generic astrometry model to this image.  this assumes the WCS terms either do not
     
    3536  }
    3637
     38  // XXX TEST: apply the input image RA & DEC to the astrometry model, save corners
     39  if (0) {
     40      // these externally supplied values are used to set the final transformation terms
     41      double RA  = psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.RA");
     42      double DEC = psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.DEC");
     43      // double POS = PM_RAD_DEG * psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.POSANGLE");
     44
     45      // get projection scale; center is supplied
     46      // XXX should this be astrom or input??
     47      float Xs = psMetadataLookupF32(&status, astrom->fpa->concepts, "XSCALE") * PM_RAD_DEG;
     48      float Ys = psMetadataLookupF32(&status, astrom->fpa->concepts, "YSCALE") * PM_RAD_DEG;
     49
     50      // allocate a new toSky projection using the reported position
     51      psFree (astrom->fpa->toSky);
     52      astrom->fpa->toSky = psProjectionAlloc (RA, DEC, Xs, Ys, PS_PROJ_DIS);
     53
     54      // local view
     55      pmFPAview *myView = pmFPAviewAlloc (0);
     56
     57      // loop over all chips, replace input astrometry elements with those from astrom
     58      pmChip *obsChip = NULL;
     59      while ((obsChip = pmFPAviewNextChip (myView, input->fpa, 1)) != NULL) {
     60          psTrace ("psastro", 4, "Chip %d: %x %x\n", myView->chip, obsChip->file_exists, obsChip->process);
     61          if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; }
     62
     63          // set the chip astrometry using the astrom file
     64          pmChip *refChip = pmFPAviewThisChip (myView, astrom->fpa);
     65
     66          psFree (obsChip->toFPA);
     67          psFree (obsChip->fromFPA);
     68
     69          // supply astrometry from model
     70          obsChip->toFPA   = psMemIncrRefCounter (refChip->toFPA);
     71          obsChip->fromFPA = psMemIncrRefCounter (refChip->fromFPA);
     72
     73          // XXX if we want to write out the result, update the header here.  this needs to be
     74          // updated with the correct HDU selection.  obsChip->hdu may not exist.
     75          // pmAstromWriteBilevelChip (obsChip->hdu->header, obsChip, NONLIN_TOL);
     76      }
     77
     78      psFree (input->fpa->toSky);
     79      psFree (input->fpa->toTPA);
     80      psFree (input->fpa->fromTPA);
     81      input->fpa->toSky   = psMemIncrRefCounter (astrom->fpa->toSky);
     82      input->fpa->toTPA   = psMemIncrRefCounter (astrom->fpa->toTPA);
     83      input->fpa->fromTPA = psMemIncrRefCounter (astrom->fpa->fromTPA);
     84
     85      // XXX this is temporarily hardwired because of model error
     86      input->fpa->toSky->type = PS_PROJ_TAN;
     87
     88      if (DEBUG) psastroDumpCorners ("corners.up.ast1.dat", "corners.dn.ast1.dat", input->fpa);
     89  }
     90
    3791  // set the model using the RA, DEC, POSANGLE of the input image.
    3892  pmAstromModelSetTP (astrom, input->fpa->concepts);
     93
     94  if (DEBUG) psastroDumpCorners ("corners.up.ast2.dat", "corners.dn.ast2.dat", astrom->fpa);
    3995
    4096  // loop over all chips, replace input astrometry elements with those from astrom
     
    57113    // updated with the correct HDU selection.  obsChip->hdu may not exist.
    58114    // pmAstromWriteBilevelChip (obsChip->hdu->header, obsChip, NONLIN_TOL);
    59 
    60    
    61 
    62115  }
    63116
     
    72125  input->fpa->toSky->type = PS_PROJ_TAN;
    73126
    74   // psastroDumpCorners ("corners.useModel.dat", input->fpa);
     127  if (DEBUG) psastroDumpCorners ("corners.up.inp.dat", "corners.dn.inp.dat", input->fpa);
    75128
    76129  // updated with the correct HDU selection.  obsChip->hdu may not exist.
Note: See TracChangeset for help on using the changeset viewer.