[yt-svn] commit/yt: xarthisius: sunrise_exporter: fix import of kpc_per_cm and sec_per_year that now reside in yt.utilities.physical_ratios
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Jan 28 11:10:47 PST 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/150126b6a5b5/
Changeset: 150126b6a5b5
Branch: yt
User: xarthisius
Date: 2016-01-28 19:02:45+00:00
Summary: sunrise_exporter: fix import of kpc_per_cm and sec_per_year that now reside in yt.utilities.physical_ratios
Affected #: 1 file
diff -r e14103b2c5950477b6ed23c988277d03c9db408a -r 150126b6a5b559611cab2f30a66094e3e7e51d30 yt/analysis_modules/sunrise_export/sunrise_exporter.py
--- a/yt/analysis_modules/sunrise_export/sunrise_exporter.py
+++ b/yt/analysis_modules/sunrise_export/sunrise_exporter.py
@@ -16,7 +16,7 @@
try:
import pyfits
-except ImportError:
+except ImportError:
pass
import os
@@ -27,7 +27,7 @@
from yt import add_field
from yt.funcs import get_pbar, mylog
-from yt.utilities.physical_constants import \
+from yt.utilities.physical_ratios import \
kpc_per_cm, \
sec_per_year
@@ -51,11 +51,11 @@
The filename of the output FITS file.
fc : array
The center of the extraction region
- fwidth : array
+ fwidth : array
Ensure this radius around the center is enclosed
Array format is (nx,ny,nz) where each element is floating point
in unitary position units where 0 is leftmost edge and 1
- the rightmost.
+ the rightmost.
Notes
-----
@@ -67,7 +67,7 @@
"""
fc = np.array(fc)
fwidth = np.array(fwidth)
-
+
#we must round the dle,dre to the nearest root grid cells
ile,ire,super_level,ncells_wide= \
round_ncells_wide(ds.domain_dimensions,fc-fwidth,fc+fwidth,nwide=ncells_wide)
@@ -80,7 +80,7 @@
mylog.info("to [%1.5f %1.5f %1.5f]-[%1.5f %1.5f %1.5f]"%(tuple(fle)+tuple(fre)))
#Create a list of the star particle properties in PARTICLE_DATA
- #Include ID, parent-ID, position, velocity, creation_mass,
+ #Include ID, parent-ID, position, velocity, creation_mass,
#formation_time, mass, age_m, age_l, metallicity, L_bol
particle_data,nstars = prepare_star_particles(ds,star_particle_type,fle=fle,fre=fre,
dd=dd,**kwargs)
@@ -89,7 +89,7 @@
#For every leaf (not-refined) cell we have a column n GRIDDATA
#Include mass_gas, mass_metals, gas_temp_m, gas_teff_m, cell_volume, SFR
#since the octree always starts with one cell, an our 0-level mesh
- #may have many cells, we must create the octree region sitting
+ #may have many cells, we must create the octree region sitting
#ontop of the first mesh by providing a negative level
output, refinement,dd,nleaf = prepare_octree(ds,ile,start_level=super_level,
debug=debug,dd=dd,center=fc)
@@ -140,7 +140,7 @@
print(" with %i halos"%num_halos)
dle,dre = domain
dle, dre = np.array(dle),np.array(dre)
- fn = fni
+ fn = fni
fn += "%03i_%03i_%03i-"%tuple(dle)
fn += "%03i_%03i_%03i"%tuple(dre)
fnf = fn + '.fits'
@@ -169,10 +169,10 @@
domains[(dle,dre)] += halo,
else:
domains[(dle,dre)] = [halo,]
- #for niceness, let's process the domains in order of
+ #for niceness, let's process the domains in order of
#the one with the most halos
domains_list = [(len(v),k,v) for k,v in domains.items()]
- domains_list.sort()
+ domains_list.sort()
domains_list.reverse() #we want the most populated domains first
return domains_list
@@ -187,12 +187,12 @@
def _temp_times_mass(field, data):
return data["Temperature"]*data["CellMassMsun"]
add_field("TemperatureTimesCellMassMsun", function=_temp_times_mass)
- fields = ["CellMassMsun","TemperatureTimesCellMassMsun",
+ fields = ["CellMassMsun","TemperatureTimesCellMassMsun",
"MetalMass","CellVolumeCode"]
-
+
#gather the field data from octs
pbar = get_pbar("Retrieving field data",len(fields))
- field_data = []
+ field_data = []
for fi,f in enumerate(fields):
field_data += dd[f],
pbar.update(fi)
@@ -202,9 +202,9 @@
#first we cast every cell as an oct
#ngrids = np.max([g.id for g in ds._grids])
grids = {}
- levels_all = {}
+ levels_all = {}
levels_finest = {}
- for l in range(100):
+ for l in range(100):
levels_finest[l]=0
levels_all[l]=0
pbar = get_pbar("Initializing octs ",len(ds.index.grids))
@@ -230,10 +230,10 @@
g.clear_data()
pbar.update(gi)
pbar.finish()
-
+
#create the octree grid list
#oct_list = amr_utils.OctreeGridList(grids)
-
+
#initialize arrays to be passed to the recursion algo
o_length = np.sum(levels_all.values())
r_length = np.sum(levels_all.values())
@@ -253,7 +253,7 @@
ile,
pos,
grids[0], #we always start on the root grid
- hs,
+ hs,
output,refined,levels,
grids,
start_level,
@@ -261,14 +261,14 @@
debug=printing,
tracker=pbar)
pbar.finish()
- #by time we get it here the 'current' position is actually
+ #by time we get it here the 'current' position is actually
#for the next spot, so we're off by 1
print('took %1.2e seconds'%(time.time()-start_time))
- print('refinement tree # of cells %i, # of leaves %i'%(pos.refined_pos,pos.output_pos))
+ print('refinement tree # of cells %i, # of leaves %i'%(pos.refined_pos,pos.output_pos))
print('first few entries :',refined[:12])
output = output[:pos.output_pos]
- refined = refined[:pos.refined_pos]
- levels = levels[:pos.refined_pos]
+ refined = refined[:pos.refined_pos]
+ levels = levels[:pos.refined_pos]
return output,refined,dd,pos.refined_pos
def print_oct(data,nd=None,nc=None):
@@ -304,7 +304,7 @@
debug=None,tracker=True):
if tracker is not None:
if pos.refined_pos%1000 == 500 : tracker.update(pos.refined_pos)
- if debug is not None:
+ if debug is not None:
debug(vars())
child_grid_index = grid.child_indices[cell_index[0],cell_index[1],cell_index[2]]
#record the refinement state
@@ -312,24 +312,24 @@
is_leaf = (child_grid_index==-1) and (level>0)
refined[pos.refined_pos] = not is_leaf #True is oct, False is leaf
ids[pos.refined_pos] = child_grid_index #True is oct, False is leaf
- pos.refined_pos+= 1
+ pos.refined_pos+= 1
if is_leaf: #never subdivide if we are on a superlevel
#then we have hit a leaf cell; write it out
for field_index in range(grid.fields.shape[0]):
output[pos.output_pos,field_index] = \
grid.fields[field_index,cell_index[0],cell_index[1],cell_index[2]]
- pos.output_pos+= 1
+ pos.output_pos+= 1
else:
assert child_grid_index>-1
#find the grid we descend into
#then find the eight cells we break up into
subgrid = grids[child_grid_index]
#calculate the floating point LE of the children
- #then translate onto the subgrid integer index
+ #then translate onto the subgrid integer index
parent_fle = grid.left_edges + cell_index*grid.dx
subgrid_ile = np.floor((parent_fle - subgrid.left_edges)/subgrid.dx)
for (vertex, hilbert_child) in hilbert:
- #vertex is a combination of three 0s and 1s to
+ #vertex is a combination of three 0s and 1s to
#denote each of the 8 octs
if level < 0:
subgrid = grid #we don't actually descend if we're a superlevel
@@ -363,10 +363,10 @@
st_table.header.update("subdivtp", "OCTREE", "Type of grid subdivision")
#not the hydro grid data
- fields = ["CellMassMsun","TemperatureTimesCellMassMsun",
+ fields = ["CellMassMsun","TemperatureTimesCellMassMsun",
"MetalMass","CellVolumeCode"]
fd = {}
- for i,f in enumerate(fields):
+ for i,f in enumerate(fields):
fd[f]=output[:,i]
del output
col_list = []
@@ -389,7 +389,7 @@
# col_list.append(pyfits.Column("L_lambda", format='D',
# array=np.zeros(size,dtype='D')))
# The units for gas_temp are really K*Msun. For older Sunrise versions
- # you must set the unit to just K
+ # you must set the unit to just K
col_list.append(pyfits.Column("gas_temp_m", format='D',
array=fd['TemperatureTimesCellMassMsun'], unit="K*Msun"))
col_list.append(pyfits.Column("gas_teff_m", format='D',
@@ -424,11 +424,11 @@
#round to the nearest power of 2
x-=1
x |= x >> 1
- x |= x >> 2
+ x |= x >> 2
x |= x >> 4
x |= x >> 8
x |= x >> 16
- x+=1
+ x+=1
return x
def round_ncells_wide(dds,fle,fre,nwide=None):
@@ -452,7 +452,7 @@
width += 0.1/dds
#quit if idxq is true:
idxq = idx[0]>0 and np.all(idx==idx[0])
- out = np.all(fle>cfle) and np.all(fre<cfre)
+ out = np.all(fle>cfle) and np.all(fre<cfre)
out &= abs(np.log2(idx[0])-np.rint(np.log2(idx[0])))<1e-5 #nwide should be a power of 2
assert width[0] < 1.1 #can't go larger than the simulation volume
nwide = idx[0]
@@ -474,13 +474,13 @@
def round_nearest_edge(ds,fle,fre):
dds = ds.domain_dimensions
ile = np.floor(fle*dds).astype('int')
- ire = np.ceil(fre*dds).astype('int')
-
+ ire = np.ceil(fre*dds).astype('int')
+
#this is the number of cells the super octree needs to expand to
#must round to the nearest power of 2
width = np.max(ire-ile)
width = nearest_power(width)
-
+
maxlevel = -np.rint(np.log2(width)).astype('int')
return ile,ire,maxlevel
@@ -534,16 +534,16 @@
col_list.append(pyfits.Column("radius", format="D", array=radius, unit="kpc"))
col_list.append(pyfits.Column("mass", format="D", array=current_mass, unit="Msun"))
col_list.append(pyfits.Column("age", format="D", array=age,unit='yr'))
- #For particles, Sunrise takes
+ #For particles, Sunrise takes
#the dimensionless metallicity, not the mass of the metals
col_list.append(pyfits.Column("metallicity", format="D",
- array=metallicity,unit="Msun"))
-
+ array=metallicity,unit="Msun"))
+
#make the table
cols = pyfits.ColDefs(col_list)
pd_table = pyfits.new_table(cols)
pd_table.name = "PARTICLEDATA"
-
+
#make sure we have nonzero particle number
assert pd_table.data.shape[0]>0
return pd_table,np.sum(idx)
@@ -553,7 +553,7 @@
"""Add three Eulerian fields Sunrise uses"""
def _MetalMass(field, data):
return data["Metallicity"] * data["CellMassMsun"]
-
+
def _convMetalMass(data):
return 1.0
add_field("MetalMass", function=_MetalMass,
@@ -594,7 +594,7 @@
self.sgn[i] = self.sgn[j]
self.sgn[j] = axis
def reorder(self,i,j,k):
- ndim = [self.dim[i],self.dim[j],self.dim[k]]
+ ndim = [self.dim[i],self.dim[j],self.dim[k]]
nsgn = [self.sgn[i],self.sgn[j],self.sgn[k]]
self.dim = ndim
self.sgn = nsgn
@@ -640,22 +640,22 @@
vertex[self.dim[0]] += self.sgn[0]
j+=1
yield vertex, self.descend(j)
- vertex[self.dim[1]] += self.sgn[1]
+ vertex[self.dim[1]] += self.sgn[1]
j+=1
yield vertex, self.descend(j)
- vertex[self.dim[0]] -= self.sgn[0]
+ vertex[self.dim[0]] -= self.sgn[0]
j+=1
yield vertex, self.descend(j)
- vertex[self.dim[2]] += self.sgn[2]
+ vertex[self.dim[2]] += self.sgn[2]
j+=1
yield vertex, self.descend(j)
- vertex[self.dim[0]] += self.sgn[0]
+ vertex[self.dim[0]] += self.sgn[0]
j+=1
yield vertex, self.descend(j)
- vertex[self.dim[1]] -= self.sgn[1]
+ vertex[self.dim[1]] -= self.sgn[1]
j+=1
yield vertex, self.descend(j)
- vertex[self.dim[0]] -= self.sgn[0]
+ vertex[self.dim[0]] -= self.sgn[0]
j+=1
yield vertex, self.descend(j)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list