updated xray examples and changed path.exists with isfile since this was what I meant

This commit is contained in:
Marco Cammarata 2017-01-20 10:55:24 +01:00
parent 042c8d0ade
commit 6bb3c682df
7 changed files with 31 additions and 45 deletions

View File

@ -518,7 +518,7 @@ def downloadPDB(pdbID,outFileName=None):
if (outFileName is None):
outFileName = pdbID+".pdb"
folder = os.path.dirname(outFileName)
if (folder != '' and not os.path.exists(folder)):
if (folder != '' and not os.path.isdir(folder)):
os.makedirs(folder)
f=open(outFileName,"w")
f.write( "".join(lines) )
@ -1301,9 +1301,8 @@ def fac(n):
def define_colors(fname="colorbrewer_all_schemes.json"):
if not os.path.exists(fname):
if not os.path.isfile(fname):
fname = os.path.dirname(os.path.realpath(__file__)) + "/" + fname
if not os.path.exists(fname):
print("Cannot find colorbrewer_all_schemes.json can't continue")
print(fname)
return

View File

@ -167,7 +167,7 @@ class DataStorage(dict):
if isinstance(fileOrDict,dict):
d = fileOrDict
elif isinstance(fileOrDict,str):
if os.path.exists(fileOrDict):
if os.path.isfile(fileOrDict):
d = read(fileOrDict)
else:
self.filename=fileOrDict

View File

@ -107,7 +107,7 @@ def getAI(poni,folder=None):
ai = pyFAI.azimuthalIntegrator.AzimuthalIntegrator(**poni)
elif isinstance(poni,str):
# look is file exists in cwd
if os.path.exists(poni):
if os.path.isfilee(poni):
ai = pyFAI.load(poni)
# if file does not exist look for one with that name around
else:
@ -123,7 +123,7 @@ def getAI(poni,folder=None):
# look for file
for path in folders:
fname = path + "/" + poni
if os.path.exists(fname):
if os.path.isfile(fname):
log.info("Found poni file %s",fname)
break
else:
@ -197,7 +197,7 @@ def doFolder(folder,files='*.edf*',nQ = 1500,force=False,mask=None,
"""
if storageFile == 'auto': storageFile = folder + "/" + "pyfai_1d.h5"
if os.path.exists(storageFile) and not force:
if os.path.isfile(storageFile) and not force:
saved = storage.DataStorage(storageFile)
else:
saved = None

View File

@ -55,18 +55,15 @@ def prepareLog():
prepareLog()
def defineCalibrants(dmin=3):
from pyFAI import calibrant
c120 = calibrant.Cell(a=10.297,b=10.716,c=13.955,alpha=72.22,beta=70.45,gamma=74.13)
p120 = np.pi*2/ np.asarray( list(c120.d_spacing(dmin=dmin).keys()) ).astype(float)
p120.sort()
c300 = calibrant.Cell(a=10.485,b=11.015,c=14.280,alpha=74.61,beta=69.29,gamma=75.29)
p300 = np.pi*2/ np.asarray( list(c300.d_spacing(dmin=dmin).keys()) ).astype(float)
p300.sort()
return xray.storage.DataStorage( dict(p120=p120, c120=c120,p300=p300,c300=c300) )
c120 = xray.cell.Triclinic(a=10.297,b=10.716,c=13.955,alpha=72.22,beta=70.45,gamma=74.13)
p120,_ = c120.reflection_list()
c300 = xray.cell.Triclinic(a=10.485,b=11.015,c=14.280,alpha=74.61,beta=69.29,gamma=75.29)
p300,_ = c300.reflection_list()
return xray.storage.DataStorage( p120=p120, c120=c120,p300=p300,c300=c300)
def readCalculations(folder="../fesalen/cif",force=False,plot=False):
npz = folder + "/fesalen_calc.npz"
if not os.path.exists(npz) or force:
if not os.path.isfile(npz) or force:
ret = dict()
for T in ("120LS","200HS","300HS"):
# calculated with lambda = 1 Ang
@ -104,41 +101,37 @@ def findCenter(cen=(484,479.5),dist=0.251):
def removeBaseline(folder,qlims=(0.5,2.5),max_iter=30,force=False):
if isinstance(folder,int): folder = g_default_folder%folder
fname = folder + "/pyfai_1d_nobaseline"+id9.default_extension
if not os.path.exists(fname) or force:
data = azav(folder,doRemoveBaseline=False)
if not os.path.isfile(fname) or force:
log.info("Calling azav with default parameters")
data = azav(folder,withBaseline=False)
# first peak (around 0.6) is weak and requires special care ...
data.q,data.data = xray.utils.removeBackground(data.q,data.data,xlims=qlims,
max_iter=max_iter,background_regions=[ (0,0.58) ])
data.q,data.data = xray.utils.removeBackground(data.q,data.data,
xlims=qlims,max_iter=max_iter,background_regions=[ (0,0.58) ])
data.save(fname)
else:
data = xray.storage.read(fname)
return data
def azav(folder,nQ=3000,force=False,saveChi=True,mask=g_default_mask,
doRemoveBaseline=True):
if isinstance(folder,int): folder = g_default_folder%folder
if isinstance(mask,int):
files = xray.utils.getFiles(folder,"*.edf*")
img = xray.azav.pyFAIread(files[0])
temp = np.ones_like(img,dtype=bool)
temp[:mask] = False
mask = temp
azav = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
if doRemoveBaseline: removeBaseline(folder)
return azav
withBaseline=True):
if withBaseline:
data=removeBaseline(folder)
else:
data = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,
saveChi=saveChi)
return data
def datared(folder,monitor=(0.5,4),showPlot=True,errMask=5,chi2Mask=2,
qlims=(0.5,3),withBaseline=False,forceDatared=False,
select=slice(None),**kw):
if isinstance(folder,int): folder = g_default_folder%folder
def_ext = id9.default_extension
data = azav(folder,withBaseline=withBaseline)
extension = def_ext if withBaseline else "_nobaseline" + def_ext
# storage files to use
diffFile = folder + "/diffs" + extension
azavFile = folder + "/pyfai_1d" + extension
if not os.path.exists(diffFile) or forceDatared:
data,diffs = id9.doFolder_dataRed(azavFile,monitor=monitor,
if not os.path.isfile(diffFile) or forceDatared:
data,diffs = id9.doFolder_dataRed(data,monitor=monitor,
errMask=errMask,chi2Mask=chi2Mask,qlims=qlims,
outStorageFile=diffFile)
else:

View File

@ -17,18 +17,12 @@ def readCalc():
calc = dict()
for name,fname in zip(names,fnames):
q,i=np.loadtxt(fold + "%s.xye.q"%fname,unpack=True)
calc[name] = xray.storage.DataStorage( dict( q=q, i=i ) )
calc[name] = dict( q=q, i=i )
return xray.storage.DataStorage(calc)
calc = readCalc()
def azav(folder,nQ=1500,force=False,saveChi=True,mask=470):
if isinstance(mask,int):
files = xray.utils.getFiles(folder,"*.edf*")
img = xray.azav.read(files[0])
temp = np.ones_like(img,dtype=bool)
temp[:mask] = False
mask = temp
def azav(folder,nQ=1500,force=False,saveChi=True,mask='y>470'):
return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
def datared(folder,monitor=(1,5),showPlot=True,**kw):

View File

@ -52,7 +52,7 @@ def doFolder_dataRed(azavStorage,monitor=None,funcForAveraging=np.nanmean,
if isinstance(azavStorage,storage.DataStorage):
data = azavStorage
folder = os.path.dirname(data.filename) if data.filename is not None else "./"
elif os.path.exists(azavStorage):
elif os.path.isfile(azavStorage):
folder = os.path.dirname(azavStorage)
data = storage.DataStorage(azavStorage)
else:

View File

@ -184,7 +184,7 @@ def saveTxt(fname,q,data,headerv=None,info=None,overwrite=True,columns=''):
info = dictionary (saved as '# key : value') or string
headerv = vector to be used as header or string
"""
if os.path.exists(fname) and not overwrite:
if os.path.isfile(fname) and not overwrite:
log.warn("File %s exists, returning",fname)
return
if isinstance(info,dict):