Changeset 9627
- Timestamp:
- Oct 18, 2006, 8:44:12 AM (20 years ago)
- Location:
- trunk/psastro/src
- Files:
-
- 11 edited
-
Makefile.am (modified) (1 diff)
-
psastro.c (modified) (8 diffs)
-
psastro.h (modified) (3 diffs)
-
psastroArguments.c (modified) (1 diff)
-
psastroAstromGuess.c (modified) (2 diffs)
-
psastroChipAstrom.c (modified) (1 diff)
-
psastroChooseRefstars.c (modified) (1 diff)
-
psastroErrorCodes.dat (modified) (1 diff)
-
psastroLoadRefstars.c (modified) (5 diffs)
-
psastroLuminosityFunction.c (modified) (6 diffs)
-
psastroRefstarSubset.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/Makefile.am
r9587 r9627 13 13 libpsastro_la_SOURCES = \ 14 14 psastroArguments.c \ 15 psastroCleanup.c \ 15 16 psastroParseCamera.c \ 16 17 psastroDataLoad.c \ -
trunk/psastro/src/psastro.c
r9587 r9627 2 2 3 3 static void usage (void) { 4 psErrorStackPrint(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output) ");4 psErrorStackPrint(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n"); 5 5 exit (2); 6 6 } … … 20 20 // load identify the data sources 21 21 if (!psastroParseCamera (config)) { 22 psErrorStackPrint(stderr, "error setting up the camera ");22 psErrorStackPrint(stderr, "error setting up the camera\n"); 23 23 exit (1); 24 24 } … … 27 27 // select subset of stars for astrometry 28 28 if (!psastroDataLoad (config)) { 29 psErrorStackPrint(stderr, "error loading input data ");29 psErrorStackPrint(stderr, "error loading input data\n"); 30 30 exit (1); 31 31 } … … 34 34 // apply the initial guess 35 35 if (!psastroAstromGuess (config)) { 36 psErrorStackPrint(stderr, "failed to determine initial astrometry guess ");36 psErrorStackPrint(stderr, "failed to determine initial astrometry guess\n"); 37 37 exit (1); 38 38 } … … 41 41 psArray *refs = psastroLoadRefstars (config); 42 42 if (!refs) { 43 psErrorStackPrint(stderr, "failed to load reference data ");43 psErrorStackPrint(stderr, "failed to load reference data\n"); 44 44 exit (1); 45 45 } 46 46 47 47 // choose reference stars corresponding to the selected chips 48 if ( psastroChooseRefstars (config, refs)) {49 psErrorStackPrint(stderr, "failed to select reference data for chips ");48 if (!psastroChooseRefstars (config, refs)) { 49 psErrorStackPrint(stderr, "failed to select reference data for chips\n"); 50 50 exit (1); 51 51 } … … 54 54 if (mosastro == NULL) { 55 55 if (!psastroChipAstrom (config, refs)) { 56 psErrorStackPrint(stderr, "failed to perform single chip astrometry ");56 psErrorStackPrint(stderr, "failed to perform single chip astrometry\n"); 57 57 exit (1); 58 58 } 59 59 } else { 60 60 if (!psastroMosaicAstrom (config, refs)) { 61 psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry ");61 psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry\n"); 62 62 exit (1); 63 63 } … … 69 69 // write out the results 70 70 if (!psastroDataSave (config)) { 71 psErrorStackPrint(stderr, "failed to write out data ");71 psErrorStackPrint(stderr, "failed to write out data\n"); 72 72 exit (1); 73 73 } … … 75 75 psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete")); 76 76 77 psFree (refs); 78 psFree (config); 79 80 psTimerStop (); 81 psMemCheckCorruption (true); 82 pmModelGroupCleanup (); 83 psTimeFinalize (); 84 pmConceptsDone (); 85 pmConfigDone (); 86 // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psastro"); 87 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psastro"); 88 89 exit (0); 77 psastroCleanup (config, refs); 78 exit (EXIT_SUCCESS); 90 79 } -
trunk/psastro/src/psastro.h
r9587 r9627 31 31 32 32 pmConfig *psastroArguments (int argc, char **argv); 33 void psastroCleanup (pmConfig *config, psArray *refs); 33 34 bool psastroParseCamera (pmConfig *config); 34 35 bool psastroDataLoad (pmConfig *config); … … 44 45 psPlaneDistort *psPlaneDistortIdentity (); 45 46 46 psArray *psastroLoadRef erences (pmConfig *config);47 psArray *psastroLoadRefstars (pmConfig *config); 47 48 bool psastroChipAstrom (pmConfig *config, psArray *refs); 48 49 bool psastroOneChip (pmFPA *fpa, pmChip *chip, psArray *refset, psArray *rawset, psMetadata *recipe, psMetadata *updates); 50 bool psastroChooseRefstars (pmConfig *config, psArray *refs); 51 bool psastroRefstarSubset (pmReadout *readout); 52 pmLumFunc *psastroLuminosityFunction (psArray *stars); 49 53 50 54 // utility functions: … … 56 60 psArray *psastroMosaicGetGrads (pmFPA *fpa, psMetadata *recipe); 57 61 bool psastroMosaicAstrom (pmConfig *config, psArray *refs); 58 bool psastroMosaicGetRefstars (pmConfig *config, psArray *refs);59 62 bool psastroMosaicChipAstrom (pmFPA *fpa, psMetadata *recipe); 60 63 bool psastroMosaicSetMatch (pmFPA *fpa, psMetadata *recipe); -
trunk/psastro/src/psastroArguments.c
r9574 r9627 27 27 // load config data from default locations 28 28 pmConfig *config = pmConfigRead(&argc, argv); 29 if (config == NULL) { 30 psError(PSASTRO_ERR_CONFIG, false, "Can't read site configuration"); 31 return NULL; 32 } 29 33 30 34 // save these recipe options until we have loaded the options -
trunk/psastro/src/psastroAstromGuess.c
r9574 r9627 80 80 p_psDeproject (raw->sky, raw->TP, fpa->projection); 81 81 82 if ((i < 10) && (psTraceGetLevel("psastro .guess") > 5)) {82 if ((i < 10) && (psTraceGetLevel("psastro") > 5)) { 83 83 fprintf (stderr, "up: %f,%f -> %f,%f -> %f,%f -> %f,%f\n", 84 84 raw->chip->x, raw->chip->y, … … 100 100 tp->x, tp->y, 101 101 raw->sky->r, raw->sky->d); 102 103 psFree (fp); 104 psFree (tp); 105 psFree (ch); 102 106 } 103 107 -
trunk/psastro/src/psastroChipAstrom.c
r9574 r9627 54 54 pmAstromWriteWCS (chip->toFPA, fpa->toSky, updates, plateScale); 55 55 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_DATA_METADATA, "psastro header stats", updates); 56 psFree (updates); 56 57 } 57 58 } -
trunk/psastro/src/psastroChooseRefstars.c
r9587 r9627 79 79 80 80 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars); 81 psFree (refstars); 81 82 82 83 psastroRefstarSubset (readout); 83 84 psFree (refstars);85 84 } 86 85 } -
trunk/psastro/src/psastroErrorCodes.dat
r9575 r9627 7 7 ARGUMENTS Incorrect arguments 8 8 CONFIG Problem in configure files 9 FITS Problem in FITS I/O 10 FITS_WCS Error interpreting FITS WCS information 11 PHOTOM Problem in photometry 12 PSF Problem in PSF 13 APERTURE Problem with aperture photometry 9 IO Problem in FITS I/O 10 WCS Error interpreting FITS WCS information 11 DATA Problem in data values -
trunk/psastro/src/psastroLoadRefstars.c
r9587 r9627 20 20 float DECmin = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MIN"); 21 21 float DECmax = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MAX"); 22 float MAGmax = psMetadataLookupF32(NULL, recipe, "MAG_MAX"); 22 23 23 24 char *CATDIR = psMetadataLookupStr(NULL, recipe, "DVO.CATDIR"); … … 38 39 close (fd); 39 40 41 psTimerStart ("psastro"); 42 40 43 // use fork to add timeout capability 41 44 // use cfitsio |filename format to avoid tempFile 42 45 # if ELIXIR_MODE 43 46 if (CATDIR) { 44 sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT elixir -D CATMODE mef - region %f %f %f %f -o %s", CATDIR, RAmin, DECmin, RAmax, DECmax, tempFile);47 sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT elixir -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", CATDIR, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile); 45 48 } else { 46 sprintf (tempLine, "getstar -D CATFORMAT elixir -D CATMODE mef - region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);49 sprintf (tempLine, "getstar -D CATFORMAT elixir -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile); 47 50 } 48 51 # else 49 52 if (CATDIR) { 50 sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT panstarrs -D CATMODE mef - region %f %f %f %f -o %s", CATDIR, RAmin, DECmin, RAmax, DECmax, tempFile);53 sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT panstarrs -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", CATDIR, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile); 51 54 } else { 52 sprintf (tempLine, "getstar -D CATFORMAT panstarrs -D CATMODE mef - region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);55 sprintf (tempLine, "getstar -D CATFORMAT panstarrs -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile); 53 56 } 54 57 # endif … … 61 64 } 62 65 66 psLogMsg ("psastro", 3, "ran getstar : %f sec\n", psTimerMark ("psastro")); 67 63 68 // the output from getstar is a file with the Average table 64 69 psFits *fits = psFitsOpen (tempFile, "r"); … … 70 75 # endif 71 76 77 psTimerStart ("psastro"); 72 78 psMetadata *header = psFitsReadHeader (NULL, fits); 73 79 psArray *table = psFitsReadTable (fits); 74 80 psFitsClose (fits); 81 75 82 unlink (tempFile); 83 psLogMsg ("psastro", 3, "read getstar output table : %f sec\n", psTimerMark ("psastro")); 76 84 77 85 // convert the Average table to the pmAstromObj entries 86 psTimerStart ("psastro"); 78 87 psArray *refs = psArrayAlloc (table->n); 79 88 for (int i = 0; i < table->n; i++) { … … 98 107 psFree (header); 99 108 psFree (table); 109 psLogMsg ("psastro", 3, "converted table to pmAstromObj : %f sec\n", psTimerMark ("psastro")); 100 110 101 111 psTrace ("psastro", 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n", 102 112 refs->n, RAmin, DECmin, RAmax, DECmax); 113 103 114 return refs; 104 115 } -
trunk/psastro/src/psastroLuminosityFunction.c
r9587 r9627 15 15 psMemSetDeallocator(func, (psFreeFunc) pmLumFuncFree); 16 16 17 func->mMin = 0;18 func->mMax = 0;19 func->slope = 0;20 func->offset = 0;17 func->mMin = mMin; 18 func->mMax = mMax; 19 func->slope = slope; 20 func->offset = offset; 21 21 22 22 return func; 23 23 } 24 24 25 pmLumFunc *psastro RefstarSubset(psArray *stars) {25 pmLumFunc *psastroLuminosityFunction (psArray *stars) { 26 26 27 27 // determine the max and min magnitude for the array of stars 28 28 pmAstromObj *star = stars->data[0]; 29 mMin = star->Mag;30 mMax = star->Mag;29 double mMin = star->Mag; 30 double mMax = star->Mag; 31 31 for (int i = 0; i < stars->n; i++) { 32 32 star = stars->data[i]; … … 35 35 } 36 36 37 int nBin = 1 + ( nMax - nMin) / dMag;37 int nBin = 1 + (mMax - mMin) / dMag; 38 38 if (nBin <= 1) { 39 39 psError(PSASTRO_ERR_DATA, true, "magnitude range of 0.0\n"); … … 45 45 // bin[i] = mMin + i*dMag : mMin + (i+1)*dMag 46 46 psVector *nMags = psVectorAlloc (nBin, PS_TYPE_F32); 47 nMags->n = nBin; 48 psVectorInit (nMags, 0); 49 47 50 for (int i = 0; i < stars->n; i++) { 48 51 star = stars->data[i]; 49 52 int bin = (star->Mag - mMin) / dMag; 50 53 nMags->data.F32[bin] += 1.0; 54 } 55 56 // find the peak and position 57 int iPeak = 0; 58 int nPeak = 0; 59 for (int i = 0; i < nMags->n; i++) { 60 if (nMags->data.F32[i] < nPeak) continue; 61 iPeak = i; 62 nPeak = nMags->data.F32[i]; 51 63 } 52 64 … … 56 68 // create 2 vectors represnting the dlogN/dlogS line 57 69 // exclude bins with no stars 70 // exclude points after the peak with N < 0.8*peak 58 71 int n = 0; 59 for (int i = 0; i < stars->n; i++) {72 for (int i = 0; i < nMags->n; i++) { 60 73 if (nMags->data.F32[i] < 1) continue; 74 if ((i > iPeak) && (nMags->data.F32[i] < 0.8*nPeak)) continue; 61 75 lnMag->data.F32[n] = log10 (nMags->data.F32[i]); 62 76 Mag->data.F32[n] = mMin + (i + 0.5)*dMag; 63 77 n++; 64 78 } 79 lnMag->n = n; 80 Mag->n = n; 81 psLogMsg ("psastro", 4, "fitting %d points to luminosity function\n", n); 65 82 66 83 psVector *mask = psVectorAlloc (nBin, PS_TYPE_MASK); 84 mask->n = Mag->n; 85 psVectorInit (mask, 0); 86 67 87 psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1); 68 88 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); … … 70 90 stats->clipIter = 3; 71 91 72 line = psVectorClipFitPolynomial1D(line, stats, mask, 1, lnMag, NULL, Mag);92 line = psVectorClipFitPolynomial1D(line, stats, mask, 0xff, lnMag, NULL, Mag); 73 93 74 94 // find min and max unmasked magnitudes 75 mMinValid = NAN;76 mMaxValid = NAN;95 double mMinValid = NAN; 96 double mMaxValid = NAN; 77 97 for (int i = 0; i < Mag->n; i++) { 78 98 if (mask->data.U8[i]) continue; … … 89 109 90 110 pmLumFunc *lumFunc = pmLumFuncAlloc (mMinValid, mMaxValid, line->coeff[0], line->coeff[1]); 111 112 psFree (lnMag); 113 psFree (nMags); 114 psFree (Mag); 115 psFree (mask); 116 psFree (line); 117 psFree (stats); 118 91 119 return (lumFunc); 92 120 } -
trunk/psastro/src/psastroRefstarSubset.c
r9587 r9627 5 5 // select the raw objects for this readout 6 6 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS"); 7 if (rawstars == NULL) { continue; } 7 if (rawstars == NULL) { 8 psError(PSASTRO_ERR_DATA, false, "missing rawstars in psastroRefstarSubset\n"); 9 return false; 10 } 8 11 9 12 // select the raw objects for this readout 10 13 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS"); 11 if (refstars == NULL) { continue; } 14 if (refstars == NULL) { 15 psError(PSASTRO_ERR_DATA, false, "missing refstars in psastroRefstarSubset\n"); 16 return false; 17 } 12 18 13 19 // calculate luminosity functions for rawstars and refstars … … 15 21 // is needed... 16 22 pmLumFunc *rawfunc = psastroLuminosityFunction (rawstars); 23 if (rawfunc == NULL) { 24 psError(PSASTRO_ERR_DATA, false, "error measuring rawstar luminosity function\n"); 25 return NULL; 26 } 17 27 pmLumFunc *reffunc = psastroLuminosityFunction (refstars); 28 if (reffunc == NULL) { 29 psError(PSASTRO_ERR_DATA, false, "error measuring refstar luminosity function\n"); 30 return NULL; 31 } 32 33 // XXXX test 34 // psFree (rawfunc); 35 // psFree (reffunc); 36 // return true; 18 37 19 38 // what is the offset between the two lines at the average magnitude? 20 mRef = 0.5*(reffunc->mMin + reffunc->mMax);21 logRho = mRef * reffunc->slope + reffunc->offset;22 mRaw = (logRho - rawfunc->offset) / rawfunc->slope;39 double mRef = 0.5*(reffunc->mMin + reffunc->mMax); 40 double logRho = mRef * reffunc->slope + reffunc->offset; 41 double mRaw = (logRho - rawfunc->offset) / rawfunc->slope; 23 42 24 43 psLogMsg ("psastro", 4, "mRef: %f, logRho: %f, mRaw: %f\n", mRef, logRho, mRaw); 25 44 26 mRefMax = rawfunc->mMax - mRaw + mRef;45 double mRefMax = rawfunc->mMax - mRaw + mRef; 27 46 psLogMsg ("psastro", 4, "clipping stars fainter than %f\n", mRefMax); 28 47 … … 31 50 pmAstromObj *ref = refstars->data[i]; 32 51 if (ref->Mag > mRefMax) continue; 33 psArrayAdd (subset, ref);52 psArrayAdd (subset, 100, ref); 34 53 } 35 54 36 psLogMsg ("psastro", 4, "keeping % d of %d reference stars\n", subset->n, refstars->n);55 psLogMsg ("psastro", 4, "keeping %ld of %ld reference stars\n", subset->n, refstars->n); 37 56 38 57 psMetadataRemoveKey (readout->analysis, "PSASTRO.REFSTARS"); 39 58 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", subset); 40 59 60 psFree (rawfunc); 61 psFree (reffunc); 62 psFree (subset); 63 41 64 return true; 42 65 }
Note:
See TracChangeset
for help on using the changeset viewer.
