ursgehrig commited on
Commit
1b645bc
·
verified ·
1 Parent(s): 1577ad4

Update data_types.py

Browse files

Fix two Python 3.13 incompatibilities: replace mutable np.ndarray defaults in StripMeasuredData with default_factory=lambda: np.zeros(...), and remove private _is_classvar/_is_dataclass_instance imports removed from the dataclasses stdlib in 3.13

Files changed (1) hide show
  1. data_types.py +13 -13
data_types.py CHANGED
@@ -1,6 +1,6 @@
1
  # -----------------------------------------------------------------------------
2
  #
3
- # This file is part of the PantoScanner distribution on:
4
  # https://huggingface.co/spaces/swissrail/PantoScanner
5
  #
6
  # PantoScanner - Analytics and measurement capability for technical objects.
@@ -16,11 +16,11 @@
16
  #
17
  # This program is distributed in the hope that it will be useful,
18
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
  # GNU General Public License for more details.
21
  #
22
  # You should have received a copy of the GNU General Public License
23
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
24
  #
25
  # -----------------------------------------------------------------------------
26
 
@@ -28,7 +28,8 @@ import os
28
  from datetime import datetime
29
  import math
30
  import numpy as np
31
- from dataclasses import dataclass, field, asdict, astuple, InitVar, fields, is_dataclass, _is_classvar, _is_dataclass_instance
 
32
  from typing import List, Dict, Tuple
33
  import cv2 as cv
34
  import json
@@ -330,10 +331,11 @@ class StripMeasuredData:
330
 
331
  bounding_box_a: BBoxCoordinates = field(init=True, default=False)
332
  bounding_box_b: BBoxCoordinates = field(init=True, default=False)
333
- estimated_euler_angles: np.ndarray = field(init=True, default=np.zeros((3, 1)))
334
- estimated_distances: np.ndarray = field(init=True, default=np.zeros((3, 1)))
335
- profile_a: np.ndarray = field(init=True, default=np.zeros((601, 2)))
336
- profile_b: np.ndarray = field(init=True, default=np.zeros((601, 2)))
 
337
  sliding_strip_type: str = field(init=True, default=False)
338
 
339
  img_matched_source_data: InitVar[ImageMatchedData] = field(init=True, default=False)
@@ -399,8 +401,8 @@ class ImgSyncedData:
399
  class ImageSourceData:
400
  img_file_path: str = field(init=True)
401
  json_file_path: str = field(init=True)
402
- img_array: np.ndarray = field(init=False)
403
- meta_data: dict = field(init=False)
404
 
405
  def load_source_data(self):
406
  self.img_array = cv.imread(self.img_file_path, cv.IMREAD_ANYDEPTH)
@@ -535,6 +537,4 @@ class ApiClientPictureData: # data given to clients, attributes inherited from
535
  image_location_latitude: float # not relevant now, but will be in the future, inherited from camera reference
536
  image_location_longitude: float # not relevant now, but will be in the future, inherited from camera reference
537
  image_location_track_ref: int # not relevant now, but will be in the future, inherited from camera reference
538
- image_train_direction_of_movement: float # train heading in degrees, or +1/-1 if the given track defines direction
539
-
540
-
 
1
  # -----------------------------------------------------------------------------
2
  #
3
+ # This file is part of the PantoScanner distribution on:
4
  # https://huggingface.co/spaces/swissrail/PantoScanner
5
  #
6
  # PantoScanner - Analytics and measurement capability for technical objects.
 
16
  #
17
  # This program is distributed in the hope that it will be useful,
18
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
  # GNU General Public License for more details.
21
  #
22
  # You should have received a copy of the GNU General Public License
23
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
24
  #
25
  # -----------------------------------------------------------------------------
26
 
 
28
  from datetime import datetime
29
  import math
30
  import numpy as np
31
+ # FIX: _is_classvar and _is_dataclass_instance are private internals removed in Python 3.13
32
+ from dataclasses import dataclass, field, asdict, astuple, InitVar, fields, is_dataclass
33
  from typing import List, Dict, Tuple
34
  import cv2 as cv
35
  import json
 
331
 
332
  bounding_box_a: BBoxCoordinates = field(init=True, default=False)
333
  bounding_box_b: BBoxCoordinates = field(init=True, default=False)
334
+ # FIX: np.ndarray is mutable — Python 3.13 requires default_factory instead of default
335
+ estimated_euler_angles: np.ndarray = field(init=True, default_factory=lambda: np.zeros((3, 1)))
336
+ estimated_distances: np.ndarray = field(init=True, default_factory=lambda: np.zeros((3, 1)))
337
+ profile_a: np.ndarray = field(init=True, default_factory=lambda: np.zeros((601, 2)))
338
+ profile_b: np.ndarray = field(init=True, default_factory=lambda: np.zeros((601, 2)))
339
  sliding_strip_type: str = field(init=True, default=False)
340
 
341
  img_matched_source_data: InitVar[ImageMatchedData] = field(init=True, default=False)
 
401
  class ImageSourceData:
402
  img_file_path: str = field(init=True)
403
  json_file_path: str = field(init=True)
404
+ img_array: np.ndarray = field(init=False, default=None)
405
+ meta_data: dict = field(init=False, default_factory=dict)
406
 
407
  def load_source_data(self):
408
  self.img_array = cv.imread(self.img_file_path, cv.IMREAD_ANYDEPTH)
 
537
  image_location_latitude: float # not relevant now, but will be in the future, inherited from camera reference
538
  image_location_longitude: float # not relevant now, but will be in the future, inherited from camera reference
539
  image_location_track_ref: int # not relevant now, but will be in the future, inherited from camera reference
540
+ image_train_direction_of_movement: float # train heading in degrees, or +1/-1 if the given track defines direction