def test_init_with_lists_calling_scale_and_detrend(): t = Topography(np.array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]), physical_sizes=(1, 1)) # the following commands should be possible without errors st = t.scale(1) st.detrend(detrend_mode='center')
def test_attribute_error(): X = np.arange(3).reshape(1, 3) Y = np.arange(4).reshape(4, 1) h = X + Y t = Topography(h, (8, 6)) # nonsense attributes return attribute error with pytest.raises(AttributeError): t.ababababababababa # # only scaled topographies have coeff # with pytest.raises(AttributeError): t.coeff st = t.scale(1) assert st.height_scale_factor == 1 # # only detrended topographies have detrend_mode # with pytest.raises(AttributeError): st.detrend_mode dm = st.detrend(detrend_mode='height').detrend_mode assert dm == 'height' # # this all should also work after pickling # t2 = pickle.loads(pickle.dumps(t)) with pytest.raises(AttributeError): t2.height_scale_factor st2 = t2.scale(1) assert st2.height_scale_factor == 1 with pytest.raises(AttributeError): st2.detrend_mode dm2 = st2.detrend(detrend_mode='height').detrend_mode assert dm2 == 'height' # # this all should also work after scaled+pickled # t3 = pickle.loads(pickle.dumps(st)) with pytest.raises(AttributeError): t3.detrend_mode dm3 = t3.detrend(detrend_mode='height').detrend_mode assert dm3 == 'height'
def topography(self, channel_index=None, physical_sizes=None, height_scale_factor=None, info={}, periodic=False, subdomain_locations=None, nb_subdomain_grid_pts=None): if channel_index is None: channel_index = self._default_channel_index if subdomain_locations is not None or \ nb_subdomain_grid_pts is not None: raise RuntimeError( 'This reader does not support MPI parallelization.') close_file = False if not hasattr(self._fobj, 'read'): fobj = open(self._fobj, 'rb') close_file = True else: fobj = self._fobj channel = self._channels[channel_index] sx, sy = self._check_physical_sizes(physical_sizes, channel.physical_sizes) nx, ny = channel.nb_grid_pts offset = self._offsets[channel_index] dtype = np.dtype('<i2') ################################### fobj.seek(offset) rawdata = fobj.read(nx * ny * dtype.itemsize) unscaleddata = np.frombuffer(rawdata, count=nx * ny, dtype=dtype).reshape(nx, ny) # internal information from file _info = dict(unit=channel.info["unit"], data_source=channel.name) _info.update(info) if 'acquisition_time' in channel.info: _info['acquisition_time'] = channel.info['acquisition_time'] # the orientation of the heights is modified in order to match # the image of gwyddion when plotted with imshow(t.heights().T) # or pcolormesh(t.heights().T) for origin in lower left and # with inverted y axis (cartesian coordinate system) surface = Topography(np.fliplr(unscaleddata.T), (sx, sy), info=_info, periodic=periodic) if height_scale_factor is None: height_scale_factor = channel.info["height_scale_factor"] surface = surface.scale(height_scale_factor) if close_file: fobj.close() return surface