-
Notifications
You must be signed in to change notification settings - Fork 2
Adoption to new easyscience (fitting, parameter unique name #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
fad0e66
4d42e74
fc815c8
1817d3a
49ff36a
a3f5ffe
fb6f968
8042883
6640d72
e00e73f
c7e7882
1f5d0eb
489d01e
8221830
23fd48e
806de85
8ae034b
54d6382
4b45d63
b666d0f
4a7db8d
18718b8
4dae7fd
c66f1cd
a13dc0b
444d975
e5ba9c9
c7bfaf6
1750d92
f812cfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
__author__ = 'github.com/arm61' | ||
|
||
from typing import List | ||
from typing import Optional | ||
|
||
from easyreflectometry.sample.base_element_collection import SIZE_DEFAULT_COLLECTION | ||
|
@@ -19,13 +20,20 @@ def __init__( | |
*models: Optional[tuple[Model]], | ||
name: str = 'EasyModels', | ||
interface=None, | ||
populate_if_none: bool = True, | ||
**kwargs, | ||
): | ||
if not models: | ||
models = [Model(interface=interface) for _ in range(SIZE_DEFAULT_COLLECTION)] | ||
if populate_if_none: | ||
models = [Model(interface=interface) for _ in range(SIZE_DEFAULT_COLLECTION)] | ||
else: | ||
models = [] | ||
super().__init__(name, interface, *models, **kwargs) | ||
self.interface = interface | ||
|
||
# Needed by the as_dict functionality | ||
self.populate_if_none = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no description of this boolean. Why is it needed in as_dict? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added code comment: |
||
|
||
def add_model(self, new_model: Model): | ||
""" | ||
Add a model to the models. | ||
|
@@ -42,6 +50,11 @@ def remove_model(self, idx: int): | |
""" | ||
del self[idx] | ||
|
||
def as_dict(self, skip: List[str] | None = None) -> dict: | ||
this_dict = super().as_dict(skip) | ||
this_dict['populate_if_none'] = self.populate_if_none | ||
return this_dict | ||
|
||
@classmethod | ||
def from_dict(cls, this_dict: dict) -> ModelCollection: | ||
""" | ||
|
@@ -50,11 +63,17 @@ def from_dict(cls, this_dict: dict) -> ModelCollection: | |
:param data: The dictionary for the collection | ||
:return: An instance of the collection | ||
""" | ||
collection = super().from_dict(this_dict) # type: ModelCollection | ||
collection_dict = this_dict.copy() | ||
# We neeed to call from_dict on the base class to get the models | ||
dict_data = collection_dict['data'] | ||
del collection_dict['data'] | ||
|
||
collection = super().from_dict(collection_dict) # type: ModelCollection | ||
|
||
for model_data in dict_data: | ||
collection.add_model(Model.from_dict(model_data)) | ||
|
||
if len(collection) != len(this_dict['data']): | ||
raise ValueError(f"Expected {len(collection)} models, got {len(this_dict['data'])}") | ||
for i, model_data in enumerate(this_dict['data']): | ||
collection[i] = Model.from_dict(model_data) | ||
|
||
return collection |
Uh oh!
There was an error while loading. Please reload this page.