Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/activity mask #73

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dev-runserver:
@echo "------------------------------------------------------------------"
@echo "Start django runserver in dev container"
@echo "------------------------------------------------------------------"
@docker compose $(ARGS) exec -T dev bash -c "nohup python manage.py runserver 0.0.0.0:8080 &"
@docker compose $(ARGS) exec -T dev bash -c "python manage.py runserver 0.0.0.0:8080"

dev-shell:
@echo
Expand Down
2 changes: 1 addition & 1 deletion deployment/docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ django-revproxy @ https://github.com/jazzband/django-revproxy/archive/refs/tags/
rasterio==1.3.10

# cplus core
git+https://github.com/kartoza/[email protected].4
git+https://github.com/kartoza/[email protected].8
55 changes: 51 additions & 4 deletions django_project/cplus_api/utils/worker_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class APITaskConfig(object):
pathway_uuid_layers = {}
carbon_uuid_layers = {}
priority_uuid_layers = {}
activity_mask_uuid_layers = {}
activity_mask_layer_paths = []
total_input_layers = 0
# output selections
ncs_with_carbon = DEFAULT_VALUES.ncs_with_carbon
Expand Down Expand Up @@ -254,6 +256,7 @@ def to_dict(self):
'pathway_uuid_layers': self.pathway_uuid_layers,
'carbon_uuid_layers': self.carbon_uuid_layers,
'priority_uuid_layers': self.priority_uuid_layers,
'activity_mask_uuid_layers': self.activity_mask_uuid_layers,
'total_input_layers': self.total_input_layers,
'ncs_with_carbon': self.ncs_with_carbon,
'landuse_project': self.landuse_project,
Expand All @@ -271,6 +274,7 @@ def to_dict(self):
'user_defined': activity.user_defined,
'pathways': [],
'priority_layers': activity.priority_layers,
'mask_paths': activity.mask_paths,
'layer_styles': activity.layer_styles
}
for pathway in activity.pathways:
Expand Down Expand Up @@ -335,6 +339,7 @@ def from_dict(cls, data: dict) -> typing.Self:
config.priority_uuid_layers = {}
config.pathway_uuid_layers = {}
config.carbon_uuid_layers = {}
config.activity_mask_uuid_layers = {}

# store priority layers
for priority_layer in config.priority_layers:
Expand Down Expand Up @@ -387,7 +392,8 @@ def from_dict(cls, data: dict) -> typing.Self:
user_defined=activity.get('user_defined', False),
pathways=[],
priority_layers=filtered_priority_layer,
layer_styles=activity.get('layer_styles', {})
layer_styles=activity.get('layer_styles', {}),
mask_paths=activity.get('mask_uuids', [])
)

# create pathways
Expand Down Expand Up @@ -427,6 +433,17 @@ def from_dict(cls, data: dict) -> typing.Self:
str(pw_uuid)
]

# create activity mask paths
mask_uuids = activity.get('mask_uuids', [])
for mask_uuid in mask_uuids:
if mask_uuid in config.activity_mask_uuid_layers:
config.activity_mask_uuid_layers[mask_uuids].append(
str(mask_uuid))
else:
config.activity_mask_uuid_layers[mask_uuid] = [
str(mask_uuid)
]

config.analysis_activities.append(activity_obj)

# create scenario object
Expand All @@ -451,6 +468,7 @@ def from_dict(cls, data: dict) -> typing.Self:
if config.sieve_mask_uuid:
config.total_input_layers += 1
config.total_input_layers += len(config.mask_layer_uuids)
config.total_input_layers += len(config.activity_mask_uuid_layers)
return config


Expand Down Expand Up @@ -553,6 +571,22 @@ def initialize_input_layers(self, scenario_path: str):
if key in carbon_uuids
})

# init activity mask layers
activity_mask_paths = {}
for mask_layer in self.task_config.activity_mask_uuid_layers:
layer_uuid = mask_layer
if layer_uuid not in self.downloaded_layers:
layer_paths = self.copy_input_layers_by_uuids(
None, [layer_uuid], scenario_path
)
activity_mask_paths[layer_uuid] = layer_paths[layer_uuid]
self.downloaded_layers.update(layer_paths)
else:
activity_mask_paths[
layer_uuid
] = self.downloaded_layers[layer_uuid]
self.task_config.activity_mask_layer_paths = activity_mask_paths

# Patch/Fix layer_path into priority layers dictionary
if priority_layer_paths:
self.patch_layer_path_to_priority_layers(priority_layer_paths)
Expand All @@ -561,7 +595,8 @@ def initialize_input_layers(self, scenario_path: str):
self.patch_layer_path_to_activities(
priority_layer_paths,
pathway_layer_paths,
carbon_layer_paths
carbon_layer_paths,
activity_mask_paths
)

# init snap layer
Expand Down Expand Up @@ -672,7 +707,8 @@ def patch_layer_path_to_priority_layers(self, priority_layer_paths):

def patch_layer_path_to_activities(
self, priority_layer_paths,
pathway_layer_paths, carbon_layer_paths):
pathway_layer_paths, carbon_layer_paths,
activity_mask_layer_paths):
"""Patch/Fix layer_path into activities.

:param priority_layer_paths: Dictionary of Layer UUID and
Expand All @@ -684,7 +720,9 @@ def patch_layer_path_to_activities(
:param carbon_layer_paths: Dictionary of Layer UUID and
actual file path for carbon layers
:type carbon_layer_paths: dict
"""
:param activity_mask_layer_paths: Dictionary of Layer UUID and
actual file path for mask layers
:type activity_mask_layer_paths: dict """
pw_uuid_mapped = self.transform_uuid_layer_paths(
self.task_config.pathway_uuid_layers, pathway_layer_paths)
priority_uuid_mapped = self.transform_uuid_layer_paths(
Expand Down Expand Up @@ -712,6 +750,15 @@ def patch_layer_path_to_activities(
carbon_layer_paths[carbon_layer_uuid])
pathway.carbon_paths = carbon_paths

for mask_uuid in activity.mask_paths:
mask_paths = []
if mask_uuid in activity_mask_layer_paths:
mask_paths.append(
activity_mask_layer_paths[mask_uuid]
)
activity.mask_paths = mask_paths
self.log_message(activity)

# update reference object
self.scenario.activities = self.task_config.analysis_activities
self.analysis_activities = (
Expand Down
Loading