Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong statistics in images with periodic boundaries #175

Open
smhr opened this issue Mar 11, 2021 · 0 comments
Open

Wrong statistics in images with periodic boundaries #175

smhr opened this issue Mar 11, 2021 · 0 comments

Comments

@smhr
Copy link

smhr commented Mar 11, 2021

I have a fits file with periodic BCs which shows projected density of a simulation snapshot. When I compute dendrogram, for structures that straddle the boundaries, the statistics seems to be wrong. please see the example.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib.ticker import LogLocator

from astrodendro import Dendrogram
from astrodendro import periodic_neighbours
from astrodendro.analysis import PPStatistic
from astrodendro import pp_catalog

from astropy.io import fits
from astropy.table import Table
from astropy import units as u
############
fig1 = plt.figure(figsize=(12, 12))

periodic_axis = [0, 1]  # data wraps along the y and x axes

ax = plt.subplot(1, 1, 1)
image = fits.getdata('my_fits.fits')
d = Dendrogram.compute(image, min_value=0.05, min_delta=0.01, min_npix=1, 
                       neighbours=periodic_neighbours(periodic_axis))
p = d.plotter()
im = ax.imshow(image, origin='lower', interpolation='nearest', 
                cmap='Blues', norm=LogNorm(vmin=0.007, vmax=1.1))
fig1.colorbar(im)

for leaf in d.leaves:
    p.plot_contour(ax, structure=leaf, linewidths=0.3, colors='blue')
    p.plot_contour(ax, structure=560, linewidths=0.6, colors='red') ## this is one of straddling structures

    s = PPStatistic(leaf)
    ellipse = s.to_mpl_ellipse(edgecolor='green', linewidth=1, facecolor='none')
    ax.add_patch(ellipse)
    
metadata = {}
metadata['data_unit'] = u.Jy

cat = pp_catalog(d.leaves, metadata, verbose=False)
cat.write('test_catalog_periodic.txt', format='ascii', overwrite=True)

## load data from catalog 
iid, area, mass, x, y = np.loadtxt('test_catalog_periodic.txt', 
                                   skiprows=1, usecols=(0,2,3,8,9), unpack=True)

for _ in range(0, iid.size):
    if iid[_] == 560:
        ax.scatter(x[_], y[_], s=10, color='k')
        ax.annotate(iid[_], (x[_], y[_]))

plt.show()

This is the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant