tecio-python 0.4.0__py3-none-any.whl → 0.4.2__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.
Files changed (39) hide show
  1. tecio/__init__.py +46 -2
  2. tecio/_constants.py +2 -2
  3. tecio/_dat_read.py +268 -17
  4. tecio/_dat_write.py +347 -10
  5. tecio/_elements.py +1311 -0
  6. tecio/_io.py +108 -31
  7. tecio/_meta.py +47 -20
  8. tecio/_plt_legacy.py +9 -1
  9. tecio/_plt_read.py +285 -89
  10. tecio/_plt_write.py +286 -9
  11. tecio/_reader.py +460 -19
  12. tecio/_szl_read.py +155 -17
  13. tecio/_szl_write.py +322 -11
  14. tecio/_utils.py +78 -15
  15. tecio/_writer.py +963 -102
  16. tecio/cli/tec2mat.py +69 -30
  17. tecio/cli/tecaux.py +24 -30
  18. tecio/cli/tecdump.py +67 -5
  19. tecio/cli/tecelretyp.py +1096 -0
  20. tecio/cli/tecextract.py +57 -14
  21. tecio/cli/tecfix.py +32 -14
  22. tecio/cli/tecmerge.py +289 -45
  23. tecio/cli/teconvert.py +29 -16
  24. tecio/cli/tecscale.py +40 -13
  25. tecio/cli/tecslice.py +158 -69
  26. tecio/cli/tecstats.py +6 -2
  27. tecio/libtecio.py +192 -67
  28. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/matlab/tecmat2struct.m +18 -18
  29. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/paraview/TecplotTecioReader.py +463 -38
  30. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/paraview/TecplotTecioWriter.py +459 -84
  31. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/METADATA +33 -17
  32. tecio_python-0.4.2.dist-info/RECORD +40 -0
  33. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/WHEEL +1 -1
  34. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/entry_points.txt +1 -0
  35. tecio_python-0.4.0.dist-info/RECORD +0 -38
  36. {tecio_python-0.4.0.data/data/share → tecio_python-0.4.2.data/data/share/tecio}/plugins/matlab/contourfe.m +0 -0
  37. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/licenses/LICENSE +0 -0
  38. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/licenses/NOTICE +0 -0
  39. {tecio_python-0.4.0.dist-info → tecio_python-0.4.2.dist-info}/top_level.txt +0 -0
tecio/_io.py CHANGED
@@ -32,11 +32,6 @@ Note:
32
32
  Note:
33
33
  Legacy PLT files (v75, v107, v111) are read-only, so ``"a"`` and ``"a+"`` raise
34
34
  :exc:`ValueError` for them.
35
-
36
- Note:
37
- FEPOLYGON and FEPOLYHEDRON zones are not copied during append operations because the
38
- ``Write`` API does not yet expose a poly-zone writer. A :exc:`NotImplementedError`
39
- is raised if such zones are encountered in the source file.
40
35
  """
41
36
 
42
37
  # ruff: noqa: A001 N806
@@ -58,14 +53,16 @@ from ._plt_read import TecplotPltReader, _is_legacy_plt
58
53
  from ._plt_write import TecplotPltWriter
59
54
  from ._reader import (
60
55
  TecplotAuxDataReader,
56
+ TecplotFEMixedZoneReader,
61
57
  TecplotFEZoneReader,
62
58
  TecplotOrderedZoneReader,
59
+ TecplotPolyZoneReader,
63
60
  TecplotReader,
64
61
  TecplotZoneReader,
65
62
  )
66
63
  from ._szl_read import TecplotSzlReader
67
64
  from ._szl_write import TecplotSzlWriter
68
- from ._writer import TecplotWriter
65
+ from ._writer import TecplotWriter, poly_face_kwargs
69
66
 
70
67
  # --------------------------------------------------------------------------------------
71
68
  # Dispatch table
@@ -164,20 +161,11 @@ def _copy_zones(reader: TecplotReader, writer: TecplotWriter) -> None:
164
161
  writer: An already-opened ``Write`` instance (file handle live).
165
162
 
166
163
  Raises:
167
- NotImplementedError: If a FEPOLYGON or FEPOLYHEDRON zone is
168
- encountered, as the ``Write`` API does not yet support them.
164
+ NotImplementedError: If a zone is neither ordered, finite-element, FEMIXED, nor
165
+ poly, or if the writer's format cannot hold a FEMIXED zone (PLT and DAT).
169
166
 
170
167
  """
171
168
  for zone in reader.zones:
172
- if isinstance(zone, TecplotFEZoneReader) and zone.zone_type in (
173
- ZoneType.FEPOLYGON,
174
- ZoneType.FEPOLYHEDRON,
175
- ):
176
- raise NotImplementedError(
177
- f"Zone '{zone.title}' is {zone.zone_type.name} — poly zone "
178
- "copying is not supported by the Write API yet."
179
- )
180
-
181
169
  # Collect per-variable metadata and data arrays
182
170
  data: list[npt.NDArray] = []
183
171
  value_locations: list[ValueLocation] = []
@@ -206,6 +194,15 @@ def _copy_zones(reader: TecplotReader, writer: TecplotWriter) -> None:
206
194
 
207
195
  if isinstance(zone, TecplotOrderedZoneReader):
208
196
  writer.write_ordered_zone(data=data, **common_kw)
197
+ elif isinstance(zone, TecplotPolyZoneReader):
198
+ con_sharing = zone.shared_connectivity
199
+ writer.write_poly_zone(
200
+ zone_type=zone.zone_type,
201
+ data=data,
202
+ con_sharing=con_sharing,
203
+ **({} if con_sharing is not None else poly_face_kwargs(zone)),
204
+ **common_kw,
205
+ )
209
206
  elif isinstance(zone, TecplotFEZoneReader):
210
207
  # Forward connectivity sharing: when shared, pass ``con_sharing`` and omit
211
208
  # the node map so the writer derives the node/cell counts from the source
@@ -218,10 +215,19 @@ def _copy_zones(reader: TecplotReader, writer: TecplotWriter) -> None:
218
215
  con_sharing=con_sharing,
219
216
  **common_kw,
220
217
  )
218
+ elif isinstance(zone, TecplotFEMixedZoneReader):
219
+ con_sharing = zone.shared_connectivity
220
+ writer.write_femixed_zone(
221
+ data=data,
222
+ cell_shapes=None if con_sharing is not None else zone.section_shapes,
223
+ node_maps=None if con_sharing is not None else zone.node_maps,
224
+ con_sharing=con_sharing,
225
+ **common_kw,
226
+ )
221
227
  else:
222
228
  raise NotImplementedError(
223
- f"Zone '{zone.title}' is neither an ordered nor a classic FE "
224
- "zone, copying it is not supported by the Write API yet."
229
+ f"Zone '{zone.title}' is neither an ordered, classic FE, FEMIXED, nor "
230
+ "poly zone, copying it is not supported by the Write API yet."
225
231
  )
226
232
 
227
233
 
@@ -241,15 +247,10 @@ class AppendWrite:
241
247
 
242
248
  The copy step preserves the original title, variable list, file type, all zone data,
243
249
  all zone metadata (strand, solution time, aux data), and variable sharing.
244
- Connectivity is copied for FE zones.
250
+ Connectivity is copied for FE and poly zones.
245
251
 
246
252
  Do not instantiate this class directly — use :func:`tecio.open`.
247
253
 
248
- Note:
249
- FEPOLYGON and FEPOLYHEDRON zones cannot be copied because the Write API does not
250
- yet expose a poly-zone writer. A :exc:`NotImplementedError` is raised during
251
- ``open()`` if such zones are present in the source file.
252
-
253
254
  Example:
254
255
  >>> with tecio.open("flow.szplt", "a") as tec:
255
256
  ... print(tec.variables) # variable list from the existing file
@@ -339,7 +340,7 @@ class AppendWrite:
339
340
  Delegates to the underlying format writer's ``write_fe_zone``
340
341
  (e.g. :meth:`tecio.TecplotWriter.write_fe_zone`). The ``variables`` parameter is
341
342
  not meaningful here — the variable list is fixed from the existing file.
342
- FEPOLYGON and FEPOLYHEDRON are not supported.
343
+ FEPOLYGON and FEPOLYHEDRON are face-based, use :meth:`write_poly_zone`.
343
344
 
344
345
  Args:
345
346
  zone_type (ZoneType): Element topology. One of:
@@ -378,10 +379,83 @@ class AppendWrite:
378
379
  aux (dict[str, str] | None): Zone-level auxiliary data.
379
380
 
380
381
  Raises:
381
- NotImplementedError: If ``zone_type`` is FEPOLYGON or FEPOLYHEDRON.
382
+ ValueError: If ``zone_type`` is FEPOLYGON or FEPOLYHEDRON.
382
383
  """
383
384
  self._writer.write_fe_zone(*args, **kwargs)
384
385
 
386
+ def write_femixed_zone(self, *args: Any, **kwargs: Any) -> None: # noqa: D417
387
+ """Append a FEMIXED (mixed finite-element) zone.
388
+
389
+ Delegates to the underlying format writer's ``write_femixed_zone``
390
+ (e.g. :meth:`tecio.TecplotSzlWriter.write_femixed_zone`). The ``variables``
391
+ parameter is not meaningful here, the variable list is fixed from the existing
392
+ file. All indices are 0-based.
393
+
394
+ Args:
395
+ data (Sequence[ndarray]): One 1-D array per active variable. NODAL arrays
396
+ need ``num_nodes`` values, CELL_CENTERED arrays the total cell count
397
+ over all sections, both inferred from the node maps.
398
+ cell_shapes (Sequence[FeCellShape] | None): Cell shape of each section
399
+ (1 to 16), all of one spatial dimension.
400
+ node_maps (Sequence[array-like] | None): One ``(num_cells, nodes_per_cell)``
401
+ 0-based integer array per section.
402
+ title (str | None): Zone title. Defaults to ``"FEMixed_Zone_{n}"``.
403
+ value_locations (Sequence[ValueLocation] | None): Per-variable value
404
+ location for active variables. Defaults to all NODAL.
405
+ passive_vars (list | tuple | set | None): Variables to mark passive.
406
+ var_sharing (dict[str | int, int] | None): ``{variable: source zone}``.
407
+ con_sharing (int | None): FEMIXED zone to share connectivity from (0-based),
408
+ in which case ``cell_shapes`` and ``node_maps`` must be omitted.
409
+ solution_time (float): Solution time. Defaults to ``0.0``.
410
+ strand_id (int): Strand ID. Defaults to ``0``.
411
+ aux (dict[str, str] | None): Zone-level auxiliary data.
412
+
413
+ Raises:
414
+ NotImplementedError: For PLT and DAT files, which cannot hold FEMIXED zones.
415
+ ValueError: On an inconsistent section layout.
416
+ """
417
+ self._writer.write_femixed_zone(*args, **kwargs)
418
+
419
+ def write_poly_zone(self, *args: Any, **kwargs: Any) -> None: # noqa: D417
420
+ """Append a polygon or polyhedron (face-based) zone.
421
+
422
+ Delegates to the underlying format writer's ``write_poly_zone``
423
+ (e.g. :meth:`tecio.TecplotPltWriter.write_poly_zone`). The ``variables``
424
+ parameter is not meaningful here, the variable list is fixed from the existing
425
+ file. All indices are 0-based.
426
+
427
+ Args:
428
+ zone_type (ZoneType): :attr:`~tecio.libtecio.ZoneType.FEPOLYGON` or
429
+ :attr:`~tecio.libtecio.ZoneType.FEPOLYHEDRON`.
430
+ data (Sequence[ndarray]): One 1-D array per active variable. NODAL arrays
431
+ need ``num_nodes`` values, CELL_CENTERED arrays ``num_elements``, both
432
+ inferred from the face map.
433
+ face_nodes (array-like | None): Flat node indices of all faces.
434
+ face_node_counts (array-like | None): Nodes per face. Required for
435
+ polyhedra, optional for polygons (always 2).
436
+ face_left_elements (array-like | None): Element left of each face, ``-1``
437
+ for none, ``-(b + 2)`` for boundary face ``b``.
438
+ face_right_elements (array-like | None): Element right of each face.
439
+ boundary_connection_counts (array-like | None): Connections per boundary
440
+ face.
441
+ boundary_connection_elements (array-like | None): Flat neighbor elements.
442
+ boundary_connection_zones (array-like | None): Flat zone of each neighbor.
443
+ title (str | None): Zone title. Defaults to ``"Poly_Zone_{n}"``.
444
+ value_locations (Sequence[ValueLocation] | None): Per-variable value
445
+ location for active variables. Defaults to all NODAL.
446
+ passive_vars (list | tuple | set | None): Variables to mark passive.
447
+ var_sharing (dict[str | int, int] | None): ``{variable: source zone}``.
448
+ con_sharing (int | None): Zone to share the face map from (0-based).
449
+ solution_time (float): Solution time. Defaults to ``0.0``.
450
+ strand_id (int): Strand ID. Defaults to ``0``.
451
+ aux (dict[str, str] | None): Zone-level auxiliary data.
452
+
453
+ Raises:
454
+ NotImplementedError: For SZPLT files, which cannot hold poly zones.
455
+ ValueError: On an inconsistent or out of range face map.
456
+ """
457
+ self._writer.write_poly_zone(*args, **kwargs)
458
+
385
459
  def add_auxdataset_dict(self, auxdict: dict[str, Any]) -> None:
386
460
  """Buffer dataset-level auxiliary data."""
387
461
  self._writer.add_auxdataset_dict(auxdict)
@@ -745,8 +819,10 @@ def open(
745
819
  * - ``variables``
746
820
  - ``None``
747
821
  - Variable name list. For SZL and PLT this may be deferred to the first
748
- :meth:`~tecio.TecplotWriter.write_ordered_zone` or
749
- :meth:`~tecio.TecplotWriter.write_fe_zone` call. Required at open time
822
+ :meth:`~tecio.TecplotWriter.write_ordered_zone`,
823
+ :meth:`~tecio.TecplotWriter.write_fe_zone`,
824
+ :meth:`~tecio.TecplotWriter.write_femixed_zone`, or
825
+ :meth:`~tecio.TecplotWriter.write_poly_zone` call. Required at open time
750
826
  for DAT.
751
827
  * - ``file_type``
752
828
  - ``FileType.FULL``
@@ -774,8 +850,6 @@ def open(
774
850
  on a legacy PLT file (v75, v107, v111).
775
851
  FileNotFoundError: ``'r'``, ``'a'``, or ``'a+'`` on a missing file.
776
852
  FileExistsError: ``'x'`` on an existing file.
777
- NotImplementedError: Append mode on a file containing FEPOLYGON or FEPOLYHEDRON
778
- zones.
779
853
 
780
854
  Examples:
781
855
  Read a file:
@@ -837,6 +911,9 @@ def open(
837
911
  def _validated_ext(path: str | os.PathLike) -> str:
838
912
  """Return *path*'s lowercased extension, or raise if unsupported.
839
913
 
914
+ Raises:
915
+ ValueError: If the extension is not supported.
916
+
840
917
  Example:
841
918
  >>> _validated_ext("flow.szplt")
842
919
  '.szplt'
tecio/_meta.py CHANGED
@@ -35,6 +35,7 @@ if TYPE_CHECKING:
35
35
  from ._constants import (
36
36
  DataType,
37
37
  FaceNeighborMode,
38
+ FeCellShape,
38
39
  FileType,
39
40
  ValueLocation,
40
41
  ZoneType,
@@ -56,26 +57,34 @@ class ZoneMeta:
56
57
  variable-type arrays of a ``TECZNE142`` zone header.
57
58
 
58
59
  Attributes:
59
- index: 0-based index of this zone within the dataset.
60
- title: Zone title.
61
- zone_type: The zone's :class:`~tecio.libtecio.ZoneType`.
62
- solution_time: Solution time (``0.0`` for static zones).
63
- strand_id: Strand ID (``0`` for static zones).
64
- num_aux_items: Number of zone-level auxiliary items written.
65
- dimensions: Nodal ``(imax, jmax, kmax)`` for ORDERED zones, else
66
- ``None``.
67
- num_nodes: Node count for FE zones, else ``None``.
68
- num_elements: Element count for FE zones, else ``None``.
69
- face_neighbor_mode: The zone's :class:`~tecio.FaceNeighborMode`, else
70
- ``None`` if it has no face-neighbor connections.
71
- num_face_connections: Number of face-neighbor connections written,
72
- else ``None`` if it has none.
73
- value_locations: Per-variable value location, full dataset length.
74
- passive_vars: Per-variable passive flags, full dataset length.
75
- shared_vars: Per-variable share-from zone index, or ``None`` for not
76
- shared, full dataset length.
77
- data_types: Per-variable data type, full dataset length.
78
-
60
+ index: 0-based index of this zone within the dataset.
61
+ title: Zone title.
62
+ zone_type: The zone's :class:`~tecio.libtecio.ZoneType`.
63
+ solution_time: Solution time (``0.0`` for static zones).
64
+ strand_id: Strand ID (``0`` for static zones).
65
+ num_aux_items: Number of zone-level auxiliary items written.
66
+ dimensions: Nodal ``(imax, jmax, kmax)`` for ORDERED zones, else
67
+ ``None``.
68
+ num_nodes: Node count for FE zones, else ``None``.
69
+ num_elements: Element count for FE zones, else ``None``.
70
+ face_neighbor_mode: The zone's :class:`~tecio.FaceNeighborMode`, else
71
+ ``None`` if it has no face-neighbor connections.
72
+ num_face_connections: Number of face-neighbor connections written, else
73
+ ``None`` if it has none.
74
+ num_faces: Face count for poly zones, else ``None``.
75
+ total_face_nodes: Total face-node entries for poly zones, else ``None``.
76
+ num_boundary_faces: Boundary face count for poly zones, else ``None``.
77
+ num_boundary_connections: Total boundary connections for poly zones, else
78
+ ``None``.
79
+ section_shapes: Cell shape of each section for FEMIXED zones, else
80
+ ``None``.
81
+ section_num_elements: Cell count of each section for FEMIXED zones, else
82
+ ``None``.
83
+ value_locations: Per-variable value location, full dataset length.
84
+ passive_vars: Per-variable passive flags, full dataset length.
85
+ shared_vars: Per-variable share-from zone index, or ``None`` for
86
+ not shared, full dataset length.
87
+ data_types: Per-variable data type, full dataset length.
79
88
  """
80
89
 
81
90
  index: int
@@ -90,6 +99,14 @@ class ZoneMeta:
90
99
  num_elements: int | None = None
91
100
  face_neighbor_mode: FaceNeighborMode | None = None
92
101
  num_face_connections: int | None = None
102
+ # Poly zones (FEPOLYGON/FEPOLYHEDRON) also record their face-map sizes.
103
+ num_faces: int | None = None
104
+ total_face_nodes: int | None = None
105
+ num_boundary_faces: int | None = None
106
+ num_boundary_connections: int | None = None
107
+ # FEMIXED zones record their per-section layout.
108
+ section_shapes: tuple[FeCellShape, ...] | None = None
109
+ section_num_elements: tuple[int, ...] | None = None
93
110
  # Per-variable descriptors (length == dataset variable count).
94
111
  value_locations: tuple[ValueLocation, ...] = ()
95
112
  passive_vars: tuple[bool, ...] = ()
@@ -101,6 +118,16 @@ class ZoneMeta:
101
118
  """Nodal ``(imax, jmax, kmax)`` for ORDERED zones, else ``None``."""
102
119
  return self.dimensions
103
120
 
121
+ @property
122
+ def num_cells(self) -> int | None:
123
+ """Cell count of any zone type, or ``None`` if not recorded."""
124
+ if self.num_elements is not None:
125
+ return self.num_elements
126
+ shape = self.cell_shape
127
+ if shape is None:
128
+ return None
129
+ return shape[0] * shape[1] * shape[2]
130
+
104
131
  @property
105
132
  def cell_shape(self) -> tuple[int, ...] | None:
106
133
  """Cell-centred ``(imax-1, jmax-1, kmax-1)`` (floored at 1) or ``None``."""
tecio/_plt_legacy.py CHANGED
@@ -149,7 +149,11 @@ def parse_v75_header(parser: _PltParser, fp: io.BufferedIOBase) -> None:
149
149
 
150
150
 
151
151
  def _parse_v75_zone_header(parser: _PltParser, fp: io.BufferedIOBase) -> None:
152
- """Parse one v75 zone header record and append it to ``parser.zones``."""
152
+ """Parse one v75 zone header record and append it to ``parser.zones``.
153
+
154
+ Raises:
155
+ PltReadError: If the data format or the FE element type is not recognised.
156
+ """
153
157
  byte_order = parser.byte_order
154
158
  meta = _ZoneMeta()
155
159
 
@@ -275,6 +279,10 @@ def parse_v75_data_section(parser: _PltParser, fp: io.BufferedIOBase) -> None:
275
279
 
276
280
  Iterates zones in declaration order, matching :meth:`_PltParser`'s
277
281
  contract for every other version.
282
+
283
+ Raises:
284
+ PltReadError: If a zone marker is wrong or a repeated variable reference is
285
+ invalid.
278
286
  """
279
287
  byte_order = parser.byte_order
280
288
  num_vars = len(parser.var_names)