def set_up_plot(self, settings=None): self.plot = Plot() if settings is not None: for key in settings: self.plot.settings[key] = settings[key] self.settings['plot'] = self.plot.settings n_rows = self.plot.settings['n_rows'] n_cols = self.plot.settings['n_cols'] if n_rows is not None and n_cols is not None: print '\nSetting up {0:d}x{1:d} plot.'.format(n_rows, n_cols) else: e_str = 'Number of {0:s} must be an integer > 0.' n_rows, n_cols = (0, 0) while n_rows < 1 or n_cols < 1: n_rows = utils.get_input_integer( \ '\nNumber of subplot rows?\n> ', error_text=e_str.format('rows'))[0] n_cols = utils.get_input_integer( \ 'Number of subplot columns?\n> ', error_text=e_str.format('columns'))[0] if n_rows < 1 or n_cols < 1: print 'Must have > 0 rows and columns.' self.plot.set_up_plot_grid(n_rows, n_cols) #self.plot.plot_grid.tight_layout(self.plot.figure) self.plot.figure.set_tight_layout(True) plt.show(block=False) print '(If you cannot see the plot, try changing the ' print 'matplotlib backend. Current backend is ' + \ plt.get_backend() + '.)'
def define_new_chain(self): files = [] while len(files) == 0: for f in raw_input('\nChain file names?\n> ').split(): new_files = glob.glob(f) if len(new_files) == 0: print 'No files matching ' + f + ' found.' elif not np.array([os.path.isfile(nf) \ for nf in new_files]).all(): print 'Some of the files specified are not valid.' else: files += new_files name = raw_input('Label for chain?\n> ') burn_in = utils.get_input_float( \ 'Burn-in fraction or number of samples?\n> ')[0] mult_column = utils.get_input_integer( \ 'Multiplicity column? (Enter -1 if none.)\n> ')[0] if mult_column < 0: mult_column = None lnlike_column = utils.get_input_integer( \ 'Log likelihood column? (Enter -1 if none.)\n> ')[0] if lnlike_column < 0: lnlike_column = None first_par_column = utils.get_input_integer( \ 'Column of first chain parameter?\n> ')[0] m = Menu(options=['File named as chain label + .paramnames', 'A different file', 'Header of chain files'], exit_str=None, header='Where are the chain parameter names?') m.get_choice() paramname_file = None params_in_header = False if m.i_choice == 1: paramname_file = raw_input('Enter file name:\n> ') elif m.i_choice == 2: params_in_header = True chain_settings = (name, files, burn_in, mult_column, lnlike_column, first_par_column, paramname_file, params_in_header) # check if name is already in history; if so, replace with new for chain in list(self.history['chains']): if chain[0] == name: self.history['chains'].remove(chain) self.history['chains'].append([1] + list(chain_settings)) return chain_settings
def get_col(self, default=None): n_cols = self.settings['n_cols'] if default is None: if n_cols > 1: col = utils.get_input_integer( \ '\nSubplot column (0-' + str(n_cols - 1) + ')?\n> ', error_text='Must choose an integer.')[0] else: col = 0 else: col = default if col < 0 or col > n_cols - 1: print 'Column number is out of required range.' col = self.get_col() return col
def get_row(self, default=None): n_rows = self.settings['n_rows'] if default is None: if n_rows > 1: row = utils.get_input_integer( \ '\nSubplot row (0-' + str(n_rows - 1) + ')?\n> ', error_text='Must choose an integer.')[0] else: row = 0 else: row = default if row < 0 or row > n_rows - 1: print 'Row number is out of required range.' row = self.get_row() return row