Skip to content

Commit

Permalink
hsypec start files updated, model class design, environment with late…
Browse files Browse the repository at this point in the history
…st matplotlib and Pyside6 error resolved
  • Loading branch information
mpatrou committed Dec 2, 2024
1 parent 18fb5d2 commit 77b13f4
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 46 deletions.
272 changes: 242 additions & 30 deletions docs/source/design/hyspecpptclasses.rst
Original file line number Diff line number Diff line change
@@ -1,56 +1,268 @@
.. _hyspecpptclasses:

Model-View-Presenter
=====================
######################




HyspecPPT Model
----------------
+++++++++++++++

The HyspecPPTModel encapsulates the backend functionality. It maintains one object: sample (Sample) that has all the valid-calculated values. The object fields are updated
every time there are new valid values received from the user (front end).

.. mermaid::

classDiagram
HyspecPPTModel <|-- SingleCrystalModel
HyspecPPTModel <|-- PowderModel
HyspecPPTModel <|-- Sample
Sample "1" -->"1" SingleCrystalParameters

class HyspecPPTModel{
<<Abstract>>
+Double incident_energy_e
+Double detector_tank_angle_s
+Double polarization_direction_angle_p
+Double delta_e
+Double mod_q
+Option graph_type
+Sample sample
}

class Sample{
+str current_sample_type
+float incident_energy_e
+float detector_tank_angle_s
+float polarization_direction_angle_p
+float delta_e
+float mod_q
+str graph_type
+SingleCrystalParameters sc_parameters
+calculate_graph_data()
+get_model_data()
+get_data()
+store_data()

-get_emin(delta_e, incident_energy_e)
-calculate_qmod()
-calculate_crosshair()
}

class SingleCrystalModel{
+Double single_crystal_a
+Double single_crystal_b
+Double single_crystal_c
+Double single_crystal_alpha
+Double single_crystal_beta
+Double single_crystal_gamma
+String single_crystal_h
+String single_crystal_k
+String single_crystal_l
+calculate_qmod()
+get_single_crystal_data()
class SingleCrystalParameters{
+float lattice_a
+float lattice_b
+float lattice_c
+float lattice_alpha
+float lattice_beta
+float lattice_gamma
+str lattice unit_h
+str lattice unit_k
+str lattice unit_l
+get_parameters()
+set_paraeters()
}

class PowderModel{
<>
}
Default Values
----------------

The parameters' default values for each Sample object are stored in a file, e.g sample_default.py, next to the model file. They are imported
in the HyspecPPT Model file and used during the Sample objects' initialization and data calculations.
More specifically the parameters with their values are:

* sample_type = "Powder"
* incident_energy_e = 20
* detector_tank_angle_s = 30
* polarization_direction_angle_p = 0
* delta_e = 0
* mod_q = 0
* lattice_a = 1
* lattice_b = 1
* lattice_c = 1
* lattice_alpha = 90
* lattice_beta = 90
* lattice_gamma = 90
* lattice unit_h = 0
* lattice unit_k = 0
* lattice unit_l = 0
* number_of_pixels = 200

Functions
-------------

The function signatures and description are included below.

-- Sample

* def calculate_graph_data(Dict data) --> Dict : The function receives data parameters, updates the sample object's field values and calculates and returns the plot data. The incoming data have the following format: e.g.
.. code-block:: bash
{
"current_sample_type": "SingleCrystal",
"incident_energy_e": <e>,
"detector_tank_angle_s" : <s2>,
"polarization_direction_angle_p" :<ao>,
"delta_e": <d_e>,
"mod_q" : <m_q>,
"graph_type" : <g_a>,
"sc_parametes" :
{
"lattice_a":<a>,
"lattice_b":<b>,
"lattice_c":<c>,
"lattice_alpha":<alpha>,
"lattice_beta":<beta>,
"lattice_gamma":<gamma>,
"lattice unit_h":<h>,
"lattice unit_k":<k>,
"lattice unit_l":<l>
}
}
In case of Powder mode the sc_parameters are not populated/included in the data dictionary and the sc_parametes is ignored for model data update e.g.:
.. code-block:: bash
{
"current_sample_type": "Powder",
"incident_energy_e": <e>,
"detector_tank_angle_s" : <s2>,
"polarization_direction_angle_p" :<ao>,
"delta_e": <d_e>,
"mod_q" : <m_q>,
"graph_type" : <g_a>,
"sc_parametes" : {}
}
The data structure is similar to the ones used in get_data() and set_data() for consistency.
Internally store_data() is called to store the parameters, and for the Single Crystal case calculate_qmod() and calculate_crosshair are called to find qmod and crosshair values respectively.
The data dictionary created for the plot have the following format:

.. code-block:: bash
{
"q_min": [], //1-d array
"q_max": [], //1-d array
"energy_transfer" : [], //1-d array
"q2d" :[[],], //2-d array
"e2d" :[[],], //2-d array
"scharf_angle" :[[],], //2-d array
"crosshair": { "x": <>, "y":<>}
}
* def get_data() --> Dict : The function returns all the sample's parameters in a dictionary format regardless the of the sample type e.g:
.. code-block:: bash
{
"current_sample_type": <sample_type>,
"incident_energy_e": <e>,
"detector_tank_angle_s" : <s2>,
"polarization_direction_angle_p" :<ao>,
"delta_e": <d_e>,
"mod_q" : <m_q>,
"graph_type" : <g_a>,
"sc_parametes" :
{
"lattice_a":<a>,
"lattice_b":<b>,
"lattice_c":<c>,
"lattice_alpha":<alpha>,
"lattice_beta":<beta>,
"lattice_gamma":<gamma>,
"lattice unit_h":<h>,
"lattice unit_k":<k>,
"lattice unit_l":<l>
}
}
The function can be called by the Presenter, in order to update the View with the memory-stored values.
* def store_data(Dict data) --> None : The function receives data parameters and updates the sample object's field values. The dictionary format is similar to get_data return value e.g.:
.. code-block:: bash
{
"current_sample_type": "SingleCrystal",
"incident_energy_e": <e>,
"detector_tank_angle_s" : <s2>,
"polarization_direction_angle_p" :<ao>,
"delta_e": <d_e>,
"mod_q" : <m_q>,
"graph_type" : <g_a>,
"sc_parametes" :
{
"lattice_a":<a>,
"lattice_b":<b>,
"lattice_c":<c>,
"lattice_alpha":<alpha>,
"lattice_beta":<beta>,
"lattice_gamma":<gamma>,
"lattice unit_h":<h>,
"lattice unit_k":<k>,
"lattice unit_l":<l>
}
}
In case of Powder mode the sc_parameters are not populated/included in the data dictionary and the sc_parametes is ignored for model data update e.g.:
.. code-block:: bash
{
"current_sample_type": "Powder",
"incident_energy_e": <e>,
"detector_tank_angle_s" : <s2>,
"polarization_direction_angle_p" :<ao>,
"delta_e": <d_e>,
"mod_q" : <m_q>,
"graph_type" : <g_a>,
"sc_parametes" : {}
}
* get_emin(delta_e, incident_energy_e) --> float : The function returns the e_min value, based on delta_e and incident_energy_e. If delta_e < -incident_energy_e, then e_min =1.2* delta_e, else e_min = delta_e.
* calculate_qmod() --> float : The function returns qmod. It calculates the value from the sc_parametes (SingleCrystal mode).
* calculate_crosshair() --> dict : The function calculates the crosshair x and y float values from the sc_parametes (SingleCrystal mode). The following format is returned:
.. code-block:: bash
{
"x": <x>,
"y": <y>
}
The get_emin and calculate_qmod functions are only used internally in the Sample Model.
-- SingleCrystalParameters
* def get_parameters(dict sc_data) --> None : The function updates the SingleCrystalParameters with the sc_data, provided in the following format e.g:
.. code-block:: bash
{
"lattice_a":<a>,
"lattice_b":<b>,
"lattice_c":<c>,
"lattice_alpha":<alpha>,
"lattice_beta":<beta>,
"lattice_gamma":<gamma>,
"lattice unit_h":<h>,
"lattice unit_k":<k>,
"lattice unit_l":<l>
}
* def set_parameters() --> Dict : The function returns a dictionary with the SingleCrystalParameters field values.
.. code-block:: bash
{
"lattice_a":<a>,
"lattice_b":<b>,
"lattice_c":<c>,
"lattice_alpha":<alpha>,
"lattice_beta":<beta>,
"lattice_gamma":<gamma>,
"lattice unit_h":<h>,
"lattice unit_k":<k>,
"lattice unit_l":<l>
}
The data structure is the same in set_parameters() and get_parameters() for consistency.
HyspecPPT View
---------------
+++++++++++++++
.. mermaid::
Expand Down Expand Up @@ -114,7 +326,7 @@ HyspecPPT View
HyspecPPT Presenter
--------------------
++++++++++++++++++++++
.. mermaid::
Expand Down
7 changes: 3 additions & 4 deletions docs/source/design/hyspecpptfields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ Below are the fields of SingleCrystal and Powder sample Models
* - Delta E
- Double
-
- 0 (for Power mode)
- 0
-
- no
* - mod Q (\|Q\|)
- Double
-
- 0 (for Power mode)
- 0
- 0 <= \|Q\| <=10
- no
* - Plot Type
Expand Down Expand Up @@ -154,5 +154,4 @@ Front end side validation can include:


Backend side validation can include:
* qmod calculation
* graph data calculations
* matplotlib save figure?
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ dependencies:
- pyqt == 5.*
- qtpy
- numpy
- scipy
- matplotlib <3.9 #resolves pyside 6 error
- matplotlib #resolves pyside 6 error * !! 0we want the latest version
- pre-commit
# package building:
- versioningit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
logger = logging.getLogger("hyspecppt")


class HomeModel:
class HyspecPPTModel:
"""Main model"""

def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Presenter for the Main tab"""


class HomePresenter:
class HyspecPPTPresenter:
"""Main presenter"""

def __init__(self, view, model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from qtpy.QtWidgets import QHBoxLayout, QWidget


class Home(QWidget):
class HyspecPPTView(QWidget):
"""Main widget"""

def __init__(self, parent=None):
Expand Down
Loading

0 comments on commit 77b13f4

Please sign in to comment.