Skip to content

Instantly share code, notes, and snippets.

@dstansby
Created April 27, 2021 14:31
Show Gist options
  • Save dstansby/e735c165cf252c4b0a530f5a3cbe2761 to your computer and use it in GitHub Desktop.
Save dstansby/e735c165cf252c4b0a530f5a3cbe2761 to your computer and use it in GitHub Desktop.
def load_data(files):
# Number of data points for each variable and time
npoints = 360 * 180
# Variable names
variables = ['lons', 'lats', 'b_all', 'b_feet', 'b_ss']
# Empty array to store data
all_data = np.zeros((len(variables), len(files), npoints)) * np.nan
dtimes = []
for j, f in enumerate(files):
f = Path(f)
dtimes.append(datetime.strptime(f.stem, dtime_fmt))
d = np.load(f)
for i, var in enumerate(variables):
# Pad data to have the same length
data = d[var]
all_data[i, j, :data.size] = data
all_data = xr.DataArray(all_data,
dims=('variable', 'time', 'points'),
coords={'variable': variables, 'time': dtimes, 'points': np.arange(npoints)})
return all_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment