1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
/*
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
*/
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <assert.h>
#include "boilerplate.h"
#include "errors.h"
#include "log.h"
#include "build-index.h"
#include "wcs-xy2rd.h"
#include "rdlist.h"
#include "sip.h"
#include "sip_qfits.h"
#include "healpix.h"
const char* OPTIONS = "hvx:w:l:u:o:d:I:N:p:R:L:Mn:U:S:f:r:J:X:Y:";
static void print_help(char* progname) {
BOILERPLATE_HELP_HEADER(stdout);
printf("\nUsage: %s\n"
" -x <input-xylist> input: source positions; assumed sorted by brightness\n"
" -w <input-wcs> input: WCS file for sources\n"
" -o <output-index> output filename for index\n"
" [-X <x-column-name>]\n"
" [-Y <y-column-name>]\n"
" [-l <min-quad-size>]: minimum fraction of the image size (diagonal) to make quads (default 0.05)\n"
" [-u <max-quad-size>]: maximum fraction of the image size (diagonal) to make quads (default 1.0)\n"
" [-d <dimquads>] number of stars in a \"quad\" (default 4).\n"
" [-N <number of healpixels]: number of healpix grid cells to put in the image (default 10)\n"
" [-I <unique-id>] set the unique ID of this index\n"
" [-S]: sort column (default: assume already sorted)\n"
" [-f]: sort in descending order (eg, for FLUX); default ascending (eg, for MAG)\n"
" [-U]: healpix Nside for uniformization (default: same as -N)\n"
" [-n <sweeps>] (ie, number of stars per fine healpix grid cell); default 10\n"
" [-r <dedup-radius>]: deduplication radius in arcseconds; default no deduplication\n"
" [-p <passes>] number of rounds of quad-building (ie, # quads per healpix cell, default 16)\n"
" [-R <reuse-times>] number of times a star can be used (default 8).\n"
" [-L <max-reuses>] make extra passes through the healpixes, increasing the \"-r\" reuse (default 20)\n"
" limit each time, up to \"max-reuses\".\n"
" [-M]: in-memory (don't use temp files)\n"
" [-J <jitter-in-pixels>]: set positional error of index stars, in pixels (default 1)\n"
"\n"
" [-v]: add verbosity.\n"
"\n", progname);
}
int main(int argc, char** argv) {
int argchar;
char* xylsfn = NULL;
char* wcsfn = NULL;
char* indexfn = NULL;
double lowf = 0.1;
double highf = 1.0;
int loglvl = LOG_MSG;
int i;
int nhp = 10;
int Nside;
sl* tempfiles;
char* tempdir = "/tmp";
int wcsext = 0;
char* rdlsfn;
sip_t sip;
double diagpix, diag, pscale;
index_params_t myip;
index_params_t* ip = &myip;
double jitterpix = 1.0;
char* xcol = NULL;
char* ycol = NULL;
build_index_defaults(ip);
while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
switch (argchar) {
case 'X':
xcol = optarg;
break;
case 'Y':
ycol = optarg;
break;
case 'J':
jitterpix = atof(optarg);
break;
case 'L':
ip->Nloosen = atoi(optarg);
break;
case 'R':
ip->Nreuse = atoi(optarg);
break;
case 'p':
ip->passes = atoi(optarg);
break;
case 'M':
ip->inmemory = TRUE;
break;
case 'U':
ip->UNside = atoi(optarg);
break;
case 'S':
ip->sortcol = optarg;
break;
case 'f':
ip->sortasc = FALSE;
break;
case 'n':
ip->sweeps = atoi(optarg);
break;
case 'r':
ip->dedup = atof(optarg);
break;
case 'N':
nhp = atoi(optarg);
break;
case 'v':
loglvl++;
break;
case 'd':
ip->dimquads = atoi(optarg);
break;
case 'I':
ip->indexid = atoi(optarg);
break;
case 'h':
print_help(argv[0]);
exit(0);
case 'x':
xylsfn = optarg;
break;
case 'w':
wcsfn = optarg;
break;
case 'o':
indexfn = optarg;
break;
case 'u':
highf = atof(optarg);
break;
case 'l':
lowf = atof(optarg);
break;
default:
return -1;
}
log_init(loglvl);
if (!xylsfn || !wcsfn || !indexfn) {
printf("Specify in & out filenames, bonehead!\n");
print_help(argv[0]);
exit( -1);
}
if (optind != argc) {
print_help(argv[0]);
printf("\nExtra command-line args were given: ");
for (i=optind; i<argc; i++) {
printf("%s ", argv[i]);
}
printf("\n");
exit(-1);
}
tempfiles = sl_new(4);
// wcs-xy2rd
rdlsfn = create_temp_file("rdls", tempdir);
sl_append_nocopy(tempfiles, rdlsfn);
logmsg("Writing RA,Decs to %s\n", rdlsfn);
if (wcs_xy2rd(wcsfn, wcsext, xylsfn, rdlsfn, xcol, ycol, FALSE, FALSE, NULL)) {
ERROR("Failed to convert xylist to rdlist");
exit(-1);
}
// compute quad size range.
// read WCS.
if (!sip_read_tan_or_sip_header_file_ext(wcsfn, wcsext, &sip, FALSE)) {
ERROR("Failed to read WCS file %s", wcsfn);
exit(-1);
}
// in pixels
diagpix = hypot(sip.wcstan.imagew, sip.wcstan.imageh);
// arcsec / pix
pscale = sip_pixel_scale(&sip);
// in arcsec
diag = diagpix * pscale;
// in arcmin
ip->qlo = arcsec2arcmin(lowf * diag);
ip->qhi = arcsec2arcmin(highf * diag);
logmsg("Image is %i x %i pixels\n", (int)sip.wcstan.imagew, (int)sip.wcstan.imageh);
logmsg("Setting quad scale range to [%g, %g] pixels, [%g, %g] arcsec ([%g, %g] arcmin)\n",
diagpix * lowf, diagpix * highf, diag * lowf, diag * highf,
ip->qlo, ip->qhi);
ip->jitter = pscale * jitterpix;
// number of healpixes:
logmsg("Image area: %g arcsec^2\n", sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale);
logmsg(" %g arcsec\n", sqrt(sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale));
logmsg(" %g arcmin\n", arcsec2arcmin(sqrt(sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale)));
logmsg("Desired hp area: %g arcsec^2\n", sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale / (double)nhp);
logmsg(" %g arcsec\n", sqrt(sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale / (double)nhp));
logmsg(" %g arcmin\n", arcsec2arcmin(sqrt(sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale / (double)nhp)));
Nside = (int)ceil(healpix_nside_for_side_length_arcmin(arcsec2arcmin(sqrt(sip.wcstan.imagew * sip.wcstan.imageh * pscale*pscale / (double)nhp))));
logverb("Chose healpix Nside=%i, side length %g arcmin\n", Nside, healpix_side_length_arcmin(Nside));
ip->Nside = Nside;
ip->scanoccupied = TRUE;
if (build_index_files(rdlsfn, indexfn, ip)) {
exit(-1);
}
// allquads
/*
{
allquads_t* aq;
qfits_header* hdr;
aq = allquads_init();
aq->dimquads = dimquads;
aq->dimcodes = dimquad2dimcode(aq->dimquads);
aq->id = id;
aq->quadfn = quadfn;
aq->codefn = codefn;
aq->skdtfn = skdtfn;
aq->quad_d2_lower = arcsec2distsq(diag * lowf);
aq->quad_d2_upper = arcsec2distsq(diag * highf);
aq->use_d2_lower = TRUE;
aq->use_d2_upper = TRUE;
if (allquads_open_outputs(aq)) {
exit(-1);
}
hdr = codefile_get_header(aq->codes);
qfits_header_add(hdr, "CIRCLE", "T", "Codes live in the circle", NULL);
if (allquads_create_quads(aq) ||
allquads_close(aq)) {
exit(-1);
}
allquads_free(aq);
}
*/
printf("Done.\n");
return 0;
}
|