diff --git a/tests/BackendTests.py b/tests/BackendTests.py index edc43de..d0b3328 100644 --- a/tests/BackendTests.py +++ b/tests/BackendTests.py @@ -1,9 +1,13 @@ +import gzip +import os.path import sys import unittest from datetime import datetime as ddatetime, datetime from pprint import pprint -from web.run import retrieve_amda_netcdf, get_data_for_target, _sta_sto +from netCDF4 import Dataset + +from web.run import retrieve_amda_netcdf, get_data_for_target, _sta_sto, _read_var FILE_DATE_FMT = "%Y-%m-%d %H:%M:%S" @@ -55,7 +59,7 @@ class AmdaTestCase(BaseTestCase): stopped_at = ddatetime.strptime("2021-12-18 00:00:00", FILE_DATE_FMT) model = {'parameters': {'dens': 'Dens', 'temp': 'Temp', 'vtot': 'Vel'}, 'slug': 'ace_swepam_real_1h'} s0, s1 = _sta_sto(model, started_at, stopped_at) - all_data = get_data_for_target(target_config, 'om', s0, s1 ) + all_data = get_data_for_target(target_config, 'om', s0, s1) self.assertEqual(1, len(all_data)) def test_sta_sto(self): @@ -68,3 +72,24 @@ class AmdaTestCase(BaseTestCase): self.assertIsInstance(s0, datetime) self.assertIsInstance(s1, datetime) + def test_read_nc(self): + SCRIPT_PATH = os.path.dirname(__file__) + PROJECT_DIR = os.path.abspath(os.path.join(SCRIPT_PATH, os.pardir)) + print("PROJECT_DIR", PROJECT_DIR) + print("SCRIPT_PATH", SCRIPT_PATH) + # return + local_netc_file = os.path.join(PROJECT_DIR,'tests-resources', 'amda-irap-omp-eu-ddservice-base-data-omni-hour-omni202107010-nc') + cdf_handle = Dataset(local_netc_file, "r", format="NETCDF4") + default_nc_keys = { + 'hee': 'HEE', + 'vtot': 'V', + 'magn': 'B', + 'temp': 'T', + 'dens': 'N', + 'pdyn': 'P_dyn', + 'atse': 'Delta_angle', + } + nc_keys = default_nc_keys.copy() + data_v = _read_var(cdf_handle, nc_keys, 'vtot') + pprint(data_v) + pprint(data_v[0]) -- libgit2 0.21.2