diff --git a/tests/BackendTests.py b/tests/BackendTests.py index 755806e..d9b4dba 100644 --- a/tests/BackendTests.py +++ b/tests/BackendTests.py @@ -5,9 +5,10 @@ import unittest from datetime import datetime as ddatetime, datetime from pprint import pprint +import numpy.ma.core from netCDF4 import Dataset -from web.run import retrieve_amda_netcdf, get_data_for_target, _sta_sto, _read_var +from web.run import retrieve_amda_netcdf, get_data_for_target, _sta_sto, _read_var, default_nc_keys FILE_DATE_FMT = "%Y-%m-%d %H:%M:%S" @@ -72,21 +73,11 @@ class AmdaTestCase(BaseTestCase): self.assertIsInstance(s0, datetime) self.assertIsInstance(s1, datetime) - def test_read_nc(self): + def test_var_read_nc_float32(self): SCRIPT_PATH = os.path.dirname(__file__) PROJECT_DIR = os.path.abspath(os.path.join(SCRIPT_PATH, os.pardir)) 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]) + self.assertIsInstance(data_v[0], numpy.float32) diff --git a/web/run.py b/web/run.py index c0622b9..f02ac9c 100644 --- a/web/run.py +++ b/web/run.py @@ -332,6 +332,16 @@ def datetime_from_list(time_list): "%Y%j%H%M%S%f" ) +# Override these using the model configuration in config.yml +default_nc_keys = { + 'hee': 'HEE', + 'vtot': 'V', + 'magn': 'B', + 'temp': 'T', + 'dens': 'N', + 'pdyn': 'P_dyn', + 'atse': 'Delta_angle', +} def _sta_sto(_cnf, _sta, _sto): if 'started_at' in _cnf: @@ -349,7 +359,7 @@ def _sta_sto(_cnf, _sta, _sto): def _read_var(_nc, _keys, _key, mandatory=False): try: - return _nc.variables[_keys[_key]] + return _nc.variables[_keys[_key]][:] except KeyError: pass if mandatory: @@ -673,16 +683,6 @@ def get_data_for_target(target_config, input_slug, # abort(500, "Invalid orbit configuration for '%s' : %s" # % (target_config['slug'], str(e))) - # Override these using the model configuration in config.yml - default_nc_keys = { - 'hee': 'HEE', - 'vtot': 'V', - 'magn': 'B', - 'temp': 'T', - 'dens': 'N', - 'pdyn': 'P_dyn', - 'atse': 'Delta_angle', - } precision = "%Y-%m-%dT%H" # model and orbits times are only equal-ish orbit_data = {} # keys are datetime as str, values arrays of XY -- libgit2 0.21.2