Ejemplo n.º 1
0
def main():
    parser = OptionParser(usage=usage)
    parser.add_option("-s", "--scale", metavar='scale',
                      action="store", dest="scale",
                      default=None, help=help['scale'])
    parser.add_option("-f", "--format", metavar='format',
                      action="store", type='string', dest="format",
                      default=None, help=help['format'])
    parser.add_option("-l", "--list", action="store_true", 
                      dest="list", help=help['list'])
    (options, args) = parser.parse_args()

    if options.list:
        output_writable_meshes()
        sys.exit(0)

    if len(args) != 2:
        parser.print_help()
        sys.exit(1)
    
    scale = options.scale
    if scale is not None:
        try:
            try:
                scale = float(scale)
            except ValueError:
                scale = [float(ii) for ii in scale.split(',')]
            scale = nm.array(scale, dtype=nm.float64, ndmin=1)
        except:
            output('bad scale! (%s)' % scale)
            parser.print_help()
            sys.exit(1)
        
    filename_in, filename_out = args
    
    mesh = Mesh.from_file(filename_in)

    if scale is not None:
        if len(scale) == 1:
            tr = nm.eye(mesh.dim, dtype=nm.float64) * scale
        elif len(scale) == mesh.dim:
            tr = nm.diag(scale)
        else:
            raise ValueError('bad scale! (%s)' % scale)
        mesh.transform_coors(tr)

    io = MeshIO.for_format(filename_out, format=options.format,
                           writable=True)

    output('writing %s...' % filename_out)
    mesh.write(filename_out, io=io)
    output('...done')
Ejemplo n.º 2
0
def _parse_val_or_vec(option, name, parser):
    if option is not None:
        try:
            try:
                option = float(option)
            except ValueError:
                option = [float(ii) for ii in option.split(',')]
            option = nm.array(option, dtype=nm.float64, ndmin=1)
        except:
            output('bad %s! (%s)' % (name, option))
            parser.print_help()
            sys.exit(1)

    return option
Ejemplo n.º 3
0
def _parse_val_or_vec(option, name, parser):
    if option is not None:
        try:
            try:
                option = float(option)
            except ValueError:
                option = [float(ii) for ii in option.split(',')]
            option = nm.array(option, dtype=nm.float64, ndmin=1)
        except:
            output('bad %s! (%s)' % (name, option))
            parser.print_help()
            sys.exit(1)

    return option
Ejemplo n.º 4
0
def main():
    parser = ArgumentParser(description=__doc__,
                            formatter_class=RawDescriptionHelpFormatter)
    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + sfepy.__version__)
    parser.add_argument('--debug',
                        action='store_true',
                        dest='debug',
                        default=False,
                        help=helps['debug'])

    group = parser.add_argument_group('Output Options')
    group.add_argument('-o',
                       '--output',
                       metavar='filename',
                       action='store',
                       dest='filename',
                       default=None,
                       help=helps['filename'])
    group.add_argument('--output-dir',
                       metavar='directory',
                       action='store',
                       dest='output_dir',
                       default=None,
                       help=helps['output_dir'])
    group.add_argument('-n',
                       '--no-show',
                       action='store_false',
                       dest='show',
                       default=True,
                       help=helps['no_show'])
    group.add_argument('--no-offscreen',
                       action='store_false',
                       dest='offscreen',
                       default=None,
                       help=helps['no_offscreen'])
    group.add_argument('-a',
                       '--animation',
                       metavar='<ffmpeg-supported format>',
                       action='store',
                       dest='anim_format',
                       default=None,
                       help=helps['anim_format'])
    group.add_argument('--ffmpeg-options',
                       metavar='<ffmpeg options>',
                       action='store',
                       dest='ffmpeg_options',
                       default='-framerate 10',
                       help=helps['ffmpeg_options'])

    group = parser.add_argument_group('Data Options')
    group.add_argument('--step',
                       type=int,
                       metavar='step',
                       action='store',
                       dest='step',
                       default=None,
                       help=helps['step'])
    group.add_argument('--time',
                       type=float,
                       metavar='time',
                       action='store',
                       dest='time',
                       default=None,
                       help=helps['time'])
    group.add_argument('-w',
                       '--watch',
                       action='store_true',
                       dest='watch',
                       default=False,
                       help=helps['watch'])
    group.add_argument('--all',
                       action='store_true',
                       dest='all',
                       default=False,
                       help=helps['all'])
    group.add_argument('--only-names',
                       metavar='list of names',
                       action='store',
                       dest='only_names',
                       default=None,
                       help=helps['only_names'])
    group.add_argument('-l',
                       '--list-ranges',
                       action='store_true',
                       dest='list_ranges',
                       default=False,
                       help=helps['list_ranges'])
    group.add_argument('--ranges',
                       type=str,
                       metavar='name1,min1,max1:name2,min2,max2:...',
                       action=ParseRanges,
                       dest='ranges',
                       help=helps['ranges'])

    group = parser.add_argument_group('View Options')
    group.add_argument('-r',
                       '--resolution',
                       type=str,
                       metavar='resolution',
                       action=ParseResolution,
                       dest='resolution',
                       help=helps['resolution'])
    group.add_argument('--layout',
                       metavar='layout',
                       action='store',
                       dest='layout',
                       default='rowcol',
                       help=helps['layout'])
    group.add_argument('--3d',
                       action='store_true',
                       dest='is_3d',
                       default=False,
                       help=helps['is_3d'])
    group.add_argument('--view',
                       type=str,
                       metavar='angle,angle[,distance[,focal_point]]',
                       action=ParseView,
                       dest='view',
                       help=helps['view'])
    group.add_argument('--roll',
                       type=float,
                       metavar='angle',
                       action='store',
                       dest='roll',
                       default=0.0,
                       help=helps['roll'])
    group.add_argument('--parallel-projection',
                       action='store_true',
                       dest='parallel_projection',
                       default=False,
                       help=helps['parallel_projection'])
    group.add_argument('--fgcolor',
                       metavar='R,G,B',
                       action='store',
                       dest='fgcolor',
                       default='0.0,0.0,0.0',
                       help=helps['fgcolor'])
    group.add_argument('--bgcolor',
                       metavar='R,G,B',
                       action='store',
                       dest='bgcolor',
                       default='1.0,1.0,1.0',
                       help=helps['bgcolor'])
    group.add_argument('--colormap',
                       metavar='colormap',
                       action='store',
                       dest='colormap',
                       default='blue-red',
                       help=helps['colormap'])
    group.add_argument('--anti-aliasing',
                       type=int,
                       metavar='value',
                       action='store',
                       dest='anti_aliasing',
                       default=None,
                       help=helps['anti_aliasing'])

    group = parser.add_argument_group('Custom Plots Options')
    group.add_argument('-b',
                       '--scalar-bar',
                       action='store_true',
                       dest='is_scalar_bar',
                       default=False,
                       help=helps['is_scalar_bar'])
    group.add_argument('--wireframe',
                       action='store_true',
                       dest='is_wireframe',
                       default=False,
                       help=helps['is_wireframe'])
    group.add_argument('--group-names',
                       type=str,
                       metavar='name1,...,nameN:...',
                       action=ParseGroupNames,
                       dest='group_names',
                       help=helps['group_names'])
    group.add_argument('--subdomains',
                       type=str,
                       metavar='mat_id_name,threshold_limits,single_color',
                       action=ParseSubdomains,
                       dest='subdomains_args',
                       default=None,
                       help=helps['subdomains'])
    group.add_argument('-d', '--domain-specific', type=str,
                       metavar='"var_name0,function_name0,' \
                       'par0=val0,par1=val1,...:var_name1,..."',
                       action=ParseDomainSpecific, dest='domain_specific',
                       default=None,
                       help=helps['domain_specific'])

    group = parser.add_argument_group('Mayavi Options')
    group.add_argument('--scalar-mode',
                       metavar='mode',
                       action='store',
                       dest='scalar_mode',
                       default='iso_surface',
                       help=helps['scalar_mode'])
    group.add_argument('--vector-mode',
                       metavar='mode',
                       action='store',
                       dest='vector_mode',
                       default='arrows_norm',
                       help=helps['vector_mode'])
    group.add_argument('-s',
                       '--scale-glyphs',
                       type=float,
                       metavar='scale',
                       action='store',
                       dest='rel_scaling',
                       default=0.05,
                       help=helps['rel_scaling'])
    group.add_argument('--clamping',
                       action='store_true',
                       dest='clamping',
                       default=False,
                       help=helps['clamping'])
    group.add_argument('--opacity',
                       type=str,
                       metavar='opacity',
                       action=ParseOpacity,
                       dest='opacity',
                       help=helps['opacity'])
    group.add_argument('--rel-text-width',
                       type=float,
                       metavar='width',
                       action='store',
                       dest='rel_text_width',
                       default=0.02,
                       help=helps['rel_text_width'])

    parser.add_argument('filenames', nargs='+')
    options = parser.parse_args()

    if options.debug:
        from sfepy.base.base import debug_on_error
        debug_on_error()

    filenames = options.filenames

    options.fgcolor = tuple([float(ii) for ii in options.fgcolor.split(',')])
    assert_(len(options.fgcolor) == 3)

    options.bgcolor = tuple([float(ii) for ii in options.bgcolor.split(',')])
    assert_(len(options.bgcolor) == 3)

    can_save = not options.show

    # Output dir / file names.
    if options.filename is None:
        can_save = False
        options.filename = 'view.png'
        if options.output_dir is None:
            options.output_dir = '.'

    else:
        options.output_dir, options.filename = os.path.split(options.filename)

    # Data filtering,
    if not options.all:
        filter_names = ['node_groups', 'mat_id']
    else:
        filter_names = []

    if options.anim_format is not None:
        # Do not call show when saving an animation.
        options.show = False

    if options.list_ranges:
        all_ranges = {}
        for ii, filename in enumerate(filenames):
            output('%d: %s' % (ii, filename))

            file_source = create_file_source(filename)
            if (options.step is None) and (options.time is None):
                steps, _ = file_source.get_ts_info()

            else:
                if options.step is not None:
                    step, _ = file_source.get_step_time(step=options.step)

                else:
                    step, _ = file_source.get_step_time(time=options.time)

                steps = [step]

            if not len(steps):
                steps = [0]

            for iis, step in enumerate(steps):
                output('%d: step %d' % (iis, step))
                file_source.get_step_time(step=step)
                source = file_source.create_source()
                ranges = get_data_ranges(source, return_only=True)
                for key, val in six.iteritems(ranges):
                    all_ranges.setdefault(key, []).append(val[3:])

        if (len(filenames) > 1) or (len(steps) > 1):
            output('union of ranges:')

        else:
            output('ranges:')

        for key, ranges in six.iteritems(all_ranges):
            aux = nm.array(ranges)
            mins = aux[:, [0, 2]].min(axis=0)
            maxs = aux[:, [1, 3]].max(axis=0)
            output('  items: %s,%e,%e' % (key, mins[0], maxs[0]))
            output('  norms: %s,%e,%e' % (key, mins[1], maxs[1]))

    else:
        if len(filenames) == 1:
            filenames = filenames[0]

        view = view_file(filenames, filter_names, options)
        if can_save:
            view.save_image(options.filename)

    if options.anim_format is not None:
        view.save_animation(options.filename)
        view.encode_animation(options.filename, options.anim_format,
                              options.ffmpeg_options)
Ejemplo n.º 5
0
def main():
    parser = OptionParser(usage=usage, version='%prog ' + sfepy.__version__)

    group = OptionGroup(parser, 'Output Options')
    group.add_option('-o', '--output', metavar='filename',
                     action='store', dest='filename',
                     default=None, help=help['filename'])
    group.add_option('--output-dir', metavar='directory',
                     action='store', dest='output_dir',
                     default=None, help=help['output_dir'])
    group.add_option('-n', '--no-show',
                     action='store_false', dest='show',
                     default=True, help=help['no_show'])
    group.add_option('', '--no-offscreen',
                     action='store_false', dest='offscreen',
                     default=None, help=help['no_offscreen'])
    group.add_option('-a', '--animation', metavar='<ffmpeg-supported format>',
                     action='store', dest='anim_format',
                     default=None, help=help['anim_format'])
    group.add_option('', '--ffmpeg-options', metavar='<ffmpeg options>',
                     action='store', dest='ffmpeg_options',
                     default='-r 10 -sameq',
                     help=help['ffmpeg_options'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Data Options')
    group.add_option('--step', type='int', metavar='step',
                     action='store', dest='step',
                     default=0, help=help['step'])
    group.add_option('-w', '--watch',
                     action='store_true', dest='watch',
                     default=False, help=help['watch'])
    group.add_option('--all',
                     action='store_true', dest='all',
                     default=False, help=help['all'])
    group.add_option('--only-names', metavar='list of names',
                     action='store', dest='only_names',
                     default=None, help=help['only_names'])
    group.add_option('-l', '--list-ranges',
                     action='store_true', dest='list_ranges',
                     default=False, help=help['list_ranges'])
    group.add_option('--ranges', type='str',
                     metavar='name1,min1,max1:name2,min2,max2:...',
                     action='callback', dest='ranges',
                     callback=parse_ranges, help=help['ranges'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'View Options')
    group.add_option('-r', '--resolution', type='str', metavar='resolution',
                     action='callback', dest='resolution',
                     callback=parse_resolution, help=help['resolution'])
    group.add_option('--layout', metavar='layout',
                     action='store', dest='layout',
                     default='rowcol', help=help['layout'])
    group.add_option('--3d',
                     action='store_true', dest='is_3d',
                     default=False, help=help['is_3d'])
    group.add_option('--view', type='str',
                     metavar='angle,angle[,distance[,focal_point]]',
                     action='callback', dest='view',
                     callback=parse_view, help=help['view'])
    group.add_option('--roll', type='float', metavar='angle',
                     action='store', dest='roll',
                     default=0.0, help=help['roll'])
    group.add_option('--fgcolor', metavar='R,G,B',
                     action='store', dest='fgcolor',
                     default='0.0,0.0,0.0', help=help['fgcolor'])
    group.add_option('--bgcolor', metavar='R,G,B',
                     action='store', dest='bgcolor',
                     default='1.0,1.0,1.0', help=help['bgcolor'])
    group.add_option('--anti-aliasing', type='int', metavar='value',
                     action='store', dest='anti_aliasing',
                     default=None, help=help['anti_aliasing'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Custom Plots Options')
    group.add_option('-b', '--scalar-bar',
                     action='store_true', dest='is_scalar_bar',
                     default=False, help=help['is_scalar_bar'])
    group.add_option('', '--wireframe',
                     action='store_true', dest='is_wireframe',
                     default=False, help=help['is_wireframe'])
    group.add_option('--group-names', type='str', metavar='name1,...,nameN:...',
                     action='callback', dest='group_names',
                     callback=parse_group_names, help=help['group_names'])
    group.add_option('--subdomains', type='str',
                     metavar='mat_id_name,threshold_limits,single_color',
                     action='callback', dest='subdomains_args',
                     callback=parse_subdomains, default=None,
                     help=help['subdomains'])
    group.add_option('-d', '--domain-specific', type='str',
                     metavar='"var_name0,function_name0,' \
                             'par0=val0,par1=val1,...:var_name1,..."',
                     action='callback', dest='domain_specific',
                     callback=parse_domain_specific, default=None,
                     help=help['domain_specific'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Mayavi Options')
    group.add_option('--scalar-mode', metavar='mode',
                     action='store', dest='scalar_mode',
                     default='iso_surface', help=help['scalar_mode'])
    group.add_option('--vector-mode', metavar='mode',
                     action='store', dest='vector_mode',
                     default='arrows_norm', help=help['vector_mode'])
    group.add_option('-s', '--scale-glyphs', type='float', metavar='scale',
                     action='store', dest='rel_scaling',
                     default=0.05, help=help['rel_scaling'])
    group.add_option('--clamping',
                     action='store_true', dest='clamping',
                     default=False, help=help['clamping'])
    group.add_option('--opacity', type='str', metavar='opacity',
                     action='callback', dest='opacity',
                     callback=parse_opacity, help=help['opacity'])
    group.add_option('--rel-text-width', type='float', metavar='width',
                     action='store', dest='rel_text_width',
                     default=0.02, help=help['rel_text_width'])
    parser.add_option_group(group)

    options, args = parser.parse_args()

    if len(args) >= 1:
        if len(args) == 1:
            filenames = glob.glob(args[0])
            filenames.sort()
        else:
            filenames = args
    else:
        parser.print_help(),
        return

    options.fgcolor = tuple([float(ii) for ii in
                             options.fgcolor.split(',')])
    assert_(len(options.fgcolor) == 3)

    options.bgcolor = tuple([float(ii) for ii in
                             options.bgcolor.split(',')])
    assert_(len(options.bgcolor) == 3)

    # Output dir / file names.
    if options.filename is None:
        options.filename = 'view.png'
        if options.output_dir is None:
            options.output_dir = '.'

    else:
        options.output_dir, options.filename = os.path.split(options.filename)

    # Data filtering,
    if not options.all:
        filter_names = ['node_groups', 'mat_id']
    else:
        filter_names = []

    if options.anim_format is not None:
        # Do not call show when saving an animation.
        options.show = False

    if options.list_ranges:
        all_ranges = {}
        for ii, filename in enumerate(filenames):
            output('%d: %s' % (ii, filename))

            file_source = create_file_source(filename)
            file_source.set_step(options.step)
            for key, val in get_data_ranges(file_source()).iteritems():
                all_ranges.setdefault(key, []).append(val[3:])

        if len(filenames) > 1:
            print 'summary of ranges:'
            for key, ranges in all_ranges.iteritems():
                aux = nm.array(ranges)
                print '  "%s": min(min): %s max(max): %s' % \
                      (key, aux[:,[0,2]].min(axis=0), aux[:,[1,3]].max(axis=0))

    else:
        if len(filenames) == 1:
            filenames = filenames[0]

        view = view_file(filenames, filter_names, options)

    if options.anim_format is not None:
        view.encode_animation(options.filename, options.anim_format,
                              options.ffmpeg_options)
Ejemplo n.º 6
0
def main():
    parser = OptionParser(usage=usage)
    parser.add_option("-s", "--scale", metavar="scale", action="store", dest="scale", default=None, help=help["scale"])
    parser.add_option(
        "-f",
        "--format",
        metavar="format",
        action="store",
        type="string",
        dest="format",
        default=None,
        help=help["format"],
    )
    parser.add_option("-l", "--list", action="store_true", dest="list", help=help["list"])
    (options, args) = parser.parse_args()

    if options.list:
        output_writable_meshes()
        sys.exit(0)

    if len(args) != 2:
        parser.print_help()
        sys.exit(1)

    scale = options.scale
    if scale is not None:
        try:
            try:
                scale = float(scale)
            except ValueError:
                scale = [float(ii) for ii in scale.split(",")]
            scale = nm.array(scale, dtype=nm.float64, ndmin=1)
        except:
            output("bad scale! (%s)" % scale)
            parser.print_help()
            sys.exit(1)

    filename_in, filename_out = args

    mesh = Mesh.from_file(filename_in)

    if scale is not None:
        if len(scale) == 1:
            tr = nm.eye(mesh.dim, dtype=nm.float64) * scale
        elif len(scale) == mesh.dim:
            tr = nm.diag(scale)
        else:
            raise ValueError("bad scale! (%s)" % scale)
        mesh.transform_coors(tr)

    io = "auto"
    if options.format:
        try:
            io = io_table[options.format](filename_out)
        except KeyError:
            output("unknown output mesh format! (%s)" % options.format)
            output_writable_meshes()
            sys.exit(1)

        if "w" not in supported_capabilities[options.format]:
            output("write support not implemented for output mesh format! (%s)" % options.format)
            output_writable_meshes()
            sys.exit(1)

    output("writing %s..." % filename_out)
    mesh.write(filename_out, io=io)
    output("...done")
Ejemplo n.º 7
0
def main():
    parser = OptionParser(usage=usage, version='%prog ' + sfepy.__version__)

    group = OptionGroup(parser, 'Output Options')
    group.add_option('-o',
                     '--output',
                     metavar='filename',
                     action='store',
                     dest='filename',
                     default=None,
                     help=help['filename'])
    group.add_option('--output-dir',
                     metavar='directory',
                     action='store',
                     dest='output_dir',
                     default=None,
                     help=help['output_dir'])
    group.add_option('-n',
                     '--no-show',
                     action='store_false',
                     dest='show',
                     default=True,
                     help=help['no_show'])
    group.add_option('',
                     '--no-offscreen',
                     action='store_false',
                     dest='offscreen',
                     default=None,
                     help=help['no_offscreen'])
    group.add_option('-a',
                     '--animation',
                     metavar='<ffmpeg-supported format>',
                     action='store',
                     dest='anim_format',
                     default=None,
                     help=help['anim_format'])
    group.add_option('',
                     '--ffmpeg-options',
                     metavar='<ffmpeg options>',
                     action='store',
                     dest='ffmpeg_options',
                     default='-r 10 -sameq',
                     help=help['ffmpeg_options'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Data Options')
    group.add_option('--step',
                     type='int',
                     metavar='step',
                     action='store',
                     dest='step',
                     default=0,
                     help=help['step'])
    group.add_option('-w',
                     '--watch',
                     action='store_true',
                     dest='watch',
                     default=False,
                     help=help['watch'])
    group.add_option('--all',
                     action='store_true',
                     dest='all',
                     default=False,
                     help=help['all'])
    group.add_option('--only-names',
                     metavar='list of names',
                     action='store',
                     dest='only_names',
                     default=None,
                     help=help['only_names'])
    group.add_option('-l',
                     '--list-ranges',
                     action='store_true',
                     dest='list_ranges',
                     default=False,
                     help=help['list_ranges'])
    group.add_option('--ranges',
                     type='str',
                     metavar='name1,min1,max1:name2,min2,max2:...',
                     action='callback',
                     dest='ranges',
                     callback=parse_ranges,
                     help=help['ranges'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'View Options')
    group.add_option('-r',
                     '--resolution',
                     type='str',
                     metavar='resolution',
                     action='callback',
                     dest='resolution',
                     callback=parse_resolution,
                     help=help['resolution'])
    group.add_option('--layout',
                     metavar='layout',
                     action='store',
                     dest='layout',
                     default='rowcol',
                     help=help['layout'])
    group.add_option('--3d',
                     action='store_true',
                     dest='is_3d',
                     default=False,
                     help=help['is_3d'])
    group.add_option('--view',
                     type='str',
                     metavar='angle,angle[,distance[,focal_point]]',
                     action='callback',
                     dest='view',
                     callback=parse_view,
                     help=help['view'])
    group.add_option('--roll',
                     type='float',
                     metavar='angle',
                     action='store',
                     dest='roll',
                     default=0.0,
                     help=help['roll'])
    group.add_option('--fgcolor',
                     metavar='R,G,B',
                     action='store',
                     dest='fgcolor',
                     default='0.0,0.0,0.0',
                     help=help['fgcolor'])
    group.add_option('--bgcolor',
                     metavar='R,G,B',
                     action='store',
                     dest='bgcolor',
                     default='1.0,1.0,1.0',
                     help=help['bgcolor'])
    group.add_option('--anti-aliasing',
                     type='int',
                     metavar='value',
                     action='store',
                     dest='anti_aliasing',
                     default=None,
                     help=help['anti_aliasing'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Custom Plots Options')
    group.add_option('-b',
                     '--scalar-bar',
                     action='store_true',
                     dest='is_scalar_bar',
                     default=False,
                     help=help['is_scalar_bar'])
    group.add_option('',
                     '--wireframe',
                     action='store_true',
                     dest='is_wireframe',
                     default=False,
                     help=help['is_wireframe'])
    group.add_option('--group-names',
                     type='str',
                     metavar='name1,...,nameN:...',
                     action='callback',
                     dest='group_names',
                     callback=parse_group_names,
                     help=help['group_names'])
    group.add_option('--subdomains',
                     type='str',
                     metavar='mat_id_name,threshold_limits,single_color',
                     action='callback',
                     dest='subdomains_args',
                     callback=parse_subdomains,
                     default=None,
                     help=help['subdomains'])
    group.add_option('-d', '--domain-specific', type='str',
                     metavar='"var_name0,function_name0,' \
                             'par0=val0,par1=val1,...:var_name1,..."',
                     action='callback', dest='domain_specific',
                     callback=parse_domain_specific, default=None,
                     help=help['domain_specific'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Mayavi Options')
    group.add_option('--scalar-mode',
                     metavar='mode',
                     action='store',
                     dest='scalar_mode',
                     default='iso_surface',
                     help=help['scalar_mode'])
    group.add_option('--vector-mode',
                     metavar='mode',
                     action='store',
                     dest='vector_mode',
                     default='arrows_norm',
                     help=help['vector_mode'])
    group.add_option('-s',
                     '--scale-glyphs',
                     type='float',
                     metavar='scale',
                     action='store',
                     dest='rel_scaling',
                     default=0.05,
                     help=help['rel_scaling'])
    group.add_option('--clamping',
                     action='store_true',
                     dest='clamping',
                     default=False,
                     help=help['clamping'])
    group.add_option('--opacity',
                     type='str',
                     metavar='opacity',
                     action='callback',
                     dest='opacity',
                     callback=parse_opacity,
                     help=help['opacity'])
    group.add_option('--rel-text-width',
                     type='float',
                     metavar='width',
                     action='store',
                     dest='rel_text_width',
                     default=0.02,
                     help=help['rel_text_width'])
    parser.add_option_group(group)

    options, args = parser.parse_args()

    if len(args) >= 1:
        if len(args) == 1:
            filenames = glob.glob(args[0])
            filenames.sort()
        else:
            filenames = args
    else:
        parser.print_help(),
        return

    options.fgcolor = tuple([float(ii) for ii in options.fgcolor.split(',')])
    assert_(len(options.fgcolor) == 3)

    options.bgcolor = tuple([float(ii) for ii in options.bgcolor.split(',')])
    assert_(len(options.bgcolor) == 3)

    # Output dir / file names.
    if options.filename is None:
        options.filename = 'view.png'
        if options.output_dir is None:
            options.output_dir = '.'

    else:
        options.output_dir, options.filename = os.path.split(options.filename)

    # Data filtering,
    if not options.all:
        filter_names = ['node_groups', 'mat_id']
    else:
        filter_names = []

    if options.anim_format is not None:
        # Do not call show when saving an animation.
        options.show = False

    if options.list_ranges:
        all_ranges = {}
        for ii, filename in enumerate(filenames):
            output('%d: %s' % (ii, filename))

            file_source = create_file_source(filename)
            file_source.set_step(options.step)
            for key, val in get_data_ranges(file_source()).iteritems():
                all_ranges.setdefault(key, []).append(val[3:])

        if len(filenames) > 1:
            print 'summary of ranges:'
            for key, ranges in all_ranges.iteritems():
                aux = nm.array(ranges)
                print '  "%s": min(min): %s max(max): %s' % \
                      (key, aux[:,[0,2]].min(axis=0), aux[:,[1,3]].max(axis=0))

    else:
        if len(filenames) == 1:
            filenames = filenames[0]

        view = view_file(filenames, filter_names, options)

    if options.anim_format is not None:
        view.encode_animation(options.filename, options.anim_format,
                              options.ffmpeg_options)
Ejemplo n.º 8
0
def main():
    parser = ArgumentParser(description=__doc__,
                            formatter_class=RawDescriptionHelpFormatter)
    parser.add_argument('--version', action='version',
                        version='%(prog)s ' + sfepy.__version__)
    parser.add_argument('--debug',
                        action='store_true', dest='debug',
                        default=False, help=helps['debug'])

    group = parser.add_argument_group('Output Options')
    group.add_argument('-o', '--output', metavar='filename',
                       action='store', dest='filename',
                       default=None, help=helps['filename'])
    group.add_argument('--output-dir', metavar='directory',
                       action='store', dest='output_dir',
                       default=None, help=helps['output_dir'])
    group.add_argument('-n', '--no-show',
                       action='store_false', dest='show',
                       default=True, help=helps['no_show'])
    group.add_argument('--no-offscreen',
                       action='store_false', dest='offscreen',
                       default=None, help=helps['no_offscreen'])
    group.add_argument('-a', '--animation',
                       metavar='<ffmpeg-supported format>', action='store',
                       dest='anim_format', default=None,
                       help=helps['anim_format'])
    group.add_argument('--ffmpeg-options', metavar='<ffmpeg options>',
                       action='store', dest='ffmpeg_options',
                       default='-r 10 -sameq',
                       help=helps['ffmpeg_options'])

    group = parser.add_argument_group('Data Options')
    group.add_argument('--step', type=int, metavar='step',
                       action='store', dest='step',
                       default=None, help=helps['step'])
    group.add_argument('--time', type=float, metavar='time',
                       action='store', dest='time',
                       default=None, help=helps['time'])
    group.add_argument('-w', '--watch',
                       action='store_true', dest='watch',
                       default=False, help=helps['watch'])
    group.add_argument('--all',
                       action='store_true', dest='all',
                       default=False, help=helps['all'])
    group.add_argument('--only-names', metavar='list of names',
                       action='store', dest='only_names',
                       default=None, help=helps['only_names'])
    group.add_argument('-l', '--list-ranges',
                       action='store_true', dest='list_ranges',
                       default=False, help=helps['list_ranges'])
    group.add_argument('--ranges', type=str,
                       metavar='name1,min1,max1:name2,min2,max2:...',
                       action=ParseRanges, dest='ranges',
                       help=helps['ranges'])

    group = parser.add_argument_group('View Options')
    group.add_argument('-r', '--resolution', type=str, metavar='resolution',
                       action=ParseResolution, dest='resolution',
                       help=helps['resolution'])
    group.add_argument('--layout', metavar='layout',
                       action='store', dest='layout',
                       default='rowcol', help=helps['layout'])
    group.add_argument('--3d',
                       action='store_true', dest='is_3d',
                       default=False, help=helps['is_3d'])
    group.add_argument('--view', type=str,
                       metavar='angle,angle[,distance[,focal_point]]',
                       action=ParseView, dest='view',
                       help=helps['view'])
    group.add_argument('--roll', type=float, metavar='angle',
                       action='store', dest='roll',
                       default=0.0, help=helps['roll'])
    group.add_argument('--parallel-projection',
                       action='store_true', dest='parallel_projection',
                       default=False, help=helps['parallel_projection'])
    group.add_argument('--fgcolor', metavar='R,G,B',
                       action='store', dest='fgcolor',
                       default='0.0,0.0,0.0', help=helps['fgcolor'])
    group.add_argument('--bgcolor', metavar='R,G,B',
                       action='store', dest='bgcolor',
                       default='1.0,1.0,1.0', help=helps['bgcolor'])
    group.add_argument('--colormap', metavar='colormap',
                       action='store', dest='colormap',
                       default='blue-red', help=helps['colormap'])
    group.add_argument('--anti-aliasing', type=int, metavar='value',
                       action='store', dest='anti_aliasing',
                       default=None, help=helps['anti_aliasing'])

    group = parser.add_argument_group('Custom Plots Options')
    group.add_argument('-b', '--scalar-bar',
                       action='store_true', dest='is_scalar_bar',
                       default=False, help=helps['is_scalar_bar'])
    group.add_argument('--wireframe',
                       action='store_true', dest='is_wireframe',
                       default=False, help=helps['is_wireframe'])
    group.add_argument('--group-names', type=str,
                       metavar='name1,...,nameN:...', action=ParseGroupNames,
                       dest='group_names', help=helps['group_names'])
    group.add_argument('--subdomains', type=str,
                       metavar='mat_id_name,threshold_limits,single_color',
                       action=ParseSubdomains, dest='subdomains_args',
                       default=None,
                       help=helps['subdomains'])
    group.add_argument('-d', '--domain-specific', type=str,
                       metavar='"var_name0,function_name0,' \
                       'par0=val0,par1=val1,...:var_name1,..."',
                       action=ParseDomainSpecific, dest='domain_specific',
                       default=None,
                       help=helps['domain_specific'])

    group = parser.add_argument_group('Mayavi Options')
    group.add_argument('--scalar-mode', metavar='mode',
                       action='store', dest='scalar_mode',
                       default='iso_surface', help=helps['scalar_mode'])
    group.add_argument('--vector-mode', metavar='mode',
                       action='store', dest='vector_mode',
                       default='arrows_norm', help=helps['vector_mode'])
    group.add_argument('-s', '--scale-glyphs', type=float, metavar='scale',
                       action='store', dest='rel_scaling',
                       default=0.05, help=helps['rel_scaling'])
    group.add_argument('--clamping',
                       action='store_true', dest='clamping',
                       default=False, help=helps['clamping'])
    group.add_argument('--opacity', type=str, metavar='opacity',
                       action=ParseOpacity, dest='opacity',
                       help=helps['opacity'])
    group.add_argument('--rel-text-width', type=float, metavar='width',
                       action='store', dest='rel_text_width',
                       default=0.02, help=helps['rel_text_width'])

    parser.add_argument('filenames', nargs='+')
    options = parser.parse_args()

    if options.debug:
        from sfepy.base.base import debug_on_error; debug_on_error()

    filenames = options.filenames

    options.fgcolor = tuple([float(ii) for ii in
                             options.fgcolor.split(',')])
    assert_(len(options.fgcolor) == 3)

    options.bgcolor = tuple([float(ii) for ii in
                             options.bgcolor.split(',')])
    assert_(len(options.bgcolor) == 3)

    can_save = not options.show

    # Output dir / file names.
    if options.filename is None:
        can_save = False
        options.filename = 'view.png'
        if options.output_dir is None:
            options.output_dir = '.'

    else:
        options.output_dir, options.filename = os.path.split(options.filename)

    # Data filtering,
    if not options.all:
        filter_names = ['node_groups', 'mat_id']
    else:
        filter_names = []

    if options.anim_format is not None:
        # Do not call show when saving an animation.
        options.show = False

    if options.list_ranges:
        all_ranges = {}
        for ii, filename in enumerate(filenames):
            output('%d: %s' % (ii, filename))

            file_source = create_file_source(filename)
            if (options.step is None) and (options.time is None):
                steps, _ = file_source.get_ts_info()

            else:
                if options.step is not None:
                    step, _ = file_source.get_step_time(step=options.step)

                else:
                    step, _ = file_source.get_step_time(time=options.time)

                steps = [step]

            if not len(steps):
                steps = [0]

            for iis, step in enumerate(steps):
                output('%d: step %d' %(iis, step))
                file_source.get_step_time(step=step)
                source = file_source.create_source()
                ranges = get_data_ranges(source, return_only=True)
                for key, val in six.iteritems(ranges):
                    all_ranges.setdefault(key, []).append(val[3:])

        if (len(filenames) > 1) or (len(steps) > 1):
            output('union of ranges:')

        else:
            output('ranges:')

        for key, ranges in six.iteritems(all_ranges):
            aux = nm.array(ranges)
            mins = aux[:, [0, 2]].min(axis=0)
            maxs = aux[:, [1, 3]].max(axis=0)
            output('  items: %s,%e,%e' % (key, mins[0], maxs[0]))
            output('  norms: %s,%e,%e' % (key, mins[1], maxs[1]))

    else:
        if len(filenames) == 1:
            filenames = filenames[0]

        view = view_file(filenames, filter_names, options)
        if can_save:
            view.save_image(options.filename)

    if options.anim_format is not None:
        view.save_animation(options.filename)
        view.encode_animation(options.filename, options.anim_format,
                              options.ffmpeg_options)
Ejemplo n.º 9
0
def main():
    parser = OptionParser(usage=usage)
    parser.add_option('-s', '--scale', metavar='scale',
                      action='store', dest='scale',
                      default=None, help=help['scale'])
    parser.add_option('-r', '--refine', metavar='level',
                      action='store', type=int, dest='refine',
                      default=0, help=help['refine'])
    parser.add_option('-f', '--format', metavar='format',
                      action='store', type='string', dest='format',
                      default=None, help=help['format'])
    parser.add_option('-l', '--list', action='store_true',
                      dest='list', help=help['list'])
    (options, args) = parser.parse_args()

    if options.list:
        output_writable_meshes()
        sys.exit(0)

    if len(args) != 2:
        parser.print_help()
        sys.exit(1)

    scale = options.scale
    if scale is not None:
        try:
            try:
                scale = float(scale)
            except ValueError:
                scale = [float(ii) for ii in scale.split(',')]
            scale = nm.array(scale, dtype=nm.float64, ndmin=1)
        except:
            output('bad scale! (%s)' % scale)
            parser.print_help()
            sys.exit(1)

    filename_in, filename_out = args

    mesh = Mesh.from_file(filename_in)

    if scale is not None:
        if len(scale) == 1:
            tr = nm.eye(mesh.dim, dtype=nm.float64) * scale
        elif len(scale) == mesh.dim:
            tr = nm.diag(scale)
        else:
            raise ValueError('bad scale! (%s)' % scale)
        mesh.transform_coors(tr)

    if options.refine > 0:
        domain = Domain(mesh.name, mesh)
        output('initial mesh: %d nodes %d elements'
               % (domain.shape.n_nod, domain.shape.n_el))

        for ii in range(options.refine):
            output('refine %d...' % ii)
            domain = domain.refine()
            output('... %d nodes %d elements'
                   % (domain.shape.n_nod, domain.shape.n_el))

        mesh = domain.mesh

    io = MeshIO.for_format(filename_out, format=options.format,
                           writable=True)

    output('writing %s...' % filename_out)
    mesh.write(filename_out, io=io)
    output('...done')
Ejemplo n.º 10
0
def main():
    parser = OptionParser(usage=usage, version="%prog " + sfepy.__version__)
    parser.add_option(
        "-l", "--list-ranges", action="store_true", dest="list_ranges", default=False, help=help["list_ranges"]
    )
    parser.add_option("-n", "--no-show", action="store_false", dest="show", default=True, help=help["no_show"])
    parser.add_option("--3d", action="store_true", dest="is_3d", default=False, help=help["is_3d"])
    parser.add_option(
        "--view",
        type="str",
        metavar="angle,angle",
        action="callback",
        dest="view",
        callback=parse_view,
        help=help["view"],
    )
    parser.add_option(
        "--roll", type="float", metavar="angle", action="store", dest="roll", default=0.0, help=help["roll"]
    )
    parser.add_option(
        "--layout", metavar="layout", action="store", dest="layout", default="rowcol", help=help["layout"]
    )
    parser.add_option(
        "--scalar-mode",
        metavar="mode",
        action="store",
        dest="scalar_mode",
        default="iso_surface",
        help=help["scalar_mode"],
    )
    parser.add_option(
        "--vector-mode",
        metavar="mode",
        action="store",
        dest="vector_mode",
        default="arrows_norm",
        help=help["vector_mode"],
    )
    parser.add_option(
        "-s",
        "--scale-glyphs",
        type="float",
        metavar="scale",
        action="store",
        dest="rel_scaling",
        default=0.05,
        help=help["rel_scaling"],
    )
    parser.add_option("--clamping", action="store_true", dest="clamping", default=False, help=help["clamping"])
    parser.add_option(
        "--ranges",
        type="str",
        metavar="name1,min1,max1:name2,min2,max2:...",
        action="callback",
        dest="ranges",
        callback=parse_ranges,
        help=help["ranges"],
    )
    parser.add_option(
        "-b", "--scalar-bar", action="store_true", dest="is_scalar_bar", default=False, help=help["is_scalar_bar"]
    )
    parser.add_option(
        "", "--wireframe", action="store_true", dest="is_wireframe", default=False, help=help["is_wireframe"]
    )
    parser.add_option(
        "--rel-text-width",
        type="float",
        metavar="width",
        action="store",
        dest="rel_text_width",
        default=0.02,
        help=help["rel_text_width"],
    )
    parser.add_option("-w", "--watch", action="store_true", dest="watch", default=False, help=help["watch"])
    parser.add_option(
        "-o", "--output", metavar="filename", action="store", dest="filename", default=None, help=help["filename"]
    )
    parser.add_option(
        "--output-dir", metavar="directory", action="store", dest="output_dir", default=None, help=help["output_dir"]
    )
    parser.add_option(
        "-a",
        "--animation",
        metavar="<ffmpeg-supported format>",
        action="store",
        dest="anim_format",
        default=None,
        help=help["anim_format"],
    )
    parser.add_option(
        "",
        "--ffmpeg-options",
        metavar='"<ffmpeg options>"',
        action="store",
        dest="ffmpeg_options",
        default="-r 10 -sameq",
        help=help["ffmpeg_options"],
    )
    parser.add_option(
        "-r",
        "--resolution",
        type="str",
        metavar="resolution",
        action="callback",
        dest="resolution",
        callback=parse_resolution,
        help=help["resolution"],
    )
    parser.add_option("--all", action="store_true", dest="all", default=False, help=help["all"])
    parser.add_option(
        "--only-names",
        metavar="list of names",
        action="store",
        dest="only_names",
        default=None,
        help=help["only_names"],
    )
    parser.add_option(
        "--group-names",
        type="str",
        metavar="name1,...,nameN:...",
        action="callback",
        dest="group_names",
        callback=parse_group_names,
        help=help["group_names"],
    )
    parser.add_option("--step", type="int", metavar="step", action="store", dest="step", default=0, help=help["step"])
    parser.add_option(
        "--anti-aliasing",
        type="int",
        metavar="value",
        action="store",
        dest="anti_aliasing",
        default=None,
        help=help["anti_aliasing"],
    )
    options, args = parser.parse_args()

    if len(args) >= 1:
        if len(args) == 1:
            filenames = glob.glob(args[0])
            filenames.sort()
        else:
            filenames = args
    else:
        parser.print_help(),
        return

    # Output dir / file names.
    if options.filename is None:
        options.filename = "view.png"
        if options.output_dir is None:
            options.output_dir = "."

    else:
        options.output_dir, options.filename = os.path.split(options.filename)

    # Data filtering,
    if not options.all:
        filter_names = ["node_groups", "mat_id"]
    else:
        filter_names = []

    if options.anim_format is not None:
        # Force the offscreen rendering when saving an animation.
        options.show = False

    if options.list_ranges:
        all_ranges = {}
        for ii, filename in enumerate(filenames):
            output("%d: %s" % (ii, filename))

            file_source = create_file_source(filename)
            file_source.set_step(options.step)
            for key, val in get_data_ranges(file_source()).iteritems():
                all_ranges.setdefault(key, []).append(val[3:])

        if len(filenames) > 1:
            print "summary of ranges:"
            for key, ranges in all_ranges.iteritems():
                aux = nm.array(ranges)
                print '  "%s": min(min): %s max(max): %s' % (
                    key,
                    aux[:, [0, 2]].min(axis=0),
                    aux[:, [1, 3]].max(axis=0),
                )

    else:
        if len(filenames) == 1:
            filenames = filenames[0]

        view = view_file(filenames, filter_names, options)

    if options.anim_format is not None:
        view.encode_animation(options.filename, options.anim_format, options.ffmpeg_options)