Skip to content

Commit b8f7783

Browse files
download methods (untested)
1 parent c985952 commit b8f7783

File tree

3 files changed

+114
-11
lines changed

3 files changed

+114
-11
lines changed

Diff for: create_master_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
fl = flares.flares('./data/flares.hdf5',sim_type='FLARES')
55

6-
in_dir = './data/'
6+
in_dir = '/cosma7/data/dp004/dc-payy1/my_files/flares_pipeline/data2'
77

88
with h5py.File('./data/flares.hdf5','w') as outfile:
99

Diff for: download_methods.py

+107-9
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def make_faceon(cop, this_g_cood, this_g_mass, this_g_vel):
6060
def extract_subfind_info(fname='data/flares.hdf5', inp='FLARES',
6161
properties = {'properties': ['MassType'],
6262
'conv_factor': [1e10],
63+
'arr_idx': [None],
6364
'save_str': ['MassType']},
64-
overwrite=False, threads=8, verbose=False):
65+
overwrite=False, threads=8, write_out=True, verbose=False):
6566

6667
fl = flares.flares(fname,inp)
6768
indices = fl.load_dataset('Indices')
@@ -81,24 +82,121 @@ def extract_subfind_info(fname='data/flares.hdf5', inp='FLARES',
8182

8283
halodir = fl.directory+'/GEAGLE_'+halo+'/data/'
8384

84-
props = properties['properties']
85-
conv_factor = properties['conv_factor']
86-
save_str = properties['save_str']
87-
88-
for _prop,_conv,_save in zip(props,conv_factor,save_str):
85+
for _prop,_conv,_save,_arr_idx in \
86+
zip(properties['properties'],
87+
properties['conv_factor'],
88+
properties['save_str'],
89+
properties['arr_idx']):
90+
8991

9092
if (fl._check_hdf5('%s/%s/Subhalo/%s'%(halo,tag,_prop)) is False) |\
9193
(overwrite == True):
9294

9395
_arr = E.read_array("SUBFIND", halodir, tag,
9496
"/Subhalo/%s"%_prop,
9597
numThreads=threads, noH=True) * _conv
96-
9798

98-
fl.create_dataset(_arr[indices[halo][tag].astype(int)], _save,
99-
'%s/%s/Galaxy/'%(halo,tag), overwrite=True, verbose=verbose)
99+
if arr_idx is not None:
100+
_arr[:arr_idx]
101+
102+
103+
if write_out is False:
104+
# return array WITHOUT indices filtering (be careful)
105+
return _arr
106+
else:
107+
fl.create_dataset(_arr[indices[halo][tag].astype(int)], _save,
108+
'%s/%s/Galaxy/'%(halo,tag), overwrite=True, verbose=verbose)
109+
110+
111+
112+
def initialise_master_file():
113+
"""
114+
Run the initial subfind download and create the indices array
115+
"""
116+
117+
print (F"Extracing information from {inp} {num} {tag}")
118+
119+
if inp == 'FLARES':
120+
sim_type = 'FLARES'
121+
fl = flares.flares(fname = './data2/',sim_type=sim_type)
122+
num = str(num)
123+
if len(num) == 1:
124+
num = '0'+num
125+
dir = fl.directory
126+
sim = F"{dir}GEAGLE_{num}/data/"
127+
128+
elif inp == 'REF':
129+
sim_type = 'PERIODIC'
130+
fl = flares.flares(fname = './data/',sim_type=sim_type)
131+
sim = fl.ref_directory
100132

133+
elif inp == 'AGNdT9':
134+
sim_type = 'PERIODIC'
135+
fl = flares.flares(fname = './data/',sim_type=sim_type)
136+
sim = fl.agn_directory
137+
138+
else:
139+
ValueError("Type of input simulation not recognized")
101140

141+
if rank == 0:
142+
print (F"Sim location: {sim}, tag: {tag}")
143+
144+
#Simulation properties
145+
z = E.read_header('SUBFIND', sim, tag, 'Redshift')
146+
a = E.read_header('SUBFIND', sim, tag, 'ExpansionFactor')
147+
148+
if inp == 'FLARES':
149+
## Selecting the subhalos within our region
150+
151+
for halo in fl.halos:
152+
print(halo)
153+
fl.create_group(halo)
154+
for tag in fl.tags:
155+
cop = E.read_array('SUBFIND', halo, tag, '/Subhalo/CentreOfPotential', noH=False, physicalUnits=False, numThreads=4) #units of cMpc/h
156+
cen, r, min_dist = fl.spherical_region(halo, tag) #units of cMpc/h
157+
indices = np.where(np.logical_and(mstar >= 10**7., np.sqrt(np.sum((cop-cen)**2, axis = 1))<=fl.radius) == True)[0]
158+
fl.create_dataset(indices.astype(int), 'Indices', '%s/%s/Galaxy/'%(halo,tag), overwrite=True, verbose=verbose)
159+
160+
else:
161+
indices = np.where(mstar >= 10**7.)[0]
162+
163+
## Galaxy global properties
164+
properties = {'properties': ['FOF/Group_M_Crit200','FOF/Group_M_Crit500','FOF/Group_M_Crit2500',
165+
'Subhalo/Mass','/Subhalo/ApertureMeasurements/Mass/030kpc','Subhalo/SubGroupNumber',
166+
'Subhalo/GroupNumber','Subhalo/Velocity'],
167+
'conv_factor': [1e10, 1e10, 1e10, 1e10, 1e10, 1, 1, 1],
168+
'arr_idx': [None, None, None, None, 4, None, None, None],
169+
'save_str': []
170+
}
171+
172+
extract_subfind_info(properties)
173+
174+
175+
# M200 = E.read_array('SUBFIND', sim, tag, 'FOF/Group_M_Crit200', numThreads=4, noH=True, physicalUnits=True)*1e10
176+
# M500 = E.read_array('SUBFIND', sim, tag, '/FOF/Group_M_Crit500', numThreads=4, noH=True, physicalUnits=True)*1e10
177+
# M2500 = E.read_array('SUBFIND', sim, tag, '/FOF/Group_M_Crit2500', numThreads=4, noH=True, physicalUnits=True)*1e10
178+
# SubhaloMass = E.read_array('SUBFIND', sim, tag, '/Subhalo/Mass', numThreads=4, noH=True, physicalUnits=True)*1e10
179+
# mstar = E.read_array('SUBFIND', sim, tag, '/Subhalo/ApertureMeasurements/Mass/030kpc', numThreads=4, noH=True, physicalUnits=True)[:,4]*1e10
180+
# sgrpno = E.read_array('SUBFIND', sim, tag, '/Subhalo/SubGroupNumber', numThreads=4)
181+
# grpno = E.read_array('SUBFIND', sim, tag, '/Subhalo/GroupNumber', numThreads=4)
182+
# vel = E.read_array('SUBFIND', sim, tag, '/Subhalo/Velocity', noH=True, physicalUnits=True, numThreads=4)
183+
184+
185+
186+
187+
188+
cop = E.read_array('SUBFIND', sim, tag, '/Subhalo/CentreOfPotential', noH=True, physicalUnits=True, numThreads=4)
189+
sfr_inst = E.read_array('SUBFIND', sim, tag, '/Subhalo/ApertureMeasurements/SFR/030kpc', numThreads=4, noH=True, physicalUnits=True)
190+
191+
192+
return None
193+
194+
195+
def extract_particle_array():
196+
"""
197+
Extract a particle array
198+
"""
199+
return None
102200

103201
def extract_info(num, tag, kernel='sph-anarchy', inp='FLARES'):
104202
"""

Diff for: download_subfind.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11

22
from download_methods import extract_subfind_info
33

4-
extract_subfind_info('data/flares.hdf5', overwrite=True, verbose=True)
4+
properties = {'properties': ['MassType'], #'BlackHoleMass','BlackHoleMassAccretionRate'],
5+
'conv_factor': [1e10],
6+
'save_str': ['MassType']} #BlackHoleMass','BlackHoleMassAccretionRate']}
7+
8+
9+
extract_subfind_info('data/flares_copy.hdf5', properties=properties, overwrite=True, verbose=True)
510

0 commit comments

Comments
 (0)