Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plexos: Fix date_from date_to Filtering #36

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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