Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small updates on seissolxdmf and seissolxdmfwriter #17

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion seissolxdmf/seissolxdmf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
from .seissolxdmf import *
__version__ = '0.1.3'
try:
from importlib.metadata import version, PackageNotFoundError
except ImportError:
from importlib_metadata import version, PackageNotFoundError

try:
__version__ = version("seissolxdmf")
except PackageNotFoundError:
# If the package is not installed, don't add __version__
pass
4 changes: 2 additions & 2 deletions seissolxdmf/seissolxdmf/seissolxdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get(prop):
if path is not None:
ref = tree.xpath(path)[0]
return get(ref)
raise NameError("%s not found in dataset" % (dataName))
raise NameError(f"{dataName} not found in dataset, available variables are {self.ReadAvailableDataFields()}")

def ReadTopologyOrGeometry(self, attribute):
""" Common function to read either connect or geometry """
Expand Down Expand Up @@ -282,5 +282,5 @@ def LoadData(self, dataName, nElements, idt=0, oneDtMem=False, firstElement=-1):
idt = -1
if firstElement == -1:
firstElement = 0
myData = ReadDataChunk(dataName, firstElement, nElements, idt)
myData = self.ReadDataChunk(dataName, firstElement, nElements, idt)
return [myData, data_prec]
33 changes: 0 additions & 33 deletions seissolxdmf/setup.py

This file was deleted.

26 changes: 26 additions & 0 deletions seissolxdmfwriter/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "seissolxdmfwriter"
version = "0.4.2"
authors = [
{name = "SeisSol Group"},
]
description = "A python writer for SeisSol xdmf output"
readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">=3.6"
keywords = ["SeisSol"]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
dependencies = [
"numpy", "h5py" ,"seissolxdmf>=0.1.2", "tqdm"
]
[project.urls]
Repository = "https://github.com/SeisSol/Visualization/seissolxdmfwriter"

[project.scripts]
seissol_output_extractor = "seissolxdmfwriter.seissol_output_extractor:main"
11 changes: 10 additions & 1 deletion seissolxdmfwriter/seissolxdmfwriter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
from .seissolxdmfwriter import *
__version__ = '0.4.1'
try:
from importlib.metadata import version, PackageNotFoundError
except ImportError:
from importlib_metadata import version, PackageNotFoundError

try:
__version__ = version("seissolxdmfwriter")
except PackageNotFoundError:
# If the package is not installed, don't add __version__
pass
25 changes: 13 additions & 12 deletions seissolxdmfwriter/seissolxdmfwriter/seissolxdmfwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def write_timeseries_xdmf(
xdmf = """<?xml version="1.0" ?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="2.0">
<Domain>"""
<Domain>
<Grid Name="TimeSeries" GridType="Collection" CollectionType="Temporal">"""
geometry_location = dataLocation(bn_prefix, "geometry", backend)
connect_location = dataLocation(bn_prefix, "connect", backend)

for i, ctime in enumerate(timeValues):
xdmf += f"""
<Grid Name="TimeSeries" GridType="Collection" CollectionType="Temporal">
<Grid Name="step_{i}" GridType="Uniform">
<Topology TopologyType="{topology}" NumberOfElements="{nCells}">
<DataItem NumberType="Int" Precision="8" Format="{data_format}" Dimensions="{nCells} {node_per_element}">{connect_location}</DataItem>
Expand All @@ -82,9 +82,9 @@ def write_timeseries_xdmf(
</DataItem>
</Attribute>"""
xdmf += """
</Grid>
</Grid>"""
</Grid>"""
xdmf += """
</Grid>
</Domain>
</Xdmf>
"""
Expand Down Expand Up @@ -225,9 +225,9 @@ def read_non_temporal(sx, ar_name, filtered_cells):
my_array = sx.ReadData(ar_name, idt)[filtered_cells]
except IndexError:
print(
f"time step {idt} of {ar_name} is corrupted, replacing with 0s"
f"time step {idt} of {ar_name} is corrupted, replacing with nans"
)
my_array = np.zeros(nel)
my_array = np.full(nel, np.nan)
if i == 0:
h5f.create_dataset(
f"/{ar_name}",
Expand All @@ -237,9 +237,9 @@ def read_non_temporal(sx, ar_name, filtered_cells):
)
if my_array.shape[0] == 0:
print(
f"time step {idt} of {ar_name} is corrupted, replacing with 0s"
f"time step {idt} of {ar_name} is corrupted, replacing with nans"
)
my_array = np.zeros(nel)
my_array = np.full(nel, np.nan)
h5f[f"/{ar_name}"][i, :] = my_array[:]
print(f"done writing {prefix}.h5")
else:
Expand All @@ -259,9 +259,9 @@ def read_non_temporal(sx, ar_name, filtered_cells):
my_array = sx.ReadData(ar_name, idt)[filtered_cells]
if my_array.shape[0] == 0:
print(
f"time step {idt} of {ar_name} is corrupted, replacing with 0s"
f"time step {idt} of {ar_name} is corrupted, replacing with nans"
)
my_array = np.zeros(nel)
my_array = np.full(nel, np.nan)
if i == 0:
mydtype = output_type(my_array, reduce_precision)
my_array[:].astype(mydtype).tofile(fid)
Expand All @@ -277,8 +277,9 @@ def write_data(
backend,
compression_level,
):
time_indices = list(dictTime.values())
if not time_indices:
if dictTime:
time_indices = list(dictTime.values())
else:
time_indices = [0]
if backend == "hdf5":
import h5py
Expand Down
38 changes: 0 additions & 38 deletions seissolxdmfwriter/setup.py

This file was deleted.