Skip to content

Commit

Permalink
Merge pull request #97 from quintel/consumer-flh
Browse files Browse the repository at this point in the history
Update full load hours for mobility demand assets based on the ETM values
  • Loading branch information
redekok authored Apr 6, 2023
2 parents 254e5d6 + a2da669 commit 84e7f94
Show file tree
Hide file tree
Showing 8 changed files with 525 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ flask-restx = "*"
# pyecore = "~=0.12.2-dev"
# pyecoregen = "*"
# lxml = "*"
pyESDL = "*"
more-itertools = "*"
requests = "*"
Flask = "*"
Flask-Caching = "*"
'sentry-sdk[flask]' = "*"
markupsafe = "==2.0.1"
pyyaml = "*"
pyesdl = "*"

[dev-packages]
pytest = "*"
Expand Down
16 changes: 8 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 35 additions & 18 deletions app/models/parsers/demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MobilityDemandParser(CapacityParser):
def __init__(self, energy_system, props, *args, **kwargs):
super().__init__(energy_system, props, *args, **kwargs)


def set_asset_generator(self):
"""
Set the generator to assets with vehicle type and carrier.
Expand All @@ -37,30 +38,28 @@ def set_asset_generator(self):
f'We currently do not support the asset {str(att).split()[-1]}'
) from att

def update(self, scenario_id):
"""
Find the demand asset and update the value of the (input) capacity
with the ETM value

Sets self.power
def update(self, scenario_id):
"""
Find the demand asset and update the value of the (input) capacity and
the full load hours with the ETM value.
self.__update_power(scenario_id)

def __update_power(self, scenario_id):
"""
For the first instance in the list of assets of this type of demand, update
the number of full load hours to the ETM value.
the power to the ETM value and (for now, statically) set the number of
full load hours.
A warning is provided if there are more instances of this asset.
Sets self.power and self.fullLoadHours
"""
asset = self.__next_asset()

# TODO: Do we still want to do this when there is no asset?
self.power = self.query_scenario(scenario_id)

if asset:
asset.power = self.power
self.power = self.query_scenario(scenario_id, self.props['attr_set']['power'])
self.full_load_hours = self.query_scenario(scenario_id, self.props['attr_set']['fullLoadHours'])

self.__update_power(asset)
self.__update_flh(asset)

# TODO: provide warning if there's more than 1 asset in the asset_generator
# How do we want to communicate this to the user? An extra part of the API
Expand All @@ -69,13 +68,31 @@ def __update_power(self, scenario_id):
# if self.__next_asset():
# print('A warning')


def __update_power(self, asset):
"""
Sets the power of the asset to the ETM value (self.power)
"""
asset.power = self.power


def __update_flh(self, asset):
"""
Sets the full load hours of the asset to the ETM value
(self.full_load_hours)
"""
# ESDL expects the FLH to be an integer value
asset.fullLoadHours = int(self.full_load_hours)


def __next_asset(self):
try:
return next(self.asset_generator)
except StopIteration:
return

def query_scenario(self, scenario_id):

def query_scenario(self, scenario_id, prop):
"""
Query the ETM scenario for the value to set the given prop to
Expand All @@ -84,11 +101,11 @@ def query_scenario(self, scenario_id):
prop (str): e.g. 'fullLoadHours'
"""

query_result = QueryScenario.execute(scenario_id, self.props['gquery'])
query_result = QueryScenario.execute(scenario_id, prop['gquery'])

if query_result.successful:
return query_result.value[self.props['gquery']]['future'] / self.props['factor']
return query_result.value[prop['gquery']]['future'] / prop['factor']

raise ETMParseError(
f"We currently do not support the ETM gquery listed in the config: {self.props['gquery']}"
f"We currently do not support the ETM gquery listed in the config: {prop['gquery']}"
)
39 changes: 27 additions & 12 deletions config/conversions/assets/demand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,38 @@
parser: mobility_demand # or volume?
fuel: HYDROGEN
vehicle: EOrderedSet([CAR=1])
attribute: power
input: # cannot be set in the ETM
gquery: capacity_of_transport_car_using_hydrogen # hydrogen_cars_in_use_of_final_demand_in_cars
factor: 1.e-6 # gquery returns value in MW
attr_set:
power:
input: # cannot be set in the ETM
gquery: capacity_of_transport_car_using_hydrogen # hydrogen_cars_in_use_of_final_demand_in_cars
factor: 1.e-6 # gquery returns value in MW
fullLoadHours:
input: # the flh are derived from a scenario and cannot be set
gquery: flh_of_transport_car_using_hydrogen
factor: 1
- asset: MobilityDemand
parser: mobility_demand # or volume?
fuel: HYDROGEN
vehicle: EOrderedSet([TRUCK=2])
attribute: power
input: # cannot be set in the ETM
gquery: capacity_of_transport_truck_using_hydrogen # hydrogen_trucks_in_use_of_final_demand_in_freight_transport_technologies
factor: 1.e-6 # gquery returns value in MW
attr_set:
power:
input: # cannot be set in the ETM
gquery: capacity_of_transport_truck_using_hydrogen # hydrogen_trucks_in_use_of_final_demand_in_freight_transport_technologies
factor: 1.e-6 # gquery returns value in MW
fullLoadHours:
input: # the flh are derived from a scenario and cannot be set
gquery: flh_of_transport_truck_using_hydrogen
factor: 1
- asset: MobilityDemand
parser: mobility_demand # or volume?
fuel: HYDROGEN
vehicle: EOrderedSet([VAN=3])
attribute: power
input: # cannot be set in the ETM
gquery: capacity_of_transport_van_using_hydrogen # hydrogen_vans_in_use_of_final_demand_in_freight_transport_technologies
factor: 1.e-6 # gquery returns value in MW
attr_set:
power:
input: # cannot be set in the ETM
gquery: capacity_of_transport_van_using_hydrogen # hydrogen_vans_in_use_of_final_demand_in_freight_transport_technologies
factor: 1.e-6 # gquery returns value in MW
fullLoadHours:
input: # the flh are derived from a scenario and cannot be set
gquery: flh_of_transport_van_using_hydrogen
factor: 1
Loading

0 comments on commit 84e7f94

Please sign in to comment.