Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
payno
id06workflow
Commits
fe0b5b62
Commit
fe0b5b62
authored
Nov 30, 2018
by
payno
Browse files
[Dim] add to_dict and from_dict functions to cast from/to a dictionary
parent
bf9bbb2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
id06workflow/core/experiment/__init__.py
View file @
fe0b5b62
...
...
@@ -483,3 +483,38 @@ class Dim(object):
def
__str__
(
self
):
return
" "
.
join
((
str
(
self
.
kind
),
str
(
self
.
name
),
'size:'
,
str
(
self
.
size
)))
def
to_dict
(
self
):
"""translate the current Dim to a dictionary"""
return
{
'name'
:
self
.
name
,
'kind'
:
self
.
kind
,
'size'
:
self
.
size
,
'relative_prev_val'
:
self
.
relative_prev_val
,
}
@
staticmethod
def
from_dict
(
_dict
):
"""
:param dict _dict: dict defining the dimension. Should contains the
following keys: name, kind, size, relative_prev_val
unique values are not stored into it because it
depends on the metadata and should be obtain from a
fit / set_dims
:return: Dim corresponding to the dict given
:rtype: :class:`Dim`
"""
assert
type
(
_dict
)
is
dict
missing_keys
=
[]
for
_key
in
(
'name'
,
'kind'
,
'size'
,
'relative_prev_val'
):
if
_key
not
in
_dict
:
missing_keys
.
append
(
missing_keys
)
if
len
(
missing_keys
)
>
0
:
raise
ValueError
(
'There is some missing keys (%s), unable to create'
'a valid Dim'
)
else
:
return
Dim
(
name
=
_dict
[
'name'
],
kind
=
_dict
[
'kind'
],
size
=
_dict
[
'size'
],
relative_prev_val
=
_dict
[
'relative_prev_val'
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment