Skip to content

Commit 5504fac

Browse files
committed
Only the historic 1990 baseline keeps its year in the key; present year is implicit
1 parent 7e202b8 commit 5504fac

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

lib/atlas/dataset.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,18 @@ def central_producers
355355
# Expects to load a file at datasets/AREA/emissions.csv with 5 index columns:
356356
# etm_sector, etm_subsector, use, ghg, year.
357357
#
358+
# Only the historic 1990 baseline keeps its year in the key; present year is implicit
359+
#
358360
# For example:
359361
# dataset.emissions.
360-
# get(:buildings, :non_specified, :energetic, :other_ghg, 2023, :value)
362+
# get(:buildings, :non_specified, :energetic, :other_ghg, :value)
361363
# # => 2796620.0
362364
#
363365
# Returns a CSVDocument.
364366
def emissions
365-
@emissions ||= CSVDocument::MultiIndex.read(
366-
path_resolver.resolve('emissions.csv'), index_size: 5
367-
)
367+
@emissions ||= CSVDocument::MultiIndex
368+
.read(path_resolver.resolve('emissions.csv'), index_size: 5)
369+
.tap { |doc| doc.table.each { |row| row[:year] = nil unless row[:year] == 1990 } }
368370
end
369371

370372
# Public: Retrieves demand and max demand data for the region. Expects to

lib/atlas/runtime.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,17 @@ def EFFICIENCY(file_key, direction, carrier)
145145
# EMISSIONS(energy_hydrogen_production, non_energetic, other_ghg)
146146
# # => 456.0
147147
#
148-
# EMISSIONS(energy_hydrogen_production, non_energetic, other_ghg, 2015)
148+
# EMISSIONS(energy_hydrogen_production, non_energetic, other_ghg, 1990)
149149
# # => 456.0
150150
#
151+
# The present year is implicit; only the 1990 baseline is suffixed with a
152+
# year in the key.
153+
#
151154
# Returns a Float or nil if not found.
152-
def EMISSIONS(sector, use, ghg, year = dataset.analysis_year)
153-
full_key = "#{sector}_#{use}_#{ghg}_#{year}".to_sym
154-
155-
dataset.emissions.to_hash[full_key]
155+
def EMISSIONS(sector, use, ghg, year = nil)
156+
dataset.emissions.to_hash[
157+
[sector, use, ghg, (1990 if year.to_i == 1990)].compact.join('_').to_sym
158+
]
156159
end
157160

158161
# Public: Given the key of a node, retrieves the production (energy

0 commit comments

Comments
 (0)