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

Fix coord renaming for AOD product in 'abi_l2_nc' reader #2216

Merged
merged 3 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion satpy/readers/abi_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""Advance Baseline Imager reader base class for the Level 1b and l2+ reader."""

import logging
from contextlib import suppress
from datetime import datetime

import numpy as np
Expand Down Expand Up @@ -76,7 +77,8 @@ def _rename_dims(nc):
if 't' in nc.dims or 't' in nc.coords:
nc = nc.rename({'t': 'time'})
if 'goes_lat_lon_projection' in nc:
nc = nc.rename({'lon': 'x', 'lat': 'y'})
with suppress(ValueError):
nc = nc.rename({'lon': 'x', 'lat': 'y'})
return nc

@property
Expand Down
66 changes: 66 additions & 0 deletions satpy/tests/reader_tests/test_abi_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,69 @@ def test_get_area_def_latlon(self, adef):
self.assertEqual(call_args[4], self.reader.ncols)
self.assertEqual(call_args[5], self.reader.nlines)
np.testing.assert_allclose(call_args[6], (-85.0, -20.0, -65.0, 20))


class Test_NC_ABI_L2_area_AOD(unittest.TestCase):
"""Test the NC_ABI_L2 reader for the AOD product."""

@mock.patch('satpy.readers.abi_base.xr')
def setUp(self, xr_):
"""Create fake data for the tests."""
from satpy.readers.abi_l2_nc import NC_ABI_L2
proj = xr.DataArray(
[],
attrs={'semi_major_axis': 1.,
'semi_minor_axis': 1.,
'inverse_flattening': 1.,
'longitude_of_prime_meridian': 0.0,
}
)

proj_ext = xr.DataArray(
[],
attrs={'geospatial_westbound_longitude': -85.0,
'geospatial_eastbound_longitude': -65.0,
'geospatial_northbound_latitude': 20.0,
'geospatial_southbound_latitude': -20.0,
'geospatial_lat_center': 0.0,
'geospatial_lon_center': -75.0,
})

x__ = xr.DataArray(
[0, 1],
attrs={'scale_factor': 2., 'add_offset': -1.},
dims=('x',),
)
y__ = xr.DataArray(
[0, 1],
attrs={'scale_factor': -2., 'add_offset': 1.},
dims=('y',),
)
fake_dataset = xr.Dataset(
data_vars={
'goes_lat_lon_projection': proj,
'geospatial_lat_lon_extent': proj_ext,
'x': x__,
'y': y__,
'RSR': xr.DataArray(np.ones((2, 2)), dims=('y', 'x')),
},
)
xr_.open_dataset.return_value = fake_dataset

self.reader = NC_ABI_L2('filename',
{'platform_shortname': 'G16', 'observation_type': 'RSR',
'scene_abbr': 'C', 'scan_mode': 'M3'},
{'filetype': 'info'})

@mock.patch('satpy.readers.abi_base.geometry.AreaDefinition')
def test_get_area_def_xy(self, adef):
"""Test the area generation."""
self.reader.get_area_def(None)

self.assertEqual(adef.call_count, 1)
call_args = tuple(adef.call_args)[0]
self.assertDictEqual(call_args[3], {'proj': 'latlong', 'a': 1.0, 'b': 1.0, 'fi': 1.0, 'pm': 0.0,
'lon_0': -75.0, 'lat_0': 0.0})
self.assertEqual(call_args[4], self.reader.ncols)
self.assertEqual(call_args[5], self.reader.nlines)
np.testing.assert_allclose(call_args[6], (-85.0, -20.0, -65.0, 20))