Skip to content

Commit

Permalink
Merge pull request #88 from JoyMonteiro/develop
Browse files Browse the repository at this point in the history
Refactor of init code
  • Loading branch information
JoyMonteiro authored Oct 9, 2018
2 parents 6b2ecbb + 500e32b commit 5aa011f
Show file tree
Hide file tree
Showing 165 changed files with 613 additions and 1,466 deletions.
8 changes: 4 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ environment:
matrix:
- PYTHON_VERSION: "3.6"
MINICONDA: "C:\\Miniconda36-x64"
# - PYTHON_VERSION: "3.5"
# MINICONDA: "C:\\Miniconda35-x64"
- PYTHON_VERSION: "3.7"
MINICONDA: "C:\\Miniconda37-x64"

platform:
- x64
Expand Down Expand Up @@ -42,15 +42,15 @@ install:
- conda install libpython
- python -m pip install -r requirements_dev.txt
- conda upgrade pip setuptools wheel
# - set COMPILER_PATH=C:\\msys64\\mingw64\\bin\\
# - set COMPILER_PATH=C:\\msys64\\mingw64\\bin\\

build_script:
- bash -c "cd /c/projects/climt/; python setup.py develop"
# - bash -c "cd /c/projects/climt/; python setup.py build --compiler=mingw32"

test_script:
- conda install pytest
- bash -c "cd /c/projects/climt; py.test"
- bash -c "cd /c/projects/climt; py.test -v"
# - bash -c "cd /c/projects/climt; find . |grep _components"

after_test:
Expand Down
109 changes: 86 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ services: docker
language: python
python: 3.6

#branches:
# except:
# - sympl-0.4.0

cache:
- pip
- directories: ~/build/CliMT/climt/climt/_lib/Linux
- directories: ~/build/CliMT/climt/climt/_lib/Darwin
env:
global:
- TWINE_USERNAME=joy.merwin
Expand All @@ -30,14 +28,29 @@ allow_failures:

before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install gfortran; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -sSL https://rvm.io/mpapis.asc | gpg --import -; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rvm get stable ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew cask uninstall oclint ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gcc ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew upgrade python ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then python3 -m venv climt_venv ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source climt_venv/bin/activate ; fi
- |
if [[ "$TRAVIS_OS_NAME" == "osx" ]];
then curl -sSL https://rvm.io/mpapis.asc | gpg --import -
rvm get stable
brew update
sudo softwareupdate -i "Command Line Tools (macOS High Sierra version 10.13) for Xcode-9.4"
brew cask uninstall oclint
brew install gcc@6
brew install md5sha1sum
fi
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh;
fi
- |
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
bash miniconda.sh -b -p $HOME/miniconda
export PATH="$HOME/miniconda/bin:$PATH"
hash -r
conda config --set always_yes yes --set changeps1 no
conda info -a
fi
install:
- python -m pip install -r requirements_dev.txt
Expand Down Expand Up @@ -76,6 +89,34 @@ jobs:
env: TOXENV=py27 CLIMT_ARCH=Linux
script:
- tox -e ${TOXENV}
- stage: big tests
dist: xenial
python: "3.7"
env: TOXENV=py37 CLIMT_ARCH=Linux
script:
- tox -e ${TOXENV}
- stage: big tests
os: osx
language: generic
env: PYTHON_VERSION=3.6 TOXENV=py36 CLIMT_ARCH=Darwin OMP_NUM_THREADS=1
install:
- conda create -q -n test-environment python=$PYTHON_VERSION
- source activate test-environment
- python -m pip install -r requirements_dev.txt
- python -m pip install -U tox
script:
- travis_wait 50 tox -e ${TOXENV}
- stage: big tests
os: osx
language: generic
env: PYTHON_VERSION=3.7 TOXENV=py37 CLIMT_ARCH=Darwin OMP_NUM_THREADS=1
install:
- conda create -q -n test-environment python=$PYTHON_VERSION
- source activate test-environment
- python -m pip install -r requirements_dev.txt
- python -m pip install -U tox
script:
- travis_wait 50 tox -e ${TOXENV}
- stage: wheels
env: CLIMT_ARCH=Linux CIBW_SKIP='cp33-* cp36-* cp35-* cp34-* cp37-* cp27-manylinux1_i686' CIBW_BEFORE_BUILD="{pip} install pandas==0.20.3"
script:
Expand Down Expand Up @@ -106,18 +147,40 @@ jobs:
python -m pip install twine
python -m twine upload wheelhouse/*.whl
fi
#- stage: wheels
# os: osx
# language: generic
# env: CLIMT_ARCH=Darwin CIBW_SKIP='cp33-* cp35-* cp34-* cp27-* cp36-manylinux1_i686'
# script:
# - |
# if [[ $TRAVIS_TAG ]]; then
# python -m pip install cibuildwheel
# travis_wait 50 cibuildwheel --output-dir wheelhouse
# python -m pip install twine
# python -m twine upload wheelhouse/*.whl
# fi
- stage: wheels
env: CLIMT_ARCH=Linux CIBW_SKIP='cp33-* cp35-* cp34-* cp27-* cp36-* cp37-manylinux1_i686'
script:
- |
if [[ $TRAVIS_TAG ]]; then
python -m pip install cibuildwheel
cibuildwheel --output-dir wheelhouse
python -m pip install twine
python -m twine upload wheelhouse/*.whl
fi
- stage: wheels
os: osx
language: generic
env: CLIMT_ARCH=Darwin CIBW_SKIP='cp33-* cp35-* cp34-* cp27-* cp37-*'
script:
- |
if [[ $TRAVIS_TAG ]]; then
python -m pip install cibuildwheel
travis_wait 50 cibuildwheel --output-dir wheelhouse
python -m pip install twine
python -m twine upload wheelhouse/*.whl
fi
- stage: wheels
os: osx
language: generic
env: CLIMT_ARCH=Darwin CIBW_SKIP='cp33-* cp35-* cp34-* cp27-* cp36-*'
script:
- |
if [[ $TRAVIS_TAG ]]; then
python -m pip install cibuildwheel
travis_wait 50 cibuildwheel --output-dir wheelhouse
python -m pip install twine
python -m twine upload wheelhouse/*.whl
fi
deploy:
Expand Down
6 changes: 5 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ History
Latest
------


* CI Testing for Mac and py37 added.
* Refactored initialisation code
* Enable the McICA version of RRTMG Longwave for consistency
with the Shortwave component.
* Fix bugs in IceSheet
Expand All @@ -24,6 +25,9 @@ Breaking Changes

* The flux outputs of GrayLongwaveRadiation have been renamed to eliminate
`on_interface_levels` to keep consistency with other components.
* All arrays are now 3/2d by default based on their expected dimensions.
* horizontal dimensions are now `model_longitude`, `model_latitude`, but inputs
used by components remain the same (`latitude`, `longitude`).



Expand Down
3 changes: 2 additions & 1 deletion climt/_components/dcmip/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import numpy as np
try:
from . import _dcmip
except ImportError:
except ImportError as error:
logging.warning(
'Import Failed. DCMIP initial conditions will not be available.')
print(error)


class DcmipInitialConditions(DiagnosticComponent):
Expand Down
48 changes: 19 additions & 29 deletions climt/_components/dry_convection/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ class DryConvectiveAdjustment(Stepper):
input_properties = {
'air_temperature': {
'units': 'degK',
'dims': ['*', 'mid_levels'],
'dims': ['mid_levels', '*'],
},
'air_pressure': {
'units': 'Pa',
'dims': ['*', 'mid_levels'],
'dims': ['mid_levels', '*'],
},
'air_pressure_on_interface_levels': {
'units': 'Pa',
'dims': ['*', 'interface_levels'],
'dims': ['interface_levels', '*'],
'alias': 'P_int',
},
'specific_humidity': {
'units': 'kg/kg',
'dims': ['*', 'mid_levels'],
'dims': ['mid_levels', '*'],
},
}

Expand Down Expand Up @@ -54,30 +54,28 @@ def array_call(self, state, time_step):
self.output_properties, state, self.input_properties
)

output_temp = output_arrays['air_temperature']
output_temp[:] = state['air_temperature']
output_temperature = output_arrays['air_temperature']
output_temperature[:] = state['air_temperature']

output_q = output_arrays['specific_humidity']
output_q[:] = q

rd_cp = self.gas_constant(q)/self.heat_capacity(q)
theta = state['air_temperature']*(self._Pref/state['air_pressure'])**rd_cp
theta_q = theta*(1 + output_q*self._Rv/self._Rdair - output_q)

# print('initial theta:', theta)
num_levels = q.shape[0]

num_levels = q.shape[-1]

for column in range(q.shape[0]):
for column in range(q.shape[-1]):
for level in range(num_levels-1, -1, -1):

dp = state['P_int'][column, :-1] - state['P_int'][column, 1:]
theta_sum = np.cumsum(theta_q[column, level::])
dp = state['P_int'][:-1, column] - state['P_int'][1:, column]
theta_q = theta*(1 + output_q*self._Rv/self._Rdair - output_q)
theta_sum = np.cumsum(theta_q[level::, column])
divisor = np.arange(1, num_levels - level+1)

theta_avg = (theta_sum/divisor)[1::]

theta_lesser = (theta_avg > theta_q[column, level+1::])
theta_lesser = (theta_avg > theta_q[level+1::, column])
if np.sum(theta_lesser) == 0:
continue

Expand All @@ -90,36 +88,28 @@ def array_call(self, state, time_step):
continue
stable_level = level + convect_to_level

q_conv = output_q[column, level:stable_level]
t_conv = output_temp[column, level:stable_level]
q_conv = output_q[level:stable_level, column]
t_conv = output_temperature[level:stable_level, column]
dp_conv = dp[level:stable_level]
p_conv_high = state['P_int'][column, level]
p_conv_low = state['P_int'][column, stable_level]
p_conv_high = state['P_int'][level, column]
p_conv_low = state['P_int'][stable_level, column]

enthalpy = self.heat_capacity(q_conv)*t_conv
integral_enthalpy = np.sum(enthalpy*dp_conv)
mean_conv_q = np.sum(q_conv*dp_conv)/(p_conv_high - p_conv_low)

output_q[column, level:stable_level] = mean_conv_q
output_q[level:stable_level, column] = mean_conv_q

rdcp_conv = self.gas_constant(mean_conv_q)/self.heat_capacity(mean_conv_q)

theta_coeff = (
state['air_pressure'][column, level:stable_level]/self._Pref)**rdcp_conv
state['air_pressure'][level:stable_level, column]/self._Pref)**rdcp_conv

integral_theta_den = np.sum(self.heat_capacity(q_conv)*theta_coeff*dp_conv)

mean_theta = integral_enthalpy/integral_theta_den

output_temp[column, level:stable_level] = mean_theta*theta_coeff

# dp = (state['P_int'][0, :-1] - state['P_int'][0, 1:])/(state['P_int'][0, 0] - state['P_int'][0, -1])
# print('Initial Enthalpy: ', np.sum(self.heat_capacity(state['specific_humidity'])*state['air_temperature']*dp))
# print('Final Enthalpy: ', np.sum(self.heat_capacity(output_q)*output_temp*dp))
# rd_cp = self.gas_constant(output_q)/self.heat_capacity(output_q)
# theta = output_temp*(self._Pref/state['air_pressure'])**rd_cp

# print('final theta: ', theta)
output_temperature[level:stable_level, column] = mean_theta*theta_coeff

return {}, output_arrays

Expand Down
3 changes: 2 additions & 1 deletion climt/_components/emanuel/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import logging
try:
from . import _emanuel_convection
except ImportError:
except ImportError as error:
logging.warning(
'Import failed. Emanuel Convection is likely not compiled and will not '
'be available.'
)
print(error)


class EmanuelConvection(ImplicitTendencyComponent):
Expand Down
Loading

0 comments on commit 5aa011f

Please sign in to comment.