def create_output_directories(self): cleanOutputDir = False if cleanOutputDir: try: shutil.rmtree(self.FILE_PATHS['PathOut']) except: pass try: os.makedirs(self.FILE_PATHS['PathOut']) except: pass # make temp directory self.tmpDir = vos.getFullPath("tmp/", self.FILE_PATHS['PathOut']) if os.path.exists(self.tmpDir): shutil.rmtree(self.tmpDir) os.makedirs(self.tmpDir) # make netcdf directory self.outNCDir = vos.getFullPath("netcdf/", self.FILE_PATHS['PathOut']) if os.path.exists(self.outNCDir): shutil.rmtree(self.outNCDir) os.makedirs(self.outNCDir) # make and populate backup directory for Python scripts self.scriptDir = vos.getFullPath("scripts/", self.FILE_PATHS['PathOut']) if os.path.exists(self.scriptDir): shutil.rmtree(self.scriptDir) os.makedirs(self.scriptDir) # working/starting directory where all Python scripts are located path_of_this_module = os.path.abspath(os.path.dirname(__file__)) self.starting_directory = path_of_this_module all_files = glob.glob(os.path.join(path_of_this_module, '*.py')) for filename in all_files: shutil.copy(filename, self.scriptDir) # make log directory self.logFileDir = vos.getFullPath("log/", self.FILE_PATHS['PathOut']) cleanLogDir = True if os.path.exists(self.logFileDir) and cleanLogDir: shutil.rmtree(self.logFileDir) os.makedirs(self.logFileDir) # make end state directory self.endStateDir = vos.getFullPath("states/", self.FILE_PATHS['PathOut']) if os.path.exists(self.endStateDir): shutil.rmtree(self.endStateDir) os.makedirs(self.endStateDir)
def initial(self): self.var.irrMgmtParameterFileNC = self.var._configuration.irrMgmtOptions[ 'irrMgmtParameterNC'] self.var.parameter_names = [ 'IrrMethod', 'IrrInterval', 'SMT1', 'SMT2', 'SMT3', 'SMT4', 'MaxIrr', 'AppEff', 'NetIrrSMT', 'WetSurf' ] for param in self.var.parameter_names: # nm = '_' + var vars(self.var)[param] = vos.netcdf2PCRobjCloneWithoutTime( self.var.irrMgmtParameterFileNC, param, cloneMapFileName=self.var.cloneMap) # check if an irrigation schedule file is required if np.sum(self.var.IrrMethod == 3) > 0: if self.var._configuration.irrMgmtOptions[ 'irrScheduleNC'] != "None": self.var._configuration.irrMgmtOptions[ 'irrScheduleNC'] = vos.getFullPath( self.var._configuration.irrMgmtOptions[item], self.var._configuration.globalOptions['inputDir']) self.var.irrScheduleFileNC = self.var._configuration.irrMgmtOptions[ 'irrScheduleNC'] else: logger.error( 'IrrMethod equals 3 in some or all places, but irrScheduleNC is not set in configuration file' ) else: self.var.irrScheduleFileNC = None
def set_clone_map(self): self.cloneMap = vos.getFullPath(self.globalOptions['cloneMap'], self.globalOptions['inputDir'])
def set_input_files(self): # set clone map self.cloneMap = vos.getFullPath(self.globalOptions['cloneMap'], self.globalOptions['inputDir']) # initial condition file if self.globalOptions['initialConditionNC'] != "None": self.globalOptions['initialConditionNC'] = vos.getFullPath( self.globalOptions['initialConditionNC'], self.globalOptions['inputDir']) # meteorological input files meteoInputFiles = [ 'precipitationNC', 'temperatureNC', 'refETPotFileNC' ] for item in meteoInputFiles: if self.meteoOptions[item] != "None": self.meteoOptions[item] = vos.getFullPath( self.meteoOptions[item], self.globalOptions['inputDir']) # CO2 concentration input file co2InputFiles = ['carbonDioxideNC'] for item in co2InputFiles: if self.carbonDioxideOptions[item] != "None": self.carbonDioxideOptions[item] = vos.getFullPath( self.carbonDioxideOptions[item], self.globalOptions['inputDir']) # groundwater input file item = 'groundwaterNC' if self.groundwaterOptions[item] != "None": self.groundwaterOptions[item] = vos.getFullPath( self.groundwaterOptions[item], self.groundwaterOptions['groundwaterInputDir']) # soil parameter input file item = 'soilAndTopoNC' if self.soilOptions[item] != "None": self.soilOptions[item] = vos.getFullPath( self.soilOptions[item], self.globalOptions['inputDir']) # crop parameter input file cropInputFiles = ['cropParameterNC', 'PotYieldNC'] for item in cropInputFiles: if item in self.cropOptions: if self.cropOptions[item] != "None": self.cropOptions[item] = vos.getFullPath( self.cropOptions[item], self.globalOptions['inputDir']) # irrigation management input file irrMgmtInputFiles = ['irrMgmtParameterNC'] for item in irrMgmtInputFiles: if self.irrMgmtOptions[item] != "None": self.irrMgmtOptions[item] = vos.getFullPath( self.irrMgmtOptions[item], self.globalOptions['inputDir']) # field management input file item = 'fieldMgmtParameterNC' if self.fieldMgmtOptions[item] != "None": self.fieldMgmtOptions[item] = vos.getFullPath( self.fieldMgmtOptions[item], self.globalOptions['inputDir'])