Changeset 33104
- Timestamp:
- Jan 15, 2012, 4:28:36 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20111122/Ohana/src
- Files:
-
- 1 added
- 9 edited
-
libautocode/def/FlatCorrection.d (modified) (1 diff)
-
libdvo/Makefile (modified) (1 diff)
-
libdvo/include/dvo.h (modified) (2 diffs)
-
libdvo/src/flatcorr_io.c (modified) (5 diffs)
-
uniphot/Makefile (modified) (1 diff)
-
uniphot/include/uniphot.h (modified) (2 diffs)
-
uniphot/src/load_zpt_table.c (modified) (3 diffs)
-
uniphot/src/match_flatcorr_to_images.c (added)
-
uniphot/src/setphot.c (modified) (3 diffs)
-
uniphot/src/update_catalog_setphot.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/FlatCorrection.d
r33103 r33104 2 2 EXTNAME FLAT_CORRECTION 3 3 TYPE BINTABLE 4 SIZE 204 SIZE 16 5 5 6 6 FIELD ID, ID, int -
branches/eam_branches/ipp-20111122/Ohana/src/libdvo/Makefile
r31636 r33104 70 70 $(SRC)/dvo_convert_PS1_V2.$(ARCH).o \ 71 71 $(SRC)/dvo_convert_PS1_REF.$(ARCH).o \ 72 $(SRC)/flatcorr_io.$(ARCH).o \ 72 73 $(SRC)/skyregion_io.$(ARCH).o \ 73 74 $(SRC)/skyregion_gsc.$(ARCH).o \ -
branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h
r31663 r33104 205 205 } SkyList; 206 206 207 typedef struct { 208 off_t Nimage; 209 FlatCorrectionImage *image; 210 off_t Ncorr; 211 int *IDtoSeq; 212 FlatCorrection *corr; 213 float ***offset; // the correction images represented as a set of arrays (same sequence as *image) 214 } FlatCorrectionTable; 215 207 216 // special-case function: 208 217 CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, off_t *Ndata, char *swapped); … … 484 493 void dvo_image_create (FITS_DB *db, double ZeroPoint); 485 494 495 /* flatcorr APIs */ 496 FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE); 497 int FlatCorrectionInternal(FlatCorrectionTable *flatcorrTable); 498 int FlatCorrectionSave (FlatCorrectionTable *flatcorrTable, char *filename); 499 float FlatCorrectionOffset (FlatCorrectionTable *flatcorr, int ID, int X, int Y); 500 486 501 /* skyregion APIs */ 487 502 int SkyTableSave PROTO((SkyTable *table, char *filename)); -
branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/flatcorr_io.c
r33103 r33104 10 10 */ 11 11 12 typedef struct {13 int Nimage;14 FlatCorrectionImage *image;15 int Ncorr;16 FlatCorrection *corr;17 float ***offset; // the correction images represented as a set of arrays (same sequence as *image)18 } FlatCorrectionTable;19 20 12 FlatCorrectionTable *FlatCorrectionLoad (char *filename, int VERBOSE) { 21 13 … … 25 17 Header theader; 26 18 FTable ftable; 27 int i;28 19 FlatCorrectionTable *flatcorrTable; 29 20 … … 85 76 86 77 // convert the table format to map format: 78 FlatCorrectionInternal (flatcorrTable); 87 79 88 // generate the arrays to hold the corrections 80 return (flatcorrTable); 81 } 82 83 int FlatCorrectionInternal(FlatCorrectionTable *flatcorrTable) { 84 85 int i, j; 86 87 // assert that the internal arrays are not yet allocated? 88 89 // generate the arrays to hold the corrections & initialize 89 90 ALLOCATE (flatcorrTable->offset, float **, flatcorrTable->Nimage); 90 91 for (i = 0; i < flatcorrTable->Nimage; i++) { 91 ALLOCATE (flatcorrTable->offset[i], float *, flatcorrTable->image[i]->Nx);92 for (j = 0; j < flatcorrTable->image[i]->Nx; j++) {93 ALLOCATE (flatcorrTable->offset[i][j], float, flatcorrTable->image[i]->Ny);94 memset (flatcorrTable->offset[i][j], 0.0, flatcorrTable->image[i]->Ny*sizeof(float));95 }92 ALLOCATE (flatcorrTable->offset[i], float *, flatcorrTable->image[i].Nx); 93 for (j = 0; j < flatcorrTable->image[i].Nx; j++) { 94 ALLOCATE (flatcorrTable->offset[i][j], float, flatcorrTable->image[i].Ny); 95 memset (flatcorrTable->offset[i][j], 0.0, flatcorrTable->image[i].Ny*sizeof(float)); 96 } 96 97 } 97 98 98 99 // create the lookup table (ID -> Seq) 100 101 // find the max value of ID 102 int MaxID = 0; 103 for (i = 0; i < flatcorrTable->Nimage; i++) { 104 MaxID = MAX(flatcorrTable->image[i].ID, MaxID); 105 } 106 107 // generate the index and init values to -1 99 108 ALLOCATE (flatcorrTable->IDtoSeq, int, MaxID); 109 for (i = 0; i < MaxID; i++) { 110 flatcorrTable->IDtoSeq[i] = -1; 111 } 112 113 // assign the ID values for each image 100 114 for (i = 0; i < flatcorrTable->Nimage; i++) { 101 flatcorrTable->IDtoSeq[i] = -1; 102 } 103 for (i = 0; i < flatcorrTable->Nimage; i++) { 104 ID = flatcorrTable->image[i].ID; 105 assert (flatcorrTable->IDtoSeq[ID] == -1); 106 flatcorrTable->IDtoSeq[ID] = i; 115 int ID = flatcorrTable->image[i].ID; 116 assert (flatcorrTable->IDtoSeq[ID] == -1); 117 flatcorrTable->IDtoSeq[ID] = i; 107 118 } 108 119 109 120 // assign the known specific correction values 110 121 for (i = 0; i < flatcorrTable->Ncorr; i++) { 111 ID = flatcorrTable->corr[i].ID;112 x = flatcorrTable->corr[i].x;113 y = flatcorrTable->corr[i].y;114 seq = flatcorrTable->IDtoSeq[ID];115 assert (seq != -1);122 int ID = flatcorrTable->corr[i].ID; 123 int x = flatcorrTable->corr[i].x; 124 int y = flatcorrTable->corr[i].y; 125 int seq = flatcorrTable->IDtoSeq[ID]; 126 assert (seq != -1); 116 127 117 flatcorrTable->offset[i][x][y] = flatcorrTable->corr[i].offset;128 flatcorrTable->offset[i][x][y] = flatcorrTable->corr[i].offset; 118 129 } 119 130 120 return (flatcorrTable);131 return TRUE; 121 132 } 122 133 … … 142 153 143 154 ftableCorr.header = &theaderCorr; 144 gfits_table_set_FlatCorrection Corr(&ftableCorr, flatcorrTable->corr, flatcorrTable->Ncorr);155 gfits_table_set_FlatCorrection (&ftableCorr, flatcorrTable->corr, flatcorrTable->Ncorr); 145 156 146 157 f = fopen (filename, "w"); … … 163 174 float FlatCorrectionOffset (FlatCorrectionTable *flatcorr, int ID, int X, int Y) { 164 175 165 // validate the flat_id (not out of range?)166 seq = flatcorr->IDtoSeq[ID];176 // validate the flat_id (not out of range?) 177 int seq = flatcorr->IDtoSeq[ID]; 167 178 168 // convert X,Y to Xbin, Ybin:169 Xbin = MAX(MIN(X / flatcorr->image[seq].DX, flatcorr->image[seq].NX- 1), 0);170 Ybin = MAX(MIN(Y / flatcorr->image[seq].DY, flatcorr->image[seq].NY- 1), 0);179 // convert X,Y to Xbin, Ybin: 180 int Xbin = MAX(MIN(X * flatcorr->image[seq].Nx / flatcorr->image[seq].DX, flatcorr->image[seq].Nx - 1), 0); 181 int Ybin = MAX(MIN(Y * flatcorr->image[seq].Ny / flatcorr->image[seq].DY, flatcorr->image[seq].Ny - 1), 0); 171 182 172 // XXX warn if X,Y are out of range? not super important unless *way* out of range183 // XXX warn if X,Y are out of range? not super important unless *way* out of range 173 184 174 offset = flatcorr->offset[seq][Xbin][Ybin];175 return offset;185 float offset = flatcorr->offset[seq][Xbin][Ybin]; 186 return offset; 176 187 } 177 188 -
branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile
r31160 r33104 52 52 $(SRC)/load_images.$(ARCH).o \ 53 53 $(SRC)/match_zpts_to_images.$(ARCH).o \ 54 $(SRC)/match_flatcorr_to_images.$(ARCH).o \ 54 55 $(SRC)/update_catalog_setphot.$(ARCH).o \ 55 56 $(SRC)/SetSignals.$(ARCH).o \ -
branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h
r31635 r33104 66 66 char STATMODE[64]; 67 67 int VERBOSE; 68 int UBERCAL; // load the supplied ubercal zero point fits table (with flat-field corrections) 68 69 int NLOOP; 69 70 int TimeSelect; … … 132 133 Image *load_images_setphot PROTO((FITS_DB *db, off_t *Nimage)); 133 134 int match_zpts_to_images PROTO((Image *image, off_t Nimage, ZptTable *zpts, int Nzpts)); 134 int update_setphot PROTO((Image *image, off_t Nimage)); 135 void update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage)); 135 int update_setphot PROTO((Image *image, off_t Nimage, FlatCorrectionTable *flatcorr)); 136 void update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr)); 137 138 ZptTable *load_zpt_ubercal (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable); 139 int match_flatcorr_to_images (Image *image, off_t Nimage, FlatCorrectionTable *flatcorrTable); 136 140 137 141 /*** time/coord conversion functions not supplied by libohana ***/ -
branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c
r33103 r33104 42 42 } 43 43 44 ZptTable *load_zpt_ubercal (char *filename, int *nzpts) { 44 # define NFILTER 5 45 # define NSEASON 4 45 46 47 char filter[NFILTER] = {'g', 'r', 'i', 'z', 'y'}; 48 double tstart[NSEASON] = {55000.0, 55296.0, 55327.0, 55662.0}; 49 double tstop[NSEASON] = {55296.0, 55327.0, 55662.0, 60000.0}; 50 51 # define NCHIP_X 8 52 # define NCHIP_Y 8 53 # define NCELL_X 2 54 # define NCELL_Y 2 55 56 ZptTable *load_zpt_ubercal (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable) { 57 58 int i, nfilter, nseason, ix, iy, ixc, iyc, Ncol, seq; 59 off_t Nrow; 60 char type[16]; 46 61 int Nzpts, NZPTS; 47 62 ZptTable *zpts; 48 double zpt, mjd, zpt_err; 63 Header header; 64 Header theader; 65 Matrix matrix; 66 FTable ftable; 49 67 50 68 FILE *f; … … 57 75 58 76 /* load in PHU segment (ignore) */ 59 ftable.header = &theader;60 77 if (!gfits_fread_header (f, &header)) { 61 78 if (VERBOSE) fprintf (stderr, "can't read Flat Correction header\n"); … … 74 91 ALLOCATE (zpts, ZptTable, NZPTS); 75 92 76 ALLOCATE (flatcorr, FlatCorrection, 4*5*X); 93 // we have 5 filters, and 4 flat-field correction sets for each 94 flatcorrTable->Ncorr = NFILTER*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y; 95 flatcorrTable->Nimage = NFILTER*NSEASON*NCHIP_X*NCHIP_Y; 77 96 78 for (i = 0; i < 5; i++) { 79 // load data for this header 80 if (!gfits_load_header (f, &theader)) return (FALSE); 97 ALLOCATE (flatcorrTable->corr, FlatCorrection, flatcorrTable->Ncorr); 98 ALLOCATE (flatcorrTable->image, FlatCorrectionImage, flatcorrTable->Nimage); 81 99 82 // read the fits table bytes 83 if (gfits_fread_ftable_data (f, &table, FALSE)) return (TRUE); 100 int corrID = 1; 101 int Nimage = 0; 102 ftable.header = &theader; 103 for (nfilter = 0; nfilter < NFILTER; nfilter++) { 104 // load data for this header 105 if (!gfits_load_header (f, &theader)) return (NULL); 106 107 // read the fits table bytes 108 if (gfits_fread_ftable_data (f, &ftable, FALSE)) return (NULL); 84 109 85 // skip over remaining bytes in data segment86 fseeko (f, table[0].datasize - table[0].validsize, SEEK_CUR);110 // skip over remaining bytes in data segment 111 fseeko (f, ftable.datasize - ftable.validsize, SEEK_CUR); 87 112 88 // load data for this header 89 if (!gfits_load_header (f, &header)) return (FALSE); 113 // need to create and assign to flat-field correction 114 double *mjd = gfits_get_bintable_column_data (&theader, &ftable, "mjd_obs", type, &Nrow, &Ncol); 115 assert (!strcmp(type, "double")); 90 116 91 // read the fits table bytes 92 if (gfits_fread_matrix (f, &matrix, FALSE)) return (TRUE); 117 double *zp = gfits_get_bintable_column_data (&theader, &ftable, "zp", type, &Nrow, &Ncol); 118 assert (!strcmp(type, "double")); 119 120 double *zperr = gfits_get_bintable_column_data (&theader, &ftable, "resid", type, &Nrow, &Ncol); 121 assert (!strcmp(type, "double")); 122 123 NZPTS += Nrow; 124 REALLOCATE (zpts, ZptTable, NZPTS); 125 for (i = 0; i < Nrow; i++) { 126 zpts[i+Nzpts].time = ohana_mjd_to_sec(mjd[i]); 127 zpts[i+Nzpts].zpt = zp[i]; 128 zpts[i+Nzpts].zpt_err = zperr[i]; 129 } 130 Nzpts += Nrow; 93 131 94 // need to create and assign to flat-field correction 95 double *mjd = gfits_get_bintable_column_data (header, table, "mjd_obs", &type, &Nrow, &Ncol); 96 assert (!strcmp(type, "double")); 132 // the image contains the flat-field corrections 97 133 98 double *zpts = gfits_get_bintable_column_data (header, table, "zp", &type, &Nrow, &Ncol); 99 assert (!strcmp(type, "double")); 100 101 double *zperr = gfits_get_bintable_column_data (header, table, "resid", &type, &Nrow, &Ncol); 102 assert (!strcmp(type, "double")); 103 104 NZPTS += Nrow; 105 REALLOCATE (zpts, ZptTable, NZPTS); 106 for (i = 0; i < Nrow; i++) { 107 zpts[i+Nzpts].time = ohana_mjd_to_sec(mjd[i]); 108 zpts[i+Nzpts].zpt = zp[i]; 109 zpts[i+Nzpts].zpt_err = zperr[i]; 134 // load data for this header 135 if (!gfits_load_header (f, &header)) return (NULL); 136 137 // read the fits table bytes 138 if (gfits_fread_matrix (f, &matrix, FALSE)) return (NULL); 139 140 for (nseason = 0; nseason < NSEASON; nseason++) { // seasons 141 for (iy = 0; iy < NCHIP_Y; iy++) { // y-chip 142 for (ix = 0; ix < NCHIP_X; ix++) { // x-chip 143 flatcorrTable->image[Nimage].Nx = NCELL_X; 144 flatcorrTable->image[Nimage].Ny = NCELL_Y; 145 flatcorrTable->image[Nimage].ID = corrID; 146 flatcorrTable->image[Nimage].DX = 4880; 147 flatcorrTable->image[Nimage].DY = 4864; 148 flatcorrTable->image[Nimage].tstart = ohana_mjd_to_sec(tstart[nseason]); 149 flatcorrTable->image[Nimage].tstop = ohana_mjd_to_sec(tstop[nseason]); 150 151 // photcode name 152 char photname[64]; 153 snprintf (photname, 64, "GPC1.%c.XY%d%d", filter[nfilter], ix, iy); 154 // note that the XY00, XY07, etc, chips will have photcode values of 0 155 flatcorrTable->image[Nimage].photcode = GetPhotcodeCodebyName(photname); 156 flatcorrTable->image[Nimage].tstart = tstart[nseason]; 157 flatcorrTable->image[Nimage].tstop = tstop[nseason]; 158 159 for (iyc = 0; iyc < NCELL_Y; iyc++) { 160 for (ixc = 0; ixc < NCELL_X; ixc++) { 161 if (ix > 3) { 162 seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + NCELL_Y - 1 - iyc)*NCHIP_X + (ix*NCELL_X + NCELL_X - 1 - ixc); 163 } else { 164 seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + iyc)*NCHIP_X + (ix*NCELL_X + ixc); 165 } 166 flatcorrTable->corr[seq].x = ixc; 167 flatcorrTable->corr[seq].y = iyc; 168 flatcorrTable->corr[seq].offset = matrix.buffer[seq]; 169 flatcorrTable->corr[seq].ID = corrID; 170 } 171 } 172 corrID ++; 173 Nimage ++; 174 } 110 175 } 111 Nzpts += Nrow; 112 113 // the image is the flat-field correction. 114 // need to byteswap or whatever 176 } 115 177 } 116 178 117 if (status != EOF) { 118 fprintf (stderr, "unexpected formatting on line %d\n", Nzpts); 119 exit (2); 120 } 179 /*** convert from corr,image format to offsets ***/ 180 FlatCorrectionInternal (flatcorrTable); 121 181 122 182 fprintf (stderr, "loaded %d zero points\n", Nzpts); -
branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c
r33103 r33104 8 8 ZptTable *zpts; 9 9 Image *image; 10 FlatCorrectionTable flatcorrTable; 10 11 11 12 /* get configuration info, args, lockfile */ … … 18 19 19 20 if (UBERCAL) { 20 zpts = load_zpt_ubercal (argv[1], &Nzpts); 21 zpts = load_zpt_ubercal (argv[1], &Nzpts, &flatcorrTable); 22 char flatcorrfile[64]; 23 snprintf (flatcorrfile, 64, "%s/flatcorr.fits", CATDIR); 24 FlatCorrectionSave(&flatcorrTable, flatcorrfile); 21 25 } else { 22 26 zpts = load_zpt_table (argv[1], &Nzpts); … … 29 33 match_zpts_to_images (image, Nimage, zpts, Nzpts); 30 34 31 update_setphot(image, Nimage); 35 if (UBERCAL) { 36 match_flatcorr_to_images (image, Nimage, &flatcorrTable); 37 } 38 39 update_setphot(image, Nimage, &flatcorrTable); 32 40 33 41 // write image table -
branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c
r33103 r33104 2 2 # include <glob.h> 3 3 4 int update_setphot (Image *image, off_t Nimage ) {4 int update_setphot (Image *image, off_t Nimage, FlatCorrectionTable *flatcorr) { 5 5 6 6 SkyRegion UserPatch; … … 54 54 } 55 55 56 update_catalog_setphot (&catalog, image, index, Nimage );56 update_catalog_setphot (&catalog, image, index, Nimage, flatcorr); 57 57 58 58 if (!UPDATE) { … … 73 73 void update_catalog_setphot (Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr) { 74 74 75 off_t i, j, m, id, idx, found; 76 float Mcal, dMcal; 75 off_t i, j, found; 77 76 78 77 found = 0; 79 78 for (i = 0; i < catalog[0].Naverage; i++) { 80 79 81 m = catalog[0].average[i].measureOffset;80 off_t m = catalog[0].average[i].measureOffset; 82 81 for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) { 83 idx = catalog[0].measure[m].imageID;82 off_t idx = catalog[0].measure[m].imageID; 84 83 if (idx <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode) 85 84 86 id = index[idx];87 Mcal = image[id].Mcal;88 dMcal = image[id].dMcal;89 Mcal_offset = 0.0;85 off_t id = index[idx]; 86 float Mcal = image[id].Mcal; 87 float dMcal = image[id].dMcal; 88 float Mcal_offset = 0.0; 90 89 91 90 // if we know about a flat-field correction, then we need to apply the sub-chip correction 92 flat_id = image[id].photom_map_id;91 int flat_id = image[id].photom_map_id; 93 92 if (flat_id > 0) { 94 93 Mcal_offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[0].measure[m].Xccd, catalog[0].measure[m].Yccd);
Note:
See TracChangeset
for help on using the changeset viewer.
