Changeset 37913
- Timestamp:
- Feb 16, 2015, 8:17:35 PM (11 years ago)
- Location:
- branches/eam_branches/ipp-20150112/Ohana/src/uniphot
- Files:
-
- 6 edited
-
Makefile (modified) (2 diffs)
-
include/setastrom.h (modified) (3 diffs)
-
src/cam_correction.c (modified) (3 diffs)
-
src/initialize_setastrom.c (modified) (6 diffs)
-
src/update_catalog_setastrom.c (modified) (3 diffs)
-
src/update_dvo_setastrom.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20150112/Ohana/src/uniphot/Makefile
r37807 r37913 112 112 $(SRC)/setastrom.$(ARCH).o \ 113 113 $(SRC)/initialize_setastrom.$(ARCH).o \ 114 $(SRC)/cam_correction.$(ARCH).o \ 114 115 $(SRC)/dcr_correction.$(ARCH).o \ 115 116 $(SRC)/kh_correction.$(ARCH).o \ … … 127 128 $(SRC)/update_dvo_setastrom.$(ARCH).o \ 128 129 $(SRC)/update_catalog_setastrom.$(ARCH).o \ 130 $(SRC)/cam_correction.$(ARCH).o \ 129 131 $(SRC)/dcr_correction.$(ARCH).o \ 130 132 $(SRC)/kh_correction.$(ARCH).o \ -
branches/eam_branches/ipp-20150112/Ohana/src/uniphot/include/setastrom.h
r37910 r37913 13 13 // we have one correction (an image) for each filter and chip 14 14 typedef struct { 15 int Nvalues; 16 int Nfilters; // number of filters 17 int NchipX; // number of chips in x 18 int NchipY; // number of chips in y 15 int Nx; // number of chips in x 16 int Ny; // number of chips in y 17 int Nfilter; // number of filters 18 int Ndir; // number of correction dimensions 19 20 int Nchips; // chip offset (Nx*Ny) 21 int Ngroup; // direction offset (Nx*Ny*Nfilters) 22 int Nvalues; // Nx*Ny*Nfilters*Ndir 23 24 int dX; // superpixel size 25 int dY; // superpixel size 26 19 27 int NxCCD; // number of pixels 28 int NyCCD; // number of pixels 29 20 30 Matrix **matrix; // allocate an array of pointers 21 // index = ix + iy*Nx + filter*N x*Ny + dir*Nx*Ny*Nfilter31 // index = ix + iy*Nx + filter*Nchips + dir*Ngroup 22 32 } CamCorrection; 23 33 … … 38 48 char *KH_FILE; 39 49 char *DCR_FILE; 50 char *CAM_FILE; 40 51 41 52 int KH_RESET; 42 53 int DCR_RESET; 54 int CAM_RESET; 43 55 44 56 SkyRegion UserPatch; … … 76 88 int load_dcr_correction (char *filename); 77 89 int get_dcr_correction (int filter, double *dX, double *dY, float Color); 90 91 int load_cam_correction (char *filename); 92 int get_cam_correction (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY); -
branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/cam_correction.c
r37910 r37913 6 6 // note that we are allocating pointers for XY00 - XY77, but only the octal elements are set (and not the 00,07,70,77 ones) 7 7 8 CamCorrection *load_cam_correction (char *filename) { 8 static CamCorrection *cam = NULL; 9 9 10 int Ncol; 11 off_t Nrow; 10 int load_cam_correction (char *filename) { 12 11 13 char type[16]; 14 char extname[80]; 15 12 int i, ix, iy, dir, filter; 16 13 Header header; 17 Header theader;18 FTable ftable;19 14 20 15 /* open file for input */ … … 29 24 30 25 // read the PHU header 31 if (!gfits_load_header (f, &header)) return (FALSE);26 if (!gfits_load_header (f, &header)) return FALSE; 32 27 33 28 int Nbytes = gfits_data_size (&header); 34 29 fseeko (f, Nbytes, SEEK_CUR); 35 30 36 ftable.header = &theader; 31 int Ndir, Nfilter, Nx, Ny, dX, dY, NxCCD, NyCCD; 32 if (!gfits_scan (&header, "NDIR", "%d", 1, &Ndir)) return FALSE; 33 if (!gfits_scan (&header, "NFILTER", "%d", 1, &Nfilter)) return FALSE; 34 if (!gfits_scan (&header, "NX", "%d", 1, &Nx)) return FALSE; 35 if (!gfits_scan (&header, "NY", "%d", 1, &Ny)) return FALSE; 36 if (!gfits_scan (&header, "DX", "%d", 1, &dX)) return FALSE; 37 if (!gfits_scan (&header, "DY", "%d", 1, &dY)) return FALSE; 37 38 38 if (!gfits_scan (&theader, "NDIR", "%d", 1, &Ndir)) return (NULL); 39 if (!gfits_scan (&theader, "NFILTER", "%d", 1, &Nfilter)) return (NULL); 40 if (!gfits_scan (&theader, "NX_CHIP", "%d", 1, &Nx)) return (NULL); 41 if (!gfits_scan (&theader, "NY_CHIP", "%d", 1, &Ny)) return (NULL); 42 if (!gfits_scan (&theader, "DX_CHIP", "%d", 1, &dX)) return (NULL); 43 if (!gfits_scan (&theader, "DY_CHIP", "%d", 1, &dY)) return (NULL); 39 if (!gfits_scan (&header, "NX_CHIP", "%d", 1, &NxCCD)) return FALSE; 40 if (!gfits_scan (&header, "NY_CHIP", "%d", 1, &NyCCD)) return FALSE; 44 41 45 42 ALLOCATE (cam->matrix, Matrix *, Ndir*Nfilter*Nx*Ny); … … 47 44 cam->Nx = Nx; // for gpc1, should be 8 48 45 cam->Ny = Ny; // for gpc1, should be 8 46 cam->Nfilter = Nfilter; // for gpc1, should be 5 47 cam->Ndir = Ndir; // for gpc1, should be 2 48 49 49 cam->dX = dX; // superpixel sampling, x-dir 50 50 cam->dY = dY; // superpixel sampling, y-dir 51 cam->Ndir = Ndir; // for gpc1, should be 252 cam->Nfilter = Nfilter; // for gpc1, should be 553 51 52 cam->NxCCD = NxCCD; // pixels per chip 53 cam->NyCCD = NyCCD; // pixels per chip 54 55 cam->Nchips = Nx * Ny; 56 cam->Ngroup = Nx * Ny * Nfilter; 57 cam->Nvalues = Nx * Ny * Nfilter * Ndir; 58 59 ALLOCATE (cam->matrix, Matrix *, cam->Nvalues); 60 for (i = 0; i < cam->Nvalues; i++) { 61 cam->matrix[i] = NULL; 62 } 63 64 int found = FALSE; 54 65 while (TRUE) { 66 Header theader; 67 55 68 // load data for this header : if not found, assume we hit the end of the file 56 69 if (!gfits_load_header (f, &theader)) break; 57 70 58 if (!gfits_scan (&theader, "FILTER", "%d", 1, &filter)) return (FALSE);59 if (!gfits_scan (&theader, "DIR", "%d", 1, &dir)) return (FALSE);60 if (!gfits_scan (&theader, "X_CHIP", "%d", 1, &ix)) return (FALSE);61 if (!gfits_scan (&theader, "Y_CHIP", "%d", 1, &iy)) return (FALSE);71 if (!gfits_scan (&theader, "FILTER", "%d", 1, &filter)) return FALSE; 72 if (!gfits_scan (&theader, "DIR", "%d", 1, &dir)) return FALSE; 73 if (!gfits_scan (&theader, "X_CHIP", "%d", 1, &ix)) return FALSE; 74 if (!gfits_scan (&theader, "Y_CHIP", "%d", 1, &iy)) return FALSE; 62 75 63 76 Matrix *matrix = NULL; 64 77 ALLOCATE (matrix, Matrix, 1); 65 if (!gfits_load_ header(f, matrix, &theader)) break;78 if (!gfits_load_matrix (f, matrix, &theader)) break; 66 79 67 int index = ix + iy* Nx + filter*Nx*Ny + dir*Nx*Ny*Nfilter;80 int index = ix + iy*cam->Nx + filter*cam->Nchips + dir*cam->Ngroup; 68 81 myAssert (index >= 0, "index too small"); 69 myAssert (index < Ndir*Nfilter*Nx*Ny, "index too big"); 82 myAssert (index < cam->Nvalues, "index too big"); 83 84 myAssert (!cam->matrix[i], "entry already assigned?"); 70 85 71 86 // assert that cam->matrix[index] is NULL? 72 87 cam->matrix[index] = matrix; 88 89 if (!found) { 90 91 } 73 92 } 74 return (TRUE);93 return TRUE; 75 94 } 76 95 77 int get_cam_correction (CamCorrection *cam, int chip, int filter, double *dX, double *dY, float Xccd, float Yccd) { 96 // input is: 97 // chipID == octal chip ID (eg 40 for XY40) 98 // filter == (01234 = grizy) 99 int get_cam_correction (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY) { 78 100 79 101 *dX = 0.0; 80 102 *dY = 0.0; 81 103 82 // split out the chip number (eg 43 for XY43) into X and Y elements83 int ix = (int) (chip / 10);84 int iy = (int) (chip % 10);104 int index, jx, jy, NxModel; 105 Matrix *matrix; 106 float *buffer, value; 85 107 86 int dir = 0; // dX 87 int index = ix + iy*cam->Nx + filter*cam->Nx*cam->Ny + dir*cam->Nx*cam->Ny*cam->Nfilter; 108 // split out the chipID number (eg 43 for XY43) into X and Y elements 109 int ix = (int) (chipID / 10); 110 int iy = (int) (chipID % 10); 88 111 89 Matrix *matrix = cam->matrix[index]; 112 // dX (dir == 0) 113 index = ix + iy*cam->Nx + filter*cam->Nchips; 90 114 91 float *buffer = (float *) matrix->buffer; 115 matrix = cam->matrix[index]; 116 NxModel = cam->matrix[index]->Naxis[0]; 92 117 93 int jx = MAX(MIN(Nx, Xccd / cam->dX), 0); 94 int jy = MAX(MIN(Nx, Yccd / cam->dY), 0); 118 buffer = (float *) matrix->buffer; 95 119 96 float value = buffer[jx + jy*Nx]; 120 jx = MAX(MIN(cam->NxCCD, Xccd / cam->dX), 0); 121 jy = MAX(MIN(cam->NyCCD, Yccd / cam->dY), 0); 122 123 value = buffer[jx + jy*NxModel]; 97 124 98 125 *dX = isnan(value) ? 0.0 : value; 99 return (TRUE); 126 127 // dY (dir == 1) uses the next block 128 index += cam->Ngroup; 129 130 matrix = cam->matrix[index]; 131 NxModel = cam->matrix[index]->Naxis[0]; 132 133 buffer = (float *) matrix->buffer; 134 135 jx = MAX(MIN(cam->NxCCD, Xccd / cam->dX), 0); 136 jy = MAX(MIN(cam->NyCCD, Yccd / cam->dY), 0); 137 138 value = buffer[jx + jy*NxModel]; 139 140 *dY = isnan(value) ? 0.0 : value; 141 142 return TRUE; 100 143 } 101 -
branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/initialize_setastrom.c
r37807 r37913 4 4 fprintf (stderr, "USAGE: setastrom [options]\n"); 5 5 fprintf (stderr, " options:\n"); 6 fprintf (stderr, " -KH (file) : supply Koppenhoefer correction splines\n"); 6 7 fprintf (stderr, " -DCR (file) : supply DCR correction splines\n"); 7 fprintf (stderr, " - KH (file) : supply Koppenhoefer correction splines\n");8 fprintf (stderr, " -CAM (file) : supply camera-static correction file\n"); 8 9 fprintf (stderr, " -v : verbose mode\n"); 9 10 fprintf (stderr, " -region Rmin Rmax Dmin Dmax\n"); … … 77 78 } 78 79 80 CAM_FILE = NULL; 81 if ((N = get_argument (argc, argv, "-CAM"))) { 82 remove_argument (N, &argc, argv); 83 char *tmpfile = strcreate (argv[N]); 84 CAM_FILE = abspath (tmpfile, DVO_MAX_PATH); 85 remove_argument (N, &argc, argv); 86 } 87 CAM_RESET = FALSE; 88 if ((N = get_argument (argc, argv, "-CAM-reset"))) { 89 remove_argument (N, &argc, argv); 90 CAM_RESET = TRUE; 91 } 92 79 93 SINGLE_CPT = NULL; 80 94 if ((N = get_argument (argc, argv, "-cpt"))) { … … 146 160 } 147 161 148 if (!KH_FILE && !DCR_FILE) { 149 fprintf (stderr, "at least one of -KH and -DCR must be supplied\n"); 150 exit (1); 162 if (!KH_FILE && !DCR_FILE && !CAM_FILE) { 163 fprintf (stderr, "WARNING: none of -CAM, -KH, -DCR supplied\n"); 151 164 } 152 165 … … 159 172 fprintf (stderr, "USAGE: setastrom_client -hostID (hostID) -catdir (catdir) -hostdir (hostdir) [options]\n"); 160 173 fprintf (stderr, " options:\n"); 174 fprintf (stderr, " -KH (file) : supply Koppenhoefer correction splines\n"); 161 175 fprintf (stderr, " -DCR (file) : supply DCR correction splines\n"); 162 fprintf (stderr, " - KH (file) : supply Koppenhoefer correction splines\n");176 fprintf (stderr, " -CAM (file) : supply camera-static correction file\n"); 163 177 fprintf (stderr, " -region Rmin Rmax Dmin Dmax\n"); 164 178 fprintf (stderr, " -update-catformat (format) : change database schema on output\n"); … … 221 235 remove_argument (N, &argc, argv); 222 236 DCR_RESET = TRUE; 237 } 238 239 CAM_FILE = NULL; 240 if ((N = get_argument (argc, argv, "-CAM"))) { 241 remove_argument (N, &argc, argv); 242 CAM_FILE = strcreate (argv[N]); 243 remove_argument (N, &argc, argv); 244 } 245 CAM_RESET = FALSE; 246 if ((N = get_argument (argc, argv, "-CAM-reset"))) { 247 remove_argument (N, &argc, argv); 248 CAM_RESET = TRUE; 223 249 } 224 250 … … 282 308 if (!CATDIR) usage_setastrom_client(); 283 309 284 if (!KH_FILE && !DCR_FILE) { 285 fprintf (stderr, "at least one of -KH and -DCR must be supplied\n"); 286 exit (1); 310 if (!KH_FILE && !DCR_FILE && !CAM_FILE) { 311 fprintf (stderr, "WARNING: none of -CAM, -KH, -DCR supplied\n"); 287 312 } 288 313 -
branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/update_catalog_setastrom.c
r37908 r37913 121 121 double dX_CAM = 0.0; 122 122 double dY_CAM = 0.0; 123 if (CAM_FILE && doCAM) {123 if (CAM_FILE) { 124 124 125 125 // camera systematic correction ("astroflat") depends on only the X,Y coordinate, 126 126 // the filter, and the chip 127 127 128 int filtCode = (int)(measure->photcode / 100); // eg, 101 = r 128 // 10134 : r, XY34 -> filtCode = 1 129 int filtCode = (int)((measure->photcode % 100) / 100); 129 130 130 131 // correction is in arcseconds 131 get_cam_correction ( 0,chipID, filtCode, measure->Xccd, measure->Yccd, &dX_CAM, &dY_CAM);132 get_cam_correction (chipID, filtCode, measure->Xccd, measure->Yccd, &dX_CAM, &dY_CAM); 132 133 } 133 134 … … 260 261 } 261 262 if (DCR_RESET) { 262 measure[0].XoffDCR = -dX_DCR / pltScale; 263 measure[0].YoffDCR = -dY_DCR / pltScale; 263 measure[0].XoffDCR = 0.0; 264 measure[0].YoffDCR = 0.0; 265 } 266 if (CAM_FILE) { 267 measure[0].XoffCAM = -dX_DCR / pltScale; 268 measure[0].YoffCAM = -dY_DCR / pltScale; 269 } 270 if (CAM_RESET) { 271 measure[0].XoffDCR = 0.0; 272 measure[0].YoffDCR = 0.0; 264 273 } 265 274 … … 274 283 measure[0].Yfix += measure[0].YoffDCR; 275 284 } 285 if (isfinite(measure[0].XoffCAM) && isfinite(measure[0].YoffCAM)) { 286 measure[0].Xfix += measure[0].XoffCAM; 287 measure[0].Yfix += measure[0].YoffCAM; 288 } 276 289 found ++; 277 290 } -
branches/eam_branches/ipp-20150112/Ohana/src/uniphot/src/update_dvo_setastrom.c
r37807 r37913 17 17 } 18 18 19 if (KH_FILE) load_kh_correction (KH_FILE); 20 if (DCR_FILE) load_dcr_correction (DCR_FILE); 19 if (KH_FILE) if (!load_kh_correction (KH_FILE)) { fprintf (stderr, "failed to load KH correction %s\n", KH_FILE ); exit (1); } 20 if (DCR_FILE) if (!load_dcr_correction (DCR_FILE)) { fprintf (stderr, "failed to load DCR correction %s\n", DCR_FILE); exit (1); } 21 if (CAM_FILE) if (!load_cam_correction (CAM_FILE)) { fprintf (stderr, "failed to load CAM correction %s\n", CAM_FILE); exit (1); } 21 22 22 23 // determine the populated SkyRegions overlapping the requested area (default depth) … … 104 105 if (KH_FILE) { snprintf (tmpline, 1024, "%s -KH %s", command, KH_FILE); strcpy (command, tmpline); } 105 106 if (DCR_FILE) { snprintf (tmpline, 1024, "%s -DCR %s", command, DCR_FILE); strcpy (command, tmpline); } 107 if (CAM_FILE) { snprintf (tmpline, 1024, "%s -CAM %s", command, CAM_FILE); strcpy (command, tmpline); } 106 108 if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); } 107 109 108 110 if (KH_RESET) { snprintf (tmpline, 1024, "%s -KH-reset", command); strcpy (command, tmpline); } 109 111 if (DCR_RESET) { snprintf (tmpline, 1024, "%s -DCR-reset", command); strcpy (command, tmpline); } 112 if (CAM_RESET) { snprintf (tmpline, 1024, "%s -CAM-reset", command); strcpy (command, tmpline); } 110 113 111 114 fprintf (stderr, "command: %s\n", command);
Note:
See TracChangeset
for help on using the changeset viewer.
