Skip to content

Commit 1ac4120

Browse files
committed
adding next reformatting step
1 parent 8e36351 commit 1ac4120

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

README

+16-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,19 @@ cosmoflow-sims/pycola> python reformatNBody-noCiC-Ns-128from256.py 0
7979

8080
The argument for this defines which file in the pycola output dir you start with. I put this in so I could run multiple versions of this code at the same time over the same output dir.
8181

82-
The output of this code is a directory inside the OmSiNs dir that has the name of the 3 cosmo params behind the simulation. Inside that dir are 8 npy files, each of which is a histogram of particle counts.
82+
The output of this code is a directory inside the OmSiNs dir that has the name of the 3 cosmo params behind the simulation. Inside that dir are 8 npy files, each of which is a histogram of particle counts.
83+
84+
85+
--------------------
86+
87+
Making the list of files for input into the CosmoFlow IO code
88+
89+
The next stage of formatting involves putting these sub-volume files into a format required by the CosmoFlow IO code, for when it makes the TFRecord files you'll actually use in the tensorflow training. For this we need a list of cosmologies, and we need to re-name all the dirs we just made to numbers that correspond to the position of this simulation on the list.
90+
I know this is not a very sensible solution.
91+
92+
First run :
93+
cosmoflow-sims/pycola/OmSiNs/makeList.py
94+
to make the list, then run:
95+
96+
cosmoflow-sims/pycola/OmSiNs/copyFiles.py
97+
to make new dirs with new names. Note that I'm copying them, rather than moving the dir, because I am cautious and didn't want to have to re-make all these files again.

pycola/OmSiNs/copyFiles.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os, shutil
2+
3+
## need to rename all the files in the numbering scheme required by the CosmoFlow IO sceme.
4+
## Previously, the dir had a useful name containing the comso params used in the sim
5+
## Now, this dir needs to be re-named so that it has a number, which corresponds to the position in the list of cosmo params
6+
## I know, this is not very sensible. But then the CosmoFlow IO code picks random sets of sims + sub-volumes to make the TFRecord files, and it's easier to do that when the file names are the numbers.
7+
8+
### In case you don't want to run this over all the files you have
9+
start = 1000
10+
stop = 1010
11+
12+
for line in open("list.txt"):
13+
if "#" in line:
14+
continue
15+
cols = line.split(",")
16+
num = cols[0]
17+
om = cols[1]
18+
si = cols[2]
19+
ns = cols[3][:-1]
20+
print line, num, om, si, ns
21+
22+
if int(num)<start or int(num)>stop:
23+
print"skipping!"
24+
continue
25+
26+
outdir = "./"+num
27+
if os.path.exists(outdir):
28+
if len(os.listdir(outdir))==8:
29+
print "done this one!"
30+
continue
31+
else:
32+
shutil.rmtree(outdir)
33+
34+
## now move the files
35+
indir = "pycola_"+om+"_"+si+"_"+ns
36+
shutil.copytree(indir, outdir)
37+

pycola/OmSiNs/makeList.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os, shutil
2+
3+
### making the list of cosmological params, which will be used by the CosmoFlow IO code to make the tensorflow files
4+
5+
list = open("list.txt", "w")
6+
print >> list, "## seed, om, si"
7+
counter = 999
8+
9+
start = 0
10+
stop = 2000
11+
12+
ct = 0
13+
for afile in os.listdir("./"):
14+
if "pycola" not in afile or "npz" in afile:
15+
continue
16+
else:
17+
print afile
18+
counter+=1
19+
20+
if counter>3000:
21+
continue
22+
23+
om = afile.split("_")[1]
24+
si = afile.split("_")[2]
25+
ns = afile.split("_")[3]
26+
print counter, om, si, ns
27+
28+
print >> list, str(counter)+","+str(om)+","+str(si)+","+str(ns)
29+

0 commit comments

Comments
 (0)