-
Notifications
You must be signed in to change notification settings - Fork 7
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
Enabling multiple weatherforecastlocations selection #146
base: main
Are you sure you want to change the base?
Enabling multiple weatherforecastlocations selection #146
Conversation
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
e9a2c72
to
b91a37e
Compare
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
Signed-off-by: black <action@github.com>
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
Signed-off-by: black <action@github.com>
openstef_dbc/services/weather.py
Outdated
@@ -55,6 +55,7 @@ def _get_nearest_weather_location( | |||
location: Union[Tuple[float, float], str], | |||
country: str = "NL", | |||
threshold: float = 150.0, | |||
k: int = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this parameter name more descriptive? E.g. number_locations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, il will change it to number_locations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @clara-de-smet,
the parameter k has been renamed to number_locations :
openstef-dbc/openstef_dbc/services/weather.py
Lines 53 to 59 in 009e60f
def _get_nearest_weather_locations( | |
self, | |
location: Union[Tuple[float, float], str], | |
country: str = "NL", | |
threshold: float = 150.0, | |
number_locations: int = 1, | |
) -> pd.Series: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this feature! See the comments for things that I found. In general it is probably worth to change the output from _get_nearest_weather_locations to a list of strings instead of supporting both a single string and a list of strings. Contact me via teams or email if you have any questions or want to discuss a little.
openstef_dbc/services/weather.py
Outdated
|
||
# Find closest weather location | ||
if distances.index.min() < threshold: | ||
if isinstance(nearest_location, pd.Series): | ||
return nearest_location.reset_index(drop=True)[0] | ||
return nearest_location.reset_index(drop=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output of this function should be string (name of the weather location).
I see in line 108 nearest weather location is created as a list, the if statement in line 112 checks if nearest location is a pd.Series which will never be the case. Probably you do not want to convert the pd.Series to a list in line 108.
If you want to return mulitple weather locations,I think it is good to update the output type hints and documentation that a list of strings is returned instead of just a string. Maybe also change the name "nearest_location" into "nearest_locations"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed.
I will apply modifications so that the output is a list of str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the class of the object returned :
It is now a dataframe with one column "input_city" containing the name of the nearest(s) weather location(s), and the distance (in km) as index.
Such information my be of interest for someone who desire to compute spatial weighted averaging of weather indices (which is RTE's case).
Therefore, the 'list' of input_city is extracted from this dataframe just before db query :
openstef-dbc/openstef_dbc/services/weather.py
Lines 303 to 308 in 009e60f
# Initialise strings for the querying influx, it is not possible to parameterize this string | |
weather_params_str = '" or r._field == "'.join(weatherparams) | |
weather_models_str = '" or r.source == "'.join(source) | |
weather_location_name_str = '" or r.input_city == "'.join( | |
location_name.to_list() | |
) |
openstef_dbc/services/weather.py
Outdated
@@ -215,6 +217,7 @@ def get_weather_data( | |||
source: Union[List[str], str] = "optimum", | |||
resolution: str = "15min", | |||
country: str = "NL", | |||
k: int = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as @clara-de-smet mentioned this should be more descriptive e.g. max_number_of_weather_locations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will use @clara-de-smet suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JanMaartenvanDoorn , k has been renamed to number_locations
openstef_dbc/services/weather.py
Outdated
|
||
# Make a list of the source and weatherparams. | ||
# Like this, it also works if source is a string instead of multiple values | ||
if isinstance(source, str): | ||
source = [source] | ||
if isinstance(weatherparams, str): | ||
weatherparams = [weatherparams] | ||
if isinstance(location_name, str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide we only return a list of strings in _get_nearest_weather_location, we do not have to do this conversion and check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to add unit tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a 2 unit tests in test_weather.py :
def test_get_multiple_location_weather_data(self, MockDataInterface): |
def test_get_single_location_weather_data(self, MockDataInterface): |
openstef_dbc/services/weather.py
Outdated
result = result.loc[datetime_start_original:] | ||
result = result[result.index >= datetime_start_original] | ||
|
||
if k == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is another k which is not so descriptive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This have been changed.
Plus, I added a merge with location_name dataframe to add "distiance" column to the returned dataframe if number_locations > 1
openstef-dbc/openstef_dbc/services/weather.py
Lines 362 to 372 in 009e60f
if number_locations == 1: | |
result = result.drop(columns="input_city") | |
else: | |
# Adding distance information en km | |
result = ( | |
result.reset_index() | |
.merge(location_name.reset_index(), how="left", on="input_city") | |
.set_index("datetime") | |
) | |
return result |
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
Signed-off-by: black <action@github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for implementing these changes!
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
…of-only-1' of https://github.com/maxi-fort/openstef-dbc into 145-extract-multiple-nearest-weather-locations-instead-of-only-1
Signed-off-by: fortinmax <maxime.fortin@rte-france.com>
Signed-off-by: black <action@github.com>
@JanMaartenvanDoorn and @clara-de-smet ,
|
The evolution enables multiple weatherforecastlocations selection.
Default is one weatherforecastlocation (the nearest) so it does not impact the original behaviour of the code.