Changeset 37464
- Timestamp:
- Oct 7, 2014, 12:27:42 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140904/Ohana/src/fakeastro
- Files:
-
- 2 added
- 9 edited
-
Makefile (modified) (1 diff)
-
include/fakeastro.h (modified) (1 diff)
-
src/fakeastro_images.c (modified) (3 diffs)
-
src/fakeastro_images_region.c (added)
-
src/get_image_patch.c (modified) (1 diff)
-
src/load_fake_stars.c (added)
-
src/load_template_images.c (modified) (3 diffs)
-
src/make_fake_stars.c (modified) (1 diff)
-
src/make_fake_stars_catalog.c (modified) (3 diffs)
-
src/match_fake_stars.c (modified) (1 diff)
-
src/save_fake_stars.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/Makefile
r37463 r37464 39 39 $(SRC)/gaussian.$(ARCH).o \ 40 40 $(SRC)/fakeastro_images.$(ARCH).o \ 41 $(SRC)/fakeastro_images_region.$(ARCH).o \ 41 42 $(SRC)/load_template_images.$(ARCH).o \ 42 43 $(SRC)/make_fake_images.$(ARCH).o \ 43 44 $(SRC)/get_image_patch.$(ARCH).o \ 45 $(SRC)/load_fake_stars.$(ARCH).o \ 44 46 $(SRC)/make_fake_stars.$(ARCH).o \ 45 47 $(SRC)/make_fake_stars_catalog.$(ARCH).o \ -
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/include/fakeastro.h
r37463 r37464 114 114 Image *make_fake_images (Image *image, int *nfakeImage); 115 115 116 Image *fakeastro_images_region (Image *image, int *nimage, int *NIMAGE, Image *refImage, int NrefImage, SkyTable *skyTableInput, SkyTable *skyTableOutput, SkyRegion *region); 117 116 118 SkyRegion *get_image_patch (Image *image); 117 Stars *make_fake_stars (SkyTable *sky, SkyRegion *patch, Image *image, int *nstars); 119 int SkyRegionsOverlap (SkyRegion *region, SkyRegion *patch); 120 int SkyRegionHasPoint (SkyRegion *region, double R, double D); 121 SkyRegion *SkyRegionExpand (SkyRegion *region, float boundary); 122 123 Catalog *load_fake_stars (SkyList *skylist, int *ncatalog); 124 125 Stars *make_fake_stars (Catalog *catalog, int Ncatalog, SkyList *skylist, Image *image, int *nstars); 118 126 Stars *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 128 int save_fake_stars (SkyTable *sky, Image *image, Stars *stars, int Nstars); 129 int match_fake_stars (Stars *stars, unsigned int NstarsIn, SkyRegion *region, Catalog *catalog, Image *image); 121 130 122 131 int InitStar (Stars *star); -
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/fakeastro_images.c
r37463 r37464 3 3 int fakeastro_images () { 4 4 5 int i, j;6 5 7 6 FITS_DB db; 8 7 9 / *** update the image table ***/8 // we are creating a new image table (what about db ID?) 10 9 snprintf (ImageCat, DVO_MAX_PATH, "%s/Images.dat", CATDIR_OUTPUT); 11 10 … … 32 31 SkyTableSetFilenames (skyTableOutput, CATDIR_OUTPUT, "cpt"); 33 32 33 // subset out the DIS exposures here: 34 35 int NrefImage; 36 Image *refImage = load_template_images (&NrefImage); 37 34 38 int Nimage = 0; 35 39 int NIMAGE = 1000; … … 38 42 ALLOCATE (image, Image, NIMAGE); 39 43 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); 78 45 79 46 /* add the new image and save */ -
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/get_image_patch.c
r37463 r37464 35 35 return region; 36 36 } 37 38 int 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 47 int 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 56 SkyRegion *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 1 1 # include "fakeastro.h" 2 2 3 Image *load_template_images (int *n image) {3 Image *load_template_images (int *nrefimage) { 4 4 5 5 FITS_DB db; … … 13 13 if (db.dbstate == LCK_EMPTY) { 14 14 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); 17 17 } 18 18 … … 26 26 Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped); 27 27 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); 30 30 } 31 31 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; 34 54 } -
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars.c
r37463 r37464 1 1 # include "fakeastro.h" 2 2 3 Stars *make_fake_stars ( SkyTable *sky, SkyRegion *patch, Image *image, int *nstars) {3 Stars *make_fake_stars (Catalog *catalog, int Ncatalog, SkyList *skylist, Image *image, int *nstars) { 4 4 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); 6 7 7 8 int Nstars = 0; 8 9 Stars *stars = NULL; 9 10 10 Catalog catalog;11 12 11 // load stars from database in these regions 13 12 int i; 14 for (i = 0; i < skylist->Nregions; i++) { 13 for (i = 0; i < Ncatalog; i++) { 14 // skylist matches catalog 15 15 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; 25 18 26 19 // 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); 31 21 } 32 22 33 SkyListFree (skylist);23 free (imagePatch); 34 24 35 25 *nstars = Nstars; -
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/make_fake_stars_catalog.c
r37463 r37464 10 10 // * what about QSOs? 11 11 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 18 Stars *make_fake_stars_catalog (Stars *stars, int *nstars, SkyRegion *imagePatch, Catalog *catalog, Image *image) { 13 19 14 20 int Nstars = *nstars; 15 *nstars += catalog->Naverage;16 21 17 22 time_t timeRef = ohana_date_to_sec("2011/05/11,00:00:00"); 18 23 19 24 if (!stars) { 20 ALLOCATE (stars, Stars, *nstars);25 ALLOCATE (stars, Stars, catalog->Naverage); 21 26 } else { 22 REALLOCATE (stars, Stars, *nstars);27 REALLOCATE (stars, Stars, Nstars + catalog->Naverage); 23 28 } 24 29 … … 49 54 50 55 // 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; 52 57 53 58 int nStar = average[i].starparOffset; … … 116 121 // this is may optionally be replaced by the internal sequence (see FilterStars.c) 117 122 stars[Nstars].measure.detID = Nstars + 1; 118 119 123 Nstars ++; 120 124 } 121 125 126 *nstars = Nstars; 122 127 return stars; 123 128 } -
branches/eam_branches/ipp-20140904/Ohana/src/fakeastro/src/match_fake_stars.c
r37463 r37464 1 1 # include "fakeastro.h" 2 2 3 int match_fake_stars (S kyRegion *region, Stars *stars, unsigned int NstarsIn, Catalog *catalog, Image *image) {3 int match_fake_stars (Stars *stars, unsigned int NstarsIn, SkyRegion *region, Catalog *catalog, Image *image) { 4 4 5 5 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 3 3 # define RESETTIME { gettimeofday (&startTimer, (void *) NULL); } 4 4 5 int save_fake_stars (SkyTable *sky, SkyRegion *patch,Image *image, Stars *stars, int Nstars) {5 int save_fake_stars (SkyTable *sky, Image *image, Stars *stars, int Nstars) { 6 6 7 7 Catalog catalog; 8 8 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); 11 14 12 15 int Naverage = 0; … … 15 18 INITTIME; 16 19 17 // load stars from database in these regions18 20 int i; 19 21 for (i = 0; i < skylist->Nregions; i++) { … … 26 28 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 27 29 30 // I want to do an update here 28 31 if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) { 29 32 fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename); … … 31 34 } 32 35 33 match_fake_stars (s kylist[0].regions[i], stars, Nstars, &catalog, image);36 match_fake_stars (stars, Nstars, skylist[0].regions[i], &catalog, image); 34 37 35 38 /* report total updated values */ … … 38 41 39 42 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; 41 44 dvo_catalog_update (&catalog, VERBOSE); 42 45 SetProtect (FALSE); … … 47 50 } 48 51 52 free (imagePatch); 49 53 SkyListFree (skylist); 50 54 return TRUE; 51 55 } 56 57 // XXX what about starpar values?
Note:
See TracChangeset
for help on using the changeset viewer.
