Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grid SEPTREFHUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
Models
GRID
Grid SEPTREFHUM
Commits
5e1f7cb3
Commit
5e1f7cb3
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Generate mapfile using Jinja2
parent
364d1dfb
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
README.md
+0
-1
0 additions, 1 deletion
README.md
SEPTREFHUM.py
+14
-2
14 additions, 2 deletions
SEPTREFHUM.py
mapfile/template.j2
+130
-0
130 additions, 0 deletions
mapfile/template.j2
with
146 additions
and
4 deletions
.gitignore
+
2
−
1
View file @
5e1f7cb3
*.nc
*.tif
*.tif.aux.xml
\ No newline at end of file
*.tif.aux.xml
mapfile/SEPTREFHUM.map
This diff is collapsed.
Click to expand it.
README.md
+
0
−
1
View file @
5e1f7cb3
...
...
@@ -54,4 +54,3 @@ gdal_merge.py -separate in/test_3.tif in/test_4.tif in/test_5.tif in/test_6.tif
**Could we live with x GeoTIFF files per timestamp, where x is the number of variables?**
###
\ No newline at end of file
This diff is collapsed.
Click to expand it.
SEPTREFHUM.py
+
14
−
2
View file @
5e1f7cb3
...
...
@@ -7,6 +7,7 @@
import
subprocess
,
glob
from
datetime
import
datetime
,
timezone
from
jinja2
import
Environment
,
FileSystemLoader
import
pytz
import
netCDF4
as
nc
...
...
@@ -100,9 +101,11 @@ subprocess.run('cdo -aexpr,"WARNING_STATUS = WHS < 20 ? 2 : -1; WARNING_STATUS =
wh_3daysum
=
nc
.
Dataset
(
'
%swh_3daysum.nc
'
%
tmpfile_path
,
'
r
'
)
timesteps
=
wh_3daysum
.
variables
[
"
time
"
][:]
timestep_index
=
1
timestep_dates
=
[]
# Used in the mapfile template
for
timestep
in
timesteps
:
timestep_date
=
datetime
.
fromtimestamp
(
timestep
)
file_date
=
timestep_date
.
astimezone
(
local_timezone
).
strftime
(
"
%Y-%m-%d
"
)
timestep_dates
.
append
(
file_date
)
# Create NetCDF result file
subprocess
.
run
(
'
cdo -seltimestep,%s/%s %sresult.nc %sresult_%s.nc
'
%
(
timestep_index
,
timestep_index
,
tmpfile_path
,
tmpfile_path
,
file_date
),
shell
=
True
)
# Split all variables into separate GeoTIFF files, using GDAL
...
...
@@ -116,8 +119,17 @@ for timestep in timesteps:
timestep_index
=
timestep_index
+
1
# Remove all temporary/intermediary files
subprocess
.
run
(
"
rm %s*
"
%
tmpfile_path
,
shell
=
True
)
# Generate mapfile
env
=
Environment
(
loader
=
FileSystemLoader
(
'
.
'
))
template
=
env
.
get_template
(
"
mapfile/template.j2
"
)
output
=
template
.
render
({
"
timestep_dates
"
:
timestep_dates
})
with
open
(
"
mapfile/SEPTREFHUM.map
"
,
'
w
'
)
as
f
:
f
.
write
(
output
)
# Remove all temporary/intermediary files
subprocess
.
run
(
"
rm %s*
"
%
tmpfile_path
,
shell
=
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mapfile/template.j2
0 → 100644
+
130
−
0
View file @
5e1f7cb3
MAP
NAME "VIPS Spatial models SEPTREFHUM"
# UTM33
EXTENT -75000 6450000 1120000 8000000
UNITS METERS
MAXSIZE 5120
CONFIG "MS_ERRORFILE" "/disks/data01/mapserver/log/SEPTREFHUM.log"
# Projection is UTM33
PROJECTION
"init=epsg:25833"
END
WEB
TEMPLATE "/disks/data01/mapserver/wms/SEPTREFHUM/query_template_SEPTREFHUM.html"
IMAGEPATH "/disks/data01/mapserver/tmp/"
IMAGEURL "/tmp/"
METADATA
"wms_keywordlist" "VIPS model Septoria Reference Humidity Model (SEPTREFHUM)"
"wms_abstract" "VIPS model SEPTREFHUM"
"wms_enable_request" "*"
"wms_title" "VIPS model SEPTREFHUM"
"wms_onlineresource" "https://testvips.nibio.no/cgi-bin/SEPTREFHUM"
"wms_getfeatureinfo_formatlist" "text/plain,text/html,text/xml"
"wms_accessconstraints" "none"
"wms_addresstype" ""
"wms_address" "Høgskoleveien 7"
"wms_city" "Ås"
"wms_stateorprovince" "Ås"
"wms_postcode" "1430"
"wms_country" "Norway"
"wms_contactelectronicmailaddress" "vips@nibio.no"
"wms_feature_info_mime_type" "text/html"
"wms_contactperson" "Berit Nordskog"
"wms_contactposition" "owner"
"wms_contactorganization" "Norsk institutt for bioøkonomi (NIBIO)"
END
END #web
############################# Start of legend #########################################################
# The legend configuration uses the CLASSITEM information in each layer to generate colour icons and labels
LEGEND
STATUS ON
KEYSIZE 16 12
LABEL
TYPE TRUETYPE
SIZE 10
COLOR 0 0 0
OFFSET 0 -3
END
END
{% for timestep_date in timestep_dates %}
LAYER
NAME "SEPTREFHUM.WARNING_STATUS {{ timestep_date }}"
DATA "/disks/data01/mapserver/data/SEPTREFHUM/result_{{ timestep_date }}.tif"
TYPE RASTER
PROCESSING "BANDS=1"
STATUS ON
METADATA
"wms_title" "Reference humidity model {{ timestep_date }}"
END
CLASSITEM "[pixel]"
# class using simple string comparison, equivalent to ([pixel] = 0)
CLASS
NAME "Varsel ferdig"
EXPRESSION ([pixel] < 1)
STYLE
COLOR 160 160 160
END
END
CLASS
NAME "Data mangler"
EXPRESSION ([pixel] >= 1 AND [pixel] < 2)
STYLE
COLOR 0 102 255
END
END
CLASS
NAME "Ingen risiko"
EXPRESSION ([pixel] >= 2 AND [pixel] < 3)
STYLE
COLOR 51 204 51
END
END
CLASS
NAME "Mulig risiko"
EXPRESSION ([pixel] >= 3 AND [pixel] < 4)
STYLE
COLOR 255 204 0
END
END
CLASS
NAME "Høy risiko"
EXPRESSION ([pixel] >= 4)
STYLE
COLOR 255 0 0
END
END
END # Layer
LAYER
NAME "SEPTREFHUM.WH {{ timestep_date }}"
DATA "/disks/data01/mapserver/data/SEPTREFHUM/result_{{ timestep_date }}.tif"
TYPE RASTER
PROCESSING "BANDS=2"
PROCESSING "SCALE=AUTO"
STATUS ON
METADATA
"wms_title" "Reference humidity model WHS {{ timestep_date }}"
END
CLASSITEM "[pixel]"
END # Layer
{% endfor %}
END #map
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment