Unverified Commit 2a4f514a authored by David Hoese's avatar David Hoese Committed by GitHub
Browse files

Fix GOES-18 platform not being recognized properly (#326)

parent 041d4bea
......@@ -210,6 +210,7 @@ class Platform(Enum):
GOES_16 = 'G16'
GOES_17 = 'G17'
GOES_18 = 'G18'
GOES_19 = 'G19'
NWP = 'NWP'
MSG8 = 'Meteosat-8'
MSG9 = 'Meteosat-9'
......@@ -224,6 +225,7 @@ PLATFORM_MAP['h9'] = Platform.HIMAWARI_9
PLATFORM_MAP['goes16'] = Platform.GOES_16
PLATFORM_MAP['goes17'] = Platform.GOES_17
PLATFORM_MAP['goes18'] = Platform.GOES_18
PLATFORM_MAP['goes19'] = Platform.GOES_19
class Info(Enum):
......
......@@ -12,7 +12,9 @@ from satpy import Scene
from satpy.tests.utils import make_dataid
from pyresample.geometry import AreaDefinition
from uwsift.workspace.importer import available_satpy_readers, SatpyImporter
from uwsift.common import Info, Kind
from uwsift.common import Info, Kind, Platform, Instrument
import pytest
def test_available_satpy_readers_defaults():
......@@ -84,9 +86,7 @@ def _get_data_array_generator(data_arrs):
yield from data_arrs
def test_satpy_importer_basic(tmpdir, monkeypatch, mocker):
"""Basic import test using Satpy."""
db_sess = mocker.MagicMock()
def _get_fake_g16_abi_c01_scene(mocker):
attrs = {
'name': 'C01',
'wavelength': (1.0, 2.0, 3.0),
......@@ -105,13 +105,44 @@ def test_satpy_importer_basic(tmpdir, monkeypatch, mocker):
'start_time': datetime(2018, 9, 10, 17, 0, 31, 100000),
'end_time': datetime(2018, 9, 10, 17, 11, 7, 800000),
'standard_name': 'toa_bidirectional_reflectance',
'sensor': 'abi',
'platform_name': 'GOES-16',
'platform_shortname': 'G16',
}
data_arr = xr.DataArray(da.from_array(np.empty((5, 5), dtype=np.float64), chunks='auto'),
attrs=attrs)
scn = Scene()
scn['C01'] = data_arr
scn.load = mocker.MagicMock() # don't do anything on load
return scn
def _get_fake_g18_abi_c01_scene(mocker):
scn = _get_fake_g16_abi_c01_scene(mocker)
scn['C01'].attrs['platform_name'] = 'GOES-18'
scn['C01'].attrs['platform_shortname'] = 'G18'
return scn
def _get_fake_g18_abi_c01_scene_no_pname(mocker):
# old versions of satpy didn't assign a proper platform_name
scn = _get_fake_g18_abi_c01_scene(mocker)
scn['C01'].attrs['platform_name'] = None
return scn
@pytest.mark.parametrize(
["get_scene", "exp_platform"],
[
(_get_fake_g16_abi_c01_scene, Platform.GOES_16),
(_get_fake_g18_abi_c01_scene, Platform.GOES_18),
(_get_fake_g18_abi_c01_scene_no_pname, Platform.GOES_18),
]
)
def test_satpy_importer_basic(get_scene, exp_platform, tmpdir, monkeypatch, mocker):
"""Basic import test using Satpy."""
db_sess = mocker.MagicMock()
scn = get_scene(mocker)
imp = SatpyImporter(['/test/file.nc'], tmpdir, db_sess,
scene=scn,
reader='abi_l1b',
......@@ -122,6 +153,8 @@ def test_satpy_importer_basic(tmpdir, monkeypatch, mocker):
assert len(products) == 1
assert products[0].info[Info.CENTRAL_WAVELENGTH] == 2.0
assert products[0].info[Info.STANDARD_NAME] == 'toa_bidirectional_reflectance'
assert products[0].info[Info.PLATFORM] == exp_platform
assert products[0].info[Info.INSTRUMENT] == Instrument.ABI
def test_satpy_importer_contour_0_360(tmpdir, monkeypatch, mocker):
......
......@@ -110,6 +110,8 @@ NOMINAL_WAVELENGTHS = {
Platform.GOES_16: _NW_GOESR_ABI,
Platform.GOES_17: _NW_GOESR_ABI,
Platform.GOES_18: _NW_GOESR_ABI,
Platform.GOES_19: _NW_GOESR_ABI,
}
# CF compliant Standard Names (should be provided by input files or the workspace)
......
......@@ -50,6 +50,8 @@ DEFAULT_GUIDEBOOK = ABI_AHI_Guidebook
GUIDEBOOKS = {
Platform.GOES_16: ABI_AHI_Guidebook,
Platform.GOES_17: ABI_AHI_Guidebook,
Platform.GOES_18: ABI_AHI_Guidebook,
Platform.GOES_19: ABI_AHI_Guidebook,
Platform.HIMAWARI_8: ABI_AHI_Guidebook,
Platform.HIMAWARI_9: ABI_AHI_Guidebook,
}
......@@ -674,6 +676,8 @@ class GeoTiffImporter(aSingleFileWithSingleProductImporter):
PLATFORM_ID_TO_PLATFORM = {
'G16': Platform.GOES_16,
'G17': Platform.GOES_17,
'G18': Platform.GOES_18,
'G19': Platform.GOES_19,
# hsd2nc export of AHI data as PUG format
'Himawari-8': Platform.HIMAWARI_8,
'Himawari-9': Platform.HIMAWARI_9,
......@@ -1022,7 +1026,7 @@ class SatpyImporter(aImporter):
def _get_platform_instrument(attrs: dict):
"""Convert SatPy platform_name/sensor to """
attrs[Info.INSTRUMENT] = attrs.get('sensor')
attrs[Info.PLATFORM] = attrs.get('platform_name')
attrs[Info.PLATFORM] = attrs.get('platform_name') or attrs.get('platform_shortname')
# Special handling of GRIB forecast data
if 'centreDescription' in attrs and \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment