Changeset 5506
- Timestamp:
- Nov 11, 2005, 9:54:59 AM (20 years ago)
- Location:
- trunk/psastro/src
- Files:
-
- 1 added
- 2 edited
-
psModUtils.c (added)
-
psastro.h (modified) (1 diff)
-
psastroBuildFPA.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastro.h
r5360 r5506 3 3 # include <unistd.h> // for unlink 4 4 # include <pslib.h> 5 # include "psLibUtils.h"6 # include "pmObjects_EAM.h"7 # include "psModulesUtils.h"8 # include "pmPSF.h"9 # include "pmPSFtry.h"10 # include "pmModelGroup.h"11 5 12 typedef struct { 13 psImage *image; 14 psImage *mask; 15 psImage *weight; 16 psMetadata *header; 17 } eamReadout; 6 typedef struct 7 { 8 psProjection *toSky; ///< Projection from tangent plane to sky 9 psPlaneDistort *toTPA; ///< Transformation from focal plane to tangent plane 10 psPlaneDistort *fromTPA; ///< Transformation from focal plane to tangent plane 11 psArray *chips; ///< The chips 12 } 13 pmFPA; 18 14 19 // top-level psphot functions 20 psMetadata *psphotArguments (int *argc, char **argv); 21 eamReadout *psphotSetup (psMetadata *config); 22 psStats *psphotImageStats (eamReadout *imdata, psMetadata *config); 23 psArray *psphotSourceStats (eamReadout *imdata, psMetadata *config, psArray *allpeaks); 24 pmPSF *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *sky); 25 bool psphotApplyPSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky); 26 bool psphotFitGalaxies (eamReadout *imdata, psMetadata *config, psArray *sources, psStats *skyStats); 27 void psphotOutput (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky); 15 typedef struct 16 { 17 // Astrometric transformations 18 psPlaneTransform *toFPA; ///< Transformation from chip to FPA coordinates 19 psPlaneTransform *fromFPA; ///< Transformation from FPA to chip coordinates 20 psArray *cells; ///< The cells 21 } 22 pmChip; 28 23 29 bool psphotMarkPSF (pmSource *source, float shapeNsigma, float minSN, float maxChi, float SATURATE); 30 bool psphotSubtractPSF (pmSource *source); 31 int psphotSortBySN (const void **a, const void **b); 32 int psphotSaveImage (psMetadata *header, psImage *image, char *filename); 33 bool psphotDefinePixels (pmSource *mySource, const eamReadout *imdata, psF32 x, psF32 y, psF32 Radius); 24 typedef struct 25 { 26 // Astrometric transformations 27 psPlaneTransform *toChip; ///< Transformations from cell to chip coordinates 28 psArray *readouts; ///< The readouts (referred to by number) 29 psMetadata *header; ///< header always corresponds to a cell 30 } 31 pmCell; 34 32 35 psArray *pmPeaksSigmaLimit (eamReadout *imdata, psMetadata *config, psStats *sky); 36 pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, float apRadius); 37 pmModel *pmSourceSelectModel (pmSource *source); 33 typedef struct 34 { 35 // Position on the cell 36 int col0; ///< Offset from the left of chip. 37 int row0; ///< Offset from the bottom of chip. 38 int colBins; ///< Amount of binning in x-dimension 39 int rowBins; ///< Amount of binning in y-dimension 40 psArray *objects; ///< sources detected / measured on readout 41 } 42 pmReadout; 38 43 39 // eamReadout functions 40 eamReadout *eamReadoutAlloc (psImage *image, psImage *noise, psImage *mask, psMetadata *header); 41 42 // output functions 43 bool pmSourcesWriteText (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 44 bool pmSourcesWriteOBJ (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 45 bool pmSourcesWriteCMP (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 46 bool pmSourcesWriteCMF (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 47 bool pmSourcesWriteSX (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 48 49 bool pmPeaksWriteText (psArray *sources, char *filename); 50 bool pmMomentsWriteText (psArray *sources, char *filename); 51 bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf); 52 bool pmModelWriteFLTs (psArray *sources, char *filename); 53 bool pmModelWriteNULLs (psArray *sources, char *filename); 54 55 int pmSourcesDophotType (pmSource *source); 44 // dummy structure for template code (psFooAlloc, etc) 45 typedef struct 46 { 47 int i; 48 } 49 psFoo; -
trunk/psastro/src/psastroBuildFPA.c
r5505 r5506 1 1 # include "psastro.h" 2 2 3 pmFPA *psastroBuildFPA (psMetadata *header, psMetadata *config) { 4 5 // this function constructs a basic template pmFPA structure based on the information in the header 6 // metadata. it converts the astrometric information in the header (WCS, etc) to the corresponding 7 // pmFPA/pmChip, etc distortion and projection elements. 8 9 // this implementation is basic, assuming a single readout,chip,cell 10 // I will not handle the datasec/biassec information to define the readout/cell 11 // these things are already handled by Paul's code. this function simple looks for the WCS information 12 // and provides those conversions. 13 14 int Nchips = 1; 15 int Ncells = 1; 16 int Nreadouts = 1; 17 18 // allocate the structures 19 20 pmFPA *fpa = pmFPAAlloc (); 21 22 fpa->chips = psArrayAlloc (Nchips); 23 for (int i = 0; i < Nchips; i++) { 24 25 pmChip *chip = pmChipAlloc (); 26 chip->fpa = fpa; // assign parent fpa (view only; don't free) 27 28 chip->cells = psArrayAlloc (Ncells); 29 for (int j = 0; j < Ncells; j++) { 30 31 pmCell *cell = pmCellAlloc (); 32 cell->chip = chip; // assign parent chip (view only; don't free) 33 cell->header = header; 34 35 pmCellInterpretWCS (cell, header); 36 37 cell->readouts = psArrayAlloc (Nreadouts); 38 for (int k = 0; k < Nreadouts; k++) { 39 40 pmReadout *readout = pmReadoutAlloc (); 41 cells->readouts->data[j] = readout; 42 } 43 chips->cells->data[j] = cell; 44 } 45 fpa->chips->data[i] = chip; 46 } 47 return (fpa); 48 } 49 50 // interpret header WCS 51 bool pmCellInterpretWCS (pmCell *cell, psMetadata *header) { 52 53 float crval1, crval2, crpix1, crpix2, cdelt1, cdelt2; 54 float pc1_1, pc1_2, pc2_1, pc2_2; 55 56 // *** interpret header data, convert to crval(i), etc 57 char *ctype = pmMetadataLookupPtr (&status, header, "CTYPE2"); 58 if (!status) { 59 psLogMsg ("psastro", 2, "warning: no WCS metadata in header\n"); 60 return false; 61 } 62 63 // determine projection type 64 type = PS_PROJ_NTYPE; 65 if (!strcmp (&ctype[4], "-SIN")) type = PS_PROJ_SIN; 66 if (!strcmp (&ctype[4], "-TAN")) type = PS_PROJ_TAN; 67 if (!strcmp (&ctype[4], "-AIT")) type = PS_PROJ_AIT; 68 if (!strcmp (&ctype[4], "-PAR")) type = PS_PROJ_PAR; 69 if (type == PS_PROJ_NTYPE) { 70 psLogMsg ("psastro", 2, "warning: unknown projection type %s\n", ctype); 71 return false; 72 } 73 74 crval1 = psMetadataLookupF32 (&status, header, "CRVAL1"); 75 crval2 = psMetadataLookupF32 (&status, header, "CRVAL2"); 76 crpix1 = psMetadataLookupF32 (&status, header, "CRPIX1"); 77 crpix2 = psMetadataLookupF32 (&status, header, "CRPIX2"); 78 79 // test the CDELTi varient 80 cdelt1 = psMetadataLookupF32 (&status, header, "CDELT1"); 81 if (status) { 82 cdelt2 = psMetadataLookupF32 (&status, header, "CDELT2"); 83 84 // test the CROTAi varient: 85 float rotate = psMetadataLookupF32 (&status, header, "CROTA2"); 86 if (status) { 87 Lambda = cdelt2 / cdelt1; 88 pc1_1 = cos(rotate*RAD_DEG); 89 pc1_2 = -sin(rotate*RAD_DEG) * Lambda; 90 pc2_1 = sin(rotate*RAD_DEG) / Lambda; 91 pc2_2 = cos(rotate*RAD_DEG); 92 goto got_matrix; 93 } 94 95 // test the PC00i00j varient: 96 pc1_1 = psMetadataLookupF32 (&status, header, "PC001001"); 97 if (status) { 98 pc1_2 = psMetadataLookupF32 (&status, header, "PC001002"); 99 pc2_1 = psMetadataLookupF32 (&status, header, "PC002001"); 100 pc2_2 = psMetadataLookupF32 (&status, header, "PC002002"); 101 102 // XXX EAM : add Elixir polynomial terms here eventually 103 goto got_matrix; 104 } 105 psLogMsg ("psastro", 2, "warning: missing rotation matrix?\n"); 106 return false; 107 } 108 109 // test the CDi_j varient 110 pc1_1 = psMetadataLookupF32 (&status, header, "CD1_1"); 111 if (status) { 112 pc1_2 = psMetadataLookupF32 (&status, header, "CD1_2"); 113 pc2_1 = psMetadataLookupF32 (&status, header, "CD2_1"); 114 pc2_2 = psMetadataLookupF32 (&status, header, "CD2_2"); 115 116 // renormalize to cdelt1, cdelt2, etc 117 float scale = hypot (pc1_1, pc1_2); 118 cdelt1 = cdelt2 = scale; 119 pc1_1 /= scale; 120 pc1_2 /= scale; 121 pc2_1 /= scale; 122 pc2_2 /= scale; 123 goto got_matrix; 124 } 125 psLogMsg ("psastro", 2, "warning: missing rotation matrix?\n"); 126 return false; 127 128 got_matrix: 129 130 // XXX EAM : these must already be set 131 chip = cell->chip; 132 fpa = chip->fpa; 133 134 // set toChip to identity as default 135 // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581) 136 cell->toChip = psPlaneTransformAlloc (2, 2); 137 cell->toChip->x->coeff[1][0] = 1; 138 cell->toChip->x->mask[1][1] = 1; 139 140 cell->toChip->y->coeff[0][1] = 1; 141 cell->toChip->y->mask[1][1] = 1; 142 143 // XXX EAM : if fpa->toSky and fpa->toTPA are already defined, then the 144 // toFPA must be modified to match the crval(i), scale(i) and crpix(i) 145 146 // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581) 147 chip->toFPA = psPlaneTransformAlloc (2, 2); 148 149 chip->toFPA->x->coeff[0][0] = crpix1; 150 chip->toFPA->x->coeff[1][0] = pc1_1; 151 chip->toFPA->x->coeff[0][1] = pc1_2; 152 chip->toFPA->x->mask[1][1] = 1; 153 154 chip->toFPA->y->coeff[0][0] = crpix2; 155 chip->toFPA->y->coeff[1][0] = pc2_1; 156 chip->toFPA->y->coeff[0][1] = pc2_2; 157 chip->toFPA->y->mask[1][1] = 1; 158 159 // set toTPA to identity as default 160 // XXX EAM : psPlaneDistortAlloc uses nTerm not nOrder (bug 581) 161 if (fpa->toTPA == NULL) { 162 fpa->toTPA = psPlaneDistortAlloc (2, 2, 1, 1); 163 fpa->toTPA->x->coeff[1][0][0][0] = 1; 164 fpa->toTPA->x->mask[1][1][0][0] = 1; 165 166 fpa->toTPA->y->coeff[0][1][0][0] = 1; 167 fpa->toTPA->y->mask[1][1][0][0] = 1; 168 } else { 169 psLogMsg ("psastro", 2, "warning: fpa distortion already defined\n"); 170 } 171 172 // center of projection is (0,0) coordinate of TPA 173 fpa->toSky = psProjectionAlloc (crval1, crval2, cdelt1, cdelt2, type); 174 return true; 175 }
Note:
See TracChangeset
for help on using the changeset viewer.
