int plot_xy_plot(const char* command, cairo_t* cairo, plot_args_t* pargs, void* baton) { plotxy_t* args = (plotxy_t*)baton; // Plot it! xylist_t* xyls; starxy_t myxy; starxy_t* xy = NULL; starxy_t* freexy = NULL; int Nxy; int i; #if 0 double t0; #endif plotstuff_builtin_apply(cairo, pargs); if (args->fn && dl_size(args->xyvals)) { ERROR("Can only plot one of xylist filename and xy_vals"); return -1; } if (!args->fn && !dl_size(args->xyvals)) { ERROR("Neither xylist filename nor xy_vals given!"); return -1; } if (args->fn) { #if 0 t0 = timenow(); #endif // Open xylist. xyls = xylist_open(args->fn); if (!xyls) { ERROR("Failed to open xylist from file \"%s\"", args->fn); return -1; } // we don't care about FLUX and BACKGROUND columns. xylist_set_include_flux(xyls, FALSE); xylist_set_include_background(xyls, FALSE); if (args->xcol) xylist_set_xname(xyls, args->xcol); if (args->ycol) xylist_set_yname(xyls, args->ycol); // Find number of entries in xylist. xy = xylist_read_field_num(xyls, args->ext, NULL); freexy = xy; xylist_close(xyls); if (!xy) { ERROR("Failed to read FITS extension %i from file %s.\n", args->ext, args->fn); return -1; } Nxy = starxy_n(xy); // If N is specified, apply it as a max. if (args->nobjs) Nxy = MIN(Nxy, args->nobjs); //logmsg("%g s to read xylist\n", timenow()-t0); } else { assert(dl_size(args->xyvals)); starxy_from_dl(&myxy, args->xyvals, FALSE, FALSE); xy = &myxy; Nxy = starxy_n(xy); } // Transform through WCSes. if (args->wcs) { double ra, dec, x, y; assert(pargs->wcs); /* // check for any overlap. double pralo,prahi,pdeclo,pdechi; double ralo,rahi,declo,dechi; anwcs_get_radec_bounds(pargs->wcs, 100, &pralo, &prahi, &pdeclo, &pdechi); anwcs_get_radec_bounds(args->wcs, 100, &ralo, &rahi, &declo, &dechi); if ( */ for (i=0; i<Nxy; i++) { anwcs_pixelxy2radec(args->wcs, // I used to add 1 here starxy_getx(xy, i), starxy_gety(xy, i), &ra, &dec); if (!plotstuff_radec2xy(pargs, ra, dec, &x, &y)) continue; logverb(" xy (%g,%g) -> RA,Dec (%g,%g) -> plot xy (%g,%g)\n", starxy_getx(xy,i), starxy_gety(xy,i), ra, dec, x, y); // add shift and scale... // FIXME -- not clear that we want to do this here... /* starxy_setx(xy, i, args->scale * (x - args->xoff)); starxy_sety(xy, i, args->scale * (y - args->yoff)); starxy_setx(xy, i, x-1); starxy_sety(xy, i, y-1); */ // Output coords: FITS -> 0-indexed image starxy_setx(xy, i, x-1); starxy_sety(xy, i, y-1); } } else { // Shift and scale xylist entries. if (args->xoff != 0.0 || args->yoff != 0.0) { for (i=0; i<Nxy; i++) { starxy_setx(xy, i, starxy_getx(xy, i) - args->xoff); starxy_sety(xy, i, starxy_gety(xy, i) - args->yoff); } } if (args->scale != 1.0) { for (i=0; i<Nxy; i++) { starxy_setx(xy, i, args->scale * starxy_getx(xy, i)); starxy_sety(xy, i, args->scale * starxy_gety(xy, i)); } } } // Plot markers. #if 0 t0 = timenow(); #endif for (i=args->firstobj; i<Nxy; i++) { double x = starxy_getx(xy, i); double y = starxy_gety(xy, i); if (plotstuff_marker_in_bounds(pargs, x, y)) plotstuff_stack_marker(pargs, x, y); } plotstuff_plot_stack(pargs, cairo); //logmsg("%g s to plot xylist\n", timenow()-t0); starxy_free(freexy); return 0; }
static sip_t* run_test(CuTest* tc, sip_t* sip, int N, double* xy, double* radec) { int i; starxy_t* sxy; tweak_t* t; sip_t* outsip; il* imcorr; il* refcorr; dl* weights; tan_t* tan = &(sip->wcstan); printf("Input SIP:\n"); sip_print_to(sip, stdout); fflush(NULL); sxy = starxy_new(N, FALSE, FALSE); starxy_set_xy_array(sxy, xy); imcorr = il_new(256); refcorr = il_new(256); weights = dl_new(256); for (i=0; i<N; i++) { il_append(imcorr, i); il_append(refcorr, i); dl_append(weights, 1.0); } t = tweak_new(); tweak_push_wcs_tan(t, tan); outsip = t->sip; outsip->a_order = outsip->b_order = sip->a_order; outsip->ap_order = outsip->bp_order = sip->ap_order; t->weighted_fit = TRUE; tweak_push_ref_ad_array(t, radec, N); tweak_push_image_xy(t, sxy); tweak_push_correspondence_indices(t, imcorr, refcorr, NULL, weights); tweak_skip_shift(t); // push correspondences // push image xy // push ref ra,dec // push ref xy (tan) // push tan tweak_go_to(t, TWEAK_HAS_LINEAR_CD); printf("Output SIP:\n"); sip_print_to(outsip, stdout); CuAssertDblEquals(tc, tan->imagew, outsip->wcstan.imagew, 1e-10); CuAssertDblEquals(tc, tan->imageh, outsip->wcstan.imageh, 1e-10); // should be exactly equal. CuAssertDblEquals(tc, tan->crpix[0], outsip->wcstan.crpix[0], 1e-10); CuAssertDblEquals(tc, tan->crpix[1], outsip->wcstan.crpix[1], 1e-10); t->sip = NULL; tweak_free(t); starxy_free(sxy); return outsip; }
// This runs after "astrometry-engine" is run on the file. static void after_solved(augment_xylist_t* axy, solve_field_args_t* sf, anbool makeplots, const char* me, anbool verbose, const char* tempdir, sl* tempdirs, sl* tempfiles, double plotscale, const char* bgfn) { sip_t wcs; double ra, dec, fieldw, fieldh; char rastr[32], decstr[32]; char* fieldunits; // print info about the field. logmsg("Field: %s\n", axy->imagefn ? axy->imagefn : axy->xylsfn); if (file_exists(axy->wcsfn)) { double orient; if (axy->wcs_last_mod) { time_t t = file_get_last_modified_time(axy->wcsfn); if (t == axy->wcs_last_mod) { logmsg("Warning: there was already a WCS file, and its timestamp has not changed.\n"); } } if (!sip_read_header_file(axy->wcsfn, &wcs)) { ERROR("Failed to read WCS header from file %s", axy->wcsfn); exit(-1); } sip_get_radec_center(&wcs, &ra, &dec); sip_get_radec_center_hms_string(&wcs, rastr, decstr); sip_get_field_size(&wcs, &fieldw, &fieldh, &fieldunits); orient = sip_get_orientation(&wcs); logmsg("Field center: (RA,Dec) = (%3.6f, %3.6f) deg.\n", ra, dec); logmsg("Field center: (RA H:M:S, Dec D:M:S) = (%s, %s).\n", rastr, decstr); logmsg("Field size: %g x %g %s\n", fieldw, fieldh, fieldunits); logmsg("Field rotation angle: up is %g degrees E of N\n", orient); } else { logmsg("Did not solve (or no WCS file was written).\n"); } // create new FITS file... if (axy->fitsimgfn && sf->newfitsfn && file_exists(axy->wcsfn)) { logmsg("Creating new FITS file \"%s\"...\n", sf->newfitsfn); if (new_wcs(axy->fitsimgfn, axy->wcsfn, sf->newfitsfn, TRUE)) { ERROR("Failed to create FITS image with new WCS headers"); exit(-1); } } // write list of index stars in image coordinates if (sf->indxylsfn && file_exists(axy->wcsfn) && file_exists(axy->rdlsfn)) { assert(axy->wcsfn); assert(axy->rdlsfn); // index rdls to xyls. if (wcs_rd2xy(axy->wcsfn, 0, axy->rdlsfn, sf->indxylsfn, NULL, NULL, FALSE, FALSE, NULL)) { ERROR("Failed to project index stars into field coordinates using wcs-rd2xy"); exit(-1); } } if (makeplots && file_exists(sf->indxylsfn) && file_readable(axy->matchfn) && file_readable(axy->wcsfn)) { logmsg("Creating index object overlay plot...\n"); if (plot_index_overlay(axy, me, sf->indxylsfn, sf->redgreenfn, plotscale, bgfn)) { ERROR("Plot index overlay failed."); } } if (makeplots && file_readable(axy->wcsfn)) { logmsg("Creating annotation plot...\n"); if (plot_annotations(axy, me, verbose, sf->ngcfn, plotscale, bgfn)) { ERROR("Plot annotations failed."); } } if (axy->imagefn && sf->kmzfn && file_exists(axy->wcsfn)) { logmsg("Writing kmz file...\n"); if (write_kmz(axy, sf->kmzfn, tempdir, tempdirs, tempfiles)) { ERROR("Failed to write KMZ."); exit(-1); } } if (sf->scampfn && file_exists(axy->wcsfn)) { //char* hdrfile = NULL; qfits_header* imageheader = NULL; starxy_t* xy; xylist_t* xyls; xyls = xylist_open(axy->axyfn); if (!xyls) { ERROR("Failed to read xylist to write SCAMP catalog"); exit(-1); } if (axy->xcol) xylist_set_xname(xyls, axy->xcol); if (axy->ycol) xylist_set_yname(xyls, axy->ycol); //xylist_set_include_flux(xyls, FALSE); xylist_set_include_background(xyls, FALSE); xy = xylist_read_field(xyls, NULL); xylist_close(xyls); if (axy->fitsimgfn) { //hdrfile = axy->fitsimgfn; imageheader = anqfits_get_header2(axy->fitsimgfn, 0); } if (axy->xylsfn) { char val[32]; //hdrfile = axy->xylsfn; imageheader = anqfits_get_header2(axy->xylsfn, 0); // Set NAXIS=2, NAXIS1=IMAGEW, NAXIS2=IMAGEH fits_header_mod_int(imageheader, "NAXIS", 2, NULL); sprintf(val, "%i", axy->W); qfits_header_add_after(imageheader, "NAXIS", "NAXIS1", val, "image width", NULL); sprintf(val, "%i", axy->H); qfits_header_add_after(imageheader, "NAXIS1", "NAXIS2", val, "image height", NULL); //fits_header_add_int(imageheader, "NAXIS1", axy->W, NULL); //fits_header_add_int(imageheader, "NAXIS2", axy->H, NULL); logverb("Using NAXIS 1,2 = %i,%i\n", axy->W, axy->H); } if (scamp_write_field(imageheader, &wcs, xy, sf->scampfn)) { ERROR("Failed to write SCAMP catalog"); exit(-1); } starxy_free(xy); if (imageheader) qfits_header_destroy(imageheader); } if (sf->scampconfigfn) { if (scamp_write_config_file(axy->scampfn, sf->scampconfigfn)) { ERROR("Failed to write SCAMP config file snippet to %s", sf->scampconfigfn); exit(-1); } } }