Skip to content

Commit a505d5d

Browse files
authored
feat: Specify the point source directory using an environment variable (#31)
The `SPAEMIS_POINT_SOURCE_DIRECTORY` is used
1 parent 4713492 commit a505d5d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

data/raw/configuration/scenarios/ssp245-high-production_victoria.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ scalers:
3030
allow_missing: true
3131
method:
3232
name: point_source
33-
point_sources: point_sources/hysupply_locations.csv
33+
point_sources: hysupply_locations.csv
3434
source_timeseries: high_production
3535
source_filters:
3636
- product: H2
@@ -39,7 +39,7 @@ scalers:
3939
allow_missing: true
4040
method:
4141
name: point_source
42-
point_sources: point_sources/hysupply_locations.csv
42+
point_sources: hysupply_locations.csv
4343
source_timeseries: high_production
4444
source_filters:
4545
- product: NOx

src/spaemis/scaling/point_source.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,22 @@ def __call__(
114114
def create_from_config(cls, method: ScalerMethod) -> "PointSourceScaler":
115115
"""
116116
Create a scaler from configuration
117+
118+
Point source information will be loaded from a directory specified by the
119+
environment variable `SPAEMIS_POINT_SOURCE_DIRECTORY`. This defaults to
120+
`data/raw/configuration/point_sources` if no environment variable
121+
is specified.
117122
"""
118123
if not isinstance(method, PointSourceMethod):
119124
raise TypeError("Incompatible configuration")
120125

126+
point_source_directory = os.environ.get(
127+
"SPAEMIS_POINT_SOURCE_DIRECTORY",
128+
os.path.join(RAW_DATA_DIR, "configuration", "point_sources"),
129+
)
130+
121131
point_info = pd.read_csv(
122-
os.path.join(RAW_DATA_DIR, "configuration", method.point_sources)
132+
os.path.join(point_source_directory, method.point_sources)
123133
)
124134
points = [
125135
Point(lat=item["lat"], lon=item["lon"])

tests/unit/scaling/test_scaling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_run(self, inventory, caplog):
275275

276276
scaler = PointSourceScaler.create_from_config(
277277
PointSourceMethod(
278-
point_sources="point_sources/hysupply_locations.csv",
278+
point_sources="hysupply_locations.csv",
279279
source_timeseries="high_production",
280280
source_filters=[{"product": "H2"}],
281281
)

0 commit comments

Comments
 (0)