Skip to content

Commit d0efc81

Browse files
committed
models: add hash method in frame and expressions
1 parent 4c76c8e commit d0efc81

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

pysits/conversions/dsl/mask.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ def __mod__(self, other: Any) -> None:
7070
"""
7171
raise NotImplementedError("Use %in_ for 'in' operation")
7272

73+
#
74+
# Hashing
75+
#
76+
def __hash__(self) -> int:
77+
"""Hash the expression."""
78+
return hash(self.r_repr())
79+
7380
#
7481
# Abstract methods
7582
#

pysits/models/frame.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ def __eq__(self, other):
162162

163163
return NotImplemented
164164

165+
#
166+
# Hashing
167+
#
168+
def __hash__(self) -> int:
169+
"""Hash the array."""
170+
return hash(self._data)
171+
165172
#
166173
# Operations
167174
#

pysits/sits/cube.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def convert_reclassify_rules(obj: object) -> MaskExpressionList:
5252

5353

5454
#
55-
# High-level operations
55+
# Cube
5656
#
5757
@function_call(r_pkg_sits.sits_cube, SITSCubeModel)
5858
@attach_doc("sits_cube")
@@ -66,18 +66,21 @@ def sits_regularize(*args, **kwargs) -> SITSCubeModel:
6666
"""Build a regular data cube from an irregular one."""
6767

6868

69-
@function_call(r_pkg_sits.sits_variance, SITSCubeModel)
70-
@attach_doc("sits_variance")
71-
def sits_variance(*args, **kwargs) -> SITSCubeModel:
72-
"""Calculate the variance of a probability cube."""
73-
74-
7569
@function_call(r_pkg_sits.sits_cube_copy, SITSCubeModel)
7670
@attach_doc("sits_cube_copy")
7771
def sits_cube_copy(*args, **kwargs) -> SITSCubeModel:
7872
"""Copy cubes."""
7973

8074

75+
#
76+
# Probability and metrics
77+
#
78+
@function_call(r_pkg_sits.sits_variance, SITSCubeModel)
79+
@attach_doc("sits_variance")
80+
def sits_variance(*args, **kwargs) -> SITSCubeModel:
81+
"""Calculate the variance of a probability cube."""
82+
83+
8184
@function_call(r_pkg_sits.sits_uncertainty, SITSCubeModel)
8285
@attach_doc("sits_uncertainty")
8386
def sits_uncertainty(*args, **kwargs) -> SITSCubeModel:
@@ -90,12 +93,18 @@ def sits_clean(*args, **kwargs) -> SITSCubeModel:
9093
"""Cleans a classified map using a local window."""
9194

9295

96+
#
97+
# Combine predictions
98+
#
9399
@function_call(r_pkg_sits.sits_combine_predictions, SITSCubeModel)
94100
@attach_doc("sits_combine_predictions")
95101
def sits_combine_predictions(*args, **kwargs) -> SITSCubeModel:
96102
"""Estimate ensemble prediction based on list of probs cubes."""
97103

98104

105+
#
106+
# Sampling
107+
#
99108
@function_call(r_pkg_sits.sits_uncertainty_sampling, SITSFrame)
100109
@attach_doc("sits_uncertainty_sampling")
101110
def sits_uncertainty_sampling(*args, **kwargs) -> SITSFrame:
@@ -108,18 +117,27 @@ def sits_confidence_sampling(*args, **kwargs) -> SITSFrame:
108117
"""Suggest high confidence samples to increase the training set."""
109118

110119

120+
#
121+
# Colors
122+
#
111123
@function_call(r_pkg_sits.sits_colors_qgis, lambda x: None)
112124
@attach_doc("sits_colors_qgis")
113125
def sits_colors_qgis(*args, **kwargs) -> None:
114126
"""Function to save color table as QML style for data cube."""
115127

116128

129+
#
130+
# Base cube
131+
#
117132
@function_call(r_pkg_sits.sits_add_base_cube, SITSCubeModel)
118133
@attach_doc("sits_add_base_cube")
119134
def sits_add_base_cube(*args, **kwargs) -> SITSCubeModel:
120135
"""Add base maps to a time series data cube."""
121136

122137

138+
#
139+
# Reclassify
140+
#
123141
@rpy2_fix_type_custom(converters=reclassify_converters)
124142
@rpy2_fix_type
125143
@attach_doc("sits_reclassify")
@@ -159,6 +177,9 @@ def sits_reclassify(
159177
return SITSCubeModel(result)
160178

161179

180+
#
181+
# Texture
182+
#
162183
@rpy2_fix_type
163184
@attach_doc("sits_texture")
164185
def sits_texture(cube, **kwargs) -> SITSCubeModel:

0 commit comments

Comments
 (0)