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
Changes from 1 commit
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
Prev Previous commit
compare latitude and longitude BMI
added a test script "checking_cru_lat_lon.py" under "Example" folder. I compared latitude and longitude from BMI and directly from netCDF files. They should be the same.
CryoECNU committed Jun 6, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 5b05be9c7fb3f8e774d7b82111c3af67389012d5
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')