Skip to content

Commit 3cbcb07

Browse files
committed
Filter index files before solving
1 parent 143e620 commit 3cbcb07

File tree

8 files changed

+857
-9
lines changed

8 files changed

+857
-9
lines changed

astrometry.net

Submodule astrometry.net updated 74 files

astrometry/series.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def run(session: requests.Session, task: tuple[str, pathlib.Path, pathlib.Path])
5353
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
5454
download_file.write(chunk)
5555
response.close()
56+
response.raise_for_status()
5657
download_path.rename(path)
5758

5859

astrometry_extension/astrometry_extension.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "mathutil.h"
33
#include "solver.h"
44
#include <Python.h>
5+
#include <libgen.h>
6+
#include <string.h>
57
#include <structmember.h>
68

79
#define LARGE_VAL 1e30
@@ -209,21 +211,38 @@ static anbool record_match_callback(MatchObj* match, void* userdata) {
209211
match->refxy = NULL;
210212
match->refstarid = NULL;
211213
match->testperm = NULL;
214+
char* index_directory_name = NULL;
215+
{
216+
char* match_indexname = strdup(match->index->indexname);
217+
char* index_directory = strdup(dirname(match_indexname));
218+
free(match_indexname);
219+
index_directory_name = strdup(basename(index_directory));
220+
free(index_directory);
221+
}
222+
char* index_name = NULL;
223+
{
224+
char* match_indexname = strdup(match->index->indexname);
225+
index_name = strdup(basename(match_indexname));
226+
free(match_indexname);
227+
}
212228
PyEval_RestoreThread(context->save);
213229
PyObject* message = PyUnicode_FromFormat(
214230
"solve %s: logodds=%s, matches=%d, conflicts=%d, distractors=%d, "
215-
"index=%d, ra=%s, dec=%s, scale=%s",
231+
"ra=%s, dec=%s, scale=%s, index=%s/%s",
216232
context->solve_id,
217233
logodds_string,
218234
context->matches.data[context->matches.size - 1].nmatch,
219235
context->matches.data[context->matches.size - 1].nconflict,
220236
context->matches.data[context->matches.size - 1].ndistractor,
221-
context->matches.data[context->matches.size - 1].nindex,
222237
ra_string,
223238
dec_string,
224-
scale_string);
239+
scale_string,
240+
index_directory_name,
241+
index_name);
225242
PyObject_CallMethod(context->logging, "info", "O", message);
226243
Py_DECREF(message);
244+
free(index_directory_name);
245+
free(index_name);
227246
anbool inserted_or_error = FALSE;
228247
for (Py_ssize_t index = 0; index < PyList_Size(context->sorted_logodds_list); ++index) {
229248
const double value = PyFloat_AsDouble(PyList_GET_ITEM(context->sorted_logodds_list, index));
@@ -581,8 +600,29 @@ static PyObject* astrometry_extension_solver_solve(PyObject* self, PyObject* arg
581600
if (!sorted_logodds_list) {
582601
return NULL;
583602
}
603+
604+
// filter index files using the position and scale hints
605+
pl* selected_indexes = pl_new(16);
606+
double maximum_quad_size_arcsec = maximum_quad_size_pixels == 0.0 ? LARGE_VAL : maximum_quad_size_pixels * scale_upper;
607+
for (size_t position = 0; position < pl_size(current->indexes); ++position) {
608+
index_t* index = pl_get(current->indexes, position);
609+
if (index_overlaps_scale_range(index, minimum_quad_size_pixels * scale_lower, maximum_quad_size_arcsec)) {
610+
if (!has_position_hint
611+
|| (has_position_hint
612+
&& index_is_within_range(index, position_hint_ra, position_hint_dec, position_hint_radius))) {
613+
pl_append(selected_indexes, index);
614+
}
615+
}
616+
}
617+
618+
if (pl_size(selected_indexes) == 0) {
619+
PyErr_SetString(PyExc_TypeError, "index files do not overlap the provided position and scale hints");
620+
pl_remove_all(selected_indexes);
621+
return NULL;
622+
}
584623
PyObject* logging = PyImport_ImportModule("logging");
585624
if (!logging) {
625+
pl_remove_all(selected_indexes);
586626
return NULL;
587627
}
588628
{
@@ -620,6 +660,7 @@ static PyObject* astrometry_extension_solver_solve(PyObject* self, PyObject* arg
620660
starxy_free_data(&starxy);
621661
PyErr_Clear();
622662
PyErr_SetString(PyExc_TypeError, "items in stars_xs and stars_ys must be floats");
663+
pl_remove_all(selected_indexes);
623664
Py_DECREF(logging);
624665
return NULL;
625666
}
@@ -633,7 +674,7 @@ static PyObject* astrometry_extension_solver_solve(PyObject* self, PyObject* arg
633674
.solver =
634675
{
635676
// input fields
636-
.indexes = current->indexes,
677+
.indexes = selected_indexes,
637678
.fieldxy = NULL,
638679
.pixel_xscale = 0.0,
639680
.predistort = NULL,
@@ -731,6 +772,7 @@ static PyObject* astrometry_extension_solver_solve(PyObject* self, PyObject* arg
731772
context.solver.fieldxy_orig = NULL;
732773
starxy_free_data(&starxy);
733774
solver_cleanup(&context.solver);
775+
pl_remove_all(selected_indexes);
734776
Py_DECREF(logging);
735777
Py_DECREF(sorted_logodds_list);
736778
return NULL;
@@ -933,6 +975,7 @@ static PyObject* astrometry_extension_solver_solve(PyObject* self, PyObject* arg
933975
context.solver.fieldxy_orig = NULL;
934976
starxy_free_data(&starxy);
935977
solver_cleanup(&context.solver);
978+
pl_remove_all(selected_indexes);
936979
Py_DECREF(logging);
937980
Py_DECREF(sorted_logodds_list);
938981
return result;

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def run(self):
249249

250250
setuptools.setup(
251251
name="astrometry",
252-
version="3.0.0",
252+
version="3.1.0",
253253
url="https://github.com/neuromorphicsystems/astrometry",
254254
author="ICNS, Alexandre Marcireau",
255255
author_email="[email protected]",

0 commit comments

Comments
 (0)