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

Separate hot water and space heating demand profiles #390

Merged
merged 8 commits into from
Jun 9, 2024

Conversation

brynpickering
Copy link
Member

Fixes #389

Checklist

Any checks which are not relevant to the PR can be pre-checked by the PR creator. All others should be checked by the reviewer. You can add extra checklist items here if required by the PR.

  • CHANGELOG updated
  • Minimal workflow tests pass
  • Tests added to cover contribution
  • Documentation updated
  • Configuration schema updated

Copy link
Contributor

@irm-codebase irm-codebase left a comment

Choose a reason for hiding this comment

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

Quick glance at the code. Overall, it looks good!

Just a couple of minor comments.

@@ -188,7 +218,8 @@ def get_daily_heat_demand(

def heat_function(t, parameters):
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to avoid using inner functions unless protection from outside callers is absolutely necessary. The main reason is that you cannot write tests for these.

Consider bringing it outside and renaming to _heat_function to specify that it's an inner function.

scripts/heat/unscaled_heat_profiles.py Outdated Show resolved Hide resolved
scripts/heat/unscaled_heat_profiles.py Outdated Show resolved Hide resolved
scripts/heat/unscaled_heat_profiles.py Outdated Show resolved Hide resolved
Update zenodo source of gridded weather data
- Remove lat-lon renaming.
- add processing profiles of entire configured year range.
- subset weather data to reduce minimal workflow runtime.
- improve variable names.
- add type hints and docstrings.
- move assumptions to top of script.
@brynpickering brynpickering mentioned this pull request Jun 7, 2024
@brynpickering brynpickering changed the base branch from develop to pr-390-file-rename-helper June 7, 2024 16:19
@brynpickering brynpickering deleted the feature-hot-water branch June 7, 2024 16:26
@brynpickering brynpickering restored the feature-hot-water branch June 7, 2024 16:26
@brynpickering brynpickering reopened this Jun 7, 2024
@brynpickering brynpickering changed the base branch from pr-390-file-rename-helper to develop June 7, 2024 16:27
@brynpickering
Copy link
Member Author

Sorry for the messy operations - fixing a github diff issue was a pain.

@brynpickering brynpickering mentioned this pull request Jun 7, 2024
5 tasks
Copy link
Contributor

@irm-codebase irm-codebase left a comment

Choose a reason for hiding this comment

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

Minor comments. Reply/fix is optional.
Approved!

rules/heat.smk Show resolved Hide resolved
"""
celsius_clipped = temperature.clip(min=HOT_WATER_LOWER_BOUND_TEMP)

return parameters["m_w"] * celsius_clipped + parameters["b_w"] + parameters["D"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Small improvement here would be to create variables with explicit names for these parameters.
But it seems like when2heat also has this style, so it's a nice to have.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, pretty sure they don't even have full names in the base source (the german govt. agency documentation).

)
for building in buildings
],
dim=pd.Index(buildings, name="building"),
)


def group_gridcells(gridded_data: xr.DataArray, weight: xr.DataArray) -> xr.DataArray:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like an internal "helper" function. Consider _group_gridcells.

rules/heat.smk Show resolved Hide resolved
The profiles need to be scaled so their magnitude matches annual heat demand data in a subsequent step.

Args:
path_to_population (str): Gridded population data, which will act as the weighting to got from grid-level profiles to profiles per model unit.
Copy link
Member

Choose a reason for hiding this comment

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

FYI: In other workflows, I stopped handing over paths as strings but rather handing data in and out. After doing this for a while, I'd recommend it. Maybe we could discuss this technical detail at one of the dev calls.

The function signature is then:

def business_logic(data: pd.DataFrame) -> pd.DataFrame:
    # code here
    return df

if __name__ == "__main__":
    data = business_logic(pd.read_csv(snakemake.input[0]))
    data.to_csv(snakemake.outptu[0])

Copy link
Member Author

Choose a reason for hiding this comment

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

I can see merits of both. Especially if reading the file is simple (no need to define header/row levels or parse dates, etc.), it would probably be easier to debug with data being handed in, rather than strings. Once you have lots going on with the data loading, I'm less certain about having so much going on in if __name__ == "__main__" because then debugging becomes hard (e.g. you can't load those parts of the script as methods in an interactive session).

Let's discuss at the next dev call.

@brynpickering brynpickering merged commit 5de87bc into develop Jun 9, 2024
3 of 4 checks passed
@timtroendle timtroendle deleted the feature-hot-water branch June 9, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate space heating and hot water demand
3 participants