dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 38 forks source link

using x_cen and y_cen in structure_at #185

Open danielseifried opened 2 years ago

danielseifried commented 2 years ago

Hello, I have the following problem: I determine the center of a structure, let's say structure A, using the "x_cen" and "y_cen" routine from PPStatistic. If I take the values stored in the outcome (after rounding to integers) and plug this into the routine "structure_at" e.g. like "structure_at(round(x_cen),round(y_cen))", it does not give me back structure A. Rather I have to use "structure_at(round(y_cen),round(x_cen))", so using the coordinates in a switched manner. I have also a minimal example describing this if needed. I am wondering if I am doing something wrong here or misinterpreting the outcome of the routines. Thanks.

keflavich commented 2 years ago

It would be helpful to provide that minimal example. But I think this is the expected, if only poorly documented, result: structure_at uses numpy indexing.

danielseifried commented 2 years ago

Hi, most probable you are right. Attached you find the minimum example using a 3x3 image with one structure. Please apologize the naming "test-program.txt", GitHub didn't allow me to upload a file ending with ".py" 3x3.txt test-program.txt

keflavich commented 2 years ago

You can just paste the code here, e.g.:

import numpy as np

from astrodendro import Dendrogram
from astrodendro.analysis import PPStatistic

data = np.array([[0,1,0], [0,0,0], [0,0,0]])

print(data)

d = Dendrogram.compute(data, min_value=0.5, min_delta=0., min_npix=1)

# there is only one structure in total
print(d.trunk[0])
print(d.trunk[0].indices())

stat = PPStatistic(d.trunk[0])

xcen = stat.x_cen.value
ycen = stat.y_cen.value

print(xcen,ycen)

# Gives "None"
print(d.structure_at((round(xcen),round(ycen))))

#Gives the right result, but x- and y-coordinate are switched
print(d.structure_at((round(ycen),round(xcen))))