satpy package¶
Subpackages¶
- satpy.composites package
- satpy.enhancements package
- satpy.readers package
- Submodules
- satpy.readers.aapp_l1b module
- satpy.readers.abi_l1b module
- satpy.readers.acspo module
- satpy.readers.ahi_hsd module
- satpy.readers.amsr2_l1b module
- satpy.readers.avhrr_l1b_gaclac module
- satpy.readers.caliop_l2_cloud module
- satpy.readers.clavrx module
- satpy.readers.electrol_hrit module
- satpy.readers.eps_l1b module
- satpy.readers.eum_base module
- satpy.readers.fci_l1c_fdhsi module
- satpy.readers.file_handlers module
- satpy.readers.generic_image module
- satpy.readers.geocat module
- satpy.readers.ghrsst_l3c_sst module
- satpy.readers.goes_imager_hrit module
- satpy.readers.goes_imager_nc module
- satpy.readers.grib module
- satpy.readers.hdf4_utils module
- satpy.readers.hdf5_utils module
- satpy.readers.hrit_base module
- satpy.readers.hrit_jma module
- satpy.readers.hrpt module
- satpy.readers.iasi_l2 module
- satpy.readers.li_l2 module
- satpy.readers.maia module
- satpy.readers.modis_l1b module
- satpy.readers.msi_safe module
- satpy.readers.netcdf_utils module
- satpy.readers.nucaps module
- satpy.readers.nwcsaf_nc module
- satpy.readers.olci_nc module
- satpy.readers.omps_edr module
- satpy.readers.sar_c_safe module
- satpy.readers.scatsat1_l2b module
- satpy.readers.scmi module
- satpy.readers.seviri_base module
- satpy.readers.seviri_l1b_hrit module
- satpy.readers.seviri_l1b_native module
- satpy.readers.seviri_l1b_native_hdr module
- satpy.readers.seviri_l1b_nc module
- satpy.readers.slstr_l1b module
- satpy.readers.utils module
- satpy.readers.viirs_compact module
- satpy.readers.viirs_edr_flood module
- satpy.readers.viirs_l1b module
- satpy.readers.viirs_sdr module
- satpy.readers.xmlformat module
- satpy.readers.yaml_reader module
- Module contents
- satpy.writers package
Submodules¶
satpy.config module¶
SatPy Configuration directory and file handling
-
satpy.config.
check_satpy
()¶ Check the satpy readers and writers for correct installation.
-
satpy.config.
check_yaml_configs
(configs, key, hdr_len)¶ Get a diagnostic for the yaml configs.
key is the section to look for to get a name for the config at hand. hdr_len is the number of lines that can be safely read from the config to get a name.
-
satpy.config.
config_search_paths
(filename, *search_dirs, **kwargs)¶
-
satpy.config.
get_config
(filename, *search_dirs, **kwargs)¶ Blends the different configs, from package defaults to .
-
satpy.config.
get_config_path
(filename, *search_dirs)¶ Get the appropriate path for a filename, in that order: filename, ., PPP_CONFIG_DIR, package’s etc dir.
-
satpy.config.
get_environ_ancpath
(default='.')¶
-
satpy.config.
get_environ_config_dir
(default='/build/satpy-0.11.1/satpy/etc')¶
-
satpy.config.
glob_config
(pattern, *search_dirs)¶ Return glob results for all possible configuration locations.
- Note: This method does not check the configuration “base” directory if the pattern includes a subdirectory.
- This is done for performance since this is usually used to find all configs for a certain component.
-
satpy.config.
recursive_dict_update
(d, u)¶ Recursive dictionary update.
Copied from:
-
satpy.config.
runtime_import
(object_path)¶ Import at runtime.
satpy.dataset module¶
Dataset objects.
-
class
satpy.dataset.
Dataset
¶ Bases:
object
Placeholder for the deprecated class.
-
class
satpy.dataset.
DatasetID
¶ Bases:
satpy.dataset.DatasetID
Identifier for all Dataset objects.
DatasetID is a namedtuple that holds identifying and classifying information about a Dataset. There are two identifying elements,
name
andwavelength
. These can be used to generically refer to a Dataset. The other elements of a DatasetID are meant to further distinguish a Dataset from the possible variations it may have. For example multiple Datasets may be called by onename
but may exist in multiple resolutions or with different calibrations such as “radiance” and “reflectance”. If an element is None then it is considered not applicable.A DatasetID can also be used in SatPy to query for a Dataset. This way a fully qualified DatasetID can be found even if some of the DatasetID elements are unknown. In this case a None signifies something that is unknown or not applicable to the requested Dataset.
Parameters: - name (str) – String identifier for the Dataset
- wavelength (float, tuple) – Single float wavelength when querying for a Dataset. Otherwise 3-element tuple of floats specifying the minimum, nominal, and maximum wavelength for a Dataset. None if not applicable.
- resolution (int, float) – Per data pixel/area resolution. If resolution varies across the Dataset then nadir view resolution is preferred. Usually this is in meters, but for lon/lat gridded data angle degrees may be used.
- polarization (str) – ‘V’ or ‘H’ polarizations of a microwave channel. None if not applicable.
- calibration (str) – String identifying the calibration level of the Dataset (ex. ‘radiance’, ‘reflectance’, etc). None if not applicable.
- level (int, float) – Pressure/altitude level of the dataset. This is typically in hPa, but may be in inverse meters for altitude datasets (1/meters).
- modifiers (tuple) – Tuple of strings identifying what corrections or other modifications have been performed on this Dataset (ex. ‘sunz_corrected’, ‘rayleigh_corrected’, etc). None or empty tuple if not applicable.
-
classmethod
from_dict
(d, **kwargs)¶ Convert a dict to an ID.
-
static
name_match
(a, b)¶ Return if two string names are equal.
Parameters: - a (str) – DatasetID.name or other string
- b (str) – DatasetID.name or other string
-
to_dict
(trim=True)¶ Convert the ID to a dict.
-
static
wavelength_match
(a, b)¶ Return if two wavelengths are equal.
Parameters: - a (tuple or scalar) – (min wl, nominal wl, max wl) or scalar wl
- b (tuple or scalar) – (min wl, nominal wl, max wl) or scalar wl
-
class
satpy.dataset.
MetadataObject
(**attributes)¶ Bases:
object
A general metadata object.
Initialize the class with attributes.
-
id
¶ Return the DatasetID of the object.
-
-
satpy.dataset.
average_datetimes
(dt_list)¶ Average a series of datetime objects.
Note
This function assumes all datetime objects are naive and in the same time zone (UTC).
Parameters: dt_list (iterable) – Datetime objects to average Returns: Average datetime as a datetime object
-
satpy.dataset.
combine_metadata
(*metadata_objects, **kwargs)¶ Combine the metadata of two or more Datasets.
If any keys are not equal or do not exist in all provided dictionaries then they are not included in the returned dictionary. By default any keys with the word ‘time’ in them and consisting of datetime objects will be averaged. This is to handle cases where data were observed at almost the same time but not exactly.
Parameters: - *metadata_objects – MetadataObject or dict objects to combine
- average_times (bool) – Average any keys with ‘time’ in the name
Returns: the combined metadata
Return type: dict
-
satpy.dataset.
dataset_walker
(datasets)¶ Walk through datasets and their ancillary data.
Yields datasets and their parent.
-
satpy.dataset.
replace_anc
(dataset, parent_dataset)¶ Replace dataset the parent_dataset’s ancillary_variables field.
satpy.multiscene module¶
MultiScene object to blend satellite data.
-
class
satpy.multiscene.
MultiScene
(scenes=None)¶ Bases:
object
Container for multiple Scene objects.
Initialize MultiScene and validate sub-scenes.
Parameters: scenes (iterable) – Scene objects to operate on (optional) Note
If the scenes passed to this object are a generator then certain operations performed will try to preserve that generator state. This may limit what properties or methods are available to the user. To avoid this behavior compute the passed generator by converting the passed scenes to a list first:
MultiScene(list(scenes))
.-
all_same_area
¶
-
blend
(blend_function=<function stack>)¶ Blend the datasets into one scene.
Note
Blending is not currently optimized for generator-based MultiScene.
-
is_generator
¶ Contained Scenes are stored as a generator.
-
load
(*args, **kwargs)¶ Load the required datasets from the multiple scenes.
-
loaded_dataset_ids
¶ Union of all Dataset IDs loaded by all children.
-
resample
(destination=None, **kwargs)¶ Resample the multiscene.
-
save_animation
(filename, datasets=None, fps=10, fill_value=None, batch_size=None, ignore_missing=False, **kwargs)¶ Helper method for saving to movie or GIF formats.
Supported formats are dependent on the imageio library and are determined by filename extension by default.
By default all datasets available will be saved to individual files using the first Scene’s datasets metadata to format the filename provided. If a dataset is not available from a Scene then a black array is used instead (np.zeros(shape)).
Parameters: - filename (str) – Filename to save to. Can include python string
formatting keys from dataset
.attrs
(ex. “{name}_{start_time:%Y%m%d_%H%M%S.gif”) - datasets (list) – DatasetIDs to save (default: all datasets)
- fps (int) – Frames per second for produced animation
- fill_value (int) – Value to use instead creating an alpha band.
- batch_size (int) – Group array computation in to this many arrays at a time. This is useful to avoid memory issues. Defaults to all of the arrays at once.
- ignore_missing (bool) – Don’t include a black frame when a dataset is missing from a child scene.
- kwargs – Additional keyword arguments to pass to imageio.get_writer.
- filename (str) – Filename to save to. Can include python string
formatting keys from dataset
-
scenes
¶ Get list of Scene objects contained in this MultiScene.
Note
If the Scenes contained in this object are stored in a generator (not list or tuple) then accessing this property will load/iterate through the generator possibly
Dataset IDs shared by all children.
-
-
satpy.multiscene.
cascaded_compute
(callback, arrays, batch_size=None, optimize=True)¶ Dask helper function for iterating over computed dask arrays.
Parameters: - callback (callable) – Called with a single numpy array computed from the provided dask arrays.
- arrays (list, tuple) – Dask arrays to pass to callback.
- batch_size (int) – Group computation in to this many arrays at a time.
- optimize (bool) – Whether to try to optimize the dask graphs of the provided arrays.
Returns: dask.Delayed object to be computed
-
satpy.multiscene.
stack
(datasets)¶ First dataset at the bottom.
satpy.node module¶
Nodes to build trees.
-
class
satpy.node.
DependencyTree
(readers, compositors, modifiers)¶ Bases:
satpy.node.Node
Structure to discover and store Dataset dependencies
Used primarily by the Scene object to organize dependency finding. Dependencies are stored used a series of Node objects which this class is a subclass of.
Collect Dataset generating information.
Collect the objects that generate and have information about Datasets including objects that may depend on certain Datasets being generated. This includes readers, compositors, and modifiers.
Parameters: - readers (dict) – Reader name -> Reader Object
- compositors (dict) – Sensor name -> Composite ID -> Composite Object
- modifiers (dict) – Sensor name -> Modifier name -> (Modifier Class, modifier options)
-
add_child
(parent, child)¶ Add a child to the node.
-
add_leaf
(ds_id, parent=None)¶
-
contains
(item)¶ Check contains when we know the exact DatasetID.
-
copy
()¶ Copy the this node tree
Note all references to readers are removed. This is meant to avoid tree copies accessing readers that would return incompatible (Area) data. Theoretically it should be possible for tree copies to request compositor or modifier information as long as they don’t depend on any datasets not already existing in the dependency tree.
-
find_dependencies
(dataset_keys, **dfilter)¶ Create the dependency tree.
Parameters: - dataset_keys (iterable) – Strings or DatasetIDs to find dependencies for
- **dfilter (dict) – Additional filter parameters. See satpy.readers.get_key for more details.
Returns: Root node of the dependency tree and a set of unknown datasets
Return type: (Node, set)
-
get_compositor
(key)¶
-
get_modifier
(comp_id)¶
-
getitem
(item)¶ Get Node when we know the exact DatasetID.
-
leaves
(nodes=None, unique=True)¶ Get the leaves of the tree starting at this root.
Parameters: - nodes (iterable) – limit leaves for these node names
- unique – only include individual leaf nodes once
Returns: list of leaf nodes
-
trunk
(nodes=None, unique=True)¶ Get the trunk nodes of the tree starting at this root.
Parameters: - nodes (iterable) – limit trunk nodes to the names specified or the children of them that are also trunk nodes.
- unique – only include individual trunk nodes once
Returns: list of trunk nodes
-
class
satpy.node.
Node
(name, data=None)¶ Bases:
object
A node object.
Init the node object.
-
add_child
(obj)¶ Add a child to the node.
-
copy
(node_cache=None)¶
-
display
(previous=0, include_data=False)¶ Display the node.
-
flatten
(d=None)¶ Flatten tree structure to a one level dictionary.
Parameters: d (dict, optional) – output dictionary to update Returns: - Node.name -> Node. The returned dictionary includes the
- current Node and all its children.
Return type: dict
-
is_leaf
¶
-
leaves
(unique=True)¶ Get the leaves of the tree starting at this root.
-
trunk
(unique=True)¶ Get the trunk of the tree starting at this root.
-
satpy.plugin_base module¶
The satpy.plugin_base
module defines the plugin API.
-
class
satpy.plugin_base.
Plugin
(ppp_config_dir=None, default_config_filename=None, config_files=None, **kwargs)¶ Bases:
object
Base plugin class for all dynamically loaded and configured objects.
Load configuration files related to this plugin.
This initializes a self.config dictionary that can be used to customize the subclass.
Parameters: - ppp_config_dir (str) – Base “etc” directory for all configuration files.
- default_config_filename (str) – Configuration filename to use if no other files have been specified with config_files.
- config_files (list or str) – Configuration files to load instead of those automatically found in ppp_config_dir and other default configuration locations.
- kwargs (dict) – Unused keyword arguments.
-
load_yaml_config
(conf)¶ Load a YAML configuration file and recursively update the overall configuration.
satpy.resample module¶
SatPy provides multiple resampling algorithms for resampling geolocated
data to uniform projected grids. The easiest way to perform resampling in
SatPy is through the Scene
object’s
resample()
method. Additional utility functions are
also available to assist in resampling data. Below is more information on
resampling with SatPy as well as links to the relevant API documentation for
available keyword arguments.
Resampling algorithms¶
Resampler | Description | Related |
---|---|---|
nearest | Nearest Neighbor | KDTreeResampler |
ewa | Elliptical Weighted Averaging | EWAResampler |
native | Native | NativeResampler |
bilinear | Bilinear | :class`~satpy.resample.BilinearResampler` |
The resampling algorithm used can be specified with the resampler
keyword
argument and defaults to nearest
:
>>> scn = Scene(...)
>>> euro_scn = global_scene.resample('euro4', resampler='nearest')
Warning
Some resampling algorithms expect certain forms of data. For example, the EWA resampling expects polar-orbiting swath data and prefers if the data can be broken in to “scan lines”. See the API documentation for a specific algorithm for more information.
Resampling for comparison and composites¶
While all the resamplers can be used to put datasets of different resolutions on to a common area, the ‘native’ resampler is designed to match datasets to one resolution in the dataset’s original projection. This is extremely useful when generating composites between bands of different resolutions.
>>> new_scn = scn.resample(resampler='native')
By default this resamples to the
highest resolution area
(smallest footprint per
pixel) shared between the loaded datasets. You can easily specify the lower
resolution area:
>>> new_scn = scn.resample(scn.min_area(), resampler='native')
Providing an area that is neither the minimum or maximum resolution area may work, but behavior is currently undefined.
Caching for geostationary data¶
SatPy will do its best to reuse calculations performed to resample datasets,
but it can only do this for the current processing and will lose this
information when the process/script ends. Some resampling algorithms, like
nearest
and bilinear
, can benefit by caching intermediate data on disk in the directory
specified by cache_dir and using it next time. This is most beneficial with
geostationary satellite data where the locations of the source data and the
target pixels don’t change over time.
>>> new_scn = scn.resample('euro4', cache_dir='/path/to/cache_dir')
See the documentation for specific algorithms to see availability and limitations of caching for that algorithm.
Create custom area definition¶
See pyresample.geometry.AreaDefinition
for information on creating
areas that can be passed to the resample method:
>>> from pyresample.geometry import AreaDefinition
>>> my_area = AreaDefinition(...)
>>> local_scene = global_scene.resample(my_area)
Create dynamic area definition¶
See pyresample.geometry.DynamicAreaDefinition
for more information.
Examples coming soon…
Store area definitions¶
Area definitions can be added to a custom YAML file (see pyresample’s documentation for more information) and loaded using pyresample’s utility methods:
>>> from pyresample.utils import parse_area_file
>>> my_area = parse_area_file('my_areas.yaml', 'my_area')[0]
Examples coming soon…
-
class
satpy.resample.
BaseResampler
(source_geo_def, target_geo_def)¶ Bases:
object
Base abstract resampler class.
Initialize resampler with geolocation information.
Parameters: - source_geo_def (SwathDefinition, AreaDefinition) – Geolocation definition for the data to be resampled
- target_geo_def (CoordinateDefinition, AreaDefinition) – Geolocation definition for the area to resample data to.
-
compute
(data, **kwargs)¶ Do the actual resampling.
This must be implemented by subclasses.
-
get_hash
(source_geo_def=None, target_geo_def=None, **kwargs)¶ Get hash for the current resample with the given kwargs.
-
precompute
(**kwargs)¶ Do the precomputation.
This is an optional step if the subclass wants to implement more complex features like caching or can share some calculations between multiple datasets to be processed.
-
resample
(data, cache_dir=None, mask_area=None, **kwargs)¶ Resample data by calling precompute and compute methods.
Only certain resampling classes may use cache_dir and the mask provided when mask_area is True. The return value of calling the precompute method is passed as the cache_id keyword argument of the compute method, but may not be used directly for caching. It is up to the individual resampler subclasses to determine how this is used.
Parameters: - data (xarray.DataArray) – Data to be resampled
- cache_dir (str) – directory to cache precomputed results (default False, optional)
- mask_area (bool) – Mask geolocation data where data values are invalid. This should be used when data values may affect what neighbors are considered valid.
Returns (xarray.DataArray): Data resampled to the target area
-
class
satpy.resample.
BilinearResampler
(source_geo_def, target_geo_def)¶ Bases:
satpy.resample.BaseResampler
Resample using bilinear.
-
compute
(data, fill_value=None, **kwargs)¶ Resample the given data using bilinear interpolation
-
load_bil_info
(cache_dir, **kwargs)¶
-
precompute
(mask=None, radius_of_influence=50000, epsilon=0, reduce_data=True, nprocs=1, cache_dir=False, **kwargs)¶ Create bilinear coefficients and store them for later use.
Note: The mask keyword should be provided if geolocation may be valid where data points are invalid. This defaults to the mask attribute of the data numpy masked array passed to the resample method.
-
save_bil_info
(cache_dir, **kwargs)¶
-
-
class
satpy.resample.
EWAResampler
(source_geo_def, target_geo_def)¶ Bases:
satpy.resample.BaseResampler
Resample using an elliptical weighted averaging algorithm.
This algorithm does not use caching or any externally provided data mask (unlike the ‘nearest’ resampler).
This algorithm works under the assumption that the data is observed one scan line at a time. However, good results can still be achieved for non-scan based data provided rows_per_scan is set to the number of rows in the entire swath or by setting it to None.
Parameters: - rows_per_scan (int, None) – Number of data rows for every observed scanline. If None then the entire swath is treated as one large scanline.
- weight_count (int) – number of elements to create in the gaussian weight table. Default is 10000. Must be at least 2
- weight_min (float) – the minimum value to store in the last position of the weight table. Default is 0.01, which, with a weight_distance_max of 1.0 produces a weight of 0.01 at a grid cell distance of 1.0. Must be greater than 0.
- weight_distance_max (float) – distance in grid cell units at which to apply a weight of weight_min. Default is 1.0. Must be greater than 0.
- weight_delta_max (float) – maximum distance in grid cells in each grid dimension over which to distribute a single swath cell. Default is 10.0.
- weight_sum_min (float) – minimum weight sum value. Cells whose weight sums are less than weight_sum_min are set to the grid fill value. Default is EPSILON.
- maximum_weight_mode (bool) – If False (default), a weighted average of all swath cells that map to a particular grid cell is used. If True, the swath cell having the maximum weight of all swath cells that map to a particular grid cell is used. This option should be used for coded/category data, i.e. snow cover.
-
compute
(data, cache_id=None, fill_value=0, weight_count=10000, weight_min=0.01, weight_distance_max=1.0, weight_delta_max=1.0, weight_sum_min=-1.0, maximum_weight_mode=False, grid_coverage=0, **kwargs)¶ Resample the data according to the precomputed X/Y coordinates.
-
precompute
(cache_dir=None, swath_usage=0, **kwargs)¶ Generate row and column arrays and store it for later use.
-
resample
(*args, **kwargs)¶ Run precompute and compute methods.
Note
This sets the default of ‘mask_area’ to False since it is not needed in EWA resampling currently.
-
class
satpy.resample.
KDTreeResampler
(source_geo_def, target_geo_def)¶ Bases:
satpy.resample.BaseResampler
Resample using a KDTree-based nearest neighbor algorithm.
This resampler implements on-disk caching when the cache_dir argument is provided to the resample method. This should provide significant performance improvements on consecutive resampling of geostationary data. It is not recommended to provide cache_dir when the mask keyword argument is provided to precompute which occurs by default for SwathDefinition source areas.
Parameters: - cache_dir (str) – Long term storage directory for intermediate results. By default only 10 different source/target combinations are cached to save space.
- mask_area (bool) – Force resampled data’s invalid pixel mask to be used when searching for nearest neighbor pixels. By default this is True for SwathDefinition source areas and False for all other area definition types.
- radius_of_influence (float) – Search radius cut off distance in meters
- epsilon (float) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time.
-
compute
(data, weight_funcs=None, fill_value=nan, with_uncert=False, **kwargs)¶ Do the actual resampling.
This must be implemented by subclasses.
-
load_neighbour_info
(cache_dir, mask=None, **kwargs)¶ Read index arrays from either the in-memory or disk cache.
-
precompute
(mask=None, radius_of_influence=None, epsilon=0, cache_dir=None, **kwargs)¶ Create a KDTree structure and store it for later use.
Note: The mask keyword should be provided if geolocation may be valid where data points are invalid.
-
save_neighbour_info
(cache_dir, mask=None, **kwargs)¶ Cache resampler’s index arrays if there is a cache dir.
-
class
satpy.resample.
NativeResampler
(source_geo_def, target_geo_def)¶ Bases:
satpy.resample.BaseResampler
Expand or reduce input datasets to be the same shape.
If data is higher resolution (more pixels) than the destination area then data is averaged to match the destination resolution.
If data is lower resolution (less pixels) than the destination area then data is repeated to match the destination resolution.
This resampler does not perform any caching or masking due to the simplicity of the operations.
Initialize resampler with geolocation information.
Parameters: - source_geo_def (SwathDefinition, AreaDefinition) – Geolocation definition for the data to be resampled
- target_geo_def (CoordinateDefinition, AreaDefinition) – Geolocation definition for the area to resample data to.
-
static
aggregate
(d, y_size, x_size)¶ Average every 4 elements (2x2) in a 2D array
-
compute
(data, expand=True, **kwargs)¶ Do the actual resampling.
This must be implemented by subclasses.
-
classmethod
expand_reduce
(d_arr, repeats)¶
-
resample
(data, cache_dir=None, mask_area=False, **kwargs)¶ Resample data by calling precompute and compute methods.
Only certain resampling classes may use cache_dir and the mask provided when mask_area is True. The return value of calling the precompute method is passed as the cache_id keyword argument of the compute method, but may not be used directly for caching. It is up to the individual resampler subclasses to determine how this is used.
Parameters: - data (xarray.DataArray) – Data to be resampled
- cache_dir (str) – directory to cache precomputed results (default False, optional)
- mask_area (bool) – Mask geolocation data where data values are invalid. This should be used when data values may affect what neighbors are considered valid.
Returns (xarray.DataArray): Data resampled to the target area
-
satpy.resample.
get_area_def
(area_name)¶ Get the definition of area_name from file.
The file is defined to use is to be placed in the $PPP_CONFIG_DIR directory, and its name is defined in satpy’s configuration file.
-
satpy.resample.
get_area_file
()¶ Find area file(s) to use.
The files are to be named areas.yaml or areas.def.
-
satpy.resample.
get_fill_value
(dataset)¶ Get the fill value of the dataset, defaulting to np.nan.
-
satpy.resample.
hash_dict
(the_dict, the_hash=None)¶
-
satpy.resample.
prepare_resampler
(source_area, destination_area, resampler=None, **resample_kwargs)¶ Instantiate and return a resampler.
-
satpy.resample.
resample
(source_area, data, destination_area, resampler=None, **kwargs)¶ Do the resampling.
-
satpy.resample.
resample_dataset
(dataset, destination_area, **kwargs)¶ Resample dataset and return the resampled version.
Parameters: - dataset (xarray.DataArray) – Data to be resampled.
- destination_area – The destination onto which to project the data, either a full blown area definition or a string corresponding to the name of the area as defined in the area file.
- **kwargs – The extra parameters to pass to the resampler objects.
Returns: A resampled DataArray with updated
.attrs["area"]
field. The dtype of the array is preserved.
satpy.scene module¶
Scene objects to hold satellite data.
-
class
satpy.scene.
Scene
(filenames=None, reader=None, filter_parameters=None, reader_kwargs=None, ppp_config_dir='/build/satpy-0.11.1/satpy/etc', base_dir=None, sensor=None, start_time=None, end_time=None, area=None)¶ Bases:
satpy.dataset.MetadataObject
The Almighty Scene Class.
Example usage:
from satpy import Scene from glob import glob # create readers and open files scn = Scene(filenames=glob('/path/to/files/*'), reader='viirs_sdr') # load datasets from input files scn.load(['I01', 'I02']) # resample from satellite native geolocation to builtin 'eurol' Area new_scn = scn.resample('eurol') # save all resampled datasets to geotiff files in the current directory new_scn.save_datasets()
Initialize Scene with Reader and Compositor objects.
To load data filenames and preferably reader must be specified. If filenames is provided without reader then the available readers will be searched for a Reader that can support the provided files. This can take a considerable amount of time so it is recommended that reader always be provided. Note without filenames the Scene is created with no Readers available requiring Datasets to be added manually:
scn = Scene() scn['my_dataset'] = Dataset(my_data_array, **my_info)
Parameters: - filenames (iterable or dict) – A sequence of files that will be used to load data from. A
dict
object should map reader names to a list of filenames for that reader. - reader (str or list) – The name of the reader to use for loading the data or a list of names.
- filter_parameters (dict) – Specify loaded file filtering parameters. Shortcut for reader_kwargs[‘filter_parameters’].
- reader_kwargs (dict) – Keyword arguments to pass to specific reader instances.
- ppp_config_dir (str) – The directory containing the configuration files for satpy.
- base_dir (str) – (DEPRECATED) The directory to search for files containing the data to load. If filenames is also provided, this is ignored.
- sensor (list or str) – (DEPRECATED: Use find_files_and_readers function) Limit used files by provided sensors.
- area (AreaDefinition) – (DEPRECATED: Use filter_parameters) Limit used files by geographic area.
- start_time (datetime) – (DEPRECATED: Use filter_parameters) Limit used files by starting time.
- end_time (datetime) – (DEPRECATED: Use filter_parameters) Limit used files by ending time.
-
all_composite_ids
(sensor_names=None)¶ Get all composite IDs that are configured.
Returns: generator of configured composite names
-
all_composite_names
(sensor_names=None)¶
-
all_dataset_ids
(reader_name=None, composites=False)¶ Get names of all datasets from loaded readers or reader_name if specified..
Returns: list of all dataset names
-
all_dataset_names
(reader_name=None, composites=False)¶
-
all_modifier_names
()¶
-
all_same_area
¶ All contained data arrays are on the same area.
-
all_same_proj
¶ All contained data array are in the same projection.
-
available_composite_ids
(available_datasets=None)¶ Get names of compositors that can be generated from the available datasets.
Returns: generator of available compositor’s names
-
available_composite_names
(available_datasets=None)¶ All configured composites known to this Scene.
-
available_dataset_ids
(reader_name=None, composites=False)¶ Get names of available datasets, globally or just for reader_name if specified, that can be loaded.
Available dataset names are determined by what each individual reader can load. This is normally determined by what files are needed to load a dataset and what files have been provided to the scene/reader.
Returns: list of available dataset names
-
available_dataset_names
(reader_name=None, composites=False)¶ Get the list of the names of the available datasets.
-
copy
(datasets=None)¶ Create a copy of the Scene including dependency information.
Parameters: datasets (list, tuple) – DatasetID objects for the datasets to include in the new Scene object.
-
create_reader_instances
(filenames=None, reader=None, reader_kwargs=None)¶ Find readers and return their instances.
-
crop
(area=None, ll_bbox=None, xy_bbox=None, dataset_ids=None)¶ Crop Scene to a specific Area boundary or bounding box.
Parameters: - area (AreaDefinition) – Area to crop the current Scene to
- ll_bbox (tuple, list) – 4-element tuple where values are in
lon/lat degrees. Elements are
(xmin, ymin, xmax, ymax)
where X is longitude and Y is latitude. - xy_bbox (tuple, list) – Same as ll_bbox but elements are in projection units.
- dataset_ids (iterable) – DatasetIDs to include in the returned Scene. Defaults to all datasets.
This method will attempt to intelligently slice the data to preserve relationships between datasets. For example, if we are cropping two DataArrays of 500m and 1000m pixel resolution then this method will assume that exactly 4 pixels of the 500m array cover the same geographic area as a single 1000m pixel. It handles these cases based on the shapes of the input arrays and adjusting slicing indexes accordingly. This method will have trouble handling cases where data arrays seem related but don’t cover the same geographic area or if the coarsest resolution data is not related to the other arrays which are related.
It can be useful to follow cropping with a call to the native resampler to resolve all datasets to the same resolution and compute any composites that could not be generated previously:
>>> cropped_scn = scn.crop(ll_bbox=(-105., 40., -95., 50.)) >>> remapped_scn = cropped_scn.resample(resampler='native')
Note
The resample method automatically crops input data before resampling to save time/memory.
-
end_time
¶ Return the end time of the file.
-
generate_composites
(nodes=None)¶ Compute all the composites contained in requirements.
-
get
(key, default=None)¶ Return value from DatasetDict with optional default.
-
classmethod
get_writer_by_ext
(extension)¶ Find the writer matching the extension.
-
images
()¶ Generate images for all the datasets from the scene.
-
iter_by_area
()¶ Generate datasets grouped by Area.
Returns: generator of (area_obj, list of dataset objects)
-
keys
(**kwargs)¶
-
load
(wishlist, calibration=None, resolution=None, polarization=None, level=None, generate=True, unload=True, **kwargs)¶ Read and generate requested datasets.
When the wishlist contains DatasetID objects they can either be fully-specified DatasetID objects with every parameter specified or they can not provide certain parameters and the “best” parameter will be chosen. For example, if a dataset is available in multiple resolutions and no resolution is specified in the wishlist’s DatasetID then the highest (smallest number) resolution will be chosen.
Loaded DataArray objects are created and stored in the Scene object.
Parameters: - wishlist (iterable) – Names (str), wavelengths (float), or DatasetID objects of the requested datasets to load. See available_dataset_ids() for what datasets are available.
- calibration (list, str) – Calibration levels to limit available datasets. This is a shortcut to having to list each DatasetID in wishlist.
- resolution (list | float) – Resolution to limit available datasets. This is a shortcut similar to calibration.
- polarization (list | str) – Polarization (‘V’, ‘H’) to limit available datasets. This is a shortcut similar to calibration.
- level (list | str) – Pressure level to limit available datasets. Pressure should be in hPa or mb. If an altitude is used it should be specified in inverse meters (1/m). The units of this parameter ultimately depend on the reader.
- generate (bool) – Generate composites from the loaded datasets (default: True)
- unload (bool) – Unload datasets that were required to generate the requested datasets (composite dependencies) but are no longer needed.
-
max_area
(datasets=None)¶ Get highest resolution area for the provided datasets.
Parameters: datasets (iterable) – Datasets whose areas will be compared. Can be either xarray.DataArray objects or identifiers to get the DataArrays from the current Scene. Defaults to all datasets.
-
min_area
(datasets=None)¶ Get lowest resolution area for the provided datasets.
Parameters: datasets (iterable) – Datasets whose areas will be compared. Can be either xarray.DataArray objects or identifiers to get the DataArrays from the current Scene. Defaults to all datasets.
-
missing_datasets
¶ DatasetIDs that have not been loaded.
-
read
(nodes=None, **kwargs)¶ Load datasets from the necessary reader.
Parameters: - nodes (iterable) – DependencyTree Node objects
- **kwargs – Keyword arguments to pass to the reader’s load method.
Returns: DatasetDict of loaded datasets
-
resample
(destination=None, datasets=None, generate=True, unload=True, resampler=None, **resample_kwargs)¶ Resample datasets and return a new scene.
Parameters: - destination (AreaDefinition, GridDefinition) – area definition to resample to. If not specified then the area returned by Scene.max_area() will be used.
- datasets (list) – Limit datasets to resample to these specified DatasetID objects . By default all currently loaded datasets are resampled.
- generate (bool) – Generate any requested composites that could not be previously due to incompatible areas (default: True).
- unload (bool) – Remove any datasets no longer needed after requested composites have been generated (default: True).
- resampler (str) – Name of resampling method to use. By default,
this is a nearest neighbor KDTree-based resampling
(‘nearest’). Other possible values include ‘native’, ‘ewa’,
etc. See the
resample
documentation for more information. - resample_kwargs – Remaining keyword arguments to pass to individual
resampler classes. See the individual resampler class
documentation
here
for available arguments.
-
save_dataset
(dataset_id, filename=None, writer=None, overlay=None, compute=True, **kwargs)¶ Save the dataset_id to file using writer (default: geotiff).
-
save_datasets
(writer='geotiff', datasets=None, compute=True, **kwargs)¶ Save all the datasets present in a scene to disk using writer.
-
show
(dataset_id, overlay=None)¶ Show the dataset on screen as an image.
-
slice
(key)¶ Slice Scene by dataset index.
Note
DataArrays that do not have an
area
attribute will not be sliced.
-
start_time
¶ Return the start time of the file.
-
unload
(keepables=None)¶ Unload all unneeded datasets.
Datasets are considered unneeded if they weren’t directly requested or added to the Scene by the user or they are no longer needed to generate composites that have yet to be generated.
Parameters: keepables (iterable) – DatasetIDs to keep whether they are needed or not.
-
values
()¶
- filenames (iterable or dict) – A sequence of files that will be used to load data from. A
satpy.utils module¶
Module defining various utilities.
-
class
satpy.utils.
OrderedConfigParser
(*args, **kwargs)¶ Bases:
object
Intercepts read and stores ordered section names. Cannot use inheritance and super as ConfigParser use old style classes.
-
read
(filename)¶ Reads config file
-
sections
()¶ Get sections from config file
-
-
satpy.utils.
angle2xyz
(azi, zen)¶ Convert azimuth and zenith to cartesian.
-
satpy.utils.
atmospheric_path_length_correction
(data, cos_zen, limit=88.0, max_sza=95.0)¶ Perform Sun zenith angle correction.
This function uses the correction method proposed by Li and Shibata (2006): https://doi.org/10.1175/JAS3682.1
The correction is limited to
limit
degrees (default: 88.0 degrees). For larger zenith angles, the correction is the same as at thelimit
ifmax_sza
is None. The default behavior is to gradually reduce the correction pastlimit
degrees up tomax_sza
where the correction becomes 0. Bothdata
andcos_zen
should be 2D arrays of the same shape.
-
satpy.utils.
debug_on
()¶ Turn debugging logging on.
-
satpy.utils.
ensure_dir
(filename)¶ Checks if the dir of f exists, otherwise create it.
-
satpy.utils.
get_logger
(name)¶ Return logger with null handler added if needed.
-
satpy.utils.
in_ipynb
()¶ Are we in a jupyter notebook?
-
satpy.utils.
logging_off
()¶ Turn logging off.
-
satpy.utils.
logging_on
(level=30)¶ Turn logging on.
-
satpy.utils.
lonlat2xyz
(lon, lat)¶ Convert lon lat to cartesian.
-
satpy.utils.
proj_units_to_meters
(proj_str)¶ Convert projection units from kilometers to meters.
-
satpy.utils.
sunzen_corr_cos
(data, cos_zen, limit=88.0, max_sza=95.0)¶ Perform Sun zenith angle correction.
The correction is based on the provided cosine of the zenith angle (
cos_zen
). The correction is limited tolimit
degrees (default: 88.0 degrees). For larger zenith angles, the correction is the same as at thelimit
ifmax_sza
is None. The default behavior is to gradually reduce the correction pastlimit
degrees up tomax_sza
where the correction becomes 0. Bothdata
andcos_zen
should be 2D arrays of the same shape.
-
satpy.utils.
trace_on
()¶ Turn trace logging on.
-
satpy.utils.
xyz2angle
(x, y, z)¶ Convert cartesian to azimuth and zenith.
-
satpy.utils.
xyz2lonlat
(x, y, z)¶ Convert cartesian to lon lat.
satpy.version module¶
Git implementation of _version.py.
-
exception
satpy.version.
NotThisMethod
¶ Bases:
Exception
Exception raised if a method is not valid for the current scenario.
-
class
satpy.version.
VersioneerConfig
¶ Bases:
object
Container for Versioneer configuration parameters.
-
satpy.version.
get_config
()¶ Create, populate and return the VersioneerConfig() object.
-
satpy.version.
get_keywords
()¶ Get the keywords needed to look up the version information.
-
satpy.version.
get_versions
()¶ Get version information or return default if unable to do so.
-
satpy.version.
git_get_keywords
(versionfile_abs)¶ Extract version information from the given file.
-
satpy.version.
git_pieces_from_vcs
(tag_prefix, root, verbose, run_command=<function run_command>)¶ Get version from ‘git describe’ in the root of the source tree.
This only gets called if the git-archive ‘subst’ keywords were not expanded, and _version.py hasn’t already been rewritten with a short version string, meaning we’re inside a checked out source tree.
-
satpy.version.
git_versions_from_keywords
(keywords, tag_prefix, verbose)¶ Get version information from git keywords.
-
satpy.version.
plus_or_dot
(pieces)¶ Return a + if we don’t already have one, else return a .
-
satpy.version.
register_vcs_handler
(vcs, method)¶ Decorator to mark a method as the handler for a particular VCS.
-
satpy.version.
render
(pieces, style)¶ Render the given version pieces into the requested style.
-
satpy.version.
render_git_describe
(pieces)¶ TAG[-DISTANCE-gHEX][-dirty].
Like ‘git describe –tags –dirty –always’.
Exceptions: 1: no tags. HEX[-dirty] (note: no ‘g’ prefix)
-
satpy.version.
render_git_describe_long
(pieces)¶ TAG-DISTANCE-gHEX[-dirty].
Like ‘git describe –tags –dirty –always -long’. The distance/hash is unconditional.
Exceptions: 1: no tags. HEX[-dirty] (note: no ‘g’ prefix)
-
satpy.version.
render_pep440
(pieces)¶ Build up version string, with post-release “local version identifier”.
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you get a tagged build and then dirty it, you’ll get TAG+0.gHEX.dirty
Exceptions: 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
-
satpy.version.
render_pep440_old
(pieces)¶ TAG[.postDISTANCE[.dev0]] .
The “.dev0” means dirty.
Eexceptions: 1: no tags. 0.postDISTANCE[.dev0]
-
satpy.version.
render_pep440_post
(pieces)¶ TAG[.postDISTANCE[.dev0]+gHEX] .
The “.dev0” means dirty. Note that .dev0 sorts backwards (a dirty tree will appear “older” than the corresponding clean one), but you shouldn’t be releasing software with -dirty anyways.
Exceptions: 1: no tags. 0.postDISTANCE[.dev0]
-
satpy.version.
render_pep440_pre
(pieces)¶ TAG[.post.devDISTANCE] – No -dirty.
Exceptions: 1: no tags. 0.post.devDISTANCE
-
satpy.version.
run_command
(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None)¶ Call the given command(s).
-
satpy.version.
versions_from_parentdir
(parentdir_prefix, root, verbose)¶ Try to determine the version from the parent directory name.
Source tarballs conventionally unpack into a directory that includes both the project name and a version string. We will also support searching up two directory levels for an appropriately named parent directory
Module contents¶
SatPy Package initializer.