def calib(): # Test calib_constants here prior to user.py, which uses mpi # and tends to hang without error... # Use cxid9114 with run 96 (known to work) as a test case. exp = "cxid9114" run_no = 96 det_str = "cspad_0002" from psana.pscalib.calib.MDBWebUtils import calib_constants pedestals, _ = calib_constants(det_str, exp=exp, ctype='pedestals', run=run_no) assert pedestals.shape == (32, 185, 388) common_mode, _ = calib_constants(det_str, exp=exp, ctype='common_mode', run=run_no) assert commmon_mode.shape == (32, 185, 388) geometry_string, _ = calib_constants(det_str, exp=exp, ctype='geometry', run=run_no) try: if not isinstance(geometry_string, str) and geometry_string is not None: import unicodedata geometry_string = unicodedata.normalize('NFKD', geometry_string).encode( 'ascii', 'ignore') except Exception as e: raise ("Error getting geometry from calib_constants: %s" % e)
def test_calib_constants_directly(expname, runnum, detnameid): logger.info('in test_calib_constants_directly') from psana.pscalib.calib.MDBWebUtils import calib_constants #'pixel_rms', 'pixel_status', 'pedestals', 'pixel_gain', 'geometry' pedestals, _ = calib_constants(detnameid, exp=expname, ctype='pedestals', run=runnum) gain, _ = calib_constants(detnameid, exp=expname, ctype='pixel_gain', run=runnum) rms, _ = calib_constants(detnameid, exp=expname, ctype='pixel_rms', run=runnum) status, _ = calib_constants(detnameid, exp=expname, ctype='pixel_status', run=runnum) logger.info(info_ndarr(pedestals, 'pedestals')) logger.info(info_ndarr(gain, 'gain ')) logger.info(info_ndarr(rms, 'rms ')) logger.info(info_ndarr(status, 'status '))
def _get_calib(self, det_name): # this routine is hacked for Mona for exafel. it has # (at least) datagram/segment numbers that have been hardwired # to zero. - cpo gain_mask, pedestals, geometry_string, common_mode = None, None, None, None if self.exp and det_name: calib_dir = os.environ.get('PS_CALIB_DIR') if calib_dir: if os.path.exists(os.path.join(calib_dir, 'gain_mask.pickle')): gain_mask = pickle.load( open(os.path.join(calib_dir, 'gain_mask.pickle'), 'r')) from psana.pscalib.calib.MDBWebUtils import calib_constants try: det = eval('self.configs[0].software.%s[0]' % (det_name)) except: return {} # calib_constants takes det string (e.g. cspad_0001) with requested calib type. # as a hack (until detid in xtc files have been changed det_str = det.dettype + '_' + det.detid pedestals, _ = calib_constants(det_str, exp=self.exp, ctype='pedestals', run=self.run_no) geometry_string, _ = calib_constants(det_str, exp=self.exp, ctype='geometry', run=self.run_no) # python2 sees geometry_string as unicode (use str to check for compatibility py2/py3) # - convert to str accordingly if not isinstance(geometry_string, str) and geometry_string is not None: import unicodedata geometry_string = unicodedata.normalize( 'NFKD', geometry_string).encode('ascii', 'ignore') common_mode, _ = calib_constants(det_str, exp=self.exp, ctype='common_mode', run=self.run_no) calib = { 'gain_mask': gain_mask, 'pedestals': pedestals, 'geometry_string': geometry_string, 'common_mode': common_mode } return calib
def pixel_gain(self): if six.PY3 and not self._pixel_gain: self._pixel_gain = calib_constants(self.det, exp=self.exp, ctype="pixel_gain", run=self.run_num)[0] return self._pixel_gain
def pixel_status(self): if six.PY3 and not self._pixel_status: self._pixel_status = calib_constants(self.det, exp=self.exp, ctype="pixel_status", run=self.run_num)[0] return self._pixel_status
def pixel_bkgd(self): if six.PY3 and not self._pixel_bkgd: self._pixel_bkgd = calib_constants(self.det, exp=self.exp, ctype="pixel_bkgd", run=self.run_num)[0] return self._pixel_bkgd
def pixel_mask(self): if six.PY3 and not self._pixel_mask: self._pixel_mask = calib_constants(self.det, exp=self.exp, ctype="pixel_mask", run=self.run_num)[0] return self._pixel_mask
def pedestals(self): if six.PY3 and not self._pedestals: self._pedestals = calib_constants(self.det, exp=self.exp, ctype="pedestals", run=self.run_num)[0] return self._pedestals
def test_opal_data_access() : tname = sys.argv[1] if len(sys.argv) > 1 else '0' print('DIRECT ACCESS CALIBRATION CONSTANTS') from psana.pscalib.calib.MDBWebUtils import calib_constants data, doc = calib_constants('ele_opal_1234', exp='amox27716', ctype='pop_rbfs', run=85) print('direct consatnts access meta:\n', doc) print('\ndirect consatnts access data:') for k,v in data.items() : print_ndarr(v, '%03d : '%k) print('DETECTOR INTERFACE ACCESS CALIBRATION CONSTANTS') ds = DataSource(files='/reg/g/psdm/detector/data2_test/xtc/data-amox27716-r0085-opal1k.xtc2') orun = next(ds.runs()) camera = orun.Detector('opal') print('test_xtcav_data expt: %s runnum: %d\n' % (orun.expt, orun.runnum)) for nev,evt in enumerate(orun.events()): if nev>10 : break print('Event %03d'%nev, end='') ####print_ndarr(camera.raw.array(evt), ' camera.raw.array(evt):') #print_ndarr(camera.img(evt), ' camera.img(evt):') #print('XXXXX', evt._dgrams[0].xtcav[0].raw.raw) #print('XXXXX', dir(evt._dgrams[0].opal[0].raw.img)) print('***',camera.raw.image(evt)) break calib_data, calib_meta = camera.calibconst.get('pop_rbfs') print('camera.calibconst.get calib_meta', calib_meta)
def test_02(): from psana.pscalib.calib.MDBWebUtils import calib_constants data, doc = calib_constants('xtcav', exp='amox23616', ctype='xtcav_pedestals', run=131) #, time_sec=t0_sec, vers=None) print('data:', data) print('metadata:') for k, v in doc.items(): print('%16s : %s' % (k, v))
def reset_calib(self, run_num): """ Update calibration pixel effects based on new run number. """ old_stdout = sys.stdout f = six.StringIO() sys.stdout = f self.run_num = run_num if psana_version==1: try: pbits = 255 gcp = GenericCalibPars(self._get_cbase(), self.calibdir, self.group, self.source, self.run_num, pbits) self._pedestals = gcp.pedestals() self._pixel_rms = gcp.pixel_rms() self._pixel_mask = gcp.pixel_mask() self._pixel_bkgd = gcp.pixel_bkgd() self._pixel_status = gcp.pixel_status() self._pixel_gain = gcp.pixel_gain() except NotImplementedError: pass else: self._pedestals = calib_constants(self.det, exp=self.exp, ctype='pedestals', run=self.run_num)[0] self._pixel_rms = calib_constants(self.det, exp=self.exp, ctype='pixel_rms', run=self.run_num)[0] self._pixel_mask = calib_constants(self.det, exp=self.exp, ctype='pixel_mask', run=self.run_num)[0] self._pixel_bkgd = calib_constants(self.det, exp=self.exp, ctype='pixel_bkgd', run=self.run_num)[0] self._pixel_status = calib_constants(self.det, exp=self.exp, ctype='pixel_status', run=self.run_num)[0] self._pixel_gain = calib_constants(self.det, exp=self.exp, ctype='pixel_gain', run=self.run_num)[0] sys.stdout = old_stdout return
def get_calibconst(det, ctype='xtcav_pedestals', detname='xtcav', expname='amox23616', run_number=131): resp = det.calibconst.get(ctype) if resp is None : # try direct access logger.warning('ACCESS TO CALIB CONSTANTS "%s"' % ctype\ + ' VIA "%s" DETECTOR INTERFACE DOES NOT WORK, USE DIRECT ACESS' % detname) from psana.pscalib.calib.MDBWebUtils import calib_constants resp = calib_constants(detname, exp=expname, ctype=ctype, run=run_number) if resp is None : logger.warning('CAN NOT ACCESS CALIB CONSTANTS "%s" FOR DETECTOR "%s"' % (ctype, detname)) import sys sys.exit('EXIT - PROBLEM NEEDS TO BE FIXED...') #dark_data, dark_meta = resp return resp
def _get_calib_constants(self, name): _name = "_" + name attribute = getattr(self, _name) if six.PY3 and attribute is None and self.det is not None: # We haven't tried to get the calib_constant yet. attribute = calib_constants( self.det, exp=self.exp, ctype=name, run=self.run_num)[0] if attribute is None: # We still don't have it raise RuntimeError("No {} available for this detector" "".format(name)) setattr(self, _name, attribute) return attribute
from psana.pscalib.calib.MDBWebUtils import calib_constants pedestals = calib_constants('cspad_0002', exp='cxid9114', ctype='pedestals', run=96, time_sec=None, vers=None) print(pedestals.shape)