1 /*
2  # This file is part of the Astrometry.net suite.
3  # Licensed under a 3-clause BSD style license - see LICENSE
4  */
5 
6 #ifndef ANTPV_H
7 #define ANTPV_H
8 
9 #include <stdio.h>
10 #include "astrometry/sip.h"
11 #include "astrometry/keywords.h"
12 
13 #define N_PV_TERMS 40
14 
15 // TPV (TAN + PV distortion) structure.
16 typedef struct {
17 
18     // A basic TAN header.
19     tan_t wcstan;
20 
21     double pv1[N_PV_TERMS];
22     double pv2[N_PV_TERMS];
23 
24 } tpv_t;
25 
26 tpv_t* tpv_new(void);
27 void   tpv_free(tpv_t* tpv);
28 
29 void sip_copy(sip_t* dest, const sip_t* src);
30 
31 // Set the given TPV wcs to the given TAN wcs.
32 void tpv_wrap_tan(const tan_t* tan, tpv_t* tpv);
33 
34 double tpv_imagew(tpv_t* tpv);
35 double tpv_imageh(tpv_t* tpv);
36 
37 // Pixels to RA,Dec in degrees.
38 void   tpv_pixelxy2radec(const tpv_t* tpv, double px, double py, double *a, double *d);
39 
40 // Pixels to XYZ unit vector.
41 void   tpv_pixelxy2xyzarr(const tpv_t* tpv, double px, double py, double *xyz);
42 
43 // RA,Dec in degrees to Pixels.
44 // Returns FALSE if the point is on the opposite side of the sphere (and hence the point
45 // does not project onto the tangent plane)
46 WarnUnusedResult
47 anbool tpv_radec2pixelxy(const tpv_t* tpv, double a, double d, double *px, double *py);
48 
49 WarnUnusedResult
50 anbool tpv_radec2pixelxy_check(const tpv_t* tpv, double ra, double dec, double *px, double *py);
51 
52 WarnUnusedResult
53 anbool tpv_xyzarr2pixelxy(const tpv_t* tpv, const double* xyz, double *px, double *py);
54 
55 WarnUnusedResult
56 anbool tpv_xyz2pixelxy(const tpv_t* tpv, double x, double y, double z, double *px, double *py);
57 
58 // Pixels to Intermediate World Coordinates in degrees.
59 void tpv_pixelxy2iwc(const tpv_t* tpv, double px, double py,
60                      double *iwcx, double* iwcy);
61 
62 
63 double tpv_det_cd(const tpv_t* tpv);
64 // returns pixel scale in arcseconds/pixel (NOT arcsec^2)
65 double tpv_pixel_scale(const tpv_t* tpv);
66 
67 // these take *relative* pixel coords (WRT crpix)
68 void   tpv_calc_inv_distortion(const tpv_t* tpv, double U, double V, double* u, double *v);
69 void   tpv_calc_distortion(const tpv_t* tpv, double u, double v, double* U, double *V);
70 
71 // Applies forward TPV distortion to pixel coords.
72 // This applies the A,B matrix terms;
73 // This is the distortion applied in the pixel-to-RA,Dec direction.
74 //   (pix -> "un"distorted -> TAN -> RA,Dec)
75 void tpv_pixel_distortion(const tpv_t* tpv, double x, double y, double* X, double *Y);
76 
77 // Reverses tpv_pixel_distortion;
78 // Applies "reverse" TPV distortion: the AP, BP matrices;
79 // This is the distortion applied in the RA,Dec-to-pixel direction:
80 //   (RA,Dec -> TAN -> undistorted -> pix)
81 void tpv_pixel_undistortion(const tpv_t* tpv, double x, double y, double* X, double *Y);
82 
83 anbool tpv_xyzarr2iwc(const tpv_t* tpv, const double* xyz,
84                       double* iwcx, double* iwcy);
85 anbool tpv_radec2iwc(const tpv_t* tpv, double ra, double dec,
86                      double* iwcx, double* iwcy);
87 
88 void tpv_iwc2pixelxy(const tpv_t* tpv, double iwcx, double iwcy,
89                      double *px, double* py);
90 
91 void tpv_iwc2radec(const tpv_t* tpv, double x, double y, double *p_ra, double *p_dec);
92 
93 void   tpv_print(const tpv_t*);
94 void   tpv_print_to(const tpv_t*, FILE* fid);
95 
96 // for python
97 void tpv_get_crval(const tpv_t* tpv, double* ra, double* dec);
98 
99 double tpv_get_orientation(const tpv_t* tpv);
100 
101 #endif
102