Skip to content

Commit

Permalink
Merge pull request #55 from geofranzi/47-nc-and-tif-climate
Browse files Browse the repository at this point in the history
47 nc and tif climate
  • Loading branch information
geofranzi authored Jul 3, 2024
2 parents 9baa415 + 22ad6bb commit eb04e2a
Show file tree
Hide file tree
Showing 4 changed files with 767 additions and 106 deletions.
7 changes: 6 additions & 1 deletion framework/climate/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .models import (CfStandardNames, ClimateChangeScenario, ClimateLayer, ClimateModelling, ClimateModellingBase,
ClimatePeriods, ClimateVariable, CoupledModelIntercomparisonProject, GlobalClimateModel,
ProcessingMethod, RegionalClimateModel,)
ProcessingMethod, RegionalClimateModel, TempResultFile,)


class CfStandardNamesAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -55,6 +55,10 @@ class ProcessingMethodAdmin(admin.ModelAdmin):
list_display = ('name',)


class TempResultFileAdmin(admin.ModelAdmin):
list_display = ('filename', 'category',)


admin.site.register(CfStandardNames, CfStandardNamesAdmin)
admin.site.register(ClimateLayer, ClimateLayerAdmin)
admin.site.register(ClimateVariable, ClimateVariableAdmin)
Expand All @@ -66,4 +70,5 @@ class ProcessingMethodAdmin(admin.ModelAdmin):
admin.site.register(GlobalClimateModel, GlobalClimateModelAdmin)
admin.site.register(RegionalClimateModel, RegionalClimateModelAdmin)
admin.site.register(ProcessingMethod, ProcessingMethodAdmin)
admin.site.register(TempResultFile, TempResultFileAdmin)
admin.site.site_header = 'Climate Administration'
52 changes: 52 additions & 0 deletions framework/climate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,55 @@ class ProvenanceInline(models.Model):

def __str__(self):
return self.relation_type + " " + self.target.name


class TempResultFile(models.Model):
NUM_BANDS_TIF_LIMIT = 250
CATEGORIES = ("water_budget", "water_budget"), ("water_budget_bias", "water_budget_bias"), ("kaariba", "kaariba")
categorized_filename = models.CharField(max_length=500, unique=True, null=True)
filename = models.CharField(max_length=400, null=True)
category = models.CharField(max_length=255, choices=CATEGORIES, null=True)
num_bands = models.IntegerField(null=True)
band_metadata = models.JSONField(default=dict)
net_cdf_times = models.JSONField(default=dict)
st_mtime_nc = models.CharField(max_length=255, null=True)
st_mtime_tif = models.CharField(max_length=255, null=True)
st_size_nc = models.CharField(max_length=255, null=True)

def get_by_cat_filename(cat_filename: str):
o = None
try:
o: TempResultFile = TempResultFile.objects.get(categorized_filename=cat_filename)
except Exception:
return None

return o

def get_file_metadata(self):
combined_metadata = {
'num_bands': self.num_bands,
'band_metadata': self.band_metadata,
'net_cdf_times': self.net_cdf_times
}

return combined_metadata

def check_raw_version(self, version):
if str(version) != self.st_mtime_nc:
return False
else:
return True

def check_cache_version(self, version):
if str(version) != self.st_mtime_tif:
return False
else:
return True

def tif_convertable(self):
if self.num_bands is None or self.num_bands > self.NUM_BANDS_TIF_LIMIT:
return False
return True

def __str__(self):
return f"[{self.category}] {str(self.filename)}"
10 changes: 6 additions & 4 deletions framework/climate/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
path('search', views.Elasticsearch.as_view(), name="search"),
path('search_collection', views.ElasticsearchCollections.as_view(), name="search_collection"),
path('search_indicator', views.ElasticsearchIndicators.as_view(), name="search_indicator"),
path('get_climate_txt', views.TextFileView.as_view(), name='get_climate_txt'),
path('select_for_wget', views.SelectionForWgetView.as_view(), name='select_for_wget'),
path('get_content', views.ContentView.as_view(), name='get_content'),
path('get_file', views.GetFileView.as_view(), name='get_file'),
path('get_temp_urls', views.get_temp_urls, name='get_temp_urls'),
path('select_temp_urls', views.select_temp_urls, name='select_temp_urls'),
path('get_content', views.FolderContentView.as_view(), name='get_content'),
path('get_temp_file', views.TempDownloadView.as_view(), name='get_temp_file'),
path('get_temp_file_metadata', views.get_ncfile_metadata, name='get_ncfile_metadata'),
path('access_tif', views.access_tif_from_ncfile, name="access_tif"),
]

urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json'])
Loading

0 comments on commit eb04e2a

Please sign in to comment.