... | ... | @@ -10,7 +10,7 @@ In order to model the hydrodynamics of a region with SLIM, forcing data need be |
|
|
|
|
|
## Python script
|
|
|
|
|
|
### Hydro
|
|
|
### Hydrodynamics
|
|
|
|
|
|
Useful imports
|
|
|
|
... | ... | @@ -36,14 +36,14 @@ Partition the mesh and store it |
|
|
Import mesh info in python
|
|
|
|
|
|
```python
|
|
|
mesh = slimPre.Mesh(mesh_file_name, mesh_proj='+proj=utm +ellps=WGS84 +zone=17')
|
|
|
mesh = slimPre.Mesh(mesh_file_name, mesh_proj='+proj=utm +ellps=WGS84 +zone=17 +north')
|
|
|
```
|
|
|
|
|
|
Get a specific region of the mesh
|
|
|
|
|
|
```python
|
|
|
region_global = slimPre.Region(mesh)
|
|
|
region_open = slimPre.Region(mesh, physical_tags=['mexico', 'atlantic'])
|
|
|
region_open = slimPre.Region(mesh, physical_tags=['mexico', 'atlantic_north', 'atlantic_east'])
|
|
|
```
|
|
|
|
|
|
Format the bathymetry, from *.tif* to *.nc*
|
... | ... | @@ -53,8 +53,7 @@ Format the bathymetry, from *.tif* to *.nc* |
|
|
bath = slimPre.geo_tiff(bath_tiff).evaluate_region(region_global)
|
|
|
bath = np.abs(bath) # convention differs from QGIS to SLIM
|
|
|
bath[bath<2] = 2 # avoid negative water depths
|
|
|
slimPre.write_file(data_dir+'bathymetry.nc', region=region_global,
|
|
|
time=None, data=[('bathymetry', bath)])
|
|
|
slimPre.write_file(data_dir+'bathymetry.nc', region=region_global, time=None, data=[('bathymetry', bath)])
|
|
|
```
|
|
|
|
|
|
Smooth the bathymetry to remove features at unresolved scales
|
... | ... | @@ -92,18 +91,49 @@ Create simple space independent wind forcing |
|
|
Generate tidal open boundary conditions (from TOPEX/Poseidon TPXO 7.2)
|
|
|
|
|
|
```python
|
|
|
final_time = '2016-01-17 00:00:00'
|
|
|
final_time = '2016-01-10 00:00:00'
|
|
|
time_tpxo = slimPre.Time(initial_time=init_time,
|
|
|
final_time=final_time, time_step=900.)
|
|
|
slimPre.tpxo_tide(region_open, time_tpxo, data_file_name=data_dir+'open_bnd.nc')
|
|
|
(ssh_tide, ux_tide, uy_tide) = slimPre.tpxo_tide(region_open, time_tpxo, data_file_name=data_dir+'open_bnd.nc')
|
|
|
```
|
|
|
|
|
|
Exit properly
|
|
|
#### More complicated data structure (HYCOM, wind, ...)
|
|
|
|
|
|
In order to include more complicated data structures in SLIM, such as HYCOM model output, no easy slim module exists. You need to extract data value for each node (or boundary node). The time steps for data values do not have to be the same as the one for the simulation (a temporal linear interpolation will be done at runtime).
|
|
|
|
|
|
Here is an example to get the sea surface height from a netCDF file produced by HYCOM.
|
|
|
|
|
|
```python
|
|
|
slimPre.exit(0)
|
|
|
from netCDF4 import Dataset
|
|
|
f = Dataset("ssh.nc4","r")
|
|
|
ssh = np.array(f.variables["surf_el"][0,:])
|
|
|
ssh[ssh<-20000] = 0 # dumb way to deal with missing values
|
|
|
lon = np.array(f.variables["lon"][:])
|
|
|
lat = np.array(f.variables["lat"][:])
|
|
|
|
|
|
region_open_lonlat = slimPre.Coordinate_system(region_open, data_proj='+proj=latlong +ellps=WGS84')
|
|
|
lonlat_open_deg = region_open_lonlat.coordinates * 180./np.pi
|
|
|
|
|
|
SSH = slimPre.interpolate_from_structured_grid(lonlat_open_deg[:,0]+360., lonlat_open_deg[:,1], lon[0], lat[0], lon[1]-lon[0], lat[1]-lat[0], ssh, fill_value=0)
|
|
|
|
|
|
slimPre.write_file(pre_data_dir+'hycom.nc', region=region_open, time=None, data=[('ssh', SSH)])
|
|
|
|
|
|
f.close()
|
|
|
```
|
|
|
|
|
|
The HYCOM data are now converted to SLIM netCDF format. As the data are produced on the same `Region` as TPXO, one can decide to simply add the sea surface height of HYCOM on top of the sea surface height of each time step of TPXO.
|
|
|
|
|
|
```python
|
|
|
hycom_plus_tide = np.copy(ssh_tide)
|
|
|
|
|
|
for i in range(len(time_tpxo._time)):
|
|
|
hycom_plus_tide[i,:] = SSH[:] + ssh_tide[i,:]
|
|
|
|
|
|
slimPre.write_file(pre_data_dir+'hycomAndTide.nc', region=region_open, time=time_tpxo, data=[('ssh', hycom_plus_tide)])
|
|
|
```
|
|
|
|
|
|
It can become harder if two data sources do not share the same time steps. For 3D HYCOM velocity, one needs to perform a weighted sum over each vertical cell to get the 2D transport. This goes beyond the scope of this introduction.
|
|
|
|
|
|
### Tracer
|
|
|
|
|
|
Create the initial conditions for the Tracer equation
|
... | ... | @@ -117,4 +147,18 @@ Set the value at the open boundaries |
|
|
```python
|
|
|
slimPre.write_file(data_dir+'concentration_mexico.nc', region=None, time=None, data=[('tracer',1.)])
|
|
|
slimPre.write_file(data_dir+'concentration_atlantic.nc', region=None, time=None, data=[('tracer',0.)])
|
|
|
```
|
|
|
|
|
|
Exit properly
|
|
|
|
|
|
```python
|
|
|
slimPre.exit(0)
|
|
|
```
|
|
|
|
|
|
## Command line
|
|
|
|
|
|
Run the preprocessing script by introducing the following command line
|
|
|
|
|
|
```bash
|
|
|
slim prepro.py
|
|
|
``` |
|
|
\ No newline at end of file |