plate_model_manager package
Submodules
plate_model_manager.exceptions module
Bases:
Exception
plate_model_manager.file_fetcher module
- class plate_model_manager.file_fetcher.FileFetcher[source]
Bases:
object
- abstractmethod fetch_file(url: str, filepath: str, filename: str | None = None, etag: str | None = None, auto_unzip: bool = True)[source]
download a file from “url” and save to “filepath” You can give a new “filename” for the file. If “etag” is given, check if etag has changed. If not changed, do not download again.
- Parameters:
url – the url to download file from
filepath – location to keep the file
filename – new file name (optional)
etag – old etag. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- Returns:
new etag
- abstractmethod fetch_files(urls, filepaths, filenames=[], etags=[], auto_unzip: bool = True)[source]
fetch multiple files concurrently
- Parameters:
urls – the urls to download files from
filepaths – location(s) to keep the files. This can be one path for all files or one path for each file.
filenames – new file names (optional)
etags – old etags. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- fetch_large_file(url: str, filepath: str, filename: str | None, filesize: int | None = None, etag: str | None = None, auto_unzip: bool = True, check_etag: bool = True, timeout=(None, None))[source]
- use multi-thread to fetch a large file.
LOOK HERE!!! Be careful when use this function. You cannot get partial content if the content is gzip encoded. So the file might be larger than the one download directly. It is useful when downloading large .zip file. Warning: this could be slower than single thread download. Some firewall sequences these requests to shape network traffic and defeat the purpose of this function completely.
check the etag and get content-length before calling this function
- Parameters:
url – the file url
filepath – location to keep the file
filename – the output filename specified by caller. ignored if auto unzip compressed data.
filesize – the size of file (in bytes)
etag – old etag. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- Returns:
new etag
plate_model_manager.network_aiohttp module
- class plate_model_manager.network_aiohttp.AiohttpFetcher[source]
Bases:
FileFetcher
- fetch_file(url: str, filepath: str, filename: str | None = None, etag: str | None = None, auto_unzip: bool = True)[source]
- download a file from “url” and save to “filepath”
You can give a new “filename” for the file. If “etag” is given, check if etag has changed. If not changed, do not download again.
- Parameters:
url – the url to download file from
filepath – location to keep the file
etag – old etag. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- fetch_files(urls, filepaths, filenames=[], etags=[], auto_unzip: bool = True)[source]
fetch multiple files concurrently
- Parameters:
urls – the urls to download files from
filepaths – location(s) to keep the files. This can be one path for all files or one path for each file.
etags – old etags. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- plate_model_manager.network_aiohttp.fetch_file(url: str, filepath: str, filename: str | None = None, etag: str | None = None, auto_unzip: bool = True)[source]
plate_model_manager.network_requests module
- class plate_model_manager.network_requests.RequestsFetcher[source]
Bases:
FileFetcher
- fetch_file(url: str, filepath: str, filename: str | None = None, etag: str | None = None, auto_unzip: bool = True, timeout=(None, None))[source]
- download a file from “url” and save to “filepath”
You can give a new “filename” for the file. If “etag” is given, check if etag has changed. If not changed, do not download again.
- Parameters:
url – the url to download file from
filepath – location to keep the file
etag – old etag. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- fetch_files(urls, filepaths: list | str, filenames=[], etags=[], auto_unzip: bool = True, timeout=(None, None))[source]
fetch multiple files concurrently
- Parameters:
urls – the urls to download files from
filepaths – location(s) to keep the files. This can be one path for all files or one path for each file.
etags – old etags. if the old etag is the same with the one on server, do not download again.
auto_unzip – bool flag to indicate if unzip .zip file automatically
- plate_model_manager.network_requests.fetch_file(url: str, filepath: str, filename: str | None = None, etag: str | None = None, auto_unzip: bool = True, timeout=(None, None))[source]
plate_model_manager.plate_model module
- class plate_model_manager.plate_model.PlateModel(model_name: str, model_cfg=None, data_dir: str = '.', readonly=False, timeout=(None, None))[source]
Bases:
object
Download and manage files required for a plate reconstruction model.
👀👇 LOOK HERE!!! 👀👇
Normally you should always use
PlateModelManager.get_model()
to get aPlateModel
object. Create aPlateModel
object directly only when you don’t have Internet connection and would like to use the local model files inreadonly
mode. Do not create aPlateModel
object directly if you have no idea what’s going on.- create_model_dir()[source]
Create a folder with a file
.metadata.json
in it to keep the model files.
- download_all_layers()[source]
Download all layers. This function calls
download_layer_files()
on every available layer.
- download_time_dependent_rasters(raster_name, times=None)[source]
Download time-dependent rasters for a given raster name.
Call
get_avail_time_dependent_raster_names()
to see all the available raster names in this model.- Parameters:
raster_name – the raster name of interest
times – if not given, download from begin to end with 1My interval
- get_COBs(return_none_if_not_exist: bool = False) List[str] | None [source]
Return a list of
Continent-Ocean Boundaries
files.
- get_avail_time_dependent_raster_names()[source]
Return all time-dependent raster names in this plate model.
- get_coastlines(return_none_if_not_exist: bool = False) List[str] | None [source]
Return a list of
coastlines
files.
- get_continental_polygons(return_none_if_not_exist: bool = False) List[str] | None [source]
Return a list of
continental polygons
files.
- get_data_dir()[source]
Return the path to a folder (parent folder of the
model dir
) containing a set of downloaded models.
- get_layer(layer_name: str, return_none_if_not_exist: bool = False) List[str] | None [source]
Get a list of layer files by a layer name. Call
get_avail_layers()
to get all the available layer names.Raise
LayerNotFoundInModel
exception to get user’s attention by default. Setreturn_none_if_not_exist
toTrue
if you don’t want to see theLayerNotFoundInModel
exception.- Parameters:
layer_name – The layer name of interest.
return_none_if_not_exist – If set to
True
, returnNone
when the layer does not exist in the model.
- Returns:
A list of file names or
None
ifreturn_none_if_not_exist
is set toTrue
.
:raises
LayerNotFoundInModel
: Raise this exception if the layer name does not exist in this model.
- get_raster(raster_name: str, time: int | float) str [source]
Return a local path for the raster file.
- get_rasters(raster_name: str, times: List[int | float]) List[str] [source]
Return local paths for the raster files.
- Parameters:
times – A list of times
- Returns:
A list of local paths
- get_static_polygons(return_none_if_not_exist: bool = False) List[str] | None [source]
Return a list of
static polygons
files.
- get_topologies(return_none_if_not_exist: bool = False) List[str] | None [source]
Return a list of
topologies
files.
- static is_model_dir(folder_path: str)[source]
Return
True
if the folder contains files of a plate model, otherwiseFalse
.
plate_model_manager.plate_model_manager module
- class plate_model_manager.plate_model_manager.PlateModelManager(model_manifest: str = '', timeout=(None, None))[source]
Bases:
object
Manage a set of public available plate reconstruction models. The model files are hosted on EarthByte servers. You need Internet connection to download the files.
- download_all_models(data_dir: str = './') None [source]
Download all available models into the
data_dir
.- Parameters:
data_dir (str) – The folder to save the model files.
- static get_local_available_model_names(local_dir: str)[source]
Return a list of model names in a local folder.
- Parameters:
local_dir (str) – The local folder containing models.
- get_model(model_name: str = 'default', data_dir: str = '.') PlateModel | None [source]
Return a
PlateModel
object for a given model name.Call
get_available_model_names()
to see a list of available model names.- Parameters:
model_name – the model name of interest
data_dir – The folder to save the model files. This
data_dir
can be changed withPlateModel.set_data_dir()
later.
- Returns:
a
PlateModel
object orNone
if the model name is no good.
plate_model_manager.present_day_rasters module
- class plate_model_manager.present_day_rasters.PresentDayRasterManager(data_dir='present-day-rasters', raster_manifest=None)[source]
Bases:
object
Manage the present-day rasters.
- get_raster(_name: str, width=1800, height=800, bbox=[-180, -80, 180, 80], large_file_hint=True)[source]
Download a raster file by name, save the raster file in
self.data_dir
and return the local path to the raster file.Call
list_present_day_rasters()
to see a list of available present-day raster names.