Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
80c0010
1
Parent(s):
5016509
fix: InputObservation comparison ok for images, and skipping time
Browse files- the timestamp is taken from the clock at the moment, infeasible to
be the same so would always update (overwrite) all observations on
reruns.
- also added a difference highlighter method for inspection
src/input/input_observation.py
CHANGED
|
@@ -117,17 +117,65 @@ class InputObservation:
|
|
| 117 |
def __eq__(self, other):
|
| 118 |
# TODO: ensure this covers all the attributes (some have been added?)
|
| 119 |
# - except inst_id which is unique
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
self.longitude == other.longitude and
|
| 123 |
self.author_email == other.author_email and
|
| 124 |
self.date == other.date and self.time == other.time and
|
| 125 |
self.date_option == other.date_option and
|
| 126 |
-
|
|
|
|
| 127 |
self.uploaded_filename == other.uploaded_filename and
|
| 128 |
-
self.image_md5 == other.
|
| 129 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
def __ne__(self, other):
|
| 133 |
return not self.__eq__(other)
|
|
|
|
| 117 |
def __eq__(self, other):
|
| 118 |
# TODO: ensure this covers all the attributes (some have been added?)
|
| 119 |
# - except inst_id which is unique
|
| 120 |
+
_image_equality = False
|
| 121 |
+
if self.image is None or other.image is None:
|
| 122 |
+
_image_equality = other.image == self.image
|
| 123 |
+
else: # maybe strong assumption: both are correctly ndarray.. should I test types intead?
|
| 124 |
+
_image_equality = (self.image == other.image).all()
|
| 125 |
+
equality = (
|
| 126 |
+
#self.image == other.image and
|
| 127 |
+
_image_equality and
|
| 128 |
+
self.latitude == other.latitude and
|
| 129 |
self.longitude == other.longitude and
|
| 130 |
self.author_email == other.author_email and
|
| 131 |
self.date == other.date and self.time == other.time and
|
| 132 |
self.date_option == other.date_option and
|
| 133 |
+
# temporarily skip time_option, it is followed by the clock and that is always differnt
|
| 134 |
+
#self.time_option == other.time_option and
|
| 135 |
self.uploaded_filename == other.uploaded_filename and
|
| 136 |
+
self.image_md5 == other.image_md5
|
| 137 |
)
|
| 138 |
+
return equality
|
| 139 |
+
|
| 140 |
+
# define a function show_diff(other) that shows the differences between two observations
|
| 141 |
+
# only highlight the differences, if element is the same don't show it
|
| 142 |
+
# have a summary at the top that shows if the observations are the same or not
|
| 143 |
+
|
| 144 |
+
def show_diff(self, other):
|
| 145 |
+
"""Show the differences between two observations"""
|
| 146 |
+
differences = []
|
| 147 |
+
if self.image is None or other.image is None:
|
| 148 |
+
if other.image != self.image:
|
| 149 |
+
differences.append(f" Image is different. (types mismatch: {type(self.image)} vs {type(other.image)})")
|
| 150 |
+
else:
|
| 151 |
+
if (self.image != other.image).any():
|
| 152 |
+
cnt = (self.image != other.image).sum()
|
| 153 |
+
differences.append(f" Image is different: {cnt} different pixels.")
|
| 154 |
+
if self.latitude != other.latitude:
|
| 155 |
+
differences.append(f" Latitude is different. (self: {self.latitude}, other: {other.latitude})")
|
| 156 |
+
if self.longitude != other.longitude:
|
| 157 |
+
differences.append(f" Longitude is different. (self: {self.longitude}, other: {other.longitude})")
|
| 158 |
+
if self.author_email != other.author_email:
|
| 159 |
+
differences.append(f" Author email is different. (self: {self.author_email}, other: {other.author_email})")
|
| 160 |
+
if self.date != other.date:
|
| 161 |
+
differences.append(f" Date is different. (self: {self.date}, other: {other.date})")
|
| 162 |
+
if self.time != other.time:
|
| 163 |
+
differences.append(f" Time is different. (self: {self.time}, other: {other.time})")
|
| 164 |
+
if self.date_option != other.date_option:
|
| 165 |
+
differences.append(f" Date option is different. (self: {self.date_option}, other: {other.date_option})")
|
| 166 |
+
if self.time_option != other.time_option:
|
| 167 |
+
differences.append(f" Time option is different. (self: {self.time_option}, other: {other.time_option})")
|
| 168 |
+
if self.uploaded_filename != other.uploaded_filename:
|
| 169 |
+
differences.append(" Uploaded filename is different.")
|
| 170 |
+
if self.image_md5 != other.image_md5:
|
| 171 |
+
differences.append(" Image MD5 hash is different.")
|
| 172 |
|
| 173 |
+
if differences:
|
| 174 |
+
print(f"Observations have {len(differences)} differences:")
|
| 175 |
+
for diff in differences:
|
| 176 |
+
print(diff)
|
| 177 |
+
else:
|
| 178 |
+
print("Observations are the same.")
|
| 179 |
|
| 180 |
def __ne__(self, other):
|
| 181 |
return not self.__eq__(other)
|