Skip to content

Commit

Permalink
Make code work evenb without xarray available, and skip verbose warning
Browse files Browse the repository at this point in the history
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
  • Loading branch information
Adam.Dybbroe committed Nov 21, 2023
1 parent 17aabb9 commit a7650f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
10 changes: 4 additions & 6 deletions pyresample/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from typing import Optional, Sequence, Union

import numpy as np
import xarray as xr
import pyproj
import yaml
from pyproj import Geod, Proj
Expand Down Expand Up @@ -695,12 +694,11 @@ def geocentric_resolution(self, ellps='WGS84', radius=None, nadir_factor=2):
raise RuntimeError("Can't confidently determine geocentric "
"resolution for 1D swath.")

if isinstance(self.lons, xr.DataArray):
if isinstance(self.lons, DataArray):
rows = self.lons['y'].shape[0]
else:
# Data have no information on dimensions, so we assume first dimension (the rows) is the y-axis:
logger.warning('As Numpy data arrays carry no information on the data layout we here ' +
'assume the first dimension (the rows) is the y-axis (the satellite scans)')
# Data have no information on dimensions, so we assume first
# dimension (the rows) is the y-axis (the satellite scans):
rows = self.shape[0]

start_row = rows // 2 # middle row
Expand All @@ -710,7 +708,7 @@ def geocentric_resolution(self, ellps='WGS84', radius=None, nadir_factor=2):
else:
dst = CRS("+proj=cart +ellps={}".format(ellps))
# simply take the first two columns of the middle of the swath
if isinstance(self.lons, xr.DataArray):
if isinstance(self.lons, DataArray):
lons = self.lons.sel(y=start_row)[:2]
lats = self.lats.sel(y=start_row)[:2]
else:
Expand Down
11 changes: 2 additions & 9 deletions pyresample/test/test_geometry/test_swath.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Test AreaDefinition objects."""
import contextlib

import logging
import dask.array as da
import numpy as np
import pytest
Expand Down Expand Up @@ -513,18 +512,12 @@ def test_striding(self, create_test_swath):
np.testing.assert_allclose(res.lons, [[178.5, -179.5]])
np.testing.assert_allclose(res.lats, [[0, 0]], atol=2e-5)

def test_swath_def_geocentric_resolution_numpy(self, caplog, create_test_swath):
def test_swath_def_geocentric_resolution_numpy(self, create_test_swath):
"""Test the SwathDefinition.geocentric_resolution method - lon/lat are a numpy arrays."""
lats = np.array([[0, 0, 0, 0], [1, 1, 1, 1.0]])
lons = np.array([[178.5, 179.5, -179.5, -178.5], [178.5, 179.5, -179.5, -178.5]])
sd = create_test_swath(lons, lats)

with caplog.at_level(logging.DEBUG):
geo_res = sd.geocentric_resolution()

log_output = ('As Numpy data arrays carry no information on the data layout we here assume ' +
'the first dimension (the rows) is the y-axis (the satellite scans)')
assert log_output in caplog.text
geo_res = sd.geocentric_resolution()

# google says 1 degrees of longitude is about ~111.321km
# so this seems good
Expand Down

0 comments on commit a7650f4

Please sign in to comment.