Skip to main content
Build Status Coverage Status Documentation Status Binder PyPi version License: MIT Code style: black

Diagnostics is a Python module designed to make analysis of diagnostic data easier. It comes with a couple of clear data-structures with automatic quality checks, easy Boolean logic operators and built-in bookkeeping. To top that off, it’s built on numpy!

Installation

The diagnostics library is tested on python 3.7. However, it should run on python 3.6 and 3.5 as well.

You can install the library using pip:

pip install pydiagnostics

Alternatively, you can clone the repository and use setup.py to install:

git clone https://github.com/tim00w/diagnostics.git
cd diagnostics
python setup.py install

Open Source

This project strives to abide by generally accepted best practices in open-source software development:

CII Best Practices

Documentation

The docs are hosted on ReadTheDocs.

Quickstart

Eager to begin and no time to read the documentation? Here is a quickstart!

TimeSeries

Diagnostic events are derived from from real occurances. For instance, your phone will probably generate a message (event) if your battery is running low (percentage below threshold value). The diagnostics library has a TimeSerie class that can capture these occurances.

For example, a TimeSerie representing your battery life, which drains 0.01% each second:

import numpy as np
import diagnostics as ds

battery_life = ds.TimeSerie(np.arange(100, 0, -0.01), fs=1)

the first argument is consists of a data array (both list() and numpy.array() are supported), and additionally you can provide some keyword parameters. Here we’ve provided the sample frequency (fs) which is 1 Hz, because we said our battery drains 0.01% each second. In this particular case we could’ve left fs out, since the default value of fs is also 1.

Now that we’ve got our data, we can easily visualize this:

battery_life.plot(show=True)

There are other keyword parameters that we can use as well, such as t0 (start time of TimeSerie in posixtime or a datetime object), and a name (default is an empty string).

from datetime import datetime

battery_life = ds.TimeSerie(np.arange(100, 0, -0.01),
                            fs=1,
                            t0=datetime(2019,1,1,8,5), # 2019-01-01 08:05
                            name='battery life')

Now we’ve got our battery life set to a specific (start-)datetime, and gave it a name. Both will come in handy later.

BooleanTimeSeries

Let’s be honest, the battery percentage of your phone does not really matter to you, unless it goes below a certain threshold. Luckily for us, our TimeSerie can easily be converted to a BooleanTimeSerie, which only contains boolean values of when the percentage reaches below 25%:

battery_below25 = battery_life <= 25

battery_below25.plot(show=True)

Now that’s easy! We can see that our battery goes below 25% at HH:MM:SS.

StateChangeArray

You could argue that our BooleanTimeSerie contains a lot of data points with the same value. I’d agree with you, and therefore introduce a class that only keeps track of the changes in data points, the StateChangeArray:

battery_low_state = battery_below25.to_statechangearray()

Alternatively, we can create a StateChangeArray (or BooleanStateChangeArray, you can probably guess the difference :smile:) from scratch:

s = ds.StateChangeArray([1, 4, 8, 13], t=[1,2,4,8], name='my state')
b = ds.BooleanStateChangeArray([True, False, True, False], t=[1,3,6,9], name='b')

Both the data array as the values for time (t) can be list() or np.array(). The time is considered as posixtime. For now it is not possible to give a datetimearray or list of datetimes as an input, but this wil be implemented in the near future.

Comparing TimeSeries and StateChangeArrays

There are more classes besides TimeSeries and StateChangearrays, each with their own advantages and disadvantages. The power of this module lies in clear transformations from one class to another (we’ve already shown the TimeSerie.to_statechangearray() method), and the comparison of multiple classes.

To start with TimeSeries, if two (or more) have the same array_length, t0 and fs, we can easily do calculations with them!

# create two TimeSerie objects that we'll combine
a = ds.TimeSerie(np.sin(np.linspace(0, 2*np.pi, 100)), t0=0, fs=1, name='a')
b = ds.TimeSerie(np.sin(2* np.linspace(0, 2*np.pi, 100)), t0=0, fs=1, name='b')

# It's this easy!
c = a + b

# We're interested in the more extreme values, lets create TimeSeries for these:
d = c <= -1
e = c >=  1

# we'll name them to keep our bookkeeping up to date
d.name = 'c <= -1'
e.name = 'c >= 1'

# and find when one of the above conditions is True!
f = d | e

# when performing boolean operators ('~', '^', '&', '|'), the library
# does it's own bookkeeping:
print(f.name)
f.plot(show=True)

Comparing StateChangeArrays would normally be a bit tricky, since the data is most likely non-linearly spaced. This means that we can’t just perform vectorized boolean operations, but we’ll need to combine both data values as well as their respective points in time.

Luckily for us, the StateChangeArray has this built in:

a = StateChangeArray([True, False, True, False], t=[2,4,6,8], name='a')
b = StateChangeArray([True, False, True, False], t=[3,5,7,9], name='b')

c = a | b
d = a & b
e = ~a
f = a ^ a
g = a ^ e

That’s pretty great right?

Reports & Events

WIP

Downloads

Metadata

Release files for pydiagnostics 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydiagnostics 0.6.0
File Size Uploaded
pydiagnostics-0.6.0.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydiagnostics 0.6.0
File Interpreter ABI Platform
pydiagnostics-0.6.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.3 kB

Release files / pydiagnostics-0.6.0.tar.gz

Download URL pydiagnostics-0.6.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8bd0a002cb2b3b75d0d61d7bf52d177bf3446000cc356be17ad5a59654fa5e11
BLAKE2b-256 checksum
How to use checksums
117fb94e031fe3398de3782abdad227544f74af8fb5f2fb994b45f58d617de6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release files / pydiagnostics-0.6.0-py2.py3-none-any.whl

Download URL pydiagnostics-0.6.0-py2.py3-none-any.whl
Size 12.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1418afa1893b69e57f44fc92ce904358e9980f621fe64c361c23ded39019506d
BLAKE2b-256 checksum
How to use checksums
c291663ca78ed5baa4f6da72a9cba8b021b00f86b7b7a5570c7d2b0eb93ee294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page