diff --git a/cruAKtemp/bmi_cruAKtemp.py b/cruAKtemp/bmi_cruAKtemp.py index f3d9b57..dff352d 100644 --- a/cruAKtemp/bmi_cruAKtemp.py +++ b/cruAKtemp/bmi_cruAKtemp.py @@ -53,6 +53,8 @@ def __init__(self): ) self._var_name_map = { + 'latitude': '_latitude', + 'longitude': '_longitude', 'atmosphere_bottom_air__temperature': 'T_air', 'atmosphere_bottom_air__temperature_mean_jan': 'T_air_prior_jan', 'atmosphere_bottom_air__temperature_mean_jul': 'T_air_prior_jul', @@ -60,6 +62,8 @@ def __init__(self): } self._var_units_map = { + 'latitude': 'degree_north', + 'longitude': 'degree_east', 'atmosphere_bottom_air__temperature': 'deg_C', 'atmosphere_bottom_air__temperature_mean_jan': 'deg_C', 'atmosphere_bottom_air__temperature_mean_jul': 'deg_C', @@ -97,6 +101,8 @@ def initialize(self, cfg_file=None): self._values = { # These are the links to the model's variables and # should be consistent with _var_name_map + 'latitude': self._model._latitude, + 'longitude': self._model._longitude, 'atmosphere_bottom_air__temperature': self._model.T_air, 'atmosphere_bottom_air__temperature_mean_jan': self._model.T_air_prior_jan, 'atmosphere_bottom_air__temperature_mean_jul': self._model.T_air_prior_jul, diff --git a/cruAKtemp/examples/checking_cru_lat_lon.py b/cruAKtemp/examples/checking_cru_lat_lon.py new file mode 100644 index 0000000..e118d2a --- /dev/null +++ b/cruAKtemp/examples/checking_cru_lat_lon.py @@ -0,0 +1,59 @@ +""" +couple_cru_KUGeo.py + +Example that couples cruAKtemp to KUGeo! + +""" + +from __future__ import print_function + +import numpy as np +from netCDF4 import Dataset + +from cruAKtemp.bmi_cruAKtemp import BmiCruAKtempMethod +from cruAKtemp.tests import data_directory + +# Initial both components with local config files +cru_config_file = "default_temperature.cfg" + +cru = BmiCruAKtempMethod() + +cru.initialize(cru_config_file) + +n_x_0 = cru._model._nc_i0 +n_y_0 = cru._model._nc_j0 +n_x_1 = cru._model._nc_i1 +n_y_1 = cru._model._nc_j1 + +t = cru.get_current_time() + +lat = cru.get_value('latitude') +lon = cru.get_value('longitude') +tmp = cru.get_value('atmosphere_bottom_air__temperature') + +tmp = np.ma.masked_less_equal(tmp, -90.) + +#print ('from BMI:', lat.max(),lat.min(), tmp.max(), tmp.min()) + +example_filename = data_directory + '/'+'cru_alaska_lowres_temperature.nc' + +# First: check the exact extent by column and row: + +ncid = Dataset(example_filename) + +lat_raw = ncid.variables['lat'][n_y_0:n_y_1,n_x_0:n_x_1] +lon_raw = ncid.variables['lon'][n_y_0:n_y_1,n_x_0:n_x_1] +lon_raw = ncid.variables['lon'][n_y_0:n_y_1,n_x_0:n_x_1] +tmp_raw = ncid.variables['temp'][0,n_y_0:n_y_1,n_x_0:n_x_1] + +tmp_raw = np.ma.masked_less_equal(tmp_raw, -90.) + +#print ('netCDF:', lat_raw.max(),lat_raw.min(), tmp_raw.max(), tmp_raw.min()) + +lat_cmp = np.abs(lat_raw - lat) +lon_cmp = np.abs(lon_raw - lon) +tmp_cmp = np.abs(tmp_raw - tmp) + +if (lat_cmp.max()>1E-7 or lon_cmp.max()>1E-7): + raise RuntimeError('Error') +