Skip to content

Commit b7a6d86

Browse files
Output total carbon emissions in kilotons for example_SHR-2
1 parent e3d3da1 commit b7a6d86

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

src/geophires_x/Outputs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,8 @@ def PrintOutputs(self, model: Model):
864864

865865
if model.economics.DoCarbonCalculations.value:
866866
summary.append(OutputTableItem('Total Avoided Carbon Emissions', '{0:10.2f}'.format(
867-
model.economics.CarbonThatWouldHaveBeenProducedTotal.quantity().to('tonne').magnitude), 'tonne'))
867+
model.economics.CarbonThatWouldHaveBeenProducedTotal.value),
868+
model.economics.CarbonThatWouldHaveBeenProducedTotal.CurrentUnits.value))
868869

869870
if model.economics.econmodel.value == EconomicModel.FCR:
870871
economic_parameters.append(OutputTableItem('Economic Model', model.economics.econmodel.value.value))
@@ -1605,7 +1606,8 @@ def PrintOutputs(self, model: Model):
16051606
f.write(f' Segment {str(i):s} Thickness: {model.reserv.layerthickness.value[i-1]:10.0f} ' + model.reserv.layerthickness.CurrentUnits.value + NL)
16061607
f.write(f' Segment {str(i+1):s} Geothermal gradient: {model.reserv.gradient.value[i]:10.4g} ' + model.reserv.gradient.CurrentUnits.value + NL)
16071608
if model.economics.DoCarbonCalculations.value:
1608-
f.write(f' Total Avoided Carbon Emissions: {model.economics.CarbonThatWouldHaveBeenProducedTotal.quantity().to("tonne").magnitude:10.2f} tonne' + NL)
1609+
f.write(f' Total Avoided Carbon Emissions: {model.economics.CarbonThatWouldHaveBeenProducedTotal.value:10.2f} '
1610+
f'{model.economics.CarbonThatWouldHaveBeenProducedTotal.CurrentUnits.value}\n')
16091611

16101612
f.write(NL)
16111613
f.write(NL)

src/geophires_x/Parameter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,16 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):
840840
:type model: :class:`~geophires_x.Model.Model`
841841
:return: None
842842
"""
843+
844+
try:
845+
oparam.value = _ureg.Quantity(oparam.value, oparam.CurrentUnits.value).to(newUnit.value).magnitude
846+
oparam.CurrentUnits = newUnit
847+
return
848+
except AttributeError as ae:
849+
# TODO refactor to check for/convert currency instead of relying on try/except once currency conversion is
850+
# re-enabled - https://github.com/NREL/GEOPHIRES-X/issues/236?title=Currency+conversions+disabled
851+
model.logger.warning(f'Failed to convert units with pint, falling back to legacy conversion code ({ae})')
852+
843853
if isinstance(oparam.value, str):
844854
return # strings have no units
845855
elif isinstance(oparam.value, bool):

src/geophires_x/Units.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class MassUnit(str, Enum):
313313
KILOGRAM = "kilogram"
314314
TONNE = "tonne"
315315
TON = "ton"
316+
KILOTON = "kiloton"
316317
LB = "pound"
317318
OZ = "ounce"
318319

tests/examples/example_SHR-2.out

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
Simulation Metadata
66
----------------------
7-
GEOPHIRES Version: 3.4.34
8-
Simulation Date: 2024-06-19
9-
Simulation Time: 07:44
10-
Calculation Time: 0.593 sec
7+
GEOPHIRES Version: 3.4.41
8+
Simulation Date: 2024-06-27
9+
Simulation Time: 12:21
10+
Calculation Time: 0.602 sec
1111

1212
***SUMMARY OF RESULTS***
1313

@@ -19,6 +19,7 @@ Simulation Metadata
1919
Flowrate per production well: 55.0 kg/sec
2020
Well depth (or total length, if not vertical): 7.5 kilometer
2121
Geothermal gradient: 50 degC/km
22+
Total Avoided Carbon Emissions: 3403.38 kiloton
2223

2324

2425
***ECONOMIC PARAMETERS***

tests/examples/example_SHR-2.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ Electricity Escalation Rate Per Year, 0.012
4545
Annual License Etc, 0
4646
Flat License Etc, 0
4747
Tax Relief Per Year, 2.212
48+
Do Carbon Price Calculations, true
49+
Units:Total Saved Carbon Production, kiloton,

0 commit comments

Comments
 (0)