[Yt-svn] yt: Draft of frontend for Daniel Ceverino's particular ART output.
hg at spacepope.org
hg at spacepope.org
Wed Sep 29 13:31:36 PDT 2010
hg Repository: yt
details: yt/rev/7817bb8a6a86
changeset: 3421:7817bb8a6a86
user: Christopher Erick Moody <cemoody at ucsc.edu>
date:
Wed Sep 29 13:31:24 2010 -0700
description:
Draft of frontend for Daniel Ceverino's particular ART output.
diffstat:
yt/frontends/cevart/__config__.py | 22 ++
yt/frontends/cevart/__init__.py | 29 ++
yt/frontends/cevart/api.py | 42 ++++
yt/frontends/cevart/ceverinoreader.py | 133 +++++++++++++
yt/frontends/cevart/data_structures.py | 388 ++++++++++++++++++++++++++++++++++++++
yt/frontends/cevart/fields.py | 61 ++++++
yt/frontends/cevart/io.py | 59 +++++
yt/frontends/cevart/setup.py | 13 +
yt/frontends/gadget/data_structures.py | 15 +-
9 files changed, 755 insertions(+), 7 deletions(-)
diffs (truncated from 811 to 300 lines):
diff -r 97c275d17e34 -r 7817bb8a6a86 yt/frontends/cevart/__config__.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/frontends/cevart/__config__.py Wed Sep 29 13:31:24 2010 -0700
@@ -0,0 +1,22 @@
+# This file is generated by /sdata/cemoody/code/yt/src/yt-trunk-svn/setup.py
+# It contains system_info results at the time of building this package.
+__all__ = ["get_info","show"]
+
+
+def get_info(name):
+ g = globals()
+ return g.get(name, g.get(name + "_info", {}))
+
+def show():
+ for name,info_dict in globals().items():
+ if name[0] == "_" or type(info_dict) is not type({}): continue
+ print name + ":"
+ if not info_dict:
+ print " NOT AVAILABLE"
+ for k,v in info_dict.items():
+ v = str(v)
+ if k == "sources" and len(v) > 200:
+ v = v[:60] + " ...\n... " + v[-60:]
+ print " %s = %s" % (k,v)
+ print
+
\ No newline at end of file
diff -r 97c275d17e34 -r 7817bb8a6a86 yt/frontends/cevart/__init__.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/frontends/cevart/__init__.py Wed Sep 29 13:31:24 2010 -0700
@@ -0,0 +1,29 @@
+"""
+API for yt.frontends.ramses
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Author: J.S. Oishi <jsoishi at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Author: Britton Smith <brittonsmith at gmail.com>
+Affiliation: MSU
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
diff -r 97c275d17e34 -r 7817bb8a6a86 yt/frontends/cevart/api.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/frontends/cevart/api.py Wed Sep 29 13:31:24 2010 -0700
@@ -0,0 +1,42 @@
+"""
+API for yt.frontends.ramses
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Author: J.S. Oishi <jsoishi at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Author: Britton Smith <brittonsmith at gmail.com>
+Affiliation: MSU
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+from .data_structures import \
+ RAMSESGrid, \
+ RAMSESHierarchy, \
+ RAMSESStaticOutput
+
+from .fields import \
+ RAMSESFieldContainer, \
+ RAMSESFieldInfo, \
+ add_ramses_field
+
+from .io import \
+ IOHandlerRAMSES
diff -r 97c275d17e34 -r 7817bb8a6a86 yt/frontends/cevart/ceverinoreader.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/frontends/cevart/ceverinoreader.py Wed Sep 29 13:31:24 2010 -0700
@@ -0,0 +1,133 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+CeverinoReader.py
+
+Created by Christopher on 2010-08-11.
+Copyright (c) 2010 __MyCompanyName__. All rights reserved.
+"""
+
+import sys
+import os
+import os.path
+import ipdb
+import numpy
+
+class BracketAccessMixin:
+ """Allow access to attributes via dictionary syntax."""
+ def __getitem__(self, name):
+ return getattr(self, name)
+
+ def __setitem__(self, name, value):
+ return setattr(self, name, value)
+
+#For format info see:
+#http://astronomy.nmsu.edu/danielcv/ForPriya/MW6/outputs/DataSet_README
+
+def read_data(file):
+ byte_size = os.path.getsize(file)
+
+ #ipdb.set_trace()
+
+
+ #Is it a DM file? Or is it a Gas file (same number of bytes per row)
+ row_size = 4+4+3*8+3*8+8+4 # 68
+ if numpy.mod(byte_size,row_size) == 0:
+ n_dm = byte_size / row_size
+ format = 'i4 ,i4 ,f8,f8,f8 ,f8,f8,f8 ,f8 ,i4'
+ data = numpy.core.records.fromfile(file, formats=format, shape=n_dm,
+ byteorder='>', names='arr_length,id,posx,posy,posz,velx,vely,velz,mass,arr_length2')
+ if numpy.all(data['arr_length']==60):
+ return 0,data
+
+ #Is it a Stars file? (Can't distinguish between S or Si unless by filename)
+ row_size = 4+4+3*8+3*8+8+4+4 # 72
+ if numpy.mod(byte_size,row_size) == 0:
+ n_dm = byte_size / row_size
+ format = 'i4 ,i4 ,f8,f8,f8 ,f8,f8,f8 ,f8,f4 ,i4'
+ data = numpy.core.records.fromfile(file, formats=format, shape=n_dm,
+ byteorder='>', names='arr_length,id,posx,posy,posz,velx,vely,velz,mass,age,arr_length2')
+ if numpy.all(data['arr_length']==64):
+ return 1,data
+
+ #Is it a SZ = Stars with Metals info file?
+ row_size = 4+4+3*8+3*8+8+4+4+4+4 # 80
+ if numpy.mod(byte_size,row_size) == 0:
+ n_dm = byte_size / row_size
+ format = 'i4 ,i4 ,f8,f8,f8 ,f8,f8,f8 ,f8,f4,f4,f4 ,i4'
+ data = numpy.core.records.fromfile(file, formats=format, shape=n_dm,
+ byteorder='>', names='arr_length,id,posx,posy,posz,velx,vely,velz,mass,age,'+
+ 'metals_snII,metals_snIa,arr_length2')
+ if numpy.all(data['arr_length']==72):
+ return 2,data
+
+ #Is it a Gas file?
+ row_size = 4+4+3*4+3*4+4+4+4 # 44
+ if numpy.mod(byte_size,row_size) == 0:
+ format = 'i4,f4, f4,f4,f4 , f4,f4,f4 ,f4,f4 ,i4'
+ data=numpy.core.records.fromfile(file, formats=format,
+ byteorder='>', names='arr_length,cell_size,posx,posy,posz,velx,vely,velz,density,'+
+ 'temperature,arr_length2')
+ if numpy.all(data['arr_length']==36):
+ return 3,data
+
+ #Is it a GZ = Gas file with metals?
+ row_size = 4+4+3*4+3*4+4+4+4+4+4 # 52
+ if numpy.mod(byte_size,row_size) == 0:
+ format = 'i4, f4, f4,f4,f4, f4,f4,f4, f4, f4, f4,f4, i4'
+ data=numpy.core.records.fromfile(file, formats=format,
+ byteorder='>', names='arr_length,cell_size,posx,posy,posz,velx,vely,velz,density,'+
+ 'temperature,metals_snII,metals_snIa,arr_length2')
+ if numpy.all(data['arr_length']==44):
+ return 4,data
+
+def append_field(rec, name, arr, dtype=None):
+ if dtype is None:
+ dtype = arr.dtype
+ arr = numpy.asarray(arr)
+ newdtype = numpy.dtype(rec.dtype.descr + [(name, dtype)])
+ newrec = numpy.empty(rec.shape, dtype=newdtype)
+ for field in rec.dtype.fields:
+ newrec[field] = rec[field]
+ newrec[name] = arr
+ return newrec
+
+def remove_field(rec, rfield):
+ descr = []
+ for format in rec.dtype.descr:
+ if format[0]==rfield: continue
+ descr += [format,]
+ newdtype = numpy.dtype(descr)
+ newrec = numpy.empty(rec.shape, dtype=newdtype)
+ for field in rec.dtype.fields:
+ if field==rfield: continue
+ newrec[field] = rec[field]
+ return newrec
+
+def read(file):
+ type,data = read_data(file)
+ data = remove_field(data,'arr_length')
+ data = remove_field(data,'arr_length2')
+ x,y,z = data['posx'],data['posy'],data['posz']
+ s = data['cell_size']/1000
+ us = numpy.unique(s)
+ xl,yl,zl = x-0.5*s,y-0.5*s,z-0.5*s
+ xr,yr,zr = x+0.5*s,y+0.5*s,z+0.5*s
+ dat=[(s==j)*idx for idx,j in enumerate(us)]
+ l=numpy.sum(numpy.array(dat),axis=0)
+ #le = numpy.array((xl,yl,zl))
+ #re = numpy.array((xr,yr,zr))
+ data = append_field(data,'left_edge_x',xl)
+ data = append_field(data,'left_edge_y',xl)
+ data = append_field(data,'left_edge_z',xl)
+ data = append_field(data,'right_edge_x',xl)
+ data = append_field(data,'right_edge_y',xl)
+ data = append_field(data,'right_edge_z',xl)
+ data = append_field(data,'level',l)
+ return data
+
+if __name__ == '__main__':
+ filename='../../data/ceverino/MW6_D875.a0.941.dat'
+ snap = Snapshot()
+ rows = snap.read_body(filename)
+ pdb.set_trace()
\ No newline at end of file
diff -r 97c275d17e34 -r 7817bb8a6a86 yt/frontends/cevart/data_structures.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/frontends/cevart/data_structures.py Wed Sep 29 13:31:24 2010 -0700
@@ -0,0 +1,388 @@
+"""
+Daniel Ceverino ART-specific data structures
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: UCSD
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import numpy as na
+import stat
+import weakref
+
+from yt.funcs import *
+from yt.data_objects.grid_patch import \
+ AMRGridPatch
+from yt.data_objects.hierarchy import \
+ AMRHierarchy
+from yt.data_objects.static_output import \
+ StaticOutput
+import _cevart_reader
+from .fields import CevartFieldContainer
+from yt.utilities.definitions import \
+ mpc_conversion
+from yt.utilities.io_handler import \
+ io_registry
+
+def num_deep_inc(f):
+ def wrap(self, *args, **kwargs):
+ self.num_deep += 1
+ rv = f(self, *args, **kwargs)
+ self.num_deep -= 1
+ return rv
+ return wrap
+
+class CevartGrid(AMRGridPatch):
More information about the yt-svn
mailing list