-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move some functions from create_derived_agasc_h5.py #161
Conversation
d551ff1
to
a986304
Compare
303d708
to
4b4e2ab
Compare
I should have marked this as WIP. I just added another commit. One question that is left is whether this is the right place for this. The stuff I'm adding might be better in a separate |
17dae1c
to
8c5e834
Compare
8c5e834
to
9160682
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks generally good. In additional to the inline comments, all the public functions need full doc strings. The non-public ones should at least have a single-line docstring with a simple description of what it is doing.
agasc/agasc.py
Outdated
h5.root.healpix_index.attrs["nside"] = nside | ||
|
||
|
||
DTYPE = np.dtype( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this more descriptive like TABLE_DTYPE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
agasc/agasc.py
Outdated
) | ||
|
||
|
||
class Order(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More descriptive, like TableOrder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
agasc/agasc.py
Outdated
if stars.dtype != DTYPE: | ||
cols = DTYPE.names | ||
missing_keys = set(cols) - set(stars.dtype.names) | ||
assert not missing_keys, f"Missing keys in stars: {missing_keys}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No assert
in non-test modules. Do a test and raise a ValueError
instead. FWIW running Python with the -OO
flag strips out assert statements. Not that we do that, but I've just been reviewing a monster astropy PR that makes astropy work with -OO
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Note: there was a trivial assert right after this, and I just removed it. My tendency would have been to keep this second assert, and let it be stripped by the -OO
option.
agasc/agasc.py
Outdated
write_healpix_index_table(filename, healpix_index, nside) | ||
|
||
|
||
def write_agasc_(filename, stars, version): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Private methods have a leading underscore, not trailing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
agasc/tests/test_agasc_2.py
Outdated
from agasc import write_agasc | ||
|
||
with ( | ||
tempfile.TemporaryDirectory() as tempdir, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the pytest tmp_path
fixture. https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
agasc/tests/test_agasc_2.py
Outdated
Path(os.environ["SKA"]) / "data" / "agasc" / "agasc_1p7.h5" | ||
) as h5_in, | ||
): | ||
t = Table(h5_in.root.data[:1000]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only line that needs the h5_in
context, so out-dent all the rest to take them out of the context manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
agasc/agasc.py
Outdated
if order == Order.DEC: | ||
logger.info("Sorting on DEC column") | ||
idx_sort = np.argsort(stars["DEC"]) | ||
elif order == Order.HEALPIX: | ||
logger.info( | ||
f"Creating healpix_index table for nside={nside} " | ||
"and sorting by healpix index" | ||
) | ||
healpix_index, idx_sort = get_healpix_index_table(stars, nside) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an opportunity to use the new switch
statement in Python 3.10!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand it, the switch statement gains us nothing in terms of performance, and it actually makes the code slightly more verbose, so I'm not sure we want to use it.
Anyway, I changed it.
…rything out of pytables context, and renamed table with one-letter name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, nice!
from agasc import write_agasc | ||
|
||
with tables.open_file( | ||
Path(os.environ["SKA"]) / "data" / "agasc" / "agasc_1p7.h5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now failing on HEAD because the file in /proj/sot/ska/data/agasc is agasc1p7.h5 (no _). I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I happen to have a link with the _
. I don't know why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I couldn't remember the filename history to know if we wanted to make the link you have or update the test to match what we've got in /proj/sot/ska.
Move some functions from create_derived_agasc_h5.py into the agasc module.
The objective is to be able to call
agasc.write_agasc
from my AGASC-Gaia scripts.Description
Fixes #
Interface impacts
Testing
Unit tests
Independent check of unit tests by [REVIEWER NAME]
Functional tests