Skip to content

Commit

Permalink
Get turbulence data from the noa unblended wafs file.
Browse files Browse the repository at this point in the history
  • Loading branch information
joanpc committed Mar 30, 2021
1 parent 97d9ce3 commit 9074449
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion noaweather/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Conf:
syspath, dirsep = '', os.sep
printableChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '

__VERSION__ = '2.5.0'
__VERSION__ = '2.5.2'

GFS_JSON_HELP = '''Here you can edit which wind levels will be downloaded from NOAA without hacking the code.
Keep the list short to optimize the download size and parsing times.
Expand Down
54 changes: 28 additions & 26 deletions noaweather/wafs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import subprocess
from datetime import datetime, timedelta
import re

from weathersource import GribWeatherSource

Expand All @@ -27,13 +28,11 @@ class WAFS(GribWeatherSource):
publish_delay = {'hours': 5, 'minutes': 0}
grib_conf_var = 'lastwafsgrib'

RE_PRAM = re.compile(r'\bparmcat=(?P<parmcat>[0-9]+) parm=(?P<parm>[0-9]+)')

def __init__(self, conf):
super(WAFS, self).__init__(conf)

def run(self, elapsed):
"""DISABLED: WAFS is not freely available anymore."""
pass

@classmethod
def get_cycle_date(cls):
"""Returns last cycle date available"""
Expand Down Expand Up @@ -72,31 +71,34 @@ def parse_grib_data(self, filepath, lat, lon):

if self.conf.spinfo:
kwargs.update({'startupinfo': self.conf.spinfo, 'shell': True})

p = subprocess.Popen([self.conf.wgrib2bin] + args, **kwargs)

it = iter(p.stdout)

cat = {}
for line in it:
r = line[:-1].split(':')
# Level, variable, value
level, variable, value, maxave = [r[4].split(' '), r[3], r[7].split(',')[2].split('=')[1], r[6]]
if len(level) > 1 and level[1] == 'mb' and maxave == 'spatial max':
# print level[1], variable, value
alt = int(c.mb2alt(float(level[0])))
value = float(value)
if value < 0:
value = 0
if variable == 'CTP':
value *= 100
if variable in ('CAT', 'CTP'):
if alt in cat:
# override existing value if bigger
if value > cat[alt]:
cat[alt] = value
else:
cat[alt] = value
print (line)
sline = line.split(':')
m = self.RE_PRAM.search(sline[3])

parmcat, parm = m.groups()
value = float(sline[7].split(',')[-1:][0][4:-1])

if parmcat == '19' and parm == '30':
# Eddy Dissipation Param
alt = int(c.mb2alt(float(sline[4][:-3])))
cat[alt] = value
if parmcat == '19' and parm == '37':
# Icing severity
pass
if parmcat == '6' and parm == '25':
# Horizontal Extent of Cumulonimbus (CB) %
pass
if parmcat == '3' and parm == '3':
# Cumulonimbus BASE or TOPS
# ICAO Standard Atmosphere Reference height in METERS
pass


turbulence = []
for key, value in cat.iteritems():
Expand All @@ -107,11 +109,11 @@ def parse_grib_data(self, filepath, lat, lon):

@classmethod
def get_download_url(cls, datecycle, cycle, forecast):
filename = "WAFS_blended_%sf%02d.grib2" % (datecycle, forecast)
url = "%s/gfs.%s/%s/%s" % (cls.baseurl, datecycle[:-2], datecycle[-2:], filename)
filename = "gfs.t%sz.wafs_0p25_unblended.f%02d.grib2" % (datecycle[-2:], forecast)
url = "%s/gfs.%s/%s/atmos/%s" % (cls.baseurl, datecycle[:-2], datecycle[-2:], filename)
return url

@classmethod
def get_cache_filename(cls, datecycle, cycle, forecast):
filename = "%s_wafs.WAFS_blended_%sf%02d.grib2" % (datecycle, datecycle, forecast)
filename = "%s_gfs.t%sz.wafs_0p25_unblended.f%02d.grib2" % (datecycle, datecycle[-2:], forecast)
return filename

0 comments on commit 9074449

Please sign in to comment.