Search code examples
pythongeometrycomputational-geometryastronomy

Slicing a circle in equal segments, Python


I have a set of close of 10,000 points on the sky. They are plotted using the RA (right ascension) and DEC (declination) on the sky. When plotted, they take the shape of a circle.

enter image description here

What I would like to do is to slice the circle into 8 equal parts and remove each part one at a time and do some calculations using the remaining parts.

To do so I came up with this illustration in mind, i.e. slicing them using the arcs.

I know that the equation of the arc is given by:

S = r * theta

where

r --> radius
theta --> angle (in our case 45 degrees)

I would somehow like to do this like:

slice1 = []
for a,b in zip(ra,dec):
    if a>some value and a<some value and b>some value and b<some value:
        slice1.append(a,b)

If they were a square, it becomes really easy, and the above equation can immediately be applied.

So once I have my slice, I can then do a numpy.where() to find out the rest of my circle.

I can easily slice it into four slices by just mentioning the min(RA),max(RA),min(DEC) and max(DEC). One such example when I do it for the first quadrant will give me this:

RA>0.0 and RA<max(RA) DEC>0.0 and DEC<max(DEC)

enter image description here

I don't know how to go about doing this in my case (i.e. into 8 quadrants!!), wherein I only have the x,y coordinates of my data points!!


Solution

  • You can compute the array of slice numbers directly with with numpy operators:

    sliceno = numpy.int32((pi + numpy.arctan2(Y, X)) * (N / (2*pi)))
    

    meaning:

    • compute the angle -pi...pi for each point with arctan2
    • shift by pi to make it a positive interval
    • rescale to 0..N-1
    • convert to an integer