Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def coarsen ( terrain ) : x = terrain.points [ : , 0 ] y = terrain.points [ : , 1 ] z = terrain.points
def coarsenterrain:
x terrain.points:
y terrain.points:
z terrain.points:
# Reshape the coordinate arrays to match the dimensions of the terrain mesh
x xreshapeterraindimensions, orderF
y yreshapeterraindimensions, orderF
z zreshapeterraindimensions, orderF
# Sample every other point along each axis
xcoarse x:: ::
ycoarse y:: ::
zcoarse z:: ::
# Calculate the new dimensions
newdims terraindimensionsterraindimensions
# Create the new coarser mesh as a StructuredGrid
coarse pvStructuredGridxcoarse.ravelF ycoarse.ravelF zcoarse.ravelF
return xcoarse, ycoarse, zcoarse, coarse
#grade write your code in this cell and DO NOT DELETE THIS LINE
#NOTE: You do not need to round any values within your results.
def bilinx y points:
# YOUR CODE HERE
# raise NotImplementedError
# to keep unique x and y coordinate
xset set
yset set
# to be able to get value at the coordinate quickly
pointsdict
for point in points:
# add coordinates to set and dict
xset.addpoint
yset.addpoint
pointsdictpoint point point
# turn it to list
xlist listxset
ylist listyset
# sort the list
xlist.sort
ylist.sort
# printxlist
# printylist
# printpointsdict
# calculate t ratio for x
tx x xlist xlist xlist
# printtx
# calculate first bilinear interpolation for x axis
bilinbottom tx pointsdictxlist ylist tx pointsdictxlist ylist
bilintop tx pointsdictxlist ylist tx pointsdictxlist ylist
# printbilinbottom
# printbilintop
# calculate t ratio for y
ty y ylist ylist ylist
# return bilinear interpolation for y axis
return ty bilinbottom ty bilintop
Now, using your bilin function, create a new mesh or StructuredGrid object named intmesh, reconstructed from coarse using bilinear interpolation, with the same dimensions as our original mesh terrain. Your new mesh should contain the interpolated zvalues for each point in terrain.
As a starting point, we have defined some of the variables that will be helpful to you for creating your new interpolated mesh. Specifically, we will be checking the values in errz and intz, as defined below:
intz: a D array with the same shape as terrain.z that will contain the bilinearly interpolated zvalues from the coarsened mesh.
Note: intz is a D M x N x array where the last dimension contains the zvalues. You should note this when assigning elements to intz. The interpolated mesh is a D M by N by array, so tests will fail if you assign values to it as if it were just a D M by N array, bypassing the zaxis entirely. So if your code looks like intzxy bilin the fix is to change it to something like intzxy bilin or intzxy bilin
errz: a list of scalar values. This should contain the absolute error values between each zvalue in the original mesh and each interpolated zvalue in the new returned mesh
Just like how we added the attribute values to our coarse mesh in order to plot the zvalues of the mesh, you should add an additional attribute errors to intmesh in order to plot the absolute error values between the zvalues in the original mesh and the interpolated zvalues in our new returned mesh.
In the code block below, complete the implementation of reconstructMeshterraincoarse which should return a tuple containing intz errz, intmesh
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started