craterslab 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: craterslab
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary:
5
5
  Home-page: https://github.com/gvieralopez/craters
6
6
  License: MIT
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  from enum import Enum
2
3
  from pathlib import Path
3
4
 
@@ -42,7 +43,10 @@ def get_untrained_model(lr=0.001) -> Sequential:
42
43
 
43
44
 
44
45
  def get_trained_model() -> Sequential:
45
- return keras.models.load_model(CACHE_PATH)
46
+ try:
47
+ return keras.models.load_model(CACHE_PATH)
48
+ except ValueError:
49
+ logging.error("Pre-trained classification model could not be loaded")
46
50
 
47
51
 
48
52
  def save_trained_model(model):
@@ -56,4 +60,3 @@ def normalize(img: np.ndarray, expand=True) -> np.ndarray:
56
60
  if expand:
57
61
  return np.expand_dims(result, axis=0)
58
62
  return result
59
-
@@ -1,4 +1,5 @@
1
1
  import math
2
+ import logging
2
3
  from dataclasses import dataclass
3
4
 
4
5
  import numpy as np
@@ -52,9 +53,12 @@ class Surface:
52
53
 
53
54
  def classify(self) -> SurfaceType:
54
55
  classifier = get_trained_model()
55
- img = normalize(self.dm.map)
56
- class_id = np.argmax(classifier.predict(img))
57
- return SurfaceType(class_id)
56
+ if classifier is not None:
57
+ img = normalize(self.dm.map)
58
+ class_id = np.argmax(classifier.predict(img))
59
+ return SurfaceType(class_id)
60
+ logging.warning(f"Using default class {SurfaceType(1)}")
61
+ return SurfaceType(1)
58
62
 
59
63
  def compute_observables(self) -> dict[str, Observable]:
60
64
  observables = {}
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  import pathlib
2
3
  from dataclasses import dataclass
3
4
 
@@ -120,9 +121,42 @@ class DepthMap:
120
121
  # Compute depth map from image
121
122
  raise NotImplementedError
122
123
 
124
+ @staticmethod
125
+ def kinect_driver_available() -> bool:
126
+ try:
127
+ from libkinect2 import Kinect2
128
+ return True
129
+ except ModuleNotFoundError:
130
+ logging.error(
131
+ 'Kinect2 driver is not installed, To install it run: pip install https://github.com/sshh12/LibKinect2/releases/download/v0.1.0/libkinect2-0.1.0.tar.gz')
132
+ return False
133
+
134
+ @staticmethod
135
+ def _get_kinect_depthmap(average_on: int) -> np.ndarray:
136
+ # Init Kinect2 w/2 sensors
137
+ from libkinect2 import Kinect2
138
+ kinect = Kinect2(use_sensors=['depth'])
139
+ kinect.connect()
140
+ kinect.wait_for_worker()
141
+ _, depth_map = next(kinect.iter_frames())
142
+ if average_on > 1:
143
+ shape = depth_map.shape[0], depth_map.shape[1], average_on
144
+ samples = np.zeros(shape, dtype=depth_map.dtype)
145
+ for i in range(average_on):
146
+ _, dm = next(kinect.iter_frames())
147
+ samples[:, :, i] = np.squeeze(dm)
148
+ depth_map = np.mean(samples, axis=-1)
149
+ kinect.disconnect()
150
+
151
+ return np.squeeze(depth_map)
152
+
123
153
  @classmethod
124
- def from_kinect_sensor(cls) -> "DepthMap":
125
- # Retrieve depth map from Kinect sensor
154
+ def from_kinect_sensor(cls, resolution: SensorResolution, average_on: int = 1) -> "DepthMap":
155
+ # Check if kinect library is installed
156
+ if cls.kinect_driver_available():
157
+ _depth_map = cls._get_kinect_depthmap(average_on)
158
+ return DepthMap(dmap=_depth_map, resolution=resolution)
159
+
126
160
  raise NotImplementedError
127
161
 
128
162
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "craterslab"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = ""
5
5
  license = "MIT"
6
6
  authors = [
@@ -18,7 +18,7 @@ install_requires = \
18
18
 
19
19
  setup_kwargs = {
20
20
  'name': 'craterslab',
21
- 'version': '0.2.0',
21
+ 'version': '0.2.2',
22
22
  'description': '',
23
23
  'long_description': '# Craters Morphology Analysis Tool\n\nA library to simplify the analysis of crater data from depth maps.\n\n## Installation\n\nCraterslab requires Python 3.10+ for functioning. Make sure you have a compliant version of [python](https://www.python.org/downloads/) installed in your system.\n\n### Installing craterslab from the repository using poetry (Recommended)\n\nMake sure you have [poetry](https://python-poetry.org/docs/) in your system and then run:\n\n```\n$ git clone https://github.com/gvieralopez/craterslab.git\n$ cd craterslab\n$ poetry install\n$ poetry shell\n```\n\nThese will create and activate an isolated virtual environment with craterslab installed on it. \n\n### Installing craterslab from pypi using pip\n\nCraterslab is also available from pypi. You can install it by running:\n\n```\n$ pip install craterslab\n```\n\nWe strongly encourage users using this method to create a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/) before installing the library.\n\n## Usage\n\nYou can find some examples on how to use the library in this repository:\n\n```\n$ git clone https://github.com/gvieralopez/craterslab.git\n$ cd craterslab/examples\n```\n\nBefore executing any example, you will need to download data from actual craters using the provided scripts:\n\n```\n$ python download_data.py\n```\n\nThen, you can execute any given example as:\n\n```\n$ python example1.py\n```\n\nSee [software documentation](https://craterslab.readthedocs.io/en/latest/) for more details.\n\n',
24
24
  'author': 'Gustavo Viera López',
File without changes
File without changes