示例#1
0
def map(
    imbin_file,
    som_file,
    map_file,
    trans_file,
    som_width,
    som_height,
    cpu_only=False,
    nrot=360,
    numthreads=10,
    overwrite=False,
    log=True,
):
    # /// Map through SOM \\\
    imgs = pu.ImageReader(imbin_file)
    if not os.path.exists(map_file) or overwrite:
        map_imbin(
            imbin_file,
            som_file,
            map_file,
            trans_file,
            som_width,
            som_height,
            numthreads=numthreads,
            cpu=cpu_only,
            nrot=nrot,
            log=log,
        )

    som = pu.SOM(som_file)
    mapping = pu.Mapping(map_file)
    transform = pu.Transform(trans_file)
    somset = pu.SOMSet(som, mapping, transform)
    return somset
示例#2
0
def init_somset(som_file, map_file=None, trans_file=None):
    """Initialize the SOMSet, which contains the SOM, mapping,
    and transform files.

    Args:
        som_file (str): Name of the SOM file.
        map_file (str, optional): Name of the mapping file. Defaults to None, 
        in which case it follows the default naming scheme.
        trans_file (str, optional): Name of the transform file. Defaults to None.

    Returns:
        pu.SOMSet: A container holding the SOM, mapping, and transform files.
    """
    som = pu.SOM(som_file)

    if map_file is None:
        map_file = som_file.replace("SOM", "MAP")
    mapping = pu.Mapping(map_file)

    if trans_file is None:
        trans_file = map_file.replace("MAP", "TRANSFORM")
    transform = pu.Transform(trans_file)

    somset = pu.SOMSet(som=som, mapping=mapping, transform=transform)
    return somset
示例#3
0
          file=outfile)
    print(f"  \includegraphics[width=0.75\\textwidth]{{{base}_img0.png}}",
          file=outfile)
    print(f"  \includegraphics[width=0.75\\textwidth]{{{base}_img1.png}}",
          file=outfile)
    print(f"  \caption{{{caption}}}", file=outfile)
    print(f"  \label{{fig:{label}}}", file=outfile)
    print(f"\end{{figure*}}", file=outfile)


if len(sys.argv) < 5:
    print(f"USAGE: {sys.argv[0]} IMG SOM MAP TRANSFORM")

imgs = pu.ImageReader(sys.argv[1])
som = pu.SOM(sys.argv[2])
mapping = pu.Mapping(sys.argv[3])
trans = pu.Transform(sys.argv[4])
somset = pu.SOMSet(som, mapping, trans)

path = pu.PathHelper("Inspection")
outfile = open("latex_imgs.tex", "w")

### SOM 2D histogram ###
som_counts(somset, True)
plt.savefig(f"som_stats.png")
plt.clf()
caption = f"The total number of images within the {imgs.data.shape[0]} input images mapped to each neuron in the SOM."
latex_figure("som_stats.png", caption, "som_stats", outfile)
print("", file=outfile)
########################
示例#4
0

if len(sys.argv) != 3:
    print("USAGE: {} sample_file som_file".format(sys.argv[0]))
    sys.exit(-1)

sample_file = sys.argv[1]
df = pd.read_csv(sample_file)

imbin = pu.ImageReader(sample_file.replace(".csv", "_imgs.bin"))

som_file = sys.argv[2]
som = pu.SOM(som_file)

map_file = som_file.replace(".bin", "_Similarity.bin")
mapping = pu.Mapping(map_file)

trans_file = som_file.replace(".bin", "_Transform.bin")
transform = pu.Transform(trans_file)

somset = pu.SOMSet(som=som, mapping=mapping, transform=transform)

### Update the component catalogue ###

bmus = mapping.bmu()
df["bmu_x"] = bmus[:, 0]
df["bmu_y"] = bmus[:, 1]
df["bmu_tup"] = mapping.bmu(return_tuples=True)
df["bmu_ed"] = mapping.bmu_ed()

trans = transform.data[np.arange(transform.data.shape[0]), bmus[:, 0], bmus[:, 1]]
示例#5
0
def source_from_catalogue(
    src_cat,
    radio_cat,
    imbin_path,
    som=None,
    show_nearby=False,
    show_bmu=False,
    idx=None,
):
    if idx is None:
        # idx = np.random.randint(len(src_cat))
        idx = src_cat[src_cat.N_components > 1].sample(1).index[0]
    src = src_cat.loc[idx]

    comp_names = src.Component_names.split(";")
    tile_id = radio_cat[radio_cat.Component_name == comp_names[0]].Tile.iloc[0]
    radio_tile = radio_cat[radio_cat.Tile == tile_id].reset_index(drop=True)
    comps = radio_tile[radio_tile["Component_name"].isin(comp_names)]

    radio_ra = np.array(src.RA_components.split(";"), dtype=float)
    radio_dec = np.array(src.DEC_components.split(";"), dtype=float)
    radio_pos = SkyCoord(radio_ra, radio_dec, unit=u.deg)

    if src.N_host_candidates > 0:
        ir_ra = np.array(src.RA_host_candidates.split(";"), dtype=float)
        ir_dec = np.array(src.DEC_host_candidates.split(";"), dtype=float)
        ir_pos = SkyCoord(ir_ra, ir_dec, unit=u.deg)

    img_file, map_file, trans_file = binary_names(tile_id, imbin_path)
    imgs = pu.ImageReader(img_file)
    mapping = pu.Mapping(map_file)
    transform = pu.Transform(trans_file)

    if som is not None:
        somset = pu.SOMSet(som, mapping, transform)

    img_idx = comps.index[0]
    comp = comps.loc[img_idx]
    npix = imgs.data.shape[-1]
    wcs = create_wcs(comp.RA, comp.DEC, npix, 3 * u.arcmin / npix)

    if show_bmu:
        plot_image(
            imgs,
            img_idx,
            somset=somset,
            wcs=wcs,
            transform_neuron=True,
            show_bmu=show_bmu,
        )
    else:
        plot_image(imgs, img_idx, wcs=wcs, show_bmu=False)
    axes = plt.gcf().axes

    if show_nearby:
        posn = SkyCoord(comp.RA, comp.DEC, unit=u.deg)
        coords = SkyCoord(radio_cat.RA, radio_cat.DEC, unit=u.deg)
        nearby = coords[posn.separation(coords) < 1.5 * u.arcmin]
        for ax in plt.gcf().axes:
            ax.scatter(
                nearby.RA, nearby.DEC, c="w", transform=ax.get_transform("world")
            )

    # for ax in plt.gcf().axes:
    #     ax.scatter(comps.RA, comps.DEC, c="r", transform=ax.get_transform("world"))

    axes[0].scatter(
        radio_pos.ra, radio_pos.dec, c="r", transform=axes[0].get_transform("world")
    )
    if src.N_host_candidates > 0:
        axes[1].scatter(
            ir_pos.ra, ir_pos.dec, c="w", transform=axes[1].get_transform("world")
        )

    plt.suptitle(f"Source ID: {idx}")