Skip to content

Commit

Permalink
fixed diffraction_objects class name
Browse files Browse the repository at this point in the history
  • Loading branch information
Alison Wu authored and Alison Wu committed Nov 7, 2024
1 parent 79a2f1e commit 2c364fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/diffpy/utils/scattering_objects/diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)


class diffraction_object:
class DiffractionObject:
def __init__(self, name="", wavelength=None):
self.name = name
self.wavelength = wavelength
Expand All @@ -29,7 +29,7 @@ def __init__(self, name="", wavelength=None):
self.metadata = {}

def __eq__(self, other):
if not isinstance(other, diffraction_object):
if not isinstance(other, DiffractionObject):
return NotImplemented
self_attributes = [key for key in self.__dict__ if not key.startswith("_")]
other_attributes = [key for key in other.__dict__ if not key.startswith("_")]
Expand Down Expand Up @@ -59,8 +59,8 @@ def __add__(self, other):
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
summed.on_tth[1] = self.on_tth[1] + other
summed.on_q[1] = self.on_q[1] + other
elif not isinstance(other, diffraction_object):
raise TypeError("I only know how to sum two Diffraction_object objects")
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to sum two DiffractionObject objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
else:
Expand All @@ -73,7 +73,7 @@ def __radd__(self, other):
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
summed.on_tth[1] = self.on_tth[1] + other
summed.on_q[1] = self.on_q[1] + other
elif not isinstance(other, diffraction_object):
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to sum two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
Expand All @@ -87,7 +87,7 @@ def __sub__(self, other):
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
subtracted.on_tth[1] = self.on_tth[1] - other
subtracted.on_q[1] = self.on_q[1] - other
elif not isinstance(other, diffraction_object):
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to subtract two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
Expand All @@ -101,7 +101,7 @@ def __rsub__(self, other):
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
subtracted.on_tth[1] = other - self.on_tth[1]
subtracted.on_q[1] = other - self.on_q[1]
elif not isinstance(other, diffraction_object):
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to subtract two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
Expand All @@ -115,7 +115,7 @@ def __mul__(self, other):
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
multiplied.on_tth[1] = other * self.on_tth[1]
multiplied.on_q[1] = other * self.on_q[1]
elif not isinstance(other, diffraction_object):
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to multiply two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
Expand All @@ -141,7 +141,7 @@ def __truediv__(self, other):
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
divided.on_tth[1] = other / self.on_tth[1]
divided.on_q[1] = other / self.on_q[1]
elif not isinstance(other, diffraction_object):
elif not isinstance(other, DiffractionObject):
raise TypeError("I only know how to multiply two Scattering_object objects")
elif self.on_tth[0].all() != other.on_tth[0].all():
raise RuntimeError(x_grid_emsg)
Expand Down Expand Up @@ -389,7 +389,7 @@ def scale_to(self, target_diff_object, xtype=None, xvalue=None):
Parameters
----------
target_diff_object: Diffraction_object
target_diff_object: DiffractionObject
the diffractoin object you want to scale the current one on to
xtype: string, optional. Default is Q
the xtype, from {XQUANTITIES}, that you will specify a point from to scale to
Expand All @@ -400,7 +400,7 @@ def scale_to(self, target_diff_object, xtype=None, xvalue=None):
Returns
-------
the rescaled Diffraction_object as a new object
the rescaled DiffractionObject as a new object
"""
scaled = deepcopy(self)
Expand Down Expand Up @@ -454,7 +454,7 @@ def dump(self, filepath, xtype=None):

with open(filepath, "w") as f:
f.write(
f"[Diffraction_object]\nname = {self.name}\nwavelength = {self.wavelength}\n"
f"[DiffractionObject]\nname = {self.name}\nwavelength = {self.wavelength}\n"
f"scat_quantity = {self.scat_quantity}\n"
)
for key, value in self.metadata.items():
Expand Down
10 changes: 5 additions & 5 deletions tests/test_diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from freezegun import freeze_time

from diffpy.utils.scattering_objects.diffraction_objects import diffraction_object
from diffpy.utils.scattering_objects.diffraction_objects import DiffractionObject

params = [
( # Default
Expand Down Expand Up @@ -222,8 +222,8 @@

@pytest.mark.parametrize("inputs1, inputs2, expected", params)
def test_diffraction_objects_equality(inputs1, inputs2, expected):
diffraction_object1 = diffraction_object()
diffraction_object2 = diffraction_object()
diffraction_object1 = DiffractionObject()
diffraction_object2 = DiffractionObject()
diffraction_object1_attributes = [key for key in diffraction_object1.__dict__ if not key.startswith("_")]
for i, attribute in enumerate(diffraction_object1_attributes):
setattr(diffraction_object1, attribute, inputs1[i])
Expand All @@ -235,7 +235,7 @@ def test_dump(tmp_path, mocker):
x, y = np.linspace(0, 5, 6), np.linspace(0, 5, 6)
directory = Path(tmp_path)
file = directory / "testfile"
test = diffraction_object()
test = DiffractionObject()
test.wavelength = 1.54
test.name = "test"
test.scat_quantity = "x-ray"
Expand All @@ -251,7 +251,7 @@ def test_dump(tmp_path, mocker):
with open(file, "r") as f:
actual = f.read()
expected = (
"[Diffraction_object]\nname = test\nwavelength = 1.54\nscat_quantity = x-ray\nthing1 = 1\n"
"[DiffractionObject]\nname = test\nwavelength = 1.54\nscat_quantity = x-ray\nthing1 = 1\n"
"thing2 = thing2\npackage_info = {'package2': '3.4.5', 'diffpy.utils': '3.3.0'}\n"
"creation_time = 2012-01-14 00:00:00\n\n"
"#### start data\n0.000000000000000000e+00 0.000000000000000000e+00\n"
Expand Down

0 comments on commit 2c364fc

Please sign in to comment.