/** fitscopy ~/DATA/tycho2-cut.fits"[RA<10 && DEC > 0 && DEC < 10]" t.fits build-index -i t.fits -o t10.index -P 10 -E -M -v -S mag build-index -1 t10.index -o t11.index -P 11 -E -M -v -S mag build-index -1 t10.index -o t12.index -P 12 -E -M -v -S mag fitsgetext -i t10.index -o t10.skdt -e 0 -e 7 -e 8 -e 9 -e 10 -e 11 -e 12 -e 13 fitsgetext -i t10.index -o t10.ind -e 0 -e 1 -e 2 -e 3 -e 4 -e 5 -e 6 fitsgetext -i t11.index -o t11.ind -e 0 -e 1 -e 2 -e 3 -e 4 -e 5 -e 6 fitsgetext -i t12.index -o t12.ind -e 0 -e 1 -e 2 -e 3 -e 4 -e 5 -e 6 */ void test_multiindex(CuTest* ct) { sl* fns; multiindex_t* mi; int i; fns = sl_new(4); sl_append(fns, "t10.ind"); sl_append(fns, "t11.ind"); sl_append(fns, "t12.ind"); mi = multiindex_open("t10.skdt", fns); printf("Got %i indices\n", multiindex_n(mi)); for (i=0; i<multiindex_n(mi); i++) { index_t* ind = multiindex_get(mi, i); printf(" %i: %s, %i stars, %i quads (%g to %g arcmin)\n", i, ind->indexname, index_nquads(ind), index_nstars(ind), ind->index_scale_lower/60., ind->index_scale_upper/60.); } multiindex_free(mi); sl_free2(fns); }
int plot_index_plot(const char* command, cairo_t* cairo, plot_args_t* pargs, void* baton) { plotindex_t* args = (plotindex_t*)baton; int i; double ra, dec, radius; double xyz[3]; double r2; pad_qidxes(args); plotstuff_builtin_apply(cairo, pargs); if (plotstuff_get_radec_center_and_radius(pargs, &ra, &dec, &radius)) { ERROR("Failed to get RA,Dec center and radius"); return -1; } radecdeg2xyzarr(ra, dec, xyz); r2 = deg2distsq(radius); logmsg("Field RA,Dec,radius = (%g,%g), %g deg\n", ra, dec, radius); logmsg("distsq: %g\n", r2); for (i=0; i<pl_size(args->indexes); i++) { index_t* index = pl_get(args->indexes, i); int j, N; int DQ; double px,py; if (args->stars) { // plot stars double* radecs = NULL; startree_search_for(index->starkd, xyz, r2, NULL, &radecs, NULL, &N); if (N) { assert(radecs); } logmsg("Found %i stars in range in index %s\n", N, index->indexname); for (j=0; j<N; j++) { logverb(" RA,Dec (%g,%g) -> x,y (%g,%g)\n", radecs[2*j], radecs[2*j+1], px, py); if (!plotstuff_radec2xy(pargs, radecs[j*2], radecs[j*2+1], &px, &py)) { ERROR("Failed to convert RA,Dec %g,%g to pixels\n", radecs[j*2], radecs[j*2+1]); continue; } cairoutils_draw_marker(cairo, pargs->marker, px, py, pargs->markersize); cairo_stroke(cairo); } free(radecs); } if (args->quads) { DQ = index_get_quad_dim(index); qidxfile* qidx = pl_get(args->qidxes, i); if (qidx) { int* stars; int Nstars; il* quadlist = il_new(256); // find stars in range. startree_search_for(index->starkd, xyz, r2, NULL, NULL, &stars, &Nstars); logmsg("Found %i stars in range of index %s\n", N, index->indexname); logmsg("Using qidx file.\n"); // find quads that each star is a member of. for (j=0; j<Nstars; j++) { uint32_t* quads; int Nquads; int k; if (qidxfile_get_quads(qidx, stars[j], &quads, &Nquads)) { ERROR("Failed to get quads for star %i\n", stars[j]); return -1; } for (k=0; k<Nquads; k++) il_insert_unique_ascending(quadlist, quads[k]); } for (j=0; j<il_size(quadlist); j++) { plotquad(cairo, pargs, args, index, il_get(quadlist, j), DQ); } } else { // plot quads N = index_nquads(index); for (j=0; j<N; j++) { plotquad(cairo, pargs, args, index, j, DQ); } } } } return 0; }
void test_solve_multiindex(CuTest* ct) { sl* fns; multiindex_t* mi; int i; solver_t* s = NULL; starxy_t* field = NULL; MatchObj* mo = NULL; xylist_t* xy = NULL; log_init(LOG_VERB); fns = sl_new(4); sl_append(fns, "../util/t10.ind"); sl_append(fns, "../util/t11.ind"); sl_append(fns, "../util/t12.ind"); mi = multiindex_open("../util/t10.skdt", fns, 0); printf("Got %i indices\n", multiindex_n(mi)); for (i=0; i<multiindex_n(mi); i++) { index_t* ind = multiindex_get(mi, i); printf(" %i: %s, %i stars, %i quads (%g to %g arcmin)\n", i, ind->indexname, index_nquads(ind), index_nstars(ind), ind->index_scale_lower/60., ind->index_scale_upper/60.); } s = solver_new(); // 10.8 s->funits_lower = 5.0; s->funits_upper = 15.0; xy = xylist_open("../util/t1.xy"); if (!xy) { ERROR("Failed to open xylist\n"); CuFail(ct, "xylist"); } field = xylist_read_field(xy, NULL); solver_set_field(s, field); solver_set_field_bounds(s, 0, 1000, 0, 1000); for (i=0; i<multiindex_n(mi); i++) { index_t* ind = multiindex_get(mi, i); solver_add_index(s, ind); } solver_run(s); if (solver_did_solve(s)) { mo = solver_get_best_match(s); matchobj_print(mo, LOG_MSG); // HACK -- ugly!! verify_free_matchobj(mo); } xylist_close(xy); solver_cleanup_field(s); solver_free(s); multiindex_free(mi); sl_free2(fns); }
int main(int argc, char *argv[]) { int argchar; char* progname = argv[0]; index_t* index; fitstable_t* table; char* indexfn = NULL; char* outfn = NULL; int i, D, N; while ((argchar = getopt (argc, argv, OPTIONS)) != -1) { switch (argchar) { case 'i': indexfn = optarg; break; case 'o': outfn = optarg; break; default: case 'h': printHelp(progname); exit(0); } } if (!(indexfn && outfn)) { printHelp(progname); exit(-1); } index = index_load(indexfn, 0, NULL); if (!index) { ERROR("Failed to open index"); exit(-1); } table = fitstable_open_for_writing(outfn); if (!table) { ERROR("Failed to open output file for writing"); exit(-1); } D = index_get_quad_dim(index); fitstable_add_write_column_array(table, fitscolumn_i32_type(), D, "quads", ""); if (fitstable_write_primary_header(table) || fitstable_write_header(table)) { ERROR("Failed to write headers"); exit(-1); } N = index_nquads(index); for (i=0; i<N; i++) { unsigned int quad[D]; quadfile_get_stars(index->quads, i, quad); if (fitstable_write_row(table, quad)) { ERROR("Failed to write quad %i", i); exit(-1); } } if (fitstable_fix_header(table)) { ERROR("Failed to fix quad header"); exit(-1); } fitstable_next_extension(table); fitstable_clear_table(table); // write star RA,Dec s. fitstable_add_write_column(table, fitscolumn_double_type(), "RA", "deg"); fitstable_add_write_column(table, fitscolumn_double_type(), "Dec", "deg"); if (fitstable_write_header(table)) { ERROR("Failed to write star header"); exit(-1); } N = index_nstars(index); for (i=0; i<N; i++) { double xyz[3]; double ra, dec; startree_get(index->starkd, i, xyz); xyzarr2radecdeg(xyz, &ra, &dec); if (fitstable_write_row(table, &ra, &dec)) { ERROR("Failed to write star %i", i); exit(-1); } } if (fitstable_fix_header(table) || fitstable_close(table)) { ERROR("Failed to fix star header and close"); exit(-1); } index_close(index); return 0; }