Coverage for ana/multiple.py : 65%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# SPDX-FileCopyrightText: 2020 Jonathan Pieper <jpieper@stud.uni-frankfurt.de>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
5"""
6Main parent class for all multiple measurements.
7These Measurements are represent by one data variable.
9All multiple measurements have a variable called ``multi_info`` which contains
10a pandas.DataFrame with parameter settings to single measurements.
12All single can be represented by
14 >>> m = ana.MultipleM()
15 >>> m
16 Nr. 0: Hloop
17 Nr. 0: RAW
18"""
20from .measurement import MeasurementClass
22import os
23import pandas as pd
25class MultipleM(MeasurementClass):
26 def __init__(self):
27 """MultipleM:
29 Main parent class for all multiple measurements. These Measurements
30 are represent by one data variable.
32 All multiple measurements have a variable called ``multi_info`` which
33 contains a pandas.DataFrame with parameter settings to single
34 measurements.
36 All multiple measurements can be represented by
38 >>> m = ana.MultipleM()
39 >>> m
40 Nr. 0: Hloop
41 Nr. 0: RAW
42 """
44 super().__init__()
45 self.multi_info = pd.DataFrame()
46 if os.path.exists('data/mfn_info.csv'):
47 self.read_csv('data/mfn_info.csv')
50 query = lambda self, request: self.multi_info.query(request)
52 def get_lofm_sweeps(self, to_show, label, options={}):
53 """Workaround to get list of measurements for sweeps.
55 Args:
56 to_show (dict): Measurement Numbers pointing to label format
57 variables: e.g. `` {nr: [-1, 1, 'Plusses', '2 mT/min']}
58 label (str): Label to show in plots: e.g. "Show %s -> %s (%s) %s "
59 -> will be formated using to_show
60 options (dict, default: empty): Additional plotting options
62 Returns:
63 dict: List of Measurements with description
64 """
66 return self.get_lofm(to_show,
67 label,
68 options)
70 def read_csv(self, *args, **kwargs):
71 """Updates multi_info DataFrame. Reads csv and adds information to
72 self.multi_info
74 Args:
75 *args:
76 **kwargs:
78 Returns:
79 None
80 """
82 self.multi_info = pd.concat([self.multi_info, pd.read_csv(*args, **kwargs)])
84 def get_lofm(self, to_show, label, options={}):
85 """Returns the List of Measurements (lofm) for plot functions
86 (see :meth:`ana.HandleM.plot`).
88 Args:
89 to_show (dict): Measurement Numbers pointing to label format
90 variables: e.g. ``{nr: [(-1, 1), 'Plusses', '5 mT/min']}``
91 label (str): Label to show in plots: e.g.
92 ``"Show %s -> %s (%s) %s "`` -> will be string formated using
93 to_show
94 options (dict, optional, default: empty): Additional plotting
95 parameters
97 Returns:
98 dict: List of Measurements with description: ``{nr: [labels]}``
99 """
100 lofm = {}
101 for nr, content in to_show.items():
102 if isinstance(content[0], tuple):
103 form = content[0][0], content[0][1], content[1], content[2]
104 # elif isinstance(content[0], str) or \
105 # isinstance(content[0], int) or \
106 # isinstance(content[0], float):
107 # form = content[0], content[1], content[2]
108 else:
109 form = content
111 lofm[nr] = [label % form, options]
113 return lofm