diff --git a/seissolxdmf/seissolxdmf/__init__.py b/seissolxdmf/seissolxdmf/__init__.py index e753673..96698cb 100644 --- a/seissolxdmf/seissolxdmf/__init__.py +++ b/seissolxdmf/seissolxdmf/__init__.py @@ -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 diff --git a/seissolxdmf/seissolxdmf/seissolxdmf.py b/seissolxdmf/seissolxdmf/seissolxdmf.py index 76dba38..f180f83 100644 --- a/seissolxdmf/seissolxdmf/seissolxdmf.py +++ b/seissolxdmf/seissolxdmf/seissolxdmf.py @@ -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 """ @@ -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] diff --git a/seissolxdmf/setup.py b/seissolxdmf/setup.py deleted file mode 100644 index 6beff31..0000000 --- a/seissolxdmf/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -import setuptools -import re - - -def get_property(prop, project): - # https://stackoverflow.com/questions/17791481/creating-a-version-attribute-for-python-packages-without-getting-into-troubl/41110107 - result = re.search( - r'{}\s*=\s*[\'"]([^\'"]*)[\'"]'.format(prop), open(project + "/__init__.py").read() - ) - return result.group(1) - - -with open("README.md", "r") as fh: - long_description = fh.read() - -project_name = "seissolxdmf" -setuptools.setup( - name=project_name, - version=get_property("__version__", project_name), - author="SeisSol Group", - description="A python reader for SeisSol xdmf output", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/SeisSol/Visualization/seissolxdmf", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - ], - python_requires=">=3.6", - install_requires=["numpy", "h5py"], -) diff --git a/seissolxdmfwriter/pyproject.toml b/seissolxdmfwriter/pyproject.toml new file mode 100644 index 0000000..619c95a --- /dev/null +++ b/seissolxdmfwriter/pyproject.toml @@ -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" diff --git a/seissolxdmfwriter/seissolxdmfwriter/__init__.py b/seissolxdmfwriter/seissolxdmfwriter/__init__.py index 2fc6317..f14c9ab 100644 --- a/seissolxdmfwriter/seissolxdmfwriter/__init__.py +++ b/seissolxdmfwriter/seissolxdmfwriter/__init__.py @@ -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 diff --git a/seissolxdmfwriter/seissolxdmfwriter/seissolxdmfwriter.py b/seissolxdmfwriter/seissolxdmfwriter/seissolxdmfwriter.py index 8dc3320..745ea67 100644 --- a/seissolxdmfwriter/seissolxdmfwriter/seissolxdmfwriter.py +++ b/seissolxdmfwriter/seissolxdmfwriter/seissolxdmfwriter.py @@ -50,13 +50,13 @@ def write_timeseries_xdmf( xdmf = """ - """ + + """ geometry_location = dataLocation(bn_prefix, "geometry", backend) connect_location = dataLocation(bn_prefix, "connect", backend) for i, ctime in enumerate(timeValues): xdmf += f""" - {connect_location} @@ -82,9 +82,9 @@ def write_timeseries_xdmf( """ xdmf += """ - - """ + """ xdmf += """ + """ @@ -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}", @@ -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: @@ -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) @@ -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 diff --git a/seissolxdmfwriter/setup.py b/seissolxdmfwriter/setup.py deleted file mode 100644 index 28bfe89..0000000 --- a/seissolxdmfwriter/setup.py +++ /dev/null @@ -1,38 +0,0 @@ -import setuptools -import re - - -def get_property(prop, project): - # https://stackoverflow.com/questions/17791481/creating-a-version-attribute-for-python-packages-without-getting-into-troubl/41110107 - result = re.search( - r'{}\s*=\s*[\'"]([^\'"]*)[\'"]'.format(prop), open(project + "/__init__.py").read() - ) - return result.group(1) - - -with open("README.md", "r") as fh: - long_description = fh.read() - -project_name = "seissolxdmfwriter" -setuptools.setup( - name=project_name, - version=get_property("__version__", project_name), - author="SeisSol Group", - description="A python writer for SeisSol xdmf output", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/SeisSol/Visualization/seissolxdmfwriter", - packages=setuptools.find_packages(), - entry_points={ - 'console_scripts': [ - 'seissol_output_extractor = seissolxdmfwriter.seissol_output_extractor:main', - ], - }, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - ], - python_requires=">=3.6", - install_requires=["numpy", "h5py","seissolxdmf>=0.1.2", "tqdm"], -)