From 8899b01fe7c8538d89488489c6c2b4d286b095f1 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Fri, 22 Oct 2021 13:23:49 -0500 Subject: [PATCH 1/6] Update _solis.py imports series working example --- WrightTools/data/_solis.py | 63 ++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/WrightTools/data/_solis.py b/WrightTools/data/_solis.py index d77be5f35..2eb7a296b 100644 --- a/WrightTools/data/_solis.py +++ b/WrightTools/data/_solis.py @@ -30,7 +30,7 @@ def from_Solis(filepath, name=None, parent=None, verbose=True) -> Data: Parameters ---------- filepath : path-like - Path to .txt file. + Path to file (should be .asc format). Can be either a local or remote file (http/ftp). Can be compressed with gz/bz2, decompression based on file name. name : string (optional) @@ -61,15 +61,33 @@ def from_Solis(filepath, name=None, parent=None, verbose=True) -> Data: axis0 = [] arr = [] attrs = {} - while True: + for i in range(2): line = f.readline().strip()[:-1] - if len(line) == 0: - break - else: - line = line.split(",") - line = [float(x) for x in line] - axis0.append(line.pop(0)) - arr.append(line) + line = [float(x) for x in line.split(",")] # TODO: robust to space, tab, comma + axis0.append(line.pop(0)) + arr.append(line) + axis0_increasing = axis0[1] - axis0[0] > 0 + + def get_frames(f, arr, axis0, increasing): + axis0_written = False + while True: + line = f.readline().strip()[:-1] + if len(line) == 0: + break + else: + line = [float(x) for x in line.split(",")] + # signature of new frames is restart of axis0 + if not axis0_written and ((line[0] - axis0[-1] > 0) != increasing): + axis0_written = True + if axis0_written: + line.pop(0) + else: + axis0.append(line.pop(0)) + arr.append(line) + return arr, axis0 + + arr, axis0 = get_frames(f, arr, axis0, axis0_increasing) + nframes = len(arr) // len(axis0) i = 0 while i < 3: @@ -94,10 +112,7 @@ def from_Solis(filepath, name=None, parent=None, verbose=True) -> Data: data = Data(**kwargs) else: data = parent.create_data(**kwargs) - arr = np.array(arr) - arr /= float(attrs["Exposure Time (secs)"]) - # signal has units of Hz because time normalized - arr = data.create_channel(name="signal", values=arr, signed=False, units="Hz") + axis0 = np.array(axis0) if float(attrs["Grating Groove Density (l/mm)"]) == 0: xname = "xindex" @@ -105,9 +120,25 @@ def from_Solis(filepath, name=None, parent=None, verbose=True) -> Data: else: xname = "wm" xunits = "nm" - data.create_variable(name=xname, values=axis0[:, None], units=xunits) - data.create_variable(name="yindex", values=np.arange(arr.shape[1])[None, :], units=None) - data.transform(data.variables[0].natural_name, "yindex") + axes = [xname, "yindex"] + + if nframes == 1: + arr = np.array(arr) + data.create_variable(name=xname, values=axis0[:, None], units=xunits) + data.create_variable(name="yindex", values=np.arange(arr.shape[-1])[None, :], units=None) + else: + arr = np.array(arr).reshape(nframes, len(axis0), len(arr[0])) + data.create_variable(name="frame", values=np.arange(nframes)[:, None, None], units=None) + data.create_variable(name=xname, values=axis0[None, :, None], units=xunits) + data.create_variable(name="yindex", values=np.arange(arr.shape[-1])[None, None, :], units=None) + axes = ["frame"] + axes + + data.transform(*axes) + print(f"arr.shape {arr.shape}") + print(f'nframes {nframes}') + arr /= float(attrs["Exposure Time (secs)"]) + # signal has units of Hz because time normalized + data.create_channel(name="signal", values=arr, signed=False, units="Hz") for key, val in attrs.items(): data.attrs[key] = val From 1bee64cc9891ea5d6b57c251a6a23c7ac31bb7fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Oct 2021 18:03:16 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- WrightTools/data/_solis.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WrightTools/data/_solis.py b/WrightTools/data/_solis.py index 2eb7a296b..071812996 100644 --- a/WrightTools/data/_solis.py +++ b/WrightTools/data/_solis.py @@ -130,12 +130,14 @@ def get_frames(f, arr, axis0, increasing): arr = np.array(arr).reshape(nframes, len(axis0), len(arr[0])) data.create_variable(name="frame", values=np.arange(nframes)[:, None, None], units=None) data.create_variable(name=xname, values=axis0[None, :, None], units=xunits) - data.create_variable(name="yindex", values=np.arange(arr.shape[-1])[None, None, :], units=None) + data.create_variable( + name="yindex", values=np.arange(arr.shape[-1])[None, None, :], units=None + ) axes = ["frame"] + axes data.transform(*axes) print(f"arr.shape {arr.shape}") - print(f'nframes {nframes}') + print(f"nframes {nframes}") arr /= float(attrs["Exposure Time (secs)"]) # signal has units of Hz because time normalized data.create_channel(name="signal", values=arr, signed=False, units="Hz") From b9e7a29b8c970d6c6a9e6eacfcf34fe25eb30775 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 25 Oct 2021 13:28:26 -0500 Subject: [PATCH 3/6] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1d5bb8b4..c479ed549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] +### Added +- `data.from_Solis`: "kinetic series" acquisition type now supported. + ## [3.4.1] ### Added From 681422f06bb7c57fbdcf9388372a89fce13d3817 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 25 Oct 2021 13:35:09 -0500 Subject: [PATCH 4/6] Update _solis.py refactor frame detection --- WrightTools/data/_solis.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/WrightTools/data/_solis.py b/WrightTools/data/_solis.py index 071812996..372658100 100644 --- a/WrightTools/data/_solis.py +++ b/WrightTools/data/_solis.py @@ -61,14 +61,13 @@ def from_Solis(filepath, name=None, parent=None, verbose=True) -> Data: axis0 = [] arr = [] attrs = {} - for i in range(2): - line = f.readline().strip()[:-1] - line = [float(x) for x in line.split(",")] # TODO: robust to space, tab, comma - axis0.append(line.pop(0)) - arr.append(line) - axis0_increasing = axis0[1] - axis0[0] > 0 - - def get_frames(f, arr, axis0, increasing): + + line0 = f.readline().strip()[:-1] + line0 = [float(x) for x in line0.split(",")] # TODO: robust to space, tab, comma + axis0.append(line0.pop(0)) + arr.append(line0) + + def get_frames(f, arr, axis0): axis0_written = False while True: line = f.readline().strip()[:-1] @@ -77,7 +76,7 @@ def get_frames(f, arr, axis0, increasing): else: line = [float(x) for x in line.split(",")] # signature of new frames is restart of axis0 - if not axis0_written and ((line[0] - axis0[-1] > 0) != increasing): + if not axis0_written and (line[0] == axis0[0]): axis0_written = True if axis0_written: line.pop(0) @@ -86,7 +85,7 @@ def get_frames(f, arr, axis0, increasing): arr.append(line) return arr, axis0 - arr, axis0 = get_frames(f, arr, axis0, axis0_increasing) + arr, axis0 = get_frames(f, arr, axis0) nframes = len(arr) // len(axis0) i = 0 @@ -136,8 +135,6 @@ def get_frames(f, arr, axis0, increasing): axes = ["frame"] + axes data.transform(*axes) - print(f"arr.shape {arr.shape}") - print(f"nframes {nframes}") arr /= float(attrs["Exposure Time (secs)"]) # signal has units of Hz because time normalized data.create_channel(name="signal", values=arr, signed=False, units="Hz") From 1104177d2a40a9709a3f6adc015b41c241f09e58 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Mon, 25 Oct 2021 15:17:48 -0500 Subject: [PATCH 5/6] test --- WrightTools/datasets/Solis/kinetic.asc.gz | Bin 0 -> 2852 bytes tests/data/from_Solis.py | 9 +++++++++ 2 files changed, 9 insertions(+) create mode 100644 WrightTools/datasets/Solis/kinetic.asc.gz diff --git a/WrightTools/datasets/Solis/kinetic.asc.gz b/WrightTools/datasets/Solis/kinetic.asc.gz new file mode 100644 index 0000000000000000000000000000000000000000..84ea4de54cf7230a838c88869437da6eace0e919 GIT binary patch literal 2852 zcmV+<3)}P`iwFoE5O-k$|7&S(Wprs{E@5+H0F7JQa@$A_eOHzKfsdXlJ4?{IH2s!! zHkqldWHNDT_E}MAo3*s4k*Q=nQ~U4Rl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do5da`#x?H_6?;D842a$Nq%pvybJUMV0jS{M5R_#rxrG zveXZ0ZSQ9|pNg{fdf^@EgYtoBd{6 zHZMQ<+4sjoSs$O14|Qvhw`J7?Px Date: Mon, 25 Oct 2021 20:18:08 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/data/from_Solis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/data/from_Solis.py b/tests/data/from_Solis.py index eff7ffcb8..c29657272 100644 --- a/tests/data/from_Solis.py +++ b/tests/data/from_Solis.py @@ -28,6 +28,7 @@ def test_xpos_ypos_fluorescence(): assert data.units == (None, None) data.close() + def test_kinetic(): p = datasets.Solis.kinetic data = wt.data.from_Solis(p)