-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add option to create HipsSurveyProperties from survey name #95
Conversation
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 left two inline comments.
Note: https://travis-ci.org/hipspy/hips/jobs/258142624#L1545
Do you know hot to fix those or should I explain?
Yes, the similar change to geometry
should definitely be a separate PR.
docs/getting_started.rst
Outdated
url = 'http://alasky.unistra.fr/DSS/DSS2Merged/properties' | ||
hips_survey = HipsSurveyProperties.fetch(url) | ||
|
||
hips_survey = HipsSurveyProperties.make('CDS/P/DSS2/red') |
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.
If you remove the import and just write this here
hips_survey = 'CDS/P/DSS2/red'
it would give the same result, no?
Please make it work that way and change the high-level docs to use that simple form.
hips/draw/simple.py
Outdated
@@ -61,7 +61,7 @@ class HipsPainter: | |||
(1000, 2000) | |||
""" | |||
|
|||
def __init__(self, geometry: WCSGeometry, hips_survey: HipsSurveyProperties, tile_format: str) -> None: | |||
def __init__(self, geometry: WCSGeometry, hips_survey: str or HipsSurveyProperties, tile_format: str) -> None: |
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 think the type annotation has to be Union
in case of multiple options, no?
https://docs.python.org/3/library/typing.html#typing.Union
@cdeil I've made the changes. I also marked the tests with |
bd13465
to
b84b776
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.
I've left a few inline comments.
When those are adressed, this PR can go in.
It's an important user experience improvement, so thanks for putting it together quickly, @adl1995 !
docs/getting_started.rst
Outdated
@@ -26,21 +26,16 @@ To draw a sky image from HiPS image tiles with the `hips` package, follow the fo | |||
coordsys='galactic', projection='AIT', | |||
) | |||
|
|||
|
|||
2. Specify the HiPS survey you want by creating a `~hips.HipsSurveyProperties` object. | |||
2. Specify the HiPS survey you want. |
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.
You should mention that users have to give the ID of the Hips survey.
hips/draw/simple.py
Outdated
@@ -35,7 +35,7 @@ class HipsPainter: | |||
---------- | |||
geometry : `~hips.utils.WCSGeometry` | |||
An object of WCSGeometry | |||
hips_survey : str or `~hips.HipsSurveyProperties` | |||
hips_survey : `str` or `~hips.HipsSurveyProperties` |
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'm using the docs pattern where I don't put backticks for PYthon built-in types like str
, list
, int
, ...
So please remove them here for consistency with the rest of our docstrings.
hips/draw/simple.py
Outdated
@@ -61,7 +61,7 @@ class HipsPainter: | |||
(1000, 2000) | |||
""" | |||
|
|||
def __init__(self, geometry: WCSGeometry, hips_survey: HipsSurveyProperties, tile_format: str) -> None: | |||
def __init__(self, geometry: WCSGeometry, hips_survey: Union[str, 'HipsSurveyProperties'], tile_format: str) -> None: |
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.
The common thing to do is to put the type, and only to put quotes if there's a forward reference issue.
So please remove the quotes from HipsSurveyProperties
here in the type annotation, and review the diff of this PR on Github to fix the other cases (I see one below).
hips/draw/simple.py
Outdated
image : `~numpy.ndarray` | ||
Output image pixels | ||
result : `~hips.HipsDrawResult` | ||
HipsDrawResult object |
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.
Don't duplicate the type name in the description. It's not useful. Here I'd suggest this desription:
Result object
hips/tiles/tests/test_surveys.py
Outdated
# TODO: look up survey by name here | ||
# Otherwise this will break when the list changes | ||
survey = surveys.data[0] | ||
survey = HipsSurveyProperties.from_name('CDS/P/2MASS/H') |
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 change to the test is no good.
I would suggest to move the code that does the name lookup from the HipsSurveyProperties.from_name
method to a HipsSurveyPropertiesList.from_name
method and then call this here from this test (instead of calling
HipsSurveyProperties.from_name('CDS/P/2MASS/H')
which will fetch the list again.
The implementation of HipsSurveyProperties.from_name
would then just be
@classmethod
def from_name(name);
surveys = HipsSurveyPropertiesList.fetch()
return surveys.from_name(name)
and maybe we'd remove it eventually.
You should also add a test with an invalid key like name='kronka lonka'
and check that a KeyError is raised.
I explained how to do that with pytest.raises
here previously: #55 (comment)
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.
@cdeil I'm not sure what you mean here. Do you mean to say create a simple class method from_name
in addition to the classmethod
?
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've updated my comment above: the class names I gave were wrong. I meant adding a normal method HipsSurveyPropertiesList.from_name
(not a classmethod), because really looking for a name is an operation on the list, i.e. the code that does the looping through surveys and looking for a name ID should be a method on HipsSurveyPropertiesList
.
Is it clear now?
hips/tiles/tests/test_surveys.py
Outdated
def test_make(self): | ||
survey = HipsSurveyProperties.make('CDS/P/EGRET/Dif/300-500') | ||
assert survey.title == 'EGRET Dif 300-500' | ||
self.survey = HipsSurveyProperties.make(self.survey) |
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 line doesn't make sense. You're setting self.survey
on the last line of the test.
Instead you should be asserting something.
I think this might work:
assert self.survey is HipsSurveyProperties.make(self.survey)
because in that case we just return the same object and "is" checks for object equality, no?
b84b776
to
09906ec
Compare
Thanks! |
As outlined in #82 and during the telecon yesterday, I have added the option to create
HipsSurveyProperties
using a survey name.@cdeil Currently, this is not implemented:
Can this be part of a separate PR?