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

Add category conversion #269

Merged
merged 42 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
952d9ac
Add initial support for converting DataArrays.
mikapfl Sep 23, 2021
2e5bb70
Depend on version of climate_categories with conversion support.
mikapfl Nov 2, 2021
2afb274
Conversions: refactor some things into own sub-functions, fix some ov…
mikapfl Nov 2, 2021
000dfc1
Conversions: refactor, do something useful with rules restricted to s…
mikapfl Nov 5, 2021
8b9b86f
Avoid name clash between weight function and its own argument.
mikapfl Nov 5, 2021
f4cc526
Require climate_categories >= 0.6.3, which introduces some API we need.
mikapfl Nov 5, 2021
506d0a9
Merge branch 'main' into mika-conversions
mikapfl Nov 14, 2023
fdbec61
style: ruff
mikapfl Nov 14, 2023
1ecee18
fix: stub file generation
mikapfl Nov 15, 2023
a7a1d9c
types: better typing for sum_rule
mikapfl Nov 15, 2023
1a2f2ba
test: some tests for correct results of convert()
mikapfl Nov 15, 2023
7e66953
perf: convert in-place
mikapfl Nov 15, 2023
a76feea
fix: types for 3.9
mikapfl Nov 15, 2023
8bf3e02
Merge branch 'main' into conversions
mikapfl Oct 7, 2024
91f9b76
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2024
80e87f0
Merge branch 'main' into conversions
mikapfl Oct 7, 2024
0849805
fix: _alias_selection is called _selection now
mikapfl Oct 7, 2024
e88f760
fix: bump minimum required version of climate_categories to something…
mikapfl Oct 7, 2024
57c8a5f
BURDI test draft
Oct 10, 2024
b9973cd
docs: add some algorithm notes
mikapfl Oct 10, 2024
4e1bb85
Merge branch 'main' into conversions
mikapfl Oct 10, 2024
77f7b16
Merge remote-tracking branch 'origin/conversions' into conversions-db
Oct 10, 2024
920999c
test for BURDI conversion
Oct 14, 2024
69c637b
ruff
Oct 14, 2024
113abda
comments
Oct 14, 2024
7428d51
add test for custom categorisations and custom conversion
Oct 17, 2024
868afbc
refactor convert
Oct 21, 2024
4ea5398
ruff
Oct 21, 2024
44c2cae
clean up
Oct 21, 2024
7ffe506
more cleanup
Oct 21, 2024
0db7373
docstring and argument passing from outer to inner convert function
Oct 21, 2024
adb202c
ruff and docstring
Oct 21, 2024
b896f64
remove _convert_inner wrapper
Oct 22, 2024
e62291d
update climate categories
Oct 24, 2024
bd9b91d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 24, 2024
1b714fd
get test data with importlib
Oct 24, 2024
73ce959
Revert "get test data with importlib"
Oct 24, 2024
2f8a35c
Merge branch 'conversions-db' of github.com:pik-primap/primap2 into c…
Oct 24, 2024
c90bb01
importlib
Oct 24, 2024
fffb84a
clean up
Oct 24, 2024
4b9bf2b
test signed commit
Oct 28, 2024
86aec44
update email for verified commits
crdanielbusch Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions primap2/_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ def select_no_scalar_dimension(
"""
if sel is None:
return obj
else:
sele: DatasetOrDataArray = obj.loc[sel]
if dim_names(obj) != dim_names(sele):
raise ValueError(
"The dimension of the selection doesn't match the dimension of the "
"orginal dataset. Likely you used a selection casting to a scalar "
"dimension, like sel={'axis': 'value'}. Please use "
"sel={'axis': ['value']} instead."
)
return sele
selection: DatasetOrDataArray = obj.loc[sel]
if dim_names(obj) != dim_names(selection):
raise ValueError(
"The dimension of the selection doesn't match the dimension of the "
"orginal dataset. Likely you used a selection casting to a scalar "
"dimension, like sel={'axis': 'value'}. Please use "
"sel={'axis': ['value']} instead."
)
return selection


class DataArrayAggregationAccessor(BaseDataArrayAccessor):
Expand All @@ -52,11 +51,10 @@ def _reduce_dim(
if dim is not None and reduce_to_dim is not None:
raise ValueError("Only one of 'dim' and 'reduce_to_dim' may be supplied, not both.")

if dim is None:
if reduce_to_dim is not None:
if isinstance(reduce_to_dim, str):
reduce_to_dim = [reduce_to_dim]
dim = set(self._da.dims) - set(reduce_to_dim)
if dim is None and reduce_to_dim is not None:
if isinstance(reduce_to_dim, str):
reduce_to_dim = [reduce_to_dim]
dim = set(self._da.dims) - set(reduce_to_dim)

return dim

Expand Down
Loading
Loading