Miscellaneous API#
wget()#
- planetary_coverage.misc.wget(url, fout, skip=False, force=False)[source]#
Web download.
- Parameters:
url (str) – URL to download
fout (str or pathlib.Path) – Output file.
skip (bool, optional) – Skip download if the output file already exists (default: False). Has the priority over
force.force (bool, optional) – Force download even if the file exists (default: False).
- Returns:
Downloaded file path.
- Return type:
- Raises:
ValueError – If the URL provided is not starting with http[s]://.
FileExistsError – If the file already exists and force is False (default).
Note
The missing sub-directories will be created.
By default, logging is set at INFO level. Use
debug_download()function to increase or disable the logging output.
Segment#
- class planetary_coverage.misc.Segment(arr)[source]#
Bases:
objectSegments object on conditional list.
- Parameters:
arr (numpy.ndarray) – Conditional list.
- property starts#
Get segment starts.
- property stops#
Get segment stops.
- property singles#
Get segment isolated single points.
- property inside#
Get segment inside points.
- property outside#
Get segment outside points.
- property istarts#
Segment starts indexes.
- property istops#
Segment stops indexes.
- property slices#
Segment slices.
rindex()#
- planetary_coverage.misc.rindex(lst, value)[source]#
Search the last index reference of a value in a list.
Solution from Stackoverflow: https://stackoverflow.com/a/63834895
Cache#
@cached_property#
- @planetary_coverage.misc.cached_property(method=None, *, parent=None)[source]#
Cached class property decorator attribute.
Can be used in the following forms:
@cached_property@cached_property()@cached_property(parent='my_parent')@cached_property(parent=('my_parent_1', ...))@cached_property(parent=['my_parent_1', ...])@cached_property(parent={'my_parent_1', ...})
- Parameters:
Note
To remove a single cached attributed, use the
delattr()function or thedelkeyword. In that case, all the child cached property will also be cleared.To clear the cache globally on this object, use the
clear_cache()method.Warning
This caching strategy is not thread-safe contrary to the functools method.
Depreciation#
@depreciated#
DepreciationHelper#
Env variable and dotenv file#
getenv()#
- planetary_coverage.misc.getenv(key: str, default: str = None, max_parents: int = None, dotenv: str = '.env') str[source]#
Get environnement variables from dotenv file or globally.
- Parameters:
key (str) – Key to query on the environment
default (str, optional) – Optional value if not found.
max_parents (int, optional) – Max number of parent to check recursively for a
.envfile. To search only the current parent setmax_parents=0. Default:None.dotenv (str, optional) – Dotenv file to search (default:
'.env'). To load only the global variables setdotenv=None.
- Returns:
Environment variable value. None, if not found.
- Return type:
Note
The function first search for a
.envfile in the current working directory, then in its parents up to the root. If a.envfile is found, the search is stopped and the file is parsed for key-values. If not present, the function will search globally if the value is present.
find_dotenv()#
print_kernels_dir()#
%load_ext planetary_coverage#
File size#
file_size()#
- planetary_coverage.misc.file_size(*fname, fmt=',.0f', skip=False) str[source]#
Get filesize as human string.
- Parameters:
*fname (str or pathlib.Path) – Filename(s) to measure.
fmt (str, optional) – Size format. Default:
',.0f'.skip (bool, optional) – Skip error handling and return zero-size if the file does not exists. Default:
False.
- Returns:
Filesize human string. If multiple files are provided, it returns the sum of their combined sizes.
- Return type:
- Raises:
FileNotFoundError – If the file does not exist.
get_size()#
- planetary_coverage.misc.filesize.get_size(fname, skip=False) int[source]#
Get filename size.
- Parameters:
fname (str or pathlib.Path) – File name to measure.
skip (bool, optional) – Skip error handling and return zero-size if the file does not exists. Default:
False.
- Returns:
Filesize as bytes.
- Return type:
- Raises:
FileNotFoundError – If the file does not exist.