bluesky / hklpy

Diffractometer computation library with ophyd pseudopositioner support
https://blueskyproject.io/hklpy
BSD 3-Clause "New" or "Revised" License
2 stars 11 forks source link

BUG: restore(clear=False) reflections added to other samples #289

Closed prjemian closed 7 months ago

prjemian commented 8 months ago
In [61]: config.restore(pathlib.Path("fourc-config.json"), clear=True)

In [62]: list_reflections(True)
Sample: main

 #   H  K  L   Two Theta    Theta      Chi      Phi   orienting   
 0   2  0  0      37.000    0.000   90.000   71.500   first        
 1   0  4  0      60.000   30.000   90.000    0.000   second       
============================================================================
Sample: EuAl4

 #   H  K  L   Two Theta    Theta      Chi      Phi   orienting   
 0   0  4  0      60.000   30.000   90.000    0.000   first        
 1   2  0  0      37.000    0.000   90.000   71.500   second       
============================================================================

In [63]: config.restore(pathlib.Path("fourc-config.json"), clear=False)

In [64]: list_reflections(True)
Sample: main

 #   H  K  L   Two Theta    Theta      Chi      Phi   orienting   
 0   2  0  0      37.000    0.000   90.000   71.500   first        
 1   0  4  0      60.000   30.000   90.000    0.000   second       
============================================================================
Sample: EuAl4

 #   H  K  L   Two Theta    Theta      Chi      Phi   orienting   
 0   0  4  0      60.000   30.000   90.000    0.000 
 1   2  0  0      37.000    0.000   90.000   71.500 
 2   2  0  0      37.000    0.000   90.000   71.500 
 3   0  4  0      60.000   30.000   90.000    0.000 
 4   0  4  0      60.000   30.000   90.000    0.000   first        
 5   2  0  0      37.000    0.000   90.000   71.500   second       
============================================================================

It looks like when clear=False, it reads reflections from 'main' also into the following sample.

Originally posted by @strempfer in https://github.com/bluesky/hklpy/issues/279#issuecomment-1798543499

prjemian commented 8 months ago

@strempfer: I have reproduced this situation in test code with the current version and am working on repairs now. In short, the restored samples should each have two reflections in this test. That fails:

        for sample in e4cv.calc._samples.values():
            assert len(sample.reflections) == 2, f"{sample.name=}"
        assert len(e4cv.calc._samples) == 4

        agent = DiffractometerConfiguration(e4cv)
        config = agent.export()

        agent.restore(config, clear=False)

        assert len(e4cv.calc._samples) == 4
        for sample in e4cv.calc._samples.values():
>           assert len(sample.reflections) == 2
E           AssertionError: assert 10 == 2
prjemian commented 8 months ago

Those commits should have been on a new branch. Since I've pushed them, will remove the changes with git revert.

prjemian commented 8 months ago

Lots of new errors now in test_configuration.py module.

prjemian commented 8 months ago

All of the form: It is not possible to compute the UB matrix when the given reflections are colinear. When this line is removed, no such error, but reflections are duplicated: https://github.com/bluesky/hklpy/blob/c8163ab8a6ad28e0342ae9d8c27695d1ed391130/hkl/configuration.py#L297

prjemian commented 8 months ago

... Starving for a sample.update_reflection() method. Alas, v2 item.