dep_tools.writers module
This module contains the definition and various implementations of
Writer objects, which are used to write files locally or to the
cloud.
- class dep_tools.writers.DsCogWriter(itempath, write_multithreaded=False, load_before_write=False, write_function=<function write_to_s3>, **kwargs)[source]
Bases:
WriterA
Writerobject which writes anxarray.Datasetto a cloud-optimized GeoTIFF (COG) file or files. A COG is written for each Dataset variable.- Parameters:
itempath (
ItemPath) – TheItemPathused to define the output path.write_multithreaded (
bool) – Whether to use multiple threads (one for each Dataset variable) when writing.load_before_write (
bool) – Whether to load the Dataset before writing. This can be useful to prevent re-reading source data from when multiple variables depend on the same source. data.write_function (
Callable) – The function actually used to write the data. It should take anxarray.DataArrayas the first parameter and the output path (as a string orPath) as a named parameter.**kwargs – Additional arguments to
write_function().
- write(xr, item_id)[source]
Write a
xarray.Dataset.- Parameters:
xr (
Dataset) – The Dataset.item_id (
str) – An item id. It is passed to theItemPathprovided on initialization to determine the output file path.
- Return type:
Union[str,List]
Returns: The output path(s) as a string or list of strings.
- class dep_tools.writers.AwsDsCogWriter(itempath, write_multithreaded=False, load_before_write=False, write_function=<function write_to_s3>, **kwargs)[source]
Bases:
DsCogWriterA
DsCogWriterwhich writes to S3 storage. The only difference is that the ItemPath is anS3ItemPath; itempath.bucket is passed as the bucket keyword argument to write_function.
- class dep_tools.writers.LocalDsCogWriter(**kwargs)[source]
Bases:
DsCogWriterA
DsCogWriterwhich writes to local storage usingdep_tools.utils.write_to_local_storage().A
Writerobject which writes anxarray.Datasetto a cloud-optimized GeoTIFF (COG) file or files. A COG is written for each Dataset variable.- Parameters:
itempath – The
ItemPathused to define the output path.write_multithreaded – Whether to use multiple threads (one for each Dataset variable) when writing.
load_before_write – Whether to load the Dataset before writing. This can be useful to prevent re-reading source data from when multiple variables depend on the same source. data.
write_function – The function actually used to write the data. It should take an
xarray.DataArrayas the first parameter and the output path (as a string orPath) as a named parameter.**kwargs – Additional arguments to
write_function().
- class dep_tools.writers.StacWriter(itempath, write_stac_function=<function write_stac_s3>, **kwargs)[source]
Bases:
WriterA
Writewhich writes spatio-temporal asset catalog (STAC) Items.- Parameters:
itempath (
GenericItemPath) – TheItemPathused to define the output path.write_stac_function (
Callable) – The function used to write a STAC item. It should take the Item as its first argument and the output path as its second.**kwargs – Additional arguments to
write_stac_function().
- class dep_tools.writers.AwsStacWriter(itempath, **kwargs)[source]
Bases:
StacWriterA
StacWriterto write to Amazon S3 Storage.- Parameters:
itempath (
S3ItemPath) – The itempath used to define the output path. itempath.bucket is passed as the bucket keyword argument todep_tools.aws.write_to_s3().**kwargs – Additional arguments to
StacWriter.__init__().
- class dep_tools.writers.LocalStacWriter(itempath, **kwargs)[source]
Bases:
StacWriterA
StacWriterto write to a local file.This class uses
dep_tools.utils.write_to_local_storage()to write the data. It is typically used for testing only.- Parameters:
itempath (
GenericItemPath) – The itempath used to define the output path.**kwargs – Additional arguments to
StacWriter.__init__().