IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37477


Ignore:
Timestamp:
Oct 9, 2014, 3:44:07 PM (12 years ago)
Author:
eugene
Message:

adding code to fit the images to the reference positions

Location:
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/Makefile

    r37471 r37477  
    4242$(SRC)/load_template_images.$(ARCH).o \
    4343$(SRC)/make_fake_images.$(ARCH).o \
     44$(SRC)/fit_fake_stars.$(ARCH).o \
     45$(SRC)/fitpoly.$(ARCH).o \
     46$(SRC)/AstromOffsetMapOps.$(ARCH).o \
    4447$(SRC)/airmass.$(ARCH).o \
    4548$(SRC)/get_image_patch.$(ARCH).o \
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/include/fakeastro.h

    r37471 r37477  
    99
    1010typedef struct {
     11  int   NfakeImage;
     12  int   NFAKEIMAGE;
     13  Image *fakeImage;
     14
     15  int   NtrueImage;
     16  int   NTRUEIMAGE;
     17  Image *trueImage;
     18} ImageInfo;
     19
     20typedef struct {
    1121  double R, D;
    1222  StarPar starpar;
     
    1626
    1727typedef struct {
     28  double Rref; // "reference" coordinate of the fake stars
     29  double Dref;
    1830  Average  average;
    1931  Measure  measure;
     
    2133  int found;
    2234} Stars;
     35
     36// structure to hold coordinate fitting terms
     37typedef struct {
     38    int Npts;
     39    int Nterms;
     40    int Norder;
     41    int Nsums;
     42    int Nelems;
     43    double **sum;
     44    double **xsum;
     45    double **ysum;
     46    double **xfit;
     47    double **yfit;
     48} CoordFit;
    2349
    2450/* used in find_matches, find_matches_refstars */
     
    3359# define DVO_MAX_PATH 1024
    3460
    35 char   ImageCat[DVO_MAX_PATH];
    3661char   GSCFILE[DVO_MAX_PATH];
    3762char   CATDIR[DVO_MAX_PATH];
     
    116141Image *make_fake_images (Image *image, int *nfakeImage);
    117142
    118 Image *fakeastro_images_region (Image *image, int *nimage, int *NIMAGE, Image *refImage, int NrefImage, SkyTable *skyTableInput, SkyTable *skyTableOutput, SkyRegion *region);
     143int fakeastro_images_region (ImageInfo *imageInfo, Image *refImage, int NrefImage, SkyTable *skyTableInput, SkyTable *skyTableOutput, SkyRegion *innerRegion);
    119144
    120145SkyRegion *get_image_patch (Image *image);
     
    135160float airmass (float secz_image, double ra, double dec, double st, double latitude);
    136161float azimuth (double ha, double dec, double latitude);
     162
     163int fit_fake_stars (Stars *stars, int Nstars, Image *image);
     164
     165double **array_init (int Nx, int Ny);
     166void array_free (double **array, int Nx);
     167CoordFit *fit_init (int order);
     168void fit_free (CoordFit *fit);
     169void fit_add (CoordFit *fit, double x1, double y1, double x2, double y2, double wt);
     170int fit_eval (CoordFit *fit);
     171void fit_apply (CoordFit *fit, double *x2, double *y2, double x1, double y1);
     172double **poly2d_dx (double **poly, int Nx, int Ny);
     173double **poly2d_dy (double **poly, int Nx, int Ny);
     174double **poly2d_copy (double **poly, int Nx, int Ny);
     175double poly2d_eval (double **poly, int Nx, int Ny, double x, double y);
     176int fit_apply_coords (CoordFit *fit, Coords *coords, int keepRef);
     177
     178int save_astrom_table ();
     179AstromOffsetTable *get_astrom_table ();
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/ConfigInit.c

    r37463 r37477  
    2525    strcpy (CATDIR, tmpcatdir);
    2626    free (tmpcatdir);
    27    
    28     sprintf (ImageCat, "%s/Images.dat", CATDIR);
    2927  }
    3028
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_images.c

    r37471 r37477  
    11# include "fakeastro.h"
     2int open_image_db (FITS_DB *db, char *ImageName);
     3int save_image_db (FITS_DB *db, Image *image, int Nimage);
    24
    35int fakeastro_images () {
    46
     7  FITS_DB dbfake, dbtrue;
    58
    6   FITS_DB db;
    7 
    8   // we are creating a new image table (what about db ID?)
    9   snprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", CATDIR_OUTPUT);
    10 
    11   /* setup image table format and lock */
    12   db.mode    = dvo_catalog_catmode (CATMODE);
    13   db.format  = dvo_catalog_catformat (CATFORMAT);
    14   int status = dvo_image_lock (&db, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
    15   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
    16 
    17   /* load or create the image table */
    18   if (db.dbstate == LCK_EMPTY) {
    19     if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
    20     dvo_image_create (&db, GetZeroPoint());
    21   } else {
    22     if (!dvo_image_load (&db, VERBOSE, FALSE)) {
    23       Shutdown ("can't read image catalog %s", db.filename);
    24     }
    25   }
     9  open_image_db (&dbfake, "Images.dat");
     10  open_image_db (&dbtrue, "Images.true.dat");
    2611
    2712  SkyTable *skyTableInput = SkyTableLoadOptimal (CATDIR_INPUT, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
     
    3116  SkyTableSetFilenames (skyTableOutput, CATDIR_OUTPUT, "cpt");
    3217
    33   // subset out the DIS exposures here:
    34 
    3518  IMAGE_ID = 1;
    3619
    3720  int NrefImage;
    38   Image *refImage = load_template_images (&NrefImage);
     21  Image *refImage = load_template_images (&NrefImage); // subset of the DIS exposures
    3922 
    40   int Nimage = 0;
    41   int NIMAGE = 1000;
    42   Image *image = NULL;
    43  
    44   ALLOCATE (image, Image, NIMAGE);
     23  ImageInfo imageInfo;
    4524
    46   image = fakeastro_images_region (image, &Nimage, &NIMAGE, refImage, NrefImage, skyTableInput, skyTableOutput, &UserPatch);
     25  imageInfo.NfakeImage = 0;
     26  imageInfo.NFAKEIMAGE = 1000;
     27  imageInfo.fakeImage = NULL;
     28  ALLOCATE (imageInfo.fakeImage, Image, imageInfo.NFAKEIMAGE);
    4729
    48   /* add the new image and save */
    49   dvo_image_addrows (&db, image, Nimage);
    50   SetProtect (TRUE);
    51   dvo_image_update (&db, VERBOSE);
    52   SetProtect (FALSE);
    53   dvo_image_unlock (&db); /* unlock? */
     30  imageInfo.NtrueImage = 0;
     31  imageInfo.NTRUEIMAGE = 1000;
     32  imageInfo.trueImage = NULL;
     33  ALLOCATE (imageInfo.trueImage, Image, imageInfo.NTRUEIMAGE);
     34
     35  fakeastro_images_region (&imageInfo, refImage, NrefImage, skyTableInput, skyTableOutput, &UserPatch);
     36
     37  save_image_db (&dbfake, imageInfo.fakeImage, imageInfo.NfakeImage);
     38  save_image_db (&dbtrue, imageInfo.trueImage, imageInfo.NtrueImage);
    5439
    5540  exit (0);
     
    6954
    7055// -input catdir -output catdir -images images.fits 
     56
     57int open_image_db (FITS_DB *db, char *ImageName) {
     58
     59  char ImageCat[DVO_MAX_PATH];
     60
     61  // we are creating a new image table (what about db ID?)
     62  snprintf (ImageCat, DVO_MAX_PATH, "%s/%s", CATDIR_OUTPUT, ImageName);
     63
     64  /* setup image table format and lock */
     65  db->mode    = dvo_catalog_catmode (CATMODE);
     66  db->format  = dvo_catalog_catformat (CATFORMAT);
     67  int status = dvo_image_lock (db, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
     68  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db->filename);
     69
     70  /* load or create the image table */
     71  if (db->dbstate != LCK_EMPTY) {
     72    Shutdown ("image table %s exists, exiting", db->filename);
     73  }
     74  dvo_image_create (db, GetZeroPoint());
     75
     76  return TRUE;
     77}
     78
     79int save_image_db (FITS_DB *db, Image *image, int Nimage) {
     80
     81  /* add the new image and save */
     82  dvo_image_addrows (db, image, Nimage);
     83  SetProtect (TRUE);
     84  dvo_image_update (db, VERBOSE);
     85  SetProtect (FALSE);
     86  dvo_image_unlock (db); /* unlock? */
     87
     88  return TRUE;
     89}
     90
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_images_region.c

    r37464 r37477  
    11# include "fakeastro.h"
    22
    3 Image *fakeastro_images_region (Image *image, int *nimage, int *NIMAGE, Image *refImage, int NrefImage, SkyTable *skyTableInput, SkyTable *skyTableOutput, SkyRegion *innerRegion) {
    4 
    5   int Nimage = *nimage;
     3int fakeastro_images_region (ImageInfo *imageInfo, Image *refImage, int NrefImage, SkyTable *skyTableInput, SkyTable *skyTableOutput, SkyRegion *innerRegion) {
    64
    75  // extend the outer region by 2.0 degrees
     
    1412  Catalog *catalog = load_fake_stars (skyListInput, &Ncatalog);
    1513
    16   int i;
     14  int i, j;
    1715  for (i = 0; i < NrefImage; i++) {
    1816
     
    3230    Image *fakeImage = make_fake_images (&refImage[i], &NfakeImage);
    3331   
    34     int j;
     32    // save the new fake images with their true image parameters (not yet fitted to the data)
     33    if (imageInfo->NtrueImage + NfakeImage >= imageInfo->NTRUEIMAGE) {
     34      imageInfo->NTRUEIMAGE += 1000 + NfakeImage;
     35      REALLOCATE (imageInfo->trueImage, Image, imageInfo->NTRUEIMAGE);
     36    }
     37    for (j = 0; j < NfakeImage; j++) {
     38      memcpy (&imageInfo->trueImage[imageInfo->NtrueImage], &fakeImage[j], sizeof(Image));
     39      imageInfo->NtrueImage ++;
     40    }
     41
    3542    for (j = 0; j < NfakeImage; j++) {
    3643
    37       // we only want to make fake stars for the fake chips
     44      // we only want to make fake stars for the fake chips (not the PHU entries)
    3845      if (strcmp(&fakeImage[j].coords.ctype[4], "-WRP")) continue;
    3946
     
    4148      Stars *fakeStars = make_fake_stars (catalog, Ncatalog, skyListInput, &fakeImage[j], &NfakeStars);
    4249     
     50      fit_fake_stars (fakeStars, NfakeStars, &fakeImage[j]);
     51
    4352      save_fake_stars (skyTableOutput, &fakeImage[j], fakeStars, NfakeStars);
    4453
     
    4655    }
    4756
    48     if (Nimage + NfakeImage >= *NIMAGE) {
    49       *NIMAGE += 1000 + NfakeImage;
    50       REALLOCATE (image, Image, *NIMAGE);
     57    // append the new fake images to the end of the full set:
     58    if (imageInfo->NfakeImage + NfakeImage >= imageInfo->NFAKEIMAGE) {
     59      imageInfo->NFAKEIMAGE += 1000 + NfakeImage;
     60      REALLOCATE (imageInfo->fakeImage, Image, imageInfo->NFAKEIMAGE);
    5161    }
    52 
    5362    for (j = 0; j < NfakeImage; j++) {
    54       memcpy (&image[Nimage], &fakeImage[j], sizeof(Image));
    55       Nimage ++;
     63      memcpy (&imageInfo->fakeImage[imageInfo->NfakeImage], &fakeImage[j], sizeof(Image));
     64      imageInfo->NfakeImage ++;
    5665    }
    5766   
     
    6170  SkyListFree (skyListInput);
    6271
    63 
    6472  for (i = 0; i < Ncatalog; i++) {
    6573    dvo_catalog_free (&catalog[i]);
    6674  }
    6775
    68   *nimage = Nimage;
    69   return (image);
     76  return TRUE;
    7077}
    7178
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars_catalog.c

    r37471 r37477  
    3737  float Mtime = 2.5*log10(image->exptime);
    3838 
    39   // XXX fix this!!
     39  // XXX hard-wired plateScale for now?
    4040  double plateScale = 0.257;
    4141
     
    7070    double Rtru = average[i].R;
    7171    double Dtru = average[i].D;
     72
     73    // XXX what is the epoch for the src catalog? J2000?
     74    stars[Nstars].Rref = Rtru; // add in any deviations we want here
     75    stars[Nstars].Dref = Dtru;
    7276
    7377    // observed position is scattered from true position by:
Note: See TracChangeset for help on using the changeset viewer.