From bcec1d315e2ce1d05dea79da3400df14b68c3ccd Mon Sep 17 00:00:00 2001 From: Alba Vilanova Date: Thu, 14 Jul 2022 16:44:44 +0200 Subject: [PATCH] Get dtype by data --- Jupyter_notebooks/1.3-points_grids.ipynb | 222 ++++++++++---------- Jupyter_notebooks/2.1-create_nes_port.ipynb | 63 +++--- nes/nc_projections/points_nes.py | 22 +- 3 files changed, 146 insertions(+), 161 deletions(-) diff --git a/Jupyter_notebooks/1.3-points_grids.ipynb b/Jupyter_notebooks/1.3-points_grids.ipynb index b551974..966ab17 100644 --- a/Jupyter_notebooks/1.3-points_grids.ipynb +++ b/Jupyter_notebooks/1.3-points_grids.ipynb @@ -418,7 +418,7 @@ " station_end_date (station) |S75 b'nan' b'nan' ... b'nan' b'nan'\n", " station_rural_back (station) |S75 b'nan' b'nan' ... b'nan' b'nan'\n", " latitude (station) float32 46.81 47.48 ... 53.33 38.88\n", - " station_ozone_classification (station) |S75 b'rural' b'rural' ... b'nan'
  • " ], "text/plain": [ "\n", @@ -710,7 +710,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 4, @@ -1409,7 +1409,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 14, @@ -1808,7 +1808,7 @@ " lat (station) float64 46.81 47.48 ... 53.33 38.88\n", " lon (station) float64 6.944 8.905 ... 6.277 16.23\n", "Attributes:\n", - " Conventions: CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", @@ -2501,7 +2501,7 @@ " source: Surface observations\n", " creator_name: Dene R. Bowdalo\n", " creator_email: dene.bowdalo@bsc.es\n", - " version: 1.4
  • title :
    Surface sulphate data in the EANET network in 2019-11.
    institution :
    Barcelona Supercomputing Center
    source :
    Surface observations
    creator_name :
    Dene R. Bowdalo
    creator_email :
    dene.bowdalo@bsc.es
    version :
    1.4
  • " ], "text/plain": [ "\n", @@ -2727,7 +2727,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 18, @@ -3980,7 +3980,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 26, @@ -4386,7 +4386,7 @@ " creator_name: Dene R. Bowdalo\n", " creator_email: dene.bowdalo@bsc.es\n", " version: 1.4\n", - " Conventions: CF-1.7
  • title :
    Surface sulphate data in the EANET network in 2019-11.
    institution :
    Barcelona Supercomputing Center
    source :
    Surface observations
    creator_name :
    Dene R. Bowdalo
    creator_email :
    dene.bowdalo@bsc.es
    version :
    1.4
    Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", diff --git a/Jupyter_notebooks/2.1-create_nes_port.ipynb b/Jupyter_notebooks/2.1-create_nes_port.ipynb index f409c1a..e66b4f8 100644 --- a/Jupyter_notebooks/2.1-create_nes_port.ipynb +++ b/Jupyter_notebooks/2.1-create_nes_port.ipynb @@ -416,7 +416,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/esarchive/scratch/avilanova/software/NES/nes/nc_projections/points_nes.py:411: 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:405: UserWarning: WARNING!!! Different data types for variable station_nameInput dtype=, data dtype=object\n", " warnings.warn(msg)\n" ] }, @@ -804,16 +804,16 @@ " 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", @@ -1023,7 +1023,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -1095,35 +1095,26 @@ ], "source": [ "for (year, month), current in df_data.groupby(['year', 'month']):\n", - " \n", - " # Transform station names into S75 type\n", - " station_names_S75 = []\n", - " for x in current.columns[2:4].to_numpy():\n", - " station_name_S75 = [x[i:i + 1] for i in range(0, 75, 1)]\n", - " station_names_S75.append(station_name_S75)\n", - " station_name = np.array(station_names_S75).astype('S1')\n", - " \n", + "\n", " # Read time\n", " times = current.index.to_pydatetime()\n", " \n", " # Fill altitude with nans\n", " altitude = np.full(len(current.columns[2:4]), np.nan)\n", - " \n", + " \n", " # Read metadata\n", - " metadata = {'station_name': {'data': station_name,\n", - " 'dimensions': ('station', 'strlen'),\n", - " 'standard_name': '',\n", - " 'dtype': 'S1'},\n", + " metadata = {'station_name': {'data': current.columns[2:4].to_numpy(),\n", + " 'dimensions': ('station'),\n", + " 'standard_name': ''},\n", " 'altitude': {'data': altitude,\n", " 'dimensions': ('station',),\n", " 'units': 'meters',\n", - " 'standard_name': 'altitude',\n", - " 'dtype': float},\n", + " 'standard_name': 'altitude'},\n", " 'sconcno2': {'data': current.iloc[:, 2:4].to_numpy(),\n", " 'units': 'µg m-3',\n", " 'dimensions': ('time', 'station',),\n", - " 'long_name': '',\n", - " 'dtype': float}}\n", + " 'long_name': ''}\n", + " }\n", " \n", " # Create object\n", " points_grid = create_nes(comm=None, info=False, projection=None, parallel_method='X',\n", @@ -1141,7 +1132,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -1504,22 +1495,22 @@ " * time (time) datetime64[ns] 2017-05-01 ... 2017-05-31T23: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", + " station_name (station) object 'NO2-UM' 'NO2-ZAL Prat'\n", " altitude (station) float64 nan nan\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", @@ -1528,7 +1519,7 @@ " * time (time) datetime64[ns] 2017-05-01 ... 2017-05-31T23:00:00\n", " * station (station) float64 0.0 1.0\n", "Data variables:\n", - " station_name (station) |S75 ...\n", + " station_name (station) object ...\n", " altitude (station) float64 ...\n", " sconcno2 (time, station) float64 ...\n", " lat (station) float64 ...\n", @@ -1537,7 +1528,7 @@ " Conventions: CF-1.7" ] }, - "execution_count": 16, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -1548,7 +1539,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -1911,22 +1902,22 @@ " * 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", + " station_name (station) object 'NO2-UM' 'NO2-ZAL Prat'\n", " altitude (station) float64 nan nan\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", @@ -1935,7 +1926,7 @@ " * 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", + " station_name (station) object ...\n", " altitude (station) float64 ...\n", " sconcno2 (time, station) float64 ...\n", " lat (station) float64 ...\n", @@ -1944,7 +1935,7 @@ " Conventions: CF-1.7" ] }, - "execution_count": 17, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } diff --git a/nes/nc_projections/points_nes.py b/nes/nc_projections/points_nes.py index 1b134c0..e0bec7f 100644 --- a/nes/nc_projections/points_nes.py +++ b/nes/nc_projections/points_nes.py @@ -364,18 +364,6 @@ class PointsNes(Nes): if 'dimensions' in var_dict.keys(): # Get dimensions var_dims = var_dict['dimensions'] - - # Convert list of strings to chars - try: - longest_str = max(var_dict['data'], key=len) - if hasattr(longest_str, '__len__'): - unicode_type = len(longest_str) - if var_dict['data'].dtype == np.dtype('