<s> import csv <EOL> from datetime import datetime <EOL> import glob <EOL> import itertools <EOL> import os <EOL> import shutil <EOL> import sys <EOL> import subprocess <EOL> import traceback <EOL> from core . modules . vistrails_module import Module , ModuleError , ModuleConnector <EOL> from core . modules . basic_modules import File , Directory , Path , new_constant , Constant <EOL> from packages . spreadsheet . basic_widgets import SpreadsheetCell , CellLocation <EOL> from packages . spreadsheet . spreadsheet_cell import QCellWidget , QCellToolBar <EOL> from core . modules . basic_modules import List <EOL> from core . modules . basic_modules import String <EOL> from PyQt4 import QtCore , QtGui <EOL> from widgets import get_predictor_widget , get_predictor_config <EOL> from enum_widget import build_enum_widget <EOL> from SelectPredictorsLayers import SelectListDialog <EOL> import utils <EOL> import packages . sahm . pySAHM . FieldDataQuery as FDQ <EOL> import packages . sahm . pySAHM . MDSBuilder as MDSB <EOL> import packages . sahm . pySAHM . PARC as parc <EOL> import packages . sahm . pySAHM . RasterFormatConverter as RFC <EOL> import packages . sahm . pySAHM . MaxentRunner as MaxentRunner <EOL> from SahmOutputViewer import SAHMModelOutputViewerCell <EOL> from SahmSpatialOutputViewer import SAHMSpatialOutputViewerCell <EOL> from utils import writetolog <EOL> from pySAHM . utilities import TrappedError <EOL> from SahmSpatialOutputViewer import setQGIS <EOL> identifier = '<STR_LIT>' <EOL> def menu_items ( ) : <EOL> """<STR_LIT>""" <EOL> def change_session_folder ( ) : <EOL> global session_dir <EOL> path = str ( QtGui . QFileDialog . getExistingDirectory ( None , <EOL> '<STR_LIT>' ) ) <EOL> session_dir = path <EOL> utils . setrootdir ( path ) <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> + "<STR_LIT:\n>" + "<STR_LIT:*>" * <NUM_LIT> ) <EOL> writetolog ( "<STR_LIT>" + session_dir ) <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> + "<STR_LIT:\n>" + "<STR_LIT:*>" * <NUM_LIT> ) <EOL> lst = [ ] <EOL> lst . append ( ( "<STR_LIT>" , change_session_folder ) ) <EOL> return ( lst ) <EOL> def expand_ports ( port_list ) : <EOL> new_port_list = [ ] <EOL> for port in port_list : <EOL> port_spec = port [ <NUM_LIT:1> ] <EOL> if type ( port_spec ) == str : <EOL> if port_spec . startswith ( '<STR_LIT:(>' ) : <EOL> port_spec = port_spec [ <NUM_LIT:1> : ] <EOL> if port_spec . endswith ( '<STR_LIT:)>' ) : <EOL> port_spec = port_spec [ : - <NUM_LIT:1> ] <EOL> new_spec_list = [ ] <EOL> for spec in port_spec . split ( '<STR_LIT:U+002C>' ) : <EOL> spec = spec . strip ( ) <EOL> parts = spec . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> namespace = None <EOL> if len ( parts ) > <NUM_LIT:1> : <EOL> mod_parts = parts [ <NUM_LIT:1> ] . rsplit ( '<STR_LIT:|>' , <NUM_LIT:1> ) <EOL> if len ( mod_parts ) > <NUM_LIT:1> : <EOL> namespace , module_name = mod_parts <EOL> else : <EOL> module_name = parts [ <NUM_LIT:1> ] <EOL> if len ( parts [ <NUM_LIT:0> ] . split ( '<STR_LIT:.>' ) ) == <NUM_LIT:1> : <EOL> id_str = '<STR_LIT>' + parts [ <NUM_LIT:0> ] <EOL> else : <EOL> id_str = parts [ <NUM_LIT:0> ] <EOL> else : <EOL> mod_parts = spec . rsplit ( '<STR_LIT:|>' , <NUM_LIT:1> ) <EOL> if len ( mod_parts ) > <NUM_LIT:1> : <EOL> namespace , module_name = mod_parts <EOL> else : <EOL> module_name = spec <EOL> id_str = identifier <EOL> if namespace : <EOL> new_spec_list . append ( id_str + '<STR_LIT::>' + module_name + '<STR_LIT::>' + namespace ) <EOL> else : <EOL> new_spec_list . append ( id_str + '<STR_LIT::>' + module_name ) <EOL> port_spec = '<STR_LIT:(>' + '<STR_LIT:U+002C>' . join ( new_spec_list ) + '<STR_LIT:)>' <EOL> new_port_list . append ( ( port [ <NUM_LIT:0> ] , port_spec ) + port [ <NUM_LIT:2> : ] ) <EOL> return new_port_list <EOL> class FieldData ( Path ) : <EOL> '''<STR_LIT>''' <EOL> _output_ports = [ ( '<STR_LIT:value>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) ] <EOL> class AggregationMethod ( String ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT:value>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' , True ) ] <EOL> _widget_class = build_enum_widget ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:None>' ] ) <EOL> @ staticmethod <EOL> def get_widget_class ( ) : <EOL> return AggregationMethod . _widget_class <EOL> class ResampleMethod ( String ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT:value>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' , True ) ] <EOL> _widget_class = build_enum_widget ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ staticmethod <EOL> def get_widget_class ( ) : <EOL> return ResampleMethod . _widget_class <EOL> class Predictor ( Constant ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) } ) , <EOL> ( '<STR_LIT:file>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( '<STR_LIT:value>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) ] <EOL> def compute ( self ) : <EOL> if ( self . has_input ( "<STR_LIT>" ) ) : <EOL> resampleMethod = self . get_input ( "<STR_LIT>" ) <EOL> if resampleMethod . lower ( ) not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ModuleError ( self , <EOL> "<STR_LIT>" ) <EOL> else : <EOL> resampleMethod = '<STR_LIT>' <EOL> if ( self . has_input ( "<STR_LIT>" ) ) : <EOL> aggregationMethod = self . get_input ( "<STR_LIT>" ) <EOL> if self . get_input ( "<STR_LIT>" ) . lower ( ) not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:none>' ] : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> else : <EOL> aggregationMethod = "<STR_LIT>" <EOL> if ( self . has_input ( "<STR_LIT>" ) ) : <EOL> if self . get_input ( "<STR_LIT>" ) == True : <EOL> categorical = '<STR_LIT:1>' <EOL> else : <EOL> categorical = '<STR_LIT:0>' <EOL> else : <EOL> categorical = '<STR_LIT:0>' <EOL> if ( self . has_input ( "<STR_LIT:file>" ) ) : <EOL> inFile = utils . getRasterName ( self . get_input ( "<STR_LIT:file>" ) . name ) <EOL> else : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> self . set_output ( '<STR_LIT:value>' , ( inFile , categorical , resampleMethod , aggregationMethod ) ) <EOL> class PredictorList ( Constant ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = expand_ports ( [ ( '<STR_LIT:value>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> _output_ports = expand_ports ( [ ( '<STR_LIT:value>' , '<STR_LIT>' ) ] ) <EOL> @ staticmethod <EOL> def translate_to_string ( v ) : <EOL> return str ( v ) <EOL> @ staticmethod <EOL> def translate_to_python ( v ) : <EOL> v_list = eval ( v ) <EOL> return v_list <EOL> @ staticmethod <EOL> def validate ( x ) : <EOL> return type ( x ) == list <EOL> def compute ( self ) : <EOL> p_list = self . force_get_input_list ( "<STR_LIT>" ) <EOL> v = self . force_get_input ( "<STR_LIT:value>" , [ ] ) <EOL> b = self . validate ( v ) <EOL> if not b : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> if len ( v ) > <NUM_LIT:0> and type ( v [ <NUM_LIT:0> ] ) == tuple : <EOL> f_list = [ utils . create_file_module ( v_elt [ <NUM_LIT:1> ] ) for v_elt in v ] <EOL> else : <EOL> f_list = v <EOL> p_list += f_list <EOL> self . set_output ( "<STR_LIT:value>" , v ) <EOL> class PredictorListFile ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> _output_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> @ staticmethod <EOL> def translate_to_string ( v ) : <EOL> return str ( v ) <EOL> @ staticmethod <EOL> def translate_to_python ( v ) : <EOL> v_list = eval ( v ) <EOL> return v_list <EOL> @ staticmethod <EOL> def validate ( x ) : <EOL> return type ( x ) == list <EOL> def compute ( self ) : <EOL> if not ( self . has_input ( "<STR_LIT>" ) or <EOL> self . has_input ( "<STR_LIT>" ) ) : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> output_fname = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> if ( self . has_input ( "<STR_LIT>" ) and <EOL> os . path . exists ( self . get_input ( "<STR_LIT>" ) . name ) ) : <EOL> shutil . copy ( self . get_input ( "<STR_LIT>" ) . name , <EOL> output_fname ) <EOL> csv_writer = csv . writer ( open ( output_fname , '<STR_LIT>' ) ) <EOL> else : <EOL> csv_writer = csv . writer ( open ( output_fname , '<STR_LIT:wb>' ) ) <EOL> csv_writer . writerow ( [ "<STR_LIT:file>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> if self . has_input ( "<STR_LIT>" ) : <EOL> p_list = self . force_get_input_list ( "<STR_LIT>" ) <EOL> for p in p_list : <EOL> if p . has_input ( '<STR_LIT>' ) : <EOL> resMethod = p . get_input ( '<STR_LIT>' ) <EOL> else : <EOL> resMethod = "<STR_LIT>" <EOL> if p . has_input ( '<STR_LIT>' ) : <EOL> aggMethod = p . get_input ( '<STR_LIT>' ) <EOL> else : <EOL> aggMethod = "<STR_LIT>" <EOL> csv_writer . writerow ( [ os . path . normpath ( p . name ) , resMethod , aggMethod ] ) <EOL> del csv_writer <EOL> output_file = utils . create_file_module ( output_fname ) <EOL> self . set_output ( '<STR_LIT>' , output_file ) <EOL> class TemplateLayer ( Path ) : <EOL> '''<STR_LIT>''' <EOL> _output_ports = [ ( '<STR_LIT:value>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) ] <EOL> class MergedDataSet ( File ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> _output_ports = expand_ports ( [ ( '<STR_LIT:value>' , '<STR_LIT>' ) ] ) <EOL> pass <EOL> class RastersWithPARCInfoCSV ( File ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> _output_ports = expand_ports ( [ ( '<STR_LIT:value>' , '<STR_LIT>' ) ] ) <EOL> pass <EOL> class ApplyModel ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def compute ( self ) : <EOL> workspace = self . force_get_input ( '<STR_LIT>' ) . name <EOL> output_dname = utils . mknextdir ( prefix = '<STR_LIT>' ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> mdsFile = self . force_get_input ( '<STR_LIT>' ) . name <EOL> args = "<STR_LIT>" + '<STR_LIT:">' + workspace + '<STR_LIT:">' + "<STR_LIT>" + '<STR_LIT:">' + mdsFile + '<STR_LIT:">' + "<STR_LIT>" + '<STR_LIT:">' + output_dname + '<STR_LIT:">' <EOL> else : <EOL> args = "<STR_LIT>" + '<STR_LIT:">' + workspace + '<STR_LIT:">' + "<STR_LIT>" + '<STR_LIT:">' + output_dname + '<STR_LIT:">' <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> makeBinMap = self . force_get_input ( '<STR_LIT>' ) <EOL> args += '<STR_LIT>' + str ( makeBinMap ) . upper ( ) <EOL> else : <EOL> args += '<STR_LIT>' <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> makeProbabilityMap = self . force_get_input ( '<STR_LIT>' ) <EOL> args += '<STR_LIT>' + str ( makeProbabilityMap ) . upper ( ) <EOL> else : <EOL> args += '<STR_LIT>' <EOL> utils . runRScript ( '<STR_LIT>' , args , self ) <EOL> input_fname = os . path . join ( output_dname , "<STR_LIT>" ) <EOL> output_fname = os . path . join ( output_dname , '<STR_LIT>' ) <EOL> if os . path . exists ( input_fname ) : <EOL> utils . tif_to_color_jpeg ( input_fname , output_fname , color_breaks_csv ) <EOL> output_file1 = utils . create_file_module ( output_fname ) <EOL> self . set_output ( '<STR_LIT>' , output_file1 ) <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" <EOL> writetolog ( msg , False , True ) <EOL> raise ModuleError ( self , msg ) <EOL> if os . path . exists ( os . path . join ( output_dname , "<STR_LIT>" ) ) : <EOL> outFileName = os . path . join ( output_dname , "<STR_LIT>" ) <EOL> output_file2 = utils . create_file_module ( outFileName ) <EOL> self . set_output ( '<STR_LIT>' , output_file2 ) <EOL> class Model ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:True>' ] ) , '<STR_LIT>' : False } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:True>' ] ) , '<STR_LIT>' : False } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:False>' ] ) , '<STR_LIT>' : False } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:2>' ] ) , '<STR_LIT>' : False } ) <EOL> ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def compute ( self ) : <EOL> global color_breaks_csv <EOL> ModelOutput = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> ModelAbbrev = ModelOutput [ self . name ] <EOL> output_dname = utils . mknextdir ( prefix = ModelAbbrev + '<STR_LIT>' ) <EOL> argsDict = utils . map_ports ( self , self . port_map ) <EOL> mdsFile = self . force_get_input ( '<STR_LIT>' ) . name <EOL> args = '<STR_LIT>' <EOL> for k , v in argsDict . iteritems ( ) : <EOL> if k == '<STR_LIT:c>' : <EOL> args += '<STR_LIT:U+0020>' + '<STR_LIT:=>' . join ( [ str ( k ) , '<STR_LIT:">' + str ( v ) + '<STR_LIT:">' ] ) <EOL> else : <EOL> args += '<STR_LIT:U+0020>' + '<STR_LIT:=>' . join ( [ str ( k ) , str ( v ) ] ) <EOL> args += "<STR_LIT>" + '<STR_LIT:">' + output_dname + '<STR_LIT:">' <EOL> args += "<STR_LIT>" + utils . MDSresponseCol ( mdsFile ) <EOL> utils . runRScript ( self . name , args , self ) <EOL> input_fname = os . path . join ( output_dname , ModelAbbrev + "<STR_LIT>" ) <EOL> output_fname = os . path . join ( output_dname , ModelAbbrev + "<STR_LIT>" ) <EOL> if os . path . exists ( input_fname ) : <EOL> self . set_output ( '<STR_LIT>' , input_fname ) <EOL> elif ( argsDict . has_key ( '<STR_LIT>' ) and argsDict [ '<STR_LIT>' ] == True ) or not argsDict . has_key ( '<STR_LIT>' ) : <EOL> msg = "<STR_LIT>" + ModelAbbrev + "<STR_LIT>" <EOL> msg += "<STR_LIT>" <EOL> msg += "<STR_LIT>" <EOL> writetolog ( msg , False , True ) <EOL> raise ModuleError ( self , msg ) <EOL> if ( argsDict . has_key ( '<STR_LIT>' ) and argsDict [ '<STR_LIT>' ] == True ) or not argsDict . has_key ( '<STR_LIT>' ) : <EOL> outFileName = os . path . join ( output_dname , ModelAbbrev + "<STR_LIT>" ) <EOL> output_file1 = utils . create_file_module ( outFileName ) <EOL> self . set_output ( '<STR_LIT>' , output_file1 ) <EOL> outFileName = os . path . join ( output_dname , ModelAbbrev + "<STR_LIT>" ) <EOL> output_file2 = utils . create_file_module ( outFileName ) <EOL> self . set_output ( '<STR_LIT>' , output_file2 ) <EOL> outFileName = os . path . join ( output_dname , ModelAbbrev + "<STR_LIT>" ) <EOL> output_file3 = utils . create_file_module ( outFileName ) <EOL> self . set_output ( '<STR_LIT>' , output_file3 ) <EOL> outFileName = os . path . join ( output_dname , ModelAbbrev + "<STR_LIT>" ) <EOL> output_file5 = utils . create_file_module ( outFileName ) <EOL> self . set_output ( '<STR_LIT>' , output_file5 ) <EOL> outFileName = os . path . join ( output_dname , "<STR_LIT>" ) <EOL> output_file6 = utils . create_file_module ( outFileName ) <EOL> self . set_output ( '<STR_LIT>' , output_file6 ) <EOL> writetolog ( "<STR_LIT>" + ModelAbbrev + "<STR_LIT>" , True , True ) <EOL> class GLM ( Model ) : <EOL> _input_ports = list ( Model . _input_ports ) <EOL> _input_ports . extend ( [ ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) , '<STR_LIT>' : True } ) , <EOL> ] ) <EOL> def __init__ ( self ) : <EOL> global models_path <EOL> Model . __init__ ( self ) <EOL> self . name = '<STR_LIT>' <EOL> self . port_map = { '<STR_LIT>' : ( '<STR_LIT:c>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) <EOL> } <EOL> class RandomForest ( Model ) : <EOL> _input_ports = list ( Model . _input_ports ) <EOL> _input_ports . extend ( [ ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:1>' ] ) , '<STR_LIT>' : True } ) , <EOL> ] ) <EOL> def __init__ ( self ) : <EOL> global models_path <EOL> Model . __init__ ( self ) <EOL> self . name = '<STR_LIT>' <EOL> self . port_map = { '<STR_LIT>' : ( '<STR_LIT:c>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) <EOL> } <EOL> class MARS ( Model ) : <EOL> _input_ports = list ( Model . _input_ports ) <EOL> _input_ports . extend ( [ ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:1>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:2>' ] ) , '<STR_LIT>' : True } ) , <EOL> ] ) <EOL> def __init__ ( self ) : <EOL> global models_path <EOL> Model . __init__ ( self ) <EOL> self . name = '<STR_LIT>' <EOL> self . port_map = { '<STR_LIT>' : ( '<STR_LIT:c>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> } <EOL> class BoostedRegressionTree ( Model ) : <EOL> _input_ports = list ( Model . _input_ports ) <EOL> _input_ports . extend ( [ ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:3>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:1>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:True>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) , '<STR_LIT>' : True } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) , '<STR_LIT>' : True } ) <EOL> ] ) <EOL> def __init__ ( self ) : <EOL> global models_path <EOL> Model . __init__ ( self ) <EOL> self . name = '<STR_LIT>' <EOL> self . port_map = { '<STR_LIT>' : ( '<STR_LIT:c>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , utils . R_boolean , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) <EOL> } <EOL> class MDSBuilder ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> ) <EOL> _output_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def compute ( self ) : <EOL> port_map = { '<STR_LIT>' : ( '<STR_LIT>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , } <EOL> MDSParams = utils . map_ports ( self , port_map ) <EOL> MDSParams [ '<STR_LIT>' ] = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> inputs_csvs = self . force_get_input_list ( '<STR_LIT>' ) <EOL> if len ( inputs_csvs ) == <NUM_LIT:0> : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> if len ( inputs_csvs ) > <NUM_LIT:1> : <EOL> inputs_csv = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> inputs_names = [ f . name for f in inputs_csvs ] <EOL> utils . merge_inputs_csvs ( inputs_names , inputs_csv ) <EOL> else : <EOL> inputs_csv = inputs_csvs [ <NUM_LIT:0> ] . name <EOL> MDSParams [ '<STR_LIT>' ] = inputs_csv <EOL> ourMDSBuilder = MDSB . MDSBuilder ( ) <EOL> utils . PySAHM_instance_params ( ourMDSBuilder , MDSParams ) <EOL> writetolog ( "<STR_LIT>" + ourMDSBuilder . inputsCSV , False , False ) <EOL> writetolog ( "<STR_LIT>" + ourMDSBuilder . fieldData , False , False ) <EOL> writetolog ( "<STR_LIT>" + ourMDSBuilder . outputMDS , False , False ) <EOL> try : <EOL> ourMDSBuilder . run ( ) <EOL> except TrappedError as e : <EOL> raise ModuleError ( self , e . message ) <EOL> except : <EOL> utils . informative_untrapped_error ( self , "<STR_LIT>" ) <EOL> output_file = utils . create_file_module ( ourMDSBuilder . outputMDS ) <EOL> self . set_output ( '<STR_LIT>' , output_file ) <EOL> class FieldDataAggregateAndWeight ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> _output_ports = expand_ports ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def compute ( self ) : <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> port_map = { '<STR_LIT>' : ( '<STR_LIT>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , None , False ) , } <EOL> KDEParams = utils . map_ports ( self , port_map ) <EOL> output_fname = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> writetolog ( "<STR_LIT>" + output_fname , True , False ) <EOL> KDEParams [ '<STR_LIT>' ] = output_fname <EOL> output_fname = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> writetolog ( "<STR_LIT>" + output_fname , True , False ) <EOL> ourFDQ = FDQ . FieldDataQuery ( ) <EOL> utils . PySAHM_instance_params ( ourFDQ , KDEParams ) <EOL> ourFDQ . processCSV ( ) <EOL> output_file = utils . create_file_module ( output_fname ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> self . set_output ( '<STR_LIT>' , output_file ) <EOL> class PARC ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:True>' ] ) , '<STR_LIT>' : True } ) ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def compute ( self ) : <EOL> ourPARC = parc . PARC ( ) <EOL> output_dname = utils . mknextdir ( prefix = '<STR_LIT>' ) <EOL> if configuration . verbose : <EOL> ourPARC . verbose = True <EOL> ourPARC . logger = utils . getLogger ( ) <EOL> ourPARC . out_dir = output_dname <EOL> if self . has_input ( "<STR_LIT>" ) : <EOL> if self . get_input ( "<STR_LIT>" ) : <EOL> ourPARC . multicores = "<STR_LIT:True>" <EOL> workingCSV = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> outputCSV = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> if self . has_input ( "<STR_LIT>" ) : <EOL> inputCSV = self . force_get_input ( "<STR_LIT>" ) . name <EOL> shutil . copy ( inputCSV , workingCSV ) <EOL> f = open ( workingCSV , "<STR_LIT>" ) <EOL> csvWriter = csv . writer ( f ) <EOL> else : <EOL> f = open ( workingCSV , "<STR_LIT:wb>" ) <EOL> csvWriter = csv . writer ( f ) <EOL> csvWriter . writerow ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> if self . has_input ( "<STR_LIT>" ) : <EOL> predictor_lists = self . force_get_input_list ( '<STR_LIT>' ) <EOL> for predictor_list in predictor_lists : <EOL> for predictor in predictor_list : <EOL> csvWriter . writerow ( list ( predictor ) ) <EOL> if self . has_input ( "<STR_LIT>" ) : <EOL> predictor_list = self . force_get_input_list ( '<STR_LIT>' ) <EOL> for predictor in predictor_list : <EOL> csvWriter . writerow ( list ( predictor ) ) <EOL> f . close ( ) <EOL> del csvWriter <EOL> ourPARC . inputs_CSV = workingCSV <EOL> ourPARC . template = self . force_get_input ( '<STR_LIT>' ) . name <EOL> writetolog ( '<STR_LIT>' + self . force_get_input ( '<STR_LIT>' ) . name ) <EOL> writetolog ( "<STR_LIT>" + output_dname , False , False ) <EOL> writetolog ( "<STR_LIT>" + workingCSV , False , False ) <EOL> try : <EOL> ourPARC . parcFiles ( ) <EOL> except TrappedError as e : <EOL> writetolog ( e . message ) <EOL> raise ModuleError ( self , e . message ) <EOL> except : <EOL> utils . informative_untrapped_error ( self , "<STR_LIT>" ) <EOL> os . remove ( workingCSV ) <EOL> predictorsDir = utils . create_dir_module ( output_dname ) <EOL> outputCSV = os . path . join ( output_dname , "<STR_LIT>" ) <EOL> output_file = utils . create_file_module ( outputCSV ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> self . set_output ( '<STR_LIT>' , output_file ) <EOL> class RasterFormatConverter ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : str ( [ '<STR_LIT:True>' ] ) , '<STR_LIT>' : True } ) ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def compute ( self ) : <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> ourRFC = RFC . FormatConverter ( ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> ourRFC . MDSFile = self . force_get_input ( '<STR_LIT>' ) . name <EOL> elif self . has_input ( '<STR_LIT>' ) : <EOL> ourRFC . inputDir = self . force_get_input ( '<STR_LIT>' ) . name <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> format = self . force_get_input ( '<STR_LIT>' ) <EOL> if format == '<STR_LIT>' : <EOL> format = '<STR_LIT>' <EOL> ourRFC . format = format <EOL> if self . has_input ( "<STR_LIT>" ) : <EOL> if self . get_input ( "<STR_LIT>" ) : <EOL> ourRFC . multicores = "<STR_LIT:True>" <EOL> ourRFC . outputDir = utils . mknextdir ( prefix = '<STR_LIT>' ) <EOL> if configuration . verbose : <EOL> ourRFC . verbose = True <EOL> ourRFC . logger = utils . getLogger ( ) <EOL> writetolog ( "<STR_LIT>" + ourRFC . outputDir , False , False ) <EOL> try : <EOL> ourRFC . run ( ) <EOL> except TrappedError as e : <EOL> raise ModuleError ( self , e . message ) <EOL> except : <EOL> utils . informative_untrapped_error ( self , "<STR_LIT>" ) <EOL> outputDir = utils . create_dir_module ( ourRFC . outputDir ) <EOL> self . set_output ( '<STR_LIT>' , outputDir ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> class TestTrainingSplit ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : str ( [ '<STR_LIT>' ] ) } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def compute ( self ) : <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> print '<STR_LIT>' <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> inputMDS = utils . dir_path_value ( self . force_get_input ( '<STR_LIT>' , [ ] ) ) <EOL> outputMDS = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> global models_path <EOL> args = "<STR_LIT>" + '<STR_LIT:">' + inputMDS + '<STR_LIT:">' + "<STR_LIT>" + '<STR_LIT:">' + outputMDS + '<STR_LIT:">' <EOL> args += "<STR_LIT>" + utils . MDSresponseCol ( inputMDS ) <EOL> if ( self . has_input ( "<STR_LIT>" ) ) : <EOL> try : <EOL> trainingProportion = float ( self . get_input ( "<STR_LIT>" ) ) <EOL> if trainingProportion <= <NUM_LIT:0> or trainingProportion > <NUM_LIT:1> : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> args += "<STR_LIT>" + str ( trainingProportion ) <EOL> except : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> if ( self . has_input ( "<STR_LIT>" ) ) : <EOL> try : <EOL> RatioPresAbs = float ( self . get_input ( "<STR_LIT>" ) ) <EOL> if RatioPresAbs <= <NUM_LIT:0> : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> args += "<STR_LIT>" + str ( trainingProportion ) <EOL> except : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> utils . runRScript ( "<STR_LIT>" , args , self ) <EOL> output = os . path . join ( outputMDS ) <EOL> if os . path . exists ( output ) : <EOL> output_file = utils . create_file_module ( output ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> writetolog ( msg , False ) <EOL> raise ModuleError ( self , msg ) <EOL> self . set_output ( "<STR_LIT>" , output_file ) <EOL> class CovariateCorrelationAndSelection ( Module ) : <EOL> '''<STR_LIT>''' <EOL> kwargs = { } <EOL> kwargs [ '<STR_LIT>' ] = str ( [ '<STR_LIT>' ] ) <EOL> _input_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , kwargs ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def compute ( self ) : <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> inputMDS = utils . dir_path_value ( self . force_get_input ( '<STR_LIT>' ) ) <EOL> selectionName = self . force_get_input ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> global session_dir <EOL> outputMDS = os . path . join ( session_dir , "<STR_LIT>" + selectionName + "<STR_LIT>" ) <EOL> displayJPEG = os . path . join ( session_dir , "<STR_LIT>" ) <EOL> writetolog ( "<STR_LIT>" + inputMDS , False , False ) <EOL> writetolog ( "<STR_LIT>" + displayJPEG , False , False ) <EOL> writetolog ( "<STR_LIT>" + outputMDS , False , False ) <EOL> if os . path . exists ( outputMDS ) : <EOL> utils . applyMDS_selection ( outputMDS , inputMDS ) <EOL> os . remove ( outputMDS ) <EOL> self . callDisplayMDS ( inputMDS , outputMDS , displayJPEG ) <EOL> output_file = utils . create_file_module ( outputMDS ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> self . set_output ( "<STR_LIT>" , output_file ) <EOL> def callDisplayMDS ( self , inputMDS , outputMDS , displayJPEG ) : <EOL> dialog = SelectListDialog ( inputMDS , outputMDS , displayJPEG , configuration . r_path ) <EOL> retVal = dialog . exec_ ( ) <EOL> if retVal == <NUM_LIT:1> : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> class ProjectionLayers ( Module ) : <EOL> '''<STR_LIT>''' <EOL> _input_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] <EOL> _output_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def compute ( self ) : <EOL> models = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> scenarioss = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> years = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> inputCSV = self . force_get_input ( '<STR_LIT>' ) . name <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> template = self . force_get_input ( '<STR_LIT>' ) . name <EOL> else : <EOL> template = '<STR_LIT>' <EOL> fromto = [ ] <EOL> climargs = { } <EOL> for input in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if self . has_input ( input ) : <EOL> climargs [ input ] = self . force_get_input ( input ) <EOL> if climargs < > { } and climargs . keys ( ) < > [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> elif climargs < > { } and climargs . keys < > [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> fromto . append ( [ r'<STR_LIT>' , <EOL> os . path . join ( '<STR_LIT>' , <EOL> climargs [ '<STR_LIT>' ] , climargs [ '<STR_LIT>' ] , climargs [ '<STR_LIT>' ] ) ] ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> crosswalkCSV = csv . reader ( open ( self . force_get_input ( '<STR_LIT>' ) , '<STR_LIT:r>' ) ) <EOL> header = crosswalkCSV <EOL> for row in crosswalkCSV : <EOL> fromto . append ( row [ <NUM_LIT:0> ] , row [ <NUM_LIT:1> ] ) <EOL> del crosswalkCSV <EOL> inCSV = csv . reader ( open ( inputCSV , '<STR_LIT:r>' ) ) <EOL> inCSV . next ( ) <EOL> workingCSV = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> tmpCSV = csv . writer ( open ( workingCSV , '<STR_LIT:wb>' ) ) <EOL> tmpCSV . writerow ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> outHeader1 = [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' ] <EOL> outHeader2 = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> outHeader3 = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> output_dname = utils . mknextdir ( prefix = '<STR_LIT>' ) <EOL> for row in inCSV : <EOL> if template == '<STR_LIT>' : <EOL> template = row [ <NUM_LIT:0> ] <EOL> fileShortName = utils . getShortName ( row [ <NUM_LIT:0> ] ) <EOL> if row [ <NUM_LIT:1> ] == <NUM_LIT:1> : <EOL> outHeader1 . append ( fileShortName + '<STR_LIT>' ) <EOL> else : <EOL> outHeader1 . append ( fileShortName ) <EOL> outHeader2 . append ( '<STR_LIT:1>' ) <EOL> outHeader3 . append ( os . path . join ( output_dname , fileShortName + '<STR_LIT>' ) ) <EOL> origFile = row [ <NUM_LIT:4> ] <EOL> newOrigFile = origFile <EOL> for lookup in fromto : <EOL> if lookup [ <NUM_LIT:0> ] in origFile : <EOL> newOrigFile = origFile . replace ( lookup [ <NUM_LIT:0> ] , lookup [ <NUM_LIT:1> ] ) <EOL> tmpCSV . writerow ( [ newOrigFile , ] + row [ <NUM_LIT:1> : <NUM_LIT:4> ] ) <EOL> del tmpCSV <EOL> ourPARC = parc . PARC ( ) <EOL> if configuration . verbose : <EOL> ourPARC . verbose = True <EOL> writetolog ( "<STR_LIT>" + output_dname , False , False ) <EOL> ourPARC . outDir = output_dname <EOL> ourPARC . inputsCSV = workingCSV <EOL> ourPARC . template = template <EOL> try : <EOL> ourPARC . parcFiles ( ) <EOL> except TrappedError as e : <EOL> raise ModuleError ( self , e . message ) <EOL> except : <EOL> utils . informative_untrapped_error ( self , "<STR_LIT>" ) <EOL> outputMDS = os . path . join ( output_dname , '<STR_LIT>' ) <EOL> outCSV = csv . writer ( open ( outputMDS , '<STR_LIT:wb>' ) ) <EOL> outCSV . writerow ( outHeader1 ) <EOL> outCSV . writerow ( outHeader2 ) <EOL> outCSV . writerow ( outHeader3 ) <EOL> output_file = utils . create_file_module ( outputMDS ) <EOL> self . set_output ( "<STR_LIT>" , output_file ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> class MAXENT ( Module ) : <EOL> _output_ports = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def compute ( self ) : <EOL> global maxent_path <EOL> ourMaxent = MaxentRunner . MAXENTRunner ( ) <EOL> ourMaxent . outputDir = utils . mknextdir ( prefix = '<STR_LIT>' ) <EOL> ourMaxent . inputMDS = self . force_get_input ( '<STR_LIT>' ) . name <EOL> ourMaxent . maxentpath = maxent_path <EOL> MaxentArgsCSV = utils . mknextfile ( prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) <EOL> argWriter = csv . writer ( open ( MaxentArgsCSV , '<STR_LIT:wb>' ) ) <EOL> argWriter . writerow ( [ '<STR_LIT>' , '<STR_LIT:value>' ] ) <EOL> for port in self . _input_ports : <EOL> if port [ <NUM_LIT:0> ] < > '<STR_LIT>' and port [ <NUM_LIT:0> ] < > '<STR_LIT>' : <EOL> if self . has_input ( port [ <NUM_LIT:0> ] ) : <EOL> port_val = self . get_input ( port [ <NUM_LIT:0> ] ) <EOL> if port [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> port_val = str ( port_val ) . lower ( ) <EOL> elif ( port [ <NUM_LIT:1> ] == "<STR_LIT>" or port [ <NUM_LIT:1> ] == "<STR_LIT>" ) : <EOL> port_val = port_val . name <EOL> argWriter . writerow ( [ port [ <NUM_LIT:0> ] , port_val ] ) <EOL> else : <EOL> kwargs = port [ <NUM_LIT:2> ] <EOL> try : <EOL> if port [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> default = kwargs [ '<STR_LIT>' ] [ <NUM_LIT:2> : - <NUM_LIT:2> ] . lower ( ) <EOL> else : <EOL> default = kwargs [ '<STR_LIT>' ] [ <NUM_LIT:2> : - <NUM_LIT:2> ] <EOL> argWriter . writerow ( [ port [ <NUM_LIT:0> ] , default ] ) <EOL> except KeyError : <EOL> pass <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> value = self . force_get_input_list ( '<STR_LIT>' ) <EOL> projlayers = '<STR_LIT:U+002C>' . join ( [ path . name for path in value ] ) <EOL> argWriter . writerow ( [ '<STR_LIT>' , projlayers ] ) <EOL> del argWriter <EOL> ourMaxent . argsCSV = MaxentArgsCSV <EOL> ourMaxent . logger = utils . getLogger ( ) <EOL> try : <EOL> ourMaxent . run ( ) <EOL> except TrappedError as e : <EOL> raise ModuleError ( self , e . message ) <EOL> except : <EOL> utils . informative_untrapped_error ( self , "<STR_LIT>" ) <EOL> lambdasfile = os . path . join ( ourMaxent . outputDir , ourMaxent . args [ "<STR_LIT>" ] + "<STR_LIT>" ) <EOL> output_file = utils . create_file_module ( lambdasfile ) <EOL> self . set_output ( "<STR_LIT>" , output_file ) <EOL> rocfile = os . path . join ( ourMaxent . outputDir , '<STR_LIT>' , ourMaxent . args [ "<STR_LIT>" ] + "<STR_LIT>" ) <EOL> output_file = utils . create_file_module ( rocfile ) <EOL> self . set_output ( "<STR_LIT>" , output_file ) <EOL> htmlfile = os . path . join ( ourMaxent . outputDir , ourMaxent . args [ "<STR_LIT>" ] + "<STR_LIT>" ) <EOL> print htmlfile <EOL> output_file = utils . create_file_module ( htmlfile ) <EOL> self . set_output ( "<STR_LIT>" , output_file ) <EOL> writetolog ( "<STR_LIT>" , True ) <EOL> def load_max_ent_params ( ) : <EOL> maxent_fname = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> csv_reader = csv . reader ( open ( maxent_fname , '<STR_LIT>' ) ) <EOL> csv_reader . next ( ) <EOL> input_ports = [ ] <EOL> input_ports . append ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> docs = { } <EOL> basic_pkg = '<STR_LIT>' <EOL> p_type_map = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> for row in csv_reader : <EOL> [ name , flag , p_type , default , doc , notes ] = row <EOL> name = name . strip ( ) <EOL> p_type = p_type . strip ( ) <EOL> if p_type in p_type_map : <EOL> p_type = p_type_map [ str ( p_type ) ] <EOL> else : <EOL> p_type = str ( p_type ) . capitalize ( ) <EOL> kwargs = { } <EOL> default = default . strip ( ) <EOL> if default : <EOL> if p_type == '<STR_LIT>' : <EOL> default = default . capitalize ( ) <EOL> kwargs [ '<STR_LIT>' ] = str ( [ default ] ) <EOL> if p_type == '<STR_LIT>' : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> input_ports . append ( ( name , '<STR_LIT:(>' + basic_pkg + '<STR_LIT::>' + p_type + '<STR_LIT:)>' , kwargs ) ) <EOL> docs [ name ] = doc <EOL> MAXENT . _input_ports = input_ports <EOL> MAXENT . _port_docs = docs <EOL> def provide_input_port_documentation ( cls , port_name ) : <EOL> return cls . _port_docs [ port_name ] <EOL> MAXENT . provide_input_port_documentation = classmethod ( provide_input_port_documentation ) <EOL> def initialize ( ) : <EOL> global maxent_path , color_breaks_csv <EOL> global session_dir <EOL> utils . config = configuration <EOL> r_path = os . path . abspath ( configuration . r_path ) <EOL> maxent_path = os . path . abspath ( configuration . maxent_path ) <EOL> import qgis . core <EOL> import qgis . gui <EOL> globals ( ) [ "<STR_LIT>" ] = qgis <EOL> setQGIS ( qgis ) <EOL> qgis_prefix = os . path . join ( configuration . qgis_path , "<STR_LIT>" ) <EOL> qgis . core . QgsApplication . setPrefixPath ( qgis_prefix , True ) <EOL> qgis . core . QgsApplication . initQgis ( ) <EOL> session_dir = utils . createrootdir ( configuration . output_dir ) <EOL> utils . createLogger ( session_dir , configuration . output_dir ) <EOL> color_breaks_csv = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> load_max_ent_params ( ) <EOL> global layers_csv_fname <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> ) <EOL> writetolog ( "<STR_LIT>" , True , True ) <EOL> writetolog ( "<STR_LIT>" ) <EOL> writetolog ( "<STR_LIT>" + layers_csv_fname ) <EOL> writetolog ( "<STR_LIT>" + r_path ) <EOL> writetolog ( "<STR_LIT>" + os . path . abspath ( configuration . gdal_path ) ) <EOL> writetolog ( "<STR_LIT>" ) <EOL> writetolog ( "<STR_LIT>" + maxent_path ) <EOL> writetolog ( "<STR_LIT>" + os . path . abspath ( configuration . qgis_path ) ) <EOL> writetolog ( "<STR_LIT>" ) <EOL> writetolog ( "<STR_LIT:U+0020>" ) <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> ) <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> ) <EOL> writetolog ( "<STR_LIT>" + session_dir ) <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> ) <EOL> writetolog ( "<STR_LIT:*>" * <NUM_LIT> ) <EOL> def finalize ( ) : <EOL> pass <EOL> def generate_namespaces ( modules ) : <EOL> module_list = [ ] <EOL> for namespace , m_list in modules . iteritems ( ) : <EOL> for module in m_list : <EOL> m_dict = { '<STR_LIT>' : namespace } <EOL> if type ( module ) == tuple : <EOL> m_dict . update ( module [ <NUM_LIT:1> ] ) <EOL> module_list . append ( ( module [ <NUM_LIT:0> ] , m_dict ) ) <EOL> else : <EOL> module_list . append ( ( module , m_dict ) ) <EOL> return module_list <EOL> def build_available_trees ( ) : <EOL> trees = { } <EOL> global layers_csv_fname <EOL> layers_csv_fname = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> csv_reader = csv . reader ( open ( layers_csv_fname , '<STR_LIT>' ) ) <EOL> csv_reader . next ( ) <EOL> first_file = csv_reader . next ( ) [ <NUM_LIT:0> ] <EOL> if not os . path . exists ( first_file ) : <EOL> print ( ( "<STR_LIT:!>" * <NUM_LIT:30> ) + "<STR_LIT>" + ( "<STR_LIT:!>" * <NUM_LIT:30> ) + "<STR_LIT:\n>" ) * <NUM_LIT:3> <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" + layers_csv_fname + "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print ( ( "<STR_LIT:!>" * <NUM_LIT:30> ) + "<STR_LIT>" + ( "<STR_LIT:!>" * <NUM_LIT:30> ) + "<STR_LIT:\n>" ) * <NUM_LIT:3> <EOL> layers_csv_fname = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> csv_reader = csv . reader ( open ( layers_csv_fname , '<STR_LIT>' ) ) <EOL> csv_reader . next ( ) <EOL> for row in csv_reader : <EOL> if row [ <NUM_LIT:2> ] not in trees : <EOL> trees [ row [ <NUM_LIT:2> ] ] = { } <EOL> available_dict = trees [ row [ <NUM_LIT:2> ] ] <EOL> if row [ <NUM_LIT:3> ] not in available_dict : <EOL> available_dict [ row [ <NUM_LIT:3> ] ] = [ ] <EOL> available_dict [ row [ <NUM_LIT:3> ] ] . append ( ( row [ <NUM_LIT:0> ] , row [ <NUM_LIT:1> ] , row [ <NUM_LIT:4> ] ) ) <EOL> return trees <EOL> def build_predictor_modules ( ) : <EOL> available_trees = build_available_trees ( ) <EOL> modules = [ ] <EOL> for name , tree in available_trees . iteritems ( ) : <EOL> name_arr = name . strip ( ) . split ( ) <EOL> class_base = '<STR_LIT>' . join ( n . capitalize ( ) for n in name_arr ) <EOL> widget_class = get_predictor_widget ( class_base , tree ) <EOL> config_class = get_predictor_config ( class_base , tree ) <EOL> class_name = class_base + "<STR_LIT>" <EOL> def get_widget_method ( w_class ) : <EOL> @ staticmethod <EOL> def get_widget_class ( ) : <EOL> return w_class <EOL> return get_widget_class <EOL> module = type ( class_name , ( PredictorList , ) , <EOL> { '<STR_LIT>' : get_widget_method ( widget_class ) , <EOL> '<STR_LIT>' : [ ( '<STR_LIT:value>' , <EOL> '<STR_LIT>' % class_name , True ) ] } ) <EOL> modules . append ( ( module , { '<STR_LIT>' : config_class } ) ) <EOL> for module in modules : <EOL> module [ <NUM_LIT:0> ] . _output_ports . append ( ( '<STR_LIT>' , '<STR_LIT>' , True ) ) <EOL> return modules <EOL> _modules = generate_namespaces ( { '<STR_LIT>' : [ <EOL> Predictor , <EOL> PredictorListFile , <EOL> FieldData , <EOL> TemplateLayer ] + build_predictor_modules ( ) , <EOL> '<STR_LIT>' : [ FieldDataAggregateAndWeight , <EOL> MDSBuilder , <EOL> PARC , <EOL> RasterFormatConverter , <EOL> ProjectionLayers , <EOL> TestTrainingSplit , <EOL> CovariateCorrelationAndSelection , <EOL> ApplyModel ] , <EOL> '<STR_LIT>' : [ GLM , <EOL> RandomForest , <EOL> MARS , <EOL> MAXENT , <EOL> BoostedRegressionTree ] , <EOL> '<STR_LIT>' : [ ( Model , { '<STR_LIT>' : True } ) , <EOL> ( ResampleMethod , { '<STR_LIT>' : True } ) , <EOL> ( AggregationMethod , { '<STR_LIT>' : True } ) , <EOL> ( PredictorList , { '<STR_LIT>' : True } ) , <EOL> ( MergedDataSet , { '<STR_LIT>' : True } ) , <EOL> ( RastersWithPARCInfoCSV , { '<STR_LIT>' : True } ) ] , <EOL> '<STR_LIT>' : [ SAHMModelOutputViewerCell , <EOL> SAHMSpatialOutputViewerCell , <EOL> ] <EOL> } ) </s>
