I am new to coding but I think I have a simple problem with a fairly simple solution I am trying to group my spatial data to just one variable. Basically here I have temperature data being loaded in from NOAA. I want to give all temperatures below 32 a value of k=1 but where values are higher then 32 k=2. I am doing this with multiple data sets (wind, visibility, freezing rain, etc.) and I want to assign ranges to letters of k then add them up at the end to plot them. So at the end I have kind of an index map (like areas with high visibility and freezing rain are possible to have flight delays (k=3) but areas of low visibility and freezing rain are likely flight delays (k=5).
I have worked with this raw temperature data in the past and I used code to plot it: cs = ax.contourf(lon, lat, t2m, levels=[-30,30,32,36,40])
Now I am just trying to give certain ranges values of k then use k for other variables and area where k is the greatest are plotted where "travel delays likely"
Here is my code and a sad attempt of an if statement:
###########Time Stamps
run_dt = datetime.utcnow()-timedelta(hours=1) # previous hour
fhr = '00'
run = run_dt.strftime('%H')
ymd = run_dt.strftime('%Y%m%d')
##########Wind Data Import
# Data download
url = 'https://nomads.ncep.noaa.gov/cgi-bin/filter_rap.pl?file=rap.t{run}z.awp252pgrbf{fhr}.grib2\
&lev_surface=on&var_GUST=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Frap.{ymd}'
URL = url.format(run=run, fhr=fhr, ymd=ymd)
r = requests.get(URL)
with open('/home/jupyter-kfa5169/FDI/wind.grib15', 'wb') as fh:
fh.write(r.content)
wind_data = xr.open_dataset('/home/jupyter-kfa5169/FDI/wind.grib15', engine='cfgrib')
lon, lat = wind_data.longitude.values-360., wind_data.latitude.values
gust = mpcalc.smooth_gaussian((wind_data.variables['gust'].values*units('m/s')).to('mph').magnitude, 4)
##########################Testing#############################
k = 4
if gust > 20:
k = 5
if gust < 20:
k= 2
Aucun commentaire:
Enregistrer un commentaire