Beispiel #1
0
 def save_log(self, filename=None):
     if filename is None:
         filename = self.log_file
     writer = utils.open_with_path(filename, 'wb')
     writer.write(json.dumps(self.settings, sort_keys=True, indent=4))
     writer.close()
     print '\nLog file saved as ' + filename
Beispiel #2
0
    def save_and_exit(self):
        # save settings
        if self.save:
            self.save_log()

        # save history
        history_writer = utils.open_with_path(self.history_file, 'w')
        history_writer.write(json.dumps(self.history))
        history_writer.close()
Beispiel #3
0
    def save_pdf(self):
        pdf = self.choose_pdf(require_data=True)
        if pdf is not None:
            file_prefix = os.path.join('Chains', time.strftime('%Y-%m-%d'),
                                       'chain_' + '_'.join(pdf.name.split()) \
                                       + time.strftime('_%Z.%H.%M.%S'))

            param_filename = file_prefix + '.paramnames'
            writer = utils.open_with_path(param_filename, 'w')
            writer.write('\n'.join(pdf.chain.parameters) + '\n')
            writer.close()
            pdf_filename = file_prefix + '_1.txt'
            writer = utils.open_with_path(pdf_filename, 'w')
            header = ''
            for key in sorted(pdf.settings):
                header += textwrap.fill(key + ': ' + str(pdf.settings[key]),
                                    subsequent_indent='    ') + '\n'
            np.savetxt(writer, pdf.chain.samples, fmt='%.6e', header=header)
            writer.close()
            print 'Saved as ' + pdf_filename
Beispiel #4
0
 def save_contour_data(self, parameters, n_samples, grid_size, smoothing, 
                       contour_pct, contour_levels, X, Y, Z):
     filename = os.path.join('Data', time.strftime('%Y-%m-%d'), 
                             time.strftime('%Z.%H.%M.%S') + '_contour.txt')
     writer = utils.open_with_path(filename, 'w')
     header = ' '.join(parameters) + ' # parameters\n' + \
         str(n_samples) + ' # n_samples\n' + \
         str(grid_size[0]) + ' ' + str(grid_size[1]) + ' # grid_size\n' + \
         str(smoothing) + ' # smoothing\n' + \
         ' '.join([str(cp) for cp in contour_pct]) + ' # contour_pct\n' + \
         ' '.join([str(cl) for cl in contour_levels]) + \
                      ' # contour_levels\n'
     np.savetxt(writer, 
                np.vstack((X.flatten(), Y.flatten(), Z.flatten())).T, 
                fmt='%.3e', header=header, comments='')
     writer.close()
     self.settings['contour_data_files'].append(filename)
Beispiel #5
0
 def save_contour_data(self, parameters, n_samples, grid_size, smoothing,
                       contour_pct, contour_levels, X, Y, Z):
     filename = os.path.join('Data', time.strftime('%Y-%m-%d'),
                             time.strftime('%Z.%H.%M.%S') + '_contour.txt')
     writer = utils.open_with_path(filename, 'w')
     header = ' '.join(parameters) + ' # parameters\n' + \
         str(n_samples) + ' # n_samples\n' + \
         str(grid_size[0]) + ' ' + str(grid_size[1]) + ' # grid_size\n' + \
         str(smoothing) + ' # smoothing\n' + \
         ' '.join([str(cp) for cp in contour_pct]) + ' # contour_pct\n' + \
         ' '.join([str(cl) for cl in contour_levels]) + \
                      ' # contour_levels\n'
     np.savetxt(writer,
                np.vstack((X.flatten(), Y.flatten(), Z.flatten())).T,
                fmt='%.3e',
                header=header,
                comments='')
     writer.close()
     self.settings['contour_data_files'].append(filename)