Skip to content

Commit

Permalink
Merge branch 'v2.0' of http://github.com/GeoscienceAustralia/tcrm int…
Browse files Browse the repository at this point in the history
…o v2.0
  • Loading branch information
wcarthur committed Mar 2, 2017
2 parents 45e2eac + 2eaa9c4 commit d16b218
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 37 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ addons:
packages:
- build-essential
- libgeos-c1
- lib-geos-dev
- libhdf5-serial-dev
- libatlas-base-dev
- gfortran
Expand Down
5 changes: 4 additions & 1 deletion PlotInterface/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ def addGraticule(self, axes, mapobj):
dd = max(dx, dy)
gr_opts = np.array([30., 10., 5., 4., 2.])
min_gr = 5
dl = gr_opts[np.where((dd/gr_opts) >= min_gr)[0][0]]
try:
dl = gr_opts[np.where((dd/gr_opts) >= min_gr)[0][0]]
except IndexError:
dl = 2.

meridians = np.arange(dl*np.floor(xmin / dl),
dl*np.ceil(xmax / dl) + dl, dl)
Expand Down
22 changes: 10 additions & 12 deletions TrackGenerator/trackSize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

LOG = logging.getLogger()

def rmax(dp, lat, eps, coeffs=[4.4726049824584306,
-0.04057322103602546,
0.00031318220949448573,
0.00014553984831170656]):
def rmax(dp, lat, eps, coeffs=[3.5843946536979779,-0.0045486143609339436,
0.78621467400844858, 0.0024030344245284741,
0.0015567629057007433]):
"""
Calculate radius to maximum wind based on pressure deficit and
latitude. This function allows for the random variate to be set
when calling the function. Default coefficients for the functional
form of ln(Rmw) are given, based on JTWC data for the southern hemisphere.
ln(Rmw) = a + b*dp + c*dp^2 + d*lat^2 + eps
ln(Rmw) = a + b*dp + c*exp(-d*dp^2) + f*lat^2 + eps
eps is not included in the coefficients (though that may be considered
by some to be more logical), so that it can remain constant for a single
Expand All @@ -47,17 +46,16 @@ def rmax(dp, lat, eps, coeffs=[4.4726049824584306,
if len(coeffs) < 4:
LOG.warn("Insufficient coefficients for rmw calculation!")
LOG.warn("Using default values")
coeffs = [4.4726049824584306,
-0.04057322103602546,
0.00031318220949448573,
0.00014553984831170656]
coeffs = [3.5843946536979779,-0.0045486143609339436,
0.78621467400844858, 0.0024030344245284741,
0.0015567629057007433]

if isinstance(dp, (np.ndarray, list)) and \
isinstance(lat, (np.ndarray, list)):
assert len(dp) == len(lat)
rm = np.exp(coeffs[0] + coeffs[1] * dp + coeffs[2] * dp * dp +
coeffs[3] * lat * lat + eps)
yy = coeffs[0] + coeffs[1]*dp + coeffs[2] * np.exp(-coeffs[3] * dp * dp) +\
coeffs[4] * np.abs(lat) + eps
rm = np.exp(yy)
return rm

def fitRmax(rmw, dp, lat):
Expand Down
7 changes: 6 additions & 1 deletion Utilities/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

from netCDF4 import Dataset, date2num, num2date

try:
from exceptions import WindowsError
except:
class WindowsError(IOError): pass

#if not getattr(__builtins__, "WindowsError", None):
# class WindowsError(IOError):
# pass
Expand Down Expand Up @@ -425,5 +430,5 @@ def loadTracksFromPath(path):
msg = "Loading {0} track files in {1}".format(len(trackfiles), path)
log.info(msg)
return loadTracksFromFiles(sorted(trackfiles))
except (IOError, WindowsError):
except (IOError, OSError, WindowsError):
raise IOError("Path {0} does not exist".format(path))
17 changes: 12 additions & 5 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ the ``$PATH`` for this to work.
Compiling the extensions
------------------------

Unix
~~~~
The model requires a number of C extensions to be compiled before
execution. These can be built using Python's inbuilt :mod:`distutils`
module. Copy the required files from the `installer` directory to the
base directory and then execute the build process::
module.


Unix
~~~~
From the base directory, execute the build process::

python intaller/setup.py build_ext -i

Expand All @@ -120,7 +122,12 @@ Windows
~~~~~~~

For Windows users, the code includes the ``compile.cmd`` script in the
main TCRM diretory that will build these extensions in place.
main TCRM diretory that will build these extensions in place. By default, TCRM uses the MinGW suite (http://www.mingw.org) for compiling the extensions. Other Windows-based packages can also be used (e.g. Cygwin). See the Python documentation on writing configuration files for the :mod:`distutils` package for more details.

Notes
~~~~~

It is recommended to use a stand-alone Python installation for compiling and running TCRM. Installations linked to other software such as ArcGIS have resulted in compilation errors, as the required :mod:`numpy` libraries are pre-compiled and packaged with such installations.

.. _testing:

Expand Down
33 changes: 16 additions & 17 deletions tests/test_trackSize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,48 @@ def setUp(self):
np.random.seed(10)
self.dparray = np.arange(10, 51, 5)
self.latarray = np.arange(-23, -5, 2)
self.rmaxout = np.array([104.08747056, 87.24373672, 74.36633603,
64.46512563, 56.83025497, 50.94959054,
46.45239542, 43.07069234, 40.61270477])
self.rmaxoutcoeffs = np.array([109.4918411, 90.31016614,
75.35799588, 63.61504735,
54.32855894, 46.93905396,
41.02780616, 36.27939815,
32.45485465])
self.rmaxout = np.array([66.21418972, 54.96078787, 45.7678418,
39.33639152, 35.22023191, 32.67958816,
31.07181726, 29.95463557, 29.06996118])

self.rmaxoutcoeffs = np.array([57.74931727, 49.76638251, 42.67145839,
37.24632781, 33.47199844, 30.98197273,
29.3570741, 28.25288743, 27.43217413])


def test_rmaxDefaults(self):
"""Test rmax returns correct value based on defaults"""
dp = 25
lat = -15
eps = np.random.normal(0, scale=0.353)
eps = 0
rmw = trackSize.rmax(dp, lat, eps)
self.assertEqual(rmw, 63.867449833342235)
self.assertAlmostEqual(rmw, 39.21410711, places=1)

def test_rmaxWrongLengths(self):
"""rmax raises exception when inputs are different lengths"""
eps = np.random.normal(0, scale=0.353)
eps = 0
latarray = np.arange(-23, 5, 2)
self.assertRaises(Exception, trackSize.rmax, self.dparray, latarray, eps)

def test_rmaxArrayInput(self):
"""Test rmax with array input"""
eps = np.random.normal(0, scale=0.353)
eps = 0
rmw = trackSize.rmax(self.dparray, self.latarray, eps)
self.numpyAssertAlmostEqual(rmw, self.rmaxout)
self.numpyAssertAlmostEqual(rmw, self.rmaxout, prec=0.1)

def test_rmaxWithCoeffs(self):
"""Test rmax with user-defined coefficients"""
eps = np.random.normal(0, scale=0.353)
coeffs = [4.5, -0.04, 0.0002, 0.0002]
eps = 0
coeffs = [3.5, -0.004, 0.7, 0.002, .001]
rmw = trackSize.rmax(self.dparray, self.latarray, eps, coeffs)
self.numpyAssertAlmostEqual(rmw, self.rmaxoutcoeffs)

def test_rmaxWithIncompleteCoeffs(self):
"""Test rmax falls back to default coefficients if not enough given"""
coeffs = [4.45, -0.05, 0.0002]
eps = np.random.normal(0, scale=0.353)
eps = 0
rmw = trackSize.rmax(self.dparray, self.latarray, eps, coeffs=coeffs)
self.numpyAssertAlmostEqual(rmw, self.rmaxout)
self.numpyAssertAlmostEqual(rmw, self.rmaxout, prec=0.1)

class TestFitRmax(NumpyTestCase.NumpyTestCase):
"""
Expand Down

0 comments on commit d16b218

Please sign in to comment.