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
8e4e9322
Commit
8e4e9322
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Simplify conversion from NetCDF to multiband GeoTIFF
parent
93394c81
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SEPTREFHUM.py
+6
-11
6 additions, 11 deletions
SEPTREFHUM.py
with
6 additions
and
11 deletions
SEPTREFHUM.py
+
6
−
11
View file @
8e4e9322
...
@@ -108,19 +108,14 @@ for timestep in timesteps:
...
@@ -108,19 +108,14 @@ for timestep in timesteps:
timestep_dates
.
append
(
file_date
)
timestep_dates
.
append
(
file_date
)
# Create NetCDF result file
# 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
)
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
# Convert to GeoTIFF
subprocess
.
run
(
"
gdal_translate -of GTiff -sds %sresult_%s.nc %stmp.tif
"
%
(
tmpfile_path
,
file_date
,
tmpfile_path
)
,
shell
=
True
)
# The variables are: 1 = time_bnds, 2= lon, 3= lat, 4= WHS, 5 = WARNING_STATUS
# We only need WHS and WARNING_STATUS
# We only need WHS and WARNING_STATUS
# Merge the WARNING_STATUS and WHS GeoTIFF files into one file with two bands.
The WARNING_STATUS should always be
# Merge the WARNING_STATUS and WHS GeoTIFF files into one file with two bands.
#
B
and #1
#
The WARNING_STATUS should always be b
and #1
subprocess
.
run
(
"
gdal_merge.py -separate -o
%sresult_%s.tif %stmp_5.tif %stmp_4.tif
"
%
(
outfile_path
,
file_date
,
tmpfile_path
,
tmp
file_
p
at
h
)
,
shell
=
True
)
subprocess
.
run
(
f
'
gdal_merge.py -separate -o
{
outfile_path
}
result_
{
file_date
}
.tif NETCDF:
"
{
tmpfile_path
}
result_
{
file_date
}
.nc
"
:WARNING_STATUS NETCDF:
"
{
tmpfile_path
}
result_
{
file_
d
at
e
}
.nc
"
:WHS
'
,
shell
=
True
)
subprocess
.
run
(
"
rm %stmp_*.tif
"
%
tmpfile_path
,
shell
=
True
)
timestep_index
=
timestep_index
+
1
timestep_index
=
timestep_index
+
1
# Generate mapfile
# Generate mapfile
env
=
Environment
(
loader
=
FileSystemLoader
(
'
.
'
))
env
=
Environment
(
loader
=
FileSystemLoader
(
'
.
'
))
template
=
env
.
get_template
(
"
mapfile/template.j2
"
)
template
=
env
.
get_template
(
"
mapfile/template.j2
"
)
...
@@ -132,4 +127,4 @@ with open("mapfile/SEPTREFHUM.map", 'w') as f:
...
@@ -132,4 +127,4 @@ with open("mapfile/SEPTREFHUM.map", 'w') as f:
# Remove all temporary/intermediary files
# Remove all temporary/intermediary files
subprocess
.
run
(
"
rm %s*
"
%
tmpfile_path
,
shell
=
True
)
subprocess
.
run
(
f
"
rm
{
tmpfile_path
}
*
"
,
shell
=
True
)
\ No newline at end of file
\ 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