Changeset 33567
- Timestamp:
- Mar 17, 2012, 4:08:54 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20111122/Ohana/src/relastro
- Files:
-
- 2 edited
-
include/relastro.h (modified) (1 diff)
-
src/bcatalog.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h
r33566 r33567 417 417 418 418 int GetScatterRawRef(float *dLsig, float *dMsig, float *dRsig, int *nKeep, StarData *raw, StarData *ref, int Nstars, float SigmaLimit); 419 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog); 419 int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *catalog); 420 int LimitDensityCatalog_RandomSample (Catalog *subcatalog, Catalog *catalog); 420 421 421 422 int initializeConstraints(); -
branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/bcatalog.c
r33452 r33567 114 114 // limit the total number of stars in the catalog 115 115 if (MaxDensityUse) { 116 LimitDensityCatalog (subcatalog, catalog);116 LimitDensityCatalog_ByNmeasure (subcatalog, catalog); 117 117 } 118 118 … … 123 123 } 124 124 125 // sort by decreasing Nmeasure (X) 126 void sort_by_Nmeasure (int *X, off_t *Y, off_t N) { 127 128 # define SWAPFUNC(A,B){ int tmpI; off_t tmpT; \ 129 tmpI = X[A]; X[A] = X[B]; X[B] = tmpI; \ 130 tmpT = Y[A]; Y[A] = Y[B]; Y[B] = tmpT; \ 131 } 132 # define COMPARE(A,B)(X[A] > X[B]) 133 134 OHANA_SORT (N, COMPARE, SWAPFUNC); 135 136 # undef SWAPFUNC 137 # undef COMPARE 138 139 } 140 125 141 /* this version does NOT use AverageTiny, MeasureTiny */ 126 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {142 int LimitDensityCatalog_ByNmeasure (Catalog *subcatalog, Catalog *catalog) { 127 143 128 144 Catalog tmpcatalog; … … 154 170 // select a random subset of Nmax stars from subcatalog using Fisher-Yates 155 171 156 // we are going to select Nmax entries by generating a random-sorted index list 157 off_t *index, tmp, i, j, ave; 172 // we are going to select Nmax entries by choosing the brightest objects 173 int *value; 174 off_t *index, i, j, ave; 158 175 ALLOCATE (index, off_t, Naverage); 176 ALLOCATE (value, int, Naverage); 159 177 for (i = 0; i < Naverage; i++) { 160 178 index[i] = i; 161 } 162 for (i = 0; i < Naverage; i++) { 163 j = (Naverage - i) * drand48() + i; // a number between i and Naverage 164 tmp = index[j]; 165 index[j] = index[i]; 166 index[i] = tmp; 167 } 179 value[i] = catalog[0].average[i].Nmeasure; 180 } 181 sort_by_Nmeasure (value, index, Naverage); 168 182 169 183 // count the number of measurements this selection will yield … … 202 216 } 203 217 218 free (index); 219 free (value); 204 220 free (subcatalog[0].average); 205 221 free (subcatalog[0].measureT); … … 217 233 } 218 234 235 /* this version does NOT use AverageTiny, MeasureTiny */ 236 int LimitDensityCatalog_RandomSample (Catalog *subcatalog, Catalog *catalog) { 237 238 Catalog tmpcatalog; 239 240 double Rmin, Rmax, Dmin, Dmax; 241 242 int Nsecfilt = GetPhotcodeNsecfilt (); 243 244 gfits_scan (&catalog[0].header, "RA0", "%lf", 1, &Rmin); 245 gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin); 246 gfits_scan (&catalog[0].header, "RA1", "%lf", 1, &Rmax); 247 gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax); 248 249 if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax); 250 251 float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin)); 252 assert (AREA > 0); 253 254 off_t Nmax = MaxDensityValue * AREA; 255 if (subcatalog[0].Naverage <= Nmax) { 256 if (VERBOSE) { 257 fprintf (stderr, "subcatalog has less than the max density\n"); 258 } 259 return (TRUE); 260 } 261 262 off_t Naverage = subcatalog[0].Naverage; 263 264 // select a random subset of Nmax stars from subcatalog using Fisher-Yates 265 266 // we are going to select Nmax entries by generating a random-sorted index list 267 off_t *index, tmp, i, j, ave; 268 ALLOCATE (index, off_t, Naverage); 269 for (i = 0; i < Naverage; i++) { 270 index[i] = i; 271 } 272 for (i = 0; i < Naverage; i++) { 273 j = (Naverage - i) * drand48() + i; // a number between i and Naverage 274 tmp = index[j]; 275 index[j] = index[i]; 276 index[i] = tmp; 277 } 278 279 // count the number of measurements this selection will yield 280 off_t NMEASURE = 0; 281 for (i = 0; i < Nmax; i++) { 282 ave = index[i]; 283 NMEASURE += subcatalog[0].average[ave].Nmeasure; 284 } 285 286 // allocate the output data 287 ALLOCATE (tmpcatalog.average, Average, Nmax); 288 ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE); 289 ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt); 290 291 off_t Nmeasure = 0; 292 293 // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links) 294 for (i = 0; i < Nmax; i++) { 295 ave = index[i]; 296 tmpcatalog.average[i] = subcatalog[0].average[ave]; 297 tmpcatalog.average[i].measureOffset = Nmeasure; 298 for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) { 299 off_t offset = subcatalog[0].average[ave].measureOffset + j; 300 tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset]; 301 tmpcatalog.measureT[Nmeasure].averef = i; 302 Nmeasure ++; 303 } 304 for (j = 0; j < Nsecfilt; j++) { 305 tmpcatalog.secfilt[i*Nsecfilt + j] = subcatalog[0].secfilt[ave*Nsecfilt + j]; 306 } 307 } 308 309 if (VERBOSE) { 310 fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n", 311 Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure, catalog[0].filename); 312 } 313 314 free (subcatalog[0].average); 315 free (subcatalog[0].measureT); 316 free (subcatalog[0].secfilt); 317 318 subcatalog[0].average = tmpcatalog.average; 319 subcatalog[0].measureT = tmpcatalog.measureT; 320 subcatalog[0].secfilt = tmpcatalog.secfilt; 321 subcatalog[0].Naverage = Nmax; 322 subcatalog[0].Nmeasure = Nmeasure; 323 subcatalog[0].Nsecfilt = catalog[0].Nsecfilt; 324 subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt; 325 326 return (TRUE); 327 } 328
Note:
See TracChangeset
for help on using the changeset viewer.
