Exemplo n.º 1
0
    def setDefaultParams(self):
        params = experiparams(self.experimentName,
                              self.runNumber,
                              detectorName=self.detectorName,
                              outDir=self.outDir)
        params.setDefaultPsana()

        self.queue = 'psanaq'
        self.nodes = 1
        self.ncpus = 12
        self.outDir = params.cxiDir
        self.logFile = params.cxiDir + "/.%J.log"
        self.noe = -1
        self.jobName = "%s-r%.4d" % (params.experimentName, params.runNumber)

        ## peak finder algorithm params
        self.minPeaks = 15
        self.maxPeaks = 2048
        self.minRes = -1
        self.pkTag = ""

        ## mask params
        self.staticMask = params.cxiDir + '/staticMask.h5'
        self.userMask_path = None

        ## other params
        self.clen = params.clenEpics
        self.coffset = params.coffset
        self.instrument = params.instrument
        self.pixelSize = params.pixelSize
        self.detectorDistance = params.detectorDistance
Exemplo n.º 2
0
def deployCenter(experimentName, runNumber, detectorName, newCx, newCy):
    ## deploy the new geometry file
    ## Calculate detector translation in x and y
    ds = psana.DataSource("exp=" + experimentName + ":run=" + str(runNumber) +
                          ':idx')
    run = ds.runs().next()
    det = psana.Detector(detectorName)
    times = run.times()
    evt = None
    counter = 0
    while evt is None:
        evt = run.event(times[counter])  # guarantee we have a valid event
        counter += 1
    psanaCx, psanaCy = det.point_indexes(evt, pxy_um=(0, 0))
    pixelSize = det.pixel_size(evt)

    print "##### current psana center: ", psanaCx, psanaCy

    dx = pixelSize * (psanaCx - newCx)  # microns
    dy = pixelSize * (psanaCy - newCy)  # microns
    geo = det.geometry(evt)

    if 'cspad' in detectorName.lower() and 'cxi' in experimentName:
        geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=0)
    elif 'rayonix' in detectorName.lower() and 'mfx' in experimentName:
        top = geo.get_top_geo()
        children = top.get_list_of_children()[0]
        geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=0)
    elif 'rayonix' in detectorName.lower() and 'xpp' in experimentName:
        top = geo.get_top_geo()
        children = top.get_list_of_children()[0]
        geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=0)
    else:
        print "autoDeploy not implemented"

    params = experiparams(experimentName=experimentName,
                          runNumber=runNumber,
                          detectorName=detectorName)
    fname = params.cxiDir + "/" + str(runNumber) + '-end.data'
    print "fname: ", fname
    geo.save_pars_in_file(fname)
    print "#################################################"
    print "Deploying psana detector geometry: ", fname
    print "#################################################"
    cmts = {
        'exp': experimentName,
        'app': 'psocake',
        'comment': 'auto recentred geometry'
    }
    calibDir = '/reg/d/psdm/' + experimentName[:3] + '/' + experimentName + '/calib'
    deploy_calib_file(cdir=calibDir,
                      src=str(det.name),
                      type='geometry',
                      run_start=int(runNumber),
                      run_end=None,
                      ifname=fname,
                      dcmts=cmts,
                      pbits=0)
Exemplo n.º 3
0
 def loadPsanaGeo(self):
     self.params = experiparams(self.experimentName,
                                self.runNumber,
                                detectorName=self.detectorName)
     self.params.setDefaultPsana()
     self.detectorDistance = self.params.detectorDistance
     self.coffset = self.params.coffset
     self.clen = self.params.clen
     self.geomfile = self.params.cxiDir + "/.temp.geom"
Exemplo n.º 4
0
def runmaster(args):

    exprun = "exp="+str(args.exp)+":run="+str(args.run)
    
    ds = psana.DataSource(exprun+':idx')
    run = ds.runs().next()
    det = psana.Detector(args.det)
    times = run.times()
    
    evt = None
    counter = 0
    while evt is None:
        evt = run.event(times[counter]) 
        counter += 1

    max_img = None
    mean_img = None
    median_img = None 

    ## counter is a monitor to record how many images have been process in total
    ## nClients is the number of clients to process the data
    counter = 0.
    nClients = comm_size-1
    while nClients > 0:
        # Remove client if the run ended
        md = mpidata()
        md.recv()

        if max_img is None:
            max_img = md.max_img
            mean_img = md.mean_img
            median_img = md.median_img 
        else:
            max_img = np.maximum(max_img, md.max_img)
            mean_img = (mean_img * counter + md.mean_img * md.small.counter)*1.0/(counter + md.small.counter)

        counter = counter + md.small.counter
        nClients -= 1
    
    print "##### Total number of images: %s/%s " % (str(counter), str(args.noe))
    params = experiparams(experimentName=args.exp, runNumber=args.run, outDir=os.path.realpath(args.outDir))
    np.save(params.cxiDir+"/"+args.exp+"_"+str(args.run).zfill(4)+"_max_assem.npy", det.image(evt, max_img))
    np.save(params.cxiDir+"/"+args.exp+"_"+str(args.run).zfill(4)+"_max.npy", max_img)
    np.save(params.cxiDir+"/"+args.exp+"_"+str(args.run).zfill(4)+"_mean_assem.npy", det.image(evt, mean_img/counter))
    np.save(params.cxiDir+"/"+args.exp+"_"+str(args.run).zfill(4)+"_mean.npy", mean_img/counter)
    print "## saving the average powder pattern to: %s" % params.cxiDir
Exemplo n.º 5
0
def checkStartFiles(experimentName, runNumber):
    copyParams = experiparams(experimentName=experimentName,
                              runNumber=runNumber)
    cxiDir = copyParams.cxiDir

    status = True
    if cxiDir is None or not os.path.exists(cxiDir):
        print "@@@@@ cxiDir does not exist "
        status = False
    if not os.path.isfile(cxiDir + '/staticMask.h5'):
        print "@@@@@ statisMask.h5 is missing "
        status = False
    if not os.path.isfile(cxiDir + '/psanaMask.npy'):
        print "@@@@@ psanaMask.npy is missing "
        status = False
    if not os.path.isfile(cxiDir + "/.temp.geom"):
        print "@@@@@ .temp.geom is missing "
        status = False
    return status
Exemplo n.º 6
0
    def setDefaultParams(self):
        params = experiparams(self.experimentName,
                              self.runNumber,
                              detectorName=self.detectorName,
                              outDir=self.outDir)
        params.setDefaultPsana()

        self.queue = 'psanaq'
        ### TODO: psocake accept former directory as outDir
        self.outDir = params.outDir
        ### TODO: indexnoe is actually not implemented in psocake
        self.indexnoe = -1
        self.pkTag = ""
        self.instrument = params.instrument
        self.pixelSize = params.pixelSize
        self.pdbfile = None
        self.clenEpics = params.clenEpics
        self.likelihood = 0.
        self.tag = "index-" + utils.getTime()
Exemplo n.º 7
0
                    type=str)
args = parser.parse_args()

if args.det is None:
    from experiment import myExp
    runs = [args.run]
    exp = myExp(args.exp, runs[0])
    try:
        exp.Det
    except:
        pass
    args.det = exp.detName
    print args.det

if args.img is None and args.mask is None:
    params = experiparams(experimentName=args.exp, runNumber=args.run)
    args.img = params.cxiDir + "/" + args.exp + "_" + str(
        args.run).zfill(4) + "_" + str(args.det) + "_mean_assem.npy"
    args.mask = params.cxiDir + "/psanaMask.npy"

image = np.load(args.img)

# assem
if args.assem:
    evt, det = experiparams.expdet(args.exp, args.run, args.det)
    if evt is None or det is None:
        pass
    else:
        image = det.image(evt, image)

if args.mask is not None and os.path.isfile(args.mask):
Exemplo n.º 8
0
def setupNewRun(experimentName=None,
                runNumber=None,
                detectorName=None,
                outDir=None,
                copyRun=None):

    params = experiparams(experimentName=experimentName,
                          runNumber=runNumber,
                          detectorName=detectorName,
                          outDir=outDir)
    copyParams = experiparams(experimentName=experimentName,
                              runNumber=copyRun,
                              detectorName=detectorName,
                              outDir=outDir)
    if not os.path.isdir(params.cxiDir):
        print params.cxiDir
        os.makedirs(params.cxiDir)

    if copyRun is not None:
        status = checkStartFiles(experimentName, copyRun)
        if status:
            from shutil import copyfile
            copyfile(src=copyParams.cxiDir + '/staticMask.h5',
                     dst=params.cxiDir + '/staticMask.h5')
            copyfile(src=copyParams.cxiDir + '/psanaMask.npy',
                     dst=params.cxiDir + '/psanaMask.npy')
            copyfile(src=copyParams.cxiDir + "/.temp.geom",
                     dst=params.cxiDir + "/.temp.geom")
            copyfile(src=copyParams.cxiDir + "/.temp.geom",
                     dst=params.cxiDir + "/temp.geom")
            print "##### copy file from run %d to %d" % (copyRun, runNumber)
            return True

    # get the psana mask from the psana server
    unassem_img, assem_img = loadPsanaMask(experimentName, runNumber,
                                           detectorName)
    np.save(params.cxiDir + '/psanaMask.npy', assem_img)
    print "##### save psanaMask: ", params.cxiDir + '/psanaMask.npy'

    ## save unassem_img to cheetah mask
    saveCheetahStaticMask(unassem_img, experimentName, detectorName,
                          params.cxiDir + '/staticMask.h5')
    print "##### save cheetah mask: ", params.cxiDir + '/staticMask.h5'

    ## load psana geometry
    calibFile = findPsanaGeometry(experimentName, runNumber, detectorName)
    print "##### load calibFile: ", calibFile

    ############################
    # Sometimes the geom file is not compatible with psocake, we need to modify a little bit
    fgeom = params.cxiDir + "/temp.geom"
    CalibFileToGeomFile(calibFile, detectorName, fgeom)
    print "##### convert calibFile to geometry file"

    ## load geom file and make a copy to .temp.geom
    f = open(fgeom)
    lines = f.readlines()
    f.close()

    f = open(params.cxiDir + "/.temp.geom", 'w')
    params.setDefaultPsana()

    for i in lines:
        #if 'mask' in i:
        #    f1.write(';'+i)
        if 'clen' in i:
            f.write(i.split(';')[-1])
        elif 'coffset' in i:
            f.write(i.split('=')[0] + "= " + str(params.coffset) + '\n')
        else:
            f.write(i)
    f.close()

    return True