示例#1
0
    def test_exceptions(self):
        """Test some exceptions.
        """
	#- Test the case where compiled_form is missing raises an
	#  error:

        model = Qtcm(compiled_form='parts')
        delattr(model, 'compiled_form')
        self.failUnlessRaises(ValueError, model.__init__)


	#- Test that varinit cannot be called in certain cases:

        model = Qtcm(compiled_form='full')
        self.failUnlessRaises(AttributeError, model.varinit)

        model = Qtcm(compiled_form='parts')
        model._cont = True
        self.failUnlessRaises(qtcm.qtcm.FieldNotReadableFromCompiledModel, 
            model.varinit)


        #- Test that arrays are not initialized on instantiation, but
        #  rather in a run session (do case with no timesteps):

        model = Qtcm(compiled_form='parts')
        for ikey in defaults.qtcm_fields_ids:
            if not self.isscalar(defaults.qtcm_fields[ikey]['value']):
                self.failUnlessRaises(AttributeError, getattr, model, ikey)

        rundirname = 'test'
        dirbasepath = utilities.prepare_outdir(rundirname)
        model.outdir.value = dirbasepath
        model.runname.value = rundirname
        model.bnddir.value = os.path.join( os.getcwd(), 'bnddir', 'r64x42' )
        model.SSTdir.value = \
            os.path.join( os.getcwd(), 'bnddir', 'r64x42', 'SST_Reynolds' )
        model.lastday.value = 0
        model.run_session()
        for ikey in defaults.qtcm_fields_ids:
            if not self.isscalar(defaults.qtcm_fields[ikey]['value']):
                self.failUnless( hasattr(model, ikey) )

        if os.path.exists(dirbasepath):  shutil.rmtree(dirbasepath)
        if os.path.exists('qtcm_00010101.restart'):  
            os.remove('qtcm_00010101.restart')
示例#2
0
    def test_exceptions(self):
        """Test some exceptions.
        """
        #- Test the case where compiled_form is missing raises an
        #  error:

        model = Qtcm(compiled_form='parts')
        delattr(model, 'compiled_form')
        self.failUnlessRaises(ValueError, model.__init__)

        #- Test that varinit cannot be called in certain cases:

        model = Qtcm(compiled_form='full')
        self.failUnlessRaises(AttributeError, model.varinit)

        model = Qtcm(compiled_form='parts')
        model._cont = True
        self.failUnlessRaises(qtcm.qtcm.FieldNotReadableFromCompiledModel,
                              model.varinit)

        #- Test that arrays are not initialized on instantiation, but
        #  rather in a run session (do case with no timesteps):

        model = Qtcm(compiled_form='parts')
        for ikey in defaults.qtcm_fields_ids:
            if not self.isscalar(defaults.qtcm_fields[ikey]['value']):
                self.failUnlessRaises(AttributeError, getattr, model, ikey)

        rundirname = 'test'
        dirbasepath = utilities.prepare_outdir(rundirname)
        model.outdir.value = dirbasepath
        model.runname.value = rundirname
        model.bnddir.value = os.path.join(os.getcwd(), 'bnddir', 'r64x42')
        model.SSTdir.value = \
            os.path.join( os.getcwd(), 'bnddir', 'r64x42', 'SST_Reynolds' )
        model.lastday.value = 0
        model.run_session()
        for ikey in defaults.qtcm_fields_ids:
            if not self.isscalar(defaults.qtcm_fields[ikey]['value']):
                self.failUnless(hasattr(model, ikey))

        if os.path.exists(dirbasepath): shutil.rmtree(dirbasepath)
        if os.path.exists('qtcm_00010101.restart'):
            os.remove('qtcm_00010101.restart')
示例#3
0
文件: f.py 项目: zhangweiiowa/qtcm
#- Imports:

import numpy as N
import sys
import os
import user

from qtcm import Qtcm
from utilities import prepare_outdir

#- Make test run directory if it doesn't exist.  Delete old proc
#  and log files as needed:

rundirname = 'full_365_aqua'
dirbasepath = prepare_outdir(rundirname)

inputs = {}
inputs['dt'] = 1200.
inputs['title'] = 'QTCM spinup part 1 test (aquaplanet)'
inputs['bnddir'] = os.path.join(os.getcwd(), 'bnddir', 'r64x42')
inputs['SSTdir'] = os.path.join( os.getcwd(), 'bnddir', 'r64x42' \
                               , 'SST_Reynolds' )
inputs['outdir'] = dirbasepath
inputs['runname'] = rundirname
inputs['landon'] = 0
inputs['year0'] = 1
inputs['month0'] = 11
inputs['day0'] = 1
inputs['lastday'] = 15
inputs['ntout'] = 1
inputs['ntouti'] = 1
示例#4
0
inputs['dt'] = 1200.
inputs['title'] ='QTCM spinup part 1 test (aquaplanet)'
inputs['bnddir'] = os.path.join( os.getcwd(), 'bnddir', 'r64x42' )
inputs['SSTdir'] = os.path.join( os.getcwd(), 'bnddir', 'r64x42' \
                               , 'SST_Reynolds' )
inputs['landon'] = 0
inputs['ntout'] = 1
inputs['ntouti'] = 1
inputs['noout'] = 0


#- Case 1:  Regular aquaplanet run using compiled_form 'full', run
#  in two passes (10 and 30 days), using restart:

rundirname = 'full_365_aqua_cont10-30_10'
dirbasepath = prepare_outdir(rundirname)

inputs1 = copy.deepcopy(inputs)
inputs1['outdir'] = dirbasepath
inputs1['runname'] = rundirname
inputs1['year0'] = 1
inputs1['month0'] = 11
inputs1['day0'] = 1
inputs1['lastday'] = 10
inputs1['mrestart'] = 0
inputs1['compiled_form'] = 'full'

model = Qtcm(**inputs1)
model.run_session()
del model
示例#5
0
文件: h.py 项目: jwblin/qtcm
except: pass




#---------------------------- Main Program -----------------------------
#
# Set variable run_verbose to True or False, depending on what I want
# to do (i.e. verbose testing or not verbose testing).

if __name__ == "__main__":

    #- Generate plots for manual comparison:

    rundirname = 'plotm_test'
    dirbasepath = utilities.prepare_outdir(rundirname)

    inputs = {}
    inputs['dt'] = 1200.
    inputs['title'] ='QTCM spinup part 1 test (aquaplanet)'
    inputs['bnddir'] = os.path.join( os.getcwd(), 'bnddir', 'r64x42' )
    inputs['SSTdir'] = os.path.join( os.getcwd(), 'bnddir', 'r64x42',
                                     'SST_Reynolds' )
    inputs['outdir'] = dirbasepath
    inputs['runname'] = rundirname
    inputs['landon'] = 0
    inputs['year0'] = 1
    inputs['month0'] = 11
    inputs['day0'] = 1
    inputs['lastday'] = 60
    inputs['ntout'] = 1
示例#6
0
文件: t.py 项目: zhangweiiowa/qtcm
    suite.addTest(unittest.makeSuite(NumPyTests))
except:
    pass

#---------------------------- Main Program -----------------------------
#
# Set variable run_verbose to True or False, depending on what I want
# to do (i.e. verbose testing or not verbose testing).

if __name__ == "__main__":

    #- Generate plots for manual comparison:

    rundirname = 'plotm_test'
    dirbasepath = utilities.prepare_outdir(rundirname)

    inputs = {}
    inputs['dt'] = 1200.
    inputs['title'] = 'QTCM spinup part 1 test (aquaplanet)'
    inputs['bnddir'] = os.path.join(os.getcwd(), 'bnddir', 'r64x42')
    inputs['SSTdir'] = os.path.join(os.getcwd(), 'bnddir', 'r64x42',
                                    'SST_Reynolds')
    inputs['outdir'] = dirbasepath
    inputs['runname'] = rundirname
    inputs['landon'] = 0
    inputs['year0'] = 1
    inputs['month0'] = 11
    inputs['day0'] = 1
    inputs['lastday'] = 15
    inputs['ntout'] = 1
示例#7
0
def _gen_plots():
    """Generate plots for manual comparison.

    This method only works with numpy.
    """
    import numpy as N
    rundirname = 'plotm_test'
    dirbasepath = utilities.prepare_outdir(rundirname)

    inputs = {}
    inputs['dt'] = 1200.
    inputs['title'] = 'QTCM spinup part 1 test (aquaplanet)'
    inputs['bnddir'] = os.path.join(os.getcwd(), 'bnddir', 'r64x42')
    inputs['SSTdir'] = os.path.join(os.getcwd(), 'bnddir', 'r64x42',
                                    'SST_Reynolds')
    inputs['outdir'] = dirbasepath
    inputs['runname'] = rundirname
    inputs['landon'] = 0
    inputs['year0'] = 1
    inputs['month0'] = 11
    inputs['day0'] = 1
    inputs['lastday'] = 60
    inputs['ntout'] = 1
    inputs['ntouti'] = 1
    inputs['noout'] = 0
    inputs['mrestart'] = 0
    inputs['compiled_form'] = 'full'

    model = Qtcm(**inputs)
    model.run_session()

    model.plotm('Qc',
                lat=[-40, 40],
                time=58,
                lon=[
                    0.,
                ],
                fn=os.path.join(dirbasepath, 'plotm1.png'))
    model.plotm('FLWut',
                lat=[-40, 40],
                time=52,
                fn=os.path.join(dirbasepath, 'plotm2.png'))
    model.plotm('Ts',
                lon=[20, 300],
                time=50,
                approx_nlev=15,
                fn=os.path.join(dirbasepath, 'plotm3.png'))
    model.plotm('Qc',
                lat=[-20, 50],
                lon=247.5,
                time=[30, 50],
                fn=os.path.join(dirbasepath, 'plotm4.png'))
    model.plotm('us', time=52, fn=os.path.join(dirbasepath, 'plotm5.png'))
    model.plotm('Qc',
                lat=5.625,
                lon=[50, 200],
                time=[20, 50],
                fn=os.path.join(dirbasepath, 'plotm6.png'))
    model.plotm('q1',
                lat=5.625,
                lon=112.5,
                time=[20, 50],
                fn=os.path.join(dirbasepath, 'plotm7.png'))
    model.plotm('vs',
                time=50,
                levels=N.arange(-10, 12, 2),
                fn=os.path.join(dirbasepath, 'plotm8.png'))
    model.plotm('Qc',
                lat=5.625,
                lon=[50, 200],
                time=[20, 50],
                levels=N.arange(-20, 320, 20),
                fn=os.path.join(dirbasepath, 'plotm9.png'))

    model.plotm('Qc',
                lat=[-40, 40],
                time=58,
                lon=[
                    0.,
                ],
                filled=1,
                fn=os.path.join(dirbasepath, 'plotm1a.png'))
    model.plotm('FLWut',
                lat=[-40, 40],
                time=52,
                filled=1,
                fn=os.path.join(dirbasepath, 'plotm2a.png'))
    model.plotm('Ts',
                lon=[20, 300],
                time=50,
                approx_nlev=15,
                filled=1,
                fn=os.path.join(dirbasepath, 'plotm3a.png'))
    model.plotm('Qc',
                lat=[-20, 50],
                lon=247.5,
                time=[30, 50],
                filled=1,
                fn=os.path.join(dirbasepath, 'plotm4a.png'))
    model.plotm('us',
                time=52,
                filled=1,
                fn=os.path.join(dirbasepath, 'plotm5a.png'))
    model.plotm('Qc',
                lat=5.625,
                lon=[50, 200],
                time=[20, 50],
                filled=True,
                fn=os.path.join(dirbasepath, 'plotm6a.png'))
    model.plotm('vs',
                time=50,
                levels=N.arange(-10, 12, 2),
                filled=True,
                fn=os.path.join(dirbasepath, 'plotm8a.png'))
    model.plotm('Qc',
                lat=5.625,
                lon=[50, 200],
                time=[20, 50],
                levels=N.arange(-20, 320, 20),
                filled=True,
                fn=os.path.join(dirbasepath, 'plotm9a.png'))

    if os.path.exists('qtcm_00011115.restart'):
        os.remove('qtcm_00011115.restart')