Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vaisala GLD360-reader. #687

Merged
merged 26 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
64eac43
Add HRV area extent definition for a ROI file.
sjoro Nov 28, 2018
d5e1e22
Add HRV area extent definition for a ROI file. Clean-up code.
sjoro Nov 28, 2018
a80e5d9
Fix flake8 & pep8 errors.
sjoro Nov 28, 2018
d7400e5
Add unittests for area extent calculations. Restructure code for clar…
sjoro Nov 30, 2018
93b35d3
Add Vaisala GLD360-reader.
sjoro Apr 1, 2019
72b1610
Fix for reading latitudes and longitudes.
sjoro Apr 3, 2019
5888ef0
Rename variables and classes.
sjoro Apr 3, 2019
c713279
Add documentation and reference. Clean-up code. Update AUTHORS.md
sjoro Apr 5, 2019
84d4cce
Add unittest for filehandler.
sjoro May 13, 2019
af926e8
Merge remote-tracking branch 'upstream/master'
sjoro May 13, 2019
5b5cb07
Merge branch 'master' into gld360-reader
sjoro May 13, 2019
2809784
Fix lint errors.
sjoro May 13, 2019
6aafdf6
Fix for seviri_l1b_native-reader. Modify vaisala_gld360-test to use u…
sjoro May 13, 2019
2bddb10
Fix seviri_l1b_native reflectance calibration.
sjoro May 14, 2019
a125fb7
Add units to datasets.
sjoro May 16, 2019
88d4f76
Update copyright text and fix docstring typos.
sjoro May 16, 2019
89eca78
Add time, latitude, and longitude as y-coordinates to power dataset.
sjoro May 16, 2019
5d06a3a
Update copyright and clean-up code for VaisalaGLD360 unittest.
sjoro May 16, 2019
8970d2a
Fix for time y-coordinate.
sjoro May 16, 2019
1328780
Make stickler happy.
sjoro May 16, 2019
cf2742c
Add a check for unit uniformity, fix units to CF convention, fix docs…
sjoro May 17, 2019
b6b6094
Check input units against reader config.
sjoro May 17, 2019
dbb8c3c
Fix unittest.
sjoro May 17, 2019
269dd21
Fix stickler complaints.
sjoro May 17, 2019
6a1c665
Add Vaisala GLD360 to reader-list in docs.
sjoro May 23, 2019
793899d
Merge branch 'master' into gld360-reader
mraspaud Jun 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following people have made contributions to this project:
- [praerien (praerien)](https://github.com/praerien)
- [ralphk11 (ralphk11)](https://github.com/ralphk11)
- [roquetp (roquetp)](https://github.com/roquetp)
- [sjoro (sjoro)](https://github.com/sjoro)
- [Sauli Joro (sjoro)](https://github.com/sjoro)
- Guido della Bruna - meteoswiss
- Marco Sassi - meteoswiss
- [Rohan Daruwala (rdaruwala)](https://github.com/rdaruwala)
Expand Down
4 changes: 4 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ the base Satpy installation.
* - MERSI-2 L1B data in HDF5 format
- `mersi2_l1b`
- Beta
* - Vaisala Global Lightning Dataset GLD360 data in ASCII format
- `vaisala_gld360`
- Beta


Indices and tables
==================
Expand Down
43 changes: 43 additions & 0 deletions satpy/etc/readers/vaisala_gld360.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
reader:
description: Vaisala Global Lightning Dataset 360 reader
name: vaisala_gld360
reader: !!python/name:satpy.readers.yaml_reader.FileYAMLReader ''
sensors: [vaisala_gld360]

file_types:
vaisala_gld360:
file_reader: !!python/name:satpy.readers.vaisala_gld360.VaisalaGLD360TextFileHandler ''
file_patterns: ['flashes_{start_time:%Y%m%d}.txt']

datasets:
sjoro marked this conversation as resolved.
Show resolved Hide resolved
time:
name: time
sensor: vaisala_gld360
resolution: 2000
file_type: vaisala_gld360

latitude:
name: latitude
sensor: vaisala_gld360
resolution: 2000
file_type: vaisala_gld360
standard_name: latitude
units: degree_north

longitude:
name: longitude
sensor: vaisala_gld360
resolution: 2000
file_type: vaisala_gld360
standard_name: longitude
units: degree_east

power:
name: power
sensor: vaisala_gld360
resolution: 2000
file_type: vaisala_gld360
coordinates:
- longitude
- latitude
units: kA
mraspaud marked this conversation as resolved.
Show resolved Hide resolved
84 changes: 84 additions & 0 deletions satpy/readers/vaisala_gld360.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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 <http://www.gnu.org/licenses/>.

"""Vaisala Global Lightning Dataset 360 reader

Vaisala Global Lightning Dataset GLD360 is data as a service
that provides real-time lightning data for accurate and early
detection and tracking of severe weather. The data provided is
generated by a Vaisala owned and operated world-wide lightning
detection sensor network.

References:
- [GLD360] https://www.vaisala.com/en/products/data-subscriptions-and-reports/data-sets/gld360

"""

import logging
import pandas as pd
import dask.array as da
import xarray as xr

from satpy import CHUNK_SIZE
from satpy.readers.file_handlers import BaseFileHandler

logger = logging.getLogger(__name__)


class VaisalaGLD360TextFileHandler(BaseFileHandler):
"""ASCII reader for Vaisala GDL360 data."""

def __init__(self, filename, filename_info, filetype_info):
super(VaisalaGLD360TextFileHandler, self).__init__(filename, filename_info, filetype_info)

names = ['date', 'time', 'latitude', 'longitude', 'power', 'unit']
types = ['str', 'str', 'float', 'float', 'float', 'str']
dtypes = dict(zip(names, types))
# Combine 'date' and 'time' into a datetime object
parse_dates = {'datetime': ['date', 'time']}

self.data = pd.read_csv(filename, delim_whitespace=True, header=None,
names=names, dtype=dtypes, parse_dates=parse_dates)

@property
def start_time(self):
return self.data['datetime'].iloc[0]

@property
def end_time(self):
return self.data['datetime'].iloc[-1]

def get_dataset(self, dataset_id, dataset_info):
"""Load a dataset."""
xarr = xr.DataArray(da.from_array(self.data[dataset_id.name],
chunks=CHUNK_SIZE), dims=["y"])

# Add time, longitude, and latitude as non-dimensional y-coordinates
xarr['time'] = ('y', self.data['datetime'])
xarr['longitude'] = ('y', self.data['longitude'])
xarr['latitude'] = ('y', self.data['latitude'])

if dataset_id.name == 'power':
# Check that units in the file match the unit specified in the
# reader yaml-file
if not (self.data.unit == dataset_info['units']).all():
raise ValueError('Inconsistent units found in file!')
xarr.attrs.update(dataset_info)

return xarr
4 changes: 3 additions & 1 deletion satpy/tests/reader_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
test_safe_sar_l2_ocn, test_viirs_edr_active_fires,
test_hdfeos_base, test_modis_l2,
test_electrol_hrit, test_mersi2_l1b,
test_avhrr_l1b_gaclac, test_fci_l1c_fdhsi)
test_avhrr_l1b_gaclac, test_vaisala_gld360,
test_fci_l1c_fdhsi)


if sys.version_info < (2, 7):
Expand Down Expand Up @@ -92,6 +93,7 @@ def suite():
mysuite.addTests(test_electrol_hrit.suite())
mysuite.addTests(test_mersi2_l1b.suite())
mysuite.addTests(test_avhrr_l1b_gaclac.suite())
mysuite.addTests(test_vaisala_gld360.suite())
mysuite.addTests(test_fci_l1c_fdhsi.suite())

return mysuite
71 changes: 71 additions & 0 deletions satpy/tests/reader_tests/test_vaisala_gld360.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python
sjoro marked this conversation as resolved.
Show resolved Hide resolved
# -*- coding: utf-8 -*-
# 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 <http://www.gnu.org/licenses/>.

"""Unittesting the Vaisala GLD360 reader.
"""

from io import StringIO

import numpy as np

from satpy.readers.vaisala_gld360 import VaisalaGLD360TextFileHandler
from satpy.dataset import DatasetID

import unittest


class TestVaisalaGLD360TextFileHandler(unittest.TestCase):
sjoro marked this conversation as resolved.
Show resolved Hide resolved

"""Test the VaisalaGLD360TextFileHandler."""

def test_vaisala_gld360(self):

expected = np.array([12.3, 13.2, -31.])

filename = StringIO(
u'2017-06-20 00:00:00.007178 30.5342 -90.1152 12.3 kA\n'
'2017-06-20 00:00:00.020162 -0.5727 104.0688 13.2 kA\n'
'2017-06-20 00:00:00.023183 12.1529 -10.8756 -31.0 kA'
)
filename_info = {}
sjoro marked this conversation as resolved.
Show resolved Hide resolved
filetype_info = {}
sjoro marked this conversation as resolved.
Show resolved Hide resolved

self.handler = VaisalaGLD360TextFileHandler(
filename, filename_info, filetype_info
)

filename.close()
dataset_id = DatasetID('power')
dataset_info = {'units': 'kA'}
result = self.handler.get_dataset(dataset_id, dataset_info).values

np.testing.assert_allclose(result, expected, rtol=1e-05)


def suite():
sjoro marked this conversation as resolved.
Show resolved Hide resolved
"""The test suite for test_vaisala_gld360."""
loader = unittest.TestLoader()
mysuite = unittest.TestSuite()
mysuite.addTest(loader.loadTestsFromTestCase(TestVaisalaGLD360TextFileHandler))
return mysuite


if __name__ == "__main__":
# So you can run tests from this module individually.
unittest.main()