def format_to_monthly_dict(values): """ Format array of values into a dictionary with monthly keys. Parameters ---------- values: list List containing lists of monthly values; shape is n x 12 Returns ------- values_dict : dictionary Dictionary containing monthly keys with corresponding values. Notes ----- { "January": [2.0, 1.0], "February": [0.98, 0.99], "March": [0.97, 1.10], "April": [1.04, 1.02], "May": [1.10, 0.99], "June": [0.99, 0.98], "July": [0.87, 0.75], "August": [0.75, 0.95], "September": [0.95, 0.9], "October": [0.98, 0.8], "November": [1.10, 1.05], "December": [2.0, 1.10] } """ assert np.shape(values)[1] == 12 months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] values_dict = helpers.create_monthly_dict() month_enum_list = list(enumerate(months)) for values_list in values: for index, month in month_enum_list: values_dict[month].append(values_list[index]) return values_dict
def format_to_monthly_dict(values): """ Format array of values into a dictionary with monthly keys. Parameters ---------- values: list List containing lists of monthly values; shape is n x 12 Returns ------- values_dict : dictionary Dictionary containing monthly keys with corresponding values. Notes ----- { "January": [2.0, 1.0], "February": [0.98, 0.99], "March": [0.97, 1.10], "April": [1.04, 1.02], "May": [1.10, 0.99], "June": [0.99, 0.98], "July": [0.87, 0.75], "August": [0.75, 0.95], "September": [0.95, 0.9], "October": [0.98, 0.8], "November": [1.10, 1.05], "December": [2.0, 1.10] } """ assert np.shape(values)[1] == 12 months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] values_dict = helpers.create_monthly_dict() month_enum_list = list(enumerate(months)) for values_list in values: for index, month in month_enum_list: values_dict[month].append(values_list[index]) return values_dict
def calculate_avg_delta_values(deltas_data, tile_list): """ Get monthly averaged delta data values for a specific list of tiles. Parameters ---------- delta_data : list List of dictionaries holding data from delta data files. Returns ------- avg_delta_values : dictionary Dictionary keys corresponding to delta variable type (i.e. precipitation (Ppt)) holding averaged data values for a specific list of tiles. Notes ----- avg_delta_values = { "Ppt": { "January": 2.0, "February": 0.98, "March": 0.97, "April": 1.04, "May": 1.10, "June": 0.99, "July": 0.87, "August": 0.75, "September": 0.95, "October": 0.98, "November": 1.10, "December": 2.0 } } """ # check that each tile in tile list is contained in the deltas_data for tile in tile_list: if tile not in deltas_data["Tile"]: raise ValueError, "Tile {} is not contined in deltas_data".format( tile) # initialize avg_delta_values with keys corresponding to variable type avg_delta_values = {} variable_type = deltas_data["Variable"] avg_delta_values[variable_type] = helpers.create_monthly_dict() # get delta values that correspond to a list of tiles values = get_monthly_values(deltas_data, tile_list=tile_list) # format the values into a dictionary containing monthly keys values_dict = format_to_monthly_dict(values) # compute average of delta values for each month and put it in avg_delta_values for key, value in values_dict.iteritems(): avg_value = np.average(value) avg_delta_values[variable_type][key] = avg_value return avg_delta_values
def calculate_avg_delta_values(deltas_data, tile_list): """ Get monthly averaged delta data values for a specific list of tiles. Parameters ---------- delta_data : list List of dictionaries holding data from delta data files. Returns ------- avg_delta_values : dictionary Dictionary keys corresponding to delta variable type (i.e. precipitation (Ppt)) holding averaged data values for a specific list of tiles. Notes ----- avg_delta_values = { "Ppt": { "January": 2.0, "February": 0.98, "March": 0.97, "April": 1.04, "May": 1.10, "June": 0.99, "July": 0.87, "August": 0.75, "September": 0.95, "October": 0.98, "November": 1.10, "December": 2.0 } } """ # check that each tile in tile list is contained in the deltas_data for tile in tile_list: if tile not in deltas_data["Tile"]: raise ValueError, "Tile {} is not contined in deltas_data".format(tile) # initialize avg_delta_values with keys corresponding to variable type avg_delta_values = {} variable_type = deltas_data["Variable"] avg_delta_values[variable_type] = helpers.create_monthly_dict() # get delta values that correspond to a list of tiles values = get_monthly_values(deltas_data, tile_list = tile_list) # format the values into a dictionary containing monthly keys values_dict = format_to_monthly_dict(values) # compute average of delta values for each month and put it in avg_delta_values for key, value in values_dict.iteritems(): avg_value = np.average(value) avg_delta_values[variable_type][key] = avg_value return avg_delta_values