def __init__(self, utc, datadir, wind=True, hail=True, torn=True): self.utc = utc tt = utils.ensure_timetuple(utc) yr = str(tt[0])[-2:] mth = '{0:02d}'.format(tt[1]) day = '{0:02d}'.format(tt[2]) threats = [] if wind: threats.append('wind') if hail: threats.append('hail') if torn: threats.append('torn') self.reports = {} for threat in threats: fname = '{0}{1}{2}_rpts_{3}.csv'.format(yr, mth, day, threat) # Check to see if file exists fpath = os.path.join(datadir, fname) scan = glob.glob(fpath) if len(scan) == 0: url = 'http://www.spc.noaa.gov/climo/reports/' cmd = 'wget {0}{1} -P {2}'.format(url, fname, datadir) os.system(cmd) if threat == 'wind': names = ('time', 'speed', 'location', 'county', 'state', 'lat', 'lon') formats = ('S4', 'S4', 'S4', 'S4', 'S4', 'f4', 'f4') elif threat == 'hail': names = ('time', 'size', 'location', 'county', 'state', 'lat', 'lon') formats = ('S4', 'S4', 'S4', 'S4', 'S4', 'f4', 'f4') elif threat == 'torn': names = ('time', 'fscale', 'location', 'county', 'state', 'lat', 'lon') formats = ('S4', 'S4', 'S4', 'S4', 'S4', 'f4', 'f4') self.reports[threat] = N.loadtxt(fpath, dtype={ 'names': names, 'formats': formats }, skiprows=1, delimiter=',', usecols=list(range(8))) #times = reports['time'] self.threats = threats
def report_datenum(self, timestamp): """ convert timestamp to datenum format. """ tt = utils.ensure_timetuple(self.utc) itime_dn = calendar.timegm(tt[0], tt[1], tt[2], 12, 0, 0) hr = int(timestamp[:2]) mn = int(timestamp[2:]) if hr < 11: # After midnight UTC hr = hr + 24 tdelta = ((hr - 12) * 60 * 60) + (mn * 60) return itime_dn + tdelta
def get_radar_fname(self): tt = utils.ensure_timetuple(self.utc) # Date for format change change = (2010, 10, 25, 0, 0, 0) if tt[0] < 1995: print("Too early in database.") raise Exception elif calendar.timegm(tt) < calendar.timegm(change): self.fmt = 'n0r' else: self.fmt = 'n0q' fname = '{0}_{1:04d}{2:02d}{3:02d}{4:02d}{5:02d}'.format(self.fmt, *tt) return fname
def get_radar_fname(self): tt = utils.ensure_timetuple(self.utc) # Date for format change change = (2010, 10, 25, 0, 0, 0) if tt[0] < 1995: print("Too early in database.") raise Exception elif calendar.timegm(tt) < calendar.timegm(change): self.fmt = "n0r" else: self.fmt = "n0q" fname = "{0}_{1:04d}{2:02d}{3:02d}{4:02d}{5:02d}".format(self.fmt, *tt) return fname
def report_datenum(self,timestamp): """ convert timestamp to datenum format. """ tt = utils.ensure_timetuple(self.utc) itime_dn = calendar.timegm(tt[0],tt[1],tt[2],12,0,0) hr = int(timestamp[:2]) mn = int(timestamp[2:]) if hr<11: # After midnight UTC hr = hr+24 tdelta = ((hr-12)*60*60) + (mn*60) return itime_dn + tdelta
def __init__(self,utc,datadir,wind=True,hail=True,torn=True): self.utc = utc tt = utils.ensure_timetuple(utc) yr = str(tt[0])[-2:] mth = '{0:02d}'.format(tt[1]) day = '{0:02d}'.format(tt[2]) threats = [] if wind: threats.append('wind') if hail: threats.append('hail') if torn: threats.append('torn') self.reports = {} for threat in threats: fname = '{0}{1}{2}_rpts_{3}.csv'.format( yr,mth,day,threat) # Check to see if file exists fpath = os.path.join(datadir,fname) scan = glob.glob(fpath) if len(scan) == 0: url = 'http://www.spc.noaa.gov/climo/reports/' cmd = 'wget {0}{1} -P {2}'.format( url,fname,datadir) os.system(cmd) if threat=='wind': names = ('time','speed','location','county', 'state','lat','lon') formats = ('S4','S4','S4','S4', 'S4','f4','f4') elif threat=='hail': names = ('time','size','location','county', 'state','lat','lon') formats = ('S4','S4','S4','S4', 'S4','f4','f4') elif threat=='torn': names = ('time','fscale','location','county', 'state','lat','lon') formats = ('S4','S4','S4','S4', 'S4','f4','f4') self.reports[threat] = N.loadtxt(fpath,dtype={'names':names,'formats':formats}, skiprows=1,delimiter=',',usecols=range(8)) #times = reports['time'] self.threats = threats
def __init__(self, utc, datadir, wind=True, hail=True, torn=True): self.utc = utc tt = utils.ensure_timetuple(utc) yr = str(tt[0])[-2:] mth = "{0:02d}".format(tt[1]) day = "{0:02d}".format(tt[2]) threats = [] if wind: threats.append("wind") if hail: threats.append("hail") if torn: threats.append("torn") self.reports = {} for threat in threats: fname = "{0}{1}{2}_rpts_{3}.csv".format(yr, mth, day, threat) # Check to see if file exists fpath = os.path.join(datadir, fname) scan = glob.glob(fpath) if len(scan) == 0: url = "http://www.spc.noaa.gov/climo/reports/" cmd = "wget {0}{1} -P {2}".format(url, fname, datadir) os.system(cmd) if threat == "wind": names = ("time", "speed", "location", "county", "state", "lat", "lon") formats = ("S4", "S4", "S4", "S4", "S4", "f4", "f4") elif threat == "hail": names = ("time", "size", "location", "county", "state", "lat", "lon") formats = ("S4", "S4", "S4", "S4", "S4", "f4", "f4") elif threat == "torn": names = ("time", "fscale", "location", "county", "state", "lat", "lon") formats = ("S4", "S4", "S4", "S4", "S4", "f4", "f4") self.reports[threat] = N.loadtxt( fpath, dtype={"names": names, "formats": formats}, skiprows=1, delimiter=",", usecols=range(8) ) # times = reports['time'] self.threats = threats
fig = plt.figure(figsize=(8, 6)) gs = M.gridspec.GridSpec(1, 2, width_ratios=[1, 3]) ax0 = plt.subplot(gs[0]) ax1 = plt.subplot(gs[1]) # import pdb; pdb.set_trace() cf0, cf1 = p.cold_pool_strength(t, ncdir=ncdir, outdir=outdir, nct=nct, dom=dom, swath_width=130, fig=fig, axes=(ax0, ax1), dz=1) hr = utils.ensure_timetuple(t)[3] fpath = os.path.join(outdir, 'coldpool_{0:02d}Z.png'.format(hr)) fig.savefig(fpath) print(("Saving figure to {0}".format(fpath))) plt.close(fig) if spaghetti: wrf_sds = [] for en in ensnames: for ex in experiments: out_sd, wrf_sd = get_folders(en, ex) wrf_sds.append(wrf_sd) lv = 2000 # Save to higher directory out_d = os.path.dirname(out_sd)
ensnames = ['s{0:02d}'.format(e) for e in range(21, 31)] return ensnames if paper == 1: nestlist = [ 'SINGLE', ] else: nestlist = ['SINGLE', 'NESTED'] #'HIRES'): if not SALplot_only: for nest in nestlist: ALLSPREAD[nest] = {} for dnt in times: utc = datetime.datetime(*utils.ensure_timetuple(dnt)[:6]) ALLSPREAD[nest][dnt] = {} dom, hires = nest_logic(nest) nct, casestr, W_fname = case_logic(case) casestr, ctrl_dir, ensnames = hires_logic(casestr, hires) ctrl_fpath = os.path.join(ctrl_dir, W_fname) radar_datadir = os.path.join('/chinook2/jrlawson/bowecho/', case[:8], 'VERIF') fhr_ = utc - nct # import pdb; pdb.set_trace() totalsec = fhr_.seconds + 24 * 60 * 60 * (fhr_.days) fhr = '{0:02d}'.format(totalsec / (60 * 60)) DATA = {} if plotfig:
def get_radar_url(self): dt = utils.ensure_timetuple(self.utc) return ('mesonet.agron.iastate.edu/archive/data/' '{0:04d}/{1:02d}/{2:02d}/GIS/uscomp/'.format(*dt))
ensnames = ['s{0:02d}'.format(e) for e in range(1,11)] elif nest == 'NESTED': ensnames = ['s{0:02d}'.format(e) for e in range(21,31)] return ensnames if paper == 1: nestlist = ['SINGLE',] else: nestlist = ['SINGLE','NESTED'] #'HIRES'): if not SALplot_only: for nest in nestlist: ALLSPREAD[nest] = {} for dnt in times: utc = datetime.datetime(*utils.ensure_timetuple(dnt)[:6]) ALLSPREAD[nest][dnt] = {} dom, hires = nest_logic(nest) nct, casestr, W_fname = case_logic(case) casestr, ctrl_dir, ensnames = hires_logic(casestr,hires) ctrl_fpath = os.path.join(ctrl_dir,W_fname) radar_datadir = os.path.join('/chinook2/jrlawson/bowecho/',case[:8],'VERIF') fhr_ = utc-nct # import pdb; pdb.set_trace() totalsec = fhr_.seconds + 24*60*60*(fhr_.days) fhr = '{0:02d}'.format(totalsec/(60*60)) DATA = {} if plotfig: p = WRFEnviron()
if ens: outdir = os.path.join(outroot,'hires','d0{0}'.format(dom),ens) ncdir = os.path.join(ncroot,ens) else: outdir = os.path.join(outroot,'hires','d0{0}'.format(dom)) ncdir = ncroot for t in times: fig = plt.figure(figsize=(8,6)) gs = M.gridspec.GridSpec(1,2,width_ratios=[1,3]) ax0 = plt.subplot(gs[0]) ax1 = plt.subplot(gs[1]) # import pdb; pdb.set_trace() cf0, cf1 = p.cold_pool_strength(t,ncdir=ncdir,outdir=outdir,nct=nct,dom=dom, swath_width=130,fig=fig,axes=(ax0,ax1),dz=1) hr = utils.ensure_timetuple(t)[3] fpath = os.path.join(outdir,'coldpool_{0:02d}Z.png'.format(hr)) fig.savefig(fpath) print(("Saving figure to {0}".format(fpath))) plt.close(fig) if spaghetti: wrf_sds = [] for en in ensnames: for ex in experiments: out_sd, wrf_sd = get_folders(en,ex) wrf_sds.append(wrf_sd) lv = 2000 # Save to higher directory out_d = os.path.dirname(out_sd)