Skip to content

Commit

Permalink
Merge pull request #151 from mcflugen/mcflugen/absolute-import-section
Browse files Browse the repository at this point in the history
Absolute import of the deltametrics.section module
  • Loading branch information
mcflugen authored Dec 4, 2024
2 parents f8cc545 + 0db68db commit 7c416b3
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 169 deletions.
4 changes: 2 additions & 2 deletions deltametrics/strat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import xarray as xr

from . import section
from deltametrics.section import CircularSection


def compute_compensation(line1, line2):
Expand Down Expand Up @@ -397,7 +397,7 @@ def compute_sedimentograph(

# loop through the sections and compute the sediment vols
for i, sect_rad in enumerate(section_radii):
sect = section.CircularSection(
sect = CircularSection(
sediment_volume[0, :, :], # must be a 2d slice to make section
radius=sect_rad, **kwargs)
# manually slice, because not set up for sections into arbitrary 3d volume
Expand Down
19 changes: 10 additions & 9 deletions tests/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from deltametrics import cube

from deltametrics import plot
from deltametrics import section
from deltametrics.section import BaseSection
from deltametrics.section import StrikeSection
from deltametrics import plan
from deltametrics.utils import NoStratigraphyError
from deltametrics.sample_data import _get_golf_path, _get_rcm8_path, _get_landsat_path
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_slice_op_invalid_name(self):
def test_register_section(self):
golf = cube.DataCube(golf_path)
golf.stratigraphy_from("eta", dz=0.1)
golf.register_section("testsection", section.StrikeSection(distance_idx=10))
golf.register_section("testsection", StrikeSection(distance_idx=10))
assert golf.sections is golf.section_set
assert len(golf.sections.keys()) == 1
assert "testsection" in golf.sections.keys()
Expand All @@ -105,15 +106,15 @@ def test_register_section(self):
with pytest.raises(TypeError, match=r"`SectionInstance` .*"):
golf.register_section("fail2", 22)
with pytest.raises(TypeError, match=r"`name` .*"):
golf.register_section(22, section.StrikeSection(distance_idx=10))
golf.register_section(22, StrikeSection(distance_idx=10))

def test_sections_slice_op(self):
golf = cube.DataCube(golf_path)
golf.stratigraphy_from("eta", dz=0.1)
golf.register_section("testsection", section.StrikeSection(distance_idx=10))
golf.register_section("testsection", StrikeSection(distance_idx=10))
assert "testsection" in golf.sections.keys()
slc = golf.sections["testsection"]
assert issubclass(type(slc), section.BaseSection)
assert issubclass(type(slc), BaseSection)

def test_register_planform(self):
golf = cube.DataCube(golf_path)
Expand Down Expand Up @@ -155,7 +156,7 @@ def test_nostratigraphy_default(self):

def test_nostratigraphy_default_attribute_derived_variable(self):
golf = cube.DataCube(golf_path)
golf.register_section("testsection", section.StrikeSection(distance_idx=10))
golf.register_section("testsection", StrikeSection(distance_idx=10))
assert golf._knows_stratigraphy is False
with pytest.raises(NoStratigraphyError):
golf.sections["testsection"]["velocity"].strat.as_stratigraphy()
Expand Down Expand Up @@ -221,7 +222,7 @@ def test_fixeddatacube_shape(self):
assert self.fixeddatacube.shape == self.fdc_shape

def test_section_no_stratigraphy(self):
sc = section.StrikeSection(self.fixeddatacube, distance_idx=10)
sc = StrikeSection(self.fixeddatacube, distance_idx=10)
_ = sc["velocity"][:, 1]
assert not hasattr(sc, "strat_attr")
with pytest.raises(NoStratigraphyError):
Expand All @@ -231,7 +232,7 @@ def test_section_no_stratigraphy(self):

def test_show_section_mocked_BaseSection_show(self):
golf = cube.DataCube(golf_path)
golf.register_section("displaysection", section.StrikeSection(distance_idx=10))
golf.register_section("displaysection", StrikeSection(distance_idx=10))
golf.sections["displaysection"].show = mock.MagicMock()
mocked = golf.sections["displaysection"].show
# no arguments is an error
Expand Down Expand Up @@ -343,7 +344,7 @@ def test_export_frozen_variable(self):

def test_section_with_stratigraphy(self):
assert hasattr(self.fixeddatacube, "strat_attr")
sc = section.StrikeSection(self.fixeddatacube, distance_idx=10)
sc = StrikeSection(self.fixeddatacube, distance_idx=10)
assert sc.strat_attr is self.fixeddatacube.strat_attr
_take = sc["velocity"][:, 1]
assert _take.shape == (self.fixeddatacube.shape[0],)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from deltametrics import mask
from deltametrics import cube
from deltametrics import plan
from deltametrics import section
from deltametrics.section import CircularSection

# a simple custom layout
simple_land = np.zeros((10, 10))
Expand Down Expand Up @@ -572,7 +572,7 @@ class TestComputeChannelWidth:
elevation_threshold=0,
flow_threshold=0.3,
)
sec = section.CircularSection(golf, radius_idx=40)
sec = CircularSection(golf, radius_idx=40)

def test_widths_simple(self):
"""Get mean and std from simple."""
Expand Down Expand Up @@ -642,7 +642,7 @@ class TestComputeChannelDepth:
elevation_threshold=0,
flow_threshold=0.3,
)
sec = section.CircularSection(golf, radius_idx=40)
sec = CircularSection(golf, radius_idx=40)

def test_depths_simple_thalweg(self):
"""Get mean and std from simple."""
Expand Down
20 changes: 10 additions & 10 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from deltametrics import plot
from deltametrics import cube
from deltametrics import section
from deltametrics.section import StrikeSection
from deltametrics.utils import NoStratigraphyError
from deltametrics.sample_data import _get_golf_path

Expand Down Expand Up @@ -392,18 +392,18 @@ class TestGetDisplayArrays:

rcm8cube_nostrat = cube.DataCube(golf_path)
rcm8cube_nostrat.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
dsv_nostrat = rcm8cube_nostrat.sections['test']['velocity']

rcm8cube = cube.DataCube(golf_path)
rcm8cube.stratigraphy_from('eta', dz=0.1)
rcm8cube.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
dsv = rcm8cube.sections['test']['velocity']

sc8cube = cube.StratigraphyCube.from_DataCube(rcm8cube, dz=0.1)
sc8cube.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
ssv = sc8cube.sections['test']['velocity']

def test_dsv_nostrat_get_display_arrays_spacetime(self):
Expand Down Expand Up @@ -486,18 +486,18 @@ class TestGetDisplayLines:

rcm8cube_nostrat = cube.DataCube(golf_path)
rcm8cube_nostrat.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
dsv_nostrat = rcm8cube_nostrat.sections['test']['velocity']

rcm8cube = cube.DataCube(golf_path)
rcm8cube.stratigraphy_from('eta', dz=0.1)
rcm8cube.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
dsv = rcm8cube.sections['test']['velocity']

sc8cube = cube.StratigraphyCube.from_DataCube(rcm8cube, dz=0.1)
sc8cube.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
ssv = sc8cube.sections['test']['velocity']

def test_dsv_nostrat_get_display_lines_spacetime(self):
Expand Down Expand Up @@ -563,18 +563,18 @@ class TestGetDisplayLimits:

rcm8cube_nostrat = cube.DataCube(golf_path)
rcm8cube_nostrat.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
dsv_nostrat = rcm8cube_nostrat.sections['test']['velocity']

rcm8cube = cube.DataCube(golf_path)
rcm8cube.stratigraphy_from('eta', dz=0.1)
rcm8cube.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
dsv = rcm8cube.sections['test']['velocity']

sc8cube = cube.StratigraphyCube.from_DataCube(rcm8cube, dz=0.1)
sc8cube.register_section(
'test', section.StrikeSection(distance_idx=5))
'test', StrikeSection(distance_idx=5))
ssv = sc8cube.sections['test']['velocity']

def test_dsv_nostrat_get_display_limits_spacetime(self):
Expand Down
Loading

0 comments on commit 7c416b3

Please sign in to comment.