Пример #1
0
    def test_Qtcm_object_field_default_values_on_init(self):
        """Test Qtcm object field values on initialization for full.

	This test looks at Field attributes not tested above to
	make sure that their values are initialized correctly.  But
	on the value in Field is tested, none of the other attributes
	of Field.  Set compiled_form to 'full' and 'parts'.
        """
        for iform in ['full', 'parts']:
            model = Qtcm(compiled_form=iform)
            self.failUnless(self.N.allclose(model.it.value, 1))
            self.failUnless(self.N.allclose(model.interval.value, 1))
            self.failUnless(self.N.allclose(model.noout.value, 0))
            self.failUnless(self.N.allclose(model.nooutr.value, 0))
            self.failUnless(self.N.allclose(model.ntout.value, -30))
            self.failUnless(self.N.allclose(model.ntouti.value, 0))
            self.failUnless(self.N.allclose(model.ntoutr.value, 0))
            self.failUnless(self.N.allclose(model.mrestart.value, 0))
            self.failUnless(self.N.allclose(model.mt0.value, 1))
            self.failUnless(self.N.allclose(model.ziml.value, 500))
            self.failUnless(self.N.allclose(model.weml.value, 0.01))
            self.failUnless(self.N.allclose(model.VVsmin.value, 4.5))
            self.failUnless(self.N.allclose(model.viscxu0.value, 7e5))
            self.failUnless(self.N.allclose(model.viscyu0.value, 7e5))
            self.failUnless(self.N.allclose(model.visc4x.value, 7e5))
            self.failUnless(self.N.allclose(model.visc4y.value, 7e5))
            self.failUnless(self.N.allclose(model.viscxu1.value, 7e5))
            self.failUnless(self.N.allclose(model.viscyu1.value, 7e5))
            self.failUnless(self.N.allclose(model.viscxT.value, 12e5))
            self.failUnless(self.N.allclose(model.viscyT.value, 12e5))
            self.failUnless(self.N.allclose(model.viscxq.value, 12e5))
            self.failUnless(self.N.allclose(model.viscyq.value, 12e5))
Пример #2
0
    def test_Qtcm_object_init_keywords_read(self):
        """Test Qtcm object reads instantiation keywords correctly.

        Test done only for a few cases.  Set compiled_form to 'full' 
        and 'parts'.
        """
        for iform in ['full', 'parts']:
            inputs = {}
            inputs['dt'] = 600.
            inputs['eps_c'] = 0.15
            inputs['compiled_form'] = iform
            model = Qtcm(**inputs)
            self.failUnlessEqual(model.dt.id, 'dt')
            self.failUnlessEqual(model.dt.value, 600.)
            self.failUnlessEqual(model.eps_c.id, 'eps_c')
            self.failUnlessEqual(model.eps_c.value, 0.15)
Пример #3
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')
Пример #4
0
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
inputs['noout'] = 0
inputs['mrestart'] = 0
inputs['compiled_form'] = 'parts'

model1 = Qtcm(**inputs)
model1.run_session()
if os.path.exists('qtcm_00011115.restart'): os.remove('qtcm_00011115.restart')

#- Aqua Run 2:  Make test run directory if it doesn't exist.  Delete
#  old proc and log files as needed, set inputs dictionary, and run:

rundirname = 'full_365_aqua_multi2'
dirbasepath = prepare_outdir(rundirname)

inputs['outdir'] = dirbasepath
inputs['runname'] = rundirname

model2 = Qtcm(**inputs)
model2.run_session()
if os.path.exists('qtcm_00011115.restart'): os.remove('qtcm_00011115.restart')
Пример #5
0
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
inputs['noout'] = 0
inputs['mrestart'] = 0
inputs['compiled_form'] = 'parts'

model1 = Qtcm(**inputs)
model1.run_session()
if os.path.exists('qtcm_00011115.restart'):  os.remove('qtcm_00011115.restart')


#- Aqua Run 2:  Make test run directory if it doesn't exist.  Delete
#  old proc and log files as needed, set inputs dictionary, and run:

rundirname = 'parts_365_aqua_multi2'
dirbasepath = prepare_outdir(rundirname)

inputs['outdir'] = dirbasepath
inputs['runname'] = rundirname

model2 = Qtcm(**inputs)
model2.run_session()
Пример #6
0
    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
    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=12,
                filled=0,
                fn=os.path.join(dirbasepath, 'plotm2.png'))
    #    model.plotm('Ts',lon=[20,300], time=50, approx_nlev=5,
    #        fn=os.path.join(dirbasepath, 'plotm3.png'))
    #   model.plotm('Qc',time=4, tmppreview=True)
    #   model.plotm('Qc',lon=[20,100], time=[0,4])  #@@@should give error
    #   model.plotm('Qc',lat=5.625, lon=[20,100], time=[0,4])
    #    model.plotm('Qc',lat=[-20, 50], lon=247.5, time=[30,50],
Пример #7
0
#  in two passes (10 and 30 days), using restart:

rundirname = 'full_365_landon_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

os.rename( os.path.join(os.getcwd(), 'qtcm_00011110.restart'),
           os.path.join(os.getcwd(), 'qtcm.restart') )

rundirname = 'full_365_landon_cont10-30_30'
dirbasepath = prepare_outdir(rundirname)
inputs1['outdir'] = dirbasepath
inputs1['runname'] = rundirname
inputs1['year0'] = -1
inputs1['month0'] = -1
inputs1['day0'] = -1
inputs1['lastday'] = 30
inputs1['mrestart'] = 1
Пример #8
0
#- Run:

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'] = 1
inputs['year0'] = 1
inputs['month0'] = 11
inputs['day0'] = 1
inputs['lastday'] = 800
inputs['ntout'] = 30
inputs['ntouti'] = 30
inputs['noout'] = 0
inputs['mrestart'] = 0
inputs['compiled_form'] = 'parts'

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

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

    # ====== end file ======
Пример #9
0
Файл: h.py Проект: jwblin/qtcm
    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=5,
#        fn=os.path.join(dirbasepath, 'plotm3.png'))
#   model.plotm('Qc',time=4, tmppreview=True)
#   model.plotm('Qc',lon=[20,100], time=[0,4])  #@@@should give error
#   model.plotm('Qc',lat=5.625, lon=[20,100], time=[0,4])
#    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'))
Пример #10
0
    def test_Qtcm_object_field_default_on_init(self):
        """Test Qtcm object field attributes on init.

	This test looks a number of Field attributes for a host of
	QTCM fields initialized when the Qtcm instance is initialized.
	It does not test all those default attributes, but for the
        ones it tests, it tests all the Field attributes that describe
        that QTCM field.  In the next test, the fields that are not in
        this test are tested, but only for the correct value.  Set
        compiled_form to 'full' and 'parts'.
        """
        for iform in ['full', 'parts']:
            model = Qtcm(compiled_form=iform)

            self.failUnless(self.N.allclose(model.dt.value, 1200.))
            self.failUnlessEqual(model.dt.id, 'dt')
            self.failUnlessEqual(model.dt.units, 's')
            self.failUnlessEqual(model.dt.long_name, 'time step')

            self.failUnless(self.N.allclose(model.eps_c.value, 0.13888889E-03))
            self.failUnlessEqual(model.eps_c.id, 'eps_c')
            self.failUnlessEqual(model.eps_c.units, '1/s')
            self.failUnlessEqual(model.eps_c.long_name, '1/tau_c NZ (5.7)')

            self.failUnlessEqual(model.title.value, 'QTCM default title')
            self.failUnlessEqual(model.title.id, 'title')
            self.failUnlessEqual(model.title.units, '')
            self.failUnlessEqual(model.title.long_name, 'a descriptive title')

            self.failUnlessEqual(model.bnddir.value,
                                 os.path.join(os.pardir, 'bnddata'))
            self.failUnlessEqual(model.bnddir.id, 'bnddir')
            self.failUnlessEqual(model.bnddir.units, '')
            self.failUnlessEqual(model.bnddir.long_name,
                                 'boundary data other than SST')

            self.failUnlessEqual(
                model.SSTdir.value,
                os.path.join(os.pardir, 'bnddata', 'SST_Reynolds'))
            self.failUnlessEqual(model.SSTdir.id, 'SSTdir')
            self.failUnlessEqual(model.SSTdir.units, '')
            self.failUnlessEqual(model.SSTdir.long_name, 'where SST files are')

            self.failUnlessEqual(
                model.outdir.value,
                os.path.join(os.pardir, 'proc', 'qtcm_output'))
            self.failUnlessEqual(model.outdir.id, 'outdir')
            self.failUnlessEqual(model.outdir.units, '')
            self.failUnlessEqual(model.outdir.long_name,
                                 'where output goes to')

            self.failUnlessEqual(model.runname.value, 'runname')
            self.failUnlessEqual(model.runname.id, 'runname')
            self.failUnlessEqual(model.runname.units, '')
            self.failUnlessEqual(model.runname.long_name,
                                 'string for an output filename')

            self.failUnlessEqual(model.landon.value, 1)
            self.failUnlessEqual(model.landon.id, 'landon')
            self.failUnlessEqual(model.landon.units, '')
            self.failUnlessEqual(model.landon.long_name,
                                 'if not 1: land = ocean with fake SST')

            self.failUnlessEqual(model.SSTmode.value, 'seasonal')
            self.failUnlessEqual(model.SSTmode.id, 'SSTmode')
            self.failUnlessEqual(model.SSTmode.units, '')
            self.failUnlessEqual(model.SSTmode.long_name,
                                 'decide what kind of SST to use')

            self.failUnlessEqual(model.year0.value, 0)
            self.failUnlessEqual(model.year0.id, 'year0')
            self.failUnlessEqual(model.year0.units, 'yr')
            self.failUnlessEqual(model.year0.long_name,
                                 'starting year; if < 0 use year in restart')

            self.failUnlessEqual(model.month0.value, -1)
            self.failUnlessEqual(model.month0.id, 'month0')
            self.failUnlessEqual(model.month0.units, 'mo')
            self.failUnlessEqual(model.month0.long_name,
                                 'starting month; if < 0 use mo in restart')

            self.failUnlessEqual(model.day0.value, -1)
            self.failUnlessEqual(model.day0.id, 'day0')
            self.failUnlessEqual(model.day0.units, 'dy')
            self.failUnlessEqual(model.day0.long_name,
                                 'starting day; if < 0 use day in restart')

            self.failUnlessEqual(model.lastday.value, 365)
            self.failUnlessEqual(model.lastday.id, 'lastday')
            self.failUnlessEqual(model.lastday.units, 'dy')
            self.failUnlessEqual(model.lastday.long_name,
                                 'last day of integration')

            self.failUnlessEqual(model.dateofmodel.value, 0)
            self.failUnlessEqual(model.dateofmodel.id, 'dateofmodel')
            self.failUnlessEqual(model.dateofmodel.units, '')
            self.failUnlessEqual(
                model.dateofmodel.long_name,
                'date of model coded as an integer as yyyymmdd')
Пример #11
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')
Пример #12
0
Файл: f.py Проект: jwblin/qtcm
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
inputs['noout'] = 0
inputs['mrestart'] = 0
inputs['compiled_form'] = 'full'

model = Qtcm(**inputs)
model.run_session()
#model.plotm('Qc',lat=[-40,40], time=4, lon=[0.,])
#model.plotm('Qc',lat=[-40,40], time=4)
model.plotm('Qc',lon=[20,300], time=4, approx_nlev=4, tmppreview=True)
#model.plotm('Qc',time=4, tmppreview=True)
#model.plotm('Qc',lon=[20,100], time=[0,4])  #@@@should give error
#model.plotm('Qc',lat=5.625, lon=[20,100], time=[0,4])
#model.plotm('Qc',lat=[-5.625, 50], lon=247.5, time=[0,4])
if os.path.exists('qtcm_00011115.restart'):  os.remove('qtcm_00011115.restart')




# ====== end file ======
Пример #13
0
rundirname = 'parts_365_aqua_nr1_cont'
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['init_with_instance_state'] = True
inputs1['compiled_form'] = 'parts'

model = Qtcm(**inputs1)
model.run_session()
snapshot = model.snapshot

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

model.run_session(cont=30)
del model

#why is this incorrect?  why when you do a continuation run for another
#  run session do you not get the same results as the 30 day run
#  from case 3?  even if you don't write the same file.  the remove thing
#  didn't work.  what if i try with snapshot once more?  it doesn't work
#  because i hvaen't assigned a new qtcm compiled module?  put that
#  into run_session?  @@@add this note re compiled model to manual
Пример #14
0
#  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

os.rename(os.path.join(os.getcwd(), 'qtcm_00011110.restart'),
          os.path.join(os.getcwd(), 'qtcm.restart'))

rundirname = 'full_365_aqua_cont10-30_30'
dirbasepath = prepare_outdir(rundirname)
inputs1['outdir'] = dirbasepath
inputs1['runname'] = rundirname
inputs1['year0'] = -1
inputs1['month0'] = -1
inputs1['day0'] = -1
inputs1['lastday'] = 30
inputs1['mrestart'] = 1
Пример #15
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')
Пример #16
0
    def test_Qtcm_object_set_and_get_items_from_compiled(self):
        """Test Qtcm set_qtcm_item and get_qtcm_item methods together.

        Also tests the set_qtcm1_item and get_qtcm1_item methods, which
        should behave identically to set_qtcm_item and get_qtcm_item.
        Only scalar parameters are tested.
        """
        for iform in ['full', 'parts']:
            model = Qtcm(compiled_form=iform)
            model.set_qtcm_item('dt', 2400.)
            model.set_qtcm_item('bnddir', 'ooga booga')
            model.set_qtcm_item('ntout', 120)
        
            self.failUnless( self.N.allclose(model.get_qtcm_item('dt'), 2400.) )
            self.failUnlessEqual( model.get_qtcm_item('bnddir'), 'ooga booga' )
            self.failUnlessEqual( model.get_qtcm_item('ntout'), 120 )
        
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'dt', 400)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'dt', 'hi')
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'bnddir', 20)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'bnddir', 20.)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'ntout', 30.)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'ntout', 'hi')
            del model

            model = Qtcm(compiled_form=iform)
            model.set_qtcm1_item('dt', 2400.)
            model.set_qtcm1_item('bnddir', 'ooga booga')
            model.set_qtcm1_item('ntout', 120)
        
            self.failUnless( self.N.allclose(model.get_qtcm1_item('dt'), 
                             2400.) )
            self.failUnlessEqual( model.get_qtcm1_item('bnddir'), 'ooga booga' )
            self.failUnlessEqual( model.get_qtcm1_item('ntout'), 120 )
        
            self.failUnlessRaises( TypeError, model.set_qtcm1_item, 'dt', 400 )
            self.failUnlessRaises( TypeError, model.set_qtcm1_item, 'dt', 'hi' )
            self.failUnlessRaises( TypeError, model.set_qtcm1_item, 'bnddir',
                                   20 )
            self.failUnlessRaises( TypeError, model.set_qtcm1_item, 'bnddir', 
                                   20. )
            self.failUnlessRaises( TypeError, model.set_qtcm1_item, 'ntout', 
                                   30. )
            self.failUnlessRaises( TypeError, model.set_qtcm1_item, 'ntout', 
                                   'hi' )
            del model
Пример #17
0
Файл: foo.py Проект: jwblin/qtcm
inputs['SSTdir'] = os.path.join( os.getcwd(), 'bnddir', 'r64x42' \
                               , 'SST_Reynolds' )
inputs['outdir'] = os.path.join( os.getcwd(), 'rundir', 'full_365_aqua' )
inputs['runname'] = 'full_365_aqua'
inputs['landon'] = 0
inputs['year0'] = 1
inputs['month0'] = 11
inputs['day0'] = 1
inputs['lastday'] = 15
inputs['ntout'] = 1
inputs['ntouti'] = 1
inputs['noout'] = 0
inputs['mrestart'] = 0
inputs['compiled_form'] = 'parts'

model = Qtcm(**inputs)
start_time_f2py = time.time()
for i in xrange(1):
    model.run_session()
print time.time() - start_time_f2py

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



#- Delete old proc and log files and move old to aqua2:

#if os.path.exists(os.path.join(os.getcwd(),'rundir','full_365_aqua2')):
#    shutil.rmtree(os.path.join(os.getcwd(),'rundir','full_365_aqua2'))
#shutil.copytree(os.path.join(os.getcwd(),'rundir','full_365_aqua'), \
#                os.path.join(os.getcwd(),'rundir','full_365_aqua2'))
Пример #18
0
    def test_Qtcm_object_set_and_get_items_from_compiled(self):
        """Test Qtcm set_qtcm_item and get_qtcm_item methods together.

        Also tests the set_qtcm1_item and get_qtcm1_item methods, which
        should behave identically to set_qtcm_item and get_qtcm_item.
        Only scalar parameters are tested.
        """
        for iform in ['full', 'parts']:
            model = Qtcm(compiled_form=iform)
            model.set_qtcm_item('dt', 2400.)
            model.set_qtcm_item('bnddir', 'ooga booga')
            model.set_qtcm_item('ntout', 120)

            self.failUnless(self.N.allclose(model.get_qtcm_item('dt'), 2400.))
            self.failUnlessEqual(model.get_qtcm_item('bnddir'), 'ooga booga')
            self.failUnlessEqual(model.get_qtcm_item('ntout'), 120)

            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'dt', 400)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'dt', 'hi')
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'bnddir', 20)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'bnddir',
                                  20.)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'ntout', 30.)
            self.failUnlessRaises(TypeError, model.set_qtcm_item, 'ntout',
                                  'hi')
            del model

            model = Qtcm(compiled_form=iform)
            model.set_qtcm1_item('dt', 2400.)
            model.set_qtcm1_item('bnddir', 'ooga booga')
            model.set_qtcm1_item('ntout', 120)

            self.failUnless(self.N.allclose(model.get_qtcm1_item('dt'), 2400.))
            self.failUnlessEqual(model.get_qtcm1_item('bnddir'), 'ooga booga')
            self.failUnlessEqual(model.get_qtcm1_item('ntout'), 120)

            self.failUnlessRaises(TypeError, model.set_qtcm1_item, 'dt', 400)
            self.failUnlessRaises(TypeError, model.set_qtcm1_item, 'dt', 'hi')
            self.failUnlessRaises(TypeError, model.set_qtcm1_item, 'bnddir',
                                  20)
            self.failUnlessRaises(TypeError, model.set_qtcm1_item, 'bnddir',
                                  20.)
            self.failUnlessRaises(TypeError, model.set_qtcm1_item, 'ntout',
                                  30.)
            self.failUnlessRaises(TypeError, model.set_qtcm1_item, 'ntout',
                                  'hi')
            del model
Пример #19
0
#  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

os.rename( os.path.join(os.getcwd(), 'qtcm_00011110.restart'),
           os.path.join(os.getcwd(), 'qtcm.restart') )

rundirname = 'full_365_aqua_cont10-30_30'
dirbasepath = prepare_outdir(rundirname)
inputs1['outdir'] = dirbasepath
inputs1['runname'] = rundirname
inputs1['year0'] = -1
inputs1['month0'] = -1
inputs1['day0'] = -1
inputs1['lastday'] = 30
inputs1['mrestart'] = 1
Пример #20
0
rundirname = 'parts_365_aqua_nr1_cont'
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['init_with_instance_state'] = True
inputs1['compiled_form'] = 'parts'

model = Qtcm(**inputs1)
model.run_session()
snapshot = model.snapshot

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

model.run_session(cont=30)
del model

#why is this incorrect?  why when you do a continuation run for another
#  run session do you not get the same results as the 30 day run
#  from case 3?  even if you don't write the same file.  the remove thing
#  didn't work.  what if i try with snapshot once more?  it doesn't work
#  because i hvaen't assigned a new qtcm compiled module?  put that
#  into run_session?  @@@add this note re compiled model to manual
Пример #21
0
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
inputs['noout'] = 0
inputs['mrestart'] = 0
inputs['compiled_form'] = 'full'

model = Qtcm(**inputs)
model.run_session()
#model.plotm('Qc',lat=[-40,40], time=4, lon=[0.,])
#model.plotm('Qc',lat=[-40,40], time=4)
model.plotm('Qc', lon=[20, 300], time=4, approx_nlev=4, tmppreview=True)
#model.plotm('Qc',time=4, tmppreview=True)
#model.plotm('Qc',lon=[20,100], time=[0,4])  #@@@should give error
#model.plotm('Qc',lat=5.625, lon=[20,100], time=[0,4])
#model.plotm('Qc',lat=[-5.625, 50], lon=247.5, time=[0,4])
if os.path.exists('qtcm_00011115.restart'):
    os.remove('qtcm_00011115.restart')

    # ====== end file ======
Пример #22
0
#  in two passes (10 and 30 days), using restart:

rundirname = 'full_365_landon_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

os.rename(os.path.join(os.getcwd(), 'qtcm_00011110.restart'),
          os.path.join(os.getcwd(), 'qtcm.restart'))

rundirname = 'full_365_landon_cont10-30_30'
dirbasepath = prepare_outdir(rundirname)
inputs1['outdir'] = dirbasepath
inputs1['runname'] = rundirname
inputs1['year0'] = -1
inputs1['month0'] = -1
inputs1['day0'] = -1
inputs1['lastday'] = 30
inputs1['mrestart'] = 1