IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31493


Ignore:
Timestamp:
May 6, 2011, 6:59:45 PM (15 years ago)
Author:
eugene
Message:

various fixes to relphot to support the dumped output Image.dat file (not yet support to apply the results)

Location:
branches/eam_branches/ipp-20110505/Ohana/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110505/Ohana/src/libfits/Makefile

    r23724 r31493  
    5454$(TABL)/F_set_column.$(ARCH).o                  $(TABL)/F_get_column.$(ARCH).o   \
    5555$(TABL)/F_table_row.$(ARCH).o                   $(TABL)/F_free_T.$(ARCH).o       \
    56 $(TABL)/F_table_varlength.$(ARCH).o
     56$(TABL)/F_table_varlength.$(ARCH).o             $(TABL)/F_copy_T.$(ARCH).o
    5757
    5858EXTERN_OBJ = \
  • branches/eam_branches/ipp-20110505/Ohana/src/libfits/include/gfitsio.h

    r29938 r31493  
    6363  Header                 *header;
    6464  char                   *buffer;
    65   off_t                   datasize;
    66   off_t                   validsize;
     65  off_t                   datasize; // size of the buffer (including block padding at the end)
     66  off_t                   validsize;  // size of the valid portion of the table (< validsize if file is short)
    6767} FTable;
    6868
     
    199199int     gfits_vtable_from_ftable       PROTO((FTable *ftable, VTable *vtable, off_t *row, off_t Nrow));
    200200int     gfits_write_table              PROTO((char *filename, FTable *ftable));
     201int     gfits_copy_ftable              PROTO((FTable *in, FTable *out));
     202int     gfits_copy_vtable              PROTO((VTable *in, VTable *out));
    201203
    202204int     gfits_create_Theader           PROTO((Header *header, char *type));
  • branches/eam_branches/ipp-20110505/Ohana/src/libfits/matrix/F_copy_M.c

    r27435 r31493  
    33
    44/*********************** fits copy header ***********************************/
    5 int gfits_copy_matrix (Matrix *matrix1, Matrix *matrix2) {
     5int gfits_copy_matrix (Matrix *in, Matrix *out) {
    66
    77  int i;
    88
    9   matrix2[0].unsign   = matrix1[0].unsign;
    10   matrix2[0].bitpix   = matrix1[0].bitpix;
    11   matrix2[0].datasize = matrix1[0].datasize;
    12   matrix2[0].bzero    = matrix1[0].bzero;
    13   matrix2[0].bscale   = matrix1[0].bscale;
    14   matrix2[0].Naxes    = matrix1[0].Naxes;
     9  out[0].unsign   = in[0].unsign;
     10  out[0].bitpix   = in[0].bitpix;
     11  out[0].datasize = in[0].datasize;
     12  out[0].bzero    = in[0].bzero;
     13  out[0].bscale   = in[0].bscale;
     14  out[0].Naxes    = in[0].Naxes;
    1515  for (i = 0; i < FT_MAX_NAXES; i++)
    16     matrix2[0].Naxis[i] = matrix1[0].Naxis[i];
     16    out[0].Naxis[i] = in[0].Naxis[i];
    1717
    18   if (matrix2[0].buffer != NULL) free (matrix2[0].buffer);
    19   ALLOCATE (matrix2[0].buffer, char, matrix2[0].datasize);
     18  if (out[0].buffer != NULL) free (out[0].buffer);
     19  ALLOCATE (out[0].buffer, char, out[0].datasize);
    2020 
    21   memcpy (matrix2[0].buffer, matrix1[0].buffer, matrix2[0].datasize);
     21  memcpy (out[0].buffer, in[0].buffer, out[0].datasize);
    2222
    2323  return (TRUE);
  • branches/eam_branches/ipp-20110505/Ohana/src/libfits/table/F_copy_T.c

    r31468 r31493  
    22# include <gfitsio.h>
    33
    4 /*********************** fits copy header ***********************************/
    5 int gfits_copy_ftable_data (FTable *table1, FTable *table2) {
    6 
    7   off_t Nbytes, Nread;
    8   char string[128];
     4/*********************** copy ftable (does not copy the header pointer) ***********************************/
     5int gfits_copy_ftable (FTable *in, FTable *out) {
    96
    107  /* find buffer size */
    11   Nbytes = gfits_data_size (table[0].header);
    12   ALLOCATE (table[0].buffer, char, Nbytes);
     8  out[0].validsize = in[0].validsize;
     9  out[0].datasize  = in[0].datasize;
    1310
    14   Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
    15   if (Nread != Nbytes) {
    16     snprintf (string, 128, "FITS file is short (%s)", __func__);
    17     perror (string);
    18     if (Nread < gfits_data_min_size (table[0].header)) {
    19       fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  gfits_data_min_size (table[0].header));
    20       if (padIfShort) {
    21         memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
    22         fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
    23         table[0].validsize = Nread;
    24         table[0].datasize = Nbytes;
    25         return (TRUE);
    26       } else {
    27         gfits_free_table  (table);
    28         return (FALSE);
    29       }
    30     }
    31     fprintf (stderr, "warning: file missing pad\n");
    32   }
    33   table[0].validsize = Nread;
    34   table[0].datasize = Nbytes;
     11  ALLOCATE (out[0].buffer, char, out[0].datasize);
     12  memcpy (out[0].buffer, in[0].buffer, out[0].datasize);
    3513  return (TRUE);
    3614}       
    3715
     16/*********************** copy ftable (does not copy the header pointer) ***********************************/
     17int gfits_copy_vtable (VTable *in, VTable *out) {
     18
     19  off_t i, Nx, Ny, Nrows;
     20
     21  /* find buffer size */
     22  Nx = in[0].header[0].Naxis[0];
     23  Ny = in[0].header[0].Naxis[1];
     24
     25  // validate these two?
     26  // table[0].datasize = gfits_data_size (table[0].header);
     27  // table[0].pad = table[0].datasize - Nx*Ny;
     28
     29  /* find buffer size */
     30  out[0].datasize = in[0].datasize;
     31  out[0].pad      = in[0].pad;
     32  out[0].Nrow     = in[0].Nrow;
     33
     34  Nrows = out[0].Nrow;
     35
     36  ALLOCATE (out[0].row, off_t, MAX (Nrows, 1));
     37  ALLOCATE (out[0].buffer, char *, MAX (Nrows, 1));
     38  for (i = 0; i < Nrows; i++) {
     39    out[0].row[i] = in[0].row[i];
     40    ALLOCATE (out[0].buffer[i], char, MAX (Nx, 1));
     41    memcpy (out[0].buffer[i], in[0].buffer[i], Nx);
     42  }
     43  return (TRUE);
     44}       
     45
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/include/relphot.h

    r31450 r31493  
    6363int    RESET;
    6464int    UPDATE;
     65int    SAVE_IMAGE_UPDATES;
    6566int    PLOTSTUFF;
    6667int    SAVEPLOT;
     
    160161float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat));
    161162Image        *getimage            PROTO((off_t N));
    162 Image        *getimages           PROTO((off_t *N));
     163Image        *getimages           PROTO((off_t *N, off_t **LineNumber));
    163164void          global_stats        PROTO((Catalog *catalog, int Ncatalog));
    164165void          initGrid            PROTO((int dX, int dY));
    165166void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
    166167void          initImageBins       PROTO((Catalog *catalog, int Ncatalog));
    167 void          initImages          PROTO((Image *input, off_t N));
     168void          initImages          PROTO((Image *input, off_t *LineNumber, off_t N));
    168169void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
    169170void          initMosaicGrid      PROTO((Image *image, off_t Nimage));
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/src/ImageOps.c

    r31450 r31493  
    99static Image        *image;   // list of available images 
    1010static off_t        Nimage;   // number of available images
     11static off_t       *LineNumber; // match of subset to full image table
    1112
    1213// to search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted index
     
    1415static off_t        *imageIdx; // list of index for image IDs
    1516
    16 Image *getimages (off_t *N) {
     17Image *getimages (off_t *N, off_t **line_number) {
    1718
    1819  *N = Nimage;
     20  if (line_number) *line_number = LineNumber;
    1921  return (image);
    2022}
     
    2426}
    2527
    26 void initImages (Image *input, off_t N) {
     28void initImages (Image *input, off_t *line_number, off_t N) {
    2729
    2830  off_t i;
    2931
    3032  image = input;
     33  LineNumber = line_number;
    3134  Nimage = N;
    3235
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/src/MosaicOps.c

    r31450 r31493  
    195195  if (!MOSAIC_ZEROPT) return;
    196196
    197   image = getimages (&Nimage);
     197  image = getimages (&Nimage, NULL);
    198198
    199199  for (i = 0; i < Nmosaic; i++) {
     
    361361  if (FREEZE_MOSAICS) return (FALSE);
    362362
    363   image = getimages (&N);
     363  image = getimages (&N, NULL);
    364364
    365365  Nsecfilt = GetPhotcodeNsecfilt ();
     
    482482  if (FREEZE_MOSAICS) return (FALSE);
    483483
    484   image = getimages (&Nimage);
     484  image = getimages (&Nimage, NULL);
    485485
    486486  ALLOCATE (imageOffset, double, Nmosaic);
     
    853853  if (!MOSAIC_ZEROPT) return;
    854854
    855   image = getimages (&Nimage);
     855  image = getimages (&Nimage, NULL);
    856856
    857857  N = 0;
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/src/args.c

    r31450 r31493  
    128128  }
    129129
     130  SAVE_IMAGE_UPDATES = TRUE;
     131  if ((N = get_argument (argc, argv, "-skip-image-updates"))) {
     132    remove_argument (N, &argc, argv);
     133    SAVE_IMAGE_UPDATES = FALSE;
     134  }
     135
    130136  MaxDensityUse = FALSE;
    131137  if ((N = get_argument (argc, argv, "-max-density"))) {
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/src/load_catalogs.c

    r30616 r31493  
    1414  // load data from each region file, only use bright stars
    1515  for (i = 0; i < skylist[0].Nregions; i++) {
     16    dvo_catalog_init (&catalog[i], TRUE);
    1617
    1718    // set up the basic catalog info
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/src/load_images.c

    r31450 r31493  
    3535
    3636  // convert database table to internal structure (binary to Image)
     37  // 'image' points to the same memory as db->ftable->buffer
    3738  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
    3839  if (!image) {
     
    4344
    4445  // select the images which overlap the selected sky regions
     46  // 'subset' points to a new copy of the data (different from 'image')
    4547  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
    4648  MARKTIME("selected %d overlapping images: %f sec\n", (int) Nsubset, dtime);
     
    4951  // XXX does this simply duplicate the memory needlessly?  we recreate these lines
    5052  // in reload_images.  If we had saved the line numbers, we could avoid this
    51   gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
    52   MARKTIME("converted ftable to vtable: %f sec\n", dtime);
     53  // vtable points *another* copy of the subset rows
     54  // (the later call to 'reload_images' copies the subset elements back on top of
     55  // the rows of the vtable)
     56  // gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nsubset);
     57  // MARKTIME("converted ftable to vtable: %f sec\n", dtime);
    5358
    5459  // save the subset of images in the static reference in ImageOps, set up indexes
    55   initImages (subset, Nsubset);
     60  initImages (subset, LineNumber, Nsubset);
    5661  MARKTIME("init images: %f sec\n", dtime);
    5762
     
    6671
    6772  Image     *image;
    68   off_t     Nimage, Nx, i;
     73  off_t     Nimage, Nx, i, *LineNumber;
    6974  VTable    *vtable;
    7075
    71   image = getimages (&Nimage);
     76  image = getimages (&Nimage, &LineNumber);
    7277
     78  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, LineNumber, Nimage);
    7379  vtable = &db[0].vtable;
    7480
  • branches/eam_branches/ipp-20110505/Ohana/src/relphot/src/relphot.c

    r31468 r31493  
    147147  }
    148148 
    149   if (SOMETHING) {
    150     FITS_DB dbX;
    151     dbX.lockstate = LCK_XCLD;
    152     dbX.timeout   = 60.0;
    153     gfits_db_init (&dbX);
    154     char filename[1024];
    155     snprintf (filename, 1024, "%s.bck", ImageCat);
    156     if (!gfits_db_lock (dbX, filename)) {
    157       fprintf (stderr, "can't lock backup image image catalog\n");
    158       return (FALSE);
    159     }
    160    
    161     // copy header
    162     gfits_copy_header (dbX.header, db.header);
    163     gfits_copy_header (dbX.theader, db.theader);
    164     gfits_copy_matrix (dbX.matrix, db.matrix);
    165     gfits_copy_table (dbX.matrix, db.matrix);
    166 
    167     // copy Images.dat to another structure
    168     dvo_image_update (&db, VERBOSE);
    169     dvo_image_unlock (&db);
    170   }
    171 
    172149  if (USE_GRID) dump_grid ();
    173   if (!UPDATE) exit (0);
    174150
    175151  /* set Mcal & Mmos for bad images */
     
    178154  MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
    179155
     156  setMcalFinal (); // copy per-mosaic calibrations to the images
     157
     158  if (SAVE_IMAGE_UPDATES) {
     159
     160    FITS_DB dbX;
     161    off_t *LineNumber;
     162    Image *image, *subset;
     163    off_t Nimage, Nsubset, i, Nx;
     164    char filename[1024];
     165
     166    gfits_db_init (&dbX);
     167    dbX.lockstate = LCK_XCLD;
     168    dbX.timeout   = 60.0;
     169    dbX.mode      = db.mode;
     170    dbX.format    = db.format;
     171
     172    snprintf (filename, 1024, "%s.bck", ImageCat);
     173    if (!gfits_db_lock (&dbX, filename)) {
     174      fprintf (stderr, "can't lock backup image image catalog\n");
     175      return (FALSE);
     176    }
     177   
     178    // apply the changes from the image subset to the full table:
     179
     180    // convert database table to internal structure (binary to Image)
     181    // 'image' points to the same memory as db->ftable->buffer
     182    image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     183    if (!image) {
     184        fprintf (stderr, "ERROR: failed to read images\n");
     185        exit (2);
     186    }
     187    gfits_scan (db.ftable.header, "NAXIS1", OFF_T_FMT, 1,  &Nx);
     188
     189    subset = getimages (&Nsubset, &LineNumber);
     190    for (i = 0; i < Nsubset; i++) {
     191      if (LineNumber[i] == -1) continue;
     192      memcpy (&image[LineNumber[i]], &subset[i], Nx);
     193    }
     194
     195    // copy Images.dat data (all or only the subset / vtable elements?)  I think I need to dump
     196    // the entire Image table, but with the updates in place I think this says: re-work the
     197    // ftable/vtable usage in this program to be more sensible...
     198    gfits_copy_header (&db.header,  &dbX.header);
     199    gfits_copy_matrix (&db.matrix,  &dbX.matrix);
     200    gfits_copy_header (&db.theader, &dbX.theader);
     201    gfits_copy_ftable (&db.ftable,  &dbX.ftable);
     202
     203    dbX.ftable.header = &dbX.theader;
     204    dbX.virtual = FALSE;
     205
     206    // copy Images.dat to another structure
     207    dvo_image_save (&dbX, VERBOSE);
     208    dvo_image_unlock (&dbX);
     209  }
     210
     211  // only change the real database if -update is requested
     212  if (!UPDATE) exit (0);
     213 
     214  reload_images (&db);
     215
    180216  /* at this point, we have correct cal coeffs in the image/mosaic structures */
    181217  for (i = 0; i < Ncatalog; i++) {
     
    191227  MARKTIME("-- updated all catalogs: %f sec\n", dtime);
    192228
    193   setMcalFinal ();
    194   reload_images (&db);
    195  
    196229  dvo_image_update (&db, VERBOSE);
    197230  dvo_image_unlock (&db);
Note: See TracChangeset for help on using the changeset viewer.