[yt-svn] commit/yt: 4 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Sep 23 12:14:25 PDT 2014
4 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/333f3475ae4d/
Changeset: 333f3475ae4d
Branch: yt
User: atmyers
Date: 2014-09-21 22:16:16+00:00
Summary: Orion Particle fixes
Affected #: 5 files
diff -r f254dd511c836dae1f313cc1963d0721dd6b19e9 -r 333f3475ae4da44d4af67cd2903ac894959f8907 yt/frontends/boxlib/data_structures.py
--- a/yt/frontends/boxlib/data_structures.py
+++ b/yt/frontends/boxlib/data_structures.py
@@ -638,6 +638,20 @@
self._read_particles()
# self.io = IOHandlerOrion
+ def _detect_output_fields(self):
+ # This is all done in _parse_header_file
+ self.field_list = [("boxlib", f) for f in
+ self.dataset._field_list]
+ self.field_indexes = dict((f[1], i)
+ for i, f in enumerate(self.field_list))
+ # There are times when field_list may change. We copy it here to
+ # avoid that possibility.
+ self.field_order = [f for f in self.field_list]
+
+ # look for particle fields
+ pfield_list = [("io", c) for c in self.io.particle_field_index.keys()]
+ self.field_list.extend(pfield_list)
+
def _read_particles(self):
"""
reads in particles and assigns them to grids. Will search for
@@ -670,8 +684,8 @@
# copied from object_finding_mixin.py
mask = np.ones(self.num_grids)
for i in xrange(len(coord)):
- np.choose(np.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
- np.choose(np.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask)
+ np.choose(np.greater(self.grid_left_edge.d[:,i],coord[i]), (mask,0), mask)
+ np.choose(np.greater(self.grid_right_edge.d[:,i],coord[i]), (0,mask), mask)
ind = np.where(mask == 1)
selected_grids = self.grids[ind]
# in orion, particles always live on the finest level.
@@ -915,7 +929,7 @@
if v in ("F", "T"):
pcast = bool
else:
- syms = (".", "D+", "D-", "E+", "E-")
+ syms = (".", "D+", "D-", "E+", "E-", "E", "D")
if any(sym in v.upper() for sym in syms for v in vals.split()):
pcast = float
else:
diff -r f254dd511c836dae1f313cc1963d0721dd6b19e9 -r 333f3475ae4da44d4af67cd2903ac894959f8907 yt/frontends/boxlib/io.py
--- a/yt/frontends/boxlib/io.py
+++ b/yt/frontends/boxlib/io.py
@@ -21,6 +21,7 @@
from yt.utilities.io_handler import \
BaseIOHandler
from yt.funcs import mylog, defaultdict
+from yt.frontends.chombo.io import parse_orion_sinks
class IOHandlerBoxlib(BaseIOHandler):
@@ -82,69 +83,59 @@
class IOHandlerOrion(IOHandlerBoxlib):
_dataset_type = "orion_native"
+ _particle_filename = None
+ @property
+ def particle_filename(self):
+ fn = self.ds.output_dir + "/StarParticles"
+ if not os.path.exists(fn):
+ fn = self.ds.output_dir + "/SinkParticles"
+ self._particle_filename = fn
+ return self._particle_filename
+
+ _particle_field_index = None
+ @property
+ def particle_field_index(self):
+
+ index = parse_orion_sinks(self.particle_filename)
+
+ self._particle_field_index = index
+ return self._particle_field_index
+
+ def _read_particle_selection(self, chunks, selector, fields):
+ rv = {}
+ chunks = list(chunks)
+
+ if selector.__class__.__name__ == "GridSelector":
+
+ if not (len(chunks) == len(chunks[0].objs) == 1):
+ raise RuntimeError
+
+ grid = chunks[0].objs[0]
+
+ for ftype, fname in fields:
+ rv[ftype, fname] = self._read_particles(grid, fname)
+
+ return rv
+
+ rv = {f: np.array([]) for f in fields}
+ for chunk in chunks:
+ for grid in chunk.objs:
+ for ftype, fname in fields:
+ data = self._read_particles(grid, fname)
+ rv[ftype, fname] = np.concatenate((data, rv[ftype, fname]))
+ return rv
+
def _read_particles(self, grid, field):
"""
parses the Orion Star Particle text files
-
+
"""
- fn = grid.ds.fullplotdir + "/StarParticles"
- if not os.path.exists(fn):
- fn = grid.ds.fullplotdir + "/SinkParticles"
-
- # Figure out the format of the particle file
- with open(fn, 'r') as f:
- lines = f.readlines()
- line = lines[1]
-
- # The basic fields that all sink particles have
- index = {'particle_mass': 0,
- 'particle_position_x': 1,
- 'particle_position_y': 2,
- 'particle_position_z': 3,
- 'particle_momentum_x': 4,
- 'particle_momentum_y': 5,
- 'particle_momentum_z': 6,
- 'particle_angmomen_x': 7,
- 'particle_angmomen_y': 8,
- 'particle_angmomen_z': 9,
- 'particle_mlast': 10,
- 'particle_mdeut': 11,
- 'particle_n': 12,
- 'particle_mdot': 13,
- 'particle_burnstate': 14,
- 'particle_id': 15}
-
- if len(line.strip().split()) == 11:
- # these are vanilla sinks, do nothing
- pass
-
- elif len(line.strip().split()) == 17:
- # these are old-style stars, add stellar model parameters
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15
-
- elif len(line.strip().split()) == 18:
- # these are the newer style, add luminosity as well
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15,
- index['particle_luminosity']= 16
-
- else:
- # give a warning if none of the above apply:
- mylog.warning('Warning - could not figure out particle output file')
- mylog.warning('These results could be nonsense!')
+ fn = self.particle_filename
def read(line, field):
- return float(line.strip().split(' ')[index[field]])
+ entry = line.strip().split(' ')[self.particle_field_index[field]]
+ return np.float(entry)
with open(fn, 'r') as f:
lines = f.readlines()
@@ -154,11 +145,12 @@
coord = read(line, "particle_position_x"), \
read(line, "particle_position_y"), \
read(line, "particle_position_z")
- if ( (grid.LeftEdge < coord).all() and
+ if ( (grid.LeftEdge <= coord).all() and
(coord <= grid.RightEdge).all() ):
particles.append(read(line, field))
return np.array(particles)
+
class IOHandlerCastro(IOHandlerBoxlib):
_dataset_type = "castro_native"
diff -r f254dd511c836dae1f313cc1963d0721dd6b19e9 -r 333f3475ae4da44d4af67cd2903ac894959f8907 yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -20,28 +20,24 @@
import numpy as np
import six
-from collections import \
- defaultdict
from stat import \
- ST_CTIME
+ ST_CTIME
from yt.funcs import *
from yt.data_objects.grid_patch import \
- AMRGridPatch
+ AMRGridPatch
from yt.geometry.grid_geometry_handler import \
- GridIndex
+ GridIndex
from yt.data_objects.static_output import \
- Dataset
+ Dataset
from yt.utilities.definitions import \
- mpc_conversion, sec_conversion
+ mpc_conversion, sec_conversion
from yt.utilities.file_handler import \
HDF5FileHandler
from yt.utilities.parallel_tools.parallel_analysis_interface import \
- parallel_root_only
+ parallel_root_only
from yt.utilities.lib.misc_utilities import \
get_box_grids_level
-from yt.utilities.io_handler import \
- io_registry
from .fields import ChomboFieldInfo, Orion2FieldInfo, \
ChomboPICFieldInfo1D, ChomboPICFieldInfo2D, ChomboPICFieldInfo3D, \
@@ -99,7 +95,7 @@
grid = ChomboGrid
_data_file = None
- def __init__(self,ds,dataset_type='chombo_hdf5'):
+ def __init__(self, ds, dataset_type='chombo_hdf5'):
self.domain_left_edge = ds.domain_left_edge
self.domain_right_edge = ds.domain_right_edge
self.dataset_type = dataset_type
@@ -107,7 +103,7 @@
if ds.dimensionality == 1:
self.dataset_type = "chombo1d_hdf5"
if ds.dimensionality == 2:
- self.dataset_type = "chombo2d_hdf5"
+ self.dataset_type = "chombo2d_hdf5"
self.field_indexes = {}
self.dataset = weakref.proxy(ds)
@@ -119,7 +115,7 @@
self.float_type = self._handle['Chombo_global'].attrs['testReal'].dtype.name
self._levels = [key for key in self._handle.keys() if key.startswith('level')]
- GridIndex.__init__(self,ds,dataset_type)
+ GridIndex.__init__(self, ds, dataset_type)
self._read_particles()
@@ -250,6 +246,7 @@
storage_filename = None, ini_filename = None):
self.fluid_types += ("chombo",)
self._handle = HDF5FileHandler(filename)
+ self.dataset_type = dataset_type
# look up the dimensionality of the dataset
D = self._handle['Chombo_global/'].attrs['SpaceDim']
@@ -257,8 +254,6 @@
self.dataset_type = 'chombo1d_hdf5'
if D == 2:
self.dataset_type = 'chombo2d_hdf5'
- if D == 3:
- self.dataset_type = 'chombo_hdf5'
# some datasets will not be time-dependent, and to make
# matters worse, the simulation time is not always
@@ -483,7 +478,7 @@
self.periodicity = [0]*3
for il,ll in enumerate(lines[lines.index('[Boundary]')+2:lines.index('[Boundary]')+2+6:2]):
self.periodicity[il] = (ll.split()[1] == 'periodic')
- self.periodicity=tuple(self.periodicity)
+ self.periodicity = tuple(self.periodicity)
for il,ll in enumerate(lines[lines.index('[Parameters]')+2:]):
if (ll.split()[0] == 'GAMMA'):
self.gamma = float(ll.split()[1])
@@ -525,6 +520,19 @@
def __init__(self, ds, dataset_type="orion_chombo_native"):
ChomboHierarchy.__init__(self, ds, dataset_type)
+ def _detect_output_fields(self):
+
+ # look for fluid fields
+ output_fields = []
+ for key, val in self._handle.attrs.items():
+ if key.startswith("component"):
+ output_fields.append(val)
+ self.field_list = [("chombo", c) for c in output_fields]
+
+ # look for particle fields
+ pfield_list = [("io", c) for c in self.io.particle_field_index.keys()]
+ self.field_list.extend(pfield_list)
+
def _read_particles(self):
self.particle_filename = self.index_filename[:-4] + 'sink'
if not os.path.exists(self.particle_filename): return
@@ -540,8 +548,8 @@
# copied from object_finding_mixin.py
mask=np.ones(self.num_grids)
for i in xrange(len(coord)):
- np.choose(np.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
- np.choose(np.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask)
+ np.choose(np.greater(self.grid_left_edge.d[:,i],coord[i]), (mask,0), mask)
+ np.choose(np.greater(self.grid_right_edge.d[:,i],coord[i]), (0,mask), mask)
ind = np.where(mask == 1)
selected_grids = self.grids[ind]
# in orion, particles always live on the finest level.
@@ -562,7 +570,7 @@
def __init__(self, filename, dataset_type='orion_chombo_native',
storage_filename = None, ini_filename = None):
- ChomboDataset.__init__(self, filename, dataset_type,
+ ChomboDataset.__init__(self, filename, dataset_type,
storage_filename, ini_filename)
def _parse_parameter_file(self):
diff -r f254dd511c836dae1f313cc1963d0721dd6b19e9 -r 333f3475ae4da44d4af67cd2903ac894959f8907 yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -35,11 +35,13 @@
vel_units = "code_length / code_time"
b_units = "code_magnetic"
+
# Chombo does not have any known fields by itself.
class ChomboFieldInfo(FieldInfoContainer):
known_other_fields = ()
known_particle_fields = ()
+
# Orion 2 Fields
# We duplicate everything here from Boxlib, because we want to be able to
# subclass it and that can be somewhat tricky.
@@ -174,18 +176,22 @@
num_neighbors=num_neighbors,
ftype=ftype)
+
def _dummy_position(field, data):
return 0.5*np.ones_like(data['particle_position_x'])
+
def _dummy_velocity(field, data):
return np.zeros_like(data['particle_velocity_x'])
+
def _dummy_field(field, data):
return 0.0 * data['gravitational_field_x']
fluid_field_types = ['chombo', 'gas']
particle_field_types = ['io', 'all']
+
class ChomboPICFieldInfo2D(ChomboPICFieldInfo3D):
known_other_fields = (
("density", (rho_units, ["density", "Density"], None)),
@@ -217,6 +223,7 @@
particle_type = True,
units = "code_length / code_time")
+
class ChomboPICFieldInfo1D(ChomboPICFieldInfo3D):
known_other_fields = (
("density", (rho_units, ["density", "Density"], None)),
@@ -253,6 +260,7 @@
particle_type = True,
units = "code_length / code_time")
+
class PlutoFieldInfo(ChomboFieldInfo):
known_other_fields = (
("rho", (rho_units, ["density"], None)),
diff -r f254dd511c836dae1f313cc1963d0721dd6b19e9 -r 333f3475ae4da44d4af67cd2903ac894959f8907 yt/frontends/chombo/io.py
--- a/yt/frontends/chombo/io.py
+++ b/yt/frontends/chombo/io.py
@@ -12,8 +12,7 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
-import h5py
-import os
+
import re
import numpy as np
from yt.utilities.logger import ytLogger as mylog
@@ -21,6 +20,7 @@
from yt.utilities.io_handler import \
BaseIOHandler
+
class IOHandlerChomboHDF5(BaseIOHandler):
_dataset_type = "chombo_hdf5"
_offset_string = 'data:offsets=0'
@@ -67,19 +67,19 @@
comp_number = int(re.match('particle_component_(\d)', key).groups()[0])
field_dict[val] = comp_number
self._particle_field_index = field_dict
- return self._particle_field_index
-
+ return self._particle_field_index
+
def _read_field_names(self,grid):
ncomp = int(self._handle.attrs['num_components'])
fns = [c[1] for c in f.attrs.items()[-ncomp-1:-1]]
-
+
def _read_data(self,grid,field):
lstring = 'level_%i' % grid.Level
lev = self._handle[lstring]
dims = grid.ActiveDimensions
shape = grid.ActiveDimensions + 2*self.ghost
boxsize = shape.prod()
-
+
grid_offset = lev[self._offset_string][grid._level_id]
start = grid_offset+self.field_dict[field]*boxsize
stop = start + boxsize
@@ -138,7 +138,7 @@
return rv
- rv = {f:np.array([]) for f in fields}
+ rv = {f: np.array([]) for f in fields}
for chunk in chunks:
for grid in chunk.objs:
for ftype, fname in fields:
@@ -161,7 +161,7 @@
# convert between the global grid id and the id on this level
grid_levels = np.array([g.Level for g in self.ds.index.grids])
- grid_ids = np.array([g.id for g in self.ds.index.grids])
+ grid_ids = np.array([g.id for g in self.ds.index.grids])
grid_level_offset = grid_ids[np.where(grid_levels == grid.Level)[0][0]]
lo = grid.id - grid_level_offset
hi = lo + 1
@@ -173,6 +173,7 @@
data = self._handle[lev]['particles:data'][offsets[lo]:offsets[hi]]
return np.asarray(data[field_index::items_per_particle], dtype=np.float64, order='F')
+
class IOHandlerChombo2DHDF5(IOHandlerChomboHDF5):
_dataset_type = "chombo2d_hdf5"
_offset_string = 'data:offsets=0'
@@ -185,6 +186,7 @@
self.dim = 2
self._read_ghost_info()
+
class IOHandlerChombo1DHDF5(IOHandlerChomboHDF5):
_dataset_type = "chombo1d_hdf5"
_offset_string = 'data:offsets=0'
@@ -197,6 +199,7 @@
self._handle = ds._handle
self._read_ghost_info()
+
class IOHandlerPlutoHDF5(IOHandlerChomboHDF5):
_dataset_type = "pluto_chombo_native"
_offset_string = 'data:offsets=0'
@@ -207,65 +210,88 @@
self.ds = ds
self._handle = ds._handle
+
+def parse_orion_sinks(fn):
+ '''
+
+ Orion sink particles are stored in text files. This function
+ is for figuring what particle fields are present based on the
+ number of entries per line in the *.sink file.
+
+ '''
+
+ # Figure out the format of the particle file
+ with open(fn, 'r') as f:
+ lines = f.readlines()
+ line = lines[1]
+
+ # The basic fields that all sink particles have
+ index = {'particle_mass': 0,
+ 'particle_position_x': 1,
+ 'particle_position_y': 2,
+ 'particle_position_z': 3,
+ 'particle_momentum_x': 4,
+ 'particle_momentum_y': 5,
+ 'particle_momentum_z': 6,
+ 'particle_angmomen_x': 7,
+ 'particle_angmomen_y': 8,
+ 'particle_angmomen_z': 9,
+ 'particle_id': -1}
+
+ if len(line.strip().split()) == 11:
+ # these are vanilla sinks, do nothing
+ pass
+
+ elif len(line.strip().split()) == 17:
+ # these are old-style stars, add stellar model parameters
+ index['particle_mlast'] = 10
+ index['particle_r'] = 11
+ index['particle_mdeut'] = 12
+ index['particle_n'] = 13
+ index['particle_mdot'] = 14,
+ index['particle_burnstate'] = 15
+
+ elif len(line.strip().split()) == 18:
+ # these are the newer style, add luminosity as well
+ index['particle_mlast'] = 10
+ index['particle_r'] = 11
+ index['particle_mdeut'] = 12
+ index['particle_n'] = 13
+ index['particle_mdot'] = 14,
+ index['particle_burnstate'] = 15,
+ index['particle_luminosity']= 16
+
+ else:
+ # give a warning if none of the above apply:
+ mylog.warning('Warning - could not figure out particle output file')
+ mylog.warning('These results could be nonsense!')
+
+ return index
+
+
class IOHandlerOrion2HDF5(IOHandlerChomboHDF5):
_dataset_type = "orion_chombo_native"
+ _particle_field_index = None
+ @property
+ def particle_field_index(self):
+
+ fn = self.ds.fullplotdir[:-4] + "sink"
+
+ index = parse_orion_sinks(fn)
+
+ self._particle_field_index = index
+ return self._particle_field_index
+
def _read_particles(self, grid, field):
"""
parses the Orion Star Particle text files
"""
- fn = grid.ds.fullplotdir[:-4] + "sink"
-
- # Figure out the format of the particle file
- with open(fn, 'r') as f:
- lines = f.readlines()
- line = lines[1]
-
- # The basic fields that all sink particles have
- index = {'particle_mass': 0,
- 'particle_position_x': 1,
- 'particle_position_y': 2,
- 'particle_position_z': 3,
- 'particle_momentum_x': 4,
- 'particle_momentum_y': 5,
- 'particle_momentum_z': 6,
- 'particle_angmomen_x': 7,
- 'particle_angmomen_y': 8,
- 'particle_angmomen_z': 9,
- 'particle_id': -1}
-
- if len(line.strip().split()) == 11:
- # these are vanilla sinks, do nothing
- pass
-
- elif len(line.strip().split()) == 17:
- # these are old-style stars, add stellar model parameters
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15
-
- elif len(line.strip().split()) == 18:
- # these are the newer style, add luminosity as well
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15,
- index['particle_luminosity']= 16
-
- else:
- # give a warning if none of the above apply:
- mylog.warning('Warning - could not figure out particle output file')
- mylog.warning('These results could be nonsense!')
-
def read(line, field):
- return float(line.strip().split(' ')[index[field]])
+ entry = line.strip().split(' ')[self.particle_field_index[field]]
+ return np.float(entry)
fn = grid.ds.fullplotdir[:-4] + "sink"
with open(fn, 'r') as f:
@@ -274,9 +300,9 @@
for line in lines[1:]:
if grid.NumberOfParticles > 0:
coord = read(line, "particle_position_x"), \
- read(line, "particle_position_y"), \
- read(line, "particle_position_z")
- if ( (grid.LeftEdge < coord).all() and
- (coord <= grid.RightEdge).all() ):
+ read(line, "particle_position_y"), \
+ read(line, "particle_position_z")
+ if ((grid.LeftEdge <= coord).all() and
+ (coord <= grid.RightEdge).all() ):
particles.append(read(line, field))
return np.array(particles)
https://bitbucket.org/yt_analysis/yt/commits/49a25f8da335/
Changeset: 49a25f8da335
Branch: yt
User: atmyers
Date: 2014-09-21 22:24:00+00:00
Summary: I didn't mean to remove this
Affected #: 1 file
diff -r 333f3475ae4da44d4af67cd2903ac894959f8907 -r 49a25f8da33573a154c04a8744b5d6ee11b1cb39 yt/__init__.py
--- a/yt/__init__.py
+++ b/yt/__init__.py
@@ -150,7 +150,7 @@
TransferFunctionHelper
from yt.utilities.parallel_tools.parallel_analysis_interface import \
- parallel_objects, enable_parallelism
+ parallel_objects, enable_parallelism, communication_system
from yt.convenience import \
load, simulation
https://bitbucket.org/yt_analysis/yt/commits/4424515ac343/
Changeset: 4424515ac343
Branch: yt
User: atmyers
Date: 2014-09-21 23:20:07+00:00
Summary: check for the existence of the sink particle file before adding particle stuff to the field list
Affected #: 2 files
diff -r 49a25f8da33573a154c04a8744b5d6ee11b1cb39 -r 4424515ac3431e661a2ea9ddc27c753a002c22ba yt/frontends/boxlib/data_structures.py
--- a/yt/frontends/boxlib/data_structures.py
+++ b/yt/frontends/boxlib/data_structures.py
@@ -649,6 +649,15 @@
self.field_order = [f for f in self.field_list]
# look for particle fields
+ self.particle_filename = None
+ for particle_filename in ["StarParticles", "SinkParticles"]:
+ fn = os.path.join(self.ds.output_dir, particle_filename)
+ if os.path.exists(fn):
+ self.particle_filename = fn
+
+ if self.particle_filename is None:
+ return
+
pfield_list = [("io", c) for c in self.io.particle_field_index.keys()]
self.field_list.extend(pfield_list)
@@ -663,9 +672,8 @@
"""
self.grid_particle_count = np.zeros(len(self.grids))
- for particle_filename in ["StarParticles", "SinkParticles"]:
- fn = os.path.join(self.ds.output_dir, particle_filename)
- if os.path.exists(fn): self._read_particle_file(fn)
+ if self.particle_filename is not None:
+ self._read_particle_file(self.particle_filename)
def _read_particle_file(self, fn):
"""actually reads the orion particle data file itself.
diff -r 49a25f8da33573a154c04a8744b5d6ee11b1cb39 -r 4424515ac3431e661a2ea9ddc27c753a002c22ba yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -530,11 +530,12 @@
self.field_list = [("chombo", c) for c in output_fields]
# look for particle fields
+ self.particle_filename = self.index_filename[:-4] + 'sink'
+ if not os.path.exists(self.particle_filename): return
pfield_list = [("io", c) for c in self.io.particle_field_index.keys()]
self.field_list.extend(pfield_list)
def _read_particles(self):
- self.particle_filename = self.index_filename[:-4] + 'sink'
if not os.path.exists(self.particle_filename): return
with open(self.particle_filename, 'r') as f:
lines = f.readlines()
https://bitbucket.org/yt_analysis/yt/commits/4cf5c5369df9/
Changeset: 4cf5c5369df9
Branch: yt
User: ngoldbaum
Date: 2014-09-23 19:14:16+00:00
Summary: Merged in atmyers/yt (pull request #1218)
Restoring Particle support for Orion in yt 3.
Affected #: 5 files
diff -r c193ac5077d28b99051393659da11c0e74125b6d -r 4cf5c5369df9b012759ab979330d8e356d1b0e00 yt/frontends/boxlib/data_structures.py
--- a/yt/frontends/boxlib/data_structures.py
+++ b/yt/frontends/boxlib/data_structures.py
@@ -638,6 +638,29 @@
self._read_particles()
# self.io = IOHandlerOrion
+ def _detect_output_fields(self):
+ # This is all done in _parse_header_file
+ self.field_list = [("boxlib", f) for f in
+ self.dataset._field_list]
+ self.field_indexes = dict((f[1], i)
+ for i, f in enumerate(self.field_list))
+ # There are times when field_list may change. We copy it here to
+ # avoid that possibility.
+ self.field_order = [f for f in self.field_list]
+
+ # look for particle fields
+ self.particle_filename = None
+ for particle_filename in ["StarParticles", "SinkParticles"]:
+ fn = os.path.join(self.ds.output_dir, particle_filename)
+ if os.path.exists(fn):
+ self.particle_filename = fn
+
+ if self.particle_filename is None:
+ return
+
+ pfield_list = [("io", c) for c in self.io.particle_field_index.keys()]
+ self.field_list.extend(pfield_list)
+
def _read_particles(self):
"""
reads in particles and assigns them to grids. Will search for
@@ -649,9 +672,8 @@
"""
self.grid_particle_count = np.zeros(len(self.grids))
- for particle_filename in ["StarParticles", "SinkParticles"]:
- fn = os.path.join(self.ds.output_dir, particle_filename)
- if os.path.exists(fn): self._read_particle_file(fn)
+ if self.particle_filename is not None:
+ self._read_particle_file(self.particle_filename)
def _read_particle_file(self, fn):
"""actually reads the orion particle data file itself.
@@ -670,8 +692,8 @@
# copied from object_finding_mixin.py
mask = np.ones(self.num_grids)
for i in xrange(len(coord)):
- np.choose(np.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
- np.choose(np.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask)
+ np.choose(np.greater(self.grid_left_edge.d[:,i],coord[i]), (mask,0), mask)
+ np.choose(np.greater(self.grid_right_edge.d[:,i],coord[i]), (0,mask), mask)
ind = np.where(mask == 1)
selected_grids = self.grids[ind]
# in orion, particles always live on the finest level.
@@ -915,7 +937,7 @@
if v in ("F", "T"):
pcast = bool
else:
- syms = (".", "D+", "D-", "E+", "E-")
+ syms = (".", "D+", "D-", "E+", "E-", "E", "D")
if any(sym in v.upper() for sym in syms for v in vals.split()):
pcast = float
else:
diff -r c193ac5077d28b99051393659da11c0e74125b6d -r 4cf5c5369df9b012759ab979330d8e356d1b0e00 yt/frontends/boxlib/io.py
--- a/yt/frontends/boxlib/io.py
+++ b/yt/frontends/boxlib/io.py
@@ -21,6 +21,7 @@
from yt.utilities.io_handler import \
BaseIOHandler
from yt.funcs import mylog, defaultdict
+from yt.frontends.chombo.io import parse_orion_sinks
class IOHandlerBoxlib(BaseIOHandler):
@@ -82,69 +83,59 @@
class IOHandlerOrion(IOHandlerBoxlib):
_dataset_type = "orion_native"
+ _particle_filename = None
+ @property
+ def particle_filename(self):
+ fn = self.ds.output_dir + "/StarParticles"
+ if not os.path.exists(fn):
+ fn = self.ds.output_dir + "/SinkParticles"
+ self._particle_filename = fn
+ return self._particle_filename
+
+ _particle_field_index = None
+ @property
+ def particle_field_index(self):
+
+ index = parse_orion_sinks(self.particle_filename)
+
+ self._particle_field_index = index
+ return self._particle_field_index
+
+ def _read_particle_selection(self, chunks, selector, fields):
+ rv = {}
+ chunks = list(chunks)
+
+ if selector.__class__.__name__ == "GridSelector":
+
+ if not (len(chunks) == len(chunks[0].objs) == 1):
+ raise RuntimeError
+
+ grid = chunks[0].objs[0]
+
+ for ftype, fname in fields:
+ rv[ftype, fname] = self._read_particles(grid, fname)
+
+ return rv
+
+ rv = {f: np.array([]) for f in fields}
+ for chunk in chunks:
+ for grid in chunk.objs:
+ for ftype, fname in fields:
+ data = self._read_particles(grid, fname)
+ rv[ftype, fname] = np.concatenate((data, rv[ftype, fname]))
+ return rv
+
def _read_particles(self, grid, field):
"""
parses the Orion Star Particle text files
-
+
"""
- fn = grid.ds.fullplotdir + "/StarParticles"
- if not os.path.exists(fn):
- fn = grid.ds.fullplotdir + "/SinkParticles"
-
- # Figure out the format of the particle file
- with open(fn, 'r') as f:
- lines = f.readlines()
- line = lines[1]
-
- # The basic fields that all sink particles have
- index = {'particle_mass': 0,
- 'particle_position_x': 1,
- 'particle_position_y': 2,
- 'particle_position_z': 3,
- 'particle_momentum_x': 4,
- 'particle_momentum_y': 5,
- 'particle_momentum_z': 6,
- 'particle_angmomen_x': 7,
- 'particle_angmomen_y': 8,
- 'particle_angmomen_z': 9,
- 'particle_mlast': 10,
- 'particle_mdeut': 11,
- 'particle_n': 12,
- 'particle_mdot': 13,
- 'particle_burnstate': 14,
- 'particle_id': 15}
-
- if len(line.strip().split()) == 11:
- # these are vanilla sinks, do nothing
- pass
-
- elif len(line.strip().split()) == 17:
- # these are old-style stars, add stellar model parameters
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15
-
- elif len(line.strip().split()) == 18:
- # these are the newer style, add luminosity as well
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15,
- index['particle_luminosity']= 16
-
- else:
- # give a warning if none of the above apply:
- mylog.warning('Warning - could not figure out particle output file')
- mylog.warning('These results could be nonsense!')
+ fn = self.particle_filename
def read(line, field):
- return float(line.strip().split(' ')[index[field]])
+ entry = line.strip().split(' ')[self.particle_field_index[field]]
+ return np.float(entry)
with open(fn, 'r') as f:
lines = f.readlines()
@@ -154,11 +145,12 @@
coord = read(line, "particle_position_x"), \
read(line, "particle_position_y"), \
read(line, "particle_position_z")
- if ( (grid.LeftEdge < coord).all() and
+ if ( (grid.LeftEdge <= coord).all() and
(coord <= grid.RightEdge).all() ):
particles.append(read(line, field))
return np.array(particles)
+
class IOHandlerCastro(IOHandlerBoxlib):
_dataset_type = "castro_native"
diff -r c193ac5077d28b99051393659da11c0e74125b6d -r 4cf5c5369df9b012759ab979330d8e356d1b0e00 yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -20,28 +20,24 @@
import numpy as np
import six
-from collections import \
- defaultdict
from stat import \
- ST_CTIME
+ ST_CTIME
from yt.funcs import *
from yt.data_objects.grid_patch import \
- AMRGridPatch
+ AMRGridPatch
from yt.geometry.grid_geometry_handler import \
- GridIndex
+ GridIndex
from yt.data_objects.static_output import \
- Dataset
+ Dataset
from yt.utilities.definitions import \
- mpc_conversion, sec_conversion
+ mpc_conversion, sec_conversion
from yt.utilities.file_handler import \
HDF5FileHandler
from yt.utilities.parallel_tools.parallel_analysis_interface import \
- parallel_root_only
+ parallel_root_only
from yt.utilities.lib.misc_utilities import \
get_box_grids_level
-from yt.utilities.io_handler import \
- io_registry
from .fields import ChomboFieldInfo, Orion2FieldInfo, \
ChomboPICFieldInfo1D, ChomboPICFieldInfo2D, ChomboPICFieldInfo3D, \
@@ -99,7 +95,7 @@
grid = ChomboGrid
_data_file = None
- def __init__(self,ds,dataset_type='chombo_hdf5'):
+ def __init__(self, ds, dataset_type='chombo_hdf5'):
self.domain_left_edge = ds.domain_left_edge
self.domain_right_edge = ds.domain_right_edge
self.dataset_type = dataset_type
@@ -107,7 +103,7 @@
if ds.dimensionality == 1:
self.dataset_type = "chombo1d_hdf5"
if ds.dimensionality == 2:
- self.dataset_type = "chombo2d_hdf5"
+ self.dataset_type = "chombo2d_hdf5"
self.field_indexes = {}
self.dataset = weakref.proxy(ds)
@@ -119,7 +115,7 @@
self.float_type = self._handle['Chombo_global'].attrs['testReal'].dtype.name
self._levels = [key for key in self._handle.keys() if key.startswith('level')]
- GridIndex.__init__(self,ds,dataset_type)
+ GridIndex.__init__(self, ds, dataset_type)
self._read_particles()
@@ -250,6 +246,7 @@
storage_filename = None, ini_filename = None):
self.fluid_types += ("chombo",)
self._handle = HDF5FileHandler(filename)
+ self.dataset_type = dataset_type
# look up the dimensionality of the dataset
D = self._handle['Chombo_global/'].attrs['SpaceDim']
@@ -257,8 +254,6 @@
self.dataset_type = 'chombo1d_hdf5'
if D == 2:
self.dataset_type = 'chombo2d_hdf5'
- if D == 3:
- self.dataset_type = 'chombo_hdf5'
# some datasets will not be time-dependent, and to make
# matters worse, the simulation time is not always
@@ -483,7 +478,7 @@
self.periodicity = [0]*3
for il,ll in enumerate(lines[lines.index('[Boundary]')+2:lines.index('[Boundary]')+2+6:2]):
self.periodicity[il] = (ll.split()[1] == 'periodic')
- self.periodicity=tuple(self.periodicity)
+ self.periodicity = tuple(self.periodicity)
for il,ll in enumerate(lines[lines.index('[Parameters]')+2:]):
if (ll.split()[0] == 'GAMMA'):
self.gamma = float(ll.split()[1])
@@ -525,8 +520,22 @@
def __init__(self, ds, dataset_type="orion_chombo_native"):
ChomboHierarchy.__init__(self, ds, dataset_type)
+ def _detect_output_fields(self):
+
+ # look for fluid fields
+ output_fields = []
+ for key, val in self._handle.attrs.items():
+ if key.startswith("component"):
+ output_fields.append(val)
+ self.field_list = [("chombo", c) for c in output_fields]
+
+ # look for particle fields
+ self.particle_filename = self.index_filename[:-4] + 'sink'
+ if not os.path.exists(self.particle_filename): return
+ pfield_list = [("io", c) for c in self.io.particle_field_index.keys()]
+ self.field_list.extend(pfield_list)
+
def _read_particles(self):
- self.particle_filename = self.index_filename[:-4] + 'sink'
if not os.path.exists(self.particle_filename): return
with open(self.particle_filename, 'r') as f:
lines = f.readlines()
@@ -540,8 +549,8 @@
# copied from object_finding_mixin.py
mask=np.ones(self.num_grids)
for i in xrange(len(coord)):
- np.choose(np.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
- np.choose(np.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask)
+ np.choose(np.greater(self.grid_left_edge.d[:,i],coord[i]), (mask,0), mask)
+ np.choose(np.greater(self.grid_right_edge.d[:,i],coord[i]), (0,mask), mask)
ind = np.where(mask == 1)
selected_grids = self.grids[ind]
# in orion, particles always live on the finest level.
@@ -562,7 +571,7 @@
def __init__(self, filename, dataset_type='orion_chombo_native',
storage_filename = None, ini_filename = None):
- ChomboDataset.__init__(self, filename, dataset_type,
+ ChomboDataset.__init__(self, filename, dataset_type,
storage_filename, ini_filename)
def _parse_parameter_file(self):
diff -r c193ac5077d28b99051393659da11c0e74125b6d -r 4cf5c5369df9b012759ab979330d8e356d1b0e00 yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -35,11 +35,13 @@
vel_units = "code_length / code_time"
b_units = "code_magnetic"
+
# Chombo does not have any known fields by itself.
class ChomboFieldInfo(FieldInfoContainer):
known_other_fields = ()
known_particle_fields = ()
+
# Orion 2 Fields
# We duplicate everything here from Boxlib, because we want to be able to
# subclass it and that can be somewhat tricky.
@@ -174,18 +176,22 @@
num_neighbors=num_neighbors,
ftype=ftype)
+
def _dummy_position(field, data):
return 0.5*np.ones_like(data['particle_position_x'])
+
def _dummy_velocity(field, data):
return np.zeros_like(data['particle_velocity_x'])
+
def _dummy_field(field, data):
return 0.0 * data['gravitational_field_x']
fluid_field_types = ['chombo', 'gas']
particle_field_types = ['io', 'all']
+
class ChomboPICFieldInfo2D(ChomboPICFieldInfo3D):
known_other_fields = (
("density", (rho_units, ["density", "Density"], None)),
@@ -217,6 +223,7 @@
particle_type = True,
units = "code_length / code_time")
+
class ChomboPICFieldInfo1D(ChomboPICFieldInfo3D):
known_other_fields = (
("density", (rho_units, ["density", "Density"], None)),
@@ -253,6 +260,7 @@
particle_type = True,
units = "code_length / code_time")
+
class PlutoFieldInfo(ChomboFieldInfo):
known_other_fields = (
("rho", (rho_units, ["density"], None)),
diff -r c193ac5077d28b99051393659da11c0e74125b6d -r 4cf5c5369df9b012759ab979330d8e356d1b0e00 yt/frontends/chombo/io.py
--- a/yt/frontends/chombo/io.py
+++ b/yt/frontends/chombo/io.py
@@ -12,8 +12,7 @@
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
-import h5py
-import os
+
import re
import numpy as np
from yt.utilities.logger import ytLogger as mylog
@@ -21,6 +20,7 @@
from yt.utilities.io_handler import \
BaseIOHandler
+
class IOHandlerChomboHDF5(BaseIOHandler):
_dataset_type = "chombo_hdf5"
_offset_string = 'data:offsets=0'
@@ -67,19 +67,19 @@
comp_number = int(re.match('particle_component_(\d)', key).groups()[0])
field_dict[val] = comp_number
self._particle_field_index = field_dict
- return self._particle_field_index
-
+ return self._particle_field_index
+
def _read_field_names(self,grid):
ncomp = int(self._handle.attrs['num_components'])
fns = [c[1] for c in f.attrs.items()[-ncomp-1:-1]]
-
+
def _read_data(self,grid,field):
lstring = 'level_%i' % grid.Level
lev = self._handle[lstring]
dims = grid.ActiveDimensions
shape = grid.ActiveDimensions + 2*self.ghost
boxsize = shape.prod()
-
+
grid_offset = lev[self._offset_string][grid._level_id]
start = grid_offset+self.field_dict[field]*boxsize
stop = start + boxsize
@@ -138,7 +138,7 @@
return rv
- rv = {f:np.array([]) for f in fields}
+ rv = {f: np.array([]) for f in fields}
for chunk in chunks:
for grid in chunk.objs:
for ftype, fname in fields:
@@ -161,7 +161,7 @@
# convert between the global grid id and the id on this level
grid_levels = np.array([g.Level for g in self.ds.index.grids])
- grid_ids = np.array([g.id for g in self.ds.index.grids])
+ grid_ids = np.array([g.id for g in self.ds.index.grids])
grid_level_offset = grid_ids[np.where(grid_levels == grid.Level)[0][0]]
lo = grid.id - grid_level_offset
hi = lo + 1
@@ -173,6 +173,7 @@
data = self._handle[lev]['particles:data'][offsets[lo]:offsets[hi]]
return np.asarray(data[field_index::items_per_particle], dtype=np.float64, order='F')
+
class IOHandlerChombo2DHDF5(IOHandlerChomboHDF5):
_dataset_type = "chombo2d_hdf5"
_offset_string = 'data:offsets=0'
@@ -185,6 +186,7 @@
self.dim = 2
self._read_ghost_info()
+
class IOHandlerChombo1DHDF5(IOHandlerChomboHDF5):
_dataset_type = "chombo1d_hdf5"
_offset_string = 'data:offsets=0'
@@ -197,6 +199,7 @@
self._handle = ds._handle
self._read_ghost_info()
+
class IOHandlerPlutoHDF5(IOHandlerChomboHDF5):
_dataset_type = "pluto_chombo_native"
_offset_string = 'data:offsets=0'
@@ -207,65 +210,88 @@
self.ds = ds
self._handle = ds._handle
+
+def parse_orion_sinks(fn):
+ '''
+
+ Orion sink particles are stored in text files. This function
+ is for figuring what particle fields are present based on the
+ number of entries per line in the *.sink file.
+
+ '''
+
+ # Figure out the format of the particle file
+ with open(fn, 'r') as f:
+ lines = f.readlines()
+ line = lines[1]
+
+ # The basic fields that all sink particles have
+ index = {'particle_mass': 0,
+ 'particle_position_x': 1,
+ 'particle_position_y': 2,
+ 'particle_position_z': 3,
+ 'particle_momentum_x': 4,
+ 'particle_momentum_y': 5,
+ 'particle_momentum_z': 6,
+ 'particle_angmomen_x': 7,
+ 'particle_angmomen_y': 8,
+ 'particle_angmomen_z': 9,
+ 'particle_id': -1}
+
+ if len(line.strip().split()) == 11:
+ # these are vanilla sinks, do nothing
+ pass
+
+ elif len(line.strip().split()) == 17:
+ # these are old-style stars, add stellar model parameters
+ index['particle_mlast'] = 10
+ index['particle_r'] = 11
+ index['particle_mdeut'] = 12
+ index['particle_n'] = 13
+ index['particle_mdot'] = 14,
+ index['particle_burnstate'] = 15
+
+ elif len(line.strip().split()) == 18:
+ # these are the newer style, add luminosity as well
+ index['particle_mlast'] = 10
+ index['particle_r'] = 11
+ index['particle_mdeut'] = 12
+ index['particle_n'] = 13
+ index['particle_mdot'] = 14,
+ index['particle_burnstate'] = 15,
+ index['particle_luminosity']= 16
+
+ else:
+ # give a warning if none of the above apply:
+ mylog.warning('Warning - could not figure out particle output file')
+ mylog.warning('These results could be nonsense!')
+
+ return index
+
+
class IOHandlerOrion2HDF5(IOHandlerChomboHDF5):
_dataset_type = "orion_chombo_native"
+ _particle_field_index = None
+ @property
+ def particle_field_index(self):
+
+ fn = self.ds.fullplotdir[:-4] + "sink"
+
+ index = parse_orion_sinks(fn)
+
+ self._particle_field_index = index
+ return self._particle_field_index
+
def _read_particles(self, grid, field):
"""
parses the Orion Star Particle text files
"""
- fn = grid.ds.fullplotdir[:-4] + "sink"
-
- # Figure out the format of the particle file
- with open(fn, 'r') as f:
- lines = f.readlines()
- line = lines[1]
-
- # The basic fields that all sink particles have
- index = {'particle_mass': 0,
- 'particle_position_x': 1,
- 'particle_position_y': 2,
- 'particle_position_z': 3,
- 'particle_momentum_x': 4,
- 'particle_momentum_y': 5,
- 'particle_momentum_z': 6,
- 'particle_angmomen_x': 7,
- 'particle_angmomen_y': 8,
- 'particle_angmomen_z': 9,
- 'particle_id': -1}
-
- if len(line.strip().split()) == 11:
- # these are vanilla sinks, do nothing
- pass
-
- elif len(line.strip().split()) == 17:
- # these are old-style stars, add stellar model parameters
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15
-
- elif len(line.strip().split()) == 18:
- # these are the newer style, add luminosity as well
- index['particle_mlast'] = 10
- index['particle_r'] = 11
- index['particle_mdeut'] = 12
- index['particle_n'] = 13
- index['particle_mdot'] = 14,
- index['particle_burnstate'] = 15,
- index['particle_luminosity']= 16
-
- else:
- # give a warning if none of the above apply:
- mylog.warning('Warning - could not figure out particle output file')
- mylog.warning('These results could be nonsense!')
-
def read(line, field):
- return float(line.strip().split(' ')[index[field]])
+ entry = line.strip().split(' ')[self.particle_field_index[field]]
+ return np.float(entry)
fn = grid.ds.fullplotdir[:-4] + "sink"
with open(fn, 'r') as f:
@@ -274,9 +300,9 @@
for line in lines[1:]:
if grid.NumberOfParticles > 0:
coord = read(line, "particle_position_x"), \
- read(line, "particle_position_y"), \
- read(line, "particle_position_z")
- if ( (grid.LeftEdge < coord).all() and
- (coord <= grid.RightEdge).all() ):
+ read(line, "particle_position_y"), \
+ read(line, "particle_position_z")
+ if ((grid.LeftEdge <= coord).all() and
+ (coord <= grid.RightEdge).all() ):
particles.append(read(line, field))
return np.array(particles)
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