Changeset 34210
- Timestamp:
- Jul 26, 2012, 8:10:41 AM (14 years ago)
- Location:
- branches/eam_branches/ipp-20120627/Ohana/src
- Files:
-
- 2 added
- 12 edited
-
addstar/include/skycells.h (modified) (3 diffs)
-
addstar/src/BoundaryTreeIO.c (modified) (16 diffs)
-
addstar/src/args_skycells.c (modified) (2 diffs)
-
addstar/src/findskycell.c (modified) (11 diffs)
-
addstar/src/sky_tessalation.c (modified) (5 diffs)
-
libdvo/Makefile (modified) (1 diff)
-
libdvo/include/dvo.h (modified) (2 diffs)
-
libdvo/src/BoundaryTree.c (added)
-
relphot/Makefile (modified) (2 diffs)
-
relphot/include/relphot.h (modified) (2 diffs)
-
relphot/src/BoundaryTreeOps.c (added)
-
relphot/src/ImageOps.c (modified) (1 diff)
-
relphot/src/StarOps.c (modified) (7 diffs)
-
relphot/src/args.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120627/Ohana/src/addstar/include/skycells.h
r33719 r34210 12 12 # include <glob.h> 13 13 14 enum {SQUARES, TRIANGLES, LOCAL, RINGS };14 enum {SQUARES, TRIANGLES, LOCAL, RINGS, TAMAS}; 15 15 enum {TETRAHEDRON, CUBE, OCTOHEDRON, DODECAHEDRON, ICOSAHEDRON}; 16 16 … … 95 95 int sky_tessellation_squares PROTO((FITS_DB *db, int level, int Nmax)); 96 96 int sky_tessellation_rings PROTO((FITS_DB *db, int level, int Nmax)); 97 int sky_tessellation_tamas PROTO((FITS_DB *db, int level, int Nmax)); 97 98 98 99 int sky_triangle_to_image PROTO((Image *image, SkyTriangle *triangle)); … … 104 105 105 106 SkyRectangle *sky_rectangle_ring PROTO((float dec, float dDEC, int *nring, char *format)); 107 SkyRectangle *sky_rectangle_tamas PROTO((double *Dec, double dm, double halfa, double halftheta, int *nring, char *format)); 106 108 107 109 SkyTriangle *sky_divide_triangles PROTO((SkyTriangle *in, int *ntriangles)); -
branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/BoundaryTreeIO.c
r34209 r34210 1 1 # include "addstar.h" 2 2 3 # define GET_COLUMN (OUT,NAME,TYPE) \3 # define GET_COLUMN_NEW(OUT,NAME,TYPE) \ 4 4 TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \ 5 5 myAssert (!strcmp(type, #TYPE), "wrong column type"); 6 6 7 // outstanding issues: 8 // create the ra,dec,name arrays in the original tree 9 // how do we deal with the name array in gfits? 7 # define GET_COLUMN_RAW(OUT,NAME,TYPE) \ 8 OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \ 9 myAssert (!strcmp(type, #TYPE), "wrong column type"); 10 10 11 11 BoundaryTree *BoundaryTreeLoad(char *filename) { 12 12 13 int i, Ncol;13 int i, j, nz, nb, Ncol; 14 14 off_t Nrow; 15 15 char type[16]; … … 45 45 gfits_scan (&header, "DEC_ORI", "%lf", 1, &tree->DEC_origin); 46 46 gfits_scan (&header, "DEC_OFF", "%lf", 1, &tree->DEC_offset); 47 // gfits_scan (&header, "NZONE", "%d", 1, &tree->Nzone); XXX not needed (redundant with table length)48 47 49 48 ftable.header = &theader; … … 58 57 59 58 // need to create and assign to flat-field correction 60 GET_COLUMN(ZONE, "ZONE", int); 61 GET_COLUMN(tree->RA_origin, "RA_ORIGIN", double); 62 GET_COLUMN(tree->RA_offset, "RA_OFFSET", double); 63 GET_COLUMN(tree->Nband, "NBAND", int); 59 GET_COLUMN_RAW(tree->Nband, "NBAND", int); 60 GET_COLUMN_RAW(tree->RA_origin, "RA_ORIGIN", double); 61 GET_COLUMN_RAW(tree->RA_offset, "RA_OFFSET", double); 64 62 gfits_free_header (&theader); 65 63 gfits_free_table (&ftable); … … 69 67 70 68 // allocate the storage arrays 71 ALLOCATE (tree->ra, double *, tree->Nzone);69 ALLOCATE (tree->ra, double *, tree->Nzone); 72 70 ALLOCATE (tree->dec, double *, tree->Nzone); 73 71 ALLOCATE (tree->cell, int *, tree->Nzone); 74 72 ALLOCATE (tree->name, char **, tree->Nzone); 75 73 for (i = 0; i < tree->Nzone; i++) { 76 ALLOCATE (tree->ra[i], double *, tree->Nband[i]); 77 ALLOCATE (tree->dec[i], double *, tree->Nband[i]); 78 ALLOCATE (tree->cell[i], int *, tree->Nband[i]); 79 ALLOCATE (tree->name[i], char **, tree->Nband[i]); 74 ALLOCATE (tree->ra[i], double, tree->Nband[i]); 75 ALLOCATE (tree->dec[i], double, tree->Nband[i]); 76 ALLOCATE (tree->cell[i], int, tree->Nband[i]); 77 ALLOCATE (tree->name[i], char *, tree->Nband[i]); 78 for (j = 0; j < tree->Nband[i]; j++) { 79 ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH); 80 } 80 81 } 81 82 } … … 83 84 /*** cell information table ***/ 84 85 { 85 86 86 // load data for this header 87 87 if (!gfits_load_header (f, &theader)) goto escape; … … 91 91 92 92 // need to create and assign to flat-field correction 93 GET_COLUMN (R, "RA",double);94 GET_COLUMN (D, "DEC",double);95 GET_COLUMN (zone, "NMEAS",int);96 GET_COLUMN (band, "MEASURE_OFF",int);97 GET_COLUMN (index, "FLAGS", int);98 GET_COLUMN (name, "CAT_ID",char); // XXX how is this done?93 GET_COLUMN_NEW(R, "RA", double); 94 GET_COLUMN_NEW(D, "DEC", double); 95 GET_COLUMN_NEW(zone, "ZONE", int); 96 GET_COLUMN_NEW(band, "BAND", int); 97 GET_COLUMN_NEW(index, "INDEX", int); 98 GET_COLUMN_NEW(name, "NAME", char); // XXX how is this done? 99 99 gfits_free_header (&theader); 100 100 gfits_free_table (&ftable); … … 107 107 tree->ra[nz][nb] = R[i]; 108 108 tree->dec[nz][nb] = D[i]; 109 tree->cell s[nz][nb] = i; // XXX ?110 tree->name[nz][nb] = name[i];109 tree->cell[nz][nb] = i; // XXX ? 110 memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH); 111 111 } 112 112 … … 139 139 int BoundaryTreeSave(char *filename, BoundaryTree *tree) { 140 140 141 int i ;141 int i, nz, nb; 142 142 Header header; 143 143 Header theader; … … 152 152 FILE *f = fopen (filename, "w"); 153 153 if (!f) { 154 fprintf (stderr, "ERROR: cannot open image subsetfile for output %s\n", filename);154 fprintf (stderr, "ERROR: cannot open boundary tree file for output %s\n", filename); 155 155 return FALSE; 156 156 } … … 159 159 gfits_modify (&header, "DEC_ORI", "%lf", 1, tree->DEC_origin); 160 160 gfits_modify (&header, "DEC_OFF", "%lf", 1, tree->DEC_offset); 161 gfits_modify (&header, "NZONE", "%d", 1, tree->Nzone);162 161 163 162 gfits_fwrite_header (f, &header); … … 170 169 gfits_create_table_header (&theader, "BINTABLE", "ZONE_DATA"); 171 170 172 gfits_define_bintable_column (&theader, "J", "ZONE", "zone sequence number", NULL, 1.0, 0.0); 171 gfits_define_bintable_column (&theader, "J", "ZONE", "zone sequence number", "none", 1.0, 0.0); 172 gfits_define_bintable_column (&theader, "J", "NBAND", "number of cells in each zone", "none", 1.0, 0.0); 173 173 gfits_define_bintable_column (&theader, "D", "RA_ORIGIN", "origin of ra cell sequence", "degree", 1.0, 0.0); 174 174 gfits_define_bintable_column (&theader, "D", "RA_OFFSET", "offset per cell of ra cell sequence", "degree/cell", 1.0, 0.0); 175 gfits_define_bintable_column (&theader, "J", "NBAND", "number of cells in each zone", NULL, 1.0, 0.0);176 175 177 176 // generate the output array that carries the data … … 179 178 180 179 // create intermediate storage arrays 181 int *zone ; ALLOCATE (zone , int, tree->Nzone);180 int *zone = NULL; ALLOCATE (zone, int, tree->Nzone); 182 181 183 182 // assign the storage arrays 184 183 for (i = 0; i < tree->Nzone; i++) { 185 zone[i] = i;184 zone[i] = i; 186 185 } 187 186 188 187 // add the columns to the output array 189 188 gfits_set_bintable_column (&theader, &ftable, "ZONE", zone, tree->Nzone); 189 gfits_set_bintable_column (&theader, &ftable, "NBAND", tree->Nband, tree->Nzone); 190 190 gfits_set_bintable_column (&theader, &ftable, "RA_ORIGIN", tree->RA_origin, tree->Nzone); 191 191 gfits_set_bintable_column (&theader, &ftable, "RA_OFFSET", tree->RA_offset, tree->Nzone); 192 gfits_set_bintable_column (&theader, &ftable, "NBAND", tree->Nband, tree->Nzone);193 194 192 free (zone); 195 193 196 194 gfits_fwrite_Theader (f, &theader); 197 gfits_fwrite_table (f, &ftable);195 gfits_fwrite_table (f, &ftable); 198 196 gfits_free_header (&theader); 199 197 gfits_free_table (&ftable); … … 204 202 gfits_create_table_header (&theader, "BINTABLE", "CELL_DATA"); 205 203 206 gfits_define_bintable_column (&theader, "D", "RA", "ra (J2000) of cell center", "degree", 1.0, 0.0); 207 gfits_define_bintable_column (&theader, "D", "DEC", "dec (J2000) of cell center", "degree", 1.0, 0.0); 208 gfits_define_bintable_column (&theader, "J", "ZONE", "zone sequence number", NULL, 1.0, 0.0); 209 gfits_define_bintable_column (&theader, "J", "BAND", "band sequence number", NULL, 1.0, 0.0); 210 gfits_define_bintable_column (&theader, "J", "INDEX", "cell index", NULL, 1.0, 0.0); 211 gfits_define_bintable_column (&theader, "J", "NAME", "cell name", NULL, 1.0, 0.0); 204 char fmt[16]; 205 snprintf (fmt, 16, "%dA", BOUNDARY_TREE_NAME_LENGTH); 206 gfits_define_bintable_column (&theader, "D", "RA", "ra (J2000) of cell center", "degree", 1.0, 0.0); 207 gfits_define_bintable_column (&theader, "D", "DEC", "dec (J2000) of cell center", "degree", 1.0, 0.0); 208 gfits_define_bintable_column (&theader, "J", "ZONE", "zone sequence number", "none", 1.0, 0.0); 209 gfits_define_bintable_column (&theader, "J", "BAND", "band sequence number", "none", 1.0, 0.0); 210 gfits_define_bintable_column (&theader, "J", "INDEX","cell index", "none", 1.0, 0.0); 211 gfits_define_bintable_column (&theader, fmt, "NAME", "cell name", "none", 1.0, 0.0); 212 212 213 213 // generate the output array that carries the data … … 216 216 int Ncell = 0; 217 217 for (i = 0; i < tree->Nzone; i++) { 218 Ncell += tree->Nband[i];218 Ncell += tree->Nband[i]; 219 219 } 220 220 … … 226 226 int *band ; ALLOCATE (band, int, Ncell); 227 227 int *index ; ALLOCATE (index, int, Ncell); 228 char **name ; ALLOCATE (name, char *, Ncell); 228 char *name ; ALLOCATE (name, char, Ncell*BOUNDARY_TREE_NAME_LENGTH); 229 230 // NOTE: a table column of characters must be fixed width, and is passed as a 231 // contiguous array of Nchar * Nrow values 229 232 230 233 // assign the storage arrays 231 234 i = 0; 232 235 for (nz = 0; nz < tree->Nzone; nz++) { 233 for (nb = 0; nb < tree->Nband[nz]; nb++) { 234 R[i] = tree->ra[nz][nb]; 235 D[i] = tree->dec[nz][nb]; 236 zone[i] = nz; 237 band[i] = nb; 238 index[i] = i; // or tree->cells[nz][nb] ? 239 name[i] = tree->name[nz][nb]; // need to memcopy this? 240 i++; 236 for (nb = 0; nb < tree->Nband[nz]; nb++) { 237 R[i] = tree->ra[nz][nb]; 238 D[i] = tree->dec[nz][nb]; 239 zone[i] = nz; 240 band[i] = nb; 241 index[i] = i; // or tree->cells[nz][nb] ? 242 memcpy(&name[i*BOUNDARY_TREE_NAME_LENGTH], tree->name[nz][nb], BOUNDARY_TREE_NAME_LENGTH); 243 i++; 244 } 241 245 } 242 246 243 247 // add the columns to the output array 244 gfits_set_bintable_column (&theader, &ftable, "RA", R, Ncell);245 gfits_set_bintable_column (&theader, &ftable, "DEC", D, Ncell);246 gfits_set_bintable_column (&theader, &ftable, "ZONE", zone, Ncell);247 gfits_set_bintable_column (&theader, &ftable, "BAND", band, Ncell);248 gfits_set_bintable_column (&theader, &ftable, "INDEX", index, Ncell);249 gfits_set_bintable_column (&theader, &ftable, "NAME", name, Ncell);248 gfits_set_bintable_column (&theader, &ftable, "RA", R, Ncell); 249 gfits_set_bintable_column (&theader, &ftable, "DEC", D, Ncell); 250 gfits_set_bintable_column (&theader, &ftable, "ZONE", zone, Ncell); 251 gfits_set_bintable_column (&theader, &ftable, "BAND", band, Ncell); 252 gfits_set_bintable_column (&theader, &ftable, "INDEX", index, Ncell); 253 gfits_set_bintable_column (&theader, &ftable, "NAME", name, Ncell); 250 254 251 255 free (R ); … … 263 267 return TRUE; 264 268 } 269 270 // the boundary tree... 271 // given an (ra,dec) pair, find the containing projection cell. 272 273 int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec) { 274 275 // first, find the containing zone 276 277 // if we know dDEC, we can get the bin instantly: 278 *zone = (dec - tree->DEC_origin) / tree->DEC_offset; 279 280 if (*zone < 0) return FALSE; 281 if (*zone >= tree->Nzone) return FALSE; 282 283 // now select the RA bin for that zone 284 *band = (ra - tree->RA_origin[*zone]) / tree->RA_offset[*zone]; 285 286 if (*band < 0) return FALSE; 287 if (*band >= tree->Nband[*zone]) *band = 0; 288 289 return TRUE; 290 } 291 -
branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/args_skycells.c
r31239 r34210 37 37 if (!strcasecmp (argv[N], "rings")) { 38 38 MODE = RINGS; 39 } 40 if (!strcasecmp (argv[N], "tamas")) { 41 MODE = TAMAS; 39 42 } 40 43 remove_argument (N, &argc, argv); … … 179 182 } 180 183 remove_argument (N, &argc, argv); 184 } 185 if (MODE == TAMAS) { 186 CELLSIZE = 3.955; 187 if ((N = get_argument (argc, argv, "-cellsize"))) { 188 remove_argument (N, &argc, argv); 189 CELLSIZE = strtod (argv[N], &ptr); 190 if ((*ptr != 0) || (CELLSIZE < 0.0)) { 191 fprintf (stderr, "-cellsize requires a floating-point argument\n"); 192 help (); 193 } 194 remove_argument (N, &argc, argv); 195 } 181 196 } 182 197 -
branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/findskycell.c
r34209 r34210 1 # include " skycells.h"1 # include "addstar.h" 2 2 3 3 static double RA_offset_RINGS_V3[] = {360.000000, 40.000000, 24.000000, 17.142857, 13.333333, 10.909091, 9.230769, 8.000000, 7.200000, … … 12 12 // in an even more specific case, RA[i,zone] = RA_origin[zone] + RA_offset[zone] 13 13 14 typedef struct { 15 int FixedGridDEC; // is the DEC sequence linear? 16 int FixedGridRA; // in the RA sequence in a zone linear? 17 18 double DEC_origin; 19 double DEC_offset; 20 21 int Nzone; 22 double *RA_origin; 23 double *RA_offset; 24 25 int *Nband; 26 int *NBAND; 27 28 int **cells; 29 } BoundaryTree; 30 31 enum {NONE, MAKE_TREE, USE_TREE}; 14 enum {TREE_NONE, TREE_MAKE, TREE_USE}; 32 15 33 16 void usage (void) { 34 17 fprintf (stderr, "USAGE: findcell -mktree (tree) (catdir)\n"); 35 fprintf (stderr, "USAGE: findcell -tree (tree) ra dec\n"); 18 fprintf (stderr, "USAGE: findcell -tree (tree) (datafile)\n"); 19 fprintf (stderr, " (datafile) should contain a list of RA,DEC pairs\n"); 36 20 exit (2); 37 21 } 38 22 39 23 int mktree (char *treefile, char *catdir); 40 int find_primary_cell_coords (BoundaryTree *tree, int *zone, int *band, double ra, double dec);24 int apply_tree (char *treefile, char *datafile); 41 25 42 26 int main (int argc, char **argv) { … … 55 39 56 40 /* extra error messages */ 57 MODE =NONE;41 int MODE = TREE_NONE; 58 42 if ((N = get_argument (argc, argv, "-mktree"))) { 59 MODE = MAKE_TREE;43 MODE = TREE_MAKE; 60 44 remove_argument (N, &argc, argv); 61 45 treefile = strcreate (argv[N]); … … 63 47 } 64 48 if ((N = get_argument (argc, argv, "-tree"))) { 65 MODE = USE_TREE;49 MODE = TREE_USE; 66 50 remove_argument (N, &argc, argv); 67 51 treefile = strcreate (argv[N]); … … 73 57 if (!MODE) usage(); 74 58 75 if (MODE == MAKE_TREE) {59 if (MODE == TREE_MAKE) { 76 60 mktree (treefile, argv[1]); 77 61 exit (0); 78 62 } 79 63 80 // mktree (treefile, argv[1]);64 apply_tree (treefile, argv[1]); 81 65 exit (0); 82 66 } … … 131 115 ALLOCATE (tree.RA_origin, double, tree.Nzone); 132 116 ALLOCATE (tree.RA_offset, double, tree.Nzone); 133 ALLOCATE (tree.cells, int *, tree.Nzone); 117 118 ALLOCATE (tree.ra, double *, tree.Nzone); 119 ALLOCATE (tree.dec, double *, tree.Nzone); 120 ALLOCATE (tree.cell, int *, tree.Nzone); 121 ALLOCATE (tree.name, char **, tree.Nzone); 122 123 // NOTE 1: the RA_origin, RA_offsets for RINGS.V3 are defined so that the first projection cell 124 // overlaps the RA = 0,360 boundary. This make the split a bit of a hack. We end up 125 // with Nbands, but the max boundary of the last band only goes to 360.0 - 126 // 0.5*RA_offset. To get the right band number for the boundary region, if the 127 // calculation for the band number lands beyond the Nbands (ie, band >= Nbands), then 128 // we need to loop back to the first band. 129 130 // NOTE 2: when we generate the zone & bands initially, we do not know the number of 131 // bands in the end. we cannot use the test of band >= Nband unless we set an absurdly 132 // large default value. Thus the value of 1000000 below. 134 133 135 134 // assign the bands for RINGS.V3 136 135 for (zone = 0; zone < tree.Nzone; zone++) { 137 tree.Nband[zone] = 0;136 tree.Nband[zone] = 1000000; 138 137 tree.NBAND[zone] = 10; 139 138 tree.RA_origin[zone] = -0.5*RA_offset_RINGS_V3[zone]; 140 139 tree.RA_offset[zone] = RA_offset_RINGS_V3[zone]; 141 ALLOCATE (tree.cells[zone], int, tree.NBAND[zone]); 140 ALLOCATE (tree.ra[zone], double, tree.NBAND[zone]); 141 ALLOCATE (tree.dec[zone], double, tree.NBAND[zone]); 142 ALLOCATE (tree.cell[zone], int, tree.NBAND[zone]); 143 ALLOCATE (tree.name[zone], char *, tree.NBAND[zone]); 142 144 for (band = 0; band < tree.NBAND[zone]; band++) { 143 tree.cells[zone][band] = -1; 145 tree.ra[zone][band] = NAN; 146 tree.dec[zone][band] = NAN; 147 tree.cell[zone][band] = -1; 148 ALLOCATE (tree.name[zone][band], char, BOUNDARY_TREE_NAME_LENGTH); 144 149 } 145 150 } … … 151 156 XY_to_RD (&ra, &dec, x, y, &image[i].coords); 152 157 153 if (! find_primary_cell_coords (&tree, &zone, &band, ra, dec)) {158 if (!BoundaryTreeCellCoords (&tree, &zone, &band, ra, dec)) { 154 159 fprintf (stderr, "mismatch!\n"); 155 160 continue; … … 159 164 if (band >= tree.NBAND[zone]) { 160 165 int start = tree.NBAND[zone]; 161 tree.Nband[zone] = band + 1;162 166 tree.NBAND[zone] = band + 10; 163 REALLOCATE (tree.cells[zone], int, tree.NBAND[zone]); 167 REALLOCATE (tree.ra[zone], double, tree.NBAND[zone]); 168 REALLOCATE (tree.dec[zone], double, tree.NBAND[zone]); 169 REALLOCATE (tree.cell[zone], int, tree.NBAND[zone]); 170 REALLOCATE (tree.name[zone], char *, tree.NBAND[zone]); 164 171 for (j = start; j < tree.NBAND[zone]; j++) { 165 tree.cells[zone][j] = -1; 172 tree.ra[zone][j] = NAN; 173 tree.dec[zone][j] = NAN; 174 tree.cell[zone][j] = -1; 175 ALLOCATE (tree.name[zone][j], char, BOUNDARY_TREE_NAME_LENGTH); 166 176 } 167 177 } 168 tree.cells[zone][band] = i; 178 tree.ra[zone][band] = ra; 179 tree.dec[zone][band] = dec; 180 tree.cell[zone][band] = i; 181 memcpy (tree.name[zone][band], image[i].name, BOUNDARY_TREE_NAME_LENGTH); 169 182 } 170 183 … … 175 188 for (band = 0; band < tree.NBAND[zone]; band++) { 176 189 // all cells should be filled 177 if (tree.cell s[zone][band] < 0) {190 if (tree.cell[zone][band] < 0) { 178 191 if (!found_last) { 179 192 found_last = TRUE; … … 205 218 ra = 360.0 * drand48(); 206 219 dec = 180.0 * drand48() - 90.0; 207 if (! find_primary_cell_coords (&tree, &zone, &band, ra, dec)) {220 if (!BoundaryTreeCellCoords (&tree, &zone, &band, ra, dec)) { 208 221 fprintf (stderr, "failure for %f,%f\n", ra, dec); 209 222 } … … 216 229 } 217 230 218 // the boundary tree... 219 // given an (ra,dec) pair, find the containing projection cell. 220 221 int find_primary_cell_coords (BoundaryTree *tree, int *zone, int *band, double ra, double dec) { 222 223 // first, find the containing zone 224 225 // if we know dDEC, we can get the bin instantly: 226 *zone = (dec - tree->DEC_origin) / tree->DEC_offset; 227 228 if (*zone < 0) return FALSE; 229 if (*zone >= tree->Nzone) return FALSE; 230 231 // now select the RA bin for that zone 232 *band = (ra - tree->RA_origin[*zone]) / tree->RA_offset[*zone]; 233 234 if (*band < 0) return FALSE; 235 // if (*band >= tree->Nband[*zone]) return FALSE; 236 237 return TRUE; 238 } 231 int apply_tree (char *treefile, char *datafile) { 232 233 BoundaryTree *tree = BoundaryTreeLoad (treefile); 234 if (!tree) { 235 fprintf (stderr, "error loading boundary tree file %s\n", treefile); 236 exit (2); 237 } 238 239 FILE *f = fopen (datafile, "r"); 240 if (!f) { 241 fprintf (stderr, "error opening data file %s\n", datafile); 242 exit (3); 243 } 244 245 double ra, dec; 246 int Nvalue = 0; 247 while ((Nvalue = fscanf (f, "%lf %lf", &ra, &dec)) != EOF) { 248 249 int zone, band; 250 if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) { 251 fprintf (stderr, "error finding cell for %f,%f\n", ra, dec); 252 continue; 253 } 254 255 fprintf (stdout, "%10.6f %10.6f %3d %3d %s\n", ra, dec, zone, band, tree->name[zone][band]); 256 } 257 258 exit (0); 259 } -
branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/sky_tessalation.c
r34088 r34210 23 23 sky_tessellation_rings (db, level, Nmax); 24 24 return TRUE; 25 case TAMAS: 26 sky_tessellation_tamas (db, level, Nmax); 27 return TRUE; 25 28 default: 26 29 break; … … 284 287 free (ring); 285 288 free (image); 289 } 290 return (TRUE); 291 } 292 293 // the RINGS tessellation uses the declination zones proposed by Tamas Budavari, 294 // based on code supplied by Tamas 2012.07.23 295 int sky_tessellation_tamas (FITS_DB *db, int level, int Nmax) { 296 297 int j, nDEC, Nimage, Nring, Ntotal, Ndigit; 298 double dec, dDEC; 299 SkyRectangle *ring; 300 Image *image; 301 char format[16]; 302 303 // The tessellation has one input parameter: the approximate cell size. Starting with 304 // the cell size, determine the optimal projection cell height (dDEC) that results in an 305 // integer number of dec zones between -90 and +90 306 307 // in fact, we place a single image on each pole, so the real range of dec is 180.0 - CELLSIZE: 308 309 nDEC = (180.0 - CELLSIZE) / CELLSIZE; 310 dDEC = (180.0 - CELLSIZE) / nDEC; 311 nDEC += 2; 312 313 // how many total projection cells for this realization? divide sky area by cell area: 314 // this is used to set the number of digits, so it does not need to be very accurate... 315 Ntotal = 41254.2 / (dDEC*dDEC); 316 Ndigit = (int)(log10(Ntotal)) + 1 ; 317 snprintf (format, 16, "skycell.%%0%dd", Ndigit); 318 319 double d2r = M_PI / 180; // is RAD_DEG 320 321 // parameter 'a' is the cell size in degrees 322 double adeg = 3.955; 323 324 // half of 'a' in radians and its atan 325 double halfa = adeg / 2 * d2r; 326 double halftheta = atan(halfa); 327 328 // loop init 329 dec = 0; // starting Decl. - could change this... 330 331 while (dec < M_PI / 2 - halftheta) { 332 double dm = dec - halftheta; // eq.5 333 if (dec == 0) dm = 0; // initial 334 335 // dec is modified by the call below 336 ring = sky_rectangle_tamas (&dec, dm, halfa, halftheta, &Nring, format); 337 if (!ring) continue; 338 339 // subdivide each image (Nx x Ny subcells) 340 Nimage = NX_SUB*NY_SUB*Nring; 341 ALLOCATE (image, Image, Nimage); 342 for (j = 0; j < Nring; j++) { 343 // convert the SkyRectangles to Images for output 344 sky_subdivide_image (&image[j*NX_SUB*NY_SUB], &ring[j], NX_SUB, NY_SUB); 345 // printf("%s %8.2f %8.2f\n", ring[j].name, ring[j].coords.crval1, ring[j].coords.crval2); 346 } 347 348 /* add the new images and save */ 349 dvo_image_addrows (db, image, Nimage); 350 SetProtect (TRUE); 351 dvo_image_update (db, VERBOSE); 352 SetProtect (FALSE); 353 dvo_image_clear_vtable (db); 354 355 free (ring); 356 free (image); 286 357 } 287 358 return (TRUE); … … 666 737 } 667 738 739 // define the parameters of a projection centers for this ring 740 // dec : ~ center of ring in Dec 741 // dDEC : approximate height 742 // nring : number of cells generated for this ring 743 // format : guide to generate the filenames (c-type string format) 744 SkyRectangle *sky_rectangle_tamas (double *Dec, double dm, double halfa, double halftheta, int *nring, char *format) { 745 746 static int Nname = 0; 747 int i, j, NX, NY; 748 SkyRectangle *ring; 749 750 double d2r = M_PI / 180; // is RAD_DEG 751 double dec = *Dec; 752 753 int nRA = (int)ceil(M_PI * cos(dm) / halftheta); // eq.6 754 double dRA = 2 * M_PI / nRA; // eq.7 755 double dp = atan(tan(dec + halftheta) * cos(dRA / 2)); // eq.9 756 757 if (dec == 0.0) { 758 ALLOCATE (ring, SkyRectangle, nRA); 759 } else { 760 ALLOCATE (ring, SkyRectangle, 2*nRA); 761 } 762 763 for (i = 0; i < nRA; i++) { 764 // R.A. can use different phase per ring 765 double ra = i * dRA; // + phase (watch wraparound) 766 767 int npass = (dec == 0.0) ? 1 : 2; 768 for (j = 0; j < npass; j++) { 769 770 int N = j*nRA + i; 771 772 memset (&ring[N], 0, sizeof(SkyRectangle)); 773 memset (&ring[N].coords, 0, sizeof(Coords)); 774 775 ring[N].coords.crval1 = ra / d2r; 776 ring[N].coords.crval2 = (j == 0) ? dec / d2r : -dec / d2r; 777 778 printf(" \t %d %25.20f %25.20f\n", i, ring[N].coords.crval2, ring[N].coords.crval1); 779 780 ring[N].coords.pc1_1 = +1.0 * X_PARITY; 781 ring[N].coords.pc1_2 = +0.0; 782 ring[N].coords.pc2_1 = -0.0; 783 ring[N].coords.pc2_2 = +1.0; 784 785 // range values are in projected degrees 786 NX = cos(dec - halftheta) * dRA * 3600.0 / SCALE / d2r; 787 NY = 2 * halftheta * 3600.0 / SCALE / d2r; 788 789 // crpix1,crpix2 is the projection center 790 ring[N].coords.crpix1 = 0.5*NX; 791 ring[N].coords.crpix2 = 0.5*NY; 792 793 ring[N].coords.cdelt1 = SCALE / 3600.0; 794 ring[N].coords.cdelt2 = SCALE / 3600.0; 795 796 strcpy (ring[N].coords.ctype, "DEC--TAN"); 797 798 ring[N].NX = NX*(1.0 + PADDING); 799 ring[N].NY = NY*(1.0 + PADDING); 800 ring[N].photcode = 1; // this needs to be set more sensibly 801 802 snprintf (ring[N].name, DVO_IMAGE_NAME_LEN, format, Nname); 803 Nname++; 804 } 805 } 806 807 // advance to next ring 808 *Dec = halftheta + dp; 809 810 *nring = (dec == 0.0) ? nRA : 2*nRA; 811 return ring; 812 } 813 668 814 // an allocated image set is supplied, we fill in the values 669 815 int sky_subdivide_image (Image *output, SkyRectangle *input, int Nx, int Ny) { … … 682 828 } 683 829 684 Ndigit = (int)(log10(Nx*Ny)) + 1 ; 685 snprintf (format, 24, "%s.%%0%dd", input[0].name, Ndigit); 830 if (Nx * Ny > 1) { 831 Ndigit = (int)(log10(Nx*Ny)) + 1 ; 832 snprintf (format, 24, "%s.%%0%dd", input[0].name, Ndigit); 833 } else { 834 snprintf (format, 24, "%s", input[0].name); 835 } 686 836 687 837 // if requested extend, the skycell boundaries so that skycells overlap … … 696 846 memcpy (&output[N].coords, &input[0].coords, sizeof(Coords)); 697 847 698 snprintf (output[N].name, DVO_IMAGE_NAME_LEN, format, N); 848 if (Nx + Ny > 1) { 849 snprintf (output[N].name, DVO_IMAGE_NAME_LEN, format, N); 850 } else { 851 snprintf (output[N].name, DVO_IMAGE_NAME_LEN, "%s", format); 852 } 853 699 854 output[N].NX = NX + 2 * pad_x; 700 855 output[N].NY = NY + 2 * pad_y; -
branches/eam_branches/ipp-20120627/Ohana/src/libdvo/Makefile
r34138 r34210 102 102 $(SRC)/db_utils.$(ARCH).o \ 103 103 $(SRC)/convert.$(ARCH).o \ 104 $(SRC)/HostTable.$(ARCH).o 104 $(SRC)/HostTable.$(ARCH).o \ 105 $(SRC)/BoundaryTree.$(ARCH).o 105 106 106 107 -
branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvo.h
r34207 r34210 293 293 } DVOTinyValueMode; 294 294 295 # define BOUNDARY_TREE_NAME_LENGTH 128 296 297 typedef struct { 298 int FixedGridDEC; // is the DEC sequence linear? 299 int FixedGridRA; // in the RA sequence in a zone linear? 300 301 double DEC_origin; 302 double DEC_offset; 303 304 int Nzone; 305 double *RA_origin; 306 double *RA_offset; 307 308 int *Nband; 309 int *NBAND; 310 311 double **ra; 312 double **dec; 313 int **cell; 314 char ***name; 315 } BoundaryTree; 316 295 317 // XXX DROP? // a reduced-subset structure for relastro 296 318 // XXX DROP? typedef struct { … … 662 684 int free_tiny_values (Catalog *catalog); 663 685 686 int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec); 687 int BoundaryTreeSave(char *filename, BoundaryTree *tree); 688 BoundaryTree *BoundaryTreeLoad(char *filename); 689 664 690 # endif // DVO_H 665 -
branches/eam_branches/ipp-20120627/Ohana/src/relphot/Makefile
r33963 r34210 49 49 $(SRC)/setExclusions.$(ARCH).o \ 50 50 $(SRC)/setMrelFinal.$(ARCH).o \ 51 $(SRC)/BoundaryTreeOps.$(ARCH).o \ 51 52 $(SRC)/write_coords.$(ARCH).o 52 53 … … 77 78 $(SRC)/setExclusions.$(ARCH).o \ 78 79 $(SRC)/setMrelFinal.$(ARCH).o \ 80 $(SRC)/BoundaryTreeOps.$(ARCH).o \ 79 81 $(SRC)/write_coords.$(ARCH).o 80 82 -
branches/eam_branches/ipp-20120627/Ohana/src/relphot/include/relphot.h
r34207 r34210 111 111 char *BCATALOG; 112 112 ModeType MODE; 113 114 char *BOUNDARY_TREE; 113 115 114 116 double MAG_LIM; … … 341 343 int client_logger_message (char *format,...); 342 344 345 int MatchImageName (off_t meas, int cat, char *name); 346 347 int load_tree (char *treefile); 348 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec); -
branches/eam_branches/ipp-20120627/Ohana/src/relphot/src/ImageOps.c
r34207 r34210 385 385 distance = hypot (measure[0].Xccd - Xcenter, measure[0].Yccd - Ycenter); 386 386 return (distance); 387 } 388 389 // returns image.Mcal - ff(x,y) 390 int MatchImageName (off_t meas, int cat, char *name) { 391 392 off_t i; 393 394 if (!name) return FALSE; 395 if (!name[0]) return FALSE; 396 397 if (!MeasureToImage) return FALSE; 398 399 i = MeasureToImage[cat][meas]; 400 if (i == -1) return FALSE; 401 402 // this is a bit crude: stack image names are of the form 403 // RINGS.V3.skycell.1495.027.sky.191211.stk.988232.cmf 404 // the primaryCell has a name of the form RINGS.V3.skycell.1495 405 406 if (!strncmp(image[i].name, name, strlen(name))) return TRUE; 407 return FALSE; 387 408 } 388 409 -
branches/eam_branches/ipp-20120627/Ohana/src/relphot/src/StarOps.c
r34207 r34210 306 306 int setMrel_catalog (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) { 307 307 308 off_t j, k, m ;308 off_t j, k, m, ID; 309 309 int N; 310 310 float Msys, Mcal, Mmos, Mgrid; … … 326 326 int isSetMrelFinal = (pass >= 0); 327 327 328 char *primaryCell = NULL; 329 ALLOCATE (primaryCell, char, DVO_MAX_PATH); 330 328 331 for (j = 0; j < catalog[Nc].Naverage; j++) { 329 332 // XXX accumulate all secfilt values in a single pass? … … 334 337 print_measure_set (&catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt], catalog[Nc].measure); 335 338 } 339 340 BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D); 336 341 337 342 int GoodPS1 = FALSE; … … 361 366 int haveStack = FALSE; 362 367 363 float stackFluxPSF = NAN; 364 float stackdFluxPSF = NAN; 365 float stackFluxKron = NAN; 366 float stackdFluxKron = NAN; 368 // need to find the measurement closest to the center of its skycell, as well as the 369 // closest for the subset of primary projection cells 370 367 371 float stackCenterOffsetMin = 1e9; 368 unsigned int stackImageIDmin; 372 int stackCenterIDmin = -1; 373 off_t stackCenterMeasureMin = -1; 374 375 float stackPrimaryOffsetMin = 1e9; 376 int stackPrimaryIDmin = -1; 377 off_t stackPrimaryMeasureMin = -1; 369 378 370 379 int forceSynth = FALSE; … … 436 445 437 446 unsigned int stackImageID; 447 448 // which stack image should we use for the mean value? 449 // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell 450 if (MatchImageName (m, Nc, primaryCell)) { 451 float stackPrimaryOffset = getCenterOffset (m, Nc, &catalog[Nc].measure[m], &stackImageID); 452 if (stackPrimaryOffset < stackPrimaryOffsetMin) { 453 stackPrimaryIDmin = stackImageID; 454 stackPrimaryMeasureMin = m; 455 } 456 } 457 458 // get the center distance for the generic case: 438 459 float stackCenterOffset = getCenterOffset (m, Nc, &catalog[Nc].measure[m], &stackImageID); 439 460 if (stackCenterOffset < stackCenterOffsetMin) { 440 stackImageIDmin = stackImageID; 441 442 float zp = Mcal + Mmos + Mgrid + PhotZeroPoint (&catalog[Nc].measure[m], &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt]); 443 444 // flux_cgs : erg sec^1 cm^-2 Hz^-1 445 // mag_inst : -2.5 log (cts/sec) 446 // mag_inst : -2.5 log (flux_inst) 447 // flux_inst = ten(-0.4*mag_inst) 448 449 // mag_AB = -2.5 log (flux_cgs) - 48.6 (~by definition) [~Vega flux in V-band] 450 // flux_cgs = ten(-0.4*(mag_AB + 48.6)) 451 452 // flux_AB : ten(-0.4*mag_AB) 453 454 // flux_cgs = ten(-0.4*48.6) * flux_AB 455 // flux_AB = ten(+0.4*48.6) * flux_cgs 456 457 // flux_Jy : flux_cgs * 10^23 458 459 // flux_AB = ten(+0.4*48.6) * ten(-23) * flux_Jy 460 461 // mag_AB = mag_inst + ZP 462 463 // flux_inst = ten(-0.4*(mag_AB - ZP)) = ten(0.4*ZP) * flux_AB 464 465 // flux_AB = flux_inst * ten(-0.4*ZP) 466 467 // flux_inst * ten(-0.4*ZP) = ten(+0.4*48.6 - 23) * flux_Jy 468 469 // flux_inst = flux_Jy * ten(0.4*ZP + 0.4*48.6 - 23) 470 // flux_inst = flux_Jy * ten(0.4*ZP - 3.56) 471 // flux_Jy = flux_inst * ten(-0.4*ZP + 3.56) 472 473 // zpFactor to go from instrumental flux to Janskies 474 float zpFactor = pow(10.0, -0.4*zp + 3.56); 475 476 // need to put in AB mag factor to get to Janskies (or uJy?) 477 stackFluxPSF = zpFactor * catalog[Nc].measure[m].FluxPSF; 478 stackdFluxPSF = zpFactor * catalog[Nc].measure[m].dFluxPSF; 479 stackFluxKron = zpFactor * catalog[Nc].measure[m].FluxKron; 480 stackdFluxKron = zpFactor * catalog[Nc].measure[m].dFluxKron; 461 stackCenterIDmin = stackImageID; 462 stackCenterMeasureMin = m; 481 463 } 482 464 } … … 619 601 620 602 if (haveStack) { 621 catalog[Nc].secfilt[Nsecfilt*j+Nsec].FluxPSF = stackFluxPSF; 622 catalog[Nc].secfilt[Nsecfilt*j+Nsec].dFluxPSF = stackdFluxPSF; 623 catalog[Nc].secfilt[Nsecfilt*j+Nsec].FluxKron = stackFluxKron; 624 catalog[Nc].secfilt[Nsecfilt*j+Nsec].dFluxKron = stackdFluxKron; 625 catalog[Nc].secfilt[Nsecfilt*j+Nsec].stackID = stackImageIDmin; 603 m = (stackPrimaryMeasureMin >= 0) ? stackPrimaryMeasureMin : stackCenterMeasureMin; 604 ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin : stackCenterIDmin; 605 606 // get the zero point for the selected image 607 float zp = Mcal + Mmos + Mgrid + PhotZeroPoint (&catalog[Nc].measure[m], &catalog[Nc].average[j], &catalog[Nc].secfilt[j*Nsecfilt]); 608 609 // flux_cgs : erg sec^1 cm^-2 Hz^-1 610 // mag_inst : -2.5 log (cts/sec) 611 // mag_inst : -2.5 log (flux_inst) 612 // flux_inst = ten(-0.4*mag_inst) 613 614 // mag_AB = -2.5 log (flux_cgs) - 48.6 (~by definition) [~Vega flux in V-band] 615 // flux_cgs = ten(-0.4*(mag_AB + 48.6)) 616 617 // flux_AB : ten(-0.4*mag_AB) 618 619 // flux_cgs = ten(-0.4*48.6) * flux_AB 620 // flux_AB = ten(+0.4*48.6) * flux_cgs 621 622 // flux_Jy : flux_cgs * 10^23 623 624 // flux_AB = ten(+0.4*48.6) * ten(-23) * flux_Jy 625 626 // mag_AB = mag_inst + ZP 627 628 // flux_inst = ten(-0.4*(mag_AB - ZP)) = ten(0.4*ZP) * flux_AB 629 630 // flux_AB = flux_inst * ten(-0.4*ZP) 631 632 // flux_inst * ten(-0.4*ZP) = ten(+0.4*48.6 - 23) * flux_Jy 633 634 // flux_inst = flux_Jy * ten(0.4*ZP + 0.4*48.6 - 23) 635 // flux_inst = flux_Jy * ten(0.4*ZP - 3.56) 636 // flux_Jy = flux_inst * ten(-0.4*ZP + 3.56) 637 638 // zpFactor to go from instrumental flux to Janskies 639 float zpFactor = pow(10.0, -0.4*zp + 3.56); 640 641 // need to put in AB mag factor to get to Janskies (or uJy?) 642 catalog[Nc].secfilt[Nsecfilt*j+Nsec].FluxPSF = zpFactor * catalog[Nc].measure[m].FluxPSF; 643 catalog[Nc].secfilt[Nsecfilt*j+Nsec].dFluxPSF = zpFactor * catalog[Nc].measure[m].dFluxPSF; 644 catalog[Nc].secfilt[Nsecfilt*j+Nsec].FluxKron = zpFactor * catalog[Nc].measure[m].FluxKron; 645 catalog[Nc].secfilt[Nsecfilt*j+Nsec].dFluxKron = zpFactor * catalog[Nc].measure[m].dFluxKron; 646 647 catalog[Nc].secfilt[Nsecfilt*j+Nsec].stackID = ID; 626 648 } 627 649 … … 680 702 } 681 703 } 704 if (primaryCell) free (primaryCell); 682 705 return (TRUE); 683 706 } -
branches/eam_branches/ipp-20120627/Ohana/src/relphot/src/args.c
r33963 r34210 197 197 } 198 198 199 if ((N = get_argument (argc, argv, "-boundary-tree"))) { 200 remove_argument (N, &argc, argv); 201 load_tree (argv[N]); 202 remove_argument (N, &argc, argv); 203 } 204 199 205 SHOW_PARAMS = FALSE; 200 206 if ((N = get_argument (argc, argv, "-params"))) {
Note:
See TracChangeset
for help on using the changeset viewer.
