Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crystal metadata change #843

Merged
merged 14 commits into from
Nov 6, 2024
Merged

Crystal metadata change #843

merged 14 commits into from
Nov 6, 2024

Conversation

stan-dot
Copy link
Contributor

Code extracted from https://github.com/DiamondLightSource/dodal/pull/722/files

I don't quite understand why do we set this as a soft signal - that is one failing test at the moment

        # Soft metadata
        # If supplied include crystal details in output of read_configuration
        with self.add_children_as_readables(ConfigSignal):
            if crystal_1_metadata.usage is not None:
                self.crystal_1_usage, _ = soft_signal_r_and_setter(
                    str, initial_value=crystal_1_metadata.usage
                )
            else:
                self.crystal_1_usage = None
                

And I deleted one test too

@stan-dot
Copy link
Contributor Author

the error has to do with crystal spacing values

@callumforrester
Copy link
Contributor

What is the reason for this change?

@stan-dot stan-dot marked this pull request as ready for review October 21, 2024 11:15
@stan-dot
Copy link
Contributor Author

@callumforrester this is a refactor as d_spacing can be directly traced from the reflection values and the material properties.

Neater for the i18 lookup service

@rtuck99
Copy link
Contributor

rtuck99 commented Oct 25, 2024

@stan-dot I have raised a PR #870 which targets this branch and extends these changes onto the I03 DCM, as a prerequisite for DiamondLightSource/mx-bluesky#520

@JamesOHeaDLS do you know if the I03 DCM also supports getting the d-spacing from epics?

@stan-dot
Copy link
Contributor Author

thanks @rtuck99 , merged

@stan-dot stan-dot requested a review from rtuck99 October 28, 2024 12:09
Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Stan. Looks like i18 has the PVs now. Some comments in code though

src/dodal/devices/dcm.py Outdated Show resolved Hide resolved
src/dodal/common/crystal_metadata.py Outdated Show resolved Hide resolved
src/dodal/common/crystal_metadata.py Outdated Show resolved Hide resolved
src/dodal/common/crystal_metadata.py Outdated Show resolved Hide resolved
@stan-dot
Copy link
Contributor Author

<<<<<<< HEAD
async def test_crystal_metadata_not_propagated_when_not_supplied():
    async with DeviceCollector(mock=True):
        dcm = DoubleCrystalMonochromator(
            prefix="FOO-MO",
            temperature_prefix="FOO-DI",
            crystal_1_metadata=None,
            crystal_2_metadata=None,
        )

    configuration = await dcm.read_configuration()
    expected_absent_keys = {
        "crystal-1-usage",
        "crystal-1-type",
        "crystal-1-reflection",
        "crystal-1-d_spacing",
        "crystal-2-usage",
        "crystal-2-type",
        "crystal-2-reflection",
        "crystal-2-d_spacing",
    }
    assert expected_absent_keys.isdisjoint(configuration)


=======
>>>>>>> e8ac54553 (add to the beamline files)

@DominicOram all is fixed besides this test. I am not sure what is the purpose of the behavior here to have absent keys. For it to pass the metadata param in the DCM init would need to be CrystalMetadata | None and not CrystalMetadata.

I'm happy to delete the test, git blame points last modification to the test, for May 2024 by @callumforrester - what is the reason for the test? I'm equally happy to keep the test and change the behavior provided I note the reason for allowing None in the code.

@DominicOram
Copy link
Contributor

all is fixed besides this test...

Ok, I'm happy to retract https://github.com/DiamondLightSource/dodal/pull/843/files#r1820621900 so that we can keep this usecase. I'm still not 100% sure when it would be necessary but that's scope creep.

@stan-dot
Copy link
Contributor Author

@DominicOram I'm afraid I don't understand your last comment

@stan-dot stan-dot force-pushed the crystal-metadata branch 2 times, most recently from c46f234 to 6ee887d Compare November 4, 2024 12:21
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.61%. Comparing base (2e58d4e) to head (d3e79cd).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #843      +/-   ##
==========================================
+ Coverage   95.60%   95.61%   +0.01%     
==========================================
  Files         125      126       +1     
  Lines        5229     5242      +13     
==========================================
+ Hits         4999     5012      +13     
  Misses        230      230              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

stan-dot and others added 6 commits November 5, 2024 14:16
Previously this was hard coded to be a static float in milimeters for some reason, forgot to update this for this PR
* Implement crystal metadata for I03 DCM

* Make type-checking happy
@stan-dot
Copy link
Contributor Author

stan-dot commented Nov 5, 2024

 self.crystal_metadata_reflection, _ = soft_signal_r_and_setter(
                Sequence[int],
                initial_value=list(cm.reflection),  # type: ignore
            )
            

I think this might be due to ophyd-async change - this is in the 'dcm' device

@stan-dot stan-dot requested a review from DominicOram November 5, 2024 15:23
Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stan-dot. Couple of minor queries, I think I may have misunderstood a previous discussion.

d_spacing: tuple[float, str]

@staticmethod
def calculate_default_d_spacing(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: Sorry, maybe I've misunderstood, I thought the conclusion of the discussion at #843 (comment) was to remove all this calculation and use the PV? Or is it not yet on i22?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the PV isn't on i22 yet then I said in that comment, can we get the ball rolling on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was a discussion was to add the PV on i18, which ultimately just was a slight name change.

regarding the static method

        self.crystal_metadata_d_spacing = epics_signal_r(float, "DSPACING:RBV")

at the moment there is the PV value used. I might have mistaken with the line above where the 'initial value' is used.

at the moment the only place when the calculation is used is in the make_crystal_metadata_from_material where if the d_spacing is not supplied by the user, it's calculated.

we could remove it and make it required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so we still need it in there for i22. That's fine, I'll make a note on the conversion issue.

@@ -74,63 +61,45 @@ def __init__(

# Soft metadata
# If supplied include crystal details in output of read_configuration
crystal_1_metadata = crystal_1_metadata or CrystalMetadata()
crystal_2_metadata = crystal_2_metadata or CrystalMetadata()
with self.add_children_as_readables(ConfigSignal):
if crystal_1_metadata.usage is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: If we've now removed the option for these to be None then I don't think we need to check them all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

async def test_metadata_reflection(dcm: DCM):
signal = dcm.crystal_metadata_reflection
v = await signal.read()
print(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: It's not best practice to leave print statements in code

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@stan-dot stan-dot merged commit bcd40a3 into main Nov 6, 2024
19 checks passed
@stan-dot stan-dot deleted the crystal-metadata branch November 6, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request i18 i22
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants