Skip to content

Commit

Permalink
Automatically identify input data type
Browse files Browse the repository at this point in the history
  • Loading branch information
John Garrett committed Mar 10, 2019
1 parent daa5a66 commit 0fa39dc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 78 deletions.
32 changes: 15 additions & 17 deletions examples/analyze-experimental-data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"For the purposes of this notebook, example data has been included in a directory called ``eg-230-data/``. This is experimental data that was taken from an SIS device illuminated by a local-oscillator at 230 GHz (see Garrett 2018).\n",
"\n",
"QMix includes two classes that can be used to analyze these experimental data:\n",
"QMix includes two classes that can be used to analyze this experimental data:\n",
"\n",
" - [qmix.exp.RawData0](https://garrettj403.github.io/QMix/qmix.exp.html#qmix.exp.exp_data.RawData0), which is used to analyze DC data (no LO illumination), and\n",
" - [qmix.exp.RawData](https://garrettj403.github.io/QMix/qmix.exp.html#qmix.exp.exp_data.RawData), which is used to analyze pumped data (with LO illumination).\n",
Expand Down Expand Up @@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -107,17 +107,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to import these files properly, we will define the properties of the CSV files, which will then be passed on to the ``RawData0`` and ``RawData`` classes."
"In order to import these files properly, we will define the properties of the CSV files, which will then be passed on to the ``RawData0`` class."
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"csv_params = dict(input_type = 'csv', # pass data as CSV data files\n",
" delimiter = ',', # delimiter used by CSV files\n",
"csv_params = dict(delimiter = ',', # delimiter used by CSV files\n",
" usecols = (0,1), # columns to import\n",
" skip_header = 1, # skip the first row (the header)\n",
" v_fmt = 'mV', # units for voltage data\n",
Expand All @@ -133,7 +132,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -150,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -162,7 +161,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -187,7 +186,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -221,7 +220,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -245,7 +244,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -270,7 +269,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -316,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -343,7 +342,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -370,7 +369,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -458,7 +457,6 @@
"source": [
"pump = qmix.exp.RawData(iv_data, dciv, hot_data, cold_data,\n",
" freq = 230.2, # LO frequency in [GHz]\n",
" input_type = \"Numpy\", # Pass in Numpy arrays\n",
" **params)"
]
},
Expand Down
34 changes: 17 additions & 17 deletions qmix/exp/exp_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ class RawData0(object):
Args:
dciv: DC I-V curve. Either a CSV data file or a Numpy array. The data
should have two columns: the first for voltage, and the second
for current. To pass a Numpy array, set the ``input_type`` keyword
argument to ``"numpy"``. To pass a CSV data file, set the
``input_type`` keyword argument to ``"csv"``. The properties of
the CSV file can be set through additional keyword arguments.
(See below).
for current. If you are using CSV files, the properties of
the CSV file can be set through additional keyword arguments
(see below).
dcif: DC IF data. Either a CSV data file or a Numpy array. The
data should have two columns: the first for voltage, and the
second for IF power.
second for IF power. If you are using CSV files, the properties of
the CSV file can be set through additional keyword arguments
(see below).
Keyword arguments:
input_type (str): Input type ('csv' or 'numpy').
delimiter (str): Delimiter for CSV files.
usecols (tuple): List of columns to import (tuple of length 2).
skip_header (int): Number of rows to skip, used to skip the header.
Expand Down Expand Up @@ -176,12 +175,12 @@ def __init__(self, dciv, dcif=None, **kw):
self.comment = comment
self.vleak = vleak

if kw['input_type'].lower() == 'csv':
if isinstance(dciv, str): # input type: CSV file
self.file_path = dciv
elif kw['input_type'].lower() == 'numpy':
elif isinstance(dciv, np.ndarray): # input type: Numpy array
self.file_path = 'Numpy array'
else:
raise ValueError('Input type not recognized.')
raise ValueError('Input data type not recognized.')

# Get DC I-V data
self.voltage, self.current, self.dc = dciv_curve(dciv, **kw)
Expand Down Expand Up @@ -640,11 +639,12 @@ class RawData(object):
Args:
ivdata: I-V data. Either a CSV data file or a Numpy array. The data
should have two columns: the first for voltage, and the second
for current.
for current. If you are using CSV files, the properties of
the CSV file can be set through additional keyword arguments
(see below).
dciv (qmix.exp.iv_data.DCIVData): DC I-V metadata
Keyword arguments:
input_type (str): Input type ('csv' or 'numpy').
delimiter (str): Delimiter for CSV files.
usecols (tuple): List of columns to import (tuple of length 2).
skip_header (int): Number of rows to skip, used to skip the header.
Expand Down Expand Up @@ -719,7 +719,7 @@ def __init__(self, ivdata, dciv, if_hot=None, if_cold=None, **kw):
analyze_if = analyze

# Sort out file paths
if kw['input_type'].lower() == 'csv':
if isinstance(ivdata, str): # input type: CSV file
self.iv_file = ivdata
self.directory = os.path.dirname(ivdata)
self.iv_filename = os.path.basename(ivdata)
Expand All @@ -729,7 +729,7 @@ def __init__(self, ivdata, dciv, if_hot=None, if_cold=None, **kw):
else:
self.filename_hot = None
self.filename_cold = None
elif kw['input_type'].lower() == 'numpy':
elif isinstance(ivdata, np.ndarray): # input type: Numpy array
self.iv_file = 'Numpy array'
self.directory = 'Numpy array'
self.iv_filename = 'Numpy array'
Expand All @@ -740,7 +740,7 @@ def __init__(self, ivdata, dciv, if_hot=None, if_cold=None, **kw):
self.filename_hot = None
self.filename_cold = None
else:
raise ValueError("Input type not recognized.")
raise ValueError("Input data type not recognized.")

# Unpack DC I-V metadata
self.dciv = dciv
Expand All @@ -755,8 +755,8 @@ def __init__(self, ivdata, dciv, if_hot=None, if_cold=None, **kw):
self.current_dc = dciv.current

# Get LO frequency
if kw['input_type'] == 'numpy' and freq is None:
str1 = 'If input_type is set to \'numpy\', '
if isinstance(ivdata, np.ndarray) and freq is None:
str1 = 'If input data is in the form of Numpy arrays, '
str2 = 'you must define the frequency of the LO signal.'
raise ValueError(str1 + str2)
self.freq, self.freq_str = _get_freq(freq, ivdata)
Expand Down
26 changes: 9 additions & 17 deletions qmix/exp/if_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ def dcif_data(ifdata, dc, **kwargs):
Args:
ifdata: IF data. Either a CSV data file or a Numpy array. The data
should have two columns: the first for voltage, and the second
for IF power. To pass a Numpy array, set the ``input_type``
keyword argument to ``"numpy"``. To pass a CSV data file, set the
``input_type`` keyword argument to ``"csv"``. The properties of
the CSV file can be set through additional keyword arguments.
(See below).
for IF power. If you are passing a CSV file, the properties of
the CSV file can be set through additional keyword arguments
(see below).
dc (qmix.exp.iv_data.DCIVData): DC I-V metadata.
Keyword Args:
input_type (str): Input type ('csv' or 'numpy').
delimiter (str): Delimiter for CSV files.
usecols (tuple): List of columns to import (tuple of length 2).
skip_header (int): Number of rows to skip, used to skip the header.
Expand Down Expand Up @@ -110,7 +107,6 @@ def if_data(if_hot, if_cold, dc, **kwargs):
dc (qmix.exp.iv_data.DCIVData): DC I-V metadata.
Keyword Args:
input_type (str): Input type ('csv' or 'numpy').
delimiter (str): Delimiter for CSV files.
usecols (tuple): List of columns to import (tuple of length 2).
skip_header (int): Number of rows to skip, used to skip the header.
Expand Down Expand Up @@ -360,11 +356,9 @@ def _load_if(ifdata, dc, **kwargs):
Args:
ifdata: IF data. Either a CSV data file or a Numpy array. The data
should have two columns: the first for voltage, and the second
for IF power. To pass a Numpy array, set the ``input_type``
keyword argument to ``"numpy"``. To pass a CSV data file, set the
``input_type`` keyword argument to ``"csv"``. The properties of
the CSV file can be set through additional keyword arguments.
(See below).
for IF power. If you are using a CSV file, the properties of
the CSV file can be set through additional keyword arguments
(see below).
dc (qmix.exp.iv_data.DCIVData): DC I-V metadata.
Keyword arguments:
Expand All @@ -377,7 +371,6 @@ def _load_if(ifdata, dc, **kwargs):
points
rseries (float): series resistance of measurement system
skip_header: number of rows to skip at the beginning of the file
input_type (str):
Returns: IF data (in matrix form)
Expand All @@ -386,7 +379,6 @@ def _load_if(ifdata, dc, **kwargs):
# Unpack keyword arguments
v_multiplier = kwargs.get('v_multiplier', PARAMS['v_multiplier'])
skip_header = kwargs.get('skip_header', PARAMS['skip_header'])
input_type = kwargs.get('input_type', PARAMS['input_type'])
sigma = kwargs.get('ifdata_sigma', PARAMS['ifdata_sigma'])
vmax = kwargs.get('ifdata_vmax', PARAMS['ifdata_vmax'])
npts = kwargs.get('ifdata_npts', PARAMS['ifdata_npts'])
Expand All @@ -396,16 +388,16 @@ def _load_if(ifdata, dc, **kwargs):
v_fmt = kwargs.get('v_fmt', PARAMS['v_fmt'])

# Import raw IF data
if input_type.lower() == 'csv':
if isinstance(ifdata, str): # assume CSV data file
ifdata = np.genfromtxt(ifdata, delimiter=delim, usecols=usecols,
skip_header=skip_header)
elif input_type.lower() == 'numpy':
elif isinstance(ifdata, np.ndarray): # Numpy array
assert isinstance(ifdata, np.ndarray), \
'I-V data should be a Numpy array.'
assert ifdata.ndim == 2, 'I-V data should be 2-dimensional.'
assert ifdata.shape[1] == 2, 'I-V data should have 2 columns.'
else:
raise ValueError("Input type not recognized.")
raise ValueError("Input data type not recognized.")

# Clean
ifdata = remove_nans_matrix(ifdata)
Expand Down
22 changes: 7 additions & 15 deletions qmix/exp/iv_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ def dciv_curve(ivdata, **kwargs):
Args:
ivdata: DC I-V data. Either a CSV data file or a Numpy array. The data
should have two columns: the first for voltage, and the second
for current. To pass a Numpy array, set the ``input_type`` keyword
argument to ``"numpy"``. To pass a CSV data file, set the
``input_type`` keyword argument to ``"csv"``. The properties of
for current. If you are using CSV files, the properties of
the CSV file can be set through additional keyword arguments.
(See below).
Keyword Args:
input_type (str): Input type ('csv' or 'numpy').
delimiter (str): Delimiter for CSV files.
usecols (tuple): List of columns to import (tuple of length 2).
skip_header (int): Number of rows to skip, used to skip the header.
Expand Down Expand Up @@ -206,16 +203,13 @@ def iv_curve(ivdata, dc, **kwargs):
Args:
ivdata: I-V data. Either a CSV data file or a Numpy array. The data
should have two columns: the first for voltage, and the second
for current. To pass a Numpy array, set the ``input_type`` keyword
argument to ``"numpy"``. To pass a CSV data file, set the
``input_type`` keyword argument to ``"csv"``. The properties of
the CSV file can be set through additional keyword arguments.
(See below).
for current. If you are using a CSV file, the properties of
the CSV file can be set through additional keyword arguments
(see below).
dc (qmix.exp.iv_data.DCIVData): DC I-V data metadata. Generated
previously by ``dciv_curve``.
Keyword Args:
input_type (str): Input type ('csv' or 'numpy').
delimiter (str): Delimiter for CSV files.
usecols (tuple): List of columns to import (tuple of length 2).
skip_header (int): Number of rows to skip, used to skip the header.
Expand Down Expand Up @@ -327,7 +321,6 @@ def _load_iv(ivdata, **kw):
for current.
Keyword Arguments:
input_type: input type ('csv' or 'numpy')
v_fmt: voltage units ('uV', 'mV', 'V')
i_fmt: current units ('uA', 'mA', 'A')
usecols: list of columns to use (tuple of length 2)
Expand All @@ -341,24 +334,23 @@ def _load_iv(ivdata, **kw):

# Unpack keyword arguments
skip_header = kw.get('skip_header', PARAMS['skip_header'])
input_type = kw.get('input_type', PARAMS['input_type'])
delimiter = kw.get('delimiter', PARAMS['delimiter'])
usecols = kw.get('usecols', PARAMS['usecols'])
v_fmt = kw.get('v_fmt', PARAMS['v_fmt'])
i_fmt = kw.get('i_fmt', PARAMS['i_fmt'])

# Import raw I-V data
if input_type.lower() == 'csv':
if isinstance(ivdata, str): # input: CSV file
vraw, iraw = np.genfromtxt(ivdata, delimiter=delimiter,
usecols=usecols, skip_header=skip_header).T
elif input_type.lower() == 'numpy':
elif isinstance(ivdata, np.ndarray): # input: Numpy array
assert isinstance(ivdata, np.ndarray), \
'I-V data should be a Numpy array.'
assert ivdata.ndim == 2, 'I-V data should be 2-dimensional.'
assert ivdata.shape[1] == 2, 'I-V data should have 2 columns.'
vraw, iraw = ivdata.T
else:
raise ValueError("Input type not recognized.")
raise ValueError("Input data type not recognized.")

# Set units
volt_v = vraw * _vfmt_dict[v_fmt]
Expand Down
4 changes: 0 additions & 4 deletions qmix/exp/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
``RawData`` either as CSV data files or as Numpy arrays. The CSV
files should have two columns: one for voltage and one for current
or IF power. The Numpy arrays should also have two columns.
- ``input_type == "csv"`` : Input type. Either ``"csv"`` or
``"numpy"``.
- CSV files:
- **Note:** All of the experimental data is expected to be stored in
CSV data files. These parameters control how the data is read in
Expand Down Expand Up @@ -162,8 +160,6 @@ class will determine the best bias voltage automatically.
"""

params = dict(
# Experimental data data
input_type = 'csv',
# CSV files
delimiter = ',',
usecols = (0, 1),
Expand Down
Loading

0 comments on commit 0fa39dc

Please sign in to comment.