Skip to content

Commit 03997b5

Browse files
committed
Fix installation problems and bump to v0.4.2
1 parent 36833f9 commit 03997b5

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

agml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = '0.4.1'
15+
__version__ = '0.4.2'
1616
__all__ = ['data', 'backend', 'viz']
1717

1818

agml/synthetic/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ def reinstall_helios():
6464
_check_helios_installation()
6565

6666

67+
def verify_helios(f):
68+
"""This decorator wraps any methods which require Helios to be installed."""
69+
def verify(*args, **kwargs):
70+
_check_helios_installation()
71+
return f(*args, **kwargs)
72+
return verify
73+
74+
6775
# Run the Helios configuration check.
6876
def _check_helios_installation():
6977
"""Checks for the latest Helios installation (and does as such).
@@ -286,11 +294,13 @@ def _get_lidar_params():
286294
################## API FUNCTIONS FOR CONVENIENCE ##################
287295

288296

297+
@verify_helios
289298
def available_canopies():
290299
"""Returns a list of available canopies in Helios."""
291300
return load_default_helios_configuration()['canopy']['types']
292301

293302

303+
@verify_helios
294304
def default_canopy_parameters(canopy):
295305
"""Returns the default canopy parameters for a given `canopy`."""
296306
return load_default_helios_configuration()['canopy']['parameters'][canopy]

agml/synthetic/generator.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from agml.backend.config import synthetic_data_save_path
3030
from agml.synthetic.options import HeliosOptions
3131
from agml.synthetic.options import AnnotationType, SimulationType
32-
from agml.synthetic.config import load_default_helios_configuration
32+
from agml.synthetic.config import load_default_helios_configuration, verify_helios
3333
from agml.synthetic.compilation import (
3434
HELIOS_BUILD, HELIOS_EXECUTABLE, XML_PATH, PROJECT_PATH
3535
)
@@ -101,21 +101,7 @@ class HeliosDataGenerator(AgMLSerializable):
101101
A specific canopy to generate images for. This can be passed for
102102
in place of `options` to initialize the default options.
103103
"""
104-
105-
def __new__(cls, *args, **kwargs):
106-
# Run the configuration check. Notice that we run this here because
107-
# users may not necessarily want to use Helios on first installing
108-
# AgML, but the `synthetic` module is loaded into the main AgML
109-
# module as in the top-level `__init__.py` file. By putting the check
110-
# here, it ensures that Helios is only installed if and when data is
111-
# actually being generated, and not just by a standard import.
112-
from .config import _check_helios_installation
113-
_check_helios_installation()
114-
del _check_helios_installation
115-
116-
# Return a `HeliosDataGenerator`.
117-
return super(HeliosDataGenerator, cls).__new__(cls)
118-
104+
@verify_helios
119105
def __init__(self, options: HeliosOptions = None, *, canopy = None):
120106
if options is None and canopy is not None:
121107
self._options = HeliosOptions(canopy)

agml/synthetic/options.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import List, Union, Sequence
2020

2121
from agml.framework import AgMLSerializable
22-
from agml.synthetic.config import load_default_helios_configuration
22+
from agml.synthetic.config import load_default_helios_configuration, verify_helios
2323
from agml.synthetic.tools import generate_camera_positions
2424

2525

@@ -277,22 +277,13 @@ class HeliosOptions(AgMLSerializable):
277277
'annotation_type', 'simulation_type', 'labels'))
278278

279279
def __new__(cls, *args, **kwargs):
280-
# Run the configuration check. Notice that we run this here because
281-
# users may not necessarily want to use Helios on first installing
282-
# AgML, but the `synthetic` module is loaded into the main AgML
283-
# module as in the top-level `__init__.py` file. By putting the check
284-
# here, it ensures that Helios is only installed if and when data is
285-
# actually being generated, and not just by a standard import.
286-
from .config import _check_helios_installation
287-
_check_helios_installation()
288-
del _check_helios_installation
289-
290280
# The default configuration parameters are loaded directly from
291281
# the `helios_config.json` file which is constructed each time
292282
# Helios is installed or updated.
293283
cls._default_config = load_default_helios_configuration()
294284
return super(HeliosOptions, cls).__new__(cls)
295285

286+
@verify_helios
296287
def __init__(self, canopy = None):
297288
# Check that the provided canopy is valid.
298289
self._initialize_canopy(canopy)
@@ -302,6 +293,9 @@ def __init__(self, canopy = None):
302293
self._simulation_type = SimulationType.RGB
303294
self._labels = ['leaves']
304295

296+
def __str__(self):
297+
return f"HeliosOptions({self._canopy})({self._to_dict()})"
298+
305299
def _initialize_canopy(self, canopy):
306300
"""Initializes Helios options from the provided canopy."""
307301
if canopy not in self._default_config['canopy']['types']:

0 commit comments

Comments
 (0)