#NEWLINE# def _initializePerturb( self , basin , forcings , vicexe , initdays = 90 , saveindb = False , saveto = 'db' , saveargs = [ ] , overwrite = True , skipsave = 0 ) : #NEWLINE# #INDENT# 'Initialize ensemble of VIC models by perturbing the meterological forcings\n        and running them *initmonths* prior to simulation start date.' #NEWLINE# statefiles = [ ] #NEWLINE# t = ( date ( self . startyear , self . startmonth , self . startday ) - relativedelta ( days = initdays ) ) #NEWLINE# modelpath = tempfile . mkdtemp ( ) #NEWLINE# model = vic . VIC ( modelpath , self . dbname , self . res , t . year , t . month , t . day , self . startyear , self . startmonth , self . startday , self . name ) #NEWLINE# ( prec , tmax , tmin , wind ) = model . getForcings ( forcings ) #NEWLINE# ( eprec , etmax , etmin , ewind ) = self . perturb ( prec , tmax , tmin , wind ) #NEWLINE# pmodels = [ ] #NEWLINE# for e in range ( self . nens ) : #NEWLINE# #INDENT# modelpath = tempfile . mkdtemp ( ) #NEWLINE# model = vic . VIC ( modelpath , self . dbname , self . res , t . year , t . month , t . day , self . startyear , self . startmonth , self . startday , self . name ) #NEWLINE# model . writeParamFile ( save_state = modelpath , init_state = False ) #NEWLINE# model . writeSoilFile ( basin ) #NEWLINE# model . writeForcings ( eprec [ e ] , etmax [ e ] , skipsave [ e ] , ewind [ e ] ) #NEWLINE# pmodels . append ( model ) #NEWLINE# #UNINDENT# procs = [ Process ( target = pmodels [ e ] . run , args = ( vicexe , ) ) for e in range ( self . nens ) ] #NEWLINE# for p in procs : #NEWLINE# #INDENT# p . start ( ) #NEWLINE# #UNINDENT# for p in procs : #NEWLINE# #INDENT# p . join ( ) #NEWLINE# #UNINDENT# if saveindb : #NEWLINE# #INDENT# if ( skipsave < 0 ) : #NEWLINE# #INDENT# skipdays = ( ( ( date ( self . startyear , self . startmonth , self . startday ) - t ) . days + 1 ) + skipsave ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# skipdays = skipsave #NEWLINE# #UNINDENT# init = overwrite #NEWLINE# for e in range ( len ( pmodels ) ) : #NEWLINE# #INDENT# model = pmodels [ e ] #NEWLINE# if ( getattr ( model . writeToDB , 'func_name' ) is not 'write_wrapper' ) : #NEWLINE# #INDENT# model . writeToDB = self . _ensembleTable ( model . writeToDB , ( e + 1 ) ) #NEWLINE# #UNINDENT# if ( e > 0 ) : #NEWLINE# #INDENT# init = False #NEWLINE# #UNINDENT# model . save ( saveto , saveargs , init , skipsave = skipdays ) #NEWLINE# #UNINDENT# #UNINDENT# for e in range ( self . nens ) : #NEWLINE# #INDENT# statefile = ( pmodels [ e ] . model_path + '/vic.state_{0:04d}{1:02d}{2:02d}' . format ( self . startyear , self . startmonth , self . startday ) ) #NEWLINE# statefiles . append ( statefile ) #NEWLINE# #UNINDENT# return statefiles