Conversation
* define base class * add init test * Fix #1127 --------- Co-authored-by: Valentin Gebhart <valentin.gebhart@usys.ethz.ch> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Add ImpactForecast * Add unit tests
* Create hazardForecast base class * Update datetime to timedelta for lead_time * Add tests --------- Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* change leadtime to timedelta * adapt impactforecast docstrings and tests * Remove stray comment --------- Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Add HazardForecast.select test --------- Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Add test for hazardForecast.concat * Skip HazardForecast.concat test --------- Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Add test for ImpactForecast.select * minor test modification --------- Co-authored-by: Evelyn Mühlhofer <evelyn.muehlhofer@meteoswiss.ch>
* Add test stub for ImpactForecast.concat * Use correct command for skipping a test * Fix merge issue
* Add data shape check for HazardForecast, ImpactForecast
Adapt Hazard from_hdf5 and write_hdf5 to forecast attributes
* Add extended select impact forecast test * Add extended hazard forecast test --------- Co-authored-by: Chahan Kropf <chahan.kropf@posteo.com> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Return impactForecast object in _return_impact * Return impactForecast object in _return_empty * Add full impactcalc test for impactForecast * Raise value error when computing impact with impact forecast without saving impact matrix * Cosmetics: Improve error message, move test to own class * Write nans for eai_exp and aai_agg when forecast is used --------- Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Chahan Kropf <chahan.kropf@posteo.com> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* add idx boolean selection for member and leadtime * Add test for weird data types --------- Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Add ImpactForecast.select --------- Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* add HazardForecast.select and extent test --------- Co-authored-by: Eliane Kobler <ekobler@student.ethz.ch> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
85b92ef to
302be63
Compare
Add min/mean/max methods --------- Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Chahan Kropf <chahan.kropf@posteo.com> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* implement changes in Impact IO and ImpactForecast IO * Update tests * Fix small issue when reading H5 for ImpactForecast --------- Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
* Add quantile and median for hazard and impact forecast * Review --------- Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Chahan Kropf <chahan.kropf@posteo.com> Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
…ython into forecast-class
* Add impact forecast tutorial * Add 'dim' argument to reductions * Update tests --------- Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com> Co-authored-by: luseverin <luca.severino@usys.ethz.ch> Co-authored-by: Evelyn Mühlhofer <evelyn.muehlhofer@meteoswiss.ch> Co-authored-by: Chahan Kropf <chahan.kropf@posteo.com>
…ython into forecast-class
|
@Evelyn-M How was the |
I downloaded it from the meteoswiss-internal data storage, since the API only permits downloads until -24 hrs. |
|
So it had been reprojected? Does MCH store the data differently than OGD? I am just wondering because it might be important to highlight the caveats when importing datasets with varying CRS and coordinate specifications. |
|
I suppose so, yes. One is the MCH grid commonly used internally for national gridded forecast products, and the OGD data has a different grid and a much larger rectangular extent around Switzerland. |
|
Can you please let me know once this is final for review? |
| import numpy as np | ||
|
|
||
|
|
||
| class Forecast: |
There was a problem hiding this comment.
It seems that there are people recommending to add "Mixin" to the class name for mixin classes. E.g. "ForecastMixin"
| """ | ||
| concat_kws = {} if concat_kws is None else concat_kws | ||
| return forecast.concat( | ||
| [ |
There was a problem hiding this comment.
I found this a bit hard to read, to understand what is happening. I see that the code is doing what it should, but maybe the variable names could be changed to make things clearer?
E.g.:
values --> attr_values
select --> attr_name
reduce_attr --> reduce_method
There was a problem hiding this comment.
Renamed and reworked a bit
| npt.assert_array_equal(idx, np.array([True, False, False, False]), strict=True) | ||
|
|
||
| idx = forecast.idx_lead_time(None) | ||
| npt.assert_array_equal(idx, np.array([False, False, False, False]), strict=True) |
There was a problem hiding this comment.
no tests for
_reduce_attrs
reduce_unique_selection
_unique_or_default
but the working of these might be tested in the functions calling them
There was a problem hiding this comment.
Private methods cannot be tested separately (because they are private?). reduce_unique_selection is tested via the reduction methods of the final classes. It's correct that a unit test should check the standalone function
| return reduced_attrs | ||
|
|
||
|
|
||
| def reduce_unique_selection( |
There was a problem hiding this comment.
on first reading I found the back on forth confusing. e.g. HazardForecast.min() calls reduce_unqiue_slection with again calls HazardForecast.min().
I see why this works, just to comment on readability
| expected_n_events = ( | ||
| forecast_netcdf_file["n_eps"] * forecast_netcdf_file["n_lead_time"] | ||
| ) | ||
| npt.assert_array_equal(haz_fc.date, np.zeros(expected_n_events, dtype=int)) |
There was a problem hiding this comment.
what about setting the date to the date of the reference time? Maybe it makes sense not to, just thinking
|
|
||
| @at_event.setter | ||
| def at_event(self, value): | ||
| """Set the total impact for each member/lead_time combination.""" |
There was a problem hiding this comment.
was this getter/setter set to allow for some future type checking or so? otherwise maybe not necessary?
There was a problem hiding this comment.
Getter/setter methods exist to emit a warning when used
| select_mask = np.array([2, 1]) | ||
| ordered_select_mask = np.array([1, 2]) | ||
| if var == "date": | ||
| # Date needs to be a valid delta |
There was a problem hiding this comment.
same as in test_hazard_forecast.py
| ) | ||
|
|
||
| num_centroids = len(impact_kwargs["coord_exp"]) | ||
| imp_fc_select = impact_forecast.select(event_names=["aaaaa", "foo"]) |
There was a problem hiding this comment.
Is it on purpose that in hazard_forecast.select() we raise an error when there is an emtpy selection and here not?
There was a problem hiding this comment.
This follows the respective base class implementations 🤷
| @pytest.fixture | ||
| def reduction_results_dim(self): | ||
| return { | ||
| "lead_time": { |
There was a problem hiding this comment.
I think at_event should always return the sum of the impact matrix over the locations (i.e., axis=1), independent of if the eventdimension corresponds to lead_time or member.
In the test, this is tested for "member" but not for "lead_time". The values look like they would give the same sum(axis=1) and sum(axis=0). Maybe we could adapt a value such that we know the right axis is summed? If too compilated, maybe the test for "member" is enough.
There was a problem hiding this comment.
I don't understand. at_event is always exactly np.sum(imp_mat, axis=1), both for member and for lead_time.
I think at_event should always return the sum of the impact matrix over the locations (i.e., axis=1), ...
I agree! The test checks this explicitly, in my perception?
There was a problem hiding this comment.
sorry, my comment was not clear. You are right, at_event should always be exactly np.sum(imp_mat, axis=1).
My point was that in the test of "lead_time", the test values seem to be chosen such that the impact matrix is always symmetric (off diagonals are the same), which is why np.sum(imp_mat, axis=1) is the same as np.sum(imp_mat, axis=0). So we actually do not test if the correct axis is summed here. However, we test this in the test of "member", so that should suffice. For me we can leave as is.
|
@chahank This is final for review 🙂 |
|
Excellent! I will try to do it swiftly. |
| "aai_agg": 14.4, | ||
| "unit": "USD", | ||
| "frequency_unit": "1/month", | ||
| "imp_mat": sparse.csr_matrix( |
There was a problem hiding this comment.
Is it worth to test for negative impact values too?
There was a problem hiding this comment.
After downloading the data, we do
dict_ens_data["TOT_PREC"] = time_ops.delta(
dict_ens_data["TOT_PREC"], np.timedelta64(1, "h")
)
This looks like we change from total values to differences. I assume we do this because how TOT_PREC is defined?
We should for sure add an explanation and warning because if I just copy the code and use it for wind speed (VMAX_10M) I do NOT want to compute the difference.
There was a problem hiding this comment.
Indeed, I added a comment
| "haz_type": "TC", | ||
| "pool": None, | ||
| "intensity": sparse.csr_matrix( | ||
| [[0.2, 0.3, 0.4], [0.1, 0.1, 0.01], [4.3, 2.1, 1.0], [5.3, 0.2, 0.0]] |
There was a problem hiding this comment.
Please include negative value intensity.
There was a problem hiding this comment.
The change to this file only wraps the previous dummy_hazard function into a fixture. I think changing the intensity values is out of scope, because changes here might have effects on all other hazard tests. We can pick this up in a discussion about the conftest.py fixtures, see #1278
|
Is there a plan already to work on the comments by @ValentinGebhart? |
|
The tutorial is now titled only impact forecast, but it is mostly about hazard forecast. This is quite confusing. Can this maybe be split into two tutorials? Or give it a different name? |
|
A few comments on the tutorial:
|
chahank
left a comment
There was a problem hiding this comment.
Excellent addition to the CLIMADA platform!
Please find a few detailled comments by @ValentinGebhart to address, and some user friendliness requests for the tutorial.
Co-authored-by: Valentin Gebhart <60438839+ValentinGebhart@users.noreply.github.com>
…ython into forecast-class
Changes proposed in this PR:
This PR resolves a major portion of #1118. Note that sub-tasks have been marked as completed when merged into this branch.
PR Author Checklist
develop)PR Reviewer Checklist