File indexing completed on 2026-04-09 07:48:46
0001
0002 """
0003
0004 ::
0005
0006 LV=box abprofile.py
0007 LV=box python2.7 abprofile.py
0008
0009
0010 ip abprofile.py --cat cvd_1_rtx_0_1M --pfx scan-pf-0 --tag 0
0011 OKG4Test run
0012
0013
0014 """
0015
0016 from __future__ import print_function
0017 import os, sys, logging, numpy as np
0018 log = logging.getLogger(__name__)
0019 from opticks.ana.profile_ import Profile
0020
0021
0022 class ABProfile(object):
0023 def __init__(self, adir, bdir ):
0024 assert not bdir is None
0025
0026 anam = os.path.basename(adir)
0027 bnam = os.path.basename(bdir)
0028 ag4 = anam[0] == "-"
0029 bg4 = bnam[0] == "-"
0030
0031 log.debug("adir %s anam %s ag4 %s" % (adir, anam, ag4))
0032 log.debug("bdir %s bnam %s bg4 %s" % (bdir, bnam, bg4))
0033
0034 log.debug("[ ab.pro.ap")
0035 self.ap = Profile(adir, "ab.pro.ap", g4=ag4)
0036 log.debug("]")
0037 log.debug("[ ab.pro.bp")
0038 self.bp = Profile(bdir, "ab.pro.bp", g4=bg4)
0039 log.debug("]")
0040
0041 valid = self.ap.valid and self.bp.valid
0042 if valid:
0043 boa = self.bp.tim/self.ap.tim if self.ap.tim > 0 else -1
0044 log.debug("self.bp.tim %s self.ap.tim %s boa %s" % (self.bp.tim, self.ap.tim, boa))
0045 else:
0046 boa = -2
0047 pass
0048 self.boa = boa
0049
0050 def _get_missing(self):
0051 return self.ap.missing or self.bp.missing
0052 missing = property(_get_missing)
0053
0054 def brief(self):
0055 return " ap.tim %-10.4f bp.tim %-10.4f bp.tim/ap.tim %-10.4f " % (self.ap.tim, self.bp.tim, self.boa )
0056
0057 def __repr__(self):
0058 return "\n".join(["ab.pro", self.brief()] + self.ap.lines() + self.bp.lines() )
0059
0060
0061
0062
0063 if __name__ == '__main__':
0064 from opticks.ana.main import opticks_main
0065 from opticks.ana.plot import init_rcParams
0066 import matplotlib.pyplot as plt
0067 init_rcParams(plt)
0068
0069 ok = opticks_main(doc=__doc__)
0070 log.info(ok.brief)
0071
0072 op = ABProfile(ok.tagdir)
0073 print(op)
0074
0075 ap = op.ap
0076 bp = op.bp
0077
0078 plt.plot( ap.t, ap.v, 'o' )
0079 plt.plot( bp.t, bp.v, 'o' )
0080
0081 plt.axvline( ap.t[ap.idx[0]], c="b" )
0082 plt.axvline( ap.t[ap.idx[1]], c="b" )
0083
0084 plt.axvline( bp.t[bp.idx[0]], c="r" )
0085 plt.axvline( bp.t[bp.idx[1]], c="r" )
0086
0087 plt.ion()
0088 plt.show()
0089
0090 log.info("tagdir: %s " % ok.tagdir)
0091