Skip to content

Commit

Permalink
Merge pull request #83 from ccht-ncsu/new_clumping_fx
Browse files Browse the repository at this point in the history
added new clumping function to deal with levees
  • Loading branch information
tomas19 authored Aug 22, 2023
2 parents b841914 + 335af98 commit 18109e6
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 117 deletions.
1 change: 1 addition & 0 deletions adds/levees_louisiana/louisiana-levees-lines.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added adds/levees_louisiana/louisiana-levees-lines.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions adds/levees_louisiana/louisiana-levees-lines.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file added adds/levees_louisiana/louisiana-levees-lines.shp
Binary file not shown.
Binary file added adds/levees_louisiana/louisiana-levees-lines.shx
Binary file not shown.
25 changes: 25 additions & 0 deletions adds/levees_louisiana/louisiana-levees-lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
========================================================================
Louisiana Levees - Lines
------------------------------------------------------------------------
https://koordinates.com/layer/20449-louisiana-levees-lines/
========================================================================
From: US National Oceanic and Atmospheric Administration (NOAA)

Region: Louisiana

CRS: WGS 84

------------------------------------------------------------------------
Processing steps applied by Koordinates
------------------------------------------------------------------------

- imported to Koordinates in Esri JSON format on 30 Aug 2016
- reprojected from WGS 84 / Pseudo-Mercator to WGS 84
- converted by Koordinates to Shapefile on 27 Jun 2022 (reference #2537192)

====================
No license specified
====================

No license was specified for this layer. This could mean default rights under copyright law for your legal jurisdiction may apply. Please check with Koordinates if you're unsure of your right to access and use this layer.

13 changes: 6 additions & 7 deletions examples/downscaling_example01.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
## first step is to add the github repo to the path, so functions can be imported
#import sys
#sys.path.append(r'/rsstu/users/j/jcdietri/DHS-CRCoE-2016-2020/tacuevas/github/Kalpana')
## in this case is not necessary since the module is in the same folder
import os
from kalpana.downscaling import meshRepLen2raster
import sys
sys.path.append(r'/home/tacuevas/github/Kalpana/kalpana')
from downscaling import meshRepLen2raster

'''
This script creates a grass location importing the DEM for downscaling and also creates
a new DEM with same resolution and extend with the size of the mesh triangles. This step
is key for the downscaling and can be run in advance, since only depends on the mesh.
'''

fort14 = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Docker/downscaling/north_carolina/inputs/fort.14' ## path of the fort.14 file
fort14 = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/downscaling/north_carolina/inputs/fort.14' ## path of the fort.14 file
epsgIn = 4326 ## CRS for lat/lon
epsgOut = 6543 ## projected CRS for NC
pathOut = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Examples_github/example01/NC9.shp' ## full path of the output shapefile
pathOut = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example01_NC/NC9_NCdems_15m.shp' ## full path of the output shapefile
grassVer = 8.2
pathRasFiles = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Docker/downscaling/north_carolina/inputs'
pathRasFiles = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/downscaling/north_carolina/inputs'
rasterFiles = 'ncDEMs_epsg6543'
## in this case we will use the same downscaling raster bounding box as the subdomain

Expand Down
46 changes: 20 additions & 26 deletions examples/downscaling_example02.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/usr/bin/env python
# coding: utf-8

## add github repo to path
#import sys
#sys.path.append(r'/rsstu/users/j/jcdietri/DHS-CRCoE-2016-2020/tacuevas/github/Kalpana')
import os
from kalpana.downscaling import runStatic

import sys
sys.path.append(r'/home/tacuevas/github/Kalpana/kalpana')
from downscaling import runStatic
'''
Example for doing the static downscaling using an existing grass location, and importing
the DEM with the mesh elements size. Both inputs were created in the example_01.
Expand All @@ -16,24 +11,24 @@


## full path of the maxele file
ncFile = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Docker/inputs/maxele.63.nc'
ncFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/inputs/maxele.63.nc'
## contour levels to use in the downscaling
## from 0 to 11 (included) every 1
levels = [0, 11, 1]
levels = [0,20, 1]
## output CRS
epsgOut = 6543
## full path for the shape file with the maxele contours
## same path is used for saving rasters and the grass location
pathOut = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Examples_github/example02/maxele_florence.shp'
pathOut = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example02_NC/maxele_florence.shp'
## version of grass 8.2 and 8.3 works
grassVer = 8.2
## path of the downscaling rasters
pathRasFiles = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Docker/downscaling/north_carolina/inputs'
pathRasFiles = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/downscaling/north_carolina/inputs'
## rasters filenames, can be a list if more than one.
## 'all' for importing ALL THE FILES in pathRasFiles
rasterFiles = 'ncDEMs_epsg6543'
## full path of the raster with the mesh element size
meshFile = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Examples_github/example01/NC9.tif'
meshFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example01_NC/NC9_NCdems_15m.tif'
## crs of adcirc output (default value)
epsgIn = 4326
## vertical unit of the maxele
Expand All @@ -49,20 +44,20 @@
subDomain = os.path.join(pathRasFiles, rasterFiles)
## epsg code or crs of the subDomain. In this case, as we are using the downscaling dem bounding box
## as the subdomain, the same epsg code must be specified.
epsgSumDom = 6543
epsgSubDom = 6543
## boolean for exporting the mesh as a shape file from maxele, not necessary in this
## case since mesh was exported as preprocess. In example_03 it is exported.
exportMesh = False
## full path of pickle file with vertical datum differences for all mesh nodes
## proprocess step
dzFile = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Docker/downscaling/north_carolina/inputs/NC9mesh_from_tss2navd88.pkl'
dzFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/downscaling/north_carolina/inputs/NC9mesh_from_tss2navd88.pkl'
## threshold to do apply the vertical datum difference, below -20 vyperdatum gives weird
## results
zeroDif = -20
## full path of the grass location if a existing one will be used
## if None a new location called 'grassLoc' is created. A new location is created in
## example_03
nameGrassLocation = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Examples_github/example01/grassLoc'
nameGrassLocation = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example01_NC/grassLoc'
## Boolean for creating grass location, in this example it was created as a preprocess
## step. In example_03 it is created.
createGrassLocation = False
Expand All @@ -77,20 +72,19 @@
compAdcirc2dem = True
## transform the water level to water depth
floodDepth = False
## define clumpling threshold from mesh
clumpThreshold = 'from_mesh'
## percentage of the minimum element area to scale the clumping threshold
perMinElemArea = 1
## export downscaled results as shape files. Slows down the process a couple of minutes
ras2vec = False
## boolean for exporing raw maxele as a DEM. Useful for debugging
exportOrg = False
## full path of the shapefile with levees
leveesFile = None
## boolean for reprojecting the downscaled dem back to lat/lon
finalOutToLatLon = True
finalOutToLatLon = False

#################### calling downscaling
runStatic(ncFile, levels, epsgOut, pathOut, grassVer, pathRasFiles, rasterFiles, meshFile,
epsgIn, vUnitIn, vUnitOut, var, conType, subDomain, epsgSumDom, exportMesh, dzFile,
zeroDif, nameGrassLocation, createGrassLocation, createLocMethod, attrCol, repLenGrowing,
compAdcirc2dem, floodDepth, clumpThreshold, perMinElemArea, ras2vec, exportOrg,
finalOutToLatLon)
runStatic(ncFile, levels, epsgOut, pathOut, grassVer, pathRasFiles, rasterFiles, meshFile, epsgIn=epsgIn,
vUnitIn=vUnitIn, vUnitOut=vUnitOut, var=var, conType =conType, subDomain=subDomain, epsgSubDom=epsgSubDom,
exportMesh= exportMesh, dzFile=dzFile, zeroDif=-zeroDif, nameGrassLocation=nameGrassLocation,
createGrassLocation=createGrassLocation, createLocMethod=createLocMethod, attrCol=attrCol,
repLenGrowing=repLenGrowing, compAdcirc2dem=compAdcirc2dem, floodDepth=floodDepth,
ras2vec=ras2vec, exportOrg=exportOrg, leveesFile = leveesFile, finalOutToLatLon=finalOutToLatLon)
87 changes: 87 additions & 0 deletions examples/downscaling_example02b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import sys
sys.path.append(r'/home/tacuevas/github/Kalpana/kalpana')
from downscaling import runStatic
'''
Idem to example02 but in this case we will use a shapefile with the levee system of
Louisiana
'''

## full path of the maxele file
ncFile = r'/mnt/coe/engr/admin/ccee/Admin/ccee/jcdietri/jcdietri/Projects/2016-2020-DHS-CRCoE/Tomas/AdCirc/Katrina/maxele.63.nc'
## contour levels to use in the downscaling
## from 0 to 11 (included) every 1
levels = [0,10, 1]
## output CRS
epsgOut = 6344
## full path for the shape file with the maxele contours
## same path is used for saving rasters and the grass location
pathOut = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example02_LA/maxele_katrina.shp'
## version of grass 8.2 and 8.3 works
grassVer = 8.2
## path of the downscaling rasters
pathRasFiles = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Data/topobathy/north_gulf_mexico'
## rasters filenames, can be a list if more than one.
## 'all' for importing ALL THE FILES in pathRasFiles
rasterFiles = 'NGMconedRes10m.tif'
## full path of the raster with the mesh element size
meshFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Debug/levees/SL16_NGM_CoNED10m.tif'
## crs of adcirc output (default value)
epsgIn = 4326
## vertical unit of the maxele
vUnitIn = 'm'
## vertical unit of the downscaled water levels
vUnitOut = 'm'
## name of the maxele variable to downscale. Always 'zeta_max' for downscaling
var = 'zeta_max'
## contours type. Always 'polygon' for downscaling
conType = 'polygon'
## full path of file (kml, kmz, shp, gpkg or tif) to crop the domain.
## in this case we will use the same downscaling raster bounding box as the subdomain
subDomain = os.path.join(pathRasFiles, rasterFiles)
## epsg code or crs of the subDomain. In this case, as we are using the downscaling dem bounding box
## as the subdomain, the same epsg code must be specified.
epsgSubDom = 6344
## boolean for exporting the mesh as a shape file from maxele, not necessary in this
## case since mesh was exported as preprocess. In example_03 it is exported.
exportMesh = False
## full path of pickle file with vertical datum differences for all mesh nodes
## proprocess step
dzFile = None
## threshold to do apply the vertical datum difference, below -20 vyperdatum gives weird
## results
zeroDif = -20
## full path of the grass location if a existing one will be used
## if None a new location called 'grassLoc' is created. A new location is created in
## example_03
nameGrassLocation = None
## Boolean for creating grass location, in this example it was created as a preprocess
## step. In example_03 it is created.
createGrassLocation = True
## Method for assigning the crs to the grass location. Default and faster option
createLocMethod = 'from_raster'
## variable to downscale, can be 'zMax', 'zMean' and 'zMin'. With 'zMean', the mean value
## of each contour is used.
attrCol = 'zMean'
## how many times the representative length the results are grown in the downscaling
repLenGrowing = 1.0
## remove wet cells with water level below the ground surface
compAdcirc2dem = True
## transform the water level to water depth
floodDepth = False
## export downscaled results as shape files. Slows down the process a couple of minutes
ras2vec = False
## boolean for exporing raw maxele as a DEM. Useful for debugging
exportOrg = False
## full path of the shapefile with levees
leveesFile = r'/home/tacuevas/github/Kalpana/adds/levees_louisiana/louisiana-levees-lines.shp'
## boolean for reprojecting the downscaled dem back to lat/lon
finalOutToLatLon = False

#################### calling downscaling
runStatic(ncFile, levels, epsgOut, pathOut, grassVer, pathRasFiles, rasterFiles, meshFile, epsgIn=epsgIn,
vUnitIn=vUnitIn, vUnitOut=vUnitOut, var=var, conType =conType, subDomain=subDomain, epsgSubDom=epsgSubDom,
exportMesh= exportMesh, dzFile=dzFile, zeroDif=-zeroDif, nameGrassLocation=nameGrassLocation,
createGrassLocation=createGrassLocation, createLocMethod=createLocMethod, attrCol=attrCol,
repLenGrowing=repLenGrowing, compAdcirc2dem=compAdcirc2dem, floodDepth=floodDepth,
ras2vec=ras2vec, exportOrg=exportOrg, leveesFile = leveesFile, finalOutToLatLon=finalOutToLatLon)
56 changes: 26 additions & 30 deletions examples/downscaling_example03.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
#!/usr/bin/env python
# coding: utf-8

## add github repo to path
#import sys
#sys.path.append(r'/rsstu/users/j/jcdietri/DHS-CRCoE-2016-2020/tacuevas/github/Kalpana')
import os
from kalpana.downscaling import runStatic

# In[1]:

import sys
sys.path.append(r'/home/tacuevas/github/Kalpana/kalpana')
from downscaling import runStatic
'''
This example combine downscaling examples 1 and 2. DEM with mesh elements size and the grass location are created. This should be considerable more slow than running example 2, since creating the inputs for the downscaling is the slower part.
Example for doing the static downscaling using an existing grass location, and importing
the DEM with the mesh elements size. Both inputs were created in the example_01.
There is a short description of all inputs below, more detail can be found in the
docstring of the function in the github repository.
'''


## full path of the maxele file
ncFile = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/inputs_kalpana_github/inputs_interactive/maxele.63.nc'
ncFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/inputs/maxele.63.nc'
## contour levels to use in the downscaling
## from 0 to 11 (included) every 1
levels = [0, 11, 1]
levels = [0,20, 1]
## output CRS
epsgOut = 6543
## full path for the shape file with the maxele contours
## same path is used for saving rasters and the grass location
pathOut = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Examples_github/example03/maxele_florence.shp'
pathOut = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example02_NC/maxele_florence.shp'
## version of grass 8.2 and 8.3 works
grassVer = 8.2
## path of the downscaling rasters
pathRasFiles = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/inputs_kalpana_github/inputs_interactive'
pathRasFiles = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/downscaling/north_carolina/inputs'
## rasters filenames, can be a list if more than one.
## 'all' for importing ALL THE FILES in pathRasFiles
rasterFiles = 'ncDEMs_epsg6543'
## full path to export the mesh shape file
meshFile = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/Kalpana/Examples_github/example03/NC9.shp'
## full path of the raster with the mesh element size
meshFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Examples_github/example03_NC/NC9_NCdems_15m.shp'
## crs of adcirc output (default value)
epsgIn = 4326
## vertical unit of the maxele
Expand All @@ -47,20 +44,20 @@
subDomain = os.path.join(pathRasFiles, rasterFiles)
## epsg code or crs of the subDomain. In this case, as we are using the downscaling dem bounding box
## as the subdomain, the same epsg code must be specified.
epsgSumDom = 6543
epsgSubDom = 6543
## boolean for exporting the mesh as a shape file from maxele, not necessary in this
## case since mesh was exported as preprocess. In example_03 it is exported.
exportMesh = True
## full path of pickle file with vertical datum differences for all mesh nodes
## proprocess step
dzFile = r'/mnt/drive1/GoogleDrive/NCSU/NCSU/inputs_kalpana_github/inputs_interactive/NC9mesh_from_tss2navd88.pkl'
dzFile = r'/mnt/drive1/Insyncs/NCSU/Kalpana/Docker/nonInteractive/downscaling/north_carolina/inputs/NC9mesh_from_tss2navd88.pkl'
## threshold to do apply the vertical datum difference, below -20 vyperdatum gives weird
## results
zeroDif = -20
## full path of the grass location if a existing one will be used
## if None a new location called 'grassLoc' is created. A new location is created in
## example_03
nameGrassLocation = 'grassLoc'
nameGrassLocation = None
## Boolean for creating grass location, in this example it was created as a preprocess
## step. In example_03 it is created.
createGrassLocation = True
Expand All @@ -75,20 +72,19 @@
compAdcirc2dem = True
## transform the water level to water depth
floodDepth = False
## define clumpling threshold from mesh
clumpThreshold = 'from_mesh'
## percentage of the minimum element area to scale the clumping threshold
perMinElemArea = 1
## export downscaled results as shape files. Slows down the process a couple of minutes
ras2vec = False
## boolean for exporing raw maxele as a DEM. Useful for debugging
exportOrg = False
## full path of the shapefile with levees
leveesFile = None
## boolean for reprojecting the downscaled dem back to lat/lon
finalOutToLatLon = True
finalOutToLatLon = False

#################### calling downscaling
runStatic(ncFile, levels, epsgOut, pathOut, grassVer, pathRasFiles, rasterFiles, meshFile,
epsgIn, vUnitIn, vUnitOut, var, conType, subDomain, epsgSumDom, exportMesh, dzFile,
zeroDif, nameGrassLocation, createGrassLocation, createLocMethod, attrCol, repLenGrowing,
compAdcirc2dem, floodDepth, clumpThreshold, perMinElemArea, ras2vec, exportOrg,
finalOutToLatLon)
runStatic(ncFile, levels, epsgOut, pathOut, grassVer, pathRasFiles, rasterFiles, meshFile, epsgIn=epsgIn,
vUnitIn=vUnitIn, vUnitOut=vUnitOut, var=var, conType =conType, subDomain=subDomain, epsgSubDom=epsgSubDom,
exportMesh= exportMesh, dzFile=dzFile, zeroDif=-zeroDif, nameGrassLocation=nameGrassLocation,
createGrassLocation=createGrassLocation, createLocMethod=createLocMethod, attrCol=attrCol,
repLenGrowing=repLenGrowing, compAdcirc2dem=compAdcirc2dem, floodDepth=floodDepth,
ras2vec=ras2vec, exportOrg=exportOrg, leveesFile = leveesFile, finalOutToLatLon=finalOutToLatLon)
Loading

0 comments on commit 18109e6

Please sign in to comment.