Changeset 38518
- Timestamp:
- Jun 23, 2015, 6:50:35 AM (11 years ago)
- Location:
- branches/eam_branches/ipp-20150616/Ohana/src/addstar
- Files:
-
- 2 added
- 4 edited
-
Makefile (modified) (1 diff)
-
include/loadgalphot.h (modified) (2 diffs)
-
src/loadgalphot_join.c (modified) (4 diffs)
-
src/loadgalphot_readstars.c (modified) (10 diffs)
-
src/sortIDs.c (added)
-
src/strhash.c (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile
r38496 r38518 256 256 $(SRC)/loadgalphot_readstars.$(ARCH).o \ 257 257 $(SRC)/loadgalphot_fit2d.$(ARCH).o \ 258 $(SRC)/loadgalphot_join.$(ARCH).o \ 258 259 $(SRC)/loadgalphot_table.$(ARCH).o \ 260 $(SRC)/strhash.$(ARCH).o \ 261 $(SRC)/sortIDs.$(ARCH).o \ 259 262 $(SRC)/psps_ids.$(ARCH).o 260 263 -
branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/loadgalphot.h
r38501 r38518 30 30 } GalPhot_Stars; 31 31 32 typedef struct { 33 int *ID; 34 int *type; 35 int N; 36 } GalPhotIDset; 37 32 38 AddstarClientOptions args_loadgalphot (int argc, char **argv, AddstarClientOptions options); 33 39 … … 53 59 int fit2d (Fit2D *fit, float *xval, float *yval, float *zval, float *zfit, char *mask, int Npts); 54 60 int fit2d_reset (Fit2D *fit); 61 62 int *join_IDs (GalPhotIDset *gal, GalPhotIDset *fit); 63 int strhash (char *string, int module); 64 65 void sort_IDs_seqonly (int *X, int *S, int N); -
branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_join.c
r38511 r38518 1 1 # include "addstar.h" 2 2 # include "loadgalphot.h" 3 4 typedef struct {5 int *ID;6 int *type;7 int N;8 } GalPhotIDset;9 3 10 4 // find the entries in 'fit' which match entries in 'gal' … … 12 6 int *join_IDs (GalPhotIDset *gal, GalPhotIDset *fit) { 13 7 14 off_t ifit, igal, first_ifit, Ifit, Igal, *seq_fit, *seq_gal, Nmatch, NMATCH; 15 opihi_int dID; 8 int Nmatch = 0; 9 int NMATCH = gal->N; 10 int *idx_gal = NULL; 11 ALLOCATE (idx_gal, int, gal->N); 16 12 17 NMATCH = gal->N;18 ALLOCATE ( idx_gal, off_t, gal->N);19 20 ALLOCATE (seq_gal, off_t, gal->N);21 ALLOCATE (seq_fit, off_t, fit->N);22 23 for (i = 0; i < gal->N; i++) { seq_gal[i] = i; }24 for (i = 0; i < fit->N; i++) { seq_fit[i] = i;}13 int *seq_fit, *seq_gal; 14 ALLOCATE (seq_gal, int, gal->N); 15 ALLOCATE (seq_fit, int, fit->N); 16 { 17 int i; 18 for (i = 0; i < gal->N; i++) { seq_gal[i] = i; } 19 for (i = 0; i < fit->N; i++) { seq_fit[i] = i; } 20 } 25 21 26 22 // sort the sequences … … 28 24 sort_IDs_seqonly (fit->ID, seq_fit, fit->N); 29 25 30 Nmatch = 0;26 int ifit, igal; 31 27 for (ifit = igal = 0; (igal < gal->N) && (ifit < fit->N);) { 32 Igal = seq_gal[i];33 Ifit = seq_fit[j];28 int Igal = seq_gal[igal]; 29 int Ifit = seq_fit[ifit]; 34 30 35 dID = gal->ID[Igal] - fit->ID[Ifit];31 int dID = gal->ID[Igal] - fit->ID[Ifit]; 36 32 37 33 if (dID < 0) { igal++; continue; } … … 40 36 // look for all matches of list2() to list1(i) 41 37 // this allows for multiple values of ID1 or ID2 42 first_ifit = ifit; 43 for (ifit = first_ifit; (dID == 0) && (ifit < fit->N); ifit++) { 44 Ifit = seq_fit[j]; 38 int ifit_first = ifit; 39 int found = FALSE; 40 for (ifit = ifit_first; (dID == 0) && (ifit < fit->N); ifit++) { 41 Ifit = seq_fit[ifit]; 45 42 dID = gal->ID[Igal] - fit->ID[Ifit]; 46 if (dID == 0) { 47 // XXX find the matching model types 48 index1->elements.Int[Nmatch] = I; 49 index2->elements.Int[Nmatch] = J; 50 43 if ((dID == 0) && (gal->type[Igal] == fit->type[Ifit])){ 44 idx_gal[Igal] = Ifit; 45 found = TRUE; 51 46 Nmatch ++; 52 47 if (Nmatch >= NMATCH) { 53 NMATCH += DMATCH; 54 REALLOCATE (index1->elements.Int, opihi_int, NMATCH); 55 REALLOCATE (index2->elements.Int, opihi_int, NMATCH); 48 NMATCH += 1000; 49 REALLOCATE (idx_gal, int, NMATCH); 56 50 } 51 break; 57 52 } 58 53 } 59 j = first_j; 60 i++; 54 myAssert (found, "gal entry not found?"); 55 ifit = ifit_first; 56 igal ++; 61 57 } 62 index1->Nelements = Nmatch;63 index2->Nelements = Nmatch;58 free (seq_gal); 59 free (seq_fit); 64 60 65 free (N1); 66 free (N2); 61 myAssert (Nmatch == gal->N, "did not find matches for all galaxies"); 62 63 for (igal = 0; igal < gal->N; igal++) { 64 ifit = idx_gal[igal]; 65 myAssert (fit->ID[ifit] == gal->ID[igal], "ID mis-match"); 66 myAssert (fit->type[ifit] == gal->type[igal], "type mis-match"); 67 } 67 68 68 return ( TRUE);69 return (idx_gal); 69 70 } -
branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_readstars.c
r38511 r38518 22 22 if (f == NULL) Shutdown ("can't read stellar parameter file: %s", filename); 23 23 24 int i, Ncol, Nsample;24 int i, j, Ncol, Nsample; 25 25 off_t Nrow = 0; 26 26 off_t NrowNew; … … 35 35 fclose (f); 36 36 return NULL; 37 }38 39 // in xgal, we have numerical values to specify the model types40 // in xfit, we have strings. these are listed with their numerical41 // match in the PHU. I need to read the list of names and set up a string hash42 43 if (!gfits_scan (PHU, "MTNUM", "%d", 1, &ModelTypeN)) { myAbort ("fail"); }44 ALLOCATE (ModelTypeName, char *, ModelTypeN);45 ALLOCATE (ModelTypeNum, int, ModelTypeN);46 ALLOCATE (ModelTypeHash, int, ModelTypeN);47 48 int tmpnumber, namehash[256][3];49 for (i = 0; i < 256; i++) {50 namehash[i][0] = -1;51 namehash[i][1] = -1;52 namehash[i][2] = -1;53 }54 55 char name[256], tmpname[256];56 for (i = 0; i < ModelTypeN; i++) {57 snprintf (name, 64, "MTNAM%02d", i);58 if (!gfits_scan (PHU, name, "%s", 1, tmpname)) { myAbort ("fail"); }59 ModelTypeName[i] = strcreate (tmpname);60 int found = FALSE;61 int myHash = strhash (tmpname);62 ModelTypeHash[i] = myHash;63 for (j = 0; (j < 3) && !found; j++) {64 if (namehash[myHash][j] != -1) continue;65 found = TRUE;66 namehash[myHash][j] = i;67 }68 myAssert (found, "hash conflict");69 snprintf (name, 64, "MTVAL%02d", i);70 if (!gfits_scan (PHU, name, "%d", 1, &tmpnumber)) { myAbort ("fail"); }71 ModelTypeNum[i] = tmpnumber;72 37 } 73 38 … … 81 46 return NULL; 82 47 } 83 84 48 ftable_xfit.header = &header_xfit; 49 50 // in xgal, we have numerical values to specify the model types 51 // in xfit, we have strings. these are listed with their numerical 52 // match in the PHU. I need to read the list of names and set up a string hash 53 54 int ModelTypeN; 55 char **ModelTypeName; 56 int *ModelTypeNum; 57 int *ModelTypeHash; 58 if (!gfits_scan (&header_xfit, "MTNUM", "%d", 1, &ModelTypeN)) { myAbort ("fail"); } 59 ALLOCATE (ModelTypeName, char *, ModelTypeN); 60 ALLOCATE (ModelTypeNum, int, ModelTypeN); 61 ALLOCATE (ModelTypeHash, int, ModelTypeN); 62 63 int tmpnumber, namehash[256][3]; 64 for (i = 0; i < 256; i++) { 65 namehash[i][0] = -1; 66 namehash[i][1] = -1; 67 namehash[i][2] = -1; 68 } 69 70 char name[256], tmpname[256]; 71 for (i = 0; i < ModelTypeN; i++) { 72 snprintf (name, 64, "MTNAM%02d", i); 73 if (!gfits_scan (&header_xfit, name, "%s", 1, tmpname)) { myAbort ("fail"); } 74 ModelTypeName[i] = strcreate (tmpname); 75 int found = FALSE; 76 int myHash = strhash (tmpname, 0xff); 77 fprintf (stderr, "model %s, hash: %d\n", tmpname, myHash); 78 ModelTypeHash[i] = myHash; 79 for (j = 0; (j < 3) && !found; j++) { 80 if (namehash[myHash][j] != -1) continue; 81 found = TRUE; 82 namehash[myHash][j] = i; 83 } 84 myAssert (found, "hash conflict"); 85 snprintf (name, 64, "MTVAL%02d", i); 86 if (!gfits_scan (&header_xfit, name, "%d", 1, &tmpnumber)) { myAbort ("fail"); } 87 ModelTypeNum[i] = tmpnumber; 88 } 85 89 86 90 if (!gfits_fread_ftable_data (f, &ftable_xfit, FALSE)) { … … 94 98 firstCol = TRUE; 95 99 GET_COLUMN (xfit, ID_fit, "IPP_IDET", int); 96 GET_COLUMN (xfit, MODEL_TYPE_str, "MODEL_TYPE", char); NcharModel = Ncol;100 GET_COLUMN (xfit, MODEL_TYPE_str, "MODEL_TYPE", char); int NcharModel = Ncol; 97 101 GET_COLUMN (xfit, EXT_WIDTH_MAJ, "EXT_WIDTH_MAJ", float); 98 102 GET_COLUMN (xfit, EXT_WIDTH_MIN, "EXT_WIDTH_MIN", float); … … 102 106 int Nfit = Nrow; 103 107 108 myAssert (NcharModel < 256, "max model type name is very long: %d", NcharModel); 109 104 110 // free the memory associated with the FITS files 105 111 gfits_free_header (&header_xfit); 106 112 gfits_free_table (&ftable_xfit); 107 113 114 char string[256]; 115 108 116 // convert MODEL_TYPE_str to MODEL_TYPE_fit (transforming strings to values) 117 int *MODEL_TYPE_fit; 109 118 ALLOCATE (MODEL_TYPE_fit, int, Nfit); 110 119 for (i = 0; i < Nfit; i++) { 111 int myHash = strhash (MODEL_TYPE_str[i]); 120 memset (string, 0, 256); 121 memcpy (string, &MODEL_TYPE_str[i*NcharModel], NcharModel); string[NcharModel] = 0; 122 stripwhite (string); 123 int myHash = strhash (string, 0xff); 112 124 int found = FALSE; 113 125 for (j = 0; !found && (j < 3); j++) { 114 126 int n = namehash[myHash][j]; 115 if (strcmp(ModelTypeName[n], MODEL_TYPE_str[i])) continue;127 if (strcmp(ModelTypeName[n], string)) continue; 116 128 MODEL_TYPE_fit[i] = ModelTypeNum[n]; 117 129 found = TRUE; 118 130 } 119 myAssert (found, "unknown model name? %s", MODEL_TYPE_str[i]);131 myAssert (found, "unknown model name? %s", string); 120 132 } 121 133 … … 155 167 GET_COLUMN (xgal, FR_MINOR_MAX, "FR_MINOR_MAX", float); 156 168 GET_COLUMN (xgal, FR_MINOR_DEL, "FR_MINOR_DEL", float); 157 Ngal = Nrow;169 int Ngal = Nrow; 158 170 159 171 // i need to match the two lists based on (ID_gal == ID_fit), (MODEL_TYPE_gal == MODEL_TYPE_fit) 160 GalPhotIDset fit , gal;161 fit .ID = ID_fit;162 fit .type = MODEL_TYPE_fit;163 fit .N = Nfit;164 gal .ID = ID_gal;165 gal .type = MODEL_TYPE_gal;166 gal .N = Ngal;167 int *i ndex = join_IDs (&gal, &fit);172 GalPhotIDset fitSet, galSet; 173 fitSet.ID = ID_fit; 174 fitSet.type = MODEL_TYPE_fit; 175 fitSet.N = Nfit; 176 galSet.ID = ID_gal; 177 galSet.type = MODEL_TYPE_gal; 178 galSet.N = Ngal; 179 int *idx_gal = join_IDs (&galSet, &fitSet); 168 180 169 181 // free the memory associated with the FITS files … … 192 204 for (i = 0; i < Nrow; i++) { 193 205 206 int ifit = idx_gal[i]; 207 194 208 double R, D; 195 209 XY_to_RD (&R, &D, X_FIT[i], Y_FIT[i], &coords); … … 208 222 // theta, theta_err, index, 209 223 // note that FR_MAJOR, etc are the fractions of the stack fit value 210 stars[i].galphot.theta = NAN; 211 stars[i].galphot.thetaErr = NAN; 224 stars[i].galphot.theta = EXT_THETA[ifit]; 225 stars[i].galphot.thetaErr = EXT_THETA_ERR[ifit]; 226 stars[i].galphot.index = INDEX[ifit]; 227 stars[i].galphot.Npix = NPIX[i]; 228 stars[i].galphot.modelType = MODEL_TYPE_gal[i]; 229 stars[i].galphot.detID = ID_gal[i]; 212 230 213 231 // I have a grid of measurements with (Flux, dFlux, Chisq) at each point … … 217 235 Nbad ++; 218 236 } 237 238 // I could either multiply FR_MAJOR_MIN, etc above or the fitted values below 239 stars[i].galphot.majorAxis *= EXT_WIDTH_MAJ[ifit]; 240 stars[i].galphot.majorAxisErr *= EXT_WIDTH_MAJ[ifit]; 241 stars[i].galphot.minorAxis *= EXT_WIDTH_MIN[ifit]; 242 stars[i].galphot.minorAxisErr *= EXT_WIDTH_MIN[ifit]; 219 243 } 220 244 … … 347 371 // use bilinear interpolation to choose Flux @ (Xmin,Ymin)? 348 372 galphot->mag = -2.5*log10(flux[iMin]); // correct for exptime? 349 galphot->magErr = -2.5*log10(fluxErr[iMin]); // correct for exptime?373 galphot->magErr = fluxErr[iMin] / flux[iMin]; 350 374 galphot->chisq = chisqMin; 351 375
Note:
See TracChangeset
for help on using the changeset viewer.
