예제 #1
0
def labelcolors(labels):
    n=len(np.unique(labels))
    c=cm.turbo(np.linspace(0, 1, n))
    colors=[]
    colorsShort=[ RGBtoHex(c[i]) for i in range(n)]
    
    for i in range(len(labels)):
        cloc=np.where(np.unique(labels)==labels.iloc[i])[0][0]
        cval=RGBtoHex(c[cloc])
        colors.append(cval)
        


    colors=np.array(colors)
    return colors, colorsShort
예제 #2
0
def main(group_number, epoch, ddddd):
    groups = [[int(g.split(",")[0]),
               int(g.split(",")[1])]
              for g in get_configs("grouops", epoch).split(";")]
    output = []

    matplotlib.use('TkAgg')
    configuration_items = get_configs_items()
    for key, value in configuration_items.items():
        rcParams[key] = value

    minor_locatorx = MultipleLocator(20)
    minor_locatory = MultipleLocator(20)
    minor_locator_level = MultipleLocator(1)

    input_file = "groups/" + epoch + ".groups"
    date = {
        date.split("-")[0].strip(): date.split("-")[1].strip()
        for date in get_configs("parameters", "dates").split(",")
    }[epoch]

    if check_if_group_is_in_file(input_file, group_number):
        group_tmp, velocity_tmp, intensity_tmp, ra_tmp, dec_tmp = \
            np.loadtxt(input_file, unpack=True, usecols=(0, 2, 3, 5, 6))

        dtype = [('group_nr', int), ('velocity', float), ('intensity', float),
                 ("ra", float), ("dec", float)]
        values = [(group_tmp[ch], velocity_tmp[ch], intensity_tmp[ch],
                   ra_tmp[ch], dec_tmp[ch]) for ch in range(0, len(group_tmp))]
        data = np.array(values, dtype=dtype)
        data = np.sort(data, order=['group_nr', 'velocity'])
        data = data[data["group_nr"] == group_number]

        max_intensity = max(data["intensity"])
        reference_index = np.where(data["intensity"] == max_intensity)[0][0]
        references_ra = data["ra"][reference_index]
        references_dec = data["dec"][reference_index]
        references_velocity = data["velocity"][reference_index]
        #print("references ra", references_ra, "references dec", references_dec,
        #"references velocity", references_velocity)

        velocity = data["velocity"]
        vel_max = max(velocity)
        vel_min = min(velocity)
        intensity = data["intensity"]
        ra = data["ra"]
        dec = data["dec"]
        ra -= references_ra
        dec -= references_dec

        fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(16, 16), dpi=90)
        fig2, ax2 = plt.subplots(nrows=1, ncols=1, figsize=(16, 16), dpi=90)
        coord_range = max(max(ra) - min(ra), max(dec) - min(dec))

        color = []
        for v in range(0, len(velocity)):
            if velocity[v] < min(velocity) or velocity[v] > max(velocity):
                c = (0, 0, 0)
            else:
                c = cm.turbo((velocity[v] - min(velocity)) /
                             (max(velocity) - min(velocity)), 1)

            color.append(c)

            el = Circle((ra[v], dec[v]),
                        radius=0.05 * np.log(intensity[v] * 1000),
                        angle=0,
                        lw=2)
            el.set_facecolor(c)
            ax[1].add_artist(el)

        ax[0].scatter(velocity, intensity, color=color, lw=2)

        slope, intercept, r_value, p_value, std_err = stats.linregress(ra, dec)
        line = slope * ra + intercept
        ax[1].plot(ra, line, 'm', linewidth=10)

        position_angle2 = 90 + np.degrees(np.arctan(slope))
        #print("position angle from linear fit is ", position_angle2)
        #print("Distance between fit and points", line-dec)
        #print("Pearsonr correlation", pearsonr(ra, line))

        max_separation = {"r": 0, "d": -1, "separation": 0}
        sky_coords = [
            SkyCoord(ra[coord], dec[coord], unit=u.arcsec)
            for coord in range(0, len(ra))
        ]
        for r in range(0, len(ra)):
            for d in range(0, len(dec)):
                if r != d:
                    separation = sky_coords[r].separation(sky_coords[d])
                    if separation > max_separation["separation"]:
                        max_separation["r"] = r
                        max_separation["d"] = d
                        max_separation["separation"] = separation

        m, b = np.polyfit([ra[max_separation["r"]], ra[max_separation["d"]]],
                          [dec[max_separation["r"]], dec[max_separation["d"]]],
                          1)
        if ddddd:
            ax[1].plot([ra[max_separation["r"]], ra[max_separation["d"]]], [
                m * ra[max_separation["r"]] + b,
                m * ra[max_separation["d"]] + b
            ],
                       "k--",
                       linewidth=10)

        position_angle = 90 + np.degrees(np.arctan(m))
        #print("position angle is ", position_angle)

        if len(velocity) >= 3:
            firs_exceeds_tmp = firs_exceeds(np.diff(velocity), 0.5)
            split_index = firs_exceeds_tmp + 1
            if firs_exceeds_tmp != -1:
                a = intensity[0:split_index]
                b = intensity[split_index:len(intensity)]
                c = velocity[0:split_index]
                d = velocity[split_index:len(velocity)]
                e = ra[0:split_index]
                f = ra[split_index:len(velocity)]
                g = dec[0:split_index]
                h = dec[split_index:len(velocity)]

                velocity_tmp = [c, d]
                intensity_tmp = [a, b]
                ra_tmp = [e, f]
                dec_tmp = [g, h]

            else:
                velocity_tmp = [velocity]
                intensity_tmp = [intensity]
                ra_tmp = [ra]
                dec_tmp = [dec]

            for gauss_nr in range(0, len(velocity_tmp)):
                size = []
                max_intensity_index = np.array(
                    intensity_tmp[gauss_nr]).argmax()
                for j in range(0, len(velocity_tmp[gauss_nr])):
                    for k in range(j + 1, len(velocity_tmp[gauss_nr])):
                        dist = np.sqrt((ra[j] - ra[k])**2 +
                                       (dec[j] - dec[k])**2)
                        size.append(dist)

                if len(velocity_tmp[gauss_nr]) >= 3:

                    amplitude = max(intensity_tmp[gauss_nr])
                    centre_of_peak_index = list(
                        intensity_tmp[gauss_nr]).index(amplitude)
                    centre_of_peak = velocity_tmp[gauss_nr][
                        centre_of_peak_index]
                    second_largest_amplitude_index = (
                        -intensity_tmp[gauss_nr]).argsort()[1]
                    second_largest_amplitude = intensity_tmp[gauss_nr][
                        second_largest_amplitude_index]
                    second_largest_centre_of_peak = velocity_tmp[gauss_nr][
                        second_largest_amplitude_index]
                    standard_deviation = np.std(intensity_tmp[gauss_nr])
                    ps = [[amplitude, centre_of_peak, standard_deviation],
                          [
                              amplitude, centre_of_peak, standard_deviation,
                              second_largest_amplitude,
                              second_largest_centre_of_peak, standard_deviation
                          ], [0.9, -6.45, 0.2],
                          [0.9, -6.45, 0.2, 0.32, -5.43, 0.1],
                          [0.361, -6.98, 0.2, 0.149, -6.489, 0.2],
                          [2.2, -6.9, 0.2, 23.6, -6.22, 0.2],
                          [1.99, -6.977, 0.05, 0.6, -7.3, 0.05],
                          [0.035, -7.75, 0.001]]

                    q = np.linspace(min(velocity_tmp[gauss_nr]),
                                    max(velocity_tmp[gauss_nr]), 10000)
                    perrs = []
                    coeffs = []
                    for p in ps:
                        #if epoch == "ea063":
                        #p = [0.035, -7.75, 0.001]
                        try:
                            if len(p) == 3:
                                coeff, var_matrix = curve_fit(
                                    gauss,
                                    velocity_tmp[gauss_nr],
                                    intensity_tmp[gauss_nr],
                                    p0=p,
                                    method="lm")
                            else:
                                coeff, var_matrix = curve_fit(
                                    gauss2,
                                    velocity_tmp[gauss_nr],
                                    intensity_tmp[gauss_nr],
                                    p0=p,
                                    method="lm")

                            perr = np.sqrt(np.diag(var_matrix))
                            perr = perr[~np.isnan(perr)]
                            perrs.append(np.mean(perr) / len(perr))
                            coeffs.append(coeff)
                        except:
                            pass

                    if len(perrs) > 0:
                        coeff_index = perrs.index(min(perrs))
                        coeff = coeffs[coeff_index]

                        if len(coeff) == 6:
                            hist_fit = gauss2(q, *coeff)
                            ax[0].plot(q, hist_fit, 'k--', linewidth=10)

                            print(
                                "{\\it %d} & %.3f & %.3f & %.1f & %.2f & %.2f & %.3f & %.3f & %.2f & %.2f & %.3f & "
                                "%.1f(%.1f) & %.3f( "
                                "%.3f)\\\\" %
                                (gauss_nr,
                                 ra_tmp[gauss_nr][max_intensity_index] +
                                 references_ra,
                                 dec_tmp[gauss_nr][max_intensity_index] +
                                 references_dec, velocity[max_intensity_index],
                                 coeff[1], coeff[2] * 2,
                                 intensity[max_intensity_index], coeff[0],
                                 coeff[4], coeff[5] * 2, coeff[3], max(size),
                                 max(size) * 1.64,
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 max(size),
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 (max(size) * 1.64)))

                            output.append([
                                -1, ra_tmp[gauss_nr][max_intensity_index],
                                dec_tmp[gauss_nr][max_intensity_index],
                                velocity[max_intensity_index], coeff[1],
                                coeff[2] * 2, intensity[max_intensity_index],
                                coeff[0], coeff[4], coeff[5] * 2, coeff[3],
                                max(size),
                                max(size) * 1.64,
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                max(size),
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                (max(size) * 1.64), position_angle,
                                position_angle2
                            ])

                        elif len(coeff) == 3:
                            hist_fit = gauss(q, *coeff)
                            ax[0].plot(q, hist_fit, 'k--', linewidth=10)

                            print(
                                "{\\it %d} & %.3f & %.3f & %.1f & %.2f & %.2f & %.3f & %.3f & %.1f(%.1f) & %.3f("
                                "%.3f)\\\\" %
                                (gauss_nr,
                                 ra_tmp[gauss_nr][max_intensity_index] +
                                 references_ra,
                                 dec_tmp[gauss_nr][max_intensity_index] +
                                 references_dec, velocity[max_intensity_index],
                                 coeff[1], coeff[2] * 2,
                                 intensity[max_intensity_index], coeff[0],
                                 max(size), max(size) * 1.64,
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 max(size),
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 (max(size) * 1.64)))

                            output.append([
                                -1, ra_tmp[gauss_nr][max_intensity_index] +
                                references_ra,
                                dec_tmp[gauss_nr][max_intensity_index] +
                                references_dec, velocity[max_intensity_index],
                                coeff[1], coeff[2] * 2,
                                intensity[max_intensity_index], coeff[0], "-",
                                "-", "-",
                                max(size),
                                max(size) * 1.64,
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                max(size),
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                (max(size) * 1.64), position_angle,
                                position_angle2
                            ])
                else:
                    if len(size) > 0:
                        print(
                            "{\\it %d} & %.3f & %.3f & %.1f & %s & %s & %.3f & %s & %.1f(%.1f) & %.3f(%.3f)\\\\"
                            %
                            (gauss_nr, ra_tmp[gauss_nr][max_intensity_index] +
                             references_ra,
                             dec_tmp[gauss_nr][max_intensity_index] +
                             references_dec, velocity[max_intensity_index],
                             "-", "-", intensity[max_intensity_index], "-",
                             max(size), max(size) * 1.64,
                             (velocity[0] - velocity[len(velocity) - 1]) /
                             max(size),
                             (velocity[0] - velocity[len(velocity) - 1]) /
                             (max(size) * 1.64)))

                        output.append([
                            -1, ra_tmp[gauss_nr][max_intensity_index],
                            dec_tmp[gauss_nr][max_intensity_index],
                            velocity[max_intensity_index], "-", "-",
                            intensity[max_intensity_index], "-", "-", "-", "-",
                            max(size),
                            max(size) * 1.64,
                            (velocity[0] - velocity[len(velocity) - 1]) /
                            max(size),
                            (velocity[0] - velocity[len(velocity) - 1]) /
                            (max(size) * 1.64), position_angle, position_angle2
                        ])

                    else:
                        print(
                            "{\\it %d} & %.3f & %.3f & %.1f & %s & %s & %.3f & %s & %s & %s\\\\"
                            %
                            (gauss_nr, ra_tmp[gauss_nr][max_intensity_index] +
                             references_ra,
                             dec_tmp[gauss_nr][max_intensity_index] +
                             references_dec, velocity[max_intensity_index],
                             "-", "-", intensity[max_intensity_index], "-",
                             "-", "-"))

                        output.append([
                            -1, ra_tmp[gauss_nr][max_intensity_index],
                            dec_tmp[gauss_nr][max_intensity_index],
                            velocity[max_intensity_index], "-", "-",
                            intensity[max_intensity_index], "-", "-", "-", "-",
                            "-", "-", "-", position_angle, position_angle2
                        ])

        ps = [[0.79, -6.7006000000000006, 0.43855130828672717],
              [8.292, -6.086, 2.8962589178124705]]

        hist_fits = list()
        hist_fits2 = list()
        hist_fits3 = list()
        q2 = np.linspace(min(velocity), max(velocity), 10000)
        colors = ["r", "b", "y", "g"]
        for g in groups:
            index1 = g[0]
            index2 = g[1]

            x = velocity[index1:index2]
            y = intensity[index1:index2]
            q = np.linspace(min(x), max(x), 10000)
            if len(x) >= 3:
                color = colors[groups.index(g)]
                p = ps[groups.index(g)]
                '''
                if groups.index(g) == 0:
                    coeff, var_matrix = curve_fit(gauss2, x, y, p0=p, method="lm", maxfev=100000)
                    hist_fit = gauss2(q, *coeff)
                else:
                    coeff, var_matrix = curve_fit(gauss, x, y, p0=p, method="lm", maxfev=100000)
                    hist_fit = gauss(q, *coeff)
                '''

                coeff, var_matrix = curve_fit(gauss,
                                              x,
                                              y,
                                              p0=p,
                                              method="lm",
                                              maxfev=100000)
                hist_fit = gauss(q, *coeff)
                hist_fit2 = gauss(velocity, *coeff)
                hist_fits.append(hist_fit)
                hist_fits2.append(hist_fit2)
                hist_fit3 = gauss(q2, *coeff)
                hist_fits3.append(hist_fit3)
                ax[0].plot(q, hist_fit, '--', c=color, linewidth=10)

                ra_tmp = ra[index1:index2]
                dec_tmp = dec[index1:index2]
                slope, intercept, r_value, p_value, std_err = stats.linregress(
                    ra_tmp, dec_tmp)
                line = slope * ra_tmp + intercept
                ax[1].plot(ra_tmp, line, c=color, linewidth=10)

                max_separation = {"r": 0, "d": -1, "separation": 0}
                sky_coords = [
                    SkyCoord(ra_tmp[coord], dec_tmp[coord], unit=u.arcsec)
                    for coord in range(0, len(ra_tmp))
                ]
                size = []
                max_intensity_index = np.array(y).argmax()
                for j in range(0, len(x)):
                    for k in range(j + 1, len(x)):
                        dist = np.sqrt((ra_tmp[j] - ra_tmp[k])**2 +
                                       (dec_tmp[j] - dec_tmp[k])**2)
                        size.append(dist)

                for r in range(0, len(ra_tmp)):
                    for d in range(0, len(dec_tmp)):
                        if r != d:
                            separation = sky_coords[r].separation(
                                sky_coords[d])
                            if separation > max_separation["separation"]:
                                max_separation["r"] = r
                                max_separation["d"] = d
                                max_separation["separation"] = separation

                m, b = np.polyfit(
                    [ra_tmp[max_separation["r"]], ra_tmp[max_separation["d"]]],
                    [
                        dec_tmp[max_separation["r"]],
                        dec_tmp[max_separation["d"]]
                    ], 1)
                position_angle = 90 + np.degrees(np.arctan(m))
                position_angle2 = 90 + np.degrees(np.arctan(slope))
                sub_group_nr = groups.index(g)

                output.append([
                    sub_group_nr, ra_tmp[max_intensity_index],
                    dec_tmp[max_intensity_index], x[max_intensity_index],
                    coeff[1], coeff[2] * 2, y[max_intensity_index], coeff[0],
                    "-", "-", "-",
                    max(size),
                    max(size) * 1.64, (x[0] - x[len(x) - 1]) / max(size),
                    (x[0] - x[len(x) - 1]) / (max(size) * 1.64),
                    position_angle, position_angle2
                ])

                #print("position angle is ", position_angle)
                #print("position angle from linear fit is ", position_angle2)
                #print("Distance between fit and points", line - dec_tmp)
                #print("Pearsonr correlation", pearsonr(ra_tmp, line))

        q2 = np.linspace(min(velocity), max(velocity), 10000)
        ax[0].plot(q2, sum(hist_fits3), c="k", linewidth=10)
        ax2.plot(velocity, intensity - sum(hist_fits2), "k-")
        ax2.plot(velocity, intensity - sum(hist_fits2), "k.", markersize=20)
        ax[0].set_xlim(vel_min - 0.1, vel_max + 0.1)
        ax[0].set_ylim((min(intensity)) - 0.5, (max(intensity) + 0.5))
        ax[0].xaxis.set_minor_locator(minor_locator_level)
        ax[0].set_title(date)
        ax[1].set_aspect("equal", adjustable='box')
        ax[1].set_xlim(
            np.mean((max(ra), min(ra))) - (coord_range / 2) - 0.5,
            np.mean((max(ra), min(ra))) + (coord_range / 2) + 0.5)
        ax[1].set_ylim(
            np.mean((max(dec), min(dec))) - (coord_range / 2) - 0.5,
            np.mean((max(dec), min(dec))) + (coord_range / 2) + 0.5)
        ax[1].invert_xaxis()
        ax[0].set_ylabel('Flux density (Jy)')
        ax[1].set_ylabel('$\\Delta$ Dec (mas)')
        ax[0].set_xlabel('$V_{\\rm LSR}$ (km s$^{-1}$)')
        ax[1].set_xlabel('$\\Delta$ RA (mas)')
        ax[1].xaxis.set_minor_locator(minor_locatorx)
        ax[1].yaxis.set_minor_locator(minor_locatory)
        ax2.set_title("Residuals for spectre")
        plt.tight_layout()
        plt.subplots_adjust(top=0.947,
                            bottom=0.085,
                            left=0.044,
                            right=0.987,
                            hspace=0.229,
                            wspace=0.182)
        plt.show()

        header2 = [
            "sub_group_nr", "ra", "dec", "velocity", "vel_fit", "sigma",
            "max_intensity", "fit_amp", "vel_fit2", "sigma2", "fit_amp2",
            "max_distance", "max_distance_au", "gradient", "gradient_au",
            "position_angle", "position_angle2"
        ]
        np.savetxt("cloudlet_sub_" + "_" + epoch + "_" + str(group_number) +
                   "._sats.csv",
                   np.array(output, dtype=object),
                   delimiter=", ",
                   fmt='%s',
                   header=",".join(header2))
    else:
        print("group is not in epoch")
        sys.exit()
예제 #3
0
def main(group_number):
    configuration_items = get_configs_items()
    for key, value in configuration_items.items():
        rcParams[key] = value

    minorLocatorx = MultipleLocator(20)
    minorLocatory = MultipleLocator(20)
    minorLocatorvel = MultipleLocator(1)

    gauss2_list = get_configs("parameters", "gauss").split(";")
    gauss2_dict = dict()

    for epoch in gauss2_list:
        gauss2_dict[epoch.split(":")[0]] = epoch.split(":")[1].split(",")

    file_order = [file.strip() for file in get_configs("parameters", "fileOrder").split(",")]
    input_files = []

    for file in file_order:
        input_files.append(file)

    dates = {file.split("-")[0].strip(): file.split("-")[1].strip() for file in
             get_configs("parameters", "dates").split(",")}

    bad_files = []
    for file in input_files:
        if not check_if_group_is_in_file(file.split(".")[0] + ".groups", group_number):
            bad_files.append(file)
            del dates[file.split(".")[0]]
    input_files = [file for file in input_files if file not in bad_files]

    fig, ax = plt.subplots(nrows=2, ncols=len(input_files), figsize=(16, 16), dpi=90)

    velocitys = []
    intensitys = []
    ras = []
    decs = []
    max_ra = []
    min_ra = []
    min_dec = []
    max_dec = []
    intensitys_max = []
    intensitys_min = []
    v_maxs = []
    v_mins = []
    for index in range(0, len(input_files)):
        input_file = "groups/" + "/" + input_files[index].split(".")[0] + ".groups"
        velocity = np.empty(0)
        intensity = np.empty(0)
        ra = np.empty(0)
        dec = np.empty(0)
        group_tmp, channel_tmp, velocity_tmp, intensity_tmp, integral_intensity_tmp, ra_tmp, dec_tmp = np.loadtxt(
            input_file, unpack=True)
        for i in range(0, len(channel_tmp)):
            if group_tmp[i] == int(group_number):
                velocity = np.append(velocity, velocity_tmp[i])
                intensity = np.append(intensity, intensity_tmp[i])
                ra = np.append(ra, ra_tmp[i])
                dec = np.append(dec, dec_tmp[i])

        v_maxs.append(max(velocity))
        v_mins.append(min(velocity))

        if len(intensity) == 0:
            intensity = [0]

        if len(velocity) == 0:
            velocity = [0]

        velocitys.append(velocity)
        intensitys.append(intensity)
        ras.append(ra)
        decs.append(dec)

        if len(ra) != 0:
            intensitys_max.append(max(intensity))
            intensitys_min.append(min(intensity))
            max_ra.append(np.max(ra))
            min_ra.append(np.min(ra))
            min_dec.append(np.min(dec))
            max_dec.append(np.max(dec))

    coord_range = max(max(max_ra) - min(min_ra), max(max_dec) - min(min_dec))
    for index in range(0, len(input_files)):
        v_max = v_maxs[index]
        v_min = v_mins[index]
        velocity = velocitys[index]
        intensity = intensitys[index]
        dec = decs[index]
        ra = ras[index]
        title = input_files[index].split(".")[0].upper() + "-" + dates[input_files[index].split(".")[0]]
        if len(velocity) >= 3:
            p1 = [max(intensity), min(velocity) + 0.5 * (max(velocity) - min(velocity)), 0.2]
            p2 = [max(intensity), min(velocity) + 0.5 * (max(velocity) - min(velocity)), 0.3,
                  max(intensity) / 4, min(velocity) + 0.5 * (max(velocity) - min(velocity)), 0.1]
            q = np.linspace(min(velocity), max(velocity), 1000)

            gauss2_groups_for_epoch = gauss2_dict[input_files[index].split(".")[0].upper()]
            if str(group_number) in gauss2_groups_for_epoch:
                try:
                    coeff, var_matrix = curve_fit(gauss2, velocity, intensity, p0=p2, maxfev=100000)
                    hist_fit = gauss2(q, *coeff)
                    ax[0][index].plot(q, hist_fit, 'k')
                except:
                    pass

            else:
                try:
                    coeff, var_matrix = curve_fit(gauss, velocity, intensity, p0=p1, maxfev=100000)
                    hist_fit = gauss(q, *coeff)
                    ax[0][index].plot(q, hist_fit, 'k')
                except:
                    pass

        rel = []
        for i in range(len(velocity) - 1):
            if velocity[i] < v_min or velocity[i] > v_max:
                c = (0, 0, 0)
            else:
                c = cm.turbo((velocity[i] - v_min) / (v_max - v_min), 1)

            ax[0][index].scatter((velocity[i], velocity[i + 1]), (intensity[i], intensity[i + 1]), color=c, lw=2)
            ax[0][index].set_xlim(min(velocity) - 0.5, max(velocity) + 0.5)
            ax[0][index].xaxis.set_minor_locator(minorLocatorvel)
            ax[0][index].set_title(title)
            ax[0][index].set_xlabel('$V_{\\rm LSR}$ (km s$^{-1}$)')

            el = Circle((ra[i], dec[i]), radius=0.1 * np.sqrt(intensity[i]), angle=0, lw=2)
            ax[1][index].add_artist(el)
            el.set_facecolor(c)
            rel.append([ra[i], dec[i], velocity[i]])

        ax[0][index].set_ylim((min(intensitys_min)) - 0.1, (max(intensitys_max) + 0.1))
        ax[1][index].set_aspect("equal", adjustable='box')
        ax[1][index].set_xlim(np.mean((max(max_ra), min(min_ra))) - (coord_range / 2) - 0.5,
                              (np.mean((max(max_ra), min(min_ra))) - (coord_range / 2) - 0.5) + 12)
        ax[1][index].set_ylim(np.mean((max(max_dec), min(min_dec))) - (coord_range / 2) - 0.5,
                              np.mean((max(max_dec), min(min_dec))) + (coord_range / 2) + 0.5 + 12)
        ax[1][index].set_xlabel('$\\Delta$ RA (mas)')
        ax[1][index].xaxis.set_minor_locator(minorLocatorx)
        ax[1][index].yaxis.set_minor_locator(minorLocatory)
        ax[1][index].invert_xaxis()

    ax[0][0].set_ylabel('Flux density (Jy)')
    ax[1][0].set_ylabel('$\\Delta$ Dec (mas)')
    plt.tight_layout()
    plt.subplots_adjust(top=0.97, bottom=0, wspace=0.18, hspace=0, left=0.05, right=0.99)
    plt.show()
예제 #4
0
    71: 16,  # "trunk"
    72: 17,  # "terrain"
    80: 18,  # "pole"
    81: 19,  # "traffic-sign"
    99: 0,  # "other-object" to "unlabeled" ----------------------------mapped
    252: 1,  # "moving-car" to "car" ------------------------------------mapped
    253: 7,  # "moving-bicyclist" to "bicyclist" ------------------------mapped
    254: 6,  # "moving-person" to "person" ------------------------------mapped
    255: 8,  # "moving-motorcyclist" to "motorcyclist" ------------------mapped
    256: 5,  # "moving-on-rails" mapped to "other-vehicle" --------------mapped
    257: 5,  # "moving-bus" mapped to "other-vehicle" -------------------mapped
    258: 4,  # "moving-truck" to "truck" --------------------------------mapped
    259: 5,  # "moving-other"-vehicle to "other-vehicle" ----------------mapped
}
_n_classes = max(labelmap.values()) + 1
_colors = cm.turbo(np.asarray(range(_n_classes)) /
                   (_n_classes - 1))[:, :3] * 255
palette = list(np.uint8(_colors).flatten())


@numba.jit
def scatter(arrary, index, value):
    for (h, w), v in zip(index, value):
        arrary[h, w] = v
    return arrary


def projection(source, grid, order, H, W):
    assert source.ndim == 2, source.ndim
    C = source.shape[1]
    proj = np.zeros((H, W, C))
    proj = np.asarray(proj, dtype=source.dtype)
def run(seed, l_, g_, k_in, k_out):
    graph = nx.planted_partition_graph(l_,
                                       g_,
                                       k_in / g_,
                                       k_out / g_,
                                       seed=seed)
    largest_cc = max(nx.connected_components(graph), key=len)
    graph = graph.subgraph(largest_cc)
    graph = nx.convert_node_labels_to_integers(graph)

    laplacian = cv._construct_laplacian(graph, use_spectral_gap=False)
    w, v = sp.linalg.eigs(laplacian, k=100, which='SM')
    #w, v = np.linalg.eig(laplacian.toarray()) #, k=50, which='SM')

    C_1 = [node for node in graph.nodes if graph.nodes[node]["block"] == 0]
    C_2 = [node for node in graph.nodes if graph.nodes[node]["block"] == 1]
    edges = np.array(graph.edges)
    _e = edges[np.isin(edges[:, 0], C_1)]
    out_edges = _e[np.isin(_e[:, 1], C_2)]

    gc = np.array([graph.nodes[node]["block"] for node in graph.nodes])
    gc[gc == 0] = -1
    diffs = []
    corr_int = []
    corr = []
    for s in range(len(w)):
        diffs.append(
            abs(np.sum([v[edge[0], s] - v[edge[1], s] for edge in out_edges])))
        v_c_int = np.array(v[:, s])
        v_c_int[v_c_int < 0] = -1
        v_c_int[v_c_int > 0] = 1
        corr_int.append(abs(np.dot(gc, v_c_int)) / len(gc))
        corr.append(abs(np.dot(gc, v[:, s]) / len(gc)))

    #w = w[1:]
    #v = v[:, 1:]
    #corr = corr[1:]
    #corr_int = corr_int[1:]
    #diffs = diffs[1:]

    v_c = v[:, np.argmax(diffs)]
    v_c_best = v[:, np.argmax(corr_int)]
    best_diff, best_corr = np.argmax(diffs), np.argmax(corr_int)

    v_c_int = np.array(v_c)
    v_c_int[v_c < 0] = -1
    v_c_int[v_c > 0] = 1
    v_c_int /= g_
    v_c_best_int = np.array(v_c_best)
    v_c_best_int[v_c_best < 0] = -1
    v_c_best_int[v_c_best > 0] = 1
    plot = True
    if plot:
        plt.figure(figsize=(4, 3))
        norm_corr = np.array(corr_int) / np.max(corr_int)
        plt.scatter(w,
                    np.array(diffs) / max(diffs),
                    s=10 + 20 * norm_corr,
                    c=cm.turbo(norm_corr))  #'k')#, marker=".")
        plt.savefig('diff_vs_eig.pdf', bbox_inches='tight')

        plt.figure(figsize=(4, 3))
        plt.plot(w, corr_int, ".", c='k')
        plt.xlabel(r'$|\sum_{ij} (\phi_s(i) - \phi_s(j))\,\delta(C_i,C_j)|$')
        plt.ylabel(r'$corr$')

        plt.figure(figsize=(4, 3))
        plt.scatter(diffs, corr_int, c=cm.turbo(norm_corr))
        # plt.scatter(diffs[best_diff], corr_int[best_diff], label="diff")
        plt.legend()
        plt.savefig('example_plot_1.pdf', bbox_inches='tight')

        plt.figure(figsize=(4, 3))
        plt.plot(-v_c, ".", label="diff", c='k', ms=0.5)
        plt.axis([0, 10000, -.02, .02])
        #plt.plot(v_c_best, ".", label="corr")
        plt.xlabel('node id')
        plt.ylabel(r'$\phi_\mathrm{best}(i)$')
        plt.legend()
        # ax2 = plt.twinx()
        # ax2.set_xlim(0, 10000)
        #ax2.plot(v_c_int, ".", label="diff_int")
        #ax2.plot(0.8 * v_c_best_int, ".", label="corr_int")
        plt.plot(gc / np.sqrt(2 * g_), c="r", lw=0.5)
        plt.savefig('best_eig.pdf', bbox_inches='tight')

        plt.figure(figsize=(4, 3))
        plt.plot(v[:, 1], ".", label="diff", c='k', ms=0.5)
        plt.axis([0, 10000, -.02, .02])
        #plt.plot(v_c_best, ".", label="corr")
        plt.xlabel('node id')
        plt.ylabel(r'$\phi_2(i)$')
        plt.legend()
        # ax2 = plt.twinx()
        # ax2.set_xlim(0, 10000)
        #ax2.plot(v_c_int, ".", label="diff_int")
        #ax2.plot(0.8 * v_c_best_int, ".", label="corr_int")
        plt.plot(gc / np.sqrt(2 * g_), c="r", lw=0.5)
        plt.savefig('second_eig.pdf')
    return corr_int[best_diff], corr_int[best_corr], corr_int[0]
예제 #6
0
def main(group_number, ddddd):
    matplotlib.use('TkAgg')
    configuration_items = get_configs_items()
    for key, value in configuration_items.items():
        rcParams[key] = value

    minor_locatorx = MultipleLocator(20)
    minor_locatory = MultipleLocator(20)
    minor_locator_level = MultipleLocator(1)

    file_order = [
        file.strip()
        for file in get_configs("parameters", "fileOrder").split(",")
    ]
    input_files = []

    for file in file_order:
        input_files.append(file)

    dates = {
        file.split("-")[0].strip(): file.split("-")[1].strip()
        for file in get_configs("parameters", "dates").split(",")
    }

    bad_files = []
    for file in input_files:
        if not check_if_group_is_in_file(
                file.split(".")[0] + ".groups", group_number):
            bad_files.append(file)
            del dates[file.split(".")[0]]
    input_files = [file for file in input_files if file not in bad_files]

    data = dict()
    max_intensity = []
    for index in range(0, len(input_files)):
        epoch = input_files[index].split(".")[0]
        data[epoch] = dict()
        input_file = "groups/" + "/" + input_files[index].split(
            ".")[0] + ".groups"
        intensity = np.empty(0)
        channels = np.empty(0)
        ra = np.empty(0)
        dec = np.empty(0)
        velocity = np.empty(0)
        group_tmp, channel_tmp, velocity_tmp, intensity_tmp, ra_tmp, dec_tmp = \
            np.loadtxt(input_file, unpack=True, usecols=(0, 1, 2, 3, 5, 6))
        for i in range(0, len(channel_tmp)):
            if group_tmp[i] == int(group_number):
                intensity = np.append(intensity, intensity_tmp[i])
                channels = np.append(channels, channel_tmp[i])
                ra = np.append(ra, ra_tmp[i])
                dec = np.append(dec, dec_tmp[i])
                velocity = np.append(velocity, velocity_tmp[i])

        max_intensity.append(max(intensity))
        data[epoch]["index_for_max_intensity"] = np.where(
            intensity == max(intensity))[0][0]
        data[epoch]["intensity"] = intensity
        data[epoch]["channels"] = channels
        data[epoch]["velocity"] = velocity
        data[epoch]["ra"] = ra
        data[epoch]["dec"] = dec

    max_max_intensity = max(max_intensity)
    epoch_index_for_max_intensity = max_intensity.index(max_max_intensity)
    epochs = list(data.keys())
    epoch_with_max_intensity = epochs[epoch_index_for_max_intensity]
    print("epoch with max intensity", epoch_with_max_intensity)
    reference_index = data[epoch_with_max_intensity]["index_for_max_intensity"]
    references_ra = data[epoch_with_max_intensity]["ra"][reference_index]
    references_dec = data[epoch_with_max_intensity]["dec"][reference_index]
    references_velocity = data[epoch_with_max_intensity]["velocity"][
        reference_index]
    print("references ra", references_ra, "references dec", references_dec,
          "references velocity", references_velocity)

    velocity_max = []
    velocity_min = []
    intensity_max = []
    intensity_min = []
    ra_max = []
    ra_min = []
    dec_max = []
    dec_min = []
    for epoch in data:

        if epoch != epoch_with_max_intensity:
            closet_velocity_index_to_references_velocity = \
                (np.abs(data[epoch]["velocity"] - references_velocity)).argmin()
            data[epoch]["ra"] -= data[epoch]["ra"][
                closet_velocity_index_to_references_velocity]
            data[epoch]["dec"] -= data[epoch]["dec"][
                closet_velocity_index_to_references_velocity]

        else:
            data[epoch]["ra"] -= references_ra
            data[epoch]["dec"] -= references_dec

        velocity_max.append(max(data[epoch]["velocity"]))
        velocity_min.append(min(data[epoch]["velocity"]))
        intensity_max.append(max(data[epoch]["intensity"]))
        intensity_min.append(min(data[epoch]["intensity"]))
        ra_max.append(max(data[epoch]["ra"]))
        ra_min.append(min(data[epoch]["ra"]))
        dec_max.append(max(data[epoch]["dec"]))
        dec_min.append(min(data[epoch]["dec"]))

    fig, ax = plt.subplots(nrows=2,
                           ncols=len(input_files),
                           figsize=(16, 16),
                           dpi=90)
    coord_range = max(max(ra_max) - min(ra_min), max(dec_max) - min(dec_min))
    output = []
    output2 = []
    for epoch in data:
        print("epoch", epoch)
        velocity = data[epoch]["velocity"]
        intensity = data[epoch]["intensity"]
        index = list(data.keys()).index(epoch)
        ra = data[epoch]["ra"]
        dec = data[epoch]["dec"]
        title = dates[epoch]

        max_separation = {"r": 0, "d": -1, "separation": 0}
        sky_coords = [
            SkyCoord(ra[coord], dec[coord], unit=u.arcsec)
            for coord in range(0, len(ra))
        ]
        for r in range(0, len(ra)):
            for d in range(0, len(dec)):
                if r != d:
                    separation = sky_coords[r].separation(sky_coords[d])
                    if separation > max_separation["separation"]:
                        max_separation["r"] = r
                        max_separation["d"] = d
                        max_separation["separation"] = separation

        m, b = np.polyfit([ra[max_separation["r"]], ra[max_separation["d"]]],
                          [dec[max_separation["r"]], dec[max_separation["d"]]],
                          1)
        if ddddd:
            ax[1][index].plot(
                [ra[max_separation["r"]], ra[max_separation["d"]]], [
                    m * ra[max_separation["r"]] + b,
                    m * ra[max_separation["d"]] + b
                ], "k--")

        position_angle = 90 + np.degrees(np.arctan(m))
        print("position angle is ", position_angle)

        if len(velocity) >= 3:
            firs_exceeds_tmp = firs_exceeds(np.diff(velocity), 0.9)
            split_index = firs_exceeds_tmp + 1
            if firs_exceeds_tmp != -1:
                a = intensity[0:split_index]
                b = intensity[split_index:len(intensity)]
                c = velocity[0:split_index]
                d = velocity[split_index:len(velocity)]
                e = ra[0:split_index]
                f = ra[split_index:len(velocity)]
                g = dec[0:split_index]
                h = dec[split_index:len(velocity)]

                velocity_tmp = [c, d]
                intensity_tmp = [a, b]
                ra_tmp = [e, f]
                dec_tmp = [g, h]

                print(split_index, len(intensity))

            else:
                velocity_tmp = [velocity]
                intensity_tmp = [intensity]
                ra_tmp = [ra]
                dec_tmp = [dec]

            print("number of gauss", len(velocity_tmp))
            for gauss_nr in range(0, len(velocity_tmp)):
                size = []
                max_intensity_index = np.array(
                    intensity_tmp[gauss_nr]).argmax()
                for j in range(0, len(velocity_tmp[gauss_nr])):
                    for k in range(j + 1, len(velocity_tmp[gauss_nr])):
                        dist = np.sqrt((ra[j] - ra[k])**2 +
                                       (dec[j] - dec[k])**2)
                        size.append(dist)

                if len(velocity_tmp[gauss_nr]) >= 3:

                    amplitude = max(intensity_tmp[gauss_nr])
                    centre_of_peak_index = list(
                        intensity_tmp[gauss_nr]).index(amplitude)
                    centre_of_peak = velocity_tmp[gauss_nr][
                        centre_of_peak_index]
                    second_largest_amplitude_index = (
                        -intensity_tmp[gauss_nr]).argsort()[1]
                    second_largest_amplitude = intensity_tmp[gauss_nr][
                        second_largest_amplitude_index]
                    second_largest_centre_of_peak = velocity_tmp[gauss_nr][
                        second_largest_amplitude_index]
                    standard_deviation = np.std(intensity_tmp[gauss_nr])
                    ps = [[amplitude, centre_of_peak, standard_deviation],
                          [
                              amplitude, centre_of_peak, standard_deviation,
                              second_largest_amplitude,
                              second_largest_centre_of_peak, standard_deviation
                          ], [0.9, -6.45, 0.2],
                          [0.9, -6.45, 0.2, 0.32, -5.43, 0.1],
                          [0.361, -6.98, 0.2, 0.149, -6.489, 0.2],
                          [2.2, -6.9, 0.2, 23.6, -6.22, 0.2],
                          [1.99, -6.977, 0.05, 0.6, -7.3, 0.05],
                          [0.035, -7.75, 0.001]]

                    q = np.linspace(min(velocity_tmp[gauss_nr]),
                                    max(velocity_tmp[gauss_nr]), 10000)
                    perrs = []
                    coeffs = []
                    for p in ps:
                        #if epoch == "ea063":
                        #    p = [0.035, -7.75, 0.001]
                        try:
                            if len(p) == 3:
                                coeff, var_matrix = curve_fit(
                                    gauss,
                                    velocity_tmp[gauss_nr],
                                    intensity_tmp[gauss_nr],
                                    p0=p,
                                    method="lm")
                            else:
                                coeff, var_matrix = curve_fit(
                                    gauss2,
                                    velocity_tmp[gauss_nr],
                                    intensity_tmp[gauss_nr],
                                    p0=p,
                                    method="lm")

                            perr = np.sqrt(np.diag(var_matrix))
                            perr = perr[~np.isnan(perr)]
                            perrs.append(np.mean(perr) / len(perr))
                            coeffs.append(coeff)
                        except:
                            pass

                    if len(perrs) > 0:
                        coeff_index = perrs.index(min(perrs))
                        coeff = coeffs[coeff_index]

                        if len(coeff) == 6:
                            hist_fit = gauss2(q, *coeff)
                            ax[0][index].plot(q, hist_fit, 'k')
                            print(
                                "{\\it %d} & %.3f & %.3f & %.1f & %.2f & %.2f & %.3f & %.3f & %.2f & %.2f & %.3f & "
                                "%.1f(%.1f) & %.3f( "
                                "%.3f)\\\\" %
                                (gauss_nr,
                                 ra_tmp[gauss_nr][max_intensity_index],
                                 dec_tmp[gauss_nr][max_intensity_index],
                                 velocity[max_intensity_index], coeff[1],
                                 coeff[2] * 2, intensity[max_intensity_index],
                                 coeff[0], coeff[4], coeff[5] * 2, coeff[3],
                                 max(size), max(size) * 1.64,
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 max(size),
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 (max(size) * 1.64)))

                            output2.append([
                                epoch, gauss_nr,
                                ra_tmp[gauss_nr][max_intensity_index],
                                dec_tmp[gauss_nr][max_intensity_index],
                                velocity[max_intensity_index], coeff[1],
                                coeff[2] * 2, intensity[max_intensity_index],
                                coeff[0], coeff[4], coeff[5] * 2, coeff[3],
                                max(size),
                                max(size) * 1.64,
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                max(size),
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                (max(size) * 1.64), position_angle
                            ])

                        elif len(coeff) == 3:
                            hist_fit = gauss(q, *coeff)
                            ax[0][index].plot(q, hist_fit, 'k')
                            print(
                                "{\\it %d} & %.3f & %.3f & %.1f & %.2f & %.2f & %.3f & %.3f & %.1f(%.1f) & %.3f("
                                "%.3f)\\\\" %
                                (gauss_nr,
                                 ra_tmp[gauss_nr][max_intensity_index],
                                 dec_tmp[gauss_nr][max_intensity_index],
                                 velocity[max_intensity_index], coeff[1],
                                 coeff[2] * 2, intensity[max_intensity_index],
                                 coeff[0], max(size), max(size) * 1.64,
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 max(size),
                                 (velocity[0] - velocity[len(velocity) - 1]) /
                                 (max(size) * 1.64)))

                            output2.append([
                                epoch, gauss_nr,
                                ra_tmp[gauss_nr][max_intensity_index],
                                dec_tmp[gauss_nr][max_intensity_index],
                                velocity[max_intensity_index], coeff[1],
                                coeff[2] * 2, intensity[max_intensity_index],
                                coeff[0], "-", "-", "-",
                                max(size),
                                max(size) * 1.64,
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                max(size),
                                (velocity[0] - velocity[len(velocity) - 1]) /
                                (max(size) * 1.64), position_angle
                            ])
                else:
                    if len(size) > 0:
                        print(
                            "{\\it %d} & %.3f & %.3f & %.1f & %s & %s & %.3f & %s & %.1f(%.1f) & %.3f(%.3f)\\\\"
                            % (gauss_nr, ra_tmp[gauss_nr][max_intensity_index],
                               dec_tmp[gauss_nr][max_intensity_index],
                               velocity[max_intensity_index], "-", "-",
                               intensity[max_intensity_index], "-", max(size),
                               max(size) * 1.64,
                               (velocity[0] - velocity[len(velocity) - 1]) /
                               max(size),
                               (velocity[0] - velocity[len(velocity) - 1]) /
                               (max(size) * 1.64)))

                        output2.append([
                            epoch, gauss_nr,
                            ra_tmp[gauss_nr][max_intensity_index],
                            dec_tmp[gauss_nr][max_intensity_index],
                            velocity[max_intensity_index], "-", "-",
                            intensity[max_intensity_index], "-", "-", "-", "-",
                            max(size),
                            max(size) * 1.64,
                            (velocity[0] - velocity[len(velocity) - 1]) /
                            max(size),
                            (velocity[0] - velocity[len(velocity) - 1]) /
                            (max(size) * 1.64), position_angle
                        ])

                    else:
                        print(
                            "{\\it %d} & %.3f & %.3f & %.1f & %s & %s & %.3f & %s & %s & %s\\\\"
                            % (gauss_nr, ra_tmp[gauss_nr][max_intensity_index],
                               dec_tmp[gauss_nr][max_intensity_index],
                               velocity[max_intensity_index], "-", "-",
                               intensity[max_intensity_index], "-", "-", "-"))

                        output2.append([
                            epoch, gauss_nr,
                            ra_tmp[gauss_nr][max_intensity_index],
                            dec_tmp[gauss_nr][max_intensity_index],
                            velocity[max_intensity_index], "-", "-",
                            intensity[max_intensity_index], "-", "-", "-", "-",
                            "-", "-", "-", position_angle
                        ])

        print("\n")

        for o in range(0, len(velocity)):
            output.append([
                epoch, velocity[o], intensity[o], ra[o], dec[o], position_angle
            ])

        for i in range(len(velocity)):
            if velocity[i] < min(velocity_min) or velocity[i] > max(
                    velocity_max):
                c = (0, 0, 0)
            else:
                c = cm.turbo((velocity[i] - min(velocity_min)) /
                             (max(velocity_max) - min(velocity_min)), 1)

            ax[0][index].scatter((velocity[i]), (intensity[i], ),
                                 color=c,
                                 lw=2)

            el = Circle((ra[i], dec[i]),
                        radius=0.05 * np.log(intensity[i] * 1000),
                        angle=0,
                        lw=2)
            el.set_facecolor(c)
            ax[1][index].add_artist(el)

        ax[0][index].set_xlim(min(velocity_min) - 0.2, max(velocity_max) + 0.5)
        ax[0][index].set_ylim((min(intensity_min)) - 0.5,
                              (max(intensity_max) + 0.5))
        ax[0][index].xaxis.set_minor_locator(minor_locator_level)
        ax[0][index].set_title(title)
        ax[0][index].set_xlabel('$V_{\\rm LSR}$ (km s$^{-1}$)')
        ax[1][index].set_aspect("equal", adjustable='box')
        ax[1][index].set_xlim(
            np.mean((max(ra_max), min(ra_min))) - (coord_range / 2) - 0.5,
            np.mean((max(ra_max), min(ra_min))) + (coord_range / 2) + 0.5)
        ax[1][index].set_ylim(
            np.mean((max(dec_max), min(dec_min))) - (coord_range / 2) - 0.5,
            np.mean((max(dec_max), min(dec_min))) + (coord_range / 2) + 0.5)
        ax[1][index].set_xlabel('$\\Delta$ RA (mas)')
        ax[1][index].xaxis.set_minor_locator(minor_locatorx)
        ax[1][index].yaxis.set_minor_locator(minor_locatory)
        ax[1][index].invert_xaxis()
        ax[1][index].set_yscale('linear')
        ax[1][index].set_yscale('linear')

    header1 = ["epoch", "velocity", "intensity", "ra", "dec", "position_angle"]
    header2 = [
        "epoch", "gauss_nr", "ra", "dec", "velocity", "coeff1", "coeff2_*_2",
        "max_intensity", "coeff0", "coeff4", "coeff5_*_2", "coeff3",
        "max_distance", "max_distance_au", "gradient", "gradient_au",
        "position_angle"
    ]

    np.savetxt("cloudlet_" + str(group_number) + "._coords.csv",
               np.array(output, dtype=object),
               delimiter=", ",
               fmt='%s',
               header=",".join(header1))
    np.savetxt("cloudlet_" + str(group_number) + "._sats.csv",
               np.array(output2, dtype=object),
               delimiter=", ",
               fmt='%s',
               header=",".join(header2))
    ax[0][0].set_ylabel('Flux density (Jy)')
    ax[1][0].set_ylabel('$\\Delta$ Dec (mas)')
    plt.tight_layout()
    plt.subplots_adjust(top=0.947,
                        bottom=0.085,
                        left=0.044,
                        right=0.987,
                        hspace=0.229,
                        wspace=0.182)
    plt.show()
예제 #7
0
def colorise_ribbon(ribbon_section, t1_section, r_threshold, t_threshold):
    t1_gray = cm.gray(np.array(t1_section / t_threshold))
    mask = ribbon_section > 0
    coloured_cortex = cm.turbo(np.array(ribbon_section / r_threshold))
    t1_gray[mask] = coloured_cortex[mask]
    return t1_gray * 255
    plt.figure()
    plt.scatter(all_g, abs(np.hstack(sum_v_g)))
    plt.ylabel(r'$|\sum_{ij} (\phi_s(i) - \phi_s(j))\,\delta(C_i,C_j)|$')
    plt.xlabel('number of nodes')

    ind = np.where(abs(np.hstack(sum_v_g)) == max(abs(np.hstack(sum_v_g))))[0]
    plt.figure()
    plt.plot(v[:, ind])
    plt.savefig('phi2.svg')

    plt.figure()
    ind = np.argsort(w)
    # colors = cm.rainbow(np.linspace(0, 1, len(w)))
    color = []
    for i, y in enumerate(abs(np.array(sum_v_g).flatten())):
        plt.scatter(w[i], y, color=cm.turbo(y))
        color.append(cm.turbo(y))
    # plt.scatter(w[ind],abs(np.array(sum_v_g)))
    plt.savefig('diffusion_differece.svg')
    #plt.axvline(lambda2,c='r')

    #compute correlation with ground truth
    gt = [
        1 / np.sqrt(g_) if i in C_1 else -1 / np.sqrt(g_)
        for i in range(len(largest_cc))
    ]
    gt = np.array(gt)
    corr = []
    for s in range(v.shape[1]):
        corr.append(gt.dot(v[:, s]))
예제 #9
0
    #if((daily_counts_65[xx] - mask_day_avgs[indices[0]]) < 0.5 * \
        mask_day_stds[indices[0]]):
        #daily_counts_65[xx] = -9
        new_daily_counts[xx] = daily_counts_65[xx]

daily_counts_65 = np.ma.masked_where(daily_counts_65 == -9, daily_counts_65)

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
#
# Plot the individual years of area time series
#
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

fig0 = plt.figure(figsize=(10, 4))
ax0 = fig0.add_subplot(1, 1, 1)
plot_c = cm.turbo((years - np.min(years)) / (np.max(years) - np.min(years)))

# Set up an array to hold the event counts
# ----------------------------------------
d_val = 4
#h_val = 1
if (interval == 0.2):
    max_val = np.round(np.max(daily_counts_65), 1) + interval
else:
    if (int(min_lat) == 75):
        max_val = int(np.max(daily_counts_65)) + 2 * interval
    else:
        max_val = int(np.max(daily_counts_65)) + interval

event_sizes = np.arange(h_val, max_val, interval)
events_yearly = np.zeros((years.shape[0], event_sizes.shape[0]))