nxs-analysis-tools 0.0.41__py3-none-any.whl → 0.0.43__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nxs-analysis-tools might be problematic. Click here for more details.

_meta/__init__.py CHANGED
@@ -6,5 +6,5 @@ __author__ = 'Steven J. Gomez Alvarado'
6
6
  __email__ = 'stevenjgomez@ucsb.edu'
7
7
  __copyright__ = f"2023, {__author__}"
8
8
  __license__ = 'MIT'
9
- __version__ = '0.0.41'
9
+ __version__ = '0.0.43'
10
10
  __repo_url__ = 'https://github.com/stevenjgomez/nxs_analysis_tools'
@@ -8,6 +8,7 @@ import re
8
8
 
9
9
  import matplotlib.pyplot as plt
10
10
  import matplotlib as mpl
11
+ import pandas as pd
11
12
  import numpy as np
12
13
  from IPython.display import display, Markdown
13
14
  from nxs_analysis_tools import load_data, Scissors
@@ -190,14 +191,24 @@ class TempDependence:
190
191
 
191
192
  # Convert all temperatures to int temporarily to sort temperatures list before loading
192
193
  self.temperatures = [int(t) for t in self.temperatures]
193
- self.temperatures.sort()
194
+
195
+ loading_template = pd.DataFrame({'temperature': self.temperatures, 'filename': items_to_load})
196
+ loading_template = loading_template.sort_values(by='temperature')
197
+ self.temperatures = loading_template['temperature']
194
198
  self.temperatures = [str(t) for t in self.temperatures]
199
+ items_to_load = loading_template['filename'].to_list()
195
200
 
196
201
  for i, item in enumerate(items_to_load):
197
202
  path = os.path.join(self.sample_directory, item)
198
203
 
199
204
  # Save dataset
200
- self.datasets[self.temperatures[i]] = load_transform(path)
205
+ try:
206
+ self.datasets[self.temperatures[i]] = load_transform(path)
207
+ except Exception as e:
208
+ # Report temperature that was unable to load, then raise exception.
209
+ temp_failed = self.temperatures[i]
210
+ print(f"Failed to load data for temperature {temp_failed} K from file {item}. Error: {e}")
211
+ raise # Re-raise the exception
201
212
 
202
213
  # Initialize scissors object
203
214
  self.scissors[self.temperatures[i]] = Scissors()
@@ -185,14 +185,14 @@ def plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None,
185
185
  """
186
186
  if isinstance(data, np.ndarray):
187
187
  if X is None:
188
- X = NXfield(np.linspace(0, data.shape[1], data.shape[1]), name='x')
188
+ X = NXfield(np.linspace(0, data.shape[0], data.shape[0]), name='x')
189
189
  if Y is None:
190
- Y = NXfield(np.linspace(0, data.shape[0], data.shape[0]), name='y')
190
+ Y = NXfield(np.linspace(0, data.shape[1], data.shape[1]), name='y')
191
191
  if transpose:
192
192
  X, Y = Y, X
193
193
  data = data.transpose()
194
194
  data = NXdata(NXfield(data, name='value'), (X, Y))
195
- data_arr = data
195
+ data_arr = data[data.signal].nxdata.transpose()
196
196
  elif isinstance(data, (NXdata, NXfield)):
197
197
  if X is None:
198
198
  X = data[data.axes[0]]
@@ -787,7 +787,8 @@ def rotate_data(data, lattice_angle, rotation_angle, rotation_axis, printout=Fal
787
787
 
788
788
  p = Padder(sliced_data)
789
789
  padding = tuple(len(sliced_data[axis]) for axis in sliced_data.axes)
790
- counts = p.pad(padding).counts
790
+ counts = p.pad(padding)
791
+ counts = p.padded[p.padded.signal]
791
792
 
792
793
  counts_skewed = ndimage.affine_transform(counts,
793
794
  t.inverted().get_matrix()[:2, :2],
@@ -848,7 +849,7 @@ def rotate_data(data, lattice_angle, rotation_angle, rotation_axis, printout=Fal
848
849
  elif rotation_axis == 2:
849
850
  output_array[:, :, i] = counts_unpadded
850
851
  print('\nDone.')
851
- return NXdata(NXfield(output_array, name='counts'),
852
+ return NXdata(NXfield(output_array, name=p.padded.signal),
852
853
  (data[data.axes[0]], data[data.axes[1]], data[data.axes[2]]))
853
854
 
854
855
 
@@ -884,7 +885,8 @@ def rotate_data2D(data, lattice_angle, rotation_angle):
884
885
 
885
886
  p = Padder(data)
886
887
  padding = tuple(len(data[axis]) for axis in data.axes)
887
- counts = p.pad(padding).counts
888
+ counts = p.pad(padding)
889
+ counts = p.padded[p.padded.signal]
888
890
 
889
891
  counts_skewed = ndimage.affine_transform(counts,
890
892
  t.inverted().get_matrix()[:2, :2],
@@ -937,7 +939,7 @@ def rotate_data2D(data, lattice_angle, rotation_angle):
937
939
  counts_unpadded = p.unpad(counts_unskewed)
938
940
 
939
941
  print('\nDone.')
940
- return NXdata(NXfield(counts_unpadded, name='counts'),
942
+ return NXdata(NXfield(counts_unpadded, name=p.padded.signal),
941
943
  (data[data.axes[0]], data[data.axes[1]]))
942
944
 
943
945
 
@@ -185,23 +185,58 @@ class Symmetrizer2D:
185
185
  q1 = data_padded[data.axes[0]]
186
186
  q2 = data_padded[data.axes[1]]
187
187
 
188
- # Define signal to be symmetrized
189
- counts = data_padded[data.signal].nxdata
190
-
191
188
  # Calculate the angle for each data point
192
189
  theta = np.arctan2(q1.reshape((-1, 1)), q2.reshape((1, -1)))
193
190
  # Create a boolean array for the range of angles
194
191
  symmetrization_mask = np.logical_and(theta >= theta_min * np.pi / 180,
195
192
  theta <= theta_max * np.pi / 180)
196
- self.symmetrization_mask = NXdata(NXfield(p.unpad(symmetrization_mask),
197
- name='mask'),
198
- (data[data.axes[0]], data[data.axes[1]])
199
- )
200
193
 
201
- self.wedge = NXdata(NXfield(p.unpad(counts * symmetrization_mask),
202
- name=data.signal),
203
- (data[data.axes[0]], data[data.axes[1]])
204
- )
194
+ # Define signal to be transformed
195
+ counts = symmetrization_mask
196
+
197
+ # Scale and skew counts
198
+ skew_angle_adj = 90 - self.skew_angle
199
+
200
+ scale2 = counts.shape[0] / counts.shape[1]
201
+ counts_unscaled2 = ndimage.affine_transform(counts,
202
+ Affine2D().scale(scale2, 1).inverted().get_matrix()[:2, :2],
203
+ offset=[-(1 - scale2) * counts.shape[
204
+ 0] / 2 / scale2, 0],
205
+ order=0,
206
+ )
207
+
208
+ scale1 = np.cos(skew_angle_adj * np.pi / 180)
209
+ counts_unscaled1 = ndimage.affine_transform(counts_unscaled2,
210
+ Affine2D().scale(scale1, 1).inverted().get_matrix()[:2, :2],
211
+ offset=[-(1 - scale1) * counts.shape[
212
+ 0] / 2 / scale1, 0],
213
+ order=0,
214
+ )
215
+
216
+ mask = ndimage.affine_transform(counts_unscaled1,
217
+ t.get_matrix()[:2, :2],
218
+ offset=[-counts.shape[0] / 2
219
+ * np.sin(skew_angle_adj * np.pi / 180), 0],
220
+ order=0,
221
+ )
222
+
223
+ # Convert mask to nxdata
224
+ mask = array_to_nxdata(mask, data_padded)
225
+
226
+ # Save mask for user interaction
227
+ self.symmetrization_mask = p.unpad(mask)
228
+
229
+ # Perform masking
230
+ wedge = mask * data_padded
231
+
232
+ # Save wedge for user interaction
233
+ self.wedge = p.unpad(wedge)
234
+
235
+ # Convert wedge back to array for further transformations
236
+ wedge = wedge[data.signal].nxdata
237
+
238
+ # Define signal to be transformed
239
+ counts = wedge
205
240
 
206
241
  # Scale and skew counts
207
242
  skew_angle_adj = 90 - self.skew_angle
@@ -216,7 +251,7 @@ class Symmetrizer2D:
216
251
  Affine2D().scale(scale1, 1).get_matrix()[:2, :2],
217
252
  offset=[(1 - scale1) * counts.shape[0] / 2, 0],
218
253
  order=0,
219
- ) * symmetrization_mask
254
+ )
220
255
 
221
256
  scale2 = counts.shape[0] / counts.shape[1]
222
257
  wedge = ndimage.affine_transform(wedge,
@@ -325,15 +360,24 @@ class Symmetrizer2D:
325
360
  symm_test = s.symmetrize_2d(data)
326
361
  fig, axesarr = plt.subplots(2, 2, figsize=(10, 8))
327
362
  axes = axesarr.reshape(-1)
363
+
364
+ # Plot the data
328
365
  plot_slice(data, skew_angle=s.skew_angle, ax=axes[0], title='data', **kwargs)
329
- plot_slice(s.symmetrization_mask, skew_angle=s.skew_angle, ax=axes[1], title='mask')
366
+
367
+ # Filter kwargs to exclude 'vmin' and 'vmax'
368
+ filtered_kwargs = {key: value for key, value in kwargs.items() if key not in ('vmin', 'vmax')}
369
+ # Plot the mask
370
+ plot_slice(s.symmetrization_mask, skew_angle=s.skew_angle, ax=axes[1], title='mask', **filtered_kwargs)
371
+
372
+ # Plot the wedge
330
373
  plot_slice(s.wedge, skew_angle=s.skew_angle, ax=axes[2], title='wedge', **kwargs)
374
+
375
+ # Plot the symmetrized data
331
376
  plot_slice(symm_test, skew_angle=s.skew_angle, ax=axes[3], title='symmetrized', **kwargs)
332
377
  plt.subplots_adjust(wspace=0.4)
333
378
  plt.show()
334
379
  return fig, axesarr
335
380
 
336
-
337
381
  class Symmetrizer3D:
338
382
  """
339
383
  A class to symmetrize 3D datasets by performing sequential 2D symmetrization on
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: nxs-analysis-tools
3
- Version: 0.0.41
3
+ Version: 0.0.43
4
4
  Summary: Reduce and transform nexus format (.nxs) scattering data.
5
5
  Author-email: "Steven J. Gomez Alvarado" <stevenjgomez@ucsb.edu>
6
6
  License: MIT License
@@ -0,0 +1,11 @@
1
+ _meta/__init__.py,sha256=kxRgW9usOeluI-Bk-1GiZ0pt5jesv-HKRThTZKAvTtI,352
2
+ nxs_analysis_tools/__init__.py,sha256=bxbTLpIcKasH3fuRZOvJ9zeu7IBBju82mOTgUV4ZqHE,530
3
+ nxs_analysis_tools/chess.py,sha256=e3ZnyepnLATXZRk2cgh6iCZ7Pk3NKJ4IvRf4xNLuu94,24984
4
+ nxs_analysis_tools/datareduction.py,sha256=arEWF8VI8qJfT--G77OJL37C_3usjfd3-wT2gTCtwZM,41964
5
+ nxs_analysis_tools/fitting.py,sha256=vPx75lKvm5pWOGBtRtff8k6J5dA6kRk3EJyzxCH5Tyk,8809
6
+ nxs_analysis_tools/pairdistribution.py,sha256=8E1grptUMb4UXVT9mBSk45xk2JwjCvTG0Rl6BlbJAdo,60013
7
+ nxs_analysis_tools-0.0.43.dist-info/LICENSE,sha256=tdnoYVH1-ogW_5-gGs9bK-IkCamH1ATJqrdL37kWTHk,1102
8
+ nxs_analysis_tools-0.0.43.dist-info/METADATA,sha256=aBNS2AJAECd6RLqqQCFBjJgrW0piIhFaDxQCekvMqFc,3895
9
+ nxs_analysis_tools-0.0.43.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
+ nxs_analysis_tools-0.0.43.dist-info/top_level.txt,sha256=8U000GNPzo6T6pOMjRdgOSO5heMzLMGjkxa1CDtyMHM,25
11
+ nxs_analysis_tools-0.0.43.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- _meta/__init__.py,sha256=QYocreoqhGDlovbW3V-ZkRa8aQqrIW5H9WvyI9XueaY,352
2
- nxs_analysis_tools/__init__.py,sha256=bxbTLpIcKasH3fuRZOvJ9zeu7IBBju82mOTgUV4ZqHE,530
3
- nxs_analysis_tools/chess.py,sha256=GUW08BcDUGD88MPZCl4yJTQp4hwd9tVNTJN_afNSUUo,24339
4
- nxs_analysis_tools/datareduction.py,sha256=e__mBGZIpJ-_-Dr6-T9hJURJazFnBy3PoWfwRxOra4U,41848
5
- nxs_analysis_tools/fitting.py,sha256=vPx75lKvm5pWOGBtRtff8k6J5dA6kRk3EJyzxCH5Tyk,8809
6
- nxs_analysis_tools/pairdistribution.py,sha256=bO-Ljst8eD5wmeq6oH8ylhHqaUyu2CvARznDupCygWQ,58245
7
- nxs_analysis_tools-0.0.41.dist-info/LICENSE,sha256=tdnoYVH1-ogW_5-gGs9bK-IkCamH1ATJqrdL37kWTHk,1102
8
- nxs_analysis_tools-0.0.41.dist-info/METADATA,sha256=2O7IvBuaAp_R_uXlwn-oZctEpIKGFlESR8gRAj_TP_U,3895
9
- nxs_analysis_tools-0.0.41.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
10
- nxs_analysis_tools-0.0.41.dist-info/top_level.txt,sha256=8U000GNPzo6T6pOMjRdgOSO5heMzLMGjkxa1CDtyMHM,25
11
- nxs_analysis_tools-0.0.41.dist-info/RECORD,,