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')
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')
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 ======
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
'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'))
, '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')
, '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() if os.path.exists('qtcm_00011115.restart'): os.remove('qtcm_00011115.restart')
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 if os.path.exists('qtcm_00011210.restart'):
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')