Skip to content

Commit

Permalink
finish implementation of review to #11
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottSoren committed Nov 11, 2021
1 parent 399290e commit 878b578
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/ixdat/backends/backend_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BackendBase:

backend_type = "none"
address = "none"
"""A location uniquely identifying the backend together with its type"""

def __init__(self):
"""Initialize the backend with dict for {table_name (str): id_counter (int)}"""
Expand Down
2 changes: 1 addition & 1 deletion src/ixdat/backends/directory_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(

@property
def address(self):
""""""
"""The directory containing the tables (folders) and rows (.ix files)"""
return str(self.project_directory)

def save(self, obj, force=False, no_updates=True):
Expand Down
4 changes: 2 additions & 2 deletions src/ixdat/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ def get_object(self):
return self.cls.get(self.id, backend=self.backend)

@property
def identity(self):
"""Placeholder also has an short_identity to check equivalence without loading"""
def short_identity(self):
"""Placeholder also has a short_identity to check equivalence without loading"""
if self.backend is DB.backend:
return self.id
return self.backend, self.id
Expand Down
12 changes: 7 additions & 5 deletions src/ixdat/exporters/csv_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class CSVExporter:
"""The default exporter, which writes delimited measurement data row-wise to file"""

def __init__(self, measurement=None, delim=",\t", default_v_list=None):
def __init__(self, measurement=None, delimiter=",\t", default_v_list=None):
"""Initiate the exported with a measurement (Measurement) and delimiter (str)"""
self.measurement = measurement
self.delim = delim
self.delimiter = delimiter
self._default_v_list = default_v_list

@property
Expand Down Expand Up @@ -49,7 +49,9 @@ def export_measurement(self, measurement, path_to_file, v_list=None, tspan=None)
s_list.append(v_name)

header_line = (
"".join([s_name + self.delim for s_name in s_list])[: -len(self.delim)]
"".join([s_name + self.delimiter for s_name in s_list])[
: -len(self.delimiter)
]
+ "\n"
)

Expand All @@ -61,10 +63,10 @@ def export_measurement(self, measurement, path_to_file, v_list=None, tspan=None)
for s_name in s_list:
if len(columns_data[s_name]) > n:
# Then put the data there:
line = line + str(columns_data[s_name][n]) + self.delim
line = line + str(columns_data[s_name][n]) + self.delimiter
else:
# No more data in this column. Just hold alignment:
line = line + self.delim
line = line + self.delimiter
line = line + "\n"
lines.append(line)

Expand Down
2 changes: 1 addition & 1 deletion src/ixdat/exporters/ec_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ECExporter(CSVExporter):
def default_v_list(self):
"""The default v_list for ECExporter is V_str, J_str, and sel_str"""
return [
# self.measurement.t_str,
# self.measurement.t_name,
self.measurement.v_name,
self.measurement.j_name,
self.measurement.selector_name,
Expand Down
10 changes: 7 additions & 3 deletions src/ixdat/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def t(self):
return self[self.control_series_name].t

@property
def t_str(self):
def t_name(self):
return self[self.control_series_name].tseries.name

def _build_file_number_series(self):
Expand Down Expand Up @@ -580,12 +580,12 @@ def data_cols(self):
"""Return a set of the names of all of the measurement's VSeries and TSeries"""
return set([s.name for s in (self.value_series + self.time_series)])

def get_original_m_id_of_series(self, series):
def get_original_m_ids_of_series(self, series):
"""Return a list of id's of component measurements to which `series` belongs."""
m_id_list = []
for m in self.component_measurements:
if series.short_identity in m.s_ids:
# FIXME: the whole id vs identity issue
# FIXME: the whole id vs short_identity issue
# see https://github.com/ixdat/ixdat/pull/11#discussion_r746632897
m_id_list.append(m.id)
return m_id_list
Expand Down Expand Up @@ -807,6 +807,10 @@ def select(self, *args, tspan=None, **kwargs):
new_measurement = new_measurement.select_values(*args, **kwargs)
return new_measurement

def copy(self):
"""Make a copy of the Measurement via its dictionary representation"""
return self.__class__.from_dict(self.as_dict())

def __add__(self, other):
"""Addition of measurements appends the series and component measurements lists.
Expand Down
29 changes: 10 additions & 19 deletions tests/test_biologic_ec_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,16 @@

path_to_file = Path(__file__).parent.parent / "test_data/biologic/Pt_poly_cv.mpt"
change_database("directory", project_name="test_biologic_ec_measurement")
# TODO: Use a temporary directory.
# see: https://github.com/ixdat/ixdat/pull/11#discussion_r677567528


class TestLog:
def __init__(self, path_to_file="~/git/ixdat_test_output.txt"):
self.path_to_file = Path(path_to_file).expanduser()
with open(self.path_to_file, "w") as f:
f.write("\n" + "-" * 80 + "\n")
f.write(f"RUNNING MODULE {__file__} AT t={time.time()}\n")
f.write("-" * 80 + "\n")

def print(self, s):
with open(self.path_to_file, "a") as f:
f.write(s + "\n")


log = TestLog()
log.print(f"cwd = {Path('.').absolute().resolve()}")
print(f"cwd = {Path('.').absolute().resolve()}")


def test_append_essential_series():
# TODO: break this up into functions testing specific things.
meas = Measurement.read(path_to_file, reader="biologic")
log.print(f"successfully read {meas}")
print(f"successfully read {meas}")

assert meas.technique == "EC"
assert len(meas["potential"].data) == len(meas["time/s"].data)
Expand All @@ -55,8 +43,9 @@ def test_append_essential_series():


def test_save_load():
# TODO: break this up into functions testing specific things.
meas = Measurement.read(path_to_file, reader="biologic")
log.print(f"successfully read {meas}")
print(f"successfully read {meas}")

# To make it complex, we first select a couple cycles, this time with select(),
# and append them:
Expand Down Expand Up @@ -107,8 +96,10 @@ def test_save_load():


if __name__ == "__main__":
# TODO: probably doesn't beling here.
# See https://github.com/ixdat/ixdat/pull/11#discussion_r677996529
meas = Measurement.read(path_to_file, reader="biologic")
log.print(f"successfully read {meas}")
print(f"successfully read {meas}")

# To make it complex, we first select a couple cycles, this time with select(),
# and append them:
Expand Down

0 comments on commit 878b578

Please sign in to comment.