IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37464


Ignore:
Timestamp:
Oct 7, 2014, 12:27:42 PM (12 years ago)
Author:
eugene
Message:

fakeastro images by region now compiles (not tested)

Location:
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro
Files:
2 added
9 edited

Legend:

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

    r37463 r37464  
    3939$(SRC)/gaussian.$(ARCH).o \
    4040$(SRC)/fakeastro_images.$(ARCH).o \
     41$(SRC)/fakeastro_images_region.$(ARCH).o \
    4142$(SRC)/load_template_images.$(ARCH).o \
    4243$(SRC)/make_fake_images.$(ARCH).o \
    4344$(SRC)/get_image_patch.$(ARCH).o \
     45$(SRC)/load_fake_stars.$(ARCH).o \
    4446$(SRC)/make_fake_stars.$(ARCH).o \
    4547$(SRC)/make_fake_stars_catalog.$(ARCH).o \
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/include/fakeastro.h

    r37463 r37464  
    114114Image *make_fake_images (Image *image, int *nfakeImage);
    115115
     116Image *fakeastro_images_region (Image *image, int *nimage, int *NIMAGE, Image *refImage, int NrefImage, SkyTable *skyTableInput, SkyTable *skyTableOutput, SkyRegion *region);
     117
    116118SkyRegion *get_image_patch (Image *image);
    117 Stars *make_fake_stars (SkyTable *sky, SkyRegion *patch, Image *image, int *nstars);
     119int SkyRegionsOverlap (SkyRegion *region, SkyRegion *patch);
     120int SkyRegionHasPoint (SkyRegion *region, double R, double D);
     121SkyRegion *SkyRegionExpand (SkyRegion *region, float boundary);
     122
     123Catalog *load_fake_stars (SkyList *skylist, int *ncatalog);
     124
     125Stars *make_fake_stars (Catalog *catalog, int Ncatalog, SkyList *skylist, Image *image, int *nstars);
    118126Stars *make_fake_stars_catalog (Stars *stars, int *nstars, SkyRegion *patch, Catalog *catalog, Image *image);
    119 int save_fake_stars (SkyTable *sky, SkyRegion *patch, Image *image, Stars *stars, int Nstars);
    120 int match_fake_stars (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, Image *image);
     127
     128int save_fake_stars (SkyTable *sky, Image *image, Stars *stars, int Nstars);
     129int match_fake_stars (Stars *stars, unsigned int NstarsIn, SkyRegion *region, Catalog *catalog, Image *image);
    121130
    122131int InitStar (Stars *star);
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_images.c

    r37463 r37464  
    33int fakeastro_images () {
    44
    5   int i, j;
    65
    76  FITS_DB db;
    87
    9   /*** update the image table ***/
     8  // we are creating a new image table (what about db ID?)
    109  snprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", CATDIR_OUTPUT);
    1110
     
    3231  SkyTableSetFilenames (skyTableOutput, CATDIR_OUTPUT, "cpt");
    3332
     33  // subset out the DIS exposures here:
     34
     35  int NrefImage;
     36  Image *refImage = load_template_images (&NrefImage);
     37 
    3438  int Nimage = 0;
    3539  int NIMAGE = 1000;
     
    3842  ALLOCATE (image, Image, NIMAGE);
    3943
    40   int Nrefimage;
    41   Image *refimage = load_template_images (&Nrefimage);
    42  
    43   for (i = 0; i < Nrefimage; i++) {
    44 
    45     // we only want to make fake images for the exposures
    46     if (strcmp(&refimage[i].coords.ctype[4], "-DIS")) continue;
    47 
    48     int NfakeImage;
    49     Image *fakeImage = make_fake_images (&refimage[i], &NfakeImage);
    50    
    51     for (j = 0; j < NfakeImage; j++) {
    52 
    53       // we only want to make fake stars for the fake chips
    54       if (strcmp(&fakeImage[j].coords.ctype[4], "-WRP")) continue;
    55 
    56       SkyRegion *patch = get_image_patch (&fakeImage[j]);
    57 
    58       int NfakeStars;
    59       Stars *fakeStars = make_fake_stars (skyTableInput, patch, &fakeImage[j], &NfakeStars);
    60      
    61       save_fake_stars (skyTableOutput, patch, &fakeImage[j], fakeStars, NfakeStars);
    62 
    63       free (fakeStars);
    64       free (patch);
    65     }
    66 
    67     if (Nimage + NfakeImage >= NIMAGE) {
    68       NIMAGE += 1000;
    69       REALLOCATE (image, Image, NIMAGE);
    70     }
    71 
    72     for (j = 0; j < NfakeImage; j++) {
    73       memcpy (&image[Nimage], &fakeImage[j], sizeof(Image));
    74     }
    75    
    76     free (fakeImage);
    77   }
     44  image = fakeastro_images_region (image, &Nimage, &NIMAGE, refImage, NrefImage, skyTableInput, skyTableOutput, &UserPatch);
    7845
    7946  /* add the new image and save */
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/get_image_patch.c

    r37463 r37464  
    3535  return region;
    3636}
     37
     38int SkyRegionHasPoint (SkyRegion *region, double R, double D) {
     39
     40  if (D >= region->Dmin) return FALSE;
     41  if (D <  region->Dmax) return FALSE;
     42  if (R >= region->Rmin) return FALSE;
     43  if (R <  region->Rmax) return FALSE;
     44  return TRUE;
     45}
     46
     47int SkyRegionsOverlap (SkyRegion *region, SkyRegion *patch) {
     48
     49  if (region->Rmin >= patch->Rmax) return FALSE;
     50  if (region->Rmax <= patch->Rmin) return FALSE;
     51  if (region->Dmin >= patch->Dmax) return FALSE;
     52  if (region->Dmax <= patch->Dmin) return FALSE;
     53  return TRUE;
     54}
     55
     56SkyRegion *SkyRegionExpand (SkyRegion *region, float boundary) {
     57
     58  SkyRegion *output = NULL;
     59  ALLOCATE (output, SkyRegion, 1);
     60
     61  output->Dmin = region->Dmin - boundary;
     62  output->Dmax = region->Dmax + boundary;
     63
     64  float dRmin = boundary / cos (RAD_DEG*region->Dmin);
     65  float dRmax = boundary / cos (RAD_DEG*region->Dmin);
     66
     67  float dR = MAX (dRmin, dRmax);
     68
     69  output->Rmin = region->Rmin - dR;
     70  output->Rmax = region->Rmax + dR;
     71
     72  return output;
     73}
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/load_template_images.c

    r37463 r37464  
    11# include "fakeastro.h"
    22
    3 Image *load_template_images (int *nimage) {
     3Image *load_template_images (int *nrefimage) {
    44
    55  FITS_DB db;
     
    1313  if (db.dbstate == LCK_EMPTY) {
    1414    dvo_image_unlock (&db); // unlock input
    15     *nimage = 0;
    16     return NULL;
     15    fprintf (stderr, "ERROR: no template images in %s\n", IMAGES_INPUT);
     16    exit (3);
    1717  }
    1818
     
    2626  Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
    2727  if (!image) {
    28     fprintf (stderr, "ERROR: failed to read images\n");
    29     return (NULL);
     28    fprintf (stderr, "ERROR: no template images in %s (though db exists)\n", IMAGES_INPUT);
     29    exit (3);
    3030  }
    3131
    32   *nimage = Nimage;
    33   return image;
     32  int NREFIMAGE = 1000;
     33  int Nrefimage = 0;
     34  Image *refimage;
     35  ALLOCATE (refimage, Image, NREFIMAGE);
     36
     37  int i;
     38  for (i = 0; i < Nimage; i++) {
     39
     40    // we only want to make fake images for the exposures
     41    if (strcmp(&image[i].coords.ctype[4], "-DIS")) continue;
     42
     43    refimage[Nrefimage] = image[i];
     44
     45    Nrefimage ++;
     46    CHECK_REALLOCATE (refimage, Image, NREFIMAGE, Nrefimage, 1000);
     47  }
     48
     49  // free the input image database
     50  gfits_db_free (&db);
     51
     52  *nrefimage = Nrefimage;
     53  return refimage;
    3454}
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars.c

    r37463 r37464  
    11# include "fakeastro.h"
    22
    3 Stars *make_fake_stars (SkyTable *sky, SkyRegion *patch, Image *image, int *nstars) {
     3Stars *make_fake_stars (Catalog *catalog, int Ncatalog, SkyList *skylist, Image *image, int *nstars) {
    44
    5   SkyList *skylist  = SkyListByPatch (sky, -1, patch);
     5  // patch is generous region around image, but limited ot this image
     6  SkyRegion *imagePatch = get_image_patch (image);
    67
    78  int Nstars = 0;
    89  Stars *stars = NULL;
    910
    10   Catalog catalog;
    11 
    1211  // load stars from database in these regions
    1312  int i;
    14   for (i = 0; i < skylist->Nregions; i++) {
     13  for (i = 0; i < Ncatalog; i++) {
     14    // skylist matches catalog
    1515
    16     // set the parameters which guide catalog open/load/create
    17     catalog.filename  = skylist[0].filename[i];
    18     catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    19     catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
    20     catalog.catflags  = LOAD_AVES | LOAD_SECF | LOAD_STARPAR;
    21     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    22     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
    23       continue;
    24     }
     16    // XXX check that catalog overlaps patch
     17    if (!SkyRegionsOverlap(skylist[0].regions[i], imagePatch)) continue;
    2518
    2619    // generate fake measurements for this image
    27     stars = make_fake_stars_catalog (stars, &Nstars, patch, &catalog, image);
    28    
    29     dvo_catalog_unlock (&catalog);
    30     dvo_catalog_free (&catalog);
     20    stars = make_fake_stars_catalog (stars, &Nstars, imagePatch, &catalog[i], image);
    3121  }
    3222
    33   SkyListFree (skylist);
     23  free (imagePatch);
    3424
    3525  *nstars = Nstars;
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars_catalog.c

    r37463 r37464  
    1010// * what about QSOs?
    1111
    12 Stars *make_fake_stars_catalog (Stars *stars, int *nstars, SkyRegion *region, Catalog *catalog, Image *image) {
     12/* used in find_matches, find_matches_refstars */
     13# define IN_PATCH(REGION,R,D) (                      \
     14((D) >= REGION[0].Dmin) && ((D) < REGION[0].Dmax) && \
     15((R) >= REGION[0].Rmin) && ((R) < REGION[0].Rmax))
     16
     17// region corresponds to the catalog
     18Stars *make_fake_stars_catalog (Stars *stars, int *nstars, SkyRegion *imagePatch, Catalog *catalog, Image *image) {
    1319
    1420  int Nstars = *nstars;
    15   *nstars += catalog->Naverage;
    1621
    1722  time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00");
    1823
    1924  if (!stars) {
    20     ALLOCATE (stars, Stars, *nstars);
     25    ALLOCATE (stars, Stars, catalog->Naverage);
    2126  } else {
    22     REALLOCATE (stars, Stars, *nstars);
     27    REALLOCATE (stars, Stars, Nstars + catalog->Naverage);
    2328  }
    2429
     
    4954
    5055    // true position from src catalog
    51     if (!IN_REGION(average[i].R, average[i].D)) continue;
     56    if (!IN_PATCH(imagePatch, average[i].R, average[i].D)) continue;
    5257
    5358    int nStar = average[i].starparOffset;
     
    116121    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
    117122    stars[Nstars].measure.detID      = Nstars + 1;
    118    
    119123    Nstars ++;
    120124  }
    121125
     126  *nstars = Nstars;
    122127  return stars;
    123128}
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/match_fake_stars.c

    r37463 r37464  
    11# include "fakeastro.h"
    22
    3 int match_fake_stars (SkyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, Image *image) {
     3int match_fake_stars (Stars *stars, unsigned int NstarsIn, SkyRegion *region, Catalog *catalog, Image *image) {
    44 
    55  off_t i, j, n, N, J, Jmin, status, Nstars;
  • branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/save_fake_stars.c

    r37463 r37464  
    33# define RESETTIME { gettimeofday (&startTimer, (void *) NULL); }
    44
    5 int save_fake_stars (SkyTable *sky, SkyRegion *patch, Image *image, Stars *stars, int Nstars) {
     5int save_fake_stars (SkyTable *sky, Image *image, Stars *stars, int Nstars) {
    66
    77  Catalog catalog;
    88
    9   // will these match, or should I mangle the input cpt names?
    10   SkyList *skylist = SkyListByPatch (sky, -1, patch);
     9  // patch is generous region around image, but limited to this image
     10  SkyRegion *imagePatch = get_image_patch (image);
     11
     12  // list of regions which cover this image
     13  SkyList *skylist = SkyListByPatch (sky, -1, imagePatch);
    1114
    1215  int Naverage = 0;
     
    1518  INITTIME;
    1619
    17   // load stars from database in these regions
    1820  int i;
    1921  for (i = 0; i < skylist->Nregions; i++) {
     
    2628    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    2729
     30    // I want to do an update here
    2831    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
    2932      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
     
    3134    }
    3235
    33     match_fake_stars (skylist[0].regions[i], stars, Nstars, &catalog, image);
     36    match_fake_stars (stars, Nstars, skylist[0].regions[i], &catalog, image);
    3437
    3538    /* report total updated values */
     
    3841
    3942    SetProtect (TRUE);
    40     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF | LOAD_LENSING;
     43    catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    4144    dvo_catalog_update (&catalog, VERBOSE);
    4245    SetProtect (FALSE);
     
    4750  }
    4851
     52  free (imagePatch);
    4953  SkyListFree (skylist);
    5054  return TRUE;
    5155}
     56
     57// XXX what about starpar values?
Note: See TracChangeset for help on using the changeset viewer.