ansys-pyensight-core 0.6.2__py3-none-any.whl → 0.7.0__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 ansys-pyensight-core might be problematic. Click here for more details.

@@ -193,7 +193,7 @@ class DockerLauncher(Launcher):
193
193
 
194
194
  self._docker_client = docker.from_env()
195
195
  except ModuleNotFoundError:
196
- raise RuntimeError("The pyansys-docker module must be installed for DockerLauncher")
196
+ raise RuntimeError("The docker module must be installed for DockerLauncher")
197
197
  except Exception:
198
198
  raise RuntimeError("Cannot initialize Docker")
199
199
 
@@ -308,7 +308,7 @@ class DockerLauncher(Launcher):
308
308
  try:
309
309
  import docker
310
310
  except ModuleNotFoundError: # pragma: no cover
311
- raise RuntimeError("The pyansys-docker module must be installed for DockerLauncher")
311
+ raise RuntimeError("The docker module must be installed for DockerLauncher")
312
312
  except Exception: # pragma: no cover
313
313
  raise RuntimeError("Cannot initialize Docker")
314
314
 
@@ -1113,6 +1113,55 @@ class Session:
1113
1113
  if self.cmd(cmd) != 0:
1114
1114
  raise RuntimeError("Unable to load the dataset.")
1115
1115
 
1116
+ def download_pyansys_example(
1117
+ self, filename: str, directory: Optional[str] = None, root: Optional[str] = None
1118
+ ) -> str:
1119
+ """Download an example dataset from the ansys/example-data repository.
1120
+ The dataset is downloaded local to the EnSight server location, so that it can
1121
+ be downloaded even if running from a container.
1122
+
1123
+ Parameters
1124
+ ----------
1125
+ filename: str
1126
+ The filename to download
1127
+ directory: str
1128
+ The directory to download the filename from
1129
+ root: str
1130
+ If set, the download will happen from another location
1131
+
1132
+ Returns
1133
+ -------
1134
+ pathname: str
1135
+ The download location, local to the EnSight server directory
1136
+
1137
+ Examples
1138
+ --------
1139
+ >>> from ansys.pyensight.core import DockerLauncher
1140
+ >>> session = DockerLauncher().start(data_directory="D:\\")
1141
+ >>> cas_file = session.download_pyansys_example("mixing_elbow.cas.h5","pyfluent/mixing_elbow")
1142
+ >>> dat_file = session.download_pyansys_example("mixing_elbow.dat.h5","pyfluent/mixing_elbow")
1143
+ >>> session.load_data(cas_file, result_file=dat_file)
1144
+ >>> remote = session.show("remote")
1145
+ >>> remote.browser()
1146
+ """
1147
+ base_uri = "https://github.com/ansys/example-data/raw/master"
1148
+ if root is not None:
1149
+ base_uri = root
1150
+ uri = f"{base_uri}/{filename}"
1151
+ if directory:
1152
+ uri = f"{base_uri}/{directory}/{filename}"
1153
+ pathname = f"{self.launcher.session_directory}/{filename}"
1154
+ script = "import requests\n"
1155
+ script += "import shutil\n"
1156
+ script += "import os\n"
1157
+ script += f'url = "{uri}"\n'
1158
+ script += f'outpath = r"""{pathname}"""\n'
1159
+ script += "with requests.get(url, stream=True) as r:\n"
1160
+ script += " with open(outpath, 'wb') as f:\n"
1161
+ script += " shutil.copyfileobj(r.raw, f)\n"
1162
+ self.cmd(script, do_eval=False)
1163
+ return pathname
1164
+
1116
1165
  def load_example(
1117
1166
  self, example_name: str, uncompress: bool = False, root: Optional[str] = None
1118
1167
  ) -> str:
@@ -1151,16 +1200,8 @@ class Session:
1151
1200
  base_uri = "https://s3.amazonaws.com/www3.ensight.com/PyEnSight/ExampleData"
1152
1201
  if root is not None:
1153
1202
  base_uri = root
1154
- uri = f"{base_uri}/{example_name}"
1155
- pathname = f"{self.launcher.session_directory}/{example_name}"
1156
- script = "import requests\n"
1157
- script += "import shutil\n"
1158
- script += "import os\n"
1159
- script += f'url = "{uri}"\n'
1160
- script += f'outpath = r"""{pathname}"""\n'
1161
- script += "with requests.get(url, stream=True) as r:\n"
1162
- script += " with open(outpath, 'wb') as f:\n"
1163
- script += " shutil.copyfileobj(r.raw, f)\n"
1203
+ pathname = self.download_pyansys_example(example_name, root=base_uri)
1204
+ script = f'outpath = r"""{pathname}"""\n'
1164
1205
  if uncompress:
1165
1206
  # in this case, remove the extension and unzip the file
1166
1207
  pathname_dir = os.path.splitext(pathname)[0]
@@ -73,8 +73,6 @@ class Export:
73
73
  ) -> None:
74
74
  """Render an image of the current EnSight scene.
75
75
 
76
- This method returns a PIL image object.
77
-
78
76
  Parameters
79
77
  ----------
80
78
  filename : str
@@ -464,3 +462,108 @@ class Export:
464
462
  mp4_data = fp.read()
465
463
 
466
464
  return mp4_data
465
+
466
+ GEOM_EXPORT_GLTF = "gltf2"
467
+ GEOM_EXPORT_AVZ = "avz"
468
+ GEOM_EXPORT_PLY = "ply"
469
+ GEOM_EXPORT_STL = "stl"
470
+
471
+ extension_map = {
472
+ GEOM_EXPORT_GLTF: ".glb",
473
+ GEOM_EXPORT_AVZ: ".avz",
474
+ GEOM_EXPORT_PLY: ".ply",
475
+ GEOM_EXPORT_STL: ".stl",
476
+ }
477
+
478
+ def _geometry_remote(
479
+ self, format: str, starting_timestep: int, frames: int, delta_timestep: int
480
+ ) -> bytes:
481
+ """EnSight-side implementation.
482
+
483
+ Parameters
484
+ ----------
485
+ format : str
486
+ The format to export
487
+ starting_timestep: int
488
+ The first timestep to export. If None, defaults to the current timestep
489
+ frames: int
490
+ Number of timesteps to save. If None, defaults from the current timestep to the last
491
+ delta_timestep: int
492
+ The delta timestep to use when exporting
493
+
494
+ Returns
495
+ -------
496
+ bytes
497
+ Geometry export in bytes
498
+ """
499
+ rawdata = None
500
+ extension = self.extension_map.get(format)
501
+ if not extension:
502
+ raise RuntimeError("The geometry export format provided is not supported.")
503
+ with tempfile.TemporaryDirectory() as tmpdirname:
504
+ self._ensight.part.select_all()
505
+ self._ensight.savegeom.format(format)
506
+ self._ensight.savegeom.begin_step(starting_timestep)
507
+ # frames is 1-indexed, so I need to decrease of 1
508
+ self._ensight.savegeom.end_step(starting_timestep + frames - 1)
509
+ self._ensight.savegeom.step_by(delta_timestep)
510
+ tmpfilename = os.path.join(tmpdirname, str(uuid.uuid1()))
511
+ self._ensight.savegeom.save_geometric_entities(tmpfilename)
512
+ with open(tmpfilename + extension, "rb") as tmpfile:
513
+ rawdata = tmpfile.read()
514
+ return rawdata
515
+
516
+ def geometry(
517
+ self,
518
+ filename: str,
519
+ format: str = GEOM_EXPORT_GLTF,
520
+ starting_timestep: Optional[int] = None,
521
+ frames: Optional[int] = 1,
522
+ delta_timestep: Optional[int] = None,
523
+ ) -> None:
524
+ """Export a geometry file.
525
+
526
+ Parameters
527
+ ----------
528
+ filename: str
529
+ The location where to export the geometry
530
+ format : str
531
+ The format to export
532
+ starting_timestep: int
533
+ The first timestep to export. If None, defaults to the current timestep
534
+ frames: int
535
+ Number of timesteps to save. If None, defaults from the current timestep to the last
536
+ delta_timestep: int
537
+ The delta timestep to use when exporting
538
+
539
+ Examples
540
+ --------
541
+ >>> s = LocalLauncher().start()
542
+ >>> data = f"{s.cei_home}/ensight{s.cei_suffix}gui/demos/Crash Queries.ens"
543
+ >>> s.ensight.objs.ensxml_restore_file(data)
544
+ >>> s.ensight.utils.export.geometry("local_file.glb", format=s.ensight.utils.export.GEOM_EXPORT_GLTF)
545
+ """
546
+ if not starting_timestep:
547
+ starting_timestep = int(self._ensight.objs.core.TIMESTEP)
548
+ if not frames or frames == -1:
549
+ # Timesteps are 0-indexed so frames need to be increased of 1
550
+ frames = int(self._ensight.objs.core.TIMESTEP_LIMITS[1]) + 1
551
+ if not delta_timestep:
552
+ delta_timestep = 1
553
+ self._remote_support_check()
554
+ raw_data = None
555
+ if isinstance(self._ensight, ModuleType):
556
+ raw_data = self._geometry_remote(
557
+ format,
558
+ starting_timestep=starting_timestep,
559
+ frames=frames,
560
+ delta_timestep=delta_timestep,
561
+ )
562
+ else:
563
+ cmd = f"ensight.utils.export._geometry_remote('{format}', {starting_timestep}, {frames}, {delta_timestep})"
564
+ raw_data = self._ensight._session.cmd(cmd)
565
+ if raw_data:
566
+ with open(filename, "wb") as fp:
567
+ fp.write(raw_data)
568
+ else:
569
+ raise IOError("Export was not successful")
@@ -31,24 +31,46 @@ class Support:
31
31
  def __init__(self, interface: Union["ensight_api.ensight", "ensight"]):
32
32
  self._ensight = interface
33
33
 
34
- @staticmethod
35
- def scoped_name(obj: Any) -> ContextManager:
34
+ def scoped_name(self, obj: Any, native_exceptions: bool = False) -> ContextManager:
36
35
  """Allow for the use of ``with`` to shorten APIs.
37
36
 
38
37
  In the EnSight and PyEnsight APIs, the interfaces can become lengthy.
39
38
  This class makes it possible to shorten APIs for modules, classes,
40
- and namespaces.
39
+ and namespaces. The native_exceptions keyword can be used to enable
40
+ exceptions for EnSight native Python API. By default, an invalid
41
+ native API call like ``ensight.part.select_begin(-9999)`` will return
42
+ -1. If native_exceptions is True, a Python exception will be thrown.
43
+ The scope of this operational change parallels the scoped_name()
44
+ instance.
45
+
46
+ Parameters
47
+ ----------
48
+ obj: Any
49
+ The object for which to generate a simplified namespace.
50
+ native_exceptions: bool
51
+ If True, then EnSight native Python API exceptions are enabled.
52
+ The default is False.
53
+
54
+ Returns
55
+ -------
56
+ The passed object wrapped in a context manager that can be used as a
57
+ simplified namespace.
41
58
 
42
59
  Examples
43
60
  --------
44
61
  >>> sn = s.ensight.utils.support.scoped_name
45
62
  >>> with sn(s.ensight.objs.core) as core, sn(s.ensight.objs.enums) as enums:
46
63
  >>> print(core.PARTS.find(True, enums.VISIBLE))
64
+
47
65
  >>> sn = ensight.utils.support.scoped_name
48
66
  >>> with sn(ensight.objs.core) as core, sn(ensight.objs.enums) as enums:
49
67
  >>> print(core.PARTS.find(True, enums.VISIBLE))
68
+
69
+ >>> sn = ensight.utils.support.scoped_name
70
+ >>> with sn(ensight.part, native_exceptions=True) as part:
71
+ >>> part.select_begin(-9999)
50
72
  """
51
- return ScopedName(obj)
73
+ return ScopedName(self._ensight, obj, native_exceptions=native_exceptions)
52
74
 
53
75
 
54
76
  class ScopedName:
@@ -59,11 +81,26 @@ class ScopedName:
59
81
  and namespaces.
60
82
  """
61
83
 
62
- def __init__(self, obj: Any):
84
+ def __init__(
85
+ self,
86
+ interface: Union["ensight_api.ensight", "ensight"],
87
+ obj: Any,
88
+ native_exceptions: bool = False,
89
+ ):
63
90
  self._obj = obj
91
+ self._ensight = interface
92
+ self._old_raise = None
93
+ if native_exceptions:
94
+ # if we are being asked to enable exceptions, record what to restore it to
95
+ self._old_raise = self._ensight.query("SENDMESG_RAISE")
64
96
 
65
97
  def __enter__(self) -> Any:
98
+ if self._old_raise is not None:
99
+ # if a restore value is set, enable them
100
+ self._ensight.sendmesgoptions(exception=1)
66
101
  return self._obj
67
102
 
68
103
  def __exit__(self, exc_type, exc_value, exc_trace):
69
- pass
104
+ if self._old_raise is not None:
105
+ # if the restore value is set, restore it here
106
+ self._ensight.sendmesgoptions(exception=self._old_raise)
@@ -1,24 +1,24 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ansys-pyensight-core
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: A python wrapper for Ansys EnSight
5
5
  Author-email: "ANSYS, Inc." <pyansys.core@ansys.com>
6
6
  Maintainer-email: "ANSYS, Inc." <pyansys.core@ansys.com>
7
- Requires-Python: >=3.8,<4
7
+ Requires-Python: >=3.9,<4
8
8
  Description-Content-Type: text/x-rst
9
9
  Classifier: Development Status :: 4 - Beta
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
12
12
  Classifier: License :: OSI Approved :: MIT License
13
13
  Classifier: Operating System :: OS Independent
14
- Classifier: Programming Language :: Python :: 3.8
15
14
  Classifier: Programming Language :: Python :: 3.9
16
15
  Classifier: Programming Language :: Python :: 3.10
17
16
  Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Dist: importlib-metadata>=4.0; python_version<='3.8'
19
19
  Requires-Dist: ansys-api-pyensight==0.3.2
20
20
  Requires-Dist: requests>=2.28.2
21
- Requires-Dist: pyansys-docker>=5.0.4
21
+ Requires-Dist: docker>=6.1.0
22
22
  Requires-Dist: urllib3<2
23
23
  Requires-Dist: typing>=3.7.4.3
24
24
  Requires-Dist: typing-extensions>=4.5.0
@@ -35,7 +35,7 @@ Requires-Dist: ansys-sphinx-theme==0.9.9 ; extra == "doc"
35
35
  Requires-Dist: sphinx-copybutton==0.5.2 ; extra == "doc"
36
36
  Requires-Dist: sphinx-gallery==0.13.0 ; extra == "doc"
37
37
  Requires-Dist: sphinxcontrib-mermaid==0.9.2 ; extra == "doc"
38
- Requires-Dist: pyansys-docker>=5.0.4 ; extra == "doc"
38
+ Requires-Dist: docker>=6.1.0 ; extra == "doc"
39
39
  Requires-Dist: matplotlib==3.7.2 ; extra == "doc"
40
40
  Requires-Dist: requests>=2.28.2 ; extra == "doc"
41
41
  Requires-Dist: sphinxcontrib.jquery==4.1 ; extra == "doc"
@@ -47,7 +47,7 @@ Requires-Dist: dill>=0.3.5.1 ; extra == "tests"
47
47
  Requires-Dist: pytest-mock==3.10.0 ; extra == "tests"
48
48
  Requires-Dist: urllib3==1.26.10 ; extra == "tests"
49
49
  Requires-Dist: requests>=2.28.2 ; extra == "tests"
50
- Requires-Dist: pyansys-docker>=5.0.4 ; extra == "tests"
50
+ Requires-Dist: docker>=6.1.0 ; extra == "tests"
51
51
  Project-URL: Changelog, https://github.com/ansys/pyensight/blob/main/CHANGELOG.rst
52
52
  Project-URL: Documentation, https://ensight.docs.pyansys.com/
53
53
  Project-URL: Homepage, https://github.com/ansys/pyensight
@@ -131,7 +131,7 @@ Installation
131
131
  ------------
132
132
  To use PyEnSight, you must have a locally installed and licensed copy of
133
133
  Ansys EnSight 2022 R2 or later. The ``ansys-pyensight-core`` package supports
134
- Python 3.8 through Python 3.11 on Windows and Linux.
134
+ Python 3.9 through Python 3.12 on Windows and Linux.
135
135
 
136
136
  Two modes of installation are available:
137
137
 
@@ -1,6 +1,6 @@
1
1
  ansys/pyensight/core/__init__.py,sha256=ZOASvqNxSR8CGJDHQACGwjtFVvI_vmmfbpy1IAmEJhk,828
2
2
  ansys/pyensight/core/deep_pixel_view.html,sha256=oZmcCIS3Dqqsoj8oheYubLAH2ZVKXao3iJM2WXYBEKs,3421
3
- ansys/pyensight/core/dockerlauncher.py,sha256=Bf3NsjxRhF4-rvgBv56v82EYaMYVr6k0hCYA8qwVvrc,27191
3
+ ansys/pyensight/core/dockerlauncher.py,sha256=tFiemu2hFQE_Ce0FlJ_TdqUs36W-gxtoe5uRL0u6JXs,27175
4
4
  ansys/pyensight/core/enscontext.py,sha256=UfeFvY4ZyOcIkgKcIyhs3GohZhWl515QFhJtBxvIfpE,11803
5
5
  ansys/pyensight/core/enshell_grpc.py,sha256=nNvJqrFG_-glM90dPAC6anFT9qXg7WohQ6CoULXgaSQ,15134
6
6
  ansys/pyensight/core/ensight_grpc.py,sha256=yFnvxjI2cAWd0c0gcM46MEIA5Ov7DUMlufqUwwc3g9U,14343
@@ -11,16 +11,16 @@ ansys/pyensight/core/listobj.py,sha256=vsVTeI3RY0P1n5GNOHW-iU95GCWnHlOg_E6leVMQS
11
11
  ansys/pyensight/core/locallauncher.py,sha256=sgaPrG-7ctXZ_ytGuHeriiVmgvI0kUeX6nKVJ4OiDUs,13984
12
12
  ansys/pyensight/core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  ansys/pyensight/core/renderable.py,sha256=z61Pum_Pa2CVoXVWOCqPngeHT_ifBS3fpqA5mZDDmnc,30777
14
- ansys/pyensight/core/session.py,sha256=fI-Z_dNJz7wD_wOabF7-jd1lSq8z3KsqS70ECeAz4NY,61036
14
+ ansys/pyensight/core/session.py,sha256=nTeqiXsOz_FffeYGsYLsWDznP86-ZBxS0AA8wgOEBeU,62690
15
15
  ansys/pyensight/core/sgeo_poll.html,sha256=1M4BIc5CZpYA3b40qzk22NcPCLhjFnWdoS2PrS6Rhn4,752
16
16
  ansys/pyensight/core/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  ansys/pyensight/core/utils/adr.py,sha256=XslZhlwcrSGzOlnhzprOv3ju_ppxxsWBjCnQL5KiNms,3570
18
- ansys/pyensight/core/utils/export.py,sha256=RDJXrVoLcxSXfiGyh_0Bxhx-tsZr_tFmKe0-1WFuc38,17652
18
+ ansys/pyensight/core/utils/export.py,sha256=MGdPAPpI4CoLR-Fnctkqf9J7--J3DPEXK79kKZGVCqw,21552
19
19
  ansys/pyensight/core/utils/parts.py,sha256=x0Zso-ef64UJ-3BmYS3dymjftaWQI21WFTsDt-ghI-k,3986
20
20
  ansys/pyensight/core/utils/query.py,sha256=cQXt_07ZuNAwueAIXinI3_f7G9lXass6j7G0aRJltZE,19035
21
- ansys/pyensight/core/utils/support.py,sha256=gNBH_VyQ_Gdas7P28W_GZ62Tz4Gg7YK8UASUzdT-lSU,2397
21
+ ansys/pyensight/core/utils/support.py,sha256=QI3z9ex7zJxjFbkCPba9DWqWgPFIThORqr0nvRfVjuc,4089
22
22
  ansys/pyensight/core/utils/views.py,sha256=vf4gSBRl6uC_LPwZdzrdMcR0dyi_PwYmRo20CPmjEBE,12209
23
- ansys_pyensight_core-0.6.2.dist-info/LICENSE,sha256=qQWivZ12ETN5l3QxvTARY-QI5eoRRlyHdwLlAj0Bg5I,1089
24
- ansys_pyensight_core-0.6.2.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
25
- ansys_pyensight_core-0.6.2.dist-info/METADATA,sha256=xrpWIqcf30R_4dS1BEvbpSxWvDMTqkUxa5uf3I9wMxI,11804
26
- ansys_pyensight_core-0.6.2.dist-info/RECORD,,
23
+ ansys_pyensight_core-0.7.0.dist-info/LICENSE,sha256=qQWivZ12ETN5l3QxvTARY-QI5eoRRlyHdwLlAj0Bg5I,1089
24
+ ansys_pyensight_core-0.7.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
25
+ ansys_pyensight_core-0.7.0.dist-info/METADATA,sha256=nKZPh4wq6SSDRrRwbZsHViS4MSp82NPfOXVOWqXARvE,11781
26
+ ansys_pyensight_core-0.7.0.dist-info/RECORD,,