-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial refactoring #119
base: master
Are you sure you want to change the base?
Initial refactoring #119
Changes from all commits
d762040
d9b1f02
91cb71d
4a3be1c
de2fa99
3977887
b9b1243
26a9d35
01327a0
a44eabc
20eaddc
a70d321
c174bfe
419694b
ace2835
839b47b
bf739c9
b6755f7
5d93959
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
# the project for the full license. # | ||
# # | ||
##################################################################### | ||
"""Lyse analysis API | ||
""" | ||
Lyse analysis API | ||
""" | ||
|
||
from lyse.dataframe_utilities import get_series_from_shot as _get_singleshot | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also import |
||
|
@@ -25,7 +26,6 @@ | |
import contextlib | ||
|
||
import labscript_utils.h5_lock, h5py | ||
from labscript_utils.labconfig import LabConfig | ||
import pandas | ||
from numpy import array, ndarray, where | ||
import types | ||
|
@@ -36,7 +36,13 @@ | |
from labscript_utils.ls_zprocess import zmq_get | ||
|
||
from labscript_utils.properties import get_attributes, get_attribute, set_attributes | ||
LYSE_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# lyse imports | ||
import lyse.dataframe_utilities | ||
import lyse.utils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little bit hesitant about this One solution would be to make a |
||
|
||
# Import this way so LYSE_DIR is exposed when someone does import lyse or from lyse import * | ||
from lyse.utils import LYSE_DIR | ||
|
||
# If running stand-alone, and not from within lyse, the below two variables | ||
# will be as follows. Otherwise lyse will override them with spinning_top = | ||
|
@@ -55,13 +61,6 @@ | |
# a flag to determine whether we should wait for the delay event | ||
_delay_flag = False | ||
|
||
# get port that lyse is using for communication | ||
try: | ||
_labconfig = LabConfig(required_params={"ports": ["lyse"]}) | ||
_lyse_port = int(_labconfig.get('ports', 'lyse')) | ||
except Exception: | ||
_lyse_port = 42519 | ||
|
||
if len(sys.argv) > 1: | ||
path = sys.argv[1] | ||
else: | ||
|
@@ -80,7 +79,7 @@ class _RoutineStorage(object): | |
routine_storage = _RoutineStorage() | ||
|
||
|
||
def data(filepath=None, host='localhost', port=_lyse_port, timeout=5, n_sequences=None, filter_kwargs=None): | ||
def data(filepath=None, host='localhost', port=lyse.utils.LYSE_PORT, timeout=5, n_sequences=None, filter_kwargs=None): | ||
"""Get data from the lyse dataframe or a file. | ||
|
||
This function allows for either extracting information from a run's hdf5 | ||
|
@@ -161,7 +160,7 @@ def data(filepath=None, host='localhost', port=_lyse_port, timeout=5, n_sequence | |
|
||
# Allow sending 'get dataframe' (without the enclosing list) if | ||
# n_sequences and filter_kwargs aren't provided. This is for backwards | ||
# compatability in case the server is running an outdated version of | ||
# compatibility in case the server is running an outdated version of | ||
# lyse. | ||
if n_sequences is None and filter_kwargs is None: | ||
command = 'get dataframe' | ||
|
@@ -178,35 +177,9 @@ def data(filepath=None, host='localhost', port=_lyse_port, timeout=5, n_sequence | |
raise ValueError(dedent(msg)) | ||
# Ensure conversion to multiindex is done, which needs to be done here | ||
# if the server is running an outdated version of lyse. | ||
_rangeindex_to_multiindex(df, inplace=True) | ||
lyse.dataframe_utilities.rangeindex_to_multiindex(df, inplace=True) | ||
return df | ||
|
||
def _rangeindex_to_multiindex(df, inplace): | ||
if isinstance(df.index, pandas.MultiIndex): | ||
# The dataframe has already been converted. | ||
return df | ||
try: | ||
padding = ('',)*(df.columns.nlevels - 1) | ||
try: | ||
integer_indexing = _labconfig.getboolean('lyse', 'integer_indexing') | ||
except (LabConfig.NoOptionError, LabConfig.NoSectionError): | ||
integer_indexing = False | ||
if integer_indexing: | ||
out = df.set_index(['sequence_index', 'run number', 'run repeat'], inplace=inplace, drop=False) | ||
# out is None if inplace is True, and is the new dataframe is inplace is False. | ||
if not inplace: | ||
df = out | ||
else: | ||
out = df.set_index([('sequence',) + padding,('run time',) + padding], inplace=inplace, drop=False) | ||
if not inplace: | ||
df = out | ||
df.index.names = ['sequence', 'run time'] | ||
except KeyError: | ||
# Empty DataFrame or index column not found, so fall back to RangeIndex instead | ||
pass | ||
df.sort_index(inplace=True) | ||
return df | ||
|
||
def globals_diff(run1, run2, group=None): | ||
"""Take a diff of the globals between two runs. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this newline make it inconsistent with the other docstring formatting? If any changes were to be made here, I'd suggest a single line
"""Lyse analysis API"""
docstring given how short it is.