Interrupted workflow

This example shows that using IO, you can easily interrupt your workflow, save it and continue some other time.

[1]:
import numpy as np
import physt

%matplotlib inline
[2]:
histogram = physt.h1(None, "fixed_width", bin_width=0.1, adaptive=True)
histogram
[2]:
Histogram1D(bins=(0,), total=0, dtype=int64)
[3]:
# Big chunk of data
data1 = np.random.normal(0, 1, 10000000)
histogram.fill_n(data1)
histogram
[3]:
Histogram1D(bins=(106,), total=10000000, dtype=int64)
[4]:
histogram.plot()
[4]:
<AxesSubplot:xlabel='axis0'>
_images/interrupted-workflow_4_1.png

Store the histogram (and delete it to pretend we come with a fresh table):

[5]:
histogram.to_json(path="./histogram.json");
del histogram

Turn off the machine, go for lunch, return home later…

Read the histogram:

[6]:
histogram = physt.io.load_json(path="./histogram.json")
histogram
[6]:
Histogram1D(bins=(106,), total=10000000, dtype=int64)
[7]:
histogram.plot()
[7]:
<AxesSubplot:xlabel='axis0'>
_images/interrupted-workflow_9_1.png

The same one ;-)

Continue filling:

[8]:
# Another big chunk of data
data1 = np.random.normal(3, 2, 10000000)
histogram.fill_n(data1)
histogram
[8]:
Histogram1D(bins=(205,), total=20000000, dtype=int64)
[9]:
histogram.plot()
[9]:
<AxesSubplot:xlabel='axis0'>
_images/interrupted-workflow_12_1.png