Skip to content

Commit

Permalink
Merge pull request #1003 from sjoro/fix-copyrights
Browse files Browse the repository at this point in the history
Update copyright header in readers. Add and fix docstrings.
  • Loading branch information
mraspaud committed Dec 6, 2019
2 parents 8831c03 + b2820c0 commit 8ded572
Show file tree
Hide file tree
Showing 23 changed files with 226 additions and 296 deletions.
5 changes: 3 additions & 2 deletions satpy/readers/_geos_area.py
Expand Up @@ -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__

Expand Down Expand Up @@ -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']),
Expand Down
27 changes: 13 additions & 14 deletions 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 <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Advance Baseline Imager reader base class for the Level 1b and l2+ reader."""

import logging
Expand Down Expand Up @@ -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']
Expand All @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions 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 <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Advanced Meteorological Imager reader for the Level 1b NetCDF4 format."""

import logging
Expand Down
6 changes: 6 additions & 0 deletions 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.
Expand All @@ -13,6 +15,7 @@
#
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Interface to CALIOP L2 HDF4 cloud products."""

import logging
import os.path
Expand All @@ -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)
Expand Down Expand Up @@ -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
26 changes: 3 additions & 23 deletions satpy/readers/electrol_hrit.py
Expand Up @@ -16,33 +16,12 @@
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.

# Copyright (c) 2014, 2015, 2016 Adam.Dybbroe

# Author(s):

# Adam.Dybbroe <adam.dybbroe@smhi.se>
# Cooke, Michael.C, UK Met Office
# Martin Raspaud <martin.raspaud@smhi.se>

# 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 <http://www.gnu.org/licenses/>.

"""HRIT format reader
**********************
"""HRIT format reader.
References:
ELECTRO-L GROUND SEGMENT MSU-GS INSTRUMENT,
LRIT/HRIT Mission Specific Implementation, February 2012
"""

import logging
Expand Down Expand Up @@ -137,6 +116,7 @@


def recarray2dict(arr):
"""Change record array to a dictionary."""
res = {}
for dtuple in arr.dtype.descr:
key = dtuple[0]
Expand Down
60 changes: 20 additions & 40 deletions satpy/readers/eps_l1b.py
Expand Up @@ -16,27 +16,7 @@
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.

# Copyright (c) 2012, 2013, 2014 Martin Raspaud

# Author(s):

# Martin Raspaud <martin.raspaud@smhi.se>

# 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 <http://www.gnu.org/licenses/>.

"""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
Expand All @@ -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


Expand All @@ -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"),
Expand Down Expand Up @@ -122,21 +98,23 @@ 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", }

sensors = {"AVHR": "avhrr-3"}

def __init__(self, filename, filename_info, filetype_info):
"""Initialize FileHandler."""
super(EPSAVHRRFile, self).__init__(
filename, filename_info, filetype_info)

Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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]],
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Expand Down

0 comments on commit 8ded572

Please sign in to comment.