Skip to content

Do not allow an empty instance of DiffractionObject - init requires xarray, yarray, xtype #227

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

Closed
Tracked by #143
bobleesj opened this issue Dec 14, 2024 · 2 comments · Fixed by #228
Closed
Tracked by #143
Assignees

Comments

@bobleesj
Copy link
Contributor

bobleesj commented Dec 14, 2024

Problem

Continuing our discussion from #224 - We do not want User to have an empty DiffractionObject instance.

Proposed solution

In our init method, we could modfy

from:

class DiffractionObject:
    def input_data(
        self,
        xarray,
        yarray,
        xtype,
        metadata={},
        scat_quantity=None,
        name=None,
        wavelength=None,
    ):

to:

class DiffractionObject:
    def __init__(
        self,
        xarray,
        yarray,
        xtype,
        wavelength,
        scat_quantity="",
        name="",
        metadata={},
    ):

        self._id = uuid.uuid4()
        self.input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata)

Here, User needs to provide xarray, yarray, xtype and wavelength. Here, xtype and wavelneght are required for the self._set_xarrays(xarray, xtype) method within input_data where we utilize self.wavelength and self.xtype as shown below:

    def _set_xarrays(self, xarray, xtype):
        self._all_arrays = np.empty(shape=(len(xarray), 4))
        if xtype.lower() in QQUANTITIES:
            self._all_arrays[:, 1] = xarray
            self._all_arrays[:, 2] = q_to_tth(xarray, self.wavelength)
            self._all_arrays[:, 3] = q_to_d(xarray)
    ....

@sbillinge I have a draft PR here: #228 for this implementation.

@sbillinge
Copy link
Contributor

I think that's about right, and I think we want input_arrays to be private.

We don't want wavelength required though. Set default to none. I think we handle that in thighs arrays. Also, pretty soon Caden will need tof neutron data in the DO and then angle is fixed and lamba is in the array....

Actually, kind of interestingly, because he has lots of detectors, angle and wavelength could both be arrays. Let's leave that for a nice future project for Caden, but for now make wavelength optional.

@bobleesj
Copy link
Contributor Author

bobleesj commented Dec 14, 2024

Noted:

  • Make input_arrays private
  • Wavelength optional, default to None

We don't want wavelength required though. Set default to none. I think we handle that in thighs arrays. Also, pretty soon Caden will need tof neutron data in the DO and then angle is fixed and lamba is in the array....

Actually, kind of interestingly, because he has lots of detectors, angle and wavelength could both be arrays. Let's leave that for a nice future project for Caden, but for now make wavelength optional.

@cadenmyers13 Hi Caden, keeping you in the loop since you've expressed an interest before. We are still refactoring and trying to have 3.6.0 release for diffpy.utils. But keeping you in the loop on how diffpy.utils can be used for all kinds of diffraction data.

@bobleesj bobleesj changed the title Do not allow an empty instance of DiffractionObject - init with xarray, yarray, xtype, and wavelenght Do not allow an empty instance of DiffractionObject - init with xarray, yarray, xtype Dec 14, 2024
@bobleesj bobleesj changed the title Do not allow an empty instance of DiffractionObject - init with xarray, yarray, xtype Do not allow an empty instance of DiffractionObject - init requires xarray, yarray, xtype Dec 14, 2024
@bobleesj bobleesj added this to the 3.6.0 release milestone Dec 16, 2024
@bobleesj bobleesj self-assigned this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants