swirlspy.utils package
Subpackages
Module contents
Utilities
- class swirlspy.utils.FrameType(value)
Bases:
IntFlagData frame value type.
- Z = 1
Reflectivity, Z
- dBR = 10
Decibel relative to rainfall rate, dBmm/h
- dBZ = 9
Decibel relative to reflectivity, dBZ
- mm = 4
Accumulated rainfall depth, mm
- mmph = 2
Rainfall rate, mm/h
- class swirlspy.utils.LazyImport(module_name)
Bases:
objectA proxy class for lazily importing a module upon first attribute access.
Attributes:
module_name (str): The name of the module to import. _module (module or None): The imported module instance, or None if not yet imported.
Args:
module_name (str): The name of the module to be lazily imported.
>>> lazy_numpy = LazyImport('numpy') >>> arr = lazy_numpy.array([1, 2, 3]) # 'numpy' is imported at this point
- swirlspy.utils.add_latlon_ticks(fig, ax, fontsize, frequency)
Adds ticks to projection.
- Parameters:
fig (matplotlib.Figure) – The Figure instance in which the plot is drawn.
ax (matplotlib.axes) – The axes on which the plot is drawn.
fontsize (int) – The fontsize desired.
frequency (float) – The degree intervals.
- swirlspy.utils.get_file(fname=None, origin=None, file_hash=None, cache_subdir='datasets', cache_dir=None, force_download=False, silent=False)
Downloads a file from a URL if it not already in the cache.
By default the file at the url origin is downloaded to the cache_dir ~/.swirlspy, placed in the cache_subdir datasets, and given the filename fname. The final location of a file example.txt would therefore be ~/.swirlspy/datasets/example.txt. Files in .tar, .tar.gz, .tar.bz, and .zip formats can also be extracted.
Passing a hash will verify the file after download. The command line programs shasum and sha256sum can compute the hash.
Example:
```python path_to_downloaded_file = get_file(
)
- param fname:
Name of the file. If an absolute path, e.g. “/path/to/file.txt” is specified, the file will be saved at that location. If None, the name of the file at origin will be used.
- param origin:
Original URL of the file.
- param file_hash:
The expected hash string of the file after download. The sha256 and md5 hash algorithms are both supported.
- param cache_subdir:
Subdirectory under the swirlspy cache dir where the file is saved. If an absolute path, e.g. “/path/to/folder” is specified, the file will be saved at that location.
- param archive_format:
Archive format to try for extracting the file. Options are “auto’, “tar’, “zip’, and None. “tar” includes tar, tar.gz, and tar.bz files. The default “auto” corresponds to [“tar”, “zip”]. None or an empty list will return no matches found.
- param cache_dir:
Location to store cached files, when None it defaults ether $SWIRLSPY_HOME if the SWIRLSPY_HOME environment variable is set or ~/.swirlspy/.
- param force_download:
If True, the file will always be re-downloaded regardless of the cache state.
- returns:
Path to the downloaded file.
⚠️ Warning on malicious downloads ⚠️
Downloading something from the Internet carries a risk. NEVER download a file/archive if you do not trust the source. We enforce that you specify the file_hash argument (if the hash of the source file is known) to make sure that the file you are getting is the one you expect.
- swirlspy.utils.locate_cuda()
Locate the CUDA driver on the system
- Returns:
True (nvidia driver found in the system)
False (nvidia driver not found in the system)
- swirlspy.utils.standardize_attr(frames: DataArray, **kwargs) DataArray
Fill the missing attribute of data frames.
- Parameters:
frames (xarray.DataArray) – Data frames data.
zero_value (float or numpy.nan, optional) – the value assigned to the no rain pixels with the same unit, transformation and accutime of the data. Default : numpy.nan
frame_type (swirlspy.utils.FrameType, optional) – the value indicated frames’ value type.