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

Make the location of "ui_results" configurable #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def registration(request):
# It is possible to use msg.add_alternative() to add HTML content too
html_content = ""
activation_url = settings.BASE_HOST + "/accounts/" + str(activation.url) + "/activate"
with open('/home/' + settings.LOCAL_USER +
'/Datacube/data_cube_ui/static/assets/media/email_template.html') as f:
from os import path
with open(path.join(settings.BASE_DIR, 'static/assets/media/email_template.html')) as f:
for line in f:
if (line == "\t\t\tAVAILABLE_TOOLS\n"):
for app in Application.objects.all():
Expand All @@ -249,7 +249,7 @@ def registration(request):
html_content = html_content.replace("ACTIVATION_URL", activation_url)
msg.add_alternative(html_content, subtype='html')
# Attaching content:
fp = open('/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/static/assets/media/banner.png',
fp = open(path.join(settings.BASE_DIR, 'static/assets/media/banner.png'),
'rb')
att = MIMEImage(fp.read()) # Or use MIMEImage, etc
fp.close()
Expand Down
5 changes: 3 additions & 2 deletions apps/cloud_coverage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.db import models
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -61,8 +62,8 @@ class Query(BaseQuery):

"""

color_scale_path = '/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/utils/color_scales/cloud_coverage'
base_result_dir = '/datacube/ui_results/cloud_coverage'
color_scale_path = os.path.join(settings.BASE_DIR, 'utils/color_scales/cloud_coverage')
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'cloud_coverage')

class Meta(BaseQuery.Meta):
unique_together = (('satellite', 'area_id', 'time_start', 'time_end', 'latitude_max', 'latitude_min',
Expand Down
1 change: 1 addition & 0 deletions apps/cloud_coverage/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def create_output_products(data, task_id=None):
titles="Clean Pixel Percentage Per Acquisition")

logger.info("All products created.")
task.rewrite_pathnames()
# task.update_bounds_from_dataset(dataset)
task.complete = True
task.execution_end = datetime.now()
Expand Down
4 changes: 3 additions & 1 deletion apps/coastal_change/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.conf import settings
from django.db import models
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -74,7 +76,7 @@ class Query(BaseQuery):

animated_product = models.ForeignKey(AnimationType)

base_result_dir = '/datacube/ui_results/coastal_change'
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'coastal_change')

class Meta(BaseQuery.Meta):
unique_together = (('satellite', 'area_id', 'time_start', 'time_end', 'latitude_max', 'latitude_min',
Expand Down
1 change: 1 addition & 0 deletions apps/coastal_change/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def create_output_products(data, task_id=None):
writer.append_data(image)

logger.info("All products created.")
task.rewrite_pathnames()
# task.update_bounds_from_dataset(dataset)
task.complete = True
task.execution_end = datetime.now()
Expand Down
4 changes: 3 additions & 1 deletion apps/custom_mosaic_tool/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.conf import settings
from django.db import models
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -83,7 +85,7 @@ class Query(BaseQuery):
animated_product = models.ForeignKey(AnimationType)
compositor = models.ForeignKey(Compositor)

base_result_dir = '/datacube/ui_results/custom_mosaic_tool'
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'custom_mosaic_tool')

class Meta(BaseQuery.Meta):
unique_together = (
Expand Down
1 change: 1 addition & 0 deletions apps/custom_mosaic_tool/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def create_output_products(data, task_id=None):
titles="Clean Pixel Percentage Per Acquisition")

logger.info("All products created.")
task.rewrite_pathnames()
# task.update_bounds_from_dataset(dataset)
task.complete = True
task.execution_end = datetime.now()
Expand Down
6 changes: 3 additions & 3 deletions apps/data_cube_manager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def update_data_cube_details(ingested_only=True):
dataset_types = DatasetType.objects.using('agdc').filter(
Q(definition__has_keys=['managed']) & Q(definition__has_keys=['measurements']))

dc = DataAccessApi(config='/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/config/.datacube.conf')
dc = DataAccessApi(config=os.path.join(os.getenv('HOME'), '.datacube.conf'))

for dataset_type in dataset_types:
ingestion_details, created = IngestionDetails.objects.get_or_create(
Expand All @@ -86,7 +86,7 @@ def run_ingestion(ingestion_definition):
Returns:
The primary key of the new dataset type.
"""
conf_path = '/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/config/.datacube.conf'
conf_path = os.path.join(os.getenv('HOME'), '.datacube.conf')
index = index_connect(local_config=LocalConfig.find([conf_path]))

source_type, output_type = ingest.make_output_type(index, ingestion_definition)
Expand All @@ -104,7 +104,7 @@ def ingestion_work(output_type, source_type, ingestion_definition):
output_type, source_type: types produced by ingest.make_output_type
ingestion_definition: dict representing a Data Cube ingestion def produced using the utils func.
"""
conf_path = '/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/config/.datacube.conf'
conf_path = os.path.join(os.getenv('HOME'), '.datacube.conf')
index = index_connect(local_config=LocalConfig.find([conf_path]))

tasks = ingest.create_task_list(index, output_type, None, source_type, ingestion_definition)
Expand Down
7 changes: 4 additions & 3 deletions apps/data_cube_manager/views/dataset_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def post(self, request):
#since everything is valid, now create yaml from defs..
product_def = utils.dataset_type_definition_from_forms(metadata_form, measurement_forms)

conf_path = '/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/config/.datacube.conf'
conf_path = os.path.join(os.getenv('HOME'), '.datacube.conf')
index = index_connect(local_config=conf_path)
try:
type_ = index.products.from_doc(product_def)
Expand Down Expand Up @@ -154,7 +154,7 @@ def post(self, request):
#since everything is valid, now create yaml from defs..
product_def = utils.dataset_type_definition_from_forms(metadata_form, measurement_forms)
try:
os.makedirs('/datacube/ui_results/data_cube_manager/product_defs/')
os.makedirs(os.path.join(settings.RESULTS_DATA_DIR, 'data_cube_manager/product_defs/'))
except:
pass

Expand All @@ -163,7 +163,8 @@ def _dict_representer(dumper, data):

yaml.SafeDumper.add_representer(OrderedDict, _dict_representer)

yaml_url = '/datacube/ui_results/data_cube_manager/product_defs/' + str(uuid.uuid4()) + '.yaml'
yaml_url = os.path.join(settings.RESULTS_DATA_DIR, 'data_cube_manager/product_defs/') \
+ str(uuid.uuid4()) + '.yaml'
with open(yaml_url, 'w') as yaml_file:
yaml.dump(product_def, yaml_file, Dumper=yaml.SafeDumper, default_flow_style=False, indent=4)
return JsonResponse({'status': 'OK', 'url': yaml_url})
Expand Down
8 changes: 5 additions & 3 deletions apps/data_cube_manager/views/ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.shortcuts import render, redirect
from django.http import HttpResponse, JsonResponse
Expand Down Expand Up @@ -103,7 +104,7 @@ def post(self, request):
ingestion_def = utils.ingestion_definition_from_forms(metadata_form, storage_form, ingestion_bounds_form,
measurement_forms)
try:
os.makedirs('/datacube/ui_results/data_cube_manager/ingestion_configurations/')
os.makedirs(os.path.join(settings.RESULTS_DATA_DIR, 'data_cube_manager/ingestion_configurations/'))
except:
pass

Expand All @@ -112,7 +113,8 @@ def _dict_representer(dumper, data):

yaml.SafeDumper.add_representer(OrderedDict, _dict_representer)

yaml_url = '/datacube/ui_results/data_cube_manager/ingestion_configurations/' + str(uuid.uuid4()) + '.yaml'
yaml_url = os.path.join(settings.RESULTS_DATA_DIR, 'data_cube_manager/ingestion_configurations/') \
+ str(uuid.uuid4()) + '.yaml'
with open(yaml_url, 'w') as yaml_file:
yaml.dump(ingestion_def, yaml_file, Dumper=yaml.SafeDumper, default_flow_style=False, indent=4)
return JsonResponse({'status': 'OK', 'url': yaml_url})
Expand Down Expand Up @@ -289,7 +291,7 @@ def post(self, request):
'description':
"Sample subset of {} created for {}".format(dataset_type.name, request.user.username),
'location':
"/datacube/ingested_data/{}".format(request.user.username),
os.path.join(os.path.dirname(settings.RESULTS_DATA_DIR), "ingested_data/{}".format(request.user.username)),
'file_path_template':
"SAMPLE_CUBE_4326_{tile_index[0]}_{tile_index[1]}_{start_time}.nc",
'summary':
Expand Down
5 changes: 3 additions & 2 deletions apps/dc_algorithm/management/commands/band_math_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.db import models
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -62,8 +63,8 @@ class Query(BaseQuery):
compositor = models.ForeignKey(Compositor)

#TODO: add color scale here
color_scale_path = '/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/utils/color_scales/default_color_scale'
base_result_dir = '/datacube/ui_results/band_math_app'
color_scale_path = os.path.join(settings.BASE_DIR, 'utils/color_scales/default_color_scale')
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'band_math_app')

class Meta(BaseQuery.Meta):
unique_together = (('satellite', 'area_id', 'time_start', 'time_end', 'latitude_max', 'latitude_min',
Expand Down
4 changes: 3 additions & 1 deletion apps/dc_algorithm/management/commands/base_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.conf import settings
from django.db import models
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -92,7 +94,7 @@ class Query(BaseQuery):
compositor = models.ForeignKey(Compositor)

# TODO: Fill out the configuration paths
base_result_dir = '/datacube/ui_results/app_name'
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'app_name')

class Meta(BaseQuery.Meta):
unique_together = (
Expand Down
18 changes: 17 additions & 1 deletion apps/dc_algorithm/models/abstract_base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Meta(Query.Meta):
#false by default, only change is false-> true
complete = models.BooleanField(default=False)

config_path = '/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/config/.datacube.conf'
config_path = os.path.join(os.getenv('HOME'), '.datacube.conf')

class Meta:
abstract = True
Expand Down Expand Up @@ -440,6 +440,22 @@ def get_progress(self):
clamped_int = max(0, min(rounded_int, 100))
return clamped_int

def rewrite_pathnames(self):
"""Rewrites all paths to be stored in the database to something the web server can serve

Converts the absolute paths of all files created during a task into paths relative
to the RESULTS_DATA_DIR configured in the Datacube UI's Django settings. This is done
by iterating over all attributes of the task and applying the conversion to those attributes
that are of type "str" and have a name ending in "_path".
"""
for attr in dir(self):
if attr.endswith("_path") and isinstance(getattr(self, attr), str):
path = getattr(self, attr)
if path.startswith(settings.RESULTS_DATA_DIR):
stripped_path = path.replace(settings.RESULTS_DATA_DIR, '', 1).lstrip(os.path.sep)
path = os.path.join(os.path.sep, "datacube", "ui_results", stripped_path)
setattr(self, attr, path)


class GenericTask(Query, Metadata, Result):
"""Serves as the model for an algorithm task containing a Query, Metadata, and Result
Expand Down
2 changes: 2 additions & 0 deletions apps/dc_algorithm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.shortcuts import render
from django.utils.decorators import method_decorator
Expand All @@ -26,6 +27,7 @@
from django.forms.models import model_to_dict
from django.views import View
from django.apps import apps
from django.conf import settings

from .models import Application, Satellite, Area

Expand Down
4 changes: 3 additions & 1 deletion apps/fractional_cover/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.conf import settings
from django.db import models
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -60,7 +62,7 @@ class Query(BaseQuery):
"""
compositor = models.ForeignKey(Compositor)

base_result_dir = '/datacube/ui_results/fractional_cover'
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'fractional_cover')

class Meta(BaseQuery.Meta):
unique_together = (('satellite', 'area_id', 'time_start', 'time_end', 'latitude_max', 'latitude_min',
Expand Down
1 change: 1 addition & 0 deletions apps/fractional_cover/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ def create_output_products(data, task_id=None):
titles="Clean Pixel Percentage Per Acquisition")

logger.info("All products created.")
task.rewrite_pathnames()
# task.update_bounds_from_dataset(dataset)
task.complete = True
task.execution_end = datetime.now()
Expand Down
11 changes: 6 additions & 5 deletions apps/ndvi_anomaly/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.db import models
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -61,16 +62,16 @@ class Query(BaseQuery):
"""
baseline_selection = models.CharField(max_length=100, default="1,2,3,4,5,6,7,8,9,10,11,12")

base_result_dir = '/datacube/ui_results/ndvi_anomaly'
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'ndvi_anomaly')
color_scales = {
'baseline_ndvi':
'/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/utils/color_scales/ndvi',
os.path.join(settings.BASE_DIR, 'utils/color_scales/ndvi'),
'scene_ndvi':
'/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/utils/color_scales/ndvi',
os.path.join(settings.BASE_DIR, 'utils/color_scales/ndvi'),
'ndvi_difference':
'/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/utils/color_scales/ndvi_difference',
os.path.join(settings.BASE_DIR, 'utils/color_scales/ndvi_difference'),
'ndvi_percentage_change':
'/home/' + settings.LOCAL_USER + '/Datacube/data_cube_ui/utils/color_scales/ndvi_percentage_change'
os.path.join(settings.BASE_DIR, 'utils/color_scales/ndvi_percentage_change')
}

class Meta(BaseQuery.Meta):
Expand Down
1 change: 1 addition & 0 deletions apps/ndvi_anomaly/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def create_output_products(data, task_id=None):
titles="Clean Pixel Percentage Per Acquisition")

logger.info("All products created.")
task.rewrite_pathnames()
# task.update_bounds_from_dataset(dataset)
task.complete = True
task.execution_end = datetime.now()
Expand Down
4 changes: 3 additions & 1 deletion apps/slip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os

from django.conf import settings
from django.db import models
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -74,7 +76,7 @@ class Query(BaseQuery):
baseline_method = models.ForeignKey(BaselineMethod)
baseline_length = models.IntegerField(default=10)

base_result_dir = '/datacube/ui_results/slip'
base_result_dir = os.path.join(settings.RESULTS_DATA_DIR, 'slip')

class Meta(BaseQuery.Meta):
unique_together = (
Expand Down
1 change: 1 addition & 0 deletions apps/slip/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def create_output_products(data, task_id=None):
titles=["Clean Pixel Percentage Per Acquisition", "SLIP Pixels Percentage Per Acquisition"])

logger.info("All products created.")
task.rewrite_pathnames()
# task.update_bounds_from_dataset(dataset)
task.complete = True
task.execution_end = datetime.now()
Expand Down
Loading