Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Fix NOAA hourly forecast #1051

Merged
merged 6 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ geodata.conf
gldcore/autotest/output.csv
python_extras/example/output.csv
*.egg
gridlabd.egg-info/
gridlabd.egg-*
16 changes: 10 additions & 6 deletions python_extras/noaa_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@

The following command downloads only the CSV data for a location:

bash$ gridlabd python -m noaa_forecast -p=45.62,-122.70 -c=test.csv
bash$ gridlabd noaa_forecast -p=45.62,-122.70 -c=test.csv

The following command downloads the CSV data and creates a GLM file with the data linked and weather object named:

bash$ gridlabd python -m noaa_forecast -p=45.62,-122.70 -c=test.csv -n=test -g=test.glm
bash$ gridlabd noaa_forecast -p=45.62,-122.70 -c=test.csv -n=test -g=test.glm

SEE ALSO

Expand All @@ -115,7 +115,7 @@ def getforecast(lat,lon):
headers = {'User-agent' : user_agent}
location = json.loads(requests.get(url,headers=headers).content.decode("utf-8"))

data = json.loads(requests.get(location["properties"]["forecast"],headers=headers).content.decode("utf-8"))
data = json.loads(requests.get(location["properties"]["forecastHourly"],headers=headers).content.decode("utf-8"))
result = {
"datetime" : [],
"temperature[degF]" : [],
Expand Down Expand Up @@ -146,10 +146,10 @@ def getforecast(lat,lon):
df.index.name = "datetime"
return df

def writeglm(data, glm=sys.stdout, name=None, csv="/dev/stdout",download_now=True):
def writeglm(data, glm=sys.stdout, name=None, csv=None,download_now=True):
"""Write weather object based on NOAA forecast"""
if glm:
if csv == 'auto':
if csv == 'auto' or csv == None:
if type(glm) is str:
csv = glm.replace(".glm",".csv")
else:
Expand All @@ -172,7 +172,11 @@ def writeglm(data, glm=sys.stdout, name=None, csv="/dev/stdout",download_now=Tru
glm.write("}\n")
if download_now:
data.to_csv(csv,header=False,float_format=float_format,date_format=date_format)
elif csv:
else:
if csv == None:
csv = "/dev/stdout"
elif csv == 'auto':
raise Exception("csv cannot be automatically named if GLM is not specified")
data.to_csv(csv,header=True,float_format=float_format,date_format=date_format)

if __name__ == "__main__":
Expand Down