From 03997b5c9fe5c1e10286a76436bbc1e734708dcd Mon Sep 17 00:00:00 2001 From: amogh7joshi Date: Sun, 2 Oct 2022 10:45:16 -0400 Subject: [PATCH] Fix installation problems and bump to v0.4.2 --- agml/__init__.py | 2 +- agml/synthetic/config.py | 10 ++++++++++ agml/synthetic/generator.py | 18 ++---------------- agml/synthetic/options.py | 16 +++++----------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/agml/__init__.py b/agml/__init__.py index 3023be682..5dffe3883 100644 --- a/agml/__init__.py +++ b/agml/__init__.py @@ -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'] diff --git a/agml/synthetic/config.py b/agml/synthetic/config.py index e7dfe53d0..32b9733a2 100644 --- a/agml/synthetic/config.py +++ b/agml/synthetic/config.py @@ -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). @@ -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] diff --git a/agml/synthetic/generator.py b/agml/synthetic/generator.py index 18346f63c..32afe66ea 100644 --- a/agml/synthetic/generator.py +++ b/agml/synthetic/generator.py @@ -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 ) @@ -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) diff --git a/agml/synthetic/options.py b/agml/synthetic/options.py index de3709e40..504912de7 100644 --- a/agml/synthetic/options.py +++ b/agml/synthetic/options.py @@ -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 @@ -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) @@ -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']: