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 subclass to get electrification profiles and versions #616

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

jenhagg
Copy link
Collaborator

@jenhagg jenhagg commented Apr 16, 2022

Purpose

Enable loading electrification profiles from blob storage or local disk, and listing the available versions. This is kind of a draft since we haven't actually uploaded the profiles or determined if this is the best way to organize them, but it is easy to change that later if we want.

What the code is doing

New InputBase subclass to reuse some of the functionality (e.g. caching) but rather than overloading the scenario_info parameter in get_data I just created a separate method with the relevant parameters. Also, to reuse the chunk of code in DataAccess that combines blob and local profiles, the logic is factored out into a function specific to each module and passed as a callback that takes just the filesystem object as an argument.

Testing

New unit test.

Time estimate

15 min

@jenhagg jenhagg self-assigned this Apr 16, 2022
@jenhagg jenhagg linked an issue Apr 16, 2022 that may be closed by this pull request
1 task
base_name = f"{end_use}_{tech}_"
matching = [f for f in _fs.listdir(".") if base_name in f]

return [f.replace(base_name, "").replace(".csv", "") for f in matching]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: I changed lstrip and rstrip to replace here because it turns out those strip any of the given characters starting from one side until one doesn't match, so it could lead to unpredictable results.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we have 'demand' or 'solar' or whatever elsewhere within the string, it seems that will get replaced as well. Should we do this via regex instead? E.g.

>>> import re
>>> s = "ab_cd_ef"
>>> match = re.search("^(?P<prefix>ab_)?(?P<main>[^_]+)(?P<suffix>_ef)?$", s)
>>> match.group('prefix')
'ab_'
>>> match.group('main')
'cd'
>>> match.group('suffix')
'_ef'

Copy link
Collaborator

Choose a reason for hiding this comment

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

@danielolsen Will that be filtered by kind first? I think it depends on the folder structure we have, unless we simply put all profiles in one folder. In general, using string parsing methods is more readable and easier to maintain.

Copy link
Contributor

@danielolsen danielolsen Apr 19, 2022

Choose a reason for hiding this comment

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

String parsing methods are definitely clearer, but have the potential for weird side effects if the strings are not always constructed in the way that we expect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With this implementation, kind is either "building" or "transportation". So the profiles in each of those folders will have the structure [end_use]_[tech]_[version].csv.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree. I will defer to @jon-hagg's decision at this point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think since we are responsible for profile names and version, and in this case replacing the entire prefix up to the version, it's unlikely we run into issues. E.g. the version should hopefully not contain ".csv" or "res_cooking_standard_heat_pump". I do like regex, but since the naming is so consistent we probably don't need it at this point?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this code operate on the local folder as well, where users may add their own arbitrarily-named profiles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does operate on the local folder. I guess we should document the expected structure for custom profiles if we don't have that yet. My assumption is that it's not supposed to work for arbitrary names, just custom versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I trust your judgement. It's not like we have a ton of users out there adding a bunch of weirdly named files yet.

Copy link
Contributor

@danielolsen danielolsen left a comment

Choose a reason for hiding this comment

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

LGTM

@jenhagg jenhagg merged commit f773043 into develop Apr 21, 2022
@jenhagg jenhagg deleted the jon/elec_input branch April 21, 2022 00:20
@jenhagg jenhagg mentioned this pull request May 27, 2022
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.

Upload electrification profiles to blob storage
3 participants