Skip to content

Commit 5ed52d0

Browse files
authored
Merge pull request #212 from siapy/fix
2 parents b996324 + 8ad021d commit 5ed52d0

8 files changed

Lines changed: 20 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ data_dir = "~/data"
7070
header_paths = sorted(Path(data_dir).rglob("*.hdr"))
7171
image_paths = sorted(Path(data_dir).rglob("*.img"))
7272

73-
imageset = SpectralImageSet.from_paths(
73+
imageset = SpectralImageSet.spy_open(
7474
header_paths=header_paths,
7575
image_paths=image_paths,
7676
)

siapy/entities/images/spimage.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ def to_signatures(self, pixels: "Pixels") -> Signatures:
124124

125125
def to_subarray(self, pixels: "Pixels") -> NDArray[np.floating[Any]]:
126126
image_arr = self.to_numpy()
127-
u_max = pixels.u().max()
128-
u_min = pixels.u().min()
129-
v_max = pixels.v().max()
130-
v_min = pixels.v().min()
127+
u_max = pixels.x().max()
128+
u_min = pixels.x().min()
129+
v_max = pixels.y().max()
130+
v_min = pixels.y().min()
131131
# create new image
132132
image_arr_area = np.nan * np.ones((int(v_max - v_min + 1), int(u_max - u_min + 1), self.bands))
133133
# convert original coordinates to coordinates for new image
134-
v_norm = pixels.v() - v_min
135-
u_norm = pixels.u() - u_min
134+
v_norm = pixels.y() - v_min
135+
u_norm = pixels.x() - u_min
136136
# write values from original image to new image
137-
image_arr_area[v_norm, u_norm, :] = image_arr[pixels.v(), pixels.u(), :]
137+
image_arr_area[v_norm, u_norm, :] = image_arr[pixels.y(), pixels.x(), :]
138138
return image_arr_area
139139

140140
def mean(self, axis: int | tuple[int, ...] | Sequence[int] | None = None) -> float | NDArray[np.floating[Any]]:

siapy/entities/pixels.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ def df_homogenious(self) -> pd.DataFrame:
7777
df_homo[self.coords.H] = 1
7878
return df_homo
7979

80-
def u(self) -> "pd.Series[float]":
81-
# TODO: change to u -> x
80+
def x(self) -> "pd.Series[float]":
8281
return self.df[self.coords.X]
8382

84-
def v(self) -> "pd.Series[float]":
83+
def y(self) -> "pd.Series[float]":
8584
return self.df[self.coords.Y]
8685

8786
def to_numpy(self) -> NDArray[np.floating[Any]]:

siapy/entities/signatures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def from_dict(cls, data: dict[str, Any]) -> "Signatures":
8787
@classmethod
8888
def from_array_and_pixels(cls, image: NDArray[np.floating[Any]], pixels: Pixels) -> "Signatures":
8989
pixels = pixels.as_type(int)
90-
u = pixels.u()
91-
v = pixels.v()
90+
u = pixels.x()
91+
v = pixels.y()
9292

9393
if image.ndim != 3:
9494
raise InvalidInputError(f"Expected a 3-dimensional array, but got {image.ndim}-dimensional array.")

siapy/utils/plots.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def display_image_with_areas(
142142

143143
for pixels in areas:
144144
ax.scatter(
145-
pixels.u(),
146-
pixels.v(),
145+
pixels.x(),
146+
pixels.y(),
147147
lw=0,
148148
marker="o",
149149
c=color,
@@ -180,8 +180,8 @@ def display_multiple_images_with_areas(
180180

181181
for pixels in selected_areas:
182182
ax.scatter(
183-
pixels.u(),
184-
pixels.v(),
183+
pixels.x(),
184+
pixels.y(),
185185
lw=0,
186186
marker="o",
187187
c=color,

tests/entities/test_entities_pixels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ def test_u():
8686
df = pd.DataFrame(iterable, columns=[Pixels.coords.X, Pixels.coords.Y])
8787
pixels = Pixels(df)
8888
expected_x = pd.Series([1, 3, 5], name=Pixels.coords.X)
89-
assert pixels.u().equals(expected_x)
89+
assert pixels.x().equals(expected_x)
9090

9191

9292
def test_v():
9393
df = pd.DataFrame(iterable, columns=[Pixels.coords.X, Pixels.coords.Y])
9494
pixels = Pixels(df)
9595
expected_y = pd.Series([2, 4, 6], name=Pixels.coords.Y)
96-
assert pixels.v().equals(expected_y)
96+
assert pixels.y().equals(expected_y)
9797

9898

9999
def test_to_numpy():

tests/entities/test_entities_signatures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_signatures_from_array_and_pixels():
186186
from_array_and_pixels = Signatures.from_array_and_pixels(image, pixels)
187187

188188
assert from_array_and_pixels.pixels == pixels
189-
assert from_array_and_pixels.signals.df.equals(pd.DataFrame(list(image[pixels.v(), pixels.u(), :])))
189+
assert from_array_and_pixels.signals.df.equals(pd.DataFrame(list(image[pixels.y(), pixels.x(), :])))
190190

191191

192192
def test_signatures_from_array_and_pixels_invalid_dimensions():

tests/utils/test_utils_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_calculate_correction_factor_from_panel_with_label(spectral_images):
159159

160160
a = image_vnir.to_numpy()
161161
pixels = get_signatures_within_convex_hull(image_vnir, rect)[0].pixels
162-
c = a[pixels.v(), pixels.u(), :]
162+
c = a[pixels.y(), pixels.x(), :]
163163
assert np.array_equal(
164164
np.full(image_vnir.bands, 0.2),
165165
np.round(c.mean(axis=0) * panel_correction, 2),

0 commit comments

Comments
 (0)