Changeset 15891
- Timestamp:
- Dec 22, 2007, 7:42:46 AM (18 years ago)
- Location:
- trunk/psastro/src
- Files:
-
- 5 added
- 15 edited
-
Makefile.am (modified) (4 diffs)
-
gpcModel.c (added)
-
psastro.h (modified) (1 diff)
-
psastroAnalysis.c (modified) (2 diffs)
-
psastroArguments.c (modified) (1 diff)
-
psastroAstromGuess.c (modified) (3 diffs)
-
psastroDefineFiles.c (modified) (1 diff)
-
psastroEnforceChips.c (modified) (3 diffs)
-
psastroFixChips.c (added)
-
psastroModel.c (modified) (1 diff)
-
psastroModelAdjust.c (added)
-
psastroModelAnalysis.c (modified) (5 diffs)
-
psastroModelBoresite.c (modified) (3 diffs)
-
psastroModelDataLoad.c (modified) (1 diff)
-
psastroModelDataSave.c (added)
-
psastroModelFitBoresite.c (modified) (4 diffs)
-
psastroModelParseCamera.c (modified) (1 diff)
-
psastroMosaicAstrom.c (modified) (1 diff)
-
psastroStandAlone.h (modified) (1 diff)
-
psastroUseModel.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/Makefile.am
r15887 r15891 3 3 libpsastro_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS) 4 4 5 bin_PROGRAMS = psastro psastroModel 5 bin_PROGRAMS = psastro psastroModel gpcModel 6 6 7 7 psastro_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS) … … 12 12 psastroModel_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSASTRO_LIBS) 13 13 psastroModel_LDADD = libpsastro.la 14 15 gpcModel_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS) 16 gpcModel_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSASTRO_LIBS) 17 gpcModel_LDADD = libpsastro.la 14 18 15 19 psastro_SOURCES = \ … … 29 33 psastroModelBoresite.c \ 30 34 psastroModelFitBoresite.c \ 35 psastroModelAdjust.c \ 36 psastroModelDataSave.c \ 31 37 psastroCleanup.c 38 39 gpcModel_SOURCES = gpcModel.c 32 40 33 41 ## move DataSave to psastro_SOURCES? … … 48 56 psastroLuminosityFunction.c \ 49 57 psastroRefstarSubset.c \ 50 psastroEnforceChips.c \ 58 psastroFixChips.c \ 59 psastroUseModel.c \ 51 60 psastroMosaicAstrom.c \ 52 61 psastroMosaicGradients.c \ -
trunk/psastro/src/psastro.h
r15562 r15891 80 80 int psastroSortByMag (const void *a, const void *b); 81 81 82 bool psastroEnforceChips (pmConfig *config, pmFPA *fpa, psMetadata *recipe); 82 bool psastroFixChips (pmConfig *config, psMetadata *recipe); 83 bool psastroUseModel (pmConfig *config, psMetadata *recipe); 83 84 84 psArray *psastroReadGetstarCatalog (psFits *fits); 85 psArray *psastroReadGetstar_PS1_DEV_0 (psFits *fits); 85 psArray *psastroReadGetstarCatalog (psFits *fits); 86 psArray *psastroReadGetstar_PS1_DEV_0 (psFits *fits); 87 88 bool psastroAstromGuessSetChip (pmFPA *fpa, pmChip *chip, pmFPAview *view, double pixelScale, bool bilevelAstrometry); 89 bool psastroAstromGuessSetFPA (pmFPA *fpa, bool *bilevelAstrometry); 86 90 87 91 # endif /* PSASTRO_H */ -
trunk/psastro/src/psastroAnalysis.c
r15562 r15891 5 5 bool status; 6 6 int nStars; 7 8 // select the current recipe 9 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE); 10 if (!recipe) { 11 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe"); 12 return false; 13 } 14 15 if (!psastroUseModel (config, recipe)) { 16 psError (PSASTRO_ERR_UNKNOWN, false, "failed to set model astrometry\n"); 17 return false; 18 } 7 19 8 20 // interpret the available initial astrometric information … … 26 38 if (!psastroChooseRefstars (config, refs)) { 27 39 psError (PSASTRO_ERR_UNKNOWN, false, "failed to select reference data for chips\n"); 28 return false;29 }30 31 // select the current recipe32 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);33 if (!recipe) {34 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");35 40 return false; 36 41 } -
trunk/psastro/src/psastroArguments.c
r15562 r15891 43 43 psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.FIX.CHIPS", PS_META_REPLACE, "", true); 44 44 } 45 // no valid header WCS: supply from astrom model 46 if ((N = psArgumentGet (argc, argv, "-use-astrommodel"))) { 47 psArgumentRemove (N, &argc, argv); 48 psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.USE.MODEL", PS_META_REPLACE, "", true); 49 } 45 50 // define the reference astrometry file 46 status = pmConfigFileSetsMD (config->arguments, &argc, argv, " REF.ASTROM", "-refastrom", "-refastromlist");51 status = pmConfigFileSetsMD (config->arguments, &argc, argv, "ASTROM.MODEL", "-astrommodel", "-astrommodellist"); 47 52 if (status) { 48 53 // if supplied, assume -fixchips is desired 49 54 psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.FIX.CHIPS", PS_META_REPLACE, "", true); 50 55 } 56 51 57 52 58 // apply mosastro mode? -
trunk/psastro/src/psastroAstromGuess.c
r15200 r15891 32 32 } 33 33 34 // have we already supplied the astrometry from the model? 35 bool useModel = psMetadataLookupBool (&status, config->arguments, "PSASTRO.USE.MODEL"); 36 if (!status) { 37 useModel = psMetadataLookupBool (&status, recipe, "PSASTRO.USE.MODEL"); 38 } 39 34 40 // select the input data sources 35 41 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); … … 46 52 } 47 53 48 pmFPAview *view = pmFPAviewAlloc (0);49 54 pmFPA *fpa = input->fpa; 50 55 51 56 // load mosaic-level astrometry? 52 57 bool bilevelAstrometry = false; 53 pmHDU *phu = pmFPAviewThisPHU (view, fpa); 54 if (phu) { 55 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1"); 56 if (ctype) { 57 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 58 } 58 if (!useModel) { 59 psastroAstromGuessSetFPA (fpa, &bilevelAstrometry); 59 60 } 60 if (bilevelAstrometry) {61 pmAstromReadBilevelMosaic (fpa, phu->header);62 }63 61 62 pmFPAview *view = pmFPAviewAlloc (0); 64 63 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 65 64 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 66 65 if (!chip->process || !chip->file_exists || !chip->data_exists) { continue; } 67 66 68 // read WCS data from the corresponding header 69 pmHDU *hdu = pmFPAviewThisHDU (view, fpa); 70 if (bilevelAstrometry) { 71 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 72 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 73 continue; 74 } 75 } else { 76 if (!pmAstromReadWCS (fpa, chip, hdu->header, pixelScale)) { 77 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 78 continue; 79 } 67 if (!useModel) { 68 if (!psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry)) continue; 80 69 } 81 70 … … 160 149 sky (ra, dec) 161 150 */ 151 152 bool psastroAstromGuessSetChip (pmFPA *fpa, pmChip *chip, pmFPAview *view, double pixelScale, bool bilevelAstrometry) { 153 154 // read WCS data from the corresponding header 155 pmHDU *hdu = pmFPAviewThisHDU (view, fpa); 156 if (bilevelAstrometry) { 157 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 158 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 159 return false; 160 } 161 } else { 162 if (!pmAstromReadWCS (fpa, chip, hdu->header, pixelScale)) { 163 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 164 return false; 165 } 166 } 167 return true; 168 } 169 170 bool psastroAstromGuessSetFPA (pmFPA *fpa, bool *bilevelAstrometry) { 171 172 pmFPAview *view = pmFPAviewAlloc (0); 173 pmHDU *phu = pmFPAviewThisPHU (view, fpa); 174 175 *bilevelAstrometry = false; 176 177 // load mosaic-level astrometry? 178 if (phu) { 179 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1"); 180 if (ctype) { 181 *bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 182 } 183 } 184 if (*bilevelAstrometry) { 185 pmAstromReadBilevelMosaic (fpa, phu->header); 186 } 187 psFree (view); 188 return true; 189 } -
trunk/psastro/src/psastroDefineFiles.c
r15669 r15891 20 20 output->save = true; 21 21 22 bool fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.FIX.CHIPS"); 23 if (fixChips) { 24 if (!psastroDefineFile (config, input->fpa, "PSASTRO.REF.ASTROM", "REF.ASTROM", PM_FPA_FILE_ASTROM, PM_DETREND_TYPE_ASTROM)) { 25 psError (PS_ERR_IO, false, "Can't find a reference astrometry file"); 22 bool fixChips = psMetadataLookupBool (&status, config->arguments, "PSASTRO.FIX.CHIPS"); 23 if (!status) { 24 fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.FIX.CHIPS"); 25 } 26 bool useModel = psMetadataLookupBool (&status, config->arguments, "PSASTRO.USE.MODEL"); 27 if (!status) { 28 fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.USE.MODEL"); 29 } 30 if (fixChips || useModel) { 31 if (!psastroDefineFile (config, input->fpa, "PSASTRO.MODEL", "ASTROM.MODEL", PM_FPA_FILE_ASTROM, PM_DETREND_TYPE_ASTROM)) { 32 psError (PS_ERR_IO, false, "Can't find an astrometry model file"); 26 33 return NULL; 27 34 } 28 }29 30 bool saveAstrom = psMetadataLookupBool (&status, recipe, "SAVE.REF.ASTROM");31 if (saveAstrom) {32 pmFPAfile *outAstrom = pmFPAfileDefineOutputFromFile (config, input, "PSASTRO.OUT.ASTROM");33 if (!outAstrom) {34 psError (PS_ERR_IO, false, "Can't find a reference astrometry file");35 return NULL;36 }37 outAstrom->save = true;38 35 } 39 36 -
trunk/psastro/src/psastroEnforceChips.c
r15670 r15891 1 1 # include "psastroInternal.h" 2 # define NONLIN_TOL 0.001 /* tolerance in pixels */ 2 3 3 bool psastroEnforceChips (pmConfig *config, pmFPA *fpa, psMetadata *recipe) { 4 XXX add a function to supply for all entries, as opposed to fixing the poor astrometry ones. 5 bool psastroEnforceChips (pmConfig *config, psMetadata *recipe) { 4 6 5 7 bool status; 6 8 9 bool fixChips = psMetadataLookupBool (&status, config->arguments, "PSASTRO.FIX.CHIPS"); 10 if (!status) { 11 fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.FIX.CHIPS"); 12 } 13 if (!fixChips) return true; 14 7 15 // identify reference astrometry table 8 16 // if not defined, correction was not requested; skip step 9 pmFPAfile *refAstrom = psMetadataLookupPtr (NULL, config->files, "REF.ASTROM"); 10 if (!refAstrom) return true; 17 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.MODEL"); 18 if (!astrom) return true; 19 20 // select the input data sources 21 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 22 if (!input) { 23 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 24 return false; 25 } 26 27 // make sure the astrometry model is loaded 28 // de-activate all files except PSASTRO.MODEL 29 // XXX do I need to supply the input->fpa->concepts to the astrom->fpa->concepts? 30 psFree (astrom->fpa->concepts); 31 astrom->fpa->concepts = psMemIncrRefCounter (input->fpa->concepts); 32 pmFPAfileActivate (config->files, false, NULL); 33 pmFPAfileActivate (config->files, true, "PSASTRO.MODEL"); 11 34 12 35 pmFPAview *view = pmFPAviewAlloc (0); 36 37 // files associated with the science image 38 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 39 psError (PS_ERR_IO, false, "Can't load the astrometry model file"); 40 return false; 41 } 42 43 // loop over all chips, replace input astrometry elements with those from astrom 44 pmChip *obsChip = NULL; 45 while ((obsChip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 46 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, obsChip->file_exists, obsChip->process); 47 if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; } 48 49 // set the chip astrometry using the astrom file 50 pmChip *refChip = pmFPAviewThisChip (view, astrom->fpa); 51 52 psFree (obsChip->toFPA); 53 psFree (obsChip->fromFPA); 54 55 // XXX can we do a straight copy? I think so, but we may need to apply a scaling factor based 56 // on the toSky or toTPA values 57 obsChip->toFPA = psMemIncrRefCounter (refChip->toFPA); 58 obsChip->fromFPA = psMemIncrRefCounter (refChip->fromFPA); 59 60 // XXX test to write out adjusted header 61 pmAstromWriteBilevelChip (obsChip->hdu->header, obsChip, NONLIN_TOL); 62 } 63 64 psFree (input->fpa->toSky); 65 psFree (input->fpa->toTPA); 66 psFree (input->fpa->fromTPA); 67 input->fpa->toSky = psMemIncrRefCounter (astrom->fpa->toSky); 68 input->fpa->toTPA = psMemIncrRefCounter (astrom->fpa->toTPA); 69 input->fpa->fromTPA = psMemIncrRefCounter (astrom->fpa->fromTPA); 70 71 psMetadata *updates = psMetadataAlloc(); 72 pmAstromWriteBilevelMosaic (updates, input->fpa, NONLIN_TOL); 73 psMetadataAddMetadata (input->fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", updates); 74 psFree (updates); 75 76 psFree (view); 77 return true; 78 } 79 80 # if (0) 13 81 14 82 // physical pixel scale in microns per pixel … … 33 101 if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; } 34 102 35 // set the chip astrometry using the refAstrom file36 pmChip *refChip = pmFPAviewThisChip (view, refAstrom->fpa);103 // set the chip astrometry using the astrom file 104 pmChip *refChip = pmFPAviewThisChip (view, astrom->fpa); 37 105 38 106 // bad Astrometry test: ref pixel or angle outside nominal … … 80 148 // XXX for this function to work, I need to: 81 149 // 1 *) define badAstrom (ref pixel too far from nominal?) (ref angle too far off?) 82 // 2) load the refAstrom fpa in the pmFPAfileIO stage150 // 2) load the astrom fpa in the pmFPAfileIO stage 83 151 // 3) allow for this operation to be optional 152 # endif -
trunk/psastro/src/psastroModel.c
r15880 r15891 31 31 // run the full astrometry analysis (chip and/or mosaic) 32 32 if (!psastroModelAnalysis (config)) { 33 psErrorStackPrint(stderr, "failure in psastro analysis\n");33 psErrorStackPrint(stderr, "failure in psastro model analysis\n"); 34 34 exit (1); 35 35 } 36 36 37 // run the full astrometry analysis (chip and/or mosaic) 38 if (!psastroModelAdjust (config)) { 39 psErrorStackPrint(stderr, "failure in psastro model adjust\n"); 40 exit (1); 41 } 42 43 // save the model 44 if (!psastroModelDataSave (config)) { 45 psErrorStackPrint(stderr, "error saving output data\n"); 46 exit (1); 47 } 48 37 49 psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete")); 38 50 -
trunk/psastro/src/psastroModelAnalysis.c
r15887 r15891 12 12 } 13 13 14 pmFPAfile *output = psMetadataLookupPtr (&status, config->files, "PSASTRO.OUT.MODEL"); 15 if (!status) psAbort ("Can't find output pmFPAfile PSASTRO.OUT.MODEL"); 16 14 17 // physical pixel scale in microns per pixel 15 18 char *refChip = psMetadataLookupStr (&status, recipe, "PSASTRO.MODEL.REF.CHIP"); … … 19 22 } 20 23 21 /* model analysis steps: 22 23 1) determine POS_ZERO: 24 * choose a reference chip 25 * what is posangle of chip 26 * posangle = FPA.POSANGLE - POS_ZERO 27 * POS_ZERO = FPA.POSANGLE - posangle 28 29 ** average over input images 30 31 2) determine boresite model 32 33 * find CRPIX1,2 for a series of images 34 * fit ellipse 35 36 */ 37 38 /***** find the POSANGLE offset *****/ 24 /* model analysis: 25 * 26 * determine POS_ZERO via comparison of measured and reported posangles 27 * POS_ZERO = FPA.POSANGLE - posangle 28 * 29 * determine boresite model: 30 * X = Xo + R_X cos(FPA.POSANGLE - T_0) cos(P_0) + R_Y sin(FPA.POSANGLE - T_0) sin(P_0) 31 * Y = Yo + R_Y sin(FPA.POSANGLE - T_0) cos(P_0) - R_X cos(FPA.POSANGLE - T_0) sin(P_0) 32 * position of reported boresite in reference chip pixels 33 * Xo, Yo : true coordinate of boresite (rotator center) in reference chip pixels 34 * R_X, R_Y : amplitude of boresite offset 35 * T_0 : reference angle for rotator 36 * P_0 : orientation of boresite ellipse 37 */ 39 38 40 39 // select the input pmFPAfile pointers … … 44 43 psArray *files = psListToArray (item->data.list); 45 44 46 // temp data vectors45 // data storage vectors for measurements 47 46 psVector *posZero = psVectorAlloc (files->n, PS_TYPE_F32); 48 47 psVector *Po = psVectorAlloc (files->n, PS_TYPE_F32); 49 psVector * Lo = psVectorAlloc (files->n, PS_TYPE_F32);50 psVector * Mo = psVectorAlloc (files->n, PS_TYPE_F32);48 psVector *Xo = psVectorAlloc (files->n, PS_TYPE_F32); 49 psVector *Yo = psVectorAlloc (files->n, PS_TYPE_F32); 51 50 51 // counter for accepted measured values 52 52 int n = 0; 53 53 54 // convert the headers for the input file into fpa astrometry terms 54 // Re-select the output fpa. The output fpa needs to have valid astrometry for the 55 // refChip. output->fpa is a copy of the pointer to one of the input->fpa, but the choice 56 // is arbitrary. select a new one that has an existing ref chip 57 psFree (output->fpa); 58 output->fpa = NULL; 59 60 // extract the relevant measured and reported values from the reference chip 55 61 for (int i = 0; i < files->n; i++) { 56 62 psMetadataItem *file = files->data[i]; 57 63 pmFPAfile *input = file->data.V; 58 64 65 // reported rotator position angle (this should perhaps be ROT, not POS) 59 66 double POSANGLE = psMetadataLookupF64 (&status, input->fpa->concepts, "FPA.POSANGLE"); 60 67 if (!status) psAbort ("missing FPA.POSANGLE"); 61 68 62 // get chip from name69 // get reference chip from name 63 70 pmChip *chip = pmConceptsChipFromName (input->fpa, refChip); 64 71 if (!chip) psAbort ("invalid chip name for reference"); 65 72 73 fprintf (stderr, "input %d : %zx : %zx : %zx\n", i, (size_t) input, (size_t) chip, (size_t) chip->toFPA); 66 74 if (!chip->toFPA) continue; 75 76 if (!output->fpa) { 77 // this one matches 78 output->fpa = psMemIncrRefCounter(input->fpa); 79 } 67 80 68 81 // we have two measurements of the posangle (may be parity flipped to different quadrants) … … 72 85 while (posZero->data.F32[n] < 0.0) posZero->data.F32[n] += 360.0; 73 86 74 Po->data.F32[n] = POSANGLE * PM_RAD_DEG; 75 Lo->data.F32[n] = chip->toFPA->x->coeff[0][0];76 Mo->data.F32[n] = chip->toFPA->y->coeff[0][0];77 fprintf (stderr, "%d : %f %f : %f = %f - %f\n", i, Lo->data.F32[n], Mo->data.F32[n], posZero->data.F32[n], POSANGLE, posangle);87 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); 78 91 n ++; 79 92 } 80 93 81 Lo->n = n;82 Mo->n = n;94 Xo->n = n; 95 Yo->n = n; 83 96 Po->n = n; 84 97 posZero->n = n; … … 88 101 89 102 fprintf (stderr, "pos zero %f +/- %f\n", stats->sampleMedian, stats->sampleStdev); 103 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.POS_ZERO", PS_META_REPLACE, "offset between obs and meas posangle", stats->sampleMedian); 90 104 91 psastroModelFitBoresite (Lo, Mo, Po); 105 psVector *params = psastroModelFitBoresite (Xo, Yo, Po); 106 if (params->n != 6) psAbort ("error"); 107 108 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.X0", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_X0]); 109 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.Y0", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_Y0]); 110 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.RX", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_RX]); 111 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.RY", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_RY]); 112 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.T0", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_T0]); 113 psMetadataAddF32 (output->fpa->concepts, PS_LIST_TAIL, "FPA.BORE.P0", PS_META_REPLACE, "boresite parameter", params->data.F32[PAR_P0]); 114 psMetadataAddStr (output->fpa->concepts, PS_LIST_TAIL, "FPA.REF.CHIP", PS_META_REPLACE, "boresite parameter", refChip); 92 115 93 116 return true; -
trunk/psastro/src/psastroModelBoresite.c
r15887 r15891 1 1 # include "psastroStandAlone.h" 2 2 3 // chisq = sum ((L_obs - L_fit(t))^2 + (M_obs - M_fit(t))^2) 4 // coord[0] = measured L or measured M 3 // the full chisq is built of two associated sums over coordinates: 4 // chisq = sum ((X_obs - X_fit(t))^2 + (Y_obs - Y_fit(t))^2) 5 // we use split this into a 2x long vector and use coord[1] to distinguish the X and Y terms: 6 // coord[0] = measured X or measured Y 5 7 // coord[1] = 0 or 1 6 8 psF32 psastroModelBoresite (psVector *deriv, const psVector *params, const psVector *coord) { … … 15 17 float sntht = sin(dtheta); 16 18 17 // value is L19 // value is X 18 20 if (coord->data.F32[1] == 0) { 19 21 20 float value = PAR[PAR_ L0] + PAR[PAR_RL]*cstht*csphi + PAR[PAR_RM]*sntht*snphi;22 float value = PAR[PAR_X0] + PAR[PAR_RX]*cstht*csphi + PAR[PAR_RY]*sntht*snphi; 21 23 22 24 if (deriv) { 23 25 psF32 *dPAR = deriv->data.F32; 24 dPAR[PAR_ L0] = 1.0;25 dPAR[PAR_ M0] = 0.0;26 dPAR[PAR_R L] = +cstht*csphi;27 dPAR[PAR_R M] = +sntht*snphi;28 dPAR[PAR_P0] = -PAR[PAR_R L]*cstht*snphi + PAR[PAR_RM]*sntht*csphi;29 dPAR[PAR_T0] = PAR[PAR_R L]*sntht*csphi - PAR[PAR_RM]*cstht*snphi;26 dPAR[PAR_X0] = 1.0; 27 dPAR[PAR_Y0] = 0.0; 28 dPAR[PAR_RX] = +cstht*csphi; 29 dPAR[PAR_RY] = +sntht*snphi; 30 dPAR[PAR_P0] = -PAR[PAR_RX]*cstht*snphi + PAR[PAR_RY]*sntht*csphi; 31 dPAR[PAR_T0] = PAR[PAR_RX]*sntht*csphi - PAR[PAR_RY]*cstht*snphi; 30 32 } 31 33 return (value); 32 34 } 33 35 34 // value is M36 // value is Y 35 37 if (coord->data.F32[1] == 1) { 36 float value = PAR[PAR_ M0] + PAR[PAR_RM]*sntht*csphi - PAR[PAR_RL]*cstht*snphi;38 float value = PAR[PAR_Y0] + PAR[PAR_RY]*sntht*csphi - PAR[PAR_RX]*cstht*snphi; 37 39 38 40 if (deriv) { 39 41 psF32 *dPAR = deriv->data.F32; 40 dPAR[PAR_ L0] = 0.0;41 dPAR[PAR_ M0] = 1.0;42 dPAR[PAR_R L] = -cstht*snphi;43 dPAR[PAR_R M] = +sntht*csphi;44 dPAR[PAR_P0] = -PAR[PAR_R M]*sntht*snphi - PAR[PAR_RL]*cstht*csphi;45 dPAR[PAR_T0] = -PAR[PAR_R M]*sntht*csphi - PAR[PAR_RL]*cstht*snphi;42 dPAR[PAR_X0] = 0.0; 43 dPAR[PAR_Y0] = 1.0; 44 dPAR[PAR_RX] = -cstht*snphi; 45 dPAR[PAR_RY] = +sntht*csphi; 46 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; 46 48 } 47 49 return (value); … … 49 51 psAbort ("programming error: invalid coordinate"); 50 52 } 51 52 # undef PAR_L053 # undef PAR_RL54 # undef PAR_PHI55 # define PAR_L0 056 # define PAR_RL 157 # define PAR_PHI 258 59 psF32 psastroModelBoresiteL (psVector *deriv, const psVector *params, const psVector *coord) {60 61 psF32 *PAR = params->data.F32;62 63 float csphi = cos(PAR[PAR_PHI]);64 float snphi = sin(PAR[PAR_PHI]);65 66 float theta = coord->data.F32[0];67 float cstht = cos(theta);68 float sntht = sin(theta);69 70 float value = PAR[PAR_L0] + PAR[PAR_RL]*cstht*csphi - PAR[PAR_RL]*sntht*snphi;71 72 if (deriv) {73 psF32 *dPAR = deriv->data.F32;74 dPAR[PAR_L0] = 1.0;75 dPAR[PAR_RL] = cstht*csphi - sntht*snphi;76 dPAR[PAR_PHI] = -PAR[PAR_RL]*cstht*snphi - PAR[PAR_RL]*sntht*csphi;77 }78 return (value);79 }80 81 psF32 psastroModelBoresiteM (psVector *deriv, const psVector *params, const psVector *coord) {82 83 psF32 *PAR = params->data.F32;84 85 float csphi = cos(PAR[PAR_PHI]);86 float snphi = sin(PAR[PAR_PHI]);87 88 float theta = coord->data.F32[0];89 float cstht = cos(theta);90 float sntht = sin(theta);91 92 float value = PAR[PAR_L0] + PAR[PAR_RL]*sntht*csphi + PAR[PAR_RL]*cstht*snphi;93 94 if (deriv) {95 psF32 *dPAR = deriv->data.F32;96 dPAR[PAR_L0] = 1.0;97 dPAR[PAR_RL] = +sntht*csphi + cstht*snphi;98 dPAR[PAR_PHI] = -PAR[PAR_RL]*sntht*snphi + PAR[PAR_RL]*cstht*csphi;99 }100 return (value);101 } -
trunk/psastro/src/psastroModelDataLoad.c
r15880 r15891 33 33 34 34 // select the input data sources 35 pmFPAfile *output = psMetadataLookupPtr (NULL, config->files, "PSASTRO. MODEL");36 if (!output) psAbort ("PSASTRO. MODEL not listed in config->files");35 pmFPAfile *output = psMetadataLookupPtr (NULL, config->files, "PSASTRO.OUT.MODEL"); 36 if (!output) psAbort ("PSASTRO.OUT.MODEL not listed in config->files"); 37 37 38 38 pmFPAview *view = pmFPAviewAlloc (0); -
trunk/psastro/src/psastroModelFitBoresite.c
r15887 r15891 2 2 3 3 // we now have a set of observed L,M values. fit these to the boresite model 4 bool psastroModelFitBoresite (psVector *Lo, psVector *Mo, psVector *Po) {4 psVector *psastroModelFitBoresite (psVector *Xo, psVector *Yo, psVector *Po) { 5 5 6 assert ( Lo->n > 2);7 assert ( Lo->n == Mo->n);8 assert ( Lo->n == Po->n);6 assert (Xo->n > 2); 7 assert (Xo->n == Yo->n); 8 assert (Xo->n == Po->n); 9 9 10 10 // arrays to hold the data to be fitted 11 psArray *x = psArrayAlloc(2* Lo->n);12 psVector *y = psVectorAlloc(2* Lo->n, PS_TYPE_F32);11 psArray *x = psArrayAlloc(2*Xo->n); 12 psVector *y = psVectorAlloc(2*Xo->n, PS_TYPE_F32); 13 13 14 14 int n = 0; 15 for (int i = 0; i < Lo->n; i++) {15 for (int i = 0; i < Xo->n; i++) { 16 16 17 17 psVector *coord = NULL; 18 18 19 // Lcoordinate value19 // X coordinate value 20 20 coord = psVectorAlloc (2, PS_TYPE_F32); 21 21 coord->data.F32[1] = 0.0; 22 22 coord->data.F32[0] = Po->data.F32[i]; 23 23 x->data[n] = coord; 24 y->data.F32[n] = Lo->data.F32[i];24 y->data.F32[n] = Xo->data.F32[i]; 25 25 n++; 26 26 27 // Mcoordinate value27 // Y coordinate value 28 28 coord = psVectorAlloc (2, PS_TYPE_F32); 29 29 coord->data.F32[1] = 1.0; 30 30 coord->data.F32[0] = Po->data.F32[i]; 31 31 x->data[n] = coord; 32 y->data.F32[n] = Mo->data.F32[i];32 y->data.F32[n] = Yo->data.F32[i]; 33 33 n++; 34 34 } … … 47 47 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_MAX | PS_STAT_MIN); 48 48 49 // center ( Lo) = mean(Lo), RL= range / 250 psVectorStats (stats, Lo, NULL, NULL, 0);51 params->data.F32[PAR_ L0] = stats->sampleMean;52 params->data.F32[PAR_R L] = (stats->max - stats->min) / 2.0;49 // center (Xo) = mean(Xo), RX = range / 2 50 psVectorStats (stats, Xo, NULL, NULL, 0); 51 params->data.F32[PAR_X0] = stats->sampleMean; 52 params->data.F32[PAR_RX] = (stats->max - stats->min) / 2.0; 53 53 54 // center ( Mo) = mean(Mo), RM= range / 255 psVectorStats (stats, Mo, NULL, NULL, 0);56 params->data.F32[PAR_ M0] = stats->sampleMean;57 params->data.F32[PAR_R M] = (stats->max - stats->min) / 2.0;54 // center (Yo) = mean(Yo), RY = range / 2 55 psVectorStats (stats, Yo, NULL, NULL, 0); 56 params->data.F32[PAR_Y0] = stats->sampleMean; 57 params->data.F32[PAR_RY] = (stats->max - stats->min) / 2.0; 58 58 59 59 params->data.F32[PAR_P0] = 0.0; … … 63 63 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); 64 64 65 fprintf (stderr, "guess values:\n");66 fprintf (stderr, "Lo: %f\n", params->data.F32[PAR_L0]);67 fprintf (stderr, "Mo: %f\n", params->data.F32[PAR_M0]);68 fprintf (stderr, "RL: %f\n", params->data.F32[PAR_RL]);69 fprintf (stderr, "RM: %f\n", params->data.F32[PAR_RM]);70 fprintf (stderr, "P0: %f\n", params->data.F32[PAR_P0]);71 fprintf (stderr, "T0: %f\n", params->data.F32[PAR_T0]);65 // fprintf (stderr, "guess values:\n"); 66 // fprintf (stderr, "Xo: %f\n", params->data.F32[PAR_X0]); 67 // fprintf (stderr, "Yo: %f\n", params->data.F32[PAR_Y0]); 68 // fprintf (stderr, "RX: %f\n", params->data.F32[PAR_RX]); 69 // fprintf (stderr, "RY: %f\n", params->data.F32[PAR_RY]); 70 // fprintf (stderr, "P0: %f\n", params->data.F32[PAR_P0]); 71 // fprintf (stderr, "T0: %f\n", params->data.F32[PAR_T0]); 72 72 73 73 // XXX skip the weights for now … … 75 75 76 76 fprintf (stderr, "fitted values:\n"); 77 fprintf (stderr, " Lo: %f\n", params->data.F32[PAR_L0]);78 fprintf (stderr, " Mo: %f\n", params->data.F32[PAR_M0]);79 fprintf (stderr, "R L: %f\n", params->data.F32[PAR_RL]);80 fprintf (stderr, "R M: %f\n", params->data.F32[PAR_RM]);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 81 fprintf (stderr, "P0: %f\n", params->data.F32[PAR_P0]); 82 82 fprintf (stderr, "T0: %f\n", params->data.F32[PAR_T0]); 83 83 84 return true;84 return params; 85 85 } 86 87 # if (0)88 # undef PAR_L089 # undef PAR_RL90 # undef PAR_PHI91 # define PAR_L0 092 # define PAR_RL 193 # define PAR_PHI 294 95 // we now have a set of observed L,M values. fit these to the boresite model96 bool psastroModelFitBoresite_L (psVector *Lo, psVector *Mo, psVector *Po) {97 98 assert (Lo->n > 2);99 assert (Lo->n == Mo->n);100 assert (Lo->n == Po->n);101 102 // arrays to hold the data to be fitted103 psArray *x = psArrayAlloc(Lo->n);104 psVector *y = psVectorAlloc(Lo->n, PS_TYPE_F32);105 106 for (int i = 0; i < Lo->n; i++) {107 108 psVector *coord = NULL;109 110 // L coordinate value111 coord = psVectorAlloc (1, PS_TYPE_F32);112 coord->data.F32[0] = Po->data.F32[i];113 x->data[i] = coord;114 y->data.F32[i] = Lo->data.F32[i];115 }116 117 psVector *params = psVectorAlloc (3, PS_TYPE_F32);118 119 // create the minimization constraints120 psMinConstraint *constraint = psMinConstraintAlloc();121 122 // XXX for now, no parameter masks, skip checkLimits123 // constraint->checkLimits = psastroModelBoresiteLimits;124 125 // make an initial guess:126 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_MAX | PS_STAT_MIN);127 128 // center (Lo) = mean(Lo), RL = range / 2129 psVectorStats (stats, Lo, NULL, NULL, 0);130 params->data.F32[PAR_L0] = stats->sampleMean;131 params->data.F32[PAR_RL] = (stats->max - stats->min) / 2.0;132 params->data.F32[PAR_PHI] = 0.0;133 134 psMinimization *myMin = psMinimizationAlloc (15, 0.001);135 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);136 137 fprintf (stderr, "guess values:\n");138 fprintf (stderr, "Lo: %f\n", params->data.F32[PAR_L0]);139 fprintf (stderr, "RL: %f\n", params->data.F32[PAR_RL]);140 fprintf (stderr, "phi: %f\n", params->data.F32[PAR_PHI]);141 142 // XXX skip the weights for now143 psMinimizeLMChi2(myMin, covar, params, constraint, x, y, NULL, psastroModelBoresiteL);144 145 fprintf (stderr, "fitted values:\n");146 fprintf (stderr, "Lo: %f\n", params->data.F32[PAR_L0]);147 fprintf (stderr, "RL: %f\n", params->data.F32[PAR_RL]);148 fprintf (stderr, "phi: %f\n", params->data.F32[PAR_PHI]);149 150 return true;151 }152 153 // we now have a set of observed L,M values. fit these to the boresite model154 bool psastroModelFitBoresite (psVector *Lo, psVector *Mo, psVector *Po) {155 156 assert (Lo->n > 2);157 assert (Lo->n == Mo->n);158 assert (Lo->n == Po->n);159 160 // arrays to hold the data to be fitted161 psArray *x = psArrayAlloc(Lo->n);162 psVector *y = psVectorAlloc(Lo->n, PS_TYPE_F32);163 164 for (int i = 0; i < Lo->n; i++) {165 166 psVector *coord = NULL;167 168 // L coordinate value169 coord = psVectorAlloc (1, PS_TYPE_F32);170 coord->data.F32[0] = Po->data.F32[i];171 x->data[i] = coord;172 y->data.F32[i] = Mo->data.F32[i];173 }174 175 psVector *params = psVectorAlloc (3, PS_TYPE_F32);176 177 // create the minimization constraints178 psMinConstraint *constraint = psMinConstraintAlloc();179 180 // XXX for now, no parameter masks, skip checkLimits181 // constraint->checkLimits = psastroModelBoresiteLimits;182 183 // make an initial guess:184 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_MAX | PS_STAT_MIN);185 186 // center (Lo) = mean(Lo), RL = range / 2187 psVectorStats (stats, Mo, NULL, NULL, 0);188 params->data.F32[PAR_L0] = stats->sampleMean;189 params->data.F32[PAR_RL] = (stats->max - stats->min) / 2.0;190 params->data.F32[PAR_PHI] = 0.0;191 192 psMinimization *myMin = psMinimizationAlloc (15, 0.001);193 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32);194 195 fprintf (stderr, "guess values:\n");196 fprintf (stderr, "Lo: %f\n", params->data.F32[PAR_L0]);197 fprintf (stderr, "RL: %f\n", params->data.F32[PAR_RL]);198 fprintf (stderr, "phi: %f\n", params->data.F32[PAR_PHI]);199 200 // XXX skip the weights for now201 psMinimizeLMChi2(myMin, covar, params, constraint, x, y, NULL, psastroModelBoresiteM);202 203 fprintf (stderr, "fitted values:\n");204 fprintf (stderr, "Lo: %f\n", params->data.F32[PAR_L0]);205 fprintf (stderr, "RL: %f\n", params->data.F32[PAR_RL]);206 fprintf (stderr, "phi: %f\n", params->data.F32[PAR_PHI]);207 208 return true;209 }210 # endif -
trunk/psastro/src/psastroModelParseCamera.c
r15880 r15891 18 18 19 19 // set up an output fpa structure & file based on the last input file 20 pmFPAfile *output = pmFPAfileDefineOutput (config, input->fpa, "PSASTRO. MODEL");20 pmFPAfile *output = pmFPAfileDefineOutput (config, input->fpa, "PSASTRO.OUT.MODEL"); 21 21 if (!output) { 22 psError(PSASTRO_ERR_CONFIG, false, "Failed to build FPA for PSASTRO. MODEL from input");22 psError(PSASTRO_ERR_CONFIG, false, "Failed to build FPA for PSASTRO.OUT.MODEL from input"); 23 23 return false; 24 24 } -
trunk/psastro/src/psastroMosaicAstrom.c
r15638 r15891 23 23 // before we do object matches, we need to (optionally) fix failed chips. We compare chips with 24 24 // the supplied mosaic model. Adjust significant outliers to match model. 25 if (!psastro EnforceChips (config, fpa, recipe)) {25 if (!psastroFixChips (config, recipe)) { 26 26 psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips"); 27 27 return false; -
trunk/psastro/src/psastroStandAlone.h
r15887 r15891 17 17 bool psastroDataLoad (pmConfig *config); 18 18 19 pmConfig *psastroModelArguments (int argc, char **argv); 20 bool psastroModelParseCamera (pmConfig *config); 21 bool psastroModelDataLoad (pmConfig *config); 22 bool psastroModelAnalysis (pmConfig *config); 19 pmConfig *psastroModelArguments (int argc, char **argv); 20 bool psastroModelParseCamera (pmConfig *config); 21 bool psastroModelDataLoad (pmConfig *config); 22 bool psastroModelAnalysis (pmConfig *config); 23 bool psastroModelAdjust (pmConfig *config); 24 bool psastroModelDataSave (pmConfig *config); 23 25 24 bool psastroModelFitBoresite (psVector *Lo, psVector *Mo, psVector *Po); 25 psF32 psastroModelBoresite (psVector *deriv, const psVector *params, const psVector *coord); 26 27 psF32 psastroModelBoresiteL (psVector *deriv, const psVector *params, const psVector *coord); 28 psF32 psastroModelBoresiteM (psVector *deriv, const psVector *params, const psVector *coord); 26 psVector *psastroModelFitBoresite (psVector *Xo, psVector *Yo, psVector *Po); 27 psF32 psastroModelBoresite (psVector *deriv, const psVector *params, const psVector *coord); 29 28 30 29 // these are used to define the boresite model parameters 31 # define PAR_ L0 0 // Lo = params[0]32 # define PAR_ M0 1 // Mo = params[1]33 # define PAR_R L 2 // RL= params[2]34 # define PAR_R M 3 // RM= params[3]30 # define PAR_X0 0 // Xo = params[0] 31 # define PAR_Y0 1 // Yo = params[1] 32 # define PAR_RX 2 // RX = params[2] 33 # define PAR_RY 3 // RY = params[3] 35 34 # define PAR_P0 4 // P0 = params[4] 36 35 # define PAR_T0 5 // phi = params[4]
Note:
See TracChangeset
for help on using the changeset viewer.
