Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check lat lon #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cruAKtemp/bmi_cruAKtemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ 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',
'atmosphere_bottom_air__temperature_year': 'T_air_prior_year'
}

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',
Expand Down Expand Up @@ -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,
Expand Down
59 changes: 59 additions & 0 deletions cruAKtemp/examples/checking_cru_lat_lon.py
Original file line number Diff line number Diff line change
@@ -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')