How to use reader for Online data

The following example shows how to use the readerOnline class, using for reading data from run 9000 to 9002 with ORCA6 detector.

from km3compass import readerOnline

Initialising a readerOnline

Initialising is a simple as this:

reader = readerOnline("D_ORCA006", minrun=9000, maxrun=9000)
Loading data from DB ...
        detoid = D_ORCA006
        minrun = 9000
        maxrun = 9000
        Getting run 9000... - Done in 1 seconds

Access file content

File content is extracted and converted in a pandas DataFrame. You can display the content like this:

print(reader.df)
       RUN       UNIXTIME  DUID  ...   AHRS_H1   AHRS_H2                datetime
4     9000  1606225800475     9  ...  0.132424 -0.180303 2020-11-24 13:50:00.475
4551  9000  1606225800475     1  ... -0.036061       NaN 2020-11-24 13:50:00.475
5     9000  1606225800476     3  ... -0.144545 -0.221212 2020-11-24 13:50:00.476
1     9000  1606225800477     3  ... -0.132424 -0.201818 2020-11-24 13:50:00.477
3377  9000  1606225800477     3  ...       NaN       NaN 2020-11-24 13:50:00.477
...    ...            ...   ...  ...       ...       ...                     ...
4602  9000  1606226400474     1  ... -0.030303 -0.190303 2020-11-24 14:00:00.474
2563  9000  1606226400475     9  ...  0.132121 -0.179091 2020-11-24 14:00:00.475
568   9000  1606226400476     3  ... -0.131818 -0.203030 2020-11-24 14:00:00.476
2818  9000  1606226400477     3  ... -0.148182 -0.220000 2020-11-24 14:00:00.477
3428  9000  1606226400478     3  ... -0.172121 -0.214545 2020-11-24 14:00:00.478

[5627 rows x 16 columns]

To get the measured magnetic field and acceleration in numpy.array format, you can do the following:

a = reader.df[["AHRS_A0", "AHRS_A1", "AHRS_A2"]].values
h = reader.df[["AHRS_H0", "AHRS_H1", "AHRS_H2"]].values

import numpy as np

print(np.shape(a), np.shape(h))
(5627, 3) (5627, 3)

It can take some time to load runs from DB. In order to speed up this process, the reader feature a save on disk option. It will create a h5 file containing the data in a dataframe format

reader.save_df("online_data.h5")
Data stored in 'online_data.h5', under key 'runs_9000_9000'

To load the previously loaded data, a filename as well as the filekey should be provided to the reader :

reader = readerOnline(filename="online_data.h5", filekey="runs_9000_9000")
Filename provided, will load data from disk ...
        filename = online_data.h5
        filekey =  runs_9000_9000

Draw a simple plot

The raw values can be displayed using matplolib. In this simple example, x vs y components of magnetic field are plotted. The aspect of x and y are set to equal, to get a better representation of the cartesian space.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.scatter(reader.df["AHRS_H0"], reader.df["AHRS_H1"])

ax.set_aspect("equal")

ax.set_xlabel("X [G]")
ax.set_ylabel("Y [G]")
ax.grid()
plt.show()
plot readerOnline

Total running time of the script: (0 minutes 1.179 seconds)

Gallery generated by Sphinx-Gallery