Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Update requirements.txt

Fixes
  • Loading branch information
kastnerp committed Feb 16, 2024
1 parent 364499d commit 235087f
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 209 deletions.
70 changes: 0 additions & 70 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ __pycache__/
*.bak
.vscode/settings.json
run_act_test.bat
.DS_Store
*.py~
16 changes: 8 additions & 8 deletions nrel_psm3_2_epw/assets.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import json
import calendar
import sys
from datetime import datetime

import numpy as np
import pandas as pd
import requests

from . import epw
from datetime import datetime
import calendar


def download_epw(lon, lat, year, location, attributes, interval, utc, your_name, api_key, reason_for_use,
your_affiliation, your_email, mailing_list, leap_year):
currentYear = datetime.now().year
if int(year) == currentYear or int(year) == currentYear-1:
if int(year) == currentYear or int(year) == currentYear - 1:
raise Exception("NREL does not provide data for the current year " + str(
year) + ". It is also unlikely that there is data availability for " + str(int(year) - 1) + ".")

Expand Down Expand Up @@ -42,8 +42,8 @@ def download_epw(lon, lat, year, location, attributes, interval, utc, your_name,

try:
r = requests.request("GET", url, params=
payload, headers=headers, timeout=20)
payload, headers=headers, timeout=20)

print(r.text)
r.raise_for_status()

Expand All @@ -66,7 +66,7 @@ def download_epw(lon, lat, year, location, attributes, interval, utc, your_name,

hours_per_year = 8760

if calendar.isleap(int(year)) and bool(leap_year) is True and all_data.shape[0] == 8784+2:
if calendar.isleap(int(year)) and bool(leap_year) is True and all_data.shape[0] == 8784 + 2:
hours_per_year = 8784

datetimes = pd.date_range('01/01/' + str(year),
Expand Down Expand Up @@ -310,7 +310,7 @@ def download_epw(lon, lat, year, location, attributes, interval, utc, your_name,

d = "_"
file_name = str(location) + d + str(lat) + d + \
str(lon) + d + str(year) + '.epw'
str(lon) + d + str(year) + '.epw'

out.write(file_name)
print("Success: File", file_name, "written")
Expand Down
147 changes: 72 additions & 75 deletions nrel_psm3_2_epw/epw.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# -*- coding: utf-8 -*-
import pandas as pd
import csv

import pandas as pd


class EPW():
"""A class which represents an EnergyPlus weather (epw) file
"""

def __init__(self):
"""
"""
self.headers={}
self.dataframe=pd.DataFrame()


def read(self,fp):
self.headers = {}
self.dataframe = pd.DataFrame()

def read(self, fp):
"""Reads an epw file
Arguments:
- fp (str): the file path of the epw file
"""

self.headers=self._read_headers(fp)
self.dataframe=self._read_data(fp)


def _read_headers(self,fp):

self.headers = self._read_headers(fp)
self.dataframe = self._read_data(fp)

def _read_headers(self, fp):
"""Reads the headers of an epw file
Arguments:
Expand All @@ -35,19 +35,18 @@ def _read_headers(self,fp):
- d (dict): a dictionary containing the header rows
"""
d={}

d = {}
with open(fp, newline='') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in csvreader:
if row[0].isdigit():
break
else:
d[row[0]]=row[1:]
d[row[0]] = row[1:]
return d


def _read_data(self,fp):

def _read_data(self, fp):
"""Reads the climate data of an epw file
Arguments:
Expand All @@ -57,52 +56,51 @@ def _read_data(self,fp):
- df (pd.DataFrame): a DataFrame comtaining the climate data
"""
names=['Year',
'Month',
'Day',
'Hour',
'Minute',
'Data Source and Uncertainty Flags',
'Dry Bulb Temperature',
'Dew Point Temperature',
'Relative Humidity',
'Atmospheric Station Pressure',
'Extraterrestrial Horizontal Radiation',
'Extraterrestrial Direct Normal Radiation',
'Horizontal Infrared Radiation Intensity',
'Global Horizontal Radiation',
'Direct Normal Radiation',
'Diffuse Horizontal Radiation',
'Global Horizontal Illuminance',
'Direct Normal Illuminance',
'Diffuse Horizontal Illuminance',
'Zenith Luminance',
'Wind Direction',
'Wind Speed',
'Total Sky Cover',
'Opaque Sky Cover (used if Horizontal IR Intensity missing)',
'Visibility',
'Ceiling Height',
'Present Weather Observation',
'Present Weather Codes',
'Precipitable Water',
'Aerosol Optical Depth',
'Snow Depth',
'Days Since Last Snowfall',
'Albedo',
'Liquid Precipitation Depth',
'Liquid Precipitation Quantity']
first_row=self._first_row_with_climate_data(fp)
df=pd.read_csv(fp,
skiprows=first_row,
header=None,
names=names)

names = ['Year',
'Month',
'Day',
'Hour',
'Minute',
'Data Source and Uncertainty Flags',
'Dry Bulb Temperature',
'Dew Point Temperature',
'Relative Humidity',
'Atmospheric Station Pressure',
'Extraterrestrial Horizontal Radiation',
'Extraterrestrial Direct Normal Radiation',
'Horizontal Infrared Radiation Intensity',
'Global Horizontal Radiation',
'Direct Normal Radiation',
'Diffuse Horizontal Radiation',
'Global Horizontal Illuminance',
'Direct Normal Illuminance',
'Diffuse Horizontal Illuminance',
'Zenith Luminance',
'Wind Direction',
'Wind Speed',
'Total Sky Cover',
'Opaque Sky Cover (used if Horizontal IR Intensity missing)',
'Visibility',
'Ceiling Height',
'Present Weather Observation',
'Present Weather Codes',
'Precipitable Water',
'Aerosol Optical Depth',
'Snow Depth',
'Days Since Last Snowfall',
'Albedo',
'Liquid Precipitation Depth',
'Liquid Precipitation Quantity']

first_row = self._first_row_with_climate_data(fp)
df = pd.read_csv(fp,
skiprows=first_row,
header=None,
names=names)
return df


def _first_row_with_climate_data(self,fp):

def _first_row_with_climate_data(self, fp):
"""Finds the first row with the climate data of an epw file
Arguments:
Expand All @@ -112,27 +110,26 @@ def _first_row_with_climate_data(self,fp):
- i (int): the row number
"""

with open(fp, newline='') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for i,row in enumerate(csvreader):
for i, row in enumerate(csvreader):
if row[0].isdigit():
break
return i


def write(self,fp):

def write(self, fp):
"""Writes an epw file
Arguments:
- fp (str): the file path of the new epw file
"""

with open(fp, 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
for k,v in self.headers.items():
csvwriter.writerow([k]+v)
for row in self.dataframe.itertuples(index= False):
csvwriter.writerow(i for i in row)
quotechar='"', quoting=csv.QUOTE_MINIMAL)
for k, v in self.headers.items():
csvwriter.writerow([k] + v)
for row in self.dataframe.itertuples(index=False):
csvwriter.writerow(i for i in row)
52 changes: 4 additions & 48 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,4 @@
altair==5.2.0
attrs==23.2.0
blinker==1.7.0
cachetools==5.3.2
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.0.0
colorama==0.4.6
DateTime==5.4
gitdb==4.0.11
GitPython==3.1.42
idna==3.6
importlib-metadata==7.0.1
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
numpy==1.26.4
packaging==23.2
pandas==2.2.0
pillow==10.2.0
protobuf==4.25.3
pyarrow==15.0.0
pydeck==0.8.1b0
Pygments==2.17.2
python-dateutil==2.8.2
pytz==2024.1
referencing==0.33.0
requests==2.31.0
rich==13.7.0
rpds-py==0.18.0
six==1.16.0
smmap==5.0.1
streamlit==1.31.1
tenacity==8.2.3
toml==0.10.2
toolz==0.12.1
tornado==6.4
typing_extensions==4.9.0
tzdata==2024.1
tzlocal==5.2
urllib3==2.2.0
validators==0.22.0
watchdog==4.0.0
zipp==3.17.0
zope.interface==6.2
click==8
numpy
pandas
requests
Loading

0 comments on commit 235087f

Please sign in to comment.