Esempio n. 1
0
    def get_parameter(self, parameter_name, parameter_type):
        """
        Returns a parameter from self.parameter as a requested type.

        Parameters
        ----------
        parameter_name : string
            Name of the parameter requested.
        parameter_type : string
            Type the parameter is requested in. Currently    
            supported: float, positive_float, int, positive_int, string,
            boolean.

        Returns
        -------
        <Type as requested in parameter_type>
            Well the parameter request casted as the type requested

        """
        if parameter_name not in self.parameters:
            sys.exit("No parameter called " + parameter_name \
                     + " is defined in parameters.csv")
        value_str = self.parameters[parameter_name]
        
        cast = Cast("Get Parameter")
        if parameter_type == "float":
            return cast.to_float(value_str, parameter_name)
        elif parameter_type == "positive_float":
            return cast.to_positive_float(value_str, parameter_name)
        elif parameter_type == "int":
            return cast.to_int(value_str, parameter_name)
        elif parameter_type == "positive_int":
            return cast.to_positive_int(value_str, parameter_name)
        elif parameter_type == "string":
            return value_str
        elif parameter_type == "boolean":
            return cast.to_boolean(value_str, parameter_name)
        else:
            sys.exit("Type '" + parameter_type + "' for parameter " \
                     + parameter_name + " is not recognised")
                read_header = True
        else:
            data_point = []
            for it, slcted_col in enumerate(slcted_cols):
                string = row[slcted_col]
                if slcted_col_types[it] == "date":
                    # remove excess characters
                    for char in remove_char_from_Date:
                        string = string.replace(char, '')
                    # remove seconds
                    string = string[:-2]
                    # store
                    data_point.append(string)
                elif slcted_col_types[it] == "int":
                    data_point.append(
                        str(cast.to_int(string, slcted_col_names[it])))
                elif slcted_col_types[it] == "float":
                    data_point.append(
                        str(cast.to_float(string, slcted_col_names[it])))
                else:
                    sys.exit("Data type '" + slcted_col_types[it] \
                             + "' not implemented.")
            data.append(data_point)
"""
SECTION 2: Store unprocessed data
"""

if store_raw_data == True:
    print("Store raw data!")

    with open('solar_irradiance.csv', mode='w', newline='') as output_file: