updated xray examples and changed path.exists with isfile since this was what I meant
This commit is contained in:
		
							parent
							
								
									042c8d0ade
								
							
						
					
					
						commit
						6bb3c682df
					
				| 
						 | 
					@ -518,7 +518,7 @@ def downloadPDB(pdbID,outFileName=None):
 | 
				
			||||||
  if (outFileName is None):
 | 
					  if (outFileName is None):
 | 
				
			||||||
    outFileName = pdbID+".pdb"
 | 
					    outFileName = pdbID+".pdb"
 | 
				
			||||||
  folder = os.path.dirname(outFileName)
 | 
					  folder = os.path.dirname(outFileName)
 | 
				
			||||||
  if (folder != '' and not os.path.exists(folder)):
 | 
					  if (folder != '' and not os.path.isdir(folder)):
 | 
				
			||||||
    os.makedirs(folder)
 | 
					    os.makedirs(folder)
 | 
				
			||||||
  f=open(outFileName,"w")
 | 
					  f=open(outFileName,"w")
 | 
				
			||||||
  f.write( "".join(lines) )
 | 
					  f.write( "".join(lines) )
 | 
				
			||||||
| 
						 | 
					@ -1301,9 +1301,8 @@ def fac(n):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def define_colors(fname="colorbrewer_all_schemes.json"):
 | 
					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
 | 
					    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("Cannot find colorbrewer_all_schemes.json can't continue")
 | 
				
			||||||
    print(fname)
 | 
					    print(fname)
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,7 @@ class DataStorage(dict):
 | 
				
			||||||
    if isinstance(fileOrDict,dict):
 | 
					    if isinstance(fileOrDict,dict):
 | 
				
			||||||
      d = fileOrDict
 | 
					      d = fileOrDict
 | 
				
			||||||
    elif isinstance(fileOrDict,str):
 | 
					    elif isinstance(fileOrDict,str):
 | 
				
			||||||
      if os.path.exists(fileOrDict):
 | 
					      if os.path.isfile(fileOrDict):
 | 
				
			||||||
        d = read(fileOrDict)
 | 
					        d = read(fileOrDict)
 | 
				
			||||||
      else:
 | 
					      else:
 | 
				
			||||||
        self.filename=fileOrDict
 | 
					        self.filename=fileOrDict
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,7 +107,7 @@ def getAI(poni,folder=None):
 | 
				
			||||||
    ai = pyFAI.azimuthalIntegrator.AzimuthalIntegrator(**poni)
 | 
					    ai = pyFAI.azimuthalIntegrator.AzimuthalIntegrator(**poni)
 | 
				
			||||||
  elif isinstance(poni,str):
 | 
					  elif isinstance(poni,str):
 | 
				
			||||||
    # look is file exists in cwd
 | 
					    # look is file exists in cwd
 | 
				
			||||||
    if os.path.exists(poni):
 | 
					    if os.path.isfilee(poni):
 | 
				
			||||||
      ai = pyFAI.load(poni)
 | 
					      ai = pyFAI.load(poni)
 | 
				
			||||||
    # if file does not exist look for one with that name around
 | 
					    # if file does not exist look for one with that name around
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
| 
						 | 
					@ -123,7 +123,7 @@ def getAI(poni,folder=None):
 | 
				
			||||||
      # look for file
 | 
					      # look for file
 | 
				
			||||||
      for path in folders:
 | 
					      for path in folders:
 | 
				
			||||||
        fname = path + "/" + poni
 | 
					        fname = path + "/" + poni
 | 
				
			||||||
        if os.path.exists(fname):
 | 
					        if os.path.isfile(fname):
 | 
				
			||||||
          log.info("Found poni file %s",fname)
 | 
					          log.info("Found poni file %s",fname)
 | 
				
			||||||
          break
 | 
					          break
 | 
				
			||||||
        else:
 | 
					        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 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)
 | 
					    saved = storage.DataStorage(storageFile)
 | 
				
			||||||
  else:
 | 
					  else:
 | 
				
			||||||
    saved = None
 | 
					    saved = None
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,18 +55,15 @@ def prepareLog():
 | 
				
			||||||
prepareLog()
 | 
					prepareLog()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def defineCalibrants(dmin=3):
 | 
					def defineCalibrants(dmin=3):
 | 
				
			||||||
  from pyFAI import calibrant
 | 
					  c120 = xray.cell.Triclinic(a=10.297,b=10.716,c=13.955,alpha=72.22,beta=70.45,gamma=74.13)
 | 
				
			||||||
  c120 = calibrant.Cell(a=10.297,b=10.716,c=13.955,alpha=72.22,beta=70.45,gamma=74.13)
 | 
					  p120,_ = c120.reflection_list()
 | 
				
			||||||
  p120 = np.pi*2/ np.asarray( list(c120.d_spacing(dmin=dmin).keys()) ).astype(float)
 | 
					  c300 = xray.cell.Triclinic(a=10.485,b=11.015,c=14.280,alpha=74.61,beta=69.29,gamma=75.29)
 | 
				
			||||||
  p120.sort()
 | 
					  p300,_ = c300.reflection_list()
 | 
				
			||||||
  c300 = calibrant.Cell(a=10.485,b=11.015,c=14.280,alpha=74.61,beta=69.29,gamma=75.29)
 | 
					  return xray.storage.DataStorage( p120=p120, c120=c120,p300=p300,c300=c300) 
 | 
				
			||||||
  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) )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def readCalculations(folder="../fesalen/cif",force=False,plot=False):
 | 
					def readCalculations(folder="../fesalen/cif",force=False,plot=False):
 | 
				
			||||||
  npz = folder + "/fesalen_calc.npz"
 | 
					  npz = folder + "/fesalen_calc.npz"
 | 
				
			||||||
  if not os.path.exists(npz) or force:
 | 
					  if not os.path.isfile(npz) or force:
 | 
				
			||||||
    ret = dict()
 | 
					    ret = dict()
 | 
				
			||||||
    for T in ("120LS","200HS","300HS"):
 | 
					    for T in ("120LS","200HS","300HS"):
 | 
				
			||||||
      # calculated with lambda = 1 Ang
 | 
					      # 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):
 | 
					def removeBaseline(folder,qlims=(0.5,2.5),max_iter=30,force=False):
 | 
				
			||||||
  if isinstance(folder,int): folder = g_default_folder%folder
 | 
					  if isinstance(folder,int): folder = g_default_folder%folder
 | 
				
			||||||
  fname    = folder + "/pyfai_1d_nobaseline"+id9.default_extension
 | 
					  fname    = folder + "/pyfai_1d_nobaseline"+id9.default_extension
 | 
				
			||||||
  if not os.path.exists(fname) or force:
 | 
					  if not os.path.isfile(fname) or force:
 | 
				
			||||||
    data = azav(folder,doRemoveBaseline=False)
 | 
					    log.info("Calling azav with default parameters")
 | 
				
			||||||
 | 
					    data = azav(folder,withBaseline=False)
 | 
				
			||||||
    # first peak (around 0.6) is weak and requires special care ...
 | 
					    # first peak (around 0.6) is weak and requires special care ...
 | 
				
			||||||
    data.q,data.data = xray.utils.removeBackground(data.q,data.data,xlims=qlims,
 | 
					    data.q,data.data = xray.utils.removeBackground(data.q,data.data,
 | 
				
			||||||
                max_iter=max_iter,background_regions=[ (0,0.58) ])
 | 
					      xlims=qlims,max_iter=max_iter,background_regions=[ (0,0.58) ])
 | 
				
			||||||
    data.save(fname)
 | 
					    data.save(fname)
 | 
				
			||||||
  else:
 | 
					  else:
 | 
				
			||||||
    data = xray.storage.read(fname)
 | 
					    data = xray.storage.read(fname)
 | 
				
			||||||
  return data
 | 
					  return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def azav(folder,nQ=3000,force=False,saveChi=True,mask=g_default_mask,
 | 
					def azav(folder,nQ=3000,force=False,saveChi=True,mask=g_default_mask,
 | 
				
			||||||
         doRemoveBaseline=True):
 | 
					         withBaseline=True):
 | 
				
			||||||
  if isinstance(folder,int): folder = g_default_folder%folder
 | 
					  if withBaseline:
 | 
				
			||||||
  if isinstance(mask,int):
 | 
					    data=removeBaseline(folder)
 | 
				
			||||||
    files = xray.utils.getFiles(folder,"*.edf*")
 | 
					  else:
 | 
				
			||||||
    img   = xray.azav.pyFAIread(files[0])
 | 
					    data = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,
 | 
				
			||||||
    temp = np.ones_like(img,dtype=bool)
 | 
					      saveChi=saveChi)
 | 
				
			||||||
    temp[:mask] = False
 | 
					  return data
 | 
				
			||||||
    mask = temp
 | 
					 | 
				
			||||||
  azav = id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
 | 
					 | 
				
			||||||
  if doRemoveBaseline: removeBaseline(folder)
 | 
					 | 
				
			||||||
  return azav
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def datared(folder,monitor=(0.5,4),showPlot=True,errMask=5,chi2Mask=2,
 | 
					def datared(folder,monitor=(0.5,4),showPlot=True,errMask=5,chi2Mask=2,
 | 
				
			||||||
            qlims=(0.5,3),withBaseline=False,forceDatared=False,
 | 
					            qlims=(0.5,3),withBaseline=False,forceDatared=False,
 | 
				
			||||||
            select=slice(None),**kw):
 | 
					            select=slice(None),**kw):
 | 
				
			||||||
  if isinstance(folder,int): folder = g_default_folder%folder
 | 
					  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
 | 
					  extension = def_ext if withBaseline else "_nobaseline" + def_ext
 | 
				
			||||||
  # storage files to use
 | 
					  # storage files to use
 | 
				
			||||||
  diffFile = folder + "/diffs" + extension
 | 
					  diffFile = folder + "/diffs" + extension
 | 
				
			||||||
  azavFile = folder + "/pyfai_1d" + extension
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if not os.path.exists(diffFile) or forceDatared:
 | 
					  if not os.path.isfile(diffFile) or forceDatared:
 | 
				
			||||||
    data,diffs = id9.doFolder_dataRed(azavFile,monitor=monitor,
 | 
					    data,diffs = id9.doFolder_dataRed(data,monitor=monitor,
 | 
				
			||||||
                 errMask=errMask,chi2Mask=chi2Mask,qlims=qlims,
 | 
					                 errMask=errMask,chi2Mask=chi2Mask,qlims=qlims,
 | 
				
			||||||
                 outStorageFile=diffFile)
 | 
					                 outStorageFile=diffFile)
 | 
				
			||||||
  else:
 | 
					  else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,18 +17,12 @@ def readCalc():
 | 
				
			||||||
  calc = dict()
 | 
					  calc = dict()
 | 
				
			||||||
  for name,fname in zip(names,fnames):
 | 
					  for name,fname in zip(names,fnames):
 | 
				
			||||||
    q,i=np.loadtxt(fold + "%s.xye.q"%fname,unpack=True)
 | 
					    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)
 | 
					  return xray.storage.DataStorage(calc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
calc = readCalc()
 | 
					calc = readCalc()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def azav(folder,nQ=1500,force=False,saveChi=True,mask=470):
 | 
					def azav(folder,nQ=1500,force=False,saveChi=True,mask='y>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
 | 
					 | 
				
			||||||
  return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
 | 
					  return id9.doFolder_azav(folder,nQ=nQ,force=force,mask=mask,saveChi=saveChi)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def datared(folder,monitor=(1,5),showPlot=True,**kw):
 | 
					def datared(folder,monitor=(1,5),showPlot=True,**kw):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@ def doFolder_dataRed(azavStorage,monitor=None,funcForAveraging=np.nanmean,
 | 
				
			||||||
  if isinstance(azavStorage,storage.DataStorage):
 | 
					  if isinstance(azavStorage,storage.DataStorage):
 | 
				
			||||||
    data = azavStorage
 | 
					    data = azavStorage
 | 
				
			||||||
    folder = os.path.dirname(data.filename) if data.filename is not None else "./"
 | 
					    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)
 | 
					    folder = os.path.dirname(azavStorage)
 | 
				
			||||||
    data = storage.DataStorage(azavStorage)
 | 
					    data = storage.DataStorage(azavStorage)
 | 
				
			||||||
  else:
 | 
					  else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -184,7 +184,7 @@ def saveTxt(fname,q,data,headerv=None,info=None,overwrite=True,columns=''):
 | 
				
			||||||
        info = dictionary (saved as '# key : value') or string
 | 
					        info = dictionary (saved as '# key : value') or string
 | 
				
			||||||
        headerv = vector to be used as header 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)
 | 
					    log.warn("File %s exists, returning",fname)
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
  if isinstance(info,dict):
 | 
					  if isinstance(info,dict):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue