sdfr 1.4.6__py3-none-win_amd64.whl → 1.4.7__py3-none-win_amd64.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.
sdfr/SDF.py CHANGED
@@ -17,6 +17,7 @@
17
17
 
18
18
  import ctypes as ct
19
19
  import numpy as np
20
+ import struct
20
21
  from enum import IntEnum
21
22
  from .loadlib import sdf_lib
22
23
 
@@ -117,6 +118,17 @@ _ct_datatypes = [
117
118
  ct.c_bool,
118
119
  0,
119
120
  ]
121
+ _st_datatypes = [
122
+ 0,
123
+ "i",
124
+ "q",
125
+ "f",
126
+ "d",
127
+ "d",
128
+ "c",
129
+ "?",
130
+ 0,
131
+ ]
120
132
 
121
133
  # Constants
122
134
  SDF_READ = 1
@@ -187,7 +199,7 @@ SdfBlock._fields_ = [
187
199
  ("ngrids", ct.c_int),
188
200
  ("offset", ct.c_int),
189
201
  ("ngb", ct.c_int * 6),
190
- ("const_value", ct.c_char * 16),
202
+ ("const_value", ct.c_byte * 16),
191
203
  ("id", ct.c_char_p),
192
204
  ("units", ct.c_char_p),
193
205
  ("mesh_id", ct.c_char_p),
@@ -339,19 +351,64 @@ class RunInfo(ct.Structure):
339
351
  class BlockList:
340
352
  """Contains all the blocks"""
341
353
 
342
- def __init__(self, filename, convert=False, derived=True):
354
+ def __init__(
355
+ self,
356
+ filename=None,
357
+ convert=False,
358
+ derived=True,
359
+ mode=SDF_READ,
360
+ code_name="sdfr",
361
+ restart=False,
362
+ ):
343
363
  self._handle = None
344
364
  clib = sdf_lib
345
365
  self._clib = clib
346
366
  clib.sdf_open.restype = ct.POINTER(SdfFile)
347
367
  clib.sdf_open.argtypes = [ct.c_char_p, ct.c_int, ct.c_int, ct.c_int]
368
+ clib.sdf_new.restype = ct.POINTER(SdfFile)
369
+ clib.sdf_new.argtypes = [ct.c_int, ct.c_int]
348
370
  clib.sdf_stack_init.argtypes = [ct.c_void_p]
349
371
  clib.sdf_read_blocklist.argtypes = [ct.c_void_p]
350
372
  clib.sdf_read_blocklist_all.argtypes = [ct.c_void_p]
351
373
  clib.sdf_helper_read_data.argtypes = [ct.c_void_p, ct.POINTER(SdfBlock)]
352
374
  clib.sdf_free_block_data.argtypes = [ct.c_void_p, ct.POINTER(SdfBlock)]
375
+ clib.sdf_stack_destroy.argtypes = [ct.c_void_p]
376
+ clib.sdf_close.argtypes = [ct.c_void_p]
377
+ clib.sdf_write.argtypes = [ct.c_void_p, ct.c_char_p]
378
+ clib.sdf_get_next_block.argtypes = [ct.c_void_p]
379
+ clib.sdf_set_namevalue.argtypes = [
380
+ ct.POINTER(SdfBlock),
381
+ ct.POINTER(ct.c_char_p),
382
+ ct.POINTER(ct.c_void_p),
383
+ ]
384
+ clib.sdf_set_code_name.argtypes = [ct.c_void_p, ct.c_char_p]
385
+ clib.sdf_set_block_name.argtypes = [
386
+ ct.c_void_p,
387
+ ct.c_char_p,
388
+ ct.c_char_p,
389
+ ]
390
+ clib.sdf_set_defaults.argtypes = [
391
+ ct.c_void_p,
392
+ ct.POINTER(SdfBlock),
393
+ ]
394
+ clib.sdf_create_id.argtypes = [
395
+ ct.c_void_p,
396
+ ct.c_char_p,
397
+ ]
398
+ clib.sdf_create_id.restype = ct.POINTER(ct.c_char_p)
399
+ clib.sdf_create_id_array.argtypes = [
400
+ ct.c_void_p,
401
+ ct.c_int,
402
+ ct.POINTER(ct.c_char_p),
403
+ ]
404
+ clib.sdf_create_id_array.restype = ct.POINTER(ct.c_char_p)
353
405
 
354
- h = clib.sdf_open(filename.encode("utf-8"), 0, 1, 0)
406
+ comm = 0
407
+ use_mmap = 0
408
+ if filename is None:
409
+ h = clib.sdf_new(comm, use_mmap)
410
+ else:
411
+ h = clib.sdf_open(filename.encode("utf-8"), comm, mode, use_mmap)
355
412
  if h is None or not bool(h):
356
413
  raise Exception(f"Failed to open file: '{filename}'")
357
414
 
@@ -361,12 +418,16 @@ class BlockList:
361
418
  h._clib = clib
362
419
  self._handle = h
363
420
  clib.sdf_stack_init(h)
364
- if derived:
365
- clib.sdf_read_blocklist_all(h)
421
+ if mode == SDF_READ:
422
+ if derived:
423
+ clib.sdf_read_blocklist_all(h)
424
+ else:
425
+ clib.sdf_read_blocklist(h)
366
426
  else:
367
- clib.sdf_read_blocklist(h)
427
+ clib.sdf_set_code_name(h, code_name.encode("utf-8"))
368
428
 
369
429
  block = h.contents.blocklist
430
+ h.contents.restart_flag = restart
370
431
  self.Header = get_header(h.contents)
371
432
  mesh_id_map = {}
372
433
  mesh_vars = []
@@ -486,12 +547,271 @@ class BlockList:
486
547
 
487
548
  def __del__(self):
488
549
  if self._handle:
489
- self._clib.sdf_stack_destroy.argtypes = [ct.c_void_p]
490
- self._clib.sdf_close.argtypes = [ct.c_void_p]
491
550
  self._clib.sdf_stack_destroy(self._handle)
492
551
  self._clib.sdf_close(self._handle)
493
552
  self._handle = None
494
553
 
554
+ def write(self, filename):
555
+ if not self._handle:
556
+ return
557
+ self._clib.sdf_write(self._handle, filename.encode())
558
+
559
+ def _set_block_name(self, id, name):
560
+ self._clib.sdf_set_block_name(
561
+ self._handle, id.encode("utf-8"), name.encode("utf-8")
562
+ )
563
+
564
+ def _create_id(self, values):
565
+ tmp = self._clib.sdf_create_id(self._handle, values.encode("utf-8"))
566
+ return ct.cast(tmp, ct.c_char_p)
567
+
568
+ def _string_array_ctype(self, values):
569
+ strings = [s.encode("utf-8") for s in values]
570
+ strings = [ct.create_string_buffer(s) for s in strings]
571
+ strings = [ct.cast(s, ct.c_char_p) for s in strings]
572
+ strings = (ct.c_char_p * len(values))(*strings)
573
+ return strings
574
+
575
+ def _create_id_array(self, values):
576
+ values = self._string_array_ctype(values)
577
+ res = self._clib.sdf_create_id_array(self._handle, len(values), values)
578
+ return res
579
+
580
+ def _add_preamble(self, id, name, datatype):
581
+ self._clib.sdf_get_next_block(self._handle)
582
+ h = self._handle.contents
583
+ h.nblocks += 1
584
+ h.nblocks_file += 1
585
+ block = h.current_block.contents
586
+ block._handle = self._handle
587
+ block._blocklist = h.blocklist
588
+ block._data = None
589
+ block.datatype = datatype
590
+ block.in_file = 1
591
+ block.AddBlock = None
592
+ self._set_block_name(id, name)
593
+ return h, block
594
+
595
+ def _add_post(self, block):
596
+ if block.AddBlock:
597
+ newblock = block.AddBlock(block)
598
+ else:
599
+ return
600
+
601
+ id = block.id.decode()
602
+ name = block.name.decode()
603
+ if not block.dont_display:
604
+ self.__dict__[name] = newblock
605
+ if block._data is not None:
606
+ newblock._data = block._data
607
+ self._block_ids.update({id: newblock})
608
+ self._block_names.update({name: newblock})
609
+
610
+ def _add_constant(self, name, value=0, datatype=None, id=None):
611
+ if datatype == SdfDataType.SDF_DATATYPE_CHARACTER:
612
+ print(f'Block "{id}", unsupported datatype: {type(value)}')
613
+ return
614
+
615
+ h, block = self._add_preamble(id, name, datatype)
616
+ block.blocktype = SdfBlockType.SDF_BLOCKTYPE_CONSTANT
617
+ block.AddBlock = BlockConstant
618
+
619
+ const_value = struct.pack(_st_datatypes[block.datatype], value)
620
+ ct.memmove(block.const_value, const_value, 16)
621
+
622
+ self._add_post(block)
623
+
624
+ def _add_namevalue(self, name, value={}, datatype=None, id=None):
625
+ h, block = self._add_preamble(id, name, datatype)
626
+ block.blocktype = SdfBlockType.SDF_BLOCKTYPE_NAMEVALUE
627
+ block.AddBlock = BlockNameValue
628
+
629
+ nvalue = len(value)
630
+ block.ndims = nvalue
631
+ ctype = _ct_datatypes[block.datatype]
632
+ if block.datatype == SdfDataType.SDF_DATATYPE_CHARACTER:
633
+ vals = self._string_array_ctype(value.values())
634
+ else:
635
+ vals = (ctype * nvalue)(*value.values())
636
+ names = self._string_array_ctype(value.keys())
637
+ vals = ct.cast(vals, ct.POINTER(ct.c_void_p))
638
+ self._clib.sdf_set_namevalue(block, names, vals)
639
+
640
+ self._add_post(block)
641
+
642
+ def _add_array(self, name, value=(), datatype=None, id=None):
643
+ if datatype == SdfDataType.SDF_DATATYPE_CHARACTER:
644
+ print(f'Block "{id}", unsupported datatype: {type(value[0])}')
645
+ return
646
+
647
+ h, block = self._add_preamble(id, name, datatype)
648
+ block.blocktype = SdfBlockType.SDF_BLOCKTYPE_ARRAY
649
+ block.AddBlock = BlockArray
650
+
651
+ block._data = np.array(value)
652
+ block.ndims = block._data.ndim
653
+ for i in range(block.ndims):
654
+ block.dims[i] = block._data.shape[i]
655
+ block.data = block._data.ctypes.data_as(ct.c_void_p)
656
+
657
+ self._add_post(block)
658
+
659
+ def _add_plainvar(
660
+ self,
661
+ name,
662
+ value=(),
663
+ datatype=None,
664
+ id=None,
665
+ mult=None,
666
+ units=None,
667
+ mesh_id=None,
668
+ stagger=None,
669
+ ):
670
+ if datatype == SdfDataType.SDF_DATATYPE_CHARACTER:
671
+ print(f'Block "{id}", unsupported datatype: {type(value[0])}')
672
+ return
673
+ try:
674
+ mult = float(mult)
675
+ except Exception:
676
+ if mult is not None:
677
+ print(f"ERROR: unable to use mult parameter, {mult}")
678
+ return
679
+ try:
680
+ stagger = SdfStagger(stagger)
681
+ except Exception:
682
+ if stagger is not None:
683
+ print(f"ERROR: unable to use stagger parameter, {stagger}")
684
+ return
685
+ if units is not None and not isinstance(units, str):
686
+ print(f"ERROR: unable to use units parameter, {units}")
687
+ return
688
+ if mesh_id is not None and not isinstance(mesh_id, str):
689
+ print(f"ERROR: unable to use mesh_id parameter, {mesh_id}")
690
+ return
691
+
692
+ h, block = self._add_preamble(id, name, datatype)
693
+ block.blocktype = SdfBlockType.SDF_BLOCKTYPE_PLAIN_VARIABLE
694
+ block.AddBlock = BlockPlainVariable
695
+
696
+ block._data = np.array(value, order="F")
697
+ block.ndims = block._data.ndim
698
+ for i in range(block.ndims):
699
+ block.dims[i] = block._data.shape[i]
700
+ block.data = block._data.ctypes.data_as(ct.c_void_p)
701
+ if mult is not None:
702
+ block.mult = mult
703
+ if isinstance(units, str):
704
+ block.units = self._create_id(units)
705
+ if isinstance(mesh_id, str):
706
+ block.mesh_id = self._create_id(mesh_id)
707
+ if stagger:
708
+ block.stagger = stagger
709
+
710
+ self._clib.sdf_set_defaults(self._handle, block)
711
+ self._add_post(block)
712
+
713
+ def _add_mesh(
714
+ self,
715
+ name,
716
+ value=None,
717
+ datatype=None,
718
+ id=None,
719
+ units=None,
720
+ labels=None,
721
+ geometry=None,
722
+ **kwargs,
723
+ ):
724
+ if datatype == SdfDataType.SDF_DATATYPE_CHARACTER:
725
+ print(f'Block "{id}", unsupported datatype: {type(value[0])}')
726
+ return
727
+
728
+ h, block = self._add_preamble(id, name, datatype)
729
+
730
+ keys = ["x", "y", "z"]
731
+ keys = [k for k in keys if k in kwargs and kwargs[k] is not None]
732
+ val = np.concatenate([kwargs[k] for k in keys]).flatten()[0]
733
+
734
+ block._data = [np.array(kwargs[k], dtype=val.dtype) for k in keys]
735
+ block._data = [np.array(row, order="F") for row in block._data]
736
+ block._data = tuple(block._data)
737
+ block.ndims = len(block._data)
738
+ block.ngrids = block.ndims
739
+ grids = [row.ctypes.data_as(ct.c_void_p) for row in block._data]
740
+ block.grids = (ct.c_void_p * block.ngrids)(*grids)
741
+ if block._data[0].ndim == 1:
742
+ block.blocktype = SdfBlockType.SDF_BLOCKTYPE_PLAIN_MESH
743
+ block.AddBlock = BlockPlainMesh
744
+ for i in range(block.ndims):
745
+ block.dims[i] = block._data[i].shape[0]
746
+ else:
747
+ block.blocktype = SdfBlockType.SDF_BLOCKTYPE_LAGRANGIAN_MESH
748
+ block.AddBlock = BlockLagrangianMesh
749
+ for i in range(block.ndims):
750
+ block.dims[i] = block._data[0].shape[i]
751
+ if isinstance(units, (list, tuple)):
752
+ block.dim_units = self._create_id_array(units)
753
+ if isinstance(labels, (list, tuple)):
754
+ block.dim_labels = self._create_id_array(labels)
755
+ if isinstance(geometry, str):
756
+ if geometry == "rz":
757
+ geometry = SdfGeometry.SDF_GEOMETRY_CYLINDRICAL
758
+ if isinstance(geometry, int):
759
+ block.geometry = geometry
760
+
761
+ self._clib.sdf_set_defaults(self._handle, block)
762
+ self._add_post(block)
763
+
764
+ def add_block(self, name, value=None, id=None, **kwargs):
765
+ if isinstance(value, dict):
766
+ val = next(iter(value.values()), None)
767
+ add_func = self._add_namevalue
768
+ elif isinstance(value, (tuple, list, np.ndarray)):
769
+ arr = np.array(value)
770
+ if arr.ndim == 1:
771
+ val = value[0]
772
+ add_func = self._add_array
773
+ else:
774
+ val = arr.flatten()[0]
775
+ add_func = self._add_plainvar
776
+ elif value is not None:
777
+ val = value
778
+ add_func = self._add_constant
779
+ else:
780
+ keys = ["x", "y", "z"]
781
+ keys = [k for k in keys if k in kwargs and kwargs[k] is not None]
782
+ val = np.concatenate([kwargs[k] for k in keys]).flatten()[0]
783
+ add_func = self._add_mesh
784
+ if id is None:
785
+ id = "grid"
786
+
787
+ if id is None:
788
+ id = name
789
+ if id in self._block_ids:
790
+ print(f'Unable to create block. ID duplicated: "{id}"')
791
+ return
792
+
793
+ datatype = None
794
+ if isinstance(val, bool):
795
+ datatype = SdfDataType.SDF_DATATYPE_LOGICAL
796
+ elif isinstance(val, np.int32):
797
+ datatype = SdfDataType.SDF_DATATYPE_INTEGER4
798
+ elif isinstance(val, (int, np.int64)):
799
+ datatype = SdfDataType.SDF_DATATYPE_INTEGER8
800
+ elif isinstance(val, np.float32):
801
+ datatype = SdfDataType.SDF_DATATYPE_REAL4
802
+ elif isinstance(val, float):
803
+ datatype = SdfDataType.SDF_DATATYPE_REAL8
804
+ elif isinstance(val, str):
805
+ datatype = SdfDataType.SDF_DATATYPE_CHARACTER
806
+ else:
807
+ add_func = None
808
+
809
+ if add_func:
810
+ add_func(name, value=value, id=id, datatype=datatype, **kwargs)
811
+ else:
812
+ print(f'Block "{id}", unsupported datatype: {type(value)}')
813
+ return
814
+
495
815
  @property
496
816
  def name_dict(self):
497
817
  """Dictionary of blocks using name field as key"""
@@ -889,10 +1209,12 @@ class BlockStitchedTensor(BlockStitched):
889
1209
 
890
1210
  def get_header(h):
891
1211
  d = {}
892
- d["filename"] = h.filename.decode()
1212
+ if h.filename:
1213
+ d["filename"] = h.filename.decode()
893
1214
  d["file_version"] = h.file_version
894
1215
  d["file_revision"] = h.file_revision
895
- d["code_name"] = h.code_name.decode()
1216
+ if h.code_name:
1217
+ d["code_name"] = h.code_name.decode()
896
1218
  d["step"] = h.step
897
1219
  d["time"] = h.time
898
1220
  d["jobid1"] = h.jobid1
@@ -958,7 +1280,7 @@ def read(file=None, convert=False, mmap=0, dict=False, derived=True):
958
1280
 
959
1281
  import warnings
960
1282
 
961
- if file == None:
1283
+ if file is None:
962
1284
  raise TypeError("Missing file parameter")
963
1285
 
964
1286
  if mmap != 0:
@@ -973,3 +1295,23 @@ def read(file=None, convert=False, mmap=0, dict=False, derived=True):
973
1295
  return blocklist._block_names
974
1296
 
975
1297
  return blocklist
1298
+
1299
+
1300
+ def new(dict=False, code_name="sdfr", restart=False):
1301
+ """Creates a new SDF blocklist and returns a dictionary of NumPy arrays.
1302
+
1303
+ Parameters
1304
+ ----------
1305
+ dict : bool, optional
1306
+ Return file contents as a dictionary rather than member names.
1307
+ """
1308
+
1309
+ blocklist = BlockList(mode=SDF_WRITE, code_name=code_name, restart=restart)
1310
+
1311
+ if isinstance(dict, str):
1312
+ if dict == "id" or dict == "ids":
1313
+ return blocklist._block_ids
1314
+ elif isinstance(dict, bool) and dict:
1315
+ return blocklist._block_names
1316
+
1317
+ return blocklist
sdfr/__init__.py CHANGED
@@ -15,9 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- _module_name = "sdfr"
19
-
20
- from .SDF import *
18
+ from .SDF import read
21
19
  from . import sdf_helper
22
20
  from ._commit_info import (
23
21
  __commit_date__,
@@ -28,7 +26,9 @@ from .loadlib import (
28
26
  __library_commit_id__,
29
27
  )
30
28
 
31
- from importlib.metadata import version, PackageNotFoundError
29
+ from importlib.metadata import version
30
+
31
+ _module_name = "sdfr"
32
32
 
33
33
  try:
34
34
  __version__ = version(_module_name)
@@ -37,6 +37,8 @@ except Exception:
37
37
 
38
38
  __all__ = [
39
39
  "SDF",
40
+ "sdf_helper",
41
+ "read",
40
42
  "__library_commit_date__",
41
43
  "__library_commit_id__",
42
44
  "__version__",
sdfr/_commit_info.py CHANGED
@@ -1,2 +1,2 @@
1
- __commit_date__ = "Fri Aug 8 17:11:48 2025 +0100"
2
- __commit_id__ = "254251dfdad1469679c14dd9bbbadf472cd9225b"
1
+ __commit_date__ = "Wed Oct 1 16:24:33 2025 +0100"
2
+ __commit_id__ = "9679453eb2ae01fe2b5845a9826755b73b3d772b"
sdfr/loadlib.py CHANGED
@@ -17,7 +17,6 @@
17
17
 
18
18
  import sys
19
19
  import ctypes as ct
20
- from contextlib import suppress
21
20
  from itertools import product
22
21
  from pathlib import Path
23
22
  from site import getsitepackages
@@ -30,11 +29,6 @@ def _loadlib():
30
29
  packages. This enables the library to be found even on an editable install.
31
30
  Raises a ``RuntimeError`` if it is missing.
32
31
  """
33
- # Try finding library using import.
34
- # Expect this to fail, but it will trigger a rebuild if the project is
35
- # installed in editable mode.
36
- with suppress(ImportError):
37
- import sdfr
38
32
 
39
33
  # Find library in site-packages or local to this module
40
34
  local_dir = Path(__file__).resolve().parent
sdfr/sdf_helper.py CHANGED
@@ -11,11 +11,11 @@ try:
11
11
  TextArea,
12
12
  AnchoredOffsetbox,
13
13
  )
14
- except:
14
+ except Exception:
15
15
  pass
16
16
  try:
17
17
  from mpl_toolkits.axes_grid1 import make_axes_locatable
18
- except:
18
+ except Exception:
19
19
  try:
20
20
  # Workaround for broken macOS installation
21
21
  import sys
@@ -25,11 +25,11 @@ except:
25
25
  os.path.join(matplotlib.__path__[0], "..", "mpl_toolkits")
26
26
  )
27
27
  from axes_grid1 import make_axes_locatable
28
- except:
28
+ except Exception:
29
29
  pass
30
30
  try:
31
31
  import builtins
32
- except:
32
+ except Exception:
33
33
  import __builtin__ as builtins
34
34
 
35
35
  try:
@@ -353,7 +353,7 @@ def get_job_id(file_list=None, base=None, block=None):
353
353
  data = sdf.read(base, mmap=0)
354
354
  if len(data.__dict__) > 1:
355
355
  return data.Header["jobid1"]
356
- except:
356
+ except Exception:
357
357
  pass
358
358
 
359
359
  # Find the job id
@@ -364,7 +364,7 @@ def get_job_id(file_list=None, base=None, block=None):
364
364
  if len(data.__dict__) < 2:
365
365
  continue
366
366
  return data.Header["jobid1"]
367
- except:
367
+ except Exception:
368
368
  pass
369
369
 
370
370
  return None
@@ -435,7 +435,7 @@ def get_files(wkd=None, base=None, block=None, varname=None, fast=True):
435
435
  file_list.append(f)
436
436
  elif len(file_list) > 0:
437
437
  break
438
- except:
438
+ except Exception:
439
439
  pass
440
440
 
441
441
  return list(reversed(file_list))
@@ -708,7 +708,7 @@ def sdfr(filename):
708
708
  def plot_auto(*args, **kwargs):
709
709
  try:
710
710
  dims = args[0].dims
711
- except:
711
+ except Exception:
712
712
  print(
713
713
  "error: Variable cannot be auto determined. "
714
714
  + "Use plot1d or plot2d"
@@ -773,7 +773,7 @@ def plot1d(
773
773
  hold=True,
774
774
  subplot=None,
775
775
  figure=None,
776
- **kwargs
776
+ **kwargs,
777
777
  ):
778
778
  global data
779
779
  global x, y, mult_x, mult_y
@@ -791,7 +791,7 @@ def plot1d(
791
791
  if not hold:
792
792
  try:
793
793
  figure.clf()
794
- except:
794
+ except Exception:
795
795
  pass
796
796
  elif not hold:
797
797
  figure.clf()
@@ -913,7 +913,7 @@ def plot_path(
913
913
  axis_only=False,
914
914
  clip_reflect=False,
915
915
  power=(-3, 3),
916
- **kwargs
916
+ **kwargs,
917
917
  ):
918
918
  """Plot an SDF path variable (eg. a laser ray)
919
919
 
@@ -1022,7 +1022,7 @@ def plot_path(
1022
1022
  if not hold:
1023
1023
  try:
1024
1024
  figure.clf()
1025
- except:
1025
+ except Exception:
1026
1026
  pass
1027
1027
  elif not hold:
1028
1028
  figure.clf()
@@ -1204,7 +1204,7 @@ def plot_path(
1204
1204
  try:
1205
1205
  cbar.formatter.set_powerlimits(power)
1206
1206
  cbar.update_ticks()
1207
- except:
1207
+ except Exception:
1208
1208
  pass
1209
1209
  subplot.colorbar = cax
1210
1210
  plt.sca(ax)
@@ -1278,21 +1278,21 @@ def plot_rays(var, skip=1, rays=None, **kwargs):
1278
1278
  else:
1279
1279
  ray_start, ray_stop = None, None
1280
1280
 
1281
- l = "ray_start"
1282
- if l in kwargs:
1283
- ray_start = kwargs[l]
1281
+ k = "ray_start"
1282
+ if k in kwargs:
1283
+ ray_start = kwargs[k]
1284
1284
 
1285
- l = "ray_stop"
1286
- if l in kwargs:
1287
- ray_stop = kwargs[l]
1285
+ k = "ray_stop"
1286
+ if k in kwargs:
1287
+ ray_stop = kwargs[k]
1288
1288
 
1289
1289
  ray_slice = slice(ray_start, ray_stop, skip)
1290
1290
 
1291
1291
  if isinstance(var, sdf.BlockStitchedPath):
1292
1292
  v = var.data[0]
1293
- l = "_label"
1294
- if l not in kwargs:
1295
- kwargs[l] = var.name
1293
+ lab = "_label"
1294
+ if lab not in kwargs:
1295
+ kwargs[lab] = var.name
1296
1296
 
1297
1297
  if isinstance(v, sdf.BlockStitchedPath):
1298
1298
  for v in var.data:
@@ -1310,8 +1310,8 @@ def plot_rays(var, skip=1, rays=None, **kwargs):
1310
1310
  if k not in kwargs or (
1311
1311
  kwargs[k] and not isinstance(kwargs[k], str)
1312
1312
  ):
1313
- kwargs[k] = kwargs[l] + " $(" + escape_latex(v.units) + ")$"
1314
- del kwargs[l]
1313
+ kwargs[k] = kwargs[lab] + " $(" + escape_latex(v.units) + ")$"
1314
+ del kwargs[lab]
1315
1315
 
1316
1316
  k0 = "vmin"
1317
1317
  k1 = "vmax"
@@ -1424,7 +1424,7 @@ def plot2d_array(
1424
1424
  cbar_wd=5,
1425
1425
  cbar_top=False,
1426
1426
  power=(-3, 3),
1427
- **kwargs
1427
+ **kwargs,
1428
1428
  ):
1429
1429
  import matplotlib as mpl
1430
1430
 
@@ -1468,7 +1468,7 @@ def plot2d_array(
1468
1468
  if not hold:
1469
1469
  try:
1470
1470
  figure.clf()
1471
- except:
1471
+ except Exception:
1472
1472
  pass
1473
1473
  elif not hold:
1474
1474
  figure.clf()
@@ -1573,7 +1573,7 @@ def plot2d_array(
1573
1573
  cmap=cmap,
1574
1574
  vmin=vrange[0],
1575
1575
  vmax=vrange[1],
1576
- **kwargs
1576
+ **kwargs,
1577
1577
  )
1578
1578
  else:
1579
1579
  X = np.multiply(mult_x, X)
@@ -1622,7 +1622,7 @@ def plot2d_array(
1622
1622
  try:
1623
1623
  cbar.formatter.set_powerlimits(power)
1624
1624
  cbar.update_ticks()
1625
- except:
1625
+ except Exception:
1626
1626
  pass
1627
1627
  subplot.colorbar = cax
1628
1628
  plt.sca(ax)
@@ -1663,7 +1663,7 @@ def plot2d(
1663
1663
  add_cbar=True,
1664
1664
  cbar_label=True,
1665
1665
  cbar_top=False,
1666
- **kwargs
1666
+ **kwargs,
1667
1667
  ):
1668
1668
  global data, fig, im, cbar
1669
1669
  global x, y, mult_x, mult_y
@@ -1807,7 +1807,7 @@ def plot2d(
1807
1807
  add_cbar=add_cbar,
1808
1808
  cbar_label=cbar_label,
1809
1809
  cbar_top=cbar_top,
1810
- **kwargs
1810
+ **kwargs,
1811
1811
  )
1812
1812
 
1813
1813
 
@@ -1828,13 +1828,13 @@ def plot_levels(
1828
1828
  out=False,
1829
1829
  title=True,
1830
1830
  levels=True,
1831
- **kwargs
1831
+ **kwargs,
1832
1832
  ):
1833
1833
  global data
1834
1834
 
1835
1835
  try:
1836
1836
  plt.clf()
1837
- except:
1837
+ except Exception:
1838
1838
  pass
1839
1839
 
1840
1840
  if iso is None:
@@ -1882,19 +1882,19 @@ def plot_levels(
1882
1882
 
1883
1883
  if levels:
1884
1884
  fmt = {}
1885
- for l, i in zip(cs.levels, range(1, len(cs.levels) + 1)):
1886
- fmt[l] = str(i)
1885
+ for level, i in zip(cs.levels, range(1, len(cs.levels) + 1)):
1886
+ fmt[level] = str(i)
1887
1887
 
1888
1888
  sidx = ""
1889
1889
  slvl = ""
1890
- for l, i in reversed(
1890
+ for level, i in reversed(
1891
1891
  list(zip(cs.levels, range(1, len(cs.levels) + 1)))
1892
1892
  ):
1893
1893
  # sidx += rtn + "%i" % i
1894
- # slvl += rtn + "%-6.4g" % l
1894
+ # slvl += rtn + "%-6.4g" % level
1895
1895
  # rtn = "\n"
1896
1896
  sidx += "%i\n" % i
1897
- slvl += "%-6.4g\n" % l
1897
+ slvl += "%-6.4g\n" % level
1898
1898
 
1899
1899
  t1 = TextArea("Level", textprops=dict(color="k", fontsize="small"))
1900
1900
  t2 = TextArea(sidx, textprops=dict(color="k", fontsize="small"))
@@ -1974,7 +1974,7 @@ def plot_contour(var, r0=None, r1=None, nl=10, iso=None, title=True, **kwargs):
1974
1974
  out=False,
1975
1975
  title=title,
1976
1976
  levels=False,
1977
- **kwargs
1977
+ **kwargs,
1978
1978
  )
1979
1979
 
1980
1980
 
@@ -1990,17 +1990,17 @@ def getdata(fname, wkd=None, verbose=True, squeeze=False):
1990
1990
  if isinstance(fname, int):
1991
1991
  try:
1992
1992
  filename = wkdir + "/%0.4i.sdf" % fname
1993
- except:
1993
+ except Exception:
1994
1994
  filename = wkdir + "/" + fname
1995
1995
  else:
1996
1996
  filename = fname
1997
1997
 
1998
1998
  try:
1999
1999
  st = os.stat(filename)
2000
- except OSError as e:
2000
+ except OSError:
2001
2001
  try:
2002
2002
  filename = "./%0.4i.sdf" % fname
2003
- except:
2003
+ except Exception:
2004
2004
  filename = "./" + fname
2005
2005
  try:
2006
2006
  st = os.stat(filename)
@@ -2034,7 +2034,7 @@ def getdata(fname, wkd=None, verbose=True, squeeze=False):
2034
2034
  for element in value.dims:
2035
2035
  dims.append([0, element - 1])
2036
2036
  subarray(value, dims)
2037
- except:
2037
+ except Exception:
2038
2038
  pass
2039
2039
 
2040
2040
  sdfdict = data._block_ids
@@ -2164,7 +2164,7 @@ def _get_grid(data, verbose=False):
2164
2164
  var = vargrid.data[n]
2165
2165
  dims = str(tuple(int(i) for i in vargrid.dims))
2166
2166
  if verbose:
2167
- print(key + dims + " = " + k)
2167
+ print(key + dims + " = " + var)
2168
2168
  globals()[key] = var
2169
2169
  builtins.__dict__[key] = var
2170
2170
 
@@ -2234,11 +2234,11 @@ def axis_offset(boxed=False):
2234
2234
  f = 1e-3
2235
2235
 
2236
2236
  # for o in ax.findobj():
2237
- for l in ax.get_lines():
2238
- bb = l.get_clip_box()
2237
+ for line in ax.get_lines():
2238
+ bb = line.get_clip_box()
2239
2239
  bb._bbox = Bbox([[-f, -f], [1 + 2 * f, 1 + 2 * f]])
2240
- l.set_clip_box(bb)
2241
- # l.set_clip_on(False)
2240
+ line.set_clip_box(bb)
2241
+ # line.set_clip_on(False)
2242
2242
 
2243
2243
  if boxed:
2244
2244
  r = matplotlib.patches.Rectangle(
@@ -2309,7 +2309,7 @@ def list_variables(data):
2309
2309
  np.array2string(np.array(val.dims), separator=", "),
2310
2310
  )
2311
2311
  )
2312
- except:
2312
+ except Exception:
2313
2313
  pass
2314
2314
 
2315
2315
 
sdfr/sdfc_shared.dll CHANGED
Binary file
sdfr/sdfc_shared.lib CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: sdfr
3
- Version: 1.4.6
3
+ Version: 1.4.7
4
4
  Summary: Python module for processing SDF files
5
5
  Author-Email: Keith Bennett <k.bennett@warwick.ac.uk>
6
6
  Requires-Dist: numpy
@@ -0,0 +1,12 @@
1
+ sdfr/__init__.py,sha256=Lhq1QwcpLC8oredJjBPvhBt13s6I2t2b4MXKpEHCisQ,1222
2
+ sdfr/_commit_info.py,sha256=LrXAQlTGyMJJESqExix_6P_vsw6c0cSqKL2vGB5wsXY,111
3
+ sdfr/loadlib.py,sha256=AFOSSEuTAu0kMLlVvtE4t_0gDwDF3VQ5HN-nwdNiMDs,2119
4
+ sdfr/SDF.py,sha256=0ltv9XrbR5-WWGmumXO8urGMwS3S_xwSRlnEunkfgxc,43412
5
+ sdfr/sdf_helper.py,sha256=Qg4Jhp69xvoochKt6lNKB6KxqnEnD4vG9GRO5LG0Stk,63666
6
+ sdfr/sdfc_shared.dll,sha256=DjVUAZfWmi8ec2fGQTDVMbb8M-OUdyFjEBP6mhLaLwA,122368
7
+ sdfr/sdfc_shared.lib,sha256=YfbcZ3vBjFYNo0VRChTdIm6GNiU0lTOtSbjq3PLwWow,4270
8
+ sdfr-1.4.7.dist-info/METADATA,sha256=_io1M0S9da5CTLcSYLqCiZuHLwnDq7RIsm7pM-oVfxI,370
9
+ sdfr-1.4.7.dist-info/WHEEL,sha256=7cuQBrKlgrMjywT6nmSZIIhuOog1xNCTkMyVVbw2aow,103
10
+ sdfr-1.4.7.dist-info/licenses/LICENSE,sha256=gpLeavs1KxgJFrpL_uVDh0MoDvPfJoZ89A5dSCl4P5U,1652
11
+ sdfr-1.4.7.dist-info/licenses/LICENSE_README.txt,sha256=KlBSoHArwoXbiygx3IJTjtgM7hLNO9o8ZMlZV77nrXs,235
12
+ sdfr-1.4.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: scikit-build-core 0.11.5
2
+ Generator: scikit-build-core 0.11.6
3
3
  Root-Is-Purelib: false
4
4
  Tag: py3-none-win_amd64
5
5
 
@@ -1,12 +0,0 @@
1
- sdfr/__init__.py,sha256=OxcJAJ0ADoE54vgqMQqxhoFWyU2ldb3fb-_LFyeZZfQ,1209
2
- sdfr/_commit_info.py,sha256=0rgHeEWqDT9BY-sUd4y9DzBpu47pTrR9Witiqaw_g-A,111
3
- sdfr/loadlib.py,sha256=xxp5MX-u7ZHIc12mcvN-y8L5UEjY-aEgINj2r-1swWk,2358
4
- sdfr/SDF.py,sha256=Vka3UM8TCbREKAf0-eppz5crPQ04bvGo2DjpMal4Kx0,31386
5
- sdfr/sdf_helper.py,sha256=EnwHKG0cHHkplE9wKAIdBb-XAhqvVbsG0aDea_6S3zU,63439
6
- sdfr/sdfc_shared.dll,sha256=dJ-8sXbze0DtqEvjrK4VhkPVOeke44HbseNw20HGI8s,121856
7
- sdfr/sdfc_shared.lib,sha256=oIgoIRQf3vaNLlzLS5fgpjpYXVXanlMp037A8EkWNeA,3616
8
- sdfr-1.4.6.dist-info/METADATA,sha256=R-u3p3Va7lHdIEud6a2DFNhIFB71_K8erUQRV3Lndw8,370
9
- sdfr-1.4.6.dist-info/WHEEL,sha256=s8reeTqZgG3jMO9N1mb5NZvAOJEkFQZZpEaDT4R2CPk,103
10
- sdfr-1.4.6.dist-info/licenses/LICENSE,sha256=gpLeavs1KxgJFrpL_uVDh0MoDvPfJoZ89A5dSCl4P5U,1652
11
- sdfr-1.4.6.dist-info/licenses/LICENSE_README.txt,sha256=KlBSoHArwoXbiygx3IJTjtgM7hLNO9o8ZMlZV77nrXs,235
12
- sdfr-1.4.6.dist-info/RECORD,,