-
Notifications
You must be signed in to change notification settings - Fork 33
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
Updates to the water module, water avaialbility and country sub-annual features #115
Conversation
Codecov Report
@@ Coverage Diff @@
## main #115 +/- ##
=======================================
- Coverage 69.3% 68.1% -1.3%
=======================================
Files 75 75
Lines 4975 5066 +91
=======================================
+ Hits 3448 3450 +2
- Misses 1527 1616 +89
|
Hey @adrivinca, thanks for the PR :) |
Thanks, I have some issues in setting it up in my VSC, it is not actually like in those instructions. But I generally run
It complaints that there are too many if conditions, but they are somehow necessary Concerning test, I did not add new functions and the tests of the existing functions will come with the PR #106 |
Yes, thanks for letting me know. Maybe I should write a small guide of my own to enable colleagues to set the tools up for automatic runs, but I will have to test my settings first. As for the complexity, the issue is that if you include too many (nested) if conditions, the code will be very complex to understand -- for people as well as for the computer. If you were to write tests, your function would now probably require about 25 different sets of parameters to be fully tested because you need to make sure to test each if-branch. One common solution is to move if-checks to new functions, which moves complexity as well. See e.g. your lines 484-502: for var in elec_hydro_var:
if "hydro_1" in var or "hydro_hc" in var:
report_iam = report_iam.append(
# Multiply electricity output of hydro to get withdrawals
# this is an ex-post model calculation and the values are taken from
# data/water/ppl_cooling_tech/tech_water_performance_ssp_msg.csv
# for hydr_n water_withdrawal_mid_m3_per output is converted by
# multiplying with 60 * 60* 24 * 365 * 1e-9 to convert it
# into km3/output
report_iam.multiply(
f"{var}", 0.161, f"Water Withdrawal|Electricity|Hydro|{var[21:28]}"
)
)
else:
report_iam = report_iam.append(
report_iam.multiply(
f"{var}", 0.323, f"Water Withdrawal|Electricity|Hydro|{var[21:28]}"
)
) Instead, you could say something like: report_iam = multiply_electricity_output_of_hydro(elec_hydro_var, report_iam)
...
def multiply_electricity_output_of_hydro(elec_hydro_var, report_iam):
for var in elec_hydro_var:
if "hydro_1" in var or "hydro_hc" in var:
report_iam = report_iam.append(
# Multiply electricity output of hydro to get withdrawals
# this is an ex-post model calculation and the values are taken from
# data/water/ppl_cooling_tech/tech_water_performance_ssp_msg.csv
# for hydr_n water_withdrawal_mid_m3_per output is converted by
# multiplying with 60 * 60* 24 * 365 * 1e-9 to convert it
# into km3/output
report_iam.multiply(
f"{var}", 0.161, f"Water Withdrawal|Electricity|Hydro|{var[21:28]}"
)
)
else:
report_iam = report_iam.append(
report_iam.multiply(
f"{var}", 0.323, f"Water Withdrawal|Electricity|Hydro|{var[21:28]}"
)
)
return report_iam Of course, you could also rename the parameters to differentiate e.g. |
thanks @glatterf42 ! I tried to set up all the automatism I could on VSC and reduced the complexity of the report function to of 6 levels. Still it is too complex for flake, so I bypass the check there, since it is not a priority to make it the perfect script. now I get a Lint error related to a config file not touched by me... I wonder if it is a problem of main |
Good catch about mypy! They released version 1.5.0 on August 10, which changed the signature of the
So my guess is we can ignore the error for the time being as it will probably be fixed by a new release of mypy soon. We could also pin version 1.4.1 until then. |
The PR you mention for adding tests, #106, had it's last push about a month ago, so I don't know how soon this will actually add tests. I understand that it seems tedious to write tests for code that you will use correctly, but if I understand correctly, our aim with this repository is to make our tools public. This has multiple benefits, but one notable drawback is that people could/will start using our code however they see fit, which does not necessarily comply to the way you intended the code to be used. If and when people run into problems on that route, they will turn to us to help them. And if Paul and I don't know what they are referring to, we will ask you. For just one or two persons, this might be fine, but there will come a point where it is more time efficient to write tests that ensure behaviour now rather helping individual cases as they come up. A very similar point can be made about code complexity; so I would ask you to please don't block the test. If you already started simplifying the code, you have a good idea how to do that now. I realise that this time requirement is often not accounted for by projects, but if at all possible, I would prefer to get the tests and linting checks to pass before merging. |
After talking to Paul, we agreed that it is fine to exclude single functions from flake8 cover for now. But please mark them with a |
Thanks for replying and checking with Paul. I'll still add the #TODO mark |
sorry for the confusion, I reverted the last commit and I have no more to add here |
No worries. Just for your information: with this PR as it is, people are able to check out the specific commit with which you added the leap_re project and thus gain access to all files you committed there even though you reverted it. If you want, we can instead remove this commit (hopefully) entirely: git reset --hard dbe1019
git push --force This should remove the last two commits and I'm hoping mentions of them as well. |
still not working for sub-annual timesteps
…ual timesteps Commented irrigation water prices for the global model, as it was referring to outdated "water_irr" level, while now there are three levels. Still to be updated
This reverts commit 0fcbc11.
c9230a8
to
9c62f1c
Compare
Rebased onto current main, now all tests are passing except for the test coverage, which #106 will hopefully add soon. Please really try to increase the coverage there as we are aiming for 100% coverage with our public tools. If you agree to do that and don't have any further additions here, we can merge this PR. |
yes please let's merge this. thanks a lot |
Hi all—please in the future try to follow the code style per commit message formatting. Please ask if you need any clarification or assistance on that. |
This PR only affects the water module with some updates:
private_data_path
package_data_path
How to review
Someone can try run the reporting ona test scenario made for Zambia with sub-annual timesteps
mix-models --url=ixmp://ixmp_dev/MESSAGEix_ZM/test_report water-ix --regions=ZMB report --water
PR checklist