예제 #1
0
def load(filename, variable):
    samples = []
    
    if variable == 'all':
        variables = ['rho', 'mx', 'my', 'E']
    else:
        variables = [variable]
    
    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(filename.replace("/", "_") + "_" + attr, f.getncattr(attr))
        
        sample = 0
        shape = f.variables['sample_0_rho'][:,:,0].shape
        next_sample_to_print = 1
        while f'sample_{sample}_rho' in f.variables.keys():
            if sample % 80 > next_sample_to_print:
                sys.stdout.write("#")
                sys.stdout.flush()
                next_sample_to_print += 1
            
            data = np.zeros((*shape, len(variables)))
            for n, variable in enumerate(variables):
                key = f'sample_{sample}'
                data[:,:,n] = f.variables[key][:,:,0]
            samples.append(data)
            sample += 1
                
    print()
    return np.array(samples)
예제 #2
0
def load_file_single_sample(filename, conserved_variables):
    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(filename.replace("/", "_") + "_" + attr, f.getncattr(attr))
            

        resolution = f.variables[f'sample_0_{conserved_variables[0]}'].shape[0]
        data = np.zeros((resolution, resolution, resolution, len(conserved_variables)))
        for variable_index, variable in enumerate(conserved_variables):
            # 42 is the answer to everything. (Wanted different realizations than the ones already shown a thousand times)
            data[:,:,:,variable_index] = f.variables[f'sample_42_{variable}'][:,:,:]
            
        return data
예제 #3
0
def load_file_mean(filename, conserved_variables, number_of_samples):
    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(filename.replace("/", "_") + "_" + attr, f.getncattr(attr))
        
        resolution = f.variables[f'sample_0_{conserved_variables[0]}'].shape[0]
        mean = np.zeros((resolution, resolution, resolution, len(conserved_variables)))
        
        for sample in range(number_of_samples):
            for variable_index, variable in enumerate(conserved_variables):
                key = f'sample_{sample}_{variable}'
                mean[:,:,:,variable_index] += f.variables[key][:,:,:]
        
        mean /= number_of_samples
        
        return mean
def load_plane_line(filename, start_y, end_y, start_z, end_z, number_of_samples, variables):
    
    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(filename.replace("/", "_") + "_" + attr, f.getncattr(attr))
        resolution = f.variables['sample_0_rho'].shape[0]
        
        length_z = end_z - start_z
        length_y = end_y - start_y
        length_x = resolution
        samples = np.zeros((number_of_samples, length_z, length_y, length_x, len(variables)))
        for variable_index, variable in enumerate(variables):
            for sample in range(number_of_samples):
                key = f'sample_{sample}_{variable}'
                
                samples[sample,:,:,:,variable_index] = f.variables[key][start_z:end_z,start_y:end_y,:]
                
    return samples
예제 #5
0
def load_plane(filename, k, number_of_samples, variables):

    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(
                filename.replace("/", "_") + "_" + attr, f.getncattr(attr))
        resolution = f.variables['sample_0_rho'].shape[0]

        samples = np.zeros(
            (number_of_samples, resolution, resolution, len(variables)))
        for variable_index, variable in enumerate(variables):
            for sample in range(number_of_samples):
                key = f'sample_{sample}_{variable}'

                samples[sample, :, :,
                        variable_index] = f.variables[key][k, :, :]

    return samples
def load_plane(filename, plane, variable):
    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(attr, f.getncattr(attr))
        return f.variables[f'sample_0_{variable}'][plane, :, :]
    parser.add_argument('--title',
                        type=str,
                        required=True,
                        help='Title of plot')

    parser.add_argument(
        '--not_zoom',
        action='store_true',
        help=
        'Disable zooming out of plot. We typically zoom out of plots because matplotlib zooms in so much it seems like it is converging. For fBm with low H, it is usually a good idea to disable this so that we actually see the slow convergence'
    )

    parser.add_argument('--compute_rate',
                        action='store_true',
                        help='Compute the convergence rate')

    parser.add_argument('--variable', type=str, default='rho', help='Variable')

    parser.add_argument('--starting_resolution',
                        type=int,
                        default=256,
                        help='Starting resolution (smallest resolution)')

    args = parser.parse_args()

    plot_info.add_additional_plot_parameters("basename", args.input_basename)

    plot_convergence_single_sample(args.input_basename, args.title,
                                   args.variable, args.starting_resolution,
                                   not args.not_zoom, args.compute_rate)
예제 #8
0
    parser.add_argument('--number_of_integration_points',
                        type=int,
                        default=10,
                        help='Number  of integration points')

    parser.add_argument(
        '--reference_solution',
        action='store_true',
        help='Use a reference solution instead of Cauchy convergence')

    args = parser.parse_args()

    basename = args.input_basename
    name = args.title
    number_of_integration_points = args.number_of_integration_points

    plot_info.add_additional_plot_parameters("basename", basename)
    plot_info.add_additional_plot_parameters("number_of_integration_points",
                                             number_of_integration_points)

    resolutions = [64, 128, 256, 512]

    if args.reference_solution:
        plotWassersteinConvergence(name, basename, resolutions,
                                   number_of_integration_points)

    else:
        plotWassersteinConvergenceReferenceSolution(
            name, basename, resolutions, number_of_integration_points)
예제 #9
0
                        default=256,
                        help='Starting resolution (smallest resolution)')

    parser.add_argument('--stat',
                        type=str,
                        default='mean',
                        help='Statistics (ether mean or variance)')

    parser.add_argument(
        '--not_zoom',
        action='store_true',
        help=
        'Disable zooming out of plot. We typically zoom out of plots because matplotlib zooms in so much it seems like it is converging. For fBm with low H, it is usually a good idea to disable this so that we actually see the slow convergence'
    )

    parser.add_argument('--compute_rate',
                        action='store_true',
                        help='Compute the convergence rate')

    args = parser.parse_args()

    plot_info.add_additional_plot_parameters("basename_a",
                                             args.input_basename_a)
    plot_info.add_additional_plot_parameters("basename_b",
                                             args.input_basename_b)

    plot_convergence(args.input_basename_a, args.name_a, args.input_basename_b,
                     args.name_b, args.title, args.variable,
                     args.starting_resolution, args.stat, not args.not_zoom,
                     args.compute_rate)
예제 #10
0
def load(filename, variable):
    with netCDF4.Dataset(filename) as f:
        for attr in f.ncattrs():
            plot_info.add_additional_plot_parameters(
                filename.replace("/", "_") + "_" + attr, f.getncattr(attr))
        return f.variables[variable][:, :, :]