diff --git a/Jupyter_notebooks/1.2-rotated_grids.ipynb b/Jupyter_notebooks/1.2-rotated_grids.ipynb index 9ace309cd1f519f0977b568452fa71f07a45de01..31b19f7ff6d02f55466f9b20c3f8c67356701e8e 100644 --- a/Jupyter_notebooks/1.2-rotated_grids.ipynb +++ b/Jupyter_notebooks/1.2-rotated_grids.ipynb @@ -415,14 +415,14 @@ " rotated_pole |S1 b''\n", "Attributes:\n", " Conventions: CF-1.7\n", - " comment: Generated on marenostrum4
  • Conventions :
    CF-1.7
    comment :
    Generated on marenostrum4
  • " ], "text/plain": [ "\n", @@ -483,7 +483,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 4, @@ -810,7 +810,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 12, @@ -1198,14 +1198,14 @@ " rotated_pole |S1 b''\n", "Attributes:\n", " Conventions: CF-1.7\n", - " comment: Generated on marenostrum4
    • time_bnds
      (time, time_nv)
      datetime64[ns]
      ...
      array([['2021-08-03T00:00:00.000000000', '2021-08-07T00:00:00.000000000']],\n",
      +       "      dtype='datetime64[ns]')
    • O3_all
      (time, lev, rlat, rlon)
      float32
      ...
      units :
      kg/m3
      long_name :
      TRACERS_044
      cell_methods :
      time: maximum (interval: 1hr)
      grid_mapping :
      rotated_pole
      [2282904 values with dtype=float32]
    • rotated_pole
      ()
      |S1
      ...
      grid_mapping_name :
      rotated_latitude_longitude
      grid_north_pole_latitude :
      39.0
      grid_north_pole_longitude :
      -170.0
      array(b'', dtype='|S1')
  • Conventions :
    CF-1.7
    comment :
    Generated on marenostrum4
  • " ], "text/plain": [ "\n", diff --git a/Jupyter_notebooks/1.4-lcc_grids.ipynb b/Jupyter_notebooks/1.4-lcc_grids.ipynb index 1d4a0f25e464fe79303033639adfad9e8c1f5212..3fc752ceb285b6e0bef1ef15c305808af709cbeb 100644 --- a/Jupyter_notebooks/1.4-lcc_grids.ipynb +++ b/Jupyter_notebooks/1.4-lcc_grids.ipynb @@ -410,7 +410,7 @@ " * lev (lev) float32 0.0\n", "Data variables:\n", " pm10 (time, lev, y, x) float32 ...\n", - " Lambert_conformal int32 -2147483647
    • pm10
      (time, lev, y, x)
      float32
      ...
      units :
      kgm-3
      grid_mapping :
      Lambert_conformal
      [9131712 values with dtype=float32]
    • Lambert_conformal
      ()
      int32
      ...
      grid_mapping_name :
      lambert_conformal_conic
      standard_parallel :
      43., 37.
      longitude_of_central_meridian :
      -3
      latitude_of_projection_origin :
      40
      array(-2147483647, dtype=int32)
  • " ], "text/plain": [ "\n", diff --git a/Jupyter_notebooks/1.5-mercator_grids.ipynb b/Jupyter_notebooks/1.5-mercator_grids.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..41550e052d20a4e27ae95a5b3e3b643c44ab142a --- /dev/null +++ b/Jupyter_notebooks/1.5-mercator_grids.ipynb @@ -0,0 +1,1410 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# How to read and write Mercator grids" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from nes import *\n", + "import xarray as xr" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "nc_path_1 = '/gpfs/scratch/bsc32/bsc32538/a4mg/HERMESv3/auxiliar_files/d01/temporal_coords.nc'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Read and write" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Open with xarray" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "#xr.open_dataset(nc_path_1, decode_times=False).drop(['lat_bnds', 'lon_bnds']).to_netcdf('input/mercator_grid_example.nc')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
    \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
    <xarray.Dataset>\n",
    +       "Dimensions:    (time: 1, y: 236, x: 210)\n",
    +       "Coordinates:\n",
    +       "  * time       (time) float64 0.0\n",
    +       "    lat        (y, x) float32 -43.52 -43.52 -43.52 -43.52 ... 49.6 49.6 49.6\n",
    +       "    lon        (y, x) float32 -18.91 -18.46 -18.01 -17.56 ... 74.22 74.67 75.12\n",
    +       "  * x          (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n",
    +       "  * y          (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n",
    +       "Data variables:\n",
    +       "    var_aux    (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0\n",
    +       "    mercator   int32 -2147483647\n",
    +       "    cell_area  (y, x) float32 1.316e+09 1.316e+09 ... 1.051e+09 1.051e+09
    " + ], + "text/plain": [ + "\n", + "Dimensions: (time: 1, y: 236, x: 210)\n", + "Coordinates:\n", + " * time (time) float64 0.0\n", + " lat (y, x) float32 ...\n", + " lon (y, x) float32 ...\n", + " * x (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n", + " * y (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n", + "Data variables:\n", + " var_aux (time, y, x) float32 ...\n", + " mercator int32 ...\n", + " cell_area (y, x) float32 ..." + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "xr.open_dataset('input/mercator_grid_example.nc', decode_times=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Open with NES" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'data': None, 'dimensions': (), 'grid_mapping_name': 'mercator', 'longitude_of_projection_origin': -18.0, 'standard_parallel': -1.5}\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1 = open_netcdf(path='input/mercator_grid_example.nc', info=True)\n", + "nessy_1" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[datetime.datetime(2000, 1, 1, 0, 0)]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.time" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': array([0]), 'units': ''}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.lev" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': masked_array(data=[-1.01014500e+05, -5.10145000e+04, -1.01450000e+03,\n", + " 4.89855000e+04, 9.89855000e+04, 1.48985500e+05,\n", + " 1.98985500e+05, 2.48985500e+05, 2.98985500e+05,\n", + " 3.48985500e+05, 3.98985500e+05, 4.48985500e+05,\n", + " 4.98985500e+05, 5.48985500e+05, 5.98985500e+05,\n", + " 6.48985500e+05, 6.98985500e+05, 7.48985500e+05,\n", + " 7.98985500e+05, 8.48985500e+05, 8.98985500e+05,\n", + " 9.48985500e+05, 9.98985500e+05, 1.04898550e+06,\n", + " 1.09898550e+06, 1.14898550e+06, 1.19898550e+06,\n", + " 1.24898550e+06, 1.29898550e+06, 1.34898550e+06,\n", + " 1.39898550e+06, 1.44898550e+06, 1.49898550e+06,\n", + " 1.54898550e+06, 1.59898550e+06, 1.64898550e+06,\n", + " 1.69898550e+06, 1.74898550e+06, 1.79898550e+06,\n", + " 1.84898550e+06, 1.89898550e+06, 1.94898550e+06,\n", + " 1.99898550e+06, 2.04898550e+06, 2.09898550e+06,\n", + " 2.14898550e+06, 2.19898550e+06, 2.24898550e+06,\n", + " 2.29898550e+06, 2.34898550e+06, 2.39898550e+06,\n", + " 2.44898550e+06, 2.49898550e+06, 2.54898550e+06,\n", + " 2.59898550e+06, 2.64898550e+06, 2.69898550e+06,\n", + " 2.74898550e+06, 2.79898550e+06, 2.84898550e+06,\n", + " 2.89898550e+06, 2.94898550e+06, 2.99898550e+06,\n", + " 3.04898550e+06, 3.09898550e+06, 3.14898550e+06,\n", + " 3.19898550e+06, 3.24898550e+06, 3.29898550e+06,\n", + " 3.34898550e+06, 3.39898550e+06, 3.44898550e+06,\n", + " 3.49898550e+06, 3.54898550e+06, 3.59898550e+06,\n", + " 3.64898550e+06, 3.69898550e+06, 3.74898550e+06,\n", + " 3.79898550e+06, 3.84898550e+06, 3.89898550e+06,\n", + " 3.94898550e+06, 3.99898550e+06, 4.04898550e+06,\n", + " 4.09898550e+06, 4.14898550e+06, 4.19898550e+06,\n", + " 4.24898550e+06, 4.29898550e+06, 4.34898550e+06,\n", + " 4.39898550e+06, 4.44898550e+06, 4.49898550e+06,\n", + " 4.54898550e+06, 4.59898550e+06, 4.64898550e+06,\n", + " 4.69898550e+06, 4.74898550e+06, 4.79898550e+06,\n", + " 4.84898550e+06, 4.89898550e+06, 4.94898550e+06,\n", + " 4.99898550e+06, 5.04898550e+06, 5.09898550e+06,\n", + " 5.14898550e+06, 5.19898550e+06, 5.24898550e+06,\n", + " 5.29898550e+06, 5.34898550e+06, 5.39898550e+06,\n", + " 5.44898550e+06, 5.49898550e+06, 5.54898550e+06,\n", + " 5.59898550e+06, 5.64898550e+06, 5.69898550e+06,\n", + " 5.74898550e+06, 5.79898550e+06, 5.84898550e+06,\n", + " 5.89898550e+06, 5.94898550e+06, 5.99898550e+06,\n", + " 6.04898550e+06, 6.09898550e+06, 6.14898550e+06,\n", + " 6.19898550e+06, 6.24898550e+06, 6.29898550e+06,\n", + " 6.34898550e+06, 6.39898550e+06, 6.44898550e+06,\n", + " 6.49898550e+06, 6.54898550e+06, 6.59898550e+06,\n", + " 6.64898550e+06, 6.69898550e+06, 6.74898550e+06,\n", + " 6.79898550e+06, 6.84898550e+06, 6.89898550e+06,\n", + " 6.94898550e+06, 6.99898550e+06, 7.04898550e+06,\n", + " 7.09898550e+06, 7.14898550e+06, 7.19898550e+06,\n", + " 7.24898550e+06, 7.29898550e+06, 7.34898550e+06,\n", + " 7.39898550e+06, 7.44898550e+06, 7.49898550e+06,\n", + " 7.54898550e+06, 7.59898550e+06, 7.64898550e+06,\n", + " 7.69898550e+06, 7.74898550e+06, 7.79898550e+06,\n", + " 7.84898550e+06, 7.89898550e+06, 7.94898550e+06,\n", + " 7.99898550e+06, 8.04898550e+06, 8.09898550e+06,\n", + " 8.14898550e+06, 8.19898550e+06, 8.24898550e+06,\n", + " 8.29898550e+06, 8.34898550e+06, 8.39898550e+06,\n", + " 8.44898550e+06, 8.49898550e+06, 8.54898550e+06,\n", + " 8.59898550e+06, 8.64898550e+06, 8.69898550e+06,\n", + " 8.74898550e+06, 8.79898550e+06, 8.84898550e+06,\n", + " 8.89898550e+06, 8.94898550e+06, 8.99898550e+06,\n", + " 9.04898550e+06, 9.09898550e+06, 9.14898550e+06,\n", + " 9.19898550e+06, 9.24898550e+06, 9.29898550e+06,\n", + " 9.34898550e+06, 9.39898550e+06, 9.44898550e+06,\n", + " 9.49898550e+06, 9.54898550e+06, 9.59898550e+06,\n", + " 9.64898550e+06, 9.69898550e+06, 9.74898550e+06,\n", + " 9.79898550e+06, 9.84898550e+06, 9.89898550e+06,\n", + " 9.94898550e+06, 9.99898550e+06, 1.00489855e+07,\n", + " 1.00989855e+07, 1.01489855e+07, 1.01989855e+07,\n", + " 1.02489855e+07, 1.02989855e+07, 1.03489855e+07],\n", + " mask=False,\n", + " fill_value=1e+20),\n", + " 'dimensions': ('x',),\n", + " 'units': '1000 m',\n", + " 'long_name': 'x coordinate of projection',\n", + " 'standard_name': 'projection_x_coordinate'}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.x" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': masked_array(data=[-5382460., -5332460., -5282460., -5232460., -5182460.,\n", + " -5132460., -5082460., -5032460., -4982460., -4932460.,\n", + " -4882460., -4832460., -4782460., -4732460., -4682460.,\n", + " -4632460., -4582460., -4532460., -4482460., -4432460.,\n", + " -4382460., -4332460., -4282460., -4232460., -4182460.,\n", + " -4132460., -4082460., -4032460., -3982460., -3932460.,\n", + " -3882460., -3832460., -3782460., -3732460., -3682460.,\n", + " -3632460., -3582460., -3532460., -3482460., -3432460.,\n", + " -3382460., -3332460., -3282460., -3232460., -3182460.,\n", + " -3132460., -3082460., -3032460., -2982460., -2932460.,\n", + " -2882460., -2832460., -2782460., -2732460., -2682460.,\n", + " -2632460., -2582460., -2532460., -2482460., -2432460.,\n", + " -2382460., -2332460., -2282460., -2232460., -2182460.,\n", + " -2132460., -2082460., -2032460., -1982460., -1932460.,\n", + " -1882460., -1832460., -1782460., -1732460., -1682460.,\n", + " -1632460., -1582460., -1532460., -1482460., -1432460.,\n", + " -1382460., -1332460., -1282460., -1232460., -1182460.,\n", + " -1132460., -1082460., -1032460., -982460., -932460.,\n", + " -882460., -832460., -782460., -732460., -682460.,\n", + " -632460., -582460., -532460., -482460., -432460.,\n", + " -382460., -332460., -282460., -232460., -182460.,\n", + " -132460., -82460., -32460., 17540., 67540.,\n", + " 117540., 167540., 217540., 267540., 317540.,\n", + " 367540., 417540., 467540., 517540., 567540.,\n", + " 617540., 667540., 717540., 767540., 817540.,\n", + " 867540., 917540., 967540., 1017540., 1067540.,\n", + " 1117540., 1167540., 1217540., 1267540., 1317540.,\n", + " 1367540., 1417540., 1467540., 1517540., 1567540.,\n", + " 1617540., 1667540., 1717540., 1767540., 1817540.,\n", + " 1867540., 1917540., 1967540., 2017540., 2067540.,\n", + " 2117540., 2167540., 2217540., 2267540., 2317540.,\n", + " 2367540., 2417540., 2467540., 2517540., 2567540.,\n", + " 2617540., 2667540., 2717540., 2767540., 2817540.,\n", + " 2867540., 2917540., 2967540., 3017540., 3067540.,\n", + " 3117540., 3167540., 3217540., 3267540., 3317540.,\n", + " 3367540., 3417540., 3467540., 3517540., 3567540.,\n", + " 3617540., 3667540., 3717540., 3767540., 3817540.,\n", + " 3867540., 3917540., 3967540., 4017540., 4067540.,\n", + " 4117540., 4167540., 4217540., 4267540., 4317540.,\n", + " 4367540., 4417540., 4467540., 4517540., 4567540.,\n", + " 4617540., 4667540., 4717540., 4767540., 4817540.,\n", + " 4867540., 4917540., 4967540., 5017540., 5067540.,\n", + " 5117540., 5167540., 5217540., 5267540., 5317540.,\n", + " 5367540., 5417540., 5467540., 5517540., 5567540.,\n", + " 5617540., 5667540., 5717540., 5767540., 5817540.,\n", + " 5867540., 5917540., 5967540., 6017540., 6067540.,\n", + " 6117540., 6167540., 6217540., 6267540., 6317540.,\n", + " 6367540.],\n", + " mask=False,\n", + " fill_value=1e+20),\n", + " 'dimensions': ('y',),\n", + " 'units': '1000 m',\n", + " 'long_name': 'y coordinate of projection',\n", + " 'standard_name': 'projection_y_coordinate'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.y" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': masked_array(\n", + " data=[[-43.5182 , -43.5182 , -43.5182 , ..., -43.5182 , -43.5182 ,\n", + " -43.5182 ],\n", + " [-43.191082, -43.191082, -43.191082, ..., -43.191082, -43.191082,\n", + " -43.191082],\n", + " [-42.8622 , -42.8622 , -42.8622 , ..., -42.8622 , -42.8622 ,\n", + " -42.8622 ],\n", + " ...,\n", + " [ 49.016712, 49.016712, 49.016712, ..., 49.016712, 49.016712,\n", + " 49.016712],\n", + " [ 49.31089 , 49.31089 , 49.31089 , ..., 49.31089 , 49.31089 ,\n", + " 49.31089 ],\n", + " [ 49.60332 , 49.60332 , 49.60332 , ..., 49.60332 , 49.60332 ,\n", + " 49.60332 ]],\n", + " mask=False,\n", + " fill_value=1e+20,\n", + " dtype=float32),\n", + " 'dimensions': ('y', 'x'),\n", + " 'units': 'degrees_north',\n", + " 'axis': 'Y',\n", + " 'long_name': 'latitude coordinate',\n", + " 'standard_name': 'latitude',\n", + " 'bounds': 'lat_bnds'}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.lat" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': masked_array(\n", + " data=[[-18.9089 , -18.459013, -18.009129, ..., 74.217415, 74.6673 ,\n", + " 75.11718 ],\n", + " [-18.9089 , -18.459013, -18.009129, ..., 74.217415, 74.6673 ,\n", + " 75.11718 ],\n", + " [-18.9089 , -18.459013, -18.009129, ..., 74.217415, 74.6673 ,\n", + " 75.11718 ],\n", + " ...,\n", + " [-18.9089 , -18.459013, -18.009129, ..., 74.217415, 74.6673 ,\n", + " 75.11718 ],\n", + " [-18.9089 , -18.459013, -18.009129, ..., 74.217415, 74.6673 ,\n", + " 75.11718 ],\n", + " [-18.9089 , -18.459013, -18.009129, ..., 74.217415, 74.6673 ,\n", + " 75.11718 ]],\n", + " mask=False,\n", + " fill_value=1e+20,\n", + " dtype=float32),\n", + " 'dimensions': ('y', 'x'),\n", + " 'units': 'degrees_east',\n", + " 'axis': 'X',\n", + " 'long_name': 'longitude coordinate',\n", + " 'standard_name': 'longitude',\n", + " 'bounds': 'lon_bnds'}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.lon" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Rank 000: Loading var_aux var (1/2)\n", + "Rank 000: Loaded var_aux var ((1, 1, 236, 210))\n", + "Rank 000: Loading cell_area var (2/2)\n", + "Rank 000: Loaded cell_area var ((1, 1, 236, 210))\n" + ] + } + ], + "source": [ + "nessy_1.load()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'var_aux': {'data': masked_array(\n", + " data=[[[[0., 0., 0., ..., 0., 0., 0.],\n", + " [0., 0., 0., ..., 0., 0., 0.],\n", + " [0., 0., 0., ..., 0., 0., 0.],\n", + " ...,\n", + " [0., 0., 0., ..., 0., 0., 0.],\n", + " [0., 0., 0., ..., 0., 0., 0.],\n", + " [0., 0., 0., ..., 0., 0., 0.]]]],\n", + " mask=False,\n", + " fill_value=1e+20,\n", + " dtype=float32),\n", + " 'dimensions': ('time', 'y', 'x'),\n", + " 'units': '?',\n", + " 'cell_measures': 'area: cell_area',\n", + " 'grid_mapping': 'mercator',\n", + " 'coordinates': 'lat lon'},\n", + " 'cell_area': {'data': masked_array(\n", + " data=[[[[1.31594240e+09, 1.31593690e+09, 1.31594240e+09, ...,\n", + " 1.31593126e+09, 1.31595354e+09, 1.31593126e+09],\n", + " [1.33020250e+09, 1.33019686e+09, 1.33020250e+09, ...,\n", + " 1.33019123e+09, 1.33021389e+09, 1.33019123e+09],\n", + " [1.34454989e+09, 1.34454426e+09, 1.34454989e+09, ...,\n", + " 1.34453850e+09, 1.34456128e+09, 1.34453850e+09],\n", + " ...,\n", + " [1.07638515e+09, 1.07638054e+09, 1.07638515e+09, ...,\n", + " 1.07637606e+09, 1.07639424e+09, 1.07637606e+09],\n", + " [1.06368742e+09, 1.06368288e+09, 1.06368742e+09, ...,\n", + " 1.06367840e+09, 1.06369645e+09, 1.06367840e+09],\n", + " [1.05104730e+09, 1.05104288e+09, 1.05104730e+09, ...,\n", + " 1.05103840e+09, 1.05105626e+09, 1.05103840e+09]]]],\n", + " mask=False,\n", + " fill_value=1e+20,\n", + " dtype=float32),\n", + " 'dimensions': ('y', 'x'),\n", + " 'long_name': 'area of the grid cell',\n", + " 'standard_name': 'cell_area',\n", + " 'units': 'm2',\n", + " 'coordinates': 'lon lat'}}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.variables" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Rank 000: Creating mercator_file_1.nc\n", + "Rank 000: NetCDF ready to write\n", + "Rank 000: Dimensions done\n", + "Rank 000: Writing var_aux var (1/2)\n", + "Rank 000: Var var_aux created (1/2)\n", + "Rank 000: Filling var_aux)\n", + "Rank 000: Var var_aux data (1/2)\n", + "Rank 000: Var var_aux completed (1/2)\n", + "Rank 000: Writing cell_area var (2/2)\n", + "Rank 000: Var cell_area created (2/2)\n", + "Rank 000: Filling cell_area)\n", + "Rank 000: Var cell_area data (2/2)\n", + "Rank 000: Var cell_area completed (2/2)\n" + ] + } + ], + "source": [ + "nessy_1.to_netcdf('mercator_file_1.nc', info=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Reopen with NES" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'data': None, 'dimensions': (), 'grid_mapping_name': 'mercator', 'standard_parallel': -1.5, 'longitude_of_projection_origin': -18.0}\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_2 = open_netcdf('mercator_file_1.nc', info=True)\n", + "nessy_2" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
    \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
    <xarray.Dataset>\n",
    +       "Dimensions:    (time: 1, lev: 1, y: 236, x: 210)\n",
    +       "Coordinates:\n",
    +       "  * time       (time) datetime64[ns] 2000-01-01\n",
    +       "  * lev        (lev) float64 0.0\n",
    +       "    lat        (y, x) float64 -43.52 -43.52 -43.52 -43.52 ... 49.6 49.6 49.6\n",
    +       "    lon        (y, x) float64 -18.91 -18.46 -18.01 -17.56 ... 74.22 74.67 75.12\n",
    +       "  * y          (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n",
    +       "  * x          (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n",
    +       "Data variables:\n",
    +       "    var_aux    (time, lev, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0\n",
    +       "    cell_area  (time, lev, y, x) float32 1.316e+09 1.316e+09 ... 1.051e+09\n",
    +       "    mercator   |S1 b''\n",
    +       "Attributes:\n",
    +       "    Conventions:  CF-1.7
    " + ], + "text/plain": [ + "\n", + "Dimensions: (time: 1, lev: 1, y: 236, x: 210)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2000-01-01\n", + " * lev (lev) float64 0.0\n", + " lat (y, x) float64 ...\n", + " lon (y, x) float64 ...\n", + " * y (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n", + " * x (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n", + "Data variables:\n", + " var_aux (time, lev, y, x) float32 ...\n", + " cell_area (time, lev, y, x) float32 ...\n", + " mercator |S1 ...\n", + "Attributes:\n", + " Conventions: CF-1.7" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "xr.open_dataset('mercator_file_1.nc')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Jupyter_notebooks/2-create_nes.ipynb b/Jupyter_notebooks/2-create_nes.ipynb index 99a24420807dd4586cffc527764904d3d65c5e02..1a75c568c5680bf042b9eaa5d9e440c0f55f375e 100644 --- a/Jupyter_notebooks/2-create_nes.ipynb +++ b/Jupyter_notebooks/2-create_nes.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# How to create regular, rotated, points and LCC grids" + "# How to create regular, rotated, points, LCC and Mercator grids" ] }, { @@ -431,7 +431,7 @@ "Data variables:\n", " crs |S1 b''\n", "Attributes:\n", - " Conventions: CF-1.7" + " Conventions: CF-1.7" ], "text/plain": [ "\n", @@ -871,13 +871,13 @@ " lon (rlat, rlon) float64 -22.18 -22.02 -21.85 ... 88.05 88.23\n", " rotated_pole |S1 b''\n", "Attributes:\n", - " Conventions: CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", @@ -1147,9 +1147,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:396: UserWarning: WARNING!!! Different data types for variable station_codeInput dtype=, data dtype=object\n", + "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:402: UserWarning: WARNING!!! Different data types for variable station_codeInput dtype=, data dtype=object\n", " warnings.warn(msg)\n", - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:396: UserWarning: WARNING!!! Different data types for variable area_classificationInput dtype=, data dtype=object\n", + "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:402: UserWarning: WARNING!!! Different data types for variable area_classificationInput dtype=, data dtype=object\n", " warnings.warn(msg)\n" ] } @@ -1528,7 +1528,7 @@ " lat (station) float64 41.38 41.73 41.57 ... 41.24 42.36\n", " lon (station) float64 2.086 1.839 2.015 ... 1.857 1.459\n", "Attributes:\n", - " Conventions: CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", @@ -2213,11 +2213,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:396: UserWarning: WARNING!!! Different data types for variable station_nameInput dtype=, data dtype=object\n", + "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:402: UserWarning: WARNING!!! Different data types for variable station_nameInput dtype=, data dtype=object\n", " warnings.warn(msg)\n", - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:396: UserWarning: WARNING!!! Different data types for variable station_codeInput dtype=, data dtype=object\n", + "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:402: UserWarning: WARNING!!! Different data types for variable station_codeInput dtype=, data dtype=object\n", " warnings.warn(msg)\n", - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:396: UserWarning: WARNING!!! Different data types for variable pm10Input dtype=, data dtype=object\n", + "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:402: UserWarning: WARNING!!! Different data types for variable pm10Input dtype=, data dtype=object\n", " warnings.warn(msg)\n" ] } @@ -2597,15 +2597,15 @@ " lat (station) float64 nan nan nan nan nan ... nan nan nan nan nan\n", " lon (station) float64 nan nan nan nan nan ... nan nan nan nan nan\n", "Attributes:\n", - " Conventions: CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", @@ -2717,7 +2717,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -2738,7 +2738,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -2757,7 +2757,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -3126,9 +3126,9 @@ " lon (y, x) float64 ...\n", " Lambert_conformal |S1 b''\n", "Attributes:\n", - " Conventions: CF-1.7" + " Conventions: CF-1.7" ], "text/plain": [ "\n", @@ -3146,7 +3146,7 @@ " Conventions: CF-1.7" ] }, - "execution_count": 4, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -3155,12 +3155,50 @@ "xr.open_dataset('lcc_grid.nc')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 5. Create Mercator grid" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "lat_ts = -1.5\n", + "lon_0 = -18.0\n", + "nx = 210\n", + "ny = 236\n", + "inc_x = 50000\n", + "inc_y = 50000\n", + "x_0 = -126017.5\n", + "y_0 = -5407460.0\n", + "mercator_grid = create_nes(comm=None, info=False, projection='mercator',\n", + " lat_ts=lat_ts, lon_0=lon_0, nx=nx, ny=ny, \n", + " inc_x=inc_x, inc_y=inc_y, x_0=x_0, y_0=y_0)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Rank 000: Creating mercator_grid.nc\n", + "Rank 000: NetCDF ready to write\n", + "Rank 000: Dimensions done\n" + ] + } + ], + "source": [ + "mercator_grid.to_netcdf('mercator_grid.nc', info=True)" + ] } ], "metadata": { diff --git a/Jupyter_notebooks/2.1-create_nes_port.ipynb b/Jupyter_notebooks/2.1-create_nes_port.ipynb index 77e90d6cc96a8632f6dd8bb6f7e46594ff17a3c1..3ed3bc4eaf309970eb0c35c5cf1a92455dc83d99 100644 --- a/Jupyter_notebooks/2.1-create_nes_port.ipynb +++ b/Jupyter_notebooks/2.1-create_nes_port.ipynb @@ -62,40 +62,40 @@ " \n", " \n", " 2017-01-01 00:00:00.000000\n", - " 0.18\n", - " NaN\n", - " 63.38\n", - " 46.01\n", - " \n", - " \n", - " 2017-01-01 01:00:00.000003\n", " 0.20\n", " NaN\n", " 64.64\n", " 49.08\n", " \n", " \n", - " 2017-01-01 01:59:59.999997\n", + " 2017-01-01 01:00:00.000003\n", " 0.18\n", " NaN\n", " 68.16\n", " 53.00\n", " \n", " \n", - " 2017-01-01 03:00:00.000000\n", + " 2017-01-01 01:59:59.999997\n", " 0.04\n", " NaN\n", " 68.29\n", " 46.75\n", " \n", " \n", - " 2017-01-01 04:00:00.000003\n", + " 2017-01-01 03:00:00.000000\n", " 0.00\n", " NaN\n", " 62.91\n", " 39.65\n", " \n", " \n", + " 2017-01-01 04:00:00.000003\n", + " 0.00\n", + " NaN\n", + " 47.13\n", + " 28.86\n", + " \n", + " \n", " ...\n", " ...\n", " ...\n", @@ -103,35 +103,35 @@ " ...\n", " \n", " \n", - " 2021-12-31 13:59:59.999997\n", + " 2021-12-31 13:00:00.000003\n", " 0.77\n", " NaN\n", " 35.38\n", " 24.96\n", " \n", " \n", - " 2021-12-31 15:00:00.000000\n", + " 2021-12-31 13:59:59.999997\n", " 0.37\n", " NaN\n", " 35.80\n", " 24.16\n", " \n", " \n", - " 2021-12-31 16:00:00.000003\n", + " 2021-12-31 15:00:00.000000\n", " 0.23\n", " NaN\n", " 29.10\n", " 25.79\n", " \n", " \n", - " 2021-12-31 16:59:59.999997\n", + " 2021-12-31 16:00:00.000003\n", " 0.14\n", " NaN\n", " 9.24\n", " 29.82\n", " \n", " \n", - " 2021-12-31 18:00:00.000000\n", + " 2021-12-31 16:59:59.999997\n", " 0.20\n", " NaN\n", " 12.76\n", @@ -139,25 +139,25 @@ " \n", " \n", "\n", - "

    43819 rows × 4 columns

    \n", + "

    43818 rows × 4 columns

    \n", "" ], "text/plain": [ " SO2-Darsena SO2-UM NO2-UM NO2-ZAL Prat\n", "Horario: UTC \n", - "2017-01-01 00:00:00.000000 0.18 NaN 63.38 46.01\n", - "2017-01-01 01:00:00.000003 0.20 NaN 64.64 49.08\n", - "2017-01-01 01:59:59.999997 0.18 NaN 68.16 53.00\n", - "2017-01-01 03:00:00.000000 0.04 NaN 68.29 46.75\n", - "2017-01-01 04:00:00.000003 0.00 NaN 62.91 39.65\n", + "2017-01-01 00:00:00.000000 0.20 NaN 64.64 49.08\n", + "2017-01-01 01:00:00.000003 0.18 NaN 68.16 53.00\n", + "2017-01-01 01:59:59.999997 0.04 NaN 68.29 46.75\n", + "2017-01-01 03:00:00.000000 0.00 NaN 62.91 39.65\n", + "2017-01-01 04:00:00.000003 0.00 NaN 47.13 28.86\n", "... ... ... ... ...\n", - "2021-12-31 13:59:59.999997 0.77 NaN 35.38 24.96\n", - "2021-12-31 15:00:00.000000 0.37 NaN 35.80 24.16\n", - "2021-12-31 16:00:00.000003 0.23 NaN 29.10 25.79\n", - "2021-12-31 16:59:59.999997 0.14 NaN 9.24 29.82\n", - "2021-12-31 18:00:00.000000 0.20 NaN 12.76 28.66\n", + "2021-12-31 13:00:00.000003 0.77 NaN 35.38 24.96\n", + "2021-12-31 13:59:59.999997 0.37 NaN 35.80 24.16\n", + "2021-12-31 15:00:00.000000 0.23 NaN 29.10 25.79\n", + "2021-12-31 16:00:00.000003 0.14 NaN 9.24 29.82\n", + "2021-12-31 16:59:59.999997 0.20 NaN 12.76 28.66\n", "\n", - "[43819 rows x 4 columns]" + "[43818 rows x 4 columns]" ] }, "execution_count": 2, @@ -185,12 +185,12 @@ " '2017-01-01 06:00:00', '2017-01-01 07:00:00',\n", " '2017-01-01 08:00:00', '2017-01-01 09:00:00',\n", " ...\n", - " '2021-12-31 09:00:00', '2021-12-31 10:00:00',\n", - " '2021-12-31 11:00:00', '2021-12-31 12:00:00',\n", - " '2021-12-31 13:00:00', '2021-12-31 14:00:00',\n", - " '2021-12-31 15:00:00', '2021-12-31 16:00:00',\n", - " '2021-12-31 17:00:00', '2021-12-31 18:00:00'],\n", - " dtype='datetime64[ns]', length=43819, freq=None)" + " '2021-12-31 08:00:00', '2021-12-31 09:00:00',\n", + " '2021-12-31 10:00:00', '2021-12-31 11:00:00',\n", + " '2021-12-31 12:00:00', '2021-12-31 13:00:00',\n", + " '2021-12-31 14:00:00', '2021-12-31 15:00:00',\n", + " '2021-12-31 16:00:00', '2021-12-31 17:00:00'],\n", + " dtype='datetime64[ns]', length=43818, freq=None)" ] }, "execution_count": 3, @@ -302,9 +302,9 @@ "array([datetime.datetime(2017, 1, 1, 0, 0),\n", " datetime.datetime(2017, 1, 1, 1, 0),\n", " datetime.datetime(2017, 1, 1, 2, 0), ...,\n", + " datetime.datetime(2021, 12, 31, 15, 0),\n", " datetime.datetime(2021, 12, 31, 16, 0),\n", - " datetime.datetime(2021, 12, 31, 17, 0),\n", - " datetime.datetime(2021, 12, 31, 18, 0)], dtype=object)" + " datetime.datetime(2021, 12, 31, 17, 0)], dtype=object)" ] }, "execution_count": 5, @@ -416,7 +416,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:401: UserWarning: WARNING!!! Different data types for variable station_nameInput dtype=, data dtype=object\n", + "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:402: UserWarning: WARNING!!! Different data types for variable station_nameInput dtype=, data dtype=object\n", " warnings.warn(msg)\n" ] }, @@ -794,32 +794,32 @@ " fill: currentColor;\n", "}\n", "
    <xarray.Dataset>\n",
    -       "Dimensions:       (time: 43819, station: 2)\n",
    +       "Dimensions:       (time: 43818, station: 2)\n",
            "Coordinates:\n",
    -       "  * time          (time) datetime64[ns] 2017-01-01 ... 2021-12-31T18:00:00\n",
    +       "  * time          (time) datetime64[ns] 2017-01-01 ... 2021-12-31T17:00:00\n",
            "  * station       (station) float64 0.0 1.0\n",
            "Data variables:\n",
            "    station_name  (station) object 'NO2-UM' 'NO2-ZAL Prat'\n",
    -       "    sconcno2      (time, station) float64 63.38 46.01 64.64 ... 12.76 28.66\n",
    +       "    sconcno2      (time, station) float64 64.64 49.08 68.16 ... 12.76 28.66\n",
            "    lat           (station) float64 41.37 41.32\n",
            "    lon           (station) float64 2.185 2.135\n",
            "Attributes:\n",
    -       "    Conventions:  CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", - "Dimensions: (time: 43819, station: 2)\n", + "Dimensions: (time: 43818, station: 2)\n", "Coordinates:\n", - " * time (time) datetime64[ns] 2017-01-01 ... 2021-12-31T18:00:00\n", + " * time (time) datetime64[ns] 2017-01-01 ... 2021-12-31T17:00:00\n", " * station (station) float64 0.0 1.0\n", "Data variables:\n", " station_name (station) object ...\n", @@ -893,15 +893,6 @@ " \n", " \n", " 2017-01-01 00:00:00\n", - " 0.18\n", - " NaN\n", - " 63.38\n", - " 46.01\n", - " 1\n", - " 2017\n", - " \n", - " \n", - " 2017-01-01 01:00:00\n", " 0.20\n", " NaN\n", " 64.64\n", @@ -910,7 +901,7 @@ " 2017\n", " \n", " \n", - " 2017-01-01 02:00:00\n", + " 2017-01-01 01:00:00\n", " 0.18\n", " NaN\n", " 68.16\n", @@ -919,7 +910,7 @@ " 2017\n", " \n", " \n", - " 2017-01-01 03:00:00\n", + " 2017-01-01 02:00:00\n", " 0.04\n", " NaN\n", " 68.29\n", @@ -928,7 +919,7 @@ " 2017\n", " \n", " \n", - " 2017-01-01 04:00:00\n", + " 2017-01-01 03:00:00\n", " 0.00\n", " NaN\n", " 62.91\n", @@ -937,6 +928,15 @@ " 2017\n", " \n", " \n", + " 2017-01-01 04:00:00\n", + " 0.00\n", + " NaN\n", + " 47.13\n", + " 28.86\n", + " 1\n", + " 2017\n", + " \n", + " \n", " ...\n", " ...\n", " ...\n", @@ -946,7 +946,7 @@ " ...\n", " \n", " \n", - " 2021-12-31 14:00:00\n", + " 2021-12-31 13:00:00\n", " 0.77\n", " NaN\n", " 35.38\n", @@ -955,7 +955,7 @@ " 2021\n", " \n", " \n", - " 2021-12-31 15:00:00\n", + " 2021-12-31 14:00:00\n", " 0.37\n", " NaN\n", " 35.80\n", @@ -964,7 +964,7 @@ " 2021\n", " \n", " \n", - " 2021-12-31 16:00:00\n", + " 2021-12-31 15:00:00\n", " 0.23\n", " NaN\n", " 29.10\n", @@ -973,7 +973,7 @@ " 2021\n", " \n", " \n", - " 2021-12-31 17:00:00\n", + " 2021-12-31 16:00:00\n", " 0.14\n", " NaN\n", " 9.24\n", @@ -982,7 +982,7 @@ " 2021\n", " \n", " \n", - " 2021-12-31 18:00:00\n", + " 2021-12-31 17:00:00\n", " 0.20\n", " NaN\n", " 12.76\n", @@ -992,24 +992,24 @@ " \n", " \n", "\n", - "

    43819 rows × 6 columns

    \n", + "

    43818 rows × 6 columns

    \n", "" ], "text/plain": [ " SO2-Darsena SO2-UM NO2-UM NO2-ZAL Prat month year\n", - "2017-01-01 00:00:00 0.18 NaN 63.38 46.01 1 2017\n", - "2017-01-01 01:00:00 0.20 NaN 64.64 49.08 1 2017\n", - "2017-01-01 02:00:00 0.18 NaN 68.16 53.00 1 2017\n", - "2017-01-01 03:00:00 0.04 NaN 68.29 46.75 1 2017\n", - "2017-01-01 04:00:00 0.00 NaN 62.91 39.65 1 2017\n", + "2017-01-01 00:00:00 0.20 NaN 64.64 49.08 1 2017\n", + "2017-01-01 01:00:00 0.18 NaN 68.16 53.00 1 2017\n", + "2017-01-01 02:00:00 0.04 NaN 68.29 46.75 1 2017\n", + "2017-01-01 03:00:00 0.00 NaN 62.91 39.65 1 2017\n", + "2017-01-01 04:00:00 0.00 NaN 47.13 28.86 1 2017\n", "... ... ... ... ... ... ...\n", - "2021-12-31 14:00:00 0.77 NaN 35.38 24.96 12 2021\n", - "2021-12-31 15:00:00 0.37 NaN 35.80 24.16 12 2021\n", - "2021-12-31 16:00:00 0.23 NaN 29.10 25.79 12 2021\n", - "2021-12-31 17:00:00 0.14 NaN 9.24 29.82 12 2021\n", - "2021-12-31 18:00:00 0.20 NaN 12.76 28.66 12 2021\n", + "2021-12-31 13:00:00 0.77 NaN 35.38 24.96 12 2021\n", + "2021-12-31 14:00:00 0.37 NaN 35.80 24.16 12 2021\n", + "2021-12-31 15:00:00 0.23 NaN 29.10 25.79 12 2021\n", + "2021-12-31 16:00:00 0.14 NaN 9.24 29.82 12 2021\n", + "2021-12-31 17:00:00 0.20 NaN 12.76 28.66 12 2021\n", "\n", - "[43819 rows x 6 columns]" + "[43818 rows x 6 columns]" ] }, "execution_count": 14, @@ -1506,20 +1506,20 @@ "Data variables:\n", " station_name (station) |S75 b'NO2-UM' b'NO2-ZAL Prat'\n", " altitude (station) float64 nan nan\n", - " sconcno2 (time, station) float64 6.88 23.03 8.77 ... 26.42 0.07 27.11\n", + " sconcno2 (time, station) float64 8.77 23.49 1.76 ... 27.11 13.87 30.07\n", " lat (station) float64 41.37 41.32\n", " lon (station) float64 2.185 2.135\n", "Attributes:\n", - " Conventions: CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", @@ -1548,7 +1548,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -1906,33 +1906,33 @@ " fill: currentColor;\n", "}\n", "
    <xarray.Dataset>\n",
    -       "Dimensions:       (time: 744, station: 2)\n",
    +       "Dimensions:       (time: 738, station: 2)\n",
            "Coordinates:\n",
    -       "  * time          (time) datetime64[ns] 2019-12-01 ... 2019-12-31T23:00:00\n",
    +       "  * time          (time) datetime64[ns] 2021-12-01 ... 2021-12-31T17:00:00\n",
            "  * station       (station) float64 0.0 1.0\n",
            "Data variables:\n",
            "    station_name  (station) |S75 b'NO2-UM' b'NO2-ZAL Prat'\n",
            "    altitude      (station) float64 nan nan\n",
    -       "    sconcno2      (time, station) float64 65.22 80.1 63.97 ... 20.7 nan 16.95\n",
    +       "    sconcno2      (time, station) float64 13.33 nan 13.42 ... 29.82 12.76 28.66\n",
            "    lat           (station) float64 41.37 41.32\n",
            "    lon           (station) float64 2.185 2.135\n",
            "Attributes:\n",
    -       "    Conventions:  CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", - "Dimensions: (time: 744, station: 2)\n", + "Dimensions: (time: 738, station: 2)\n", "Coordinates:\n", - " * time (time) datetime64[ns] 2019-12-01 ... 2019-12-31T23:00:00\n", + " * time (time) datetime64[ns] 2021-12-01 ... 2021-12-31T17:00:00\n", " * station (station) float64 0.0 1.0\n", "Data variables:\n", " station_name (station) |S75 ...\n", @@ -1944,21 +1944,14 @@ " Conventions: CF-1.7" ] }, - "execution_count": 17, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "xr.open_dataset('/esarchive/obs/generalitat/port-barcelona/hourly/sconcno2/sconcno2_201912.nc')" + "xr.open_dataset('/esarchive/obs/generalitat/port-barcelona/hourly/sconcno2/sconcno2_202112.nc')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/Jupyter_notebooks/input/Dades_Port_Barcelona_2017-2021_corr.xlsx b/Jupyter_notebooks/input/Dades_Port_Barcelona_2017-2021_corr.xlsx index 387c74b075e319b2cc2df2560b69d647d83761ef..4aca3769586044b3906cc5a6a901ce4376ed07ec 100644 Binary files a/Jupyter_notebooks/input/Dades_Port_Barcelona_2017-2021_corr.xlsx and b/Jupyter_notebooks/input/Dades_Port_Barcelona_2017-2021_corr.xlsx differ diff --git a/nes/create_nes.py b/nes/create_nes.py index c5ae01d2cfea9674de1d36045104e1fd10d8c02f..8add0fa0f0a15176611a968e10ff7153414c5804 100644 --- a/nes/create_nes.py +++ b/nes/create_nes.py @@ -2,9 +2,7 @@ import warnings from netCDF4 import num2date - from mpi4py import MPI - from .nc_projections import * @@ -60,6 +58,10 @@ def create_nes(comm=None, info=False, projection=None, parallel_method='Y', bala nessy = LCCNes(comm=comm, dataset=None, xarray=None, info=info, parallel_method=parallel_method, avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, balanced=balanced, create_nes=True, times=times, **kwargs) + elif projection == 'mercator': + nessy = MercatorNes(comm=comm, dataset=None, xarray=None, info=info, parallel_method=parallel_method, + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, balanced=balanced, + create_nes=True, times=times, **kwargs) else: raise NotImplementedError(projection) diff --git a/nes/interpolation/horizontal_interpolation.py b/nes/interpolation/horizontal_interpolation.py index c7c5a8b13940a20c9245bbc682e3765712c48ca1..63098c3c0ebff647992783374fce876f77a750bd 100644 --- a/nes/interpolation/horizontal_interpolation.py +++ b/nes/interpolation/horizontal_interpolation.py @@ -26,7 +26,7 @@ def interpolate_horizontal(self, dst_grid, weight_matrix_path=None, kind='Neares Path to the weight matrix to read/create kind : str Kind of horizontal interpolation. choices = ['NearestNeighbour'] - n_neighbours: int + n_neighbours : int Used if kind == NearestNeighbour. Number of nearest neighbours to interpolate. default = 4 info: bool Indicates if you want to print extra info during the interpolation process. @@ -127,7 +127,7 @@ def get_weights_idx_t_axis(self, dst_grid, weight_matrix_path, kind, n_neighbour Path to the weight matrix to read/create kind : str Kind of horizontal interpolation. choices = ['NearestNeighbour'] - n_neighbours: int + n_neighbours : int Used if kind == NearestNeighbour. Number of nearest neighbours to interpolate. default = 4 Returns @@ -197,7 +197,7 @@ def get_weights_idx_xy_axis(self, dst_grid, weight_matrix_path, kind, n_neighbou Path to the weight matrix to read/create kind : str Kind of horizontal interpolation. choices = ['NearestNeighbour'] - n_neighbours: int + n_neighbours : int Used if kind == NearestNeighbour. Number of nearest neighbours to interpolate. default = 4 Returns @@ -289,7 +289,7 @@ def create_nn_weight_matrix(self, dst_grid, n_neighbours=4, info=False): Source projection Nes Object dst_grid : nes.Nes Final projection Nes object - n_neighbours: int + n_neighbours : int Used if kind == NearestNeighbour. Number of nearest neighbours to interpolate. default = 4 info: bool Indicates if you want to print extra info during the interpolation process. diff --git a/nes/interpolation/vertical_interpolation.py b/nes/interpolation/vertical_interpolation.py index e7d5f4e55454746946d29b41bd4e949d3d346794..3af5aaf0c8fbd51f9815f27ec92baeae3cc9b03d 100644 --- a/nes/interpolation/vertical_interpolation.py +++ b/nes/interpolation/vertical_interpolation.py @@ -33,21 +33,15 @@ def interpolate_vertical(self, new_levels, new_src_vertical=None, kind='linear', ---------- self : Nes Source Nes object - new_levels : list List of new vertical levels - new_src_vertical - kind : str Vertical interpolation type. - extrapolate : None, tuple, str Extrapolate method (for non linear operations) - info: None, bool Indicates if you want to print extra information - """ if info is None: info = self.print_info diff --git a/nes/load_nes.py b/nes/load_nes.py index a60c95d65d0632fd34c959ae93028b4402f8d2f5..5d9199851401e61127d894eedeebc3a2d2f4295b 100644 --- a/nes/load_nes.py +++ b/nes/load_nes.py @@ -6,7 +6,8 @@ from netCDF4 import Dataset from .nc_projections import * -def open_netcdf(path, comm=None, xarray=False, info=False, parallel_method='Y', avoid_first_hours=0, avoid_last_hours=0, +def open_netcdf(path, comm=None, xarray=False, info=False, parallel_method='Y', + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, balanced=False): """ Open a netCDF file @@ -70,6 +71,11 @@ def open_netcdf(path, comm=None, xarray=False, info=False, parallel_method='Y', nessy = LCCNes(comm=comm, dataset=dataset, xarray=xarray, info=info, parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, first_level=first_level, last_level=last_level, create_nes=False, balanced=balanced,) + elif __is_mercator(dataset): + # Mercator grids + nessy = MercatorNes(comm=comm, dataset=dataset, xarray=xarray, info=info, parallel_method=parallel_method, + avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, + first_level=first_level, last_level=last_level, create_nes=False, balanced=balanced,) else: # Regular grids nessy = LatLonNes(comm=comm, dataset=dataset, xarray=xarray, info=info, parallel_method=parallel_method, @@ -100,7 +106,19 @@ def __is_rotated(dataset): def __is_points(dataset): + """ + Check if the netCDF is a points dataset in non-GHOST format or not. + + Parameters + ---------- + dataset : Dataset + netcdf4-python opened dataset object + Returns + ------- + value : bool + Indicated if the netCDF is a points non-GHOST one + """ if 'station' in dataset.dimensions: return True else: @@ -108,15 +126,58 @@ def __is_points(dataset): def __is_points_GHOST(dataset): + """ + Check if the netCDF is a points dataset in GHOST format or not. + Parameters + ---------- + dataset : Dataset + netcdf4-python opened dataset object + + Returns + ------- + value : bool + Indicated if the netCDF is a points GHOST one + """ if 'N_flag_codes' in dataset.dimensions and 'N_qa_codes' in dataset.dimensions: return True else: return False def __is_lcc(dataset): - - if 'x' in dataset.dimensions and 'y' in dataset.dimensions: + """ + Check if the netCDF is in Lambert Conformal Conic (LCC) projection or not. + + Parameters + ---------- + dataset : Dataset + netcdf4-python opened dataset object + + Returns + ------- + value : bool + Indicated if the netCDF is a LCC one + """ + if 'Lambert_conformal' in dataset.variables.keys(): + return True + else: + return False + +def __is_mercator(dataset): + """ + Check if the netCDF is in Mercator projection or not. + + Parameters + ---------- + dataset : Dataset + netcdf4-python opened dataset object + + Returns + ------- + value : bool + Indicated if the netCDF is a Mercator one + """ + if 'mercator' in dataset.variables.keys(): return True else: return False diff --git a/nes/nc_projections/__init__.py b/nes/nc_projections/__init__.py index 2fca06a3344ca440fc4af8fcb55e1277c06febe6..384265791dea5ec6fb4dcada082558f858e5628c 100644 --- a/nes/nc_projections/__init__.py +++ b/nes/nc_projections/__init__.py @@ -4,3 +4,4 @@ from .rotated_nes import RotatedNes from .points_nes import PointsNes from .points_nes_ghost import PointsNesGHOST from .lcc_nes import LCCNes +from .mercator_nes import MercatorNes diff --git a/nes/nc_projections/latlon_nes.py b/nes/nc_projections/latlon_nes.py index 737eb1263833d50e7c82c2cd483f1cfbc9fc3df9..77bb451f171d5e6a459e3d2749e67a637615a1af 100644 --- a/nes/nc_projections/latlon_nes.py +++ b/nes/nc_projections/latlon_nes.py @@ -89,7 +89,7 @@ class LatLonNes(Nes): Number of hours to remove from last time steps. parallel_method : str Indicates the parallelization method that you want. Default over Y axis - accepted values: ['Y', 'T'] + accepted values: ['X', 'Y', 'T'] """ new = LatLonNes(comm=comm, path=path, info=info, dataset=dataset, xarray=xarray, balanced=balanced, parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, diff --git a/nes/nc_projections/lcc_nes.py b/nes/nc_projections/lcc_nes.py index 66a6a1ec7f8a04d3256dcf79c278448f2972d853..bee48a94a3fa36f3a2705be34d1f71713faab915 100644 --- a/nes/nc_projections/lcc_nes.py +++ b/nes/nc_projections/lcc_nes.py @@ -11,15 +11,23 @@ class LCCNes(Nes): Attributes ---------- + _y : dict + Y coordinates dictionary with the complete 'data' key for all the values and the rest of the attributes. + _x : dict + X coordinates dictionary with the complete 'data' key for all the values and the rest of the attributes. + y : dict + Y coordinates dictionary with the portion of 'data' corresponding to the rank values. + x : dict + X coordinates dictionary with the portion of 'data' corresponding to the rank values. _var_dim : tuple Tuple with the name of the Y and X dimensions for the variables. - ('lat', 'lon') for a regular latitude-longitude projection. + ('y', 'x',) for a LCC projection. _lat_dim : tuple Tuple with the name of the dimensions of the Latitude values. - ('lat',) for a regular latitude-longitude projection. + ('y', 'x',) for a LCC projection. _lon_dim : tuple Tuple with the name of the dimensions of the Longitude values. - ('lon',) for a regular latitude-longitude projection. + ('y', 'x') for a LCC projection. """ def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='Y', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, @@ -102,7 +110,7 @@ class LCCNes(Nes): Number of hours to remove from last time steps. parallel_method : str Indicates the parallelization method that you want. Default over Y axis - accepted values: ['Y', 'T'] + accepted values: ['X', 'Y', 'T'] """ new = LCCNes(comm=comm, path=path, info=info, dataset=dataset, xarray=xarray, balanced=balanced, parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, @@ -162,19 +170,25 @@ class LCCNes(Nes): super(LCCNes, self)._create_dimension_variables(netcdf) - # LCC LATITUDES + # LCC Y COORDINATES y = netcdf.createVariable('y', self._y['data'].dtype, ('y',)) y.long_name = "y coordinate of projection" - y.units = Units("m", formatted=True).units + if 'units' in self._y.keys(): + y.units = Units(self._y['units'], formatted=True).units + else: + y.units = 'm' y.standard_name = "projection_y_coordinate" if self.size > 1: y.set_collective(True) y[:] = self._y['data'] - # LCC LONGITUDES + # LCC X COORDINATES x = netcdf.createVariable('x', self._x['data'].dtype, ('x',)) x.long_name = "x coordinate of projection" - x.units = Units("m", formatted=True).units + if 'units' in self._x.keys(): + x.units = Units(self._x['units'], formatted=True).units + else: + x.units = 'm' x.standard_name = "projection_x_coordinate" if self.size > 1: x.set_collective(True) @@ -241,7 +255,7 @@ class LCCNes(Nes): def _create_metadata(self, netcdf): """ - Create the 'crs' variable for the lamber conformal latitude longitude grid_mapping. + Create the 'crs' variable for the lamber conformal grid_mapping. Parameters ---------- diff --git a/nes/nc_projections/mercator_nes.py b/nes/nc_projections/mercator_nes.py new file mode 100644 index 0000000000000000000000000000000000000000..278e2048d7922557116d4f39524be52894a8292b --- /dev/null +++ b/nes/nc_projections/mercator_nes.py @@ -0,0 +1,268 @@ +#!/usr/bin/env python + +import numpy as np +from cfunits import Units +from pyproj import Proj +from nes.nc_projections.default_nes import Nes + + +class MercatorNes(Nes): + """ + + Attributes + ---------- + _y : dict + Y coordinates dictionary with the complete 'data' key for all the values and the rest of the attributes. + _x : dict + X coordinates dictionary with the complete 'data' key for all the values and the rest of the attributes. + y : dict + Y coordinates dictionary with the portion of 'data' corresponding to the rank values. + x : dict + X coordinates dictionary with the portion of 'data' corresponding to the rank values. + _var_dim : tuple + Tuple with the name of the Y and X dimensions for the variables. + ('y', 'x') for a Mercator projection. + _lat_dim : tuple + Tuple with the name of the dimensions of the Latitude values. + ('y', 'x') for a Mercator projection. + _lon_dim : tuple + Tuple with the name of the dimensions of the Longitude values. + ('y', 'x') for a Mercator projection. + """ + def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='Y', + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, + balanced=False, times=None, **kwargs): + """ + Initialize the MercatorNes class + + Parameters + ---------- + comm: MPI.COMM + Path to the CSV file that contains all the information. + path: str + Path to the NetCDF to initialize the object + info: bool + Indicates if you want to get reading/writing info + dataset: Dataset + NetCDF4-python Dataset to initialize the class + xarray: bool: + (Not working) Indicates if you want to use xarray as default + parallel_method : str + Indicates the parallelization method that you want. Default over Y axis + accepted values: ['X', 'Y', 'T'] + avoid_first_hours : int + Number of hours to remove from first time steps. + avoid_last_hours : int + Number of hours to remove from last time steps. + """ + super(MercatorNes, self).__init__(comm=comm, path=path, info=info, dataset=dataset, + xarray=xarray, parallel_method=parallel_method, balanced=balanced, + avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, + first_level=first_level, last_level=last_level, create_nes=create_nes, + times=times, **kwargs) + + if create_nes: + # Dimensions screening + self.lat = self._get_coordinate_values(self._lat, 'Y') + self.lon = self._get_coordinate_values(self._lon, 'X') + else: + # Complete dimensions + self._y = self._get_coordinate_dimension('y') + self._x = self._get_coordinate_dimension('x') + + # Dimensions screening + self.y = self._get_coordinate_values(self._y, 'Y') + self.x = self._get_coordinate_values(self._x, 'X') + + # Get projection details + self.projection_data = self.get_projection_data(create_nes, **kwargs) + + # Set axis limits for parallel writing + self.write_axis_limits = self.get_write_axis_limits() + + self._var_dim = ('y', 'x') + self._lat_dim = ('y', 'x') + self._lon_dim = ('y', 'x') + + self.free_vars('crs') + + + @staticmethod + def new(comm=None, path=None, info=False, dataset=None, xarray=False, create=False, balanced=False, + parallel_method='Y', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None): + """ + Initialize the Nes class + + Parameters + ---------- + comm: MPI.COMM + MPI Communicator + path: str + Path to the NetCDF to initialize the object + info: bool + Indicates if you want to get reading/writing info + dataset: Dataset + NetCDF4-python Dataset to initialize the class + xarray: bool: + (Not working) Indicates if you want to use xarray as default + avoid_first_hours : int + Number of hours to remove from first time steps. + avoid_last_hours : int + Number of hours to remove from last time steps. + parallel_method : str + Indicates the parallelization method that you want. Default over Y axis + accepted values: ['X', 'Y', 'T'] + """ + new = MercatorNes(comm=comm, path=path, info=info, dataset=dataset, xarray=xarray, balanced=balanced, + parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, + avoid_last_hours=avoid_last_hours, first_level=first_level, last_level=last_level) + return new + + def get_projection_data(self, create_nes, **kwargs): + """ + Read the projection data + + Returns + ------- + projection : dict + Dictionary with the projection data + """ + + if create_nes: + projection = {'data': None, + 'dimensions': (), + 'grid_mapping_name': 'mercator', + 'standard_parallel': [kwargs['lat_ts']], # TODO: Check if True + 'longitude_of_projection_origin': kwargs['lon_0'], + } + + else: + projection = self.variables['mercator'] + print(projection) + self.free_vars('mercator') + + return projection + + def _create_dimensions(self, netcdf): + """ + Create the 'y', 'x' dimensions and the super dimensions ('lev', 'time'). + + Parameters + ---------- + netcdf : Dataset + NetCDF object. + """ + super(MercatorNes, self)._create_dimensions(netcdf) + + netcdf.createDimension('y', len(self._y['data'])) + netcdf.createDimension('x', len(self._x['data'])) + + return None + + def _create_dimension_variables(self, netcdf): + """ + Create the 'y' and 'x' variables. + + Parameters + ---------- + netcdf : Dataset + NetCDF object. + """ + + super(MercatorNes, self)._create_dimension_variables(netcdf) + + # MERCATOR Y COORDINATES + y = netcdf.createVariable('y', self._y['data'].dtype, ('y',)) + y.long_name = "y coordinate of projection" + if 'units' in self._y.keys(): + y.units = Units(self._y['units'], formatted=True).units + else: + y.units = 'm' + y.standard_name = "projection_y_coordinate" + if self.size > 1: + y.set_collective(True) + y[:] = self._y['data'] + + # MERCATOR X COORDINATES + x = netcdf.createVariable('x', self._x['data'].dtype, ('x',)) + x.long_name = "x coordinate of projection" + if 'units' in self._x.keys(): + x.units = Units(self._x['units'], formatted=True).units + else: + x.units = 'm' + x.standard_name = "projection_x_coordinate" + if self.size > 1: + x.set_collective(True) + x[:] = self._x['data'] + + return None + + def _create_centroids(self, **kwargs): + """ + Calculate center latitudes and longitudes from grid details. + + Parameters + ---------- + netcdf : Dataset + NetCDF object. + """ + + # Create a regular grid in metres (1D) + self._x = {'data': np.linspace(kwargs['x_0'] + (kwargs['inc_x'] / 2), + kwargs['x_0'] + (kwargs['inc_x'] / 2) + + (kwargs['inc_x'] * (kwargs['nx'] - 1)), kwargs['nx'], + dtype=np.float)} + + + self._y = {'data': np.linspace(kwargs['y_0'] + (kwargs['inc_y'] / 2), + kwargs['y_0'] + (kwargs['inc_y'] / 2) + + (kwargs['inc_y'] * (kwargs['ny'] - 1)), kwargs['ny'], + dtype=np.float)} + + # Create a regular grid in metres (1D to 2D) + x = np.array([self._x['data']] * len(self._y['data'])) + y = np.array([self._y['data']] * len(self._x['data'])).T + + projection = Proj( + proj='merc', + a=6370000.00, + b=6370000.00, + lat_ts=kwargs['lat_ts'], + lon_0=kwargs['lon_0'], + ) + + # Calculate center latitudes and longitudes (UTM to Mercator) + self.center_lons, self.center_lats = projection(x, y, inverse=True) + + return {'data': self.center_lats}, {'data': self.center_lons} + + @staticmethod + def _set_var_crs(var): + """ + Set the grid_mapping to 'mercator'. + + Parameters + ---------- + var : Variable + netCDF4-python variable object. + """ + var.grid_mapping = 'mercator' + + return None + + def _create_metadata(self, netcdf): + """ + Create the 'crs' variable for the Mercator grid_mapping. + + Parameters + ---------- + netcdf : Dataset + netcdf4-python Dataset + """ + + mapping = netcdf.createVariable('mercator', 'c') + mapping.grid_mapping_name = self.projection_data['grid_mapping_name'] + mapping.standard_parallel = self.projection_data['standard_parallel'] + mapping.longitude_of_projection_origin = self.projection_data['longitude_of_projection_origin'] + + return None diff --git a/nes/nc_projections/points_nes.py b/nes/nc_projections/points_nes.py index 0471cb68f79fc1ab926b6869d85410c84d3c8174..4759073cda9ebf69c447eb4bd2dc648d75b3be5a 100644 --- a/nes/nc_projections/points_nes.py +++ b/nes/nc_projections/points_nes.py @@ -108,7 +108,7 @@ class PointsNes(Nes): Number of hours to remove from last time steps. parallel_method : str Indicates the parallelization method that you want. Default over Y axis - accepted values: ['Y', 'T'] + accepted values: ['X'] """ new = PointsNes(comm=comm, path=path, info=info, dataset=dataset, xarray=xarray, balanced=balanced, parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, diff --git a/nes/nc_projections/points_nes_ghost.py b/nes/nc_projections/points_nes_ghost.py index 59b708465e140ce8f2f140310e9ae1dfdc840076..386e4f3cc4b0109b70993472b2e32bef92946227 100644 --- a/nes/nc_projections/points_nes_ghost.py +++ b/nes/nc_projections/points_nes_ghost.py @@ -83,7 +83,7 @@ class PointsNesGHOST(PointsNes): Number of hours to remove from last time steps. parallel_method : str Indicates the parallelization method that you want. Default over Y axis - accepted values: ['Y', 'T'] + accepted values: ['X'] """ new = PointsNesGHOST(comm=comm, path=path, info=info, dataset=dataset, xarray=xarray, balanced=balanced, parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, diff --git a/nes/nc_projections/rotated_nes.py b/nes/nc_projections/rotated_nes.py index 6132742cbb5700e3cb2377e236badb00f1835d20..935aa252c7ceea693fe729d13308615beb73fa7d 100644 --- a/nes/nc_projections/rotated_nes.py +++ b/nes/nc_projections/rotated_nes.py @@ -112,7 +112,7 @@ class RotatedNes(Nes): Number of hours to remove from last time steps. parallel_method : str Indicates the parallelization method that you want. Default over Y axis - accepted values: ['Y', 'T'] + accepted values: ['X', 'Y', 'T'] """ new = RotatedNes(comm=comm, path=path, info=info, dataset=dataset, xarray=xarray, balanced=balanced, parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, @@ -174,7 +174,10 @@ class RotatedNes(Nes): # ROTATED LATITUDES rlat = netcdf.createVariable('rlat', self._rlat['data'].dtype, ('rlat',)) rlat.long_name = "latitude in rotated pole grid" - rlat.units = Units("degrees", formatted=True).units + if 'units' in self._rlat.keys(): + rlat.units = Units(self._rlat['units'], formatted=True).units + else: + rlat.units = 'degrees' rlat.standard_name = "grid_latitude" if self.size > 1: rlat.set_collective(True) @@ -183,7 +186,10 @@ class RotatedNes(Nes): # ROTATED LONGITUDES rlon = netcdf.createVariable('rlon', self._rlon['data'].dtype, ('rlon',)) rlon.long_name = "longitude in rotated pole grid" - rlon.units = Units("degrees", formatted=True).units + if 'units' in self._rlon.keys(): + rlon.units = Units(self._rlon['units'], formatted=True).units + else: + rlon.units = 'degrees' rlon.standard_name = "grid_longitude" if self.size > 1: rlon.set_collective(True) diff --git a/tests/2-nes_tests_by_projection.py b/tests/2-nes_tests_by_projection.py index da542f42122247e62ccf1d43478ddd8d7a999b8c..098a5ab781cf1b09d33f45d20047b7b5daae1099 100644 --- a/tests/2-nes_tests_by_projection.py +++ b/tests/2-nes_tests_by_projection.py @@ -24,7 +24,11 @@ paths = {'regular_file': {'path': '/gpfs/scratch/bsc32/bsc32538/mr_multiplyby/or 'lcc_file': {'path': '/esarchive/exp/wrf-hermes-cmaq/b075/eu/hourly/pm10/pm10_2022062600.nc', 'projection': 'lcc', 'variables': [], # all - 'parallel_methods': ['X', 'Y', 'T']} + 'parallel_methods': ['X', 'Y', 'T']}, + 'mercator_file': {'path': '/gpfs/projects/bsc32/bsc32543/hermesv3_gr/OUT/HERMESv3_MercatorTest_2018010100.nc', + 'projection': 'mercator', + 'variables': [], # all + 'parallel_methods': ['X', 'Y', 'T']} } results = []