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 VERIFY_H
7 #define VERIFY_H
8 
9 #include "astrometry/kdtree.h"
10 #include "astrometry/matchobj.h"
11 #include "astrometry/bl.h"
12 #include "astrometry/starkd.h"
13 #include "astrometry/sip.h"
14 #include "astrometry/bl.h"
15 #include "astrometry/starxy.h"
16 
17 struct verify_field_t {
18     const starxy_t* field;
19     // this copy is normal.
20     double* xy;
21     // this copy is permuted by the kdtree
22     double* fieldcopy;
23     kdtree_t* ftree;
24 
25     // should this field be spatially uniformized at the index's scale?
26     anbool do_uniformize;
27     // should this field be de-duplicated (have nearby sources removed)?
28     anbool do_dedup;
29     // apply radius-of-relevance filtering
30     anbool do_ror;
31 };
32 typedef struct verify_field_t verify_field_t;
33 
34 
35 /*
36  This function must be called once for each field before verification
37  begins.  We build a kdtree out of the field stars (in pixel space)
38  which will be used during deduplication.
39  */
40 verify_field_t* verify_field_preprocess(const starxy_t* fieldxy);
41 
42 /*
43  This function must be called after all verification calls for a field
44  are finished; we clean up the data structures we created in the
45  verify_field_preprocess() function.
46  */
47 void verify_field_free(verify_field_t* vf);
48 
49 
50 
51 
52 void verify_count_hits(int* theta, int besti, int* p_nmatch, int* p_nconflict, int* p_ndistractor);
53 
54 void verify_wcs(const startree_t* skdt,
55                 int index_cutnside,
56                 const sip_t* sip,
57                 const verify_field_t* vf,
58                 double verify_pix2,
59                 double distractors,
60                 double fieldW,
61                 double fieldH,
62                 double logratio_tobail,
63                 double logratio_toaccept,
64                 double logratio_tostoplooking,
65 
66                 double* logodds,
67                 int* nfield, int* nindex,
68                 int* nmatch, int* nconflict, int* ndistractor
69                 // int** theta ?
70                 );
71 
72 /*
73  Uses the following entries in the "mo" struct:
74  -wcs_valid
75  -wcstan
76  -center
77  -radius
78  -field[]
79  -star[]
80  -dimquads
81 
82  Sets the following:
83  -nfield
84  -noverlap
85  -nconflict
86  -nindex
87  -(matchobj_compute_derived() values)
88  -logodds
89  -corr_field
90  -corr_index
91  */
92 void verify_hit(const startree_t* skdt,
93                 int index_cutnside,
94                 // input/output param.
95                 MatchObj* mo,
96                 const sip_t* sip, // if non-NULL, verify this SIP WCS.
97                 const verify_field_t* vf,
98                 double verify_pix2,
99                 double distractors,
100                 double fieldW,
101                 double fieldH,
102                 double logratio_tobail,
103                 double logratio_toaccept,
104                 double logratio_tostoplooking,
105                 anbool distance_from_quad_bonus,
106                 anbool fake_match);
107 
108 // Distractor
109 #define THETA_DISTRACTOR -1
110 // Conflict
111 #define THETA_CONFLICT -2
112 // Filtered out
113 #define THETA_FILTERED -3
114 // Not examined because the bail-out threshold was reached.
115 #define THETA_BAILEDOUT -4
116 // Not examined because the stop-looking threshold was reached.
117 #define THETA_STOPPEDLOOKING -5
118 
119 /*
120  void verify_apply_ror(double* refxy, int* starids, int* p_NR,
121  int index_cutnside,
122  MatchObj* mo,
123  const verify_field_t* vf,
124  double pix2,
125  double distractors,
126  double fieldW,
127  double fieldH,
128  anbool do_gamma, anbool fake_match,
129  double** p_testxy, double** p_sigma2s,
130  int* p_NT, int** p_perm, double* p_effA,
131  int* p_uninw, int* p_uninh);
132  */
133 
134 /**
135  Returns the best log-odds encountered.
136  */
137 double verify_star_lists(double* refxys, int NR,
138                          const double* testxys, const double* testsigma2s, int NT,
139                          double effective_area,
140                          double distractors,
141                          double logodds_bail,
142                          double logodds_accept,
143                          int* p_besti,
144                          double** p_all_logodds, int** p_theta,
145                          double* p_worstlogodds,
146                          int** p_testperm);
147 
148 void verify_get_uniformize_scale(int cutnside, double scale, int W, int H, int* uni_nw, int* uni_nh);
149 
150 void verify_uniformize_field(const double* xy, int* perm, int N,
151                              double fieldW, double fieldH,
152                              int nw, int nh,
153                              int** p_bincounts,
154                              int** p_binids);
155 
156 double* verify_uniformize_bin_centers(double fieldW, double fieldH,
157                                       int nw, int nh);
158 
159 void verify_get_quad_center(const verify_field_t* vf, const MatchObj* mo, double* centerpix,
160                             double* quadr2);
161 
162 /*
163  int verify_get_test_stars(const verify_field_t* vf, MatchObj* mo,
164  double pix2, anbool do_gamma,
165  anbool fake_match,
166  double** p_sigma2s, int** p_perm);
167  */
168 
169 void verify_get_index_stars(const double* fieldcenter, double fieldr2,
170                             const startree_t* skdt, const sip_t* sip, const tan_t* tan,
171                             double fieldW, double fieldH,
172                             double** p_indexradec,
173                             double** p_indexpix, int** p_starids, int* p_nindex);
174 
175 /*
176  anbool* verify_deduplicate_field_stars(const verify_field_t* vf, double* sigma2s, double nsigmas);
177  */
178 /*
179  double* verify_compute_sigma2s_arr(const double* xy, int NF,
180  const double* qc, double Q2,
181  double verify_pix2, anbool do_gamma);
182  */
183 
184 // For use with matchobj.h : matchodds
185 double verify_logodds_to_weight(double lodds);
186 
187 void verify_free_matchobj(MatchObj* mo);
188 
189 void verify_matchobj_deep_copy(const MatchObj* mo, MatchObj* dest);
190 
191 double verify_get_ror2(double Q2, double area,
192                        double distractors, int NR, double pix2);
193 
194 
195 
196 double verify_star_lists_ror(double* refxys, int NR,
197                              const double* testxys, const double* testsigma2s, int NT,
198                              double pix2, double gamma,
199                              const double* qc, double Q2,
200                              double W, double H,
201                              double distractors,
202                              double logodds_bail,
203                              double logodds_stoplooking,
204                              int* p_besti,
205                              double** p_all_logodds, int** p_theta,
206                              double* p_worstlogodds,
207                              int** p_testperm, int** p_refperm);
208 
209 #endif
210