|
|
# Preprocessing the data
|
|
|
|
|
|
In order to model the hydrodynamics of a region with SLIM, forcing data need be converted to SLIM-specific data format. Commonly used data, such as TPXO tidal model output, are easily handled with, while other data may need specific treatment. Hereafter, some useful data and their webpages are listed, and an example of a script converting all necessary data is detailed.
|
|
|
|
|
|
## Download
|
|
|
|
|
|
- HYCOM [https://hycom.org/]
|
|
|
- velocity [http://ncss.hycom.org/thredds/ncss/grid/GLBu0.08/expt_91.2/uv3z/dataset.html]
|
|
|
- surface elevation [http://ncss.hycom.org/thredds/ncss/grid/GLBu0.08/expt_91.2/ssh/dataset.html]
|
|
|
|
|
|
## Python script
|
|
|
|
|
|
### Hydro
|
|
|
|
|
|
Useful imports
|
|
|
|
|
|
```python
|
|
|
import slimPre
|
|
|
import numpy as np
|
|
|
```
|
|
|
|
|
|
SLIM uses MPI to run efficiently on several cores. The following command states that each partition data is stored in a different folder
|
|
|
|
|
|
```python
|
|
|
data_dir_base = 'data_'+slimPre.partition_nb()+'/'
|
|
|
data_dir = data_dir_base+slimPre.partition_id()+'/'
|
|
|
slimPre.make_directory(data_dir)
|
|
|
```
|
|
|
|
|
|
Partition the mesh and store it
|
|
|
|
|
|
```python
|
|
|
mesh_file_name = slimPre.partition_mesh('bahamas.msh', data_dir+"mesh.msh")
|
|
|
```
|
|
|
|
|
|
Import mesh info in python
|
|
|
|
|
|
```python
|
|
|
mesh = slimPre.Mesh(mesh_file_name, mesh_proj='+proj=utm +ellps=WGS84 +zone=17')
|
|
|
```
|
|
|
|
|
|
Get a specific region of the mesh
|
|
|
|
|
|
```python
|
|
|
region_global = slimPre.Region(mesh)
|
|
|
region_open = slimPre.Region(mesh, physical_tags=['mexico', 'atlantic'])
|
|
|
```
|
|
|
|
|
|
Format the bathymetry, from *.tif* to *.nc*
|
|
|
|
|
|
```python
|
|
|
bath_tiff = '../etopo.tif'
|
|
|
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)])
|
|
|
```
|
|
|
|
|
|
Smooth the bathymetry to remove features at unresolved scales
|
|
|
|
|
|
```python
|
|
|
slimPre.smooth_bathymetry(mesh, (data_dir+'bathymetry.nc','bathymetry'), output_file_name=data_dir_base+'bathymetry_smooth', coefficient=0.5)
|
|
|
```
|
|
|
|
|
|
Compute the coriolis parameter $`f=2\Omega \sin \phi`$ (where $`\Omega`$ is the rotation rate of the Earth and $`\phi`$ is the latitude)
|
|
|
|
|
|
```python
|
|
|
region_global_lonlat = slimPre.Coordinate_system(region_global, data_proj='+proj=latlong +ellps=WGS84')
|
|
|
lonlat = region_global_lonlat.coordinates
|
|
|
corio = 2 * 7.292e-5 * np.sin(lonlat[:,1])
|
|
|
slimPre.write_file(data_dir+'coriolis.nc', region=region_global, time=None, data=[('coriolis', corio)])
|
|
|
```
|
|
|
|
|
|
Create a file with the gravity (in case of extraterrestrial model)
|
|
|
|
|
|
```python
|
|
|
slimPre.write_file(data_dir+'gravity.nc', region=None, time=None, data=[('gravity', 9.81)])
|
|
|
```
|
|
|
|
|
|
Create simple space independent wind forcing
|
|
|
|
|
|
```python
|
|
|
t = [3600*j for j in range(3)] # t = [0, 3600, 7200]
|
|
|
init_time = '2016-01-01 00:00:00'
|
|
|
time = slimPre.Time(time_vector=t, initial_time=init_time)
|
|
|
windEast = [-5.7, -6.5, -4.2]
|
|
|
windNorth = [0, 1.4, 4.1]
|
|
|
slimPre.write_file(data_dir+'wind.nc', region=None, time=time, data=[('wind_east', windEast), ('wind_north', windNorth)])
|
|
|
```
|
|
|
|
|
|
Generate tidal open boundary conditions (from TOPEX/Poseidon TPXO 7.2)
|
|
|
|
|
|
```python
|
|
|
final_time = '2016-01-17 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')
|
|
|
```
|
|
|
|
|
|
Exit properly
|
|
|
|
|
|
```python
|
|
|
slimPre.exit(0)
|
|
|
```
|
|
|
|
|
|
### Tracer
|
|
|
|
|
|
Create the initial conditions for the Tracer equation
|
|
|
|
|
|
```python
|
|
|
slimPre.write_file(data_dir+'init_tracer.nc', region=None, time=None, data=[('tracer', 0.)])
|
|
|
```
|
|
|
|
|
|
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.)])
|
|
|
``` |
|
|
\ No newline at end of file |