Created
March 22, 2024 18:18
-
-
Save rileyhales/fe588578ff803e3609964c5d19fa9220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
with xr.open_dataset('./2023era5/2023_11_era5_hourly.nc') as ds: | |
# find the time steps where the runoff is not nan when expver=1 | |
a = ds.ro.sel(latitude=0, longitude=0, expver=1) | |
expver1_timesteps = a.time[~np.isnan(a)] | |
# find the time steps where the runoff is not nan when expver=5 | |
b = ds.ro.sel(latitude=0, longitude=0, expver=5) | |
expver5_timesteps = b.time[~np.isnan(b)] | |
# assert that the two timesteps combined are the same as the original | |
assert len(ds.time) == len(expver1_timesteps) + len(expver5_timesteps) | |
# combine the two | |
xr.concat([ | |
ds.sel(expver=1, time=expver1_timesteps.values).drop_vars('expver'), | |
ds.sel(expver=5, time=expver5_timesteps.values).drop_vars('expver') | |
], dim='time').to_netcdf('./2023era5/2023_11_era5_hourly_noexpver.nc') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment