Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo n.º 3
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