Skip to content

Commit

Permalink
use data container
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Sep 25, 2024
1 parent 0720961 commit a2dc7c1
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import json
import os
from pathlib import Path
from typing import List

from easyscience.fitting import AvailableMinimizers

from easyreflectometry.data.data_store import DataSet1D
from easyreflectometry.model import ModelCollection
from easyreflectometry.sample import MaterialCollection

Expand All @@ -17,7 +19,7 @@ def __init__(self):
self._materials: MaterialCollection = None
self._calculator = None
self._minimizer: AvailableMinimizers = None
self._experiments = None
self._experiments: List[DataSet1D] = None
self._report = None

# Project flags
Expand Down Expand Up @@ -70,7 +72,7 @@ def _construct_project_dict(self, include_materials_not_in_model=False):

project_dict['colors'] = self.parent._model_proxy._colors

def _add_materials_not_in_model_dict(self, project_json: dict):
def _add_materials_not_in_model_dict(self, project_dict: dict):
materials_in_model = []
for model in self._models:
for assembly in model.sample:
Expand All @@ -80,19 +82,19 @@ def _add_materials_not_in_model_dict(self, project_json: dict):
for material in self._materials:
if material not in materials_in_model:
materials_not_in_model.append(material)
project_json['materials_not_in_model'] = MaterialCollection(materials_not_in_model).as_dict(skip=['interface'])
project_dict['materials_not_in_model'] = MaterialCollection(materials_not_in_model).as_dict(skip=['interface'])

def _add_experiments_to_dict(self, project_json: dict):
project_json['experiments'] = []
project_json['experiments_models'] = []
project_json['experiments_names'] = []
def _add_experiments_to_dict(self, project_dict: dict):
project_dict['experiments'] = []
project_dict['experiments_models'] = []
project_dict['experiments_names'] = []
for experiment in self._experiments:
if self._experiments[0].xe is not None:
project_json['experiments'].append([experiment.x, experiment.y, experiment.ye, experiment.xe])
project_dict['experiments'].append([experiment.x, experiment.y, experiment.ye, experiment.xe])
else:
project_json['experiments'].append([experiment.x, experiment.y, experiment.ye])
project_json['experiments_models'].append(experiment.model.name)
project_json['experiments_names'].append(experiment.name)
project_dict['experiments'].append([experiment.x, experiment.y, experiment.ye])
project_dict['experiments_models'].append(experiment.model.name)
project_dict['experiments_names'].append(experiment.name)

def _extract_project_dict(self, project_dict):
self._models = ModelCollection.from_dict(project_dict['models'])
Expand All @@ -104,14 +106,17 @@ def _extract_project_dict(self, project_dict):
self._experiments = self._extract_experiments_from_dict(project_dict)
self._materials = MaterialCollection.from_dict(project_dict['materials'])

def _extracy_experiments_from_dict(self, project_json: dict):
project_json['experiments'] = []
project_json['experiments_models'] = []
project_json['experiments_names'] = []
for experiment in self._experiments:
if self._experiments[0].xe is not None:
project_json['experiments'].append([experiment.x, experiment.y, experiment.ye, experiment.xe])
else:
project_json['experiments'].append([experiment.x, experiment.y, experiment.ye])
project_json['experiments_models'].append(experiment.model.name)
project_json['experiments_names'].append(experiment.name)
def _extract_experiments_from_dict(self, project_dict: dict):
self._experiments: List[DataSet1D] = []

for i in range(len(project_dict['experiments'])):
self._experiments.append(
DataSet1D(
name=project_dict['experiments_names'][i],
x=project_dict['experiments'][i][0],
y=project_dict['experiments'][i][1],
ye=project_dict['experiments'][i][2],
xe=project_dict['experiments'][i][3],
model=self._models[project_dict['experiments_models'][i]],
)
)

0 comments on commit a2dc7c1

Please sign in to comment.