refactor: minor change to Mars dataset downloading logic. - #503
Conversation
|
Thanks for the PR. It looks good, but I'll need about 2 weeks before I can get to this. After we agree on this, we'll have to make changes to a couple similar datasets that do the same thing. |
@MarkWieczorek Thanks, I can get started on applying this to other datasets if you'd like. I see a total of nine datasets which offer multiple resolutions. Just let me know which of these two implementations you'd prefer:
The latter is more abstracted/complicated, but since it would apply to nine datasets, it would hopefully make future adjustments much easier (cleanness and aesthetics are a bonus). Like I said I'm happy to implement either one, just want to avoid stepping on any toes. Thanks again for your time. |
|
Thanks for your effort on putting this together, and sorry about how long it took to get back to you. I am thinking that it might be best to create some kind of small helper function to find out if a suitable local file already exists. But instead of putting it in the I just have one comment about this comment in the code:
I think that you are assuming that the registry will always be ordered like in this example. Maybe that is ok, but I am just worried that in the future someone might use an inverted order. Perhaps we shouldn't make any assumptions on the ordering. What do you think? |
087eb30 to
0d90fbc
Compare
…isting high-res models instead of downloading lower-res models.
- Context:
- Some datasets have multiple resolutions, e.g. `pyshtools.datasets.Mars.MOLA_shape` has degrees 5759, 2879, 1439, and 719.
- Current behavior:
- When a user loads a dataset, pyshtools chooses the smallest model which satisfies the user's input lmax -- for example, calling `MOLA_shape(2000)` will download the 2879 model. However, if you then call `MOLA_shape(1000)`, pyshtools will download the 1439 model. We would save space/time to reuse the previously downloaded 2879 model.
- Improvement:
- This commit makes it so in aforementioned scenario, pyshtools will load the existing 2879 model.
- In terms of code, all datasets with multiple resolutions now call the method `_choose_sh_model(...)` (located in `/pyshtools/datasets/_utils.py`). This takes the user's desired lmax and a pooch object containing available models, and either loads any existing model with sufficient resolution, or downloads the smallest model with enough resolution.
0d90fbc to
b38cdc9
Compare
|
@MarkWieczorek Apologies for the delay. I've cleaned up this PR so it's a single commit with all intended changes. To summarize (since it's been a while):
|
|
I'm starting to look at this (finally), and will accept this before putting out a new release next week. However, I'm confused why this PR didn't trigger the CI tests. Could you rebase this on the current develop branch and see if this triggers the tests? If not, don't worry about... |
|
Ok. I'll merge this. I think an easier way would be to modify Pooch so that it allows one to add arbitrary metadata for each file in the registry. For our case, the only metadata that really matters is the lmax that is encoded in the filename. I'll bring this up with the Pooch maintainer. It should be as simple as adding an optional metadata dictionary. |
Right now, the dataset
pyshtools.datasets.Mars.MOLA_shapehas multiple resolutions available (5759, 2879, 1439, and 719), and chooses/downloads the smallest model which satisfies the user's inputlmax. For example, if you callMOLA_shape(2000), it will download the 2879 model. However, if you then callMOLA_shape(1000), it will download the 1439 model instead of reusing the previously downloaded 2879 model. This commit modifiesMOLA_shapeso in the aforementioned scenario, it will use the 2879 model.Note that this relies on dictionaries maintaining order of declaration/insertion which was implemented in python 3.6.
This change is only applied to Mars datasets. I'd be happy to apply this change to other datasets with multiple resolutions as well, just let me know.
Reminders
developbranch: themasterbranch is used only when releasing new versions.make checkto ensure that the python code follows standard formatting conventions.