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 5 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ 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
40 changes: 40 additions & 0 deletions satpy/etc/readers/vaisala_gld360.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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
datetime:
name: datetime
sensor: vaisala_gld360
resolution: 2000
file_type: vaisala_gld360

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

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

power:
name: power
sensor: vaisala_gld360
resolution: 2000
file_type: vaisala_gld360
coordinates:
- longitude
- latitude
74 changes: 74 additions & 0 deletions satpy/readers/vaisala_gld360.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2016.
sjoro marked this conversation as resolved.
Show resolved Hide resolved
#
#
# 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 i
sjoro marked this conversation as resolved.
Show resolved Hide resolved
s 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))
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
"""
sjoro marked this conversation as resolved.
Show resolved Hide resolved
xarr = xr.DataArray(da.from_array(self.data[dataset_id.name],
chunks=CHUNK_SIZE), dims=["y"])
xarr.attrs.update(dataset_info)

return xarr
3 changes: 2 additions & 1 deletion satpy/tests/reader_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
test_nc_slstr, test_olci_nc,
test_viirs_edr_flood, test_nwcsaf_nc,
test_seviri_l1b_hrit, test_sar_c_safe,
test_modis_l1b)
test_modis_l1b, test_vaisala_gld360)


if sys.version_info < (2, 7):
Expand Down Expand Up @@ -82,5 +82,6 @@ def suite():
mysuite.addTests(test_seviri_l1b_hrit.suite())
mysuite.addTests(test_sar_c_safe.suite())
mysuite.addTests(test_modis_l1b.suite())
mysuite.addTests(test_vaisala_gld360.suite())

return mysuite
89 changes: 89 additions & 0 deletions satpy/tests/reader_tests/test_vaisala_gld360.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python
sjoro marked this conversation as resolved.
Show resolved Hide resolved
# -*- coding: utf-8 -*-

# Copyright (c) 2017-2018 PyTroll Community

# Author(s):

# Adam.Dybbroe <adam.dybbroe@smhi.se>
# Sauli Joro <sauli.joro@eumetsat.int>

# 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/>.

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

import sys
sjoro marked this conversation as resolved.
Show resolved Hide resolved
from io import StringIO

import numpy as np

from satpy.readers.vaisala_gld360 import (
VaisalaGLD360TextFileHandler
)
sjoro marked this conversation as resolved.
Show resolved Hide resolved
from satpy.dataset import DatasetID

if sys.version_info < (2, 7):
import unittest2 as unittest
sjoro marked this conversation as resolved.
Show resolved Hide resolved
else:
import unittest

try:
from unittest import mock
except ImportError:
import mock
sjoro marked this conversation as resolved.
Show resolved Hide resolved


EXPECTED_POWER = np.array([ 12.3, 13.2, -31. ])
sjoro marked this conversation as resolved.
Show resolved Hide resolved

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

"""Test the VaisalaGLD360TextFileHandler."""

def test_vaisala_gld360(self):

expected = EXPECTED_POWER
sjoro marked this conversation as resolved.
Show resolved Hide resolved

filename = StringIO(
sjoro marked this conversation as resolved.
Show resolved Hide resolved
'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.close()
dataset_id = DatasetID('power')
dataset_info = {}
result = self.handler.get_dataset(dataset_id, dataset_info).values

# import ipdb; ipdb.set_trace()
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_scene.
sjoro marked this conversation as resolved.
Show resolved Hide resolved
"""
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()