Save groupcat as csv for illustris-1(snapshot135)

Maryam salimi
  • 1
  • 7 Dec '19

Hello

I have to get some information of halos as csv from group catalog and save it in a file, but I couldn't find python codes for this in illustris site.
I downloaded groupcat for illustris-1 (snapshot 135 (4.5 GB)) .I found some codes in net, like these :

fields_of_halo ="GroupBHMass , GroupBHMdot , GroupGasMetallicity , GroupLen , GroupLenType , GroupMass , GroupMassType , GroupNsubs , GroupPos , GroupSFR , GroupStarMetallicity , GroupVel , GroupWindMass , Group_M_Crit200 , Group_M_Crit500, Group_M_Mean200 , Group_M_TopHat200 , Group_R_Crit200 , Group_R_Crit500 , Group_R_Mean200 , Group_R_TopHat200"
with open ("groupcat_halodata.txt", "w") as out_file:
fields_halo = "ID , " + fields_of_halo
fields_halo +="\n"
out_file.write(fields_halo)
for i in range (100):
out_string = ""
out_string += str(halos['GroupFirstSub'][i])
out_string += " , " + str( halos['GroupBHMass'][i])
out_string += " , " + str(halos['GroupBHMdot'][i])
out_string += " , " + str( halos['GroupGasMetallicity'][i])
out_string += " , " + str(halos['GroupLen'][i])
out_string += " , " + str( halos['GroupLenType'][i])
out_string += " , " + str(halos['GroupMass'][i])
out_string += " , " + str( halos['GroupMassType'][i])
out_string += " , " + str(halos['GroupNsubs'][i])
out_string += " , " + str( halos['GroupPos'][i])
out_string += " , " + str(halos['GroupSFR'][i])
out_string += " , " + str( halos['GroupStarMetallicity'][i])
out_string += " , " + str(halos['GroupVel'][i])
out_string += " , " + str( halos['GroupWindMass'][i])
out_string += " , " + str(halos['Group_M_Crit200'][i])
out_string += " , " + str( halos['Group_M_Crit500'][i])
out_string += " , " + str(halos['Group_M_Mean200'][i])
out_string += " , " + str( halos['Group_M_TopHat200'][i])
out_string += " , " + str(halos['Group_R_Crit200'][i])
out_string += " , " + str( halos['Group_R_Crit500'][i])
out_string += " , " + str(halos['Group_R_Mean200'][i])
out_string += " , " + str( halos['Group_R_TopHat200'][i])
out_string += "\n"
out_file.write(out_string)

,they work ,but they don't seem to be right...
And I have to save something like 'GroupLenType' separately, but I don't know how...

I just start working with illustris and I hope you will help me .

thank you

Dylan Nelson
  • 7 Dec '19

Hi,

I would suggest to use numpy.savetxt.

You can write the whole file in one command, if you first make a single numpy array e.g. arr = np.vstack( (halos['GroupLen'], halos['GroupSFR'], ...) ).

Maryam salimi
  • 13 Dec '19

Hi,

I wrote it. Thank you very much .

  • Page 1 of 1