Description
Problem
Our DiffractionObject
contains the following methods that are not currently being used:
set_angles_from_list
, set_angles_from
, set_qs_from_range
:
def set_angles_from_list(self, angles_list):
self.angles = angles_list
self.n_steps = len(angles_list) - 1.0
self.begin_angle = self.angles[0]
self.end_angle = self.angles[-1]
def set_qs_from_range(self, begin_q, end_q, step_size=None, n_steps=None):
"""
create an array of linear spaced Q-values
Parameters
----------
begin_q float
the beginning angle
end_q float
the ending angle
step_size float
the size of the step between points. Only specify step_size or n_steps, not both
n_steps integer
the number of steps. Odd numbers are preferred. Only specify step_size or n_steps, not both
Returns
-------
Sets self.qs
self.qs array of floats
the q values in the independent array
"""
self.qs = self._set_array_from_range(begin_q, end_q, step_size=step_size, n_steps=n_steps)
def set_angles_from_range(self, begin_angle, end_angle, step_size=None, n_steps=None):
"""
create an array of linear spaced angle-values
Parameters
----------
begin_angle float
the beginning angle
end_angle float
the ending angle
step_size float
the size of the step between points. Only specify step_size or n_steps, not both
n_steps integer
the number of steps. Odd numbers are preferred. Only specify step_size or n_steps, not both
Returns
-------
Sets self.angles
self.angles array of floats
the q values in the independent array
"""
self.angles = self._set_array_from_range(begin_angle, end_angle, step_size=step_size, n_steps=n_steps)
def _set_array_from_range(self, begin, end, step_size=None, n_steps=None):
if step_size is not None and n_steps is not None:
print(
"WARNING: both step_size and n_steps have been given. n_steps will be used and step_size will be "
"reset."
)
array = np.linspace(begin, end, n_steps)
elif step_size is not None:
array = np.arange(begin, end, step_size)
elif n_steps is not None:
array = np.linspace(begin, end, n_steps)
return array
The above methods could be used for the following UCs in mind written by @sbillinge below:
- crystallographer wants to generate an x-array on a grid
- crystallogrpher (cr) inputs, start, stop, step, xtype
- DO creates xtype-array on this grid, and populates the other x-grids automatically.
I am not sure how this will be used tbh because there needs to be a yarray and this needs a matching xarray, so maybe we don't need this. But if there is already a yarray and the person wants everything on a different grid, a UC would be
- cr instantiates a DO with and xarray and a yarray and an xtype
- cr wants it on a different xarray
- cr supplies start, stop, step xtype
- DO generates new xarrays on this grid
- DO interpolates the yarray onto this grid and replaces the old yarray with this one
Again, I wonder actually how useful this would be. Maybe it is better to put it into an issue and leave it in case someone asks for it. The same would go for other ways to generate arrays.
Originally posted by @sbillinge in #188 (comment)
Proposed solution
As written above, it would be better to make an issue here and address the above needs once User asks for this specific feature.