Skip to content

Commit

Permalink
cleaned up external config
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophGehbauer committed May 13, 2024
1 parent 74ae3fb commit 7e2e940
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 47 deletions.
4 changes: 2 additions & 2 deletions afc/defaultConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def default_parameter(tariff_name='e19-2020', hvac_control=True,
weight_glare=0, precompute_radiance=False,
location_latitude=37.85, location_longitude=-122.24,
location_orientation=0, view_orient=0,
timezone=120, elevation=100, number_occupants=1,
timezone=120, elevation=170, number_occupants=1,
schedule=None, wpi_min=500, glare_max=0.4, instance_id=0,
debug=False):
"""Function to load the default parameters for AFC."""
Expand Down Expand Up @@ -251,7 +251,7 @@ def default_parameter(tariff_name='e19-2020', hvac_control=True,
view_orient = view_orient,
timezone = timezone,
orient = location_orientation,
elevation = elevation,
elevation = ft_to_m(elevation),
width = ft_to_m(room_width),
depth = ft_to_m(room_depth),
height = ft_to_m(room_height),
Expand Down
16 changes: 8 additions & 8 deletions afc/externalConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def config_from_dict(config):
# Update occupant wpi prefernces (80%=>250lx 100%=>350lx 120%=>450lx.)
wpi_min = 250 + max(0, (config['occupant_brightness'] - 80) * 5)

# Get timezone and elevation
lat = config['location_latitude']
lon = config['location_longitude']
timezone = int(get_timezone(lat, lon) * -1 * 15) # tz spans 15 deg of longitude
#elevation = get_elevation(lat, lon) # experiemntal; in m need to convert to ft

# Upload default_parameter with arguments from json
window_full_width = config['window_width'] * config['window_count']
parameter = default_parameter(tariff_name=config['tariff_name'],
Expand All @@ -105,14 +111,8 @@ def config_from_dict(config):
glare_max=glare_max,
instance_id=config['system_id'],
debug=config['debug'],
timezone = get_timezone(
config['location_latitude'],
config['location_longitude']
),
elevation = get_elevation(
config['location_latitude'],
config['location_longitude']
)
timezone=timezone,
elevation=config['location_elevation'],
)

# Update windows position and dimensions
Expand Down
2 changes: 1 addition & 1 deletion afc/resources/config/example_config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"system_id": "Test-AAA", "location_state": "CA", "location_city": "Berkeley", "location_orientation": 0, "room_width": 10, "room_height": 11, "room_depth": 15, "occupant_1_direction": 0, "occupant_brightness": 100, "occupant_glare": 100, "window_width": 4.5, "window_height": 8.5, "window_sill": 0.5, "window_count": 2, "system_type": "ec-71t", "system_light": "LED", "system_cooling": "el", "system_cooling_eff": 3.5, "system_heating": "el", "system_heating_eff": 0.95, "location_latitude": 37.85, "location_longitude": -122.24, "occupant_number": 1, "debug": false, "tariff_name": "e19-2020", "building_age": "new_constr", "interface_status": "Updated Configuration."}
{"system_id": "Test-AAA", "location_state": "CA", "location_city": "Berkeley", "location_orientation": 0, "room_width": 10, "room_height": 11, "room_depth": 15, "occupant_1_direction": 0, "occupant_brightness": 100, "occupant_glare": 100, "window_width": 4.5, "window_height": 8.5, "window_sill": 0.5, "window_count": 2, "system_type": "ec-71t", "system_light": "LED", "system_cooling": "el", "system_cooling_eff": 3.5, "system_heating": "el", "system_heating_eff": 0.95, "location_latitude": 37.85, "location_longitude": -122.24, "location_elevation": 170, "occupant_number": 1, "debug": false, "tariff_name": "e19-2020", "building_age": "new_constr", "interface_status": "Updated Configuration."}
30 changes: 19 additions & 11 deletions afc/utility/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@
Location handling module.
"""

from datetime import datetime
# pylint: disable=redefined-outer-name, invalid-name

import json
from timezonefinder import TimezoneFinder
from datetime import datetime
import pytz
import requests
from timezonefinder import TimezoneFinder

def get_timezone(latitude, longitude):
"""Utility function to obtain the timezine from latitude and longitude
def get_timezone(lat, lon):
"""Utility function to obtain the timezone from latitude and longitude.
"""
# We set the date to the 1st January and not now as the off set may vary along the year
# Select period during standard time
year = datetime.now().year
date_time = datetime(year, 1, 1)

# Find the timezone based on the given coordinates
tf = TimezoneFinder()
timezone_name = tf.timezone_at(lat=latitude, lng=longitude)
# Get the timezone object using pytz
timezone_name = tf.timezone_at(lat=lat, lng=lon)
# Convert to pytz
timezone = pytz.timezone(timezone_name)

# Determine the offset from UTC/GMT
# Determine the time offset from UTC/GMT
offset_seconds = timezone.utcoffset(date_time).total_seconds()
offset_hours = offset_seconds / 3600 # Convert to hours
offset_hours = offset_seconds / (60*60) # Convert to hours

return int(abs(offset_hours)*15)
return offset_hours

def get_elevation(lat, lon):
"""Utility function to obtain the elevation of a place from latitude and longitude
"""Utility function to obtain the surface elevation from latitude and longitude.
"""
# Request the elevation on open elevation
response = requests.post(
Expand All @@ -47,3 +49,9 @@ def get_elevation(lat, lon):
# Convert from json
elevation = json.loads(response.content)["results"][0]["elevation"]
return elevation

if __name__ == '__main__':
lat = 37.87
lon = -122.27
print(f'Timezone (should be -8 hours): {get_timezone(lat, lon)}')
print(f'Elevation (should be 52 meter): {get_elevation(lat, lon)}')
29 changes: 22 additions & 7 deletions dev/Development-ControllerWrapper.ipynb

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions dev/Development-JsonParser.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test1():

# check
res = ctrl.get_output(keys=['opt-stats', 'duration'])
assert 19.5 < res['opt-stats']['objective'] < 20.5
assert res['opt-stats']['duration'] < 5
assert 20.0 < res['opt-stats']['objective'] < 20.5
assert res['opt-stats']['duration'] < 1
assert res['opt-stats']['termination'] == 'optimal'
assert res['duration']['all'] < 60*5

0 comments on commit 7e2e940

Please sign in to comment.