def deploy(self): with pg.BusyCursor(): # Calculate detector translation required in x and y dx = self.parent.pixelSize * 1e6 * (self.parent.roi.centreX - self.parent.cx) # microns dy = self.parent.pixelSize * 1e6 * (self.parent.roi.centreY - self.parent.cy) # microns dz = np.mean(-self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6 # microns geo = self.parent.det.geometry(self.parent.evt) top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=-dy, dy=-dx, dz=dz) fname = self.parent.psocakeRunDir + "/"+str(self.parent.runNumber)+'-end.data' geo.save_pars_in_file(fname) print("#################################################") print("Deploying psana detector geometry: ", fname) print("#################################################") cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'recentred geometry'} if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = self.parent.dir + '/' + self.parent.experimentName[:3] + '/' + \ self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre() # Show mask self.parent.mk.updatePsanaMaskOn()
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)
def deploy(self): with pg.BusyCursor(): # Calculate detector translation in x and y dx = self.parent.pixelSize * 1e6 * ( self.parent.cx - self.parent.roi.centreX) # microns dy = self.parent.pixelSize * 1e6 * ( self.parent.cy - self.parent.roi.centreY) # microns dz = np.mean(self.parent.det.coords_z(self.parent.evt) ) - self.parent.detectorDistance * 1e6 # microns geo = self.parent.det.geometry(self.parent.evt) if 'cspad' in self.parent.detInfo.lower( ) and 'cxi' in self.parent.experimentName: geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower( ) and 'mfx' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower( ) and 'xpp' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) else: print "deploy not implemented" fname = self.parent.psocakeRunDir + "/" + str( self.parent.runNumber) + '-end.data' geo.save_pars_in_file(fname) print "#################################################" print "Deploying psana detector geometry: ", fname print "#################################################" cmts = { 'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'recentred geometry' } if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = '/reg/d/psdm/' + self.parent.experimentName[: 3] + '/' + self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre()
def syncGeom(self): with pg.BusyCursor(): print "#################################################" print "Updating psana geometry with CrystFEL geometry" print "#################################################" self.parent.geom.findPsanaGeometry() psanaGeom = self.parent.psocakeRunDir + "/.temp.data" if self.parent.args.localCalib: cmd = [ "crystfel2psana", "-e", self.parent.experimentName, "-r", str(self.parent.runNumber), "-d", str(self.parent.det.name), "--rootDir", '.', "-c", self.geom, "-p", psanaGeom, "-z", str(self.parent.clen) ] else: cmd = [ "crystfel2psana", "-e", self.parent.experimentName, "-r", str(self.parent.runNumber), "-d", str(self.parent.det.name), "--rootDir", self.parent.rootDir, "-c", self.geom, "-p", psanaGeom, "-z", str(self.parent.clen) ] if self.parent.args.v >= 0: print "cmd: ", cmd p = subprocess.Popen(cmd, stdout=subprocess.PIPE) output = p.communicate()[0] p.stdout.close() # Reload new psana geometry cmts = { 'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'converted from crystfel geometry' } if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = '/reg/d/psdm/' + self.parent.experimentName[: 3] + '/' + self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=psanaGeom, dcmts=cmts, pbits=0) self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.parent.geom.updateRings() self.parent.index.updateIndex() self.parent.geom.drawCentre()
def autoDeploy(self): with pg.BusyCursor(): powderHits = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxHits.npy') powderMisses = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxMisses.npy') powderImg = self.parent.det.image(self.parent.evt, np.maximum(powderHits,powderMisses)) centreRow, centreCol = findDetectorCentre(np.log(abs(powderImg)), self.parent.cx, self.parent.cy, range=200) print("Current centre along row,centre along column: ", self.parent.cx, self.parent.cy) print("Optimum centre along row,centre along column: ", centreRow, centreCol) allowedDeviation = 175 # pixels if abs(self.parent.cx - centreRow) <= allowedDeviation and \ abs(self.parent.cy - centreCol) <= allowedDeviation: deploy = True else: deploy = False print "Too far away from current centre. I will not deploy the auto centred geometry." if deploy: # Calculate detector translation in x and y dx = self.parent.pixelSize * 1e6 * (self.parent.cx - centreRow) # microns dy = self.parent.pixelSize * 1e6 * (self.parent.cy - centreCol) # microns dz = np.mean(self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6 # microns geo = self.parent.det.geometry(self.parent.evt) if 'cspad' in self.parent.detInfo.lower() and 'cxi' in self.parent.experimentName: geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower() and 'mfx' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower() and 'xpp' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) else: print "autoDeploy not implemented" fname = self.parent.psocakeRunDir + "/" + str(self.parent.runNumber) + '-end.data' geo.save_pars_in_file(fname) print "#################################################" print "Deploying psana detector geometry: ", fname print "#################################################" cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'auto recentred geometry'} if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = '/reg/d/psdm/' + self.parent.experimentName[:3] + '/' + self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre()
def autoDeploy(self): with pg.BusyCursor(): powderHits = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxHits.npy') powderMisses = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxMisses.npy') powderImg = self.parent.det.image(self.parent.evt, np.maximum(powderHits,powderMisses)) centreRow, centreCol = findDetectorCentre(np.log(abs(powderImg)), self.parent.cx, self.parent.cy, range=200) print("Current centre along row,centre along column: ", self.parent.cx, self.parent.cy) print("Optimum centre along row,centre along column: ", centreRow, centreCol) allowedDeviation = 175 # pixels if abs(self.parent.cx - centreRow) <= allowedDeviation and \ abs(self.parent.cy - centreCol) <= allowedDeviation: deploy = True else: deploy = False print "Too far away from current centre. I will not deploy the auto centred geometry." if deploy: # Calculate detector translation in x and y dx = self.parent.pixelSize * 1e6 * (self.parent.cx - centreRow) # microns dy = self.parent.pixelSize * 1e6 * (self.parent.cy - centreCol) # microns dz = np.mean(self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6 # microns geo = self.parent.det.geometry(self.parent.evt) if 'cspad' in self.parent.detInfo.lower() and 'cxi' in self.parent.experimentName: geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower() and 'mfx' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower() and 'xpp' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) else: print "autoDeploy not implemented" fname = self.parent.psocakeRunDir + "/" + str(self.parent.runNumber) + '-end.data' geo.save_pars_in_file(fname) print "#################################################" print "Deploying psana detector geometry: ", fname print "#################################################" cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'auto recentred geometry'} if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = '/reg/d/psdm/' + self.parent.experimentName[:3] + '/' + self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre()
def autoDeploy(self): #FIXME: yet to verify this works correctly on new lab coordinate with pg.BusyCursor(): powderHits = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxHits.npy') powderMisses = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxMisses.npy') powderImg = self.parent.det.image(self.parent.evt, np.maximum(powderHits,powderMisses)) centreRow, centreCol = findDetectorCentre(np.log(abs(powderImg)), self.parent.cx, self.parent.cy, range=200) print("Current centre along row,centre along column: ", self.parent.cx, self.parent.cy) print("Optimum centre along row,centre along column: ", centreRow, centreCol) allowedDeviation = 175 # pixels if abs(self.parent.cx - centreRow) <= allowedDeviation and \ abs(self.parent.cy - centreCol) <= allowedDeviation: deploy = True else: deploy = False print("Too far away from current centre. I will not deploy the auto centred geometry.") if deploy: # Calculate detector translation in x and y dx = self.parent.pixelSize * 1e6 * (self.parent.cx - centreRow) # microns dy = self.parent.pixelSize * 1e6 * (self.parent.cy - centreCol) # microns dz = np.mean(-self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6 # microns dx = self.parent.pixelSize * 1e6 * (self.parent.roi.centreX - self.parent.cx) # microns dy = self.parent.pixelSize * 1e6 * (self.parent.roi.centreY - self.parent.cy) # microns dz = np.mean(-self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6 # microns geo = self.parent.det.geometry(self.parent.evt) top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=-dy, dy=-dx, dz=dz) fname = self.parent.psocakeRunDir + "/" + str(self.parent.runNumber) + '-end.data' geo.save_pars_in_file(fname) print("#################################################") print("Deploying psana detector geometry: ", fname) print("#################################################") cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'auto recentred geometry'} if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = self.parent.dir + '/' + self.parent.experimentName[:3] + '/' + self.parent.experimentName + \ '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre() # Show mask self.parent.mk.updatePsanaMaskOn()
def syncGeom(self): with pg.BusyCursor(): print "#################################################" print "Updating psana geometry with CrystFEL geometry" print "#################################################" self.parent.geom.findPsanaGeometry() psanaGeom = self.parent.psocakeRunDir + "/.temp.data" if self.parent.args.localCalib: cmd = ["crystfel2psana", "-e", self.parent.experimentName, "-r", str(self.parent.runNumber), "-d", str(self.parent.det.name), "--rootDir", '.', "-c", self.geom, "-p", psanaGeom, "-z", str(self.parent.clen)] else: cmd = ["crystfel2psana", "-e", self.parent.experimentName, "-r", str(self.parent.runNumber), "-d", str(self.parent.det.name), "--rootDir", self.parent.rootDir, "-c", self.geom, "-p", psanaGeom, "-z", str(self.parent.clen)] if self.parent.args.v >= 0: print "cmd: ", cmd p = subprocess.Popen(cmd, stdout=subprocess.PIPE) output = p.communicate()[0] p.stdout.close() # Reload new psana geometry cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'converted from crystfel geometry'} if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = '/reg/d/psdm/' + self.parent.experimentName[:3] + '/' + self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=psanaGeom, dcmts=cmts, pbits=0) self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.parent.geom.updateRings() self.parent.index.updateIndex() self.parent.geom.drawCentre()
def deploy(self): with pg.BusyCursor(): # Calculate detector translation in x and y dx = self.parent.pixelSize * 1e6 * (self.parent.cx - self.parent.roi.centreX) # microns dy = self.parent.pixelSize * 1e6 * (self.parent.cy - self.parent.roi.centreY) # microns dz = np.mean(self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance*1e6 # microns geo = self.parent.det.geometry(self.parent.evt) if 'cspad' in self.parent.detInfo.lower() and 'cxi' in self.parent.experimentName: geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower() and 'mfx' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower() and 'xpp' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) else: print "deploy not implemented" fname = self.parent.psocakeRunDir + "/"+str(self.parent.runNumber)+'-end.data' geo.save_pars_in_file(fname) print "#################################################" print "Deploying psana detector geometry: ", fname print "#################################################" cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'recentred geometry'} if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = '/reg/d/psdm/'+self.parent.experimentName[:3]+'/'+self.parent.experimentName+'/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre()
def deploy(self): with pg.BusyCursor(): if self.parent.facility == self.parent.facilityLCLS: # Calculate detector translation required in x and y dx = self.parent.pixelSize * 1e6 * ( self.parent.cx - self.parent.roi.centreX) # microns dy = self.parent.pixelSize * 1e6 * ( self.parent.cy - self.parent.roi.centreY) # microns dz = np.mean(self.parent.det.coords_z(self.parent.evt) ) - self.parent.detectorDistance * 1e6 # microns geo = self.parent.det.geometry(self.parent.evt) if 'cspad' in self.parent.detInfo.lower( ) and 'cxi' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'cspad' in self.parent.detInfo.lower( ) and 'mfx' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower( ) and 'mfx' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) elif 'rayonix' in self.parent.detInfo.lower( ) and 'xpp' in self.parent.experimentName: top = geo.get_top_geo() children = top.get_list_of_children()[0] geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz) else: print "deploy not implemented" fname = self.parent.psocakeRunDir + "/" + str( self.parent.runNumber) + '-end.data' geo.save_pars_in_file(fname) print "#################################################" print "Deploying psana detector geometry: ", fname print "#################################################" cmts = { 'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'recentred geometry' } if self.parent.args.localCalib: calibDir = './calib' elif self.parent.args.outDir is None: calibDir = self.parent.rootDir + '/calib' else: calibDir = self.parent.dir + '/' + self.parent.experimentName[:3] + '/' + \ self.parent.experimentName + '/calib' deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry', run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre() elif self.parent.facility == self.parent.facilityPAL: print "deploy::geom = ", self.parent.psocakeRunDir + '/.temp.geom' # deploy CrystFEL geometry with open(self.parent.psocakeRunDir + '/.temp.geom', 'r') as f: lines = f.readlines() for i, line in enumerate(lines): if 'clen' in line: lines[i] = 'clen = ' + str( self.parent.detectorDistance) + '\n' try: if 'p0/corner_x' in line: lines[i] = 'p0/corner_x = ' + str( -self.parent.roi.centreY) + '\n' if 'p0/corner_y' in line: lines[i] = 'p0/corner_y = ' + str( self.parent.roi.centreX) + '\n' except: pass fname = self.parent.rootDir + '/calib/' + self.parent.detInfo + '/geometry/' + \ str(self.parent.runNumber) + '-end.geom' # Make a backup of existing geometry if os.path.exists(fname): timeStr = datetime.datetime.now().isoformat() copyfile(fname, fname + '-' + timeStr) print "#################################################" print "Deploying detector geometry: ", fname print "#################################################" with open(fname, 'w') as f: f.writelines(lines) # Reload new psana geometry self.parent.exp.setupExperiment() self.parent.img.getDetImage(self.parent.eventNumber) self.updateRings() self.parent.index.updateIndex() self.drawCentre()