Created
April 27, 2021 14:31
-
-
Save dstansby/e735c165cf252c4b0a530f5a3cbe2761 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
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