Cache downloaded data files#152
Merged
wschwanghart merged 1 commit intoTopoToolbox:mainfrom Mar 30, 2026
Merged
Conversation
Resolves TopoToolbox#151 This PR adds two functions to the IOtools: - `ttcachedir` returns the name of a platform-specific cache directory - `ttclearcache` deletes that directory to clear the cache `readopentopo`, `readexample` and `readopenalti` are modified to use `ttcachedir` instead of `tempname` when generating the files. The new behavior of `ttcachedir`, `readopentopo` and `readexample` follows that of their counterparts in pytopotoolbox. The default cache directories are - Windows: %LOCALAPPDATA%\topotoolbox - macOS: $HOME/Library/Caches/topotoolbox - Linux: $XDG_CACHE_HOME/topotoolbox (defaults to $HOME/.cache/topotoolbox if $XDG_CACHE_HOME is undefined) If the necessary environment variables (i.e. %LOCALAPPDATA%) don't exist, an error is thrown, but if the directory doesn't exist, it is created by `ttcachedir`. I've included an option for the user to supply a custom cache directory to `ttcachedir` and `ttclearcache`, but this option is not exposed at the moment to `readopentopo`, etc. because I didn't want to modify the input arguments to those functions too much. If the cache directory doesn't exist when you call `readopentopo`, you'll get an error from `ttcachedir`, which is probably more confusing than it should be. The default name of the OpenTopography files is changed to match pytopotoolbox, which in turn follows the CSDMS bmi_topography tool's naming convention. It is OpenTopo_$SOUTH_$NORTH_$WEST_$EAST_$DEMTYPE.tif This could use more testing, especially on Windows and macOS platforms. Signed-off-by: William Kearney <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #151
This PR adds two functions to the IOtools:
ttcachedirreturns the name of a platform-specific cache directoryttclearcachedeletes that directory to clear the cachereadopentopo,readexampleandreadopenaltiare modified to usettcachedirinstead oftempnamewhen generating the files.The new behavior of
ttcachedir,readopentopoandreadexamplefollows that of their counterparts in pytopotoolbox. The default cache directories areIf the necessary environment variables (i.e. %LOCALAPPDATA%) don't exist, an error is thrown, but if the directory doesn't exist, it is created by
ttcachedir. I've included an option for the user to supply a custom cache directory tottcachedirandttclearcache, but this option is not exposed at the moment toreadopentopo, etc. because I didn't want to modify the input arguments to those functions too much. If the cache directory doesn't exist when you callreadopentopo, you'll get an error fromttcachedir, which is probably more confusing than it should be.The default name of the OpenTopography files is changed to match pytopotoolbox, which in turn follows the CSDMS bmi_topography tool's naming convention. It is
OpenTopo_$SOUTH_$NORTH_$WEST_$EAST_$DEMTYPE.tif
This could use more testing, especially on Windows and macOS platforms.