Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Sep 19, 2024
1 parent 31fb1ea commit 92e02d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gpm/gv/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def plot_quicklook(
mask_sr = da_sr > z_min_threshold_sr

# Retrieve SR extent
sr_extent = ds_sr.gpm.extent()
sr_extent = ds_sr.gpm.extent() # noqa
gr_extent = ds_gr.xradar_dev.extent()

# Create figure
Expand Down
52 changes: 16 additions & 36 deletions gpm/utils/pyresample.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@
def remap(src_ds, dst_ds, radius_of_influence=20000, fill_value=np.nan):
"""Remap dataset to another one using nearest-neighbour."""
from gpm.checks import get_spatial_dimensions
from gpm.dataset.crs import (
_get_crs_coordinates,
_get_swath_dim_coords,
_get_proj_dim_coords,
set_dataset_crs
)
from gpm.dataset.crs import _get_crs_coordinates, _get_proj_dim_coords, _get_swath_dim_coords, set_dataset_crs

try:
from pyresample.future.resamplers.nearest import KDTreeNearestXarrayResampler
except ImportError:
Expand All @@ -59,45 +55,28 @@ def remap(src_ds, dst_ds, radius_of_influence=20000, fill_value=np.nan):
dst_crs_coords = _get_crs_coordinates(dst_ds)[0]

# Rename dimensions to x, y for pyresample compatibility
<<<<<<< HEAD
x_dim, y_dim = get_spatial_dimensions(src_ds)
src_ds = src_ds.swap_dims({y_dim: "y", x_dim: "x"})

# Define spatial coordinates of new object
if dst_ds.gpm.is_orbit: # SwathDefinition
x_coord, y_coord = _get_swath_dim_coords(dst_ds) # dst_ds.gpm.x, # dst_ds.gpm.y
if dst_ds.gpm.is_orbit: # SwathDefinition
x_coord, y_coord = _get_swath_dim_coords(dst_ds) # dst_ds.gpm.x, # dst_ds.gpm.y
dst_spatial_coords = {
x_coord: xr.DataArray(dst_ds[x_coord].data,
dims=list(dst_ds[x_coord].dims),
attrs=dst_ds[x_coord].attrs),
y_coord: xr.DataArray(dst_ds[y_coord].data,
dims=list(dst_ds[y_coord].dims),
attrs=dst_ds[y_coord].attrs),
x_coord: xr.DataArray(dst_ds[x_coord].data, dims=list(dst_ds[x_coord].dims), attrs=dst_ds[x_coord].attrs),
y_coord: xr.DataArray(dst_ds[y_coord].data, dims=list(dst_ds[y_coord].dims), attrs=dst_ds[y_coord].attrs),
}
else: # AreaDefinition
else: # AreaDefinition
x_arr, y_arr = dst_area.get_proj_coords()
x_coord, y_coord = _get_proj_dim_coords(dst_ds) # dst_ds.gpm.x, # dst_ds.gpm.y
x_coord, y_coord = _get_proj_dim_coords(dst_ds) # dst_ds.gpm.x, # dst_ds.gpm.y
dst_spatial_coords = {
x_coord: xr.DataArray(x_arr,
dims=list(dst_ds[x_coord].dims),
attrs=dst_ds[x_coord].attrs),
y_coord: xr.DataArray(y_arr,
dims=list(dst_ds[y_coord].dims),
attrs=dst_ds[y_coord].attrs),
x_coord: xr.DataArray(x_arr, dims=list(dst_ds[x_coord].dims), attrs=dst_ds[x_coord].attrs),
y_coord: xr.DataArray(y_arr, dims=list(dst_ds[y_coord].dims), attrs=dst_ds[y_coord].attrs),
}
# Update units attribute if was rad or radians for geostationary data !
if dst_spatial_coords[x_coord].attrs.get("units", "") in ["rad", "radians"]:
dst_spatial_coords[x_coord].attrs["units"] = "deg"
dst_spatial_coords[y_coord].attrs["units"] = "deg"

=======
if src_ds.gpm.is_orbit:
src_ds = src_ds.swap_dims({"cross_track": "y", "along_track": "x"})
elif not np.all(np.isin(["x", "y"], list(src_ds.dims))):
# TODO: GENERALIZE to allow also latitude, longitude !
src_ds = src_ds.swap_dims({"lat": "y", "lon": "x"})

>>>>>>> e740a7b5f4b1f3d796f1207a41d1706653876c2a
# Define resampler
resampler = KDTreeNearestXarrayResampler(src_area, dst_area)
resampler.precompute(radius_of_influence=radius_of_influence)
Expand All @@ -121,16 +100,17 @@ def remap(src_ds, dst_ds, radius_of_influence=20000, fill_value=np.nan):

# Revert to original spatial dimensions (of destination dataset)
x_dim, y_dim = get_spatial_dimensions(dst_ds)
ds = ds.swap_dims({"y": y_dim, "x": x_dim })
ds = ds.swap_dims({"y": y_dim, "x": x_dim})

# Add spatial coordinates
ds = ds.assign_coords(dst_spatial_coords)

# Add destination crs
ds = set_dataset_crs(ds,
crs=dst_area.crs,
grid_mapping_name=dst_crs_coords,
)
ds = set_dataset_crs(
ds,
crs=dst_area.crs,
grid_mapping_name=dst_crs_coords,
)
# Coordinates specifics to gpm-api
gpm_api_coords = ["gpm_id", "gpm_time", "gpm_granule_id", "gpm_along_track_id", "gpm_cross_track_id"]
gpm_api_coords_dict = {c: dst_ds.reset_coords()[c] for c in gpm_api_coords if c in dst_ds.coords}
Expand Down

0 comments on commit 92e02d6

Please sign in to comment.