Commit 3eb0face authored by Carl Schreck's avatar Carl Schreck
Browse files

Added check_basin

parent 31908e7b
......@@ -8,6 +8,7 @@ __license__ = "BSD-3.0"
import xarray as xr
import numpy as np
import sys
#from shapely.geometry import Point, Polygon
sys.path.append('/home/carl/lib/python')
import cjs
......@@ -21,6 +22,7 @@ class Ibtracs:
else:
self.inpath = inpath
self.ds = xr.open_dataset(self.inpath)
self.ds['lon'] = self.ds.lon.where(self.ds.lon > 0, self.ds.lon+360)
def find_tropical(self, thresh=35, keep_subtropical=True):
if keep_subtropical:
......@@ -47,14 +49,55 @@ class Ibtracs:
is_eligible = is_main & is_tropical & is_strong
neligible = np.sum(is_eligible, axis=1)
ind_eligible = np.argmax(is_eligible,1)
retval = is_eligible
retval[:,:] = False
retval = False & is_eligible
for i,j in enumerate(ind_eligible):
if neligible[i] > 0:
retval[i,j] = True
retval['oned'] = np.any(retval, axis=1)
# print(np.c_[self.ds.sid.values[retval1d],self.ds.usa_wind.values[retval],lmi[retval1d]])
return(retval)
def check_basin(self, target_basin='NA'):
target_basin = target_basin.upper()
# Handle special cases
if target_basin in ['ALL', 'GL']:
retval = self.ds.lat.notnull()
elif target_basin is 'NH':
retval = self.ds.lat >= 0
elif target_basin is 'SH':
retval = self.ds.lat < 0
elif target_basin is 'WMOSP':
retval = (self.ds.lat < 0) & (self.ds.lon >= 160)
elif target_basin is 'WMOSI':
retval = (self.ds.lat < 0) & (self.ds.lon < 90)
elif target_basin is 'WMOAUS':
retval = ((self.ds.lat < 0) & (self.ds.lon >= 90)
& (self.ds.lon < 160))
elif target_basin is 'WMOCP':
retval = ((self.ds.lat >= 0) & (self.ds.lat < 40)
& (self.ds.lon >= 180) & (self.ds.lon < 220))
elif target_basin is 'NA_MDR':
retval = ((self.ds.lat >= 10) & (self.ds.lat < 20)
& (self.ds.lon >= 275) & (self.ds.lon < 340))
elif target_basin is 'US_KOSSIN':
retval = ((self.ds.lat >= 25) & (self.ds.lat < 50)
& (self.ds.lon >= 260) & (self.ds.lon < 295))
elif target_basin is 'US_GC':
retval = ((self.ds.lat >= 25) & (self.ds.lat < 35)
& (self.ds.lon >= 260) & (self.ds.lon < 275))
elif target_basin is 'US_FL':
retval = ((self.ds.lat >= 20) & (self.ds.lat < 30)
& (self.ds.lon >= 275) & (self.ds.lon < 285))
#US_EC will require point in polygon
#manual function: http://www.ariel.com.au/a/python-point-int-poly.html
#https://automating-gis-processes.github.io/CSC18/lessons/L4/point-in-polygon.html
else
retval = target_basin == self.ds.basin
return(retval)
......@@ -16,7 +16,8 @@ cjs.tstamp('Here we go!')
#ibt = ibtracs.Ibtracs('last3years')
ibt = ibtracs.Ibtracs('ALL')
#ibt = ibtracs.Ibtracs('last3years')
ibt.find_first_ind(96)
lmi_ind = ibt.find_first_ind(-1)
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