def test_velocity(self): fig = plt.figure(num=None, figsize=(12, 8), dpi=100, facecolor='w', edgecolor='k') gs1 = gridspec.GridSpec(4, 1) plt.matplotlib.rcParams.update({'font.size': 14}) nm = 'rn300_R10_M3Mht3t30_Ni0_E003wAq2e3' path = '~/Sn/Release/svn_kepler/stella/branches/lucy/run/res/sncurve/rednovaM31/tt/' vels = vel.compute_vel(nm, os.path.expanduser(path)) ax = fig.add_subplot(gs1[:, 0]) vel.plot_vel(ax, vels) plt.show()
def run_scm(bands, distance, names, path, t50, t_beg, t_end, z): res = np.array(np.zeros(len(names)), dtype=np.dtype({'names': ['v'] + bands, 'formats': [np.float] * (1 + len(bands))})) im = 0 for name in names: vels = velocity.compute_vel(name, path, z=z, t_beg=t_beg, t_end=t_end) if vels is None: print "No enough data for %s " % name continue curves = light_curve_func.curves_compute(name, path, bands, z=z, distance=distance, t_beg=t_beg, t_end=t_end) v = extract_time(t50, vels['time'], vels['vel']) res[im]['v'] = v # dic_results[name]['v'] = v for bname in bands: m = extract_time(t50, curves.get(bname).Time, curves.get(bname).Mag) res[im][bname] = m print "Run: %s [%d/%d]" % (name, im + 1, len(names)) im += 1 res = res[res[:]['v'] > 0] return res
def main(name='', model_ext='.ph'): is_quiet = True is_save_mags = False is_save_plot = False is_plot_time_points = False is_extinction = False is_vel = False label = None fsave = None t_diff = 1.00001 # path = '' path = os.getcwd() z = 0 e = 0. magnification = 1. distance = 10. # pc callback = None xlim = None ylim = None # bshift = None bshift = {} try: opts, args = getopt.getopt(sys.argv[1:], "hqwtc:d:p:e:i:b:l:m:vs:x:y:z:") except getopt.GetoptError as err: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) if len(args) > 0: path, name = os.path.split(str(args[0])) path = os.path.expanduser(path) name = name.replace('.ph', '') elif len(opts) == 0: usage() sys.exit(2) if not name: for opt, arg in opts: if opt == '-i': name = os.path.splitext(os.path.basename(str(arg)))[0] break bands = ['U', 'B', 'V', 'R', "I"] # bands = ['U', 'B', 'V', 'R', "I", 'UVM2', "UVW1", "UVW2", 'g', "r", "i"] for opt, arg in opts: if opt == '-e': e = float(arg) is_extinction = True continue if opt == '-b': bands = [] band.Band.load_settings() for b in str(arg).split('-'): # extract band shift if ':' in b: bname, shift = b.split(':') if '_' in shift: bshift[bname] = -float(shift.replace('_', '')) else: bshift[bname] = float(shift) else: bname = b if not band.band_is_exist(bname): print 'No such band: ' + bname sys.exit(2) bands.append(bname) continue if opt == '-c': c = lc_wrapper(str(arg)) if callback is not None: c = cb.CallBackArray((callback, c)) callback = c continue if opt == '-q': is_quiet = False continue if opt == '-s': is_save_plot = True fsave = str.strip(arg) continue if opt == '-w': is_save_mags = True continue if opt == '-t': is_plot_time_points = True continue if opt == '-v': is_vel = True continue if opt == '-m': magnification = float(arg) continue if opt == '-z': z = float(arg) continue if opt == '-d': distance = float(arg) continue if opt == '-l': label = str.strip(arg) continue if opt == '-x': xlim = map(float, str(arg).split(':')) continue if opt == '-y': ylim = map(float, str(arg).split(':')) continue if opt == '-p': path = os.path.expanduser(str(arg)) if not (os.path.isdir(path) and os.path.exists(path)): print "No such directory: " + path sys.exit(2) continue elif opt == '-h': usage() sys.exit(2) print "Plot magnitudes on z=%f at distance=%e [cosmology D(z)=%s Mpc]" % (z, distance, cosmology_D_by_z(z)) names = [] if name != '': names.append(name) else: # run for all files in the path names = get_model_names(path, model_ext) if len(names) > 0: models_mags = {} # dict((k, None) for k in names) models_vels = {} # dict((k, None) for k in names) i = 0 for name in names: i += 1 # mags = lcf.compute_mag(name, path, bands, ext=ext, z=z, distance=distance, magnification=magnification, # t_diff=t_diff, is_show_info=not is_quiet, is_save=is_save_mags) curves = lcf.curves_compute(name, path, bands, z=z, distance=distance, magnification=magnification, is_save=is_save_mags) if is_extinction: lcf.curves_reddening(curves, ebv=e, z=z) # lcf.plot_curves(curves) # exit() # models_mags[name] = mags models_mags[name] = curves if not is_quiet: # z, distance = 0.145, 687.7e6 # pc for comparison with Maria # lcf.plot_bands(mags, bands, title=name, fname='', is_time_points=is_plot_time_points) lcf.plot_bands(curves, bands, title=name, fname='', is_time_points=is_plot_time_points) if is_vel: vels = vel.compute_vel(name, path, z=z) if vels is None: sys.exit("No data for: %s in %s" % (name, path)) models_vels[name] = vels print "Finish velocity: %s [%d/%d]" % (name, i, len(names)) else: models_vels = None print "Finish mags: %s [%d/%d] in %s" % (name, i, len(names), path) if label is None: if callback is not None: label = "ts=%s z=%4.2f D=%6.2e mu=%3.1f ebv=%4.2f" % ( callback.arg_totext(0), z, distance, magnification, e) else: label = "z=%4.2f D=%6.2e mu=%3.1f ebv=%4.2f" % (z, distance, magnification, e) if is_save_plot: if len(fsave) == 0: if is_vel: fsave = "ubv_vel_%s" % name else: fsave = "ubv_%s" % name if is_extinction and e > 0: fsave = "%s_e0%2d" % (fsave, int(e * 100)) # bad formula for name d = os.path.expanduser('~/') # d = '/home/bakl/Sn/my/conf/2016/snrefsdal/img' fsave = os.path.join(d, fsave) + '.pdf' plot_all(models_vels, models_mags, bands, call=callback, xlim=xlim, ylim=ylim, is_time_points=is_plot_time_points, title=label, fsave=fsave, bshift=bshift) # plot_all(dic_results, bands, xlim=(-10, 410), is_time_points=is_plot_time_points) # plot_all(dic_results, bands, xlim=(-10, 410), callback=callback, is_time_points=is_plot_time_points) # plot_all(dic_results, bands, ylim=(40, 23), is_time_points=is_plot_time_points) else: print "There are no models in the directory: %s with extension: %s " % (path, model_ext)