-
Notifications
You must be signed in to change notification settings - Fork 2
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 category conversion #269
Conversation
…pecific categories.
# Conflicts: # primap-stubs.patch # primap2/_selection.py # primap2/accessors.py # setup.cfg
for more information, see https://pre-commit.ci
@@ -0,0 +1,40 @@ | |||
# references: non_annex1_data repo | |||
# last_update: 2024-10-14 |
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.
@JGuetschow does the BURDI
to IPCCC2006_PRIMAP
conversion make sense to you? I took took the rules from the config in the UNFCCC_non-AnnexI_data repo. The rules here combine the mapping and aggregation step. However we still need some aggregation after the conversion, for example for "3": {"sources": ["M.AG", "M.LULUCF"]
. That's beyond the scope of what the conversion should do if I remember correctly?
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 could add 4 + 5, 3
as a rule to aggregate AFOLU as you already do the same for 2 and 3. I think we just wanted to exclude downscaling, not aggregation.
primap2/_convert.py
Outdated
def _convert_inner( | ||
self, | ||
dim: Hashable | str, | ||
categorization: climate_categories.Categorization | str, | ||
*, | ||
# TODO type will change to climate_categories.Conversion when | ||
# https://github.com/primap-community/climate_categories/pull/164 is merged | ||
conversion: climate_categories._conversions.Conversion, |
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.
Now that I see the definition of _convert_inner
, I think we can go all-in with this approach. As you said in chat, we can leave the whole "get the right conversion" business to climate_categories
, where we have functions for this already. So, we just call this here convert
and throw away the wrapper which fetches the conversion from a name. The resulting call for a "simple" conversion would look like this:
import climate_categories as cc
conversion = cc.BURDI.conversion_to(cc.IPCC2006_PRIMAP)
da.convert("category", conversion=conversion)
for me, this is actually more transparent than what the current convert
does:
da.convert("category", "IPCC2006_PRIMAP")
Sure, the current convert
function needs less typing, but it also hides where the conversions come from, so as soon as you define your own categorization which is not built into climate_categories, it is unclear how you would use it. In contrast, using the "inner" function as the public API, it is obvious that you can build your own conversion and pass that.
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 think I originally designed the API of convert
to be similar to e.g. GWP and unit conversion. However, for units and also global warming potentials, we assume that user-defined units and GWPs will be super uncommon, so hiding the complexities from the user made sense. So, users don't have to pass a Unit
object, they can simply pass a string with a name.
However, here, I think we already know from the non-AnnexI repo that we will frequently have to modify the conversion
before we can use (or use a fully custom conversion). In this case, users have a Conversion
object already anyway, so it makes sense to use the Conversion
object instead of names.
But we should check that the passed Conversion
actually converts from the actual source categorization of the data and refuse to convert FAOstat categories using a conversion from BURDI to IPCC2006.
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.
makes all sense to me
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 the input Mika and Johannes. Mika if you could have a quick look at _convert.py
again, that would be great. I have now integrated the changes from the latest climate categories release. In the end, only a few lines of code changed.
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've added a few comments. Have to submit a review so they are actually visible.
primap2/_convert.py
Outdated
def _convert_inner( | ||
self, | ||
dim: Hashable | str, | ||
categorization: climate_categories.Categorization | str, | ||
*, | ||
# TODO type will change to climate_categories.Conversion when | ||
# https://github.com/primap-community/climate_categories/pull/164 is merged | ||
conversion: climate_categories._conversions.Conversion, |
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.
makes all sense to me
4.A,3.A.1 | ||
4.B,3.A.2 | ||
4.C,3.C.7 | ||
4.D + 4.C + 4.E + 4.F + 4.G,3.C |
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.
It would be good to also map 4.D to single category, else we have some of the 3.C subcategories but not all which can lead to confusion and problems in category aggregation and consistency checks. I would add an M-category to IPCC2006_PRIMAP
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.
Ok thanks. I will take this to another PR. And maybe move it to climate categories, because this is where the conversion will live.
@@ -0,0 +1,40 @@ | |||
# references: non_annex1_data repo | |||
# last_update: 2024-10-14 |
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 could add 4 + 5, 3
as a rule to aggregate AFOLU as you already do the same for 2 and 3. I think we just wanted to exclude downscaling, not aggregation.
for more information, see https://pre-commit.ci
This reverts commit 1b714fd.
…onversions-db pre commit
Before you merge, you need to change the target of the PR to |
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, definitely a cleaner API now, and adding the tests is super useful for further development. 🙂
categorization. Contains ``climate_categories.Categorization`` | ||
object for old and new categorization. |
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.
categorization. Contains ``climate_categories.Categorization`` | |
object for old and new categorization. | |
categorization. Contains the ``climate_categories.Categorization`` | |
objects for the old and the new categorization. |
Changes we also discussed which aren't in this PR yet, but will be much easier now with the added tests:
Probably, these changes deserve their own PR each. Also, still some open questions around best usability re the downscaling question. My suggestion: In a first PR remove the |
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #269 +/- ##
==========================================
- Coverage 97.20% 96.96% -0.24%
==========================================
Files 47 49 +2
Lines 4397 4612 +215
==========================================
+ Hits 4274 4472 +198
- Misses 123 140 +17 ☔ View full report in Codecov by Sentry. |
Pull request
Please confirm that this pull request has done the following:
{pr}.thing.md
file in the directorychangelog
added - see changelog/README.md for detailsDescription
Continues Mika's work from #74. We want to be able to convert categories from one standard into another, for example from IPCC1996 to IPCC2006. More info here primap-community/climate_categories#160