core module
- class lys.core.DaskWave(data, *axes, chunks='auto', **note)[source]
Bases:
QObjectDaskWave class is a central data class in lys, which is used for easy parallel computing via dask.
This class is mainly used for parallel computing of data with axes and notes, which enables us to consistent calculation of data and axes. Particularly, DaskWave is extensively used in MultiCut.
datais a dask array of any dimension. SeeWaveforaxesandnote.Semi-automatic parallel computing is executed when lys is launched with parallel computing option (-n).
See dask manual in https://docs.dask.org/en/latest/ for detailed usage of dask array.
All public methods in data, axes, and note are accessible from DaskWave class through __getattr__.
DaskWave and Wave can easily be converted to each other via construtor of DaskWave and
compute()method.- Parameters:
data (Wave or array_like or dask array) – The data of any dimension
axes (list of array_like) – The axes of data
note (dict) – metadata for Wave.
chunks ('auto' or tuple) – chunks to be used for dask array.
Example1:
from lys import Wave, DaskWave w = Wave([1,2,3]) # Initial wave dw = DaskWave(w) # Convert to DaskWave dw.data *= 2 result = dw.compute() # Parallel computing is executed through dask. Result is Wave. print(result,data) # [2,4,6]
Example2:
from lys import Wave, DaskWave dw = DaskWave([1,2,3]) # through dask.array.from_array dw.compute().data # [1,2,3]
Example3:
from lys import Wave, DaskWave import dask.array as da arr = da.from_array([1,2,3]) # dask array can be prepared by other mehotds, such as dask.delayed if data is huge dw = DaskWave(arr) dw.compute().data #[1,2,3]
- axes
Axes of
WaveandDaskWaveimplemented asWaveAxesclass.axes is list of numpy arrays and is used to visualize data.
All public methods in WaveAxes class can also be accessed from
WaveandDaskWavethrough __getattr__.Example:
from lys import Wave w = Wave(np.ones([3,3]), [1,2,3], [4,5,6]) print(w.axes) # [array([1, 2, 3]), array([4, 5, 6])] w.axes[0] = [7,8,9] print(w.axes) # [array([7, 8, 9]), array([4, 5, 6])] print(w.x, w.y) # [7,8,9], [4,5,6], shortcut to axes[0] and axes[1]
See also
WaveAxes,x,y,z
- compute()[source]
Return calculated Wave.
Wave.data.compute() is called when this method is called.
After lazy evaluation is finished, this method returns calculated Wave.
- Returns:
cauculated result
- Return type:
- data
data is dask array that represents data of
DaskWaveAll public methods of data can be accessed from
DaskWavevia __getattr__.
- duplicate()[source]
Create duplicated DaskWave
- Returns:
duplicated wave.
- Return type:
Example:
from lys import DaskWave w = DaskWave([1,2,3]) w2=w.duplicate() print(w2.compute().data) # [1,2,3]
- classmethod initWorkers(n_workers, threads_per_worker=1)[source]
Initializa local cluster. This method is automatically called when lys is launched with parallel computing option. DO NOT call this method within lys.
- Parameters:
n_workers (int) – number of workers to be launched.
threads_per_worker (int) – number of therads for each worker.
- note
Metadata of
WaveandDaskWaveimplemented asWaveNoteclass.All public methods can also be accessed from
WaveandDaskWavethrough __getattr__.note is python dictionary and is used to save metadata in
WaveDaskWaveclass.Example:
from lys import Wave w = Wave([1,2,3], key = "item") print(w.note["key"]) # item w.note["key2"] = 1111 print(w.note["key2"]) # 1111
- class lys.core.SettingDict(file=None)[source]
Bases:
dictWrapped dict, internally used to automatically save settings
SettingDict is wrapper of dict that is is automatically saved when __setitem__ and __delitem__ are called.
If file is not specified, SettingDict behave as normal dict class.
If file does not exist, the file is automatically created.
- Parameters:
file (string) – The filename to be loaded and saved
Examples:
from lys import SettingDict d = SettingDict("Setting.dic") d["setting1"] = "SettingString" d2 = SettingDict("Setting.dic") # setting.dic is loaded d2["setting1"] # SettingString
- class lys.core.Wave(data=None, *axes, **note)[source]
Bases:
QObjectWave class is a central data class in lys, which is composed of
data,axes, andnote.datais a numpy array of any dimension andaxesis a list of numpy arrays with size = data.ndim.noteis a dictionary, which is used to save metadata.All public methods in data, axes, and note are accessible from Wave class through __getattr__.
There are several ways to generate Wave. (See Examples).
- Parameters:
data (array_like or str) – The data of any dimension, or filename to be loaded
axes (list of array_like) – The axes of data
note (dict) – metadata for Wave.
Basic initialization without axes and note:
from lys import Wave w = Wave([1,2,3]) # Axes are automatically set. print(w.data, w.x) # [1 2 3] [0. 1. 2.]
Basic initialization with axes and note:
from lys import Wave w = Wave(np.ones([2,3]), [1,2], [1,2,3], name="wave1") print(w.axes) # [array([1, 2]), array([1, 2, 3])] print(w.x) # [1 2], axes can be accessed from Wave.x, Wave.y etc... print(w.note) # {'name': 'wave1'}, keyword arguments are saved in note
Initialize Wave from array of Wave:
from lys import Wave w = Wave([1,2,3], [4,5,6]) w2 = Wave([w,w], [7,8]) print(w2.data) # [[1 2 3], [1 2 3]] print(w2.x, w2.y) # [7,8], [4,5,6]
Save & load numpy npz file:
from lys import Wave w = Wave([1,2,3]) w.export("wave.npz") # save wave to wave.npz w2 = Wave("wave.npz") print(w2.data) # [1 2 3]
Direct access numpy array methods:
from lys import Wave w = Wave(np.zeros((100,100))) print(w.shape) # (100,100)
- axes
Axes of
WaveandDaskWaveimplemented asWaveAxesclass.axes is list of numpy arrays and is used to visualize data.
All public methods in WaveAxes class can also be accessed from
WaveandDaskWavethrough __getattr__.Example:
from lys import Wave w = Wave(np.ones([3,3]), [1,2,3], [4,5,6]) print(w.axes) # [array([1, 2, 3]), array([4, 5, 6])] w.axes[0] = [7,8,9] print(w.axes) # [array([7, 8, 9]), array([4, 5, 6])] print(w.x, w.y) # [7,8,9], [4,5,6], shortcut to axes[0] and axes[1]
See also
WaveAxes,x,y,z
- data
data is numpy.ndarray that represents data of
WaveAll public methods of data can also be accessed from
Wave.Any type of sequential array will be automatically converted to numpy.ndarray when it is set as data.
Example:
from lys import Wave w = Wave([1,2,3]) print(w.data) # [1,2,3] w.data = [2,3,4] print(w.data) # [2,3,4]
- duplicate()[source]
Create duplicated Wave
- Returns:
Duplicated wave.
- Return type:
Example:
from lys import Wave w = Wave([1,2,3]) w2=w.duplicate() print(w2.data) # [1,2,3]
- export(path, type='npz')[source]
Export Wave to file.
- Parameters:
path (str) – File path to be saved.
type (str) – File extension. See
SupportedFormats().
Exmple:
from lys import Wave w = Wave([1,2,3]) w.export("wave.npz") w2 = Wave.importFrom("wave.npz") print(w2.data) # [1,2,3] w3 = Wave("wave.npz") # If the file is .npz, this is also possible.
See also
- static importFrom(path)[source]
Import Wave from file.
- Parameters:
path (str) – File path to be saved.
type (str) – File extension. See
SupportedFormats().
See also
- modified
modified is a pyqtSignal, which is emitted when Wave is changed.
Example:
from lys import Wave w = Wave([1,2,3], name="wave1") w.modified.connect(lambda w: print("modified", w.name)) w.data = [2,3,4] # modified wave1
- note
Metadata of
WaveandDaskWaveimplemented asWaveNoteclass.All public methods can also be accessed from
WaveandDaskWavethrough __getattr__.note is python dictionary and is used to save metadata in
WaveDaskWaveclass.Example:
from lys import Wave w = Wave([1,2,3], key = "item") print(w.note["key"]) # item w.note["key2"] = 1111 print(w.note["key2"]) # 1111
- update()[source]
Emit modified signal
When data is directly changed by indexing, modified signal is not emitted. Calling update() emit modified signal manually.
Example:
from lys import Wave w = Wave([1,2,3]) w.modified.connect(lambda: print("modified")) w.data = [0, 1, 2] # modified, modified is emitted when Wave.data is changed. w.data[1] = 0 # modified is NOT emitted through data.__setitem__ is called. w.update() # modified
- class lys.core.WaveAxes(parent, axes, force=False)[source]
Bases:
listAxes in
WaveandDaskWaveclassWaveAxes is a list of numpy array that defines axes of the
WaveandDaskWave.All public methods in WaveAxes can also be accessed from
WaveandDaskWavethrough __getattr__.Some usufull functions are added to built-in list.
WaveAxes should be initialized from
WaveandDaskWaveclass. Users SHOULD NOT directly instantiate this class.- getAxis(dim)[source]
Shortcut to wave.axes[dim]
- Parameters:
dim (int) – The dimension of the axis.
- Returns:
The axis of the specified dimension.
- Return type:
numpy.ndarray
- pointToPos(indice, axis=None)[source]
Translate the specified indice to the position in data.
This method can be accessed directly from
WaveandDaskWaveclass through __getattr__.If axis is None, then indice should be array of size = data.ndim. indice = (n1, n2, n3, …) is translated to position (x, y, z, …)
If axis is not None, then indice is interpreted as indice in axis-th dimension. When axis = 1, indice = (n1, n2, n3, …) is translated to positions (y1, y2, y3, …)
- Parameters:
indice (array of int) – The indice that is translted to position.
axis (None or int) – see above description
- Returns:
The position corresponding to indice.
- Return type:
tuple or float
Example:
from lys import Wave w = Wave(np.ones([3,3]), [1,2,3], [3,4,5]) w.pointToPos((1,1)) # (2,4), index (1,1) corresponds to position (x,y)=(2,4) w.pointToPos((0,1,2), axis=0) # (1,2,3), index (0,1,2) in the 0th dimension correspoinds position (x1, x2, x3 = 1,2,3) w.pointToPos(1, axis=0) # 2, index 1 in 0th dimensions correspoinds position x = 2
- posToPoint(pos, axis=None)[source]
Translate the specified position in axis to the nearest indice in data.
This method can be accessed directly from
WaveandDaskWaveclass through __getattr__.If axis is None, then pos should be array of size = data.ndim. pos = (x,y,z,…) is translated to indice (n1, n2, n3, …)
if axis is not None, then pos is interpreted as position in axis-th dimension. When axis = 1, pos = (y1, y2, y3, …) is translated to indice (n1, n2, n3, …)
- Parameters:
pos (numpy.ndarray or float) – The position that is translted to indice.
axis (None or int) – see above description
- Returns:
The indice corresponding to pos.
- Return type:
tuple or int
Example:
from lys import Wave w = Wave(np.ones([3,3]), [1,2,3], [3,4,5]) w.posToPoint((2,4)) # (1,1), position (x,y)=(2,4) corresponds index (1,1) w.posToPoint((1,2,3), axis=0) # (0,1,2), position (x1, x2, x3 = 1,2,3) in the 0th dimension correspoinds index (0,1,2) w.posToPoint(2, axis=0) # 1, position x = 2 correspoinds index 1 in 0th dimension
- property x
Shortcut to axes[0]
- property y
Shortcut to axes[1].
- property z
Shortcut to axes[2].
- class lys.core.WaveNote[source]
Bases:
dictNote in
WaveandDaskWaveclassWaveNote is a dictionary to save metadata in
WaveandDaskWaveclass. All public methods can also be accessed fromWaveandDaskWavethrough __getattr__. Some usufull functions are added to built-in dict.WaveNote should be initialized from
WaveandDaskWaveclass. Users SHOULD NOT directly instantiate this class.