Changeset 41615
- Timestamp:
- May 25, 2021, 5:00:52 PM (5 years ago)
- Location:
- branches/eam_branches/relphot.20210521
- Files:
-
- 7 edited
-
include/relphot.h (modified) (3 diffs)
-
src/GridIO.c (modified) (7 diffs)
-
src/GridOps.c (modified) (4 diffs)
-
src/args.c (modified) (4 diffs)
-
src/reload_catalogs.c (modified) (1 diff)
-
src/relphot_client.c (modified) (1 diff)
-
src/relphot_images.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/relphot.20210521/include/relphot.h
r41611 r41615 66 66 PS1_w = 6, 67 67 } PS1filters; 68 69 typedef enum { 70 GRID_MEAN = 0, 71 GRID_STDEV = 1, 72 GRID_NPTS = 2, 73 } GridOutputMode; 68 74 69 75 typedef struct { … … 374 380 int SKY_DEPTH; /** XXX EAM : depth of catalog tables, fix usage */ 375 381 char *SYNTH_ZERO_POINTS; 382 char *GRID_MEANFILE; 376 383 377 384 // globals for parallel region operations … … 574 581 void setMflatFromGrid PROTO((Catalog *catalog)); 575 582 void initGridBins PROTO(()); 576 GridCorrectionType *getGridCorr PROTO((int *Nlast)); 577 int GridCorrectionSave PROTO((char *filename)); 583 GridCorrectionType *getGridCorrByCode PROTO((int code)); 584 GridCorrectionType *getGridCorrNext PROTO((int *Nlast)); 585 int GridCorrectionSave PROTO((void)); 586 int GridCorrectionSaveFile PROTO((char *filename, GridOutputMode mode)); 587 void GridCorrectionLoad PROTO((char *filename)); 578 588 void initImageBins PROTO((Catalog *catalog, int Ncatalog, int doImageList)); 579 589 void initImagesSubset PROTO((ImageSubset *input, off_t *line_number, off_t N)); -
branches/eam_branches/relphot.20210521/src/GridIO.c
r41610 r41615 1 1 # include "relphot.h" 2 2 3 int GridCorrectionSave (char *filename) { 3 int GridCorrectionSave () { 4 5 if (!GRID_ZEROPT) return TRUE; 6 7 char filename[1024], uniquer[12]; 8 int TIME = time(NULL); 9 int PID = getpid(); 10 11 snprintf_nowarn (uniquer, 12, "%05d.%05d", PID, TIME % 100000); 12 13 snprintf (filename, 1024, "%s/gridcorr.mean.%s.fits", CATDIR, uniquer); 14 if (!GridCorrectionSaveFile (filename, GRID_MEAN)) return FALSE; 15 GRID_MEANFILE = strcreate (filename); // save in the global so we can pass to e.g., reload_catalogs 16 17 snprintf (filename, 1024, "%s/gridcorr.stdev.%s.fits", CATDIR, uniquer); 18 if (!GridCorrectionSaveFile (filename, GRID_STDEV)) return FALSE; 19 20 snprintf (filename, 1024, "%s/gridcorr.npts.%s.fits", CATDIR, uniquer); 21 if (!GridCorrectionSaveFile (filename, GRID_NPTS)) return FALSE; 22 23 return TRUE; 24 } 25 26 int GridCorrectionSaveFile (char *filename, GridOutputMode mode) { 4 27 5 28 /* open file for input */ … … 27 50 28 51 while (TRUE) { 29 // getGridCorr () takes a photcode and returns the *next* valid grid correction pointer (start at -1)30 GridCorrectionType *GridCorr = getGridCorr (&Nlast);52 // getGridCorreNext() takes a photcode and returns the *next* valid grid correction pointer (start at -1) 53 GridCorrectionType *GridCorr = getGridCorrNext (&Nlast); 31 54 if (!GridCorr) break; 32 55 33 56 int filter = GetPhotcodeEquivCodebyCode (GridCorr->photcode); 57 char *filtname = GetPhotcodeNamebyCode (filter); // reference, do not free 58 char *photname = GetPhotcodeNamebyCode (GridCorr->photcode); // reference, do not free 34 59 35 60 Header header; … … 37 62 38 63 gfits_init_header (&header); 39 header.bitpix = -32;40 header.Naxes = 2;64 header.bitpix = (mode == GRID_NPTS) ? 32 : -32; 65 header.Naxes = 2; 41 66 header.Naxis[0] = GridCorr->Nx; 42 67 header.Naxis[1] = GridCorr->Ny; … … 48 73 // create header & matrix 49 74 if (!gfits_modify (&header, "PHOTCODE", "%d", 1, GridCorr->photcode)) myAbort ("failed to set PHOTCODE"); 50 if (!gfits_modify (&header, "FILTER", "% d", 1, filter))myAbort ("failed to set FILTER");75 if (!gfits_modify (&header, "FILTER", "%s", 1, filtname)) myAbort ("failed to set FILTER"); 51 76 if (!gfits_modify (&header, "SEASON", "%d", 1, 0)) myAbort ("failed to set SEASON"); // XXX hard-wired for now 52 77 if (!gfits_modify (&header, "X_CHIP", "%d", 1, -1)) myAbort ("failed to set X_CHIP"); … … 58 83 59 84 int Nx = GridCorr->Nx; 60 float *value = (float *) matrix.buffer;61 85 86 float *fvalue = (float *) matrix.buffer; 87 int *ivalue = (int *) matrix.buffer; 88 62 89 for (int iy = 0; iy < GridCorr->Ny; iy++) { 63 90 for (int ix = 0; ix < GridCorr->Nx; ix++) { 64 value[ix + iy*Nx] = GridCorr->Mgrid[ix][iy]; 91 switch (mode) { 92 case GRID_MEAN: fvalue[ix + iy*Nx] = GridCorr-> Mgrid[ix][iy]; break; 93 case GRID_STDEV: fvalue[ix + iy*Nx] = GridCorr->dMgrid[ix][iy]; break; 94 case GRID_NPTS: ivalue[ix + iy*Nx] = GridCorr->nMgrid[ix][iy]; break; 95 } 65 96 } 66 97 } 67 98 99 char extname[85]; 100 switch (mode) { 101 // XXX If we add seasons, add here: 102 case GRID_MEAN: snprintf (extname, 85, "%s.%s", photname, "MEAN"); break; 103 case GRID_STDEV: snprintf (extname, 85, "%s.%s", photname, "STDEV"); break; 104 case GRID_NPTS: snprintf (extname, 85, "%s.%s", photname, "NPTS"); break; 105 } 106 gfits_modify (&header, "EXTNAME", "%s", 1, extname); 107 68 108 gfits_primary_to_extended (&header, "IMAGE", "Image Extension"); 69 109 gfits_fwrite_header (f, &header); … … 78 118 } 79 119 80 # if (0) 81 CamPhotomCorrection *CamPhotomCorrectionLoad (char *filename) { 120 void GridCorrectionLoad (char *filename) { 82 121 83 int i, ix, iy, season, filter;122 int photcode; 84 123 85 Header *phu = gfits_alloc_header(); 124 Header phu; 125 Header header; 126 Matrix matrix; 127 128 if (!GRID_ZEROPT) return; 129 130 // allocate the basic containing structures: 131 initGridBins (); 86 132 87 133 /* open file for input */ … … 89 135 if (f == (FILE *) NULL) { 90 136 gprint (GP_ERR, "can't open file for read : %s\n", filename); 91 return FALSE;137 return; 92 138 } 93 139 94 140 // read the PHU header 95 if (!gfits_ load_header (f, phu)) return FALSE;141 if (!gfits_fread_header (f, &phu)) return; 96 142 97 int Nbytes = gfits_data_size (phu); 143 // move to the first extension 144 int Nbytes = gfits_data_size (&phu); 98 145 fseeko (f, Nbytes, SEEK_CUR); 99 146 100 int Nseason, Nfilter, Nx, Ny, dX, dY, NxCCD, NyCCD; 101 if (!gfits_scan (phu, "NSEASON", "%d", 1, &Nseason)) return FALSE; 102 if (!gfits_scan (phu, "NFILTER", "%d", 1, &Nfilter)) return FALSE; 103 if (!gfits_scan (phu, "NX", "%d", 1, &Nx)) return FALSE; 104 if (!gfits_scan (phu, "NY", "%d", 1, &Ny)) return FALSE; 105 if (!gfits_scan (phu, "DX", "%d", 1, &dX)) return FALSE; 106 if (!gfits_scan (phu, "DY", "%d", 1, &dY)) return FALSE; 107 if (!gfits_scan (phu, "NX_CHIP", "%d", 1, &NxCCD)) return FALSE; 108 if (!gfits_scan (phu, "NY_CHIP", "%d", 1, &NyCCD)) return FALSE; 147 gfits_free_header (&phu); 109 148 110 CamPhotomCorrection *cam = CamPhotomCorrectionAlloc (Nx, Ny, Nfilter, Nseason);111 cam->phu = phu;149 while (gfits_fread_header (f, &header)) { 150 if (!gfits_fread_matrix (f, &matrix, &header)) myAbort ("failed to read matrix"); 112 151 113 cam->dX = dX; // superpixel sampling, x-dir 114 cam->dY = dY; // superpixel sampling, y-dir 152 if (!gfits_scan (&header, "PHOTCODE", "%d", 1, &photcode)) myAbort ("failed to get PHOTCODE"); 153 GridCorrectionType *GridCorr = getGridCorrByCode (photcode); 154 GridCorr->photcode = photcode; 115 155 116 cam->NxCCD = NxCCD; // pixels per chip 117 cam->NyCCD = NyCCD; // pixels per chip 156 if (!gfits_scan (&header, "DX_CHIP", "%f", 1, &GridCorr->dX)) myAbort ("failed to get DX_CHIP"); 157 if (!gfits_scan (&header, "DY_CHIP", "%f", 1, &GridCorr->dY)) myAbort ("failed to get DY_CHIP"); 158 if (!gfits_scan (&header, "NX_CHIP", "%d", 1, &GridCorr->Nx)) myAbort ("failed to get NX_CHIP"); 159 if (!gfits_scan (&header, "NY_CHIP", "%d", 1, &GridCorr->Ny)) myAbort ("failed to get NY_CHIP"); 160 161 GridCorr->dMgrid = NULL; 162 GridCorr->nMgrid = NULL; 163 ALLOCATE (GridCorr->Mgrid, float *, GridCorr->Nx); 164 for (int ix = 0; ix < GridCorr->Nx; ix++) { 165 ALLOCATE (GridCorr->Mgrid[ix], float, GridCorr->Ny); 166 } 118 167 119 for (i = 0; i < Nseason; i++) {120 char field[256]; 121 double value;168 int Nx = GridCorr->Nx; 169 170 float *fvalue = (float *) matrix.buffer; 122 171 123 snprintf (field, 256, "TS_%03d", i);124 if (!gfits_scan (phu, field, "%lf", 1, &value)) return FALSE;125 cam->tstart[i] = ohana_mjd_to_sec(value);126 127 snprintf (field, 256, "TE_%03d", i);128 if (!gfits_scan (phu, field, "%lf", 1, &value)) return FALSE;129 cam->tstop[i] = ohana_mjd_to_sec(value);172 for (int iy = 0; iy < GridCorr->Ny; iy++) { 173 for (int ix = 0; ix < GridCorr->Nx; ix++) { 174 GridCorr-> Mgrid[ix][iy] = fvalue[ix + iy*Nx]; 175 } 176 } 177 gfits_free_header (&header); 178 gfits_free_matrix (&matrix); 130 179 } 131 132 while (TRUE) { 133 // load data for this header : if not found, assume we hit the end of the file 134 Header *header = gfits_alloc_header(); 135 if (!gfits_load_header (f, header)) { 136 free (header); 137 break; 138 } 139 140 if (!gfits_scan (header, "FILTER", "%d", 1, &filter)) myAbort ("failed to find FILTER"); 141 if (!gfits_scan (header, "SEASON", "%d", 1, &season)) myAbort ("failed to find SEASON"); 142 if (!gfits_scan (header, "X_CHIP", "%d", 1, &ix)) myAbort ("failed to find X_CHIP"); 143 if (!gfits_scan (header, "Y_CHIP", "%d", 1, &iy)) myAbort ("failed to find Y_CHIP"); 144 // XXX NOTE: astroflat.20150209.fits had ix and iy backwards in header 145 // double-check that the new flats are OK 146 147 Matrix *matrix = gfits_alloc_matrix(); 148 if (!gfits_load_matrix (f, matrix, header)) myAbort ("failed to read matrix"); 149 150 int index = ix + iy*cam->Nx + filter*cam->Nchips + season*cam->Nflats; 151 myAssert (index >= 0, "index too small"); 152 myAssert (index < cam->Nvalues, "index too big"); 153 154 myAssert (!cam->matrix[index], "entry already assigned?"); 155 156 cam->matrix[index] = matrix; 157 cam->header[index] = header; 158 } 159 return cam; 180 gfits_free_header (&header); 160 181 } 161 # endif162 -
branches/eam_branches/relphot.20210521/src/GridOps.c
r41610 r41615 68 68 for (int ix = 0; ix < GridCorr[code]->Nx; ix++) { 69 69 FREE (GridCorr[code]-> Mgrid[ix]); 70 FREE (GridCorr[code]->dMgrid[ix]);71 FREE (GridCorr[code]->nMgrid[ix]);70 if (GridCorr[code]->dMgrid) FREE (GridCorr[code]->dMgrid[ix]); 71 if (GridCorr[code]->nMgrid) FREE (GridCorr[code]->nMgrid[ix]); 72 72 } 73 73 … … 85 85 } 86 86 87 GridCorrectionType *getGridCorr (int *Nlast) {87 GridCorrectionType *getGridCorrNext (int *Nlast) { 88 88 89 89 if (GridCorr == NULL) return NULL; … … 99 99 *Nlast = i; 100 100 } 101 return result; 102 } 103 104 GridCorrectionType *getGridCorrByCode (int code) { 105 106 if (GridCorr == NULL) return NULL; 107 108 if (code >= NGridCorr) return NULL; 109 if (code < 0) return NULL; 110 111 ALLOCATE(GridCorr[code], GridCorrectionType, 1) 112 GridCorrectionType *result = GridCorr[code]; 101 113 return result; 102 114 } … … 135 147 ALLOCATE (GridCorr[code]->nMgrid, int *, NX_BIN); 136 148 for (int ix = 0; ix < NX_BIN; ix++) { 137 ALLOCATE (GridCorr[code]-> Mgrid[ix], float, N X_BIN);138 ALLOCATE (GridCorr[code]->dMgrid[ix], float, N X_BIN);139 ALLOCATE (GridCorr[code]->nMgrid[ix], int, N X_BIN);149 ALLOCATE (GridCorr[code]-> Mgrid[ix], float, NY_BIN); 150 ALLOCATE (GridCorr[code]->dMgrid[ix], float, NY_BIN); 151 ALLOCATE (GridCorr[code]->nMgrid[ix], int, NY_BIN); 140 152 } 141 153 } -
branches/eam_branches/relphot.20210521/src/args.c
r41603 r41615 382 382 // GRID_ZEROPT is not valid for all cases, probably should be its own mode... 383 383 GRID_ZEROPT = FALSE; 384 GRID_MEANFILE = NULL; // this is set by GridCorrectionSave() 384 385 if ((N = get_argument (argc, argv, "-grid"))) { 385 386 remove_argument (N, &argc, argv); … … 602 603 FREE (REGION_FILE); 603 604 FREE (SYNTH_ZERO_POINTS); 605 FREE (GRID_MEANFILE); 604 606 FREE (IMAGE_TABLE); 605 607 FREE (CATDIR); … … 858 860 } 859 861 862 // load the GridCorrection file 863 GRID_ZEROPT = FALSE; 864 GRID_MEANFILE = NULL; 865 if ((N = get_argument (argc, argv, "-grid"))) { 866 GRID_ZEROPT = TRUE; 867 remove_argument (N, &argc, argv); 868 GRID_MEANFILE = strcreate (argv[N]); 869 remove_argument (N, &argc, argv); 870 } 871 860 872 ImagSelect = FALSE; 861 873 if ((N = get_argument (argc, argv, "-instmag"))) { … … 916 928 917 929 FREE (SYNTH_ZERO_POINTS); 930 FREE (GRID_MEANFILE); 918 931 FREE (BOUNDARY_TREE); 919 932 FREE (UPDATE_CATFORMAT); -
branches/eam_branches/relphot.20210521/src/reload_catalogs.c
r41607 r41615 264 264 if (BOUNDARY_TREE) { strextend (&command, "-boundary-tree %s", BOUNDARY_TREE); } 265 265 if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); } 266 if (GRID_ZEROPT) { strextend (&command, "-grid %s", GRID_MEANFILE); } 266 267 if (USE_BASIC_CHECK) { strextend (&command, "-basic-image-search"); } 267 268 if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); } -
branches/eam_branches/relphot.20210521/src/relphot_client.c
r41606 r41615 80 80 initImagesSubset (image, NULL, Nimage); 81 81 82 // load grid corrections here 83 GridCorrectionLoad (GRID_MEANFILE); 84 82 85 reload_catalogs (skylist, HOST_ID, HOSTDIR); 83 86 freeImages ((char *)image); 84 87 free (image); 88 freeGridBins (); 85 89 client_logger_message ("updated catalogs\n"); 86 90 relphot_client_free (sky, skylist); -
branches/eam_branches/relphot.20210521/src/relphot_images.c
r41610 r41615 144 144 freeTGroupBins (Ncatalog); 145 145 146 GridCorrectionSave ("test.grid.fits"); 146 GridCorrectionSave (); 147 147 148 // end of if (NLOOP > 0) block : this loop determines the offsets per chip 148 149 } else {
Note:
See TracChangeset
for help on using the changeset viewer.
