Skip to content

Commit

Permalink
Fix installation problems and bump to v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh7joshi committed Oct 2, 2022
1 parent 36833f9 commit 03997b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion agml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.4.1'
__version__ = '0.4.2'
__all__ = ['data', 'backend', 'viz']


Expand Down
10 changes: 10 additions & 0 deletions agml/synthetic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def reinstall_helios():
_check_helios_installation()


def verify_helios(f):
"""This decorator wraps any methods which require Helios to be installed."""
def verify(*args, **kwargs):
_check_helios_installation()
return f(*args, **kwargs)
return verify


# Run the Helios configuration check.
def _check_helios_installation():
"""Checks for the latest Helios installation (and does as such).
Expand Down Expand Up @@ -286,11 +294,13 @@ def _get_lidar_params():
################## API FUNCTIONS FOR CONVENIENCE ##################


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


@verify_helios
def default_canopy_parameters(canopy):
"""Returns the default canopy parameters for a given `canopy`."""
return load_default_helios_configuration()['canopy']['parameters'][canopy]
Expand Down
18 changes: 2 additions & 16 deletions agml/synthetic/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from agml.backend.config import synthetic_data_save_path
from agml.synthetic.options import HeliosOptions
from agml.synthetic.options import AnnotationType, SimulationType
from agml.synthetic.config import load_default_helios_configuration
from agml.synthetic.config import load_default_helios_configuration, verify_helios
from agml.synthetic.compilation import (
HELIOS_BUILD, HELIOS_EXECUTABLE, XML_PATH, PROJECT_PATH
)
Expand Down Expand Up @@ -101,21 +101,7 @@ class HeliosDataGenerator(AgMLSerializable):
A specific canopy to generate images for. This can be passed for
in place of `options` to initialize the default options.
"""

def __new__(cls, *args, **kwargs):
# Run the configuration check. Notice that we run this here because
# users may not necessarily want to use Helios on first installing
# AgML, but the `synthetic` module is loaded into the main AgML
# module as in the top-level `__init__.py` file. By putting the check
# here, it ensures that Helios is only installed if and when data is
# actually being generated, and not just by a standard import.
from .config import _check_helios_installation
_check_helios_installation()
del _check_helios_installation

# Return a `HeliosDataGenerator`.
return super(HeliosDataGenerator, cls).__new__(cls)

@verify_helios
def __init__(self, options: HeliosOptions = None, *, canopy = None):
if options is None and canopy is not None:
self._options = HeliosOptions(canopy)
Expand Down
16 changes: 5 additions & 11 deletions agml/synthetic/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import List, Union, Sequence

from agml.framework import AgMLSerializable
from agml.synthetic.config import load_default_helios_configuration
from agml.synthetic.config import load_default_helios_configuration, verify_helios
from agml.synthetic.tools import generate_camera_positions


Expand Down Expand Up @@ -277,22 +277,13 @@ class HeliosOptions(AgMLSerializable):
'annotation_type', 'simulation_type', 'labels'))

def __new__(cls, *args, **kwargs):
# Run the configuration check. Notice that we run this here because
# users may not necessarily want to use Helios on first installing
# AgML, but the `synthetic` module is loaded into the main AgML
# module as in the top-level `__init__.py` file. By putting the check
# here, it ensures that Helios is only installed if and when data is
# actually being generated, and not just by a standard import.
from .config import _check_helios_installation
_check_helios_installation()
del _check_helios_installation

# The default configuration parameters are loaded directly from
# the `helios_config.json` file which is constructed each time
# Helios is installed or updated.
cls._default_config = load_default_helios_configuration()
return super(HeliosOptions, cls).__new__(cls)

@verify_helios
def __init__(self, canopy = None):
# Check that the provided canopy is valid.
self._initialize_canopy(canopy)
Expand All @@ -302,6 +293,9 @@ def __init__(self, canopy = None):
self._simulation_type = SimulationType.RGB
self._labels = ['leaves']

def __str__(self):
return f"HeliosOptions({self._canopy})({self._to_dict()})"

def _initialize_canopy(self, canopy):
"""Initializes Helios options from the provided canopy."""
if canopy not in self._default_config['canopy']['types']:
Expand Down

0 comments on commit 03997b5

Please sign in to comment.