@@ -19,6 +19,57 @@ def get_args(parser, params, kwargs):
1919 return opts , pargs
2020
2121
22+ def __get_morph_opts__ (parser , scale , stretch , smear , plot , ** kwargs ):
23+ # Check for Python-specific options
24+ python_morphs = ["funcy" ]
25+ pymorphs = {}
26+ for pmorph in python_morphs :
27+ if pmorph in kwargs :
28+ pmorph_value = kwargs .pop (pmorph )
29+ pymorphs .update ({pmorph : pmorph_value })
30+
31+ # Special handling of parameters with dashes
32+ kwargs_copy = kwargs .copy ()
33+ kwargs = {}
34+ for key in kwargs_copy .keys ():
35+ new_key = key
36+ if "_" in key :
37+ new_key = key .replace ("_" , "-" )
38+ kwargs .update ({new_key : kwargs_copy [key ]})
39+
40+ # Special handling of store_true and store_false parameters
41+ opts_storing_values = [
42+ "verbose" ,
43+ "pearson" ,
44+ "addpearson" ,
45+ "apply" ,
46+ "reverse" ,
47+ ]
48+ opts_to_ignore = ["multiple-morphs" , "multiple-targets" ]
49+ for opt in opts_storing_values :
50+ if opt in kwargs :
51+ # Remove if user sets false in params
52+ if not kwargs [opt ]:
53+ kwargs .pop (opt )
54+ for opt in opts_to_ignore :
55+ if opt in kwargs :
56+ kwargs .pop (opt )
57+
58+ # Wrap the CLI
59+ params = {
60+ "scale" : scale ,
61+ "stretch" : stretch ,
62+ "smear" : smear ,
63+ "noplot" : True if not plot else None ,
64+ }
65+ opts , _ = get_args (parser , params , kwargs )
66+
67+ if not len (pymorphs ) > 0 :
68+ pymorphs = None
69+
70+ return opts , pymorphs
71+
72+
2273# Take in file names as input.
2374def morph (
2475 morph_file ,
@@ -58,38 +109,12 @@ def morph(
58109 Function after morph where morph_table[:,0] is the abscissa and
59110 morph_table[:,1] is the ordinate.
60111 """
61-
62- # Check for Python-specific morphs
63- python_morphs = ["funcy" ]
64- pymorphs = {}
65- for pmorph in python_morphs :
66- if pmorph in kwargs :
67- pmorph_value = kwargs .pop (pmorph )
68- pymorphs .update ({pmorph : pmorph_value })
69-
70- # Special handling of parameters with dashes
71- kwargs_copy = kwargs .copy ()
72- kwargs = {}
73- for key in kwargs_copy .keys ():
74- new_key = key
75- if "_" in key :
76- new_key = key .replace ("_" , "-" )
77- kwargs .update ({new_key : kwargs_copy [key ]})
78-
79- # Wrap the CLI
80- parser = create_option_parser ()
81- params = {
82- "scale" : scale ,
83- "stretch" : stretch ,
84- "smear" : smear ,
85- "noplot" : True if not plot else None ,
86- }
87- opts , _ = get_args (parser , params , kwargs )
88-
89112 pargs = [morph_file , target_file ]
113+ parser = create_option_parser ()
114+ opts , pymorphs = __get_morph_opts__ (
115+ parser , scale , stretch , smear , plot , ** kwargs
116+ )
90117
91- if not len (pymorphs ) > 0 :
92- pymorphs = None
93118 return single_morph (
94119 parser ,
95120 opts ,
@@ -139,36 +164,18 @@ def morph_arrays(
139164 Function after morph where morph_table[:,0] is the abscissa and
140165 morph_table[:,1] is the ordinate.
141166 """
142- # Check for Python-specific morphs
143- python_morphs = ["funcy" ]
144- pymorphs = {}
145- for pmorph in python_morphs :
146- if pmorph in kwargs :
147- pmorph_value = kwargs .pop (pmorph )
148- pymorphs .update ({pmorph : pmorph_value })
149-
150- # Wrap the CLI
151- parser = create_option_parser ()
152- params = {
153- "scale" : scale ,
154- "stretch" : stretch ,
155- "smear" : smear ,
156- "noplot" : True if not plot else None ,
157- }
158- opts , _ = get_args (parser , params , kwargs )
159-
160167 morph_table = np .array (morph_table )
161168 target_table = np .array (target_table )
162-
163169 x_morph = morph_table [:, 0 ]
164170 y_morph = morph_table [:, 1 ]
165171 x_target = target_table [:, 0 ]
166172 y_target = target_table [:, 1 ]
167-
168173 pargs = ["Morph" , "Target" , x_morph , y_morph , x_target , y_target ]
174+ parser = create_option_parser ()
175+ opts , pymorphs = __get_morph_opts__ (
176+ parser , scale , stretch , smear , plot , ** kwargs
177+ )
169178
170- if not len (pymorphs ) > 0 :
171- pymorphs = None
172179 return single_morph (
173180 parser ,
174181 opts ,
0 commit comments