From 6bb05cb42859479a404eff976745749dad98bbbd Mon Sep 17 00:00:00 2001 From: Nils Brueggemann <nils.brueggemann@mpimet.mpg.de> Date: Tue, 11 Mar 2025 12:16:29 +0100 Subject: [PATCH] pyicon_tb.py: Resolved some bugs regarding argument passing from interp_to_rectgrid_xr to native and healpix interpolation. --- pyicon/pyicon_tb.py | 71 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/pyicon/pyicon_tb.py b/pyicon/pyicon_tb.py index d978aee..f38222b 100644 --- a/pyicon/pyicon_tb.py +++ b/pyicon/pyicon_tb.py @@ -229,16 +229,16 @@ def smoothen_data(da_i, antialias=2): return da_out def native_to_rectgrid(arr, - fpath_ckdtree='auto', - res=0.3, - lon_reg=None, lat_reg=None, - coordinates='auto', - radius_of_influence=1000e3, - compute=True, - mask_out_of_range=True, - mask_out_of_range_before=False, - verbose=True, - ): + fpath_ckdtree='auto', + res=0.3, + lon_reg=None, lat_reg=None, + coordinates='auto', + radius_of_influence=1000e3, + compute=True, + mask_out_of_range=True, + mask_out_of_range_before=False, + verbose=True, + ): # --- rename dimensions if necessary for dim in ['cell', 'edge', 'vertex', 'ncells_2', 'ncells_3']: @@ -329,9 +329,24 @@ def native_to_rectgrid(arr, return arr_interp def interp_to_rectgrid_xr(arr, + # native_to_rectgrid params + fpath_ckdtree='auto', + coordinates='auto', + radius_of_influence=1000e3, + mask_out_of_range=True, + mask_out_of_range_before=False, + # hp_to_rectgrid params + lon=None, + lat=None, + # common args + lon_reg=None, lat_reg=None, + res=0.3, + compute=True, + verbose=True, + # local arguments mask_to_zero=False, antialias=1, - **kwargs): + ): # --- check if data is healpix try: if arr.grid_mapping=='crs' or arr.grid_mapping=='healpix': @@ -346,9 +361,28 @@ def interp_to_rectgrid_xr(arr, # --- if data is healpix to healpix interpolation and exit if grid_type=='native': - arr_interp = native_to_rectgrid(arr, **kwargs) + arr_interp = native_to_rectgrid(arr, + fpath_ckdtree=fpath_ckdtree, + coordinates=coordinates, + radius_of_influence=radius_of_influence, + mask_out_of_range=mask_out_of_range, + mask_out_of_range_before=mask_out_of_range_before, + # common + lon_reg=lon_reg, lat_reg=lat_reg, + res=res, + compute=compute, + verbose=True, + ) elif grid_type=='healpix': - arr_interp = hp_to_rectgrid(arr, **kwargs) + arr_interp = hp_to_rectgrid(arr, + lon=lon, + lat=lat, + # common + lon_reg=lon_reg, lat_reg=lat_reg, + res=res, + compute=compute, + verbose=True, + ) # --- set missing values to 0. if mask_to_zero: @@ -477,8 +511,17 @@ def hp_to_section(arr, name='170W', p1=None, p2=None, npoints=200): arr_interp = arr_interp.assign_attrs(attrs) return arr_interp -def hp_to_rectgrid(arr, lon=None, lat=None, lon_reg=[-180,180], lat_reg=[-90, 90], res=0.3, compute=True): +def hp_to_rectgrid(arr, + lon=None, lat=None, + lon_reg=None, lat_reg=None, + res=0.3, compute=True, + verbose=False, + ): import healpy as hp + if lon_reg is None: + lon_reg=[-180,180] + if lat_reg is None: + lat_reg=[-90, 90] if lon is None: lon = np.arange(lon_reg[0], lon_reg[1], res) if lat is None: -- GitLab