def get_ray_lengths(self,x=None,y=None,PositionTol = 3,Coords='Display'):
# Work out ray lengths for all raytraced pixels
RayLength = np.sqrt(np.sum( (self.ray_end_coords - self.ray_start_coords) **2,axis=-1))
# If no x and y given, return them all
if x is None and y is None:
if self.fullchip:
if Coords.lower() == 'display':
return RayLength
else:
return self.transform.display_to_original_image(RayLength,binning=self.binning)
else:
return RayLength
else:
if self.x is None or self.y is None:
raise Exception('This ray data does not have x and y pixel indices!')
# Otherwise, return the ones at given x and y pixel coords.
if np.shape(x) != np.shape(y):
raise ValueError('x and y arrays must be the same shape!')
else:
if Coords.lower() == 'original':
x,y = self.transform.original_to_display_coords(x,y)
orig_shape = np.shape(x)
x = np.reshape(x,np.size(x),order='F')
y = np.reshape(y,np.size(y),order='F')
RL = np.zeros(np.shape(x))
RayLength = RayLength.flatten()
xflat = self.x.flatten()
yflat = self.y.flatten()
for pointno in range(x.size):
if np.isnan(x[pointno]) or np.isnan(y[pointno]):
RL[pointno] = np.nan
continue
deltaX = xflat - x[pointno]
deltaY = yflat - y[pointno]
deltaR = np.sqrt(deltaX**2 + deltaY**2)
if np.nanmin(deltaR) <= PositionTol:
RL[pointno] = RayLength[np.nanargmin(deltaR)]
else:
raise Exception('No ray-traced pixel within PositionTol of requested pixel!')
return np.reshape(RL,orig_shape,order='F')
# Return unit vectors of sight-line direction for each pixel.
评论列表
文章目录