Skip to content

How do I make this code faster #2821

Answered by dopplershift
DOptimusPrime asked this question in Q&A
Discussion options

You must be logged in to vote

I did some testing locally with some synthetic data I made of similar size (though for only two time chunks of 2208):

import metpy.calc as mpcalc
from metpy.units import units
import numpy as np
import xarray as xr

ntime = 2208
nlat = 1015
nlon = 1359

# Create one big array and then tell xarray to turn into Dask chunks
u = v = xr.DataArray(np.full((2 * ntime, nlat, nlon), 1., dtype=np.float32),
                     coords={'time': np.arange(2 * ntime), 'lat': np.linspace(-90, 90, nlat), 'lon': np.linspace(0, 360, nlon)},
                     attrs={'units': 'm/s'}).chunk({'time': 2208})

# Calculate, .compute() tells Dask to actually do the computation
s = mpcalc.wind_speed(u, v).compute()

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@DOptimusPrime
Comment options

@dopplershift
Comment options

@DOptimusPrime
Comment options

@dopplershift
Comment options

@DOptimusPrime
Comment options

Comment options

You must be logged in to vote
1 reply
@DOptimusPrime
Comment options

Answer selected by dopplershift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants