Пример #1
0
    def buid_dict_from_ini_file(self, section):
        """
        Return the .cfg file as a series of dictionaries depending on which section is called.

        the configparser package reads everything as a string, so we have to cast it
        ourselves. This isn't entriely straightforward, as we need to (i) catch None's,
        (ii) catch underscores as isalpha() ignores these and (iii) cast float/ints

        Parameters:
        -----------
        section : string
            Identifier to grab the relevant section from the .cfg file, e.g. "params"

        Returns:
        --------
        d : dictionary
            dictionary containing stuff from the .cfg file.
        """
        flags = ['model_optroot', "deciduous_model", \
                 'water_stress', "fixleafnc", "passiveconst", \
                 "calc_sw_params",'fixed_stem_nc','exudation',\
                 'adjust_rtslow', 'ncycle', 'grazing','output_ascii',\
                 'frost']
        flags_up = ["assim_model", "print_options", "alloc_model", \
                    "ps_pathway","gs_model", "respiration_model"]

        d = {}
        options = self.Config.options(section)
        for option in options:
            try:
                value = self.Config.get(section, option)
                if section == "params" or section == "state":
                    if value.replace('_','').isalpha() and value != "None":
                        d[option] = value
                    elif value.replace('_','').isalpha() and value == "None":
                        d[option] = None
                    else:
                        d[option] = float(value)
                elif section == "control":
                    if option in flags:
                        d[option] = str2boolean(value)
                    elif option in flags_up:
                        d[option] = value.upper()
                    elif value.replace('_','').isalpha() and value != "None":
                        d[option] = value
                    elif value.replace('_','').isalpha() and value == "None":
                        d[option] = None
                    else:
                        d[option] = int(value)
                elif section == "print" or section == "files":
                    d[option] = value
            except:
                print("Error reading .Cfg file into dicitonary: %s!" % option)
                d[option] = None

        return d
Пример #2
0
    def buid_dict_from_ini_file(self, section):
        """
        Return the .cfg file as a series of dictionaries depending on which section is called.

        the configparser package reads everything as a string, so we have to cast it
        ourselves. This isn't entriely straightforward, as we need to (i) catch None's,
        (ii) catch underscores as isalpha() ignores these and (iii) cast float/ints

        Parameters:
        -----------
        section : string
            Identifier to grab the relevant section from the .cfg file, e.g. "params"

        Returns:
        --------
        d : dictionary
            dictionary containing stuff from the .cfg file.
        """
        flags = ['model_optroot', "deciduous_model", \
                 'water_stress', "fixleafnc", "passiveconst", \
                 "calc_sw_params",'fixed_stem_nc','exudation',\
                 'adjust_rtslow', 'ncycle', 'output_ascii',\
                 'frost']
        flags_up = ["assim_model", "print_options", "alloc_model", \
                    "ps_pathway","gs_model", "respiration_model"]

        d = {}
        options = self.Config.options(section)
        for option in options:
            try:
                value = self.Config.get(section, option)
                if section == "params" or section == "state":
                    if value.replace('_','').isalpha() and value != "None":
                        d[option] = value
                    elif value.replace('_','').isalpha() and value == "None":
                        d[option] = None
                    else:
                        d[option] = float(value)
                elif section == "control":
                    if option in flags:
                        d[option] = str2boolean(value)
                    elif option in flags_up:
                        d[option] = value.upper()
                    elif value.replace('_','').isalpha() and value != "None":
                        d[option] = value
                    elif value.replace('_','').isalpha() and value == "None":
                        d[option] = None
                    else:
                        d[option] = int(value)
                elif section == "print" or section == "files":
                    d[option] = value
            except:
                print("Error reading .Cfg file into dicitonary: %s!" % option)
                d[option] = None

        return d
Пример #3
0
def turn_strings_into_bools(control):
    flags = ['model_optroot', "deciduous_model", "modeljm", \
             "water_stress", "fixleafnc", "passiveconst", "calc_sw_params",\
             'fixed_stem_nc']
    for i in flags:
        setattr(control, i, str2boolean(getattr(control, i)))
Пример #4
0
def turn_strings_into_bools(control):
    flags = ['model_optroot', "deciduous_model", "grazing", "modeljm", \
             "water_stress", "fixleafnc", "passiveconst"]
    for i in flags:
        setattr(control, i, str2boolean(getattr(control, i)))
Пример #5
0
def turn_strings_into_bools(control):
    flags = ['model_optroot', "deciduous_model", "grazing", "modeljm", \
             "water_stress", "fixleafnc", "passiveconst"]
    for i in flags:
        setattr(control, i, str2boolean(getattr(control, i)))