Skip to content

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

Closed
@bobleesj

Description

@bobleesj

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions