| 1 |
import pytest |
| 2 |
from polsarpro.decompositions import ( |
| 3 |
h_a_alpha, |
| 4 |
freeman, |
| 5 |
yamaguchi3, |
| 6 |
yamaguchi4, |
| 7 |
tsvm, |
| 8 |
vanzyl, |
| 9 |
cameron, |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
@pytest.mark.parametrize( |
| 14 |
"synthetic_poldata", ["S", "C2", "C3", "C4", "T3", "T4"], indirect=True |
| 15 |
) |
| 16 |
def test_h_a_alpha(synthetic_poldata): |
| 17 |
input_data = synthetic_poldata |
| 18 |
|
| 19 |
for _, ds in input_data.items(): |
| 20 |
res = h_a_alpha( |
| 21 |
input_data=ds, |
| 22 |
boxcar_size=[5, 5], |
| 23 |
flags=("alpha", "entropy", "anisotropy", "betas"), |
| 24 |
) |
| 25 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 26 |
shp = ds[var].shape |
| 27 |
assert all((res[it].shape == shp for it in ["entropy", "alpha", "anisotropy"])) |
| 28 |
assert res.betas.shape == shp + (3,) |
| 29 |
assert all( |
| 30 |
( |
| 31 |
res[it].dtype == "float32" |
| 32 |
for it in ["entropy", "alpha", "anisotropy", "betas"] |
| 33 |
) |
| 34 |
) |
| 35 |
|
| 36 |
|
| 37 |
@pytest.mark.parametrize("synthetic_poldata", ["S", "C3", "T3"], indirect=True) |
| 38 |
@pytest.mark.filterwarnings("ignore:invalid") |
| 39 |
def test_freeman(synthetic_poldata): |
| 40 |
|
| 41 |
input_data = synthetic_poldata |
| 42 |
|
| 43 |
for _, ds in input_data.items(): |
| 44 |
# uses dask specific functions and cannot be run on numpy arrays |
| 45 |
ds = ds.chunk("auto") |
| 46 |
res = freeman( |
| 47 |
input_data=ds, |
| 48 |
boxcar_size=[5, 5], |
| 49 |
) |
| 50 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 51 |
shp = ds[var].shape |
| 52 |
assert all((res[it].shape == shp for it in ["odd", "double", "volume"])) |
| 53 |
assert all((res[it].dtype == "float32" for it in ["odd", "double", "volume"])) |
| 54 |
|
| 55 |
|
| 56 |
@pytest.mark.parametrize("synthetic_poldata", ["S", "C3", "T3"], indirect=True) |
| 57 |
@pytest.mark.filterwarnings("ignore:invalid") |
| 58 |
def test_yamaguchi3(synthetic_poldata): |
| 59 |
|
| 60 |
input_data = synthetic_poldata |
| 61 |
|
| 62 |
for _, ds in input_data.items(): |
| 63 |
# uses dask specific functions and cannot be run on numpy arrays |
| 64 |
ds = ds.chunk("auto") |
| 65 |
res = yamaguchi3( |
| 66 |
input_data=ds, |
| 67 |
boxcar_size=[5, 5], |
| 68 |
) |
| 69 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 70 |
shp = ds[var].shape |
| 71 |
assert all((res[it].shape == shp for it in ["odd", "double", "volume"])) |
| 72 |
assert all((res[it].dtype == "float32" for it in ["odd", "double", "volume"])) |
| 73 |
|
| 74 |
|
| 75 |
@pytest.mark.parametrize("synthetic_poldata", ["S", "C3", "T3"], indirect=True) |
| 76 |
@pytest.mark.filterwarnings("ignore:invalid") |
| 77 |
def test_yamaguchi4(synthetic_poldata): |
| 78 |
|
| 79 |
input_data = synthetic_poldata |
| 80 |
|
| 81 |
for _, ds in input_data.items(): |
| 82 |
for mode in ["y4o", "y4r", "s4r"]: |
| 83 |
# uses dask specific functions and cannot be run on numpy arrays |
| 84 |
ds = ds.chunk("auto") |
| 85 |
res = yamaguchi4(input_data=ds, boxcar_size=[5, 5], mode=mode) |
| 86 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 87 |
shp = ds[var].shape |
| 88 |
assert all( |
| 89 |
(res[it].shape == shp for it in ["odd", "double", "volume", "helix"]) |
| 90 |
) |
| 91 |
assert all( |
| 92 |
( |
| 93 |
res[it].dtype == "float32" |
| 94 |
for it in ["odd", "double", "volume", "helix"] |
| 95 |
) |
| 96 |
) |
| 97 |
|
| 98 |
|
| 99 |
@pytest.mark.parametrize("synthetic_poldata", ["S", "C3", "T3"], indirect=True) |
| 100 |
def test_tsvm(synthetic_poldata): |
| 101 |
input_data = synthetic_poldata |
| 102 |
|
| 103 |
# input flags and corresponding output names |
| 104 |
in_out = { |
| 105 |
"alpha_phi_tau_psi": ("alpha_s", "phi_s", "tau_m", "psi"), |
| 106 |
"alpha": ("alpha_s1", "alpha_s2", "alpha_s3"), |
| 107 |
"phi": ("phi_s1", "phi_s2", "phi_s3"), |
| 108 |
"tau": ("tau_m1", "tau_m2", "tau_m3"), |
| 109 |
"psi": ("psi1", "psi2", "psi3"), |
| 110 |
} |
| 111 |
|
| 112 |
for _, ds in input_data.items(): |
| 113 |
res = tsvm( |
| 114 |
input_data=ds, |
| 115 |
boxcar_size=[5, 5], |
| 116 |
flags=tuple(in_out.keys()), |
| 117 |
) |
| 118 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 119 |
shp = ds[var].shape |
| 120 |
for flag in in_out: |
| 121 |
for name in in_out[flag]: |
| 122 |
assert res[name].dtype == "float32" |
| 123 |
assert res[name].shape == shp |
| 124 |
|
| 125 |
|
| 126 |
@pytest.mark.parametrize("synthetic_poldata", ["S", "C3", "T3"], indirect=True) |
| 127 |
@pytest.mark.filterwarnings("ignore:invalid") |
| 128 |
def test_vanzyl(synthetic_poldata): |
| 129 |
|
| 130 |
input_data = synthetic_poldata |
| 131 |
|
| 132 |
for _, ds in input_data.items(): |
| 133 |
# uses dask specific functions and cannot be run on numpy arrays |
| 134 |
ds = ds.chunk("auto") |
| 135 |
res = vanzyl( |
| 136 |
input_data=ds, |
| 137 |
boxcar_size=[5, 5], |
| 138 |
) |
| 139 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 140 |
shp = ds[var].shape |
| 141 |
assert all((res[it].shape == shp for it in ["odd", "double", "volume"])) |
| 142 |
assert all((res[it].dtype == "float32" for it in ["odd", "double", "volume"])) |
| 143 |
|
| 144 |
|
| 145 |
@pytest.mark.parametrize("synthetic_poldata", ["S"], indirect=True) |
| 146 |
def test_cameron(synthetic_poldata): |
| 147 |
input_data = synthetic_poldata |
| 148 |
|
| 149 |
for _, ds in input_data.items(): |
| 150 |
input_data = ds.chunk(x=64, y=64) |
| 151 |
res = cameron(input_data=input_data) |
| 152 |
var = "hh" if "hh" in ds.data_vars else "m11" |
| 153 |
shp = ds[var].shape |
| 154 |
assert res["cameron"].shape == shp |
| 155 |
assert res["cameron"].dtype == "int32" |