nxs-analysis-tools 0.0.46__py3-none-any.whl → 0.0.47__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-2025, {__author__}"
8
8
  __license__ = 'MIT'
9
- __version__ = '0.0.46'
9
+ __version__ = '0.0.47'
10
10
  __repo_url__ = 'https://github.com/stevenjgomez/nxs_analysis_tools'
@@ -16,7 +16,7 @@ from scipy import ndimage
16
16
  # Specify items on which users are allowed to perform standalone imports
17
17
  __all__ = ['load_data', 'load_transform', 'plot_slice', 'Scissors',
18
18
  'reciprocal_lattice_params', 'rotate_data', 'rotate_data_2D'
19
- 'array_to_nxdata', 'Padder']
19
+ 'array_to_nxdata', 'Padder']
20
20
 
21
21
 
22
22
  def load_data(path, print_tree=True):
@@ -107,7 +107,7 @@ def array_to_nxdata(array, data_template, signal_name=None):
107
107
  tuple(d[d.axes[i]] for i in range(len(d.axes))))
108
108
 
109
109
 
110
- def plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None,
110
+ def plot_slice(data, X=None, Y=None, sum_axis=None, transpose=False, vmin=None, vmax=None,
111
111
  skew_angle=90, ax=None, xlim=None, ylim=None,
112
112
  xticks=None, yticks=None, cbar=True, logscale=False,
113
113
  symlogscale=False, cmap='viridis', linthresh=1,
@@ -130,6 +130,10 @@ def plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None,
130
130
  The Y axis values. If None, a default range from 0 to the number of
131
131
  rows in `data` is used.
132
132
 
133
+ sum_axis : int, optional
134
+ If the input data is 3D, this specifies the axis to sum over in order
135
+ to reduce the data to 2D for plotting. Required if `data` has three dimensions.
136
+
133
137
  transpose : bool, optional
134
138
  If True, transpose the dataset and its axes before plotting.
135
139
  Default is False.
@@ -199,7 +203,37 @@ def plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None,
199
203
  p : :class:`matplotlib.collections.QuadMesh`
200
204
  The `matplotlib` QuadMesh object representing the plotted data.
201
205
  """
206
+ is_array = False
207
+ is_nxdata = False
208
+
202
209
  if isinstance(data, np.ndarray):
210
+ is_array = True
211
+ elif isinstance(data, (NXdata, NXfield)):
212
+ is_nxdata = True
213
+ else:
214
+ raise TypeError(f"Unexpected data type: {type(data)}. "
215
+ f"Supported types are np.ndarray and NXdata.")
216
+
217
+ # If three-dimensional, demand sum_axis to reduce to two dimensions.
218
+ if is_array and len(data.shape) == 3:
219
+ assert sum_axis is not None, "sum_axis must be specified when data is a 3D array"
220
+
221
+ data = data.sum(axis=sum_axis)
222
+
223
+ if is_nxdata and len(data.shape) == 3:
224
+ assert sum_axis is not None, "sum_axis must be specified when data is a 3D array"
225
+
226
+ arr = data.nxsignal.nxdata
227
+ arr = arr.sum(axis=sum_axis)
228
+
229
+ # Create a 2D template from the original nxdata
230
+ slice_obj = [slice(None)] * len(data.shape)
231
+ slice_obj[sum_axis] = 0
232
+
233
+ # Use the 2D template to create a new nxdata
234
+ data = array_to_nxdata(arr, data[slice_obj])
235
+
236
+ if is_array:
203
237
  if X is None:
204
238
  X = NXfield(np.linspace(0, data.shape[0], data.shape[0]), name='x')
205
239
  if Y is None:
@@ -209,7 +243,7 @@ def plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None,
209
243
  data = data.transpose()
210
244
  data = NXdata(NXfield(data, name='value'), (X, Y))
211
245
  data_arr = data[data.signal].nxdata.transpose()
212
- elif isinstance(data, (NXdata, NXfield)):
246
+ elif is_nxdata:
213
247
  if X is None:
214
248
  X = data[data.axes[0]]
215
249
  if Y is None:
@@ -218,9 +252,6 @@ def plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None,
218
252
  X, Y = Y, X
219
253
  data = data.transpose()
220
254
  data_arr = data[data.signal].nxdata.transpose()
221
- else:
222
- raise TypeError(f"Unexpected data type: {type(data)}. "
223
- f"Supported types are np.ndarray and NXdata.")
224
255
 
225
256
  # Display Markdown heading
226
257
  if mdheading is None:
@@ -559,22 +590,31 @@ class Scissors:
559
590
 
560
591
  return self.linecut
561
592
 
562
- def highlight_integration_window(self, data=None, label=None, highlight_color='red', **kwargs):
593
+ def highlight_integration_window(self, data=None, width=None, height=None, label=None, highlight_color='red',
594
+ **kwargs):
563
595
  """
564
- Plots integration window highlighted on the three principal cross sections of the first
565
- temperature dataset.
596
+ Plots the integration window highlighted on the three principal 2D cross-sections of a 3D dataset.
566
597
 
567
598
  Parameters
568
599
  ----------
569
600
  data : array-like, optional
570
- The 2D heatmap dataset to plot. If not provided, the dataset stored in `self.data` will
571
- be used.
601
+ The 3D dataset to visualize. If not provided, uses `self.data`.
602
+ width : float, optional
603
+ Width of the visible x-axis range in each subplot. Used to zoom in on the integration region.
604
+ height : float, optional
605
+ Height of the visible y-axis range in each subplot. Used to zoom in on the integration region.
572
606
  label : str, optional
573
- The label for the integration window plot.
607
+ Label for the rectangle patch marking the integration window, used in the legend.
574
608
  highlight_color : str, optional
575
- The edge color used to highlight the integration window. Default is 'red'.
576
- **kwargs : keyword arguments, optional
577
- Additional keyword arguments to customize the plot.
609
+ Color of the rectangle edges highlighting the integration window. Default is 'red'.
610
+ **kwargs : dict, optional
611
+ Additional keyword arguments passed to `plot_slice` for customizing the plot (e.g., colormap, vmin, vmax).
612
+
613
+ Returns
614
+ -------
615
+ p1, p2, p3 : matplotlib.collections.QuadMesh
616
+ The plotted QuadMesh objects for the three cross-sections:
617
+ XY at fixed Z, XZ at fixed Y, and YZ at fixed X.
578
618
 
579
619
  """
580
620
  data = self.data if data is None else data
@@ -584,7 +624,7 @@ class Scissors:
584
624
  # Create a figure and subplots
585
625
  fig, axes = plt.subplots(1, 3, figsize=(15, 4))
586
626
 
587
- # Plot cross section 1
627
+ # Plot cross-section 1
588
628
  slice_obj = [slice(None)] * data.ndim
589
629
  slice_obj[2] = center[2]
590
630
 
@@ -603,7 +643,12 @@ class Scissors:
603
643
  )
604
644
  ax.add_patch(rect_diffuse)
605
645
 
606
- # Plot cross section 2
646
+ if 'xlim' not in kwargs and width is not None:
647
+ ax.set(xlim=(center[0] - width / 2, center[0] + width / 2))
648
+ if 'ylim' not in kwargs and height is not None:
649
+ ax.set(ylim=(center[1] - height / 2, center[1] + height / 2))
650
+
651
+ # Plot cross-section 2
607
652
  slice_obj = [slice(None)] * data.ndim
608
653
  slice_obj[1] = center[1]
609
654
 
@@ -622,7 +667,12 @@ class Scissors:
622
667
  )
623
668
  ax.add_patch(rect_diffuse)
624
669
 
625
- # Plot cross section 3
670
+ if 'xlim' not in kwargs and width is not None:
671
+ ax.set(xlim=(center[0] - width / 2, center[0] + width / 2))
672
+ if 'ylim' not in kwargs and height is not None:
673
+ ax.set(ylim=(center[2] - height / 2, center[2] + height / 2))
674
+
675
+ # Plot cross-section 3
626
676
  slice_obj = [slice(None)] * data.ndim
627
677
  slice_obj[0] = center[0]
628
678
 
@@ -641,6 +691,11 @@ class Scissors:
641
691
  )
642
692
  ax.add_patch(rect_diffuse)
643
693
 
694
+ if 'xlim' not in kwargs and width is not None:
695
+ ax.set(xlim=(center[1] - width / 2, center[1] + width / 2))
696
+ if 'ylim' not in kwargs and height is not None:
697
+ ax.set(ylim=(center[2] - height / 2, center[2] + height / 2))
698
+
644
699
  # Adjust subplot padding
645
700
  fig.subplots_adjust(wspace=0.5)
646
701
 
@@ -665,7 +720,7 @@ class Scissors:
665
720
 
666
721
  fig, axes = plt.subplots(1, 3, figsize=(15, 4))
667
722
 
668
- # Plot cross section 1
723
+ # Plot cross-section 1
669
724
  slice_obj = [slice(None)] * data.ndim
670
725
  slice_obj[2] = center[2]
671
726
  p1 = plot_slice(data[slice_obj],
@@ -685,7 +740,7 @@ class Scissors:
685
740
  **kwargs)
686
741
  axes[1].set_aspect(len(data[data.axes[0]].nxdata) / len(data[data.axes[2]].nxdata))
687
742
 
688
- # Plot cross section 3
743
+ # Plot cross-section 3
689
744
  slice_obj = [slice(None)] * data.ndim
690
745
  slice_obj[0] = center[0]
691
746
  p2 = plot_slice(data[slice_obj],
@@ -1015,7 +1070,7 @@ class Padder:
1015
1070
  self.data = data
1016
1071
 
1017
1072
  self.steps = tuple((data[axis].nxdata[1] - data[axis].nxdata[0])
1018
- for axis in data.axes)
1073
+ for axis in data.axes)
1019
1074
 
1020
1075
  # Absolute value of the maximum value; assumes the domain of the input
1021
1076
  # is symmetric (eg, -H_min = H_max)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nxs-analysis-tools
3
- Version: 0.0.46
3
+ Version: 0.0.47
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=MPxIjim0z8Ugh3YLct0a3ThFNGcKhqJCTs5T_tZYZt0,357
2
+ nxs_analysis_tools/__init__.py,sha256=bxbTLpIcKasH3fuRZOvJ9zeu7IBBju82mOTgUV4ZqHE,530
3
+ nxs_analysis_tools/chess.py,sha256=bSSDMAuZLS9se1EJjNa6uuuQFiJZJcWGrEJX0oAm5gc,27470
4
+ nxs_analysis_tools/datareduction.py,sha256=YlfsjFpv9CJl7C8HPlX6AN4ZrWngvMFTBwvl_Axh6oM,44903
5
+ nxs_analysis_tools/fitting.py,sha256=vPx75lKvm5pWOGBtRtff8k6J5dA6kRk3EJyzxCH5Tyk,8809
6
+ nxs_analysis_tools/pairdistribution.py,sha256=CZvXCfCumZp84LQKsJShwgDx5wtDOGpOoOAxjI0jms0,62272
7
+ nxs_analysis_tools-0.0.47.dist-info/licenses/LICENSE,sha256=tbfd7DgSzDiNJpXHXqK6e2usHdJQfLrQKHxti7eyH9k,1107
8
+ nxs_analysis_tools-0.0.47.dist-info/METADATA,sha256=x4opbN0G8rIeAlJfJtFJlSNqJMmBWBALtNSbhCgAdBo,3923
9
+ nxs_analysis_tools-0.0.47.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
10
+ nxs_analysis_tools-0.0.47.dist-info/top_level.txt,sha256=8U000GNPzo6T6pOMjRdgOSO5heMzLMGjkxa1CDtyMHM,25
11
+ nxs_analysis_tools-0.0.47.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- _meta/__init__.py,sha256=9BhNnrOTX8WpPVjSzNRyYktMYI7OyHFZowP9aIUuksk,357
2
- nxs_analysis_tools/__init__.py,sha256=bxbTLpIcKasH3fuRZOvJ9zeu7IBBju82mOTgUV4ZqHE,530
3
- nxs_analysis_tools/chess.py,sha256=bSSDMAuZLS9se1EJjNa6uuuQFiJZJcWGrEJX0oAm5gc,27470
4
- nxs_analysis_tools/datareduction.py,sha256=d24_Vw3-0iOZHdd1JK36idjI5CJmqDEjhcZaaire2fU,42403
5
- nxs_analysis_tools/fitting.py,sha256=vPx75lKvm5pWOGBtRtff8k6J5dA6kRk3EJyzxCH5Tyk,8809
6
- nxs_analysis_tools/pairdistribution.py,sha256=CZvXCfCumZp84LQKsJShwgDx5wtDOGpOoOAxjI0jms0,62272
7
- nxs_analysis_tools-0.0.46.dist-info/licenses/LICENSE,sha256=tbfd7DgSzDiNJpXHXqK6e2usHdJQfLrQKHxti7eyH9k,1107
8
- nxs_analysis_tools-0.0.46.dist-info/METADATA,sha256=Scvtqz8Db5H0C0OC9AwqUj_c8kYmrYgNwWOV1Issod4,3923
9
- nxs_analysis_tools-0.0.46.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
10
- nxs_analysis_tools-0.0.46.dist-info/top_level.txt,sha256=8U000GNPzo6T6pOMjRdgOSO5heMzLMGjkxa1CDtyMHM,25
11
- nxs_analysis_tools-0.0.46.dist-info/RECORD,,