Question: import matplotlib.pyplot as plt import numpy as np def main ( ) : im = loadImage ( ' 3 0 0 _ 2 6 a
import matplotlib.pyplot as plt
import numpy as np
def main:
im loadImageabigvltsjpg
imDphi opticalSystemim
images gerchbergSaxtonimDphi
saveFramesimages
def loadImagename:
im pltimreadname
if lenimshape:
im im::im::im::
imim
imim
return im
def opticalSystemimwidth:
im occultSquareimwidth
IMaIMp dftim
rng nprandom.defaultrng
imR rngrandomimshape
Dphi dftimR
im idftIMaIMpDphi
return imDphi
def occultSquareimwidth:
h w imshape
centerh h
centerw w
halfwidth width
imcenterh halfwidth:centerh halfwidth, centerw halfwidth:centerw halfwidth
return im
def dftim:
IM npfftrfftim
IMa npabsIM
IMp npangleIM
return IMaIMp
def idftIMaIMp:
IM IMa npcosIMpj npsinIMp
im npfftirfftIM
imim
imim
return im
def gerchbergSaxtonimmaxIters,Dphi:
IMaIMp dftim
images
for k in rangemaxIters:
printIteration d of dkmaxIters
if k :
correctedIMp IMp
elif k maxIters:
correctedIMp IMp Dphi
else:
correctedIMp IMp k maxIters Dphi # Linear interpolation
im idftIMa correctedIMp
images.appendim
return images
def saveFramesimages:
shape imagesshape imagesshape
image npzerosshape imagesdtype
maxIters lenimages
for k in rangemaxIters:
image: : : imagesk: : npnewaxis # Equal parts of red, green, and blue
pltimshowimage
plttitlefCoronagraph Iteration: k # Adjusted title
pltaxisoff # Hide axes
pltsavefigfcoronagraphkpng
pltshow
main this is my python code: please make the follwoing changes in my python code: In the saveFrames function, insert pltsubplot and pltsubplot statements so that images are shown on the right side only. Rename the occultSquare function to occultCircle, both where it is defined and also where it is invoked. Revise its definition so that instead of blacking out, or occulting, a square of the specified width, the function occults a circle with that diameter, or width.
The occulted group of pixels must be at the centre of the image. Verify that your program runs.Modify the occultCircle function to return a second argument, mask, that is a D NumPy array of boolean entries. Initialize it using npfull, to have the same shape as the first input argument, im but with the value False. For every entry of im you occult, assign the corresponding entry of mask to True. Modify the invocation in opticalSystem of occultCircle so that its output arguments are assigned to two variables, the first of which, im is the same as before. Verify that your program runs.Modify opticalSystem to return a third argument, mask, the mask obtained from occultCircle. Modify main to accept the third output argument from opticalSystem and to pass it as a fourth input argument to gerchbergSaxton. Modify gerchbergSaxton to accept a fourth input argument, mask, and to return a second output argument, errors, initialized to an empty list. Modify saveFrames to
accept a second input argument, errors. So that you can verify your program runs, modify main to accept the errors argument from gerchbergSaxton and to pass it on to saveFrames.
In gerchbergSaxton, compute a float, error, from the result, im of each idft invocation and the
fourth input argument, mask. Append each such float, error, to the list, errors, that the function
returns. The error is the sum total of the squared values of im entries where corresponding mask
entries are True. Outsource computation to a function, occultError, with two input arguments and one output argument, that you define and invoke appropriately. Verify that your program runs.Examine the computed list, errors, with the Variable Explorer using a breakpoint inside saveFrames.
Expected values can be read approximately from the coronagraphvapng files. Compute the maximum, maxErrors, of errors within saveFrames. Without altering the rightside image, make and annotate the leftside plot as indicated in the given png files. Verify your program works.Examine the coronagraphvbpng files. To meet the implied requirements, modify saveFrames. Remove all pltsubplot and any pltaxisoff statements. Plot the graph first with correct limits Using a pltimshow statement with an extent argument, where you determine the expression add the image to the graph plotted lines will show Use pltgcasetaspect where you must compute from maxIters and maxErrors, so image is crrct
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
