Changeset 35593 for branches/eam_branches/ipp-20130509
- Timestamp:
- May 22, 2013, 4:54:28 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130509/Ohana/src/uniphot
- Files:
-
- 9 edited
-
Makefile (modified) (3 diffs)
-
include/fiximids.h (modified) (5 diffs)
-
src/ImageSubsetFixImageIDs.c (modified) (13 diffs)
-
src/fiximids.c (modified) (1 diff)
-
src/fiximids_client.c (modified) (3 diffs)
-
src/initialize_fiximids.c (modified) (2 diffs)
-
src/load_images_fiximids.c (modified) (5 diffs)
-
src/update_catalog_fiximids.c (modified) (3 diffs)
-
src/update_dvo_fiximids.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/Makefile
r35103 r35593 1 default: uniphot setphot setphot_client setfwhm 1 default: uniphot setphot setphot_client setfwhm setposangle setposangle_client setastrom setastrom_client fiximids fiximids_client 2 2 help: 3 3 @echo "make options: uniphot setphot setfwhm default help install default (uniphot setphot setfwhm)" … … 25 25 setastrom: $(BIN)/setastrom.$(ARCH) 26 26 setastrom_client: $(BIN)/setastrom_client.$(ARCH) 27 fiximids: $(BIN)/fiximids.$(ARCH) 28 fiximids_client: $(BIN)/fiximids_client.$(ARCH) 27 29 28 install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client 30 install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client $(DESTBIN)/setposangle $(DESTBIN)/setposangle_client $(DESTBIN)/setastrom $(DESTBIN)/setastrom_client $(DESTBIN)/fiximids $(DESTBIN)/fiximids_client 29 31 30 32 UNIPHOT = \ … … 137 139 $(SETFWHM): $(INC)/uniphot.h 138 140 $(BIN)/setfwhm.$(ARCH): $(SETFWHM) 141 142 FIXIMIDS = \ 143 $(SRC)/fiximids.$(ARCH).o \ 144 $(SRC)/initialize_fiximids.$(ARCH).o \ 145 $(SRC)/load_images_fiximids.$(ARCH).o \ 146 $(SRC)/ImageSubsetFixImageIDs.$(ARCH).o \ 147 $(SRC)/update_dvo_fiximids.$(ARCH).o \ 148 $(SRC)/update_catalog_fiximids.$(ARCH).o \ 149 $(SRC)/SetSignals.$(ARCH).o \ 150 $(SRC)/Shutdown.$(ARCH).o 151 152 $(FIXIMIDS): $(INC)/fiximids.h 153 $(BIN)/fiximids.$(ARCH): $(FIXIMIDS) 154 155 FIXIMIDS_CLIENT = \ 156 $(SRC)/fiximids_client.$(ARCH).o \ 157 $(SRC)/initialize_fiximids.$(ARCH).o \ 158 $(SRC)/load_images_fiximids.$(ARCH).o \ 159 $(SRC)/ImageSubsetFixImageIDs.$(ARCH).o \ 160 $(SRC)/update_dvo_fiximids.$(ARCH).o \ 161 $(SRC)/update_catalog_fiximids.$(ARCH).o \ 162 $(SRC)/SetSignals.$(ARCH).o \ 163 $(SRC)/Shutdown.$(ARCH).o 164 165 $(FIXIMIDS_CLIENT): $(INC)/fiximids.h 166 $(BIN)/fiximids_client.$(ARCH): $(FIXIMIDS_CLIENT) 167 -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/include/fiximids.h
r35591 r35593 2 2 # include <dvo.h> 3 3 # include <signal.h> 4 5 typedef struct {6 unsigned int start;7 unsigned int stop;8 Coords coords;9 } Mosaic;10 4 11 5 // to determine the image ID, we need time (tzero + trate) and photcode … … 14 8 unsigned short NX; // image width 15 9 unsigned short NY; // image height 10 unsigned int nstar; // number of stars on the image 16 11 e_time tzero; // readout time (row 0) 17 12 unsigned char trate; // scan rate (100 usec/pixel) … … 28 23 char *SINGLE_CPT; 29 24 int VERBOSE; 30 int RESET; 25 int VERBOSE_IMSTATS; 26 int SUMMARY_IMSTATS; 27 char *IMSTATS_FILE; // location of partial imstats file for remote client 31 28 int UPDATE; 32 29 int PARALLEL; … … 40 37 void ConfigInit PROTO((int *argc, char **argv)); 41 38 42 void usage_fiximids PROTO(()); 43 void initialize_fiximids PROTO((int argc, char **argv)); 44 int args_fiximids PROTO((int argc, char **argv)); 45 46 void usage_fiximids_client PROTO(()); 47 void initialize_fiximids_client PROTO((int argc, char **argv)); 48 int args_fiximids_client PROTO((int argc, char **argv)); 49 50 // int update_dvo_fiximids_client PROTO((ImageSubset *image, off_t Nimage, FlatCorrectionTable *flatcorr)); 39 void usage_fiximids PROTO(()); 40 void initialize_fiximids PROTO((int argc, char **argv)); 41 int args_fiximids PROTO((int argc, char **argv)); 42 43 void usage_fiximids_client PROTO(()); 44 void initialize_fiximids_client PROTO((int argc, char **argv)); 45 int args_fiximids_client PROTO((int argc, char **argv)); 51 46 52 47 ImageSubset *ImageSubsetLoad PROTO((char *filename, off_t *nimage)); 53 48 int ImageSubsetSave PROTO((char *filename, ImageSubset *image, off_t Nimage)); 54 Image *ImagesFromSubset PROTO((ImageSubset *subset, off_t N));55 49 ImageSubset *ImagesToSubset PROTO((Image *image, off_t N)); 56 50 57 void lock_image_db PROTO((FITS_DB *db, char *filename));58 void unlock_image_db PROTO((FITS_DB *db));59 void create_image_db PROTO((FITS_DB *db));60 51 void set_db PROTO((FITS_DB *in)); 61 52 int Shutdown PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) ); … … 64 55 int SetSignals PROTO((void)); 65 56 66 Image *load_images_fiximids PROTO((FITS_DB *db, off_t *Nimage)); 67 int update_dvo_fiximids PROTO((ImageSubset *image, off_t Nimage)); 68 int update_dvo_fiximids_parallel PROTO((SkyTable *sky, ImageSubset *image, off_t Nimage)); 57 Image *load_images_fiximids PROTO((FITS_DB *db, off_t *Nimage)); 58 int update_dvo_fiximids PROTO((ImageSubset *image, off_t Nimage)); 59 int update_dvo_fiximids_parallel PROTO((SkyTable *sky, ImageSubset *image, off_t Nimage)); 60 61 void update_catalog_fiximids PROTO((Catalog *catalog)); 69 62 70 void update_catalog_fiximids PROTO((Catalog *catalog, ImageSubset *image, off_t *index, off_t Nimage)); 71 int fiximids_local_astrometry PROTO((float *posAngle, float *pltScale, double x, double y, Coords *mosaic, Coords *coords)); 63 void sort_image_times PROTO((e_time *S, e_time *E, short *C, unsigned int *I, unsigned int *Q, off_t N)); 64 int FindImageID PROTO((off_t *ID, off_t *Seq, e_time time, short photcode)); 65 void initImageIndex PROTO((ImageSubset *image, off_t Nimage_init)); 72 66 73 off_t getMosaicByTimes PROTO((unsigned int start, unsigned int stop, unsigned int *startMos, unsigned int *stopMos, off_t *indexMos)); 74 void sort_mosaic_times PROTO((unsigned int *S, unsigned int *E, off_t *I, off_t N)); 75 void initMosaics PROTO((ImageSubset *image, off_t Nimage)); 76 Mosaic *getMosaicForImage PROTO((off_t im)); 67 void BumpValidImage PROTO((int Seq)); 68 void BumpInvalidImage PROTO((int Seq)); 69 void CompareImageCounts PROTO((ImageSubset *image, off_t Nimage_comp)); 70 void SummaryImageStats PROTO((ImageSubset *image, off_t Nimage_comp)); 71 72 int ImageValidSave PROTO((char *filename)); 73 int ImageValidLoad PROTO((char *filename)); -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/ImageSubsetFixImageIDs.c
r35591 r35593 1 1 # include "fiximids.h" 2 # define FT_BZERO_INT16 1.0*0x8000 3 # define FT_BZERO_INT32 1.0*0x80000000 2 4 3 5 # define GET_COLUMN(OUT,NAME,TYPE) \ … … 8 10 9 11 int Ncol; 10 off_t i , j, k;12 off_t i; 11 13 off_t Nrow; 12 14 Header header; … … 55 57 56 58 GET_COLUMN (imageID, "IMAGE_ID", int); 57 GET_COLUMN (NX, "NX", int); 58 GET_COLUMN (NY, "NY", int); 59 GET_COLUMN (tzero, "TZERO", float); 60 GET_COLUMN (trate, "TRATE", float); 59 GET_COLUMN (NX, "NX", short); 60 GET_COLUMN (NY, "NY", short); 61 GET_COLUMN (nstar, "nstar", int); 62 GET_COLUMN (tzero, "TZERO", int); 63 GET_COLUMN (trate, "TRATE", short); 61 64 GET_COLUMN (photcode, "PHOTCODE" , short); 62 65 … … 66 69 image[i].NX = NX[i]; 67 70 image[i].NY = NY[i]; 71 image[i].nstar = nstar[i]; 68 72 image[i].tzero = tzero[i]; 69 73 image[i].trate = trate[i]; … … 75 79 free (NX); 76 80 free (NY); 81 free (nstar); 77 82 free (tzero); 78 83 free (trate); … … 85 90 int ImageSubsetSave(char *filename, ImageSubset *image, off_t Nimage) { 86 91 87 off_t i , j, k;92 off_t i; 88 93 Header header; 89 94 Header theader; … … 100 105 // an unsigned int needs to have bzero of 0x8000 101 106 gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", "tmp", 1.0, FT_BZERO_INT32); 102 gfits_define_bintable_column (&theader, "J", "NX", "tmp", "tmp", 1.0, 0.0); 103 gfits_define_bintable_column (&theader, "J", "NY", "tmp", "tmp", 1.0, 0.0); 104 gfits_define_bintable_column (&theader, "E", "TZERO", "tmp", "tmp", 1.0, 0.0); 105 gfits_define_bintable_column (&theader, "E", "TRATE", "tmp", "tmp", 1.0, 0.0); 107 gfits_define_bintable_column (&theader, "I", "NX", "tmp", "tmp", 1.0, 0.0); 108 gfits_define_bintable_column (&theader, "I", "NY", "tmp", "tmp", 1.0, 0.0); 109 gfits_define_bintable_column (&theader, "J", "NSTAR", "tmp", "tmp", 1.0, FT_BZERO_INT32); 110 gfits_define_bintable_column (&theader, "J", "TZERO", "tmp", "tmp", 1.0, 0.0); 111 gfits_define_bintable_column (&theader, "I", "TRATE", "tmp", "tmp", 1.0, 0.0); 106 112 gfits_define_bintable_column (&theader, "I", "PHOTCODE", "tmp", "tmp", 1.0, 0.0); 107 113 … … 109 115 gfits_create_table (&theader, &ftable); 110 116 111 unsigned int *imageID; 112 int *NX, *NY; 113 float *tzero, *trate; 117 unsigned int *imageID, *nstar; 118 short *NX, *NY; 119 e_time *tzero; 120 short *trate; 114 121 short *photcode; 115 122 116 123 // create intermediate storage arrays 117 124 ALLOCATE (imageID, unsigned int, Nimage); 118 ALLOCATE (NX, int, Nimage); 119 ALLOCATE (NY, int, Nimage); 120 ALLOCATE (tzero, float, Nimage); 121 ALLOCATE (trate, float, Nimage); 122 ALLOCATE (photcode, int, Nimage); 125 ALLOCATE (NX, short, Nimage); 126 ALLOCATE (NY, short, Nimage); 127 ALLOCATE (nstar, unsigned int, Nimage); 128 ALLOCATE (tzero, e_time, Nimage); 129 ALLOCATE (trate, short, Nimage); 130 ALLOCATE (photcode, short, Nimage); 123 131 124 132 // assign the storage arrays … … 127 135 NX[i] = image[i].NX ; 128 136 NY[i] = image[i].NY ; 137 nstar[i] = image[i].nstar ; 129 138 tzero[i] = image[i].tzero ; 130 139 trate[i] = image[i].trate ; … … 136 145 gfits_set_bintable_column (&theader, &ftable, "NX", NX, Nimage); 137 146 gfits_set_bintable_column (&theader, &ftable, "NY", NY, Nimage); 147 gfits_set_bintable_column (&theader, &ftable, "NSTAR", nstar, Nimage); 138 148 gfits_set_bintable_column (&theader, &ftable, "TZERO", tzero, Nimage); 139 149 gfits_set_bintable_column (&theader, &ftable, "TRATE", trate, Nimage); … … 143 153 free (NX ); 144 154 free (NY ); 155 free (nstar ); 145 156 free (tzero ); 146 157 free (trate ); … … 169 180 } 170 181 171 // XXX drop these two?172 173 # if (0)174 Image *ImagesFromSubset (ImageSubset *subset, off_t N) {175 176 off_t i;177 178 // we have been given an ImageSubset array, containing a reduced set of image fields179 // create full a Image array and save the needed values180 Image *image = NULL;181 ALLOCATE (image, Image, N);182 for (i = 0; i < N; i++) {183 image[i].imageID = subset[i].imageID;184 image[i].NX = subset[i].NX ;185 image[i].NY = subset[i].NY ;186 image[i].tzero = subset[i].tzero ;187 image[i].trate = subset[i].trate ;188 image[i].coords = subset[i].coords ;189 }190 return image;191 }192 193 182 ImageSubset *ImagesToSubset (Image *image, off_t N) { 194 183 … … 201 190 202 191 for (i = 0; i < N; i++) { 203 subset[i].imageID = image[i].imageID; 204 subset[i].NX = image[i].NX ; 205 subset[i].NY = image[i].NY ; 206 subset[i].tzero = image[i].tzero ; 207 subset[i].trate = image[i].trate ; 208 subset[i].coords = image[i].coords ; 192 subset[i].imageID = image[i].imageID ; 193 subset[i].NX = image[i].NX ; 194 subset[i].NY = image[i].NY ; 195 subset[i].nstar = image[i].nstar ; 196 subset[i].tzero = image[i].tzero ; 197 subset[i].trate = image[i].trate ; 198 subset[i].photcode = image[i].photcode ; 209 199 } 210 200 return subset; 211 201 } 212 202 213 # endif (0) 203 -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/fiximids.c
r35591 r35593 24 24 status = update_dvo_fiximids (subset, Nimage); 25 25 26 if (VERBOSE_IMSTATS) { 27 CompareImageCounts (subset, Nimage); 28 } 29 30 if (SUMMARY_IMSTATS) { 31 SummaryImageStats (subset, Nimage); 32 } 33 26 34 if (!status) exit (1); 27 35 exit (0); -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/fiximids_client.c
r35591 r35593 1 # include " setposangle.h"1 # include "fiximids.h" 2 2 3 // setposangle_client is run on a remote host and is responsible for updating the catalogs3 // fiximids_client is run on a remote host and is responsible for updating the catalogs 4 4 // owned by that host. 5 5 6 // setposangle_client -hostname (hostname) -catdir (catdir) -hostdir (hostdir) -images (images)6 // fiximids_client -hostname (hostname) -catdir (catdir) -hostdir (hostdir) -images (images) 7 7 // load the SkyTable and HostTable from (catdir) [contains the host responsibilities] 8 8 // load the image data from (images) [contains the zp infomation to apply] … … 13 13 14 14 // get configuration info, args, lockfile (set CATDIR, HOST_ID, HOSTDIR, IMAGES) 15 initialize_ setposangle_client (argc, argv);15 initialize_fiximids_client (argc, argv); 16 16 17 17 // load the image subset table from the specified location … … 19 19 ImageSubset *subset = ImageSubsetLoad (IMAGES, &Nimage); 20 20 21 update_dvo_ setposangle(subset, Nimage);21 update_dvo_fiximids (subset, Nimage); 22 22 23 23 exit (0); -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/initialize_fiximids.c
r35592 r35593 54 54 if ((N = get_argument (argc, argv, "-v"))) { 55 55 VERBOSE = TRUE; 56 remove_argument (N, &argc, argv); 57 } 58 59 SUMMARY_IMSTATS = FALSE; 60 if ((N = get_argument (argc, argv, "-imstats"))) { 61 SUMMARY_IMSTATS = TRUE; 62 remove_argument (N, &argc, argv); 63 } 64 VERBOSE_IMSTATS = FALSE; 65 if ((N = get_argument (argc, argv, "-vimstats"))) { 66 SUMMARY_IMSTATS = TRUE; 67 VERBOSE_IMSTATS = TRUE; 56 68 remove_argument (N, &argc, argv); 57 69 } … … 168 180 } 169 181 182 VERBOSE_IMSTATS = FALSE; 183 IMSTATS_FILE = NULL; 184 if ((N = get_argument (argc, argv, "-imstats"))) { 185 remove_argument (N, &argc, argv); 186 IMSTATS_FILE = strcreate (argv[N]); 187 remove_argument (N, &argc, argv); 188 } 189 170 190 UPDATE = FALSE; 171 191 if ((N = get_argument (argc, argv, "-update"))) { -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/load_images_fiximids.c
r35592 r35593 1 1 # include "fiximids.h" 2 3 off_t Nimage; 4 e_time *startImage; 5 e_time *stopImage; 6 short *photcodeImage; 7 8 Image *load_images_fiximids (FITS_DB *db, off_t *N) { 2 # define FT_BZERO_INT32 1.0*0x80000000 3 4 off_t Nimage = 0; 5 e_time *startImage = NULL; 6 e_time *stopImage = NULL; 7 short *photcodeImage = NULL; 8 unsigned int *imageID = NULL; 9 unsigned int *imageSeq = NULL; 10 int *Nimage_valid = NULL; 11 int *Nimage_invalid = NULL; 12 13 Image *load_images_fiximids (FITS_DB *db, off_t *Nimage_load) { 9 14 10 15 Image *image; … … 16 21 17 22 /* use a vtable to keep the images to be calibrated */ 18 image = gfits_table_get_Image (&db[0].ftable, Nimage , &db[0].swapped);23 image = gfits_table_get_Image (&db[0].ftable, Nimage_load, &db[0].swapped); 19 24 if (!image) { 20 25 fprintf (stderr, "ERROR: failed to read images\n"); … … 22 27 } 23 28 24 // XXX init lookup tables 25 26 fprintf (stderr, "loaded "OFF_T_FMT" images\n", *Nimage); 29 fprintf (stderr, "loaded "OFF_T_FMT" images\n", *Nimage_load); 27 30 28 31 return (image); 32 } 33 34 // find mosaic frames (unique time periods & photcode name matches mosaic) 35 void initImageIndex (ImageSubset *image, off_t Nimage_init) { 36 37 off_t i; 38 39 Nimage = Nimage_init; 40 ALLOCATE (startImage, e_time, Nimage); 41 ALLOCATE (stopImage, e_time, Nimage); 42 ALLOCATE (photcodeImage, short, Nimage); 43 ALLOCATE (imageID, unsigned int, Nimage); 44 ALLOCATE (imageSeq, unsigned int, Nimage); 45 46 ALLOCATE (Nimage_valid, int, Nimage); 47 ALLOCATE (Nimage_invalid, int, Nimage); 48 49 memset (Nimage_valid, 0, Nimage*sizeof(int)); 50 memset (Nimage_invalid, 0, Nimage*sizeof(int)); 51 52 // save the image data in the local static arrays 53 for (i = 0; i < Nimage; i++) { 54 55 /* set image time range (small boundary buffer) */ 56 e_time start = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1); 57 e_time stop = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1); 58 59 startImage[i] = start; 60 stopImage[i] = stop; 61 photcodeImage[i] = image[i].photcode; 62 imageID[i] = image[i].imageID; 63 imageSeq[i] = i; 64 } 65 66 // sort the index, start, and stop by the start times: 67 sort_image_times (startImage, stopImage, photcodeImage, imageID, imageSeq, Nimage); 68 69 return; 29 70 } 30 71 … … 32 73 // This code is copied from relastro/src/MosaicOps.c 33 74 34 off_t FindImageID (e_time time, short photcode) { 35 36 // use bisection to find the overlapping imagea 37 38 off_t Nlo, Nhi, N; 39 40 // find the last mosaic before start 41 Nlo = 0; Nhi = Nmosaic; 75 // find the image by time. this search makes the following assumptions: 76 // 1) there is only a single EXPOSURE from a single camera with the given exposure time 77 // 2) there may be multiple IMAGES from that exposure, distinguished by photcode 78 // 3) the image data has been sorted by start time 79 // 4) once we have (time > start[i]) we are past the images of interest 80 int FindImageID (off_t *ID, off_t *Seq, e_time time, short photcode) { 81 82 off_t Nlo, Nhi, N, Ni; 83 84 *ID = 0; 85 *Seq = -1; 86 87 // Find the last image ending BEFORE 'time' (time > start[i]). 88 // Use bisection to find the overlapping images. 89 Nlo = 0; Nhi = Nimage; 42 90 while (Nhi - Nlo > 10) { 43 91 N = 0.5*(Nlo + Nhi); 44 if (st artMos[N] < start) {92 if (stopImage[N] < time) { 45 93 Nlo = MAX(N, 0); 46 94 } else { 47 Nhi = MIN(N + 1, N mosaic);95 Nhi = MIN(N + 1, Nimage); 48 96 } 49 97 } 50 98 51 // check for the matched mosaic starting from Nlo 52 // we may have to go much beyond Nlo since stop is not sorted 53 // can we use a sorted version of stop to check when we are beyond the valid range?? 54 for (N = Nlo; N < Nmosaic; N++) { 55 if (stop < stopMos[N]) continue; 56 if (start > startMos[N]) continue; 57 if (stop < startMos[N]) return (-1); 58 return (indexMos[N]); 59 } 60 61 return (-1); 99 // check for the matched images starting from Nlo 100 for (N = Nlo; N < Nimage; N++) { 101 if (time > stopImage[N]) continue; 102 if (time < startImage[N]) return FALSE; 103 // a possible image match (start <= time <= stop) 104 for (Ni = N; (Ni < Nimage) && (time <= stopImage[Ni]); Ni++) { 105 if (photcodeImage[Ni] == photcode) { 106 *ID = imageID[Ni]; 107 *Seq = imageSeq[Ni]; 108 return TRUE; 109 } 110 } 111 return FALSE; 112 } 113 return FALSE; 114 } 115 116 // increment the count of valid detections for this image 117 void BumpValidImage (int Seq) { 118 myAssert (Seq >= 0, "impossible seq"); 119 myAssert (Seq < Nimage, "impossible seq"); 120 Nimage_valid[Seq] ++; 121 } 122 123 // increment the count of invalid detections for this image 124 void BumpInvalidImage (int Seq) { 125 myAssert (Seq >= 0, "impossible seq"); 126 myAssert (Seq < Nimage, "impossible seq"); 127 Nimage_invalid[Seq] ++; 128 } 129 130 void CompareImageCounts (ImageSubset *image, off_t Nimage_comp) { 131 132 off_t i; 133 134 for (i = 0; i < Nimage_comp; i++) { 135 // XXX can I limit the images to those in range of the user region? 136 137 if (Nimage_valid[i] + Nimage_invalid[i] == 0) continue; // XXX for now, skip (optionally?) images with no matched detections 138 if (image[i].photcode == 0) continue; // skip images with 0 photcode (eg, PHU) 139 140 char *date = ohana_sec_to_date (image[i].tzero); 141 char *code = GetPhotcodeNamebyCode (image[i].photcode); 142 fprintf (stderr, "image %s %s : %d %d %d : %f\n", date, code, image[i].nstar, Nimage_valid[i], Nimage_invalid[i], 143 (Nimage_valid[i] + Nimage_invalid[i]) / (float) image[i].nstar); 144 } 145 } 146 147 void SummaryImageStats (ImageSubset *image, off_t Nimage_comp) { 148 149 off_t i; 150 151 // let's report the following: 152 // Nimages with corrected image IDs 153 // Nimages with Nsum / Nstar < 0.95 154 // Nimages with Nsum / Nstar < 0.99 155 156 int Nfixed = 0; 157 int Nbad_1 = 0; 158 int Nbad_2 = 0; 159 160 for (i = 0; i < Nimage_comp; i++) { 161 if (Nimage_valid[i] + Nimage_invalid[i] == 0) continue; // XXX for now, skip (optionally?) images with no matched detections 162 if (image[i].photcode == 0) continue; // skip images with 0 photcode (eg, PHU) 163 164 if (Nimage_invalid[i] > 0) Nfixed ++; 165 166 float found_ratio = (Nimage_valid[i] + Nimage_invalid[i]) / (float) image[i].nstar; 167 168 if (found_ratio < 0.99) Nbad_1 ++; 169 if (found_ratio < 0.95) Nbad_2 ++; 170 } 171 172 fprintf (stderr, "Nfixed: %d, Ndrop (>1%%) %d, Ndrop (>5%%) %d\n", Nfixed, Nbad_1, Nbad_2); 62 173 } 63 174 64 175 // sort two times vectors and an index by first time vector 65 void sort_ mosaic_times (unsigned int *S, unsigned int *E, off_t *I, off_t N) {66 67 # define SWAPFUNC(A,B){ unsigned int tmp_t; off_t tmp_i;\176 void sort_image_times (e_time *S, e_time *E, short *C, unsigned int *I, unsigned int *Q, off_t N) { 177 178 # define SWAPFUNC(A,B){ e_time tmp_t; unsigned int tmp_u; short tmp_c; \ 68 179 tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \ 69 180 tmp_t = E[A]; E[A] = E[B]; E[B] = tmp_t; \ 70 tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \ 181 tmp_c = C[A]; C[A] = C[B]; C[B] = tmp_c; \ 182 tmp_u = I[A]; I[A] = I[B]; I[B] = tmp_u; \ 183 tmp_u = Q[A]; Q[A] = Q[B]; Q[B] = tmp_u; \ 71 184 } 72 185 # define COMPARE(A,B)(S[A] < S[B]) … … 79 192 } 80 193 81 // use the time to make the match, but use bracketing to make it faster: 82 83 // find mosaic frames (unique time periods & photcode name matches mosaic) 84 void initMosaics (ImageSubset *image, off_t Nimage) { 85 86 off_t i, Nmos, NMOSAIC; 87 unsigned int start, stop; 88 89 unsigned int *startMos, *stopMos; 90 off_t *indexMos; 91 92 Nmosaic = 0; 93 NMOSAIC = 10; 94 ALLOCATE (mosaic, Mosaic, NMOSAIC); 95 96 ALLOCATE (startMos, unsigned int, NMOSAIC); 97 ALLOCATE (stopMos, unsigned int, NMOSAIC); 98 ALLOCATE (indexMos, off_t, NMOSAIC); 99 100 /* find the mosaic images (coords.ctype = DIS); generate list of unique mosaics */ 101 for (i = 0; i < Nimage; i++) { 102 if (strcmp(&image[i].coords.ctype[4], "-DIS")) continue; 103 104 /* set image time range */ 105 start = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1); 106 stop = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1); 107 108 /* a new mosaic, define ranges */ 109 mosaic[Nmosaic].start = start; 110 mosaic[Nmosaic].stop = stop; 111 mosaic[Nmosaic].coords = image[i].coords; 112 113 startMos[Nmosaic] = start; 114 stopMos[Nmosaic] = stop; 115 indexMos[Nmosaic] = Nmosaic; 116 117 Nmosaic ++; 118 if (Nmosaic == NMOSAIC) { 119 NMOSAIC += 10; 120 REALLOCATE (mosaic, Mosaic, NMOSAIC); 121 REALLOCATE (startMos, unsigned int, NMOSAIC); 122 REALLOCATE (stopMos, unsigned int, NMOSAIC); 123 REALLOCATE (indexMos, off_t, NMOSAIC); 124 } 125 } 126 127 // sort the index, start, and stop by the start times: 128 sort_mosaic_times (startMos, stopMos, indexMos, Nmosaic); 129 130 // array to store image->mosaic index 131 Nmosaic_for_images = Nimage; 132 ALLOCATE (mosaic_for_images, off_t, Nmosaic_for_images); 133 134 /* now assign the WRP images to these mosaics */ 135 for (i = 0; i < Nimage; i++) { 136 mosaic_for_images[i] = -1; // default value for no mosaic found 137 138 if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue; 139 140 /* set image time range */ 141 start = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1); 142 stop = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1); 143 144 Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos); 145 if (Nmos == -1) { 146 fprintf (stderr, "cannot match mosaic for %d (ID = %d)\n", (int) i, (int) image[i].imageID); 147 continue; 148 } 149 150 // mosaic corresponding to this image 151 mosaic_for_images[i] = Nmos; 152 } 153 154 free (startMos); 155 free (stopMos); 156 free (indexMos); 157 return; 158 } 159 160 Mosaic *getMosaicForImage (off_t im) { 161 162 off_t mos; 163 164 if (im < 0) abort(); 165 if (im >= Nmosaic_for_images) abort(); 166 167 // search for the mosaic that 168 mos = mosaic_for_images[im]; 169 if (mos < 0) return NULL; 170 171 return &mosaic[mos]; 172 } 173 194 # define GET_COLUMN(OUT,NAME,TYPE) \ 195 TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \ 196 myAssert (!strcmp(type, #TYPE), "wrong column type"); 197 198 int ImageValidLoad(char *filename) { 199 200 int Ncol; 201 off_t i; 202 off_t Nrow; 203 Header header; 204 Header theader; 205 Matrix matrix; 206 FTable ftable; 207 208 FILE *f = fopen (filename, "r"); 209 if (!f) { 210 fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename); 211 return FALSE; 212 } 213 214 /* load in PHU segment (ignore) */ 215 if (!gfits_fread_header (f, &header)) { 216 if (VERBOSE) fprintf (stderr, "can't read image subset header\n"); 217 fclose (f); 218 return FALSE; 219 } 220 if (!gfits_fread_matrix (f, &matrix, &header)) { 221 if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n"); 222 gfits_free_header (&header); 223 fclose (f); 224 return FALSE; 225 } 226 227 ftable.header = &theader; 228 229 // load data for this header 230 if (!gfits_load_header (f, &theader)) { 231 if (VERBOSE) fprintf (stderr, "can't read table header\n"); 232 fclose (f); 233 return FALSE; 234 } 235 236 // read the fits table bytes 237 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { 238 if (VERBOSE) fprintf (stderr, "can't read table data\n"); 239 fclose (f); 240 return FALSE; 241 } 242 fclose (f); 243 244 char type[16]; 245 246 GET_COLUMN (Nvalid, "NVALID", int); 247 GET_COLUMN (Ninvalid, "NINVALID", int); 248 249 myAssert (Nrow == Nimage, "wrong size imstats result file\n"); 250 251 // merge the new arrays into the single array? 252 for (i = 0; i < Nrow; i++) { 253 Nimage_valid[i] += Nvalid[i]; 254 Nimage_invalid[i] += Ninvalid[i]; 255 } 256 fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow); 257 258 free (Nvalid); 259 free (Ninvalid); 260 261 return TRUE; 262 } 263 264 int ImageValidSave(char *filename) { 265 266 Header header; 267 Header theader; 268 Matrix matrix; 269 FTable ftable; 270 271 gfits_init_header (&header); 272 header.extend = TRUE; 273 gfits_create_header (&header); 274 gfits_create_matrix (&header, &matrix); 275 276 gfits_create_table_header (&theader, "BINTABLE", "IMAGE_VALID"); 277 278 // create the table layout 279 gfits_define_bintable_column (&theader, "J", "NVALID", "tmp", "tmp", 1.0, FT_BZERO_INT32); 280 gfits_define_bintable_column (&theader, "J", "NINVALID", "tmp", "tmp", 1.0, FT_BZERO_INT32); 281 282 // generate the output array that carries the data 283 gfits_create_table (&theader, &ftable); 284 285 // add the columns to the output array 286 gfits_set_bintable_column (&theader, &ftable, "NVALID", Nimage_valid, Nimage); 287 gfits_set_bintable_column (&theader, &ftable, "NINVALID", Nimage_invalid, Nimage); 288 289 FILE *f = fopen (filename, "w"); 290 if (!f) { 291 fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", filename); 292 return FALSE; 293 } 294 295 gfits_fwrite_header (f, &header); 296 gfits_fwrite_matrix (f, &matrix); 297 gfits_fwrite_Theader (f, &theader); 298 gfits_fwrite_table (f, &ftable); 299 300 gfits_free_header (&header); 301 gfits_free_matrix (&matrix); 302 gfits_free_header (&theader); 303 gfits_free_table (&ftable); 304 305 fclose (f); 306 fflush (f); 307 308 return TRUE; 309 } -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_catalog_fiximids.c
r35592 r35593 1 1 # include "fiximids.h" 2 2 3 void update_catalog_fiximids (Catalog *catalog , ImageSubset *image, off_t *index, off_t Nimage) {3 void update_catalog_fiximids (Catalog *catalog) { 4 4 5 float posAngle, pltScale; 6 off_t i, j, found; 5 off_t i; 7 6 8 found = 0; 7 off_t found = 0; 8 off_t Nvalid = 0; 9 off_t Ninvalid = 0; 10 9 11 for (i = 0; i < catalog[0].Nmeasure; i++) { 10 12 … … 17 19 e_time time = catalog[0].measure[i].t; 18 20 19 off_t imageID = FindImageID (time, photcode); 20 if (imageID <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode) 21 // skip detections with no valid imageID (eg, ref photcode) 22 23 off_t imageID, Seq; 24 if (!FindImageID (&imageID, &Seq, time, photcode)) continue; 25 if (imageID <= 0) continue; 21 26 22 27 if (imageID == catalog[0].measure[i].imageID) { 23 28 // existing image ID is valid 24 29 Nvalid ++; 25 onImage[imageID] ++; 26 continue; 30 BumpValidImage (Seq); 31 } else { 32 // existing image ID is NOT valid 33 Ninvalid ++; 34 catalog[0].measure[i].imageID = imageID; 35 BumpInvalidImage (Seq); 27 36 } 28 29 // existing image ID is NOT valid30 catalog[0].measure[i].imageID = imageID;31 Ninvalid ++;32 onImage[imageID] ++;33 continue;34 37 35 38 found ++; … … 37 40 38 41 if (found) { 39 fprintf (stderr, "found "OFF_T_FMT" matches \n", found);42 fprintf (stderr, "found "OFF_T_FMT" matches: "OFF_T_FMT" valid, "OFF_T_FMT" invalid\n", found, Nvalid, Ninvalid); 40 43 } 41 44 } -
branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_dvo_fiximids.c
r35592 r35593 6 6 SkyList *skylist = NULL; 7 7 Catalog catalog; 8 off_t i , maxID, *index;8 off_t i; 9 9 10 10 // load the current sky table (layout of all SkyRegions) … … 12 12 SkyTableSetFilenames (sky, CATDIR, "cpt"); 13 13 14 // generate index tables 15 initImageIndex (image, Nimage); 16 14 17 if (PARALLEL && !HOST_ID) { 15 18 update_dvo_fiximids_parallel (sky, image, Nimage); 16 19 return TRUE; 17 20 } 18 19 // create an index for the image IDs20 maxID = 0;21 for (i = 0; i < Nimage; i++) {22 maxID = MAX(maxID, image[i].imageID);23 }24 ALLOCATE (index, off_t, maxID + 1);25 for (i = 0; i < maxID + 1; i++) {26 index[i] = -1;27 }28 for (i = 0; i < Nimage; i++) {29 if (!image[i].imageID) continue; // images with ID == 0 are virtual30 index[image[i].imageID] = i;31 }32 33 // set up the links between images and mosaics34 initMosaics (image, Nimage);35 21 36 22 // determine the populated SkyRegions overlapping the requested area (default depth) … … 69 55 } 70 56 71 update_catalog_fiximids (&catalog , image, index, Nimage);57 update_catalog_fiximids (&catalog); 72 58 73 59 if (!UPDATE) { … … 83 69 dvo_catalog_free (&catalog); 84 70 } 71 72 // for the remote clients, we need to dump out the results table (Nvalid, Ninvalid) 73 if (HOST_ID && IMSTATS_FILE) { 74 ImageValidSave (IMSTATS_FILE); 75 } 76 85 77 return (TRUE); 86 78 } … … 90 82 int update_dvo_fiximids_parallel (SkyTable *sky, ImageSubset *image, off_t Nimage) { 91 83 84 char uniquer[12]; 85 int TIME = time(NULL); 86 int PID = getpid(); 87 snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000); 88 92 89 // write out the subset table of image information 93 90 char imageFile[512]; 94 snprintf (imageFile, 512, "%s/ Images.subset.dat", CATDIR);91 snprintf (imageFile, 512, "%s/fiximids.images.%s.dat", CATDIR, uniquer); 95 92 96 93 if (!ImageSubsetSave (imageFile, image, Nimage)) { … … 112 109 table->hosts[i].pathname = tmppath; 113 110 111 ALLOCATE (table->hosts[i].results, char, 1024); 112 snprintf (table->hosts[i].results, 1024, "%s/fiximids.results.%s.dat", table->hosts[i].pathname, uniquer); 113 114 114 char command[1024]; 115 115 snprintf (command, 1024, "fiximids_client -hostID %d -catdir %s -hostdir %s -images %s -region %f %f %f %f", 116 table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile, 116 table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, imageFile, 117 117 UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax); 118 118 119 fprintf (stderr, "command: %s\n", command);119 int saveImstats = VERBOSE_IMSTATS || SUMMARY_IMSTATS; 120 120 121 121 char tmpline[1024]; 122 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 123 if (SINGLE_CPT) { snprintf (tmpline, 1024, "%s -cpt %s", SINGLE_CPT, command); strcpy (command, tmpline); } 124 if (UPDATE) { snprintf (tmpline, 1024, "%s -update", command); strcpy (command, tmpline); } 122 if (VERBOSE) { snprintf (tmpline, 1024, "%s -v", command); strcpy (command, tmpline); } 123 if (saveImstats) { snprintf (tmpline, 1024, "%s -imstats %s", command, table->hosts[i].results); strcpy (command, tmpline); } 124 if (SINGLE_CPT) { snprintf (tmpline, 1024, "%s -cpt %s", command, SINGLE_CPT); strcpy (command, tmpline); } 125 if (UPDATE) { snprintf (tmpline, 1024, "%s -update", command); strcpy (command, tmpline); } 126 127 fprintf (stderr, "command: %s\n", command); 125 128 126 129 if (PARALLEL_MANUAL) continue; … … 154 157 } 155 158 159 if (VERBOSE_IMSTATS || SUMMARY_IMSTATS) { 160 for (i = 0; i < table->Nhosts; i++) { 161 while (!ImageValidLoad (table->hosts[i].results)) { 162 // failed to get the data from this host. This can happen for various reasons. Give the user a chance to try again... 163 fprintf (stderr, "failed to read data from %s, stopping operations until this can be fixed\n", table->hosts[i].hostname); 164 fprintf (stderr, "you may run the command manually and send this process the CONT signal\n"); 165 int pid = getpid(); 166 kill (pid, SIGSTOP); 167 fprintf (stderr, "retrying %s\n", table->hosts[i].results); 168 } 169 } 170 } 171 156 172 return (TRUE); 157 173 }
Note:
See TracChangeset
for help on using the changeset viewer.
