Exemplo n.º 1
0
    plot_arr = plot_arr[np.where(plot_arr[:, 2] > z_thresh)]

    print(plot_arr.shape)

    x_range = range(0, 101)
    x_dict = dict()

    for x_val in x_range:
        x_dict[x_val] = list()

        list_vals = plot_arr[np.where((plot_arr[:, 0]*100.0).astype(np.int16) == x_val)].tolist()

        if len(list_vals) > bin_limit:
            temp_list = list(range(len(list_vals)))
            list_locs = Sublist(temp_list).random_selection(bin_limit)
        else:
            list_locs = list(range(len(list_vals)))

        x_dict[x_val] += list(list_vals[ii] for ii in list_locs)

    x_counts = dict()
    plot_dicts_ = list()
    for k, v in x_dict.items():
        x_counts[k] = len(v)
        plot_dicts_ += list({xvar: elem[0], yvar: elem[1], zvar: elem[2]} for elem in v)

    print(x_counts)
    print(len(plot_dicts_))

    freq_list, bin_edges = np.histogram(list(float(pt[xvar]) for pt in plot_dicts_), bins=eq_bins, range=(0, 1))
Exemplo n.º 2
0
def quantile_regress(x,
                     y,
                     q=None,
                     degree=1,
                     xlim=None,
                     ylim=None,
                     print_summary=False):
    if q is None:
        q = [0.1, 0.5, 0.9]
    elif type(q).__name__ in ('int', 'float', 'str'):
        try:
            q = [float(q)]
        except Exception as e:
            print(e)
    elif type(q).__name__ in ('list', 'tuple'):
        q = Sublist(q)
    else:
        raise ValueError("Data type not understood: q")

    if type(x).__name__ in ('list', 'tuple', 'NoneType'):
        x_ = np.array(x)
    else:
        x_ = x.copy()

    if type(y).__name__ in ('list', 'tuple', 'NoneType'):
        y_ = np.array(y)
    else:
        y_ = y.copy()

    if xlim is not None:
        y_ = y_[np.where((x_ >= xlim[0]) & (x_ <= xlim[1]))]
        x_ = x_[np.where((x_ >= xlim[0]) & (x_ <= xlim[1]))]

    if ylim is not None:
        x_ = x_[np.where((y_ >= ylim[0]) & (y_ <= ylim[1]))]
        y_ = y_[np.where((y_ >= ylim[0]) & (y_ <= ylim[1]))]

    '''
    y_ = y_[:, np.newaxis]
    const_ = (x_ * 0.0) + 1.0
    x_ = np.hstack([x_[:, np.newaxis], const_[:, np.newaxis]])
    '''

    df = pd.DataFrame({'y': y_, 'x': x_})

    if degree == 0:
        raise RuntimeError('Degree of polynomial should be > 0')

    rel_str = 'y ~ '
    for ii in range(degree):
        if ii == 0:
            rel_str += 'x'
        else:
            rel_str += ' + I(x ** {})'.format(str(float(ii + 1)))

    mod = smf.quantreg(rel_str, df)
    mod.initialize()

    q_res = list()
    for q_ in q:
        res_ = mod.fit(q=q_)

        if print_summary:
            print(res_.summary())
            print('\n')

        q_res.append({
            'q': q_,
            'rsq': res_.rsquared,
            'adj_rsq': res_.rsquared_adj,
            'coeffs': list(reversed(list(res_.params))),
            'pvals': res_.pvalues.tolist(),
            'stderrs': res_.bse.tolist()
        })

    return q_res
Exemplo n.º 3
0
    plot_arr = plot_arr[np.where(plot_arr[:, 2] > z_thresh)]

    print(plot_arr.shape)

    x_range = range(0, 101)
    x_dict = dict()

    for x_val in x_range:
        x_dict[x_val] = list()

        list_vals = plot_arr[np.where(plot_arr[:, 0] == float(x_val) /
                                      100.0)].tolist()

        if len(list_vals) > bin_limit:
            temp_list = list(range(len(list_vals)))
            list_locs = Sublist(temp_list).random_selection(bin_limit)
        else:
            list_locs = list(range(len(list_vals)))

        x_dict[x_val] += list(list_vals[ii] for ii in list_locs)

    x_counts = dict()
    plot_dicts_ = list()
    for k, v in x_dict.items():
        x_counts[k] = len(v)
        plot_dicts_ += list({xvar: elem[0], yvar: elem[1]} for elem in v)

    print(x_counts)
    print(len(plot_dicts_))

    freq_list, bin_edges = np.histogram(list(
Exemplo n.º 4
0
    fire_types = ['single', 'multiple']

    xvar = 'tree_cover'
    yvar = 'time_since_fire'
    zvar = 'decid_frac'

    # ylim = (0, 80)  # time since fire
    ylim = (1950, 2018)
    xlim = (0, 1)  # tree cover
    zlim = (0, 1)  # deciduous fraction

    zcount_lim = 100000

    x_ = np.array(list(range(0, 101))) / 100.0
    # y_ = np.array(Sublist.frange(0, 70, 1))
    y_ = np.array(Sublist.frange(1950, 2018, 1))
    lenx = x_.shape[0]
    leny = y_.shape[0]

    print(x_)
    print(y_)

    years = [1992, 2000, 2005, 2010, 2015]

    version = 11

    filelist = list(in_dir + 'year_{}_{}_{}_fire.csv'.format(
        str(year_edge[0])[2:],
        str(year_edge[1])[2:], fire_type) for year_edge in year_edges
                    for fire_type in fire_types)
Exemplo n.º 5
0
        xvar = '{}_2'.format(bandname)
        xlabel = 'Season 2 {}'.format(bandname.upper())

        yvar = '{}_1'.format(bandname)
        ylabel = 'Season 1 {}'.format(bandname.upper())

        pts = list()

        for i in range(0, len(val_dicts)):
            try:
                pts.append((float(val_dicts[i][xvar]), float(val_dicts[i][yvar])))
            except ValueError:
                pass

        maxx = Sublist.percentile(list(elem[0] for elem in pts), 99.995)
        maxy = Sublist.percentile(list(elem[1] for elem in pts), 99.995)

        max_elem = max(maxx, maxy)

        Opt.cprint('X and Y limits: {:3.3f} {:3.3f}'.format(maxx, maxy))

        plot_heatmap = {
            'type': 'rheatmap2',
            'points': pts,
            'xlabel': xlabel,
            'ylabel': ylabel,
            'color_bar_label': 'Data-points per bin',
            'plotfile': plot_file,
            'xlim': (0, max_elem),
            'ylim': (0, max_elem),
    fire_types = ['single', 'multiple']

    xvar = 'tree_cover'
    yvar = 'time_since_fire'
    zvar = 'decid_frac'

    ylim = (0, 80)  # time since fire
    # ylim = (1950, 2018)
    xlim = (0, 1)  # tree cover
    zlim = (0, 1)  # deciduous fraction

    zcount_lim = 100000

    x_ = np.array(list(range(0, 101))) / 100.0
    # y_ = np.array(Sublist.frange(0, 70, 1))
    y_ = np.array(Sublist.frange(0, 80, 1))
    lenx = x_.shape[0]
    leny = y_.shape[0]

    print(x_)
    print(y_)

    years = [1992, 2000, 2005, 2010, 2015]

    version = 12

    filelist = list(in_dir + 'year_{}_{}_{}_fire.csv'.format(
        str(year_edge[0])[2:],
        str(year_edge[1])[2:], fire_type) for year_edge in year_edges
                    for fire_type in fire_types)
Exemplo n.º 7
0
        for x_val in x_range:
            x_dict[x_val] = list()

            list_vals = list()
            for dict_ in val_dicts:
                if dict_[xvar] == x_val and dict_[yvar] > 0 and dict_[
                        xvar_] >= cutoff:
                    temp = {
                        xvar: float(dict_[xvar]) / 100.0,
                        yvar: float(dict_[yvar]) / 1000.0,
                        xvar_: float(dict_[xvar_] / 100.0)
                    }
                    list_vals.append(temp)

            if len(list_vals) > bin_limit:
                list_vals = Sublist(list_vals).random_selection(bin_limit)

            x_dict[x_val] += list_vals

        x_counts = dict()
        plot_dicts_ = list()
        for k, v in x_dict.items():
            x_counts[k] = len(v)
            plot_dicts_ += v

        print(x_counts)
        print(len(plot_dicts_))

        freq_list, bin_edges = np.histogram(list(
            float(pt[xvar]) for pt in plot_dicts_),
                                            bins=25,