-
Notifications
You must be signed in to change notification settings - Fork 370
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 simple cache mechanism to GoogleWTS class #1533
Conversation
4dc717d
to
544ea03
Compare
@adrien-berchet, thanks for the PR! Coverage has been pretty flaky recently and should hopefully be more reliable when we drop Python 2 support. So, I wouldn't read into it too much right now. |
Thanks for your feedback. |
@greglucas I rebased the branch on master |
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.
Overall, I think this looks really good. One question is whether we want to have a cache_path
at all? Would it make sense to just put a kwarg cache=True
and then use the data_dir
that is already in Cartopy config:
https://scitools.org.uk/cartopy/docs/latest/cartopy.html#cartopy.config
Maybe make a new cache dir for your saved files underneath that? Then a user could easily clean up all local Cartopy files and not need to remember what cache_path they used.
There was also #795, which doesn't seem to have been completed. I have not compared the implementations. |
Indeed it would be possible to store the cache in |
Indeed, I did not know it. |
I have also never used What about adding a cartopy/lib/cartopy/__init__.py Lines 23 to 27 in 466c901
Then we could change the keyword argument input to the function to just be cache and allow |
7464add
to
59292e1
Compare
9757d12
to
3832c59
Compare
I rebased on master and added a |
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 that is a pretty nice way to do it! The only downside is that I think it will use a new tempdir
for each virtual environment a user would create I think because this is creating a random tempdir
at each installation. That is one thing I like about the current Natural Earth data being downloaded to my user space rather than per each venv I create.
I'm fine with it as is, just want to make sure that is what you want as a user and this makes sense to others too.
I was also wondering why the new cache
keyword argument didn't have any docstrings with it in all of these new places and it turns out we just don't have any docstrings there currently :(
lib/cartopy/io/img_tiles.py
Outdated
"""Load the cache""" | ||
if self.cache_path is not None: | ||
if not os.path.exists(self._cache_dir): | ||
os.makedirs(self._cache_dir) |
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.
Do we want emit a warning message telling them we are creating the cache_dir in case a user didn't realize they were making this dir?
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.
We could indeed. But maybe only in the case where cache=True
, because when the user explicitly sets a directory path we can suppose he knows what he is doing.
|
||
config = {'pre_existing_data_dir': '', | ||
'data_dir': _data_dir, | ||
'cache_dir': _cache_dir, |
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.
Add an entry into the docstring below describing what this new entry is for.
In fact, when If you are ok with that I will add the docstrings (I was waiting the final version to write the doc). |
Oh and I have another question @greglucas : since we provide a default path to a temp directory, should we set the default value of the cache parameter to True? |
527d9ef
to
928d785
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 tested this out locally in two different virtual environments and you're right it does maintain the same temporary cache_dir
in both of them.
I think that we should keep this as an additional option for now, and potentially default to it in a follow-up PR? It may be nice to set a global default somehow though, so you don't have to specify the cache keyword with every single call... Something along the lines of the mpl.rcParams way of doing things.
For now, I think this looks great! So I'll approve it and wait to see if anyone else has any feedback on it for a bit before merging.
Ok, thanks! Let's wait for other feedbacks then :) |
928d785
to
368cc27
Compare
Thank you for rebasing, I just reran the doc CI build that was failing and everything looks good now. |
I'm not so sure about tempdir, as that is shared by users, and this doesn't use a user-specific name, nor an exclusive creation mode. I think the user cache may be a better location? Though it's not consistent across platforms ( |
Hi @QuLogic |
368cc27
to
714b99f
Compare
714b99f
to
ce75352
Compare
Hi there, I just realized that this PR was still pending. I rebased and added a note about cache privacy in |
👍 My approval still stands. I think this is good with the note you've added, especially since this isn't on by default and the user has to opt-in. |
Rationale
During my development I made many tests implying fetching tiles from Google. In the end, my IP address got banned for some time...
I propose a very simple cache mechanism to store tiles so that it is not needed to request tiles from the server at each test.
With this, it is possible to write:
gt_cache = cimgt.GoogleTiles(cache="\tmp\cartopy_cache")
and all tiles downloaded downloaded by this
GoogleWTS
object will be stored in the given directory for later use.Implications