Skip to content

Cache downloaded data files#152

Merged
wschwanghart merged 1 commit intoTopoToolbox:mainfrom
wkearn:ttcachedir
Mar 30, 2026
Merged

Cache downloaded data files#152
wschwanghart merged 1 commit intoTopoToolbox:mainfrom
wkearn:ttcachedir

Conversation

@wkearn
Copy link
Copy Markdown
Member

@wkearn wkearn commented Mar 30, 2026

Resolves #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.

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]>
@wschwanghart wschwanghart merged commit 6f19897 into TopoToolbox:main Mar 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caching readexample and readopentopo results

2 participants