this_dir = os.path.dirname(os.path.realpath(__file__)) this_test = os.path.basename(this_dir) species.allow_similarly_named_components = True # Read in data from the CO𝘕CEPT snapshots a = [] nprocs_list = sorted(int(dname[(dname.index('python_') + 7):]) for dname in [os.path.basename(dname) for dname in glob('{}/output_python_*'.format(this_dir))]) components = {'cython': {n: [] for n in nprocs_list}, 'python': {n: [] for n in nprocs_list}} for cp in components.keys(): for n in nprocs_list: for fname in sorted(glob('{}/output_{}_{}/snapshot_a=*'.format(this_dir, cp, n)), key=lambda s: s[(s.index('=') + 1):]): snapshot = load(fname, compare_params=False) if cp == 'cython' and n == 1: a.append(snapshot.params['a']) components[cp][n].append(snapshot.components[0]) N_snapshots = len(a) # Begin analysis masterprint('Analyzing {} data ...'.format(this_test)) # Using the particle order of the cython snapshot as the standard, find the corresponding # ID's in the python snapshots and order these particles accoringly. N = components['cython'][1][0].N D2 = zeros(N) ID = zeros(N, dtype='int') for i in range(N_snapshots): for n in nprocs_list:
# Imports from the CO𝘕CEPT code from commons import * from snapshot import load import species # Absolute path and name of the directory of this file this_dir = os.path.dirname(os.path.realpath(__file__)) this_test = os.path.basename(this_dir) # Read in data from the CO𝘕CEPT snapshots species.allow_similarly_named_components = True a = [] components = [] for fname in sorted(glob(this_dir + '/output/snapshot_a=*'), key=lambda s: s[(s.index('=') + 1):]): snapshot = load(fname, compare_params=False) a.append(snapshot.params['a']) components.append(snapshot.components[0]) N_snapshots = len(a) # Read in data from the GADGET-2 snapshots components_gadget = [] for fname in sorted(glob(this_dir + '/Gadget2/output/snapshot_*'))[:N_snapshots]: components_gadget.append(load(fname, compare_params=False, only_components=True)[0]) # Begin analysis masterprint('Analysing {} data ...'.format(this_test)) # Using the particle order of CO𝘕CEPT as the standard, find the corresponding # ID's in the GADGET-2 snapshots and order these particles accordingly. N = components[0].N
# Imports from the CO𝘕CEPT code from commons import * from snapshot import load import species # Absolute path and name of the directory of this file this_dir = os.path.dirname(os.path.realpath(__file__)) this_test = os.path.basename(this_dir) # Read in data from the CO𝘕CEPT snapshots species.allow_similarly_named_components = True a = [] components = [] for fname in sorted(glob(this_dir + '/output/snapshot_a=*'), key=lambda s: s[(s.index('=') + 1):]): snapshot = load(fname, compare_params=False) a.append(snapshot.params['a']) components.append(snapshot.components[0]) N_snapshots = len(a) # Read in data from the GADGET snapshots components_gadget = [] for fname in sorted(glob(this_dir + '/output/snapshot_gadget_*'), key=lambda s: s[(s.index('gadget_') + 7):])[:N_snapshots]: components_gadget.append( load(fname, compare_params=False, only_components=True)[0]) # Begin analysis masterprint('Analyzing {} data ...'.format(this_test)) # Using the particle order of CO𝘕CEPT as the standard, find the corresponding
# The author of CO𝘕CEPT can be contacted at dakin(at)phys.au.dk # The latest version of CO𝘕CEPT is available at # https://github.com/jmd-dk/concept/ # This file has to be run in pure Python mode! # Imports from the CO𝘕CEPT code from commons import * from snapshot import load # Absolute path and name of the directory of this file this_dir = os.path.dirname(os.path.realpath(__file__)) this_test = os.path.basename(this_dir) # Read in the particles component = load(initial_conditions, only_components=True)[0] N = component.N posx = component.posx posy = component.posy posz = component.posz # Begin analysis masterprint('Analyzing {} data ...'.format(this_test)) # Volume and linear size of cube with the volume of a sphere with radius R_tophat V = 4 * π / 3 * R_tophat**3 L = cbrt(V) # The number of complete L*L*L cubes within the box N_cubes_lin = int(boxsize // L) N_cubes = N_cubes_lin**3 # The number of particles in each of these cubes, if the snapshot is completely homogeneous
import snapshot import hello_world # First let's take a snapshot of the # hello_world package. path = snapshot.capture(hello_world, '/tmp/hello_world_snap/', overwrite=True) hello_world_snap = snapshot.load(path) print(hello_world_snap.__file__) # The snapshot is loaded from the specified directory. The code was all copied to # and is under the snapshot: print("From original package code", hello_world.func1()) print("From snapshot", hello_world_snap.hello_world.func1()) # You can import from the snapshot as if it were a regular package from hello_world_snap import hello_world print("From snapshot, overwriting the original package code", hello_world.func1())
from commons import * from snapshot import load import species # Absolute path and name of the directory of this file this_dir = os.path.dirname(os.path.realpath(__file__)) this_test = os.path.basename(this_dir) # Read in data from the CO𝘕CEPT snapshots species.allow_similarly_named_components = True a = [] x = [] x_std = [] for fname in sorted(glob(this_dir + '/output/snapshot_a=*'), key=lambda s: s[(s.index('=') + 1):]): snapshot = load(fname, compare_params=False) posx = snapshot.components[0].posx a.append(snapshot.params['a']) x.append(np.mean(posx)) x_std.append(np.std(posx)) N_snapshots = len(a) # Read in data from the GADGET snapshots x_gadget = [] x_std_gadget = [] for fname in sorted(glob(this_dir + '/output/snapshot_gadget_*'), key=lambda s: s[(s.index('gadget_') + 7):])[:N_snapshots]: components_gadget = load(fname, compare_params=False, only_components=True)[0] x_gadget.append(np.mean(components_gadget.posx)) x_std_gadget.append(np.std(components_gadget.posx))
def load_results(subtest): ncomponents_values = set() nprocs_values = set() subtiling_values = set() directory_pattern = get_directory( subtest, '*', '*', subtiling={ 'domain': None, 'tile': '*' }[subtest], ) for directory in glob(directory_pattern): match = re.search(directory_pattern.replace('*', '(.+)'), directory) ncomponents_values.add(int(match.group(1))) nprocs_values.add(int(match.group(2))) if subtest == 'tile': subtiling_values.add(int(match.group(3))) ncomponents_values = sorted(ncomponents_values) nprocs_values = sorted(nprocs_values) if subtest == 'domain': subtiling_values = [None] elif subtest == 'tile': subtiling_values = sorted(subtiling_values) pos = {} times = set() lattice_sites = None for ncomponents in ncomponents_values: for nprocs in nprocs_values: for subtiling in subtiling_values: directory = get_directory(subtest, ncomponents, nprocs, subtiling) for fname in sorted(glob(f'{directory}/snapshot_t=*')): if not fname.endswith('.hdf5'): continue t = float(re.search(rf't=(.+){unit_time}', fname).group(1)) times.add(t) snapshot = load(fname) if subtest == 'domain': posx, posy, posz, = [], [], [] elif subtest == 'tile': if lattice_sites is None: N = sum([ component.N for component in snapshot.components ]) N_lin = int(round(cbrt(N))) distance = boxsize / N_lin lattice_sites = [] for i in range(N_lin): x = (0.5 + i) * distance for j in range(N_lin): y = (0.5 + j) * distance for k in range(N_lin): z = (0.5 + k) * distance lattice_sites.append((x, y, z)) lattice_sites = asarray(lattice_sites) posx = empty(N_lin**3, dtype=float) posy = empty(N_lin**3, dtype=float) posz = empty(N_lin**3, dtype=float) indices_all = [] for component in snapshot.components: if component.N == 0: continue if subtest == 'domain': posx += list(component.posx) posy += list(component.posy) posz += list(component.posz) elif subtest == 'tile': # Sort particles according to the lattice indices = [] for x, y, z in zip(component.posx, component.posy, component.posz): orders = np.argsort( sum((asarray( (x, y, z)) - lattice_sites)**2, 1)) for order in orders: if order not in indices_all: indices.append(order) indices_all.append(order) break indices = asarray(indices) posx[indices] = component.posx posy[indices] = component.posy posz[indices] = component.posz if subtest == 'tile': key = (ncomponents, nprocs, subtiling, t) elif subtest == 'domain': key = (ncomponents, nprocs, t) pos[key] = [asarray(posx), asarray(posy), asarray(posz)] times = sorted(times) softening_length = is_selected(component, select_softening_length) return ncomponents_values, nprocs_values, subtiling_values, times, pos, softening_length
# https://github.com/jmd-dk/concept/ # This file has to be run in pure Python mode! # Imports from the CO𝘕CEPT code from commons import * from snapshot import load # Absolute path and name of the directory of this file this_dir = os.path.dirname(os.path.realpath(__file__)) this_test = os.path.basename(this_dir) # Read in the particles component = load(initial_conditions, only_components=True)[0] N = component.N posx = component.posx posy = component.posy posz = component.posz # Begin analysis masterprint('Analyzing {} data ...'.format(this_test)) # Volume and linear size of cube with the volume of a sphere with radius R_tophat V = 4*π/3*R_tophat**3 L = cbrt(V) # The number of complete L*L*L cubes within the box N_cubes_lin = int(boxsize//L) N_cubes = N_cubes_lin**3 # The number of particles in each of these cubes, if the snapshot is completely homogeneous