Commit 1f1bbcf1 authored by Carl Schreck's avatar Carl Schreck

Automated Nightly Commit - Fri Jun 14 00:01:13 EDT 2019

parent 4b1cc362
...@@ -7,25 +7,58 @@ __copyright__ = "Copyright 2019, North Carolina State University" ...@@ -7,25 +7,58 @@ __copyright__ = "Copyright 2019, North Carolina State University"
__license__ = "BSD-3.0" __license__ = "BSD-3.0"
import xarray as xr import xarray as xr
import sys import pandas as pd
sys.path.append('/Users/carl/lib/python') import os
import cjs import cjs # '~carl/lib-py'
cjs.tstamp('Here we go!')
# These are some parameters that could be useful to have up top # These are some parameters that could be useful to have up top
wave_name = 'kelvin' wave_name = 'kelvin'
in_path = '~/data/ var_name = 'olr'
min_lon = 100
cjs.tstamp('Here we go!') max_lon = 100
min_lat = -10
max_lat = 10
out_path = 'output/' + var_name + '_' + wave_name
cjs.tstamp('Reading and averaging') cjs.tstamp('Reading and averaging')
if var_name == 'olr':
in_path = os.environ['NASA_YMC'] + '/fcst_verif/olr.k09.nc'
elif var_name == 'trmm':
in_path = os.environ['NASA_YMC'] + '/fcst_verif/rain.k09.nc'
ds = xr.open_dataset(in_path)
if min_lon == max_lon:
wave = ds[wave_name].sel(lon=min_lon, method='nearest')
else:
wave = ds[wave_name].sel(lon=slice(min_lon,max_lon)).mean(dim='lon')
if min_lat == max_lat:
wave = wave.sel(lat=min_lat, method='nearest')
else:
wave = wave.sel(lat=slice(min_lat,max_lat)).mean(dim='lat')
cjs.tstamp('Calculate tendency') cjs.tstamp('Calculate tendency')
tend = wave.differentiate('time')
cjs.tstamp('Standardize both') cjs.tstamp('Standardize both')
wave = (wave - wave.mean()) / wave.std()
tend = (tend - tend.mean()) / tend.std()
cjs.tstamp('Calculate amplitude and phase') cjs.tstamp('Calculate amplitude and phase')
amp = (wave**2 + tend**2)**0.5
phase = xr.where((wave >= 0) & (abs(wave) >= abs(tend)), 'H', '')
phase = xr.where((wave < 0) & (abs(wave) >= abs(tend)), 'L', phase)
phase = xr.where((tend >= 0) & (abs(tend) >= abs(wave)), 'I', phase)
phase = xr.where((tend < 0) & (abs(tend) >= abs(wave)), 'D', phase)
cjs.tstamp('Write result') cjs.tstamp('Write result')
df = pd.DataFrame({'time':wave.time, 'wave':wave, 'tend':tend, 'amp':amp,
'phase':phase})
df.to_csv(out_path + '.csv', index=False, float_format='%6.3f')
cjs.tstamp('Thank you, come again.') cjs.tstamp('Thank you, come again.')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment