Пример #1
0
def test_save_log_record_at_start():
    """save_log_record_at_start(dirrepo, procname, dirmode=0o777, filemode=0o666, tsfmt='%Y-%m-%dT%H:%M:%S%z', scrname='nondef_scrname')
   """
    dirrepo = '/a/b/c/d'
    procname = 'test_procname'
    scrname = 'test_scrname'
    ut.save_log_record_at_start(dirrepo, procname, scrname=scrname)
Пример #2
0
 def __init__(self, dirrepo, **kwa):
     self.dirrepo = dirrepo.rstrip('/')
     self.dirmode = kwa.get('dirmode', 0o777)
     self.filemode = kwa.get('filemode', 0o666)
     self.umask = kwa.get('umask', 0o0)
     self.dirname_log = kwa.get('dirname_log', 'logs')
     self.year = kwa.get('year', ut.str_tstamp(fmt='%Y'))
     self.tstamp = kwa.get('tstamp', ut.str_tstamp(fmt='%Y-%m-%dT%H%M%S'))
     self.dettype = kwa.get('dettype', None)
     if self.dettype is not None: self.dirrepo += '/%s' % self.dettype
     self.dir_log_at_start = kwa.get('dir_log_at_start', DIR_LOG_AT_START)
Пример #3
0
 def cons_and_meta_for_ctype(self, ctype='pedestals'):
     logger.debug('cons_and_meta_for_ctype(ctype="%s")'%ctype)
     cc = self.calibconst()
     if cc is None: return None
     cons_and_meta = cc.get(ctype, None)
     if ut.is_none(cons_and_meta, 'calibconst["%s"] is None'%ctype): return None, None
     return cons_and_meta
Пример #4
0
 def geotxt_and_meta(self):
     logger.debug('geotxt_and_meta')
     cc = self.calibconst()
     if cc is None: return None
     geotxt_and_meta = cc.get('geometry', None)
     if ut.is_none(geotxt_and_meta, 'calibconst[geometry] is None'): return None, None
     return geotxt_and_meta
Пример #5
0
 def segment_numbers_total(self):
     """returns total list list of segment numbers."""
     nsegs = self.number_of_segments_total()
     segnums = None if ut.is_none(nsegs, 'number_of_segments_total is None') else\
               list(range(nsegs))
               #tuple(np.arange(nsegs, dtype=np.uint16))
     logger.debug('segnums: %s' % str(segnums))
     return segnums
Пример #6
0
    def image(self, nda, segnums=None, **kwa):
        """
        Create 2-d image.

        Parameters
        ----------
        nda: np.array, ndim=3
            array shaped as daq raw data.

        segnums: list/tuple of segment (uint) indexes

        mapmode: int, optional, default: 2
            control on overlapping pixels on image map.
            0/1/2/3/4: statistics of entries / last / max / mean pixel intensity / interpolated (TBD) - ascending data index.

        fillholes: bool, optional, default: True
            control on map bins inside the panel with 0 entries from data.
            True/False: fill empty bin with minimal intensity of four neares neighbors/ do not fill.

        vbase: float, optional, default: 0
            value substituted for all image map bins without entry from data.

        Returns
        -------
        image: np.array, ndim=2
        """
        logger.debug('in CalibConstants.image')

        if any(v is None for v in self._pix_rc):
            self.cached_pixel_coord_indexes(segnums, **kwa)
            if any(v is None for v in self._pix_rc): return None

        vbase     = kwa.get('vbase',0)
        mapmode   = kwa.get('mapmode',2)
        fillholes = kwa.get('fillholes',True)

        if mapmode==0: return self.img_entries

        if ut.is_none(nda, 'CalibConstants.image calib returns None'): return None

        logger.debug(info_ndarr(nda, 'nda ', last=3))
        rows, cols = self._pix_rc
        logger.debug(info_ndarr(rows, 'rows ', last=3))
        logger.debug(info_ndarr(cols, 'cols ', last=3))

        img = img_from_pixel_arrays(rows, cols, weight=nda, vbase=vbase) # mapmode==1
        if   mapmode==2: img_multipixel_max(img, nda, self.dmulti_pix_to_img_idx)
        elif mapmode==3: img_multipixel_mean(img, nda, self.dmulti_pix_to_img_idx, self.dmulti_imgidx_numentries)

        if mapmode<4 and fillholes: fill_holes(img, self.hole_rows, self.hole_cols)

        return img if mapmode<4 else\
               img_interpolated(nda, self._cached_interpol_pars()) if mapmode==4 else\
               self.img_entries
Пример #7
0
    def pixel_coords(self, **kwa):
        """ returns x, y, z - three np.ndarray
        """
        logger.debug('pixel_coords')
        geo = self.geo()
        if ut.is_none(geo, 'geo is None'): return None

        #return geo.get_pixel_xy_at_z(self, zplane=None, oname=None, oindex=0, do_tilt=True, cframe=0)
        return geo.get_pixel_coords(\
            do_tilt            = kwa.get('do_tilt',True),\
            cframe             = kwa.get('cframe',0))
Пример #8
0
 def geo(self):
     """ return GeometryAccess() object
     """
     if self._geo is None:
         geotxt, meta = self.geotxt_and_meta()
         if geotxt is None:
             geotxt = self.geotxt_default()
             if ut.is_none(geotxt, 'geo geotxt is None'): return None
         self._geo = GeometryAccess()
         self._geo.load_pars_from_str(geotxt)
     return self._geo
Пример #9
0
    def pixel_coord_indexes(self, **kwa):
        """ returns ix, iy - two np.ndarray
        """
        logger.debug('pixel_coord_indexes')
        geo = self.geo()
        if ut.is_none(geo, 'geo is None'): return None

        return geo.get_pixel_coord_indexes(\
            pix_scale_size_um  = kwa.get('pix_scale_size_um',None),\
            xy0_off_pix        = kwa.get('xy0_off_pix',None),\
            do_tilt            = kwa.get('do_tilt',True),\
            cframe             = kwa.get('cframe',0))
Пример #10
0
 def calibconst(self):
     logger.debug('calibconst')
     cc = self._calibconst
     if ut.is_none(cc, 'self._calibconst is None'): return None
     return cc
Пример #11
0
 def seg_geo(self):
     logger.debug('pixel_coords')
     geo = self.geo()
     if ut.is_none(geo, 'geo is None'): return None
     return None if ut.is_none(geo, 'geo is None') else\
            geo.get_seg_geo().algo
Пример #12
0
 def shape_as_daq(self):
     peds = self.pedestals()
     if ut.is_none(peds, 'shape_as_daq - pedestals is None, can not define daq data shape - returns None'): return None
     return peds.shape if peds.ndim<4 else peds.shape[-3:]
Пример #13
0
 def makedir(self, d):
     """create and return directory d with mode defined in object property"""
     ut.create_directory(d, self.dirmode, umask=self.umask)
     return d
Пример #14
0
 def save_record_at_start(self, procname, tsfmt='%Y-%m-%dT%H:%M:%S%z'):
     ut.save_record_at_start(self, procname, tsfmt=tsfmt)
Пример #15
0
                                     procname)

    def dir_log_at_start_year(self):
        """return directory <dirlog_at_start>/<year>"""
        return os.path.join(self.dir_log_at_start, self.year)

    def makedir_log_at_start_year(self):
        """create and return directory"""
        return self.makedir(self.dir_log_at_start_year())

    def logname_at_start(self, procname):
        return '%s/%s_logrec_%s.txt' % (self.makedir_log_at_start_year(),
                                        self.year, procname)

    def save_record_at_start(self, procname, tsfmt='%Y-%m-%dT%H:%M:%S%z'):
        ut.save_record_at_start(self, procname, tsfmt=tsfmt)


if __name__ == "__main__":
    dirrepo = './work'
    fname = 'testfname'
    procname = 'testproc-%s' % ut.get_login()
    repoman = RepoManager(dirrepo, dirmode=0o777, filemode=0o666)
    print('makedir_logs %s' % repoman.makedir_logs())
    print('logname %s' % repoman.logname(procname))
    print('makedir_constants %s' % repoman.makedir_constants())
    print('logname_at_start %s' % repoman.logname_at_start(fname))
    repoman.save_record_at_start('test_of_RepoManager')

# EOF