def bin_reader(wfile, index=0, ytox=1., zscale=1., crop=[None, None, None], center=None): """Read a binary .npy file containing a list of lists in form (imdata, dx). Can crop data and translate on three coordinates. crop is calculated on raw data, center is the position of the central point after crop and scaling.""" d = np.load(wfile) data = d[index][0] ypix = d[index][1] ny, nx = data.shape x = np.arange(nx) * ypix * ytox * nx / (nx - 1) y = np.arange(ny) * ypix * ny / (ny - 1) y = max(y) - y data = data * zscale data, x, y = crop_data(data, x, y, *crop) if center is not None: assert len(center) >= 2 x = x - (np.max(x) + np.min(x)) / 2. + center[0] y = y - (np.max(y) + np.min(y)) / 2. + center[1] if len(center) == 3: data = data - (np.nanmax(data) + np.nanmin(data)) / 2. + center[2] return data, x, y
def fitsWFS_reader(wfile, ypix=1., ytox=1., zscale=1., crop=[None, None, None], center=None, strip=False, scale=(1, 1, 1.)): """return data (matrix) and x,y (vectors) from fits WFS file. I don't understand very well order of data, inverting data works for S22 for bump positive, but sample seems rotated and horizontally flipped. If strip is set, nan are removed. strip is done after centering and scaling, so center is calculated on full data.""" aa = fits.open(wfile) header = aa[0].header data = -aa[0].data aa.close() #adjust crop and scales ny, nx = data.shape x = np.arange(nx) * ypix * ytox * nx / (nx - 1) * scale[0] y = np.arange(ny) * ypix * ny / (ny - 1) * scale[1] data = data * zscale * scale[2] #if any x or y is inverted invert data and orient as cartesian. if x[-1] < x[0]: x = x[::-1] data = np.fliplr(data) x = x - min(x) if y[-1] < y[0]: y = y[::-1] data = np.flipud(data) y = y - min(y) #doing cropping here has the effect of cropping on cartesian orientation, #coordinates for crop are independent on center and dependent on scale and pixel size. #center is doing later, resulting in center of cropped data only is placed in the suitable position. if crop is None: crop = [None, None, None] data, x, y = crop_data(data, x, y, *crop) #center data if center is None, leave unchanged if center is not None: assert len(center) >= 2 x = x - (np.max(x) + np.min(x)) / 2. + center[0] y = y - (np.max(y) + np.min(y)) / 2. + center[1] if len(center) == 3: data = data - (np.nanmax(data) + np.nanmin(data)) / 2. + center[2] if strip: #messes up x and y data, x, y = remove_nan_frame(data, x, y) return data, x, y
def crop(self, *args, **kwargs): res = self.copy() res.data, res.x, res.y = crop_data(self.data, self.x, self.y, *args, **kwargs) return res
def crop(self, *args, **kwargs): """crop data making use of function data2D.crop_data, where data,x,y are taken from a""" res = self.copy() res.data, res.x, res.y = crop_data(self.data, self.x, self.y, *args, **kwargs) return res
def crop(self, *args, **kwargs): self.data, self.x, self.y = crop_data(self.data, self.x, self.y, *args, **kwargs) return self