diff options
Diffstat (limited to 'src/argaze/AreaOfInterest/AOIFeatures.py')
-rw-r--r-- | src/argaze/AreaOfInterest/AOIFeatures.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/argaze/AreaOfInterest/AOIFeatures.py b/src/argaze/AreaOfInterest/AOIFeatures.py index 8c684c0..5a9d0a9 100644 --- a/src/argaze/AreaOfInterest/AOIFeatures.py +++ b/src/argaze/AreaOfInterest/AOIFeatures.py @@ -241,6 +241,42 @@ class AOIScene(): for name, area in areas.items(): self[name] = AreaOfInterest(area) + @classmethod + def from_dict(self, aoi_scene_data, working_directory: str = None) -> AOISceneType: + """Load attributes from dictionary. + + Parameters: + aoi_scene_data: dictionary with attributes to load + working_directory: folder path where to load files when a dictionary value is a relative filepath. + """ + + # Load areas + areas = {} + + for name, area in aoi_scene_data.items(): + areas[name] = AreaOfInterest(area) + + # Guess dimension from first area dimension + dimension = areas.values()[0].dimension + + return AOIScene(dimension = dimension, areas = areas) + + @classmethod + def from_json(self, json_filepath: str) -> AOISceneType: + """ + Load attributes from .json file. + + Parameters: + json_filepath: path to json file + """ + + with open(json_filepath) as configuration_file: + + aoi_scene_data = json.load(configuration_file) + working_directory = os.path.dirname(json_filepath) + + return AOIScene.from_dict(aoi_scene_data, working_directory) + def __getitem__(self, name) -> AreaOfInterest: """Get an AOI from the scene.""" |