예제 #1
0
def snapshot_info():
    # This function should not run in parallel
    if not master:
        return
    # Extract the path to snapshot(s)
    path = special_params['path']
    # Get list of snapshots
    snapshot_filenames = locate_snapshots(path)
    # Print out information about each snapshot
    for snapshot_filename in snapshot_filenames:
        # Print out heading stating the filename
        heading = ('\nInformation about "{}"'.format(sensible_path(snapshot_filename)))
        masterprint(terminal.bold(heading))
        # Print out snapshot type
        snapshot_type = get_snapshot_type(snapshot_filename)
        masterprint('{:<18} {}'.format('Snapshot type', snapshot_type))
        # Load parameters from the snapshot
        params = load_params(snapshot_filename, compare_params=False)
        # Print out global parameters
        masterprint('{:<18} {:.12g}'.format('a', params['a']))
        masterprint('{:<18} {:.12g} {}'.format('boxsize', params['boxsize'], units.length))
        unit = units.km/(units.s*units.Mpc)
        unit_str = 'km s' + unicode('⁻') + unicode('¹') + ' Mpc' + unicode('⁻') + unicode('¹')
        masterprint('{:<18} {:.12g} {}'.format('H0', params['H0']/unit, unit_str))
        masterprint('{:<18} {:.12g}'.format(unicode('Ω') + 'm', params['Ωm']))
        masterprint('{:<18} {:.12g}'.format(unicode('Ω') + unicode('Λ'), params['ΩΛ']))
        # Print out particle information
        for particle_type in params['particle_attributes']:
            masterprint(particle_type + ':')
            particle_attribute = params['particle_attributes'][particle_type]
            masterprint('{:<14} {}'.format('species', particle_attribute['species']), indent=4)
            masterprint('{:<14} {}'.format('N', particle_attribute['N']), indent=4)
            value = particle_attribute['mass']/units.m_sun
            masterprint('{:<14} {:.12e} {}'.format('mass', value, 'm_sun'), indent=4)
        # Print out GADGET header for GADGET snapshots
        if not 'header' in params:
            continue
        masterprint('GADGET header:')
        for key, val in params['header'].items():
            masterprint('{:<14} {}'.format(key, val), indent=4)
예제 #2
0
def locate_snapshots(path):
    # Get all files from the path
    if master and not os.path.exists(path):
        msg = 'Path "{}" does not exist!'.format(path)
        abort(msg)
    if os.path.isdir(path):
        filenames = [os.path.join(path, filename)
                     for filename in os.listdir(path)
                     if os.path.isfile(os.path.join(path, filename))]
    else:
        filenames = [path]
    # Only use snapshots
    snapshot_filenames = [filename for filename in filenames
                          if get_snapshot_type(filename)]
    # Abort if none of the files where snapshots
    if master and not snapshot_filenames:
        if os.path.isdir(path):
            msg = ('The directory "{}" does not contain any snapshots.'
                   ).format(path)
        else:
            msg = ('The file "{}" is not a valid snapshot.'
                   ).format(path)
        abort(msg)
    return snapshot_filenames