Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 3, 2025
1 parent d9773aa commit 0d08137
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
49 changes: 36 additions & 13 deletions src/hyspecppt/hppt/hppt_model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Model for the polarization planning tool"""
import numpy as np

import logging

import numpy as np

logger = logging.getLogger("hyspecppt")


class SingleCrystalParameters:
"""Model for single crystal calculations"""

a: float
b: float
c: float
Expand All @@ -22,7 +25,7 @@ def __init__(self) -> None:
return

def set_parameters(self, params: dict[str, float]) -> None:
"""store single crystal parameters
"""Store single crystal parameters
Args:
params: dict - contains the following keys:
Expand All @@ -40,14 +43,24 @@ def set_parameters(self, params: dict[str, float]) -> None:
self.l = params["l"]

def get_paramters(self) -> dict[str, float]:
"""returns all the parameters as a dictionary"""
"""Returns all the parameters as a dictionary"""
try:
return dict(a=self.a, b=self.b, c=self.c, alpha=self.alpha, beta=self.beta, gamma=self.gamma, h=self.h, k=self.k, l=self.l)
return dict(
a=self.a,
b=self.b,
c=self.c,
alpha=self.alpha,
beta=self.beta,
gamma=self.gamma,
h=self.h,
k=self.k,
l=self.l,
)
except AttributeError:
logger.error("The parameters were not initialized")

def calculate_modQ(self) -> float:
"""returns |Q| from lattice parameters and h, k, l"""
"""Returns |Q| from lattice parameters and h, k, l"""
try:
ca = np.cos(np.radians(self.alpha))
sa = np.sin(np.radians(self.alpha))
Expand Down Expand Up @@ -80,17 +93,24 @@ def calculate_modQ(self) -> float:

class CrosshairParameters:
"""Model for the crosshair parameters"""

modQ: float
DeltaE: float
current_experiment_type: str
sc_parameters: SingleCrystalParameters

def __init__(self):
self.sc_parameters=SingleCrystalParameters()

def store_data(self, *, current_experiment_type: str = None, DeltaE: float = None,
modQ: float = None, sc_parameters:dict[str, float] = None) -> None:
"""store crosshair parameters including in SC mode"""
self.sc_parameters = SingleCrystalParameters()

def store_data(
self,
*,
current_experiment_type: str = None,
DeltaE: float = None,
modQ: float = None,
sc_parameters: dict[str, float] = None,
) -> None:
"""Store crosshair parameters including in SC mode"""
if current_experiment_type is not None:
self.current_experiment_type = current_experiment_type
if DeltaE is not None:
Expand All @@ -101,14 +121,15 @@ def store_data(self, *, current_experiment_type: str = None, DeltaE: float = Non
self.sc_parameters.set_parameters(sc_parameters)

def get_crosshair(self) -> dict[str, float]:
"""get the crosshair"""
"""Get the crosshair"""
if self.current_experiment_type == "crystal":
self.modQ = self.sc_parameters.calculate_modQ()
return dict(DeltaE=self.DeltaE, modQ=self.modQ)


class HyspecPPTModel:
"""Main model"""

Ei: float = 0
S2: float = 0
alpha_p: float = 0
Expand All @@ -125,7 +146,9 @@ def store_experiment_data(self, Ei: float, S2: float, alpha_p: float, plot_type:
self.alpha_p = alpha_p
self.plot_type = plot_type

def store_crosshair_data(self, *, current_experiment_type: str = None, DeltaE: float = None, modQ: float = None) -> None:
def store_crosshair_data(
self, *, current_experiment_type: str = None, DeltaE: float = None, modQ: float = None
) -> None:
self.cp.store_data(current_experiment_type=current_experiment_type, DeltaE=DeltaE, modQ=modQ)

def store_single_crystal_data(self, params: dict[str, float]) -> None:
Expand All @@ -135,4 +158,4 @@ def get_crosshair(self) -> dict[str, float]:
return self.cp.get_crosshair()

def calculate_graph_data(self):
return [1,2,3]
return [1, 2, 3]
24 changes: 12 additions & 12 deletions src/hyspecppt/hppt/hppt_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ def __init__(self, view: "[QWidget]", model: "[QWidget]"):
"""
self._view = view
self._model = model
#initialize widgets
# initialize widgets
self.view.EW.initializeCombo(PLOT_TYPES)
self.view.EW.set_values(DEFAULT_EXPERIMENT)
self.view.CW.set_values(DEFAULT_CROSSHAIR)
self.view.SCW.set_values(DEFAULT_LATTICE)
#select calculation mode
# select calculation mode
self.view.SelW.set_SC_toggle(True)
#initialize model
# initialize model
self.model.store_experiment_data(**DEFAULT_EXPERIMENT)
self.model.store_crosshair_data(current_experiment_type="crystal", **DEFAULT_CROSSHAIR)
self.model.store_single_crystal_data(DEFAULT_LATTICE)

#connections
# connections
self.view.EW.valid_signal.connect(self.update_experiment_values)
self.view.SelW.sc_rb.toggled.connect(self.q_mode_SC)
self.view.SelW.powder_rb.toggled.connect(self.q_mode_powder)
Expand All @@ -45,15 +45,15 @@ def model(self):
return self._model

def q_mode_powder(self) -> None:
"""switch to powder mode"""
self.model.store_crosshair_data(current_experiment_type='powder')
"""Switch to powder mode"""
self.model.store_crosshair_data(current_experiment_type="powder")
crosshair = self.model.get_crosshair()
self.view.CW.set_values(crosshair)
self.set_PlotWidget_values(cursor_position=crosshair)

def q_mode_SC(self) -> None:
"""switch to crystal"""
self.model.store_crosshair_data(current_experiment_type='crystal')
"""Switch to crystal"""
self.model.store_crosshair_data(current_experiment_type="crystal")
crosshair = self.model.get_crosshair()
self.view.CW.set_values(crosshair)
self.set_PlotWidget_values(cursor_position=crosshair)
Expand All @@ -62,11 +62,11 @@ def update_experiment_values(self, new_values: dict[str, float]) -> None:
"""Ei/S2/alpha_p/plot_type update"""
self.model.store_experiment_data(**new_values)
new_intensity = self.model.calculate_graph_data()
self.set_PlotWidget_values(intensity = new_intensity)
self.set_PlotWidget_values(intensity=new_intensity)

def update_cursor_values(self, new_values: dict[str, float]) -> None:
"""DeltaE/modQ update"""
#TODO: check on DeltaE<-Ei
# TODO: check on DeltaE<-Ei
self.model.store_crosshair_data(**new_values)
self.set_PlotWidget_values(cursor_position=new_values)

Expand All @@ -76,6 +76,6 @@ def update_SC_values(self, new_values: dict[str, float]) -> None:
self.view.CW.set_values(new_position)
self.set_PlotWidget_values(cursor_position=new_position)

def set_PlotWidget_values(self, intensity = "new_intensity", cursor_position = "new_position", label="new_label"):
def set_PlotWidget_values(self, intensity="new_intensity", cursor_position="new_position", label="new_label"):
"""Pass through intensity matrix into plot in view"""
print('call plot:', intensity, cursor_position, label)
print("call plot:", intensity, cursor_position, label)
2 changes: 1 addition & 1 deletion src/hyspecppt/hppt/hppt_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def validate_all_inputs(self):
out_signal[k] = float(edit.text())

if len(out_signal) == 9:
print('sc view emmit')
print("sc view emmit")
self.valid_signal.emit(out_signal)


Expand Down

0 comments on commit 0d08137

Please sign in to comment.