def main(): """ Log file format: par_name: par squared: <bool> header header f0 f1 flag_min f_min v_min flag_max f_max v_max kind desc """ parser = OptionParser( usage = usage, version = "%prog" ) parser.add_option( "-o", "", metavar = 'fig_name', action = "store", dest = "fig_name", default = 'band_gaps.png', help = help['fig_name'] ) parser.add_option( "-d", "--same-dir", metavar = 'same_dir', action = "store_true", dest = "same_dir", default = False, help = help['same_dir'] ) parser.add_option( "-g", "--grey", metavar = 'grey', action = "store_true", dest = "grey", default = False, help = help['grey'] ) options, args = parser.parse_args() if options.grey: plot_rsc = plot_rsc_grey else: plot_rsc = plot_rsc_color n_strips = len( args ) pylab.rcParams.update( plot_rsc['params'] ) fig = pylab.figure( 1 ) fig.clf() pars = [] for ii, arg in enumerate( args ): print arg fd = open( arg, 'r' ) par_name, par = fd.readline().split( ':' ) pars.append( '%.2f' % float( par ) ) squared = eval( fd.readline().split( ':' )[1] ) n_zeroed = eval( fd.readline().split( ':' )[1] ) n_eigs = eval( fd.readline().split( ':' )[1] ) print 'zeroed eigenmomenta: %d of %d' % (n_zeroed, n_eigs) # Skip gaps header. fd.readline() fd.readline() n_interval = int( fd.readline() ) freq_range = [] gaps = [] kinds = [] for ir in xrange( n_interval ): vv = fd.readline().split() desc = fd.readline() freq_range.append( float( vv[0] ) ) last_f = float( vv[1] ) gmin = (int( vv[2] ), float( vv[3] ), float( vv[4] )) gmax = (int( vv[5] ), float( vv[6] ), float( vv[7] )) gaps.append( (gmin, gmax) ) kinds.append( (vv[8], desc.strip()) ) freq_range.append( last_f ) freq_range = nm.array( freq_range ) # Skip resonances header. fd.readline() n_resonance = int( fd.readline() ) valid = [] resonances = [] n_valid = 0 for ir in xrange( n_resonance ): vv = fd.readline().split() valid.append( int( vv[0] ) ) if valid[-1]: n_valid += 1 resonances.append( float( vv[1] ) ) fd.close() ## print freq_range ## print gaps ## print kinds plot_gaps( 1, plot_rsc, gaps, kinds, freq_range, [ii-0.4, ii+0.4] ) plot_eigs( 1, plot_rsc, plot_labels, valid, resonances, [ii-0.4, ii+0.4] ) ax = fig.gca() ax.set_xlim( [freq_range[0], freq_range[-1]] ) ax.set_yticks( range( n_strips ) ) ax.set_yticklabels( pars ) ax.set_ylabel( par_name ) if squared: ax.set_xlabel( r'$\lambda$, $\omega^2$' ) else: ax.set_xlabel( r'$\sqrt{\lambda}$, $\omega$' ) pylab.axis( 'tight' ) print par_name fig_name = options.fig_name if options.same_dir: in_dir = op.split( args[0] )[0] fig_name = op.join( in_dir, op.split( fig_name )[1] ) fig.savefig( fig_name ) pylab.show()
def call( self ): """In parametric runs, cached data (homogenized coefficients, Christoffel acoustic tensor and eigenvalue problem solution) are cleared according to 'clear_cache' aplication options. Example: clear_cache = {'cached_christoffel' : True, 'cached_evp' : True} """ options = self.options for key, val in self.app_options.clear_cache.iteritems(): if val and key.startswith('cached_'): setattr(self, key, None) if options.phase_velocity: # No band gaps in this case. return self.compute_phase_velocity() evp = self.solve_eigen_problem() self.fix_eig_range( evp.eigs.shape[0] ) if options.detect_band_gaps: bg = detect_band_gaps( self.problem, evp.kind, evp.eigs_rescaled, evp.eig_vectors, self.app_options, self.conf.funmod ) if options.plot: plot_range, teigs = transform_plot_data( bg.logs.eigs, bg.opts.plot_transform, self.conf.funmod ) plot_rsc = bg.opts.plot_rsc plot_opts = bg.opts.plot_options plot_labels = bg.opts.plot_labels plt.rcParams.update( plot_rsc['params'] ) fig = plot_gaps( 1, plot_rsc, bg.gaps, bg.kinds, bg.freq_range_margins, plot_range, clear = True ) fig = plot_logs( 1, plot_rsc, plot_labels, bg.logs.freqs, teigs, bg.valid[bg.eig_range], bg.freq_range_initial, plot_range, False, show_legend = plot_opts['legend'], new_axes = True ) fig_name = bg.opts.fig_name if fig_name is not None: fig.savefig( fig_name ) if plot_opts['show']: plt.show() elif options.analyze_dispersion: christoffel, iw_dir = self.compute_cat(ret_iw_dir=True) bg = detect_band_gaps( self.problem, evp.kind, evp.eigs_rescaled, evp.eig_vectors, self.app_options, self.conf.funmod, christoffel = christoffel ) output( 'computing polarization angles...' ) pas = compute_polarization_angles( iw_dir, bg.logs.eig_vectors ) output( '...done' ) bg.polarization_angles = pas output( 'computing phase velocity...' ) bg.phase_velocity = self.compute_phase_velocity() output( '...done' ) if options.plot: plot_rsc = bg.opts.plot_rsc plot_opts = bg.opts.plot_options plt.rcParams.update( plot_rsc['params'] ) aux = transform_plot_data( pas, bg.opts.plot_transform_angle, self.conf.funmod ) plot_range, pas = aux plot_labels = bg.opts.plot_labels_angle fig = plot_gaps( 1, plot_rsc, bg.gaps, bg.kinds, bg.freq_range_margins, plot_range, clear = True ) fig = plot_logs( 1, plot_rsc, plot_labels, bg.logs.freqs, pas, bg.valid[bg.eig_range], bg.freq_range_initial, plot_range, False, show_legend = plot_opts['legend'], new_axes = True ) fig_name = bg.opts.fig_name_angle if fig_name is not None: fig.savefig( fig_name ) aux = transform_plot_data( bg.logs.eigs, bg.opts.plot_transform_wave, self.conf.funmod ) plot_range, teigs = aux plot_labels = bg.opts.plot_labels_wave fig = plot_gaps( 2, plot_rsc, bg.gaps, bg.kinds, bg.freq_range_margins, plot_range, clear = True ) fig = plot_logs( 2, plot_rsc, plot_labels, bg.logs.freqs, teigs, bg.valid[bg.eig_range], bg.freq_range_initial, plot_range, False, show_legend = plot_opts['legend'], new_axes = True ) fig_name = bg.opts.fig_name_wave if fig_name is not None: fig.savefig( fig_name ) if plot_opts['show']: plt.show() else: bg = None return evp, bg