Skip to content

Commit b5b7b46

Browse files
authored
Merge pull request #72 from EasyScience/develop
Release 1.0.0
2 parents 3ace9d1 + 15c2ba1 commit b5b7b46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+454
-437
lines changed

.github/workflows/documentation-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
- name: Upgrade pip
3030
run: |
3131
python -m pip install --upgrade pip
32+
- name: Force upgrade of sphinx-rtd-theme to build documentation, not compatible with docutils 0.20.1
33+
run: |
34+
pip install --upgrade --force-reinstall sphinx-rtd-theme
3235
- name: Set up Python
3336
uses: actions/setup-python@v5
3437
with:

Examples/fitting/plot_constraints.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This example shows the usages of the different constraints.
55
"""
66

7-
from easyscience.Fitting import Constraints
7+
from easyscience.fitting import Constraints
88
from easyscience.Objects.ObjectClasses import Parameter
99

1010
p1 = Parameter('p1', 1)
@@ -15,7 +15,7 @@
1515
p1.value = value
1616
print(f'Set Value: {value}, Parameter Value: {p1}')
1717

18-
#%%
18+
# %%
1919
# To include embedded rST, use a line of >= 20 ``#``'s or ``#%%`` between your
2020
# rST and your code. This separates your example
2121
# into distinct text and code blocks. You can continue writing code below the

docs/src/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
#
9696
# This is also used if you do content translation via gettext catalogs.
9797
# Usually you set "language" from the command line for these cases.
98-
language = None
98+
language = 'en'
9999

100100
# List of patterns, relative to source directory, that match files and
101101
# directories to ignore when looking for source files.

docs/src/getting-started/installation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The easiest way of obtaining EasyScience and using it in your project is via pip
1414
$ pip install EasyScience
1515
1616
Install as an EasyScience developer
17-
--------------------------------
17+
-----------------------------------
1818

1919
You can obtain the latest development source from our `Github repository
2020
<https://github.com/easyScience/EasyScience>`_.:

docs/src/reference/base.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ Parameters and Objects
55
Descriptors
66
===========
77

8-
.. autoclass:: easyscience.Objects.Base.Descriptor
8+
.. autoclass:: easyscience.Objects.Variable.Descriptor
99
:members:
1010

1111
Parameters
1212
==========
1313

14-
.. autoclass:: easyscience.Objects.Base.Parameter
14+
.. autoclass:: easyscience.Objects.Variable.Parameter
1515
:members:
1616
:inherited-members:
1717

@@ -22,11 +22,11 @@ Super Classes and Collections
2222
Super Classes
2323
=============
2424

25-
.. autoclass:: easyscience.Objects.Base.BasedBase
25+
.. autoclass:: easyscience.Objects.ObjectClasses.BasedBase
2626
:members:
2727
:inherited-members:
2828

29-
.. autoclass:: easyscience.Objects.Base.BaseObj
29+
.. autoclass:: easyscience.Objects.ObjectClasses.BaseObj
3030
:members: +_add_component
3131
:inherited-members:
3232

examples_old/example1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55

6-
from easyscience.Fitting import Fitter
6+
from easyscience.fitting import Fitter
77
from easyscience.Objects.ObjectClasses import BaseObj
88
from easyscience.Objects.ObjectClasses import Parameter
99

examples_old/example1_dream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55

6-
from easyscience.Fitting import Fitter
6+
from easyscience.fitting import Fitter
77
from easyscience.Objects.ObjectClasses import BaseObj
88
from easyscience.Objects.ObjectClasses import Parameter
99

examples_old/example2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55

6-
from easyscience.Fitting import Fitter
6+
from easyscience.fitting import Fitter
77
from easyscience.Objects.ObjectClasses import BaseObj
88
from easyscience.Objects.ObjectClasses import Parameter
99

examples_old/example3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77

8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.ObjectClasses import BaseObj
1010
from easyscience.Objects.ObjectClasses import Parameter
1111

examples_old/example4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
from easyscience import global_object
13-
from easyscience.Fitting import Fitter
13+
from easyscience.fitting import Fitter
1414
from easyscience.Objects.core import ComponentSerializer
1515
from easyscience.Objects.ObjectClasses import BaseObj
1616
from easyscience.Objects.ObjectClasses import Parameter

examples_old/example5_broken.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010

1111
from easyscience import global_object
12-
from easyscience.Fitting import Fitter
12+
from easyscience.fitting import Fitter
1313
from easyscience.Objects.Base import BaseObj
1414
from easyscience.Objects.Base import Parameter
1515
from easyscience.Objects.core import ComponentSerializer

examples_old/example_dataset2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77
from easyscience.Datasets.xarray import xr
8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.ObjectClasses import BaseObj
1010
from easyscience.Objects.ObjectClasses import Parameter
1111

examples_old/example_dataset2pt2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77
from easyscience.Datasets.xarray import xr
8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.ObjectClasses import BaseObj
1010
from easyscience.Objects.ObjectClasses import Parameter
1111

examples_old/example_dataset2pt2_broken.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77
from easyscience.Datasets.xarray import xr
8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.Base import BaseObj
1010
from easyscience.Objects.Base import Parameter
1111

examples_old/example_dataset3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99
from easyscience.Datasets.xarray import xr
10-
from easyscience.Fitting import Fitter
10+
from easyscience.fitting import Fitter
1111
from easyscience.Objects.ObjectClasses import BaseObj
1212
from easyscience.Objects.ObjectClasses import Parameter
1313

examples_old/example_dataset3pt2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77
from easyscience.Datasets.xarray import xr
8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.ObjectClasses import BaseObj
1010
from easyscience.Objects.ObjectClasses import Parameter
1111

examples_old/example_dataset4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77
from easyscience.Datasets.xarray import xr
8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.ObjectClasses import BaseObj
1010
from easyscience.Objects.ObjectClasses import Parameter
1111

examples_old/example_dataset4_2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import numpy as np
77
from easyscience.Datasets.xarray import xr
8-
from easyscience.Fitting import Fitter
8+
from easyscience.fitting import Fitter
99
from easyscience.Objects.ObjectClasses import BaseObj
1010
from easyscience.Objects.ObjectClasses import Parameter
1111

src/easyscience/Datasets/xarray.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,13 @@ def sigma_generator(
281281
282282
:param variable_label: Name of the DataArray to perform the calculation on
283283
:type variable_label: str
284-
:param sigma_func: Function to generate the sigmas. Must be of the form f(x) and return an array of the same
285-
shape as the input. DEFAULT: sqrt(|data|)
284+
:param sigma_func: Function to generate the sigmas. Must be of the form f(x) and return an array of the same shape as the input. Default sqrt(\|x\|)
286285
:type sigma_func: Callable
287286
:param label_prefix: What prefix should be used to designate a sigma DataArray from a data DataArray
288287
:type label_prefix: str
289288
:return: None
290289
:rtype: None
291-
"""
290+
""" # noqa: E501
292291
sigma_values = sigma_func(self._obj[variable_label])
293292
self.sigma_attach(variable_label, sigma_values, label_prefix)
294293

src/easyscience/Objects/Groups.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
from easyscience.Objects.ObjectClasses import Descriptor
2323

2424
if TYPE_CHECKING:
25-
from easyscience.Utils.typing import B
26-
from easyscience.Utils.typing import V
27-
from easyscience.Utils.typing import iF
25+
from easyscience.Objects.Inferface import iF
26+
from easyscience.Objects.ObjectClasses import B
27+
from easyscience.Objects.Variable import V
2828

2929

3030
class BaseCollection(BasedBase, MutableSequence):

src/easyscience/Objects/ObjectClasses.py

+10-23
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
from .Variable import Parameter
2929

3030
if TYPE_CHECKING:
31-
from easyscience.Utils.typing import C
32-
from easyscience.Utils.typing import V
33-
from easyscience.Utils.typing import iF
31+
from easyscience.fitting.Constraints import C
32+
from easyscience.Objects.Inferface import iF
33+
from easyscience.Objects.Variable import V
3434

3535

3636
class BasedBase(ComponentSerializer):
@@ -41,10 +41,10 @@ class BasedBase(ComponentSerializer):
4141
def __init__(self, name: str, interface: Optional[iF] = None, unique_name: Optional[str] = None):
4242
self._global_object = global_object
4343
if unique_name is None:
44-
unique_name = self._unique_name_generator()
44+
unique_name = self._global_object.generate_unique_name(self.__class__.__name__)
4545
self._unique_name = unique_name
4646
self._name = name
47-
self._global_object.map.add_vertex(self, obj_type="created")
47+
self._global_object.map.add_vertex(self, obj_type='created')
4848
self.interface = interface
4949
self.user_data: dict = {}
5050

@@ -69,16 +69,16 @@ def __reduce__(self):
6969

7070
@property
7171
def unique_name(self) -> str:
72-
""" Get the unique name of the object."""
72+
"""Get the unique name of the object."""
7373
return self._unique_name
7474

7575
@unique_name.setter
7676
def unique_name(self, new_unique_name: str):
77-
""" Set a new unique name for the object. The old name is still kept in the map.
78-
77+
"""Set a new unique name for the object. The old name is still kept in the map.
78+
7979
:param new_unique_name: New unique name for the object"""
8080
if not isinstance(new_unique_name, str):
81-
raise TypeError("Unique name has to be a string.")
81+
raise TypeError('Unique name has to be a string.')
8282
self._unique_name = new_unique_name
8383
self._global_object.map.add_vertex(self)
8484

@@ -206,18 +206,6 @@ def get_fit_parameters(self) -> Union[List[Parameter], List[NewParameter]]:
206206
fit_list.append(item)
207207
return fit_list
208208

209-
def _unique_name_generator(self) -> str:
210-
"""
211-
Generate a generic unique name for the object using the class name and a global iterator.
212-
"""
213-
class_name = self.__class__.__name__
214-
iterator_string = str(self._global_object.map._get_name_iterator(class_name))
215-
name = class_name + "_" + iterator_string
216-
while name in self._global_object.map.vertices():
217-
iterator_string = str(self._global_object.map._get_name_iterator(class_name))
218-
name = class_name + "_" + iterator_string
219-
return name
220-
221209
def __dir__(self) -> Iterable[str]:
222210
"""
223211
This creates auto-completion and helps out in iPython notebooks.
@@ -226,7 +214,6 @@ def __dir__(self) -> Iterable[str]:
226214
"""
227215
new_class_objs = list(k for k in dir(self.__class__) if not k.startswith('_'))
228216
return sorted(new_class_objs)
229-
230217

231218

232219
if TYPE_CHECKING:
@@ -267,7 +254,7 @@ def __init__(
267254
self._kwargs = kwargs
268255
for key in kwargs.keys():
269256
if key in known_keys:
270-
raise AttributeError("Kwargs cannot overwrite class attributes in BaseObj.")
257+
raise AttributeError('Kwargs cannot overwrite class attributes in BaseObj.')
271258
if issubclass(type(kwargs[key]), (BasedBase, Descriptor, DescriptorBase)) or 'BaseCollection' in [
272259
c.__name__ for c in type(kwargs[key]).__bases__
273260
]:

src/easyscience/Objects/Variable.py

+6-19
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from easyscience.Utils.Exceptions import CoreSetException
3838

3939
if TYPE_CHECKING:
40-
from easyscience.Utils.typing import C
40+
from easyscience.fitting.Constraints import C
4141

4242
Q_ = ureg.Quantity
4343
M_ = ureg.Measurement
@@ -109,7 +109,7 @@ def __init__(
109109
if not hasattr(self, '_args'):
110110
self._args = {'value': None, 'units': ''}
111111
if unique_name is None:
112-
unique_name = self._unique_name_generator()
112+
unique_name = self._global_object.generate_unique_name(self.__class__.__name__)
113113
self._unique_name = unique_name
114114
self.name = name
115115
# Let the collective know we've been assimilated
@@ -190,14 +190,14 @@ def unique_name(self) -> str:
190190
:return: Unique name of this object
191191
"""
192192
return self._unique_name
193-
193+
194194
@unique_name.setter
195195
def unique_name(self, new_unique_name: str):
196-
""" Set a new unique name for the object. The old name is still kept in the map.
197-
196+
"""Set a new unique name for the object. The old name is still kept in the map.
197+
198198
:param new_unique_name: New unique name for the object"""
199199
if not isinstance(new_unique_name, str):
200-
raise TypeError("Unique name has to be a string.")
200+
raise TypeError('Unique name has to be a string.')
201201
self._unique_name = new_unique_name
202202
self._global_object.map.add_vertex(self)
203203

@@ -363,19 +363,6 @@ def convert_unit(self, unit_str: str):
363363
self._args['value'] = self.raw_value
364364
self._args['units'] = str(self.unit)
365365

366-
def _unique_name_generator(self) -> str:
367-
"""
368-
Generate a generic unique name for the object using the class name and a global iterator.
369-
"""
370-
class_name = self.__class__.__name__
371-
iterator_string = str(self._global_object.map._get_name_iterator(class_name))
372-
name = class_name + "_" + iterator_string
373-
while name in self._global_object.map.vertices():
374-
iterator_string = str(self._global_object.map._get_name_iterator(class_name))
375-
name = class_name + "_" + iterator_string
376-
return name
377-
378-
379366
# @cached_property
380367
@property
381368
def compatible_units(self) -> List[str]:

0 commit comments

Comments
 (0)