IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39288 for trunk


Ignore:
Timestamp:
Dec 17, 2015, 8:53:56 PM (11 years ago)
Author:
eugene
Message:

merge astrometric corrections into setphot; add some history headers

Location:
trunk/Ohana/src/uniphot
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/uniphot/Makefile

    r39272 r39288  
    1 # default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client setgalmodel setgalmodel_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
    2 default: uniphot setfwhm setposangle setposangle_client setastrom setastrom_client setgalmodel setgalmodel_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
     1default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client setgalmodel setgalmodel_client fiximids fiximids_client fixstkids fixstkids_client ckids ckids_client
    32
    43help:
     
    3635ckids_client: $(BIN)/ckids_client.$(ARCH)
    3736
    38 # install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/setgalmodel $(DESTBIN)/setgalmodel_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
    39 install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/setgalmodel $(DESTBIN)/setgalmodel_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
     37install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/setgalmodel $(DESTBIN)/setgalmodel_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client $(DESTBIN)/fixstkids $(DESTBIN)/fixstkids_client $(DESTBIN)/ckids $(DESTBIN)/ckids_client
    4038
    4139UNIPHOT = \
     
    7068$(SRC)/match_camcorr_to_images.$(ARCH).o            \
    7169$(SRC)/cam_zpt_correction.$(ARCH).o         \
     70$(SRC)/cam_correction.$(ARCH).o \
     71$(SRC)/dcr_correction.$(ARCH).o \
     72$(SRC)/kh_correction.$(ARCH).o \
     73$(SRC)/astrom_correction.$(ARCH).o \
    7274$(SRC)/update_dvo_setphot.$(ARCH).o \
    7375$(SRC)/update_catalog_setphot.$(ARCH).o \
     76$(SRC)/update_catalog_setastrom.$(ARCH).o \
    7477$(SRC)/repair_catalog_by_objID.$(ARCH).o \
    7578$(SRC)/SetSignals.$(ARCH).o         \
     
    8386$(SRC)/update_dvo_setphot.$(ARCH).o \
    8487$(SRC)/update_catalog_setphot.$(ARCH).o \
     88$(SRC)/update_catalog_setastrom.$(ARCH).o \
    8589$(SRC)/repair_catalog_by_objID.$(ARCH).o \
    8690$(SRC)/initialize_setphot_client.$(ARCH).o \
     91$(SRC)/cam_zpt_correction.$(ARCH).o         \
     92$(SRC)/cam_correction.$(ARCH).o \
     93$(SRC)/dcr_correction.$(ARCH).o \
     94$(SRC)/kh_correction.$(ARCH).o \
     95$(SRC)/astrom_correction.$(ARCH).o \
    8796$(SRC)/SetSignals.$(ARCH).o         \
    8897$(SRC)/Shutdown.$(ARCH).o           \
  • trunk/Ohana/src/uniphot/include/setastrom.h

    r38986 r39288  
    3030  Matrix **matrix; // allocate an array of pointers
    3131  // index = ix + iy*Nx + filter*Nchips + dir*Ngroup
    32 } CamCorrection;
     32} CamAstromCorrection;
    3333
    3434/* global variables set in parameter file */
     
    4848char        *KH_FILE;
    4949char        *DCR_FILE;
    50 char        *CAM_FILE;
    5150char        *TYC_FILE;
     51
     52char        *CAM_ASTROM_FILE;
    5253
    5354int          KH_RESET;
     
    9192int get_dcr_correction (int filter, double *dX, double *dY, float Color);
    9293
    93 int load_cam_correction (char *filename);
    94 int get_cam_correction (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY);
     94int CamAstromCorrectionLoad (char *filename);
     95int CamAstromCorrectionValue (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY);
    9596
    9697int load_tyc_correction (char *filename);
  • trunk/Ohana/src/uniphot/include/setphot.h

    r39272 r39288  
    4343 
    4444  // index = ix + iy*Nx + filter*Nchips + dir*Ngroup
    45 } CamCorrection;
     45} CamPhotomCorrection;
    4646
    4747/* global variables set in parameter file */
     
    5353char        *IMAGES;
    5454char        *SINGLE_CPT;
    55 char        *CAM_FILE;
     55
     56char        *KH_FILE;
     57char        *DCR_FILE;
     58char        *CAM_PHOTOM_FILE;
     59char        *CAM_ASTROM_FILE;
     60
     61int          KH_RESET;
     62int          DCR_RESET;
     63int          CAM_RESET;
     64
    5665int          VERBOSE;
    5766int          RESET;
     
    96105Image        *load_images_setphot    PROTO((FITS_DB *db, off_t *Nimage));
    97106int           match_zpts_to_images   PROTO((Image *image, off_t Nimage, ZptTable *zpts, int Nzpts));
    98 int           update_dvo_setphot     PROTO((Image *image, off_t Nimage, CamCorrection *camcorr));
    99 void          update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage, CamCorrection *camcorr));
     107int           update_dvo_setphot     PROTO((Image *image, off_t Nimage, CamPhotomCorrection *camcorr));
     108void          update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage, CamPhotomCorrection *camcorr));
    100109void          update_catalog_setphot_client PROTO((Catalog *catalog, ImageSubset *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr));
    101110
     
    109118int           repair_catalog_by_objID     PROTO((Catalog *catalog));
    110119
    111 void           free_cam_correction          PROTO((CamCorrection *cam));
    112 CamCorrection *alloc_cam_correction         PROTO((int Nx, int Ny, int Nfilter, int Nseason));
    113 CamCorrection *load_cam_correction          PROTO((char *filename));
    114 int            save_cam_correction          PROTO((CamCorrection *cam, char *filename));
    115 // int            get_cam_correction        PROTO((int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY));
    116 float          get_cam_correction           PROTO((CamCorrection *cam, int flat_id, float Xccd, float Yccd));
    117 CamCorrection *merge_flatcorr_and_camcorr   PROTO((FlatCorrectionTable *flatcorr, CamCorrection *camcorr));
     120void          CamPhotomCorrectionFree            PROTO((CamPhotomCorrection *cam));
     121CamPhotomCorrection *CamPhotomCorrectionAlloc    PROTO((int Nx, int Ny, int Nfilter, int Nseason));
     122CamPhotomCorrection *CamPhotomCorrectionLoad     PROTO((char *filename));
     123int            CamPhotomCorrectionSave           PROTO((CamPhotomCorrection *cam, char *filename));
     124float          CamPhotomCorrectionValue          PROTO((CamPhotomCorrection *cam, int flat_id, float Xccd, float Yccd));
    118125
    119 int            match_camcorr_to_images      PROTO((Image *image, off_t Nimage, CamCorrection *camcorr));
     126int            match_camcorr_to_images      PROTO((Image *image, off_t Nimage, CamPhotomCorrection *camcorr));
     127CamPhotomCorrection *merge_flatcorr_and_camcorr   PROTO((FlatCorrectionTable *flatcorr, CamPhotomCorrection *camcorr));
     128
     129// spline correction functions
     130double spline_apply_dbl (double *x, double *y, double *y2, int N, double X);
     131
     132int load_kh_correction (char *filename);
     133int get_kh_correction (int sub, int chip, double *dX, double *dY, float Minst);
     134
     135int load_dcr_correction (char *filename);
     136int get_dcr_correction (int filter, double *dX, double *dY, float Color);
     137
     138int CamAstromCorrectionLoad (char *filename);
     139int CamAstromCorrectionValue (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY);
     140
     141
     142int           update_catalog_setastrom        PROTO((Catalog *catalog));
  • trunk/Ohana/src/uniphot/src/cam_correction.c

    r39262 r39288  
    66// note that we are allocating pointers for XY00 - XY77, but only the octal elements are set (and not the 00,07,70,77 ones)
    77
    8 static CamCorrection *cam = NULL;
     8static CamAstromCorrection *cam = NULL;
    99
    10 int load_cam_correction (char *filename) {
     10int CamAstromCorrectionLoad (char *filename) {
    1111
    1212  int i, ix, iy, dir, filter;
     
    2020  }
    2121
    22   ALLOCATE (cam, CamCorrection, 1);
     22  ALLOCATE (cam, CamAstromCorrection, 1);
    2323
    2424  // read the PHU header
     
    9696// chipID == octal chip ID (eg 40 for XY40)
    9797// filter == (01234 = grizy)
    98 int get_cam_correction (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY) {
     98int CamAstromCorrectionValue (int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY) {
    9999
    100100  *dX = 0.0;
  • trunk/Ohana/src/uniphot/src/cam_zpt_correction.c

    r39278 r39288  
    99// note that we are allocating pointers for XY00 - XY77, but only the octal elements are set (and not the 00,07,70,77 ones)
    1010
    11 void free_cam_correction (CamCorrection *cam) {
     11void CamPhotomCorrectionFree (CamPhotomCorrection *cam) {
    1212
    1313  if (!cam) return;
     
    2828}
    2929
    30 CamCorrection *alloc_cam_correction (int Nx, int Ny, int Nfilter, int Nseason) {
    31 
    32   CamCorrection *cam;
    33 
    34   ALLOCATE (cam, CamCorrection, 1);
     30CamPhotomCorrection *CamPhotomCorrectionAlloc (int Nx, int Ny, int Nfilter, int Nseason) {
     31
     32  CamPhotomCorrection *cam;
     33
     34  ALLOCATE (cam, CamPhotomCorrection, 1);
    3535
    3636  cam->phu = NULL;
     
    5959}
    6060
    61 CamCorrection *load_cam_correction (char *filename) {
     61CamPhotomCorrection *CamPhotomCorrectionLoad (char *filename) {
    6262
    6363  int i, ix, iy, season, filter;
     
    8888  if (!gfits_scan (phu, "NY_CHIP", "%d", 1, &NyCCD))   return FALSE;
    8989
    90   CamCorrection *cam = alloc_cam_correction (Nx, Ny, Nfilter, Nseason);
     90  CamPhotomCorrection *cam = CamPhotomCorrectionAlloc (Nx, Ny, Nfilter, Nseason);
    9191  cam->phu = phu;
    9292
     
    140140}
    141141
    142 int save_cam_correction (CamCorrection *cam, char *filename) {
     142int CamPhotomCorrectionSave (CamPhotomCorrection *cam, char *filename) {
    143143
    144144  int i;
     
    170170}
    171171
    172 # if (0)
    173 // input is:
    174 // chipID == octal chip ID (eg 40 for XY40)
    175 // filter == (01234 = grizy)
    176 int get_cam_correction (CamCorrection *cam, int chipID, int filter, float Xccd, float Yccd, double *dX, double *dY) {
    177 
    178   *dX = 0.0;
    179   *dY = 0.0;
    180 
    181   int index, jx, jy, NxModel;
    182   Matrix *matrix;
    183   float *buffer, value;
    184 
    185   // split out the chipID number (eg 43 for XY43) into X and Y elements
    186   int ix = (int) (chipID / 10);
    187   int iy = (int) (chipID % 10);
    188 
    189   // dX (dir == 0)
    190   index = ix + iy*cam->Nx + filter*cam->Nchips;
    191 
    192   matrix = cam->matrix[index];
    193   NxModel = cam->matrix[index]->Naxis[0];
    194 
    195   buffer = (float *) matrix->buffer;
    196 
    197   jx = MAX(MIN(cam->NxCCD, Xccd / cam->dX), 0);
    198   jy = MAX(MIN(cam->NyCCD, Yccd / cam->dY), 0);
    199 
    200   value = buffer[jx + jy*NxModel];
    201 
    202   *dX = isnan(value) ? 0.0 : value;
    203 
    204   // dY (dir == 1) uses the next block
    205   index += cam->Ngroup;
    206 
    207   matrix = cam->matrix[index];
    208   NxModel = cam->matrix[index]->Naxis[0];
    209 
    210   buffer = (float *) matrix->buffer;
    211 
    212   jx = MAX(MIN(cam->NxCCD, Xccd / cam->dX), 0);
    213   jy = MAX(MIN(cam->NyCCD, Yccd / cam->dY), 0);
    214 
    215   value = buffer[jx + jy*NxModel];
    216 
    217   *dY = isnan(value) ? 0.0 : value;
    218 
    219   return TRUE;
    220 }
    221 # endif
    222 
    223 float get_cam_correction (CamCorrection *cam, int flat_id, float Xccd, float Yccd) {
     172float CamPhotomCorrectionValue (CamPhotomCorrection *cam, int flat_id, float Xccd, float Yccd) {
    224173
    225174  if (!flat_id) return 0.0;
     
    249198}
    250199
    251 CamCorrection *merge_flatcorr_and_camcorr (FlatCorrectionTable *flatcorr, CamCorrection *camcorr) {
     200CamPhotomCorrection *merge_flatcorr_and_camcorr (FlatCorrectionTable *flatcorr, CamPhotomCorrection *camcorr) {
    252201
    253202  int i, j, ix, iy, Nf, Ns;
     
    260209  myAssert (camcorr->Nseason == 1, "no code to merge seasons flats to seasonal flats");
    261210
    262   // we need to create a new CamCorrection with Nx,Ny,Nfilter from camcorr and Nseason from flatcorr:
    263   CamCorrection *newcorr = alloc_cam_correction (camcorr->Nx, camcorr->Ny, camcorr->Nfilter, flatcorr->Nseason);
     211  // we need to create a new CamPhotomCorrection with Nx,Ny,Nfilter from camcorr and Nseason from flatcorr:
     212  CamPhotomCorrection *newcorr = CamPhotomCorrectionAlloc (camcorr->Nx, camcorr->Ny, camcorr->Nfilter, flatcorr->Nseason);
    264213  newcorr->phu = gfits_alloc_header();
    265214  gfits_create_header(newcorr->phu);
  • trunk/Ohana/src/uniphot/src/dcr_correction.c

    r37807 r39288  
    2626
    2727  char type[16];
    28   char extname[80];
    2928
    3029  Header header;
     
    6766    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (FALSE);
    6867   
    69     if (!gfits_scan (&theader, "EXTNAME", "%s", 1, extname)) return (FALSE);
     68    char word[80];
     69    if (!gfits_scan (&theader, "EXTNAME", "%s", 1, word)) return (FALSE);
     70    char *extname = strcreate(word);
    7071
    7172    // figure out the filter and direction from the EXTNAME
     73    // EXTNAME is of the form DCR.[grizy].dP[xy]
    7274
    73     // EXTNAME is of the form [grizy].[xy].v0 where
    74     char filtname = extname[0];
     75    char *ptr = NULL;
     76    char *w0 = strtok_r (extname, ".", &ptr); myAssert (w0, "invalid dcr file");
     77    char *w1 = strtok_r (NULL, ".", &ptr); myAssert (w1, "invalid dcr file");
     78    char *w2 = strtok_r (NULL, ".", &ptr); myAssert (w2, "invalid dcr file");
     79   
     80    myAssert (!strcmp(w0, "DCR"), "invalid dcr file");
     81
     82    char filtname = w1[0];
    7583    int filtnum = -1;
    7684    switch (filtname) {
     
    8694
    8795    int dir = -1;
    88     if (extname[2] == 'x') {
     96    if (w2[2] == 'x') {
    8997      dir = 0;
    9098    }
    91     if (extname[2] == 'y') {
     99    if (w2[2] == 'y') {
    92100      dir = 1;
    93101    }
  • trunk/Ohana/src/uniphot/src/initialize_setastrom.c

    r38464 r39288  
    7979  }
    8080
    81   CAM_FILE = NULL;
     81  CAM_ASTROM_FILE = NULL;
    8282  if ((N = get_argument (argc, argv, "-CAM"))) {
    8383    remove_argument (N, &argc, argv);
    8484    char *tmpfile = strcreate (argv[N]);
    85     CAM_FILE = abspath (tmpfile, DVO_MAX_PATH);
     85    CAM_ASTROM_FILE = abspath (tmpfile, DVO_MAX_PATH);
    8686    remove_argument (N, &argc, argv);
    8787  }
     
    174174  }
    175175
    176   if (!KH_FILE && !DCR_FILE && !CAM_FILE && !TYC_FILE) {
     176  if (!KH_FILE && !DCR_FILE && !CAM_ASTROM_FILE && !TYC_FILE) {
    177177    fprintf (stderr, "WARNING: none of -CAM, -KH, -DCR, -TYC supplied\n");
    178178  }
     
    252252  }
    253253
    254   CAM_FILE = NULL;
     254  CAM_ASTROM_FILE = NULL;
    255255  if ((N = get_argument (argc, argv, "-CAM"))) {
    256256    remove_argument (N, &argc, argv);
    257     CAM_FILE = strcreate (argv[N]);
     257    CAM_ASTROM_FILE = strcreate (argv[N]);
    258258    remove_argument (N, &argc, argv);
    259259  }
     
    336336  if (!CATDIR) usage_setastrom_client();
    337337
    338   if (!KH_FILE && !DCR_FILE && !CAM_FILE && !TYC_FILE) {
     338  if (!KH_FILE && !DCR_FILE && !CAM_ASTROM_FILE && !TYC_FILE) {
    339339    fprintf (stderr, "WARNING: none of -CAM, -KH, -DCR, -TYC supplied\n");
    340340  }
  • trunk/Ohana/src/uniphot/src/initialize_setphot.c

    r39272 r39288  
    3434  int N;
    3535
    36   CAM_FILE = NULL;
     36  KH_FILE = NULL;
     37  if ((N = get_argument (argc, argv, "-KH"))) {
     38    remove_argument (N, &argc, argv);
     39    char *tmpfile = strcreate (argv[N]);
     40    KH_FILE = abspath (tmpfile, DVO_MAX_PATH);
     41    remove_argument (N, &argc, argv);
     42  }
     43  KH_RESET = FALSE;
     44  if ((N = get_argument (argc, argv, "-KH-reset"))) {
     45    remove_argument (N, &argc, argv);
     46    KH_RESET = TRUE;
     47  }
     48
     49  DCR_FILE = NULL;
     50  if ((N = get_argument (argc, argv, "-DCR"))) {
     51    remove_argument (N, &argc, argv);
     52    char *tmpfile = strcreate (argv[N]);
     53    DCR_FILE = abspath (tmpfile, DVO_MAX_PATH);
     54    remove_argument (N, &argc, argv);
     55  }
     56  DCR_RESET = FALSE;
     57  if ((N = get_argument (argc, argv, "-DCR-reset"))) {
     58    remove_argument (N, &argc, argv);
     59    DCR_RESET = TRUE;
     60  }
     61
     62  CAM_ASTROM_FILE = NULL;
     63  if ((N = get_argument (argc, argv, "-CAM"))) {
     64    remove_argument (N, &argc, argv);
     65    char *tmpfile = strcreate (argv[N]);
     66    CAM_ASTROM_FILE = abspath (tmpfile, DVO_MAX_PATH);
     67    remove_argument (N, &argc, argv);
     68  }
     69  CAM_RESET = FALSE;
     70  if ((N = get_argument (argc, argv, "-CAM-reset"))) {
     71    remove_argument (N, &argc, argv);
     72    CAM_RESET = TRUE;
     73  }
     74
     75  CAM_PHOTOM_FILE = NULL;
    3776  if ((N = get_argument (argc, argv, "-cam-flat"))) {
    3877    remove_argument (N, &argc, argv);
    3978    char *tmpfile = strcreate (argv[N]);
    40     CAM_FILE = abspath (tmpfile, DVO_MAX_PATH);
     79    CAM_PHOTOM_FILE = abspath (tmpfile, DVO_MAX_PATH);
    4180    remove_argument (N, &argc, argv);
    4281  }
     
    126165    remove_argument (N, &argc, argv);
    127166    UBERCAL = TRUE;
    128     if (!CAM_FILE) {
     167    if (!CAM_PHOTOM_FILE) {
    129168      fprintf (stderr, "ubercal now requires a high-res static flat-file: -cam-flat filename\n");
    130169      exit (2);
  • trunk/Ohana/src/uniphot/src/initialize_setphot_client.c

    r39262 r39288  
    2727  int N;
    2828
    29   CAM_FILE = NULL;
     29  KH_FILE = NULL;
     30  if ((N = get_argument (argc, argv, "-KH"))) {
     31    remove_argument (N, &argc, argv);
     32    char *tmpfile = strcreate (argv[N]);
     33    KH_FILE = abspath (tmpfile, DVO_MAX_PATH);
     34    remove_argument (N, &argc, argv);
     35  }
     36  KH_RESET = FALSE;
     37  if ((N = get_argument (argc, argv, "-KH-reset"))) {
     38    remove_argument (N, &argc, argv);
     39    KH_RESET = TRUE;
     40  }
     41
     42  DCR_FILE = NULL;
     43  if ((N = get_argument (argc, argv, "-DCR"))) {
     44    remove_argument (N, &argc, argv);
     45    char *tmpfile = strcreate (argv[N]);
     46    DCR_FILE = abspath (tmpfile, DVO_MAX_PATH);
     47    remove_argument (N, &argc, argv);
     48  }
     49  DCR_RESET = FALSE;
     50  if ((N = get_argument (argc, argv, "-DCR-reset"))) {
     51    remove_argument (N, &argc, argv);
     52    DCR_RESET = TRUE;
     53  }
     54
     55  CAM_ASTROM_FILE = NULL;
    3056  if ((N = get_argument (argc, argv, "-CAM"))) {
    3157    remove_argument (N, &argc, argv);
    3258    char *tmpfile = strcreate (argv[N]);
    33     CAM_FILE = abspath (tmpfile, DVO_MAX_PATH);
     59    CAM_ASTROM_FILE = abspath (tmpfile, DVO_MAX_PATH);
    3460    remove_argument (N, &argc, argv);
    3561  }
     
    3965    CAM_RESET = TRUE;
    4066  }
     67
     68  CAM_PHOTOM_FILE = NULL;
     69/*
     70  if ((N = get_argument (argc, argv, "-cam-flat"))) {
     71    remove_argument (N, &argc, argv);
     72    char *tmpfile = strcreate (argv[N]);
     73    CAM_PHOTOM_FILE = abspath (tmpfile, DVO_MAX_PATH);
     74    remove_argument (N, &argc, argv);
     75  }
     76*/
    4177
    4278  VERBOSE = FALSE;
  • trunk/Ohana/src/uniphot/src/match_camcorr_to_images.c

    r39272 r39288  
    44// the photcode is used to find the actual flat correction
    55
    6 int match_camcorr_to_images (Image *image, off_t Nimage, CamCorrection *camcorr) {
     6int match_camcorr_to_images (Image *image, off_t Nimage, CamPhotomCorrection *camcorr) {
    77
    88  int i, j;
    99
    10   // we have an array of CamCorrection->matrix values, where each matrix is a flat-field image
     10  // we have an array of CamPhotomCorrection->matrix values, where each matrix is a flat-field image
    1111  // the sequence is seq = ix + Nx_chip*iy + filter*Nchips + season*(Nchips*Nfilter)
    1212
  • trunk/Ohana/src/uniphot/src/setphot.c

    r39272 r39288  
    88  ZptTable *zpts;
    99
    10   CamCorrection *camcorr = NULL;
     10  CamPhotomCorrection *camcorr = NULL;
    1111  FlatCorrectionTable flatcorrTable;
    1212
     
    3131    // XXX should this program save any old copy of this file?
    3232
    33     CamCorrection *rawcorr = load_cam_correction (CAM_FILE);
     33    CamPhotomCorrection *rawcorr = CamPhotomCorrectionLoad (CAM_PHOTOM_FILE);
    3434    if (!rawcorr) {
    3535      fprintf (stderr, "failed to load camera-static flat-field correction\n");
     
    4141    size = snprintf (newflatfile, DVO_MAX_PATH, "%s/flatfield.fits", CATDIR);
    4242    assert (size < DVO_MAX_PATH);
    43     save_cam_correction (camcorr, newflatfile);
     43    CamPhotomCorrectionSave (camcorr, newflatfile);
    4444  } else {
    4545    zpts = load_zpt_table (argv[1], &Nzpts);
  • trunk/Ohana/src/uniphot/src/setphot_client.c

    r38986 r39288  
    2222
    2323  // load the flat-field correction table from CATDIR
    24   char flatcorrFile[1024];
    25   snprintf (flatcorrFile, 1024, "%s/flatcorr.fits", CATDIR);
    26   FlatCorrectionTable *flatcorrTable = FlatCorrectionLoad (flatcorrFile, VERBOSE);
     24  char flatfieldFile[1024];
     25  snprintf (flatfieldFile, 1024, "%s/flatfield.fits", CATDIR);
    2726
    28   update_dvo_setphot (image, Nimage, flatcorrTable);
     27  CamPhotomCorrection *camcorr = CamPhotomCorrectionLoad (flatfieldFile);
     28  if (!camcorr) {
     29    fprintf (stderr, "failed to load camera-static flat-field correction\n");
     30    exit (2);
     31  }
     32
     33  update_dvo_setphot (image, Nimage, camcorr);
    2934
    3035  exit (0);
  • trunk/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r38986 r39288  
    1111  off_t i;
    1212
     13  // this is the special date when KH corrections stopped being needed
    1314  time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00");
    1415
     
    121122    double dX_CAM = 0.0;
    122123    double dY_CAM = 0.0;
    123     if (CAM_FILE) {
     124    if (CAM_ASTROM_FILE) {
    124125
    125126      // camera systematic correction ("astroflat") depends on only the X,Y coordinate,
     
    130131
    131132      // correction is in arcseconds
    132       get_cam_correction (chipID, filtCode, measure->Xccd, measure->Yccd, &dX_CAM, &dY_CAM);
     133      CamAstromCorrectionValue (chipID, filtCode, measure->Xccd, measure->Yccd, &dX_CAM, &dY_CAM);
    133134    }
    134135
     
    166167      }
    167168      int filtSeq = filtCode % 100;
    168       if (!isfinite(dColor)) goto skip_DCR;
     169      if (!isfinite(dColor)) {
     170        goto skip_DCR;
     171      }
    169172
    170173      // I need to get the parallactic angle, but I only have alt & az, s:o
     
    195198      // WARNING: these are NOT sin(ha),cos(ha) but are scaled
    196199      // double ha = DEG_RAD * atan2 (sinh, cosh);
    197       double sinh = -cs_alt * sn_az;
    198       double cosh =  sn_alt * cs_lat - cs_alt * cs_az * sn_lat;
    199       double r_ha = hypot(sinh, cosh);
    200       double sn_ha = sinh / r_ha;
    201       double cs_ha = cosh / r_ha;
    202 
    203       sinh = -cs_az * sn_alt * sn_ha * sn_lat + sn_az * sn_alt * cs_ha - sn_ha * cs_alt * cs_lat;
    204       cosh = -sn_az          * sn_ha * sn_lat - cs_az          * cs_ha;
    205       double r_rot = hypot(sinh, cosh);
    206 
    207       double sn_rot = -sinh / r_rot;
    208       double cs_rot = +cosh / r_rot;
     200
     201      // EAM 20151217: this is the old version of the code.  it is mathematically identical but does some extra work:
     202      // double sinh = -cs_alt * sn_az;
     203      // double cosh =  sn_alt * cs_lat - cs_alt * cs_az * sn_lat;
     204      // double r_ha = hypot(sinh, cosh);
     205      // double sn_ha = sinh / r_ha;
     206      // double cs_ha = cosh / r_ha;
     207
     208      // sinh = -cs_az * sn_alt * sn_ha * sn_lat + sn_az * sn_alt * cs_ha - sn_ha * cs_alt * cs_lat;
     209      // cosh = -sn_az          * sn_ha * sn_lat - cs_az          * cs_ha;
     210      // double r_rot = hypot(sinh, cosh);
     211      // double sn_rot = -sinh / r_rot;
     212      // double cs_rot = +cosh / r_rot;
     213
     214      // EAM 20151217: this is the new version:
     215      double sn_ha = -cs_alt * sn_az;
     216      double cs_ha =  sn_alt * cs_lat - cs_alt * cs_az * sn_lat;
     217
     218      double sn_rot_r = -cs_az * sn_alt * sn_ha * sn_lat + sn_az * sn_alt * cs_ha - sn_ha * cs_alt * cs_lat;
     219      double cs_rot_r = -sn_az          * sn_ha * sn_lat - cs_az          * cs_ha;
     220      double r_rot = hypot(sn_rot_r, cs_rot_r);
     221
     222      double sn_rot = -sn_rot_r / r_rot;
     223      double cs_rot =  cs_rot_r / r_rot;
    209224
    210225      double dPx = 0.0;
     
    248263
    249264    // do not modify the original Xccd,Yccd values
     265    // dR,dD are measured as measure.D - average.D
     266    // thus we correct back to the truth (average) with
     267    // average.D = measure.D - dD
    250268    if (KH_FILE) {
    251269      measure[0].XoffKH = -dX_KH / pltScale;
     
    264282      measure[0].YoffDCR = 0.0;
    265283    }
    266     if (CAM_FILE) {
     284    if (CAM_ASTROM_FILE) {
    267285      measure[0].XoffCAM = -dX_CAM / pltScale;
    268286      measure[0].YoffCAM = -dY_CAM / pltScale;
     
    291309
    292310  if (found) {
    293     fprintf (stderr, "found "OFF_T_FMT" matches\n", found);
     311    fprintf (stderr, "found "OFF_T_FMT" matches for setastrom\n", found);
    294312  }
    295313
  • trunk/Ohana/src/uniphot/src/update_catalog_setphot.c

    r39279 r39288  
    11# include "setphot.h"
    22
    3 void update_catalog_setphot (Catalog *catalog, Image *image, off_t *index, off_t Nimage, CamCorrection *camcorr) {
     3void update_catalog_setphot (Catalog *catalog, Image *image, off_t *index, off_t Nimage, CamPhotomCorrection *camcorr) {
    44
    5   off_t i, j, found;
     5  off_t i, found;
    66
    77  // if we are resetting, reset all flags
     
    99
    1010  found = 0;   
    11   for (i = 0; i < catalog[0].Naverage; i++) {
     11  for (i = 0; i < catalog[0].Nmeasure; i++) {
    1212
    13     off_t m = catalog[0].average[i].measureOffset;
    14     for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
    15       off_t idx = catalog[0].measure[m].imageID;
    16       if (idx <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode)
     13    Measure *measure = &catalog[0].measure[i];
    1714
    18       off_t id = index[idx];
    19       if (id < 0) continue;
     15    // only do GPC1 data for now
     16    if (measure[0].photcode < 10000) continue;
     17    if (measure[0].photcode > 10600) continue;
     18     
     19    off_t idx = measure[0].imageID;
     20    if (idx <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode)
    2021
    21       float Mcal = image[id].Mcal;
    22       float dMcal = image[id].dMcal;
    23       float Mflat = 0.0;
     22    off_t id = index[idx];
     23    if (id < 0) continue;
    2424
    25       // if we know about a flat-field correction, then we need to apply the sub-chip correction
    26       int flat_id = image[id].photom_map_id;
    27       if (flat_id > 0) {
    28         Mflat = get_cam_correction (camcorr, flat_id, catalog[0].measure[m].Xccd, catalog[0].measure[m].Yccd);
    29       }
     25    float Mcal = image[id].Mcal;
     26    float dMcal = image[id].dMcal;
     27    float Mflat = 0.0;
    3028
    31       catalog[0].measure[m].Mcal = Mcal;
    32       catalog[0].measure[m].Mflat = Mflat; // in the previous version, Mcal_offset (which is added to Mflat) had a negative sign here
    33       catalog[0].measure[m].dMcal = dMcal;
    34       myAssert(isfinite(catalog[0].measure[m].Mcal), "oops: ubercal made a nan");
     29    // if we know about a flat-field correction, then we need to apply the sub-chip correction
     30    int flat_id = image[id].photom_map_id;
     31    if (flat_id > 0) {
     32      Mflat = CamPhotomCorrectionValue (camcorr, flat_id, measure[0].Xccd, measure[0].Yccd);
     33    }
    3534
    36       if (RESET) {
    37         catalog[0].measure[m].dbFlags &= ~photomFlags;
    38       }
     35    measure[0].Mcal = Mcal;
     36    measure[0].Mflat = Mflat; // in the previous version, Mcal_offset (which is added to Mflat) had a negative sign here
     37    measure[0].dMcal = dMcal;
     38    myAssert(isfinite(measure[0].Mcal), "oops: ubercal made a nan");
    3939
    40       // if we are setting the zero points from an UBERCAL database, and this detection is from one of those images,
    41       // then tag the measurement as well
    42       if (UBERCAL && (image[id].flags & ID_IMAGE_PHOTOM_UBERCAL)) {
    43         catalog[0].measure[m].dbFlags |=  ID_MEAS_PHOTOM_UBERCAL;
    44       }
     40    if (RESET) {
     41      measure[0].dbFlags &= ~photomFlags;
     42    }
    4543
    46       found ++;
     44    // if we are setting the zero points from an UBERCAL database, and this detection is from one of those images,
     45    // then tag the measurement as well
     46    if (UBERCAL && (image[id].flags & ID_IMAGE_PHOTOM_UBERCAL)) {
     47      measure[0].dbFlags |=  ID_MEAS_PHOTOM_UBERCAL;
    4748    }
     49
     50    found ++;
    4851  }
    4952
    5053  if (found) {
    51     fprintf (stderr, "found "OFF_T_FMT" matches\n", found);
     54    fprintf (stderr, "found "OFF_T_FMT" matches for setphot\n", found);
    5255  }
    5356}
  • trunk/Ohana/src/uniphot/src/update_dvo_setastrom.c

    r38986 r39288  
    1919  if (KH_FILE)  if (!load_kh_correction  (KH_FILE))  { fprintf (stderr, "failed to load KH  correction %s\n", KH_FILE ); exit (1); }
    2020  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); }
    2221  if (TYC_FILE) if (!load_tyc_correction (TYC_FILE)) { fprintf (stderr, "failed to load TYC correction %s\n", TYC_FILE); exit (1); }
     22
     23  if (CAM_ASTROM_FILE) if (!CamAstromCorrectionLoad (CAM_ASTROM_FILE)) { fprintf (stderr, "failed to load CAM correction %s\n", CAM_ASTROM_FILE); exit (1); }
    2324
    2425  // determine the populated SkyRegions overlapping the requested area (default depth)
     
    8384    gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry
    8485
    85     snprintf (history, 128, "setastrom options: KH: %1d, DCR: %1d, CAM: %1d", (KH_FILE != NULL), (DCR_FILE != NULL), (CAM_FILE != NULL));
     86    snprintf (history, 128, "setastrom options: KH: %1d, DCR: %1d, CAM: %1d", (KH_FILE != NULL), (DCR_FILE != NULL), (CAM_ASTROM_FILE != NULL));
    8687    gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry
    8788
     
    121122    if (KH_FILE)          { strextend (&command, "-KH %s", KH_FILE); }
    122123    if (DCR_FILE)         { strextend (&command, "-DCR %s", DCR_FILE); }
    123     if (CAM_FILE)         { strextend (&command, "-CAM %s", CAM_FILE); }
     124    if (CAM_ASTROM_FILE)          { strextend (&command, "-CAM %s", CAM_ASTROM_FILE); }
    124125    if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
    125126    if (KH_RESET)         { strextend (&command, "-KH-reset"); }
  • trunk/Ohana/src/uniphot/src/update_dvo_setphot.c

    r39272 r39288  
    33
    44// XXX convert this to use the ImageSubset to save space
    5 int update_dvo_setphot (Image *image, off_t Nimage, CamCorrection *camcorr) {
     5int update_dvo_setphot (Image *image, off_t Nimage, CamPhotomCorrection *camcorr) {
    66
    77  SkyTable *sky = NULL;
     
    1919  }
    2020
     21  if (KH_FILE)  if (!load_kh_correction  (KH_FILE))  { fprintf (stderr, "failed to load KH  correction %s\n", KH_FILE ); exit (1); }
     22  if (DCR_FILE) if (!load_dcr_correction (DCR_FILE)) { fprintf (stderr, "failed to load DCR correction %s\n", DCR_FILE); exit (1); }
     23
     24  if (CAM_ASTROM_FILE) if (!CamAstromCorrectionLoad (CAM_ASTROM_FILE)) { fprintf (stderr, "failed to load CAM correction %s\n", CAM_ASTROM_FILE); exit (1); }
     25
    2126  // create an index for the image IDs
    2227  maxID = 0;
     
    5459    catalog.filename    = HOST_ID ? localFilename : skylist[0].filename[i];
    5560    catalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE;
     61    if (KH_FILE || DCR_FILE || CAM_ASTROM_FILE) {
     62      catalog.catflags |= DVO_LOAD_SECFILT;
     63    }
    5664    catalog.Nsecfilt    = GetPhotcodeNsecfilt ();
    5765
     
    7482
    7583    update_catalog_setphot (&catalog, image, index, Nimage, camcorr);
     84
     85    if (KH_FILE || DCR_FILE || CAM_ASTROM_FILE) {
     86      update_catalog_setastrom (&catalog);
     87    }
    7688
    7789    if (!UPDATE) {
     
    92104    gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry
    93105
    94     snprintf (history, 128, "setphot options: reset: %1d, ubercal: %1d", RESET, UBERCAL);
     106    snprintf (history, 128, "setphot options: reset: %1d, ubercal: %1d, camflat: %1d", RESET, UBERCAL, (CAM_PHOTOM_FILE != NULL));
    95107    gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry
     108
     109    if (KH_FILE || DCR_FILE || CAM_ASTROM_FILE) {
     110      gfits_modify (&catalog.header, "SETASTR", "%s", 1, moddate); // replaces the single entry
     111
     112      snprintf (history, 128, "setphot (setastrom) options: KH: %1d, DCR: %1d, CAM: %1d", (KH_FILE != NULL), (DCR_FILE != NULL), (CAM_ASTROM_FILE != NULL));
     113      gfits_modify_alt (&catalog.header, "HISTORY", "%S", 0, history); // adds a new entry
     114    }
    96115
    97116    free (moddate);
     
    139158    if (RESET)           { strextend (&command, "-reset"); }
    140159    if (UPDATE)          { strextend (&command, "-update"); }
    141     if (UBERCAL)         { strextend (&command, "-ubercal"); }
    142160    if (REPAIR_BY_OBJID) { strextend (&command, "-repair-by-objid"); }
     161
     162    if (UBERCAL)         { strextend (&command, "-ubercal"); }
     163    // if (CAM_PHOTOM_FILE) { strextend (&command, "-cam-flat %s", CAM_PHOTOM_FILE); }
     164
     165    if (KH_FILE)          { strextend (&command, "-KH %s", KH_FILE); }
     166    if (DCR_FILE)         { strextend (&command, "-DCR %s", DCR_FILE); }
     167    if (CAM_ASTROM_FILE)  { strextend (&command, "-CAM %s", CAM_ASTROM_FILE); }
     168
     169    if (KH_RESET)         { strextend (&command, "-KH-reset"); }
     170    if (DCR_RESET)        { strextend (&command, "-DCR-reset"); }
     171    if (CAM_RESET)        { strextend (&command, "-CAM-reset"); }
    143172
    144173    fprintf (stderr, "command: %s\n", command);
Note: See TracChangeset for help on using the changeset viewer.