Skip to content

[DOCS] More "pythonic" way for creating pixel coordinates in Voronoi binning example #101

@Knusper

Description

@Knusper
  • Describe the issue with the content

The Voronoi binning example in the tutorial contains the following code:

# First we need to make lists of pixel Coordinates
# note this will be stupid big with large data cubes
# in that case find a smartter way to make these arrays

# ... X is a 1D list of length 150**2
X = []
for x in np.arange(0, cube.shape[2]):
    X+=[x]*cube.shape[2]

x =  np.array(X)

# ... Y is a 1D list of length 150**2
Y=[]
for y in np.arange(0,cube.shape[1]):
    Y+=list(np.arange(0,cube.shape[1]))

y =  np.array(Y)

I don't know if finding a smarter way was meant an exercise for the reader, but I certainly think there is a more efficient way provided by numpy to do this.

  • Location of the issue in the documentation

https://heloises.github.io/hoki/Voronoi_binning_of_SED_data.html#Book-keeping---creating-the-pixel-coordinate,-signal-and-noise-arrays

  • Suggestion to improve or clear confusion

This does the trick:

X, Y = np.indices((cube.shape[2], cube.shape[1]))
x = X.flatten()
y = Y.flatten()

Can provide PR if you want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions