Skip to content

Commit

Permalink
Fixed logic bug in mapping_functor that caused some quantities to bec…
Browse files Browse the repository at this point in the history
…ome skipped
  • Loading branch information
atomprobe-tc committed Nov 3, 2024
1 parent 61ba15b commit 460341f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
50 changes: 25 additions & 25 deletions src/pynxtools_em/concepts/mapping_functors_pint.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,17 @@ def map_functor(
set_value(template, trg, src_values, trg_dtype_key)
elif case == "case_three_str": # str, ureg.Unit, str
src_val = mdata.get(f"{prfx_src}{cmd[2]}")
if not src_val:
continue
trg = var_path_to_spcfc_path(f"{prfx_trg}/{cmd[0]}", ids)
if isinstance(src_val, ureg.Quantity):
set_value(template, trg, src_val.to(cmd[1]), trg_dtype_key)
else:
set_value(
template, trg, ureg.Quantity(src_val, cmd[1].units), trg_dtype_key
)
if src_val is not None:
trg = var_path_to_spcfc_path(f"{prfx_trg}/{cmd[0]}", ids)
if isinstance(src_val, ureg.Quantity):
set_value(template, trg, src_val.to(cmd[1]), trg_dtype_key)
else:
set_value(
template,
trg,
ureg.Quantity(src_val, cmd[1].units),
trg_dtype_key,
)
elif case == "case_three_list": # str, ureg.Unit, list
if len(cmd[2]) == 0:
continue
Expand Down Expand Up @@ -340,14 +342,13 @@ def map_functor(
)
elif case == "case_five_str":
src_val = mdata.get(f"{prfx_src}{cmd[2]}")
if not src_val:
continue
trg = var_path_to_spcfc_path(f"{prfx_trg}/{cmd[0]}", ids)
if isinstance(src_val, ureg.Quantity):
set_value(template, trg, src_val.to(cmd[1]), trg_dtype_key)
else:
pint_src = ureg.Quantity(src_val, cmd[3])
set_value(template, trg, pint_src.to(cmd[1]), trg_dtype_key)
if src_val is not None:
trg = var_path_to_spcfc_path(f"{prfx_trg}/{cmd[0]}", ids)
if isinstance(src_val, ureg.Quantity):
set_value(template, trg, src_val.to(cmd[1]), trg_dtype_key)
else:
pint_src = ureg.Quantity(src_val, cmd[3])
set_value(template, trg, pint_src.to(cmd[1]), trg_dtype_key)
elif case == "case_five_list":
if len(cmd[2]) == 0:
continue
Expand Down Expand Up @@ -375,14 +376,13 @@ def map_functor(
continue
src_val = mdata[f"{prfx_src}{cmd[2]}"]
src_unit = mdata[f"{prfx_src}{cmd[3]}"]
if not src_val or not src_unit:
continue
trg = var_path_to_spcfc_path(f"{prfx_trg}/{cmd[0]}", ids)
if isinstance(src_val, ureg.Quantity):
set_value(template, trg, src_val.units.to(cmd[1]), trg_dtype_key)
else:
pint_src = ureg.Quantity(src_val, ureg.Unit(src_unit))
set_value(template, trg, pint_src.to(cmd[1]), trg_dtype_key)
if src_val is not None and src_unit is not None:
trg = var_path_to_spcfc_path(f"{prfx_trg}/{cmd[0]}", ids)
if isinstance(src_val, ureg.Quantity):
set_value(template, trg, src_val.units.to(cmd[1]), trg_dtype_key)
else:
pint_src = ureg.Quantity(src_val, ureg.Unit(src_unit))
set_value(template, trg, pint_src.to(cmd[1]), trg_dtype_key)
return template


Expand Down
3 changes: 2 additions & 1 deletion src/pynxtools_em/configurations/image_tiff_fei_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
),
],
}
# TODO:: L68 should be commented in again related to TODO in case_five_list
# TODO:: L68 should be commented in again related to not handling list of ureg.Quantity
# as catched currently in case_five_list of concepts/mapping_functors_pint L361


FEI_TECNAI_DYNAMIC_VARIOUS_NX: Dict[str, Any] = {
Expand Down

0 comments on commit 460341f

Please sign in to comment.