-
Notifications
You must be signed in to change notification settings - Fork 4
Examples
Before using alphaBetaLab to generate the alpha and beta coefficients on regular meshes for WW3, the modeller needs to generate the mesh configuration files with the GRIDGEN package.
An example of script running alphaBetaLab on regular grids can be found in /alphaBetaLabGitRepo/examples/ww3/regularMesh/bathyAndObstructionsCaribbean/obstFileBuilder.py
From a global domain, this example estimates the UOST parameters on a subdomain covering the Caribbean sea.
The first line of such script imports the module numpy for vector computation:
import numpy as np
The subsequent 2 lines import the components of alphaBetaLab used in this example:
from alphaBetaLab.abOptionManager import abOptions
from alphaBetaLab.abEstimateAndSave import abEstimateAndSaveRegularEtopo1, regularGridSpecWW3
Follows the definition of the spectral mesh:
dirs = np.linspace(0, 2*np.pi, 25)
nfreq = 25
minfrq = .04118
frqfactor = 1.1
freqs = [minfrq*(frqfactor**i) for i in range(1,nfreq + 1)]
These parameters must be equal to the ones used generating the mesh configuration files with the GRIDGEN package. Then the spatial grid is defined:
gridname = 'g_glb150'
maskFilePath = gridname + '.mask'
regularGridSpec = regularGridSpecWW3(
xmin= -180, ymin=-70,
dx=1.5, dy=1.5,
nx=240, ny=94,
maskFilePath=maskFilePath)
where maskFilePath is the path to the mask file generated by GRIDGEN. The bathymetry file path is defined:
etopoFilePath = '/mypath/gridgen1.1/reference_data/etopo1.nc'
The output directory is selected:
outputDestDir = './output/'
The number of cores for parallelization is defined:
nParWorker = 32
In this example only the part of the domain on the Caribbean is considered. The limits of such subdomain are defined with the instructions
llcrnr = [-100, 5]
urcrnr = [-55, 30]
where llcrnr is the low-left corner, urcrnr is the up-right corner.
The options object with the subdomain is created. This step is optional: if no option is provided to the algorithm, the default parameters will be used on the whole domain.
opt = abOptions(llcrnr=llcrnr, urcrnr=urcrnr)
The final instruction launches the algorithm and saves the output files
abEstimateAndSaveRegularEtopo1(dirs, freqs, gridname, regularGridSpec, etopoFilePath, outputDestDir, nParWorker, opt)
To launch the elaboration the user should use the console commands:
$ cd /alphaBetaLabGitRepo/examples/ww3/regularMesh/bathyAndObstructionsCaribbean/
$ /myminiconda/bin/python obstFileBuilder.py
where /myminiconda/bin/python is the python instance where alphaBetaLab is installed (see the installation guide).
The elaboration of this example should take a few minutes on a 12-core workstation. At the end, the output files obstructions_local.g_glb150.in and obstructions_shadow.g_glb150.in should be found in the directory ./output/ defined above.
A similar (slower) example can be found in /alphaBetaLabGitRepo/examples/ww3/regularMesh/bathyAndObstructionsGlobal/obstFileBuilder.py, that estimates the UOST parameters for the whole global domain.
An example script to run WW3 (version 6.x) with UOST using the obstruction files created above is available in /alphaBetaLabGitRepo/examples/ww3/regularMesh/wwiiiRunCFSR .
Before using alphaBetaLab to generate the alpha and beta coefficients on triangular meshes, the modeller needs to generate the msh file using a mesher, like polymesh, gmesh, OceanMesh2D or others.
An example of script running alphaBetaLab on triangular meshes can be found in /alphaBetaLabGitRepo/examples/ww3/triangularMesh/bathyAndObstructions/obstFileBuilder.py
As for the previous example, the first lines are dedicated to importing into the script the needed components of alphaBetaLab and other libraries:
import numpy as np
from alphaBetaLab.abOptionManager import abOptions
from alphaBetaLab.abEstimateAndSave import triMeshSpecFromMshFile, abEstimateAndSaveTriangularEtopo1
The spectral grid is then defined
dirs = np.linspace(0, 2*np.pi, 25)
nfreq = 25
minfrq = .04118
frqfactor = 1.1
freqs = [minfrq*(frqfactor**i) for i in range(1,nfreq + 1)]
The mesh is defined instantiating a triangular mesh object, which loads the specifications from a msh file:
gridname = 'ww3'
mshfile = 'med.msh'
triMeshSpec = triMeshSpecFromMshFile(mshfile)
The path of the bathymetry file is set:
etopoFilePath = '/mypath/gridgen1.1/reference_data/etopo1.nc'
The output directory is assigned:
outputDestDir = './output/'
The number of cores for running parallel is defined:
nParWorker = 32
The options object is instantiated, with a parameter indicating the minimum size of the cells that should be considered:
minSizeKm = 3
opt = abOptions(minSizeKm=minSizeKm)
Such small cells are discarded in this example, as they would require too small a global time step to be adequately estimated in WW3, and their inclusion would slow down the computations of alphaBetaLab.
Finally, the instruction to perform the computation and save the output is given:
abEstimateAndSaveTriangularEtopo1(dirs, freqs, gridname, triMeshSpec, etopoFilePath, outputDestDir, nParWorker)
To launch the elaboration the user should use the console commands:
$ cd /alphaBetaLabGitRepo/examples/ww3/triangularMesh/bathyAndObstructions/
$ /myminiconda/bin/python obstFileBuilder.py
where /myminiconda/bin/python is the python instance where alphaBetaLab is installed (see the installation guide).
At the end of the elaboration, which may require some minutes, the output files obstructions_local.ww3.in and obstructions_shadow.ww3.in should be found in the directory ./output/ defined above.
An example script to run WW3 (version 6.x) with UOST using the obstruction files created above is available in /alphaBetaLabGitRepo/examples/ww3/triangularMesh/wwiiiRunCFSR .