Skip to content
Snippets Groups Projects
Commit 9e0e646e authored by tomrink's avatar tomrink
Browse files

snapshot...

parent 9c609b64
Branches
Tags
No related merge requests found
......@@ -442,3 +442,46 @@ def get_voxel_s(xr_dataset, fld_name_s, lon, lat, press, x_width=3, y_width=3, z
fakeDim1=lat_coords[y_start:y_stop], fakeDim0=plevs[z_start:z_stop])
return sub_fld
def get_volume(xr_dataset, fld_name, press_range=None, lon_range=None, lat_range=None):
# p_idx = value_to_index(plevs, press)
fld = xr_dataset[fld_name]
x_lo = 0
x_hi = NX
y_lo = 0
y_hi = NY
z_lo = 0
z_hi = NZ
if lon_range is not None:
lon_lo = lon_range[0]
lon_hi = lon_range[1]
if lon360:
if lon_lo < 0:
lon_lo += 360
if lon_hi < 0:
lon_hi += 360
x_lo = value_to_index(lon_coords, lon_lo)
x_hi = value_to_index(lon_coords, lon_hi)
if lat_range is not None:
lat_lo = lat_range[0]
lat_hi = lat_range[1]
y_lo = value_to_index(lat_coords, lat_lo)
y_hi = value_to_index(lat_coords, lat_hi)
if press_range is not None:
z_lo = value_to_index(plevs, press_range[0])
z_hi = value_to_index(plevs, press_range[1])
sub_fld = fld[y_lo:y_hi, x_lo:x_hi, z_lo:z_hi]
sub_fld = sub_fld.expand_dims('channel')
sub_fld = sub_fld.assign_coords(channel=[fld_name], fakeDim2=lon_coords[x_lo:x_hi], fakeDim1=lat_coords[y_lo:y_hi], fakeDim0=plevs[z_lo:z_hi])
return sub_fld
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment