def test_inline_composites(self): """Test that inline composites are working.""" from satpy.composites import CompositorLoader cl_ = CompositorLoader() cl_.load_sensor_composites('visir') comps = cl_.compositors # Check that "fog" product has all its prerequisites defined keys = comps['visir'].keys() fog = [comps['visir'][dsid] for dsid in keys if "fog" == dsid.name][0] self.assertEqual(fog.attrs['prerequisites'][0], 'fog_dep_0') self.assertEqual(fog.attrs['prerequisites'][1], 'fog_dep_1') self.assertEqual(fog.attrs['prerequisites'][2], 10.8) # Check that the sub-composite dependencies use wavelengths # (numeric values) keys = comps['visir'].keys() fog_dep_ids = [dsid for dsid in keys if "fog_dep" in dsid.name] self.assertEqual(comps['visir'][fog_dep_ids[0]].attrs['prerequisites'], [12.0, 10.8]) self.assertEqual(comps['visir'][fog_dep_ids[1]].attrs['prerequisites'], [10.8, 8.7]) # Check the same for SEVIRI and verify channel names are used # in the sub-composite dependencies instead of wavelengths cl_ = CompositorLoader() cl_.load_sensor_composites('seviri') comps = cl_.compositors keys = comps['seviri'].keys() fog_dep_ids = [dsid for dsid in keys if "fog_dep" in dsid.name] self.assertEqual( comps['seviri'][fog_dep_ids[0]].attrs['prerequisites'], ['IR_120', 'IR_108']) self.assertEqual( comps['seviri'][fog_dep_ids[1]].attrs['prerequisites'], ['IR_108', 'IR_087'])
def __init__(self, filenames=None, ppp_config_dir=get_environ_config_dir(), reader=None, base_dir=None, **metadata): """The Scene object constructor. Args: filenames: A sequence of files that will be used to load data from. ppp_config_dir: The directory containing the configuration files for satpy. reader: The name of the reader to use for loading the data. base_dir: The directory to search for files containing the data to load. metadata: Free metadata information. """ InfoObject.__init__(self, **metadata) # Set the PPP_CONFIG_DIR in the environment in case it's used elsewhere # in pytroll LOG.debug("Setting 'PPP_CONFIG_DIR' to '%s'", ppp_config_dir) os.environ["PPP_CONFIG_DIR"] = self.ppp_config_dir = ppp_config_dir self.readers = self.create_reader_instances(filenames=filenames, base_dir=base_dir, reader=reader) self.info.update(self._compute_metadata_from_readers()) self.datasets = DatasetDict() self.cpl = CompositorLoader(self.ppp_config_dir) self.compositors = {} self.wishlist = set()
def __init__(self, filenames=None, ppp_config_dir=None, reader=None, base_dir=None, **info): """The Scene object constructor. """ # Get PPP_CONFIG_DIR self.ppp_config_dir = ppp_config_dir or get_environ_config_dir() # Set the PPP_CONFIG_DIR in the environment in case it's used elsewhere # in pytroll LOG.debug("Setting 'PPP_CONFIG_DIR' to '%s'", self.ppp_config_dir) os.environ["PPP_CONFIG_DIR"] = self.ppp_config_dir InfoObject.__init__(self, **info) self.readers = {} self.datasets = DatasetDict() self.cpl = CompositorLoader(self.ppp_config_dir) self.compositors = {} self.wishlist = set() if filenames is not None and not filenames: raise ValueError("Filenames are specified but empty") finder = ReaderFinder( ppp_config_dir=self.ppp_config_dir, base_dir=base_dir, start_time=self.info.get('start_time'), end_time=self.info.get('end_time'), area=self.info.get('area'), ) try: reader_instances = finder(reader=reader, sensor=self.info.get("sensor"), filenames=filenames) except ValueError as err: if filenames is None and base_dir is None: LOG.info( 'Neither filenames nor base_dir provided, ' 'creating an empty scene (error was %s)', str(err)) reader_instances = [] else: raise # reader finder could return multiple readers sensors = [] for reader_instance in reader_instances: if reader_instance: self.readers[reader_instance.name] = reader_instance sensors.extend(reader_instance.sensor_names) # if the user didn't tell us what sensors to work with, let's figure it # out if not self.info.get("sensor"): self.info["sensor"] = sensors
def test_load_composite(self): """Test that composites are loadable.""" # when dedicated composites for FCI FDHSI are implemented in satpy, # this method should probably move to a dedicated class and module # in the tests.compositor_tests package from satpy.composites import CompositorLoader cl = CompositorLoader() (comps, mods) = cl.load_compositors(["fci"]) assert len(comps["fci"]) > 0 assert len(mods["fci"]) > 0
def __init__(self, filenames=None, reader=None, filter_parameters=None, reader_kwargs=None, ppp_config_dir=get_environ_config_dir(), base_dir=None, sensor=None, start_time=None, end_time=None, area=None): """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) Args: 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. """ super(Scene, self).__init__() # Set the PPP_CONFIG_DIR in the environment in case it's used elsewhere in pytroll LOG.debug("Setting 'PPP_CONFIG_DIR' to '%s'", ppp_config_dir) os.environ["PPP_CONFIG_DIR"] = self.ppp_config_dir = ppp_config_dir if not filenames and (start_time or end_time or base_dir): import warnings warnings.warn( "Deprecated: Use " + "'from satpy import find_files_and_readers' to find files") from satpy import find_files_and_readers filenames = find_files_and_readers( start_time=start_time, end_time=end_time, base_dir=base_dir, reader=reader, sensor=sensor, ppp_config_dir=self.ppp_config_dir, reader_kwargs=reader_kwargs, ) elif start_time or end_time or area: import warnings warnings.warn( "Deprecated: Use " + "'filter_parameters' to filter loaded files by 'start_time', " + "'end_time', or 'area'.") fp = filter_parameters if filter_parameters else {} fp.update({ 'start_time': start_time, 'end_time': end_time, 'area': area, }) filter_parameters = fp if filter_parameters: if reader_kwargs is None: reader_kwargs = {} reader_kwargs.setdefault('filter_parameters', {}).update(filter_parameters) if filenames and isinstance(filenames, str): raise ValueError( "'filenames' must be a list of files: Scene(filenames=[filename])" ) self.readers = self.create_reader_instances( filenames=filenames, reader=reader, reader_kwargs=reader_kwargs) self.attrs.update(self._compute_metadata_from_readers()) self.datasets = DatasetDict() self.cpl = CompositorLoader(self.ppp_config_dir) comps, mods = self.cpl.load_compositors(self.attrs['sensor']) self.wishlist = set() self.dep_tree = DependencyTree(self.readers, comps, mods) self.resamplers = {}
def test_load_composite_yaml(self): """Test loading the yaml for this sensor.""" from satpy.composites import CompositorLoader cl = CompositorLoader() cl.load_sensor_composites('viirs')
def __init__(self, filenames=None, ppp_config_dir=get_environ_config_dir(), reader=None, base_dir=None, sensor=None, start_time=None, end_time=None, area=None, reader_kwargs=None, **metadata): """The Scene object constructor. Note to load data either `filenames`, `reader`, or a 'base_dir' must be specified. If `filenames` is not specified then `reader` must be specified to search the current directory or `base_dir` if specified. If neither `filenames` nor `reader` is specified then `base_dir` will be used to find any files matching the file patterns for any configured readers. Otherwise the Scene is created with no Readers available meaning Datasets must be added manually: scn = Scene(sensor='viirs', start_time=start_time) scn['my_dataset'] = Dataset(my_data_array, **my_info) Args: filenames (iterable): A sequence of files that will be used to load data from. ppp_config_dir (str): The directory containing the configuration files for satpy. reader: The name of the reader to use for loading the data. base_dir (str): The directory to search for files containing the data to load. If *filenames* is also provided, this is ignored. sensor (list or str): Limit used files by provided sensors. area (AreaDefinition): Limit used files by geographic area. start_time (datetime): Limit used files by starting time. end_time (datetime): Limit used files by ending time. reader_kwargs (dict): Keyword arguments to pass to specific reader instances. metadata: Other metadata to assign to the Scene's ``.info``. """ InfoObject.__init__(self, sensor=sensor or set(), area=area, start_time=start_time, end_time=end_time, **metadata) # Set the PPP_CONFIG_DIR in the environment in case it's used elsewhere # in pytroll LOG.debug("Setting 'PPP_CONFIG_DIR' to '%s'", ppp_config_dir) os.environ["PPP_CONFIG_DIR"] = self.ppp_config_dir = ppp_config_dir self.readers = self.create_reader_instances( filenames=filenames, base_dir=base_dir, reader=reader, reader_kwargs=reader_kwargs) self.info.update(self._compute_metadata_from_readers()) self.datasets = DatasetDict() self.cpl = CompositorLoader(self.ppp_config_dir) comps, mods = self.cpl.load_compositors(self.info['sensor']) self.wishlist = set() self.dep_tree = DependencyTree(self.readers, comps, mods)