Exemple #1
0
void startree_search_for_radec(const startree_t* s, double ra, double dec, double radius,
							   double** xyzresults, double** radecresults,
							   int** starinds, int* nresults) {
	double xyz[3];
	double r2;
	radecdeg2xyzarr(ra, dec, xyz);
	r2 = deg2distsq(radius);
	startree_search_for(s, xyz, r2, xyzresults, radecresults, starinds, nresults);
}
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;
}
Exemple #3
0
void startree_search(const startree_t* s, const double* xyzcenter, double radius2,
                     double** xyzresults, double** radecresults, int* nresults) {
	startree_search_for(s, xyzcenter, radius2, xyzresults, radecresults, NULL, nresults);
}
int allquads_create_quads(allquads_t* aq) {
	quadbuilder_t* qb;
	int i, N;
	double* xyz;

	qb = quadbuilder_init();

	qb->quadd2_high = aq->quad_d2_upper;
	qb->quadd2_low  = aq->quad_d2_lower;
	qb->check_scale_high = aq->use_d2_upper;
	qb->check_scale_low  = aq->use_d2_lower;

	qb->dimquads = aq->dimquads;
	qb->add_quad = add_quad;
	qb->add_quad_token = aq;

	N = startree_N(aq->starkd);

	if (!qb->check_scale_high) {
		int* inds;
		inds = malloc(N * sizeof(int));
		for (i=0; i<N; i++)
			inds[i] = i;
		xyz = malloc(3 * N * sizeof(double));
		kdtree_copy_data_double(aq->starkd->tree, 0, N, xyz);

		qb->starxyz = xyz;
		qb->starinds = inds;
		qb->Nstars = N;

		quadbuilder_create(qb);

		free(xyz);
		free(inds);
	} else {
		int nq;
		int lastgrass = 0;

		/*
		 xyz = malloc(3 * N * sizeof(double));
		 kdtree_copy_data_double(aq->starkd->tree, 0, N, xyz);
		 */

		// star A = i
		nq = aq->quads->numquads;
		for (i=0; i<N; i++) {
			double xyzA[3];
			int* inds;
			int NR;

			int grass = (i*80 / N);
			if (grass != lastgrass) {
				printf(".");
				fflush(stdout);
				lastgrass = grass;
			}

			startree_get(aq->starkd, i, xyzA);

			startree_search_for(aq->starkd, xyzA, aq->quad_d2_upper,
								&xyz, NULL, &inds, &NR);

			/*
			 startree_search_for(aq->starkd, xyzA, aq->quad_d2_upper,
			 NULL, NULL, &inds, &NR);
			 */

			logverb("Star %i of %i: found %i stars in range\n", i+1, N, NR);
			aq->starA = i;
			qb->starxyz = xyz;
			qb->starinds = inds;
			qb->Nstars = NR;
			qb->check_AB_stars = check_AB;
			qb->check_AB_stars_token = aq;
			//qb->check_full_quad = check_full_quad;
			//qb->check_full_quad_token = aq;

			quadbuilder_create(qb);

			logverb("Star %i of %i: wrote %i quads for this star, total %i so far.\n", i+1, N, aq->quads->numquads - nq, aq->quads->numquads);
			free(inds);
			free(xyz);
		}
		//
		//free(xyz);

		printf("\n");
	}

	quadbuilder_free(qb);
	return 0;
}