ecmwf: correct bug on ensemble ingest
2 files changed, 36 insertions(+), 35 deletions(-)

M meteo_scraper/ecmwf_scraper.py
M test/test_ecmwf.py
M meteo_scraper/ecmwf_scraper.py +34 -35
@@ 129,42 129,41 @@ def exploit_grib_file_hres(tsa, gribfile
             tsa.replace(seriesname, ts, author='scraper-ecmwf')
 
 
-def exploit_grib_file_ens(tsa, gribfile):
-    for param, unit in PARAMETERS.values():
-        print(f'retrieving {param} for zones...')
-        gt = gribfile[param]
-        print(f'subset for param {param} ready')
-        values = mv.values(gt)
-        print(f'values for param {param} ready')
-        index = np.unique(mv.valid_date(gt))
+def exploit_grib_file_ens(tsa, gribfile, param, unit):
+    print(f'retrieving {param} for zones...')
+    gt = gribfile[param]
+    print(f'subset for param {param} ready')
+    values = mv.values(gt)
+    print(f'values for param {param} ready')
+    index = np.unique(mv.valid_date(gt))
 
-        for zone in ZONES:
-            mask_zone = construct_zone_mask(zone, np.shape(values))
-            val_zone = values[:, mask_zone]
-            val_mean_zone = np.mean(val_zone, axis=1)
-            list_ts = []
-            for ens in range(51):
-                ens_values =  val_mean_zone[[51*(i) + ens for i in range(len(index))]]
-                ts = pd.Series(data=ens_values, index = index)
-                list_ts.append(ts.to_frame(ens+1))
-            df = pd.concat(list_ts, axis=1)
+    for zone in ZONES:
+        mask_zone = construct_zone_mask(zone, np.shape(values))
+        val_zone = values[:, mask_zone]
+        val_mean_zone = np.mean(val_zone, axis=1)
+        list_ts = []
+        for ens in range(51):
+            ens_values =  val_mean_zone[[51*(i) + ens for i in range(len(index))]]
+            ts = pd.Series(data=ens_values, index = index)
+            list_ts.append(ts.to_frame(ens+1))
+        df = pd.concat(list_ts, axis=1)
 
-            group_name = f'meteo.area.{zone.lower()}.{param}.{unit.lower()}.ens.ecmwf.fcst.3-6h'
-            tsa.group_replace(group_name, df, author='scraper-ecmwf')
+        group_name = f'meteo.area.{zone.lower()}.{param}.{unit.lower()}.ens.ecmwf.fcst.3-6h'
+        tsa.group_replace(group_name, df, author='scraper-ecmwf')
 
-        # print(f'retrieving {param} for cities...')
-        # for row in CITIES.iterrows():
-        #     print(row)
-        #     index_city = nearest_gridpoint(row[1].lng, row[1].lat)
-        #     val_city = values[:, index_city]
-        #     list_ts = []
-        #     for ens in range(51):
-        #         ens_values =  val_city[[51*(i) + ens for i in range(len(index))]]
-        #         ts = pd.Series(data=ens_values, index = index)
-        #         list_ts.append(ts.to_frame(ens+1))
-        #     df = pd.concat(list_ts, axis=1)
-        #     group_name = f"meteo.city.{(row[1].country).replace(' ', '').lower()}.{(row[1].city_ascii).replace(' ', '').lower()}.{param}.{unit.lower()}.ens.ecmwf.fcst.3h"
-        #     tsa.group_replace(group_name, df, author='scraper-ecmwf')
+    # print(f'retrieving {param} for cities...')
+    # for row in CITIES.iterrows():
+    #     print(row)
+    #     index_city = nearest_gridpoint(row[1].lng, row[1].lat)
+    #     val_city = values[:, index_city]
+    #     list_ts = []
+    #     for ens in range(51):
+    #         ens_values =  val_city[[51*(i) + ens for i in range(len(index))]]
+    #         ts = pd.Series(data=ens_values, index = index)
+    #         list_ts.append(ts.to_frame(ens+1))
+    #     df = pd.concat(list_ts, axis=1)
+    #     group_name = f"meteo.city.{(row[1].country).replace(' ', '').lower()}.{(row[1].city_ascii).replace(' ', '').lower()}.{param}.{unit.lower()}.ens.ecmwf.fcst.3h"
+    #     tsa.group_replace(group_name, df, author='scraper-ecmwf')
 
 
 def hres_ecmwfdata_to_refinery(tsa, filename_hres):

          
@@ 173,6 172,6 @@ def hres_ecmwfdata_to_refinery(tsa, file
 
 
 def ens_ecmwfdata_to_refinery(tsa, filename_ens):
-    for param in PARAMS:
+    for param, unit in PARAMETERS.values():
         gribfile_ens = mv.read(f'{param}_{filename_ens}')
-        exploit_grib_file_ens(tsa, gribfile_ens)
+        exploit_grib_file_ens(tsa, gribfile_ens, param, unit)

          
M test/test_ecmwf.py +2 -0
@@ 1,6 1,7 @@ 
 import metview as mv
 import numpy as np
 
+
 def test_det_values():
     param = '2t'
     filename = 'ecmwf_hres.grib'

          
@@ 10,6 11,7 @@ def test_det_values():
 
     assert np.shape(values)[1] == 405900
 
+
 def test_ens_values():
     param = '2t'
     filename = 'ecmwf_ens.grib'