Changeset 34868
- Timestamp:
- Dec 21, 2012, 12:55:14 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20121219/Ohana/src/uniphot
- Files:
-
- 1 added
- 7 edited
-
Makefile (modified) (1 diff)
-
include/setastrom.h (modified) (3 diffs)
-
src/astrom_correction.c (modified) (4 diffs)
-
src/initialize_setastrom.c (modified) (6 diffs)
-
src/setastrom.c (modified) (1 diff)
-
src/setastrom_client.c (added)
-
src/update_catalog_setastrom.c (modified) (2 diffs)
-
src/update_dvo_setastrom.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/Makefile
r34867 r34868 118 118 $(SRC)/update_catalog_setastrom.$(ARCH).o \ 119 119 $(SRC)/astrom_correction.$(ARCH).o \ 120 $(SRC)/initialize_setastrom _client.$(ARCH).o120 $(SRC)/initialize_setastrom.$(ARCH).o 121 121 122 122 $(SETASTROM_CLIENT): $(INC)/setastrom.h -
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/include/setastrom.h
r34867 r34868 2 2 # include <dvo.h> 3 3 # include <signal.h> 4 5 // the interpolating spline information: this is based on the spline used by opihi/cmd.data/spline.c 6 typedef struct { 7 int Nknots; 8 double *xk; 9 double *yk; 10 double *y2; 11 } Spline; 4 12 5 13 /* global variables set in parameter file */ … … 14 22 int PARALLEL_MANUAL; 15 23 int PARALLEL_SERIAL; 24 char *UPDATE_CATFORMAT; 25 26 SkyRegion UserPatch; 16 27 17 28 /***** prototypes ****/ 18 29 int main PROTO((int argc, char **argv)); 19 30 31 void GetConfig PROTO((char *config, char *field, char *format, int N, void *ptr)); 20 32 void ConfigInit PROTO((int *argc, char **argv)); 33 21 34 void usage_setastrom PROTO(()); 22 35 void initialize_setastrom PROTO((int argc, char **argv)); … … 32 45 // int SetSignals PROTO((void)); 33 46 34 int update_dvo_setastrom PROTO(( ));35 int update_dvo_setastrom_parallel PROTO((SkyTable *sky ));47 int update_dvo_setastrom PROTO((char *corrfile)); 48 int update_dvo_setastrom_parallel PROTO((SkyTable *sky, char *corrfile)); 36 49 37 voidupdate_catalog_setastrom PROTO((Catalog *catalog));50 int update_catalog_setastrom PROTO((Catalog *catalog)); 38 51 52 // spline correction functions 53 int load_astrom_correction (char *filename); 54 int get_astrom_correction (int sub, int chip, double *dX, double *dY, float Minst); 55 double spline_apply_dbl (double *x, double *y, double *y2, int N, double X); -
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/src/astrom_correction.c
r34867 r34868 13 13 // these are stored in an N-D array of (Spline *) splineset[sub][dir][chip] 14 14 15 // the interpolating spline information: this is based on the spline used by opihi/cmd.data/spline.c16 typedef struct {17 int Nknots;18 double *xk;19 double *yk;20 double *y2;21 char *name;22 } Spline;23 24 15 # define N_SUB 2 25 16 # define N_DIR 2 … … 30 21 31 22 int load_astrom_correction (char *filename) { 23 24 int Ncol; 25 off_t Nrow; 26 27 char type[16]; 28 char extname[80]; 32 29 33 30 Header header; … … 54 51 55 52 // we have a N-D array of splines: 56 // splineset[subset][dir][chip] 57 ALLOCATE (splineset, Spline ***, 2); 58 for (sub = 0; sub < 2; sub++) { 59 ALLOCATE (splineset[sub], Spline **, 2); 60 for (dir = 0; dir < 2; dir++) { 61 ALLOCATE (splineset[sub][dir], Spline *, 78); 62 for (chip = 0; chip < 78; chip ++) { 53 // splineset[sub][dir][chip] 54 55 ALLOCATE (splineset, Spline ***, N_SUB); 56 for (sub = 0; sub < N_SUB; sub++) { 57 ALLOCATE (splineset[sub], Spline **, N_DIR); 58 for (dir = 0; dir < N_DIR; dir++) { 59 ALLOCATE (splineset[sub][dir], Spline *, N_CHIP); 60 for (chip = 0; chip < N_CHIP; chip ++) { 63 61 splineset[sub][dir][chip] = NULL; 64 62 } … … 70 68 if (!gfits_load_header (f, &theader)) break; 71 69 72 if (!gfits_fread_ftable_data (f, & table, FALSE)) return (FALSE);70 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (FALSE); 73 71 74 if (!gfits_scan ( header, "EXTNAME", "%s", 1, extname)) return (FALSE);72 if (!gfits_scan (&theader, "EXTNAME", "%s", 1, extname)) return (FALSE); 75 73 76 74 // figure out the chip ID, diretion, and sequence from the EXTNAME 77 75 78 int chip = XX; 79 int dir = XX; 80 int subset = XX; 76 // EXTNAME is of the form XY%d%d.D%s.T%s where 77 char chipname[3]; 78 chipname[0] = extname[2]; 79 chipname[1] = extname[3]; 80 chipname[2] = 0; 81 int chip = atoi(chipname); 82 myAssert (chip > 0, "error in extname %s not(chip > 0)\n", extname); 83 myAssert (chip < 77, "error in extname %s not(chip < 77)\n", extname); 84 myAssert (chip != 7, "error in extname %s not(chip != 7)\n", extname); 85 myAssert (chip != 70, "error in extname %s not(chip != 70)\n", extname); 81 86 82 splineset[sub][dir][chip] = CreateSpline (Nrow); 87 int dir = -1; 88 if (extname[6] == 'X') { 89 dir = 0; 90 } 91 if (extname[6] == 'Y') { 92 dir = 1; 93 } 94 myAssert (dir != -1, "error in extname %s (dir)\n", extname); 83 95 84 // XXX: need to handle case of spline data not existing... 85 96 int sub = -1; 97 if (extname[6] == '0') { 98 sub = 0; 99 } 100 if (extname[6] == '1') { 101 sub = 1; 102 } 103 myAssert (sub != -1, "error in extname %s (sub)\n", extname); 104 86 105 // need to create and assign to flat-field correction 87 106 double *xk = gfits_get_bintable_column_data (&theader, &ftable, "X_KNOT", type, &Nrow, &Ncol); 88 assert (!strcmp(type, "double"));107 myAssert (!strcmp(type, "double"), "error reading X_KNOT"); 89 108 90 109 // need to create and assign to flat-field correction 91 110 double *yk = gfits_get_bintable_column_data (&theader, &ftable, "Y_KNOT", type, &Nrow, &Ncol); 92 assert (!strcmp(type, "double"));111 myAssert (!strcmp(type, "double"), "error reading X_KNOT"); 93 112 94 113 // need to create and assign to flat-field correction 95 114 double *y2 = gfits_get_bintable_column_data (&theader, &ftable, "DY2_DX", type, &Nrow, &Ncol); 96 assert (!strcmp(type, "double"));115 myAssert (!strcmp(type, "double"), "error reading X_KNOT"); 97 116 117 ALLOCATE (splineset[sub][dir][chip], Spline, 1); 98 118 splineset[sub][dir][chip]->xk = xk; 99 119 splineset[sub][dir][chip]->yk = yk; 100 120 splineset[sub][dir][chip]->y2 = y2; 101 121 splineset[sub][dir][chip]->Nknots = Nrow; 102 122 } 103 123 return (TRUE); 104 124 } 125 126 int get_astrom_correction (int sub, int chip, double *dX, double *dY, float Minst) { 127 128 Spline *spline = NULL; 129 130 *dX = 0.0; 131 *dY = 0.0; 132 133 spline = splineset[sub][0][chip]; 134 if (spline) { 135 *dX = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst); 136 } 137 138 spline = splineset[sub][1][chip]; 139 if (spline) { 140 *dY = spline_apply_dbl (spline->xk, spline->yk, spline->y2, spline->Nknots, Minst); 141 } 142 return (TRUE); 143 } 144 145 /* evaluate spline for x, y, y2 at X */ 146 double spline_apply_dbl (double *x, double *y, double *y2, int N, double X) { 147 148 int i, lo, hi; 149 double dx, a, b, value; 150 151 /* find correct element in array (x must be sorted) */ 152 lo = 0; 153 hi = N-1; 154 while (hi - lo > 1) { 155 i = 0.5*(hi+lo); 156 if (x[i] > X) { 157 hi = i; 158 } else { 159 lo = i; 160 } 161 } 162 163 /* error condition: duplicate abssisca */ 164 dx = x[hi] - x[lo]; 165 if (dx == 0.0) { 166 return (HUGE_VAL); 167 } 168 169 /* evaluate spline */ 170 a = (x[hi] - X) / dx; 171 b = (X - x[lo]) / dx; 172 173 value = a*y[lo] + b*y[hi] + ((a*a*a - a)*y2[lo] + (b*b*b - b)*y2[hi])*(dx*dx) / 6.0; 174 return (value); 175 176 } -
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/src/initialize_setastrom.c
r34867 r34868 2 2 3 3 void usage_setastrom () { 4 fprintf (stderr, "USAGE: setastrom [options]\n");4 fprintf (stderr, "USAGE: setastrom (corrections) [options]\n"); 5 5 fprintf (stderr, " options:\n"); 6 6 fprintf (stderr, " -v : verbose mode\n"); 7 fprintf (stderr, " -region Rmin Rmax Dmin Dmax\n"); 8 fprintf (stderr, " -update-catformat (format) : change database schema on output\n"); 7 9 fprintf (stderr, " -update : actually write results to detections tables\n"); 8 10 fprintf (stderr, " -parallel : run in parallel mode\n"); … … 46 48 47 49 int N; 50 51 /* specify portion of the sky : allow default of all sky? */ 52 UserPatch.Rmin = 0; 53 UserPatch.Rmax = 360; 54 UserPatch.Dmin = -90; 55 UserPatch.Dmax = +90; 56 if ((N = get_argument (argc, argv, "-region"))) { 57 remove_argument (N, &argc, argv); 58 UserPatch.Rmin = atof (argv[N]); 59 remove_argument (N, &argc, argv); 60 UserPatch.Rmax = atof (argv[N]); 61 remove_argument (N, &argc, argv); 62 UserPatch.Dmin = atof (argv[N]); 63 remove_argument (N, &argc, argv); 64 UserPatch.Dmax = atof (argv[N]); 65 remove_argument (N, &argc, argv); 66 } 67 68 UPDATE_CATFORMAT = NULL; 69 if ((N = get_argument (argc, argv, "-update-catformat"))) { 70 remove_argument (N, &argc, argv); 71 UPDATE_CATFORMAT = strcreate (argv[N]); 72 remove_argument (N, &argc, argv); 73 } 48 74 49 75 VERBOSE = FALSE; … … 85 111 } 86 112 87 if (argc != 1) usage_setastrom();113 if (argc != 2) usage_setastrom(); 88 114 89 115 return (TRUE); … … 91 117 92 118 void usage_setastrom_client () { 93 fprintf (stderr, "USAGE: setastrom_client -hostID (hostID) -catdir (catdir) -hostdir (hostdir) -images (images) [options]\n");119 fprintf (stderr, "USAGE: setastrom_client (correction) -hostID (hostID) -catdir (catdir) -hostdir (hostdir) [options]\n"); 94 120 fprintf (stderr, " options:\n"); 121 fprintf (stderr, " -region Rmin Rmax Dmin Dmax\n"); 122 fprintf (stderr, " -update-catformat (format) : change database schema on output\n"); 95 123 fprintf (stderr, " -v : verbose mode\n"); 96 124 fprintf (stderr, " -update : actually write results to detections tables\n"); … … 129 157 int N; 130 158 159 /* specify portion of the sky : allow default of all sky? */ 160 UserPatch.Rmin = 0; 161 UserPatch.Rmax = 360; 162 UserPatch.Dmin = -90; 163 UserPatch.Dmax = +90; 164 if ((N = get_argument (argc, argv, "-region"))) { 165 remove_argument (N, &argc, argv); 166 UserPatch.Rmin = atof (argv[N]); 167 remove_argument (N, &argc, argv); 168 UserPatch.Rmax = atof (argv[N]); 169 remove_argument (N, &argc, argv); 170 UserPatch.Dmin = atof (argv[N]); 171 remove_argument (N, &argc, argv); 172 UserPatch.Dmax = atof (argv[N]); 173 remove_argument (N, &argc, argv); 174 } 175 176 UPDATE_CATFORMAT = NULL; 177 if ((N = get_argument (argc, argv, "-update-catformat"))) { 178 remove_argument (N, &argc, argv); 179 UPDATE_CATFORMAT = strcreate (argv[N]); 180 remove_argument (N, &argc, argv); 181 } 182 131 183 VERBOSE = FALSE; 132 184 if ((N = get_argument (argc, argv, "-v"))) { … … 164 216 if (!CATDIR) usage_setastrom_client(); 165 217 166 IMAGES = NULL; 167 if ((N = get_argument (argc, argv, "-images"))) { 168 remove_argument (N, &argc, argv); 169 IMAGES = strcreate (argv[N]); 170 remove_argument (N, &argc, argv); 171 } 172 if (!IMAGES) usage_setastrom_client(); 173 174 if (argc != 1) usage_setastrom_client(); 218 if (argc != 2) usage_setastrom_client(); 175 219 return (TRUE); 176 220 } 177 178 void GetConfig (char *config, char *field, char *format, int N, void *ptr);179 221 180 222 void ConfigInit (int *argc, char **argv) { -
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/src/setastrom.c
r34866 r34868 4 4 5 5 int status; 6 FITS_DB db;7 6 8 7 /* get configuration info, args, lockfile */ 9 8 initialize_setastrom (argc, argv); 10 9 11 load_correction (); 12 13 status = update_dvo_setastrom (subset, Nimage); 10 // argv[1] holds the correction file 11 status = update_dvo_setastrom (argv[1]); 14 12 15 13 if (!status) exit (1); -
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/src/update_catalog_setastrom.c
r34866 r34868 7 7 int update_catalog_setastrom (Catalog *catalog) { 8 8 9 off_t i, j,found;9 off_t i, found; 10 10 11 int timeRef = somefunc("2011/05/11");11 time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00"); 12 12 13 13 for (i = 0; i < catalog[0].Nmeasure; i++) { … … 19 19 double Xccd = catalog[0].measure[i].Xccd; 20 20 double Yccd = catalog[0].measure[i].Yccd; 21 double posAngle = FromShortDegrees(catalog[0].measure[i].posangle);22 21 double pltScale = fabs(catalog[0].measure[i].pltscale); 22 23 // this is not needed, is it? 24 // double posAngle = FromShortDegrees(catalog[0].measure[i].posangle); 23 25 24 26 // I need to know which chip we have. use photcode assuming range 25 27 int chip = catalog[0].measure[i].photcode % 100; 26 28 29 float Minst = PhotInst (&catalog[0].measure[i]); 30 31 double dX; 32 double dY; 33 27 34 // correction is in arcseconds 28 35 if (catalog[0].measure[i].t < timeRef) { 29 get_ correction (0, chip, &dX, &dY);36 get_astrom_correction (0, chip, &dX, &dY, Minst); 30 37 } else { 31 get_ correction (1, chip, &dX, &dY);38 get_astrom_correction (1, chip, &dX, &dY, Minst); 32 39 } 33 40 -
branches/eam_branches/ipp-20121219/Ohana/src/uniphot/src/update_dvo_setastrom.c
r34866 r34868 1 1 # include "setastrom.h" 2 2 3 int update_dvo_setastrom ( ) {3 int update_dvo_setastrom (char *corrfile) { 4 4 5 SkyRegion UserPatch;6 5 SkyTable *sky = NULL; 7 6 SkyList *skylist = NULL; 8 7 Catalog catalog; 9 off_t i , maxID, *index;8 off_t i; 10 9 11 10 // load the current sky table (layout of all SkyRegions) … … 14 13 15 14 if (PARALLEL && !HOST_ID) { 16 update_dvo_setastrom_parallel (sky);17 return TRUE;15 int status = update_dvo_setastrom_parallel (sky, corrfile); 16 return status; 18 17 } 19 18 19 load_astrom_correction (corrfile); 20 20 21 // determine the populated SkyRegions overlapping the requested area (default depth) 21 UserPatch.Rmin = 0;22 UserPatch.Rmax = 360;23 UserPatch.Dmin = -90;24 UserPatch.Dmax = +90;25 22 skylist = SkyListByPatch (sky, -1, &UserPatch); 26 23 … … 60 57 } 61 58 62 XXX: update format here 59 // modify the output format as desired (ignore current format on disk) 60 if (UPDATE_CATFORMAT) { 61 catalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT); 62 } 63 63 64 64 if (VERBOSE) fprintf (stderr, "saving catalog %s\n", catalog.filename); … … 73 73 # define DEBUG 1 74 74 75 int update_dvo_setastrom_parallel (SkyTable *sky ) {75 int update_dvo_setastrom_parallel (SkyTable *sky, char *corrfile) { 76 76 77 77 // now launch the setastrom_client jobs to the parallel hosts 78 79 char *abscorrfile = abspath (corrfile, DVO_MAX_PATH); 78 80 79 81 // load the list of hosts … … 89 91 90 92 char command[1024]; 91 snprintf (command, 1024, "setastrom_client -hostID %d -catdir %s -hostdir %s", 92 table->hosts[i].hostID, CATDIR, table->hosts[i].pathname); 93 snprintf (command, 1024, "setastrom_client %s -hostID %d -catdir %s -hostdir %s -region %f %f %f %f", 94 abscorrfile, table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, 95 UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax); 93 96 94 97 fprintf (stderr, "command: %s\n", command); 95 98 96 99 char tmpline[1024]; 97 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 98 if (UPDATE) { snprintf (tmpline, 1024, "%s -update", command); strcpy (command, tmpline); } 100 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 101 if (UPDATE) { snprintf (tmpline, 1024, "%s -update", command); strcpy (command, tmpline); } 102 if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); } 99 103 100 104 if (PARALLEL_MANUAL) continue; … … 117 121 } 118 122 } 123 free (abscorrfile); 119 124 120 125 // wait for the remote jobs to be completed
Note:
See TracChangeset
for help on using the changeset viewer.
