PyPSA / pypsa-usa

PyPSA-USA: An Open-Source Energy System Optimization Model for the United States
https://pypsa-usa.readthedocs.io
MIT License
52 stars 20 forks source link

Create utility function for creating snapshots #225

Closed trevorb1 closed 4 months ago

trevorb1 commented 6 months ago

Feature Request

We have this bit of code in a few places:

snapshot_config = snakemake.config["snapshots"]
sns_start = pd.to_datetime(snapshot_config["start"])
sns_end = pd.to_datetime(snapshot_config["end"])
sns_inclusive = snapshot_config["inclusive"]

snapshots = pd.date_range(
    freq="h",
    start=sns_start,
    end=sns_end,
    inclusive=sns_inclusive,
)

We should probably turn it into a utility function that we just pass in the snapshot_config variable and we get the datetime out

Suggested Solution


def create_snapshots(snapshot_config: Dict[str,str]) -> pd.date_range

    return pd.date_range(
            freq="h",
            start=pd.to_datetime(snapshot_config["start"]),
            end=pd.to_datetime(snapshot_config["end"]),
            inclusive=snapshot_config["inclusive"],
    )

Additional Info

No response