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

feat: state demand profile interface function #327

Merged

Conversation

dmuldrew
Copy link
Collaborator

@dmuldrew dmuldrew commented Jan 9, 2023

Pull Request doc

Purpose

Create an interface function to simplify generating profiles by state. Also, finished merging the LDV/HDV smart charging functions into one common function.

What the code is doing

This function generates a dictionary of vehicle miles traveled (bev_vmt) for a specific geographic regions within a given state. It then outputs a demand profile for each geographic region. The state function input is also mapped to a census region which loads the appropriate vehicle census data.

Testing

manual testing so far, would like to eventually add an automated integration test

Time estimate

~30min

@dmuldrew dmuldrew self-assigned this Jan 9, 2023
@dmuldrew dmuldrew changed the title Dmuldrew/demand profile interface feat: state demand profile interface function Jan 9, 2023
Copy link
Collaborator

@BainanXia BainanXia left a comment

Choose a reason for hiding this comment

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

Let's be more specific on the doc strings of input parameters given this will be a user-facing function, i.e. which parameter is used for which charing strategy; if a parameter is only used for smart charing, then it should be optional; speaking of that, it would be great if we can add some checks on different combinations of the input parameters based on different charing strategies.

:param np.array load_demand: initial load demand (MW for each hour)
:param int power: (optional) charger power, EVSE kW; default value: 6.6 kW;
:param int location_strategy: (optional) where the vehicle can charge-1, 2, 3, 4, or 5;
1-home only, 2-home and work related, 3-anywhere if possibile,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the difference between work related and work?

Choose a reason for hiding this comment

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

Nothing as far as I know. I'll double-check with Kate.

Choose a reason for hiding this comment

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

Aha! Reply from Kate: It is currently labeled work-related, because there are a couple "whyfrom" and "whyto" answers that have work in the description. For instance, 04=Work-related meeting / trip. This is a nuance that I don't think is worth parsing in the data nor the code. I'm ok with leaving it as work related but also open to changing it.

Comment on lines 76 to 88
urban_bev_vmt = load_urbanized_scaling_factor(
model_year=model_year,
veh_type=veh_type,
veh_range=veh_range,
urbanized_area=urban_area,
state=state,
filepath=urban_scaling_filepath,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the logic that splits large urban areas that crossing state borders will kick in here, in the downstream function calls once implemented, right?

Choose a reason for hiding this comment

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

I believe that logic will actually be part of the pre-algorithm data processing step that we'll finish via #317. Each state will have a separate entry to include its portion of those urban areas.
Example: from the ua_st_list_all.xls file, Dubuque IA--IL has population of 64,767 in IA and 3,051 in IL.
Currently we've used the ua_list_all.xls file, which has Dubuque IA--IL with a population of 67,818.

@rouille rouille force-pushed the transportation_electrification branch from f1a8a2f to 556f0db Compare January 11, 2023 21:56
@dmuldrew dmuldrew force-pushed the dmuldrew/demand_profile_interface branch from 5a76be2 to c186098 Compare January 11, 2023 22:25
@dmuldrew dmuldrew requested a review from BainanXia January 11, 2023 22:27
Comment on lines 14 to 31
def ldv_weekend_weekend_check(x, y):
"""Helper function to select weekday/weekend data rows

:param int x: data weekday/weekend value
:param int y: model year weekday/weekend value
:return: (*bool*) -- if data row matches whether the current day is a weekday/weekend
"""
return x == y


def hdv_use_all_data_rows(x, y):
"""Helper function to select weekday/weekend data rows

:param int x: data weekday/weekend value
:param int y: model year weekday/weekend value
:return: (*bool*) -- always returns true to use all data rows
"""
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite follow what we are doing here.

Choose a reason for hiding this comment

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

This looks similar to the get_data_day and/or get_input_day' functions in data_helper.py`. Could one of those be used instead of creating a new function?

Choose a reason for hiding this comment

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

Bainan - the context is that the LDV and LDT data from NHTS has a differentiation between weekday and weekend trip patterns. The MDV and HDV data does not have that differentiation

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. Nonetheless, having a function simply returning x == y and another one always returning True seems to be redundant. I would suggest to use lambda if necessary.

Copy link
Collaborator Author

@dmuldrew dmuldrew Jan 11, 2023

Choose a reason for hiding this comment

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

It's an intermediate refactoring step before changing the looping structure...I wanted to use lambda functions instead of function definitions but the linter complained:
https://www.flake8rules.com/rules/E731.html

Ideally I'm going to get rid of the double loop over all the data every day, and switch out weekend and weekday dataframes for the light vehicle case.

The function use_data_row determines if a data row is used for a particular day:

if use_data_row(data_day[i], input_day[day_iter]):

and is set based on whether veh_type is "ldv"/"ldt" or "mdv"/"hdv"

  if veh_type.lower() == "ldv" or veh_type.lower() == "ldt":
      use_data_row = ldv_weekend_weekend_check
  elif veh_type.lower() == "mdv" or veh_type.lower() == "hdv":
      use_data_row = hdv_use_all_data_rows

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dmuldrew So eventually we will get rid of this, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I'm definitely not happy with it long-term

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool. Let's leave it as it is for now then.

@rouille rouille force-pushed the transportation_electrification branch from bcc38ef to a80e79e Compare January 12, 2023 23:04
@dmuldrew dmuldrew force-pushed the dmuldrew/demand_profile_interface branch from ce796cb to 17bf9dd Compare January 17, 2023 17:03
@dmuldrew
Copy link
Collaborator Author

Looks like
prereise/gather/flexibilitydata/doe/tests/test_bus_data.py::test_get_bus_fips
is failing in PR test workflows

@rouille rouille force-pushed the transportation_electrification branch from d93a2c3 to ff67e97 Compare January 19, 2023 01:33
@dmuldrew dmuldrew force-pushed the dmuldrew/demand_profile_interface branch from 99d8c59 to 2f3b94c Compare January 19, 2023 19:54
Copy link
Collaborator

@BainanXia BainanXia left a comment

Choose a reason for hiding this comment

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

Thanks!

@dmuldrew dmuldrew force-pushed the dmuldrew/demand_profile_interface branch from 2f3b94c to 0daa966 Compare January 19, 2023 21:25
@dmuldrew dmuldrew merged commit 31ead30 into transportation_electrification Jan 19, 2023
@dmuldrew dmuldrew deleted the dmuldrew/demand_profile_interface branch January 19, 2023 21:34
rouille pushed a commit that referenced this pull request Jan 20, 2023
…ile_interface

feat: state demand profile interface function
rouille pushed a commit that referenced this pull request Feb 1, 2023
…ile_interface

feat: state demand profile interface function
rouille pushed a commit that referenced this pull request Feb 1, 2023
…ile_interface

feat: state demand profile interface function
rouille pushed a commit that referenced this pull request Feb 24, 2023
…ile_interface

feat: state demand profile interface function
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.

3 participants