void tan_add_to_header(qfits_header* hdr, const tan_t* tan) { wcs_hdr_common(hdr, tan); if (tan->sin) { qfits_header_add_after(hdr, "WCSAXES", "CTYPE2", "DEC--SIN", "SIN projection", NULL); qfits_header_add_after(hdr, "WCSAXES", "CTYPE1", "RA---SIN", "SIN projection", NULL); } else { qfits_header_add_after(hdr, "WCSAXES", "CTYPE2", "DEC--TAN", "TAN (gnomic) projection", NULL); qfits_header_add_after(hdr, "WCSAXES", "CTYPE1", "RA---TAN", "TAN (gnomic) projection", NULL); } }
void sip_add_to_header(qfits_header* hdr, const sip_t* sip) { wcs_hdr_common(hdr, &(sip->wcstan)); if (sip->wcstan.sin) { qfits_header_add_after(hdr, "WCSAXES", "CTYPE2", "DEC--SIN-SIP", "SIN projection + SIP distortions", NULL); qfits_header_add_after(hdr, "WCSAXES", "CTYPE1", "RA---SIN-SIP", "SIN projection + SIP distortions", NULL); } else { qfits_header_add_after(hdr, "WCSAXES", "CTYPE2", "DEC--TAN-SIP", "TAN (gnomic) projection + SIP distortions", NULL); qfits_header_add_after(hdr, "WCSAXES", "CTYPE1", "RA---TAN-SIP", "TAN (gnomic) projection + SIP distortions", NULL); } fits_header_add_int(hdr, "A_ORDER", sip->a_order, "Polynomial order, axis 1"); add_polynomial(hdr, "A_%i_%i", sip->a_order, (double*)sip->a, SIP_MAXORDER); fits_header_add_int(hdr, "B_ORDER", sip->b_order, "Polynomial order, axis 2"); add_polynomial(hdr, "B_%i_%i", sip->b_order, (double*)sip->b, SIP_MAXORDER); fits_header_add_int(hdr, "AP_ORDER", sip->ap_order, "Inv polynomial order, axis 1"); add_polynomial(hdr, "AP_%i_%i", sip->ap_order, (double*)sip->ap, SIP_MAXORDER); fits_header_add_int(hdr, "BP_ORDER", sip->bp_order, "Inv polynomial order, axis 2"); add_polynomial(hdr, "BP_%i_%i", sip->bp_order, (double*)sip->bp, SIP_MAXORDER); }
// Add FITS keywords void add_fits_keywords(struct transformation t,char *filename) { int i,j,k,l,m; int naxis1,naxis2,naxis3; qfits_header *qh; qfitsdumper qd; qfitsloader ql; char key[FITS_LINESZ+1]; char val[FITS_LINESZ+1]; char com[FITS_LINESZ+1]; char lin[FITS_LINESZ+1]; FILE *file; float *fbuf; naxis1=atoi(qfits_query_hdr(filename,"NAXIS1")); naxis2=atoi(qfits_query_hdr(filename,"NAXIS2")); naxis3=atoi(qfits_query_hdr(filename,"NAXIS3")); fbuf=malloc(sizeof(float)*naxis1*naxis2*naxis3); // Read header qh=qfits_header_read(filename); ql.xtnum=0; ql.ptype=PTYPE_FLOAT; ql.filename=filename; for (k=0,l=0;k<naxis3;k++) { ql.pnum=k; // Initialize load if (qfitsloader_init(&ql) != 0) printf("Error initializing data loading\n"); // Test load if (qfits_loadpix(&ql) != 0) printf("Error loading actual data\n"); for (i=0,m=0;i<naxis1;i++) { for (j=0;j<naxis2;j++) { fbuf[l]=ql.fbuf[m]; l++; m++; } } } qfits_header_add_after(qh,"MJD-OBS","CUNIT2","'deg'"," ",NULL); qfits_header_add_after(qh,"MJD-OBS","CUNIT1","'deg'"," ",NULL); qfits_header_add_after(qh,"MJD-OBS","CTYPE2","'DEC--TAN'"," ",NULL); qfits_header_add_after(qh,"MJD-OBS","CTYPE1","'RA---TAN'"," ",NULL); sprintf(val,"%e",t.b[2]/3600.0); qfits_header_add_after(qh,"MJD-OBS","CD2_2",val," ",NULL); sprintf(val,"%e",t.b[1]/3600.0); qfits_header_add_after(qh,"MJD-OBS","CD2_1",val," ",NULL); sprintf(val,"%e",t.a[2]/3600.0); qfits_header_add_after(qh,"MJD-OBS","CD1_2",val," ",NULL); sprintf(val,"%e",t.a[1]/3600.0); qfits_header_add_after(qh,"MJD-OBS","CD1_1",val," ",NULL); sprintf(val,"%f",t.de0); qfits_header_add_after(qh,"MJD-OBS","CRVAL2",val," ",NULL); sprintf(val,"%f",t.ra0); qfits_header_add_after(qh,"MJD-OBS","CRVAL1",val," ",NULL); sprintf(val,"%f",t.y0); qfits_header_add_after(qh,"MJD-OBS","CRPIX2",val," ",NULL); sprintf(val,"%f",t.x0); qfits_header_add_after(qh,"MJD-OBS","CRPIX1",val," ",NULL); file=fopen(filename,"w"); qfits_header_dump(qh,file); fclose(file); qfits_header_destroy(qh); qd.filename=filename; qd.npix=naxis1*naxis2*naxis3; qd.ptype=PTYPE_FLOAT; qd.fbuf=fbuf; qd.out_ptype=-32; qfits_pixdump(&qd); free(fbuf); return; }
// 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); } } }