Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ICARTT Python Package
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MBEES
ICARTT Python Package
Commits
a68241f6
Commit
a68241f6
authored
3 years ago
by
Florian Obersteiner
Browse files
Options
Downloads
Patches
Plain Diff
func sanitize: more meaningful name, use np.isclose for float equality comparison
parent
8dca7d6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
code refactor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/icartt/dataset.py
+8
-7
8 additions, 7 deletions
src/icartt/dataset.py
with
8 additions
and
7 deletions
src/icartt/dataset.py
+
8
−
7
View file @
a68241f6
...
...
@@ -25,9 +25,10 @@ class VariableType(IntEnum):
DependentVariable
=
4
def
sanitize
(
val
,
miss
):
# TODO: should not use == for float comparison instead, use np.isclose
return
float
(
val
)
if
not
float
(
val
)
==
float
(
miss
)
else
np
.
NaN
def
vmiss_to_npnan
(
val
,
miss
):
"""
converts value to np.nan if is (almost) equal to miss
"""
val
,
miss
=
map
(
float
,
(
val
,
miss
))
return
np
.
NaN
if
np
.
isclose
(
val
,
miss
)
else
val
class
DataStore1001
:
...
...
@@ -63,12 +64,12 @@ class DataStore1001:
if
not
self
.
ivarname
in
kwargs
.
keys
():
raise
Exception
(
"
Need independent variable data.
"
)
ivarvalue
=
sanitize
(
kwargs
[
self
.
ivarname
],
self
.
missvals
[
self
.
ivarname
])
ivarvalue
=
vmiss_to_npnan
(
kwargs
[
self
.
ivarname
],
self
.
missvals
[
self
.
ivarname
])
newline
=
np
.
array
(
np
.
NaN
,
dtype
=
[(
v
,
"
f8
"
)
for
v
in
self
.
varnames
])
for
key
in
kwargs
.
keys
():
if
key
in
self
.
varnames
:
newline
[
key
]
=
sanitize
(
kwargs
[
key
],
self
.
missvals
[
key
])
newline
[
key
]
=
vmiss_to_npnan
(
kwargs
[
key
],
self
.
missvals
[
key
])
if
type
(
self
.
data
)
is
type
(
None
):
# TODO: None is the sole instance of None ;-) => can use "if self.data is None"
self
.
data
=
newline
...
...
@@ -141,7 +142,7 @@ class DataStore2110(collections.UserDict):
def
_addBulk
(
self
,
raw
,
n
):
cur
=
0
while
cur
<
n
:
ivarvalue
=
sanitize
(
raw
[
cur
][
0
],
self
.
missvals
[
self
.
ivarname
])
ivarvalue
=
vmiss_to_npnan
(
raw
[
cur
][
0
],
self
.
missvals
[
self
.
ivarname
])
self
.
_addAuxline
(
raw
[
cur
])
cur
+=
1
...
...
@@ -159,7 +160,7 @@ class DataStore2110(collections.UserDict):
if
not
self
.
ivarname
in
kwargs
.
keys
():
raise
Exception
(
"
Need independent variable data.
"
)
ivarvalue
=
sanitize
(
kwargs
[
self
.
ivarname
],
self
.
missvals
[
self
.
ivarname
])
ivarvalue
=
vmiss_to_npnan
(
kwargs
[
self
.
ivarname
],
self
.
missvals
[
self
.
ivarname
])
# this is an AUX line
if
any
([
x
in
self
.
auxvarnames
for
x
in
kwargs
.
keys
()]):
# TODO: any (all as well) do not require a comprehension; pure generator expression works fine
...
...
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