Commits

Shea Garrison-Kimmel committed 641cd45

Updated enbid2irate to work with new enbid.py

Comments (0)

Files changed (2)

 
 def read_and_write_enbid_binary(fname,outname,snapnum,dset_name="EnBiDDensity",
     t0_name="Gas",t1_name="Dark_Halo",t2_name="Dark_Disk",
-    t3_name="Dark_Bulge",t4_name="Star",t5_name="Dark_Boundary"):
+    t3_name="Dark_Bulge",t4_name="Star",t5_name="Dark_Boundary",units_name,units_ar):
 
     """
     Reads an EnBiD binary file, as produced when run on a Gadget snapshot,
     else:
         pdata = snap.create_group('ParticleData')
         
+    if dset_name+'unitname' in pdata.attrs.keys():
+        if pdata.attrs[dset_name+'unitname'] != units_name or (pdata.attrs[dset_name+'unitcgs'] != units_ar).all():
+            msg = "Density units in existing file are different than those provided.\n"
+            raise ValueError(msg)
+    else:
+        pdata.attrs[dset_name+'unitname'] = units_name
+        pdata.attrs[dset_name+'unitcgs'] = units_ar            
+        
     rhosize = struct.unpack('<I',f.read(4))[0]
     
     snapname = "Snapshot{0:05}".format(snapnum)
     if ngas:
         if t0_name in pdata.keys():
             try:
-                pdata[t0_name].create_dataset(dset_name,data=fromstring(f.read(4*ngas),dtype='f'))
+                dset = pdata[t0_name].create_dataset(dset_name,data=fromstring(f.read(4*ngas),dtype='f'))
             except KeyError:
                 msg = "{0} already exists under {1} in {2}".format(dset_name,t0_name,snapname)
                 raise KeyError(msg)

scripts/enbid2irate

 usage = "usage:  %prog <EnBiD binary file> <IRATE file> <snapshot number> [options]"
 parser = OptionParser(usage=usage)
 
+"""
 cosmooptions = OptionGroup(parser,"Cosmology","Specify pieces of the cosmology that aren't included in the Gadget file header.")
 cosmooptions.add_option("--s8","--sigma8",dest="sigma8",type="float",help="Optionally provide sigma_8 to store as an attribute to the Cosmology group.  Needed for a valid IRATE file, but only needs to be provided once for each file.  If the output file already contains a value for sigma_8 and it doesn't match the value provided here, the code will exit.",default=None)
 cosmooptions.add_option("--ns","--n_s",dest="ns",type="float",help="Optionally provide n_s, the power spectrum tilt, to store as an attribute to the Cosmology group.  Needed for a valid IRATE file, but only needs to be provided once for each file.  If the output file already contains a value for n_s and it doesn't match the value provided here, the code will exit.",default=None)
 cosmooptions.add_option("--oB","--omegaB",dest="omegaB",type="float",help="Optionally provide omega_B, present day baryon density, to store as an attribute to the Cosmology group.  Needed for a valid IRATE file, but only needs to be provided once for each file.  If the output file already contains a value for omega_B and it doesn't match the value provided here, the code will exit.",default=None)
+"""
 
 outoptions = OptionGroup(parser,"Output Options","Modify the format and organization of the output file.")
 outoptions.add_option("--t0name","--gasname",dest="gasname",help="Name for group that gas particles are saved under.  Default = %default",default="Gas")
 if " " in ops.gasname or " " in ops.haloname or " " in ops.diskname or " " in ops.bulgename or " " in ops.starname or " " in ops.bndryname:
     print "Sorry, names for groups cannot contain spaces."
     sys.exit(1337)
+    
+for n in [ops.gasname,ops.haloname,ops.diskname,ops.bulgename,ops.starname,ops.bndryname]:
+    if not n.startswith('Gas') and not n.startswith('Dark') and not n.startswith('Star'):
+        print "Sorry, names for groups must start with either 'Gas', 'Dark', or 'Star'."
 
 try:
-    read_and_write_enbid(inname,outname,snapnum,ops.gname,ops.sigma8,ops.ns,ops.omegaB,
+    read_and_write_enbid_binary(inname,outname,snapnum,,ops.gname,
     ops.gasname,ops.haloname,ops.diskname,ops.bulgename,ops.starname,ops.bndryname,
     ops.uname,units)
 except Exception,e: