Skip to content

Commit

Permalink
Merge pull request #22 from mnagaso/devel
Browse files Browse the repository at this point in the history
multi value parameter can be written out in one line / avoid conversi…
  • Loading branch information
xumi1993 authored Nov 9, 2024
2 parents 04410d3 + 5f3b684 commit ab28be8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
5 changes: 3 additions & 2 deletions pytomoatt/para.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .utils.common import init_axis, str2val

yaml = YAML()
yaml.default_flow_style = True

class ATTPara:
"""Class for read and write parameter file with ``yaml`` format
Expand All @@ -24,10 +25,10 @@ def init_axis(self):
self.input_params['domain']['n_rtp'],
)
return dep, lat, lon, dd, dt, dp

def update_param(self, key: str, value) -> None:
"""Update a parameter in the YAML file.
:param key: The key of parameter file to be set. Use '.' to separate the keys.
:type key: str
"""
Expand Down
35 changes: 26 additions & 9 deletions pytomoatt/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,38 @@ def ignore_nan_3d(data):
xidx = np.arange(data.shape[2])
zz, xx, yy = np.meshgrid(zidx, yidx, xidx, indexing='ij')
interpolated = griddata(
points, values,
(zz, xx, yy),
points, values,
(zz, xx, yy),
method='nearest'
)
result = interpolated.reshape(data.shape)
return result

def str2val(str_val):
# single value handling
# return integer
try:
return int(str_val)
except ValueError:
try:
return float(str_val)
except ValueError:
try:
return [float(v) for v in str_val.strip('[]').split(',')]
except ValueError:
return str_val
pass

# return float
try:
return float(str_val)
except ValueError:
pass

# list values handling
# return list of integer
try:
return [int(v) for v in str_val.strip('[]').split(',')]
except ValueError:
pass

# return list of float
try:
return [float(v) for v in str_val.strip('[]').split(',')]
except ValueError:
pass

return str_val

0 comments on commit ab28be8

Please sign in to comment.