Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions bin/ibw_to_mat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python

import argparse
import os
import sys

import numpy as np
import scipy.io as sio

script_dir = os.path.dirname(os.path.abspath(__file__))
vendor_dir = os.path.join(script_dir, "..", "vendor")
sys.path.insert(0, vendor_dir)

from ibwpy import ibwpy


def create_parser():
parser = argparse.ArgumentParser(
description="Combine Igor Binary Wave files into a single matlab file that "
"can be read by ASCAM."
)
parser.add_argument("current", help="Current .ibw file.")
parser.add_argument("--command", help="Command Voltage .ibw file.")
parser.add_argument("--piezo", help="Piezo Voltage .ibw file.")
parser.add_argument(
"--sampling-rate",
dest="sampling_rate",
default=25000,
help="Piezo Voltage .ibw file.",
)
parser.add_argument("--output", help="Output filename.")

return parser


def main():
parser = create_parser()
args = parser.parse_args()

# Load the three IBW files
current_data = ibwpy.load(args.current).array
if args.command:
command_data = ibwpy.load(args.command).array
if args.piezo:
piezo_data = ibwpy.load(args.piezo).array

# Sampling parameters
num_points = current_data.shape[0] # Number of data points per sweep
num_sweeps = current_data.shape[1] # Number of sweeps

# Create the time vector
time_vector = np.arange(num_points) / args.sampling_rate

# Create a dictionary to hold the data for ASCAM
ascam_data = {
"c001_Time": time_vector # Time variable
}

# Populate the dictionary with data for each sweep
for i in range(num_sweeps):
# For each sweep, assign the corresponding data for Ipatch, Piezo, and Command
ascam_data[f"c002_Ipatch_{i + 1}"] = current_data[:, i]
if args.piezo:
ascam_data[f"c003_Piezo_{i + 1}"] = piezo_data[:, i]
if args.command:
ascam_data[f"c004_Command_{i + 1}"] = command_data[:, i]

# Save the data to a .mat file
sio.savemat(args.output, ascam_data)


if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions vendor/ibwpy/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Hiroaki Takahashi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions vendor/ibwpy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ibwpy
Read and write [Igor Pro](https://www.wavemetrics.com/) files (Igor binary wave) with Python

## Installation
### Install with pip (using Git, recommended)
1. Install ibwpy with pip
```bash
$ python -m pip install git+https://github.com/MiLL4U/ibwpy.git
```

### Install with pip (without Git)
1. download a wheel package (*.whl) from [Releases](https://github.com/MiLL4U/ibwpy/releases)

2. Install ibwpy with pip
```bash
$ python -m pip install ibwpy-x.y.z-py3-none-any.whl
```
<span style="color: #FFAAAA">(replace x.y.z with the version of ibwpy which you downloaded)</span>

### Install with git clone
1. Clone this repository

```bash
$ git clone https://github.com/MiLL4U/ibwpy.git
```

2. Go into the repository

```bash
$ cd ibwpy
```

3. Install ibwpy with setup.py

```bash
$ python setup.py install
```

## Examples
### Read
Read wave from ibw file:
```python
import ibwpy as ip
test_wave = ip.load("test_wave.ibw")
print(test_wave)
```

### Make
Make new wave from Numpy array
```python
import numpy as np

arr_1 = np.array([[1., 2., 3.],
[1.5, 2.5, 3.5]])
wave_1 = ip.from_nparray(arr_1, 'wave1')
# wave1 (IgorBinaryWave)
# [[1. 2. 3. ]
# [1.5 2.5 3.5]]
```

### Calculation
Treat wave as NumPy array:
```python
arr_2 = np.ones((2, 3))
print(arr_2)
# [[1. 1. 1.]
# [1. 1. 1.]]

wave_1 = wave_1 + arr_2
print(wave_1)
# wave1 (IgorBinaryWave)
# [[2. 3. 4. ]
# [2.5 3.5 4.5]]
```

### Save
Save wave as ibw file
```python
wave_1.save("wave1.ibw")
```
38 changes: 38 additions & 0 deletions vendor/ibwpy/ibwpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
IBWPy
=====

Provides
1. Functions for reading/writing Igor binary wave (*.ibw) directly
2. Interfaces to edit ibw files as NumPy array
"""

from typing import List, Tuple, Union

import numpy as np

from .constants import DEFAULT_DTYPE, IBWDType
from .igorbinarywave import BinaryWave5, BinaryWave5Loader
from .waveheader import BinaryWaveHeader5


def make(shape: Union[List[int], Tuple[int, ...]],
name: str, dtype: IBWDType = DEFAULT_DTYPE) -> BinaryWave5:
shape_tuple = tuple(shape)
header = BinaryWaveHeader5(shape=shape_tuple, name=name, dtype=dtype)
zeros = np.zeros(shape, dtype=dtype)
res = BinaryWave5(ibw_header=header, wave_values=zeros)
return res


def from_nparray(array: np.ndarray, name: str) -> BinaryWave5:
header = BinaryWaveHeader5(shape=array.shape, name=name,
dtype=str(array.dtype))
res = BinaryWave5(ibw_header=header, wave_values=array)
return res


def load(path: str) -> BinaryWave5:
loader = BinaryWave5Loader(path)
res = loader.load()
return res
9 changes: 9 additions & 0 deletions vendor/ibwpy/ibwpy/commonfunc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .constants import TEXT_ENCODE, TEXT_ENCODE_2ND


def decode_unicode(text_buf: bytes):
try:
res = text_buf.decode(TEXT_ENCODE)
except UnicodeDecodeError:
res = text_buf.decode(TEXT_ENCODE_2ND)
return res
17 changes: 17 additions & 0 deletions vendor/ibwpy/ibwpy/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import datetime

from typing_extensions import Literal

IBWPY_VERSION = "1.0.4"

IBWDType = Literal['float32', 'float64', 'int8', 'int16', 'int32']
DEFAULT_DTYPE: IBWDType = 'float32'

WAVE_HEADER_SIZE = 320

DATETIME_OFFSET = datetime.datetime(1904, 1, 1, 0, 0, 0)
MAX_WAVE_NAME_LENGTH = 31

TEXT_ENCODE = 'utf-8'
TEXT_ENCODE_2ND = 'shift_jis'
DEFAULT_EOL = '\r'
Loading