Skip to content

Commit

Permalink
chagne plot results to universal key workd "intensity" and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleQianliMa committed Jan 16, 2025
1 parent a403058 commit 7666585
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/hyspecppt/hppt/hppt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ def calculate_graph_data(self) -> list[float]:
Q_hi = np.sqrt(ki**2 + kf**2 - 2 * ki * kf * np.cos(np.radians(np.abs(self.S2) + 30)))

if self.plot_type == PLOT_TYPES[0]: # alpha
return dict(Q_low=Q_low, Q_hi=Q_hi, E=E, Q2d=Q2d, E2d=E2d, ang_PQ=ang_PQ)
return dict(Q_low=Q_low, Q_hi=Q_hi, E=E, Q2d=Q2d, E2d=E2d, intensity=ang_PQ)

if self.plot_type == PLOT_TYPES[1]: # cos^2(alpha)
return dict(Q_low=Q_low, Q_hi=Q_hi, E=E, Q2d=Q2d, E2d=E2d, cos2_ang_PQ=np.cos(np.radians(ang_PQ)) ** 2)
return dict(Q_low=Q_low, Q_hi=Q_hi, E=E, Q2d=Q2d, E2d=E2d, intensity=np.cos(np.radians(ang_PQ)) ** 2)

if self.plot_type == PLOT_TYPES[2]: # "(cos^2(a)+1)/2"
return dict(
Expand All @@ -239,7 +239,7 @@ def calculate_graph_data(self) -> list[float]:
E=E,
Q2d=Q2d,
E2d=E2d,
cos2_ang_PQ_plus_1_div_2=(np.cos(np.radians(ang_PQ)) ** 2 + 1) / 2,
intensity=(np.cos(np.radians(ang_PQ)) ** 2 + 1) / 2,
)
except AttributeError:
logger.error("The parameters were not initialized")
32 changes: 16 additions & 16 deletions tests/hppt_model/test_hyspecpptmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def test_calculate_graph_data_alpha():
assert np.isclose(model.calculate_graph_data()["E2d"][0][0], -20)
assert np.isclose(model.calculate_graph_data()["E2d"][0][199], 18.0)

assert np.isnan(model.calculate_graph_data()["ang_PQ"][0][0]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["ang_PQ"][84][4]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][0][0]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][84][4]) # not allowed (Q, E) positions

assert np.isclose(model.calculate_graph_data()["ang_PQ"][84][5], 166.59943)
assert np.isclose(model.calculate_graph_data()["ang_PQ"][199][0], 114.73561)
assert np.isnan(model.calculate_graph_data()["ang_PQ"][199][1]) # not allowed (Q, E) positions
assert np.isclose(model.calculate_graph_data()["intensity"][84][5], 166.59943)
assert np.isclose(model.calculate_graph_data()["intensity"][199][0], 114.73561)
assert np.isnan(model.calculate_graph_data()["intensity"][199][1]) # not allowed (Q, E) positions


def test_calculate_graph_data_cos2_alpha():
Expand All @@ -109,15 +109,15 @@ def test_calculate_graph_data_cos2_alpha():
assert np.isclose(model.calculate_graph_data()["E2d"][0][0], -20)
assert np.isclose(model.calculate_graph_data()["E2d"][0][199], 18.0)

assert np.isnan(model.calculate_graph_data()["cos2_ang_PQ"][0][0]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["cos2_ang_PQ"][84][4]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][0][0]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][84][4]) # not allowed (Q, E) positions

assert np.isclose(model.calculate_graph_data()["cos2_ang_PQ"][84][5], np.cos(np.radians(166.59943)) ** 2)
assert np.isclose(model.calculate_graph_data()["cos2_ang_PQ"][199][0], np.cos(np.radians(114.73561)) ** 2)
assert np.isnan(model.calculate_graph_data()["cos2_ang_PQ"][199][1]) # not allowed (Q, E) positions
assert np.isclose(model.calculate_graph_data()["intensity"][84][5], np.cos(np.radians(166.59943)) ** 2)
assert np.isclose(model.calculate_graph_data()["intensity"][199][0], np.cos(np.radians(114.73561)) ** 2)
assert np.isnan(model.calculate_graph_data()["intensity"][199][1]) # not allowed (Q, E) positions


def test_calculate_graph_data_cos2_ang_PQ_plus_1_div_2():
def test_calculate_graph_data_intensity():
"""Test calculating different graph data"""
model = HyspecPPTModel()
model.set_experiment_data(Ei=20.0, S2=60.0, alpha_p=30.0, plot_type=PLOT_TYPES[2])
Expand All @@ -137,16 +137,16 @@ def test_calculate_graph_data_cos2_ang_PQ_plus_1_div_2():
assert np.isclose(model.calculate_graph_data()["E2d"][0][0], -20)
assert np.isclose(model.calculate_graph_data()["E2d"][0][199], 18.0)

assert np.isnan(model.calculate_graph_data()["cos2_ang_PQ_plus_1_div_2"][0][0]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["cos2_ang_PQ_plus_1_div_2"][84][4]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][0][0]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][84][4]) # not allowed (Q, E) positions

assert np.isclose(
model.calculate_graph_data()["cos2_ang_PQ_plus_1_div_2"][84][5], (np.cos(np.radians(166.59943)) ** 2 + 1) / 2
model.calculate_graph_data()["intensity"][84][5], (np.cos(np.radians(166.59943)) ** 2 + 1) / 2
)
assert np.isclose(
model.calculate_graph_data()["cos2_ang_PQ_plus_1_div_2"][199][0], (np.cos(np.radians(114.73561)) ** 2 + 1) / 2
model.calculate_graph_data()["intensity"][199][0], (np.cos(np.radians(114.73561)) ** 2 + 1) / 2
)
assert np.isnan(model.calculate_graph_data()["cos2_ang_PQ_plus_1_div_2"][199][1]) # not allowed (Q, E) positions
assert np.isnan(model.calculate_graph_data()["intensity"][199][1]) # not allowed (Q, E) positions


def test_DeltaE_less_than_negative_Ei():
Expand Down

0 comments on commit 7666585

Please sign in to comment.