From b2820c0baa44889c6f3a8b9303000b2f4b3da258 Mon Sep 17 00:00:00 2001 From: Sauli Joro Date: Fri, 6 Dec 2019 11:20:04 +0000 Subject: [PATCH] Update copyright header in readers. Add and fix docstrings. --- satpy/readers/_geos_area.py | 5 ++- satpy/readers/abi_base.py | 27 ++++++------- satpy/readers/ami_l1b.py | 22 +++++----- satpy/readers/caliop_l2_cloud.py | 6 +++ satpy/readers/electrol_hrit.py | 26 ++---------- satpy/readers/eps_l1b.py | 60 ++++++++++------------------ satpy/readers/fci_l1c_fdhsi.py | 38 ++++-------------- satpy/readers/file_handlers.py | 32 +++++---------- satpy/readers/generic_image.py | 20 +--------- satpy/readers/geocat.py | 40 +++++++++---------- satpy/readers/ghrsst_l3c_sst.py | 31 +++----------- satpy/readers/goes_imager_hrit.py | 12 +++--- satpy/readers/hdf4_utils.py | 1 + satpy/readers/hdf5_utils.py | 13 +++--- satpy/readers/hrit_base.py | 12 +++--- satpy/readers/netcdf_utils.py | 12 +++--- satpy/readers/nucaps.py | 38 +++++++++--------- satpy/readers/nwcsaf_msg2013_hdf5.py | 35 +++++++--------- satpy/readers/seviri_l2_bufr.py | 2 +- satpy/readers/tropomi_l2.py | 25 +++++++----- satpy/readers/viirs_edr_flood.py | 11 +++++ satpy/readers/viirs_l1b.py | 17 ++++++-- satpy/readers/viirs_sdr.py | 37 ++++++++++------- 23 files changed, 226 insertions(+), 296 deletions(-) diff --git a/satpy/readers/_geos_area.py b/satpy/readers/_geos_area.py index 2368b016e1..5284c44181 100644 --- a/satpy/readers/_geos_area.py +++ b/satpy/readers/_geos_area.py @@ -35,8 +35,8 @@ def get_xy_from_linecol(line, col, offsets, factors): """ loff, coff = offsets lfac, cfac = factors - x__ = float(col - coff) / (float(cfac) / 2**16) - y__ = float(line - loff) / (float(lfac) / 2**16) + x__ = float(col - coff) / (float(cfac) / 2 ** 16) + y__ = float(line - loff) / (float(lfac) / 2 ** 16) return x__, y__ @@ -126,6 +126,7 @@ def get_area_definition(pdict, a_ext): for the scene in radians Returns: a_def: An area definition for the scene + """ proj_dict = {'a': float(pdict['a']), 'b': float(pdict['b']), diff --git a/satpy/readers/abi_base.py b/satpy/readers/abi_base.py index ec17b7fb02..c639275152 100644 --- a/satpy/readers/abi_base.py +++ b/satpy/readers/abi_base.py @@ -1,20 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# # Copyright (c) 2016-2018 Satpy developers # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# This file is part of satpy. +# +# satpy is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# satpy is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# You should have received a copy of the GNU General Public License along with +# satpy. If not, see . """Advance Baseline Imager reader base class for the Level 1b and l2+ reader.""" import logging @@ -46,12 +46,12 @@ def __init__(self, filename, filename_info, filetype_info): self.nc = xr.open_dataset(self.filename, decode_cf=True, mask_and_scale=False, - chunks={'x': CHUNK_SIZE, 'y': CHUNK_SIZE},) + chunks={'x': CHUNK_SIZE, 'y': CHUNK_SIZE}, ) except ValueError: self.nc = xr.open_dataset(self.filename, decode_cf=True, mask_and_scale=False, - chunks={'lon': CHUNK_SIZE, 'lat': CHUNK_SIZE},) + chunks={'lon': CHUNK_SIZE, 'lat': CHUNK_SIZE}, ) self.nc = self.nc.rename({'t': 'time'}) platform_shortname = filename_info['platform_shortname'] @@ -74,7 +74,6 @@ def __getitem__(self, item): Some datasets use a 32-bit float scaling factor like the 'x' and 'y' variables which causes inaccurate unscaled data values. This method forces the scale factor to a 64-bit float first. - """ def is_int(val): return np.issubdtype(val.dtype, np.integer) if hasattr(val, 'dtype') else isinstance(val, int) diff --git a/satpy/readers/ami_l1b.py b/satpy/readers/ami_l1b.py index 035c048ff4..4406510664 100644 --- a/satpy/readers/ami_l1b.py +++ b/satpy/readers/ami_l1b.py @@ -1,20 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# # Copyright (c) 2019 Satpy developers # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# This file is part of satpy. +# +# satpy is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# satpy is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# You should have received a copy of the GNU General Public License along with +# satpy. If not, see . """Advanced Meteorological Imager reader for the Level 1b NetCDF4 format.""" import logging diff --git a/satpy/readers/caliop_l2_cloud.py b/satpy/readers/caliop_l2_cloud.py index 06db58e2ea..52fe945e62 100644 --- a/satpy/readers/caliop_l2_cloud.py +++ b/satpy/readers/caliop_l2_cloud.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- # Copyright (c) 2016 Satpy developers # # This file is part of satpy. @@ -13,6 +15,7 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . +"""Interface to CALIOP L2 HDF4 cloud products.""" import logging import os.path @@ -31,6 +34,7 @@ class HDF4BandReader(BaseFileHandler): """CALIOP v3 HDF4 reader.""" def __init__(self, filename, filename_info, filetype_info): + """Initialze file handler.""" super(HDF4BandReader, self).__init__(filename, filename_info, filetype_info) @@ -102,8 +106,10 @@ def get_lonlats(self): @property def start_time(self): + """Get start time.""" return self._start_time @property def end_time(self): + """Get end time.""" return self._end_time diff --git a/satpy/readers/electrol_hrit.py b/satpy/readers/electrol_hrit.py index 2edd01573e..34acb68a89 100644 --- a/satpy/readers/electrol_hrit.py +++ b/satpy/readers/electrol_hrit.py @@ -16,33 +16,12 @@ # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -# Copyright (c) 2014, 2015, 2016 Adam.Dybbroe - -# Author(s): - -# Adam.Dybbroe -# Cooke, Michael.C, UK Met Office -# Martin Raspaud - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -"""HRIT format reader -********************** +"""HRIT format reader. References: ELECTRO-L GROUND SEGMENT MSU-GS INSTRUMENT, LRIT/HRIT Mission Specific Implementation, February 2012 + """ import logging @@ -137,6 +116,7 @@ def recarray2dict(arr): + """Change record array to a dictionary.""" res = {} for dtuple in arr.dtype.descr: key = dtuple[0] diff --git a/satpy/readers/eps_l1b.py b/satpy/readers/eps_l1b.py index de80bc6904..ffbf8feed0 100644 --- a/satpy/readers/eps_l1b.py +++ b/satpy/readers/eps_l1b.py @@ -16,27 +16,7 @@ # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -# Copyright (c) 2012, 2013, 2014 Martin Raspaud - -# Author(s): - -# Martin Raspaud - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -"""Reader for eps level 1b data. Uses xml files as a format description. -""" +"""Reader for eps level 1b data. Uses xml files as a format description.""" import logging import os @@ -59,14 +39,12 @@ def radiance_to_bt(arr, wc_, a__, b__): - """Convert to BT. - """ + """Convert to BT.""" return a__ + b__ * (C2 * wc_ / (da.log(1 + (C1 * (wc_ ** 3) / arr)))) def radiance_to_refl(arr, solar_flux): - """Convert to reflectances. - """ + """Convert to reflectances.""" return arr * np.pi * 100.0 / solar_flux @@ -76,9 +54,7 @@ def radiance_to_refl(arr, solar_flux): def read_raw(filename): - """Read *filename* without scaling it afterwards. - """ - + """Read *filename* without scaling it afterwards.""" form = XMLFormat(os.path.join(CONFIG_PATH, "eps_avhrrl1b_6.5.xml")) grh_dtype = np.dtype([("record_class", "|i1"), @@ -122,14 +98,15 @@ def read_raw(filename): def create_xarray(arr): + """Create xarray with correct dimensions.""" res = arr res = xr.DataArray(res, dims=['y', 'x']) return res class EPSAVHRRFile(BaseFileHandler): - """Eps level 1b reader for AVHRR data. - """ + """Eps level 1b reader for AVHRR data.""" + spacecrafts = {"M01": "Metop-B", "M02": "Metop-A", "M03": "Metop-C", } @@ -137,6 +114,7 @@ class EPSAVHRRFile(BaseFileHandler): sensors = {"AVHR": "avhrr-3"} def __init__(self, filename, filename_info, filetype_info): + """Initialize FileHandler.""" super(EPSAVHRRFile, self).__init__( filename, filename_info, filetype_info) @@ -177,6 +155,7 @@ def _read_all(self, filename): self.pixels = self["EARTH_VIEWS_PER_SCANLINE"] def __getitem__(self, key): + """Get value for given key.""" for altkey in self.form.scales.keys(): try: try: @@ -193,8 +172,7 @@ def __getitem__(self, key): raise KeyError("No matching value for " + str(key)) def keys(self): - """List of reader's keys. - """ + """List of reader's keys.""" keys = [] for val in self.form.scales.values(): keys += val.dtype.fields.keys() @@ -222,8 +200,7 @@ def _get_full_lonlats(self): str(earth_views_per_scanline)) def get_full_lonlats(self): - """Get the interpolated lons/lats. - """ + """Get the interpolated lons/lats.""" if self.lons is not None and self.lats is not None: return self.lons, self.lats @@ -273,8 +250,7 @@ def _get_full_angles(self): str(earth_views_per_scanline)) def get_full_angles(self): - """Get the interpolated lons/lats. - """ + """Get the interpolated lons/lats.""" if (self.sun_azi is not None and self.sun_zen is not None and self.sat_azi is not None and self.sat_zen is not None): return self.sun_azi, self.sun_zen, self.sat_azi, self.sat_zen @@ -291,6 +267,7 @@ def get_full_angles(self): return self.sun_azi, self.sun_zen, self.sat_azi, self.sat_zen def get_bounding_box(self): + """Get bounding box.""" if self.mdrs is None: self._read_all(self.filename) lats = np.hstack([self["EARTH_LOCATION_FIRST"][0, [0]], @@ -409,6 +386,7 @@ def get_dataset(self, key, info): return dataset def get_lonlats(self): + """Get lonlats.""" if self.area is None: if self.lons is None or self.lats is None: self.lons, self.lats = self.get_full_lonlats() @@ -419,34 +397,36 @@ def get_lonlats(self): @property def platform_name(self): + """Get platform name.""" return self.spacecrafts[self["SPACECRAFT_ID"]] @property def sensor_name(self): + """Get sensor name.""" return self.sensors[self["INSTRUMENT_ID"]] @property def start_time(self): + """Get start time.""" # return datetime.strptime(self["SENSING_START"], "%Y%m%d%H%M%SZ") return self._start_time @property def end_time(self): + """Get end time.""" # return datetime.strptime(self["SENSING_END"], "%Y%m%d%H%M%SZ") return self._end_time if __name__ == '__main__': def norm255(a__): - """normalize array to uint8. - """ + """Normalize array to uint8.""" arr = a__ * 1.0 arr = (arr - arr.min()) * 255.0 / (arr.max() - arr.min()) return arr.astype(np.uint8) def show(a__): - """show array. - """ + """Show array.""" from PIL import Image Image.fromarray(norm255(a__), "L").show() diff --git a/satpy/readers/fci_l1c_fdhsi.py b/satpy/readers/fci_l1c_fdhsi.py index 91cd1632c4..43ea8c48a3 100644 --- a/satpy/readers/fci_l1c_fdhsi.py +++ b/satpy/readers/fci_l1c_fdhsi.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017 Satpy developers +# Copyright (c) 2017-2019 Satpy developers # # This file is part of satpy. # @@ -15,30 +15,7 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -# Copyright (c) 2016--2019. - -# Author(s): - -# -# Thomas Leppelt -# Sauli Joro -# Gerrit Holl - -# This file is part of satpy. - -# satpy is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. - -# satpy is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License along with -# satpy. If not, see . - -"""Interface to MTG-FCI-FDHSI L1C NetCDF files +"""Interface to MTG-FCI-FDHSI L1C NetCDF files. This module defines the :class:`FCIFDHSIFileHandler` file handler, to be used for reading Meteosat Third Generation (MTG) Flexible Combined @@ -66,7 +43,7 @@ class FCIFDHSIFileHandler(NetCDF4FileHandler): - """Class implementing the MTG FCI FDHSI File Reader + """Class implementing the MTG FCI FDHSI File . This class implements the Meteosat Third Generation (MTG) Flexible Combined Imager (FCI) Full Disk High Spectral Imagery (FDHSI) reader. @@ -77,6 +54,7 @@ class using the :mod:`~satpy.Scene.load` method with the reader """ def __init__(self, filename, filename_info, filetype_info): + """Initialize file handler.""" super(FCIFDHSIFileHandler, self).__init__(filename, filename_info, filetype_info) logger.debug('Reading: {}'.format(self.filename)) @@ -87,15 +65,16 @@ def __init__(self, filename, filename_info, filetype_info): @property def start_time(self): + """Get start time.""" return self.filename_info['start_time'] @property def end_time(self): + """Get end time.""" return self.filename_info['end_time'] def get_dataset(self, key, info=None): """Load a dataset.""" - logger.debug('Reading {} from {}'.format(key.name, self.filename)) # Get the dataset # Get metadata for given dataset @@ -143,6 +122,7 @@ def get_dataset(self, key, info=None): return res def get_channel_dataset(self, channel): + """Get channel dataset.""" root_group = 'data/{}'.format(channel) group = 'data/{}/measured'.format(channel) @@ -232,8 +212,7 @@ def get_area_def(self, key, info=None): return area def calibrate(self, data, key, measured, root): - """Data calibration.""" - + """Calibrate data.""" if key.calibration == 'brightness_temperature': data = self._ir_calibrate(data, measured, root) elif key.calibration == 'reflectance': @@ -248,7 +227,6 @@ def calibrate(self, data, key, measured, root): def _ir_calibrate(self, radiance, measured, root): """IR channel calibration.""" - coef = self[measured + "/radiance_unit_conversion_coefficient"] wl_c = self[root + "/central_wavelength_actual"] diff --git a/satpy/readers/file_handlers.py b/satpy/readers/file_handlers.py index efc0394547..ab085b0d81 100644 --- a/satpy/readers/file_handlers.py +++ b/satpy/readers/file_handlers.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017 Satpy developers +# Copyright (c) 2017-2019 Satpy developers # # This file is part of satpy. # @@ -15,25 +15,7 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -# Copyright (c) 2016. - -# Author(s): - -# David Hoese - -# This file is part of satpy. - -# satpy is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. - -# satpy is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License along with -# satpy. If not, see . +"""Interface for BaseFileHandlers.""" from abc import ABCMeta @@ -45,8 +27,10 @@ class BaseFileHandler(six.with_metaclass(ABCMeta, object)): + """Base file handler.""" def __init__(self, filename, filename_info, filetype_info): + """Initialize file handler.""" self.filename = str(filename) self.navigation_reader = None self.filename_info = filename_info @@ -54,15 +38,19 @@ def __init__(self, filename, filename_info, filetype_info): self.metadata = filename_info.copy() def __str__(self): + """Customize __str__.""" return "<{}: '{}'>".format(self.__class__.__name__, self.filename) def __repr__(self): + """Customize __repr__.""" return str(self) def get_dataset(self, dataset_id, ds_info): + """Get dataset.""" raise NotImplementedError def get_area_def(self, dsid): + """Get area definition.""" raise NotImplementedError def get_bounding_box(self): @@ -143,10 +131,12 @@ def combine_info(self, all_infos): @property def start_time(self): + """Get start time.""" return self.filename_info['start_time'] @property def end_time(self): + """Get end time.""" return self.filename_info.get('end_time', self.start_time) @property @@ -155,7 +145,7 @@ def sensor_names(self): raise NotImplementedError def file_type_matches(self, ds_ftype): - """This file handler's type can handle this dataset's file type. + """Match file handler's type to this dataset's file type. Args: ds_ftype (str or list): File type or list of file types that a diff --git a/satpy/readers/generic_image.py b/satpy/readers/generic_image.py index cbf760df24..7794d95e30 100644 --- a/satpy/readers/generic_image.py +++ b/satpy/readers/generic_image.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017 Satpy developers +# Copyright (c) 2017-2019 Satpy developers # # This file is part of satpy. # @@ -15,24 +15,6 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -# Author(s): - -# Lorenzo Clementi -# Panu Lahtinen - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - """ Reader for generic image (e.g. gif, png, jpg, tif, geotiff, ...). diff --git a/satpy/readers/geocat.py b/satpy/readers/geocat.py index 386564f015..574ef14710 100644 --- a/satpy/readers/geocat.py +++ b/satpy/readers/geocat.py @@ -1,25 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017 Satpy developers -# -# This file is part of satpy. -# -# satpy is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# satpy is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# satpy. If not, see . -# Copyright (c) 2017. -# -# Author(s): -# -# David Hoese +# Copyright (c) 2017-2019 Satpy developers # # This file is part of satpy. # @@ -71,6 +52,8 @@ class GEOCATFileHandler(NetCDF4FileHandler): + """GEOCAT netCDF4 file handler.""" + sensors = { 'goes': 'goes_imager', 'himawari8': 'ahi', @@ -92,6 +75,7 @@ class GEOCATFileHandler(NetCDF4FileHandler): } def get_sensor(self, sensor): + """Get sensor.""" last_resort = None for k, v in self.sensors.items(): if k == sensor: @@ -103,6 +87,7 @@ def get_sensor(self, sensor): raise ValueError("Unknown sensor '{}'".format(sensor)) def get_platform(self, platform): + """Get platform.""" for k, v in self.platforms.items(): if k in platform: return v @@ -117,23 +102,28 @@ def _get_proj(self, platform, ref_lon): @property def sensor_names(self): + """Get sensor names.""" return [self.get_sensor(self['/attr/Sensor_Name'])] @property def start_time(self): + """Get start time.""" return self.filename_info['start_time'] @property def end_time(self): + """Get end time.""" return self.filename_info.get('end_time', self.start_time) @property def is_geo(self): + """Check platform.""" platform = self.get_platform(self['/attr/Platform_Name']) return platform in GEO_PROJS @property def resolution(self): + """Get resolution.""" elem_res = self['/attr/Element_Resolution'] return int(elem_res * 1000) @@ -199,6 +189,7 @@ def available_datasets(self, configured_datasets=None): yield True, ds_info def get_shape(self, dataset_id, ds_info): + """Get shape.""" var_name = ds_info.get('file_key', dataset_id.name) return self[var_name + '/shape'] @@ -238,6 +229,7 @@ def _load_nav(self, name): return nav[:] def get_area_def(self, dsid): + """Get area definition.""" if not self.is_geo: raise NotImplementedError("Don't know how to get the Area Definition for this file") @@ -263,6 +255,7 @@ def get_area_def(self, dsid): return area_def def get_metadata(self, dataset_id, ds_info): + """Get metadata.""" var_name = ds_info.get('file_key', dataset_id.name) shape = self.get_shape(dataset_id, ds_info) info = getattr(self[var_name], 'attrs', {}) @@ -283,7 +276,12 @@ def get_metadata(self, dataset_id, ds_info): return info - def get_dataset(self, dataset_id, ds_info, xslice=slice(None), yslice=slice(None)): + def get_dataset(self, dataset_id, ds_info, xslice=None, yslice=None): + """Get dataset.""" + if xslice is None: + xslice = slice(None) + if yslice is None: + yslice = slice(None) var_name = ds_info.get('file_key', dataset_id.name) # FUTURE: Metadata retrieval may be separate info = self.get_metadata(dataset_id, ds_info) diff --git a/satpy/readers/ghrsst_l3c_sst.py b/satpy/readers/ghrsst_l3c_sst.py index b8a48b4aae..8055cdfd56 100644 --- a/satpy/readers/ghrsst_l3c_sst.py +++ b/satpy/readers/ghrsst_l3c_sst.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017 Satpy developers +# Copyright (c) 2017-2019 Satpy developers # # This file is part of satpy. # @@ -16,27 +16,7 @@ # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -# Copyright (c) 2016 Adam.Dybbroe - -# Author(s): - -# Adam.Dybbroe - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -"""An OSISAF SST reader for the netCDF GHRSST format -""" +"""An OSISAF SST reader for the netCDF GHRSST format.""" import logging from datetime import datetime @@ -59,7 +39,7 @@ def _parse_datetime(self, datestr): return datetime.strptime(datestr, '%Y%m%dT%H%M%SZ') def get_area_def(self, area_id, area_info): - """Override abstract baseclass method""" + """Override abstract baseclass method.""" raise NotImplementedError def get_dataset(self, dataset_id, ds_info, out=None): @@ -117,8 +97,7 @@ def get_dataset(self, dataset_id, ds_info, out=None): return cls(out, **ds_info) def get_lonlats(self, navid, nav_info, lon_out=None, lat_out=None): - """Load an area. - """ + """Load an area.""" lon_key = 'lon' valid_min = self[lon_key + '/attr/valid_min'] valid_max = self[lon_key + '/attr/valid_max'] @@ -136,9 +115,11 @@ def get_lonlats(self, navid, nav_info, lon_out=None, lat_out=None): @property def start_time(self): + """Get start time.""" # return self.filename_info['start_time'] return self._parse_datetime(self['/attr/start_time']) @property def end_time(self): + """Get end time.""" return self._parse_datetime(self['/attr/stop_time']) diff --git a/satpy/readers/goes_imager_hrit.py b/satpy/readers/goes_imager_hrit.py index d2e65b25d8..a50cdab125 100644 --- a/satpy/readers/goes_imager_hrit.py +++ b/satpy/readers/goes_imager_hrit.py @@ -15,13 +15,13 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""GOES HRIT format reader -**************************** +"""GOES HRIT format reader. References: LRIT/HRIT Mission Specific Implementation, February 2012 GVARRDL98.pdf 05057_SPE_MSG_LRIT_HRI + """ import logging @@ -40,6 +40,8 @@ class CalibrationError(Exception): + """Dummy error-class.""" + pass @@ -113,6 +115,7 @@ class CalibrationError(Exception): def make_sgs_time(sgs_time_array): + """Make sgs time.""" year = ((sgs_time_array['century'] >> 4) * 1000 + (sgs_time_array['century'] & 15) * 100 + (sgs_time_array['year'] >> 4) * 10 + @@ -156,6 +159,7 @@ def make_sgs_time(sgs_time_array): def make_gvar_float(float_val): + """Make gvar float.""" sign = 1 if float_val < 0: float_val = -float_val @@ -230,8 +234,7 @@ def make_gvar_float(float_val): class HRITGOESPrologueFileHandler(HRITFileHandler): - - """GOES HRIT format reader""" + """GOES HRIT format reader.""" def __init__(self, filename, filename_info, filetype_info): """Initialize the reader.""" @@ -254,7 +257,6 @@ def read_prologue(self): def process_prologue(self): """Reprocess prologue to correct types.""" - for key in ['TCurr', 'TCHED', 'TCTRL', 'TLHED', 'TLTRL', 'TIPFS', 'TINFS', 'TISPC', 'TIECL', 'TIBBC', 'TISTR', 'TLRAN', 'TIIRT', 'TIVIT', 'TCLMT', 'TIONA']: diff --git a/satpy/readers/hdf4_utils.py b/satpy/readers/hdf4_utils.py index 0d828f3d6e..e29f2717c7 100644 --- a/satpy/readers/hdf4_utils.py +++ b/satpy/readers/hdf4_utils.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License along with # satpy. If not, see . """Helpers for reading hdf4-based files.""" + import logging from pyhdf.SD import SD, SDC, SDS diff --git a/satpy/readers/hdf5_utils.py b/satpy/readers/hdf5_utils.py index 45919fccb4..acc7aee1f1 100644 --- a/satpy/readers/hdf5_utils.py +++ b/satpy/readers/hdf5_utils.py @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""Helpers for reading hdf5-based files. +"""Helpers for reading hdf5-based files.""" -""" import logging import h5py import numpy as np @@ -33,10 +32,10 @@ class HDF5FileHandler(BaseFileHandler): - """Small class for inspecting a HDF5 file and retrieve its metadata/header data. - """ + """Small class for inspecting a HDF5 file and retrieve its metadata/header data.""" def __init__(self, filename, filename_info, filetype_info): + """Initialize file handler.""" super(HDF5FileHandler, self).__init__( filename, filename_info, filetype_info) self.file_content = {} @@ -69,13 +68,14 @@ def _collect_attrs(self, name, attrs): self.file_content[fc_key] = value def get_reference(self, name, key): - + """Get reference.""" with h5py.File(self.filename, 'r') as hf: if isinstance(hf[name].attrs[key], h5py.h5r.Reference): ref_name = h5py.h5r.get_name(hf[name].attrs[key], hf.id) return hf[ref_name][()] def collect_metadata(self, name, obj): + """Collect metadata.""" if isinstance(obj, h5py.Dataset): self.file_content[name] = obj self.file_content[name + "/dtype"] = obj.dtype @@ -83,6 +83,7 @@ def collect_metadata(self, name, obj): self._collect_attrs(name, obj.attrs) def __getitem__(self, key): + """Get item for given key.""" val = self.file_content[key] if isinstance(val, h5py.Dataset): # these datasets are closed and inaccessible when the file is closed, need to reopen @@ -95,9 +96,11 @@ def __getitem__(self, key): return val def __contains__(self, item): + """Get item from file content.""" return item in self.file_content def get(self, item, default=None): + """Get item.""" if item in self: return self[item] else: diff --git a/satpy/readers/hrit_base.py b/satpy/readers/hrit_base.py index be4742c015..ce63ca4d33 100644 --- a/satpy/readers/hrit_base.py +++ b/satpy/readers/hrit_base.py @@ -15,8 +15,7 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""HRIT/LRIT format reader -*************************** +"""HRIT/LRIT format reader. This module is the base module for all HRIT-based formats. Here, you will find the common building blocks for hrit reading. @@ -152,7 +151,6 @@ def decompress(infile, outdir='.'): class HRITFileHandler(BaseFileHandler): - """HRIT standard format reader.""" def __init__(self, filename, filename_info, filetype_info, hdr_info): @@ -175,10 +173,7 @@ def __init__(self, filename, filename_info, filetype_info, hdr_info): self._end_time = self._start_time + timedelta(minutes=15) def _get_hd(self, hdr_info): - """Open the file, read and get the basic file header info and set the mda - dictionary - """ - + """Open the file, read and get the basic file header info and set the mda dictionary.""" hdr_map, variable_length_headers, text_headers = hdr_info with open(self.filename) as fp: @@ -227,14 +222,17 @@ def _get_hd(self, hdr_info): self.mda['orbital_parameters'] = {} def get_shape(self, dsid, ds_info): + """Get shape.""" return int(self.mda['number_of_lines']), int(self.mda['number_of_columns']) @property def start_time(self): + """Get start time.""" return self._start_time @property def end_time(self): + """Get end time.""" return self._end_time def get_dataset(self, key, info): diff --git a/satpy/readers/netcdf_utils.py b/satpy/readers/netcdf_utils.py index 02d00baf5c..4194b66ac9 100644 --- a/satpy/readers/netcdf_utils.py +++ b/satpy/readers/netcdf_utils.py @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""Helpers for reading netcdf-based files. +"""Helpers for reading netcdf-based files.""" -""" import netCDF4 import logging import xarray as xr @@ -30,7 +29,6 @@ class NetCDF4FileHandler(BaseFileHandler): - """Small class for inspecting a NetCDF4 file and retrieving its metadata/header data. File information can be accessed using bracket notation. Variables are @@ -60,6 +58,7 @@ class NetCDF4FileHandler(BaseFileHandler): def __init__(self, filename, filename_info, filetype_info, auto_maskandscale=False, xarray_kwargs=None): + """Initilize file handler.""" super(NetCDF4FileHandler, self).__init__( filename, filename_info, filetype_info) self.file_content = {} @@ -82,8 +81,7 @@ def __init__(self, filename, filename_info, filetype_info, self._xarray_kwargs.setdefault('mask_and_scale', self.auto_maskandscale) def _collect_attrs(self, name, obj): - """Collect all the attributes for the provided file object. - """ + """Collect all the attributes for the provided file object.""" for key in obj.ncattrs(): value = getattr(obj, key) fc_key = "{}/attr/{}".format(name, key) @@ -110,11 +108,13 @@ def collect_metadata(self, name, obj): self._collect_attrs(name, obj) def collect_dimensions(self, name, obj): + """Collect dimensions.""" for dim_name, dim_obj in obj.dimensions.items(): dim_name = "{}/dimension/{}".format(name, dim_name) self.file_content[dim_name] = len(dim_obj) def __getitem__(self, key): + """Get item for given key.""" val = self.file_content[key] if isinstance(val, netCDF4.Variable): # these datasets are closed and inaccessible when the file is @@ -141,9 +141,11 @@ def __getitem__(self, key): return val def __contains__(self, item): + """Get item from file content.""" return item in self.file_content def get(self, item, default=None): + """Get item.""" if item in self: return self[item] else: diff --git a/satpy/readers/nucaps.py b/satpy/readers/nucaps.py index 27c00f32b3..245c533814 100644 --- a/satpy/readers/nucaps.py +++ b/satpy/readers/nucaps.py @@ -15,8 +15,8 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""Interface to NUCAPS Retrieval NetCDF files -""" +"""Interface to NUCAPS Retrieval NetCDF files.""" + from datetime import datetime import xarray as xr import numpy as np @@ -48,46 +48,45 @@ class NUCAPSFileHandler(NetCDF4FileHandler): - """NUCAPS File Reader - """ + """File handler for NUCAPS netCDF4 format.""" def __init__(self, *args, **kwargs): + """Initialize file handler.""" kwargs.setdefault('xarray_kwargs', {}).setdefault( 'decode_times', False) super(NUCAPSFileHandler, self).__init__(*args, **kwargs) def __contains__(self, item): + """Return item from file content.""" return item in self.file_content def _parse_datetime(self, datestr): - """Parse NUCAPS datetime string. - """ + """Parse NUCAPS datetime string.""" return datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S.%fZ") @property def start_time(self): + """Get start time.""" return self._parse_datetime(self['/attr/time_coverage_start']) @property def end_time(self): + """Get end time.""" return self._parse_datetime(self['/attr/time_coverage_end']) @property def start_orbit_number(self): - """Return orbit number for the beginning of the swath. - """ + """Return orbit number for the beginning of the swath.""" return int(self['/attr/start_orbit_number']) @property def end_orbit_number(self): - """Return orbit number for the end of the swath. - """ + """Return orbit number for the end of the swath.""" return int(self['/attr/end_orbit_number']) @property def platform_name(self): - """Return standard platform name for the file's data. - """ + """Return standard platform name for the file's data.""" res = self['/attr/platform_name'] if isinstance(res, np.ndarray): return str(res.astype(str)) @@ -96,8 +95,7 @@ def platform_name(self): @property def sensor_names(self): - """Return standard sensor or instrument name for the file's data. - """ + """Return standard sensor or instrument name for the file's data.""" res = self['/attr/instrument_name'] if isinstance(res, np.ndarray): res = str(res.astype(str)) @@ -107,8 +105,7 @@ def sensor_names(self): return res def get_shape(self, ds_id, ds_info): - """Return data array shape for item specified. - """ + """Return data array shape for item specified.""" var_path = ds_info.get('file_key', '{}'.format(ds_id.name)) if var_path + '/shape' not in self: # loading a scalar value @@ -122,6 +119,7 @@ def get_shape(self, ds_id, ds_info): return shape def get_metadata(self, dataset_id, ds_info): + """Get metadata.""" var_path = ds_info.get('file_key', '{}'.format(dataset_id.name)) shape = self.get_shape(dataset_id, ds_info) file_units = ds_info.get('file_units', @@ -152,7 +150,7 @@ def get_metadata(self, dataset_id, ds_info): return info def get_dataset(self, dataset_id, ds_info): - """Load data array and metadata for specified dataset""" + """Load data array and metadata for specified dataset.""" var_path = ds_info.get('file_key', '{}'.format(dataset_id.name)) metadata = self.get_metadata(dataset_id, ds_info) valid_min, valid_max = self[var_path + '/attr/valid_range'] @@ -189,8 +187,8 @@ def get_dataset(self, dataset_id, ds_info): class NUCAPSReader(FileYAMLReader): - """Reader for NUCAPS NetCDF4 files. - """ + """Reader for NUCAPS NetCDF4 files.""" + def __init__(self, config_files, mask_surface=True, mask_quality=True, **kwargs): """Configure reader behavior. @@ -206,7 +204,7 @@ def __init__(self, config_files, mask_surface=True, mask_quality=True, **kwargs) self.mask_quality = self.info.get('mask_quality', mask_quality) def load_ds_ids_from_config(self): - """Convert config dataset entries to DatasetIDs + """Convert config dataset entries to DatasetIDs. Special handling is done to provide level specific datasets for any pressured based datasets. For example, a dataset is diff --git a/satpy/readers/nwcsaf_msg2013_hdf5.py b/satpy/readers/nwcsaf_msg2013_hdf5.py index f65253c641..fb0610d44a 100644 --- a/satpy/readers/nwcsaf_msg2013_hdf5.py +++ b/satpy/readers/nwcsaf_msg2013_hdf5.py @@ -1,25 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - -# Copyright (c) 2019 Pytroll - -# Author(s): - -# Adam.Dybbroe - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +# Copyright (c) 2019 Satpy developers +# +# This file is part of satpy. +# +# satpy is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# satpy is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# satpy. If not, see . """Reader for the old NWCSAF/Geo (v2013 and earlier) cloud product format. References: diff --git a/satpy/readers/seviri_l2_bufr.py b/satpy/readers/seviri_l2_bufr.py index af6768efa4..5204a0894d 100644 --- a/satpy/readers/seviri_l2_bufr.py +++ b/satpy/readers/seviri_l2_bufr.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2017-2019 Satpy developers +# Copyright (c) 2019 Satpy developers # # This file is part of satpy. # diff --git a/satpy/readers/tropomi_l2.py b/satpy/readers/tropomi_l2.py index 4cf5eb2441..8c8a3aab65 100644 --- a/satpy/readers/tropomi_l2.py +++ b/satpy/readers/tropomi_l2.py @@ -1,23 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# # Copyright (c) 2019 Satpy developers # -# This file is part of Satpy. +# This file is part of satpy. # -# Satpy is free software: you can redistribute it and/or modify it under the +# satpy is free software: you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation, either version 3 of the License, or (at your option) any later # version. # -# Satpy is distributed in the hope that it will be useful, but WITHOUT ANY +# satpy is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with -# Satpy. If not, see . +# satpy. If not, see . -"""Interface to TROPOMI L2 Reader +"""Interface to TROPOMI L2 Reader. The TROPOspheric Monitoring Instrument (TROPOMI) is the satellite instrument on board the Copernicus Sentinel-5 Precursor satellite. It measures key @@ -29,6 +28,7 @@ http://www.tropomi.eu/data-products/level-2-products """ + from satpy.readers.netcdf_utils import NetCDF4FileHandler, netCDF4 import logging import numpy as np @@ -37,33 +37,38 @@ class TROPOMIL2FileHandler(NetCDF4FileHandler): + """File handler for TROPOMI L2 netCDF files.""" + @property def start_time(self): + """Get start time.""" return self.filename_info['start_time'] @property def end_time(self): + """Get end time.""" return self.filename_info.get('end_time', self.start_time) @property def platform_shortname(self): + """Get start time.""" return self.filename_info['platform_shortname'] @property def sensor(self): - """ Retrieves the sensor name from the file """ + """Get sensor.""" res = self['/attr/sensor'] if isinstance(res, np.ndarray): return str(res.astype(str)) return res def available_datasets(self, configured_datasets=None): - """Automatically determine datasets provided by this file""" + """Automatically determine datasets provided by this file.""" logger.debug("Available_datasets begin...") # Determine shape of the geolocation data (lat/lon) lat_shape = None - for var_name, val in self.file_content.items(): + for var_name, _val in self.file_content.items(): # Could probably avoid this hardcoding, will think on it if (var_name == 'PRODUCT/latitude'): lat_shape = self[var_name + "/shape"] @@ -127,6 +132,7 @@ def available_datasets(self, configured_datasets=None): yield True, new_info def get_metadata(self, data, ds_info): + """Get metadata.""" metadata = {} metadata.update(data.attrs) metadata.update(ds_info) @@ -140,6 +146,7 @@ def get_metadata(self, data, ds_info): return metadata def get_dataset(self, ds_id, ds_info): + """Get dataset.""" logger.debug("Getting data for: %s", ds_id.name) file_key = ds_info.get('file_key', ds_id.name) data = self[file_key] diff --git a/satpy/readers/viirs_edr_flood.py b/satpy/readers/viirs_edr_flood.py index 7a44942498..a39aa3899e 100644 --- a/satpy/readers/viirs_edr_flood.py +++ b/satpy/readers/viirs_edr_flood.py @@ -15,22 +15,29 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . +"""Interface to VIIRS flood product.""" + from satpy.readers.hdf4_utils import HDF4FileHandler from pyresample import geometry import numpy as np class VIIRSEDRFlood(HDF4FileHandler): + """VIIRS EDR Flood-product handler for HDF4 files.""" + @property def start_time(self): + """Get start time.""" return self.filename_info['start_time'] @property def end_time(self): + """Get end time.""" return self.filename_info.get('end_time', self.start_time) @property def sensor_name(self): + """Get sensor name.""" sensor = self['/attr/SensorIdentifyCode'] if isinstance(sensor, np.ndarray): return str(sensor.astype(str)).lower() @@ -38,12 +45,14 @@ def sensor_name(self): @property def platform_name(self): + """Get platform name.""" platform_name = self['/attr/Satellitename'] if isinstance(platform_name, np.ndarray): return str(platform_name.astype(str)).lower() return platform_name.lower() def get_metadata(self, data, ds_info): + """Get metadata.""" metadata = {} metadata.update(data.attrs) metadata.update(ds_info) @@ -57,6 +66,7 @@ def get_metadata(self, data, ds_info): return metadata def get_dataset(self, ds_id, ds_info): + """Get dataset.""" data = self[ds_id.name] data.attrs = self.get_metadata(data, ds_info) @@ -73,6 +83,7 @@ def get_dataset(self, ds_id, ds_info): return data def get_area_def(self, ds_id): + """Get area definition.""" data = self[ds_id.name] proj_dict = { diff --git a/satpy/readers/viirs_l1b.py b/satpy/readers/viirs_l1b.py index beb2f3bdcd..16f3c0e372 100644 --- a/satpy/readers/viirs_l1b.py +++ b/satpy/readers/viirs_l1b.py @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""Interface to VIIRS L1B format +"""Interface to VIIRS L1B format.""" -""" import logging from datetime import datetime import numpy as np @@ -27,14 +26,15 @@ class VIIRSL1BFileHandler(NetCDF4FileHandler): - """VIIRS L1B File Reader - """ + """VIIRS L1B File Reader.""" def _parse_datetime(self, datestr): + """Parse datetime.""" return datetime.strptime(datestr, "%Y-%m-%dT%H:%M:%S.000Z") @property def start_orbit_number(self): + """Get start orbit number.""" try: return int(self['/attr/orbit_number']) except KeyError: @@ -42,6 +42,7 @@ def start_orbit_number(self): @property def end_orbit_number(self): + """Get end orbit number.""" try: return int(self['/attr/orbit_number']) except KeyError: @@ -49,6 +50,7 @@ def end_orbit_number(self): @property def platform_name(self): + """Get platform name.""" try: res = self.get('/attr/platform', self.filename_info['platform_shortname']) @@ -65,6 +67,7 @@ def platform_name(self): @property def sensor_name(self): + """Get sensor name.""" res = self['/attr/instrument'] if isinstance(res, np.ndarray): return str(res.astype(str)) @@ -72,6 +75,7 @@ def sensor_name(self): return res def adjust_scaling_factors(self, factors, file_units, output_units): + """Adjust scaling factors.""" if factors is None or factors[0] is None: factors = [1, 0] if file_units == output_units: @@ -93,15 +97,18 @@ def adjust_scaling_factors(self, factors, file_units, output_units): return factors def get_shape(self, ds_id, ds_info): + """Get shape.""" var_path = ds_info.get('file_key', 'observation_data/{}'.format(ds_id.name)) return self.get(var_path + '/shape', 1) @property def start_time(self): + """Get start time.""" return self._parse_datetime(self['/attr/time_coverage_start']) @property def end_time(self): + """Get end time.""" return self._parse_datetime(self['/attr/time_coverage_end']) def _get_dataset_file_units(self, dataset_id, ds_info, var_path): @@ -164,6 +171,7 @@ def _get_dataset_valid_range(self, dataset_id, ds_info, var_path): return valid_min, valid_max, scale_factor, scale_offset def get_metadata(self, dataset_id, ds_info): + """Get metadata.""" var_path = ds_info.get('file_key', 'observation_data/{}'.format(dataset_id.name)) shape = self.get_shape(dataset_id, ds_info) file_units = self._get_dataset_file_units(dataset_id, ds_info, var_path) @@ -189,6 +197,7 @@ def get_metadata(self, dataset_id, ds_info): return i def get_dataset(self, dataset_id, ds_info): + """Get dataset.""" var_path = ds_info.get('file_key', 'observation_data/{}'.format(dataset_id.name)) metadata = self.get_metadata(dataset_id, ds_info) shape = metadata['shape'] diff --git a/satpy/readers/viirs_sdr.py b/satpy/readers/viirs_sdr.py index 539d889d70..5497f155cc 100644 --- a/satpy/readers/viirs_sdr.py +++ b/satpy/readers/viirs_sdr.py @@ -15,8 +15,7 @@ # # You should have received a copy of the GNU General Public License along with # satpy. If not, see . -"""Interface to VIIRS SDR format -********************************** +"""Interface to VIIRS SDR format. This reader implements the support of VIIRS SDR files as produced by CSPP and CLASS. It is comprised of two parts: @@ -48,17 +47,15 @@ def _get_invalid_info(granule_data): """Get a detailed report of the missing data. - N/A: not applicable - MISS: required value missing at time of processing - OBPT: onboard pixel trim (overlapping/bow-tie pixel removed during - SDR processing) - OGPT: on-ground pixel trim (overlapping/bow-tie pixel removed - during EDR processing) - ERR: error occurred during processing / non-convergence - ELINT: ellipsoid intersect failed / instrument line-of-sight does - not intersect the Earth’s surface - VDNE: value does not exist / processing algorithm did not execute - SOUB: scaled out-of-bounds / solution not within allowed range + + N/A: not applicable + MISS: required value missing at time of processing + OBPT: onboard pixel trim (overlapping/bow-tie pixel removed during SDR processing) + OGPT: on-ground pixel trim (overlapping/bow-tie pixel removed during EDR processing) + ERR: error occurred during processing / non-convergence + ELINT: ellipsoid intersect failed / instrument line-of-sight does not intersect the Earth’s surface + VDNE: value does not exist / processing algorithm did not execute + SOUB: scaled out-of-bounds / solution not within allowed range """ if issubclass(granule_data.dtype.type, np.integer): msg = ("na:" + str((granule_data == 65535).sum()) + @@ -116,11 +113,13 @@ class VIIRSSDRFileHandler(HDF5FileHandler): """VIIRS HDF5 File Reader.""" def __init__(self, filename, filename_info, filetype_info, use_tc=None, **kwargs): + """Initialize file handler.""" self.datasets = filename_info['datasets'].split('-') self.use_tc = use_tc super(VIIRSSDRFileHandler, self).__init__(filename, filename_info, filetype_info) def __getitem__(self, item): + """Get item.""" if '*' in item: # this is an aggregated field that can't easily be loaded, need to # join things together @@ -156,6 +155,7 @@ def _parse_datetime(self, datestr, timestr): @property def start_time(self): + """Get start time.""" dataset_group = DATASET_KEYS[self.datasets[0]] default_start_date = 'Data_Products/{dataset_group}/{dataset_group}_Aggr/attr/AggregateBeginningDate' default_start_time = 'Data_Products/{dataset_group}/{dataset_group}_Aggr/attr/AggregateBeginningTime' @@ -165,6 +165,7 @@ def start_time(self): @property def end_time(self): + """Get end time.""" dataset_group = DATASET_KEYS[self.datasets[0]] default_end_date = 'Data_Products/{dataset_group}/{dataset_group}_Aggr/attr/AggregateEndingDate' default_end_time = 'Data_Products/{dataset_group}/{dataset_group}_Aggr/attr/AggregateEndingTime' @@ -174,6 +175,7 @@ def end_time(self): @property def start_orbit_number(self): + """Get start orbit number.""" dataset_group = DATASET_KEYS[self.datasets[0]] default = 'Data_Products/{dataset_group}/{dataset_group}_Aggr/attr/AggregateBeginningOrbitNumber' start_orbit_path = self.filetype_info.get('start_orbit', default).format(dataset_group=dataset_group) @@ -181,6 +183,7 @@ def start_orbit_number(self): @property def end_orbit_number(self): + """Get end orbit number.""" dataset_group = DATASET_KEYS[self.datasets[0]] default = 'Data_Products/{dataset_group}/{dataset_group}_Aggr/attr/AggregateEndingOrbitNumber' end_orbit_path = self.filetype_info.get('end_orbit', default).format(dataset_group=dataset_group) @@ -188,6 +191,7 @@ def end_orbit_number(self): @property def platform_name(self): + """Get platform name.""" default = '/attr/Platform_Short_Name' platform_path = self.filetype_info.get( 'platform_name', default).format(**self.filetype_info) @@ -200,6 +204,7 @@ def platform_name(self): @property def sensor_name(self): + """Get sensor name.""" dataset_group = DATASET_KEYS[self.datasets[0]] default = 'Data_Products/{dataset_group}/attr/Instrument_Short_Name' sensor_path = self.filetype_info.get( @@ -207,6 +212,7 @@ def sensor_name(self): return self[sensor_path].lower() def get_file_units(self, dataset_id, ds_info): + """Get file units.""" file_units = ds_info.get("file_units") # Guess the file units if we need to (normally we would get this from @@ -242,6 +248,7 @@ def scale_swath_data(self, data, scaling_factors): return data def adjust_scaling_factors(self, factors, file_units, output_units): + """Adjust scaling factors.""" if file_units == output_units: LOG.debug("File units and output units are the same (%s)", file_units) return factors @@ -287,6 +294,7 @@ def expand_single_values(var, scans): return expanded def concatenate_dataset(self, dataset_group, var_path): + """Concatenate dataset.""" if 'I' in dataset_group: scan_size = 32 else: @@ -313,6 +321,7 @@ def concatenate_dataset(self, dataset_group, var_path): return self.expand_single_values(variable, scans) def mask_fill_values(self, data, ds_info): + """Mask fill values.""" is_floating = np.issubdtype(data.dtype, np.floating) if is_floating: @@ -481,7 +490,7 @@ def filter_filenames_by_info(self, filename_items): if not fdict[to_del]['datasets']: del fdict[to_del] filename_items = fdict.items() - for filename, filename_info in filename_items: + for _filename, filename_info in filename_items: filename_info['datasets'] = '-'.join(filename_info['datasets']) return super(VIIRSSDRReader, self).filter_filenames_by_info(filename_items)