Slicing a circle in equal segments, Python

I have a set of 10,000 points in the sky. They are built using RA (right ascension) and DEC (declination) in the sky. When depicted, they take the form of a circle.

enter image description here

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

To do this, I came up with this illustration, that is, I cut them using arcs.

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

S = r * theta 

Where

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

I would like to do it like this:

 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 square, it becomes very easy, and the above equation can be applied immediately.

So, as soon as I have my piece, I can do numpy.where() to find out the rest of my circle.

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

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

enter image description here

I do not know how to do this in my case (i.e. in 8 quadrants !!), where I have x, y coordinates for my data points !!

+5
source share
3 answers

You can compute an array of slice numbers directly using numpy operators:

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

value:

  • calculate angle -pi ... pi for each point with arctan2
  • shift pi to make it a positive interval
  • scale to 0 .. N-1
  • convert to integer
+4
source

You should probably use math.atan2 :

 angle = math.atan2(dec, ra) if angle >= n*math.pi/4 and angle < (n+1)*math.pi/4: # point is inside slice number n 

Basically, atan2 returns the angle to a point from the x axis. By dividing it into pi / 4 intervals, you get your pieces. But be careful - atan2 returns angles between -pi and pi, so you must specify your fragments from -4 to 3 (or you can add pi to the corner or convert it in some other way).

EDIT: changing the code, it will look like this:

 slice1 = [] n = 0 #change 0 to desired slice number here (from -4 to 3) for a,b in zip(ra,dec): angle = math.atan2(b,a) if angle >= n*math.pi/4 and angle < (n+1)*math.pi/4: slice1.append(a,b) 
+5
source

First find the quadrant using your formula. The octant can then be determined by comparing abs(x) with abs(y) .

In the lower octane, abs(x) >= abs(y) . The other has abs(x) < abs(y)

+2
source

All Articles