Skip to content

Commit

Permalink
release 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tillbiskup committed Jan 13, 2024
2 parents 1376dd2 + 170b45a commit df3423e
Show file tree
Hide file tree
Showing 39 changed files with 4,866 additions and 425 deletions.
4 changes: 3 additions & 1 deletion .prospector.yaml
@@ -1,6 +1,8 @@
# For general information of how to configure prospector visit
# https://prospector.landscape.io/en/master/profiles.html

autodetect: false

inherits:
- strictness_high

Expand All @@ -17,7 +19,7 @@ pep257:
pylint:
options:
max-attributes: 16
max-module-lines: 4500
max-module-lines: 5000

pyroma:
run: true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2017-22 Till Biskup
Copyright (c) 2017-24 Till Biskup
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.8.3
0.9.0
118 changes: 116 additions & 2 deletions aspecd/analysis.py
Expand Up @@ -113,13 +113,23 @@
Perform linear regression without fitting the intercept on 1D data. Note
that this is mathematically different from a polynomial fit of first order.
* :class:`DeviceDataExtraction`
Extract device data as separate dataset.
Datasets may contain additional data as device data in
:attr:`aspecd.dataset.Dataset.device_data`. For details,
see :class:`aspecd.dataset.DeviceData`. To further process and analyse
these device data, the most general way is to extract them as
individual dataset and perform all further tasks on it.
Writing own analysis steps
==========================
Each real analysis step should inherit from either
:class:`aspecd.processing.SingleProcessingStep` in case of operating on a
single dataset only or from :class:`aspecd.processing.MultiProcessingStep` in
:class:`aspecd.analysis.SingleAnalysisStep` in case of operating on a
single dataset only or from :class:`aspecd.analysis.MultiAnalysisStep` in
case of operating on several datasets at once. Furthermore, all analysis
steps should be contained in one module named "analysis". This allows for
easy automation and replay of analysis steps, particularly in context of
Expand Down Expand Up @@ -1951,3 +1961,107 @@ def _perform_task(self):
self.result = [self.parameters["offset"], float(results[0])]
else:
self.result = float(results[0])


class DeviceDataExtraction(SingleAnalysisStep):
"""
Extract device data as separate dataset.
Datasets may contain additional data as device data in
:attr:`aspecd.dataset.Dataset.device_data`. For details,
see :class:`aspecd.dataset.DeviceData`. To further process and analyse
these device data, the most general way is to extract them as
individual dataset and perform all further tasks on it.
A reference to the original dataset is stored in
:attr:`aspecd.dataset.Dataset.references`.
Attributes
----------
result : :class:`aspecd.dataset.CalculatedDataset`
Dataset containing the device data.
The device the data are extracted for is provided by the parameter
``device``, see below.
parameters : :class:`dict`
All parameters necessary for this step.
device : :class:`str`
Name of the device the data should be extracted for.
Raises a :class:`KeyError` if the device does not exist.
Default: ''
Raises
------
KeyError
Raised if device is not present in
:attr:`aspecd.dataset.Dataset.device_data`
Examples
--------
For convenience, a series of examples in recipe style (for details of
the recipe-driven data analysis, see :mod:`aspecd.tasks`) is given below
for how to make use of this class. The examples focus each on a single
aspect.
Suppose you have a dataset that contains device data referenced with
the key "timestamp", and you want to extract those device data and
make them accessible from within the recipe using the name "timestamp"
as well:
.. code-block:: yaml
- kind: singleanalysis
type: DeviceDataExtraction
properties:
parameters:
device: timestamp
result: timestamp
.. versionadded:: 0.9
"""

def __init__(self):
super().__init__()
self.description = 'Extract device data'
self.parameters["device"] = ''

@staticmethod
def applicable(dataset):
"""
Check whether analysis step is applicable to the given dataset.
Device data extraction is only possible if device data are present.
Parameters
----------
dataset : :class:`aspecd.dataset.Dataset`
Dataset to check
Returns
-------
applicable : :class:`bool`
Whether dataset is applicable
"""
return dataset.device_data

def _sanitise_parameters(self):
device = self.parameters["device"]
if device not in self.dataset.device_data.keys():
raise KeyError(f"Device '{device}' not found in dataset")

def _perform_task(self):
device = self.parameters["device"]
dataset = self.create_dataset()
dataset.data = copy.deepcopy(self.dataset.device_data[device])
reference = aspecd.dataset.DatasetReference()
reference.from_dataset(self.dataset)
dataset.references.append(reference)
self.result = dataset

0 comments on commit df3423e

Please sign in to comment.