SrtmConf#
- class pycraf.pathprof.SrtmConf[source]#
Bases:
MultiState
Provide a global state to adjust SRTM configuration.
By default,
pycraf
will look for SRTM ‘.hgt’ files (the terrain data) in the SRTMDATA environment variable. If this is not defined, the local directory (‘./’) is used for look-up. It is possible during run-time to change the directory where to look for ‘.hgt’ files with theSrtmConf
manager:from pycraf.pathprof import SrtmConf SrtmConf.set(srtm_dir='/path/to/srtmdir')
This will also check, if all ‘.hgt’ files have the same size. If not an error is raised.
Alternatively, if only a temporary change of the config is desired, one can use
SrtmConf
as a context manager:with SrtmConf.set(srtm_dir='/path/to/srtmdir'): # do stuff
Afterwards, the old settings will be re-established. It is also possible to allow downloading of missing ‘.hgt’ files:
SrtmConf.set(download='missing')
The default behavior is to not download anything (
download='never'
). There is even an option, to always force download (download='always'
).The default download server will be
server='nasa_v2.1'
. One could also use the (very old) data (server='nasa_v1.0'
) or inofficial tiles from viewfinderpanorama (server='viewpano'
).Of course, one can set several of these options simultaneously:
with SrtmConf.set( srtm_dir='/path/to/srtmdir', download='missing', server='viewpano' ): # do stuff
Last, but not least, it is possible to use different interpolation methods. The default method uses bi-linear interpolation (
interp='linear'
). One can also have nearest-neighbor (interp='nearest'
) or spline (interp='spline'
) interpolation. The two former internally useRegularGridInterpolator
, the latter employsRectBivariateSpline
that also allows custom spline degrees (kx
andky
, default: 3) and smoothing factor (s
, default: 0.). To change these use:SrtmConf.set(interp='spline', spline_opts=(k, s))
We refer to
RectBivariateSpline
description for further information.Two read-only attributes are present,
tile_size
(pixels) andhgt_res
(m), which are automatically inferred from the tile data.URLS:
Note: As of Spring 2021, NASA decided to put all SRTM data products behind a log-in page, such that automatic download ceases to work. If you prefer to use NASA tiles (over viewpano), please use their services, e.g., the
Land Processes Distributed Active Archive Center
Attributes Summary
Methods Summary
hook
(**kwargs)A hook which is called everytime when attributes are about to change.
validate
(**kwargs)This checks, if the provided inputs for
download
andserver
are allowed.Attributes Documentation
- download = 'never'#
- hgt_res = 90.0#
- interp = 'linear'#
- server = 'viewpano'#
- spline_opts = (3, 0)#
- srtm_dir = '/home/vsts/work/1/srtm'#
- tile_size = 1201#
Methods Documentation
- classmethod hook(**kwargs)[source]#
A hook which is called everytime when attributes are about to change.
You should override this method if you want to enable pre-processing or monitoring of your attributes. For example, one could use this to react to attribute changes:
>>> from pycraf.utils import MultiState >>> class MyState(MultiState): ... ... _attributes = ('foo', 'bar') ... foo = 1 ... bar = "guido" ... ... @classmethod ... def hook(cls, **kwargs): ... if 'bar' in kwargs: ... if kwargs['bar'] != cls.bar: ... print('{} about to change: {} --> {}'.format( ... 'bar', kwargs['bar'], cls.bar ... )) ... # do stuff ... >>> _ = MyState.set(bar="david") bar about to change: david --> guido >>> _ = MyState.set(bar="david") >>> _ = MyState.set(bar="guido") bar about to change: guido --> david >>> with MyState.set(bar="david"): ... pass bar about to change: david --> guido bar about to change: guido --> david
- classmethod validate(**kwargs)[source]#
This checks, if the provided inputs for
download
andserver
are allowed. Possible values are:download
: ‘never’, ‘missing’, ‘always’server
: ‘viewpano’ # removed: ‘nasa_v2.1’, ‘nasa_v1.0’interp
: ‘nearest’, ‘linear’, ‘spline’spline_opts
: tuple(k, s) (k = degree, s = smoothing factor)