Skip to content

Commit

Permalink
release 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tillbiskup committed Jul 24, 2022
2 parents 215d107 + 783fc27 commit caae503
Show file tree
Hide file tree
Showing 25 changed files with 10,361 additions and 53 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.1
0.3.0
47 changes: 26 additions & 21 deletions cwepr/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import aspecd.analysis
import aspecd.dataset
import aspecd.utils


class FieldCalibration(aspecd.analysis.SingleAnalysisStep):
Expand Down Expand Up @@ -573,7 +574,7 @@ class AmplitudeVsPower(aspecd.analysis.SingleAnalysisStep):
- PowerSweep
result: power_sweep_analysis
- kind: singleanalysis
type: PolynomialFitOnData
type: FitOnData
properties:
parameters:
order: 1
Expand Down Expand Up @@ -668,7 +669,7 @@ def _assign_units_to_result(self):
self.result.data.axes[1].quantity = 'EPR amplitude'


class PolynomialFitOnData(aspecd.analysis.SingleAnalysisStep):
class FitOnData(aspecd.analysis.SingleAnalysisStep):
"""Perform polynomial fit on data and return its parameters or a dataset.
Developed tests first.
Expand All @@ -689,8 +690,9 @@ class PolynomialFitOnData(aspecd.analysis.SingleAnalysisStep):
Default: 1
return_type : :class: `str`
Choose to returning the coefficients of the fit or a calculated
dataset containing the curve to plot.
Choose to returning the coefficients of the fit in order
of increasing degree or a calculated dataset containing the curve to
plot.
Default: coefficients.
Expand All @@ -710,7 +712,7 @@ class PolynomialFitOnData(aspecd.analysis.SingleAnalysisStep):
.. code-block:: yaml
- kind: singleanalysis
type: PolynomialFitOnData
type: FitOnData
properties:
parameters:
points: 5
Expand All @@ -719,24 +721,22 @@ class PolynomialFitOnData(aspecd.analysis.SingleAnalysisStep):
add_origin: True
result: fit
<<<<<<< HEAD
=======
.. versionchanged:: 0.3
Rewrite to perform fits with fixed intercept, remove parameter
"add_origin", introduced "fixed_intercerpt".
Return coefficients in order of increasing degree
>>>>>>> fd083d6... Prospector run, updated roadmap and changelog
"""

def __init__(self):
super().__init__()
self.description = "Perform polynomial fit and return parameters."
self.description = "Perform fit and return parameters."
self.result = None
self.parameters['points'] = 3
self.parameters['order'] = 1
self.parameters['return_type'] = 'coefficients'
self.parameters['add_origin'] = False
self.parameters['fixed_intercept'] = False
self.parameters['offset'] = 0
self.parameters['coefficients'] = []
# private properties
self._curve = None
Expand All @@ -762,10 +762,12 @@ def applicable(dataset):
return dataset.data.data.ndim == 1

def _perform_task(self):
if self.parameters['add_origin']:
self._add_origin()
self._get_coefficients()
self._get_curve()
if self.parameters['fixed_intercept']:
self._linear_regression_with_fixed_intercept()
self._get_curve()
else:
self._get_coefficients()
self._get_curve()
self._assign_result()

def _get_coefficients(self):
Expand All @@ -778,21 +780,24 @@ def _get_coefficients(self):

def _get_curve(self):
self._curve = self.create_dataset()
slope = np.polynomial.Polynomial(self.parameters['coefficients'])
self._curve.data.data = slope(self.dataset.data.axes[0].values)
self._curve.data.axes[0] = self.dataset.data.axes[0]
self._curve.data.data = np.polyval(self.parameters['coefficients'],
self.dataset.data.axes[0].values)
self._curve.data.axes[0].values = self.dataset.data.axes[0].values

def _assign_result(self):
if self.parameters['return_type'].lower() == 'dataset':
self.result = self._curve
else:
self.result = self.parameters['coefficients']

def _add_origin(self):
self.dataset.data.axes[0].values = \
np.insert(self.dataset.data.axes[0].values, 0, 0)
self.dataset.data.data = np.insert(self.dataset.data.data, 0, 0)
def _linear_regression_with_fixed_intercept(self):
analysis = aspecd.analysis.LinearRegressionWithFixedIntercept()
aspecd.utils.copy_values_between_dicts(source=self.parameters,
target=analysis.parameters)
analysis.parameters['polynomial_coefficients'] = True
analysis.dataset = self.dataset
result = self.dataset.analyse(analysis)
self.parameters['coefficients'] = result.result


class PtpVsModAmp(aspecd.analysis.SingleAnalysisStep):
Expand Down
28 changes: 21 additions & 7 deletions cwepr/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
"""
Subpackage for IO.
Generally, for each file format, the importer resides in a separate module.
The import statements below should *only* import the respective classes.
Currently, in addition to modules for the individual data file formats,
there are a series of more general modules:
Generally, for each file format (or class of formats), the importer resides
in a separate module.
Currently, a number of more or less well-known and widely used EPR file
formats are supported:
=========================== ============= ==========================
Format Extensions Module
=========================== ============= ==========================
Bruker ESP and EMX par, spc :mod:`cwepr.io.esp_winepr`
Bruker BES3T DSC, DTA :mod:`cwepr.io.bes3t`
Magnettech (now Bruker) XML xml :mod:`cwepr.io.magnettech`
NIEHS PEST lmb, exp, dat :mod:`cwepr.io.niehs`
--------------------------- ------------- --------------------------
Generic text file txt :mod:`cwepr.io.txt_file`
=========================== ============= ==========================
In addition to modules for the individual data file formats, there are a
series of more general modules:
* factory
Expand All @@ -20,9 +32,11 @@
"""

# The import statements below should *only* import the respective classes.
from .factory import DatasetImporterFactory
from .magnettech import MagnettechXMLImporter, GoniometerSweepImporter
from .txt_file import TxtImporter
from .bes3t import BES3TImporter
from .esp_winepr import ESPWinEPRImporter
from .niehs import NIEHSDatImporter, NIEHSLmbImporter, NIEHSExpImporter
from .exporter import ASCIIExporter, MetadataExporter
5 changes: 4 additions & 1 deletion cwepr/io/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ def __init__(self):
self.supported_formats = {"BES3T": [".DTA", ".DSC"],
"ESPWinEPR": [".spc", ".par"],
"MagnettechXML": [".xml"],
"NIEHSDat": [".dat"],
"NIEHSLmb": [".lmb"],
"NIEHSExp": [".exp"],
"Txt": [".txt"],
"Csv": [".csv"]}
}
self.data_format = None

def _get_importer(self):
Expand Down
2 changes: 1 addition & 1 deletion cwepr/io/magnettech.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MagnettechXMLImporter(aspecd.io.DatasetImporter):
"""Import cw-EPR raw data from the Magnettech benchtop spectrometer.
Magnettech provides a XML-file with the results. Specialities of this
format are existing and will be briefly explained: The data is coded in
format are existing and will be briefly explained: The data is encoded in
hex numbers, and the *y* axis consists of 10 times more points than the
*y* axis. Therefore, an interpolation is needed to expand the axis to the
necessary amount of points.
Expand Down
Loading

0 comments on commit caae503

Please sign in to comment.