Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TKE Calculation on Resampled Timeseries #1384

Open
tjwixtrom opened this issue May 28, 2020 · 0 comments
Open

TKE Calculation on Resampled Timeseries #1384

tjwixtrom opened this issue May 28, 2020 · 0 comments
Labels
Type: Feature New functionality

Comments

@tjwixtrom
Copy link
Contributor

Currently the tke function is designed to perform the calculation as averaged over the entire input time series. Often it is desirable to average over a smaller time period. This is easy to do for calculation of something like variance with Xarray; var = data.resample(freq='1Min').var(). It would be useful to have a similar functionality within Metpy, where calculation like TKE and similar (I'm hoping to add some others) would be performed on a user-specified resample frequency, or be designed to accept an Xarray resample object. Below is a working example, though probably not robust enough yet.

def turbulence_kinetic_energy(*args, freq=None, dim=None):
    terms = []
    for arg in args:
        if freq is None:
            perturbation = arg - arg.mean()
            term = (perturbation**2).mean()
        else:
            perturbation = arg - arg.mean(dim=dim)
            term = (perturbation**2).resample(time=freq).mean(dim=dim)
        terms.append(term) 
    return 0.5 * (sum(terms))

And an example of a function that accepts resample objects:

def turbulence_intensity(ws, dim=None):
    sdev = ws.std(dim=dim)
    mean = ws.mean(dim=dim)
    return sdev / mean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New functionality
Projects
None yet
Development

No branches or pull requests

1 participant