Changeset 38518 for branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/loadgalphot_readstars.c
- Timestamp:
- Jun 23, 2015, 6:50:35 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.
