Closed javierggt closed 2 years ago
Not quite in this PR, but this code got my attention. It is making a view of a subset of a Table and then sorting within that view. Apparently that works, but it still strikes me as possibly sketchy. It is also a lot slower than it needs to be because of making lots of tables and sorting columns that don't need attention.
matches = matches.group_by('obsid')
for g in matches.groups:
g.sort(['cat_order', 'dr'])
result = table.vstack([g[0] for g in matches.groups])
This should be orders of magnitude faster and equivalent [EDIT: confirmed]:
mg = matches.group_by('obsid')
indices = mg.groups.indices
idxs = []
for i0, i1 in zip(indices[:-1], indices[1:]):
idxs_sort = np.lexsort((mg['dr'][i0:i1], mg['cat_order'][i0:i1]))
idxs.append(i0 + idxs_sort[0])
result = mg[idxs]
Not quite in this PR...
I could make an issue with this and follow-up after this PR. I will check.
Digging further on the point about the cross match code above, two things:
catalogs=['ICRS', 'Tycho2', '2MASS', 'SDSS', 'USNO-B1.0'],
should choose 2MASS
. My original get_xcorr
gives the 2MASS match, but the result from this branch is the SDSS
one. [EDIT] I think this was a different bug unrelated to the cross-match code in question.
get_xcorr(xray_src, cat_src, obs)
function). The code below takes about 3 minutes to complete while the original get_xcorr
finishes in 4 seconds.
xcorr = cross_match.compute_cross_matches(
catalogs=['ICRS', 'Tycho2', '2MASS', 'SDSS', 'USNO-B1.0'],
dr=10000,
snr=-10000,
r_angle=10000,
r_angle_grating=10000,
near_neighbor_dist=-10000,
)
I fixed the discrepancies between my original API code and this version with ff34529.
@javierggt - this PR is basically fine at this point except for the minor comments I made that are all easily fixed. If you just take care of those then we can merge this one.
I made changes that I believe address @taldcroft's comments.
I also made a couple new commits:
db.save
to be consistentI pushed a commit so the narrative docs include the information that future-me will need.
I committed a fix for a failure I got, which I believe traces back to changing the return values of empty tables. I didn't spend much time checking why, but the bottomline is I add some extra columns to empty tables so the result's type is consistent with the case of non-empty tables, and downstream code can handle it.
I ran the tests above and check that the output is consistent with expectations.
I fixed two typos and will squash in a moment.
:tada:
This PR is a refactor of the cross-match methods, partly to address requests in issue #15 and partly to fix a few things.
The things that changed upon @taldcroft request:
Other cleanup:
astromon_21
).Testing
NOTE: the observation code examples in the docs only run on HEAD and if you have access to arc5gl.
and
and this one only writes xray_src and obs, the rest are empty