LLNL-PyDV 3.8.2__tar.gz → 3.9.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LLNL-PyDV
3
- Version: 3.8.2
3
+ Version: 3.9.1
4
4
  Summary: PyDV: Python Data Visualizer
5
5
  License: BSD
6
6
  License-File: LICENSE
@@ -510,6 +510,9 @@ class Command(cmd.Cmd, object):
510
510
  def do_rdsina(self, line):
511
511
  self.do_readsina(line)
512
512
 
513
+ def do_rdsinah5(self, line):
514
+ self.do_readsinahdf5(line)
515
+
513
516
  def do_cur(self, line):
514
517
  self.do_curve(line)
515
518
 
@@ -636,6 +639,8 @@ class Command(cmd.Cmd, object):
636
639
  arg = 'readcsv'
637
640
  elif (arg == 'rdsina'):
638
641
  arg = 'readsina'
642
+ elif (arg == 'rdsinah5'):
643
+ arg = 'readsinahdf5'
639
644
  elif (arg == 'convol'):
640
645
  arg = 'convolve'
641
646
  elif (arg == 'convolb'):
@@ -1110,6 +1115,9 @@ class Command(cmd.Cmd, object):
1110
1115
  elif line[-1].endswith(".json"):
1111
1116
  self.do_readsina(" ".join(line))
1112
1117
  return
1118
+ elif line[-1].endswith(".hdf5") or line[-1].endswith(".h5") or line[-1].endswith(".hdf"):
1119
+ self.do_readsinahdf5(" ".join(line))
1120
+ return
1113
1121
 
1114
1122
  if n == 1:
1115
1123
  self.load(line[0])
@@ -1174,10 +1182,8 @@ class Command(cmd.Cmd, object):
1174
1182
 
1175
1183
  def do_readsina(self, line):
1176
1184
  """
1177
- Read all curves from Sina data file. PyDV assumes there is only one record in the Sina file, and if there are
1178
- more than one then PyDV only reads the first. PyDV also assumes there is only one independent variable per
1179
- curve_set; if there are more than one then PyDV may exhibit undefined behavior. The next available prefix
1180
- (see the prefix command) is automatically assigned the menu index of the first curve in each data file read.
1185
+ Read all curves from Sina data file. The next available prefix (see the prefix command) is automatically
1186
+ assigned the menu index of the first curve in each data file read.
1181
1187
 
1182
1188
  .. code::
1183
1189
 
@@ -1196,6 +1202,28 @@ class Command(cmd.Cmd, object):
1196
1202
  self.redraw = False
1197
1203
  self.plotter.updateDialogs()
1198
1204
 
1205
+ def do_readsinahdf5(self, line):
1206
+ """
1207
+ Read all curves from Sina hdf5 data file. The next available prefix (see the prefix command) is automatically
1208
+ assigned the menu index of the first curve in each data file read.
1209
+
1210
+ .. code::
1211
+
1212
+ [PyDV]: <readsinahdf5 | rdsinah5> <filename.hdf5>
1213
+
1214
+ Ex:
1215
+ [PyDV]: readsinahdf5 my_file.hdf5
1216
+ """
1217
+
1218
+ try:
1219
+ line = line.split()
1220
+ self.load_sinahdf5(line[0])
1221
+ except:
1222
+ pdvutil.print_own_docstring(self)
1223
+ finally:
1224
+ self.redraw = False
1225
+ self.plotter.updateDialogs()
1226
+
1199
1227
  def do_setxcolumn(self, line):
1200
1228
  """
1201
1229
  Set x column for reading column formatted data files (.gnu or .csv).
@@ -9440,6 +9468,16 @@ class Command(cmd.Cmd, object):
9440
9468
  self.curvelist += curves
9441
9469
  self.filelist.append((fname, len(curves)))
9442
9470
 
9471
+ def load_sinahdf5(self, fname):
9472
+ """
9473
+ Load a Sina HDF5 data file, add parsed curves to the curvelist
9474
+ """
9475
+
9476
+ curves = pydvpy.readsinahdf5(fname, self.debug)
9477
+ if len(curves) > 0:
9478
+ self.curvelist += curves
9479
+ self.filelist.append((fname, len(curves)))
9480
+
9443
9481
  def loadrc(self):
9444
9482
  """
9445
9483
  Read in a resource definition file
@@ -66,8 +66,7 @@ import re
66
66
  import copy
67
67
  from multiprocessing import Pool, cpu_count
68
68
  import subprocess
69
-
70
- from distutils.version import LooseVersion
69
+ import h5py
71
70
 
72
71
  import numpy as np
73
72
  import scipy
@@ -566,6 +565,8 @@ def read(fname, gnu=False, xcol=0, verbose=False, pattern=None, matches=None):
566
565
  return readcsv(fname=fname, xcol=xcol, verbose=verbose)
567
566
  elif str(fname).endswith(".json"):
568
567
  return readsina(fname=fname, verbose=verbose)
568
+ elif str(fname).endswith(".hdf5") or str(fname).endswith(".h5") or str(fname).endswith(".hdf"):
569
+ return readsinahdf5(fname, verbose=verbose)
569
570
  elif gnu or str(fname).endswith(".gnu"):
570
571
  return __loadcolumns(fname, xcol)
571
572
  elif pdbLoaded:
@@ -743,7 +744,7 @@ def readcsv(fname, xcol=0, verbose=False):
743
744
  return curvelist
744
745
 
745
746
 
746
- def readsina(fname, verbose=False):
747
+ def readsina(fname, verbose=False, hdf5_path=None):
747
748
  """
748
749
  Load a Sina JSON data file, add parsed curves to a curvelist.
749
750
 
@@ -758,77 +759,97 @@ def readsina(fname, verbose=False):
758
759
  :type fname: str
759
760
  :param verbose: prints the error stacktrace when True
760
761
  :type verbose: bool
762
+ :param hdf5_path: File path for HDF5 sina file. Should not be set by user, only used internally, defaults to None.
763
+ :type hdf5_path: str, optional.
761
764
  :returns: list: the list of curves from the sina file
762
765
  """
763
- curves = {}
764
- listed_order = []
765
- try:
766
- # Try to load the order in which the user wants to load the curves into PyDV
767
- with open(fname, 'r') as fp:
768
- try:
769
- order_options = json.load(fp)['records'][0]['data']['SINA_timeplot_order']['value']
770
- except:
771
- order_options = []
772
-
773
- # Load the curve data from the curve_sets
774
- with open(fname, 'r') as fp:
766
+ def add_curve_set(curve_sets, record_id, order_options, library=''):
767
+
768
+ curves = {}
769
+ listed_order = []
770
+ for curve_set_name, curve_set in curve_sets.items():
771
+ for name_ind, v_ind in curve_set['independent'].items():
772
+ independent_name = name_ind
773
+ independent_value = v_ind['value']
774
+ for name, v in curve_set['dependent'].items():
775
+ # TODO: Save the name x and y names with the curves
776
+ dependent_variable_name = name
777
+ if order_options:
778
+ full_name = curve_set_name + '__SINA_DEP__' + dependent_variable_name
779
+ else:
780
+ full_name = curve_set_name + '__SINA_DEP__' + dependent_variable_name + \
781
+ '__SINA_INDEP__' + independent_name
782
+ dependent_variable_value = v['value']
783
+ curve_name = dependent_variable_name + ' vs ' + independent_name + " (" + \
784
+ curve_set_name + ")"
785
+ if library != '':
786
+ curve_name += ' ' + library
787
+ full_name += '__LIBRARY__' + library
788
+ c = makecurve(x=independent_value,
789
+ y=dependent_variable_value,
790
+ name=curve_name,
791
+ filename=fname if hdf5_path is None else hdf5_path,
792
+ xlabel=independent_name,
793
+ ylabel=dependent_variable_name,
794
+ title=curve_name,
795
+ record_id=record_id)
796
+ c.step = False
797
+ c.xticks_labels = {}
798
+ if verbose:
799
+ print(f"Appended curve: {curve_name}, len x,y: {len(c.x)},{len(c.y)}")
800
+ curves[full_name] = c
801
+ listed_order.append(full_name)
802
+
803
+ if order_options:
775
804
  try:
776
- sina_file = json.load(fp)
777
- record_id = sina_file['records'][0]['id']
778
- curve_sets = sina_file['records'][0]['curve_sets']
779
- library_data = sina_file['records'][0].get('library_data', {})
780
-
781
- def add_curve_set(curve_sets, curves, listed_order, library=''):
782
- for curve_set_name, curve_set in curve_sets.items():
783
- for name_ind, v_ind in curve_set['independent'].items():
784
- independent_name = name_ind
785
- independent_value = v_ind['value']
786
- for name, v in curve_set['dependent'].items():
787
- # TODO: Save the name x and y names with the curves
788
- dependent_variable_name = name
789
- if order_options:
790
- full_name = curve_set_name + '__SINA_DEP__' + dependent_variable_name
791
- else:
792
- full_name = curve_set_name + '__SINA_DEP__' + dependent_variable_name + \
793
- '__SINA_INDEP__' + independent_name
794
- dependent_variable_value = v['value']
795
- curve_name = dependent_variable_name + ' vs ' + independent_name + " (" + \
796
- curve_set_name + ")"
797
- if library != '':
798
- curve_name += ' ' + library
799
- full_name += '__LIBRARY__' + library
800
- c = makecurve(x=independent_value,
801
- y=dependent_variable_value,
802
- name=curve_name,
803
- filename=fname,
804
- xlabel=independent_name,
805
- ylabel=dependent_variable_name,
806
- title=curve_name,
807
- record_id=record_id)
808
- c.step = False
809
- c.xticks_labels = {}
810
- if verbose:
811
- print("Appended curve: {}, len x,y: {},{}"
812
- .format(curve_name, len(c.x), len(c.y)))
813
- curves[full_name] = c
814
- listed_order.append(full_name)
815
- return curves, listed_order
816
-
817
- curves, listed_order = add_curve_set(curve_sets, curves, listed_order)
818
-
819
- for library in library_data:
820
- if 'curve_sets' in library_data[library]:
821
- curve_sets = library_data[library]['curve_sets']
822
- curves, listed_order = add_curve_set(curve_sets, curves, listed_order, library=library)
805
+ curves_lst_temp = [curves[name] for name in order_options]
823
806
  except KeyError:
824
- print('readsina: Sina file {} is malformed'.format(fname))
807
+ print('readsina: mismatch between dependent variable names in the curve_sets and the '
808
+ 'ordering specified in SINA_timeplot_order. Using default ordering instead.')
809
+ curves_lst_temp = [curves[name] for name in listed_order]
825
810
  if verbose:
826
- traceback.print_exc(file=sys.stdout)
827
- return []
811
+ traceback.print_exc(File=sys.stdout)
812
+ else:
813
+ curves_lst_temp = [curves[name] for name in listed_order]
814
+
815
+ return curves_lst_temp
828
816
 
829
- # Try to load the order in which the user wants to load the curves into PyDV
830
- if not order_options:
831
- order_options = listed_order
817
+ def cycle_thru_recs(sina_file):
818
+ curves_lst = []
819
+
820
+ for rec in sina_file['records']:
821
+
822
+ record_id = rec.get('id', rec.get("local_id", ""))
823
+ curve_sets = rec.get('curve_sets', {})
824
+ library_data = rec.get('library_data', {})
825
+ order_options = rec.get('data', {}).get('SINA_timeplot_order', {}).get('value', [])
826
+
827
+ curves_lst_temp = add_curve_set(curve_sets, record_id, order_options)
828
+ curves_lst.extend(curves_lst_temp)
829
+
830
+ for library in library_data:
831
+ if 'curve_sets' in library_data[library]:
832
+ curve_sets = library_data[library].get('curve_sets', {})
833
+ order_options = library_data[library].get('data',
834
+ {}).get('SINA_timeplot_order',
835
+ {}).get('value', [])
836
+ curves_lst_temp = add_curve_set(curve_sets, record_id, order_options, library=library)
837
+ curves_lst.extend(curves_lst_temp)
838
+ return curves_lst
839
+
840
+ try:
841
+ # Load the curve data from the curve_sets
842
+ try:
843
+ if not isinstance(fname, dict):
844
+ with open(fname, 'r') as fp:
845
+ curves_lst = cycle_thru_recs(json.load(fp))
846
+ else:
847
+ curves_lst = cycle_thru_recs(fname)
848
+ except KeyError:
849
+ print('readsina: Sina file {} is malformed'.format(fname))
850
+ if verbose:
851
+ traceback.print_exc(file=sys.stdout)
852
+ return []
832
853
 
833
854
  except IOError:
834
855
  print('readsina: could not load file: {}'.format(fname))
@@ -836,17 +857,75 @@ def readsina(fname, verbose=False):
836
857
  traceback.print_exc(file=sys.stdout)
837
858
  return []
838
859
 
839
- try:
840
- curves_lst = [curves[name] for name in order_options]
841
- except KeyError:
842
- print('readsina: mismatch between dependent variable names in the curve_sets and the '
843
- 'ordering specified in SINA_timeplot_order. Using default ordering instead.')
844
- if verbose:
845
- traceback.print_exc(File=sys.stdout)
846
- curves_lst = [curves[name] for name in listed_order]
847
860
  return curves_lst
848
861
 
849
862
 
863
+ def readsinahdf5(hdf5_path, verbose=False):
864
+ # def load_document_hdf5(hdf5_path): Taken from sina/utils.py
865
+ """
866
+ Retrieves records and relationships from HDF5
867
+ """
868
+ reconstructed_doc = {}
869
+
870
+ def coerce_numpy_to_json(val):
871
+ # There's no single quick way to do this when numpy and hdf5 combine,
872
+ # so we have a manual method...
873
+ if isinstance(val, bytes):
874
+ val = val.decode("utf-8")
875
+ if isinstance(val, h5py.Empty):
876
+ val = dict()
877
+ if isinstance(val, np.integer):
878
+ val = int(val)
879
+ elif isinstance(val, np.floating):
880
+ val = float(val)
881
+ elif isinstance(val, np.ndarray):
882
+ is_word = len(np.shape(val)) == 1 and isinstance(val[0], bytes)
883
+ val = [x.decode("utf-8") if isinstance(x, bytes)
884
+ else x for x in val.tolist()]
885
+ if is_word:
886
+ val = ''.join(val)
887
+ elif np.shape(val)[0] == 1:
888
+ val = val[0]
889
+ return val
890
+
891
+ def add_arbitrary_path_to_dict(some_path, val):
892
+ chunk = reconstructed_doc
893
+ layers = some_path.split("/")
894
+ for depth, layer in enumerate(layers):
895
+ if not layer:
896
+ continue
897
+ if layer not in chunk:
898
+ chunk[layer] = dict()
899
+ if depth == len(layers) - 1:
900
+ if isinstance(val, list):
901
+ chunk[layer] = [coerce_numpy_to_json(x) for x in val]
902
+ else:
903
+ chunk[layer] = coerce_numpy_to_json(val)
904
+ else:
905
+ chunk = chunk[layer]
906
+
907
+ def yoink_dataset_or_recurse(path, chunk):
908
+ if isinstance(chunk, h5py.Group):
909
+ for key, val in chunk.items():
910
+ # Recovery for common wonky HDF5 issue
911
+ if (isinstance(val, h5py.Group) and '0' in val.keys() and key in ("value", "tags")):
912
+ add_arbitrary_path_to_dict(path + "/" + key, [chunk[key][x][()] for x in val])
913
+ else:
914
+ yoink_dataset_or_recurse(path + "/" + key, val)
915
+ else:
916
+ add_arbitrary_path_to_dict(path, chunk[()])
917
+ with h5py.File(hdf5_path, 'r') as src:
918
+ yoink_dataset_or_recurse("", src)
919
+ # Now we have to (temporarily!) smooth the object->list thing between our hdf5
920
+ # and JSON entries...
921
+ reconstructed_doc["records"] = ([x for x in reconstructed_doc["records"].values()]
922
+ if "records" in reconstructed_doc else list())
923
+ # reconstructed_doc["relationships"] = ([x for x in reconstructed_doc["relationships"].values()]
924
+ # if "relationships" in reconstructed_doc else list())
925
+
926
+ return readsina(reconstructed_doc, hdf5_path=hdf5_path)
927
+
928
+
850
929
  ########################################################
851
930
  ################## Math Functions ##################### # noqa e266
852
931
  ########################################################
@@ -2842,16 +2921,11 @@ def fft(c, n=None, axis=-1, norm=None):
2842
2921
  :type norm: None, "ortho", optional
2843
2922
  :return: Curve tuple -- Two curves with the real and imaginary parts.
2844
2923
  """
2845
- numpy1_10 = LooseVersion(np.__version__) >= LooseVersion("1.10.0")
2846
2924
  cnorm = c.normalize()
2847
2925
  clen = len(c.x)
2848
2926
 
2849
- if numpy1_10:
2850
- complex_array = np.fft.fft(cnorm.y, n, axis, norm)
2851
- complex_array = np.fft.fftshift(complex_array)
2852
- else:
2853
- complex_array = np.fft.fft(cnorm.y, n, axis)
2854
- complex_array = np.fft.fftshift(complex_array)
2927
+ complex_array = np.fft.fft(cnorm.y, n, axis, norm)
2928
+ complex_array = np.fft.fftshift(complex_array)
2855
2929
 
2856
2930
  val = 1.0 / (float(max(cnorm.x) - min(cnorm.x)) / 2.0)
2857
2931
  x = np.fft.fftfreq(clen, d=val)
@@ -3190,7 +3264,7 @@ def fit(c, n=1, logx=False, logy=False):
3190
3264
  if logy:
3191
3265
  y = np.log10(y)
3192
3266
 
3193
- coeffs = scipy.polyfit(x, y, n)
3267
+ coeffs = np.polyfit(x, y, n)
3194
3268
  if len(coeffs) == 2:
3195
3269
  print("slope = ", coeffs[0], " intercept = ", coeffs[1])
3196
3270
  else:
@@ -3206,7 +3280,7 @@ def fit(c, n=1, logx=False, logy=False):
3206
3280
  oString = "%dth " % n
3207
3281
 
3208
3282
  x = np.array(x)
3209
- y = scipy.polyval(coeffs, x)
3283
+ y = np.polyval(coeffs, x)
3210
3284
 
3211
3285
  if logx:
3212
3286
  x = 10.0**x
@@ -3902,12 +3976,7 @@ def __ifft(cr, ci):
3902
3976
  """
3903
3977
  carray = cr.y + 1j * ci.y
3904
3978
 
3905
- numpy1_10 = LooseVersion(np.__version__) >= LooseVersion("1.10.0")
3906
-
3907
- if numpy1_10:
3908
- complex_array = np.fft.ifft(carray)
3909
- else:
3910
- complex_array = np.fft.ifft(carray)
3979
+ complex_array = np.fft.ifft(carray)
3911
3980
 
3912
3981
  # nc1.x = np.array(cr.x)
3913
3982
  nc1y = complex_array.real
@@ -0,0 +1 @@
1
+ 02.12.2026
@@ -0,0 +1 @@
1
+ 3.9.1
@@ -1,7 +1,7 @@
1
1
  [tool]
2
2
  [tool.poetry]
3
3
  name = "LLNL-PyDV"
4
- version = "3.8.2"
4
+ version = "3.9.1"
5
5
  description = "PyDV: Python Data Visualizer"
6
6
  license = "BSD"
7
7
  classifiers = [
@@ -64,7 +64,7 @@ build-backend = "poetry.core.masonry.api"
64
64
  line-length = 79
65
65
 
66
66
  [tool.bumpver]
67
- current_version = "3.8.2"
67
+ current_version = "3.9.1"
68
68
  version_pattern = "MAJOR.MINOR.PATCH"
69
69
  commit_message = "bump version {old_version} -> {new_version}"
70
70
  commit = true
@@ -1 +0,0 @@
1
- 10.22.2025
@@ -1 +0,0 @@
1
- 3.8.2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes