コード例 #1
0
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;
}
コード例 #2
0
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);
        }
	}
}
コード例 #3
0
int plot_annotations_plot(const char* cmd, cairo_t* cairo,
							 plot_args_t* pargs, void* baton) {
	plotann_t* ann = (plotann_t*)baton;

	// Set fonts, etc, before calling plotting routines
	plotstuff_builtin_apply(cairo, pargs);

	if (ann->NGC)
		plot_ngc(cairo, pargs, ann);

	if (ann->bright)
		plot_brightstars(cairo, pargs, ann);

	if (ann->HD)
		plot_hd(cairo, pargs, ann);

	if (ann->constellations)
		plot_constellations(cairo, pargs, ann);

	if (bl_size(ann->targets))
		plot_targets(cairo, pargs, ann);

	return plotstuff_plot_stack(pargs, cairo);
}
コード例 #4
0
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;
}
コード例 #5
0
ファイル: plothealpix.c プロジェクト: Carl4/astrometry.net
int plot_healpix_plot(const char* command,
					  cairo_t* cairo, plot_args_t* pargs, void* baton) {
	plothealpix_t* args = (plothealpix_t*)baton;
	double ra,dec,rad;
	il* hps;
	int i;
	double hpstep;
	int minx[12], maxx[12], miny[12], maxy[12];

	plotstuff_builtin_apply(cairo, pargs);

	if (plotstuff_get_radec_center_and_radius(pargs, &ra, &dec, &rad)) {
		ERROR("Failed to get RA,Dec center and radius");
		return -1;
	}
	hps = healpix_rangesearch_radec(ra, dec, rad, args->nside, NULL);
	logmsg("Found %zu healpixes in range.\n", il_size(hps));
	hpstep = args->nside * args->stepsize * plotstuff_pixel_scale(pargs) / 60.0 / healpix_side_length_arcmin(args->nside);
	hpstep = MIN(1, hpstep);
	logmsg("Taking steps of %g in healpix space\n", hpstep);

	// For each of the 12 top-level healpixes, find the range of healpixes covered by this image.
	for (i=0; i<12; i++) {
		maxx[i] = maxy[i] = -1;
		minx[i] = miny[i] = args->nside+1;
	}
	for (i=0; i<il_size(hps); i++) {
		int hp = il_get(hps, i);
		int hpx, hpy;
		int bighp;
		healpix_decompose_xy(hp, &bighp, &hpx, &hpy, args->nside);
		logverb("  hp %i: bighp %i, x,y (%i,%i)\n", i, bighp, hpx, hpy);
		minx[bighp] = MIN(minx[bighp], hpx);
		maxx[bighp] = MAX(maxx[bighp], hpx);
		miny[bighp] = MIN(miny[bighp], hpy);
		maxy[bighp] = MAX(maxy[bighp], hpy);
	}
	il_free(hps);

	for (i=0; i<12; i++) {
		int hx,hy;
		int hp;
		double d, frac;
		double x,y;

		if (maxx[i] == -1)
			continue;
		logverb("Big healpix %i: x range [%i, %i], y range [%i, %i]\n",
			   i, minx[i], maxx[i], miny[i], maxy[i]);

		for (hy = miny[i]; hy <= maxy[i]; hy++) {
			logverb("  y=%i\n", hy);
			for (d=minx[i]; d<=maxx[i]; d+=hpstep) {
				hx = floor(d);
				frac = d - hx;
				hp = healpix_compose_xy(i, hx, hy, args->nside);
				healpix_to_radecdeg(hp, args->nside, frac, 0.0, &ra, &dec);
				if (!plotstuff_radec2xy(pargs, ra, dec, &x, &y))
					continue;
				if (d == minx[i])
					cairo_move_to(pargs->cairo, x, y);
				else
					cairo_line_to(pargs->cairo, x, y);
			}
			cairo_stroke(pargs->cairo);
		}
		for (hx = minx[i]; hx <= maxx[i]; hx++) {
			for (d=miny[i]; d<=maxy[i]; d+=hpstep) {
				hy = floor(d);
				frac = d - hy;
				hp = healpix_compose_xy(i, hx, hy, args->nside);
				healpix_to_radecdeg(hp, args->nside, 0.0, frac, &ra, &dec);
				if (!plotstuff_radec2xy(pargs, ra, dec, &x, &y))
					continue;
				if (d == miny[i])
					cairo_move_to(pargs->cairo, x, y);
				else
					cairo_line_to(pargs->cairo, x, y);
			}
			cairo_stroke(pargs->cairo);
		}
	}
	return 0;
}
コード例 #6
0
ファイル: plotxy.c プロジェクト: HarvardPHATSY/astrometry.net
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;
}
コード例 #7
0
int plot_fill_plot(const char* command,
					cairo_t* cairo, plot_args_t* pargs, void* baton) {
	plotstuff_builtin_apply(cairo, pargs);
	cairo_paint(cairo);
	return 0;
}
コード例 #8
0
static void plot_constellations(cairo_t* cairo, plot_args_t* pargs, plotann_t* ann) {
	int i, N;
	double ra,dec,radius;
	double xyzf[3];
	// Find the field center and radius
	anwcs_get_radec_center_and_radius(pargs->wcs, &ra, &dec, &radius);
	logverb("Plotting constellations: field center %g,%g, radius %g\n",
			ra, dec, radius);
	radecdeg2xyzarr(ra, dec, xyzf);
	radius = deg2dist(radius);

	N = constellations_n();
	for (i=0; i<N; i++) {
		int j, k;
		// Find the approximate center and radius of this constellation
		// and see if it overlaps with the field.
		il* stars = constellations_get_unique_stars(i);
		double xyzj[3];
		double xyzc[3];
		double maxr2 = 0;
		dl* rds;
		xyzc[0] = xyzc[1] = xyzc[2] = 0.0;
		xyzj[0] = xyzj[1] = xyzj[2] = 0.0;
		for (j=0; j<il_size(stars); j++) {
			constellations_get_star_radec(il_get(stars, j), &ra, &dec);
			radecdeg2xyzarr(ra, dec, xyzj);
			for (k=0; k<3; k++)
				xyzc[k] += xyzj[k];
		}
		normalize_3(xyzc);
		for (j=0; j<il_size(stars); j++) {
			constellations_get_star_radec(il_get(stars, j), &ra, &dec);
			maxr2 = MAX(maxr2, distsq(xyzc, xyzj, 3));
		}
		il_free(stars);
		maxr2 = square(sqrt(maxr2) + radius);
		if (distsq(xyzf, xyzc, 3) > maxr2) {
			xyzarr2radecdeg(xyzc, &ra, &dec);
			logverb("Constellation %s (center %g,%g, radius %g) out of bounds\n",
					constellations_get_shortname(i), ra, dec,
					dist2deg(sqrt(maxr2) - radius));
			logverb("  dist from field center to constellation center is %g deg\n",
					distsq2deg(distsq(xyzf, xyzc, 3)));
			logverb("  max radius: %g\n", distsq2deg(maxr2));
			continue;
		}

        if (ann->constellation_pastel) {
            float r,g,b;
            xyzarr2radecdeg(xyzc, &ra, &dec);
            color_for_radec(ra, dec, &r,&g,&b);
            plotstuff_set_rgba2(pargs, r,g,b, 0.8);
            plotstuff_builtin_apply(cairo, pargs);
        }

		// Phew, plot it.
		if (ann->constellation_lines) {
			rds = constellations_get_lines_radec(i);
			logverb("Constellation %s: plotting %zu lines\n",
					constellations_get_shortname(i), dl_size(rds)/4);
			for (j=0; j<dl_size(rds)/4; j++) {
				double r1,d1,r2,d2;
				double r3,d3,r4,d4;
                double off = ann->constellation_lines_offset;
				r1 = dl_get(rds, j*4+0);
				d1 = dl_get(rds, j*4+1);
				r2 = dl_get(rds, j*4+2);
				d2 = dl_get(rds, j*4+3);
				if (anwcs_find_discontinuity(pargs->wcs, r1, d1, r2, d2,
											 &r3, &d3, &r4, &d4)) {
					logverb("Discontinuous: %g,%g -- %g,%g\n", r1, d1, r2, d2);
					logverb("  %g,%g == %g,%g\n", r3,d3, r4,d4);
                    plot_offset_line_rd(NULL, pargs, r1,d1,r3,d3, off, 0.);
                    plot_offset_line_rd(NULL, pargs, r4,d4,r2,d2, 0., off);
				} else {
                    plot_offset_line_rd(NULL, pargs, r1,d1,r2,d2, off, off);
				}
				plotstuff_stroke(pargs);
			}
			dl_free(rds);
		}

		if (ann->constellation_labels ||
			ann->constellation_markers) {
			// Put the label at the center of mass of the stars that
			// are in-bounds
			int Nin = 0;
			stars = constellations_get_unique_stars(i);
			xyzc[0] = xyzc[1] = xyzc[2] = 0.0;
			logverb("Labeling %s: %zu stars\n", constellations_get_shortname(i),
					il_size(stars));
			for (j=0; j<il_size(stars); j++) {
				constellations_get_star_radec(il_get(stars, j), &ra, &dec);
				if (!anwcs_radec_is_inside_image(pargs->wcs, ra, dec))
					continue;
				if (ann->constellation_markers)
					plotstuff_marker_radec(pargs, ra, dec);
				radecdeg2xyzarr(ra, dec, xyzj);
				for (k=0; k<3; k++)
					xyzc[k] += xyzj[k];
				Nin++;
			}
			logverb("  %i stars in-bounds\n", Nin);
			if (ann->constellation_labels && Nin) {
				const char* label;
				normalize_3(xyzc);
				xyzarr2radecdeg(xyzc, &ra, &dec);
				if (ann->constellation_labels_long)
					label = constellations_get_longname(i);
				else
					label = constellations_get_shortname(i);
				plotstuff_text_radec(pargs, ra, dec, label);
			}
			il_free(stars);
		}
	}
}
コード例 #9
0
ファイル: plotstuff.c プロジェクト: barentsen/astrometry.net
static int plot_builtin_command(const char* cmd, const char* cmdargs,
								plot_args_t* pargs, void* baton) {
	if (streq(cmd, "plot_color")) {
		if (parse_color_rgba(cmdargs, pargs->rgba)) {
			ERROR("Failed to parse plot_color: \"%s\"", cmdargs);
			return -1;
		}
	} else if (streq(cmd, "plot_bgcolor")) {
		if (parse_color_rgba(cmdargs, pargs->bg_rgba)) {
			ERROR("Failed to parse plot_bgcolor: \"%s\"", cmdargs);
			return -1;
		}
	} else if (streq(cmd, "plot_fontsize")) {
		pargs->fontsize = atof(cmdargs);
	} else if (streq(cmd, "plot_alpha")) {
		if (plotstuff_set_alpha(pargs, atof(cmdargs))) {
			ERROR("Failed to set alpha");
			return -1;
		}
	} else if (streq(cmd, "plot_op")) {
		if (streq(cmdargs, "add")) {
			pargs->op = CAIRO_OPERATOR_ADD;
		} else if (streq(cmdargs, "reset")) {
			pargs->op = CAIRO_OPERATOR_OVER;
		} else {
			ERROR("Didn't understand op: %s", cmdargs);
			return -1;
		}
	} else if (streq(cmd, "plot_lw")) {
		pargs->lw = atof(cmdargs);
	} else if (streq(cmd, "plot_bglw")) {
		pargs->bg_lw = atof(cmdargs);
	} else if (streq(cmd, "plot_marker")) {
		if (plotstuff_set_marker(pargs, cmdargs)) {
			return -1;
		}
	} else if (streq(cmd, "plot_markersize")) {
		pargs->markersize = atof(cmdargs);
	} else if (streq(cmd, "plot_size")) {
		int W, H;
		if (sscanf(cmdargs, "%i %i", &W, &H) != 2) {
			ERROR("Failed to parse plot_size args \"%s\"", cmdargs);
			return -1;
		}
		plotstuff_set_size(pargs, W, H);
	} else if (streq(cmd, "plot_wcs")) {
		if (plotstuff_set_wcs_file(pargs, cmdargs, 0)) {
			return -1;
		}
	} else if (streq(cmd, "plot_wcs_box")) {
		float ra, dec, width;
		if (sscanf(cmdargs, "%f %f %f", &ra, &dec, &width) != 3) {
			ERROR("Failed to parse plot_wcs_box args \"%s\"", cmdargs);
			return -1;
		}
		if (plotstuff_set_wcs_box(pargs, ra, dec, width)) {
			return -1;
		}
	} else if (streq(cmd, "plot_wcs_setsize")) {
		assert(pargs->wcs);
		plotstuff_set_size_wcs(pargs);
	} else if (streq(cmd, "plot_label_radec")) {
		assert(pargs->wcs);
		double ra, dec;
		int nc;
		const char* label;
		if (sscanf(cmdargs, "%lf %lf %n", &ra, &dec, &nc) != 3) {
			ERROR("Failed to parse plot_label_radec args \"%s\"", cmdargs);
			return -1;
		}
		label = cmdargs + nc;
		return plotstuff_text_radec(pargs, ra, dec, label);
	} else {
		ERROR("Did not understand command: \"%s\"", cmd);
		return -1;
	}
	if (pargs->cairo)
		plotstuff_builtin_apply(pargs->cairo, pargs);
	return 0;
}
コード例 #10
0
ファイル: plotstuff.c プロジェクト: barentsen/astrometry.net
static int plot_builtin_init2(plot_args_t* pargs, void* baton) {
	plotstuff_builtin_apply(pargs->cairo, pargs);
	// Inits that aren't in "plot_builtin"
	cairo_set_antialias(pargs->cairo, CAIRO_ANTIALIAS_GRAY);
	return 0;
}
コード例 #11
0
ファイル: plotstuff.c プロジェクト: barentsen/astrometry.net
int plotstuff_move_to_radec(plot_args_t* pargs, double ra, double dec) {
	assert(pargs->cairo);
	plotstuff_builtin_apply(pargs->cairo, pargs);
	return moveto_lineto_radec(pargs, ra, dec, TRUE);
}