cleanupSwift.py 1.09 KB
Newer Older
Loic Hausammann's avatar
Loic Hausammann committed
1
#!/usr/bin/env python3
lhausamm's avatar
lhausamm committed
2

Loic Hausammann's avatar
Loic Hausammann committed
3
# ./translate_particles.py filename output_name
lhausamm's avatar
lhausamm committed
4
5
from h5py import File
import sys
Loic Hausammann's avatar
Loic Hausammann committed
6
from shutil import copyfile
lhausamm's avatar
lhausamm committed
7
8

NPartType = 1
Loic Hausammann's avatar
Loic Hausammann committed
9
10
11
12
13
14
filename = sys.argv[-2]
out = sys.argv[-1]

copyfile(filename, out)

f = File(out)
lhausamm's avatar
lhausamm committed
15

Loic Hausammann's avatar
Loic Hausammann committed
16
for i in range(6):
Loic Hausammann's avatar
Gear    
Loic Hausammann committed
17
    name = "PartType{}/ElementAbundances".format(i)
Loic Hausammann's avatar
Loic Hausammann committed
18
19
    if name in f:
        del f[name]
20

lhausamm's avatar
lhausamm committed
21
22
23
24
25
for i in range(NPartType):
    name = "PartType%i" % i
    if name not in f:
        continue

Loic Hausammann's avatar
Gear    
Loic Hausammann committed
26
    grp = f[name + "/SmoothingLengths"]
lhausamm's avatar
lhausamm committed
27
28
    grp[:] *= 1.823

Loic Hausammann's avatar
Gear    
Loic Hausammann committed
29
30
31
32
33
34
35
36
37
38
39
40
41
    # fix issue due to the name of densities
    fields = [("Density", "Densities"),
              ("Entropies", "Entropies"),
              ("InternalEnergy", "InternalEnergies"),
              ("SmoothingLength", "SmoothingLengths")]

    for field in fields:
        if field[1] in f[name] and field[0] not in f[name]:
            f[name + "/" + field[0]] = f[name + "/" + field[1]]




Loic Hausammann's avatar
Loic Hausammann committed
42
43
44
45
46
cosmo = f["Cosmology"].attrs
head = f["Header"].attrs
head["OmegaLambda"] = cosmo["Omega_lambda"]
head["Omega0"] = cosmo["Omega_b"]
head["HubbleParam"] = cosmo["H0 [internal units]"]
Loic Hausammann's avatar
Gear    
Loic Hausammann committed
47
head["Time"] = head["Time"][0]
Loic Hausammann's avatar
Loic Hausammann committed
48

lhausamm's avatar
lhausamm committed
49
f.close()