maelstromscientist
maelstromscientist

Reputation: 551

Integrating over a circle in a 2D array

I'm trying to integrate over the area of a circular aperture superimposed on an array of pixels (see image below). However, I need to determine the fraction of flux (area) inside the circular aperture, and leave out anything outside the circular aperture in each square pixel on the boundary of the circle.

How would I go about coding this in numpy/python such that I am getting an accurate measure of the flux inside the circle?

enter image description here

Upvotes: 2

Views: 1862

Answers (2)

Eric
Eric

Reputation: 97641

  1. Draw a white circle on a black background of the radius you're after in an image editor of your choice, and save a bitmap of your output
  2. Load the image in your code, with scipy.misc.imload, and divide the pixel values by 255 so you have a mask in 0.0...1.0
  3. Calculate the sum of the product of that mask with your data to integrate

Upvotes: 0

Neil G
Neil G

Reputation: 33242

Calculate the proportion of each pixel that is within the circle using calculus. (Integrate the equation of your circle between the left-right boundaries of the each.)

Upvotes: 1

Related Questions