Skip to content

Commit

Permalink
Plexos: Fix date_from date_to Filtering (#36)
Browse files Browse the repository at this point in the history
There was an edge case where the date_from / date_to filter used a date
in the middle of a study year. I resolved this filtering by filtering
the property by the year listed in date_from date_to instead.

I also added a note and ticket for future work to ensure partial year
properties are added to `max_active_power`
  • Loading branch information
ktehranchi committed Sep 26, 2024
1 parent fb21275 commit 36dc981
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/r2x/parser/parser_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ def pl_filter_year(df, year: int | None = None, year_columns=["t", "year"], **kw

def filter_property_dates(system_data: pl.DataFrame, study_year: int):
"""filters query by date_from and date_to"""
# note this only filters by first day of year, at some point revisit this to include partial years
# Remove Property by study year & date_from/to
study_year_date = datetime(study_year, 1, 1)
date_filter = ((pl.col("date_from").is_null()) | (pl.col("date_from") <= study_year_date)) & (
(pl.col("date_to").is_null()) | (pl.col("date_to") >= study_year_date)
)

# Convert date_from and date_to to datetime
system_data = system_data.with_columns(
[
Expand All @@ -40,6 +33,18 @@ def filter_property_dates(system_data: pl.DataFrame, study_year: int):
]
)

# Create two new columns year_from and year_to
system_data = system_data.with_columns(
[
pl.col("date_from").dt.year().alias("year_from"),
pl.col("date_to").dt.year().alias("year_to"),
]
)

# Remove Property by study year & date_from/to
date_filter = ((pl.col("date_from").is_null()) | (pl.col("year_from") <= study_year)) & (
(pl.col("date_to").is_null()) | (pl.col("year_to") >= study_year)
)
system_data = system_data.filter(date_filter)
return system_data

Expand Down
3 changes: 3 additions & 0 deletions src/r2x/parser/plexos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,9 @@ def _set_unit_availability(self, mapped_records):
Set availability and active power limit TS for generators.
Note: variables use infrasys naming scheme, rating != plexos rating.
"""
# TODO @ktehranchi: #35 Include date_from and date_to in the availability
# https://github.com/NREL/R2X/issues/35

availability = mapped_records.get("available", None)
if availability is not None and availability > 0:
# Set availability, rating, storage_capacity as multiplier of availability/'units'
Expand Down

0 comments on commit 36dc981

Please sign in to comment.