getgfs
getgfs copied to clipboard
Request all data from next day for once
I'm trying to retrieve the next day forecast. There is any way of getting all values for once or only requesting hour per hour?
It would appear I made it only do one time at a time. Because of the format of the API it would be non-trivial to request a range of times as one request, but you could easily iterate through a set of times and turn it into an array. If you do this it would be great if you could add a wrapper for it to this library!
I create a loop to request this values to the next day but after some interaction i'm retriving the same values. ` horarios =['00:00','01:00','02:00','03:00', '04:00','05:00','06:00','07:00', '08:00','09:00','10:00','11:00', '12:00','13:00','14:00','15:00', '16:00','17:00','18:00','19:00', '20:00','21:00','22:00','23:00']
#Dia de interesse
t1 = date.today()
t2 = date.today()+timedelta(days=1)
t3 = date.today()+timedelta(days=2)
t4 = date.today()+timedelta(days=3)
t5 = date.today()+timedelta(days=4)
t1 = t1.strftime("%Y%m%d")
t2 = t2.strftime("%Y%m%d")
t3 = t3.strftime("%Y%m%d")
t4 = t4.strftime("%Y%m%d")
t5 = t5.strftime("%Y%m%d")
#Coordenadas grid 0.25 AS1
lat=['-5.25','-5.25']
long=['-35.00','-35.75']
parque=['REN1','VSM']
f=getgfs.Forecast("0p25",'1hr')
list_parques=['REN1','REN2','REN3','REN4','VSM']
df = pd.DataFrame(columns=list_parques)
datas = [t1,t2,t3,t4,t5]
for p in range(len(parque)):
lista_aux=[]
for d in range(len(datas)):
dia=[datas[d]]*len(horarios)
for j in range(len(horarios)):
res=f.get(["gustsfc"],dia[j] +' '+ horarios[j], lat[p],long[p])
print("gustsfc" + dia[j] +' '+ horarios[j] + lat[p] + long[p])
lista_aux.append(res.variables["gustsfc"].data)
lista_aux = np.array(lista_aux).flatten()
df[parque[p]] = lista_aux
`
The same. Getting repeated data for forecasted dates.
Is it possible that current date is hardcoded somewhere?
import getgfs
import numpy as np
from datetime import datetime, timedelta
# Getting the current date and time
dt = datetime.now()
print("Date and time is:", dt)
today = dt.strftime("%Y%m%d")
#Create the list of 3 dates from now
dates = []
for i in range(3):
newdate = datetime.today() + timedelta(days=i)
dates.append(newdate.strftime("%Y%m%d"))
f = getgfs.Forecast("0p25")
f.search("precipitation")
# ROIs search
xy = [["Gilgit", '[35.0:36.0]', '[74.0:75.0]']]
for i in range(len(xy)):
print("++++++++++++")
print(xy[i][0])
print("++++++++++++")
for d in dates:
for t in [12]:
timestamp = d+" "+str(t)+":00"
res = f.get(["apcpsfc"],timestamp, xy[i][1], xy[i][2])
val = res.variables["apcpsfc"].data
for y in range(len(val[0])):
for x in range(len(val[0][y])):
if (val[0][y][x] > 9999):
val[0][y][x] = np.nan
print(timestamp)
print(val[0])
The result is repeating even if the query is for a different day
Date and time is: 2023-03-22 06:56:49.299838
20230322
++++++++++++
Gilgit
++++++++++++
20230322 12:00
[[1.5625 1.9375 1.75 1.5625 0.375 ]
[0.6875 0.3125 2.3125 3.6875 0.8125]
[0.25 0.1875 0.25 0.5 0.625 ]
[2. 0.9375 0.1875 0. 0.1875]
[0.8125 0.0625 0.1875 0.5 0.75 ]]
20230323 12:00
[[1.5625 1.9375 1.75 1.5625 0.375 ]
[0.6875 0.3125 2.3125 3.6875 0.8125]
[0.25 0.1875 0.25 0.5 0.625 ]
[2. 0.9375 0.1875 0. 0.1875]
[0.8125 0.0625 0.1875 0.5 0.75 ]]
20230324 12:00
[[1.5625 1.9375 1.75 1.5625 0.375 ]
[0.6875 0.3125 2.3125 3.6875 0.8125]
[0.25 0.1875 0.25 0.5 0.625 ]
[2. 0.9375 0.1875 0. 0.1875]
[0.8125 0.0625 0.1875 0.5 0.75 ]]
Is it possible that only the current day is hardcoded in the lib?