int plot_radec_plot(const char* command, cairo_t* cairo, plot_args_t* pargs, void* baton) { plotradec_t* args = (plotradec_t*)baton; // Plot it! rd_t myrd; rd_t* rd = NULL; //rd_t* freerd = NULL; int Nrd; int i; if (!pargs->wcs) { ERROR("plotting radec but not plot_wcs has been set."); return -1; } if (args->fn && dl_size(args->radecvals)) { ERROR("Can only plot one of rdlist filename and radec_vals"); return -1; } if (!args->fn && !dl_size(args->radecvals)) { ERROR("Neither rdlist filename nor radec_vals given!"); return -1; } plotstuff_builtin_apply(cairo, pargs); rd = get_rd(args, &myrd); if (!rd) return -1; Nrd = rd_n(rd); // If N is specified, apply it as a max. if (args->nobjs) Nrd = MIN(Nrd, args->nobjs); // Plot markers. for (i=args->firstobj; i<Nrd; i++) { double x,y; double ra = rd_getra(rd, i); double dec = rd_getdec(rd, i); if (!plotstuff_radec2xy(pargs, ra, dec, &x, &y)) continue; if (!plotstuff_marker_in_bounds(pargs, x, y)) continue; plotstuff_stack_marker(pargs, x-1, y-1); } plotstuff_plot_stack(pargs, cairo); if (rd != &myrd) rd_free(rd); //rd_free(freerd); return 0; }
static void plot_hd(cairo_t* cairo, plot_args_t* pargs, plotann_t* ann) { int i, N; hd_catalog_t* hdcat = NULL; double ra,dec,rad; bl* hdlist = NULL; if (!ann->hd_catalog) return; hdcat = henry_draper_open(ann->hd_catalog); if (!hdcat) { ERROR("Failed to open Henry Draper catalog file \"%s\"", ann->hd_catalog); return; } if (plotstuff_get_radec_center_and_radius(pargs, &ra, &dec, &rad)) { ERROR("Failed to get RA,Dec,radius from plotstuff"); return; } hdlist = henry_draper_get(hdcat, ra, dec, deg2arcsec(rad)); logverb("Got %zu Henry Draper stars\n", bl_size(hdlist)); N = bl_size(hdlist); for (i=0; i<N; i++) { hd_entry_t* entry = bl_access(hdlist, i); double px, py; char label[16]; if (!plotstuff_radec2xy(pargs, entry->ra, entry->dec, &px, &py)) continue; px -= 1; py -= 1; if (px < 1 || py < 1 || px > pargs->W || py > pargs->H) continue; logverb("HD %i at RA,Dec (%g,%g) -> xy (%g, %g)\n", entry->hd, entry->ra, entry->dec, px, py); plotstuff_stack_marker(pargs, px, py); if (ann->HD_labels) { sprintf(label, "HD %i", entry->hd); plotstuff_stack_text(pargs, cairo, label, px, py); } } bl_free(hdlist); henry_draper_close(hdcat); }
static void plot_brightstars(cairo_t* cairo, plot_args_t* pargs, plotann_t* ann) { int i, N; // Get plot center, to use in trimming bright stars double rc,dc,radius; plotstuff_get_radec_center_and_radius(pargs, &rc, &dc, &radius); N = bright_stars_n(); for (i=0; i<N; i++) { double px, py; char* label; const brightstar_t* bs = bright_stars_get(i); // skip unnamed if (!strlen(bs->name) && !strlen(bs->common_name)) continue; // skip stars too far away if (deg_between_radecdeg(rc, dc, bs->ra, bs->dec) > radius * 1.2) continue; if (!plotstuff_radec2xy(pargs, bs->ra, bs->dec, &px, &py)) continue; logverb("Bright star %s/%s at RA,Dec (%g,%g) -> xy (%g, %g)\n", bs->name, bs->common_name, bs->ra, bs->dec, px, py); if (px < 1 || py < 1 || px > pargs->W || py > pargs->H) continue; px -= 1; py -= 1; if (ann->bright_pastel) { float r,g,b; color_for_radec(bs->ra, bs->dec, &r,&g,&b); plotstuff_set_rgba2(pargs, r,g,b, 0.8); plotstuff_builtin_apply(cairo, pargs); } plotstuff_stack_marker(pargs, px, py); if (ann->bright_labels) { label = (strlen(bs->common_name) ? bs->common_name : bs->name); plotstuff_stack_text(pargs, cairo, label, px, py); } } }
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 void plot_targets(cairo_t* cairo, plot_args_t* pargs, plotann_t* ann) { int i; double cra, cdec; plotstuff_get_radec_center_and_radius(pargs, &cra, &cdec, NULL); for (i=0; i<bl_size(ann->targets); i++) { target_t* tar = bl_access(ann->targets, i); double px,py; double cx,cy; double dx,dy, r; double ex,ey; double ly, ry, tx, bx; double distdeg; anbool okquadrant; char* txt; logverb("Target: \"%s\" at (%g,%g)\n", tar->name, tar->ra, tar->dec); okquadrant = plotstuff_radec2xy(pargs, tar->ra, tar->dec, &px, &py); px -= 1; py -= 1; if (okquadrant && px >= 0 && px < pargs->W && py >= 0 && py < pargs->H) { // inside the image! logverb("Target \"%s\" is inside the image, at pixel (%g,%g)\n", tar->name, px, py); plotstuff_stack_marker(pargs, px, py); plotstuff_stack_text(pargs, cairo, tar->name, px, py); continue; } // outside the image: find intersection point. cx = pargs->W / 2.0; cy = pargs->H / 2.0; if (okquadrant) { logverb("Target \"%s\" is outside the image, at pixel (%g,%g)\n", tar->name, px, py); dx = px - cx; dy = py - cy; } else { double cxyz[3]; double txyz[3]; double vec[3]; int j; double ra,dec; logverb("Target \"%s\" is way outside the image.\n", tar->name); // fallback. radecdeg2xyzarr(cra, cdec, cxyz); radecdeg2xyzarr(tar->ra, tar->dec, txyz); for (j=0; j<3; j++) vec[j] = cxyz[j] + 0.1 * txyz[j]; normalize_3(vec); xyzarr2radecdeg(vec, &ra, &dec); okquadrant = plotstuff_radec2xy(pargs, ra, dec, &px, &py); assert(okquadrant); dx = px - cx; dy = py - cy; if ((dx*dx + dy*dy) < (cx*cx + cy*cy)) { double scale = 3.0 * sqrt(cx*cx + cy*cy) / sqrt(dx*dx + dy*dy); dx *= scale; dy *= scale; } } ly = (-(pargs->W/2.0) / dx) * dy + cy; ry = ( (pargs->W/2.0) / dx) * dy + cy; bx = (-(pargs->H/2.0) / dy) * dx + cx; tx = ( (pargs->H/2.0) / dy) * dx + cx; logverb("ly %g, ry %g, bx %g, tx %g\n", ly, ry, bx, tx); if (px < cx && ly >= 0 && ly < pargs->H) { ex = 0.0; ey = ly; } else if (px >= cx && ry >= 0 && ry < pargs->H) { ex = pargs->W - 1; ey = ry; } else if (py < cy && bx >= 0 && bx < pargs->W) { ex = bx; ey = 0; } else if (py >= cy && tx >= 0 && tx < pargs->W) { ex = tx; ey = pargs->H - 1; } else { logverb("None of the edges are in bounds: px,py=(%g,%g); ly=%g, ry=%g, bx=%g, tx=%g\n", px,py,ly,ry,bx,tx); continue; } dx = ex - cx; dy = ey - cy; r = sqrt(dx*dx + dy*dy); px = (r-100.0) / r * dx + cx; py = (r-100.0) / r * dy + cy; plotstuff_stack_arrow(pargs, px, py, ex, ey); logverb("Arrow from (%g,%g) to (%g,%g)\n", px, py, ex, ey); distdeg = deg_between_radecdeg(cra, cdec, tar->ra, tar->dec); asprintf_safe(&txt, "%s: %.1f deg", tar->name, distdeg); plotstuff_stack_text(pargs, cairo, txt, px, py); } }
static void plot_ngc(cairo_t* cairo, plot_args_t* pargs, plotann_t* ann) { double imscale; double imsize; int i, N; // arcsec/pixel imscale = plotstuff_pixel_scale(pargs); // arcmin imsize = imscale * MIN(pargs->W, pargs->H) / 60.0; N = ngc_num_entries(); logverb("Checking %i NGC/IC objects.\n", N); for (i=0; i<N; i++) { ngc_entry* ngc; char* names; double pixrad; double px, py; double r; ngc = ngc_get_entry_accurate(i); if (!ngc) break; if (ngc->size < imsize * ann->ngc_fraction) { // FIXME -- just plot an X-mark with label. debug("%s %i: size %g arcmin < limit of %g\n", (ngc->is_ngc ? "NGC":"IC"), ngc->id, ngc->size, imsize*ann->ngc_fraction); continue; } if (!plotstuff_radec2xy(pargs, ngc->ra, ngc->dec, &px, &py)) { debug("%s %i: RA,Dec (%.1f,%.1f) is >90 deg away.\n", (ngc->is_ngc ? "NGC":"IC"), ngc->id, ngc->ra, ngc->dec); continue; } px -= 1; py -= 1; pixrad = 0.5 * ngc->size * 60.0 / imscale; if (px < -pixrad || py < -pixrad || px > pargs->W + pixrad || py > pargs->H + pixrad) { debug("%s %i: RA,Dec (%.1f,%.1f), pix (%.1f,%.1f) is out-of-bounds\n", (ngc->is_ngc ? "NGC":"IC"), ngc->id, ngc->ra, ngc->dec, px, py); continue; } names = ngc_get_name_list(ngc, " / "); printf("%s\n", names); logverb("%s %i: RA,Dec (%.1f,%.1f), size %g arcmin, pix (%.1f,%.1f), radius %g\n", (ngc->is_ngc ? "NGC":"IC"), ngc->id, ngc->ra, ngc->dec, ngc->size, px, py, pixrad); debug("size: %f arcsec, pix radius: %f pixels\n", ngc->size, pixrad); // save old marker size... r = pargs->markersize; pargs->markersize = pixrad; plotstuff_stack_marker(pargs, px, py); plotstuff_stack_text(pargs, cairo, names, px, py); free(names); // revert old marker size... pargs->markersize = r; /* if (json) { char* namelist = sl_implode(names, "\", \""); sl_appendf(json, "{ \"type\" : \"ngc\", " " \"names\" : [ \"%s\" ], " " \"pixelx\" : %g, " " \"pixely\" : %g, " " \"radius\" : %g }" , namelist, px, py, pixsize/2.0); free(namelist); } */ } }