I'm getting hourly UV index from the ftp site of NOAA. As mentioned here, the forecast time is present in the file name as uv.t12z.grbfXX, where XX is the forecast hour (01 to 120)
. But inside the grib2 files, the key hour
always indicate that the hour is 12. Also the date doesn't changes at all in any of the file. As of today it is 2016/06/04
in all of the 120 files. I couldn't find the timezone in the key of the file as well.
So, I wanted to know, if I want to find the UV Index of Delhi(28.6139, 77.2090) timezone: Asia/Kolkata
on 2016/06/05
at 2 pm
, how can I calculate this from those files ? Is it the UV index in the uv.t12z.grbf38
file assuming 01
in the files is 00:00 hrs on 2016/06/04
. I couldn't find anything in documentation regarding this.
Here's the code snippet for finding the hour:
import pygrib
grbs = pygrib.open('uv.t12z.grbf01.grib2')
grb = grbs.select(name='UV index')[0]
year = grb.year
month = grb.month
day = grb.day
hour = grb.hour
minute = grb.minute
print year,month,day,hour,minute
Output:
>>2016 6 4 12 0
Values hour, day, month, year
in GRIB file only indicate start time of a weather forecast (it is initial time from which forecast is produced).
Date and time in this file is according to UTC.
To get forecast date and time in UTC you need to add to initial time a value XX
.
Then to get your local time add to this value your time shift.
I.e., I need to convert uv.t12z.grbf38, from which hour, day, month, year = 12,1,1,2016
to Moscow time. First, I add to start time 38 hours and get 2,3,1,2016
(this time according to UTC). Moscow has time shift +3 UTC, it means, local time is 5:00 3 January, 2016.
You may convert date and time vise-versa as I wrote above.