Skip to content

Commit

Permalink
Merge pull request #240 from neutrinoceros/nfields
Browse files Browse the repository at this point in the history
ENH: add a convenience `nfields` property to `GasDataSet`
  • Loading branch information
neutrinoceros authored Feb 19, 2024
2 parents 8692f09 + 1ca82e3 commit c2ad0ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions nonos/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,3 +1652,12 @@ def items(self) -> ItemsView[str, "GasField"]:
items of the dict
"""
return self.dict.items()

@property
def nfields(self) -> int:
"""
Returns
=======
The number of fields in the GasDataSet
"""
return len(self.dict)
8 changes: 4 additions & 4 deletions tests/test_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ def test_roundtrip_simple(test_data_dir, tmp_path):

os.chdir(tmp_path / "mydir")
ds = GasDataSet(500)
assert len(list(ds.keys())) == 7
assert ds.nfields == 7

gf = ds["RHO"].azimuthal_average()

gf.save()
dsnpy = GasDataSet.from_npy(500, operation="azimuthal_average")
assert len(list(dsnpy.keys())) == 1
assert dsnpy.nfields == 1


def test_roundtrip_other_dir(test_data_dir, tmp_path):
os.chdir(test_data_dir / "idefix_spherical_planet3d")
gf = GasDataSet(500)["RHO"].azimuthal_average()
gf.save(tmp_path)
dsnpy = GasDataSet.from_npy(500, operation="azimuthal_average", directory=tmp_path)
assert len(list(dsnpy.keys())) == 1
assert dsnpy.nfields == 1


def test_api_vtk_by_name(test_data_dir):
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_api_fluid_fargo3d(test_data_dir):
on = 5

ds = GasDataSet(on, fluid="dust2")
assert len(list(ds.keys())) == 1
assert ds.nfields == 1

with pytest.raises(
FileNotFoundError,
Expand Down

0 comments on commit c2ad0ea

Please sign in to comment.