Slicing a circle in equal segments, Python

2024/12/9 21:41:25

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!!

Answer

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
https://en.xdnf.cn/q/73200.html

Related Q&A

Pyautogui screenshot. Where does it go? How to save and find later?

I am learning from Al Sweigarts you tube video for automating the boring stuff. I got to the part of taking screenshots. He didnt really explain in his video so I tested things out. I found that it tak…

How to get pip to point to newer version of Python

I have two versions of Python installed on my centOS server. [ethan@demo ~]$ python2.6 --version Python 2.6.6 [ehtan@demo ~]$ python --version Python 2.7.3The older version (2.6) is required by some es…

Connect JS client with Python server

Im relatively new to JS and Python, so this is probably a beginners question. Im trying to send a string from a JS client to Python Server (and then send the string to another Python client).This is my…

Pip does not acknowledge Cython

I just installed pip and Python via home-brew on a fresh Mac OS installation.First of all, my pip is not installing dependencies at all - which forces me to re-run pip install tables 3 times and every …

Is it me or is pygame.key.get_pressed() not working?

okay, so I am making a basic space-ship game.I cant get rotation to work because it scrambles the bitmap, but thats for another question.Should I even use a gif? any other filetype suggestions?back t…

Find out if a python script is running in IDLE or terminal/command prompt

Is there a way to find out if the python script is running in the IDLE interpreter or the terminal?Works cross-platform if possible, or if needed a different way for each platform.Work with Python 2 a…

How to map coordinates in AxesImage to coordinates in saved image file?

I use matplotlib to display a matrix of numbers as an image, attach labels along the axes, and save the plot to a PNG file. For the purpose of creating an HTML image map, I need to know the pixel coor…

Why am I getting IOError: [Errno 13] Permission denied?

I am creating Log file for the code but I am getting the following error :[Tue Jun 11 17:22:59 2013] [error] [client 127.0.0.1] import mainLCF [Tue Jun 11 17:22:59 2013] [error] [client 127.0.0.1] …

Difference between bytearray and list

What is the difference between bytearray and for example, a list or tuple?As the name suggests, bytearray must be an array that carries byte objects. In python, it seems that bytes and str are treate…

python NameError: name anything is not defined (but it is!)

Note: Solved. It turned out that I was importing a previous version of the same module.It is easy to find similar topics on StackOverflow, where someone ran into a NameError. But most of the questions …