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

Add handling for submission of subannual/hourly timeseries data #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions definitions/subannual/year.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Default entry for the subannual column

- Year:
duration: 1
38 changes: 35 additions & 3 deletions workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,39 @@
def main(df: pyam.IamDataFrame) -> pyam.IamDataFrame:
"""Project/instance-specific workflow for scenario processing"""

# Run the validation and region-processing
dsd = DataStructureDefinition(here / "definitions")
dimensions = ["region", "variable"]
if "subannual" in df.dimensions or df.time_col == "time":
dimensions = dimensions + ["subannual"]

# initialize the codelists and region-processing
dsd = DataStructureDefinition(here / "definitions", dimensions=dimensions)
processor = RegionProcessor.from_directory(path=here / "mappings", dsd=dsd)
return process(df, dsd, processor=processor)

# run the validation and region-processing
df = process(df, dsd, processor=processor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the validation fail here for anything that's not year in the subannual column?


# convert to subannual format if data provided in datetime format
if df.time_col == "time":
logger.info('Re-casting from "time" column to categorical "subannual" format')
df = df.swap_time_for_year(subannual=OE_SUBANNUAL_FORMAT)

# check that any datetime-like items in "subannual" are valid datetime and UTC+01:00
if "subannual" in df.dimensions:
_datetime = [s for s in df.subannual if s not in dsd.subannual]

for d in _datetime:
try:
_dt = datetime.strptime(f"2020-{d}", "%Y-%m-%d %H:%M%z")
except ValueError:
try:
datetime.strptime(f"2020-{d}", "%Y-%m-%d %H:%M")
except ValueError:
raise ValueError(f"Invalid subannual timeslice: {d}")

raise ValueError(f"Missing timezone: {d}")

# casting to datetime with timezone was successful
if not (_dt.tzname() == EXP_TZ or _dt.utcoffset() == EXP_TIME_OFFSET):
raise ValueError(f"Invalid timezone: {d}")

return df
Loading