Skip to content

Commit

Permalink
Merge pull request #208 from pycroscopy/gerd4
Browse files Browse the repository at this point in the history
update
  • Loading branch information
gduscher committed May 20, 2024
2 parents 64dde6d + d89f42d commit 8136fda
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion notebooks/00_basic_usage/create_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2623,7 +2623,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.7"
},
"toc": {
"base_numbering": 1,
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',

'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Cython',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering :: Information Analysis'],
keywords=['imaging', 'spectra', 'multidimensional', 'scientific',
Expand All @@ -60,7 +61,7 @@
author_email='pycroscopy@gmail.com',
install_requires=requirements,

tests_require=['unittest2;python_version<"3.0"', 'pytest'],
tests_require=['pytest'],
platforms=['Linux', 'Mac OSX', 'Windows 10/8.1/8/7'],
# package_data={'sample':['dataset_1.dat']}
test_suite='pytest',
Expand Down
2 changes: 1 addition & 1 deletion sidpy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = '0.12.3'
time = '2024-01-09 10:30:00'
time = '2024-01-19 10:30:00'
32 changes: 18 additions & 14 deletions sidpy/sid/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def from_array(cls, x, title='generic', chunks='auto', lock=False,
the title of this dataset
lock: boolean
datatype: str or sidpy.DataType
data type of set: i.e.: 'image', spectrum', ..
data type of set: i.e.: 'image', 'spectrum', ...
units: str
units of dataset i.e. counts, A
quantity: str
Expand Down Expand Up @@ -328,7 +328,7 @@ def like_data(self, data, title=None, chunks='auto', lock=False,
# if coordinates is None:
# coordinates = self.point_cloud['coordinates']

new_data = self.from_array(data, chunks=chunks, lock=lock, variance =variance)
new_data = self.from_array(data, chunks=chunks, lock=lock, variance=variance)

new_data.data_type = self.data_type

Expand Down Expand Up @@ -647,6 +647,9 @@ def plot(self, verbose=False, figure=None, **kwargs):
self.view = CurveVisualizer(self, figure=figure, **kwargs)
elif self.data_type == DataType.POINT_CLOUD:
self.view = PointCloudVisualizer(self, figure=figure, **kwargs)
elif self.data_type == DataType.SPECTRAL_IMAGE:
print('sp')
self.view = SpectralImageVisualizer(self, figure=figure, **kwargs)
else:
raise NotImplementedError('Datasets with data_type {} cannot be plotted, yet.'.format(self.data_type))
elif len(self.shape) == 3:
Expand Down Expand Up @@ -708,6 +711,8 @@ def set_thumbnail(self, figure=None, thumbnail_size=128):
Parameters
----------
figure : matplotlib figure object
optional figure directive for output
thumbnail_size: int
size of icon in pixels (length of square)
Expand Down Expand Up @@ -791,7 +796,6 @@ def get_dimensions_types(self):
out_types.append(axis.dimension_type)
return out_types


def get_dimensions_by_type(self, dims_in, return_axis=False):
""" get dimension by dimension_type name
Expand Down Expand Up @@ -821,7 +825,7 @@ def get_dimensions_by_type(self, dims_in, return_axis=False):

def get_image_dims(self, return_axis=False):
"""Get all spatial dimensions"""
return self.get_dimensions_by_type(DimensionType.SPATIAL, return_axis=return_axis)
return self.get_dimensions_by_type([DimensionType.SPATIAL,DimensionType.RECIPROCAL], return_axis=return_axis)

def get_spectral_dims(self, return_axis=False):
"""Get all spectral dimensions"""
Expand Down Expand Up @@ -1073,7 +1077,7 @@ def fft(self, dimension_type=None):
Returns
-------
fft_dset: 2D or 3D complex sidpy.Dataset (not tested for higher dimensions)
2 or 3 dimensional matrix arranged in the same way as input
2 or 3-dimensional matrix arranged in the same way as input
Example
-------
Expand Down Expand Up @@ -1237,7 +1241,7 @@ def all(self, axis=None, keepdims=False, split_every=None, out=None):
checkdims=False)
if self._variance is not None:
result._variance = self._variance.all(axis=axis, keepdims=keepdims,
split_every=split_every, out=out)
split_every=split_every, out=out)
return result, locals().copy()

@reduce_dims
Expand All @@ -1260,9 +1264,9 @@ def min(self, axis=None, keepdims=False, split_every=None, out=None):
if self._variance is not None:
if axis is not None:
_min_ind_axis = super().argmin(axis=axis, split_every=split_every, out=out)
_coords = np.array(list(np.ndindex(_min_ind_axis.shape))) #list?
_coords = np.array(list(np.ndindex(_min_ind_axis.shape))) # list?
_inds = np.insert(_coords, axis, np.array(_min_ind_axis).flatten(), axis=1)
_extracted_points = da.take(self._variance.flatten(), np.ravel_multi_index(_inds.T, (self._variance.shape)))
_extracted_points = da.take(self._variance.flatten(), np.ravel_multi_index(_inds.T, self._variance.shape))
result._variance = _extracted_points.reshape(result.shape).rechunk(result.chunksize)
else:
_ind = np.unravel_index(super().min(), self._variance.shape)
Expand All @@ -1279,9 +1283,9 @@ def max(self, axis=None, keepdims=False, split_every=None, out=None):
if self._variance is not None:
if axis is not None:
_max_ind_axis = super().argmax(axis=axis, split_every=split_every, out=out)
_coords = np.array(list(np.ndindex(_max_ind_axis.shape))) #list?
_coords = np.array(list(np.ndindex(_max_ind_axis.shape))) # list?
_inds = np.insert(_coords, axis, np.array(_max_ind_axis).flatten(), axis=1)
_extracted_points = da.take(self._variance.flatten(), np.ravel_multi_index(_inds.T, (self._variance.shape)))
_extracted_points = da.take(self._variance.flatten(), np.ravel_multi_index(_inds.T, self._variance.shape))
result._variance = _extracted_points.reshape(result.shape).rechunk(result.chunksize)

return result, locals().copy()
Expand All @@ -1294,8 +1298,8 @@ def sum(self, axis=None, dtype=None, keepdims=False, split_every=None, out=None)
checkdims=False)
if self._variance is not None:
result._variance = abs(self._variance).sum(axis=axis, dtype=dtype, keepdims=keepdims,
split_every=split_every, out=out)
#TODO imaginary
split_every=split_every, out=out)
# TODO imaginary
return result, locals().copy()

@reduce_dims
Expand All @@ -1310,7 +1314,7 @@ def mean(self, axis=None, dtype=None, keepdims=False, split_every=None, out=None
else:
sh = axis
result._variance = self._variance.sum(axis=axis, dtype=dtype, keepdims=keepdims,
split_every=split_every, out=out)/sh**2
split_every=split_every, out=out)/sh**2

return result, locals().copy()

Expand Down Expand Up @@ -1367,7 +1371,7 @@ def astype(self, dtype, **kwargs):

def flatten(self):

result = self.like_data(super().flatten(), title_prefix='flattened_',
result = self.like_data(super().flatten(), title_prefix='flattened_',
check_dims=False)

if self._variance is not None:
Expand Down
24 changes: 15 additions & 9 deletions sidpy/viz/dataset_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
if sys.version_info.major == 3:
unicode = str


default_cmap = plt.cm.viridis


Expand Down Expand Up @@ -597,6 +598,7 @@ def __init__(self, dset, figure=None, horizontal=True, **kwargs):
self.y = 0
self.bin_x = 1
self.bin_y = 1
self.line_scan = False

self.set_dataset()

Expand Down Expand Up @@ -645,7 +647,9 @@ def verify_dataset(self):
else:
selection.append(slice(0, 1))

if len(image_dims) != 2:
if len(image_dims) == 1:
self.line_scan = True
elif len(image_dims) != 2:
raise TypeError('We need two dimensions with dimension_type SPATIAL: to plot an image')
if len(channel_dim) >1:
raise ValueError("We have more than one Channel Dimension, this won't work for the visualizer")
Expand Down Expand Up @@ -683,8 +687,9 @@ def set_dataset(self):
self.scaleY = 1.0
self.analysis = []
self.plot_legend = False
if not self.line_scan:
self.extent_rd = self.dset.get_extent(self.image_dims)

self.extent_rd = self.dset.get_extent(self.image_dims)

def set_image(self, **kwargs):
if len(self.channel_axis)>0:
Expand Down Expand Up @@ -766,19 +771,20 @@ def _update_image(self, event_value):
self.axes[0].set_ylabel('{} [{}]'.format(self.dset._axes[self.image_dims[1]].quantity,
self.dset._axes[self.image_dims[1]].units))

self.axes[0].set_xticks(np.linspace(self.extent[0], self.extent[1], 5),)
self.axes[0].set_xticklabels(np.round(np.linspace(self.extent_rd[0], self.extent_rd[1], 5), 2))
if not self.line_scan:
self.axes[0].set_xticks(np.linspace(self.extent[0], self.extent[1], 5),)
self.axes[0].set_xticklabels(np.round(np.linspace(self.extent_rd[0], self.extent_rd[1], 5), 2))

self.axes[0].set_yticks(np.linspace(self.extent[2], self.extent[3], 5),)
self.axes[0].set_yticklabels(np.round(np.linspace(self.extent_rd[2], self.extent_rd[3], 5), 2))
self.axes[0].set_yticks(np.linspace(self.extent[2], self.extent[3], 5),)
self.axes[0].set_yticklabels(np.round(np.linspace(self.extent_rd[2], self.extent_rd[3], 5), 2))

self.axes[0].set_ylabel('{} [{}]'.format(self.dset._axes[self.image_dims[1]].quantity,
self.dset._axes[self.image_dims[1]].units))

self.axes[0].set_xlabel('{} [{}]'.format(self.dset._axes[self.image_dims[0]].quantity,
self.dset._axes[self.image_dims[0]].units))

self.axes[0].set_ylabel('{} [{}]'.format(self.dset._axes[self.image_dims[1]].quantity,
self.dset._axes[self.image_dims[1]].units))


if self.dset._axes[self.image_dims[0]].units =='m':
scaled_values_y = self.dset._axes[self.image_dims[1]].values*1E9
scaled_values_x = self.dset._axes[self.image_dims[0]].values*1E9
Expand Down

0 comments on commit 8136fda

Please sign in to comment.