Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
f0350d25
Commit
f0350d25
authored
5 years ago
by
Markus Scheidgen
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug in unit conversion optimization.
parent
1d1192df
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/unit_conversion/unit_conversion.py
+8
-1
8 additions, 1 deletion
common/python/nomadcore/unit_conversion/unit_conversion.py
with
8 additions
and
1 deletion
common/python/nomadcore/unit_conversion/unit_conversion.py
+
8
−
1
View file @
f0350d25
...
...
@@ -12,6 +12,7 @@ import re
import
logging
from
pint
import
UnitRegistry
import
cachetools
import
numpy
as
np
logger
=
logging
.
getLogger
(
__name__
)
# disable warnings from pint
logging
.
getLogger
(
"
pint
"
).
setLevel
(
logging
.
ERROR
)
...
...
@@ -58,7 +59,13 @@ def convert_unit(value, unit, target_unit=None):
"""
factor
=
get_multiplicative_factor
(
unit
,
target_unit
)
if
factor
is
not
None
:
return
value
*
factor
try
:
if
isinstance
(
value
,
(
list
,
tuple
)):
return
(
np
.
array
(
value
)
*
factor
).
tolist
()
else
:
return
value
*
factor
except
Exception
as
e
:
logger
.
error
(
'
could not perform optimized unit conversion
'
,
exc_info
=
e
)
# Check that the unit is valid
unit_def
=
ureg_cached
(
unit
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment