f.init() print "generated discrete dynamics" # Allocate memory u = copy.deepcopy(u0) v = copy.deepcopy(v0) h = copy.deepcopy(h0) # Prepare plotting if plot_progress: fig = plt.figure(1) ax = fig.add_subplot(111, projection="3d") # plt.clf() # plt.grid(True) plt.ion() plt.hold(False) plt.draw() plt.show() # Measurement h_meas = [] # Simulate once to generate "measurements" for k in range(num_measurements): # Visualize the pool if plot_progress: # plt.ioff() # print h[::numboxes_per_plot] ax.cla() surf = ax.plot_surface(
from norml import maml_rl from norml import tools from norml.tools import utility flags.DEFINE_integer('framerate', 25, 'Video framerate.') flags.DEFINE_bool('render', True, 'Create video?') flags.DEFINE_string('model_dir', None, 'Checkpoint path for saved model') flags.DEFINE_string('output_dir', '/tmp', 'Where to store states, rewards...') flags.DEFINE_integer('test_task_index', 0, 'Which task modifier to use for testing') flags.DEFINE_bool('eval_meta', True, 'Whether to evaluate the meta policy') flags.DEFINE_bool('eval_finetune', True, 'Whether to evaluate the finetune policy') flags.DEFINE_integer('num_finetune_steps', 1, 'Number of finetune steps to perform') plt.ion() def _load_config(): if '.ckpt-' in FLAGS.model_dir: config_path = os.path.dirname(FLAGS.model_dir) else: config_path = FLAGS.model_dir tf.logging.info('Loading config: %s' % config_path) config = utility.load_config(config_path) return config def _save_result(renders, states, returns, actions, output_dir): """Saves the results of policy rollouts to file.
def plot_spectrum(result, correct = True, interactive = False): plt.close('all') plt.ioff() if interactive: plt.ion() hdu = fits.open(result['ORIGINALFILE']) galaxy = gaussian_filter(hdu[1].data, 1) thumbnail = hdu['THUMBNAIL'].data twoD = hdu['2D'].data header = hdu[0].header header1 = hdu[1].header hdu.close() lamRange = header1['CRVAL1'] + np.array([0., header1['CD1_1'] * (header1['NAXIS1'] - 1)]) if correct: zp = 1. + (result['VREL'] / 299792.458) else: zp = 1. wavelength = np.linspace(lamRange[0],lamRange[1], header1['NAXIS1']) / zp ymin, ymax = np.min(galaxy), np.max(galaxy) ylim = [ymin, ymax] + np.array([-0.02, 0.1])*(ymax-ymin) ylim[0] = 0. xmin, xmax = np.min(wavelength), np.max(wavelength) ### Define multipanel size and properties fig = plt.figure(figsize=(8,6)) gs = gridspec.GridSpec(200,130,bottom=0.10,left=0.10,right=0.95) ### Plot the object in the sky ax_obj = fig.add_subplot(gs[0:70,105:130]) ax_obj.imshow(thumbnail, cmap = 'gray', interpolation = 'nearest') ax_obj.set_xticks([]) ax_obj.set_yticks([]) ### Plot the 2D spectrum ax_2d = fig.add_subplot(gs[0:11,0:100]) ix_start = header['START_{}'.format(int(result['DETECT']))] ix_end = header['END_{}'.format(int(result['DETECT']))] ax_2d.imshow(twoD, cmap='spectral', aspect = "auto", origin = 'lower', extent=[xmin, xmax, 0, 1], vmin = -0.2, vmax=0.2) ax_2d.set_xticks([]) ax_2d.set_yticks([]) ### Add spectra subpanels ax_spectrum = fig.add_subplot(gs[11:85,0:100]) ax_blue = fig.add_subplot(gs[110:200,0:50]) ax_red = fig.add_subplot(gs[110:200,51:100]) ### Plot some atomic lines line_wave = [4861., 5175., 5892., 6562.8, 8498., 8542., 8662.] # ['Hbeta', 'Mgb', 'NaD', 'Halpha', 'CaT', 'CaT', 'CaT'] for i in range(len(line_wave)): x = [line_wave[i], line_wave[i]] y = [ylim[0], ylim[1]] ax_spectrum.plot(x, y, c= 'gray', linewidth=1.0) ax_blue.plot(x, y, c= 'gray', linewidth=1.0) ax_red.plot(x, y, c= 'gray', linewidth=1.0) ### Plot the spectrum ax_spectrum.plot(wavelength, galaxy, 'k', linewidth=1.3) ax_spectrum.set_ylim(ylim) ax_spectrum.set_xlim([xmin,xmax]) ax_spectrum.set_ylabel(r'Arbitrary Flux') ax_spectrum.set_xlabel(r'Restframe Wavelength [ $\AA$ ]') ### Plot blue part of the spectrum x1, x2 = 300, 750 ax_blue.plot(wavelength[x1:x2], galaxy[x1:x2], 'k', linewidth=1.3) ax_blue.set_xlim(wavelength[x1],wavelength[x2]) ax_blue.set_ylim(galaxy[x1:x2].min(), galaxy[x1:x2].max()) ax_blue.set_yticks([]) ### Plot red part of the spectrum x1, x2 = 1400, 1500 ax_red.plot(wavelength[x1:x2], galaxy[x1:x2], 'k', linewidth=1.3) ax_red.set_xlim(wavelength[x1],wavelength[x2]) ax_red.set_ylim(galaxy[x1:x2].min(), galaxy[x1:x2].max()) ax_red.set_yticks([]) ### Plot text #if interactive: textplot = fig.add_subplot(gs[80:200,105:130]) kwarg = {'va' : 'center', 'ha' : 'left', 'size' : 'medium'} textplot.text(0.1, 1.0,r'ID = {} \, {}'.format(result.ID, int(result.DETECT)),**kwarg) textplot.text(0.1, 0.9,r'$v =$ {}'.format(int(result.VREL)), **kwarg) textplot.text(0.1, 0.8,r'$\delta \, v = $ {}'.format(int(result.VERR)), **kwarg) textplot.text(0.1, 0.7,r'SN1 = {0:.2f}'.format(result.SN1), **kwarg) textplot.text(0.1, 0.6,r'SN2 = {0:.2f}'.format(result.SN2), **kwarg) textplot.text(0.1, 0.5,r'TDR = {0:.2f}'.format(result.TDR), **kwarg) textplot.text(0.1, 0.4,r'SG = {}'.format(result.SG), **kwarg) textplot.axis('off') return fig