Ejemplo n.º 1
0
    def get_points(self):
        """
        All points in the block.
        """
        for axis, num in ordered_iteritems(self.n_slice):
            am = self._axis_map[axis]

            shape = np.array((self.resolution[0], self.resolution[1], num))
            pb = np.zeros((3,), dtype=np.object)
            for ii in range(3):
                pb[am[ii]] = np.linspace(0, self.dims[ii], shape[ii])

            if num > 1:
                delta = pb[am[2]][1] - pb[am[2]][0]
            else:
                delta = 0.0
            x1, x2 = np.meshgrid(pb[am[0]], pb[am[1]])
            x1 = x1.ravel()
            x2 = x2.ravel()

            points = np.empty((x1.shape[0], 3), dtype=np.float64)
            points[:,am[0]] = x1
            points[:,am[1]] = x2

            yield pb, points, delta, num, axis, am
Ejemplo n.º 2
0
def format_dict(d, raw=None, indent=2):
    """Format a dictionary for printing.

    Parameters:

        d : dict
            The dictionary.

        raw : dict
            The raw (unadjusted) dictionary to compare with.

        indent : int
            The indentation level.

    Return:

        msg : string
           The string with dictionary's key : val formatted in two columns.
    """
    if raw is None:
        raw = d

    msg = ''
    for key, val in ordered_iteritems(d):
        if val == raw[key]:
            msg += (' ' * indent) + ('%s : %s\n' % (key, val))
        else:
            msg += (' ' * indent) + ('%s : %s (%s)\n' % (key, val, raw[key]))

    msg = msg[:-1]

    return msg
Ejemplo n.º 3
0
Archivo: utils.py Proyecto: rc/gensei
def format_dict(d, raw=None, indent=2):
    """Format a dictionary for printing.

    Parameters:

        d : dict
            The dictionary.

        raw : dict
            The raw (unadjusted) dictionary to compare with.

        indent : int
            The indentation level.

    Return:

        msg : string
           The string with dictionary's key : val formatted in two columns.
    """
    if raw is None:
        raw = d
        
    msg = ''
    for key, val in ordered_iteritems(d):
        if val == raw[key]:
            msg += (' ' * indent) + ('%s : %s\n' % (key, val))
        else:
            msg += (' ' * indent) + ('%s : %s (%s)\n' % (key, val, raw[key]))

    msg = msg[:-1]

    return msg
Ejemplo n.º 4
0
    def report(self, filename):
        fd = self.fd_open(filename)

        if self.is_placed:
            Object.report(self, fd, header=False)
            fd.write('intersections per axis:\n')
            for axis, ints in ordered_iteritems(self.intersection_counters):
                fd.write('  %s (%d): %s\n' % (axis, len(ints), ints))
        else:
            fd.write(format_dict(self.conf.get_dict(),
                                 raw=self.requested_conf.get_dict()) + '\n')
            
        self.fd_close()
Ejemplo n.º 5
0
    def format_intersection_statistics(self, is_output=False):
        if is_output:
            space = ''
        else:
            space = '  '

        msg = []
        for axis, num in ordered_iteritems(self.box.n_slice):
            msg.append(space + 'axis %s (%d sections):' % (axis, num))
            ok = True
            for key, obj in ordered_iteritems(self):
                if not obj.has_intersection(axis):
                    msg.append(space + '  warning: object %s is not intersected'
                               % key)
                    ok = False
            if ok:
                msg.append(space
                           + '  all objects intersected by at least one section')

        if is_output:
            output('\n'.join(msg))

        return msg
Ejemplo n.º 6
0
    def report(self, filename):
        fd = self.fd_open(filename)

        if self.is_placed:
            Object.report(self, fd, header=False)
            fd.write('intersections per axis:\n')
            for axis, ints in ordered_iteritems(self.intersection_counters):
                fd.write('  %s (%d): %s\n' % (axis, len(ints), ints))
        else:
            fd.write(
                format_dict(self.conf.get_dict(),
                            raw=self.requested_conf.get_dict()) + '\n')

        self.fd_close()
Ejemplo n.º 7
0
    def format_statistics(self):
        units = self.box.units

        msg = [_dashes, 'statistics', _dashes]

        msg.append('  number of objects per class:')
        msg.append(format_dict(self.n_object, self.n_object_requested, 4))
        msg.append(_dashes)

        msg.append('  total object volume fraction:           %f' \
                   % self.total_object_volume_fraction)
        msg.append('  total object volume [(%s)^3]:           %f' \
                   % (units, self.total_object_volume))
        msg.append('  total object surface fraction [1/(%s)]: %f' \
                   % (units, self.total_object_surface_fraction))
        msg.append('  total object surface [(%s)^2]:          %f' \
                   % (units, self.total_object_surface))
        msg.append('  total object length density [1/(%s)^2]: %f' \
                   % (units, self.total_object_length_density))
        msg.append('  total object length [(%s)]:             %f' \
                   % (units, self.total_object_length))
        msg.append(_dashes)

        msg.append('  missed objects per axis:')
        missed = {}.fromkeys(self.box.n_slice.keys(), 0)
        for obj in self.itervalues():
            for axis, ints in obj.intersection_counters.iteritems():
                missed[axis] += len(ints) == 0
        for axis, val in ordered_iteritems(missed):
            msg.append('    %s: %d' % (axis, val))
        msg.extend(self.format_intersection_statistics())
        msg.append(_dashes)

        ipac = {}.fromkeys(self.box.n_slice.keys())
        for axis in ipac.iterkeys():
            volumes = self.section_volumes[axis]
            ipac[axis] = {}.fromkeys(volumes.keys(), 0)

        for key, obj in self.iteritems():
            for axis, ints in obj.intersection_counters.iteritems():
                val = len(ints)
                ipac[axis][obj.obj_class] += val

        msg.append('  intersections per class:')
        for axis, iac in ordered_iteritems(ipac):
            msg.append('    axis: %s' % axis)
            for key, ints in ordered_iteritems(iac):
                msg.append('      %s: % 3d average: %5.2f for %d objects' \
                           % (key, ints,
                              float(ints) / self.n_object[key],
                              self.n_object[key]))
        msg.append(_dashes)

        msg.append('  volumes per class:')
        for axis, volumes in ordered_iteritems(self.section_volumes):
            msg.append('    axis: %s' % axis)
            for key, val in ordered_iteritems(volumes):
                stats = self.stats_per_class[key]
                msg.append('      class: %s' % key)
                msg.append('        true volume V1 [(%s)^3]:          %f' \
                           % (units, stats.volume))
                msg.append('        section-based volume V2 [(%s)^3]: %f' \
                           % (units, val))
                msg.append('        true volume fraction:             %f' \
                           % (stats.volume / self.box.volume))
                msg.append('        section-based volume fraction:    %f' \
                           % (val / self.box.volume))
                msg.append('        ratio V2/V1 (accuracy estimate):  %f' \
                           % (val / stats.volume))
        msg.append(_dashes)

        msg.append('  surfaces per class:')
        for axis, surfaces in ordered_iteritems(self.section_surfaces):
            msg.append('    axis: %s' % axis)
            for key, val in ordered_iteritems(surfaces):
                stats = self.stats_per_class[key]
                msg.append('      class: %s' % key)
                msg.append('        true (approximate) surface S1 [(%s)^2]: %f' \
                           % (units, stats.surface))
                msg.append('        section-based surface S2 [(%s)^2]:      %f' \
                           % (units, val))
                msg.append('        true (approximate) surface fraction:    %f' \
                           % (stats.surface / self.box.volume))
                msg.append('        section surface fraction [1/(%s)]:      %f' \
                           % (units, val / self.box.volume))
                msg.append('        ratio S2/S1 (accuracy estimate):        %f' \
                           % (val / stats.surface))
        msg.append(_dashes)

        msg.append('  lengths per class:')
        for axis, iac in ordered_iteritems(ipac):
            msg.append('    axis: %s' % axis)
            for key, n_i in ordered_iteritems(iac):
                val = 2.0 * n_i /  self.box.get_area(axis) * self.box.volume
                val /= self.box.n_slice[axis]

                stats = self.stats_per_class[key]
                msg.append('      class: %s' % key)
                msg.append('        true length L1 [(%s)]:             %f' \
                           % (units, stats.length))
                msg.append('        section-based length L2 [(%s)]:    %f' \
                           % (units, val))
                msg.append('        true length density [1/(%s)^2]:    %f' \
                           % (units, stats.length / self.box.volume))
                msg.append('        section length density [1/(%s)^2]: %f' \
                           % (units, val / self.box.volume))
                msg.append('        ratio L2/L1 (accuracy estimate):   %f' \
                           % (val / stats.length))
        msg.append(_dashes)

        msg.append('  circumferences per object:')
        msg.append(_dashes)

        keys = [point[:2] for point in self.points]
        header = '|'.join([' %s:% 4d' % key for key in keys])
        msg.append('            ' + '|' + header + '|')
        coor = '|'.join(['%7.2f' % point[2] for point in self.points])
        msg.append('coordinate  ' + '|' + coor + '|')
        msg.append('-' * 12 + '--------' * len(keys))
        for name, circs in ordered_iteritems(self.section_circumferences):
            line = ['     '] * len(keys)
            for circ in circs:
                ic = keys.index(circ[:2])
                line[ic] = '%7.2f' % circ[-1]
            msg.append(name.ljust(12) + '|' + '|'.join(line) + '|')
#            import pdb; pdb.set_trace()
        msg.append(_dashes)


        return msg