From 74d72100d4ad8a7f6e6a3d6dd535fcae6560b189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Fri, 3 Jun 2022 08:34:02 +0300 Subject: [PATCH] Fix typos in argproc.py, metavars to "labeled" parameters --- qpms/argproc.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/qpms/argproc.py b/qpms/argproc.py index aeddda5..2295f72 100644 --- a/qpms/argproc.py +++ b/qpms/argproc.py @@ -227,9 +227,10 @@ class hashable_complex_matrix(tuple): numpy.ndarray(..., dtype=complex) (which by itself is not hashable) """ def __new__(self, matrix): + import numpy as np if isinstance(matrix, str): - matrix = ast.literal_eval(string) - matrix = np.ndarray(matrix, dtype=complex, copy=False) + matrix = ast.literal_eval(matrix) + matrix = np.array(matrix, dtype=complex, copy=False) return super().__new__(hashable_complex_matrix, (tuple(row) for row in matrix)) # auxiliary structures for t-matrix generator specifications @@ -275,42 +276,48 @@ class ArgParser: mpgrp.add_argument("-p", "--position", nargs='+', action=make_dict_action(argtype=sfloat, postaction='append', first_is_key=False), help="Particle positions, cartesion coordinates (default particle properties)") mpgrp.add_argument("+p", "++position", nargs='+', action=make_dict_action(argtype=sfloat, postaction='append', - first_is_key=True), help="Particle positions, cartesian coordinates (labeled)") + first_is_key=True), metavar=('LABEL', 'POSITION'), help="Particle positions, cartesian coordinates (labeled)") mpgrp.add_argument("-L", "--lMax", nargs=1, default={}, action=make_dict_action(argtype=int, postaction='store', first_is_key=False,), help="Cutoff multipole degree (default)") mpgrp.add_argument("+L", "++lMax", nargs=2, action=make_dict_action(argtype=int, postaction='store', first_is_key=True,), - help="Cutoff multipole degree (labeled)") + metavar=('LABEL', 'LMAX'), + help="Cutoff multipole degree (labeled)") mpgrp.add_argument("-m", "--material", nargs=1, default={}, action=make_dict_action(argtype=material_spec, postaction='store', first_is_key=False,), help='particle material (Au, Ag, ... for Lorentz-Drude or number for constant refractive index) (default)') mpgrp.add_argument("+m", "++material", nargs=2, action=make_dict_action(argtype=material_spec, postaction='store', first_is_key=True,), + metavar=('LABEL', 'MATERIAL'), help='particle material (Au, Ag, ... for Lorentz-Drude or number for constant refractive index) (labeled)') mpgrp.add_argument("-r", "--radius", nargs=1, default={}, action=make_dict_action(argtype=float, postaction='store', first_is_key=False,), help='particle radius (sphere or cylinder; default)') mpgrp.add_argument("+r", "++radius", nargs=2, action=make_dict_action(argtype=float, postaction='store', first_is_key=True,), + metavar=('LABEL', 'RADIUS'), help='particle radius (sphere or cylinder; labeled)') mpgrp.add_argument("-H", "--height", nargs=1, default={}, action=make_dict_action(argtype=float, postaction='store', first_is_key=False,), help='particle radius (cylinder; default)') mpgrp.add_argument("+H", "++height", nargs=2, action=make_dict_action(argtype=float, postaction='store', first_is_key=True,), + metavar=('LABEL', 'HEIGȞT'), help='particle radius (cylinder; labeled)') # Alternatively, add a constant T-matrix - mpgrp.add_argmuent("-w", "--vswf-set", nargs=1, default={}, - action=make_dict_action(argtype=string2basespec, postaction='store', first_is_key=False), + mpgrp.add_argument("-w", "--vswf-set", nargs=1, default={}, + action=make_dict_action(argtype=string2bspec, 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_argmuent("+w", "++vswf-set", nargs=2, default={}, - action=make_dict_action(argtype=string2basespec, postaction='store', first_is_key=True), + mpgrp.add_argument("+w", "++vswf-set", nargs=2, default={}, + action=make_dict_action(argtype=string2bspec, 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_argmuent("-T", "--constant-tmatrix", nargs=1, default={}, + mpgrp.add_argument("-T", "--constant-tmatrix", nargs=1, default={}, action=make_dict_action(argtype=hashable_complex_matrix, postaction='store', first_is_key=False), help='constant T-matrix (elements must correspond to --vswf-set)') - mpgrp.add_argmuent("+T", "++constant-tmatrix", nargs=2, default={}, + mpgrp.add_argument("+T", "++constant-tmatrix", nargs=2, default={}, + metavar=('LABEL', 'TMATRIX'), action=make_dict_action(argtype=hashable_complex_matrix, postaction='store', first_is_key=True), help='constant T-matrix (elements must correspond to ++vswf-set)')