Parsing of logarithmic units
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start at the cf_xarray.units units entry point and reproduce the reported units("lg(re mg.m-3)") failure. Check how the Pint registry handles this expression and identify the relevant existing tests, if any. Done means the documented logarithmic unit no longer raises UndefinedUnitError and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Description
Hi,
I'm working with data files having units provided as lg(re mg.m-3), which according to the udunits documentation here is valid.
However trying to parse this with the units module of cf_xarrays seems to crash:
In [5]: from cf_xarray.units import units
In [6]: units("lg(re mg.m-3)")
---------------------------------------------------------------------------
UndefinedUnitError Traceback (most recent call last)
Cell In[6], line 1
----> 1 units("lg(re mg.m-3)")
File ~/mambaforge/envs/satpy/lib/python3.11/site-packages/pint/facets/plain/registry.py:1264, in PlainRegistry.parse_expression(self, input_string, case_sensitive, use_decimal, **values)
1261 input_string = string_preprocessor(input_string)
1262 gen = tokenizer(input_string)
-> 1264 return build_eval_tree(gen).evaluate(
1265 lambda x: self._eval_token(x, case_sensitive=case_sensitive, **values)
1266 )
File ~/mambaforge/envs/satpy/lib/python3.11/site-packages/pint/pint_eval.py:114, in EvalTreeNode.evaluate(self, define_op, bin_op, un_op)
112 if op_text not in bin_op:
113 raise DefinitionSyntaxError('missing binary operator "%s"' % op_text)
--> 114 left = self.left.evaluate(define_op, bin_op, un_op)
115 return bin_op[op_text](left, self.right.evaluate(define_op, bin_op, un_op))
116 elif self.operator:
117 # unary operator
File ~/mambaforge/envs/satpy/lib/python3.11/site-packages/pint/pint_eval.py:124, in EvalTreeNode.evaluate(self, define_op, bin_op, un_op)
121 return un_op[op_text](self.left.evaluate(define_op, bin_op, un_op))
122 else:
123 # single value
--> 124 return define_op(self.left)
File ~/mambaforge/envs/satpy/lib/python3.11/site-packages/pint/facets/plain/registry.py:1265, in PlainRegistry.parse_expression.<locals>.<lambda>(x)
1261 input_string = string_preprocessor(input_string)
1262 gen = tokenizer(input_string)
1264 return build_eval_tree(gen).evaluate(
-> 1265 lambda x: self._eval_token(x, case_sensitive=case_sensitive, **values)
1266 )
File ~/mambaforge/envs/satpy/lib/python3.11/site-packages/pint/facets/plain/registry.py:1151, in PlainRegistry._eval_token(self, token, case_sensitive, use_decimal, **values)
1146 return self.Quantity(values[token_text])
1147 else:
1148 return self.Quantity(
1149 1,
1150 self.UnitsContainer(
-> 1151 {self.get_name(token_text, case_sensitive=case_sensitive): 1}
1152 ),
1153 )
1154 elif token_type == NUMBER:
1155 return ParserHelper.eval_token(token, non_int_type=self.non_int_type)
File ~/mambaforge/envs/satpy/lib/python3.11/site-packages/pint/facets/plain/registry.py:599, in PlainRegistry.get_name(self, name_or_alias, case_sensitive)
597 candidates = self.parse_unit_name(name_or_alias, case_sensitive)
598 if not candidates:
--> 599 raise UndefinedUnitError(name_or_alias)
600 elif len(candidates) == 1:
601 prefix, unit_name, _ = candidates[0]
UndefinedUnitError: 'lg' is not defined in the unit registry
I guess this is not implemented. Anything I can do to help with this?
- Dominant language
- Python
- Stars
- 181
- Forks
- 49
- Avg merge
- 43m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from xarray-contrib/cf-xarray
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
xarray-contrib/cf-xarray#623 ·
-
Consider adding opt-in support for circular axes when calling `bounds_to_vertices` (related to #594) Open
Difficulty 5/5 Over a week Newbie friendliness 38/100
xarray-contrib/cf-xarray#596 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
xarray-contrib/cf-xarray#570 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
xarray-contrib/cf-xarray#568 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
xarray-contrib/cf-xarray#566 · 2 comments ·
All issues in xarray-contrib/cf-xarray
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
zostera/django-bootstrap4#894 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3276 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#759 ·