diff --git a/.gitignore b/.gitignore index 2b7cdc2..4a1d483 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +test/ +temp/ \ No newline at end of file diff --git a/dist/nt2py-0.3.0.tar.gz b/dist/nt2py-0.3.0.tar.gz new file mode 100644 index 0000000..9f9bb67 Binary files /dev/null and b/dist/nt2py-0.3.0.tar.gz differ diff --git a/nt2/__init__.py b/nt2/__init__.py index 8933427..f2b3589 100644 --- a/nt2/__init__.py +++ b/nt2/__init__.py @@ -1 +1 @@ -__version__ = ["0.2.1"] +__version__ = "0.3.0" \ No newline at end of file diff --git a/nt2/read.py b/nt2/read.py index edeec06..44faede 100644 --- a/nt2/read.py +++ b/nt2/read.py @@ -589,8 +589,8 @@ def EdgeToCenter(arr): "Ttz": "Pz", } CoordinateDict = { - "cartesian": {"x": "x", "y": "y", "z": "z", "1": "x", "2": "y", "3": "z"}, - "spherical": { + "cart": {"x": "x", "y": "y", "z": "z", "1": "x", "2": "y", "3": "z"}, + "sph": { "r": "r", "theta": "θ" if useGreek else "th", "phi": "φ" if useGreek else "ph", @@ -600,7 +600,7 @@ def EdgeToCenter(arr): }, } PrtlDict = { - "cartesian": { + "cart": { "X1": "x", "X2": "y", "X3": "z", @@ -608,7 +608,7 @@ def EdgeToCenter(arr): "U2": "uy", "U3": "uz", }, - "spherical": { + "sph": { "X1": "r", "X2": "θ" if useGreek else "th", "X3": "φ" if useGreek else "ph", @@ -623,40 +623,39 @@ def EdgeToCenter(arr): except OSError: raise OSError(f"Could not open file {self.fname}") step0 = list(self.file.keys())[0] - nsteps = int(self.file.attrs["NumSteps"]) + nsteps = len(self.file.keys()) ngh = int(self.file.attrs["NGhosts"]) layout = "right" if self.file.attrs["LayoutRight"] == 1 else "left" dimension = int(self.file.attrs["Dimension"]) coordinates = self.file.attrs["Coordinates"].decode("UTF-8") - if coordinates == "qspherical": - coordinates = "spherical" - if coordinates == "spherical": + if coordinates == "qsph": + coordinates = "sph" + if coordinates == "sph": self.metric = SphericalMetric() else: self.metric = MinkowskiMetric() coords = list(CoordinateDict[coordinates].values())[::-1][-dimension:] # cell-centered coords - cc_coords = { - c: EdgeToCenter(self.file.attrs[f"X{i+1}"]) - for i, c in enumerate(coords[::-1]) - } - # upper and lower limits of the cell + cc_coords = {c: self.file[step0][f"X{i+1}"] for i, c in enumerate(coords[::-1])} + # cell edges cell_1 = { f"{c}_1": ( c, - self.file.attrs[f"X{i+1}"][:-1], + self.file[step0][f"X{i+1}e"][:-1], ) for i, c in enumerate(coords[::-1]) } cell_2 = { f"{c}_2": ( c, - self.file.attrs[f"X{i+1}"][1:], + self.file[step0][f"X{i+1}e"][1:], ) for i, c in enumerate(coords[::-1]) } - times = np.array([self.file[f"Step{s}"]["Time"][()] for s in range(nsteps)]) + times = np.array( + [self.file[f"Step{s}"]["Time"][()] for s in range(nsteps)], dtype=float + ) if dimension == 1: noghosts = slice(ngh, -ngh) if ngh > 0 else slice(None) @@ -700,9 +699,11 @@ def EdgeToCenter(arr): dask_arrays.append(array[noghosts]) k_ = reduce( - lambda x, y: x.replace(*y) - if "_" not in x - else "_".join([x.split("_")[0].replace(*y)] + x.split("_")[1:]), + lambda x, y: ( + x.replace(*y) + if "_" not in x + else "_".join([x.split("_")[0].replace(*y)] + x.split("_")[1:]) + ), [k, *list(CoordinateDict[coordinates].items())], ) k_ = reduce( @@ -722,68 +723,68 @@ def EdgeToCenter(arr): ) self.dataset[k_] = x - prtls = [ - k - for k in self.file[step0].keys() - if (k.startswith("X") or k.startswith("U") or k.startswith("W")) - ] + # prtls = [ + # k + # for k in self.file[step0].keys() + # if (k.startswith("X") or k.startswith("U") or k.startswith("W")) + # ] - species = np.unique( - [int(pq.split("_")[1]) for pq in self.file[step0].keys() if pq in prtls] - ) + # species = np.unique( + # [int(pq.split("_")[1]) for pq in self.file[step0].keys() if pq in prtls] + # ) - def list_to_ragged(arr): - max_len = np.max([len(a) for a in arr]) - return map( - lambda a: np.concatenate([a, np.full(max_len - len(a), np.nan)]), arr - ) + # def list_to_ragged(arr): + # max_len = np.max([len(a) for a in arr]) + # return map( + # lambda a: np.concatenate([a, np.full(max_len - len(a), np.nan)]), arr + # ) self._particles = {} - for s in species: - prtl_data = {} - for q in [ - f"X1_{s}", - f"X2_{s}", - f"X3_{s}", - f"U1_{s}", - f"U2_{s}", - f"U3_{s}", - f"W_{s}", - ]: - if q[0] in ["X", "U"]: - q_ = PrtlDict[coordinates][q.split("_")[0]] - else: - q_ = q.split("_")[0] - if q not in prtls: - continue - if q not in prtl_data.keys(): - prtl_data[q_] = [] - for k in range(nsteps): - step_k = f"Step{k}" - if q in self.file[step_k].keys(): - prtl_data[q_].append(self.file[step_k][q]) - else: - prtl_data[q_].append(np.full_like(prtl_data[q_][-1], np.nan)) - prtl_data[q_] = list_to_ragged(prtl_data[q_]) - prtl_data[q_] = da.from_array(list(prtl_data[q_])) - prtl_data[q_] = xr.DataArray( - prtl_data[q_], dims=["t", "id"], name=q_, coords={"t": times} - ) - if coordinates == "spherical": - prtl_data["x"] = ( - prtl_data[PrtlDict[coordinates]["X1"]] - * np.sin(prtl_data[PrtlDict[coordinates]["X2"]]) - * np.cos(prtl_data[PrtlDict[coordinates]["X3"]]) - ) - prtl_data["y"] = ( - prtl_data[PrtlDict[coordinates]["X1"]] - * np.sin(prtl_data[PrtlDict[coordinates]["X2"]]) - * np.sin(prtl_data[PrtlDict[coordinates]["X3"]]) - ) - prtl_data["z"] = prtl_data[PrtlDict[coordinates]["X1"]] * np.cos( - prtl_data[PrtlDict[coordinates]["X2"]] - ) - self._particles[s] = xr.Dataset(prtl_data) + # for s in species: + # prtl_data = {} + # for q in [ + # f"X1_{s}", + # f"X2_{s}", + # f"X3_{s}", + # f"U1_{s}", + # f"U2_{s}", + # f"U3_{s}", + # f"W_{s}", + # ]: + # if q[0] in ["X", "U"]: + # q_ = PrtlDict[coordinates][q.split("_")[0]] + # else: + # q_ = q.split("_")[0] + # if q not in prtls: + # continue + # if q not in prtl_data.keys(): + # prtl_data[q_] = [] + # for k in range(nsteps): + # step_k = f"Step{k}" + # if q in self.file[step_k].keys(): + # prtl_data[q_].append(self.file[step_k][q]) + # else: + # prtl_data[q_].append(np.full_like(prtl_data[q_][-1], np.nan)) + # prtl_data[q_] = list_to_ragged(prtl_data[q_]) + # prtl_data[q_] = da.from_array(list(prtl_data[q_])) + # prtl_data[q_] = xr.DataArray( + # prtl_data[q_], dims=["t", "id"], name=q_, coords={"t": times} + # ) + # if coordinates == "spherical": + # prtl_data["x"] = ( + # prtl_data[PrtlDict[coordinates]["X1"]] + # * np.sin(prtl_data[PrtlDict[coordinates]["X2"]]) + # * np.cos(prtl_data[PrtlDict[coordinates]["X3"]]) + # ) + # prtl_data["y"] = ( + # prtl_data[PrtlDict[coordinates]["X1"]] + # * np.sin(prtl_data[PrtlDict[coordinates]["X2"]]) + # * np.sin(prtl_data[PrtlDict[coordinates]["X3"]]) + # ) + # prtl_data["z"] = prtl_data[PrtlDict[coordinates]["X1"]] * np.cos( + # prtl_data[PrtlDict[coordinates]["X2"]] + # ) + # self._particles[s] = xr.Dataset(prtl_data) def __del__(self): self.file.close() @@ -878,7 +879,7 @@ def makeMovie(self, plot, makeframes=True, **kwargs): exp.makeFrames( plot, np.arange(len(self.t)), - f"{self.attrs['Title']}/frames", + f"{self.attrs['simulation.name']}/frames", data=self, num_cpus=kwargs.pop("num_cpus", None), ) @@ -887,9 +888,9 @@ def makeMovie(self, plot, makeframes=True, **kwargs): makemovie = True if makemovie: exp.makeMovie( - input=f"{self.attrs['Title']}/frames/", + input=f"{self.attrs['simulation.name']}/frames/", overwrite=True, - output=f"{self.attrs['Title']}.mp4", + output=f"{self.attrs['simulation.name']}.mp4", number=5, **kwargs, ) diff --git a/pyproject.toml b/pyproject.toml index 6bf3ecf..1f6ee41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,45 @@ [build-system] -requires = ["setuptools", "wheel", "setuptools_scm", "pypandoc"] -build-backend = 'setuptools.build_meta' \ No newline at end of file +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "nt2py" +dynamic = ["version"] +dependencies = [ +"types-setuptools", +"dask", +"xarray", +"numpy", +"scipy", +"h5py", +"h5pickle", +"matplotlib", +"tqdm", +"contourpy", +] +requires-python = ">=3.8" +authors = [{ name = "Hayk", email = "haykh.astro@gmail.com" }] +maintainers = [{ name = "Hayk", email = "haykh.astro@gmail.com" }] +description = "Post-processing & visualization toolkit for the Entity PIC code" +readme = "README.md" +license = { file = "LICENSE" } +classifiers = [ +"Development Status :: 5 - Production/Stable", +"Intended Audience :: Science/Research", +"Intended Audience :: Education", +"Topic :: Scientific/Engineering :: Physics", +"Topic :: Scientific/Engineering :: Astronomy", +"License :: OSI Approved :: BSD License", +"Programming Language :: Python :: 3 :: Only", +"Programming Language :: Python :: 3.8", +"Programming Language :: Python :: 3.9", +"Programming Language :: Python :: 3.10", +"Programming Language :: Python :: 3.11", +"Programming Language :: Python :: 3.12", +] + +[project.urls] +Repository = "https://github.com/entity-toolkit/nt2py" + +[tool.hatch.version] +path = "nt2/__init__.py" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 52a3a52..0000000 --- a/setup.cfg +++ /dev/null @@ -1,23 +0,0 @@ -[metadata] -name = nt2py -version = attr: nt2.__version__ -description = Post-processing & visualization toolkit for the Entity PIC code -author = haykh -author_email = haykh.astro@gmail.com -license = BSD 3-Clause License -url = https://github.com/entity-toolkit/nt2 - -[options] -zip_safe = False -python_requires = >=3.6 -packages = find: -install_requires = - types-setuptools - numpy - matplotlib - h5pickle - h5py - pandas - xarray - dask - tqdm diff --git a/setup.py b/setup.py deleted file mode 100644 index ea29581..0000000 --- a/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from setuptools import setup -from pathlib import Path - -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - -setup( - long_description=long_description, - long_description_content_type="text/markdown", -)