4. Generate forcings

Open In Colab

4.1. Install pyTESEO

  • If you are running this notebook from Google colab uncomment and run !pip install pyteseo && pyteseo-tests in the cell below. Doing this you will install pyteseo from pypi repository and run pyteseo-tests to check the installation (all tests have to succeed).

  • If you are using this notebook in your own local machine you need to install the library from the local repo pip install . or pypi pip install pyteseo.

# !pip install pyteseo && pyteseo-tests
import os
import xarray as xr
from datetime import datetime, timedelta
from pyteseo.io.forcings import write_2d_forcing
from pyteseo.wrapper import TeseoWrapper
from pyteseo.connections.cmems import access_global_currents, access_global_winds
from pathlib import Path


username = os.environ.get("CMEMS_username")
password = os.environ.get("CMEMS_password")
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 5
      3 from datetime import datetime, timedelta
      4 from pyteseo.io.forcings import write_2d_forcing
----> 5 from pyteseo.wrapper import TeseoWrapper
      6 from pyteseo.connections.cmems import access_global_currents, access_global_winds
      7 from pathlib import Path

ModuleNotFoundError: No module named 'pyteseo.wrapper'
# Define time range and domain to extract forcings
lon_min = -5.5
lon_max = -1
lat_min = 43.25
lat_max = 44.25

date_ini = datetime(2022, 1, 6)
date_end = date_ini + timedelta(days=3)

bbox = (lon_min, lat_min, lon_max, lat_max)
timebox = (date_ini, date_end)
print(username)
garagon
df_currents = access_global_currents(username, password, bbox, timebox)
df_currents
 garagon login successful! 🙂 
/home/aragong/miniconda3/envs/pyteseo-dev/lib/python3.11/site-packages/pyteseo/connections/cmems.py:163: UserWarning: rename 'time' to 'time' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  return ds.rename({ds_t: standard_t, ds_x: standard_x, ds_y: standard_y})
time lat lon u v
0 0.0 43.166668 -5.583333 NaN NaN
1 0.0 43.166668 -5.500000 NaN NaN
2 0.0 43.166668 -5.416667 NaN NaN
3 0.0 43.166668 -5.333333 NaN NaN
4 0.0 43.166668 -5.250000 NaN NaN
... ... ... ... ... ...
62410 72.0 44.333332 -1.250000 NaN NaN
62411 72.0 44.333332 -1.166667 NaN NaN
62412 72.0 44.333332 -1.083333 NaN NaN
62413 72.0 44.333332 -1.000000 NaN NaN
62414 72.0 44.333332 -0.916667 NaN NaN

62415 rows × 5 columns

df_winds = access_global_winds(username, password, bbox, timebox)
df_winds
 garagon login successful! 🙂 
time lat lon u v
0 0.0 43.1875 -5.5625 0.30 -0.07
1 0.0 43.1875 -5.4375 0.53 -0.29
2 0.0 43.1875 -5.3125 0.54 -0.60
3 0.0 43.1875 -5.1875 0.44 -0.67
4 0.0 43.1875 -5.0625 0.24 -0.49
... ... ... ... ... ...
27735 72.0 44.3125 -1.4375 8.97 -4.60
27736 72.0 44.3125 -1.3125 7.69 -3.76
27737 72.0 44.3125 -1.1875 5.80 -2.47
27738 72.0 44.3125 -1.0625 4.99 -1.76
27739 72.0 44.3125 -0.9375 4.65 -1.32

27740 rows × 5 columns

dir_path = Path("../../tmp/test_simulation")
job = TeseoWrapper(dir_path)
Creating TESEO folder structure...
DONE! Created @ /home/aragong/repositories/pyteseo/tmp/test_simulation
write_2d_forcing(df_currents, job.input_dir, "currents")
write_2d_forcing(df_winds, job.input_dir, "winds")
print([str(path.name) + "\n" for path in Path(job.input_dir).glob("*.*")])
['winds_029h.txt\n', 'winds_030h.txt\n', 'winds_004h.txt\n', 'currents_026h.txt\n', 'winds_031h.txt\n', 'currents_055h.txt\n', 'currents_004h.txt\n', 'winds_021h.txt\n', 'winds_026h.txt\n', 'winds_057h.txt\n', 'winds_027h.txt\n', 'currents_045h.txt\n', 'winds_040h.txt\n', 'currents_020h.txt\n', 'currents_014h.txt\n', 'currents_018h.txt\n', 'currents_058h.txt\n', 'currents_040h.txt\n', 'currents_069h.txt\n', 'currents_029h.txt\n', 'currents_015h.txt\n', 'currents_041h.txt\n', 'lstwinds.pre\n', 'currents_031h.txt\n', 'currents_054h.txt\n', 'winds_063h.txt\n', 'winds_022h.txt\n', 'winds_009h.txt\n', 'winds_058h.txt\n', 'winds_035h.txt\n', 'winds_033h.txt\n', 'currents_049h.txt\n', 'winds_015h.txt\n', 'currents_012h.txt\n', 'currents_032h.txt\n', 'winds_046h.txt\n', 'currents_019h.txt\n', 'winds_006h.txt\n', 'winds_008h.txt\n', 'winds_062h.txt\n', 'currents_035h.txt\n', 'winds_013h.txt\n', 'currents_017h.txt\n', 'winds_028h.txt\n', 'winds_070h.txt\n', 'currents_072h.txt\n', 'winds_041h.txt\n', 'winds_036h.txt\n', 'winds_012h.txt\n', 'winds_003h.txt\n', 'currents_010h.txt\n', 'currents_033h.txt\n', 'currents_005h.txt\n', 'winds_067h.txt\n', 'winds_005h.txt\n', 'currents_028h.txt\n', 'currents_039h.txt\n', 'currents_050h.txt\n', 'winds_049h.txt\n', 'winds_025h.txt\n', 'currents_016h.txt\n', 'winds_066h.txt\n', 'winds_064h.txt\n', 'winds_061h.txt\n', 'currents_046h.txt\n', 'currents_056h.txt\n', 'winds_007h.txt\n', 'currents_001h.txt\n', 'currents_000h.txt\n', 'winds_072h.txt\n', 'winds_034h.txt\n', 'winds_023h.txt\n', 'currents_070h.txt\n', 'winds_039h.txt\n', 'winds_037h.txt\n', 'currents_013h.txt\n', 'winds_044h.txt\n', 'currents_044h.txt\n', 'winds_069h.txt\n', 'winds_068h.txt\n', 'currents_053h.txt\n', 'currents_057h.txt\n', 'winds_016h.txt\n', 'currents_051h.txt\n', 'winds_011h.txt\n', 'currents_061h.txt\n', 'winds_053h.txt\n', 'currents_065h.txt\n', 'winds_052h.txt\n', 'currents_048h.txt\n', 'winds_050h.txt\n', 'winds_059h.txt\n', 'winds_010h.txt\n', 'currents_003h.txt\n', 'winds_051h.txt\n', 'currents_024h.txt\n', 'currents_063h.txt\n', 'currents_043h.txt\n', 'currents_008h.txt\n', 'winds_055h.txt\n', 'winds_071h.txt\n', 'currents_066h.txt\n', 'winds_042h.txt\n', 'currents_023h.txt\n', 'winds_056h.txt\n', 'currents_027h.txt\n', 'currents_071h.txt\n', 'currents_059h.txt\n', 'currents_036h.txt\n', 'currents_025h.txt\n', 'winds_043h.txt\n', 'currents_068h.txt\n', 'winds_032h.txt\n', 'winds_020h.txt\n', 'winds_054h.txt\n', 'currents_006h.txt\n', 'winds_014h.txt\n', 'currents_037h.txt\n', 'currents_062h.txt\n', 'currents_052h.txt\n', 'currents_034h.txt\n', 'lstcurr.pre\n', 'winds_045h.txt\n', 'winds_017h.txt\n', 'winds_047h.txt\n', 'winds_001h.txt\n', 'currents_007h.txt\n', 'currents_002h.txt\n', 'winds_065h.txt\n', 'currents_022h.txt\n', 'currents_030h.txt\n', 'currents_042h.txt\n', 'currents_038h.txt\n', 'winds_060h.txt\n', 'winds_019h.txt\n', 'currents_067h.txt\n', 'winds_002h.txt\n', 'currents_021h.txt\n', 'currents_009h.txt\n', 'winds_024h.txt\n', 'winds_000h.txt\n', 'currents_011h.txt\n', 'currents_060h.txt\n', 'currents_047h.txt\n', 'winds_038h.txt\n', 'winds_048h.txt\n', 'currents_064h.txt\n', 'winds_018h.txt\n']