Exemplo n.º 1
0
def get_monthly_normals(data_folder_path, start_date = None, end_date = None):

    """
    returns numpy array of the monthly normals of the shape (12, nx, ny)
    """
    result = [0.0 for i in xrange(12)]
    record_counts = [0.0 for i in xrange(12)]
    for file_name in os.listdir(data_folder_path):
        date_month = ccc_util.get_month_date_from_name(file_name)

        #focus only on the interval of interest
        if start_date is not None:
            if date_month < start_date:
                continue

        if end_date is not None:
            if date_month > end_date:
                continue


        data = champ_ccc(os.path.join(data_folder_path, file_name)).charge_champs()
        m = date_month.month - 1
        for record in data:
            field = record["field"]
            result[m] += field
            record_counts[m] += 1.0

    result = np.array(result)
    record_counts = [ count * np.ones(result.shape[1:]) for count in record_counts ]
    record_counts = np.array(record_counts)
    result /= np.array(record_counts)
    return result


    pass
Exemplo n.º 2
0
def get_seasonal_mean(data_folder_path, start_date = None, end_date = None, months = None):
    """
    returns seasonal mean
    """
    result = 0.0
    record_count = 0.0
    for file_name in os.listdir(data_folder_path):
        date_month = ccc_util.get_month_date_from_name(file_name)


        #take only months of interest
        if date_month.month not in months:
            continue

        #focus only on the interval of interest
        if start_date is not None:
            if date_month < start_date:
                continue

        if end_date is not None:
            if date_month > end_date:
                continue


        data = champ_ccc(os.path.join(data_folder_path, file_name)).charge_champs()
        for record in data:
            field = record["field"]
            result += field
            record_count += 1.0

    return result / record_count