Skip to content
Snippets Groups Projects
Commit 75879b2d authored by Francois POLACK's avatar Francois POLACK
Browse files

refact: Suppressed wildcards in imports

parent c10a12e7
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ import matplotlib.pyplot as plt
import matplotlib.figure as fig
import matplotlib.patches as patches
from matplotlib.backend_tools import ToolBase #, ToolCursorPosition #, ToolToggleBase
from processing import *
from processing import fit2D_order2, fit2D_poly
def on_press(event):
......
......@@ -35,15 +35,17 @@ from pathlib import Path
import h5py as h5
import matplotlib.pyplot as plt
import matplotlib.figure as fig
import nexusformat.nexus.tree as nx
import ZygoDat
import ZygoXYZ
import ZygoDatx
from processing import *
from processing import fit2D_poly, fit_toroid, fit2D_order2, fit_toroid1, holey_periodogram, \
spline_interpolate, makePowerList, fit_conic_cylinder
from activefigure import new_active_figure, Viewer2D, on_mouse_move
import warnings
import pickle
from pathlib import Path
from nexusformat.nexus.tree import *
class HeightMap(object):
'''! @brief The HeightMap object-
......@@ -131,10 +133,19 @@ class HeightMap(object):
if not Path(filename).is_file():
tkinter.Tk().withdraw()
filename=filedialog.askopenfilename(title="Open a Zygo data file", filetypes=(("Zygo dat","*.dat"), ("Zygo datx","*.datx"),
("Zygo XYZ", "*.xyz"), ("Zygo ascii","*.ascii") ))
("Zygo XYZ", "*.xyz"), ("Zygo ascii","*.ascii"), ("Lei matlab","*.mat") ))
if Path(filename).suffix==".mat":
import scipy.io as sio
sio.whosmat(filename)
data=sio.loadmat(filename)
self.filepath=filename
self.x=data['x2d'][0,:]
self.y=data['y2d'][:,0]
fileorigin=[self.x[0], self.y[0]]
pixel=[abs(self.x[1]-self.x[0]), abs(self.y[1]-self.y[0])]
self.ze=self.z=self.rawZ=np.ma.masked_invalid( data['z2d_res'])
else:
if Path(filename).suffix==".dat":
datfile=ZygoDat.DatFile()
elif Path(filename).suffix==".xyz" or Path(filename).suffix==".ascii":
......@@ -731,74 +742,74 @@ class HeightMap(object):
# Create raw_data
xraw=np.linspace(-origin_x*xpix,(self.rawZ.shape[1]-origin_x)*xpix,num=self.rawZ.shape[1], endpoint=False)
yraw=np.linspace(-origin_y*ypix,(self.rawZ.shape[0]-origin_y)*ypix,num=self.rawZ.shape[0], endpoint=False)
x=NXfield(xraw, name='x', unit='meter')
y=NXfield(yraw, name='y', unit='meter')
rawdata=NXdata(NXfield(self.rawZ, name='height', unit='meter'),[x,y],name='raw_data')
x=nx.NXfield(xraw, name='x', unit='meter')
y=nx.NXfield(yraw, name='y', unit='meter')
rawdata=nx.NXdata(nx.NXfield(self.rawZ, name='height', unit='meter'),[x,y],name='raw_data')
#create detrended data group wit height and slope fields
height=NXfield(self.ze, name='height', unit='meter')
height=nx.NXfield(self.ze, name='height', unit='meter')
xview=np.linspace((self.ROIorigin[0]-origin_x)*xpix,(self.ROIorigin[0]+self.ROIsize[0]-origin_x)*xpix,num=self.z.shape[1], endpoint=False)
yview=np.linspace((self.ROIorigin[1]-origin_y)*ypix,(self.ROIorigin[1]+self.ROIsize[1]-origin_y)*ypix,num=self.z.shape[0], endpoint=False)
x=NXfield(xview, name='x', unit='meter')
y=NXfield(yview, name='y', unit='meter')
slope_x=NXfield(self.dzdx, name='slope_x', unit='radian')
slope_y=NXfield(self.dzdy, name='slope_y', unit='radian')
x=nx.NXfield(xview, name='x', unit='meter')
y=nx.NXfield(yview, name='y', unit='meter')
slope_x=nx.NXfield(self.dzdx, name='slope_x', unit='radian')
slope_y=nx.NXfield(self.dzdy, name='slope_y', unit='radian')
detrended_height=NXdata(height,[x,y], name='detrended_height')
detrended_height=nx.NXdata(height,[x,y], name='detrended_height')
#create the process group with detrending parameters and ROI definition
region=NXgroup( name='ROI', nxclass='NXregion', start=self.ROIorigin, count=self.ROIsize)
region.region_type=NXattr('rectangular')
process=NXprocess(region)
process.program=NXattr('detrend')
process.fit=NXattr('toroid')
process.radius_x=NXfield(self.fitparams[1],unit='meter')
process.radius_y=NXfield(self.fitparams[3],unit='meter')
process.rotation=NXfield(self.fitparams[0],unit='radian')
region=nx.NXgroup( name='ROI', nxclass='NXregion', start=self.ROIorigin, count=self.ROIsize)
region.region_type=nx.NXattr('rectangular')
process=nx.NXprocess(region)
process.program=nx.NXattr('detrend')
process.fit=nx.NXattr('toroid')
process.radius_x=nx.NXfield(self.fitparams[1],unit='meter')
process.radius_y=nx.NXfield(self.fitparams[3],unit='meter')
process.rotation=nx.NXfield(self.fitparams[0],unit='radian')
# the process.data group defining the process group will be a link. It cannot be set before the whole tree is created
#attach the process group to the detrended data group
detrended_height.process=process
#create the sample and instrument group
sample=NXsample()
detector=NXdetector(pixel_size_x=NXfield(self.pixel[0], unit='meter'), pixel_size_y=NXfield(self.pixel[1], unit='meter'))
instrument= NXinstrument(detector)
sample=nx.NXsample()
detector=nx.NXdetector(pixel_size_x=nx.NXfield(self.pixel[0], unit='meter'), pixel_size_y=nx.NXfield(self.pixel[1], unit='meter'))
instrument= nx.NXinstrument(detector)
#Create the measurement NXentry with the group which don't contain links
entry=NXentry(detrended_height,rawdata,sample,instrument, name='measurement1')
entry.definition=NXattr('NXmetrology')
#Create the measurement nx.NXentry with the group which don't contain links
entry=nx.NXentry(detrended_height,rawdata,sample,instrument, name='measurement1')
entry.definition=nx.NXattr('NXmetrology')
# add a the source data to the process group as alink
process.data=NXlink(rawdata)
process.data=nx.NXlink(rawdata)
detrended_slopes=NXdata(slope_x,[NXlink(x),NXlink(y)], slope_y=slope_y, name='detrended_slopes')
detrended_slopes=nx.NXdata(slope_x,[nx.NXlink(x),nx.NXlink(y)], slope_y=slope_y, name='detrended_slopes')
#create the process group with detrending parameters and ROI definition
process=NXprocess()
process.program=NXattr('numerical_derivation')
process.method=NXattr('3 points')
process=nx.NXprocess()
process.program=nx.NXattr('numerical_derivation')
process.method=nx.NXattr('3 points')
#attach the process group to the detrended data group
detrended_slopes.process=process
#Attach the slope group to the enntry
entry.detrended_slopes=detrended_slopes
#link the data to the process group
process.data=NXlink(detrended_height)
process.data=nx.NXlink(detrended_height)
# add the data group require by the NXmetrology definition
entry.data=NXdata(NXlink(height), [NXlink(x), NXlink(y)], slope_x=NXlink(slope_x), slope_y=NXlink(slope_y))
entry.data=nx.NXdata(nx.NXlink(height), [nx.NXlink(x), nx.NXlink(y)], slope_x=nx.NXlink(slope_x), slope_y=nx.NXlink(slope_y))
entry.data.set_default()
#add a drawing in the sample group if defined
if self.sample_drawing!=None:
add_drawing(sample,self.sample_drawing)
#add a fiducial group to the sample group
if self.fiducial_list != None:
sample.fiducials=NXgroup(nxclass='NXfiducials')
sample.fiducials=nx.NXgroup(nxclass='NXfiducials')
for name in self.fiducial_list:
fiducial=self.fiducial_list[name]
coord=((fiducial['coordinates'][0]-origin_x)*xpix, (fiducial['coordinates'][1]-origin_y)*ypix)
sample.fiducials.insert(NXfield(coord, name=name, unit='meter'))
sample.fiducials.insert(nx.NXfield(coord, name=name, unit='meter'))
0
#print(name, ': ', fiducial['mark'], fiducial['coordinates'][0]*self.pixel[0]*1.e3, fiducial['coordinates'][1]*self.pixel[1]*1.e3,'mm')
#print(sample['NXfiducials'])
#put the measurement entry in the default path
root=NXroot(entry)
root=nx.NXroot(entry)
entry.set_default()
# erase the old file if any and write the NeXus tree to the file
......@@ -827,14 +838,14 @@ def add_drawing(parent,filename):
if ext=='.svg' or ext=='.dxf':
with open(filename, 'r') as file:
text=file.read()
parent.drawing=NXfield(text)
parent.drawing=nx.NXfield(text)
elif ext=='.pdf':
with open(filename,'rb') as file:
filedata=file.read()
parent.drawing=NXfield(bytearray(filedata), dtype='uint8')
parent.drawing=nx.NXfield(bytearray(filedata), dtype='uint8')
else:
print("Invalid drawing file extension: ", ext)
parent.drawing.format=NXattr(ext)
parent.drawing.format=nx.NXattr(ext)
# this module function returns a HeightMap object from a previously saved .hmap file
......
......@@ -218,7 +218,7 @@ def spline_interpolate(data, window=('tukey', 0.2) ):
x=xbase[~ segment.mask]
y=segment[~ segment.mask]
# defining 1st derivative null at ends (periodic is not working)
# defining 1st derivative null at ends since Tuckey window was applied (periodic is not working)
spline3=scipy.interpolate.make_interp_spline(x, y, bc_type=([(1, 0.0)], [(1, 0.0)]))
outdata[outrow,:]=spline3(xbase, extrapolate='periodic')
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment