argproc don't convert --vswf-set arguments directly to BaseSpec

BaseSpec is currently not picklable, and we want to be able to save
the command line arguments used.

Hence we first save the ilist as tuple instead.
This commit is contained in:
Marek Nečada 2022-06-06 05:19:11 +03:00
parent 74d72100d4
commit 5086e42353
1 changed files with 7 additions and 5 deletions

View File

@ -238,12 +238,14 @@ constant_tmatrix_spec = namedtuple("constant_tmatrix_spec", ("bspec", "matrix"))
cyl_sph_dimensions = namedtuple("cyl_sph_dimensions", ("radius", "height", "lMax_extend"))
tmgen_spec = namedtuple("tmgen_spec", ("bgspec", "fgspec", "dims"))
def string2bspec(string):
def string2bspec_tuple(string):
"""
Converts string representation of list to BaseSpec.
Converts string representation of list to BaseSpec...
And then to tuple, because we want the arguments to be picklable :(
"""
from .cybspec import BaseSpec
return BaseSpec(ast.literal_eval(string))
bspec = BaseSpec(ast.literal_eval(string))
return tuple(i for i in bspec.ilist)
class ArgParser:
''' Common argument parsing engine for QPMS python CLI scripts. '''
@ -307,10 +309,10 @@ class ArgParser:
help='particle radius (cylinder; labeled)')
# Alternatively, add a constant T-matrix
mpgrp.add_argument("-w", "--vswf-set", nargs=1, default={},
action=make_dict_action(argtype=string2bspec, postaction='store', first_is_key=False),
action=make_dict_action(argtype=string2bspec_tuple, postaction='store', first_is_key=False),
help='Manual specification of VSWF set codes (format as a python list of integers); see docs on qpms_uvswfi_t for valid codes or simply use --lMax instead. Overrides --lMax.')
mpgrp.add_argument("+w", "++vswf-set", nargs=2, default={},
action=make_dict_action(argtype=string2bspec, postaction='store', first_is_key=True),
action=make_dict_action(argtype=string2bspec_tuple, postaction='store', first_is_key=True),
metavar=('LABEL', "VSWF_SET"),
help='Manual specification of VSWF set codes (format as a python list of integers); see docs on qpms_uvswfi_t for valid codes or simply use ++lMax instead. Overrides ++lMax and --lMax.')
mpgrp.add_argument("-T", "--constant-tmatrix", nargs=1, default={},