Skip to content

Still issue loading None in morph.squeeze #298

@Luiskitsu

Description

@Luiskitsu

Problem

We are getting an error when trying to use None for morph.squeeze.
See the error below:

ValueError Traceback (most recent call last)
File ~/miniforge3/envs/bglk_lcls/lib/python3.13/site-packages/diffpy/morph/morphapp.py:607, in single_morph(parser, opts, pargs, stdout_flag, python_wrap, pymorphs)
606 try:
--> 607 squeeze_dict_in.update({f"a{idx}": float(coeff)})
608 idx += 1

ValueError: could not convert string to float: 'None'

During handling of the above exception, another exception occurred:

SystemExit Traceback (most recent call last)
Cell In[9], line 2
1 # Instantiate run object
----> 2 run_object = Run(run_number,
3 background_number,
4 sample_name,
5 sample_composition,
6 instrument,
7 experiment_number,
8 number_of_static_samples=number_of_static_samples,
9 delay_motor=delay_motor,
10 delay_scale=delay_scale,
11 delay_hshift=delay_hshift,
12 delay_vshift=delay_vshift,
13 delay_stretch=delay_stretch,
14 delay_smear=delay_smear,
15 delay_squeeze=delay_squeeze,
16 pdfgetter_config=pdfgetter_config,
17 getx_scale=getx_scale,
18 getx_squeeze_parms=getx_squeeze_parms,
19 q_min=q_min,
20 q_max=q_max,
21 fit_qmin=fit_qmin,
22 fit_qmax=fit_qmax,
23 q_min_morph=q_min_morph,
24 q_max_morph=q_max_morph,
25 pdf_rmin=pdf_rmin,
26 pdf_rmax=pdf_rmax,
27 azimuthal_selector=azimuthal_selector,
28 )
29 morph_parameters = run_object.morph_parameters # Dictionary with fitted morph parameters. The key is the delay.
30 get_ipython().run_line_magic('tb', '')

File ~/dev/ufpdf-xfel-scripts/src/ufpdf_xfel_scripts/lcls/run.py:187, in Run.init(self, run_number, background_number, sample_name, sample_composition, instrument, experiment_number, number_of_static_samples, target_id, q_min, q_max, r_min_fom, r_max_fom, q_min_morph, q_max_morph, delay_scale, delay_hshift, delay_vshift, delay_stretch, delay_squeeze, delay_smear, points_away_t0_plot_on_off, verbose, delay_motor, pdfgetter_config, getx_scale, getx_squeeze_parms, fit_qmin, fit_qmax, pdf_rmin, pdf_rmax, azimuthal_selector)
185 self._load()
186 self._reduce()
--> 187 self._morph()
188 try:
189 self._transform()

File ~/dev/ufpdf-xfel-scripts/src/ufpdf_xfel_scripts/lcls/run.py:543, in Run._morph(self)
540 morph_off_table = np.column_stack([x, y_off])
542 # fit morph parameters
--> 543 morph_parameters_on, _ = morph_arrays(
544 morph_on_table, target_table, **params
545 )
546 morph_parameters_off, _ = morph_arrays(
547 morph_off_table, target_table, **params
548 )
550 # apply parameters without refining. This is a workaround
551 # because of limited range of x that morph returns

File ~/miniforge3/envs/bglk_lcls/lib/python3.13/site-packages/diffpy/morph/morphpy.py:186, in morph_arrays(morph_table, target_table, scale, stretch, smear, plot, **kwargs)
181 parser = create_option_parser()
182 opts, pymorphs = get_morph_opts(
183 parser, scale, stretch, smear, plot, **kwargs
184 )
--> 186 return single_morph(
187 parser,
188 opts,
189 pargs,
190 stdout_flag=False,
191 python_wrap=True,
192 pymorphs=pymorphs,
193 )

File ~/miniforge3/envs/bglk_lcls/lib/python3.13/site-packages/diffpy/morph/morphapp.py:610, in single_morph(parser, opts, pargs, stdout_flag, python_wrap, pymorphs)
608 idx += 1
609 except ValueError:
--> 610 parser.error(f"{coeff} could not be converted to float.")
611 squeeze_poly_deg = len(squeeze_dict_in.keys())
612 squeeze_morph = morphs.MorphSqueeze()

File ~/miniforge3/envs/bglk_lcls/lib/python3.13/optparse.py:1569, in OptionParser.error(self, msg)
1562 """error(msg : string)
1563
1564 Print a usage message incorporating 'msg' to stderr and exit.
1565 If you override this in a subclass, it should not return -- it
1566 should either exit or raise an exception.
1567 """
1568 self.print_usage(sys.stderr)
-> 1569 self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))

File ~/miniforge3/envs/bglk_lcls/lib/python3.13/optparse.py:1559, in OptionParser.exit(self, status, msg)
1557 if msg:
1558 sys.stderr.write(msg)
-> 1559 sys.exit(status)

SystemExit: 2

Proposed solution

Allow morph.squeeze to be None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions