# HG changeset patch # User J.S. Oishi # Date 1283190495 25200 # Branch yt # Node ID ee593344cc89ff4da9614be57a24e9570cd5fe60 # Parent 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 # Parent e5a77f1fceccbc9973ce4aa2bae2bbf11a96c706 merged the beginnings of yt2 (from yt2-reorganization branch) into yt. diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 .hgignore --- a/.hgignore Mon Aug 30 10:02:07 2010 -0700 +++ b/.hgignore Mon Aug 30 10:48:15 2010 -0700 @@ -1,3 +1,7 @@ +build +yt.egg-info +__config__.py syntax: glob *.pyc .*.swp +*.so \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 check_for_setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_for_setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,4 @@ +import os + +for dirpath, dirnames, filenames in os.walk("yt"): + if "setup.py" not in filenames: print dirpath diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 clean.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clean.sh Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,4 @@ +find . -name "*.so" -exec rm -v {} \; +find . -name "*.pyc" -exec rm -v {} \; +find . -name "__config__.py" -exec rm -v {} \; +rm -rvf build dist diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 doc/REORG_NOTES --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/REORG_NOTES Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,7 @@ +* creating yt/frontends for the front end to each code + - created a uniform set of files for each: + data_structures.py + definitions.py + fields.py + io.py + misc.py \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 doc/REORG_NOTES~ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/REORG_NOTES~ Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,1 @@ +* as part of new \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 examples/README --- a/examples/README Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -Hi there! This directory used to contain examples. Now they're all in the -cookbook! You can find that by either going to: - -http://yt.enzotools.org/doc/ - -Or by unzipping doc/docs_html.zip and opening the index.html file in a web -browser, and browing to the cookbook. - -If you'd like to add a recipe, drop us an email at the yt-users mailing list -- -we'd love your contribution! diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 examples/cookbook_timeseries_avg_temp.py --- a/examples/cookbook_timeseries_avg_temp.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -from yt.mods import * - -avg_T = [] -times = [] -for i in range(30): - pf = load("my_output%04i" % (i)) - v, c = pf.h.find_max("Density") - sp = pf.h.sphere(c, 10.0/pf['kpc']) - avg_T.append(sp.quantities["WeightedAverageQuantity"]\ - ("Temperature", "CellMassMsun")) - times.append(pf["CosmologyCurrentTime"] * pf["years"]) -pylab.loglog(times, avg_T) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 examples/cookbook_timeseries_max_dens.py --- a/examples/cookbook_timeseries_max_dens.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -from yt.mods import * - -max_rho = [] -max_pos = [] -times = [] -for i in range(30): - pf = load("my_output%04i" % (i)) - v, c = pf.h.find_max("Density") - max_rho.append(v) - max_pos.append(c) - times.append(pf["CosmologyCurrentTime"] * pf["years"]) -pylab.loglog(times, max_rho) -pylab.clf() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 examples/fastBuildMerge.py --- a/examples/fastBuildMerge.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -#!/usr/bin/python - -# Stephen Skory -# sskory@physics.ucsd.edu -# created August 2006 -# modified June 2008 -# this python script builds a script for creating halo merger trees using hop inside yt -# see http://yt.enzotools.org/ for more info on yt and this script. - -# the output of GraphViz at the very will have boxes connected by arrows. -# The arrow into a box is how much of the previous halo's DM & stars is -# contributing to that halo. -# Similarly the arrow leaving a box is how much of the DM & stars is leaving -# that halo for the next one. -# Inside the box, the top % is how much of the halo is accreted from the -# 'ether'; particles that in the previous time step were assigned to no group. -# Similarly, the bottom % is how much of the halo leaves and is assigned to no -# group in the next time step. -# The middle of the box shows how many star/DM particles are in the halo, -# and the (x,y,z) position of the halo's center. - -# to run this, set all the things below to your liking, -# and then 'python fastBuildMerge.py > mergeScript.py -# 'chmod u+x mergeScript.py' -# './mergeScript.py' - -# the GraphViz file -outfile = "157-120.dot" -# the directory basename, no trailing slash needed -# if a data dump is /path/to/enzo/data/DD0243/data0243, put /path/to/enzo/data/DD below -dirbasename = "/path/to/enzo/data/DD" -# usually DD, maybe RD, or data -filebasename = "data" -# the maximum number of groups analyzed at one time step -hardmaxgroup = 2500 -# the hop density threshold used for grouping -hopthreshold = 80.0 -# dm only, True or False -dmonly = "True" - -# The range of data dumps you wish to operate upon. It's a good idea to manually see how far back -# haloes exist before setting the end value. -# start > end -end = 120 -start = 157 - -# A list of the haloes in the final data dump for which you want to find ancestors. Use the IDs provided -# by hop, so you'll probably have to run hop on the final data dump before deciding which haloes to -# put here, unless you know it's the largest halo, which is always ID=0. It can be a singleton. -indices = [0,1] - -# change below to reflect where python is -# it is important to use python >= 2.5 as previous versions have a memory bug -# which affects this script, which is important if you're running large datasets. -print "#!/usr/bin/env /Library/Frameworks/Python.framework/Versions/Current/bin/python" - -# ---------- you shouldn't have to change anything below. --------- -# ----------------------------------------------------------------- -# ----------------------------------------------------------------- - -name = 'Merger' - -print "import yt.lagos as lagos" -print "from yt.lagos import mylog" -print "from yt.mods import *" -print "import yt.lagos.hop.Merger as %s" % name - -print """ -def instantiateSnapshots(dirbasename,filebasename,start,end): - redshift = {} - snapshots = {} - for i in range(start-end): - j = start - i - file = "%s%04d/%s%04d" % (dirbasename,j,filebasename,j) - snapshot = lagos.EnzoStaticOutput(file) - redshift[j] = snapshot["CosmologyCurrentRedshift"] - # put the snapshot instance into the dict snapshots - snapshots[j] = snapshot - - string = "Read in %d snapshots." % len(redshift) - mylog.info(string) - return(snapshots,redshift) -""" - - -print "positions = {}" -print "dirbasename = \"%s\"" % dirbasename -print "filebasename = \"%s\"" % filebasename -print "hardmaxgroup = %d" % hardmaxgroup -print "indices = " + str(indices) -print "start = %d" % start -print "end = %d" % end -print "dmonly = \"%s\"" % dmonly - -# first let's read in the redshifts, and instantiate the snapshots -print "(snapshots,redshift) = instantiateSnapshots(dirbasename,filebasename,start,end-1)" - -# open the dotfile -print "fopen = open('%s', 'w')" % outfile - -# write the preambles for the dotfile -print "%s.writeTop(fopen)" % name -print "%s.writeNode(fopen)" % name - -print "\n" - -# loop over all the snapshots -for i in range(start-end): - snapshot = start - i - # snapshots should be in time-reverse order, so this loop will count *down*, so the next snapshot - # to load has a lower index - nextsnapshot = snapshot-1 - # if we're at the bottom, we're done! - if (nextsnapshot < end): - break - - # we need to run hop on the snapshot - print "hop_results = HaloFinder.HOPHaloFinder(snapshots[%d], threshold=%f, dm_only=dmonly)" % \ - (nextsnapshot,hopthreshold) - - # get the group info for the next snapshot - # get group positions - print "positions = %s.convertPositions(hop_results,%d,positions,hardmaxgroup)" % (name,nextsnapshot) - # get particle IDs - print "g%04d = %s.convertGroups(hop_results,%d,hardmaxgroup)" % (nextsnapshot,name,nextsnapshot) - # sort the particles in each group - print "for g in g%04d: g.particles.sort()" % nextsnapshot - # delete the sphere which contains all the particles, to clear up memory - print "del sphere" - # delete hop_results now that we're done with them, too - print "del hop_results\n" - - # in the beginning we need to read in two groups before we build the links, so do everything above - # again - if (snapshot==start): - print "hop_results = HaloFinder.HOPHaloFinder(snapshots[%d], threshold=%f, dm_only=dmonly)" % \ - (snapshot,hopthreshold) - print "positions = %s.convertPositionsSelected(hop_results,%d,positions,indices)" % (name,snapshot) - print "g%04d = %s.convertGroupsSelected(hop_results,%d,indices)" % (snapshot,name,snapshot) - print "for g in g%04d: g.particles.sort()\n" % snapshot - print "del sphere" - print "del hop_results" - - - # for just the last group (in time), a singleton, usually. - if (snapshot==start): - print "for g in g%04d: g.flag = 1\n" % start - - # build links which requires two neighboring groups at once. - print "(links%04d%04d,g%04d,g%04d) = %s.buildLinks(g%04d,g%04d,positions)" % \ - (nextsnapshot,snapshot,nextsnapshot,snapshot,name,nextsnapshot,snapshot) - - # write out levels which keeps the boxes on one line rather than put how graphviz wants aesthetically - - print "%s.writeLevels(fopen, g%04d,redshift[%d])" % (name,nextsnapshot,nextsnapshot) - if (snapshot==start): - print "%s.writeLevels(fopen, g%04d,redshift[%d])" % (name,snapshot,snapshot) - - # print out label stuff - - print "%s.writeOpen(fopen)" % name - - # for the first (last in time) halo, write out the box labels using style 2 - if (snapshot==start): - print "%s.writeLabels(fopen, g%04d, positions, 2)" % (name,snapshot) - # middle time steps get type 1 - if (snapshot!=start): - print "%s.writeLabels(fopen, g%04d, positions, 1)" % (name,snapshot) - # the top, first in time get type 0 - if (nextsnapshot==end): - print "%s.writeLabels(fopen, g%04d, positions, 0)" % (name,nextsnapshot) - - print "%s.writeClose(fopen)" % name - - print "%s.writeOpen(fopen)" % name - print "%s.writeLinks(fopen,links%04d%04d, g%04d, g%04d)" % (name,nextsnapshot,snapshot,nextsnapshot,snapshot) - print "%s.writeClose(fopen)" % name - - print "for g in g%04d: del g.particles\n\n" % snapshot - -# close the dotfile -print "%s.writeClose(fopen)" % name -print "fopen.close()" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 make_apipy.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make_apipy.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +ss = """\"\"\" +API for %s + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +\"\"\" +""" + +import sys, os +n = sys.argv[-1] + +fn = os.path.join(os.path.abspath(n), "api.py") +#if os.path.exists(fn): + #print "%s exists! Not overwriting." % fn +bn = n.replace("/",".") + +print "%s -> %s" % (bn, fn) + +open(fn, "w").write(ss % (bn)) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 make_setuppy.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make_setuppy.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,25 @@ +ss = r"""#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('%s',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config +""" + +import sys, os +n = sys.argv[-1] + +fn = os.path.join(os.path.abspath(n), "setup.py") +if os.path.exists(fn): + print "%s exists! Not overwriting." % fn +bn = os.path.basename(n) + +print "%s -> %s" % (bn, fn) + +open(fn, "w").write(ss % bn) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/basic.py --- a/scripts/basic.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -#!python2.5 -from yt.mods import * - -fido.runAction() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/fbranch --- a/scripts/fbranch Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -basic.py \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/fbury --- a/scripts/fbury Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -basic.py \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/fdigup --- a/scripts/fdigup Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -basic.py \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/fido --- a/scripts/fido Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -basic.py \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/fimport --- a/scripts/fimport Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -basic.py \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/reason --- a/scripts/reason Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,809 +0,0 @@ -#!python - -import wx, base64, cStringIO - -def makeBitmap(data): - stream = cStringIO.StringIO(data) - return wx.BitmapFromImage(wx.ImageFromStream(stream)) - -class ReasonApp(wx.App): - def ShowSplash(self, bitmap): - wx.InitAllImageHandlers() - wx.SplashScreen(bitmap, - wx.SPLASH_CENTRE_ON_PARENT | wx.SPLASH_TIMEOUT, - 5000, None, -1) - wx.Yield() - - def AfterInit(self): - frame = yt.reason.ReasonMainWindow(None, -1) - frame.Center() - self.SetTopWindow(frame) - frame.Show() - -png1_b64 = \ -"""iVBORw0KGgoAAAANSUhEUgAAAf0AAADgCAIAAACGkSguAAAKOGlDQ1BJQ0MgUHJvZmlsZQAAeJyN -lmdUU1kXhvfNTU/oCR0SqlQpoXcICCgdEQRbgAgMgYQQFAuDig27jCgoZZCxISPO0EYRBOsIqDRF -ERAVFAZRBMECmO9HbF+ZNd/+te9Z9551n+e8Z60NQKVxBAIeBgCSkkXCEG8PZsTSSCahG1CgAAVM -gMqJSRW4BwX5wd/W9H1AAAA6TTkCAS+KEZNdmB6s1vlultN2sbzz778DAAApYcTSSACECQC0OElv -BQC0aEnvAwC0tSKBCABZBgC0mHhOLAAiAAAT4eIQNgBSAADScZK+HACkoyX9JQCQXhMTJwJAWgFQ -+eTYhGQA7AAA3iWWmxoDQGECQH6MQCgCoFwCANOkJH4sAOUlABhELI1kSn4zxQzA8xKADPfbGucC -QEkegOF37+m8AlC5CXA079vaZAggAIAo3k1dzbIEAACE6gGA6xeLJ/UBCDkAcwfF4pnjYvFcKQDa -C9DIi0kTrvnsCMGwAP7pWcL5uVAEAAEEg2JxODyBSCJTqFLSMrJy8go0uqKSsoqqmroGg6mlraOr -p29gaGRsYmpmbmHJsraxtbN3dHJ2cXXzYHt6efv4LlzkFxAYFBy6OGxJ+NLIqGXLV6zkRMfEclfH -xSck8pKS+YIUYWramrXp69Zv2Phj5qbNW7K2btu+I3vX7j179+0/cDDnp0OHj+TlHz1WUFhU/HPJ -8dJfTpw8dfpM2dny8l/PVZz/7ffKquqa2to/Llysu1Tf0HC5senK1WvXrt+4+eetW80trbdv37nb -1t7R0dnVde9+d/eDhz09j3r7+vofDww8efpscHDo+YvhkZG/Rl+OvXo9/ubNxOTbqel37z98nJmd -+ySW8OMJRBKJTKFKfYevpq6hyWBq6ejq6c8zMDI2MZ1vZmHJsrK2sbN3cHRydnFz92B7ei3w8V24 -yM8/ICg4JHRx2JKIz/yrONES/h8SeUnJghRhquiLgIwfMz8L2Pm9gdz/UPDVwRcFVdU1XxRcbmxq -unJVYuCbAAn/gwcPv+A/efr02eDQ8xfDwxL6V6/H30xMvp36ij/3SQyAYFAUi8Xh8QQikUQmU6hU -KWlpGVk5eXkFGp2uqKQsSYKmJoOpJQnDPANJHEznm5lbWLJYVtY2tnb2Do5OTs4urhItXgskufD3 -Dwj8rGZJ+Fc5q77GQ+KHL0j5ztCGjRnfQiJx9L8k/VtQvsvJN0dfFLW03r7T1t7Rda/7YU9v/8DT -wecjo2Pjk1PvZ+bEAJL7DgCAtwHYWwQQzgXwNwDYfgXAQAtA1RsgSApgsT1gJlmAKe0GpMQbUAQA -I7lbgAIRpEERGGAENuAJoRALabADjkEltMIgfEJUEBskBOEj+5AKpA2ZxChjXDBczEFMHWYIlUdd -UR56DG1BZ7FmWA42F9uCQ3FuuExcHe493gafiq/ETxFsCesIDUQc0Y+YSxwi2ZO2ke6R9chryLco -mpRUyi0qk5pObZcykSqQmpNeLt0gw5TJkhmWDZStlNOQ2yE3Ib9Cvk3BVaGCpkM7SlelFypqK5Yp -WSrVKfsoP1D5QWVW9YDaPLV69TD1EY1tmlqa9YwoxhyzRMtX6612no67zhvdEr0Qfax+9bw4A4ZB -r2GOUYgx3fieSb4pZ77h/DdmDeb7LVZZslgEVq9Vg3WuzVrbSDsXe20HvMNLx4dOzc51LuWuRW6H -3Hd7ZLE3e27zyl6wx3ufz1HfiwtH/RT9wwJ2BzYGfQixD81a3LqEHr4ioiISiYpYVruCsXLbqr+i -F8d0cr1XN8S7JTQnBvMGk9cI6ClVqRFp2DU16QnrGRteZJzLzNjsl6W2dWx7x84Luwr27N639cCG -HP6h+MOivMNHewvti/eXjP2y4OSZM8Szy3+9fl73911VE7URF2ou0RvSG/uuOl3PuzndHNB69s5s -e1hn2b2ZB949ub2P++uekJ4FD9m9SBipGK0aaxmnTdi/tZxe977pY8kcViz+ev54oII8qIIumIEj -+EA4xMFayIYCOA/XoRfeItKIIeKJrEIykALkEtKHAYwuZiFGgDmMacAMozTUHU1GC9HbqBhrieVi -j2LbcWQcG5eBu4j7gLfDr8XXEYDgRcgmdBDVifHEahJKCiWdIM2QA8knyWJKJKWGqkAVUO9KmUkd -kpqRjpFukbGSKZKlyq6THZZbKtcq7yZfq2CmcIqmTSuh69HLFFmK9Uq+SveUucofVPar6qrWq0Wo -Tajv1TDSaNZMYFAYvzGjtAhaNdqxOgo6N3Uz9Wz1xvXL5sUa6BuMGpYZrTH2MqGa9JtWzs8yizS3 -saBZTFp2sWqtSq132ayz5dmttA928HS0c3JwdnRxcnV283D39Qhmr/RM9dq5oMC7wqfZ9+Miaz+e -f3nAcJBWcHTI8dDJMOcl28M7ljIik6OuL9dasWllH8c2Oi+WxOWv7o73SbicaMo7nazLL00xFp4S -WaRdXhuY3r9etFEuoyIzbNOHLce2um0b33EqO3K3zJ72fXkHludo/NSbW33kUH7msfzCc8VNJY9K -X52kn7YqCytff67w/I3fp6sNa1de2F93tX620eXK5mt/3Ph0y6Fl++0/2+gd3K7K+7MPvR8V940P -+D4tHHzzInjk59GZV+Hjlye1p7LfjX1cNvtILP58+iRQACaYgQeEAx+y4Qy0w1tEFfFAEpHDyDVk -CmOAWYEpwwyi2igHPY4OYY2xAuxFHAGXiruBV8Un428StAkZhEdEJ2IxyYSUS0bIfPJjSijlJtWZ -WiXFkhqQ5kgPysTLvJZNl0PlDsgz5asUfBUGaBvpGvRGxUQlBaXLynwVXZUe1Z/UAtXJ6jc0tmsu -YBAZd5nHtBK1HXUoOk906/Ry9VPmeRuYGsoZvjN6Ztxm0mRaM/+EWYl5sUWRZTGr1Oq8dY3NLdte -u3EHrKOyk4PzcpdNrr+4tblPsPU8l3nlLrjr/cnXdmHSouN+PQG0wMCgzOCmUPziwLAjS3oijJeK -Iq8sU16euqJzlSEnK3okNpRbHacWvydhLpHHe5Ycwe9KCRW2igLSutZGpQ+sT9wwk7E3U3fTxS1+ -WY+3rduhtrN+V+Ru8d5f90cdxOecPbTksNSRi/khRycKdhd5FI+XnCiNPmF4cvp0fdnBct45r/Pq -v72uvFpdVCu44F+nfOlFQ3Vj2pV5V+9f33mT9WdL8+qW2duZdz60pbQPdgZ31d+ndXMf1PSgj7x6 -M/r29m95XDxw/cnQM9Kg4uDk0NPn74aREcJfMqPIaOvLorH8Vzmvd4ynvomYMJgYmax8e2Rq/XTE -O+v3Mu+ff/j5Y+SM9szEbPPc2U+1YjGAZEYEAAA6m8/jC5l+bE8mm8NLiBZyRNzYL+MWHdjABx7w -QQhM8AM2eAIT2MABHiRANAiBAyLgQuw/7vT/l4ibLgIAYPMF64QJcfEiprtAwOMy2fwkQZqIKzRh -+ibHzDdhWpqbswAAJHMtAABeFqDACADgD3/hf+37L+6De+NRVk/VAAAgAElEQVR4nOx9d2AdR7X3 -maurbllyk+QiN7nGLYkTlzRSCAmQECAQCAQIEEIo7wHvPeBRQ3t88Hh0CKEkQEggpDenOD1OHPfe -JFnNalaxZfV2757vj21ndmd2Z26RlaCTjXzv3DO/c2bmnDOzs7Mz7Lbbbrv00kthnMZpnMZpnP41 -KDpzRtnCBYsBABgCoJWMwIBZn5mT6if6CyNpSNJYEHMQIcnASAZtHAl/UjjkC/KZxVC8sGRUSn1x -kPDLdZNJSkv1JoyDhJ8p4MjRPVZ/Gorm+zkEB0l6oFpCnLQXSvKDFEfi/sno41UpYSjeZcJxdF1M -Vx9dnCgCmq7CEIT+EBjtmD+dKoFcOtd4NFhKgijzwXLgITgSuRRHIS9wLGJ+JX34sjMhD1f/Ehw5 -jyRGS8soM9xwHVJXltTow7eXrK8S48ttMqA+ZWYv1Ae8BXJ5BDE6sK6YhCcFOHJ3k0HJzJ7JxkQy -d5bhKxdHkMyEHxVNUWLSKrFeZkJqLkNlERxNk1bRJwqAiNYQXTyoRlc5pEBErEd5hYG62+chYWe0 -L0Q3HWXNSECRjPQ8kV7ahxHBwvrnWCT8HmtDp1oQkFk/IwOGVik4HqobAmNWXTAGaLiloLJsSGAI -6NiNmZH5eNT0MUR2Y2Z09DFQ0H+irYapj8FcfYDqg64+riyiaAr1AVo/En2A1g/VB1x9ACVWx/c3 -oYNSBN5CRMGJ4/HYhjCGqrgeCuzH+5W4doBJ0x+kLinqhpEUjMldzOXhb9bEPLz+7kdeH7Gs1Jm0 -81fFhDgeorbps67Lj5ZJM4AoohX3GWMoqi0+3IkbOKgBxB0al0z6FfS2t/1JaugUR4gucTzkMsjG -+ByIUB+/IM7ufT9IeSgOcj8FOAxS/X184/qE60NjmUxREPH47ESojyfQczgklnm1EspKWB/CJBsS -yVxA6m5JuqRIJY4lhfr8q5m0gj5RREekOEIDX+kqTNz9gYyfZOT8TZJBmMx4hnCeNMsKyGLIeAiT -IWFSwaGkopuMJ1X6pIqHGwekQx86TDEkPBIKqGfOZST+o+RWurJkPE5sRdlQLFyctrvJ9OGZhPqk -RVaaTEhC6XYxJVkSnCiApANSAJUxKfEnyK2dFaVfUi8rgSwJO2GaKFX6pIpHhSkpWQnbrbo4neFF -srJkPKkQ9oZpU22m1IlTwRlFl5fhRPnfZI8HxmmcxmmcxulNQlH+Bmk0R5bjNE7jNE7jdBooGkeM -2zcektG+ZxotGUoVVDI4unnTzZ8OWbrp6aB01FuqeNJN6dBhlH1nNJtjNIt2unROt6vq8Ufpg57A -VSopodGc0kxV3nTzp0OWbno6KB31NprTsMlQOnQYZd8ZzeYY1Scdo8ijwp8qV9XjjwL3nGEs+Mw4 -jdM4jdM4pZHM+X0z3KvccSRJ6YAda5i6eUdTVrpx0oH/RiljqmSdLvtJILuuiDdi078R84bjRA0k -a0iZgCOllA7Y04EZ0Ciyd4ulWZLRP1VlV8BJZk4ymd2VRrOMKaPRbNPTaD8qbfkGMW+OUhVzx27Z -6TpO+UurkpWe3GhB/GjA3awDGfAvywoyyjZdSUqZAH4nRivqxpUFQklaHBk/ebMCIx5dBSolk5du -1oEKdar96E3yPpSSbtplkeim0D8p5ZVl9+xzoNkd6lpv4nID+BNWjCa7cwa8a+i6ktewBIok5PLJ -mLrkByo5zeaqUmRdHdz3dTkUkoHfUUHi86Qh+dpBzsjoG2PUKCmMxHC94px/ZUZMK44Jk/kWUNEt -tCweLVScn6oga2FJoE0mL/d6tq5usrKnKK9KPXP4KvcckuJq52Wc+YnfxZX0GRy8ZC8ar2iHhY+V -0lhPE0P7Bj6j1E0ovwjH64bCquP3C1JzJUENqYYImqxi6lQdTZOQtkU68CkZEh5ZuCD8UbeVSSWT -fbQoOVtVme0v5JFJdZht20EXBGk6Na6QgaWptiQv5RPg+PSRyEVNfqmqyEQgEgfzqkryYmheT+sI -9ZRiStSR6h/kbxp55TpLQfXKQlFQryxci6PgYViAnnxebZeR5FWxN2ql4Tqb4THYlQLdTcFVw/Bl -OLIQoeL+srATIFbFnHRNzrN2Ri+vpmtL9UTCHwVEMNDZ5g0ZMLQG6eYHJ53CB/LY/yCguUussw+c -lcvREe2MSJgZumM5K7utmIND+zeTB33KMw8PJZFccHJY1UOqV6Q/8+jv2p5dFSSBloWrBFMmrV6+ -MsEpnakTEkgenyuXU3DmeI2H03InJxlFcr0ptkD0VGlYXq5BiSzmlILsnIKkpAHIjKQYNo9iWag+ -zKMe5bSa1a5/MvAxLYeBbY2OBXLVAmBtcm4WyMqs5DIyuRw+7xGOLTEABCNYLo0fNDJQdyDlcMgA -YjwMSH/kUcZSmBFBBopd1VdvApf3uh6nj4kZIZiGH9OU65qufL9opylDzJX4Lvodn0+hgY+YOocv -y0tTbHOyh1M2D0pyuWVx+j0w53kMJAZlbfNma4lOgaw6cXVAIDykFPQfgkPBHCheqDoPDTvkmx3l -hDiUKKZZ6QYgQ6tBGL0lQvevilwaS/3vQ/A15BbLU70Anm3ySCD0o4n0CZDIyaX4At1kELRcKnKD -ZPlUC9HfTqEtwTysOvr4hJO8XIvz2qKtg+0CXh3sf0R1q+oyQbbkZSGu6pOLTgZHT75Y5JPAfURy -AbjI6XMTRyQRxKlElPdOH6vwCPjj/IBR4qoklVpVkKlIzdXfNFIeVfcJySvlAS0eMr8PPkYBBTmM -Jr8KVKrEKfi5yCvTKlfG78+TOn3SzZ+qNh0L+pxOGxhLOCmEGgtm80Y3ldTwuPvvK5O3sxqncXoz -kmd8HTReG6c3L7052zqK7nBSVsIABwjl9zCriAgQnXBeFcx04KdbbqpwxnK5TpduAQuPUJKupc8Y -rPOx0NypwkmHLF3+MdKsAooCOk/U3HkqHs9FVCuHtFf0nHqSRLqKemI11DBTrzMkUY2pao701Fu6 -61NP53SYbursNlU2k3obSCCLSnTUL3Lq9Umdieryj90QEeVGL+hyCIXpplNhjHz2MKc7nSojG6ql -JB2UlqdzNJbTVUa/b9Z05D8Lf0p3OiThesmkJ+kaFHxMuSqMDdMaCyGCm993Bvyj2QBv1nQYe4Y1 -np5YerqHC2MhHdLgAmMtHcaeaZ2udPOcReer3QF4BrHOz5Lq5HoY8sWLE/BTqAhJLyZ7UY1jl+Ek -UAQtnHTzp0rPVLXLaOKP5XaUydVNT4eesgxpUmk0cVIld6zpI2ZPSs8oGIiGFxkJECOZuXSk6dZ7 -Gsz8Zr9dZyahyyQifrqL0XSUpMv4uXRm6cPM99IAAQAhIqzHRHVwKkdQXpC/GCJ5wTpl/KJ0BgCG -VQRU1FNXH8kJ0FplYQAGY46eEbLaTKvsXhxDhuN+IW8q+TZRCXUHWTrK0sXTvOlwPakOVLJt6l6T -ZiaqI4zwE6UZAUVOOS9+GI5Cui4OaUppc+uYNAMw3BfTIGK4otXchxEc913RiOT5kr5LktLT11xo -3EfSrK5FUEPxjALE6eT1I2Z/4PkFUM4HYWebbDqCHeupTYg3x5DpGZbuj/XSTTNOd7on1qddrmSU -Ir1vo4GJcPnGJCnHEf/gHUxhytORS3cFp9711HAkJq3qGihJl/GfrnTyJVGTRu5bAibqVq0UJ0L1 -pH2Vgp4ESMZvvrflG4hrj2oU0qU9slewyxOeTn9JYOSgla6iZ8BPKUrnkhMd/I+n66VDalxA22U8 -pGMq3rQwuWlxmbGWPgZNS5JuSNI5SjykRBHAuQNmQmYqGAN7wOB0yaBDnNH7jQcSp8vyyiRI+D2t -oi1L0qhiWQBo14yn9+dwxDBqOqjoJuJnQLZ2AWm1h8pNFY6HtMubTHqKXCARnBTlVeEJdQ1t/mTS -VZY7ylyYT0y46dNtul58mfvL4njiOrjreZikW0GSmd5HahPKVJMMqf1q2B9V+GWCw/NK1ZRyyTFp -M7qf3clQ5H+RSJPLCm+LxPMi3/R6L3VzJeeGsAo46SlvOAXlFVlFIrK48IujkzdQT3GVSrIo2UCK -mkDJzcWy5DaWSChwqt3dOpC4sBqJ19R7Yr0kXAftTCTmD+dy9+fxbYoXgp60EiGwASChaqQpr0oW -FSiV/XbkefX0Gc+bvrwynABYlbxaOEnqqSLodLlbSormSUydeaTXhWU4qcL3rONMnBLu5GUZdUcK -lNKdV7GwqRxv6tAbRW4yeU+jziqiU1WcZIqmVUVvoPrX0iFN7atCY61oFDMKgAgGedzjmXJmNn+A -FC8/CvgdEA+zTDMlfl18Tf6EdU5BCqYAR0ZBeUVjAF1Zo80vPc8kBfgBLoD2jLuim3jzyvAlTaCk -jw6mJy8k7D4o5tfFTEofSewSYgakiPVIj0mrYqZaBwCAKBj2s2POQtDHGmw5ivwy8GDY08ufGObY -SZGRbt5/Wf6Aptd1k2Typlsfh/n0us/o6BOcEoyvnjcdLpw8PwBA1ACwXjvgGFI12+GRmg5Y2dRW -MrKSwR/L+qcDJ1WyktFnNHXQxUy3zaRKhzGo0mjyqPC/0euEjved/Tg5EK1uWZ0/HbAynlTJSgZ/ -LOufDpyx0L6jqYMuf7ptJlU6pFCcCs9YqBZd/jd2nUSBLOjheO1ugE760nRKQRPDzP3CSAaxOrLX -pHhhenmTez0rPK9HBxbWHPKzmsV5k+Hnjzcdx1HFkbdjUi6QIv4x554JuEkojow/Gbf18LzhzDJ1 -OFED0X5vi2zrAGSPDS5Zsg5V9gYacOudXCgE2ap6KVToSyueJpbwoyydKirRU0l/cTL5wfQ2h42e -UWqIyoUAjPBTfQLqx/0mTpfWG4rlups4efSX4pAPxEClOJr1IMchObndCPXqh99HIVUuoGbnKEjn -HJzWp8fghO3CRO3C43BQ3g5EBsU3TSgObWLZe2dCfGpafBDkS6/r2hBqBqlzE5KV+3J63C0KwJw6 -8tqWkyoyXE4uynpqGQ75wTNiEb5FwPiCCQXIcBTxHQrQU+oYlJ1k5l625kW4n8WOwaVL+xIFHEOm -J/lsyH6Qx6ZwPWU6pEhPaT2o6ED5NcslE+0JZKEDVJnLoLxobqLmXgV8pJHrEHYTEeACon7Xq7zM -JbVxKI+Oa4PH1CUkjoP8D7ruqeIOo+hukvN1uTiLXDqV6jYAculCHBkUygvg6cQSw/HG8XTqAJ7Y -hOJ0oQ4BeWV9qq4OyeDIMo+mDumozwT4k3EN0cAtKbfyOG8yeXVdSeYmoMCTsDunAwfUeCiNprmm -IXREEdAAtGuQWR8MsMYF5gyRM3ZAFwkdyWr8rjpmL224JkgmqmT7htrpZl508jKry2cA5v1lSLqO -LF86EB2oLFK/yFxJgIbdNsgYs1+IZohob4rB7WHAXENmiIbDQ/KC+QHt+nT5IeX83EQhA8LDCKZM -Zwk/JYZI9NGqE0qeujUIDtfWXGEEbURloc2Ddj0A2XgXCL7tMkhcwHUly+jRhbc/YCrdzdEI3MIQ -uUjkWhBuuZBUBqkup0o4V2WkSrm3Jjh3IDyyna1D0v2YpCZCXJLUl0hniTsgcQcId9VwV5K5sApm -gIsRPYHoyQgmCDE5PSHq9ofEoGndOfsZi0iLHz3/ugno4/F+keW171VU03VkKevAM/FsnD5OdaFc -Hz8P8lWKo8TP68/HoHBMCT8lWV6VOuFw9OpW3kbcF35DZ6FoXq4HgwMN4kmBu/l45HKlOgtdQ+ZW -AoEydxB9DE3XxfQbO+GRbAym4A7JuGoymLouhtZ/vkqQuk8UfRUj6mi89ZkAD/0gJAckSX4VnGR4 -FPWUMaeKJ934/2p6+nn8zCo8aXKflPOkyj3T7W7p4AlQXkaniz9NZh8Fbn6fAcnjz+z/KTEeTyK1 -V5RkZL68/kY1lOUmw6OoJ6aZB0Vl9xdExjOuZygP8H8VeUbBfVLCg3LNYSy5Wzp4/MxCHtA0Gw9+ -qNkH4IMkPVVmH0WDucvmGM2AJAMtmoCE1afOppI9HXlHk4c/6ooJ02k9p1sfXT3ToYMKzxjRU8sd -TpfcVLVFAJsw3WPDY8HdUsWTjDsnY5bpLlcUwR7v87cHfIbQ7i11JBOVOA7TDKcqmIq6yQQTP+Ew -U1XPCnklouTtfpqI0zO8PnlKma0mVy2JqoEk1nO34knIVbJhNYUpZKpcTIVSFSKSwNR3Z11KwnQV -ykLWcaLiWQKjGAtSI0plr+xEUFPFJGFPRulk5CZDyXikQl7Ns19SaatJxZpUNGUiGGF5pL/rC5Oa -bqoCs4rcdGAmUZYUjjRSDRMFalljYHg3Tm8WGsV+a5RpbGs3xujNVFlvnrKY521Z5RHdWjCw14gC -oGTJgC5xu5YTcCk/EH4g/KmfE7KmEgSykiQFVZWWAPCqhvMngc8/7tGUxS1GTkK3JJqYw0SCqVz/ -kFDTy9ZiJMufqEsq4SfhAlyrIeFPw1BfGgpSxB8kOs0mPaouFkVzwxEExuxXPbgXPdDaNMJagIoU -xiFF56S3rLZtAdJfxFDo+dFSw7R9u4oQgL4eJFNDgM/brY3jxAhxbaoUmYYZwbvWnpJbyXwZhXra -/AYDUhmhenL4gjoP0pPbuk9XliExG5pVgO8LUAZJUWhfcxcCa4ZcsG9SYP2H2WRAOoeg4DLI27lI -rvO+mmmixCWV2yIEH1xXsnCdKgsrAnFnvpMNcEnNKuV+l5miRuiQ4gfowNVeGkw6zP29WaX8KvpH -AZkpHL1V5FQwaTfnhBbkgheVQ18O9JaTuYVHg3RR/r7K8VUhj3+DJ5/yHB6RC0SuZZQ0r8UDXh6i -VQiPXy7Vk5KvfaSxSbrnF+Hx5ZLiOPXg4TF8OP4FlSo4gfpwZiPBQb90+xeHHyVyOW6Zx/hSbH6f -Pj4z5tyRWKagXJC0ywjtx+ueHBSRK9FNqL/Z9MxX58qmLqhqmUtywywfpnqIoHJV9AwxRR5HyMOh -KZsidW3084TjyEKZmguIXSyKiAY6t42Cmw2DZGS2qmiPDuzms1cemP/avX3EupdwxgHuggy0cYBB -xHnF2rzxsGW7PEh4vDhIcBjBcb2A9rwRsHe1YubIycI3R1R2oexIi5a/WXlpWcAdgtEXXiN0I0BS -dbTdI7RhTB4STy0eQ4JDurkINVBiI4ysezEMdPIyUhZu30PCYzUjAgBEZDy0TrRxSFlou/hwTOIW -Y1mbG5j1IKkroPhUTxJDDYIDXll2iyDYpmIQuQzcGwhm2oo5ukVXV0TXYyPgMHvswcWJSHEYwUGC -4+oDDg6AeYdDLd82Y5fH0hmAIRhmmW3TpO/5030tDGCOqbt7mLgeD+B1DSSuYfMgRMzCWS7GiIs5 -LcDr4HNVkVwSFoiermlRuWDtJ2rxk4FOhHtxlpqHhAclPODjcfohodtKQ4REFgkvdoA0PxOXt2/Y -wOPyrlh7HaddS/ZPvt4b6Rf+Jx+5rhT3/yRi59gkm0DxUDIcsUKU4pKiyIpIv/uKI+CX60Bwwlnk -OBimD89DTYrenErVJPExLt28UKEsCjjUyuKytToKG2kptTvHEl63nh+4PKJPMtQg3VDCQ+Og/cEA -eeP59BGIlOscXndkxocjJjEDOrgTmitfnQFyPf9600E/dPhcIwgHuLF/eAgKMDNpKBPzK5krx6Ia -zkyK8nUUzDwqdBpFvxlJuzpTVf8qtpoinDcxjenSKwxfRpU05UrZx3Slp4boPg2+Qb5FqUofBRHj -6ePp4+mJpY9BlcbT05VuruP0c4OQO7n0URAxnj6ePp6efPppFD2ePhrpUcN+cgu+3n+cxmmcxmmc -3nxkzu87623thVPmQ2DzA4JnVYUEyl0xwOd1+pOA+R8exPqdnmJBPmjxyGShT+FgPZ2CWPzklSmO -x6xHBmAvXBDs0eHXGD0fgTFAeqaGDo9MlslMX6xhPh4ZDsrKJStLmushmXLploWrB+68FOZYoIB8 -ViTAlrmVzJVS4oYS3bgKEJm3rICBbkgyi05BDHJDFVkyPcNcGNJjWkmZ5ai6dhQRDHQOR3LXL/KV -Jnrq761n9Kb7QYKyy3m0lBHKEstFYEILCcuL9icBIyJiU1Nd/0Bffl7BhAkFhYWTnN9isVhTU117 -e2tPT1dJyczy+Yuzs3M861UGBvorKg50dXciYmHhpKLCyYWFkyYWFEWjUb8o969Ube78E28boeAL -v6qOLzkjOCF5zbr18/O6yeS6LLIySvIqlUumm9jaPB/d7558PtUleXkNxZbsSw3gV83LW36IbjLz -5vk03VDyReaG0qwqbhjaCwSZlq7LJJNXz+w5piT0hCgDtNbqotV9JkJh2YQDF78dpjxvCCUjV8S/ -+fUXvvu9L3V3n3ISc3Lyrr7qui984duvvvb8b37zP42Ndc5PxcXTb/vt/TNmlDkp9977p9/d/uOR -kWEvMossXrRs9Tnnn7P6vJUrz83NzdMoIyWR9gyc5d2AYG3+EMCfKlke3oTlBumvo5sfE3wjYF3d -VOQyO4KlSRbF9/zOyUqROCGlyoV1XVIRP90ukA6zl8mSkbeM//vjOy44/63kVy0tVPhZGEPCgEny -pB7zi1+6Ydv2Tf702WXzGxpr/YfUfeaW//7IDZ9xvr7tyhW9vd1BWjKWmZl19VUf+OhHPjdtWqmu -em/06k0PpqLcUVLPl3Raqi4dhdXl53gUMijpwM+UjWXTTa8OUUAm2ELAC6QCH8KvcloFD67CL5sh -EqOq1Y0Kv1g3Geaxhhph+sjICDXpoaFBqVImPuLw8NCDD931xIb7rnnXh2782L8XFk72s6WuWlLV -BOnQTZdfxZ7DywtpLnLouDkVsgT86WgLWWoC7aI5FBbrDN59KJSam3CfLtPV5Q/nIfvvC/P5NNC9 -F9HqzlATX5F51PB1a8cw4nHDoNsqKNLQ0OB999+5adPG//3xn+fNW+T5VXcIIX0tNw15k9JNwTPS -XXYVER41tYwiyaFgytyT4Epeg1WidLueUBbNnszcCZxGU5cxofCjtg70XHW18EW4SC/Md8gSo5EB -hs5wqdzySR1GBZ+5v5HNLVR1SNi2YjF3ewLt2A/QcrzxM5+79vvf+925qy9wTs1BsHZo9RADoDxS -tUX1yMCaVHXSMJDfK5fkFU5oquKLPMOLL8rLgJvclGiqOihVMXWVeCq0Xm9eFX7NaQDZzhccb2hZ -1NyQbwsaC/RcTIUnXE8CpWI2AOEn/XjcSup6EheQ4ovMPkhnBVm07CrvbfEkNhpU4AkHVGJRG+jR -TixUgnRzi+R0CKV4PIZ6te+l3t7ur3z1xkcf3jlhwsTgMY4n1kvFiX7wxEqVqpDmTTe+KG8Qj5os -lSxKLSjq5oP6CRVLUxGso6dWQVTzpsPFNAvuT07M5Ly8YW6l4gLiPME4icpC/rytNxW9IQpl8FNs -paUzGxpqdUFmzpybl1/whijvODk03l7jdBopAmDYF74xL2OMFUGDDCNO897224fWnHuRbhOuW3vx -lq0v9PZ2jdf/G/Yar8Pxa1SvKKK1DzUA6kacsUenuwia8o14HA13FUnBhMJ/+/y3P/2Za/r7+9RB -7v3nH/9535/y8wu++Y1frFt7sZ4GKabTXf9vBhqvw3FKO0XRsOM+ffKjiUJNNeAhEwv6UQNWZdWD -PG/ilHJM54AOk7ZsefH7P/yiVtC3cbC3t/uuv/167blvCVgdJG8muvBLL+6MhXpWMT9d20tGn3Tn -VcMU50hIn/S6m24zJVMtyVWpDDP17pMek3O/RdE+nwUQ6CFMsp01OOUIj5MV5emOSgmAO9+SxAlP -J3kD8F19KA/okWEYBrrbw/zfz7/R19ejieHSoUO7Dx/et2TpKvcIIs/zbUdv+tSfGiuCQXgY4aGR -gxEe/rgjUbqqDmIeRvDF6Sq68WXUwzETdK2L8HDrfFKBo6YP9zaCitvKBdnuliqFg9wKtfBdN2Th -6cCbmczUDcKjZtKYhFmmQh8kISkor6unu56HMaArexylGfmCJP56jMBdj8g3kv8QNfA4ALFPaZ+B -YntKFkekP8fvaTwFB9YiRMNwDo1E6Oo6mSiSRQ8/dtdXFv8kQvpJg5bLFQwItO8iKnk+OUUW9mky -HORvZYTdLXKmxZ0VSngMwsM5CREnPh+JHscnr4dwHOCXIBITkpm6J65x1TCKOLRc4vjINyvd5Yg/ -yJSki0K2ZxMCJRyiqJifWhNK5KrgeJbzpdzUxwaO1GVIfRqExz13BZF7H43EOIY0QLp5GWkMcuwz -v6qWXyxMujmuj2FEezudeRyAuelcbblW4KSTQzTNmG6ngxiHS1fgl8ldvmz1rl2v+d+Dk5EheGcu -KXrttWdjXxrJjGbRljH/ZQCG28UAY1wEdnjQEPakrmUhuK1qDtCIdTCHh4EAn+oDAM4xyQwAUYAj -kyvDkZWX4gDwB1IDwWekXMjVg5O5t7ervq5q3vwlebn59JznU6c6du/bkhHJmD599vTps/PzC9zC -EFfi5DI/C1dIT70Ri2MAMDDQf+TIniMVe89atX7JklXAu3Bvb1dtTUVJyYziaTOARYSViyDrTLim -pB0vz+7yuK5EXRWIKzE+PYwfCD94+GUhhTSloz8XUgC4oEXGApwJkbBgGIKeSGYq6AiUm7TZJxHX -IIUh6/QN0dyLrguAx7WJnlEy1qUuzNetODbxIcvbW4m+EMMCUXpgzxyS16eZKF2Cg57vicq9/gOf -3bFj08FDu/w/CQkNczdUKaAu9ff3Hti348wz1/lvQsyyODIqKva3tjXl5xdkZWUXT5sxbVopYxHz -176BvtraipMn28rnL50xYw7Nb9KBgzs6TrRmZ+XMn7+kuHiG80tLy7HGptru7s7CwsnF02bMnl1u -55UUjX93wdsg5GMsNlJZdaCj43hx8Yz585ZkZWX39nYdOry7t7d7ZGS4pGTW0iWrsrNzA8obZJWu -Oo4+6Bkl9/f3vfraMy+89PiePa8bhjFt2vQ//f7p3A6w6jwAACAASURBVNw8k6O/v/ejH79sYMB9 -MFNUNOWyS69511U3TJ9eJi4X9y3Q8H3fhoYH7rrrlw898ud4PA4Af4tm/s/3/3TWmec5rrpt+8u3 -fvfT5q9ZWTnl85e86+obLn7LVRkZGVJ8BfP2u8zIyHBdfVVJ8cyJE4uc9OPHG6prDs2cMXfuXPdN -cpTcAMpcD4gLm5tW5ecXMBq1PTqphBTar3jZpe4vzIAS05Vt7kpZUDbXKZOrEIt1XSyKINufZ5y0 -aXBwYHBwQCsLaS9WMKHwZGd7kjps2fbiypXrgrd+eGXTU//7f/9FN/7Mysq54m3XXnH5+156ZcPj -T9zt7BT03vd8/FOf/GokkuFwbt36wre/e4tjQvn5E+fPW7x2zSVHKva++tozVMoHP3DLjR/9jwR2 -ofBQx4nWT37qbYOD/ebXnJy8dWsvra+vqq2rcHgmFU39+td+uXLFmiRl2cScv80tx/7+j9++/PKG -4ZEhx9vb2pqPHj24fPm55tfde7YMDPTRmNLZ2fHAg3c89PBf1q295PoPfnbxopUpUgwOHdr10198 -raGh2kkZGRnetOmZVSvXO1X9zMYHYrGY+XloaODQ4d2Hj+z5819+9oHrPn3VOz+UmNyXX3ly7txF -c2YvcFJajjd86T8/0NnZDgBTp5auW3vp6rMvfGXTky++9LjJsHLl2m9/4zcFBWaXEGIGJzvbv33r -zUerDwEAY1BUNGXJ4jOvfe8nntjw95de3oBoZGRElyxe9d73fPyC869IrAhjgxj5C6HVki4lvvud -369bc6lICdnwMyU8oyYogCf1+Hff86u/3fMrCZuArr7qw5/7zK22u7JNrz51++9/0HGiVR3BTwvK -z/jNrx5hLAIA9mjCO7j47Oevrq457M/LGPMPiG65+RvvefeNztdPffrKYyToBGRkjD38wJ7c3Hwy -qKH6cLwBPHff82uVWs3OyvnbX18mG9UFYarwDA4O/OFPP6QxlNJvf/XIggXLzLyvvvb0D374b7Kx -ZDSa+embv/Guq26wpQgpxNLi8fjw8HBubt6Xv/qhffu3eX695OKrvvrlnzHGTJzv/8/nX33taYEM -xi44/4r//NKPc3PzA2QJFXv/B88pm1X+05/8w+ldurtPXXf9GlpqvxksXXLmz396n6OYSKiVfvNn -3l5fX+VX2APIGPvD7U/NLiuneQML4uERmoGHPymzSQVP2nWg+zSA2lRDSnhGTVAAT+rxK6v2K/CT -nHzlX3D+levWvnXb9hdffmXDlq0vDA3p3TqYdKyhOh43MjLILC73AQGgR7LbszByDQ0PuU/M0Ghu -OaaYERFHRkZycny3wiLJ9KfjrQ0lxTPsrguKiqYK+xWfnoMbnrr3+g98VoipIpfynDp14tbv3lxR -uU8mrmjSNDKdGDRqi8VGbvvdd1ua6z9109fkdz9BpXtm4/13/PkngPhvn/+esO16errpDb3shAZE -3PTq0w2Ntb/+xUOZmVkBEj2KjYwM9/R0HTy0s66ucu7cxeYPBQVFhYWTT506QfE9mQ8f2XOsoWZ2 -WXmwG1bXHD527KhQYX9KQ0NN2axyJ6+K/vKvMv4EzSZFPGnXIQJgruA3Q9D4ldTlPzIlmKLRqAch -I5qxfv1bv/qVn935p+fOPvsCLTSThoeHmlvqg/Xs6wva5d+nZKaTseNEazwuGPwKKSsrO39CgW4d -Hq0+eOt3b96993UnZcGCZYoSNzz5j1g8lpKmvPe+2wOCfiSSUVg42WGeSE5VExIiPvr4XSc62xLQ -5OFH//KLX32zu7uzu+fUD3/0Bf+gGAAyM7NoluLimQHK1NVVPP/iI1o6ZNjHvb26+RmaXlZWHiDI -pE2vPhmKHzdUjcqqz5S67b/gFUEAcytmc20JuVwyyCXjUeBXYaaUsKAAfnAuGY8+P5GrY7vLzlj9 -oes/D8D8agPApElTv/WN30yePE3LH0yqq68MqMZ4PKb1alhmNNPB0lppOmVKiUyHgKp+9vlH6uur -tm9/2TAsi5gzZ6H5QDKUOjqO82VPpClraiv+ed/vX3zpsQBBq1atM29BzCwLFyzPy5sQrFs8Ht+7 -d4uui1VW7r/zzz9B55V6RMOI+8GnT59t8psIZ555XvBjlb/97ZdPP3N/LBZXdD0AyMiIAsCOnZsM -Ax1BsxXi/mubnzV4AX6XL5+/dOLEkL7TIQOE7SizMS7gyaONClQ4j240S45fRU8xZsTpOkFeX0Au -uXKh/J4GcBqPMis2njCvimIUXcyjz0+lKpouRCIZX/7yT/PzJ8obErKycq99700JPBft7DwhMRow -EHp6e9VukC3KiGY6aPn5hYohGACWLzs3uClpLHZSj9VXAcCBg9sdtszMbPu+PpwqK/cn05QjIyM/ -/dlX/nrXz4J7uIvfchUAM+w4Es3M/tY3b6NPv4XU1tbc1tZktwUKzZha8sjI8E9++mWVm8iZM+aC -OSuCAAhTJhdPmjQ1gP/EybZf/fqbN99yxYmOVkXXmzChEACOHj0wMNhvrT9GOOecoPfDTaqpOdze -0RLs8gCRggmFocW0SNyOMvfnYiVIo40Yih8uhPPI8cXqJccf7lYyzEh48FO4ZFWepouRS1d0evmV -46lhxO+++5doGMFlueySa1SdgVB/f49QZ1NKX++pcAhCpSWznHqYNm36de+/RTHj+nVvZQAB9UnL -bv1qGOYzktqaIyPDQ06u8vIzFIUePXoAjZBpy4A2feyxv9bWHkEMaceqqgO07cCIP/rYXcKROKW7 -/vbzmz51+b59WxTt/Mkn/9HUVKtS6ukz5tBC/f4P/3PyZMjCMERsaTn2j3t/q1hdRYWTASAWix05 -vNtpsrPPPD8vryBYEADs3LlJ2Nz0au9oUSmpqfqohQuZzsFmrH6lIxyp6BxBtCb4DXohIxfpQAzm -XrRXMdzLQPlFslOVZLB8Xqoe7dDcYqrk5eQmxU+qyGFWtVwAgOeef7i+vjq4LPkTiqZMKQ3H4qm/ -v8+Io90cXj17ejS2gli79rIVK9bRgUNpSZniLcjUqdP9dSs3FWYga2yq7+/vAYBYPFZTV+H8On/+ -GYpCq6oOCO1ENgii6T29Pffed3to0AeAJzbcU1Nb4RhtdXXFli3PheZCxFg89qP//Y+uni40mHMJ -7ap/YEBRGQCoq6ukLm+u3Fehjc8+0NR8TMVVS0pmmVn2H9geN6xBbiQjc926y0KlHDq0y4ijPKpA -V3fX8PCQisKMRSZPKQ2NSMm5fzgmH77EoUk7DGrrL61PYSSneSP8rYN9yfoVrvug6TSv/JJml6Qr -iVDoAhXV0+OnYkFjqE+otr4itCzz5y3Rhc3KyjHfJ/Q2JQAC9PZ2qUPV11cNDPRTJV/d/IxiMHrw -oT+Zc8Hq7VhRudfJXlNzxPl13lzVSqirr4zFYxptTa7nX3jE7HVUiEUy+GKpUlfXiVde2SC3eYse -f/xv3d2qT1MOHtpJ59DVV4LF4/G//+PXombyqjfXboL9+7dRzkveck1ol3ys4WhgVAH1bamue/+n -y+cvS1HokPErYI4JfGl9hkbyiOCxApAUg4hIMt0g6fDmTFe0XYcam2o8s4/uZSfOn686xWHSzJnz -rr76o34cBz8eNh1B6fjxY1u2PUdx6usrFfPW1VcGlEuYXlW5HxHt7BUGGmb63DmLFYWOjAzX1WnL -RQONuPHU0/9wpIdSTlYuMXU9euHFR4y4EeAyhhF/euM/1YGnTCmhOD06XfsrmzbU1h0JNfWzzjzf -jO+VVfsGhwac9BXL1557ziXBIrKysr3Bh5c1PDyoqG1V1YFk3TbQDP5F0iPg9AnOTYRhdyxmStz+ -4E83f4qDVa2W4dJ0O4vZ+Tg4ZhbDNgWH3yD8SHDiRC5NV+Gncr38iAZaf7VwJProRv6uUye5oVac -XHaPvWpVyNoMSlOnln77m3/Izsz14yBYKdlZ4sXdMorHDKu8CAMD/W1tzYoZT55so3Ld+nQuapQI -iFBZ5S6drK+rcvTPzSsoLp6lKPfo0YOuJTsXlSuq5337typOpps0MNDvuoDmkduVlft6erukLgaw -c9er7e2q9QwAeTkTAJiDkxlVXJsPAICITz/9TyOGvKnbcTNupWdGs03+WGzk8KFd1JU+ceNX3f2I -RHTWmRe669ZE7jNpUomitrt2b9q/b1vi7h9mBoHmqmFOYwaH/ELSIxyMyiQoCi96ZJA8LwciunsJ -F6SrmHzajOrgLA1TxJHxaBIzty8LFLeofOW0aTNU0CbkT/zON/9UMm1msNqFBaoL5iwiaO3tzeqd -WyQSCatSeswUxkaGa+uOONkbGo9S/ecrT/XU1B6ynlXqmMdTT/1da+De19ftgMQ039sAgNqawwFW -+swz92op09V1khY5OAr7ae/ezT5l6PFfCIgPPPQHR6X9+7di3A0XpSVl//fj+7OycoTgjLGF5cuD -2yIvJ3+C8nqegwe3J9C+KfDuNyQP52LOFTGQxe3L4G8Lxi/dSz/yQygmi0T+3w/uIdsPSKm3r/uO -v/yosmp/MGBJaVlWVra6hoiukhMmFKlnzMudoFV71bWHY7ERJ3tX18munk7n19mzFyrKrak5pNtw -vf0923a8oF40T7V0d3dq5QWAmtrDMmXaOlp27npFC62goIgiTJ5UrJW95fix1vam4CrqIOtt9uzb -7Pl1w1N/l83VIOJ3vn/TPff+Km4YAfhnn3WhoraDgwNp9eJ/hSsCQBf9sPErqUublGBvu/1WxRem -du959Y93/AANCEBjkLH67LfoqWnnLZw4pbSkzPNjdnaOcOn6+nVXaNVelW+Xi8aGWufX2bMXKc53 -1dVXGnFDS3R7a7Nh6E3WFBfPcrJrdYcm1ddXyZpp69bndZU5d/UlDCIOwllnXaT72se+fVuDq4iq -VFNzuKeni2876bvNAICIDz70x8aGmgD891xzk7MzRzBlZ+eOnke/Sa8ocPMTCaxJGaekKPQeoa2t -cddujdHf0eoDp7pOFBVOCeC5/gP/XlG554TiBnDIKfm97/z13vt+09/fMzI8NBIbiUYzP/WJb2Zl -5WzZ9mx1zcGOjpaCCUUnTraev/7KK6/4ICgU0KGqo/s9zE3NNUuXnG1+nl2mOt4fHh5saKyeM3tR -OKtNGovHAQBg6ZKziwqnOtouKF/x7nd94uFH71BHaG6pk9VMfX2l1p3j1KnT5807g2ZZt+atl11y -7XMvPKAOcvDQ9ksvfk9Ab0HfTkA09ux57cIL3umkzJ9/RkXlngB8w4g/+czfP/WJb8pE1NdXRiKR -eDy8w8vMzAYduxonP0Xth51BpLuVlJBfhRmTSA9VIIU6yGVp2iIDtLOgZzs++ySFwxVB7uQnRKw7 -VrFqxXoPJqX+gd5eydZsAkBAA9DBKZo07dM3f8dWHxBZhDEAuPytH7gcDEd/89wIc1ARulWgSf4x -Y3NLXRwNE7+4pCwazVTcAamm9lDZ7IVSub7zZ3Tj/oeu/yIyQEDnVIv3vPtTTz59j7N/dSi1tjYY -Tna+Ho41CHbgCaDzzrvSgbL+RiLXvf+zL778sPpC/ubmOg+ISU4FeqD27HvtvPPf7gTx8vLloXvn -vbLpiY999MuZmdlC97zzr/9PceunrOxs02uU3dlpJbfJVMxS3XQh5fyiI4N0dfalu2fCRKxJSmvN -U8jzA0+ikNkcHqK7jMrJS8l9qKuCDyJl/AoQTDqZxfEDLzoVslyegoLwWXhPk3nwHf3Rfpeu5Xi9 -7tBm6pTpDqYh0vmhh/+ovsTbbC/DXQoHDJh5mU+mDXfphJuOpFxCHRxYs426ujtbjtd7RDc11Tk4 -jEVKS2Yr6lxbd8RcKCVqa7du7ZqGjhPH1Su5fP6yxYvO8jR9Tu6ENWveqogAAKe6ToyMDPtNLm5g -Q6NgZ8oAuvD8q8wKpzhFk4pXLF+vDjIw2MdVkbvq0lGMi/sHyUYaiLBo4apwEQO9+/dv9dQbjQ+K -qmZm5qi7pL1KybCXKGGYWbrZVXg8IUKXP9REDXCDmJyf0xmlZXHCshE1edxBp135wj7f0zJqPChK -dxs5YEwdyuNJFxoOI8kynlTJuvrqG6trDrS0eOOXjBhwQyRenPXt+HHBvscBFIlEpk6d4cBStZ1b -6JraQ+qACIDW0TzowfFzOiSrRmEZTXuIRrNGRriXNlv4yZCysgWKMbGm9hCgdHUllWsAAHAPLUNp -1qwFBgqGxsvOWPPqqxvU45cRj0PUcj5SEcKhoZRmly2cXbbQ9CePWZ577qV796me+rlq5fmOU/I4 -dqPz4/32juaBgT5nH/+SktkTJ07u6joBgbR9xwurVl0QIWNZvRENAABkZ+U45aUkc2FfWYJcw0O6 -PHJT1+VxLULF9XT1dPfj5DtPd7xMf/CM2flOVcjD4XhEeBhsWZ4hoYAnNJ3ikEGllCdQFu02BXVC -izxn9uLr3v9v6o/UkAGPw/X55tXUVKOIZtKUKaUZkQwHiC+OlXzqVIcGIgIQfTzVKKxDXzXSQRAK -dZuQX7Rq5Xkeya1tjQZ5D3XtmstDt700qavrpOcWUybXqpCwgEVp+vQ55r5DfDFhUpHe5qnCKmXA -Cidq3DVecME7EQQWDggLyleo4zz9zD07d78sdBNrvM9PwhQVTc3OzqXiFi86K1TKrt2v2JVGb8GR -jAPDKTMzS6IntT06/pWZARfBkuARm7pPJesSc8hl6bqSCk809K0TlEUxrhslPEzWh3k6aCb8iNIe -UMwvGzB4jqoWy+IziIEkxREa6vHWY3+643uobMQMmYHMPQybE8UAoLOzjS5pV6Hi4jIpJgAAGIZB -l0uGEiIYhrQtULONUNLuzz73z527XvKIjsVG2ttbiqdZu8mvWfO25cvX/+7339wRtuZyxfL1aABE -6LhSYg8AAJCTrfEuG4OItbaFP3O7qFBv9aS5OY8n8bUtT7W2NaiDrFp5ITlwndw7Mpg5c2FWZvaQ -2quw8Xh8x46Xz1wl2l8TAcA7z3PZpe+3JpdslsWLz9q+4/lg4z95su3YsaOzZy+iNmHqbxiqXpOV -lesKUQoL1Fz9dzImi8S1pWYvYVIJcYGm6NeH19NbbyI9Zeq4TFHyo7jeEYVn1vM8RDB/4D3h5idc -uOKihIdLR0E6JVleKoCRRvXooIsjKssf/nir1pEmLGK+NyfSwQBgsGPHi7q3wvPnLgXD1sksr/1k -hzEABEP54BSw8tnzPP5mtfWk+B4WoQ6evPFY/KGHxHuQtbTUTzPjPgID3LDhr6FBHwDOW3clAwCD -b3dXB3R1QAAGV17x4R07X1DssE91daCBjDEuzgLkFyjvJGzlQXe+wrahrVs3qo8bsrKyZ06f7xST -d0PMYJG5c5dWVO5WRDt2rMKyHJF5e57rNjRU9XZ3kZetcOnic1Sk7N376uyyhTw+AgRMy3kpMzMb -7Qkbqqk0jNDMnFmiaxIAHpPwpntIhsN0cGR5vfgiHJn+Xnya1w01Ef/MjH2jYE+Nofsuq+dO0rmc -eRDr2YFz609vWLwPcUT3ItxjET494bzIf3RxZDzcG27iuzJDzNOrucUxYxGPem5dIWLceGXTo+pR -wKQVy88jm7KB2zRoNV9GRjSq8x6/pRrX9BCA7zUPRI4HBXkPHHi9q1s809LX103z7tu/WUXlP9zx -nVh8hNgGgNPeQPQ0EBDAgN27X1Gv556eTtJejsVJhiMSikQiLJLhepptlpWBqyE9NHv2YhaJiN3Q -QEScXjpHHa2h8ahVIpG7xePcPeK27c99+7s3DA0Not2mc+Yszs0Nn4Xbu+81w0CB+yjH/azMbMFs -iKoLq5qE+a6y2D0DzNsIw/fmJbKU3CeJvGTZToSvFVdpfupRxkN2h6CxPjQvl52vTmE6ePB18vpV -db2EWINWXhTzmCuL1YkBk26ygfDiyw9X1xzQAszJyVu06Cx+tk9Q+eRYbQUStF0IvrfeaPOJ8soe -P177ns+uW3MFlTtzptIBLE1NNc8//wDXStJ6RsMwNm95Sr0+ppfOBWQ2joOPwI8sg2n+vOUZkajH -wrt7Tsn6PzHI3GVooMx+EGHmjHL1p01DQwPHWxsEPmsAGhD3HS7fcrz+sSfutJ6/GAjIliw+O1RK -ReXuwYF+v/uoz/NkZuaEmBwX+zwurGQS4Twpy8tHklD8ZPISiqD+I1Mx6WRIK7gqJYEpy6p8VrVF -9ll9Aqqs2nvvfb9AUTQMoGVnrOGiiYQUX4w0ydfPcfWApB6kFRlW1QcObRWKfuiR3935lx/QR7ul -JXMUA9mDj/yur783tCoQsav7RGdnm3qFxONxIU7hxClFhYJTroQb16w++xIArttAA091hhyW4qHy -+cs5EB+97fLrVyz3Pi0PoMbGahlUTDQ9+PiGP7efaHF4li4+J7R1YrGRQ4e38+VGA1H9mVNWZrZf -Pc7EknNtVDHpsUqK+kfN2Vvg3wigwSYgXURk6hSQOXNL8uyewKYgQsqDJI0B+t5gSCavOYHmpjP7 -AwXUmz8BYJEIEr0QYHCwr/5YxYGDWzY8+Retp68mrV1zpTXJJSLRVGg4WfdYJAttVmobyE1L0n/9 -063uXHR/f49szRIiPv/i/Zde+v6yWQtNfvWJi56eU7t2v3j++nc66hH9OcrL1dvF7KFHbs/MzH7n -Oz7OfBbyH1/85dZtz7oNx9jyM9auXHFeb19XS0tda+uxU10nRkaGzl192ayyhYbdTI4+WsuKLrzg -XevXXWkgbRcvRSIZ177nM/sPbEa1AUR3z0k/p/k9LrLGkZGhzZs3vOuqTyIwAFy69FwVKfsPvr5q -5QVOD2GGIM88UgBlZmYjdRubUhVSPIk60c8fRpx0r9kH6yB7RC3K64QmDxcG6B81bwHAsVyRNjqV -6xQMfdqIMQNqIVEeJx5xH/w4IuUQSRbmcnG1h6RoFFNr/1sw53nsfhcAnthw50MP32buy66FY9L0 -0rlrzrkckFvAqzH1ICFz1MAbIjVosSxqDzyPN29N7eHgfqjzZFvZzIUmf0mx6qtbALBj54vr1r7D -jC8yR0KASEZmXl6B1gP5+x741dDQwHuuuYW5D+MQAWbPXlpWtoSKM6VPyC9auODMhQvONJubMYYo -cKUu5YNWAKCu/nAsbmRkRIJd8sGHf6duTj09pwzRegfDMAzJ/PvW7c9e9Y5PmDG8bNaiCfmFPWFP -uQ4e2kZWHgAAjAxrbGhqzvN4SCVcACi5Rip40McjdhmVWB8m18tL91+Q6e/O79NpXM9LZc5YzvOT -kEeGE4CJoiwJ8CQsK1W66Y73ASK03jY89Ze4EU8s6APA1e/8JGPeBzaeojndvB7Jm1LY7ijn8SPU -1B0MFn7iZKvDPHVamXpftv/A5lgs5p8I9us2qUhzCSbiI4/94e///FncMDzVC86bzMAAmKf+AYGZ -CytEVaG+zQMANDRUbd7yVLDbxkZGDh7coo7Z19djjjo8UAH7xB07VtHSeswp+9Il4UP+pqbq7u6T -1G2jmdmlyndy0cxsgUkrhIIEzDUxk1bH8Rtn8jwqukXN4RzI70BUokRCkURGZJGsAnA61OP5xd2w -EDMjGtUSxCIRep+ueMSokGZMn7d2LXfX7yf3nsXQqBJzvB+KqSJXSI2NR4O7uvpjFYZhmAPnaDRz -8uSSEyeUXq8dGhpobqk154hkAsz0hQvPamzS2x0BAJ7ZePfgYP9Hb/h6JMI9LwmWFUCxmN4+/sND -g7KmMVMjGVFQfq4LAH19XZ57OxOKRTICXsetr69w7sOWLDl3+87nQscu9ccqli9ztpFgAHDRhe+9 -7/6fh2bMyIiaq+Ac3bQoVeEi/WEnGVnhdw7uuSv2/6f9onTaldHTJyNDM+4Dd9hxwpSdnXfLp3/M -WIZioWLKc6kAaaxbcxVaY9jWCzU1+2mu0hLVgSEAHDtWoaLJEoUHkkJ6+ZWHbrv9K4P9fbplF14j -mk90srPzQjELdI7ZCcB597s+I9xtGwBOdrY6bOvXvbOoMOS95Qn5hXNmn+FxMc8WHTLKyspOn0FS -szSvsYwpl+UO7GU87rnqgOl08X+NS+YYMrLe/XFbLBFijN308e/MmlGurqf2E+P0VBcCxo3Y8da6 -YOENjVUjI0NOLq2439BQaZ3NFHgtXXyO1honSjt3vfCDH9/Y2lqffIX410oGU3Z2bihmfv5EdcAJ -EwplOBeef83CBWcKc53qbHMqOTsr5yMf/lpxsfeQBkqlpXMH+ns8+Nu2PaMywzl/3vI0WSM1S+ca -y5jJyIog2kuqUyeXfEt3GWkRSSmTuVdIAieiGTumTZ3FVZY+FU6c8pEPf/3ssy7T0lMz7ptV4WY/ -cbJ1/4HNRyp2HqnYOTxsbSrZ3997pGLnptce27Xnpa6uk4qatLU3hSoTj8fq6484WUpKZquPzRsa -q1TUyM8vOme1xm6aHmpqqv7+Dz+2b/9rrt3ouYD1r+zZqYxywsb7hoEdHRrn9E6cOBX4e1Dnuu+B -X1ZU7hTmys7OpZyrVl70w+89/NEPf13WTEer9/7yN18cGOinuYrUdjdavOgcV8NUuTzyAXI086bj -UtAniuaLNQhgLrtUjD6MfHCnjf18YXCqOAkQpghfi1sj7hdMmLR08bl0qr1w4pQTJ5VmrqdNnTlv -7rKlS9asW/OOzMws6Xw9XTOB1l9zda+6nojOy4cAAE9vvOuhR3/rIMwuW7xyxYWHDm+trTvoJEYi -Gd+79b4Sc9tkW66Qjvv2XhZSdfX+8nkrzc8zSuerK9/QUImGbEcOrn6uuPwj23do7JHgof7+7l/9 -9ovvueazb7/iRgDnJhpUXQABmHt2uSJlZeVaCkvMe2CwT3b8oZAKJ06R2dLRaumLxGefeSmYMYbQ -Cy/dH1CZzS01r2958uKLrnVSyuetPHhoS2j9P/LY7UuXrJk3Z5noR1/eBN1fxCFypVTnTRE/Un6x -PlHr5C0gT1GdhenuumRffyCrRJW8wqXwioFIQs4wKQAAIABJREFUuoz+dOMjAIBWPL3+g1/OzZuI -DJ29mf77y3e8+PL9G5+7O2AInJ2d99X/+tOsmQvBXiPobVgT0Nw0wPzAb/4VUz6LwyRzgGBST8/J -R5+4nR69VH/sSP0x785x8Xhs8+sbrrn6lqCBOUNA1tqmtMt0bf1BA9FEmzt3WUZGVPGWpae381R3 -BzfjLKmf2WVLzj/vXa++9qgKrJAMw3jokd8ea6j82A3fys7O9f4scw3iSllZvlyBZM7vm3mFpNuJ -zZl9BpeFmLpsSU80mvXa64+/771fiEQyHP7e/q6m5pDHNo8/+ceLLnyve3LLgvAd/AHAMOKdp9rn -eqb6ZC6pGOv9JuHfLk1Wz+nIqxTrQ9w8iBA87+tagztEQGRoMOuvM0Equ7FyuhmU53Uu5wVispeF -AEp4g2yAi4xMLN3PYxClXbDU46vfp0ciGTOnL0A0oazsvX09e/dtCo5o8Xis81Tb4FC/eVKUqAjM -+mshM4/+GRmZU6fMUDURoE0OTc21igG3rb0hpE0NhghtbY0qQ+z6Y+48T1ZW3vnnXaOufkNDFd+I -fP2Q+r/h+q8vX6bxdqufEHH7jo0/+r9PtrU1JuAaWZmCN3sDKDsrL3iuQyvwz5q1cPLkUgvE1dnS -Vhb3Y7HhZ5//+8bn76H8JzqOh4rr6upoPl7r1My8OctVH7Ek5rb+S+DXvnAk5PeZsdCcCD86zWN/ -UHLVQJ1pXrT+evBlOiOY7+sCWD1lmJl4R77opmsNLbiFRnzOUBzPIiXdIU3wHVAQfzipH2tnGPFf -/vbfv/ftB+nWDnf+5Vuho6RYbPg3t30JgE2dMqOsbPFbLrx2yWLfimlaRSJvPfvstz6z8a+KqlrW -ZKutmKu3t8sN6PI6bFPbc7izkzsP65qrPtPT07lr9/MqeRsbK5edsV6lHRmL5OVpPAUNkPg/P/7o -jR+5ddXKi7TsR3d/p6ysXN+0DPdVa9rqzJUX2+yCSBB8L/vMxrvecuH7su37leJpZaHHLgLAoUNb -p5fMMz9nZeWWzVpUf+xwqJ52QAv0TZVyo/CLfLBN01ReskoHvrRcEnwJf8RZomgkcBnkSiijeZdh -vRtivYCQjFBuCVOKLg1MxQNCTTp58viBQ5tp9pbjdSoZzeZq72jctfv5X/z6c3f+9dZT3Sc4PcPa -5V1X3SLoLWTigDkZp0yZqZirtHSuSvV2nFR66jgyMtzX3+Pkys0reMeVn1R8utvYfDRuGKHtiwgG -4juu/ITKppKh1N/f/bs/fHnD03dq2Vim5jxPZnZOKLg6WseJ5kC/C4r7vb2ntu/Y6DBnZuVOV3gM -c6RiO22a8nLxeiEPoWPhOo7sRDnyIYlwIXWxFIUg+5RFw0hLKHPjvo/IraJ7uxJw0Wzh/IQB0a09 -DHg/zSNIdFdLmVT4Q4tGuyEM5dddH3n8eD2njz4h4tZtT/7ofz/W1dXuqKpQLtbVpXTk1sSJU5Yv -O9+pxsmTS6dOVQr9ZbMWM3v+WtYEhoEn1Z5jRzMyPWvVd+0OOeLDocamo4F26OzCaiBCcfHcj95w -a8JrOikhGo8/cfsjj91mnvQb6CYWaY33o9GsCIsG+peeVR09utuZHfADhs5hvr7lCVrSuXOFj145 -qqzaaRiGk2XF8guV+nLViOQPNeD4M+0D/JFBGD3U5Bo6bhiAL9NNTx+ex9Ut4qlH82IIzJrYU6ob -3ohBhZ+iKkzFcYKYe8kwBYo5s2I6RePyhvLrvm+JnqnERKmzs/WPd3wtNjLsNxqhnrt3Pxe6at6k -iy+6Lj9vIq2KNedcGZpr0qSS1We9VWigVI2erg7FnnLq1JkMuHcd9ux9SSUjALS21sXjI3I7pE6C -gLhqxUXvuPITiuDBhIjPbPzLtm1PKrpJlk7cz8zM9pTFZ9sQiWSqAw4OOgsrRRUVON4HgOqafX19 -pxw1Fsw/MzSIDw721dUddEQsLD8rPy/87BqViCR3c71oQ0KNklxZ7D5d+LKyR3x9CyJ/R+D/NYxk -clOW3X/7lmheeRXpFcFiHhnRjft84ynNSoqpumbvfQ/+jG5ZHKDn4YrtiEqyNm95zDDiNG9BwZRQ -f37nlTdFo1mh9dnZpbrt8NSpMz15s7JUQ2Q8Hms9Xq/Wjha9/YpPrl93tSJ+KD306K9lWzd7SLhj -s4wY8xqn37aj0ayMiOo75INDfQFNFjreRzQOH96KdvRYtFDp+K0jFdscQYxFVqy4MDSL3CldndXc -XBcnnF8N36XTFWkj3FNs8YNsJrlkPIHdZziUbl5dlQLT3efjTstoyNWP+wbVIcndM1/b/EjL8TqV -8g4O9itidnQ0NbfUUsDde17EsD4jL69QpR1nzliseCbtlCkzPTgzZyxSLAIANLfU8O1LoAzmb2KA -yPXXff2c1Veoiwignp6T27Y/NTw8FGo/mVG99TwqPpWTo3rGTiw2Eo/H5a4Rvlbt8JFtzsvRhYXF -xdPCN0+tqNxBZ4dWrbg4fKpHWmRKqQoLKiFIJjfd4S5xuRHrdsfw3PqoENWSENdFgpSNy6JwiIwu -SdUI5HfkOlWhI1lxjxHXgHndFF9ZlKIhPvf83UbcCC2v+rIcAGgy58cNRAMHB/qqjopf2qT05NN/ -ovO2suqqrtnT1a30mGHJojXA35fPmK5xklTL8VojbnDti6R9RQoyYDd88Fvr1qZm1H/3P37w1W9c -ed8DP3FvyET2qbueR8Uv1OM+WFM9YlJZo3zoyBaaZdHC1aFZauv2Dw8POlkWL1oT+hKDtKjSMJIM -fzLhSxMzLfqL+cn5usEzBJQt+M5HJVZ7QEKyOD+AnResvzSd+6Cghp4OSmXRjfsGcqsBPvC+ry5c -sFp3kx9KO3Y909nVGqqqVtw3t4Y2a6bjZDMq+H9jU2V9/aFgO+np6fzr325V0eS8ddecsfQ8T/YZ -MxaoF6G1tU7bLAEjGRnXX/e1D77/q7rHKvgJEYeHB1559YHtO56yZIn0ydRavx9qqQaigdk5eeqQ -A27cBwpiLTEJo+7ujqbmo072JYvXqhy/dbR6jyMrIxJdtjTkFQppE+o3ccKjyjTjOGFNGN/sdO5x -tQIRPcl6HtWnqppPYelFT33UAOHLbJXWMXt/HaVDB6UK0V0CaDeedS1aeO7nbvn1d7/1yPp11yS2 -PWQ8Hqus3BmqqlbcB3DrTf0gwIbGyuDq3b3n+a5uJTRhs04v1Yj77R2NQS0ot20Atn7du7/x3/dd -evGHk4/+APDQo7/s6j4hUyASiWr1+krF0dlze3DQ2VgUPXUSvI7ToSMVW53sixaeG80If7BcWWVP -9QAgwGKF3kLDzQ1RnaTU69OAI4/1NN1AcRkVrogB3kXfSBfXK1wG/4GCeBlkHZ0IUwaS8GVhkgGo -VhlV9Lny8pu04rXhk4IIEyZMef97v/KJj/1I6w7dpJLiOavPuiJAf+urzlYNiMyZnFBXibGI0JAc -MzvWcARRKSS1dzT6cbKz8ydPmq6ljEr7Clu8qLD46nd89vzzrg2XFEZ9fV1PP3OHNekkUmPpkvXh -KDapmO7wiMb+PIMDfVIotXfRG5uqDHtNfmY0p7xc5aT17bTC588N2bBByT1JjPG4bYDXB5irzDzU -Q0cK8zqhDEkoC5VC8wrW8xikc/HEZ2Hcdgj4X2XpAVAGyQL2V8NWKYDfn55aTMWylBTP1dtiBQ36 -3orTHTOAZWdc8LlbfpufH76sjVI0M/tYw6GAsluX2tjNVtKl7GzBpEEkEimcyJ0nzhhbumS9QC4p -Y0Ojd1cfGXWcaPTjIOKM6apD/nlzVyi2L/p+tSoQ4K2XfmTKZJ39LSS0ZdvjHSebhXaLOkv4VfwI -NZ85DQ71C6Hi8Vhfv9I5lC0t1dRNli5ZHzoSamqu6uvvcpp4ypSZEycKjqd3iDphAiFI2OjBZiAj -rVDmcQEZf6r0CXA9QIxaTABADubxrChUSieNK9y+Qba9gjSd/GDeEGnhuMqQfeHo+FK2Qx+Xzhcq -lP+ef35/aEh1qQy4kwminwBmTF948yd/fvsf/31goFcRsKmp8q57bv3GV+93nE14EGhca56HMQAw -ZwumTp19+WUfP9ZwqLe3c8KESUWFxfPnn7lk8bq83IJDhzcfrd558mRLUWHxOauvLCiY6kwwcNtG -MACA4ZHB4621ivLzcieaW2p6mnj69AX7D76igjAyMhxQzy7xJkd5GEBebuFNN/7kD3f+R+epVkXN -hRSPxzY+9+cPvu/r4J6Ma7lMPB47UqF6LOLgYO/IyFBWZk6w62ntxzk42O/ZvdSa5EHVucHWtvpY -PG4eQMQYLD/jgkce+0VwFkSjsmrnqpWXOnIXzD9r5+6Ncn7LGnVDhOcn2Rm5hqg+g/jTjZOqdPIl -ar6hZX6R3XWHptNtIVViuhK4iqOq9EmoKZf/otUXqscykwxeOX+DzZqxeNWKy7Zs09gksqu73UBk -toJCg9Cc32fO7QFjGZdfxr3TFLGdb9nSC5YuOd9mY7JymelNjZWovIddSfE8M5enfqaXlqtsAgMA -r299tLh47oXnX0dUcHFcPVGc7jTxtOK5X/j8HXf/49tHq3cpKi+k3Xuefe81/+nswubg19TtHxzs -U8fp7GybNm02LY/f9fTG++arW750xjImT57R0RG+mVI8PtLe3lBaMg8AEKGwsHTmjEWNTRXBuaqO -7lyx/BJnsLJyxWW79jwrbVm7vjyqylzVkzU8XVSfoB9zZTgyuamK9TJ8+iUC4jsGSp4HDtL7i9CJ -FxUoXTVURCcjSwtfa2wFAMhPwQnxFy9ep/XMIB6P9fR0BuupF/e5J0vgecmAu5G0BuUsoN5MUp/k -AYC8vIlt7ceaj1fThd4GYmlpuTrIK6/eJ3ypTdd+8vOLbvr4zy664APqov0Ui43U1O7147d3KO1K -7dDJzhZR7Zr6g4EQN4y4zpmaQ0PSdZzLlp6vCNLccpQWbfmyi0INuKp6B5W1eNHa/PwiGbNBrE7F -VdXCjkqUE79jpR/iUhPKknnnKwKcFiC6QhnUr2SgUqhGumSN6DxDAwBUwF84f3VuToEWbFdXezCm -1vw+YxHlOlGtt8bGClR7qAsAr73+4E9+/uGf/fJjv/j1jV2nWh38KZNmqj9N6exs6Q6rFsUrIxK9 -6u2fv/66b+kut6dUVbUDDW8tdXeLDy6XkR/B0xYjw3oLi4eGBmSA69a8W3H8cby1liq2YtnFoVk6 -Ohpp62REoqvPkm8Hom1yb0QelStxnEhyY/BxcikWG9ZdHxm2rQIiYlZW7mdu/s2kolJ12FNdbcGY -WnoyYMFoCVBjk8Z4H8CyzOaWoxufv9OpNAAoLdE5e6upIlX6A8BZq9728Y/8WPigW4Wqqrf7YXt7 -T6FydwgAOTkTgvXUWswDAOa8mZBe3/qIom6trbU047Sps4unzQnOMn36ggkTptBcb3/bLVe94/PC -niYjkqHcUOMkpgiJ9rIOAFJ36cKq8KdK1WRwEBGHNcdWYIWzcB1273k2kqG6ywoAdHFxX6CwXv9k -xYKUtdHQ0IDuhIZDDY1HKLLWKv7GpiN2n5GaspTPX/3Jj/00LzeRLfubW4729XV5MKNRjVYGgP6B -nmD9h4f04n5GRlRW/HaFyX2TRmLDHpUuvujDwfcKbW31R2t2UrmMRZYuEr/AlZ8/aYy5fzI42u6j -ySNOj6IBhoEMABnyT8gd0hiA6JAurAp/EqrSrPTpO5ceBBDT2XzfwjZbI1AhROPFV+6Wswmou/uE -YaDtaYKMeus4gSGKcXykwIPY1FSpVRxK3d3tNK/6o10AaGyqsBlV+D1VJGx7nF227KaP//zOu/6r -t7dTRQc3J2Jt3d5lZ1xEE7Oz8tWLAwDDQwNSZkTQXMwDABkZWbIqGlJ/4IyAzqogBgBw1qorjh07 -9Pq2h2U54vGRv9/7na99+UE6dbbhmdv8pWOMTZ1SJil1qiLVacKhhZIuT0zGDd1067wtNAGZxIiQ -/Gsr5PUDUXz0oLlZ1IIpkk9kyZuUn+Z08zJJDrkObi145JJ0f9645ub7AIBoIFk3xy3Ic3n0rCcn -J3/F8kvcjLQLs0H139eV6yDCB0+N8jyNzSGrOwKor79rJDYSjWaa+KUlGo92G5uOGAYyJhjdbN7y -UFOzO/W0eNG6lcsuBYDWttqa2t3tJxr6+rviseFzVl+1ZNE6T97ppQs+d/Pvn33hTsOI7dn3nLo+ -p7raDbRdCgEAcrL13veeUDDF2zS8ZWbn5GdkZKpvD56RETXXmPndbXBIfaERWv6Hrj5Xv/ML/QPd -e/dLj0jrH+iuqt6xdLE9xkfxm8YlxfMzM3MEBqni8r4s7keZ6Ur4uSW/4mSlKMeFeu0zthLXzTq3 -AQCQoduXIOMDvGD8i/JSSfstYRYO213/xzjrI81KOp8AfqKou1AVJDzoHC4vkEs/CTs3S4dYTC+Y -AoDhsV9aFW49ayzmycjI/NAHvl8ybb6zSFK4uFtvfp+ZD4FIKGCS5WRkhTAxJt4lkTW1JD7ez82d -aMTiEMky8UtLymfOWKz4tKCv71RXV1tRUQnyTlVbv/eJp35N15Xu3rvxSOUWQNy7/zl6T3boyKs3 -3vCTheVr7MKA2WaFhSXXvvu/9+zduHe/6mkwpj4YB8YY2jjZOm9oFxWVTC8pRwMCXHVC/uRLLvrI -cy/eqahVZjQXDMYZnW326nF/dtlyewjpumfV0W37DrwQnPHwkdcWL7Te80KABeXnHKnc7NF87bnX -ADJ3SCMchiIdwPLurBBnOY8jps71hpwJic2eAzUiQh4+PFIlyMk/1JWQupKMR5jMhYIomHGfATMY -rUd+kG9/YO4HC53x6JSH/sv4X4GrE5KCaA+r0YFlttaCAOiKcW9Pffzu6IPPZHFY/FazesM7zWIu -S6dloToncEgTgjXcRwveJxGAsWg0W32l0JatDxdPnVtQMMX6TkK0E5bVz38HAICIgfatoFlF/q7I -0pbUs6ft7M8GQHNzpY50jq5993+bwz0TPiMj59M33V5Z+frd//g6CprNS41NRwonlngCQVX1Ds/L -BIi4e88z/uyIeOjwpvL551hzaJxAVlu/V6s/6+k96bFMrfH+OWddFY3mWFNwnik9YqVnLLnw+Zf+ -gqjU00+cOBUtm3YBzbcxhtT27l66+Pw151yD6HENON5eF9o+FZVb0AxGCACwsHyNP0thYQmSMOIO -j8hg0KoQJ8nwDbdprfvGckhMnQZLgs/FUOD4yV/Pe2UiHoOkeMORh59T0cxL+gDJSIxGaSrXfl8X -RbXgJ1/o9ERUKYI/Y6gIf8NIuknvx2BZSviBukkqIWKud9Qhw9mPyoSR9DdZWbmKcT8eHzl0ZNOc -2SvPW/d+wc82vtb+PAwi5uJ8iiAmWX9JPo/EhhN+qAsADz/2k1MXta499z0Uue7YfpWgDwCNTUeW -LLmQ8f1We3udugKxeMxAFM6yzp+3eueuJxU1AYDevk4P1MSJxeom9NIrd80uWz5v7lkAQTV/30M/ -UL+9K5gw1fDNrqDVcOHLFgonFr/76q/k5Ex0QWyXmVEafl5Cd09HU3PVjOkW56RJM4uKSjtPcSdx -vvDSXxaUr2X8/Yj3EyiGAl8Y8ZmrH1IKyI1wzZRgCG+KwMX8mIIMwbrRAYr7Q8T7yNd67Es/APkQ -+pxaxi8DDH48LeM3ydl2IkCoTFaq9HHTtc60s9qBq3OpXN2dIDs7WwwxspWiOd73V064zrKU48er -VXb0lVFfX+fWHY/SF2ROnmx+dfO9itmbmiuIPpZWQ0MD6gpkRKIyd1i65KKAt4381Nvb6cGZOnWu -+n6csfjIq6//03ARBDXf0dFw/Hi1ImCERSZMmCJzh7jCsoWu7ra77vkK2dTTNYCyWctycsLvZioq -X6cZF8w/18PQ2HR4eHgAEeXur26Wst1rEjdv+7MMMzhvOvQUk7kvmz8D/YDkQyiijF8GGIATyh+q -ZAJ5dfVx05n+vvm+bZrEcrVhwaObrxR68/sZUpyQuhKktByv0i4PTx3t9QMDPQ50U0uFeh01t1Qi -eenX1EplJOtQdna+qPURESMso1RnXenw8IAHJyMSnTo1/Iwqh1paqkgNC2q+4qjqbj8AMH36ImAR -HtAlQ225WlNLxcHDr/hNgrGMRQu9j8T9VHl0C923t3z+Of7p3d4ep79MzIU9KUHmqoOTKlnp1hMQ -ree66qFF9sh5nCCB81Ks1ggj/eG594FxUoDWysLUNH1rWw0mZzkI2Nh02BkJzpyxVD3vwGDPiZON -UybPoon5eRqD9Ny8iYAgK0LBhKCNJP3kb6bSkvLWthrF7D29J3p6ThRMmCJjqK7erl7bC8rXyMxG -ZbDvUG3drlUr3+aP10sWX7hv/3PB+jQ1H+nrPeXcNs2dcyaLRDzDlJ7eE0Xua4z/yhFJVvbwOrHm -eex+AczhPx0xOulmIrmsRBm/J91JsXqatKXLrnTjRFhUbfmYSznZE/iu3P1G0/v6TmnBDg8PinR2 -MSNMo4ti4D3AW0VnWXq/2na+wXTq1HEbGQoLivN0dqtuaq7w6DlxosbxlsXT5gW4ySl+MjqYzlxx -BTNXnhCc4uL5akuVLWppqZTpE4vF6hv2K+Lk5hacueIK28e9LqA0PLGpr79L6Cbl884N3dkCEauq -tzo65GRPmOXr1/v7TxHXcyrfUHBtbXNNbXpgSEkAh3oixXEPnfHLNVOsfRoMhdgtIxm/J10YK9OR -HqBnunGyNddfLyxfC+S8Y1nDTy9dqAU7PNwPAp1dzLw8jUDJIJJCZ5g1c6lWXBNSdla+jYyIOF3h -maFDLS0VpEoAEOfOXqWuUmFBcYCbtHXUK+JMLJi2bs21fpzF5eu1Tm1rbDrsHNPs0aex6aD6e1vr -zn1fUWGpzAW0BgoATutzbpIZzZo/75zQrFVHtzpGi4jz53kP6TUMTDREnIZYT9MDQ0oacfw8Uasf -kN0PjJMO5eYUDA72KDIvLF83c8ZSVKj3C9Z/6P6Hv6u+saI5cRxA+XmTFKHAXr+fEhoeHjh0+GVF -W5sxffGVl38+KzM3KzPXwPjw8MBIbGhwsMcwjAXz11CVSqaVH63epqhDU0uFpziLFpxfNvOMhqaD -KtkfefzHH//ILyMRwYYKsdhwf3+XohrdPe0nO49PKvIeGTZ5ctmF62/Y+MLtirV08PBLF194o/Cn -6pqd6m594mQjIsr7PxaJRFTXBZkRR0RLFp1/pPK1YK2qa3fE43GnhufPO+elTXfRLIYRT5VB/stS -1BycA0Dyo7Bxys0t6FSekrn4wo8rvpO1sHz9p268/fGn/q+p+bAK/1BY3J9eurC6drsKFKQ07m/a -fM+xxgOKzLNnrZg5XXpzwMX94nL+deogajleFY8bnocx6gfRNLUc2b7rsTWr3+v/qbWtFnVqqvLo -60KcvQc2asXr5pYq/x1PLDa0a+8GdWWafd2hh3JzCvr6VY1bBrWgfH0kkmEYQU8LBgd7jzUenFNm -nbY4o3RJTs4EOpyKxWLjcT9JihgG2Bd3ACO36TP5orKvvRBHBUR6eqQuv6wgOgp7dFbRJzdHY4uu -g0depACGD9nBNwxsbavp7VXdpHd4eMCqZ8PFNHHMLwvnr9fp5iMynHjccL6hpzactiZ59x/U2Mag -pGQhIoRiGojTpmrsyjkyMtjeUU/LMjTYd7xVY5XR1u0PjowM+S3h9W33ad029/d3G6T2HCosLFEH -AYADh11Dcsx4x+7HtR4LdZ5qdo78FLpGfr7qPSLypzJQV8rJmjCnbEUoQlX1NkcRADZvzln015HY -UHBICXJ5iQnRQ3RVTE7KT/KhMAwSrajLI3ErikhxqKzgcBGMYxgYtZ6NgO8hsG3A3nMKnS8kXfY2 -MMVB4A5yRJJORbsHxaHgvQovDhlZeG5S6SvEDg4Gq2p/YIQfSbrwOTnVJ0dno/wt2x44c8U7igrd -O33ZgXnPvfz7rdsfVI8pwyMDhsPsbNgAzo4SkD9hsrqewBgCOiuA4kbsmed/c+DQc1lZef39XZFI -ZOqUueee/e7CwtKKqlcbGvf39p3s7++KRjOLCqfffOMfnHcJu3vau3s61MWWFC8wzPlZVxPyM1mR -NHnyzGg0K6a8HLO5pWLa1Llgt2/HyUatjepOdR3fsfvxNavfS/Wpr9996MjL6iAAMGXybDQAgO42 -AoAwa8ayyqrX1Zt7/4GN68+5Li+v0LGfkZGhLdvu1+qEZkxf4oQCoUtOmzK3rb1WCQvJ1jo+15s/ -99za+j3Buh2t3nLpRZ9wXG/enNWHKzY5WUaGh8yj0ZC6DHKQYhcGqQnREAGu83ChxhC9E4sAjPCj -KDRRsdaUu1AuSiqFhAJaSpSXNxgHuPe2DPIcmAZHdG4ILER0atOwLkTnIyCG49DjIkCCYxAcqjGC -e8qMpZLTi9igaBAe7hkJpyeVS8tFy0v1F+tD+JcsCj9ayCHDiDU2H6L9jSvC1twAiBt44ODzWj48 -PDyINpoBbj2AYRVy337p4aV+YhCxgj4CIGza/LfdezeMjAz19XUiGvF4rLXt6BNP//Sef355x65H -WtuqzfSRkaH2jrrO7jbD1qSpSWmSyqTMzJwpRbOsOnHszWkyUj8GAkBk6hSNZe+9fZ2O/QDAlEll -WieaAcC2nQ/GjZhjQkYs/sTTP9Vqo8zM7PLytX5XAoSliy/WUqev/9TWnQ8aZtA2AAw4cPC5HuW7 -Q5Pmzj4b7SUGAAJXWrjgPPV7xACceXPDH+22d9SdPHXcccl5c7hHuzFjJCRESEKN3VdYhkRdA51I -QkwdwEKwQo0TScB1JSkOtQUbwdJHYtIqpk5DBA0dKvgUh5y7wj9CpncoNF14b0Vze6dE6DyMCMcg -PQ6Hjxwmd+MiuoszeH34Oxz+q1CuQ3xZhPobfLkca1q04Lz589aAMrW31xloOPUMDhRR9Xhrpfq8 -qkkjIwNcHdqYttrGnv1P6QSpiKULoAGR+SowAAAgAElEQVTG3v1Pi3hQCNjSfMQxieaWI+pCp02d -iwysOrGPknObjDYlIho4beo85eLAgnlrXEwDM6LZJdM0ZooAoLu7zXx7yNSn7URdV3ebFkL5vLWZ -GdmCaQrAgoJpZbNWaqG1d9SbVWHq09RyWKsTAivue32WmndJseoraVI3QQTEaVPmTlCYMqo6usXR -p2BiMffKhRNo5S4pDVkkrAndjYskBokkwE3QuOJkOLwsVyW5LLfmgNeBmjrBoTrQdM5lJGWJmp/N -5pI1Y3hLK9qYpghU4EkGX0EuP7Mj47fTN77w6+qarXL9vDQ03I+k7vhqtEQz3SV0ACMjg4Zh3fqh -r21isaHunnZ1NOu5LiIA9PV39vZpbDTffLxy0cIL7c8a2y+XTCtH+17eJbkNTJsyV/3R7u79T731 -4lto4y4oX3+87ai6emB3pP+/veuOk6pI/tVvZmdz3mWBZdldFiTnoCgKHIhihBPEiJ6int6p6Hl6 -d96Zvd/pRcMF9Tz1DOeZMSsIohJURDKSc2ZzntD1++PNe69e6Jl+OzPL4m195gOzPdXfqq6u6u7X -r4P63dV5RyoN6DcRbeWDcAIb0O8Hu/eskW+7QyE/ksd7t51Qamp216I+xFUcjon86ps3ZPRhTBkx -9Hyk543pQNqXstKR6zbMj4yzdduykcPO0zUpKx1ZWbVHw0Guq2pIkApVkz5O4WZVu11xJPagCZsy -eqBm9Lyi+7ba4UOpnUUnSsl1G1y8twSAZF9GVNFZmV1cYQIAIgYCLRHUdknGfVtud11pagDn/JCb -d6cD+5+OZGdD1E+Bm/H+6rXv19VX0ux9Kk5xu54tFpNmpOf1KhsToer79h7n9bo67slkq9aWBlf6 -jBx2PmPeyG7f0CD1bmb8uKt7lY2OHDKnnHT5kIFneiJeIbd77xp6m1hZz5F0Tj32UI139rjgtF9e -BZFpn1hK24YPO3aiE/WRf7Woktfji1p8ny8j1eVNfl6Pj4ef65w/rkg7nwcQISlJ9h5zlbKyuqoF -PHx0p/xdr8MGn92taz9Xli/IK5PXKhj0r1rzPo2Qgvxy+1L6yESluzrGAAAGDTyDWtWx0vv3/YE8 -oHpPluGH0ls9AMDnSx0+5LyoFpbcArbhu0UNjdWRobIyi6ZMmtuvz/gIOJyHtm3/Ss9SUjxE7yfQ -1ul2ftx+FHQmmcxt6J1EWRKdHksRXMhyS8x6Q7SzDrk5xa5gp0yam5SUGgFTnpK8yfShJC01V1Fc -XDNQWjJCtdWBA7IXqefl9pg04afEwlJ1kZaWm5rqYjHVkcodFsw+FafIZwcAqkOz9GY9APB4vEMH -nR21vz/lxMvle1mvN5nmzXBzTNCwweeQw+aEH39A6tTSw0e2zl/4mADNoF27v13/XZRrWPLyeup5 -vd6U4m4Dwz/ErSlIRN5EN0fx0UFBVBfbmsLMaQGonUToBtnWlrbd6CIcOfxYimAsDYqaVz7YVAqF -gjI65OWWyGMOHXxO/74TBfZxrWbfPuPD95wgIqKieM88/TYmfcNMKBRQJR44tElytrqqeu93mz9z -Wb+ALof8VdV7LfU7ZPC5Ho/s1Ep+Xmlaai6poJ7yK3AG9p+SkZ4v9rfwJy09f8zICyVnn5K8yRSk -Zw/Zkycy0vNHDZ+pdUKRVJK/+ScY9AtwjFDyeqMc1APAPEoSzV7acziE7yiyVr2bpsNZH7d55Zoa -Z57YMGX0j46paA9NyMlvlEWwHCZSl0AZHMW6Aonwft4tfixyZfAlA0Mnv79J37kTQaXcnGL52ec1 -695/54PfBoMBtOmvC5LXcOPmRbv2rKbKBAN++ZJWVu1Ry3XQzUvd2rqDhqqCULBXQX5+mQsRtfvV -G1R08KyMwmGDz5HJm5qSdcH5DzKm6GpkZBQOH3K+TF6vxzd6xEx7YDu63MhhP8zKjH5mXGZGwcjh -F2hRjBxx5PALRg532AlsIcbYmaf/PCUlUyYEJMf7AAAQCUf9sbCwjzfKrRI47717m1sb9Prt2WO4 -hg6Rw1AmhCMQzS7vfpFxKDmGZDvjKMABQ4gh885IYxU9ICfr2TldaEzYKY+pu6Rnw4GpMgi+Kx6w -6EYLTHloP0H1p7VI5crwiHTTa8Il+QOtluLYZXHE3BwX431Evnnr5ytXvWmvGkOWNIVCgb371ur2 -CQQCi794Un6dSVX1HuDob20+WiV7YBkA5OWWOq+xtXkL5cnP6ynfO4ZCwaNHd4IZc9TIWT5fWtS8 -zS1136x6i3NTmOzbL3W8z6gRM7Myu0iGjKL4fjD+xvR04THLKuVkF3s8KRQnGPRv2hJ9E9mJoy4p -6T5UMgQCftl2H9GhuTCFCaLCvN2K+kXGqak9sGPHCtRMVFhQEX7RhUaYU+VNDaKoeaHhQNt02sLQ -9tRsFsdWyLEJksWJF49LfRR93XV4bwKxIO0IHEa7VLxubiLJAYfWhLn/sfBo26kMcZH5Kabe3iGp -YCSGQxJvzmWk/iGjm+7lLgl5yFJGYmWjwvLctPsqHTy8GTla201NlkstDZDDR7a2+qXuWVWpqnoP -Rzx42N1F6nm5JRZ34twU2LYiAXIoyKtwVayDh7da6jfFlzV5ws2OZ65ZaNPmRUBqLRAKHKncETVX -YUHFyGEzOWfyIVNaMvJHlzw9aviFEWD37Fu9/KvnAbmOs237l1FP9agoH3viyIvlQ0B+ngcAHJoL -rcXQQ7W426CoMLv3fBNWkAMiK+s5SsW26OzoKs7Nhc3s3Gx2u57OHkc+Mm2uEMEmiz5buMAxN1Mo -aKb0j1fTXasv8i+oq0JR+0KHeWjc1WviIelWHJ2ZilD/Y+QnAkgvR0Yk67MF/CifTgurYaIbWXbd -Qm04JpAxztFuSTBbMjOzq9ebFAz65YErq3ZxRDAXRNUTXWrp86Xr16U2N7tbx1ldsw8RD7iZ5PF6 -kzMzujj0TqSCHMuVn1fq4sxIgKbGatRMpMvq3Wvc1NM9Hy54KPLppw2NlU1N9SmpmQCACNXVe6LK -TUvLnTr5F+E5ay0RwVTR4bKYC6soSaOGz1yz/l2/uMdtaW2kjnTk6PbIz2T9+06eNP5GBPVGHXEI -aMR5SH6NEKpHJUcLpW5dB0TdcrF77ypUt3EwAISK8pM3blqoNYxWnalXWNsiYtjw+nYzgz30rGqJ -wzP2dMMN5HTT7Wx80/OStAg4Srhy1ADQB/9qEjPMa+zw1d4jgJ4JtQdMTp6wbDhhw3MzlN4Bqy6i -/qe9agjjqH0UhMUBaBuWtR7Lnh7enc3D5UeMgw7GFyQGI/xB6QdhnfJzS5Hi6VWARiICMmC52T2i -wxGqqd0fCoZALzvTatLlPA8AFBX2BVVJhhkS082UVMseObotcnhTysvpwdSDhMJDB2f97eXyKsnd -igbI61ZU2Cc8H6h5tWruXmVjL5n5t1NPmlPWc1RqivCigsamKt0ramsPOvL4fOnqly6FvWec93B2 -dnejCG5CyedNGzVsZoRZLB4KUJx657X24ewjhv5w0oSb1IWkuksDOoWVls4QUuXPntIiwhaeplDq -2qVf1Cvq6huO1NQe0MOzZ4+RaWk5Xk9SG8JTG0eDnkbaCjSMQEMP0QyuCzXsg2BKN/jFoeecHglf -ryAw0tHsQjqPKGTM+OpmDbM/0T5H/R/1XwzfY0YnAQjGIJqBlm7GQSRuaz6IyjiDzJJO+TUlEMF0 -hVvkvLQ7jV0HUmCmFVjnb3VavJ+Skjls8PTlXz9vb/gYY927DQZuSODMAV/Vvbz0pCOV2y0IJcXD -QqHA/oMOM8tJ3pRgMKAwr9HJg2EEeSruNrhLQR/k4cFCTlZxWmp2U7PsuRHpaXnAWZeCPpu3fW63 -gCOVlZ6I5InMrn+E9BMqxu87sE5GUFHhCd2KBiF5+AP9ADmAnMzuQ4dMGzrk/JWr31j65bOOgIFA -K9f8yXEsnJnR5aILHt27b3VKclZxt8GMMTVuDZXlQwlgxNCZGRmFiz5/3HG+hSPnBMeRJzur68Rx -PwXGehQPBmRoDu0o4cCUE/pMXL12nh3WTjlZ3RAZABOGLQME9HiTS0tG7tgVZX97S2tDlqaPhyWd -PPqK/Pxyruup80ULzzAXGfRwWvXRXAvA2VUi4NB+WhTanJwTaQ55gWCSHIv+nhMqJuSowxALkbFn -fNITAZ5QhV2m+7ypBw9vam6uSU/P9yalcB4qKuwzZeLtfXqdWpBXzpEHg62AGOJBAPAlpZ056Zfd -uvSXEgFQVNj30JFNdfXGuLKwoGLq5DtLS0YdrdzR1FSFxusFlpvdY+yYK7oU9HHEVAdZ+w5Yz8HP -zekxZsQlHsVbW38AEZOSUkqKh00+7ZbwoBXVMFO8Xt+uPd+oWXxJqbk5JUMGnnvSqNmMsUCgxR9o -1jXJye4+ZOA5+XnlOdnFBw5t8HiStEcrnpSUMqj/1PHjbjhaub2xqVLVKsmb0qN42ISTb2CK2dH1 -Dx2fOKUX5JdX1+xpaa1D4OrEC2NsQL8zepePq67Zw0OBtNScgvzyspJRp0+4NSkpJRo+K8zvXVWz -u77hiGUax5eUOmbEJV7t1sCDhzbu2G26+KUgv9fUSb/IzOiSl9MzK1NwrrJLT8vPLetdPo7zYFWN -dVqpIK+8d/k4nX/n7q8qq3ZSbfv2mXTSqMu6dx2UlVkE+uMUxY+mTEFumeLx+v2NzS21AMCY0q2o -/6TTbqooP8Xr9VXX7AGA9LTcirKTx46+wutJlsEsKjyhpnZfY1OlXpwuBX2GDDy3snpXMNiiKJ7S -ktHDB0+nFVOQ3ys9Na+NYdvOLUMHxmRnnX5Xac/RABDuoE1cOsUlPaHgFoqbLPKH6JIUmsxtU5ZM -+5fbpiEteLYpyTAOI39iIOCvrduXnJyZmVGo/xoM+Zuba1OSM5tbalOSM32+VFBn8JxxHPVUSQHg -Ic5bW+tTU7LIOn2LbmDGVHRMRN7qbwwG/R6PNzUlm2TkdhwOij7rRHYEKNHsEDk9/G+Ic7+/wePx -+YzdT3adZfCRc15Zvevwkc2V1bvqGw57FG+/PpPLeo7WckFN3f4P5j8AgCkpWXm5paU9RpX0GOEx -3g/H19uxpbVh09aFlVU7a+sO1tUfzEgvOG3sjwsLeus8h45sWrzk7z5fWn5eeZeCPr1KxyYl+QiU -q/B0oIbGypTkDK/XwDSHSWRBEcioiKbmWq8nyedLC7dMzjii8JRsImJxs6jpMrJi0SemvOys0+8q -KxktME0ndVInUXJsJS0/Of4aqzwn0MgSI6jaSf/r5EVtOU+nd3RSJ0lT5NGrzNg2viIjTwd0UieZ -yKtOuGrP4S6vn+ikOFNCxoyd9H2hTvf436T417sXOGAIwgN+5mqtR3SiCxWACSfI205m/LbbJF44 -ZnI7u2kmQQ66CpNMiscmKzp+TJQATNfljUEHk6xEuEpbMLWJWntSW+Wari91C3VcyI3RXPEKvZjC -IQYLEbne8JLhiOS2YDo/Wl6GutFZNh8j/2t8rpQM8zvJa4Pulpe8bSahaMEPbt3BBCNyRALaZh8A -OR+QfBOnk2vb0rd+Lu1m5YlTcUz8tO2TyGAKMQn8qHJRTm5kZUDeN46FXCubRPsr48auQ6+tdS0p -S6bp8Kor/AGYtkmA2XO6LZjR/DL6KhmsuwAjKuq2nUUqF1TrRpIbAT+WoIqp/XWJE4tDaD6v20r/ -AW28seDLUkLa+jjhuO2TJNzGHBrhkVekcX6MIRl3HIghTATMkcLWTRNhxWEER1h9xCcSHYYdIZS8 -yBmGmNkR4/e0hfY6csCORZwwb1i0234kVn3cUkLK7pbfYdTRFr0SYbd4YSbazu7nWKRCo+34CcaJ -LxQBdQ7btppXb82iALRnGHYETHq/rqMs21JQmfmUKD2gDsIAzJt6nUHMB1hQrZwFidaxyvEzwt/G -Arphi9tTnDw/o39YU9zyx6KnWx5KbnWLxW4mcXEJBxsOzS/DH0WuxZPJnnWRiu5CMpY6dRtuxyo8 -bY7EbClRRbhVycqvP/c4aRVDdXjDx1BYWQgvfUJClFI6ihLaGRmRRzpo/6YHBvH4SM8PbeKPECFu -n2xlKkPmKS7O/PZ4Jilu+UVljFfZZQZqJucWZHDbRjjzW1xLEA7RJ1PQQJDldyXXEmLR/Nl1SIqh -ooeGXmQt3KJMcrvll27ro7ifrWp4NLltlyXij1h9MYSYVz1NyDW6aLwScRzjABU1o23I7g7nGMoV -ATriHKf8krXfZlny3uVYNTHmbbNiEUrqiK+3aJL8cZPrxB8ZXMTjFqfjhHCEjG75ZVwrAo6omCZZ -Tl2+exwvIJgOZzL/r0FQGGbCRTNPGFo7DIlTVgpqA0eNh+ptVACSjstphIZWxUwaY3R+U0EY0Yfb -8lId0MhkLgAAgulQKFNNiKBopTJndksRHPEdt69b8AWHQDEpfaLpIJblTje36dQM6pOqY9Wb6kVc -F3omq7fYzILmeLNGnSh8nMwrCDck/zGqDyM4HJyjzKoIWsul/mE0HIwuVxWFj8ntrXYnvuHgotTo -2qICe1PgoLlVB1ooMqXPmHPTYYGNHkqmmiDTBkhcyHwWW7SQoekWb3GyCoSPaNVlyejvjENna7wc -9KPOGQUSu4+9BmhR1II7FF00Q2QuhzmjYyMuUAAEeW1sAlmU2UlCJD0JmZ8FhWyOPObkaHaOoAZG -55FJl9PHpZ4C3SjZDz93kiDAJ+k03kVypcouKiZGUJXCusOJ5NVGklNsRPZqJ9LlmhpxszKOeS0F -F/wh5RsoSCf6OAsSGZ8uTbfFXdvdmIY25RdN4TCJkBERXVtvdmmX4SzA8aJheBOH89nLYPY3Fp1f -eNCr/jVO6ZYOzzE9Fn5ZfchDn7F+DE0PgzRdxO+cDkJZXAJTpEMsuonkuk3vuPrIuTdNp2QJGccz -liOky+gQC78xfExwiCUi5NuiZwdwY+d0SonRjaZ71esRNLMwTa65A8E4pFtOl0Yb8/cjHTA8A8eQ -IaD6axzTmTbDx4BxDJ99iIhMuzupMz2+6RAOVVLL0dIhwaGUmPQOF0qJSE9ESB6Poe1FBNQO5UXQ -prbNXRNqnSntmUxtOjUzC+eg3RqYvY2iWIQyNPhpBjIuMT+faHkNoXYJhJ8RfsuYzoofUU9AUbl0 -7RC1fFrBtHRiUiT8QPiR8NMqcMCnchEwPPeosWlbggz8iPxA+FFeHxkcUsyYyuvWnhHlinB0uUBd -XRwaFooaGswUGnYvMuNYt3kZcp1D0r2eBpRWlTqIKCQJhFRoiEJYFJIOSkYMeUl8WVfROKO6tNvQ -a7MrOodSm/TUzmkw/2T908jiTOj4h/2LiIhQFPALMUQKi9gF/FF1lJQlNJH9h8giBfzuqkCcIuJH -h5+l9ZHBEZHb8rq1p0ucKP7m+CUiuyWLW/ugQG689LT+LhGSDpljCY02NRf0iyy+jAgnTlGVuQ09 -oSi3riiQIqOn15Bn7WYpG3NIR3Doah3yOoJQFvMMXBQQACQHvDFyI1wHkWWqASbgEojj9PYR4eui -+MiSKb4MT3vqfKzsYw2FuIcG4XMry4Qt464CWQkPDXNBnIuV6JCPoBKhWNxMhidurijjG855vci1 -Y7kYiA0ULd2qsIAHye/UyZzLK1LAXGAUszliRpVl1dOtLAEPSvC4lUVv2BScpxbJjFFxTER4TAda -/Q/YhxJt060U79BwKws6cmiIGVCCJ/7lgoS4tPCstxjcXnhsokvfIBQ+fz8qX3xIpo9sMwn7FfeU -UD0p0SdQZhMdleKlp1ucdrMPpTbYqj31jNH92tPl/hf0JDCUrI8Wju7UnqF0jDC9qK3fd94RICbR -ei0ziedABKniO37diDYPlBxeXkUkt0WTw4/2IIauccT8Mjak3O4eWt3KdV+/0fitA+H28itJfolQ -ipssKZuD81/mAV/7quSm+jACv7vio8CdEh3yZv54uW7bcYz1+yj3SOPo3WIfcd6UEREf7Zi2vM4V -bE5Ex7xifiorCn6EX0T4jLxGQeGMnUMqalm0vM7VhE5/2fI61wJK8cvoKSqjgywLiEiuaKFLm8sY -Ua6MSzvoYON3Xooml1fk+UJZUfPK8Eu7vTOUyP3symg/uRu4ipsFmf7JWTdXVY8AjBH3RpF5xZKN -1Hi5bvRwE+EY8zxMxoTmDsbZQIRH9oILwRBEaFlBPyd0ejdPMpL8omKKeMjYQowqHIoJ8krYgTxO -iKPNSW4EPaNWcaL0dOKHCDpH8ysgZXFrH4gQaTGEiQXHsWUVtqcSci34JkyxGgabqPhxCmEQJDNx -KMWup2xImu6siG7eqPrTr2qzE7XjjSVkqMup63kQABBjulxXYqDRdkyJ0VMkfRwBJJxcVrhMMVHw -3eUzllS6m25OVq5IT7f4IsxE6ynil8RJhHtT8DZ4uKMObqtMYpAoZHbr9q6Y2yBLBlbG/dy6UKJD -2C2mDL+Xc+Dcnv49pni5UCd1Uid10nFJXgDnXXid1Emd1Emd9L0kct9WQp5vOqmTOgh1um6HokTP -rHRSJPIiBwxpr6jB/G4Yze+bKaH2NsrCI5nXkVmGJ5a8xwTfkgKC9M6Udk1BCR6SKBUOxzkP/UJ5 -IJHhRn92gYNx06cNKXCM8sY1RVvHidovqHMwoq7T22IRj0xeoPerkFqX4oklbzvjC+LPnm7N3snT -cXhiC4fjhicRodTBedrkHscqb1x51HsWEUBdaaT1DkgsxcB8aQtNN8uwE4LpZHEnFtMp2q55CLdQ -N5c8segGos3ZzHQXksLMDNqfpg3ZnTwdhkfk6jLhcNzwJCCUOhoPxNE9SLpikxKF59i7txcwzIcM -TAuJaUFou+aYHsHhGOHh0XgkMR1674TJikU34cEazuqbcEKCvPGShRI8sciKF49In/a0TwRKqHvH -i+d41DnRZYeOEWLHKEzI+TxoukPCBIMk3bkjJfwouJOWkSwI4i2NSP6n/blTOrOpavCYVbKnO/XQ -mm4CnFjKwjUzMjB2+yEAc0q34HCCw8zVofPS6uMCm+iXMpv5TReGYHR+k024G3x1w71jebnAbq7L -S3hFtuWUy9CficpLDyq31C9NTyh/hPA0ksXXUEcNW+vdvDRMBFUj3JfoFLZUtDmsEKlyTvyma7pJ -Og1/kT4WuaIqFoQYEjuwmFxOQjfu5AZtwJEooxdRv1/X4QgAppWcqYBALeFQcgd+nU+rbKPFA109 -0UpSjR8F/Ghhpr0/kLxI8oJTXpoNCT+5n5nyiDAJrsUCptubtH8ZqPfghKUyU5gIzKvzW8uCBqbJ -yE6QYn5nFWTxza4RGd/K41Quwm7CQWDAaW8VxVZW2xIeItfwbVt5iQLmRovggOjWIsdwcIMvw++U -TqvG6GSIzpYvVgtJurqJHwg/Un6p8AQbfqTmwmiTzXIj6Cnj0toFhAzAuPAGASDKCZZtCWfq9uik -KJr+ss0/RsJhqm1RSycw2n1bAuWcKsMhhfoU1dPBjchPEcDl+QXdH8ZJlsNwRVIfjBMP2BgciyDi -iQumJZE6kPh4ciM2E28rh/CSsYO8XDugDE8EI0uGTJtlUUKSLMIRZ5SsbpNK0dxPeNVK28KtTU1E -dDdAoqqFYguNKHJldAYAy5lFjtUnwqfnMJswBW2EIw9i+MhqteD6cf4mULRqRhlMBSBy284Tb1kI -AAiKWkYGAMC18QotJdA+22zDY8ND20Tz+SIK4TGqzOyskXEi8zi7Lk1NPI+zrcyBFJ0HTMerONx8 -FYHHrCojeU25HXnAPEpHR3Z3oSrESVAYyvG0PYTd8zjoA4KhA5jdgwta4PYMMdG5nm7d2wsI2mON -yT4CY4l49NDTxxbOdW/PLWaQ4mESFRwfWUaVoW2aSdQeOeA7S00Yjrg45ClPUHSxI8rIcqenDI97 -m0SscGkeEAz6JHnQ8auAx9IAuQzDtvNYGCKMKwUUC097NgUOmBFgox4Ha8lr7myjh5iMDqI+KRb3 -Ns5hjpXiAtKRxbp1pfaQllgBx6hKhdTR9EkEdZAydhA1XFFH0Fmms40JM07kRXC8b0s0vyQiSX65 -aauYRMQlbyL0OV7KmAgd4iXreKmX41GHBKkRS97j0YzHhw7kfl0Tua1RSX6JR+E2iVB/U1+q6K96 -mPV3eZLVx1EumA3vFlOG7FL0dSPSFEtdxAsz1noR2QFoOjpzmn52KfdY8CdaB4jg0sxIt24ATYhK -jrMiEYRJ8Ov621IkVJFpwM2qRMU0SY+Di0bUAa1fvYjIHdeiHoeE5F9ok+PHRW67iY40Wfi/RPK9 -SiIew7+XJAql9g4x2rdItqgR+eMcMjGX/1i5qDretw4VkZHjFZCuMCCbccjQijGzubV0K46+6YCR -S+vpCwZGVkVYcPSX9Uhe4AjSwayPCF9KrpMdxPYBTpZ1KGQCjZPNcopgAx598GJ0Yx5JN+GEyGID -jyFLEfG7lSuBL4NjSif2Me0Xi8UOMuV1K9dyQ5LhrcbONqYtjlb/MEKDuJBsaLjBQXI0CGMowS/Q -hzOTPlpI0lC1pjvpKRtipO0AGsIR7MBc4jArDsWHGF1CxlUkQt51SEro6baJUNfzAAAgrTBuclBS -wWgoRPiRCxyamypSjxJEgKBeKuqIZOuPFQcJDpUrSneHL6e/gUMdixNHV/S9l4zMvCCwkPEgFyLp -CkkHks5JOhPioCMOlQuCdBTg03QugS+HQ8pL7CNTXiGOy/ICkSvCMelD99Ca2jJjmQateourGE0T -F7SJAheSw0G3oRcVBxCYFpLIgGuZGUmPOcSc2npBiEXEd4ED5nRT6MXLFQU4Ild03RQQfPehgY76 -0PX7xM/pwISkG9oAMLLhi/YNDIEGhnB1cTR8IDhgblsdDxUhfX+s+M7pAnwL0QpgYGxmQEG68/Z4 -lUcTYX3/EhkHSR7qQNREseE7l0uMT0nGPuCYDuRXNFW3VU5kHPf2jxACzq4ucFFRyJjKQMa2zuWK -LfRkQjvG0HOsdwSTfVyFWIwhbOs/QWYAACAASURBVD2F4Fi4kLsQixeOuCnwcgzfs8jo+B3JoRkM -GKkBPd1SEzqPKZ1THApJeZiz9RmSQRAjnTZ5sCV5TVmJLNMAh4y3KI9FB8Ju0tlQG5ljcDIAJP0x -KuEt06ry2oZp9YgBizMCA0TFOBmEXOLMmHZCB+WRwtFcJ4zDDRyu46i/asM7xsMlYICcnlSi6DjE -RGjiN+mvmwrpjheVwa6DSDeaLrItAx4+hQQ1trAJlfBflMekGyAo4RM0zGMsZ9vqFtZKT9o+0l4z -OhlExHEGemPGuIkHCA/SsbapP2AOOLR9NDWu1I1JeNLQpoUiYWV2b/J4YG0i9PLSFsIZ0zI3RcIz -egibph9opYibCAE+ou4SwJC4hMGhukQ4j9m9STigoiNGd1Eahgyiu6I1DI1wZqCli12d7mM0NLLg -G/dtIZ2ZNqlkqRenWhKlCn4xd+DirAZHpAN8XCmDzjwyOkTXGS2/aS/MzemIZi6DhzsW0+A388QL -R8xjmq104JbDdFeWSOnOtkX9X7CYQ8ADzjw0u7NtHUQIGKLuqZHmiSJZhseW6owjA+L4gyg8RZhx -b08i6GDld+MScuEQ3UUterqWS8KBShC4Ov3J/BfBp+fzxGf/Vid1Uid1Uid1ZDLW8wAACB5sO6mT -OqmTOul7Q15Q79cNU+eIv5M6qZM66XtOXs6RhxDAvFhKihxfw8sSzdCRnzI6tp4xVcH/FMVWj/Gx -c8f2JQsde9eSM9ex1/N4IWodr/a2hiG62uqP5Iv+YrkNzqy+uzC/CW8rjvWNeryDq4O5FX1pwxJR -XrMs1l6yYiEpPV3WY7xcPRYdEkH2SKHm6gAKEor2mrc9wt8sNC7hkIiwksL0Yngdp+lqQWkBoi9u -yfIm/JjjHC9kKWlCy9uesmKhROgZR1fvUPQ9K1d7hn+83Kwd3NUB04sc1fe6SPbuCXclmcBNC2mj -80iy2XnUBxLUVn4z0xL+mFSS59ENqHefdFpMBrN99DxOeVD7gLZqmdl4TCDm+4qVRPqD7ntIfM8u -Ll72SQSmpFx5qPCP6BwOkSlyKMWimwx/R66CRPOQdC8GtD3Z+kF7TN8ZAExlVsI3TjOu7cHRGMKk -aPt6WJhHE4Rh5wAAhRnVrPHoexyYekGkAkzRcNVbhrW8xq6MkO0AUdR1QFBfVHBArj/tINNPEVSY -aggGGo92MaWil0dB9Gg6cxa+kJ5pZVTF8fBeEsY0/TV7MQ+qezwAAUKM8Og1AYqinSWEpv3oRh/D -yAc1WWDD8XADJ0TaJoXmta4VtuMwFYfoHM6uGNyM4Bin0jAAxsKCNFn28jIFdD0BybVFyMKFZoC6 -zhwU5LrXOG4yAgbg4UZ1BJjVPqorqnYOq4cCuajbSj2uw2Qt1OpU61owpHU5Fr2U8G1sDAB5eO+M -vj8njKniqJhB445sVIj/6eGj9jFOYaiQMDTp6wEdH0Jg3mgb/ofpbqzWOF3Lh1pejccWJsj0HV0K -rXdtf6yl6k3l0i6zZQBK+Ipy1PKioz09mttzhiFkYA9VQK3ZAdLshJsCu1wwnZmhKJoR9DC06KC6 -mV6FIQk3kw9VB7KmqkMgpGFIQsPog7VQVW8DRxKq4XxIysIAELzAAezrebRGJ9wWaNu80EAibGgc -tqPzhJta2kCHSKms+HpbrxVSs6Ce1xT+Oj41lH66CIQNodcEPZDEWS4DrpCyBGwGAQjfq6j7um5Q -ANK4AAapidCA0CuPAyfmom0rqQizaIX8zQ1+Ts1LN4lQHNvhTXZ9kOoDaJTRclCUrqcJ0+qsUfBp -eTmxD9GZW/Dtcs0up/b3VvuYFqo56GzI1Ucf9oOutDGEueqNZtQUAqi5FrED6t0nAgSI5zDNG/W8 -drKEiYZtMrkAP9xtKFoc6XK5Oa9RLqI3t8glhdb5aThr/YUeesJyhUdgtD82tcUmewZ0M5L6soSq -KK/FRDoEOQ7SFIaUIriZPnwhZkTiQq5DVXC2moGj6uDsolpoaG24NfTQXN1ET0+OMioZuoR7S+3D -dFOpvUdI8x41mx4AIYCg6cgOpvaKAYCAKsZUwYYIAAZMT8QQGq28zqnzE7nqLmTwszA+QHhPNpr5 -HXG4pqX+U2S54cjXOhwOLIB6eY0AoHbQVQ0bmpEiaI8vFj110VQuAmPGWBFDtirQK1L9cG3cDVp7 -quEzvXRc64ntcqmeemAAsKCBb3K4INPTjb34KIdP7MBCmssiINXfZXlZUKsXbmu7DVNrLs1N9jHh -O5YLADmDoFbF4TM3VCgjnZwMq9khimsZIcb08nJiBwDgCEGtvAAmuSHtmC3dnuaQCdc7J/Wiy9Xw -WQiNcllcOsiM0GYYJeQ5QIDwq+NEWwjTM+lQxQlBdm7KJdcPueDKgYf2Nx7e1whBDBcNTKEnFaok -tFkQS8qy73pswuIPdgaDxrN/lJCxuUq4atSWUDeCOGQMcMlQJa7OdG9U22szTk5+yoNPTP7mswNN -tQEIwZ1/PK2lJbhvV51WlYapZfT0YitgK1hItIM8NT0pKzf50N4Gx19BdZ0kBK/2MNZijIPAC5Ck -OVYrYEDuZlM7vhcgSbvh3K+NcSg+J+lOGG5lAoTxkejvLFf9SfVCD4IPQD37NMSgGemxxhJSo+mp -ACRr44UQQBOG5erpCBACbCVRGrmMkqkKQDLqcrEJrHJVfVppOhI9DX3M+G0vL5rSBfro/JEIHb7p -Lq1WfTNxaZKOLeJhu7ws+192UuXqIdASnuYCBpAEYX04YECkDwLAj24fMezkrnOnv++wR9+C38oK -C9OnzOhdMSC3sDidI869+H3kAH7oWZZz4/0n3nvdooYWPw3J6381Zu/22nf+vUnFu+nBkzavrfzw -5S12UXldUl9ZOmv1sgNLPtxdtaMJ6y0sEU1ha1IggHpIYhKkZfsmnVdx548+wTpXDh7uW7qXZs65 -c9T//fyzQJADGK515W3DR5zWraHBjwDh84m1gTJT4B/3rdi9pSaS2uJyRa54X6Z30rkVf/zFUrVl -GPuDkjVLDmEtAJhCoN/Aghc/m3HFuDfWfX04Quh5wTTxGYVOO6f0qjtGzBr5X+GRDmpb7HdKD9D5 -k7aSCCde+HGUGwJopkNfcNUqRCcO0Owm/VjJjZc+x0puBJd2TE80OchFV/qkZSRd/YsRmTnJoycW -f7lwbwR8X7LnricmnHt5v43fHlmxeN+uT2uOHmziDWE3zs71TZnZ+8GffIoBpCEwanz31HQvaIeA -jflBcSjE9T8pXXzj4N1ba26b9VFbrn4yh155v9wXl804Je8p1NJ5IwcA3sqd7pGNCg3Mw06/oKKp -PvCH277QAU6e0vP6e0b/5/G1VUeaVdif/f6Uec9u3Lq+ijHGGDQ1+C3N6UtfznzqwRWL3t7huoBm -4pwDAG/i2IgAwEPIQ9pEPnH1A1vrH/zJ4r07ahEQOFxzy6ievbPvuvoTiw28KDO01Eh9HBcfgWSl -JJ8nPTOpprLF/lNyiqe1RZ9/pQNhB+y0jCR/aygYMA3YFA9LTvE2Nzo0umZwAGDpmb6W5mAoyO34 -NmYAgIwsX0Nd5BgydM7K9dVV2x6aAAAgJc0bCmLAb8JnjFowStnbhRKhgwizPcvbEXRwSwnX+Ydz -BmxdX1lT2TL7Z8O+XLRHFMxZucmPvHF299LMGSNe3rL2KIA17EMcASDE9W4nTJwj58Z5naEQhkLc -cmSfx6ukZST1HpS/afXR9OwkRGis96sbSBUPqxiQBwA7vqumIZ+R5WtpDqopuYWp1UeMXj051ZuZ -40vP9GXk+BCBh7Cx3q+qxzkHhj175wQDfN/OOqoDY1DWNzc1zbttQ5W9BdizvfaXl89//O1zvvli -/ydvbgOAbj0zf/fC6Q/f+sVrT63T3zfO/b+xn7y1/dN3HJp1tYwZWb70bF9Gjg8AGuv8eg/XpTij -a4+M7Rur7O1MeqavYkDe4f0NB/cYMyshztV/wye7aUZWf83MSa6vaQWAmqrmj17b2ljnR8CMbF96 -VlJGdtgs/paQXky13TfRP+dPW/zujucfWa3+Oeq04l/85dRLT3510rSKYSd3zcpNOfOiEwChpTm4 -cN52e2l1euiFKWfM7F19tCU1zfuHny957Z/ru5ZkvPrNRdOHvHTfU5NOOaPnko9333f9ooN7GgCw -sFv6TQ+cNO7M0qzc5ObGwN3XLPzkre0AcMKQgnufnFjeLw8QD+yunzNlXuWhJkVhv3zktCkzeqdl -JH367o7fXPVJS3Pwkp8OGTym6PV/brjniYlFPTJefGz1I3cuQ4SKAXm/fXZyeb9cj0d589mNv//Z -560tIREzAJx10Qk33D2moFv6kf0Nt1744ZZ1lYLyIQBMu7L/zx46JTnV09wYfOiWz99/eTMAFBVn -vPbtRReO+u89T0wceWp3X7LntK5Pq53fZTcNPefSvicMKfC3BL9ctHfuBe+7H4wkghKhQ4RHwnaj -jqCDW0qszh6vcvncYf9382c1lS3PLf5hrwF5W9dXOXLecM+JXUsyLj/19UP7nOd11SaMo3XFmHp1 -q96wcI4h20Gtg0Z3+d3zUwq7pQf8ofHnlAHALTM/2LDyyGlnld3z5MS66laPh2XmJN81Z+Fn7+9U -s7y68qInf7siyafMvmX41nWVc2cYk1RX3zFyxjUDFQ97ZcUsANi9tfbaM+epkXX2pX1n3zK8sFta -Zk7ygje23XrhB2qu/sMLf//SGUxhisKSUz23zvxg1bKDlgIufn/n3+776v6nJ323+uihvQ1/+O+Z -89/Y9upT69TzizUjQCjkHMP9RxT+/qUzupdl/ezhU35yzxgA+PFZ7+zYVN2tZ+aDz0zu1T/34J6G -igF5Lzy6+vG7vwwFuVo7P7lnzKU3Dt3xXXVxWdbW9ZW/vGK+2vpzrXcNTx0g6A8yXUsynlt8wV1z -Pvly4d6iHhnzd145tc/ze7fXPvnR+b3653k0s7z42Jp//2WVqpsXbfM8rz617lePjH/lqXUtTUEA -mHX9oAVvbmMedtLkHj16ZadnJo2dXAIANVUtn7y9DbXZbwudNKnk5Ck9x3d/uraqJTsvJcnnQUDF -w3ILUh976+w3n93427mLH3397PNm93viwa99yZ6/vD516/qq8we/2NQQeHPVxV6fgoB5halPz5/2 -/KOrLjv1NUVhQ07s2tjgR8BbfnfK4DFFM0b+JxTCfy2YPuPagc8/sio51TP0pK69+uXe8+OF3iTl -qY+mvfnshv276v/69jmffbBzzhlvdS/NeviFKdf9evSjv1nmyLxzc82Icd3veXLi9ee8s2rZgdse -HnfXPyZefuqroqP2R4zrftffJ95x+UefzNt+5sw+v31u8vbN1RtXHgYF1GK+8Oiqn1384fKq64AB -B7zox4Nn3zLs1lkfrF9x+Ipbh592Vpn8k5MrEo0SE0HtKSsWktGzI5QlETpQzLNn9W5tCS56Zzvn -uParQ1fcOvw3cxY4euGEc8vffGbDwX31Ilh1BMrR2oBwjpxz3bcxfLWTiefbZQfO7PPcY2+es3lt -5WN3L1c5+gzK/8vrZ/1i9scfv7YFAKZdOeDPr06dPuylXVtqEAARf/3XCV8v3vuH279Y8tEu2pX8 -9d7lXy7a8/T86Wf2+Xf4VHkMT2OMmdjjtos/2LKuctDoopeXz6oYmLdlXWVaRtLj887+50Pf/Odv -axhj19815v5/TZ425EXLjAIA/P3+L4ecWPTH/5658dvDAPB/cxdz2uoDIKI+BrfQmq8OntnnucX7 -59z/k0UL3tymauXxsEfeOGvbhqprz5oX8IdKemW/tGRm9dHm5/78LQDM+cWIsy/pO33oS/t31fmS -PQ+/eObvXzpj9vjXOUeOJmtrE8dY2C396QXT3//Ppi8X7UGAUIgzxkKhEAJePPaVXz4yPic/5Y7L -P7bUgILAOXAOyLUvH722pa6mdcY1AxEwtyh1wjnlr/5zXWOj/9fXLPjvE2v3767/9TULfj1n/u9v -/1zt1FH7cO1fDthQ15qTn3LZTUNzC1OrKpsPH2hAbeX2Oy9t+s8/1uzeVvPBq1smnFuODCdN7zVg -RJeHf/55TVVzqz8UCHD17fq0H/WvOtL0xG+/CgRCLa3Brz/b29joBwVmXjPwjWc3+FI8qenerz/b -N3ZyiXpRRF6X1Ntnf/TV4r1LF+zetObohHPLTzq9pLg86+/3f1VT3bJx1eG3nts489pBqkfmdUm9 -Y/ZHXy7eu3TB7s1rjo4/txwBp/+o/1ef7j20r76oJGPpgt3DT+6WlOrhpIy0vDPmDFy17MDHr28J -BELvvvTdd6uPXnD1AGBhA7/29PrXn93Q0OB/8fHVLS0BYHjzA2P//ZdvV391MMR5c1MAwu/tHawn -SqefCHn1FTMogdmesiQx201PS14LT9sUs+vjqlB2N4tdFsW86rYRz/5pZZBzBHz2zyvPvqRvftc0 -e8YeFVnFZVnLF+2xpF9289D+Iwp1ftWHLUqqt4QYioXFW5UMobqoGjlytWO4/jdjFr+348PXNocQ -Q4ivP7P+my/2z7ljpBpToRD+7tbPrpn61ifztjW3BKncECIHDIUwhJwjclTTAQB+dfX8TWuPhhDX -fHXwwO76QWOKEPCcS/t6vMrGVUcGnVg0cEyX1csPlPbOLu+X66jkHbM/yslP+cF5vebOfK+5JWhx -FbX5FVk+hMgYBIJcLREHnDS9orRPzoM3f+pvDXLE3dtqHvnNsuvvGsMU8CYr19055s+/WrJnZy1H -bG4J3nPDwkGji8ZOKUHQV4uFZQEAB8ztkvr0/GnvvPjdn3+9VO0SAiEOAMEQ54AckTHgPPwARn1G -n+cxOrAgx6ce+nruAyf/94m1M64e+Ol7Ow4fbMDw7J7alxoTS5ZuTrfE6q8PXn/e2zf8esy1vxz9 -1r83PnrX0sP7G9VMLz+xxpwbB48pWr5wT11tC4aXYoG6KKlHr+xtG6vUKtQXYhWXZWVkJ0+9sM+k -ab0AQGFsx+ZqVfLXi/dt31SFRJni0sy9O+qOHmlUFVv15YHcgtTkNK/KvG1Tlan2APsNLUxJ8/7m -bxMBgDG2dMHuzGxfS1MAzaWDsCaZ3y49gIBh8OUHSnplaw4Brz+zDgGDwdADNy9ChPITcrPzUhbM -2waA2kuGcP3pmJxozpzSgYwB0aZPfNOpYiJ93KYnQv9Y9JTXB2w/idLt+ugpPN7pdv0j63nK6T37 -Di2cPXf4RdcPAQCvV0lO8Vzy0yF/+fVSRIMfAI4cakTE8n65K77YR9Ovum1kU2Ng3cpDhmyGeggY -2rJwDiQdg6hqQGuj+w0tePGvq/WBPANY8fneSedXhPER62pauDazbg1JBshRh0LQdhdqW9sQoLHe -j4gcsGJgnr81dMUtw3UrLZi33ZPEuNl4KnhVZfP8N7f2rMjWH32oqzD1ZjajsFb7M4XRx50ThhZs -WnO0rqZFr8qvPtubmZ3crSwzPSPJl+z5avFetYkAgKOHGrd/V9V3SMHnH+4MLy7VisMY5BWmPrNg -+sJ3tv/t/uXkvThC+CUwIgAw4NzoBXXyghPNe+G7n9590oxrBl147aDbZ3+kZ2ppCfmSPfalz5bS -qumfvrdj8fs7+g/vcvvDp/7p5bMuG/+qxaCTp1WsXHoAAZJTvM1NQTV9wIgupX1y1HvhNq89+tO7 -T1I8SjBolGvf7vqmBv+f7lyyatkBw9XMxerRK7vf0ML7b/o0Jy+luDQzKzeltqoFAAaM6FJX3dKk -teMqlWjMHGDL+sqayuaHbvsctV5OR7a8VkOAA3sbBozsokMNGlm0ae1RfTGxRTdfqhcRm5qCHMDr -YVN+2Fv91TGGO9M7VDpEc/XjJX3O7aNe+tvq159Zr6efcUGfS64f+sT/fd3YYAQFA2hqCGzbWHXa -1LJXn17HSQjwEFdnohGgsTEAAOnZybVkUQMCpGf6GhoCIXJ2BmMmfQw7M2DMWJcf8IcUD9NxEIAj -BAKmtT7OOGrzal43z9Tl/8yoSvWFMwDUVrUc3t9404XvIelj9Ei3u4SKxJ1EM8aA0dt8DeKk7DoF -/CGmMNqEqnKDAd7q5wDAPIzTekQIBLjBTwQ0NwcP7W+cPK3imT9/W3W4iQgB1FRSFCMDLZeCxhOZ -sQciEORPPrzitt+Na6jzf/35Pj19y/rKnhXZRd0zGEBxaZbH51HTy/rm/u6ZKSXlWUwTMO7MsqKS -zBDiupWH3np+Q2ZOMtc6MXVnynmX9i3plf3CX1dxxIXv7Rgzvri4V/awk7o98NTkuurW7NxkBFj4 -7g5FYXNuH6V4GAIUl2f5UryBIH/vv5tvvGesN9mLCKW9c8ZPLQ8PJRhwgOQ07833jV32ye5Vyw4s -XbD76KGmK28d7k1WupVlnndZvzee24Bm5ps0Zgbw3subzrusf1m/3BBCenbyWbP6+nweBsAAmMLu -fGTC5Om9ueZ8b/5746hTi0ee1oMDjj295+DRRW89v4GTZxlq0k2rjxzc2/DDKwfkFaTe849JXUsy -1LksRj7mx3Zj+EBxROkiHHN6dBxzenQcMT6dqTge9acfU73o/GDmd0yXVjUKTuz4A0Z2GTmu+98e -/Gr9N4fVz7pvDj/x0AqPl82YMwgIvsr/u9s+nzyt4sZ7xgLZ6ci5selt17Zaf2tw5LjunJg6Nd3b -q1/u9o1VOo6iMPXoLws+1xpNXcl13xwePb4HMkP5EyeWrF1xiOtjKQecsNzmRn9yiqekPFvHDz8X -MMMIwIAjcoAlC3YPGtVlxMnd9N9CaNjN7hIIQPWkdlaPr4/g0s1NwYp+ubqe61YeOmFQfnZuio4/ -ZmKPo4ca9++t37mlurHeP+q0HjpOftf0iv55a785hFpx1AadAwADf0vwhvPf3rm55ukPp2XmJodV -ZQy0QzQYQFNToGJAnj0kFXNZjKK99q91/tbgC4+vQtIE7dpW/dLf17yz9rIPv7vileWzUtM8avpJ -PyiZfsWA4ad012b9sLxvznPzfzh/848+/u7KO/8y4S+/WapPE3199Lrlh66bde2QG2e+u2NzNQIs -+2T315/v+3DD7D//Z+rdN3yyavmB4vIsYLhvV+1VZ75x1qwTVtbcsPTANa8uuyg7LxkA77txUX1t -6xd758zfcuU/3j6vYkCuGpATz+m1/NB1C7dfpXjYzRe9FwiGGhv9P53x7nmX9Pt059Uff3fl7m21 -j96zTO3k7cwc8NMPdjx277IXFs34cMPsDzfMnnphH1DCvpVbmHLpT4ZOv6K/7gBffLzzkbuWPv3B -tM92z/n7W+c9MPfTb5bsJyMSU9PBAR+7d9mcn4/8ZPuPqo82v/DX1eqiUto2gYnQ1UeEY053+4mO -I8Z3V5aOp78zjrkPMHhE6W4/icO/5vZR77286cjBBopTX9vyxnMbrpw7XJ3loPiffbjjzmvmX/zj -wS8smjHz6oE9K7JT072cq+fVIACGgqF//v6bO35/6iXXD8nvkuZNUk6e1PNPL03dt6t+0fvbdRym -MI+HqSfLWPRnij4jhAD4twe/HDeldMZVA9U/Z984dOCIwicf+lptgpjCPB67/cO0eX1lfW3rjfee -1GdwvnquEdPafR1fUZjiYQC44ot9Lz+59u9vnzfrx4O7lWb6Uj16U+boEorCFMXZjRljTPCTivDN -F/suvHbwKaeXJqd4AWDx+zu+W3Pk/icnJad7OWDfwflz7xv7x18tQcRQiD96z7Jf/uHU8hNyADA9 -M+nBpyYtXbB7xed7AVBRT0zSZCkKA4W1tAZvvPDdfbvqn3z3/LQMr2pSANBbrZVL9g8aWTTr2sEF -RanUjS3rOI2vfYcUNDUEXn9uPTUuR7j/lkV/umtJ1+KMnVtq1Cc+AHjpidUrl+3buPoIauORZx9Z -+dyjK7PzUnLzUw/sqW9pDur4p5Y+5W8NNTcGyPRR4CcXvF1QlH70UCNHuGHG2wCgvvVZs+LgucP+ -nd8lDQEqDzepWVpaAjde+E56pi8tPenIwUYNBxe9u/32Kz+sr/PzkLERZOXy/RMrni4uzaqraa2v -bXVkph7077+ueukfq7uXZu3bWafdOQ8AcORQ49SBzx4+0Ehf6D/5hxXPPvZtcc+sfbvq9EX6+/fU -neD5k2XqCQFe+de6d1/ZxBhrbvD/6k8TDuytR9u8myNRHibk+v7wu80bC0+8ypJoPd3yWPgzsnwn -T+556cRXbSsq4fnHv50+e0CfQfkbvj1sEfHKv9Z98PqW624fNfPqQTffO7awW7qiMI+X6eHy6H3L -WlqCdzx86l2PTmhqDKRn+ua/tfXac99sbTXOtfF6meJhqD3uU7UVRT2uJazTzq3V10+f98A/Jt94 -90ker9JY77/u/HkH9tWr/B5PGMexjI0N/mvOfWvWnMFPfzB917aaSye8wrSGUs+ieAzl77tp4bJF -e664cdhPfnNil24Zi97dft35b9mjUU1QtCLYZXu8CtXKXjUP3PLpj24Z8fPfjes3pOC0sn8e2tcw -9+L37//HpCX7rqk83FRQlP74/ctffWadyv/sIyszsn1vrrjk8IHGou4Zn3208+4bPlGrjDboqukY -QwRsbQ3eNOvdR14++69vnHv11DdUNkUr5odvbrnrhgWTz6/45R9P+9OdS559ZGVYt65wVRoM0PX0 -JXu6dEsvLst+6F9T/njnknf+852THWi5XFCPsqxPt88ZkPpIa2tIh2JtgiLahHGu/fnoUeOKfzxt -nkxTes3PR8kzRxIepuj6jzyl+5TpfT5+c8uhfQ1jf9Bz7r1jL5n46q6tli3dMZk3Bmq7XBqHrF11 -jk7tq1tHr7sIWxEj71LU55STfJ6MLF9tdas24AuL9niVkvKctIyknZurm5sClpiyHoQZ7SfGoLg0 -KxTCg3vryE/MvNsxkqpJPo+/NaT+SbNo72C1P7VXAB6vwkMYYc9w5CJIauVL9ra2BPWUrJyUgqK0 -XdtqLItHGQNvkqe0IvvQ0/lKnAAAAfBJREFU/saGulYyyFRlMUe5ST7P2Ikln32001ElxsDjVZBj -SDtNz6tPRalBkluQ8q8Pfrhh1eF7b1q48N3t+vgdtQk1MJzLobgR+aGpKTB/3taQ8ZYi/ESkH5NM -EaKSDq5m2bW1xpOk6FsoIoPs2lrjTVLoyJ3ZlJeUCwBovWfAgX/rxspBI4vm3Daqe8/MlUv3Xz/j -nZ1bq6OWz2JAxxRH3ST5nfKiLUVWljoScSNLVs/YywW2coF7TIuHcMLPrIxRVIoQJjHwYwT++jrn -LeWWn+zurR/72NoabD1iPcQSAXiQ79hSJQof+4OvgY/O/Ht21tqLJjNEU3n0pw21JdfLoj/W62Gr -8vNAyKKbVVuBaDVEo7qQPkthlB2hprq5prrZQSKC3x/csrHSjoZIQsws1+8PLv5oBxVHiSOEAqbT -wVghXJUG/SlThM4tdpLpHr/HpA+d6DoCpyD9XyO3dui0WycdR9Th3Fu/X9cglB20mTKR75HyChr9 -eD0jHyucNhcf7faPl6z24o9LXrd2aAe7xZJXhr+j6dNBxHW6dxv4wa1uXj2HqwfViHJi7Jri1TNE -f653q48cTvuZzjx/LZcjug5t1yc2WbHkdWvz9nRvGVlu69EZP4512p7FF+dsu3vLcMi4gRgnum4d -IcxFqf8PCRGIaBilWYMAAAAASUVORK5CYII= -""" - -reason_splash = base64.b64decode(png1_b64) - -app = ReasonApp(0) -app.ShowSplash(makeBitmap(reason_splash)) - -import yt.reason -app.AfterInit() -app.MainLoop() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 scripts/yt_particles.py --- a/scripts/yt_particles.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -#!python2.5 - -import optparse -import math -import os, os.path -import sys - -my_opts = optparse.OptionParser() -my_opts.add_option("-w", "--width", - action="store", type="float", - dest="width", default=1.0, - help="Width in specified units") -my_opts.add_option("-u", "--unit", - action="store", type="string", - dest="unit", default='1', - help="Desired units") -my_opts.add_option("-k", "--slab-width", - action="store", type="float", - dest="slab_width", default=1.0, - help="Slab width in specified units") -my_opts.add_option("-g", "--slab-unit", - action="store", type="string", - dest="slab_unit", default='1', - help="Desired units for the slab") -my_opts.add_option("-b", "--basename", - action="store", type="string", - dest="basename", default="galaxy", - help="Basename of parameter files") -my_opts.add_option("-c", "--center", - action="store", type="float", - dest="center", default=None, - nargs=3, - help="Center (-1,-1,-1 for max)") -my_opts.add_option("-z", "--zlim", - action="store", type="float", - dest="zlim", default=None, - nargs=2, - help="Color limits (min, max)") -my_opts.add_option("-a", "--axis", - action="store", type="int", - dest="axis", default=4, - help="Axis (4 for all three)") -my_opts.add_option("-l", "--log", - action="store_true", - dest="takelog", default=False, - help="Take the log of the field?") -my_opts.add_option("-f", "--field", - action="store", type="string", - dest="field", default=None, - help="Field to color by") -my_opts.add_option("-s", "--skip", - action="store", type="int", - dest="skip", default=1, - help="Skip factor for outputs") -my_opts.add_option("-m", "--colormap", - action="store", type="string", - dest="cmap", default="jet", - help="Colormap name") -my_opts.add_option("-o", "--output", - action="store", type="string", - dest="output", default="particle_frames/", - help="Folder in which to place output frames") -my_opts.add_option("-t", "--particle-type", - action="store", type="int", - dest="ptype", default=2, - help="Particle type to select") -my_opts.add_option("-e", "--age-cut", - action="store", type="float", - dest="age_filter", default=None, - nargs=2, - help="Bounds for the field to select") - - -opts, args = my_opts.parse_args() - -import yt.lagos as lagos -import yt.raven as raven -import yt.fido as fido -import numpy as na -mylog = fido.mylog - - - -if not os.path.isdir(opts.output): - os.mkdir(opts.output) - -try: - first = int(args[0]) - last = int(args[1]) -except: - mylog.error("Hey, sorry, but you need to specify the first and last outputs you want to look at.") - sys.exit() - -print first, last, range(first, last+1, opts.skip) - -import pylab -from matplotlib.colors import LogNorm, Normalize - -if opts.takelog: - myNorm = LogNorm -else: - myNorm = Normalize - -for n in range(first,last+1,opts.skip): # This is the array of galaxy outputs we want - # Now we figure out where this file is - bn_try = opts.basename + "%04i" % n - if os.path.isfile(bn_try): - fn = bn_try - else: - fn = os.path.join(bn_try + ".dir", bn_try) - mylog.info("Now attempting to zoom in on %s", fn) - try: - a = lagos.EnzoStaticOutput(fn) - min_dx = a.h.get_smallest_dx() - except: - mylog.warning("Something messed up! Are you sure you gave good info?") - continue - - if opts.center == None: - mylog.info("No center fed in; seeking.") - v, center = a.h.find_max("Density") - else: - mylog.info("Center fed in; not seeking.") - center = opts.center - mylog.info("Setting center to %0.3f %0.3f %0.3f", - center[0], center[1], center[2]) - - # Now we deal with all the plotting. - - if opts.axis == 4: - axes = range(3) - else: - axes = [opts.axis] - - gI = na.where(a.h.gridNumberOfParticles.ravel() > 0) - - npart = na.sum(a.h.gridNumberOfParticles) - pos = na.zeros((npart,4)) # three plus fielD - ni = 0 - mylog.info("Getting particles from %s grids", len(gI[0])) - for grid in a.h.grids[gI]: - pi = na.where(grid["particle_type"] == opts.ptype) - x = grid["particle_position_x"][pi] - y = grid["particle_position_y"][pi] - z = grid["particle_position_z"][pi] - pos[ni:ni+x.shape[0],0] = x - pos[ni:ni+x.shape[0],1] = y - pos[ni:ni+x.shape[0],2] = z - if opts.field: - if opts.field == "age": - pos[ni:ni+x.shape[0],3] = \ - (a["InitialTime"] - grid["creation_time"][pi]) \ - * a["years"] - else: - pos[ni:ni+x.shape[0],3] = grid[opts.field][pi] - ni += x.shape[0] - - for ax in axes: - mylog.info("Adding plot for axis %i", ax) - pylab.clf() - xa = lagos.x_dict[ax] - ya = lagos.y_dict[ax] - - z1 = center[ax] - opts.slab_width/a[opts.slab_unit] * 0.5 - z2 = center[ax] + opts.slab_width/a[opts.slab_unit] * 0.5 - - newpos = pos[na.where((pos[:,ax] > z1) - & (pos[:,ax] < z2))] - if newpos.shape[0] == 0: - mylog.info("Hey, no particles match the criteria. Moving on.") - continue - if opts.age_filter and opts.field == "age": - newpos = newpos[na.where((newpos[:,3] > opts.age_filter[0]) - & (newpos[:,3] < opts.age_filter[1]))] - mylog.info("Constraining to %s - %s, which gives us %s particles", - z1,z2,newpos.shape[0]) - if opts.field: - #print "MM", \ - #newpos[:,xa].min(), newpos[:,xa].max(), \ - #newpos[:,3].min(), newpos[:,3].max() - pylab.scatter(newpos[:,xa].ravel(), - newpos[:,ya].ravel(), - c=newpos[:,3].ravel(), - faceted=False,s=1.0, - alpha=1.0, - norm=myNorm()) - if opts.zlim: - pylab.clim(opts.zlim[0], opts.zlim[1]) - pylab.colorbar() - else: - pylab.scatter(newpos[:,xa].ravel(), - newpos[:,ya].ravel(), - c='k',faceted=False,s=1.0, - alpha=1.0) - - x1 = center[xa] - \ - opts.width / (2.0*a[opts.unit]) - x2 = center[xa] + \ - opts.width / (2.0*a[opts.unit]) - y1 = center[ya] - \ - opts.width / (2.0*a[opts.unit]) - y2 = center[ya] + \ - opts.width / (2.0*a[opts.unit]) - pylab.xlim(x1, x2) - pylab.ylim(y1, y2) - pylab.savefig(os.path.join(opts.output,"particle_frame%06i_%s.png" - % (n,lagos.axis_names[ax]))) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 setup.py --- a/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ b/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -7,9 +7,7 @@ import setuptools -APP = ['reason.py'] DATA_FILES = [] -PY2APP_OPTIONS = {'argv_emulation': True} VERSION = "2.0dev" if os.path.exists('MANIFEST'): os.remove('MANIFEST') @@ -65,9 +63,7 @@ url = "http://yt.enzotools.org/", license="GPL-3", configuration=configuration, - app=APP, # for py2app data_files=DATA_FILES, - options={'py2app':PY2APP_OPTIONS}, zip_safe=False, package_data = {'': ['*.so'], } ) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 tests/regression_scripts/gal.py --- a/tests/regression_scripts/gal.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -""" Original with Weave: -Doing contour 9 / 10 (4.56276e-14 9.91625e-14) -yt.lagos INFO 2008-04-10 17:04:45,085 Getting field Density from 197 -yt.lagos INFO 2008-04-10 17:04:46,284 Contouring over 1061337 cells with 30115 candidates -yt.lagos INFO 2008-04-10 17:05:17,880 Getting field tempContours from 197 -yt.lagos INFO 2008-04-10 17:05:18,305 Identified 5 contours between 4.56276e-14 and 2.15510e-13 -yt.lagos INFO 2008-04-10 17:05:18,312 Getting field Contours from 197 -yt.lagos INFO 2008-04-10 17:05:19,330 Getting field GridIndices from 197 - Contour id 0.0 has: 4.56297e-14 9.88512e-14 (2351) (4 grids, 11081.0 11087.0) - Contour id 1.0 has: 4.58381e-14 5.41707e-14 (13) (1 grids, 11079.0 11079.0) - Contour id 2.0 has: 4.60523e-14 4.79728e-14 (19) (2 grids, 11079.0 11082.0) - Contour id 3.0 has: 4.56287e-14 2.15439e-13 (26063) (32 grids, 11040.0 11103.0) - Contour id 4.0 has: 4.56339e-14 7.18032e-14 (1669) (3 grids, 11039.0 11051.0) -""" - -""" New with C extension: -yt.lagos INFO 2008-04-11 00:18:03,943 Getting field Density from 197 -yt.lagos INFO 2008-04-11 00:18:05,109 Contouring over 1061337 cells with 30115 candidates -yt.lagos INFO 2008-04-11 00:18:36,243 Getting field tempContours from 197 -yt.lagos INFO 2008-04-11 00:18:36,626 Identified 5 contours between 4.56276e-14 and 2.15510e-13 -yt.lagos INFO 2008-04-11 00:18:36,633 Getting field Contours from 197 -yt.lagos INFO 2008-04-11 00:18:37,601 Getting field GridIndices from 197 - Contour id 0.0 has: 3.43716e-14 9.88512e-14 (2352) (4 grids, 11081.0 11087.0) - Contour id 1.0 has: 4.58381e-14 5.41707e-14 (13) (1 grids, 11079.0 11079.0) - Contour id 2.0 has: 4.60523e-14 4.79728e-14 (19) (2 grids, 11079.0 11082.0) - Contour id 3.0 has: 4.56287e-14 2.15439e-13 (26063) (32 grids, 11040.0 11103.0) - Contour id 4.0 has: 4.56339e-14 7.18032e-14 (1669) (3 grids, 11039.0 11051.0) -""" - -"""With C extension and no ->data[] accesses -yt.lagos INFO 2008-04-11 14:19:24,079 Getting field Density from 197 -yt.lagos INFO 2008-04-11 14:19:25,356 Contouring over 1061337 cells with 30115 candidates -yt.lagos INFO 2008-04-11 14:19:58,070 Getting field tempContours from 197 -yt.lagos INFO 2008-04-11 14:19:58,455 Identified 5 contours between 4.56276e-14 and 2.15510e-13 -yt.lagos INFO 2008-04-11 14:19:58,462 Getting field Contours from 197 -yt.lagos INFO 2008-04-11 14:19:59,418 Getting field GridIndices from 197 - Contour id 0.0 has: 4.56297e-14 9.88512e-14 (2351) (4 grids, 11081.0 11087.0) - Contour id 1.0 has: 4.58381e-14 5.41707e-14 (13) (1 grids, 11079.0 11079.0) - Contour id 2.0 has: 4.60523e-14 4.79728e-14 (19) (2 grids, 11079.0 11082.0) - Contour id 3.0 has: 4.56287e-14 2.15439e-13 (26063) (32 grids, 11040.0 11103.0) - Contour id 4.0 has: 4.56339e-14 7.18032e-14 (1669) (3 grids, 11039.0 11051.0) -""" - - -import sys -sys.path.insert(0,"/Users/matthewturk/Development/yt/trunk") -from yt.config import ytcfg - -ytcfg["yt","LogLevel"] = '20' -ytcfg["yt","logFile"] = "False" -ytcfg["yt","suppressStreamLogging"] = "True" - -con_field = "Temperature" -con_field = "Density" - -import yt.lagos as lagos -import yt.raven as raven -import numpy as na -import scipy.weave as weave -import scipy.weave.converters as converters - -print lagos, raven - -#fn = "/Users/matthewturk/Research/data/yt_test_data/galaxy1360.dir/galaxy1360" -fn = "/Users/matthewturk/Research/data/DataDir0036/DataDump0036" -a = lagos.EnzoStaticOutput(fn) - -v,c = a.h.find_max("Density") - -sp = a.h.sphere(c,20000.0/a['au']) -sp2 = a.h.sphere(c,200.0/a['au']) - -#lagos.identify_contours(sp, "Density", 1e-27, 1e-24) -#lagos.identify_contours(sp, "Density", 1e-33, 1e-22) -nc = 10 -cons = na.logspace(na.log10(sp2[con_field].min()*0.9), - na.log10(sp2[con_field].max()),nc+1) -do_plot = 1 -k = [] -k_bad = [] -for i in [8]:#range(nc): - [grid.clear_data() for grid in sp._grids] - mi, ma = cons[i], cons[i+1] - print "Doing contour %s / %s (%0.5e %0.5e)" % (i+1,nc,mi,ma) - mq=lagos.identify_contours(sp, con_field, mi, sp[con_field].max()) - for cid in mq: - sp["Contours"][mq[cid]] = cid - k.append(na.unique(sp["Contours"]).size) - my_con = sp["Contours"] - sp._flush_data_to_grids("Contours",-1) - for cid in na.unique(sp["Contours"])[1:]: - cid_ind = na.where(sp["Contours"] == cid) - print "\tContour id %s has: %0.5e %0.5e (%s) (%s grids, %s %s)" % \ - (cid, sp[con_field][cid_ind].min(), sp[con_field][cid_ind].max(), - sp["Density"][cid_ind].size, - na.unique(sp["GridIndices"][cid_ind]).size, - na.unique(sp["GridIndices"][cid_ind]).min(), - na.unique(sp["GridIndices"][cid_ind]).max(), - ) - #sp = a.h.sphere(c,20000.0/a['au']) - sp.get_data("Contours",in_grids=True) - if not na.all(sp["Contours"] == my_con): - khdoihiueh0 - g_bad = 0 - for grid in sp._grids: - grid['dx'] = na.ones(grid.ActiveDimensions)*grid.dx - grid['dy'] = na.ones(grid.ActiveDimensions)*grid.dy - grid['dz'] = na.ones(grid.ActiveDimensions)*grid.dz - g_bad+=lagos.check_neighbors(grid) - print "GRID:",g_bad - k_bad.append(lagos.check_neighbors(sp)) - print "SOURCE",k_bad[-1] - if do_plot: - #c=na.array([sp["x"][ind][-1],sp["y"][ind][-1],sp["z"][ind][-1]]) - pc = raven.PlotCollection(a, center=c) - pc.add_slice("Density",0) - pc.add_slice("Density",1) - pc.add_slice("Density",2) - for field in ["Density","Contours"]: - pc.switch_field(field) - pc.set_width(10000,'au') - pc.save("test_bds_%02i_10000au" % i) - pc.set_width(2000,'au') - pc.save("test_bds_%02i_02000au" % i) - pc.set_width(1000,'au') - pc.save("test_bds_%02i_01000au" % i) - pc.set_width(100,'au') - pc.save("test_bds_%02i_00100au" % i) - del sp.data["Contours"] -print k -print k_bad diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 tests/regression_scripts/get_particles.py --- a/tests/regression_scripts/get_particles.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -import sys -sys.path.insert(0,"/Users/matthewturk/Development/yt/trunk/") - -import numpy as na -import yt.lagos as lagos - -a = lagos.EnzoStaticOutput("galaxy1800.dir/galaxy1800") - -sp = a.h.sphere([0.5,0.5,0.5], 1.0) - -print sp["ParticleMassMsun"].max() -print sp["particle_velocity_x"].max() - -print sp['particle_velocity_x'][sp['particle_type']==2].size -print sp['particle_velocity_x'][sp['particle_type']==1].size - -for grid in a.h.grids: - LE = grid.LeftEdge - RE = grid.RightEdge - center = (LE + RE)/2.0 - grid.set_field_parameter('center', center) - rad = grid["RadiusCode"].max() - reg = a.h.region(center, LE, RE) - sph = a.h.sphere(center, rad) - print "Checking region corresponding to grid", center, LE, RE - # Now let's manually check our sizes - pos = na.array([reg['particle_position_x'], - reg['particle_position_y'], - reg['particle_position_z']]).transpose() - spos = na.array([sph['particle_position_x'], - sph['particle_position_y'], - sph['particle_position_z']]).transpose() - mrad = na.array( na.sqrt(((spos - center)**2.0).sum(axis=1))) - if na.any( na.all(pos > RE,axis=1) | na.all(pos < LE,axis=1) ) \ - or na.any(mrad > rad): - print grid, na.any(mrad > rad), na.any( na.all(pos > RE,axis=1) | na.all(pos < LE,axis=1) ) - raise KeyError diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 tests/regression_scripts/test_radtrans.py --- a/tests/regression_scripts/test_radtrans.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -from yt.lagos import RTIntegrator as RT -import numpy as na -import pylab, time - -size = 16 - -i_s = na.ones((size*2,size*2), dtype='float') -o_s = na.zeros((size,size,size), dtype='float') -e = na.ones((size,size,size), dtype='float') * 0 -e[:,:,size/2:] = 0.0 -a = na.ones((size,size,size), dtype='float') -#a[:,:,:size/2] = 0.0 - -def output_plots(image_field, axis): - arr = image_field.swapaxes(0, axis) - for i in range(arr.shape[axis]): - print i - pylab.clf() - pylab.imshow(arr[i,...], interpolation='nearest') - pylab.colorbar() - pylab.clim(image_field.min(), image_field.max()) - pylab.savefig("RT/image_%s_%04i.png" % (axis,i)) - -dx = 1.0/size -t1 = time.time() -RT.Transfer3D(i_s, o_s, e, a, 2,4, 2,4, 2, 8, 2, 2, dx) -t2 = time.time() -print "Took %0.3e seconds for a %s box" % (t2-t1, o_s.shape) - -pylab.clf() -pylab.plot(range(size), o_s[:,0,0].ravel()) -pylab.savefig("RT/line_plot_0.png") - -pylab.clf() -pylab.plot(range(size), o_s[0,:,0].ravel()) -pylab.savefig("RT/line_plot_1.png") - -pylab.clf() -pylab.plot(range(size), o_s[0,0,:].ravel()) -pylab.savefig("RT/line_plot_2.png") - -pylab.clf() -pylab.imshow(i_s, interpolation='nearest') -pylab.colorbar() -pylab.savefig("RT/resultant_image.png") - -output_plots(o_s, 0) -output_plots(o_s, 1) -output_plots(o_s, 2) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 tests/regression_scripts/test_radtrans1d.py --- a/tests/regression_scripts/test_radtrans1d.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -from yt.lagos import RTIntegrator as RT -import numpy as na -import pylab, time - -size = 1024 - -i_s = 1.0 -o_s = na.zeros(size, dtype='float') -e = na.ones(size, dtype='float') * 0 -e[size/2:] = 0.0 -a = na.ones(size, dtype='float') -#a[:,:,:size/2] = 0.0 - -dx = na.ones(size, dtype='float') * 1.0/size -t1 = time.time() -RT.Transfer1D(i_s, o_s, e, a, dx, 0, size) -t2 = time.time() -print "Took %0.3e seconds for a %s box" % (t2-t1, o_s.shape) - -pylab.clf() -pylab.plot(range(size), o_s) -pylab.savefig("RT/line_plot_0.png") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 tests/test_lagos.py --- a/tests/test_lagos.py Mon Aug 30 10:02:07 2010 -0700 +++ b/tests/test_lagos.py Mon Aug 30 10:48:15 2010 -0700 @@ -16,10 +16,16 @@ ytcfg["lagos","serialize"] = "False" import cPickle -import yt.lagos -import yt.lagos.OutputTypes import numpy as na -from yt.fido import ParameterFileStore +#from yt.utilities.exceptions import * +from yt.data_objects.field_info_container import \ + ValidationException +from yt.mods import * +from yt.analysis_modules.level_sets.api import * +from yt.utilities.linear_interpolators import \ + UnilinearFieldInterpolator, \ + BilinearFieldInterpolator, \ + TrilinearFieldInterpolator # The dataset used is located at: # http://yt.spacepope.org/DD0018.zip @@ -28,7 +34,7 @@ class LagosTestingBase: def setUp(self): - self.OutputFile = yt.lagos.EnzoStaticOutput(fn) + self.OutputFile = load(fn) self.hierarchy = self.OutputFile.hierarchy self.v, self.c = self.hierarchy.find_max("Density") gp = os.path.join(os.path.dirname(fn),"*.yt") @@ -54,19 +60,19 @@ ytcfg['lagos', 'serialize'] = "True" def testCacheFile(self): - pf1 = yt.lagos.EnzoStaticOutput(fn) + pf1 = load(fn) pf2 = self.pfs.get_pf_hash(pf1._hash()) self.assertTrue(pf1 is pf2) def testGrabFile(self): - pf1 = yt.lagos.EnzoStaticOutput(fn) + pf1 = load(fn) hash = pf1._hash() del pf1 pf2 = self.pfs.get_pf_hash(hash) self.assertTrue(hash == pf2._hash()) def testGetCurrentTimeID(self): - pf1 = yt.lagos.EnzoStaticOutput(fn) + pf1 = load(fn) hash = pf1._hash() ctid = pf1["CurrentTimeIdentifier"] del pf1 @@ -166,14 +172,14 @@ self.assertEqual(na.product(self.data["Density"].shape), na.product(self.data[field.name].shape)) del self.data[field.name] - except yt.lagos.ValidationException: + except ValidationException: pass return field_function def _returnProfile1DFunction(field, weight, accumulation, lazy): def add_field_function(self): self.data.set_field_parameter("center",[.5,.5,.5]) - profile = yt.lagos.BinnedProfile1D( + profile = BinnedProfile1D( self.data, 8, "RadiusCode", 0, 1.0, False, lazy) profile.add_fields(field, weight=weight, accumulation=accumulation) return add_field_function @@ -183,7 +189,7 @@ self.data.set_field_parameter("center",[.5,.5,.5]) cv_min = self.hierarchy.get_smallest_dx()**3.0 cv_max = 1.0 / max(self.OutputFile["TopGridDimensions"]) - profile = yt.lagos.BinnedProfile2D(self.data, + profile = BinnedProfile2D(self.data, 8, "RadiusCode", 1e-3, 1.0, True, 8, "CellVolumeCode", cv_min, cv_max, True, lazy) profile.add_fields(field, weight=weight, accumulation=accumulation) @@ -200,7 +206,7 @@ class Data3DBase: def testProfileAccumulateMass(self): self.data.set_field_parameter("center",[0.5]*3) - profile = yt.lagos.BinnedProfile1D(self.data, 8, "RadiusCode", 0, 1.0, + profile = BinnedProfile1D(self.data, 8, "RadiusCode", 0, 1.0, False, True) profile.add_fields("CellMassMsun", weight=None, accumulation=True) v1 = profile["CellMassMsun"].max() @@ -227,20 +233,20 @@ self.assertEqual(len(contours[1]), 1) def testContoursCache(self): - cid = yt.lagos.identify_contours(self.data, "Density", + cid = identify_contours(self.data, "Density", self.data["Density"].min()*2.00, self.data["Density"].max()*1.01) self.assertEqual(len(cid), 2) def testContoursObtain(self): - cid = yt.lagos.identify_contours(self.data, "Density", + cid = identify_contours(self.data, "Density", self.data["Density"].min()*2.00, self.data["Density"].max()*1.01) self.assertEqual(len(cid), 2) def testContoursValidityMax(self): v1 = self.data["Density"].max()*0.99 v2 = self.data["Density"].max()*1.01 - cid = yt.lagos.identify_contours(self.data, "Density", v1, v2) + cid = identify_contours(self.data, "Density", v1, v2) self.assertTrue(na.all(v1 < self.data["Density"][cid[0]]) and na.all(v2 > self.data["Density"][cid[0]])) self.assertEqual(len(cid), 1) @@ -248,7 +254,7 @@ def testContoursValidityMin(self): v1 = self.data["Density"].min()*0.99 v2 = self.data["Density"].min()*1.01 - cid = yt.lagos.identify_contours(self.data, "Density", v1, v2) + cid = identify_contours(self.data, "Density", v1, v2) self.assertTrue(na.all(v1 < self.data["Density"][cid[0]]) and na.all(v2 > self.data["Density"][cid[0]])) self.assertEqual(len(cid), 3) @@ -258,9 +264,9 @@ pf, obj = cPickle.loads(ps) self.assertEqual(obj["CellMassMsun"].sum(), self.data["CellMassMsun"].sum()) -for field_name in yt.lagos.FieldInfo: +for field_name in FieldInfo: if field_name.startswith("PT"): continue - field = yt.lagos.FieldInfo[field_name] + field = FieldInfo[field_name] setattr(DataTypeTestingBase, "test%s" % field.name, _returnFieldFunction(field)) field = "Temperature" @@ -516,12 +522,12 @@ # contours outside. This are overridden to make sure this does not # happen again! def testContoursObtain(self): - cid = yt.lagos.identify_contours(self.data, "Density", + cid = identify_contours(self.data, "Density", self.data["Density"].min()*2.00, self.data["Density"].max()*1.01) self.assertEqual(len(cid), 10) def testContoursCache(self): - cid = yt.lagos.identify_contours(self.data, "Density", + cid = identify_contours(self.data, "Density", self.data["Density"].min()*2.00, self.data["Density"].max()*1.01) self.assertEqual(len(cid), 10) @@ -570,12 +576,12 @@ # contours outside. This are overridden to make sure this does not # happen again! def testContoursObtain(self): - cid = yt.lagos.identify_contours(self.data, "Density", + cid = identify_contours(self.data, "Density", self.data["Density"].min()*2.00, self.data["Density"].max()*1.01) self.assertEqual(len(cid), 10) def testContoursCache(self): - cid = yt.lagos.identify_contours(self.data, "Density", + cid = identify_contours(self.data, "Density", self.data["Density"].min()*2.00, self.data["Density"].max()*1.01) self.assertEqual(len(cid), 10) @@ -607,7 +613,7 @@ table = na.mgrid[x0:x1:nstep_x*1j] - self.ufi_x = yt.lagos.UnilinearFieldInterpolator(table, + self.ufi_x = UnilinearFieldInterpolator(table, (x0,x1),'x') self.my_dict = {} self.my_dict['x'] = na.random.uniform(x0,x1,nvals) @@ -628,9 +634,9 @@ table = na.mgrid[x0:x1:nstep_x*1j, y0:y1:nstep_y*1j] - self.bfi_x = yt.lagos.BilinearFieldInterpolator(table[0,...], + self.bfi_x = BilinearFieldInterpolator(table[0,...], (x0,x1,y0,y1),['x','y']) - self.bfi_y = yt.lagos.BilinearFieldInterpolator(table[1,...], + self.bfi_y = BilinearFieldInterpolator(table[1,...], (x0,x1,y0,y1),['x','y']) self.my_dict = {} self.my_dict['x'] = na.random.uniform(x0,x1,nvals) @@ -660,11 +666,11 @@ y0:y1:nstep_y*1j, z0:z1:nstep_z*1j] - self.tfi_x = yt.lagos.TrilinearFieldInterpolator(table[0,...], + self.tfi_x = TrilinearFieldInterpolator(table[0,...], (x0,x1,y0,y1,z0,z1),['x','y','z']) - self.tfi_y = yt.lagos.TrilinearFieldInterpolator(table[1,...], + self.tfi_y = TrilinearFieldInterpolator(table[1,...], (x0,x1,y0,y1,z0,z1),['x','y','z']) - self.tfi_z = yt.lagos.TrilinearFieldInterpolator(table[2,...], + self.tfi_z = TrilinearFieldInterpolator(table[2,...], (x0,x1,y0,y1,z0,z1),['x','y','z']) self.my_dict = {} self.my_dict['x'] = na.random.uniform(x0,x1,nvals) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/CICDeposit.pyx --- a/yt/_amr_utils/CICDeposit.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -""" -Simle integrators for the radiative transfer equation - -Author: Britton Smith -Affiliation: CASA/University of Colorado -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008 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 . -""" - -@cython.boundscheck(False) -@cython.wraparound(False) -def CICDeposit_3(np.ndarray[np.float64_t, ndim=1] posx, - np.ndarray[np.float64_t, ndim=1] posy, - np.ndarray[np.float64_t, ndim=1] posz, - np.ndarray[np.float32_t, ndim=1] mass, - np.int64_t npositions, - np.ndarray[np.float32_t, ndim=3] field, - np.ndarray[np.float64_t, ndim=1] leftEdge, - np.ndarray[np.int32_t, ndim=1] gridDimension, - np.float64_t cellSize): - - cdef int i1, j1, k1, n - cdef double xpos, ypos, zpos - cdef double fact, edge0, edge1, edge2 - cdef double le0, le1, le2 - cdef float dx, dy, dz, dx2, dy2, dz2 - - edge0 = ( gridDimension[0]) - 0.5001 - edge1 = ( gridDimension[1]) - 0.5001 - edge2 = ( gridDimension[2]) - 0.5001 - fact = 1.0 / cellSize - - le0 = leftEdge[0] - le1 = leftEdge[1] - le2 = leftEdge[2] - - for n in range(npositions): - - # Compute the position of the central cell - xpos = fmin(fmax((posx[n] - le0)*fact, 0.5001), edge0) - ypos = fmin(fmax((posy[n] - le1)*fact, 0.5001), edge1) - zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2) - - i1 = (xpos + 0.5) - j1 = (ypos + 0.5) - k1 = (zpos + 0.5) - - # Compute the weights - dx = ( i1) + 0.5 - xpos - dy = ( j1) + 0.5 - ypos - dz = ( k1) + 0.5 - zpos - dx2 = 1.0 - dx - dy2 = 1.0 - dy - dz2 = 1.0 - dz - - # Interpolate from field into sumfield - field[i1-1,j1-1,k1-1] += mass[n] * dx * dy * dz - field[i1 ,j1-1,k1-1] += mass[n] * dx2 * dy * dz - field[i1-1,j1 ,k1-1] += mass[n] * dx * dy2 * dz - field[i1 ,j1 ,k1-1] += mass[n] * dx2 * dy2 * dz - field[i1-1,j1-1,k1 ] += mass[n] * dx * dy * dz2 - field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2 - field[i1-1,j1 ,k1 ] += mass[n] * dx * dy2 * dz2 - field[i1 ,j1 ,k1 ] += mass[n] * dx2 * dy2 * dz2 diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/ContourFinding.pyx --- a/yt/_amr_utils/ContourFinding.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -""" -A two-pass contour finding algorithm - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -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 . -""" - -import numpy as np -cimport numpy as np -cimport cython - -cdef extern from "math.h": - double fabs(double x) - -cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): - if i0 > i1: return i0 - return i1 - -cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - if i0 < i1: return i0 - return i1 - -@cython.boundscheck(False) -def construct_boundary_relationships( - np.ndarray[dtype=np.int64_t, ndim=3] contour_ids): - # We only look at the boundary and one cell in - cdef int i, j, nx, ny, nz, offset_i, offset_j, oi, oj - cdef np.int64_t c1, c2 - tree = [] - nx = contour_ids.shape[0] - ny = contour_ids.shape[1] - nz = contour_ids.shape[2] - # First x-pass - for i in range(ny): - for j in range(nz): - for offset_i in range(3): - oi = offset_i - 1 - if i == 0 and oi == -1: continue - if i == ny - 1 and oj == 1: continue - for offset_j in range(3): - oj = offset_j - 1 - if j == 0 and oj == -1: continue - if j == nz - 1 and oj == 1: continue - c1 = contour_ids[0, i, j] - c2 = contour_ids[1, i + oi, j + oj] - if c1 > -1 and c2 > -1: - tree.append((i64max(c1,c2), i64min(c1,c2))) - c1 = contour_ids[nx-1, i, j] - c2 = contour_ids[nx-2, i + oi, j + oj] - if c1 > -1 and c2 > -1: - tree.append((i64max(c1,c2), i64min(c1,c2))) - # Now y-pass - for i in range(nx): - for j in range(nz): - for offset_i in range(3): - oi = offset_i - 1 - if i == 0 and oi == -1: continue - if i == nx - 1 and oj == 1: continue - for offset_j in range(3): - oj = offset_j - 1 - if j == 0 and oj == -1: continue - if j == nz - 1 and oj == 1: continue - c1 = contour_ids[i, 0, j] - c2 = contour_ids[i + oi, 1, j + oj] - if c1 > -1 and c2 > -1: - tree.append((i64max(c1,c2), i64min(c1,c2))) - c1 = contour_ids[i, ny-1, j] - c2 = contour_ids[i + oi, ny-2, j + oj] - if c1 > -1 and c2 > -1: - tree.append((i64max(c1,c2), i64min(c1,c2))) - for i in range(nx): - for j in range(ny): - for offset_i in range(3): - oi = offset_i - 1 - if i == 0 and oi == -1: continue - if i == nx - 1 and oj == 1: continue - for offset_j in range(3): - oj = offset_j - 1 - if j == 0 and oj == -1: continue - if j == ny - 1 and oj == 1: continue - c1 = contour_ids[i, j, 0] - c2 = contour_ids[i + oi, j + oj, 1] - if c1 > -1 and c2 > -1: - tree.append((i64max(c1,c2), i64min(c1,c2))) - c1 = contour_ids[i, j, nz-1] - c2 = contour_ids[i + oi, j + oj, nz-2] - if c1 > -1 and c2 > -1: - tree.append((i64max(c1,c2), i64min(c1,c2))) - return tree - -cdef inline int are_neighbors( - np.float64_t x1, np.float64_t y1, np.float64_t z1, - np.float64_t dx1, np.float64_t dy1, np.float64_t dz1, - np.float64_t x2, np.float64_t y2, np.float64_t z2, - np.float64_t dx2, np.float64_t dy2, np.float64_t dz2, - ): - # We assume an epsilon of 1e-15 - if fabs(x1-x2) > 0.5*(dx1+dx2): return 0 - if fabs(y1-y2) > 0.5*(dy1+dy2): return 0 - if fabs(z1-z2) > 0.5*(dz1+dz2): return 0 - return 1 - -@cython.boundscheck(False) -@cython.wraparound(False) -def identify_field_neighbors( - np.ndarray[dtype=np.float64_t, ndim=1] field, - np.ndarray[dtype=np.float64_t, ndim=1] x, - np.ndarray[dtype=np.float64_t, ndim=1] y, - np.ndarray[dtype=np.float64_t, ndim=1] z, - np.ndarray[dtype=np.float64_t, ndim=1] dx, - np.ndarray[dtype=np.float64_t, ndim=1] dy, - np.ndarray[dtype=np.float64_t, ndim=1] dz, - ): - # We assume this field is pre-jittered; it has no identical values. - cdef int outer, inner, N, added - cdef np.float64_t x1, y1, z1, dx1, dy1, dz1 - N = field.shape[0] - #cdef np.ndarray[dtype=np.object_t] joins - joins = [[] for outer in range(N)] - #joins = np.empty(N, dtype='object') - for outer in range(N): - if (outer % 10000) == 0: print outer, N - x1 = x[outer] - y1 = y[outer] - z1 = z[outer] - dx1 = dx[outer] - dy1 = dy[outer] - dz1 = dz[outer] - this_joins = joins[outer] - added = 0 - # Go in reverse order - for inner in range(outer, 0, -1): - if not are_neighbors(x1, y1, z1, dx1, dy1, dz1, - x[inner], y[inner], z[inner], - dx[inner], dy[inner], dz[inner]): - continue - # Hot dog, we have a weiner! - this_joins.append(inner) - added += 1 - if added == 26: break - return joins - -@cython.boundscheck(False) -@cython.wraparound(False) -def extract_identified_contours(int max_ind, joins): - cdef int i - contours = [] - for i in range(max_ind + 1): # +1 to get to the max_ind itself - contours.append(set([i])) - if len(joins[i]) == 0: - continue - proto_contour = [i] - for j in joins[i]: - proto_contour += contours[j] - proto_contour = set(proto_contour) - for j in proto_contour: - contours[j] = proto_contour - return contours diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/DepthFirstOctree.pyx --- a/yt/_amr_utils/DepthFirstOctree.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -""" -This is a recursive function to return a depth-first octree - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008 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 . -""" - -import numpy as np -cimport numpy as np -cimport cython - -cdef class position: - cdef public int output_pos, refined_pos - def __cinit__(self): - self.output_pos = 0 - self.refined_pos = 0 - -cdef class OctreeGrid: - cdef public object child_indices, fields, left_edges, dimensions, dx - cdef public int level - def __cinit__(self, - np.ndarray[np.int32_t, ndim=3] child_indices, - np.ndarray[np.float64_t, ndim=4] fields, - np.ndarray[np.float64_t, ndim=1] left_edges, - np.ndarray[np.int32_t, ndim=1] dimensions, - np.ndarray[np.float64_t, ndim=1] dx, - int level): - self.child_indices = child_indices - self.fields = fields - self.left_edges = left_edges - self.dimensions = dimensions - self.dx = dx - self.level = level - -cdef class OctreeGridList: - cdef public object grids - def __cinit__(self, grids): - self.grids = grids - - def __getitem__(self, int item): - return self.grids[item] - -@cython.boundscheck(False) -def RecurseOctreeDepthFirst(int i_i, int j_i, int k_i, - int i_f, int j_f, int k_f, - position curpos, int gi, - np.ndarray[np.float64_t, ndim=2] output, - np.ndarray[np.int32_t, ndim=1] refined, - OctreeGridList grids): - cdef int i, i_off, j, j_off, k, k_off, ci, fi - cdef int child_i, child_j, child_k - cdef OctreeGrid child_grid - cdef OctreeGrid grid = grids[gi-1] - cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - cdef np.float64_t dx = grid.dx[0] - cdef np.float64_t child_dx - cdef np.ndarray[np.float64_t, ndim=1] child_leftedges - cdef np.float64_t cx, cy, cz - for i_off in range(i_f): - i = i_off + i_i - cx = (leftedges[0] + i*dx) - for j_off in range(j_f): - j = j_off + j_i - cy = (leftedges[1] + j*dx) - for k_off in range(k_f): - k = k_off + k_i - cz = (leftedges[2] + k*dx) - ci = grid.child_indices[i,j,k] - if ci == -1: - for fi in range(fields.shape[0]): - output[curpos.output_pos,fi] = fields[fi,i,j,k] - refined[curpos.refined_pos] = 0 - curpos.output_pos += 1 - curpos.refined_pos += 1 - else: - refined[curpos.refined_pos] = 1 - curpos.refined_pos += 1 - child_grid = grids[ci-1] - child_dx = child_grid.dx[0] - child_leftedges = child_grid.left_edges - child_i = int((cx - child_leftedges[0])/child_dx) - child_j = int((cy - child_leftedges[1])/child_dx) - child_k = int((cz - child_leftedges[2])/child_dx) - s = RecurseOctreeDepthFirst(child_i, child_j, child_k, 2, 2, 2, - curpos, ci, output, refined, grids) - return s - -@cython.boundscheck(False) -def RecurseOctreeByLevels(int i_i, int j_i, int k_i, - int i_f, int j_f, int k_f, - np.ndarray[np.int32_t, ndim=1] curpos, - int gi, - np.ndarray[np.float64_t, ndim=2] output, - np.ndarray[np.int32_t, ndim=2] genealogy, - np.ndarray[np.float64_t, ndim=2] corners, - OctreeGridList grids): - cdef np.int32_t i, i_off, j, j_off, k, k_off, ci, fi - cdef int child_i, child_j, child_k - cdef OctreeGrid child_grid - cdef OctreeGrid grid = grids[gi-1] - cdef int level = grid.level - cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - cdef np.float64_t dx = grid.dx[0] - cdef np.float64_t child_dx - cdef np.ndarray[np.float64_t, ndim=1] child_leftedges - cdef np.float64_t cx, cy, cz - cdef int cp - for i_off in range(i_f): - i = i_off + i_i - cx = (leftedges[0] + i*dx) - if i_f > 2: print k, cz - for j_off in range(j_f): - j = j_off + j_i - cy = (leftedges[1] + j*dx) - for k_off in range(k_f): - k = k_off + k_i - cz = (leftedges[2] + k*dx) - cp = curpos[level] - corners[cp, 0] = cx - corners[cp, 1] = cy - corners[cp, 2] = cz - genealogy[curpos[level], 2] = level - # always output data - for fi in range(fields.shape[0]): - output[cp,fi] = fields[fi,i,j,k] - ci = child_indices[i,j,k] - if ci > -1: - child_grid = grids[ci-1] - child_dx = child_grid.dx[0] - child_leftedges = child_grid.left_edges - child_i = int((cx-child_leftedges[0])/child_dx) - child_j = int((cy-child_leftedges[1])/child_dx) - child_k = int((cz-child_leftedges[2])/child_dx) - # set current child id to id of next cell to examine - genealogy[cp, 0] = curpos[level+1] - # set next parent id to id of current cell - genealogy[curpos[level+1]:curpos[level+1]+8, 1] = cp - s = RecurseOctreeByLevels(child_i, child_j, child_k, 2, 2, 2, - curpos, ci, output, genealogy, - corners, grids) - curpos[level] += 1 - return s - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/FixedInterpolator.c --- a/yt/_amr_utils/FixedInterpolator.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/************************************************************************ -* Copyright (C) 2009 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 . -* -************************************************************************/ - - -// -// A small, tiny, itty bitty module for computation-intensive interpolation -// that I can't seem to make fast in Cython -// - -#include "FixedInterpolator.h" - -#define VINDEX(A,B,C) data[((((A)+ci[0])*(ds[1]+1)+((B)+ci[1]))*(ds[2]+1)+ci[2]+(C))] -// (((C*ds[1])+B)*ds[0]+A) -#define OINDEX(A,B,C) data[(A)*(ds[1]+1)*(ds[2]+1)+(B)*ds[2]+(B)+(C)] - -npy_float64 fast_interpolate(int ds[3], int ci[3], npy_float64 dp[3], - npy_float64 *data) -{ - int i; - npy_float64 dv, dm[3]; - for(i=0;i<3;i++)dm[i] = (1.0 - dp[i]); - dv = 0.0; - dv += VINDEX(0,0,0) * (dm[0]*dm[1]*dm[2]); - dv += VINDEX(0,0,1) * (dm[0]*dm[1]*dp[2]); - dv += VINDEX(0,1,0) * (dm[0]*dp[1]*dm[2]); - dv += VINDEX(0,1,1) * (dm[0]*dp[1]*dp[2]); - dv += VINDEX(1,0,0) * (dp[0]*dm[1]*dm[2]); - dv += VINDEX(1,0,1) * (dp[0]*dm[1]*dp[2]); - dv += VINDEX(1,1,0) * (dp[0]*dp[1]*dm[2]); - dv += VINDEX(1,1,1) * (dp[0]*dp[1]*dp[2]); - /*assert(dv < -20);*/ - return dv; -} - -npy_float64 offset_interpolate(int ds[3], npy_float64 dp[3], npy_float64 *data) -{ - int i; - npy_float64 dv, vz[4]; - - dv = 1.0 - dp[2]; - vz[0] = dv*OINDEX(0,0,0) + dp[2]*OINDEX(0,0,1); - vz[1] = dv*OINDEX(0,1,0) + dp[2]*OINDEX(0,1,1); - vz[2] = dv*OINDEX(1,0,0) + dp[2]*OINDEX(1,0,1); - vz[3] = dv*OINDEX(1,1,0) + dp[2]*OINDEX(1,1,1); - - dv = 1.0 - dp[1]; - vz[0] = dv*vz[0] + dp[1]*vz[1]; - vz[1] = dv*vz[2] + dp[1]*vz[3]; - - dv = 1.0 - dp[0]; - vz[0] = dv*vz[0] + dp[0]*vz[1]; - - return vz[0]; -} - -npy_float64 trilinear_interpolate(int ds[3], int ci[3], npy_float64 dp[3], - npy_float64 *data) -{ - /* dims is one less than the dimensions of the array */ - int i; - npy_float64 dm[3], vz[4]; - //dp is the distance to the plane. dm is val, dp = 1-val - for(i=0;i<3;i++)dm[i] = (1.0 - dp[i]); - - //First interpolate in z - vz[0] = dm[2]*VINDEX(0,0,0) + dp[2]*VINDEX(0,0,1); - vz[1] = dm[2]*VINDEX(0,1,0) + dp[2]*VINDEX(0,1,1); - vz[2] = dm[2]*VINDEX(1,0,0) + dp[2]*VINDEX(1,0,1); - vz[3] = dm[2]*VINDEX(1,1,0) + dp[2]*VINDEX(1,1,1); - - //Then in y - vz[0] = dm[1]*vz[0] + dp[1]*vz[1]; - vz[1] = dm[1]*vz[2] + dp[1]*vz[3]; - - //Then in x - vz[0] = dm[0]*vz[0] + dp[0]*vz[1]; - /*assert(dv < -20);*/ - return vz[0]; -} - -npy_float64 eval_gradient(int *ds, int *ci, npy_float64 *dp, - npy_float64 *data, npy_float64 *grad) -{ - // We just take some small value - - int i; - npy_float64 denom, plus, minus, backup, normval; - - normval = 0.0; - for (i = 0; i < 3; i++) { - backup = dp[i]; - grad[i] = 0.0; - if (dp[i] >= 0.95) {plus = dp[i]; minus = dp[i] - 0.05;} - else if (dp[i] <= 0.05) {plus = dp[i] + 0.05; minus = 0.0;} - else {plus = dp[i] + 0.05; minus = dp[i] - 0.05;} - //fprintf(stderr, "DIM: %d %0.3lf %0.3lf\n", i, plus, minus); - denom = plus - minus; - dp[i] = plus; - grad[i] += trilinear_interpolate(ds, ci, dp, data) / denom; - dp[i] = minus; - grad[i] -= trilinear_interpolate(ds, ci, dp, data) / denom; - dp[i] = backup; - normval += grad[i]*grad[i]; - } - if (normval != 0.0){ - normval = sqrt(normval); - for (i = 0; i < 3; i++) grad[i] /= -normval; - //fprintf(stderr, "Normval: %0.3lf %0.3lf %0.3lf %0.3lf\n", - // normval, grad[0], grad[1], grad[2]); - }else{ - grad[0]=grad[1]=grad[2]=0.0; - } -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/FixedInterpolator.h --- a/yt/_amr_utils/FixedInterpolator.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/************************************************************************ -* Copyright (C) 2009 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 . -* -************************************************************************/ - - -// -// A small, tiny, itty bitty module for computation-intensive interpolation -// that I can't seem to make fast in Cython -// - -#include "Python.h" - -#include -#include -#include -#include - -#include "numpy/ndarrayobject.h" - -npy_float64 fast_interpolate(int ds[3], int ci[3], npy_float64 dp[3], - npy_float64 *data); - -npy_float64 offset_interpolate(int ds[3], npy_float64 dp[3], npy_float64 *data); - -npy_float64 trilinear_interpolate(int ds[3], int ci[3], npy_float64 dp[3], - npy_float64 *data); - -npy_float64 eval_gradient(int ds[3], int ci[3], npy_float64 dp[3], - npy_float64 *data, npy_float64 *grad); diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/Interpolators.pyx --- a/yt/_amr_utils/Interpolators.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -""" -Simple interpolators - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008 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 . -""" - -import numpy as np -cimport numpy as np -cimport cython - -@cython.boundscheck(False) -def UnilinearlyInterpolate(np.ndarray[np.float64_t, ndim=1] table, - np.ndarray[np.float64_t, ndim=1] x_vals, - np.ndarray[np.float64_t, ndim=1] x_bins, - np.ndarray[np.int32_t, ndim=1] x_is, - np.ndarray[np.float64_t, ndim=1] output): - cdef double x, xp, xm - cdef int i, x_i, y_i - for i in range(x_vals.shape[0]): - x_i = x_is[i] - x = x_vals[i] - dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - xp = (x - x_bins[x_i]) * dx_inv - xm = (x_bins[x_i+1] - x) * dx_inv - output[i] = table[x_i ] * (xm) \ - + table[x_i+1] * (xp) - -@cython.boundscheck(False) -def BilinearlyInterpolate(np.ndarray[np.float64_t, ndim=2] table, - np.ndarray[np.float64_t, ndim=1] x_vals, - np.ndarray[np.float64_t, ndim=1] y_vals, - np.ndarray[np.float64_t, ndim=1] x_bins, - np.ndarray[np.float64_t, ndim=1] y_bins, - np.ndarray[np.int32_t, ndim=1] x_is, - np.ndarray[np.int32_t, ndim=1] y_is, - np.ndarray[np.float64_t, ndim=1] output): - cdef double x, xp, xm - cdef double y, yp, ym - cdef double dx_inv, dy_inv - cdef int i, x_i, y_i - for i in range(x_vals.shape[0]): - x_i = x_is[i] - y_i = y_is[i] - x = x_vals[i] - y = y_vals[i] - dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - xp = (x - x_bins[x_i]) * dx_inv - yp = (y - y_bins[y_i]) * dy_inv - xm = (x_bins[x_i+1] - x) * dx_inv - ym = (y_bins[y_i+1] - y) * dy_inv - output[i] = table[x_i , y_i ] * (xm*ym) \ - + table[x_i+1, y_i ] * (xp*ym) \ - + table[x_i , y_i+1] * (xm*yp) \ - + table[x_i+1, y_i+1] * (xp*yp) - -@cython.boundscheck(False) -def TrilinearlyInterpolate(np.ndarray[np.float64_t, ndim=3] table, - np.ndarray[np.float64_t, ndim=1] x_vals, - np.ndarray[np.float64_t, ndim=1] y_vals, - np.ndarray[np.float64_t, ndim=1] z_vals, - np.ndarray[np.float64_t, ndim=1] x_bins, - np.ndarray[np.float64_t, ndim=1] y_bins, - np.ndarray[np.float64_t, ndim=1] z_bins, - np.ndarray[np.int_t, ndim=1] x_is, - np.ndarray[np.int_t, ndim=1] y_is, - np.ndarray[np.int_t, ndim=1] z_is, - np.ndarray[np.float64_t, ndim=1] output): - cdef double x, xp, xm - cdef double y, yp, ym - cdef double z, zp, zm - cdef double dx_inv, dy_inv, dz_inv - cdef int i, x_i, y_i, z_i - for i in range(x_vals.shape[0]): - x_i = x_is[i] - y_i = y_is[i] - z_i = z_is[i] - x = x_vals[i] - y = y_vals[i] - z = z_vals[i] - dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - dz_inv = 1.0 / (z_bins[z_i+1] - z_bins[z_i]) - xp = (x - x_bins[x_i]) * dx_inv - yp = (y - y_bins[y_i]) * dy_inv - zp = (z - z_bins[z_i]) * dz_inv - xm = (x_bins[x_i+1] - x) * dx_inv - ym = (y_bins[y_i+1] - y) * dy_inv - zm = (z_bins[z_i+1] - z) * dz_inv - output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ - + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ - + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ - + table[x_i ,y_i ,z_i+1] * (xm*ym*zp) \ - + table[x_i+1,y_i ,z_i+1] * (xp*ym*zp) \ - + table[x_i ,y_i+1,z_i+1] * (xm*yp*zp) \ - + table[x_i+1,y_i+1,z_i ] * (xp*yp*zm) \ - + table[x_i+1,y_i+1,z_i+1] * (xp*yp*zp) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/Octree.pyx --- a/yt/_amr_utils/Octree.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,280 +0,0 @@ -""" -A refine-by-two AMR-specific octree - -Author: Matthew Turk -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 . -""" - - -import numpy as np -cimport numpy as np -# Double up here for def'd functions -cimport numpy as cnp -cimport cython - -from stdlib cimport malloc, free, abs - -cdef extern from "stdlib.h": - # NOTE that size_t might not be int - void *alloca(int) - -cdef struct OctreeNode: - np.float64_t *val - np.float64_t weight_val - np.int64_t pos[3] - int level - int nvals - OctreeNode *children[2][2][2] - -cdef void OTN_add_value(OctreeNode *self, - np.float64_t *val, np.float64_t weight_val): - cdef int i - for i in range(self.nvals): - self.val[i] += val[i] - self.weight_val += weight_val - -cdef void OTN_refine(OctreeNode *self): - cdef int i, j, i1, j1 - cdef np.int64_t npos[3] - cdef OctreeNode *node - for i in range(2): - npos[0] = self.pos[0] * 2 + i - for j in range(2): - npos[1] = self.pos[1] * 2 + j - # We have to be careful with allocation... - for k in range(2): - npos[2] = self.pos[2] * 2 + k - self.children[i][j][k] = OTN_initialize( - npos, - self.nvals, self.val, self.weight_val, - self.level + 1) - for i in range(self.nvals): self.val[i] = 0.0 - self.weight_val = 0.0 - -cdef OctreeNode *OTN_initialize(np.int64_t pos[3], int nvals, - np.float64_t *val, np.float64_t weight_val, - int level): - cdef OctreeNode *node - cdef int i, j - node = malloc(sizeof(OctreeNode)) - node.pos[0] = pos[0] - node.pos[1] = pos[1] - node.pos[2] = pos[2] - node.nvals = nvals - node.val = malloc( - nvals * sizeof(np.float64_t)) - for i in range(nvals): - node.val[i] = val[i] - node.weight_val = weight_val - for i in range(2): - for j in range(2): - for k in range(2): - node.children[i][j][k] = NULL - node.level = level - return node - -cdef void OTN_free(OctreeNode *node): - cdef int i, j - for i in range(2): - for j in range(2): - for k in range(2): - if node.children[i][j][k] == NULL: continue - OTN_free(node.children[i][j][k]) - free(node.val) - free(node) - -cdef class Octree: - cdef int nvals - cdef np.int64_t po2[80] - cdef OctreeNode ****root_nodes - cdef np.int64_t top_grid_dims[3] - - def __cinit__(self, np.ndarray[np.int64_t, ndim=1] top_grid_dims, - int nvals): - cdef int i, j - cdef OctreeNode *node - cdef np.int64_t pos[3] - cdef np.float64_t *vals = alloca( - sizeof(np.float64_t)*nvals) - cdef np.float64_t weight_val = 0.0 - self.nvals = nvals - for i in range(nvals): vals[i] = 0.0 - - self.top_grid_dims[0] = top_grid_dims[0] - self.top_grid_dims[1] = top_grid_dims[1] - self.top_grid_dims[2] = top_grid_dims[2] - - # This wouldn't be necessary if we did bitshifting... - for i in range(80): - self.po2[i] = 2**i - # Cython doesn't seem to like sizeof(OctreeNode ***) - self.root_nodes = \ - malloc(sizeof(void*) * top_grid_dims[0]) - - # We initialize our root values to 0.0. - for i in range(top_grid_dims[0]): - pos[0] = i - self.root_nodes[i] = \ - malloc(sizeof(OctreeNode **) * top_grid_dims[1]) - for j in range(top_grid_dims[1]): - pos[1] = j - self.root_nodes[i][j] = \ - malloc(sizeof(OctreeNode *) * top_grid_dims[1]) - for k in range(top_grid_dims[2]): - pos[2] = k - self.root_nodes[i][j][k] = OTN_initialize( - pos, nvals, vals, weight_val, 0) - - cdef void add_to_position(self, - int level, np.int64_t pos[3], - np.float64_t *val, - np.float64_t weight_val): - cdef int i, j - cdef OctreeNode *node - node = self.find_on_root_level(pos, level) - cdef np.int64_t fac - for L in range(level): - if node.children[0][0][0] == NULL: - OTN_refine(node) - # Maybe we should use bitwise operators? - fac = self.po2[level - L - 1] - i = (pos[0] >= fac*(2*node.pos[0]+1)) - j = (pos[1] >= fac*(2*node.pos[1]+1)) - k = (pos[2] >= fac*(2*node.pos[2]+1)) - node = node.children[i][j][k] - OTN_add_value(node, val, weight_val) - - cdef OctreeNode *find_on_root_level(self, np.int64_t pos[3], int level): - # We need this because the root level won't just have four children - # So we find on the root level, then we traverse the tree. - cdef np.int64_t i, j - i = (pos[0] / self.po2[level]) - j = (pos[1] / self.po2[level]) - k = (pos[2] / self.po2[level]) - return self.root_nodes[i][j][k] - - - @cython.boundscheck(False) - @cython.wraparound(False) - def add_array_to_tree(self, int level, - np.ndarray[np.int64_t, ndim=1] pxs, - np.ndarray[np.int64_t, ndim=1] pys, - np.ndarray[np.int64_t, ndim=1] pzs, - np.ndarray[np.float64_t, ndim=2] pvals, - np.ndarray[np.float64_t, ndim=1] pweight_vals): - cdef int np = pxs.shape[0] - cdef int p - cdef cnp.float64_t *vals - cdef cnp.float64_t *data = pvals.data - cdef cnp.int64_t pos[3] - for p in range(np): - vals = data + self.nvals*p - pos[0] = pxs[p] - pos[1] = pys[p] - pos[2] = pzs[p] - self.add_to_position(level, pos, vals, pweight_vals[p]) - - def add_grid_to_tree(self, int level, - np.ndarray[np.int64_t, ndim=1] start_index, - np.ndarray[np.float64_t, ndim=2] pvals, - np.ndarray[np.float64_t, ndim=2] wvals, - np.ndarray[np.int32_t, ndim=2] cm): - pass - - @cython.boundscheck(False) - @cython.wraparound(False) - def get_all_from_level(self, int level, int count_only = 0): - cdef int i, j - cdef int total = 0 - vals = [] - for i in range(self.top_grid_dims[0]): - for j in range(self.top_grid_dims[1]): - for k in range(self.top_grid_dims[2]): - total += self.count_at_level(self.root_nodes[i][j][k], level) - if count_only: return total - # Allocate our array - cdef np.ndarray[np.int64_t, ndim=2] npos - cdef np.ndarray[np.float64_t, ndim=2] nvals - cdef np.ndarray[np.float64_t, ndim=1] nwvals - npos = np.zeros( (total, 2), dtype='int64') - nvals = np.zeros( (total, self.nvals), dtype='float64') - nwvals = np.zeros( total, dtype='float64') - cdef np.int64_t curpos = 0 - cdef np.int64_t *pdata = npos.data - cdef np.float64_t *vdata = nvals.data - cdef np.float64_t *wdata = nwvals.data - for i in range(self.top_grid_dims[0]): - for j in range(self.top_grid_dims[1]): - for k in range(self.top_grid_dims[2]): - curpos += self.fill_from_level(self.root_nodes[i][j][k], - level, curpos, pdata, vdata, wdata) - return npos, nvals, nwvals - - cdef int count_at_level(self, OctreeNode *node, int level): - cdef int i, j - # We only really return a non-zero, calculated value if we are at the - # level in question. - if node.level == level: - # We return 1 if there are no finer points at this level and zero - # if there are - return (node.children[0][0][0] == NULL) - if node.children[0][0][0] == NULL: return 0 - cdef int count = 0 - for i in range(2): - for j in range(2): - for k in range(2): - count += self.count_at_level(node.children[i][j][k], level) - return count - - cdef int fill_from_level(self, OctreeNode *node, int level, - np.int64_t curpos, - np.int64_t *pdata, - np.float64_t *vdata, - np.float64_t *wdata): - cdef int i, j - if node.level == level: - if node.children[0][0][0] != NULL: return 0 - for i in range(self.nvals): - vdata[self.nvals * curpos + i] = node.val[i] - wdata[curpos] = node.weight_val - pdata[curpos * 3] = node.pos[0] - pdata[curpos * 3 + 1] = node.pos[1] - pdata[curpos * 3 + 2] = node.pos[2] - return 1 - if node.children[0][0] == NULL: return 0 - cdef np.int64_t added = 0 - for i in range(2): - for j in range(2): - for k in range(2): - added += self.fill_from_level(node.children[i][j][k], - level, curpos + added, pdata, vdata, wdata) - return added - - def __dealloc__(self): - cdef int i, j - for i in range(self.top_grid_dims[0]): - for j in range(self.top_grid_dims[1]): - for k in range(self.top_grid_dims[2]): - OTN_free(self.root_nodes[i][j][k]) - free(self.root_nodes[i][j]) - free(self.root_nodes[i]) - free(self.root_nodes) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/PointsInVolume.pyx --- a/yt/_amr_utils/PointsInVolume.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,217 +0,0 @@ -""" -Checks for points contained in a volume - -Author: John Wise -Affiliation: Princeton -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 John. 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 . -""" - - -import numpy as np -cimport numpy as np -cimport cython - -cdef extern from "math.h": - double fabs(double x) - -@cython.wraparound(False) -@cython.boundscheck(False) -def planar_points_in_volume( - np.ndarray[np.float64_t, ndim=2] points, - np.ndarray[np.int8_t, ndim=1] pmask, # pixel mask - np.ndarray[np.float64_t, ndim=1] left_edge, - np.ndarray[np.float64_t, ndim=1] right_edge, - np.ndarray[np.int32_t, ndim=3] mask, - float dx): - cdef np.ndarray[np.int8_t, ndim=1] \ - valid = np.zeros(points.shape[0], dtype='int8') - cdef int i, dim, count - cdef int ex - cdef double dx_inv - cdef unsigned int idx[3] - count = 0 - dx_inv = 1.0 / dx - for i in xrange(points.shape[0]): - if pmask[i] == 0: - continue - ex = 1 - for dim in xrange(3): - if points[i,dim] < left_edge[dim] or points[i,dim] > right_edge[dim]: - valid[i] = ex = 0 - break - if ex == 1: - for dim in xrange(3): - idx[dim] = \ - ((points[i,dim] - left_edge[dim]) * dx_inv) - if mask[idx[0], idx[1], idx[2]] == 1: - valid[i] = 1 - count += 1 - - cdef np.ndarray[np.int32_t, ndim=1] result = np.empty(count, dtype='int32') - count = 0 - for i in xrange(points.shape[0]): - if valid[i] == 1 and pmask[i] == 1: - result[count] = i - count += 1 - - return result - -cdef inline void set_rotated_pos( - np.float64_t cp[3], np.float64_t rdds[3][3], - np.float64_t rorigin[3], int i, int j, int k): - cdef int oi - for oi in range(3): - cp[oi] = rdds[0][oi] * (0.5 + i) \ - + rdds[1][oi] * (0.5 + j) \ - + rdds[2][oi] * (0.5 + k) \ - + rorigin[oi] - -#@cython.wraparound(False) -#@cython.boundscheck(False) -def grid_points_in_volume( - np.ndarray[np.float64_t, ndim=1] box_lengths, - np.ndarray[np.float64_t, ndim=1] box_origin, - np.ndarray[np.float64_t, ndim=2] rot_mat, - np.ndarray[np.float64_t, ndim=1] grid_left_edge, - np.ndarray[np.float64_t, ndim=1] grid_right_edge, - np.ndarray[np.float64_t, ndim=1] dds, - np.ndarray[np.int32_t, ndim=3] mask, - int break_first): - cdef int n[3], i, j, k, ax - cdef np.float64_t rds[3][3], cur_pos[3], rorigin[3] - for i in range(3): - rorigin[i] = 0.0 - for i in range(3): - n[i] = mask.shape[i] - for j in range(3): - # Set up our transposed dx, which has a component in every - # direction - rds[i][j] = dds[i] * rot_mat[j,i] - # In our rotated coordinate system, the box origin is 0,0,0 - # so we subtract the box_origin from the grid_origin and rotate - # that - rorigin[j] += (grid_left_edge[i] - box_origin[i]) * rot_mat[j,i] - - for i in range(n[0]): - for j in range(n[1]): - for k in range(n[2]): - set_rotated_pos(cur_pos, rds, rorigin, i, j, k) - if (cur_pos[0] > box_lengths[0]): continue - if (cur_pos[1] > box_lengths[1]): continue - if (cur_pos[2] > box_lengths[2]): continue - if (cur_pos[0] < 0.0): continue - if (cur_pos[1] < 0.0): continue - if (cur_pos[2] < 0.0): continue - if break_first: - if mask[i,j,k]: return 1 - else: - mask[i,j,k] = 1 - return 0 - -cdef void normalize_vector(np.float64_t vec[3]): - cdef int i - cdef np.float64_t norm = 0.0 - for i in range(3): - norm += vec[i]*vec[i] - norm = norm**0.5 - for i in range(3): - vec[i] /= norm - -cdef void get_cross_product(np.float64_t v1[3], - np.float64_t v2[3], - np.float64_t cp[3]): - cp[0] = v1[1]*v2[2] - v1[2]*v2[1] - cp[1] = v1[3]*v2[0] - v1[0]*v2[3] - cp[2] = v1[0]*v2[1] - v1[1]*v2[0] - #print cp[0], cp[1], cp[2] - -cdef int check_projected_overlap( - np.float64_t sep_ax[3], np.float64_t sep_vec[3], int gi, - np.float64_t b_vec[3][3], np.float64_t g_vec[3][3]): - cdef int g_ax, b_ax - cdef np.float64_t tba, tga, ba, ga, sep_dot - ba = ga = sep_dot = 0.0 - for g_ax in range(3): - # We need the grid vectors, which we'll precompute here - tba = tga = 0.0 - for b_ax in range(3): - tba += b_vec[g_ax][b_ax] * sep_vec[b_ax] - tga += g_vec[g_ax][b_ax] * sep_vec[b_ax] - ba += fabs(tba) - ga += fabs(tga) - sep_dot += sep_vec[g_ax] * sep_ax[g_ax] - #print sep_vec[0], sep_vec[1], sep_vec[2], - #print sep_ax[0], sep_ax[1], sep_ax[2] - return (fabs(sep_dot) > ba+ga) - # Now we do - -@cython.wraparound(False) -@cython.boundscheck(False) -def find_grids_in_inclined_box( - np.ndarray[np.float64_t, ndim=2] box_vectors, - np.ndarray[np.float64_t, ndim=1] box_center, - np.ndarray[np.float64_t, ndim=2] grid_left_edges, - np.ndarray[np.float64_t, ndim=2] grid_right_edges): - - # http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php?page=5 - cdef int n = grid_right_edges.shape[0] - cdef int g_ax, b_ax, gi - cdef np.float64_t b_vec[3][3], g_vec[3][3], a_vec[3][3], sep_ax[15][3] - cdef np.float64_t sep_vec[3], norm - cdef np.ndarray[np.int32_t, ndim=1] good = np.zeros(n, dtype='int32') - cdef np.ndarray[np.float64_t, ndim=2] grid_centers - # Fill in our axis unit vectors - for b_ax in range(3): - for g_ax in range(3): - a_vec[b_ax][g_ax] = (b_ax == g_ax) - grid_centers = (grid_right_edges + grid_left_edges)/2.0 - - # Now we pre-compute our candidate separating axes, because the unit - # vectors for all the grids are identical - for b_ax in range(3): - # We have 6 principal axes we already know, which are the grid (domain) - # principal axes and the box axes - sep_ax[b_ax][0] = sep_ax[b_ax][1] = sep_ax[b_ax][2] = 0.0 - sep_ax[b_ax][b_ax] = 1.0 # delta_ijk, for grid axes - for g_ax in range(3): - b_vec[b_ax][g_ax] = 0.5*box_vectors[b_ax,g_ax] - sep_ax[b_ax + 3][g_ax] = b_vec[b_ax][g_ax] # box axes - normalize_vector(sep_ax[b_ax + 3]) - for g_ax in range(3): - get_cross_product(b_vec[b_ax], a_vec[g_ax], sep_ax[b_ax*3 + g_ax + 6]) - normalize_vector(sep_ax[b_ax*3 + g_ax + 6]) - - for gi in range(n): - for g_ax in range(3): - # Calculate the separation vector - sep_vec[g_ax] = grid_centers[gi, g_ax] - box_center[g_ax] - # Calculate the grid axis lengths - g_vec[g_ax][0] = g_vec[g_ax][1] = g_vec[g_ax][2] = 0.0 - g_vec[g_ax][g_ax] = 0.5 * (grid_right_edges[gi, g_ax] - - grid_left_edges[gi, g_ax]) - for b_ax in range(15): - #print b_ax, - if check_projected_overlap( - sep_ax[b_ax], sep_vec, gi, - b_vec, g_vec): - good[gi] = 1 - break - return good - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/QuadTree.pyx --- a/yt/_amr_utils/QuadTree.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,257 +0,0 @@ -""" -A refine-by-two AMR-specific quadtree - -Author: Matthew Turk -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 . -""" - - -import numpy as np -cimport numpy as np -# Double up here for def'd functions -cimport numpy as cnp -cimport cython - -from stdlib cimport malloc, free, abs - -cdef extern from "stdlib.h": - # NOTE that size_t might not be int - void *alloca(int) - -cdef struct QuadTreeNode: - np.float64_t *val - np.float64_t weight_val - np.int64_t pos[2] - int level - int nvals - QuadTreeNode *children[2][2] - -cdef void QTN_add_value(QuadTreeNode *self, - np.float64_t *val, np.float64_t weight_val): - cdef int i - for i in range(self.nvals): - self.val[i] += val[i] - self.weight_val += weight_val - -cdef void QTN_refine(QuadTreeNode *self): - cdef int i, j, i1, j1 - cdef np.int64_t npos[2] - cdef QuadTreeNode *node - for i in range(2): - npos[0] = self.pos[0] * 2 + i - for j in range(2): - npos[1] = self.pos[1] * 2 + j - # We have to be careful with allocation... - self.children[i][j] = QTN_initialize( - npos, - self.nvals, self.val, self.weight_val, - self.level + 1) - for i in range(self.nvals): self.val[i] = 0.0 - self.weight_val = 0.0 - -cdef QuadTreeNode *QTN_initialize(np.int64_t pos[2], int nvals, - np.float64_t *val, np.float64_t weight_val, - int level): - cdef QuadTreeNode *node - cdef int i, j - node = malloc(sizeof(QuadTreeNode)) - node.pos[0] = pos[0] - node.pos[1] = pos[1] - node.nvals = nvals - node.val = malloc( - nvals * sizeof(np.float64_t)) - for i in range(nvals): - node.val[i] = val[i] - node.weight_val = weight_val - for i in range(2): - for j in range(2): - node.children[i][j] = NULL - node.level = level - return node - -cdef void QTN_free(QuadTreeNode *node): - cdef int i, j - for i in range(2): - for j in range(2): - if node.children[i][j] == NULL: continue - QTN_free(node.children[i][j]) - free(node.val) - free(node) - -cdef class QuadTree: - cdef int nvals - cdef np.int64_t po2[80] - cdef QuadTreeNode ***root_nodes - cdef np.int64_t top_grid_dims[2] - - def __cinit__(self, np.ndarray[np.int64_t, ndim=1] top_grid_dims, - int nvals): - cdef int i, j - cdef QuadTreeNode *node - cdef np.int64_t pos[2] - cdef np.float64_t *vals = alloca( - sizeof(np.float64_t)*nvals) - cdef np.float64_t weight_val = 0.0 - self.nvals = nvals - for i in range(nvals): vals[i] = 0.0 - - self.top_grid_dims[0] = top_grid_dims[0] - self.top_grid_dims[1] = top_grid_dims[1] - - # This wouldn't be necessary if we did bitshifting... - for i in range(80): - self.po2[i] = 2**i - self.root_nodes = \ - malloc(sizeof(QuadTreeNode **) * top_grid_dims[0]) - - # We initialize our root values to 0.0. - for i in range(top_grid_dims[0]): - pos[0] = i - self.root_nodes[i] = \ - malloc(sizeof(QuadTreeNode *) * top_grid_dims[1]) - for j in range(top_grid_dims[1]): - pos[1] = j - self.root_nodes[i][j] = QTN_initialize( - pos, nvals, vals, weight_val, 0) - - cdef void add_to_position(self, - int level, np.int64_t pos[2], - np.float64_t *val, - np.float64_t weight_val): - cdef int i, j - cdef QuadTreeNode *node - node = self.find_on_root_level(pos, level) - cdef np.int64_t fac - for L in range(level): - if node.children[0][0] == NULL: - QTN_refine(node) - # Maybe we should use bitwise operators? - fac = self.po2[level - L - 1] - i = (pos[0] >= fac*(2*node.pos[0]+1)) - j = (pos[1] >= fac*(2*node.pos[1]+1)) - node = node.children[i][j] - QTN_add_value(node, val, weight_val) - - cdef QuadTreeNode *find_on_root_level(self, np.int64_t pos[2], int level): - # We need this because the root level won't just have four children - # So we find on the root level, then we traverse the tree. - cdef np.int64_t i, j - i = (pos[0] / self.po2[level]) - j = (pos[1] / self.po2[level]) - return self.root_nodes[i][j] - - - @cython.boundscheck(False) - @cython.wraparound(False) - def add_array_to_tree(self, int level, - np.ndarray[np.int64_t, ndim=1] pxs, - np.ndarray[np.int64_t, ndim=1] pys, - np.ndarray[np.float64_t, ndim=2] pvals, - np.ndarray[np.float64_t, ndim=1] pweight_vals): - cdef int np = pxs.shape[0] - cdef int p - cdef cnp.float64_t *vals - cdef cnp.float64_t *data = pvals.data - cdef cnp.int64_t pos[2] - for p in range(np): - vals = data + self.nvals*p - pos[0] = pxs[p] - pos[1] = pys[p] - self.add_to_position(level, pos, vals, pweight_vals[p]) - - def add_grid_to_tree(self, int level, - np.ndarray[np.int64_t, ndim=1] start_index, - np.ndarray[np.float64_t, ndim=2] pvals, - np.ndarray[np.float64_t, ndim=2] wvals, - np.ndarray[np.int32_t, ndim=2] cm): - pass - - @cython.boundscheck(False) - @cython.wraparound(False) - def get_all_from_level(self, int level, int count_only = 0): - cdef int i, j - cdef int total = 0 - vals = [] - for i in range(self.top_grid_dims[0]): - for j in range(self.top_grid_dims[1]): - total += self.count_at_level(self.root_nodes[i][j], level) - if count_only: return total - # Allocate our array - cdef np.ndarray[np.int64_t, ndim=2] npos - cdef np.ndarray[np.float64_t, ndim=2] nvals - cdef np.ndarray[np.float64_t, ndim=1] nwvals - npos = np.zeros( (total, 2), dtype='int64') - nvals = np.zeros( (total, self.nvals), dtype='float64') - nwvals = np.zeros( total, dtype='float64') - cdef np.int64_t curpos = 0 - cdef np.int64_t *pdata = npos.data - cdef np.float64_t *vdata = nvals.data - cdef np.float64_t *wdata = nwvals.data - for i in range(self.top_grid_dims[0]): - for j in range(self.top_grid_dims[1]): - curpos += self.fill_from_level(self.root_nodes[i][j], - level, curpos, pdata, vdata, wdata) - return npos, nvals, nwvals - - cdef int count_at_level(self, QuadTreeNode *node, int level): - cdef int i, j - # We only really return a non-zero, calculated value if we are at the - # level in question. - if node.level == level: - # We return 1 if there are no finer points at this level and zero - # if there are - return (node.children[0][0] == NULL) - if node.children[0][0] == NULL: return 0 - cdef int count = 0 - for i in range(2): - for j in range(2): - count += self.count_at_level(node.children[i][j], level) - return count - - cdef int fill_from_level(self, QuadTreeNode *node, int level, - np.int64_t curpos, - np.int64_t *pdata, - np.float64_t *vdata, - np.float64_t *wdata): - cdef int i, j - if node.level == level: - if node.children[0][0] != NULL: return 0 - for i in range(self.nvals): - vdata[self.nvals * curpos + i] = node.val[i] - wdata[curpos] = node.weight_val - pdata[curpos * 2] = node.pos[0] - pdata[curpos * 2 + 1] = node.pos[1] - return 1 - if node.children[0][0] == NULL: return 0 - cdef np.int64_t added = 0 - for i in range(2): - for j in range(2): - added += self.fill_from_level(node.children[i][j], - level, curpos + added, pdata, vdata, wdata) - return added - - def __dealloc__(self): - cdef int i, j - for i in range(self.top_grid_dims[0]): - for j in range(self.top_grid_dims[1]): - QTN_free(self.root_nodes[i][j]) - free(self.root_nodes[i]) - free(self.root_nodes) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/RayIntegrators.pyx --- a/yt/_amr_utils/RayIntegrators.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,374 +0,0 @@ -""" -Simle integrators for the radiative transfer equation - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008 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 . -""" - -import numpy as np -cimport numpy as np -cimport cython -from stdlib cimport malloc, free, abs - -cdef extern from "math.h": - double exp(double x) - float expf(float x) - -@cython.boundscheck(False) -def Transfer3D(np.ndarray[np.float64_t, ndim=3] i_s, - np.ndarray[np.float64_t, ndim=4] o_s, - np.ndarray[np.float64_t, ndim=4] e, - np.ndarray[np.float64_t, ndim=4] a, - int imin, int imax, int jmin, int jmax, - int kmin, int kmax, int istride, int jstride, - np.float64_t dx): - """ - This function accepts an incoming slab (*i_s*), a buffer - for an outgoing set of values at every point in the grid (*o_s*), - an emission array (*e*), an absorption array (*a*), and dimensions of - the grid (*imin*, *imax*, *jmin*, *jmax*, *kmin*, *kmax*) as well - as strides in the *i* and *j* directions, and a *dx* of the grid being - integrated. - """ - cdef int i, ii - cdef int j, jj - cdef int k, kk - cdef int n, nn - nn = o_s.shape[3] # This might be slow - cdef np.float64_t *temp = malloc(sizeof(np.float64_t) * nn) - for i in range((imax-imin)*istride): - ii = i + imin*istride - for j in range((jmax-jmin)*jstride): - jj = j + jmin*jstride - # Not sure about the ordering of the loops here - for n in range(nn): - temp[n] = i_s[ii,jj,n] - for k in range(kmax-kmin): - kk = k + kmin#*kstride, which doesn't make any sense - for n in range(nn): - o_s[i,j,k,n] = temp[n] + dx*(e[i,j,k,n] - temp[n]*a[i,j,k,n]) - temp[n] = o_s[i,j,k,n] - for n in range(nn): - i_s[ii,jj,n] = temp[n] - free(temp) - -@cython.boundscheck(False) -def TransferShells(np.ndarray[np.float64_t, ndim=3] i_s, - np.ndarray[np.float64_t, ndim=3] data, - np.ndarray[np.float64_t, ndim=2] shells): - """ - This function accepts an incoming slab (*i_s*), a buffer of *data*, - and a list of shells specified as [ (value, tolerance, r, g, b), ... ]. - """ - cdef int i, ii - cdef int j, jj - cdef int k, kk - cdef int n, nn - cdef np.float64_t dist - ii = data.shape[0] - jj = data.shape[1] - kk = data.shape[2] - nn = shells.shape[0] - cdef float rgba[4] - cdef float alpha - for i in range(ii): - for j in range(jj): - # Not sure about the ordering of the loops here - for k in range(kk): - for n in range(nn): - dist = shells[n, 0] - data[i,j,k] - if dist < 0: dist *= -1.0 - if dist < shells[n,1]: - dist = exp(-dist/8.0) - rgba[0] = shells[n,2] - rgba[1] = shells[n,3] - rgba[2] = shells[n,4] - rgba[3] = shells[n,5] - alpha = i_s[i,j,3] - dist *= dist # This might improve appearance - i_s[i,j,0] += (1.0 - alpha)*rgba[0]*dist*rgba[3] - i_s[i,j,1] += (1.0 - alpha)*rgba[1]*dist*rgba[3] - i_s[i,j,2] += (1.0 - alpha)*rgba[2]*dist*rgba[3] - i_s[i,j,3] += (1.0 - alpha)*rgba[3]*dist*rgba[3] - break - -@cython.boundscheck(False) -def Transfer1D(float i_s, - np.ndarray[np.float_t, ndim=1] o_s, - np.ndarray[np.float_t, ndim=1] e, - np.ndarray[np.float_t, ndim=1] a, - np.ndarray[np.float_t, ndim=1] dx, - int imin, int imax): - cdef int i - for i in range(imin, imax): - o_s[i] = i_s + dx[i]*(e[i] - i_s*a[i]) - i_s = o_s[i] - return i_s - -@cython.wraparound(False) -@cython.boundscheck(False) -def VoxelTraversal(np.ndarray[np.int_t, ndim=3] grid_mask, - np.ndarray[np.float64_t, ndim=3] grid_t, - np.ndarray[np.float64_t, ndim=3] grid_dt, - np.ndarray[np.float64_t, ndim=1] left_edge, - np.ndarray[np.float64_t, ndim=1] right_edge, - np.ndarray[np.float64_t, ndim=1] dx, - np.ndarray[np.float64_t, ndim=1] u, - np.ndarray[np.float64_t, ndim=1] v): - # We're roughly following Amanatides & Woo - # Find the first place the ray hits the grid on its path - # Do left edge then right edge in each dim - cdef int i, x, y - cdef np.float64_t tl, tr, intersect_t, enter_t, exit_t, dt_tolerance - cdef np.ndarray[np.int64_t, ndim=1] step = np.empty((3,), dtype=np.int64) - cdef np.ndarray[np.int64_t, ndim=1] cur_ind = np.empty((3,), dtype=np.int64) - cdef np.ndarray[np.float64_t, ndim=1] tdelta = np.empty((3,), dtype=np.float64) - cdef np.ndarray[np.float64_t, ndim=1] tmax = np.empty((3,), dtype=np.float64) - cdef np.ndarray[np.float64_t, ndim=1] intersect = np.empty((3,), dtype=np.float64) - intersect_t = 1 - dt_tolerance = 1e-6 - # recall p = v * t + u - # where p is position, v is our vector, u is the start point - for i in range(3): - # As long as we're iterating, set some other stuff, too - if(v[i] < 0): step[i] = -1 - else: step[i] = 1 - x = (i+1)%3 - y = (i+2)%3 - tl = (left_edge[i] - u[i])/v[i] - tr = (right_edge[i] - u[i])/v[i] - if (left_edge[x] <= (u[x] + tl*v[x]) <= right_edge[x]) and \ - (left_edge[y] <= (u[y] + tl*v[y]) <= right_edge[y]) and \ - (0.0 <= tl < intersect_t): - intersect_t = tl - if (left_edge[x] <= (u[x] + tr*v[x]) <= right_edge[x]) and \ - (left_edge[y] <= (u[y] + tr*v[y]) <= right_edge[y]) and \ - (0.0 <= tr < intersect_t): - intersect_t = tr - # if fully enclosed - if (left_edge[0] <= u[0] <= right_edge[0]) and \ - (left_edge[1] <= u[1] <= right_edge[1]) and \ - (left_edge[2] <= u[2] <= right_edge[2]): - intersect_t = 0.0 - if not (0 <= intersect_t <= 1): return - # Now get the indices of the intersection - intersect = u + intersect_t * v - for i in range(3): - cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - if cur_ind[i] == grid_mask.shape[i] and step[i] < 0: - cur_ind[i] = grid_mask.shape[i] - 1 - if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - tdelta[i] = (dx[i]/v[i]) - if tdelta[i] < 0: tdelta[i] *= -1 - # The variable intersect contains the point we first pierce the grid - enter_t = intersect_t - while 1: - if (not (0 <= cur_ind[0] < grid_mask.shape[0])) or \ - (not (0 <= cur_ind[1] < grid_mask.shape[1])) or \ - (not (0 <= cur_ind[2] < grid_mask.shape[2])): - break - # Note that we are calculating t on the fly, but we get *negative* t - # values from what they should be. - # If we've reached t = 1, we are done. - grid_mask[cur_ind[0], cur_ind[1], cur_ind[2]] = 1 - if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = 1.0 - enter_t - break - if tmax[0] < tmax[1]: - if tmax[0] < tmax[2]: - grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[0] - enter_t - enter_t = tmax[0] - tmax[0] += tdelta[0] - cur_ind[0] += step[0] - else: - grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - enter_t = tmax[2] - tmax[2] += tdelta[2] - cur_ind[2] += step[2] - else: - if tmax[1] < tmax[2]: - grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[1] - enter_t - enter_t = tmax[1] - tmax[1] += tdelta[1] - cur_ind[1] += step[1] - else: - grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - enter_t = tmax[2] - tmax[2] += tdelta[2] - cur_ind[2] += step[2] - return - -@cython.wraparound(False) -@cython.boundscheck(False) -def PlaneVoxelIntegration(np.ndarray[np.float64_t, ndim=1] left_edge, - np.ndarray[np.float64_t, ndim=1] right_edge, - np.ndarray[np.float64_t, ndim=1] dx, - np.ndarray[np.float64_t, ndim=2] ug, - np.ndarray[np.float64_t, ndim=1] v, - np.ndarray[np.float64_t, ndim=2] image, - np.ndarray[np.float64_t, ndim=3] data, - np.ndarray[np.float64_t, ndim=2] shells): - # We're roughly following Amanatides & Woo on a ray-by-ray basis - # Note that for now it's just shells, but this can and should be - # generalized to transfer functions - cdef int i, x, y, vi - intersect_t = 1 - dt_tolerance = 1e-6 - cdef int nv = ug.shape[0] - cdef int nshells = shells.shape[0] - cdef np.ndarray[np.float64_t, ndim=1] u = np.empty((3,), dtype=np.float64) - # Copy things into temporary location for passing between functions - for vi in range(nv): - for i in range(3): u[i] = ug[vi, i] - integrate_ray(u, v, left_edge, right_edge, dx, - nshells, vi, data, shells, image) - -@cython.wraparound(False) -@cython.boundscheck(False) -def integrate_ray(np.ndarray[np.float64_t, ndim=1] u, - np.ndarray[np.float64_t, ndim=1] v, - np.ndarray[np.float64_t, ndim=1] left_edge, - np.ndarray[np.float64_t, ndim=1] right_edge, - np.ndarray[np.float64_t, ndim=1] dx, - int nshells, int ind, - np.ndarray[np.float64_t, ndim=3] data, - np.ndarray[np.float64_t, ndim=2] shells, - np.ndarray[np.float64_t, ndim=2] image): - cdef int step[3], x, y, i, n - cdef np.float64_t intersect_t = 1 - cdef np.float64_t dt_tolerance = 1e-6 - cdef np.float64_t tl, tr, enter_t, exit_t - cdef np.int64_t cur_ind[3] - cdef np.float64_t tdelta[3] - cdef np.float64_t tmax[3] - cdef np.float64_t intersect[3] - cdef np.float64_t dt, dv - cdef np.float64_t dist, alpha - cdef np.float64_t one = 1.0 - cdef int dims[3] - cdef np.float64_t rgba[4], temp_x, temp_y - for i in range(3): - # As long as we're iterating, set some other stuff, too - dims[i] = data.shape[i] - if(v[i] < 0): step[i] = -1 - else: step[i] = 1 - x = (i+1)%3 - y = (i+2)%3 - tl = (left_edge[i] - u[i])/v[i] - tr = (right_edge[i] - u[i])/v[i] - temp_x = (u[x] + tl*v[x]) - temp_y = (u[y] + tl*v[y]) - if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - (0.0 <= tl) and (tl < intersect_t): - intersect_t = tl - temp_x = (u[x] + tr*v[x]) - temp_y = (u[y] + tr*v[y]) - if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - (0.0 <= tr) and (tr < intersect_t): - intersect_t = tr - # if fully enclosed - if (left_edge[0] <= u[0] <= right_edge[0]) and \ - (left_edge[1] <= u[1] <= right_edge[1]) and \ - (left_edge[2] <= u[2] <= right_edge[2]): - intersect_t = 0.0 - if not (0 <= intersect_t <= 1): - #print "Returning: intersect_t ==", intersect_t - return - # Now get the indices of the intersection - for i in range(3): intersect[i] = u[i] + intersect_t * v[i] - cdef int ncells = 0 - for i in range(3): - cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - if cur_ind[i] == dims[i] and step[i] < 0: - cur_ind[i] = dims[i] - 1 - if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - tdelta[i] = (dx[i]/v[i]) - if tdelta[i] < 0: tdelta[i] *= -1 - # The variable intersect contains the point we first pierce the grid - enter_t = intersect_t - if (not (0 <= cur_ind[0] < dims[0])) or \ - (not (0 <= cur_ind[1] < dims[1])) or \ - (not (0 <= cur_ind[2] < dims[2])): - #print "Returning: cur_ind", cur_ind[0], cur_ind[1], cur_ind[2] - #print " dims: ", dims[0], dims[1], dims[2] - #print " intersect:", intersect[0], intersect[1], intersect[2] - #print " intersect:", intersect_t - #print " u :", u[0], u[1], u[2] - # - return - #print cur_ind[0], dims[0], cur_ind[1], dims[1], cur_ind[2], dims[2] - dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] - #dt = 1e300 - while 1: - if image[ind,3] >= 1.0: break - if (not (0 <= cur_ind[0] < dims[0])) or \ - (not (0 <= cur_ind[1] < dims[1])) or \ - (not (0 <= cur_ind[2] < dims[2])): - break - # Do our transfer here - for n in range(nshells): - dist = shells[n, 0] - dv - if dist < shells[n,1]: - dist = exp(-dist/8.0) - alpha = (1.0 - shells[n,5])*shells[n,5]#*dt - image[ind,0] += alpha*shells[n,2]*dist - image[ind,1] += alpha*shells[n,3]*dist - image[ind,2] += alpha*shells[n,4]*dist - image[ind,3] += alpha*shells[n,5]*dist - #image[ind,i] += rgba[i]*dist*rgba[3]/dt - #print rgba[i], image[ind,i], dist, dt - break - if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - dt = 1.0 - enter_t - break - if tmax[0] < tmax[1]: - if tmax[0] < tmax[2]: - dt = tmax[0] - enter_t - enter_t = tmax[0] - tmax[0] += tdelta[0] - cur_ind[0] += step[0] - else: - dt = tmax[2] - enter_t - enter_t = tmax[2] - tmax[2] += tdelta[2] - cur_ind[2] += step[2] - else: - if tmax[1] < tmax[2]: - dt = tmax[1] - enter_t - enter_t = tmax[1] - tmax[1] += tdelta[1] - cur_ind[1] += step[1] - else: - dt = tmax[2] - enter_t - enter_t = tmax[2] - tmax[2] += tdelta[2] - cur_ind[2] += step[2] - dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/VolumeIntegrator.pyx --- a/yt/_amr_utils/VolumeIntegrator.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,656 +0,0 @@ -""" -Simple integrators for the radiative transfer equation - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as np -cimport numpy as np -cimport cython -from stdlib cimport malloc, free, abs - -cdef inline int imax(int i0, int i1): - if i0 > i1: return i0 - return i1 - -cdef inline np.float64_t fmax(np.float64_t f0, np.float64_t f1): - if f0 > f1: return f0 - return f1 - -cdef inline int imin(int i0, int i1): - if i0 < i1: return i0 - return i1 - -cdef inline np.float64_t fmin(np.float64_t f0, np.float64_t f1): - if f0 < f1: return f0 - return f1 - -cdef inline int iclip(int i, int a, int b): - if i < a: return a - if i > b: return b - return i - -cdef inline np.float64_t fclip(np.float64_t f, - np.float64_t a, np.float64_t b): - return fmin(fmax(f, a), b) - -cdef extern from "math.h": - double exp(double x) - float expf(float x) - double floor(double x) - double ceil(double x) - double fmod(double x, double y) - double log2(double x) - long int lrint(double x) - -cdef extern from "FixedInterpolator.h": - np.float64_t fast_interpolate(int ds[3], int ci[3], np.float64_t dp[3], - np.float64_t *data) - np.float64_t offset_interpolate(int ds[3], np.float64_t dp[3], np.float64_t *data) - np.float64_t trilinear_interpolate(int ds[3], int ci[3], np.float64_t dp[3], - np.float64_t *data) - np.float64_t eval_gradient(int *ds, int *ci, np.float64_t *dp, - np.float64_t *data, np.float64_t *grad) - -cdef class VectorPlane - -cdef struct FieldInterpolationTable: - # Note that we make an assumption about retaining a reference to values - # externally. - np.float64_t *values - np.float64_t bounds[2] - np.float64_t dbin - np.float64_t idbin - int field_id - int weight_field_id - int weight_table_id - int nbins - int pass_through - -cdef void FIT_initialize_table(FieldInterpolationTable *fit, int nbins, - np.float64_t *values, np.float64_t bounds1, np.float64_t bounds2, - int field_id, int weight_field_id = -1, int weight_table_id = -1, - int pass_through = 0): - fit.bounds[0] = bounds1; fit.bounds[1] = bounds2 - fit.nbins = nbins - fit.dbin = (fit.bounds[1] - fit.bounds[0])/fit.nbins - fit.idbin = 1.0/fit.dbin - # Better not pull this out from under us, yo - fit.values = values - fit.field_id = field_id - fit.weight_field_id = weight_field_id - fit.weight_table_id = weight_table_id - fit.pass_through = pass_through - -cdef np.float64_t FIT_get_value(FieldInterpolationTable *fit, - np.float64_t *dvs): - cdef np.float64_t bv, dy, dd, tf - cdef int bin_id - if fit.pass_through == 1: return dvs[fit.field_id] - if dvs[fit.field_id] > fit.bounds[1] or dvs[fit.field_id] < fit.bounds[0]: return 0.0 - bin_id = ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin) - dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0 - bv = fit.values[bin_id] - dy = fit.values[bin_id + 1] - bv - if fit.weight_field_id != -1: - return dvs[fit.weight_field_id] * (bv + dd*dy*fit.idbin) - return (bv + dd*dy*fit.idbin) - -cdef class TransferFunctionProxy: - cdef int n_fields - cdef int n_field_tables - cdef public int ns - - # These are the field tables and their affiliated storage. - # We have one field_id for every table. Note that a single field can - # correspond to multiple tables, and each field table will only have - # interpolate called once. - cdef FieldInterpolationTable field_tables[6] - cdef np.float64_t istorage[6] - - # Here are the field tables that correspond to each of the six channels. - # We have three emission channels, three absorption channels. - cdef int field_table_ids[6] - - # We store a reference to the transfer function object and to the field - # interpolation tables - cdef public object tf_obj - cdef public object my_field_tables - - def __cinit__(self, tf_obj): - # We have N fields. We have 6 channels. We have M field tables. - # The idea is that we can have multiple channels corresponding to the - # same field table. So, we create storage for the outputs from all the - # field tables. We need to know which field value to pass in to the - # field table, and we need to know which table to use for each of the - # six channels. - cdef int i - cdef np.ndarray[np.float64_t, ndim=1] temp - cdef FieldInterpolationTable fit - - self.tf_obj = tf_obj - - self.n_field_tables = tf_obj.n_field_tables - for i in range(6): self.istorage[i] = 0.0 - - self.my_field_tables = [] - for i in range(self.n_field_tables): - temp = tf_obj.tables[i].y - FIT_initialize_table(&self.field_tables[i], - temp.shape[0], - temp.data, - tf_obj.tables[i].x_bounds[0], - tf_obj.tables[i].x_bounds[1], - tf_obj.field_ids[i], tf_obj.weight_field_ids[i], - tf_obj.weight_table_ids[i], - tf_obj.tables[i].pass_through) - self.my_field_tables.append((tf_obj.tables[i], - tf_obj.tables[i].y)) - self.field_tables[i].field_id = tf_obj.field_ids[i] - self.field_tables[i].weight_field_id = tf_obj.weight_field_ids[i] - print "Field table", i, "corresponds to", - print self.field_tables[i].field_id, - print "(Weighted with ", self.field_tables[i].weight_field_id, - print ")" - - for i in range(6): - self.field_table_ids[i] = tf_obj.field_table_ids[i] - print "Channel", i, "corresponds to", self.field_table_ids[i] - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef void eval_transfer(self, np.float64_t dt, np.float64_t *dvs, - np.float64_t *rgba, np.float64_t *grad): - cdef int i, fid, use - cdef np.float64_t ta, tf, trgba[6], dot_prod - # NOTE: We now disable this. I have left it to ease the process of - # potentially, one day, re-including it. - #use = 0 - #for i in range(self.n_field_tables): - # fid = self.field_tables[i].field_id - # if (dvs[fid] >= self.field_tables[i].bounds[0]) and \ - # (dvs[fid] <= self.field_tables[i].bounds[1]): - # use = 1 - # break - for i in range(self.n_field_tables): - self.istorage[i] = FIT_get_value(&self.field_tables[i], dvs) - # We have to do this after the interpolation - for i in range(self.n_field_tables): - fid = self.field_tables[i].weight_table_id - if fid != -1: self.istorage[i] *= self.istorage[fid] - for i in range(6): - trgba[i] = self.istorage[self.field_table_ids[i]] - #print i, trgba[i], - #print - # A few words on opacity. We're going to be integrating equation 1.23 - # from Rybicki & Lightman. dI_\nu / ds = -\alpha_\nu I_\nu + j_\nu - # \alpha_nu = \kappa \rho , but we leave that up to the input - # transfer function. - # SOoooooOOOooo, the upshot is that we are doing a rectangular - # integration here: - # I_{i+1} = ds * C_i + (1.0 - ds*alpha_i) * I_i - for i in range(3): - # This is the new way: alpha corresponds to opacity of a given - # slice. Previously it was ill-defined, but represented some - # measure of emissivity. - ta = fmax((1.0 - dt*trgba[i+3]), 0.0) - rgba[i ] = dt*trgba[i ] + ta * rgba[i ] - #rgba[i+3] = dt*trgba[i+3] + ta * rgba[i+3] - # This is the old way: - #rgba[i ] += trgba[i] * (1.0 - rgba[i+3])*dt*trgba[i+3] - #rgba[i+3] += trgba[i] * (1.0 - rgba[i+3])*dt*trgba[i+3] - -cdef class VectorPlane: - cdef public object avp_pos, avp_dir, acenter, aimage - cdef np.float64_t *vp_pos, *vp_dir, *center, *image, - cdef np.float64_t pdx, pdy, bounds[4] - cdef int nv[2] - cdef int vp_strides[3] - cdef int im_strides[3] - cdef int vd_strides[3] - cdef public object ax_vec, ay_vec - cdef np.float64_t *x_vec, *y_vec - - def __cinit__(self, - np.ndarray[np.float64_t, ndim=3] vp_pos, - np.ndarray vp_dir, - np.ndarray[np.float64_t, ndim=1] center, - bounds, - np.ndarray[np.float64_t, ndim=3] image, - np.ndarray[np.float64_t, ndim=1] x_vec, - np.ndarray[np.float64_t, ndim=1] y_vec): - cdef int i, j - self.avp_pos = vp_pos - self.avp_dir = vp_dir - self.acenter = center - self.aimage = image - self.ax_vec = x_vec - self.ay_vec = y_vec - self.vp_pos = vp_pos.data - self.vp_dir = vp_dir.data - self.center = center.data - self.image = image.data - self.x_vec = x_vec.data - self.y_vec = y_vec.data - self.nv[0] = vp_pos.shape[0] - self.nv[1] = vp_pos.shape[1] - for i in range(4): self.bounds[i] = bounds[i] - self.pdx = (self.bounds[1] - self.bounds[0])/self.nv[0] - self.pdy = (self.bounds[3] - self.bounds[2])/self.nv[1] - for i in range(3): - self.vp_strides[i] = vp_pos.strides[i] / 8 - self.im_strides[i] = image.strides[i] / 8 - if vp_dir.ndim > 1: - for i in range(3): - self.vd_strides[i] = vp_dir.strides[i] / 8 - else: - self.vd_strides[0] = self.vd_strides[1] = self.vd_strides[2] = -1 - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef void get_start_stop(self, np.float64_t *ex, int *rv): - # Extrema need to be re-centered - cdef np.float64_t cx, cy - cdef int i - cx = cy = 0.0 - for i in range(3): - cx += self.center[i] * self.x_vec[i] - cy += self.center[i] * self.y_vec[i] - rv[0] = lrint((ex[0] - cx - self.bounds[0])/self.pdx) - rv[1] = rv[0] + lrint((ex[1] - ex[0])/self.pdx) - rv[2] = lrint((ex[2] - cy - self.bounds[2])/self.pdy) - rv[3] = rv[2] + lrint((ex[3] - ex[2])/self.pdy) - - cdef inline void copy_into(self, np.float64_t *fv, np.float64_t *tv, - int i, int j, int nk, int strides[3]): - # We know the first two dimensions of our from-vector, and our - # to-vector is flat and 'ni' long - cdef int k - cdef int offset = strides[0] * i + strides[1] * j - for k in range(nk): - tv[k] = fv[offset + k] - - cdef inline void copy_back(self, np.float64_t *fv, np.float64_t *tv, - int i, int j, int nk, int strides[3]): - cdef int k - cdef int offset = strides[0] * i + strides[1] * j - for k in range(nk): - tv[offset + k] = fv[k] - -cdef class PartitionedGrid: - cdef public object my_data - cdef public object LeftEdge - cdef public object RightEdge - cdef np.float64_t *data[6] - cdef np.float64_t dvs[6] - cdef np.float64_t left_edge[3] - cdef np.float64_t right_edge[3] - cdef np.float64_t dds[3] - cdef np.float64_t idds[3] - cdef int dims[3] - cdef public int parent_grid_id - cdef public int n_fields - - @cython.boundscheck(False) - @cython.wraparound(False) - def __cinit__(self, - int parent_grid_id, int n_fields, data, - np.ndarray[np.float64_t, ndim=1] left_edge, - np.ndarray[np.float64_t, ndim=1] right_edge, - np.ndarray[np.int64_t, ndim=1] dims): - # The data is likely brought in via a slice, so we copy it - cdef int i, j, k, size - cdef np.ndarray[np.float64_t, ndim=3] tdata - self.parent_grid_id = parent_grid_id - self.LeftEdge = left_edge - self.RightEdge = right_edge - for i in range(3): - self.left_edge[i] = left_edge[i] - self.right_edge[i] = right_edge[i] - self.dims[i] = dims[i] - self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] - self.idds[i] = 1.0/self.dds[i] - self.my_data = data - self.n_fields = n_fields - for i in range(n_fields): - tdata = data[i] - self.data[i] = tdata.data - - @cython.boundscheck(False) - @cython.wraparound(False) - def cast_plane(self, TransferFunctionProxy tf, VectorPlane vp): - # This routine will iterate over all of the vectors and cast each in - # turn. Might benefit from a more sophisticated intersection check, - # like http://courses.csusm.edu/cs697exz/ray_box.htm - cdef int vi, vj, hit, i, ni, nj, nn - cdef int iter[4] - cdef np.float64_t v_pos[3], v_dir[3], rgba[6], extrema[4] - hit = 0 - self.calculate_extent(vp, extrema) - vp.get_start_stop(extrema, iter) - iter[0] = iclip(iter[0], 0, vp.nv[0]) - iter[1] = iclip(iter[1], 0, vp.nv[0]) - iter[2] = iclip(iter[2], 0, vp.nv[1]) - iter[3] = iclip(iter[3], 0, vp.nv[1]) - if vp.vd_strides[0] == -1: - for vi in range(iter[0], iter[1]): - for vj in range(iter[2], iter[3]): - vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - self.integrate_ray(v_pos, vp.vp_dir, rgba, tf) - vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - else: - # If we do not have an orthographic projection, we have to cast all - # our rays (until we can get an extrema calculation...) - for vi in range(vp.nv[0]): - for vj in range(vp.nv[1]): - vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - vp.copy_into(vp.vp_dir, v_dir, vi, vj, 3, vp.vd_strides) - self.integrate_ray(v_pos, v_dir, rgba, tf) - vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - return hit - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef void calculate_extent(self, VectorPlane vp, - np.float64_t extrema[4]): - # We do this for all eight corners - cdef np.float64_t *edges[2], temp - edges[0] = self.left_edge - edges[1] = self.right_edge - extrema[0] = extrema[2] = 1e300; extrema[1] = extrema[3] = -1e300 - cdef int i, j, k - for i in range(2): - for j in range(2): - for k in range(2): - # This should rotate it into the vector plane - temp = edges[i][0] * vp.x_vec[0] - temp += edges[j][1] * vp.x_vec[1] - temp += edges[k][2] * vp.x_vec[2] - if temp < extrema[0]: extrema[0] = temp - if temp > extrema[1]: extrema[1] = temp - temp = edges[i][0] * vp.y_vec[0] - temp += edges[j][1] * vp.y_vec[1] - temp += edges[k][2] * vp.y_vec[2] - if temp < extrema[2]: extrema[2] = temp - if temp > extrema[3]: extrema[3] = temp - #print extrema[0], extrema[1], extrema[2], extrema[3] - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef int integrate_ray(self, np.float64_t v_pos[3], - np.float64_t v_dir[3], - np.float64_t rgba[4], - TransferFunctionProxy tf): - cdef int cur_ind[3], step[3], x, y, i, n, flat_ind, hit, direction - cdef np.float64_t intersect_t = 1.0 - cdef np.float64_t iv_dir[3] - cdef np.float64_t intersect[3], tmax[3], tdelta[3] - cdef np.float64_t enter_t, dist, alpha, dt, exit_t - cdef np.float64_t tr, tl, temp_x, temp_y, dv - for i in range(3): - if (v_dir[i] < 0): - step[i] = -1 - elif (v_dir[i] == 0): - step[i] = 1 - tmax[i] = 1e60 - iv_dir[i] = 1e60 - tdelta[i] = 1e-60 - continue - else: - step[i] = 1 - x = (i+1) % 3 - y = (i+2) % 3 - iv_dir[i] = 1.0/v_dir[i] - tl = (self.left_edge[i] - v_pos[i])*iv_dir[i] - temp_x = (v_pos[x] + tl*v_dir[x]) - temp_y = (v_pos[y] + tl*v_dir[y]) - if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - 0.0 <= tl and tl < intersect_t: - direction = i - intersect_t = tl - tr = (self.right_edge[i] - v_pos[i])*iv_dir[i] - temp_x = (v_pos[x] + tr*v_dir[x]) - temp_y = (v_pos[y] + tr*v_dir[y]) - if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - 0.0 <= tr and tr < intersect_t: - direction = i - intersect_t = tr - if self.left_edge[0] <= v_pos[0] and v_pos[0] <= self.right_edge[0] and \ - self.left_edge[1] <= v_pos[1] and v_pos[1] <= self.right_edge[1] and \ - self.left_edge[2] <= v_pos[2] and v_pos[2] <= self.right_edge[2]: - intersect_t = 0.0 - if not ((0.0 <= intersect_t) and (intersect_t < 1.0)): return 0 - for i in range(3): - intersect[i] = v_pos[i] + intersect_t * v_dir[i] - cur_ind[i] = floor((intersect[i] + - step[i]*1e-8*self.dds[i] - - self.left_edge[i])*self.idds[i]) - tmax[i] = (((cur_ind[i]+step[i])*self.dds[i])+ - self.left_edge[i]-v_pos[i])*iv_dir[i] - # This deals with the asymmetry in having our indices refer to the - # left edge of a cell, but the right edge of the brick being one - # extra zone out. - if cur_ind[i] == self.dims[i] and step[i] < 0: - cur_ind[i] = self.dims[i] - 1 - if cur_ind[i] < 0 or cur_ind[i] >= self.dims[i]: return 0 - if step[i] > 0: - tmax[i] = (((cur_ind[i]+1)*self.dds[i]) - +self.left_edge[i]-v_pos[i])*iv_dir[i] - if step[i] < 0: - tmax[i] = (((cur_ind[i]+0)*self.dds[i]) - +self.left_edge[i]-v_pos[i])*iv_dir[i] - tdelta[i] = (self.dds[i]*iv_dir[i]) - if tdelta[i] < 0: tdelta[i] *= -1 - # We have to jumpstart our calculation - enter_t = intersect_t - while 1: - # dims here is one less than the dimensions of the data, - # but we are tracing on the grid, not on the data... - if (not (0 <= cur_ind[0] < self.dims[0])) or \ - (not (0 <= cur_ind[1] < self.dims[1])) or \ - (not (0 <= cur_ind[2] < self.dims[2])): - break - hit += 1 - if tmax[0] < tmax[1]: - if tmax[0] < tmax[2]: - exit_t = fmin(tmax[0], 1.0) - self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - rgba, tf) - cur_ind[0] += step[0] - enter_t = tmax[0] - tmax[0] += tdelta[0] - else: - exit_t = fmin(tmax[2], 1.0) - self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - rgba, tf) - cur_ind[2] += step[2] - enter_t = tmax[2] - tmax[2] += tdelta[2] - else: - if tmax[1] < tmax[2]: - exit_t = fmin(tmax[1], 1.0) - self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - rgba, tf) - cur_ind[1] += step[1] - enter_t = tmax[1] - tmax[1] += tdelta[1] - else: - exit_t = fmin(tmax[2], 1.0) - self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - rgba, tf) - cur_ind[2] += step[2] - enter_t = tmax[2] - tmax[2] += tdelta[2] - if enter_t > 1.0: break - return hit - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef void sample_values(self, - np.float64_t v_pos[3], - np.float64_t v_dir[3], - np.float64_t enter_t, - np.float64_t exit_t, - int ci[3], - np.float64_t *rgba, - TransferFunctionProxy tf): - cdef np.float64_t cp[3], dp[3], temp, dt, t, dv - cdef np.float64_t grad[3], ds[3] - grad[0] = grad[1] = grad[2] = 0.0 - cdef int dti, i - dt = (exit_t - enter_t) / tf.ns # 4 samples should be dt=0.25 - cdef int offset = ci[0] * (self.dims[1] + 1) * (self.dims[2] + 1) \ - + ci[1] * (self.dims[2] + 1) + ci[2] - for i in range(3): - # temp is the left edge of the current cell - temp = ci[i] * self.dds[i] + self.left_edge[i] - # this gets us dp as the current first sample position - dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp - dp[i] *= self.idds[i] - ds[i] = v_dir[i] * self.idds[i] * dt - for dti in range(tf.ns): - for i in range(self.n_fields): - self.dvs[i] = offset_interpolate(self.dims, dp, self.data[i] + offset) - #if (dv < tf.x_bounds[0]) or (dv > tf.x_bounds[1]): - # continue - for i in range(3): - dp[i] += ds[i] - tf.eval_transfer(dt, self.dvs, rgba, grad) - -cdef class GridFace: - cdef int direction - cdef public np.float64_t coord - cdef np.float64_t left_edge[3] - cdef np.float64_t right_edge[3] - - @cython.boundscheck(False) - @cython.wraparound(False) - def __init__(self, grid, int direction, int left): - self.direction = direction - if left == 1: - self.coord = grid.LeftEdge[direction] - else: - self.coord = grid.RightEdge[direction] - cdef int i - for i in range(3): - self.left_edge[i] = grid.LeftEdge[i] - self.right_edge[i] = grid.RightEdge[i] - self.left_edge[direction] = self.right_edge[direction] = self.coord - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef int proj_overlap(self, np.float64_t *left_edge, np.float64_t *right_edge): - cdef int xax, yax - xax = (self.direction + 1) % 3 - yax = (self.direction + 2) % 3 - if left_edge[xax] >= self.right_edge[xax]: return 0 - if right_edge[xax] <= self.left_edge[xax]: return 0 - if left_edge[yax] >= self.right_edge[yax]: return 0 - if right_edge[yax] <= self.left_edge[yax]: return 0 - return 1 - -cdef class ProtoPrism: - cdef np.float64_t left_edge[3] - cdef np.float64_t right_edge[3] - cdef public object LeftEdge - cdef public object RightEdge - cdef public object subgrid_faces - cdef public int parent_grid_id - def __cinit__(self, int parent_grid_id, - np.ndarray[np.float64_t, ndim=1] left_edge, - np.ndarray[np.float64_t, ndim=1] right_edge, - subgrid_faces): - self.parent_grid_id = parent_grid_id - cdef int i - self.LeftEdge = left_edge - self.RightEdge = right_edge - for i in range(3): - self.left_edge[i] = left_edge[i] - self.right_edge[i] = right_edge[i] - self.subgrid_faces = subgrid_faces - - @cython.boundscheck(False) - @cython.wraparound(False) - def sweep(self, int direction = 0, int stack = 0): - cdef int i - cdef GridFace face - cdef np.float64_t proto_split[3] - for i in range(3): proto_split[i] = self.right_edge[i] - for face in self.subgrid_faces[direction]: - proto_split[direction] = face.coord - if proto_split[direction] <= self.left_edge[direction]: - continue - if proto_split[direction] == self.right_edge[direction]: - if stack == 2: return [self] - return self.sweep((direction + 1) % 3, stack + 1) - if face.proj_overlap(self.left_edge, proto_split) == 1: - left, right = self.split(proto_split, direction) - LC = left.sweep((direction + 1) % 3) - RC = right.sweep(direction) - return LC + RC - raise RuntimeError - - @cython.boundscheck(False) - @cython.wraparound(False) - cdef object split(self, np.float64_t *sp, int direction): - cdef int i - cdef np.ndarray split_left = self.LeftEdge.copy() - cdef np.ndarray split_right = self.RightEdge.copy() - - for i in range(3): split_left[i] = self.right_edge[i] - split_left[direction] = sp[direction] - left = ProtoPrism(self.parent_grid_id, self.LeftEdge, split_left, - self.subgrid_faces) - - for i in range(3): split_right[i] = self.left_edge[i] - split_right[direction] = sp[direction] - right = ProtoPrism(self.parent_grid_id, split_right, self.RightEdge, - self.subgrid_faces) - - return (left, right) - - @cython.boundscheck(False) - @cython.wraparound(False) - def get_brick(self, np.ndarray[np.float64_t, ndim=1] grid_left_edge, - np.ndarray[np.float64_t, ndim=1] grid_dds, - child_mask): - # We get passed in the left edge, the dds (which gives dimensions) and - # the data, which is already vertex-centered. - cdef PartitionedGrid PG - cdef int li[3], ri[3], idims[3], i - for i in range(3): - li[i] = lrint((self.left_edge[i] - grid_left_edge[i])/grid_dds[i]) - ri[i] = lrint((self.right_edge[i] - grid_left_edge[i])/grid_dds[i]) - idims[i] = ri[i] - li[i] - if child_mask[li[0], li[1], li[2]] == 0: return [] - cdef np.ndarray[np.int64_t, ndim=1] dims = np.empty(3, dtype='int64') - for i in range(3): - dims[i] = idims[i] - #cdef np.ndarray[np.float64_t, ndim=3] new_data - #new_data = data[li[0]:ri[0]+1,li[1]:ri[1]+1,li[2]:ri[2]+1].copy() - #PG = PartitionedGrid(self.parent_grid_id, new_data, - # self.LeftEdge, self.RightEdge, dims) - return ((li[0], ri[0]), (li[1], ri[1]), (li[2], ri[2]), dims) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/fortran_reader.pyx --- a/yt/_amr_utils/fortran_reader.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -""" -Simple readers for fortran unformatted data, specifically for the Tiger code. - -Author: Matthew Turk -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 . -""" - -import numpy as np -cimport numpy as np -cimport cython - -from stdio cimport fopen, fclose, FILE - -cdef extern from "stdio.h": - cdef int SEEK_SET - cdef int SEEK_CUR - cdef int SEEK_END - int fseek(FILE *stream, long offset, int whence) - size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) - long ftell(FILE *stream) - -@cython.boundscheck(False) -@cython.wraparound(False) -def read_tiger_section( - char *fn, - np.ndarray[np.int64_t, ndim=1] slab_start, - np.ndarray[np.int64_t, ndim=1] slab_size, - np.ndarray[np.int64_t, ndim=1] root_size, - int offset = 36): - cdef int strides[3] - strides[0] = 1 - strides[1] = root_size[0] * strides[0] - strides[2] = strides[1] * root_size[1] + 2 - cdef np.int64_t i, j, k - cdef np.ndarray buffer = np.zeros(slab_size, dtype='float32', order='F') - cdef FILE *f = fopen(fn, "rb") - #for i in range(3): offset += strides[i] * slab_start[i] - cdef np.int64_t pos = 0 - cdef np.int64_t moff = 0 - cdef float *data = buffer.data - fseek(f, offset, 0) - # If anybody wants to convert this loop to a SEEK_CUR, that'd be great. - for i in range(slab_size[2]): - for j in range(slab_size[1]): - moff = (slab_start[0] ) * strides[0] \ - + (slab_start[1] + j) * strides[1] \ - + (slab_start[2] + i) * strides[2] - #print offset + 4 * moff, pos - fseek(f, offset + 4 * moff, SEEK_SET) - fread( (data + pos), 4, slab_size[0], f) - pos += slab_size[0] - return buffer diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/_amr_utils/png_writer.pyx --- a/yt/_amr_utils/png_writer.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -""" -A light interface to libpng - -Author: Matthew Turk -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 . -""" - -import numpy as np -cimport numpy as np -cimport cython - -from stdio cimport fopen, fclose, FILE - -cdef extern from "stdlib.h": - # NOTE that size_t might not be int - void *alloca(int) - -cdef extern from "png.h": - ctypedef unsigned long png_uint_32 - ctypedef long png_int_32 - ctypedef unsigned short png_uint_16 - ctypedef short png_int_16 - ctypedef unsigned char png_byte - ctypedef void *png_voidp - ctypedef png_byte *png_bytep - ctypedef png_uint_32 *png_uint_32p - ctypedef png_int_32 *png_int_32p - ctypedef png_uint_16 *png_uint_16p - ctypedef png_int_16 *png_int_16p - ctypedef char *png_charp - ctypedef char *png_const_charp - ctypedef FILE *png_FILE_p - - ctypedef struct png_struct: - pass - ctypedef png_struct *png_structp - - ctypedef struct png_info: - pass - ctypedef png_info *png_infop - - ctypedef struct png_color_8: - png_byte red - png_byte green - png_byte blue - png_byte gray - png_byte alpha - ctypedef png_color_8 *png_color_8p - - cdef png_const_charp PNG_LIBPNG_VER_STRING - - # Note that we don't support error or warning functions - png_structp png_create_write_struct( - png_const_charp user_png_ver, png_voidp error_ptr, - void *error_fn, void *warn_fn) - - png_infop png_create_info_struct(png_structp png_ptr) - - void png_init_io(png_structp png_ptr, png_FILE_p fp) - - void png_set_IHDR(png_structp png_ptr, png_infop info_ptr, - png_uint_32 width, png_uint_32 height, int bit_depth, - int color_type, int interlace_method, int compression_method, - int filter_method) - - cdef int PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE - cdef int PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE - - void png_set_pHYs(png_structp png_ptr, png_infop info_ptr, - png_uint_32 res_x, png_uint_32 res_y, int unit_type) - - cdef int PNG_RESOLUTION_METER - - void png_set_sBIT(png_structp png_ptr, png_infop info_ptr, - png_color_8p sig_bit) - - void png_write_info(png_structp png_ptr, png_infop info_ptr) - void png_write_image(png_structp png_ptr, png_bytep *image) - void png_write_end(png_structp png_ptr, png_infop info_ptr) - - void png_destroy_write_struct( - png_structp *png_ptr_ptr, png_infop *info_ptr_ptr) - -def write_png(np.ndarray[np.uint8_t, ndim=3] buffer, - char *filename, int dpi=100): - - # This is something of a translation of the matplotlib _png module - cdef png_byte *pix_buffer = buffer.data - cdef int width = buffer.shape[1] - cdef int height = buffer.shape[0] - - cdef FILE* fileobj = fopen(filename, "wb") - cdef png_bytep *row_pointers - cdef png_structp png_ptr - cdef png_infop info_ptr - - cdef png_color_8 sig_bit - cdef png_uint_32 row - - row_pointers = alloca(sizeof(png_bytep) * height) - - for row in range(height): - row_pointers[row] = pix_buffer + row * width * 4 - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL) - info_ptr = png_create_info_struct(png_ptr) - - # Um we are ignoring setjmp sorry guys - - png_init_io(png_ptr, fileobj) - - png_set_IHDR(png_ptr, info_ptr, width, height, 8, - PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE) - - cdef size_t dots_per_meter = (dpi / (2.54 / 100.0)) - png_set_pHYs(png_ptr, info_ptr, dots_per_meter, dots_per_meter, - PNG_RESOLUTION_METER) - - sig_bit.gray = 0 - sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 8 - - png_set_sBIT(png_ptr, info_ptr, &sig_bit) - - png_write_info(png_ptr, info_ptr) - png_write_image(png_ptr, row_pointers) - png_write_end(png_ptr, info_ptr) - - fclose(fileobj) - png_destroy_write_struct(&png_ptr, &info_ptr) - -def add_points_to_image( - np.ndarray[np.uint8_t, ndim=3] buffer, - np.ndarray[np.float64_t, ndim=1] px, - np.ndarray[np.float64_t, ndim=1] py, - np.float64_t pv): - cdef int i, j, k, pi - cdef int np = px.shape[0] - cdef int xs = buffer.shape[0] - cdef int ys = buffer.shape[1] - cdef int v - v = iclip((pv * 255), 0, 255) - for pi in range(np): - j = (xs * px[pi]) - i = (ys * py[pi]) - for k in range(3): - buffer[i, j, k] = 0 - return - for i in range(xs): - for j in range(ys): - for k in range(3): - v = buffer[i, j, k] - buffer[i, j, k] = iclip(v, 0, 255) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/amr_utils.c --- a/yt/amr_utils.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32107 +0,0 @@ -/* Generated by Cython 0.13.beta0 on Mon Aug 2 07:18:26 2010 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#else - -#include /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif - -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif - -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif - -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif - -#if PY_VERSION_HEX < 0x02040000 - #define METH_COEXIST 0 - #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) - #define PyDict_Contains(d,o) PySequence_Contains(d,o) -#endif - -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) PyInt_AsLong(o) - #define PyNumber_Index(o) PyNumber_Int(o) - #define PyIndex_Check(o) PyNumber_Check(o) - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - -#endif - -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" -#endif - -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif - -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif - -#ifndef PySet_CheckExact -# define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif - -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif - -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - -#ifdef __cplusplus -#define __PYX_EXTERN_C extern "C" -#else -#define __PYX_EXTERN_C extern -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include -#define __PYX_HAVE_API__yt__amr_utils -#include "stdio.h" -#include "stdlib.h" -#include "numpy/arrayobject.h" -#include "numpy/ufuncobject.h" -#include "math.h" -#include "FixedInterpolator.h" -#include "png.h" - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || defined(__INTEL_COMPILER) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) - - -#ifdef __GNUC__ -/* Test for GCC > 2.95 */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#else /* __GNUC__ > 2 ... */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -#if !defined(CYTHON_CCOMPLEX) - #if defined(__cplusplus) - #define CYTHON_CCOMPLEX 1 - #elif defined(_Complex_I) - #define CYTHON_CCOMPLEX 1 - #else - #define CYTHON_CCOMPLEX 0 - #endif -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #include - #else - #include - #endif -#endif - -#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__) - #undef _Complex_I - #define _Complex_I 1.0fj -#endif - -static const char *__pyx_f[] = { - "DepthFirstOctree.pyx", - "PointsInVolume.pyx", - "VolumeIntegrator.pyx", - "Interpolators.pyx", - "RayIntegrators.pyx", - "CICDeposit.pyx", - "ContourFinding.pyx", - "png_writer.pyx", - "fortran_reader.pyx", - "QuadTree.pyx", - "numpy.pxd", - "amr_utils.pyx", -}; - -typedef npy_int8 __pyx_t_5numpy_int8_t; - -typedef npy_int16 __pyx_t_5numpy_int16_t; - -typedef npy_int32 __pyx_t_5numpy_int32_t; - -typedef npy_int64 __pyx_t_5numpy_int64_t; - -typedef npy_uint8 __pyx_t_5numpy_uint8_t; - -typedef npy_uint16 __pyx_t_5numpy_uint16_t; - -typedef npy_uint32 __pyx_t_5numpy_uint32_t; - -typedef npy_uint64 __pyx_t_5numpy_uint64_t; - -typedef npy_float32 __pyx_t_5numpy_float32_t; - -typedef npy_float64 __pyx_t_5numpy_float64_t; - -typedef npy_long __pyx_t_5numpy_int_t; - -typedef npy_longlong __pyx_t_5numpy_long_t; - -typedef npy_intp __pyx_t_5numpy_intp_t; - -typedef npy_uintp __pyx_t_5numpy_uintp_t; - -typedef npy_ulong __pyx_t_5numpy_uint_t; - -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -typedef npy_double __pyx_t_5numpy_float_t; - -typedef npy_double __pyx_t_5numpy_double_t; - -typedef npy_longdouble __pyx_t_5numpy_longdouble_t; - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< float > __pyx_t_float_complex; - #else - typedef float _Complex __pyx_t_float_complex; - #endif -#else - typedef struct { float real, imag; } __pyx_t_float_complex; -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< double > __pyx_t_double_complex; - #else - typedef double _Complex __pyx_t_double_complex; - #endif -#else - typedef struct { double real, imag; } __pyx_t_double_complex; -#endif - -/* Type declarations */ - -typedef npy_cfloat __pyx_t_5numpy_cfloat_t; - -typedef npy_cdouble __pyx_t_5numpy_cdouble_t; - -typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; - -typedef npy_cdouble __pyx_t_5numpy_complex_t; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":76 - * cdef class VectorPlane - * - * cdef struct FieldInterpolationTable: # <<<<<<<<<<<<<< - * # Note that we make an assumption about retaining a reference to values - * # externally. - */ - -struct __pyx_t_2yt_9amr_utils_FieldInterpolationTable { - __pyx_t_5numpy_float64_t *values; - __pyx_t_5numpy_float64_t bounds[2]; - __pyx_t_5numpy_float64_t dbin; - __pyx_t_5numpy_float64_t idbin; - int field_id; - int weight_field_id; - int weight_table_id; - int nbins; - int pass_through; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":89 - * int pass_through - * - * cdef void FIT_initialize_table(FieldInterpolationTable *fit, int nbins, # <<<<<<<<<<<<<< - * np.float64_t *values, np.float64_t bounds1, np.float64_t bounds2, - * int field_id, int weight_field_id = -1, int weight_table_id = -1, - */ - -struct __pyx_opt_args_2yt_9amr_utils_FIT_initialize_table { - int __pyx_n; - int weight_field_id; - int weight_table_id; - int pass_through; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":39 - * void *alloca(int) - * - * cdef struct QuadTreeNode: # <<<<<<<<<<<<<< - * np.float64_t *val - * np.float64_t weight_val - */ - -struct __pyx_t_2yt_9amr_utils_QuadTreeNode { - __pyx_t_5numpy_float64_t *val; - __pyx_t_5numpy_float64_t weight_val; - __pyx_t_5numpy_int64_t pos[2]; - int level; - int nvals; - struct __pyx_t_2yt_9amr_utils_QuadTreeNode *children[2][2]; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":118 - * return (bv + dd*dy*fit.idbin) - * - * cdef class TransferFunctionProxy: # <<<<<<<<<<<<<< - * cdef int n_fields - * cdef int n_field_tables - */ - -struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy { - PyObject_HEAD - struct __pyx_vtabstruct_2yt_9amr_utils_TransferFunctionProxy *__pyx_vtab; - int n_fields; - int n_field_tables; - int ns; - struct __pyx_t_2yt_9amr_utils_FieldInterpolationTable field_tables[6]; - __pyx_t_5numpy_float64_t istorage[6]; - int field_table_ids[6]; - PyObject *tf_obj; - PyObject *my_field_tables; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":36 - * self.refined_pos = 0 - * - * cdef class OctreeGrid: # <<<<<<<<<<<<<< - * cdef public object child_indices, fields, left_edges, dimensions, dx - * cdef public int level - */ - -struct __pyx_obj_2yt_9amr_utils_OctreeGrid { - PyObject_HEAD - PyObject *child_indices; - PyObject *fields; - PyObject *left_edges; - PyObject *dimensions; - PyObject *dx; - int level; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":53 - * self.level = level - * - * cdef class OctreeGridList: # <<<<<<<<<<<<<< - * cdef public object grids - * def __cinit__(self, grids): - */ - -struct __pyx_obj_2yt_9amr_utils_OctreeGridList { - PyObject_HEAD - PyObject *grids; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":575 - * return 1 - * - * cdef class ProtoPrism: # <<<<<<<<<<<<<< - * cdef np.float64_t left_edge[3] - * cdef np.float64_t right_edge[3] - */ - -struct __pyx_obj_2yt_9amr_utils_ProtoPrism { - PyObject_HEAD - struct __pyx_vtabstruct_2yt_9amr_utils_ProtoPrism *__pyx_vtab; - __pyx_t_5numpy_float64_t left_edge[3]; - __pyx_t_5numpy_float64_t right_edge[3]; - PyObject *LeftEdge; - PyObject *RightEdge; - PyObject *subgrid_faces; - int parent_grid_id; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":30 - * cimport cython - * - * cdef class position: # <<<<<<<<<<<<<< - * cdef public int output_pos, refined_pos - * def __cinit__(self): - */ - -struct __pyx_obj_2yt_9amr_utils_position { - PyObject_HEAD - int output_pos; - int refined_pos; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":543 - * tf.eval_transfer(dt, self.dvs, rgba, grad) - * - * cdef class GridFace: # <<<<<<<<<<<<<< - * cdef int direction - * cdef public np.float64_t coord - */ - -struct __pyx_obj_2yt_9amr_utils_GridFace { - PyObject_HEAD - struct __pyx_vtabstruct_2yt_9amr_utils_GridFace *__pyx_vtab; - int direction; - __pyx_t_5numpy_float64_t coord; - __pyx_t_5numpy_float64_t left_edge[3]; - __pyx_t_5numpy_float64_t right_edge[3]; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":99 - * free(node) - * - * cdef class QuadTree: # <<<<<<<<<<<<<< - * cdef int nvals - * cdef np.int64_t po2[80] - */ - -struct __pyx_obj_2yt_9amr_utils_QuadTree { - PyObject_HEAD - struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *__pyx_vtab; - int nvals; - __pyx_t_5numpy_int64_t po2[80]; - struct __pyx_t_2yt_9amr_utils_QuadTreeNode ***root_nodes; - __pyx_t_5numpy_int64_t top_grid_dims[2]; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":74 - * np.float64_t *data, np.float64_t *grad) - * - * cdef class VectorPlane # <<<<<<<<<<<<<< - * - * cdef struct FieldInterpolationTable: - */ - -struct __pyx_obj_2yt_9amr_utils_VectorPlane { - PyObject_HEAD - struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *__pyx_vtab; - PyObject *avp_pos; - PyObject *avp_dir; - PyObject *acenter; - PyObject *aimage; - __pyx_t_5numpy_float64_t *vp_pos; - __pyx_t_5numpy_float64_t *vp_dir; - __pyx_t_5numpy_float64_t *center; - __pyx_t_5numpy_float64_t *image; - __pyx_t_5numpy_float64_t pdx; - __pyx_t_5numpy_float64_t pdy; - __pyx_t_5numpy_float64_t bounds[4]; - int nv[2]; - int vp_strides[3]; - int im_strides[3]; - int vd_strides[3]; - PyObject *ax_vec; - PyObject *ay_vec; - __pyx_t_5numpy_float64_t *x_vec; - __pyx_t_5numpy_float64_t *y_vec; -}; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":299 - * tv[offset + k] = fv[k] - * - * cdef class PartitionedGrid: # <<<<<<<<<<<<<< - * cdef public object my_data - * cdef public object LeftEdge - */ - -struct __pyx_obj_2yt_9amr_utils_PartitionedGrid { - PyObject_HEAD - struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *__pyx_vtab; - PyObject *my_data; - PyObject *LeftEdge; - PyObject *RightEdge; - __pyx_t_5numpy_float64_t *data[6]; - __pyx_t_5numpy_float64_t dvs[6]; - __pyx_t_5numpy_float64_t left_edge[3]; - __pyx_t_5numpy_float64_t right_edge[3]; - __pyx_t_5numpy_float64_t dds[3]; - __pyx_t_5numpy_float64_t idds[3]; - int dims[3]; - int parent_grid_id; - int n_fields; -}; - - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":543 - * tf.eval_transfer(dt, self.dvs, rgba, grad) - * - * cdef class GridFace: # <<<<<<<<<<<<<< - * cdef int direction - * cdef public np.float64_t coord - */ - -struct __pyx_vtabstruct_2yt_9amr_utils_GridFace { - int (*proj_overlap)(struct __pyx_obj_2yt_9amr_utils_GridFace *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *); -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_GridFace *__pyx_vtabptr_2yt_9amr_utils_GridFace; - - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":118 - * return (bv + dd*dy*fit.idbin) - * - * cdef class TransferFunctionProxy: # <<<<<<<<<<<<<< - * cdef int n_fields - * cdef int n_field_tables - */ - -struct __pyx_vtabstruct_2yt_9amr_utils_TransferFunctionProxy { - void (*eval_transfer)(struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *); -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_TransferFunctionProxy *__pyx_vtabptr_2yt_9amr_utils_TransferFunctionProxy; - - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":575 - * return 1 - * - * cdef class ProtoPrism: # <<<<<<<<<<<<<< - * cdef np.float64_t left_edge[3] - * cdef np.float64_t right_edge[3] - */ - -struct __pyx_vtabstruct_2yt_9amr_utils_ProtoPrism { - PyObject *(*split)(struct __pyx_obj_2yt_9amr_utils_ProtoPrism *, __pyx_t_5numpy_float64_t *, int); -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_ProtoPrism *__pyx_vtabptr_2yt_9amr_utils_ProtoPrism; - - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":99 - * free(node) - * - * cdef class QuadTree: # <<<<<<<<<<<<<< - * cdef int nvals - * cdef np.int64_t po2[80] - */ - -struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree { - void (*add_to_position)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, int, __pyx_t_5numpy_int64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t); - struct __pyx_t_2yt_9amr_utils_QuadTreeNode *(*find_on_root_level)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, __pyx_t_5numpy_int64_t *, int); - int (*count_at_level)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, struct __pyx_t_2yt_9amr_utils_QuadTreeNode *, int); - int (*fill_from_level)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, struct __pyx_t_2yt_9amr_utils_QuadTreeNode *, int, __pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *); -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *__pyx_vtabptr_2yt_9amr_utils_QuadTree; - - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":222 - * #rgba[i+3] += trgba[i] * (1.0 - rgba[i+3])*dt*trgba[i+3] - * - * cdef class VectorPlane: # <<<<<<<<<<<<<< - * cdef public object avp_pos, avp_dir, acenter, aimage - * cdef np.float64_t *vp_pos, *vp_dir, *center, *image, - */ - -struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane { - void (*get_start_stop)(struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *, int *); - void (*copy_into)(struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, int, int, int, int *); - void (*copy_back)(struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, int, int, int, int *); -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *__pyx_vtabptr_2yt_9amr_utils_VectorPlane; - - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":299 - * tv[offset + k] = fv[k] - * - * cdef class PartitionedGrid: # <<<<<<<<<<<<<< - * cdef public object my_data - * cdef public object LeftEdge - */ - -struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid { - void (*calculate_extent)(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *, struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *); - int (*integrate_ray)(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *); - void (*sample_values)(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, int *, __pyx_t_5numpy_float64_t *, struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *); -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *__pyx_vtabptr_2yt_9amr_utils_PartitionedGrid; - -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif - -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); - end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; - } - #define __Pyx_RefNannySetupContext(name) void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) - #define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0) -#else - #define __Pyx_RefNannySetupContext(name) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0) -#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, - const char* function_name, int kw_allowed); /*proto*/ - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, PyObject* kw_name); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ - -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact); /*proto*/ - -/* Run-time type information about structs used with buffers */ -struct __Pyx_StructField_; - -typedef struct { - const char* name; /* for error messages only */ - struct __Pyx_StructField_* fields; - size_t size; /* sizeof(type) */ - char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */ -} __Pyx_TypeInfo; - -typedef struct __Pyx_StructField_ { - __Pyx_TypeInfo* type; - const char* name; - size_t offset; -} __Pyx_StructField; - -typedef struct { - __Pyx_StructField* field; - size_t parent_offset; -} __Pyx_BufFmt_StackElem; - - -static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); -static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} - - -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - - -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { - PyObject *r; - if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { - r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - } - else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - } - else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) { - r = PySequence_GetItem(o, i); - } - else { - r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); - } - return r; -} - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ -#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) -#define __Pyx_BufPtrStrided4d(type, buf, i0, s0, i1, s1, i2, s2, i3, s3) (type)((char*)buf + i0 * s0 + i1 * s1 + i2 * s2 + i3 * s3) -#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) - -static void __Pyx_RaiseBufferFallbackError(void); /*proto*/ -#define __Pyx_BufPtrStrided3d(type, buf, i0, s0, i1, s1, i2, s2) (type)((char*)buf + i0 * s0 + i1 * s1 + i2 * s2) -static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ - -static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */ - -static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { - if (likely(PyList_CheckExact(L))) { - if (PyList_Append(L, x) < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; /* this is just to have an accurate signature */ - } - else { - PyObject *r, *m; - m = __Pyx_GetAttrString(L, "append"); - if (!m) return NULL; - r = PyObject_CallFunctionObjArgs(m, x, NULL); - Py_DECREF(m); - return r; - } -} - -static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ -static int __Pyx_EndUnpack(PyObject *, Py_ssize_t expected); /*proto*/ - -#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_SetItemInt_Fast(o, i, v) : \ - __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) - -static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { - int r; - if (!j) return -1; - r = PyObject_SetItem(o, j, v); - Py_DECREF(j); - return r; -} - -static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { - if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { - Py_INCREF(v); - Py_DECREF(PyList_GET_ITEM(o, i)); - PyList_SET_ITEM(o, i, v); - return 1; - } - else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && (likely(i >= 0))) - return PySequence_SetItem(o, i, v); - else { - PyObject *j = PyInt_FromSsize_t(i); - return __Pyx_SetItemInt_Generic(o, j, v); - } -} - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /* proto */ - -#define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) - -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); - -static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/ -#if PY_MAJOR_VERSION < 3 -static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); -static void __Pyx_ReleaseBuffer(Py_buffer *view); -#else -#define __Pyx_GetBuffer PyObject_GetBuffer -#define __Pyx_ReleaseBuffer PyBuffer_Release -#endif - -Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0}; -Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1}; - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_intp(npy_intp); - -static CYTHON_INLINE npy_int32 __Pyx_PyInt_from_py_npy_int32(PyObject *); - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int32(npy_int32); - -static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/ -#if PY_MAJOR_VERSION >= 3 -static PyObject* __pyx_print = 0; -static PyObject* __pyx_print_kwargs = 0; -#endif - -static CYTHON_INLINE npy_int64 __Pyx_PyInt_from_py_npy_int64(PyObject *); - -static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int64(npy_int64); - -#if PY_VERSION_HEX < 0x02050000 -#ifndef PyAnySet_CheckExact - -#define PyAnySet_CheckExact(ob) \ - ((ob)->ob_type == &PySet_Type || \ - (ob)->ob_type == &PyFrozenSet_Type) - -#define PySet_New(iterable) \ - PyObject_CallFunctionObjArgs((PyObject *)&PySet_Type, (iterable), NULL) - -#define Pyx_PyFrozenSet_New(iterable) \ - PyObject_CallFunctionObjArgs((PyObject *)&PyFrozenSet_Type, (iterable), NULL) - -#define PySet_Size(anyset) \ - PyObject_Size((anyset)) - -#define PySet_Contains(anyset, key) \ - PySequence_Contains((anyset), (key)) - -#define PySet_Pop(set) \ - PyObject_CallMethod(set, (char *)"pop", NULL) - -static CYTHON_INLINE int PySet_Clear(PyObject *set) { - PyObject *ret = PyObject_CallMethod(set, (char *)"clear", NULL); - if (!ret) return -1; - Py_DECREF(ret); return 0; -} - -static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) { - PyObject *ret = PyObject_CallMethod(set, (char *)"discard", (char *)"O", key); - if (!ret) return -1; - Py_DECREF(ret); return 0; -} - -static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) { - PyObject *ret = PyObject_CallMethod(set, (char *)"add", (char *)"O", key); - if (!ret) return -1; - Py_DECREF(ret); return 0; -} - -#endif /* PyAnySet_CheckExact (<= Py2.4) */ - -#if PY_VERSION_HEX < 0x02040000 -#ifndef Py_SETOBJECT_H -#define Py_SETOBJECT_H - -static PyTypeObject *__Pyx_PySet_Type = NULL; -static PyTypeObject *__Pyx_PyFrozenSet_Type = NULL; - -#define PySet_Type (*__Pyx_PySet_Type) -#define PyFrozenSet_Type (*__Pyx_PyFrozenSet_Type) - -#define PyAnySet_Check(ob) \ - (PyAnySet_CheckExact(ob) || \ - PyType_IsSubtype((ob)->ob_type, &PySet_Type) || \ - PyType_IsSubtype((ob)->ob_type, &PyFrozenSet_Type)) - -#define PyFrozenSet_CheckExact(ob) ((ob)->ob_type == &PyFrozenSet_Type) - -static int __Pyx_Py23SetsImport(void) { - PyObject *sets=0, *Set=0, *ImmutableSet=0; - - sets = PyImport_ImportModule((char *)"sets"); - if (!sets) goto bad; - Set = PyObject_GetAttrString(sets, (char *)"Set"); - if (!Set) goto bad; - ImmutableSet = PyObject_GetAttrString(sets, (char *)"ImmutableSet"); - if (!ImmutableSet) goto bad; - Py_DECREF(sets); - - __Pyx_PySet_Type = (PyTypeObject*) Set; - __Pyx_PyFrozenSet_Type = (PyTypeObject*) ImmutableSet; - - return 0; - - bad: - Py_XDECREF(sets); - Py_XDECREF(Set); - Py_XDECREF(ImmutableSet); - return -1; -} - -#else -static int __Pyx_Py23SetsImport(void) { return 0; } -#endif /* !Py_SETOBJECT_H */ -#endif /* < Py2.4 */ -#endif /* < Py2.5 */ - -static CYTHON_INLINE png_uint_32 __Pyx_PyInt_from_py_png_uint_32(PyObject *); - -static CYTHON_INLINE long __Pyx_pow_long(long, long); /* proto */ - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #define __Pyx_CREAL(z) ((z).real()) - #define __Pyx_CIMAG(z) ((z).imag()) - #else - #define __Pyx_CREAL(z) (__real__(z)) - #define __Pyx_CIMAG(z) (__imag__(z)) - #endif -#else - #define __Pyx_CREAL(z) ((z).real) - #define __Pyx_CIMAG(z) ((z).imag) -#endif - -#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX - #define __Pyx_SET_CREAL(z,x) ((z).real(x)) - #define __Pyx_SET_CIMAG(z,y) ((z).imag(y)) -#else - #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x) - #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y) -#endif - -static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eqf(a, b) ((a)==(b)) - #define __Pyx_c_sumf(a, b) ((a)+(b)) - #define __Pyx_c_difff(a, b) ((a)-(b)) - #define __Pyx_c_prodf(a, b) ((a)*(b)) - #define __Pyx_c_quotf(a, b) ((a)/(b)) - #define __Pyx_c_negf(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zerof(z) ((z)==(float)0) - #define __Pyx_c_conjf(z) (::std::conj(z)) - /*#define __Pyx_c_absf(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zerof(z) ((z)==0) - #define __Pyx_c_conjf(z) (conjf(z)) - /*#define __Pyx_c_absf(z) (cabsf(z))*/ - #endif -#else - static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex); - static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex); - /*static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);*/ -#endif - -static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eq(a, b) ((a)==(b)) - #define __Pyx_c_sum(a, b) ((a)+(b)) - #define __Pyx_c_diff(a, b) ((a)-(b)) - #define __Pyx_c_prod(a, b) ((a)*(b)) - #define __Pyx_c_quot(a, b) ((a)/(b)) - #define __Pyx_c_neg(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zero(z) ((z)==(double)0) - #define __Pyx_c_conj(z) (::std::conj(z)) - /*#define __Pyx_c_abs(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zero(z) ((z)==0) - #define __Pyx_c_conj(z) (conj(z)) - /*#define __Pyx_c_abs(z) (cabs(z))*/ - #endif -#else - static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex); - static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex); - /*static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);*/ -#endif - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static void __Pyx_WriteUnraisable(const char *name); /*proto*/ - -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict); /*proto*/ - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static void __Pyx_AddTraceback(const char *funcname); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ -/* Module declarations from cpython.buffer */ - -/* Module declarations from cpython.ref */ - -/* Module declarations from libc.stdio */ - -/* Module declarations from cpython.object */ - -/* Module declarations from libc.stdlib */ - -/* Module declarations from numpy */ - -/* Module declarations from numpy */ - -static PyTypeObject *__pyx_ptype_5numpy_dtype = 0; -static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0; -static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0; -static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *, PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *, PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/ -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *); /*proto*/ -/* Module declarations from cython */ - -/* Module declarations from stdlib */ - -/* Module declarations from stdio */ - -/* Module declarations from yt.amr_utils */ - -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_position = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_OctreeGrid = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_OctreeGridList = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_VectorPlane = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_TransferFunctionProxy = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_PartitionedGrid = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_GridFace = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_ProtoPrism = 0; -static PyTypeObject *__pyx_ptype_2yt_9amr_utils_QuadTree = 0; -static CYTHON_INLINE void __pyx_f_2yt_9amr_utils_set_rotated_pos(__pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t (*)[3], __pyx_t_5numpy_float64_t *, int, int, int); /*proto*/ -static void __pyx_f_2yt_9amr_utils_normalize_vector(__pyx_t_5numpy_float64_t *); /*proto*/ -static void __pyx_f_2yt_9amr_utils_get_cross_product(__pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *); /*proto*/ -static int __pyx_f_2yt_9amr_utils_check_projected_overlap(__pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, int, __pyx_t_5numpy_float64_t (*)[3], __pyx_t_5numpy_float64_t (*)[3]); /*proto*/ -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_imax(int, int); /*proto*/ -static CYTHON_INLINE __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_fmax(__pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t); /*proto*/ -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_imin(int, int); /*proto*/ -static CYTHON_INLINE __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_fmin(__pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t); /*proto*/ -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_iclip(int, int, int); /*proto*/ -static CYTHON_INLINE __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_fclip(__pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t); /*proto*/ -static void __pyx_f_2yt_9amr_utils_FIT_initialize_table(struct __pyx_t_2yt_9amr_utils_FieldInterpolationTable *, int, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, int, struct __pyx_opt_args_2yt_9amr_utils_FIT_initialize_table *__pyx_optional_args); /*proto*/ -static __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_FIT_get_value(struct __pyx_t_2yt_9amr_utils_FieldInterpolationTable *, __pyx_t_5numpy_float64_t *); /*proto*/ -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9amr_utils_i64max(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /*proto*/ -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9amr_utils_i64min(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /*proto*/ -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_are_neighbors(__pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t); /*proto*/ -static void __pyx_f_2yt_9amr_utils_QTN_add_value(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t); /*proto*/ -static void __pyx_f_2yt_9amr_utils_QTN_refine(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *); /*proto*/ -static struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_f_2yt_9amr_utils_QTN_initialize(__pyx_t_5numpy_int64_t *, int, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t, int); /*proto*/ -static void __pyx_f_2yt_9amr_utils_QTN_free(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *); /*proto*/ -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t = { "int32_t", NULL, sizeof(__pyx_t_5numpy_int32_t), 'I' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t = { "float64_t", NULL, sizeof(__pyx_t_5numpy_float64_t), 'R' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int_t = { "int_t", NULL, sizeof(__pyx_t_5numpy_int_t), 'I' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t = { "int8_t", NULL, sizeof(__pyx_t_5numpy_int8_t), 'I' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float_t = { "float_t", NULL, sizeof(__pyx_t_5numpy_float_t), 'R' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t = { "int64_t", NULL, sizeof(__pyx_t_5numpy_int64_t), 'I' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t = { "float32_t", NULL, sizeof(__pyx_t_5numpy_float32_t), 'R' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t = { "uint8_t", NULL, sizeof(__pyx_t_5numpy_uint8_t), 'U' }; -#define __Pyx_MODULE_NAME "yt.amr_utils" -int __pyx_module_is_main_yt__amr_utils = 0; - -/* Implementation of yt.amr_utils */ -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_xrange; -static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_builtin_ValueError; -static char __pyx_k_1[] = "RecurseOctreeDepthFirst"; -static char __pyx_k_2[] = "RecurseOctreeByLevels"; -static char __pyx_k_3[] = "Field table"; -static char __pyx_k_4[] = "corresponds to"; -static char __pyx_k_5[] = "(Weighted with "; -static char __pyx_k_6[] = ")"; -static char __pyx_k_7[] = "ndarray is not C contiguous"; -static char __pyx_k_8[] = "ndarray is not Fortran contiguous"; -static char __pyx_k_9[] = "Non-native byte order not supported"; -static char __pyx_k_10[] = "unknown dtype code in numpy.pxd (%d)"; -static char __pyx_k_11[] = "Format string allocated too short, see comment in numpy.pxd"; -static char __pyx_k_12[] = "Format string allocated too short."; -static char __pyx_k_13[] = "\nContainer file to hold all our Cython routines. This is to avoid problems with\nstatic linking.\n\nAuthor: Matthew Turk \nAffiliation: KIPAC/SLAC/Stanford\nHomepage: http://yt.enzotools.org/\nLicense:\n Copyright (C) 2008 Matthew Turk. All Rights Reserved.\n\n This file is part of yt.\n\n yt is free software; you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation; either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see .\n"; -static char __pyx_k_14[] = "Transfer3D (line 36)"; -static char __pyx_k_15[] = "TransferShells (line 74)"; -static char __pyx_k__B[] = "B"; -static char __pyx_k__F[] = "F"; -static char __pyx_k__H[] = "H"; -static char __pyx_k__I[] = "I"; -static char __pyx_k__L[] = "L"; -static char __pyx_k__O[] = "O"; -static char __pyx_k__Q[] = "Q"; -static char __pyx_k__a[] = "a"; -static char __pyx_k__b[] = "b"; -static char __pyx_k__d[] = "d"; -static char __pyx_k__e[] = "e"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__g[] = "g"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__l[] = "l"; -static char __pyx_k__q[] = "q"; -static char __pyx_k__u[] = "u"; -static char __pyx_k__v[] = "v"; -static char __pyx_k__x[] = "x"; -static char __pyx_k__y[] = "y"; -static char __pyx_k__z[] = "z"; -static char __pyx_k__Zd[] = "Zd"; -static char __pyx_k__Zf[] = "Zf"; -static char __pyx_k__Zg[] = "Zg"; -static char __pyx_k__cm[] = "cm"; -static char __pyx_k__dx[] = "dx"; -static char __pyx_k__dy[] = "dy"; -static char __pyx_k__dz[] = "dz"; -static char __pyx_k__fn[] = "fn"; -static char __pyx_k__gi[] = "gi"; -static char __pyx_k__np[] = "np"; -static char __pyx_k__ns[] = "ns"; -static char __pyx_k__nv[] = "nv"; -static char __pyx_k__pv[] = "pv"; -static char __pyx_k__px[] = "px"; -static char __pyx_k__py[] = "py"; -static char __pyx_k__rb[] = "rb"; -static char __pyx_k__tf[] = "tf"; -static char __pyx_k__ug[] = "ug"; -static char __pyx_k__vp[] = "vp"; -static char __pyx_k__wb[] = "wb"; -static char __pyx_k__buf[] = "buf"; -static char __pyx_k__dds[] = "dds"; -static char __pyx_k__dpi[] = "dpi"; -static char __pyx_k__dvs[] = "dvs"; -static char __pyx_k__i_f[] = "i_f"; -static char __pyx_k__i_i[] = "i_i"; -static char __pyx_k__i_s[] = "i_s"; -static char __pyx_k__ind[] = "ind"; -static char __pyx_k__j_f[] = "j_f"; -static char __pyx_k__j_i[] = "j_i"; -static char __pyx_k__k_f[] = "k_f"; -static char __pyx_k__k_i[] = "k_i"; -static char __pyx_k__o_s[] = "o_s"; -static char __pyx_k__obj[] = "obj"; -static char __pyx_k__pdx[] = "pdx"; -static char __pyx_k__pdy[] = "pdy"; -static char __pyx_k__po2[] = "po2"; -static char __pyx_k__pos[] = "pos"; -static char __pyx_k__pxs[] = "pxs"; -static char __pyx_k__pys[] = "pys"; -static char __pyx_k__red[] = "red"; -static char __pyx_k__val[] = "val"; -static char __pyx_k__base[] = "base"; -static char __pyx_k__blue[] = "blue"; -static char __pyx_k__copy[] = "copy"; -static char __pyx_k__data[] = "data"; -static char __pyx_k__dbin[] = "dbin"; -static char __pyx_k__dims[] = "dims"; -static char __pyx_k__gray[] = "gray"; -static char __pyx_k__grid[] = "grid"; -static char __pyx_k__idds[] = "idds"; -static char __pyx_k__imax[] = "imax"; -static char __pyx_k__imin[] = "imin"; -static char __pyx_k__int8[] = "int8"; -static char __pyx_k__jmax[] = "jmax"; -static char __pyx_k__jmin[] = "jmin"; -static char __pyx_k__kmax[] = "kmax"; -static char __pyx_k__kmin[] = "kmin"; -static char __pyx_k__left[] = "left"; -static char __pyx_k__mask[] = "mask"; -static char __pyx_k__mass[] = "mass"; -static char __pyx_k__ndim[] = "ndim"; -static char __pyx_k__posx[] = "posx"; -static char __pyx_k__posy[] = "posy"; -static char __pyx_k__posz[] = "posz"; -static char __pyx_k__x_is[] = "x_is"; -static char __pyx_k__y_is[] = "y_is"; -static char __pyx_k__z_is[] = "z_is"; -static char __pyx_k__alpha[] = "alpha"; -static char __pyx_k__coord[] = "coord"; -static char __pyx_k__descr[] = "descr"; -static char __pyx_k__dtype[] = "dtype"; -static char __pyx_k__empty[] = "empty"; -static char __pyx_k__field[] = "field"; -static char __pyx_k__floor[] = "floor"; -static char __pyx_k__green[] = "green"; -static char __pyx_k__grids[] = "grids"; -static char __pyx_k__idbin[] = "idbin"; -static char __pyx_k__image[] = "image"; -static char __pyx_k__int32[] = "int32"; -static char __pyx_k__int64[] = "int64"; -static char __pyx_k__joins[] = "joins"; -static char __pyx_k__level[] = "level"; -static char __pyx_k__names[] = "names"; -static char __pyx_k__nbins[] = "nbins"; -static char __pyx_k__numpy[] = "numpy"; -static char __pyx_k__nvals[] = "nvals"; -static char __pyx_k__order[] = "order"; -static char __pyx_k__pmask[] = "pmask"; -static char __pyx_k__pvals[] = "pvals"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__shape[] = "shape"; -static char __pyx_k__split[] = "split"; -static char __pyx_k__stack[] = "stack"; -static char __pyx_k__sweep[] = "sweep"; -static char __pyx_k__table[] = "table"; -static char __pyx_k__wvals[] = "wvals"; -static char __pyx_k__x_vec[] = "x_vec"; -static char __pyx_k__y_vec[] = "y_vec"; -static char __pyx_k__zeros[] = "zeros"; -static char __pyx_k__aimage[] = "aimage"; -static char __pyx_k__ax_vec[] = "ax_vec"; -static char __pyx_k__ay_vec[] = "ay_vec"; -static char __pyx_k__bounds[] = "bounds"; -static char __pyx_k__buffer[] = "buffer"; -static char __pyx_k__center[] = "center"; -static char __pyx_k__curpos[] = "curpos"; -static char __pyx_k__fields[] = "fields"; -static char __pyx_k__format[] = "format"; -static char __pyx_k__grid_t[] = "grid_t"; -static char __pyx_k__offset[] = "offset"; -static char __pyx_k__output[] = "output"; -static char __pyx_k__points[] = "points"; -static char __pyx_k__shells[] = "shells"; -static char __pyx_k__tables[] = "tables"; -static char __pyx_k__tf_obj[] = "tf_obj"; -static char __pyx_k__values[] = "values"; -static char __pyx_k__vp_dir[] = "vp_dir"; -static char __pyx_k__vp_pos[] = "vp_pos"; -static char __pyx_k__x_bins[] = "x_bins"; -static char __pyx_k__x_vals[] = "x_vals"; -static char __pyx_k__xrange[] = "xrange"; -static char __pyx_k__y_bins[] = "y_bins"; -static char __pyx_k__y_vals[] = "y_vals"; -static char __pyx_k__z_bins[] = "z_bins"; -static char __pyx_k__z_vals[] = "z_vals"; -static char __pyx_k__Channel[] = "Channel"; -static char __pyx_k__acenter[] = "acenter"; -static char __pyx_k__avp_dir[] = "avp_dir"; -static char __pyx_k__avp_pos[] = "avp_pos"; -static char __pyx_k__corners[] = "corners"; -static char __pyx_k__float32[] = "float32"; -static char __pyx_k__float64[] = "float64"; -static char __pyx_k__grid_dt[] = "grid_dt"; -static char __pyx_k__istride[] = "istride"; -static char __pyx_k__jstride[] = "jstride"; -static char __pyx_k__max_ind[] = "max_ind"; -static char __pyx_k__my_data[] = "my_data"; -static char __pyx_k__nshells[] = "nshells"; -static char __pyx_k__refined[] = "refined"; -static char __pyx_k__rot_mat[] = "rot_mat"; -static char __pyx_k__strides[] = "strides"; -static char __pyx_k__LeftEdge[] = "LeftEdge"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__cellSize[] = "cellSize"; -static char __pyx_k__children[] = "children"; -static char __pyx_k__field_id[] = "field_id"; -static char __pyx_k__filename[] = "filename"; -static char __pyx_k__grid_dds[] = "grid_dds"; -static char __pyx_k__istorage[] = "istorage"; -static char __pyx_k__itemsize[] = "itemsize"; -static char __pyx_k__leftEdge[] = "leftEdge"; -static char __pyx_k__n_fields[] = "n_fields"; -static char __pyx_k__readonly[] = "readonly"; -static char __pyx_k__type_num[] = "type_num"; -static char __pyx_k__x_bounds[] = "x_bounds"; -static char __pyx_k__RightEdge[] = "RightEdge"; -static char __pyx_k__byteorder[] = "byteorder"; -static char __pyx_k__copy_back[] = "copy_back"; -static char __pyx_k__copy_into[] = "copy_into"; -static char __pyx_k__direction[] = "direction"; -static char __pyx_k__field_ids[] = "field_ids"; -static char __pyx_k__genealogy[] = "genealogy"; -static char __pyx_k__grid_mask[] = "grid_mask"; -static char __pyx_k__left_edge[] = "left_edge"; -static char __pyx_k__root_size[] = "root_size"; -static char __pyx_k__slab_size[] = "slab_size"; -static char __pyx_k__Transfer3D[] = "Transfer3D"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__box_center[] = "box_center"; -static char __pyx_k__box_origin[] = "box_origin"; -static char __pyx_k__child_mask[] = "child_mask"; -static char __pyx_k__count_only[] = "count_only"; -static char __pyx_k__dimensions[] = "dimensions"; -static char __pyx_k__im_strides[] = "im_strides"; -static char __pyx_k__left_edges[] = "left_edges"; -static char __pyx_k__npositions[] = "npositions"; -static char __pyx_k__output_pos[] = "output_pos"; -static char __pyx_k__right_edge[] = "right_edge"; -static char __pyx_k__root_nodes[] = "root_nodes"; -static char __pyx_k__slab_start[] = "slab_start"; -static char __pyx_k__suboffsets[] = "suboffsets"; -static char __pyx_k__vd_strides[] = "vd_strides"; -static char __pyx_k__vp_strides[] = "vp_strides"; -static char __pyx_k__weight_val[] = "weight_val"; -static char __pyx_k__box_lengths[] = "box_lengths"; -static char __pyx_k__box_vectors[] = "box_vectors"; -static char __pyx_k__break_first[] = "break_first"; -static char __pyx_k__refined_pos[] = "refined_pos"; -static char __pyx_k__start_index[] = "start_index"; -static char __pyx_k__RuntimeError[] = "RuntimeError"; -static char __pyx_k__field_tables[] = "field_tables"; -static char __pyx_k__pass_through[] = "pass_through"; -static char __pyx_k__proj_overlap[] = "proj_overlap"; -static char __pyx_k__pweight_vals[] = "pweight_vals"; -static char __pyx_k__child_indices[] = "child_indices"; -static char __pyx_k__eval_transfer[] = "eval_transfer"; -static char __pyx_k__gridDimension[] = "gridDimension"; -static char __pyx_k__integrate_ray[] = "integrate_ray"; -static char __pyx_k__sample_values[] = "sample_values"; -static char __pyx_k__subgrid_faces[] = "subgrid_faces"; -static char __pyx_k__top_grid_dims[] = "top_grid_dims"; -static char __pyx_k__TransferShells[] = "TransferShells"; -static char __pyx_k__count_at_level[] = "count_at_level"; -static char __pyx_k__get_start_stop[] = "get_start_stop"; -static char __pyx_k__grid_left_edge[] = "grid_left_edge"; -static char __pyx_k__n_field_tables[] = "n_field_tables"; -static char __pyx_k__parent_grid_id[] = "parent_grid_id"; -static char __pyx_k__add_to_position[] = "add_to_position"; -static char __pyx_k__field_table_ids[] = "field_table_ids"; -static char __pyx_k__fill_from_level[] = "fill_from_level"; -static char __pyx_k__grid_left_edges[] = "grid_left_edges"; -static char __pyx_k__grid_right_edge[] = "grid_right_edge"; -static char __pyx_k__my_field_tables[] = "my_field_tables"; -static char __pyx_k__weight_field_id[] = "weight_field_id"; -static char __pyx_k__weight_table_id[] = "weight_table_id"; -static char __pyx_k__calculate_extent[] = "calculate_extent"; -static char __pyx_k__grid_right_edges[] = "grid_right_edges"; -static char __pyx_k__weight_field_ids[] = "weight_field_ids"; -static char __pyx_k__weight_table_ids[] = "weight_table_ids"; -static char __pyx_k__find_on_root_level[] = "find_on_root_level"; -static PyObject *__pyx_n_s_1; -static PyObject *__pyx_kp_u_10; -static PyObject *__pyx_kp_u_11; -static PyObject *__pyx_kp_u_12; -static PyObject *__pyx_kp_u_14; -static PyObject *__pyx_kp_u_15; -static PyObject *__pyx_n_s_2; -static PyObject *__pyx_kp_s_3; -static PyObject *__pyx_kp_s_4; -static PyObject *__pyx_kp_s_5; -static PyObject *__pyx_kp_s_6; -static PyObject *__pyx_kp_u_7; -static PyObject *__pyx_kp_u_8; -static PyObject *__pyx_kp_u_9; -static PyObject *__pyx_n_s__Channel; -static PyObject *__pyx_n_s__F; -static PyObject *__pyx_n_s__LeftEdge; -static PyObject *__pyx_n_s__RightEdge; -static PyObject *__pyx_n_s__RuntimeError; -static PyObject *__pyx_n_s__Transfer3D; -static PyObject *__pyx_n_s__TransferShells; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__a; -static PyObject *__pyx_n_s__acenter; -static PyObject *__pyx_n_s__add_to_position; -static PyObject *__pyx_n_s__aimage; -static PyObject *__pyx_n_s__alpha; -static PyObject *__pyx_n_s__avp_dir; -static PyObject *__pyx_n_s__avp_pos; -static PyObject *__pyx_n_s__ax_vec; -static PyObject *__pyx_n_s__ay_vec; -static PyObject *__pyx_n_s__base; -static PyObject *__pyx_n_s__blue; -static PyObject *__pyx_n_s__bounds; -static PyObject *__pyx_n_s__box_center; -static PyObject *__pyx_n_s__box_lengths; -static PyObject *__pyx_n_s__box_origin; -static PyObject *__pyx_n_s__box_vectors; -static PyObject *__pyx_n_s__break_first; -static PyObject *__pyx_n_s__buf; -static PyObject *__pyx_n_s__buffer; -static PyObject *__pyx_n_s__byteorder; -static PyObject *__pyx_n_s__calculate_extent; -static PyObject *__pyx_n_s__cellSize; -static PyObject *__pyx_n_s__center; -static PyObject *__pyx_n_s__child_indices; -static PyObject *__pyx_n_s__child_mask; -static PyObject *__pyx_n_s__children; -static PyObject *__pyx_n_s__cm; -static PyObject *__pyx_n_s__coord; -static PyObject *__pyx_n_s__copy; -static PyObject *__pyx_n_s__copy_back; -static PyObject *__pyx_n_s__copy_into; -static PyObject *__pyx_n_s__corners; -static PyObject *__pyx_n_s__count_at_level; -static PyObject *__pyx_n_s__count_only; -static PyObject *__pyx_n_s__curpos; -static PyObject *__pyx_n_s__data; -static PyObject *__pyx_n_s__dbin; -static PyObject *__pyx_n_s__dds; -static PyObject *__pyx_n_s__descr; -static PyObject *__pyx_n_s__dimensions; -static PyObject *__pyx_n_s__dims; -static PyObject *__pyx_n_s__direction; -static PyObject *__pyx_n_s__dpi; -static PyObject *__pyx_n_s__dtype; -static PyObject *__pyx_n_s__dvs; -static PyObject *__pyx_n_s__dx; -static PyObject *__pyx_n_s__dy; -static PyObject *__pyx_n_s__dz; -static PyObject *__pyx_n_s__e; -static PyObject *__pyx_n_s__empty; -static PyObject *__pyx_n_s__eval_transfer; -static PyObject *__pyx_n_s__field; -static PyObject *__pyx_n_s__field_id; -static PyObject *__pyx_n_s__field_ids; -static PyObject *__pyx_n_s__field_table_ids; -static PyObject *__pyx_n_s__field_tables; -static PyObject *__pyx_n_s__fields; -static PyObject *__pyx_n_s__filename; -static PyObject *__pyx_n_s__fill_from_level; -static PyObject *__pyx_n_s__find_on_root_level; -static PyObject *__pyx_n_s__float32; -static PyObject *__pyx_n_s__float64; -static PyObject *__pyx_n_s__floor; -static PyObject *__pyx_n_s__fn; -static PyObject *__pyx_n_s__format; -static PyObject *__pyx_n_s__genealogy; -static PyObject *__pyx_n_s__get_start_stop; -static PyObject *__pyx_n_s__gi; -static PyObject *__pyx_n_s__gray; -static PyObject *__pyx_n_s__green; -static PyObject *__pyx_n_s__grid; -static PyObject *__pyx_n_s__gridDimension; -static PyObject *__pyx_n_s__grid_dds; -static PyObject *__pyx_n_s__grid_dt; -static PyObject *__pyx_n_s__grid_left_edge; -static PyObject *__pyx_n_s__grid_left_edges; -static PyObject *__pyx_n_s__grid_mask; -static PyObject *__pyx_n_s__grid_right_edge; -static PyObject *__pyx_n_s__grid_right_edges; -static PyObject *__pyx_n_s__grid_t; -static PyObject *__pyx_n_s__grids; -static PyObject *__pyx_n_s__i_f; -static PyObject *__pyx_n_s__i_i; -static PyObject *__pyx_n_s__i_s; -static PyObject *__pyx_n_s__idbin; -static PyObject *__pyx_n_s__idds; -static PyObject *__pyx_n_s__im_strides; -static PyObject *__pyx_n_s__image; -static PyObject *__pyx_n_s__imax; -static PyObject *__pyx_n_s__imin; -static PyObject *__pyx_n_s__ind; -static PyObject *__pyx_n_s__int32; -static PyObject *__pyx_n_s__int64; -static PyObject *__pyx_n_s__int8; -static PyObject *__pyx_n_s__integrate_ray; -static PyObject *__pyx_n_s__istorage; -static PyObject *__pyx_n_s__istride; -static PyObject *__pyx_n_s__itemsize; -static PyObject *__pyx_n_s__j_f; -static PyObject *__pyx_n_s__j_i; -static PyObject *__pyx_n_s__jmax; -static PyObject *__pyx_n_s__jmin; -static PyObject *__pyx_n_s__joins; -static PyObject *__pyx_n_s__jstride; -static PyObject *__pyx_n_s__k_f; -static PyObject *__pyx_n_s__k_i; -static PyObject *__pyx_n_s__kmax; -static PyObject *__pyx_n_s__kmin; -static PyObject *__pyx_n_s__left; -static PyObject *__pyx_n_s__leftEdge; -static PyObject *__pyx_n_s__left_edge; -static PyObject *__pyx_n_s__left_edges; -static PyObject *__pyx_n_s__level; -static PyObject *__pyx_n_s__mask; -static PyObject *__pyx_n_s__mass; -static PyObject *__pyx_n_s__max_ind; -static PyObject *__pyx_n_s__my_data; -static PyObject *__pyx_n_s__my_field_tables; -static PyObject *__pyx_n_s__n_field_tables; -static PyObject *__pyx_n_s__n_fields; -static PyObject *__pyx_n_s__names; -static PyObject *__pyx_n_s__nbins; -static PyObject *__pyx_n_s__ndim; -static PyObject *__pyx_n_s__np; -static PyObject *__pyx_n_s__npositions; -static PyObject *__pyx_n_s__ns; -static PyObject *__pyx_n_s__nshells; -static PyObject *__pyx_n_s__numpy; -static PyObject *__pyx_n_s__nv; -static PyObject *__pyx_n_s__nvals; -static PyObject *__pyx_n_s__o_s; -static PyObject *__pyx_n_s__obj; -static PyObject *__pyx_n_s__offset; -static PyObject *__pyx_n_s__order; -static PyObject *__pyx_n_s__output; -static PyObject *__pyx_n_s__output_pos; -static PyObject *__pyx_n_s__parent_grid_id; -static PyObject *__pyx_n_s__pass_through; -static PyObject *__pyx_n_s__pdx; -static PyObject *__pyx_n_s__pdy; -static PyObject *__pyx_n_s__pmask; -static PyObject *__pyx_n_s__po2; -static PyObject *__pyx_n_s__points; -static PyObject *__pyx_n_s__pos; -static PyObject *__pyx_n_s__posx; -static PyObject *__pyx_n_s__posy; -static PyObject *__pyx_n_s__posz; -static PyObject *__pyx_n_s__proj_overlap; -static PyObject *__pyx_n_s__pv; -static PyObject *__pyx_n_s__pvals; -static PyObject *__pyx_n_s__pweight_vals; -static PyObject *__pyx_n_s__px; -static PyObject *__pyx_n_s__pxs; -static PyObject *__pyx_n_s__py; -static PyObject *__pyx_n_s__pys; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__readonly; -static PyObject *__pyx_n_s__red; -static PyObject *__pyx_n_s__refined; -static PyObject *__pyx_n_s__refined_pos; -static PyObject *__pyx_n_s__right_edge; -static PyObject *__pyx_n_s__root_nodes; -static PyObject *__pyx_n_s__root_size; -static PyObject *__pyx_n_s__rot_mat; -static PyObject *__pyx_n_s__sample_values; -static PyObject *__pyx_n_s__shape; -static PyObject *__pyx_n_s__shells; -static PyObject *__pyx_n_s__slab_size; -static PyObject *__pyx_n_s__slab_start; -static PyObject *__pyx_n_s__split; -static PyObject *__pyx_n_s__stack; -static PyObject *__pyx_n_s__start_index; -static PyObject *__pyx_n_s__strides; -static PyObject *__pyx_n_s__subgrid_faces; -static PyObject *__pyx_n_s__suboffsets; -static PyObject *__pyx_n_s__sweep; -static PyObject *__pyx_n_s__table; -static PyObject *__pyx_n_s__tables; -static PyObject *__pyx_n_s__tf; -static PyObject *__pyx_n_s__tf_obj; -static PyObject *__pyx_n_s__top_grid_dims; -static PyObject *__pyx_n_s__type_num; -static PyObject *__pyx_n_s__u; -static PyObject *__pyx_n_s__ug; -static PyObject *__pyx_n_s__v; -static PyObject *__pyx_n_s__val; -static PyObject *__pyx_n_s__values; -static PyObject *__pyx_n_s__vd_strides; -static PyObject *__pyx_n_s__vp; -static PyObject *__pyx_n_s__vp_dir; -static PyObject *__pyx_n_s__vp_pos; -static PyObject *__pyx_n_s__vp_strides; -static PyObject *__pyx_n_s__weight_field_id; -static PyObject *__pyx_n_s__weight_field_ids; -static PyObject *__pyx_n_s__weight_table_id; -static PyObject *__pyx_n_s__weight_table_ids; -static PyObject *__pyx_n_s__weight_val; -static PyObject *__pyx_n_s__wvals; -static PyObject *__pyx_n_s__x; -static PyObject *__pyx_n_s__x_bins; -static PyObject *__pyx_n_s__x_bounds; -static PyObject *__pyx_n_s__x_is; -static PyObject *__pyx_n_s__x_vals; -static PyObject *__pyx_n_s__x_vec; -static PyObject *__pyx_n_s__xrange; -static PyObject *__pyx_n_s__y; -static PyObject *__pyx_n_s__y_bins; -static PyObject *__pyx_n_s__y_is; -static PyObject *__pyx_n_s__y_vals; -static PyObject *__pyx_n_s__y_vec; -static PyObject *__pyx_n_s__z; -static PyObject *__pyx_n_s__z_bins; -static PyObject *__pyx_n_s__z_is; -static PyObject *__pyx_n_s__z_vals; -static PyObject *__pyx_n_s__zeros; -static PyObject *__pyx_int_0; -static PyObject *__pyx_int_1; -static PyObject *__pyx_int_2; -static PyObject *__pyx_int_3; -static PyObject *__pyx_int_15; - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":31 - * - * cdef class position: - * cdef public int output_pos, refined_pos # <<<<<<<<<<<<<< - * def __cinit__(self): - * self.output_pos = 0 - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_8position_10output_pos___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_8position_10output_pos___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_position *)__pyx_v_self)->output_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.position.output_pos.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_8position_10output_pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_8position_10output_pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_position *)__pyx_v_self)->output_pos = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.position.output_pos.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_8position_11refined_pos___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_8position_11refined_pos___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_position *)__pyx_v_self)->refined_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.position.refined_pos.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_8position_11refined_pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_8position_11refined_pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_position *)__pyx_v_self)->refined_pos = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.position.refined_pos.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":32 - * cdef class position: - * cdef public int output_pos, refined_pos - * def __cinit__(self): # <<<<<<<<<<<<<< - * self.output_pos = 0 - * self.refined_pos = 0 - */ - -static int __pyx_pf_2yt_9amr_utils_8position___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_8position___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":33 - * cdef public int output_pos, refined_pos - * def __cinit__(self): - * self.output_pos = 0 # <<<<<<<<<<<<<< - * self.refined_pos = 0 - * - */ - ((struct __pyx_obj_2yt_9amr_utils_position *)__pyx_v_self)->output_pos = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":34 - * def __cinit__(self): - * self.output_pos = 0 - * self.refined_pos = 0 # <<<<<<<<<<<<<< - * - * cdef class OctreeGrid: - */ - ((struct __pyx_obj_2yt_9amr_utils_position *)__pyx_v_self)->refined_pos = 0; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":37 - * - * cdef class OctreeGrid: - * cdef public object child_indices, fields, left_edges, dimensions, dx # <<<<<<<<<<<<<< - * cdef public int level - * def __cinit__(self, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":38 - * cdef class OctreeGrid: - * cdef public object child_indices, fields, left_edges, dimensions, dx - * cdef public int level # <<<<<<<<<<<<<< - * def __cinit__(self, - * np.ndarray[np.int32_t, ndim=3] child_indices, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_5level___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10OctreeGrid_5level___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.OctreeGrid.level.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_5level___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid_5level___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->level = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.OctreeGrid.level.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":39 - * cdef public object child_indices, fields, left_edges, dimensions, dx - * cdef public int level - * def __cinit__(self, # <<<<<<<<<<<<<< - * np.ndarray[np.int32_t, ndim=3] child_indices, - * np.ndarray[np.float64_t, ndim=4] fields, - */ - -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10OctreeGrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_child_indices = 0; - PyArrayObject *__pyx_v_fields = 0; - PyArrayObject *__pyx_v_left_edges = 0; - PyArrayObject *__pyx_v_dimensions = 0; - PyArrayObject *__pyx_v_dx = 0; - int __pyx_v_level; - Py_buffer __pyx_bstruct_child_indices; - Py_ssize_t __pyx_bstride_0_child_indices = 0; - Py_ssize_t __pyx_bstride_1_child_indices = 0; - Py_ssize_t __pyx_bstride_2_child_indices = 0; - Py_ssize_t __pyx_bshape_0_child_indices = 0; - Py_ssize_t __pyx_bshape_1_child_indices = 0; - Py_ssize_t __pyx_bshape_2_child_indices = 0; - Py_buffer __pyx_bstruct_fields; - Py_ssize_t __pyx_bstride_0_fields = 0; - Py_ssize_t __pyx_bstride_1_fields = 0; - Py_ssize_t __pyx_bstride_2_fields = 0; - Py_ssize_t __pyx_bstride_3_fields = 0; - Py_ssize_t __pyx_bshape_0_fields = 0; - Py_ssize_t __pyx_bshape_1_fields = 0; - Py_ssize_t __pyx_bshape_2_fields = 0; - Py_ssize_t __pyx_bshape_3_fields = 0; - Py_buffer __pyx_bstruct_dx; - Py_ssize_t __pyx_bstride_0_dx = 0; - Py_ssize_t __pyx_bshape_0_dx = 0; - Py_buffer __pyx_bstruct_left_edges; - Py_ssize_t __pyx_bstride_0_left_edges = 0; - Py_ssize_t __pyx_bshape_0_left_edges = 0; - Py_buffer __pyx_bstruct_dimensions; - Py_ssize_t __pyx_bstride_0_dimensions = 0; - Py_ssize_t __pyx_bshape_0_dimensions = 0; - int __pyx_r; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__child_indices,&__pyx_n_s__fields,&__pyx_n_s__left_edges,&__pyx_n_s__dimensions,&__pyx_n_s__dx,&__pyx_n_s__level,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[6] = {0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_indices); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fields); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edges); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dimensions); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_child_indices = ((PyArrayObject *)values[0]); - __pyx_v_fields = ((PyArrayObject *)values[1]); - __pyx_v_left_edges = ((PyArrayObject *)values[2]); - __pyx_v_dimensions = ((PyArrayObject *)values[3]); - __pyx_v_dx = ((PyArrayObject *)values[4]); - __pyx_v_level = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_child_indices = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_fields = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_left_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_dimensions = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_dx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.OctreeGrid.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_child_indices.buf = NULL; - __pyx_bstruct_fields.buf = NULL; - __pyx_bstruct_left_edges.buf = NULL; - __pyx_bstruct_dimensions.buf = NULL; - __pyx_bstruct_dx.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_indices), __pyx_ptype_5numpy_ndarray, 1, "child_indices", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fields), __pyx_ptype_5numpy_ndarray, 1, "fields", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edges), __pyx_ptype_5numpy_ndarray, 1, "left_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dimensions), __pyx_ptype_5numpy_ndarray, 1, "dimensions", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dx), __pyx_ptype_5numpy_ndarray, 1, "dx", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_indices, (PyObject*)__pyx_v_child_indices, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_child_indices = __pyx_bstruct_child_indices.strides[0]; __pyx_bstride_1_child_indices = __pyx_bstruct_child_indices.strides[1]; __pyx_bstride_2_child_indices = __pyx_bstruct_child_indices.strides[2]; - __pyx_bshape_0_child_indices = __pyx_bstruct_child_indices.shape[0]; __pyx_bshape_1_child_indices = __pyx_bstruct_child_indices.shape[1]; __pyx_bshape_2_child_indices = __pyx_bstruct_child_indices.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_fields, (PyObject*)__pyx_v_fields, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_fields = __pyx_bstruct_fields.strides[0]; __pyx_bstride_1_fields = __pyx_bstruct_fields.strides[1]; __pyx_bstride_2_fields = __pyx_bstruct_fields.strides[2]; __pyx_bstride_3_fields = __pyx_bstruct_fields.strides[3]; - __pyx_bshape_0_fields = __pyx_bstruct_fields.shape[0]; __pyx_bshape_1_fields = __pyx_bstruct_fields.shape[1]; __pyx_bshape_2_fields = __pyx_bstruct_fields.shape[2]; __pyx_bshape_3_fields = __pyx_bstruct_fields.shape[3]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edges, (PyObject*)__pyx_v_left_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edges = __pyx_bstruct_left_edges.strides[0]; - __pyx_bshape_0_left_edges = __pyx_bstruct_left_edges.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dimensions, (PyObject*)__pyx_v_dimensions, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dimensions = __pyx_bstruct_dimensions.strides[0]; - __pyx_bshape_0_dimensions = __pyx_bstruct_dimensions.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dx, (PyObject*)__pyx_v_dx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dx = __pyx_bstruct_dx.strides[0]; - __pyx_bshape_0_dx = __pyx_bstruct_dx.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":46 - * np.ndarray[np.float64_t, ndim=1] dx, - * int level): - * self.child_indices = child_indices # <<<<<<<<<<<<<< - * self.fields = fields - * self.left_edges = left_edges - */ - __Pyx_INCREF(((PyObject *)__pyx_v_child_indices)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_child_indices)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->child_indices = ((PyObject *)__pyx_v_child_indices); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":47 - * int level): - * self.child_indices = child_indices - * self.fields = fields # <<<<<<<<<<<<<< - * self.left_edges = left_edges - * self.dimensions = dimensions - */ - __Pyx_INCREF(((PyObject *)__pyx_v_fields)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fields)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->fields = ((PyObject *)__pyx_v_fields); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":48 - * self.child_indices = child_indices - * self.fields = fields - * self.left_edges = left_edges # <<<<<<<<<<<<<< - * self.dimensions = dimensions - * self.dx = dx - */ - __Pyx_INCREF(((PyObject *)__pyx_v_left_edges)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_left_edges)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->left_edges = ((PyObject *)__pyx_v_left_edges); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":49 - * self.fields = fields - * self.left_edges = left_edges - * self.dimensions = dimensions # <<<<<<<<<<<<<< - * self.dx = dx - * self.level = level - */ - __Pyx_INCREF(((PyObject *)__pyx_v_dimensions)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_dimensions)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dimensions = ((PyObject *)__pyx_v_dimensions); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":50 - * self.left_edges = left_edges - * self.dimensions = dimensions - * self.dx = dx # <<<<<<<<<<<<<< - * self.level = level - * - */ - __Pyx_INCREF(((PyObject *)__pyx_v_dx)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_dx)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->dx = ((PyObject *)__pyx_v_dx); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":51 - * self.dimensions = dimensions - * self.dx = dx - * self.level = level # <<<<<<<<<<<<<< - * - * cdef class OctreeGridList: - */ - ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_v_self)->level = __pyx_v_level; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_indices); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_fields); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.OctreeGrid.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_indices); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_fields); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __pyx_L2:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":54 - * - * cdef class OctreeGridList: - * cdef public object grids # <<<<<<<<<<<<<< - * def __cinit__(self, grids): - * self.grids = grids - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":55 - * cdef class OctreeGridList: - * cdef public object grids - * def __cinit__(self, grids): # <<<<<<<<<<<<<< - * self.grids = grids - * - */ - -static int __pyx_pf_2yt_9amr_utils_14OctreeGridList___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_14OctreeGridList___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_grids = 0; - int __pyx_r; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__grids,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[1] = {0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grids); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_grids = values[0]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_grids = PyTuple_GET_ITEM(__pyx_args, 0); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.OctreeGridList.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":56 - * cdef public object grids - * def __cinit__(self, grids): - * self.grids = grids # <<<<<<<<<<<<<< - * - * def __getitem__(self, int item): - */ - __Pyx_INCREF(__pyx_v_grids); - __Pyx_GIVEREF(__pyx_v_grids); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids); - ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids = __pyx_v_grids; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":58 - * self.grids = grids - * - * def __getitem__(self, int item): # <<<<<<<<<<<<<< - * return self.grids[item] - * - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_14OctreeGridList___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_item); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_14OctreeGridList___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_item) { - int __pyx_v_item; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__getitem__"); - assert(__pyx_arg_item); { - __pyx_v_item = __Pyx_PyInt_AsInt(__pyx_arg_item); if (unlikely((__pyx_v_item == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.OctreeGridList.__getitem__"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":59 - * - * def __getitem__(self, int item): - * return self.grids[item] # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)__pyx_v_self)->grids, __pyx_v_item, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.OctreeGridList.__getitem__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":62 - * - * @cython.boundscheck(False) - * def RecurseOctreeDepthFirst(int i_i, int j_i, int k_i, # <<<<<<<<<<<<<< - * int i_f, int j_f, int k_f, - * position curpos, int gi, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_RecurseOctreeDepthFirst(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_RecurseOctreeDepthFirst(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_i_i; - int __pyx_v_j_i; - int __pyx_v_k_i; - int __pyx_v_i_f; - int __pyx_v_j_f; - int __pyx_v_k_f; - struct __pyx_obj_2yt_9amr_utils_position *__pyx_v_curpos = 0; - int __pyx_v_gi; - PyArrayObject *__pyx_v_output = 0; - PyArrayObject *__pyx_v_refined = 0; - struct __pyx_obj_2yt_9amr_utils_OctreeGridList *__pyx_v_grids = 0; - int __pyx_v_i; - int __pyx_v_i_off; - int __pyx_v_j; - int __pyx_v_j_off; - int __pyx_v_k; - int __pyx_v_k_off; - int __pyx_v_ci; - int __pyx_v_fi; - int __pyx_v_child_i; - int __pyx_v_child_j; - int __pyx_v_child_k; - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *__pyx_v_child_grid; - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *__pyx_v_grid = 0; - PyArrayObject *__pyx_v_child_indices = 0; - PyArrayObject *__pyx_v_dimensions = 0; - PyArrayObject *__pyx_v_fields = 0; - PyArrayObject *__pyx_v_leftedges = 0; - __pyx_t_5numpy_float64_t __pyx_v_dx; - __pyx_t_5numpy_float64_t __pyx_v_child_dx; - PyArrayObject *__pyx_v_child_leftedges; - __pyx_t_5numpy_float64_t __pyx_v_cx; - __pyx_t_5numpy_float64_t __pyx_v_cy; - __pyx_t_5numpy_float64_t __pyx_v_cz; - PyObject *__pyx_v_s; - Py_buffer __pyx_bstruct_leftedges; - Py_ssize_t __pyx_bstride_0_leftedges = 0; - Py_ssize_t __pyx_bshape_0_leftedges = 0; - Py_buffer __pyx_bstruct_refined; - Py_ssize_t __pyx_bstride_0_refined = 0; - Py_ssize_t __pyx_bshape_0_refined = 0; - Py_buffer __pyx_bstruct_child_leftedges; - Py_ssize_t __pyx_bstride_0_child_leftedges = 0; - Py_ssize_t __pyx_bshape_0_child_leftedges = 0; - Py_buffer __pyx_bstruct_dimensions; - Py_ssize_t __pyx_bstride_0_dimensions = 0; - Py_ssize_t __pyx_bshape_0_dimensions = 0; - Py_buffer __pyx_bstruct_child_indices; - Py_ssize_t __pyx_bstride_0_child_indices = 0; - Py_ssize_t __pyx_bstride_1_child_indices = 0; - Py_ssize_t __pyx_bstride_2_child_indices = 0; - Py_ssize_t __pyx_bshape_0_child_indices = 0; - Py_ssize_t __pyx_bshape_1_child_indices = 0; - Py_ssize_t __pyx_bshape_2_child_indices = 0; - Py_buffer __pyx_bstruct_fields; - Py_ssize_t __pyx_bstride_0_fields = 0; - Py_ssize_t __pyx_bstride_1_fields = 0; - Py_ssize_t __pyx_bstride_2_fields = 0; - Py_ssize_t __pyx_bstride_3_fields = 0; - Py_ssize_t __pyx_bshape_0_fields = 0; - Py_ssize_t __pyx_bshape_1_fields = 0; - Py_ssize_t __pyx_bshape_2_fields = 0; - Py_ssize_t __pyx_bshape_3_fields = 0; - Py_buffer __pyx_bstruct_output; - Py_ssize_t __pyx_bstride_0_output = 0; - Py_ssize_t __pyx_bstride_1_output = 0; - Py_ssize_t __pyx_bshape_0_output = 0; - Py_ssize_t __pyx_bshape_1_output = 0; - PyObject *__pyx_r = NULL; - long __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyArrayObject *__pyx_t_3 = NULL; - PyArrayObject *__pyx_t_4 = NULL; - PyArrayObject *__pyx_t_5 = NULL; - PyArrayObject *__pyx_t_6 = NULL; - __pyx_t_5numpy_float64_t __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - long __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - long __pyx_t_15; - PyObject *__pyx_t_16 = NULL; - PyObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - int __pyx_t_19; - int __pyx_t_20; - npy_intp __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - long __pyx_t_29; - PyArrayObject *__pyx_t_30 = NULL; - int __pyx_t_31; - PyObject *__pyx_t_32 = NULL; - PyObject *__pyx_t_33 = NULL; - PyObject *__pyx_t_34 = NULL; - long __pyx_t_35; - long __pyx_t_36; - PyObject *__pyx_t_37 = NULL; - PyObject *__pyx_t_38 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i_i,&__pyx_n_s__j_i,&__pyx_n_s__k_i,&__pyx_n_s__i_f,&__pyx_n_s__j_f,&__pyx_n_s__k_f,&__pyx_n_s__curpos,&__pyx_n_s__gi,&__pyx_n_s__output,&__pyx_n_s__refined,&__pyx_n_s__grids,0}; - __Pyx_RefNannySetupContext("RecurseOctreeDepthFirst"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_i); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_i); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k_i); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_f); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_f); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k_f); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__curpos); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gi); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 8: - values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__output); - if (likely(values[8])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 9: - values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refined); - if (likely(values[9])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 10: - values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grids); - if (likely(values[10])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, 10); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "RecurseOctreeDepthFirst") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_i_i = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_i_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_i = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_j_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_i = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_k_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_i_f = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_i_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_f = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_j_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_f = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_k_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_curpos = ((struct __pyx_obj_2yt_9amr_utils_position *)values[6]); - __pyx_v_gi = __Pyx_PyInt_AsInt(values[7]); if (unlikely((__pyx_v_gi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_output = ((PyArrayObject *)values[8]); - __pyx_v_refined = ((PyArrayObject *)values[9]); - __pyx_v_grids = ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)values[10]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 11) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_i_i = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_i_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_i = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_j_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_i = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_k_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_i_f = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_i_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_f = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_j_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_f = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_k_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_curpos = ((struct __pyx_obj_2yt_9amr_utils_position *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_gi = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 7)); if (unlikely((__pyx_v_gi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_output = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 8)); - __pyx_v_refined = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 9)); - __pyx_v_grids = ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)PyTuple_GET_ITEM(__pyx_args, 10)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("RecurseOctreeDepthFirst", 1, 11, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.RecurseOctreeDepthFirst"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_child_grid = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_child_leftedges = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_s = Py_None; __Pyx_INCREF(Py_None); - __pyx_bstruct_child_indices.buf = NULL; - __pyx_bstruct_dimensions.buf = NULL; - __pyx_bstruct_fields.buf = NULL; - __pyx_bstruct_leftedges.buf = NULL; - __pyx_bstruct_child_leftedges.buf = NULL; - __pyx_bstruct_output.buf = NULL; - __pyx_bstruct_refined.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_curpos), __pyx_ptype_2yt_9amr_utils_position, 1, "curpos", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output), __pyx_ptype_5numpy_ndarray, 1, "output", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_refined), __pyx_ptype_5numpy_ndarray, 1, "refined", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grids), __pyx_ptype_2yt_9amr_utils_OctreeGridList, 1, "grids", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_output, (PyObject*)__pyx_v_output, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_output = __pyx_bstruct_output.strides[0]; __pyx_bstride_1_output = __pyx_bstruct_output.strides[1]; - __pyx_bshape_0_output = __pyx_bstruct_output.shape[0]; __pyx_bshape_1_output = __pyx_bstruct_output.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_refined, (PyObject*)__pyx_v_refined, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_refined = __pyx_bstruct_refined.strides[0]; - __pyx_bshape_0_refined = __pyx_bstruct_refined.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":71 - * cdef int child_i, child_j, child_k - * cdef OctreeGrid child_grid - * cdef OctreeGrid grid = grids[gi-1] # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - */ - __pyx_t_1 = (__pyx_v_gi - 1); - __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_grids), __pyx_t_1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_2yt_9amr_utils_OctreeGrid))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_grid = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":72 - * cdef OctreeGrid child_grid - * cdef OctreeGrid grid = grids[gi-1] - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - */ - if (!(likely(((__pyx_v_grid->child_indices) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->child_indices, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = ((PyArrayObject *)__pyx_v_grid->child_indices); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_indices, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) { - __pyx_v_child_indices = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_child_indices.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_child_indices = __pyx_bstruct_child_indices.strides[0]; __pyx_bstride_1_child_indices = __pyx_bstruct_child_indices.strides[1]; __pyx_bstride_2_child_indices = __pyx_bstruct_child_indices.strides[2]; - __pyx_bshape_0_child_indices = __pyx_bstruct_child_indices.shape[0]; __pyx_bshape_1_child_indices = __pyx_bstruct_child_indices.shape[1]; __pyx_bshape_2_child_indices = __pyx_bstruct_child_indices.shape[2]; - } - } - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_v_grid->child_indices); - __pyx_v_child_indices = ((PyArrayObject *)__pyx_v_grid->child_indices); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":73 - * cdef OctreeGrid grid = grids[gi-1] - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - */ - if (!(likely(((__pyx_v_grid->dimensions) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->dimensions, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = ((PyArrayObject *)__pyx_v_grid->dimensions); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dimensions, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - __pyx_v_dimensions = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_dimensions.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_dimensions = __pyx_bstruct_dimensions.strides[0]; - __pyx_bshape_0_dimensions = __pyx_bstruct_dimensions.shape[0]; - } - } - __pyx_t_4 = 0; - __Pyx_INCREF(__pyx_v_grid->dimensions); - __pyx_v_dimensions = ((PyArrayObject *)__pyx_v_grid->dimensions); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":74 - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - * cdef np.float64_t dx = grid.dx[0] - */ - if (!(likely(((__pyx_v_grid->fields) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->fields, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((PyArrayObject *)__pyx_v_grid->fields); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_fields, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) { - __pyx_v_fields = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_fields.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_fields = __pyx_bstruct_fields.strides[0]; __pyx_bstride_1_fields = __pyx_bstruct_fields.strides[1]; __pyx_bstride_2_fields = __pyx_bstruct_fields.strides[2]; __pyx_bstride_3_fields = __pyx_bstruct_fields.strides[3]; - __pyx_bshape_0_fields = __pyx_bstruct_fields.shape[0]; __pyx_bshape_1_fields = __pyx_bstruct_fields.shape[1]; __pyx_bshape_2_fields = __pyx_bstruct_fields.shape[2]; __pyx_bshape_3_fields = __pyx_bstruct_fields.shape[3]; - } - } - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_v_grid->fields); - __pyx_v_fields = ((PyArrayObject *)__pyx_v_grid->fields); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":75 - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges # <<<<<<<<<<<<<< - * cdef np.float64_t dx = grid.dx[0] - * cdef np.float64_t child_dx - */ - if (!(likely(((__pyx_v_grid->left_edges) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->left_edges, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = ((PyArrayObject *)__pyx_v_grid->left_edges); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_leftedges, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - __pyx_v_leftedges = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_leftedges.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_leftedges = __pyx_bstruct_leftedges.strides[0]; - __pyx_bshape_0_leftedges = __pyx_bstruct_leftedges.shape[0]; - } - } - __pyx_t_6 = 0; - __Pyx_INCREF(__pyx_v_grid->left_edges); - __pyx_v_leftedges = ((PyArrayObject *)__pyx_v_grid->left_edges); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":76 - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - * cdef np.float64_t dx = grid.dx[0] # <<<<<<<<<<<<<< - * cdef np.float64_t child_dx - * cdef np.ndarray[np.float64_t, ndim=1] child_leftedges - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_grid->dx, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_7 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_dx = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":80 - * cdef np.ndarray[np.float64_t, ndim=1] child_leftedges - * cdef np.float64_t cx, cy, cz - * for k_off in range(k_f): # <<<<<<<<<<<<<< - * k = k_off + k_i - * cz = (leftedges[2] + k*dx) - */ - __pyx_t_8 = __pyx_v_k_f; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_k_off = __pyx_t_9; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":81 - * cdef np.float64_t cx, cy, cz - * for k_off in range(k_f): - * k = k_off + k_i # <<<<<<<<<<<<<< - * cz = (leftedges[2] + k*dx) - * for j_off in range(j_f): - */ - __pyx_v_k = (__pyx_v_k_off + __pyx_v_k_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":82 - * for k_off in range(k_f): - * k = k_off + k_i - * cz = (leftedges[2] + k*dx) # <<<<<<<<<<<<<< - * for j_off in range(j_f): - * j = j_off + j_i - */ - __pyx_t_1 = 2; - if (__pyx_t_1 < 0) __pyx_t_1 += __pyx_bshape_0_leftedges; - __pyx_v_cz = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftedges.buf, __pyx_t_1, __pyx_bstride_0_leftedges)) + (__pyx_v_k * __pyx_v_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":83 - * k = k_off + k_i - * cz = (leftedges[2] + k*dx) - * for j_off in range(j_f): # <<<<<<<<<<<<<< - * j = j_off + j_i - * cy = (leftedges[1] + j*dx) - */ - __pyx_t_10 = __pyx_v_j_f; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_j_off = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":84 - * cz = (leftedges[2] + k*dx) - * for j_off in range(j_f): - * j = j_off + j_i # <<<<<<<<<<<<<< - * cy = (leftedges[1] + j*dx) - * for i_off in range(i_f): - */ - __pyx_v_j = (__pyx_v_j_off + __pyx_v_j_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":85 - * for j_off in range(j_f): - * j = j_off + j_i - * cy = (leftedges[1] + j*dx) # <<<<<<<<<<<<<< - * for i_off in range(i_f): - * i = i_off + i_i - */ - __pyx_t_12 = 1; - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_0_leftedges; - __pyx_v_cy = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftedges.buf, __pyx_t_12, __pyx_bstride_0_leftedges)) + (__pyx_v_j * __pyx_v_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":86 - * j = j_off + j_i - * cy = (leftedges[1] + j*dx) - * for i_off in range(i_f): # <<<<<<<<<<<<<< - * i = i_off + i_i - * cx = (leftedges[0] + i*dx) - */ - __pyx_t_13 = __pyx_v_i_f; - for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { - __pyx_v_i_off = __pyx_t_14; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":87 - * cy = (leftedges[1] + j*dx) - * for i_off in range(i_f): - * i = i_off + i_i # <<<<<<<<<<<<<< - * cx = (leftedges[0] + i*dx) - * ci = grid.child_indices[i,j,k] - */ - __pyx_v_i = (__pyx_v_i_off + __pyx_v_i_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":88 - * for i_off in range(i_f): - * i = i_off + i_i - * cx = (leftedges[0] + i*dx) # <<<<<<<<<<<<<< - * ci = grid.child_indices[i,j,k] - * if ci == -1: - */ - __pyx_t_15 = 0; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_0_leftedges; - __pyx_v_cx = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftedges.buf, __pyx_t_15, __pyx_bstride_0_leftedges)) + (__pyx_v_i * __pyx_v_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":89 - * i = i_off + i_i - * cx = (leftedges[0] + i*dx) - * ci = grid.child_indices[i,j,k] # <<<<<<<<<<<<<< - * if ci == -1: - * for fi in range(fields.shape[0]): - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_16 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_17 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_18 = PyTuple_New(3); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_16); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_2 = 0; - __pyx_t_16 = 0; - __pyx_t_17 = 0; - __pyx_t_17 = PyObject_GetItem(__pyx_v_grid->child_indices, __pyx_t_18); if (!__pyx_t_17) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_t_19 = __Pyx_PyInt_AsInt(__pyx_t_17); if (unlikely((__pyx_t_19 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __pyx_v_ci = __pyx_t_19; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":90 - * cx = (leftedges[0] + i*dx) - * ci = grid.child_indices[i,j,k] - * if ci == -1: # <<<<<<<<<<<<<< - * for fi in range(fields.shape[0]): - * output[curpos.output_pos,fi] = fields[fi,i,j,k] - */ - __pyx_t_20 = (__pyx_v_ci == -1); - if (__pyx_t_20) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":91 - * ci = grid.child_indices[i,j,k] - * if ci == -1: - * for fi in range(fields.shape[0]): # <<<<<<<<<<<<<< - * output[curpos.output_pos,fi] = fields[fi,i,j,k] - * refined[curpos.refined_pos] = 0 - */ - __pyx_t_21 = (__pyx_v_fields->dimensions[0]); - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_21; __pyx_t_19+=1) { - __pyx_v_fi = __pyx_t_19; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":92 - * if ci == -1: - * for fi in range(fields.shape[0]): - * output[curpos.output_pos,fi] = fields[fi,i,j,k] # <<<<<<<<<<<<<< - * refined[curpos.refined_pos] = 0 - * curpos.output_pos += 1 - */ - __pyx_t_22 = __pyx_v_fi; - __pyx_t_23 = __pyx_v_i; - __pyx_t_24 = __pyx_v_j; - __pyx_t_25 = __pyx_v_k; - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_0_fields; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_1_fields; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_2_fields; - if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_3_fields; - __pyx_t_26 = __pyx_v_curpos->output_pos; - __pyx_t_27 = __pyx_v_fi; - if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_0_output; - if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_1_output; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_output.buf, __pyx_t_26, __pyx_bstride_0_output, __pyx_t_27, __pyx_bstride_1_output) = (*__Pyx_BufPtrStrided4d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_fields.buf, __pyx_t_22, __pyx_bstride_0_fields, __pyx_t_23, __pyx_bstride_1_fields, __pyx_t_24, __pyx_bstride_2_fields, __pyx_t_25, __pyx_bstride_3_fields)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":93 - * for fi in range(fields.shape[0]): - * output[curpos.output_pos,fi] = fields[fi,i,j,k] - * refined[curpos.refined_pos] = 0 # <<<<<<<<<<<<<< - * curpos.output_pos += 1 - * curpos.refined_pos += 1 - */ - __pyx_t_19 = __pyx_v_curpos->refined_pos; - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_0_refined; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_refined.buf, __pyx_t_19, __pyx_bstride_0_refined) = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":94 - * output[curpos.output_pos,fi] = fields[fi,i,j,k] - * refined[curpos.refined_pos] = 0 - * curpos.output_pos += 1 # <<<<<<<<<<<<<< - * curpos.refined_pos += 1 - * else: - */ - __pyx_v_curpos->output_pos += 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":95 - * refined[curpos.refined_pos] = 0 - * curpos.output_pos += 1 - * curpos.refined_pos += 1 # <<<<<<<<<<<<<< - * else: - * refined[curpos.refined_pos] = 1 - */ - __pyx_v_curpos->refined_pos += 1; - goto __pyx_L12; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":97 - * curpos.refined_pos += 1 - * else: - * refined[curpos.refined_pos] = 1 # <<<<<<<<<<<<<< - * curpos.refined_pos += 1 - * child_grid = grids[ci-1] - */ - __pyx_t_28 = __pyx_v_curpos->refined_pos; - if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_0_refined; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_refined.buf, __pyx_t_28, __pyx_bstride_0_refined) = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":98 - * else: - * refined[curpos.refined_pos] = 1 - * curpos.refined_pos += 1 # <<<<<<<<<<<<<< - * child_grid = grids[ci-1] - * child_dx = child_grid.dx[0] - */ - __pyx_v_curpos->refined_pos += 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":99 - * refined[curpos.refined_pos] = 1 - * curpos.refined_pos += 1 - * child_grid = grids[ci-1] # <<<<<<<<<<<<<< - * child_dx = child_grid.dx[0] - * child_leftedges = child_grid.left_edges - */ - __pyx_t_29 = (__pyx_v_ci - 1); - __pyx_t_17 = __Pyx_GetItemInt(((PyObject *)__pyx_v_grids), __pyx_t_29, sizeof(long), PyInt_FromLong); if (!__pyx_t_17) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - if (!(likely(((__pyx_t_17) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_17, __pyx_ptype_2yt_9amr_utils_OctreeGrid))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_v_child_grid)); - __pyx_v_child_grid = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_t_17); - __pyx_t_17 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":100 - * curpos.refined_pos += 1 - * child_grid = grids[ci-1] - * child_dx = child_grid.dx[0] # <<<<<<<<<<<<<< - * child_leftedges = child_grid.left_edges - * child_i = int((cx - child_leftedges[0])/child_dx) - */ - __pyx_t_17 = __Pyx_GetItemInt(__pyx_v_child_grid->dx, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_17) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_17); if (unlikely((__pyx_t_7 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __pyx_v_child_dx = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":101 - * child_grid = grids[ci-1] - * child_dx = child_grid.dx[0] - * child_leftedges = child_grid.left_edges # <<<<<<<<<<<<<< - * child_i = int((cx - child_leftedges[0])/child_dx) - * child_j = int((cy - child_leftedges[1])/child_dx) - */ - if (!(likely(((__pyx_v_child_grid->left_edges) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_child_grid->left_edges, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_30 = ((PyArrayObject *)__pyx_v_child_grid->left_edges); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_leftedges); - __pyx_t_31 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_child_leftedges, (PyObject*)__pyx_t_30, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_31 < 0)) { - PyErr_Fetch(&__pyx_t_32, &__pyx_t_33, &__pyx_t_34); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_leftedges, (PyObject*)__pyx_v_child_leftedges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_32); Py_XDECREF(__pyx_t_33); Py_XDECREF(__pyx_t_34); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_32, __pyx_t_33, __pyx_t_34); - } - } - __pyx_bstride_0_child_leftedges = __pyx_bstruct_child_leftedges.strides[0]; - __pyx_bshape_0_child_leftedges = __pyx_bstruct_child_leftedges.shape[0]; - if (unlikely(__pyx_t_31 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_30 = 0; - __Pyx_INCREF(__pyx_v_child_grid->left_edges); - __Pyx_DECREF(((PyObject *)__pyx_v_child_leftedges)); - __pyx_v_child_leftedges = ((PyArrayObject *)__pyx_v_child_grid->left_edges); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":102 - * child_dx = child_grid.dx[0] - * child_leftedges = child_grid.left_edges - * child_i = int((cx - child_leftedges[0])/child_dx) # <<<<<<<<<<<<<< - * child_j = int((cy - child_leftedges[1])/child_dx) - * child_k = int((cz - child_leftedges[2])/child_dx) - */ - __pyx_t_29 = 0; - if (__pyx_t_29 < 0) __pyx_t_29 += __pyx_bshape_0_child_leftedges; - __pyx_t_7 = (__pyx_v_cx - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_child_leftedges.buf, __pyx_t_29, __pyx_bstride_0_child_leftedges))); - if (unlikely(__pyx_v_child_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_child_i = ((int)(__pyx_t_7 / __pyx_v_child_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":103 - * child_leftedges = child_grid.left_edges - * child_i = int((cx - child_leftedges[0])/child_dx) - * child_j = int((cy - child_leftedges[1])/child_dx) # <<<<<<<<<<<<<< - * child_k = int((cz - child_leftedges[2])/child_dx) - * s = RecurseOctreeDepthFirst(child_i, child_j, child_k, 2, 2, 2, - */ - __pyx_t_35 = 1; - if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_bshape_0_child_leftedges; - __pyx_t_7 = (__pyx_v_cy - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_child_leftedges.buf, __pyx_t_35, __pyx_bstride_0_child_leftedges))); - if (unlikely(__pyx_v_child_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_child_j = ((int)(__pyx_t_7 / __pyx_v_child_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":104 - * child_i = int((cx - child_leftedges[0])/child_dx) - * child_j = int((cy - child_leftedges[1])/child_dx) - * child_k = int((cz - child_leftedges[2])/child_dx) # <<<<<<<<<<<<<< - * s = RecurseOctreeDepthFirst(child_i, child_j, child_k, 2, 2, 2, - * curpos, ci, output, refined, grids) - */ - __pyx_t_36 = 2; - if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_bshape_0_child_leftedges; - __pyx_t_7 = (__pyx_v_cz - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_child_leftedges.buf, __pyx_t_36, __pyx_bstride_0_child_leftedges))); - if (unlikely(__pyx_v_child_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_child_k = ((int)(__pyx_t_7 / __pyx_v_child_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":105 - * child_j = int((cy - child_leftedges[1])/child_dx) - * child_k = int((cz - child_leftedges[2])/child_dx) - * s = RecurseOctreeDepthFirst(child_i, child_j, child_k, 2, 2, 2, # <<<<<<<<<<<<<< - * curpos, ci, output, refined, grids) - * return s - */ - __pyx_t_17 = __Pyx_GetName(__pyx_m, __pyx_n_s_1); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_18 = PyInt_FromLong(__pyx_v_child_i); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_16 = PyInt_FromLong(__pyx_v_child_j); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_2 = PyInt_FromLong(__pyx_v_child_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":106 - * child_k = int((cz - child_leftedges[2])/child_dx) - * s = RecurseOctreeDepthFirst(child_i, child_j, child_k, 2, 2, 2, - * curpos, ci, output, refined, grids) # <<<<<<<<<<<<<< - * return s - * - */ - __pyx_t_37 = PyInt_FromLong(__pyx_v_ci); if (unlikely(!__pyx_t_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_37); - __pyx_t_38 = PyTuple_New(11); if (unlikely(!__pyx_t_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_38); - PyTuple_SET_ITEM(__pyx_t_38, 0, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_38, 1, __pyx_t_16); - __Pyx_GIVEREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_38, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_38, 3, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_38, 4, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_38, 5, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(((PyObject *)__pyx_v_curpos)); - PyTuple_SET_ITEM(__pyx_t_38, 6, ((PyObject *)__pyx_v_curpos)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_curpos)); - PyTuple_SET_ITEM(__pyx_t_38, 7, __pyx_t_37); - __Pyx_GIVEREF(__pyx_t_37); - __Pyx_INCREF(((PyObject *)__pyx_v_output)); - PyTuple_SET_ITEM(__pyx_t_38, 8, ((PyObject *)__pyx_v_output)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_output)); - __Pyx_INCREF(((PyObject *)__pyx_v_refined)); - PyTuple_SET_ITEM(__pyx_t_38, 9, ((PyObject *)__pyx_v_refined)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_refined)); - __Pyx_INCREF(((PyObject *)__pyx_v_grids)); - PyTuple_SET_ITEM(__pyx_t_38, 10, ((PyObject *)__pyx_v_grids)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_grids)); - __pyx_t_18 = 0; - __pyx_t_16 = 0; - __pyx_t_2 = 0; - __pyx_t_37 = 0; - __pyx_t_37 = PyObject_Call(__pyx_t_17, __pyx_t_38, NULL); if (unlikely(!__pyx_t_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_37); - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_DECREF(__pyx_t_38); __pyx_t_38 = 0; - __Pyx_DECREF(__pyx_v_s); - __pyx_v_s = __pyx_t_37; - __pyx_t_37 = 0; - } - __pyx_L12:; - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":107 - * s = RecurseOctreeDepthFirst(child_i, child_j, child_k, 2, 2, 2, - * curpos, ci, output, refined, grids) - * return s # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_s); - __pyx_r = __pyx_v_s; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_16); - __Pyx_XDECREF(__pyx_t_17); - __Pyx_XDECREF(__pyx_t_18); - __Pyx_XDECREF(__pyx_t_37); - __Pyx_XDECREF(__pyx_t_38); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_refined); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_indices); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_fields); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.RecurseOctreeDepthFirst"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_refined); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_indices); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_fields); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __pyx_L2:; - __Pyx_DECREF((PyObject *)__pyx_v_child_grid); - __Pyx_XDECREF((PyObject *)__pyx_v_grid); - __Pyx_XDECREF((PyObject *)__pyx_v_child_indices); - __Pyx_XDECREF((PyObject *)__pyx_v_dimensions); - __Pyx_XDECREF((PyObject *)__pyx_v_fields); - __Pyx_XDECREF((PyObject *)__pyx_v_leftedges); - __Pyx_DECREF((PyObject *)__pyx_v_child_leftedges); - __Pyx_DECREF(__pyx_v_s); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":110 - * - * @cython.boundscheck(False) - * def RecurseOctreeByLevels(int i_i, int j_i, int k_i, # <<<<<<<<<<<<<< - * int i_f, int j_f, int k_f, - * np.ndarray[np.int32_t, ndim=1] curpos, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_RecurseOctreeByLevels(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_RecurseOctreeByLevels(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_i_i; - int __pyx_v_j_i; - int __pyx_v_k_i; - int __pyx_v_i_f; - int __pyx_v_j_f; - int __pyx_v_k_f; - PyArrayObject *__pyx_v_curpos = 0; - int __pyx_v_gi; - PyArrayObject *__pyx_v_output = 0; - PyArrayObject *__pyx_v_genealogy = 0; - PyArrayObject *__pyx_v_corners = 0; - struct __pyx_obj_2yt_9amr_utils_OctreeGridList *__pyx_v_grids = 0; - __pyx_t_5numpy_int32_t __pyx_v_i; - __pyx_t_5numpy_int32_t __pyx_v_i_off; - __pyx_t_5numpy_int32_t __pyx_v_j; - __pyx_t_5numpy_int32_t __pyx_v_j_off; - __pyx_t_5numpy_int32_t __pyx_v_k; - __pyx_t_5numpy_int32_t __pyx_v_k_off; - __pyx_t_5numpy_int32_t __pyx_v_ci; - __pyx_t_5numpy_int32_t __pyx_v_fi; - int __pyx_v_child_i; - int __pyx_v_child_j; - int __pyx_v_child_k; - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *__pyx_v_child_grid; - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *__pyx_v_grid = 0; - int __pyx_v_level; - PyArrayObject *__pyx_v_child_indices = 0; - PyArrayObject *__pyx_v_dimensions = 0; - PyArrayObject *__pyx_v_fields = 0; - PyArrayObject *__pyx_v_leftedges = 0; - __pyx_t_5numpy_float64_t __pyx_v_dx; - __pyx_t_5numpy_float64_t __pyx_v_child_dx; - PyArrayObject *__pyx_v_child_leftedges; - __pyx_t_5numpy_float64_t __pyx_v_cx; - __pyx_t_5numpy_float64_t __pyx_v_cy; - __pyx_t_5numpy_float64_t __pyx_v_cz; - int __pyx_v_cp; - PyObject *__pyx_v_s; - Py_buffer __pyx_bstruct_leftedges; - Py_ssize_t __pyx_bstride_0_leftedges = 0; - Py_ssize_t __pyx_bshape_0_leftedges = 0; - Py_buffer __pyx_bstruct_curpos; - Py_ssize_t __pyx_bstride_0_curpos = 0; - Py_ssize_t __pyx_bshape_0_curpos = 0; - Py_buffer __pyx_bstruct_child_leftedges; - Py_ssize_t __pyx_bstride_0_child_leftedges = 0; - Py_ssize_t __pyx_bshape_0_child_leftedges = 0; - Py_buffer __pyx_bstruct_dimensions; - Py_ssize_t __pyx_bstride_0_dimensions = 0; - Py_ssize_t __pyx_bshape_0_dimensions = 0; - Py_buffer __pyx_bstruct_child_indices; - Py_ssize_t __pyx_bstride_0_child_indices = 0; - Py_ssize_t __pyx_bstride_1_child_indices = 0; - Py_ssize_t __pyx_bstride_2_child_indices = 0; - Py_ssize_t __pyx_bshape_0_child_indices = 0; - Py_ssize_t __pyx_bshape_1_child_indices = 0; - Py_ssize_t __pyx_bshape_2_child_indices = 0; - Py_buffer __pyx_bstruct_genealogy; - Py_ssize_t __pyx_bstride_0_genealogy = 0; - Py_ssize_t __pyx_bstride_1_genealogy = 0; - Py_ssize_t __pyx_bshape_0_genealogy = 0; - Py_ssize_t __pyx_bshape_1_genealogy = 0; - Py_buffer __pyx_bstruct_corners; - Py_ssize_t __pyx_bstride_0_corners = 0; - Py_ssize_t __pyx_bstride_1_corners = 0; - Py_ssize_t __pyx_bshape_0_corners = 0; - Py_ssize_t __pyx_bshape_1_corners = 0; - Py_buffer __pyx_bstruct_fields; - Py_ssize_t __pyx_bstride_0_fields = 0; - Py_ssize_t __pyx_bstride_1_fields = 0; - Py_ssize_t __pyx_bstride_2_fields = 0; - Py_ssize_t __pyx_bstride_3_fields = 0; - Py_ssize_t __pyx_bshape_0_fields = 0; - Py_ssize_t __pyx_bshape_1_fields = 0; - Py_ssize_t __pyx_bshape_2_fields = 0; - Py_ssize_t __pyx_bshape_3_fields = 0; - Py_buffer __pyx_bstruct_output; - Py_ssize_t __pyx_bstride_0_output = 0; - Py_ssize_t __pyx_bstride_1_output = 0; - Py_ssize_t __pyx_bshape_0_output = 0; - Py_ssize_t __pyx_bshape_1_output = 0; - PyObject *__pyx_r = NULL; - long __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyArrayObject *__pyx_t_3 = NULL; - PyArrayObject *__pyx_t_4 = NULL; - PyArrayObject *__pyx_t_5 = NULL; - PyArrayObject *__pyx_t_6 = NULL; - __pyx_t_5numpy_float64_t __pyx_t_7; - int __pyx_t_8; - __pyx_t_5numpy_int32_t __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - int __pyx_t_13; - __pyx_t_5numpy_int32_t __pyx_t_14; - long __pyx_t_15; - int __pyx_t_16; - __pyx_t_5numpy_int32_t __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - long __pyx_t_21; - int __pyx_t_22; - long __pyx_t_23; - int __pyx_t_24; - long __pyx_t_25; - int __pyx_t_26; - __pyx_t_5numpy_int32_t __pyx_t_27; - long __pyx_t_28; - npy_intp __pyx_t_29; - __pyx_t_5numpy_int32_t __pyx_t_30; - __pyx_t_5numpy_int32_t __pyx_t_31; - __pyx_t_5numpy_int32_t __pyx_t_32; - __pyx_t_5numpy_int32_t __pyx_t_33; - __pyx_t_5numpy_int32_t __pyx_t_34; - int __pyx_t_35; - __pyx_t_5numpy_int32_t __pyx_t_36; - __pyx_t_5numpy_int32_t __pyx_t_37; - __pyx_t_5numpy_int32_t __pyx_t_38; - long __pyx_t_39; - PyArrayObject *__pyx_t_40 = NULL; - int __pyx_t_41; - PyObject *__pyx_t_42 = NULL; - PyObject *__pyx_t_43 = NULL; - PyObject *__pyx_t_44 = NULL; - long __pyx_t_45; - long __pyx_t_46; - long __pyx_t_47; - long __pyx_t_48; - long __pyx_t_49; - long __pyx_t_50; - PyObject *__pyx_t_51 = NULL; - PyObject *__pyx_t_52 = NULL; - PyObject *__pyx_t_53 = NULL; - int __pyx_t_54; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i_i,&__pyx_n_s__j_i,&__pyx_n_s__k_i,&__pyx_n_s__i_f,&__pyx_n_s__j_f,&__pyx_n_s__k_f,&__pyx_n_s__curpos,&__pyx_n_s__gi,&__pyx_n_s__output,&__pyx_n_s__genealogy,&__pyx_n_s__corners,&__pyx_n_s__grids,0}; - __Pyx_RefNannySetupContext("RecurseOctreeByLevels"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_i); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_i); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k_i); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_f); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j_f); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k_f); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__curpos); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gi); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 8: - values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__output); - if (likely(values[8])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 9: - values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__genealogy); - if (likely(values[9])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 10: - values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__corners); - if (likely(values[10])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 10); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 11: - values[11] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grids); - if (likely(values[11])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, 11); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "RecurseOctreeByLevels") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_i_i = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_i_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_i = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_j_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_i = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_k_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_i_f = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_i_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_f = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_j_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_f = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_k_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_curpos = ((PyArrayObject *)values[6]); - __pyx_v_gi = __Pyx_PyInt_AsInt(values[7]); if (unlikely((__pyx_v_gi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_output = ((PyArrayObject *)values[8]); - __pyx_v_genealogy = ((PyArrayObject *)values[9]); - __pyx_v_corners = ((PyArrayObject *)values[10]); - __pyx_v_grids = ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)values[11]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 12) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_i_i = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_i_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_i = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_j_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_i = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_k_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_i_f = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_i_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j_f = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_j_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_k_f = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_k_f == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_curpos = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_gi = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 7)); if (unlikely((__pyx_v_gi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_output = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 8)); - __pyx_v_genealogy = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 9)); - __pyx_v_corners = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 10)); - __pyx_v_grids = ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)PyTuple_GET_ITEM(__pyx_args, 11)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("RecurseOctreeByLevels", 1, 12, 12, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.RecurseOctreeByLevels"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_child_grid = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_child_leftedges = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_s = Py_None; __Pyx_INCREF(Py_None); - __pyx_bstruct_child_indices.buf = NULL; - __pyx_bstruct_dimensions.buf = NULL; - __pyx_bstruct_fields.buf = NULL; - __pyx_bstruct_leftedges.buf = NULL; - __pyx_bstruct_child_leftedges.buf = NULL; - __pyx_bstruct_curpos.buf = NULL; - __pyx_bstruct_output.buf = NULL; - __pyx_bstruct_genealogy.buf = NULL; - __pyx_bstruct_corners.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_curpos), __pyx_ptype_5numpy_ndarray, 1, "curpos", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output), __pyx_ptype_5numpy_ndarray, 1, "output", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_genealogy), __pyx_ptype_5numpy_ndarray, 1, "genealogy", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_corners), __pyx_ptype_5numpy_ndarray, 1, "corners", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grids), __pyx_ptype_2yt_9amr_utils_OctreeGridList, 1, "grids", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_curpos, (PyObject*)__pyx_v_curpos, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_curpos = __pyx_bstruct_curpos.strides[0]; - __pyx_bshape_0_curpos = __pyx_bstruct_curpos.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_output, (PyObject*)__pyx_v_output, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_output = __pyx_bstruct_output.strides[0]; __pyx_bstride_1_output = __pyx_bstruct_output.strides[1]; - __pyx_bshape_0_output = __pyx_bstruct_output.shape[0]; __pyx_bshape_1_output = __pyx_bstruct_output.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_genealogy, (PyObject*)__pyx_v_genealogy, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_genealogy = __pyx_bstruct_genealogy.strides[0]; __pyx_bstride_1_genealogy = __pyx_bstruct_genealogy.strides[1]; - __pyx_bshape_0_genealogy = __pyx_bstruct_genealogy.shape[0]; __pyx_bshape_1_genealogy = __pyx_bstruct_genealogy.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_corners, (PyObject*)__pyx_v_corners, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_corners = __pyx_bstruct_corners.strides[0]; __pyx_bstride_1_corners = __pyx_bstruct_corners.strides[1]; - __pyx_bshape_0_corners = __pyx_bstruct_corners.shape[0]; __pyx_bshape_1_corners = __pyx_bstruct_corners.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":121 - * cdef int child_i, child_j, child_k - * cdef OctreeGrid child_grid - * cdef OctreeGrid grid = grids[gi-1] # <<<<<<<<<<<<<< - * cdef int level = grid.level - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - */ - __pyx_t_1 = (__pyx_v_gi - 1); - __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_grids), __pyx_t_1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_2yt_9amr_utils_OctreeGrid))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_grid = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":122 - * cdef OctreeGrid child_grid - * cdef OctreeGrid grid = grids[gi-1] - * cdef int level = grid.level # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - */ - __pyx_v_level = __pyx_v_grid->level; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":123 - * cdef OctreeGrid grid = grids[gi-1] - * cdef int level = grid.level - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - */ - if (!(likely(((__pyx_v_grid->child_indices) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->child_indices, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = ((PyArrayObject *)__pyx_v_grid->child_indices); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_indices, (PyObject*)__pyx_t_3, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) { - __pyx_v_child_indices = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_child_indices.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_child_indices = __pyx_bstruct_child_indices.strides[0]; __pyx_bstride_1_child_indices = __pyx_bstruct_child_indices.strides[1]; __pyx_bstride_2_child_indices = __pyx_bstruct_child_indices.strides[2]; - __pyx_bshape_0_child_indices = __pyx_bstruct_child_indices.shape[0]; __pyx_bshape_1_child_indices = __pyx_bstruct_child_indices.shape[1]; __pyx_bshape_2_child_indices = __pyx_bstruct_child_indices.shape[2]; - } - } - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_v_grid->child_indices); - __pyx_v_child_indices = ((PyArrayObject *)__pyx_v_grid->child_indices); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":124 - * cdef int level = grid.level - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - */ - if (!(likely(((__pyx_v_grid->dimensions) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->dimensions, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = ((PyArrayObject *)__pyx_v_grid->dimensions); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dimensions, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - __pyx_v_dimensions = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_dimensions.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_dimensions = __pyx_bstruct_dimensions.strides[0]; - __pyx_bshape_0_dimensions = __pyx_bstruct_dimensions.shape[0]; - } - } - __pyx_t_4 = 0; - __Pyx_INCREF(__pyx_v_grid->dimensions); - __pyx_v_dimensions = ((PyArrayObject *)__pyx_v_grid->dimensions); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":125 - * cdef np.ndarray[np.int32_t, ndim=3] child_indices = grid.child_indices - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - * cdef np.float64_t dx = grid.dx[0] - */ - if (!(likely(((__pyx_v_grid->fields) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->fields, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((PyArrayObject *)__pyx_v_grid->fields); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_fields, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) { - __pyx_v_fields = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_fields.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_fields = __pyx_bstruct_fields.strides[0]; __pyx_bstride_1_fields = __pyx_bstruct_fields.strides[1]; __pyx_bstride_2_fields = __pyx_bstruct_fields.strides[2]; __pyx_bstride_3_fields = __pyx_bstruct_fields.strides[3]; - __pyx_bshape_0_fields = __pyx_bstruct_fields.shape[0]; __pyx_bshape_1_fields = __pyx_bstruct_fields.shape[1]; __pyx_bshape_2_fields = __pyx_bstruct_fields.shape[2]; __pyx_bshape_3_fields = __pyx_bstruct_fields.shape[3]; - } - } - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_v_grid->fields); - __pyx_v_fields = ((PyArrayObject *)__pyx_v_grid->fields); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":126 - * cdef np.ndarray[np.int32_t, ndim=1] dimensions = grid.dimensions - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges # <<<<<<<<<<<<<< - * cdef np.float64_t dx = grid.dx[0] - * cdef np.float64_t child_dx - */ - if (!(likely(((__pyx_v_grid->left_edges) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_grid->left_edges, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = ((PyArrayObject *)__pyx_v_grid->left_edges); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_leftedges, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - __pyx_v_leftedges = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_leftedges.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_leftedges = __pyx_bstruct_leftedges.strides[0]; - __pyx_bshape_0_leftedges = __pyx_bstruct_leftedges.shape[0]; - } - } - __pyx_t_6 = 0; - __Pyx_INCREF(__pyx_v_grid->left_edges); - __pyx_v_leftedges = ((PyArrayObject *)__pyx_v_grid->left_edges); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":127 - * cdef np.ndarray[np.float64_t, ndim=4] fields = grid.fields - * cdef np.ndarray[np.float64_t, ndim=1] leftedges = grid.left_edges - * cdef np.float64_t dx = grid.dx[0] # <<<<<<<<<<<<<< - * cdef np.float64_t child_dx - * cdef np.ndarray[np.float64_t, ndim=1] child_leftedges - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_grid->dx, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_7 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_dx = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":132 - * cdef np.float64_t cx, cy, cz - * cdef int cp - * for i_off in range(i_f): # <<<<<<<<<<<<<< - * i = i_off + i_i - * cx = (leftedges[0] + i*dx) - */ - __pyx_t_8 = __pyx_v_i_f; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i_off = __pyx_t_9; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":133 - * cdef int cp - * for i_off in range(i_f): - * i = i_off + i_i # <<<<<<<<<<<<<< - * cx = (leftedges[0] + i*dx) - * if i_f > 2: print k, cz - */ - __pyx_v_i = (__pyx_v_i_off + __pyx_v_i_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":134 - * for i_off in range(i_f): - * i = i_off + i_i - * cx = (leftedges[0] + i*dx) # <<<<<<<<<<<<<< - * if i_f > 2: print k, cz - * for j_off in range(j_f): - */ - __pyx_t_1 = 0; - if (__pyx_t_1 < 0) __pyx_t_1 += __pyx_bshape_0_leftedges; - __pyx_v_cx = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftedges.buf, __pyx_t_1, __pyx_bstride_0_leftedges)) + (__pyx_v_i * __pyx_v_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":135 - * i = i_off + i_i - * cx = (leftedges[0] + i*dx) - * if i_f > 2: print k, cz # <<<<<<<<<<<<<< - * for j_off in range(j_f): - * j = j_off + j_i - */ - __pyx_t_10 = (__pyx_v_i_f > 2); - if (__pyx_t_10) { - __pyx_t_2 = __Pyx_PyInt_to_py_npy_int32(__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = PyFloat_FromDouble(__pyx_v_cz); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - __pyx_t_2 = 0; - __pyx_t_11 = 0; - if (__Pyx_Print(0, __pyx_t_12, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":136 - * cx = (leftedges[0] + i*dx) - * if i_f > 2: print k, cz - * for j_off in range(j_f): # <<<<<<<<<<<<<< - * j = j_off + j_i - * cy = (leftedges[1] + j*dx) - */ - __pyx_t_13 = __pyx_v_j_f; - for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { - __pyx_v_j_off = __pyx_t_14; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":137 - * if i_f > 2: print k, cz - * for j_off in range(j_f): - * j = j_off + j_i # <<<<<<<<<<<<<< - * cy = (leftedges[1] + j*dx) - * for k_off in range(k_f): - */ - __pyx_v_j = (__pyx_v_j_off + __pyx_v_j_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":138 - * for j_off in range(j_f): - * j = j_off + j_i - * cy = (leftedges[1] + j*dx) # <<<<<<<<<<<<<< - * for k_off in range(k_f): - * k = k_off + k_i - */ - __pyx_t_15 = 1; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_0_leftedges; - __pyx_v_cy = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftedges.buf, __pyx_t_15, __pyx_bstride_0_leftedges)) + (__pyx_v_j * __pyx_v_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":139 - * j = j_off + j_i - * cy = (leftedges[1] + j*dx) - * for k_off in range(k_f): # <<<<<<<<<<<<<< - * k = k_off + k_i - * cz = (leftedges[2] + k*dx) - */ - __pyx_t_16 = __pyx_v_k_f; - for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) { - __pyx_v_k_off = __pyx_t_17; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":140 - * cy = (leftedges[1] + j*dx) - * for k_off in range(k_f): - * k = k_off + k_i # <<<<<<<<<<<<<< - * cz = (leftedges[2] + k*dx) - * cp = curpos[level] - */ - __pyx_v_k = (__pyx_v_k_off + __pyx_v_k_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":141 - * for k_off in range(k_f): - * k = k_off + k_i - * cz = (leftedges[2] + k*dx) # <<<<<<<<<<<<<< - * cp = curpos[level] - * corners[cp, 0] = cx - */ - __pyx_t_18 = 2; - if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_bshape_0_leftedges; - __pyx_v_cz = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftedges.buf, __pyx_t_18, __pyx_bstride_0_leftedges)) + (__pyx_v_k * __pyx_v_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":142 - * k = k_off + k_i - * cz = (leftedges[2] + k*dx) - * cp = curpos[level] # <<<<<<<<<<<<<< - * corners[cp, 0] = cx - * corners[cp, 1] = cy - */ - __pyx_t_19 = __pyx_v_level; - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_0_curpos; - __pyx_v_cp = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_curpos.buf, __pyx_t_19, __pyx_bstride_0_curpos)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":143 - * cz = (leftedges[2] + k*dx) - * cp = curpos[level] - * corners[cp, 0] = cx # <<<<<<<<<<<<<< - * corners[cp, 1] = cy - * corners[cp, 2] = cz - */ - __pyx_t_20 = __pyx_v_cp; - __pyx_t_21 = 0; - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_0_corners; - if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_1_corners; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_corners.buf, __pyx_t_20, __pyx_bstride_0_corners, __pyx_t_21, __pyx_bstride_1_corners) = __pyx_v_cx; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":144 - * cp = curpos[level] - * corners[cp, 0] = cx - * corners[cp, 1] = cy # <<<<<<<<<<<<<< - * corners[cp, 2] = cz - * genealogy[curpos[level], 2] = level - */ - __pyx_t_22 = __pyx_v_cp; - __pyx_t_23 = 1; - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_0_corners; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_1_corners; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_corners.buf, __pyx_t_22, __pyx_bstride_0_corners, __pyx_t_23, __pyx_bstride_1_corners) = __pyx_v_cy; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":145 - * corners[cp, 0] = cx - * corners[cp, 1] = cy - * corners[cp, 2] = cz # <<<<<<<<<<<<<< - * genealogy[curpos[level], 2] = level - * # always output data - */ - __pyx_t_24 = __pyx_v_cp; - __pyx_t_25 = 2; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_0_corners; - if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_1_corners; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_corners.buf, __pyx_t_24, __pyx_bstride_0_corners, __pyx_t_25, __pyx_bstride_1_corners) = __pyx_v_cz; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":146 - * corners[cp, 1] = cy - * corners[cp, 2] = cz - * genealogy[curpos[level], 2] = level # <<<<<<<<<<<<<< - * # always output data - * for fi in range(fields.shape[0]): - */ - __pyx_t_26 = __pyx_v_level; - if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_0_curpos; - __pyx_t_27 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_curpos.buf, __pyx_t_26, __pyx_bstride_0_curpos)); - __pyx_t_28 = 2; - if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_0_genealogy; - if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_1_genealogy; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_genealogy.buf, __pyx_t_27, __pyx_bstride_0_genealogy, __pyx_t_28, __pyx_bstride_1_genealogy) = __pyx_v_level; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":148 - * genealogy[curpos[level], 2] = level - * # always output data - * for fi in range(fields.shape[0]): # <<<<<<<<<<<<<< - * output[cp,fi] = fields[fi,i,j,k] - * ci = child_indices[i,j,k] - */ - __pyx_t_29 = (__pyx_v_fields->dimensions[0]); - for (__pyx_t_30 = 0; __pyx_t_30 < __pyx_t_29; __pyx_t_30+=1) { - __pyx_v_fi = __pyx_t_30; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":149 - * # always output data - * for fi in range(fields.shape[0]): - * output[cp,fi] = fields[fi,i,j,k] # <<<<<<<<<<<<<< - * ci = child_indices[i,j,k] - * if ci > -1: - */ - __pyx_t_31 = __pyx_v_fi; - __pyx_t_32 = __pyx_v_i; - __pyx_t_33 = __pyx_v_j; - __pyx_t_34 = __pyx_v_k; - if (__pyx_t_31 < 0) __pyx_t_31 += __pyx_bshape_0_fields; - if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_bshape_1_fields; - if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_bshape_2_fields; - if (__pyx_t_34 < 0) __pyx_t_34 += __pyx_bshape_3_fields; - __pyx_t_35 = __pyx_v_cp; - __pyx_t_36 = __pyx_v_fi; - if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_bshape_0_output; - if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_bshape_1_output; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_output.buf, __pyx_t_35, __pyx_bstride_0_output, __pyx_t_36, __pyx_bstride_1_output) = (*__Pyx_BufPtrStrided4d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_fields.buf, __pyx_t_31, __pyx_bstride_0_fields, __pyx_t_32, __pyx_bstride_1_fields, __pyx_t_33, __pyx_bstride_2_fields, __pyx_t_34, __pyx_bstride_3_fields)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":150 - * for fi in range(fields.shape[0]): - * output[cp,fi] = fields[fi,i,j,k] - * ci = child_indices[i,j,k] # <<<<<<<<<<<<<< - * if ci > -1: - * child_grid = grids[ci-1] - */ - __pyx_t_30 = __pyx_v_i; - __pyx_t_37 = __pyx_v_j; - __pyx_t_38 = __pyx_v_k; - if (__pyx_t_30 < 0) __pyx_t_30 += __pyx_bshape_0_child_indices; - if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_bshape_1_child_indices; - if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_bshape_2_child_indices; - __pyx_v_ci = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_child_indices.buf, __pyx_t_30, __pyx_bstride_0_child_indices, __pyx_t_37, __pyx_bstride_1_child_indices, __pyx_t_38, __pyx_bstride_2_child_indices)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":151 - * output[cp,fi] = fields[fi,i,j,k] - * ci = child_indices[i,j,k] - * if ci > -1: # <<<<<<<<<<<<<< - * child_grid = grids[ci-1] - * child_dx = child_grid.dx[0] - */ - __pyx_t_10 = (__pyx_v_ci > -1); - if (__pyx_t_10) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":152 - * ci = child_indices[i,j,k] - * if ci > -1: - * child_grid = grids[ci-1] # <<<<<<<<<<<<<< - * child_dx = child_grid.dx[0] - * child_leftedges = child_grid.left_edges - */ - __pyx_t_39 = (__pyx_v_ci - 1); - __pyx_t_12 = __Pyx_GetItemInt(((PyObject *)__pyx_v_grids), __pyx_t_39, sizeof(long), PyInt_FromLong); if (!__pyx_t_12) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_2yt_9amr_utils_OctreeGrid))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_v_child_grid)); - __pyx_v_child_grid = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":153 - * if ci > -1: - * child_grid = grids[ci-1] - * child_dx = child_grid.dx[0] # <<<<<<<<<<<<<< - * child_leftedges = child_grid.left_edges - * child_i = int((cx-child_leftedges[0])/child_dx) - */ - __pyx_t_12 = __Pyx_GetItemInt(__pyx_v_child_grid->dx, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_12) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_12); if (unlikely((__pyx_t_7 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_v_child_dx = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":154 - * child_grid = grids[ci-1] - * child_dx = child_grid.dx[0] - * child_leftedges = child_grid.left_edges # <<<<<<<<<<<<<< - * child_i = int((cx-child_leftedges[0])/child_dx) - * child_j = int((cy-child_leftedges[1])/child_dx) - */ - if (!(likely(((__pyx_v_child_grid->left_edges) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_child_grid->left_edges, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_40 = ((PyArrayObject *)__pyx_v_child_grid->left_edges); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_leftedges); - __pyx_t_41 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_child_leftedges, (PyObject*)__pyx_t_40, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_41 < 0)) { - PyErr_Fetch(&__pyx_t_42, &__pyx_t_43, &__pyx_t_44); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_leftedges, (PyObject*)__pyx_v_child_leftedges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_42); Py_XDECREF(__pyx_t_43); Py_XDECREF(__pyx_t_44); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_42, __pyx_t_43, __pyx_t_44); - } - } - __pyx_bstride_0_child_leftedges = __pyx_bstruct_child_leftedges.strides[0]; - __pyx_bshape_0_child_leftedges = __pyx_bstruct_child_leftedges.shape[0]; - if (unlikely(__pyx_t_41 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_40 = 0; - __Pyx_INCREF(__pyx_v_child_grid->left_edges); - __Pyx_DECREF(((PyObject *)__pyx_v_child_leftedges)); - __pyx_v_child_leftedges = ((PyArrayObject *)__pyx_v_child_grid->left_edges); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":155 - * child_dx = child_grid.dx[0] - * child_leftedges = child_grid.left_edges - * child_i = int((cx-child_leftedges[0])/child_dx) # <<<<<<<<<<<<<< - * child_j = int((cy-child_leftedges[1])/child_dx) - * child_k = int((cz-child_leftedges[2])/child_dx) - */ - __pyx_t_39 = 0; - if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_bshape_0_child_leftedges; - __pyx_t_7 = (__pyx_v_cx - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_child_leftedges.buf, __pyx_t_39, __pyx_bstride_0_child_leftedges))); - if (unlikely(__pyx_v_child_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_child_i = ((int)(__pyx_t_7 / __pyx_v_child_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":156 - * child_leftedges = child_grid.left_edges - * child_i = int((cx-child_leftedges[0])/child_dx) - * child_j = int((cy-child_leftedges[1])/child_dx) # <<<<<<<<<<<<<< - * child_k = int((cz-child_leftedges[2])/child_dx) - * # set current child id to id of next cell to examine - */ - __pyx_t_45 = 1; - if (__pyx_t_45 < 0) __pyx_t_45 += __pyx_bshape_0_child_leftedges; - __pyx_t_7 = (__pyx_v_cy - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_child_leftedges.buf, __pyx_t_45, __pyx_bstride_0_child_leftedges))); - if (unlikely(__pyx_v_child_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_child_j = ((int)(__pyx_t_7 / __pyx_v_child_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":157 - * child_i = int((cx-child_leftedges[0])/child_dx) - * child_j = int((cy-child_leftedges[1])/child_dx) - * child_k = int((cz-child_leftedges[2])/child_dx) # <<<<<<<<<<<<<< - * # set current child id to id of next cell to examine - * genealogy[cp, 0] = curpos[level+1] - */ - __pyx_t_46 = 2; - if (__pyx_t_46 < 0) __pyx_t_46 += __pyx_bshape_0_child_leftedges; - __pyx_t_7 = (__pyx_v_cz - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_child_leftedges.buf, __pyx_t_46, __pyx_bstride_0_child_leftedges))); - if (unlikely(__pyx_v_child_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_child_k = ((int)(__pyx_t_7 / __pyx_v_child_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":159 - * child_k = int((cz-child_leftedges[2])/child_dx) - * # set current child id to id of next cell to examine - * genealogy[cp, 0] = curpos[level+1] # <<<<<<<<<<<<<< - * # set next parent id to id of current cell - * genealogy[curpos[level+1]:curpos[level+1]+8, 1] = cp - */ - __pyx_t_47 = (__pyx_v_level + 1); - if (__pyx_t_47 < 0) __pyx_t_47 += __pyx_bshape_0_curpos; - __pyx_t_41 = __pyx_v_cp; - __pyx_t_48 = 0; - if (__pyx_t_41 < 0) __pyx_t_41 += __pyx_bshape_0_genealogy; - if (__pyx_t_48 < 0) __pyx_t_48 += __pyx_bshape_1_genealogy; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_genealogy.buf, __pyx_t_41, __pyx_bstride_0_genealogy, __pyx_t_48, __pyx_bstride_1_genealogy) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_curpos.buf, __pyx_t_47, __pyx_bstride_0_curpos)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":161 - * genealogy[cp, 0] = curpos[level+1] - * # set next parent id to id of current cell - * genealogy[curpos[level+1]:curpos[level+1]+8, 1] = cp # <<<<<<<<<<<<<< - * s = RecurseOctreeByLevels(child_i, child_j, child_k, 2, 2, 2, - * curpos, ci, output, genealogy, - */ - __pyx_t_12 = PyInt_FromLong(__pyx_v_cp); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_49 = (__pyx_v_level + 1); - if (__pyx_t_49 < 0) __pyx_t_49 += __pyx_bshape_0_curpos; - __pyx_t_11 = __Pyx_PyInt_to_py_npy_int32((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_curpos.buf, __pyx_t_49, __pyx_bstride_0_curpos))); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_50 = (__pyx_v_level + 1); - if (__pyx_t_50 < 0) __pyx_t_50 += __pyx_bshape_0_curpos; - __pyx_t_2 = PyInt_FromLong(((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_curpos.buf, __pyx_t_50, __pyx_bstride_0_curpos)) + 8)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_51 = PySlice_New(__pyx_t_11, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_51); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_51); - __Pyx_GIVEREF(__pyx_t_51); - __Pyx_INCREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - __pyx_t_51 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_genealogy), __pyx_t_2, __pyx_t_12) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":162 - * # set next parent id to id of current cell - * genealogy[curpos[level+1]:curpos[level+1]+8, 1] = cp - * s = RecurseOctreeByLevels(child_i, child_j, child_k, 2, 2, 2, # <<<<<<<<<<<<<< - * curpos, ci, output, genealogy, - * corners, grids) - */ - __pyx_t_12 = __Pyx_GetName(__pyx_m, __pyx_n_s_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_2 = PyInt_FromLong(__pyx_v_child_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_51 = PyInt_FromLong(__pyx_v_child_j); if (unlikely(!__pyx_t_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_51); - __pyx_t_11 = PyInt_FromLong(__pyx_v_child_k); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":163 - * genealogy[curpos[level+1]:curpos[level+1]+8, 1] = cp - * s = RecurseOctreeByLevels(child_i, child_j, child_k, 2, 2, 2, - * curpos, ci, output, genealogy, # <<<<<<<<<<<<<< - * corners, grids) - * curpos[level] += 1 - */ - __pyx_t_52 = __Pyx_PyInt_to_py_npy_int32(__pyx_v_ci); if (unlikely(!__pyx_t_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_52); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":164 - * s = RecurseOctreeByLevels(child_i, child_j, child_k, 2, 2, 2, - * curpos, ci, output, genealogy, - * corners, grids) # <<<<<<<<<<<<<< - * curpos[level] += 1 - * return s - */ - __pyx_t_53 = PyTuple_New(12); if (unlikely(!__pyx_t_53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_53); - PyTuple_SET_ITEM(__pyx_t_53, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_53, 1, __pyx_t_51); - __Pyx_GIVEREF(__pyx_t_51); - PyTuple_SET_ITEM(__pyx_t_53, 2, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_53, 3, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_53, 4, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_53, 5, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(((PyObject *)__pyx_v_curpos)); - PyTuple_SET_ITEM(__pyx_t_53, 6, ((PyObject *)__pyx_v_curpos)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_curpos)); - PyTuple_SET_ITEM(__pyx_t_53, 7, __pyx_t_52); - __Pyx_GIVEREF(__pyx_t_52); - __Pyx_INCREF(((PyObject *)__pyx_v_output)); - PyTuple_SET_ITEM(__pyx_t_53, 8, ((PyObject *)__pyx_v_output)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_output)); - __Pyx_INCREF(((PyObject *)__pyx_v_genealogy)); - PyTuple_SET_ITEM(__pyx_t_53, 9, ((PyObject *)__pyx_v_genealogy)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_genealogy)); - __Pyx_INCREF(((PyObject *)__pyx_v_corners)); - PyTuple_SET_ITEM(__pyx_t_53, 10, ((PyObject *)__pyx_v_corners)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_corners)); - __Pyx_INCREF(((PyObject *)__pyx_v_grids)); - PyTuple_SET_ITEM(__pyx_t_53, 11, ((PyObject *)__pyx_v_grids)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_grids)); - __pyx_t_2 = 0; - __pyx_t_51 = 0; - __pyx_t_11 = 0; - __pyx_t_52 = 0; - __pyx_t_52 = PyObject_Call(__pyx_t_12, __pyx_t_53, NULL); if (unlikely(!__pyx_t_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_52); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_53); __pyx_t_53 = 0; - __Pyx_DECREF(__pyx_v_s); - __pyx_v_s = __pyx_t_52; - __pyx_t_52 = 0; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":165 - * curpos, ci, output, genealogy, - * corners, grids) - * curpos[level] += 1 # <<<<<<<<<<<<<< - * return s - * - */ - __pyx_t_54 = __pyx_v_level; - if (__pyx_t_54 < 0) __pyx_t_54 += __pyx_bshape_0_curpos; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_curpos.buf, __pyx_t_54, __pyx_bstride_0_curpos) += 1; - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":166 - * corners, grids) - * curpos[level] += 1 - * return s # <<<<<<<<<<<<<< - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_s); - __pyx_r = __pyx_v_s; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_51); - __Pyx_XDECREF(__pyx_t_52); - __Pyx_XDECREF(__pyx_t_53); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_curpos); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_indices); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_genealogy); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_corners); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_fields); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.RecurseOctreeByLevels"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_curpos); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_leftedges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_indices); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_genealogy); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_corners); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_fields); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __pyx_L2:; - __Pyx_DECREF((PyObject *)__pyx_v_child_grid); - __Pyx_XDECREF((PyObject *)__pyx_v_grid); - __Pyx_XDECREF((PyObject *)__pyx_v_child_indices); - __Pyx_XDECREF((PyObject *)__pyx_v_dimensions); - __Pyx_XDECREF((PyObject *)__pyx_v_fields); - __Pyx_XDECREF((PyObject *)__pyx_v_leftedges); - __Pyx_DECREF((PyObject *)__pyx_v_child_leftedges); - __Pyx_DECREF(__pyx_v_s); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":31 - * - * @cython.boundscheck(False) - * def UnilinearlyInterpolate(np.ndarray[np.float64_t, ndim=1] table, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] x_vals, - * np.ndarray[np.float64_t, ndim=1] x_bins, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_UnilinearlyInterpolate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_UnilinearlyInterpolate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_table = 0; - PyArrayObject *__pyx_v_x_vals = 0; - PyArrayObject *__pyx_v_x_bins = 0; - PyArrayObject *__pyx_v_x_is = 0; - PyArrayObject *__pyx_v_output = 0; - double __pyx_v_x; - double __pyx_v_xp; - double __pyx_v_xm; - int __pyx_v_i; - int __pyx_v_x_i; - PyObject *__pyx_v_dx_inv; - Py_buffer __pyx_bstruct_x_is; - Py_ssize_t __pyx_bstride_0_x_is = 0; - Py_ssize_t __pyx_bshape_0_x_is = 0; - Py_buffer __pyx_bstruct_output; - Py_ssize_t __pyx_bstride_0_output = 0; - Py_ssize_t __pyx_bshape_0_output = 0; - Py_buffer __pyx_bstruct_x_vals; - Py_ssize_t __pyx_bstride_0_x_vals = 0; - Py_ssize_t __pyx_bshape_0_x_vals = 0; - Py_buffer __pyx_bstruct_table; - Py_ssize_t __pyx_bstride_0_table = 0; - Py_ssize_t __pyx_bshape_0_table = 0; - Py_buffer __pyx_bstruct_x_bins; - Py_ssize_t __pyx_bstride_0_x_bins = 0; - Py_ssize_t __pyx_bshape_0_x_bins = 0; - PyObject *__pyx_r = NULL; - npy_intp __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - long __pyx_t_5; - int __pyx_t_6; - __pyx_t_5numpy_float64_t __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - double __pyx_t_11; - long __pyx_t_12; - int __pyx_t_13; - long __pyx_t_14; - int __pyx_t_15; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__table,&__pyx_n_s__x_vals,&__pyx_n_s__x_bins,&__pyx_n_s__x_is,&__pyx_n_s__output,0}; - __Pyx_RefNannySetupContext("UnilinearlyInterpolate"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[5] = {0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__table); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_vals); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("UnilinearlyInterpolate", 1, 5, 5, 1); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_bins); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("UnilinearlyInterpolate", 1, 5, 5, 2); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_is); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("UnilinearlyInterpolate", 1, 5, 5, 3); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__output); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("UnilinearlyInterpolate", 1, 5, 5, 4); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "UnilinearlyInterpolate") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_table = ((PyArrayObject *)values[0]); - __pyx_v_x_vals = ((PyArrayObject *)values[1]); - __pyx_v_x_bins = ((PyArrayObject *)values[2]); - __pyx_v_x_is = ((PyArrayObject *)values[3]); - __pyx_v_output = ((PyArrayObject *)values[4]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_table = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_x_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_x_bins = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_x_is = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_output = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("UnilinearlyInterpolate", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.UnilinearlyInterpolate"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_dx_inv = Py_None; __Pyx_INCREF(Py_None); - __pyx_bstruct_table.buf = NULL; - __pyx_bstruct_x_vals.buf = NULL; - __pyx_bstruct_x_bins.buf = NULL; - __pyx_bstruct_x_is.buf = NULL; - __pyx_bstruct_output.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_table), __pyx_ptype_5numpy_ndarray, 1, "table", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_vals), __pyx_ptype_5numpy_ndarray, 1, "x_vals", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_bins), __pyx_ptype_5numpy_ndarray, 1, "x_bins", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_is), __pyx_ptype_5numpy_ndarray, 1, "x_is", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output), __pyx_ptype_5numpy_ndarray, 1, "output", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_table, (PyObject*)__pyx_v_table, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_table = __pyx_bstruct_table.strides[0]; - __pyx_bshape_0_table = __pyx_bstruct_table.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_vals, (PyObject*)__pyx_v_x_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_vals = __pyx_bstruct_x_vals.strides[0]; - __pyx_bshape_0_x_vals = __pyx_bstruct_x_vals.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_bins, (PyObject*)__pyx_v_x_bins, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_bins = __pyx_bstruct_x_bins.strides[0]; - __pyx_bshape_0_x_bins = __pyx_bstruct_x_bins.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_is, (PyObject*)__pyx_v_x_is, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_is = __pyx_bstruct_x_is.strides[0]; - __pyx_bshape_0_x_is = __pyx_bstruct_x_is.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_output, (PyObject*)__pyx_v_output, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_output = __pyx_bstruct_output.strides[0]; - __pyx_bshape_0_output = __pyx_bstruct_output.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":38 - * cdef double x, xp, xm - * cdef int i, x_i, y_i - * for i in range(x_vals.shape[0]): # <<<<<<<<<<<<<< - * x_i = x_is[i] - * x = x_vals[i] - */ - __pyx_t_1 = (__pyx_v_x_vals->dimensions[0]); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":39 - * cdef int i, x_i, y_i - * for i in range(x_vals.shape[0]): - * x_i = x_is[i] # <<<<<<<<<<<<<< - * x = x_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - */ - __pyx_t_3 = __pyx_v_i; - if (__pyx_t_3 < 0) __pyx_t_3 += __pyx_bshape_0_x_is; - __pyx_v_x_i = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_x_is.buf, __pyx_t_3, __pyx_bstride_0_x_is)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":40 - * for i in range(x_vals.shape[0]): - * x_i = x_is[i] - * x = x_vals[i] # <<<<<<<<<<<<<< - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * xp = (x - x_bins[x_i]) * dx_inv - */ - __pyx_t_4 = __pyx_v_i; - if (__pyx_t_4 < 0) __pyx_t_4 += __pyx_bshape_0_x_vals; - __pyx_v_x = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_vals.buf, __pyx_t_4, __pyx_bstride_0_x_vals)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":41 - * x_i = x_is[i] - * x = x_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) # <<<<<<<<<<<<<< - * xp = (x - x_bins[x_i]) * dx_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - */ - __pyx_t_5 = (__pyx_v_x_i + 1); - if (__pyx_t_5 < 0) __pyx_t_5 += __pyx_bshape_0_x_bins; - __pyx_t_6 = __pyx_v_x_i; - if (__pyx_t_6 < 0) __pyx_t_6 += __pyx_bshape_0_x_bins; - __pyx_t_7 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_5, __pyx_bstride_0_x_bins)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_6, __pyx_bstride_0_x_bins))); - if (unlikely(__pyx_t_7 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyFloat_FromDouble((1.0 / __pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_v_dx_inv); - __pyx_v_dx_inv = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":42 - * x = x_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * xp = (x - x_bins[x_i]) * dx_inv # <<<<<<<<<<<<<< - * xm = (x_bins[x_i+1] - x) * dx_inv - * output[i] = table[x_i ] * (xm) \ - */ - __pyx_t_9 = __pyx_v_x_i; - if (__pyx_t_9 < 0) __pyx_t_9 += __pyx_bshape_0_x_bins; - __pyx_t_8 = PyFloat_FromDouble((__pyx_v_x - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_9, __pyx_bstride_0_x_bins)))); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = PyNumber_Multiply(__pyx_t_8, __pyx_v_dx_inv); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_10); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_xp = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":43 - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * xp = (x - x_bins[x_i]) * dx_inv - * xm = (x_bins[x_i+1] - x) * dx_inv # <<<<<<<<<<<<<< - * output[i] = table[x_i ] * (xm) \ - * + table[x_i+1] * (xp) - */ - __pyx_t_12 = (__pyx_v_x_i + 1); - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_0_x_bins; - __pyx_t_10 = PyFloat_FromDouble(((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_12, __pyx_bstride_0_x_bins)) - __pyx_v_x)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_8 = PyNumber_Multiply(__pyx_t_10, __pyx_v_dx_inv); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_xm = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":44 - * xp = (x - x_bins[x_i]) * dx_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - * output[i] = table[x_i ] * (xm) \ # <<<<<<<<<<<<<< - * + table[x_i+1] * (xp) - * - */ - __pyx_t_13 = __pyx_v_x_i; - if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_bshape_0_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":45 - * xm = (x_bins[x_i+1] - x) * dx_inv - * output[i] = table[x_i ] * (xm) \ - * + table[x_i+1] * (xp) # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __pyx_t_14 = (__pyx_v_x_i + 1); - if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_bshape_0_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":44 - * xp = (x - x_bins[x_i]) * dx_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - * output[i] = table[x_i ] * (xm) \ # <<<<<<<<<<<<<< - * + table[x_i+1] * (xp) - * - */ - __pyx_t_15 = __pyx_v_i; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_0_output; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_output.buf, __pyx_t_15, __pyx_bstride_0_output) = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_13, __pyx_bstride_0_table)) * __pyx_v_xm) + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_14, __pyx_bstride_0_table)) * __pyx_v_xp)); - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_table); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_bins); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.UnilinearlyInterpolate"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_table); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_bins); - __pyx_L2:; - __Pyx_DECREF(__pyx_v_dx_inv); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":48 - * - * @cython.boundscheck(False) - * def BilinearlyInterpolate(np.ndarray[np.float64_t, ndim=2] table, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] x_vals, - * np.ndarray[np.float64_t, ndim=1] y_vals, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_BilinearlyInterpolate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_BilinearlyInterpolate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_table = 0; - PyArrayObject *__pyx_v_x_vals = 0; - PyArrayObject *__pyx_v_y_vals = 0; - PyArrayObject *__pyx_v_x_bins = 0; - PyArrayObject *__pyx_v_y_bins = 0; - PyArrayObject *__pyx_v_x_is = 0; - PyArrayObject *__pyx_v_y_is = 0; - PyArrayObject *__pyx_v_output = 0; - double __pyx_v_x; - double __pyx_v_xp; - double __pyx_v_xm; - double __pyx_v_y; - double __pyx_v_yp; - double __pyx_v_ym; - double __pyx_v_dx_inv; - double __pyx_v_dy_inv; - int __pyx_v_i; - int __pyx_v_x_i; - int __pyx_v_y_i; - Py_buffer __pyx_bstruct_y_vals; - Py_ssize_t __pyx_bstride_0_y_vals = 0; - Py_ssize_t __pyx_bshape_0_y_vals = 0; - Py_buffer __pyx_bstruct_output; - Py_ssize_t __pyx_bstride_0_output = 0; - Py_ssize_t __pyx_bshape_0_output = 0; - Py_buffer __pyx_bstruct_y_is; - Py_ssize_t __pyx_bstride_0_y_is = 0; - Py_ssize_t __pyx_bshape_0_y_is = 0; - Py_buffer __pyx_bstruct_y_bins; - Py_ssize_t __pyx_bstride_0_y_bins = 0; - Py_ssize_t __pyx_bshape_0_y_bins = 0; - Py_buffer __pyx_bstruct_x_is; - Py_ssize_t __pyx_bstride_0_x_is = 0; - Py_ssize_t __pyx_bshape_0_x_is = 0; - Py_buffer __pyx_bstruct_x_vals; - Py_ssize_t __pyx_bstride_0_x_vals = 0; - Py_ssize_t __pyx_bshape_0_x_vals = 0; - Py_buffer __pyx_bstruct_table; - Py_ssize_t __pyx_bstride_0_table = 0; - Py_ssize_t __pyx_bstride_1_table = 0; - Py_ssize_t __pyx_bshape_0_table = 0; - Py_ssize_t __pyx_bshape_1_table = 0; - Py_buffer __pyx_bstruct_x_bins; - Py_ssize_t __pyx_bstride_0_x_bins = 0; - Py_ssize_t __pyx_bshape_0_x_bins = 0; - PyObject *__pyx_r = NULL; - npy_intp __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - long __pyx_t_7; - int __pyx_t_8; - __pyx_t_5numpy_float64_t __pyx_t_9; - long __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - long __pyx_t_14; - long __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - long __pyx_t_21; - long __pyx_t_22; - long __pyx_t_23; - int __pyx_t_24; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__table,&__pyx_n_s__x_vals,&__pyx_n_s__y_vals,&__pyx_n_s__x_bins,&__pyx_n_s__y_bins,&__pyx_n_s__x_is,&__pyx_n_s__y_is,&__pyx_n_s__output,0}; - __Pyx_RefNannySetupContext("BilinearlyInterpolate"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[8] = {0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__table); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_vals); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 1); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_vals); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 2); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_bins); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 3); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_bins); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 4); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_is); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 5); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_is); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 6); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__output); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, 7); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "BilinearlyInterpolate") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_table = ((PyArrayObject *)values[0]); - __pyx_v_x_vals = ((PyArrayObject *)values[1]); - __pyx_v_y_vals = ((PyArrayObject *)values[2]); - __pyx_v_x_bins = ((PyArrayObject *)values[3]); - __pyx_v_y_bins = ((PyArrayObject *)values[4]); - __pyx_v_x_is = ((PyArrayObject *)values[5]); - __pyx_v_y_is = ((PyArrayObject *)values[6]); - __pyx_v_output = ((PyArrayObject *)values[7]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 8) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_table = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_x_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_y_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_x_bins = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_y_bins = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_x_is = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_y_is = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_output = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 7)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("BilinearlyInterpolate", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.BilinearlyInterpolate"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_table.buf = NULL; - __pyx_bstruct_x_vals.buf = NULL; - __pyx_bstruct_y_vals.buf = NULL; - __pyx_bstruct_x_bins.buf = NULL; - __pyx_bstruct_y_bins.buf = NULL; - __pyx_bstruct_x_is.buf = NULL; - __pyx_bstruct_y_is.buf = NULL; - __pyx_bstruct_output.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_table), __pyx_ptype_5numpy_ndarray, 1, "table", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_vals), __pyx_ptype_5numpy_ndarray, 1, "x_vals", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_vals), __pyx_ptype_5numpy_ndarray, 1, "y_vals", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_bins), __pyx_ptype_5numpy_ndarray, 1, "x_bins", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_bins), __pyx_ptype_5numpy_ndarray, 1, "y_bins", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_is), __pyx_ptype_5numpy_ndarray, 1, "x_is", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_is), __pyx_ptype_5numpy_ndarray, 1, "y_is", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output), __pyx_ptype_5numpy_ndarray, 1, "output", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_table, (PyObject*)__pyx_v_table, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_table = __pyx_bstruct_table.strides[0]; __pyx_bstride_1_table = __pyx_bstruct_table.strides[1]; - __pyx_bshape_0_table = __pyx_bstruct_table.shape[0]; __pyx_bshape_1_table = __pyx_bstruct_table.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_vals, (PyObject*)__pyx_v_x_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_vals = __pyx_bstruct_x_vals.strides[0]; - __pyx_bshape_0_x_vals = __pyx_bstruct_x_vals.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_vals, (PyObject*)__pyx_v_y_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_vals = __pyx_bstruct_y_vals.strides[0]; - __pyx_bshape_0_y_vals = __pyx_bstruct_y_vals.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_bins, (PyObject*)__pyx_v_x_bins, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_bins = __pyx_bstruct_x_bins.strides[0]; - __pyx_bshape_0_x_bins = __pyx_bstruct_x_bins.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_bins, (PyObject*)__pyx_v_y_bins, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_bins = __pyx_bstruct_y_bins.strides[0]; - __pyx_bshape_0_y_bins = __pyx_bstruct_y_bins.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_is, (PyObject*)__pyx_v_x_is, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_is = __pyx_bstruct_x_is.strides[0]; - __pyx_bshape_0_x_is = __pyx_bstruct_x_is.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_is, (PyObject*)__pyx_v_y_is, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_is = __pyx_bstruct_y_is.strides[0]; - __pyx_bshape_0_y_is = __pyx_bstruct_y_is.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_output, (PyObject*)__pyx_v_output, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_output = __pyx_bstruct_output.strides[0]; - __pyx_bshape_0_output = __pyx_bstruct_output.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":60 - * cdef double dx_inv, dy_inv - * cdef int i, x_i, y_i - * for i in range(x_vals.shape[0]): # <<<<<<<<<<<<<< - * x_i = x_is[i] - * y_i = y_is[i] - */ - __pyx_t_1 = (__pyx_v_x_vals->dimensions[0]); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":61 - * cdef int i, x_i, y_i - * for i in range(x_vals.shape[0]): - * x_i = x_is[i] # <<<<<<<<<<<<<< - * y_i = y_is[i] - * x = x_vals[i] - */ - __pyx_t_3 = __pyx_v_i; - if (__pyx_t_3 < 0) __pyx_t_3 += __pyx_bshape_0_x_is; - __pyx_v_x_i = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_x_is.buf, __pyx_t_3, __pyx_bstride_0_x_is)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":62 - * for i in range(x_vals.shape[0]): - * x_i = x_is[i] - * y_i = y_is[i] # <<<<<<<<<<<<<< - * x = x_vals[i] - * y = y_vals[i] - */ - __pyx_t_4 = __pyx_v_i; - if (__pyx_t_4 < 0) __pyx_t_4 += __pyx_bshape_0_y_is; - __pyx_v_y_i = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_y_is.buf, __pyx_t_4, __pyx_bstride_0_y_is)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":63 - * x_i = x_is[i] - * y_i = y_is[i] - * x = x_vals[i] # <<<<<<<<<<<<<< - * y = y_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - */ - __pyx_t_5 = __pyx_v_i; - if (__pyx_t_5 < 0) __pyx_t_5 += __pyx_bshape_0_x_vals; - __pyx_v_x = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_vals.buf, __pyx_t_5, __pyx_bstride_0_x_vals)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":64 - * y_i = y_is[i] - * x = x_vals[i] - * y = y_vals[i] # <<<<<<<<<<<<<< - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - */ - __pyx_t_6 = __pyx_v_i; - if (__pyx_t_6 < 0) __pyx_t_6 += __pyx_bshape_0_y_vals; - __pyx_v_y = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_vals.buf, __pyx_t_6, __pyx_bstride_0_y_vals)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":65 - * x = x_vals[i] - * y = y_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) # <<<<<<<<<<<<<< - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - * xp = (x - x_bins[x_i]) * dx_inv - */ - __pyx_t_7 = (__pyx_v_x_i + 1); - if (__pyx_t_7 < 0) __pyx_t_7 += __pyx_bshape_0_x_bins; - __pyx_t_8 = __pyx_v_x_i; - if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_bshape_0_x_bins; - __pyx_t_9 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_7, __pyx_bstride_0_x_bins)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_8, __pyx_bstride_0_x_bins))); - if (unlikely(__pyx_t_9 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dx_inv = (1.0 / __pyx_t_9); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":66 - * y = y_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) # <<<<<<<<<<<<<< - * xp = (x - x_bins[x_i]) * dx_inv - * yp = (y - y_bins[y_i]) * dy_inv - */ - __pyx_t_10 = (__pyx_v_y_i + 1); - if (__pyx_t_10 < 0) __pyx_t_10 += __pyx_bshape_0_y_bins; - __pyx_t_11 = __pyx_v_y_i; - if (__pyx_t_11 < 0) __pyx_t_11 += __pyx_bshape_0_y_bins; - __pyx_t_9 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_10, __pyx_bstride_0_y_bins)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_11, __pyx_bstride_0_y_bins))); - if (unlikely(__pyx_t_9 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dy_inv = (1.0 / __pyx_t_9); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":67 - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - * xp = (x - x_bins[x_i]) * dx_inv # <<<<<<<<<<<<<< - * yp = (y - y_bins[y_i]) * dy_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - */ - __pyx_t_12 = __pyx_v_x_i; - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_0_x_bins; - __pyx_v_xp = ((__pyx_v_x - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_12, __pyx_bstride_0_x_bins))) * __pyx_v_dx_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":68 - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - * xp = (x - x_bins[x_i]) * dx_inv - * yp = (y - y_bins[y_i]) * dy_inv # <<<<<<<<<<<<<< - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv - */ - __pyx_t_13 = __pyx_v_y_i; - if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_bshape_0_y_bins; - __pyx_v_yp = ((__pyx_v_y - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_13, __pyx_bstride_0_y_bins))) * __pyx_v_dy_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":69 - * xp = (x - x_bins[x_i]) * dx_inv - * yp = (y - y_bins[y_i]) * dy_inv - * xm = (x_bins[x_i+1] - x) * dx_inv # <<<<<<<<<<<<<< - * ym = (y_bins[y_i+1] - y) * dy_inv - * output[i] = table[x_i , y_i ] * (xm*ym) \ - */ - __pyx_t_14 = (__pyx_v_x_i + 1); - if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_bshape_0_x_bins; - __pyx_v_xm = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_14, __pyx_bstride_0_x_bins)) - __pyx_v_x) * __pyx_v_dx_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":70 - * yp = (y - y_bins[y_i]) * dy_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv # <<<<<<<<<<<<<< - * output[i] = table[x_i , y_i ] * (xm*ym) \ - * + table[x_i+1, y_i ] * (xp*ym) \ - */ - __pyx_t_15 = (__pyx_v_y_i + 1); - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_0_y_bins; - __pyx_v_ym = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_15, __pyx_bstride_0_y_bins)) - __pyx_v_y) * __pyx_v_dy_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":71 - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv - * output[i] = table[x_i , y_i ] * (xm*ym) \ # <<<<<<<<<<<<<< - * + table[x_i+1, y_i ] * (xp*ym) \ - * + table[x_i , y_i+1] * (xm*yp) \ - */ - __pyx_t_16 = __pyx_v_x_i; - __pyx_t_17 = __pyx_v_y_i; - if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_bshape_0_table; - if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_bshape_1_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":72 - * ym = (y_bins[y_i+1] - y) * dy_inv - * output[i] = table[x_i , y_i ] * (xm*ym) \ - * + table[x_i+1, y_i ] * (xp*ym) \ # <<<<<<<<<<<<<< - * + table[x_i , y_i+1] * (xm*yp) \ - * + table[x_i+1, y_i+1] * (xp*yp) - */ - __pyx_t_18 = (__pyx_v_x_i + 1); - __pyx_t_19 = __pyx_v_y_i; - if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_bshape_0_table; - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_1_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":73 - * output[i] = table[x_i , y_i ] * (xm*ym) \ - * + table[x_i+1, y_i ] * (xp*ym) \ - * + table[x_i , y_i+1] * (xm*yp) \ # <<<<<<<<<<<<<< - * + table[x_i+1, y_i+1] * (xp*yp) - * - */ - __pyx_t_20 = __pyx_v_x_i; - __pyx_t_21 = (__pyx_v_y_i + 1); - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_0_table; - if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_1_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":74 - * + table[x_i+1, y_i ] * (xp*ym) \ - * + table[x_i , y_i+1] * (xm*yp) \ - * + table[x_i+1, y_i+1] * (xp*yp) # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __pyx_t_22 = (__pyx_v_x_i + 1); - __pyx_t_23 = (__pyx_v_y_i + 1); - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_0_table; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_1_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":71 - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv - * output[i] = table[x_i , y_i ] * (xm*ym) \ # <<<<<<<<<<<<<< - * + table[x_i+1, y_i ] * (xp*ym) \ - * + table[x_i , y_i+1] * (xm*yp) \ - */ - __pyx_t_24 = __pyx_v_i; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_0_output; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_output.buf, __pyx_t_24, __pyx_bstride_0_output) = (((((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_16, __pyx_bstride_0_table, __pyx_t_17, __pyx_bstride_1_table)) * (__pyx_v_xm * __pyx_v_ym)) + ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_18, __pyx_bstride_0_table, __pyx_t_19, __pyx_bstride_1_table)) * (__pyx_v_xp * __pyx_v_ym))) + ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_20, __pyx_bstride_0_table, __pyx_t_21, __pyx_bstride_1_table)) * (__pyx_v_xm * __pyx_v_yp))) + ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_22, __pyx_bstride_0_table, __pyx_t_23, __pyx_bstride_1_table)) * (__pyx_v_xp * __pyx_v_yp))); - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_table); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_bins); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.BilinearlyInterpolate"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_table); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_bins); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":77 - * - * @cython.boundscheck(False) - * def TrilinearlyInterpolate(np.ndarray[np.float64_t, ndim=3] table, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] x_vals, - * np.ndarray[np.float64_t, ndim=1] y_vals, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_TrilinearlyInterpolate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_TrilinearlyInterpolate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_table = 0; - PyArrayObject *__pyx_v_x_vals = 0; - PyArrayObject *__pyx_v_y_vals = 0; - PyArrayObject *__pyx_v_z_vals = 0; - PyArrayObject *__pyx_v_x_bins = 0; - PyArrayObject *__pyx_v_y_bins = 0; - PyArrayObject *__pyx_v_z_bins = 0; - PyArrayObject *__pyx_v_x_is = 0; - PyArrayObject *__pyx_v_y_is = 0; - PyArrayObject *__pyx_v_z_is = 0; - PyArrayObject *__pyx_v_output = 0; - double __pyx_v_x; - double __pyx_v_xp; - double __pyx_v_xm; - double __pyx_v_y; - double __pyx_v_yp; - double __pyx_v_ym; - double __pyx_v_z; - double __pyx_v_zp; - double __pyx_v_zm; - double __pyx_v_dx_inv; - double __pyx_v_dy_inv; - double __pyx_v_dz_inv; - int __pyx_v_i; - int __pyx_v_x_i; - int __pyx_v_y_i; - int __pyx_v_z_i; - Py_buffer __pyx_bstruct_z_is; - Py_ssize_t __pyx_bstride_0_z_is = 0; - Py_ssize_t __pyx_bshape_0_z_is = 0; - Py_buffer __pyx_bstruct_x_vals; - Py_ssize_t __pyx_bstride_0_x_vals = 0; - Py_ssize_t __pyx_bshape_0_x_vals = 0; - Py_buffer __pyx_bstruct_y_is; - Py_ssize_t __pyx_bstride_0_y_is = 0; - Py_ssize_t __pyx_bshape_0_y_is = 0; - Py_buffer __pyx_bstruct_y_bins; - Py_ssize_t __pyx_bstride_0_y_bins = 0; - Py_ssize_t __pyx_bshape_0_y_bins = 0; - Py_buffer __pyx_bstruct_z_bins; - Py_ssize_t __pyx_bstride_0_z_bins = 0; - Py_ssize_t __pyx_bshape_0_z_bins = 0; - Py_buffer __pyx_bstruct_x_is; - Py_ssize_t __pyx_bstride_0_x_is = 0; - Py_ssize_t __pyx_bshape_0_x_is = 0; - Py_buffer __pyx_bstruct_output; - Py_ssize_t __pyx_bstride_0_output = 0; - Py_ssize_t __pyx_bshape_0_output = 0; - Py_buffer __pyx_bstruct_table; - Py_ssize_t __pyx_bstride_0_table = 0; - Py_ssize_t __pyx_bstride_1_table = 0; - Py_ssize_t __pyx_bstride_2_table = 0; - Py_ssize_t __pyx_bshape_0_table = 0; - Py_ssize_t __pyx_bshape_1_table = 0; - Py_ssize_t __pyx_bshape_2_table = 0; - Py_buffer __pyx_bstruct_x_bins; - Py_ssize_t __pyx_bstride_0_x_bins = 0; - Py_ssize_t __pyx_bshape_0_x_bins = 0; - Py_buffer __pyx_bstruct_y_vals; - Py_ssize_t __pyx_bstride_0_y_vals = 0; - Py_ssize_t __pyx_bshape_0_y_vals = 0; - Py_buffer __pyx_bstruct_z_vals; - Py_ssize_t __pyx_bstride_0_z_vals = 0; - Py_ssize_t __pyx_bshape_0_z_vals = 0; - PyObject *__pyx_r = NULL; - npy_intp __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - long __pyx_t_9; - int __pyx_t_10; - __pyx_t_5numpy_float64_t __pyx_t_11; - long __pyx_t_12; - int __pyx_t_13; - long __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - long __pyx_t_19; - long __pyx_t_20; - long __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - long __pyx_t_25; - int __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - long __pyx_t_29; - int __pyx_t_30; - int __pyx_t_31; - int __pyx_t_32; - long __pyx_t_33; - long __pyx_t_34; - int __pyx_t_35; - long __pyx_t_36; - int __pyx_t_37; - long __pyx_t_38; - long __pyx_t_39; - long __pyx_t_40; - long __pyx_t_41; - int __pyx_t_42; - long __pyx_t_43; - long __pyx_t_44; - long __pyx_t_45; - int __pyx_t_46; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__table,&__pyx_n_s__x_vals,&__pyx_n_s__y_vals,&__pyx_n_s__z_vals,&__pyx_n_s__x_bins,&__pyx_n_s__y_bins,&__pyx_n_s__z_bins,&__pyx_n_s__x_is,&__pyx_n_s__y_is,&__pyx_n_s__z_is,&__pyx_n_s__output,0}; - __Pyx_RefNannySetupContext("TrilinearlyInterpolate"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__table); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_vals); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 1); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_vals); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 2); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__z_vals); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 3); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_bins); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 4); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_bins); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 5); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__z_bins); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 6); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_is); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 7); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 8: - values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_is); - if (likely(values[8])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 8); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 9: - values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__z_is); - if (likely(values[9])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 9); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 10: - values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__output); - if (likely(values[10])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, 10); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "TrilinearlyInterpolate") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_table = ((PyArrayObject *)values[0]); - __pyx_v_x_vals = ((PyArrayObject *)values[1]); - __pyx_v_y_vals = ((PyArrayObject *)values[2]); - __pyx_v_z_vals = ((PyArrayObject *)values[3]); - __pyx_v_x_bins = ((PyArrayObject *)values[4]); - __pyx_v_y_bins = ((PyArrayObject *)values[5]); - __pyx_v_z_bins = ((PyArrayObject *)values[6]); - __pyx_v_x_is = ((PyArrayObject *)values[7]); - __pyx_v_y_is = ((PyArrayObject *)values[8]); - __pyx_v_z_is = ((PyArrayObject *)values[9]); - __pyx_v_output = ((PyArrayObject *)values[10]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 11) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_table = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_x_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_y_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_z_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_x_bins = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_y_bins = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_z_bins = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_x_is = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 7)); - __pyx_v_y_is = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 8)); - __pyx_v_z_is = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 9)); - __pyx_v_output = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 10)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("TrilinearlyInterpolate", 1, 11, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.TrilinearlyInterpolate"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_table.buf = NULL; - __pyx_bstruct_x_vals.buf = NULL; - __pyx_bstruct_y_vals.buf = NULL; - __pyx_bstruct_z_vals.buf = NULL; - __pyx_bstruct_x_bins.buf = NULL; - __pyx_bstruct_y_bins.buf = NULL; - __pyx_bstruct_z_bins.buf = NULL; - __pyx_bstruct_x_is.buf = NULL; - __pyx_bstruct_y_is.buf = NULL; - __pyx_bstruct_z_is.buf = NULL; - __pyx_bstruct_output.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_table), __pyx_ptype_5numpy_ndarray, 1, "table", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_vals), __pyx_ptype_5numpy_ndarray, 1, "x_vals", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_vals), __pyx_ptype_5numpy_ndarray, 1, "y_vals", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z_vals), __pyx_ptype_5numpy_ndarray, 1, "z_vals", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_bins), __pyx_ptype_5numpy_ndarray, 1, "x_bins", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_bins), __pyx_ptype_5numpy_ndarray, 1, "y_bins", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z_bins), __pyx_ptype_5numpy_ndarray, 1, "z_bins", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_is), __pyx_ptype_5numpy_ndarray, 1, "x_is", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_is), __pyx_ptype_5numpy_ndarray, 1, "y_is", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z_is), __pyx_ptype_5numpy_ndarray, 1, "z_is", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_output), __pyx_ptype_5numpy_ndarray, 1, "output", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_table, (PyObject*)__pyx_v_table, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_table = __pyx_bstruct_table.strides[0]; __pyx_bstride_1_table = __pyx_bstruct_table.strides[1]; __pyx_bstride_2_table = __pyx_bstruct_table.strides[2]; - __pyx_bshape_0_table = __pyx_bstruct_table.shape[0]; __pyx_bshape_1_table = __pyx_bstruct_table.shape[1]; __pyx_bshape_2_table = __pyx_bstruct_table.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_vals, (PyObject*)__pyx_v_x_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_vals = __pyx_bstruct_x_vals.strides[0]; - __pyx_bshape_0_x_vals = __pyx_bstruct_x_vals.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_vals, (PyObject*)__pyx_v_y_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_vals = __pyx_bstruct_y_vals.strides[0]; - __pyx_bshape_0_y_vals = __pyx_bstruct_y_vals.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_z_vals, (PyObject*)__pyx_v_z_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_z_vals = __pyx_bstruct_z_vals.strides[0]; - __pyx_bshape_0_z_vals = __pyx_bstruct_z_vals.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_bins, (PyObject*)__pyx_v_x_bins, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_bins = __pyx_bstruct_x_bins.strides[0]; - __pyx_bshape_0_x_bins = __pyx_bstruct_x_bins.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_bins, (PyObject*)__pyx_v_y_bins, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_bins = __pyx_bstruct_y_bins.strides[0]; - __pyx_bshape_0_y_bins = __pyx_bstruct_y_bins.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_z_bins, (PyObject*)__pyx_v_z_bins, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_z_bins = __pyx_bstruct_z_bins.strides[0]; - __pyx_bshape_0_z_bins = __pyx_bstruct_z_bins.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_is, (PyObject*)__pyx_v_x_is, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_is = __pyx_bstruct_x_is.strides[0]; - __pyx_bshape_0_x_is = __pyx_bstruct_x_is.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_is, (PyObject*)__pyx_v_y_is, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_is = __pyx_bstruct_y_is.strides[0]; - __pyx_bshape_0_y_is = __pyx_bstruct_y_is.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_z_is, (PyObject*)__pyx_v_z_is, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_z_is = __pyx_bstruct_z_is.strides[0]; - __pyx_bshape_0_z_is = __pyx_bstruct_z_is.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_output, (PyObject*)__pyx_v_output, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_output = __pyx_bstruct_output.strides[0]; - __pyx_bshape_0_output = __pyx_bstruct_output.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":93 - * cdef double dx_inv, dy_inv, dz_inv - * cdef int i, x_i, y_i, z_i - * for i in range(x_vals.shape[0]): # <<<<<<<<<<<<<< - * x_i = x_is[i] - * y_i = y_is[i] - */ - __pyx_t_1 = (__pyx_v_x_vals->dimensions[0]); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":94 - * cdef int i, x_i, y_i, z_i - * for i in range(x_vals.shape[0]): - * x_i = x_is[i] # <<<<<<<<<<<<<< - * y_i = y_is[i] - * z_i = z_is[i] - */ - __pyx_t_3 = __pyx_v_i; - if (__pyx_t_3 < 0) __pyx_t_3 += __pyx_bshape_0_x_is; - __pyx_v_x_i = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_x_is.buf, __pyx_t_3, __pyx_bstride_0_x_is)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":95 - * for i in range(x_vals.shape[0]): - * x_i = x_is[i] - * y_i = y_is[i] # <<<<<<<<<<<<<< - * z_i = z_is[i] - * x = x_vals[i] - */ - __pyx_t_4 = __pyx_v_i; - if (__pyx_t_4 < 0) __pyx_t_4 += __pyx_bshape_0_y_is; - __pyx_v_y_i = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_y_is.buf, __pyx_t_4, __pyx_bstride_0_y_is)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":96 - * x_i = x_is[i] - * y_i = y_is[i] - * z_i = z_is[i] # <<<<<<<<<<<<<< - * x = x_vals[i] - * y = y_vals[i] - */ - __pyx_t_5 = __pyx_v_i; - if (__pyx_t_5 < 0) __pyx_t_5 += __pyx_bshape_0_z_is; - __pyx_v_z_i = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_bstruct_z_is.buf, __pyx_t_5, __pyx_bstride_0_z_is)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":97 - * y_i = y_is[i] - * z_i = z_is[i] - * x = x_vals[i] # <<<<<<<<<<<<<< - * y = y_vals[i] - * z = z_vals[i] - */ - __pyx_t_6 = __pyx_v_i; - if (__pyx_t_6 < 0) __pyx_t_6 += __pyx_bshape_0_x_vals; - __pyx_v_x = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_vals.buf, __pyx_t_6, __pyx_bstride_0_x_vals)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":98 - * z_i = z_is[i] - * x = x_vals[i] - * y = y_vals[i] # <<<<<<<<<<<<<< - * z = z_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - */ - __pyx_t_7 = __pyx_v_i; - if (__pyx_t_7 < 0) __pyx_t_7 += __pyx_bshape_0_y_vals; - __pyx_v_y = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_vals.buf, __pyx_t_7, __pyx_bstride_0_y_vals)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":99 - * x = x_vals[i] - * y = y_vals[i] - * z = z_vals[i] # <<<<<<<<<<<<<< - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - */ - __pyx_t_8 = __pyx_v_i; - if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_bshape_0_z_vals; - __pyx_v_z = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z_vals.buf, __pyx_t_8, __pyx_bstride_0_z_vals)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":100 - * y = y_vals[i] - * z = z_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) # <<<<<<<<<<<<<< - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - * dz_inv = 1.0 / (z_bins[z_i+1] - z_bins[z_i]) - */ - __pyx_t_9 = (__pyx_v_x_i + 1); - if (__pyx_t_9 < 0) __pyx_t_9 += __pyx_bshape_0_x_bins; - __pyx_t_10 = __pyx_v_x_i; - if (__pyx_t_10 < 0) __pyx_t_10 += __pyx_bshape_0_x_bins; - __pyx_t_11 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_9, __pyx_bstride_0_x_bins)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_10, __pyx_bstride_0_x_bins))); - if (unlikely(__pyx_t_11 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dx_inv = (1.0 / __pyx_t_11); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":101 - * z = z_vals[i] - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) # <<<<<<<<<<<<<< - * dz_inv = 1.0 / (z_bins[z_i+1] - z_bins[z_i]) - * xp = (x - x_bins[x_i]) * dx_inv - */ - __pyx_t_12 = (__pyx_v_y_i + 1); - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_0_y_bins; - __pyx_t_13 = __pyx_v_y_i; - if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_bshape_0_y_bins; - __pyx_t_11 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_12, __pyx_bstride_0_y_bins)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_13, __pyx_bstride_0_y_bins))); - if (unlikely(__pyx_t_11 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dy_inv = (1.0 / __pyx_t_11); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":102 - * dx_inv = 1.0 / (x_bins[x_i+1] - x_bins[x_i]) - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - * dz_inv = 1.0 / (z_bins[z_i+1] - z_bins[z_i]) # <<<<<<<<<<<<<< - * xp = (x - x_bins[x_i]) * dx_inv - * yp = (y - y_bins[y_i]) * dy_inv - */ - __pyx_t_14 = (__pyx_v_z_i + 1); - if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_bshape_0_z_bins; - __pyx_t_15 = __pyx_v_z_i; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_0_z_bins; - __pyx_t_11 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z_bins.buf, __pyx_t_14, __pyx_bstride_0_z_bins)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z_bins.buf, __pyx_t_15, __pyx_bstride_0_z_bins))); - if (unlikely(__pyx_t_11 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dz_inv = (1.0 / __pyx_t_11); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":103 - * dy_inv = 1.0 / (y_bins[y_i+1] - y_bins[y_i]) - * dz_inv = 1.0 / (z_bins[z_i+1] - z_bins[z_i]) - * xp = (x - x_bins[x_i]) * dx_inv # <<<<<<<<<<<<<< - * yp = (y - y_bins[y_i]) * dy_inv - * zp = (z - z_bins[z_i]) * dz_inv - */ - __pyx_t_16 = __pyx_v_x_i; - if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_bshape_0_x_bins; - __pyx_v_xp = ((__pyx_v_x - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_16, __pyx_bstride_0_x_bins))) * __pyx_v_dx_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":104 - * dz_inv = 1.0 / (z_bins[z_i+1] - z_bins[z_i]) - * xp = (x - x_bins[x_i]) * dx_inv - * yp = (y - y_bins[y_i]) * dy_inv # <<<<<<<<<<<<<< - * zp = (z - z_bins[z_i]) * dz_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - */ - __pyx_t_17 = __pyx_v_y_i; - if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_bshape_0_y_bins; - __pyx_v_yp = ((__pyx_v_y - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_17, __pyx_bstride_0_y_bins))) * __pyx_v_dy_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":105 - * xp = (x - x_bins[x_i]) * dx_inv - * yp = (y - y_bins[y_i]) * dy_inv - * zp = (z - z_bins[z_i]) * dz_inv # <<<<<<<<<<<<<< - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv - */ - __pyx_t_18 = __pyx_v_z_i; - if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_bshape_0_z_bins; - __pyx_v_zp = ((__pyx_v_z - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z_bins.buf, __pyx_t_18, __pyx_bstride_0_z_bins))) * __pyx_v_dz_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":106 - * yp = (y - y_bins[y_i]) * dy_inv - * zp = (z - z_bins[z_i]) * dz_inv - * xm = (x_bins[x_i+1] - x) * dx_inv # <<<<<<<<<<<<<< - * ym = (y_bins[y_i+1] - y) * dy_inv - * zm = (z_bins[z_i+1] - z) * dz_inv - */ - __pyx_t_19 = (__pyx_v_x_i + 1); - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_0_x_bins; - __pyx_v_xm = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x_bins.buf, __pyx_t_19, __pyx_bstride_0_x_bins)) - __pyx_v_x) * __pyx_v_dx_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":107 - * zp = (z - z_bins[z_i]) * dz_inv - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv # <<<<<<<<<<<<<< - * zm = (z_bins[z_i+1] - z) * dz_inv - * output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ - */ - __pyx_t_20 = (__pyx_v_y_i + 1); - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_0_y_bins; - __pyx_v_ym = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y_bins.buf, __pyx_t_20, __pyx_bstride_0_y_bins)) - __pyx_v_y) * __pyx_v_dy_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":108 - * xm = (x_bins[x_i+1] - x) * dx_inv - * ym = (y_bins[y_i+1] - y) * dy_inv - * zm = (z_bins[z_i+1] - z) * dz_inv # <<<<<<<<<<<<<< - * output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ - * + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ - */ - __pyx_t_21 = (__pyx_v_z_i + 1); - if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_0_z_bins; - __pyx_v_zm = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z_bins.buf, __pyx_t_21, __pyx_bstride_0_z_bins)) - __pyx_v_z) * __pyx_v_dz_inv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":109 - * ym = (y_bins[y_i+1] - y) * dy_inv - * zm = (z_bins[z_i+1] - z) * dz_inv - * output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ # <<<<<<<<<<<<<< - * + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ - * + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ - */ - __pyx_t_22 = __pyx_v_x_i; - __pyx_t_23 = __pyx_v_y_i; - __pyx_t_24 = __pyx_v_z_i; - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_0_table; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_1_table; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":110 - * zm = (z_bins[z_i+1] - z) * dz_inv - * output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ - * + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ # <<<<<<<<<<<<<< - * + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ - * + table[x_i ,y_i ,z_i+1] * (xm*ym*zp) \ - */ - __pyx_t_25 = (__pyx_v_x_i + 1); - __pyx_t_26 = __pyx_v_y_i; - __pyx_t_27 = __pyx_v_z_i; - if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_0_table; - if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_1_table; - if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":111 - * output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ - * + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ - * + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ # <<<<<<<<<<<<<< - * + table[x_i ,y_i ,z_i+1] * (xm*ym*zp) \ - * + table[x_i+1,y_i ,z_i+1] * (xp*ym*zp) \ - */ - __pyx_t_28 = __pyx_v_x_i; - __pyx_t_29 = (__pyx_v_y_i + 1); - __pyx_t_30 = __pyx_v_z_i; - if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_0_table; - if (__pyx_t_29 < 0) __pyx_t_29 += __pyx_bshape_1_table; - if (__pyx_t_30 < 0) __pyx_t_30 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":112 - * + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ - * + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ - * + table[x_i ,y_i ,z_i+1] * (xm*ym*zp) \ # <<<<<<<<<<<<<< - * + table[x_i+1,y_i ,z_i+1] * (xp*ym*zp) \ - * + table[x_i ,y_i+1,z_i+1] * (xm*yp*zp) \ - */ - __pyx_t_31 = __pyx_v_x_i; - __pyx_t_32 = __pyx_v_y_i; - __pyx_t_33 = (__pyx_v_z_i + 1); - if (__pyx_t_31 < 0) __pyx_t_31 += __pyx_bshape_0_table; - if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_bshape_1_table; - if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":113 - * + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ - * + table[x_i ,y_i ,z_i+1] * (xm*ym*zp) \ - * + table[x_i+1,y_i ,z_i+1] * (xp*ym*zp) \ # <<<<<<<<<<<<<< - * + table[x_i ,y_i+1,z_i+1] * (xm*yp*zp) \ - * + table[x_i+1,y_i+1,z_i ] * (xp*yp*zm) \ - */ - __pyx_t_34 = (__pyx_v_x_i + 1); - __pyx_t_35 = __pyx_v_y_i; - __pyx_t_36 = (__pyx_v_z_i + 1); - if (__pyx_t_34 < 0) __pyx_t_34 += __pyx_bshape_0_table; - if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_bshape_1_table; - if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":114 - * + table[x_i ,y_i ,z_i+1] * (xm*ym*zp) \ - * + table[x_i+1,y_i ,z_i+1] * (xp*ym*zp) \ - * + table[x_i ,y_i+1,z_i+1] * (xm*yp*zp) \ # <<<<<<<<<<<<<< - * + table[x_i+1,y_i+1,z_i ] * (xp*yp*zm) \ - * + table[x_i+1,y_i+1,z_i+1] * (xp*yp*zp) - */ - __pyx_t_37 = __pyx_v_x_i; - __pyx_t_38 = (__pyx_v_y_i + 1); - __pyx_t_39 = (__pyx_v_z_i + 1); - if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_bshape_0_table; - if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_bshape_1_table; - if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":115 - * + table[x_i+1,y_i ,z_i+1] * (xp*ym*zp) \ - * + table[x_i ,y_i+1,z_i+1] * (xm*yp*zp) \ - * + table[x_i+1,y_i+1,z_i ] * (xp*yp*zm) \ # <<<<<<<<<<<<<< - * + table[x_i+1,y_i+1,z_i+1] * (xp*yp*zp) - */ - __pyx_t_40 = (__pyx_v_x_i + 1); - __pyx_t_41 = (__pyx_v_y_i + 1); - __pyx_t_42 = __pyx_v_z_i; - if (__pyx_t_40 < 0) __pyx_t_40 += __pyx_bshape_0_table; - if (__pyx_t_41 < 0) __pyx_t_41 += __pyx_bshape_1_table; - if (__pyx_t_42 < 0) __pyx_t_42 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":116 - * + table[x_i ,y_i+1,z_i+1] * (xm*yp*zp) \ - * + table[x_i+1,y_i+1,z_i ] * (xp*yp*zm) \ - * + table[x_i+1,y_i+1,z_i+1] * (xp*yp*zp) # <<<<<<<<<<<<<< - */ - __pyx_t_43 = (__pyx_v_x_i + 1); - __pyx_t_44 = (__pyx_v_y_i + 1); - __pyx_t_45 = (__pyx_v_z_i + 1); - if (__pyx_t_43 < 0) __pyx_t_43 += __pyx_bshape_0_table; - if (__pyx_t_44 < 0) __pyx_t_44 += __pyx_bshape_1_table; - if (__pyx_t_45 < 0) __pyx_t_45 += __pyx_bshape_2_table; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":109 - * ym = (y_bins[y_i+1] - y) * dy_inv - * zm = (z_bins[z_i+1] - z) * dz_inv - * output[i] = table[x_i ,y_i ,z_i ] * (xm*ym*zm) \ # <<<<<<<<<<<<<< - * + table[x_i+1,y_i ,z_i ] * (xp*ym*zm) \ - * + table[x_i ,y_i+1,z_i ] * (xm*yp*zm) \ - */ - __pyx_t_46 = __pyx_v_i; - if (__pyx_t_46 < 0) __pyx_t_46 += __pyx_bshape_0_output; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_output.buf, __pyx_t_46, __pyx_bstride_0_output) = (((((((((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_22, __pyx_bstride_0_table, __pyx_t_23, __pyx_bstride_1_table, __pyx_t_24, __pyx_bstride_2_table)) * ((__pyx_v_xm * __pyx_v_ym) * __pyx_v_zm)) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_25, __pyx_bstride_0_table, __pyx_t_26, __pyx_bstride_1_table, __pyx_t_27, __pyx_bstride_2_table)) * ((__pyx_v_xp * __pyx_v_ym) * __pyx_v_zm))) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_28, __pyx_bstride_0_table, __pyx_t_29, __pyx_bstride_1_table, __pyx_t_30, __pyx_bstride_2_table)) * ((__pyx_v_xm * __pyx_v_yp) * __pyx_v_zm))) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_31, __pyx_bstride_0_table, __pyx_t_32, __pyx_bstride_1_table, __pyx_t_33, __pyx_bstride_2_table)) * ((__pyx_v_xm * __pyx_v_ym) * __pyx_v_zp))) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_34, __pyx_bstride_0_table, __pyx_t_35, __pyx_bstride_1_table, __pyx_t_36, __pyx_bstride_2_table)) * ((__pyx_v_xp * __pyx_v_ym) * __pyx_v_zp))) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_37, __pyx_bstride_0_table, __pyx_t_38, __pyx_bstride_1_table, __pyx_t_39, __pyx_bstride_2_table)) * ((__pyx_v_xm * __pyx_v_yp) * __pyx_v_zp))) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_40, __pyx_bstride_0_table, __pyx_t_41, __pyx_bstride_1_table, __pyx_t_42, __pyx_bstride_2_table)) * ((__pyx_v_xp * __pyx_v_yp) * __pyx_v_zm))) + ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_table.buf, __pyx_t_43, __pyx_bstride_0_table, __pyx_t_44, __pyx_bstride_1_table, __pyx_t_45, __pyx_bstride_2_table)) * ((__pyx_v_xp * __pyx_v_yp) * __pyx_v_zp))); - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_table); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z_vals); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.TrilinearlyInterpolate"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_is); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_output); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_table); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_bins); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z_vals); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":36 - * @cython.wraparound(False) - * @cython.boundscheck(False) - * def planar_points_in_volume( # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=2] points, - * np.ndarray[np.int8_t, ndim=1] pmask, # pixel mask - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_planar_points_in_volume(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_planar_points_in_volume(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_points = 0; - PyArrayObject *__pyx_v_pmask = 0; - PyArrayObject *__pyx_v_left_edge = 0; - PyArrayObject *__pyx_v_right_edge = 0; - PyArrayObject *__pyx_v_mask = 0; - float __pyx_v_dx; - PyArrayObject *__pyx_v_valid = 0; - int __pyx_v_i; - int __pyx_v_dim; - int __pyx_v_count; - int __pyx_v_ex; - double __pyx_v_dx_inv; - unsigned int __pyx_v_idx[3]; - PyArrayObject *__pyx_v_result = 0; - Py_buffer __pyx_bstruct_valid; - Py_ssize_t __pyx_bstride_0_valid = 0; - Py_ssize_t __pyx_bshape_0_valid = 0; - Py_buffer __pyx_bstruct_right_edge; - Py_ssize_t __pyx_bstride_0_right_edge = 0; - Py_ssize_t __pyx_bshape_0_right_edge = 0; - Py_buffer __pyx_bstruct_mask; - Py_ssize_t __pyx_bstride_0_mask = 0; - Py_ssize_t __pyx_bstride_1_mask = 0; - Py_ssize_t __pyx_bstride_2_mask = 0; - Py_ssize_t __pyx_bshape_0_mask = 0; - Py_ssize_t __pyx_bshape_1_mask = 0; - Py_ssize_t __pyx_bshape_2_mask = 0; - Py_buffer __pyx_bstruct_points; - Py_ssize_t __pyx_bstride_0_points = 0; - Py_ssize_t __pyx_bstride_1_points = 0; - Py_ssize_t __pyx_bshape_0_points = 0; - Py_ssize_t __pyx_bshape_1_points = 0; - Py_buffer __pyx_bstruct_left_edge; - Py_ssize_t __pyx_bstride_0_left_edge = 0; - Py_ssize_t __pyx_bshape_0_left_edge = 0; - Py_buffer __pyx_bstruct_pmask; - Py_ssize_t __pyx_bstride_0_pmask = 0; - Py_ssize_t __pyx_bshape_0_pmask = 0; - Py_buffer __pyx_bstruct_result; - Py_ssize_t __pyx_bstride_0_result = 0; - Py_ssize_t __pyx_bshape_0_result = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyArrayObject *__pyx_t_5 = NULL; - npy_intp __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - unsigned int __pyx_t_23; - unsigned int __pyx_t_24; - unsigned int __pyx_t_25; - PyArrayObject *__pyx_t_26 = NULL; - int __pyx_t_27; - int __pyx_t_28; - int __pyx_t_29; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__points,&__pyx_n_s__pmask,&__pyx_n_s__left_edge,&__pyx_n_s__right_edge,&__pyx_n_s__mask,&__pyx_n_s__dx,0}; - __Pyx_RefNannySetupContext("planar_points_in_volume"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[6] = {0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__points); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pmask); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("planar_points_in_volume", 1, 6, 6, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edge); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("planar_points_in_volume", 1, 6, 6, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edge); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("planar_points_in_volume", 1, 6, 6, 3); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mask); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("planar_points_in_volume", 1, 6, 6, 4); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("planar_points_in_volume", 1, 6, 6, 5); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "planar_points_in_volume") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_points = ((PyArrayObject *)values[0]); - __pyx_v_pmask = ((PyArrayObject *)values[1]); - __pyx_v_left_edge = ((PyArrayObject *)values[2]); - __pyx_v_right_edge = ((PyArrayObject *)values[3]); - __pyx_v_mask = ((PyArrayObject *)values[4]); - __pyx_v_dx = __pyx_PyFloat_AsDouble(values[5]); if (unlikely((__pyx_v_dx == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_points = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_pmask = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_mask = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_dx = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_dx == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("planar_points_in_volume", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.planar_points_in_volume"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_valid.buf = NULL; - __pyx_bstruct_result.buf = NULL; - __pyx_bstruct_points.buf = NULL; - __pyx_bstruct_pmask.buf = NULL; - __pyx_bstruct_left_edge.buf = NULL; - __pyx_bstruct_right_edge.buf = NULL; - __pyx_bstruct_mask.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_points), __pyx_ptype_5numpy_ndarray, 1, "points", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pmask), __pyx_ptype_5numpy_ndarray, 1, "pmask", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edge), __pyx_ptype_5numpy_ndarray, 1, "left_edge", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edge), __pyx_ptype_5numpy_ndarray, 1, "right_edge", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mask), __pyx_ptype_5numpy_ndarray, 1, "mask", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_points, (PyObject*)__pyx_v_points, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_points = __pyx_bstruct_points.strides[0]; __pyx_bstride_1_points = __pyx_bstruct_points.strides[1]; - __pyx_bshape_0_points = __pyx_bstruct_points.shape[0]; __pyx_bshape_1_points = __pyx_bstruct_points.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_pmask, (PyObject*)__pyx_v_pmask, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_pmask = __pyx_bstruct_pmask.strides[0]; - __pyx_bshape_0_pmask = __pyx_bstruct_pmask.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edge, (PyObject*)__pyx_v_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edge = __pyx_bstruct_left_edge.strides[0]; - __pyx_bshape_0_left_edge = __pyx_bstruct_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edge, (PyObject*)__pyx_v_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edge = __pyx_bstruct_right_edge.strides[0]; - __pyx_bshape_0_right_edge = __pyx_bstruct_right_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_mask, (PyObject*)__pyx_v_mask, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_mask = __pyx_bstruct_mask.strides[0]; __pyx_bstride_1_mask = __pyx_bstruct_mask.strides[1]; __pyx_bstride_2_mask = __pyx_bstruct_mask.strides[2]; - __pyx_bshape_0_mask = __pyx_bstruct_mask.shape[0]; __pyx_bshape_1_mask = __pyx_bstruct_mask.shape[1]; __pyx_bshape_2_mask = __pyx_bstruct_mask.shape[2]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":44 - * float dx): - * cdef np.ndarray[np.int8_t, ndim=1] \ - * valid = np.zeros(points.shape[0], dtype='int8') # <<<<<<<<<<<<<< - * cdef int i, dim, count - * cdef int ex - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_to_py_npy_intp((__pyx_v_points->dimensions[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int8)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((PyArrayObject *)__pyx_t_4); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_valid, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_valid = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_valid.buf = NULL; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_valid = __pyx_bstruct_valid.strides[0]; - __pyx_bshape_0_valid = __pyx_bstruct_valid.shape[0]; - } - } - __pyx_t_5 = 0; - __pyx_v_valid = ((PyArrayObject *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":49 - * cdef double dx_inv - * cdef unsigned int idx[3] - * count = 0 # <<<<<<<<<<<<<< - * dx_inv = 1.0 / dx - * for i in xrange(points.shape[0]): - */ - __pyx_v_count = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":50 - * cdef unsigned int idx[3] - * count = 0 - * dx_inv = 1.0 / dx # <<<<<<<<<<<<<< - * for i in xrange(points.shape[0]): - * if pmask[i] == 0: - */ - if (unlikely(__pyx_v_dx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dx_inv = (1.0 / __pyx_v_dx); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":51 - * count = 0 - * dx_inv = 1.0 / dx - * for i in xrange(points.shape[0]): # <<<<<<<<<<<<<< - * if pmask[i] == 0: - * continue - */ - __pyx_t_6 = (__pyx_v_points->dimensions[0]); - for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { - __pyx_v_i = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":52 - * dx_inv = 1.0 / dx - * for i in xrange(points.shape[0]): - * if pmask[i] == 0: # <<<<<<<<<<<<<< - * continue - * ex = 1 - */ - __pyx_t_8 = __pyx_v_i; - __pyx_t_9 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_bstruct_pmask.buf, __pyx_t_8, __pyx_bstride_0_pmask)) == 0); - if (__pyx_t_9) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":53 - * for i in xrange(points.shape[0]): - * if pmask[i] == 0: - * continue # <<<<<<<<<<<<<< - * ex = 1 - * for dim in xrange(3): - */ - goto __pyx_L6_continue; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":54 - * if pmask[i] == 0: - * continue - * ex = 1 # <<<<<<<<<<<<<< - * for dim in xrange(3): - * if points[i,dim] < left_edge[dim] or points[i,dim] > right_edge[dim]: - */ - __pyx_v_ex = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":55 - * continue - * ex = 1 - * for dim in xrange(3): # <<<<<<<<<<<<<< - * if points[i,dim] < left_edge[dim] or points[i,dim] > right_edge[dim]: - * valid[i] = ex = 0 - */ - for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) { - __pyx_v_dim = __pyx_t_10; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":56 - * ex = 1 - * for dim in xrange(3): - * if points[i,dim] < left_edge[dim] or points[i,dim] > right_edge[dim]: # <<<<<<<<<<<<<< - * valid[i] = ex = 0 - * break - */ - __pyx_t_11 = __pyx_v_i; - __pyx_t_12 = __pyx_v_dim; - __pyx_t_13 = __pyx_v_dim; - __pyx_t_9 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_points.buf, __pyx_t_11, __pyx_bstride_0_points, __pyx_t_12, __pyx_bstride_1_points)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_13, __pyx_bstride_0_left_edge))); - if (!__pyx_t_9) { - __pyx_t_14 = __pyx_v_i; - __pyx_t_15 = __pyx_v_dim; - __pyx_t_16 = __pyx_v_dim; - __pyx_t_17 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_points.buf, __pyx_t_14, __pyx_bstride_0_points, __pyx_t_15, __pyx_bstride_1_points)) > (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_16, __pyx_bstride_0_right_edge))); - __pyx_t_18 = __pyx_t_17; - } else { - __pyx_t_18 = __pyx_t_9; - } - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":57 - * for dim in xrange(3): - * if points[i,dim] < left_edge[dim] or points[i,dim] > right_edge[dim]: - * valid[i] = ex = 0 # <<<<<<<<<<<<<< - * break - * if ex == 1: - */ - __pyx_t_19 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_bstruct_valid.buf, __pyx_t_19, __pyx_bstride_0_valid) = 0; - __pyx_v_ex = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":58 - * if points[i,dim] < left_edge[dim] or points[i,dim] > right_edge[dim]: - * valid[i] = ex = 0 - * break # <<<<<<<<<<<<<< - * if ex == 1: - * for dim in xrange(3): - */ - goto __pyx_L10_break; - goto __pyx_L11; - } - __pyx_L11:; - } - __pyx_L10_break:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":59 - * valid[i] = ex = 0 - * break - * if ex == 1: # <<<<<<<<<<<<<< - * for dim in xrange(3): - * idx[dim] = \ - */ - __pyx_t_18 = (__pyx_v_ex == 1); - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":60 - * break - * if ex == 1: - * for dim in xrange(3): # <<<<<<<<<<<<<< - * idx[dim] = \ - * ((points[i,dim] - left_edge[dim]) * dx_inv) - */ - for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) { - __pyx_v_dim = __pyx_t_10; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":62 - * for dim in xrange(3): - * idx[dim] = \ - * ((points[i,dim] - left_edge[dim]) * dx_inv) # <<<<<<<<<<<<<< - * if mask[idx[0], idx[1], idx[2]] == 1: - * valid[i] = 1 - */ - __pyx_t_20 = __pyx_v_i; - __pyx_t_21 = __pyx_v_dim; - __pyx_t_22 = __pyx_v_dim; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":61 - * if ex == 1: - * for dim in xrange(3): - * idx[dim] = \ # <<<<<<<<<<<<<< - * ((points[i,dim] - left_edge[dim]) * dx_inv) - * if mask[idx[0], idx[1], idx[2]] == 1: - */ - (__pyx_v_idx[__pyx_v_dim]) = ((unsigned int)(((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_points.buf, __pyx_t_20, __pyx_bstride_0_points, __pyx_t_21, __pyx_bstride_1_points)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_22, __pyx_bstride_0_left_edge))) * __pyx_v_dx_inv)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":63 - * idx[dim] = \ - * ((points[i,dim] - left_edge[dim]) * dx_inv) - * if mask[idx[0], idx[1], idx[2]] == 1: # <<<<<<<<<<<<<< - * valid[i] = 1 - * count += 1 - */ - __pyx_t_23 = (__pyx_v_idx[0]); - __pyx_t_24 = (__pyx_v_idx[1]); - __pyx_t_25 = (__pyx_v_idx[2]); - __pyx_t_18 = ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_mask.buf, __pyx_t_23, __pyx_bstride_0_mask, __pyx_t_24, __pyx_bstride_1_mask, __pyx_t_25, __pyx_bstride_2_mask)) == 1); - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":64 - * ((points[i,dim] - left_edge[dim]) * dx_inv) - * if mask[idx[0], idx[1], idx[2]] == 1: - * valid[i] = 1 # <<<<<<<<<<<<<< - * count += 1 - * - */ - __pyx_t_10 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_bstruct_valid.buf, __pyx_t_10, __pyx_bstride_0_valid) = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":65 - * if mask[idx[0], idx[1], idx[2]] == 1: - * valid[i] = 1 - * count += 1 # <<<<<<<<<<<<<< - * - * cdef np.ndarray[np.int32_t, ndim=1] result = np.empty(count, dtype='int32') - */ - __pyx_v_count += 1; - goto __pyx_L15; - } - __pyx_L15:; - goto __pyx_L12; - } - __pyx_L12:; - __pyx_L6_continue:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":67 - * count += 1 - * - * cdef np.ndarray[np.int32_t, ndim=1] result = np.empty(count, dtype='int32') # <<<<<<<<<<<<<< - * count = 0 - * for i in xrange(points.shape[0]): - */ - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyInt_FromLong(__pyx_v_count); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int32)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_26 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_result, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_result.buf = NULL; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_result = __pyx_bstruct_result.strides[0]; - __pyx_bshape_0_result = __pyx_bstruct_result.shape[0]; - } - } - __pyx_t_26 = 0; - __pyx_v_result = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":68 - * - * cdef np.ndarray[np.int32_t, ndim=1] result = np.empty(count, dtype='int32') - * count = 0 # <<<<<<<<<<<<<< - * for i in xrange(points.shape[0]): - * if valid[i] == 1 and pmask[i] == 1: - */ - __pyx_v_count = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":69 - * cdef np.ndarray[np.int32_t, ndim=1] result = np.empty(count, dtype='int32') - * count = 0 - * for i in xrange(points.shape[0]): # <<<<<<<<<<<<<< - * if valid[i] == 1 and pmask[i] == 1: - * result[count] = i - */ - __pyx_t_6 = (__pyx_v_points->dimensions[0]); - for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { - __pyx_v_i = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":70 - * count = 0 - * for i in xrange(points.shape[0]): - * if valid[i] == 1 and pmask[i] == 1: # <<<<<<<<<<<<<< - * result[count] = i - * count += 1 - */ - __pyx_t_27 = __pyx_v_i; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_bstruct_valid.buf, __pyx_t_27, __pyx_bstride_0_valid)) == 1); - if (__pyx_t_18) { - __pyx_t_28 = __pyx_v_i; - __pyx_t_9 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_bstruct_pmask.buf, __pyx_t_28, __pyx_bstride_0_pmask)) == 1); - __pyx_t_17 = __pyx_t_9; - } else { - __pyx_t_17 = __pyx_t_18; - } - if (__pyx_t_17) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":71 - * for i in xrange(points.shape[0]): - * if valid[i] == 1 and pmask[i] == 1: - * result[count] = i # <<<<<<<<<<<<<< - * count += 1 - * - */ - __pyx_t_29 = __pyx_v_count; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_result.buf, __pyx_t_29, __pyx_bstride_0_result) = __pyx_v_i; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":72 - * if valid[i] == 1 and pmask[i] == 1: - * result[count] = i - * count += 1 # <<<<<<<<<<<<<< - * - * return result - */ - __pyx_v_count += 1; - goto __pyx_L18; - } - __pyx_L18:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":74 - * count += 1 - * - * return result # <<<<<<<<<<<<<< - * - * cdef inline void set_rotated_pos( - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_valid); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_points); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pmask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_result); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.planar_points_in_volume"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_valid); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_points); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pmask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_result); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_valid); - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":76 - * return result - * - * cdef inline void set_rotated_pos( # <<<<<<<<<<<<<< - * np.float64_t cp[3], np.float64_t rdds[3][3], - * np.float64_t rorigin[3], int i, int j, int k): - */ - -static CYTHON_INLINE void __pyx_f_2yt_9amr_utils_set_rotated_pos(__pyx_t_5numpy_float64_t *__pyx_v_cp, __pyx_t_5numpy_float64_t (*__pyx_v_rdds)[3], __pyx_t_5numpy_float64_t *__pyx_v_rorigin, int __pyx_v_i, int __pyx_v_j, int __pyx_v_k) { - int __pyx_v_oi; - int __pyx_t_1; - __Pyx_RefNannySetupContext("set_rotated_pos"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":80 - * np.float64_t rorigin[3], int i, int j, int k): - * cdef int oi - * for oi in range(3): # <<<<<<<<<<<<<< - * cp[oi] = rdds[0][oi] * (0.5 + i) \ - * + rdds[1][oi] * (0.5 + j) \ - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_oi = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":81 - * cdef int oi - * for oi in range(3): - * cp[oi] = rdds[0][oi] * (0.5 + i) \ # <<<<<<<<<<<<<< - * + rdds[1][oi] * (0.5 + j) \ - * + rdds[2][oi] * (0.5 + k) \ - */ - (__pyx_v_cp[__pyx_v_oi]) = ((((((__pyx_v_rdds[0])[__pyx_v_oi]) * (0.5 + __pyx_v_i)) + (((__pyx_v_rdds[1])[__pyx_v_oi]) * (0.5 + __pyx_v_j))) + (((__pyx_v_rdds[2])[__pyx_v_oi]) * (0.5 + __pyx_v_k))) + (__pyx_v_rorigin[__pyx_v_oi])); - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":88 - * #@cython.wraparound(False) - * #@cython.boundscheck(False) - * def grid_points_in_volume( # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] box_lengths, - * np.ndarray[np.float64_t, ndim=1] box_origin, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_grid_points_in_volume(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_grid_points_in_volume(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_box_lengths = 0; - PyArrayObject *__pyx_v_box_origin = 0; - PyArrayObject *__pyx_v_rot_mat = 0; - PyArrayObject *__pyx_v_grid_left_edge = 0; - PyArrayObject *__pyx_v_grid_right_edge = 0; - PyArrayObject *__pyx_v_dds = 0; - PyArrayObject *__pyx_v_mask = 0; - int __pyx_v_break_first; - int __pyx_v_n[3]; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_k; - __pyx_t_5numpy_float64_t __pyx_v_rds[3][3]; - __pyx_t_5numpy_float64_t __pyx_v_cur_pos[3]; - __pyx_t_5numpy_float64_t __pyx_v_rorigin[3]; - Py_buffer __pyx_bstruct_dds; - Py_ssize_t __pyx_bstride_0_dds = 0; - Py_ssize_t __pyx_bshape_0_dds = 0; - Py_buffer __pyx_bstruct_grid_right_edge; - Py_ssize_t __pyx_bstride_0_grid_right_edge = 0; - Py_ssize_t __pyx_bshape_0_grid_right_edge = 0; - Py_buffer __pyx_bstruct_mask; - Py_ssize_t __pyx_bstride_0_mask = 0; - Py_ssize_t __pyx_bstride_1_mask = 0; - Py_ssize_t __pyx_bstride_2_mask = 0; - Py_ssize_t __pyx_bshape_0_mask = 0; - Py_ssize_t __pyx_bshape_1_mask = 0; - Py_ssize_t __pyx_bshape_2_mask = 0; - Py_buffer __pyx_bstruct_box_lengths; - Py_ssize_t __pyx_bstride_0_box_lengths = 0; - Py_ssize_t __pyx_bshape_0_box_lengths = 0; - Py_buffer __pyx_bstruct_rot_mat; - Py_ssize_t __pyx_bstride_0_rot_mat = 0; - Py_ssize_t __pyx_bstride_1_rot_mat = 0; - Py_ssize_t __pyx_bshape_0_rot_mat = 0; - Py_ssize_t __pyx_bshape_1_rot_mat = 0; - Py_buffer __pyx_bstruct_box_origin; - Py_ssize_t __pyx_bstride_0_box_origin = 0; - Py_ssize_t __pyx_bshape_0_box_origin = 0; - Py_buffer __pyx_bstruct_grid_left_edge; - Py_ssize_t __pyx_bstride_0_grid_left_edge = 0; - Py_ssize_t __pyx_bshape_0_grid_left_edge = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - long __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - long __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - __pyx_t_5numpy_int32_t __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__box_lengths,&__pyx_n_s__box_origin,&__pyx_n_s__rot_mat,&__pyx_n_s__grid_left_edge,&__pyx_n_s__grid_right_edge,&__pyx_n_s__dds,&__pyx_n_s__mask,&__pyx_n_s__break_first,0}; - __Pyx_RefNannySetupContext("grid_points_in_volume"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[8] = {0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__box_lengths); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__box_origin); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rot_mat); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_left_edge); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 3); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_right_edge); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 4); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dds); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 5); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mask); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 6); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__break_first); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, 7); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "grid_points_in_volume") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_box_lengths = ((PyArrayObject *)values[0]); - __pyx_v_box_origin = ((PyArrayObject *)values[1]); - __pyx_v_rot_mat = ((PyArrayObject *)values[2]); - __pyx_v_grid_left_edge = ((PyArrayObject *)values[3]); - __pyx_v_grid_right_edge = ((PyArrayObject *)values[4]); - __pyx_v_dds = ((PyArrayObject *)values[5]); - __pyx_v_mask = ((PyArrayObject *)values[6]); - __pyx_v_break_first = __Pyx_PyInt_AsInt(values[7]); if (unlikely((__pyx_v_break_first == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 8) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_box_lengths = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_box_origin = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_rot_mat = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_grid_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_grid_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_dds = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_mask = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_break_first = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 7)); if (unlikely((__pyx_v_break_first == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("grid_points_in_volume", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.grid_points_in_volume"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_box_lengths.buf = NULL; - __pyx_bstruct_box_origin.buf = NULL; - __pyx_bstruct_rot_mat.buf = NULL; - __pyx_bstruct_grid_left_edge.buf = NULL; - __pyx_bstruct_grid_right_edge.buf = NULL; - __pyx_bstruct_dds.buf = NULL; - __pyx_bstruct_mask.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_box_lengths), __pyx_ptype_5numpy_ndarray, 1, "box_lengths", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_box_origin), __pyx_ptype_5numpy_ndarray, 1, "box_origin", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_rot_mat), __pyx_ptype_5numpy_ndarray, 1, "rot_mat", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_left_edge), __pyx_ptype_5numpy_ndarray, 1, "grid_left_edge", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_right_edge), __pyx_ptype_5numpy_ndarray, 1, "grid_right_edge", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dds), __pyx_ptype_5numpy_ndarray, 1, "dds", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mask), __pyx_ptype_5numpy_ndarray, 1, "mask", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_box_lengths, (PyObject*)__pyx_v_box_lengths, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_box_lengths = __pyx_bstruct_box_lengths.strides[0]; - __pyx_bshape_0_box_lengths = __pyx_bstruct_box_lengths.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_box_origin, (PyObject*)__pyx_v_box_origin, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_box_origin = __pyx_bstruct_box_origin.strides[0]; - __pyx_bshape_0_box_origin = __pyx_bstruct_box_origin.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_rot_mat, (PyObject*)__pyx_v_rot_mat, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_rot_mat = __pyx_bstruct_rot_mat.strides[0]; __pyx_bstride_1_rot_mat = __pyx_bstruct_rot_mat.strides[1]; - __pyx_bshape_0_rot_mat = __pyx_bstruct_rot_mat.shape[0]; __pyx_bshape_1_rot_mat = __pyx_bstruct_rot_mat.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_left_edge, (PyObject*)__pyx_v_grid_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_left_edge = __pyx_bstruct_grid_left_edge.strides[0]; - __pyx_bshape_0_grid_left_edge = __pyx_bstruct_grid_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_right_edge, (PyObject*)__pyx_v_grid_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_right_edge = __pyx_bstruct_grid_right_edge.strides[0]; - __pyx_bshape_0_grid_right_edge = __pyx_bstruct_grid_right_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dds, (PyObject*)__pyx_v_dds, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dds = __pyx_bstruct_dds.strides[0]; - __pyx_bshape_0_dds = __pyx_bstruct_dds.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_mask, (PyObject*)__pyx_v_mask, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_mask = __pyx_bstruct_mask.strides[0]; __pyx_bstride_1_mask = __pyx_bstruct_mask.strides[1]; __pyx_bstride_2_mask = __pyx_bstruct_mask.strides[2]; - __pyx_bshape_0_mask = __pyx_bstruct_mask.shape[0]; __pyx_bshape_1_mask = __pyx_bstruct_mask.shape[1]; __pyx_bshape_2_mask = __pyx_bstruct_mask.shape[2]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":99 - * cdef int n[3], i, j, k, ax - * cdef np.float64_t rds[3][3], cur_pos[3], rorigin[3] - * for i in range(3): # <<<<<<<<<<<<<< - * rorigin[i] = 0.0 - * for i in range(3): - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":100 - * cdef np.float64_t rds[3][3], cur_pos[3], rorigin[3] - * for i in range(3): - * rorigin[i] = 0.0 # <<<<<<<<<<<<<< - * for i in range(3): - * n[i] = mask.shape[i] - */ - (__pyx_v_rorigin[__pyx_v_i]) = 0.0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":101 - * for i in range(3): - * rorigin[i] = 0.0 - * for i in range(3): # <<<<<<<<<<<<<< - * n[i] = mask.shape[i] - * for j in range(3): - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":102 - * rorigin[i] = 0.0 - * for i in range(3): - * n[i] = mask.shape[i] # <<<<<<<<<<<<<< - * for j in range(3): - * # Set up our transposed dx, which has a component in every - */ - (__pyx_v_n[__pyx_v_i]) = (__pyx_v_mask->dimensions[__pyx_v_i]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":103 - * for i in range(3): - * n[i] = mask.shape[i] - * for j in range(3): # <<<<<<<<<<<<<< - * # Set up our transposed dx, which has a component in every - * # direction - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { - __pyx_v_j = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":106 - * # Set up our transposed dx, which has a component in every - * # direction - * rds[i][j] = dds[i] * rot_mat[j,i] # <<<<<<<<<<<<<< - * # In our rotated coordinate system, the box origin is 0,0,0 - * # so we subtract the box_origin from the grid_origin and rotate - */ - __pyx_t_3 = __pyx_v_i; - __pyx_t_4 = -1; - if (__pyx_t_3 < 0) { - __pyx_t_3 += __pyx_bshape_0_dds; - if (unlikely(__pyx_t_3 < 0)) __pyx_t_4 = 0; - } else if (unlikely(__pyx_t_3 >= __pyx_bshape_0_dds)) __pyx_t_4 = 0; - if (unlikely(__pyx_t_4 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_4); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = __pyx_v_j; - __pyx_t_5 = __pyx_v_i; - __pyx_t_6 = -1; - if (__pyx_t_4 < 0) { - __pyx_t_4 += __pyx_bshape_0_rot_mat; - if (unlikely(__pyx_t_4 < 0)) __pyx_t_6 = 0; - } else if (unlikely(__pyx_t_4 >= __pyx_bshape_0_rot_mat)) __pyx_t_6 = 0; - if (__pyx_t_5 < 0) { - __pyx_t_5 += __pyx_bshape_1_rot_mat; - if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 1; - } else if (unlikely(__pyx_t_5 >= __pyx_bshape_1_rot_mat)) __pyx_t_6 = 1; - if (unlikely(__pyx_t_6 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_6); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - ((__pyx_v_rds[__pyx_v_i])[__pyx_v_j]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dds.buf, __pyx_t_3, __pyx_bstride_0_dds)) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_rot_mat.buf, __pyx_t_4, __pyx_bstride_0_rot_mat, __pyx_t_5, __pyx_bstride_1_rot_mat))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":110 - * # so we subtract the box_origin from the grid_origin and rotate - * # that - * rorigin[j] += (grid_left_edge[i] - box_origin[i]) * rot_mat[j,i] # <<<<<<<<<<<<<< - * - * for i in range(n[0]): - */ - __pyx_t_6 = __pyx_v_i; - __pyx_t_7 = -1; - if (__pyx_t_6 < 0) { - __pyx_t_6 += __pyx_bshape_0_grid_left_edge; - if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0; - } else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_grid_left_edge)) __pyx_t_7 = 0; - if (unlikely(__pyx_t_7 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_7); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_7 = __pyx_v_i; - __pyx_t_8 = -1; - if (__pyx_t_7 < 0) { - __pyx_t_7 += __pyx_bshape_0_box_origin; - if (unlikely(__pyx_t_7 < 0)) __pyx_t_8 = 0; - } else if (unlikely(__pyx_t_7 >= __pyx_bshape_0_box_origin)) __pyx_t_8 = 0; - if (unlikely(__pyx_t_8 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_8); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = __pyx_v_j; - __pyx_t_9 = __pyx_v_i; - __pyx_t_10 = -1; - if (__pyx_t_8 < 0) { - __pyx_t_8 += __pyx_bshape_0_rot_mat; - if (unlikely(__pyx_t_8 < 0)) __pyx_t_10 = 0; - } else if (unlikely(__pyx_t_8 >= __pyx_bshape_0_rot_mat)) __pyx_t_10 = 0; - if (__pyx_t_9 < 0) { - __pyx_t_9 += __pyx_bshape_1_rot_mat; - if (unlikely(__pyx_t_9 < 0)) __pyx_t_10 = 1; - } else if (unlikely(__pyx_t_9 >= __pyx_bshape_1_rot_mat)) __pyx_t_10 = 1; - if (unlikely(__pyx_t_10 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_10); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_rorigin[__pyx_v_j]) += (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_left_edge.buf, __pyx_t_6, __pyx_bstride_0_grid_left_edge)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_box_origin.buf, __pyx_t_7, __pyx_bstride_0_box_origin))) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_rot_mat.buf, __pyx_t_8, __pyx_bstride_0_rot_mat, __pyx_t_9, __pyx_bstride_1_rot_mat))); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":112 - * rorigin[j] += (grid_left_edge[i] - box_origin[i]) * rot_mat[j,i] - * - * for i in range(n[0]): # <<<<<<<<<<<<<< - * for j in range(n[1]): - * for k in range(n[2]): - */ - __pyx_t_1 = (__pyx_v_n[0]); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":113 - * - * for i in range(n[0]): - * for j in range(n[1]): # <<<<<<<<<<<<<< - * for k in range(n[2]): - * set_rotated_pos(cur_pos, rds, rorigin, i, j, k) - */ - __pyx_t_10 = (__pyx_v_n[1]); - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_j = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":114 - * for i in range(n[0]): - * for j in range(n[1]): - * for k in range(n[2]): # <<<<<<<<<<<<<< - * set_rotated_pos(cur_pos, rds, rorigin, i, j, k) - * if (cur_pos[0] > box_lengths[0]): continue - */ - __pyx_t_12 = (__pyx_v_n[2]); - for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) { - __pyx_v_k = __pyx_t_13; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":115 - * for j in range(n[1]): - * for k in range(n[2]): - * set_rotated_pos(cur_pos, rds, rorigin, i, j, k) # <<<<<<<<<<<<<< - * if (cur_pos[0] > box_lengths[0]): continue - * if (cur_pos[1] > box_lengths[1]): continue - */ - __pyx_f_2yt_9amr_utils_set_rotated_pos(__pyx_v_cur_pos, __pyx_v_rds, __pyx_v_rorigin, __pyx_v_i, __pyx_v_j, __pyx_v_k); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":116 - * for k in range(n[2]): - * set_rotated_pos(cur_pos, rds, rorigin, i, j, k) - * if (cur_pos[0] > box_lengths[0]): continue # <<<<<<<<<<<<<< - * if (cur_pos[1] > box_lengths[1]): continue - * if (cur_pos[2] > box_lengths[2]): continue - */ - __pyx_t_14 = 0; - __pyx_t_15 = -1; - if (__pyx_t_14 < 0) { - __pyx_t_14 += __pyx_bshape_0_box_lengths; - if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 0; - } else if (unlikely(__pyx_t_14 >= __pyx_bshape_0_box_lengths)) __pyx_t_15 = 0; - if (unlikely(__pyx_t_15 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_15); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_16 = ((__pyx_v_cur_pos[0]) > (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_box_lengths.buf, __pyx_t_14, __pyx_bstride_0_box_lengths))); - if (__pyx_t_16) { - goto __pyx_L16_continue; - goto __pyx_L18; - } - __pyx_L18:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":117 - * set_rotated_pos(cur_pos, rds, rorigin, i, j, k) - * if (cur_pos[0] > box_lengths[0]): continue - * if (cur_pos[1] > box_lengths[1]): continue # <<<<<<<<<<<<<< - * if (cur_pos[2] > box_lengths[2]): continue - * if (cur_pos[0] < 0.0): continue - */ - __pyx_t_17 = 1; - __pyx_t_15 = -1; - if (__pyx_t_17 < 0) { - __pyx_t_17 += __pyx_bshape_0_box_lengths; - if (unlikely(__pyx_t_17 < 0)) __pyx_t_15 = 0; - } else if (unlikely(__pyx_t_17 >= __pyx_bshape_0_box_lengths)) __pyx_t_15 = 0; - if (unlikely(__pyx_t_15 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_15); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_16 = ((__pyx_v_cur_pos[1]) > (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_box_lengths.buf, __pyx_t_17, __pyx_bstride_0_box_lengths))); - if (__pyx_t_16) { - goto __pyx_L16_continue; - goto __pyx_L19; - } - __pyx_L19:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":118 - * if (cur_pos[0] > box_lengths[0]): continue - * if (cur_pos[1] > box_lengths[1]): continue - * if (cur_pos[2] > box_lengths[2]): continue # <<<<<<<<<<<<<< - * if (cur_pos[0] < 0.0): continue - * if (cur_pos[1] < 0.0): continue - */ - __pyx_t_18 = 2; - __pyx_t_15 = -1; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_bshape_0_box_lengths; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_15 = 0; - } else if (unlikely(__pyx_t_18 >= __pyx_bshape_0_box_lengths)) __pyx_t_15 = 0; - if (unlikely(__pyx_t_15 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_15); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_16 = ((__pyx_v_cur_pos[2]) > (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_box_lengths.buf, __pyx_t_18, __pyx_bstride_0_box_lengths))); - if (__pyx_t_16) { - goto __pyx_L16_continue; - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":119 - * if (cur_pos[1] > box_lengths[1]): continue - * if (cur_pos[2] > box_lengths[2]): continue - * if (cur_pos[0] < 0.0): continue # <<<<<<<<<<<<<< - * if (cur_pos[1] < 0.0): continue - * if (cur_pos[2] < 0.0): continue - */ - __pyx_t_16 = ((__pyx_v_cur_pos[0]) < 0.0); - if (__pyx_t_16) { - goto __pyx_L16_continue; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":120 - * if (cur_pos[2] > box_lengths[2]): continue - * if (cur_pos[0] < 0.0): continue - * if (cur_pos[1] < 0.0): continue # <<<<<<<<<<<<<< - * if (cur_pos[2] < 0.0): continue - * if break_first: - */ - __pyx_t_16 = ((__pyx_v_cur_pos[1]) < 0.0); - if (__pyx_t_16) { - goto __pyx_L16_continue; - goto __pyx_L22; - } - __pyx_L22:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":121 - * if (cur_pos[0] < 0.0): continue - * if (cur_pos[1] < 0.0): continue - * if (cur_pos[2] < 0.0): continue # <<<<<<<<<<<<<< - * if break_first: - * if mask[i,j,k]: return 1 - */ - __pyx_t_16 = ((__pyx_v_cur_pos[2]) < 0.0); - if (__pyx_t_16) { - goto __pyx_L16_continue; - goto __pyx_L23; - } - __pyx_L23:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":122 - * if (cur_pos[1] < 0.0): continue - * if (cur_pos[2] < 0.0): continue - * if break_first: # <<<<<<<<<<<<<< - * if mask[i,j,k]: return 1 - * else: - */ - if (__pyx_v_break_first) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":123 - * if (cur_pos[2] < 0.0): continue - * if break_first: - * if mask[i,j,k]: return 1 # <<<<<<<<<<<<<< - * else: - * mask[i,j,k] = 1 - */ - __pyx_t_15 = __pyx_v_i; - __pyx_t_19 = __pyx_v_j; - __pyx_t_20 = __pyx_v_k; - __pyx_t_21 = -1; - if (__pyx_t_15 < 0) { - __pyx_t_15 += __pyx_bshape_0_mask; - if (unlikely(__pyx_t_15 < 0)) __pyx_t_21 = 0; - } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_mask)) __pyx_t_21 = 0; - if (__pyx_t_19 < 0) { - __pyx_t_19 += __pyx_bshape_1_mask; - if (unlikely(__pyx_t_19 < 0)) __pyx_t_21 = 1; - } else if (unlikely(__pyx_t_19 >= __pyx_bshape_1_mask)) __pyx_t_21 = 1; - if (__pyx_t_20 < 0) { - __pyx_t_20 += __pyx_bshape_2_mask; - if (unlikely(__pyx_t_20 < 0)) __pyx_t_21 = 2; - } else if (unlikely(__pyx_t_20 >= __pyx_bshape_2_mask)) __pyx_t_21 = 2; - if (unlikely(__pyx_t_21 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_21); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_22 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_mask.buf, __pyx_t_15, __pyx_bstride_0_mask, __pyx_t_19, __pyx_bstride_1_mask, __pyx_t_20, __pyx_bstride_2_mask)); - if (__pyx_t_22) { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_int_1); - __pyx_r = __pyx_int_1; - goto __pyx_L0; - goto __pyx_L25; - } - __pyx_L25:; - goto __pyx_L24; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":125 - * if mask[i,j,k]: return 1 - * else: - * mask[i,j,k] = 1 # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_t_21 = __pyx_v_i; - __pyx_t_23 = __pyx_v_j; - __pyx_t_24 = __pyx_v_k; - __pyx_t_25 = -1; - if (__pyx_t_21 < 0) { - __pyx_t_21 += __pyx_bshape_0_mask; - if (unlikely(__pyx_t_21 < 0)) __pyx_t_25 = 0; - } else if (unlikely(__pyx_t_21 >= __pyx_bshape_0_mask)) __pyx_t_25 = 0; - if (__pyx_t_23 < 0) { - __pyx_t_23 += __pyx_bshape_1_mask; - if (unlikely(__pyx_t_23 < 0)) __pyx_t_25 = 1; - } else if (unlikely(__pyx_t_23 >= __pyx_bshape_1_mask)) __pyx_t_25 = 1; - if (__pyx_t_24 < 0) { - __pyx_t_24 += __pyx_bshape_2_mask; - if (unlikely(__pyx_t_24 < 0)) __pyx_t_25 = 2; - } else if (unlikely(__pyx_t_24 >= __pyx_bshape_2_mask)) __pyx_t_25 = 2; - if (unlikely(__pyx_t_25 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_25); - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_mask.buf, __pyx_t_21, __pyx_bstride_0_mask, __pyx_t_23, __pyx_bstride_1_mask, __pyx_t_24, __pyx_bstride_2_mask) = 1; - } - __pyx_L24:; - __pyx_L16_continue:; - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":126 - * else: - * mask[i,j,k] = 1 - * return 0 # <<<<<<<<<<<<<< - * - * cdef void normalize_vector(np.float64_t vec[3]): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_int_0); - __pyx_r = __pyx_int_0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dds); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_lengths); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_rot_mat); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_origin); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_left_edge); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.grid_points_in_volume"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dds); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_lengths); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_rot_mat); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_origin); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_left_edge); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":128 - * return 0 - * - * cdef void normalize_vector(np.float64_t vec[3]): # <<<<<<<<<<<<<< - * cdef int i - * cdef np.float64_t norm = 0.0 - */ - -static void __pyx_f_2yt_9amr_utils_normalize_vector(__pyx_t_5numpy_float64_t *__pyx_v_vec) { - int __pyx_v_i; - __pyx_t_5numpy_float64_t __pyx_v_norm; - int __pyx_t_1; - __Pyx_RefNannySetupContext("normalize_vector"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":130 - * cdef void normalize_vector(np.float64_t vec[3]): - * cdef int i - * cdef np.float64_t norm = 0.0 # <<<<<<<<<<<<<< - * for i in range(3): - * norm += vec[i]*vec[i] - */ - __pyx_v_norm = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":131 - * cdef int i - * cdef np.float64_t norm = 0.0 - * for i in range(3): # <<<<<<<<<<<<<< - * norm += vec[i]*vec[i] - * norm = norm**0.5 - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":132 - * cdef np.float64_t norm = 0.0 - * for i in range(3): - * norm += vec[i]*vec[i] # <<<<<<<<<<<<<< - * norm = norm**0.5 - * for i in range(3): - */ - __pyx_v_norm += ((__pyx_v_vec[__pyx_v_i]) * (__pyx_v_vec[__pyx_v_i])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":133 - * for i in range(3): - * norm += vec[i]*vec[i] - * norm = norm**0.5 # <<<<<<<<<<<<<< - * for i in range(3): - * vec[i] /= norm - */ - __pyx_v_norm = pow(__pyx_v_norm, 0.5); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":134 - * norm += vec[i]*vec[i] - * norm = norm**0.5 - * for i in range(3): # <<<<<<<<<<<<<< - * vec[i] /= norm - * - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":135 - * norm = norm**0.5 - * for i in range(3): - * vec[i] /= norm # <<<<<<<<<<<<<< - * - * cdef void get_cross_product(np.float64_t v1[3], - */ - (__pyx_v_vec[__pyx_v_i]) /= __pyx_v_norm; - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":137 - * vec[i] /= norm - * - * cdef void get_cross_product(np.float64_t v1[3], # <<<<<<<<<<<<<< - * np.float64_t v2[3], - * np.float64_t cp[3]): - */ - -static void __pyx_f_2yt_9amr_utils_get_cross_product(__pyx_t_5numpy_float64_t *__pyx_v_v1, __pyx_t_5numpy_float64_t *__pyx_v_v2, __pyx_t_5numpy_float64_t *__pyx_v_cp) { - __Pyx_RefNannySetupContext("get_cross_product"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":140 - * np.float64_t v2[3], - * np.float64_t cp[3]): - * cp[0] = v1[1]*v2[2] - v1[2]*v2[1] # <<<<<<<<<<<<<< - * cp[1] = v1[3]*v2[0] - v1[0]*v2[3] - * cp[2] = v1[0]*v2[1] - v1[1]*v2[0] - */ - (__pyx_v_cp[0]) = (((__pyx_v_v1[1]) * (__pyx_v_v2[2])) - ((__pyx_v_v1[2]) * (__pyx_v_v2[1]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":141 - * np.float64_t cp[3]): - * cp[0] = v1[1]*v2[2] - v1[2]*v2[1] - * cp[1] = v1[3]*v2[0] - v1[0]*v2[3] # <<<<<<<<<<<<<< - * cp[2] = v1[0]*v2[1] - v1[1]*v2[0] - * #print cp[0], cp[1], cp[2] - */ - (__pyx_v_cp[1]) = (((__pyx_v_v1[3]) * (__pyx_v_v2[0])) - ((__pyx_v_v1[0]) * (__pyx_v_v2[3]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":142 - * cp[0] = v1[1]*v2[2] - v1[2]*v2[1] - * cp[1] = v1[3]*v2[0] - v1[0]*v2[3] - * cp[2] = v1[0]*v2[1] - v1[1]*v2[0] # <<<<<<<<<<<<<< - * #print cp[0], cp[1], cp[2] - * - */ - (__pyx_v_cp[2]) = (((__pyx_v_v1[0]) * (__pyx_v_v2[1])) - ((__pyx_v_v1[1]) * (__pyx_v_v2[0]))); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":145 - * #print cp[0], cp[1], cp[2] - * - * cdef int check_projected_overlap( # <<<<<<<<<<<<<< - * np.float64_t sep_ax[3], np.float64_t sep_vec[3], int gi, - * np.float64_t b_vec[3][3], np.float64_t g_vec[3][3]): - */ - -static int __pyx_f_2yt_9amr_utils_check_projected_overlap(__pyx_t_5numpy_float64_t *__pyx_v_sep_ax, __pyx_t_5numpy_float64_t *__pyx_v_sep_vec, int __pyx_v_gi, __pyx_t_5numpy_float64_t (*__pyx_v_b_vec)[3], __pyx_t_5numpy_float64_t (*__pyx_v_g_vec)[3]) { - int __pyx_v_g_ax; - int __pyx_v_b_ax; - __pyx_t_5numpy_float64_t __pyx_v_tba; - __pyx_t_5numpy_float64_t __pyx_v_tga; - __pyx_t_5numpy_float64_t __pyx_v_ba; - __pyx_t_5numpy_float64_t __pyx_v_ga; - __pyx_t_5numpy_float64_t __pyx_v_sep_dot; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("check_projected_overlap"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":150 - * cdef int g_ax, b_ax - * cdef np.float64_t tba, tga, ba, ga, sep_dot - * ba = ga = sep_dot = 0.0 # <<<<<<<<<<<<<< - * for g_ax in range(3): - * # We need the grid vectors, which we'll precompute here - */ - __pyx_v_ba = 0.0; - __pyx_v_ga = 0.0; - __pyx_v_sep_dot = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":151 - * cdef np.float64_t tba, tga, ba, ga, sep_dot - * ba = ga = sep_dot = 0.0 - * for g_ax in range(3): # <<<<<<<<<<<<<< - * # We need the grid vectors, which we'll precompute here - * tba = tga = 0.0 - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_g_ax = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":153 - * for g_ax in range(3): - * # We need the grid vectors, which we'll precompute here - * tba = tga = 0.0 # <<<<<<<<<<<<<< - * for b_ax in range(3): - * tba += b_vec[g_ax][b_ax] * sep_vec[b_ax] - */ - __pyx_v_tba = 0.0; - __pyx_v_tga = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":154 - * # We need the grid vectors, which we'll precompute here - * tba = tga = 0.0 - * for b_ax in range(3): # <<<<<<<<<<<<<< - * tba += b_vec[g_ax][b_ax] * sep_vec[b_ax] - * tga += g_vec[g_ax][b_ax] * sep_vec[b_ax] - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { - __pyx_v_b_ax = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":155 - * tba = tga = 0.0 - * for b_ax in range(3): - * tba += b_vec[g_ax][b_ax] * sep_vec[b_ax] # <<<<<<<<<<<<<< - * tga += g_vec[g_ax][b_ax] * sep_vec[b_ax] - * ba += fabs(tba) - */ - __pyx_v_tba += (((__pyx_v_b_vec[__pyx_v_g_ax])[__pyx_v_b_ax]) * (__pyx_v_sep_vec[__pyx_v_b_ax])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":156 - * for b_ax in range(3): - * tba += b_vec[g_ax][b_ax] * sep_vec[b_ax] - * tga += g_vec[g_ax][b_ax] * sep_vec[b_ax] # <<<<<<<<<<<<<< - * ba += fabs(tba) - * ga += fabs(tga) - */ - __pyx_v_tga += (((__pyx_v_g_vec[__pyx_v_g_ax])[__pyx_v_b_ax]) * (__pyx_v_sep_vec[__pyx_v_b_ax])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":157 - * tba += b_vec[g_ax][b_ax] * sep_vec[b_ax] - * tga += g_vec[g_ax][b_ax] * sep_vec[b_ax] - * ba += fabs(tba) # <<<<<<<<<<<<<< - * ga += fabs(tga) - * sep_dot += sep_vec[g_ax] * sep_ax[g_ax] - */ - __pyx_v_ba += fabs(__pyx_v_tba); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":158 - * tga += g_vec[g_ax][b_ax] * sep_vec[b_ax] - * ba += fabs(tba) - * ga += fabs(tga) # <<<<<<<<<<<<<< - * sep_dot += sep_vec[g_ax] * sep_ax[g_ax] - * #print sep_vec[0], sep_vec[1], sep_vec[2], - */ - __pyx_v_ga += fabs(__pyx_v_tga); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":159 - * ba += fabs(tba) - * ga += fabs(tga) - * sep_dot += sep_vec[g_ax] * sep_ax[g_ax] # <<<<<<<<<<<<<< - * #print sep_vec[0], sep_vec[1], sep_vec[2], - * #print sep_ax[0], sep_ax[1], sep_ax[2] - */ - __pyx_v_sep_dot += ((__pyx_v_sep_vec[__pyx_v_g_ax]) * (__pyx_v_sep_ax[__pyx_v_g_ax])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":162 - * #print sep_vec[0], sep_vec[1], sep_vec[2], - * #print sep_ax[0], sep_ax[1], sep_ax[2] - * return (fabs(sep_dot) > ba+ga) # <<<<<<<<<<<<<< - * # Now we do - * - */ - __pyx_r = (fabs(__pyx_v_sep_dot) > (__pyx_v_ba + __pyx_v_ga)); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":167 - * @cython.wraparound(False) - * @cython.boundscheck(False) - * def find_grids_in_inclined_box( # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=2] box_vectors, - * np.ndarray[np.float64_t, ndim=1] box_center, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_find_grids_in_inclined_box(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_find_grids_in_inclined_box(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_box_vectors = 0; - PyArrayObject *__pyx_v_box_center = 0; - PyArrayObject *__pyx_v_grid_left_edges = 0; - PyArrayObject *__pyx_v_grid_right_edges = 0; - int __pyx_v_n; - int __pyx_v_g_ax; - int __pyx_v_b_ax; - int __pyx_v_gi; - __pyx_t_5numpy_float64_t __pyx_v_b_vec[3][3]; - __pyx_t_5numpy_float64_t __pyx_v_g_vec[3][3]; - __pyx_t_5numpy_float64_t __pyx_v_a_vec[3][3]; - __pyx_t_5numpy_float64_t __pyx_v_sep_ax[15][3]; - __pyx_t_5numpy_float64_t __pyx_v_sep_vec[3]; - PyArrayObject *__pyx_v_good = 0; - PyArrayObject *__pyx_v_grid_centers; - Py_buffer __pyx_bstruct_grid_left_edges; - Py_ssize_t __pyx_bstride_0_grid_left_edges = 0; - Py_ssize_t __pyx_bstride_1_grid_left_edges = 0; - Py_ssize_t __pyx_bshape_0_grid_left_edges = 0; - Py_ssize_t __pyx_bshape_1_grid_left_edges = 0; - Py_buffer __pyx_bstruct_box_vectors; - Py_ssize_t __pyx_bstride_0_box_vectors = 0; - Py_ssize_t __pyx_bstride_1_box_vectors = 0; - Py_ssize_t __pyx_bshape_0_box_vectors = 0; - Py_ssize_t __pyx_bshape_1_box_vectors = 0; - Py_buffer __pyx_bstruct_good; - Py_ssize_t __pyx_bstride_0_good = 0; - Py_ssize_t __pyx_bshape_0_good = 0; - Py_buffer __pyx_bstruct_grid_right_edges; - Py_ssize_t __pyx_bstride_0_grid_right_edges = 0; - Py_ssize_t __pyx_bstride_1_grid_right_edges = 0; - Py_ssize_t __pyx_bshape_0_grid_right_edges = 0; - Py_ssize_t __pyx_bshape_1_grid_right_edges = 0; - Py_buffer __pyx_bstruct_grid_centers; - Py_ssize_t __pyx_bstride_0_grid_centers = 0; - Py_ssize_t __pyx_bstride_1_grid_centers = 0; - Py_ssize_t __pyx_bshape_0_grid_centers = 0; - Py_ssize_t __pyx_bshape_1_grid_centers = 0; - Py_buffer __pyx_bstruct_box_center; - Py_ssize_t __pyx_bstride_0_box_center = 0; - Py_ssize_t __pyx_bshape_0_box_center = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyArrayObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_t_7; - PyArrayObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__box_vectors,&__pyx_n_s__box_center,&__pyx_n_s__grid_left_edges,&__pyx_n_s__grid_right_edges,0}; - __Pyx_RefNannySetupContext("find_grids_in_inclined_box"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[4] = {0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__box_vectors); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__box_center); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("find_grids_in_inclined_box", 1, 4, 4, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_left_edges); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("find_grids_in_inclined_box", 1, 4, 4, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_right_edges); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("find_grids_in_inclined_box", 1, 4, 4, 3); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "find_grids_in_inclined_box") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_box_vectors = ((PyArrayObject *)values[0]); - __pyx_v_box_center = ((PyArrayObject *)values[1]); - __pyx_v_grid_left_edges = ((PyArrayObject *)values[2]); - __pyx_v_grid_right_edges = ((PyArrayObject *)values[3]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_box_vectors = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_box_center = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_grid_left_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_grid_right_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("find_grids_in_inclined_box", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.find_grids_in_inclined_box"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_grid_centers = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_good.buf = NULL; - __pyx_bstruct_grid_centers.buf = NULL; - __pyx_bstruct_box_vectors.buf = NULL; - __pyx_bstruct_box_center.buf = NULL; - __pyx_bstruct_grid_left_edges.buf = NULL; - __pyx_bstruct_grid_right_edges.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_box_vectors), __pyx_ptype_5numpy_ndarray, 1, "box_vectors", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_box_center), __pyx_ptype_5numpy_ndarray, 1, "box_center", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_left_edges), __pyx_ptype_5numpy_ndarray, 1, "grid_left_edges", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_right_edges), __pyx_ptype_5numpy_ndarray, 1, "grid_right_edges", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_box_vectors, (PyObject*)__pyx_v_box_vectors, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_box_vectors = __pyx_bstruct_box_vectors.strides[0]; __pyx_bstride_1_box_vectors = __pyx_bstruct_box_vectors.strides[1]; - __pyx_bshape_0_box_vectors = __pyx_bstruct_box_vectors.shape[0]; __pyx_bshape_1_box_vectors = __pyx_bstruct_box_vectors.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_box_center, (PyObject*)__pyx_v_box_center, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_box_center = __pyx_bstruct_box_center.strides[0]; - __pyx_bshape_0_box_center = __pyx_bstruct_box_center.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_left_edges, (PyObject*)__pyx_v_grid_left_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_left_edges = __pyx_bstruct_grid_left_edges.strides[0]; __pyx_bstride_1_grid_left_edges = __pyx_bstruct_grid_left_edges.strides[1]; - __pyx_bshape_0_grid_left_edges = __pyx_bstruct_grid_left_edges.shape[0]; __pyx_bshape_1_grid_left_edges = __pyx_bstruct_grid_left_edges.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_right_edges, (PyObject*)__pyx_v_grid_right_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_right_edges = __pyx_bstruct_grid_right_edges.strides[0]; __pyx_bstride_1_grid_right_edges = __pyx_bstruct_grid_right_edges.strides[1]; - __pyx_bshape_0_grid_right_edges = __pyx_bstruct_grid_right_edges.shape[0]; __pyx_bshape_1_grid_right_edges = __pyx_bstruct_grid_right_edges.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":174 - * - * # http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php?page=5 - * cdef int n = grid_right_edges.shape[0] # <<<<<<<<<<<<<< - * cdef int g_ax, b_ax, gi - * cdef np.float64_t b_vec[3][3], g_vec[3][3], a_vec[3][3], sep_ax[15][3] - */ - __pyx_v_n = (__pyx_v_grid_right_edges->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":178 - * cdef np.float64_t b_vec[3][3], g_vec[3][3], a_vec[3][3], sep_ax[15][3] - * cdef np.float64_t sep_vec[3], norm - * cdef np.ndarray[np.int32_t, ndim=1] good = np.zeros(n, dtype='int32') # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=2] grid_centers - * # Fill in our axis unit vectors - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int32)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((PyArrayObject *)__pyx_t_4); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_good, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_good = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_good.buf = NULL; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_good = __pyx_bstruct_good.strides[0]; - __pyx_bshape_0_good = __pyx_bstruct_good.shape[0]; - } - } - __pyx_t_5 = 0; - __pyx_v_good = ((PyArrayObject *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":181 - * cdef np.ndarray[np.float64_t, ndim=2] grid_centers - * # Fill in our axis unit vectors - * for b_ax in range(3): # <<<<<<<<<<<<<< - * for g_ax in range(3): - * a_vec[b_ax][g_ax] = (b_ax == g_ax) - */ - for (__pyx_t_6 = 0; __pyx_t_6 < 3; __pyx_t_6+=1) { - __pyx_v_b_ax = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":182 - * # Fill in our axis unit vectors - * for b_ax in range(3): - * for g_ax in range(3): # <<<<<<<<<<<<<< - * a_vec[b_ax][g_ax] = (b_ax == g_ax) - * grid_centers = (grid_right_edges + grid_left_edges)/2.0 - */ - for (__pyx_t_7 = 0; __pyx_t_7 < 3; __pyx_t_7+=1) { - __pyx_v_g_ax = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":183 - * for b_ax in range(3): - * for g_ax in range(3): - * a_vec[b_ax][g_ax] = (b_ax == g_ax) # <<<<<<<<<<<<<< - * grid_centers = (grid_right_edges + grid_left_edges)/2.0 - * - */ - ((__pyx_v_a_vec[__pyx_v_b_ax])[__pyx_v_g_ax]) = ((__pyx_t_5numpy_float64_t)(__pyx_v_b_ax == __pyx_v_g_ax)); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":184 - * for g_ax in range(3): - * a_vec[b_ax][g_ax] = (b_ax == g_ax) - * grid_centers = (grid_right_edges + grid_left_edges)/2.0 # <<<<<<<<<<<<<< - * - * # Now we pre-compute our candidate separating axes, because the unit - */ - __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_v_grid_right_edges), ((PyObject *)__pyx_v_grid_left_edges)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyFloat_FromDouble(2.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = ((PyArrayObject *)__pyx_t_3); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_centers); - __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_centers, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_6 < 0)) { - PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_centers, (PyObject*)__pyx_v_grid_centers, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11); - } - } - __pyx_bstride_0_grid_centers = __pyx_bstruct_grid_centers.strides[0]; __pyx_bstride_1_grid_centers = __pyx_bstruct_grid_centers.strides[1]; - __pyx_bshape_0_grid_centers = __pyx_bstruct_grid_centers.shape[0]; __pyx_bshape_1_grid_centers = __pyx_bstruct_grid_centers.shape[1]; - if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_grid_centers)); - __pyx_v_grid_centers = ((PyArrayObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":188 - * # Now we pre-compute our candidate separating axes, because the unit - * # vectors for all the grids are identical - * for b_ax in range(3): # <<<<<<<<<<<<<< - * # We have 6 principal axes we already know, which are the grid (domain) - * # principal axes and the box axes - */ - for (__pyx_t_6 = 0; __pyx_t_6 < 3; __pyx_t_6+=1) { - __pyx_v_b_ax = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":191 - * # We have 6 principal axes we already know, which are the grid (domain) - * # principal axes and the box axes - * sep_ax[b_ax][0] = sep_ax[b_ax][1] = sep_ax[b_ax][2] = 0.0 # <<<<<<<<<<<<<< - * sep_ax[b_ax][b_ax] = 1.0 # delta_ijk, for grid axes - * for g_ax in range(3): - */ - ((__pyx_v_sep_ax[__pyx_v_b_ax])[0]) = 0.0; - ((__pyx_v_sep_ax[__pyx_v_b_ax])[1]) = 0.0; - ((__pyx_v_sep_ax[__pyx_v_b_ax])[2]) = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":192 - * # principal axes and the box axes - * sep_ax[b_ax][0] = sep_ax[b_ax][1] = sep_ax[b_ax][2] = 0.0 - * sep_ax[b_ax][b_ax] = 1.0 # delta_ijk, for grid axes # <<<<<<<<<<<<<< - * for g_ax in range(3): - * b_vec[b_ax][g_ax] = 0.5*box_vectors[b_ax,g_ax] - */ - ((__pyx_v_sep_ax[__pyx_v_b_ax])[__pyx_v_b_ax]) = 1.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":193 - * sep_ax[b_ax][0] = sep_ax[b_ax][1] = sep_ax[b_ax][2] = 0.0 - * sep_ax[b_ax][b_ax] = 1.0 # delta_ijk, for grid axes - * for g_ax in range(3): # <<<<<<<<<<<<<< - * b_vec[b_ax][g_ax] = 0.5*box_vectors[b_ax,g_ax] - * sep_ax[b_ax + 3][g_ax] = b_vec[b_ax][g_ax] # box axes - */ - for (__pyx_t_7 = 0; __pyx_t_7 < 3; __pyx_t_7+=1) { - __pyx_v_g_ax = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":194 - * sep_ax[b_ax][b_ax] = 1.0 # delta_ijk, for grid axes - * for g_ax in range(3): - * b_vec[b_ax][g_ax] = 0.5*box_vectors[b_ax,g_ax] # <<<<<<<<<<<<<< - * sep_ax[b_ax + 3][g_ax] = b_vec[b_ax][g_ax] # box axes - * normalize_vector(sep_ax[b_ax + 3]) - */ - __pyx_t_12 = __pyx_v_b_ax; - __pyx_t_13 = __pyx_v_g_ax; - ((__pyx_v_b_vec[__pyx_v_b_ax])[__pyx_v_g_ax]) = (0.5 * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_box_vectors.buf, __pyx_t_12, __pyx_bstride_0_box_vectors, __pyx_t_13, __pyx_bstride_1_box_vectors))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":195 - * for g_ax in range(3): - * b_vec[b_ax][g_ax] = 0.5*box_vectors[b_ax,g_ax] - * sep_ax[b_ax + 3][g_ax] = b_vec[b_ax][g_ax] # box axes # <<<<<<<<<<<<<< - * normalize_vector(sep_ax[b_ax + 3]) - * for g_ax in range(3): - */ - ((__pyx_v_sep_ax[(__pyx_v_b_ax + 3)])[__pyx_v_g_ax]) = ((__pyx_v_b_vec[__pyx_v_b_ax])[__pyx_v_g_ax]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":196 - * b_vec[b_ax][g_ax] = 0.5*box_vectors[b_ax,g_ax] - * sep_ax[b_ax + 3][g_ax] = b_vec[b_ax][g_ax] # box axes - * normalize_vector(sep_ax[b_ax + 3]) # <<<<<<<<<<<<<< - * for g_ax in range(3): - * get_cross_product(b_vec[b_ax], a_vec[g_ax], sep_ax[b_ax*3 + g_ax + 6]) - */ - __pyx_f_2yt_9amr_utils_normalize_vector((__pyx_v_sep_ax[(__pyx_v_b_ax + 3)])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":197 - * sep_ax[b_ax + 3][g_ax] = b_vec[b_ax][g_ax] # box axes - * normalize_vector(sep_ax[b_ax + 3]) - * for g_ax in range(3): # <<<<<<<<<<<<<< - * get_cross_product(b_vec[b_ax], a_vec[g_ax], sep_ax[b_ax*3 + g_ax + 6]) - * normalize_vector(sep_ax[b_ax*3 + g_ax + 6]) - */ - for (__pyx_t_7 = 0; __pyx_t_7 < 3; __pyx_t_7+=1) { - __pyx_v_g_ax = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":198 - * normalize_vector(sep_ax[b_ax + 3]) - * for g_ax in range(3): - * get_cross_product(b_vec[b_ax], a_vec[g_ax], sep_ax[b_ax*3 + g_ax + 6]) # <<<<<<<<<<<<<< - * normalize_vector(sep_ax[b_ax*3 + g_ax + 6]) - * - */ - __pyx_f_2yt_9amr_utils_get_cross_product((__pyx_v_b_vec[__pyx_v_b_ax]), (__pyx_v_a_vec[__pyx_v_g_ax]), (__pyx_v_sep_ax[(((__pyx_v_b_ax * 3) + __pyx_v_g_ax) + 6)])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":199 - * for g_ax in range(3): - * get_cross_product(b_vec[b_ax], a_vec[g_ax], sep_ax[b_ax*3 + g_ax + 6]) - * normalize_vector(sep_ax[b_ax*3 + g_ax + 6]) # <<<<<<<<<<<<<< - * - * for gi in range(n): - */ - __pyx_f_2yt_9amr_utils_normalize_vector((__pyx_v_sep_ax[(((__pyx_v_b_ax * 3) + __pyx_v_g_ax) + 6)])); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":201 - * normalize_vector(sep_ax[b_ax*3 + g_ax + 6]) - * - * for gi in range(n): # <<<<<<<<<<<<<< - * for g_ax in range(3): - * # Calculate the separation vector - */ - __pyx_t_6 = __pyx_v_n; - for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { - __pyx_v_gi = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":202 - * - * for gi in range(n): - * for g_ax in range(3): # <<<<<<<<<<<<<< - * # Calculate the separation vector - * sep_vec[g_ax] = grid_centers[gi, g_ax] - box_center[g_ax] - */ - for (__pyx_t_14 = 0; __pyx_t_14 < 3; __pyx_t_14+=1) { - __pyx_v_g_ax = __pyx_t_14; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":204 - * for g_ax in range(3): - * # Calculate the separation vector - * sep_vec[g_ax] = grid_centers[gi, g_ax] - box_center[g_ax] # <<<<<<<<<<<<<< - * # Calculate the grid axis lengths - * g_vec[g_ax][0] = g_vec[g_ax][1] = g_vec[g_ax][2] = 0.0 - */ - __pyx_t_15 = __pyx_v_gi; - __pyx_t_16 = __pyx_v_g_ax; - __pyx_t_17 = __pyx_v_g_ax; - (__pyx_v_sep_vec[__pyx_v_g_ax]) = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_centers.buf, __pyx_t_15, __pyx_bstride_0_grid_centers, __pyx_t_16, __pyx_bstride_1_grid_centers)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_box_center.buf, __pyx_t_17, __pyx_bstride_0_box_center))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":206 - * sep_vec[g_ax] = grid_centers[gi, g_ax] - box_center[g_ax] - * # Calculate the grid axis lengths - * g_vec[g_ax][0] = g_vec[g_ax][1] = g_vec[g_ax][2] = 0.0 # <<<<<<<<<<<<<< - * g_vec[g_ax][g_ax] = 0.5 * (grid_right_edges[gi, g_ax] - * - grid_left_edges[gi, g_ax]) - */ - ((__pyx_v_g_vec[__pyx_v_g_ax])[0]) = 0.0; - ((__pyx_v_g_vec[__pyx_v_g_ax])[1]) = 0.0; - ((__pyx_v_g_vec[__pyx_v_g_ax])[2]) = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":207 - * # Calculate the grid axis lengths - * g_vec[g_ax][0] = g_vec[g_ax][1] = g_vec[g_ax][2] = 0.0 - * g_vec[g_ax][g_ax] = 0.5 * (grid_right_edges[gi, g_ax] # <<<<<<<<<<<<<< - * - grid_left_edges[gi, g_ax]) - * for b_ax in range(15): - */ - __pyx_t_18 = __pyx_v_gi; - __pyx_t_19 = __pyx_v_g_ax; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":208 - * g_vec[g_ax][0] = g_vec[g_ax][1] = g_vec[g_ax][2] = 0.0 - * g_vec[g_ax][g_ax] = 0.5 * (grid_right_edges[gi, g_ax] - * - grid_left_edges[gi, g_ax]) # <<<<<<<<<<<<<< - * for b_ax in range(15): - * #print b_ax, - */ - __pyx_t_20 = __pyx_v_gi; - __pyx_t_21 = __pyx_v_g_ax; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":207 - * # Calculate the grid axis lengths - * g_vec[g_ax][0] = g_vec[g_ax][1] = g_vec[g_ax][2] = 0.0 - * g_vec[g_ax][g_ax] = 0.5 * (grid_right_edges[gi, g_ax] # <<<<<<<<<<<<<< - * - grid_left_edges[gi, g_ax]) - * for b_ax in range(15): - */ - ((__pyx_v_g_vec[__pyx_v_g_ax])[__pyx_v_g_ax]) = (0.5 * ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_right_edges.buf, __pyx_t_18, __pyx_bstride_0_grid_right_edges, __pyx_t_19, __pyx_bstride_1_grid_right_edges)) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_left_edges.buf, __pyx_t_20, __pyx_bstride_0_grid_left_edges, __pyx_t_21, __pyx_bstride_1_grid_left_edges)))); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":209 - * g_vec[g_ax][g_ax] = 0.5 * (grid_right_edges[gi, g_ax] - * - grid_left_edges[gi, g_ax]) - * for b_ax in range(15): # <<<<<<<<<<<<<< - * #print b_ax, - * if check_projected_overlap( - */ - for (__pyx_t_14 = 0; __pyx_t_14 < 15; __pyx_t_14+=1) { - __pyx_v_b_ax = __pyx_t_14; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":213 - * if check_projected_overlap( - * sep_ax[b_ax], sep_vec, gi, - * b_vec, g_vec): # <<<<<<<<<<<<<< - * good[gi] = 1 - * break - */ - __pyx_t_22 = __pyx_f_2yt_9amr_utils_check_projected_overlap((__pyx_v_sep_ax[__pyx_v_b_ax]), __pyx_v_sep_vec, __pyx_v_gi, __pyx_v_b_vec, __pyx_v_g_vec); - if (__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":214 - * sep_ax[b_ax], sep_vec, gi, - * b_vec, g_vec): - * good[gi] = 1 # <<<<<<<<<<<<<< - * break - * return good - */ - __pyx_t_22 = __pyx_v_gi; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_good.buf, __pyx_t_22, __pyx_bstride_0_good) = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":215 - * b_vec, g_vec): - * good[gi] = 1 - * break # <<<<<<<<<<<<<< - * return good - * - */ - goto __pyx_L21_break; - goto __pyx_L22; - } - __pyx_L22:; - } - __pyx_L21_break:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":216 - * good[gi] = 1 - * break - * return good # <<<<<<<<<<<<<< - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_good)); - __pyx_r = ((PyObject *)__pyx_v_good); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_left_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_vectors); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_good); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_right_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_centers); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_center); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.find_grids_in_inclined_box"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_left_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_vectors); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_good); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_right_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_centers); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_box_center); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_good); - __Pyx_DECREF((PyObject *)__pyx_v_grid_centers); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":36 - * - * @cython.boundscheck(False) - * def Transfer3D(np.ndarray[np.float64_t, ndim=3] i_s, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=4] o_s, - * np.ndarray[np.float64_t, ndim=4] e, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_Transfer3D(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_2yt_9amr_utils_Transfer3D[] = "\n This function accepts an incoming slab (*i_s*), a buffer\n for an outgoing set of values at every point in the grid (*o_s*),\n an emission array (*e*), an absorption array (*a*), and dimensions of\n the grid (*imin*, *imax*, *jmin*, *jmax*, *kmin*, *kmax*) as well\n as strides in the *i* and *j* directions, and a *dx* of the grid being\n integrated.\n "; -static PyObject *__pyx_pf_2yt_9amr_utils_Transfer3D(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_i_s = 0; - PyArrayObject *__pyx_v_o_s = 0; - PyArrayObject *__pyx_v_e = 0; - PyArrayObject *__pyx_v_a = 0; - int __pyx_v_imin; - int __pyx_v_imax; - int __pyx_v_jmin; - int __pyx_v_jmax; - int __pyx_v_kmin; - int __pyx_v_kmax; - int __pyx_v_istride; - int __pyx_v_jstride; - __pyx_t_5numpy_float64_t __pyx_v_dx; - int __pyx_v_i; - int __pyx_v_ii; - int __pyx_v_j; - int __pyx_v_jj; - int __pyx_v_k; - int __pyx_v_kk; - int __pyx_v_n; - int __pyx_v_nn; - __pyx_t_5numpy_float64_t *__pyx_v_temp; - Py_buffer __pyx_bstruct_o_s; - Py_ssize_t __pyx_bstride_0_o_s = 0; - Py_ssize_t __pyx_bstride_1_o_s = 0; - Py_ssize_t __pyx_bstride_2_o_s = 0; - Py_ssize_t __pyx_bstride_3_o_s = 0; - Py_ssize_t __pyx_bshape_0_o_s = 0; - Py_ssize_t __pyx_bshape_1_o_s = 0; - Py_ssize_t __pyx_bshape_2_o_s = 0; - Py_ssize_t __pyx_bshape_3_o_s = 0; - Py_buffer __pyx_bstruct_i_s; - Py_ssize_t __pyx_bstride_0_i_s = 0; - Py_ssize_t __pyx_bstride_1_i_s = 0; - Py_ssize_t __pyx_bstride_2_i_s = 0; - Py_ssize_t __pyx_bshape_0_i_s = 0; - Py_ssize_t __pyx_bshape_1_i_s = 0; - Py_ssize_t __pyx_bshape_2_i_s = 0; - Py_buffer __pyx_bstruct_a; - Py_ssize_t __pyx_bstride_0_a = 0; - Py_ssize_t __pyx_bstride_1_a = 0; - Py_ssize_t __pyx_bstride_2_a = 0; - Py_ssize_t __pyx_bstride_3_a = 0; - Py_ssize_t __pyx_bshape_0_a = 0; - Py_ssize_t __pyx_bshape_1_a = 0; - Py_ssize_t __pyx_bshape_2_a = 0; - Py_ssize_t __pyx_bshape_3_a = 0; - Py_buffer __pyx_bstruct_e; - Py_ssize_t __pyx_bstride_0_e = 0; - Py_ssize_t __pyx_bstride_1_e = 0; - Py_ssize_t __pyx_bstride_2_e = 0; - Py_ssize_t __pyx_bstride_3_e = 0; - Py_ssize_t __pyx_bshape_0_e = 0; - Py_ssize_t __pyx_bshape_1_e = 0; - Py_ssize_t __pyx_bshape_2_e = 0; - Py_ssize_t __pyx_bshape_3_e = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i_s,&__pyx_n_s__o_s,&__pyx_n_s__e,&__pyx_n_s__a,&__pyx_n_s__imin,&__pyx_n_s__imax,&__pyx_n_s__jmin,&__pyx_n_s__jmax,&__pyx_n_s__kmin,&__pyx_n_s__kmax,&__pyx_n_s__istride,&__pyx_n_s__jstride,&__pyx_n_s__dx,0}; - __Pyx_RefNannySetupContext("Transfer3D"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_s); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__o_s); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 2); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 3); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__imin); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 4); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__imax); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 5); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__jmin); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 6); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__jmax); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 7); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 8: - values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__kmin); - if (likely(values[8])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 8); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 9: - values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__kmax); - if (likely(values[9])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 9); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 10: - values[10] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__istride); - if (likely(values[10])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 10); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 11: - values[11] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__jstride); - if (likely(values[11])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 11); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 12: - values[12] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[12])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, 12); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "Transfer3D") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_i_s = ((PyArrayObject *)values[0]); - __pyx_v_o_s = ((PyArrayObject *)values[1]); - __pyx_v_e = ((PyArrayObject *)values[2]); - __pyx_v_a = ((PyArrayObject *)values[3]); - __pyx_v_imin = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_imin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_imax = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_imax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_jmin = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_jmin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_jmax = __Pyx_PyInt_AsInt(values[7]); if (unlikely((__pyx_v_jmax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_kmin = __Pyx_PyInt_AsInt(values[8]); if (unlikely((__pyx_v_kmin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_kmax = __Pyx_PyInt_AsInt(values[9]); if (unlikely((__pyx_v_kmax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_istride = __Pyx_PyInt_AsInt(values[10]); if (unlikely((__pyx_v_istride == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_jstride = __Pyx_PyInt_AsInt(values[11]); if (unlikely((__pyx_v_jstride == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_dx = __pyx_PyFloat_AsDouble(values[12]); if (unlikely((__pyx_v_dx == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 13) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_i_s = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_o_s = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_e = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_a = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_imin = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_imin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_imax = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_imax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_jmin = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 6)); if (unlikely((__pyx_v_jmin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_jmax = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 7)); if (unlikely((__pyx_v_jmax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_kmin = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 8)); if (unlikely((__pyx_v_kmin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_kmax = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 9)); if (unlikely((__pyx_v_kmax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_istride = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 10)); if (unlikely((__pyx_v_istride == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_jstride = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 11)); if (unlikely((__pyx_v_jstride == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_dx = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 12)); if (unlikely((__pyx_v_dx == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("Transfer3D", 1, 13, 13, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.Transfer3D"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_i_s.buf = NULL; - __pyx_bstruct_o_s.buf = NULL; - __pyx_bstruct_e.buf = NULL; - __pyx_bstruct_a.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_i_s), __pyx_ptype_5numpy_ndarray, 1, "i_s", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_o_s), __pyx_ptype_5numpy_ndarray, 1, "o_s", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_5numpy_ndarray, 1, "e", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_5numpy_ndarray, 1, "a", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_i_s, (PyObject*)__pyx_v_i_s, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_i_s = __pyx_bstruct_i_s.strides[0]; __pyx_bstride_1_i_s = __pyx_bstruct_i_s.strides[1]; __pyx_bstride_2_i_s = __pyx_bstruct_i_s.strides[2]; - __pyx_bshape_0_i_s = __pyx_bstruct_i_s.shape[0]; __pyx_bshape_1_i_s = __pyx_bstruct_i_s.shape[1]; __pyx_bshape_2_i_s = __pyx_bstruct_i_s.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_o_s, (PyObject*)__pyx_v_o_s, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 4, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_o_s = __pyx_bstruct_o_s.strides[0]; __pyx_bstride_1_o_s = __pyx_bstruct_o_s.strides[1]; __pyx_bstride_2_o_s = __pyx_bstruct_o_s.strides[2]; __pyx_bstride_3_o_s = __pyx_bstruct_o_s.strides[3]; - __pyx_bshape_0_o_s = __pyx_bstruct_o_s.shape[0]; __pyx_bshape_1_o_s = __pyx_bstruct_o_s.shape[1]; __pyx_bshape_2_o_s = __pyx_bstruct_o_s.shape[2]; __pyx_bshape_3_o_s = __pyx_bstruct_o_s.shape[3]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_e, (PyObject*)__pyx_v_e, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_e = __pyx_bstruct_e.strides[0]; __pyx_bstride_1_e = __pyx_bstruct_e.strides[1]; __pyx_bstride_2_e = __pyx_bstruct_e.strides[2]; __pyx_bstride_3_e = __pyx_bstruct_e.strides[3]; - __pyx_bshape_0_e = __pyx_bstruct_e.shape[0]; __pyx_bshape_1_e = __pyx_bstruct_e.shape[1]; __pyx_bshape_2_e = __pyx_bstruct_e.shape[2]; __pyx_bshape_3_e = __pyx_bstruct_e.shape[3]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_a, (PyObject*)__pyx_v_a, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_a = __pyx_bstruct_a.strides[0]; __pyx_bstride_1_a = __pyx_bstruct_a.strides[1]; __pyx_bstride_2_a = __pyx_bstruct_a.strides[2]; __pyx_bstride_3_a = __pyx_bstruct_a.strides[3]; - __pyx_bshape_0_a = __pyx_bstruct_a.shape[0]; __pyx_bshape_1_a = __pyx_bstruct_a.shape[1]; __pyx_bshape_2_a = __pyx_bstruct_a.shape[2]; __pyx_bshape_3_a = __pyx_bstruct_a.shape[3]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":55 - * cdef int k, kk - * cdef int n, nn - * nn = o_s.shape[3] # This might be slow # <<<<<<<<<<<<<< - * cdef np.float64_t *temp = malloc(sizeof(np.float64_t) * nn) - * for i in range((imax-imin)*istride): - */ - __pyx_v_nn = (__pyx_v_o_s->dimensions[3]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":56 - * cdef int n, nn - * nn = o_s.shape[3] # This might be slow - * cdef np.float64_t *temp = malloc(sizeof(np.float64_t) * nn) # <<<<<<<<<<<<<< - * for i in range((imax-imin)*istride): - * ii = i + imin*istride - */ - __pyx_v_temp = ((__pyx_t_5numpy_float64_t *)malloc(((sizeof(__pyx_t_5numpy_float64_t)) * __pyx_v_nn))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":57 - * nn = o_s.shape[3] # This might be slow - * cdef np.float64_t *temp = malloc(sizeof(np.float64_t) * nn) - * for i in range((imax-imin)*istride): # <<<<<<<<<<<<<< - * ii = i + imin*istride - * for j in range((jmax-jmin)*jstride): - */ - __pyx_t_1 = ((__pyx_v_imax - __pyx_v_imin) * __pyx_v_istride); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":58 - * cdef np.float64_t *temp = malloc(sizeof(np.float64_t) * nn) - * for i in range((imax-imin)*istride): - * ii = i + imin*istride # <<<<<<<<<<<<<< - * for j in range((jmax-jmin)*jstride): - * jj = j + jmin*jstride - */ - __pyx_v_ii = (__pyx_v_i + (__pyx_v_imin * __pyx_v_istride)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":59 - * for i in range((imax-imin)*istride): - * ii = i + imin*istride - * for j in range((jmax-jmin)*jstride): # <<<<<<<<<<<<<< - * jj = j + jmin*jstride - * # Not sure about the ordering of the loops here - */ - __pyx_t_3 = ((__pyx_v_jmax - __pyx_v_jmin) * __pyx_v_jstride); - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_j = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":60 - * ii = i + imin*istride - * for j in range((jmax-jmin)*jstride): - * jj = j + jmin*jstride # <<<<<<<<<<<<<< - * # Not sure about the ordering of the loops here - * for n in range(nn): - */ - __pyx_v_jj = (__pyx_v_j + (__pyx_v_jmin * __pyx_v_jstride)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":62 - * jj = j + jmin*jstride - * # Not sure about the ordering of the loops here - * for n in range(nn): # <<<<<<<<<<<<<< - * temp[n] = i_s[ii,jj,n] - * for k in range(kmax-kmin): - */ - __pyx_t_5 = __pyx_v_nn; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_n = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":63 - * # Not sure about the ordering of the loops here - * for n in range(nn): - * temp[n] = i_s[ii,jj,n] # <<<<<<<<<<<<<< - * for k in range(kmax-kmin): - * kk = k + kmin#*kstride, which doesn't make any sense - */ - __pyx_t_7 = __pyx_v_ii; - __pyx_t_8 = __pyx_v_jj; - __pyx_t_9 = __pyx_v_n; - if (__pyx_t_7 < 0) __pyx_t_7 += __pyx_bshape_0_i_s; - if (__pyx_t_8 < 0) __pyx_t_8 += __pyx_bshape_1_i_s; - if (__pyx_t_9 < 0) __pyx_t_9 += __pyx_bshape_2_i_s; - (__pyx_v_temp[__pyx_v_n]) = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_7, __pyx_bstride_0_i_s, __pyx_t_8, __pyx_bstride_1_i_s, __pyx_t_9, __pyx_bstride_2_i_s)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":64 - * for n in range(nn): - * temp[n] = i_s[ii,jj,n] - * for k in range(kmax-kmin): # <<<<<<<<<<<<<< - * kk = k + kmin#*kstride, which doesn't make any sense - * for n in range(nn): - */ - __pyx_t_5 = (__pyx_v_kmax - __pyx_v_kmin); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_k = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":65 - * temp[n] = i_s[ii,jj,n] - * for k in range(kmax-kmin): - * kk = k + kmin#*kstride, which doesn't make any sense # <<<<<<<<<<<<<< - * for n in range(nn): - * o_s[i,j,k,n] = temp[n] + dx*(e[i,j,k,n] - temp[n]*a[i,j,k,n]) - */ - __pyx_v_kk = (__pyx_v_k + __pyx_v_kmin); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":66 - * for k in range(kmax-kmin): - * kk = k + kmin#*kstride, which doesn't make any sense - * for n in range(nn): # <<<<<<<<<<<<<< - * o_s[i,j,k,n] = temp[n] + dx*(e[i,j,k,n] - temp[n]*a[i,j,k,n]) - * temp[n] = o_s[i,j,k,n] - */ - __pyx_t_10 = __pyx_v_nn; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_n = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":67 - * kk = k + kmin#*kstride, which doesn't make any sense - * for n in range(nn): - * o_s[i,j,k,n] = temp[n] + dx*(e[i,j,k,n] - temp[n]*a[i,j,k,n]) # <<<<<<<<<<<<<< - * temp[n] = o_s[i,j,k,n] - * for n in range(nn): - */ - __pyx_t_12 = __pyx_v_i; - __pyx_t_13 = __pyx_v_j; - __pyx_t_14 = __pyx_v_k; - __pyx_t_15 = __pyx_v_n; - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_0_e; - if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_bshape_1_e; - if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_bshape_2_e; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_3_e; - __pyx_t_16 = __pyx_v_i; - __pyx_t_17 = __pyx_v_j; - __pyx_t_18 = __pyx_v_k; - __pyx_t_19 = __pyx_v_n; - if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_bshape_0_a; - if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_bshape_1_a; - if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_bshape_2_a; - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_3_a; - __pyx_t_20 = __pyx_v_i; - __pyx_t_21 = __pyx_v_j; - __pyx_t_22 = __pyx_v_k; - __pyx_t_23 = __pyx_v_n; - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_0_o_s; - if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_1_o_s; - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_2_o_s; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_3_o_s; - *__Pyx_BufPtrStrided4d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_o_s.buf, __pyx_t_20, __pyx_bstride_0_o_s, __pyx_t_21, __pyx_bstride_1_o_s, __pyx_t_22, __pyx_bstride_2_o_s, __pyx_t_23, __pyx_bstride_3_o_s) = ((__pyx_v_temp[__pyx_v_n]) + (__pyx_v_dx * ((*__Pyx_BufPtrStrided4d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_e.buf, __pyx_t_12, __pyx_bstride_0_e, __pyx_t_13, __pyx_bstride_1_e, __pyx_t_14, __pyx_bstride_2_e, __pyx_t_15, __pyx_bstride_3_e)) - ((__pyx_v_temp[__pyx_v_n]) * (*__Pyx_BufPtrStrided4d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_a.buf, __pyx_t_16, __pyx_bstride_0_a, __pyx_t_17, __pyx_bstride_1_a, __pyx_t_18, __pyx_bstride_2_a, __pyx_t_19, __pyx_bstride_3_a)))))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":68 - * for n in range(nn): - * o_s[i,j,k,n] = temp[n] + dx*(e[i,j,k,n] - temp[n]*a[i,j,k,n]) - * temp[n] = o_s[i,j,k,n] # <<<<<<<<<<<<<< - * for n in range(nn): - * i_s[ii,jj,n] = temp[n] - */ - __pyx_t_24 = __pyx_v_i; - __pyx_t_25 = __pyx_v_j; - __pyx_t_26 = __pyx_v_k; - __pyx_t_27 = __pyx_v_n; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_0_o_s; - if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_1_o_s; - if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_2_o_s; - if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_3_o_s; - (__pyx_v_temp[__pyx_v_n]) = (*__Pyx_BufPtrStrided4d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_o_s.buf, __pyx_t_24, __pyx_bstride_0_o_s, __pyx_t_25, __pyx_bstride_1_o_s, __pyx_t_26, __pyx_bstride_2_o_s, __pyx_t_27, __pyx_bstride_3_o_s)); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":69 - * o_s[i,j,k,n] = temp[n] + dx*(e[i,j,k,n] - temp[n]*a[i,j,k,n]) - * temp[n] = o_s[i,j,k,n] - * for n in range(nn): # <<<<<<<<<<<<<< - * i_s[ii,jj,n] = temp[n] - * free(temp) - */ - __pyx_t_5 = __pyx_v_nn; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_n = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":70 - * temp[n] = o_s[i,j,k,n] - * for n in range(nn): - * i_s[ii,jj,n] = temp[n] # <<<<<<<<<<<<<< - * free(temp) - * - */ - __pyx_t_10 = __pyx_v_ii; - __pyx_t_11 = __pyx_v_jj; - __pyx_t_28 = __pyx_v_n; - if (__pyx_t_10 < 0) __pyx_t_10 += __pyx_bshape_0_i_s; - if (__pyx_t_11 < 0) __pyx_t_11 += __pyx_bshape_1_i_s; - if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_2_i_s; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_10, __pyx_bstride_0_i_s, __pyx_t_11, __pyx_bstride_1_i_s, __pyx_t_28, __pyx_bstride_2_i_s) = (__pyx_v_temp[__pyx_v_n]); - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":71 - * for n in range(nn): - * i_s[ii,jj,n] = temp[n] - * free(temp) # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - free(__pyx_v_temp); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_o_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_i_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_a); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_e); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.Transfer3D"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_o_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_i_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_a); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_e); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":74 - * - * @cython.boundscheck(False) - * def TransferShells(np.ndarray[np.float64_t, ndim=3] i_s, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=3] data, - * np.ndarray[np.float64_t, ndim=2] shells): - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_TransferShells(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_2yt_9amr_utils_TransferShells[] = "\n This function accepts an incoming slab (*i_s*), a buffer of *data*,\n and a list of shells specified as [ (value, tolerance, r, g, b), ... ].\n "; -static PyObject *__pyx_pf_2yt_9amr_utils_TransferShells(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_i_s = 0; - PyArrayObject *__pyx_v_data = 0; - PyArrayObject *__pyx_v_shells = 0; - int __pyx_v_i; - int __pyx_v_ii; - int __pyx_v_j; - int __pyx_v_jj; - int __pyx_v_k; - int __pyx_v_kk; - int __pyx_v_n; - int __pyx_v_nn; - __pyx_t_5numpy_float64_t __pyx_v_dist; - float __pyx_v_rgba[4]; - float __pyx_v_alpha; - Py_buffer __pyx_bstruct_shells; - Py_ssize_t __pyx_bstride_0_shells = 0; - Py_ssize_t __pyx_bstride_1_shells = 0; - Py_ssize_t __pyx_bshape_0_shells = 0; - Py_ssize_t __pyx_bshape_1_shells = 0; - Py_buffer __pyx_bstruct_i_s; - Py_ssize_t __pyx_bstride_0_i_s = 0; - Py_ssize_t __pyx_bstride_1_i_s = 0; - Py_ssize_t __pyx_bstride_2_i_s = 0; - Py_ssize_t __pyx_bshape_0_i_s = 0; - Py_ssize_t __pyx_bshape_1_i_s = 0; - Py_ssize_t __pyx_bshape_2_i_s = 0; - Py_buffer __pyx_bstruct_data; - Py_ssize_t __pyx_bstride_0_data = 0; - Py_ssize_t __pyx_bstride_1_data = 0; - Py_ssize_t __pyx_bstride_2_data = 0; - Py_ssize_t __pyx_bshape_0_data = 0; - Py_ssize_t __pyx_bshape_1_data = 0; - Py_ssize_t __pyx_bshape_2_data = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - long __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - long __pyx_t_16; - int __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - long __pyx_t_20; - int __pyx_t_21; - long __pyx_t_22; - int __pyx_t_23; - long __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - long __pyx_t_27; - int __pyx_t_28; - int __pyx_t_29; - long __pyx_t_30; - int __pyx_t_31; - int __pyx_t_32; - long __pyx_t_33; - int __pyx_t_34; - int __pyx_t_35; - long __pyx_t_36; - int __pyx_t_37; - int __pyx_t_38; - long __pyx_t_39; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i_s,&__pyx_n_s__data,&__pyx_n_s__shells,0}; - __Pyx_RefNannySetupContext("TransferShells"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[3] = {0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_s); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TransferShells", 1, 3, 3, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__shells); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("TransferShells", 1, 3, 3, 2); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "TransferShells") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_i_s = ((PyArrayObject *)values[0]); - __pyx_v_data = ((PyArrayObject *)values[1]); - __pyx_v_shells = ((PyArrayObject *)values[2]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_i_s = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_data = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_shells = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("TransferShells", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.TransferShells"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_i_s.buf = NULL; - __pyx_bstruct_data.buf = NULL; - __pyx_bstruct_shells.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_i_s), __pyx_ptype_5numpy_ndarray, 1, "i_s", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shells), __pyx_ptype_5numpy_ndarray, 1, "shells", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_i_s, (PyObject*)__pyx_v_i_s, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_i_s = __pyx_bstruct_i_s.strides[0]; __pyx_bstride_1_i_s = __pyx_bstruct_i_s.strides[1]; __pyx_bstride_2_i_s = __pyx_bstruct_i_s.strides[2]; - __pyx_bshape_0_i_s = __pyx_bstruct_i_s.shape[0]; __pyx_bshape_1_i_s = __pyx_bstruct_i_s.shape[1]; __pyx_bshape_2_i_s = __pyx_bstruct_i_s.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bstride_2_data = __pyx_bstruct_data.strides[2]; - __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; __pyx_bshape_2_data = __pyx_bstruct_data.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_shells, (PyObject*)__pyx_v_shells, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_shells = __pyx_bstruct_shells.strides[0]; __pyx_bstride_1_shells = __pyx_bstruct_shells.strides[1]; - __pyx_bshape_0_shells = __pyx_bstruct_shells.shape[0]; __pyx_bshape_1_shells = __pyx_bstruct_shells.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":86 - * cdef int n, nn - * cdef np.float64_t dist - * ii = data.shape[0] # <<<<<<<<<<<<<< - * jj = data.shape[1] - * kk = data.shape[2] - */ - __pyx_v_ii = (__pyx_v_data->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":87 - * cdef np.float64_t dist - * ii = data.shape[0] - * jj = data.shape[1] # <<<<<<<<<<<<<< - * kk = data.shape[2] - * nn = shells.shape[0] - */ - __pyx_v_jj = (__pyx_v_data->dimensions[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":88 - * ii = data.shape[0] - * jj = data.shape[1] - * kk = data.shape[2] # <<<<<<<<<<<<<< - * nn = shells.shape[0] - * cdef float rgba[4] - */ - __pyx_v_kk = (__pyx_v_data->dimensions[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":89 - * jj = data.shape[1] - * kk = data.shape[2] - * nn = shells.shape[0] # <<<<<<<<<<<<<< - * cdef float rgba[4] - * cdef float alpha - */ - __pyx_v_nn = (__pyx_v_shells->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":92 - * cdef float rgba[4] - * cdef float alpha - * for i in range(ii): # <<<<<<<<<<<<<< - * for j in range(jj): - * # Not sure about the ordering of the loops here - */ - __pyx_t_1 = __pyx_v_ii; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":93 - * cdef float alpha - * for i in range(ii): - * for j in range(jj): # <<<<<<<<<<<<<< - * # Not sure about the ordering of the loops here - * for k in range(kk): - */ - __pyx_t_3 = __pyx_v_jj; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_j = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":95 - * for j in range(jj): - * # Not sure about the ordering of the loops here - * for k in range(kk): # <<<<<<<<<<<<<< - * for n in range(nn): - * dist = shells[n, 0] - data[i,j,k] - */ - __pyx_t_5 = __pyx_v_kk; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_k = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":96 - * # Not sure about the ordering of the loops here - * for k in range(kk): - * for n in range(nn): # <<<<<<<<<<<<<< - * dist = shells[n, 0] - data[i,j,k] - * if dist < 0: dist *= -1.0 - */ - __pyx_t_7 = __pyx_v_nn; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_n = __pyx_t_8; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":97 - * for k in range(kk): - * for n in range(nn): - * dist = shells[n, 0] - data[i,j,k] # <<<<<<<<<<<<<< - * if dist < 0: dist *= -1.0 - * if dist < shells[n,1]: - */ - __pyx_t_9 = __pyx_v_n; - __pyx_t_10 = 0; - if (__pyx_t_9 < 0) __pyx_t_9 += __pyx_bshape_0_shells; - if (__pyx_t_10 < 0) __pyx_t_10 += __pyx_bshape_1_shells; - __pyx_t_11 = __pyx_v_i; - __pyx_t_12 = __pyx_v_j; - __pyx_t_13 = __pyx_v_k; - if (__pyx_t_11 < 0) __pyx_t_11 += __pyx_bshape_0_data; - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_1_data; - if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_bshape_2_data; - __pyx_v_dist = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_9, __pyx_bstride_0_shells, __pyx_t_10, __pyx_bstride_1_shells)) - (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_data.buf, __pyx_t_11, __pyx_bstride_0_data, __pyx_t_12, __pyx_bstride_1_data, __pyx_t_13, __pyx_bstride_2_data))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":98 - * for n in range(nn): - * dist = shells[n, 0] - data[i,j,k] - * if dist < 0: dist *= -1.0 # <<<<<<<<<<<<<< - * if dist < shells[n,1]: - * dist = exp(-dist/8.0) - */ - __pyx_t_14 = (__pyx_v_dist < 0.0); - if (__pyx_t_14) { - __pyx_v_dist *= (-1.0); - goto __pyx_L14; - } - __pyx_L14:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":99 - * dist = shells[n, 0] - data[i,j,k] - * if dist < 0: dist *= -1.0 - * if dist < shells[n,1]: # <<<<<<<<<<<<<< - * dist = exp(-dist/8.0) - * rgba[0] = shells[n,2] - */ - __pyx_t_15 = __pyx_v_n; - __pyx_t_16 = 1; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_0_shells; - if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_bshape_1_shells; - __pyx_t_14 = (__pyx_v_dist < (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_15, __pyx_bstride_0_shells, __pyx_t_16, __pyx_bstride_1_shells))); - if (__pyx_t_14) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":100 - * if dist < 0: dist *= -1.0 - * if dist < shells[n,1]: - * dist = exp(-dist/8.0) # <<<<<<<<<<<<<< - * rgba[0] = shells[n,2] - * rgba[1] = shells[n,3] - */ - __pyx_v_dist = exp(((-__pyx_v_dist) / 8.0)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":101 - * if dist < shells[n,1]: - * dist = exp(-dist/8.0) - * rgba[0] = shells[n,2] # <<<<<<<<<<<<<< - * rgba[1] = shells[n,3] - * rgba[2] = shells[n,4] - */ - __pyx_t_17 = __pyx_v_n; - __pyx_t_18 = 2; - if (__pyx_t_17 < 0) __pyx_t_17 += __pyx_bshape_0_shells; - if (__pyx_t_18 < 0) __pyx_t_18 += __pyx_bshape_1_shells; - (__pyx_v_rgba[0]) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_17, __pyx_bstride_0_shells, __pyx_t_18, __pyx_bstride_1_shells)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":102 - * dist = exp(-dist/8.0) - * rgba[0] = shells[n,2] - * rgba[1] = shells[n,3] # <<<<<<<<<<<<<< - * rgba[2] = shells[n,4] - * rgba[3] = shells[n,5] - */ - __pyx_t_19 = __pyx_v_n; - __pyx_t_20 = 3; - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_0_shells; - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_1_shells; - (__pyx_v_rgba[1]) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_19, __pyx_bstride_0_shells, __pyx_t_20, __pyx_bstride_1_shells)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":103 - * rgba[0] = shells[n,2] - * rgba[1] = shells[n,3] - * rgba[2] = shells[n,4] # <<<<<<<<<<<<<< - * rgba[3] = shells[n,5] - * alpha = i_s[i,j,3] - */ - __pyx_t_21 = __pyx_v_n; - __pyx_t_22 = 4; - if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_0_shells; - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_1_shells; - (__pyx_v_rgba[2]) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_21, __pyx_bstride_0_shells, __pyx_t_22, __pyx_bstride_1_shells)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":104 - * rgba[1] = shells[n,3] - * rgba[2] = shells[n,4] - * rgba[3] = shells[n,5] # <<<<<<<<<<<<<< - * alpha = i_s[i,j,3] - * dist *= dist # This might improve appearance - */ - __pyx_t_23 = __pyx_v_n; - __pyx_t_24 = 5; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_0_shells; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_1_shells; - (__pyx_v_rgba[3]) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_23, __pyx_bstride_0_shells, __pyx_t_24, __pyx_bstride_1_shells)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":105 - * rgba[2] = shells[n,4] - * rgba[3] = shells[n,5] - * alpha = i_s[i,j,3] # <<<<<<<<<<<<<< - * dist *= dist # This might improve appearance - * i_s[i,j,0] += (1.0 - alpha)*rgba[0]*dist*rgba[3] - */ - __pyx_t_25 = __pyx_v_i; - __pyx_t_26 = __pyx_v_j; - __pyx_t_27 = 3; - if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_0_i_s; - if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_1_i_s; - if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_2_i_s; - __pyx_v_alpha = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_25, __pyx_bstride_0_i_s, __pyx_t_26, __pyx_bstride_1_i_s, __pyx_t_27, __pyx_bstride_2_i_s)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":106 - * rgba[3] = shells[n,5] - * alpha = i_s[i,j,3] - * dist *= dist # This might improve appearance # <<<<<<<<<<<<<< - * i_s[i,j,0] += (1.0 - alpha)*rgba[0]*dist*rgba[3] - * i_s[i,j,1] += (1.0 - alpha)*rgba[1]*dist*rgba[3] - */ - __pyx_v_dist *= __pyx_v_dist; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":107 - * alpha = i_s[i,j,3] - * dist *= dist # This might improve appearance - * i_s[i,j,0] += (1.0 - alpha)*rgba[0]*dist*rgba[3] # <<<<<<<<<<<<<< - * i_s[i,j,1] += (1.0 - alpha)*rgba[1]*dist*rgba[3] - * i_s[i,j,2] += (1.0 - alpha)*rgba[2]*dist*rgba[3] - */ - __pyx_t_28 = __pyx_v_i; - __pyx_t_29 = __pyx_v_j; - __pyx_t_30 = 0; - if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_0_i_s; - if (__pyx_t_29 < 0) __pyx_t_29 += __pyx_bshape_1_i_s; - if (__pyx_t_30 < 0) __pyx_t_30 += __pyx_bshape_2_i_s; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_28, __pyx_bstride_0_i_s, __pyx_t_29, __pyx_bstride_1_i_s, __pyx_t_30, __pyx_bstride_2_i_s) += ((((1.0 - __pyx_v_alpha) * (__pyx_v_rgba[0])) * __pyx_v_dist) * (__pyx_v_rgba[3])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":108 - * dist *= dist # This might improve appearance - * i_s[i,j,0] += (1.0 - alpha)*rgba[0]*dist*rgba[3] - * i_s[i,j,1] += (1.0 - alpha)*rgba[1]*dist*rgba[3] # <<<<<<<<<<<<<< - * i_s[i,j,2] += (1.0 - alpha)*rgba[2]*dist*rgba[3] - * i_s[i,j,3] += (1.0 - alpha)*rgba[3]*dist*rgba[3] - */ - __pyx_t_31 = __pyx_v_i; - __pyx_t_32 = __pyx_v_j; - __pyx_t_33 = 1; - if (__pyx_t_31 < 0) __pyx_t_31 += __pyx_bshape_0_i_s; - if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_bshape_1_i_s; - if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_bshape_2_i_s; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_31, __pyx_bstride_0_i_s, __pyx_t_32, __pyx_bstride_1_i_s, __pyx_t_33, __pyx_bstride_2_i_s) += ((((1.0 - __pyx_v_alpha) * (__pyx_v_rgba[1])) * __pyx_v_dist) * (__pyx_v_rgba[3])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":109 - * i_s[i,j,0] += (1.0 - alpha)*rgba[0]*dist*rgba[3] - * i_s[i,j,1] += (1.0 - alpha)*rgba[1]*dist*rgba[3] - * i_s[i,j,2] += (1.0 - alpha)*rgba[2]*dist*rgba[3] # <<<<<<<<<<<<<< - * i_s[i,j,3] += (1.0 - alpha)*rgba[3]*dist*rgba[3] - * break - */ - __pyx_t_34 = __pyx_v_i; - __pyx_t_35 = __pyx_v_j; - __pyx_t_36 = 2; - if (__pyx_t_34 < 0) __pyx_t_34 += __pyx_bshape_0_i_s; - if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_bshape_1_i_s; - if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_bshape_2_i_s; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_34, __pyx_bstride_0_i_s, __pyx_t_35, __pyx_bstride_1_i_s, __pyx_t_36, __pyx_bstride_2_i_s) += ((((1.0 - __pyx_v_alpha) * (__pyx_v_rgba[2])) * __pyx_v_dist) * (__pyx_v_rgba[3])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":110 - * i_s[i,j,1] += (1.0 - alpha)*rgba[1]*dist*rgba[3] - * i_s[i,j,2] += (1.0 - alpha)*rgba[2]*dist*rgba[3] - * i_s[i,j,3] += (1.0 - alpha)*rgba[3]*dist*rgba[3] # <<<<<<<<<<<<<< - * break - * - */ - __pyx_t_37 = __pyx_v_i; - __pyx_t_38 = __pyx_v_j; - __pyx_t_39 = 3; - if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_bshape_0_i_s; - if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_bshape_1_i_s; - if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_bshape_2_i_s; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_i_s.buf, __pyx_t_37, __pyx_bstride_0_i_s, __pyx_t_38, __pyx_bstride_1_i_s, __pyx_t_39, __pyx_bstride_2_i_s) += ((((1.0 - __pyx_v_alpha) * (__pyx_v_rgba[3])) * __pyx_v_dist) * (__pyx_v_rgba[3])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":111 - * i_s[i,j,2] += (1.0 - alpha)*rgba[2]*dist*rgba[3] - * i_s[i,j,3] += (1.0 - alpha)*rgba[3]*dist*rgba[3] - * break # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - goto __pyx_L13_break; - goto __pyx_L15; - } - __pyx_L15:; - } - __pyx_L13_break:; - } - } - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_shells); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_i_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.TransferShells"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_shells); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_i_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":114 - * - * @cython.boundscheck(False) - * def Transfer1D(float i_s, # <<<<<<<<<<<<<< - * np.ndarray[np.float_t, ndim=1] o_s, - * np.ndarray[np.float_t, ndim=1] e, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_Transfer1D(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_Transfer1D(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - float __pyx_v_i_s; - PyArrayObject *__pyx_v_o_s = 0; - PyArrayObject *__pyx_v_e = 0; - PyArrayObject *__pyx_v_a = 0; - PyArrayObject *__pyx_v_dx = 0; - int __pyx_v_imin; - int __pyx_v_imax; - int __pyx_v_i; - Py_buffer __pyx_bstruct_a; - Py_ssize_t __pyx_bstride_0_a = 0; - Py_ssize_t __pyx_bshape_0_a = 0; - Py_buffer __pyx_bstruct_e; - Py_ssize_t __pyx_bstride_0_e = 0; - Py_ssize_t __pyx_bshape_0_e = 0; - Py_buffer __pyx_bstruct_o_s; - Py_ssize_t __pyx_bstride_0_o_s = 0; - Py_ssize_t __pyx_bshape_0_o_s = 0; - Py_buffer __pyx_bstruct_dx; - Py_ssize_t __pyx_bstride_0_dx = 0; - Py_ssize_t __pyx_bshape_0_dx = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i_s,&__pyx_n_s__o_s,&__pyx_n_s__e,&__pyx_n_s__a,&__pyx_n_s__dx,&__pyx_n_s__imin,&__pyx_n_s__imax,0}; - __Pyx_RefNannySetupContext("Transfer1D"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[7] = {0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i_s); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__o_s); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, 2); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, 3); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, 4); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__imin); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, 5); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__imax); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, 6); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "Transfer1D") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_i_s = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_i_s == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_o_s = ((PyArrayObject *)values[1]); - __pyx_v_e = ((PyArrayObject *)values[2]); - __pyx_v_a = ((PyArrayObject *)values[3]); - __pyx_v_dx = ((PyArrayObject *)values[4]); - __pyx_v_imin = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_imin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_imax = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_imax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_i_s = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_i_s == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_o_s = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_e = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_a = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_dx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_imin = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_imin == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_imax = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 6)); if (unlikely((__pyx_v_imax == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("Transfer1D", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.Transfer1D"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_o_s.buf = NULL; - __pyx_bstruct_e.buf = NULL; - __pyx_bstruct_a.buf = NULL; - __pyx_bstruct_dx.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_o_s), __pyx_ptype_5numpy_ndarray, 1, "o_s", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_5numpy_ndarray, 1, "e", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_5numpy_ndarray, 1, "a", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dx), __pyx_ptype_5numpy_ndarray, 1, "dx", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_o_s, (PyObject*)__pyx_v_o_s, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_o_s = __pyx_bstruct_o_s.strides[0]; - __pyx_bshape_0_o_s = __pyx_bstruct_o_s.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_e, (PyObject*)__pyx_v_e, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_e = __pyx_bstruct_e.strides[0]; - __pyx_bshape_0_e = __pyx_bstruct_e.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_a, (PyObject*)__pyx_v_a, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_a = __pyx_bstruct_a.strides[0]; - __pyx_bshape_0_a = __pyx_bstruct_a.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dx, (PyObject*)__pyx_v_dx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dx = __pyx_bstruct_dx.strides[0]; - __pyx_bshape_0_dx = __pyx_bstruct_dx.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":121 - * int imin, int imax): - * cdef int i - * for i in range(imin, imax): # <<<<<<<<<<<<<< - * o_s[i] = i_s + dx[i]*(e[i] - i_s*a[i]) - * i_s = o_s[i] - */ - __pyx_t_1 = __pyx_v_imax; - for (__pyx_t_2 = __pyx_v_imin; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":122 - * cdef int i - * for i in range(imin, imax): - * o_s[i] = i_s + dx[i]*(e[i] - i_s*a[i]) # <<<<<<<<<<<<<< - * i_s = o_s[i] - * return i_s - */ - __pyx_t_3 = __pyx_v_i; - if (__pyx_t_3 < 0) __pyx_t_3 += __pyx_bshape_0_dx; - __pyx_t_4 = __pyx_v_i; - if (__pyx_t_4 < 0) __pyx_t_4 += __pyx_bshape_0_e; - __pyx_t_5 = __pyx_v_i; - if (__pyx_t_5 < 0) __pyx_t_5 += __pyx_bshape_0_a; - __pyx_t_6 = __pyx_v_i; - if (__pyx_t_6 < 0) __pyx_t_6 += __pyx_bshape_0_o_s; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_bstruct_o_s.buf, __pyx_t_6, __pyx_bstride_0_o_s) = (__pyx_v_i_s + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_bstruct_dx.buf, __pyx_t_3, __pyx_bstride_0_dx)) * ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_bstruct_e.buf, __pyx_t_4, __pyx_bstride_0_e)) - (__pyx_v_i_s * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_bstruct_a.buf, __pyx_t_5, __pyx_bstride_0_a)))))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":123 - * for i in range(imin, imax): - * o_s[i] = i_s + dx[i]*(e[i] - i_s*a[i]) - * i_s = o_s[i] # <<<<<<<<<<<<<< - * return i_s - * - */ - __pyx_t_7 = __pyx_v_i; - if (__pyx_t_7 < 0) __pyx_t_7 += __pyx_bshape_0_o_s; - __pyx_v_i_s = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_bstruct_o_s.buf, __pyx_t_7, __pyx_bstride_0_o_s)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":124 - * o_s[i] = i_s + dx[i]*(e[i] - i_s*a[i]) - * i_s = o_s[i] - * return i_s # <<<<<<<<<<<<<< - * - * @cython.wraparound(False) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = PyFloat_FromDouble(__pyx_v_i_s); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_8); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_a); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_e); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_o_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.Transfer1D"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_a); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_e); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_o_s); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":128 - * @cython.wraparound(False) - * @cython.boundscheck(False) - * def VoxelTraversal(np.ndarray[np.int_t, ndim=3] grid_mask, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=3] grid_t, - * np.ndarray[np.float64_t, ndim=3] grid_dt, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_VoxelTraversal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_VoxelTraversal(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_grid_mask = 0; - PyArrayObject *__pyx_v_grid_t = 0; - PyArrayObject *__pyx_v_grid_dt = 0; - PyArrayObject *__pyx_v_left_edge = 0; - PyArrayObject *__pyx_v_right_edge = 0; - PyArrayObject *__pyx_v_dx = 0; - PyArrayObject *__pyx_v_u = 0; - PyArrayObject *__pyx_v_v = 0; - int __pyx_v_i; - int __pyx_v_x; - int __pyx_v_y; - __pyx_t_5numpy_float64_t __pyx_v_tl; - __pyx_t_5numpy_float64_t __pyx_v_tr; - __pyx_t_5numpy_float64_t __pyx_v_intersect_t; - __pyx_t_5numpy_float64_t __pyx_v_enter_t; - __pyx_t_5numpy_float64_t __pyx_v_dt_tolerance; - PyArrayObject *__pyx_v_step = 0; - PyArrayObject *__pyx_v_cur_ind = 0; - PyArrayObject *__pyx_v_tdelta = 0; - PyArrayObject *__pyx_v_tmax = 0; - PyArrayObject *__pyx_v_intersect = 0; - Py_buffer __pyx_bstruct_right_edge; - Py_ssize_t __pyx_bstride_0_right_edge = 0; - Py_ssize_t __pyx_bshape_0_right_edge = 0; - Py_buffer __pyx_bstruct_intersect; - Py_ssize_t __pyx_bstride_0_intersect = 0; - Py_ssize_t __pyx_bshape_0_intersect = 0; - Py_buffer __pyx_bstruct_grid_t; - Py_ssize_t __pyx_bstride_0_grid_t = 0; - Py_ssize_t __pyx_bstride_1_grid_t = 0; - Py_ssize_t __pyx_bstride_2_grid_t = 0; - Py_ssize_t __pyx_bshape_0_grid_t = 0; - Py_ssize_t __pyx_bshape_1_grid_t = 0; - Py_ssize_t __pyx_bshape_2_grid_t = 0; - Py_buffer __pyx_bstruct_grid_dt; - Py_ssize_t __pyx_bstride_0_grid_dt = 0; - Py_ssize_t __pyx_bstride_1_grid_dt = 0; - Py_ssize_t __pyx_bstride_2_grid_dt = 0; - Py_ssize_t __pyx_bshape_0_grid_dt = 0; - Py_ssize_t __pyx_bshape_1_grid_dt = 0; - Py_ssize_t __pyx_bshape_2_grid_dt = 0; - Py_buffer __pyx_bstruct_cur_ind; - Py_ssize_t __pyx_bstride_0_cur_ind = 0; - Py_ssize_t __pyx_bshape_0_cur_ind = 0; - Py_buffer __pyx_bstruct_left_edge; - Py_ssize_t __pyx_bstride_0_left_edge = 0; - Py_ssize_t __pyx_bshape_0_left_edge = 0; - Py_buffer __pyx_bstruct_step; - Py_ssize_t __pyx_bstride_0_step = 0; - Py_ssize_t __pyx_bshape_0_step = 0; - Py_buffer __pyx_bstruct_dx; - Py_ssize_t __pyx_bstride_0_dx = 0; - Py_ssize_t __pyx_bshape_0_dx = 0; - Py_buffer __pyx_bstruct_tdelta; - Py_ssize_t __pyx_bstride_0_tdelta = 0; - Py_ssize_t __pyx_bshape_0_tdelta = 0; - Py_buffer __pyx_bstruct_tmax; - Py_ssize_t __pyx_bstride_0_tmax = 0; - Py_ssize_t __pyx_bshape_0_tmax = 0; - Py_buffer __pyx_bstruct_grid_mask; - Py_ssize_t __pyx_bstride_0_grid_mask = 0; - Py_ssize_t __pyx_bstride_1_grid_mask = 0; - Py_ssize_t __pyx_bstride_2_grid_mask = 0; - Py_ssize_t __pyx_bshape_0_grid_mask = 0; - Py_ssize_t __pyx_bshape_1_grid_mask = 0; - Py_ssize_t __pyx_bshape_2_grid_mask = 0; - Py_buffer __pyx_bstruct_u; - Py_ssize_t __pyx_bstride_0_u = 0; - Py_ssize_t __pyx_bshape_0_u = 0; - Py_buffer __pyx_bstruct_v; - Py_ssize_t __pyx_bstride_0_v = 0; - Py_ssize_t __pyx_bshape_0_v = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyArrayObject *__pyx_t_6 = NULL; - PyArrayObject *__pyx_t_7 = NULL; - PyArrayObject *__pyx_t_8 = NULL; - PyArrayObject *__pyx_t_9 = NULL; - PyArrayObject *__pyx_t_10 = NULL; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - __pyx_t_5numpy_float64_t __pyx_t_18; - int __pyx_t_19; - __pyx_t_5numpy_float64_t __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - int __pyx_t_29; - int __pyx_t_30; - int __pyx_t_31; - int __pyx_t_32; - int __pyx_t_33; - int __pyx_t_34; - int __pyx_t_35; - int __pyx_t_36; - int __pyx_t_37; - int __pyx_t_38; - int __pyx_t_39; - int __pyx_t_40; - int __pyx_t_41; - int __pyx_t_42; - long __pyx_t_43; - long __pyx_t_44; - long __pyx_t_45; - long __pyx_t_46; - long __pyx_t_47; - long __pyx_t_48; - long __pyx_t_49; - long __pyx_t_50; - long __pyx_t_51; - PyObject *__pyx_t_52 = NULL; - PyObject *__pyx_t_53 = NULL; - PyObject *__pyx_t_54 = NULL; - int __pyx_t_55; - int __pyx_t_56; - int __pyx_t_57; - int __pyx_t_58; - __pyx_t_5numpy_int64_t __pyx_t_59; - int __pyx_t_60; - int __pyx_t_61; - int __pyx_t_62; - int __pyx_t_63; - int __pyx_t_64; - int __pyx_t_65; - int __pyx_t_66; - int __pyx_t_67; - int __pyx_t_68; - int __pyx_t_69; - int __pyx_t_70; - int __pyx_t_71; - int __pyx_t_72; - int __pyx_t_73; - int __pyx_t_74; - int __pyx_t_75; - int __pyx_t_76; - int __pyx_t_77; - int __pyx_t_78; - int __pyx_t_79; - int __pyx_t_80; - int __pyx_t_81; - int __pyx_t_82; - int __pyx_t_83; - int __pyx_t_84; - int __pyx_t_85; - int __pyx_t_86; - int __pyx_t_87; - int __pyx_t_88; - int __pyx_t_89; - long __pyx_t_90; - long __pyx_t_91; - long __pyx_t_92; - long __pyx_t_93; - long __pyx_t_94; - long __pyx_t_95; - __pyx_t_5numpy_int64_t __pyx_t_96; - __pyx_t_5numpy_int64_t __pyx_t_97; - long __pyx_t_98; - long __pyx_t_99; - long __pyx_t_100; - long __pyx_t_101; - long __pyx_t_102; - long __pyx_t_103; - __pyx_t_5numpy_int64_t __pyx_t_104; - __pyx_t_5numpy_int64_t __pyx_t_105; - __pyx_t_5numpy_int64_t __pyx_t_106; - long __pyx_t_107; - long __pyx_t_108; - long __pyx_t_109; - long __pyx_t_110; - long __pyx_t_111; - long __pyx_t_112; - long __pyx_t_113; - __pyx_t_5numpy_int64_t __pyx_t_114; - __pyx_t_5numpy_int64_t __pyx_t_115; - __pyx_t_5numpy_int64_t __pyx_t_116; - long __pyx_t_117; - long __pyx_t_118; - long __pyx_t_119; - long __pyx_t_120; - __pyx_t_5numpy_int64_t __pyx_t_121; - __pyx_t_5numpy_int64_t __pyx_t_122; - __pyx_t_5numpy_int64_t __pyx_t_123; - long __pyx_t_124; - long __pyx_t_125; - long __pyx_t_126; - long __pyx_t_127; - long __pyx_t_128; - long __pyx_t_129; - long __pyx_t_130; - long __pyx_t_131; - __pyx_t_5numpy_int64_t __pyx_t_132; - __pyx_t_5numpy_int64_t __pyx_t_133; - __pyx_t_5numpy_int64_t __pyx_t_134; - long __pyx_t_135; - long __pyx_t_136; - long __pyx_t_137; - long __pyx_t_138; - __pyx_t_5numpy_int64_t __pyx_t_139; - __pyx_t_5numpy_int64_t __pyx_t_140; - __pyx_t_5numpy_int64_t __pyx_t_141; - long __pyx_t_142; - long __pyx_t_143; - long __pyx_t_144; - long __pyx_t_145; - long __pyx_t_146; - long __pyx_t_147; - long __pyx_t_148; - long __pyx_t_149; - long __pyx_t_150; - long __pyx_t_151; - __pyx_t_5numpy_int64_t __pyx_t_152; - __pyx_t_5numpy_int64_t __pyx_t_153; - __pyx_t_5numpy_int64_t __pyx_t_154; - long __pyx_t_155; - long __pyx_t_156; - long __pyx_t_157; - long __pyx_t_158; - __pyx_t_5numpy_int64_t __pyx_t_159; - __pyx_t_5numpy_int64_t __pyx_t_160; - __pyx_t_5numpy_int64_t __pyx_t_161; - long __pyx_t_162; - long __pyx_t_163; - long __pyx_t_164; - long __pyx_t_165; - long __pyx_t_166; - long __pyx_t_167; - long __pyx_t_168; - long __pyx_t_169; - __pyx_t_5numpy_int64_t __pyx_t_170; - __pyx_t_5numpy_int64_t __pyx_t_171; - __pyx_t_5numpy_int64_t __pyx_t_172; - long __pyx_t_173; - long __pyx_t_174; - long __pyx_t_175; - long __pyx_t_176; - __pyx_t_5numpy_int64_t __pyx_t_177; - __pyx_t_5numpy_int64_t __pyx_t_178; - __pyx_t_5numpy_int64_t __pyx_t_179; - long __pyx_t_180; - long __pyx_t_181; - long __pyx_t_182; - long __pyx_t_183; - long __pyx_t_184; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__grid_mask,&__pyx_n_s__grid_t,&__pyx_n_s__grid_dt,&__pyx_n_s__left_edge,&__pyx_n_s__right_edge,&__pyx_n_s__dx,&__pyx_n_s__u,&__pyx_n_s__v,0}; - __Pyx_RefNannySetupContext("VoxelTraversal"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[8] = {0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_mask); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_t); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_dt); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 2); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edge); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 3); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edge); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 4); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 5); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__u); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 6); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__v); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, 7); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "VoxelTraversal") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_grid_mask = ((PyArrayObject *)values[0]); - __pyx_v_grid_t = ((PyArrayObject *)values[1]); - __pyx_v_grid_dt = ((PyArrayObject *)values[2]); - __pyx_v_left_edge = ((PyArrayObject *)values[3]); - __pyx_v_right_edge = ((PyArrayObject *)values[4]); - __pyx_v_dx = ((PyArrayObject *)values[5]); - __pyx_v_u = ((PyArrayObject *)values[6]); - __pyx_v_v = ((PyArrayObject *)values[7]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 8) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_grid_mask = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_grid_t = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_grid_dt = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_dx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_u = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_v = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 7)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("VoxelTraversal", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.VoxelTraversal"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_step.buf = NULL; - __pyx_bstruct_cur_ind.buf = NULL; - __pyx_bstruct_tdelta.buf = NULL; - __pyx_bstruct_tmax.buf = NULL; - __pyx_bstruct_intersect.buf = NULL; - __pyx_bstruct_grid_mask.buf = NULL; - __pyx_bstruct_grid_t.buf = NULL; - __pyx_bstruct_grid_dt.buf = NULL; - __pyx_bstruct_left_edge.buf = NULL; - __pyx_bstruct_right_edge.buf = NULL; - __pyx_bstruct_dx.buf = NULL; - __pyx_bstruct_u.buf = NULL; - __pyx_bstruct_v.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_mask), __pyx_ptype_5numpy_ndarray, 1, "grid_mask", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_t), __pyx_ptype_5numpy_ndarray, 1, "grid_t", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_dt), __pyx_ptype_5numpy_ndarray, 1, "grid_dt", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edge), __pyx_ptype_5numpy_ndarray, 1, "left_edge", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edge), __pyx_ptype_5numpy_ndarray, 1, "right_edge", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dx), __pyx_ptype_5numpy_ndarray, 1, "dx", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_u), __pyx_ptype_5numpy_ndarray, 1, "u", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_v), __pyx_ptype_5numpy_ndarray, 1, "v", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_mask, (PyObject*)__pyx_v_grid_mask, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_mask = __pyx_bstruct_grid_mask.strides[0]; __pyx_bstride_1_grid_mask = __pyx_bstruct_grid_mask.strides[1]; __pyx_bstride_2_grid_mask = __pyx_bstruct_grid_mask.strides[2]; - __pyx_bshape_0_grid_mask = __pyx_bstruct_grid_mask.shape[0]; __pyx_bshape_1_grid_mask = __pyx_bstruct_grid_mask.shape[1]; __pyx_bshape_2_grid_mask = __pyx_bstruct_grid_mask.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_t, (PyObject*)__pyx_v_grid_t, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_t = __pyx_bstruct_grid_t.strides[0]; __pyx_bstride_1_grid_t = __pyx_bstruct_grid_t.strides[1]; __pyx_bstride_2_grid_t = __pyx_bstruct_grid_t.strides[2]; - __pyx_bshape_0_grid_t = __pyx_bstruct_grid_t.shape[0]; __pyx_bshape_1_grid_t = __pyx_bstruct_grid_t.shape[1]; __pyx_bshape_2_grid_t = __pyx_bstruct_grid_t.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_dt, (PyObject*)__pyx_v_grid_dt, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_dt = __pyx_bstruct_grid_dt.strides[0]; __pyx_bstride_1_grid_dt = __pyx_bstruct_grid_dt.strides[1]; __pyx_bstride_2_grid_dt = __pyx_bstruct_grid_dt.strides[2]; - __pyx_bshape_0_grid_dt = __pyx_bstruct_grid_dt.shape[0]; __pyx_bshape_1_grid_dt = __pyx_bstruct_grid_dt.shape[1]; __pyx_bshape_2_grid_dt = __pyx_bstruct_grid_dt.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edge, (PyObject*)__pyx_v_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edge = __pyx_bstruct_left_edge.strides[0]; - __pyx_bshape_0_left_edge = __pyx_bstruct_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edge, (PyObject*)__pyx_v_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edge = __pyx_bstruct_right_edge.strides[0]; - __pyx_bshape_0_right_edge = __pyx_bstruct_right_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dx, (PyObject*)__pyx_v_dx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dx = __pyx_bstruct_dx.strides[0]; - __pyx_bshape_0_dx = __pyx_bstruct_dx.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_u, (PyObject*)__pyx_v_u, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_u = __pyx_bstruct_u.strides[0]; - __pyx_bshape_0_u = __pyx_bstruct_u.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_v, (PyObject*)__pyx_v_v, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_v = __pyx_bstruct_v.strides[0]; - __pyx_bshape_0_v = __pyx_bstruct_v.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":141 - * cdef int i, x, y - * cdef np.float64_t tl, tr, intersect_t, enter_t, exit_t, dt_tolerance - * cdef np.ndarray[np.int64_t, ndim=1] step = np.empty((3,), dtype=np.int64) # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int64_t, ndim=1] cur_ind = np.empty((3,), dtype=np.int64) - * cdef np.ndarray[np.float64_t, ndim=1] tdelta = np.empty((3,), dtype=np.float64) - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__int64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_step, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_step = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_step.buf = NULL; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_step = __pyx_bstruct_step.strides[0]; - __pyx_bshape_0_step = __pyx_bstruct_step.shape[0]; - } - } - __pyx_t_6 = 0; - __pyx_v_step = ((PyArrayObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":142 - * cdef np.float64_t tl, tr, intersect_t, enter_t, exit_t, dt_tolerance - * cdef np.ndarray[np.int64_t, ndim=1] step = np.empty((3,), dtype=np.int64) - * cdef np.ndarray[np.int64_t, ndim=1] cur_ind = np.empty((3,), dtype=np.int64) # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=1] tdelta = np.empty((3,), dtype=np.float64) - * cdef np.ndarray[np.float64_t, ndim=1] tmax = np.empty((3,), dtype=np.float64) - */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__int64); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_3, ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_7 = ((PyArrayObject *)__pyx_t_4); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_cur_ind, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_cur_ind = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_cur_ind.buf = NULL; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_cur_ind = __pyx_bstruct_cur_ind.strides[0]; - __pyx_bshape_0_cur_ind = __pyx_bstruct_cur_ind.shape[0]; - } - } - __pyx_t_7 = 0; - __pyx_v_cur_ind = ((PyArrayObject *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":143 - * cdef np.ndarray[np.int64_t, ndim=1] step = np.empty((3,), dtype=np.int64) - * cdef np.ndarray[np.int64_t, ndim=1] cur_ind = np.empty((3,), dtype=np.int64) - * cdef np.ndarray[np.float64_t, ndim=1] tdelta = np.empty((3,), dtype=np.float64) # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=1] tmax = np.empty((3,), dtype=np.float64) - * cdef np.ndarray[np.float64_t, ndim=1] intersect = np.empty((3,), dtype=np.float64) - */ - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__float64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_tdelta, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_tdelta = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_tdelta.buf = NULL; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_tdelta = __pyx_bstruct_tdelta.strides[0]; - __pyx_bshape_0_tdelta = __pyx_bstruct_tdelta.shape[0]; - } - } - __pyx_t_8 = 0; - __pyx_v_tdelta = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":144 - * cdef np.ndarray[np.int64_t, ndim=1] cur_ind = np.empty((3,), dtype=np.int64) - * cdef np.ndarray[np.float64_t, ndim=1] tdelta = np.empty((3,), dtype=np.float64) - * cdef np.ndarray[np.float64_t, ndim=1] tmax = np.empty((3,), dtype=np.float64) # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=1] intersect = np.empty((3,), dtype=np.float64) - * intersect_t = 1 - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__empty); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__float64); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_3, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_tmax, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_tmax = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_tmax.buf = NULL; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_tmax = __pyx_bstruct_tmax.strides[0]; - __pyx_bshape_0_tmax = __pyx_bstruct_tmax.shape[0]; - } - } - __pyx_t_9 = 0; - __pyx_v_tmax = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":145 - * cdef np.ndarray[np.float64_t, ndim=1] tdelta = np.empty((3,), dtype=np.float64) - * cdef np.ndarray[np.float64_t, ndim=1] tmax = np.empty((3,), dtype=np.float64) - * cdef np.ndarray[np.float64_t, ndim=1] intersect = np.empty((3,), dtype=np.float64) # <<<<<<<<<<<<<< - * intersect_t = 1 - * dt_tolerance = 1e-6 - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = ((PyArrayObject *)__pyx_t_5); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_intersect, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - __pyx_v_intersect = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_intersect.buf = NULL; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_intersect = __pyx_bstruct_intersect.strides[0]; - __pyx_bshape_0_intersect = __pyx_bstruct_intersect.shape[0]; - } - } - __pyx_t_10 = 0; - __pyx_v_intersect = ((PyArrayObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":146 - * cdef np.ndarray[np.float64_t, ndim=1] tmax = np.empty((3,), dtype=np.float64) - * cdef np.ndarray[np.float64_t, ndim=1] intersect = np.empty((3,), dtype=np.float64) - * intersect_t = 1 # <<<<<<<<<<<<<< - * dt_tolerance = 1e-6 - * # recall p = v * t + u - */ - __pyx_v_intersect_t = 1.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":147 - * cdef np.ndarray[np.float64_t, ndim=1] intersect = np.empty((3,), dtype=np.float64) - * intersect_t = 1 - * dt_tolerance = 1e-6 # <<<<<<<<<<<<<< - * # recall p = v * t + u - * # where p is position, v is our vector, u is the start point - */ - __pyx_v_dt_tolerance = 1e-6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":150 - * # recall p = v * t + u - * # where p is position, v is our vector, u is the start point - * for i in range(3): # <<<<<<<<<<<<<< - * # As long as we're iterating, set some other stuff, too - * if(v[i] < 0): step[i] = -1 - */ - for (__pyx_t_11 = 0; __pyx_t_11 < 3; __pyx_t_11+=1) { - __pyx_v_i = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":152 - * for i in range(3): - * # As long as we're iterating, set some other stuff, too - * if(v[i] < 0): step[i] = -1 # <<<<<<<<<<<<<< - * else: step[i] = 1 - * x = (i+1)%3 - */ - __pyx_t_12 = __pyx_v_i; - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_12, __pyx_bstride_0_v)) < 0.0); - if (__pyx_t_13) { - __pyx_t_14 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_14, __pyx_bstride_0_step) = -1; - goto __pyx_L8; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":153 - * # As long as we're iterating, set some other stuff, too - * if(v[i] < 0): step[i] = -1 - * else: step[i] = 1 # <<<<<<<<<<<<<< - * x = (i+1)%3 - * y = (i+2)%3 - */ - __pyx_t_15 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_15, __pyx_bstride_0_step) = 1; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":154 - * if(v[i] < 0): step[i] = -1 - * else: step[i] = 1 - * x = (i+1)%3 # <<<<<<<<<<<<<< - * y = (i+2)%3 - * tl = (left_edge[i] - u[i])/v[i] - */ - __pyx_v_x = __Pyx_mod_long((__pyx_v_i + 1), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":155 - * else: step[i] = 1 - * x = (i+1)%3 - * y = (i+2)%3 # <<<<<<<<<<<<<< - * tl = (left_edge[i] - u[i])/v[i] - * tr = (right_edge[i] - u[i])/v[i] - */ - __pyx_v_y = __Pyx_mod_long((__pyx_v_i + 2), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":156 - * x = (i+1)%3 - * y = (i+2)%3 - * tl = (left_edge[i] - u[i])/v[i] # <<<<<<<<<<<<<< - * tr = (right_edge[i] - u[i])/v[i] - * if (left_edge[x] <= (u[x] + tl*v[x]) <= right_edge[x]) and \ - */ - __pyx_t_16 = __pyx_v_i; - __pyx_t_17 = __pyx_v_i; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_16, __pyx_bstride_0_left_edge)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_17, __pyx_bstride_0_u))); - __pyx_t_19 = __pyx_v_i; - __pyx_t_20 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_19, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_20 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_tl = (__pyx_t_18 / __pyx_t_20); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":157 - * y = (i+2)%3 - * tl = (left_edge[i] - u[i])/v[i] - * tr = (right_edge[i] - u[i])/v[i] # <<<<<<<<<<<<<< - * if (left_edge[x] <= (u[x] + tl*v[x]) <= right_edge[x]) and \ - * (left_edge[y] <= (u[y] + tl*v[y]) <= right_edge[y]) and \ - */ - __pyx_t_21 = __pyx_v_i; - __pyx_t_22 = __pyx_v_i; - __pyx_t_20 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_21, __pyx_bstride_0_right_edge)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_22, __pyx_bstride_0_u))); - __pyx_t_23 = __pyx_v_i; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_23, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_18 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_tr = (__pyx_t_20 / __pyx_t_18); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":158 - * tl = (left_edge[i] - u[i])/v[i] - * tr = (right_edge[i] - u[i])/v[i] - * if (left_edge[x] <= (u[x] + tl*v[x]) <= right_edge[x]) and \ # <<<<<<<<<<<<<< - * (left_edge[y] <= (u[y] + tl*v[y]) <= right_edge[y]) and \ - * (0.0 <= tl < intersect_t): - */ - __pyx_t_24 = __pyx_v_x; - __pyx_t_25 = __pyx_v_x; - __pyx_t_26 = __pyx_v_x; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_25, __pyx_bstride_0_u)) + (__pyx_v_tl * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_26, __pyx_bstride_0_v)))); - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_24, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_13) { - __pyx_t_27 = __pyx_v_x; - __pyx_t_13 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_27, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":159 - * tr = (right_edge[i] - u[i])/v[i] - * if (left_edge[x] <= (u[x] + tl*v[x]) <= right_edge[x]) and \ - * (left_edge[y] <= (u[y] + tl*v[y]) <= right_edge[y]) and \ # <<<<<<<<<<<<<< - * (0.0 <= tl < intersect_t): - * intersect_t = tl - */ - __pyx_t_28 = __pyx_v_y; - __pyx_t_29 = __pyx_v_y; - __pyx_t_30 = __pyx_v_y; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_29, __pyx_bstride_0_u)) + (__pyx_v_tl * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_30, __pyx_bstride_0_v)))); - __pyx_t_31 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_28, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_31) { - __pyx_t_32 = __pyx_v_y; - __pyx_t_31 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_32, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":160 - * if (left_edge[x] <= (u[x] + tl*v[x]) <= right_edge[x]) and \ - * (left_edge[y] <= (u[y] + tl*v[y]) <= right_edge[y]) and \ - * (0.0 <= tl < intersect_t): # <<<<<<<<<<<<<< - * intersect_t = tl - * if (left_edge[x] <= (u[x] + tr*v[x]) <= right_edge[x]) and \ - */ - __pyx_t_33 = (0.0 <= __pyx_v_tl); - if (__pyx_t_33) { - __pyx_t_33 = (__pyx_v_tl < __pyx_v_intersect_t); - } - __pyx_t_34 = __pyx_t_33; - } else { - __pyx_t_34 = __pyx_t_31; - } - __pyx_t_31 = __pyx_t_34; - } else { - __pyx_t_31 = __pyx_t_13; - } - if (__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":161 - * (left_edge[y] <= (u[y] + tl*v[y]) <= right_edge[y]) and \ - * (0.0 <= tl < intersect_t): - * intersect_t = tl # <<<<<<<<<<<<<< - * if (left_edge[x] <= (u[x] + tr*v[x]) <= right_edge[x]) and \ - * (left_edge[y] <= (u[y] + tr*v[y]) <= right_edge[y]) and \ - */ - __pyx_v_intersect_t = __pyx_v_tl; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":162 - * (0.0 <= tl < intersect_t): - * intersect_t = tl - * if (left_edge[x] <= (u[x] + tr*v[x]) <= right_edge[x]) and \ # <<<<<<<<<<<<<< - * (left_edge[y] <= (u[y] + tr*v[y]) <= right_edge[y]) and \ - * (0.0 <= tr < intersect_t): - */ - __pyx_t_35 = __pyx_v_x; - __pyx_t_36 = __pyx_v_x; - __pyx_t_37 = __pyx_v_x; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_36, __pyx_bstride_0_u)) + (__pyx_v_tr * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_37, __pyx_bstride_0_v)))); - __pyx_t_31 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_35, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_31) { - __pyx_t_38 = __pyx_v_x; - __pyx_t_31 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_38, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":163 - * intersect_t = tl - * if (left_edge[x] <= (u[x] + tr*v[x]) <= right_edge[x]) and \ - * (left_edge[y] <= (u[y] + tr*v[y]) <= right_edge[y]) and \ # <<<<<<<<<<<<<< - * (0.0 <= tr < intersect_t): - * intersect_t = tr - */ - __pyx_t_39 = __pyx_v_y; - __pyx_t_40 = __pyx_v_y; - __pyx_t_41 = __pyx_v_y; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_40, __pyx_bstride_0_u)) + (__pyx_v_tr * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_41, __pyx_bstride_0_v)))); - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_39, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_13) { - __pyx_t_42 = __pyx_v_y; - __pyx_t_13 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_42, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":164 - * if (left_edge[x] <= (u[x] + tr*v[x]) <= right_edge[x]) and \ - * (left_edge[y] <= (u[y] + tr*v[y]) <= right_edge[y]) and \ - * (0.0 <= tr < intersect_t): # <<<<<<<<<<<<<< - * intersect_t = tr - * # if fully enclosed - */ - __pyx_t_34 = (0.0 <= __pyx_v_tr); - if (__pyx_t_34) { - __pyx_t_34 = (__pyx_v_tr < __pyx_v_intersect_t); - } - __pyx_t_33 = __pyx_t_34; - } else { - __pyx_t_33 = __pyx_t_13; - } - __pyx_t_13 = __pyx_t_33; - } else { - __pyx_t_13 = __pyx_t_31; - } - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":165 - * (left_edge[y] <= (u[y] + tr*v[y]) <= right_edge[y]) and \ - * (0.0 <= tr < intersect_t): - * intersect_t = tr # <<<<<<<<<<<<<< - * # if fully enclosed - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ - */ - __pyx_v_intersect_t = __pyx_v_tr; - goto __pyx_L10; - } - __pyx_L10:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":167 - * intersect_t = tr - * # if fully enclosed - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ # <<<<<<<<<<<<<< - * (left_edge[1] <= u[1] <= right_edge[1]) and \ - * (left_edge[2] <= u[2] <= right_edge[2]): - */ - __pyx_t_43 = 0; - __pyx_t_44 = 0; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_44, __pyx_bstride_0_u)); - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_43, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_13) { - __pyx_t_45 = 0; - __pyx_t_13 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_45, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":168 - * # if fully enclosed - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ - * (left_edge[1] <= u[1] <= right_edge[1]) and \ # <<<<<<<<<<<<<< - * (left_edge[2] <= u[2] <= right_edge[2]): - * intersect_t = 0.0 - */ - __pyx_t_46 = 1; - __pyx_t_47 = 1; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_47, __pyx_bstride_0_u)); - __pyx_t_31 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_46, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_31) { - __pyx_t_48 = 1; - __pyx_t_31 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_48, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":169 - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ - * (left_edge[1] <= u[1] <= right_edge[1]) and \ - * (left_edge[2] <= u[2] <= right_edge[2]): # <<<<<<<<<<<<<< - * intersect_t = 0.0 - * if not (0 <= intersect_t <= 1): return - */ - __pyx_t_49 = 2; - __pyx_t_50 = 2; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_50, __pyx_bstride_0_u)); - __pyx_t_33 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_49, __pyx_bstride_0_left_edge)) <= __pyx_t_18); - if (__pyx_t_33) { - __pyx_t_51 = 2; - __pyx_t_33 = (__pyx_t_18 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_51, __pyx_bstride_0_right_edge))); - } - __pyx_t_34 = __pyx_t_33; - } else { - __pyx_t_34 = __pyx_t_31; - } - __pyx_t_31 = __pyx_t_34; - } else { - __pyx_t_31 = __pyx_t_13; - } - if (__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":170 - * (left_edge[1] <= u[1] <= right_edge[1]) and \ - * (left_edge[2] <= u[2] <= right_edge[2]): - * intersect_t = 0.0 # <<<<<<<<<<<<<< - * if not (0 <= intersect_t <= 1): return - * # Now get the indices of the intersection - */ - __pyx_v_intersect_t = 0.0; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":171 - * (left_edge[2] <= u[2] <= right_edge[2]): - * intersect_t = 0.0 - * if not (0 <= intersect_t <= 1): return # <<<<<<<<<<<<<< - * # Now get the indices of the intersection - * intersect = u + intersect_t * v - */ - __pyx_t_31 = (0.0 <= __pyx_v_intersect_t); - if (__pyx_t_31) { - __pyx_t_31 = (__pyx_v_intersect_t <= 1.0); - } - __pyx_t_13 = (!__pyx_t_31); - if (__pyx_t_13) { - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":173 - * if not (0 <= intersect_t <= 1): return - * # Now get the indices of the intersection - * intersect = u + intersect_t * v # <<<<<<<<<<<<<< - * for i in range(3): - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - */ - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_intersect_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, ((PyObject *)__pyx_v_v)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(((PyObject *)__pyx_v_u), __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = ((PyArrayObject *)__pyx_t_5); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_intersect); - __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_intersect, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_11 < 0)) { - PyErr_Fetch(&__pyx_t_52, &__pyx_t_53, &__pyx_t_54); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_intersect, (PyObject*)__pyx_v_intersect, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_52); Py_XDECREF(__pyx_t_53); Py_XDECREF(__pyx_t_54); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_52, __pyx_t_53, __pyx_t_54); - } - } - __pyx_bstride_0_intersect = __pyx_bstruct_intersect.strides[0]; - __pyx_bshape_0_intersect = __pyx_bstruct_intersect.shape[0]; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_intersect)); - __pyx_v_intersect = ((PyArrayObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":174 - * # Now get the indices of the intersection - * intersect = u + intersect_t * v - * for i in range(3): # <<<<<<<<<<<<<< - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - */ - for (__pyx_t_11 = 0; __pyx_t_11 < 3; __pyx_t_11+=1) { - __pyx_v_i = __pyx_t_11; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":175 - * intersect = u + intersect_t * v - * for i in range(3): - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) # <<<<<<<<<<<<<< - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - * if cur_ind[i] == grid_mask.shape[i] and step[i] < 0: - */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__floor); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_55 = __pyx_v_i; - __pyx_t_56 = __pyx_v_i; - __pyx_t_57 = __pyx_v_i; - __pyx_t_18 = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_intersect.buf, __pyx_t_55, __pyx_bstride_0_intersect)) + (1e-8 * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_56, __pyx_bstride_0_dx)))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_57, __pyx_bstride_0_left_edge))); - __pyx_t_58 = __pyx_v_i; - __pyx_t_20 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_58, __pyx_bstride_0_dx)); - if (unlikely(__pyx_t_20 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyFloat_FromDouble((__pyx_t_18 / __pyx_t_20)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_59 = __Pyx_PyInt_from_py_npy_int64(__pyx_t_5); if (unlikely((__pyx_t_59 == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_60 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_60, __pyx_bstride_0_cur_ind) = __pyx_t_59; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":176 - * for i in range(3): - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] # <<<<<<<<<<<<<< - * if cur_ind[i] == grid_mask.shape[i] and step[i] < 0: - * cur_ind[i] = grid_mask.shape[i] - 1 - */ - __pyx_t_61 = __pyx_v_i; - __pyx_t_62 = __pyx_v_i; - __pyx_t_63 = __pyx_v_i; - __pyx_t_64 = __pyx_v_i; - __pyx_t_65 = __pyx_v_i; - __pyx_t_20 = (((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_61, __pyx_bstride_0_cur_ind)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_62, __pyx_bstride_0_step))) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_63, __pyx_bstride_0_dx))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_64, __pyx_bstride_0_left_edge))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_65, __pyx_bstride_0_u))); - __pyx_t_66 = __pyx_v_i; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_66, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_18 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_67 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_67, __pyx_bstride_0_tmax) = (__pyx_t_20 / __pyx_t_18); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":177 - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - * if cur_ind[i] == grid_mask.shape[i] and step[i] < 0: # <<<<<<<<<<<<<< - * cur_ind[i] = grid_mask.shape[i] - 1 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - */ - __pyx_t_68 = __pyx_v_i; - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_68, __pyx_bstride_0_cur_ind)) == (__pyx_v_grid_mask->dimensions[__pyx_v_i])); - if (__pyx_t_13) { - __pyx_t_69 = __pyx_v_i; - __pyx_t_31 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_69, __pyx_bstride_0_step)) < 0); - __pyx_t_34 = __pyx_t_31; - } else { - __pyx_t_34 = __pyx_t_13; - } - if (__pyx_t_34) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":178 - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - * if cur_ind[i] == grid_mask.shape[i] and step[i] < 0: - * cur_ind[i] = grid_mask.shape[i] - 1 # <<<<<<<<<<<<<< - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - */ - __pyx_t_70 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_70, __pyx_bstride_0_cur_ind) = ((__pyx_v_grid_mask->dimensions[__pyx_v_i]) - 1); - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":179 - * if cur_ind[i] == grid_mask.shape[i] and step[i] < 0: - * cur_ind[i] = grid_mask.shape[i] - 1 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] # <<<<<<<<<<<<<< - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - * tdelta[i] = (dx[i]/v[i]) - */ - __pyx_t_71 = __pyx_v_i; - __pyx_t_34 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_71, __pyx_bstride_0_step)) > 0); - if (__pyx_t_34) { - __pyx_t_72 = __pyx_v_i; - __pyx_t_73 = __pyx_v_i; - __pyx_t_74 = __pyx_v_i; - __pyx_t_75 = __pyx_v_i; - __pyx_t_18 = (((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_72, __pyx_bstride_0_cur_ind)) + 1) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_73, __pyx_bstride_0_dx))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_74, __pyx_bstride_0_left_edge))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_75, __pyx_bstride_0_u))); - __pyx_t_76 = __pyx_v_i; - __pyx_t_20 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_76, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_20 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_77 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_77, __pyx_bstride_0_tmax) = (__pyx_t_18 / __pyx_t_20); - goto __pyx_L16; - } - __pyx_L16:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":180 - * cur_ind[i] = grid_mask.shape[i] - 1 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] # <<<<<<<<<<<<<< - * tdelta[i] = (dx[i]/v[i]) - * if tdelta[i] < 0: tdelta[i] *= -1 - */ - __pyx_t_78 = __pyx_v_i; - __pyx_t_34 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_78, __pyx_bstride_0_step)) < 0); - if (__pyx_t_34) { - __pyx_t_79 = __pyx_v_i; - __pyx_t_80 = __pyx_v_i; - __pyx_t_81 = __pyx_v_i; - __pyx_t_82 = __pyx_v_i; - __pyx_t_20 = (((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_79, __pyx_bstride_0_cur_ind)) + 0) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_80, __pyx_bstride_0_dx))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_81, __pyx_bstride_0_left_edge))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_82, __pyx_bstride_0_u))); - __pyx_t_83 = __pyx_v_i; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_83, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_18 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_84 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_84, __pyx_bstride_0_tmax) = (__pyx_t_20 / __pyx_t_18); - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":181 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - * tdelta[i] = (dx[i]/v[i]) # <<<<<<<<<<<<<< - * if tdelta[i] < 0: tdelta[i] *= -1 - * # The variable intersect contains the point we first pierce the grid - */ - __pyx_t_85 = __pyx_v_i; - __pyx_t_18 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_85, __pyx_bstride_0_dx)); - __pyx_t_86 = __pyx_v_i; - __pyx_t_20 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_86, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_20 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_87 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_87, __pyx_bstride_0_tdelta) = (__pyx_t_18 / __pyx_t_20); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":182 - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - * tdelta[i] = (dx[i]/v[i]) - * if tdelta[i] < 0: tdelta[i] *= -1 # <<<<<<<<<<<<<< - * # The variable intersect contains the point we first pierce the grid - * enter_t = intersect_t - */ - __pyx_t_88 = __pyx_v_i; - __pyx_t_34 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_88, __pyx_bstride_0_tdelta)) < 0.0); - if (__pyx_t_34) { - __pyx_t_89 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_89, __pyx_bstride_0_tdelta) *= -1.0; - goto __pyx_L18; - } - __pyx_L18:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":184 - * if tdelta[i] < 0: tdelta[i] *= -1 - * # The variable intersect contains the point we first pierce the grid - * enter_t = intersect_t # <<<<<<<<<<<<<< - * while 1: - * if (not (0 <= cur_ind[0] < grid_mask.shape[0])) or \ - */ - __pyx_v_enter_t = __pyx_v_intersect_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":185 - * # The variable intersect contains the point we first pierce the grid - * enter_t = intersect_t - * while 1: # <<<<<<<<<<<<<< - * if (not (0 <= cur_ind[0] < grid_mask.shape[0])) or \ - * (not (0 <= cur_ind[1] < grid_mask.shape[1])) or \ - */ - while (1) { - if (!1) break; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":186 - * enter_t = intersect_t - * while 1: - * if (not (0 <= cur_ind[0] < grid_mask.shape[0])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[1] < grid_mask.shape[1])) or \ - * (not (0 <= cur_ind[2] < grid_mask.shape[2])): - */ - __pyx_t_90 = 0; - __pyx_t_59 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_90, __pyx_bstride_0_cur_ind)); - __pyx_t_34 = (0 <= __pyx_t_59); - if (__pyx_t_34) { - __pyx_t_34 = (__pyx_t_59 < (__pyx_v_grid_mask->dimensions[0])); - } - __pyx_t_13 = (!__pyx_t_34); - if (!__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":187 - * while 1: - * if (not (0 <= cur_ind[0] < grid_mask.shape[0])) or \ - * (not (0 <= cur_ind[1] < grid_mask.shape[1])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[2] < grid_mask.shape[2])): - * break - */ - __pyx_t_91 = 1; - __pyx_t_59 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_91, __pyx_bstride_0_cur_ind)); - __pyx_t_34 = (0 <= __pyx_t_59); - if (__pyx_t_34) { - __pyx_t_34 = (__pyx_t_59 < (__pyx_v_grid_mask->dimensions[1])); - } - __pyx_t_31 = (!__pyx_t_34); - if (!__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":188 - * if (not (0 <= cur_ind[0] < grid_mask.shape[0])) or \ - * (not (0 <= cur_ind[1] < grid_mask.shape[1])) or \ - * (not (0 <= cur_ind[2] < grid_mask.shape[2])): # <<<<<<<<<<<<<< - * break - * # Note that we are calculating t on the fly, but we get *negative* t - */ - __pyx_t_92 = 2; - __pyx_t_59 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_92, __pyx_bstride_0_cur_ind)); - __pyx_t_34 = (0 <= __pyx_t_59); - if (__pyx_t_34) { - __pyx_t_34 = (__pyx_t_59 < (__pyx_v_grid_mask->dimensions[2])); - } - __pyx_t_33 = (!__pyx_t_34); - __pyx_t_34 = __pyx_t_33; - } else { - __pyx_t_34 = __pyx_t_31; - } - __pyx_t_31 = __pyx_t_34; - } else { - __pyx_t_31 = __pyx_t_13; - } - if (__pyx_t_31) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":189 - * (not (0 <= cur_ind[1] < grid_mask.shape[1])) or \ - * (not (0 <= cur_ind[2] < grid_mask.shape[2])): - * break # <<<<<<<<<<<<<< - * # Note that we are calculating t on the fly, but we get *negative* t - * # values from what they should be. - */ - goto __pyx_L20_break; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":193 - * # values from what they should be. - * # If we've reached t = 1, we are done. - * grid_mask[cur_ind[0], cur_ind[1], cur_ind[2]] = 1 # <<<<<<<<<<<<<< - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = 1.0 - enter_t - */ - __pyx_t_93 = 0; - __pyx_t_94 = 1; - __pyx_t_95 = 2; - __pyx_t_59 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_93, __pyx_bstride_0_cur_ind)); - __pyx_t_96 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_94, __pyx_bstride_0_cur_ind)); - __pyx_t_97 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_95, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int_t *, __pyx_bstruct_grid_mask.buf, __pyx_t_59, __pyx_bstride_0_grid_mask, __pyx_t_96, __pyx_bstride_1_grid_mask, __pyx_t_97, __pyx_bstride_2_grid_mask) = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":194 - * # If we've reached t = 1, we are done. - * grid_mask[cur_ind[0], cur_ind[1], cur_ind[2]] = 1 - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): # <<<<<<<<<<<<<< - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = 1.0 - enter_t - * break - */ - __pyx_t_98 = 0; - __pyx_t_31 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_98, __pyx_bstride_0_tmax)) > 1.0); - if (__pyx_t_31) { - __pyx_t_99 = 1; - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_99, __pyx_bstride_0_tmax)) > 1.0); - if (__pyx_t_13) { - __pyx_t_100 = 2; - __pyx_t_34 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_100, __pyx_bstride_0_tmax)) > 1.0); - __pyx_t_33 = __pyx_t_34; - } else { - __pyx_t_33 = __pyx_t_13; - } - __pyx_t_13 = __pyx_t_33; - } else { - __pyx_t_13 = __pyx_t_31; - } - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":195 - * grid_mask[cur_ind[0], cur_ind[1], cur_ind[2]] = 1 - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = 1.0 - enter_t # <<<<<<<<<<<<<< - * break - * if tmax[0] < tmax[1]: - */ - __pyx_t_101 = 0; - __pyx_t_102 = 1; - __pyx_t_103 = 2; - __pyx_t_104 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_101, __pyx_bstride_0_cur_ind)); - __pyx_t_105 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_102, __pyx_bstride_0_cur_ind)); - __pyx_t_106 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_103, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dt.buf, __pyx_t_104, __pyx_bstride_0_grid_dt, __pyx_t_105, __pyx_bstride_1_grid_dt, __pyx_t_106, __pyx_bstride_2_grid_dt) = (1.0 - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":196 - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = 1.0 - enter_t - * break # <<<<<<<<<<<<<< - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: - */ - goto __pyx_L20_break; - goto __pyx_L22; - } - __pyx_L22:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":197 - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = 1.0 - enter_t - * break - * if tmax[0] < tmax[1]: # <<<<<<<<<<<<<< - * if tmax[0] < tmax[2]: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - */ - __pyx_t_107 = 0; - __pyx_t_108 = 1; - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_107, __pyx_bstride_0_tmax)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_108, __pyx_bstride_0_tmax))); - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":198 - * break - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: # <<<<<<<<<<<<<< - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[0] - enter_t - */ - __pyx_t_109 = 0; - __pyx_t_110 = 2; - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_109, __pyx_bstride_0_tmax)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_110, __pyx_bstride_0_tmax))); - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":199 - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t # <<<<<<<<<<<<<< - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[0] - enter_t - * enter_t = tmax[0] - */ - __pyx_t_111 = 0; - __pyx_t_112 = 1; - __pyx_t_113 = 2; - __pyx_t_114 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_111, __pyx_bstride_0_cur_ind)); - __pyx_t_115 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_112, __pyx_bstride_0_cur_ind)); - __pyx_t_116 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_113, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_t.buf, __pyx_t_114, __pyx_bstride_0_grid_t, __pyx_t_115, __pyx_bstride_1_grid_t, __pyx_t_116, __pyx_bstride_2_grid_t) = __pyx_v_enter_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":200 - * if tmax[0] < tmax[2]: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[0] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[0] - * tmax[0] += tdelta[0] - */ - __pyx_t_117 = 0; - __pyx_t_118 = 0; - __pyx_t_119 = 1; - __pyx_t_120 = 2; - __pyx_t_121 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_118, __pyx_bstride_0_cur_ind)); - __pyx_t_122 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_119, __pyx_bstride_0_cur_ind)); - __pyx_t_123 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_120, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dt.buf, __pyx_t_121, __pyx_bstride_0_grid_dt, __pyx_t_122, __pyx_bstride_1_grid_dt, __pyx_t_123, __pyx_bstride_2_grid_dt) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_117, __pyx_bstride_0_tmax)) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":201 - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[0] - enter_t - * enter_t = tmax[0] # <<<<<<<<<<<<<< - * tmax[0] += tdelta[0] - * cur_ind[0] += step[0] - */ - __pyx_t_124 = 0; - __pyx_v_enter_t = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_124, __pyx_bstride_0_tmax)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":202 - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[0] - enter_t - * enter_t = tmax[0] - * tmax[0] += tdelta[0] # <<<<<<<<<<<<<< - * cur_ind[0] += step[0] - * else: - */ - __pyx_t_125 = 0; - __pyx_t_126 = 0; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_126, __pyx_bstride_0_tmax) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_125, __pyx_bstride_0_tdelta)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":203 - * enter_t = tmax[0] - * tmax[0] += tdelta[0] - * cur_ind[0] += step[0] # <<<<<<<<<<<<<< - * else: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - */ - __pyx_t_127 = 0; - __pyx_t_128 = 0; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_128, __pyx_bstride_0_cur_ind) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_127, __pyx_bstride_0_step)); - goto __pyx_L24; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":205 - * cur_ind[0] += step[0] - * else: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t # <<<<<<<<<<<<<< - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - * enter_t = tmax[2] - */ - __pyx_t_129 = 0; - __pyx_t_130 = 1; - __pyx_t_131 = 2; - __pyx_t_132 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_129, __pyx_bstride_0_cur_ind)); - __pyx_t_133 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_130, __pyx_bstride_0_cur_ind)); - __pyx_t_134 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_131, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_t.buf, __pyx_t_132, __pyx_bstride_0_grid_t, __pyx_t_133, __pyx_bstride_1_grid_t, __pyx_t_134, __pyx_bstride_2_grid_t) = __pyx_v_enter_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":206 - * else: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - */ - __pyx_t_135 = 2; - __pyx_t_136 = 0; - __pyx_t_137 = 1; - __pyx_t_138 = 2; - __pyx_t_139 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_136, __pyx_bstride_0_cur_ind)); - __pyx_t_140 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_137, __pyx_bstride_0_cur_ind)); - __pyx_t_141 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_138, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dt.buf, __pyx_t_139, __pyx_bstride_0_grid_dt, __pyx_t_140, __pyx_bstride_1_grid_dt, __pyx_t_141, __pyx_bstride_2_grid_dt) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_135, __pyx_bstride_0_tmax)) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":207 - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - * enter_t = tmax[2] # <<<<<<<<<<<<<< - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] - */ - __pyx_t_142 = 2; - __pyx_v_enter_t = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_142, __pyx_bstride_0_tmax)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":208 - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - * enter_t = tmax[2] - * tmax[2] += tdelta[2] # <<<<<<<<<<<<<< - * cur_ind[2] += step[2] - * else: - */ - __pyx_t_143 = 2; - __pyx_t_144 = 2; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_144, __pyx_bstride_0_tmax) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_143, __pyx_bstride_0_tdelta)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":209 - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] # <<<<<<<<<<<<<< - * else: - * if tmax[1] < tmax[2]: - */ - __pyx_t_145 = 2; - __pyx_t_146 = 2; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_146, __pyx_bstride_0_cur_ind) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_145, __pyx_bstride_0_step)); - } - __pyx_L24:; - goto __pyx_L23; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":211 - * cur_ind[2] += step[2] - * else: - * if tmax[1] < tmax[2]: # <<<<<<<<<<<<<< - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[1] - enter_t - */ - __pyx_t_147 = 1; - __pyx_t_148 = 2; - __pyx_t_13 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_147, __pyx_bstride_0_tmax)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_148, __pyx_bstride_0_tmax))); - if (__pyx_t_13) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":212 - * else: - * if tmax[1] < tmax[2]: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t # <<<<<<<<<<<<<< - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[1] - enter_t - * enter_t = tmax[1] - */ - __pyx_t_149 = 0; - __pyx_t_150 = 1; - __pyx_t_151 = 2; - __pyx_t_152 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_149, __pyx_bstride_0_cur_ind)); - __pyx_t_153 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_150, __pyx_bstride_0_cur_ind)); - __pyx_t_154 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_151, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_t.buf, __pyx_t_152, __pyx_bstride_0_grid_t, __pyx_t_153, __pyx_bstride_1_grid_t, __pyx_t_154, __pyx_bstride_2_grid_t) = __pyx_v_enter_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":213 - * if tmax[1] < tmax[2]: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[1] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[1] - * tmax[1] += tdelta[1] - */ - __pyx_t_155 = 1; - __pyx_t_156 = 0; - __pyx_t_157 = 1; - __pyx_t_158 = 2; - __pyx_t_159 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_156, __pyx_bstride_0_cur_ind)); - __pyx_t_160 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_157, __pyx_bstride_0_cur_ind)); - __pyx_t_161 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_158, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dt.buf, __pyx_t_159, __pyx_bstride_0_grid_dt, __pyx_t_160, __pyx_bstride_1_grid_dt, __pyx_t_161, __pyx_bstride_2_grid_dt) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_155, __pyx_bstride_0_tmax)) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":214 - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[1] - enter_t - * enter_t = tmax[1] # <<<<<<<<<<<<<< - * tmax[1] += tdelta[1] - * cur_ind[1] += step[1] - */ - __pyx_t_162 = 1; - __pyx_v_enter_t = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_162, __pyx_bstride_0_tmax)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":215 - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[1] - enter_t - * enter_t = tmax[1] - * tmax[1] += tdelta[1] # <<<<<<<<<<<<<< - * cur_ind[1] += step[1] - * else: - */ - __pyx_t_163 = 1; - __pyx_t_164 = 1; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_164, __pyx_bstride_0_tmax) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_163, __pyx_bstride_0_tdelta)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":216 - * enter_t = tmax[1] - * tmax[1] += tdelta[1] - * cur_ind[1] += step[1] # <<<<<<<<<<<<<< - * else: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - */ - __pyx_t_165 = 1; - __pyx_t_166 = 1; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_166, __pyx_bstride_0_cur_ind) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_165, __pyx_bstride_0_step)); - goto __pyx_L25; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":218 - * cur_ind[1] += step[1] - * else: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t # <<<<<<<<<<<<<< - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - * enter_t = tmax[2] - */ - __pyx_t_167 = 0; - __pyx_t_168 = 1; - __pyx_t_169 = 2; - __pyx_t_170 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_167, __pyx_bstride_0_cur_ind)); - __pyx_t_171 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_168, __pyx_bstride_0_cur_ind)); - __pyx_t_172 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_169, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_t.buf, __pyx_t_170, __pyx_bstride_0_grid_t, __pyx_t_171, __pyx_bstride_1_grid_t, __pyx_t_172, __pyx_bstride_2_grid_t) = __pyx_v_enter_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":219 - * else: - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - */ - __pyx_t_173 = 2; - __pyx_t_174 = 0; - __pyx_t_175 = 1; - __pyx_t_176 = 2; - __pyx_t_177 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_174, __pyx_bstride_0_cur_ind)); - __pyx_t_178 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_175, __pyx_bstride_0_cur_ind)); - __pyx_t_179 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_176, __pyx_bstride_0_cur_ind)); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dt.buf, __pyx_t_177, __pyx_bstride_0_grid_dt, __pyx_t_178, __pyx_bstride_1_grid_dt, __pyx_t_179, __pyx_bstride_2_grid_dt) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_173, __pyx_bstride_0_tmax)) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":220 - * grid_t[cur_ind[0], cur_ind[1], cur_ind[2]] = enter_t - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - * enter_t = tmax[2] # <<<<<<<<<<<<<< - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] - */ - __pyx_t_180 = 2; - __pyx_v_enter_t = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_180, __pyx_bstride_0_tmax)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":221 - * grid_dt[cur_ind[0], cur_ind[1], cur_ind[2]] = tmax[2] - enter_t - * enter_t = tmax[2] - * tmax[2] += tdelta[2] # <<<<<<<<<<<<<< - * cur_ind[2] += step[2] - * return - */ - __pyx_t_181 = 2; - __pyx_t_182 = 2; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tmax.buf, __pyx_t_182, __pyx_bstride_0_tmax) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_tdelta.buf, __pyx_t_181, __pyx_bstride_0_tdelta)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":222 - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] # <<<<<<<<<<<<<< - * return - * - */ - __pyx_t_183 = 2; - __pyx_t_184 = 2; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_cur_ind.buf, __pyx_t_184, __pyx_bstride_0_cur_ind) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_step.buf, __pyx_t_183, __pyx_bstride_0_step)); - } - __pyx_L25:; - } - __pyx_L23:; - } - __pyx_L20_break:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":223 - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] - * return # <<<<<<<<<<<<<< - * - * @cython.wraparound(False) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_intersect); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_t); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dt); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_cur_ind); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_step); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tdelta); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tmax); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_u); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_v); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.VoxelTraversal"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_intersect); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_t); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dt); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_cur_ind); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_step); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tdelta); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tmax); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_u); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_v); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_step); - __Pyx_XDECREF((PyObject *)__pyx_v_cur_ind); - __Pyx_XDECREF((PyObject *)__pyx_v_tdelta); - __Pyx_XDECREF((PyObject *)__pyx_v_tmax); - __Pyx_XDECREF((PyObject *)__pyx_v_intersect); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":227 - * @cython.wraparound(False) - * @cython.boundscheck(False) - * def PlaneVoxelIntegration(np.ndarray[np.float64_t, ndim=1] left_edge, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] right_edge, - * np.ndarray[np.float64_t, ndim=1] dx, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_PlaneVoxelIntegration(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_PlaneVoxelIntegration(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_left_edge = 0; - PyArrayObject *__pyx_v_right_edge = 0; - PyArrayObject *__pyx_v_dx = 0; - PyArrayObject *__pyx_v_ug = 0; - PyArrayObject *__pyx_v_v = 0; - PyArrayObject *__pyx_v_image = 0; - PyArrayObject *__pyx_v_data = 0; - PyArrayObject *__pyx_v_shells = 0; - int __pyx_v_i; - int __pyx_v_vi; - long __pyx_v_intersect_t; - double __pyx_v_dt_tolerance; - int __pyx_v_nv; - int __pyx_v_nshells; - PyArrayObject *__pyx_v_u = 0; - Py_buffer __pyx_bstruct_u; - Py_ssize_t __pyx_bstride_0_u = 0; - Py_ssize_t __pyx_bshape_0_u = 0; - Py_buffer __pyx_bstruct_shells; - Py_ssize_t __pyx_bstride_0_shells = 0; - Py_ssize_t __pyx_bstride_1_shells = 0; - Py_ssize_t __pyx_bshape_0_shells = 0; - Py_ssize_t __pyx_bshape_1_shells = 0; - Py_buffer __pyx_bstruct_image; - Py_ssize_t __pyx_bstride_0_image = 0; - Py_ssize_t __pyx_bstride_1_image = 0; - Py_ssize_t __pyx_bshape_0_image = 0; - Py_ssize_t __pyx_bshape_1_image = 0; - Py_buffer __pyx_bstruct_right_edge; - Py_ssize_t __pyx_bstride_0_right_edge = 0; - Py_ssize_t __pyx_bshape_0_right_edge = 0; - Py_buffer __pyx_bstruct_dx; - Py_ssize_t __pyx_bstride_0_dx = 0; - Py_ssize_t __pyx_bshape_0_dx = 0; - Py_buffer __pyx_bstruct_v; - Py_ssize_t __pyx_bstride_0_v = 0; - Py_ssize_t __pyx_bshape_0_v = 0; - Py_buffer __pyx_bstruct_left_edge; - Py_ssize_t __pyx_bstride_0_left_edge = 0; - Py_ssize_t __pyx_bshape_0_left_edge = 0; - Py_buffer __pyx_bstruct_ug; - Py_ssize_t __pyx_bstride_0_ug = 0; - Py_ssize_t __pyx_bstride_1_ug = 0; - Py_ssize_t __pyx_bshape_0_ug = 0; - Py_ssize_t __pyx_bshape_1_ug = 0; - Py_buffer __pyx_bstruct_data; - Py_ssize_t __pyx_bstride_0_data = 0; - Py_ssize_t __pyx_bstride_1_data = 0; - Py_ssize_t __pyx_bstride_2_data = 0; - Py_ssize_t __pyx_bshape_0_data = 0; - Py_ssize_t __pyx_bshape_1_data = 0; - Py_ssize_t __pyx_bshape_2_data = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyArrayObject *__pyx_t_6 = NULL; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__left_edge,&__pyx_n_s__right_edge,&__pyx_n_s__dx,&__pyx_n_s__ug,&__pyx_n_s__v,&__pyx_n_s__image,&__pyx_n_s__data,&__pyx_n_s__shells,0}; - __Pyx_RefNannySetupContext("PlaneVoxelIntegration"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[8] = {0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edge); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edge); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 2); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ug); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 3); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__v); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 4); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__image); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 5); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 6); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__shells); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, 7); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "PlaneVoxelIntegration") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_left_edge = ((PyArrayObject *)values[0]); - __pyx_v_right_edge = ((PyArrayObject *)values[1]); - __pyx_v_dx = ((PyArrayObject *)values[2]); - __pyx_v_ug = ((PyArrayObject *)values[3]); - __pyx_v_v = ((PyArrayObject *)values[4]); - __pyx_v_image = ((PyArrayObject *)values[5]); - __pyx_v_data = ((PyArrayObject *)values[6]); - __pyx_v_shells = ((PyArrayObject *)values[7]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 8) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_dx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_ug = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_v = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_image = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_data = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_shells = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 7)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("PlaneVoxelIntegration", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.PlaneVoxelIntegration"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_u.buf = NULL; - __pyx_bstruct_left_edge.buf = NULL; - __pyx_bstruct_right_edge.buf = NULL; - __pyx_bstruct_dx.buf = NULL; - __pyx_bstruct_ug.buf = NULL; - __pyx_bstruct_v.buf = NULL; - __pyx_bstruct_image.buf = NULL; - __pyx_bstruct_data.buf = NULL; - __pyx_bstruct_shells.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edge), __pyx_ptype_5numpy_ndarray, 1, "left_edge", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edge), __pyx_ptype_5numpy_ndarray, 1, "right_edge", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dx), __pyx_ptype_5numpy_ndarray, 1, "dx", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ug), __pyx_ptype_5numpy_ndarray, 1, "ug", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_v), __pyx_ptype_5numpy_ndarray, 1, "v", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_image), __pyx_ptype_5numpy_ndarray, 1, "image", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shells), __pyx_ptype_5numpy_ndarray, 1, "shells", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edge, (PyObject*)__pyx_v_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edge = __pyx_bstruct_left_edge.strides[0]; - __pyx_bshape_0_left_edge = __pyx_bstruct_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edge, (PyObject*)__pyx_v_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edge = __pyx_bstruct_right_edge.strides[0]; - __pyx_bshape_0_right_edge = __pyx_bstruct_right_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dx, (PyObject*)__pyx_v_dx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dx = __pyx_bstruct_dx.strides[0]; - __pyx_bshape_0_dx = __pyx_bstruct_dx.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_ug, (PyObject*)__pyx_v_ug, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_ug = __pyx_bstruct_ug.strides[0]; __pyx_bstride_1_ug = __pyx_bstruct_ug.strides[1]; - __pyx_bshape_0_ug = __pyx_bstruct_ug.shape[0]; __pyx_bshape_1_ug = __pyx_bstruct_ug.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_v, (PyObject*)__pyx_v_v, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_v = __pyx_bstruct_v.strides[0]; - __pyx_bshape_0_v = __pyx_bstruct_v.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_image, (PyObject*)__pyx_v_image, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_image = __pyx_bstruct_image.strides[0]; __pyx_bstride_1_image = __pyx_bstruct_image.strides[1]; - __pyx_bshape_0_image = __pyx_bstruct_image.shape[0]; __pyx_bshape_1_image = __pyx_bstruct_image.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bstride_2_data = __pyx_bstruct_data.strides[2]; - __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; __pyx_bshape_2_data = __pyx_bstruct_data.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_shells, (PyObject*)__pyx_v_shells, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_shells = __pyx_bstruct_shells.strides[0]; __pyx_bstride_1_shells = __pyx_bstruct_shells.strides[1]; - __pyx_bshape_0_shells = __pyx_bstruct_shells.shape[0]; __pyx_bshape_1_shells = __pyx_bstruct_shells.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":239 - * # generalized to transfer functions - * cdef int i, x, y, vi - * intersect_t = 1 # <<<<<<<<<<<<<< - * dt_tolerance = 1e-6 - * cdef int nv = ug.shape[0] - */ - __pyx_v_intersect_t = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":240 - * cdef int i, x, y, vi - * intersect_t = 1 - * dt_tolerance = 1e-6 # <<<<<<<<<<<<<< - * cdef int nv = ug.shape[0] - * cdef int nshells = shells.shape[0] - */ - __pyx_v_dt_tolerance = 1e-6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":241 - * intersect_t = 1 - * dt_tolerance = 1e-6 - * cdef int nv = ug.shape[0] # <<<<<<<<<<<<<< - * cdef int nshells = shells.shape[0] - * cdef np.ndarray[np.float64_t, ndim=1] u = np.empty((3,), dtype=np.float64) - */ - __pyx_v_nv = (__pyx_v_ug->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":242 - * dt_tolerance = 1e-6 - * cdef int nv = ug.shape[0] - * cdef int nshells = shells.shape[0] # <<<<<<<<<<<<<< - * cdef np.ndarray[np.float64_t, ndim=1] u = np.empty((3,), dtype=np.float64) - * # Copy things into temporary location for passing between functions - */ - __pyx_v_nshells = (__pyx_v_shells->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":243 - * cdef int nv = ug.shape[0] - * cdef int nshells = shells.shape[0] - * cdef np.ndarray[np.float64_t, ndim=1] u = np.empty((3,), dtype=np.float64) # <<<<<<<<<<<<<< - * # Copy things into temporary location for passing between functions - * for vi in range(nv): - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__float64); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_u, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_u = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_u.buf = NULL; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_u = __pyx_bstruct_u.strides[0]; - __pyx_bshape_0_u = __pyx_bstruct_u.shape[0]; - } - } - __pyx_t_6 = 0; - __pyx_v_u = ((PyArrayObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":245 - * cdef np.ndarray[np.float64_t, ndim=1] u = np.empty((3,), dtype=np.float64) - * # Copy things into temporary location for passing between functions - * for vi in range(nv): # <<<<<<<<<<<<<< - * for i in range(3): u[i] = ug[vi, i] - * integrate_ray(u, v, left_edge, right_edge, dx, - */ - __pyx_t_7 = __pyx_v_nv; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_vi = __pyx_t_8; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":246 - * # Copy things into temporary location for passing between functions - * for vi in range(nv): - * for i in range(3): u[i] = ug[vi, i] # <<<<<<<<<<<<<< - * integrate_ray(u, v, left_edge, right_edge, dx, - * nshells, vi, data, shells, image) - */ - for (__pyx_t_9 = 0; __pyx_t_9 < 3; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; - __pyx_t_10 = __pyx_v_vi; - __pyx_t_11 = __pyx_v_i; - __pyx_t_12 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_12, __pyx_bstride_0_u) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_ug.buf, __pyx_t_10, __pyx_bstride_0_ug, __pyx_t_11, __pyx_bstride_1_ug)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":247 - * for vi in range(nv): - * for i in range(3): u[i] = ug[vi, i] - * integrate_ray(u, v, left_edge, right_edge, dx, # <<<<<<<<<<<<<< - * nshells, vi, data, shells, image) - * - */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__integrate_ray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":248 - * for i in range(3): u[i] = ug[vi, i] - * integrate_ray(u, v, left_edge, right_edge, dx, - * nshells, vi, data, shells, image) # <<<<<<<<<<<<<< - * - * @cython.wraparound(False) - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_nshells); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyInt_FromLong(__pyx_v_vi); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_u)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_u)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_u)); - __Pyx_INCREF(((PyObject *)__pyx_v_v)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_v)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_v)); - __Pyx_INCREF(((PyObject *)__pyx_v_left_edge)); - PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_left_edge)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_left_edge)); - __Pyx_INCREF(((PyObject *)__pyx_v_right_edge)); - PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_right_edge)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_right_edge)); - __Pyx_INCREF(((PyObject *)__pyx_v_dx)); - PyTuple_SET_ITEM(__pyx_t_2, 4, ((PyObject *)__pyx_v_dx)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_dx)); - PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 6, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_data)); - PyTuple_SET_ITEM(__pyx_t_2, 7, ((PyObject *)__pyx_v_data)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_data)); - __Pyx_INCREF(((PyObject *)__pyx_v_shells)); - PyTuple_SET_ITEM(__pyx_t_2, 8, ((PyObject *)__pyx_v_shells)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_shells)); - __Pyx_INCREF(((PyObject *)__pyx_v_image)); - PyTuple_SET_ITEM(__pyx_t_2, 9, ((PyObject *)__pyx_v_image)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_image)); - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_u); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_shells); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_image); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_v); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ug); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.PlaneVoxelIntegration"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_u); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_shells); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_image); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_v); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ug); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_u); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":252 - * @cython.wraparound(False) - * @cython.boundscheck(False) - * def integrate_ray(np.ndarray[np.float64_t, ndim=1] u, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] v, - * np.ndarray[np.float64_t, ndim=1] left_edge, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_integrate_ray(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_integrate_ray(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_u = 0; - PyArrayObject *__pyx_v_v = 0; - PyArrayObject *__pyx_v_left_edge = 0; - PyArrayObject *__pyx_v_right_edge = 0; - PyArrayObject *__pyx_v_dx = 0; - int __pyx_v_nshells; - int __pyx_v_ind; - PyArrayObject *__pyx_v_data = 0; - PyArrayObject *__pyx_v_shells = 0; - PyArrayObject *__pyx_v_image = 0; - int __pyx_v_step[3]; - int __pyx_v_x; - int __pyx_v_y; - int __pyx_v_i; - int __pyx_v_n; - __pyx_t_5numpy_float64_t __pyx_v_intersect_t; - __pyx_t_5numpy_float64_t __pyx_v_dt_tolerance; - __pyx_t_5numpy_float64_t __pyx_v_tl; - __pyx_t_5numpy_float64_t __pyx_v_tr; - __pyx_t_5numpy_float64_t __pyx_v_enter_t; - __pyx_t_5numpy_int64_t __pyx_v_cur_ind[3]; - __pyx_t_5numpy_float64_t __pyx_v_tdelta[3]; - __pyx_t_5numpy_float64_t __pyx_v_tmax[3]; - __pyx_t_5numpy_float64_t __pyx_v_intersect[3]; - __pyx_t_5numpy_float64_t __pyx_v_dt; - __pyx_t_5numpy_float64_t __pyx_v_dv; - __pyx_t_5numpy_float64_t __pyx_v_dist; - __pyx_t_5numpy_float64_t __pyx_v_alpha; - __pyx_t_5numpy_float64_t __pyx_v_one; - int __pyx_v_dims[3]; - __pyx_t_5numpy_float64_t __pyx_v_temp_x; - __pyx_t_5numpy_float64_t __pyx_v_temp_y; - int __pyx_v_ncells; - Py_buffer __pyx_bstruct_image; - Py_ssize_t __pyx_bstride_0_image = 0; - Py_ssize_t __pyx_bstride_1_image = 0; - Py_ssize_t __pyx_bshape_0_image = 0; - Py_ssize_t __pyx_bshape_1_image = 0; - Py_buffer __pyx_bstruct_shells; - Py_ssize_t __pyx_bstride_0_shells = 0; - Py_ssize_t __pyx_bstride_1_shells = 0; - Py_ssize_t __pyx_bshape_0_shells = 0; - Py_ssize_t __pyx_bshape_1_shells = 0; - Py_buffer __pyx_bstruct_right_edge; - Py_ssize_t __pyx_bstride_0_right_edge = 0; - Py_ssize_t __pyx_bshape_0_right_edge = 0; - Py_buffer __pyx_bstruct_left_edge; - Py_ssize_t __pyx_bstride_0_left_edge = 0; - Py_ssize_t __pyx_bshape_0_left_edge = 0; - Py_buffer __pyx_bstruct_dx; - Py_ssize_t __pyx_bstride_0_dx = 0; - Py_ssize_t __pyx_bshape_0_dx = 0; - Py_buffer __pyx_bstruct_data; - Py_ssize_t __pyx_bstride_0_data = 0; - Py_ssize_t __pyx_bstride_1_data = 0; - Py_ssize_t __pyx_bstride_2_data = 0; - Py_ssize_t __pyx_bshape_0_data = 0; - Py_ssize_t __pyx_bshape_1_data = 0; - Py_ssize_t __pyx_bshape_2_data = 0; - Py_buffer __pyx_bstruct_u; - Py_ssize_t __pyx_bstride_0_u = 0; - Py_ssize_t __pyx_bshape_0_u = 0; - Py_buffer __pyx_bstruct_v; - Py_ssize_t __pyx_bstride_0_v = 0; - Py_ssize_t __pyx_bshape_0_v = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - __pyx_t_5numpy_float64_t __pyx_t_6; - int __pyx_t_7; - __pyx_t_5numpy_float64_t __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - int __pyx_t_29; - int __pyx_t_30; - int __pyx_t_31; - int __pyx_t_32; - int __pyx_t_33; - long __pyx_t_34; - long __pyx_t_35; - long __pyx_t_36; - long __pyx_t_37; - long __pyx_t_38; - long __pyx_t_39; - long __pyx_t_40; - long __pyx_t_41; - long __pyx_t_42; - int __pyx_t_43; - int __pyx_t_44; - PyObject *__pyx_t_45 = NULL; - PyObject *__pyx_t_46 = NULL; - int __pyx_t_47; - int __pyx_t_48; - int __pyx_t_49; - PyObject *__pyx_t_50 = NULL; - __pyx_t_5numpy_int64_t __pyx_t_51; - int __pyx_t_52; - int __pyx_t_53; - int __pyx_t_54; - int __pyx_t_55; - int __pyx_t_56; - int __pyx_t_57; - int __pyx_t_58; - int __pyx_t_59; - int __pyx_t_60; - int __pyx_t_61; - int __pyx_t_62; - int __pyx_t_63; - int __pyx_t_64; - int __pyx_t_65; - __pyx_t_5numpy_int64_t __pyx_t_66; - __pyx_t_5numpy_int64_t __pyx_t_67; - long __pyx_t_68; - __pyx_t_5numpy_int64_t __pyx_t_69; - int __pyx_t_70; - int __pyx_t_71; - int __pyx_t_72; - long __pyx_t_73; - int __pyx_t_74; - long __pyx_t_75; - int __pyx_t_76; - long __pyx_t_77; - int __pyx_t_78; - long __pyx_t_79; - int __pyx_t_80; - long __pyx_t_81; - int __pyx_t_82; - long __pyx_t_83; - int __pyx_t_84; - long __pyx_t_85; - int __pyx_t_86; - long __pyx_t_87; - int __pyx_t_88; - long __pyx_t_89; - int __pyx_t_90; - long __pyx_t_91; - int __pyx_t_92; - long __pyx_t_93; - int __pyx_t_94; - long __pyx_t_95; - __pyx_t_5numpy_int64_t __pyx_t_96; - __pyx_t_5numpy_int64_t __pyx_t_97; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__u,&__pyx_n_s__v,&__pyx_n_s__left_edge,&__pyx_n_s__right_edge,&__pyx_n_s__dx,&__pyx_n_s__nshells,&__pyx_n_s__ind,&__pyx_n_s__data,&__pyx_n_s__shells,&__pyx_n_s__image,0}; - __Pyx_RefNannySetupContext("integrate_ray"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__u); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__v); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edge); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 2); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edge); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 3); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 4); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nshells); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 5); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ind); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 6); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 7); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 8: - values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__shells); - if (likely(values[8])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 8); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 9: - values[9] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__image); - if (likely(values[9])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, 9); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "integrate_ray") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_u = ((PyArrayObject *)values[0]); - __pyx_v_v = ((PyArrayObject *)values[1]); - __pyx_v_left_edge = ((PyArrayObject *)values[2]); - __pyx_v_right_edge = ((PyArrayObject *)values[3]); - __pyx_v_dx = ((PyArrayObject *)values[4]); - __pyx_v_nshells = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_nshells == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_ind = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_ind == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_data = ((PyArrayObject *)values[7]); - __pyx_v_shells = ((PyArrayObject *)values[8]); - __pyx_v_image = ((PyArrayObject *)values[9]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 10) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_u = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_v = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_dx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_nshells = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_nshells == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_ind = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 6)); if (unlikely((__pyx_v_ind == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_data = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 7)); - __pyx_v_shells = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 8)); - __pyx_v_image = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 9)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("integrate_ray", 1, 10, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.integrate_ray"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_u.buf = NULL; - __pyx_bstruct_v.buf = NULL; - __pyx_bstruct_left_edge.buf = NULL; - __pyx_bstruct_right_edge.buf = NULL; - __pyx_bstruct_dx.buf = NULL; - __pyx_bstruct_data.buf = NULL; - __pyx_bstruct_shells.buf = NULL; - __pyx_bstruct_image.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_u), __pyx_ptype_5numpy_ndarray, 1, "u", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_v), __pyx_ptype_5numpy_ndarray, 1, "v", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edge), __pyx_ptype_5numpy_ndarray, 1, "left_edge", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edge), __pyx_ptype_5numpy_ndarray, 1, "right_edge", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dx), __pyx_ptype_5numpy_ndarray, 1, "dx", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shells), __pyx_ptype_5numpy_ndarray, 1, "shells", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_image), __pyx_ptype_5numpy_ndarray, 1, "image", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_u, (PyObject*)__pyx_v_u, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_u = __pyx_bstruct_u.strides[0]; - __pyx_bshape_0_u = __pyx_bstruct_u.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_v, (PyObject*)__pyx_v_v, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_v = __pyx_bstruct_v.strides[0]; - __pyx_bshape_0_v = __pyx_bstruct_v.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edge, (PyObject*)__pyx_v_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edge = __pyx_bstruct_left_edge.strides[0]; - __pyx_bshape_0_left_edge = __pyx_bstruct_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edge, (PyObject*)__pyx_v_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edge = __pyx_bstruct_right_edge.strides[0]; - __pyx_bshape_0_right_edge = __pyx_bstruct_right_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dx, (PyObject*)__pyx_v_dx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dx = __pyx_bstruct_dx.strides[0]; - __pyx_bshape_0_dx = __pyx_bstruct_dx.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bstride_2_data = __pyx_bstruct_data.strides[2]; - __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; __pyx_bshape_2_data = __pyx_bstruct_data.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_shells, (PyObject*)__pyx_v_shells, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_shells = __pyx_bstruct_shells.strides[0]; __pyx_bstride_1_shells = __pyx_bstruct_shells.strides[1]; - __pyx_bshape_0_shells = __pyx_bstruct_shells.shape[0]; __pyx_bshape_1_shells = __pyx_bstruct_shells.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_image, (PyObject*)__pyx_v_image, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_image = __pyx_bstruct_image.strides[0]; __pyx_bstride_1_image = __pyx_bstruct_image.strides[1]; - __pyx_bshape_0_image = __pyx_bstruct_image.shape[0]; __pyx_bshape_1_image = __pyx_bstruct_image.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":262 - * np.ndarray[np.float64_t, ndim=2] image): - * cdef int step[3], x, y, i, n - * cdef np.float64_t intersect_t = 1 # <<<<<<<<<<<<<< - * cdef np.float64_t dt_tolerance = 1e-6 - * cdef np.float64_t tl, tr, enter_t, exit_t - */ - __pyx_v_intersect_t = 1.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":263 - * cdef int step[3], x, y, i, n - * cdef np.float64_t intersect_t = 1 - * cdef np.float64_t dt_tolerance = 1e-6 # <<<<<<<<<<<<<< - * cdef np.float64_t tl, tr, enter_t, exit_t - * cdef np.int64_t cur_ind[3] - */ - __pyx_v_dt_tolerance = 1e-6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":271 - * cdef np.float64_t dt, dv - * cdef np.float64_t dist, alpha - * cdef np.float64_t one = 1.0 # <<<<<<<<<<<<<< - * cdef int dims[3] - * cdef np.float64_t rgba[4], temp_x, temp_y - */ - __pyx_v_one = 1.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":274 - * cdef int dims[3] - * cdef np.float64_t rgba[4], temp_x, temp_y - * for i in range(3): # <<<<<<<<<<<<<< - * # As long as we're iterating, set some other stuff, too - * dims[i] = data.shape[i] - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":276 - * for i in range(3): - * # As long as we're iterating, set some other stuff, too - * dims[i] = data.shape[i] # <<<<<<<<<<<<<< - * if(v[i] < 0): step[i] = -1 - * else: step[i] = 1 - */ - (__pyx_v_dims[__pyx_v_i]) = (__pyx_v_data->dimensions[__pyx_v_i]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":277 - * # As long as we're iterating, set some other stuff, too - * dims[i] = data.shape[i] - * if(v[i] < 0): step[i] = -1 # <<<<<<<<<<<<<< - * else: step[i] = 1 - * x = (i+1)%3 - */ - __pyx_t_2 = __pyx_v_i; - __pyx_t_3 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_2, __pyx_bstride_0_v)) < 0.0); - if (__pyx_t_3) { - (__pyx_v_step[__pyx_v_i]) = -1; - goto __pyx_L8; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":278 - * dims[i] = data.shape[i] - * if(v[i] < 0): step[i] = -1 - * else: step[i] = 1 # <<<<<<<<<<<<<< - * x = (i+1)%3 - * y = (i+2)%3 - */ - (__pyx_v_step[__pyx_v_i]) = 1; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":279 - * if(v[i] < 0): step[i] = -1 - * else: step[i] = 1 - * x = (i+1)%3 # <<<<<<<<<<<<<< - * y = (i+2)%3 - * tl = (left_edge[i] - u[i])/v[i] - */ - __pyx_v_x = __Pyx_mod_long((__pyx_v_i + 1), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":280 - * else: step[i] = 1 - * x = (i+1)%3 - * y = (i+2)%3 # <<<<<<<<<<<<<< - * tl = (left_edge[i] - u[i])/v[i] - * tr = (right_edge[i] - u[i])/v[i] - */ - __pyx_v_y = __Pyx_mod_long((__pyx_v_i + 2), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":281 - * x = (i+1)%3 - * y = (i+2)%3 - * tl = (left_edge[i] - u[i])/v[i] # <<<<<<<<<<<<<< - * tr = (right_edge[i] - u[i])/v[i] - * temp_x = (u[x] + tl*v[x]) - */ - __pyx_t_4 = __pyx_v_i; - __pyx_t_5 = __pyx_v_i; - __pyx_t_6 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_4, __pyx_bstride_0_left_edge)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_5, __pyx_bstride_0_u))); - __pyx_t_7 = __pyx_v_i; - __pyx_t_8 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_7, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_8 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_tl = (__pyx_t_6 / __pyx_t_8); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":282 - * y = (i+2)%3 - * tl = (left_edge[i] - u[i])/v[i] - * tr = (right_edge[i] - u[i])/v[i] # <<<<<<<<<<<<<< - * temp_x = (u[x] + tl*v[x]) - * temp_y = (u[y] + tl*v[y]) - */ - __pyx_t_9 = __pyx_v_i; - __pyx_t_10 = __pyx_v_i; - __pyx_t_8 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_9, __pyx_bstride_0_right_edge)) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_10, __pyx_bstride_0_u))); - __pyx_t_11 = __pyx_v_i; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_11, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_6 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_tr = (__pyx_t_8 / __pyx_t_6); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":283 - * tl = (left_edge[i] - u[i])/v[i] - * tr = (right_edge[i] - u[i])/v[i] - * temp_x = (u[x] + tl*v[x]) # <<<<<<<<<<<<<< - * temp_y = (u[y] + tl*v[y]) - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - */ - __pyx_t_12 = __pyx_v_x; - __pyx_t_13 = __pyx_v_x; - __pyx_v_temp_x = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_12, __pyx_bstride_0_u)) + (__pyx_v_tl * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_13, __pyx_bstride_0_v)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":284 - * tr = (right_edge[i] - u[i])/v[i] - * temp_x = (u[x] + tl*v[x]) - * temp_y = (u[y] + tl*v[y]) # <<<<<<<<<<<<<< - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - */ - __pyx_t_14 = __pyx_v_y; - __pyx_t_15 = __pyx_v_y; - __pyx_v_temp_y = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_14, __pyx_bstride_0_u)) + (__pyx_v_tl * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_15, __pyx_bstride_0_v)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":285 - * temp_x = (u[x] + tl*v[x]) - * temp_y = (u[y] + tl*v[y]) - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ # <<<<<<<<<<<<<< - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - * (0.0 <= tl) and (tl < intersect_t): - */ - __pyx_t_16 = __pyx_v_x; - __pyx_t_3 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_16, __pyx_bstride_0_left_edge)) <= __pyx_v_temp_x); - if (__pyx_t_3) { - __pyx_t_17 = __pyx_v_x; - __pyx_t_18 = (__pyx_v_temp_x <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_17, __pyx_bstride_0_right_edge))); - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":286 - * temp_y = (u[y] + tl*v[y]) - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ # <<<<<<<<<<<<<< - * (0.0 <= tl) and (tl < intersect_t): - * intersect_t = tl - */ - __pyx_t_19 = __pyx_v_y; - __pyx_t_20 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_19, __pyx_bstride_0_left_edge)) <= __pyx_v_temp_y); - if (__pyx_t_20) { - __pyx_t_21 = __pyx_v_y; - __pyx_t_22 = (__pyx_v_temp_y <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_21, __pyx_bstride_0_right_edge))); - if (__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":287 - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - * (0.0 <= tl) and (tl < intersect_t): # <<<<<<<<<<<<<< - * intersect_t = tl - * temp_x = (u[x] + tr*v[x]) - */ - __pyx_t_23 = (0.0 <= __pyx_v_tl); - if (__pyx_t_23) { - __pyx_t_24 = (__pyx_v_tl < __pyx_v_intersect_t); - __pyx_t_25 = __pyx_t_24; - } else { - __pyx_t_25 = __pyx_t_23; - } - __pyx_t_23 = __pyx_t_25; - } else { - __pyx_t_23 = __pyx_t_22; - } - __pyx_t_22 = __pyx_t_23; - } else { - __pyx_t_22 = __pyx_t_20; - } - __pyx_t_20 = __pyx_t_22; - } else { - __pyx_t_20 = __pyx_t_18; - } - __pyx_t_18 = __pyx_t_20; - } else { - __pyx_t_18 = __pyx_t_3; - } - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":288 - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - * (0.0 <= tl) and (tl < intersect_t): - * intersect_t = tl # <<<<<<<<<<<<<< - * temp_x = (u[x] + tr*v[x]) - * temp_y = (u[y] + tr*v[y]) - */ - __pyx_v_intersect_t = __pyx_v_tl; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":289 - * (0.0 <= tl) and (tl < intersect_t): - * intersect_t = tl - * temp_x = (u[x] + tr*v[x]) # <<<<<<<<<<<<<< - * temp_y = (u[y] + tr*v[y]) - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - */ - __pyx_t_26 = __pyx_v_x; - __pyx_t_27 = __pyx_v_x; - __pyx_v_temp_x = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_26, __pyx_bstride_0_u)) + (__pyx_v_tr * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_27, __pyx_bstride_0_v)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":290 - * intersect_t = tl - * temp_x = (u[x] + tr*v[x]) - * temp_y = (u[y] + tr*v[y]) # <<<<<<<<<<<<<< - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - */ - __pyx_t_28 = __pyx_v_y; - __pyx_t_29 = __pyx_v_y; - __pyx_v_temp_y = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_28, __pyx_bstride_0_u)) + (__pyx_v_tr * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_29, __pyx_bstride_0_v)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":291 - * temp_x = (u[x] + tr*v[x]) - * temp_y = (u[y] + tr*v[y]) - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ # <<<<<<<<<<<<<< - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - * (0.0 <= tr) and (tr < intersect_t): - */ - __pyx_t_30 = __pyx_v_x; - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_30, __pyx_bstride_0_left_edge)) <= __pyx_v_temp_x); - if (__pyx_t_18) { - __pyx_t_31 = __pyx_v_x; - __pyx_t_3 = (__pyx_v_temp_x <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_31, __pyx_bstride_0_right_edge))); - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":292 - * temp_y = (u[y] + tr*v[y]) - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ # <<<<<<<<<<<<<< - * (0.0 <= tr) and (tr < intersect_t): - * intersect_t = tr - */ - __pyx_t_32 = __pyx_v_y; - __pyx_t_20 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_32, __pyx_bstride_0_left_edge)) <= __pyx_v_temp_y); - if (__pyx_t_20) { - __pyx_t_33 = __pyx_v_y; - __pyx_t_22 = (__pyx_v_temp_y <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_33, __pyx_bstride_0_right_edge))); - if (__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":293 - * if (left_edge[x] <= temp_x) and (temp_x <= right_edge[x]) and \ - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - * (0.0 <= tr) and (tr < intersect_t): # <<<<<<<<<<<<<< - * intersect_t = tr - * # if fully enclosed - */ - __pyx_t_23 = (0.0 <= __pyx_v_tr); - if (__pyx_t_23) { - __pyx_t_25 = (__pyx_v_tr < __pyx_v_intersect_t); - __pyx_t_24 = __pyx_t_25; - } else { - __pyx_t_24 = __pyx_t_23; - } - __pyx_t_23 = __pyx_t_24; - } else { - __pyx_t_23 = __pyx_t_22; - } - __pyx_t_22 = __pyx_t_23; - } else { - __pyx_t_22 = __pyx_t_20; - } - __pyx_t_20 = __pyx_t_22; - } else { - __pyx_t_20 = __pyx_t_3; - } - __pyx_t_3 = __pyx_t_20; - } else { - __pyx_t_3 = __pyx_t_18; - } - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":294 - * (left_edge[y] <= temp_y) and (temp_y <= right_edge[y]) and \ - * (0.0 <= tr) and (tr < intersect_t): - * intersect_t = tr # <<<<<<<<<<<<<< - * # if fully enclosed - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ - */ - __pyx_v_intersect_t = __pyx_v_tr; - goto __pyx_L10; - } - __pyx_L10:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":296 - * intersect_t = tr - * # if fully enclosed - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ # <<<<<<<<<<<<<< - * (left_edge[1] <= u[1] <= right_edge[1]) and \ - * (left_edge[2] <= u[2] <= right_edge[2]): - */ - __pyx_t_34 = 0; - __pyx_t_35 = 0; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_35, __pyx_bstride_0_u)); - __pyx_t_3 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_34, __pyx_bstride_0_left_edge)) <= __pyx_t_6); - if (__pyx_t_3) { - __pyx_t_36 = 0; - __pyx_t_3 = (__pyx_t_6 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_36, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":297 - * # if fully enclosed - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ - * (left_edge[1] <= u[1] <= right_edge[1]) and \ # <<<<<<<<<<<<<< - * (left_edge[2] <= u[2] <= right_edge[2]): - * intersect_t = 0.0 - */ - __pyx_t_37 = 1; - __pyx_t_38 = 1; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_38, __pyx_bstride_0_u)); - __pyx_t_18 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_37, __pyx_bstride_0_left_edge)) <= __pyx_t_6); - if (__pyx_t_18) { - __pyx_t_39 = 1; - __pyx_t_18 = (__pyx_t_6 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_39, __pyx_bstride_0_right_edge))); - } - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":298 - * if (left_edge[0] <= u[0] <= right_edge[0]) and \ - * (left_edge[1] <= u[1] <= right_edge[1]) and \ - * (left_edge[2] <= u[2] <= right_edge[2]): # <<<<<<<<<<<<<< - * intersect_t = 0.0 - * if not (0 <= intersect_t <= 1): - */ - __pyx_t_40 = 2; - __pyx_t_41 = 2; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_41, __pyx_bstride_0_u)); - __pyx_t_20 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_40, __pyx_bstride_0_left_edge)) <= __pyx_t_6); - if (__pyx_t_20) { - __pyx_t_42 = 2; - __pyx_t_20 = (__pyx_t_6 <= (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_42, __pyx_bstride_0_right_edge))); - } - __pyx_t_22 = __pyx_t_20; - } else { - __pyx_t_22 = __pyx_t_18; - } - __pyx_t_18 = __pyx_t_22; - } else { - __pyx_t_18 = __pyx_t_3; - } - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":299 - * (left_edge[1] <= u[1] <= right_edge[1]) and \ - * (left_edge[2] <= u[2] <= right_edge[2]): - * intersect_t = 0.0 # <<<<<<<<<<<<<< - * if not (0 <= intersect_t <= 1): - * #print "Returning: intersect_t ==", intersect_t - */ - __pyx_v_intersect_t = 0.0; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":300 - * (left_edge[2] <= u[2] <= right_edge[2]): - * intersect_t = 0.0 - * if not (0 <= intersect_t <= 1): # <<<<<<<<<<<<<< - * #print "Returning: intersect_t ==", intersect_t - * return - */ - __pyx_t_18 = (0.0 <= __pyx_v_intersect_t); - if (__pyx_t_18) { - __pyx_t_18 = (__pyx_v_intersect_t <= 1.0); - } - __pyx_t_3 = (!__pyx_t_18); - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":302 - * if not (0 <= intersect_t <= 1): - * #print "Returning: intersect_t ==", intersect_t - * return # <<<<<<<<<<<<<< - * # Now get the indices of the intersection - * for i in range(3): intersect[i] = u[i] + intersect_t * v[i] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":304 - * return - * # Now get the indices of the intersection - * for i in range(3): intersect[i] = u[i] + intersect_t * v[i] # <<<<<<<<<<<<<< - * cdef int ncells = 0 - * for i in range(3): - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - __pyx_t_43 = __pyx_v_i; - __pyx_t_44 = __pyx_v_i; - (__pyx_v_intersect[__pyx_v_i]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_43, __pyx_bstride_0_u)) + (__pyx_v_intersect_t * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_44, __pyx_bstride_0_v)))); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":305 - * # Now get the indices of the intersection - * for i in range(3): intersect[i] = u[i] + intersect_t * v[i] - * cdef int ncells = 0 # <<<<<<<<<<<<<< - * for i in range(3): - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - */ - __pyx_v_ncells = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":306 - * for i in range(3): intersect[i] = u[i] + intersect_t * v[i] - * cdef int ncells = 0 - * for i in range(3): # <<<<<<<<<<<<<< - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":307 - * cdef int ncells = 0 - * for i in range(3): - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) # <<<<<<<<<<<<<< - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - * if cur_ind[i] == dims[i] and step[i] < 0: - */ - __pyx_t_45 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_45)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_45); - __pyx_t_46 = PyObject_GetAttr(__pyx_t_45, __pyx_n_s__floor); if (unlikely(!__pyx_t_46)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_46); - __Pyx_DECREF(__pyx_t_45); __pyx_t_45 = 0; - __pyx_t_47 = __pyx_v_i; - __pyx_t_48 = __pyx_v_i; - __pyx_t_6 = (((__pyx_v_intersect[__pyx_v_i]) + (1e-8 * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_47, __pyx_bstride_0_dx)))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_48, __pyx_bstride_0_left_edge))); - __pyx_t_49 = __pyx_v_i; - __pyx_t_8 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_49, __pyx_bstride_0_dx)); - if (unlikely(__pyx_t_8 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_45 = PyFloat_FromDouble((__pyx_t_6 / __pyx_t_8)); if (unlikely(!__pyx_t_45)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_45); - __pyx_t_50 = PyTuple_New(1); if (unlikely(!__pyx_t_50)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_50); - PyTuple_SET_ITEM(__pyx_t_50, 0, __pyx_t_45); - __Pyx_GIVEREF(__pyx_t_45); - __pyx_t_45 = 0; - __pyx_t_45 = PyObject_Call(__pyx_t_46, __pyx_t_50, NULL); if (unlikely(!__pyx_t_45)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_45); - __Pyx_DECREF(__pyx_t_46); __pyx_t_46 = 0; - __Pyx_DECREF(__pyx_t_50); __pyx_t_50 = 0; - __pyx_t_51 = __Pyx_PyInt_from_py_npy_int64(__pyx_t_45); if (unlikely((__pyx_t_51 == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_45); __pyx_t_45 = 0; - (__pyx_v_cur_ind[__pyx_v_i]) = __pyx_t_51; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":308 - * for i in range(3): - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] # <<<<<<<<<<<<<< - * if cur_ind[i] == dims[i] and step[i] < 0: - * cur_ind[i] = dims[i] - 1 - */ - __pyx_t_52 = __pyx_v_i; - __pyx_t_53 = __pyx_v_i; - __pyx_t_54 = __pyx_v_i; - __pyx_t_8 = (((((__pyx_v_cur_ind[__pyx_v_i]) + (__pyx_v_step[__pyx_v_i])) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_52, __pyx_bstride_0_dx))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_53, __pyx_bstride_0_left_edge))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_54, __pyx_bstride_0_u))); - __pyx_t_55 = __pyx_v_i; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_55, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_6 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_tmax[__pyx_v_i]) = (__pyx_t_8 / __pyx_t_6); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":309 - * cur_ind[i] = np.floor((intersect[i] + 1e-8*dx[i] - left_edge[i])/dx[i]) - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - * if cur_ind[i] == dims[i] and step[i] < 0: # <<<<<<<<<<<<<< - * cur_ind[i] = dims[i] - 1 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - */ - __pyx_t_3 = ((__pyx_v_cur_ind[__pyx_v_i]) == (__pyx_v_dims[__pyx_v_i])); - if (__pyx_t_3) { - __pyx_t_18 = ((__pyx_v_step[__pyx_v_i]) < 0); - __pyx_t_22 = __pyx_t_18; - } else { - __pyx_t_22 = __pyx_t_3; - } - if (__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":310 - * tmax[i] = (((cur_ind[i]+step[i])*dx[i])+left_edge[i]-u[i])/v[i] - * if cur_ind[i] == dims[i] and step[i] < 0: - * cur_ind[i] = dims[i] - 1 # <<<<<<<<<<<<<< - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - */ - (__pyx_v_cur_ind[__pyx_v_i]) = ((__pyx_v_dims[__pyx_v_i]) - 1); - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":311 - * if cur_ind[i] == dims[i] and step[i] < 0: - * cur_ind[i] = dims[i] - 1 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] # <<<<<<<<<<<<<< - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - * tdelta[i] = (dx[i]/v[i]) - */ - __pyx_t_22 = ((__pyx_v_step[__pyx_v_i]) > 0); - if (__pyx_t_22) { - __pyx_t_56 = __pyx_v_i; - __pyx_t_57 = __pyx_v_i; - __pyx_t_58 = __pyx_v_i; - __pyx_t_6 = (((((__pyx_v_cur_ind[__pyx_v_i]) + 1) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_56, __pyx_bstride_0_dx))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_57, __pyx_bstride_0_left_edge))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_58, __pyx_bstride_0_u))); - __pyx_t_59 = __pyx_v_i; - __pyx_t_8 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_59, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_8 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_tmax[__pyx_v_i]) = (__pyx_t_6 / __pyx_t_8); - goto __pyx_L18; - } - __pyx_L18:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":312 - * cur_ind[i] = dims[i] - 1 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] # <<<<<<<<<<<<<< - * tdelta[i] = (dx[i]/v[i]) - * if tdelta[i] < 0: tdelta[i] *= -1 - */ - __pyx_t_22 = ((__pyx_v_step[__pyx_v_i]) < 0); - if (__pyx_t_22) { - __pyx_t_60 = __pyx_v_i; - __pyx_t_61 = __pyx_v_i; - __pyx_t_62 = __pyx_v_i; - __pyx_t_8 = (((((__pyx_v_cur_ind[__pyx_v_i]) + 0) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_60, __pyx_bstride_0_dx))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_61, __pyx_bstride_0_left_edge))) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_u.buf, __pyx_t_62, __pyx_bstride_0_u))); - __pyx_t_63 = __pyx_v_i; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_63, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_6 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_tmax[__pyx_v_i]) = (__pyx_t_8 / __pyx_t_6); - goto __pyx_L19; - } - __pyx_L19:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":313 - * if step[i] > 0: tmax[i] = (((cur_ind[i]+1)*dx[i])+left_edge[i]-u[i])/v[i] - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - * tdelta[i] = (dx[i]/v[i]) # <<<<<<<<<<<<<< - * if tdelta[i] < 0: tdelta[i] *= -1 - * # The variable intersect contains the point we first pierce the grid - */ - __pyx_t_64 = __pyx_v_i; - __pyx_t_6 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_64, __pyx_bstride_0_dx)); - __pyx_t_65 = __pyx_v_i; - __pyx_t_8 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_v.buf, __pyx_t_65, __pyx_bstride_0_v)); - if (unlikely(__pyx_t_8 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_tdelta[__pyx_v_i]) = (__pyx_t_6 / __pyx_t_8); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":314 - * if step[i] < 0: tmax[i] = (((cur_ind[i]+0)*dx[i])+left_edge[i]-u[i])/v[i] - * tdelta[i] = (dx[i]/v[i]) - * if tdelta[i] < 0: tdelta[i] *= -1 # <<<<<<<<<<<<<< - * # The variable intersect contains the point we first pierce the grid - * enter_t = intersect_t - */ - __pyx_t_22 = ((__pyx_v_tdelta[__pyx_v_i]) < 0.0); - if (__pyx_t_22) { - (__pyx_v_tdelta[__pyx_v_i]) *= -1.0; - goto __pyx_L20; - } - __pyx_L20:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":316 - * if tdelta[i] < 0: tdelta[i] *= -1 - * # The variable intersect contains the point we first pierce the grid - * enter_t = intersect_t # <<<<<<<<<<<<<< - * if (not (0 <= cur_ind[0] < dims[0])) or \ - * (not (0 <= cur_ind[1] < dims[1])) or \ - */ - __pyx_v_enter_t = __pyx_v_intersect_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":317 - * # The variable intersect contains the point we first pierce the grid - * enter_t = intersect_t - * if (not (0 <= cur_ind[0] < dims[0])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[1] < dims[1])) or \ - * (not (0 <= cur_ind[2] < dims[2])): - */ - __pyx_t_51 = (__pyx_v_cur_ind[0]); - __pyx_t_22 = (0 <= __pyx_t_51); - if (__pyx_t_22) { - __pyx_t_22 = (__pyx_t_51 < (__pyx_v_dims[0])); - } - __pyx_t_3 = (!__pyx_t_22); - if (!__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":318 - * enter_t = intersect_t - * if (not (0 <= cur_ind[0] < dims[0])) or \ - * (not (0 <= cur_ind[1] < dims[1])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[2] < dims[2])): - * #print "Returning: cur_ind", cur_ind[0], cur_ind[1], cur_ind[2] - */ - __pyx_t_51 = (__pyx_v_cur_ind[1]); - __pyx_t_22 = (0 <= __pyx_t_51); - if (__pyx_t_22) { - __pyx_t_22 = (__pyx_t_51 < (__pyx_v_dims[1])); - } - __pyx_t_18 = (!__pyx_t_22); - if (!__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":319 - * if (not (0 <= cur_ind[0] < dims[0])) or \ - * (not (0 <= cur_ind[1] < dims[1])) or \ - * (not (0 <= cur_ind[2] < dims[2])): # <<<<<<<<<<<<<< - * #print "Returning: cur_ind", cur_ind[0], cur_ind[1], cur_ind[2] - * #print " dims: ", dims[0], dims[1], dims[2] - */ - __pyx_t_51 = (__pyx_v_cur_ind[2]); - __pyx_t_22 = (0 <= __pyx_t_51); - if (__pyx_t_22) { - __pyx_t_22 = (__pyx_t_51 < (__pyx_v_dims[2])); - } - __pyx_t_20 = (!__pyx_t_22); - __pyx_t_22 = __pyx_t_20; - } else { - __pyx_t_22 = __pyx_t_18; - } - __pyx_t_18 = __pyx_t_22; - } else { - __pyx_t_18 = __pyx_t_3; - } - if (__pyx_t_18) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":326 - * #print " u :", u[0], u[1], u[2] - * # - * return # <<<<<<<<<<<<<< - * #print cur_ind[0], dims[0], cur_ind[1], dims[1], cur_ind[2], dims[2] - * dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":328 - * return - * #print cur_ind[0], dims[0], cur_ind[1], dims[1], cur_ind[2], dims[2] - * dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] # <<<<<<<<<<<<<< - * #dt = 1e300 - * while 1: - */ - __pyx_t_51 = (__pyx_v_cur_ind[0]); - __pyx_t_66 = (__pyx_v_cur_ind[1]); - __pyx_t_67 = (__pyx_v_cur_ind[2]); - __pyx_v_dv = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_data.buf, __pyx_t_51, __pyx_bstride_0_data, __pyx_t_66, __pyx_bstride_1_data, __pyx_t_67, __pyx_bstride_2_data)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":330 - * dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] - * #dt = 1e300 - * while 1: # <<<<<<<<<<<<<< - * if image[ind,3] >= 1.0: break - * if (not (0 <= cur_ind[0] < dims[0])) or \ - */ - while (1) { - if (!1) break; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":331 - * #dt = 1e300 - * while 1: - * if image[ind,3] >= 1.0: break # <<<<<<<<<<<<<< - * if (not (0 <= cur_ind[0] < dims[0])) or \ - * (not (0 <= cur_ind[1] < dims[1])) or \ - */ - __pyx_t_1 = __pyx_v_ind; - __pyx_t_68 = 3; - __pyx_t_18 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_image.buf, __pyx_t_1, __pyx_bstride_0_image, __pyx_t_68, __pyx_bstride_1_image)) >= 1.0); - if (__pyx_t_18) { - goto __pyx_L23_break; - goto __pyx_L24; - } - __pyx_L24:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":332 - * while 1: - * if image[ind,3] >= 1.0: break - * if (not (0 <= cur_ind[0] < dims[0])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[1] < dims[1])) or \ - * (not (0 <= cur_ind[2] < dims[2])): - */ - __pyx_t_69 = (__pyx_v_cur_ind[0]); - __pyx_t_18 = (0 <= __pyx_t_69); - if (__pyx_t_18) { - __pyx_t_18 = (__pyx_t_69 < (__pyx_v_dims[0])); - } - __pyx_t_3 = (!__pyx_t_18); - if (!__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":333 - * if image[ind,3] >= 1.0: break - * if (not (0 <= cur_ind[0] < dims[0])) or \ - * (not (0 <= cur_ind[1] < dims[1])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[2] < dims[2])): - * break - */ - __pyx_t_69 = (__pyx_v_cur_ind[1]); - __pyx_t_18 = (0 <= __pyx_t_69); - if (__pyx_t_18) { - __pyx_t_18 = (__pyx_t_69 < (__pyx_v_dims[1])); - } - __pyx_t_22 = (!__pyx_t_18); - if (!__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":334 - * if (not (0 <= cur_ind[0] < dims[0])) or \ - * (not (0 <= cur_ind[1] < dims[1])) or \ - * (not (0 <= cur_ind[2] < dims[2])): # <<<<<<<<<<<<<< - * break - * # Do our transfer here - */ - __pyx_t_69 = (__pyx_v_cur_ind[2]); - __pyx_t_18 = (0 <= __pyx_t_69); - if (__pyx_t_18) { - __pyx_t_18 = (__pyx_t_69 < (__pyx_v_dims[2])); - } - __pyx_t_20 = (!__pyx_t_18); - __pyx_t_18 = __pyx_t_20; - } else { - __pyx_t_18 = __pyx_t_22; - } - __pyx_t_22 = __pyx_t_18; - } else { - __pyx_t_22 = __pyx_t_3; - } - if (__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":335 - * (not (0 <= cur_ind[1] < dims[1])) or \ - * (not (0 <= cur_ind[2] < dims[2])): - * break # <<<<<<<<<<<<<< - * # Do our transfer here - * for n in range(nshells): - */ - goto __pyx_L23_break; - goto __pyx_L25; - } - __pyx_L25:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":337 - * break - * # Do our transfer here - * for n in range(nshells): # <<<<<<<<<<<<<< - * dist = shells[n, 0] - dv - * if dist < shells[n,1]: - */ - __pyx_t_70 = __pyx_v_nshells; - for (__pyx_t_71 = 0; __pyx_t_71 < __pyx_t_70; __pyx_t_71+=1) { - __pyx_v_n = __pyx_t_71; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":338 - * # Do our transfer here - * for n in range(nshells): - * dist = shells[n, 0] - dv # <<<<<<<<<<<<<< - * if dist < shells[n,1]: - * dist = exp(-dist/8.0) - */ - __pyx_t_72 = __pyx_v_n; - __pyx_t_73 = 0; - __pyx_v_dist = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_72, __pyx_bstride_0_shells, __pyx_t_73, __pyx_bstride_1_shells)) - __pyx_v_dv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":339 - * for n in range(nshells): - * dist = shells[n, 0] - dv - * if dist < shells[n,1]: # <<<<<<<<<<<<<< - * dist = exp(-dist/8.0) - * alpha = (1.0 - shells[n,5])*shells[n,5]#*dt - */ - __pyx_t_74 = __pyx_v_n; - __pyx_t_75 = 1; - __pyx_t_22 = (__pyx_v_dist < (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_74, __pyx_bstride_0_shells, __pyx_t_75, __pyx_bstride_1_shells))); - if (__pyx_t_22) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":340 - * dist = shells[n, 0] - dv - * if dist < shells[n,1]: - * dist = exp(-dist/8.0) # <<<<<<<<<<<<<< - * alpha = (1.0 - shells[n,5])*shells[n,5]#*dt - * image[ind,0] += alpha*shells[n,2]*dist - */ - __pyx_v_dist = exp(((-__pyx_v_dist) / 8.0)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":341 - * if dist < shells[n,1]: - * dist = exp(-dist/8.0) - * alpha = (1.0 - shells[n,5])*shells[n,5]#*dt # <<<<<<<<<<<<<< - * image[ind,0] += alpha*shells[n,2]*dist - * image[ind,1] += alpha*shells[n,3]*dist - */ - __pyx_t_76 = __pyx_v_n; - __pyx_t_77 = 5; - __pyx_t_78 = __pyx_v_n; - __pyx_t_79 = 5; - __pyx_v_alpha = ((1.0 - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_76, __pyx_bstride_0_shells, __pyx_t_77, __pyx_bstride_1_shells))) * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_78, __pyx_bstride_0_shells, __pyx_t_79, __pyx_bstride_1_shells))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":342 - * dist = exp(-dist/8.0) - * alpha = (1.0 - shells[n,5])*shells[n,5]#*dt - * image[ind,0] += alpha*shells[n,2]*dist # <<<<<<<<<<<<<< - * image[ind,1] += alpha*shells[n,3]*dist - * image[ind,2] += alpha*shells[n,4]*dist - */ - __pyx_t_80 = __pyx_v_n; - __pyx_t_81 = 2; - __pyx_t_82 = __pyx_v_ind; - __pyx_t_83 = 0; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_image.buf, __pyx_t_82, __pyx_bstride_0_image, __pyx_t_83, __pyx_bstride_1_image) += ((__pyx_v_alpha * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_80, __pyx_bstride_0_shells, __pyx_t_81, __pyx_bstride_1_shells))) * __pyx_v_dist); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":343 - * alpha = (1.0 - shells[n,5])*shells[n,5]#*dt - * image[ind,0] += alpha*shells[n,2]*dist - * image[ind,1] += alpha*shells[n,3]*dist # <<<<<<<<<<<<<< - * image[ind,2] += alpha*shells[n,4]*dist - * image[ind,3] += alpha*shells[n,5]*dist - */ - __pyx_t_84 = __pyx_v_n; - __pyx_t_85 = 3; - __pyx_t_86 = __pyx_v_ind; - __pyx_t_87 = 1; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_image.buf, __pyx_t_86, __pyx_bstride_0_image, __pyx_t_87, __pyx_bstride_1_image) += ((__pyx_v_alpha * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_84, __pyx_bstride_0_shells, __pyx_t_85, __pyx_bstride_1_shells))) * __pyx_v_dist); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":344 - * image[ind,0] += alpha*shells[n,2]*dist - * image[ind,1] += alpha*shells[n,3]*dist - * image[ind,2] += alpha*shells[n,4]*dist # <<<<<<<<<<<<<< - * image[ind,3] += alpha*shells[n,5]*dist - * #image[ind,i] += rgba[i]*dist*rgba[3]/dt - */ - __pyx_t_88 = __pyx_v_n; - __pyx_t_89 = 4; - __pyx_t_90 = __pyx_v_ind; - __pyx_t_91 = 2; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_image.buf, __pyx_t_90, __pyx_bstride_0_image, __pyx_t_91, __pyx_bstride_1_image) += ((__pyx_v_alpha * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_88, __pyx_bstride_0_shells, __pyx_t_89, __pyx_bstride_1_shells))) * __pyx_v_dist); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":345 - * image[ind,1] += alpha*shells[n,3]*dist - * image[ind,2] += alpha*shells[n,4]*dist - * image[ind,3] += alpha*shells[n,5]*dist # <<<<<<<<<<<<<< - * #image[ind,i] += rgba[i]*dist*rgba[3]/dt - * #print rgba[i], image[ind,i], dist, dt - */ - __pyx_t_92 = __pyx_v_n; - __pyx_t_93 = 5; - __pyx_t_94 = __pyx_v_ind; - __pyx_t_95 = 3; - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_image.buf, __pyx_t_94, __pyx_bstride_0_image, __pyx_t_95, __pyx_bstride_1_image) += ((__pyx_v_alpha * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_shells.buf, __pyx_t_92, __pyx_bstride_0_shells, __pyx_t_93, __pyx_bstride_1_shells))) * __pyx_v_dist); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":348 - * #image[ind,i] += rgba[i]*dist*rgba[3]/dt - * #print rgba[i], image[ind,i], dist, dt - * break # <<<<<<<<<<<<<< - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - * dt = 1.0 - enter_t - */ - goto __pyx_L27_break; - goto __pyx_L28; - } - __pyx_L28:; - } - __pyx_L27_break:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":349 - * #print rgba[i], image[ind,i], dist, dt - * break - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): # <<<<<<<<<<<<<< - * dt = 1.0 - enter_t - * break - */ - __pyx_t_22 = ((__pyx_v_tmax[0]) > 1.0); - if (__pyx_t_22) { - __pyx_t_3 = ((__pyx_v_tmax[1]) > 1.0); - if (__pyx_t_3) { - __pyx_t_18 = ((__pyx_v_tmax[2]) > 1.0); - __pyx_t_20 = __pyx_t_18; - } else { - __pyx_t_20 = __pyx_t_3; - } - __pyx_t_3 = __pyx_t_20; - } else { - __pyx_t_3 = __pyx_t_22; - } - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":350 - * break - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - * dt = 1.0 - enter_t # <<<<<<<<<<<<<< - * break - * if tmax[0] < tmax[1]: - */ - __pyx_v_dt = (1.0 - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":351 - * if (tmax[0] > 1.0) and (tmax[1] > 1.0) and (tmax[2] > 1.0): - * dt = 1.0 - enter_t - * break # <<<<<<<<<<<<<< - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: - */ - goto __pyx_L23_break; - goto __pyx_L29; - } - __pyx_L29:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":352 - * dt = 1.0 - enter_t - * break - * if tmax[0] < tmax[1]: # <<<<<<<<<<<<<< - * if tmax[0] < tmax[2]: - * dt = tmax[0] - enter_t - */ - __pyx_t_3 = ((__pyx_v_tmax[0]) < (__pyx_v_tmax[1])); - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":353 - * break - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: # <<<<<<<<<<<<<< - * dt = tmax[0] - enter_t - * enter_t = tmax[0] - */ - __pyx_t_3 = ((__pyx_v_tmax[0]) < (__pyx_v_tmax[2])); - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":354 - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: - * dt = tmax[0] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[0] - * tmax[0] += tdelta[0] - */ - __pyx_v_dt = ((__pyx_v_tmax[0]) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":355 - * if tmax[0] < tmax[2]: - * dt = tmax[0] - enter_t - * enter_t = tmax[0] # <<<<<<<<<<<<<< - * tmax[0] += tdelta[0] - * cur_ind[0] += step[0] - */ - __pyx_v_enter_t = (__pyx_v_tmax[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":356 - * dt = tmax[0] - enter_t - * enter_t = tmax[0] - * tmax[0] += tdelta[0] # <<<<<<<<<<<<<< - * cur_ind[0] += step[0] - * else: - */ - (__pyx_v_tmax[0]) += (__pyx_v_tdelta[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":357 - * enter_t = tmax[0] - * tmax[0] += tdelta[0] - * cur_ind[0] += step[0] # <<<<<<<<<<<<<< - * else: - * dt = tmax[2] - enter_t - */ - (__pyx_v_cur_ind[0]) += (__pyx_v_step[0]); - goto __pyx_L31; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":359 - * cur_ind[0] += step[0] - * else: - * dt = tmax[2] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - */ - __pyx_v_dt = ((__pyx_v_tmax[2]) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":360 - * else: - * dt = tmax[2] - enter_t - * enter_t = tmax[2] # <<<<<<<<<<<<<< - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] - */ - __pyx_v_enter_t = (__pyx_v_tmax[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":361 - * dt = tmax[2] - enter_t - * enter_t = tmax[2] - * tmax[2] += tdelta[2] # <<<<<<<<<<<<<< - * cur_ind[2] += step[2] - * else: - */ - (__pyx_v_tmax[2]) += (__pyx_v_tdelta[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":362 - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] # <<<<<<<<<<<<<< - * else: - * if tmax[1] < tmax[2]: - */ - (__pyx_v_cur_ind[2]) += (__pyx_v_step[2]); - } - __pyx_L31:; - goto __pyx_L30; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":364 - * cur_ind[2] += step[2] - * else: - * if tmax[1] < tmax[2]: # <<<<<<<<<<<<<< - * dt = tmax[1] - enter_t - * enter_t = tmax[1] - */ - __pyx_t_3 = ((__pyx_v_tmax[1]) < (__pyx_v_tmax[2])); - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":365 - * else: - * if tmax[1] < tmax[2]: - * dt = tmax[1] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[1] - * tmax[1] += tdelta[1] - */ - __pyx_v_dt = ((__pyx_v_tmax[1]) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":366 - * if tmax[1] < tmax[2]: - * dt = tmax[1] - enter_t - * enter_t = tmax[1] # <<<<<<<<<<<<<< - * tmax[1] += tdelta[1] - * cur_ind[1] += step[1] - */ - __pyx_v_enter_t = (__pyx_v_tmax[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":367 - * dt = tmax[1] - enter_t - * enter_t = tmax[1] - * tmax[1] += tdelta[1] # <<<<<<<<<<<<<< - * cur_ind[1] += step[1] - * else: - */ - (__pyx_v_tmax[1]) += (__pyx_v_tdelta[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":368 - * enter_t = tmax[1] - * tmax[1] += tdelta[1] - * cur_ind[1] += step[1] # <<<<<<<<<<<<<< - * else: - * dt = tmax[2] - enter_t - */ - (__pyx_v_cur_ind[1]) += (__pyx_v_step[1]); - goto __pyx_L32; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":370 - * cur_ind[1] += step[1] - * else: - * dt = tmax[2] - enter_t # <<<<<<<<<<<<<< - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - */ - __pyx_v_dt = ((__pyx_v_tmax[2]) - __pyx_v_enter_t); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":371 - * else: - * dt = tmax[2] - enter_t - * enter_t = tmax[2] # <<<<<<<<<<<<<< - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] - */ - __pyx_v_enter_t = (__pyx_v_tmax[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":372 - * dt = tmax[2] - enter_t - * enter_t = tmax[2] - * tmax[2] += tdelta[2] # <<<<<<<<<<<<<< - * cur_ind[2] += step[2] - * dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] - */ - (__pyx_v_tmax[2]) += (__pyx_v_tdelta[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":373 - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] # <<<<<<<<<<<<<< - * dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] - */ - (__pyx_v_cur_ind[2]) += (__pyx_v_step[2]); - } - __pyx_L32:; - } - __pyx_L30:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":374 - * tmax[2] += tdelta[2] - * cur_ind[2] += step[2] - * dv = data[cur_ind[0], cur_ind[1], cur_ind[2]] # <<<<<<<<<<<<<< - */ - __pyx_t_69 = (__pyx_v_cur_ind[0]); - __pyx_t_96 = (__pyx_v_cur_ind[1]); - __pyx_t_97 = (__pyx_v_cur_ind[2]); - __pyx_v_dv = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_data.buf, __pyx_t_69, __pyx_bstride_0_data, __pyx_t_96, __pyx_bstride_1_data, __pyx_t_97, __pyx_bstride_2_data)); - } - __pyx_L23_break:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_45); - __Pyx_XDECREF(__pyx_t_46); - __Pyx_XDECREF(__pyx_t_50); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_image); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_shells); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_u); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_v); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.integrate_ray"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_image); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_shells); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_u); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_v); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":31 - * from stdlib cimport malloc, free, abs - * - * cdef inline int imax(int i0, int i1): # <<<<<<<<<<<<<< - * if i0 > i1: return i0 - * return i1 - */ - -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_imax(int __pyx_v_i0, int __pyx_v_i1) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("imax"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":32 - * - * cdef inline int imax(int i0, int i1): - * if i0 > i1: return i0 # <<<<<<<<<<<<<< - * return i1 - * - */ - __pyx_t_1 = (__pyx_v_i0 > __pyx_v_i1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_i0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":33 - * cdef inline int imax(int i0, int i1): - * if i0 > i1: return i0 - * return i1 # <<<<<<<<<<<<<< - * - * cdef inline np.float64_t fmax(np.float64_t f0, np.float64_t f1): - */ - __pyx_r = __pyx_v_i1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":35 - * return i1 - * - * cdef inline np.float64_t fmax(np.float64_t f0, np.float64_t f1): # <<<<<<<<<<<<<< - * if f0 > f1: return f0 - * return f1 - */ - -static CYTHON_INLINE __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_fmax(__pyx_t_5numpy_float64_t __pyx_v_f0, __pyx_t_5numpy_float64_t __pyx_v_f1) { - __pyx_t_5numpy_float64_t __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("fmax"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":36 - * - * cdef inline np.float64_t fmax(np.float64_t f0, np.float64_t f1): - * if f0 > f1: return f0 # <<<<<<<<<<<<<< - * return f1 - * - */ - __pyx_t_1 = (__pyx_v_f0 > __pyx_v_f1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_f0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":37 - * cdef inline np.float64_t fmax(np.float64_t f0, np.float64_t f1): - * if f0 > f1: return f0 - * return f1 # <<<<<<<<<<<<<< - * - * cdef inline int imin(int i0, int i1): - */ - __pyx_r = __pyx_v_f1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":39 - * return f1 - * - * cdef inline int imin(int i0, int i1): # <<<<<<<<<<<<<< - * if i0 < i1: return i0 - * return i1 - */ - -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_imin(int __pyx_v_i0, int __pyx_v_i1) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("imin"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":40 - * - * cdef inline int imin(int i0, int i1): - * if i0 < i1: return i0 # <<<<<<<<<<<<<< - * return i1 - * - */ - __pyx_t_1 = (__pyx_v_i0 < __pyx_v_i1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_i0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":41 - * cdef inline int imin(int i0, int i1): - * if i0 < i1: return i0 - * return i1 # <<<<<<<<<<<<<< - * - * cdef inline np.float64_t fmin(np.float64_t f0, np.float64_t f1): - */ - __pyx_r = __pyx_v_i1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":43 - * return i1 - * - * cdef inline np.float64_t fmin(np.float64_t f0, np.float64_t f1): # <<<<<<<<<<<<<< - * if f0 < f1: return f0 - * return f1 - */ - -static CYTHON_INLINE __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_fmin(__pyx_t_5numpy_float64_t __pyx_v_f0, __pyx_t_5numpy_float64_t __pyx_v_f1) { - __pyx_t_5numpy_float64_t __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("fmin"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":44 - * - * cdef inline np.float64_t fmin(np.float64_t f0, np.float64_t f1): - * if f0 < f1: return f0 # <<<<<<<<<<<<<< - * return f1 - * - */ - __pyx_t_1 = (__pyx_v_f0 < __pyx_v_f1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_f0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":45 - * cdef inline np.float64_t fmin(np.float64_t f0, np.float64_t f1): - * if f0 < f1: return f0 - * return f1 # <<<<<<<<<<<<<< - * - * cdef inline int iclip(int i, int a, int b): - */ - __pyx_r = __pyx_v_f1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":47 - * return f1 - * - * cdef inline int iclip(int i, int a, int b): # <<<<<<<<<<<<<< - * if i < a: return a - * if i > b: return b - */ - -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_iclip(int __pyx_v_i, int __pyx_v_a, int __pyx_v_b) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("iclip"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":48 - * - * cdef inline int iclip(int i, int a, int b): - * if i < a: return a # <<<<<<<<<<<<<< - * if i > b: return b - * return i - */ - __pyx_t_1 = (__pyx_v_i < __pyx_v_a); - if (__pyx_t_1) { - __pyx_r = __pyx_v_a; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":49 - * cdef inline int iclip(int i, int a, int b): - * if i < a: return a - * if i > b: return b # <<<<<<<<<<<<<< - * return i - * - */ - __pyx_t_1 = (__pyx_v_i > __pyx_v_b); - if (__pyx_t_1) { - __pyx_r = __pyx_v_b; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":50 - * if i < a: return a - * if i > b: return b - * return i # <<<<<<<<<<<<<< - * - * cdef inline np.float64_t fclip(np.float64_t f, - */ - __pyx_r = __pyx_v_i; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":52 - * return i - * - * cdef inline np.float64_t fclip(np.float64_t f, # <<<<<<<<<<<<<< - * np.float64_t a, np.float64_t b): - * return fmin(fmax(f, a), b) - */ - -static CYTHON_INLINE __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_fclip(__pyx_t_5numpy_float64_t __pyx_v_f, __pyx_t_5numpy_float64_t __pyx_v_a, __pyx_t_5numpy_float64_t __pyx_v_b) { - __pyx_t_5numpy_float64_t __pyx_r; - __Pyx_RefNannySetupContext("fclip"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":54 - * cdef inline np.float64_t fclip(np.float64_t f, - * np.float64_t a, np.float64_t b): - * return fmin(fmax(f, a), b) # <<<<<<<<<<<<<< - * - * cdef extern from "math.h": - */ - __pyx_r = __pyx_f_2yt_9amr_utils_fmin(__pyx_f_2yt_9amr_utils_fmax(__pyx_v_f, __pyx_v_a), __pyx_v_b); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":89 - * int pass_through - * - * cdef void FIT_initialize_table(FieldInterpolationTable *fit, int nbins, # <<<<<<<<<<<<<< - * np.float64_t *values, np.float64_t bounds1, np.float64_t bounds2, - * int field_id, int weight_field_id = -1, int weight_table_id = -1, - */ - -static void __pyx_f_2yt_9amr_utils_FIT_initialize_table(struct __pyx_t_2yt_9amr_utils_FieldInterpolationTable *__pyx_v_fit, int __pyx_v_nbins, __pyx_t_5numpy_float64_t *__pyx_v_values, __pyx_t_5numpy_float64_t __pyx_v_bounds1, __pyx_t_5numpy_float64_t __pyx_v_bounds2, int __pyx_v_field_id, struct __pyx_opt_args_2yt_9amr_utils_FIT_initialize_table *__pyx_optional_args) { - int __pyx_v_weight_field_id = ((int)-1); - int __pyx_v_weight_table_id = ((int)-1); - int __pyx_v_pass_through = ((int)0); - __pyx_t_5numpy_float64_t __pyx_t_1; - __Pyx_RefNannySetupContext("FIT_initialize_table"); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_weight_field_id = __pyx_optional_args->weight_field_id; - if (__pyx_optional_args->__pyx_n > 1) { - __pyx_v_weight_table_id = __pyx_optional_args->weight_table_id; - if (__pyx_optional_args->__pyx_n > 2) { - __pyx_v_pass_through = __pyx_optional_args->pass_through; - } - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":93 - * int field_id, int weight_field_id = -1, int weight_table_id = -1, - * int pass_through = 0): - * fit.bounds[0] = bounds1; fit.bounds[1] = bounds2 # <<<<<<<<<<<<<< - * fit.nbins = nbins - * fit.dbin = (fit.bounds[1] - fit.bounds[0])/fit.nbins - */ - (__pyx_v_fit->bounds[0]) = __pyx_v_bounds1; - (__pyx_v_fit->bounds[1]) = __pyx_v_bounds2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":94 - * int pass_through = 0): - * fit.bounds[0] = bounds1; fit.bounds[1] = bounds2 - * fit.nbins = nbins # <<<<<<<<<<<<<< - * fit.dbin = (fit.bounds[1] - fit.bounds[0])/fit.nbins - * fit.idbin = 1.0/fit.dbin - */ - __pyx_v_fit->nbins = __pyx_v_nbins; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":95 - * fit.bounds[0] = bounds1; fit.bounds[1] = bounds2 - * fit.nbins = nbins - * fit.dbin = (fit.bounds[1] - fit.bounds[0])/fit.nbins # <<<<<<<<<<<<<< - * fit.idbin = 1.0/fit.dbin - * # Better not pull this out from under us, yo - */ - __pyx_t_1 = ((__pyx_v_fit->bounds[1]) - (__pyx_v_fit->bounds[0])); - if (unlikely(__pyx_v_fit->nbins == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_fit->dbin = (__pyx_t_1 / __pyx_v_fit->nbins); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":96 - * fit.nbins = nbins - * fit.dbin = (fit.bounds[1] - fit.bounds[0])/fit.nbins - * fit.idbin = 1.0/fit.dbin # <<<<<<<<<<<<<< - * # Better not pull this out from under us, yo - * fit.values = values - */ - if (unlikely(__pyx_v_fit->dbin == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_fit->idbin = (1.0 / __pyx_v_fit->dbin); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":98 - * fit.idbin = 1.0/fit.dbin - * # Better not pull this out from under us, yo - * fit.values = values # <<<<<<<<<<<<<< - * fit.field_id = field_id - * fit.weight_field_id = weight_field_id - */ - __pyx_v_fit->values = __pyx_v_values; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":99 - * # Better not pull this out from under us, yo - * fit.values = values - * fit.field_id = field_id # <<<<<<<<<<<<<< - * fit.weight_field_id = weight_field_id - * fit.weight_table_id = weight_table_id - */ - __pyx_v_fit->field_id = __pyx_v_field_id; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":100 - * fit.values = values - * fit.field_id = field_id - * fit.weight_field_id = weight_field_id # <<<<<<<<<<<<<< - * fit.weight_table_id = weight_table_id - * fit.pass_through = pass_through - */ - __pyx_v_fit->weight_field_id = __pyx_v_weight_field_id; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":101 - * fit.field_id = field_id - * fit.weight_field_id = weight_field_id - * fit.weight_table_id = weight_table_id # <<<<<<<<<<<<<< - * fit.pass_through = pass_through - * - */ - __pyx_v_fit->weight_table_id = __pyx_v_weight_table_id; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":102 - * fit.weight_field_id = weight_field_id - * fit.weight_table_id = weight_table_id - * fit.pass_through = pass_through # <<<<<<<<<<<<<< - * - * cdef np.float64_t FIT_get_value(FieldInterpolationTable *fit, - */ - __pyx_v_fit->pass_through = __pyx_v_pass_through; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("yt.amr_utils.FIT_initialize_table"); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":104 - * fit.pass_through = pass_through - * - * cdef np.float64_t FIT_get_value(FieldInterpolationTable *fit, # <<<<<<<<<<<<<< - * np.float64_t *dvs): - * cdef np.float64_t bv, dy, dd, tf - */ - -static __pyx_t_5numpy_float64_t __pyx_f_2yt_9amr_utils_FIT_get_value(struct __pyx_t_2yt_9amr_utils_FieldInterpolationTable *__pyx_v_fit, __pyx_t_5numpy_float64_t *__pyx_v_dvs) { - __pyx_t_5numpy_float64_t __pyx_v_bv; - __pyx_t_5numpy_float64_t __pyx_v_dy; - __pyx_t_5numpy_float64_t __pyx_v_dd; - int __pyx_v_bin_id; - __pyx_t_5numpy_float64_t __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("FIT_get_value"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":108 - * cdef np.float64_t bv, dy, dd, tf - * cdef int bin_id - * if fit.pass_through == 1: return dvs[fit.field_id] # <<<<<<<<<<<<<< - * if dvs[fit.field_id] > fit.bounds[1] or dvs[fit.field_id] < fit.bounds[0]: return 0.0 - * bin_id = ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin) - */ - __pyx_t_1 = (__pyx_v_fit->pass_through == 1); - if (__pyx_t_1) { - __pyx_r = (__pyx_v_dvs[__pyx_v_fit->field_id]); - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":109 - * cdef int bin_id - * if fit.pass_through == 1: return dvs[fit.field_id] - * if dvs[fit.field_id] > fit.bounds[1] or dvs[fit.field_id] < fit.bounds[0]: return 0.0 # <<<<<<<<<<<<<< - * bin_id = ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin) - * dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0 - */ - __pyx_t_1 = ((__pyx_v_dvs[__pyx_v_fit->field_id]) > (__pyx_v_fit->bounds[1])); - if (!__pyx_t_1) { - __pyx_t_2 = ((__pyx_v_dvs[__pyx_v_fit->field_id]) < (__pyx_v_fit->bounds[0])); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - __pyx_r = 0.0; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":110 - * if fit.pass_through == 1: return dvs[fit.field_id] - * if dvs[fit.field_id] > fit.bounds[1] or dvs[fit.field_id] < fit.bounds[0]: return 0.0 - * bin_id = ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin) # <<<<<<<<<<<<<< - * dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0 - * bv = fit.values[bin_id] - */ - __pyx_v_bin_id = ((int)(((__pyx_v_dvs[__pyx_v_fit->field_id]) - (__pyx_v_fit->bounds[0])) * __pyx_v_fit->idbin)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":111 - * if dvs[fit.field_id] > fit.bounds[1] or dvs[fit.field_id] < fit.bounds[0]: return 0.0 - * bin_id = ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin) - * dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0 # <<<<<<<<<<<<<< - * bv = fit.values[bin_id] - * dy = fit.values[bin_id + 1] - bv - */ - __pyx_v_dd = ((__pyx_v_dvs[__pyx_v_fit->field_id]) - ((__pyx_v_fit->bounds[0]) + (__pyx_v_bin_id * __pyx_v_fit->dbin))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":112 - * bin_id = ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin) - * dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0 - * bv = fit.values[bin_id] # <<<<<<<<<<<<<< - * dy = fit.values[bin_id + 1] - bv - * if fit.weight_field_id != -1: - */ - __pyx_v_bv = (__pyx_v_fit->values[__pyx_v_bin_id]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":113 - * dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0 - * bv = fit.values[bin_id] - * dy = fit.values[bin_id + 1] - bv # <<<<<<<<<<<<<< - * if fit.weight_field_id != -1: - * return dvs[fit.weight_field_id] * (bv + dd*dy*fit.idbin) - */ - __pyx_v_dy = ((__pyx_v_fit->values[(__pyx_v_bin_id + 1)]) - __pyx_v_bv); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":114 - * bv = fit.values[bin_id] - * dy = fit.values[bin_id + 1] - bv - * if fit.weight_field_id != -1: # <<<<<<<<<<<<<< - * return dvs[fit.weight_field_id] * (bv + dd*dy*fit.idbin) - * return (bv + dd*dy*fit.idbin) - */ - __pyx_t_3 = (__pyx_v_fit->weight_field_id != -1); - if (__pyx_t_3) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":115 - * dy = fit.values[bin_id + 1] - bv - * if fit.weight_field_id != -1: - * return dvs[fit.weight_field_id] * (bv + dd*dy*fit.idbin) # <<<<<<<<<<<<<< - * return (bv + dd*dy*fit.idbin) - * - */ - __pyx_r = ((__pyx_v_dvs[__pyx_v_fit->weight_field_id]) * (__pyx_v_bv + ((__pyx_v_dd * __pyx_v_dy) * __pyx_v_fit->idbin))); - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":116 - * if fit.weight_field_id != -1: - * return dvs[fit.weight_field_id] * (bv + dd*dy*fit.idbin) - * return (bv + dd*dy*fit.idbin) # <<<<<<<<<<<<<< - * - * cdef class TransferFunctionProxy: - */ - __pyx_r = (__pyx_v_bv + ((__pyx_v_dd * __pyx_v_dy) * __pyx_v_fit->idbin)); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":121 - * cdef int n_fields - * cdef int n_field_tables - * cdef public int ns # <<<<<<<<<<<<<< - * - * # These are the field tables and their affiliated storage. - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_2ns___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_2ns___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->ns); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.TransferFunctionProxy.ns.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_2ns___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_2ns___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->ns = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.TransferFunctionProxy.ns.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":136 - * # We store a reference to the transfer function object and to the field - * # interpolation tables - * cdef public object tf_obj # <<<<<<<<<<<<<< - * cdef public object my_field_tables - * - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":137 - * # interpolation tables - * cdef public object tf_obj - * cdef public object my_field_tables # <<<<<<<<<<<<<< - * - * def __cinit__(self, tf_obj): - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":139 - * cdef public object my_field_tables - * - * def __cinit__(self, tf_obj): # <<<<<<<<<<<<<< - * # We have N fields. We have 6 channels. We have M field tables. - * # The idea is that we can have multiple channels corresponding to the - */ - -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_tf_obj = 0; - int __pyx_v_i; - PyArrayObject *__pyx_v_temp; - Py_buffer __pyx_bstruct_temp; - Py_ssize_t __pyx_bstride_0_temp = 0; - Py_ssize_t __pyx_bshape_0_temp = 0; - int __pyx_r; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyArrayObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - __pyx_t_5numpy_float64_t __pyx_t_10; - __pyx_t_5numpy_float64_t __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - struct __pyx_opt_args_2yt_9amr_utils_FIT_initialize_table __pyx_t_15; - PyObject *__pyx_t_16 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__tf_obj,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[1] = {0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tf_obj); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_tf_obj = values[0]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_tf_obj = PyTuple_GET_ITEM(__pyx_args, 0); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.TransferFunctionProxy.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_v_temp = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_temp.buf = NULL; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":150 - * cdef FieldInterpolationTable fit - * - * self.tf_obj = tf_obj # <<<<<<<<<<<<<< - * - * self.n_field_tables = tf_obj.n_field_tables - */ - __Pyx_INCREF(__pyx_v_tf_obj); - __Pyx_GIVEREF(__pyx_v_tf_obj); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj); - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->tf_obj = __pyx_v_tf_obj; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":152 - * self.tf_obj = tf_obj - * - * self.n_field_tables = tf_obj.n_field_tables # <<<<<<<<<<<<<< - * for i in range(6): self.istorage[i] = 0.0 - * - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__n_field_tables); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->n_field_tables = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":153 - * - * self.n_field_tables = tf_obj.n_field_tables - * for i in range(6): self.istorage[i] = 0.0 # <<<<<<<<<<<<<< - * - * self.my_field_tables = [] - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 6; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - (((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->istorage[__pyx_v_i]) = 0.0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":155 - * for i in range(6): self.istorage[i] = 0.0 - * - * self.my_field_tables = [] # <<<<<<<<<<<<<< - * for i in range(self.n_field_tables): - * temp = tf_obj.tables[i].y - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables); - ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":156 - * - * self.my_field_tables = [] - * for i in range(self.n_field_tables): # <<<<<<<<<<<<<< - * temp = tf_obj.tables[i].y - * FIT_initialize_table(&self.field_tables[i], - */ - __pyx_t_2 = ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->n_field_tables; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":157 - * self.my_field_tables = [] - * for i in range(self.n_field_tables): - * temp = tf_obj.tables[i].y # <<<<<<<<<<<<<< - * FIT_initialize_table(&self.field_tables[i], - * temp.shape[0], - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__tables); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__y); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((PyArrayObject *)__pyx_t_1); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_temp); - __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_temp, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_6 < 0)) { - PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_temp, (PyObject*)__pyx_v_temp, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9); - } - } - __pyx_bstride_0_temp = __pyx_bstruct_temp.strides[0]; - __pyx_bshape_0_temp = __pyx_bstruct_temp.shape[0]; - if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_temp)); - __pyx_v_temp = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":161 - * temp.shape[0], - * temp.data, - * tf_obj.tables[i].x_bounds[0], # <<<<<<<<<<<<<< - * tf_obj.tables[i].x_bounds[1], - * tf_obj.field_ids[i], tf_obj.weight_field_ids[i], - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__tables); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__x_bounds); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_10 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":162 - * temp.data, - * tf_obj.tables[i].x_bounds[0], - * tf_obj.tables[i].x_bounds[1], # <<<<<<<<<<<<<< - * tf_obj.field_ids[i], tf_obj.weight_field_ids[i], - * tf_obj.weight_table_ids[i], - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__tables); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__x_bounds); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_11 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":163 - * tf_obj.tables[i].x_bounds[0], - * tf_obj.tables[i].x_bounds[1], - * tf_obj.field_ids[i], tf_obj.weight_field_ids[i], # <<<<<<<<<<<<<< - * tf_obj.weight_table_ids[i], - * tf_obj.tables[i].pass_through) - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__field_ids); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__weight_field_ids); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_12 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":164 - * tf_obj.tables[i].x_bounds[1], - * tf_obj.field_ids[i], tf_obj.weight_field_ids[i], - * tf_obj.weight_table_ids[i], # <<<<<<<<<<<<<< - * tf_obj.tables[i].pass_through) - * self.my_field_tables.append((tf_obj.tables[i], - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__weight_table_ids); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":165 - * tf_obj.field_ids[i], tf_obj.weight_field_ids[i], - * tf_obj.weight_table_ids[i], - * tf_obj.tables[i].pass_through) # <<<<<<<<<<<<<< - * self.my_field_tables.append((tf_obj.tables[i], - * tf_obj.tables[i].y)) - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__tables); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__pass_through); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_15.__pyx_n = 3; - __pyx_t_15.weight_field_id = __pyx_t_12; - __pyx_t_15.weight_table_id = __pyx_t_13; - __pyx_t_15.pass_through = __pyx_t_14; - __pyx_f_2yt_9amr_utils_FIT_initialize_table((&(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_tables[__pyx_v_i])), (__pyx_v_temp->dimensions[0]), ((__pyx_t_5numpy_float64_t *)__pyx_v_temp->data), __pyx_t_10, __pyx_t_11, __pyx_t_6, &__pyx_t_15); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":166 - * tf_obj.weight_table_ids[i], - * tf_obj.tables[i].pass_through) - * self.my_field_tables.append((tf_obj.tables[i], # <<<<<<<<<<<<<< - * tf_obj.tables[i].y)) - * self.field_tables[i].field_id = tf_obj.field_ids[i] - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__tables); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":167 - * tf_obj.tables[i].pass_through) - * self.my_field_tables.append((tf_obj.tables[i], - * tf_obj.tables[i].y)) # <<<<<<<<<<<<<< - * self.field_tables[i].field_id = tf_obj.field_ids[i] - * self.field_tables[i].weight_field_id = tf_obj.weight_field_ids[i] - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__tables); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_16) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_16, __pyx_n_s__y); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->my_field_tables, __pyx_t_16); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":168 - * self.my_field_tables.append((tf_obj.tables[i], - * tf_obj.tables[i].y)) - * self.field_tables[i].field_id = tf_obj.field_ids[i] # <<<<<<<<<<<<<< - * self.field_tables[i].weight_field_id = tf_obj.weight_field_ids[i] - * print "Field table", i, "corresponds to", - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__field_ids); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_16) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_16); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - (((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_tables[__pyx_v_i]).field_id = __pyx_t_14; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":169 - * tf_obj.tables[i].y)) - * self.field_tables[i].field_id = tf_obj.field_ids[i] - * self.field_tables[i].weight_field_id = tf_obj.weight_field_ids[i] # <<<<<<<<<<<<<< - * print "Field table", i, "corresponds to", - * print self.field_tables[i].field_id, - */ - __pyx_t_16 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__weight_field_ids); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_16, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_14 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - (((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_tables[__pyx_v_i]).weight_field_id = __pyx_t_14; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":170 - * self.field_tables[i].field_id = tf_obj.field_ids[i] - * self.field_tables[i].weight_field_id = tf_obj.weight_field_ids[i] - * print "Field table", i, "corresponds to", # <<<<<<<<<<<<<< - * print self.field_tables[i].field_id, - * print "(Weighted with ", self.field_tables[i].weight_field_id, - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_16 = PyTuple_New(3); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_t_16, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_4)); - PyTuple_SET_ITEM(__pyx_t_16, 2, ((PyObject *)__pyx_kp_s_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4)); - __pyx_t_4 = 0; - if (__Pyx_Print(0, __pyx_t_16, 0) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":171 - * self.field_tables[i].weight_field_id = tf_obj.weight_field_ids[i] - * print "Field table", i, "corresponds to", - * print self.field_tables[i].field_id, # <<<<<<<<<<<<<< - * print "(Weighted with ", self.field_tables[i].weight_field_id, - * print ")" - */ - __pyx_t_16 = PyInt_FromLong((((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_tables[__pyx_v_i]).field_id); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_16); - __Pyx_GIVEREF(__pyx_t_16); - __pyx_t_16 = 0; - if (__Pyx_Print(0, __pyx_t_4, 0) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":172 - * print "Field table", i, "corresponds to", - * print self.field_tables[i].field_id, - * print "(Weighted with ", self.field_tables[i].weight_field_id, # <<<<<<<<<<<<<< - * print ")" - * - */ - __pyx_t_4 = PyInt_FromLong((((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_tables[__pyx_v_i]).weight_field_id); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_5)); - PyTuple_SET_ITEM(__pyx_t_16, 0, ((PyObject *)__pyx_kp_s_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_5)); - PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - if (__Pyx_Print(0, __pyx_t_16, 0) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":173 - * print self.field_tables[i].field_id, - * print "(Weighted with ", self.field_tables[i].weight_field_id, - * print ")" # <<<<<<<<<<<<<< - * - * for i in range(6): - */ - if (__Pyx_PrintOne(0, ((PyObject *)__pyx_kp_s_6)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":175 - * print ")" - * - * for i in range(6): # <<<<<<<<<<<<<< - * self.field_table_ids[i] = tf_obj.field_table_ids[i] - * print "Channel", i, "corresponds to", self.field_table_ids[i] - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 6; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":176 - * - * for i in range(6): - * self.field_table_ids[i] = tf_obj.field_table_ids[i] # <<<<<<<<<<<<<< - * print "Channel", i, "corresponds to", self.field_table_ids[i] - * - */ - __pyx_t_16 = PyObject_GetAttr(__pyx_v_tf_obj, __pyx_n_s__field_table_ids); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_16, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - (((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_table_ids[__pyx_v_i]) = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":177 - * for i in range(6): - * self.field_table_ids[i] = tf_obj.field_table_ids[i] - * print "Channel", i, "corresponds to", self.field_table_ids[i] # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_16 = PyInt_FromLong((((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_self)->field_table_ids[__pyx_v_i])); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__Channel)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__Channel)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Channel)); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_4)); - PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_kp_s_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4)); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_16); - __Pyx_GIVEREF(__pyx_t_16); - __pyx_t_4 = 0; - __pyx_t_16 = 0; - if (__Pyx_Print(0, __pyx_t_1, 1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_16); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_temp); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.TransferFunctionProxy.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_temp); - __pyx_L2:; - __Pyx_DECREF((PyObject *)__pyx_v_temp); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":181 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef void eval_transfer(self, np.float64_t dt, np.float64_t *dvs, # <<<<<<<<<<<<<< - * np.float64_t *rgba, np.float64_t *grad): - * cdef int i, fid, use - */ - -static void __pyx_f_2yt_9amr_utils_21TransferFunctionProxy_eval_transfer(struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *__pyx_v_self, __pyx_t_5numpy_float64_t __pyx_v_dt, __pyx_t_5numpy_float64_t *__pyx_v_dvs, __pyx_t_5numpy_float64_t *__pyx_v_rgba, __pyx_t_5numpy_float64_t *__pyx_v_grad) { - int __pyx_v_i; - int __pyx_v_fid; - __pyx_t_5numpy_float64_t __pyx_v_ta; - __pyx_t_5numpy_float64_t __pyx_v_trgba[6]; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("eval_transfer"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":194 - * # use = 1 - * # break - * for i in range(self.n_field_tables): # <<<<<<<<<<<<<< - * self.istorage[i] = FIT_get_value(&self.field_tables[i], dvs) - * # We have to do this after the interpolation - */ - __pyx_t_1 = __pyx_v_self->n_field_tables; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":195 - * # break - * for i in range(self.n_field_tables): - * self.istorage[i] = FIT_get_value(&self.field_tables[i], dvs) # <<<<<<<<<<<<<< - * # We have to do this after the interpolation - * for i in range(self.n_field_tables): - */ - (__pyx_v_self->istorage[__pyx_v_i]) = __pyx_f_2yt_9amr_utils_FIT_get_value((&(__pyx_v_self->field_tables[__pyx_v_i])), __pyx_v_dvs); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":197 - * self.istorage[i] = FIT_get_value(&self.field_tables[i], dvs) - * # We have to do this after the interpolation - * for i in range(self.n_field_tables): # <<<<<<<<<<<<<< - * fid = self.field_tables[i].weight_table_id - * if fid != -1: self.istorage[i] *= self.istorage[fid] - */ - __pyx_t_1 = __pyx_v_self->n_field_tables; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":198 - * # We have to do this after the interpolation - * for i in range(self.n_field_tables): - * fid = self.field_tables[i].weight_table_id # <<<<<<<<<<<<<< - * if fid != -1: self.istorage[i] *= self.istorage[fid] - * for i in range(6): - */ - __pyx_v_fid = (__pyx_v_self->field_tables[__pyx_v_i]).weight_table_id; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":199 - * for i in range(self.n_field_tables): - * fid = self.field_tables[i].weight_table_id - * if fid != -1: self.istorage[i] *= self.istorage[fid] # <<<<<<<<<<<<<< - * for i in range(6): - * trgba[i] = self.istorage[self.field_table_ids[i]] - */ - __pyx_t_3 = (__pyx_v_fid != -1); - if (__pyx_t_3) { - (__pyx_v_self->istorage[__pyx_v_i]) *= (__pyx_v_self->istorage[__pyx_v_fid]); - goto __pyx_L7; - } - __pyx_L7:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":200 - * fid = self.field_tables[i].weight_table_id - * if fid != -1: self.istorage[i] *= self.istorage[fid] - * for i in range(6): # <<<<<<<<<<<<<< - * trgba[i] = self.istorage[self.field_table_ids[i]] - * #print i, trgba[i], - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 6; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":201 - * if fid != -1: self.istorage[i] *= self.istorage[fid] - * for i in range(6): - * trgba[i] = self.istorage[self.field_table_ids[i]] # <<<<<<<<<<<<<< - * #print i, trgba[i], - * #print - */ - (__pyx_v_trgba[__pyx_v_i]) = (__pyx_v_self->istorage[(__pyx_v_self->field_table_ids[__pyx_v_i])]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":211 - * # integration here: - * # I_{i+1} = ds * C_i + (1.0 - ds*alpha_i) * I_i - * for i in range(3): # <<<<<<<<<<<<<< - * # This is the new way: alpha corresponds to opacity of a given - * # slice. Previously it was ill-defined, but represented some - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":215 - * # slice. Previously it was ill-defined, but represented some - * # measure of emissivity. - * ta = fmax((1.0 - dt*trgba[i+3]), 0.0) # <<<<<<<<<<<<<< - * rgba[i ] = dt*trgba[i ] + ta * rgba[i ] - * #rgba[i+3] = dt*trgba[i+3] + ta * rgba[i+3] - */ - __pyx_v_ta = __pyx_f_2yt_9amr_utils_fmax((1.0 - (__pyx_v_dt * (__pyx_v_trgba[(__pyx_v_i + 3)]))), 0.0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":216 - * # measure of emissivity. - * ta = fmax((1.0 - dt*trgba[i+3]), 0.0) - * rgba[i ] = dt*trgba[i ] + ta * rgba[i ] # <<<<<<<<<<<<<< - * #rgba[i+3] = dt*trgba[i+3] + ta * rgba[i+3] - * # This is the old way: - */ - (__pyx_v_rgba[__pyx_v_i]) = ((__pyx_v_dt * (__pyx_v_trgba[__pyx_v_i])) + (__pyx_v_ta * (__pyx_v_rgba[__pyx_v_i]))); - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":223 - * - * cdef class VectorPlane: - * cdef public object avp_pos, avp_dir, acenter, aimage # <<<<<<<<<<<<<< - * cdef np.float64_t *vp_pos, *vp_dir, *center, *image, - * cdef np.float64_t pdx, pdy, bounds[4] - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":230 - * cdef int im_strides[3] - * cdef int vd_strides[3] - * cdef public object ax_vec, ay_vec # <<<<<<<<<<<<<< - * cdef np.float64_t *x_vec, *y_vec - * - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":233 - * cdef np.float64_t *x_vec, *y_vec - * - * def __cinit__(self, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=3] vp_pos, - * np.ndarray vp_dir, - */ - -static int __pyx_pf_2yt_9amr_utils_11VectorPlane___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_11VectorPlane___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_vp_pos = 0; - PyArrayObject *__pyx_v_vp_dir = 0; - PyArrayObject *__pyx_v_center = 0; - PyObject *__pyx_v_bounds = 0; - PyArrayObject *__pyx_v_image = 0; - PyArrayObject *__pyx_v_x_vec = 0; - PyArrayObject *__pyx_v_y_vec = 0; - int __pyx_v_i; - Py_buffer __pyx_bstruct_center; - Py_ssize_t __pyx_bstride_0_center = 0; - Py_ssize_t __pyx_bshape_0_center = 0; - Py_buffer __pyx_bstruct_x_vec; - Py_ssize_t __pyx_bstride_0_x_vec = 0; - Py_ssize_t __pyx_bshape_0_x_vec = 0; - Py_buffer __pyx_bstruct_y_vec; - Py_ssize_t __pyx_bstride_0_y_vec = 0; - Py_ssize_t __pyx_bshape_0_y_vec = 0; - Py_buffer __pyx_bstruct_image; - Py_ssize_t __pyx_bstride_0_image = 0; - Py_ssize_t __pyx_bstride_1_image = 0; - Py_ssize_t __pyx_bstride_2_image = 0; - Py_ssize_t __pyx_bshape_0_image = 0; - Py_ssize_t __pyx_bshape_1_image = 0; - Py_ssize_t __pyx_bshape_2_image = 0; - Py_buffer __pyx_bstruct_vp_pos; - Py_ssize_t __pyx_bstride_0_vp_pos = 0; - Py_ssize_t __pyx_bstride_1_vp_pos = 0; - Py_ssize_t __pyx_bstride_2_vp_pos = 0; - Py_ssize_t __pyx_bshape_0_vp_pos = 0; - Py_ssize_t __pyx_bshape_1_vp_pos = 0; - Py_ssize_t __pyx_bshape_2_vp_pos = 0; - int __pyx_r; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - __pyx_t_5numpy_float64_t __pyx_t_3; - int __pyx_t_4; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__vp_pos,&__pyx_n_s__vp_dir,&__pyx_n_s__center,&__pyx_n_s__bounds,&__pyx_n_s__image,&__pyx_n_s__x_vec,&__pyx_n_s__y_vec,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[7] = {0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__vp_pos); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__vp_dir); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__center); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bounds); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, 3); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__image); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, 4); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x_vec); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, 5); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y_vec); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, 6); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_vp_pos = ((PyArrayObject *)values[0]); - __pyx_v_vp_dir = ((PyArrayObject *)values[1]); - __pyx_v_center = ((PyArrayObject *)values[2]); - __pyx_v_bounds = values[3]; - __pyx_v_image = ((PyArrayObject *)values[4]); - __pyx_v_x_vec = ((PyArrayObject *)values[5]); - __pyx_v_y_vec = ((PyArrayObject *)values[6]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_vp_pos = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_vp_dir = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_center = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_bounds = PyTuple_GET_ITEM(__pyx_args, 3); - __pyx_v_image = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_x_vec = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_y_vec = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.VectorPlane.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_vp_pos.buf = NULL; - __pyx_bstruct_center.buf = NULL; - __pyx_bstruct_image.buf = NULL; - __pyx_bstruct_x_vec.buf = NULL; - __pyx_bstruct_y_vec.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vp_pos), __pyx_ptype_5numpy_ndarray, 1, "vp_pos", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vp_dir), __pyx_ptype_5numpy_ndarray, 1, "vp_dir", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_center), __pyx_ptype_5numpy_ndarray, 1, "center", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_image), __pyx_ptype_5numpy_ndarray, 1, "image", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x_vec), __pyx_ptype_5numpy_ndarray, 1, "x_vec", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y_vec), __pyx_ptype_5numpy_ndarray, 1, "y_vec", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_vp_pos, (PyObject*)__pyx_v_vp_pos, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_vp_pos = __pyx_bstruct_vp_pos.strides[0]; __pyx_bstride_1_vp_pos = __pyx_bstruct_vp_pos.strides[1]; __pyx_bstride_2_vp_pos = __pyx_bstruct_vp_pos.strides[2]; - __pyx_bshape_0_vp_pos = __pyx_bstruct_vp_pos.shape[0]; __pyx_bshape_1_vp_pos = __pyx_bstruct_vp_pos.shape[1]; __pyx_bshape_2_vp_pos = __pyx_bstruct_vp_pos.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_center, (PyObject*)__pyx_v_center, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_center = __pyx_bstruct_center.strides[0]; - __pyx_bshape_0_center = __pyx_bstruct_center.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_image, (PyObject*)__pyx_v_image, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_image = __pyx_bstruct_image.strides[0]; __pyx_bstride_1_image = __pyx_bstruct_image.strides[1]; __pyx_bstride_2_image = __pyx_bstruct_image.strides[2]; - __pyx_bshape_0_image = __pyx_bstruct_image.shape[0]; __pyx_bshape_1_image = __pyx_bstruct_image.shape[1]; __pyx_bshape_2_image = __pyx_bstruct_image.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x_vec, (PyObject*)__pyx_v_x_vec, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x_vec = __pyx_bstruct_x_vec.strides[0]; - __pyx_bshape_0_x_vec = __pyx_bstruct_x_vec.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y_vec, (PyObject*)__pyx_v_y_vec, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y_vec = __pyx_bstruct_y_vec.strides[0]; - __pyx_bshape_0_y_vec = __pyx_bstruct_y_vec.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":242 - * np.ndarray[np.float64_t, ndim=1] y_vec): - * cdef int i, j - * self.avp_pos = vp_pos # <<<<<<<<<<<<<< - * self.avp_dir = vp_dir - * self.acenter = center - */ - __Pyx_INCREF(((PyObject *)__pyx_v_vp_pos)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_vp_pos)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_pos = ((PyObject *)__pyx_v_vp_pos); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":243 - * cdef int i, j - * self.avp_pos = vp_pos - * self.avp_dir = vp_dir # <<<<<<<<<<<<<< - * self.acenter = center - * self.aimage = image - */ - __Pyx_INCREF(((PyObject *)__pyx_v_vp_dir)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_vp_dir)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->avp_dir = ((PyObject *)__pyx_v_vp_dir); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":244 - * self.avp_pos = vp_pos - * self.avp_dir = vp_dir - * self.acenter = center # <<<<<<<<<<<<<< - * self.aimage = image - * self.ax_vec = x_vec - */ - __Pyx_INCREF(((PyObject *)__pyx_v_center)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_center)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->acenter = ((PyObject *)__pyx_v_center); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":245 - * self.avp_dir = vp_dir - * self.acenter = center - * self.aimage = image # <<<<<<<<<<<<<< - * self.ax_vec = x_vec - * self.ay_vec = y_vec - */ - __Pyx_INCREF(((PyObject *)__pyx_v_image)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_image)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->aimage = ((PyObject *)__pyx_v_image); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":246 - * self.acenter = center - * self.aimage = image - * self.ax_vec = x_vec # <<<<<<<<<<<<<< - * self.ay_vec = y_vec - * self.vp_pos = vp_pos.data - */ - __Pyx_INCREF(((PyObject *)__pyx_v_x_vec)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_x_vec)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ax_vec = ((PyObject *)__pyx_v_x_vec); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":247 - * self.aimage = image - * self.ax_vec = x_vec - * self.ay_vec = y_vec # <<<<<<<<<<<<<< - * self.vp_pos = vp_pos.data - * self.vp_dir = vp_dir.data - */ - __Pyx_INCREF(((PyObject *)__pyx_v_y_vec)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_y_vec)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec); - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->ay_vec = ((PyObject *)__pyx_v_y_vec); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":248 - * self.ax_vec = x_vec - * self.ay_vec = y_vec - * self.vp_pos = vp_pos.data # <<<<<<<<<<<<<< - * self.vp_dir = vp_dir.data - * self.center = center.data - */ - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vp_pos = ((__pyx_t_5numpy_float64_t *)__pyx_v_vp_pos->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":249 - * self.ay_vec = y_vec - * self.vp_pos = vp_pos.data - * self.vp_dir = vp_dir.data # <<<<<<<<<<<<<< - * self.center = center.data - * self.image = image.data - */ - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vp_dir = ((__pyx_t_5numpy_float64_t *)__pyx_v_vp_dir->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":250 - * self.vp_pos = vp_pos.data - * self.vp_dir = vp_dir.data - * self.center = center.data # <<<<<<<<<<<<<< - * self.image = image.data - * self.x_vec = x_vec.data - */ - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->center = ((__pyx_t_5numpy_float64_t *)__pyx_v_center->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":251 - * self.vp_dir = vp_dir.data - * self.center = center.data - * self.image = image.data # <<<<<<<<<<<<<< - * self.x_vec = x_vec.data - * self.y_vec = y_vec.data - */ - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->image = ((__pyx_t_5numpy_float64_t *)__pyx_v_image->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":252 - * self.center = center.data - * self.image = image.data - * self.x_vec = x_vec.data # <<<<<<<<<<<<<< - * self.y_vec = y_vec.data - * self.nv[0] = vp_pos.shape[0] - */ - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->x_vec = ((__pyx_t_5numpy_float64_t *)__pyx_v_x_vec->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":253 - * self.image = image.data - * self.x_vec = x_vec.data - * self.y_vec = y_vec.data # <<<<<<<<<<<<<< - * self.nv[0] = vp_pos.shape[0] - * self.nv[1] = vp_pos.shape[1] - */ - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->y_vec = ((__pyx_t_5numpy_float64_t *)__pyx_v_y_vec->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":254 - * self.x_vec = x_vec.data - * self.y_vec = y_vec.data - * self.nv[0] = vp_pos.shape[0] # <<<<<<<<<<<<<< - * self.nv[1] = vp_pos.shape[1] - * for i in range(4): self.bounds[i] = bounds[i] - */ - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->nv[0]) = (__pyx_v_vp_pos->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":255 - * self.y_vec = y_vec.data - * self.nv[0] = vp_pos.shape[0] - * self.nv[1] = vp_pos.shape[1] # <<<<<<<<<<<<<< - * for i in range(4): self.bounds[i] = bounds[i] - * self.pdx = (self.bounds[1] - self.bounds[0])/self.nv[0] - */ - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->nv[1]) = (__pyx_v_vp_pos->dimensions[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":256 - * self.nv[0] = vp_pos.shape[0] - * self.nv[1] = vp_pos.shape[1] - * for i in range(4): self.bounds[i] = bounds[i] # <<<<<<<<<<<<<< - * self.pdx = (self.bounds[1] - self.bounds[0])/self.nv[0] - * self.pdy = (self.bounds[3] - self.bounds[2])/self.nv[1] - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 4; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_bounds, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_3 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->bounds[__pyx_v_i]) = __pyx_t_3; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":257 - * self.nv[1] = vp_pos.shape[1] - * for i in range(4): self.bounds[i] = bounds[i] - * self.pdx = (self.bounds[1] - self.bounds[0])/self.nv[0] # <<<<<<<<<<<<<< - * self.pdy = (self.bounds[3] - self.bounds[2])/self.nv[1] - * for i in range(3): - */ - __pyx_t_3 = ((((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->bounds[1]) - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->bounds[0])); - __pyx_t_1 = (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->nv[0]); - if (unlikely(__pyx_t_1 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->pdx = (__pyx_t_3 / __pyx_t_1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":258 - * for i in range(4): self.bounds[i] = bounds[i] - * self.pdx = (self.bounds[1] - self.bounds[0])/self.nv[0] - * self.pdy = (self.bounds[3] - self.bounds[2])/self.nv[1] # <<<<<<<<<<<<<< - * for i in range(3): - * self.vp_strides[i] = vp_pos.strides[i] / 8 - */ - __pyx_t_3 = ((((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->bounds[3]) - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->bounds[2])); - __pyx_t_1 = (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->nv[1]); - if (unlikely(__pyx_t_1 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->pdy = (__pyx_t_3 / __pyx_t_1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":259 - * self.pdx = (self.bounds[1] - self.bounds[0])/self.nv[0] - * self.pdy = (self.bounds[3] - self.bounds[2])/self.nv[1] - * for i in range(3): # <<<<<<<<<<<<<< - * self.vp_strides[i] = vp_pos.strides[i] / 8 - * self.im_strides[i] = image.strides[i] / 8 - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":260 - * self.pdy = (self.bounds[3] - self.bounds[2])/self.nv[1] - * for i in range(3): - * self.vp_strides[i] = vp_pos.strides[i] / 8 # <<<<<<<<<<<<<< - * self.im_strides[i] = image.strides[i] / 8 - * if vp_dir.ndim > 1: - */ - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vp_strides[__pyx_v_i]) = __Pyx_div_long((__pyx_v_vp_pos->strides[__pyx_v_i]), 8); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":261 - * for i in range(3): - * self.vp_strides[i] = vp_pos.strides[i] / 8 - * self.im_strides[i] = image.strides[i] / 8 # <<<<<<<<<<<<<< - * if vp_dir.ndim > 1: - * for i in range(3): - */ - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->im_strides[__pyx_v_i]) = __Pyx_div_long((__pyx_v_image->strides[__pyx_v_i]), 8); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":262 - * self.vp_strides[i] = vp_pos.strides[i] / 8 - * self.im_strides[i] = image.strides[i] / 8 - * if vp_dir.ndim > 1: # <<<<<<<<<<<<<< - * for i in range(3): - * self.vd_strides[i] = vp_dir.strides[i] / 8 - */ - __pyx_t_4 = (__pyx_v_vp_dir->nd > 1); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":263 - * self.im_strides[i] = image.strides[i] / 8 - * if vp_dir.ndim > 1: - * for i in range(3): # <<<<<<<<<<<<<< - * self.vd_strides[i] = vp_dir.strides[i] / 8 - * else: - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":264 - * if vp_dir.ndim > 1: - * for i in range(3): - * self.vd_strides[i] = vp_dir.strides[i] / 8 # <<<<<<<<<<<<<< - * else: - * self.vd_strides[0] = self.vd_strides[1] = self.vd_strides[2] = -1 - */ - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vd_strides[__pyx_v_i]) = __Pyx_div_long((__pyx_v_vp_dir->strides[__pyx_v_i]), 8); - } - goto __pyx_L10; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":266 - * self.vd_strides[i] = vp_dir.strides[i] / 8 - * else: - * self.vd_strides[0] = self.vd_strides[1] = self.vd_strides[2] = -1 # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vd_strides[0]) = -1; - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vd_strides[1]) = -1; - (((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)__pyx_v_self)->vd_strides[2]) = -1; - } - __pyx_L10:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_center); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vec); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_vec); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_image); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_vp_pos); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.VectorPlane.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_center); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x_vec); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y_vec); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_image); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_vp_pos); - __pyx_L2:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":270 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef void get_start_stop(self, np.float64_t *ex, int *rv): # <<<<<<<<<<<<<< - * # Extrema need to be re-centered - * cdef np.float64_t cx, cy - */ - -static void __pyx_f_2yt_9amr_utils_11VectorPlane_get_start_stop(struct __pyx_obj_2yt_9amr_utils_VectorPlane *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_ex, int *__pyx_v_rv) { - __pyx_t_5numpy_float64_t __pyx_v_cx; - __pyx_t_5numpy_float64_t __pyx_v_cy; - int __pyx_v_i; - int __pyx_t_1; - __pyx_t_5numpy_float64_t __pyx_t_2; - __Pyx_RefNannySetupContext("get_start_stop"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":274 - * cdef np.float64_t cx, cy - * cdef int i - * cx = cy = 0.0 # <<<<<<<<<<<<<< - * for i in range(3): - * cx += self.center[i] * self.x_vec[i] - */ - __pyx_v_cx = 0.0; - __pyx_v_cy = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":275 - * cdef int i - * cx = cy = 0.0 - * for i in range(3): # <<<<<<<<<<<<<< - * cx += self.center[i] * self.x_vec[i] - * cy += self.center[i] * self.y_vec[i] - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":276 - * cx = cy = 0.0 - * for i in range(3): - * cx += self.center[i] * self.x_vec[i] # <<<<<<<<<<<<<< - * cy += self.center[i] * self.y_vec[i] - * rv[0] = lrint((ex[0] - cx - self.bounds[0])/self.pdx) - */ - __pyx_v_cx += ((__pyx_v_self->center[__pyx_v_i]) * (__pyx_v_self->x_vec[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":277 - * for i in range(3): - * cx += self.center[i] * self.x_vec[i] - * cy += self.center[i] * self.y_vec[i] # <<<<<<<<<<<<<< - * rv[0] = lrint((ex[0] - cx - self.bounds[0])/self.pdx) - * rv[1] = rv[0] + lrint((ex[1] - ex[0])/self.pdx) - */ - __pyx_v_cy += ((__pyx_v_self->center[__pyx_v_i]) * (__pyx_v_self->y_vec[__pyx_v_i])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":278 - * cx += self.center[i] * self.x_vec[i] - * cy += self.center[i] * self.y_vec[i] - * rv[0] = lrint((ex[0] - cx - self.bounds[0])/self.pdx) # <<<<<<<<<<<<<< - * rv[1] = rv[0] + lrint((ex[1] - ex[0])/self.pdx) - * rv[2] = lrint((ex[2] - cy - self.bounds[2])/self.pdy) - */ - __pyx_t_2 = (((__pyx_v_ex[0]) - __pyx_v_cx) - (__pyx_v_self->bounds[0])); - if (unlikely(__pyx_v_self->pdx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_rv[0]) = lrint((__pyx_t_2 / __pyx_v_self->pdx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":279 - * cy += self.center[i] * self.y_vec[i] - * rv[0] = lrint((ex[0] - cx - self.bounds[0])/self.pdx) - * rv[1] = rv[0] + lrint((ex[1] - ex[0])/self.pdx) # <<<<<<<<<<<<<< - * rv[2] = lrint((ex[2] - cy - self.bounds[2])/self.pdy) - * rv[3] = rv[2] + lrint((ex[3] - ex[2])/self.pdy) - */ - __pyx_t_2 = ((__pyx_v_ex[1]) - (__pyx_v_ex[0])); - if (unlikely(__pyx_v_self->pdx == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_rv[1]) = ((__pyx_v_rv[0]) + lrint((__pyx_t_2 / __pyx_v_self->pdx))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":280 - * rv[0] = lrint((ex[0] - cx - self.bounds[0])/self.pdx) - * rv[1] = rv[0] + lrint((ex[1] - ex[0])/self.pdx) - * rv[2] = lrint((ex[2] - cy - self.bounds[2])/self.pdy) # <<<<<<<<<<<<<< - * rv[3] = rv[2] + lrint((ex[3] - ex[2])/self.pdy) - * - */ - __pyx_t_2 = (((__pyx_v_ex[2]) - __pyx_v_cy) - (__pyx_v_self->bounds[2])); - if (unlikely(__pyx_v_self->pdy == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_rv[2]) = lrint((__pyx_t_2 / __pyx_v_self->pdy)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":281 - * rv[1] = rv[0] + lrint((ex[1] - ex[0])/self.pdx) - * rv[2] = lrint((ex[2] - cy - self.bounds[2])/self.pdy) - * rv[3] = rv[2] + lrint((ex[3] - ex[2])/self.pdy) # <<<<<<<<<<<<<< - * - * cdef inline void copy_into(self, np.float64_t *fv, np.float64_t *tv, - */ - __pyx_t_2 = ((__pyx_v_ex[3]) - (__pyx_v_ex[2])); - if (unlikely(__pyx_v_self->pdy == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_rv[3]) = ((__pyx_v_rv[2]) + lrint((__pyx_t_2 / __pyx_v_self->pdy))); - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("yt.amr_utils.VectorPlane.get_start_stop"); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":283 - * rv[3] = rv[2] + lrint((ex[3] - ex[2])/self.pdy) - * - * cdef inline void copy_into(self, np.float64_t *fv, np.float64_t *tv, # <<<<<<<<<<<<<< - * int i, int j, int nk, int strides[3]): - * # We know the first two dimensions of our from-vector, and our - */ - -static CYTHON_INLINE void __pyx_f_2yt_9amr_utils_11VectorPlane_copy_into(struct __pyx_obj_2yt_9amr_utils_VectorPlane *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_fv, __pyx_t_5numpy_float64_t *__pyx_v_tv, int __pyx_v_i, int __pyx_v_j, int __pyx_v_nk, int *__pyx_v_strides) { - int __pyx_v_k; - int __pyx_v_offset; - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("copy_into"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":288 - * # to-vector is flat and 'ni' long - * cdef int k - * cdef int offset = strides[0] * i + strides[1] * j # <<<<<<<<<<<<<< - * for k in range(nk): - * tv[k] = fv[offset + k] - */ - __pyx_v_offset = (((__pyx_v_strides[0]) * __pyx_v_i) + ((__pyx_v_strides[1]) * __pyx_v_j)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":289 - * cdef int k - * cdef int offset = strides[0] * i + strides[1] * j - * for k in range(nk): # <<<<<<<<<<<<<< - * tv[k] = fv[offset + k] - * - */ - __pyx_t_1 = __pyx_v_nk; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_k = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":290 - * cdef int offset = strides[0] * i + strides[1] * j - * for k in range(nk): - * tv[k] = fv[offset + k] # <<<<<<<<<<<<<< - * - * cdef inline void copy_back(self, np.float64_t *fv, np.float64_t *tv, - */ - (__pyx_v_tv[__pyx_v_k]) = (__pyx_v_fv[(__pyx_v_offset + __pyx_v_k)]); - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":292 - * tv[k] = fv[offset + k] - * - * cdef inline void copy_back(self, np.float64_t *fv, np.float64_t *tv, # <<<<<<<<<<<<<< - * int i, int j, int nk, int strides[3]): - * cdef int k - */ - -static CYTHON_INLINE void __pyx_f_2yt_9amr_utils_11VectorPlane_copy_back(struct __pyx_obj_2yt_9amr_utils_VectorPlane *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_fv, __pyx_t_5numpy_float64_t *__pyx_v_tv, int __pyx_v_i, int __pyx_v_j, int __pyx_v_nk, int *__pyx_v_strides) { - int __pyx_v_k; - int __pyx_v_offset; - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("copy_back"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":295 - * int i, int j, int nk, int strides[3]): - * cdef int k - * cdef int offset = strides[0] * i + strides[1] * j # <<<<<<<<<<<<<< - * for k in range(nk): - * tv[offset + k] = fv[k] - */ - __pyx_v_offset = (((__pyx_v_strides[0]) * __pyx_v_i) + ((__pyx_v_strides[1]) * __pyx_v_j)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":296 - * cdef int k - * cdef int offset = strides[0] * i + strides[1] * j - * for k in range(nk): # <<<<<<<<<<<<<< - * tv[offset + k] = fv[k] - * - */ - __pyx_t_1 = __pyx_v_nk; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_k = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":297 - * cdef int offset = strides[0] * i + strides[1] * j - * for k in range(nk): - * tv[offset + k] = fv[k] # <<<<<<<<<<<<<< - * - * cdef class PartitionedGrid: - */ - (__pyx_v_tv[(__pyx_v_offset + __pyx_v_k)]) = (__pyx_v_fv[__pyx_v_k]); - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":300 - * - * cdef class PartitionedGrid: - * cdef public object my_data # <<<<<<<<<<<<<< - * cdef public object LeftEdge - * cdef public object RightEdge - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":301 - * cdef class PartitionedGrid: - * cdef public object my_data - * cdef public object LeftEdge # <<<<<<<<<<<<<< - * cdef public object RightEdge - * cdef np.float64_t *data[6] - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":302 - * cdef public object my_data - * cdef public object LeftEdge - * cdef public object RightEdge # <<<<<<<<<<<<<< - * cdef np.float64_t *data[6] - * cdef np.float64_t dvs[6] - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":310 - * cdef np.float64_t idds[3] - * cdef int dims[3] - * cdef public int parent_grid_id # <<<<<<<<<<<<<< - * cdef public int n_fields - * - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_14parent_grid_id___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_14parent_grid_id___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->parent_grid_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.parent_grid_id.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_14parent_grid_id___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_14parent_grid_id___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->parent_grid_id = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.parent_grid_id.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":311 - * cdef int dims[3] - * cdef public int parent_grid_id - * cdef public int n_fields # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_8n_fields___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_8n_fields___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->n_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.n_fields.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8n_fields___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8n_fields___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->n_fields = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.n_fields.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":315 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def __cinit__(self, # <<<<<<<<<<<<<< - * int parent_grid_id, int n_fields, data, - * np.ndarray[np.float64_t, ndim=1] left_edge, - */ - -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_15PartitionedGrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_parent_grid_id; - int __pyx_v_n_fields; - PyObject *__pyx_v_data = 0; - PyArrayObject *__pyx_v_left_edge = 0; - PyArrayObject *__pyx_v_right_edge = 0; - PyArrayObject *__pyx_v_dims = 0; - int __pyx_v_i; - PyArrayObject *__pyx_v_tdata; - Py_buffer __pyx_bstruct_tdata; - Py_ssize_t __pyx_bstride_0_tdata = 0; - Py_ssize_t __pyx_bstride_1_tdata = 0; - Py_ssize_t __pyx_bstride_2_tdata = 0; - Py_ssize_t __pyx_bshape_0_tdata = 0; - Py_ssize_t __pyx_bshape_1_tdata = 0; - Py_ssize_t __pyx_bshape_2_tdata = 0; - Py_buffer __pyx_bstruct_right_edge; - Py_ssize_t __pyx_bstride_0_right_edge = 0; - Py_ssize_t __pyx_bshape_0_right_edge = 0; - Py_buffer __pyx_bstruct_dims; - Py_ssize_t __pyx_bstride_0_dims = 0; - Py_ssize_t __pyx_bshape_0_dims = 0; - Py_buffer __pyx_bstruct_left_edge; - Py_ssize_t __pyx_bstride_0_left_edge = 0; - Py_ssize_t __pyx_bshape_0_left_edge = 0; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __pyx_t_5numpy_float64_t __pyx_t_5; - int __pyx_t_6; - __pyx_t_5numpy_int64_t __pyx_t_7; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyArrayObject *__pyx_t_10 = NULL; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__parent_grid_id,&__pyx_n_s__n_fields,&__pyx_n_s__data,&__pyx_n_s__left_edge,&__pyx_n_s__right_edge,&__pyx_n_s__dims,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[6] = {0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parent_grid_id); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_fields); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edge); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 3); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edge); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 4); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dims); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 5); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_parent_grid_id = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_parent_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_fields = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_n_fields == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_data = values[2]; - __pyx_v_left_edge = ((PyArrayObject *)values[3]); - __pyx_v_right_edge = ((PyArrayObject *)values[4]); - __pyx_v_dims = ((PyArrayObject *)values[5]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_parent_grid_id = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_parent_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_fields = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_n_fields == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_data = PyTuple_GET_ITEM(__pyx_args, 2); - __pyx_v_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_dims = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_v_tdata = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_tdata.buf = NULL; - __pyx_bstruct_left_edge.buf = NULL; - __pyx_bstruct_right_edge.buf = NULL; - __pyx_bstruct_dims.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edge), __pyx_ptype_5numpy_ndarray, 1, "left_edge", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edge), __pyx_ptype_5numpy_ndarray, 1, "right_edge", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 318; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dims), __pyx_ptype_5numpy_ndarray, 1, "dims", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 319; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edge, (PyObject*)__pyx_v_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edge = __pyx_bstruct_left_edge.strides[0]; - __pyx_bshape_0_left_edge = __pyx_bstruct_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edge, (PyObject*)__pyx_v_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edge = __pyx_bstruct_right_edge.strides[0]; - __pyx_bshape_0_right_edge = __pyx_bstruct_right_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dims, (PyObject*)__pyx_v_dims, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dims = __pyx_bstruct_dims.strides[0]; - __pyx_bshape_0_dims = __pyx_bstruct_dims.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":323 - * cdef int i, j, k, size - * cdef np.ndarray[np.float64_t, ndim=3] tdata - * self.parent_grid_id = parent_grid_id # <<<<<<<<<<<<<< - * self.LeftEdge = left_edge - * self.RightEdge = right_edge - */ - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->parent_grid_id = __pyx_v_parent_grid_id; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":324 - * cdef np.ndarray[np.float64_t, ndim=3] tdata - * self.parent_grid_id = parent_grid_id - * self.LeftEdge = left_edge # <<<<<<<<<<<<<< - * self.RightEdge = right_edge - * for i in range(3): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_left_edge)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_left_edge)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->LeftEdge = ((PyObject *)__pyx_v_left_edge); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":325 - * self.parent_grid_id = parent_grid_id - * self.LeftEdge = left_edge - * self.RightEdge = right_edge # <<<<<<<<<<<<<< - * for i in range(3): - * self.left_edge[i] = left_edge[i] - */ - __Pyx_INCREF(((PyObject *)__pyx_v_right_edge)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_right_edge)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->RightEdge = ((PyObject *)__pyx_v_right_edge); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":326 - * self.LeftEdge = left_edge - * self.RightEdge = right_edge - * for i in range(3): # <<<<<<<<<<<<<< - * self.left_edge[i] = left_edge[i] - * self.right_edge[i] = right_edge[i] - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":327 - * self.RightEdge = right_edge - * for i in range(3): - * self.left_edge[i] = left_edge[i] # <<<<<<<<<<<<<< - * self.right_edge[i] = right_edge[i] - * self.dims[i] = dims[i] - */ - __pyx_t_2 = __pyx_v_i; - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->left_edge[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_2, __pyx_bstride_0_left_edge)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":328 - * for i in range(3): - * self.left_edge[i] = left_edge[i] - * self.right_edge[i] = right_edge[i] # <<<<<<<<<<<<<< - * self.dims[i] = dims[i] - * self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] - */ - __pyx_t_3 = __pyx_v_i; - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->right_edge[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_3, __pyx_bstride_0_right_edge)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":329 - * self.left_edge[i] = left_edge[i] - * self.right_edge[i] = right_edge[i] - * self.dims[i] = dims[i] # <<<<<<<<<<<<<< - * self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] - * self.idds[i] = 1.0/self.dds[i] - */ - __pyx_t_4 = __pyx_v_i; - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->dims[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dims.buf, __pyx_t_4, __pyx_bstride_0_dims)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":330 - * self.right_edge[i] = right_edge[i] - * self.dims[i] = dims[i] - * self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] # <<<<<<<<<<<<<< - * self.idds[i] = 1.0/self.dds[i] - * self.my_data = data - */ - __pyx_t_5 = ((((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->right_edge[__pyx_v_i]) - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->left_edge[__pyx_v_i])); - __pyx_t_6 = __pyx_v_i; - __pyx_t_7 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dims.buf, __pyx_t_6, __pyx_bstride_0_dims)); - if (unlikely(__pyx_t_7 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->dds[__pyx_v_i]) = (__pyx_t_5 / __pyx_t_7); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":331 - * self.dims[i] = dims[i] - * self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] - * self.idds[i] = 1.0/self.dds[i] # <<<<<<<<<<<<<< - * self.my_data = data - * self.n_fields = n_fields - */ - __pyx_t_5 = (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->dds[__pyx_v_i]); - if (unlikely(__pyx_t_5 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->idds[__pyx_v_i]) = (1.0 / __pyx_t_5); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":332 - * self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] - * self.idds[i] = 1.0/self.dds[i] - * self.my_data = data # <<<<<<<<<<<<<< - * self.n_fields = n_fields - * for i in range(n_fields): - */ - __Pyx_INCREF(__pyx_v_data); - __Pyx_GIVEREF(__pyx_v_data); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data); - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->my_data = __pyx_v_data; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":333 - * self.idds[i] = 1.0/self.dds[i] - * self.my_data = data - * self.n_fields = n_fields # <<<<<<<<<<<<<< - * for i in range(n_fields): - * tdata = data[i] - */ - ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->n_fields = __pyx_v_n_fields; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":334 - * self.my_data = data - * self.n_fields = n_fields - * for i in range(n_fields): # <<<<<<<<<<<<<< - * tdata = data[i] - * self.data[i] = tdata.data - */ - __pyx_t_1 = __pyx_v_n_fields; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_1; __pyx_t_8+=1) { - __pyx_v_i = __pyx_t_8; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":335 - * self.n_fields = n_fields - * for i in range(n_fields): - * tdata = data[i] # <<<<<<<<<<<<<< - * self.data[i] = tdata.data - * - */ - __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_data, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = ((PyArrayObject *)__pyx_t_9); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tdata); - __pyx_t_11 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_tdata, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack); - if (unlikely(__pyx_t_11 < 0)) { - PyErr_Fetch(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_tdata, (PyObject*)__pyx_v_tdata, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_14); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_12, __pyx_t_13, __pyx_t_14); - } - } - __pyx_bstride_0_tdata = __pyx_bstruct_tdata.strides[0]; __pyx_bstride_1_tdata = __pyx_bstruct_tdata.strides[1]; __pyx_bstride_2_tdata = __pyx_bstruct_tdata.strides[2]; - __pyx_bshape_0_tdata = __pyx_bstruct_tdata.shape[0]; __pyx_bshape_1_tdata = __pyx_bstruct_tdata.shape[1]; __pyx_bshape_2_tdata = __pyx_bstruct_tdata.shape[2]; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_tdata)); - __pyx_v_tdata = ((PyArrayObject *)__pyx_t_9); - __pyx_t_9 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":336 - * for i in range(n_fields): - * tdata = data[i] - * self.data[i] = tdata.data # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - (((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->data[__pyx_v_i]) = ((__pyx_t_5numpy_float64_t *)__pyx_v_tdata->data); - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_9); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tdata); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dims); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tdata); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dims); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __pyx_L2:; - __Pyx_DECREF((PyObject *)__pyx_v_tdata); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":340 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def cast_plane(self, TransferFunctionProxy tf, VectorPlane vp): # <<<<<<<<<<<<<< - * # This routine will iterate over all of the vectors and cast each in - * # turn. Might benefit from a more sophisticated intersection check, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_cast_plane(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_15PartitionedGrid_cast_plane(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *__pyx_v_tf = 0; - struct __pyx_obj_2yt_9amr_utils_VectorPlane *__pyx_v_vp = 0; - int __pyx_v_vi; - int __pyx_v_vj; - int __pyx_v_hit; - int __pyx_v_iter[4]; - __pyx_t_5numpy_float64_t __pyx_v_v_pos[3]; - __pyx_t_5numpy_float64_t __pyx_v_v_dir[3]; - __pyx_t_5numpy_float64_t __pyx_v_rgba[6]; - __pyx_t_5numpy_float64_t __pyx_v_extrema[4]; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__tf,&__pyx_n_s__vp,0}; - __Pyx_RefNannySetupContext("cast_plane"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tf); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__vp); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("cast_plane", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "cast_plane") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_tf = ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)values[0]); - __pyx_v_vp = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)values[1]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_tf = ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_vp = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)PyTuple_GET_ITEM(__pyx_args, 1)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("cast_plane", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.cast_plane"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tf), __pyx_ptype_2yt_9amr_utils_TransferFunctionProxy, 1, "tf", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vp), __pyx_ptype_2yt_9amr_utils_VectorPlane, 1, "vp", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":347 - * cdef int iter[4] - * cdef np.float64_t v_pos[3], v_dir[3], rgba[6], extrema[4] - * hit = 0 # <<<<<<<<<<<<<< - * self.calculate_extent(vp, extrema) - * vp.get_start_stop(extrema, iter) - */ - __pyx_v_hit = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":348 - * cdef np.float64_t v_pos[3], v_dir[3], rgba[6], extrema[4] - * hit = 0 - * self.calculate_extent(vp, extrema) # <<<<<<<<<<<<<< - * vp.get_start_stop(extrema, iter) - * iter[0] = iclip(iter[0], 0, vp.nv[0]) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->__pyx_vtab)->calculate_extent(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self), __pyx_v_vp, __pyx_v_extrema); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":349 - * hit = 0 - * self.calculate_extent(vp, extrema) - * vp.get_start_stop(extrema, iter) # <<<<<<<<<<<<<< - * iter[0] = iclip(iter[0], 0, vp.nv[0]) - * iter[1] = iclip(iter[1], 0, vp.nv[0]) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->get_start_stop(__pyx_v_vp, __pyx_v_extrema, __pyx_v_iter); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":350 - * self.calculate_extent(vp, extrema) - * vp.get_start_stop(extrema, iter) - * iter[0] = iclip(iter[0], 0, vp.nv[0]) # <<<<<<<<<<<<<< - * iter[1] = iclip(iter[1], 0, vp.nv[0]) - * iter[2] = iclip(iter[2], 0, vp.nv[1]) - */ - (__pyx_v_iter[0]) = __pyx_f_2yt_9amr_utils_iclip((__pyx_v_iter[0]), 0, (__pyx_v_vp->nv[0])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":351 - * vp.get_start_stop(extrema, iter) - * iter[0] = iclip(iter[0], 0, vp.nv[0]) - * iter[1] = iclip(iter[1], 0, vp.nv[0]) # <<<<<<<<<<<<<< - * iter[2] = iclip(iter[2], 0, vp.nv[1]) - * iter[3] = iclip(iter[3], 0, vp.nv[1]) - */ - (__pyx_v_iter[1]) = __pyx_f_2yt_9amr_utils_iclip((__pyx_v_iter[1]), 0, (__pyx_v_vp->nv[0])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":352 - * iter[0] = iclip(iter[0], 0, vp.nv[0]) - * iter[1] = iclip(iter[1], 0, vp.nv[0]) - * iter[2] = iclip(iter[2], 0, vp.nv[1]) # <<<<<<<<<<<<<< - * iter[3] = iclip(iter[3], 0, vp.nv[1]) - * if vp.vd_strides[0] == -1: - */ - (__pyx_v_iter[2]) = __pyx_f_2yt_9amr_utils_iclip((__pyx_v_iter[2]), 0, (__pyx_v_vp->nv[1])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":353 - * iter[1] = iclip(iter[1], 0, vp.nv[0]) - * iter[2] = iclip(iter[2], 0, vp.nv[1]) - * iter[3] = iclip(iter[3], 0, vp.nv[1]) # <<<<<<<<<<<<<< - * if vp.vd_strides[0] == -1: - * for vi in range(iter[0], iter[1]): - */ - (__pyx_v_iter[3]) = __pyx_f_2yt_9amr_utils_iclip((__pyx_v_iter[3]), 0, (__pyx_v_vp->nv[1])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":354 - * iter[2] = iclip(iter[2], 0, vp.nv[1]) - * iter[3] = iclip(iter[3], 0, vp.nv[1]) - * if vp.vd_strides[0] == -1: # <<<<<<<<<<<<<< - * for vi in range(iter[0], iter[1]): - * for vj in range(iter[2], iter[3]): - */ - __pyx_t_1 = ((__pyx_v_vp->vd_strides[0]) == -1); - if (__pyx_t_1) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":355 - * iter[3] = iclip(iter[3], 0, vp.nv[1]) - * if vp.vd_strides[0] == -1: - * for vi in range(iter[0], iter[1]): # <<<<<<<<<<<<<< - * for vj in range(iter[2], iter[3]): - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - */ - __pyx_t_2 = (__pyx_v_iter[1]); - for (__pyx_t_3 = (__pyx_v_iter[0]); __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_vi = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":356 - * if vp.vd_strides[0] == -1: - * for vi in range(iter[0], iter[1]): - * for vj in range(iter[2], iter[3]): # <<<<<<<<<<<<<< - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - */ - __pyx_t_4 = (__pyx_v_iter[3]); - for (__pyx_t_5 = (__pyx_v_iter[2]); __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_vj = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":357 - * for vi in range(iter[0], iter[1]): - * for vj in range(iter[2], iter[3]): - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) # <<<<<<<<<<<<<< - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - * self.integrate_ray(v_pos, vp.vp_dir, rgba, tf) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_into(__pyx_v_vp, __pyx_v_vp->vp_pos, __pyx_v_v_pos, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->vp_strides); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":358 - * for vj in range(iter[2], iter[3]): - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) # <<<<<<<<<<<<<< - * self.integrate_ray(v_pos, vp.vp_dir, rgba, tf) - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_into(__pyx_v_vp, __pyx_v_vp->image, __pyx_v_rgba, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->im_strides); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":359 - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - * self.integrate_ray(v_pos, vp.vp_dir, rgba, tf) # <<<<<<<<<<<<<< - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - * else: - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->__pyx_vtab)->integrate_ray(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self), __pyx_v_v_pos, __pyx_v_vp->vp_dir, __pyx_v_rgba, __pyx_v_tf); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":360 - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - * self.integrate_ray(v_pos, vp.vp_dir, rgba, tf) - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) # <<<<<<<<<<<<<< - * else: - * # If we do not have an orthographic projection, we have to cast all - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_back(__pyx_v_vp, __pyx_v_rgba, __pyx_v_vp->image, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->im_strides); - } - } - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":364 - * # If we do not have an orthographic projection, we have to cast all - * # our rays (until we can get an extrema calculation...) - * for vi in range(vp.nv[0]): # <<<<<<<<<<<<<< - * for vj in range(vp.nv[1]): - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - */ - __pyx_t_2 = (__pyx_v_vp->nv[0]); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_vi = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":365 - * # our rays (until we can get an extrema calculation...) - * for vi in range(vp.nv[0]): - * for vj in range(vp.nv[1]): # <<<<<<<<<<<<<< - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - */ - __pyx_t_4 = (__pyx_v_vp->nv[1]); - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_vj = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":366 - * for vi in range(vp.nv[0]): - * for vj in range(vp.nv[1]): - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) # <<<<<<<<<<<<<< - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - * vp.copy_into(vp.vp_dir, v_dir, vi, vj, 3, vp.vd_strides) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_into(__pyx_v_vp, __pyx_v_vp->vp_pos, __pyx_v_v_pos, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->vp_strides); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":367 - * for vj in range(vp.nv[1]): - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) # <<<<<<<<<<<<<< - * vp.copy_into(vp.vp_dir, v_dir, vi, vj, 3, vp.vd_strides) - * self.integrate_ray(v_pos, v_dir, rgba, tf) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_into(__pyx_v_vp, __pyx_v_vp->image, __pyx_v_rgba, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->im_strides); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":368 - * vp.copy_into(vp.vp_pos, v_pos, vi, vj, 3, vp.vp_strides) - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - * vp.copy_into(vp.vp_dir, v_dir, vi, vj, 3, vp.vd_strides) # <<<<<<<<<<<<<< - * self.integrate_ray(v_pos, v_dir, rgba, tf) - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_into(__pyx_v_vp, __pyx_v_vp->vp_dir, __pyx_v_v_dir, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->vd_strides); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":369 - * vp.copy_into(vp.image, rgba, vi, vj, 3, vp.im_strides) - * vp.copy_into(vp.vp_dir, v_dir, vi, vj, 3, vp.vd_strides) - * self.integrate_ray(v_pos, v_dir, rgba, tf) # <<<<<<<<<<<<<< - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - * return hit - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self)->__pyx_vtab)->integrate_ray(((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self), __pyx_v_v_pos, __pyx_v_v_dir, __pyx_v_rgba, __pyx_v_tf); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":370 - * vp.copy_into(vp.vp_dir, v_dir, vi, vj, 3, vp.vd_strides) - * self.integrate_ray(v_pos, v_dir, rgba, tf) - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) # <<<<<<<<<<<<<< - * return hit - * - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane *)__pyx_v_vp->__pyx_vtab)->copy_back(__pyx_v_vp, __pyx_v_rgba, __pyx_v_vp->image, __pyx_v_vi, __pyx_v_vj, 3, __pyx_v_vp->im_strides); - } - } - } - __pyx_L6:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":371 - * self.integrate_ray(v_pos, v_dir, rgba, tf) - * vp.copy_back(rgba, vp.image, vi, vj, 3, vp.im_strides) - * return hit # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = PyInt_FromLong(__pyx_v_hit); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("yt.amr_utils.PartitionedGrid.cast_plane"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":375 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef void calculate_extent(self, VectorPlane vp, # <<<<<<<<<<<<<< - * np.float64_t extrema[4]): - * # We do this for all eight corners - */ - -static void __pyx_f_2yt_9amr_utils_15PartitionedGrid_calculate_extent(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *__pyx_v_self, struct __pyx_obj_2yt_9amr_utils_VectorPlane *__pyx_v_vp, __pyx_t_5numpy_float64_t *__pyx_v_extrema) { - __pyx_t_5numpy_float64_t *__pyx_v_edges[2]; - __pyx_t_5numpy_float64_t __pyx_v_temp; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_k; - double __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - __Pyx_RefNannySetupContext("calculate_extent"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":379 - * # We do this for all eight corners - * cdef np.float64_t *edges[2], temp - * edges[0] = self.left_edge # <<<<<<<<<<<<<< - * edges[1] = self.right_edge - * extrema[0] = extrema[2] = 1e300; extrema[1] = extrema[3] = -1e300 - */ - (__pyx_v_edges[0]) = __pyx_v_self->left_edge; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":380 - * cdef np.float64_t *edges[2], temp - * edges[0] = self.left_edge - * edges[1] = self.right_edge # <<<<<<<<<<<<<< - * extrema[0] = extrema[2] = 1e300; extrema[1] = extrema[3] = -1e300 - * cdef int i, j, k - */ - (__pyx_v_edges[1]) = __pyx_v_self->right_edge; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":381 - * edges[0] = self.left_edge - * edges[1] = self.right_edge - * extrema[0] = extrema[2] = 1e300; extrema[1] = extrema[3] = -1e300 # <<<<<<<<<<<<<< - * cdef int i, j, k - * for i in range(2): - */ - (__pyx_v_extrema[0]) = 1e300; - (__pyx_v_extrema[2]) = 1e300; - __pyx_t_1 = (-1e300); - (__pyx_v_extrema[1]) = __pyx_t_1; - (__pyx_v_extrema[3]) = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":383 - * extrema[0] = extrema[2] = 1e300; extrema[1] = extrema[3] = -1e300 - * cdef int i, j, k - * for i in range(2): # <<<<<<<<<<<<<< - * for j in range(2): - * for k in range(2): - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 2; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":384 - * cdef int i, j, k - * for i in range(2): - * for j in range(2): # <<<<<<<<<<<<<< - * for k in range(2): - * # This should rotate it into the vector plane - */ - for (__pyx_t_3 = 0; __pyx_t_3 < 2; __pyx_t_3+=1) { - __pyx_v_j = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":385 - * for i in range(2): - * for j in range(2): - * for k in range(2): # <<<<<<<<<<<<<< - * # This should rotate it into the vector plane - * temp = edges[i][0] * vp.x_vec[0] - */ - for (__pyx_t_4 = 0; __pyx_t_4 < 2; __pyx_t_4+=1) { - __pyx_v_k = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":387 - * for k in range(2): - * # This should rotate it into the vector plane - * temp = edges[i][0] * vp.x_vec[0] # <<<<<<<<<<<<<< - * temp += edges[j][1] * vp.x_vec[1] - * temp += edges[k][2] * vp.x_vec[2] - */ - __pyx_v_temp = (((__pyx_v_edges[__pyx_v_i])[0]) * (__pyx_v_vp->x_vec[0])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":388 - * # This should rotate it into the vector plane - * temp = edges[i][0] * vp.x_vec[0] - * temp += edges[j][1] * vp.x_vec[1] # <<<<<<<<<<<<<< - * temp += edges[k][2] * vp.x_vec[2] - * if temp < extrema[0]: extrema[0] = temp - */ - __pyx_v_temp += (((__pyx_v_edges[__pyx_v_j])[1]) * (__pyx_v_vp->x_vec[1])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":389 - * temp = edges[i][0] * vp.x_vec[0] - * temp += edges[j][1] * vp.x_vec[1] - * temp += edges[k][2] * vp.x_vec[2] # <<<<<<<<<<<<<< - * if temp < extrema[0]: extrema[0] = temp - * if temp > extrema[1]: extrema[1] = temp - */ - __pyx_v_temp += (((__pyx_v_edges[__pyx_v_k])[2]) * (__pyx_v_vp->x_vec[2])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":390 - * temp += edges[j][1] * vp.x_vec[1] - * temp += edges[k][2] * vp.x_vec[2] - * if temp < extrema[0]: extrema[0] = temp # <<<<<<<<<<<<<< - * if temp > extrema[1]: extrema[1] = temp - * temp = edges[i][0] * vp.y_vec[0] - */ - __pyx_t_5 = (__pyx_v_temp < (__pyx_v_extrema[0])); - if (__pyx_t_5) { - (__pyx_v_extrema[0]) = __pyx_v_temp; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":391 - * temp += edges[k][2] * vp.x_vec[2] - * if temp < extrema[0]: extrema[0] = temp - * if temp > extrema[1]: extrema[1] = temp # <<<<<<<<<<<<<< - * temp = edges[i][0] * vp.y_vec[0] - * temp += edges[j][1] * vp.y_vec[1] - */ - __pyx_t_5 = (__pyx_v_temp > (__pyx_v_extrema[1])); - if (__pyx_t_5) { - (__pyx_v_extrema[1]) = __pyx_v_temp; - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":392 - * if temp < extrema[0]: extrema[0] = temp - * if temp > extrema[1]: extrema[1] = temp - * temp = edges[i][0] * vp.y_vec[0] # <<<<<<<<<<<<<< - * temp += edges[j][1] * vp.y_vec[1] - * temp += edges[k][2] * vp.y_vec[2] - */ - __pyx_v_temp = (((__pyx_v_edges[__pyx_v_i])[0]) * (__pyx_v_vp->y_vec[0])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":393 - * if temp > extrema[1]: extrema[1] = temp - * temp = edges[i][0] * vp.y_vec[0] - * temp += edges[j][1] * vp.y_vec[1] # <<<<<<<<<<<<<< - * temp += edges[k][2] * vp.y_vec[2] - * if temp < extrema[2]: extrema[2] = temp - */ - __pyx_v_temp += (((__pyx_v_edges[__pyx_v_j])[1]) * (__pyx_v_vp->y_vec[1])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":394 - * temp = edges[i][0] * vp.y_vec[0] - * temp += edges[j][1] * vp.y_vec[1] - * temp += edges[k][2] * vp.y_vec[2] # <<<<<<<<<<<<<< - * if temp < extrema[2]: extrema[2] = temp - * if temp > extrema[3]: extrema[3] = temp - */ - __pyx_v_temp += (((__pyx_v_edges[__pyx_v_k])[2]) * (__pyx_v_vp->y_vec[2])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":395 - * temp += edges[j][1] * vp.y_vec[1] - * temp += edges[k][2] * vp.y_vec[2] - * if temp < extrema[2]: extrema[2] = temp # <<<<<<<<<<<<<< - * if temp > extrema[3]: extrema[3] = temp - * #print extrema[0], extrema[1], extrema[2], extrema[3] - */ - __pyx_t_5 = (__pyx_v_temp < (__pyx_v_extrema[2])); - if (__pyx_t_5) { - (__pyx_v_extrema[2]) = __pyx_v_temp; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":396 - * temp += edges[k][2] * vp.y_vec[2] - * if temp < extrema[2]: extrema[2] = temp - * if temp > extrema[3]: extrema[3] = temp # <<<<<<<<<<<<<< - * #print extrema[0], extrema[1], extrema[2], extrema[3] - * - */ - __pyx_t_5 = (__pyx_v_temp > (__pyx_v_extrema[3])); - if (__pyx_t_5) { - (__pyx_v_extrema[3]) = __pyx_v_temp; - goto __pyx_L12; - } - __pyx_L12:; - } - } - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":401 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef int integrate_ray(self, np.float64_t v_pos[3], # <<<<<<<<<<<<<< - * np.float64_t v_dir[3], - * np.float64_t rgba[4], - */ - -static int __pyx_f_2yt_9amr_utils_15PartitionedGrid_integrate_ray(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_v_pos, __pyx_t_5numpy_float64_t *__pyx_v_v_dir, __pyx_t_5numpy_float64_t *__pyx_v_rgba, struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *__pyx_v_tf) { - int __pyx_v_cur_ind[3]; - int __pyx_v_step[3]; - int __pyx_v_x; - int __pyx_v_y; - int __pyx_v_i; - int __pyx_v_hit; - int __pyx_v_direction; - __pyx_t_5numpy_float64_t __pyx_v_intersect_t; - __pyx_t_5numpy_float64_t __pyx_v_iv_dir[3]; - __pyx_t_5numpy_float64_t __pyx_v_intersect[3]; - __pyx_t_5numpy_float64_t __pyx_v_tmax[3]; - __pyx_t_5numpy_float64_t __pyx_v_tdelta[3]; - __pyx_t_5numpy_float64_t __pyx_v_enter_t; - __pyx_t_5numpy_float64_t __pyx_v_exit_t; - __pyx_t_5numpy_float64_t __pyx_v_tr; - __pyx_t_5numpy_float64_t __pyx_v_tl; - __pyx_t_5numpy_float64_t __pyx_v_temp_x; - __pyx_t_5numpy_float64_t __pyx_v_temp_y; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - __pyx_t_5numpy_float64_t __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - __Pyx_RefNannySetupContext("integrate_ray"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":406 - * TransferFunctionProxy tf): - * cdef int cur_ind[3], step[3], x, y, i, n, flat_ind, hit, direction - * cdef np.float64_t intersect_t = 1.0 # <<<<<<<<<<<<<< - * cdef np.float64_t iv_dir[3] - * cdef np.float64_t intersect[3], tmax[3], tdelta[3] - */ - __pyx_v_intersect_t = 1.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":411 - * cdef np.float64_t enter_t, dist, alpha, dt, exit_t - * cdef np.float64_t tr, tl, temp_x, temp_y, dv - * for i in range(3): # <<<<<<<<<<<<<< - * if (v_dir[i] < 0): - * step[i] = -1 - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":412 - * cdef np.float64_t tr, tl, temp_x, temp_y, dv - * for i in range(3): - * if (v_dir[i] < 0): # <<<<<<<<<<<<<< - * step[i] = -1 - * elif (v_dir[i] == 0): - */ - __pyx_t_2 = ((__pyx_v_v_dir[__pyx_v_i]) < 0.0); - if (__pyx_t_2) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":413 - * for i in range(3): - * if (v_dir[i] < 0): - * step[i] = -1 # <<<<<<<<<<<<<< - * elif (v_dir[i] == 0): - * step[i] = 1 - */ - (__pyx_v_step[__pyx_v_i]) = -1; - goto __pyx_L5; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":414 - * if (v_dir[i] < 0): - * step[i] = -1 - * elif (v_dir[i] == 0): # <<<<<<<<<<<<<< - * step[i] = 1 - * tmax[i] = 1e60 - */ - __pyx_t_2 = ((__pyx_v_v_dir[__pyx_v_i]) == 0.0); - if (__pyx_t_2) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":415 - * step[i] = -1 - * elif (v_dir[i] == 0): - * step[i] = 1 # <<<<<<<<<<<<<< - * tmax[i] = 1e60 - * iv_dir[i] = 1e60 - */ - (__pyx_v_step[__pyx_v_i]) = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":416 - * elif (v_dir[i] == 0): - * step[i] = 1 - * tmax[i] = 1e60 # <<<<<<<<<<<<<< - * iv_dir[i] = 1e60 - * tdelta[i] = 1e-60 - */ - (__pyx_v_tmax[__pyx_v_i]) = 1e60; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":417 - * step[i] = 1 - * tmax[i] = 1e60 - * iv_dir[i] = 1e60 # <<<<<<<<<<<<<< - * tdelta[i] = 1e-60 - * continue - */ - (__pyx_v_iv_dir[__pyx_v_i]) = 1e60; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":418 - * tmax[i] = 1e60 - * iv_dir[i] = 1e60 - * tdelta[i] = 1e-60 # <<<<<<<<<<<<<< - * continue - * else: - */ - (__pyx_v_tdelta[__pyx_v_i]) = 1e-60; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":419 - * iv_dir[i] = 1e60 - * tdelta[i] = 1e-60 - * continue # <<<<<<<<<<<<<< - * else: - * step[i] = 1 - */ - goto __pyx_L3_continue; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":421 - * continue - * else: - * step[i] = 1 # <<<<<<<<<<<<<< - * x = (i+1) % 3 - * y = (i+2) % 3 - */ - (__pyx_v_step[__pyx_v_i]) = 1; - } - __pyx_L5:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":422 - * else: - * step[i] = 1 - * x = (i+1) % 3 # <<<<<<<<<<<<<< - * y = (i+2) % 3 - * iv_dir[i] = 1.0/v_dir[i] - */ - __pyx_v_x = __Pyx_mod_long((__pyx_v_i + 1), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":423 - * step[i] = 1 - * x = (i+1) % 3 - * y = (i+2) % 3 # <<<<<<<<<<<<<< - * iv_dir[i] = 1.0/v_dir[i] - * tl = (self.left_edge[i] - v_pos[i])*iv_dir[i] - */ - __pyx_v_y = __Pyx_mod_long((__pyx_v_i + 2), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":424 - * x = (i+1) % 3 - * y = (i+2) % 3 - * iv_dir[i] = 1.0/v_dir[i] # <<<<<<<<<<<<<< - * tl = (self.left_edge[i] - v_pos[i])*iv_dir[i] - * temp_x = (v_pos[x] + tl*v_dir[x]) - */ - __pyx_t_3 = (__pyx_v_v_dir[__pyx_v_i]); - if (unlikely(__pyx_t_3 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_iv_dir[__pyx_v_i]) = (1.0 / __pyx_t_3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":425 - * y = (i+2) % 3 - * iv_dir[i] = 1.0/v_dir[i] - * tl = (self.left_edge[i] - v_pos[i])*iv_dir[i] # <<<<<<<<<<<<<< - * temp_x = (v_pos[x] + tl*v_dir[x]) - * temp_y = (v_pos[y] + tl*v_dir[y]) - */ - __pyx_v_tl = (((__pyx_v_self->left_edge[__pyx_v_i]) - (__pyx_v_v_pos[__pyx_v_i])) * (__pyx_v_iv_dir[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":426 - * iv_dir[i] = 1.0/v_dir[i] - * tl = (self.left_edge[i] - v_pos[i])*iv_dir[i] - * temp_x = (v_pos[x] + tl*v_dir[x]) # <<<<<<<<<<<<<< - * temp_y = (v_pos[y] + tl*v_dir[y]) - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - */ - __pyx_v_temp_x = ((__pyx_v_v_pos[__pyx_v_x]) + (__pyx_v_tl * (__pyx_v_v_dir[__pyx_v_x]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":427 - * tl = (self.left_edge[i] - v_pos[i])*iv_dir[i] - * temp_x = (v_pos[x] + tl*v_dir[x]) - * temp_y = (v_pos[y] + tl*v_dir[y]) # <<<<<<<<<<<<<< - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - */ - __pyx_v_temp_y = ((__pyx_v_v_pos[__pyx_v_y]) + (__pyx_v_tl * (__pyx_v_v_dir[__pyx_v_y]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":428 - * temp_x = (v_pos[x] + tl*v_dir[x]) - * temp_y = (v_pos[y] + tl*v_dir[y]) - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ # <<<<<<<<<<<<<< - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - * 0.0 <= tl and tl < intersect_t: - */ - __pyx_t_2 = ((__pyx_v_self->left_edge[__pyx_v_x]) <= __pyx_v_temp_x); - if (__pyx_t_2) { - __pyx_t_4 = (__pyx_v_temp_x <= (__pyx_v_self->right_edge[__pyx_v_x])); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":429 - * temp_y = (v_pos[y] + tl*v_dir[y]) - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ # <<<<<<<<<<<<<< - * 0.0 <= tl and tl < intersect_t: - * direction = i - */ - __pyx_t_5 = ((__pyx_v_self->left_edge[__pyx_v_y]) <= __pyx_v_temp_y); - if (__pyx_t_5) { - __pyx_t_6 = (__pyx_v_temp_y <= (__pyx_v_self->right_edge[__pyx_v_y])); - if (__pyx_t_6) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":430 - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - * 0.0 <= tl and tl < intersect_t: # <<<<<<<<<<<<<< - * direction = i - * intersect_t = tl - */ - __pyx_t_7 = (0.0 <= __pyx_v_tl); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_tl < __pyx_v_intersect_t); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_6; - } - __pyx_t_6 = __pyx_t_7; - } else { - __pyx_t_6 = __pyx_t_5; - } - __pyx_t_5 = __pyx_t_6; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_t_4 = __pyx_t_5; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":431 - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - * 0.0 <= tl and tl < intersect_t: - * direction = i # <<<<<<<<<<<<<< - * intersect_t = tl - * tr = (self.right_edge[i] - v_pos[i])*iv_dir[i] - */ - __pyx_v_direction = __pyx_v_i; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":432 - * 0.0 <= tl and tl < intersect_t: - * direction = i - * intersect_t = tl # <<<<<<<<<<<<<< - * tr = (self.right_edge[i] - v_pos[i])*iv_dir[i] - * temp_x = (v_pos[x] + tr*v_dir[x]) - */ - __pyx_v_intersect_t = __pyx_v_tl; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":433 - * direction = i - * intersect_t = tl - * tr = (self.right_edge[i] - v_pos[i])*iv_dir[i] # <<<<<<<<<<<<<< - * temp_x = (v_pos[x] + tr*v_dir[x]) - * temp_y = (v_pos[y] + tr*v_dir[y]) - */ - __pyx_v_tr = (((__pyx_v_self->right_edge[__pyx_v_i]) - (__pyx_v_v_pos[__pyx_v_i])) * (__pyx_v_iv_dir[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":434 - * intersect_t = tl - * tr = (self.right_edge[i] - v_pos[i])*iv_dir[i] - * temp_x = (v_pos[x] + tr*v_dir[x]) # <<<<<<<<<<<<<< - * temp_y = (v_pos[y] + tr*v_dir[y]) - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - */ - __pyx_v_temp_x = ((__pyx_v_v_pos[__pyx_v_x]) + (__pyx_v_tr * (__pyx_v_v_dir[__pyx_v_x]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":435 - * tr = (self.right_edge[i] - v_pos[i])*iv_dir[i] - * temp_x = (v_pos[x] + tr*v_dir[x]) - * temp_y = (v_pos[y] + tr*v_dir[y]) # <<<<<<<<<<<<<< - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - */ - __pyx_v_temp_y = ((__pyx_v_v_pos[__pyx_v_y]) + (__pyx_v_tr * (__pyx_v_v_dir[__pyx_v_y]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":436 - * temp_x = (v_pos[x] + tr*v_dir[x]) - * temp_y = (v_pos[y] + tr*v_dir[y]) - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ # <<<<<<<<<<<<<< - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - * 0.0 <= tr and tr < intersect_t: - */ - __pyx_t_4 = ((__pyx_v_self->left_edge[__pyx_v_x]) <= __pyx_v_temp_x); - if (__pyx_t_4) { - __pyx_t_2 = (__pyx_v_temp_x <= (__pyx_v_self->right_edge[__pyx_v_x])); - if (__pyx_t_2) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":437 - * temp_y = (v_pos[y] + tr*v_dir[y]) - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ # <<<<<<<<<<<<<< - * 0.0 <= tr and tr < intersect_t: - * direction = i - */ - __pyx_t_5 = ((__pyx_v_self->left_edge[__pyx_v_y]) <= __pyx_v_temp_y); - if (__pyx_t_5) { - __pyx_t_6 = (__pyx_v_temp_y <= (__pyx_v_self->right_edge[__pyx_v_y])); - if (__pyx_t_6) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":438 - * if self.left_edge[x] <= temp_x and temp_x <= self.right_edge[x] and \ - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - * 0.0 <= tr and tr < intersect_t: # <<<<<<<<<<<<<< - * direction = i - * intersect_t = tr - */ - __pyx_t_7 = (0.0 <= __pyx_v_tr); - if (__pyx_t_7) { - __pyx_t_9 = (__pyx_v_tr < __pyx_v_intersect_t); - __pyx_t_8 = __pyx_t_9; - } else { - __pyx_t_8 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_8; - } else { - __pyx_t_7 = __pyx_t_6; - } - __pyx_t_6 = __pyx_t_7; - } else { - __pyx_t_6 = __pyx_t_5; - } - __pyx_t_5 = __pyx_t_6; - } else { - __pyx_t_5 = __pyx_t_2; - } - __pyx_t_2 = __pyx_t_5; - } else { - __pyx_t_2 = __pyx_t_4; - } - if (__pyx_t_2) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":439 - * self.left_edge[y] <= temp_y and temp_y <= self.right_edge[y] and \ - * 0.0 <= tr and tr < intersect_t: - * direction = i # <<<<<<<<<<<<<< - * intersect_t = tr - * if self.left_edge[0] <= v_pos[0] and v_pos[0] <= self.right_edge[0] and \ - */ - __pyx_v_direction = __pyx_v_i; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":440 - * 0.0 <= tr and tr < intersect_t: - * direction = i - * intersect_t = tr # <<<<<<<<<<<<<< - * if self.left_edge[0] <= v_pos[0] and v_pos[0] <= self.right_edge[0] and \ - * self.left_edge[1] <= v_pos[1] and v_pos[1] <= self.right_edge[1] and \ - */ - __pyx_v_intersect_t = __pyx_v_tr; - goto __pyx_L7; - } - __pyx_L7:; - __pyx_L3_continue:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":441 - * direction = i - * intersect_t = tr - * if self.left_edge[0] <= v_pos[0] and v_pos[0] <= self.right_edge[0] and \ # <<<<<<<<<<<<<< - * self.left_edge[1] <= v_pos[1] and v_pos[1] <= self.right_edge[1] and \ - * self.left_edge[2] <= v_pos[2] and v_pos[2] <= self.right_edge[2]: - */ - __pyx_t_2 = ((__pyx_v_self->left_edge[0]) <= (__pyx_v_v_pos[0])); - if (__pyx_t_2) { - __pyx_t_4 = ((__pyx_v_v_pos[0]) <= (__pyx_v_self->right_edge[0])); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":442 - * intersect_t = tr - * if self.left_edge[0] <= v_pos[0] and v_pos[0] <= self.right_edge[0] and \ - * self.left_edge[1] <= v_pos[1] and v_pos[1] <= self.right_edge[1] and \ # <<<<<<<<<<<<<< - * self.left_edge[2] <= v_pos[2] and v_pos[2] <= self.right_edge[2]: - * intersect_t = 0.0 - */ - __pyx_t_5 = ((__pyx_v_self->left_edge[1]) <= (__pyx_v_v_pos[1])); - if (__pyx_t_5) { - __pyx_t_6 = ((__pyx_v_v_pos[1]) <= (__pyx_v_self->right_edge[1])); - if (__pyx_t_6) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":443 - * if self.left_edge[0] <= v_pos[0] and v_pos[0] <= self.right_edge[0] and \ - * self.left_edge[1] <= v_pos[1] and v_pos[1] <= self.right_edge[1] and \ - * self.left_edge[2] <= v_pos[2] and v_pos[2] <= self.right_edge[2]: # <<<<<<<<<<<<<< - * intersect_t = 0.0 - * if not ((0.0 <= intersect_t) and (intersect_t < 1.0)): return 0 - */ - __pyx_t_7 = ((__pyx_v_self->left_edge[2]) <= (__pyx_v_v_pos[2])); - if (__pyx_t_7) { - __pyx_t_8 = ((__pyx_v_v_pos[2]) <= (__pyx_v_self->right_edge[2])); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_6; - } - __pyx_t_6 = __pyx_t_7; - } else { - __pyx_t_6 = __pyx_t_5; - } - __pyx_t_5 = __pyx_t_6; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_t_4 = __pyx_t_5; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":444 - * self.left_edge[1] <= v_pos[1] and v_pos[1] <= self.right_edge[1] and \ - * self.left_edge[2] <= v_pos[2] and v_pos[2] <= self.right_edge[2]: - * intersect_t = 0.0 # <<<<<<<<<<<<<< - * if not ((0.0 <= intersect_t) and (intersect_t < 1.0)): return 0 - * for i in range(3): - */ - __pyx_v_intersect_t = 0.0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":445 - * self.left_edge[2] <= v_pos[2] and v_pos[2] <= self.right_edge[2]: - * intersect_t = 0.0 - * if not ((0.0 <= intersect_t) and (intersect_t < 1.0)): return 0 # <<<<<<<<<<<<<< - * for i in range(3): - * intersect[i] = v_pos[i] + intersect_t * v_dir[i] - */ - __pyx_t_4 = (0.0 <= __pyx_v_intersect_t); - if (__pyx_t_4) { - __pyx_t_2 = (__pyx_v_intersect_t < 1.0); - __pyx_t_5 = __pyx_t_2; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_t_4 = (!__pyx_t_5); - if (__pyx_t_4) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":446 - * intersect_t = 0.0 - * if not ((0.0 <= intersect_t) and (intersect_t < 1.0)): return 0 - * for i in range(3): # <<<<<<<<<<<<<< - * intersect[i] = v_pos[i] + intersect_t * v_dir[i] - * cur_ind[i] = floor((intersect[i] + - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":447 - * if not ((0.0 <= intersect_t) and (intersect_t < 1.0)): return 0 - * for i in range(3): - * intersect[i] = v_pos[i] + intersect_t * v_dir[i] # <<<<<<<<<<<<<< - * cur_ind[i] = floor((intersect[i] + - * step[i]*1e-8*self.dds[i] - - */ - (__pyx_v_intersect[__pyx_v_i]) = ((__pyx_v_v_pos[__pyx_v_i]) + (__pyx_v_intersect_t * (__pyx_v_v_dir[__pyx_v_i]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":448 - * for i in range(3): - * intersect[i] = v_pos[i] + intersect_t * v_dir[i] - * cur_ind[i] = floor((intersect[i] + # <<<<<<<<<<<<<< - * step[i]*1e-8*self.dds[i] - - * self.left_edge[i])*self.idds[i]) - */ - (__pyx_v_cur_ind[__pyx_v_i]) = ((int)floor(((((__pyx_v_intersect[__pyx_v_i]) + (((__pyx_v_step[__pyx_v_i]) * 1e-8) * (__pyx_v_self->dds[__pyx_v_i]))) - (__pyx_v_self->left_edge[__pyx_v_i])) * (__pyx_v_self->idds[__pyx_v_i])))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":451 - * step[i]*1e-8*self.dds[i] - - * self.left_edge[i])*self.idds[i]) - * tmax[i] = (((cur_ind[i]+step[i])*self.dds[i])+ # <<<<<<<<<<<<<< - * self.left_edge[i]-v_pos[i])*iv_dir[i] - * # This deals with the asymmetry in having our indices refer to the - */ - (__pyx_v_tmax[__pyx_v_i]) = ((((((__pyx_v_cur_ind[__pyx_v_i]) + (__pyx_v_step[__pyx_v_i])) * (__pyx_v_self->dds[__pyx_v_i])) + (__pyx_v_self->left_edge[__pyx_v_i])) - (__pyx_v_v_pos[__pyx_v_i])) * (__pyx_v_iv_dir[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":456 - * # left edge of a cell, but the right edge of the brick being one - * # extra zone out. - * if cur_ind[i] == self.dims[i] and step[i] < 0: # <<<<<<<<<<<<<< - * cur_ind[i] = self.dims[i] - 1 - * if cur_ind[i] < 0 or cur_ind[i] >= self.dims[i]: return 0 - */ - __pyx_t_4 = ((__pyx_v_cur_ind[__pyx_v_i]) == (__pyx_v_self->dims[__pyx_v_i])); - if (__pyx_t_4) { - __pyx_t_5 = ((__pyx_v_step[__pyx_v_i]) < 0); - __pyx_t_2 = __pyx_t_5; - } else { - __pyx_t_2 = __pyx_t_4; - } - if (__pyx_t_2) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":457 - * # extra zone out. - * if cur_ind[i] == self.dims[i] and step[i] < 0: - * cur_ind[i] = self.dims[i] - 1 # <<<<<<<<<<<<<< - * if cur_ind[i] < 0 or cur_ind[i] >= self.dims[i]: return 0 - * if step[i] > 0: - */ - (__pyx_v_cur_ind[__pyx_v_i]) = ((__pyx_v_self->dims[__pyx_v_i]) - 1); - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":458 - * if cur_ind[i] == self.dims[i] and step[i] < 0: - * cur_ind[i] = self.dims[i] - 1 - * if cur_ind[i] < 0 or cur_ind[i] >= self.dims[i]: return 0 # <<<<<<<<<<<<<< - * if step[i] > 0: - * tmax[i] = (((cur_ind[i]+1)*self.dds[i]) - */ - __pyx_t_2 = ((__pyx_v_cur_ind[__pyx_v_i]) < 0); - if (!__pyx_t_2) { - __pyx_t_4 = ((__pyx_v_cur_ind[__pyx_v_i]) >= (__pyx_v_self->dims[__pyx_v_i])); - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_2; - } - if (__pyx_t_5) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L13; - } - __pyx_L13:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":459 - * cur_ind[i] = self.dims[i] - 1 - * if cur_ind[i] < 0 or cur_ind[i] >= self.dims[i]: return 0 - * if step[i] > 0: # <<<<<<<<<<<<<< - * tmax[i] = (((cur_ind[i]+1)*self.dds[i]) - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - */ - __pyx_t_5 = ((__pyx_v_step[__pyx_v_i]) > 0); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":460 - * if cur_ind[i] < 0 or cur_ind[i] >= self.dims[i]: return 0 - * if step[i] > 0: - * tmax[i] = (((cur_ind[i]+1)*self.dds[i]) # <<<<<<<<<<<<<< - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - * if step[i] < 0: - */ - (__pyx_v_tmax[__pyx_v_i]) = ((((((__pyx_v_cur_ind[__pyx_v_i]) + 1) * (__pyx_v_self->dds[__pyx_v_i])) + (__pyx_v_self->left_edge[__pyx_v_i])) - (__pyx_v_v_pos[__pyx_v_i])) * (__pyx_v_iv_dir[__pyx_v_i])); - goto __pyx_L14; - } - __pyx_L14:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":462 - * tmax[i] = (((cur_ind[i]+1)*self.dds[i]) - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - * if step[i] < 0: # <<<<<<<<<<<<<< - * tmax[i] = (((cur_ind[i]+0)*self.dds[i]) - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - */ - __pyx_t_5 = ((__pyx_v_step[__pyx_v_i]) < 0); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":463 - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - * if step[i] < 0: - * tmax[i] = (((cur_ind[i]+0)*self.dds[i]) # <<<<<<<<<<<<<< - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - * tdelta[i] = (self.dds[i]*iv_dir[i]) - */ - (__pyx_v_tmax[__pyx_v_i]) = ((((((__pyx_v_cur_ind[__pyx_v_i]) + 0) * (__pyx_v_self->dds[__pyx_v_i])) + (__pyx_v_self->left_edge[__pyx_v_i])) - (__pyx_v_v_pos[__pyx_v_i])) * (__pyx_v_iv_dir[__pyx_v_i])); - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":465 - * tmax[i] = (((cur_ind[i]+0)*self.dds[i]) - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - * tdelta[i] = (self.dds[i]*iv_dir[i]) # <<<<<<<<<<<<<< - * if tdelta[i] < 0: tdelta[i] *= -1 - * # We have to jumpstart our calculation - */ - (__pyx_v_tdelta[__pyx_v_i]) = ((__pyx_v_self->dds[__pyx_v_i]) * (__pyx_v_iv_dir[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":466 - * +self.left_edge[i]-v_pos[i])*iv_dir[i] - * tdelta[i] = (self.dds[i]*iv_dir[i]) - * if tdelta[i] < 0: tdelta[i] *= -1 # <<<<<<<<<<<<<< - * # We have to jumpstart our calculation - * enter_t = intersect_t - */ - __pyx_t_5 = ((__pyx_v_tdelta[__pyx_v_i]) < 0.0); - if (__pyx_t_5) { - (__pyx_v_tdelta[__pyx_v_i]) *= -1.0; - goto __pyx_L16; - } - __pyx_L16:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":468 - * if tdelta[i] < 0: tdelta[i] *= -1 - * # We have to jumpstart our calculation - * enter_t = intersect_t # <<<<<<<<<<<<<< - * while 1: - * # dims here is one less than the dimensions of the data, - */ - __pyx_v_enter_t = __pyx_v_intersect_t; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":469 - * # We have to jumpstart our calculation - * enter_t = intersect_t - * while 1: # <<<<<<<<<<<<<< - * # dims here is one less than the dimensions of the data, - * # but we are tracing on the grid, not on the data... - */ - while (1) { - if (!1) break; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":472 - * # dims here is one less than the dimensions of the data, - * # but we are tracing on the grid, not on the data... - * if (not (0 <= cur_ind[0] < self.dims[0])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[1] < self.dims[1])) or \ - * (not (0 <= cur_ind[2] < self.dims[2])): - */ - __pyx_t_1 = (__pyx_v_cur_ind[0]); - __pyx_t_5 = (0 <= __pyx_t_1); - if (__pyx_t_5) { - __pyx_t_5 = (__pyx_t_1 < (__pyx_v_self->dims[0])); - } - __pyx_t_2 = (!__pyx_t_5); - if (!__pyx_t_2) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":473 - * # but we are tracing on the grid, not on the data... - * if (not (0 <= cur_ind[0] < self.dims[0])) or \ - * (not (0 <= cur_ind[1] < self.dims[1])) or \ # <<<<<<<<<<<<<< - * (not (0 <= cur_ind[2] < self.dims[2])): - * break - */ - __pyx_t_1 = (__pyx_v_cur_ind[1]); - __pyx_t_5 = (0 <= __pyx_t_1); - if (__pyx_t_5) { - __pyx_t_5 = (__pyx_t_1 < (__pyx_v_self->dims[1])); - } - __pyx_t_4 = (!__pyx_t_5); - if (!__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":474 - * if (not (0 <= cur_ind[0] < self.dims[0])) or \ - * (not (0 <= cur_ind[1] < self.dims[1])) or \ - * (not (0 <= cur_ind[2] < self.dims[2])): # <<<<<<<<<<<<<< - * break - * hit += 1 - */ - __pyx_t_1 = (__pyx_v_cur_ind[2]); - __pyx_t_5 = (0 <= __pyx_t_1); - if (__pyx_t_5) { - __pyx_t_5 = (__pyx_t_1 < (__pyx_v_self->dims[2])); - } - __pyx_t_6 = (!__pyx_t_5); - __pyx_t_5 = __pyx_t_6; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_t_4 = __pyx_t_5; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":475 - * (not (0 <= cur_ind[1] < self.dims[1])) or \ - * (not (0 <= cur_ind[2] < self.dims[2])): - * break # <<<<<<<<<<<<<< - * hit += 1 - * if tmax[0] < tmax[1]: - */ - goto __pyx_L18_break; - goto __pyx_L19; - } - __pyx_L19:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":476 - * (not (0 <= cur_ind[2] < self.dims[2])): - * break - * hit += 1 # <<<<<<<<<<<<<< - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: - */ - __pyx_v_hit += 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":477 - * break - * hit += 1 - * if tmax[0] < tmax[1]: # <<<<<<<<<<<<<< - * if tmax[0] < tmax[2]: - * exit_t = fmin(tmax[0], 1.0) - */ - __pyx_t_4 = ((__pyx_v_tmax[0]) < (__pyx_v_tmax[1])); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":478 - * hit += 1 - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: # <<<<<<<<<<<<<< - * exit_t = fmin(tmax[0], 1.0) - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - */ - __pyx_t_4 = ((__pyx_v_tmax[0]) < (__pyx_v_tmax[2])); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":479 - * if tmax[0] < tmax[1]: - * if tmax[0] < tmax[2]: - * exit_t = fmin(tmax[0], 1.0) # <<<<<<<<<<<<<< - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - */ - __pyx_v_exit_t = __pyx_f_2yt_9amr_utils_fmin((__pyx_v_tmax[0]), 1.0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":481 - * exit_t = fmin(tmax[0], 1.0) - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) # <<<<<<<<<<<<<< - * cur_ind[0] += step[0] - * enter_t = tmax[0] - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self->__pyx_vtab)->sample_values(__pyx_v_self, __pyx_v_v_pos, __pyx_v_v_dir, __pyx_v_enter_t, __pyx_v_exit_t, __pyx_v_cur_ind, __pyx_v_rgba, __pyx_v_tf); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":482 - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - * cur_ind[0] += step[0] # <<<<<<<<<<<<<< - * enter_t = tmax[0] - * tmax[0] += tdelta[0] - */ - (__pyx_v_cur_ind[0]) += (__pyx_v_step[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":483 - * rgba, tf) - * cur_ind[0] += step[0] - * enter_t = tmax[0] # <<<<<<<<<<<<<< - * tmax[0] += tdelta[0] - * else: - */ - __pyx_v_enter_t = (__pyx_v_tmax[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":484 - * cur_ind[0] += step[0] - * enter_t = tmax[0] - * tmax[0] += tdelta[0] # <<<<<<<<<<<<<< - * else: - * exit_t = fmin(tmax[2], 1.0) - */ - (__pyx_v_tmax[0]) += (__pyx_v_tdelta[0]); - goto __pyx_L21; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":486 - * tmax[0] += tdelta[0] - * else: - * exit_t = fmin(tmax[2], 1.0) # <<<<<<<<<<<<<< - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - */ - __pyx_v_exit_t = __pyx_f_2yt_9amr_utils_fmin((__pyx_v_tmax[2]), 1.0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":488 - * exit_t = fmin(tmax[2], 1.0) - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) # <<<<<<<<<<<<<< - * cur_ind[2] += step[2] - * enter_t = tmax[2] - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self->__pyx_vtab)->sample_values(__pyx_v_self, __pyx_v_v_pos, __pyx_v_v_dir, __pyx_v_enter_t, __pyx_v_exit_t, __pyx_v_cur_ind, __pyx_v_rgba, __pyx_v_tf); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":489 - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - * cur_ind[2] += step[2] # <<<<<<<<<<<<<< - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - */ - (__pyx_v_cur_ind[2]) += (__pyx_v_step[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":490 - * rgba, tf) - * cur_ind[2] += step[2] - * enter_t = tmax[2] # <<<<<<<<<<<<<< - * tmax[2] += tdelta[2] - * else: - */ - __pyx_v_enter_t = (__pyx_v_tmax[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":491 - * cur_ind[2] += step[2] - * enter_t = tmax[2] - * tmax[2] += tdelta[2] # <<<<<<<<<<<<<< - * else: - * if tmax[1] < tmax[2]: - */ - (__pyx_v_tmax[2]) += (__pyx_v_tdelta[2]); - } - __pyx_L21:; - goto __pyx_L20; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":493 - * tmax[2] += tdelta[2] - * else: - * if tmax[1] < tmax[2]: # <<<<<<<<<<<<<< - * exit_t = fmin(tmax[1], 1.0) - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - */ - __pyx_t_4 = ((__pyx_v_tmax[1]) < (__pyx_v_tmax[2])); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":494 - * else: - * if tmax[1] < tmax[2]: - * exit_t = fmin(tmax[1], 1.0) # <<<<<<<<<<<<<< - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - */ - __pyx_v_exit_t = __pyx_f_2yt_9amr_utils_fmin((__pyx_v_tmax[1]), 1.0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":496 - * exit_t = fmin(tmax[1], 1.0) - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) # <<<<<<<<<<<<<< - * cur_ind[1] += step[1] - * enter_t = tmax[1] - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self->__pyx_vtab)->sample_values(__pyx_v_self, __pyx_v_v_pos, __pyx_v_v_dir, __pyx_v_enter_t, __pyx_v_exit_t, __pyx_v_cur_ind, __pyx_v_rgba, __pyx_v_tf); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":497 - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - * cur_ind[1] += step[1] # <<<<<<<<<<<<<< - * enter_t = tmax[1] - * tmax[1] += tdelta[1] - */ - (__pyx_v_cur_ind[1]) += (__pyx_v_step[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":498 - * rgba, tf) - * cur_ind[1] += step[1] - * enter_t = tmax[1] # <<<<<<<<<<<<<< - * tmax[1] += tdelta[1] - * else: - */ - __pyx_v_enter_t = (__pyx_v_tmax[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":499 - * cur_ind[1] += step[1] - * enter_t = tmax[1] - * tmax[1] += tdelta[1] # <<<<<<<<<<<<<< - * else: - * exit_t = fmin(tmax[2], 1.0) - */ - (__pyx_v_tmax[1]) += (__pyx_v_tdelta[1]); - goto __pyx_L22; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":501 - * tmax[1] += tdelta[1] - * else: - * exit_t = fmin(tmax[2], 1.0) # <<<<<<<<<<<<<< - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - */ - __pyx_v_exit_t = __pyx_f_2yt_9amr_utils_fmin((__pyx_v_tmax[2]), 1.0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":503 - * exit_t = fmin(tmax[2], 1.0) - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) # <<<<<<<<<<<<<< - * cur_ind[2] += step[2] - * enter_t = tmax[2] - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid *)__pyx_v_self->__pyx_vtab)->sample_values(__pyx_v_self, __pyx_v_v_pos, __pyx_v_v_dir, __pyx_v_enter_t, __pyx_v_exit_t, __pyx_v_cur_ind, __pyx_v_rgba, __pyx_v_tf); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":504 - * self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, - * rgba, tf) - * cur_ind[2] += step[2] # <<<<<<<<<<<<<< - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - */ - (__pyx_v_cur_ind[2]) += (__pyx_v_step[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":505 - * rgba, tf) - * cur_ind[2] += step[2] - * enter_t = tmax[2] # <<<<<<<<<<<<<< - * tmax[2] += tdelta[2] - * if enter_t > 1.0: break - */ - __pyx_v_enter_t = (__pyx_v_tmax[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":506 - * cur_ind[2] += step[2] - * enter_t = tmax[2] - * tmax[2] += tdelta[2] # <<<<<<<<<<<<<< - * if enter_t > 1.0: break - * return hit - */ - (__pyx_v_tmax[2]) += (__pyx_v_tdelta[2]); - } - __pyx_L22:; - } - __pyx_L20:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":507 - * enter_t = tmax[2] - * tmax[2] += tdelta[2] - * if enter_t > 1.0: break # <<<<<<<<<<<<<< - * return hit - * - */ - __pyx_t_4 = (__pyx_v_enter_t > 1.0); - if (__pyx_t_4) { - goto __pyx_L18_break; - goto __pyx_L23; - } - __pyx_L23:; - } - __pyx_L18_break:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":508 - * tmax[2] += tdelta[2] - * if enter_t > 1.0: break - * return hit # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __pyx_r = __pyx_v_hit; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("yt.amr_utils.PartitionedGrid.integrate_ray"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":512 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef void sample_values(self, # <<<<<<<<<<<<<< - * np.float64_t v_pos[3], - * np.float64_t v_dir[3], - */ - -static void __pyx_f_2yt_9amr_utils_15PartitionedGrid_sample_values(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_v_pos, __pyx_t_5numpy_float64_t *__pyx_v_v_dir, __pyx_t_5numpy_float64_t __pyx_v_enter_t, __pyx_t_5numpy_float64_t __pyx_v_exit_t, int *__pyx_v_ci, __pyx_t_5numpy_float64_t *__pyx_v_rgba, struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *__pyx_v_tf) { - __pyx_t_5numpy_float64_t __pyx_v_dp[3]; - __pyx_t_5numpy_float64_t __pyx_v_temp; - __pyx_t_5numpy_float64_t __pyx_v_dt; - __pyx_t_5numpy_float64_t __pyx_v_grad[3]; - __pyx_t_5numpy_float64_t __pyx_v_ds[3]; - int __pyx_v_dti; - int __pyx_v_i; - int __pyx_v_offset; - __pyx_t_5numpy_float64_t __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - __Pyx_RefNannySetupContext("sample_values"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":522 - * cdef np.float64_t cp[3], dp[3], temp, dt, t, dv - * cdef np.float64_t grad[3], ds[3] - * grad[0] = grad[1] = grad[2] = 0.0 # <<<<<<<<<<<<<< - * cdef int dti, i - * dt = (exit_t - enter_t) / tf.ns # 4 samples should be dt=0.25 - */ - (__pyx_v_grad[0]) = 0.0; - (__pyx_v_grad[1]) = 0.0; - (__pyx_v_grad[2]) = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":524 - * grad[0] = grad[1] = grad[2] = 0.0 - * cdef int dti, i - * dt = (exit_t - enter_t) / tf.ns # 4 samples should be dt=0.25 # <<<<<<<<<<<<<< - * cdef int offset = ci[0] * (self.dims[1] + 1) * (self.dims[2] + 1) \ - * + ci[1] * (self.dims[2] + 1) + ci[2] - */ - __pyx_t_1 = (__pyx_v_exit_t - __pyx_v_enter_t); - if (unlikely(__pyx_v_tf->ns == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dt = (__pyx_t_1 / __pyx_v_tf->ns); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":526 - * dt = (exit_t - enter_t) / tf.ns # 4 samples should be dt=0.25 - * cdef int offset = ci[0] * (self.dims[1] + 1) * (self.dims[2] + 1) \ - * + ci[1] * (self.dims[2] + 1) + ci[2] # <<<<<<<<<<<<<< - * for i in range(3): - * # temp is the left edge of the current cell - */ - __pyx_v_offset = (((((__pyx_v_ci[0]) * ((__pyx_v_self->dims[1]) + 1)) * ((__pyx_v_self->dims[2]) + 1)) + ((__pyx_v_ci[1]) * ((__pyx_v_self->dims[2]) + 1))) + (__pyx_v_ci[2])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":527 - * cdef int offset = ci[0] * (self.dims[1] + 1) * (self.dims[2] + 1) \ - * + ci[1] * (self.dims[2] + 1) + ci[2] - * for i in range(3): # <<<<<<<<<<<<<< - * # temp is the left edge of the current cell - * temp = ci[i] * self.dds[i] + self.left_edge[i] - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":529 - * for i in range(3): - * # temp is the left edge of the current cell - * temp = ci[i] * self.dds[i] + self.left_edge[i] # <<<<<<<<<<<<<< - * # this gets us dp as the current first sample position - * dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp - */ - __pyx_v_temp = (((__pyx_v_ci[__pyx_v_i]) * (__pyx_v_self->dds[__pyx_v_i])) + (__pyx_v_self->left_edge[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":531 - * temp = ci[i] * self.dds[i] + self.left_edge[i] - * # this gets us dp as the current first sample position - * dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp # <<<<<<<<<<<<<< - * dp[i] *= self.idds[i] - * ds[i] = v_dir[i] * self.idds[i] * dt - */ - (__pyx_v_dp[__pyx_v_i]) = ((((__pyx_v_enter_t + (0.5 * __pyx_v_dt)) * (__pyx_v_v_dir[__pyx_v_i])) + (__pyx_v_v_pos[__pyx_v_i])) - __pyx_v_temp); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":532 - * # this gets us dp as the current first sample position - * dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp - * dp[i] *= self.idds[i] # <<<<<<<<<<<<<< - * ds[i] = v_dir[i] * self.idds[i] * dt - * for dti in range(tf.ns): - */ - (__pyx_v_dp[__pyx_v_i]) *= (__pyx_v_self->idds[__pyx_v_i]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":533 - * dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp - * dp[i] *= self.idds[i] - * ds[i] = v_dir[i] * self.idds[i] * dt # <<<<<<<<<<<<<< - * for dti in range(tf.ns): - * for i in range(self.n_fields): - */ - (__pyx_v_ds[__pyx_v_i]) = (((__pyx_v_v_dir[__pyx_v_i]) * (__pyx_v_self->idds[__pyx_v_i])) * __pyx_v_dt); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":534 - * dp[i] *= self.idds[i] - * ds[i] = v_dir[i] * self.idds[i] * dt - * for dti in range(tf.ns): # <<<<<<<<<<<<<< - * for i in range(self.n_fields): - * self.dvs[i] = offset_interpolate(self.dims, dp, self.data[i] + offset) - */ - __pyx_t_2 = __pyx_v_tf->ns; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_dti = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":535 - * ds[i] = v_dir[i] * self.idds[i] * dt - * for dti in range(tf.ns): - * for i in range(self.n_fields): # <<<<<<<<<<<<<< - * self.dvs[i] = offset_interpolate(self.dims, dp, self.data[i] + offset) - * #if (dv < tf.x_bounds[0]) or (dv > tf.x_bounds[1]): - */ - __pyx_t_4 = __pyx_v_self->n_fields; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":536 - * for dti in range(tf.ns): - * for i in range(self.n_fields): - * self.dvs[i] = offset_interpolate(self.dims, dp, self.data[i] + offset) # <<<<<<<<<<<<<< - * #if (dv < tf.x_bounds[0]) or (dv > tf.x_bounds[1]): - * # continue - */ - (__pyx_v_self->dvs[__pyx_v_i]) = offset_interpolate(__pyx_v_self->dims, __pyx_v_dp, ((__pyx_v_self->data[__pyx_v_i]) + __pyx_v_offset)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":539 - * #if (dv < tf.x_bounds[0]) or (dv > tf.x_bounds[1]): - * # continue - * for i in range(3): # <<<<<<<<<<<<<< - * dp[i] += ds[i] - * tf.eval_transfer(dt, self.dvs, rgba, grad) - */ - for (__pyx_t_4 = 0; __pyx_t_4 < 3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":540 - * # continue - * for i in range(3): - * dp[i] += ds[i] # <<<<<<<<<<<<<< - * tf.eval_transfer(dt, self.dvs, rgba, grad) - * - */ - (__pyx_v_dp[__pyx_v_i]) += (__pyx_v_ds[__pyx_v_i]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":541 - * for i in range(3): - * dp[i] += ds[i] - * tf.eval_transfer(dt, self.dvs, rgba, grad) # <<<<<<<<<<<<<< - * - * cdef class GridFace: - */ - ((struct __pyx_vtabstruct_2yt_9amr_utils_TransferFunctionProxy *)__pyx_v_tf->__pyx_vtab)->eval_transfer(__pyx_v_tf, __pyx_v_dt, __pyx_v_self->dvs, __pyx_v_rgba, __pyx_v_grad); - } - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("yt.amr_utils.PartitionedGrid.sample_values"); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":545 - * cdef class GridFace: - * cdef int direction - * cdef public np.float64_t coord # <<<<<<<<<<<<<< - * cdef np.float64_t left_edge[3] - * cdef np.float64_t right_edge[3] - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_8GridFace_5coord___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_8GridFace_5coord___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->coord); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.GridFace.coord.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_8GridFace_5coord___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_8GridFace_5coord___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __pyx_t_5numpy_float64_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_1 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->coord = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.GridFace.coord.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":551 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def __init__(self, grid, int direction, int left): # <<<<<<<<<<<<<< - * self.direction = direction - * if left == 1: - */ - -static int __pyx_pf_2yt_9amr_utils_8GridFace___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_8GridFace___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_grid = 0; - int __pyx_v_direction; - int __pyx_v_left; - int __pyx_v_i; - int __pyx_r; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __pyx_t_5numpy_float64_t __pyx_t_4; - int __pyx_t_5; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__grid,&__pyx_n_s__direction,&__pyx_n_s__left,0}; - __Pyx_RefNannySetupContext("__init__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[3] = {0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__direction); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_grid = values[0]; - __pyx_v_direction = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_left = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_left == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_grid = PyTuple_GET_ITEM(__pyx_args, 0); - __pyx_v_direction = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_left = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_left == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.GridFace.__init__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":552 - * @cython.wraparound(False) - * def __init__(self, grid, int direction, int left): - * self.direction = direction # <<<<<<<<<<<<<< - * if left == 1: - * self.coord = grid.LeftEdge[direction] - */ - ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->direction = __pyx_v_direction; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":553 - * def __init__(self, grid, int direction, int left): - * self.direction = direction - * if left == 1: # <<<<<<<<<<<<<< - * self.coord = grid.LeftEdge[direction] - * else: - */ - __pyx_t_1 = (__pyx_v_left == 1); - if (__pyx_t_1) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":554 - * self.direction = direction - * if left == 1: - * self.coord = grid.LeftEdge[direction] # <<<<<<<<<<<<<< - * else: - * self.coord = grid.RightEdge[direction] - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_grid, __pyx_n_s__LeftEdge); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, __pyx_v_direction, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_4 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->coord = __pyx_t_4; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":556 - * self.coord = grid.LeftEdge[direction] - * else: - * self.coord = grid.RightEdge[direction] # <<<<<<<<<<<<<< - * cdef int i - * for i in range(3): - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_grid, __pyx_n_s__RightEdge); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_direction, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_4 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->coord = __pyx_t_4; - } - __pyx_L6:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":558 - * self.coord = grid.RightEdge[direction] - * cdef int i - * for i in range(3): # <<<<<<<<<<<<<< - * self.left_edge[i] = grid.LeftEdge[i] - * self.right_edge[i] = grid.RightEdge[i] - */ - for (__pyx_t_5 = 0; __pyx_t_5 < 3; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":559 - * cdef int i - * for i in range(3): - * self.left_edge[i] = grid.LeftEdge[i] # <<<<<<<<<<<<<< - * self.right_edge[i] = grid.RightEdge[i] - * self.left_edge[direction] = self.right_edge[direction] = self.coord - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_grid, __pyx_n_s__LeftEdge); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_4 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - (((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->left_edge[__pyx_v_i]) = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":560 - * for i in range(3): - * self.left_edge[i] = grid.LeftEdge[i] - * self.right_edge[i] = grid.RightEdge[i] # <<<<<<<<<<<<<< - * self.left_edge[direction] = self.right_edge[direction] = self.coord - * - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_grid, __pyx_n_s__RightEdge); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_4 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - (((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->right_edge[__pyx_v_i]) = __pyx_t_4; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":561 - * self.left_edge[i] = grid.LeftEdge[i] - * self.right_edge[i] = grid.RightEdge[i] - * self.left_edge[direction] = self.right_edge[direction] = self.coord # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - (((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->left_edge[__pyx_v_direction]) = ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->coord; - (((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->right_edge[__pyx_v_direction]) = ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_v_self)->coord; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("yt.amr_utils.GridFace.__init__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":565 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef int proj_overlap(self, np.float64_t *left_edge, np.float64_t *right_edge): # <<<<<<<<<<<<<< - * cdef int xax, yax - * xax = (self.direction + 1) % 3 - */ - -static int __pyx_f_2yt_9amr_utils_8GridFace_proj_overlap(struct __pyx_obj_2yt_9amr_utils_GridFace *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_left_edge, __pyx_t_5numpy_float64_t *__pyx_v_right_edge) { - int __pyx_v_xax; - int __pyx_v_yax; - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("proj_overlap"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":567 - * cdef int proj_overlap(self, np.float64_t *left_edge, np.float64_t *right_edge): - * cdef int xax, yax - * xax = (self.direction + 1) % 3 # <<<<<<<<<<<<<< - * yax = (self.direction + 2) % 3 - * if left_edge[xax] >= self.right_edge[xax]: return 0 - */ - __pyx_v_xax = __Pyx_mod_long((__pyx_v_self->direction + 1), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":568 - * cdef int xax, yax - * xax = (self.direction + 1) % 3 - * yax = (self.direction + 2) % 3 # <<<<<<<<<<<<<< - * if left_edge[xax] >= self.right_edge[xax]: return 0 - * if right_edge[xax] <= self.left_edge[xax]: return 0 - */ - __pyx_v_yax = __Pyx_mod_long((__pyx_v_self->direction + 2), 3); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":569 - * xax = (self.direction + 1) % 3 - * yax = (self.direction + 2) % 3 - * if left_edge[xax] >= self.right_edge[xax]: return 0 # <<<<<<<<<<<<<< - * if right_edge[xax] <= self.left_edge[xax]: return 0 - * if left_edge[yax] >= self.right_edge[yax]: return 0 - */ - __pyx_t_1 = ((__pyx_v_left_edge[__pyx_v_xax]) >= (__pyx_v_self->right_edge[__pyx_v_xax])); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":570 - * yax = (self.direction + 2) % 3 - * if left_edge[xax] >= self.right_edge[xax]: return 0 - * if right_edge[xax] <= self.left_edge[xax]: return 0 # <<<<<<<<<<<<<< - * if left_edge[yax] >= self.right_edge[yax]: return 0 - * if right_edge[yax] <= self.left_edge[yax]: return 0 - */ - __pyx_t_1 = ((__pyx_v_right_edge[__pyx_v_xax]) <= (__pyx_v_self->left_edge[__pyx_v_xax])); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":571 - * if left_edge[xax] >= self.right_edge[xax]: return 0 - * if right_edge[xax] <= self.left_edge[xax]: return 0 - * if left_edge[yax] >= self.right_edge[yax]: return 0 # <<<<<<<<<<<<<< - * if right_edge[yax] <= self.left_edge[yax]: return 0 - * return 1 - */ - __pyx_t_1 = ((__pyx_v_left_edge[__pyx_v_yax]) >= (__pyx_v_self->right_edge[__pyx_v_yax])); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":572 - * if right_edge[xax] <= self.left_edge[xax]: return 0 - * if left_edge[yax] >= self.right_edge[yax]: return 0 - * if right_edge[yax] <= self.left_edge[yax]: return 0 # <<<<<<<<<<<<<< - * return 1 - * - */ - __pyx_t_1 = ((__pyx_v_right_edge[__pyx_v_yax]) <= (__pyx_v_self->left_edge[__pyx_v_yax])); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":573 - * if left_edge[yax] >= self.right_edge[yax]: return 0 - * if right_edge[yax] <= self.left_edge[yax]: return 0 - * return 1 # <<<<<<<<<<<<<< - * - * cdef class ProtoPrism: - */ - __pyx_r = 1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":578 - * cdef np.float64_t left_edge[3] - * cdef np.float64_t right_edge[3] - * cdef public object LeftEdge # <<<<<<<<<<<<<< - * cdef public object RightEdge - * cdef public object subgrid_faces - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":579 - * cdef np.float64_t right_edge[3] - * cdef public object LeftEdge - * cdef public object RightEdge # <<<<<<<<<<<<<< - * cdef public object subgrid_faces - * cdef public int parent_grid_id - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":580 - * cdef public object LeftEdge - * cdef public object RightEdge - * cdef public object subgrid_faces # <<<<<<<<<<<<<< - * cdef public int parent_grid_id - * def __cinit__(self, int parent_grid_id, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - __pyx_r = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":581 - * cdef public object RightEdge - * cdef public object subgrid_faces - * cdef public int parent_grid_id # <<<<<<<<<<<<<< - * def __cinit__(self, int parent_grid_id, - * np.ndarray[np.float64_t, ndim=1] left_edge, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_14parent_grid_id___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_14parent_grid_id___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->parent_grid_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.parent_grid_id.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_14parent_grid_id___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism_14parent_grid_id___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->parent_grid_id = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.parent_grid_id.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":582 - * cdef public object subgrid_faces - * cdef public int parent_grid_id - * def __cinit__(self, int parent_grid_id, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] left_edge, - * np.ndarray[np.float64_t, ndim=1] right_edge, - */ - -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_10ProtoPrism___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_parent_grid_id; - PyArrayObject *__pyx_v_left_edge = 0; - PyArrayObject *__pyx_v_right_edge = 0; - PyObject *__pyx_v_subgrid_faces = 0; - int __pyx_v_i; - Py_buffer __pyx_bstruct_right_edge; - Py_ssize_t __pyx_bstride_0_right_edge = 0; - Py_ssize_t __pyx_bshape_0_right_edge = 0; - Py_buffer __pyx_bstruct_left_edge; - Py_ssize_t __pyx_bstride_0_left_edge = 0; - Py_ssize_t __pyx_bshape_0_left_edge = 0; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__parent_grid_id,&__pyx_n_s__left_edge,&__pyx_n_s__right_edge,&__pyx_n_s__subgrid_faces,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[4] = {0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__parent_grid_id); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edge); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edge); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__subgrid_faces); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, 3); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_parent_grid_id = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_parent_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_left_edge = ((PyArrayObject *)values[1]); - __pyx_v_right_edge = ((PyArrayObject *)values[2]); - __pyx_v_subgrid_faces = values[3]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_parent_grid_id = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_parent_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_right_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_subgrid_faces = PyTuple_GET_ITEM(__pyx_args, 3); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_left_edge.buf = NULL; - __pyx_bstruct_right_edge.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edge), __pyx_ptype_5numpy_ndarray, 1, "left_edge", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edge), __pyx_ptype_5numpy_ndarray, 1, "right_edge", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edge, (PyObject*)__pyx_v_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edge = __pyx_bstruct_left_edge.strides[0]; - __pyx_bshape_0_left_edge = __pyx_bstruct_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edge, (PyObject*)__pyx_v_right_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edge = __pyx_bstruct_right_edge.strides[0]; - __pyx_bshape_0_right_edge = __pyx_bstruct_right_edge.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":586 - * np.ndarray[np.float64_t, ndim=1] right_edge, - * subgrid_faces): - * self.parent_grid_id = parent_grid_id # <<<<<<<<<<<<<< - * cdef int i - * self.LeftEdge = left_edge - */ - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->parent_grid_id = __pyx_v_parent_grid_id; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":588 - * self.parent_grid_id = parent_grid_id - * cdef int i - * self.LeftEdge = left_edge # <<<<<<<<<<<<<< - * self.RightEdge = right_edge - * for i in range(3): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_left_edge)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_left_edge)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->LeftEdge = ((PyObject *)__pyx_v_left_edge); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":589 - * cdef int i - * self.LeftEdge = left_edge - * self.RightEdge = right_edge # <<<<<<<<<<<<<< - * for i in range(3): - * self.left_edge[i] = left_edge[i] - */ - __Pyx_INCREF(((PyObject *)__pyx_v_right_edge)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_right_edge)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->RightEdge = ((PyObject *)__pyx_v_right_edge); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":590 - * self.LeftEdge = left_edge - * self.RightEdge = right_edge - * for i in range(3): # <<<<<<<<<<<<<< - * self.left_edge[i] = left_edge[i] - * self.right_edge[i] = right_edge[i] - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":591 - * self.RightEdge = right_edge - * for i in range(3): - * self.left_edge[i] = left_edge[i] # <<<<<<<<<<<<<< - * self.right_edge[i] = right_edge[i] - * self.subgrid_faces = subgrid_faces - */ - __pyx_t_2 = __pyx_v_i; - __pyx_t_3 = -1; - if (__pyx_t_2 < 0) { - __pyx_t_2 += __pyx_bshape_0_left_edge; - if (unlikely(__pyx_t_2 < 0)) __pyx_t_3 = 0; - } else if (unlikely(__pyx_t_2 >= __pyx_bshape_0_left_edge)) __pyx_t_3 = 0; - if (unlikely(__pyx_t_3 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_3); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->left_edge[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edge.buf, __pyx_t_2, __pyx_bstride_0_left_edge)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":592 - * for i in range(3): - * self.left_edge[i] = left_edge[i] - * self.right_edge[i] = right_edge[i] # <<<<<<<<<<<<<< - * self.subgrid_faces = subgrid_faces - * - */ - __pyx_t_3 = __pyx_v_i; - __pyx_t_4 = -1; - if (__pyx_t_3 < 0) { - __pyx_t_3 += __pyx_bshape_0_right_edge; - if (unlikely(__pyx_t_3 < 0)) __pyx_t_4 = 0; - } else if (unlikely(__pyx_t_3 >= __pyx_bshape_0_right_edge)) __pyx_t_4 = 0; - if (unlikely(__pyx_t_4 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_4); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->right_edge[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edge.buf, __pyx_t_3, __pyx_bstride_0_right_edge)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":593 - * self.left_edge[i] = left_edge[i] - * self.right_edge[i] = right_edge[i] - * self.subgrid_faces = subgrid_faces # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_INCREF(__pyx_v_subgrid_faces); - __Pyx_GIVEREF(__pyx_v_subgrid_faces); - __Pyx_GOTREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - __Pyx_DECREF(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces); - ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces = __pyx_v_subgrid_faces; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edge); - __pyx_L2:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":597 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def sweep(self, int direction = 0, int stack = 0): # <<<<<<<<<<<<<< - * cdef int i - * cdef GridFace face - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_sweep(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_sweep(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_direction; - int __pyx_v_stack; - int __pyx_v_i; - struct __pyx_obj_2yt_9amr_utils_GridFace *__pyx_v_face; - __pyx_t_5numpy_float64_t __pyx_v_proto_split[3]; - PyObject *__pyx_v_left; - PyObject *__pyx_v_right; - PyObject *__pyx_v_LC; - PyObject *__pyx_v_RC; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__direction,&__pyx_n_s__stack,0}; - __Pyx_RefNannySetupContext("sweep"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__direction); - if (unlikely(value)) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__stack); - if (unlikely(value)) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "sweep") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - if (values[0]) { - __pyx_v_direction = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_direction = ((int)0); - } - if (values[1]) { - __pyx_v_stack = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_stack == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_stack = ((int)0); - } - } else { - __pyx_v_direction = ((int)0); - __pyx_v_stack = ((int)0); - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: __pyx_v_stack = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_stack == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 1: __pyx_v_direction = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("sweep", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.sweep"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_face = ((struct __pyx_obj_2yt_9amr_utils_GridFace *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_left = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_right = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_LC = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_RC = Py_None; __Pyx_INCREF(Py_None); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":601 - * cdef GridFace face - * cdef np.float64_t proto_split[3] - * for i in range(3): proto_split[i] = self.right_edge[i] # <<<<<<<<<<<<<< - * for face in self.subgrid_faces[direction]: - * proto_split[direction] = face.coord - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - (__pyx_v_proto_split[__pyx_v_i]) = (((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->right_edge[__pyx_v_i]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":602 - * cdef np.float64_t proto_split[3] - * for i in range(3): proto_split[i] = self.right_edge[i] - * for face in self.subgrid_faces[direction]: # <<<<<<<<<<<<<< - * proto_split[direction] = face.coord - * if proto_split[direction] <= self.left_edge[direction]: - */ - __pyx_t_3 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->subgrid_faces, __pyx_v_direction, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_2 = 0; __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); - } else { - __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; - } else if (likely(PyTuple_CheckExact(__pyx_t_4))) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; - } else { - __pyx_t_3 = PyIter_Next(__pyx_t_4); - if (!__pyx_t_3) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_2yt_9amr_utils_GridFace))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_v_face)); - __pyx_v_face = ((struct __pyx_obj_2yt_9amr_utils_GridFace *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":603 - * for i in range(3): proto_split[i] = self.right_edge[i] - * for face in self.subgrid_faces[direction]: - * proto_split[direction] = face.coord # <<<<<<<<<<<<<< - * if proto_split[direction] <= self.left_edge[direction]: - * continue - */ - (__pyx_v_proto_split[__pyx_v_direction]) = __pyx_v_face->coord; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":604 - * for face in self.subgrid_faces[direction]: - * proto_split[direction] = face.coord - * if proto_split[direction] <= self.left_edge[direction]: # <<<<<<<<<<<<<< - * continue - * if proto_split[direction] == self.right_edge[direction]: - */ - __pyx_t_5 = ((__pyx_v_proto_split[__pyx_v_direction]) <= (((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->left_edge[__pyx_v_direction])); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":605 - * proto_split[direction] = face.coord - * if proto_split[direction] <= self.left_edge[direction]: - * continue # <<<<<<<<<<<<<< - * if proto_split[direction] == self.right_edge[direction]: - * if stack == 2: return [self] - */ - goto __pyx_L8_continue; - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":606 - * if proto_split[direction] <= self.left_edge[direction]: - * continue - * if proto_split[direction] == self.right_edge[direction]: # <<<<<<<<<<<<<< - * if stack == 2: return [self] - * return self.sweep((direction + 1) % 3, stack + 1) - */ - __pyx_t_5 = ((__pyx_v_proto_split[__pyx_v_direction]) == (((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->right_edge[__pyx_v_direction])); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":607 - * continue - * if proto_split[direction] == self.right_edge[direction]: - * if stack == 2: return [self] # <<<<<<<<<<<<<< - * return self.sweep((direction + 1) % 3, stack + 1) - * if face.proj_overlap(self.left_edge, proto_split) == 1: - */ - __pyx_t_5 = (__pyx_v_stack == 2); - if (__pyx_t_5) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_INCREF(__pyx_v_self); - PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_self); - __Pyx_GIVEREF(__pyx_v_self); - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":608 - * if proto_split[direction] == self.right_edge[direction]: - * if stack == 2: return [self] - * return self.sweep((direction + 1) % 3, stack + 1) # <<<<<<<<<<<<<< - * if face.proj_overlap(self.left_edge, proto_split) == 1: - * left, right = self.split(proto_split, direction) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__sweep); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyInt_FromLong(__Pyx_mod_long((__pyx_v_direction + 1), 3)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyInt_FromLong((__pyx_v_stack + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":609 - * if stack == 2: return [self] - * return self.sweep((direction + 1) % 3, stack + 1) - * if face.proj_overlap(self.left_edge, proto_split) == 1: # <<<<<<<<<<<<<< - * left, right = self.split(proto_split, direction) - * LC = left.sweep((direction + 1) % 3) - */ - __pyx_t_5 = (((struct __pyx_vtabstruct_2yt_9amr_utils_GridFace *)__pyx_v_face->__pyx_vtab)->proj_overlap(__pyx_v_face, ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->left_edge, __pyx_v_proto_split) == 1); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":610 - * return self.sweep((direction + 1) % 3, stack + 1) - * if face.proj_overlap(self.left_edge, proto_split) == 1: - * left, right = self.split(proto_split, direction) # <<<<<<<<<<<<<< - * LC = left.sweep((direction + 1) % 3) - * RC = right.sweep(direction) - */ - __pyx_t_7 = ((struct __pyx_vtabstruct_2yt_9amr_utils_ProtoPrism *)((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->__pyx_vtab)->split(((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self), __pyx_v_proto_split, __pyx_v_direction); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - if (PyTuple_CheckExact(__pyx_t_7) && likely(PyTuple_GET_SIZE(__pyx_t_7) == 2)) { - PyObject* tuple = __pyx_t_7; - __pyx_t_8 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_8); - __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_v_left); - __pyx_v_left = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_v_right); - __pyx_v_right = __pyx_t_3; - __pyx_t_3 = 0; - } else { - __pyx_t_6 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_EndUnpack(__pyx_t_6, 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_v_left); - __pyx_v_left = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_v_right); - __pyx_v_right = __pyx_t_3; - __pyx_t_3 = 0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":611 - * if face.proj_overlap(self.left_edge, proto_split) == 1: - * left, right = self.split(proto_split, direction) - * LC = left.sweep((direction + 1) % 3) # <<<<<<<<<<<<<< - * RC = right.sweep(direction) - * return LC + RC - */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_left, __pyx_n_s__sweep); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyInt_FromLong(__Pyx_mod_long((__pyx_v_direction + 1), 3)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_v_LC); - __pyx_v_LC = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":612 - * left, right = self.split(proto_split, direction) - * LC = left.sweep((direction + 1) % 3) - * RC = right.sweep(direction) # <<<<<<<<<<<<<< - * return LC + RC - * raise RuntimeError - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_right, __pyx_n_s__sweep); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyInt_FromLong(__pyx_v_direction); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_v_RC); - __pyx_v_RC = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":613 - * LC = left.sweep((direction + 1) % 3) - * RC = right.sweep(direction) - * return LC + RC # <<<<<<<<<<<<<< - * raise RuntimeError - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = PyNumber_Add(__pyx_v_LC, __pyx_v_RC); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L13; - } - __pyx_L13:; - __pyx_L8_continue:; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":614 - * RC = right.sweep(direction) - * return LC + RC - * raise RuntimeError # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_Raise(__pyx_builtin_RuntimeError, 0, 0); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.sweep"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF((PyObject *)__pyx_v_face); - __Pyx_DECREF(__pyx_v_left); - __Pyx_DECREF(__pyx_v_right); - __Pyx_DECREF(__pyx_v_LC); - __Pyx_DECREF(__pyx_v_RC); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":618 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * cdef object split(self, np.float64_t *sp, int direction): # <<<<<<<<<<<<<< - * cdef int i - * cdef np.ndarray split_left = self.LeftEdge.copy() - */ - -static PyObject *__pyx_f_2yt_9amr_utils_10ProtoPrism_split(struct __pyx_obj_2yt_9amr_utils_ProtoPrism *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_sp, int __pyx_v_direction) { - int __pyx_v_i; - PyArrayObject *__pyx_v_split_left = 0; - PyArrayObject *__pyx_v_split_right = 0; - struct __pyx_obj_2yt_9amr_utils_ProtoPrism *__pyx_v_left; - struct __pyx_obj_2yt_9amr_utils_ProtoPrism *__pyx_v_right; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - __Pyx_RefNannySetupContext("split"); - __pyx_v_left = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_right = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)Py_None); __Pyx_INCREF(Py_None); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":620 - * cdef object split(self, np.float64_t *sp, int direction): - * cdef int i - * cdef np.ndarray split_left = self.LeftEdge.copy() # <<<<<<<<<<<<<< - * cdef np.ndarray split_right = self.RightEdge.copy() - * - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_self->LeftEdge, __pyx_n_s__copy); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_split_left = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":621 - * cdef int i - * cdef np.ndarray split_left = self.LeftEdge.copy() - * cdef np.ndarray split_right = self.RightEdge.copy() # <<<<<<<<<<<<<< - * - * for i in range(3): split_left[i] = self.right_edge[i] - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_self->RightEdge, __pyx_n_s__copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_split_right = ((PyArrayObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":623 - * cdef np.ndarray split_right = self.RightEdge.copy() - * - * for i in range(3): split_left[i] = self.right_edge[i] # <<<<<<<<<<<<<< - * split_left[direction] = sp[direction] - * left = ProtoPrism(self.parent_grid_id, self.LeftEdge, split_left, - */ - for (__pyx_t_3 = 0; __pyx_t_3 < 3; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->right_edge[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_split_left), __pyx_v_i, __pyx_t_1, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":624 - * - * for i in range(3): split_left[i] = self.right_edge[i] - * split_left[direction] = sp[direction] # <<<<<<<<<<<<<< - * left = ProtoPrism(self.parent_grid_id, self.LeftEdge, split_left, - * self.subgrid_faces) - */ - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_sp[__pyx_v_direction])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_split_left), __pyx_v_direction, __pyx_t_1, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":625 - * for i in range(3): split_left[i] = self.right_edge[i] - * split_left[direction] = sp[direction] - * left = ProtoPrism(self.parent_grid_id, self.LeftEdge, split_left, # <<<<<<<<<<<<<< - * self.subgrid_faces) - * - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->parent_grid_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":626 - * split_left[direction] = sp[direction] - * left = ProtoPrism(self.parent_grid_id, self.LeftEdge, split_left, - * self.subgrid_faces) # <<<<<<<<<<<<<< - * - * for i in range(3): split_right[i] = self.left_edge[i] - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_self->LeftEdge); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->LeftEdge); - __Pyx_GIVEREF(__pyx_v_self->LeftEdge); - __Pyx_INCREF(((PyObject *)__pyx_v_split_left)); - PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_split_left)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_split_left)); - __Pyx_INCREF(__pyx_v_self->subgrid_faces); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_self->subgrid_faces); - __Pyx_GIVEREF(__pyx_v_self->subgrid_faces); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_2yt_9amr_utils_ProtoPrism)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_left)); - __pyx_v_left = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":628 - * self.subgrid_faces) - * - * for i in range(3): split_right[i] = self.left_edge[i] # <<<<<<<<<<<<<< - * split_right[direction] = sp[direction] - * right = ProtoPrism(self.parent_grid_id, split_right, self.RightEdge, - */ - for (__pyx_t_3 = 0; __pyx_t_3 < 3; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->left_edge[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_split_right), __pyx_v_i, __pyx_t_1, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":629 - * - * for i in range(3): split_right[i] = self.left_edge[i] - * split_right[direction] = sp[direction] # <<<<<<<<<<<<<< - * right = ProtoPrism(self.parent_grid_id, split_right, self.RightEdge, - * self.subgrid_faces) - */ - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_sp[__pyx_v_direction])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_split_right), __pyx_v_direction, __pyx_t_1, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":630 - * for i in range(3): split_right[i] = self.left_edge[i] - * split_right[direction] = sp[direction] - * right = ProtoPrism(self.parent_grid_id, split_right, self.RightEdge, # <<<<<<<<<<<<<< - * self.subgrid_faces) - * - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->parent_grid_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":631 - * split_right[direction] = sp[direction] - * right = ProtoPrism(self.parent_grid_id, split_right, self.RightEdge, - * self.subgrid_faces) # <<<<<<<<<<<<<< - * - * return (left, right) - */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_split_right)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_split_right)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_split_right)); - __Pyx_INCREF(__pyx_v_self->RightEdge); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_self->RightEdge); - __Pyx_GIVEREF(__pyx_v_self->RightEdge); - __Pyx_INCREF(__pyx_v_self->subgrid_faces); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_self->subgrid_faces); - __Pyx_GIVEREF(__pyx_v_self->subgrid_faces); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_2yt_9amr_utils_ProtoPrism)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_right)); - __pyx_v_right = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":633 - * self.subgrid_faces) - * - * return (left, right) # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_left)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_left)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_left)); - __Pyx_INCREF(((PyObject *)__pyx_v_right)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_right)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_right)); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.split"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_split_left); - __Pyx_XDECREF((PyObject *)__pyx_v_split_right); - __Pyx_DECREF((PyObject *)__pyx_v_left); - __Pyx_DECREF((PyObject *)__pyx_v_right); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":637 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def get_brick(self, np.ndarray[np.float64_t, ndim=1] grid_left_edge, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] grid_dds, - * child_mask): - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_get_brick(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_10ProtoPrism_get_brick(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_grid_left_edge = 0; - PyArrayObject *__pyx_v_grid_dds = 0; - PyObject *__pyx_v_child_mask = 0; - int __pyx_v_li[3]; - int __pyx_v_ri[3]; - int __pyx_v_idims[3]; - int __pyx_v_i; - PyArrayObject *__pyx_v_dims = 0; - Py_buffer __pyx_bstruct_grid_dds; - Py_ssize_t __pyx_bstride_0_grid_dds = 0; - Py_ssize_t __pyx_bshape_0_grid_dds = 0; - Py_buffer __pyx_bstruct_dims; - Py_ssize_t __pyx_bstride_0_dims = 0; - Py_ssize_t __pyx_bshape_0_dims = 0; - Py_buffer __pyx_bstruct_grid_left_edge; - Py_ssize_t __pyx_bstride_0_grid_left_edge = 0; - Py_ssize_t __pyx_bshape_0_grid_left_edge = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - __pyx_t_5numpy_float64_t __pyx_t_3; - int __pyx_t_4; - __pyx_t_5numpy_float64_t __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - int __pyx_t_12; - PyArrayObject *__pyx_t_13 = NULL; - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__grid_left_edge,&__pyx_n_s__grid_dds,&__pyx_n_s__child_mask,0}; - __Pyx_RefNannySetupContext("get_brick"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[3] = {0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_left_edge); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_dds); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_brick", 1, 3, 3, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_mask); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_brick", 1, 3, 3, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "get_brick") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_grid_left_edge = ((PyArrayObject *)values[0]); - __pyx_v_grid_dds = ((PyArrayObject *)values[1]); - __pyx_v_child_mask = values[2]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_grid_left_edge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_grid_dds = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_child_mask = PyTuple_GET_ITEM(__pyx_args, 2); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_brick", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.get_brick"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_dims.buf = NULL; - __pyx_bstruct_grid_left_edge.buf = NULL; - __pyx_bstruct_grid_dds.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_left_edge), __pyx_ptype_5numpy_ndarray, 1, "grid_left_edge", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_dds), __pyx_ptype_5numpy_ndarray, 1, "grid_dds", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_left_edge, (PyObject*)__pyx_v_grid_left_edge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_left_edge = __pyx_bstruct_grid_left_edge.strides[0]; - __pyx_bshape_0_grid_left_edge = __pyx_bstruct_grid_left_edge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_dds, (PyObject*)__pyx_v_grid_dds, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_dds = __pyx_bstruct_grid_dds.strides[0]; - __pyx_bshape_0_grid_dds = __pyx_bstruct_grid_dds.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":644 - * cdef PartitionedGrid PG - * cdef int li[3], ri[3], idims[3], i - * for i in range(3): # <<<<<<<<<<<<<< - * li[i] = lrint((self.left_edge[i] - grid_left_edge[i])/grid_dds[i]) - * ri[i] = lrint((self.right_edge[i] - grid_left_edge[i])/grid_dds[i]) - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":645 - * cdef int li[3], ri[3], idims[3], i - * for i in range(3): - * li[i] = lrint((self.left_edge[i] - grid_left_edge[i])/grid_dds[i]) # <<<<<<<<<<<<<< - * ri[i] = lrint((self.right_edge[i] - grid_left_edge[i])/grid_dds[i]) - * idims[i] = ri[i] - li[i] - */ - __pyx_t_2 = __pyx_v_i; - __pyx_t_3 = ((((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->left_edge[__pyx_v_i]) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_left_edge.buf, __pyx_t_2, __pyx_bstride_0_grid_left_edge))); - __pyx_t_4 = __pyx_v_i; - __pyx_t_5 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dds.buf, __pyx_t_4, __pyx_bstride_0_grid_dds)); - if (unlikely(__pyx_t_5 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_li[__pyx_v_i]) = lrint((__pyx_t_3 / __pyx_t_5)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":646 - * for i in range(3): - * li[i] = lrint((self.left_edge[i] - grid_left_edge[i])/grid_dds[i]) - * ri[i] = lrint((self.right_edge[i] - grid_left_edge[i])/grid_dds[i]) # <<<<<<<<<<<<<< - * idims[i] = ri[i] - li[i] - * if child_mask[li[0], li[1], li[2]] == 0: return [] - */ - __pyx_t_6 = __pyx_v_i; - __pyx_t_5 = ((((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)__pyx_v_self)->right_edge[__pyx_v_i]) - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_left_edge.buf, __pyx_t_6, __pyx_bstride_0_grid_left_edge))); - __pyx_t_7 = __pyx_v_i; - __pyx_t_3 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_grid_dds.buf, __pyx_t_7, __pyx_bstride_0_grid_dds)); - if (unlikely(__pyx_t_3 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_ri[__pyx_v_i]) = lrint((__pyx_t_5 / __pyx_t_3)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":647 - * li[i] = lrint((self.left_edge[i] - grid_left_edge[i])/grid_dds[i]) - * ri[i] = lrint((self.right_edge[i] - grid_left_edge[i])/grid_dds[i]) - * idims[i] = ri[i] - li[i] # <<<<<<<<<<<<<< - * if child_mask[li[0], li[1], li[2]] == 0: return [] - * cdef np.ndarray[np.int64_t, ndim=1] dims = np.empty(3, dtype='int64') - */ - (__pyx_v_idims[__pyx_v_i]) = ((__pyx_v_ri[__pyx_v_i]) - (__pyx_v_li[__pyx_v_i])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":648 - * ri[i] = lrint((self.right_edge[i] - grid_left_edge[i])/grid_dds[i]) - * idims[i] = ri[i] - li[i] - * if child_mask[li[0], li[1], li[2]] == 0: return [] # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int64_t, ndim=1] dims = np.empty(3, dtype='int64') - * for i in range(3): - */ - __pyx_t_8 = PyInt_FromLong((__pyx_v_li[0])); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyInt_FromLong((__pyx_v_li[1])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyInt_FromLong((__pyx_v_li[2])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_GetItem(__pyx_v_child_mask, __pyx_t_11); if (!__pyx_t_10) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyObject_RichCompare(__pyx_t_10, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (__pyx_t_12) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_11)); - __pyx_r = ((PyObject *)__pyx_t_11); - __pyx_t_11 = 0; - goto __pyx_L0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":649 - * idims[i] = ri[i] - li[i] - * if child_mask[li[0], li[1], li[2]] == 0: return [] - * cdef np.ndarray[np.int64_t, ndim=1] dims = np.empty(3, dtype='int64') # <<<<<<<<<<<<<< - * for i in range(3): - * dims[i] = idims[i] - */ - __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__empty); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int64)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = PyEval_CallObjectWithKeywords(__pyx_t_10, __pyx_t_11, ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = ((PyArrayObject *)__pyx_t_8); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dims, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - __pyx_v_dims = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_dims.buf = NULL; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_dims = __pyx_bstruct_dims.strides[0]; - __pyx_bshape_0_dims = __pyx_bstruct_dims.shape[0]; - } - } - __pyx_t_13 = 0; - __pyx_v_dims = ((PyArrayObject *)__pyx_t_8); - __pyx_t_8 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":650 - * if child_mask[li[0], li[1], li[2]] == 0: return [] - * cdef np.ndarray[np.int64_t, ndim=1] dims = np.empty(3, dtype='int64') - * for i in range(3): # <<<<<<<<<<<<<< - * dims[i] = idims[i] - * #cdef np.ndarray[np.float64_t, ndim=3] new_data - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":651 - * cdef np.ndarray[np.int64_t, ndim=1] dims = np.empty(3, dtype='int64') - * for i in range(3): - * dims[i] = idims[i] # <<<<<<<<<<<<<< - * #cdef np.ndarray[np.float64_t, ndim=3] new_data - * #new_data = data[li[0]:ri[0]+1,li[1]:ri[1]+1,li[2]:ri[2]+1].copy() - */ - __pyx_t_14 = __pyx_v_i; - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dims.buf, __pyx_t_14, __pyx_bstride_0_dims) = (__pyx_v_idims[__pyx_v_i]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":656 - * #PG = PartitionedGrid(self.parent_grid_id, new_data, - * # self.LeftEdge, self.RightEdge, dims) - * return ((li[0], ri[0]), (li[1], ri[1]), (li[2], ri[2]), dims) # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = PyInt_FromLong((__pyx_v_li[0])); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyInt_FromLong((__pyx_v_ri[0])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = PyInt_FromLong((__pyx_v_li[1])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyInt_FromLong((__pyx_v_ri[1])); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_9 = 0; - __pyx_t_8 = 0; - __pyx_t_8 = PyInt_FromLong((__pyx_v_li[2])); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyInt_FromLong((__pyx_v_ri[2])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = PyTuple_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - __Pyx_INCREF(((PyObject *)__pyx_v_dims)); - PyTuple_SET_ITEM(__pyx_t_9, 3, ((PyObject *)__pyx_v_dims)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_dims)); - __pyx_t_11 = 0; - __pyx_t_10 = 0; - __pyx_t_15 = 0; - __pyx_r = __pyx_t_9; - __pyx_t_9 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_15); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dds); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dims); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_left_edge); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.ProtoPrism.get_brick"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dds); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dims); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_left_edge); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_dims); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":28 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def CICDeposit_3(np.ndarray[np.float64_t, ndim=1] posx, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=1] posy, - * np.ndarray[np.float64_t, ndim=1] posz, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_CICDeposit_3(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_CICDeposit_3(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_posx = 0; - PyArrayObject *__pyx_v_posy = 0; - PyArrayObject *__pyx_v_posz = 0; - PyArrayObject *__pyx_v_mass = 0; - __pyx_t_5numpy_int64_t __pyx_v_npositions; - PyArrayObject *__pyx_v_field = 0; - PyArrayObject *__pyx_v_leftEdge = 0; - PyArrayObject *__pyx_v_gridDimension = 0; - __pyx_t_5numpy_float64_t __pyx_v_cellSize; - int __pyx_v_i1; - int __pyx_v_j1; - int __pyx_v_k1; - int __pyx_v_n; - double __pyx_v_xpos; - double __pyx_v_ypos; - double __pyx_v_zpos; - double __pyx_v_fact; - double __pyx_v_edge0; - double __pyx_v_edge1; - double __pyx_v_edge2; - double __pyx_v_le0; - double __pyx_v_le1; - double __pyx_v_le2; - float __pyx_v_dx; - float __pyx_v_dy; - float __pyx_v_dz; - float __pyx_v_dx2; - float __pyx_v_dy2; - float __pyx_v_dz2; - Py_buffer __pyx_bstruct_field; - Py_ssize_t __pyx_bstride_0_field = 0; - Py_ssize_t __pyx_bstride_1_field = 0; - Py_ssize_t __pyx_bstride_2_field = 0; - Py_ssize_t __pyx_bshape_0_field = 0; - Py_ssize_t __pyx_bshape_1_field = 0; - Py_ssize_t __pyx_bshape_2_field = 0; - Py_buffer __pyx_bstruct_leftEdge; - Py_ssize_t __pyx_bstride_0_leftEdge = 0; - Py_ssize_t __pyx_bshape_0_leftEdge = 0; - Py_buffer __pyx_bstruct_posz; - Py_ssize_t __pyx_bstride_0_posz = 0; - Py_ssize_t __pyx_bshape_0_posz = 0; - Py_buffer __pyx_bstruct_posx; - Py_ssize_t __pyx_bstride_0_posx = 0; - Py_ssize_t __pyx_bshape_0_posx = 0; - Py_buffer __pyx_bstruct_posy; - Py_ssize_t __pyx_bstride_0_posy = 0; - Py_ssize_t __pyx_bshape_0_posy = 0; - Py_buffer __pyx_bstruct_gridDimension; - Py_ssize_t __pyx_bstride_0_gridDimension = 0; - Py_ssize_t __pyx_bshape_0_gridDimension = 0; - Py_buffer __pyx_bstruct_mass; - Py_ssize_t __pyx_bstride_0_mass = 0; - Py_ssize_t __pyx_bshape_0_mass = 0; - PyObject *__pyx_r = NULL; - long __pyx_t_1; - long __pyx_t_2; - long __pyx_t_3; - long __pyx_t_4; - long __pyx_t_5; - long __pyx_t_6; - __pyx_t_5numpy_int64_t __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - long __pyx_t_13; - long __pyx_t_14; - long __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - long __pyx_t_18; - long __pyx_t_19; - int __pyx_t_20; - long __pyx_t_21; - int __pyx_t_22; - long __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_t_26; - long __pyx_t_27; - int __pyx_t_28; - long __pyx_t_29; - long __pyx_t_30; - int __pyx_t_31; - int __pyx_t_32; - int __pyx_t_33; - long __pyx_t_34; - int __pyx_t_35; - int __pyx_t_36; - long __pyx_t_37; - int __pyx_t_38; - int __pyx_t_39; - int __pyx_t_40; - int __pyx_t_41; - int __pyx_t_42; - int __pyx_t_43; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__posx,&__pyx_n_s__posy,&__pyx_n_s__posz,&__pyx_n_s__mass,&__pyx_n_s__npositions,&__pyx_n_s__field,&__pyx_n_s__leftEdge,&__pyx_n_s__gridDimension,&__pyx_n_s__cellSize,0}; - __Pyx_RefNannySetupContext("CICDeposit_3"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__posx); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__posy); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__posz); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 2); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mass); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 3); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__npositions); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 4); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 5); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__leftEdge); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 6); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gridDimension); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 7); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 8: - values[8] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cellSize); - if (likely(values[8])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, 8); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "CICDeposit_3") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_posx = ((PyArrayObject *)values[0]); - __pyx_v_posy = ((PyArrayObject *)values[1]); - __pyx_v_posz = ((PyArrayObject *)values[2]); - __pyx_v_mass = ((PyArrayObject *)values[3]); - __pyx_v_npositions = __Pyx_PyInt_from_py_npy_int64(values[4]); if (unlikely((__pyx_v_npositions == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_field = ((PyArrayObject *)values[5]); - __pyx_v_leftEdge = ((PyArrayObject *)values[6]); - __pyx_v_gridDimension = ((PyArrayObject *)values[7]); - __pyx_v_cellSize = __pyx_PyFloat_AsDouble(values[8]); if (unlikely((__pyx_v_cellSize == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 9) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_posx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_posy = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_posz = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_mass = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_npositions = __Pyx_PyInt_from_py_npy_int64(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_npositions == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_field = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_leftEdge = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - __pyx_v_gridDimension = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 7)); - __pyx_v_cellSize = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 8)); if (unlikely((__pyx_v_cellSize == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("CICDeposit_3", 1, 9, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.CICDeposit_3"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_posx.buf = NULL; - __pyx_bstruct_posy.buf = NULL; - __pyx_bstruct_posz.buf = NULL; - __pyx_bstruct_mass.buf = NULL; - __pyx_bstruct_field.buf = NULL; - __pyx_bstruct_leftEdge.buf = NULL; - __pyx_bstruct_gridDimension.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_posx), __pyx_ptype_5numpy_ndarray, 1, "posx", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_posy), __pyx_ptype_5numpy_ndarray, 1, "posy", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_posz), __pyx_ptype_5numpy_ndarray, 1, "posz", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mass), __pyx_ptype_5numpy_ndarray, 1, "mass", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_field), __pyx_ptype_5numpy_ndarray, 1, "field", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_leftEdge), __pyx_ptype_5numpy_ndarray, 1, "leftEdge", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_gridDimension), __pyx_ptype_5numpy_ndarray, 1, "gridDimension", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_posx, (PyObject*)__pyx_v_posx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_posx = __pyx_bstruct_posx.strides[0]; - __pyx_bshape_0_posx = __pyx_bstruct_posx.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_posy, (PyObject*)__pyx_v_posy, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_posy = __pyx_bstruct_posy.strides[0]; - __pyx_bshape_0_posy = __pyx_bstruct_posy.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_posz, (PyObject*)__pyx_v_posz, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_posz = __pyx_bstruct_posz.strides[0]; - __pyx_bshape_0_posz = __pyx_bstruct_posz.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_mass, (PyObject*)__pyx_v_mass, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_mass = __pyx_bstruct_mass.strides[0]; - __pyx_bshape_0_mass = __pyx_bstruct_mass.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_field, (PyObject*)__pyx_v_field, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_field = __pyx_bstruct_field.strides[0]; __pyx_bstride_1_field = __pyx_bstruct_field.strides[1]; __pyx_bstride_2_field = __pyx_bstruct_field.strides[2]; - __pyx_bshape_0_field = __pyx_bstruct_field.shape[0]; __pyx_bshape_1_field = __pyx_bstruct_field.shape[1]; __pyx_bshape_2_field = __pyx_bstruct_field.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_leftEdge, (PyObject*)__pyx_v_leftEdge, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_leftEdge = __pyx_bstruct_leftEdge.strides[0]; - __pyx_bshape_0_leftEdge = __pyx_bstruct_leftEdge.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_gridDimension, (PyObject*)__pyx_v_gridDimension, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_gridDimension = __pyx_bstruct_gridDimension.strides[0]; - __pyx_bshape_0_gridDimension = __pyx_bstruct_gridDimension.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":44 - * cdef float dx, dy, dz, dx2, dy2, dz2 - * - * edge0 = ( gridDimension[0]) - 0.5001 # <<<<<<<<<<<<<< - * edge1 = ( gridDimension[1]) - 0.5001 - * edge2 = ( gridDimension[2]) - 0.5001 - */ - __pyx_t_1 = 0; - __pyx_v_edge0 = (((float)(*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_gridDimension.buf, __pyx_t_1, __pyx_bstride_0_gridDimension))) - 0.5001); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":45 - * - * edge0 = ( gridDimension[0]) - 0.5001 - * edge1 = ( gridDimension[1]) - 0.5001 # <<<<<<<<<<<<<< - * edge2 = ( gridDimension[2]) - 0.5001 - * fact = 1.0 / cellSize - */ - __pyx_t_2 = 1; - __pyx_v_edge1 = (((float)(*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_gridDimension.buf, __pyx_t_2, __pyx_bstride_0_gridDimension))) - 0.5001); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":46 - * edge0 = ( gridDimension[0]) - 0.5001 - * edge1 = ( gridDimension[1]) - 0.5001 - * edge2 = ( gridDimension[2]) - 0.5001 # <<<<<<<<<<<<<< - * fact = 1.0 / cellSize - * - */ - __pyx_t_3 = 2; - __pyx_v_edge2 = (((float)(*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_gridDimension.buf, __pyx_t_3, __pyx_bstride_0_gridDimension))) - 0.5001); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":47 - * edge1 = ( gridDimension[1]) - 0.5001 - * edge2 = ( gridDimension[2]) - 0.5001 - * fact = 1.0 / cellSize # <<<<<<<<<<<<<< - * - * le0 = leftEdge[0] - */ - if (unlikely(__pyx_v_cellSize == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_fact = (1.0 / __pyx_v_cellSize); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":49 - * fact = 1.0 / cellSize - * - * le0 = leftEdge[0] # <<<<<<<<<<<<<< - * le1 = leftEdge[1] - * le2 = leftEdge[2] - */ - __pyx_t_4 = 0; - __pyx_v_le0 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftEdge.buf, __pyx_t_4, __pyx_bstride_0_leftEdge)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":50 - * - * le0 = leftEdge[0] - * le1 = leftEdge[1] # <<<<<<<<<<<<<< - * le2 = leftEdge[2] - * - */ - __pyx_t_5 = 1; - __pyx_v_le1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftEdge.buf, __pyx_t_5, __pyx_bstride_0_leftEdge)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":51 - * le0 = leftEdge[0] - * le1 = leftEdge[1] - * le2 = leftEdge[2] # <<<<<<<<<<<<<< - * - * for n in range(npositions): - */ - __pyx_t_6 = 2; - __pyx_v_le2 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_leftEdge.buf, __pyx_t_6, __pyx_bstride_0_leftEdge)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":53 - * le2 = leftEdge[2] - * - * for n in range(npositions): # <<<<<<<<<<<<<< - * - * # Compute the position of the central cell - */ - __pyx_t_7 = __pyx_v_npositions; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_n = __pyx_t_8; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":56 - * - * # Compute the position of the central cell - * xpos = fmin(fmax((posx[n] - le0)*fact, 0.5001), edge0) # <<<<<<<<<<<<<< - * ypos = fmin(fmax((posy[n] - le1)*fact, 0.5001), edge1) - * zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2) - */ - __pyx_t_9 = __pyx_v_n; - __pyx_v_xpos = __pyx_f_2yt_9amr_utils_fmin(__pyx_f_2yt_9amr_utils_fmax((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_posx.buf, __pyx_t_9, __pyx_bstride_0_posx)) - __pyx_v_le0) * __pyx_v_fact), 0.5001), __pyx_v_edge0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":57 - * # Compute the position of the central cell - * xpos = fmin(fmax((posx[n] - le0)*fact, 0.5001), edge0) - * ypos = fmin(fmax((posy[n] - le1)*fact, 0.5001), edge1) # <<<<<<<<<<<<<< - * zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2) - * - */ - __pyx_t_10 = __pyx_v_n; - __pyx_v_ypos = __pyx_f_2yt_9amr_utils_fmin(__pyx_f_2yt_9amr_utils_fmax((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_posy.buf, __pyx_t_10, __pyx_bstride_0_posy)) - __pyx_v_le1) * __pyx_v_fact), 0.5001), __pyx_v_edge1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":58 - * xpos = fmin(fmax((posx[n] - le0)*fact, 0.5001), edge0) - * ypos = fmin(fmax((posy[n] - le1)*fact, 0.5001), edge1) - * zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2) # <<<<<<<<<<<<<< - * - * i1 = (xpos + 0.5) - */ - __pyx_t_11 = __pyx_v_n; - __pyx_v_zpos = __pyx_f_2yt_9amr_utils_fmin(__pyx_f_2yt_9amr_utils_fmax((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_posz.buf, __pyx_t_11, __pyx_bstride_0_posz)) - __pyx_v_le2) * __pyx_v_fact), 0.5001), __pyx_v_edge2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":60 - * zpos = fmin(fmax((posz[n] - le2)*fact, 0.5001), edge2) - * - * i1 = (xpos + 0.5) # <<<<<<<<<<<<<< - * j1 = (ypos + 0.5) - * k1 = (zpos + 0.5) - */ - __pyx_v_i1 = ((int)(__pyx_v_xpos + 0.5)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":61 - * - * i1 = (xpos + 0.5) - * j1 = (ypos + 0.5) # <<<<<<<<<<<<<< - * k1 = (zpos + 0.5) - * - */ - __pyx_v_j1 = ((int)(__pyx_v_ypos + 0.5)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":62 - * i1 = (xpos + 0.5) - * j1 = (ypos + 0.5) - * k1 = (zpos + 0.5) # <<<<<<<<<<<<<< - * - * # Compute the weights - */ - __pyx_v_k1 = ((int)(__pyx_v_zpos + 0.5)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":65 - * - * # Compute the weights - * dx = ( i1) + 0.5 - xpos # <<<<<<<<<<<<<< - * dy = ( j1) + 0.5 - ypos - * dz = ( k1) + 0.5 - zpos - */ - __pyx_v_dx = ((((float)__pyx_v_i1) + 0.5) - __pyx_v_xpos); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":66 - * # Compute the weights - * dx = ( i1) + 0.5 - xpos - * dy = ( j1) + 0.5 - ypos # <<<<<<<<<<<<<< - * dz = ( k1) + 0.5 - zpos - * dx2 = 1.0 - dx - */ - __pyx_v_dy = ((((float)__pyx_v_j1) + 0.5) - __pyx_v_ypos); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":67 - * dx = ( i1) + 0.5 - xpos - * dy = ( j1) + 0.5 - ypos - * dz = ( k1) + 0.5 - zpos # <<<<<<<<<<<<<< - * dx2 = 1.0 - dx - * dy2 = 1.0 - dy - */ - __pyx_v_dz = ((((float)__pyx_v_k1) + 0.5) - __pyx_v_zpos); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":68 - * dy = ( j1) + 0.5 - ypos - * dz = ( k1) + 0.5 - zpos - * dx2 = 1.0 - dx # <<<<<<<<<<<<<< - * dy2 = 1.0 - dy - * dz2 = 1.0 - dz - */ - __pyx_v_dx2 = (1.0 - __pyx_v_dx); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":69 - * dz = ( k1) + 0.5 - zpos - * dx2 = 1.0 - dx - * dy2 = 1.0 - dy # <<<<<<<<<<<<<< - * dz2 = 1.0 - dz - * - */ - __pyx_v_dy2 = (1.0 - __pyx_v_dy); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":70 - * dx2 = 1.0 - dx - * dy2 = 1.0 - dy - * dz2 = 1.0 - dz # <<<<<<<<<<<<<< - * - * # Interpolate from field into sumfield - */ - __pyx_v_dz2 = (1.0 - __pyx_v_dz); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":73 - * - * # Interpolate from field into sumfield - * field[i1-1,j1-1,k1-1] += mass[n] * dx * dy * dz # <<<<<<<<<<<<<< - * field[i1 ,j1-1,k1-1] += mass[n] * dx2 * dy * dz - * field[i1-1,j1 ,k1-1] += mass[n] * dx * dy2 * dz - */ - __pyx_t_12 = __pyx_v_n; - __pyx_t_13 = (__pyx_v_i1 - 1); - __pyx_t_14 = (__pyx_v_j1 - 1); - __pyx_t_15 = (__pyx_v_k1 - 1); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_13, __pyx_bstride_0_field, __pyx_t_14, __pyx_bstride_1_field, __pyx_t_15, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_12, __pyx_bstride_0_mass)) * __pyx_v_dx) * __pyx_v_dy) * __pyx_v_dz); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":74 - * # Interpolate from field into sumfield - * field[i1-1,j1-1,k1-1] += mass[n] * dx * dy * dz - * field[i1 ,j1-1,k1-1] += mass[n] * dx2 * dy * dz # <<<<<<<<<<<<<< - * field[i1-1,j1 ,k1-1] += mass[n] * dx * dy2 * dz - * field[i1 ,j1 ,k1-1] += mass[n] * dx2 * dy2 * dz - */ - __pyx_t_16 = __pyx_v_n; - __pyx_t_17 = __pyx_v_i1; - __pyx_t_18 = (__pyx_v_j1 - 1); - __pyx_t_19 = (__pyx_v_k1 - 1); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_17, __pyx_bstride_0_field, __pyx_t_18, __pyx_bstride_1_field, __pyx_t_19, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_16, __pyx_bstride_0_mass)) * __pyx_v_dx2) * __pyx_v_dy) * __pyx_v_dz); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":75 - * field[i1-1,j1-1,k1-1] += mass[n] * dx * dy * dz - * field[i1 ,j1-1,k1-1] += mass[n] * dx2 * dy * dz - * field[i1-1,j1 ,k1-1] += mass[n] * dx * dy2 * dz # <<<<<<<<<<<<<< - * field[i1 ,j1 ,k1-1] += mass[n] * dx2 * dy2 * dz - * field[i1-1,j1-1,k1 ] += mass[n] * dx * dy * dz2 - */ - __pyx_t_20 = __pyx_v_n; - __pyx_t_21 = (__pyx_v_i1 - 1); - __pyx_t_22 = __pyx_v_j1; - __pyx_t_23 = (__pyx_v_k1 - 1); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_21, __pyx_bstride_0_field, __pyx_t_22, __pyx_bstride_1_field, __pyx_t_23, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_20, __pyx_bstride_0_mass)) * __pyx_v_dx) * __pyx_v_dy2) * __pyx_v_dz); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":76 - * field[i1 ,j1-1,k1-1] += mass[n] * dx2 * dy * dz - * field[i1-1,j1 ,k1-1] += mass[n] * dx * dy2 * dz - * field[i1 ,j1 ,k1-1] += mass[n] * dx2 * dy2 * dz # <<<<<<<<<<<<<< - * field[i1-1,j1-1,k1 ] += mass[n] * dx * dy * dz2 - * field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2 - */ - __pyx_t_24 = __pyx_v_n; - __pyx_t_25 = __pyx_v_i1; - __pyx_t_26 = __pyx_v_j1; - __pyx_t_27 = (__pyx_v_k1 - 1); - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_25, __pyx_bstride_0_field, __pyx_t_26, __pyx_bstride_1_field, __pyx_t_27, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_24, __pyx_bstride_0_mass)) * __pyx_v_dx2) * __pyx_v_dy2) * __pyx_v_dz); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":77 - * field[i1-1,j1 ,k1-1] += mass[n] * dx * dy2 * dz - * field[i1 ,j1 ,k1-1] += mass[n] * dx2 * dy2 * dz - * field[i1-1,j1-1,k1 ] += mass[n] * dx * dy * dz2 # <<<<<<<<<<<<<< - * field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2 - * field[i1-1,j1 ,k1 ] += mass[n] * dx * dy2 * dz2 - */ - __pyx_t_28 = __pyx_v_n; - __pyx_t_29 = (__pyx_v_i1 - 1); - __pyx_t_30 = (__pyx_v_j1 - 1); - __pyx_t_31 = __pyx_v_k1; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_29, __pyx_bstride_0_field, __pyx_t_30, __pyx_bstride_1_field, __pyx_t_31, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_28, __pyx_bstride_0_mass)) * __pyx_v_dx) * __pyx_v_dy) * __pyx_v_dz2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":78 - * field[i1 ,j1 ,k1-1] += mass[n] * dx2 * dy2 * dz - * field[i1-1,j1-1,k1 ] += mass[n] * dx * dy * dz2 - * field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2 # <<<<<<<<<<<<<< - * field[i1-1,j1 ,k1 ] += mass[n] * dx * dy2 * dz2 - * field[i1 ,j1 ,k1 ] += mass[n] * dx2 * dy2 * dz2 - */ - __pyx_t_32 = __pyx_v_n; - __pyx_t_33 = __pyx_v_i1; - __pyx_t_34 = (__pyx_v_j1 - 1); - __pyx_t_35 = __pyx_v_k1; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_33, __pyx_bstride_0_field, __pyx_t_34, __pyx_bstride_1_field, __pyx_t_35, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_32, __pyx_bstride_0_mass)) * __pyx_v_dx2) * __pyx_v_dy) * __pyx_v_dz2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":79 - * field[i1-1,j1-1,k1 ] += mass[n] * dx * dy * dz2 - * field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2 - * field[i1-1,j1 ,k1 ] += mass[n] * dx * dy2 * dz2 # <<<<<<<<<<<<<< - * field[i1 ,j1 ,k1 ] += mass[n] * dx2 * dy2 * dz2 - */ - __pyx_t_36 = __pyx_v_n; - __pyx_t_37 = (__pyx_v_i1 - 1); - __pyx_t_38 = __pyx_v_j1; - __pyx_t_39 = __pyx_v_k1; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_37, __pyx_bstride_0_field, __pyx_t_38, __pyx_bstride_1_field, __pyx_t_39, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_36, __pyx_bstride_0_mass)) * __pyx_v_dx) * __pyx_v_dy2) * __pyx_v_dz2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/CICDeposit.pyx":80 - * field[i1 ,j1-1,k1 ] += mass[n] * dx2 * dy * dz2 - * field[i1-1,j1 ,k1 ] += mass[n] * dx * dy2 * dz2 - * field[i1 ,j1 ,k1 ] += mass[n] * dx2 * dy2 * dz2 # <<<<<<<<<<<<<< - */ - __pyx_t_40 = __pyx_v_n; - __pyx_t_41 = __pyx_v_i1; - __pyx_t_42 = __pyx_v_j1; - __pyx_t_43 = __pyx_v_k1; - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_field.buf, __pyx_t_41, __pyx_bstride_0_field, __pyx_t_42, __pyx_bstride_1_field, __pyx_t_43, __pyx_bstride_2_field) += ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_bstruct_mass.buf, __pyx_t_40, __pyx_bstride_0_mass)) * __pyx_v_dx2) * __pyx_v_dy2) * __pyx_v_dz2); - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_field); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_leftEdge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_posz); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_posx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_posy); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gridDimension); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_mass); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.CICDeposit_3"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_field); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_leftEdge); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_posz); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_posx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_posy); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gridDimension); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_mass); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":33 - * double fabs(double x) - * - * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): # <<<<<<<<<<<<<< - * if i0 > i1: return i0 - * return i1 - */ - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9amr_utils_i64max(__pyx_t_5numpy_int64_t __pyx_v_i0, __pyx_t_5numpy_int64_t __pyx_v_i1) { - __pyx_t_5numpy_int64_t __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("i64max"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":34 - * - * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): - * if i0 > i1: return i0 # <<<<<<<<<<<<<< - * return i1 - * - */ - __pyx_t_1 = (__pyx_v_i0 > __pyx_v_i1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_i0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":35 - * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): - * if i0 > i1: return i0 - * return i1 # <<<<<<<<<<<<<< - * - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - */ - __pyx_r = __pyx_v_i1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":37 - * return i1 - * - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): # <<<<<<<<<<<<<< - * if i0 < i1: return i0 - * return i1 - */ - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9amr_utils_i64min(__pyx_t_5numpy_int64_t __pyx_v_i0, __pyx_t_5numpy_int64_t __pyx_v_i1) { - __pyx_t_5numpy_int64_t __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("i64min"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":38 - * - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - * if i0 < i1: return i0 # <<<<<<<<<<<<<< - * return i1 - * - */ - __pyx_t_1 = (__pyx_v_i0 < __pyx_v_i1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_i0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":39 - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - * if i0 < i1: return i0 - * return i1 # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __pyx_r = __pyx_v_i1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":42 - * - * @cython.boundscheck(False) - * def construct_boundary_relationships( # <<<<<<<<<<<<<< - * np.ndarray[dtype=np.int64_t, ndim=3] contour_ids): - * # We only look at the boundary and one cell in - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_construct_boundary_relationships(PyObject *__pyx_self, PyObject *__pyx_v_contour_ids); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_construct_boundary_relationships(PyObject *__pyx_self, PyObject *__pyx_v_contour_ids) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_nx; - int __pyx_v_ny; - int __pyx_v_nz; - int __pyx_v_offset_i; - int __pyx_v_offset_j; - int __pyx_v_oi; - int __pyx_v_oj; - __pyx_t_5numpy_int64_t __pyx_v_c1; - __pyx_t_5numpy_int64_t __pyx_v_c2; - PyObject *__pyx_v_tree; - Py_buffer __pyx_bstruct_contour_ids; - Py_ssize_t __pyx_bstride_0_contour_ids = 0; - Py_ssize_t __pyx_bstride_1_contour_ids = 0; - Py_ssize_t __pyx_bstride_2_contour_ids = 0; - Py_ssize_t __pyx_bshape_0_contour_ids = 0; - Py_ssize_t __pyx_bshape_1_contour_ids = 0; - Py_ssize_t __pyx_bshape_2_contour_ids = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - long __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - long __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - PyObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - int __pyx_t_19; - long __pyx_t_20; - int __pyx_t_21; - long __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - long __pyx_t_26; - int __pyx_t_27; - int __pyx_t_28; - long __pyx_t_29; - int __pyx_t_30; - int __pyx_t_31; - long __pyx_t_32; - int __pyx_t_33; - int __pyx_t_34; - long __pyx_t_35; - int __pyx_t_36; - int __pyx_t_37; - int __pyx_t_38; - long __pyx_t_39; - int __pyx_t_40; - int __pyx_t_41; - long __pyx_t_42; - int __pyx_t_43; - int __pyx_t_44; - long __pyx_t_45; - int __pyx_t_46; - int __pyx_t_47; - long __pyx_t_48; - int __pyx_t_49; - __Pyx_RefNannySetupContext("construct_boundary_relationships"); - __pyx_self = __pyx_self; - __pyx_v_tree = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_contour_ids.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_contour_ids), __pyx_ptype_5numpy_ndarray, 1, "contour_ids", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_contour_ids, (PyObject*)__pyx_v_contour_ids, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_contour_ids = __pyx_bstruct_contour_ids.strides[0]; __pyx_bstride_1_contour_ids = __pyx_bstruct_contour_ids.strides[1]; __pyx_bstride_2_contour_ids = __pyx_bstruct_contour_ids.strides[2]; - __pyx_bshape_0_contour_ids = __pyx_bstruct_contour_ids.shape[0]; __pyx_bshape_1_contour_ids = __pyx_bstruct_contour_ids.shape[1]; __pyx_bshape_2_contour_ids = __pyx_bstruct_contour_ids.shape[2]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":47 - * cdef int i, j, nx, ny, nz, offset_i, offset_j, oi, oj - * cdef np.int64_t c1, c2 - * tree = [] # <<<<<<<<<<<<<< - * nx = contour_ids.shape[0] - * ny = contour_ids.shape[1] - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_tree)); - __pyx_v_tree = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":48 - * cdef np.int64_t c1, c2 - * tree = [] - * nx = contour_ids.shape[0] # <<<<<<<<<<<<<< - * ny = contour_ids.shape[1] - * nz = contour_ids.shape[2] - */ - __pyx_v_nx = (((PyArrayObject *)__pyx_v_contour_ids)->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":49 - * tree = [] - * nx = contour_ids.shape[0] - * ny = contour_ids.shape[1] # <<<<<<<<<<<<<< - * nz = contour_ids.shape[2] - * # First x-pass - */ - __pyx_v_ny = (((PyArrayObject *)__pyx_v_contour_ids)->dimensions[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":50 - * nx = contour_ids.shape[0] - * ny = contour_ids.shape[1] - * nz = contour_ids.shape[2] # <<<<<<<<<<<<<< - * # First x-pass - * for i in range(ny): - */ - __pyx_v_nz = (((PyArrayObject *)__pyx_v_contour_ids)->dimensions[2]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":52 - * nz = contour_ids.shape[2] - * # First x-pass - * for i in range(ny): # <<<<<<<<<<<<<< - * for j in range(nz): - * for offset_i in range(3): - */ - __pyx_t_2 = __pyx_v_ny; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":53 - * # First x-pass - * for i in range(ny): - * for j in range(nz): # <<<<<<<<<<<<<< - * for offset_i in range(3): - * oi = offset_i - 1 - */ - __pyx_t_4 = __pyx_v_nz; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_j = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":54 - * for i in range(ny): - * for j in range(nz): - * for offset_i in range(3): # <<<<<<<<<<<<<< - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue - */ - for (__pyx_t_6 = 0; __pyx_t_6 < 3; __pyx_t_6+=1) { - __pyx_v_offset_i = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":55 - * for j in range(nz): - * for offset_i in range(3): - * oi = offset_i - 1 # <<<<<<<<<<<<<< - * if i == 0 and oi == -1: continue - * if i == ny - 1 and oj == 1: continue - */ - __pyx_v_oi = (__pyx_v_offset_i - 1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":56 - * for offset_i in range(3): - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue # <<<<<<<<<<<<<< - * if i == ny - 1 and oj == 1: continue - * for offset_j in range(3): - */ - __pyx_t_7 = (__pyx_v_i == 0); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_oi == -1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - goto __pyx_L9_continue; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":57 - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue - * if i == ny - 1 and oj == 1: continue # <<<<<<<<<<<<<< - * for offset_j in range(3): - * oj = offset_j - 1 - */ - __pyx_t_9 = (__pyx_v_i == (__pyx_v_ny - 1)); - if (__pyx_t_9) { - __pyx_t_7 = (__pyx_v_oj == 1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - goto __pyx_L9_continue; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":58 - * if i == 0 and oi == -1: continue - * if i == ny - 1 and oj == 1: continue - * for offset_j in range(3): # <<<<<<<<<<<<<< - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue - */ - for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) { - __pyx_v_offset_j = __pyx_t_10; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":59 - * if i == ny - 1 and oj == 1: continue - * for offset_j in range(3): - * oj = offset_j - 1 # <<<<<<<<<<<<<< - * if j == 0 and oj == -1: continue - * if j == nz - 1 and oj == 1: continue - */ - __pyx_v_oj = (__pyx_v_offset_j - 1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":60 - * for offset_j in range(3): - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue # <<<<<<<<<<<<<< - * if j == nz - 1 and oj == 1: continue - * c1 = contour_ids[0, i, j] - */ - __pyx_t_8 = (__pyx_v_j == 0); - if (__pyx_t_8) { - __pyx_t_9 = (__pyx_v_oj == -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - goto __pyx_L13_continue; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":61 - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue - * if j == nz - 1 and oj == 1: continue # <<<<<<<<<<<<<< - * c1 = contour_ids[0, i, j] - * c2 = contour_ids[1, i + oi, j + oj] - */ - __pyx_t_7 = (__pyx_v_j == (__pyx_v_nz - 1)); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_oj == 1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - goto __pyx_L13_continue; - goto __pyx_L16; - } - __pyx_L16:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":62 - * if j == 0 and oj == -1: continue - * if j == nz - 1 and oj == 1: continue - * c1 = contour_ids[0, i, j] # <<<<<<<<<<<<<< - * c2 = contour_ids[1, i + oi, j + oj] - * if c1 > -1 and c2 > -1: - */ - __pyx_t_11 = 0; - __pyx_t_12 = __pyx_v_i; - __pyx_t_13 = __pyx_v_j; - if (__pyx_t_11 < 0) __pyx_t_11 += __pyx_bshape_0_contour_ids; - if (__pyx_t_12 < 0) __pyx_t_12 += __pyx_bshape_1_contour_ids; - if (__pyx_t_13 < 0) __pyx_t_13 += __pyx_bshape_2_contour_ids; - __pyx_v_c1 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_11, __pyx_bstride_0_contour_ids, __pyx_t_12, __pyx_bstride_1_contour_ids, __pyx_t_13, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":63 - * if j == nz - 1 and oj == 1: continue - * c1 = contour_ids[0, i, j] - * c2 = contour_ids[1, i + oi, j + oj] # <<<<<<<<<<<<<< - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - */ - __pyx_t_14 = 1; - __pyx_t_15 = (__pyx_v_i + __pyx_v_oi); - __pyx_t_16 = (__pyx_v_j + __pyx_v_oj); - if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_bshape_0_contour_ids; - if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_1_contour_ids; - if (__pyx_t_16 < 0) __pyx_t_16 += __pyx_bshape_2_contour_ids; - __pyx_v_c2 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_14, __pyx_bstride_0_contour_ids, __pyx_t_15, __pyx_bstride_1_contour_ids, __pyx_t_16, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":64 - * c1 = contour_ids[0, i, j] - * c2 = contour_ids[1, i + oi, j + oj] - * if c1 > -1 and c2 > -1: # <<<<<<<<<<<<<< - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[nx-1, i, j] - */ - __pyx_t_9 = (__pyx_v_c1 > -1); - if (__pyx_t_9) { - __pyx_t_7 = (__pyx_v_c2 > -1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":65 - * c2 = contour_ids[1, i + oi, j + oj] - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) # <<<<<<<<<<<<<< - * c1 = contour_ids[nx-1, i, j] - * c2 = contour_ids[nx-2, i + oi, j + oj] - */ - if (unlikely(__pyx_v_tree == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64max(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_17 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64min(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_1 = 0; - __pyx_t_17 = 0; - __pyx_t_19 = PyList_Append(((PyObject *)__pyx_v_tree), __pyx_t_18); if (unlikely(__pyx_t_19 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":66 - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[nx-1, i, j] # <<<<<<<<<<<<<< - * c2 = contour_ids[nx-2, i + oi, j + oj] - * if c1 > -1 and c2 > -1: - */ - __pyx_t_20 = (__pyx_v_nx - 1); - __pyx_t_19 = __pyx_v_i; - __pyx_t_21 = __pyx_v_j; - if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_0_contour_ids; - if (__pyx_t_19 < 0) __pyx_t_19 += __pyx_bshape_1_contour_ids; - if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_2_contour_ids; - __pyx_v_c1 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_20, __pyx_bstride_0_contour_ids, __pyx_t_19, __pyx_bstride_1_contour_ids, __pyx_t_21, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":67 - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[nx-1, i, j] - * c2 = contour_ids[nx-2, i + oi, j + oj] # <<<<<<<<<<<<<< - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - */ - __pyx_t_22 = (__pyx_v_nx - 2); - __pyx_t_23 = (__pyx_v_i + __pyx_v_oi); - __pyx_t_24 = (__pyx_v_j + __pyx_v_oj); - if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_0_contour_ids; - if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_1_contour_ids; - if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_2_contour_ids; - __pyx_v_c2 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_22, __pyx_bstride_0_contour_ids, __pyx_t_23, __pyx_bstride_1_contour_ids, __pyx_t_24, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":68 - * c1 = contour_ids[nx-1, i, j] - * c2 = contour_ids[nx-2, i + oi, j + oj] - * if c1 > -1 and c2 > -1: # <<<<<<<<<<<<<< - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * # Now y-pass - */ - __pyx_t_8 = (__pyx_v_c1 > -1); - if (__pyx_t_8) { - __pyx_t_9 = (__pyx_v_c2 > -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":69 - * c2 = contour_ids[nx-2, i + oi, j + oj] - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) # <<<<<<<<<<<<<< - * # Now y-pass - * for i in range(nx): - */ - if (unlikely(__pyx_v_tree == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_18 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64max(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_17 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64min(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_18 = 0; - __pyx_t_17 = 0; - __pyx_t_25 = PyList_Append(((PyObject *)__pyx_v_tree), __pyx_t_1); if (unlikely(__pyx_t_25 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L18; - } - __pyx_L18:; - __pyx_L13_continue:; - } - __pyx_L9_continue:; - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":71 - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * # Now y-pass - * for i in range(nx): # <<<<<<<<<<<<<< - * for j in range(nz): - * for offset_i in range(3): - */ - __pyx_t_2 = __pyx_v_nx; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":72 - * # Now y-pass - * for i in range(nx): - * for j in range(nz): # <<<<<<<<<<<<<< - * for offset_i in range(3): - * oi = offset_i - 1 - */ - __pyx_t_4 = __pyx_v_nz; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_j = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":73 - * for i in range(nx): - * for j in range(nz): - * for offset_i in range(3): # <<<<<<<<<<<<<< - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue - */ - for (__pyx_t_6 = 0; __pyx_t_6 < 3; __pyx_t_6+=1) { - __pyx_v_offset_i = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":74 - * for j in range(nz): - * for offset_i in range(3): - * oi = offset_i - 1 # <<<<<<<<<<<<<< - * if i == 0 and oi == -1: continue - * if i == nx - 1 and oj == 1: continue - */ - __pyx_v_oi = (__pyx_v_offset_i - 1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":75 - * for offset_i in range(3): - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue # <<<<<<<<<<<<<< - * if i == nx - 1 and oj == 1: continue - * for offset_j in range(3): - */ - __pyx_t_7 = (__pyx_v_i == 0); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_oi == -1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - goto __pyx_L23_continue; - goto __pyx_L25; - } - __pyx_L25:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":76 - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue - * if i == nx - 1 and oj == 1: continue # <<<<<<<<<<<<<< - * for offset_j in range(3): - * oj = offset_j - 1 - */ - __pyx_t_9 = (__pyx_v_i == (__pyx_v_nx - 1)); - if (__pyx_t_9) { - __pyx_t_7 = (__pyx_v_oj == 1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - goto __pyx_L23_continue; - goto __pyx_L26; - } - __pyx_L26:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":77 - * if i == 0 and oi == -1: continue - * if i == nx - 1 and oj == 1: continue - * for offset_j in range(3): # <<<<<<<<<<<<<< - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue - */ - for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) { - __pyx_v_offset_j = __pyx_t_10; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":78 - * if i == nx - 1 and oj == 1: continue - * for offset_j in range(3): - * oj = offset_j - 1 # <<<<<<<<<<<<<< - * if j == 0 and oj == -1: continue - * if j == nz - 1 and oj == 1: continue - */ - __pyx_v_oj = (__pyx_v_offset_j - 1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":79 - * for offset_j in range(3): - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue # <<<<<<<<<<<<<< - * if j == nz - 1 and oj == 1: continue - * c1 = contour_ids[i, 0, j] - */ - __pyx_t_8 = (__pyx_v_j == 0); - if (__pyx_t_8) { - __pyx_t_9 = (__pyx_v_oj == -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - goto __pyx_L27_continue; - goto __pyx_L29; - } - __pyx_L29:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":80 - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue - * if j == nz - 1 and oj == 1: continue # <<<<<<<<<<<<<< - * c1 = contour_ids[i, 0, j] - * c2 = contour_ids[i + oi, 1, j + oj] - */ - __pyx_t_7 = (__pyx_v_j == (__pyx_v_nz - 1)); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_oj == 1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - goto __pyx_L27_continue; - goto __pyx_L30; - } - __pyx_L30:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":81 - * if j == 0 and oj == -1: continue - * if j == nz - 1 and oj == 1: continue - * c1 = contour_ids[i, 0, j] # <<<<<<<<<<<<<< - * c2 = contour_ids[i + oi, 1, j + oj] - * if c1 > -1 and c2 > -1: - */ - __pyx_t_25 = __pyx_v_i; - __pyx_t_26 = 0; - __pyx_t_27 = __pyx_v_j; - if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_0_contour_ids; - if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_1_contour_ids; - if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_2_contour_ids; - __pyx_v_c1 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_25, __pyx_bstride_0_contour_ids, __pyx_t_26, __pyx_bstride_1_contour_ids, __pyx_t_27, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":82 - * if j == nz - 1 and oj == 1: continue - * c1 = contour_ids[i, 0, j] - * c2 = contour_ids[i + oi, 1, j + oj] # <<<<<<<<<<<<<< - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - */ - __pyx_t_28 = (__pyx_v_i + __pyx_v_oi); - __pyx_t_29 = 1; - __pyx_t_30 = (__pyx_v_j + __pyx_v_oj); - if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_0_contour_ids; - if (__pyx_t_29 < 0) __pyx_t_29 += __pyx_bshape_1_contour_ids; - if (__pyx_t_30 < 0) __pyx_t_30 += __pyx_bshape_2_contour_ids; - __pyx_v_c2 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_28, __pyx_bstride_0_contour_ids, __pyx_t_29, __pyx_bstride_1_contour_ids, __pyx_t_30, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":83 - * c1 = contour_ids[i, 0, j] - * c2 = contour_ids[i + oi, 1, j + oj] - * if c1 > -1 and c2 > -1: # <<<<<<<<<<<<<< - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[i, ny-1, j] - */ - __pyx_t_9 = (__pyx_v_c1 > -1); - if (__pyx_t_9) { - __pyx_t_7 = (__pyx_v_c2 > -1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":84 - * c2 = contour_ids[i + oi, 1, j + oj] - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) # <<<<<<<<<<<<<< - * c1 = contour_ids[i, ny-1, j] - * c2 = contour_ids[i + oi, ny-2, j + oj] - */ - if (unlikely(__pyx_v_tree == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64max(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_17 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64min(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_1 = 0; - __pyx_t_17 = 0; - __pyx_t_31 = PyList_Append(((PyObject *)__pyx_v_tree), __pyx_t_18); if (unlikely(__pyx_t_31 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - goto __pyx_L31; - } - __pyx_L31:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":85 - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[i, ny-1, j] # <<<<<<<<<<<<<< - * c2 = contour_ids[i + oi, ny-2, j + oj] - * if c1 > -1 and c2 > -1: - */ - __pyx_t_31 = __pyx_v_i; - __pyx_t_32 = (__pyx_v_ny - 1); - __pyx_t_33 = __pyx_v_j; - if (__pyx_t_31 < 0) __pyx_t_31 += __pyx_bshape_0_contour_ids; - if (__pyx_t_32 < 0) __pyx_t_32 += __pyx_bshape_1_contour_ids; - if (__pyx_t_33 < 0) __pyx_t_33 += __pyx_bshape_2_contour_ids; - __pyx_v_c1 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_31, __pyx_bstride_0_contour_ids, __pyx_t_32, __pyx_bstride_1_contour_ids, __pyx_t_33, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":86 - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[i, ny-1, j] - * c2 = contour_ids[i + oi, ny-2, j + oj] # <<<<<<<<<<<<<< - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - */ - __pyx_t_34 = (__pyx_v_i + __pyx_v_oi); - __pyx_t_35 = (__pyx_v_ny - 2); - __pyx_t_36 = (__pyx_v_j + __pyx_v_oj); - if (__pyx_t_34 < 0) __pyx_t_34 += __pyx_bshape_0_contour_ids; - if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_bshape_1_contour_ids; - if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_bshape_2_contour_ids; - __pyx_v_c2 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_34, __pyx_bstride_0_contour_ids, __pyx_t_35, __pyx_bstride_1_contour_ids, __pyx_t_36, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":87 - * c1 = contour_ids[i, ny-1, j] - * c2 = contour_ids[i + oi, ny-2, j + oj] - * if c1 > -1 and c2 > -1: # <<<<<<<<<<<<<< - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * for i in range(nx): - */ - __pyx_t_8 = (__pyx_v_c1 > -1); - if (__pyx_t_8) { - __pyx_t_9 = (__pyx_v_c2 > -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":88 - * c2 = contour_ids[i + oi, ny-2, j + oj] - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) # <<<<<<<<<<<<<< - * for i in range(nx): - * for j in range(ny): - */ - if (unlikely(__pyx_v_tree == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_18 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64max(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_17 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64min(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_18 = 0; - __pyx_t_17 = 0; - __pyx_t_37 = PyList_Append(((PyObject *)__pyx_v_tree), __pyx_t_1); if (unlikely(__pyx_t_37 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L32; - } - __pyx_L32:; - __pyx_L27_continue:; - } - __pyx_L23_continue:; - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":89 - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * for i in range(nx): # <<<<<<<<<<<<<< - * for j in range(ny): - * for offset_i in range(3): - */ - __pyx_t_2 = __pyx_v_nx; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":90 - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * for i in range(nx): - * for j in range(ny): # <<<<<<<<<<<<<< - * for offset_i in range(3): - * oi = offset_i - 1 - */ - __pyx_t_4 = __pyx_v_ny; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_j = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":91 - * for i in range(nx): - * for j in range(ny): - * for offset_i in range(3): # <<<<<<<<<<<<<< - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue - */ - for (__pyx_t_6 = 0; __pyx_t_6 < 3; __pyx_t_6+=1) { - __pyx_v_offset_i = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":92 - * for j in range(ny): - * for offset_i in range(3): - * oi = offset_i - 1 # <<<<<<<<<<<<<< - * if i == 0 and oi == -1: continue - * if i == nx - 1 and oj == 1: continue - */ - __pyx_v_oi = (__pyx_v_offset_i - 1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":93 - * for offset_i in range(3): - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue # <<<<<<<<<<<<<< - * if i == nx - 1 and oj == 1: continue - * for offset_j in range(3): - */ - __pyx_t_7 = (__pyx_v_i == 0); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_oi == -1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - goto __pyx_L37_continue; - goto __pyx_L39; - } - __pyx_L39:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":94 - * oi = offset_i - 1 - * if i == 0 and oi == -1: continue - * if i == nx - 1 and oj == 1: continue # <<<<<<<<<<<<<< - * for offset_j in range(3): - * oj = offset_j - 1 - */ - __pyx_t_9 = (__pyx_v_i == (__pyx_v_nx - 1)); - if (__pyx_t_9) { - __pyx_t_7 = (__pyx_v_oj == 1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - goto __pyx_L37_continue; - goto __pyx_L40; - } - __pyx_L40:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":95 - * if i == 0 and oi == -1: continue - * if i == nx - 1 and oj == 1: continue - * for offset_j in range(3): # <<<<<<<<<<<<<< - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue - */ - for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) { - __pyx_v_offset_j = __pyx_t_10; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":96 - * if i == nx - 1 and oj == 1: continue - * for offset_j in range(3): - * oj = offset_j - 1 # <<<<<<<<<<<<<< - * if j == 0 and oj == -1: continue - * if j == ny - 1 and oj == 1: continue - */ - __pyx_v_oj = (__pyx_v_offset_j - 1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":97 - * for offset_j in range(3): - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue # <<<<<<<<<<<<<< - * if j == ny - 1 and oj == 1: continue - * c1 = contour_ids[i, j, 0] - */ - __pyx_t_8 = (__pyx_v_j == 0); - if (__pyx_t_8) { - __pyx_t_9 = (__pyx_v_oj == -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - goto __pyx_L41_continue; - goto __pyx_L43; - } - __pyx_L43:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":98 - * oj = offset_j - 1 - * if j == 0 and oj == -1: continue - * if j == ny - 1 and oj == 1: continue # <<<<<<<<<<<<<< - * c1 = contour_ids[i, j, 0] - * c2 = contour_ids[i + oi, j + oj, 1] - */ - __pyx_t_7 = (__pyx_v_j == (__pyx_v_ny - 1)); - if (__pyx_t_7) { - __pyx_t_8 = (__pyx_v_oj == 1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - goto __pyx_L41_continue; - goto __pyx_L44; - } - __pyx_L44:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":99 - * if j == 0 and oj == -1: continue - * if j == ny - 1 and oj == 1: continue - * c1 = contour_ids[i, j, 0] # <<<<<<<<<<<<<< - * c2 = contour_ids[i + oi, j + oj, 1] - * if c1 > -1 and c2 > -1: - */ - __pyx_t_37 = __pyx_v_i; - __pyx_t_38 = __pyx_v_j; - __pyx_t_39 = 0; - if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_bshape_0_contour_ids; - if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_bshape_1_contour_ids; - if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_bshape_2_contour_ids; - __pyx_v_c1 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_37, __pyx_bstride_0_contour_ids, __pyx_t_38, __pyx_bstride_1_contour_ids, __pyx_t_39, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":100 - * if j == ny - 1 and oj == 1: continue - * c1 = contour_ids[i, j, 0] - * c2 = contour_ids[i + oi, j + oj, 1] # <<<<<<<<<<<<<< - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - */ - __pyx_t_40 = (__pyx_v_i + __pyx_v_oi); - __pyx_t_41 = (__pyx_v_j + __pyx_v_oj); - __pyx_t_42 = 1; - if (__pyx_t_40 < 0) __pyx_t_40 += __pyx_bshape_0_contour_ids; - if (__pyx_t_41 < 0) __pyx_t_41 += __pyx_bshape_1_contour_ids; - if (__pyx_t_42 < 0) __pyx_t_42 += __pyx_bshape_2_contour_ids; - __pyx_v_c2 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_40, __pyx_bstride_0_contour_ids, __pyx_t_41, __pyx_bstride_1_contour_ids, __pyx_t_42, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":101 - * c1 = contour_ids[i, j, 0] - * c2 = contour_ids[i + oi, j + oj, 1] - * if c1 > -1 and c2 > -1: # <<<<<<<<<<<<<< - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[i, j, nz-1] - */ - __pyx_t_9 = (__pyx_v_c1 > -1); - if (__pyx_t_9) { - __pyx_t_7 = (__pyx_v_c2 > -1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":102 - * c2 = contour_ids[i + oi, j + oj, 1] - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) # <<<<<<<<<<<<<< - * c1 = contour_ids[i, j, nz-1] - * c2 = contour_ids[i + oi, j + oj, nz-2] - */ - if (unlikely(__pyx_v_tree == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64max(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_17 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64min(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_18 = PyTuple_New(2); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_1 = 0; - __pyx_t_17 = 0; - __pyx_t_43 = PyList_Append(((PyObject *)__pyx_v_tree), __pyx_t_18); if (unlikely(__pyx_t_43 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - goto __pyx_L45; - } - __pyx_L45:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":103 - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[i, j, nz-1] # <<<<<<<<<<<<<< - * c2 = contour_ids[i + oi, j + oj, nz-2] - * if c1 > -1 and c2 > -1: - */ - __pyx_t_43 = __pyx_v_i; - __pyx_t_44 = __pyx_v_j; - __pyx_t_45 = (__pyx_v_nz - 1); - if (__pyx_t_43 < 0) __pyx_t_43 += __pyx_bshape_0_contour_ids; - if (__pyx_t_44 < 0) __pyx_t_44 += __pyx_bshape_1_contour_ids; - if (__pyx_t_45 < 0) __pyx_t_45 += __pyx_bshape_2_contour_ids; - __pyx_v_c1 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_43, __pyx_bstride_0_contour_ids, __pyx_t_44, __pyx_bstride_1_contour_ids, __pyx_t_45, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":104 - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * c1 = contour_ids[i, j, nz-1] - * c2 = contour_ids[i + oi, j + oj, nz-2] # <<<<<<<<<<<<<< - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - */ - __pyx_t_46 = (__pyx_v_i + __pyx_v_oi); - __pyx_t_47 = (__pyx_v_j + __pyx_v_oj); - __pyx_t_48 = (__pyx_v_nz - 2); - if (__pyx_t_46 < 0) __pyx_t_46 += __pyx_bshape_0_contour_ids; - if (__pyx_t_47 < 0) __pyx_t_47 += __pyx_bshape_1_contour_ids; - if (__pyx_t_48 < 0) __pyx_t_48 += __pyx_bshape_2_contour_ids; - __pyx_v_c2 = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_contour_ids.buf, __pyx_t_46, __pyx_bstride_0_contour_ids, __pyx_t_47, __pyx_bstride_1_contour_ids, __pyx_t_48, __pyx_bstride_2_contour_ids)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":105 - * c1 = contour_ids[i, j, nz-1] - * c2 = contour_ids[i + oi, j + oj, nz-2] - * if c1 > -1 and c2 > -1: # <<<<<<<<<<<<<< - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * return tree - */ - __pyx_t_8 = (__pyx_v_c1 > -1); - if (__pyx_t_8) { - __pyx_t_9 = (__pyx_v_c2 > -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":106 - * c2 = contour_ids[i + oi, j + oj, nz-2] - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) # <<<<<<<<<<<<<< - * return tree - * - */ - if (unlikely(__pyx_v_tree == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_18 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64max(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_17 = __Pyx_PyInt_to_py_npy_int64(__pyx_f_2yt_9amr_utils_i64min(__pyx_v_c1, __pyx_v_c2)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_17); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_17); - __Pyx_GIVEREF(__pyx_t_17); - __pyx_t_18 = 0; - __pyx_t_17 = 0; - __pyx_t_49 = PyList_Append(((PyObject *)__pyx_v_tree), __pyx_t_1); if (unlikely(__pyx_t_49 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L46; - } - __pyx_L46:; - __pyx_L41_continue:; - } - __pyx_L37_continue:; - } - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":107 - * if c1 > -1 and c2 > -1: - * tree.append((i64max(c1,c2), i64min(c1,c2))) - * return tree # <<<<<<<<<<<<<< - * - * cdef inline int are_neighbors( - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_tree)); - __pyx_r = ((PyObject *)__pyx_v_tree); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_17); - __Pyx_XDECREF(__pyx_t_18); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_contour_ids); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.construct_boundary_relationships"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_contour_ids); - __pyx_L2:; - __Pyx_DECREF(__pyx_v_tree); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":109 - * return tree - * - * cdef inline int are_neighbors( # <<<<<<<<<<<<<< - * np.float64_t x1, np.float64_t y1, np.float64_t z1, - * np.float64_t dx1, np.float64_t dy1, np.float64_t dz1, - */ - -static CYTHON_INLINE int __pyx_f_2yt_9amr_utils_are_neighbors(__pyx_t_5numpy_float64_t __pyx_v_x1, __pyx_t_5numpy_float64_t __pyx_v_y1, __pyx_t_5numpy_float64_t __pyx_v_z1, __pyx_t_5numpy_float64_t __pyx_v_dx1, __pyx_t_5numpy_float64_t __pyx_v_dy1, __pyx_t_5numpy_float64_t __pyx_v_dz1, __pyx_t_5numpy_float64_t __pyx_v_x2, __pyx_t_5numpy_float64_t __pyx_v_y2, __pyx_t_5numpy_float64_t __pyx_v_z2, __pyx_t_5numpy_float64_t __pyx_v_dx2, __pyx_t_5numpy_float64_t __pyx_v_dy2, __pyx_t_5numpy_float64_t __pyx_v_dz2) { - int __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("are_neighbors"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":116 - * ): - * # We assume an epsilon of 1e-15 - * if fabs(x1-x2) > 0.5*(dx1+dx2): return 0 # <<<<<<<<<<<<<< - * if fabs(y1-y2) > 0.5*(dy1+dy2): return 0 - * if fabs(z1-z2) > 0.5*(dz1+dz2): return 0 - */ - __pyx_t_1 = (fabs((__pyx_v_x1 - __pyx_v_x2)) > (0.5 * (__pyx_v_dx1 + __pyx_v_dx2))); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":117 - * # We assume an epsilon of 1e-15 - * if fabs(x1-x2) > 0.5*(dx1+dx2): return 0 - * if fabs(y1-y2) > 0.5*(dy1+dy2): return 0 # <<<<<<<<<<<<<< - * if fabs(z1-z2) > 0.5*(dz1+dz2): return 0 - * return 1 - */ - __pyx_t_1 = (fabs((__pyx_v_y1 - __pyx_v_y2)) > (0.5 * (__pyx_v_dy1 + __pyx_v_dy2))); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":118 - * if fabs(x1-x2) > 0.5*(dx1+dx2): return 0 - * if fabs(y1-y2) > 0.5*(dy1+dy2): return 0 - * if fabs(z1-z2) > 0.5*(dz1+dz2): return 0 # <<<<<<<<<<<<<< - * return 1 - * - */ - __pyx_t_1 = (fabs((__pyx_v_z1 - __pyx_v_z2)) > (0.5 * (__pyx_v_dz1 + __pyx_v_dz2))); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":119 - * if fabs(y1-y2) > 0.5*(dy1+dy2): return 0 - * if fabs(z1-z2) > 0.5*(dz1+dz2): return 0 - * return 1 # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __pyx_r = 1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":123 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def identify_field_neighbors( # <<<<<<<<<<<<<< - * np.ndarray[dtype=np.float64_t, ndim=1] field, - * np.ndarray[dtype=np.float64_t, ndim=1] x, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_identify_field_neighbors(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_identify_field_neighbors(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_field = 0; - PyArrayObject *__pyx_v_x = 0; - PyArrayObject *__pyx_v_y = 0; - PyArrayObject *__pyx_v_z = 0; - PyArrayObject *__pyx_v_dx = 0; - PyArrayObject *__pyx_v_dy = 0; - PyArrayObject *__pyx_v_dz = 0; - int __pyx_v_outer; - int __pyx_v_inner; - int __pyx_v_N; - int __pyx_v_added; - __pyx_t_5numpy_float64_t __pyx_v_x1; - __pyx_t_5numpy_float64_t __pyx_v_y1; - __pyx_t_5numpy_float64_t __pyx_v_z1; - __pyx_t_5numpy_float64_t __pyx_v_dx1; - __pyx_t_5numpy_float64_t __pyx_v_dy1; - __pyx_t_5numpy_float64_t __pyx_v_dz1; - PyObject *__pyx_v_joins; - PyObject *__pyx_v_this_joins; - Py_buffer __pyx_bstruct_field; - Py_ssize_t __pyx_bstride_0_field = 0; - Py_ssize_t __pyx_bshape_0_field = 0; - Py_buffer __pyx_bstruct_dz; - Py_ssize_t __pyx_bstride_0_dz = 0; - Py_ssize_t __pyx_bshape_0_dz = 0; - Py_buffer __pyx_bstruct_dx; - Py_ssize_t __pyx_bstride_0_dx = 0; - Py_ssize_t __pyx_bshape_0_dx = 0; - Py_buffer __pyx_bstruct_dy; - Py_ssize_t __pyx_bstride_0_dy = 0; - Py_ssize_t __pyx_bshape_0_dy = 0; - Py_buffer __pyx_bstruct_y; - Py_ssize_t __pyx_bstride_0_y = 0; - Py_ssize_t __pyx_bshape_0_y = 0; - Py_buffer __pyx_bstruct_x; - Py_ssize_t __pyx_bstride_0_x = 0; - Py_ssize_t __pyx_bshape_0_x = 0; - Py_buffer __pyx_bstruct_z; - Py_ssize_t __pyx_bstride_0_z = 0; - Py_ssize_t __pyx_bshape_0_z = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__field,&__pyx_n_s__x,&__pyx_n_s__y,&__pyx_n_s__z,&__pyx_n_s__dx,&__pyx_n_s__dy,&__pyx_n_s__dz,0}; - __Pyx_RefNannySetupContext("identify_field_neighbors"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[7] = {0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, 1); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, 2); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__z); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, 3); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, 4); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dy); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, 5); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dz); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, 6); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "identify_field_neighbors") < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_field = ((PyArrayObject *)values[0]); - __pyx_v_x = ((PyArrayObject *)values[1]); - __pyx_v_y = ((PyArrayObject *)values[2]); - __pyx_v_z = ((PyArrayObject *)values[3]); - __pyx_v_dx = ((PyArrayObject *)values[4]); - __pyx_v_dy = ((PyArrayObject *)values[5]); - __pyx_v_dz = ((PyArrayObject *)values[6]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_field = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_x = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_y = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_z = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_dx = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_dy = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - __pyx_v_dz = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 6)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("identify_field_neighbors", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.identify_field_neighbors"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_joins = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_this_joins = Py_None; __Pyx_INCREF(Py_None); - __pyx_bstruct_field.buf = NULL; - __pyx_bstruct_x.buf = NULL; - __pyx_bstruct_y.buf = NULL; - __pyx_bstruct_z.buf = NULL; - __pyx_bstruct_dx.buf = NULL; - __pyx_bstruct_dy.buf = NULL; - __pyx_bstruct_dz.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_field), __pyx_ptype_5numpy_ndarray, 1, "field", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5numpy_ndarray, 1, "x", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5numpy_ndarray, 1, "y", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_z), __pyx_ptype_5numpy_ndarray, 1, "z", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dx), __pyx_ptype_5numpy_ndarray, 1, "dx", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dy), __pyx_ptype_5numpy_ndarray, 1, "dy", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dz), __pyx_ptype_5numpy_ndarray, 1, "dz", 0))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_field, (PyObject*)__pyx_v_field, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_field = __pyx_bstruct_field.strides[0]; - __pyx_bshape_0_field = __pyx_bstruct_field.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_x, (PyObject*)__pyx_v_x, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_x = __pyx_bstruct_x.strides[0]; - __pyx_bshape_0_x = __pyx_bstruct_x.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_y, (PyObject*)__pyx_v_y, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_y = __pyx_bstruct_y.strides[0]; - __pyx_bshape_0_y = __pyx_bstruct_y.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_z, (PyObject*)__pyx_v_z, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_z = __pyx_bstruct_z.strides[0]; - __pyx_bshape_0_z = __pyx_bstruct_z.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dx, (PyObject*)__pyx_v_dx, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dx = __pyx_bstruct_dx.strides[0]; - __pyx_bshape_0_dx = __pyx_bstruct_dx.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dy, (PyObject*)__pyx_v_dy, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dy = __pyx_bstruct_dy.strides[0]; - __pyx_bshape_0_dy = __pyx_bstruct_dy.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dz, (PyObject*)__pyx_v_dz, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dz = __pyx_bstruct_dz.strides[0]; - __pyx_bshape_0_dz = __pyx_bstruct_dz.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":135 - * cdef int outer, inner, N, added - * cdef np.float64_t x1, y1, z1, dx1, dy1, dz1 - * N = field.shape[0] # <<<<<<<<<<<<<< - * #cdef np.ndarray[dtype=np.object_t] joins - * joins = [[] for outer in range(N)] - */ - __pyx_v_N = (__pyx_v_field->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":137 - * N = field.shape[0] - * #cdef np.ndarray[dtype=np.object_t] joins - * joins = [[] for outer in range(N)] # <<<<<<<<<<<<<< - * #joins = np.empty(N, dtype='object') - * for outer in range(N): - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = __pyx_v_N; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_outer = __pyx_t_3; - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (unlikely(PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - } - __Pyx_INCREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_joins)); - __pyx_v_joins = __pyx_t_1; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":139 - * joins = [[] for outer in range(N)] - * #joins = np.empty(N, dtype='object') - * for outer in range(N): # <<<<<<<<<<<<<< - * if (outer % 10000) == 0: print outer, N - * x1 = x[outer] - */ - __pyx_t_2 = __pyx_v_N; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_outer = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":140 - * #joins = np.empty(N, dtype='object') - * for outer in range(N): - * if (outer % 10000) == 0: print outer, N # <<<<<<<<<<<<<< - * x1 = x[outer] - * y1 = y[outer] - */ - __pyx_t_5 = (__Pyx_mod_long(__pyx_v_outer, 10000) == 0); - if (__pyx_t_5) { - __pyx_t_1 = PyInt_FromLong(__pyx_v_outer); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - if (__Pyx_Print(0, __pyx_t_6, 1) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":141 - * for outer in range(N): - * if (outer % 10000) == 0: print outer, N - * x1 = x[outer] # <<<<<<<<<<<<<< - * y1 = y[outer] - * z1 = z[outer] - */ - __pyx_t_7 = __pyx_v_outer; - __pyx_v_x1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x.buf, __pyx_t_7, __pyx_bstride_0_x)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":142 - * if (outer % 10000) == 0: print outer, N - * x1 = x[outer] - * y1 = y[outer] # <<<<<<<<<<<<<< - * z1 = z[outer] - * dx1 = dx[outer] - */ - __pyx_t_8 = __pyx_v_outer; - __pyx_v_y1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y.buf, __pyx_t_8, __pyx_bstride_0_y)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":143 - * x1 = x[outer] - * y1 = y[outer] - * z1 = z[outer] # <<<<<<<<<<<<<< - * dx1 = dx[outer] - * dy1 = dy[outer] - */ - __pyx_t_9 = __pyx_v_outer; - __pyx_v_z1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z.buf, __pyx_t_9, __pyx_bstride_0_z)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":144 - * y1 = y[outer] - * z1 = z[outer] - * dx1 = dx[outer] # <<<<<<<<<<<<<< - * dy1 = dy[outer] - * dz1 = dz[outer] - */ - __pyx_t_10 = __pyx_v_outer; - __pyx_v_dx1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_10, __pyx_bstride_0_dx)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":145 - * z1 = z[outer] - * dx1 = dx[outer] - * dy1 = dy[outer] # <<<<<<<<<<<<<< - * dz1 = dz[outer] - * this_joins = joins[outer] - */ - __pyx_t_11 = __pyx_v_outer; - __pyx_v_dy1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dy.buf, __pyx_t_11, __pyx_bstride_0_dy)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":146 - * dx1 = dx[outer] - * dy1 = dy[outer] - * dz1 = dz[outer] # <<<<<<<<<<<<<< - * this_joins = joins[outer] - * added = 0 - */ - __pyx_t_12 = __pyx_v_outer; - __pyx_v_dz1 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dz.buf, __pyx_t_12, __pyx_bstride_0_dz)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":147 - * dy1 = dy[outer] - * dz1 = dz[outer] - * this_joins = joins[outer] # <<<<<<<<<<<<<< - * added = 0 - * # Go in reverse order - */ - __pyx_t_6 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_joins), __pyx_v_outer, sizeof(int), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_v_this_joins); - __pyx_v_this_joins = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":148 - * dz1 = dz[outer] - * this_joins = joins[outer] - * added = 0 # <<<<<<<<<<<<<< - * # Go in reverse order - * for inner in range(outer, 0, -1): - */ - __pyx_v_added = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":150 - * added = 0 - * # Go in reverse order - * for inner in range(outer, 0, -1): # <<<<<<<<<<<<<< - * if not are_neighbors(x1, y1, z1, dx1, dy1, dz1, - * x[inner], y[inner], z[inner], - */ - for (__pyx_t_13 = __pyx_v_outer; __pyx_t_13 > 0; __pyx_t_13-=1) { - __pyx_v_inner = __pyx_t_13; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":152 - * for inner in range(outer, 0, -1): - * if not are_neighbors(x1, y1, z1, dx1, dy1, dz1, - * x[inner], y[inner], z[inner], # <<<<<<<<<<<<<< - * dx[inner], dy[inner], dz[inner]): - * continue - */ - __pyx_t_14 = __pyx_v_inner; - __pyx_t_15 = __pyx_v_inner; - __pyx_t_16 = __pyx_v_inner; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":153 - * if not are_neighbors(x1, y1, z1, dx1, dy1, dz1, - * x[inner], y[inner], z[inner], - * dx[inner], dy[inner], dz[inner]): # <<<<<<<<<<<<<< - * continue - * # Hot dog, we have a weiner! - */ - __pyx_t_17 = __pyx_v_inner; - __pyx_t_18 = __pyx_v_inner; - __pyx_t_19 = __pyx_v_inner; - __pyx_t_5 = (!__pyx_f_2yt_9amr_utils_are_neighbors(__pyx_v_x1, __pyx_v_y1, __pyx_v_z1, __pyx_v_dx1, __pyx_v_dy1, __pyx_v_dz1, (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_x.buf, __pyx_t_14, __pyx_bstride_0_x)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_y.buf, __pyx_t_15, __pyx_bstride_0_y)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_z.buf, __pyx_t_16, __pyx_bstride_0_z)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dx.buf, __pyx_t_17, __pyx_bstride_0_dx)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dy.buf, __pyx_t_18, __pyx_bstride_0_dy)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_dz.buf, __pyx_t_19, __pyx_bstride_0_dz)))); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":154 - * x[inner], y[inner], z[inner], - * dx[inner], dy[inner], dz[inner]): - * continue # <<<<<<<<<<<<<< - * # Hot dog, we have a weiner! - * this_joins.append(inner) - */ - goto __pyx_L11_continue; - goto __pyx_L13; - } - __pyx_L13:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":156 - * continue - * # Hot dog, we have a weiner! - * this_joins.append(inner) # <<<<<<<<<<<<<< - * added += 1 - * if added == 26: break - */ - __pyx_t_6 = PyInt_FromLong(__pyx_v_inner); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_this_joins, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":157 - * # Hot dog, we have a weiner! - * this_joins.append(inner) - * added += 1 # <<<<<<<<<<<<<< - * if added == 26: break - * return joins - */ - __pyx_v_added += 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":158 - * this_joins.append(inner) - * added += 1 - * if added == 26: break # <<<<<<<<<<<<<< - * return joins - * - */ - __pyx_t_5 = (__pyx_v_added == 26); - if (__pyx_t_5) { - goto __pyx_L12_break; - goto __pyx_L14; - } - __pyx_L14:; - __pyx_L11_continue:; - } - __pyx_L12_break:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":159 - * added += 1 - * if added == 26: break - * return joins # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_joins)); - __pyx_r = ((PyObject *)__pyx_v_joins); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_field); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dz); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dy); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.identify_field_neighbors"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_field); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dz); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dx); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dy); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_y); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_x); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_z); - __pyx_L2:; - __Pyx_DECREF(__pyx_v_joins); - __Pyx_DECREF(__pyx_v_this_joins); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":163 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def extract_identified_contours(int max_ind, joins): # <<<<<<<<<<<<<< - * cdef int i - * contours = [] - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_extract_identified_contours(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_extract_identified_contours(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_max_ind; - PyObject *__pyx_v_joins = 0; - int __pyx_v_i; - PyObject *__pyx_v_contours; - PyObject *__pyx_v_proto_contour; - PyObject *__pyx_v_j; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - long __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - Py_ssize_t __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__max_ind,&__pyx_n_s__joins,0}; - __Pyx_RefNannySetupContext("extract_identified_contours"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_ind); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__joins); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("extract_identified_contours", 1, 2, 2, 1); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "extract_identified_contours") < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_max_ind = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_max_ind == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_joins = values[1]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_max_ind = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_max_ind == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_joins = PyTuple_GET_ITEM(__pyx_args, 1); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("extract_identified_contours", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.extract_identified_contours"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_contours = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_proto_contour = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_j = Py_None; __Pyx_INCREF(Py_None); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":165 - * def extract_identified_contours(int max_ind, joins): - * cdef int i - * contours = [] # <<<<<<<<<<<<<< - * for i in range(max_ind + 1): # +1 to get to the max_ind itself - * contours.append(set([i])) - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_contours)); - __pyx_v_contours = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":166 - * cdef int i - * contours = [] - * for i in range(max_ind + 1): # +1 to get to the max_ind itself # <<<<<<<<<<<<<< - * contours.append(set([i])) - * if len(joins[i]) == 0: - */ - __pyx_t_2 = (__pyx_v_max_ind + 1); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":167 - * contours = [] - * for i in range(max_ind + 1): # +1 to get to the max_ind itself - * contours.append(set([i])) # <<<<<<<<<<<<<< - * if len(joins[i]) == 0: - * continue - */ - if (unlikely(__pyx_v_contours == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[6]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)&PySet_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = PyList_Append(((PyObject *)__pyx_v_contours), __pyx_t_4); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":168 - * for i in range(max_ind + 1): # +1 to get to the max_ind itself - * contours.append(set([i])) - * if len(joins[i]) == 0: # <<<<<<<<<<<<<< - * continue - * proto_contour = [i] - */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_joins, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = (__pyx_t_6 == 0); - if (__pyx_t_7) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":169 - * contours.append(set([i])) - * if len(joins[i]) == 0: - * continue # <<<<<<<<<<<<<< - * proto_contour = [i] - * for j in joins[i]: - */ - goto __pyx_L6_continue; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":170 - * if len(joins[i]) == 0: - * continue - * proto_contour = [i] # <<<<<<<<<<<<<< - * for j in joins[i]: - * proto_contour += contours[j] - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_proto_contour); - __pyx_v_proto_contour = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":171 - * continue - * proto_contour = [i] - * for j in joins[i]: # <<<<<<<<<<<<<< - * proto_contour += contours[j] - * proto_contour = set(proto_contour) - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_joins, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_6 = 0; __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); - } else { - __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; - } else if (likely(PyTuple_CheckExact(__pyx_t_4))) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; - } else { - __pyx_t_1 = PyIter_Next(__pyx_t_4); - if (!__pyx_t_1) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_DECREF(__pyx_v_j); - __pyx_v_j = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":172 - * proto_contour = [i] - * for j in joins[i]: - * proto_contour += contours[j] # <<<<<<<<<<<<<< - * proto_contour = set(proto_contour) - * for j in proto_contour: - */ - __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_contours), __pyx_v_j); if (!__pyx_t_1) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_v_proto_contour, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_proto_contour); - __pyx_v_proto_contour = __pyx_t_8; - __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":173 - * for j in joins[i]: - * proto_contour += contours[j] - * proto_contour = set(proto_contour) # <<<<<<<<<<<<<< - * for j in proto_contour: - * contours[j] = proto_contour - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_proto_contour); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_proto_contour); - __Pyx_GIVEREF(__pyx_v_proto_contour); - __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)&PySet_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_proto_contour); - __pyx_v_proto_contour = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":174 - * proto_contour += contours[j] - * proto_contour = set(proto_contour) - * for j in proto_contour: # <<<<<<<<<<<<<< - * contours[j] = proto_contour - * return contours - */ - if (PyList_CheckExact(__pyx_v_proto_contour) || PyTuple_CheckExact(__pyx_v_proto_contour)) { - __pyx_t_6 = 0; __pyx_t_8 = __pyx_v_proto_contour; __Pyx_INCREF(__pyx_t_8); - } else { - __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_proto_contour); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - } - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; - } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; - } else { - __pyx_t_4 = PyIter_Next(__pyx_t_8); - if (!__pyx_t_4) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_DECREF(__pyx_v_j); - __pyx_v_j = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":175 - * proto_contour = set(proto_contour) - * for j in proto_contour: - * contours[j] = proto_contour # <<<<<<<<<<<<<< - * return contours - */ - if (PyObject_SetItem(((PyObject *)__pyx_v_contours), __pyx_v_j, __pyx_v_proto_contour) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_L6_continue:; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":176 - * for j in proto_contour: - * contours[j] = proto_contour - * return contours # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_contours)); - __pyx_r = ((PyObject *)__pyx_v_contours); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("yt.amr_utils.extract_identified_contours"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_contours); - __Pyx_DECREF(__pyx_v_proto_contour); - __Pyx_DECREF(__pyx_v_j); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":102 - * png_structp *png_ptr_ptr, png_infop *info_ptr_ptr) - * - * def write_png(np.ndarray[np.uint8_t, ndim=3] buffer, # <<<<<<<<<<<<<< - * char *filename, int dpi=100): - * - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_write_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_write_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_buffer = 0; - char *__pyx_v_filename; - int __pyx_v_dpi; - png_byte *__pyx_v_pix_buffer; - int __pyx_v_width; - int __pyx_v_height; - FILE *__pyx_v_fileobj; - png_bytep *__pyx_v_row_pointers; - png_structp __pyx_v_png_ptr; - png_infop __pyx_v_info_ptr; - png_color_8 __pyx_v_sig_bit; - png_uint_32 __pyx_v_row; - size_t __pyx_v_dots_per_meter; - Py_buffer __pyx_bstruct_buffer; - Py_ssize_t __pyx_bstride_0_buffer = 0; - Py_ssize_t __pyx_bstride_1_buffer = 0; - Py_ssize_t __pyx_bstride_2_buffer = 0; - Py_ssize_t __pyx_bshape_0_buffer = 0; - Py_ssize_t __pyx_bshape_1_buffer = 0; - Py_ssize_t __pyx_bshape_2_buffer = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - png_uint_32 __pyx_t_2; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__filename,&__pyx_n_s__dpi,0}; - __Pyx_RefNannySetupContext("write_png"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[3] = {0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("write_png", 0, 2, 3, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dpi); - if (unlikely(value)) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "write_png") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_buffer = ((PyArrayObject *)values[0]); - __pyx_v_filename = PyBytes_AsString(values[1]); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - if (values[2]) { - __pyx_v_dpi = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_dpi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_dpi = ((int)100); - } - } else { - __pyx_v_dpi = ((int)100); - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: - __pyx_v_dpi = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_dpi == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 2: - __pyx_v_filename = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_buffer = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("write_png", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.write_png"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_buffer.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_buffer), __pyx_ptype_5numpy_ndarray, 1, "buffer", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_buffer, (PyObject*)__pyx_v_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_buffer = __pyx_bstruct_buffer.strides[0]; __pyx_bstride_1_buffer = __pyx_bstruct_buffer.strides[1]; __pyx_bstride_2_buffer = __pyx_bstruct_buffer.strides[2]; - __pyx_bshape_0_buffer = __pyx_bstruct_buffer.shape[0]; __pyx_bshape_1_buffer = __pyx_bstruct_buffer.shape[1]; __pyx_bshape_2_buffer = __pyx_bstruct_buffer.shape[2]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":106 - * - * # This is something of a translation of the matplotlib _png module - * cdef png_byte *pix_buffer = buffer.data # <<<<<<<<<<<<<< - * cdef int width = buffer.shape[1] - * cdef int height = buffer.shape[0] - */ - __pyx_v_pix_buffer = ((png_byte *)__pyx_v_buffer->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":107 - * # This is something of a translation of the matplotlib _png module - * cdef png_byte *pix_buffer = buffer.data - * cdef int width = buffer.shape[1] # <<<<<<<<<<<<<< - * cdef int height = buffer.shape[0] - * - */ - __pyx_v_width = (__pyx_v_buffer->dimensions[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":108 - * cdef png_byte *pix_buffer = buffer.data - * cdef int width = buffer.shape[1] - * cdef int height = buffer.shape[0] # <<<<<<<<<<<<<< - * - * cdef FILE* fileobj = fopen(filename, "wb") - */ - __pyx_v_height = (__pyx_v_buffer->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":110 - * cdef int height = buffer.shape[0] - * - * cdef FILE* fileobj = fopen(filename, "wb") # <<<<<<<<<<<<<< - * cdef png_bytep *row_pointers - * cdef png_structp png_ptr - */ - __pyx_v_fileobj = fopen(__pyx_v_filename, __pyx_k__wb); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":118 - * cdef png_uint_32 row - * - * row_pointers = alloca(sizeof(png_bytep) * height) # <<<<<<<<<<<<<< - * - * for row in range(height): - */ - __pyx_v_row_pointers = ((png_bytep *)alloca(((sizeof(png_bytep)) * __pyx_v_height))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":120 - * row_pointers = alloca(sizeof(png_bytep) * height) - * - * for row in range(height): # <<<<<<<<<<<<<< - * row_pointers[row] = pix_buffer + row * width * 4 - * png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL) - */ - __pyx_t_1 = __pyx_v_height; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_row = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":121 - * - * for row in range(height): - * row_pointers[row] = pix_buffer + row * width * 4 # <<<<<<<<<<<<<< - * png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL) - * info_ptr = png_create_info_struct(png_ptr) - */ - (__pyx_v_row_pointers[__pyx_v_row]) = (__pyx_v_pix_buffer + ((__pyx_v_row * __pyx_v_width) * 4)); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":122 - * for row in range(height): - * row_pointers[row] = pix_buffer + row * width * 4 - * png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL) # <<<<<<<<<<<<<< - * info_ptr = png_create_info_struct(png_ptr) - * - */ - __pyx_v_png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":123 - * row_pointers[row] = pix_buffer + row * width * 4 - * png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL) - * info_ptr = png_create_info_struct(png_ptr) # <<<<<<<<<<<<<< - * - * # Um we are ignoring setjmp sorry guys - */ - __pyx_v_info_ptr = png_create_info_struct(__pyx_v_png_ptr); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":127 - * # Um we are ignoring setjmp sorry guys - * - * png_init_io(png_ptr, fileobj) # <<<<<<<<<<<<<< - * - * png_set_IHDR(png_ptr, info_ptr, width, height, 8, - */ - png_init_io(__pyx_v_png_ptr, __pyx_v_fileobj); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":131 - * png_set_IHDR(png_ptr, info_ptr, width, height, 8, - * PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, - * PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE) # <<<<<<<<<<<<<< - * - * cdef size_t dots_per_meter = (dpi / (2.54 / 100.0)) - */ - png_set_IHDR(__pyx_v_png_ptr, __pyx_v_info_ptr, __pyx_v_width, __pyx_v_height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":133 - * PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE) - * - * cdef size_t dots_per_meter = (dpi / (2.54 / 100.0)) # <<<<<<<<<<<<<< - * png_set_pHYs(png_ptr, info_ptr, dots_per_meter, dots_per_meter, - * PNG_RESOLUTION_METER) - */ - __pyx_v_dots_per_meter = ((size_t)(__pyx_v_dpi / (2.54 / 100.0))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":135 - * cdef size_t dots_per_meter = (dpi / (2.54 / 100.0)) - * png_set_pHYs(png_ptr, info_ptr, dots_per_meter, dots_per_meter, - * PNG_RESOLUTION_METER) # <<<<<<<<<<<<<< - * - * sig_bit.gray = 0 - */ - png_set_pHYs(__pyx_v_png_ptr, __pyx_v_info_ptr, __pyx_v_dots_per_meter, __pyx_v_dots_per_meter, PNG_RESOLUTION_METER); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":137 - * PNG_RESOLUTION_METER) - * - * sig_bit.gray = 0 # <<<<<<<<<<<<<< - * sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 8 - * - */ - __pyx_v_sig_bit.gray = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":138 - * - * sig_bit.gray = 0 - * sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 8 # <<<<<<<<<<<<<< - * - * png_set_sBIT(png_ptr, info_ptr, &sig_bit) - */ - __pyx_v_sig_bit.red = 8; - __pyx_v_sig_bit.green = 8; - __pyx_v_sig_bit.blue = 8; - __pyx_v_sig_bit.alpha = 8; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":140 - * sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 8 - * - * png_set_sBIT(png_ptr, info_ptr, &sig_bit) # <<<<<<<<<<<<<< - * - * png_write_info(png_ptr, info_ptr) - */ - png_set_sBIT(__pyx_v_png_ptr, __pyx_v_info_ptr, (&__pyx_v_sig_bit)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":142 - * png_set_sBIT(png_ptr, info_ptr, &sig_bit) - * - * png_write_info(png_ptr, info_ptr) # <<<<<<<<<<<<<< - * png_write_image(png_ptr, row_pointers) - * png_write_end(png_ptr, info_ptr) - */ - png_write_info(__pyx_v_png_ptr, __pyx_v_info_ptr); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":143 - * - * png_write_info(png_ptr, info_ptr) - * png_write_image(png_ptr, row_pointers) # <<<<<<<<<<<<<< - * png_write_end(png_ptr, info_ptr) - * - */ - png_write_image(__pyx_v_png_ptr, __pyx_v_row_pointers); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":144 - * png_write_info(png_ptr, info_ptr) - * png_write_image(png_ptr, row_pointers) - * png_write_end(png_ptr, info_ptr) # <<<<<<<<<<<<<< - * - * fclose(fileobj) - */ - png_write_end(__pyx_v_png_ptr, __pyx_v_info_ptr); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":146 - * png_write_end(png_ptr, info_ptr) - * - * fclose(fileobj) # <<<<<<<<<<<<<< - * png_destroy_write_struct(&png_ptr, &info_ptr) - * - */ - fclose(__pyx_v_fileobj); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":147 - * - * fclose(fileobj) - * png_destroy_write_struct(&png_ptr, &info_ptr) # <<<<<<<<<<<<<< - * - * def add_points_to_image( - */ - png_destroy_write_struct((&__pyx_v_png_ptr), (&__pyx_v_info_ptr)); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_buffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.write_png"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_buffer); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":149 - * png_destroy_write_struct(&png_ptr, &info_ptr) - * - * def add_points_to_image( # <<<<<<<<<<<<<< - * np.ndarray[np.uint8_t, ndim=3] buffer, - * np.ndarray[np.float64_t, ndim=1] px, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_add_points_to_image(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_add_points_to_image(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_buffer = 0; - PyArrayObject *__pyx_v_px = 0; - PyArrayObject *__pyx_v_py = 0; - __pyx_t_5numpy_float64_t __pyx_v_pv; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_k; - int __pyx_v_pi; - int __pyx_v_np; - int __pyx_v_xs; - int __pyx_v_ys; - int __pyx_v_v; - Py_buffer __pyx_bstruct_buffer; - Py_ssize_t __pyx_bstride_0_buffer = 0; - Py_ssize_t __pyx_bstride_1_buffer = 0; - Py_ssize_t __pyx_bstride_2_buffer = 0; - Py_ssize_t __pyx_bshape_0_buffer = 0; - Py_ssize_t __pyx_bshape_1_buffer = 0; - Py_ssize_t __pyx_bshape_2_buffer = 0; - Py_buffer __pyx_bstruct_px; - Py_ssize_t __pyx_bstride_0_px = 0; - Py_ssize_t __pyx_bshape_0_px = 0; - Py_buffer __pyx_bstruct_py; - Py_ssize_t __pyx_bstride_0_py = 0; - Py_ssize_t __pyx_bshape_0_py = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__buffer,&__pyx_n_s__px,&__pyx_n_s__py,&__pyx_n_s__pv,0}; - __Pyx_RefNannySetupContext("add_points_to_image"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[4] = {0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__buffer); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__px); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_points_to_image", 1, 4, 4, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__py); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_points_to_image", 1, 4, 4, 2); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pv); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_points_to_image", 1, 4, 4, 3); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_points_to_image") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_buffer = ((PyArrayObject *)values[0]); - __pyx_v_px = ((PyArrayObject *)values[1]); - __pyx_v_py = ((PyArrayObject *)values[2]); - __pyx_v_pv = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_pv == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_buffer = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_px = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_py = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_pv = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_pv == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_points_to_image", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.add_points_to_image"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_buffer.buf = NULL; - __pyx_bstruct_px.buf = NULL; - __pyx_bstruct_py.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_buffer), __pyx_ptype_5numpy_ndarray, 1, "buffer", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_px), __pyx_ptype_5numpy_ndarray, 1, "px", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_py), __pyx_ptype_5numpy_ndarray, 1, "py", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_buffer, (PyObject*)__pyx_v_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_buffer = __pyx_bstruct_buffer.strides[0]; __pyx_bstride_1_buffer = __pyx_bstruct_buffer.strides[1]; __pyx_bstride_2_buffer = __pyx_bstruct_buffer.strides[2]; - __pyx_bshape_0_buffer = __pyx_bstruct_buffer.shape[0]; __pyx_bshape_1_buffer = __pyx_bstruct_buffer.shape[1]; __pyx_bshape_2_buffer = __pyx_bstruct_buffer.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_px, (PyObject*)__pyx_v_px, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_px = __pyx_bstruct_px.strides[0]; - __pyx_bshape_0_px = __pyx_bstruct_px.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_py, (PyObject*)__pyx_v_py, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_py = __pyx_bstruct_py.strides[0]; - __pyx_bshape_0_py = __pyx_bstruct_py.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":155 - * np.float64_t pv): - * cdef int i, j, k, pi - * cdef int np = px.shape[0] # <<<<<<<<<<<<<< - * cdef int xs = buffer.shape[0] - * cdef int ys = buffer.shape[1] - */ - __pyx_v_np = (__pyx_v_px->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":156 - * cdef int i, j, k, pi - * cdef int np = px.shape[0] - * cdef int xs = buffer.shape[0] # <<<<<<<<<<<<<< - * cdef int ys = buffer.shape[1] - * cdef int v - */ - __pyx_v_xs = (__pyx_v_buffer->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":157 - * cdef int np = px.shape[0] - * cdef int xs = buffer.shape[0] - * cdef int ys = buffer.shape[1] # <<<<<<<<<<<<<< - * cdef int v - * v = iclip((pv * 255), 0, 255) - */ - __pyx_v_ys = (__pyx_v_buffer->dimensions[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":159 - * cdef int ys = buffer.shape[1] - * cdef int v - * v = iclip((pv * 255), 0, 255) # <<<<<<<<<<<<<< - * for pi in range(np): - * j = (xs * px[pi]) - */ - __pyx_v_v = __pyx_f_2yt_9amr_utils_iclip(((int)(__pyx_v_pv * 255.0)), 0, 255); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":160 - * cdef int v - * v = iclip((pv * 255), 0, 255) - * for pi in range(np): # <<<<<<<<<<<<<< - * j = (xs * px[pi]) - * i = (ys * py[pi]) - */ - __pyx_t_1 = __pyx_v_np; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_pi = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":161 - * v = iclip((pv * 255), 0, 255) - * for pi in range(np): - * j = (xs * px[pi]) # <<<<<<<<<<<<<< - * i = (ys * py[pi]) - * for k in range(3): - */ - __pyx_t_3 = __pyx_v_pi; - __pyx_t_4 = -1; - if (__pyx_t_3 < 0) { - __pyx_t_3 += __pyx_bshape_0_px; - if (unlikely(__pyx_t_3 < 0)) __pyx_t_4 = 0; - } else if (unlikely(__pyx_t_3 >= __pyx_bshape_0_px)) __pyx_t_4 = 0; - if (unlikely(__pyx_t_4 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_4); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_j = ((int)(__pyx_v_xs * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_px.buf, __pyx_t_3, __pyx_bstride_0_px)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":162 - * for pi in range(np): - * j = (xs * px[pi]) - * i = (ys * py[pi]) # <<<<<<<<<<<<<< - * for k in range(3): - * buffer[i, j, k] = 0 - */ - __pyx_t_4 = __pyx_v_pi; - __pyx_t_5 = -1; - if (__pyx_t_4 < 0) { - __pyx_t_4 += __pyx_bshape_0_py; - if (unlikely(__pyx_t_4 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_4 >= __pyx_bshape_0_py)) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_i = ((int)(__pyx_v_ys * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_py.buf, __pyx_t_4, __pyx_bstride_0_py)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":163 - * j = (xs * px[pi]) - * i = (ys * py[pi]) - * for k in range(3): # <<<<<<<<<<<<<< - * buffer[i, j, k] = 0 - * return - */ - for (__pyx_t_5 = 0; __pyx_t_5 < 3; __pyx_t_5+=1) { - __pyx_v_k = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":164 - * i = (ys * py[pi]) - * for k in range(3): - * buffer[i, j, k] = 0 # <<<<<<<<<<<<<< - * return - * for i in range(xs): - */ - __pyx_t_6 = __pyx_v_i; - __pyx_t_7 = __pyx_v_j; - __pyx_t_8 = __pyx_v_k; - __pyx_t_9 = -1; - if (__pyx_t_6 < 0) { - __pyx_t_6 += __pyx_bshape_0_buffer; - if (unlikely(__pyx_t_6 < 0)) __pyx_t_9 = 0; - } else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_buffer)) __pyx_t_9 = 0; - if (__pyx_t_7 < 0) { - __pyx_t_7 += __pyx_bshape_1_buffer; - if (unlikely(__pyx_t_7 < 0)) __pyx_t_9 = 1; - } else if (unlikely(__pyx_t_7 >= __pyx_bshape_1_buffer)) __pyx_t_9 = 1; - if (__pyx_t_8 < 0) { - __pyx_t_8 += __pyx_bshape_2_buffer; - if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 2; - } else if (unlikely(__pyx_t_8 >= __pyx_bshape_2_buffer)) __pyx_t_9 = 2; - if (unlikely(__pyx_t_9 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_9); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_bstruct_buffer.buf, __pyx_t_6, __pyx_bstride_0_buffer, __pyx_t_7, __pyx_bstride_1_buffer, __pyx_t_8, __pyx_bstride_2_buffer) = 0; - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":165 - * for k in range(3): - * buffer[i, j, k] = 0 - * return # <<<<<<<<<<<<<< - * for i in range(xs): - * for j in range(ys): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":166 - * buffer[i, j, k] = 0 - * return - * for i in range(xs): # <<<<<<<<<<<<<< - * for j in range(ys): - * for k in range(3): - */ - __pyx_t_1 = __pyx_v_xs; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":167 - * return - * for i in range(xs): - * for j in range(ys): # <<<<<<<<<<<<<< - * for k in range(3): - * v = buffer[i, j, k] - */ - __pyx_t_5 = __pyx_v_ys; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_5; __pyx_t_9+=1) { - __pyx_v_j = __pyx_t_9; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":168 - * for i in range(xs): - * for j in range(ys): - * for k in range(3): # <<<<<<<<<<<<<< - * v = buffer[i, j, k] - * buffer[i, j, k] = iclip(v, 0, 255) - */ - for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) { - __pyx_v_k = __pyx_t_10; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":169 - * for j in range(ys): - * for k in range(3): - * v = buffer[i, j, k] # <<<<<<<<<<<<<< - * buffer[i, j, k] = iclip(v, 0, 255) - */ - __pyx_t_11 = __pyx_v_i; - __pyx_t_12 = __pyx_v_j; - __pyx_t_13 = __pyx_v_k; - __pyx_t_14 = -1; - if (__pyx_t_11 < 0) { - __pyx_t_11 += __pyx_bshape_0_buffer; - if (unlikely(__pyx_t_11 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_11 >= __pyx_bshape_0_buffer)) __pyx_t_14 = 0; - if (__pyx_t_12 < 0) { - __pyx_t_12 += __pyx_bshape_1_buffer; - if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 1; - } else if (unlikely(__pyx_t_12 >= __pyx_bshape_1_buffer)) __pyx_t_14 = 1; - if (__pyx_t_13 < 0) { - __pyx_t_13 += __pyx_bshape_2_buffer; - if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 2; - } else if (unlikely(__pyx_t_13 >= __pyx_bshape_2_buffer)) __pyx_t_14 = 2; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_v = (*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_bstruct_buffer.buf, __pyx_t_11, __pyx_bstride_0_buffer, __pyx_t_12, __pyx_bstride_1_buffer, __pyx_t_13, __pyx_bstride_2_buffer)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":170 - * for k in range(3): - * v = buffer[i, j, k] - * buffer[i, j, k] = iclip(v, 0, 255) # <<<<<<<<<<<<<< - */ - __pyx_t_14 = __pyx_v_i; - __pyx_t_15 = __pyx_v_j; - __pyx_t_16 = __pyx_v_k; - __pyx_t_17 = -1; - if (__pyx_t_14 < 0) { - __pyx_t_14 += __pyx_bshape_0_buffer; - if (unlikely(__pyx_t_14 < 0)) __pyx_t_17 = 0; - } else if (unlikely(__pyx_t_14 >= __pyx_bshape_0_buffer)) __pyx_t_17 = 0; - if (__pyx_t_15 < 0) { - __pyx_t_15 += __pyx_bshape_1_buffer; - if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 1; - } else if (unlikely(__pyx_t_15 >= __pyx_bshape_1_buffer)) __pyx_t_17 = 1; - if (__pyx_t_16 < 0) { - __pyx_t_16 += __pyx_bshape_2_buffer; - if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 2; - } else if (unlikely(__pyx_t_16 >= __pyx_bshape_2_buffer)) __pyx_t_17 = 2; - if (unlikely(__pyx_t_17 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_17); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_uint8_t *, __pyx_bstruct_buffer.buf, __pyx_t_14, __pyx_bstride_0_buffer, __pyx_t_15, __pyx_bstride_1_buffer, __pyx_t_16, __pyx_bstride_2_buffer) = __pyx_f_2yt_9amr_utils_iclip(__pyx_v_v, 0, 255); - } - } - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_buffer); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_px); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_py); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.add_points_to_image"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_buffer); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_px); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_py); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":42 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def read_tiger_section( # <<<<<<<<<<<<<< - * char *fn, - * np.ndarray[np.int64_t, ndim=1] slab_start, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_read_tiger_section(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_read_tiger_section(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_fn; - PyArrayObject *__pyx_v_slab_start = 0; - PyArrayObject *__pyx_v_slab_size = 0; - PyArrayObject *__pyx_v_root_size = 0; - int __pyx_v_offset; - int __pyx_v_strides[3]; - __pyx_t_5numpy_int64_t __pyx_v_i; - __pyx_t_5numpy_int64_t __pyx_v_j; - PyArrayObject *__pyx_v_buffer = 0; - FILE *__pyx_v_f; - __pyx_t_5numpy_int64_t __pyx_v_pos; - __pyx_t_5numpy_int64_t __pyx_v_moff; - float *__pyx_v_data; - Py_buffer __pyx_bstruct_slab_size; - Py_ssize_t __pyx_bstride_0_slab_size = 0; - Py_ssize_t __pyx_bshape_0_slab_size = 0; - Py_buffer __pyx_bstruct_slab_start; - Py_ssize_t __pyx_bstride_0_slab_start = 0; - Py_ssize_t __pyx_bshape_0_slab_start = 0; - Py_buffer __pyx_bstruct_root_size; - Py_ssize_t __pyx_bstride_0_root_size = 0; - Py_ssize_t __pyx_bshape_0_root_size = 0; - PyObject *__pyx_r = NULL; - long __pyx_t_1; - long __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - long __pyx_t_7; - __pyx_t_5numpy_int64_t __pyx_t_8; - __pyx_t_5numpy_int64_t __pyx_t_9; - long __pyx_t_10; - __pyx_t_5numpy_int64_t __pyx_t_11; - __pyx_t_5numpy_int64_t __pyx_t_12; - long __pyx_t_13; - long __pyx_t_14; - long __pyx_t_15; - long __pyx_t_16; - long __pyx_t_17; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fn,&__pyx_n_s__slab_start,&__pyx_n_s__slab_size,&__pyx_n_s__root_size,&__pyx_n_s__offset,0}; - __Pyx_RefNannySetupContext("read_tiger_section"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[5] = {0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fn); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__slab_start); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_tiger_section", 0, 4, 5, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__slab_size); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_tiger_section", 0, 4, 5, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__root_size); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_tiger_section", 0, 4, 5, 3); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset); - if (unlikely(value)) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read_tiger_section") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_fn = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_fn) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_slab_start = ((PyArrayObject *)values[1]); - __pyx_v_slab_size = ((PyArrayObject *)values[2]); - __pyx_v_root_size = ((PyArrayObject *)values[3]); - if (values[4]) { - __pyx_v_offset = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_offset = ((int)36); - } - } else { - __pyx_v_offset = ((int)36); - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: - __pyx_v_offset = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 4: - __pyx_v_root_size = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_slab_size = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_slab_start = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_fn = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_fn) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("read_tiger_section", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.read_tiger_section"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_slab_start.buf = NULL; - __pyx_bstruct_slab_size.buf = NULL; - __pyx_bstruct_root_size.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_slab_start), __pyx_ptype_5numpy_ndarray, 1, "slab_start", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_slab_size), __pyx_ptype_5numpy_ndarray, 1, "slab_size", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_root_size), __pyx_ptype_5numpy_ndarray, 1, "root_size", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_slab_start, (PyObject*)__pyx_v_slab_start, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_slab_start = __pyx_bstruct_slab_start.strides[0]; - __pyx_bshape_0_slab_start = __pyx_bstruct_slab_start.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_slab_size, (PyObject*)__pyx_v_slab_size, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_slab_size = __pyx_bstruct_slab_size.strides[0]; - __pyx_bshape_0_slab_size = __pyx_bstruct_slab_size.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_root_size, (PyObject*)__pyx_v_root_size, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_root_size = __pyx_bstruct_root_size.strides[0]; - __pyx_bshape_0_root_size = __pyx_bstruct_root_size.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":49 - * int offset = 36): - * cdef int strides[3] - * strides[0] = 1 # <<<<<<<<<<<<<< - * strides[1] = root_size[0] * strides[0] - * strides[2] = strides[1] * root_size[1] + 2 - */ - (__pyx_v_strides[0]) = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":50 - * cdef int strides[3] - * strides[0] = 1 - * strides[1] = root_size[0] * strides[0] # <<<<<<<<<<<<<< - * strides[2] = strides[1] * root_size[1] + 2 - * cdef np.int64_t i, j, k - */ - __pyx_t_1 = 0; - (__pyx_v_strides[1]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_root_size.buf, __pyx_t_1, __pyx_bstride_0_root_size)) * (__pyx_v_strides[0])); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":51 - * strides[0] = 1 - * strides[1] = root_size[0] * strides[0] - * strides[2] = strides[1] * root_size[1] + 2 # <<<<<<<<<<<<<< - * cdef np.int64_t i, j, k - * cdef np.ndarray buffer = np.zeros(slab_size, dtype='float32', order='F') - */ - __pyx_t_2 = 1; - (__pyx_v_strides[2]) = (((__pyx_v_strides[1]) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_root_size.buf, __pyx_t_2, __pyx_bstride_0_root_size))) + 2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":53 - * strides[2] = strides[1] * root_size[1] + 2 - * cdef np.int64_t i, j, k - * cdef np.ndarray buffer = np.zeros(slab_size, dtype='float32', order='F') # <<<<<<<<<<<<<< - * cdef FILE *f = fopen(fn, "rb") - * #for i in range(3): offset += strides[i] * slab_start[i] - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_slab_size)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_slab_size)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_slab_size)); - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__float32)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_4, __pyx_t_3, ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_buffer = ((PyArrayObject *)__pyx_t_6); - __pyx_t_6 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":54 - * cdef np.int64_t i, j, k - * cdef np.ndarray buffer = np.zeros(slab_size, dtype='float32', order='F') - * cdef FILE *f = fopen(fn, "rb") # <<<<<<<<<<<<<< - * #for i in range(3): offset += strides[i] * slab_start[i] - * cdef np.int64_t pos = 0 - */ - __pyx_v_f = fopen(__pyx_v_fn, __pyx_k__rb); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":56 - * cdef FILE *f = fopen(fn, "rb") - * #for i in range(3): offset += strides[i] * slab_start[i] - * cdef np.int64_t pos = 0 # <<<<<<<<<<<<<< - * cdef np.int64_t moff = 0 - * cdef float *data = buffer.data - */ - __pyx_v_pos = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":57 - * #for i in range(3): offset += strides[i] * slab_start[i] - * cdef np.int64_t pos = 0 - * cdef np.int64_t moff = 0 # <<<<<<<<<<<<<< - * cdef float *data = buffer.data - * fseek(f, offset, 0) - */ - __pyx_v_moff = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":58 - * cdef np.int64_t pos = 0 - * cdef np.int64_t moff = 0 - * cdef float *data = buffer.data # <<<<<<<<<<<<<< - * fseek(f, offset, 0) - * # If anybody wants to convert this loop to a SEEK_CUR, that'd be great. - */ - __pyx_v_data = ((float *)__pyx_v_buffer->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":59 - * cdef np.int64_t moff = 0 - * cdef float *data = buffer.data - * fseek(f, offset, 0) # <<<<<<<<<<<<<< - * # If anybody wants to convert this loop to a SEEK_CUR, that'd be great. - * for i in range(slab_size[2]): - */ - fseek(__pyx_v_f, __pyx_v_offset, 0); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":61 - * fseek(f, offset, 0) - * # If anybody wants to convert this loop to a SEEK_CUR, that'd be great. - * for i in range(slab_size[2]): # <<<<<<<<<<<<<< - * for j in range(slab_size[1]): - * moff = (slab_start[0] ) * strides[0] \ - */ - __pyx_t_7 = 2; - __pyx_t_8 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_size.buf, __pyx_t_7, __pyx_bstride_0_slab_size)); - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":62 - * # If anybody wants to convert this loop to a SEEK_CUR, that'd be great. - * for i in range(slab_size[2]): - * for j in range(slab_size[1]): # <<<<<<<<<<<<<< - * moff = (slab_start[0] ) * strides[0] \ - * + (slab_start[1] + j) * strides[1] \ - */ - __pyx_t_10 = 1; - __pyx_t_11 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_size.buf, __pyx_t_10, __pyx_bstride_0_slab_size)); - for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { - __pyx_v_j = __pyx_t_12; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":63 - * for i in range(slab_size[2]): - * for j in range(slab_size[1]): - * moff = (slab_start[0] ) * strides[0] \ # <<<<<<<<<<<<<< - * + (slab_start[1] + j) * strides[1] \ - * + (slab_start[2] + i) * strides[2] - */ - __pyx_t_13 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":64 - * for j in range(slab_size[1]): - * moff = (slab_start[0] ) * strides[0] \ - * + (slab_start[1] + j) * strides[1] \ # <<<<<<<<<<<<<< - * + (slab_start[2] + i) * strides[2] - * #print offset + 4 * moff, pos - */ - __pyx_t_14 = 1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":65 - * moff = (slab_start[0] ) * strides[0] \ - * + (slab_start[1] + j) * strides[1] \ - * + (slab_start[2] + i) * strides[2] # <<<<<<<<<<<<<< - * #print offset + 4 * moff, pos - * fseek(f, offset + 4 * moff, SEEK_SET) - */ - __pyx_t_15 = 2; - __pyx_v_moff = ((((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_start.buf, __pyx_t_13, __pyx_bstride_0_slab_start)) * (__pyx_v_strides[0])) + (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_start.buf, __pyx_t_14, __pyx_bstride_0_slab_start)) + __pyx_v_j) * (__pyx_v_strides[1]))) + (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_start.buf, __pyx_t_15, __pyx_bstride_0_slab_start)) + __pyx_v_i) * (__pyx_v_strides[2]))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":67 - * + (slab_start[2] + i) * strides[2] - * #print offset + 4 * moff, pos - * fseek(f, offset + 4 * moff, SEEK_SET) # <<<<<<<<<<<<<< - * fread( (data + pos), 4, slab_size[0], f) - * pos += slab_size[0] - */ - fseek(__pyx_v_f, (__pyx_v_offset + (4 * __pyx_v_moff)), SEEK_SET); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":68 - * #print offset + 4 * moff, pos - * fseek(f, offset + 4 * moff, SEEK_SET) - * fread( (data + pos), 4, slab_size[0], f) # <<<<<<<<<<<<<< - * pos += slab_size[0] - * return buffer - */ - __pyx_t_16 = 0; - fread(((void *)(__pyx_v_data + __pyx_v_pos)), 4, (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_size.buf, __pyx_t_16, __pyx_bstride_0_slab_size)), __pyx_v_f); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":69 - * fseek(f, offset + 4 * moff, SEEK_SET) - * fread( (data + pos), 4, slab_size[0], f) - * pos += slab_size[0] # <<<<<<<<<<<<<< - * return buffer - */ - __pyx_t_17 = 0; - __pyx_v_pos += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_slab_size.buf, __pyx_t_17, __pyx_bstride_0_slab_size)); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":70 - * fread( (data + pos), 4, slab_size[0], f) - * pos += slab_size[0] - * return buffer # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_buffer)); - __pyx_r = ((PyObject *)__pyx_v_buffer); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_slab_size); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_slab_start); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_root_size); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.read_tiger_section"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_slab_size); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_slab_start); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_root_size); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_buffer); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":47 - * QuadTreeNode *children[2][2] - * - * cdef void QTN_add_value(QuadTreeNode *self, # <<<<<<<<<<<<<< - * np.float64_t *val, np.float64_t weight_val): - * cdef int i - */ - -static void __pyx_f_2yt_9amr_utils_QTN_add_value(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_self, __pyx_t_5numpy_float64_t *__pyx_v_val, __pyx_t_5numpy_float64_t __pyx_v_weight_val) { - int __pyx_v_i; - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("QTN_add_value"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":50 - * np.float64_t *val, np.float64_t weight_val): - * cdef int i - * for i in range(self.nvals): # <<<<<<<<<<<<<< - * self.val[i] += val[i] - * self.weight_val += weight_val - */ - __pyx_t_1 = __pyx_v_self->nvals; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":51 - * cdef int i - * for i in range(self.nvals): - * self.val[i] += val[i] # <<<<<<<<<<<<<< - * self.weight_val += weight_val - * - */ - (__pyx_v_self->val[__pyx_v_i]) += (__pyx_v_val[__pyx_v_i]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":52 - * for i in range(self.nvals): - * self.val[i] += val[i] - * self.weight_val += weight_val # <<<<<<<<<<<<<< - * - * cdef void QTN_refine(QuadTreeNode *self): - */ - __pyx_v_self->weight_val += __pyx_v_weight_val; - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":54 - * self.weight_val += weight_val - * - * cdef void QTN_refine(QuadTreeNode *self): # <<<<<<<<<<<<<< - * cdef int i, j, i1, j1 - * cdef np.int64_t npos[2] - */ - -static void __pyx_f_2yt_9amr_utils_QTN_refine(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_self) { - int __pyx_v_i; - int __pyx_v_j; - __pyx_t_5numpy_int64_t __pyx_v_npos[2]; - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("QTN_refine"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":58 - * cdef np.int64_t npos[2] - * cdef QuadTreeNode *node - * for i in range(2): # <<<<<<<<<<<<<< - * npos[0] = self.pos[0] * 2 + i - * for j in range(2): - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 2; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":59 - * cdef QuadTreeNode *node - * for i in range(2): - * npos[0] = self.pos[0] * 2 + i # <<<<<<<<<<<<<< - * for j in range(2): - * npos[1] = self.pos[1] * 2 + j - */ - (__pyx_v_npos[0]) = (((__pyx_v_self->pos[0]) * 2) + __pyx_v_i); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":60 - * for i in range(2): - * npos[0] = self.pos[0] * 2 + i - * for j in range(2): # <<<<<<<<<<<<<< - * npos[1] = self.pos[1] * 2 + j - * # We have to be careful with allocation... - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 2; __pyx_t_2+=1) { - __pyx_v_j = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":61 - * npos[0] = self.pos[0] * 2 + i - * for j in range(2): - * npos[1] = self.pos[1] * 2 + j # <<<<<<<<<<<<<< - * # We have to be careful with allocation... - * self.children[i][j] = QTN_initialize( - */ - (__pyx_v_npos[1]) = (((__pyx_v_self->pos[1]) * 2) + __pyx_v_j); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":63 - * npos[1] = self.pos[1] * 2 + j - * # We have to be careful with allocation... - * self.children[i][j] = QTN_initialize( # <<<<<<<<<<<<<< - * npos, - * self.nvals, self.val, self.weight_val, - */ - ((__pyx_v_self->children[__pyx_v_i])[__pyx_v_j]) = __pyx_f_2yt_9amr_utils_QTN_initialize(__pyx_v_npos, __pyx_v_self->nvals, __pyx_v_self->val, __pyx_v_self->weight_val, (__pyx_v_self->level + 1)); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":67 - * self.nvals, self.val, self.weight_val, - * self.level + 1) - * for i in range(self.nvals): self.val[i] = 0.0 # <<<<<<<<<<<<<< - * self.weight_val = 0.0 - * - */ - __pyx_t_1 = __pyx_v_self->nvals; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - (__pyx_v_self->val[__pyx_v_i]) = 0.0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":68 - * self.level + 1) - * for i in range(self.nvals): self.val[i] = 0.0 - * self.weight_val = 0.0 # <<<<<<<<<<<<<< - * - * cdef QuadTreeNode *QTN_initialize(np.int64_t pos[2], int nvals, - */ - __pyx_v_self->weight_val = 0.0; - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":70 - * self.weight_val = 0.0 - * - * cdef QuadTreeNode *QTN_initialize(np.int64_t pos[2], int nvals, # <<<<<<<<<<<<<< - * np.float64_t *val, np.float64_t weight_val, - * int level): - */ - -static struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_f_2yt_9amr_utils_QTN_initialize(__pyx_t_5numpy_int64_t *__pyx_v_pos, int __pyx_v_nvals, __pyx_t_5numpy_float64_t *__pyx_v_val, __pyx_t_5numpy_float64_t __pyx_v_weight_val, int __pyx_v_level) { - struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_node; - int __pyx_v_i; - int __pyx_v_j; - struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_r; - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("QTN_initialize"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":75 - * cdef QuadTreeNode *node - * cdef int i, j - * node = malloc(sizeof(QuadTreeNode)) # <<<<<<<<<<<<<< - * node.pos[0] = pos[0] - * node.pos[1] = pos[1] - */ - __pyx_v_node = ((struct __pyx_t_2yt_9amr_utils_QuadTreeNode *)malloc((sizeof(struct __pyx_t_2yt_9amr_utils_QuadTreeNode)))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":76 - * cdef int i, j - * node = malloc(sizeof(QuadTreeNode)) - * node.pos[0] = pos[0] # <<<<<<<<<<<<<< - * node.pos[1] = pos[1] - * node.nvals = nvals - */ - (__pyx_v_node->pos[0]) = (__pyx_v_pos[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":77 - * node = malloc(sizeof(QuadTreeNode)) - * node.pos[0] = pos[0] - * node.pos[1] = pos[1] # <<<<<<<<<<<<<< - * node.nvals = nvals - * node.val = malloc( - */ - (__pyx_v_node->pos[1]) = (__pyx_v_pos[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":78 - * node.pos[0] = pos[0] - * node.pos[1] = pos[1] - * node.nvals = nvals # <<<<<<<<<<<<<< - * node.val = malloc( - * nvals * sizeof(np.float64_t)) - */ - __pyx_v_node->nvals = __pyx_v_nvals; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":79 - * node.pos[1] = pos[1] - * node.nvals = nvals - * node.val = malloc( # <<<<<<<<<<<<<< - * nvals * sizeof(np.float64_t)) - * for i in range(nvals): - */ - __pyx_v_node->val = ((__pyx_t_5numpy_float64_t *)malloc((__pyx_v_nvals * (sizeof(__pyx_t_5numpy_float64_t))))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":81 - * node.val = malloc( - * nvals * sizeof(np.float64_t)) - * for i in range(nvals): # <<<<<<<<<<<<<< - * node.val[i] = val[i] - * node.weight_val = weight_val - */ - __pyx_t_1 = __pyx_v_nvals; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":82 - * nvals * sizeof(np.float64_t)) - * for i in range(nvals): - * node.val[i] = val[i] # <<<<<<<<<<<<<< - * node.weight_val = weight_val - * for i in range(2): - */ - (__pyx_v_node->val[__pyx_v_i]) = (__pyx_v_val[__pyx_v_i]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":83 - * for i in range(nvals): - * node.val[i] = val[i] - * node.weight_val = weight_val # <<<<<<<<<<<<<< - * for i in range(2): - * for j in range(2): - */ - __pyx_v_node->weight_val = __pyx_v_weight_val; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":84 - * node.val[i] = val[i] - * node.weight_val = weight_val - * for i in range(2): # <<<<<<<<<<<<<< - * for j in range(2): - * node.children[i][j] = NULL - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 2; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":85 - * node.weight_val = weight_val - * for i in range(2): - * for j in range(2): # <<<<<<<<<<<<<< - * node.children[i][j] = NULL - * node.level = level - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 2; __pyx_t_2+=1) { - __pyx_v_j = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":86 - * for i in range(2): - * for j in range(2): - * node.children[i][j] = NULL # <<<<<<<<<<<<<< - * node.level = level - * return node - */ - ((__pyx_v_node->children[__pyx_v_i])[__pyx_v_j]) = NULL; - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":87 - * for j in range(2): - * node.children[i][j] = NULL - * node.level = level # <<<<<<<<<<<<<< - * return node - * - */ - __pyx_v_node->level = __pyx_v_level; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":88 - * node.children[i][j] = NULL - * node.level = level - * return node # <<<<<<<<<<<<<< - * - * cdef void QTN_free(QuadTreeNode *node): - */ - __pyx_r = __pyx_v_node; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":90 - * return node - * - * cdef void QTN_free(QuadTreeNode *node): # <<<<<<<<<<<<<< - * cdef int i, j - * for i in range(2): - */ - -static void __pyx_f_2yt_9amr_utils_QTN_free(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_node) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("QTN_free"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":92 - * cdef void QTN_free(QuadTreeNode *node): - * cdef int i, j - * for i in range(2): # <<<<<<<<<<<<<< - * for j in range(2): - * if node.children[i][j] == NULL: continue - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 2; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":93 - * cdef int i, j - * for i in range(2): - * for j in range(2): # <<<<<<<<<<<<<< - * if node.children[i][j] == NULL: continue - * QTN_free(node.children[i][j]) - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 2; __pyx_t_2+=1) { - __pyx_v_j = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":94 - * for i in range(2): - * for j in range(2): - * if node.children[i][j] == NULL: continue # <<<<<<<<<<<<<< - * QTN_free(node.children[i][j]) - * free(node.val) - */ - __pyx_t_3 = (((__pyx_v_node->children[__pyx_v_i])[__pyx_v_j]) == NULL); - if (__pyx_t_3) { - goto __pyx_L5_continue; - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":95 - * for j in range(2): - * if node.children[i][j] == NULL: continue - * QTN_free(node.children[i][j]) # <<<<<<<<<<<<<< - * free(node.val) - * free(node) - */ - __pyx_f_2yt_9amr_utils_QTN_free(((__pyx_v_node->children[__pyx_v_i])[__pyx_v_j])); - __pyx_L5_continue:; - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":96 - * if node.children[i][j] == NULL: continue - * QTN_free(node.children[i][j]) - * free(node.val) # <<<<<<<<<<<<<< - * free(node) - * - */ - free(__pyx_v_node->val); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":97 - * QTN_free(node.children[i][j]) - * free(node.val) - * free(node) # <<<<<<<<<<<<<< - * - * cdef class QuadTree: - */ - free(__pyx_v_node); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":105 - * cdef np.int64_t top_grid_dims[2] - * - * def __cinit__(self, np.ndarray[np.int64_t, ndim=1] top_grid_dims, # <<<<<<<<<<<<<< - * int nvals): - * cdef int i, j - */ - -static int __pyx_pf_2yt_9amr_utils_8QuadTree___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_9amr_utils_8QuadTree___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_top_grid_dims = 0; - int __pyx_v_nvals; - int __pyx_v_i; - int __pyx_v_j; - __pyx_t_5numpy_int64_t __pyx_v_pos[2]; - __pyx_t_5numpy_float64_t *__pyx_v_vals; - __pyx_t_5numpy_float64_t __pyx_v_weight_val; - Py_buffer __pyx_bstruct_top_grid_dims; - Py_ssize_t __pyx_bstride_0_top_grid_dims = 0; - Py_ssize_t __pyx_bshape_0_top_grid_dims = 0; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - long __pyx_t_3; - long __pyx_t_4; - long __pyx_t_5; - long __pyx_t_6; - __pyx_t_5numpy_int64_t __pyx_t_7; - long __pyx_t_8; - long __pyx_t_9; - __pyx_t_5numpy_int64_t __pyx_t_10; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__top_grid_dims,&__pyx_n_s__nvals,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__top_grid_dims); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nvals); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_top_grid_dims = ((PyArrayObject *)values[0]); - __pyx_v_nvals = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_nvals == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_top_grid_dims = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_nvals = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_nvals == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.QuadTree.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_top_grid_dims.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_top_grid_dims), __pyx_ptype_5numpy_ndarray, 1, "top_grid_dims", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_top_grid_dims, (PyObject*)__pyx_v_top_grid_dims, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_top_grid_dims = __pyx_bstruct_top_grid_dims.strides[0]; - __pyx_bshape_0_top_grid_dims = __pyx_bstruct_top_grid_dims.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":111 - * cdef np.int64_t pos[2] - * cdef np.float64_t *vals = alloca( - * sizeof(np.float64_t)*nvals) # <<<<<<<<<<<<<< - * cdef np.float64_t weight_val = 0.0 - * self.nvals = nvals - */ - __pyx_v_vals = ((__pyx_t_5numpy_float64_t *)alloca(((sizeof(__pyx_t_5numpy_float64_t)) * __pyx_v_nvals))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":112 - * cdef np.float64_t *vals = alloca( - * sizeof(np.float64_t)*nvals) - * cdef np.float64_t weight_val = 0.0 # <<<<<<<<<<<<<< - * self.nvals = nvals - * for i in range(nvals): vals[i] = 0.0 - */ - __pyx_v_weight_val = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":113 - * sizeof(np.float64_t)*nvals) - * cdef np.float64_t weight_val = 0.0 - * self.nvals = nvals # <<<<<<<<<<<<<< - * for i in range(nvals): vals[i] = 0.0 - * - */ - ((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->nvals = __pyx_v_nvals; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":114 - * cdef np.float64_t weight_val = 0.0 - * self.nvals = nvals - * for i in range(nvals): vals[i] = 0.0 # <<<<<<<<<<<<<< - * - * self.top_grid_dims[0] = top_grid_dims[0] - */ - __pyx_t_1 = __pyx_v_nvals; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - (__pyx_v_vals[__pyx_v_i]) = 0.0; - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":116 - * for i in range(nvals): vals[i] = 0.0 - * - * self.top_grid_dims[0] = top_grid_dims[0] # <<<<<<<<<<<<<< - * self.top_grid_dims[1] = top_grid_dims[1] - * - */ - __pyx_t_3 = 0; - __pyx_t_1 = -1; - if (__pyx_t_3 < 0) { - __pyx_t_3 += __pyx_bshape_0_top_grid_dims; - if (unlikely(__pyx_t_3 < 0)) __pyx_t_1 = 0; - } else if (unlikely(__pyx_t_3 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_1 = 0; - if (unlikely(__pyx_t_1 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_1); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[0]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_3, __pyx_bstride_0_top_grid_dims)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":117 - * - * self.top_grid_dims[0] = top_grid_dims[0] - * self.top_grid_dims[1] = top_grid_dims[1] # <<<<<<<<<<<<<< - * - * # This wouldn't be necessary if we did bitshifting... - */ - __pyx_t_4 = 1; - __pyx_t_1 = -1; - if (__pyx_t_4 < 0) { - __pyx_t_4 += __pyx_bshape_0_top_grid_dims; - if (unlikely(__pyx_t_4 < 0)) __pyx_t_1 = 0; - } else if (unlikely(__pyx_t_4 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_1 = 0; - if (unlikely(__pyx_t_1 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_1); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[1]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_4, __pyx_bstride_0_top_grid_dims)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":120 - * - * # This wouldn't be necessary if we did bitshifting... - * for i in range(80): # <<<<<<<<<<<<<< - * self.po2[i] = 2**i - * self.root_nodes = \ - */ - for (__pyx_t_1 = 0; __pyx_t_1 < 80; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":121 - * # This wouldn't be necessary if we did bitshifting... - * for i in range(80): - * self.po2[i] = 2**i # <<<<<<<<<<<<<< - * self.root_nodes = \ - * malloc(sizeof(QuadTreeNode **) * top_grid_dims[0]) - */ - (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->po2[__pyx_v_i]) = __Pyx_pow_long(2, __pyx_v_i); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":123 - * self.po2[i] = 2**i - * self.root_nodes = \ - * malloc(sizeof(QuadTreeNode **) * top_grid_dims[0]) # <<<<<<<<<<<<<< - * - * # We initialize our root values to 0.0. - */ - __pyx_t_5 = 0; - __pyx_t_1 = -1; - if (__pyx_t_5 < 0) { - __pyx_t_5 += __pyx_bshape_0_top_grid_dims; - if (unlikely(__pyx_t_5 < 0)) __pyx_t_1 = 0; - } else if (unlikely(__pyx_t_5 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_1 = 0; - if (unlikely(__pyx_t_1 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_1); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":122 - * for i in range(80): - * self.po2[i] = 2**i - * self.root_nodes = \ # <<<<<<<<<<<<<< - * malloc(sizeof(QuadTreeNode **) * top_grid_dims[0]) - * - */ - ((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes = ((struct __pyx_t_2yt_9amr_utils_QuadTreeNode ***)malloc(((sizeof(struct __pyx_t_2yt_9amr_utils_QuadTreeNode **)) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_5, __pyx_bstride_0_top_grid_dims))))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":126 - * - * # We initialize our root values to 0.0. - * for i in range(top_grid_dims[0]): # <<<<<<<<<<<<<< - * pos[0] = i - * self.root_nodes[i] = \ - */ - __pyx_t_6 = 0; - __pyx_t_1 = -1; - if (__pyx_t_6 < 0) { - __pyx_t_6 += __pyx_bshape_0_top_grid_dims; - if (unlikely(__pyx_t_6 < 0)) __pyx_t_1 = 0; - } else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_1 = 0; - if (unlikely(__pyx_t_1 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_1); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_7 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_6, __pyx_bstride_0_top_grid_dims)); - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_7; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":127 - * # We initialize our root values to 0.0. - * for i in range(top_grid_dims[0]): - * pos[0] = i # <<<<<<<<<<<<<< - * self.root_nodes[i] = \ - * malloc(sizeof(QuadTreeNode *) * top_grid_dims[1]) - */ - (__pyx_v_pos[0]) = __pyx_v_i; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":129 - * pos[0] = i - * self.root_nodes[i] = \ - * malloc(sizeof(QuadTreeNode *) * top_grid_dims[1]) # <<<<<<<<<<<<<< - * for j in range(top_grid_dims[1]): - * pos[1] = j - */ - __pyx_t_8 = 1; - __pyx_t_2 = -1; - if (__pyx_t_8 < 0) { - __pyx_t_8 += __pyx_bshape_0_top_grid_dims; - if (unlikely(__pyx_t_8 < 0)) __pyx_t_2 = 0; - } else if (unlikely(__pyx_t_8 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_2 = 0; - if (unlikely(__pyx_t_2 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_2); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":128 - * for i in range(top_grid_dims[0]): - * pos[0] = i - * self.root_nodes[i] = \ # <<<<<<<<<<<<<< - * malloc(sizeof(QuadTreeNode *) * top_grid_dims[1]) - * for j in range(top_grid_dims[1]): - */ - (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes[__pyx_v_i]) = ((struct __pyx_t_2yt_9amr_utils_QuadTreeNode **)malloc(((sizeof(struct __pyx_t_2yt_9amr_utils_QuadTreeNode *)) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_8, __pyx_bstride_0_top_grid_dims))))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":130 - * self.root_nodes[i] = \ - * malloc(sizeof(QuadTreeNode *) * top_grid_dims[1]) - * for j in range(top_grid_dims[1]): # <<<<<<<<<<<<<< - * pos[1] = j - * self.root_nodes[i][j] = QTN_initialize( - */ - __pyx_t_9 = 1; - __pyx_t_2 = -1; - if (__pyx_t_9 < 0) { - __pyx_t_9 += __pyx_bshape_0_top_grid_dims; - if (unlikely(__pyx_t_9 < 0)) __pyx_t_2 = 0; - } else if (unlikely(__pyx_t_9 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_2 = 0; - if (unlikely(__pyx_t_2 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_2); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_9, __pyx_bstride_0_top_grid_dims)); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_10; __pyx_t_2+=1) { - __pyx_v_j = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":131 - * malloc(sizeof(QuadTreeNode *) * top_grid_dims[1]) - * for j in range(top_grid_dims[1]): - * pos[1] = j # <<<<<<<<<<<<<< - * self.root_nodes[i][j] = QTN_initialize( - * pos, nvals, vals, weight_val, 0) - */ - (__pyx_v_pos[1]) = __pyx_v_j; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":132 - * for j in range(top_grid_dims[1]): - * pos[1] = j - * self.root_nodes[i][j] = QTN_initialize( # <<<<<<<<<<<<<< - * pos, nvals, vals, weight_val, 0) - * - */ - ((((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes[__pyx_v_i])[__pyx_v_j]) = __pyx_f_2yt_9amr_utils_QTN_initialize(__pyx_v_pos, __pyx_v_nvals, __pyx_v_vals, __pyx_v_weight_val, 0); - } - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_top_grid_dims); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.QuadTree.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_top_grid_dims); - __pyx_L2:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":135 - * pos, nvals, vals, weight_val, 0) - * - * cdef void add_to_position(self, # <<<<<<<<<<<<<< - * int level, np.int64_t pos[2], - * np.float64_t *val, - */ - -static void __pyx_f_2yt_9amr_utils_8QuadTree_add_to_position(struct __pyx_obj_2yt_9amr_utils_QuadTree *__pyx_v_self, int __pyx_v_level, __pyx_t_5numpy_int64_t *__pyx_v_pos, __pyx_t_5numpy_float64_t *__pyx_v_val, __pyx_t_5numpy_float64_t __pyx_v_weight_val) { - int __pyx_v_i; - int __pyx_v_j; - struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_node; - __pyx_t_5numpy_int64_t __pyx_v_fac; - PyObject *__pyx_v_L; - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - __Pyx_RefNannySetupContext("add_to_position"); - __pyx_v_L = Py_None; __Pyx_INCREF(Py_None); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":141 - * cdef int i, j - * cdef QuadTreeNode *node - * node = self.find_on_root_level(pos, level) # <<<<<<<<<<<<<< - * cdef np.int64_t fac - * for L in range(level): - */ - __pyx_v_node = ((struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *)__pyx_v_self->__pyx_vtab)->find_on_root_level(__pyx_v_self, __pyx_v_pos, __pyx_v_level); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":143 - * node = self.find_on_root_level(pos, level) - * cdef np.int64_t fac - * for L in range(level): # <<<<<<<<<<<<<< - * if node.children[0][0] == NULL: - * QTN_refine(node) - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_level); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_range, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = 0; __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); - } else { - __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - } else if (likely(PyTuple_CheckExact(__pyx_t_3))) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - } else { - __pyx_t_2 = PyIter_Next(__pyx_t_3); - if (!__pyx_t_2) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_DECREF(__pyx_v_L); - __pyx_v_L = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":144 - * cdef np.int64_t fac - * for L in range(level): - * if node.children[0][0] == NULL: # <<<<<<<<<<<<<< - * QTN_refine(node) - * # Maybe we should use bitwise operators? - */ - __pyx_t_4 = (((__pyx_v_node->children[0])[0]) == NULL); - if (__pyx_t_4) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":145 - * for L in range(level): - * if node.children[0][0] == NULL: - * QTN_refine(node) # <<<<<<<<<<<<<< - * # Maybe we should use bitwise operators? - * fac = self.po2[level - L - 1] - */ - __pyx_f_2yt_9amr_utils_QTN_refine(__pyx_v_node); - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":147 - * QTN_refine(node) - * # Maybe we should use bitwise operators? - * fac = self.po2[level - L - 1] # <<<<<<<<<<<<<< - * i = (pos[0] >= fac*(2*node.pos[0]+1)) - * j = (pos[1] >= fac*(2*node.pos[1]+1)) - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_level); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyNumber_Subtract(__pyx_t_2, __pyx_v_L); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Subtract(__pyx_t_5, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_fac = (__pyx_v_self->po2[__pyx_t_6]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":148 - * # Maybe we should use bitwise operators? - * fac = self.po2[level - L - 1] - * i = (pos[0] >= fac*(2*node.pos[0]+1)) # <<<<<<<<<<<<<< - * j = (pos[1] >= fac*(2*node.pos[1]+1)) - * node = node.children[i][j] - */ - __pyx_v_i = ((__pyx_v_pos[0]) >= (__pyx_v_fac * ((2 * (__pyx_v_node->pos[0])) + 1))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":149 - * fac = self.po2[level - L - 1] - * i = (pos[0] >= fac*(2*node.pos[0]+1)) - * j = (pos[1] >= fac*(2*node.pos[1]+1)) # <<<<<<<<<<<<<< - * node = node.children[i][j] - * QTN_add_value(node, val, weight_val) - */ - __pyx_v_j = ((__pyx_v_pos[1]) >= (__pyx_v_fac * ((2 * (__pyx_v_node->pos[1])) + 1))); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":150 - * i = (pos[0] >= fac*(2*node.pos[0]+1)) - * j = (pos[1] >= fac*(2*node.pos[1]+1)) - * node = node.children[i][j] # <<<<<<<<<<<<<< - * QTN_add_value(node, val, weight_val) - * - */ - __pyx_v_node = ((__pyx_v_node->children[__pyx_v_i])[__pyx_v_j]); - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":151 - * j = (pos[1] >= fac*(2*node.pos[1]+1)) - * node = node.children[i][j] - * QTN_add_value(node, val, weight_val) # <<<<<<<<<<<<<< - * - * cdef QuadTreeNode *find_on_root_level(self, np.int64_t pos[2], int level): - */ - __pyx_f_2yt_9amr_utils_QTN_add_value(__pyx_v_node, __pyx_v_val, __pyx_v_weight_val); - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_WriteUnraisable("yt.amr_utils.QuadTree.add_to_position"); - __pyx_L0:; - __Pyx_DECREF(__pyx_v_L); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":153 - * QTN_add_value(node, val, weight_val) - * - * cdef QuadTreeNode *find_on_root_level(self, np.int64_t pos[2], int level): # <<<<<<<<<<<<<< - * # We need this because the root level won't just have four children - * # So we find on the root level, then we traverse the tree. - */ - -static struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_f_2yt_9amr_utils_8QuadTree_find_on_root_level(struct __pyx_obj_2yt_9amr_utils_QuadTree *__pyx_v_self, __pyx_t_5numpy_int64_t *__pyx_v_pos, int __pyx_v_level) { - __pyx_t_5numpy_int64_t __pyx_v_i; - __pyx_t_5numpy_int64_t __pyx_v_j; - struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_r; - __pyx_t_5numpy_int64_t __pyx_t_1; - __pyx_t_5numpy_int64_t __pyx_t_2; - __Pyx_RefNannySetupContext("find_on_root_level"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":157 - * # So we find on the root level, then we traverse the tree. - * cdef np.int64_t i, j - * i = (pos[0] / self.po2[level]) # <<<<<<<<<<<<<< - * j = (pos[1] / self.po2[level]) - * return self.root_nodes[i][j] - */ - __pyx_t_1 = (__pyx_v_pos[0]); - __pyx_t_2 = (__pyx_v_self->po2[__pyx_v_level]); - if (unlikely(__pyx_t_2 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(__pyx_t_5numpy_int64_t) == sizeof(long) && unlikely(__pyx_t_2 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_1))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_i = __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_1, __pyx_t_2); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":158 - * cdef np.int64_t i, j - * i = (pos[0] / self.po2[level]) - * j = (pos[1] / self.po2[level]) # <<<<<<<<<<<<<< - * return self.root_nodes[i][j] - * - */ - __pyx_t_2 = (__pyx_v_pos[1]); - __pyx_t_1 = (__pyx_v_self->po2[__pyx_v_level]); - if (unlikely(__pyx_t_1 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(__pyx_t_5numpy_int64_t) == sizeof(long) && unlikely(__pyx_t_1 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_2))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[9]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_j = __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_2, __pyx_t_1); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":159 - * i = (pos[0] / self.po2[level]) - * j = (pos[1] / self.po2[level]) - * return self.root_nodes[i][j] # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = ((__pyx_v_self->root_nodes[__pyx_v_i])[__pyx_v_j]); - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("yt.amr_utils.QuadTree.find_on_root_level"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":164 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def add_array_to_tree(self, int level, # <<<<<<<<<<<<<< - * np.ndarray[np.int64_t, ndim=1] pxs, - * np.ndarray[np.int64_t, ndim=1] pys, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_8QuadTree_add_array_to_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_8QuadTree_add_array_to_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_level; - PyArrayObject *__pyx_v_pxs = 0; - PyArrayObject *__pyx_v_pys = 0; - PyArrayObject *__pyx_v_pvals = 0; - PyArrayObject *__pyx_v_pweight_vals = 0; - int __pyx_v_np; - int __pyx_v_p; - __pyx_t_5numpy_float64_t *__pyx_v_vals; - __pyx_t_5numpy_float64_t *__pyx_v_data; - __pyx_t_5numpy_int64_t __pyx_v_pos[2]; - Py_buffer __pyx_bstruct_pweight_vals; - Py_ssize_t __pyx_bstride_0_pweight_vals = 0; - Py_ssize_t __pyx_bshape_0_pweight_vals = 0; - Py_buffer __pyx_bstruct_pxs; - Py_ssize_t __pyx_bstride_0_pxs = 0; - Py_ssize_t __pyx_bshape_0_pxs = 0; - Py_buffer __pyx_bstruct_pvals; - Py_ssize_t __pyx_bstride_0_pvals = 0; - Py_ssize_t __pyx_bstride_1_pvals = 0; - Py_ssize_t __pyx_bshape_0_pvals = 0; - Py_ssize_t __pyx_bshape_1_pvals = 0; - Py_buffer __pyx_bstruct_pys; - Py_ssize_t __pyx_bstride_0_pys = 0; - Py_ssize_t __pyx_bshape_0_pys = 0; - PyObject *__pyx_r = NULL; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__level,&__pyx_n_s__pxs,&__pyx_n_s__pys,&__pyx_n_s__pvals,&__pyx_n_s__pweight_vals,0}; - __Pyx_RefNannySetupContext("add_array_to_tree"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[5] = {0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pxs); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_array_to_tree", 1, 5, 5, 1); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pys); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_array_to_tree", 1, 5, 5, 2); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pvals); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_array_to_tree", 1, 5, 5, 3); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pweight_vals); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_array_to_tree", 1, 5, 5, 4); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_array_to_tree") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_level = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_pxs = ((PyArrayObject *)values[1]); - __pyx_v_pys = ((PyArrayObject *)values[2]); - __pyx_v_pvals = ((PyArrayObject *)values[3]); - __pyx_v_pweight_vals = ((PyArrayObject *)values[4]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_pxs = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_pys = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_pvals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_pweight_vals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_array_to_tree", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.QuadTree.add_array_to_tree"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_pxs.buf = NULL; - __pyx_bstruct_pys.buf = NULL; - __pyx_bstruct_pvals.buf = NULL; - __pyx_bstruct_pweight_vals.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pxs), __pyx_ptype_5numpy_ndarray, 1, "pxs", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pys), __pyx_ptype_5numpy_ndarray, 1, "pys", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pvals), __pyx_ptype_5numpy_ndarray, 1, "pvals", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pweight_vals), __pyx_ptype_5numpy_ndarray, 1, "pweight_vals", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_pxs, (PyObject*)__pyx_v_pxs, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_pxs = __pyx_bstruct_pxs.strides[0]; - __pyx_bshape_0_pxs = __pyx_bstruct_pxs.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_pys, (PyObject*)__pyx_v_pys, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_pys = __pyx_bstruct_pys.strides[0]; - __pyx_bshape_0_pys = __pyx_bstruct_pys.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_pvals, (PyObject*)__pyx_v_pvals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_pvals = __pyx_bstruct_pvals.strides[0]; __pyx_bstride_1_pvals = __pyx_bstruct_pvals.strides[1]; - __pyx_bshape_0_pvals = __pyx_bstruct_pvals.shape[0]; __pyx_bshape_1_pvals = __pyx_bstruct_pvals.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_pweight_vals, (PyObject*)__pyx_v_pweight_vals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_pweight_vals = __pyx_bstruct_pweight_vals.strides[0]; - __pyx_bshape_0_pweight_vals = __pyx_bstruct_pweight_vals.shape[0]; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":169 - * np.ndarray[np.float64_t, ndim=2] pvals, - * np.ndarray[np.float64_t, ndim=1] pweight_vals): - * cdef int np = pxs.shape[0] # <<<<<<<<<<<<<< - * cdef int p - * cdef cnp.float64_t *vals - */ - __pyx_v_np = (__pyx_v_pxs->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":172 - * cdef int p - * cdef cnp.float64_t *vals - * cdef cnp.float64_t *data = pvals.data # <<<<<<<<<<<<<< - * cdef cnp.int64_t pos[2] - * for p in range(np): - */ - __pyx_v_data = ((__pyx_t_5numpy_float64_t *)__pyx_v_pvals->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":174 - * cdef cnp.float64_t *data = pvals.data - * cdef cnp.int64_t pos[2] - * for p in range(np): # <<<<<<<<<<<<<< - * vals = data + self.nvals*p - * pos[0] = pxs[p] - */ - __pyx_t_1 = __pyx_v_np; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_p = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":175 - * cdef cnp.int64_t pos[2] - * for p in range(np): - * vals = data + self.nvals*p # <<<<<<<<<<<<<< - * pos[0] = pxs[p] - * pos[1] = pys[p] - */ - __pyx_v_vals = (__pyx_v_data + (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->nvals * __pyx_v_p)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":176 - * for p in range(np): - * vals = data + self.nvals*p - * pos[0] = pxs[p] # <<<<<<<<<<<<<< - * pos[1] = pys[p] - * self.add_to_position(level, pos, vals, pweight_vals[p]) - */ - __pyx_t_3 = __pyx_v_p; - (__pyx_v_pos[0]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_pxs.buf, __pyx_t_3, __pyx_bstride_0_pxs)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":177 - * vals = data + self.nvals*p - * pos[0] = pxs[p] - * pos[1] = pys[p] # <<<<<<<<<<<<<< - * self.add_to_position(level, pos, vals, pweight_vals[p]) - * - */ - __pyx_t_4 = __pyx_v_p; - (__pyx_v_pos[1]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_pys.buf, __pyx_t_4, __pyx_bstride_0_pys)); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":178 - * pos[0] = pxs[p] - * pos[1] = pys[p] - * self.add_to_position(level, pos, vals, pweight_vals[p]) # <<<<<<<<<<<<<< - * - * def add_grid_to_tree(self, int level, - */ - __pyx_t_5 = __pyx_v_p; - ((struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *)((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->__pyx_vtab)->add_to_position(((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self), __pyx_v_level, __pyx_v_pos, __pyx_v_vals, (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_pweight_vals.buf, __pyx_t_5, __pyx_bstride_0_pweight_vals))); - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pweight_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pxs); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pys); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.QuadTree.add_array_to_tree"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pweight_vals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pxs); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pys); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":180 - * self.add_to_position(level, pos, vals, pweight_vals[p]) - * - * def add_grid_to_tree(self, int level, # <<<<<<<<<<<<<< - * np.ndarray[np.int64_t, ndim=1] start_index, - * np.ndarray[np.float64_t, ndim=2] pvals, - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_8QuadTree_add_grid_to_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_8QuadTree_add_grid_to_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_level; - PyArrayObject *__pyx_v_start_index = 0; - PyArrayObject *__pyx_v_pvals = 0; - PyArrayObject *__pyx_v_wvals = 0; - PyArrayObject *__pyx_v_cm = 0; - Py_buffer __pyx_bstruct_cm; - Py_ssize_t __pyx_bstride_0_cm = 0; - Py_ssize_t __pyx_bstride_1_cm = 0; - Py_ssize_t __pyx_bshape_0_cm = 0; - Py_ssize_t __pyx_bshape_1_cm = 0; - Py_buffer __pyx_bstruct_pvals; - Py_ssize_t __pyx_bstride_0_pvals = 0; - Py_ssize_t __pyx_bstride_1_pvals = 0; - Py_ssize_t __pyx_bshape_0_pvals = 0; - Py_ssize_t __pyx_bshape_1_pvals = 0; - Py_buffer __pyx_bstruct_wvals; - Py_ssize_t __pyx_bstride_0_wvals = 0; - Py_ssize_t __pyx_bstride_1_wvals = 0; - Py_ssize_t __pyx_bshape_0_wvals = 0; - Py_ssize_t __pyx_bshape_1_wvals = 0; - Py_buffer __pyx_bstruct_start_index; - Py_ssize_t __pyx_bstride_0_start_index = 0; - Py_ssize_t __pyx_bshape_0_start_index = 0; - PyObject *__pyx_r = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__level,&__pyx_n_s__start_index,&__pyx_n_s__pvals,&__pyx_n_s__wvals,&__pyx_n_s__cm,0}; - __Pyx_RefNannySetupContext("add_grid_to_tree"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[5] = {0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start_index); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_grid_to_tree", 1, 5, 5, 1); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pvals); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_grid_to_tree", 1, 5, 5, 2); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__wvals); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_grid_to_tree", 1, 5, 5, 3); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cm); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_grid_to_tree", 1, 5, 5, 4); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add_grid_to_tree") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_level = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_start_index = ((PyArrayObject *)values[1]); - __pyx_v_pvals = ((PyArrayObject *)values[2]); - __pyx_v_wvals = ((PyArrayObject *)values[3]); - __pyx_v_cm = ((PyArrayObject *)values[4]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_start_index = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_pvals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_wvals = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_cm = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_grid_to_tree", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.QuadTree.add_grid_to_tree"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_start_index.buf = NULL; - __pyx_bstruct_pvals.buf = NULL; - __pyx_bstruct_wvals.buf = NULL; - __pyx_bstruct_cm.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_start_index), __pyx_ptype_5numpy_ndarray, 1, "start_index", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pvals), __pyx_ptype_5numpy_ndarray, 1, "pvals", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_wvals), __pyx_ptype_5numpy_ndarray, 1, "wvals", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_cm), __pyx_ptype_5numpy_ndarray, 1, "cm", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_start_index, (PyObject*)__pyx_v_start_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_start_index = __pyx_bstruct_start_index.strides[0]; - __pyx_bshape_0_start_index = __pyx_bstruct_start_index.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_pvals, (PyObject*)__pyx_v_pvals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_pvals = __pyx_bstruct_pvals.strides[0]; __pyx_bstride_1_pvals = __pyx_bstruct_pvals.strides[1]; - __pyx_bshape_0_pvals = __pyx_bstruct_pvals.shape[0]; __pyx_bshape_1_pvals = __pyx_bstruct_pvals.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_wvals, (PyObject*)__pyx_v_wvals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_wvals = __pyx_bstruct_wvals.strides[0]; __pyx_bstride_1_wvals = __pyx_bstruct_wvals.strides[1]; - __pyx_bshape_0_wvals = __pyx_bstruct_wvals.shape[0]; __pyx_bshape_1_wvals = __pyx_bstruct_wvals.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_cm, (PyObject*)__pyx_v_cm, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_cm = __pyx_bstruct_cm.strides[0]; __pyx_bstride_1_cm = __pyx_bstruct_cm.strides[1]; - __pyx_bshape_0_cm = __pyx_bstruct_cm.shape[0]; __pyx_bshape_1_cm = __pyx_bstruct_cm.shape[1]; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_cm); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_wvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_start_index); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.QuadTree.add_grid_to_tree"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_cm); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_pvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_wvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_start_index); - __pyx_L2:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":189 - * @cython.boundscheck(False) - * @cython.wraparound(False) - * def get_all_from_level(self, int level, int count_only = 0): # <<<<<<<<<<<<<< - * cdef int i, j - * cdef int total = 0 - */ - -static PyObject *__pyx_pf_2yt_9amr_utils_8QuadTree_get_all_from_level(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_9amr_utils_8QuadTree_get_all_from_level(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_level; - int __pyx_v_count_only; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_total; - PyObject *__pyx_v_vals; - PyArrayObject *__pyx_v_npos; - PyArrayObject *__pyx_v_nvals; - PyArrayObject *__pyx_v_nwvals; - __pyx_t_5numpy_int64_t __pyx_v_curpos; - __pyx_t_5numpy_int64_t *__pyx_v_pdata; - __pyx_t_5numpy_float64_t *__pyx_v_vdata; - __pyx_t_5numpy_float64_t *__pyx_v_wdata; - Py_buffer __pyx_bstruct_nwvals; - Py_ssize_t __pyx_bstride_0_nwvals = 0; - Py_ssize_t __pyx_bshape_0_nwvals = 0; - Py_buffer __pyx_bstruct_nvals; - Py_ssize_t __pyx_bstride_0_nvals = 0; - Py_ssize_t __pyx_bstride_1_nvals = 0; - Py_ssize_t __pyx_bshape_0_nvals = 0; - Py_ssize_t __pyx_bshape_1_nvals = 0; - Py_buffer __pyx_bstruct_npos; - Py_ssize_t __pyx_bstride_0_npos = 0; - Py_ssize_t __pyx_bstride_1_npos = 0; - Py_ssize_t __pyx_bshape_0_npos = 0; - Py_ssize_t __pyx_bshape_1_npos = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __pyx_t_5numpy_int64_t __pyx_t_2; - int __pyx_t_3; - __pyx_t_5numpy_int64_t __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyArrayObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyArrayObject *__pyx_t_13 = NULL; - PyArrayObject *__pyx_t_14 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__level,&__pyx_n_s__count_only,0}; - __Pyx_RefNannySetupContext("get_all_from_level"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__count_only); - if (unlikely(value)) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "get_all_from_level") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_level = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - if (values[1]) { - __pyx_v_count_only = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_count_only == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_count_only = ((int)0); - } - } else { - __pyx_v_count_only = ((int)0); - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: __pyx_v_count_only = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_count_only == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 1: __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_all_from_level", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[9]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.amr_utils.QuadTree.get_all_from_level"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_vals = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_npos = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_nvals = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_nwvals = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_npos.buf = NULL; - __pyx_bstruct_nvals.buf = NULL; - __pyx_bstruct_nwvals.buf = NULL; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":191 - * def get_all_from_level(self, int level, int count_only = 0): - * cdef int i, j - * cdef int total = 0 # <<<<<<<<<<<<<< - * vals = [] - * for i in range(self.top_grid_dims[0]): - */ - __pyx_v_total = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":192 - * cdef int i, j - * cdef int total = 0 - * vals = [] # <<<<<<<<<<<<<< - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_vals)); - __pyx_v_vals = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":193 - * cdef int total = 0 - * vals = [] - * for i in range(self.top_grid_dims[0]): # <<<<<<<<<<<<<< - * for j in range(self.top_grid_dims[1]): - * total += self.count_at_level(self.root_nodes[i][j], level) - */ - __pyx_t_2 = (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[0]); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":194 - * vals = [] - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): # <<<<<<<<<<<<<< - * total += self.count_at_level(self.root_nodes[i][j], level) - * if count_only: return total - */ - __pyx_t_4 = (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[1]); - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_j = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":195 - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): - * total += self.count_at_level(self.root_nodes[i][j], level) # <<<<<<<<<<<<<< - * if count_only: return total - * # Allocate our array - */ - __pyx_v_total += ((struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *)((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->__pyx_vtab)->count_at_level(((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self), ((((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes[__pyx_v_i])[__pyx_v_j]), __pyx_v_level); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":196 - * for j in range(self.top_grid_dims[1]): - * total += self.count_at_level(self.root_nodes[i][j], level) - * if count_only: return total # <<<<<<<<<<<<<< - * # Allocate our array - * cdef np.ndarray[np.int64_t, ndim=2] npos - */ - if (__pyx_v_count_only) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_total); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":201 - * cdef np.ndarray[np.float64_t, ndim=2] nvals - * cdef np.ndarray[np.float64_t, ndim=1] nwvals - * npos = np.zeros( (total, 2), dtype='int64') # <<<<<<<<<<<<<< - * nvals = np.zeros( (total, self.nvals), dtype='float64') - * nwvals = np.zeros( total, dtype='float64') - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_total); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_7)); - if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int64)) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = PyEval_CallObjectWithKeywords(__pyx_t_6, __pyx_t_1, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = ((PyArrayObject *)__pyx_t_8); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_npos); - __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_npos, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_3 < 0)) { - PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_npos, (PyObject*)__pyx_v_npos, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12); - } - } - __pyx_bstride_0_npos = __pyx_bstruct_npos.strides[0]; __pyx_bstride_1_npos = __pyx_bstruct_npos.strides[1]; - __pyx_bshape_0_npos = __pyx_bstruct_npos.shape[0]; __pyx_bshape_1_npos = __pyx_bstruct_npos.shape[1]; - if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_9 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_npos)); - __pyx_v_npos = ((PyArrayObject *)__pyx_t_8); - __pyx_t_8 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":202 - * cdef np.ndarray[np.float64_t, ndim=1] nwvals - * npos = np.zeros( (total, 2), dtype='int64') - * nvals = np.zeros( (total, self.nvals), dtype='float64') # <<<<<<<<<<<<<< - * nwvals = np.zeros( total, dtype='float64') - * cdef np.int64_t curpos = 0 - */ - __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__zeros); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyInt_FromLong(__pyx_v_total); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->nvals); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_8 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__float64)) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = PyEval_CallObjectWithKeywords(__pyx_t_7, __pyx_t_1, ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = ((PyArrayObject *)__pyx_t_8); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_nvals); - __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_nvals, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); - if (unlikely(__pyx_t_3 < 0)) { - PyErr_Fetch(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_nvals, (PyObject*)__pyx_v_nvals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_12, __pyx_t_11, __pyx_t_10); - } - } - __pyx_bstride_0_nvals = __pyx_bstruct_nvals.strides[0]; __pyx_bstride_1_nvals = __pyx_bstruct_nvals.strides[1]; - __pyx_bshape_0_nvals = __pyx_bstruct_nvals.shape[0]; __pyx_bshape_1_nvals = __pyx_bstruct_nvals.shape[1]; - if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_13 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_nvals)); - __pyx_v_nvals = ((PyArrayObject *)__pyx_t_8); - __pyx_t_8 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":203 - * npos = np.zeros( (total, 2), dtype='int64') - * nvals = np.zeros( (total, self.nvals), dtype='float64') - * nwvals = np.zeros( total, dtype='float64') # <<<<<<<<<<<<<< - * cdef np.int64_t curpos = 0 - * cdef np.int64_t *pdata = npos.data - */ - __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__zeros); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyInt_FromLong(__pyx_v_total); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_8)); - if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__float64)) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_7 = PyEval_CallObjectWithKeywords(__pyx_t_6, __pyx_t_1, ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_14 = ((PyArrayObject *)__pyx_t_7); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_nwvals); - __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_nwvals, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_3 < 0)) { - PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_nwvals, (PyObject*)__pyx_v_nwvals, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12); - } - } - __pyx_bstride_0_nwvals = __pyx_bstruct_nwvals.strides[0]; - __pyx_bshape_0_nwvals = __pyx_bstruct_nwvals.shape[0]; - if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_14 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_nwvals)); - __pyx_v_nwvals = ((PyArrayObject *)__pyx_t_7); - __pyx_t_7 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":204 - * nvals = np.zeros( (total, self.nvals), dtype='float64') - * nwvals = np.zeros( total, dtype='float64') - * cdef np.int64_t curpos = 0 # <<<<<<<<<<<<<< - * cdef np.int64_t *pdata = npos.data - * cdef np.float64_t *vdata = nvals.data - */ - __pyx_v_curpos = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":205 - * nwvals = np.zeros( total, dtype='float64') - * cdef np.int64_t curpos = 0 - * cdef np.int64_t *pdata = npos.data # <<<<<<<<<<<<<< - * cdef np.float64_t *vdata = nvals.data - * cdef np.float64_t *wdata = nwvals.data - */ - __pyx_v_pdata = ((__pyx_t_5numpy_int64_t *)__pyx_v_npos->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":206 - * cdef np.int64_t curpos = 0 - * cdef np.int64_t *pdata = npos.data - * cdef np.float64_t *vdata = nvals.data # <<<<<<<<<<<<<< - * cdef np.float64_t *wdata = nwvals.data - * for i in range(self.top_grid_dims[0]): - */ - __pyx_v_vdata = ((__pyx_t_5numpy_float64_t *)__pyx_v_nvals->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":207 - * cdef np.int64_t *pdata = npos.data - * cdef np.float64_t *vdata = nvals.data - * cdef np.float64_t *wdata = nwvals.data # <<<<<<<<<<<<<< - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): - */ - __pyx_v_wdata = ((__pyx_t_5numpy_float64_t *)__pyx_v_nwvals->data); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":208 - * cdef np.float64_t *vdata = nvals.data - * cdef np.float64_t *wdata = nwvals.data - * for i in range(self.top_grid_dims[0]): # <<<<<<<<<<<<<< - * for j in range(self.top_grid_dims[1]): - * curpos += self.fill_from_level(self.root_nodes[i][j], - */ - __pyx_t_2 = (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[0]); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":209 - * cdef np.float64_t *wdata = nwvals.data - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): # <<<<<<<<<<<<<< - * curpos += self.fill_from_level(self.root_nodes[i][j], - * level, curpos, pdata, vdata, wdata) - */ - __pyx_t_4 = (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[1]); - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_j = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":211 - * for j in range(self.top_grid_dims[1]): - * curpos += self.fill_from_level(self.root_nodes[i][j], - * level, curpos, pdata, vdata, wdata) # <<<<<<<<<<<<<< - * return npos, nvals, nwvals - * - */ - __pyx_v_curpos += ((struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *)((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->__pyx_vtab)->fill_from_level(((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self), ((((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes[__pyx_v_i])[__pyx_v_j]), __pyx_v_level, __pyx_v_curpos, __pyx_v_pdata, __pyx_v_vdata, __pyx_v_wdata); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":212 - * curpos += self.fill_from_level(self.root_nodes[i][j], - * level, curpos, pdata, vdata, wdata) - * return npos, nvals, nwvals # <<<<<<<<<<<<<< - * - * cdef int count_at_level(self, QuadTreeNode *node, int level): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_v_npos)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_npos)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_npos)); - __Pyx_INCREF(((PyObject *)__pyx_v_nvals)); - PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_v_nvals)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_nvals)); - __Pyx_INCREF(((PyObject *)__pyx_v_nwvals)); - PyTuple_SET_ITEM(__pyx_t_7, 2, ((PyObject *)__pyx_v_nwvals)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_nwvals)); - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_nwvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_nvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_npos); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.amr_utils.QuadTree.get_all_from_level"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_nwvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_nvals); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_npos); - __pyx_L2:; - __Pyx_DECREF(__pyx_v_vals); - __Pyx_DECREF((PyObject *)__pyx_v_npos); - __Pyx_DECREF((PyObject *)__pyx_v_nvals); - __Pyx_DECREF((PyObject *)__pyx_v_nwvals); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":214 - * return npos, nvals, nwvals - * - * cdef int count_at_level(self, QuadTreeNode *node, int level): # <<<<<<<<<<<<<< - * cdef int i, j - * # We only really return a non-zero, calculated value if we are at the - */ - -static int __pyx_f_2yt_9amr_utils_8QuadTree_count_at_level(struct __pyx_obj_2yt_9amr_utils_QuadTree *__pyx_v_self, struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_node, int __pyx_v_level) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_count; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("count_at_level"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":218 - * # We only really return a non-zero, calculated value if we are at the - * # level in question. - * if node.level == level: # <<<<<<<<<<<<<< - * # We return 1 if there are no finer points at this level and zero - * # if there are - */ - __pyx_t_1 = (__pyx_v_node->level == __pyx_v_level); - if (__pyx_t_1) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":221 - * # We return 1 if there are no finer points at this level and zero - * # if there are - * return (node.children[0][0] == NULL) # <<<<<<<<<<<<<< - * if node.children[0][0] == NULL: return 0 - * cdef int count = 0 - */ - __pyx_r = (((__pyx_v_node->children[0])[0]) == NULL); - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":222 - * # if there are - * return (node.children[0][0] == NULL) - * if node.children[0][0] == NULL: return 0 # <<<<<<<<<<<<<< - * cdef int count = 0 - * for i in range(2): - */ - __pyx_t_1 = (((__pyx_v_node->children[0])[0]) == NULL); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":223 - * return (node.children[0][0] == NULL) - * if node.children[0][0] == NULL: return 0 - * cdef int count = 0 # <<<<<<<<<<<<<< - * for i in range(2): - * for j in range(2): - */ - __pyx_v_count = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":224 - * if node.children[0][0] == NULL: return 0 - * cdef int count = 0 - * for i in range(2): # <<<<<<<<<<<<<< - * for j in range(2): - * count += self.count_at_level(node.children[i][j], level) - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 2; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":225 - * cdef int count = 0 - * for i in range(2): - * for j in range(2): # <<<<<<<<<<<<<< - * count += self.count_at_level(node.children[i][j], level) - * return count - */ - for (__pyx_t_3 = 0; __pyx_t_3 < 2; __pyx_t_3+=1) { - __pyx_v_j = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":226 - * for i in range(2): - * for j in range(2): - * count += self.count_at_level(node.children[i][j], level) # <<<<<<<<<<<<<< - * return count - * - */ - __pyx_v_count += ((struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *)__pyx_v_self->__pyx_vtab)->count_at_level(__pyx_v_self, ((__pyx_v_node->children[__pyx_v_i])[__pyx_v_j]), __pyx_v_level); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":227 - * for j in range(2): - * count += self.count_at_level(node.children[i][j], level) - * return count # <<<<<<<<<<<<<< - * - * cdef int fill_from_level(self, QuadTreeNode *node, int level, - */ - __pyx_r = __pyx_v_count; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":229 - * return count - * - * cdef int fill_from_level(self, QuadTreeNode *node, int level, # <<<<<<<<<<<<<< - * np.int64_t curpos, - * np.int64_t *pdata, - */ - -static int __pyx_f_2yt_9amr_utils_8QuadTree_fill_from_level(struct __pyx_obj_2yt_9amr_utils_QuadTree *__pyx_v_self, struct __pyx_t_2yt_9amr_utils_QuadTreeNode *__pyx_v_node, int __pyx_v_level, __pyx_t_5numpy_int64_t __pyx_v_curpos, __pyx_t_5numpy_int64_t *__pyx_v_pdata, __pyx_t_5numpy_float64_t *__pyx_v_vdata, __pyx_t_5numpy_float64_t *__pyx_v_wdata) { - int __pyx_v_i; - int __pyx_v_j; - __pyx_t_5numpy_int64_t __pyx_v_added; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("fill_from_level"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":235 - * np.float64_t *wdata): - * cdef int i, j - * if node.level == level: # <<<<<<<<<<<<<< - * if node.children[0][0] != NULL: return 0 - * for i in range(self.nvals): - */ - __pyx_t_1 = (__pyx_v_node->level == __pyx_v_level); - if (__pyx_t_1) { - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":236 - * cdef int i, j - * if node.level == level: - * if node.children[0][0] != NULL: return 0 # <<<<<<<<<<<<<< - * for i in range(self.nvals): - * vdata[self.nvals * curpos + i] = node.val[i] - */ - __pyx_t_1 = (((__pyx_v_node->children[0])[0]) != NULL); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":237 - * if node.level == level: - * if node.children[0][0] != NULL: return 0 - * for i in range(self.nvals): # <<<<<<<<<<<<<< - * vdata[self.nvals * curpos + i] = node.val[i] - * wdata[curpos] = node.weight_val - */ - __pyx_t_2 = __pyx_v_self->nvals; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":238 - * if node.children[0][0] != NULL: return 0 - * for i in range(self.nvals): - * vdata[self.nvals * curpos + i] = node.val[i] # <<<<<<<<<<<<<< - * wdata[curpos] = node.weight_val - * pdata[curpos * 2] = node.pos[0] - */ - (__pyx_v_vdata[((__pyx_v_self->nvals * __pyx_v_curpos) + __pyx_v_i)]) = (__pyx_v_node->val[__pyx_v_i]); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":239 - * for i in range(self.nvals): - * vdata[self.nvals * curpos + i] = node.val[i] - * wdata[curpos] = node.weight_val # <<<<<<<<<<<<<< - * pdata[curpos * 2] = node.pos[0] - * pdata[curpos * 2 + 1] = node.pos[1] - */ - (__pyx_v_wdata[__pyx_v_curpos]) = __pyx_v_node->weight_val; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":240 - * vdata[self.nvals * curpos + i] = node.val[i] - * wdata[curpos] = node.weight_val - * pdata[curpos * 2] = node.pos[0] # <<<<<<<<<<<<<< - * pdata[curpos * 2 + 1] = node.pos[1] - * return 1 - */ - (__pyx_v_pdata[(__pyx_v_curpos * 2)]) = (__pyx_v_node->pos[0]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":241 - * wdata[curpos] = node.weight_val - * pdata[curpos * 2] = node.pos[0] - * pdata[curpos * 2 + 1] = node.pos[1] # <<<<<<<<<<<<<< - * return 1 - * if node.children[0][0] == NULL: return 0 - */ - (__pyx_v_pdata[((__pyx_v_curpos * 2) + 1)]) = (__pyx_v_node->pos[1]); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":242 - * pdata[curpos * 2] = node.pos[0] - * pdata[curpos * 2 + 1] = node.pos[1] - * return 1 # <<<<<<<<<<<<<< - * if node.children[0][0] == NULL: return 0 - * cdef np.int64_t added = 0 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":243 - * pdata[curpos * 2 + 1] = node.pos[1] - * return 1 - * if node.children[0][0] == NULL: return 0 # <<<<<<<<<<<<<< - * cdef np.int64_t added = 0 - * for i in range(2): - */ - __pyx_t_1 = (((__pyx_v_node->children[0])[0]) == NULL); - if (__pyx_t_1) { - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":244 - * return 1 - * if node.children[0][0] == NULL: return 0 - * cdef np.int64_t added = 0 # <<<<<<<<<<<<<< - * for i in range(2): - * for j in range(2): - */ - __pyx_v_added = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":245 - * if node.children[0][0] == NULL: return 0 - * cdef np.int64_t added = 0 - * for i in range(2): # <<<<<<<<<<<<<< - * for j in range(2): - * added += self.fill_from_level(node.children[i][j], - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 2; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":246 - * cdef np.int64_t added = 0 - * for i in range(2): - * for j in range(2): # <<<<<<<<<<<<<< - * added += self.fill_from_level(node.children[i][j], - * level, curpos + added, pdata, vdata, wdata) - */ - for (__pyx_t_3 = 0; __pyx_t_3 < 2; __pyx_t_3+=1) { - __pyx_v_j = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":248 - * for j in range(2): - * added += self.fill_from_level(node.children[i][j], - * level, curpos + added, pdata, vdata, wdata) # <<<<<<<<<<<<<< - * return added - * - */ - __pyx_v_added += ((struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree *)__pyx_v_self->__pyx_vtab)->fill_from_level(__pyx_v_self, ((__pyx_v_node->children[__pyx_v_i])[__pyx_v_j]), __pyx_v_level, (__pyx_v_curpos + __pyx_v_added), __pyx_v_pdata, __pyx_v_vdata, __pyx_v_wdata); - } - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":249 - * added += self.fill_from_level(node.children[i][j], - * level, curpos + added, pdata, vdata, wdata) - * return added # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_r = __pyx_v_added; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":251 - * return added - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * cdef int i, j - * for i in range(self.top_grid_dims[0]): - */ - -static void __pyx_pf_2yt_9amr_utils_8QuadTree___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pf_2yt_9amr_utils_8QuadTree___dealloc__(PyObject *__pyx_v_self) { - int __pyx_v_i; - int __pyx_v_j; - __pyx_t_5numpy_int64_t __pyx_t_1; - int __pyx_t_2; - __pyx_t_5numpy_int64_t __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("__dealloc__"); - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":253 - * def __dealloc__(self): - * cdef int i, j - * for i in range(self.top_grid_dims[0]): # <<<<<<<<<<<<<< - * for j in range(self.top_grid_dims[1]): - * QTN_free(self.root_nodes[i][j]) - */ - __pyx_t_1 = (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[0]); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":254 - * cdef int i, j - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): # <<<<<<<<<<<<<< - * QTN_free(self.root_nodes[i][j]) - * free(self.root_nodes[i]) - */ - __pyx_t_3 = (((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->top_grid_dims[1]); - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_j = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":255 - * for i in range(self.top_grid_dims[0]): - * for j in range(self.top_grid_dims[1]): - * QTN_free(self.root_nodes[i][j]) # <<<<<<<<<<<<<< - * free(self.root_nodes[i]) - * free(self.root_nodes) - */ - __pyx_f_2yt_9amr_utils_QTN_free(((((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes[__pyx_v_i])[__pyx_v_j])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":256 - * for j in range(self.top_grid_dims[1]): - * QTN_free(self.root_nodes[i][j]) - * free(self.root_nodes[i]) # <<<<<<<<<<<<<< - * free(self.root_nodes) - */ - free((((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes[__pyx_v_i])); - } - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":257 - * QTN_free(self.root_nodes[i][j]) - * free(self.root_nodes[i]) - * free(self.root_nodes) # <<<<<<<<<<<<<< - */ - free(((struct __pyx_obj_2yt_9amr_utils_QuadTree *)__pyx_v_self)->root_nodes); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":188 - * # experimental exception made for __getbuffer__ and __releasebuffer__ - * # -- the details of this may change. - * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fullfill the PEP. - */ - -static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_v_copy_shape; - int __pyx_v_i; - int __pyx_v_ndim; - int __pyx_v_endian_detector; - int __pyx_v_little_endian; - int __pyx_v_t; - char *__pyx_v_f; - PyArray_Descr *__pyx_v_descr = 0; - int __pyx_v_offset; - int __pyx_v_hasfields; - int __pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - char *__pyx_t_9; - __Pyx_RefNannySetupContext("__getbuffer__"); - if (__pyx_v_info == NULL) return 0; - __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(__pyx_v_info->obj); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":194 - * # of flags - * cdef int copy_shape, i, ndim - * cdef int endian_detector = 1 # <<<<<<<<<<<<<< - * cdef bint little_endian = ((&endian_detector)[0] != 0) - * - */ - __pyx_v_endian_detector = 1; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":195 - * cdef int copy_shape, i, ndim - * cdef int endian_detector = 1 - * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< - * - * ndim = PyArray_NDIM(self) - */ - __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":197 - * cdef bint little_endian = ((&endian_detector)[0] != 0) - * - * ndim = PyArray_NDIM(self) # <<<<<<<<<<<<<< - * - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - */ - __pyx_v_ndim = PyArray_NDIM(((PyArrayObject *)__pyx_v_self)); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":199 - * ndim = PyArray_NDIM(self) - * - * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< - * copy_shape = 1 - * else: - */ - __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":200 - * - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - * copy_shape = 1 # <<<<<<<<<<<<<< - * else: - * copy_shape = 0 - */ - __pyx_v_copy_shape = 1; - goto __pyx_L5; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":202 - * copy_shape = 1 - * else: - * copy_shape = 0 # <<<<<<<<<<<<<< - * - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - */ - __pyx_v_copy_shape = 0; - } - __pyx_L5:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":204 - * copy_shape = 0 - * - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) # <<<<<<<<<<<<<< - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":205 - * - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): # <<<<<<<<<<<<<< - * raise ValueError(u"ndarray is not C contiguous") - * - */ - __pyx_t_2 = (!PyArray_CHKFLAGS(((PyArrayObject *)__pyx_v_self), NPY_C_CONTIGUOUS)); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":206 - * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): - * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_7)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_u_7)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_7)); - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":208 - * raise ValueError(u"ndarray is not C contiguous") - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) # <<<<<<<<<<<<<< - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") - */ - __pyx_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS); - if (__pyx_t_3) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":209 - * - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): # <<<<<<<<<<<<<< - * raise ValueError(u"ndarray is not Fortran contiguous") - * - */ - __pyx_t_1 = (!PyArray_CHKFLAGS(((PyArrayObject *)__pyx_v_self), NPY_F_CONTIGUOUS)); - __pyx_t_2 = __pyx_t_1; - } else { - __pyx_t_2 = __pyx_t_3; - } - if (__pyx_t_2) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":210 - * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) - * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): - * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< - * - * info.buf = PyArray_DATA(self) - */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_8)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_u_8)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_8)); - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":212 - * raise ValueError(u"ndarray is not Fortran contiguous") - * - * info.buf = PyArray_DATA(self) # <<<<<<<<<<<<<< - * info.ndim = ndim - * if copy_shape: - */ - __pyx_v_info->buf = PyArray_DATA(((PyArrayObject *)__pyx_v_self)); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":213 - * - * info.buf = PyArray_DATA(self) - * info.ndim = ndim # <<<<<<<<<<<<<< - * if copy_shape: - * # Allocate new buffer for strides and shape info. This is allocated - */ - __pyx_v_info->ndim = __pyx_v_ndim; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":214 - * info.buf = PyArray_DATA(self) - * info.ndim = ndim - * if copy_shape: # <<<<<<<<<<<<<< - * # Allocate new buffer for strides and shape info. This is allocated - * # as one block, strides first. - */ - if (__pyx_v_copy_shape) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":217 - * # Allocate new buffer for strides and shape info. This is allocated - * # as one block, strides first. - * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) # <<<<<<<<<<<<<< - * info.shape = info.strides + ndim - * for i in range(ndim): - */ - __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * __pyx_v_ndim) * 2))); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":218 - * # as one block, strides first. - * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) - * info.shape = info.strides + ndim # <<<<<<<<<<<<<< - * for i in range(ndim): - * info.strides[i] = PyArray_STRIDES(self)[i] - */ - __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":219 - * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) - * info.shape = info.strides + ndim - * for i in range(ndim): # <<<<<<<<<<<<<< - * info.strides[i] = PyArray_STRIDES(self)[i] - * info.shape[i] = PyArray_DIMS(self)[i] - */ - __pyx_t_6 = __pyx_v_ndim; - for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { - __pyx_v_i = __pyx_t_7; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":220 - * info.shape = info.strides + ndim - * for i in range(ndim): - * info.strides[i] = PyArray_STRIDES(self)[i] # <<<<<<<<<<<<<< - * info.shape[i] = PyArray_DIMS(self)[i] - * else: - */ - (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(((PyArrayObject *)__pyx_v_self))[__pyx_v_i]); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":221 - * for i in range(ndim): - * info.strides[i] = PyArray_STRIDES(self)[i] - * info.shape[i] = PyArray_DIMS(self)[i] # <<<<<<<<<<<<<< - * else: - * info.strides = PyArray_STRIDES(self) - */ - (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(((PyArrayObject *)__pyx_v_self))[__pyx_v_i]); - } - goto __pyx_L8; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":223 - * info.shape[i] = PyArray_DIMS(self)[i] - * else: - * info.strides = PyArray_STRIDES(self) # <<<<<<<<<<<<<< - * info.shape = PyArray_DIMS(self) - * info.suboffsets = NULL - */ - __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(((PyArrayObject *)__pyx_v_self))); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":224 - * else: - * info.strides = PyArray_STRIDES(self) - * info.shape = PyArray_DIMS(self) # <<<<<<<<<<<<<< - * info.suboffsets = NULL - * info.itemsize = PyArray_ITEMSIZE(self) - */ - __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(((PyArrayObject *)__pyx_v_self))); - } - __pyx_L8:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":225 - * info.strides = PyArray_STRIDES(self) - * info.shape = PyArray_DIMS(self) - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * info.itemsize = PyArray_ITEMSIZE(self) - * info.readonly = not PyArray_ISWRITEABLE(self) - */ - __pyx_v_info->suboffsets = NULL; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":226 - * info.shape = PyArray_DIMS(self) - * info.suboffsets = NULL - * info.itemsize = PyArray_ITEMSIZE(self) # <<<<<<<<<<<<<< - * info.readonly = not PyArray_ISWRITEABLE(self) - * - */ - __pyx_v_info->itemsize = PyArray_ITEMSIZE(((PyArrayObject *)__pyx_v_self)); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":227 - * info.suboffsets = NULL - * info.itemsize = PyArray_ITEMSIZE(self) - * info.readonly = not PyArray_ISWRITEABLE(self) # <<<<<<<<<<<<<< - * - * cdef int t - */ - __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(((PyArrayObject *)__pyx_v_self))); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":230 - * - * cdef int t - * cdef char* f = NULL # <<<<<<<<<<<<<< - * cdef dtype descr = self.descr - * cdef list stack - */ - __pyx_v_f = NULL; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":231 - * cdef int t - * cdef char* f = NULL - * cdef dtype descr = self.descr # <<<<<<<<<<<<<< - * cdef list stack - * cdef int offset - */ - __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_v_self)->descr)); - __pyx_v_descr = ((PyArrayObject *)__pyx_v_self)->descr; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":235 - * cdef int offset - * - * cdef bint hasfields = PyDataType_HASFIELDS(descr) # <<<<<<<<<<<<<< - * - * if not hasfields and not copy_shape: - */ - __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":237 - * cdef bint hasfields = PyDataType_HASFIELDS(descr) - * - * if not hasfields and not copy_shape: # <<<<<<<<<<<<<< - * # do not call releasebuffer - * info.obj = None - */ - __pyx_t_2 = (!__pyx_v_hasfields); - if (__pyx_t_2) { - __pyx_t_3 = (!__pyx_v_copy_shape); - __pyx_t_1 = __pyx_t_3; - } else { - __pyx_t_1 = __pyx_t_2; - } - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":239 - * if not hasfields and not copy_shape: - * # do not call releasebuffer - * info.obj = None # <<<<<<<<<<<<<< - * else: - * # need to call releasebuffer - */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = Py_None; - goto __pyx_L11; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":242 - * else: - * # need to call releasebuffer - * info.obj = self # <<<<<<<<<<<<<< - * - * if not hasfields: - */ - __Pyx_INCREF(__pyx_v_self); - __Pyx_GIVEREF(__pyx_v_self); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = __pyx_v_self; - } - __pyx_L11:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":244 - * info.obj = self - * - * if not hasfields: # <<<<<<<<<<<<<< - * t = descr.type_num - * if ((descr.byteorder == '>' and little_endian) or - */ - __pyx_t_1 = (!__pyx_v_hasfields); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":245 - * - * if not hasfields: - * t = descr.type_num # <<<<<<<<<<<<<< - * if ((descr.byteorder == '>' and little_endian) or - * (descr.byteorder == '<' and not little_endian)): - */ - __pyx_v_t = __pyx_v_descr->type_num; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":246 - * if not hasfields: - * t = descr.type_num - * if ((descr.byteorder == '>' and little_endian) or # <<<<<<<<<<<<<< - * (descr.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") - */ - __pyx_t_1 = (__pyx_v_descr->byteorder == '>'); - if (__pyx_t_1) { - __pyx_t_2 = __pyx_v_little_endian; - } else { - __pyx_t_2 = __pyx_t_1; - } - if (!__pyx_t_2) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":247 - * t = descr.type_num - * if ((descr.byteorder == '>' and little_endian) or - * (descr.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< - * raise ValueError(u"Non-native byte order not supported") - * if t == NPY_BYTE: f = "b" - */ - __pyx_t_1 = (__pyx_v_descr->byteorder == '<'); - if (__pyx_t_1) { - __pyx_t_3 = (!__pyx_v_little_endian); - __pyx_t_8 = __pyx_t_3; - } else { - __pyx_t_8 = __pyx_t_1; - } - __pyx_t_1 = __pyx_t_8; - } else { - __pyx_t_1 = __pyx_t_2; - } - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":248 - * if ((descr.byteorder == '>' and little_endian) or - * (descr.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_9)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_u_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_9)); - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L13; - } - __pyx_L13:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":249 - * (descr.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") - * if t == NPY_BYTE: f = "b" # <<<<<<<<<<<<<< - * elif t == NPY_UBYTE: f = "B" - * elif t == NPY_SHORT: f = "h" - */ - __pyx_t_1 = (__pyx_v_t == NPY_BYTE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__b; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":250 - * raise ValueError(u"Non-native byte order not supported") - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" # <<<<<<<<<<<<<< - * elif t == NPY_SHORT: f = "h" - * elif t == NPY_USHORT: f = "H" - */ - __pyx_t_1 = (__pyx_v_t == NPY_UBYTE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__B; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":251 - * if t == NPY_BYTE: f = "b" - * elif t == NPY_UBYTE: f = "B" - * elif t == NPY_SHORT: f = "h" # <<<<<<<<<<<<<< - * elif t == NPY_USHORT: f = "H" - * elif t == NPY_INT: f = "i" - */ - __pyx_t_1 = (__pyx_v_t == NPY_SHORT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__h; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":252 - * elif t == NPY_UBYTE: f = "B" - * elif t == NPY_SHORT: f = "h" - * elif t == NPY_USHORT: f = "H" # <<<<<<<<<<<<<< - * elif t == NPY_INT: f = "i" - * elif t == NPY_UINT: f = "I" - */ - __pyx_t_1 = (__pyx_v_t == NPY_USHORT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__H; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":253 - * elif t == NPY_SHORT: f = "h" - * elif t == NPY_USHORT: f = "H" - * elif t == NPY_INT: f = "i" # <<<<<<<<<<<<<< - * elif t == NPY_UINT: f = "I" - * elif t == NPY_LONG: f = "l" - */ - __pyx_t_1 = (__pyx_v_t == NPY_INT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__i; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":254 - * elif t == NPY_USHORT: f = "H" - * elif t == NPY_INT: f = "i" - * elif t == NPY_UINT: f = "I" # <<<<<<<<<<<<<< - * elif t == NPY_LONG: f = "l" - * elif t == NPY_ULONG: f = "L" - */ - __pyx_t_1 = (__pyx_v_t == NPY_UINT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__I; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":255 - * elif t == NPY_INT: f = "i" - * elif t == NPY_UINT: f = "I" - * elif t == NPY_LONG: f = "l" # <<<<<<<<<<<<<< - * elif t == NPY_ULONG: f = "L" - * elif t == NPY_LONGLONG: f = "q" - */ - __pyx_t_1 = (__pyx_v_t == NPY_LONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__l; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":256 - * elif t == NPY_UINT: f = "I" - * elif t == NPY_LONG: f = "l" - * elif t == NPY_ULONG: f = "L" # <<<<<<<<<<<<<< - * elif t == NPY_LONGLONG: f = "q" - * elif t == NPY_ULONGLONG: f = "Q" - */ - __pyx_t_1 = (__pyx_v_t == NPY_ULONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__L; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":257 - * elif t == NPY_LONG: f = "l" - * elif t == NPY_ULONG: f = "L" - * elif t == NPY_LONGLONG: f = "q" # <<<<<<<<<<<<<< - * elif t == NPY_ULONGLONG: f = "Q" - * elif t == NPY_FLOAT: f = "f" - */ - __pyx_t_1 = (__pyx_v_t == NPY_LONGLONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__q; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":258 - * elif t == NPY_ULONG: f = "L" - * elif t == NPY_LONGLONG: f = "q" - * elif t == NPY_ULONGLONG: f = "Q" # <<<<<<<<<<<<<< - * elif t == NPY_FLOAT: f = "f" - * elif t == NPY_DOUBLE: f = "d" - */ - __pyx_t_1 = (__pyx_v_t == NPY_ULONGLONG); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Q; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":259 - * elif t == NPY_LONGLONG: f = "q" - * elif t == NPY_ULONGLONG: f = "Q" - * elif t == NPY_FLOAT: f = "f" # <<<<<<<<<<<<<< - * elif t == NPY_DOUBLE: f = "d" - * elif t == NPY_LONGDOUBLE: f = "g" - */ - __pyx_t_1 = (__pyx_v_t == NPY_FLOAT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__f; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":260 - * elif t == NPY_ULONGLONG: f = "Q" - * elif t == NPY_FLOAT: f = "f" - * elif t == NPY_DOUBLE: f = "d" # <<<<<<<<<<<<<< - * elif t == NPY_LONGDOUBLE: f = "g" - * elif t == NPY_CFLOAT: f = "Zf" - */ - __pyx_t_1 = (__pyx_v_t == NPY_DOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__d; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":261 - * elif t == NPY_FLOAT: f = "f" - * elif t == NPY_DOUBLE: f = "d" - * elif t == NPY_LONGDOUBLE: f = "g" # <<<<<<<<<<<<<< - * elif t == NPY_CFLOAT: f = "Zf" - * elif t == NPY_CDOUBLE: f = "Zd" - */ - __pyx_t_1 = (__pyx_v_t == NPY_LONGDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__g; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":262 - * elif t == NPY_DOUBLE: f = "d" - * elif t == NPY_LONGDOUBLE: f = "g" - * elif t == NPY_CFLOAT: f = "Zf" # <<<<<<<<<<<<<< - * elif t == NPY_CDOUBLE: f = "Zd" - * elif t == NPY_CLONGDOUBLE: f = "Zg" - */ - __pyx_t_1 = (__pyx_v_t == NPY_CFLOAT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zf; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":263 - * elif t == NPY_LONGDOUBLE: f = "g" - * elif t == NPY_CFLOAT: f = "Zf" - * elif t == NPY_CDOUBLE: f = "Zd" # <<<<<<<<<<<<<< - * elif t == NPY_CLONGDOUBLE: f = "Zg" - * elif t == NPY_OBJECT: f = "O" - */ - __pyx_t_1 = (__pyx_v_t == NPY_CDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zd; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":264 - * elif t == NPY_CFLOAT: f = "Zf" - * elif t == NPY_CDOUBLE: f = "Zd" - * elif t == NPY_CLONGDOUBLE: f = "Zg" # <<<<<<<<<<<<<< - * elif t == NPY_OBJECT: f = "O" - * else: - */ - __pyx_t_1 = (__pyx_v_t == NPY_CLONGDOUBLE); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__Zg; - goto __pyx_L14; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":265 - * elif t == NPY_CDOUBLE: f = "Zd" - * elif t == NPY_CLONGDOUBLE: f = "Zg" - * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - */ - __pyx_t_1 = (__pyx_v_t == NPY_OBJECT); - if (__pyx_t_1) { - __pyx_v_f = __pyx_k__O; - goto __pyx_L14; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":267 - * elif t == NPY_OBJECT: f = "O" - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< - * info.format = f - * return - */ - __pyx_t_5 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_10), __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L14:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":268 - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - * info.format = f # <<<<<<<<<<<<<< - * return - * else: - */ - __pyx_v_info->format = __pyx_v_f; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":269 - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - * info.format = f - * return # <<<<<<<<<<<<<< - * else: - * info.format = stdlib.malloc(_buffer_format_string_len) - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L12; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":271 - * return - * else: - * info.format = stdlib.malloc(_buffer_format_string_len) # <<<<<<<<<<<<<< - * info.format[0] = '^' # Native data types, manual alignment - * offset = 0 - */ - __pyx_v_info->format = ((char *)malloc(255)); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":272 - * else: - * info.format = stdlib.malloc(_buffer_format_string_len) - * info.format[0] = '^' # Native data types, manual alignment # <<<<<<<<<<<<<< - * offset = 0 - * f = _util_dtypestring(descr, info.format + 1, - */ - (__pyx_v_info->format[0]) = '^'; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":273 - * info.format = stdlib.malloc(_buffer_format_string_len) - * info.format[0] = '^' # Native data types, manual alignment - * offset = 0 # <<<<<<<<<<<<<< - * f = _util_dtypestring(descr, info.format + 1, - * info.format + _buffer_format_string_len, - */ - __pyx_v_offset = 0; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":276 - * f = _util_dtypestring(descr, info.format + 1, - * info.format + _buffer_format_string_len, - * &offset) # <<<<<<<<<<<<<< - * f[0] = 0 # Terminate format string - * - */ - __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_9; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":277 - * info.format + _buffer_format_string_len, - * &offset) - * f[0] = 0 # Terminate format string # <<<<<<<<<<<<<< - * - * def __releasebuffer__(ndarray self, Py_buffer* info): - */ - (__pyx_v_f[0]) = 0; - } - __pyx_L12:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("numpy.ndarray.__getbuffer__"); - __pyx_r = -1; - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL; - goto __pyx_L2; - __pyx_L0:; - if (__pyx_v_info->obj == Py_None) { - __Pyx_GOTREF(Py_None); - __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; - } - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_descr); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":279 - * f[0] = 0 # Terminate format string - * - * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) - */ - -static CYTHON_UNUSED void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ -static CYTHON_UNUSED void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { - int __pyx_t_1; - __Pyx_RefNannySetupContext("__releasebuffer__"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":280 - * - * def __releasebuffer__(ndarray self, Py_buffer* info): - * if PyArray_HASFIELDS(self): # <<<<<<<<<<<<<< - * stdlib.free(info.format) - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - */ - __pyx_t_1 = PyArray_HASFIELDS(((PyArrayObject *)__pyx_v_self)); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":281 - * def __releasebuffer__(ndarray self, Py_buffer* info): - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) # <<<<<<<<<<<<<< - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - * stdlib.free(info.strides) - */ - free(__pyx_v_info->format); - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":282 - * if PyArray_HASFIELDS(self): - * stdlib.free(info.format) - * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< - * stdlib.free(info.strides) - * # info.shape was stored after info.strides in the same block - */ - __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":283 - * stdlib.free(info.format) - * if sizeof(npy_intp) != sizeof(Py_ssize_t): - * stdlib.free(info.strides) # <<<<<<<<<<<<<< - * # info.shape was stored after info.strides in the same block - * - */ - free(__pyx_v_info->strides); - goto __pyx_L6; - } - __pyx_L6:; - - __Pyx_RefNannyFinishContext(); -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":756 - * ctypedef npy_cdouble complex_t - * - * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(1, a) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew1"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":757 - * - * cdef inline object PyArray_MultiIterNew1(a): - * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew2(a, b): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":759 - * return PyArray_MultiIterNew(1, a) - * - * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(2, a, b) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew2"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":760 - * - * cdef inline object PyArray_MultiIterNew2(a, b): - * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":762 - * return PyArray_MultiIterNew(2, a, b) - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(3, a, b, c) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew3"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":763 - * - * cdef inline object PyArray_MultiIterNew3(a, b, c): - * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":765 - * return PyArray_MultiIterNew(3, a, b, c) - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(4, a, b, c, d) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew4"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":766 - * - * cdef inline object PyArray_MultiIterNew4(a, b, c, d): - * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":768 - * return PyArray_MultiIterNew(4, a, b, c, d) - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("PyArray_MultiIterNew5"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":769 - * - * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): - * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< - * - * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":771 - * return PyArray_MultiIterNew(5, a, b, c, d, e) - * - * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< - * # Recursive utility function used in __getbuffer__ to get format - * # string. The new location in the format string is returned. - */ - -static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) { - PyArray_Descr *__pyx_v_child; - int __pyx_v_endian_detector; - int __pyx_v_little_endian; - PyObject *__pyx_v_fields; - PyObject *__pyx_v_childname; - PyObject *__pyx_v_new_offset; - PyObject *__pyx_v_t; - char *__pyx_r; - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - char *__pyx_t_10; - __Pyx_RefNannySetupContext("_util_dtypestring"); - __pyx_v_child = ((PyArray_Descr *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_fields = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_childname = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_new_offset = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_t = Py_None; __Pyx_INCREF(Py_None); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":778 - * cdef int delta_offset - * cdef tuple i - * cdef int endian_detector = 1 # <<<<<<<<<<<<<< - * cdef bint little_endian = ((&endian_detector)[0] != 0) - * cdef tuple fields - */ - __pyx_v_endian_detector = 1; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":779 - * cdef tuple i - * cdef int endian_detector = 1 - * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< - * cdef tuple fields - * - */ - __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":782 - * cdef tuple fields - * - * for childname in descr.names: # <<<<<<<<<<<<<< - * fields = descr.fields[childname] - * child, new_offset = fields - */ - if (likely(((PyObject *)__pyx_v_descr->names) != Py_None)) { - __pyx_t_1 = 0; __pyx_t_2 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_2); - } else { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - for (;;) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; - __Pyx_DECREF(__pyx_v_childname); - __pyx_v_childname = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":783 - * - * for childname in descr.names: - * fields = descr.fields[childname] # <<<<<<<<<<<<<< - * child, new_offset = fields - * - */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_v_fields)); - __pyx_v_fields = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":784 - * for childname in descr.names: - * fields = descr.fields[childname] - * child, new_offset = fields # <<<<<<<<<<<<<< - * - * if (end - f) - (new_offset - offset[0]) < 15: - */ - if (likely(((PyObject *)__pyx_v_fields) != Py_None) && likely(PyTuple_GET_SIZE(((PyObject *)__pyx_v_fields)) == 2)) { - PyObject* tuple = ((PyObject *)__pyx_v_fields); - __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_v_child)); - __pyx_v_child = ((PyArray_Descr *)__pyx_t_3); - __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_v_new_offset); - __pyx_v_new_offset = __pyx_t_4; - __pyx_t_4 = 0; - } else { - __Pyx_UnpackTupleError(((PyObject *)__pyx_v_fields), 2); - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":786 - * child, new_offset = fields - * - * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") - * - */ - __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":787 - * - * if (end - f) - (new_offset - offset[0]) < 15: - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< - * - * if ((child.byteorder == '>' and little_endian) or - */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_11)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_u_11)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_11)); - __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":789 - * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") - * - * if ((child.byteorder == '>' and little_endian) or # <<<<<<<<<<<<<< - * (child.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") - */ - __pyx_t_6 = (__pyx_v_child->byteorder == '>'); - if (__pyx_t_6) { - __pyx_t_7 = __pyx_v_little_endian; - } else { - __pyx_t_7 = __pyx_t_6; - } - if (!__pyx_t_7) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":790 - * - * if ((child.byteorder == '>' and little_endian) or - * (child.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< - * raise ValueError(u"Non-native byte order not supported") - * # One could encode it in the format string and have Cython - */ - __pyx_t_6 = (__pyx_v_child->byteorder == '<'); - if (__pyx_t_6) { - __pyx_t_8 = (!__pyx_v_little_endian); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_6; - } - __pyx_t_6 = __pyx_t_9; - } else { - __pyx_t_6 = __pyx_t_7; - } - if (__pyx_t_6) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":791 - * if ((child.byteorder == '>' and little_endian) or - * (child.byteorder == '<' and not little_endian)): - * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< - * # One could encode it in the format string and have Cython - * # complain instead, BUT: < and > in format strings also imply - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_9)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_9)); - __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":801 - * - * # Output padding bytes - * while offset[0] < new_offset: # <<<<<<<<<<<<<< - * f[0] = 120 # "x"; pad byte - * f += 1 - */ - while (1) { - __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_6) break; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":802 - * # Output padding bytes - * while offset[0] < new_offset: - * f[0] = 120 # "x"; pad byte # <<<<<<<<<<<<<< - * f += 1 - * offset[0] += 1 - */ - (__pyx_v_f[0]) = 120; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":803 - * while offset[0] < new_offset: - * f[0] = 120 # "x"; pad byte - * f += 1 # <<<<<<<<<<<<<< - * offset[0] += 1 - * - */ - __pyx_v_f += 1; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":804 - * f[0] = 120 # "x"; pad byte - * f += 1 - * offset[0] += 1 # <<<<<<<<<<<<<< - * - * offset[0] += child.itemsize - */ - (__pyx_v_offset[0]) += 1; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":806 - * offset[0] += 1 - * - * offset[0] += child.itemsize # <<<<<<<<<<<<<< - * - * if not PyDataType_HASFIELDS(child): - */ - (__pyx_v_offset[0]) += __pyx_v_child->elsize; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":808 - * offset[0] += child.itemsize - * - * if not PyDataType_HASFIELDS(child): # <<<<<<<<<<<<<< - * t = child.type_num - * if end - f < 5: - */ - __pyx_t_6 = (!PyDataType_HASFIELDS(__pyx_v_child)); - if (__pyx_t_6) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":809 - * - * if not PyDataType_HASFIELDS(child): - * t = child.type_num # <<<<<<<<<<<<<< - * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") - */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_v_t); - __pyx_v_t = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":810 - * if not PyDataType_HASFIELDS(child): - * t = child.type_num - * if end - f < 5: # <<<<<<<<<<<<<< - * raise RuntimeError(u"Format string allocated too short.") - * - */ - __pyx_t_6 = ((__pyx_v_end - __pyx_v_f) < 5); - if (__pyx_t_6) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":811 - * t = child.type_num - * if end - f < 5: - * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< - * - * # Until ticket #99 is fixed, use integers to avoid warnings - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_u_12)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_12)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_12)); - __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":814 - * - * # Until ticket #99 is fixed, use integers to avoid warnings - * if t == NPY_BYTE: f[0] = 98 #"b" # <<<<<<<<<<<<<< - * elif t == NPY_UBYTE: f[0] = 66 #"B" - * elif t == NPY_SHORT: f[0] = 104 #"h" - */ - __pyx_t_5 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 98; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":815 - * # Until ticket #99 is fixed, use integers to avoid warnings - * if t == NPY_BYTE: f[0] = 98 #"b" - * elif t == NPY_UBYTE: f[0] = 66 #"B" # <<<<<<<<<<<<<< - * elif t == NPY_SHORT: f[0] = 104 #"h" - * elif t == NPY_USHORT: f[0] = 72 #"H" - */ - __pyx_t_3 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 66; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":816 - * if t == NPY_BYTE: f[0] = 98 #"b" - * elif t == NPY_UBYTE: f[0] = 66 #"B" - * elif t == NPY_SHORT: f[0] = 104 #"h" # <<<<<<<<<<<<<< - * elif t == NPY_USHORT: f[0] = 72 #"H" - * elif t == NPY_INT: f[0] = 105 #"i" - */ - __pyx_t_5 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 104; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":817 - * elif t == NPY_UBYTE: f[0] = 66 #"B" - * elif t == NPY_SHORT: f[0] = 104 #"h" - * elif t == NPY_USHORT: f[0] = 72 #"H" # <<<<<<<<<<<<<< - * elif t == NPY_INT: f[0] = 105 #"i" - * elif t == NPY_UINT: f[0] = 73 #"I" - */ - __pyx_t_3 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 72; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":818 - * elif t == NPY_SHORT: f[0] = 104 #"h" - * elif t == NPY_USHORT: f[0] = 72 #"H" - * elif t == NPY_INT: f[0] = 105 #"i" # <<<<<<<<<<<<<< - * elif t == NPY_UINT: f[0] = 73 #"I" - * elif t == NPY_LONG: f[0] = 108 #"l" - */ - __pyx_t_5 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 105; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":819 - * elif t == NPY_USHORT: f[0] = 72 #"H" - * elif t == NPY_INT: f[0] = 105 #"i" - * elif t == NPY_UINT: f[0] = 73 #"I" # <<<<<<<<<<<<<< - * elif t == NPY_LONG: f[0] = 108 #"l" - * elif t == NPY_ULONG: f[0] = 76 #"L" - */ - __pyx_t_3 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 73; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":820 - * elif t == NPY_INT: f[0] = 105 #"i" - * elif t == NPY_UINT: f[0] = 73 #"I" - * elif t == NPY_LONG: f[0] = 108 #"l" # <<<<<<<<<<<<<< - * elif t == NPY_ULONG: f[0] = 76 #"L" - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - */ - __pyx_t_5 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 108; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":821 - * elif t == NPY_UINT: f[0] = 73 #"I" - * elif t == NPY_LONG: f[0] = 108 #"l" - * elif t == NPY_ULONG: f[0] = 76 #"L" # <<<<<<<<<<<<<< - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - */ - __pyx_t_3 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 76; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":822 - * elif t == NPY_LONG: f[0] = 108 #"l" - * elif t == NPY_ULONG: f[0] = 76 #"L" - * elif t == NPY_LONGLONG: f[0] = 113 #"q" # <<<<<<<<<<<<<< - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - * elif t == NPY_FLOAT: f[0] = 102 #"f" - */ - __pyx_t_5 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 113; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":823 - * elif t == NPY_ULONG: f[0] = 76 #"L" - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" # <<<<<<<<<<<<<< - * elif t == NPY_FLOAT: f[0] = 102 #"f" - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - */ - __pyx_t_3 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 81; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":824 - * elif t == NPY_LONGLONG: f[0] = 113 #"q" - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - * elif t == NPY_FLOAT: f[0] = 102 #"f" # <<<<<<<<<<<<<< - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - */ - __pyx_t_5 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 102; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":825 - * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" - * elif t == NPY_FLOAT: f[0] = 102 #"f" - * elif t == NPY_DOUBLE: f[0] = 100 #"d" # <<<<<<<<<<<<<< - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - */ - __pyx_t_3 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 100; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":826 - * elif t == NPY_FLOAT: f[0] = 102 #"f" - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" # <<<<<<<<<<<<<< - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - */ - __pyx_t_5 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 103; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":827 - * elif t == NPY_DOUBLE: f[0] = 100 #"d" - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf # <<<<<<<<<<<<<< - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg - */ - __pyx_t_3 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 90; - (__pyx_v_f[1]) = 102; - __pyx_v_f += 1; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":828 - * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd # <<<<<<<<<<<<<< - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg - * elif t == NPY_OBJECT: f[0] = 79 #"O" - */ - __pyx_t_5 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 90; - (__pyx_v_f[1]) = 100; - __pyx_v_f += 1; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":829 - * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg # <<<<<<<<<<<<<< - * elif t == NPY_OBJECT: f[0] = 79 #"O" - * else: - */ - __pyx_t_3 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 90; - (__pyx_v_f[1]) = 103; - __pyx_v_f += 1; - goto __pyx_L11; - } - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":830 - * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd - * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg - * elif t == NPY_OBJECT: f[0] = 79 #"O" # <<<<<<<<<<<<<< - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - */ - __pyx_t_5 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_6) { - (__pyx_v_f[0]) = 79; - goto __pyx_L11; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":832 - * elif t == NPY_OBJECT: f[0] = 79 #"O" - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< - * f += 1 - * else: - */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_10), __pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[10]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L11:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":833 - * else: - * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) - * f += 1 # <<<<<<<<<<<<<< - * else: - * # Cython ignores struct boundary information ("T{...}"), - */ - __pyx_v_f += 1; - goto __pyx_L9; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":837 - * # Cython ignores struct boundary information ("T{...}"), - * # so don't output it - * f = _util_dtypestring(child, f, end, offset) # <<<<<<<<<<<<<< - * return f - * - */ - __pyx_t_10 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f = __pyx_t_10; - } - __pyx_L9:; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":838 - * # so don't output it - * f = _util_dtypestring(child, f, end, offset) - * return f # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_f; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("numpy._util_dtypestring"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF((PyObject *)__pyx_v_child); - __Pyx_DECREF(__pyx_v_fields); - __Pyx_DECREF(__pyx_v_childname); - __Pyx_DECREF(__pyx_v_new_offset); - __Pyx_DECREF(__pyx_v_t); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":953 - * - * - * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< - * cdef PyObject* baseptr - * if base is None: - */ - -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { - PyObject *__pyx_v_baseptr; - int __pyx_t_1; - __Pyx_RefNannySetupContext("set_array_base"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":955 - * cdef inline void set_array_base(ndarray arr, object base): - * cdef PyObject* baseptr - * if base is None: # <<<<<<<<<<<<<< - * baseptr = NULL - * else: - */ - __pyx_t_1 = (__pyx_v_base == Py_None); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":956 - * cdef PyObject* baseptr - * if base is None: - * baseptr = NULL # <<<<<<<<<<<<<< - * else: - * Py_INCREF(base) # important to do this before decref below! - */ - __pyx_v_baseptr = NULL; - goto __pyx_L3; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":958 - * baseptr = NULL - * else: - * Py_INCREF(base) # important to do this before decref below! # <<<<<<<<<<<<<< - * baseptr = base - * Py_XDECREF(arr.base) - */ - Py_INCREF(__pyx_v_base); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":959 - * else: - * Py_INCREF(base) # important to do this before decref below! - * baseptr = base # <<<<<<<<<<<<<< - * Py_XDECREF(arr.base) - * arr.base = baseptr - */ - __pyx_v_baseptr = ((PyObject *)__pyx_v_base); - } - __pyx_L3:; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":960 - * Py_INCREF(base) # important to do this before decref below! - * baseptr = base - * Py_XDECREF(arr.base) # <<<<<<<<<<<<<< - * arr.base = baseptr - * - */ - Py_XDECREF(__pyx_v_arr->base); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":961 - * baseptr = base - * Py_XDECREF(arr.base) - * arr.base = baseptr # <<<<<<<<<<<<<< - * - * cdef inline object get_array_base(ndarray arr): - */ - __pyx_v_arr->base = __pyx_v_baseptr; - - __Pyx_RefNannyFinishContext(); -} - -/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":963 - * arr.base = baseptr - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * if arr.base is NULL: - * return None - */ - -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { - PyObject *__pyx_r = NULL; - int __pyx_t_1; - __Pyx_RefNannySetupContext("get_array_base"); - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":964 - * - * cdef inline object get_array_base(ndarray arr): - * if arr.base is NULL: # <<<<<<<<<<<<<< - * return None - * else: - */ - __pyx_t_1 = (__pyx_v_arr->base == NULL); - if (__pyx_t_1) { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":965 - * cdef inline object get_array_base(ndarray arr): - * if arr.base is NULL: - * return None # <<<<<<<<<<<<<< - * else: - * return arr.base - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":967 - * return None - * else: - * return arr.base # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_arr->base)); - __pyx_r = ((PyObject *)__pyx_v_arr->base); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_tp_new_2yt_9amr_utils_position(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - if (__pyx_pf_2yt_9amr_utils_8position___cinit__(o, __pyx_empty_tuple, NULL) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_position(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_8position_output_pos(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_8position_10output_pos___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_8position_output_pos(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_8position_10output_pos___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_8position_refined_pos(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_8position_11refined_pos___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_8position_refined_pos(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_8position_11refined_pos___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_position[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_position[] = { - {(char *)"output_pos", __pyx_getprop_2yt_9amr_utils_8position_output_pos, __pyx_setprop_2yt_9amr_utils_8position_output_pos, 0, 0}, - {(char *)"refined_pos", __pyx_getprop_2yt_9amr_utils_8position_refined_pos, __pyx_setprop_2yt_9amr_utils_8position_refined_pos, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_position = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_position = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_position = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_position = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_position = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.position"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_position), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_position, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_position, /*tp_as_number*/ - &__pyx_tp_as_sequence_position, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_position, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_position, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_position, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_position, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_position, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_OctreeGrid(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)o); - p->child_indices = Py_None; Py_INCREF(Py_None); - p->fields = Py_None; Py_INCREF(Py_None); - p->left_edges = Py_None; Py_INCREF(Py_None); - p->dimensions = Py_None; Py_INCREF(Py_None); - p->dx = Py_None; Py_INCREF(Py_None); - if (__pyx_pf_2yt_9amr_utils_10OctreeGrid___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_OctreeGrid(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *p = (struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)o; - Py_XDECREF(p->child_indices); - Py_XDECREF(p->fields); - Py_XDECREF(p->left_edges); - Py_XDECREF(p->dimensions); - Py_XDECREF(p->dx); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_2yt_9amr_utils_OctreeGrid(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *p = (struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)o; - if (p->child_indices) { - e = (*v)(p->child_indices, a); if (e) return e; - } - if (p->fields) { - e = (*v)(p->fields, a); if (e) return e; - } - if (p->left_edges) { - e = (*v)(p->left_edges, a); if (e) return e; - } - if (p->dimensions) { - e = (*v)(p->dimensions, a); if (e) return e; - } - if (p->dx) { - e = (*v)(p->dx, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_2yt_9amr_utils_OctreeGrid(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_OctreeGrid *p = (struct __pyx_obj_2yt_9amr_utils_OctreeGrid *)o; - PyObject* tmp; - tmp = ((PyObject*)p->child_indices); - p->child_indices = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fields); - p->fields = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->left_edges); - p->left_edges = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->dimensions); - p->dimensions = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->dx); - p->dx = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10OctreeGrid_child_indices(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10OctreeGrid_child_indices(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_13child_indices___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10OctreeGrid_fields(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10OctreeGrid_fields(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_6fields___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10OctreeGrid_left_edges(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10OctreeGrid_left_edges(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_10left_edges___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10OctreeGrid_dimensions(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10OctreeGrid_dimensions(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_10dimensions___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10OctreeGrid_dx(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10OctreeGrid_dx(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_2dx___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10OctreeGrid_level(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_5level___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10OctreeGrid_level(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10OctreeGrid_5level___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_OctreeGrid[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_OctreeGrid[] = { - {(char *)"child_indices", __pyx_getprop_2yt_9amr_utils_10OctreeGrid_child_indices, __pyx_setprop_2yt_9amr_utils_10OctreeGrid_child_indices, 0, 0}, - {(char *)"fields", __pyx_getprop_2yt_9amr_utils_10OctreeGrid_fields, __pyx_setprop_2yt_9amr_utils_10OctreeGrid_fields, 0, 0}, - {(char *)"left_edges", __pyx_getprop_2yt_9amr_utils_10OctreeGrid_left_edges, __pyx_setprop_2yt_9amr_utils_10OctreeGrid_left_edges, 0, 0}, - {(char *)"dimensions", __pyx_getprop_2yt_9amr_utils_10OctreeGrid_dimensions, __pyx_setprop_2yt_9amr_utils_10OctreeGrid_dimensions, 0, 0}, - {(char *)"dx", __pyx_getprop_2yt_9amr_utils_10OctreeGrid_dx, __pyx_setprop_2yt_9amr_utils_10OctreeGrid_dx, 0, 0}, - {(char *)"level", __pyx_getprop_2yt_9amr_utils_10OctreeGrid_level, __pyx_setprop_2yt_9amr_utils_10OctreeGrid_level, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_OctreeGrid = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_OctreeGrid = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_OctreeGrid = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_OctreeGrid = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_OctreeGrid = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.OctreeGrid"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_OctreeGrid), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_OctreeGrid, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_OctreeGrid, /*tp_as_number*/ - &__pyx_tp_as_sequence_OctreeGrid, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_OctreeGrid, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_OctreeGrid, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_2yt_9amr_utils_OctreeGrid, /*tp_traverse*/ - __pyx_tp_clear_2yt_9amr_utils_OctreeGrid, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_OctreeGrid, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_OctreeGrid, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_OctreeGrid, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_OctreeGridList(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_OctreeGridList *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)o); - p->grids = Py_None; Py_INCREF(Py_None); - if (__pyx_pf_2yt_9amr_utils_14OctreeGridList___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_OctreeGridList(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_OctreeGridList *p = (struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)o; - Py_XDECREF(p->grids); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_2yt_9amr_utils_OctreeGridList(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_2yt_9amr_utils_OctreeGridList *p = (struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)o; - if (p->grids) { - e = (*v)(p->grids, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_2yt_9amr_utils_OctreeGridList(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_OctreeGridList *p = (struct __pyx_obj_2yt_9amr_utils_OctreeGridList *)o; - PyObject* tmp; - tmp = ((PyObject*)p->grids); - p->grids = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} -static PyObject *__pyx_sq_item_2yt_9amr_utils_OctreeGridList(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_14OctreeGridList_grids(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_14OctreeGridList_grids(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_14OctreeGridList_5grids___del__(o); - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_OctreeGridList[] = { - {__Pyx_NAMESTR("__getitem__"), (PyCFunction)__pyx_pf_2yt_9amr_utils_14OctreeGridList___getitem__, METH_O|METH_COEXIST, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_OctreeGridList[] = { - {(char *)"grids", __pyx_getprop_2yt_9amr_utils_14OctreeGridList_grids, __pyx_setprop_2yt_9amr_utils_14OctreeGridList_grids, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_OctreeGridList = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_OctreeGridList = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_2yt_9amr_utils_OctreeGridList, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_OctreeGridList = { - 0, /*mp_length*/ - __pyx_pf_2yt_9amr_utils_14OctreeGridList___getitem__, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_OctreeGridList = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_OctreeGridList = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.OctreeGridList"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_OctreeGridList), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_OctreeGridList, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_OctreeGridList, /*tp_as_number*/ - &__pyx_tp_as_sequence_OctreeGridList, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_OctreeGridList, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_OctreeGridList, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_2yt_9amr_utils_OctreeGridList, /*tp_traverse*/ - __pyx_tp_clear_2yt_9amr_utils_OctreeGridList, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_OctreeGridList, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_OctreeGridList, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_OctreeGridList, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_VectorPlane __pyx_vtable_2yt_9amr_utils_VectorPlane; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_VectorPlane(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_VectorPlane *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_VectorPlane *)o); - p->__pyx_vtab = __pyx_vtabptr_2yt_9amr_utils_VectorPlane; - p->avp_pos = Py_None; Py_INCREF(Py_None); - p->avp_dir = Py_None; Py_INCREF(Py_None); - p->acenter = Py_None; Py_INCREF(Py_None); - p->aimage = Py_None; Py_INCREF(Py_None); - p->ax_vec = Py_None; Py_INCREF(Py_None); - p->ay_vec = Py_None; Py_INCREF(Py_None); - if (__pyx_pf_2yt_9amr_utils_11VectorPlane___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_VectorPlane(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_VectorPlane *p = (struct __pyx_obj_2yt_9amr_utils_VectorPlane *)o; - Py_XDECREF(p->avp_pos); - Py_XDECREF(p->avp_dir); - Py_XDECREF(p->acenter); - Py_XDECREF(p->aimage); - Py_XDECREF(p->ax_vec); - Py_XDECREF(p->ay_vec); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_2yt_9amr_utils_VectorPlane(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_2yt_9amr_utils_VectorPlane *p = (struct __pyx_obj_2yt_9amr_utils_VectorPlane *)o; - if (p->avp_pos) { - e = (*v)(p->avp_pos, a); if (e) return e; - } - if (p->avp_dir) { - e = (*v)(p->avp_dir, a); if (e) return e; - } - if (p->acenter) { - e = (*v)(p->acenter, a); if (e) return e; - } - if (p->aimage) { - e = (*v)(p->aimage, a); if (e) return e; - } - if (p->ax_vec) { - e = (*v)(p->ax_vec, a); if (e) return e; - } - if (p->ay_vec) { - e = (*v)(p->ay_vec, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_2yt_9amr_utils_VectorPlane(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_VectorPlane *p = (struct __pyx_obj_2yt_9amr_utils_VectorPlane *)o; - PyObject* tmp; - tmp = ((PyObject*)p->avp_pos); - p->avp_pos = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->avp_dir); - p->avp_dir = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->acenter); - p->acenter = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->aimage); - p->aimage = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->ax_vec); - p->ax_vec = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->ay_vec); - p->ay_vec = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_11VectorPlane_avp_pos(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_11VectorPlane_avp_pos(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_pos___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_11VectorPlane_avp_dir(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_11VectorPlane_avp_dir(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7avp_dir___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_11VectorPlane_acenter(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_11VectorPlane_acenter(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_7acenter___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_11VectorPlane_aimage(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_11VectorPlane_aimage(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6aimage___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_11VectorPlane_ax_vec(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_11VectorPlane_ax_vec(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6ax_vec___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_11VectorPlane_ay_vec(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_11VectorPlane_ay_vec(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_11VectorPlane_6ay_vec___del__(o); - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_VectorPlane[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_VectorPlane[] = { - {(char *)"avp_pos", __pyx_getprop_2yt_9amr_utils_11VectorPlane_avp_pos, __pyx_setprop_2yt_9amr_utils_11VectorPlane_avp_pos, 0, 0}, - {(char *)"avp_dir", __pyx_getprop_2yt_9amr_utils_11VectorPlane_avp_dir, __pyx_setprop_2yt_9amr_utils_11VectorPlane_avp_dir, 0, 0}, - {(char *)"acenter", __pyx_getprop_2yt_9amr_utils_11VectorPlane_acenter, __pyx_setprop_2yt_9amr_utils_11VectorPlane_acenter, 0, 0}, - {(char *)"aimage", __pyx_getprop_2yt_9amr_utils_11VectorPlane_aimage, __pyx_setprop_2yt_9amr_utils_11VectorPlane_aimage, 0, 0}, - {(char *)"ax_vec", __pyx_getprop_2yt_9amr_utils_11VectorPlane_ax_vec, __pyx_setprop_2yt_9amr_utils_11VectorPlane_ax_vec, 0, 0}, - {(char *)"ay_vec", __pyx_getprop_2yt_9amr_utils_11VectorPlane_ay_vec, __pyx_setprop_2yt_9amr_utils_11VectorPlane_ay_vec, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_VectorPlane = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_VectorPlane = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_VectorPlane = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_VectorPlane = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_VectorPlane = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.VectorPlane"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_VectorPlane), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_VectorPlane, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_VectorPlane, /*tp_as_number*/ - &__pyx_tp_as_sequence_VectorPlane, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_VectorPlane, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_VectorPlane, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_2yt_9amr_utils_VectorPlane, /*tp_traverse*/ - __pyx_tp_clear_2yt_9amr_utils_VectorPlane, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_VectorPlane, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_VectorPlane, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_VectorPlane, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_TransferFunctionProxy __pyx_vtable_2yt_9amr_utils_TransferFunctionProxy; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_TransferFunctionProxy(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)o); - p->__pyx_vtab = __pyx_vtabptr_2yt_9amr_utils_TransferFunctionProxy; - p->tf_obj = Py_None; Py_INCREF(Py_None); - p->my_field_tables = Py_None; Py_INCREF(Py_None); - if (__pyx_pf_2yt_9amr_utils_21TransferFunctionProxy___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_TransferFunctionProxy(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *p = (struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)o; - Py_XDECREF(p->tf_obj); - Py_XDECREF(p->my_field_tables); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_2yt_9amr_utils_TransferFunctionProxy(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *p = (struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)o; - if (p->tf_obj) { - e = (*v)(p->tf_obj, a); if (e) return e; - } - if (p->my_field_tables) { - e = (*v)(p->my_field_tables, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_2yt_9amr_utils_TransferFunctionProxy(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *p = (struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *)o; - PyObject* tmp; - tmp = ((PyObject*)p->tf_obj); - p->tf_obj = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->my_field_tables); - p->my_field_tables = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_21TransferFunctionProxy_ns(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_2ns___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_21TransferFunctionProxy_ns(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_2ns___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_21TransferFunctionProxy_tf_obj(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_21TransferFunctionProxy_tf_obj(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_6tf_obj___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_21TransferFunctionProxy_my_field_tables(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_21TransferFunctionProxy_my_field_tables(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_21TransferFunctionProxy_15my_field_tables___del__(o); - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_TransferFunctionProxy[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_TransferFunctionProxy[] = { - {(char *)"ns", __pyx_getprop_2yt_9amr_utils_21TransferFunctionProxy_ns, __pyx_setprop_2yt_9amr_utils_21TransferFunctionProxy_ns, 0, 0}, - {(char *)"tf_obj", __pyx_getprop_2yt_9amr_utils_21TransferFunctionProxy_tf_obj, __pyx_setprop_2yt_9amr_utils_21TransferFunctionProxy_tf_obj, 0, 0}, - {(char *)"my_field_tables", __pyx_getprop_2yt_9amr_utils_21TransferFunctionProxy_my_field_tables, __pyx_setprop_2yt_9amr_utils_21TransferFunctionProxy_my_field_tables, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_TransferFunctionProxy = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_TransferFunctionProxy = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_TransferFunctionProxy = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_TransferFunctionProxy = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_TransferFunctionProxy = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.TransferFunctionProxy"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_TransferFunctionProxy, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_TransferFunctionProxy, /*tp_as_number*/ - &__pyx_tp_as_sequence_TransferFunctionProxy, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_TransferFunctionProxy, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_TransferFunctionProxy, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_2yt_9amr_utils_TransferFunctionProxy, /*tp_traverse*/ - __pyx_tp_clear_2yt_9amr_utils_TransferFunctionProxy, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_TransferFunctionProxy, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_TransferFunctionProxy, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_TransferFunctionProxy, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_PartitionedGrid __pyx_vtable_2yt_9amr_utils_PartitionedGrid; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_PartitionedGrid(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)o); - p->__pyx_vtab = __pyx_vtabptr_2yt_9amr_utils_PartitionedGrid; - p->my_data = Py_None; Py_INCREF(Py_None); - p->LeftEdge = Py_None; Py_INCREF(Py_None); - p->RightEdge = Py_None; Py_INCREF(Py_None); - if (__pyx_pf_2yt_9amr_utils_15PartitionedGrid___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_PartitionedGrid(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *p = (struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)o; - Py_XDECREF(p->my_data); - Py_XDECREF(p->LeftEdge); - Py_XDECREF(p->RightEdge); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_2yt_9amr_utils_PartitionedGrid(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *p = (struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)o; - if (p->my_data) { - e = (*v)(p->my_data, a); if (e) return e; - } - if (p->LeftEdge) { - e = (*v)(p->LeftEdge, a); if (e) return e; - } - if (p->RightEdge) { - e = (*v)(p->RightEdge, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_2yt_9amr_utils_PartitionedGrid(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *p = (struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *)o; - PyObject* tmp; - tmp = ((PyObject*)p->my_data); - p->my_data = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->LeftEdge); - p->LeftEdge = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->RightEdge); - p->RightEdge = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_15PartitionedGrid_my_data(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_my_data(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_7my_data___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_15PartitionedGrid_LeftEdge(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_LeftEdge(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8LeftEdge___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_15PartitionedGrid_RightEdge(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_RightEdge(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_9RightEdge___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_15PartitionedGrid_parent_grid_id(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_14parent_grid_id___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_parent_grid_id(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_14parent_grid_id___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_15PartitionedGrid_n_fields(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8n_fields___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_n_fields(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_15PartitionedGrid_8n_fields___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_PartitionedGrid[] = { - {__Pyx_NAMESTR("cast_plane"), (PyCFunction)__pyx_pf_2yt_9amr_utils_15PartitionedGrid_cast_plane, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_PartitionedGrid[] = { - {(char *)"my_data", __pyx_getprop_2yt_9amr_utils_15PartitionedGrid_my_data, __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_my_data, 0, 0}, - {(char *)"LeftEdge", __pyx_getprop_2yt_9amr_utils_15PartitionedGrid_LeftEdge, __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_LeftEdge, 0, 0}, - {(char *)"RightEdge", __pyx_getprop_2yt_9amr_utils_15PartitionedGrid_RightEdge, __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_RightEdge, 0, 0}, - {(char *)"parent_grid_id", __pyx_getprop_2yt_9amr_utils_15PartitionedGrid_parent_grid_id, __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_parent_grid_id, 0, 0}, - {(char *)"n_fields", __pyx_getprop_2yt_9amr_utils_15PartitionedGrid_n_fields, __pyx_setprop_2yt_9amr_utils_15PartitionedGrid_n_fields, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_PartitionedGrid = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_PartitionedGrid = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_PartitionedGrid = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_PartitionedGrid = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_PartitionedGrid = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.PartitionedGrid"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_PartitionedGrid, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_PartitionedGrid, /*tp_as_number*/ - &__pyx_tp_as_sequence_PartitionedGrid, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_PartitionedGrid, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_PartitionedGrid, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_2yt_9amr_utils_PartitionedGrid, /*tp_traverse*/ - __pyx_tp_clear_2yt_9amr_utils_PartitionedGrid, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_PartitionedGrid, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_PartitionedGrid, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_PartitionedGrid, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_GridFace __pyx_vtable_2yt_9amr_utils_GridFace; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_GridFace(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_GridFace *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_GridFace *)o); - p->__pyx_vtab = __pyx_vtabptr_2yt_9amr_utils_GridFace; - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_GridFace(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_8GridFace_coord(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_8GridFace_5coord___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_8GridFace_coord(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_8GridFace_5coord___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_GridFace[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_GridFace[] = { - {(char *)"coord", __pyx_getprop_2yt_9amr_utils_8GridFace_coord, __pyx_setprop_2yt_9amr_utils_8GridFace_coord, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_GridFace = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_GridFace = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_GridFace = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_GridFace = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_GridFace = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.GridFace"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_GridFace), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_GridFace, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_GridFace, /*tp_as_number*/ - &__pyx_tp_as_sequence_GridFace, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_GridFace, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_GridFace, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_GridFace, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_GridFace, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_pf_2yt_9amr_utils_8GridFace___init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_GridFace, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_ProtoPrism __pyx_vtable_2yt_9amr_utils_ProtoPrism; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_ProtoPrism(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_ProtoPrism *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)o); - p->__pyx_vtab = __pyx_vtabptr_2yt_9amr_utils_ProtoPrism; - p->LeftEdge = Py_None; Py_INCREF(Py_None); - p->RightEdge = Py_None; Py_INCREF(Py_None); - p->subgrid_faces = Py_None; Py_INCREF(Py_None); - if (__pyx_pf_2yt_9amr_utils_10ProtoPrism___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_ProtoPrism(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_ProtoPrism *p = (struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)o; - Py_XDECREF(p->LeftEdge); - Py_XDECREF(p->RightEdge); - Py_XDECREF(p->subgrid_faces); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_2yt_9amr_utils_ProtoPrism(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_2yt_9amr_utils_ProtoPrism *p = (struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)o; - if (p->LeftEdge) { - e = (*v)(p->LeftEdge, a); if (e) return e; - } - if (p->RightEdge) { - e = (*v)(p->RightEdge, a); if (e) return e; - } - if (p->subgrid_faces) { - e = (*v)(p->subgrid_faces, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_2yt_9amr_utils_ProtoPrism(PyObject *o) { - struct __pyx_obj_2yt_9amr_utils_ProtoPrism *p = (struct __pyx_obj_2yt_9amr_utils_ProtoPrism *)o; - PyObject* tmp; - tmp = ((PyObject*)p->LeftEdge); - p->LeftEdge = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->RightEdge); - p->RightEdge = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->subgrid_faces); - p->subgrid_faces = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10ProtoPrism_LeftEdge(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10ProtoPrism_LeftEdge(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_8LeftEdge___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10ProtoPrism_RightEdge(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10ProtoPrism_RightEdge(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_9RightEdge___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10ProtoPrism_subgrid_faces(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10ProtoPrism_subgrid_faces(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___set__(o, v); - } - else { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_13subgrid_faces___del__(o); - } -} - -static PyObject *__pyx_getprop_2yt_9amr_utils_10ProtoPrism_parent_grid_id(PyObject *o, void *x) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_14parent_grid_id___get__(o); -} - -static int __pyx_setprop_2yt_9amr_utils_10ProtoPrism_parent_grid_id(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pf_2yt_9amr_utils_10ProtoPrism_14parent_grid_id___set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_ProtoPrism[] = { - {__Pyx_NAMESTR("sweep"), (PyCFunction)__pyx_pf_2yt_9amr_utils_10ProtoPrism_sweep, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_brick"), (PyCFunction)__pyx_pf_2yt_9amr_utils_10ProtoPrism_get_brick, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_2yt_9amr_utils_ProtoPrism[] = { - {(char *)"LeftEdge", __pyx_getprop_2yt_9amr_utils_10ProtoPrism_LeftEdge, __pyx_setprop_2yt_9amr_utils_10ProtoPrism_LeftEdge, 0, 0}, - {(char *)"RightEdge", __pyx_getprop_2yt_9amr_utils_10ProtoPrism_RightEdge, __pyx_setprop_2yt_9amr_utils_10ProtoPrism_RightEdge, 0, 0}, - {(char *)"subgrid_faces", __pyx_getprop_2yt_9amr_utils_10ProtoPrism_subgrid_faces, __pyx_setprop_2yt_9amr_utils_10ProtoPrism_subgrid_faces, 0, 0}, - {(char *)"parent_grid_id", __pyx_getprop_2yt_9amr_utils_10ProtoPrism_parent_grid_id, __pyx_setprop_2yt_9amr_utils_10ProtoPrism_parent_grid_id, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_ProtoPrism = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_ProtoPrism = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_ProtoPrism = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_ProtoPrism = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_ProtoPrism = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.ProtoPrism"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_ProtoPrism), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_ProtoPrism, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_ProtoPrism, /*tp_as_number*/ - &__pyx_tp_as_sequence_ProtoPrism, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_ProtoPrism, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_ProtoPrism, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_2yt_9amr_utils_ProtoPrism, /*tp_traverse*/ - __pyx_tp_clear_2yt_9amr_utils_ProtoPrism, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_ProtoPrism, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_2yt_9amr_utils_ProtoPrism, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_ProtoPrism, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; -static struct __pyx_vtabstruct_2yt_9amr_utils_QuadTree __pyx_vtable_2yt_9amr_utils_QuadTree; - -static PyObject *__pyx_tp_new_2yt_9amr_utils_QuadTree(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_2yt_9amr_utils_QuadTree *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_2yt_9amr_utils_QuadTree *)o); - p->__pyx_vtab = __pyx_vtabptr_2yt_9amr_utils_QuadTree; - if (__pyx_pf_2yt_9amr_utils_8QuadTree___cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_2yt_9amr_utils_QuadTree(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pf_2yt_9amr_utils_8QuadTree___dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_2yt_9amr_utils_QuadTree[] = { - {__Pyx_NAMESTR("add_array_to_tree"), (PyCFunction)__pyx_pf_2yt_9amr_utils_8QuadTree_add_array_to_tree, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("add_grid_to_tree"), (PyCFunction)__pyx_pf_2yt_9amr_utils_8QuadTree_add_grid_to_tree, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_all_from_level"), (PyCFunction)__pyx_pf_2yt_9amr_utils_8QuadTree_get_all_from_level, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_QuadTree = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_QuadTree = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_QuadTree = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_QuadTree = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_2yt_9amr_utils_QuadTree = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("yt.amr_utils.QuadTree"), /*tp_name*/ - sizeof(struct __pyx_obj_2yt_9amr_utils_QuadTree), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_2yt_9amr_utils_QuadTree, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*tp_compare*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_QuadTree, /*tp_as_number*/ - &__pyx_tp_as_sequence_QuadTree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_QuadTree, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_QuadTree, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_2yt_9amr_utils_QuadTree, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_2yt_9amr_utils_QuadTree, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyMethodDef __pyx_methods[] = { - {__Pyx_NAMESTR("RecurseOctreeDepthFirst"), (PyCFunction)__pyx_pf_2yt_9amr_utils_RecurseOctreeDepthFirst, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("RecurseOctreeByLevels"), (PyCFunction)__pyx_pf_2yt_9amr_utils_RecurseOctreeByLevels, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("UnilinearlyInterpolate"), (PyCFunction)__pyx_pf_2yt_9amr_utils_UnilinearlyInterpolate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("BilinearlyInterpolate"), (PyCFunction)__pyx_pf_2yt_9amr_utils_BilinearlyInterpolate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("TrilinearlyInterpolate"), (PyCFunction)__pyx_pf_2yt_9amr_utils_TrilinearlyInterpolate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("planar_points_in_volume"), (PyCFunction)__pyx_pf_2yt_9amr_utils_planar_points_in_volume, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("grid_points_in_volume"), (PyCFunction)__pyx_pf_2yt_9amr_utils_grid_points_in_volume, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("find_grids_in_inclined_box"), (PyCFunction)__pyx_pf_2yt_9amr_utils_find_grids_in_inclined_box, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("Transfer3D"), (PyCFunction)__pyx_pf_2yt_9amr_utils_Transfer3D, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_2yt_9amr_utils_Transfer3D)}, - {__Pyx_NAMESTR("TransferShells"), (PyCFunction)__pyx_pf_2yt_9amr_utils_TransferShells, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_2yt_9amr_utils_TransferShells)}, - {__Pyx_NAMESTR("Transfer1D"), (PyCFunction)__pyx_pf_2yt_9amr_utils_Transfer1D, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("VoxelTraversal"), (PyCFunction)__pyx_pf_2yt_9amr_utils_VoxelTraversal, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("PlaneVoxelIntegration"), (PyCFunction)__pyx_pf_2yt_9amr_utils_PlaneVoxelIntegration, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("integrate_ray"), (PyCFunction)__pyx_pf_2yt_9amr_utils_integrate_ray, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("CICDeposit_3"), (PyCFunction)__pyx_pf_2yt_9amr_utils_CICDeposit_3, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("construct_boundary_relationships"), (PyCFunction)__pyx_pf_2yt_9amr_utils_construct_boundary_relationships, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("identify_field_neighbors"), (PyCFunction)__pyx_pf_2yt_9amr_utils_identify_field_neighbors, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("extract_identified_contours"), (PyCFunction)__pyx_pf_2yt_9amr_utils_extract_identified_contours, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_png"), (PyCFunction)__pyx_pf_2yt_9amr_utils_write_png, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("add_points_to_image"), (PyCFunction)__pyx_pf_2yt_9amr_utils_add_points_to_image, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_tiger_section"), (PyCFunction)__pyx_pf_2yt_9amr_utils_read_tiger_section, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("amr_utils"), - __Pyx_DOCSTR(__pyx_k_13), /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_n_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 1}, - {&__pyx_kp_u_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 1, 0, 0}, - {&__pyx_kp_u_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 1, 0, 0}, - {&__pyx_kp_u_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 1, 0, 0}, - {&__pyx_kp_u_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 1, 0, 0}, - {&__pyx_kp_u_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 1, 0, 0}, - {&__pyx_n_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 1}, - {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, - {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, - {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, - {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, - {&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0}, - {&__pyx_kp_u_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 1, 0, 0}, - {&__pyx_kp_u_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 1, 0, 0}, - {&__pyx_n_s__Channel, __pyx_k__Channel, sizeof(__pyx_k__Channel), 0, 0, 1, 1}, - {&__pyx_n_s__F, __pyx_k__F, sizeof(__pyx_k__F), 0, 0, 1, 1}, - {&__pyx_n_s__LeftEdge, __pyx_k__LeftEdge, sizeof(__pyx_k__LeftEdge), 0, 0, 1, 1}, - {&__pyx_n_s__RightEdge, __pyx_k__RightEdge, sizeof(__pyx_k__RightEdge), 0, 0, 1, 1}, - {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1}, - {&__pyx_n_s__Transfer3D, __pyx_k__Transfer3D, sizeof(__pyx_k__Transfer3D), 0, 0, 1, 1}, - {&__pyx_n_s__TransferShells, __pyx_k__TransferShells, sizeof(__pyx_k__TransferShells), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1}, - {&__pyx_n_s__acenter, __pyx_k__acenter, sizeof(__pyx_k__acenter), 0, 0, 1, 1}, - {&__pyx_n_s__add_to_position, __pyx_k__add_to_position, sizeof(__pyx_k__add_to_position), 0, 0, 1, 1}, - {&__pyx_n_s__aimage, __pyx_k__aimage, sizeof(__pyx_k__aimage), 0, 0, 1, 1}, - {&__pyx_n_s__alpha, __pyx_k__alpha, sizeof(__pyx_k__alpha), 0, 0, 1, 1}, - {&__pyx_n_s__avp_dir, __pyx_k__avp_dir, sizeof(__pyx_k__avp_dir), 0, 0, 1, 1}, - {&__pyx_n_s__avp_pos, __pyx_k__avp_pos, sizeof(__pyx_k__avp_pos), 0, 0, 1, 1}, - {&__pyx_n_s__ax_vec, __pyx_k__ax_vec, sizeof(__pyx_k__ax_vec), 0, 0, 1, 1}, - {&__pyx_n_s__ay_vec, __pyx_k__ay_vec, sizeof(__pyx_k__ay_vec), 0, 0, 1, 1}, - {&__pyx_n_s__base, __pyx_k__base, sizeof(__pyx_k__base), 0, 0, 1, 1}, - {&__pyx_n_s__blue, __pyx_k__blue, sizeof(__pyx_k__blue), 0, 0, 1, 1}, - {&__pyx_n_s__bounds, __pyx_k__bounds, sizeof(__pyx_k__bounds), 0, 0, 1, 1}, - {&__pyx_n_s__box_center, __pyx_k__box_center, sizeof(__pyx_k__box_center), 0, 0, 1, 1}, - {&__pyx_n_s__box_lengths, __pyx_k__box_lengths, sizeof(__pyx_k__box_lengths), 0, 0, 1, 1}, - {&__pyx_n_s__box_origin, __pyx_k__box_origin, sizeof(__pyx_k__box_origin), 0, 0, 1, 1}, - {&__pyx_n_s__box_vectors, __pyx_k__box_vectors, sizeof(__pyx_k__box_vectors), 0, 0, 1, 1}, - {&__pyx_n_s__break_first, __pyx_k__break_first, sizeof(__pyx_k__break_first), 0, 0, 1, 1}, - {&__pyx_n_s__buf, __pyx_k__buf, sizeof(__pyx_k__buf), 0, 0, 1, 1}, - {&__pyx_n_s__buffer, __pyx_k__buffer, sizeof(__pyx_k__buffer), 0, 0, 1, 1}, - {&__pyx_n_s__byteorder, __pyx_k__byteorder, sizeof(__pyx_k__byteorder), 0, 0, 1, 1}, - {&__pyx_n_s__calculate_extent, __pyx_k__calculate_extent, sizeof(__pyx_k__calculate_extent), 0, 0, 1, 1}, - {&__pyx_n_s__cellSize, __pyx_k__cellSize, sizeof(__pyx_k__cellSize), 0, 0, 1, 1}, - {&__pyx_n_s__center, __pyx_k__center, sizeof(__pyx_k__center), 0, 0, 1, 1}, - {&__pyx_n_s__child_indices, __pyx_k__child_indices, sizeof(__pyx_k__child_indices), 0, 0, 1, 1}, - {&__pyx_n_s__child_mask, __pyx_k__child_mask, sizeof(__pyx_k__child_mask), 0, 0, 1, 1}, - {&__pyx_n_s__children, __pyx_k__children, sizeof(__pyx_k__children), 0, 0, 1, 1}, - {&__pyx_n_s__cm, __pyx_k__cm, sizeof(__pyx_k__cm), 0, 0, 1, 1}, - {&__pyx_n_s__coord, __pyx_k__coord, sizeof(__pyx_k__coord), 0, 0, 1, 1}, - {&__pyx_n_s__copy, __pyx_k__copy, sizeof(__pyx_k__copy), 0, 0, 1, 1}, - {&__pyx_n_s__copy_back, __pyx_k__copy_back, sizeof(__pyx_k__copy_back), 0, 0, 1, 1}, - {&__pyx_n_s__copy_into, __pyx_k__copy_into, sizeof(__pyx_k__copy_into), 0, 0, 1, 1}, - {&__pyx_n_s__corners, __pyx_k__corners, sizeof(__pyx_k__corners), 0, 0, 1, 1}, - {&__pyx_n_s__count_at_level, __pyx_k__count_at_level, sizeof(__pyx_k__count_at_level), 0, 0, 1, 1}, - {&__pyx_n_s__count_only, __pyx_k__count_only, sizeof(__pyx_k__count_only), 0, 0, 1, 1}, - {&__pyx_n_s__curpos, __pyx_k__curpos, sizeof(__pyx_k__curpos), 0, 0, 1, 1}, - {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1}, - {&__pyx_n_s__dbin, __pyx_k__dbin, sizeof(__pyx_k__dbin), 0, 0, 1, 1}, - {&__pyx_n_s__dds, __pyx_k__dds, sizeof(__pyx_k__dds), 0, 0, 1, 1}, - {&__pyx_n_s__descr, __pyx_k__descr, sizeof(__pyx_k__descr), 0, 0, 1, 1}, - {&__pyx_n_s__dimensions, __pyx_k__dimensions, sizeof(__pyx_k__dimensions), 0, 0, 1, 1}, - {&__pyx_n_s__dims, __pyx_k__dims, sizeof(__pyx_k__dims), 0, 0, 1, 1}, - {&__pyx_n_s__direction, __pyx_k__direction, sizeof(__pyx_k__direction), 0, 0, 1, 1}, - {&__pyx_n_s__dpi, __pyx_k__dpi, sizeof(__pyx_k__dpi), 0, 0, 1, 1}, - {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1}, - {&__pyx_n_s__dvs, __pyx_k__dvs, sizeof(__pyx_k__dvs), 0, 0, 1, 1}, - {&__pyx_n_s__dx, __pyx_k__dx, sizeof(__pyx_k__dx), 0, 0, 1, 1}, - {&__pyx_n_s__dy, __pyx_k__dy, sizeof(__pyx_k__dy), 0, 0, 1, 1}, - {&__pyx_n_s__dz, __pyx_k__dz, sizeof(__pyx_k__dz), 0, 0, 1, 1}, - {&__pyx_n_s__e, __pyx_k__e, sizeof(__pyx_k__e), 0, 0, 1, 1}, - {&__pyx_n_s__empty, __pyx_k__empty, sizeof(__pyx_k__empty), 0, 0, 1, 1}, - {&__pyx_n_s__eval_transfer, __pyx_k__eval_transfer, sizeof(__pyx_k__eval_transfer), 0, 0, 1, 1}, - {&__pyx_n_s__field, __pyx_k__field, sizeof(__pyx_k__field), 0, 0, 1, 1}, - {&__pyx_n_s__field_id, __pyx_k__field_id, sizeof(__pyx_k__field_id), 0, 0, 1, 1}, - {&__pyx_n_s__field_ids, __pyx_k__field_ids, sizeof(__pyx_k__field_ids), 0, 0, 1, 1}, - {&__pyx_n_s__field_table_ids, __pyx_k__field_table_ids, sizeof(__pyx_k__field_table_ids), 0, 0, 1, 1}, - {&__pyx_n_s__field_tables, __pyx_k__field_tables, sizeof(__pyx_k__field_tables), 0, 0, 1, 1}, - {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1}, - {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1}, - {&__pyx_n_s__fill_from_level, __pyx_k__fill_from_level, sizeof(__pyx_k__fill_from_level), 0, 0, 1, 1}, - {&__pyx_n_s__find_on_root_level, __pyx_k__find_on_root_level, sizeof(__pyx_k__find_on_root_level), 0, 0, 1, 1}, - {&__pyx_n_s__float32, __pyx_k__float32, sizeof(__pyx_k__float32), 0, 0, 1, 1}, - {&__pyx_n_s__float64, __pyx_k__float64, sizeof(__pyx_k__float64), 0, 0, 1, 1}, - {&__pyx_n_s__floor, __pyx_k__floor, sizeof(__pyx_k__floor), 0, 0, 1, 1}, - {&__pyx_n_s__fn, __pyx_k__fn, sizeof(__pyx_k__fn), 0, 0, 1, 1}, - {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1}, - {&__pyx_n_s__genealogy, __pyx_k__genealogy, sizeof(__pyx_k__genealogy), 0, 0, 1, 1}, - {&__pyx_n_s__get_start_stop, __pyx_k__get_start_stop, sizeof(__pyx_k__get_start_stop), 0, 0, 1, 1}, - {&__pyx_n_s__gi, __pyx_k__gi, sizeof(__pyx_k__gi), 0, 0, 1, 1}, - {&__pyx_n_s__gray, __pyx_k__gray, sizeof(__pyx_k__gray), 0, 0, 1, 1}, - {&__pyx_n_s__green, __pyx_k__green, sizeof(__pyx_k__green), 0, 0, 1, 1}, - {&__pyx_n_s__grid, __pyx_k__grid, sizeof(__pyx_k__grid), 0, 0, 1, 1}, - {&__pyx_n_s__gridDimension, __pyx_k__gridDimension, sizeof(__pyx_k__gridDimension), 0, 0, 1, 1}, - {&__pyx_n_s__grid_dds, __pyx_k__grid_dds, sizeof(__pyx_k__grid_dds), 0, 0, 1, 1}, - {&__pyx_n_s__grid_dt, __pyx_k__grid_dt, sizeof(__pyx_k__grid_dt), 0, 0, 1, 1}, - {&__pyx_n_s__grid_left_edge, __pyx_k__grid_left_edge, sizeof(__pyx_k__grid_left_edge), 0, 0, 1, 1}, - {&__pyx_n_s__grid_left_edges, __pyx_k__grid_left_edges, sizeof(__pyx_k__grid_left_edges), 0, 0, 1, 1}, - {&__pyx_n_s__grid_mask, __pyx_k__grid_mask, sizeof(__pyx_k__grid_mask), 0, 0, 1, 1}, - {&__pyx_n_s__grid_right_edge, __pyx_k__grid_right_edge, sizeof(__pyx_k__grid_right_edge), 0, 0, 1, 1}, - {&__pyx_n_s__grid_right_edges, __pyx_k__grid_right_edges, sizeof(__pyx_k__grid_right_edges), 0, 0, 1, 1}, - {&__pyx_n_s__grid_t, __pyx_k__grid_t, sizeof(__pyx_k__grid_t), 0, 0, 1, 1}, - {&__pyx_n_s__grids, __pyx_k__grids, sizeof(__pyx_k__grids), 0, 0, 1, 1}, - {&__pyx_n_s__i_f, __pyx_k__i_f, sizeof(__pyx_k__i_f), 0, 0, 1, 1}, - {&__pyx_n_s__i_i, __pyx_k__i_i, sizeof(__pyx_k__i_i), 0, 0, 1, 1}, - {&__pyx_n_s__i_s, __pyx_k__i_s, sizeof(__pyx_k__i_s), 0, 0, 1, 1}, - {&__pyx_n_s__idbin, __pyx_k__idbin, sizeof(__pyx_k__idbin), 0, 0, 1, 1}, - {&__pyx_n_s__idds, __pyx_k__idds, sizeof(__pyx_k__idds), 0, 0, 1, 1}, - {&__pyx_n_s__im_strides, __pyx_k__im_strides, sizeof(__pyx_k__im_strides), 0, 0, 1, 1}, - {&__pyx_n_s__image, __pyx_k__image, sizeof(__pyx_k__image), 0, 0, 1, 1}, - {&__pyx_n_s__imax, __pyx_k__imax, sizeof(__pyx_k__imax), 0, 0, 1, 1}, - {&__pyx_n_s__imin, __pyx_k__imin, sizeof(__pyx_k__imin), 0, 0, 1, 1}, - {&__pyx_n_s__ind, __pyx_k__ind, sizeof(__pyx_k__ind), 0, 0, 1, 1}, - {&__pyx_n_s__int32, __pyx_k__int32, sizeof(__pyx_k__int32), 0, 0, 1, 1}, - {&__pyx_n_s__int64, __pyx_k__int64, sizeof(__pyx_k__int64), 0, 0, 1, 1}, - {&__pyx_n_s__int8, __pyx_k__int8, sizeof(__pyx_k__int8), 0, 0, 1, 1}, - {&__pyx_n_s__integrate_ray, __pyx_k__integrate_ray, sizeof(__pyx_k__integrate_ray), 0, 0, 1, 1}, - {&__pyx_n_s__istorage, __pyx_k__istorage, sizeof(__pyx_k__istorage), 0, 0, 1, 1}, - {&__pyx_n_s__istride, __pyx_k__istride, sizeof(__pyx_k__istride), 0, 0, 1, 1}, - {&__pyx_n_s__itemsize, __pyx_k__itemsize, sizeof(__pyx_k__itemsize), 0, 0, 1, 1}, - {&__pyx_n_s__j_f, __pyx_k__j_f, sizeof(__pyx_k__j_f), 0, 0, 1, 1}, - {&__pyx_n_s__j_i, __pyx_k__j_i, sizeof(__pyx_k__j_i), 0, 0, 1, 1}, - {&__pyx_n_s__jmax, __pyx_k__jmax, sizeof(__pyx_k__jmax), 0, 0, 1, 1}, - {&__pyx_n_s__jmin, __pyx_k__jmin, sizeof(__pyx_k__jmin), 0, 0, 1, 1}, - {&__pyx_n_s__joins, __pyx_k__joins, sizeof(__pyx_k__joins), 0, 0, 1, 1}, - {&__pyx_n_s__jstride, __pyx_k__jstride, sizeof(__pyx_k__jstride), 0, 0, 1, 1}, - {&__pyx_n_s__k_f, __pyx_k__k_f, sizeof(__pyx_k__k_f), 0, 0, 1, 1}, - {&__pyx_n_s__k_i, __pyx_k__k_i, sizeof(__pyx_k__k_i), 0, 0, 1, 1}, - {&__pyx_n_s__kmax, __pyx_k__kmax, sizeof(__pyx_k__kmax), 0, 0, 1, 1}, - {&__pyx_n_s__kmin, __pyx_k__kmin, sizeof(__pyx_k__kmin), 0, 0, 1, 1}, - {&__pyx_n_s__left, __pyx_k__left, sizeof(__pyx_k__left), 0, 0, 1, 1}, - {&__pyx_n_s__leftEdge, __pyx_k__leftEdge, sizeof(__pyx_k__leftEdge), 0, 0, 1, 1}, - {&__pyx_n_s__left_edge, __pyx_k__left_edge, sizeof(__pyx_k__left_edge), 0, 0, 1, 1}, - {&__pyx_n_s__left_edges, __pyx_k__left_edges, sizeof(__pyx_k__left_edges), 0, 0, 1, 1}, - {&__pyx_n_s__level, __pyx_k__level, sizeof(__pyx_k__level), 0, 0, 1, 1}, - {&__pyx_n_s__mask, __pyx_k__mask, sizeof(__pyx_k__mask), 0, 0, 1, 1}, - {&__pyx_n_s__mass, __pyx_k__mass, sizeof(__pyx_k__mass), 0, 0, 1, 1}, - {&__pyx_n_s__max_ind, __pyx_k__max_ind, sizeof(__pyx_k__max_ind), 0, 0, 1, 1}, - {&__pyx_n_s__my_data, __pyx_k__my_data, sizeof(__pyx_k__my_data), 0, 0, 1, 1}, - {&__pyx_n_s__my_field_tables, __pyx_k__my_field_tables, sizeof(__pyx_k__my_field_tables), 0, 0, 1, 1}, - {&__pyx_n_s__n_field_tables, __pyx_k__n_field_tables, sizeof(__pyx_k__n_field_tables), 0, 0, 1, 1}, - {&__pyx_n_s__n_fields, __pyx_k__n_fields, sizeof(__pyx_k__n_fields), 0, 0, 1, 1}, - {&__pyx_n_s__names, __pyx_k__names, sizeof(__pyx_k__names), 0, 0, 1, 1}, - {&__pyx_n_s__nbins, __pyx_k__nbins, sizeof(__pyx_k__nbins), 0, 0, 1, 1}, - {&__pyx_n_s__ndim, __pyx_k__ndim, sizeof(__pyx_k__ndim), 0, 0, 1, 1}, - {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1}, - {&__pyx_n_s__npositions, __pyx_k__npositions, sizeof(__pyx_k__npositions), 0, 0, 1, 1}, - {&__pyx_n_s__ns, __pyx_k__ns, sizeof(__pyx_k__ns), 0, 0, 1, 1}, - {&__pyx_n_s__nshells, __pyx_k__nshells, sizeof(__pyx_k__nshells), 0, 0, 1, 1}, - {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, - {&__pyx_n_s__nv, __pyx_k__nv, sizeof(__pyx_k__nv), 0, 0, 1, 1}, - {&__pyx_n_s__nvals, __pyx_k__nvals, sizeof(__pyx_k__nvals), 0, 0, 1, 1}, - {&__pyx_n_s__o_s, __pyx_k__o_s, sizeof(__pyx_k__o_s), 0, 0, 1, 1}, - {&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1}, - {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1}, - {&__pyx_n_s__order, __pyx_k__order, sizeof(__pyx_k__order), 0, 0, 1, 1}, - {&__pyx_n_s__output, __pyx_k__output, sizeof(__pyx_k__output), 0, 0, 1, 1}, - {&__pyx_n_s__output_pos, __pyx_k__output_pos, sizeof(__pyx_k__output_pos), 0, 0, 1, 1}, - {&__pyx_n_s__parent_grid_id, __pyx_k__parent_grid_id, sizeof(__pyx_k__parent_grid_id), 0, 0, 1, 1}, - {&__pyx_n_s__pass_through, __pyx_k__pass_through, sizeof(__pyx_k__pass_through), 0, 0, 1, 1}, - {&__pyx_n_s__pdx, __pyx_k__pdx, sizeof(__pyx_k__pdx), 0, 0, 1, 1}, - {&__pyx_n_s__pdy, __pyx_k__pdy, sizeof(__pyx_k__pdy), 0, 0, 1, 1}, - {&__pyx_n_s__pmask, __pyx_k__pmask, sizeof(__pyx_k__pmask), 0, 0, 1, 1}, - {&__pyx_n_s__po2, __pyx_k__po2, sizeof(__pyx_k__po2), 0, 0, 1, 1}, - {&__pyx_n_s__points, __pyx_k__points, sizeof(__pyx_k__points), 0, 0, 1, 1}, - {&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1}, - {&__pyx_n_s__posx, __pyx_k__posx, sizeof(__pyx_k__posx), 0, 0, 1, 1}, - {&__pyx_n_s__posy, __pyx_k__posy, sizeof(__pyx_k__posy), 0, 0, 1, 1}, - {&__pyx_n_s__posz, __pyx_k__posz, sizeof(__pyx_k__posz), 0, 0, 1, 1}, - {&__pyx_n_s__proj_overlap, __pyx_k__proj_overlap, sizeof(__pyx_k__proj_overlap), 0, 0, 1, 1}, - {&__pyx_n_s__pv, __pyx_k__pv, sizeof(__pyx_k__pv), 0, 0, 1, 1}, - {&__pyx_n_s__pvals, __pyx_k__pvals, sizeof(__pyx_k__pvals), 0, 0, 1, 1}, - {&__pyx_n_s__pweight_vals, __pyx_k__pweight_vals, sizeof(__pyx_k__pweight_vals), 0, 0, 1, 1}, - {&__pyx_n_s__px, __pyx_k__px, sizeof(__pyx_k__px), 0, 0, 1, 1}, - {&__pyx_n_s__pxs, __pyx_k__pxs, sizeof(__pyx_k__pxs), 0, 0, 1, 1}, - {&__pyx_n_s__py, __pyx_k__py, sizeof(__pyx_k__py), 0, 0, 1, 1}, - {&__pyx_n_s__pys, __pyx_k__pys, sizeof(__pyx_k__pys), 0, 0, 1, 1}, - {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, - {&__pyx_n_s__readonly, __pyx_k__readonly, sizeof(__pyx_k__readonly), 0, 0, 1, 1}, - {&__pyx_n_s__red, __pyx_k__red, sizeof(__pyx_k__red), 0, 0, 1, 1}, - {&__pyx_n_s__refined, __pyx_k__refined, sizeof(__pyx_k__refined), 0, 0, 1, 1}, - {&__pyx_n_s__refined_pos, __pyx_k__refined_pos, sizeof(__pyx_k__refined_pos), 0, 0, 1, 1}, - {&__pyx_n_s__right_edge, __pyx_k__right_edge, sizeof(__pyx_k__right_edge), 0, 0, 1, 1}, - {&__pyx_n_s__root_nodes, __pyx_k__root_nodes, sizeof(__pyx_k__root_nodes), 0, 0, 1, 1}, - {&__pyx_n_s__root_size, __pyx_k__root_size, sizeof(__pyx_k__root_size), 0, 0, 1, 1}, - {&__pyx_n_s__rot_mat, __pyx_k__rot_mat, sizeof(__pyx_k__rot_mat), 0, 0, 1, 1}, - {&__pyx_n_s__sample_values, __pyx_k__sample_values, sizeof(__pyx_k__sample_values), 0, 0, 1, 1}, - {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, - {&__pyx_n_s__shells, __pyx_k__shells, sizeof(__pyx_k__shells), 0, 0, 1, 1}, - {&__pyx_n_s__slab_size, __pyx_k__slab_size, sizeof(__pyx_k__slab_size), 0, 0, 1, 1}, - {&__pyx_n_s__slab_start, __pyx_k__slab_start, sizeof(__pyx_k__slab_start), 0, 0, 1, 1}, - {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, - {&__pyx_n_s__stack, __pyx_k__stack, sizeof(__pyx_k__stack), 0, 0, 1, 1}, - {&__pyx_n_s__start_index, __pyx_k__start_index, sizeof(__pyx_k__start_index), 0, 0, 1, 1}, - {&__pyx_n_s__strides, __pyx_k__strides, sizeof(__pyx_k__strides), 0, 0, 1, 1}, - {&__pyx_n_s__subgrid_faces, __pyx_k__subgrid_faces, sizeof(__pyx_k__subgrid_faces), 0, 0, 1, 1}, - {&__pyx_n_s__suboffsets, __pyx_k__suboffsets, sizeof(__pyx_k__suboffsets), 0, 0, 1, 1}, - {&__pyx_n_s__sweep, __pyx_k__sweep, sizeof(__pyx_k__sweep), 0, 0, 1, 1}, - {&__pyx_n_s__table, __pyx_k__table, sizeof(__pyx_k__table), 0, 0, 1, 1}, - {&__pyx_n_s__tables, __pyx_k__tables, sizeof(__pyx_k__tables), 0, 0, 1, 1}, - {&__pyx_n_s__tf, __pyx_k__tf, sizeof(__pyx_k__tf), 0, 0, 1, 1}, - {&__pyx_n_s__tf_obj, __pyx_k__tf_obj, sizeof(__pyx_k__tf_obj), 0, 0, 1, 1}, - {&__pyx_n_s__top_grid_dims, __pyx_k__top_grid_dims, sizeof(__pyx_k__top_grid_dims), 0, 0, 1, 1}, - {&__pyx_n_s__type_num, __pyx_k__type_num, sizeof(__pyx_k__type_num), 0, 0, 1, 1}, - {&__pyx_n_s__u, __pyx_k__u, sizeof(__pyx_k__u), 0, 0, 1, 1}, - {&__pyx_n_s__ug, __pyx_k__ug, sizeof(__pyx_k__ug), 0, 0, 1, 1}, - {&__pyx_n_s__v, __pyx_k__v, sizeof(__pyx_k__v), 0, 0, 1, 1}, - {&__pyx_n_s__val, __pyx_k__val, sizeof(__pyx_k__val), 0, 0, 1, 1}, - {&__pyx_n_s__values, __pyx_k__values, sizeof(__pyx_k__values), 0, 0, 1, 1}, - {&__pyx_n_s__vd_strides, __pyx_k__vd_strides, sizeof(__pyx_k__vd_strides), 0, 0, 1, 1}, - {&__pyx_n_s__vp, __pyx_k__vp, sizeof(__pyx_k__vp), 0, 0, 1, 1}, - {&__pyx_n_s__vp_dir, __pyx_k__vp_dir, sizeof(__pyx_k__vp_dir), 0, 0, 1, 1}, - {&__pyx_n_s__vp_pos, __pyx_k__vp_pos, sizeof(__pyx_k__vp_pos), 0, 0, 1, 1}, - {&__pyx_n_s__vp_strides, __pyx_k__vp_strides, sizeof(__pyx_k__vp_strides), 0, 0, 1, 1}, - {&__pyx_n_s__weight_field_id, __pyx_k__weight_field_id, sizeof(__pyx_k__weight_field_id), 0, 0, 1, 1}, - {&__pyx_n_s__weight_field_ids, __pyx_k__weight_field_ids, sizeof(__pyx_k__weight_field_ids), 0, 0, 1, 1}, - {&__pyx_n_s__weight_table_id, __pyx_k__weight_table_id, sizeof(__pyx_k__weight_table_id), 0, 0, 1, 1}, - {&__pyx_n_s__weight_table_ids, __pyx_k__weight_table_ids, sizeof(__pyx_k__weight_table_ids), 0, 0, 1, 1}, - {&__pyx_n_s__weight_val, __pyx_k__weight_val, sizeof(__pyx_k__weight_val), 0, 0, 1, 1}, - {&__pyx_n_s__wvals, __pyx_k__wvals, sizeof(__pyx_k__wvals), 0, 0, 1, 1}, - {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1}, - {&__pyx_n_s__x_bins, __pyx_k__x_bins, sizeof(__pyx_k__x_bins), 0, 0, 1, 1}, - {&__pyx_n_s__x_bounds, __pyx_k__x_bounds, sizeof(__pyx_k__x_bounds), 0, 0, 1, 1}, - {&__pyx_n_s__x_is, __pyx_k__x_is, sizeof(__pyx_k__x_is), 0, 0, 1, 1}, - {&__pyx_n_s__x_vals, __pyx_k__x_vals, sizeof(__pyx_k__x_vals), 0, 0, 1, 1}, - {&__pyx_n_s__x_vec, __pyx_k__x_vec, sizeof(__pyx_k__x_vec), 0, 0, 1, 1}, - {&__pyx_n_s__xrange, __pyx_k__xrange, sizeof(__pyx_k__xrange), 0, 0, 1, 1}, - {&__pyx_n_s__y, __pyx_k__y, sizeof(__pyx_k__y), 0, 0, 1, 1}, - {&__pyx_n_s__y_bins, __pyx_k__y_bins, sizeof(__pyx_k__y_bins), 0, 0, 1, 1}, - {&__pyx_n_s__y_is, __pyx_k__y_is, sizeof(__pyx_k__y_is), 0, 0, 1, 1}, - {&__pyx_n_s__y_vals, __pyx_k__y_vals, sizeof(__pyx_k__y_vals), 0, 0, 1, 1}, - {&__pyx_n_s__y_vec, __pyx_k__y_vec, sizeof(__pyx_k__y_vec), 0, 0, 1, 1}, - {&__pyx_n_s__z, __pyx_k__z, sizeof(__pyx_k__z), 0, 0, 1, 1}, - {&__pyx_n_s__z_bins, __pyx_k__z_bins, sizeof(__pyx_k__z_bins), 0, 0, 1, 1}, - {&__pyx_n_s__z_is, __pyx_k__z_is, sizeof(__pyx_k__z_is), 0, 0, 1, 1}, - {&__pyx_n_s__z_vals, __pyx_k__z_vals, sizeof(__pyx_k__z_vals), 0, 0, 1, 1}, - {&__pyx_n_s__zeros, __pyx_k__zeros, sizeof(__pyx_k__zeros), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if PY_MAJOR_VERSION >= 3 - __pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #else - __pyx_builtin_xrange = __Pyx_GetName(__pyx_b, __pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitGlobals(void) { - #if PY_VERSION_HEX < 0x02040000 - if (unlikely(__Pyx_Py23SetsImport() < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initamr_utils(void); /*proto*/ -PyMODINIT_FUNC initamr_utils(void) -#else -PyMODINIT_FUNC PyInit_amr_utils(void); /*proto*/ -PyMODINIT_FUNC PyInit_amr_utils(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - #if CYTHON_REFNANNY - void* __pyx_refnanny = NULL; - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_amr_utils(void)", __LINE__, __FILE__); - #endif - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __pyx_binding_PyCFunctionType_USED - if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("amr_utils"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_13), 0, PYTHON_API_VERSION); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (!__pyx_m) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - #if PY_MAJOR_VERSION < 3 - Py_INCREF(__pyx_m); - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); - if (!__pyx_b) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_yt__amr_utils) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_position) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "position", (PyObject *)&__pyx_type_2yt_9amr_utils_position) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_position = &__pyx_type_2yt_9amr_utils_position; - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_OctreeGrid) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "OctreeGrid", (PyObject *)&__pyx_type_2yt_9amr_utils_OctreeGrid) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_OctreeGrid = &__pyx_type_2yt_9amr_utils_OctreeGrid; - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_OctreeGridList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "OctreeGridList", (PyObject *)&__pyx_type_2yt_9amr_utils_OctreeGridList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_OctreeGridList = &__pyx_type_2yt_9amr_utils_OctreeGridList; - __pyx_vtabptr_2yt_9amr_utils_VectorPlane = &__pyx_vtable_2yt_9amr_utils_VectorPlane; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_2yt_9amr_utils_VectorPlane.get_start_stop = (void (*)(struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *, int *))__pyx_f_2yt_9amr_utils_11VectorPlane_get_start_stop; - __pyx_vtable_2yt_9amr_utils_VectorPlane.copy_into = (void (*)(struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, int, int, int, int *))__pyx_f_2yt_9amr_utils_11VectorPlane_copy_into; - __pyx_vtable_2yt_9amr_utils_VectorPlane.copy_back = (void (*)(struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, int, int, int, int *))__pyx_f_2yt_9amr_utils_11VectorPlane_copy_back; - #else - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_VectorPlane.get_start_stop = (void(*)(void))__pyx_f_2yt_9amr_utils_11VectorPlane_get_start_stop; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_VectorPlane.copy_into = (void(*)(void))__pyx_f_2yt_9amr_utils_11VectorPlane_copy_into; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_VectorPlane.copy_back = (void(*)(void))__pyx_f_2yt_9amr_utils_11VectorPlane_copy_back; - #endif - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_VectorPlane) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_2yt_9amr_utils_VectorPlane.tp_dict, __pyx_vtabptr_2yt_9amr_utils_VectorPlane) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "VectorPlane", (PyObject *)&__pyx_type_2yt_9amr_utils_VectorPlane) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_VectorPlane = &__pyx_type_2yt_9amr_utils_VectorPlane; - __pyx_vtabptr_2yt_9amr_utils_TransferFunctionProxy = &__pyx_vtable_2yt_9amr_utils_TransferFunctionProxy; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_2yt_9amr_utils_TransferFunctionProxy.eval_transfer = (void (*)(struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *))__pyx_f_2yt_9amr_utils_21TransferFunctionProxy_eval_transfer; - #else - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_TransferFunctionProxy.eval_transfer = (void(*)(void))__pyx_f_2yt_9amr_utils_21TransferFunctionProxy_eval_transfer; - #endif - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_TransferFunctionProxy) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_2yt_9amr_utils_TransferFunctionProxy.tp_dict, __pyx_vtabptr_2yt_9amr_utils_TransferFunctionProxy) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TransferFunctionProxy", (PyObject *)&__pyx_type_2yt_9amr_utils_TransferFunctionProxy) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_TransferFunctionProxy = &__pyx_type_2yt_9amr_utils_TransferFunctionProxy; - __pyx_vtabptr_2yt_9amr_utils_PartitionedGrid = &__pyx_vtable_2yt_9amr_utils_PartitionedGrid; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_2yt_9amr_utils_PartitionedGrid.calculate_extent = (void (*)(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *, struct __pyx_obj_2yt_9amr_utils_VectorPlane *, __pyx_t_5numpy_float64_t *))__pyx_f_2yt_9amr_utils_15PartitionedGrid_calculate_extent; - __pyx_vtable_2yt_9amr_utils_PartitionedGrid.integrate_ray = (int (*)(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *))__pyx_f_2yt_9amr_utils_15PartitionedGrid_integrate_ray; - __pyx_vtable_2yt_9amr_utils_PartitionedGrid.sample_values = (void (*)(struct __pyx_obj_2yt_9amr_utils_PartitionedGrid *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t, __pyx_t_5numpy_float64_t, int *, __pyx_t_5numpy_float64_t *, struct __pyx_obj_2yt_9amr_utils_TransferFunctionProxy *))__pyx_f_2yt_9amr_utils_15PartitionedGrid_sample_values; - #else - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_PartitionedGrid.calculate_extent = (void(*)(void))__pyx_f_2yt_9amr_utils_15PartitionedGrid_calculate_extent; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_PartitionedGrid.integrate_ray = (void(*)(void))__pyx_f_2yt_9amr_utils_15PartitionedGrid_integrate_ray; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_PartitionedGrid.sample_values = (void(*)(void))__pyx_f_2yt_9amr_utils_15PartitionedGrid_sample_values; - #endif - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_PartitionedGrid) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_2yt_9amr_utils_PartitionedGrid.tp_dict, __pyx_vtabptr_2yt_9amr_utils_PartitionedGrid) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "PartitionedGrid", (PyObject *)&__pyx_type_2yt_9amr_utils_PartitionedGrid) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_PartitionedGrid = &__pyx_type_2yt_9amr_utils_PartitionedGrid; - __pyx_vtabptr_2yt_9amr_utils_GridFace = &__pyx_vtable_2yt_9amr_utils_GridFace; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_2yt_9amr_utils_GridFace.proj_overlap = (int (*)(struct __pyx_obj_2yt_9amr_utils_GridFace *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *))__pyx_f_2yt_9amr_utils_8GridFace_proj_overlap; - #else - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_GridFace.proj_overlap = (void(*)(void))__pyx_f_2yt_9amr_utils_8GridFace_proj_overlap; - #endif - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_GridFace) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_2yt_9amr_utils_GridFace.tp_dict, __pyx_vtabptr_2yt_9amr_utils_GridFace) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "GridFace", (PyObject *)&__pyx_type_2yt_9amr_utils_GridFace) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_GridFace = &__pyx_type_2yt_9amr_utils_GridFace; - __pyx_vtabptr_2yt_9amr_utils_ProtoPrism = &__pyx_vtable_2yt_9amr_utils_ProtoPrism; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_2yt_9amr_utils_ProtoPrism.split = (PyObject *(*)(struct __pyx_obj_2yt_9amr_utils_ProtoPrism *, __pyx_t_5numpy_float64_t *, int))__pyx_f_2yt_9amr_utils_10ProtoPrism_split; - #else - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_ProtoPrism.split = (void(*)(void))__pyx_f_2yt_9amr_utils_10ProtoPrism_split; - #endif - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_ProtoPrism) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_2yt_9amr_utils_ProtoPrism.tp_dict, __pyx_vtabptr_2yt_9amr_utils_ProtoPrism) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "ProtoPrism", (PyObject *)&__pyx_type_2yt_9amr_utils_ProtoPrism) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_ProtoPrism = &__pyx_type_2yt_9amr_utils_ProtoPrism; - __pyx_vtabptr_2yt_9amr_utils_QuadTree = &__pyx_vtable_2yt_9amr_utils_QuadTree; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_2yt_9amr_utils_QuadTree.add_to_position = (void (*)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, int, __pyx_t_5numpy_int64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t))__pyx_f_2yt_9amr_utils_8QuadTree_add_to_position; - __pyx_vtable_2yt_9amr_utils_QuadTree.find_on_root_level = (struct __pyx_t_2yt_9amr_utils_QuadTreeNode *(*)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, __pyx_t_5numpy_int64_t *, int))__pyx_f_2yt_9amr_utils_8QuadTree_find_on_root_level; - __pyx_vtable_2yt_9amr_utils_QuadTree.count_at_level = (int (*)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, struct __pyx_t_2yt_9amr_utils_QuadTreeNode *, int))__pyx_f_2yt_9amr_utils_8QuadTree_count_at_level; - __pyx_vtable_2yt_9amr_utils_QuadTree.fill_from_level = (int (*)(struct __pyx_obj_2yt_9amr_utils_QuadTree *, struct __pyx_t_2yt_9amr_utils_QuadTreeNode *, int, __pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t *, __pyx_t_5numpy_float64_t *, __pyx_t_5numpy_float64_t *))__pyx_f_2yt_9amr_utils_8QuadTree_fill_from_level; - #else - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_QuadTree.add_to_position = (void(*)(void))__pyx_f_2yt_9amr_utils_8QuadTree_add_to_position; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_QuadTree.find_on_root_level = (void(*)(void))__pyx_f_2yt_9amr_utils_8QuadTree_find_on_root_level; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_QuadTree.count_at_level = (void(*)(void))__pyx_f_2yt_9amr_utils_8QuadTree_count_at_level; - *(void(**)(void))&__pyx_vtable_2yt_9amr_utils_QuadTree.fill_from_level = (void(*)(void))__pyx_f_2yt_9amr_utils_8QuadTree_fill_from_level; - #endif - if (PyType_Ready(&__pyx_type_2yt_9amr_utils_QuadTree) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_2yt_9amr_utils_QuadTree.tp_dict, __pyx_vtabptr_2yt_9amr_utils_QuadTree) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "QuadTree", (PyObject *)&__pyx_type_2yt_9amr_utils_QuadTree) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_2yt_9amr_utils_QuadTree = &__pyx_type_2yt_9amr_utils_QuadTree; - /*--- Type import code ---*/ - __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "/Users/matthewturk/yt/yt/yt/amr_utils.pyx":32 - * - * # Set up some imports - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/DepthFirstOctree.pyx":26 - * """ - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/Interpolators.pyx":1 - * """ # <<<<<<<<<<<<<< - * Simple interpolators - * - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/PointsInVolume.pyx":27 - * - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/RayIntegrators.pyx":26 - * """ - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/VolumeIntegrator.pyx":1 - * """ # <<<<<<<<<<<<<< - * Simple integrators for the radiative transfer equation - * - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/ContourFinding.pyx":26 - * """ - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/png_writer.pyx":1 - * """ # <<<<<<<<<<<<<< - * A light interface to libpng - * - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/fortran_reader.pyx":26 - * """ - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * cimport cython - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/_amr_utils/QuadTree.pyx":27 - * - * - * import numpy as np # <<<<<<<<<<<<<< - * cimport numpy as np - * # Double up here for def'd functions - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/amr_utils.pyx":1 - * """ # <<<<<<<<<<<<<< - * Container file to hold all our Cython routines. This is to avoid problems with - * static linking. - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyObject_GetAttr(__pyx_m, __pyx_n_s__Transfer3D); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_2, "__doc__"); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_14), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__TransferShells); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetAttrString(__pyx_t_3, "__doc__"); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_15), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":963 - * arr.base = baseptr - * - * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< - * if arr.base is NULL: - * return None - */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - if (__pyx_m) { - __Pyx_AddTraceback("init yt.amr_utils"); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init yt.amr_utils"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) - PyErr_SetObject(PyExc_NameError, name); - return result; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *number, *more_or_less; - - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - number = (num_expected == 1) ? "" : "s"; - PyErr_Format(PyExc_TypeError, - #if PY_VERSION_HEX < 0x02050000 - "%s() takes %s %d positional argument%s (%d given)", - #else - "%s() takes %s %zd positional argument%s (%zd given)", - #endif - func_name, more_or_less, num_expected, number, num_found); -} - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) - #else - if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) - #endif - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - return 0; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AS_STRING(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - } else { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { - #else - if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { - #endif - goto invalid_keyword_type; - } else { - for (name = first_kw_arg; *name; name++) { - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) break; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) break; - #endif - } - if (*name) { - values[name-argnames] = value; - } else { - /* unexpected keyword found */ - for (name=argnames; name != first_kw_arg; name++) { - if (**name == key) goto arg_passed_twice; - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) goto arg_passed_twice; - #endif - } - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - } - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, **name); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact) -{ - if (!type) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (none_allowed && obj == Py_None) return 1; - else if (exact) { - if (Py_TYPE(obj) == type) return 1; - } - else { - if (PyObject_TypeCheck(obj, type)) return 1; - } - PyErr_Format(PyExc_TypeError, - "Argument '%s' has incorrect type (expected %s, got %s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); - return 0; -} - -static CYTHON_INLINE int __Pyx_IsLittleEndian(void) { - unsigned int n = 1; - return *(unsigned char*)(&n) != 0; -} - -typedef struct { - __Pyx_StructField root; - __Pyx_BufFmt_StackElem* head; - size_t fmt_offset; - int new_count, enc_count; - int is_complex; - char enc_type; - char packmode; -} __Pyx_BufFmt_Context; - -static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, - __Pyx_BufFmt_StackElem* stack, - __Pyx_TypeInfo* type) { - stack[0].field = &ctx->root; - stack[0].parent_offset = 0; - ctx->root.type = type; - ctx->root.name = "buffer dtype"; - ctx->root.offset = 0; - ctx->head = stack; - ctx->head->field = &ctx->root; - ctx->fmt_offset = 0; - ctx->head->parent_offset = 0; - ctx->packmode = '@'; - ctx->new_count = 1; - ctx->enc_count = 0; - ctx->enc_type = 0; - ctx->is_complex = 0; - while (type->typegroup == 'S') { - ++ctx->head; - ctx->head->field = type->fields; - ctx->head->parent_offset = 0; - type = type->fields->type; - } -} - -static int __Pyx_BufFmt_ParseNumber(const char** ts) { - int count; - const char* t = *ts; - if (*t < '0' || *t > '9') { - return -1; - } else { - count = *t++ - '0'; - while (*t >= '0' && *t < '9') { - count *= 10; - count += *t++ - '0'; - } - } - *ts = t; - return count; -} - -static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { - char msg[] = {ch, 0}; - PyErr_Format(PyExc_ValueError, "Unexpected format string character: '%s'", msg); -} - -static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { - switch (ch) { - case 'b': return "'char'"; - case 'B': return "'unsigned char'"; - case 'h': return "'short'"; - case 'H': return "'unsigned short'"; - case 'i': return "'int'"; - case 'I': return "'unsigned int'"; - case 'l': return "'long'"; - case 'L': return "'unsigned long'"; - case 'q': return "'long long'"; - case 'Q': return "'unsigned long long'"; - case 'f': return (is_complex ? "'complex float'" : "'float'"); - case 'd': return (is_complex ? "'complex double'" : "'double'"); - case 'g': return (is_complex ? "'complex long double'" : "'long double'"); - case 'T': return "a struct"; - case 'O': return "Python object"; - case 'P': return "a pointer"; - case 0: return "end"; - default: return "unparseable format string"; - } -} - -static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': return 1; - case 'h': case 'H': return 2; - case 'i': case 'I': case 'l': case 'L': return 4; - case 'q': case 'Q': return 8; - case 'f': return (is_complex ? 8 : 4); - case 'd': return (is_complex ? 16 : 8); - case 'g': { - PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); - return 0; - } - case 'O': case 'P': return sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } -} - -static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { - switch (ch) { - case 'c': case 'b': case 'B': return 1; - case 'h': case 'H': return sizeof(short); - case 'i': case 'I': return sizeof(int); - case 'l': case 'L': return sizeof(long); - #ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(PY_LONG_LONG); - #endif - case 'f': return sizeof(float) * (is_complex ? 2 : 1); - case 'd': return sizeof(double) * (is_complex ? 2 : 1); - case 'g': return sizeof(long double) * (is_complex ? 2 : 1); - case 'O': case 'P': return sizeof(void*); - default: { - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } - } -} - -typedef struct { char c; short x; } __Pyx_st_short; -typedef struct { char c; int x; } __Pyx_st_int; -typedef struct { char c; long x; } __Pyx_st_long; -typedef struct { char c; float x; } __Pyx_st_float; -typedef struct { char c; double x; } __Pyx_st_double; -typedef struct { char c; long double x; } __Pyx_st_longdouble; -typedef struct { char c; void *x; } __Pyx_st_void_p; -#ifdef HAVE_LONG_LONG -typedef struct { char c; PY_LONG_LONG x; } __Pyx_s_long_long; -#endif - -static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { - switch (ch) { - case '?': case 'c': case 'b': case 'B': return 1; - case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); - case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); - case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); -#ifdef HAVE_LONG_LONG - case 'q': case 'Q': return sizeof(__Pyx_s_long_long) - sizeof(PY_LONG_LONG); -#endif - case 'f': return sizeof(__Pyx_st_float) - sizeof(float); - case 'd': return sizeof(__Pyx_st_double) - sizeof(double); - case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); - case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); - default: - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } -} - -static size_t __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { - switch (ch) { - case 'c': case 'b': case 'h': case 'i': case 'l': case 'q': return 'I'; - case 'B': case 'H': case 'I': case 'L': case 'Q': return 'U'; - case 'f': case 'd': case 'g': return (is_complex ? 'C' : 'R'); - case 'O': return 'O'; - case 'P': return 'P'; - default: { - __Pyx_BufFmt_RaiseUnexpectedChar(ch); - return 0; - } - } -} - -static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { - if (ctx->head == NULL || ctx->head->field == &ctx->root) { - const char* expected; - const char* quote; - if (ctx->head == NULL) { - expected = "end"; - quote = ""; - } else { - expected = ctx->head->field->type->name; - quote = "'"; - } - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch, expected %s%s%s but got %s", - quote, expected, quote, - __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); - } else { - __Pyx_StructField* field = ctx->head->field; - __Pyx_StructField* parent = (ctx->head - 1)->field; - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", - field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), - parent->type->name, field->name); - } -} - -static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { - char group; - size_t size, offset; - if (ctx->enc_type == 0) return 0; - group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); - do { - __Pyx_StructField* field = ctx->head->field; - __Pyx_TypeInfo* type = field->type; - - if (ctx->packmode == '@' || ctx->packmode == '^') { - size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); - } else { - size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); - } - if (ctx->packmode == '@') { - int align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); - int align_mod_offset; - if (align_at == 0) return -1; - align_mod_offset = ctx->fmt_offset % align_at; - if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; - } - - if (type->size != size || type->typegroup != group) { - if (type->typegroup == 'C' && type->fields != NULL) { - /* special case -- treat as struct rather than complex number */ - size_t parent_offset = ctx->head->parent_offset + field->offset; - ++ctx->head; - ctx->head->field = type->fields; - ctx->head->parent_offset = parent_offset; - continue; - } - - __Pyx_BufFmt_RaiseExpected(ctx); - return -1; - } - - offset = ctx->head->parent_offset + field->offset; - if (ctx->fmt_offset != offset) { - PyErr_Format(PyExc_ValueError, - "Buffer dtype mismatch; next field is at offset %"PY_FORMAT_SIZE_T"d " - "but %"PY_FORMAT_SIZE_T"d expected", ctx->fmt_offset, offset); - return -1; - } - - ctx->fmt_offset += size; - - --ctx->enc_count; /* Consume from buffer string */ - - /* Done checking, move to next field, pushing or popping struct stack if needed */ - while (1) { - if (field == &ctx->root) { - ctx->head = NULL; - if (ctx->enc_count != 0) { - __Pyx_BufFmt_RaiseExpected(ctx); - return -1; - } - break; /* breaks both loops as ctx->enc_count == 0 */ - } - ctx->head->field = ++field; - if (field->type == NULL) { - --ctx->head; - field = ctx->head->field; - continue; - } else if (field->type->typegroup == 'S') { - size_t parent_offset = ctx->head->parent_offset + field->offset; - if (field->type->fields->type == NULL) continue; /* empty struct */ - field = field->type->fields; - ++ctx->head; - ctx->head->field = field; - ctx->head->parent_offset = parent_offset; - break; - } else { - break; - } - } - } while (ctx->enc_count); - ctx->enc_type = 0; - ctx->is_complex = 0; - return 0; -} - -static int __Pyx_BufFmt_FirstPack(__Pyx_BufFmt_Context* ctx) { - if (ctx->enc_type != 0 || ctx->packmode != '@') { - PyErr_SetString(PyExc_ValueError, "Buffer packing mode currently only allowed at beginning of format string (this is a defect)"); - return -1; - } - return 0; -} - -static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { - int got_Z = 0; - while (1) { - switch(*ts) { - case 0: - if (ctx->enc_type != 0 && ctx->head == NULL) { - __Pyx_BufFmt_RaiseExpected(ctx); - return NULL; - } - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - if (ctx->head != NULL) { - __Pyx_BufFmt_RaiseExpected(ctx); - return NULL; - } - return ts; - case ' ': - case 10: - case 13: - ++ts; - break; - case '<': - if (!__Pyx_IsLittleEndian()) { - PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); - return NULL; - } - if (__Pyx_BufFmt_FirstPack(ctx) == -1) return NULL; - ctx->packmode = '='; - ++ts; - break; - case '>': - case '!': - if (__Pyx_IsLittleEndian()) { - PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); - return NULL; - } - if (__Pyx_BufFmt_FirstPack(ctx) == -1) return NULL; - ctx->packmode = '='; - ++ts; - break; - case '=': - case '@': - case '^': - if (__Pyx_BufFmt_FirstPack(ctx) == -1) return NULL; - ctx->packmode = *ts++; - break; - case 'T': /* substruct */ - { - int i; - const char* ts_after_sub; - int struct_count = ctx->new_count; - ctx->new_count = 1; - ++ts; - if (*ts != '{') { - PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); - return NULL; - } - ++ts; - ts_after_sub = ts; - for (i = 0; i != struct_count; ++i) { - ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); - if (!ts_after_sub) return NULL; - } - ts = ts_after_sub; - } - break; - case '}': /* end of substruct; either repeat or move on */ - ++ts; - return ts; - case 'x': - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->fmt_offset += ctx->new_count; - ctx->new_count = 1; - ctx->enc_count = 0; - ctx->enc_type = 0; - ++ts; - break; - case 'Z': - got_Z = 1; - ++ts; - if (*ts != 'f' && *ts != 'd' && *ts != 'g') { - __Pyx_BufFmt_RaiseUnexpectedChar('Z'); - return NULL; - } /* fall through */ - case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': - case 'l': case 'L': case 'q': case 'Q': - case 'f': case 'd': case 'g': - case 'O': - if (ctx->enc_type == *ts && got_Z == ctx->is_complex) { - /* Continue pooling same type */ - ctx->enc_count += ctx->new_count; - } else { - /* New type */ - if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; - ctx->enc_count = ctx->new_count; - ctx->enc_type = *ts; - ctx->is_complex = got_Z; - } - ++ts; - ctx->new_count = 1; - got_Z = 0; - break; - default: - { - ctx->new_count = __Pyx_BufFmt_ParseNumber(&ts); - if (ctx->new_count == -1) { /* First char was not a digit */ - char msg[2] = { *ts, 0 }; - PyErr_Format(PyExc_ValueError, - "Does not understand character buffer dtype format string ('%s')", msg); - return NULL; - } - } - - } - } -} - -static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) { - buf->buf = NULL; - buf->obj = NULL; - buf->strides = __Pyx_zeros; - buf->shape = __Pyx_zeros; - buf->suboffsets = __Pyx_minusones; -} - -static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack) { - if (obj == Py_None) { - __Pyx_ZeroBuffer(buf); - return 0; - } - buf->buf = NULL; - if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail; - if (buf->ndim != nd) { - PyErr_Format(PyExc_ValueError, - "Buffer has wrong number of dimensions (expected %d, got %d)", - nd, buf->ndim); - goto fail; - } - if (!cast) { - __Pyx_BufFmt_Context ctx; - __Pyx_BufFmt_Init(&ctx, stack, dtype); - if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; - } - if ((unsigned)buf->itemsize != dtype->size) { - PyErr_Format(PyExc_ValueError, - "Item size of buffer (%"PY_FORMAT_SIZE_T"d byte%s) does not match size of '%s' (%"PY_FORMAT_SIZE_T"d byte%s)", - buf->itemsize, (buf->itemsize > 1) ? "s" : "", - dtype->name, - dtype->size, (dtype->size > 1) ? "s" : ""); - goto fail; - } - if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; - return 0; -fail:; - __Pyx_ZeroBuffer(buf); - return -1; -} - -static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { - if (info->buf == NULL) return; - if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; - __Pyx_ReleaseBuffer(info); -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -} - -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -} - - - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - -static void __Pyx_RaiseBufferFallbackError(void) { - PyErr_Format(PyExc_ValueError, - "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!"); -} - -static void __Pyx_RaiseBufferIndexError(int axis) { - PyErr_Format(PyExc_IndexError, - "Out of bounds on buffer access (axis %d)", axis); -} - - -static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { - long r = a % b; - r += ((r != 0) & ((r ^ b) < 0)) * b; - return r; -} - -static CYTHON_INLINE long __Pyx_div_long(long a, long b) { - long q = a / b; - long r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; -} - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - #if PY_VERSION_HEX < 0x02050000 - "need more than %d value%s to unpack", (int)index, - #else - "need more than %zd value%s to unpack", index, - #endif - (index == 1) ? "" : "s"); -} - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { - PyErr_Format(PyExc_ValueError, - #if PY_VERSION_HEX < 0x02050000 - "too many values to unpack (expected %d)", (int)expected); - #else - "too many values to unpack (expected %zd)", expected); - #endif -} - -static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { - PyObject *item; - if (!(item = PyIter_Next(iter))) { - if (!PyErr_Occurred()) { - __Pyx_RaiseNeedMoreValuesError(index); - } - } - return item; -} - -static int __Pyx_EndUnpack(PyObject *iter, Py_ssize_t expected) { - PyObject *item; - if ((item = PyIter_Next(iter))) { - Py_DECREF(item); - __Pyx_RaiseTooManyValuesError(expected); - return -1; - } - else if (!PyErr_Occurred()) - return 0; - else - return -1; -} - - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_5numpy_int64_t a, __pyx_t_5numpy_int64_t b) { - __pyx_t_5numpy_int64_t q = a / b; - __pyx_t_5numpy_int64_t r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; -} - -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); -} - -static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { - if (t == Py_None) { - __Pyx_RaiseNoneNotIterableError(); - } else if (PyTuple_GET_SIZE(t) < index) { - __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); - } else { - __Pyx_RaiseTooManyValuesError(index); - } -} - -#if PY_MAJOR_VERSION < 3 -static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { - #if PY_VERSION_HEX >= 0x02060000 - if (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HAVE_NEWBUFFER) - return PyObject_GetBuffer(obj, view, flags); - #endif - if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pf_5numpy_7ndarray___getbuffer__(obj, view, flags); - else { - PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); - return -1; - } -} - -static void __Pyx_ReleaseBuffer(Py_buffer *view) { - PyObject* obj = view->obj; - if (obj) { -if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) __pyx_pf_5numpy_7ndarray___releasebuffer__(obj, view); - Py_DECREF(obj); - view->obj = NULL; - } -} - -#endif - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { - PyObject *py_import = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!py_import) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); -bad: - Py_XDECREF(empty_list); - Py_XDECREF(py_import); - Py_XDECREF(empty_dict); - return module; -} - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_intp(npy_intp val) { - const npy_intp neg_one = (npy_intp)-1, const_zero = (npy_intp)0; - const int is_unsigned = const_zero < neg_one; - if ((sizeof(npy_intp) == sizeof(char)) || - (sizeof(npy_intp) == sizeof(short))) { - return PyInt_FromLong((long)val); - } else if ((sizeof(npy_intp) == sizeof(int)) || - (sizeof(npy_intp) == sizeof(long))) { - if (is_unsigned) - return PyLong_FromUnsignedLong((unsigned long)val); - else - return PyInt_FromLong((long)val); - } else if (sizeof(npy_intp) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); - else - return PyLong_FromLongLong((PY_LONG_LONG)val); - } else { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - return _PyLong_FromByteArray(bytes, sizeof(npy_intp), - little, !is_unsigned); - } -} - -static CYTHON_INLINE npy_int32 __Pyx_PyInt_from_py_npy_int32(PyObject* x) { - const npy_int32 neg_one = (npy_int32)-1, const_zero = (npy_int32)0; - const int is_unsigned = const_zero < neg_one; - if (sizeof(npy_int32) == sizeof(char)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedChar(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedChar(x); - } else if (sizeof(npy_int32) == sizeof(short)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedShort(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedShort(x); - } else if (sizeof(npy_int32) == sizeof(int)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedInt(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedInt(x); - } else if (sizeof(npy_int32) == sizeof(long)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedLong(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedLong(x); - } else if (sizeof(npy_int32) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return (npy_int32)__Pyx_PyInt_AsUnsignedLongLong(x); - else - return (npy_int32)__Pyx_PyInt_AsSignedLongLong(x); - } else { - npy_int32 val; - PyObject *v = __Pyx_PyNumber_Int(x); - #if PY_VERSION_HEX < 0x03000000 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); - } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; - } - return (npy_int32)-1; - } -} - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int32(npy_int32 val) { - const npy_int32 neg_one = (npy_int32)-1, const_zero = (npy_int32)0; - const int is_unsigned = const_zero < neg_one; - if ((sizeof(npy_int32) == sizeof(char)) || - (sizeof(npy_int32) == sizeof(short))) { - return PyInt_FromLong((long)val); - } else if ((sizeof(npy_int32) == sizeof(int)) || - (sizeof(npy_int32) == sizeof(long))) { - if (is_unsigned) - return PyLong_FromUnsignedLong((unsigned long)val); - else - return PyInt_FromLong((long)val); - } else if (sizeof(npy_int32) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); - else - return PyLong_FromLongLong((PY_LONG_LONG)val); - } else { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - return _PyLong_FromByteArray(bytes, sizeof(npy_int32), - little, !is_unsigned); - } -} - -#if PY_MAJOR_VERSION < 3 -static PyObject *__Pyx_GetStdout(void) { - PyObject *f = PySys_GetObject((char *)"stdout"); - if (!f) { - PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); - } - return f; -} - -static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) { - PyObject* v; - int i; - - if (!f) { - if (!(f = __Pyx_GetStdout())) - return -1; - } - for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) { - if (PyFile_SoftSpace(f, 1)) { - if (PyFile_WriteString(" ", f) < 0) - return -1; - } - v = PyTuple_GET_ITEM(arg_tuple, i); - if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0) - return -1; - if (PyString_Check(v)) { - char *s = PyString_AsString(v); - Py_ssize_t len = PyString_Size(v); - if (len > 0 && - isspace(Py_CHARMASK(s[len-1])) && - s[len-1] != ' ') - PyFile_SoftSpace(f, 0); - } - } - if (newline) { - if (PyFile_WriteString("\n", f) < 0) - return -1; - PyFile_SoftSpace(f, 0); - } - return 0; -} - -#else /* Python 3 has a print function */ - -static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) { - PyObject* kwargs = 0; - PyObject* result = 0; - PyObject* end_string; - if (unlikely(!__pyx_print)) { - __pyx_print = __Pyx_GetAttrString(__pyx_b, "print"); - if (!__pyx_print) - return -1; - } - if (stream) { - kwargs = PyDict_New(); - if (unlikely(!kwargs)) - return -1; - if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0)) - goto bad; - if (!newline) { - end_string = PyUnicode_FromStringAndSize(" ", 1); - if (unlikely(!end_string)) - goto bad; - if (PyDict_SetItemString(kwargs, "end", end_string) < 0) { - Py_DECREF(end_string); - goto bad; - } - Py_DECREF(end_string); - } - } else if (!newline) { - if (unlikely(!__pyx_print_kwargs)) { - __pyx_print_kwargs = PyDict_New(); - if (unlikely(!__pyx_print_kwargs)) - return -1; - end_string = PyUnicode_FromStringAndSize(" ", 1); - if (unlikely(!end_string)) - return -1; - if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) { - Py_DECREF(end_string); - return -1; - } - Py_DECREF(end_string); - } - kwargs = __pyx_print_kwargs; - } - result = PyObject_Call(__pyx_print, arg_tuple, kwargs); - if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs)) - Py_DECREF(kwargs); - if (!result) - return -1; - Py_DECREF(result); - return 0; -bad: - if (kwargs != __pyx_print_kwargs) - Py_XDECREF(kwargs); - return -1; -} - -#endif - -static CYTHON_INLINE npy_int64 __Pyx_PyInt_from_py_npy_int64(PyObject* x) { - const npy_int64 neg_one = (npy_int64)-1, const_zero = (npy_int64)0; - const int is_unsigned = const_zero < neg_one; - if (sizeof(npy_int64) == sizeof(char)) { - if (is_unsigned) - return (npy_int64)__Pyx_PyInt_AsUnsignedChar(x); - else - return (npy_int64)__Pyx_PyInt_AsSignedChar(x); - } else if (sizeof(npy_int64) == sizeof(short)) { - if (is_unsigned) - return (npy_int64)__Pyx_PyInt_AsUnsignedShort(x); - else - return (npy_int64)__Pyx_PyInt_AsSignedShort(x); - } else if (sizeof(npy_int64) == sizeof(int)) { - if (is_unsigned) - return (npy_int64)__Pyx_PyInt_AsUnsignedInt(x); - else - return (npy_int64)__Pyx_PyInt_AsSignedInt(x); - } else if (sizeof(npy_int64) == sizeof(long)) { - if (is_unsigned) - return (npy_int64)__Pyx_PyInt_AsUnsignedLong(x); - else - return (npy_int64)__Pyx_PyInt_AsSignedLong(x); - } else if (sizeof(npy_int64) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return (npy_int64)__Pyx_PyInt_AsUnsignedLongLong(x); - else - return (npy_int64)__Pyx_PyInt_AsSignedLongLong(x); - } else { - npy_int64 val; - PyObject *v = __Pyx_PyNumber_Int(x); - #if PY_VERSION_HEX < 0x03000000 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); - } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; - } - return (npy_int64)-1; - } -} - -#if PY_MAJOR_VERSION < 3 - -static int __Pyx_PrintOne(PyObject* f, PyObject *o) { - if (!f) { - if (!(f = __Pyx_GetStdout())) - return -1; - } - if (PyFile_SoftSpace(f, 0)) { - if (PyFile_WriteString(" ", f) < 0) - return -1; - } - if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0) - return -1; - if (PyFile_WriteString("\n", f) < 0) - return -1; - return 0; - /* the line below is just to avoid compiler - * compiler warnings about unused functions */ - return __Pyx_Print(f, NULL, 0); -} - -#else /* Python 3 has a print function */ - -static int __Pyx_PrintOne(PyObject* stream, PyObject *o) { - int res; - PyObject* arg_tuple = PyTuple_New(1); - if (unlikely(!arg_tuple)) - return -1; - Py_INCREF(o); - PyTuple_SET_ITEM(arg_tuple, 0, o); - res = __Pyx_Print(stream, arg_tuple, 1); - Py_DECREF(arg_tuple); - return res; -} - -#endif - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { - Py_XINCREF(type); - Py_XINCREF(value); - Py_XINCREF(tb); - /* First, check the traceback argument, replacing None with NULL. */ - if (tb == Py_None) { - Py_DECREF(tb); - tb = 0; - } - else if (tb != NULL && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - /* Next, replace a missing value with None */ - if (value == NULL) { - value = Py_None; - Py_INCREF(value); - } - #if PY_VERSION_HEX < 0x02050000 - if (!PyClass_Check(type)) - #else - if (!PyType_Check(type)) - #endif - { - /* Raising an instance. The value should be a dummy. */ - if (value != Py_None) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - /* Normalize to raise , */ - Py_DECREF(value); - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} - -#else /* Python 3+ */ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (!PyExceptionClass_Check(type)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - - PyErr_SetObject(type, value); - - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } - -bad: - return; -} -#endif - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int64(npy_int64 val) { - const npy_int64 neg_one = (npy_int64)-1, const_zero = (npy_int64)0; - const int is_unsigned = const_zero < neg_one; - if ((sizeof(npy_int64) == sizeof(char)) || - (sizeof(npy_int64) == sizeof(short))) { - return PyInt_FromLong((long)val); - } else if ((sizeof(npy_int64) == sizeof(int)) || - (sizeof(npy_int64) == sizeof(long))) { - if (is_unsigned) - return PyLong_FromUnsignedLong((unsigned long)val); - else - return PyInt_FromLong((long)val); - } else if (sizeof(npy_int64) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); - else - return PyLong_FromLongLong((PY_LONG_LONG)val); - } else { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - return _PyLong_FromByteArray(bytes, sizeof(npy_int64), - little, !is_unsigned); - } -} - -static CYTHON_INLINE png_uint_32 __Pyx_PyInt_from_py_png_uint_32(PyObject* x) { - const png_uint_32 neg_one = (png_uint_32)-1, const_zero = (png_uint_32)0; - const int is_unsigned = const_zero < neg_one; - if (sizeof(png_uint_32) == sizeof(char)) { - if (is_unsigned) - return (png_uint_32)__Pyx_PyInt_AsUnsignedChar(x); - else - return (png_uint_32)__Pyx_PyInt_AsSignedChar(x); - } else if (sizeof(png_uint_32) == sizeof(short)) { - if (is_unsigned) - return (png_uint_32)__Pyx_PyInt_AsUnsignedShort(x); - else - return (png_uint_32)__Pyx_PyInt_AsSignedShort(x); - } else if (sizeof(png_uint_32) == sizeof(int)) { - if (is_unsigned) - return (png_uint_32)__Pyx_PyInt_AsUnsignedInt(x); - else - return (png_uint_32)__Pyx_PyInt_AsSignedInt(x); - } else if (sizeof(png_uint_32) == sizeof(long)) { - if (is_unsigned) - return (png_uint_32)__Pyx_PyInt_AsUnsignedLong(x); - else - return (png_uint_32)__Pyx_PyInt_AsSignedLong(x); - } else if (sizeof(png_uint_32) == sizeof(PY_LONG_LONG)) { - if (is_unsigned) - return (png_uint_32)__Pyx_PyInt_AsUnsignedLongLong(x); - else - return (png_uint_32)__Pyx_PyInt_AsSignedLongLong(x); - } else { - png_uint_32 val; - PyObject *v = __Pyx_PyNumber_Int(x); - #if PY_VERSION_HEX < 0x03000000 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); - } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; - } - return (png_uint_32)-1; - } -} - -static CYTHON_INLINE long __Pyx_pow_long(long b, long e) { - long t = b; - switch (e) { - case 3: - t *= b; - case 2: - t *= b; - case 1: - return t; - case 0: - return 1; - } - if (unlikely(e<0)) return 0; - t = 1; - while (likely(e)) { - t *= (b * (e&1)) | ((~e)&1); /* 1 or b */ - b *= b; - e >>= 1; - } - return t; -} - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - return ::std::complex< float >(x, y); - } - #else - static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - return x + y*(__pyx_t_float_complex)_Complex_I; - } - #endif -#else - static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { - __pyx_t_float_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif - -#if CYTHON_CCOMPLEX -#else - static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - return (a.real == b.real) && (a.imag == b.imag); - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) { - __pyx_t_float_complex z; - float denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) { - __pyx_t_float_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) { - __pyx_t_float_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } -/* - static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) { -#if HAVE_HYPOT - return hypotf(z.real, z.imag); -#else - return sqrtf(z.real*z.real + z.imag*z.imag); -#endif - } -*/ -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - return ::std::complex< double >(x, y); - } - #else - static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - return x + y*(__pyx_t_double_complex)_Complex_I; - } - #endif -#else - static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { - __pyx_t_double_complex z; - z.real = x; - z.imag = y; - return z; - } -#endif - -#if CYTHON_CCOMPLEX -#else - static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) { - return (a.real == b.real) && (a.imag == b.imag); - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real + b.real; - z.imag = a.imag + b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real - b.real; - z.imag = a.imag - b.imag; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - z.real = a.real * b.real - a.imag * b.imag; - z.imag = a.real * b.imag + a.imag * b.real; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) { - __pyx_t_double_complex z; - double denom = b.real * b.real + b.imag * b.imag; - z.real = (a.real * b.real + a.imag * b.imag) / denom; - z.imag = (a.imag * b.real - a.real * b.imag) / denom; - return z; - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = -a.real; - z.imag = -a.imag; - return z; - } - static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) { - return (a.real == 0) && (a.imag == 0); - } - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) { - __pyx_t_double_complex z; - z.real = a.real; - z.imag = -a.imag; - return z; - } -/* - static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) { -#if HAVE_HYPOT - return hypot(z.real, z.imag); -#else - return sqrt(z.real*z.real + z.imag*z.imag); -#endif - } -*/ -#endif - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return PyLong_AsUnsignedLong(x); - } else { - return PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return PyLong_AsUnsignedLongLong(x); - } else { - return PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return PyLong_AsUnsignedLong(x); - } else { - return PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return PyLong_AsUnsignedLongLong(x); - } else { - return PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return PyLong_AsUnsignedLong(x); - } else { - return PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return PyLong_AsUnsignedLongLong(x); - } else { - return PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static void __Pyx_WriteUnraisable(const char *name) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - -static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - PyObject *ob = PyCapsule_New(vtable, 0, 0); -#else - PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); -#endif - if (!ob) - goto bad; - if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) - goto bad; - Py_DECREF(ob); - return 0; -bad: - Py_XDECREF(ob); - return -1; -} - -#ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, - long size, int strict) -{ - PyObject *py_module = 0; - PyObject *result = 0; - PyObject *py_name = 0; - char warning[200]; - - py_module = __Pyx_ImportModule(module_name); - if (!py_module) - goto bad; - #if PY_MAJOR_VERSION < 3 - py_name = PyString_FromString(class_name); - #else - py_name = PyUnicode_FromString(class_name); - #endif - if (!py_name) - goto bad; - result = PyObject_GetAttr(py_module, py_name); - Py_DECREF(py_name); - py_name = 0; - Py_DECREF(py_module); - py_module = 0; - if (!result) - goto bad; - if (!PyType_Check(result)) { - PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", - module_name, class_name); - goto bad; - } - if (!strict && ((PyTypeObject *)result)->tp_basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility", - module_name, class_name); - #if PY_VERSION_HEX < 0x02050000 - PyErr_Warn(NULL, warning); - #else - PyErr_WarnEx(NULL, warning, 0); - #endif - } - else if (((PyTypeObject *)result)->tp_basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", - module_name, class_name); - goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(py_module); - Py_XDECREF(result); - return 0; -} -#endif - -#ifndef __PYX_HAVE_RT_ImportModule -#define __PYX_HAVE_RT_ImportModule -static PyObject *__Pyx_ImportModule(const char *name) { - PyObject *py_name = 0; - PyObject *py_module = 0; - - #if PY_MAJOR_VERSION < 3 - py_name = PyString_FromString(name); - #else - py_name = PyUnicode_FromString(name); - #endif - if (!py_name) - goto bad; - py_module = PyImport_Import(py_name); - Py_DECREF(py_name); - return py_module; -bad: - Py_XDECREF(py_name); - return 0; -} -#endif - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" - -static void __Pyx_AddTraceback(const char *funcname) { - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - PyObject *py_globals = 0; - PyCodeObject *py_code = 0; - PyFrameObject *py_frame = 0; - - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(__pyx_filename); - #else - py_srcfile = PyUnicode_FromString(__pyx_filename); - #endif - if (!py_srcfile) goto bad; - if (__pyx_clineno) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_code = PyCode_New( - 0, /*int argcount,*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*int kwonlyargcount,*/ - #endif - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - __pyx_lineno, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - if (!py_code) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = __pyx_lineno; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/amr_utils.pyx --- a/yt/amr_utils.pyx Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -""" -Container file to hold all our Cython routines. This is to avoid problems with -static linking. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008 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 . -""" - -#cython embedsignature=True -#cython cdivision=True -#cython always_allow_keywords=True - -# Set up some imports -import numpy as np -cimport numpy as np -cimport cython - -# We include all of our files - -include "_amr_utils/DepthFirstOctree.pyx" -include "_amr_utils/Interpolators.pyx" -include "_amr_utils/PointsInVolume.pyx" -include "_amr_utils/RayIntegrators.pyx" -include "_amr_utils/VolumeIntegrator.pyx" -include "_amr_utils/CICDeposit.pyx" -include "_amr_utils/ContourFinding.pyx" -include "_amr_utils/png_writer.pyx" -include "_amr_utils/fortran_reader.pyx" -include "_amr_utils/QuadTree.pyx" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,119 @@ +""" +API for yt.analysis_modules + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .coordinate_transformation.api import \ + spherical_regrid + +from .halo_finding.api import \ + Halo, \ + HOPHalo, \ + parallelHOPHalo, \ + FOFHalo, \ + HaloList, \ + HOPHaloList, \ + FOFHaloList, \ + parallelHOPHaloList, \ + GenericHaloFinder, \ + parallelHF, \ + HOPHaloFinder, \ + FOFHaloFinder, \ + HaloFinder + +from .halo_mass_function.api import \ + HaloMassFcn, \ + TransferFunction, \ + integrate_inf + +from .halo_merger_tree.api import \ + DatabaseFunctions, \ + MergerTree, \ + MergerTreeConnect, \ + Node, \ + Link, \ + MergerTreeDotOutput, \ + MergerTreeTextOutput + +from .halo_profiler.api import \ + VirialFilter, \ + HaloProfiler, \ + FakeProfile, \ + shift_projections + +from .hierarchy_subset.api import \ + ConstructedRootGrid, \ + AMRExtractedGridProxy, \ + ExtractedHierarchy, \ + ExtractedParameterFile + +from .level_sets.api import \ + GridConsiderationQueue, \ + coalesce_join_tree, \ + identify_contours, \ + Clump, \ + find_clumps, \ + get_lowest_clumps, \ + write_clump_hierarchy, \ + write_clumps, \ + write_old_clump_hierarchy, \ + write_old_clumps, \ + write_old_clump_info, \ + _DistanceToMainClump, \ + recursive_all_clumps, \ + return_all_clumps, \ + return_bottom_clumps, \ + recursive_bottom_clumps, \ + clump_list_sort + +#from .light_ray.api import \ +# LightRay + +from .light_cone.api import \ + commonNVolume, \ + commonSegment, \ + light_cone_halo_mask, \ + light_cone_halo_map, \ + light_cone_projection, \ + project_unique_light_cones, \ + find_unique_solutions + +from .simulation_handler.api import \ + EnzoSimulation + +from .spectral_integrator.api import \ + SpectralFrequencyIntegrator, \ + create_table_from_textfiles + +from .sfr_spectrum.api import \ + StarFormationRate, \ + SpectrumBuilder + +from .two_point_functions.api import \ + TwoPointFunctions, \ + FcnSet diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/coordinate_transformation/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/coordinate_transformation/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,32 @@ +""" +API for coordinate_transformation + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .transforms import \ + spherical_regrid diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/coordinate_transformation/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/coordinate_transformation/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('coordinate_transformation',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/coordinate_transformation/transforms.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/coordinate_transformation/transforms.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,129 @@ +""" +Transformations between coordinate systems + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Author: JS Oishi +Organization: UC Berkeley +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 Matthew Turk, J. S. Oishi. 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 . +""" + +import numpy as na +from yt.funcs import * + +from yt.utilities.linear_interpolators import \ + TrilinearFieldInterpolator + +def spherical_regrid(pf, nr, ntheta, nphi, rmax, fields, + center=None, smoothed=True): + """ + This function takes a parameter file (*pf*) along with the *nr*, *ntheta* + and *nphi* points to generate out to *rmax*, and it grids *fields* onto + those points and returns a dict. *center* if supplied will be the center, + otherwise the most dense point will be chosen. *smoothed* governs whether + regular covering grids or smoothed covering grids will be used. + """ + mylog.warning("This code may produce some artifacts of interpolation") + mylog.warning("See yt/extensions/coordinate_transforms.py for plotting information") + if center is None: center = pf.h.find_max("Density")[1] + fields = ensure_list(fields) + r,theta,phi = na.mgrid[0:rmax:nr*1j, + 0:na.pi:ntheta*1j, + 0:2*na.pi:nphi*1j] + new_grid = dict(r=r, theta=theta, phi=phi) + new_grid['x'] = r*na.sin(theta)*na.cos(phi) + center[0] + new_grid['y'] = r*na.sin(theta)*na.sin(phi) + center[1] + new_grid['z'] = r*na.cos(theta) + center[2] + sphere = pf.h.sphere(center, rmax) + return arbitrary_regrid(new_grid, sphere, fields, smoothed) + +def arbitrary_regrid(new_grid, data_source, fields, smoothed=True): + """ + This function accepts a dict of points 'x', 'y' and 'z' and a data source + from which to interpolate new points, along with a list of fields it needs + to regrid onto those xyz points. It then returns interpolated points. + This has not been well-tested other than for regular spherical regridding. + """ + fields = ensure_list(fields) + new_grid['handled'] = na.zeros(new_grid['x'].shape, dtype='bool') + for field in fields: + new_grid[field] = na.zeros(new_grid['x'].shape, dtype='float64') + grid_order = na.argsort(data_source.gridLevels) + ng = len(data_source._grids) + + for i,grid in enumerate(data_source._grids[grid_order][::-1]): + mylog.info("Regridding grid % 4i / % 4i (%s - %s)", i, ng, grid.id, grid.Level) + cg = grid.retrieve_ghost_zones(1, fields, smoothed=smoothed) + + # makes x0,x1,y0,y1,z0,z1 + bounds = na.concatenate(zip(cg.left_edge, cg.right_edge)) + + + # Now we figure out which of our points are inside this grid + # Note that we're only looking at the grid, not the grid-with-ghost-zones + point_ind = na.ones(new_grid['handled'].shape, dtype='bool') # everything at first + for i,ax in enumerate('xyz'): # i = 0,1,2 ; ax = x, y, z + # &= does a logical_and on the array + point_ind &= ( ( grid.LeftEdge[i] <= new_grid[ax] ) + & ( new_grid[ax] <= grid.RightEdge[i] ) ) + point_ind &= (new_grid['handled'] == False) # only want unhandled points + + # If we don't have any, we can just leave + if point_ind.sum() == 0: continue + + # because of the funky way the interpolator takes points, we have to make a + # new dict of just the points inside this grid + point_grid = {'x' : new_grid['x'][point_ind], + 'y' : new_grid['y'][point_ind], + 'z' : new_grid['z'][point_ind]} + + # Now we know which of the points in new_grid are inside this grid + for field in fields: + interpolator = TrilinearFieldInterpolator( + cg[field],bounds,['x','y','z']) + new_grid[field][point_ind] = interpolator(point_grid) + + new_grid['handled'][point_ind] = True + + mylog.info("Finished with %s dangling points", + new_grid['handled'].size - new_grid['handled'].sum()) + + return new_grid + +""" +# The following will work to plot through different slices: + +import pylab +for i in range(n_theta): + print "Doing % 3i / % 3i" % (i, n_theta) + pylab.clf() + ax=pylab.subplot(1,1,1, projection="polar", aspect=1.) + ax.pcolormesh(phi[:,i,:], r[:,i,:], + na.log10(sph_grid[field][:,i,:])) + pylab.savefig("polar/latitude_%03i.png" % i) + +for i in range(n_phi): + print "Doing % 3i / % 3i" % (i, n_phi) + pylab.clf() + ax=pylab.subplot(1,1,1, projection="polar", aspect=1.) + ax.pcolormesh(theta[:,:,i], r[:,:,i], + na.log10(sph_grid[field][:,:,i])) + pylab.savefig("polar/longitude_%03i.png" % i) +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,44 @@ +""" +API for halo_finding + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from halo_objects import \ + Halo, \ + HOPHalo, \ + parallelHOPHalo, \ + FOFHalo, \ + HaloList, \ + HOPHaloList, \ + FOFHaloList, \ + parallelHOPHaloList, \ + GenericHaloFinder, \ + parallelHF, \ + HOPHaloFinder, \ + FOFHaloFinder, \ + HaloFinder diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/EnzoFOF.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/EnzoFOF.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,203 @@ +/************************************************************************ +* Copyright (C) 2008-2009 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 . +* +************************************************************************/ + +// +// EnzoFOF +// A module for running friends-of-friends halo finding on a set of particles +// + +#include "Python.h" +#include +#include +#include +#include +#include "kd.h" +#include "tipsydefs.h" + +#include "numpy/ndarrayobject.h" + + +static PyObject *_FOFerror; + +static PyObject * +Py_EnzoFOF(PyObject *obj, PyObject *args) +{ + PyObject *oxpos, *oypos, *ozpos; + + PyArrayObject *xpos, *ypos, *zpos; + xpos=ypos=zpos=NULL; + float link = 0.2; + + int i; + + if (!PyArg_ParseTuple(args, "OOO|f", + &oxpos, &oypos, &ozpos, &link)) + return PyErr_Format(_FOFerror, + "EnzoFOF: Invalid parameters."); + + /* First the regular source arrays */ + + xpos = (PyArrayObject *) PyArray_FromAny(oxpos, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if(!xpos){ + PyErr_Format(_FOFerror, + "EnzoFOF: xpos didn't work."); + goto _fail; + } + int num_particles = PyArray_SIZE(xpos); + + ypos = (PyArrayObject *) PyArray_FromAny(oypos, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if((!ypos)||(PyArray_SIZE(ypos) != num_particles)) { + PyErr_Format(_FOFerror, + "EnzoFOF: xpos and ypos must be the same length."); + goto _fail; + } + + zpos = (PyArrayObject *) PyArray_FromAny(ozpos, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if((!zpos)||(PyArray_SIZE(zpos) != num_particles)) { + PyErr_Format(_FOFerror, + "EnzoFOF: xpos and zpos must be the same length."); + goto _fail; + } + + /* let's get started with the FOF stuff */ + + KDFOF kd; + int nBucket,j; + float fPeriod[3],fEps; + int nMembers,nGroup,bVerbose=1; + int sec,usec; + + /* linking length */ + fprintf(stdout, "Link length is %f\n", link); + fEps = link; + + nBucket = 16; + nMembers = 8; + + for (j=0;j<3;++j) fPeriod[j] = 1.0; + + /* initialize the kd FOF structure */ + + kdInitFoF(&kd,nBucket,fPeriod); + + /* kdReadTipsyFoF(kd,stdin,bDark,bGas,bStar); */ + + /* Copy positions into kd structure. */ + + fprintf(stdout, "Filling in %d particles\n", num_particles); + kd->nActive = num_particles; + kd->p = (PARTICLEFOF *)malloc(kd->nActive*sizeof(PARTICLEFOF)); + assert(kd->p != NULL); + for (i = 0; i < num_particles; i++) { + kd->p[i].iOrder = i; + kd->p[i].r[0] = (float)(*(npy_float64*) PyArray_GETPTR1(xpos, i)); + kd->p[i].r[1] = (float)(*(npy_float64*) PyArray_GETPTR1(ypos, i)); + kd->p[i].r[2] = (float)(*(npy_float64*) PyArray_GETPTR1(zpos, i)); + } + + kdBuildTreeFoF(kd); + kdTimeFoF(kd,&sec,&usec); + nGroup = kdFoF(kd,fEps); + kdTimeFoF(kd,&sec,&usec); + if (bVerbose) printf("Number of initial groups:%d\n",nGroup); + nGroup = kdTooSmallFoF(kd,nMembers); + if (bVerbose) { + printf("Number of groups:%d\n",nGroup); + printf("FOF CPU TIME: %d.%06d secs\n",sec,usec); + } + kdOrderFoF(kd); + + /* kdOutGroupFoF(kd,ach); */ + + // Now we need to get the groupID, realID. + // This will give us the index into the original array. + // Additionally, note that we don't really need to tie the index + // back to the ID in this code, as we can do that back in the python code. + // All we need to do is group information. + + // Tags are in kd->p[i].iGroup + PyArrayObject *particle_group_id = (PyArrayObject *) + PyArray_SimpleNewFromDescr(1, PyArray_DIMS(xpos), + PyArray_DescrFromType(NPY_INT32)); + + for (i = 0; i < num_particles; i++) { + // group tag is in kd->p[i].iGroup + *(npy_int32*)(PyArray_GETPTR1(particle_group_id, i)) = + (npy_int32) kd->p[i].iGroup; + } + + kdFinishFoF(kd); + + PyArray_UpdateFlags(particle_group_id, NPY_OWNDATA | particle_group_id->flags); + PyObject *return_value = Py_BuildValue("N", particle_group_id); + + Py_DECREF(xpos); + Py_DECREF(ypos); + Py_DECREF(zpos); + + /* We don't need this, as it's done in kdFinish + if(kd->p!=NULL)free(kd->p); + */ + + return return_value; + +_fail: + Py_XDECREF(xpos); + Py_XDECREF(ypos); + Py_XDECREF(zpos); + + if(kd->p!=NULL)free(kd->p); + + return NULL; + +} + +static PyMethodDef _FOFMethods[] = { + {"RunFOF", Py_EnzoFOF, METH_VARARGS}, + {NULL, NULL} /* Sentinel */ +}; + +/* platform independent*/ +#ifdef MS_WIN32 +__declspec(dllexport) +#endif + +void initEnzoFOF(void) +{ + PyObject *m, *d; + m = Py_InitModule("EnzoFOF", _FOFMethods); + d = PyModule_GetDict(m); + _FOFerror = PyErr_NewException("EnzoFOF.FOFerror", NULL, NULL); + PyDict_SetItemString(d, "error", _FOFerror); + import_array(); +} + +/* + * Local Variables: + * mode: C + * c-file-style: "python" + * End: + */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/README Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,34 @@ + + + FOF v1.1 + + A Group Finder for N-body Simulations + + October 26, 1994 + +Changes from v1.0: + o Fixed bug in tree building, this bug only affected cases where + a very small "bucket" size was chosen and the number of particles + was not a power of two. + +Included are: + README + Makefile + cat1/fof.1 + kd.c + kd.h + main.c + man1/fof.1 + tipsydefs.h + +For detailed information read the man page (either cat1/fof.1 or +man1/fof.1). + +To build: + + > make + +To get further information contact: + + hpccsoft@astro.washington.edu + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/fof_main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/fof_main.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#include +#include "kd.h" + + +void usage(void) +{ + fprintf(stderr,"USAGE:\n"); + fprintf(stderr,"fof -e \n"); + fprintf(stderr," [-m ] [-dgs] [-v]\n"); + fprintf(stderr," [-o ] [-p ]\n"); + fprintf(stderr," [-px ] [-py ] [-pz ]\n"); + fprintf(stderr,"Input taken from stdin in tipsy binary format.\n"); + fprintf(stderr,"SEE MAN PAGE: fof(1) for more information.\n"); + exit(1); + } + +void main(int argc,char **argv) +{ + KDFOF kd; + int nBucket,i,j; + char ach[80]; + float fPeriod[3],fEps; + int bDark,bGas,bStar; + int nMembers,nGroup,bVerbose; + int sec,usec; + char *p; + + nBucket = 16; + nMembers = 8; + bDark = 1; + bGas = 1; + bStar = 1; + bVerbose = 0; + strcpy(ach,"fof"); + i = 1; + for (j=0;j<3;++j) fPeriod[j] = HUGE; + while (i < argc) { + if (!strcmp(argv[i],"-e")) { + ++i; + fEps = atof(argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-m")) { + ++i; + nMembers = atoi(argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-o")) { + ++i; + strcpy(ach,argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-p")) { + ++i; + fPeriod[0] = atof(argv[i]); + fPeriod[1] = atof(argv[i]); + fPeriod[2] = atof(argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-px")) { + ++i; + fPeriod[0] = atof(argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-py")) { + ++i; + fPeriod[1] = atof(argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-pz")) { + ++i; + fPeriod[2] = atof(argv[i]); + ++i; + } + else if (!strcmp(argv[i],"-v")) { + bVerbose = 1; + ++i; + } + else if (*argv[i] == '-') { + p = argv[i]; + ++p; + if (*p == 'd' || *p == 'g' || *p == 's') { + bDark = 0; + bGas = 0; + bStar = 0; + } + else usage(); + while (isalpha(*p)) { + switch (*p) { + case 'd': + bDark = 1; + break; + case 'g': + bGas = 1; + break; + case 's': + bStar = 1; + break; + default: + usage(); + } + ++p; + } + ++i; + } + else usage(); + } + kdInitFoF(&kd,nBucket,fPeriod); + kdReadTipsyFoF(kd,stdin,bDark,bGas,bStar); + kdBuildTreeFoF(kd); + kdTimeFoF(kd,&sec,&usec); + nGroup = kdFoF(kd,fEps); + kdTimeFoF(kd,&sec,&usec); + if (bVerbose) printf("Number of initial groups:%d\n",nGroup); + nGroup = kdTooSmallFoF(kd,nMembers); + if (bVerbose) { + printf("Number of groups:%d\n",nGroup); + printf("FOF CPU TIME: %d.%06d secs\n",sec,usec); + } + kdOrderFoF(kd); + strcat(ach,".grp"); + kdOutGroupFoF(kd,ach); + kdFinishFoF(kd); + } + + + + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/kd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/kd.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,444 @@ +#include +#include +#include +#include +#include +#include +#include "kd.h" +#include "tipsydefs.h" + + +void kdTimeFoF(KDFOF kd,int *puSecond,int *puMicro) +{ + struct rusage ru; + + getrusage(0,&ru); + *puMicro = ru.ru_utime.tv_usec - kd->uMicro; + *puSecond = ru.ru_utime.tv_sec - kd->uSecond; + if (*puMicro < 0) { + *puMicro += 1000000; + *puSecond -= 1; + } + kd->uSecond = ru.ru_utime.tv_sec; + kd->uMicro = ru.ru_utime.tv_usec; + } + + +int kdInitFoF(KDFOF *pkd,int nBucket,float *fPeriod) +{ + KDFOF kd; + int j; + + kd = (KDFOF)malloc(sizeof(struct kdContext)); + assert(kd != NULL); + kd->nBucket = nBucket; + for (j=0;j<3;++j) kd->fPeriod[j] = fPeriod[j]; + kd->p = NULL; + kd->kdNodes = NULL; + *pkd = kd; + return(1); + } + + +void kdReadTipsyFoF(KDFOF kd,FILE *fp,int bDark,int bGas,int bStar) +{ + int i,j,nCnt; + struct dump h; + struct gas_particle gp; + struct dark_particle dp; + struct star_particle sp; + + fread(&h,sizeof(struct dump),1,fp); + kd->nParticles = h.nbodies; + kd->nDark = h.ndark; + kd->nGas = h.nsph; + kd->nStar = h.nstar; + kd->fTime = h.time; + kd->nActive = 0; + if (bDark) kd->nActive += kd->nDark; + if (bGas) kd->nActive += kd->nGas; + if (bStar) kd->nActive += kd->nStar; + kd->bDark = bDark; + kd->bGas = bGas; + kd->bStar = bStar; + /* + ** Allocate particles. + */ + kd->p = (PARTICLEFOF *)malloc(kd->nActive*sizeof(PARTICLEFOF)); + assert(kd->p != NULL); + /* + ** Read Stuff! + */ + nCnt = 0; + for (i=0;ip[nCnt].iOrder = nCnt; + for (j=0;j<3;++j) kd->p[nCnt].r[j] = gp.pos[j]; + ++nCnt; + } + } + for (i=0;ip[nCnt].iOrder = nCnt; + for (j=0;j<3;++j) kd->p[nCnt].r[j] = dp.pos[j]; + ++nCnt; + } + } + for (i=0;ip[nCnt].iOrder = nCnt; + for (j=0;j<3;++j) kd->p[nCnt].r[j] = sp.pos[j]; + ++nCnt; + } + } + } + + +void kdSelectFoF(KDFOF kd,int d,int k,int l,int r) +{ + PARTICLEFOF *p,t; + double v; + int i,j; + + p = kd->p; + while (r > l) { + v = p[k].r[d]; + t = p[r]; + p[r] = p[k]; + p[k] = t; + i = l - 1; + j = r; + while (1) { + while (i < j) if (p[++i].r[d] >= v) break; + while (i < j) if (p[--j].r[d] <= v) break; + t = p[i]; + p[i] = p[j]; + p[j] = t; + if (j <= i) break; + } + p[j] = p[i]; + p[i] = p[r]; + p[r] = t; + if (i >= k) r = i - 1; + if (i <= k) l = i + 1; + } + } + + +void kdCombineFoF(KDNFOF *p1,KDNFOF *p2,KDNFOF *pOut) +{ + int j; + + /* + ** Combine the bounds. + */ + for (j=0;j<3;++j) { + if (p2->bnd.fMin[j] < p1->bnd.fMin[j]) + pOut->bnd.fMin[j] = p2->bnd.fMin[j]; + else + pOut->bnd.fMin[j] = p1->bnd.fMin[j]; + if (p2->bnd.fMax[j] > p1->bnd.fMax[j]) + pOut->bnd.fMax[j] = p2->bnd.fMax[j]; + else + pOut->bnd.fMax[j] = p1->bnd.fMax[j]; + } + } + + +void kdUpPassFoF(KDFOF kd,int iCell) +{ + KDNFOF *c; + int l,u,pj,j; + + c = kd->kdNodes; + if (c[iCell].iDim != -1) { + l = LOWERFOF(iCell); + u = UPPERFOF(iCell); + kdUpPassFoF(kd,l); + kdUpPassFoF(kd,u); + kdCombineFoF(&c[l],&c[u],&c[iCell]); + } + else { + l = c[iCell].pLower; + u = c[iCell].pUpper; + for (j=0;j<3;++j) { + c[iCell].bnd.fMin[j] = kd->p[u].r[j]; + c[iCell].bnd.fMax[j] = kd->p[u].r[j]; + } + for (pj=l;pjp[pj].r[j] < c[iCell].bnd.fMin[j]) + c[iCell].bnd.fMin[j] = kd->p[pj].r[j]; + if (kd->p[pj].r[j] > c[iCell].bnd.fMax[j]) + c[iCell].bnd.fMax[j] = kd->p[pj].r[j]; + } + } + } + } + +void kdBuildTreeFoF(KDFOF kd) +{ + int l,n,i,d,m,j,diff; + KDNFOF *c; + BNDFOF bnd; + + n = kd->nActive; + kd->nLevels = 1; + l = 1; + while (n > kd->nBucket) { + n = n>>1; + l = l<<1; + ++kd->nLevels; + } + kd->nSplit = l; + kd->nNodes = l<<1; + if (kd->kdNodes != NULL) free(kd->kdNodes); + kd->kdNodes = (KDNFOF *)malloc(kd->nNodes*sizeof(KDNFOF)); + assert(kd->kdNodes != NULL); + /* + ** Calculate Bounds. + */ + for (j=0;j<3;++j) { + bnd.fMin[j] = kd->p[0].r[j]; + bnd.fMax[j] = kd->p[0].r[j]; + } + for (i=1;inActive;++i) { + for (j=0;j<3;++j) { + if (bnd.fMin[j] > kd->p[i].r[j]) + bnd.fMin[j] = kd->p[i].r[j]; + else if (bnd.fMax[j] < kd->p[i].r[j]) + bnd.fMax[j] = kd->p[i].r[j]; + } + } + /* + ** Set up ROOTFOF node + */ + c = kd->kdNodes; + c[ROOTFOF].pLower = 0; + c[ROOTFOF].pUpper = kd->nActive-1; + c[ROOTFOF].bnd = bnd; + i = ROOTFOF; + while (1) { + assert(c[i].pUpper - c[i].pLower + 1 > 0); + if (i < kd->nSplit && (c[i].pUpper - c[i].pLower) > 0) { + d = 0; + for (j=1;j<3;++j) { + if (c[i].bnd.fMax[j]-c[i].bnd.fMin[j] > + c[i].bnd.fMax[d]-c[i].bnd.fMin[d]) d = j; + } + c[i].iDim = d; + + m = (c[i].pLower + c[i].pUpper)/2; + kdSelectFoF(kd,d,m,c[i].pLower,c[i].pUpper); + + c[i].fSplit = kd->p[m].r[d]; + c[LOWERFOF(i)].bnd = c[i].bnd; + c[LOWERFOF(i)].bnd.fMax[d] = c[i].fSplit; + c[LOWERFOF(i)].pLower = c[i].pLower; + c[LOWERFOF(i)].pUpper = m; + c[UPPERFOF(i)].bnd = c[i].bnd; + c[UPPERFOF(i)].bnd.fMin[d] = c[i].fSplit; + c[UPPERFOF(i)].pLower = m+1; + c[UPPERFOF(i)].pUpper = c[i].pUpper; + diff = (m-c[i].pLower+1)-(c[i].pUpper-m); + assert(diff == 0 || diff == 1); + i = LOWERFOF(i); + } + else { + c[i].iDim = -1; + SETNEXTFOF(i); + if (i == ROOTFOF) break; + } + } + kdUpPassFoF(kd,ROOTFOF); + } + + +int kdFoF(KDFOF kd,float fEps) +{ + PARTICLEFOF *p; + KDNFOF *c; + int pi,pj,pn,cp; + + int iGroup; + + int *Fifo,iHead,iTail,nFifo; + float fEps2; + float dx,dy,dz,x,y,z,lx,ly,lz,sx,sy,sz,fDist2; + + p = kd->p; + c = kd->kdNodes; + lx = kd->fPeriod[0]; + ly = kd->fPeriod[1]; + lz = kd->fPeriod[2]; + fEps2 = fEps*fEps; + for (pn=0;pnnActive;++pn) p[pn].iGroup = 0; + nFifo = kd->nActive; + Fifo = (int *)malloc(nFifo*sizeof(int)); + assert(Fifo != NULL); + iHead = 0; + iTail = 0; + iGroup = 0; + for (pn=0;pnnActive;++pn) { + if (p[pn].iGroup) continue; + ++iGroup; + /* + ** Mark it and add to the do-fifo. + */ + p[pn].iGroup = iGroup; + Fifo[iTail++] = pn; + if (iTail == nFifo) iTail = 0; + while (iHead != iTail) { + pi = Fifo[iHead++]; + if (iHead == nFifo) iHead = 0; + /* + ** Now do an fEps-Ball Gather! + */ + x = p[pi].r[0]; + y = p[pi].r[1]; + z = p[pi].r[2]; + cp = ROOTFOF; + while (1) { + INTERSECTFOF(c,cp,fEps2,lx,ly,lz,x,y,z,sx,sy,sz); + /* + ** We have an intersection to test. + */ + if (c[cp].iDim >= 0) { + cp = LOWERFOF(cp); + continue; + } + else { + for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { + if (p[pj].iGroup) continue; + dx = sx - p[pj].r[0]; + dy = sy - p[pj].r[1]; + dz = sz - p[pj].r[2]; + fDist2 = dx*dx + dy*dy + dz*dz; + if (fDist2 < fEps2) { + /* + ** Mark it and add to the do-fifo. + */ + p[pj].iGroup = iGroup; + Fifo[iTail++] = pj; + if (iTail == nFifo) iTail = 0; + } + } + SETNEXTFOF(cp); + if (cp == ROOTFOF) break; + continue; + } + ContainedCell: + for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { + if (p[pj].iGroup) continue; + /* + ** Mark it and add to the do-fifo. + */ + p[pj].iGroup = iGroup; + Fifo[iTail++] = pj; + if (iTail == nFifo) iTail = 0; + } + GetNextCell: + SETNEXTFOF(cp); + if (cp == ROOTFOF) break; + } + } + } + free(Fifo); + kd->nGroup = iGroup+1; + return(kd->nGroup-1); + } + + +int kdTooSmallFoF(KDFOF kd,int nMembers) +{ + int *pnMembers,*pMap; + int i,pi,nGroup; + + pnMembers = (int *)malloc(kd->nGroup*sizeof(int)); + assert(pnMembers != NULL); + pMap = (int *)malloc(kd->nGroup*sizeof(int)); + assert(pMap != NULL); + for (i=0;inGroup;++i) pnMembers[i] = 0; + for (pi=0;pinActive;++pi) { + ++pnMembers[kd->p[pi].iGroup]; + } + for (i=1;inGroup;++i) { + if (pnMembers[i] < nMembers) { + pnMembers[i] = 0; + } + } + /* + ** Create a remapping! + */ + pMap[0] = 0; + nGroup = 1; + for (i=1;inGroup;++i) { + pMap[i] = nGroup; + if (pnMembers[i] == 0) { + pMap[i] = -1; /* was 0 */ + } + else { + ++nGroup; + } + } + /* + ** Remap the groups. + */ + for (pi=0;pinActive;++pi) { + kd->p[pi].iGroup = pMap[kd->p[pi].iGroup]; + } + free(pMap); + free(pnMembers); + kd->nGroup = nGroup; + return(nGroup-1); + } + + +int CmpParticlesFoF(const void *v1,const void *v2) +{ + PARTICLEFOF *p1 = (PARTICLEFOF *)v1; + PARTICLEFOF *p2 = (PARTICLEFOF *)v2; + return(p1->iOrder - p2->iOrder); + } + +void kdOrderFoF(KDFOF kd) +{ + qsort(kd->p,kd->nActive,sizeof(PARTICLEFOF),CmpParticlesFoF); + } + + +void kdOutGroupFoF(KDFOF kd,char *pszFile) +{ + FILE *fp; + int i,iCnt; + + fp = fopen(pszFile,"w"); + assert(fp != NULL); + fprintf(fp,"%d\n",kd->nParticles); + iCnt = 0; + for (i=0;inGas;++i) { + if (kd->bGas) fprintf(fp,"%d\n",kd->p[iCnt++].iGroup); + else fprintf(fp,"0\n"); + } + for (i=0;inDark;++i) { + if (kd->bDark) fprintf(fp,"%d\n",kd->p[iCnt++].iGroup); + else fprintf(fp,"0\n"); + } + for (i=0;inStar;++i) { + if (kd->bStar) fprintf(fp,"%d\n",kd->p[iCnt++].iGroup); + else fprintf(fp,"0\n"); + } + fclose(fp); + } + + +void kdFinishFoF(KDFOF kd) +{ + free(kd->p); + free(kd->kdNodes); + free(kd); + } + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/kd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/kd.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,203 @@ +#ifndef KDFOF_HINCLUDED +#define KDFOF_HINCLUDED + +#define ROOTFOF 1 +#define LOWERFOF(i) (i<<1) +#define UPPERFOF(i) ((i<<1)+1) +#define PARENTFOF(i) (i>>1) +#define SIBLINGFOF(i) ((i&1)?i-1:i+1) +#define SETNEXTFOF(i)\ +{\ + while (i&1) i=i>>1;\ + ++i;\ + } + +#define DARKFOF 1 +#define GASFOF 2 +#define STARFOF 4 + +#define KDFOF_ORDERTEMP 256 + +typedef struct Particle { + float r[3]; + int iGroup; + int iOrder; + } PARTICLEFOF; + +typedef struct bndBound { + float fMin[3]; + float fMax[3]; + } BNDFOF; + +typedef struct kdNode { + float fSplit; + BNDFOF bnd; + int iDim; + int pLower; + int pUpper; + } KDNFOF; + +typedef struct kdContext { + int nBucket; + int nParticles; + int nDark; + int nGas; + int nStar; + int bDark; + int bGas; + int bStar; + int nActive; + float fTime; + float fPeriod[3]; + int nLevels; + int nNodes; + int nSplit; + PARTICLEFOF *p; + KDNFOF *kdNodes; + int nGroup; + int uSecond; + int uMicro; + } * KDFOF; + + +#define INTERSECTFOF(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz)\ +{\ + float dx,dy,dz,dx1,dy1,dz1,fDist2,fMax2;\ + dx = c[cp].bnd.fMin[0]-x;\ + dx1 = x-c[cp].bnd.fMax[0];\ + dy = c[cp].bnd.fMin[1]-y;\ + dy1 = y-c[cp].bnd.fMax[1];\ + dz = c[cp].bnd.fMin[2]-z;\ + dz1 = z-c[cp].bnd.fMax[2];\ + if (dx > 0.0) {\ + if (dx1+lx < dx) {\ + dx1 += lx;\ + dx -= lx;\ + sx = x+lx;\ + fDist2 = dx1*dx1;\ + fMax2 = dx*dx;\ + }\ + else {\ + sx = x;\ + fDist2 = dx*dx;\ + fMax2 = dx1*dx1;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else if (dx1 > 0.0) {\ + if (dx+lx < dx1) {\ + dx += lx;\ + dx1 -= lx;\ + sx = x-lx;\ + fDist2 = dx*dx;\ + fMax2 = dx1*dx1;\ + }\ + else {\ + sx = x;\ + fDist2 = dx1*dx1;\ + fMax2 = dx*dx;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else {\ + sx = x;\ + fDist2 = 0.0;\ + if (dx < dx1) fMax2 = dx*dx;\ + else fMax2 = dx1*dx1;\ + }\ + if (dy > 0.0) {\ + if (dy1+ly < dy) {\ + dy1 += ly;\ + dy -= ly;\ + sy = y+ly;\ + fDist2 += dy1*dy1;\ + fMax2 += dy*dy;\ + }\ + else {\ + sy = y;\ + fDist2 += dy*dy;\ + fMax2 += dy1*dy1;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else if (dy1 > 0.0) {\ + if (dy+ly < dy1) {\ + dy += ly;\ + dy1 -= ly;\ + sy = y-ly;\ + fDist2 += dy*dy;\ + fMax2 += dy1*dy1;\ + }\ + else {\ + sy = y;\ + fDist2 += dy1*dy1;\ + fMax2 += dy*dy;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else {\ + sy = y;\ + if (dy < dy1) fMax2 += dy*dy;\ + else fMax2 += dy1*dy1;\ + }\ + if (dz > 0.0) {\ + if (dz1+lz < dz) {\ + dz1 += lz;\ + dz -= lz;\ + sz = z+lz;\ + fDist2 += dz1*dz1;\ + fMax2 += dz*dz;\ + }\ + else {\ + sz = z;\ + fDist2 += dz*dz;\ + fMax2 += dz1*dz1;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else if (dz1 > 0.0) {\ + if (dz+lz < dz1) {\ + dz += lz;\ + dz1 -= lz;\ + sz = z-lz;\ + fDist2 += dz*dz;\ + fMax2 += dz1*dz1;\ + }\ + else {\ + sz = z;\ + fDist2 += dz1*dz1;\ + fMax2 += dz*dz;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else {\ + sz = z;\ + if (dz < dz1) fMax2 += dz*dz;\ + else fMax2 += dz1*dz1;\ + }\ + if (fMax2 < fBall2) goto ContainedCell;\ + } + + +void kdTimeFoF(KDFOF,int *,int *); +int kdInitFoF(KDFOF *,int,float *); +void kdReadTipsyFoF(KDFOF,FILE *,int,int,int); +void kdBuildTreeFoF(KDFOF); +int kdFoF(KDFOF,float); +int kdTooSmallFoF(KDFOF,int); +void kdOrderFoF(KDFOF); +void kdOutGroupFoF(KDFOF,char *); +void kdFinishFoF(KDFOF); + +#endif + + + + + + + + + + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('fof',parent_package,top_path) + config.add_extension("EnzoFOF", sources= + ["EnzoFOF.c", + "kd.c"], + libraries=["m"]) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/fof/tipsydefs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/fof/tipsydefs.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,46 @@ +#ifndef _TIPSYDEFS_H +#define _TIPSYDEFS_H +#define MAXDIM 3 +#define forever for(;;) + +typedef float Real; + +struct gas_particle { + Real mass; + Real pos[MAXDIM]; + Real vel[MAXDIM]; + Real rho; + Real temp; + Real hsmooth; + Real metals ; + Real phi ; +} ; + +struct dark_particle { + Real mass; + Real pos[MAXDIM]; + Real vel[MAXDIM]; + Real eps; + Real phi ; +} ; + +struct star_particle { + Real mass; + Real pos[MAXDIM]; + Real vel[MAXDIM]; + Real metals ; + Real tform ; + Real eps; + Real phi ; +} ; + +struct dump { + double time ; + int nbodies ; + int ndim ; + int nsph ; + int ndark ; + int nstar ; +} ; + +#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/halo_objects.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/halo_objects.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,1856 @@ +""" +HOP-output data handling + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Author: Stephen Skory +Affiliation: UCSD Physics/CASS +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 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 . +""" + +import gc +import h5py +import itertools +import math +import numpy as na +import random +import sys + +from yt.funcs import * + +from yt.config import ytcfg +from yt.utilities.performance_counters import \ + yt_counters, time_function + +from .hop.EnzoHop import RunHOP +from .fof.EnzoFOF import RunFOF +try: + from parallel_hop.parallel_hop_interface import \ + ParallelHOPHaloFinder +except ImportError: + mylog.debug("Parallel HOP not imported.") + +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelDummy, \ + ParallelAnalysisInterface, \ + parallel_blocking_call + +TINY = 1.e-40 + +class Halo(object): + """ + A data source that returns particle information about the members of a + HOP-identified halo. + """ + __metaclass__ = ParallelDummy # This will proxy up our methods + _distributed = False + _processing = False + _owner = 0 + indices = None + dont_wrap = ["get_sphere", "write_particle_list"] + extra_wrap = ["__getitem__"] + + def __init__(self, halo_list, id, indices = None, size=None, CoM=None, + max_dens_point=None, group_total_mass=None, max_radius=None, bulk_vel=None, + tasks=None, rms_vel=None): + self._max_dens = halo_list._max_dens + self.id = id + self.data = halo_list._data_source + if indices is not None: + self.indices = halo_list._base_indices[indices] + else: + self.indices = None + # We assume that if indices = None, the instantiator has OTHER plans + # for us -- i.e., setting it somehow else + self.size = size + self.CoM = CoM + self.max_dens_point = max_dens_point + self.group_total_mass = group_total_mass + self.max_radius = max_radius + self.bulk_vel = bulk_vel + self.tasks = tasks + self.rms_vel = rms_vel + self.bin_count = None + self.overdensity = None + + def center_of_mass(self): + r"""Calculate and return the center of mass. + + The center of mass of the halo is directly calculated and returned. + + Examples + -------- + >>> com = halos[0].center_of_mass() + """ + c_vec = self.maximum_density_location() - na.array([0.5,0.5,0.5]) + pm = self["ParticleMassMsun"] + cx = (self["particle_position_x"] - c_vec[0]) + cy = (self["particle_position_y"] - c_vec[1]) + cz = (self["particle_position_z"] - c_vec[2]) + com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) + return (com*pm).sum(axis=1)/pm.sum() + c_vec + + def maximum_density(self): + r"""Return the HOP-identified maximum density. Not applicable to + FOF halos. + + Return the HOP-identified maximum density. Not applicable to FOF halos. + + Examples + -------- + >>> max_dens = halos[0].maximum_density() + """ + return self._max_dens[self.id][0] + + def maximum_density_location(self): + r"""Return the location HOP identified as maximally dense. Not + applicable to FOF halos. + + Return the location HOP identified as maximally dense. + + Examples + -------- + >>> max_dens_loc = halos[0].maximum_density_location() + """ + return na.array([ + self._max_dens[self.id][1], + self._max_dens[self.id][2], + self._max_dens[self.id][3]]) + + def total_mass(self): + r"""Returns the total mass in solar masses of the halo. + + Returns the total mass in solar masses of just the particles in the + halo. + + Examples + -------- + >>> halos[0].total_mass() + """ + return self["ParticleMassMsun"].sum() + + def bulk_velocity(self): + r"""Returns the mass-weighted average velocity in cm/s. + + This calculates and returns the mass-weighted average velocity of just + the particles in the halo in cm/s. + + Examples + -------- + >>> bv = halos[0].bulk_velocity() + """ + pm = self["ParticleMassMsun"] + vx = (self["particle_velocity_x"] * pm).sum() + vy = (self["particle_velocity_y"] * pm).sum() + vz = (self["particle_velocity_z"] * pm).sum() + return na.array([vx,vy,vz])/pm.sum() + + def rms_velocity(self): + r"""Returns the mass-weighted RMS velocity for the halo + particles in cgs units. + + Calculate and return the mass-weighted RMS velocity for just the + particles in the halo. The bulk velocity of the halo is subtracted + before computation. + + Examples + -------- + >>> rms_vel = halos[0].rms_velocity() + """ + bv = self.bulk_velocity() + pm = self["ParticleMassMsun"] + sm = pm.sum() + vx = (self["particle_velocity_x"] - bv[0]) * pm/sm + vy = (self["particle_velocity_y"] - bv[1]) * pm/sm + vz = (self["particle_velocity_z"] - bv[2]) * pm/sm + s = vx**2. + vy**2. + vz**2. + ms = na.mean(s) + return na.sqrt(ms) * pm.size + + def maximum_radius(self, center_of_mass=True): + r"""Returns the maximum radius in the halo for all particles, + either from the point of maximum density or from the + center of mass. + + The maximum radius from the most dense point is calculated. This + accounts for periodicity. + + Parameters + ---------- + center_of_mass : bool + True chooses the center of mass when calculating the maximum radius. + False chooses from the maximum density location for HOP halos + (it has no effect for FOF halos). + Default = True. + + Examples + -------- + >>> radius = halos[0].maximum_radius() + """ + if center_of_mass: center = self.center_of_mass() + else: center = self.maximum_density_location() + rx = na.abs(self["particle_position_x"]-center[0]) + ry = na.abs(self["particle_position_y"]-center[1]) + rz = na.abs(self["particle_position_z"]-center[2]) + DW = self.data.pf.domain_right_edge - self.data.pf.domain_left_edge + r = na.sqrt(na.minimum(rx, DW[0]-rx)**2.0 + + na.minimum(ry, DW[1]-ry)**2.0 + + na.minimum(rz, DW[2]-rz)**2.0) + return r.max() + + def __getitem__(self, key): + if ytcfg.getboolean("yt","inline") == False: + return self.data[key][self.indices] + else: + return self.data[key][self.indices] + + def get_sphere(self, center_of_mass=True): + r"""Returns a sphere source. + + This will generate a new, empty sphere source centered on this halo, + with the maximum radius of the halo. + + Parameters + ---------- + center_of_mass : bool, optional + True chooses the center of mass when calculating the maximum radius. + False chooses from the maximum density location for HOP halos + (it has no effect for FOF halos). + Default = True. + + Returns + ------- + sphere : `yt.data_objects.api.AMRSphereBase` + The empty data source. + + Examples + -------- + >>> sp = halos[0].get_sphere() + """ + if center_of_mass: center = self.center_of_mass() + else: center = self.maximum_density_location() + radius = self.maximum_radius() + # A bit of a long-reach here... + sphere = self.data.hierarchy.sphere( + center, radius=radius) + return sphere + + def get_size(self): + return self.indices.size + + def write_particle_list(self, handle): + self._processing = True + gn = "Halo%08i" % (self.id) + handle.create_group("/%s" % gn) + for field in ["particle_position_%s" % ax for ax in 'xyz'] \ + + ["particle_velocity_%s" % ax for ax in 'xyz'] \ + + ["particle_index"] + ["ParticleMassMsun"]: + handle.create_dataset("/%s/%s" % (gn, field), data=self[field]) + if 'creation_time' in self.data.pf.h.field_list: + handle.create_dataset("/%s/creation_time" % gn, + data=self['creation_time']) + n = handle["/%s" % gn] + # set attributes on n + self._processing = False + + def virial_mass(self, virial_overdensity=200., bins=300): + r"""Return the virial mass of the halo in Msun, using only the particles + in the halo (no baryonic information used). + + The virial mass is calculated, using the built in `Halo.virial_info` + functionality. The mass is then returned. + + Parameters + ---------- + virial_overdensity : float + The overdensity threshold compared to the universal average when + calculating the virial mass. Default = 200. + bins : int + The number of spherical bins used to calculate overdensities. + Default = 300. + + Returns + ------- + mass : float + The virial mass in solar masses of the particles in the halo. -1 + if not virialized. + + Examples + -------- + >>> vm = halos[0].virial_mass() + """ + self.virial_info(bins=bins) + vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) + if vir_bin != -1: + return self.mass_bins[vir_bin] + else: + return -1 + + + def virial_radius(self, virial_overdensity=200., bins=300): + r"""Return the virial radius of the halo in code units. + + The virial radius of the halo is calculated, using only the particles + in the halo (no baryonic information used). Returns -1 if the halo is + not virialized. + + Parameters + ---------- + virial_overdensity : float + The overdensity threshold compared to the universal average when + calculating the virial radius. Default = 200. + bins : integer + The number of spherical bins used to calculate overdensities. + Default = 300. + + Returns + ------- + radius : float + The virial raius in code units of the particles in the halo. -1 + if not virialized. + + Examples + -------- + >>> vr = halos[0].virial_radius() + """ + self.virial_info(bins=bins) + vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) + if vir_bin != -1: + return self.radial_bins[vir_bin] + else: + return -1 + + def virial_bin(self, virial_overdensity=200., bins=300): + r"""Returns the bin index of the virial radius of the halo. Generally, + it is better to call virial_radius instead, which calls this function + automatically. + """ + self.virial_info(bins=bins) + over = (self.overdensity > virial_overdensity) + if (over == True).any(): + vir_bin = max(na.arange(bins+1)[over]) + return vir_bin + else: + return -1 + + def virial_info(self, bins=300): + r"""Calculates the virial information for the halo. Generally, it is + better to call virial_radius or virial_mass instead, which calls this + function automatically. + """ + # Skip if we've already calculated for this number of bins. + if self.bin_count == bins and self.overdensity is not None: + return None + self.bin_count = bins + # Cosmology + h = self.data.pf.hubble_constant + Om_matter = self.data.pf.omega_matter + z = self.data.pf.current_redshift + rho_crit_now = 1.8788e-29 * h**2.0 * Om_matter # g cm^-3 + Msun2g = 1.989e33 + rho_crit = rho_crit_now * ((1.0 + z)**3.0) + + # Get some pertinent information about the halo. + self.mass_bins = na.zeros(self.bin_count+1, dtype='float64') + dist = na.empty(self.indices.size, dtype='float64') + cen = self.center_of_mass() + period = self.data.pf.domain_right_edge - \ + self.data.pf.domain_left_edge + mark = 0 + # Find the distances to the particles. I don't like this much, but I + # can't see a way to eliminate a loop like this, either here or in + # yt.math. + for pos in izip(self["particle_position_x"], self["particle_position_y"], + self["particle_position_z"]): + dist[mark] = periodic_dist(cen, pos, period) + mark += 1 + # Set up the radial bins. + # Multiply min and max to prevent issues with digitize below. + self.radial_bins = na.logspace(math.log10(min(dist)*.99 + TINY), + math.log10(max(dist)*1.01 + 2*TINY), num=self.bin_count+1) + # Find out which bin each particle goes into, and add the particle + # mass to that bin. + inds = na.digitize(dist, self.radial_bins) - 1 + if self["particle_position_x"].size > 1: + for index in na.unique(inds): + self.mass_bins[index] += sum(self["ParticleMassMsun"][inds==index]) + # Now forward sum the masses in the bins. + for i in xrange(self.bin_count): + self.mass_bins[i+1] += self.mass_bins[i] + # Calculate the over densities in the bins. + self.overdensity = self.mass_bins * Msun2g / \ + (4./3. * math.pi * rho_crit * \ + (self.radial_bins * self.data.pf["cm"])**3.0) + + +class HOPHalo(Halo): + pass + +class parallelHOPHalo(Halo,ParallelAnalysisInterface): + dont_wrap = ["maximum_density","maximum_density_location", + "center_of_mass","total_mass","bulk_velocity","maximum_radius", + "get_size","get_sphere", "write_particle_list","__getitem__", + "virial_info", "virial_bin", "virial_mass", "virial_radius", + "rms_velocity"] + + def maximum_density(self): + r"""Return the HOP-identified maximum density. + + Return the HOP-identified maximum density. + + Examples + -------- + >>> max_dens = halos[0].maximum_density() + """ + if self.max_dens_point is not None: + return self.max_dens_point[0] + max = self._mpi_allmax(self._max_dens[self.id][0]) + return max + + def maximum_density_location(self): + r"""Return the location HOP identified as maximally dense. + + Return the location HOP identified as maximally dense. + + Examples + -------- + >>> max_dens_loc = halos[0].maximum_density_location() + """ + if self.max_dens_point is not None: + return self.max_dens_point[1:] + # If I own the maximum density, my location is globally correct. + max_dens = self.maximum_density() + if self._max_dens[self.id][0] == max_dens: + value = na.array([ + self._max_dens[self.id][1], + self._max_dens[self.id][2], + self._max_dens[self.id][3]]) + else: + value = na.array([0,0,0]) + # This works, and isn't appropriate but for now will be fine... + value = self._mpi_allsum(value) + return value + + def center_of_mass(self): + r"""Calculate and return the center of mass. + + The center of mass of the halo is directly calculated and returned. + + Examples + -------- + >>> com = halos[0].center_of_mass() + """ + # If it's precomputed, we save time! + if self.CoM is not None: + return self.CoM + # This need to be called by all tasks, but not all will end up using + # it. + c_vec = self.maximum_density_location() - na.array([0.5,0.5,0.5]) + if self.indices is not None: + pm = self["ParticleMassMsun"] + cx = (self["particle_position_x"] - c_vec[0]) + cy = (self["particle_position_y"] - c_vec[1]) + cz = (self["particle_position_z"] - c_vec[2]) + com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) + my_mass = pm.sum() + my_com = ((com*pm).sum(axis=1)/my_mass + c_vec) * my_mass + else: + my_mass = 0. + my_com = na.array([0.,0.,0.]) + global_mass = self._mpi_allsum(my_mass) + global_com = self._mpi_allsum(my_com) + return global_com / global_mass + + def total_mass(self): + r"""Returns the total mass in solar masses of the halo. + + Returns the total mass in solar masses of just the particles in the + halo. + + Examples + -------- + >>> halos[0].total_mass() + """ + if self.group_total_mass is not None: + return self.group_total_mass + if self.indices is not None: + my_mass = self["ParticleMassMsun"].sum() + else: + my_mass = 0. + global_mass = self._mpi_allsum(float(my_mass)) + return global_mass + + def bulk_velocity(self): + r"""Returns the mass-weighted average velocity in cm/s. + + This calculates and returns the mass-weighted average velocity of just + the particles in the halo in cm/s. + + Examples + -------- + >>> bv = halos[0].bulk_velocity() + """ + if self.bulk_vel is not None: + return self.bulk_vel + # Unf. this cannot be reasonably computed inside of parallelHOP because + # we don't pass velocities in. + if self.indices is not None: + pm = self["ParticleMassMsun"] + vx = (self["particle_velocity_x"] * pm).sum() + vy = (self["particle_velocity_y"] * pm).sum() + vz = (self["particle_velocity_z"] * pm).sum() + pm = pm.sum() + else: + pm = 0. + vx = 0. + vy = 0. + vz = 0. + bv = na.array([vx,vy,vz,pm]) + global_bv = self._mpi_allsum(bv) + return global_bv[:3]/global_bv[3] + + def rms_velocity(self): + r"""Returns the mass-weighted RMS velocity for the halo + particles in cgs units. + + Calculate and return the mass-weighted RMS velocity for just the + particles in the halo. The bulk velocity of the halo is subtracted + before computation. + + Examples + -------- + >>> rms_vel = halos[0].rms_velocity() + """ + if self.rms_vel is not None: + return self.rms_vel + bv = self.bulk_velocity() + pm = self["ParticleMassMsun"] + sm = pm.sum() + if self.indices is not None: + vx = (self["particle_velocity_x"] - bv[0]) * pm/sm + vy = (self["particle_velocity_y"] - bv[1]) * pm/sm + vz = (self["particle_velocity_z"] - bv[2]) * pm/sm + s = vx**2 + vy**2 + vz**2 + s = na.sum(s) + size = vx.size + ss = na.array([s, float(size)]) + else: + ss = na.array([0.,0.]) + global_ss = self._mpi_allsum(ss) + ms = global_ss[0] / global_ss[1] + return na.sqrt(ms) * global_ss[1] + + def maximum_radius(self, center_of_mass=True): + r"""Returns the maximum radius in the halo for all particles, + either from the point of maximum density or from the + center of mass. + + The maximum radius from the most dense point is calculated. This + accounts for periodicity. + + Parameters + ---------- + center_of_mass : bool + True chooses the center of mass when calculating the maximum radius. + False chooses from the maximum density location for HOP halos + (it has no effect for FOF halos). + Default = True. + + Examples + -------- + >>> radius = halos[0].maximum_radius() + """ + if self.max_radius is not None: + return self.max_radius + if center_of_mass: center = self.center_of_mass() + else: center = self.maximum_density_location() + DW = self.data.pf.domain_right_edge - self.data.pf.domain_left_edge + if self.indices is not None: + rx = na.abs(self["particle_position_x"]-center[0]) + ry = na.abs(self["particle_position_y"]-center[1]) + rz = na.abs(self["particle_position_z"]-center[2]) + r = na.sqrt(na.minimum(rx, DW[0]-rx)**2.0 + + na.minimum(ry, DW[1]-ry)**2.0 + + na.minimum(rz, DW[2]-rz)**2.0) + my_max = r.max() + + else: + my_max = 0. + return self._mpi_allmax(my_max) + + def get_size(self): + if self.size is not None: + return self.size + if self.indices is not None: + my_size = self.indices.size + else: + my_size = 0 + global_size = self._mpi_allsum(my_size) + return global_size + + def __getitem__(self, key): + if ytcfg.getboolean("yt","inline") == False: + return self.data[key][self.indices] + else: + return self.data[key][self.indices] + + def virial_mass(self, virial_overdensity=200., bins=300): + r"""Return the virial mass of the halo in Msun, using only the particles + in the halo (no baryonic information used). + + The virial mass is calculated, using the built in `Halo.virial_info` + functionality. The mass is then returned. + + Parameters + ---------- + virial_overdensity : float + The overdensity threshold compared to the universal average when + calculating the virial mass. Default = 200. + bins : int + The number of spherical bins used to calculate overdensities. + Default = 300. + + Returns + ------- + mass : float + The virial mass in solar masses of the particles in the halo. -1 + if not virialized. + + Examples + -------- + >>> vm = halos[0].virial_mass() + """ + self.virial_info(bins=bins) + vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) + if vir_bin != -1: + return self.mass_bins[vir_bin] + else: + return -1 + + + def virial_radius(self, virial_overdensity=200., bins=300): + r"""Return the virial radius of the halo in code units. + + The virial radius of the halo is calculated, using only the particles + in the halo (no baryonic information used). Returns -1 if the halo is + not virialized. + + Parameters + ---------- + virial_overdensity : float + The overdensity threshold compared to the universal average when + calculating the virial radius. Default = 200. + bins : integer + The number of spherical bins used to calculate overdensities. + Default = 300. + + Returns + ------- + radius : float + The virial raius in code units of the particles in the halo. -1 + if not virialized. + + Examples + -------- + >>> vr = halos[0].virial_radius() + """ + self.virial_info(bins=bins) + vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) + if vir_bin != -1: + return self.radial_bins[vir_bin] + else: + return -1 + + def virial_bin(self, virial_overdensity=200., bins=300): + r"""Returns the bin index of the virial radius of the halo. Generally, + it is better to call virial_radius instead, which calls this function + automatically. + """ + self.virial_info(bins=bins) + over = (self.overdensity > virial_overdensity) + if (over == True).any(): + vir_bin = max(na.arange(bins+1)[over]) + return vir_bin + else: + return -1 + + def virial_info(self, bins=300): + r"""Calculates the virial information for the halo. Generally, it is + better to call virial_radius or virial_mass instead, which calls this + function automatically. + """ + # Skip if we've already calculated for this number of bins. + if self.bin_count == bins and self.overdensity is not None: + return None + # Do this for all because all will use it. + self.bin_count = bins + period = self.data.pf.domain_right_edge - \ + self.data.pf.domain_left_edge + self.mass_bins = na.zeros(self.bin_count+1, dtype='float64') + cen = self.center_of_mass() + # Cosmology + h = self.data.pf.hubble_constant + Om_matter = self.data.pf.omega_matter + z = self.data.pf.current_redshift + rho_crit_now = 1.8788e-29 * h**2.0 * Om_matter # g cm^-3 + Msun2g = 1.989e33 + rho_crit = rho_crit_now * ((1.0 + z)**3.0) + # If I own some of this halo operate on the particles. + if self.indices is not None: + # Get some pertinent information about the halo. + dist = na.empty(self.indices.size, dtype='float64') + mark = 0 + # Find the distances to the particles. I don't like this much, but I + # can't see a way to eliminate a loop like this, either here or in + # yt.math. + for pos in izip(self["particle_position_x"], self["particle_position_y"], + self["particle_position_z"]): + dist[mark] = periodic_dist(cen, pos, period) + mark += 1 + dist_min, dist_max = min(dist), max(dist) + # If I don't have this halo, make some dummy values. + else: + dist_min = max(period) + dist_max = 0.0 + # In this parallel case, we're going to find the global dist extrema + # and built identical bins on all tasks. + dist_min = self._mpi_allmin(dist_min) + dist_max = self._mpi_allmax(dist_max) + # Set up the radial bins. + # Multiply min and max to prevent issues with digitize below. + self.radial_bins = na.logspace(math.log10(dist_min*.99 + TINY), + math.log10(dist_max*1.01 + 2*TINY), num=self.bin_count+1) + if self.indices is not None and self.indices.size > 1: + # Find out which bin each particle goes into, and add the particle + # mass to that bin. + inds = na.digitize(dist, self.radial_bins) - 1 + for index in na.unique(inds): + self.mass_bins[index] += sum(self["ParticleMassMsun"][inds==index]) + # Now forward sum the masses in the bins. + for i in xrange(self.bin_count): + self.mass_bins[i+1] += self.mass_bins[i] + # Sum up the mass_bins globally + self.mass_bins = self._mpi_Allsum_double(self.mass_bins) + # Calculate the over densities in the bins. + self.overdensity = self.mass_bins * Msun2g / \ + (4./3. * math.pi * rho_crit * \ + (self.radial_bins * self.data.pf["cm"])**3.0) + + +class FOFHalo(Halo): + + def center_of_mass(self): + r"""Calculate and return the center of mass. + + The center of mass of the halo is directly calculated and returned. + + Examples + -------- + >>> com = halos[0].center_of_mass() + """ + pm = self["ParticleMassMsun"] + cx = self["particle_position_x"] + cy = self["particle_position_y"] + cz = self["particle_position_z"] + c_vec = na.array([cx[0],cy[0],cz[0]]) - na.array([0.5,0.5,0.5]) + cx = cx - c_vec[0] + cy = cy - c_vec[1] + cz = cz - c_vec[2] + com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) + com = (pm * com).sum(axis=1)/pm.sum() + c_vec + return com + + def maximum_density(self): + r"""Not implemented.""" + return -1 + + def maximum_density_location(self): + r"""Not implemented.""" + return self.center_of_mass() + +class HaloList(object): + + _fields = ["particle_position_%s" % ax for ax in 'xyz'] + + def __init__(self, data_source, dm_only = True): + """ + Run hop on *data_source* with a given density *threshold*. If + *dm_only* is set, only run it on the dark matter particles, otherwise + on all particles. Returns an iterable collection of *HopGroup* items. + """ + self._data_source = data_source + self.dm_only = dm_only + self._groups = [] + self._max_dens = {} + self.__obtain_particles() + self._run_finder() + mylog.info("Parsing outputs") + self._parse_output() + mylog.debug("Finished. (%s)", len(self)) + + def __obtain_particles(self): + if self.dm_only: ii = self._get_dm_indices() + else: ii = slice(None) + self.particle_fields = {} + for field in self._fields: + if ytcfg.getboolean("yt","inline") == False: + tot_part = self._data_source[field].size + if field == "particle_index": + self.particle_fields[field] = self._data_source[field][ii].astype('int64') + else: + self.particle_fields[field] = self._data_source[field][ii].astype('float64') + else: + tot_part = self._data_source[field].size + if field == "particle_index": + self.particle_fields[field] = self._data_source[field][ii].astype('int64') + else: + self.particle_fields[field] = self._data_source[field][ii].astype('float64') + self._base_indices = na.arange(tot_part)[ii] + + def _get_dm_indices(self): + if 'creation_time' in self._data_source.hierarchy.field_list: + mylog.debug("Differentiating based on creation time") + return (self._data_source["creation_time"] < 0) + elif 'particle_type' in self._data_source.hierarchy.field_list: + mylog.debug("Differentiating based on particle type") + return (self._data_source["particle_type"] == 1) + else: + mylog.warning("No particle_type, no creation_time, so not distinguishing.") + return slice(None) + + + def _parse_output(self): + unique_ids = na.unique(self.tags) + counts = na.bincount(self.tags+1) + sort_indices = na.argsort(self.tags) + grab_indices = na.indices(self.tags.shape).ravel()[sort_indices] + dens = self.densities[sort_indices] + cp = 0 + for i in unique_ids: + cp_c = cp + counts[i+1] + if i == -1: + cp += counts[i+1] + continue + group_indices = grab_indices[cp:cp_c] + self._groups.append(self._halo_class(self, i, group_indices)) + md_i = na.argmax(dens[cp:cp_c]) + px, py, pz = [self.particle_fields['particle_position_%s'%ax][group_indices] + for ax in 'xyz'] + self._max_dens[i] = (dens[cp:cp_c][md_i], px[md_i], py[md_i], pz[md_i]) + cp += counts[i+1] + + def __len__(self): + return len(self._groups) + + def __iter__(self): + for i in self._groups: yield i + + def __getitem__(self, key): + return self._groups[key] + + def nearest_neighbors_3D(self, haloID, num_neighbors=7, search_radius=.2): + r"""For a halo its nearest neighbors in 3D using the kd tree. + + This will calculate the nearest neighbors of a halo, using the kD tree. + Returns a list of the neighbors distances and ID with format + [distance,haloID]. + + Parameters + ---------- + haloID : integer + The halo to find neighbors for. + num_neighbors : integer + How many neighbors to search for. Default = 7. + search_radius : float + How far away to look for neighbors in code units. Default = 0.2. + + Examples + -------- + >>> neighbors = halos.nearest_neighbors_3D(0) + """ + period = self.pf.domain_right_edge - self.pf.domain_left_edge + # Initialize the dataset of points from all the haloes + dataset = [] + for group in self: + p = Point() + p.data = group.center_of_mass().tolist() + p.haloID = group.id + dataset.append(p) + mylog.info('Building kd tree...') + kd = buildKdHyperRectTree(dataset[:],2*num_neighbors) + # make the neighbors object + neighbors = Neighbors() + neighbors.k = num_neighbors + neighbors.points = [] + neighbors.minDistanceSquared = search_radius * search_radius + mylog.info('Finding nearest neighbors...') + getKNN(self[haloID].center_of_mass().tolist(), kd, neighbors,0., period.tolist()) + # convert the data in order to return something less perverse than a + # Neighbors object, also root the distances + n_points = [] + for n in neighbors.points: + n_points.append([math.sqrt(n[0]),n[1].haloID]) + return n_points + + def nearest_neighbors_2D(self, haloID, num_neighbors=7, search_radius=.2, + proj_dim=0): + r"""For a halo its nearest neighbors in 2D using the kd tree. + + This will strip a dimension from consideration in the kD-tree, and then + calculate all the nearest projected neighbors of a halo. Returns a + list of the neighbors distances and ID with format [distance,haloID]. + + Parameters + ---------- + haloID : int + The halo to find neighbors for. + num_neighbors : int + How many neighbors to search for. Default = 7. + search_radius : float + How far away to look for neighbors in code units. Default = 0.2. + proj_dim : int + Which dimension (0, 1, or 2) to project the halos into 2D. + Default = 0. + + Examples + -------- + >>> neighbors = halos.nearest_neighbors_2D(0) + """ + # Set up a vector to multiply other vectors by to project along proj_dim + vec = na.array([1.,1.,1.]) + vec[proj_dim] = 0. + period = self.pf.domain_right_edge - self.pf.domain_left_edge + period = period * vec + # Initialize the dataset of points from all the haloes + dataset = [] + for group in self: + p = Point() + cm = group.center_of_mass() * vec + p.data = cm.tolist() + p.haloID = group.id + dataset.append(p) + mylog.info('Building kd tree...') + kd = buildKdHyperRectTree(dataset[:],2*num_neighbors) + # make the neighbors object + neighbors = Neighbors() + neighbors.k = num_neighbors + neighbors.points = [] + neighbors.minDistanceSquared = search_radius * search_radius + mylog.info('Finding nearest neighbors...') + cm = self[haloID].center_of_mass() * vec + getKNN(cm.tolist(), kd, neighbors,0., period.tolist()) + # convert the data in order to return something less perverse than a + # Neighbors object, also root the distances + n_points = [] + for n in neighbors.points: + n_points.append([math.sqrt(n[0]),n[1].haloID]) + return n_points + + def write_out(self, filename): + r"""Write out standard halo information to a text file. + + Parameters + ---------- + filename : String + The name of the file to write to. + + Examples + -------- + >>> halos.write_out("HopAnalysis.out") + """ + if hasattr(filename, 'write'): + f = filename + else: + f = open(filename,"w") + f.write("# HALOS FOUND WITH %s\n" % (self._name)) + f.write("\t".join(["# Group","Mass","# part","max dens" + "x","y","z", "center-of-mass", + "x","y","z", + "vx","vy","vz","max_r","rms_v","\n"])) + for group in self: + f.write("%10i\t" % group.id) + f.write("%0.9e\t" % group.total_mass()) + f.write("%10i\t" % group.get_size()) + f.write("%0.9e\t" % group.maximum_density()) + f.write("\t".join(["%0.9e" % v for v in group.maximum_density_location()])) + f.write("\t") + f.write("\t".join(["%0.9e" % v for v in group.center_of_mass()])) + f.write("\t") + f.write("\t".join(["%0.9e" % v for v in group.bulk_velocity()])) + f.write("\t") + f.write("%0.9e\t" % group.maximum_radius()) + f.write("%0.9e\t" % group.rms_velocity()) + f.write("\n") + f.flush() + f.close() + + def write_particle_lists_txt(self, prefix, fp=None): + r"""Write out the names of the HDF5 files containing halo particle data + to a text file. Needed in particular for parallel analysis output. + + Parameters + ---------- + prefix : String + The prefix for the name of the file. + + Examples + -------- + >>> halos.write_particle_lists_txt("halo-parts") + """ + if hasattr(fp, 'write'): + f = fp + else: + f = open("%s.txt" % prefix,"w") + for group in self: + if group.tasks is not None: + fn = "" + for task in group.tasks: + fn += "%s.h5 " % self._get_filename(prefix, rank=task) + elif self._distributed: + fn = "%s.h5" % self._get_filename(prefix, rank=group._owner) + else: + fn = "%s.h5" % self._get_filename(prefix) + gn = "Halo%08i" % (group.id) + f.write("%s %s\n" % (gn, fn)) + f.flush() + f.close() + +class HOPHaloList(HaloList): + + _name = "HOP" + _halo_class = HOPHalo + _fields = ["particle_position_%s" % ax for ax in 'xyz'] + \ + ["ParticleMassMsun"] + + def __init__(self, data_source, threshold=160.0, dm_only=True): + """ + Run hop on *data_source* with a given density *threshold*. If + *dm_only* is set, only run it on the dark matter particles, otherwise + on all particles. Returns an iterable collection of *HopGroup* items. + """ + self.threshold = threshold + mylog.info("Initializing HOP") + HaloList.__init__(self, data_source, dm_only) + + def _run_finder(self): + self.densities, self.tags = \ + RunHOP(self.particle_fields["particle_position_x"], + self.particle_fields["particle_position_y"], + self.particle_fields["particle_position_z"], + self.particle_fields["ParticleMassMsun"], + self.threshold) + self.particle_fields["densities"] = self.densities + self.particle_fields["tags"] = self.tags + + def write_out(self, filename="HopAnalysis.out"): + r"""Write out standard halo information to a text file. + + Parameters + ---------- + filename : String + The name of the file to write to. Default = "HopAnalysis.out". + + Examples + -------- + >>> halos.write_out("HopAnalysis.out") + """ + HaloList.write_out(self, filename) + +class FOFHaloList(HaloList): + _name = "FOF" + _halo_class = FOFHalo + + def __init__(self, data_source, link=0.2, dm_only=True): + self.link = link + mylog.info("Initializing FOF") + HaloList.__init__(self, data_source, dm_only) + + def _run_finder(self): + self.tags = \ + RunFOF(self.particle_fields["particle_position_x"], + self.particle_fields["particle_position_y"], + self.particle_fields["particle_position_z"], + self.link) + self.densities = na.ones(self.tags.size, dtype='float64') * -1 + self.particle_fields["densities"] = self.densities + self.particle_fields["tags"] = self.tags + + def write_out(self, filename="FOFAnalysis.out"): + r"""Write out standard halo information to a text file. + + Parameters + ---------- + filename : String + The name of the file to write to. Default = "FOFAnalysis.out". + + Examples + -------- + >>> halos.write_out("FOFAnalysis.out") + """ + HaloList.write_out(self, filename) + +class parallelHOPHaloList(HaloList,ParallelAnalysisInterface): + _name = "parallelHOP" + _halo_class = parallelHOPHalo + _fields = ["particle_position_%s" % ax for ax in 'xyz'] + \ + ["ParticleMassMsun", "particle_index"] + + def __init__(self, data_source, padding, num_neighbors, bounds, total_mass, + period, threshold=160.0, dm_only=True, rearrange=True, premerge=True): + """ + Run hop on *data_source* with a given density *threshold*. If + *dm_only* is set, only run it on the dark matter particles, otherwise + on all particles. Returns an iterable collection of *HopGroup* items. + """ + self.threshold = threshold + self.num_neighbors = num_neighbors + self.bounds = bounds + self.total_mass = total_mass + self.rearrange = rearrange + self.period = period + self._data_source = data_source + self.premerge = premerge + mylog.info("Initializing HOP") + HaloList.__init__(self, data_source, dm_only) + + def _run_finder(self): + yt_counters("Reading Data") + # Test to make sure the particle IDs aren't suspicious. + exit = False + if (self.particle_fields["particle_index"] < 0).any(): + mylog.error("Negative values in particle_index field. Parallel HOP will fail.") + exit = True + if na.unique(self.particle_fields["particle_index"]).size != \ + self.particle_fields["particle_index"].size: + mylog.error("Non-unique values in particle_index field. Parallel HOP will fail.") + exit = True + self._mpi_exit_test(exit) + obj = ParallelHOPHaloFinder(self.period, self.padding, + self.num_neighbors, self.bounds, + self.particle_fields["particle_position_x"], + self.particle_fields["particle_position_y"], + self.particle_fields["particle_position_z"], + self.particle_fields["particle_index"], + self.particle_fields["ParticleMassMsun"]/self.total_mass, + self.threshold, rearrange=self.rearrange, premerge=self.premerge) + self.densities, self.tags = obj.density, obj.chainID + # I'm going to go ahead and delete self.densities because it's not + # actually being used. I'm not going to remove it altogether because + # it may be useful to someone someday. + del self.densities + self.group_count = obj.group_count + self.group_sizes = obj.group_sizes + if self.group_count == 0: + mylog.info("There are no halos found.") + return + self.CoM = obj.CoM + self.Tot_M = obj.Tot_M * self.total_mass + self.max_dens_point = obj.max_dens_point + self.max_radius = obj.max_radius + # Precompute the bulk velocity in parallel. + yt_counters("Precomp bulk vel.") + self.bulk_vel = na.zeros((self.group_count, 3), dtype='float64') + yt_counters("bulk vel. reading data") + pm = self.particle_fields["ParticleMassMsun"] + if ytcfg.getboolean("yt","inline") == False: + xv = self._data_source["particle_velocity_x"][self._base_indices] + yv = self._data_source["particle_velocity_y"][self._base_indices] + zv = self._data_source["particle_velocity_z"][self._base_indices] + else: + xv = self._data_source["particle_velocity_x"][self._base_indices] + yv = self._data_source["particle_velocity_y"][self._base_indices] + zv = self._data_source["particle_velocity_z"][self._base_indices] + yt_counters("bulk vel. reading data") + yt_counters("bulk vel. computing") + select = (self.tags >= 0) + calc = len(na.where(select == True)[0]) + if calc: + vel = na.empty((calc, 3), dtype='float64') + ms = pm[select] + vel[:,0] = xv[select] * ms + vel[:,1] = yv[select] * ms + vel[:,2] = zv[select] * ms + subchain = self.tags[select] + sort = subchain.argsort() + vel = vel[sort] + sort_subchain = subchain[sort] + uniq_subchain = na.unique(sort_subchain) + diff_subchain = na.ediff1d(sort_subchain) + marks = (diff_subchain > 0) + marks = na.arange(calc)[marks] + 1 + marks = na.concatenate(([0], marks, [calc])) + for i, u in enumerate(uniq_subchain): + self.bulk_vel[u] = na.sum(vel[marks[i]:marks[i+1]], axis=0) + del vel, subchain, sort_subchain + del diff_subchain + # Bring it together, and divide by the previously computed total mass + # of each halo. + self.bulk_vel = self._mpi_Allsum_double(self.bulk_vel) + for groupID in xrange(self.group_count): + self.bulk_vel[groupID] = self.bulk_vel[groupID] / self.Tot_M[groupID] + yt_counters("bulk vel. computing") + # Now calculate the RMS velocity of the groups in parallel, very + # similarly to the bulk velocity and re-using some of the arrays. + yt_counters("rms vel computing") + rms_vel_temp = na.zeros((self.group_count,2), dtype='float64') + if calc: + vel = na.empty((calc, 3), dtype='float64') + vel[:,0] = xv[select] * ms + vel[:,1] = yv[select] * ms + vel[:,2] = zv[select] * ms + vel = vel[sort] + for i, u in enumerate(uniq_subchain): + # This finds the sum locally. + rms_vel_temp[u][0] = na.sum(((vel[marks[i]:marks[i+1]] - \ + self.bulk_vel[u]) / self.Tot_M[u])**2.) + # I could use self.group_sizes... + rms_vel_temp[u][1] = marks[i+1] - marks[i] + del vel, marks, uniq_subchain + # Bring it together. + rms_vel_temp = self._mpi_Allsum_double(rms_vel_temp) + self.rms_vel = na.empty(self.group_count, dtype='float64') + for groupID in xrange(self.group_count): + # Here we do the Mean and the Root. + self.rms_vel[groupID] = \ + na.sqrt(rms_vel_temp[groupID][0] / rms_vel_temp[groupID][1]) * \ + self.group_sizes[groupID] + del rms_vel_temp + yt_counters("rms vel computing") + self.taskID = obj.mine + self.halo_taskmap = obj.halo_taskmap # A defaultdict. + del obj + yt_counters("Precomp bulk vel.") + + def _parse_output(self): + yt_counters("Final Grouping") + """ + Each task will make an entry for all groups, but it may be empty. + """ + unique_ids = na.unique(self.tags) + counts = na.bincount((self.tags+1).tolist()) + sort_indices = na.argsort(self.tags) + grab_indices = na.indices(self.tags.shape).ravel()[sort_indices] + del sort_indices + cp = 0 + index = 0 + # We want arrays for parallel HOP + self._groups = na.empty(self.group_count, dtype='object') + self._max_dens = na.empty((self.group_count, 4), dtype='float64') + if self.group_count == 0: + mylog.info("There are no halos found.") + return + for i in unique_ids: + if i == -1: + cp += counts[i+1] + continue + # If there is a gap in the unique_ids, make empty groups to + # fill it in. + while index < i: + self._groups[index] = self._halo_class(self, index, \ + size=self.group_sizes[index], CoM=self.CoM[index], \ + max_dens_point=self.max_dens_point[index], \ + group_total_mass=self.Tot_M[index], max_radius=self.max_radius[index], + bulk_vel=self.bulk_vel[index], tasks=self.halo_taskmap[index], + rms_vel=self.rms_vel[index]) + # I don't own this halo + self._do_not_claim_object(self._groups[index]) + self._max_dens[index] = [self.max_dens_point[index][0], self.max_dens_point[index][1], \ + self.max_dens_point[index][2], self.max_dens_point[index][3]] + index += 1 + cp_c = cp + counts[i+1] + group_indices = grab_indices[cp:cp_c] + self._groups[index] = self._halo_class(self, i, group_indices, \ + size=self.group_sizes[i], CoM=self.CoM[i], \ + max_dens_point=self.max_dens_point[i], \ + group_total_mass=self.Tot_M[i], max_radius=self.max_radius[i], + bulk_vel=self.bulk_vel[i], tasks=self.halo_taskmap[index], + rms_vel=self.rms_vel[i]) + # This halo may be owned by many, including this task + self._claim_object(self._groups[index]) + self._max_dens[index] = [self.max_dens_point[i][0], self.max_dens_point[i][1], \ + self.max_dens_point[i][2], self.max_dens_point[i][3]] + cp += counts[i+1] + index += 1 + # If there are missing groups at the end, add them. + while index < self.group_count: + self._groups[index] = self._halo_class(self, index, \ + size=self.group_sizes[index], CoM=self.CoM[index], \ + max_dens_point=self.max_dens_point[i], \ + group_total_mass=self.Tot_M[index], max_radius=self.max_radius[index], + bulk_vel=self.bulk_vel[index], tasks=self.halo_taskmap[index], + rms_vel=self.rms_vel[index]) + self._do_not_claim_object(self._groups[index]) + self._max_dens[index] = [self.max_dens_point[index][0], self.max_dens_point[index][1], \ + self.max_dens_point[index][2], self.max_dens_point[index][3]] + index += 1 + # Clean up + del self.max_dens_point, self.max_radius, self.bulk_vel + del self.halo_taskmap, self.tags, self.rms_vel + del grab_indices, unique_ids, counts + try: + del group_indices + except UnboundLocalError: + pass + + def __len__(self): + return self.group_count + + def write_out(self, filename="parallelHopAnalysis.out"): + r"""Write out standard halo information to a text file. + + Parameters + ---------- + filename : String + The name of the file to write to. + Default = "parallelHopAnalysis.out". + + Examples + -------- + >>> halos.write_out("parallelHopAnalysis.out") + """ + HaloList.write_out(self, filename) + +class GenericHaloFinder(HaloList, ParallelAnalysisInterface): + def __init__(self, pf, dm_only=True, padding=0.0): + self.pf = pf + self.hierarchy = pf.h + self.center = (pf.domain_right_edge + pf.domain_left_edge)/2.0 + + def _parse_halolist(self, threshold_adjustment): + groups, max_dens, hi = [], {}, 0 + LE, RE = self.bounds + for halo in self._groups: + this_max_dens = halo.maximum_density_location() + # if the most dense particle is in the box, keep it + if na.all((this_max_dens >= LE) & (this_max_dens <= RE)): + # Now we add the halo information to OURSELVES, taken from the + # self.hop_list + # We need to mock up the HOPHaloList thingie, so we need to set: + # self._max_dens + max_dens_temp = list(self._max_dens[halo.id])[0] / threshold_adjustment + max_dens[hi] = [max_dens_temp] + list(self._max_dens[halo.id])[1:4] + groups.append(self._halo_class(self, hi)) + groups[-1].indices = halo.indices + self._claim_object(groups[-1]) + hi += 1 + del self._groups, self._max_dens # explicit >> implicit + self._groups = groups + self._max_dens = max_dens + + def _join_halolists(self): + # First we get the total number of halos the entire collection + # has identified + # Note I have added a new method here to help us get information + # about processors and ownership and so forth. + # _mpi_info_dict returns a dict of {proc: whatever} where whatever is + # what is fed in on each proc. + mine, halo_info = self._mpi_info_dict(len(self)) + nhalos = sum(halo_info.values()) + # Figure out our offset + my_first_id = sum([v for k,v in halo_info.items() if k < mine]) + # Fix our max_dens + max_dens = {} + for i,m in self._max_dens.items(): max_dens[i+my_first_id] = m + self._max_dens = max_dens + for halo in self._groups: + halo._max_dens = self._max_dens + # sort the list by the size of the groups + # Now we add ghost halos and reassign all the IDs + # Note: we already know which halos we own! + after = my_first_id + len(self._groups) + # One single fake halo, not owned, does the trick + self._groups = [self._halo_class(self, i) for i in range(my_first_id)] + \ + self._groups + \ + [self._halo_class(self, i) for i in range(after, nhalos)] + id = 0 + for proc in sorted(halo_info.keys()): + for halo in self._groups[id:id+halo_info[proc]]: + halo.id = id + halo._distributed = self._distributed + halo._owner = proc + id += 1 + def haloCmp(h1,h2): + c = cmp(h1.total_mass(),h2.total_mass()) + if c != 0: + return -1 * c + if c == 0: + return cmp(h1.center_of_mass()[0],h2.center_of_mass()[0]) + self._groups.sort(haloCmp) + sorted_max_dens = {} + for i, halo in enumerate(self._groups): + if halo.id in self._max_dens: + sorted_max_dens[i] = self._max_dens[halo.id] + halo.id = i + self._max_dens = sorted_max_dens + for i, halo in enumerate(self._groups): + halo._max_dens = self._max_dens + + def _reposition_particles(self, bounds): + # This only does periodicity. We do NOT want to deal with anything + # else. The only reason we even do periodicity is the + LE, RE = bounds + dw = self.pf.domain_right_edge - self.pf.domain_left_edge + for i, ax in enumerate('xyz'): + arr = self._data_source["particle_position_%s" % ax] + arr[arr < LE[i]-self.padding] += dw[i] + arr[arr > RE[i]+self.padding] -= dw[i] + + def write_out(self, filename): + r"""Write out standard halo information to a text file. + + Parameters + ---------- + filename : String + The name of the file to write to. + + Examples + -------- + >>> halos.write_out("HopAnalysis.out") + """ + f = self._write_on_root(filename) + HaloList.write_out(self, f) + + def write_particle_lists_txt(self, prefix): + r"""Write out the names of the HDF5 files containing halo particle data + to a text file. + + This function wirtes out the names of all the HDF5 files that would + contain halo particle data. Only the root processor writes out. + + Parameters + ---------- + prefix : String + The prefix for the name of the file. + + Examples + -------- + >>> halos.write_particle_lists_txt("halo-parts") + """ + f = self._write_on_root("%s.txt" % prefix) + HaloList.write_particle_lists_txt(self, prefix, fp=f) + + @parallel_blocking_call + def write_particle_lists(self, prefix): + r"""Write out the particle data for halos to HDF5 files. + + This function will accept a filename prefix, and for every halo it will + write out an HDF5 file containing the positions, velocities, indices + and masses of the constituent particles. However, if the halo finder + is run in parallel, halos will only be written out on the processors to + which they belong. See `Halo.write_particle_lists_txt` for how to + track these halos globally across files. + + Parameters + ---------- + prefix : String + The prefix for the name(s) of the HDF5 files. + + Examples + -------- + >>> halos.write_particle_lists("halo-parts") + """ + fn = "%s.h5" % self._get_filename(prefix) + f = h5py.File(fn, "w") + for halo in self._groups: + if not self._is_mine(halo): continue + halo.write_particle_list(f) + +class parallelHF(GenericHaloFinder, parallelHOPHaloList): + def __init__(self, pf, threshold=160, dm_only=True, resize=True, rearrange=True,\ + fancy_padding=True, safety=1.5, premerge=True, sample=0.03): + r"""Parallel HOP halo finder. + + Halos are built by: + 1. Calculating a density for each particle based on a smoothing kernel. + 2. Recursively linking particles to other particles from lower density + particles to higher. + 3. Geometrically proximate chains are identified and + 4. merged into final halos following merging rules. + + Lower thresholds generally produce more halos, and the largest halos + become larger. Also, halos become more filamentary and over-connected. + + This is very similar to HOP, but it does not produce precisely the + same halos due to unavoidable numerical differences. + + Skory et al. "Parallel HOP: A Scalable Halo Finder for Massive + Cosmological Data Sets." arXiv (2010) 1001.3411 + + Parameters + ---------- + pf : EnzoStaticOutput object + threshold : float + The density threshold used when building halos. Default = 160.0. + dm_only : bool + If True, only dark matter particles are used when building halos. + Default = False. + resize : bool + Turns load-balancing on or off. Default = True. + rearrange : bool + Turns on faster nearest neighbor searches at the cost of increased + memory usage. Default = True. + fancy_padding : bool + True calculates padding independently for each face of each + subvolume. Default = True. + safety : float + Due to variances in inter-particle spacing in the volume, the + padding may need to be increased above the raw calculation. + This number is multiplied to the calculated padding, and values + >1 increase the padding. Default = 1.5. + premerge : bool + True merges chains in two steps (rather than one with False), which + can speed up halo finding by 25% or more. However, True can result + in small (<<1%) variations in the final halo masses when compared + to False. Default = True. + sample : float + The fraction of the full dataset on which load-balancing is + performed. Default = 0.03. + + Examples + ------- + >>> pf = load("RedshiftOutput0000") + >>> halos = parallelHF(pf) + """ + GenericHaloFinder.__init__(self, pf, dm_only, padding=0.0) + self.padding = 0.0 + self.num_neighbors = 65 + self.safety = safety + self.sample = sample + period = pf.domain_right_edge - pf.domain_left_edge + topbounds = na.array([[0., 0., 0.], period]) + # Cut up the volume evenly initially, with no padding. + padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) + # also get the total mass of particles + yt_counters("Reading Data") + # Adaptive subregions by bisection. + ds_names = ["particle_position_x","particle_position_y","particle_position_z"] + if ytcfg.getboolean("yt","inline") == False and \ + resize and self._mpi_get_size() != 1: + random.seed(self._mpi_get_rank()) + cut_list = self._partition_hierarchy_3d_bisection_list() + root_points = self._subsample_points() + self.bucket_bounds = [] + if self._mpi_get_rank() == 0: + self._recursive_divide(root_points, topbounds, 0, cut_list) + self.bucket_bounds = self._mpi_bcast_pickled(self.bucket_bounds) + my_bounds = self.bucket_bounds[self._mpi_get_rank()] + LE, RE = my_bounds[0], my_bounds[1] + self._data_source = self.hierarchy.region_strict([0.]*3, LE, RE) + # If this isn't parallel, define the region as an AMRRegionStrict so + # particle IO works. + if self._mpi_get_size() == 1: + self._data_source = self.hierarchy.periodic_region_strict([0.5]*3, LE, RE) + # get the average spacing between particles for this region + # The except is for the serial case, where the full box is what we want. + if ytcfg.getboolean("yt","inline") == False: + data = self._data_source["particle_position_x"] + else: + data = self._data_source["particle_position_x"] + try: + l = self._data_source.right_edge - self._data_source.left_edge + except AttributeError: + l = pf.domain_right_edge - pf.domain_left_edge + vol = l[0] * l[1] * l[2] + full_vol = vol + if not fancy_padding: + avg_spacing = (float(vol) / data.size)**(1./3.) + # padding is a function of inter-particle spacing, this is an + # approximation, but it's OK with the safety factor + padding = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing + self.padding = (na.ones(3,dtype='float64')*padding, na.ones(3,dtype='float64')*padding) + mylog.info('padding %s avg_spacing %f vol %f local_parts %d' % \ + (str(self.padding), avg_spacing, vol, data.size)) + # Another approach to padding, perhaps more accurate. + elif fancy_padding and self._distributed: + LE_padding, RE_padding = na.empty(3,dtype='float64'), na.empty(3,dtype='float64') + avg_spacing = (float(vol) / data.size)**(1./3.) + base_padding = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing + for dim in xrange(3): + if ytcfg.getboolean("yt","inline") == False: + data = self._data_source[ds_names[dim]] + else: + data = self._data_source[ds_names[dim]] + num_bins = 1000 + width = self._data_source.right_edge[dim] - self._data_source.left_edge[dim] + area = (self._data_source.right_edge[(dim+1)%3] - self._data_source.left_edge[(dim+1)%3]) * \ + (self._data_source.right_edge[(dim+2)%3] - self._data_source.left_edge[(dim+2)%3]) + bin_width = base_padding + num_bins = int(math.ceil(width / bin_width)) + bins = na.arange(num_bins+1, dtype='float64') * bin_width + self._data_source.left_edge[dim] + counts, bins = na.histogram(data, bins, new=True) + # left side. + start = 0 + count = counts[0] + while count < self.num_neighbors: + start += 1 + count += counts[start] + # Get the avg spacing in just this boundary. + vol = area * (bins[start+1] - bins[0]) + avg_spacing = (float(vol) / count)**(1./3.) + LE_padding[dim] = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing + # right side. + start = -1 + count = counts[-1] + while count < self.num_neighbors: + start -= 1 + count += counts[start] + vol = area * (bins[-1] - bins[start-1]) + avg_spacing = (float(vol) / count)**(1./3.) + RE_padding[dim] = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing + self.padding = (LE_padding, RE_padding) + del bins, counts + mylog.info('fancy_padding %s avg_spacing %f full_vol %f local_parts %d %s' % \ + (str(self.padding), avg_spacing, full_vol, data.size, str(self._data_source))) + # Now we get the full box mass after we have the final composition of + # subvolumes. + if ytcfg.getboolean("yt","inline") == False: + total_mass = self._mpi_allsum((self._data_source["ParticleMassMsun"].astype('float64')).sum()) + else: + total_mass = self._mpi_allsum((self._data_source["ParticleMassMsun"].astype('float64')).sum()) + if not self._distributed: + self.padding = (na.zeros(3,dtype='float64'), na.zeros(3,dtype='float64')) + self.bounds = (LE, RE) + (LE_padding, RE_padding) = self.padding + parallelHOPHaloList.__init__(self, self._data_source, self.padding, \ + self.num_neighbors, self.bounds, total_mass, period, \ + threshold=threshold, dm_only=dm_only, rearrange=rearrange, premerge=premerge) + self._join_halolists() + yt_counters("Final Grouping") + + def _subsample_points(self): + # Read in a random subset of the points in each domain, and then + # collect them on the root task. + xp = self._data_source["particle_position_x"] + n_parts = self._mpi_allsum(xp.size) + local_parts = xp.size + random_points = int(self.sample * n_parts) + # We want to get a representative selection of random particles in + # each subvolume. + adjust = float(local_parts) / ( float(n_parts) / self._mpi_get_size()) + n_random = int(adjust * float(random_points) / self._mpi_get_size()) + mylog.info("Reading in %d random particles." % n_random) + # Get unique random particles. + my_points = na.empty((n_random, 3), dtype='float64') + uni = na.array(random.sample(xrange(xp.size), n_random)) + uni = uni[uni.argsort()] + my_points[:,0] = xp[uni] + del xp + self._data_source.clear_data() + my_points[:,1] = self._data_source["particle_position_y"][uni] + self._data_source.clear_data() + my_points[:,2] = self._data_source["particle_position_z"][uni] + self._data_source.clear_data() + del uni + # Collect them on the root task. + mine, sizes = self._mpi_info_dict(n_random) + if mine == 0: + tot_random = sum(sizes.values()) + root_points = na.empty((tot_random, 3), dtype='float64') + root_points.shape = (1, 3*tot_random) + else: + root_points = na.empty([]) + my_points.shape = (1, n_random*3) + root_points = self._mpi_concatenate_array_on_root_double(my_points[0]) + del my_points + if mine == 0: + root_points.shape = (tot_random, 3) + return root_points + + def _recursive_divide(self, points, bounds, level, cut_list): + dim = cut_list[level][0] + parts = points.shape[0] + num_bins = 1000 + width = bounds[1][dim] - bounds[0][dim] + bin_width = width / num_bins + bins = na.arange(num_bins+1, dtype='float64') * bin_width + bounds[0][dim] + counts, bins = na.histogram(points[:,dim], bins) + # Find the bin that passes the cut points. + midpoints = [bounds[0][dim]] + sum = 0 + bin = 0 + for step in xrange(1,cut_list[level][1]): + while sum < ((parts*step)/cut_list[level][1]): + lastsum = sum + sum += counts[bin] + bin += 1 + # Bin edges + left_edge = bins[bin-1] + right_edge = bins[bin] + # Find a better approx of the midpoint cut line using a linear approx. + a = float(sum - lastsum) / (right_edge - left_edge) + midpoints.append(left_edge + (0.5 - (float(lastsum) / parts / 2)) / a) + midpoints.append(bounds[1][dim]) + + # Split the points & update the bounds. + subpoints = [] + subbounds = [] + for pair in zip(midpoints[:-1],midpoints[1:]): + select = na.bitwise_and(points[:,dim] >= pair[0], + points[:,dim] < pair[1]) + subpoints.append(points[select]) + nb = bounds.copy() + nb[0][dim] = pair[0] + nb[1][dim] = pair[1] + subbounds.append(nb) + # If we're at the maxlevel, make a bucket. Otherwise, recurse down. + maxlevel = len(cut_list) - 1 + for pair in zip(subpoints, subbounds): + if level == maxlevel: + self.bucket_bounds.append(pair[1]) + else: + self._recursive_divide(pair[0], pair[1], level+1, cut_list) + + def _join_halolists(self): + if self.group_count == 0: + mylog.info("There are no halos found.") + return + ms = -self.Tot_M.copy() + del self.Tot_M + Cx = self.CoM[:,0].copy() + sorted = na.lexsort([Cx, ms]) + del Cx, ms + self._groups = self._groups[sorted] + self._max_dens = self._max_dens[sorted] + for i in xrange(self.group_count): + self._groups[i].id = i + del sorted, self.group_sizes, self.CoM + + +class HOPHaloFinder(GenericHaloFinder, HOPHaloList): + def __init__(self, pf, threshold=160, dm_only=True, padding=0.02): + r"""HOP halo finder. + + Halos are built by: + 1. Calculating a density for each particle based on a smoothing kernel. + 2. Recursively linking particles to other particles from lower density + particles to higher. + 3. Geometrically proximate chains are identified and + 4. merged into final halos following merging rules. + + Lower thresholds generally produce more halos, and the largest halos + become larger. Also, halos become more filamentary and over-connected. + + Eisenstein and Hut. "HOP: A New Group-Finding Algorithm for N-Body + Simulations." ApJ (1998) vol. 498 pp. 137-142 + + Parameters + ---------- + pf : EnzoStaticOutput object + threshold : float + The density threshold used when building halos. Default = 160.0. + dm_only : bool + If True, only dark matter particles are used when building halos. + Default = False. + padding : float + When run in parallel, the finder needs to surround each subvolume + with duplicated particles for halo finidng to work. This number + must be no smaller than the radius of the largest halo in the box + in code units. Default = 0.02. + + Examples + ------- + >>> pf = load("RedshiftOutput0000") + >>> halos = HaloFinder(pf) + """ + GenericHaloFinder.__init__(self, pf, dm_only, padding) + + # do it once with no padding so the total_mass is correct (no duplicated particles) + self.padding = 0.0 + padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) + # For scaling the threshold, note that it's a passthrough + if dm_only: + select = self._get_dm_indices() + total_mass = self._mpi_allsum((self._data_source["ParticleMassMsun"][select]).sum()) + else: + total_mass = self._mpi_allsum(self._data_source["ParticleMassMsun"].sum()) + # MJT: Note that instead of this, if we are assuming that the particles + # are all on different processors, we should instead construct an + # object representing the entire domain and sum it "lazily" with + # Derived Quantities. + self.padding = padding #* pf["unitary"] # This should be clevererer + padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) + self.bounds = (LE, RE) + # reflect particles around the periodic boundary + #self._reposition_particles((LE, RE)) + if dm_only: + select = self._get_dm_indices() + sub_mass = self._data_source["ParticleMassMsun"][select].sum() + else: + sub_mass = self._data_source["ParticleMassMsun"].sum() + HOPHaloList.__init__(self, self._data_source, threshold*total_mass/sub_mass, dm_only) + self._parse_halolist(total_mass/sub_mass) + self._join_halolists() + +class FOFHaloFinder(GenericHaloFinder, FOFHaloList): + def __init__(self, pf, link=0.2, dm_only=True, padding=0.02): + r"""Friends-of-friends halo finder. + + Halos are found by linking together all pairs of particles closer than + some distance from each other. Particles may have multiple links, + and halos are found by recursively linking together all such pairs. + + Larger linking lengths produce more halos, and the largest halos + become larger. Also, halos become more filamentary and over-connected. + + Davis et al. "The evolution of large-scale structure in a universe + dominated by cold dark matter." ApJ (1985) vol. 292 pp. 371-394 + + Parameters + ---------- + pf : EnzoStaticOutput object + link : float + The interparticle distance (compared to the overall average) + used to build the halos. Default = 0.2. + dm_only : bool + If True, only dark matter particles are used when building halos. + Default = False. + padding : float + When run in parallel, the finder needs to surround each subvolume + with duplicated particles for halo finidng to work. This number + must be no smaller than the radius of the largest halo in the box + in code units. Default = 0.02. + + Examples + ------- + >>> pf = load("RedshiftOutput0000") + >>> halos = FOFHaloFinder(pf) + """ + self.pf = pf + self.hierarchy = pf.h + self.center = (pf.domain_right_edge + pf.domain_left_edge)/2.0 + self.padding = 0.0 #* pf["unitary"] # This should be clevererer + # get the total number of particles across all procs, with no padding + padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) + n_parts = self._mpi_allsum(self._data_source["particle_position_x"].size) + # get the average spacing between particles + l = pf.domain_right_edge - pf.domain_left_edge + vol = l[0] * l[1] * l[2] + avg_spacing = (float(vol) / n_parts)**(1./3.) + self.padding = padding + padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) + self.bounds = (LE, RE) + # reflect particles around the periodic boundary + #self._reposition_particles((LE, RE)) + # here is where the FOF halo finder is run + FOFHaloList.__init__(self, self._data_source, link * avg_spacing, dm_only) + self._parse_halolist(1.) + self._join_halolists() + +HaloFinder = HOPHaloFinder diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/EnzoHop.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/EnzoHop.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,448 @@ +/************************************************************************ +* Copyright (C) 2008-2009 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 . +* +************************************************************************/ + +// +// EnzoHop +// A module for running HOP halo finding on a set of particles +// + +#include "Python.h" +#include "structmember.h" +#include +#include +#include +#include +#include "kd.h" +#include "hop.h" +#include "hop_numpy.h" + +#include "numpy/ndarrayobject.h" + +void initgrouplist(Grouplist *g); +void hop_main(KD kd, HC *my_comm, float densthres); +void regroup_main(float dens_outer, HC *my_comm); +static PyObject *_HOPerror; + +int convert_particle_arrays( + PyObject *oxpos, PyObject *oypos, PyObject *ozpos, PyObject *omass, + PyArrayObject **xpos, PyArrayObject **ypos, PyArrayObject **zpos, + PyArrayObject **mass) +{ + + /* First the regular source arrays */ + + *xpos = (PyArrayObject *) PyArray_FromAny(oxpos, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if(!*xpos){ + PyErr_Format(_HOPerror, + "EnzoHop: xpos didn't work."); + return -1; + } + int num_particles = PyArray_SIZE(*xpos); + + *ypos = (PyArrayObject *) PyArray_FromAny(oypos, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if((!*ypos)||(PyArray_SIZE(*ypos) != num_particles)) { + PyErr_Format(_HOPerror, + "EnzoHop: xpos and ypos must be the same length."); + return -1; + } + + *zpos = (PyArrayObject *) PyArray_FromAny(ozpos, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if((!*zpos)||(PyArray_SIZE(*zpos) != num_particles)) { + PyErr_Format(_HOPerror, + "EnzoHop: xpos and zpos must be the same length."); + return -1; + } + + *mass = (PyArrayObject *) PyArray_FromAny(omass, + PyArray_DescrFromType(NPY_FLOAT64), 1, 1, + NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); + if((!*mass)||(PyArray_SIZE(*mass) != num_particles)) { + PyErr_Format(_HOPerror, + "EnzoHop: xpos and mass must be the same length."); + return -1; + } + + return num_particles; + +} + + +static PyObject * +Py_EnzoHop(PyObject *obj, PyObject *args) +{ + PyObject *oxpos, *oypos, *ozpos, + *omass; + + PyArrayObject *xpos, *ypos, *zpos, + *mass; + xpos=ypos=zpos=mass=NULL; + npy_float64 totalmass = 0.0; + float normalize_to = 1.0; + float thresh = 160.0; + + int i; + + if (!PyArg_ParseTuple(args, "OOOO|ff", + &oxpos, &oypos, &ozpos, &omass, &thresh, &normalize_to)) + return PyErr_Format(_HOPerror, + "EnzoHop: Invalid parameters."); + + int num_particles = convert_particle_arrays( + oxpos, oypos, ozpos, omass, + &xpos, &ypos, &zpos, &mass); + if (num_particles < 0) goto _fail; + + for(i = 0; i < num_particles; i++) + totalmass+=*(npy_float64*)PyArray_GETPTR1(mass,i); + totalmass /= normalize_to; + + /* initialize the kd hop structure */ + + KD kd; + int nBucket = 16, kdcount = 0; + kdInit(&kd, nBucket); + kd->nActive = num_particles; + kd->p = malloc(sizeof(PARTICLE)*num_particles); + if (kd->p == NULL) { + fprintf(stderr, "failed allocating particles.\n"); + goto _fail; + } + + /* Copy positions into kd structure. */ + PyArrayObject *particle_density = (PyArrayObject *) + PyArray_SimpleNewFromDescr(1, PyArray_DIMS(xpos), + PyArray_DescrFromType(NPY_FLOAT64)); + + fprintf(stdout, "Copying arrays for %d particles\n", num_particles); + kd->np_masses = (npy_float64*) mass->data; + kd->np_pos[0] = (npy_float64*) xpos->data; + kd->np_pos[1] = (npy_float64*) ypos->data; + kd->np_pos[2] = (npy_float64*) zpos->data; + kd->np_densities = (npy_float64*) particle_density->data; + kd->totalmass = totalmass; + for (i = 0; i < num_particles; i++) kd->p[i].np_index = i; + + HC my_comm; + my_comm.s = newslice(); + my_comm.gl = (Grouplist*)malloc(sizeof(Grouplist)); + if(my_comm.gl == NULL) { + fprintf(stderr, "failed allocating Grouplist\n"); + goto _fail; + } + initgrouplist(my_comm.gl); + + fprintf(stderr, "Calling hop... %d %0.3e\n",num_particles,thresh); + hop_main(kd, &my_comm, thresh); + + fprintf(stderr, "Calling regroup...\n"); + regroup_main(thresh, &my_comm); + + // Now we need to get the groupID, realID and the density. + // This will give us the index into the original array. + // Additionally, note that we don't really need to tie the index + // back to the ID in this code, as we can do that back in the python code. + // All we need to do is provide density and group information. + + // Tags (as per writetagsf77) are in gl.s->ntag+1 and there are gl.s->numlist of them. + PyArrayObject *particle_group_id = (PyArrayObject *) + PyArray_SimpleNewFromDescr(1, PyArray_DIMS(xpos), + PyArray_DescrFromType(NPY_INT32)); + + for (i = 0; i < num_particles; i++) { + // tag is in gl.s->ntag[i+1] + *(npy_int32*)(PyArray_GETPTR1(particle_group_id, i)) = + (npy_int32) my_comm.s->ntag[i+1]; + } + + kdFinish(kd); + free(my_comm.gl); + free_slice(my_comm.s); + + PyArray_UpdateFlags(particle_density, NPY_OWNDATA | particle_density->flags); + PyArray_UpdateFlags(particle_group_id, NPY_OWNDATA | particle_group_id->flags); + PyObject *return_value = Py_BuildValue("NN", particle_density, particle_group_id); + + Py_DECREF(xpos); + Py_DECREF(ypos); + Py_DECREF(zpos); + Py_DECREF(mass); + + /* We don't need this, as it's done in kdFinish + if(kd->p!=NULL)free(kd->p); + */ + + return return_value; + +_fail: + Py_XDECREF(xpos); + Py_XDECREF(ypos); + Py_XDECREF(zpos); + Py_XDECREF(mass); + + if(kd->p!=NULL)free(kd->p); + + return NULL; + +} + +static PyMethodDef _HOPMethods[] = { + {"RunHOP", Py_EnzoHop, METH_VARARGS}, + {NULL, NULL} /* Sentinel */ +}; + +/* platform independent*/ +#ifdef MS_WIN32 +__declspec(dllexport) +#endif + +// +// Now a fun wrapper class for the kD-tree +// + +typedef struct { + PyObject_HEAD + KD kd; + PyArrayObject *xpos, *ypos, *zpos; + PyArrayObject *mass, *densities; + int num_particles; +} kDTreeType; + +static int +kDTreeType_init(kDTreeType *self, PyObject *args, PyObject *kwds) +{ + int nBuckets = 16, i; + float normalize_to = 1.0; + static char *kwlist[] = {"xpos", "ypos", "zpos", "mass", + "nbuckets", "norm", NULL}; + PyObject *oxpos, *oypos, *ozpos, + *omass; + self->xpos=self->ypos=self->zpos=self->mass=NULL; + + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOOO|if", kwlist, + &oxpos, &oypos, &ozpos, &omass, + &nBuckets, &normalize_to)) + return -1; /* Should this give an error? */ + + kdInit(&self->kd, nBuckets); + + self->num_particles = convert_particle_arrays( + oxpos, oypos, ozpos, omass, + &self->xpos, &self->ypos, &self->zpos, &self->mass); + + self->kd->nActive = self->num_particles; + self->kd->p = malloc(sizeof(PARTICLE)*self->num_particles); + if (self->kd->p == NULL) { + fprintf(stderr, "failed allocating particles.\n"); + goto _fail; + } + + /* Now we set up our Density array */ + self->densities = (PyArrayObject *) + PyArray_SimpleNewFromDescr(1, PyArray_DIMS(self->xpos), + PyArray_DescrFromType(NPY_FLOAT64)); + + npy_float64 totalmass = 0.0; + for(i= 0; i < self->num_particles; i++) { + self->kd->p[i].np_index = i; + *(npy_float64*)(PyArray_GETPTR1(self->densities, i)) = 0.0; + totalmass+=*(npy_float64*)PyArray_GETPTR1(self->mass,i); + } + totalmass /= normalize_to; + + + self->kd->np_masses = (npy_float64 *)self->mass->data; + self->kd->np_pos[0] = (npy_float64 *)self->xpos->data; + self->kd->np_pos[1] = (npy_float64 *)self->ypos->data; + self->kd->np_pos[2] = (npy_float64 *)self->zpos->data; + self->kd->np_densities = (npy_float64 *)self->densities->data; + self->kd->totalmass = totalmass; + + PrepareKD(self->kd); + kdBuildTree(self->kd); + + return 0; + + _fail: + Py_XDECREF(self->xpos); + Py_XDECREF(self->ypos); + Py_XDECREF(self->zpos); + Py_XDECREF(self->mass); + + if(self->kd->p!=NULL)free(self->kd->p); + + return -1; +} + +static void +kDTreeType_dealloc(kDTreeType *self) +{ + kdFinish(self->kd); + Py_XDECREF(self->xpos); + Py_XDECREF(self->ypos); + Py_XDECREF(self->zpos); + Py_XDECREF(self->mass); + + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject * +kDTreeType_up_pass(kDTreeType *self, PyObject *args) { + int iCell; + + if (!PyArg_ParseTuple(args, "i", &iCell)) + return PyErr_Format(_HOPerror, + "kDTree.up_pass: invalid parameters."); + + if(iCell >= self->num_particles) + return PyErr_Format(_HOPerror, + "kDTree.up_pass: iCell cannot be >= num_particles!"); + + kdUpPass(self->kd, iCell); + return Py_None; +} + +static PyObject * +kDTreeType_median_jst(kDTreeType *self, PyObject *args) { + int d, l, u; + + if (!PyArg_ParseTuple(args, "iii", &d, &l, &u)) + return PyErr_Format(_HOPerror, + "kDTree.median_jst: invalid parameters."); + + if(d >= 3) + return PyErr_Format(_HOPerror, + "kDTree.median_jst: d cannot be >= 3!"); + + if(l >= self->num_particles) + return PyErr_Format(_HOPerror, + "kDTree.median_jst: l cannot be >= num_particles!"); + + if(u >= self->num_particles) + return PyErr_Format(_HOPerror, + "kDTree.median_jst: u cannot be >= num_particles!"); + + int median = kdMedianJst(self->kd, d, l, u); + + PyObject *omedian = PyInt_FromLong((long)median); + return omedian; +} + +static PyMemberDef kDTreeType_members[] = { + { "xpos", T_OBJECT, offsetof(kDTreeType, xpos), 0, + "The xposition array."}, + { "ypos", T_OBJECT, offsetof(kDTreeType, ypos), 0, + "The yposition array."}, + { "zpos", T_OBJECT, offsetof(kDTreeType, zpos), 0, + "The zposition array."}, + { "mass", T_OBJECT, offsetof(kDTreeType, mass), 0, + "The mass array."}, + { "densities", T_OBJECT, offsetof(kDTreeType, densities), 0, + "The density array."}, + { "num_particles", T_INT, offsetof(kDTreeType, num_particles), 0, + "The number of particles"}, + { NULL } +}; + +static PyMethodDef +kDTreeType_methods[] = { + { "up_pass", (PyCFunction) kDTreeType_up_pass, METH_VARARGS, + "Pass up something or another, I'm not really sure."}, + { "median_jst", (PyCFunction) kDTreeType_median_jst, METH_VARARGS, + "Use the JST Median algorithm on two points along a dimension."}, + // typically there would be more here... + + { NULL } +}; + +static PyTypeObject +kDTreeTypeDict = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + "kDTree", /* tp_name */ + sizeof(kDTreeType), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)kDTreeType_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "kDTree object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + kDTreeType_methods, /* tp_methods */ + kDTreeType_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)kDTreeType_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +void initEnzoHop(void) +{ + PyObject *m, *d; + m = Py_InitModule("EnzoHop", _HOPMethods); + d = PyModule_GetDict(m); + _HOPerror = PyErr_NewException("EnzoHop.HOPerror", NULL, NULL); + PyDict_SetItemString(d, "error", _HOPerror); + + kDTreeTypeDict.tp_new = PyType_GenericNew; + if (PyType_Ready(&kDTreeTypeDict) < 0) { + return; + } + + Py_INCREF(&kDTreeTypeDict); + PyModule_AddObject(m, "kDTree", (PyObject*)&kDTreeTypeDict); + + import_array(); +} + +/* + * Local Variables: + * mode: C + * c-file-style: "python" + * End: + */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/README Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,22 @@ +Matthew Turk +May 2008 + +This code (described below) has been modified to be wrapped as a shared library +callable from Python, as a part of the yt toolkit. + +Stephen Skory +May/June 2007 + +This is a new implementation of hop for enzo datasets, to replace the +fragile 'enzohop.' enzohop uses the enzo grid functionality to extract +the particle data from the HDF5 datasets. newhop uses plain HDF5 C++ calls +to extract the data, which is then fed into the hop mechanism. As far as I +know, this version is fine with 64 bit integers/floats, which enzohop isn't. + +There are a few versions of newhop which build on datastar just fine. I +haven't tested it on other machines. The default build 'newhop' is for +packed datasets and will include both stars and dm in the grouping. +THe other versions are for non-packed datasets, or if you want to only +consider dm particles for grouping. Hop doesn't like datasets with too +many particles, (I've never done tests, but I know that 20 million +particles give hop problems) so sometimes dm-only is the only way to go. diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/hop.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/hop.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,36 @@ +#include "slice.h" +//#define free(A) if(A==NULL)fprintf(stderr,"FREEING DOUBLE\n");fprintf(stderr,"Freeing "#A" ("__FILE__":%d)\n",__LINE__);free(A); + +/* ----------------------------------------------------------------------- */ +/* The following structures track all the information about the groups */ + +typedef struct groupstruct { + int npart; /* Number of particles in the group */ + int npartcum; /* Cumulative number of particles */ + int nread; /* Number read so far, also a utility field */ + double compos[3], comvel[3];/* Lists of group CoM position and velocities */ + double comtemp[3]; /* Temporary CoM position */ + int idmerge; /* The new group ID # after merging. Not necessarily + unique! */ + int rootgroup; /* The fully traced group id */ +} Group; /* Type Group is defined */ + +typedef struct groupliststruct { + int npart; /* Number of particles in the simulation */ + int ngroups; /* Number of groups in list */ + int nnewgroups; /* Number of groups after relabeling */ + int npartingroups; /* Number of particles in groups */ + Group *list; /* List of groups, zero-offset */ +} Grouplist; /* Type Grouplist is defined */ + + +typedef struct hopComm { + int ngroups; + int nb; + float *gdensity; + float *g1vec; + float *g2vec; + float *fdensity; + Grouplist *gl; + Slice *s; +} HC; diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/hop_hop.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/hop_hop.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,940 @@ +/* HOP.C -- Daniel Eisenstein, 1997 +Based on a paper by Daniel Eisenstein & Piet Hut, +"HOP: A New Group-Finding Algorithm for N-body Simulations." +See the included documentation or view it at +http://www.sns.ias.edu/~eisenste/hop/hop_doc.html */ + +/* main() was customized from that of SMOOTH v2.0.1, by Joachim Stadel + and the NASA HPCC ESS at the University of Washington Dept. of Astronomy. */ +/* PrepareKD() is a code fragment from the same program. */ +/* ssort() is a C-translation of the Slatec FORTRAN routine of + R.E. Jones and J.A. Wisniewski (SNLA) */ +/* The other routines were written by DJE. */ + +/* Version 1.0 (12/15/97) -- Original Release */ + +#include +#include +#include +#include +#include +#include +#include "kd.h" +#include "hop.h" +#include "smooth.h" +#include "hop_numpy.h" + +//#include "macros_and_parameters.h" +#define ISYM "d" +#define GSYM "g" +#define FSYM "f" + +/* To give info to the user: INFORM("info"); */ +#define INFORM(string) printf(string); fflush(stdout) + +int SnapNumber; + +int ReadSimulationFile(KD, FILE *); + +void smDensityTH(SMX smx,int pi,int nSmooth,int *pList,float *fList); + +void smHop(SMX smx,int pi,int nSmooth,int *pList,float *fList); +void FindGroups(SMX smx); +void SortGroups(SMX smx); + +void MergeGroupsHash(SMX smx); +void smMergeHash(SMX smx,int pi,int nSmooth,int *pList,float *fList); +void ReSizeSMX(SMX smx, int nSmooth); + +void PrepareKD(KD kd); +void binOutHop(SMX smx, HC *my_comm, float densthres); +void outGroupMerge(SMX smx, HC *my_comm); + +/* void main(int argc,char **argv) */ +void hop_main(KD kd, HC *my_comm, float densthres) +{ + /* KD kd; */ + SMX smx; + int nBucket,nSmooth,i,j; + FILE *fp, *fpb; + char ach[80],achFile[80], *inputfile, *densfile; + float fPeriod[3]; + int bDensity,bGroup,bSym,bMerge,nDens,nHop,nMerge,bTopHat; + float fDensThresh; + + nBucket = 16; + nSmooth = 64; + nDens = 64; + nHop = -1; +/* fDensThresh = 3.0; */ + fDensThresh = -1.0; + bDensity = 3; + bGroup = 3; + bMerge = 3; + bSym = 1; + bTopHat = 0; + strcpy(achFile,"output_hop"); + inputfile = NULL; + i = 1; +/* for (j=0;j<3;++j) fPeriod[j] = HUGE; */ + for (j=0;j<3;++j) fPeriod[j] = 1.0; + nMerge = 4; + + + if (nHop<0) nHop=nDens; + if (bDensity==0) nSmooth = nHop+1; + else nSmooth = nDens+1; + /* When smSmooth() is asked for nSmooth particles, it seems to + generally return nSmooth-1 particles, including primary itself. + Hence, when we want nDens or nSmooth particles (including the + primary) we should ask for one more. By convention, I've chosen + to have nMerge reflect the number *not* including the primary, + so in this case we need to ask for two more! */ + + assert(!bMerge || nMergenHop = nHop; + smx->nDens = nDens; + smx->nMerge = nMerge; + smx->nGroups = 0; + smx->fDensThresh = fDensThresh; + + INFORM("Building Tree...\n"); + kdBuildTree(kd); + + if (bDensity) { + INFORM("Finding Densities...\n"); + if (bTopHat) smSmooth(smx,smDensityTH); + else if (bSym) smSmooth(smx,smDensitySym); + else smSmooth(smx,smDensity); + } /* Else, we've read them */ + if (bGroup) { + INFORM("Finding Densest Neighbors...\n"); + if (bDensity && nHop=nSmooth) { + nSmooth = nHop+1; + ReSizeSMX(smx,nSmooth); + } + smSmooth(smx,smHop); + } + } + + INFORM("Grouping...\n"); + if (bGroup) FindGroups(smx); + if (bGroup) SortGroups(smx); + + if (bMerge) { + INFORM("Merging Groups...\n"); + MergeGroupsHash(smx); + } + + kdOrder(kd); + INFORM("Writing Output...\n"); + + if (bMerge&2) { + smx->nSmooth=nSmooth; /* Restore this for output */ + outGroupMerge(smx, my_comm); + } + if (bMerge) free(smx->hash); + + if (bGroup&2) { + binOutHop(smx, my_comm, densthres); + } + if (bGroup) {free(smx->densestingroup); free(smx->nmembers);} + smFinish(smx); + //kdFinish(kd); + INFORM("All Done!"); + return; +} + + +/* ============================================================= */ +/* ===================== New Density Routine =================== */ +/* ============================================================= */ + +void smDensityTH(SMX smx,int pi,int nSmooth,int *pList,float *fList) +/* Find density only using top-hat kernal. */ +{ +#ifdef DIFFERENT_MASSES + int j; + float totalmass; + for (j=0,totalmass=0.0; jkd, pList[j]); + NP_DENS(smx->kd, pi) = totalmass*0.75*M_1_PI/ + smx->pfBall2[pi]/sqrt(smx->pfBall2[pi]); +#else + /* This case is simple: the total mass is nSmooth times the mass + per particle */ + NP_DENS(smx->kd, pi) = (nSmooth)*smx->kd->fMass*0.75*M_1_PI/ + smx->pfBall2[pi]/sqrt(smx->pfBall2[pi]); +#endif + return; +} + +/* ============================================================= */ +/* ================== Hop to Neighbors/Form Groups ============= */ +/* ============================================================= */ + +void smHop(SMX smx,int pi,int nSmooth,int *pList,float *fList) +/* Look at the nHop nearest particles and find the one with the +highest density. Store its ID number in iHop as -1-ID (to make it negative) */ +/* nSmooth tends to be the expected value (smx->nSmooth-1) but can vary plus +or minus 1 (at least). */ +/* If Merging is turned off, nMerge should be huge so as to avoid extra +sorting below */ +{ + int i,max, search, didsort; + float maxden; + void ssort(float X[], int Y[], int N, int KFLAG); + + /* If the density is less than the threshold requirement, then assign 0 */ + if (NP_DENS(smx->kd, pi)fDensThresh) { + smx->kd->p[pi].iHop = 0; + return; + } + + /* If we have exactly the right number, then it doesn't matter how + we search them. Otherwise, we need to sort first. */ + /* We can destroy pList and fList if we want. fList holds the square radii*/ + + search = smx->nHop; + if (smx->nHop>nSmooth) search = nSmooth; /* Very rare exception */ + + if (smx->nHopnMerge+2kd, pList[i])>maxden) { + max = i; + maxden = NP_DENS(smx->kd, pList[i]); + } + } + smx->kd->p[pi].iHop = -1-pList[max]; + + /* check to see if the particle we link to doesn't link back + to ourselves, pi. If it does, connect this particle (pi) to itself. + This can only happen if pList[max] < pi*/ + if (pList[max] < pi) { + if (smx->kd->p[pList[max]].iHop == -1-pi) { + smx->kd->p[pi].iHop = -1-pi; + } + } + + /* If a sort was done, then we can save time in the Merge step by + recording the new Ball radius. */ + /* Place the new radius in between the two boundary because occasionally + the floating point math comes out strange when comparing two floats */ + if (didsort && smx->nMerge+2pfBall2[pi] = 0.5*(fList[smx->nMerge+1]+fList[smx->nMerge]); + return; +} + +/* ----------------------------------------------------------------- */ + +void FindGroups(SMX smx) +/* Number the maxima. Trace each particle uphill to a maximum. */ +/* The local maxima were stored as in iHop as -1-ID (negative numbers); +now we will store group number as positive numbers (1..n) in the same spot */ +/* Zero is left as an error condition */ +/* The particles MUST be left in the BuildTree order, for that is how the +iHop tracing is done */ +/* Allocate space for densestingroup, from 0 to nGroups +(inclusive) and store the particle number of the maxima, which is the +densest particle in the group. Ditto for nmembers[], the number of +particles in the group */ +{ + int j, ng, current, localmax; + PARTICLE *p; + + smx->nGroups = 0; + /* First look for maxima, where particle ID = iHop. Number the groups */ + for (j=0, p=smx->kd->p;jkd->nActive;j++,p++) + if (p->iHop == -1-j) { /* Was p->iOrder */ + /* Yes, it's a maximum */ + smx->nGroups++; + /* p->iHop = smx->nGroups; */ + } + + /* Now catalog the maxima, before numbering the groups */ + smx->densestingroup = (int *)malloc((size_t)((smx->nGroups+1)*sizeof(int))); + assert(smx->densestingroup!=NULL); + smx->nmembers = (int *)malloc((size_t)(sizeof(int)*(smx->nGroups+1))); + assert(smx->nmembers!=NULL); + + ng = 0; + for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) + if (p->iHop== -1-j) { + /* It's a maximum */ + ng++; + smx->densestingroup[ng] = p->iOrder; + p->iHop = ng; + } + + /* Now take the remaining particles and trace up to a maximum */ + for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) { + if (p->iHop>=0) continue; /* It's a maximum or an error */ + localmax = -1-p->iHop; + while (smx->kd->p[localmax].iHop<0) + localmax = -1-smx->kd->p[localmax].iHop; + ng = smx->kd->p[localmax].iHop; + /* Now assign this group number to the whole lineage! */ + /* Note that errors (iHop=0) will propagate */ + current = -1-p->iHop; + p->iHop = ng; + while (smx->kd->p[current].iHop<0) { + localmax = -1-smx->kd->p[current].iHop; + smx->kd->p[current].iHop = ng; + current = localmax; + } + } + return; +} + +/* ----------------------------------------------------------------- */ + +void SortGroups(SMX smx) +/* Renumber the groups in order of number of members. */ +/* Move the group numbering from unit offset to zero offset */ +/* Move error condition (group=0) to (group=-1) */ +/* Store the number of members and most dense particle in each group */ +{ + int j, *indx, *irank, *ip; + PARTICLE *p; + void make_rank_table(int n, int *ivect, int *rank); + + indx = (int *)malloc((size_t)(sizeof(int)*(smx->nGroups+1))); + assert(indx!=NULL); + irank = (int *)malloc((size_t)(sizeof(int)*(smx->nGroups+1))); + assert(irank!=NULL); + + /* Count the number of members in each group */ + for (j=0;j<=smx->nGroups;j++) smx->nmembers[j]=0; + for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) + smx->nmembers[p->iHop]++; + + make_rank_table(smx->nGroups, smx->nmembers,irank); + + for (j=1;j<=smx->nGroups;j++) irank[j] = smx->nGroups-irank[j]; + irank[0] = -1; /* Move old 0's to new -1's */ + /* irank[j] is the new group number of group j: zero-offset, ordered + large to small */ + + /* Relabel all the particles */ + for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) + p->iHop = irank[p->iHop]; + + /* Sort the nmembers and densestingroup lists to reflect the new ordering */ + /* Use indx as a temp space */ + for (j=1;j<=smx->nGroups;j++) indx[irank[j]]=smx->densestingroup[j]; + ip = smx->densestingroup; + smx->densestingroup = indx; + indx = ip; + /* Number of error (old_group=0) is in nmembers[0]; move it to [nGroups] */ + for (j=1;j<=smx->nGroups;j++) indx[irank[j]]=smx->nmembers[j]; + indx[smx->nGroups]=smx->nmembers[0]; + free(smx->nmembers); + smx->nmembers = indx; + + free(irank); + /* Note that the memory allocated to indx is now used by smx->densestingroup + and so it should not be free'd. */ + return; +} + +/* ================================================================== */ +/* ========================== Group Merging ========================= */ +/* ================================================================== */ + +void MergeGroupsHash(SMX smx) +/* We're going to look through the particles looking for boundary particles, +defined as particles with close neighbors of a different group, and store +the most dense boundary point (average of the two points) */ +/* The matrix of boundaries is stored in a hash table */ +/* SortGroups() should be called previous to this, so that all the +particles are in the assumed group numbering, i.e. 0 to ngroup-1, with +-1 being unattached. The tags are not altered */ +/* In smHop, if nMerge+2 was smaller than nSmooth, we set the new radius +for searching. If not, we left the old radius alone. Either way, we're +ready to go. */ +{ + int j, k, g, next, newgroup; + + ReSizeSMX(smx, smx->nMerge+2); /* Alter the smoothing scale on smx */ + smx->nHashLength = smx->nGroups*10+1; + smx->hash = (Boundary *)malloc(smx->nHashLength*sizeof(Boundary)); + assert(smx->hash!=NULL); + for (j=0;jnHashLength;j++) { + smx->hash[j].nGroup1 = -1; + smx->hash[j].nGroup2 = -1; + smx->hash[j].fDensity = -1.0; + } /* Mark the slot as unused */ + + smReSmooth(smx,smMergeHash); /* Record all the boundary particles */ + return; +} + +/* ----------------------------------------------------------------- */ + +void smMergeHash(SMX smx,int pi,int nSmooth,int *pList,float *fList) +/* Look at the list for groups which are not that of the particle */ +/* If found, and if density is high enough, then mark it as a boundary */ +/* by recording it in the hash table */ +{ + int j,group; + float averdensity; + int g1,g2,count; + unsigned long hashpoint; + Boundary *hp; + int search; + void ssort(float X[], int Y[], int N, int KFLAG); + + group = smx->kd->p[pi].iHop; + if (group==(-1)) return; /* This particle isn't in a group */ + + /* It seems that BallGather doesn't always get the right number of + particles....*/ + search = nSmooth; + if (nSmooth>smx->nMerge+1) { + ssort(fList-1,pList-1,nSmooth,2); + search = smx->nMerge+1; + } + for (j=0;jkd->p[pList[j]].iHop; + if (g2==-1 || g2==group) continue; /* Same group or unassigned */ + /* It's in a different group; we need to connect the two */ + if (groupkd, pi) + + NP_DENS(smx->kd, pList[j])); + hashpoint = (g1+1)*g2; /* Avoid multiplying by 0 */ + hashpoint = hashpoint % smx->nHashLength; + hp = smx->hash+hashpoint; + count = 0; + for (;;) { + if (hp->nGroup1==(-1)) { /* Empty slot */ + hp->nGroup1 = g1; + hp->nGroup2 = g2; + hp->fDensity = averdensity; + break; + } + if (hp->nGroup1==g1 && hp->nGroup2==g2) { + /* We've seen this pair of groups before */ + if (hp->fDensity > averdensity) break; + else { + hp->fDensity = averdensity; + break; + } + } + /* Else, this slot was full, go to the next one */ + hp++; + if (hp>=smx->hash+smx->nHashLength) hp = smx->hash; + if (++count>1000) { + fprintf(stderr,"Hash Table is too full.\n"); + exit(1); + } + } + /* Look at the next particle */ + } + return; +} + + +/* ----------------------------------------------------------------- */ + +void ReSizeSMX(SMX smx, int nSmooth) +/* Set a new smoothing length, resizing the arrays which depend on this, +but leaving the particle information intact. */ +/* However, because we won't always have resized pfBall2 (the search +radius) correctly, we won't reduce the size of the fList and pList +arrays */ +{ + PQ_STATIC; + if (nSmooth>smx->nSmooth) { /* We're increasing the size */ + smx->nListSize = nSmooth+RESMOOTH_SAFE; + free(smx->fList); + smx->fList = (float *)malloc(smx->nListSize*sizeof(float)); + assert(smx->fList != NULL); + free(smx->pList); + smx->pList = (int *)malloc(smx->nListSize*sizeof(int)); + assert(smx->pList != NULL); + } + smx->nSmooth=nSmooth; + free(smx->pq); + smx->pq = (PQ *)malloc(nSmooth*sizeof(PQ)); + assert(smx->pq != NULL); + PQ_INIT(smx->pq,nSmooth); + return; +} + +/* ===================================================================== */ +/* ===================== Input/Output, Binary and ASCII ================ */ +/* ===================================================================== */ + +void PrepareKD(KD kd) +/* This labels all the particles and finds the min/max of the positions */ +/* It used to appear in kd.c within kdReadTipsy(), but it seems so general +that I'll spare the user the trouble of including it in any custom input +routines */ +{ + BND bnd; + int i, j; + + /* Label the particles, so that we can restore the order at the end */ + for (i=0;inActive;i++) { + kd->p[i].iOrder=i; + } + /* + ** Calculate Bounds. + */ + for (j=0;j<3;++j) { + bnd.fMin[j] = NP_POS(kd, 0, j); + bnd.fMax[j] = NP_POS(kd, 0, j); + } + for (i=1;inActive;++i) { + for (j=0;j<3;++j) { + if (bnd.fMin[j] > NP_POS(kd, i, j)) + bnd.fMin[j] = NP_POS(kd, i, j); + else if (bnd.fMax[j] < NP_POS(kd, i, j)) + bnd.fMax[j] = NP_POS(kd, i, j); + } + } + kd->bnd = bnd; + return; +} + +void binOutHop(SMX smx, HC *my_comm, float densthres) +/* Write Group tag for each particle. Particles should be ordered. */ +/* Binary file: nActive, nGroups, list of Groups */ +{ + int j,dummy; + /* FILE *blahfp = fopen("Part-PreMergeGroup.txt","w"); *//* S Skory */ + Grouplist *g = my_comm->gl; + Slice *s = my_comm->s; + + g->npart = s->numlist = s->numpart = smx->kd->nActive; + g->ngroups = smx->nGroups; + s->ntag = ivector(1,s->numlist); + //s->ID = ivector(1,s->numlist); + for (j=0;jkd->nActive;j++) { + //s->ID[1+j] = smx->kd->p[j].iID; /* S Skory's addition */ + if (NP_DENS(smx->kd,j) < densthres) s->ntag[j+1] = -1; + else s->ntag[j+1] = smx->kd->p[j].iHop; + + } + + /* Here I'm going to add on the end of the file the real particle IDs for all the particles + added above, in the same order as above. S Skory */ + return; +} + +/* ----------------------------------------------------------------- */ + +void outGroupMerge(SMX smx, HC *my_comm) +/* Write an ASCII file with information on the groups and group merging */ +/* Start the boundary list with the only ### line */ +/* Groups should be ordered before calling this (else densities will be wrong)*/ +{ + int j, den; + Boundary *hp; + + my_comm->gdensity = vector(0,smx->nGroups-1); + for (j=0;jnGroups;j++) { + den = smx->densestingroup[j]; + my_comm->gdensity[j]=NP_DENS(smx->kd, den); + } + int nb = 0; + for (j=0, hp=smx->hash;jnHashLength; j++,hp++) + if (hp->nGroup1>=0)nb++; + my_comm->ngroups = smx->nGroups; + my_comm->nb = nb; + my_comm->g1vec = vector(0,nb); + my_comm->g2vec = vector(0,nb); + my_comm->fdensity = vector(0,smx->nHashLength); + nb = 0; + for (j=0, hp=smx->hash;jnHashLength; j++,hp++) + if (hp->nGroup1>=0){ + my_comm->g1vec[nb] = hp->nGroup1; + my_comm->g2vec[nb] = hp->nGroup2; + my_comm->fdensity[nb++] = hp->fDensity; + } + return; +} + + +/* ================================================================== */ +/* ======================= Sorting ================================== */ +/* ================================================================== */ + +typedef struct index_struct { + float value; + int index; +} *ptrindex; + +int cmp_index(const void *a, const void *b) +{ + if ( ((ptrindex)a)->value<((ptrindex)b)->value) return -1; + else if ( ((ptrindex)a)->value>((ptrindex)b)->value) return 1; + else return 0; +} + +void make_rank_table(int n, int *ivect, int *rank) +/* Given a vector of integers ivect[1..n], construct a rank table rank[1..n] +so that rank[j] contains the ordering of element j, with rank[j]=n indicating +that the jth element was the highest, and rank[j]=1 indicating that it +was the lowest. Storage for rank[] should be declared externally */ +/* I don't think this routine is particularly fast, but it's a +miniscule fraction of the runtime */ +{ + int j; + ptrindex sortvect; + + sortvect = (ptrindex)malloc(n*sizeof(struct index_struct)); + for (j=0;j T) { + X[IJ] = X[I]; + X[I] = T; + T = X[IJ]; + } + L = J; + + /* If last element of array is less than than T, interchange with T */ + + if (X[J] < T) { + X[IJ] = X[J]; + X[J] = T; + T = X[IJ]; + + /* If first element of array is greater than T, interchange with T */ + + if (X[I] > T) { + X[IJ] = X[I]; + X[I] = T; + T = X[IJ]; + } + } + + /* Find an element in the second half of the array which is smaller */ + /* than T */ + +line40: L = L-1; + if (X[L] > T) goto line40; + + /* Find an element in the first half of the array which is greater */ + /* than T */ + +line50: K = K+1; + if (X[K] < T) goto line50; + + /* Interchange these elements */ + + if (K <= L) { + TT = X[L]; + X[L] = X[K]; + X[K] = TT; + goto line40; + } + + /* Save upper and lower subscripts of the array yet to be sorted */ + + if (L-I > J-K) { + IL[M] = I; + IU[M] = L; + I = K; + M = M+1; + } else { + IL[M] = K; + IU[M] = J; + J = L; + M = M+1; + } + goto line70; + + /* Begin again on another portion of the unsorted array */ + +line60: M = M-1; + if (M == 0) goto line190; + I = IL[M]; + J = IU[M]; + +line70: if (J-I >= 1) goto line30; + if (I == 1) goto line20; + I = I-1; + +line80: I = I+1; + if (I == J) goto line60; + T = X[I+1]; + if (X[I] <= T) goto line80; + K = I; + +line90: X[K+1] = X[K]; + K = K-1; + if (T < X[K]) goto line90; + X[K+1] = T; + goto line80; + + /* Sort X and carry Y along */ + +line100: M = 1; + I = 1; + J = NN; + R = 0.375E0; + +line110: if (I == J) goto line150; + if (R <= 0.5898437E0) + R = R+3.90625E-2; + else R = R-0.21875E0; + +line120: K = I; + + /* Select a central element of the array and save it in location T */ + + IJ = I + (int)((J-I)*R); + T = X[IJ]; + TY = Y[IJ]; + + /* If first element of array is greater than T, interchange with T */ + + if (X[I] > T) { + X[IJ] = X[I]; + X[I] = T; + T = X[IJ]; + Y[IJ] = Y[I]; + Y[I] = TY; + TY = Y[IJ]; + } + L = J; +; + /* If last element of array is less than T, interchange with T */ + + if (X[J] < T) { + X[IJ] = X[J]; + X[J] = T; + T = X[IJ]; + Y[IJ] = Y[J]; + Y[J] = TY; + TY = Y[IJ]; + + /* If first element of array is greater than T, interchange with T */ + + if (X[I] > T) { + X[IJ] = X[I]; + X[I] = T; + T = X[IJ]; + Y[IJ] = Y[I]; + Y[I] = TY; + TY = Y[IJ]; + } + } + + /* Find an element in the second half of the array which is smaller */ + /* than T */ + +line130: L = L-1; + if (X[L] > T) goto line130; + + /* Find an element in the first half of the array which is greater */ + /* than T */ + +line140: K = K+1; + if (X[K] < T) goto line140; + + /* Interchange these elements */ + + if (K <= L) { + TT = X[L]; + X[L] = X[K]; + X[K] = TT; + TTY = Y[L]; + Y[L] = Y[K]; + Y[K] = TTY; + goto line130; + } + + /* Save upper and lower subscripts of the array yet to be sorted */ + + if (L-I > J-K) { + IL[M] = I; + IU[M] = L; + I = K; + M = M+1; + } else { + IL[M] = K; + IU[M] = J; + J = L; + M = M+1; + } + goto line160; + + /* Begin again on another portion of the unsorted array */ + +line150: M = M-1; + if (M == 0) goto line190; + I = IL[M]; + J = IU[M]; + +line160: if (J-I >= 1) goto line120; + if (I == 1) goto line110; + I = I-1; + +line170: I = I+1; + if (I == J) goto line150; + T = X[I+1]; + TY = Y[I+1]; + if (X[I] <= T) goto line170; + K = I; + +line180: X[K+1] = X[K]; + Y[K+1] = Y[K]; + K = K-1; + if (T < X[K]) goto line180; + X[K+1] = T; + Y[K+1] = TY; + goto line170; + + /* Clean up */ + +line190: if (KFLAG <= -1) + for (I=1; I<=NN; I++) + X[I] = -X[I]; + + return; +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/hop_kd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/hop_kd.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,225 @@ +/* KD.C */ +/* This was written by Joachim Stadel and the NASA HPCC ESS at +the University of Washington Department of Astronomy as part of +the SMOOTH program, v2.0.1. +URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ + +/* DJE--I have removed all the subroutines not used by HOP, notably +the input and output routines. */ + +/* HOP Version 1.0 (12/15/97) -- Original Release */ + +#include +#include +#include +#include +#include +#include +#include "kd.h" +#include "hop_numpy.h" +//#include "macros_and_parameters.h" +/* #include "tipsydefs.h" */ /* Don't need this, since I removed kdReadTipsy()*/ + + +#define MAX_ROOT_ITTR 32 + + +void kdTime(KD kd,int *puSecond,int *puMicro) +{ + struct rusage ru; + + getrusage(0,&ru); + *puMicro = ru.ru_utime.tv_usec - kd->uMicro; + *puSecond = ru.ru_utime.tv_sec - kd->uSecond; + if (*puMicro < 0) { + *puMicro += 1000000; + *puSecond -= 1; + } + kd->uSecond = ru.ru_utime.tv_sec; + kd->uMicro = ru.ru_utime.tv_usec; + } + + +int kdInit(KD *pkd,int nBucket) +{ + KD kd; + + kd = (KD)malloc(sizeof(struct kdContext)); + assert(kd != NULL); + kd->nBucket = nBucket; + kd->kdNodes = NULL; + *pkd = kd; + return(1); + } + +/* + ** JST's Median Algorithm + */ +int kdMedianJst(KD kd,int d,int l,int u) +{ + npy_float64 fm; + int i,k,m; + PARTICLE *p,t; + + p = kd->p; + k = (l+u)/2; + m = k; + while (l < u) { + m = (l+u)/2; + fm = NP_POS(kd, m, d); + t = p[m]; + p[m] = p[u]; + p[u] = t; + i = u-1; + m = l; + while (NP_POS(kd, m, d) < fm) ++m; + while (m < i) { + while (NP_POS(kd, i, d) >= fm) if (--i == m) break; + /* + ** Swap + */ + t = p[m]; + p[m] = p[i]; + p[i] = t; + --i; + while (NP_POS(kd, m, d) < fm) ++m; + } + t = p[m]; + p[m] = p[u]; + p[u] = t; + if (k <= m) u = m-1; + if (k >= m) l = m+1; + } + return(m); + } + + +void kdCombine(KDN *p1,KDN *p2,KDN *pOut) +{ + int j; + + /* + ** Combine the bounds. + */ + for (j=0;j<3;++j) { + if (p2->bnd.fMin[j] < p1->bnd.fMin[j]) + pOut->bnd.fMin[j] = p2->bnd.fMin[j]; + else + pOut->bnd.fMin[j] = p1->bnd.fMin[j]; + if (p2->bnd.fMax[j] > p1->bnd.fMax[j]) + pOut->bnd.fMax[j] = p2->bnd.fMax[j]; + else + pOut->bnd.fMax[j] = p1->bnd.fMax[j]; + } + } + + +void kdUpPass(KD kd,int iCell) +{ + KDN *c; + int l,u,pj,j; + + c = kd->kdNodes; + if (c[iCell].iDim != -1) { + l = LOWER(iCell); + u = UPPER(iCell); + kdUpPass(kd,l); + kdUpPass(kd,u); + kdCombine(&c[l],&c[u],&c[iCell]); + } + else { + l = c[iCell].pLower; + u = c[iCell].pUpper; + for (j=0;j<3;++j) { + c[iCell].bnd.fMin[j] = NP_POS(kd, u, j); + c[iCell].bnd.fMax[j] = NP_POS(kd, u, j); + } + for (pj=l;pj c[iCell].bnd.fMax[j]) + c[iCell].bnd.fMax[j] = NP_POS(kd, pj, j); + } + } + } + } + +int kdBuildTree(KD kd) +{ + int l,n,i,d,m,j,ct; + KDN *c; + + n = kd->nActive; + kd->nLevels = 1; + l = 1; + while (n > kd->nBucket) { + n = n>>1; + l = l<<1; + ++kd->nLevels; + } + kd->nSplit = l; + kd->nNodes = l<<1; + kd->kdNodes = (KDN *)malloc(kd->nNodes*sizeof(KDN)); + assert(kd->kdNodes != NULL); + /* + ** Set up ROOT node + */ + c = kd->kdNodes; + c[ROOT].pLower = 0; + c[ROOT].pUpper = kd->nActive-1; + c[ROOT].bnd = kd->bnd; + i = ROOT; + ct = ROOT; + SETNEXT(ct); + while (1) { + if (i < kd->nSplit) { + d = 0; + for (j=1;j<3;++j) { + if (c[i].bnd.fMax[j]-c[i].bnd.fMin[j] > + c[i].bnd.fMax[d]-c[i].bnd.fMin[d]) d = j; + } + c[i].iDim = d; + m = kdMedianJst(kd,d,c[i].pLower,c[i].pUpper); + c[i].fSplit = NP_POS(kd, m, d); + c[LOWER(i)].bnd = c[i].bnd; + c[LOWER(i)].bnd.fMax[d] = c[i].fSplit; + c[LOWER(i)].pLower = c[i].pLower; + c[LOWER(i)].pUpper = m-1; + c[UPPER(i)].bnd = c[i].bnd; + c[UPPER(i)].bnd.fMin[d] = c[i].fSplit; + c[UPPER(i)].pLower = m; + c[UPPER(i)].pUpper = c[i].pUpper; + i = LOWER(i); + } + else { + c[i].iDim = -1; + SETNEXT(i); + if (i == ct) break; + } + } + kdUpPass(kd,ROOT); + return(1); + } + + +int cmpParticles(const void *v1,const void *v2) +{ + PARTICLE *p1=(PARTICLE *)v1,*p2=(PARTICLE *)v2; + + return(p1->iOrder - p2->iOrder); + } + + +void kdOrder(KD kd) +{ + qsort(kd->p,kd->nActive,sizeof(PARTICLE),cmpParticles); + } + +void kdFinish(KD kd) +{ + if(kd->p!=NULL)free(kd->p); + if(kd->kdNodes!=NULL)free(kd->kdNodes); + free(kd); + } + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/hop_numpy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/hop_numpy.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#ifndef _NUMPY_HOP_H +#include "Python.h" +#include "numpy/ndarrayobject.h" + +#define NP_DENS(kd, in) \ + kd->np_densities[kd->p[in].np_index] +#define NP_POS(kd, in, dim) \ + kd->np_pos[dim][kd->p[in].np_index] +#define NP_MASS(kd, in) \ + (kd->np_masses[kd->p[in].np_index]/kd->totalmass) + +#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/hop_regroup.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/hop_regroup.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,726 @@ +/* REGROUP.C, Daniel Eisenstein, 1997 */ +/* Based on a paper by Daniel Eisenstein & Piet Hut, +"HOP: A New Group-Finding Algorithm for N-body Simulations." +See the included documentation or view it at +http://www.sns.ias.edu/~eisenste/hop/hop_doc.html */ + +/* Version 1.0 (12/15/97) -- Original Release */ + +#include "slice.h" +#include +#include +#include +#include +#include +#include +//#include "macros_and_parameters.h" +#include "hop.h" + +#define ISYM "d" +#define GSYM "g" +#define FSYM "f" + +/* #define MINDENS (-FLT_MAX/3.0) */ +#define MINDENS (-1.e+30/3.0) +/* This is the most negative density that can be accomodated. Note +that MINDENS*2.0 is referenced in the code and so must be properly +represented by the machine. There's no reason for this to be close to +the actual minimum of the density. */ + +#define INFORM(pstr) printf(pstr); fflush(stdout) +/* Used for messages, e.g. INFORM("Doing this"); */ + +#define UNBOUND -2 /* The tag marker for unbound particles */ + +/* ----------------------------------------------------------------------- */ +/* Prototypes */ +void initgrouplist(Grouplist *g); +void readtags(Slice *s, Grouplist *g, char *fname); +void densitycut(Slice *s, char *fname, float densthresh); +void writegmerge(Slice *s, Grouplist *gl, char *fname, float pt, float mt); +void readgmerge(Slice *s, Grouplist *gl, char *fname); +void merge_groups_boundaries(Slice *s, Grouplist *gl, char *fname, + float peakdensthresh, float saddledensthresh, float densthresh, HC *my_comm); +void translatetags(Slice *s, Grouplist *gl); +void writetags(Slice *s, Grouplist *gl, char *fname); +void writetagsf77(Slice *s, Grouplist *gl, char *fname); +void count_membership(Slice *s, Grouplist *g); +void sort_groups(Slice *s, Grouplist *gl, int mingroupsize, char *fname); + +/* ----------------------------------------------------------------------- */ +/* We use the following structure to handle the user interface: */ + +typedef struct controlstruct { + char *tagname; /* Input file for group tags */ + char *densname; /* Input file for density file */ + char *gmergename; /* Input file for group boundary specifications, OR + input file for group merging data */ + char *outsizename; /* Output file for size output*/ + char *outtagname; /* Output file for group tags */ + char *outgmergename; /* Output file for group merging */ + + int qdenscut; /* =1 if we're making a density cut, =0 otherwise */ + float densthresh; /* The outer density threshold (delta_outer)*/ + + int qgbound; /* =1 if we are to read the boundaries file and + determine the merging.*/ + float peak_thresh; /* Density threshold for peak (delta_peak) */ + float saddle_thresh; /* Density threshold for merging (delta_saddle) */ + int qgmerge_given; /* =1 if we are to use a group translation from file */ + + int mingroupsize; /* The minimum group size we follow */ + int qoutput; /* =1 if we are to write the tags */ + int qf77; /* =1 if binary output if in f77 format */ + int qpipe; /* =1 if we are to write the output tags to stdout */ + int qsort; /* =1 if we are to sort */ + + /* The following aren't used in the present version, but I included + them in case the user wants to customize the program: */ + char *dataname; /* Input file for particle data */ + int qunbind; /* =1 if we are to unbind at all */ +} Controls; /* Type Controls is defined */ + +/* ====================================================================== */ +/* ===================== User Interface ================================= */ +/* ====================================================================== */ + +void parsecommandline(float dens_outer, Controls *c) +{ + int narg, qmerge; + char *outname, *rootname; + narg = 1; + rootname = c->dataname = c->densname = c->gmergename = c->tagname = + outname = c->outsizename = c->outtagname = c->outgmergename = NULL; + c->qdenscut = -1; + qmerge = 1; + c->qgmerge_given = 0; + + c->qunbind = 0; + c->qoutput = 1; + c->qsort = 1; + c->qpipe = 0; + c->qf77 = 0; + + c->mingroupsize = -1; + if (2.0*MINDENS>=MINDENS || MINDENS>=0) + myerror("MINDENS seems to be illegal."); + /* Need MINDENS<0 and 2*MINDENS to be machine-representable */ + c->densthresh = 2.0*MINDENS; + c->saddle_thresh = 2.0*MINDENS; + c->peak_thresh = 2.0*MINDENS; + + /* GLB: hard-code some parameters. */ + + c->peak_thresh = 3.0*dens_outer; + c->saddle_thresh = 2.5*dens_outer; + c->densthresh = dens_outer; + c->qdenscut = 1; + rootname = "output_hop"; + + /* Get the input files ready */ + if (c->qdenscut==-1) { + /* Neither -douter nor -nodens was chosen. */ + mywarn("Outer density threshold left unspecified. Skipping this cut."); + c->qdenscut = 0; + } else if (c->qdenscut==1) { + /* We have a chosen density. Need to figure out the density file. */ + if (c->densname==NULL) { + if (rootname==NULL) + myerror("No density file name or root has been specified."); + c->densname = (char *)malloc(80); + strcpy(c->densname,rootname); strcat(c->densname, ".den"); + } + } else c->densname = NULL; /* We have no reason to read it */ + + if (c->tagname==NULL) { + if (rootname==NULL) + myerror("No .hop file name or root has been specified."); + c->tagname = (char *)malloc(80); + strcpy(c->tagname,rootname); strcat(c->tagname, ".hop"); + } + + if (qmerge==1) { + if (c->qgmerge_given==0) { + /* We need to have a .gbound file */ + c->qgbound = 1; + if (c->saddle_threshpeak_threshgmergename==NULL) { + if (rootname==NULL) + myerror("No .gbound file name or root has been specified."); + c->gmergename = (char *)malloc(80); + strcpy(c->gmergename,rootname); + strcat(c->gmergename, ".gbound"); + } + } else c->qgbound = 0; /* We know c->mergename is ready to go */ + } else c->gmergename = NULL; /* No reason to read it */ + + /* Get the output files ready */ + /* If a default name wasn't given, we'll assume zregroup */ + if (outname==NULL) { + outname = (char *)malloc(20); + strcpy(outname,"zregroup"); + } + /* Primary tag output: */ + if (c->qoutput) { /* Need to figure out where we're sending the output */ + if (c->qpipe&&c->outtagname) + myerror("Conflicting instructions--gave specific output name and told to pipe."); + if (c->qpipe>0) mywarn("Writing tags to stdout."); + if (c->qpipe) c->outtagname = NULL; /* Our signal to send to stdout */ + else if (c->outtagname==NULL) { + c->outtagname = (char *)malloc(80); + strcpy(c->outtagname, outname); + strcat(c->outtagname, ".tag"); + } /* Otherwise the name was set by the user */ + } else { + /* We're not outputing tags */ + if (c->qpipe) myerror("Conflicting instructions--told to pipe and not to output."); + } + + if (c->qsort) { + if (c->qpipe>=0) { /* The user didn't specify quiet */ + c->outsizename = (char *)malloc(80); + strcpy(c->outsizename, outname); + strcat(c->outsizename, ".size"); + } + } + + if (c->qpipe>=0) { /* The user didn't specify quiet */ + c->outgmergename = (char *)malloc(80); + strcpy(c->outgmergename, outname); + strcat(c->outgmergename, ".gmerge"); + } + + if (c->mingroupsize >= 0 && !c->qsort) + myerror("Imposition of a certain group size occurs within the sort routine."); + if (c->qsort && c->mingroupsize < 0) { + mywarn("No minimum group size specified. Assuming 10 particles."); + c->mingroupsize = 10; + } + + if (c->densthreshdensthresh=MINDENS; + /* This is our default--a very negative number */ + + return; +} + +/* ====================================================================== */ +/* ============================== MAIN() ================================ */ +/* ====================================================================== */ + +/* void main(int argc, char *argv[]) */ +void regroup_main(float dens_outer, HC *my_comm) +{ + Grouplist *gl = my_comm->gl; + Slice *s = my_comm->s; + FILE *f; + Controls c; + + /* parsecommandline(argc, argv, &c); */ + parsecommandline(dens_outer, &c); + + //initgrouplist(gl); + //s=newslice(); + + /* We need to read the tag file and perhaps perform a density cut */ + // We don't read anymore (mjt) + //readtags(s,gl,c.tagname); + + // We cut in advance now (mjt) + //if (c.qdenscut) densitycut(s,c.densname,c.densthresh); + + /* Next do the merging of the input groups */ + if (c.qgbound) { + /* We're going to read a .gbound file and merge groups */ + merge_groups_boundaries(s,gl,c.gmergename, + c.peak_thresh, c.saddle_thresh, c.densthresh, my_comm); + /* Renumber the groups from large to small; remove any tiny ones */ + //if (c.qsort) sort_groups(s, gl, c.mingroupsize, c.outsizename); + if (c.qsort) sort_groups(s, gl, c.mingroupsize, NULL); + //writegmerge(s, gl, c.outgmergename, c.peak_thresh, c.saddle_thresh); + translatetags(s,gl); + } + else if (c.qgmerge_given) { + /* We're going to read a .gmerge file and merge groups as it says */ + readgmerge(s, gl, c.gmergename); + translatetags(s, gl); + } /* Else we'll use the tags as given by the original .hop file */ + + /* If one wants to manipulate the groups any more, this is a good + place to do it. For example, you might want to remove unbound particles: + if (c.qunbind) { + get_particle_data(s, gl, c.dataname); + unbind_particles(s, gl, c.mingroupsize); + } + */ + + /* Write the output */ + /*if (c.qoutput) { + if (c.qf77) writetagsf77(s, gl, c.outtagname); + else writetags(s, gl, c.outtagname); + }*/ + + //free_slice(s); + return; +} + +/* ================================================================= */ +/* =================== Initialization Routines ===================== */ +/* ================================================================= */ + +void initgrouplist(Grouplist *g) +/* Just make sure this stuff is zero */ +{ + g->list = NULL; + g->npartingroups = g->npart = g->ngroups = 0; g->nnewgroups = 0; + return; +} + +void readtags(Slice *s, Grouplist *g, char *fname) +/* Read the tag file named fname into s->ntag[] */ +/* Groups need not be sorted, but must be numbered from 0 to ngroups-1 */ +{ + FILE *f; + + if ((f=fopen(fname,"r"))==NULL) myerror("Input tag file not found."); + if (fread(&(g->npart),sizeof(int),1,f)!=1) myerror("Tag file read error."); + if (fread(&(g->ngroups),sizeof(int),1,f)!=1) myerror("Tag file read error."); + fprintf(stderr,"Number of particles: %"ISYM". Number of groups: %"ISYM".\n", + g->npart, g->ngroups); + + s->numpart = g->npart; + s->numlist = g->npart; + s->ntag = ivector(1,s->numlist); + //s->ID = ivector(1,s->numlist); + fread(s->ntag+1, sizeof(int), s->numlist, f); /* Read in all the tags */ + //fread(s->ID+1, sizeof(int), s->numlist,f); /* Read in the real particle IDs. S Skory */ + fclose(f); + + return; +} + +/* ========================== Density Cut ======================== */ + +#define MAXBLOCK 65536 /* Read the file 256k at a time */ + +void densitycut(Slice *s, char *fname, float densthresh) +/* Read the density file and change the tag on any particle with density +less than densthresh to -1, thus removing them from groups */ +/* This will leave some groups with no particles, which is fine */ +/* We read the file in segments, so as to reduce memory consumption */ +{ + FILE *f; + int j, numread, npart, block; /* block was a float by mistake */ + float density[MAXBLOCK]; + + if ((f=fopen(fname,"r"))==NULL) + myerror("Density file not found."); + npart = 0; fread(&npart,sizeof(int),1,f); + if (npart!=s->numpart) + mywarn("Density file doesn't match slice description."); + + numread = 0; + block = MAXBLOCK; /* Start off big */ + while (numreadntag[numread+j]=(-1); /* s->ntag is unit-offset */ + numread+=block; + } + fclose(f); + return; +} + +/* ====================== Read/Write .gmerge files ======================= */ +/* The gmerge file is just a map from the old (pre-regroup) group numbers +to the new (post-regroup) group numbers. Of course, there are more "old" +groups than "new" groups, since the point of regroup() is to merge groups. */ + +void writegmerge(Slice *s, Grouplist *gl, char *fname, float pt, float mt) +/* Write the translation between old groups and new groups, ASCII */ +{ + FILE *f; + int j; + Group *gr; + + if (fname==NULL) return; /* We've been told not to write anything */ + + if ((f=fopen(fname,"w"))==NULL) myerror("Can't open gmerge file for write."); + fprintf(f,"%"ISYM"\n%"ISYM"\n%"ISYM"\n", gl->npart, gl->ngroups, gl->nnewgroups); + fprintf(f,"%"FSYM"\n%"FSYM"\n", pt, mt); + for (j=0,gr=gl->list;jngroups;j++,gr++) + fprintf(f,"%"ISYM" %"ISYM"\n", j, gr->idmerge); + fclose(f); + return; +} + +void readgmerge(Slice *s, Grouplist *gl, char *fname) +/* Read the translation between old groups and new groups, ASCII */ +/* Also, set up gl->list for translation */ +{ + FILE *f; + int j, dummy; + Group *gr; + float pt, mt; + + if ((f=fopen(fname,"r"))==NULL) myerror("Can't open gmerge read file."); + if (fscanf(f,"%"ISYM"\n%"ISYM"\n%"ISYM"\n", &(gl->npart), &(gl->ngroups), + &(gl->nnewgroups))!=3) myerror("Error in header of gmerge file."); + if (gl->npart!=s->numpart) myerror("Number of particles in gmerge file doesn't match that of tags file."); + fscanf(f,"%"FSYM" %"FSYM"\n", &pt, &mt); + + if (gl->list!=NULL) free(gl->list); + gl->list = (Group *)malloc((size_t)(gl->ngroups *sizeof(Group))); + if (gl->list==NULL) myerror("Error in allocating gl->list."); + + for (j=0,gr=gl->list; jngroups; j++,gr++) { + if (fscanf(f,"%"ISYM" %"ISYM"\n", &dummy, &(gr->idmerge))!=2 || dummy!=j) + myerror("Error in reading gmerge file."); + gr->npart = -1; /* We're not setting this */ + } + fclose(f); + return; +} + +/* ====================== GROUP MERGING BY BOUNDARIES ================ */ + +void merge_groups_boundaries(Slice *s, Grouplist *gl, char *mergename, + float peakdensthresh, float saddledensthresh, float densthresh, + HC *my_comm) +/* Read in the gmerge file and decide which groups are to be merged. +Groups are numbered 0 to ngroups-1. Groups with boundaries greater +than saddledensthresh are merged. Groups with maximum densities +less than peakdensthresh are merged to the group with +maxdensity above peakdensthresh with which it shares the highest +density border. */ +/* Only groups with maximum densities above peakdensthresh can be group +centers. */ +/* Allocate space for the grouplist and store the merging results in +the idmerge field. */ +/* I think this will work even if saddledensthreshgdensity; + ngroups = my_comm->ngroups; + + if (densthreshngroups = ngroups; + if (gl->list!=NULL) free(gl->list); + gl->list = (Group *)malloc((size_t)(gl->ngroups *sizeof(Group))); + fprintf(stderr,"ngroups = %d\n",ngroups); + if (gl->list==NULL) myerror("Error in allocating gl->list."); + for (j=0,gr=gl->list;jngroups;j++,gr++) { + /* If group is too underdense, it cannot be a group center */ + if (gdensity[j]idmerge=(-1);} + else {gr->idmerge = j;} + gr->npart = -1; /* Not doing anything with this */ + densestbound[j] = 2.0*MINDENS; /* Initialize */ + densestboundgroup[j] = -1; /* Initialize */ + } + + /* Now step through the list of boundaries */ + /* If a boundary is between two groups with max densities above + peakdensthresh and if the boundary is above saddledensthresh, then + merge the groups (keeping the lower number of the two). */ + /* If one of the groups is above peakdensthresh and the other is + below, and if the boundary density is higher than any seen previously + for the lower density group, then record this information */ + /* If neither group is above peakdensthresh, skip the boundary */ + + /* make few arrays to eliminate the need to write a file to disk. The entries in + the arrays should be no larger than my_comm->nb. + Skory. + */ + int *g1temp,*g2temp; + float *denstemp; + g1temp = (int *)malloc(sizeof(int) * my_comm->nb); + g2temp = (int *)malloc(sizeof(int) * my_comm->nb); + denstemp = (float *)malloc(sizeof(float) * my_comm->nb); + + int temppos = 0; + for(j=0;j<(my_comm->nb);j++) { + g1 = my_comm->g1vec[j]; + g2 = my_comm->g2vec[j]; + dens = my_comm->fdensity[j]; + if (gdensity[g1]densthresh && gdensity[g2]>densthresh && + dens>densthresh) { + g1temp[temppos] = g1; + g2temp[temppos] = g2; + denstemp[temppos] = dens; + temppos += 1; + } + continue; /* group isn't dense enough */ + } + if (gdensity[g1]>=peakdensthresh && gdensity[g2]>=peakdensthresh) + if (denslist[g1].idmerge) + g1=gl->list[g1].idmerge; + while (g2!=gl->list[g2].idmerge) + g2=gl->list[g2].idmerge; + if (g1list[g2].idmerge=g1; + else gl->list[g1].idmerge=g2; + continue; /* Go to the next boundary */ + } + /* Else one is above peakdensthresh, the other below. */ + /* Make the high one g1 */ + if (gdensity[g1]densestbound[g2]) { + /* It's the densest boundary yet */ + densestbound[g2] = dens; + densestboundgroup[g2] = g1; + } + } /* Get the next boundary line */ + + + /* Now the fringe groups are connected to the proper group + (>peakdensthresh) with the largest boundary. But we want to look + through the boundaries between fringe groups to propagate this + along. Connections are only as good as their smallest boundary */ + /* Keep the density of the connection in densestbound, and the + proper group it leads to in densestboundgroup */ + do { + changes = 0; + for (j=0;jdensestbound[g1]) { + dummy[0] = g2; g2=g1; g1=dummy[0]; + } + if (dens>densestbound[g2]&&densestbound[g1]>densestbound[g2]) { + changes++; + if (densngroups;j++) { + if (densestbound[j]>=densthresh) + gl->list[j].idmerge = densestboundgroup[j]; + } + /* Now we want to number the newly merged groups */ + /* The center groups are given negative numbers <-1 */ + for (j=0,gl->nnewgroups=0; jngroups; j++) + if (gl->list[j].idmerge==j) { + gl->list[j].idmerge = -2-(gl->nnewgroups++); + } + + /* Now trace each group through until a negative number is reached */ + for (j=0; jngroups; j++) { + if (gl->list[j].idmerge<0) continue; + g1 = j; + while ((g1=gl->list[g1].idmerge)>=0); + g2 = j; + do gl->list[g2].idmerge = g1; + while ((g2=gl->list[g2].idmerge)>=0); + } + + /* Finally, renumber the groups 0..N-1 */ + for (j=0,gr=gl->list;jngroups;j++,gr++) + gr->idmerge = -2-gr->idmerge; /* Keep -1 -> -1 */ + + + /* And delete the tempfile */ + remove(tempfilename); + free_vector(gdensity,0,ngroups-1); + free_vector(densestbound,0,ngroups-1); + free_ivector(densestboundgroup,0,ngroups-1); + return; +} + +/* ======================================================================= */ +/* =============== Update the tags and write them out ==================== */ +/* ======================================================================= */ + +void translatetags(Slice *s, Grouplist *gl) +/* Alter s->ntag to have the new groups. Reset gl so as to reflect the +new number of groups. */ +{ + int j; + + + for (j=1;j<=s->numlist;j++) + if (s->ntag[j]>=0) { + s->ntag[j] = gl->list[s->ntag[j]].idmerge; + } + /* Otherwise, translate the unbound particles */ + else if (s->ntag[j]<-1) + s->ntag[j] = UNBOUND - gl->list[UNBOUND-s->ntag[j]].idmerge; + free(gl->list); + gl->list = NULL; + gl->ngroups = gl->nnewgroups; + return; +} + +void writetags(Slice *s, Grouplist *gl, char *fname) +/* Write s->ntag to file */ +/* If fname==NULL, write to stdout */ +{ + FILE *f; + + + if (fname!=NULL) { + if ((f=fopen(fname,"w"))==NULL) myerror("Error opening new tag file."); + } else f=stdout; + fwrite(&(s->numpart),sizeof(int),1,f); + printf("writetags: s->numpart = %d gl->ngroups = %d\n", + s->numpart, gl->ngroups); + fwrite(&(gl->ngroups),sizeof(int),1,f); + fwrite(s->ntag+1,sizeof(int),s->numlist,f); + //fwrite(s->ID+1,sizeof(int),s->numlist,f); /* S Skory */ + fclose(f); + + return; +} + +void writetagsf77(Slice *s, Grouplist *gl, char *fname) +/* Write s->ntag to file */ +/* If fname==NULL, write to stdout */ +/* Use a format readable for FORTRAN unformatted read commands */ +{ + FILE *f; + int dummy; + if (fname!=NULL) { + if ((f=fopen(fname,"w"))==NULL) myerror("Error opening new tag file."); + } else f=stdout; + dummy = 8; fwrite(&dummy,sizeof(int),1,f); + fwrite(&(s->numpart),sizeof(int),1,f); + fwrite(&(gl->ngroups),sizeof(int),1,f); + fwrite(&dummy,sizeof(int),1,f); + dummy = s->numlist*sizeof(int); fwrite(&dummy,sizeof(int),1,f); + fwrite(s->ntag+1,sizeof(int),s->numlist,f); + fwrite(&dummy,sizeof(int),1,f); + fclose(f); + return; +} + +/* ====================================================================== */ +/* ========================== Sorting the Groups ======================== */ +/* ====================================================================== */ + +void sort_groups(Slice *s, Grouplist *gl, int mingroupsize, char *fname) +/* Sort the groups, as labeled by the idmerge field not their original +number, from largest to smallest. Alter the idmerge field to this new +numbering, setting any below mingroupsize to -1. */ +/* If fname!=NULL, write a little output file listing the group sizes */ +{ + FILE *f; + int j,k, *order, partingroup, igr, *newnum, nmergedgroups; + float *gsize; + Group *c; + void make_index_table(int n, float *fvect, int *index); + + nmergedgroups = gl->nnewgroups; + gsize = vector(0,nmergedgroups-1); + order = ivector(1,nmergedgroups); + newnum = ivector(0,nmergedgroups-1); + + /* First we need to find the number of particles in each group */ + for (j=0,c=gl->list;jngroups;j++,c++) c->npart=0; + + for (j=1;j<=s->numlist;j++) { /* Look through all the particles */ + igr = s->ntag[j]; + if (igr>=0) + if (igrngroups) gl->list[igr].npart++; + else myerror("Group tag is out of bounds."); + } + /* Now combine these to find the number in the new groups */ + for (j=0;jlist;jngroups;j++,c++) + if (c->idmerge>=0 && c->idmergeidmerge]+=c->npart; + else if (c->idmerge>=nmergedgroups) + myerror("Group idmerge is out of bounds."); + + make_index_table(nmergedgroups, gsize-1, order); + /* But remember that order[] thinks that gsize is unit-offset */ + for (j=nmergedgroups,k=0;j>0; j--,k++) + if (gsize[order[j]-1]>mingroupsize-0.5) newnum[order[j]-1]=k; + else break; /* All of the rest are too small */ + + gl->nnewgroups = k; + for (;j>0;j--) newnum[order[j]-1]=(-1); + /* Newnum[] holds the new sorted number for merged group j */ + + /* Now assign sorted group numbers to idmerge */ + partingroup = 0; + for (j=0,c=gl->list;jngroups;j++,c++) + if (c->idmerge>=0) + if ((c->idmerge = newnum[c->idmerge])>=0) + partingroup+=c->npart; + + /* Output the .size file, if inputed name isn't NULL */ + if (fname!=NULL) { + f = fopen(fname,"w"); + fprintf(f,"%"ISYM"\n%"ISYM"\n%"ISYM"\n", s->numpart, partingroup, gl->nnewgroups); + for (j=0;jnnewgroups;j++) + fprintf(f,"%"ISYM" %"ISYM"\n", j, (int)gsize[order[nmergedgroups-j]-1]); + fclose(f); + } + free_ivector(order,1,nmergedgroups); + free_vector(gsize,0,nmergedgroups-1); + free_ivector(newnum,0,nmergedgroups-1); + return; +} + +/* ======================== Sorting ============================ */ + +typedef struct index_struct { + float value; + int index; +} *ptrindex; + +int cmp_index_regroup(const void *a, const void *b) +{ + if ( ((ptrindex)a)->value<((ptrindex)b)->value) return -1; + else if ( ((ptrindex)a)->value>((ptrindex)b)->value) return 1; + else return 0; +} + +void make_index_table(int n, float *fvect, int *index) +/* Given a vector of floats fvect[1..n], construct a index table index[1..n] +so that index[j] contains the ID number of the jth lowest element. +Storage for index[] should be declared externally */ +/* This isn't fast, but it takes a tiny fraction of the runtime */ +{ + int j; + ptrindex sortvect; + + sortvect = (ptrindex)malloc(n*sizeof(struct index_struct)); + for (j=0;jpid = NULL; s->offset = 0; + s->px = s->py = s->pz = s->vx = s->vy = s->vz = NULL; + s->ntag = NULL; + //s->ID = NULL; /* S Skory */ + s->numpart = s->numlist = 0; + return s; +} + +void free_tags(Slice *s) +/* Free the tag vector */ +{ + if (s->ntag!=NULL) { + free_ivector(s->ntag, 1, s->numlist); + s->ntag=NULL; + //free_ivector(s->ID, 1, s->numlist); /* S Skory */ + //s->ID=NULL; + } + return; +} + +void free_data(Slice *s) +/* Free all the data vectors */ +{ + if (s->pid!=NULL) {free(s->pid); s->pid=NULL;} + if (s->px!=NULL) {free_vector(s->px,1,s->numlist); s->px=NULL;} + if (s->py!=NULL) {free_vector(s->py,1,s->numlist); s->py=NULL;} + if (s->pz!=NULL) {free_vector(s->pz,1,s->numlist); s->pz=NULL;} + if (s->vx!=NULL) {free_vector(s->vx,1,s->numlist); s->vx=NULL;} + if (s->vy!=NULL) {free_vector(s->vy,1,s->numlist); s->vy=NULL;} + if (s->vz!=NULL) {free_vector(s->vz,1,s->numlist); s->vz=NULL;} + return; +} + +void free_slice(Slice *s) +/* Free the space associated with the vectors in the given Slice */ +/* Then free the Slice variable itself */ +{ + free_tags(s); + free_data(s); + free(s); + return; +} + +/* =================================================================== */ + +int f77write(FILE *f, void *p, int len) +/* len is number of bytes to be written from p[0..len-1] */ +/* Return 0 if successful, 1 if not */ +{ + if (fwrite(&len,sizeof(int),1,f)!=1) return 1; + if (fwrite(p,1,len,f)!=len) return 1; + if (fwrite(&len,sizeof(int),1,f)!=1) return 1; + return 0; +} + +int f77read(FILE *f, void *p, int maxbytes) +/* Read a FORTRAN style block from the given file */ +/* maxbytes is the amount of space the pointer p points to */ +/* Space must be allocated to read the whole block into p */ +/* Return amount read, scream if there's a problem */ +/* Reading is done ZERO-OFFSET */ +{ + int size, size2; + if (fread(&size,sizeof(int),1,f)!=1) + myerror("f77read(): Error reading begin delimiter."); + if (size>maxbytes) + myerror("f77read(): Block delimiter exceeds size of storage."); + if (sizenumpart = sizeheader[0]; + s->numblocks = sizeheader[1]; + s->numperblock = sizeheader[0]/sizeheader[1]; + if (s->numpart != s->numblocks*(s->numperblock)) + myerror("Number of blocks not an even divisor of number of particles."); + + s->z = header[0]; + s->boxsize = header[1]*1000.0; /* We use kpc, not Mpc */ + s->physsize = s->boxsize/(1.0+s->z); /* We use kpc, not Mpc */ + s->velscale = 100.0*header[1]*sqrt(3.0/8.0/PI)/(1.0+s->z); + /* To go from data to pec vel */ + s->omega = header[4]; + if (header[6]!=0.0) myerror("HDM component listed in header."); + s->lambda = header[7]; + s->h0 = header[8]; + s->sigma8 = header[9]; /* At z=0 */ + + /* Now find some computed quantities. */ + s->a = 1.0/(1.0+s->z); + s->curv = 1.0-s->omega-s->lambda; + s->gamma = s->omega*(s->h0); + s->specn = 1.0; + s->hubb = 0.1*sqrt(s->omega/CUBE(s->a)+s->curv/SQR(s->a)+s->lambda)*(s->a); + + /* The following assume Omega = 1 */ + s->masspart = RHOCRIT/s->numpart*CUBE(s->boxsize); + s->growth = s->a; + s->t = HTIME*(s->h0)*pow(s->a, 1.5); + return 0; +} + +void normalizedata(Slice *s, int conp, int conv) +/* Put raw data into comoving h^-1 kpc and km/s units */ +{ + int j; + float velnorm; + if (conp) { + for (j=1;j<=s->numlist;j++) s->px[j] *= s->boxsize; + for (j=1;j<=s->numlist;j++) s->py[j] *= s->boxsize; + for (j=1;j<=s->numlist;j++) s->pz[j] *= s->boxsize; + } + + if (conv) { + for (j=1;j<=s->numlist;j++) s->vx[j] *= s->velscale; + for (j=1;j<=s->numlist;j++) s->vy[j] *= s->velscale; + for (j=1;j<=s->numlist;j++) s->vz[j] *= s->velscale; + } + return; +} + +/* ================================================================ */ + +int read_alldata(FILE *f, FILE *ftag, Slice *s, int conp, int conv) +/* Read all the data, including the tags if ftag!=NULL. */ +/* Store positions and velocities unless conp or conv = 0 */ +/* Assume that the data file header has been skipped, but read the +tag file header. */ +{ + int block; + float *dummylist; + + dummylist = NULL; + if (!conp || !conv) dummylist = vector(1,s->numperblock); + if (s->pid!=NULL) + mywarn("Non-NULL s->pid[] passed to read_alldata(). Ignoring..."); + + s->numlist=s->numpart; + if (conp) { + s->px=vector(1,s->numlist); + s->py=vector(1,s->numlist); + s->pz=vector(1,s->numlist); + } + if (conv) { + s->vx=vector(1,s->numlist); + s->vy=vector(1,s->numlist); + s->vz=vector(1,s->numlist); + } + if (ftag!=NULL) { + s->ntag = ivector(1,s->numlist); + s->ID = ivector(1,s->numlist); /* S Skory */ + } + + + printf("Reading data..."); + for (block=0;blocknumblocks;block++) { + /* Read the three position blocks */ + if (conp) { /* Store the data */ + f77read(f, s->px+s->numperblock*block+1, s->numperblock*sizeof(float)); + f77read(f, s->py+s->numperblock*block+1, s->numperblock*sizeof(float)); + f77read(f, s->pz+s->numperblock*block+1, s->numperblock*sizeof(float)); + } else { /* Don't store the data */ + f77read(f, dummylist+1, s->numperblock*sizeof(float)); + f77read(f, dummylist+1, s->numperblock*sizeof(float)); + f77read(f, dummylist+1, s->numperblock*sizeof(float)); + } + /* Now read the three velocity blocks */ + if (conv) { /* Store the data */ + f77read(f, s->vx+s->numperblock*block+1, s->numperblock*sizeof(float)); + f77read(f, s->vy+s->numperblock*block+1, s->numperblock*sizeof(float)); + f77read(f, s->vz+s->numperblock*block+1, s->numperblock*sizeof(float)); + } else { /* Don't store the data */ + f77read(f, dummylist+1, s->numperblock*sizeof(float)); + f77read(f, dummylist+1, s->numperblock*sizeof(float)); + f77read(f, dummylist+1, s->numperblock*sizeof(float)); + } + if (block%8==1) {printf("."); fflush(stdout);} + } + if (dummylist!=NULL) free_vector(dummylist, 1, s->numperblock); + normalizedata(s,conp,conv); + + if (ftag!=NULL) { + printf("tags..."); fflush(stdout); + readalltags(ftag, s); + } + + printf("done!"); fflush(stdout); + return 0; +} + +int read_partdata(FILE *f, FILE *ftag, Slice *s) +/* Read one block (128k particles) of data into Slice s. Allocate needed +storage, erasing and freeing previous storage. */ +/* This cannot be done with s->pid!=NULL, so s->pid is ignored and s->numlist +is reset to BLOCKSIZE */ +/* Unlike other routines, this stores both positions and velocities in +all cases (since the storage requirements are already small */ +/* If ftag==NULL, don't read the tag file. Otherwise do read it. */ +{ + if (s->pid!=NULL) + mywarn("Non-trivial pid[] not supported with incremental reads"); + /* If we need to reallocate memory, do it. Otherwise, just write over */ + if (s->px==NULL || s->vx==NULL || s->numlist!=s->numperblock) { + if (s->px!=NULL) free_vector(s->px,1,s->numlist); + if (s->py!=NULL) free_vector(s->py,1,s->numlist); + if (s->pz!=NULL) free_vector(s->pz,1,s->numlist); + if (s->vx!=NULL) free_vector(s->vx,1,s->numlist); + if (s->vy!=NULL) free_vector(s->vy,1,s->numlist); + if (s->vz!=NULL) free_vector(s->vz,1,s->numlist); + if (ftag!=NULL && s->ntag!=NULL) { + free_ivector(s->ntag, 1, s->numlist); + free_ivector(s->ID, 1, s->numlist); /* S Skory */ + } + s->numlist = s->numperblock; + s->px = vector(1,s->numlist); + s->py = vector(1,s->numlist); + s->pz = vector(1,s->numlist); + s->vx = vector(1,s->numlist); + s->vy = vector(1,s->numlist); + s->vz = vector(1,s->numlist); + if (ftag!=NULL) { + s->ntag = ivector(1, s->numlist); + s->ID = ivector(1, s->numlist); /* S Skory */ + } + s->offset=0; + /* fprintf(stderr, "Reallocating data arrays.\n"); */ + } + else s->offset+=s->numlist; + + f77read(f,s->px+1,sizeof(float)*s->numlist); + f77read(f,s->py+1,sizeof(float)*s->numlist); + f77read(f,s->pz+1,sizeof(float)*s->numlist); + f77read(f,s->vx+1,sizeof(float)*s->numlist); + f77read(f,s->vy+1,sizeof(float)*s->numlist); + f77read(f,s->vz+1,sizeof(float)*s->numlist); + + if (ftag!=NULL) readtag(ftag, s->numlist, s->ntag); + normalizedata(s,1,1); + return 0; +} + +/* =============================================================== */ + +int readtag(FILE *f, int numread, int *ntag) +/* Read numread values from FILE f and put the values in ntag */ +/* Return 0 if successful, 1 if not */ +/* The storage ntag[1..numread] must exist */ +/* Note: the first 8 bytes of the tag file contain the number of particles +and the number of groups. These must be skipped before calling this routine. */ +{ + if (fread(ntag+1, sizeof(int), numread, f)!=numread) + myerror("Error in reading tag file."); + return 0; +} + +int skiptagheader(FILE *f, Slice *s) +/* Read the first 8 bytes from the tag file. Check that the first int equals +the number of particles. Return the second, which is the number of groups */ +{ + int dummy[2]; + if (fread(&dummy, sizeof(int), 2, f)!=2) myerror("Error in reading tag file."); + if (s->numpart!=0 && dummy[0]!=s->numpart) + myerror("First number in tag file doesn't match expected number of particles."); + s->numgroups = dummy[1]; + return dummy[1]; +} + +int readalltags(FILE *f, Slice *s) +/* Read the whole tag file. Allocate memory as needed */ +/* Return the number of groups */ +{ + int dummy[2]; + if (s->ntag==NULL || s->numlist!=s->numpart) { + if (s->ntag!=NULL) { + free_ivector(s->ntag, 1, s->numlist); + free_ivector(s->ID, 1, s->numlist); /* S Skory */ + } + s->numlist = s->numpart; + s->ntag = ivector(1, s->numlist); + s->ID = ivector(1, s->numlist); + } + if (fread(&dummy, sizeof(int), 2, f)!=2) myerror("Error 1 in reading tag file."); + if (dummy[0]!=s->numpart) + myerror("First int of tag file doesn't match numpart."); + s->numgroups = dummy[1]; + + if (fread(s->ntag+1, sizeof(int), s->numlist, f)!=s->numlist) + myerror("Couldn't read entire tag file."); + return dummy[1]; +} + +#endif + +/* ===================== Warnings and Errors =========================== */ + +/* Print a message and die */ +void myerror(char *message) +{ + fprintf(stderr, "%s\n", message); + exit(1); return; +} + +/* Just print a message */ +void mywarn(char *message) +{ + fprintf(stderr, "%s\n", message); + fflush(NULL); /* Flush everything, so we know where we are */ + return; +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/hop_smooth.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/hop_smooth.c Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,476 @@ +/* SMOOTH.C */ +/* This was written by Joachim Stadel and the NASA HPCC ESS at +the University of Washington Department of Astronomy as part of +the SMOOTH program, v2.0.1. +URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ + +/* DJE--I have removed unneeded subroutines, notably those having +to do with velocity field reconstructions (because they refer to +particle data that I chose not to store) and output routines +(because I wanted binary output). Also, the density subroutine +was slightly customized to reduce memory consumption in +the case of equal mass particles. */ + +/* HOP Version 1.0 (12/15/97) -- Original Release */ + +#include +#include +#include +#include +#include "smooth.h" +#include "kd.h" +#include "hop_numpy.h" + +#define ISYM "d" +#define GSYM "g" + +//#include "macros_and_parameters.h" + +#define IMARK 1 /* All particles are marked to be included */ + +int smInit(SMX *psmx,KD kd,int nSmooth,float *fPeriod) +{ + SMX smx; + PQ_STATIC; + int pi,j; + fprintf(stderr,"nSmooth = %d kd->nActive = %d\n", nSmooth, kd->nActive); + assert(nSmooth <= kd->nActive); + smx = (SMX)malloc(sizeof(struct smContext)); + assert(smx != NULL); + smx->kd = NULL; + + smx->kd = kd; + smx->nSmooth = nSmooth; + smx->pq = (PQ *)malloc(nSmooth*sizeof(PQ)); + assert(smx->pq != NULL); + PQ_INIT(smx->pq,nSmooth); + smx->pfBall2 = (float *)malloc((kd->nActive+1)*sizeof(int)); + assert(smx->pfBall2 != NULL); + smx->iMark = (char *)malloc(kd->nActive*sizeof(char)); + assert(smx->iMark); + smx->nListSize = smx->nSmooth+RESMOOTH_SAFE; + smx->fList = (float *)malloc(smx->nListSize*sizeof(float)); + assert(smx->fList != NULL); + smx->pList = (int *)malloc(smx->nListSize*sizeof(int)); + assert(smx->pList != NULL); + /* + ** Set for Periodic Boundary Conditions. + */ + for (j=0;j<3;++j) smx->fPeriod[j] = fPeriod[j]; + /* + ** Initialize arrays for calculated quantities.--DJE + */ + for (pi=0;pikd->nActive;++pi) { + NP_DENS(smx->kd, pi) = 0.0; + smx->kd->p[pi].iHop = 0; + } + *psmx = smx; + return(1); + } + + +void smFinish(SMX smx) +{ + free(smx->pfBall2); + free(smx->iMark); + free(smx->pq); + free(smx); + } + + +void smBallSearch(SMX smx,float fBall2,float *ri) +{ + KDN *c; + PARTICLE *p; + int cell,cp,ct,pj; + float fDist2,dx,dy,dz,lx,ly,lz,sx,sy,sz,x,y,z; + PQ *pq; + PQ_STATIC; + + c = smx->kd->kdNodes; + p = smx->kd->p; + pq = smx->pqHead; + x = ri[0]; + y = ri[1]; + z = ri[2]; + lx = smx->fPeriod[0]; + ly = smx->fPeriod[1]; + lz = smx->fPeriod[2]; + cell = ROOT; + /* + ** First find the "local" Bucket. + ** This could mearly be the closest bucket to ri[3]. + */ + while (cell < smx->kd->nSplit) { + if (ri[c[cell].iDim] < c[cell].fSplit) cell = LOWER(cell); + else cell = UPPER(cell); + } + /* + ** Now start the search from the bucket given by cell! + */ + for (pj=c[cell].pLower;pj<=c[cell].pUpper;++pj) { + dx = x - NP_POS(smx->kd, pj, 0); + dy = y - NP_POS(smx->kd, pj, 1); + dz = z - NP_POS(smx->kd, pj, 2); + fDist2 = dx*dx + dy*dy + dz*dz; + if (fDist2 < fBall2) { + if (smx->iMark[pj]) continue; + smx->iMark[pq->p] = 0; + smx->iMark[pj] = 1; + pq->fKey = fDist2; + pq->p = pj; + pq->ax = 0.0; + pq->ay = 0.0; + pq->az = 0.0; + PQ_REPLACE(pq); + fBall2 = pq->fKey; + } + } + while (cell != ROOT) { + cp = SIBLING(cell); + ct = cp; + SETNEXT(ct); + while (1) { + INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz); + /* + ** We have an intersection to test. + */ + if (cp < smx->kd->nSplit) { + cp = LOWER(cp); + continue; + } + else { + for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { + dx = sx - NP_POS(smx->kd, pj, 0); + dy = sy - NP_POS(smx->kd, pj, 1); + dz = sz - NP_POS(smx->kd, pj, 2); + fDist2 = dx*dx + dy*dy + dz*dz; + if (fDist2 < fBall2) { + if (smx->iMark[pj]) continue; + smx->iMark[pq->p] = 0; + smx->iMark[pj] = 1; + pq->fKey = fDist2; + pq->p = pj; + pq->ax = sx - x; + pq->ay = sy - y; + pq->az = sz - z; + PQ_REPLACE(pq); + fBall2 = pq->fKey; + } + } + } + GetNextCell: + SETNEXT(cp); + if (cp == ct) break; + } + cell = PARENT(cell); + } + smx->pqHead = pq; + } + + +int smBallGather(SMX smx,float fBall2,float *ri) +{ + KDN *c; + PARTICLE *p; + int pj,nCnt,cp,nSplit; + float dx,dy,dz,x,y,z,lx,ly,lz,sx,sy,sz,fDist2; + + c = smx->kd->kdNodes; + p = smx->kd->p; + nSplit = smx->kd->nSplit; + lx = smx->fPeriod[0]; + ly = smx->fPeriod[1]; + lz = smx->fPeriod[2]; + x = ri[0]; + y = ri[1]; + z = ri[2]; + nCnt = 0; + cp = ROOT; + while (1) { + INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz); + /* + ** We have an intersection to test. + */ + if (cp < nSplit) { + cp = LOWER(cp); + continue; + } + else { + for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { + dx = sx - NP_POS(smx->kd, pj, 0); + dy = sy - NP_POS(smx->kd, pj, 1); + dz = sz - NP_POS(smx->kd, pj, 2); + fDist2 = dx*dx + dy*dy + dz*dz; + if (fDist2 < fBall2) { + smx->fList[nCnt] = fDist2; + smx->pList[nCnt++] = pj; + /* Insert debugging flag here */ + if (nCnt > smx->nListSize) { + fprintf(stderr,"nCnt too big.\n"); + } + } + } + } + GetNextCell: + SETNEXT(cp); + if (cp == ROOT) break; + } + assert(nCnt <= smx->nListSize); + return(nCnt); + } + + +void smSmooth(SMX smx,void (*fncSmooth)(SMX,int,int,int *,float *)) +{ + KDN *c; + PARTICLE *p; + PQ *pq,*pqLast; + PQ_STATIC; + int cell; + int pi,pin,pj,pNext,nCnt,nSmooth; + float dx,dy,dz,x,y,z,h2,ax,ay,az; + float temp_ri[3]; + + + for (pi=0;pikd->nActive;++pi) { + if (IMARK) smx->pfBall2[pi] = -1.0; + else smx->pfBall2[pi] = 1.0; /* pretend it is already done! */ + } + smx->pfBall2[smx->kd->nActive] = -1.0; /* stop condition */ + for (pi=0;pikd->nActive;++pi) { + smx->iMark[pi] = 0; + } + pqLast = &smx->pq[smx->nSmooth-1]; + c = smx->kd->kdNodes; + p = smx->kd->p; + nSmooth = smx->nSmooth; + /* + ** Initialize Priority Queue. + */ + pin = 0; + pNext = 1; + ax = 0.0; + ay = 0.0; + az = 0.0; + for (pq=smx->pq,pj=0;pq<=pqLast;++pq,++pj) { + smx->iMark[pj] = 1; + pq->p = pj; + pq->ax = ax; + pq->ay = ay; + pq->az = az; + } + while (1) { + if (smx->pfBall2[pin] >= 0) { + /* + ** Find next particle which is not done, and load the + ** priority queue with nSmooth number of particles. + */ + while (smx->pfBall2[pNext] >= 0) ++pNext; + /* + ** Check if we are really finished. + */ + if (pNext == smx->kd->nActive) break; + pi = pNext; + ++pNext; + x = NP_POS(smx->kd, pi, 0); + y = NP_POS(smx->kd, pi, 1); + z = NP_POS(smx->kd, pi, 2); + /* printf("%"ISYM": %"GSYM" %"GSYM" %"GSYM"\n", pi, x, y, z); */ + /* + ** First find the "local" Bucket. + ** This could mearly be the closest bucket to ri[3]. + */ + cell = ROOT; + while (cell < smx->kd->nSplit) { + if (NP_POS(smx->kd, pi, c[cell].iDim) < c[cell].fSplit) + cell = LOWER(cell); + else + cell = UPPER(cell); + } + /* + ** Remove everything from the queue. + */ + smx->pqHead = NULL; + for (pq=smx->pq;pq<=pqLast;++pq) smx->iMark[pq->p] = 0; + /* + ** Add everything from pj up to and including pj+nSmooth-1. + */ + pj = c[cell].pLower; + if (pj > smx->kd->nActive - nSmooth) + pj = smx->kd->nActive - nSmooth; + for (pq=smx->pq;pq<=pqLast;++pq) { + smx->iMark[pj] = 1; + dx = x - NP_POS(smx->kd, pj, 0); + dy = y - NP_POS(smx->kd, pj, 1); + dz = z - NP_POS(smx->kd, pj, 2); + pq->fKey = dx*dx + dy*dy + dz*dz; + pq->p = pj++; + pq->ax = 0.0; + pq->ay = 0.0; + pq->az = 0.0; + } + PQ_BUILD(smx->pq,nSmooth,smx->pqHead); + } + else { + /* + ** Calculate the priority queue using the previous particles! + */ + pi = pin; + x = NP_POS(smx->kd, pi, 0); + y = NP_POS(smx->kd, pi, 1); + z = NP_POS(smx->kd, pi, 2); + smx->pqHead = NULL; + for (pq=smx->pq;pq<=pqLast;++pq) { + pq->ax -= ax; + pq->ay -= ay; + pq->az -= az; + dx = x + pq->ax - NP_POS(smx->kd, pq->p, 0); + dy = y + pq->ay - NP_POS(smx->kd, pq->p, 1); + dz = z + pq->az - NP_POS(smx->kd, pq->p, 2); + pq->fKey = dx*dx + dy*dy + dz*dz; + } + PQ_BUILD(smx->pq,nSmooth,smx->pqHead); + ax = 0.0; + ay = 0.0; + az = 0.0; + } + temp_ri[0] = NP_POS(smx->kd, pi, 0); + temp_ri[1] = NP_POS(smx->kd, pi, 1); + temp_ri[2] = NP_POS(smx->kd, pi, 2); + smBallSearch(smx,smx->pqHead->fKey,temp_ri); + smx->pfBall2[pi] = smx->pqHead->fKey; + /* + ** Pick next particle, 'pin'. + ** Create fList and pList for function 'fncSmooth'. + */ + pin = pi; + nCnt = 0; + h2 = smx->pqHead->fKey; + for (pq=smx->pq;pq<=pqLast;++pq) { + if (pq == smx->pqHead) continue; + smx->pList[nCnt] = pq->p; + smx->fList[nCnt++] = pq->fKey; + if (smx->pfBall2[pq->p] >= 0) continue; + if (pq->fKey < h2) { + pin = pq->p; + h2 = pq->fKey; + ax = pq->ax; + ay = pq->ay; + az = pq->az; + } + } + (*fncSmooth)(smx,pi,nCnt,smx->pList,smx->fList); + } + } + + +void smReSmooth(SMX smx,void (*fncSmooth)(SMX,int,int,int *,float *)) +{ + PARTICLE *p; + int pi,nSmooth; + float temp_ri[3]; + + p = smx->kd->p; + for (pi=0;pikd->nActive;++pi) { + if (IMARK == 0) continue; + /* + ** Do a Ball Gather at the radius of the most distant particle + ** which is smDensity sets in smx->pBall[pi]. + */ + temp_ri[0] = NP_POS(smx->kd, pi, 0); + temp_ri[1] = NP_POS(smx->kd, pi, 1); + temp_ri[2] = NP_POS(smx->kd, pi, 2); + nSmooth = smBallGather(smx,smx->pfBall2[pi],temp_ri); + (*fncSmooth)(smx,pi,nSmooth,smx->pList,smx->fList); + } + } + + +void smDensity(SMX smx,int pi,int nSmooth,int *pList,float *fList) +{ + float ih2,r2,rs,fDensity; + int i,pj; + + ih2 = 4.0/smx->pfBall2[pi]; + fDensity = 0.0; + for (i=0;ikd, pj); +#else + fDensity += rs*smx->kd->fMass; +#endif + } + NP_DENS(smx->kd, pi) = M_1_PI*sqrt(ih2)*ih2*fDensity; + } + + +void smDensitySym(SMX smx,int pi,int nSmooth,int *pList,float *fList) +{ + float fNorm,ih2,r2,rs; + int i,pj; + + ih2 = 4.0/smx->pfBall2[pi]; + fNorm = 0.5*M_1_PI*sqrt(ih2)*ih2; + for (i=0;ikd, pi) += rs*NP_MASS(smx->kd, pj); + NP_DENS(smx->kd, pj) += rs*NP_MASS(smx->kd, pi); +#else + smx->kd->p[pi].fDensity += rs*smx->kd->fMass; + smx->kd->p[pj].fDensity += rs*smx->kd->fMass; +#endif + } + } + +/* I'm not using the following function, but I left it here in case someone +wants the densities outputted in Tipsy format. But you're probably better +off just fetching the smooth() program from the HPCC web site... */ + +void smOutDensity(SMX smx,FILE *fp) +{ + int i,iCnt; + + fprintf(fp,"%"ISYM"\n",smx->kd->nParticles); + iCnt = 0; + for (i=0;ikd->nGas;++i) { + if (smx->kd->bGas) { + if (IMARK) + fprintf(fp,"%.8"GSYM"\n",NP_DENS(smx->kd, iCnt)); + else fprintf(fp,"0\n"); + ++iCnt; + } + else fprintf(fp,"0\n"); + } + for (i=0;ikd->nDark;++i) { + if (smx->kd->bDark) { + if (IMARK) + fprintf(fp,"%.8"GSYM"\n",NP_DENS(smx->kd, iCnt)); + else fprintf(fp,"0\n"); + ++iCnt; + } + else fprintf(fp,"0\n"); + } + for (i=0;ikd->nStar;++i) { + if (smx->kd->bStar) { + if (IMARK) + fprintf(fp,"%.8"GSYM"\n",NP_DENS(smx->kd, iCnt)); + else fprintf(fp,"0\n"); + ++iCnt; + } + else fprintf(fp,"0\n"); + } +} + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/kd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/kd.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,203 @@ +/* KD.H */ +/* This was written by Joachim Stadel and the NASA HPCC ESS at +the University of Washington Department of Astronomy as part of +the SMOOTH program, v2.0.1. +URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ + +/* DJE--I have made a few alterations to the PARTICLE structure +in order to reduce memory consumption. */ + +/* HOP Version 1.0 (12/15/97) -- Original Release */ + +/* GLB--set different masses on */ + +#define DIFFERENT_MASSES + +//#include "macros_and_parameters.h" + +#ifndef KD_HINCLUDED +#define KD_HINCLUDED + +#include "Python.h" +#include "numpy/ndarrayobject.h" + +#define ROOT 1 +#define LOWER(i) (i<<1) +#define UPPER(i) ((i<<1)+1) +#define PARENT(i) (i>>1) +#define SIBLING(i) ((i&1)?i-1:i+1) +#define SETNEXT(i)\ +{\ + while (i&1) i=i>>1;\ + ++i;\ + } + +#define DARK 1 +#define GAS 2 +#define STAR 4 + +typedef struct Particle { + int np_index; + int iHop; + int iOrder; +#if 0 + float r[3]; + float fDensity; + // int iID; /* the real ID of the particle S. Skory */ + int iHop; /* DJE: The number of the highest-density neighbor; + Later, the group number. */ +#ifdef DIFFERENT_MASSES + float fMass; +#endif + /* DJE: The following are unused and cost too much memory to keep */ + /* float v[3]; */ + /* float fMass; */ + /* int iMark; */ + /* float vMean[3]; */ + /* float fVelDisp2; */ +#endif + } PARTICLE; + +typedef struct bndBound { + float fMin[3]; + float fMax[3]; + } BND; + +typedef struct kdNode { + float fSplit; + BND bnd; + int iDim; + int pLower; + int pUpper; + } KDN; + +typedef struct kdContext { + int nBucket; + int nParticles; + int nDark; + int nGas; + int nStar; + int bDark; + int bGas; + int bStar; + int nActive; + float fTime; + BND bnd; + int nLevels; + int nNodes; + int nSplit; + float fMass; /* DJE: If all particles have the same mass */ + PARTICLE *p; + KDN *kdNodes; + int uSecond; + int uMicro; + npy_float64 *np_densities; + npy_float64 *np_pos[3]; + npy_float64 *np_masses; + float totalmass; + } * KD; + + +#define INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz)\ +{\ + float dx,dy,dz,dx1,dy1,dz1,fDist2;\ + dx = c[cp].bnd.fMin[0]-x;\ + dx1 = x-c[cp].bnd.fMax[0];\ + dy = c[cp].bnd.fMin[1]-y;\ + dy1 = y-c[cp].bnd.fMax[1];\ + dz = c[cp].bnd.fMin[2]-z;\ + dz1 = z-c[cp].bnd.fMax[2];\ + if (dx > 0.0) {\ + dx1 += lx;\ + if (dx1 < dx) {\ + fDist2 = dx1*dx1;\ + sx = x+lx;\ + }\ + else {\ + fDist2 = dx*dx;\ + sx = x;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else if (dx1 > 0.0) {\ + dx += lx;\ + if (dx < dx1) {\ + fDist2 = dx*dx;\ + sx = x-lx;\ + }\ + else {\ + fDist2 = dx1*dx1;\ + sx = x;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else {\ + fDist2 = 0.0;\ + sx = x;\ + }\ + if (dy > 0.0) {\ + dy1 += ly;\ + if (dy1 < dy) {\ + fDist2 += dy1*dy1;\ + sy = y+ly;\ + }\ + else {\ + fDist2 += dy*dy;\ + sy = y;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else if (dy1 > 0.0) {\ + dy += ly;\ + if (dy < dy1) {\ + fDist2 += dy*dy;\ + sy = y-ly;\ + }\ + else {\ + fDist2 += dy1*dy1;\ + sy = y;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else {\ + sy = y;\ + }\ + if (dz > 0.0) {\ + dz1 += lz;\ + if (dz1 < dz) {\ + fDist2 += dz1*dz1;\ + sz = z+lz;\ + }\ + else {\ + fDist2 += dz*dz;\ + sz = z;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else if (dz1 > 0.0) {\ + dz += lz;\ + if (dz < dz1) {\ + fDist2 += dz*dz;\ + sz = z-lz;\ + }\ + else {\ + fDist2 += dz1*dz1;\ + sz = z;\ + }\ + if (fDist2 > fBall2) goto GetNextCell;\ + }\ + else {\ + sz = z;\ + }\ + } + + +void kdTime(KD,int *,int *); +int kdInit(KD *,int); +int kdReadTipsy(KD,FILE *,int,int,int); +void kdInMark(KD,char *); +int kdBuildTree(KD); +void kdOrder(KD); +void kdFinish(KD); + +#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,19 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('hop',parent_package,top_path) + config.add_extension("EnzoHop", sources= + ["EnzoHop.c", + "hop_hop.c", + "hop_kd.c", + "hop_regroup.c", + "hop_slice.c", + "hop_smooth.c",]) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/slice.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/slice.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,97 @@ +/* SLICE.H, Daniel Eisenstein, 1997 */ +/* Based on a paper by Daniel Eisenstein & Piet Hut, +"HOP: A New Group-Finding Algorithm for N-body Simulations." +See the included documentation or view it at +http://www.sns.ias.edu/~eisenste/hop/hop_doc.html */ + +/* Version 1.0 (12/15/97) -- Original Release */ + +#ifndef NBODYUTIL_H +#define NBODYUTIL_H + +#define RHOCRIT 277.5 /* in h^2 Msun/kpc^3 */ +#define HTIME 9.7776 /* in h^-1 Gyr */ +#define GNEWT 4.51e-6 /* in kpc^3/Msun/Gyr^2, h cancels */ +#define KMS 0.975 /* to convert from kpc/Gyr to km/s */ + +#define PI 3.141592654 +#define ROOT2 1.414213562 +#define ROOTPI2 1.253314137 /* sqrt(Pi/2) */ + +#include +#include +#include +//#include "macros_and_parameters.h" + +/* Structure to hold data from one time slice and info about the slice */ +/* This needn't hold all of the points; it might just hold some subset */ +/* Hence, data vectors are just given as arrays here */ +/* Usage: pid[] Array goes from 0 to pid[0]. pid is NULL if the particle +numbering is just the trivial mapping. Kinematic arrays go from 1 to numlist +and can be NULL if the data hasn't been read. Numlist==pid[0] often */ + +typedef struct slicestruct { +#ifdef NOT_USED + /* First, some generic stuff about the simulation */ + float omega, lambda, curv; + float h0; /* H_0 = 100 km/s/Mpc * h0 */ + float specn, gamma; /* The spectral index and BBKS PS Gamma */ + float sigma8; /* At z=0 */ + + /* Next, some information about this slice in particular */ + float z, a, t, growth; + /* a=1 at z=0, g=a at early times */ + float hubb; /* This is a*H(z), but without h0. So it's 0.1 km/s/kpc + redshifted appropriately. This is used to relate + comoving positions and peculiar velocities */ + + /* Now some information about the data */ + int numblocks; /* Number of blocks in the data file */ + int numperblock; /* Number of particles per block */ + float masspart; /* Mass per particle in h^-1 Msun */ + float boxsize; /* Comoving size of box in h^-1 kpc */ + float physsize; /* Physical Size in h^-1 kpc */ + float velscale; /* To turn raw velocity data into peculiar vel in km/s*/ +#endif + + int numpart; /* Total number of particles in the simulation */ + /* Now the data itself */ + int *pid; /* The id number of the particle */ + /* pid[0] holds the number of particles in the list */ + int offset; /* If pid==NULL, then the arrays are consecutively + numbered, starting from offset+1 */ + int numlist; /* Length of arrays below, set when allocated */ + float *px, *py, *pz, *vx, *vy, *vz; /* The kinematic information */ + + /* And here's the group tag information */ + int *ntag; /* Only stored for the numlist above */ + //int *ID; /* The real, true ID of the particle. S Skory */ + int numgroups; /* The number of groups read out of the tag file */ +} Slice; /* Type Slice is defined */ + +/* Prototypes */ +Slice *newslice(); +void free_tags(Slice *s); +void free_data(Slice *s); +void free_slice(Slice *s); +int f77write(FILE *f, void *p, int len); +int f77read(FILE *f, void *p, int len); +float *vector(long nl, long nh); +int *ivector(long nl, long nh); +void free_vector(float *v, long nl, long nh); +void free_ivector(int *v, long nl, long nh); + +void myerror(char *message); +void mywarn(char *message); + +int read_header(FILE *f, Slice *s); +void normalizedata(Slice *s, int conp, int conv); +int read_alldata(FILE *f, FILE *ftag, Slice *s, int conp, int conv); +int read_partdata(FILE *f, FILE *ftag, Slice *s); + +int readtag(FILE *f, int numread, int *ntag); +int skiptagheader(FILE *f, Slice *s); +int readalltags(FILE *f, Slice *s); + + +#endif /* NBODYUTIL_H */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/hop/smooth.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/hop/smooth.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,140 @@ +/* SMOOTH.H */ +/* This was written by Joachim Stadel and the NASA HPCC ESS at +the University of Washington Department of Astronomy as part of +the SMOOTH program, v2.0.1. +URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ + +/* DJE--I have made a few additions to the SMX structure +in order to store information necessary for HOP. I have also +added the Boundary structure. */ + +/* HOP Version 1.0 (12/15/97) -- Original Release */ + +#ifndef SMOOTH_HINCLUDED +#define SMOOTH_HINCLUDED + +#include "kd.h" +//#include "macros_and_parameters.h" + +#define RESMOOTH_SAFE 30 + +/* DJE: Define this structure to hold the boundary data. */ +typedef struct boundarystruct { + int nGroup1, nGroup2; /* The two groups involved, ordered such + that nGroup1>1];\ + (pq)[PQ_j].pqFromExt = &(pq)[(PQ_j+(n))>>1];\ + }\ + } + + +#define PQ_BUILD(pq,n,q)\ +{\ + for (PQ_j=(n)-1;PQ_j>0;--PQ_j) {\ + PQ_i = (PQ_j<<1);\ + if (PQ_i < (n)) PQ_t = (pq)[PQ_i].pqWinner;\ + else PQ_t = &(pq)[PQ_i-(n)];\ + ++PQ_i;\ + if (PQ_i < (n)) PQ_lt = (pq)[PQ_i].pqWinner;\ + else PQ_lt = &(pq)[PQ_i-(n)];\ + if (PQ_t->fKey < PQ_lt->fKey) {\ + (pq)[PQ_j].pqLoser = PQ_t;\ + (pq)[PQ_j].pqWinner = PQ_lt;\ + }\ + else {\ + (pq)[PQ_j].pqLoser = PQ_lt;\ + (pq)[PQ_j].pqWinner = PQ_t;\ + }\ + }\ + (q) = (pq)[1].pqWinner;\ + } + + +#define PQ_REPLACE(q)\ +{\ + PQ_t = (q)->pqFromExt;\ + while (PQ_t) {\ + if (PQ_t->pqLoser->fKey > (q)->fKey) {\ + PQ_lt = PQ_t->pqLoser;\ + PQ_t->pqLoser = (q);\ + (q) = PQ_lt;\ + }\ + PQ_t = PQ_t->pqFromInt;\ + }\ + } + + + +int smInit(SMX *,KD,int,float *); +void smFinish(SMX); +void smBallSearch(SMX,float,float *); +int smBallGather(SMX,float,float *); +void smSmooth(SMX,void (*)(SMX,int,int,int *,float *)); +void smReSmooth(SMX,void (*)(SMX,int,int,int *,float *)); +void smDensity(SMX,int,int,int *,float *); +void smDensitySym(SMX,int,int,int *,float *); +void smMeanVel(SMX,int,int,int *,float *); +void smMeanVelSym(SMX,int,int,int *,float *); +void smVelDisp(SMX,int,int,int *,float *); +void smVelDispSym(SMX,int,int,int *,float *); +void smNull(SMX,int,int,int *,float *); +void smOutDensity(SMX,FILE *); +void smOutMeanVel(SMX,FILE *); +void smOutVelDisp(SMX,FILE *); +void smOutPhase(SMX,FILE *); +void smOutMach(SMX,FILE *); +void smOutSpeed(SMX,FILE *); + +#endif + + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/parallel_hop/parallel_hop_interface.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/parallel_hop/parallel_hop_interface.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,1506 @@ +""" +A implementation of the HOP algorithm that runs in parallel. + +Author: Stephen Skory +Affiliation: UCSD/CASS +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Stephen Skory. 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 . +""" + +from collections import defaultdict +import itertools, sys +import numpy as na + +from yt.funcs import * +from yt.utilities.performance_counters import yt_counters, time_function +try: + from yt.utilities.kdtree import \ + chainHOP_tags_dens, \ + create_tree, fKD, find_nn_nearest_neighbors +except ImportError: + mylog.debug("The Fortran kD-Tree did not import correctly.") + +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + parallel_blocking_call, \ + ParallelAnalysisInterface + +class ParallelHOPHaloFinder(ParallelAnalysisInterface): + def __init__(self,period, padding, num_neighbors, bounds, + xpos, ypos, zpos, index, mass, threshold=160.0, rearrange=True, + premerge=True): + self.threshold = threshold + self.rearrange = rearrange + self.premerge = premerge + self.saddlethresh = 2.5 * threshold + self.peakthresh = 3 * threshold + self.period = period + self.padding = padding + self.num_neighbors = num_neighbors + self.bounds = bounds + self.xpos = xpos + self.ypos = ypos + self.zpos = zpos + self.real_size = len(self.xpos) + self.index = na.array(index, dtype='int64') + self.mass = mass + self.padded_particles = [] + self.nMerge = 4 + yt_counters("chainHOP") + self.max_mem = 0 + self.__max_memory() + self._chain_hop() + yt_counters("chainHOP") + + def _global_bounds_neighbors(self): + """ + Build a dict of the boundaries of all the tasks, and figure out which + tasks are our geometric neighbors. + """ + self.neighbors = set([]) + self.mine, global_bounds = self._mpi_info_dict(self.bounds) + my_LE, my_RE = self.bounds + # Put the vertices into a big list, each row is + # array[x,y,z, taskID] + vertices = [] + my_vertices = [] + for taskID in global_bounds: + thisLE, thisRE = global_bounds[taskID] + if self.mine != taskID: + vertices.append(na.array([thisLE[0], thisLE[1], thisLE[2], taskID])) + vertices.append(na.array([thisLE[0], thisLE[1], thisRE[2], taskID])) + vertices.append(na.array([thisLE[0], thisRE[1], thisLE[2], taskID])) + vertices.append(na.array([thisRE[0], thisLE[1], thisLE[2], taskID])) + vertices.append(na.array([thisLE[0], thisRE[1], thisRE[2], taskID])) + vertices.append(na.array([thisRE[0], thisLE[1], thisRE[2], taskID])) + vertices.append(na.array([thisRE[0], thisRE[1], thisLE[2], taskID])) + vertices.append(na.array([thisRE[0], thisRE[1], thisRE[2], taskID])) + if self.mine == taskID: + my_vertices.append(na.array([thisLE[0], thisLE[1], thisLE[2]])) + my_vertices.append(na.array([thisLE[0], thisLE[1], thisRE[2]])) + my_vertices.append(na.array([thisLE[0], thisRE[1], thisLE[2]])) + my_vertices.append(na.array([thisRE[0], thisLE[1], thisLE[2]])) + my_vertices.append(na.array([thisLE[0], thisRE[1], thisRE[2]])) + my_vertices.append(na.array([thisRE[0], thisLE[1], thisRE[2]])) + my_vertices.append(na.array([thisRE[0], thisRE[1], thisLE[2]])) + my_vertices.append(na.array([thisRE[0], thisRE[1], thisRE[2]])) + # Find the neighbors we share corners with. Yes, this is lazy with + # a double loop, but it works and this is definitely not a performance + # bottleneck. + for my_vertex in my_vertices: + for vertex in vertices: + if vertex[3] in self.neighbors: continue + # If the corners touch, it's easy. This is the case if resizing + # (load-balancing) is turned off. + if (my_vertex % self.period == vertex[0:3] % self.period).all(): + self.neighbors.add(int(vertex[3])) + continue + # Also test to see if the distance to this corner is within + # max_padding, which is more likely the case with load-balancing + # turned on. + dx = min( na.fabs(my_vertex[0] - vertex[0]), \ + self.period[0] - na.fabs(my_vertex[0] - vertex[0])) + dy = min( na.fabs(my_vertex[1] - vertex[1]), \ + self.period[1] - na.fabs(my_vertex[1] - vertex[1])) + dz = min( na.fabs(my_vertex[2] - vertex[2]), \ + self.period[2] - na.fabs(my_vertex[2] - vertex[2])) + d = na.sqrt(dx*dx + dy*dy + dz*dz) + if d <= self.max_padding: + self.neighbors.add(int(vertex[3])) + # Faces and edges. + for dim in range(3): + dim1 = (dim + 1) % 3 + dim2 = (dim + 2) % 3 + left_face = my_LE[dim] + right_face = my_RE[dim] + for taskID in global_bounds: + if taskID == self.mine or taskID in self.neighbors: continue + thisLE, thisRE = global_bounds[taskID] + max1 = max(my_LE[dim1], thisLE[dim1]) + max2 = max(my_LE[dim2], thisLE[dim2]) + min1 = min(my_RE[dim1], thisRE[dim1]) + min2 = min(my_RE[dim2], thisRE[dim2]) + # Faces. + # First, faces that touch directly. + if (thisRE[dim] == left_face or thisRE[dim]%self.period[dim] == left_face) and \ + max1 <= min1 and max2 <= min2: + self.neighbors.add(taskID) + continue + elif (thisLE[dim] == right_face or thisLE[dim] == right_face%self.period[dim]) and \ + max1 <= min1 and max2 <= min2: + self.neighbors.add(taskID) + continue + # If an intervening subvolume has a width less than the padding + # (rare, but possible), a neighbor may not actually touch, so + # we need to account for that. + if (abs(thisRE[dim] - left_face) <= self.max_padding or \ + abs(thisRE[dim]%self.period[dim] - left_face) <= self.max_padding) and \ + max1 <= min1 and max2 <= min2: + self.neighbors.add(taskID) + continue + elif (abs(thisLE[dim] - right_face) <= self.max_padding or \ + abs(thisLE[dim] - right_face%self.period[dim]) <= self.max_padding) and \ + max1 <= min1 and max2 <= min2: + self.neighbors.add(taskID) + continue + # Edges. + # First, edges that touch. + elif (my_LE[dim] == (thisRE[dim]%self.period[dim]) and \ + my_LE[dim1] == (thisRE[dim1]%self.period[dim1]) and \ + max2 <= min2) or \ + (my_LE[dim] == (thisRE[dim]%self.period[dim]) and \ + my_LE[dim2] == (thisRE[dim2]%self.period[dim2]) and \ + max1 <= min1): + self.neighbors.add(taskID) + continue + elif ((my_RE[dim]%self.period[dim]) == thisLE[dim] and \ + (my_RE[dim1]%self.period[dim1]) == thisLE[dim1] and \ + max2 <= min2) or \ + ((my_RE[dim]%self.period[dim]) == thisLE[dim] and \ + (my_RE[dim2]%self.period[dim2]) == thisLE[dim2] and \ + max1 <= min1): + self.neighbors.add(taskID) + continue + # Now edges that don't touch, but are close. + if (abs(my_LE[dim] - thisRE[dim]%self.period[dim]) <= self.max_padding and \ + abs(my_LE[dim1] - thisRE[dim1]%self.period[dim1]) <= self.max_padding and \ + max2 <= min2) or \ + (abs(my_LE[dim] - thisRE[dim]%self.period[dim]) <= self.max_padding and \ + abs(my_LE[dim2] - thisRE[dim2]%self.period[dim2]) <= self.max_padding and \ + max1 <= min1): + self.neighbors.add(taskID) + continue + elif (abs(my_RE[dim]%self.period[dim] - thisLE[dim]) <= self.max_padding and \ + abs(my_RE[dim1]%self.period[dim1] - thisLE[dim1]) <= self.max_padding and \ + max2 <= min2) or \ + (abs(my_RE[dim]%self.period[dim] - thisLE[dim]) <= self.max_padding and \ + abs(my_RE[dim2]%self.period[dim2] - thisLE[dim2]) <= self.max_padding and \ + max1 <= min1): + self.neighbors.add(taskID) + continue + # Now we build a global dict of neighbor sets, and if a remote task + # lists us as their neighbor, we add them as our neighbor. This is + # probably not needed because the stuff above should be symmetric, + # but it isn't a big issue. + self.mine, global_neighbors = self._mpi_info_dict(self.neighbors) + for taskID in global_neighbors: + if taskID == self.mine: continue + if self.mine in global_neighbors[taskID]: + self.neighbors.add(taskID) + # We can remove ourselves from the set if it got added somehow. + self.neighbors.discard(self.mine) + # Clean up. + del global_neighbors, global_bounds, vertices, my_vertices + + def _global_padding(self, round): + """ + Find the maximum padding of all our neighbors, used to send our + annulus data. + """ + if round == 'first': + max_pad = na.max(self.padding) + self.mine, self.global_padding = self._mpi_info_dict(max_pad) + self.max_padding = max(self.global_padding.itervalues()) + elif round == 'second': + self.max_padding = 0. + for neighbor in self.neighbors: + self.max_padding = na.maximum(self.global_padding[neighbor], \ + self.max_padding) + + def _communicate_padding_data(self): + """ + Send the particles each of my neighbors need to build up their padding. + """ + yt_counters("Communicate discriminated padding") + # First build a global dict of the padded boundaries of all the tasks. + (LE, RE) = self.bounds + (LE_padding, RE_padding) = self.padding + temp_LE = LE - LE_padding + temp_RE = RE + RE_padding + expanded_bounds = (temp_LE, temp_RE) + self.mine, global_exp_bounds = self._mpi_info_dict(expanded_bounds) + send_real_indices = {} + send_points = {} + send_mass = {} + send_size = {} + # This will reduce the size of the loop over particles. + yt_counters("Picking padding data to send.") + send_count = len(na.where(self.is_inside_annulus == True)[0]) + points = na.empty((send_count, 3), dtype='float64') + points[:,0] = self.xpos[self.is_inside_annulus] + points[:,1] = self.ypos[self.is_inside_annulus] + points[:,2] = self.zpos[self.is_inside_annulus] + real_indices = self.index[self.is_inside_annulus].astype('int64') + mass = self.mass[self.is_inside_annulus].astype('float64') + # Make the arrays to send. + shift_points = points.copy() + for neighbor in self.neighbors: + temp_LE, temp_RE = global_exp_bounds[neighbor] + for i in xrange(3): + left = ((points[:,i] < temp_LE[i]) * (points[:,i] < temp_RE[i])) * self.period[i] + right = ((points[:,i] > temp_LE[i]) * (points[:,i] > temp_RE[i])) * self.period[i] + shift_points[:,i] = points[:,i] + left - right + is_inside = ( (shift_points >= temp_LE).all(axis=1) * \ + (shift_points < temp_RE).all(axis=1) ) + send_real_indices[neighbor] = real_indices[is_inside].copy() + send_points[neighbor] = shift_points[is_inside].copy() + send_mass[neighbor] = mass[is_inside].copy() + send_size[neighbor] = len(na.where(is_inside == True)[0]) + del points, shift_points, mass, real_indices + yt_counters("Picking padding data to send.") + # Communicate the sizes to send. + self.mine, global_send_count = self._mpi_info_dict(send_size) + del send_size + # Initialize the arrays to receive data. + yt_counters("Initalizing recv arrays.") + recv_real_indices = {} + recv_points = {} + recv_mass = {} + recv_size = 0 + for opp_neighbor in self.neighbors: + opp_size = global_send_count[opp_neighbor][self.mine] + recv_real_indices[opp_neighbor] = na.empty(opp_size, dtype='int64') + recv_points[opp_neighbor] = na.empty((opp_size, 3), dtype='float64') + recv_mass[opp_neighbor] = na.empty(opp_size, dtype='float64') + recv_size += opp_size + yt_counters("Initalizing recv arrays.") + # Setup the receiving slots. + yt_counters("MPI stuff.") + hooks = [] + for opp_neighbor in self.neighbors: + hooks.append(self._mpi_Irecv_long(recv_real_indices[opp_neighbor], opp_neighbor)) + hooks.append(self._mpi_Irecv_double(recv_points[opp_neighbor], opp_neighbor)) + hooks.append(self._mpi_Irecv_double(recv_mass[opp_neighbor], opp_neighbor)) + # Let's wait here to be absolutely sure that all the receive buffers + # have been created before any sending happens! + self._barrier() + # Now we send the data. + for neighbor in self.neighbors: + hooks.append(self._mpi_Isend_long(send_real_indices[neighbor], neighbor)) + hooks.append(self._mpi_Isend_double(send_points[neighbor], neighbor)) + hooks.append(self._mpi_Isend_double(send_mass[neighbor], neighbor)) + # Now we use the data, after all the comms are done. + self._mpi_Request_Waitall(hooks) + yt_counters("MPI stuff.") + yt_counters("Processing padded data.") + del send_real_indices, send_points, send_mass + # Now we add the data to ourselves. + self.index_pad = na.empty(recv_size, dtype='int64') + self.xpos_pad = na.empty(recv_size, dtype='float64') + self.ypos_pad = na.empty(recv_size, dtype='float64') + self.zpos_pad = na.empty(recv_size, dtype='float64') + self.mass_pad = na.empty(recv_size, dtype='float64') + so_far = 0 + for opp_neighbor in self.neighbors: + opp_size = global_send_count[opp_neighbor][self.mine] + self.index_pad[so_far:so_far+opp_size] = recv_real_indices[opp_neighbor] + # Clean up immediately to reduce peak memory usage. + del recv_real_indices[opp_neighbor] + self.xpos_pad[so_far:so_far+opp_size] = recv_points[opp_neighbor][:,0] + self.ypos_pad[so_far:so_far+opp_size] = recv_points[opp_neighbor][:,1] + self.zpos_pad[so_far:so_far+opp_size] = recv_points[opp_neighbor][:,2] + del recv_points[opp_neighbor] + self.mass_pad[so_far:so_far+opp_size] = recv_mass[opp_neighbor] + del recv_mass[opp_neighbor] + so_far += opp_size + yt_counters("Processing padded data.") + # The KDtree node search wants the particles to be in the full box, + # not the expanded dimensions of shifted (<0 or >1 generally) volume, + # so we fix the positions of particles here. + yt_counters("Flipping coordinates around the periodic boundary.") + self.xpos_pad = self.xpos_pad % self.period[0] + self.ypos_pad = self.ypos_pad % self.period[1] + self.zpos_pad = self.zpos_pad % self.period[2] + yt_counters("Flipping coordinates around the periodic boundary.") + self.size = self.index.size + self.index_pad.size + # Now that we have the full size, initialize the chainID array + self.chainID = na.ones(self.size,dtype='int64') * -1 + # Clean up explicitly, but these should be empty dicts by now. + del recv_real_indices, hooks, recv_points, recv_mass + yt_counters("Communicate discriminated padding") + + def _init_kd_tree(self): + """ + Set up the data objects that get passed to the kD-tree code. + """ + yt_counters("init kd tree") + # Yes, we really do need to initialize this many arrays. + # They're deleted in _parallelHOP. + fKD.dens = na.asfortranarray(na.zeros(self.size, dtype='float64')) + fKD.mass = na.concatenate((self.mass, self.mass_pad)) + fKD.pos = na.asfortranarray(na.empty((3, self.size), dtype='float64')) + # This actually copies the data into the fortran space. + fKD.pos[0, :] = na.concatenate((self.xpos, self.xpos_pad)) + fKD.pos[1, :] = na.concatenate((self.ypos, self.ypos_pad)) + fKD.pos[2, :] = na.concatenate((self.zpos, self.zpos_pad)) + fKD.qv = na.asfortranarray(na.empty(3, dtype='float64')) + fKD.nn = self.num_neighbors + # Plus 2 because we're looking for that neighbor, but only keeping + # nMerge + 1 neighbor tags, skipping ourselves. + fKD.nMerge = self.nMerge + 2 + fKD.nparts = self.size + fKD.sort = True # Slower, but needed in _connect_chains + fKD.rearrange = self.rearrange # True is faster, but uses more memory + # Now call the fortran. + create_tree(0) + self.__max_memory() + yt_counters("init kd tree") + + def _is_inside(self, round): + """ + There are three classes of particles. + 1. Particles inside the 'real' region of each subvolume. + 2. Particles ouside, added in the 'padding' for purposes of having + correct particle densities in the real region. + 3. Particles that are one padding distance inside the edges of the + real region. The chainIDs of these particles are communicated + to the neighboring tasks so chains can be merged into groups. + The input *round* is either 'first' or 'second.' First is before the + padded particles have been communicated, and second after. + """ + # Test to see if the points are in the 'real' region + (LE, RE) = self.bounds + if round == 'first': + points = na.empty((self.real_size, 3), dtype='float64') + points[:,0] = self.xpos + points[:,1] = self.ypos + points[:,2] = self.zpos + self.is_inside = ( (points >= LE).all(axis=1) * \ + (points < RE).all(axis=1) ) + elif round == 'second': + self.is_inside = ( (fKD.pos.T >= LE).all(axis=1) * \ + (fKD.pos.T < RE).all(axis=1) ) + # Below we find out which particles are in the `annulus', one padding + # distance inside the boundaries. First we find the particles outside + # this inner boundary. + temp_LE = LE + self.max_padding + temp_RE = RE - self.max_padding + if round == 'first': + inner = na.invert( (points >= temp_LE).all(axis=1) * \ + (points < temp_RE).all(axis=1) ) + elif round == 'second' or round == 'third': + inner = na.invert( (fKD.pos.T >= temp_LE).all(axis=1) * \ + (fKD.pos.T < temp_RE).all(axis=1) ) + if round == 'first': + del points + # After inverting the logic above, we want points that are both + # inside the real region, but within one padding of the boundary, + # and this will do it. + self.is_inside_annulus = na.bitwise_and(self.is_inside, inner) + del inner + # Below we make a mapping of real particle index->local ID + # Unf. this has to be a dict, because any task can have + # particles of any particle_index, which means that if it were an + # array every task would probably end up having this array be as long + # as the full number of particles. + # We can skip this the first two times around. + if round == 'third': + temp = na.arange(self.size) + my_part = na.bitwise_or(na.invert(self.is_inside), self.is_inside_annulus) + my_part = na.bitwise_and(my_part, (self.chainID != -1)) + catted_indices = na.concatenate( + (self.index, self.index_pad))[my_part] + self.rev_index = dict.fromkeys(catted_indices) + self.rev_index.update(itertools.izip(catted_indices, temp[my_part])) + del my_part, temp, catted_indices + self.__max_memory() + + def _densestNN(self): + """ + For all particles, find their densest nearest neighbor. It is done in + chunks to keep the memory usage down. + The first search of nearest neighbors (done earlier) did not return all + num_neighbor neighbors, so we need to do it again, but we're not + keeping the all of this data, just using it. + """ + yt_counters("densestNN") + self.densestNN = na.empty(self.size,dtype='int64') + # We find nearest neighbors in chunks. + chunksize = 10000 + fKD.chunk_tags = na.asfortranarray(na.empty((self.num_neighbors, chunksize), dtype='int64')) + start = 1 # Fortran counting! + finish = 0 + while finish < self.size: + finish = min(finish+chunksize,self.size) + # Call the fortran. start and finish refer to the data locations + # in fKD.pos, and specify the range of particles to find nearest + # neighbors + fKD.start = start + fKD.finish = finish + find_chunk_nearest_neighbors() + chunk_NNtags = (fKD.chunk_tags[:,:finish-start+1] - 1).transpose() + # Find the densest nearest neighbors by referencing the already + # calculated density. + n_dens = na.take(self.density,chunk_NNtags) + max_loc = na.argmax(n_dens,axis=1) + for i in xrange(finish - start + 1): # +1 for fortran counting. + j = start + i - 1 # -1 for fortran counting. + self.densestNN[j] = chunk_NNtags[i,max_loc[i]] + start = finish + 1 + yt_counters("densestNN") + self.__max_memory() + del chunk_NNtags, max_loc, n_dens + + def _build_chains(self): + """ + Build the first round of particle chains. If the particle is too low in + density, move on. + """ + yt_counters("build_chains") + chainIDmax = 0 + self.densest_in_chain = na.ones(10000, dtype='float64') * -1 # chainID->density, one to one + self.densest_in_chain_real_index = na.ones(10000, dtype='int64') * -1 # chainID->real_index, one to one + for i in xrange(int(self.size)): + # If it's already in a group, move on, or if this particle is + # in the padding, move on because chains can only terminate in + # the padding, not begin, or if this particle is too low in + # density, move on. + if self.chainID[i] > -1 or not self.is_inside[i] or \ + self.density[i] < self.threshold: + continue + chainIDnew = self._recurse_links(i, chainIDmax) + # If the new chainID returned is the same as we entered, the chain + # has been named chainIDmax, so we need to start a new chain + # in the next loop. + if chainIDnew == chainIDmax: + chainIDmax += 1 + self.padded_particles = na.array(self.padded_particles, dtype='int64') + self.densest_in_chain = self.__clean_up_array(self.densest_in_chain) + self.densest_in_chain_real_index = self.__clean_up_array(self.densest_in_chain_real_index) + yt_counters("build_chains") + self.__max_memory() + return chainIDmax + + def _recurse_links(self, pi, chainIDmax): + """ + Recurse up the chain to a) a self-highest density particle, + b) a particle that already has a chainID, then turn it back around + assigning that chainID to where we came from. If c) which + is a particle in the padding, terminate the chain right then + and there, because chains only go one particle deep into the padding. + """ + nn = self.densestNN[pi] + inside = self.is_inside[pi] + nn_chainID = self.chainID[nn] + # Linking to an already chainID-ed particle (don't make links from + # padded particles!) + if nn_chainID > -1 and inside: + self.chainID[pi] = nn_chainID + return nn_chainID + # If pi is a self-most dense particle or inside the padding, end/create + # a new chain. + elif nn == pi or not inside: + self.chainID[pi] = chainIDmax + self.densest_in_chain = self.__add_to_array(self.densest_in_chain, + chainIDmax, self.density[pi], 'float64') + if pi < self.real_size: + self.densest_in_chain_real_index = self.__add_to_array(self.densest_in_chain_real_index, + chainIDmax, self.index[pi], 'int64') + else: + self.densest_in_chain_real_index = self.__add_to_array(self.densest_in_chain_real_index, + chainIDmax, self.index_pad[pi-self.real_size], 'int64') + # if this is a padded particle, record it for later + if not inside: + self.padded_particles.append(pi) + return chainIDmax + # Otherwise, recursively link to nearest neighbors. + else: + chainIDnew = self._recurse_links(nn, chainIDmax) + self.chainID[pi] = chainIDnew + return chainIDnew + + def _recurse_preconnected_links(self, chain_map, thisID): + if min(thisID, min(chain_map[thisID])) == thisID: + return thisID + else: + return self._recurse_preconnected_links(chain_map, min(chain_map[thisID])) + + def _preconnect_chains(self, chain_count): + """ + In each subvolume, chains that share a boundary that both have high + enough peak densities are prelinked in order to reduce the size of the + global chain objects. This is very similar to _connect_chains(). + """ + # First we'll sort them, which will be used below. + mylog.info("Locally sorting chains...") + yt_counters("preconnect_chains") + yt_counters("local chain sorting.") + sort = self.densest_in_chain.argsort() + sort = na.flipud(sort) + map = na.empty(sort.size,dtype='int64') + map[sort] = na.arange(sort.size) + self.densest_in_chain = self.densest_in_chain[sort] + self.densest_in_chain_real_index = self.densest_in_chain_real_index[sort] + del sort + for i,chID in enumerate(self.chainID): + if chID == -1: continue + self.chainID[i] = map[chID] + del map + yt_counters("local chain sorting.") + mylog.info("Preconnecting %d chains..." % chain_count) + chain_map = defaultdict(set) + for i in xrange(max(self.chainID)+1): + chain_map[i].add(i) + # Plus 2 because we're looking for that neighbor, but only keeping + # nMerge + 1 neighbor tags, skipping ourselves. + fKD.dist = na.empty(self.nMerge+2, dtype='float64') + fKD.tags = na.empty(self.nMerge+2, dtype='int64') + # We can change this here to make the searches faster. + fKD.nn = self.nMerge+2 + yt_counters("preconnect kd tree search.") + for i in xrange(self.size): + # Don't consider this particle if it's not part of a chain. + if self.chainID[i] < 0: continue + chainID_i = self.chainID[i] + # If this particle is in the padding, don't make a connection. + if not self.is_inside[i]: continue + # Find this particle's chain max_dens. + part_max_dens = self.densest_in_chain[chainID_i] + # We're only connecting >= peakthresh chains now. + if part_max_dens < self.peakthresh: continue + # Loop over nMerge closest nearest neighbors. + fKD.qv = fKD.pos[:, i] + find_nn_nearest_neighbors() + NNtags = fKD.tags[:] - 1 + same_count = 0 + for j in xrange(int(self.nMerge+1)): + thisNN = NNtags[j+1] # Don't consider ourselves at NNtags[0] + thisNN_chainID = self.chainID[thisNN] + # If our neighbor is in the same chain, move on. + # Move on if these chains are already connected: + if chainID_i == thisNN_chainID or \ + thisNN_chainID in chain_map[chainID_i]: + same_count += 1 + continue + # Everything immediately below is for + # neighboring particles with a chainID. + if thisNN_chainID >= 0: + # Find thisNN's chain's max_dens. + thisNN_max_dens = self.densest_in_chain[thisNN_chainID] + # We're only linking peakthresh chains + if thisNN_max_dens < self.peakthresh: continue + # Calculate the two groups boundary density. + boundary_density = (self.density[thisNN] + self.density[i]) / 2. + # Don't connect if the boundary is too low. + if boundary_density < self.saddlethresh: continue + # Mark these chains as related. + chain_map[thisNN_chainID].add(chainID_i) + chain_map[chainID_i].add(thisNN_chainID) + if same_count == self.nMerge + 1: + # All our neighbors are in the same chain already, so + # we don't need to search again. + self.search_again[i] = False + try: + del NNtags + except UnboundLocalError: + pass + yt_counters("preconnect kd tree search.") + # Recursively jump links until we get to a chain whose densest + # link is to itself. At that point we've found the densest chain + # in this set of sets and we keep a record of that. + yt_counters("preconnect pregrouping.") + final_chain_map = na.empty(max(self.chainID)+1, dtype='int64') + removed = 0 + for i in xrange(max(self.chainID)+1): + j = chain_count - i - 1 + densest_link = self._recurse_preconnected_links(chain_map, j) + final_chain_map[j] = densest_link + if j != densest_link: + removed += 1 + self.densest_in_chain[j] = -1 + self.densest_in_chain_real_index[j] = -1 + del chain_map + for i in xrange(self.size): + if self.chainID[i] != -1: + self.chainID[i] = final_chain_map[self.chainID[i]] + del final_chain_map + # Now make the chainID assignments consecutive. + map = na.empty(self.densest_in_chain.size, dtype='int64') + dic_new = na.empty(chain_count - removed, dtype='float64') + dicri_new = na.empty(chain_count - removed, dtype='int64') + new = 0 + for i,dic in enumerate(self.densest_in_chain): + if dic > 0: + map[i] = new + dic_new[new] = dic + dicri_new[new] = self.densest_in_chain_real_index[i] + new += 1 + else: + map[i] = -1 + for i in range(self.size): + if self.chainID[i] != -1: + self.chainID[i] = map[self.chainID[i]] + del map + self.densest_in_chain = dic_new.copy() + del dic_new + self.densest_in_chain_real_index = dicri_new.copy() + del dicri_new + self.__max_memory() + yt_counters("preconnect pregrouping.") + mylog.info("Preconnected %d chains." % removed) + yt_counters("preconnect_chains") + + return chain_count - removed + + def _globally_assign_chainIDs(self, chain_count): + """ + Convert local chainIDs into globally unique chainIDs. + """ + yt_counters("globally_assign_chainIDs") + # First find out the number of chains on each processor. + self.mine, chain_info = self._mpi_info_dict(chain_count) + self.nchains = sum(chain_info.values()) + # Figure out our offset. + self.my_first_id = sum([v for k,v in chain_info.iteritems() if k < self.mine]) + # Change particle IDs, -1 always means no chain assignment. + select = (self.chainID != -1) + select = select * self.my_first_id + self.chainID += select + del select + yt_counters("globally_assign_chainIDs") + + def _create_global_densest_in_chain(self): + """ + With the globally unique chainIDs, update densest_in_chain. + """ + yt_counters("create_global_densest_in_chain") + # Shift the values over effectively by concatenating them in the same + # order as the values have been shifted in _globally_assign_chainIDs() + yt_counters("global chain MPI stuff.") + self.densest_in_chain = self._mpi_concatenate_array_double(self.densest_in_chain) + self.densest_in_chain_real_index = self._mpi_concatenate_array_long(self.densest_in_chain_real_index) + yt_counters("global chain MPI stuff.") + # Sort the chains by density here. This is an attempt to make it such + # that the merging stuff in a few steps happens in the same order + # all the time. + mylog.info("Sorting chains...") + yt_counters("global chain sorting.") + sort = self.densest_in_chain.argsort() + sort = na.flipud(sort) + map = na.empty(sort.size,dtype='int64') + map[sort] =na.arange(sort.size) + self.densest_in_chain = self.densest_in_chain[sort] + self.densest_in_chain_real_index = self.densest_in_chain_real_index[sort] + del sort + for i,chID in enumerate(self.chainID): + if chID == -1: continue + self.chainID[i] = map[chID] + del map + yt_counters("global chain sorting.") + # For some reason chains that share the most-dense particle are not + # being linked, so we link them 'by hand' here. + mylog.info("Pre-linking chains 'by hand'...") + yt_counters("global chain hand-linking.") + # If there are no repeats, we can skip this mess entirely. + uniq = na.unique(self.densest_in_chain_real_index) + if uniq.size != self.densest_in_chain_real_index.size: + # Find only the real particle indices that are repeated to reduce + # the dict workload below. + dicri = self.densest_in_chain_real_index[self.densest_in_chain_real_index.argsort()] + diff = na.ediff1d(dicri) + diff = (diff == 0) # Picks out the places where the ids are equal + diff = na.concatenate((diff, [False])) # Makes it the same length + # This has only the repeated IDs. Sets are faster at searches than + # arrays. + dicri = set(dicri[diff]) + reverse = defaultdict(set) + # Here we find a reverse mapping of real particle ID to chainID + for chainID, real_index in enumerate(self.densest_in_chain_real_index): + if real_index in dicri: + reverse[real_index].add(chainID) + del dicri, diff + # If the real index has len(set)>1, there are multiple chains that need + # to be linked + tolink = defaultdict(set) + for real in reverse: + if len(reverse[real]) > 1: + # Unf. can't slice a set, so this will have to do. + tolink[min(reverse[real])] = reverse[real] + tolink[min(reverse[real])].discard(min(reverse[real])) + del reverse + # Now we will remove the other chains from the dicts and re-assign + # particles to their new chainID. + fix_map = {} + for tokeep in tolink: + for remove in tolink[tokeep]: + fix_map[remove] = tokeep + self.densest_in_chain[remove] = -1.0 + self.densest_in_chain_real_index[remove] = -1 + for i, chainID in enumerate(self.chainID): + try: + new = fix_map[chainID] + except KeyError: + continue + self.chainID[i] = new + del tolink, fix_map + del uniq + yt_counters("global chain hand-linking.") + yt_counters("create_global_densest_in_chain") + + def _communicate_uphill_info(self): + """ + Communicate the links to the correct neighbors from uphill_info. + """ + yt_counters("communicate_uphill_info") + # Find out how many particles we're going to receive, and make arrays + # of the right size and type to store them. + to_recv_count = 0 + temp_indices = dict.fromkeys(self.neighbors) + temp_chainIDs = dict.fromkeys(self.neighbors) + for opp_neighbor in self.neighbors: + opp_size = self.global_padded_count[opp_neighbor] + to_recv_count += opp_size + temp_indices[opp_neighbor] = na.empty(opp_size, dtype='int64') + temp_chainIDs[opp_neighbor] = na.empty(opp_size, dtype='int64') + # The arrays we'll actually keep around... + self.recv_real_indices = na.empty(to_recv_count, dtype='int64') + self.recv_chainIDs = na.empty(to_recv_count, dtype='int64') + # Set up the receives, but don't actually use them. + hooks = [] + for opp_neighbor in self.neighbors: + hooks.append(self._mpi_Irecv_long(temp_indices[opp_neighbor], opp_neighbor)) + hooks.append(self._mpi_Irecv_long(temp_chainIDs[opp_neighbor], opp_neighbor)) + # Make sure all the receive buffers are set before continuing. + self._barrier() + # Send padded particles to our neighbors. + for neighbor in self.neighbors: + hooks.append(self._mpi_Isend_long(self.uphill_real_indices, neighbor)) + hooks.append(self._mpi_Isend_long(self.uphill_chainIDs, neighbor)) + # Now actually use the data once it's good to go. + self._mpi_Request_Waitall(hooks) + self.__max_memory() + so_far = 0 + for opp_neighbor in self.neighbors: + opp_size = self.global_padded_count[opp_neighbor] + # Only save the part of the buffer that we want to the right places + # in the full listing. + self.recv_real_indices[so_far:(so_far + opp_size)] = \ + temp_indices[opp_neighbor][0:opp_size] + self.recv_chainIDs[so_far:(so_far + opp_size)] = \ + temp_chainIDs[opp_neighbor][0:opp_size] + so_far += opp_size + # Clean up. + del temp_indices, temp_chainIDs, hooks + yt_counters("communicate_uphill_info") + + def _recurse_global_chain_links(self, chainID_translate_map_global, chainID, seen): + """ + Step up the global chain links until we reach the self-densest chain, + very similarly to the recursion of particles to densest nearest + neighbors. + """ + new_chainID = chainID_translate_map_global[chainID] + if new_chainID == chainID: + return int(chainID) + elif new_chainID in seen: + # Bad things are about to happen if this condition is met! The + # padding probably needs to be increased (using the safety factor). + mylog.info('seen %s' % str(seen)) + for s in seen: + mylog.info('%d %d' % (s, chainID_translate_map_global[s])) + else: + seen.append(new_chainID) + return self._recurse_global_chain_links(chainID_translate_map_global, new_chainID, seen) + + def _connect_chains_across_tasks(self): + """ + Using the uphill links of chains, chains are linked across boundaries. + Chains that link to a remote chain are recorded, and a complete dict + of chain connections is created, globally. Then chainIDs are + reassigned recursively, assigning the ID of the most dense chainID + to every chain that links to it. + """ + yt_counters("connect_chains_across_tasks") + # Remote (lower dens) chain -> local (higher) chain. + chainID_translate_map_local = na.arange(self.nchains) + # Build the stuff to send. + self.uphill_real_indices = na.concatenate(( + self.index, self.index_pad))[self.padded_particles] + self.uphill_chainIDs = self.chainID[self.padded_particles] + del self.padded_particles + # Now we make a global dict of how many particles each task is + # sending. + self.global_padded_count = {self.mine:self.uphill_chainIDs.size} + self.global_padded_count = self._mpi_joindict(self.global_padded_count) + # Send/receive 'em. + self._communicate_uphill_info() + del self.global_padded_count + self.__max_memory() + # Fix the IDs to localIDs. + for i,real_index in enumerate(self.recv_real_indices): + try: + localID = self.rev_index[real_index] + # We don't want to update the chainIDs of my padded particles. + # Remember we are supposed to be only considering particles + # in my *real* region, that are padded in my neighbor. + if not self.is_inside[localID]: + # Make it negative so we can skip it below. + self.recv_real_indices[i] = -1 + continue + self.recv_real_indices[i] = localID + except KeyError: + # This is probably a particle we don't even own, so we want + # to ignore it. + self.recv_real_indices[i] = -1 + continue + # Now relate the local chainIDs to the received chainIDs + for i,localID in enumerate(self.recv_real_indices): + # If the 'new' chainID is different that what we already have, + # we need to record it, but we skip particles that were assigned + # -1 above. Also, since links are supposed to go only uphill, + # ensure that they are being recorded that way below. + if localID != -1 and self.chainID[localID] != -1: + if self.recv_chainIDs[i] != self.chainID[localID] and \ + self.densest_in_chain[self.chainID[localID]] >= self.densest_in_chain[self.recv_chainIDs[i]] and \ + self.densest_in_chain[self.chainID[localID]] != -1.0 and \ + self.densest_in_chain[self.recv_chainIDs[i]] != -1.0: + chainID_translate_map_local[self.recv_chainIDs[i]] = \ + self.chainID[localID] + self.__max_memory() + # In chainID_translate_map_local, chains may + # 'point' to only one chain, but a chain may have many that point to + # it. Therefore each key (a chain) in this dict is unique, but the items + # the keys point to are not necessarily unique. + chainID_translate_map_global = \ + self._mpi_minimum_array_long(chainID_translate_map_local) + # Loop over chains, smallest to largest density, recursively until + # we reach a self-assigned chain. Then we assign that final chainID to + # the *current* one only. + seen = [] + for key, density in enumerate(self.densest_in_chain): + if density == -1: continue # Skip 'deleted' chains + seen = [] + seen.append(key) + new_chainID = \ + self._recurse_global_chain_links(chainID_translate_map_global, key, seen) + chainID_translate_map_global[key] = new_chainID + # At the same time, remove chains from densest_in_chain that have + # been reassigned. + if key != new_chainID: + self.densest_in_chain[key] = -1.0 + self.densest_in_chain_real_index[key] = -1 + # Also fix nchains to keep up. + self.nchains -= 1 + self.__max_memory() + # Convert local particles to their new chainID + for i in xrange(int(self.size)): + old_chainID = self.chainID[i] + if old_chainID == -1: continue + new_chainID = chainID_translate_map_global[old_chainID] + self.chainID[i] = new_chainID + del chainID_translate_map_local, self.recv_chainIDs + del self.recv_real_indices, self.uphill_real_indices, self.uphill_chainIDs + del seen, chainID_translate_map_global + yt_counters("connect_chains_across_tasks") + + def _communicate_annulus_chainIDs(self): + """ + Transmit all of our chainID-ed particles that are within self.padding + of the boundaries to all of our neighbors. Tests show that this is + faster than trying to figure out which of the neighbors to send the data + to. + """ + yt_counters("communicate_annulus_chainIDs") + # Pick the particles in the annulus. + real_indices = na.concatenate( + (self.index, self.index_pad))[self.is_inside_annulus] + chainIDs = self.chainID[self.is_inside_annulus] + # We're done with this here. + del self.is_inside_annulus + # Eliminate un-assigned particles. + select = (chainIDs != -1) + real_indices = real_indices[select] + chainIDs = chainIDs[select] + send_count = real_indices.size + # Here distribute the counts globally. Unfortunately, it's a barrier(), + # but there's so many places in this that need to be globally synched + # that it's not worth the effort right now to make this one spot better. + global_annulus_count = {self.mine:send_count} + global_annulus_count = self._mpi_joindict(global_annulus_count) + # Set up the receiving arrays. + recv_real_indices = dict.fromkeys(self.neighbors) + recv_chainIDs = dict.fromkeys(self.neighbors) + for opp_neighbor in self.neighbors: + opp_size = global_annulus_count[opp_neighbor] + recv_real_indices[opp_neighbor] = na.empty(opp_size, dtype='int64') + recv_chainIDs[opp_neighbor] = na.empty(opp_size, dtype='int64') + # Set up the receving hooks. + hooks = [] + for opp_neighbor in self.neighbors: + hooks.append(self._mpi_Irecv_long(recv_real_indices[opp_neighbor], opp_neighbor)) + hooks.append(self._mpi_Irecv_long(recv_chainIDs[opp_neighbor], opp_neighbor)) + # Make sure the recv buffers are set before continuing. + self._barrier() + # Now we send them. + for neighbor in self.neighbors: + hooks.append(self._mpi_Isend_long(real_indices, neighbor)) + hooks.append(self._mpi_Isend_long(chainIDs, neighbor)) + # Now we use them when they're nice and ripe. + self._mpi_Request_Waitall(hooks) + self.__max_memory() + for opp_neighbor in self.neighbors: + opp_size = global_annulus_count[opp_neighbor] + # Update our local data. + for i,real_index in enumerate(recv_real_indices[opp_neighbor][0:opp_size]): + try: + localID = self.rev_index[real_index] + # We are only updating our particles that are in our + # padding, so to be rigorous we will skip particles + # that are in our real region. + if self.is_inside[localID]: + continue + self.chainID[localID] = recv_chainIDs[opp_neighbor][i] + except KeyError: + # We ignore data that's not for us. + continue + # Clean up. + del recv_real_indices, recv_chainIDs, real_indices, chainIDs, select + del hooks, global_annulus_count + # We're done with this here. + del self.rev_index + yt_counters("communicate_annulus_chainIDs") + + + def _connect_chains(self): + """ + With the set of particle chains, build a mapping of connected chainIDs + by finding the highest boundary density neighbor for each chain. Some + chains will have no neighbors! + """ + yt_counters("connect_chains") + self.chain_densest_n = {} # chainID -> {chainIDs->boundary dens} + # Plus 2 because we're looking for that neighbor, but only keeping + # nMerge + 1 neighbor tags, skipping ourselves. + fKD.dist = na.empty(self.nMerge+2, dtype='float64') + fKD.tags = na.empty(self.nMerge+2, dtype='int64') + # We can change this here to make the searches faster. + fKD.nn = self.nMerge+2 + for i in xrange(int(self.size)): + # Don't consider this particle if it's not part of a chain. + if self.chainID[i] < 0: continue + # If this particle is in the padding, don't make a connection. + if not self.is_inside[i]: continue + # Make sure that we should search this particle again. + if not self.search_again[i]: continue + # Find this particle's chain max_dens. + part_max_dens = self.densest_in_chain[self.chainID[i]] + # Make sure we're skipping deleted chains. + if part_max_dens == -1.0: continue + # Loop over nMerge closest nearest neighbors. + fKD.qv = fKD.pos[:, i] + find_nn_nearest_neighbors() + NNtags = fKD.tags[:] - 1 + for j in xrange(int(self.nMerge+1)): + thisNN = NNtags[j+1] # Don't consider ourselves at NNtags[0] + thisNN_chainID = self.chainID[thisNN] + # If our neighbor is in the same chain, move on. + if self.chainID[i] == thisNN_chainID: continue + # Everything immediately below is for + # neighboring particles with a chainID. + if thisNN_chainID >= 0: + # Find thisNN's chain's max_dens. + thisNN_max_dens = self.densest_in_chain[thisNN_chainID] + if thisNN_max_dens == -1.0: continue + # Calculate the two groups boundary density. + boundary_density = (self.density[thisNN] + self.density[i]) / 2. + # Find out who's denser. + if thisNN_max_dens >= part_max_dens: + higher_chain = thisNN_chainID + lower_chain = self.chainID[i] + else: + higher_chain = self.chainID[i] + lower_chain = thisNN_chainID + # Make sure that the higher density chain has an entry. + try: + test = self.chain_densest_n[int(higher_chain)] + except KeyError: + self.chain_densest_n[int(higher_chain)] = {} + # See if this boundary density is higher than + # previously recorded for this pair of chains. + # Links only go one direction. + try: + old = self.chain_densest_n[int(higher_chain)][int(lower_chain)] + if old < boundary_density: + # make this the new densest boundary between this pair + self.chain_densest_n[int(higher_chain)][int(lower_chain)] = \ + boundary_density + except KeyError: + # we haven't seen this pairing before, record this as the + # new densest boundary between chains + self.chain_densest_n[int(higher_chain)][int(lower_chain)] = \ + boundary_density + else: + continue + try: + del point, NNtags, results + except UnboundLocalError: + pass + self.__max_memory() + yt_counters("connect_chains") + + def _make_global_chain_densest_n(self): + """ + We want to record the maximum boundary density between all chains on + all tasks. + """ + yt_counters("make_global_chain_densest_n") + (self.top_keys, self.bot_keys, self.vals) = \ + self._mpi_maxdict_dict(self.chain_densest_n) + self.__max_memory() + del self.chain_densest_n + yt_counters("make_global_chain_densest_n") + + def _build_groups(self): + """ + With the collection of possible chain links, build groups. + """ + yt_counters("build_groups") + # We need to find out which pairs of self.top_keys, self.bot_keys are + # both < self.peakthresh, and create arrays that will store this + # relationship. + both = na.bitwise_and((self.densest_in_chain[self.top_keys] < self.peakthresh), + (self.densest_in_chain[self.bot_keys] < self.peakthresh)) + g_high = self.top_keys[both] + g_low = self.bot_keys[both] + g_dens = self.vals[both] + del both + self.reverse_map = na.ones(self.densest_in_chain.size) * -1 + densestbound = na.ones(self.densest_in_chain.size) * -1.0 + for i, gl in enumerate(g_low): + if g_dens[i] > densestbound[gl]: + densestbound[gl] = g_dens[i] + groupID = 0 + # First assign a group to all chains with max_dens above peakthresh. + # The initial groupIDs will be assigned with decending peak density. + # This guarantees that the group with the smaller groupID is the + # higher chain, as in chain_high below. + for chainID,density in enumerate(self.densest_in_chain): + if density == -1.0: continue + if self.densest_in_chain[chainID] >= self.peakthresh: + self.reverse_map[chainID] = groupID + groupID += 1 + group_equivalancy_map = na.empty(groupID, dtype='object') + for i in xrange(groupID): + group_equivalancy_map[i] = set([]) + # Loop over all of the chain linkages. + for i,chain_high in enumerate(self.top_keys): + chain_low = self.bot_keys[i] + dens = self.vals[i] + max_dens_high = self.densest_in_chain[chain_high] + max_dens_low = self.densest_in_chain[chain_low] + if max_dens_high == -1.0 or max_dens_low == -1.0: continue + # If neither are peak density groups, mark them for later + # consideration. + if max_dens_high < self.peakthresh and \ + max_dens_low < self.peakthresh: + # This step is now done vectorized above, with the g_dens + # stuff. + continue + # If both are peak density groups, and have a boundary density + # that is high enough, make them into a group, otherwise + # move onto another linkage. + if max_dens_high >= self.peakthresh and \ + max_dens_low >= self.peakthresh: + if dens < self.saddlethresh: + continue + else: + group_high = self.reverse_map[chain_high] + group_low = self.reverse_map[chain_low] + if group_high == -1 or group_low == -1: continue + # Both are already identified as groups, so we need + # to re-assign the less dense group to the denser + # groupID. + if group_low != group_high: + group_equivalancy_map[group_low].add(group_high) + group_equivalancy_map[group_high].add(group_low) + continue + # Else, one is above peakthresh, the other below + # find out if this is the densest boundary seen so far for + # the lower chain. + group_high = self.reverse_map[chain_high] + if group_high == -1: continue + if dens >= densestbound[chain_low]: + densestbound[chain_low] = dens + self.reverse_map[chain_low] = group_high + self.__max_memory() + del self.top_keys, self.bot_keys, self.vals + # Now refactor group_equivalancy_map back into reverse_map. The group + # mapping may be more than one link long, so we need to do it + # recursively. The best way to think about this is a field full of + # rabbit holes. The holes are connected at nexuses at the surface. + # Each groupID (key) in group_equivalancy_map represents a hole, and + # the values the nexuses are the tunnels lead to. The tunnels are two-way, + # and when you go through it, you block the passage through that + # tunnel in that direction, so you don't repeat yourself later. You can + # go back through that tunnel, but your search ends there because all + # the other tunnels have been closed at the old nexus. In this fashion your search + # spreads out like the water shooting out of the ground in 'Caddy + # Shack.' + Set_list = [] + # We only want the holes that are modulo mine. + keys = na.arange(groupID, dtype='int64') + size = self._mpi_get_size() + select = (keys % size == self.mine) + groupIDs = keys[select] + mine_groupIDs = set([]) # Records only ones modulo mine. + not_mine_groupIDs = set([]) # All the others. + # Declare these to prevent Errors when they're del-ed below, in case + # this task doesn't create them in the loop, for whatever reason. + current_sets, new_mine, new_other = [], [], [] + new_set, final_set, to_add_set, liter = set([]), set([]), set([]), set([]) + to_add_set = set([]) + for groupID in groupIDs: + if groupID in mine_groupIDs: + continue + mine_groupIDs.add(groupID) + current_sets = [] + new_set = group_equivalancy_map[groupID] + final_set = new_set.copy() + while len(new_set) > 0: + to_add_set = set([]) + liter = new_set.difference(mine_groupIDs).difference(not_mine_groupIDs) + new_mine, new_other = [], [] + for link_gID in liter: + to_add_set.update(group_equivalancy_map[link_gID]) + if link_gID % size == self.mine: + new_mine.append(link_gID) + else: + new_other.append(link_gID) + mine_groupIDs.update(new_mine) + not_mine_groupIDs.update(new_other) + final_set.update(to_add_set) + new_set = to_add_set + # Make sure it's not empty + final_set.add(groupID) + Set_list.append(final_set) + self.__max_memory() + del group_equivalancy_map, final_set, keys, select, groupIDs, current_sets + del mine_groupIDs, not_mine_groupIDs, new_set, to_add_set, liter + # Convert this list of sets into a look-up table + lookup = na.ones(self.densest_in_chain.size, dtype='int64') * (self.densest_in_chain.size + 2) + for i,item in enumerate(Set_list): + item_min = min(item) + for groupID in item: + lookup[groupID] = item_min + self.__max_memory() + del Set_list + # To bring it all together, find the minimum values at each entry + # globally. + lookup = self._mpi_minimum_array_long(lookup) + # Now apply this to reverse_map + for chainID,groupID in enumerate(self.reverse_map): + if groupID == -1: + continue + if lookup[groupID] != (self.densest_in_chain.size + 2): + self.reverse_map[chainID] = lookup[groupID] + del lookup + """ + Now the fringe chains are connected to the proper group + (>peakthresh) with the largest boundary. But we want to look + through the boundaries between fringe groups to propagate this + along. Connections are only as good as their smallest boundary + """ + changes = 1 + while changes: + changes = 0 + for j,dens in enumerate(g_dens): + chain_high = g_high[j] + chain_low = g_low[j] + # If the density of this boundary and the densestbound of + # the other chain is higher than a chain's densestbound, then + # replace it. We also don't want to link to un-assigned + # neighbors, and we can skip neighbors we're already assigned to. + if dens >= densestbound[chain_low] and \ + densestbound[chain_high] > densestbound[chain_low] and \ + self.reverse_map[chain_high] != -1 and \ + self.reverse_map[chain_low] != self.reverse_map[chain_high]: + changes += 1 + if dens < densestbound[chain_high]: + densestbound[chain_low] = dens + else: + densestbound[chain_low] = densestbound[chain_high] + self.reverse_map[chain_low] = self.reverse_map[chain_high] + self.__max_memory() + del g_high, g_low, g_dens, densestbound + # Now we have to find the unique groupIDs, since they may have been + # merged. + temp = list(set(self.reverse_map)) + # Remove -1 from the list. + try: + temp.pop(temp.index(-1)) + except ValueError: + # There are no groups, probably. + pass + # Make a secondary map to make the IDs consecutive. + values = na.arange(len(temp)) + secondary_map = dict(itertools.izip(temp, values)) + del values + # Update reverse_map + for chain, map in enumerate(self.reverse_map): + # Don't attempt to fix non-assigned chains. + if map == -1: continue + self.reverse_map[chain] = secondary_map[map] + group_count = len(temp) + del secondary_map, temp + yt_counters("build_groups") + self.__max_memory() + return group_count + + def _translate_groupIDs(self, group_count): + """ + Using the maps, convert the particle chainIDs into their locally-final + groupIDs. + """ + yt_counters("translate_groupIDs") + self.I_own = set([]) + for i in xrange(int(self.size)): + # Don't translate non-affiliated particles. + if self.chainID[i] == -1: continue + # We want to remove the group tag from padded particles, + # so when we return it to HaloFinding, there is no duplication. + if self.is_inside[i]: + self.chainID[i] = self.reverse_map[self.chainID[i]] + self.I_own.add(self.chainID[i]) + else: + self.chainID[i] = -1 + del self.is_inside + # Create a densest_in_group, analogous to densest_in_chain. + keys = na.arange(group_count) + vals = na.zeros(group_count) + self.densest_in_group = dict(itertools.izip(keys,vals)) + self.densest_in_group_real_index = self.densest_in_group.copy() + del keys, vals + for chainID,max_dens in enumerate(self.densest_in_chain): + if max_dens == -1.0: continue + groupID = self.reverse_map[chainID] + if groupID == -1: continue + if self.densest_in_group[groupID] < max_dens: + self.densest_in_group[groupID] = max_dens + self.densest_in_group_real_index[groupID] = self.densest_in_chain_real_index[chainID] + del self.densest_in_chain, self.densest_in_chain_real_index, self.reverse_map + del self.densest_in_group + yt_counters("translate_groupIDs") + + def _precompute_group_info(self): + yt_counters("Precomp.") + """ + For all groups, compute the various global properties, except bulk + velocity, to save time in HaloFinding.py (fewer barriers!). + """ + select = (self.chainID != -1) + calc = len(na.where(select == True)[0]) + loc = na.empty((calc, 3), dtype='float64') + loc[:, 0] = na.concatenate((self.xpos, self.xpos_pad))[select] + loc[:, 1] = na.concatenate((self.ypos, self.ypos_pad))[select] + loc[:, 2] = na.concatenate((self.zpos, self.zpos_pad))[select] + self.__max_memory() + del self.xpos_pad, self.ypos_pad, self.zpos_pad + subchain = self.chainID[select] + # First we need to find the maximum density point for all groups. + # I think this will be faster than several vector operations that need + # to pull the entire chainID array out of memory several times. + yt_counters("max dens point") + max_dens_point = na.zeros((self.group_count,4),dtype='float64') + for i,part in enumerate(na.arange(self.size)[select]): + groupID = self.chainID[part] + if part < self.real_size: + real_index = self.index[part] + else: + real_index = self.index_pad[part - self.real_size] + if real_index == self.densest_in_group_real_index[groupID]: + max_dens_point[groupID] = na.array([self.density[part], \ + loc[i, 0], loc[i, 1], loc[i, 2]]) + del self.index, self.index_pad, self.densest_in_group_real_index + # Now we broadcast this, effectively, with an allsum. Even though + # some groups are on multiple tasks, there is only one densest_in_chain + # and only that task contributed above. + self.max_dens_point = self._mpi_Allsum_double(max_dens_point) + del max_dens_point + yt_counters("max dens point") + # Now CoM. + yt_counters("CoM") + CoM_M = na.zeros((self.group_count,3),dtype='float64') + Tot_M = na.zeros(self.group_count, dtype='float64') + #c_vec = self.max_dens_point[:,1:4][subchain] - na.array([0.5,0.5,0.5]) + if calc: + c_vec = self.max_dens_point[:,1:4][subchain] - na.array([0.5,0.5,0.5]) + size = na.bincount(self.chainID[select]).astype('int64') + else: + # This task has no particles in groups! + size = na.zeros(self.group_count, dtype='int64') + # In case this task doesn't have all the groups, add trailing zeros. + if size.size != self.group_count: + size = na.concatenate((size, na.zeros(self.group_count - size.size, dtype='int64'))) + if calc: + cc = loc - c_vec + cc = cc - na.floor(cc) + ms = na.concatenate((self.mass, self.mass_pad))[select] + # Most of the time, the masses will be all the same, and we can try + # to save some effort. + ms_u = na.unique(ms) + if ms_u.size == 1: + single = True + Tot_M = size.astype('float64') * ms_u + del ms_u + else: + single = False + del ms_u + cc[:,0] = cc[:,0] * ms + cc[:,1] = cc[:,1] * ms + cc[:,2] = cc[:,2] * ms + sort = subchain.argsort() + cc = cc[sort] + sort_subchain = subchain[sort] + uniq_subchain = na.unique(sort_subchain) + diff_subchain = na.ediff1d(sort_subchain) + marks = (diff_subchain > 0) + marks = na.arange(calc)[marks] + 1 + marks = na.concatenate(([0], marks, [calc])) + for i, u in enumerate(uniq_subchain): + CoM_M[u] = na.sum(cc[marks[i]:marks[i+1]], axis=0) + if not single: + for i,groupID in enumerate(subchain): + Tot_M[groupID] += ms[i] + del cc, ms + for groupID in xrange(int(self.group_count)): + # Don't divide by zero. + if groupID in self.I_own: + CoM_M[groupID] /= Tot_M[groupID] + CoM_M[groupID] += self.max_dens_point[groupID,1:4] - na.array([0.5,0.5,0.5]) + CoM_M[groupID] *= Tot_M[groupID] + # Now we find their global values + self.group_sizes = self._mpi_Allsum_long(size) + CoM_M = self._mpi_Allsum_double(CoM_M) + self.Tot_M = self._mpi_Allsum_double(Tot_M) + self.CoM = na.empty((self.group_count,3), dtype='float64') + for groupID in xrange(int(self.group_count)): + self.CoM[groupID] = CoM_M[groupID] / self.Tot_M[groupID] + yt_counters("CoM") + self.__max_memory() + # Now we find the maximum radius for all groups. + yt_counters("max radius") + max_radius = na.zeros(self.group_count, dtype='float64') + if calc: + com = self.CoM[subchain] + rad = na.fabs(com - loc) + dist = (na.minimum(rad, self.period - rad)**2.).sum(axis=1) + dist = dist[sort] + for i, u in enumerate(uniq_subchain): + max_radius[u] = na.max(dist[marks[i]:marks[i+1]]) + # Find the maximum across all tasks. + mylog.info('Fraction of particles in this region in groups: %f' % (float(calc)/self.size)) + self.max_radius = self._mpi_double_array_max(max_radius) + self.max_radius = na.sqrt(self.max_radius) + yt_counters("max radius") + yt_counters("Precomp.") + self.__max_memory() + del select, loc, subchain, CoM_M, Tot_M, size, max_radius + if calc: + del c_vec + del sort_subchain, uniq_subchain, diff_subchain, marks, dist, sort + del rad, com + + def _chain_hop(self): + self._global_padding('first') + self._global_bounds_neighbors() + self._global_padding('second') + self._is_inside('first') + mylog.info('Distributing padded particles...') + self._communicate_padding_data() + mylog.info('Building kd tree for %d particles...' % \ + self.size) + self._init_kd_tree() + # Mark particles in as being in/out of the domain. + self._is_inside('second') + # Loop over the particles to find NN for each. + mylog.info('Finding nearest neighbors/density...') + yt_counters("chainHOP_tags_dens") + chainHOP_tags_dens() + yt_counters("chainHOP_tags_dens") + self.density = fKD.dens.copy() + # Now each particle has NNtags, and a local self density. + # Let's find densest NN + mylog.info('Finding densest nearest neighbors...') + self._densestNN() + # Build the chain of links. + mylog.info('Building particle chains...') + chain_count = self._build_chains() + # This array tracks whether or not relationships for this particle + # need to be examined twice, in preconnect_chains and in connect_chains + self.search_again = na.ones(self.size, dtype='bool') + if self.premerge: + chain_count = self._preconnect_chains(chain_count) + mylog.info('Gobally assigning chainIDs...') + self._globally_assign_chainIDs(chain_count) + mylog.info('Globally finding densest in chains...') + self._create_global_densest_in_chain() + mylog.info('Building chain connections across tasks...') + self._is_inside('third') + self._connect_chains_across_tasks() + mylog.info('Communicating connected chains...') + self._communicate_annulus_chainIDs() + mylog.info('Connecting %d chains into groups...' % self.nchains) + self._connect_chains() + del fKD.dens, fKD.mass, fKD.dens + del fKD.pos, fKD.chunk_tags + free_tree(0) # Frees the kdtree object. + del self.densestNN + mylog.info('Communicating group links globally...') + self._make_global_chain_densest_n() + mylog.info('Building final groups...') + group_count = self._build_groups() + self.group_count = group_count + mylog.info('Remapping particles to final groups...') + self._translate_groupIDs(group_count) + mylog.info('Precomputing info for %d groups...' % group_count) + self._precompute_group_info() + mylog.info("All done! Max Memory = %d MB" % self.max_mem) + # We need to fix chainID and density because HaloFinding is expecting + # an array only as long as the real data. + self.chainID = self.chainID[:self.real_size] + self.density = self.density[:self.real_size] + # We'll make this a global object, which can be used to write a text + # file giving the names of hdf5 files the particles for each halo. + self.mine, self.I_own = self._mpi_info_dict(self.I_own) + self.halo_taskmap = defaultdict(set) + for taskID in self.I_own: + for groupID in self.I_own[taskID]: + self.halo_taskmap[groupID].add(taskID) + del self.I_own + del self.mass, self.xpos, self.ypos, self.zpos + + def __add_to_array(self, arr, key, value, type): + """ + In an effort to replace the functionality of a dict with an array, in + order to save memory, this function adds items to an array. If the + array is not long enough, it is resized and filled with 'bad' values.""" + + try: + arr[key] = value + except IndexError: + arr = na.concatenate((arr, na.ones(10000, dtype=type)*-1)) + arr[key] = value + return arr + + def __clean_up_array(self, arr): + good = (arr != -1) + return arr[good] + + def __max_memory(self): + my_mem = get_memory_usage() + self.max_mem = max(my_mem, self.max_mem) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/parallel_hop/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/parallel_hop/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('parallel_hop_interface',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_finding/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_finding/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('halo_finding',parent_package,top_path) + config.add_subpackage("fof") + config.add_subpackage("hop") + config.add_subpackage("parallel_hop") + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_mass_function/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_mass_function/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,34 @@ +""" +API for halo_mass_function + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .halo_mass_function import \ + HaloMassFcn, \ + TransferFunction, \ + integrate_inf diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_mass_function/halo_mass_function.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_mass_function/halo_mass_function.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,740 @@ +""" +halo_mass_function - Halo Mass Function and supporting functions. + +Author: Stephen Skory +Affiliation: UC San Diego / CASS +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Stephen Skory (and others). 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 . +""" + +import numpy as na +import math, time + +from yt.funcs import * +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelDummy, \ + ParallelAnalysisInterface, \ + parallel_blocking_call + +class HaloMassFcn(ParallelAnalysisInterface): + def __init__(self, pf, halo_file=None, omega_matter0=None, omega_lambda0=None, + omega_baryon0=0.05, hubble0=None, sigma8input=0.86, primordial_index=1.0, + this_redshift=None, log_mass_min=None, log_mass_max=None, num_sigma_bins=360, + fitting_function=4, mass_column=5): + """ + Initalize a HaloMassFcn object to analyze the distribution of haloes + as a function of mass. + :param halo_file (str): The filename of the output of the Halo Profiler. + Default=None. + :param omega_matter0 (float): The fraction of the universe made up of + matter (dark and baryonic). Default=None. + :param omega_lambda0 (float): The fraction of the universe made up of + dark energy. Default=None. + :param omega_baryon0 (float): The fraction of the universe made up of + ordinary baryonic matter. This should match the value + used to create the initial conditions, using 'inits'. This is + *not* stored in the enzo datset so it must be checked by hand. + Default=0.05. + :param hubble0 (float): The expansion rate of the universe in units of + 100 km/s/Mpc. Default=None. + :param sigma8input (float): The amplitude of the linear power + spectrum at z=0 as specified by the rms amplitude of mass-fluctuations + in a top-hat sphere of radius 8 Mpc/h. This should match the value + used to create the initial conditions, using 'inits'. This is + *not* stored in the enzo datset so it must be checked by hand. + Default=0.86. + :param primoridal_index (float): This is the index of the mass power + spectrum before modification by the transfer function. A value of 1 + corresponds to the scale-free primordial spectrum. This should match + the value used to make the initial conditions using 'inits'. This is + *not* stored in the enzo datset so it must be checked by hand. + Default=1.0. + :param this_redshift (float): The current redshift. Default=None. + :param log_mass_min (float): The log10 of the mass of the minimum of the + halo mass range. Default=None. + :param log_mass_max (float): The log10 of the mass of the maximum of the + halo mass range. Default=None. + :param num_sigma_bins (float): The number of bins (points) to use for + the calculations and generated fit. Default=360. + :param fitting_function (int): Which fitting function to use. + 1 = Press-schechter, 2 = Jenkins, 3 = Sheth-Tormen, 4 = Warren fit + 5 = Tinker + Default=4. + :param mass_column (int): The column of halo_file that contains the + masses of the haloes. Default=4. + """ + self.pf = pf + self.halo_file = halo_file + self.omega_matter0 = omega_matter0 + self.omega_lambda0 = omega_lambda0 + self.omega_baryon0 = omega_baryon0 + self.hubble0 = hubble0 + self.sigma8input = sigma8input + self.primordial_index = primordial_index + self.this_redshift = this_redshift + self.log_mass_min = log_mass_min + self.log_mass_max = log_mass_max + self.num_sigma_bins = num_sigma_bins + self.fitting_function = fitting_function + self.mass_column = mass_column + + # Determine the run mode. + if halo_file is None: + # We are hand-picking our various cosmological parameters + self.mode = 'single' + else: + # Make the fit using the same cosmological parameters as the dataset. + self.mode = 'haloes' + self.omega_matter0 = self.pf.omega_matter + self.omega_lambda0 = self.pf.omega_lambda + self.hubble0 = self.pf.hubble_constant + self.this_redshift = self.pf.current_redshift + self.read_haloes() + if self.log_mass_min == None: + self.log_mass_min = math.log10(min(self.haloes)) + if self.log_mass_max == None: + self.log_mass_max = math.log10(max(self.haloes)) + + # Input error check. + if self.mode == 'single': + if omega_matter0 == None or omega_lambda0 == None or \ + hubble0 == None or this_redshift == None or log_mass_min == None or\ + log_mass_max == None: + mylog.error("All of these parameters need to be set:") + mylog.error("[omega_matter0, omega_lambda0, \ + hubble0, this_redshift, log_mass_min, log_mass_max]") + mylog.error("[%s,%s,%s,%s,%s,%s]" % (omega_matter0,\ + omega_lambda0, hubble0, this_redshift,\ + log_mass_min, log_mass_max)) + return None + + # Poke the user to make sure they're doing it right. + mylog.info( + """ + Please make sure these are the correct values! They are + not stored in enzo datasets, so must be entered by hand. + sigma8input=%f primordial_index=%f omega_baryon0=%f + """ % (self.sigma8input, self.primordial_index, self.omega_baryon0)) + time.sleep(1) + + # Do the calculations. + self.sigmaM() + self.dndm() + + if self.mode == 'haloes': + self.bin_haloes() + + def write_out(self, prefix='HMF', fit=True, haloes=True): + """ + Writes out the halo mass functions to file(s) with prefix *prefix*. + """ + # First the fit file. + if fit: + fitname = prefix + '-fit.dat' + fp = self._write_on_root(fitname) + line = \ + """#Columns: +#1. log10 of mass (Msolar, NOT Msolar/h) +#2. mass (Msolar/h) +#3. (dn/dM)*dM (differential number density of haloes, per Mpc^3 (NOT h^3/Mpc^3) +#4. cumulative number density of halos (per Mpc^3, NOT h^3/Mpc^3) +""" + fp.write(line) + for i in xrange(self.logmassarray.size - 1): + line = "%e\t%e\t%e\t%e\n" % (self.logmassarray[i], self.massarray[i], + self.dn_M_z[i], self.nofmz_cum[i]) + fp.write(line) + fp.close() + if self.mode == 'haloes' and haloes: + haloname = prefix + '-haloes.dat' + fp = self._write_on_root(haloname) + line = \ + """#Columns: +#1. log10 of mass (Msolar, NOT Msolar/h) +#2. mass (Msolar/h) +#3. cumulative number density of haloes (per Mpc^3, NOT h^3/Mpc^3) +""" + fp.write(line) + for i in xrange(self.logmassarray.size - 1): + line = "%e\t%e\t%e\n" % (self.logmassarray[i], self.massarray[i], + self.dis[i]) + fp.write(line) + fp.close() + + def read_haloes(self): + """ + Read in the virial masses of the haloes. + """ + mylog.info("Reading halo masses from %s" % self.halo_file) + f = open(self.halo_file,'r') + line = f.readline() + if line == "": + self.haloes = na.array([]) + return + while line[0] == '#': + line = f.readline() + self.haloes = [] + while line: + line = line.split() + mass = float(line[self.mass_column]) + if mass > 0: + self.haloes.append(float(line[self.mass_column])) + line = f.readline() + f.close() + self.haloes = na.array(self.haloes) + + def bin_haloes(self): + """ + With the list of virial masses, find the halo mass function. + """ + bins = na.logspace(self.log_mass_min, + self.log_mass_max,self.num_sigma_bins) + avgs = (bins[1:]+bins[:-1])/2. + dis, bins = na.histogram(self.haloes,bins,new=True) + # add right to left + for i,b in enumerate(dis): + dis[self.num_sigma_bins-i-3] += dis[self.num_sigma_bins-i-2] + if i == (self.num_sigma_bins - 3): break + + self.dis = dis / self.pf['CosmologyComovingBoxSize']**3.0 * self.hubble0**3.0 + + def sigmaM(self): + """ + Written by BWO, 2006 (updated 25 January 2007). + Converted to Python by Stephen Skory December 2009. + + This routine takes in cosmological parameters and creates a file (array) with + sigma(M) in it, which is necessary for various press-schechter type + stuff. In principle one can calculate it ahead of time, but it's far, + far faster in the long run to calculate your sigma(M) ahead of time. + + Inputs: cosmology, user must set parameters + + Outputs: four columns of data containing the following information: + + 1) log mass (Msolar) + 2) mass (Msolar/h) + 3) Radius (comoving Mpc/h) + 4) sigma (normalized) using Msun/h as the input + + The arrays output are used later. + """ + + # Set up the transfer function object. + self.TF = TransferFunction(self.omega_matter0, self.omega_baryon0, 0.0, 0, + self.omega_lambda0, self.hubble0, self.this_redshift); + + if self.TF.qwarn: + mylog.error("You should probably fix your cosmology parameters!") + + # output arrays + # 1) log10 of mass (Msolar, NOT Msolar/h) + self.Rarray = na.empty(self.num_sigma_bins,dtype='float64') + # 2) mass (Msolar/h) + self.logmassarray = na.empty(self.num_sigma_bins, dtype='float64') + # 3) spatial scale corresponding to that radius (Mpc/h) + self.massarray = na.empty(self.num_sigma_bins, dtype='float64') + # 4) sigma(M, z=0, where mass is in Msun/h) + self.sigmaarray = na.empty(self.num_sigma_bins, dtype='float64') + + # get sigma_8 normalization + R = 8.0; # in units of Mpc/h (comoving) + + sigma8_unnorm = math.sqrt(self.sigma_squared_of_R(R)); + sigma_normalization = self.sigma8input / sigma8_unnorm; + + rho0 = self.omega_matter0 * 2.78e+11; # in units of h^2 Msolar/Mpc^3 + + # spacing in mass of our sigma calculation + dm = (float(self.log_mass_max) - self.log_mass_min)/self.num_sigma_bins; + + """ + loop over the total number of sigma_bins the user has requested. + For each bin, calculate mass and equivalent radius, and call + sigma_squared_of_R to get the sigma(R) (equivalent to sigma(M)), + normalize by user-specified sigma_8, and then write out. + """ + for i in xrange(self.num_sigma_bins): + + # thislogmass is in units of Msolar, NOT Msolar/h + thislogmass = self.log_mass_min + i*dm + + # mass in units of h^-1 Msolar + thismass = math.pow(10.0, thislogmass) * self.hubble0; + + # radius is in units of h^-1 Mpc (comoving) + thisradius = math.pow( 3.0*thismass / 4.0 / math.pi / rho0, 1.0/3.0 ); + + R = thisradius; # h^-1 Mpc (comoving) + + self.Rarray[i] = thisradius; # h^-1 Mpc (comoving) + self.logmassarray[i] = thislogmass; # Msun (NOT Msun/h) + self.massarray[i] = thismass; # Msun/h + + # get normalized sigma(R) + self.sigmaarray[i] = math.sqrt(self.sigma_squared_of_R(R)) * sigma_normalization; + # All done! + + def dndm(self): + + # constants - set these before calling any functions! + rho0 = self.omega_matter0 * 2.78e+11; # in units of h^2 Msolar/Mpc^3 + self.delta_c0 = 1.69; # critical density for turnaround (Press-Schechter) + + nofmz_cum = 0.0; # keep track of cumulative number density + + # Loop over masses, going BACKWARD, and calculate dn/dm as well as the + # cumulative mass function. + + # output arrays + # 5) (dn/dM)*dM (differential number density of halos, per Mpc^3 (NOT h^3/Mpc^3) + self.dn_M_z = na.empty(self.num_sigma_bins, dtype='float64') + # 6) cumulative number density of halos (per Mpc^3, NOT h^3/Mpc^3) + self.nofmz_cum = na.zeros(self.num_sigma_bins, dtype='float64') + + for j in xrange(self.num_sigma_bins - 1): + i = (self.num_sigma_bins - 2) - j + + thissigma = self.sigmaof_M_z(i, self.this_redshift); + nextsigma = self.sigmaof_M_z(i+1, self.this_redshift); + + # calc dsigmadm - has units of h (since massarray has units of h^-1) + dsigmadm = (nextsigma-thissigma) / (self.massarray[i+1] - self.massarray[i]); + + # calculate dn(M,z) (dn/dM * dM) + # this has units of h^3 since rho0 has units of h^2, dsigmadm + # has units of h, and massarray has units of h^-1 + dn_M_z = -1.0 / thissigma * dsigmadm * rho0 / self.massarray[i] * \ + self.multiplicityfunction(thissigma)*(self.massarray[i+1] - self.massarray[i]); + + # scale by h^4 to get rid of all factors of h + dn_M_z *= math.pow(self.hubble0, 4.0); + + # keep track of cumulative number density + if dn_M_z > 1.0e-20: + nofmz_cum += dn_M_z; + + # Store this. + self.nofmz_cum[i] = nofmz_cum + self.dn_M_z[i] = dn_M_z + + + def sigma_squared_of_R(self, R): + """ + /* calculates sigma^2(R). This is the routine where the magic happens (or + whatever it is that we do here). Integrates the sigma_squared_integrand + parameter from R to infinity. Calls GSL (gnu scientific library) to do + the actual integration. + + Note that R is in h^-1 Mpc (comoving) + */ + """ + self.R = R + result = integrate_inf(self.sigma_squared_integrand) + + sigmasquaredofR = result / 2.0 / math.pi / math.pi + + return sigmasquaredofR; + + def sigma_squared_integrand(self, k): + """ + /* integrand for integral to get sigma^2(R). */ + """ + + Rcom = self.R; # this is R in comoving Mpc/h + + f = k*k*self.PofK(k)*na.power( abs(self.WofK(Rcom,k)), 2.0); + + return f + + def PofK(self, k): + """ + /* returns power spectrum as a function of wavenumber k */ + """ + + thisPofK = na.power(k, self.primordial_index) * na.power( self.TofK(k), 2.0); + + return thisPofK; + + def TofK(self, k): + """ + /* returns transfer function as a function of wavenumber k. */ + """ + + thisTofK = self.TF.TFmdm_onek_hmpc(k); + + return thisTofK; + + def WofK(self, R, k): + """ + returns W(k), which is the fourier transform of the top-hat function. + """ + + x = R*k; + + thisWofK = 3.0 * ( na.sin(x) - x*na.cos(x) ) / (x*x*x); + + return thisWofK; + + def multiplicityfunction(self, sigma): + """ + /* Multiplicity function - this is where the various fitting functions/analytic + theories are different. The various places where I found these fitting functions + are listed below. */ + """ + + nu = self.delta_c0 / sigma; + + if self.fitting_function==1: + # Press-Schechter (This form from Jenkins et al. 2001, MNRAS 321, 372-384, eqtn. 5) + thismult = math.sqrt(2.0/math.pi) * nu * math.exp(-0.5*nu*nu); + + elif self.fitting_function==2: + # Jenkins et al. 2001, MNRAS 321, 372-384, eqtn. 9 + thismult = 0.315 * math.exp( -1.0 * math.pow( abs( math.log(1.0/sigma) + 0.61), 3.8 ) ); + + elif self.fitting_function==3: + # Sheth-Tormen 1999, eqtn 10, using expression from Jenkins et al. 2001, eqtn. 7 + A=0.3222; + a=0.707; + p=0.3; + thismult = A*math.sqrt(2.0*a/math.pi)*(1.0+ math.pow( 1.0/(nu*nu*a), p) )*\ + nu * math.exp(-0.5*a*nu*nu); + + elif self.fitting_function==4: + # LANL fitting function - Warren et al. 2005, astro-ph/0506395, eqtn. 5 + A=0.7234; + a=1.625; + b=0.2538; + c=1.1982; + thismult = A*( math.pow(sigma, -1.0*a) + b)*math.exp(-1.0*c / sigma / sigma ); + + elif self.fitting_function==5: + # Tinker et al. 2008, eqn 3, \Delta=300 # \Delta=200 + A = 0.2 #0.186 + a = 1.52 #1.47 + b = 2.25 #2.57 + c = 1.27 #1.19 + thismult = A * ( math.pow((sigma / b), -a) + 1) * \ + math.exp(-1 * c / sigma / sigma) + + else: + mylog.error("Don't understand this. Fitting function requested is %d\n", + self.fitting_function) + return None + + return thismult + + def sigmaof_M_z(self, sigmabin, redshift): + """ + /* sigma(M, z) */ + """ + + thissigma = self.Dofz(redshift) * self.sigmaarray[sigmabin]; + + return thissigma; + + def Dofz(self, redshift): + """ + /* Growth function */ + """ + + thisDofz = self.gofz(redshift) / self.gofz(0.0) / (1.0+redshift); + + return thisDofz; + + + def gofz(self, redshift): + """ + /* g(z) - I don't think this has any other name*/ + """ + + thisgofz = 2.5 * self.omega_matter_of_z(redshift) / \ + ( math.pow( self.omega_matter_of_z(redshift), 4.0/7.0 ) - \ + self.omega_lambda_of_z(redshift) + \ + ( (1.0 + self.omega_matter_of_z(redshift) / 2.0) * \ + (1.0 + self.omega_lambda_of_z(redshift) / 70.0) )) + + return thisgofz; + + + def omega_matter_of_z(self,redshift): + """ + /* Omega matter as a function of redshift */ + """ + + thisomofz = self.omega_matter0 * math.pow( 1.0+redshift, 3.0) / \ + math.pow( self.Eofz(redshift), 2.0 ); + + return thisomofz; + + def omega_lambda_of_z(self,redshift): + """ + /* Omega lambda as a function of redshift */ + """ + + thisolofz = self.omega_lambda0 / math.pow( self.Eofz(redshift), 2.0 ) + + return thisolofz; + + def Eofz(self, redshift): + """ + /* E(z) - I don't think this has any other name */ + """ + thiseofz = math.sqrt( self.omega_lambda0 \ + + (1.0 - self.omega_lambda0 - self.omega_matter0)*math.pow( 1.0+redshift, 2.0) \ + + self.omega_matter0 * math.pow( 1.0+redshift, 3.0) ); + + return thiseofz; + + +""" +/* Fitting Formulae for CDM + Baryon + Massive Neutrino (MDM) cosmologies. */ +/* Daniel J. Eisenstein & Wayne Hu, Institute for Advanced Study */ + +/* There are two primary routines here, one to set the cosmology, the +other to construct the transfer function for a single wavenumber k. +You should call the former once (per cosmology) and the latter as +many times as you want. */ + +/* TFmdm_set_cosm() -- User passes all the cosmological parameters as + arguments; the routine sets up all of the scalar quantites needed + computation of the fitting formula. The input parameters are: + 1) omega_matter -- Density of CDM, baryons, and massive neutrinos, + in units of the critical density. + 2) omega_baryon -- Density of baryons, in units of critical. + 3) omega_hdm -- Density of massive neutrinos, in units of critical + 4) degen_hdm -- (Int) Number of degenerate massive neutrino species + 5) omega_lambda -- Cosmological constant + 6) hubble -- Hubble constant, in units of 100 km/s/Mpc + 7) redshift -- The redshift at which to evaluate */ + +/* TFmdm_onek_mpc() -- User passes a single wavenumber, in units of Mpc^-1. + Routine returns the transfer function from the Eisenstein & Hu + fitting formula, based on the cosmology currently held in the + internal variables. The routine returns T_cb (the CDM+Baryon + density-weighted transfer function), although T_cbn (the CDM+ + Baryon+Neutrino density-weighted transfer function) is stored + in the global variable tf_cbnu. */ + +/* We also supply TFmdm_onek_hmpc(), which is identical to the previous + routine, but takes the wavenumber in units of h Mpc^-1. */ + +/* We hold the internal scalar quantities in global variables, so that +the user may access them in an external program, via "extern" declarations. */ + +/* Please note that all internal length scales are in Mpc, not h^-1 Mpc! */ +""" + +class TransferFunction(object): + def __init__(self, omega_matter, omega_baryon, omega_hdm, + degen_hdm, omega_lambda, hubble, redshift): + """ + /* This routine takes cosmological parameters and a redshift and sets up + all the internal scalar quantities needed to compute the transfer function. */ + /* INPUT: omega_matter -- Density of CDM, baryons, and massive neutrinos, + in units of the critical density. */ + /* omega_baryon -- Density of baryons, in units of critical. */ + /* omega_hdm -- Density of massive neutrinos, in units of critical */ + /* degen_hdm -- (Int) Number of degenerate massive neutrino species */ + /* omega_lambda -- Cosmological constant */ + /* hubble -- Hubble constant, in units of 100 km/s/Mpc */ + /* redshift -- The redshift at which to evaluate */ + /* OUTPUT: Returns 0 if all is well, 1 if a warning was issued. Otherwise, + sets many global variables for use in TFmdm_onek_mpc() */ + """ + self.qwarn = 0; + self.theta_cmb = 2.728/2.7 # Assuming T_cmb = 2.728 K + + # Look for strange input + if (omega_baryon<0.0): + mylog.error("TFmdm_set_cosm(): Negative omega_baryon set to trace amount.\n") + self.qwarn = 1 + if (omega_hdm<0.0): + mylog.error("TFmdm_set_cosm(): Negative omega_hdm set to trace amount.\n") + self.qwarn = 1; + if (hubble<=0.0): + mylog.error("TFmdm_set_cosm(): Negative Hubble constant illegal.\n") + return None + elif (hubble>2.0): + mylog.error("TFmdm_set_cosm(): Hubble constant should be in units of 100 km/s/Mpc.\n"); + self.qwarn = 1; + if (redshift<=-1.0): + mylog.error("TFmdm_set_cosm(): Redshift < -1 is illegal.\n"); + return None + elif (redshift>99.0): + mylog.error("TFmdm_set_cosm(): Large redshift entered. TF may be inaccurate.\n"); + self.qwarn = 1; + + if (degen_hdm<1): degen_hdm=1; + self.num_degen_hdm = degen_hdm; + # Have to save this for TFmdm_onek_mpc() + # This routine would crash if baryons or neutrinos were zero, + # so don't allow that. + if (omega_baryon<=0): omega_baryon=1e-5; + if (omega_hdm<=0): omega_hdm=1e-5; + + self.omega_curv = 1.0-omega_matter-omega_lambda; + self.omhh = omega_matter*SQR(hubble); + self.obhh = omega_baryon*SQR(hubble); + self.onhh = omega_hdm*SQR(hubble); + self.f_baryon = omega_baryon/omega_matter; + self.f_hdm = omega_hdm/omega_matter; + self.f_cdm = 1.0-self.f_baryon-self.f_hdm; + self.f_cb = self.f_cdm+self.f_baryon; + self.f_bnu = self.f_baryon+self.f_hdm; + + # Compute the equality scale. + self.z_equality = 25000.0*self.omhh/SQR(SQR(self.theta_cmb)) # Actually 1+z_eq + self.k_equality = 0.0746*self.omhh/SQR(self.theta_cmb); + + # Compute the drag epoch and sound horizon + z_drag_b1 = 0.313*math.pow(self.omhh,-0.419)*(1+0.607*math.pow(self.omhh,0.674)); + z_drag_b2 = 0.238*math.pow(self.omhh,0.223); + self.z_drag = 1291*math.pow(self.omhh,0.251)/(1.0+0.659*math.pow(self.omhh,0.828))* \ + (1.0+z_drag_b1*math.pow(self.obhh,z_drag_b2)); + self.y_drag = self.z_equality/(1.0+self.z_drag); + + self.sound_horizon_fit = 44.5*math.log(9.83/self.omhh)/math.sqrt(1.0+10.0*math.pow(self.obhh,0.75)); + + # Set up for the free-streaming & infall growth function + self.p_c = 0.25*(5.0-math.sqrt(1+24.0*self.f_cdm)); + self.p_cb = 0.25*(5.0-math.sqrt(1+24.0*self.f_cb)); + + omega_denom = omega_lambda+SQR(1.0+redshift)*(self.omega_curv+\ + omega_matter*(1.0+redshift)); + self.omega_lambda_z = omega_lambda/omega_denom; + self.omega_matter_z = omega_matter*SQR(1.0+redshift)*(1.0+redshift)/omega_denom; + self.growth_k0 = self.z_equality/(1.0+redshift)*2.5*self.omega_matter_z/ \ + (math.pow(self.omega_matter_z,4.0/7.0)-self.omega_lambda_z+ \ + (1.0+self.omega_matter_z/2.0)*(1.0+self.omega_lambda_z/70.0)); + self.growth_to_z0 = self.z_equality*2.5*omega_matter/(math.pow(omega_matter,4.0/7.0) \ + -omega_lambda + (1.0+omega_matter/2.0)*(1.0+omega_lambda/70.0)); + self.growth_to_z0 = self.growth_k0/self.growth_to_z0; + + # Compute small-scale suppression + self.alpha_nu = self.f_cdm/self.f_cb*(5.0-2.*(self.p_c+self.p_cb))/(5.-4.*self.p_cb)* \ + math.pow(1+self.y_drag,self.p_cb-self.p_c)* \ + (1+self.f_bnu*(-0.553+0.126*self.f_bnu*self.f_bnu))/ \ + (1-0.193*math.sqrt(self.f_hdm*self.num_degen_hdm)+0.169*self.f_hdm*math.pow(self.num_degen_hdm,0.2))* \ + (1+(self.p_c-self.p_cb)/2*(1+1/(3.-4.*self.p_c)/(7.-4.*self.p_cb))/(1+self.y_drag)); + self.alpha_gamma = math.sqrt(self.alpha_nu); + self.beta_c = 1/(1-0.949*self.f_bnu); + # Done setting scalar variables + self.hhubble = hubble # Need to pass Hubble constant to TFmdm_onek_hmpc() + + + def TFmdm_onek_mpc(self, kk): + """ + /* Given a wavenumber in Mpc^-1, return the transfer function for the + cosmology held in the global variables. */ + /* Input: kk -- Wavenumber in Mpc^-1 */ + /* Output: The following are set as global variables: + growth_cb -- the transfer function for density-weighted + CDM + Baryon perturbations. + growth_cbnu -- the transfer function for density-weighted + CDM + Baryon + Massive Neutrino perturbations. */ + /* The function returns growth_cb */ + """ + + self.qq = kk/self.omhh*SQR(self.theta_cmb); + + # Compute the scale-dependent growth functions + self.y_freestream = 17.2*self.f_hdm*(1+0.488*math.pow(self.f_hdm,-7.0/6.0))* \ + SQR(self.num_degen_hdm*self.qq/self.f_hdm); + temp1 = math.pow(self.growth_k0, 1.0-self.p_cb); + temp2 = na.power(self.growth_k0/(1+self.y_freestream),0.7); + self.growth_cb = na.power(1.0+temp2, self.p_cb/0.7)*temp1; + self.growth_cbnu = na.power(na.power(self.f_cb,0.7/self.p_cb)+temp2, self.p_cb/0.7)*temp1; + + # Compute the master function + self.gamma_eff = self.omhh*(self.alpha_gamma+(1-self.alpha_gamma)/ \ + (1+SQR(SQR(kk*self.sound_horizon_fit*0.43)))); + self.qq_eff = self.qq*self.omhh/self.gamma_eff; + + tf_sup_L = na.log(2.71828+1.84*self.beta_c*self.alpha_gamma*self.qq_eff); + tf_sup_C = 14.4+325/(1+60.5*na.power(self.qq_eff,1.11)); + self.tf_sup = tf_sup_L/(tf_sup_L+tf_sup_C*SQR(self.qq_eff)); + + self.qq_nu = 3.92*self.qq*math.sqrt(self.num_degen_hdm/self.f_hdm); + self.max_fs_correction = 1+1.2*math.pow(self.f_hdm,0.64)*math.pow(self.num_degen_hdm,0.3+0.6*self.f_hdm)/ \ + (na.power(self.qq_nu,-1.6)+na.power(self.qq_nu,0.8)); + self.tf_master = self.tf_sup*self.max_fs_correction; + + # Now compute the CDM+HDM+baryon transfer functions + tf_cb = self.tf_master*self.growth_cb/self.growth_k0; + tf_cbnu = self.tf_master*self.growth_cbnu/self.growth_k0; + return tf_cb + + + def TFmdm_onek_hmpc(self, kk): + """ + /* Given a wavenumber in h Mpc^-1, return the transfer function for the + cosmology held in the global variables. */ + /* Input: kk -- Wavenumber in h Mpc^-1 */ + /* Output: The following are set as global variables: + growth_cb -- the transfer function for density-weighted + CDM + Baryon perturbations. + growth_cbnu -- the transfer function for density-weighted + CDM + Baryon + Massive Neutrino perturbations. */ + /* The function returns growth_cb */ + """ + return self.TFmdm_onek_mpc(kk*self.hhubble); + +def SQR(a): + return a*a + +def integrate_inf(fcn, error=1e-7, initial_guess=10): + """ + Integrate a function *fcn* from zero to infinity, stopping when the answer + changes by less than *error*. Hopefully someday we can do something + better than this! + """ + xvals = na.logspace(0,na.log10(initial_guess), initial_guess+1)-.9 + yvals = fcn(xvals) + xdiffs = xvals[1:] - xvals[:-1] + # Trapezoid rule, but with different dxes between values, so na.trapz + # will not work. + areas = (yvals[1:] + yvals[:-1]) * xdiffs / 2.0 + area0 = na.sum(areas) + # Next guess. + next_guess = 10 * initial_guess + xvals = na.logspace(0,na.log10(next_guess), 2*initial_guess**2+1)-.99 + yvals = fcn(xvals) + xdiffs = xvals[1:] - xvals[:-1] + # Trapezoid rule. + areas = (yvals[1:] + yvals[:-1]) * xdiffs / 2.0 + area1 = na.sum(areas) + # Now we refine until the error is smaller than *error*. + diff = area1 - area0 + area_final = area1 + area_last = area1 + one_pow = 3 + while diff > error: + next_guess *= 10 + xvals = na.logspace(0,na.log10(next_guess), one_pow*initial_guess**one_pow+1) - (1 - 0.1**one_pow) + yvals = fcn(xvals) + xdiffs = xvals[1:] - xvals[:-1] + # Trapezoid rule. + areas = (yvals[1:] + yvals[:-1]) * xdiffs / 2.0 + area_next = na.sum(areas) + diff = area_next - area_last + area_last = area_next + one_pow+=1 + return area_last diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_mass_function/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_mass_function/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('halo_mass_function',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_merger_tree/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_merger_tree/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,38 @@ +""" +API for halo_merger_tree + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .merger_tree import \ + DatabaseFunctions, \ + MergerTree, \ + MergerTreeConnect, \ + Node, \ + Link, \ + MergerTreeDotOutput, \ + MergerTreeTextOutput diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_merger_tree/merger_tree.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_merger_tree/merger_tree.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,1164 @@ +""" +MergerTree class and member functions. + +Author: Stephen Skory +Affiliation: CASS/UC San Diego, CA +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2010 Stephen Skory. 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 . +""" + +import numpy as na +import os, glob, md5, time, gc, sys +import h5py +import types +import sqlite3 as sql +from yt.funcs import * + +from yt.analysis_modules.halo_finding.halo_objects import \ + FOFHaloFinder, HaloFinder +from yt.analysis_modules.halo_profiler.multi_halo_profiler import \ + HaloProfiler +from yt.convenience import load +try: + from yt.utilities.kdtree import * +except ImportError: + mylog.debug("The Fortran kD-Tree did not import correctly.") +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelDummy, \ + ParallelAnalysisInterface, \ + parallel_blocking_call + + +column_types = { +"GlobalHaloID":"INTEGER", +"SnapCurrentTimeIdentifier":"INTEGER", +"SnapZ":"FLOAT", +"SnapHaloID":"INTEGER", +"HaloMass":"FLOAT", +"NumPart":"INTEGER", +"CenMassX":"FLOAT", +"CenMassY":"FLOAT", +"CenMassZ":"FLOAT", +"BulkVelX":"FLOAT", +"BulkVelY":"FLOAT", +"BulkVelZ":"FLOAT", +"MaxRad":"FLOAT", +"ChildHaloID0":"INTEGER", +"ChildHaloFrac0":"FLOAT", +"ChildHaloID1":"INTEGER", +"ChildHaloFrac1":"FLOAT", +"ChildHaloID2":"INTEGER", +"ChildHaloFrac2":"FLOAT", +"ChildHaloID3":"INTEGER", +"ChildHaloFrac3":"FLOAT", +"ChildHaloID4":"INTEGER", +"ChildHaloFrac4":"FLOAT"} + +# In order. +columns = ["GlobalHaloID", "SnapCurrentTimeIdentifier", "SnapZ", +"SnapHaloID", "HaloMass", "NumPart", "CenMassX", "CenMassY", +"CenMassZ", "BulkVelX", "BulkVelY", "BulkVelZ", "MaxRad", +"ChildHaloID0", "ChildHaloFrac0", +"ChildHaloID1", "ChildHaloFrac1", +"ChildHaloID2", "ChildHaloFrac2", +"ChildHaloID3", "ChildHaloFrac3", +"ChildHaloID4", "ChildHaloFrac4"] + +class DatabaseFunctions(object): + # Common database functions so it doesn't have to be repeated. + def _open_database(self): + # open the database. Check to make sure the database file exists. + if not os.path.exists(self.database): + mylog.error("The database file %s cannot be found. Exiting." % \ + self.database) + return False + self.conn = sql.connect(self.database) + self.cursor = self.conn.cursor() + return True + + def _close_database(self): + # close the database cleanly. + self.cursor.close() + self.conn.close() + +class MergerTree(DatabaseFunctions, ParallelAnalysisInterface): + def __init__(self, restart_files=[], database='halos.db', + halo_finder_function=HaloFinder, halo_finder_threshold=80.0, + FOF_link_length=0.2, dm_only=False, refresh=False, sleep=1, + index=True): + r"""Build a merger tree of halos over a time-ordered set of snapshots. + This will run a halo finder to find the halos first if it hasn't already + been done. The output is a SQLite database file, which may need to + be stored on a different disk than the data snapshots. See the full + documentation for details. + + Parameters + --------- + restart_files : List of strings + A list containing the paths to the forward time-ordered set of + data snapshots. + database : String + Name of SQLite database file. Default = "halos.db". + halo_finder_function : HaloFinder name + The name of the halo finder to use if halo finding is run by + the merger tree. Options: HaloFinder, FOFHaloFinder, parallelHF. + Note that this is not a string, so no quotes. Default = HaloFinder. + halo_finder_threshold : Float + If using HaloFinder or parallelHF, the value of the density threshold + used when halo finding. Default = 80.0. + FOF_link_length : Float + If using FOFHaloFinder, the linking length between particles. + Default = 0.2. + dm_only : Boolean + When halo finding, whether to restrict to only dark matter particles. + Default = False. + refresh : Boolean + True forces the halo finder to run even if the halo data has been + detected on disk. Default = False. + sleep : Float + Due to the nature of the SQLite database and network file systems, + it is crucial that all tasks see the database in the same state at + all times. This parameter specifies how long in seconds the merger + tree waits between checks to ensure the database is synched across + all tasks. Default = 1. + index : Boolean + SQLite databases can have added to them an index which greatly + speeds up future queries of the database, + at the cost of doubling the disk space used by the file. + Default = True. + + Examples: + >>> rf = ['/scratch/user/sim1/DD0000/data0000', + ... '/scratch/user/sim1/DD0001/data0001', + ... '/scratch/user/sim1/DD0002/data0002'] + >>> MergerTree(rf, database = '/home/user/sim1-halos.db', + ... halo_finder_function=parallelHF) + """ + self.restart_files = restart_files # list of enzo restart files + self.with_halos = na.ones(len(restart_files), dtype='bool') + self.database = database # the sqlite database of haloes. + self.halo_finder_function = halo_finder_function # which halo finder to use + self.halo_finder_threshold = halo_finder_threshold # overdensity threshold + self.FOF_link_length= FOF_link_length # For FOF + self.dm_only = dm_only + self.refresh = refresh + self.sleep = sleep # How long to wait between db sync checks. + if self.sleep <= 0.: + self.sleep = 5 + # MPI stuff + self.mine = self._mpi_get_rank() + if self.mine is None: + self.mine = 0 + self.size = self._mpi_get_size() + if self.size is None: + self.size = 1 + # Get to work. + if self.refresh and self.mine == 0: + try: + os.unlink(self.database) + except: + pass + self._barrier() + self._open_create_database() + self._create_halo_table() + self._run_halo_finder_add_to_db() + # Find the h5 file names for all the halos. + for snap in self.restart_files: + self._build_h5_refs(snap) + # Loop over the pairs of snapshots to locate likely neighbors, and + # then use those likely neighbors to compute fractional contributions. + last = None + self.write_values = [] + self.write_values_dict = defaultdict(dict) + for snap, pair in enumerate(zip(self.restart_files[:-1], self.restart_files[1:])): + if not self.with_halos[snap] or not self.with_halos[snap+1]: + continue + self._find_likely_children(pair[0], pair[1]) + # last is the data for the parent dataset, which can be supplied + # as the child from the previous round for all but the first loop. + last = self._compute_child_fraction(pair[0], pair[1], last) + del last + # Now update the database with all the writes. + mylog.info("Updating database with parent-child relationships.") + self._copy_and_update_db() + self._barrier() + mylog.info("Done!") + + def _read_halo_lists(self): + self.halo_lists = [] + for i,file in enumerate(self.halo_files): + hp = HaloProfiler(self.restart_files[i], halo_list_file=file) + self.halo_lists.append(hp.all_halos) + + def _run_halo_finder_add_to_db(self): + for cycle, file in enumerate(self.restart_files): + gc.collect() + pf = load(file) + # If the halos are already found, skip this data step, unless + # refresh is True. + dir = os.path.dirname(file) + if os.path.exists(os.path.join(dir, 'MergerHalos.out')) and \ + os.path.exists(os.path.join(dir, 'MergerHalos.txt')) and \ + glob.glob(os.path.join(dir, 'MergerHalos*h5')) is not [] and \ + not self.refresh: + pass + else: + # Run the halo finder. + if self.halo_finder_function == FOFHaloFinder: + halos = self.halo_finder_function(pf, + link=self.FOF_link_length, dm_only=self.dm_only) + else: + halos = self.halo_finder_function(pf, + threshold=self.halo_finder_threshold, dm_only=self.dm_only) + halos.write_out(os.path.join(dir, 'MergerHalos.out')) + halos.write_particle_lists(os.path.join(dir, 'MergerHalos')) + halos.write_particle_lists_txt(os.path.join(dir, 'MergerHalos')) + if len(halos) == 0: + mylog.info("Dataset %s has no halos." % file) + self.with_halos[cycle] = False + continue + del halos + # Now add halo data to the db if it isn't already there by + # checking the first halo. + currt = pf.unique_identifier + line = "SELECT GlobalHaloID from Halos where SnapHaloID=0\ + and SnapCurrentTimeIdentifier=%d;" % currt + self.cursor.execute(line) + result = self.cursor.fetchone() + if result != None: + continue + red = pf.current_redshift + # Read the halos off the disk using the Halo Profiler tools. + hp = HaloProfiler(file, halo_list_file='MergerHalos.out', + halo_list_format={'id':0, 'mass':1, 'numpart':2, 'center':[7, 8, 9], 'velocity':[10, 11, 12], 'r_max':13}) + if len(hp.all_halos) == 0: + mylog.info("Dataset %s has no halos." % file) + self.with_halos[cycle] = False + continue + mylog.info("Entering halos into database for z=%f" % red) + if self.mine == 0: + for ID,halo in enumerate(hp.all_halos): + numpart = int(halo['numpart']) + values = (None, currt, red, ID, halo['mass'], numpart, + halo['center'][0], halo['center'][1], halo['center'][2], + halo['velocity'][0], halo['velocity'][1], halo['velocity'][2], + halo['r_max'] / pf['mpc'], + -1,0.,-1,0.,-1,0.,-1,0.,-1,0.) + # 23 question marks for 23 data columns. + line = '' + for i in range(23): + line += '?,' + # Pull off the last comma. + line = 'INSERT into Halos VALUES (' + line[:-1] + ')' + self.cursor.execute(line, values) + self.conn.commit() + self._barrier() + del hp + + def _open_create_database(self): + # open the database. This creates the database file on disk if it + # doesn't already exist. Open it first on root, and then on the others. + if self.mine == 0: + self.conn = sql.connect(self.database) + self._barrier() + self._ensure_db_sync() + if self.mine != 0: + self.conn = sql.connect(self.database) + self.cursor = self.conn.cursor() + + def _ensure_db_sync(self): + # If the database becomes out of sync for each task, ostensibly due to + # parallel file system funniness, things will go bad very quickly. + # Therefore, just to be very, very careful, we will ensure that the + # md5 hash of the file is identical across all tasks before proceeding. + self._barrier() + for i in range(5): + try: + file = open(self.database) + except IOError: + # This is to give a little bit of time for the database creation + # to replicate across the file system. + time.sleep(self.sleep) + file = open(self.database) + hash = md5.md5(file.read()).hexdigest() + file.close() + ignore, hashes = self._mpi_info_dict(hash) + hashes = set(hashes.values()) + if len(hashes) == 1: + break + else: + # Wait a little bit for the file system to (hopefully) sync up. + time.sleep(self.sleep) + if len(hashes) == 1: + return + else: + mylog.error("The file system is not properly synchronizing the database.") + raise RunTimeError("Fatal error. Exiting.") + + def _create_halo_table(self): + if self.mine == 0: + # Handle the error if it already exists. + try: + # Create the table that will store the halo data. + line = "CREATE TABLE Halos (GlobalHaloID INTEGER PRIMARY KEY,\ + SnapCurrentTimeIdentifier INTEGER, SnapZ FLOAT, SnapHaloID INTEGER, \ + HaloMass FLOAT,\ + NumPart INTEGER, CenMassX FLOAT, CenMassY FLOAT,\ + CenMassZ FLOAT, BulkVelX FLOAT, BulkVelY FLOAT, BulkVelZ FLOAT,\ + MaxRad FLOAT,\ + ChildHaloID0 INTEGER, ChildHaloFrac0 FLOAT, \ + ChildHaloID1 INTEGER, ChildHaloFrac1 FLOAT, \ + ChildHaloID2 INTEGER, ChildHaloFrac2 FLOAT, \ + ChildHaloID3 INTEGER, ChildHaloFrac3 FLOAT, \ + ChildHaloID4 INTEGER, ChildHaloFrac4 FLOAT);" + self.cursor.execute(line) + self.conn.commit() + except sql.OperationalError: + pass + self._barrier() + + def _find_likely_children(self, parentfile, childfile): + # For each halo in the parent list, identify likely children in the + # list of children. + + # First, read in the locations of the child halos. + child_pf = load(childfile) + child_t = child_pf.unique_identifier + line = "SELECT SnapHaloID, CenMassX, CenMassY, CenMassZ FROM \ + Halos WHERE SnapCurrentTimeIdentifier = %d" % child_t + self.cursor.execute(line) + + mylog.info("Finding likely parents for z=%1.5f child halos." % \ + child_pf.current_redshift) + + # Build the kdtree for the children by looping over the fetched rows. + child_points = [] + for row in self.cursor: + child_points.append([row[1], row[2], row[3]]) + # Turn it into fortran. + child_points = na.array(child_points) + fKD.pos = na.asfortranarray(child_points.T) + fKD.qv = na.empty(3, dtype='float64') + fKD.dist = na.empty(5, dtype='float64') + fKD.tags = na.empty(5, dtype='int64') + fKD.nn = 5 + fKD.sort = True + fKD.rearrange = True + create_tree(0) + + # Find the parent points from the database. + parent_pf = load(parentfile) + parent_t = parent_pf.unique_identifier + line = "SELECT SnapHaloID, CenMassX, CenMassY, CenMassZ FROM \ + Halos WHERE SnapCurrentTimeIdentifier = %d" % parent_t + self.cursor.execute(line) + + # Loop over the returned rows, and find the likely neighbors for the + # parents. + candidates = {} + for row in self.cursor: + fKD.qv = na.array([row[1], row[2], row[3]]) + find_nn_nearest_neighbors() + NNtags = fKD.tags[:] - 1 + nIDs = [] + for n in NNtags: + nIDs.append(n) + if len(nIDs) < 5: + # We need to fill in fake halos if there aren't enough halos, + # which can happen at high redshifts. + while len(nIDs) < 5: + nIDs.append(-1) + candidates[row[0]] = nIDs + + del fKD.pos, fKD.tags, fKD.dist + free_tree(0) # Frees the kdtree object. + + self.candidates = candidates + + # This stores the masses contributed to each child candidate. + self.child_mass_arr = na.zeros(len(candidates)*5, dtype='float64') + # Records where to put the entries in the above array. + self.child_mass_loc = defaultdict(dict) + for i,halo in enumerate(sorted(candidates)): + for j, child in enumerate(candidates[halo]): + self.child_mass_loc[halo][child] = i*5 + j + + def _build_h5_refs(self, filename): + # For this snapshot, add lists of file names that contain the + # particle info for each halo. + if not hasattr(self, 'h5files'): + self.h5files = defaultdict(dict) + if not hasattr(self, 'names'): + self.names = defaultdict(set) + file_pf = load(filename) + currt = file_pf.unique_identifier + dir = os.path.dirname(filename) + h5txt = os.path.join(dir, 'MergerHalos.txt') + lines = file(h5txt) + names = set([]) + for i,line in enumerate(lines): + # Get rid of the carriage returns and turn it into a list. + line = line.strip().split() + self.h5files[currt][i] = line[1:] + names.update(line[1:]) + self.names[currt].update(line[1:]) + lines.close() + + def _compute_child_fraction(self, parentfile, childfile, last): + # Given a parent and child snapshot, and a list of child candidates, + # compute what fraction of the parent halo goes to each of the children. + + parent_pf = load(parentfile) + child_pf = load(childfile) + parent_currt = parent_pf.unique_identifier + child_currt = child_pf.unique_identifier + + mylog.info("Computing fractional contribututions of particles to z=%1.5f halos." % \ + child_pf.current_redshift) + + if last == None: + # First we're going to read in the particles, haloIDs and masses from + # the parent dataset. + parent_names = list(self.names[parent_currt]) + parent_names.sort() + parent_IDs = na.array([], dtype='int64') + parent_masses = na.array([], dtype='float64') + parent_halos = na.array([], dtype='int32') + for i,pname in enumerate(parent_names): + if i>=self.mine and i%self.size==self.mine: + h5fp = h5py.File(pname) + for group in h5fp: + gID = int(group[4:]) + thisIDs = h5fp[group]['particle_index'][:] + thisMasses = h5fp[group]['ParticleMassMsun'][:] + parent_IDs = na.concatenate((parent_IDs, thisIDs)) + parent_masses = na.concatenate((parent_masses, thisMasses)) + parent_halos = na.concatenate((parent_halos, + na.ones(thisIDs.size, dtype='int32') * gID)) + h5fp.close() + + # Sort the arrays by particle index in ascending order. + sort = parent_IDs.argsort() + parent_IDs = parent_IDs[sort] + parent_masses = parent_masses[sort] + parent_halos = parent_halos[sort] + del sort + else: + # We can use old data and save disk reading. + (parent_IDs, parent_masses, parent_halos) = last + # Used to communicate un-matched particles. + parent_send = na.ones(parent_IDs.size, dtype='bool') + + # Now get the child halo data. + child_names = list(self.names[child_currt]) + child_names.sort() + child_IDs = na.array([], dtype='int64') + child_masses = na.array([], dtype='float64') + child_halos = na.array([], dtype='int32') + for i,cname in enumerate(child_names): + if i>=self.mine and i%self.size==self.mine: + h5fp = h5py.File(cname) + for group in h5fp: + gID = int(group[4:]) + thisIDs = h5fp[group]['particle_index'][:] + thisMasses = h5fp[group]['ParticleMassMsun'][:] + child_IDs = na.concatenate((child_IDs, thisIDs)) + child_masses = na.concatenate((child_masses, thisMasses)) + child_halos = na.concatenate((child_halos, + na.ones(thisIDs.size, dtype='int32') * gID)) + h5fp.close() + + # Sort the arrays by particle index. + sort = child_IDs.argsort() + child_IDs = child_IDs[sort] + child_masses = child_masses[sort] + child_halos = child_halos[sort] + child_send = na.ones(child_IDs.size, dtype='bool') + del sort + + # Parent IDs on the left, child IDs on the right. We skip down both + # columns matching IDs. If they are out of synch, the index(es) is/are + # advanced until they match up again. + left = 0 + right = 0 + while left < parent_IDs.size and right < child_IDs.size: + if parent_IDs[left] == child_IDs[right]: + # They match up, add this relationship. + try: + loc = self.child_mass_loc[parent_halos[left]][child_halos[right]] + except KeyError: + # This happens when a child halo contains a particle from + # a parent halo, but the child is not identified as a + # candidate child halo. So we do nothing and move on with + # our lives. + left += 1 + right += 1 + continue + self.child_mass_arr[loc] += parent_masses[left] + # Mark this pair so we don't send them later. + parent_send[left] = False + child_send[right] = False + left += 1 + right += 1 + continue + if parent_IDs[left] < child_IDs[right]: + # The left is too small, so we need to increase it. + left += 1 + continue + if parent_IDs[left] > child_IDs[right]: + # Right too small. + right += 1 + continue + + # Now we send all the un-matched particles to the root task for one more + # pass. This depends on the assumption that most of the particles do + # not move very much between data dumps, so that not too many particles + # will be dumped on the single task. + parent_IDs_tosend = parent_IDs[parent_send] + parent_masses_tosend = parent_masses[parent_send] + parent_halos_tosend = parent_halos[parent_send] + child_IDs_tosend = child_IDs[child_send] + child_halos_tosend = child_halos[child_send] + + parent_IDs_tosend = self._mpi_concatenate_array_on_root_long(parent_IDs_tosend) + parent_masses_tosend = self._mpi_concatenate_array_on_root_double(parent_masses_tosend) + parent_halos_tosend = self._mpi_concatenate_array_on_root_int(parent_halos_tosend) + child_IDs_tosend = self._mpi_concatenate_array_on_root_long(child_IDs_tosend) + child_halos_tosend = self._mpi_concatenate_array_on_root_int(child_halos_tosend) + + # Resort the received particles. + Psort = parent_IDs_tosend.argsort() + parent_IDs_tosend = parent_IDs_tosend[Psort] + parent_masses_tosend = parent_masses_tosend[Psort] + parent_halos_tosend = parent_halos_tosend[Psort] + Csort = child_IDs_tosend.argsort() + child_IDs_tosend = child_IDs_tosend[Csort] + child_halos_tosend = child_halos_tosend[Csort] + del Psort, Csort + + # Now Again. + if self.mine == 0: + matched = 0 + left = 0 + right = 0 + while left < parent_IDs_tosend.size and right < child_IDs_tosend.size: + if parent_IDs_tosend[left] == child_IDs_tosend[right]: + # They match up, add this relationship. + try: + loc = self.child_mass_loc[parent_halos_tosend[left]][child_halos_tosend[right]] + except KeyError: + # This happens when a child halo contains a particle from + # a parent halo, but the child is not identified as a + # candidate child halo. So we do nothing and move on with + # our lives. + left += 1 + right += 1 + continue + self.child_mass_arr[loc] += parent_masses_tosend[left] + matched += 1 + left += 1 + right += 1 + continue + if parent_IDs_tosend[left] < child_IDs_tosend[right]: + # The left is too small, so we need to increase it. + left += 1 + continue + if parent_IDs_tosend[left] > child_IDs_tosend[right]: + # Right too small. + right += 1 + continue + mylog.info("Clean-up round matched %d of %d parents and %d children." % \ + (matched, parent_IDs_tosend.size, child_IDs_tosend.size)) + + # Now we sum up the contributions globally. + self.child_mass_arr = self._mpi_Allsum_double(self.child_mass_arr) + + # Turn these Msol masses into percentages of the parent. + line = "SELECT HaloMass FROM Halos WHERE SnapCurrentTimeIdentifier=%d \ + ORDER BY SnapHaloID ASC;" % parent_currt + self.cursor.execute(line) + mark = 0 + result = self.cursor.fetchone() + while result: + mass = result[0] + self.child_mass_arr[mark:mark+5] /= mass + mark += 5 + result = self.cursor.fetchone() + + # Get the global ID for the SnapHaloID=0 from the child, this will + # be used to prevent unnecessary SQL reads. + line = "SELECT GlobalHaloID FROM Halos WHERE SnapCurrentTimeIdentifier=%d \ + AND SnapHaloID=0;" % child_currt + self.cursor.execute(line) + baseChildID = self.cursor.fetchone()[0] + + # Now we prepare a big list of writes to put in the database. + for i,parent_halo in enumerate(sorted(self.candidates)): + child_indexes = [] + child_per = [] + for j,child in enumerate(self.candidates[parent_halo]): + if child == -1: + # Account for fake children. + child_indexes.append(-1) + child_per.append(0.) + continue + # We need to get the GlobalHaloID for this child. + child_globalID = baseChildID + child + child_indexes.append(child_globalID) + child_per.append(self.child_mass_arr[i*5 + j]) + # Sort by percentages, desending. + child_per, child_indexes = zip(*sorted(zip(child_per, child_indexes), reverse=True)) + values = [] + for pair in zip(child_indexes, child_per): + values.extend([int(pair[0]), float(pair[1])]) + #values.extend([parent_currt, parent_halo]) + # This has the child ID, child percent listed five times, followed + # by the currt and this parent halo ID (SnapHaloID). + #values = tuple(values) + self.write_values.append(values) + self.write_values_dict[parent_currt][parent_halo] = values + + return (child_IDs, child_masses, child_halos) + + def _copy_and_update_db(self): + """ + Because doing an UPDATE of a SQLite database is really slow, what we'll + do here is basically read in lines from the database, and then insert + the parent-child relationships, writing to a new DB. + """ + temp_name = self.database + '-tmp' + if self.mine == 0: + to_write = [] + # Open the temporary database. + try: + os.remove(temp_name) + except OSError: + pass + temp_conn = sql.connect(temp_name) + temp_cursor = temp_conn.cursor() + line = "CREATE TABLE Halos (GlobalHaloID INTEGER PRIMARY KEY,\ + SnapCurrentTimeIdentifier INTEGER, SnapZ FLOAT, SnapHaloID INTEGER, \ + HaloMass FLOAT,\ + NumPart INTEGER, CenMassX FLOAT, CenMassY FLOAT,\ + CenMassZ FLOAT, BulkVelX FLOAT, BulkVelY FLOAT, BulkVelZ FLOAT,\ + MaxRad FLOAT,\ + ChildHaloID0 INTEGER, ChildHaloFrac0 FLOAT, \ + ChildHaloID1 INTEGER, ChildHaloFrac1 FLOAT, \ + ChildHaloID2 INTEGER, ChildHaloFrac2 FLOAT, \ + ChildHaloID3 INTEGER, ChildHaloFrac3 FLOAT, \ + ChildHaloID4 INTEGER, ChildHaloFrac4 FLOAT);" + temp_cursor.execute(line) + temp_conn.commit() + # Get all the data! + self.cursor.execute("SELECT * FROM Halos;") + results = self.cursor.fetchone() + while results: + results = list(results) + currt = results[1] + hid = results[3] + # If for some reason this halo doesn't have relationships, + # we'll just keep the old results the same. + try: + lookup = self.write_values_dict[currt][hid] + new = tuple(results[:-10] + lookup) + except KeyError: + new = tuple(results) + to_write.append(new) + results = self.cursor.fetchone() + # Now write to the temp database. + # 23 question marks for 23 data columns. + line = '' + for i in range(23): + line += '?,' + # Pull off the last comma. + line = 'INSERT into Halos VALUES (' + line[:-1] + ')' + for insert in to_write: + temp_cursor.execute(line, insert) + temp_conn.commit() + mylog.info("Creating database index.") + line = "CREATE INDEX IF NOT EXISTS HalosIndex ON Halos (" + for name in columns: + line += name +"," + line = line[:-1] + ");" + temp_cursor.execute(line) + temp_cursor.close() + temp_conn.close() + self._close_database() + self._barrier() + if self.mine == 0: + os.rename(temp_name, self.database) + +class MergerTreeConnect(DatabaseFunctions): + def __init__(self, database='halos.db'): + r"""Create a convenience object for accessing data from the halo database. + + Parameters + ---------- + database : String + The name of the halo database to access. Default = 'halos.db'. + + Examples + ------- + >>> mtc = MergerTreeConnect('/home/user/sim1-halos.db') + """ + self.database = database + result = self._open_database() + if not result: + return None + + def close(self): + r"""Cleanly close access to the database. + + Examples + -------- + >>> mtc.close() + """ + # To be more like typical Python open/close. + self._close_database() + + def query(self, string): + r"""Performs a query of the database and returns the results as a list + of tuple(s), even if the result is singular. + + Parameters + ---------- + string : String + The SQL query of the database. + + Examples + ------- + >>> results = mtc.query("SELECT GlobalHaloID from Halos where SnapHaloID = 0 and \ + ... SnapZ = 0;") + """ + # Query the database and return a list of tuples. + if string is None: + mylog.error("You must enter a SQL query.") + return None + items = [] + self.cursor.execute(string) + results = self.cursor.fetchone() + while results: + items.append(results) + results = self.cursor.fetchone() + return items + + def get_GlobalHaloID(self, SnapHaloID, z): + r"""Returns the GlobalHaloID for the given halo. + + Parameters + --------- + SnapHaloID : Integer + The index label for the halo of interest, equivalent to + the first column of the halo finder text output file. + z : Float + The redshift for the halo of interest. The value returned will be + for the halo with SnapHaloID equal to ID (above) with redshift + closest to this value. + + Examples + -------- + >>> this_halo = mtc.get_GlobalHaloID(0, 0.) + """ + string = "SELECT GlobalHaloID,SnapZ FROM Halos WHERE SnapHaloID = %d;" \ + % SnapHaloID + minz = 99999. + # If -1 is returned, something went wrong. + this_halo = -1 + self.cursor.execute(string) + results = self.cursor.fetchone() + while results: + if abs(results[1] - z) < minz: + minz = abs(results[1] - z) + this_halo = results[0] + results = self.cursor.fetchone() + return this_halo + + def get_halo_parents(self, GlobalHaloID): + r"""Returns a list of the parent halos to the given halo, along with + the contribution fractions from parent to child. + + This function returns a list of lists, where each entry in the top list + is [GlobalHaloID, ChildHaloFrac] of the parent halo in relationship + to the given child halo. + + Parameters + ---------- + GlobalHaloID : Integer + The GlobalHaloID of the halo of interest. + + Examples + -------- + >>> parents = mtc.get_halo_parents(1688) + >>> print parents + [[1544, 0.9642857141249418], + [1613, 0.0], + [1614, 0.0], + [1489, 0.0], + [1512, 0.0], + [1519, 0.0], + [1609, 0.0]] + """ + parents = [] + for i in range(5): + string = "SELECT GlobalHaloID, ChildHaloFrac%d FROM Halos\ + WHERE ChildHaloID%d=%d;" % (i, i, GlobalHaloID) + self.cursor.execute(string) + results = self.cursor.fetchone() + while results: + parents.append([results[0], results[1]]) + results = self.cursor.fetchone() + return parents + + def get_direct_parent(self, GlobalHaloID): + r"""Returns the GlobalHaloID of the direct parent of the given halo. + + This is accomplished by identifying the most massive parent halo + that contributes at least 50% of its mass to the given halo. + + Parameters + ---------- + GlobalHaloID : Integer + The GlobalHaloID of the halo of interest. + + Examples + -------- + >>> parent = mtc.get_direct_parent(1688) + >>> print parent + 1544 + """ + parents = self.get_halo_parents(GlobalHaloID) + mass = 0 + ID = None + for parent in parents: + if parent[1] < 0.5: continue + info = self.get_halo_info(parent[0]) + if info['HaloMass'] > mass: + mass = info['HaloMass'] + ID = parent[0] + return ID + + def get_halo_info(self, GlobalHaloID): + r"""Returns all available information for the given GlobalHaloID + in the form of a dict. + + Parameters + ---------- + GlobalHaloID : Integer + The unique index for the halo of interest. + + Examples + -------- + >>> info = mtc.get_halo_info(1544) + >>> print info + {'BulkVelX': -32759799.359999999, + 'BulkVelY': -28740239.109999999, + 'BulkVelZ': -20066000.690000001, + 'CenMassX': 0.23059111360000001, + 'CenMassY': 0.4061139809, + 'CenMassZ': 0.80882763749999997, + 'ChildHaloFrac0': 0.9642857141249418, + 'ChildHaloFrac1': 0.0, + 'ChildHaloFrac2': 0.0, + 'ChildHaloFrac3': 0.0, + 'ChildHaloFrac4': 0.0, + 'ChildHaloID0': 1688, + 'ChildHaloID1': 1712, + 'ChildHaloID2': 1664, + 'ChildHaloID3': 1657, + 'ChildHaloID4': 1634, + 'GlobalHaloID': 1544, + 'HaloMass': 20934692770000.0, + 'MaxRad': 0.01531299899, + 'NumPart': 196, + 'SnapCurrentTimeIdentifier': 1275946788, + 'SnapHaloID': 56, + 'SnapZ': 0.024169713061444002} + """ + string = "SELECT * FROM Halos WHERE GlobalHaloID=%d;" % GlobalHaloID + d = {} + self.cursor.execute(string) + results = self.cursor.fetchone() + for pair in zip(columns, results): + d[pair[0]] = pair[1] + return d + +class Node(object): + def __init__(self, CoM, mass, parentIDs, z, color): + self.CoM = CoM + self.mass = mass + self.parentIDs = parentIDs # In descending order of contribution + self.z = z + self.color = color + +class Link(object): + def __init__(self): + self.childIDs = [] + self.fractions = [] + +class MergerTreeDotOutput(DatabaseFunctions, ParallelAnalysisInterface): + def __init__(self, halos=None, database='halos.db', + dotfile='MergerTree.gv', current_time=None, link_min=0.2): + r"""Output the merger tree history for a given set of halo(s) in Graphviz + format. + + Parameters + --------- + halos : Integer or list of integers + If current_time below is not specified or is None, this is an integer + or list of integers with the GlobalHaloIDs of the halos to be + tracked. If current_time is specified, this is the SnapHaloIDs + for the halos to be tracked, which is identical to what is in + HopAnalysis.out files (for example). + database : String + The name of the database file. Default = 'halos.db'. + dotfile : String + The name of the file to write to. Default = 'MergerTree.gv' + current_time : Integer + The SnapCurrentTimeIdentifier for the snapshot for the halos to + be tracked. This is identical to the CurrentTimeIdentifier in + Enzo restart files. Default = None. + link_min : Float + When establishing a parent/child relationship, this is the minimum + mass fraction of the parent halo contributed to + the child halo that will be tracked + while building the Graphviz file. Default = 0.2. + + Examples + -------- + >>> MergerTreeDotOutput(halos=182842, database='/home/user/sim1-halos.db', + ... dotfile = 'halo-182842.gv') + """ + self.database = database + self.link_min = link_min + if halos is None: + mylog.error("Please provide at least one halo to start the tree. Exiting.") + return None + result = self._open_database() + if not result: + mylog.warn("The database did not open correctly!") + return None + if type(halos) == types.IntType: + halos = [halos] + if current_time is not None: + halos = self._translate_haloIDs(halos, current_time) + newhalos = set(halos) + # A key is the GlobalHaloID for this halo, and the content is a + # Node object. + self.nodes = {} + # A key is the GlobalHaloID for the parent in the relationship, + # and the content is a Link ojbect. + self.links = defaultdict(Link) + # Record which halos are at the same z level for convenience. + # They key is a z value, and the content a list of co-leveled halo IDs. + self.levels = defaultdict(list) + # For the first set of halos. + self._add_nodes(newhalos) + # Recurse over parents. + while len(newhalos) > 0: + mylog.info("Finding parents for %d children." % len(newhalos)) + newhalos = self._find_parents(newhalos) + self._add_nodes(newhalos) + mylog.info("Writing out %s to disk." % dotfile) + self._open_dot(dotfile) + self._write_nodes() + self._write_links() + self._write_levels() + self._close_dot() + self._close_database() + return None + + def _translate_haloIDs(self, halos, current_time): + # If the input is in the haloID equivalent to SnapHaloID, translate them + # to GlobalHaloIDs. + new_haloIDs=[] + for halo in halos: + line = "SELECT GlobalHaloID FROM Halos WHERE SnapHaloID=? AND \ + SnapCurrentTimeIdentifier=? limit 1;" + values = (halo, current_time) + self.cursor.execute(line, values) + new_haloIDs.append(self.cursor.fetchone()[0]) + return new_haloIDs + + def _find_parents(self, halos): + # Given a set of halos, find their parents and add that to each of their + # node records. At the same time, make a link record for that + # relationship. + # This stores the newly discovered parent halos. + newhalos = set([]) + for halo in halos: + line = "SELECT GlobalHaloID, ChildHaloFrac0,\ + ChildHaloFrac1, ChildHaloFrac2,ChildHaloFrac3, ChildHaloFrac4,\ + ChildHaloID0, ChildHaloID1, ChildHaloID2, \ + ChildHaloID3, ChildHaloID4 \ + FROM Halos WHERE\ + ChildHaloID0=? or ChildHaloID1=? or ChildHaloID2=? or\ + ChildHaloID3=? or ChildHaloID4=?;" + values = (halo, halo, halo, halo, halo) + self.cursor.execute(line, values) + result = self.cursor.fetchone() + while result: + res = list(result) + pID = result[0] + pfracs = res[1:6] + cIDs = res[6:11] + for pair in zip(cIDs, pfracs): + if pair[1] <= self.link_min or pair[0] != halo: + continue + else: + self.nodes[halo].parentIDs.append(pID) + self.links[pID].childIDs.append(halo) + self.links[pID].fractions.append(pair[1]) + newhalos.add(pID) + result = self.cursor.fetchone() + return newhalos + + def _add_nodes(self, newhalos): + # Each call of this function always happens for a set of newhalos that + # are at the same z. To give the halos color we will figure out how + # many halos total were found this z. + # There's probably a way to do this with only one SQL operation. + if len(newhalos) == 0: + return + ahalo = list(newhalos)[0] + line = 'SELECT SnapCurrentTimeIdentifier FROM Halos WHERE GlobalHaloID=?;' + values = (ahalo,) + self.cursor.execute(line, values) + result = self.cursor.fetchone() + # Use currt to get the number. + line = 'SELECT max(SnapHaloID) FROM Halos where SnapCurrentTimeIdentifier=?;' + values = (result[0],) + self.cursor.execute(line, values) + maxID = self.cursor.fetchone()[0] + # For the new halos, create nodes for them. + for halo in newhalos: + line = 'SELECT SnapZ, HaloMass, CenMassX, CenMassY, CenMassZ,\ + SnapHaloID FROM Halos WHERE GlobalHaloID=? limit 1;' + value = (halo,) + self.cursor.execute(line, value) + result = self.cursor.fetchone() + self.nodes[halo] = Node(na.array([result[2],result[3],result[4]]), + result[1], [], result[0], 1. - float(result[5])/(maxID+1)) #+1 to prevent /0 + self.levels[result[0]].append(halo) + + def _open_dot(self, dotfile): + # Write out the opening stuff in the dotfile. + self.dotfile=self._write_on_root(dotfile) + line = 'digraph galaxy {size="10, 10";\n' + line += 'node [style=bold, shape=record];\n' + self.dotfile.write(line) + + def _close_dot(self): + self.dotfile.write("\n};\n") + self.dotfile.close() + + def _write_nodes(self): + # Write out the nodes to the dot file. + self.dotfile.write("{\n") + for halo in self.nodes: + this = self.nodes[halo] + line = '"%d" [label="{%1.3e\\n(%1.3f,%1.3f,%1.3f)}", shape="record",' \ + % (halo, this.mass, this.CoM[0], this.CoM[1], this.CoM[2]) + line += ' color="%0.3f 1. %0.3f"];\n' % (this.color, this.color) + self.dotfile.write(line) + self.dotfile.write("};\n") + + def _write_links(self): + # Write out the links to the dot file. + self.dotfile.write("{\n") + for parent in self.links: + this = self.links[parent] + for child,frac in zip(this.childIDs, this.fractions): + if frac > self.link_min: + line = '"%d"->"%d" [label="%3.2f%%", color="blue", fontsize=10];\n' \ + % (parent, child, frac*100.) + self.dotfile.write(line) + self.dotfile.write("};\n") + + def _write_levels(self): + # Write out the co-leveled halos to the dot file. + for z in self.levels: + this = self.levels[z] + self.dotfile.write("{ rank = same;\n") + line = '"%1.5f"; ' % z + for halo in this: + line += '"%d"; ' % halo + line += "\n};\n" + self.dotfile.write(line) + # Also write out the unlinked boxes for the redshifts. + line = '{"%1.5f" [label="{%1.5f}", shape="record" color="green"];}\n' \ + % (z, z) + +class MergerTreeTextOutput(DatabaseFunctions, ParallelAnalysisInterface): + def __init__(self, database='halos.db', outfile='MergerTreeDB.txt'): + r"""Dump the contents of the merger tree database to a text file. + This is generally not recommended. + + Parameters + ---------- + database : String + Name of the database to access. Default = 'halos.db'. + outfile : String + Name of the file to write to. Default = 'MergerTreeDB.txt'. + + Examples + -------- + >>> MergerTreeTextOutput(database='/home/user/sim1-halos.db', + ... outfile='halos-db.txt') + """ + self.database = database + self.outfile = outfile + result = self._open_database() + if not result: + mylog.warn("Database file not read correctly!") + return None + self._write_out() + self._close_database() + return None + + def _write_out(self): + # Essentially dump the contents of the database into a text file. + fp = open(self.outfile, "w") + # Make the header line. + spacing = {} + for column in columns: + spacing[column] = (max(15,len(column)+1)) + line = "# " + for column in columns: + line += "%s" % column.ljust(spacing[column]) + line += "\n" + fp.write(line) + # Get the data. + line = "SELECT * FROM Halos ORDER BY SnapZ DESC, SnapHaloID ASC;" + self.cursor.execute(line) + results = self.cursor.fetchone() + # Write out the columns. + while results: + line = " " + for i,column in enumerate(columns): + if column_types[column] == "FLOAT": + this = "%1.6e" % results[i] + line += this.ljust(spacing[column]) + if column_types[column] == "INTEGER": + this = "%d" % results[i] + line += this.ljust(spacing[column]) + line += "\n" + fp.write(line) + results = self.cursor.fetchone() + fp.close() + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_merger_tree/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_merger_tree/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('halo_merger_tree',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_profiler/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_profiler/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,37 @@ +""" +API for halo_profiler + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .halo_filters import \ + VirialFilter + +from .multi_halo_profiler import \ + HaloProfiler, \ + FakeProfile, \ + shift_projections diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_profiler/halo_filters.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_profiler/halo_filters.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,116 @@ +""" +Halo filters to be used with the HaloProfiler. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +from copy import deepcopy +import numpy as na + +from yt.funcs import * + +def VirialFilter(profile,overdensity_field='ActualOverdensity', + virial_overdensity=200.,must_be_virialized=True, + virial_filters=[['TotalMassMsun','>=','1e14']], + virial_quantities=['TotalMassMsun','RadiusMpc'], + virial_index=None): + """ + Filter halos by virial quantities. + Return values are a True or False whether the halo passed the filter, + along with a dictionary of virial quantities for the fields specified in + the virial_quantities keyword. Thresholds for virial quantities are + given with the virial_filters keyword in the following way: + [field, condition, value]. + """ + + fields = deepcopy(virial_quantities) + if virial_filters is None: virial_filters = [] + for vfilter in virial_filters: + if not vfilter[0] in fields: + fields.append(vfilter[0]) + + overDensity = [] + temp_profile = {} + for field in fields: + temp_profile[field] = [] + + for q in range(len(profile[overdensity_field])): + good = True + if (profile[overdensity_field][q] != profile[overdensity_field][q]): + good = False + continue + for field in fields: + if (profile[field][q] != profile[field][q]): + good = False + break + if good: + overDensity.append(profile[overdensity_field][q]) + for field in fields: + temp_profile[field].append(profile[field][q]) + + virial = {} + for field in fields: + virial[field] = 0.0 + + if (not (na.array(overDensity) >= virial_overdensity).any()) and \ + must_be_virialized: + mylog.error("This halo is not virialized!") + return [False, {}] + + if (len(overDensity) < 2): + mylog.error("Skipping halo with no valid points in profile.") + return [False, {}] + + if (overDensity[1] <= virial_overdensity): + index = 0 + elif (overDensity[-1] >= virial_overdensity): + index = -2 + else: + for q in (na.arange(len(overDensity)-2))+2: + if (overDensity[q] < virial_overdensity): + index = q - 1 + break + + if type(virial_index) is list: + virial_index.append(index) + + for field in fields: + if (overDensity[index+1] - overDensity[index]) == 0: + mylog.error("Overdensity profile has slope of zero.") + return [False, {}] + else: + slope = (temp_profile[field][index+1] - temp_profile[field][index]) / \ + (overDensity[index+1] - overDensity[index]) + value = slope * (virial_overdensity - overDensity[index]) + \ + temp_profile[field][index] + virial[field] = value + + for vfilter in virial_filters: + if eval("%s %s %s" % (virial[vfilter[0]],vfilter[1],vfilter[2])): + mylog.debug("(%s %s %s) returned True for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]])) + continue + else: + mylog.debug("(%s %s %s) returned False for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]])) + return [False, {}] + + return [True, dict((q,virial[q]) for q in virial_quantities)] + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_profiler/multi_halo_profiler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_profiler/multi_halo_profiler.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,839 @@ +""" +HaloProfiler class and member functions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +import numpy as na +import os +import h5py +import types + +from yt.funcs import * + +from yt.convenience import \ + load +from yt.data_objects.profiles import \ + BinnedProfile1D +from yt.analysis_modules.halo_finding.api import \ + HaloFinder +from .halo_filters import \ + VirialFilter +from yt.data_objects.field_info_container import \ + add_field + +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelAnalysisInterface, \ + parallel_blocking_call, \ + parallel_root_only +from yt.visualization.fixed_resolution import \ + FixedResolutionBuffer +from yt.visualization.plot_collection import \ + PlotCollection + +PROFILE_RADIUS_THRESHOLD = 2 + +class HaloProfiler(ParallelAnalysisInterface): + "Radial profiling, filtering, and projections for halos in cosmological simulations." + def __init__(self, dataset, halos='multiple', halo_list_file='HopAnalysis.out', halo_list_format='yt_hop', + halo_finder_function=HaloFinder, halo_finder_args=None, halo_finder_kwargs=None, + use_density_center=False, density_center_exponent=1.0, use_field_max_center=None, + halo_radius=0.1, radius_units='1', n_profile_bins=50, + profile_output_dir='radial_profiles', projection_output_dir='projections', + projection_width=8.0, projection_width_units='mpc', project_at_level='max', + velocity_center=['bulk', 'halo'], filter_quantities=['id','center']): + """ + Initialize a HaloProfiler object. + :param halos (str): "multiple" for profiling more than one halo. In this mode halos are read in + from a list or identified with a halo finder. In "single" mode, the one and only halo + center is identified automatically as the location of the peak in the density field. + Default: "multiple". + :param halo_list_file (str): name of file containing the list of halos. The HaloProfiler will + look for this file in the data directory. Default: "HopAnalysis.out". + :param halo_list_format (str or dict): the format of the halo list file. "yt_hop" for the format + given by yt's halo finders. "enzo_hop" for the format written by enzo_hop. This keyword + can also be given in the form of a dictionary specifying the column in which various + properties can be found. For example, {"id": 0, "center": [1, 2, 3], "mass": 4, "radius": 5}. + Default: "yt_hop". + :param halo_finder_function (function): If halos is set to multiple and the file given by + halo_list_file does not exit, the halo finding function specified here will be called. + Default: HaloFinder (yt_hop). + :param halo_finder_args (tuple): args given with call to halo finder function. Default: None. + :param halo_finder_kwargs (dict): kwargs given with call to halo finder function. Default: None. + :param use_density_center (bool): re-center halos before performing profiles with an center of mass + weighted by overdensity. This is generally not needed. Default: False. + :param density_center_exponent (float): when use_density_center set to True, this specifies the + exponent, alpha, such that the halo center calculation is weighted by overdensity^alpha. + Default: 1.0. + :param use_field_max_center (str): another alternative for halo re-centering by selecting the + location of the maximum of the field given by this keyword. This is generally not needed. + Default: None. + :param halo_radius (float): if no halo radii are provided in the halo list file, this parameter is + used to specify the radius out to which radial profiles will be made. This keyword is also + used when halos is set to single. Default: 0.1. + :param radius_units (str): the units of halo_radius. Default: "1" (code units). + :param n_profile_bins (int): the number of bins in the radial profiles. Default: 50. + :param profile_output_dir (str): the subdirectory, inside the data directory, in which radial profile + output files will be created. The directory will be created if it does not exist. + Default: "radial_profiles". + :param projection_output_dir (str): the subdirectory, inside the data directory, in which projection + output files will be created. The directory will be created if it does not exist. + Default: "projections". + :param projection_width (float): the width of halo projections. Default: 8.0. + :param projection_width_units (str): the units of projection_width. Default: "mpc". + :param project_at_level (int or "max"): the maximum refinement level to be included in projections. + Default: "max" (maximum level within the dataset). + :param velocity_center (list): the method in which the halo bulk velocity is calculated (used for + calculation of radial and tangential velocities. Valid options are: + - ["bulk", "halo"] (Default): the velocity provided in the halo list + - ["bulk", "sphere"]: the bulk velocity of the sphere centered on the halo center. + - ["max", field]: the velocity of the cell that is the location of the maximum of the field + specified (used only when halos set to single). + :param filter_quantities (list): quantities from the original halo list file to be written out in the + filtered list file. Default: ['id','center']. + """ + + self.dataset = dataset + + self.profile_output_dir = profile_output_dir + self.projection_output_dir = projection_output_dir + self.n_profile_bins = n_profile_bins + self.projection_width = projection_width + self.projection_width_units = projection_width_units + self.project_at_level = project_at_level + self.filter_quantities = filter_quantities + if self.filter_quantities is None: self.filter_quantities = [] + + self.profile_fields = [] + self.projection_fields = [] + + self._halo_filters = [] + self.all_halos = [] + self.filtered_halos = [] + self._projection_halo_list = [] + + # Set halo finder function and parameters, if needed. + self.halo_finder_function = halo_finder_function + self.halo_finder_args = halo_finder_args + if self.halo_finder_args is None: self.halo_finder_args = () + self.halo_finder_kwargs = halo_finder_kwargs + if self.halo_finder_kwargs is None: self.halo_finder_kwargs = {} + + # Set option to get halos from hop or single halo at density maximum. + # multiple: get halos from hop + # single: get single halo from density maximum + self.halos = halos + if not(self.halos is 'multiple' or self.halos is 'single'): + mylog.error("Keyword, halos, must be either 'single' or 'multiple'.") + return None + + # Set halo list format. + # 'yt_hop': yt hop output. + # 'enzo_hop': enzo_hop output. + # dictionary: a dictionary containing fields and their corresponding columns. + self.halo_list_file = halo_list_file + if halo_list_format == 'yt_hop': + self.halo_list_format = {'id':0, 'mass':1, 'center':[7, 8, 9], 'velocity':[10, 11, 12], 'r_max':13} + elif halo_list_format == 'enzo_hop': + self.halo_list_format = {'id':0, 'center':[4, 5, 6]} + elif isinstance(halo_list_format, types.DictType): + self.halo_list_format = halo_list_format + else: + mylog.error("Keyword, halo_list_format, must be 'yt_hop', 'enzo_hop', or a dictionary of custom settings.") + return None + + # Option to recenter sphere on density center. + self.use_density_center = use_density_center + self.density_center_exponent = density_center_exponent + if self.use_density_center: + def _MatterDensityXTotalMass(field, data): + return na.power((data['Matter_Density'] * data['TotalMassMsun']), self.density_center_exponent) + def _Convert_MatterDensityXTotalMass(data): + return 1 + add_field("MatterDensityXTotalMass", units=r"", + function=_MatterDensityXTotalMass, + convert_function=_Convert_MatterDensityXTotalMass) + + # Option to recenter sphere on the location of a field max. + self.use_field_max_center = use_field_max_center + if self.use_field_max_center is not None: + self.use_density_center = False + + # Look for any field that might need to have the bulk velocity set. + self._need_bulk_velocity = False + for field in [hp['field'] for hp in self.profile_fields]: + if 'Velocity' in field or 'Mach' in field: + self._need_bulk_velocity = True + break + + # Check validity for VelocityCenter parameter which toggles how the + # velocity is zeroed out for radial velocity profiles. + self.velocity_center = velocity_center[:] + if self.velocity_center[0] == 'bulk': + if self.velocity_center[1] == 'halo' and \ + self.halos is 'single': + mylog.error("Parameter, VelocityCenter, must be set to 'bulk sphere' or 'max ' with halos flag set to 'single'.") + return None + if self.velocity_center[1] == 'halo' and \ + self.halo_list_format is 'enzo_hop': + mylog.error("Parameter, VelocityCenter, must be 'bulk sphere' for old style hop output files.") + return None + if not(self.velocity_center[1] == 'halo' or + self.velocity_center[1] == 'sphere'): + mylog.error("Second value of VelocityCenter must be either 'halo' or 'sphere' if first value is 'bulk'.") + return None + elif self.velocity_center[0] == 'max': + if self.halos is 'multiple': + mylog.error("Getting velocity center from a max field value only works with halos='single'.") + return None + else: + mylog.error("First value of parameter, VelocityCenter, must be either 'bulk' or 'max'.") + return None + + # Create dataset object. + self.pf = load(self.dataset) + self.pf.h + if self.halos is 'single' or not 'r_max' in self.halo_list_format: + self.halo_radius = halo_radius / self.pf[radius_units] + + # Get halo(s). + if self.halos is 'single': + v, center = self.pf.h.find_max('Density') + singleHalo = {} + singleHalo['center'] = center + singleHalo['r_max'] = self.halo_radius * self.pf.units['mpc'] + singleHalo['id'] = 0 + self.all_halos.append(singleHalo) + elif self.halos is 'multiple': + # Get hop data. + self._load_halo_data() + if len(self.all_halos) == 0: + mylog.error("No halos loaded, there will be nothing to do.") + return None + else: + mylog.error("I don't know whether to get halos from hop or from density maximum. This should not have happened.") + return None + + def add_halo_filter(self, function, *args, **kwargs): + "Add a halo filter to the filter list." + + self._halo_filters.append({'function':function, 'args':args, 'kwargs':kwargs}) + + def add_profile(self, field, weight_field=None, accumulation=False): + "Add a field for profiling." + + self.profile_fields.append({'field':field, 'weight_field':weight_field, 'accumulation':accumulation}) + + def add_projection(self, field, weight_field=None): + "Add a field for projection." + + self.projection_fields.append({'field':field, 'weight_field':weight_field}) + + @parallel_blocking_call + def make_profiles(self, filename=None, prefilters=None, **kwargs): + "Make radial profiles for all halos on the list." + + # Reset filtered halo list. + self.filtered_halos = [] + + # Check to see if the VirialFilter has been added to the filter list. + # If a lower mass cutoff is being used, use it to make a pre-filter. + if prefilters is None: prefilters = [] + virial_prefilter = None + virial_prefilter_safety_factor = 0.5 + all_filter_functions = [hf['function'] for hf in self._halo_filters] + virial_filter = VirialFilter in all_filter_functions + if 'mass' in self.halo_list_format and VirialFilter in all_filter_functions: + vFilter = self._halo_filters[all_filter_functions.index(VirialFilter)] + if vFilter['kwargs'].has_key('virial_filters') and \ + vFilter['kwargs']['virial_filters'] is not None: + all_vqFilters = [vqf[0] for vqf in vFilter['kwargs']['virial_filters']] + if 'TotalMassMsun' in all_vqFilters: + mass_filter = vFilter['kwargs']['virial_filters'][all_vqFilters.index('TotalMassMsun')] + if '>' in mass_filter[1]: + virial_prefilter = "halo['mass'] %s %f * %s" % (mass_filter[1], virial_prefilter_safety_factor, mass_filter[2]) + prefilters.append(virial_prefilter) + elif '<' in mass_filter[1]: + virial_prefilter = "halo['mass'] %s %f * %s" % (mass_filter[1], (1./virial_prefilter_safety_factor), mass_filter[2]) + prefilters.append(virial_prefilter) + + # Add profile fields necessary for calculating virial quantities. + if virial_filter: self._check_for_needed_profile_fields() + + outputDir = "%s/%s" % (self.pf.fullpath, self.profile_output_dir) + self.__check_directory(outputDir) + + # Profile all halos. + for halo in self._get_objs('all_halos', round_robin=True): + + # Apply prefilters to avoid profiling unwanted halos. + filter_result = True + haloQuantities = {} + if prefilters is not None: + for prefilter in prefilters: + if not eval(prefilter): + filter_result = False + break + + if filter_result and len(self.profile_fields) > 0: + + profile_filename = "%s/Halo_%04d_profile.dat" % (outputDir, halo['id']) + + profiledHalo = self._get_halo_profile(halo, profile_filename, virial_filter=virial_filter) + + if profiledHalo is None: + continue + + # Apply filter and keep track of the quantities that are returned. + for hFilter in self._halo_filters: + filter_result, filterQuantities = hFilter['function'](profiledHalo, *hFilter['args'], **hFilter['kwargs']) + + if not filter_result: break + + if filterQuantities is not None: + haloQuantities.update(filterQuantities) + + if filter_result: + for quantity in self.filter_quantities: + if halo.has_key(quantity): haloQuantities[quantity] = halo[quantity] + + self.filtered_halos.append(haloQuantities) + + self.filtered_halos = self._mpi_catlist(self.filtered_halos) + self.filtered_halos.sort(key = lambda a:a['id']) + + if filename is not None: + self._write_filtered_halo_list(filename, **kwargs) + + def _get_halo_profile(self, halo, filename, virial_filter=True, force_write=False): + """ + Profile a single halo and write profile data to a file. + If file already exists, read profile data from file. + Return a dictionary of id, center, and virial quantities if virial_filter is True. + """ + + # Read profile from file if it already exists. + # If not, profile will be None. + profile = self._read_profile(filename) + + # Make profile if necessary. + newProfile = profile is None + if newProfile: + + r_min = 2 * self.pf.h.get_smallest_dx() * self.pf['mpc'] + if (halo['r_max'] / r_min < PROFILE_RADIUS_THRESHOLD): + mylog.error("Skipping halo with r_max / r_min = %f." % (halo['r_max']/r_min)) + return None + + sphere = self.pf.h.sphere(halo['center'], halo['r_max']/self.pf.units['mpc']) + if len(sphere._grids) == 0: return None + new_sphere = False + + if self.use_density_center: + dc_x = sphere.quantities['WeightedAverageQuantity']('x', 'MatterDensityXTotalMass') + dc_y = sphere.quantities['WeightedAverageQuantity']('y', 'MatterDensityXTotalMass') + dc_z = sphere.quantities['WeightedAverageQuantity']('z', 'MatterDensityXTotalMass') + mylog.info("Moving halo center from %s to %s." % (halo['center'], [dc_x, dc_y, dc_z])) + halo['center'] = [dc_x, dc_y, dc_z] + new_sphere = True + + if self.use_field_max_center is not None: + ma, maxi, mx, my, mz, mg = sphere.quantities['MaxLocation'](self.use_field_max_center) + mylog.info("Moving halo center from %s to %s." % (halo['center'], [mx, my, mz])) + halo['center'] = [mx, my, mz] + new_sphere = True + + if new_sphere: + # Temporary solution to memory leak. + for g in self.pf.h.grids: + g.clear_data() + sphere.clear_data() + del sphere + sphere = self.pf.h.sphere(halo['center'], halo['r_max']/self.pf.units['mpc']) + + if self._need_bulk_velocity: + # Set bulk velocity to zero out radial velocity profiles. + if self.velocity_center[0] == 'bulk': + if self.velocity_center[1] == 'halo': + sphere.set_field_parameter('bulk_velocity', halo['velocity']) + elif self.velocity_center[1] == 'sphere': + sphere.set_field_parameter('bulk_velocity', sphere.quantities['BulkVelocity']()) + else: + mylog.error("Invalid parameter: VelocityCenter.") + elif self.velocity_center[0] == 'max': + max_grid, max_cell, max_value, max_location = self.pf.h.find_max_cell_location(self.velocity_center[1]) + sphere.set_field_parameter('bulk_velocity', [max_grid['x-velocity'][max_cell], + max_grid['y-velocity'][max_cell], + max_grid['z-velocity'][max_cell]]) + + profile = BinnedProfile1D(sphere, self.n_profile_bins, "RadiusMpc", + r_min, halo['r_max'], + log_space=True, lazy_reader=False) + for hp in self.profile_fields: + profile.add_fields(hp['field'], weight=hp['weight_field'], accumulation=hp['accumulation']) + + if virial_filter: + self._add_actual_overdensity(profile) + + if newProfile: + mylog.info("Writing halo %d" % halo['id']) + profile.write_out(filename, format='%0.6e') + elif force_write: + mylog.info("Re-writing halo %d" % halo['id']) + self._write_profile(profile, filename, format='%0.6e') + + if newProfile: + # Temporary solution to memory leak. + for g in self.pf.h.grids: + g.clear_data() + sphere.clear_data() + del sphere + + return profile + + @parallel_blocking_call + def make_projections(self, axes=[0, 1, 2], halo_list='filtered', save_images=False, save_cube=True): + "Make projections of all halos using specified fields." + + # Get list of halos for projecting. + if halo_list == 'filtered': + self._halo_projection_list = self.filtered_halos + elif halo_list == 'all': + self._halo_projection_list = self.all_halos + elif isinstance(halo_list, types.StringType): + self._halo_projection_list = self._read_halo_list(halo_list) + elif isinstance(halo_list, types.ListType): + self._halo_projection_list = halo_list + else: + mylog.error("Keyword, halo_list', must be 'filtered', 'all', a filename, or an actual list.") + return + + if len(self._halo_projection_list) == 0: + mylog.error("Halo list for projections is empty.") + return + + # Set resolution for fixed resolution output. + if save_cube: + if self.project_at_level == 'max': + proj_level = self.pf.h.max_level + else: + proj_level = int(self.project_at_level) + proj_dx = self.pf.units[self.projection_width_units] / self.pf.parameters['TopGridDimensions'][0] / \ + (self.pf.parameters['RefineBy']**proj_level) + projectionResolution = int(self.projection_width / proj_dx) + + outputDir = "%s/%s" % (self.pf.fullpath, self.projection_output_dir) + self.__check_directory(outputDir) + + center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] + self.pf.parameters['DomainRightEdge'][w]) + for w in range(self.pf.parameters['TopGridRank'])] + + for halo in self._get_objs('_halo_projection_list', round_robin=True): + if halo is None: + continue + # Check if region will overlap domain edge. + # Using non-periodic regions is faster than using periodic ones. + leftEdge = [(halo['center'][w] - 0.5 * self.projection_width/self.pf.units[self.projection_width_units]) + for w in range(len(halo['center']))] + rightEdge = [(halo['center'][w] + 0.5 * self.projection_width/self.pf.units[self.projection_width_units]) + for w in range(len(halo['center']))] + + mylog.info("Projecting halo %04d in region: [%f, %f, %f] to [%f, %f, %f]." % + (halo['id'], leftEdge[0], leftEdge[1], leftEdge[2], rightEdge[0], rightEdge[1], rightEdge[2])) + + need_per = False + for w in range(len(halo['center'])): + if ((leftEdge[w] < self.pf.parameters['DomainLeftEdge'][w]) or + (rightEdge[w] > self.pf.parameters['DomainRightEdge'][w])): + need_per = True + break + + if need_per: + region = self.pf.h.periodic_region(halo['center'], leftEdge, rightEdge) + else: + region = self.pf.h.region(halo['center'], leftEdge, rightEdge) + + # Make projections. + if not isinstance(axes, types.ListType): axes = list([axes]) + for w in axes: + # Create a plot collection. + pc = PlotCollection(self.pf, center=center) + # YT projections do not follow the right-hand rule. + coords = range(3) + del coords[w] + x_axis = coords[0] + y_axis = coords[1] + + for hp in self.projection_fields: + pc.add_projection(hp['field'], w, weight_field=hp['weight_field'], data_source=region) + + # Set x and y limits, shift image if it overlaps domain boundary. + if need_per: + pw = self.projection_width/self.pf.units[self.projection_width_units] + shift_projections(self.pf, pc, halo['center'], center, w) + # Projection has now been shifted to center of box. + proj_left = [center[x_axis]-0.5*pw, center[y_axis]-0.5*pw] + proj_right = [center[x_axis]+0.5*pw, center[y_axis]+0.5*pw] + else: + proj_left = [leftEdge[x_axis], leftEdge[y_axis]] + proj_right = [rightEdge[x_axis], rightEdge[y_axis]] + + pc.set_xlim(proj_left[0], proj_right[0]) + pc.set_ylim(proj_left[1], proj_right[1]) + + # Save projection data to hdf5 file. + if save_cube: + axis_labels = ['x', 'y', 'z'] + dataFilename = "%s/Halo_%04d_%s_data.h5" % \ + (outputDir, halo['id'], axis_labels[w]) + mylog.info("Saving projection data to %s." % dataFilename) + + output = h5py.File(dataFilename, "a") + # Create fixed resolution buffer for each projection and write them out. + for e, hp in enumerate(self.projection_fields): + frb = FixedResolutionBuffer(pc.plots[e].data, (proj_left[0], proj_right[0], proj_left[1], proj_right[1]), + (projectionResolution, projectionResolution), + antialias=False) + dataset_name = "%s_%s" % (hp['field'], hp['weight_field']) + if dataset_name in output.listnames(): del output[dataset_name] + output.create_dataset(dataset_name, data=frb[hp['field']]) + output.close() + + if save_images: + pc.save("%s/Halo_%04d" % (outputDir, halo['id']), force_save=True) + + del region + + def _add_actual_overdensity(self, profile): + "Calculate overdensity from TotalMassMsun and CellVolume fields." + + if 'ActualOverdensity' in profile.keys(): + return + + rho_crit_now = 1.8788e-29 * self.pf.hubble_constant**2.0 * \ + self.pf.omega_matter # g cm^-3 + Msun2g = 1.989e33 + rho_crit = rho_crit_now * ((1.0 + self.pf.current_redshift)**3.0) + + profile['ActualOverdensity'] = (Msun2g * profile['TotalMassMsun']) / \ + profile['CellVolume'] / rho_crit + + def _check_for_needed_profile_fields(self): + "Make sure CellVolume and TotalMass fields are added so virial quantities can be calculated." + all_profile_fields = [hp['field'] for hp in self.profile_fields] + if not 'CellVolume' in all_profile_fields: + mylog.info("Adding CellVolume field to so virial quantities can be calculated") + self.add_profile('CellVolume', weight_field=None, accumulation=True) + if not 'TotalMassMsun' in all_profile_fields: + mylog.info("Adding TotalMassMsun field to so virial quantities can be calculated") + self.add_profile('TotalMassMsun', weight_field=None, accumulation=True) + + def _load_halo_data(self, filename=None): + "Read hop output file or run hop if it doesn't exist." + + # Don't run if hop data already loaded. + if self.all_halos: + return + + if filename is None: + filename = self.halo_list_file + + hopFile = "%s/%s" % (self.pf.fullpath, filename) + + if not(os.path.exists(hopFile)): + mylog.info("Hop file not found, running hop to get halos.") + self._run_hop(hopFile) + + self.all_halos = self._read_halo_list(hopFile) + + def _read_halo_list(self, listFile): + """ + Read halo list from aue file. + Allow for columnar data in varying formats. + """ + + def __isE(arg): + parts = arg.lower().split('e') + if len(parts) != 2: return False + return not (True in [q.isalpha() for q in ''.join(parts)]) + + def __get_num(arg): + if __isE(arg): + return float(arg) + if arg != arg.swapcase(): + return arg + return float(arg) + + mylog.info("Reading halo information from %s." % listFile) + haloList = [] + listLines = file(listFile) + + fields = self.halo_list_format.keys() + getID = not 'id' in fields + getR_max = not 'r_max' in fields + + for line in listLines: + line = line.strip() + if not(line.startswith('#')): + halo = {} + onLine = line.split() + for field in fields: + if isinstance(self.halo_list_format[field], types.ListType): + halo[field] = [__get_num(onLine[q]) for q in self.halo_list_format[field]] + else: + halo[field] = __get_num(onLine[self.halo_list_format[field]]) + if getID: halo['id'] = len(haloList) + if getR_max: + halo['r_max'] = self.halo_radius * self.pf.units['mpc'] + else: + halo['r_max'] *= self.pf.units['mpc'] + haloList.append(halo) + + mylog.info("Loaded %d halos." % (len(haloList))) + return haloList + + def _read_profile(self, profileFile): + "Read radial profile from file. Return None if it doesn't have all the fields requested." + + # Check to see if file exists. + if not os.path.exists(profileFile): + return None + + f = open(profileFile, 'r') + lines = f.readlines() + f.close() + + # Get fields from header. + header = lines.pop(0) + header = header.strip() + fields = header.split() + # First string is '#'. + fields.pop(0) + + profile = {} + profile_obj = FakeProfile(self.pf) + for field in fields: + profile[field] = [] + + # Check if all fields needed are present. + all_profile_fields = [hp['field'] for hp in self.profile_fields] + for field in all_profile_fields: + if not field in profile: + return None + + # Fill profile fields, skip bad values. + for line in lines: + line = line.strip() + onLine = line.split() + lineOK = True + for value in onLine: + if value.isalpha(): + lineOK = False + break + if lineOK: + for q, field in enumerate(fields): + profile[field].append(float(onLine[q])) + + for field in fields: + profile[field] = na.array(profile[field]) + + profile_obj._data = profile + + if len(profile[fields[0]]) > 1: + return profile_obj + else: + return None + + @parallel_blocking_call + def _run_hop(self, hopFile): + "Run hop to get halos." + + hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args, **self.halo_finder_kwargs) + hop_results.write_out(hopFile) + + del hop_results + self.pf.h.clear_all_data() + + @parallel_root_only + def _write_filtered_halo_list(self, filename, format="%s"): + """ + Write out list of filtered halos along with any quantities + picked up during the filtering process. + """ + + if len(self.filtered_halos) == 0: + mylog.error("No halos in filtered list.") + return + + filename = "%s/%s" % (self.pf.fullpath, filename) + mylog.info("Writing filtered halo list to %s." % filename) + file = open(filename, "w") + fields = [field for field in sorted(self.filtered_halos[0])] + halo_fields = [] + for halo_field in self.filter_quantities: + if halo_field in fields: + fields.remove(halo_field) + halo_fields.append(halo_field) + # Make it so number of fields in header is same as number of data columns. + header_fields = [] + for halo_field in halo_fields: + if isinstance(self.filtered_halos[0][halo_field], types.ListType): + header_fields.extend(["%s[%d]" % (halo_field, q) + for q in range(len(self.filtered_halos[0][halo_field]))]) + else: + header_fields.append(halo_field) + file.write("# ") + file.write("\t".join(header_fields + fields + ["\n"])) + + for halo in self.filtered_halos: + for halo_field in halo_fields: + if isinstance(halo[halo_field], types.ListType): + field_data = na.array(halo[halo_field]) + field_data.tofile(file, sep="\t", format=format) + else: + if halo_field == 'id': + file.write("%04d" % halo[halo_field]) + else: + file.write("%s" % halo[halo_field]) + file.write("\t") + field_data = na.array([halo[field] for field in fields]) + field_data.tofile(file, sep="\t", format=format) + file.write("\n") + file.close() + + def _write_profile(self, profile, filename, format="%0.16e"): + fid = open(filename, "w") + fields = [field for field in sorted(profile.keys()) if field != "UsedBins"] + fid.write("\t".join(["#"] + fields + ["\n"])) + field_data = na.array([profile[field] for field in fields]) + for line in range(field_data.shape[1]): + field_data[:, line].tofile(fid, sep="\t", format=format) + fid.write("\n") + fid.close() + + @parallel_root_only + def __check_directory(self, outputDir): + if (os.path.exists(outputDir)): + if not(os.path.isdir(outputDir)): + mylog.error("Output directory exists, but is not a directory: %s." % outputDir) + raise IOError(outputDir) + else: + os.mkdir(outputDir) + +def shift_projections(pf, pc, oldCenter, newCenter, axis): + """ + Shift projection data around. + This is necessary when projecting a preiodic region. + """ + offset = [newCenter[q]-oldCenter[q] for q in range(len(oldCenter))] + width = [pf.parameters['DomainRightEdge'][q]-pf.parameters['DomainLeftEdge'][q] for q in range(len(oldCenter))] + + del offset[axis] + del width[axis] + + for plot in pc.plots: + # Get name of data field. + other_fields = {'px':True, 'py':True, 'pdx':True, 'pdy':True, 'weight_field':True} + for pfield in plot.data.data.keys(): + if not(other_fields.has_key(pfield)): + field = pfield + break + + # Shift x and y positions. + plot['px'] += offset[0] + plot['py'] += offset[1] + + # Wrap off-edge cells back around to other side (periodic boundary conditions). + plot['px'][plot['px'] < 0] += width[0] + plot['py'][plot['py'] < 0] += width[1] + plot['px'][plot['px'] > width[0]] -= width[0] + plot['py'][plot['py'] > width[1]] -= width[1] + + # After shifting, some cells have fractional coverage on both sides of the box. + # Find those cells and make copies to be placed on the other side. + + # Cells hanging off the right edge. + add_x_px = plot['px'][plot['px'] + 0.5 * plot['pdx'] > width[0]] + add_x_px -= width[0] + add_x_py = plot['py'][plot['px'] + 0.5 * plot['pdx'] > width[0]] + add_x_pdx = plot['pdx'][plot['px'] + 0.5 * plot['pdx'] > width[0]] + add_x_pdy = plot['pdy'][plot['px'] + 0.5 * plot['pdx'] > width[0]] + add_x_field = plot[field][plot['px'] + 0.5 * plot['pdx'] > width[0]] + add_x_weight_field = plot['weight_field'][plot['px'] + 0.5 * plot['pdx'] > width[0]] + + # Cells hanging off the left edge. + add2_x_px = plot['px'][plot['px'] - 0.5 * plot['pdx'] < 0] + add2_x_px += width[0] + add2_x_py = plot['py'][plot['px'] - 0.5 * plot['pdx'] < 0] + add2_x_pdx = plot['pdx'][plot['px'] - 0.5 * plot['pdx'] < 0] + add2_x_pdy = plot['pdy'][plot['px'] - 0.5 * plot['pdx'] < 0] + add2_x_field = plot[field][plot['px'] - 0.5 * plot['pdx'] < 0] + add2_x_weight_field = plot['weight_field'][plot['px'] - 0.5 * plot['pdx'] < 0] + + # Cells hanging off the top edge. + add_y_px = plot['px'][plot['py'] + 0.5 * plot['pdy'] > width[1]] + add_y_py = plot['py'][plot['py'] + 0.5 * plot['pdy'] > width[1]] + add_y_py -= width[1] + add_y_pdx = plot['pdx'][plot['py'] + 0.5 * plot['pdy'] > width[1]] + add_y_pdy = plot['pdy'][plot['py'] + 0.5 * plot['pdy'] > width[1]] + add_y_field = plot[field][plot['py'] + 0.5 * plot['pdy'] > width[1]] + add_y_weight_field = plot['weight_field'][plot['py'] + 0.5 * plot['pdy'] > width[1]] + + # Cells hanging off the bottom edge. + add2_y_px = plot['px'][plot['py'] - 0.5 * plot['pdy'] < 0] + add2_y_py = plot['py'][plot['py'] - 0.5 * plot['pdy'] < 0] + add2_y_py += width[1] + add2_y_pdx = plot['pdx'][plot['py'] - 0.5 * plot['pdy'] < 0] + add2_y_pdy = plot['pdy'][plot['py'] - 0.5 * plot['pdy'] < 0] + add2_y_field = plot[field][plot['py'] - 0.5 * plot['pdy'] < 0] + add2_y_weight_field = plot['weight_field'][plot['py'] - 0.5 * plot['pdy'] < 0] + + # Add the hanging cells back to the projection data. + plot.data['px'] = na.concatenate([plot['px'], add_x_px, add_y_px, add2_x_px, add2_y_px]) + plot.data['py'] = na.concatenate([plot['py'], add_x_py, add_y_py, add2_x_py, add2_y_py]) + plot.data['pdx'] = na.concatenate([plot['pdx'], add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx]) + plot.data['pdy'] = na.concatenate([plot['pdy'], add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy]) + plot.data[field] = na.concatenate([plot[field], add_x_field, add_y_field, add2_x_field, add2_y_field]) + plot.data['weight_field'] = na.concatenate([plot['weight_field'], + add_x_weight_field, add_y_weight_field, add2_x_weight_field, add2_y_weight_field]) + + # Delete original copies of hanging cells. + del add_x_px, add_y_px, add2_x_px, add2_y_px + del add_x_py, add_y_py, add2_x_py, add2_y_py + del add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx + del add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy + del add_x_field, add_y_field, add2_x_field, add2_y_field + del add_x_weight_field, add_y_weight_field, add2_x_weight_field, add2_y_weight_field + +class FakeProfile(ParallelAnalysisInterface): + """ + This is used to mimic a profile object when reading profile data from disk. + """ + def __init__(self, pf): + self.pf = pf + self._data = {} + + def __getitem__(self, key): + return self._data[key] + + def keys(self): + return self._data.keys() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/halo_profiler/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/halo_profiler/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('halo_profiler',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/hierarchy_subset/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/hierarchy_subset/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,36 @@ +""" +API for hierarchy_subset + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .hierarchy_subset import \ + ConstructedRootGrid, \ + AMRExtractedGridProxy, \ + ExtractedHierarchy, \ + ExtractedParameterFile + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/hierarchy_subset/hierarchy_subset.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/hierarchy_subset/hierarchy_subset.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,353 @@ +""" +A means of extracting a subset of the hierarchy + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 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 . +""" + +import h5py, os.path +import numpy as na + +from yt.funcs import * +from yt.data_objects.grid_patch import \ + AMRGridPatch +from yt.data_objects.static_output import \ + StaticOutput +from yt.data_objects.hierarchy import \ + AMRHierarchy + +class DummyHierarchy(object): + pass + +class ConstructedRootGrid(AMRGridPatch): + __slots__ = ['base_grid', 'id', 'base_pf'] + _id_offset = 1 + def __init__(self, base_pf, pf, hierarchy, level, left_edge, right_edge): + """ + This is a fake root grid, constructed by creating a + :class:`yt.data_objects.api.CoveringGridBase` at a given *level* between + *left_edge* and *right_edge*. + """ + self.pf = pf + self.base_pf = base_pf + self.field_parameters = {} + self.NumberOfParticles = 0 + self.id = 1 + self.hierarchy = hierarchy + self._child_mask = self._child_indices = self._child_index_mask = None + self.Level = level + self.LeftEdge = left_edge + self.RightEdge = right_edge + self.start_index = na.min([grid.get_global_startindex() for grid in + base_pf.h.select_grids(level)], axis=0).astype('int64') + self.dds = base_pf.h.select_grids(level)[0].dds.copy() + dims = (self.RightEdge-self.LeftEdge)/self.dds + self.ActiveDimensions = dims + print "Constructing base grid of size %s" % (self.ActiveDimensions) + self.base_grid = base_pf.h.smoothed_covering_grid(level, self.LeftEdge, + self.RightEdge, dims=dims) + self.base_grid.Level = self.base_grid.level + self.data = {} + #self._calculate_child_masks() + self.Parent = None + self.Children = [] + + def get_vertex_centered_data(self, field, smoothed=True): + vc = self.base_pf.h.smoothed_covering_grid(self.base_grid.Level, + self.base_grid.LeftEdge - self.base_grid.dds*0.5, + self.base_grid.RightEdge + self.base_grid.dds*0.5, + dims = self.ActiveDimensions + 1) + return vc[field] + +class AMRExtractedGridProxy(AMRGridPatch): + __slots__ = ['base_grid'] + _id_offset = 1 + def __init__(self, grid_id, base_grid, hierarchy): + # We make a little birdhouse in our soul for the base_grid + # (they're the only bee in our bonnet!) + self.base_grid = base_grid + AMRGridPatch.__init__(self, grid_id, filename = None, hierarchy=hierarchy) + self.Parent = None + self.Children = [] + self.Level = -1 + + def get_vertex_centered_data(self, *args, **kwargs): + return self.base_grid.get_vertex_centered_data(*args, **kwargs) + +class OldExtractedHierarchy(object): + + def __init__(self, pf, min_level, max_level = -1, offset = None, + always_copy=False): + """ + This is a class that extracts a hierarchy from another hierarchy, + filling in regions as necessary. It accepts a parameter file (*pf*), a + *min_level*, a *max_level*, and alternately an *offset*. This class is + typically or exclusively used to extract for the purposes of visualization. + """ + self.pf = pf + self.always_copy = always_copy + self.min_level = min_level + self.int_offset = na.min([grid.get_global_startindex() for grid in + pf.h.select_grids(min_level)], axis=0).astype('float64') + min_left = na.min([grid.LeftEdge for grid in + pf.h.select_grids(min_level)], axis=0).astype('float64') + max_right = na.max([grid.RightEdge for grid in + pf.h.select_grids(min_level)], axis=0).astype('float64') + if offset is None: offset = (max_right + min_left)/2.0 + self.left_edge_offset = offset + self.mult_factor = 2**min_level + self.min_left_edge = self._convert_coords(min_left) + self.max_right_edge = self._convert_coords(max_right) + if max_level == -1: max_level = pf.h.max_level + self.max_level = min(max_level, pf.h.max_level) + self.final_level = self.max_level - self.min_level + if len(self.pf.h.select_grids(self.min_level)) > 0: + self._base_grid = ConstructedRootGrid(self.pf, self.min_level, + min_left, max_right) + else: self._base_grid = None + + def select_level(self, level): + if level == 0 and self._base_grid is not None: + return [self._base_grid] + return self.pf.h.select_grids(self.min_level + level) + + def export_output(self, afile, n, field): + # I prefer dict access, but tables doesn't. + # But h5py does! + time_node = afile.create_group("/time-%s" % n) + time_node.attrs['time'] = self.pf.current_time + time_node.attrs['numLevels'] = self.pf.h.max_level+1-self.min_level + # Can take a while, so let's get a progressbar + self._export_all_levels(afile, time_node, field) + + def _export_all_levels(self, afile, time_node, field): + pbar = yt.funcs.get_pbar("Exporting levels", self.final_level+1) + for i,grid_set in enumerate(self.get_levels()): + pbar.update(i) + self.export_level(afile, time_node, i, field, grid_set) + pbar.finish() + + def export_level(self, afile, time_node, level, field, grids = None): + level_node = afile.create_group("%s/level-%s" % (time_node,level)) + # Grid objects on this level... + if grids is None: grids = self.pf.h.select_grids(level+self.min_level) + level_node.attrs['delta'] = grids[0].dds*self.mult_factor + level_node.attrs['relativeRefinementFactor'] = na.array([2]*3, dtype='int32') + level_node.attrs['numGrids'] = len(grids) + for i,g in enumerate(grids): + self.export_grid(afile, level_node, g, i, field) + + def _convert_grid(self, grid): + int_origin = (grid.get_global_startindex() \ + - self.int_offset*2**(grid.Level-self.min_level)).astype('int64') + level_int_origin = (grid.LeftEdge - self.left_edge_offset)/grid.dds + origin = self._convert_coords(grid.LeftEdge) + dds = grid.dds * self.mult_factor + return int_origin, level_int_origin, origin, dds + + def export_grid(self, afile, level_node, grid, i, field): + grid_node = afile.create_group("%s/grid-%s" % (level_node,i)) + int_origin, lint, origin, dds = self._convert_grid(grid) + grid_node.attrs['integerOrigin'] = int_origin + grid_node.attrs['origin'] = origin + grid_node.attrs['ghostzoneFlags'] = na.zeros(6, dtype='int32') + grid_node.attrs['numGhostzones'] = na.zeros(3, dtype='int32') + grid_node.attrs['dims'] = grid.ActiveDimensions[::-1].astype('int32') + if not self.always_copy and self.pf.h.data_style == 6 \ + and field in self.pf.h.field_list: + if grid.hierarchy.data_style == -1: # constructed grid + # if we can get conversion in amira we won't need to do this + ff = grid[field].astype('float32') + ff /= self.pf.conversion_factors.get(field, 1.0) + afile.create_dataset("%s/grid-data" % grid_node, data=ff.swapaxes(0,2)) + else: + tfn = os.path.abspath(afile.filename) + gfn = os.path.abspath(grid.filename) + fpn = os.path.commonprefix([tfn, grid.filename]) + fn = grid.filename[len(os.path.commonprefix([tfn, grid.filename])):] + grid_node.attrs['referenceFileName'] = fn + grid_node.attrs['referenceDataPath'] = \ + "/Grid%08i/%s" % (grid.id, field) + else: + # Export our array + afile.create_dataset("%s/grid-data" % grid_node, + data = grid[field].astype('float32').swapaxes(0,2)) + + def _convert_coords(self, val): + return (val - self.left_edge_offset)*self.mult_factor + +class ExtractedHierarchy(AMRHierarchy): + + grid = AMRExtractedGridProxy + + def __init__(self, pf, data_style): + # First we set up our translation between original and extracted + self.data_style = data_style + self.min_level = pf.min_level + self.int_offset = na.min([grid.get_global_startindex() for grid in + pf.base_pf.h.select_grids(pf.min_level)], axis=0).astype('float64') + min_left = na.min([grid.LeftEdge for grid in + pf.base_pf.h.select_grids(pf.min_level)], axis=0).astype('float64') + max_right = na.max([grid.RightEdge for grid in + pf.base_pf.h.select_grids(pf.min_level)], axis=0).astype('float64') + level_dx = pf.base_pf.h.select_grids(pf.min_level)[0].dds[0] + dims = ((max_right-min_left)/level_dx) + max_right += (dims.max() - dims) * level_dx + offset = pf.offset + if offset is None: offset = min_left + self.left_edge_offset = offset + pf.offset = offset + self.mult_factor = 2**pf.min_level + self.min_left_edge = self._convert_coords(min_left) + self.max_right_edge = self._convert_coords(max_right) + self.min_left, self.max_right = min_left, max_right + max_level = pf.max_level + if max_level == -1: max_level = pf.base_pf.h.max_level + self.max_level = min(max_level, pf.base_pf.h.max_level) + self.final_level = self.max_level - self.min_level + + # Now we utilize the existing machinery for generating the appropriate + # arrays of grids, etc etc. + self.base_pf = pf.base_pf + AMRHierarchy.__init__(self, pf, data_style) + + # Now a few cleanups + self.pf.override["DomainRightEdge"] = self.max_right_edge + self.pf.override["DomainLeftEdge"] = self.min_left_edge + for u,v in self.base_pf.units.items(): + self.pf.override[u] = v / self.mult_factor + self.pf.override['unitary'] = 1.0 / (self.pf.domain_right_edge - + self.pf.domain_left_edge).max() + + def _count_grids(self): + self.num_grids = 1 + sum( ( # 1 is the base grid + len(self.base_pf.h.select_grids(level)) + for level in range(self.min_level+1, self.max_level)) ) + + def _parse_hierarchy(self): + # Here we need to set up the grid info, which for the Enzo hierarchy + # is done like: + # self.grid_dimensions.flat[:] = ei + # self.grid_dimensions -= na.array(si, self.float_type) + # self.grid_dimensions += 1 + # self.grid_left_edge.flat[:] = LE + # self.grid_right_edge.flat[:] = RE + # self.grid_particle_count.flat[:] = np + # self.grids = na.array(self.grids, dtype='object') + # + # For now, we make the presupposition that all of our grids are + # strictly nested and we are not doing any cuts. However, we do + # construct a root grid! + root_level_grids = self.base_pf.h.select_grids(self.min_level) + base_grid = ConstructedRootGrid(self.base_pf, self.pf, self, + self.min_level, self.min_left, self.max_right) + self._fill_grid_arrays(base_grid, 0) + grids = [base_grid] + # We need to ensure we have the correct parentage relationships + # However, we want the parent/child to be to the new proxy grids + # so we need to map between the old ids and the new ids + self.id_map = {} + grid_id = 2 # id 0 is the base grid + for level in range(self.min_level+1, self.max_level): + for grid in self.base_pf.h.select_grids(level): + # This next little bit will have to be changed if we ever move to + # not-strictly-nested AMR hierarchies + parent = self.id_map.get(grid.Parent.id, base_grid) + grids.append(self.grid(grid_id, grid, self)) + parent.Children.append(grids[-1]) + grids[-1].Parent = parent + self.id_map[grid.id] = grids[-1] + # Now we fill in our arrays of values -- note that we + # are filling in values from the base grids, not the newly + # extracted grids. We will perform bulk changes after we + # finish. + self._fill_grid_arrays(grid, grid_id-1) + grid_id += 1 + + self.grid_left_edge = self._convert_coords(self.grid_left_edge) + self.grid_right_edge = self._convert_coords(self.grid_right_edge) + self.grids = na.array(grids, dtype='object') + + def _fill_grid_arrays(self, grid, i): + # This just fills in the grid arrays for a single grid -- + # note that we presuppose here that we are being handed a grid object + # that has these defined; this means we are being handed the *base* + # grid, not the newly extracted one + self.grid_dimensions[i,:] = grid.ActiveDimensions + self.grid_left_edge[i,:] = grid.LeftEdge + self.grid_right_edge[i,:] = grid.RightEdge + self.grid_particle_count[i] = grid.NumberOfParticles + + def _populate_grid_objects(self): + for grid in self.grids: + grid.Level = grid.base_grid.Level - self.pf.min_level + grid._prepare_grid() + grid._setup_dx() + grid.start_index = None + self.max_level -= self.pf.min_level + print "New max level:", self.max_level + + def _convert_coords(self, val): + return (val - self.left_edge_offset)*self.mult_factor + + def _detect_fields(self): + self.field_list = self.base_pf.h.field_list[:] + + def _setup_unknown_fields(self): + pass # Done in the base_h + + def _setup_derived_fields(self): + self.derived_field_list = self.base_pf.h.derived_field_list[:] + + def _initialize_data_storage(self): + self._data_file = None + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + +class ExtractedParameterFile(StaticOutput): + _hierarchy_class = ExtractedHierarchy + data_style = "extracted" + + def __init__(self, base_pf, min_level, max_level = -1, offset = None): + self.base_pf = base_pf + self.min_level = min_level + self.max_level = max_level + self.offset = offset + self.override = {} + + def __repr__(self): + return "extracted_%s" % self.base_pf + + def __getattr__(self, name): + # This won't get called if 'name' is found already + # and we'd like it to raise AttributeError if it's not anywhere + if name in ['h', 'hierarchy']: + return StaticOutput._get_hierarchy(self) + return getattr(self.base_pf, name) + + def __getitem__(self, key): + if key not in self.override: + return self.base_pf[key] + return self.override[key] + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/hierarchy_subset/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/hierarchy_subset/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('hierarchy_subset',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/level_sets/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/level_sets/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,52 @@ +""" +API for level_sets + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .contour_finder import \ + GridConsiderationQueue, \ + coalesce_join_tree, \ + identify_contours + +from .clump_handling import \ + Clump, \ + find_clumps, \ + get_lowest_clumps, \ + write_clump_hierarchy, \ + write_clumps, \ + write_old_clump_hierarchy, \ + write_old_clumps, \ + write_old_clump_info, \ + _DistanceToMainClump + +from .clump_tools import \ + recursive_all_clumps, \ + return_all_clumps, \ + return_bottom_clumps, \ + recursive_bottom_clumps, \ + clump_list_sort diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/level_sets/clump_handling.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/level_sets/clump_handling.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,292 @@ +""" +Clump finding helper classes + +Author: Britton Smith +Affiliation: University of Colorado at Boulder +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +import numpy as na +import copy + +from .contour_finder import identify_contours + +class Clump(object): + children = None + def __init__(self, data, parent, field, cached_fields = None, + function=None, clump_info=None): + self.parent = parent + self.data = data + self.field = field + self.min_val = self.data[field].min() + self.max_val = self.data[field].max() + self.cached_fields = cached_fields + + # List containing characteristics about clumps that are to be written + # out by the write routines. + if clump_info is None: + self.set_default_clump_info() + else: + # Clump info will act the same if add_info_item is called before or after clump finding. + self.clump_info = copy.deepcopy(clump_info) + + # Function determining whether a clump is valid and should be kept. + self.default_function = 'self.data.quantities["IsBound"](truncate=True,include_thermal_energy=True) > 1.0' + if function is None: + self.function = self.default_function + else: + self.function = function + + # Return value of validity function, saved so it does not have to be calculated again. + self.function_value = None + + def add_info_item(self,quantity,format): + "Adds an entry to clump_info list and tells children to do the same." + + self.clump_info.append({'quantity':quantity, 'format':format}) + if self.children is None: return + for child in self.children: + child.add_info_item(quantity,format) + + def set_default_clump_info(self): + "Defines default entries in the clump_info array." + + # add_info_item is recursive so this function does not need to be. + self.clump_info = [] + + # Number of cells. + self.add_info_item('self.data["CellMassMsun"].size','"Cells: %d" % value') + # Gas mass in solar masses. + self.add_info_item('self.data["CellMassMsun"].sum()','"Mass: %e Msolar" % value') + # Volume-weighted Jeans mass. + self.add_info_item('self.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellVolume")', + '"Jeans Mass (vol-weighted): %.6e Msolar" % value') + # Mass-weighted Jeans mass. + self.add_info_item('self.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellMassMsun")', + '"Jeans Mass (mass-weighted): %.6e Msolar" % value') + # Max level. + self.add_info_item('self.data["GridLevel"].max()','"Max grid level: %d" % value') + # Minimum number density. + self.add_info_item('self.data["NumberDensity"].min()','"Min number density: %.6e cm^-3" % value') + # Maximum number density. + self.add_info_item('self.data["NumberDensity"].max()','"Max number density: %.6e cm^-3" % value') + + def clear_clump_info(self): + "Clears the clump_info array and passes the instruction to its children." + + self.clump_info = [] + if self.children is None: return + for child in self.children: + child.clear_clump_info() + + def write_info(self,level,f_ptr): + "Writes information for clump using the list of items in clump_info." + + for item in self.clump_info: + # Call if callable, otherwise do an eval. + if callable(item['quantity']): + value = item['quantity']() + else: + value = eval(item['quantity']) + output = eval(item['format']) + f_ptr.write("%s%s" % ('\t'*level,output)) + f_ptr.write("\n") + + def find_children(self, min_val, max_val = None): + if self.children is not None: + print "Wiping out existing children clumps." + self.children = [] + if max_val is None: max_val = self.max_val + contour_info = identify_contours(self.data, self.field, min_val, max_val, + self.cached_fields) + for cid in contour_info: + new_clump = self.data.extract_region(contour_info[cid]) + self.children.append(Clump(new_clump, self, self.field, + self.cached_fields,function=self.function, + clump_info=self.clump_info)) + + def pass_down(self,operation): + "Performs an operation on a clump with an exec and passes the instruction down to clump children." + + # Call if callable, otherwise do an exec. + if callable(operation): + operation() + else: + exec(operation) + + for child in self.children: + child.pass_down(operation) + + def _isValid(self): + "Perform user specified function to determine if child clumps should be kept." + + # Only call function if it has not been already. + if self.function_value is None: + self.function_value = eval(self.function) + + return self.function_value + + def __reduce__(self): + return (_reconstruct_clump, + (self.parent, self.field, self.min_val, self.max_val, + self.function_value, self.children, self.data, self.clump_info, self.function)) + + def __getitem__(self,request): + return self.data[request] + +def _reconstruct_clump(parent, field, mi, ma, function_value, children, data, clump_info, + function=None): + obj = object.__new__(Clump) + if iterable(parent): parent = parent[1] + if children is None: children = [] + obj.parent, obj.field, obj.min_val, obj.max_val, obj.function_value, obj.children, obj.clump_info, obj.function = \ + parent, field, mi, ma, function_value, children, clump_info, function + # Now we override, because the parent/child relationship seems a bit + # unreliable in the unpickling + for child in children: child.parent = obj + obj.data = data[1] # Strip out the PF + if obj.parent is None: return (data[0], obj) + return obj + +def find_clumps(clump, min_val, max_val, d_clump): + print "Finding clumps: min: %e, max: %e, step: %f" % (min_val, max_val, d_clump) + if min_val >= max_val: return + clump.find_children(min_val) + + if (len(clump.children) == 1): + find_clumps(clump, min_val*d_clump, max_val, d_clump) + + elif (len(clump.children) > 0): + these_children = [] + print "Investigating %d children." % len(clump.children) + for child in clump.children: + find_clumps(child, min_val*d_clump, max_val, d_clump) + if ((child.children is not None) and (len(child.children) > 0)): + these_children.append(child) + elif (child._isValid()): + these_children.append(child) + else: + print "Eliminating invalid, childless clump with %d cells." % len(child.data["CellMassMsun"]) + if (len(these_children) > 1): + print "%d of %d children survived." % (len(these_children),len(clump.children)) + clump.children = these_children + elif (len(these_children) == 1): + print "%d of %d children survived, linking its children to parent." % (len(these_children),len(clump.children)) + clump.children = these_children[0].children + else: + print "%d of %d children survived, erasing children." % (len(these_children),len(clump.children)) + clump.children = [] + +def get_lowest_clumps(clump, clump_list=None): + "Return a list of all clumps at the bottom of the hierarchy." + + if clump_list is None: clump_list = [] + if clump.children is None or len(clump.children) == 0: + clump_list.append(clump) + if clump.children is not None and len(clump.children) > 0: + for child in clump.children: + get_lowest_clumps(child, clump_list=clump_list) + + return clump_list + +def write_clump_hierarchy(clump,level,f_ptr): + for q in range(level): + f_ptr.write("\t") + f_ptr.write("Clump at level %d:\n" % level) + clump.write_info(level,f_ptr) + f_ptr.write("\n") + f_ptr.flush() + if ((clump.children is not None) and (len(clump.children) > 0)): + for child in clump.children: + write_clump_hierarchy(child,(level+1),f_ptr) + +def write_clumps(clump,level,f_ptr): + if ((clump.children is None) or (len(clump.children) == 0)): + f_ptr.write("%sClump:\n" % ("\t"*level)) + clump.write_info(level,f_ptr) + f_ptr.write("\n") + f_ptr.flush() + if ((clump.children is not None) and (len(clump.children) > 0)): + for child in clump.children: + write_clumps(child,0,f_ptr) + +# Old clump info writing routines. +def write_old_clump_hierarchy(clump,level,f_ptr): + for q in range(level): + f_ptr.write("\t") + f_ptr.write("Clump at level %d:\n" % level) + clump.write_info(level,f_ptr) + write_old_clump_info(clump,level,f_ptr) + f_ptr.write("\n") + f_ptr.flush() + if ((clump.children is not None) and (len(clump.children) > 0)): + for child in clump.children: + write_clump_hierarchy(child,(level+1),f_ptr) + +def write_old_clumps(clump,level,f_ptr): + if ((clump.children is None) or (len(clump.children) == 0)): + f_ptr.write("%sClump:\n" % ("\t"*level)) + write_old_clump_info(clump,level,f_ptr) + f_ptr.write("\n") + f_ptr.flush() + if ((clump.children is not None) and (len(clump.children) > 0)): + for child in clump.children: + write_clumps(child,0,f_ptr) + +__clump_info_template = \ +""" +%(tl)sCells: %(num_cells)s +%(tl)sMass: %(total_mass).6e Msolar +%(tl)sJeans Mass (vol-weighted): %(jeans_mass_vol).6e Msolar +%(tl)sJeans Mass (mass-weighted): %(jeans_mass_mass).6e Msolar +%(tl)sMax grid level: %(max_level)s +%(tl)sMin number density: %(min_density).6e cm^-3 +%(tl)sMax number density: %(max_density).6e cm^-3 + +""" + +def write_old_clump_info(clump,level,f_ptr): + fmt_dict = {'tl': "\t" * level} + fmt_dict['num_cells'] = clump.data["CellMassMsun"].size, + fmt_dict['total_mass'] = clump.data["CellMassMsun"].sum() + fmt_dict['jeans_mass_vol'] = clump.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellVolume") + fmt_dict['jeans_mass_mass'] = clump.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellMassMsun") + fmt_dict['max_level'] = clump.data["GridLevel"].max() + fmt_dict['min_density'] = clump.data["NumberDensity"].min() + fmt_dict['max_density'] = clump.data["NumberDensity"].max() + f_ptr.write(__clump_info_template % fmt_dict) + +# Recipes for various clump calculations. +recipes = {} + +# Distance from clump center of mass to center of mass of top level object. +def _DistanceToMainClump(master,units='pc'): + masterCOM = master.data.quantities['CenterOfMass']() + pass_command = "self.masterCOM = [%.10f, %.10f, %.10f]" % (masterCOM[0], + masterCOM[1], + masterCOM[2]) + master.pass_down(pass_command) + master.pass_down("self.com = self.data.quantities['CenterOfMass']()") + + quantity = "((self.com[0]-self.masterCOM[0])**2 + (self.com[1]-self.masterCOM[1])**2 + (self.com[2]-self.masterCOM[2])**2)**(0.5)*self.data.pf.units['%s']" % units + format = "%s%s%s" % ("'Distance from center: %.6e ",units,"' % value") + + master.add_info_item(quantity,format) + +recipes['DistanceToMainClump'] = _DistanceToMainClump diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/level_sets/clump_tools.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/level_sets/clump_tools.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,95 @@ +""" +Clump tools for use with the yt Clump object + +Author: David Collins +Affiliation: Center for Astrophysics and Space Sciences, U C San Diego +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2009 David Collins. 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 . +""" + +import numpy as na +nar = na.array + +counter = 0 +def recursive_all_clumps(clump,list,level,parentnumber): + """A recursive function to flatten the hierarchy in *clump*. + Not to be called directly: please call return_all_clumps, below.""" + global counter + counter += 1 + clump.number = counter + clump.parentnumber = parentnumber + counter += 1 + list.append(clump) + clump.level = level + if clump.children != None: + for child in clump.children: + x = recursive_all_clumps(child,list,level+1,clump.number) + return list + +def return_all_clumps(clump): + """Flatten the hierarchy defined by *clump*. + Additionally adds three variables to the clump: + level = depth of hierarchy + number = index of clump in the final array + parentnumber = index of this clumps parent + + """ + global counter + counter = 0 + list = [] + level = 0 + clump.level = level + parentnumber=-1 + recursive_all_clumps(clump,list,level,parentnumber) + return list + +def return_bottom_clumps(clump,dbg=0): + """Recursively return clumps at the bottom of the hierarchy. + This gives a list of clumps similar to what one would get from a CLUMPFIND routine""" + global counter + counter = 0 + list = [] + level = 0 + recursive_bottom_clumps(clump,list,dbg,level) + return list +def recursive_bottom_clumps(clump,clump_list, dbg = 0,level=0): + """Loops over a list of clumps (clumps) and fills clump_list with the bottom most. + Recursive. Prints the level and the number of cores to the screen.""" + + global counter + if dbg > 0: + print tabs(level), "l =",level, "n_core",counter + + if ((clump.children is None) or (len(clump.children) == 0)): + counter += 1 + clump_list.append( clump ) + else: + for child in clump.children: + recursive_bottom_clumps(child,clump_list,dbg=dbg,level=level+1) + +def clump_list_sort(clump_list): + """Returns a copy of clump_list, sorted by ascending minimum density. This + eliminates overlap when passing to + yt.visualization.plot_modification.ClumpContourCallback""" + minDensity = [c['Density'].min() for c in clump_list] + + args = na.argsort(minDensity) + list = nar(clump_list)[args] + reverse = range(list.size-1,-1,-1) + return list[reverse] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/level_sets/contour_finder.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/level_sets/contour_finder.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,328 @@ +""" +This module contains a routine to search for topologically connected sets + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +from itertools import chain +import numpy as na + +from yt.funcs import * +import yt.utilities.data_point_utilities as data_point_utilities +import yt.utilities.amr_utils as amr_utils + +class GridConsiderationQueue: + def __init__(self, white_list, priority_func=None): + """ + This class exists to serve the contour finder. It ensures that + we can create a cascading set of queue dependencies, and if + a grid is touched again ahead of time we can bump it to the top + of the queue again. It like has few uses. + """ + self.to_consider = [] + self.considered = set() + self.n = 0 + self.white_list = set(white_list) + self.priority_func = priority_func + + def add(self, grids, force=False): + if not hasattr(grids,'size'): + grids = ensure_list(grids) + i = self.n + to_check = self.white_list.intersection(grids) + if not force: to_check.difference_update(self.considered) + for g in sorted(to_check, key=self.priority_func): + try: + # We only delete from subsequent checks + del self.to_consider[self.to_consider.index(g, i)] + self.to_consider.insert(i,g) + i += 1 + except ValueError: + self.to_consider.append(g) + + def __iter__(self): + return self + + def next(self): + if self.n >= len(self.to_consider): + raise StopIteration + tr = self.to_consider[self.n] + self.considered.add(tr) + self.n += 1 + return tr + + def progress(self): + return self.n, len(self.to_consider) + +# We want an algorithm that deals with growing a given contour to *all* the +# cells in a grid. + +def old_identify_contours(data_source, field, min_val, max_val, cached_fields=None): + """ + Given a *data_source*, we will search for topologically connected sets + in *field* between *min_val* and *max_val*. + """ + if cached_fields is None: cached_fields = defaultdict(lambda: dict()) + maxn_cells = na.sum([g.ActiveDimensions.prod() for g in data_source._grids]) + contour_ind = na.where( (data_source[field] > min_val) + & (data_source[field] < max_val))[0] + np = contour_ind.size + if np == 0: + return {} + cur_max_id = maxn_cells - np + contour_ids = na.arange(maxn_cells, cur_max_id, -1) + 1 # Minimum of 1 + data_source["tempContours"] = na.ones(data_source[field].shape, dtype='int32')*-1 + mylog.info("Contouring over %s cells with %s candidates", contour_ids[0],np) + data_source["tempContours"][contour_ind] = contour_ids[:] + data_source._flush_data_to_grids("tempContours", -1, dtype='int32') + my_queue = GridConsiderationQueue(white_list = data_source._grids, + priority_func = lambda g: -1*g["tempContours"].max()) + my_queue.add(data_source._grids) + for i,grid in enumerate(my_queue): + mylog.info("Examining %s of %s", *my_queue.progress()) + max_before = grid["tempContours"].max() + to_get = ["tempContours"] + if field in cached_fields[grid.id] and \ + not na.any( (cached_fields[grid.id][field] > min_val) + & (cached_fields[grid.id][field] < max_val)): + continue + for f in [field, "GridIndices"]: + if f not in cached_fields[grid.id]: to_get.append(f) + cg = grid.retrieve_ghost_zones(1,to_get) + for f in [field, "GridIndices"]: + if f in cached_fields[grid.id]: + cg.data[f] = cached_fields[grid.id][f] + else: + cached_fields[grid.id][f] = cg[f] + local_ind = na.where( (cg[field] > min_val) + & (cg[field] < max_val) + & (cg["tempContours"] == -1) ) + if local_ind[0].size > 0: + kk = na.arange(cur_max_id, cur_max_id-local_ind[0].size, -1) + cg["tempContours"][local_ind] = kk[:] + cur_max_id -= local_ind[0].size + fd = cg["tempContours"].astype('int64') + fd_original = fd.copy() + if na.all(fd > -1): + fd[:] = fd.max() + else: + xi_u,yi_u,zi_u = na.where(fd > -1) + cor_order = na.argsort(-1*fd[(xi_u,yi_u,zi_u)]) + xi = xi_u[cor_order] + yi = yi_u[cor_order] + zi = zi_u[cor_order] + while data_point_utilities.FindContours(fd, xi, yi, zi) < 0: pass + cg["tempContours"] = fd.copy().astype('float64') + cg.flush_data("tempContours") + my_queue.add(cg._grids) + force_ind = na.unique(cg["GridIndices"][na.where( + (cg["tempContours"] > fd_original) + & (cg["GridIndices"] != grid.id-grid._id_offset) )]) + if len(force_ind) > 0: + my_queue.add(data_source.hierarchy.grids[force_ind.astype('int32')], force=True) + for ax in 'xyz': + if not iterable(grid['d%s'%ax]): + grid['d%s'%ax] = grid['d%s'%ax]*na.ones(grid.ActiveDimensions) + del data_source.data["tempContours"] # Force a reload from the grids + data_source.get_data("tempContours", in_grids=True) + i = 0 + contour_ind = {} + for contour_id in na.unique(data_source["tempContours"]): + if contour_id == -1: continue + contour_ind[i] = na.where(data_source["tempContours"] == contour_id) + mylog.debug("Contour id %s has %s cells", i, contour_ind[i][0].size) + i += 1 + mylog.info("Identified %s contours between %0.5e and %0.5e", + len(contour_ind.keys()),min_val,max_val) + for grid in chain(data_source._grids, cg._grids): + grid.data.pop("tempContours", None) + del data_source.data["tempContours"] + return contour_ind + +def check_neighbors(data_object, field="Contours"): + """ + This method is a means of error checking in the contour finder. + """ + n_bad = na.zeros(1, dtype='int32') + for cid in na.unique(data_object[field]): + if cid == -1: continue + ids = na.where(data_object[field] == cid) + mx = data_object['x'][ids].copy() + my = data_object['y'][ids].copy() + mz = data_object['z'][ids].copy() + mdx = data_object['dx'][ids].copy() + mdy = data_object['dy'][ids].copy() + mdz = data_object['dz'][ids].copy() + grid_ids_m = data_object['GridIndices'][ids].copy() + grid_levels_m = data_object['GridLevel'][ids].copy() + mp = mx.size + ids = na.where( (data_object[field] != cid) + & (data_object[field] >= 0 )) + nx = data_object['x'][ids].copy() + ny = data_object['y'][ids].copy() + nz = data_object['z'][ids].copy() + ndx = data_object['dx'][ids].copy() + ndy = data_object['dy'][ids].copy() + ndz = data_object['dz'][ids].copy() + grid_ids_n = data_object['GridIndices'][ids].copy() + grid_levels_n = data_object['GridLevel'][ids].copy() + np = nx.size + weave.inline(check_cell_distance, + ['mx','my','mz','mdx','mdy','mdz','mp', + 'nx','ny','nz','ndx','ndy','ndz','np','n_bad', + 'grid_ids_m', 'grid_levels_m', 'grid_ids_n', 'grid_levels_n'], + compiler='gcc', type_converters=converters.blitz, + auto_downcast=0, verbose=2) + return n_bad[0] + +check_cell_distance = \ +r""" +using namespace std; +int i, j, k; +long double cell_dist, rad_m, rad_n; +k=0; +for(i=0;i 1.01 * (rad_n/2.0+rad_m/2.0)) continue; + if(fabsl(mx(i)-nx(j))>(mdx(i)+ndx(j))/2.0) continue; + if(fabsl(my(i)-ny(j))>(mdy(i)+ndy(j))/2.0) continue; + if(fabsl(mz(i)-nz(j))>(mdz(i)+ndz(j))/2.0) continue; + k++; + break; + cout << cell_dist << "\t" << 1.01*(rad_n/2.0+rad_m/2.0) << "\t"; + cout << grid_ids_m(i) << "\t" << grid_ids_n(j) << endl; + } +} +n_bad(0) += k; +""" + +def coalesce_join_tree(jtree1): + joins = defaultdict(set) + nj = jtree1.shape[0] + for i1 in range(nj): + current_new = jtree1[i1, 0] + current_old = jtree1[i1, 1] + for i2 in range(nj): + if jtree1[i2, 1] == current_new: + current_new = max(current_new, jtree1[i2, 0]) + jtree1[i1, 0] = current_new + for i1 in range(nj): + joins[jtree1[i1, 0]].update([jtree1[i1, 1], jtree1[i1, 0]]) + updated = -1 + while updated != 0: + keys = list(reversed(sorted(joins.keys()))) + updated = 0 + for k1 in keys + keys[::-1]: + if k1 not in joins: continue + s1 = joins[k1] + for k2 in keys + keys[::-1]: + if k2 >= k1: continue + if k2 not in joins: continue + s2 = joins[k2] + if k2 in s1: + s1.update(joins.pop(k2)) + updated += 1 + elif not s1.isdisjoint(s2): + s1.update(joins.pop(k2)) + s1.update([k2]) + updated += 1 + return joins + +def identify_contours(data_source, field, min_val, max_val, + cached_fields=None): + cur_max_id = na.sum([g.ActiveDimensions.prod() for g in data_source._grids]) + pbar = get_pbar("First pass", len(data_source._grids)) + grids = sorted(data_source._grids, key=lambda g: -g.Level) + total_contours = 0 + tree = [] + for gi,grid in enumerate(grids): + pbar.update(gi+1) + cm = data_source._get_cut_mask(grid) + if cm is True: cm = na.ones(grid.ActiveDimensions, dtype='bool') + local_ind = na.where( (grid[field] > min_val) + & (grid[field] < max_val) & cm ) + if local_ind[0].size == 0: continue + kk = na.arange(cur_max_id, cur_max_id-local_ind[0].size, -1) + grid["tempContours"] = na.ones(grid.ActiveDimensions, dtype='int64') * -1 + grid["tempContours"][local_ind] = kk[:] + cur_max_id -= local_ind[0].size + xi_u,yi_u,zi_u = na.where(grid["tempContours"] > -1) + cor_order = na.argsort(-1*grid["tempContours"][(xi_u,yi_u,zi_u)]) + fd_orig = grid["tempContours"].copy() + xi = xi_u[cor_order] + yi = yi_u[cor_order] + zi = zi_u[cor_order] + while data_point_utilities.FindContours(grid["tempContours"], xi, yi, zi) < 0: + pass + total_contours += na.unique(grid["tempContours"][grid["tempContours"] > -1]).size + new_contours = na.unique(grid["tempContours"][grid["tempContours"] > -1]).tolist() + tree += zip(new_contours, new_contours) + pbar.finish() + pbar = get_pbar("Calculating joins ", len(data_source._grids)) + grid_set = set() + for gi,grid in enumerate(grids): + pbar.update(gi) + cg = grid.retrieve_ghost_zones(1, "tempContours", smoothed=False) + grid_set.update(set(cg._grids)) + fd = cg["tempContours"].astype('int64') + tree += amr_utils.construct_boundary_relationships(fd) + pbar.finish() + sort_new = na.array(list(set(tree)), dtype='int64') + mylog.info("Coalescing %s joins", sort_new.shape[0]) + joins = coalesce_join_tree(sort_new) + pbar = get_pbar("Joining ", len(joins)) + # This process could and should be done faster + for i, new in enumerate(sorted(joins.keys())): + pbar.update(i) + old_set = joins[new] + for old in old_set: + if old == new: continue + i1 = (data_source["tempContours"] == old) + data_source["tempContours"][i1] = new + pbar.finish() + data_source._flush_data_to_grids("tempContours", -1, dtype='int64') + del data_source.data["tempContours"] # Force a reload from the grids + data_source.get_data("tempContours", in_grids=True) + contour_ind = {} + i = 0 + for contour_id in na.unique(data_source["tempContours"]): + if contour_id == -1: continue + contour_ind[i] = na.where(data_source["tempContours"] == contour_id) + mylog.debug("Contour id %s has %s cells", i, contour_ind[i][0].size) + i += 1 + mylog.info("Identified %s contours between %0.5e and %0.5e", + len(contour_ind.keys()),min_val,max_val) + for grid in chain(grid_set): + grid.data.pop("tempContours", None) + del data_source.data["tempContours"] + return contour_ind diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/level_sets/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/level_sets/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('level_sets',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,25 @@ +""" +Import stuff for light cone generator. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,44 @@ +""" +API for lightcone + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .common_n_volume import \ + commonNVolume, \ + commonSegment + +from .halo_mask import \ + light_cone_halo_mask, \ + light_cone_halo_map + +from .light_cone import \ + LightCone + +from .unique_solution import \ + project_unique_light_cones, \ + find_unique_solutions diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/common_n_volume.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/common_n_volume.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,127 @@ +""" +Function to calculate volume in common between two n-cubes, with optional +periodic boundary conditions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +import numpy as na + +def commonNVolume(nCube1,nCube2,periodic=None): + "Return the n-volume in common between the two n-cubes." + + # Check for proper args. + if ((len(na.shape(nCube1)) != 2) or + (na.shape(nCube1)[1] != 2) or + (na.shape(nCube1) != na.shape(nCube2))): + print "Arguments must be 2 (n,2) numpy array." + return 0 + + if ((periodic is not None) and + (na.shape(nCube1) != na.shape(periodic))): + print "periodic argument must be (n,2) numpy array." + return 0 + + nCommon = 1.0 + for q in range(na.shape(nCube1)[0]): + if (periodic is None): + nCommon *= commonSegment(nCube1[q],nCube2[q]) + else: + nCommon *= commonSegment(nCube1[q],nCube2[q],periodic=periodic[q]) + + return nCommon + +def commonSegment(seg1,seg2,periodic=None): + "Return the length of the common segment." + + # Check for proper args. + if ((len(seg1) != 2) or (len(seg2) != 2)): + print "Arguments must be arrays of size 2." + return 0 + + # If not periodic, then this is very easy. + if periodic is None: + seg1.sort() + len1 = seg1[1] - seg1[0] + seg2.sort() + len2 = seg2[1] - seg2[0] + + common = 0.0 + + add = seg1[1] - seg2[0] + if ((add > 0) and (add <= max(len1,len2))): + common += add + add = seg2[1] - seg1[0] + if ((add > 0) and (add <= max(len1,len2))): + common += add + common = min(common,len1,len2) + return common + + # If periodic, it's a little more complicated. + else: + if len(periodic) != 2: + print "periodic array must be of size 2." + return 0 + + seg1.sort() + flen1 = seg1[1] - seg1[0] + len1 = flen1 - int(flen1) + seg2.sort() + flen2 = seg2[1] - seg2[0] + len2 = flen2 - int(flen2) + + periodic.sort() + scale = periodic[1] - periodic[0] + + if (abs(int(flen1)-int(flen2)) >= scale): + return min(flen1,flen2) + + # Adjust for periodicity + seg1[0] = na.mod(seg1[0],scale) + periodic[0] + seg1[1] = seg1[0] + len1 + if (seg1[1] > periodic[1]): seg1[1] -= scale + seg2[0] = na.mod(seg2[0],scale) + periodic[0] + seg2[1] = seg2[0] + len2 + if (seg2[1] > periodic[1]): seg2[1] -= scale + + # create list of non-periodic segments + pseg1 = [] + if (seg1[0] >= seg1[1]): + pseg1.append([seg1[0],periodic[1]]) + pseg1.append([periodic[0],seg1[1]]) + else: + pseg1.append(seg1) + pseg2 = [] + if (seg2[0] >= seg2[1]): + pseg2.append([seg2[0],periodic[1]]) + pseg2.append([periodic[0],seg2[1]]) + else: + pseg2.append(seg2) + + # Add up common segments. + common = min(int(flen1),int(flen2)) + + for subseg1 in pseg1: + for subseg2 in pseg2: + common += commonSegment(subseg1,subseg2) + + return common diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/halo_mask.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/halo_mask.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,319 @@ +""" +Light cone halo mask functions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +from yt.analysis_modules.halo_profiler.api import HaloProfiler +from yt.convenience import load +from yt.utilities.logger import ytLogger as mylog +from yt.config import ytcfg +import copy +import numpy as na +import h5py + +def light_cone_halo_mask(lightCone, cube_file=None, mask_file=None, **kwargs): + "Make a boolean mask to cut clusters out of light cone projections." + + pixels = int(lightCone.field_of_view_in_arcminutes * 60.0 / + lightCone.image_resolution_in_arcseconds) + + light_cone_mask = [] + + # Loop through files in light cone solution and get virial quantities. + for slice in lightCone.light_cone_solution: + halo_list = _get_halo_list(slice['filename'], **kwargs) + light_cone_mask.append(_make_slice_mask(slice, halo_list, pixels)) + + # Write out cube of masks from each slice. + if cube_file is not None and ytcfg.getint("yt", "__parallel_rank") == 0: + mylog.info("Saving halo mask cube to %s." % cube_file) + output = h5py.File(cube_file, 'a') + output.create_dataset('haloMaskCube', data=na.array(light_cone_mask)) + output.close() + + # Write out final mask. + if mask_file is not None and ytcfg.getint("yt", "__parallel_rank") == 0: + # Final mask is simply the product of the mask from each slice. + mylog.info("Saving halo mask to %s." % mask_file) + finalMask = na.ones(shape=(pixels, pixels)) + for mask in light_cone_mask: + finalMask *= mask + + output = h5py.File(mask_file, 'a') + output.create_dataset('HaloMask', data=na.array(finalMask)) + output.close() + + return light_cone_mask + +def light_cone_halo_map(lightCone, map_file='halo_map.out', **kwargs): + "Make a text list of location of halos in a light cone image with virial quantities." + + haloMap = [] + + # Loop through files in light cone solution and get virial quantities. + for slice in lightCone.light_cone_solution: + halo_list = _get_halo_list(slice['filename'], **kwargs) + haloMap.extend(_make_slice_halo_map(slice, halo_list)) + + # Write out file. + if ytcfg.getint("yt", "__parallel_rank") == 0: + mylog.info("Saving halo map to %s." % map_file) + f = open(map_file, 'w') + f.write("#z x y M [Msun] R [Mpc] R [image]\n") + for halo in haloMap: + f.write("%7.4f %9.6f %9.6f %9.3e %9.3e %9.3e\n" % \ + (halo['redshift'], halo['x'], halo['y'], + halo['mass'], halo['radiusMpc'], halo['radiusImage'])) + f.close() + +def _get_halo_list(dataset, halo_profiler_kwargs=None, halo_profiler_actions=None, halo_list='all'): + "Load a list of halos for the dataset." + + if halo_profiler_kwargs is None: halo_profiler_kwargs = {} + if halo_profiler_actions is None: halo_profiler_actions = [] + + hp = HaloProfiler(dataset, **halo_profiler_kwargs) + for action in halo_profiler_actions: + if not action.has_key('args'): action['args'] = () + if not action.has_key('kwargs'): action['kwargs'] = {} + action['function'](hp, *action['args'], **action['kwargs']) + + if halo_list == 'all': + return_list = copy.deepcopy(hp.all_halos) + elif halo_list == 'filtered': + return_list = copy.deepcopy(hp.filtered_halos) + else: + mylog.error("Keyword, halo_list, must be either 'all' or 'filtered'.") + return_list = None + + del hp + return return_list + +def _make_slice_mask(slice, halo_list, pixels): + "Make halo mask for one slice in light cone solution." + + # Get shifted, tiled halo list. + all_halo_x, all_halo_y, all_halo_radius, all_halo_mass = _make_slice_halo_list(slice, halo_list) + + # Make boolean mask and cut out halos. + dx = slice['WidthBoxFraction'] / pixels + x = [(q + 0.5) * dx for q in range(pixels)] + haloMask = na.ones(shape=(pixels, pixels), dtype=bool) + + # Cut out any pixel that has any part at all in the circle. + for q in range(len(all_halo_radius)): + dif_xIndex = na.array(int(all_halo_x[q]/dx) - na.array(range(pixels))) != 0 + dif_yIndex = na.array(int(all_halo_y[q]/dx) - na.array(range(pixels))) != 0 + + xDistance = (na.abs(x - all_halo_x[q]) - (0.5 * dx)) * dif_xIndex + yDistance = (na.abs(x - all_halo_y[q]) - (0.5 * dx)) * dif_yIndex + + distance = na.array([na.sqrt(w**2 + xDistance**2) for w in yDistance]) + haloMask *= (distance >= all_halo_radius[q]) + + return haloMask + +def _make_slice_halo_map(slice, halo_list): + "Make list of halos for one slice in light cone solution." + + # Get units to convert virial radii back to physical units. + dataset_object = load(slice['filename']) + Mpc_units = dataset_object.units['mpc'] + del dataset_object + + # Get shifted, tiled halo list. + all_halo_x, all_halo_y, all_halo_radius, all_halo_mass = _make_slice_halo_list(slice, halo_list) + + # Construct list of halos + haloMap = [] + + for q in range(len(all_halo_x)): + # Give radius in both physics units and units of the image (0 to 1). + radiusMpc = all_halo_radius[q] * Mpc_units + radiusImage = all_halo_radius[q] / slice['WidthBoxFraction'] + + haloMap.append({'x':all_halo_x[q]/slice['WidthBoxFraction'], + 'y':all_halo_y[q]/slice['WidthBoxFraction'], + 'redshift':slice['redshift'], + 'radiusMpc':radiusMpc, + 'radiusImage':radiusImage, + 'mass':all_halo_mass[q]}) + + return haloMap + +def _make_slice_halo_list(slice, halo_list): + "Make shifted, tiled list of halos for halo mask and halo map." + + # Make numpy arrays for halo centers and virial radii. + halo_x = [] + halo_y = [] + halo_depth = [] + halo_radius = [] + halo_mass = [] + + # Get units to convert virial radii to code units. + dataset_object = load(slice['filename']) + Mpc_units = dataset_object.units['mpc'] + del dataset_object + + for halo in halo_list: + if halo is not None: + center = copy.deepcopy(halo['center']) + halo_depth.append(center.pop(slice['ProjectionAxis'])) + halo_x.append(center[0]) + halo_y.append(center[1]) + halo_radius.append(halo['RadiusMpc']/Mpc_units) + halo_mass.append(halo['TotalMassMsun']) + + halo_x = na.array(halo_x) + halo_y = na.array(halo_y) + halo_depth = na.array(halo_depth) + halo_radius = na.array(halo_radius) + halo_mass = na.array(halo_mass) + + # Adjust halo centers along line of sight. + depthCenter = slice['ProjectionCenter'][slice['ProjectionAxis']] + depthLeft = depthCenter - 0.5 * slice['DepthBoxFraction'] + depthRight = depthCenter + 0.5 * slice['DepthBoxFraction'] + + # Make boolean mask to pick out centers in region along line of sight. + # Halos near edges may wrap around to other side. + add_left = (halo_depth + halo_radius) > 1 # should be box width + add_right = (halo_depth - halo_radius) < 0 + + halo_depth = na.concatenate([halo_depth, (halo_depth[add_left]-1), (halo_depth[add_right]+1)]) + halo_x = na.concatenate([halo_x, halo_x[add_left], halo_x[add_right]]) + halo_y = na.concatenate([halo_y, halo_y[add_left], halo_y[add_right]]) + halo_radius = na.concatenate([halo_radius, halo_radius[add_left], halo_radius[add_right]]) + halo_mass = na.concatenate([halo_mass, halo_mass[add_left], halo_mass[add_right]]) + + del add_left, add_right + + # Cut out the halos outside the region of interest. + if (slice['DepthBoxFraction'] < 1): + if (depthLeft < 0): + mask = ((halo_depth + halo_radius >= 0) & (halo_depth - halo_radius <= depthRight)) | \ + ((halo_depth + halo_radius >= depthLeft + 1) & (halo_depth - halo_radius <= 1)) + elif (depthRight > 1): + mask = ((halo_depth + halo_radius >= 0) & (halo_depth - halo_radius <= depthRight - 1)) | \ + ((halo_depth + halo_radius >= depthLeft) & (halo_depth - halo_radius <= 1)) + else: + mask = (halo_depth + halo_radius >= depthLeft) & (halo_depth - halo_radius <= depthRight) + + halo_x = halo_x[mask] + halo_y = halo_y[mask] + halo_radius = halo_radius[mask] + halo_mass = halo_mass[mask] + del mask + del halo_depth + + all_halo_x = na.array([]) + all_halo_y = na.array([]) + all_halo_radius = na.array([]) + all_halo_mass = na.array([]) + + # Tile halos of width box fraction is greater than one. + # Copy original into offset positions to make tiles. + for x in range(int(na.ceil(slice['WidthBoxFraction']))): + for y in range(int(na.ceil(slice['WidthBoxFraction']))): + all_halo_x = na.concatenate([all_halo_x, halo_x+x]) + all_halo_y = na.concatenate([all_halo_y, halo_y+y]) + all_halo_radius = na.concatenate([all_halo_radius, halo_radius]) + all_halo_mass = na.concatenate([all_halo_mass, halo_mass]) + + del halo_x, halo_y, halo_radius, halo_mass + + # Shift centers laterally. + offset = copy.deepcopy(slice['ProjectionCenter']) + del offset[slice['ProjectionAxis']] + + # Shift x and y positions. + all_halo_x -= offset[0] + all_halo_y -= offset[1] + + # Wrap off-edge centers back around to other side (periodic boundary conditions). + all_halo_x[all_halo_x < 0] += na.ceil(slice['WidthBoxFraction']) + all_halo_y[all_halo_y < 0] += na.ceil(slice['WidthBoxFraction']) + + # After shifting, some centers have fractional coverage on both sides of the box. + # Find those centers and make copies to be placed on the other side. + + # Centers hanging off the right edge. + add_x_right = all_halo_x + all_halo_radius > na.ceil(slice['WidthBoxFraction']) + add_x_halo_x = all_halo_x[add_x_right] + add_x_halo_x -= na.ceil(slice['WidthBoxFraction']) + add_x_halo_y = all_halo_y[add_x_right] + add_x_halo_radius = all_halo_radius[add_x_right] + add_x_halo_mass = all_halo_mass[add_x_right] + del add_x_right + + # Centers hanging off the left edge. + add_x_left = all_halo_x - all_halo_radius < 0 + add2_x_halo_x = all_halo_x[add_x_left] + add2_x_halo_x += na.ceil(slice['WidthBoxFraction']) + add2_x_halo_y = all_halo_y[add_x_left] + add2_x_halo_radius = all_halo_radius[add_x_left] + add2_x_halo_mass = all_halo_mass[add_x_left] + del add_x_left + + # Centers hanging off the top edge. + add_y_right = all_halo_y + all_halo_radius > na.ceil(slice['WidthBoxFraction']) + add_y_halo_x = all_halo_x[add_y_right] + add_y_halo_y = all_halo_y[add_y_right] + add_y_halo_y -= na.ceil(slice['WidthBoxFraction']) + add_y_halo_radius = all_halo_radius[add_y_right] + add_y_halo_mass = all_halo_mass[add_y_right] + del add_y_right + + # Centers hanging off the bottom edge. + add_y_left = all_halo_y - all_halo_radius < 0 + add2_y_halo_x = all_halo_x[add_y_left] + add2_y_halo_y = all_halo_y[add_y_left] + add2_y_halo_y += na.ceil(slice['WidthBoxFraction']) + add2_y_halo_radius = all_halo_radius[add_y_left] + add2_y_halo_mass = all_halo_mass[add_y_left] + del add_y_left + + # Add the hanging centers back to the projection data. + all_halo_x = na.concatenate([all_halo_x, add_x_halo_x, add2_x_halo_x, add_y_halo_x, add2_y_halo_x]) + all_halo_y = na.concatenate([all_halo_y, add_x_halo_y, add2_x_halo_y, add_y_halo_y, add2_y_halo_y]) + all_halo_radius = na.concatenate([all_halo_radius, add_x_halo_radius, add2_x_halo_radius, + add_y_halo_radius, add2_y_halo_radius]) + all_halo_mass = na.concatenate([all_halo_mass, add_x_halo_mass, add2_x_halo_mass, + add_y_halo_mass, add2_y_halo_mass]) + + del add_x_halo_x, add_x_halo_y, add_x_halo_radius + del add2_x_halo_x, add2_x_halo_y, add2_x_halo_radius + del add_y_halo_x, add_y_halo_y, add_y_halo_radius + del add2_y_halo_x, add2_y_halo_y, add2_y_halo_radius + + # Cut edges to proper width. + cut_mask = (all_halo_x - all_halo_radius < slice['WidthBoxFraction']) & \ + (all_halo_y - all_halo_radius < slice['WidthBoxFraction']) + all_halo_x = all_halo_x[cut_mask] + all_halo_y = all_halo_y[cut_mask] + all_halo_radius = all_halo_radius[cut_mask] + all_halo_mass = all_halo_mass[cut_mask] + del cut_mask + + return (all_halo_x, all_halo_y, all_halo_radius, all_halo_mass) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/light_cone.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/light_cone.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,567 @@ +""" +LightCone class and member functions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +import copy +import os +import numpy as na + +from yt.funcs import * + +from yt.analysis_modules.simulation_handler.enzo_simulation \ + import EnzoSimulation +from yt.config import ytcfg +from yt.convenience import load +from yt.utilities.cosmology import Cosmology +from yt.visualization.plot_collection import \ + PlotCollection + +from .common_n_volume import commonNVolume +from .halo_mask import light_cone_halo_map, \ + light_cone_halo_mask +from .light_cone_projection import LightConeProjection + +class LightCone(EnzoSimulation): + def __init__(self, EnzoParameterFile, initial_redshift=1.0, + final_redshift=0.0, observer_redshift=0.0, + field_of_view_in_arcminutes=600.0, image_resolution_in_arcseconds=60.0, + use_minimum_datasets=True, deltaz_min=0.0, minimum_coherent_box_fraction=0.0, + output_dir='LC', output_prefix='LightCone', **kwargs): + """ + Initialize a LightCone object. + :param initial_redshift (float): the initial (highest) redshift for the light cone. Default: 1.0. + :param final_redshift (float): the final (lowest) redshift for the light cone. Default: 0.0. + :param observer_redshift (float): the redshift of the observer. Default: 0.0. + :param field_of_view_in_arcminutes (float): the field of view of the image in units of arcminutes. + Default: 600.0. + :param image_resolution_in_arcseconds (float): the size of each image pixel in units of arcseconds. + Default: 60.0. + :param use_minimum_datasets (bool): if True, the minimum number of datasets is used to connect the + initial and final redshift. If false, the light cone solution will contain as many entries + as possible within the redshift interval. Default: True. + :param deltaz_min (float): specifies the minimum :math:`\Delta z` between consecutive datasets in + the returned list. Default: 0.0. + :param minimum_coherent_box_fraction (float): used with use_minimum_datasets set to False, this + parameter specifies the fraction of the total box size to be traversed before rerandomizing + the projection axis and center. This was invented to allow light cones with thin slices to + sample coherent large scale structure, but in practice does not work so well. Try setting + this parameter to 1 and see what happens. Default: 0.0. + :param output_dir (str): the directory in which images and data files will be written. Default: 'LC'. + :param output_prefix (str): the prefix of all images and data files. Default: 'LightCone'. + """ + + self.initial_redshift = initial_redshift + self.final_redshift = final_redshift + self.observer_redshift = observer_redshift + self.field_of_view_in_arcminutes = field_of_view_in_arcminutes + self.image_resolution_in_arcseconds = image_resolution_in_arcseconds + self.use_minimum_datasets = use_minimum_datasets + self.deltaz_min = deltaz_min + self.minimum_coherent_box_fraction = minimum_coherent_box_fraction + self.output_dir = output_dir + self.output_prefix = output_prefix + + self.master_solution = [] # kept to compare with recycled solutions + self.projection_stack = [] + self.projection_weight_field_stack = [] + self.halo_mask = [] + + # Original random seed of the first solution. + self.originalRandomSeed = 0 + + # Parameters for recycling light cone solutions. + self.recycleSolution = False + self.recycleRandomSeed = 0 + + # Initialize EnzoSimulation machinery for getting dataset list. + EnzoSimulation.__init__(self, EnzoParameterFile, initial_redshift=self.initial_redshift, + final_redshift=self.final_redshift, links=True, + enzo_parameters={'CosmologyComovingBoxSize':float}, **kwargs) + + # Calculate number of pixels. + self.pixels = int(self.field_of_view_in_arcminutes * 60.0 / \ + self.image_resolution_in_arcseconds) + + if ytcfg.getint("yt", "__parallel_rank") == 0: + # Create output directory. + if (os.path.exists(self.output_dir)): + if not(os.path.isdir(self.output_dir)): + mylog.error("Output directory exists, but is not a directory: %s." % self.output_dir) + self.output_dir = './' + else: + os.mkdir(self.output_dir) + + # Get list of datasets for light cone solution. + self.light_cone_solution = self.create_cosmology_splice(minimal=self.use_minimum_datasets, + deltaz_min=self.deltaz_min) + + def calculate_light_cone_solution(self, seed=None, filename=None): + """ + Create list of projections to be added together to make the light cone. + :param seed (int): the seed for the random number generator. Any light cone solution + can be reproduced by giving the same random seed. Default: None (each solution + will be distinct). + :param filename (str): if given, a text file detailing the solution will be written out. Default: None. + """ + + # Don't use box coherence with maximum projection depths. + if self.use_minimum_datasets and \ + self.minimum_coherent_box_fraction > 0: + mylog.info("Setting minimum_coherent_box_fraction to 0 with minimal light cone.") + self.minimum_coherent_box_fraction = 0 + + # Make sure recycling flag is off. + self.recycleSolution = False + + # Get rid of old halo mask, if one was there. + self.halo_mask = [] + + if seed is not None: + self.originalRandomSeed = int(seed) + + # Calculate projection sizes, and get random projection axes and centers. + na.random.seed(self.originalRandomSeed) + + # For box coherence, keep track of effective depth travelled. + boxFractionUsed = 0.0 + + for q in range(len(self.light_cone_solution)): + if self.light_cone_solution[q].has_key('previous'): del self.light_cone_solution[q]['previous'] + if self.light_cone_solution[q].has_key('next'): del self.light_cone_solution[q]['next'] + if (q == len(self.light_cone_solution) - 1): + z_next = self.final_redshift + else: + z_next = self.light_cone_solution[q+1]['redshift'] + + # Calculate fraction of box required for a depth of delta z + self.light_cone_solution[q]['DepthBoxFraction'] = \ + self.cosmology.ComovingRadialDistance(z_next, self.light_cone_solution[q]['redshift']) * \ + self.enzoParameters['CosmologyHubbleConstantNow'] / self.enzoParameters['CosmologyComovingBoxSize'] + + # Simple error check to make sure more than 100% of box depth is never required. + if (self.light_cone_solution[q]['DepthBoxFraction'] > 1.0): + mylog.debug("Warning: box fraction required to go from z = %f to %f is %f" % + (self.light_cone_solution[q]['redshift'], z_next, + self.light_cone_solution[q]['DepthBoxFraction'])) + mylog.debug("Full box delta z is %f, but it is %f to the next data dump." % + (self.light_cone_solution[q]['deltazMax'], + self.light_cone_solution[q]['redshift']-z_next)) + + # Calculate fraction of box required for width corresponding to requested image size. + scale = self.cosmology.AngularScale_1arcsec_kpc(self.observer_redshift, self.light_cone_solution[q]['redshift']) + size = self.field_of_view_in_arcminutes * 60.0 * scale / 1000.0 + boxSizeProper = self.enzoParameters['CosmologyComovingBoxSize'] / (self.enzoParameters['CosmologyHubbleConstantNow'] * + (1.0 + self.light_cone_solution[q]['redshift'])) + self.light_cone_solution[q]['WidthBoxFraction'] = size / boxSizeProper + + # Get projection axis and center. + # If using box coherence, only get random axis and center if enough of the box has been used, + # or if boxFractionUsed will be greater than 1 after this slice. + if (q == 0) or (self.minimum_coherent_box_fraction == 0) or \ + (boxFractionUsed > self.minimum_coherent_box_fraction) or \ + (boxFractionUsed + self.light_cone_solution[q]['DepthBoxFraction'] > 1.0): + # Random axis and center. + self.light_cone_solution[q]['ProjectionAxis'] = na.random.randint(0, 3) + self.light_cone_solution[q]['ProjectionCenter'] = [na.random.random(), na.random.random(), na.random.random()] + boxFractionUsed = 0.0 + else: + # Same axis and center as previous slice, but with depth center shifted. + self.light_cone_solution[q]['ProjectionAxis'] = self.light_cone_solution[q-1]['ProjectionAxis'] + self.light_cone_solution[q]['ProjectionCenter'] = copy.deepcopy(self.light_cone_solution[q-1]['ProjectionCenter']) + self.light_cone_solution[q]['ProjectionCenter'][self.light_cone_solution[q]['ProjectionAxis']] += \ + 0.5 * (self.light_cone_solution[q]['DepthBoxFraction'] + self.light_cone_solution[q-1]['DepthBoxFraction']) + if self.light_cone_solution[q]['ProjectionCenter'][self.light_cone_solution[q]['ProjectionAxis']] >= 1.0: + self.light_cone_solution[q]['ProjectionCenter'][self.light_cone_solution[q]['ProjectionAxis']] -= 1.0 + + boxFractionUsed += self.light_cone_solution[q]['DepthBoxFraction'] + + # Store this as the master solution. + self.master_solution = [copy.deepcopy(q) for q in self.light_cone_solution] + + # Write solution to a file. + if filename is not None: + self._save_light_cone_solution(filename=filename) + + def get_halo_mask(self, mask_file=None, map_file=None, **kwargs): + """ + Gets a halo mask from a file or makes a new one. + :param mask_file (str): specify an hdf5 file to output the halo mask. + :param map_file (str): specify a text file to output the halo map + (locations in image of halos). + """ + + # Get halo map if map_file given. + if map_file is not None and not os.path.exists(map_file): + light_cone_halo_map(self, map_file=map_file, **kwargs) + + # Check if file already exists. + if mask_file is not None and os.path.exists(mask_file): + mylog.info('Reading halo mask from %s.' % mask_file) + input = h5py.File(mask_file, 'r') + self.halo_mask = input['HaloMask'].value + input.close() + + # Otherwise, make a halo mask. + else: + halo_mask_cube = light_cone_halo_mask(self, mask_file=mask_file, **kwargs) + # Collapse cube into final mask. + if ytcfg.getint("yt", "__parallel_rank") == 0: + self.halo_mask = na.ones(shape=(self.pixels, self.pixels), dtype=bool) + for mask in halo_mask_cube: + self.halo_mask *= mask + del halo_mask_cube + + def project_light_cone(self, field, weight_field=None, apply_halo_mask=False, node=None, + save_stack=True, save_slice_images=False, flatten_stack=False, photon_field=False, + add_redshift_label=False, **kwargs): + """ + Create projections for light cone, then add them together. + :param weight_field (str): the weight field of the projection. This has the same meaning as in standard + projections. Default: None. + :param apply_halo_mask (bool): if True, a boolean mask is apply to the light cone projection. See below for a + description of halo masks. Default: False. + :param node (str): a prefix to be prepended to the node name under which the projection data is serialized. + Default: None. + :param save_stack (bool): if True, the unflatted light cone data including each individual slice is written to + an hdf5 file. Default: True. + :param save_slice_images (bool): save images for each individual projection slice. Default: False. + :param flatten_stack (bool): if True, the light cone stack is continually flattened each time a slice is added + in order to save memory. This is generally not necessary. Default: False. + :param photon_field (bool): if True, the projection data for each slice is decremented by 4 Pi R^2`, where R + is the luminosity distance between the observer and the slice redshift. Default: False. + """ + + # Clear projection stack. + self.projection_stack = [] + self.projection_weight_field_stack = [] + if (self.light_cone_solution[-1].has_key('object')): + del self.light_cone_solution[-1]['object'] + + if not(self.output_dir.endswith("/")): + self.output_dir += "/" + + for q, output in enumerate(self.light_cone_solution): + if node is None: + name = "%s%s_%04d_%04d" % (self.output_dir, self.output_prefix, + q, len(self.light_cone_solution)) + else: + name = "%s%s_%s_%04d_%04d" % (self.output_dir, self.output_prefix, + node, q, len(self.light_cone_solution)) + output['object'] = load(output['filename']) + frb = LightConeProjection(output, field, self.pixels, weight_field=weight_field, + save_image=save_slice_images, + name=name, node=node, **kwargs) + if ytcfg.getint("yt", "__parallel_rank") == 0: + if photon_field: + # Decrement the flux by the luminosity distance. Assume field in frb is in erg/s/cm^2/Hz + co = lagos.Cosmology(HubbleConstantNow = (100.0 * self.enzoParameters['CosmologyHubbleConstantNow']), + OmegaMatterNow = self.enzoParameters['CosmologyOmegaMatterNow'], + OmegaLambdaNow = self.enzoParameters['CosmologyOmegaLambdaNow']) + dL = self.cosmology.LuminosityDistance(self.observer_redshift, output['redshift']) #in Mpc + boxSizeProper = self.enzoParameters['CosmologyComovingBoxSize'] / (self.enzoParameters['CosmologyHubbleConstantNow'] * + (1.0 + output['redshift'])) + pixelarea = (boxSizeProper/self.pixels)**2 #in proper cm^2 + factor = pixelarea/(4.0*na.pi*dL**2) + mylog.info("Distance to slice = %e" % dL) + frb[field] *= factor #in erg/s/cm^2/Hz on observer's image plane. + + if ytcfg.getint("yt", "__parallel_rank") == 0: + if weight_field is not None: + # Data come back normalized by the weight field. + # Undo that so it can be added up for the light cone. + self.projection_stack.append(frb[field]*frb['weight_field']) + self.projection_weight_field_stack.append(frb['weight_field']) + else: + self.projection_stack.append(frb[field]) + + # Delete the frb. This saves a decent amount of ram. + if (q < len(self.light_cone_solution) - 1): + del frb + + # Flatten stack to save memory. + if flatten_stack and (len(self.projection_stack) > 1): + self.projection_stack = [sum(self.projection_stack)] + if weight_field is not None: + self.projection_weight_field_stack = [sum(self.projection_weight_field_stack)] + + # Delete the plot collection now that the frb is deleted. + del output['pc'] + + # Unless this is the last slice, delete the dataset object. + # The last one will be saved to make the plot collection. + if (q < len(self.light_cone_solution) - 1): + del output['object'] + + if ytcfg.getint("yt", "__parallel_rank") == 0: + # Add up slices to make light cone projection. + if (weight_field is None): + lightConeProjection = sum(self.projection_stack) + else: + lightConeProjection = sum(self.projection_stack) / sum(self.projection_weight_field_stack) + + if node is None: + filename = "%s%s" % (self.output_dir, self.output_prefix) + else: + filename = "%s%s_%s" % (self.output_dir, self.output_prefix, node) + + # Save the last fixed resolution buffer for the plot collection, + # but replace the data with the full light cone projection data. + frb.data[field] = lightConeProjection + + # Write stack to hdf5 file. + if save_stack: + self._save_light_cone_stack(field=field, weight_field=weight_field, filename=filename) + + # Apply halo mask. + if apply_halo_mask: + if len(self.halo_mask) > 0: + mylog.info("Applying halo mask.") + frb.data[field] *= self.halo_mask + else: + mylog.error("No halo mask loaded, call get_halo_mask.") + + # Make a plot collection for the light cone projection. + center = [0.5 * (self.light_cone_solution[-1]['object'].parameters['DomainLeftEdge'][w] + + self.light_cone_solution[-1]['object'].parameters['DomainRightEdge'][w]) + for w in range(self.light_cone_solution[-1]['object'].parameters['TopGridRank'])] + pc = PlotCollection(self.light_cone_solution[-1]['object'], center=center) + pc.add_fixed_resolution_plot(frb, field, **kwargs) + pc.save(filename) + + # Return the plot collection so the user can remake the plot if they want. + return pc + + def rerandomize_light_cone_solution(self, newSeed, recycle=True, filename=None): + """ + When making a projection for a light cone, only randomizations along the line of sight make any + given projection unique, since the lateral shifting and tiling is done after the projection is made. + Therefore, multiple light cones can be made from a single set of projections by introducing different + lateral random shifts and keeping all the original shifts along the line of sight. + This routine will take in a new random seed and rerandomize the parts of the light cone that do not contribute + to creating a unique projection object. Additionally, this routine is built such that if the same random + seed is given for the rerandomizing, the solution will be identical to the original. + + This routine has now been updated to be a general solution rescrambler. If the keyword recycle is set to + True, then it will recycle. Otherwise, it will create a completely new solution. + + :param recycle (bool): if True, the new solution will have the same shift in the line of sight as the original + solution. Since the projections of each slice are serialized and stored for the entire width of the + box (even if the width used is left than the total box), the projection data can be deserialized + instead of being remade from scratch. This can greatly speed up the creation of a large number of light + cone projections. Default: True. + :param filename (str): if given, a text file detailing the solution will be written out. Default: None. + """ + + # Get rid of old halo mask, if one was there. + self.halo_mask = [] + + # Clean pf objects out of light cone solution. + for slice in self.light_cone_solution: + if slice.has_key('object'): + del slice['object'] + + if recycle: + mylog.debug("Recycling solution made with %s with new seed %s." % + (self.originalRandomSeed, newSeed)) + self.recycleRandomSeed = int(newSeed) + else: + mylog.debug("Creating new solution with random seed %s." % newSeed) + self.originalRandomSeed = int(newSeed) + self.recycleRandomSeed = 0 + + self.recycleSolution = recycle + + # Keep track of fraction of volume in common between the original and recycled solution. + commonVolume = 0.0 + totalVolume = 0.0 + + # For box coherence, keep track of effective depth travelled. + boxFractionUsed = 0.0 + + # Seed random number generator with new seed. + na.random.seed(int(newSeed)) + + for q, output in enumerate(self.light_cone_solution): + # It is necessary to make the same number of calls to the random number generator + # so the original solution willbe produced if the same seed is given. + + # Get projection axis and center. + # If using box coherence, only get random axis and center if enough of the box has been used, + # or if boxFractionUsed will be greater than 1 after this slice. + if (q == 0) or (self.minimum_coherent_box_fraction == 0) or \ + (boxFractionUsed > self.minimum_coherent_box_fraction) or \ + (boxFractionUsed + self.light_cone_solution[q]['DepthBoxFraction'] > 1.0): + # Get random projection axis and center. + # If recycling, axis will get thrown away since it is used in creating a unique projection object. + newAxis = na.random.randint(0, 3) + + newCenter = [na.random.random(), na.random.random(), na.random.random()] + boxFractionUsed = 0.0 + else: + # Same axis and center as previous slice, but with depth center shifted. + newAxis = self.light_cone_solution[q-1]['ProjectionAxis'] + newCenter = copy.deepcopy(self.light_cone_solution[q-1]['ProjectionCenter']) + newCenter[newAxis] += \ + 0.5 * (self.light_cone_solution[q]['DepthBoxFraction'] + self.light_cone_solution[q-1]['DepthBoxFraction']) + if newCenter[newAxis] >= 1.0: + newCenter[newAxis] -= 1.0 + + if recycle: + output['ProjectionAxis'] = self.master_solution[q]['ProjectionAxis'] + else: + output['ProjectionAxis'] = newAxis + + boxFractionUsed += self.light_cone_solution[q]['DepthBoxFraction'] + + # Make list of rectangle corners to calculate common volume. + newCube = na.zeros(shape=(len(newCenter), 2)) + oldCube = na.zeros(shape=(len(newCenter), 2)) + for w in range(len(newCenter)): + if (w == self.master_solution[q]['ProjectionAxis']): + oldCube[w] = [self.master_solution[q]['ProjectionCenter'][w] - 0.5 * self.master_solution[q]['DepthBoxFraction'], + self.master_solution[q]['ProjectionCenter'][w] + 0.5 * self.master_solution[q]['DepthBoxFraction']] + else: + oldCube[w] = [self.master_solution[q]['ProjectionCenter'][w] - 0.5 * self.master_solution[q]['WidthBoxFraction'], + self.master_solution[q]['ProjectionCenter'][w] + 0.5 * self.master_solution[q]['WidthBoxFraction']] + + if (w == output['ProjectionAxis']): + if recycle: + newCube[w] = oldCube[w] + else: + newCube[w] = [newCenter[w] - 0.5 * self.master_solution[q]['DepthBoxFraction'], + newCenter[w] + 0.5 * self.master_solution[q]['DepthBoxFraction']] + else: + newCube[w] = [newCenter[w] - 0.5 * self.master_solution[q]['WidthBoxFraction'], + newCenter[w] + 0.5 * self.master_solution[q]['WidthBoxFraction']] + + commonVolume += commonNVolume(oldCube, newCube, periodic=na.array([[0, 1], [0, 1], [0, 1]])) + totalVolume += output['DepthBoxFraction'] * output['WidthBoxFraction']**2 + + # Replace centers for every axis except the line of sight axis. + for w in range(len(newCenter)): + if not(recycle and (w == self.light_cone_solution[q]['ProjectionAxis'])): + self.light_cone_solution[q]['ProjectionCenter'][w] = newCenter[w] + + if recycle: + mylog.debug("Fractional common volume between master and recycled solution is %.2e" % (commonVolume/totalVolume)) + else: + mylog.debug("Fraction of total volume in common with old solution is %.2e." % (commonVolume/totalVolume)) + self.master_solution = [copy.deepcopy(q) for q in self.light_cone_solution] + + # Write solution to a file. + if filename is not None: + self._save_light_cone_solution(filename=filename) + + def restore_master_solution(self): + "Reset the active light cone solution to the master solution." + self.light_cone_solution = [copy.deepcopy(q) for q in self.master_solution] + + @rootonly + def _save_light_cone_solution(self, filename="light_cone.dat"): + "Write out a text file with information on light cone solution." + + mylog.info("Saving light cone solution to %s." % filename) + + f = open(filename, 'w') + if self.recycleSolution: + f.write("Recycled Solution\n") + f.write("OriginalRandomSeed = %s\n" % self.originalRandomSeed) + f.write("RecycleRandomSeed = %s\n" % self.recycleRandomSeed) + else: + f.write("Original Solution\n") + f.write("OriginalRandomSeed = %s\n" % self.originalRandomSeed) + f.write("EnzoParameterFile = %s\n" % self.EnzoParameterFile) + f.write("\n") + for q, output in enumerate(self.light_cone_solution): + f.write("Proj %04d, %s, z = %f, depth/box = %f, width/box = %f, axis = %d, center = %f, %f, %f\n" % + (q, output['filename'], output['redshift'], output['DepthBoxFraction'], output['WidthBoxFraction'], + output['ProjectionAxis'], output['ProjectionCenter'][0], output['ProjectionCenter'][1], output['ProjectionCenter'][2])) + f.close() + + def _save_light_cone_stack(self, field=None, weight_field=None, filename=None, over_write=True): + "Save the light cone projection stack as a 3d array in and hdf5 file." + + # Make list of redshifts to include as a dataset attribute. + redshiftList = na.array([slice['redshift'] for slice in self.light_cone_solution]) + + field_node = "%s_%s" % (field, weight_field) + weight_field_node = "weight_field_%s" % weight_field + + import h5py + if (filename is None): + filename = "%s/%s_data" % (self.output_dir, self.output_prefix) + if not(filename.endswith('.h5')): + filename += ".h5" + + if (len(self.projection_stack) == 0): + mylog.debug("save_light_cone_stack: no projection data loaded.") + return + + mylog.info("Writing light cone data to %s." % filename) + + output = h5py.File(filename, "a") + + node_exists = field_node in output.listnames() + + if node_exists: + if over_write: + mylog.info("Dataset, %s, already exists, overwriting." % field_node) + write_data = True + del output[field_node] + else: + mylog.info("Dataset, %s, already exists in %s, not saving." % (field_node, filename)) + write_data = False + else: + write_data = True + + if write_data: + mylog.info("Saving %s to %s." % (field_node, filename)) + self.projection_stack = na.array(self.projection_stack) + field_dataset = output.create_dataset(field_node, data=self.projection_stack) + field_dataset.attrs['redshifts'] = redshiftList + field_dataset.attrs['observer_redshift'] = na.float(self.observer_redshift) + field_dataset.attrs['field_of_view_in_arcminutes'] = na.float(self.field_of_view_in_arcminutes) + field_dataset.attrs['image_resolution_in_arcseconds'] = na.float(self.image_resolution_in_arcseconds) + + if (len(self.projection_weight_field_stack) > 0): + if node_exists: + if over_write: + mylog.info("Dataset, %s, already exists, overwriting." % weight_field_node) + del output[field_node] + else: + mylog.info("Dataset, %s, already exists in %s, not saving." % (weight_field_node, filename)) + write_data = False + else: + write_data = True + + if write_data: + mylog.info("Saving %s to %s." % (weight_field_node, filename)) + self.projection_weight_field_stack = na.array(self.projection_weight_field_stack) + weight_field_dataset = output.create_dataset(weight_field_node, data=self.projection_weight_field_stack) + weight_field_dataset.attrs['redshifts'] = redshiftList + weight_field_dataset.attrs['observer_redshift'] = na.float(self.observer_redshift) + weight_field_dataset.attrs['field_of_view_in_arcminutes'] = na.float(self.field_of_view_in_arcminutes) + weight_field_dataset.attrs['image_resolution_in_arcseconds'] = na.float(self.image_resolution_in_arcseconds) + + output.close() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/light_cone_projection.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/light_cone_projection.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,280 @@ +""" +Create randomly centered, tiled projections to be used in light cones. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +import numpy as na +import copy + +from yt.funcs import * +from yt.config import ytcfg +from yt.visualization.fixed_resolution import \ + FixedResolutionBuffer +from yt.visualization.plot_collection import \ + PlotCollection +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + parallel_blocking_call + +@parallel_blocking_call +def LightConeProjection(lightConeSlice, field, pixels, weight_field=None, + save_image=False, name="", node=None, field_cuts=None, + add_redshift_label=False, **kwargs): + "Create a single projection to be added into the light cone stack." + + # Use some projection parameters to seed random number generator to make unique node name. + # We are just saving the projection object, so only the projection axis needs to be considered + # since the lateral shifting and tiling occurs after the projection object is made. + # Likewise, only the DepthBoxFraction needs to be considered. + + # ProjectionAxis + # ProjectionCenter[ProjectionAxis] + # DepthBoxFraction + + # Name node with user specified keyword if given with 'node' keyword. + node_name = "LightCone_%s_%d_%f_%f" % (node, lightConeSlice['ProjectionAxis'], + lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']], + lightConeSlice['DepthBoxFraction']) + + mylog.info("Making projection at z = %f from %s." % (lightConeSlice['redshift'], lightConeSlice['filename'])) + + region_center = [0.5 * (lightConeSlice['object'].parameters['DomainRightEdge'][q] + + lightConeSlice['object'].parameters['DomainLeftEdge'][q]) \ + for q in range(lightConeSlice['object'].parameters['TopGridRank'])] + + # Make the plot collection and put it in the slice so we can delete it cleanly in the same scope + # as where the frb will be deleted. + lightConeSlice['pc'] = PlotCollection(lightConeSlice['object'], center=region_center) + + # 1. The Depth Problem + # Use coordinate field cut in line of sight to cut projection to proper depth. + if field_cuts is None: + these_field_cuts = [] + else: + these_field_cuts = copy.deepcopy(field_cuts) + + if (lightConeSlice['DepthBoxFraction'] < 1): + axis = ('x', 'y', 'z')[lightConeSlice['ProjectionAxis']] + depthLeft = lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']] \ + - 0.5 * lightConeSlice['DepthBoxFraction'] + depthRight = lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']] \ + + 0.5 * lightConeSlice['DepthBoxFraction'] + if (depthLeft < 0): + cut_mask = "((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= 0) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= %f)) | ((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= 1))" % \ + (axis, axis, axis, axis, depthRight, axis, axis, (depthLeft+1), axis, axis) + elif (depthRight > 1): + cut_mask = "((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= 0) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= %f)) | ((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= 1))" % \ + (axis, axis, axis, axis, (depthRight-1), axis, axis, depthLeft, axis, axis) + else: + cut_mask = "(grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"%s\"] <= %f)" % (axis, axis, depthLeft, axis, axis, depthRight) + + these_field_cuts.append(cut_mask) + + # Make projection. + lightConeSlice['pc'].add_projection(field, lightConeSlice['ProjectionAxis'], + weight_field=weight_field, + field_parameters=dict(field_cuts=these_field_cuts, + node_name=node_name), + **kwargs) + + # If parallel: all the processes have the whole projection object, but we only need to do the tiling, shifting, and cutting once. + if ytcfg.getint("yt", "__parallel_rank") == 0: + + # 2. The Tile Problem + # Tile projection to specified width. + + # Original projection data. + original_px = copy.deepcopy(lightConeSlice['pc'].plots[0].data['px']) + original_py = copy.deepcopy(lightConeSlice['pc'].plots[0].data['py']) + original_pdx = copy.deepcopy(lightConeSlice['pc'].plots[0].data['pdx']) + original_pdy = copy.deepcopy(lightConeSlice['pc'].plots[0].data['pdy']) + original_field = copy.deepcopy(lightConeSlice['pc'].plots[0].data[field]) + original_weight_field = copy.deepcopy(lightConeSlice['pc'].plots[0].data['weight_field']) + + # Copy original into offset positions to make tiles. + for x in range(int(na.ceil(lightConeSlice['WidthBoxFraction']))): + for y in range(int(na.ceil(lightConeSlice['WidthBoxFraction']))): + if ((x + y) > 0): + lightConeSlice['pc'].plots[0].data['px'] = \ + na.concatenate([lightConeSlice['pc'].plots[0].data['px'], original_px+x]) + lightConeSlice['pc'].plots[0].data['py'] = \ + na.concatenate([lightConeSlice['pc'].plots[0].data['py'], original_py+y]) + lightConeSlice['pc'].plots[0].data['pdx'] = \ + na.concatenate([lightConeSlice['pc'].plots[0].data['pdx'], original_pdx]) + lightConeSlice['pc'].plots[0].data['pdy'] = \ + na.concatenate([lightConeSlice['pc'].plots[0].data['pdy'], original_pdy]) + lightConeSlice['pc'].plots[0].data[field] = \ + na.concatenate([lightConeSlice['pc'].plots[0].data[field], original_field]) + lightConeSlice['pc'].plots[0].data['weight_field'] = \ + na.concatenate([lightConeSlice['pc'].plots[0].data['weight_field'], + original_weight_field]) + + # Delete originals. + del original_px + del original_py + del original_pdx + del original_pdy + del original_field + del original_weight_field + + # 3. The Shift Problem + # Shift projection by random x and y offsets. + + offset = copy.deepcopy(lightConeSlice['ProjectionCenter']) + # Delete depth coordinate. + del offset[lightConeSlice['ProjectionAxis']] + + # Shift x and y positions. + lightConeSlice['pc'].plots[0]['px'] -= offset[0] + lightConeSlice['pc'].plots[0]['py'] -= offset[1] + + # Wrap off-edge cells back around to other side (periodic boundary conditions). + lightConeSlice['pc'].plots[0]['px'][lightConeSlice['pc'].plots[0]['px'] < 0] += \ + na.ceil(lightConeSlice['WidthBoxFraction']) + lightConeSlice['pc'].plots[0]['py'][lightConeSlice['pc'].plots[0]['py'] < 0] += \ + na.ceil(lightConeSlice['WidthBoxFraction']) + + # After shifting, some cells have fractional coverage on both sides of the box. + # Find those cells and make copies to be placed on the other side. + + # Cells hanging off the right edge. + add_x_right = lightConeSlice['pc'].plots[0]['px'] + \ + 0.5 * lightConeSlice['pc'].plots[0]['pdx'] > na.ceil(lightConeSlice['WidthBoxFraction']) + add_x_px = lightConeSlice['pc'].plots[0]['px'][add_x_right] + add_x_px -= na.ceil(lightConeSlice['WidthBoxFraction']) + add_x_py = lightConeSlice['pc'].plots[0]['py'][add_x_right] + add_x_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_x_right] + add_x_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_x_right] + add_x_field = lightConeSlice['pc'].plots[0][field][add_x_right] + add_x_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_x_right] + del add_x_right + + # Cells hanging off the left edge. + add_x_left = lightConeSlice['pc'].plots[0]['px'] - \ + 0.5 * lightConeSlice['pc'].plots[0]['pdx'] < 0 + add2_x_px = lightConeSlice['pc'].plots[0]['px'][add_x_left] + add2_x_px += na.ceil(lightConeSlice['WidthBoxFraction']) + add2_x_py = lightConeSlice['pc'].plots[0]['py'][add_x_left] + add2_x_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_x_left] + add2_x_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_x_left] + add2_x_field = lightConeSlice['pc'].plots[0][field][add_x_left] + add2_x_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_x_left] + del add_x_left + + # Cells hanging off the top edge. + add_y_right = lightConeSlice['pc'].plots[0]['py'] + \ + 0.5 * lightConeSlice['pc'].plots[0]['pdy'] > na.ceil(lightConeSlice['WidthBoxFraction']) + add_y_px = lightConeSlice['pc'].plots[0]['px'][add_y_right] + add_y_py = lightConeSlice['pc'].plots[0]['py'][add_y_right] + add_y_py -= na.ceil(lightConeSlice['WidthBoxFraction']) + add_y_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_y_right] + add_y_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_y_right] + add_y_field = lightConeSlice['pc'].plots[0][field][add_y_right] + add_y_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_y_right] + del add_y_right + + # Cells hanging off the bottom edge. + add_y_left = lightConeSlice['pc'].plots[0]['py'] - \ + 0.5 * lightConeSlice['pc'].plots[0]['pdy'] < 0 + add2_y_px = lightConeSlice['pc'].plots[0]['px'][add_y_left] + add2_y_py = lightConeSlice['pc'].plots[0]['py'][add_y_left] + add2_y_py += na.ceil(lightConeSlice['WidthBoxFraction']) + add2_y_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_y_left] + add2_y_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_y_left] + add2_y_field = lightConeSlice['pc'].plots[0][field][add_y_left] + add2_y_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_y_left] + del add_y_left + + # Add the hanging cells back to the projection data. + lightConeSlice['pc'].plots[0].data['px'] = \ + na.concatenate([lightConeSlice['pc'].plots[0]['px'], add_x_px, add_y_px, + add2_x_px, add2_y_px]) + lightConeSlice['pc'].plots[0].data['py'] = \ + na.concatenate([lightConeSlice['pc'].plots[0]['py'], add_x_py, add_y_py, + add2_x_py, add2_y_py]) + lightConeSlice['pc'].plots[0].data['pdx'] = \ + na.concatenate([lightConeSlice['pc'].plots[0]['pdx'], add_x_pdx, add_y_pdx, + add2_x_pdx, add2_y_pdx]) + lightConeSlice['pc'].plots[0].data['pdy'] = \ + na.concatenate([lightConeSlice['pc'].plots[0]['pdy'], add_x_pdy, add_y_pdy, + add2_x_pdy, add2_y_pdy]) + lightConeSlice['pc'].plots[0].data[field] = \ + na.concatenate([lightConeSlice['pc'].plots[0][field], add_x_field, add_y_field, + add2_x_field, add2_y_field]) + lightConeSlice['pc'].plots[0].data['weight_field'] = \ + na.concatenate([lightConeSlice['pc'].plots[0]['weight_field'], + add_x_weight_field, add_y_weight_field, + add2_x_weight_field, add2_y_weight_field]) + + # Delete original copies of hanging cells. + del add_x_px, add_y_px, add2_x_px, add2_y_px + del add_x_py, add_y_py, add2_x_py, add2_y_py + del add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx + del add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy + del add_x_field, add_y_field, add2_x_field, add2_y_field + del add_x_weight_field, add_y_weight_field, add2_x_weight_field, add2_y_weight_field + + # Tiles were made rounding up the width to the nearest integer. + # Cut off the edges to get the specified width. + # Cut in the x direction. + cut_x = lightConeSlice['pc'].plots[0].data['px'] - \ + 0.5 * lightConeSlice['pc'].plots[0].data['pdx'] < lightConeSlice['WidthBoxFraction'] + lightConeSlice['pc'].plots[0].data['px'] = lightConeSlice['pc'].plots[0].data['px'][cut_x] + lightConeSlice['pc'].plots[0].data['py'] = lightConeSlice['pc'].plots[0].data['py'][cut_x] + lightConeSlice['pc'].plots[0].data['pdx'] = lightConeSlice['pc'].plots[0].data['pdx'][cut_x] + lightConeSlice['pc'].plots[0].data['pdy'] = lightConeSlice['pc'].plots[0].data['pdy'][cut_x] + lightConeSlice['pc'].plots[0].data[field] = lightConeSlice['pc'].plots[0].data[field][cut_x] + lightConeSlice['pc'].plots[0].data['weight_field'] = \ + lightConeSlice['pc'].plots[0].data['weight_field'][cut_x] + del cut_x + + # Cut in the y direction. + cut_y = lightConeSlice['pc'].plots[0].data['py'] - \ + 0.5 * lightConeSlice['pc'].plots[0].data['pdy'] < lightConeSlice['WidthBoxFraction'] + lightConeSlice['pc'].plots[0].data['px'] = lightConeSlice['pc'].plots[0].data['px'][cut_y] + lightConeSlice['pc'].plots[0].data['py'] = lightConeSlice['pc'].plots[0].data['py'][cut_y] + lightConeSlice['pc'].plots[0].data['pdx'] = lightConeSlice['pc'].plots[0].data['pdx'][cut_y] + lightConeSlice['pc'].plots[0].data['pdy'] = lightConeSlice['pc'].plots[0].data['pdy'][cut_y] + lightConeSlice['pc'].plots[0].data[field] = lightConeSlice['pc'].plots[0].data[field][cut_y] + lightConeSlice['pc'].plots[0].data['weight_field'] = lightConeSlice['pc'].plots[0].data['weight_field'][cut_y] + del cut_y + + # Save an image if requested. + if save_image: + lightConeSlice['pc'].set_xlim(0, lightConeSlice['WidthBoxFraction']) + lightConeSlice['pc'].set_ylim(0, lightConeSlice['WidthBoxFraction']) + if add_redshift_label: + lightConeSlice['pc'].plots[-1].modify['text']((0.5, 0.03), "z = %.3f" % lightConeSlice['redshift'], + dict(color='black',size=50)) + lightConeSlice['pc'].save(name) + + # Create fixed resolution buffer to return back to the light cone object. + # These buffers will be stacked together to make the light cone. + frb = FixedResolutionBuffer(lightConeSlice['pc'].plots[0].data, \ + (0, lightConeSlice['WidthBoxFraction'], + 0, lightConeSlice['WidthBoxFraction']), + (pixels, pixels), antialias=False) + + return frb + else: + # If running in parallel and this is not the root process, return None. + return None diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('light_cone',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_cone/unique_solution.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_cone/unique_solution.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,224 @@ +""" +Functions to generate unique light cone solutions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +import copy +import numpy as na +import random as rand +import sys + +from yt.utilities.logger import ytLogger as mylog +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + parallel_root_only + +from .light_cone import LightCone +from .common_n_volume import commonNVolume + +def project_unique_light_cones(lightcone, seed_file, field, **kwargs): + "Make light cone projections using list of random seeds in a file." + + seedList = _read_seed_file(seed_file) + + prefix = lightcone.output_prefix + lightcone.calculate_light_cone_solution(seed=0) + lastSeed = None + + for seed in seedList: + if (seed['master'] != lastSeed): + lightcone.rerandomize_light_cone_solution(seed['master'], recycle=False) + lastSeed = seed['master'] + if (seed['recycle'] is not None): + lightcone.rerandomize_light_cone_solution(seed['recycle'], recycle=True) + + lightcone.output_prefix = "%s_%s_%s" % (prefix, seed['master'], seed['recycle']) + lightcone.project_light_cone(field, **kwargs) + +def find_unique_solutions(lightcone1, solutions=100, seed=None, max_overlap=0.25, failures=10, + recycle=True, filename='unique.dat'): + "Find a set of random seeds that will give light cones will minimal volume overlap." + + lightcone2 = copy.deepcopy(lightcone1) + lightcone1.calculate_light_cone_solution(seed=0) + lightcone2.calculate_light_cone_solution(seed=0) + + uniqueSeeds = [] + if recycle: + master = None + newRecycleSeed = None + fails = 0 + recycleFails = 0 + + maxCommon = 0.0 + + # Need to continuall save and reset the state of the random number generator + # since it is being reset by the light cone generator. + if seed is None: + state = None + else: + rand.seed(seed) + state = rand.getstate() + + failDigits = str(int(na.log10(failures))+1) + + while (len(uniqueSeeds) < solutions): + # Create new random seed. + if (recycle and master is not None): + newSeed = master + if state is not None: rand.setstate(state) + newRecycleSeed = rand.randint(1, 1e9) + state = rand.getstate() + else: + if state is not None: rand.setstate(state) + newSeed = rand.randint(1, 1e9) + state = rand.getstate() + if recycle: + master = newSeed + recycleFails = 0 + newRecycleSeed = None + + sys.stderr.write(("Unique solutions: %d, consecutive failures: %"+failDigits+"d, %"+failDigits+"d.\r") % \ + (len(uniqueSeeds), fails, recycleFails)) + + lightcone1.rerandomize_light_cone_solution(newSeed, recycle=False) + if newRecycleSeed is not None: + lightcone1.rerandomize_light_cone_solution(newRecycleSeed, recycle=True) + + # Compare with all other seeds. + testPass = True + for uniqueSeed in uniqueSeeds: + lightcone2.rerandomize_light_cone_solution(uniqueSeed['master'], recycle=False) + if uniqueSeed['recycle'] is not None: + lightcone2.rerandomize_light_cone_solution(uniqueSeed['recycle'], recycle=True) + + common = _compare_solutions(lightcone1.light_cone_solution, lightcone2.light_cone_solution) + + if (common > max_overlap): + testPass = False + break + else: + maxCommon = max(maxCommon, common) + + if testPass: + uniqueSeeds.append({'master':newSeed, 'recycle':newRecycleSeed}) + fails = 0 + recycleFails = 0 + + else: + if recycle: + recycleFails += 1 + else: + fails += 1 + + if (recycleFails >= failures): + sys.stderr.write(("Unique solutions: %d, consecutive failures: %"+failDigits+"d, %"+failDigits+"d.\n") % \ + (len(uniqueSeeds), fails, recycleFails)) + fails += 1 + mylog.info("Max recycled failures reached with master seed %d." % newSeed) + master = None + if (fails >= failures): + sys.stderr.write(("Unique solutions: %d, consecutive failures: %"+failDigits+"d, %"+failDigits+"d.\n") % \ + (len(uniqueSeeds), fails, recycleFails)) + mylog.error("Max consecutive failures reached.") + break + + mylog.info("Created %d unique solutions." % len(uniqueSeeds)) + mylog.info("Maximum common volume is %.2e." % maxCommon) + _write_seed_file(uniqueSeeds, filename) + return uniqueSeeds + +def _compare_solutions(solution1, solution2): + "Calculate common volume between two light cone solutions." + + if (len(solution1) != len(solution2)): + mylog.error("Cannot compare light cone solutions with unequal numbers of slices.") + return -1 + + commonVolume = 0.0 + totalVolume = 0.0 + + # Check that solution volumes are the same. + if((solution1[0]['DepthBoxFraction'] * solution1[0]['WidthBoxFraction']**2) != + (solution2[0]['DepthBoxFraction'] * solution2[0]['WidthBoxFraction']**2)): + mylog.error("Light cone solutions do not have equal volumes, will use the smaller one.") + + for q in range(len(solution1)): + cube1 = na.zeros(shape=(len(solution1[q]['ProjectionCenter']), 2)) + volume1 = 1.0 + for w in range(len(cube1)): + if (w == solution1[q]['ProjectionAxis']): + width = solution1[q]['DepthBoxFraction'] + else: + width = solution1[q]['WidthBoxFraction'] + volume1 *= width + cube1[w] = [solution1[q]['ProjectionCenter'][w] - 0.5 * width, + solution1[q]['ProjectionCenter'][w] + 0.5 * width] + + cube2 = na.zeros(shape=(len(solution2[q]['ProjectionCenter']), 2)) + volume2 = 1.0 + for w in range(len(cube2)): + if (w == solution2[q]['ProjectionAxis']): + width = solution2[q]['DepthBoxFraction'] + else: + width = solution2[q]['WidthBoxFraction'] + volume2 *= width + cube2[w] = [solution2[q]['ProjectionCenter'][w] - 0.5 * width, + solution2[q]['ProjectionCenter'][w] + 0.5 * width] + + totalVolume += min(volume1, volume2) + commonVolume += commonNVolume(cube1, cube2, periodic=na.array([[0, 1], [0, 1], [0, 1]])) + + return (commonVolume/totalVolume) + +def _read_seed_file(filename): + "Read list of random seeds from a file." + + mylog.info("Reading random seed list from %s." % filename) + + seedList = [] + + lines = file(filename) + for line in lines: + if line[0] != '#': + line = line.strip() + onLine = line.split(',') + if (len(onLine) == 1): + seedList.append({'master':onLine[0], 'recycle':None}) + else: + seedList.append({'master':onLine[0], 'recycle':onLine[1]}) + + return seedList + +@parallel_root_only +def _write_seed_file(seedList, filename): + "Write list of random seeds to a file." + + mylog.info("Writing random seed list to %s." % filename) + + f = open(filename, 'w') + for seed in seedList: + if seed['recycle'] is None: + f.write("%s\n" % seed['master']) + else: + f.write("%s,%s\n" % (seed['master'], seed['recycle'])) + f.close() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_ray/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_ray/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,32 @@ +""" +API for light_ray + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .light_ray import \ + LightRay diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_ray/light_ray.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_ray/light_ray.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,408 @@ +""" +LightRay class and member functions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +try: + from mpi4py import MPI + parallel_light_ray = True + my_rank = MPI.COMM_WORLD.rank + my_size = MPI.COMM_WORLD.size +except ImportError: + parallel_light_ray = False + my_rank = 0 + my_size = 1 + +import copy +import h5py +import numpy as na + +from yt.funcs import * + +from yt.analysis_modules.simulation_handler.enzo_simulation import \ + EnzoSimulation +from yt.analysis_modules.halo_profiler.multi_halo_profiler import \ + HaloProfiler +from yt.convenience import load +from yt.utilities.logger import lagosLogger as mylog + +class LightRay(EnzoSimulation): + def __init__(self, EnzoParameterFile, FinalRedshift, InitialRedshift, + deltaz_min=0.0, use_minimum_datasets=True, + minimum_coherent_box_fraction=0.0, **kwargs): + + EnzoSimulation.__init__(self, EnzoParameterFile, + initial_redshift=InitialRedshift, + final_redshift=FinalRedshift, links=True, + enzo_parameters={'CosmologyComovingBoxSize':float}, + **kwargs) + + self.deltaz_min = deltaz_min + self.use_minimum_datasets = use_minimum_datasets + self.minimum_coherent_box_fraction = minimum_coherent_box_fraction + self.dtype = '>f8' + + self.light_ray_solution = [] + self._data = {} + + # Don't use box coherence with maximum dataset depths. + if self.use_minimum_datasets and self.minimum_coherent_box_fraction > 0: + mylog.info("Setting minimum_coherent_box_fraction to 0 with minimal light ray.") + self.minimum_coherent_box_fraction = 0 + + # Get list of datasets for light ray solution. + self.light_ray_solution = \ + self.create_cosmology_splice(minimal=self.use_minimum_datasets, + deltaz_min=self.deltaz_min) + + def _calculate_light_ray_solution(self, seed=None, filename=None): + "Create list of datasets to be added together to make the light ray." + + # Calculate dataset sizes, and get random dataset axes and centers. + na.random.seed(seed) + + # For box coherence, keep track of effective depth travelled. + boxFractionUsed = 0.0 + + for q in range(len(self.light_ray_solution)): + if (q == len(self.light_ray_solution) - 1): + z_next = self.FinalRedshift + else: + z_next = self.light_ray_solution[q+1]['redshift'] + + # Calculate fraction of box required for a depth of delta z + self.light_ray_solution[q]['TraversalBoxFraction'] = \ + self.cosmology.ComovingRadialDistance(\ + z_next, self.light_ray_solution[q]['redshift']) * \ + self.enzoParameters['CosmologyHubbleConstantNow'] / \ + self.enzoParameters['CosmologyComovingBoxSize'] + + # Simple error check to make sure more than 100% of box depth + # is never required. + if (self.light_ray_solution[q]['TraversalBoxFraction'] > 1.0): + mylog.error("Warning: box fraction required to go from z = %f to %f is %f" % + (self.light_ray_solution[q]['redshift'], z_next, + self.light_ray_solution[q]['TraversalBoxFraction'])) + mylog.error("Full box delta z is %f, but it is %f to the next data dump." % + (self.light_ray_solution[q]['deltazMax'], + self.light_ray_solution[q]['redshift']-z_next)) + + # Get dataset axis and center. + # If using box coherence, only get start point and vector if + # enough of the box has been used, + # or if boxFractionUsed will be greater than 1 after this slice. + if (q == 0) or (self.minimum_coherent_box_fraction == 0) or \ + (boxFractionUsed > self.minimum_coherent_box_fraction) or \ + (boxFractionUsed + self.light_ray_solution[q]['TraversalBoxFraction'] > 1.0): + # Random star point + self.light_ray_solution[q]['start'] = na.random.random(3) + theta = na.pi * na.random.random() + phi = 2 * na.pi * na.random.random() + boxFractionUsed = 0.0 + else: + # Use end point of previous segment and same theta and phi. + self.light_ray_solution[q]['start'] = self.light_ray_solution[q-1]['end'][:] + + self.light_ray_solution[q]['end'] = self.light_ray_solution[q]['start'] + \ + self.light_ray_solution[q]['TraversalBoxFraction'] * \ + na.array([na.cos(phi) * na.sin(theta), + na.sin(phi) * na.sin(theta), + na.cos(theta)]) + boxFractionUsed += self.light_ray_solution[q]['TraversalBoxFraction'] + + if filename is not None: + self._write_light_ray_solution(filename, \ + extra_info={'EnzoParameterFile':self.EnzoParameterFile, + 'RandomSeed':seed, + 'InitialRedshift':self.InitialRedshift, + 'FinalRedshift':self.FinalRedshift}) + + def make_light_ray(self, seed=None, fields=None, + solution_filename=None, data_filename=None, + get_nearest_galaxy=False, **kwargs): + "Create a light ray and get field values for each lixel." + + # Calculate solution. + self._calculate_light_ray_solution(seed=seed, filename=solution_filename) + + # Initialize data structures. + self._data = {} + data = [] + if fields is None: fields = [] + all_fields = [field for field in fields] + all_fields.extend(['dl', 'dredshift', 'redshift']) + if get_nearest_galaxy: + all_fields.extend(['x', 'y', 'z', 'nearest_galaxy', 'nearest_galaxy_mass']) + fields.extend(['x', 'y', 'z']) + + todo = na.arange(my_rank, len(self.light_ray_solution), my_size) + for index in todo: + segment = self.light_ray_solution[index] + mylog.info("Proc %04d: creating ray segment at z = %f." % + (my_rank, segment['redshift'])) + if segment['next'] is None: + next_redshift = self.FinalRedshift + else: + next_redshift = segment['next']['redshift'] + + mylog.info("Getting segment at z = %s: %s to %s." % + (segment['redshift'], segment['start'], segment['end'])) + + if get_nearest_galaxy: + halo_list = self._get_halo_list(segment['filename'], **kwargs) + + # Load dataset for segment. + pf = load(segment['filename']) + + # Break periodic ray into non-periodic segments. + sub_segments = periodic_ray(segment['start'], segment['end']) + + # Prepare data structure for subsegment. + sub_data = {} + sub_data['segment_redshift'] = segment['redshift'] + for field in all_fields: + sub_data[field] = na.array([], dtype=self.dtype) + + # Get data for all subsegments in segment. + for sub_segment in sub_segments: + mylog.info("Getting subsegment: %s to %s." % + (list(sub_segment[0]), list(sub_segment[1]))) + sub_ray = pf.h.ray(sub_segment[0], sub_segment[1]) + sub_data['dl'] = na.concatenate([sub_data['dl'], + (sub_ray['dts'] * + vector_length(sub_segment[0], + sub_segment[1]))]) + for field in fields: + sub_data[field] = na.concatenate([sub_data[field], + (sub_ray[field])]) + + sub_ray.clear_data() + del sub_ray + + # Get redshift for each lixel. Assume linear relation between l and z. + sub_data['dredshift'] = (segment['redshift'] - next_redshift) * \ + (sub_data['dl'] / vector_length(segment['start'], segment['end'])) + sub_data['redshift'] = segment['redshift'] \ + - sub_data['dredshift'].cumsum() + sub_data['dredshift'] + + # Calculate distance to nearest object on halo list for each lixel. + if get_nearest_galaxy: + sub_data['nearest_galaxy'], sub_data['nearest_galaxy_mass'] = \ + self._get_nearest_galaxy_distance(sub_data, halo_list) + sub_data['nearest_galaxy'] *= pf.units['mpccm'] + + # Remove empty lixels. + sub_dl_nonzero = sub_data['dl'].nonzero() + for field in all_fields: + sub_data[field] = sub_data[field][sub_dl_nonzero] + del sub_dl_nonzero + + # Convert dl to Mpc comoving. + sub_data['dl'] *= pf.units['cm'] + + # Add segment to list. + data.append(sub_data) + + pf.h.clear_all_data() + del pf + + if parallel_light_ray: + MPI.COMM_WORLD.Barrier() + if my_rank == 0: + for proc in range(1, my_size): + buf = MPI.COMM_WORLD.recv(source=proc, tag=0) + data += buf + else: + MPI.COMM_WORLD.send(data, dest=0, tag=0) + del data + MPI.COMM_WORLD.Barrier() + + if my_rank == 0: + data.sort(key=lambda a:a['segment_redshift'], reverse=True) + data = self._flatten_ray_data(data, exceptions=['segment_redshift']) + + if data_filename is not None: + self._write_light_ray(data_filename, data) + + self._data = data + return data + + def _flatten_ray_data(self, data, exceptions=None): + "Flatten the list of dicts into one dict." + + if exceptions is None: exceptions = [] + new_data = {} + for datum in data: + for field in [field for field in datum.keys() + if field not in exceptions]: + if new_data.has_key(field): + new_data[field] = na.concatenate([new_data[field], datum[field]]) + else: + new_data[field] = na.copy(datum[field]) + + return new_data + + def _get_halo_list(self, dataset, halo_profiler_kwargs=None, + halo_profiler_actions=None, halo_list='all'): + "Load a list of halos for the dataset." + + if halo_profiler_kwargs is None: halo_profiler_kwargs = {} + if halo_profiler_actions is None: halo_profiler_actions = [] + + hp = HaloProfiler(dataset, **halo_profiler_kwargs) + for action in halo_profiler_actions: + if not action.has_key('args'): action['args'] = () + if not action.has_key('kwargs'): action['kwargs'] = {} + action['function'](hp, *action['args'], **action['kwargs']) + + if halo_list == 'all': + return_list = copy.deepcopy(hp.all_halos) + elif halo_list == 'filtered': + return_list = copy.deepcopy(hp.filtered_halos) + else: + mylog.error("Keyword, halo_list, must be either 'all' or 'filtered'.") + return_list = None + + del hp + return return_list + + def _get_nearest_galaxy_distance(self, data, halo_list): + """ + Calculate distance to nearest object in halo list for each lixel in data. + Return list of distances and masses of nearest objects. + """ + + # Create position array from halo list. + halo_centers = na.array(map(lambda halo: halo['center'], halo_list)) + halo_mass = na.array(map(lambda halo: halo['TotalMassMsun'], halo_list)) + + nearest_distance = na.zeros(data['x'].shape) + nearest_mass = na.zeros(data['x'].shape) + for index in xrange(nearest_distance.size): + nearest = na.argmin(periodic_distance(na.array([data['x'][index], + data['y'][index], + data['z'][index]]), + halo_centers)) + nearest_distance[index] = periodic_distance(na.array([data['x'][index], + data['y'][index], + data['z'][index]]), + halo_centers[nearest]) + nearest_mass[index] = halo_mass[nearest] + + return (nearest_distance, nearest_mass) + + def _write_light_ray(self, filename, data): + "Write light ray data to hdf5 file." + + mylog.info("Saving light ray data to %s." % filename) + output = h5py.File(filename, 'w') + for field in data.keys(): + output.create_dataset(field, data=data[field], dtype=self.dtype) + output.close() + + def _write_light_ray_solution(self, filename, extra_info=None): + "Write light ray solution to a file." + + if my_rank != 0: return + + mylog.info("Writing light ray solution to %s." % filename) + f = open(filename, 'w') + if extra_info is not None: + for par, val in extra_info.items(): + f.write("%s = %s\n" % (par, val)) + f.write("\nSegment Redshift dl/box Start x y z End x y z Dataset\n") + for q, segment in enumerate(self.light_ray_solution): + f.write("%04d %.6f %.6f % .10f % .10f % .10f % .10f % .10f % .10f %s\n" % \ + (q, segment['redshift'], segment['TraversalBoxFraction'], + segment['start'][0], segment['start'][1], segment['start'][2], + segment['end'][0], segment['end'][1], segment['end'][2], + segment['filename'])) + f.close() + +def vector_length(start, end): + "Calculate vector length." + + return na.sqrt(na.power((end - start), 2).sum()) + +def periodic_distance(coord1, coord2): + "Calculate length of shortest vector between to points in periodic domain." + dif = coord1 - coord2 + + dim = na.ones(coord1.shape,dtype=int) + def periodic_bind(num): + pos = na.abs(num % dim) + neg = na.abs(num % -dim) + return na.min([pos,neg],axis=0) + + dif = periodic_bind(dif) + return na.sqrt((dif * dif).sum(axis=-1)) + +def periodic_ray(start, end, left=None, right=None): + "Break up periodic ray into non-periodic segments." + + if left is None: + left = na.zeros(start.shape) + if right is None: + right = na.ones(start.shape) + dim = right - left + + vector = end - start + wall = na.zeros(start.shape) + close = na.zeros(start.shape, dtype=object) + + left_bound = vector < 0 + right_bound = vector > 0 + no_bound = vector == 0.0 + bound = vector != 0.0 + + wall[left_bound] = left[left_bound] + close[left_bound] = na.max + wall[right_bound] = right[right_bound] + close[right_bound] = na.min + wall[no_bound] = na.inf + close[no_bound] = na.min + + segments = [] + this_start = na.copy(start) + this_end = na.copy(end) + t = 0.0 + tolerance = 1e-6 + + while t < 1.0 - tolerance: + nearest = na.array([close[q]([this_end[q], wall[q]]) \ + for q in range(start.size)]) + dt = ((nearest - this_start) / vector)[bound].min() + now = this_start + vector * dt + segments.append([na.copy(this_start), na.copy(now)]) + this_start = na.copy(now) + hit_left = (this_start <= left) & (vector < 0) + if (hit_left).any(): + this_start[hit_left] += dim[hit_left] + this_end[hit_left] += dim[hit_left] + hit_right = (this_start >= right) & (vector > 0) + if (hit_right).any(): + this_start[hit_right] -= dim[hit_right] + this_end[hit_right] -= dim[hit_right] + t += dt + + return segments diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/light_ray/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/light_ray/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('light_ray',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import setuptools + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('analysis_modules',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + config.add_subpackage("coordinate_transformation") + config.add_subpackage("halo_finding") + config.add_subpackage("halo_mass_function") + config.add_subpackage("halo_merger_tree") + config.add_subpackage("halo_profiler") + config.add_subpackage("hierarchy_subset") + config.add_subpackage("level_sets") + config.add_subpackage("light_ray") + config.add_subpackage("light_cone") + config.add_subpackage("simulation_handler") + config.add_subpackage("spectral_integrator") + config.add_subpackage("star_analysis") + config.add_subpackage("two_point_functions") + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/simulation_handler/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/simulation_handler/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,32 @@ +""" +API for simulation_handler + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .enzo_simulation import \ + EnzoSimulation diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/simulation_handler/enzo_simulation.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/simulation_handler/enzo_simulation.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,606 @@ +""" +EnzoSimulation class and member functions. + +Author: Britton Smith +Affiliation: CASA/University of CO, Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Britton Smith. 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 . +""" + +from yt.funcs import * + +import numpy as na +import glob +import os + +dt_Tolerance = 1e-3 + +from yt.utilities.cosmology import \ + Cosmology, \ + EnzoCosmology + +from yt.convenience import \ + load + +class EnzoSimulation(object): + """ + Super class for performing the same operation over all data dumps in + a simulation from one redshift to another. + """ + def __init__(self, EnzoParameterFile, initial_time=None, final_time=None, initial_redshift=None, final_redshift=None, + links=False, enzo_parameters=None, get_time_outputs=True, get_redshift_outputs=True, get_available_data=False, + get_data_by_force=False): + """ + Initialize an EnzoSimulation object. + :param initial_time (float): the initial time in code units for the dataset list. Default: None. + :param final_time (float): the final time in code units for the dataset list. Default: None. + :param initial_redshift (float): the initial (highest) redshift for the dataset list. Only for + cosmological simulations. Default: None. + :param final_redshift (float): the final (lowest) redshift for the dataset list. Only for cosmological + simulations. Default: None. + :param links (bool): if True, each entry in the dataset list will contain entries, previous and next, that + point to the previous and next entries on the dataset list. Default: False. + :param enzo_parameters (dict): a dictionary specify additional parameters to be retrieved from the + parameter file. The format should be the name of the parameter as the key and the variable type as + the value. For example, {'CosmologyComovingBoxSize':float}. All parameter values will be stored in + the dictionary attribute, enzoParameters. Default: None. + :param get_time_outputs (bool): if False, the time datasets, specified in Enzo with the dtDataDump, will not + be added to the dataset list. Default: True. + :param get_redshift_outputs (bool): if False, the redshift datasets will not be added to the dataset list. Default: True. + :param get_available_data (bool): if True, only datasets that are found to exist at the file path are added + to the list. Default: False. + :param get_data_by_force (bool): if True, time data dumps are not calculated using dtDataDump. Instead, the + the working directory is searched for directories that match the datadumpname keyword. Each dataset + is loaded up to get the time and redshift manually. This is useful with collapse simulations that use + OutputFirstTimeAtLevel or with simulations that make outputs based on cycle numbers. Default: False. + """ + self.EnzoParameterFile = EnzoParameterFile + self.enzoParameters = {} + self.redshift_outputs = [] + self.allOutputs = [] + self.InitialTime = initial_time + self.FinalTime = final_time + self.InitialRedshift = initial_redshift + self.FinalRedshift = final_redshift + self.links = links + self.get_time_outputs = get_time_outputs + self.get_redshift_outputs = get_redshift_outputs + self.get_available_data = get_available_data + + # Add any extra parameters to parameter dict. + if enzo_parameters is None: enzo_parameters = {} + EnzoParameterDict.update(enzo_parameters) + + # Set some parameter defaults. + self._set_parameter_defaults() + + # Read parameters. + self._read_enzo_parameter_file() + + # Get all the appropriate datasets. + self._get_all_outputs(brute_force=get_data_by_force) + + def _calculate_redshift_dump_times(self): + "Calculates time from redshift of redshift dumps." + + for output in self.redshift_outputs: + output['time'] = self.enzo_cosmology.ComputeTimeFromRedshift(output['redshift']) / \ + self.enzo_cosmology.TimeUnits + + def _calculate_time_dumps(self): + "Calculates time dumps and their redshifts if cosmological." + + if self.enzoParameters['dtDataDump'] <= 0.0: return [] + time_outputs = [] + + index = 0 + current_time = self.SimulationInitialTime + while (current_time <= self.FinalTime) or \ + (abs(self.FinalTime - current_time) / self.FinalTime) < dt_Tolerance: + filename = "%s/%s%04d/%s%04d" % (self.enzoParameters['GlobalDir'], + self.enzoParameters['DataDumpDir'],index, + self.enzoParameters['DataDumpName'],index) + + output = {'index':index,'filename':filename,'time':current_time} + if self.enzoParameters['ComovingCoordinates']: + t = self.enzo_cosmology.InitialTime + (self.enzoParameters['dtDataDump'] * self.enzo_cosmology.TimeUnits * index) + output['redshift'] = self.enzo_cosmology.ComputeRedshiftFromTime(t) + + if not self.get_available_data or os.path.exists(filename): + time_outputs.append(output) + + current_time += self.enzoParameters['dtDataDump'] + index += 1 + + return time_outputs + + def _combine_data_outputs(self, brute_force=False): + "Combines redshift and time data into one sorted list." + + # If True, get time dumps just by looking through the working directory. + if brute_force: + time_outputs = self._get_outputs_by_force() + + # Calculate time dumps based on dtDataDump + elif self.enzoParameters.has_key('dtDataDump') and self.get_time_outputs: + time_outputs = self._calculate_time_dumps() + + else: + time_outputs =[] + + # Calculate times for redshift dumps. + if self.enzoParameters['ComovingCoordinates'] and self.get_redshift_outputs: + self._calculate_redshift_dump_times() + else: + self.redshift_outputs = [] + + self.allOutputs = self.redshift_outputs + time_outputs + self.allOutputs.sort(key=lambda obj:obj['time']) + + start_index = None + end_index = None + + # Add links to next and previous dataset to each entry. + for q in range(len(self.allOutputs)): + if self.allOutputs[q].has_key('index'): del self.allOutputs[q]['index'] + + if start_index is None: + if self.allOutputs[q]['time'] >= self.InitialTime or \ + abs(self.allOutputs[q]['time'] - self.InitialTime) < \ + self.allOutputs[q]['time'] * dt_Tolerance: + start_index = q + + if end_index is None: + if self.allOutputs[q]['time'] > self.FinalTime: + end_index = q - 1 + if abs(self.allOutputs[q]['time'] - self.FinalTime) < \ + self.allOutputs[q]['time'] * dt_Tolerance: + end_index = q + if q == len(self.allOutputs) - 1: + end_index = q + + for q in range(len(self.allOutputs)): + if self.links and start_index is not None: + if q <= start_index: + self.allOutputs[q]['previous'] = None + else: + self.allOutputs[q]['previous'] = self.allOutputs[q-1] + + if q >= end_index: + self.allOutputs[q]['next'] = None + else: + self.allOutputs[q]['next'] = self.allOutputs[q+1] + + del self.redshift_outputs + + if end_index is None: + end_index = len(self.allOutputs)-1 + + self.allOutputs = self.allOutputs[start_index:end_index+1] + mylog.info("Loaded %s total data outputs." % len(self.allOutputs)) + + def _get_all_outputs(self, brute_force=False): + """ + Get all the datasets in the time/redshift interval requested, or search + the data directory for potential datasets. + """ + + # Check for sufficient starting/ending parameters. + if self.InitialTime is None and self.InitialRedshift is None: + if self.enzoParameters['ComovingCoordinates'] and \ + 'CosmologyInitialRedshift' in self.enzoParameters: + self.InitialRedshift = self.enzoParameters['CosmologyInitialRedshift'] + elif 'InitialTime' in self.enzoParameters: + self.InitialTime = self.enzoParameters['InitialTime'] + else: + mylog.error("Couldn't find parameter for initial time or redshift from parameter file.") + return None + + if self.FinalTime is None and self.FinalRedshift is None: + if self.enzoParameters['ComovingCoordinates'] and \ + 'CosmologyFinalRedshift' in self.enzoParameters: + self.FinalRedshift = self.enzoParameters['CosmologyFinalRedshift'] + elif 'StopTime' in self.enzoParameters: + self.FinalTime = self.enzoParameters['StopTime'] + else: + mylog.error("Couldn't find parameter for final time or redshift from parameter file.") + return None + + # Convert initial/final redshifts to times. + if self.enzoParameters['ComovingCoordinates']: + # Instantiate a cosmology calculator. + self.cosmology = Cosmology(HubbleConstantNow = + (100.0 * self.enzoParameters['CosmologyHubbleConstantNow']), + OmegaMatterNow = self.enzoParameters['CosmologyOmegaMatterNow'], + OmegaLambdaNow = self.enzoParameters['CosmologyOmegaLambdaNow']) + + # Instantiate EnzoCosmology object for units and time conversions. + self.enzo_cosmology = EnzoCosmology(HubbleConstantNow = + (100.0 * self.enzoParameters['CosmologyHubbleConstantNow']), + OmegaMatterNow = self.enzoParameters['CosmologyOmegaMatterNow'], + OmegaLambdaNow = self.enzoParameters['CosmologyOmegaLambdaNow'], + InitialRedshift = self.enzoParameters['CosmologyInitialRedshift']) + if self.InitialRedshift is not None: + self.InitialTime = self.enzo_cosmology.ComputeTimeFromRedshift(self.InitialRedshift) / \ + self.enzo_cosmology.TimeUnits + if self.FinalRedshift is not None: + self.FinalTime = self.enzo_cosmology.ComputeTimeFromRedshift(self.FinalRedshift) / \ + self.enzo_cosmology.TimeUnits + + # Get initial time of simulation. + if self.enzoParameters['ComovingCoordinates'] and \ + 'CosmologyInitialRedshift' in self.enzoParameters: + self.SimulationInitialTime = self.enzo_cosmology.InitialTime / self.enzo_cosmology.TimeUnits + elif 'InitialTime' in self.enzoParameters: + self.SimulationInitialTime = self.enzoParameters['InitialTime'] + else: + self.SimulationInitialTime = 0.0 + + # Combine all data dumps in to ordered list. + self._combine_data_outputs(brute_force=brute_force) + + def _get_outputs_by_force(self): + """ + Search for directories matching the data dump keywords. + If found, get dataset times by brute force py opening the pf. + """ + + # look for time dumps. + potential_time_outputs = glob.glob("%s/%s*" % (self.enzoParameters['GlobalDir'], + self.enzoParameters['DataDumpDir'])) + time_outputs = [] + mylog.info("Checking validity of %d potential time dumps." % + len(potential_time_outputs)) + + for output in potential_time_outputs: + index = output[output.find(self.enzoParameters['DataDumpDir']) + + len(self.enzoParameters['DataDumpDir']):] + filename = "%s/%s%s/%s%s" % (self.enzoParameters['GlobalDir'], + self.enzoParameters['DataDumpDir'], index, + self.enzoParameters['DataDumpName'], index) + if os.path.exists(filename): + pf = load(filename) + if pf is not None: + time_outputs.append({'filename': filename, 'time': pf.current_time}) + if self.enzoParameters['ComovingCoordinates']: + time_outputs[-1]['redshift'] = pf.current_redshift + del pf + mylog.info("Located %d time dumps." % len(time_outputs)) + return time_outputs + + def _read_enzo_parameter_file(self): + "Reads an Enzo parameter file looking for cosmology and output parameters." + lines = open(self.EnzoParameterFile).readlines() + for line in lines: + if line.find("#") >= 0: # Keep the commented lines + line=line[:line.find("#")] + line=line.strip() + if len(line) < 2: + continue + try: + param, vals = map(str,line.split("=")) + param = param.strip() + vals = vals.strip().split("#", 1)[0].split("//", 1)[0] + except ValueError: + continue + if EnzoParameterDict.has_key(param): + t = map(EnzoParameterDict[param], vals.split()) + if len(t) == 1: + self.enzoParameters[param] = t[0] + else: + self.enzoParameters[param] = t + elif param.startswith("CosmologyOutputRedshift["): + index = param[param.find("[")+1:param.find("]")] + self.redshift_outputs.append({'index':int(index), 'redshift':float(vals)}) + + # Add filenames to redshift outputs. + tempRedshiftList = [] + for output in self.redshift_outputs: + output["filename"] = "%s/%s%04d/%s%04d" % (self.enzoParameters['GlobalDir'], + self.enzoParameters['RedshiftDumpDir'],output['index'], + self.enzoParameters['RedshiftDumpName'],output['index']) + if not self.get_available_data or os.path.exists(output["filename"]): + tempRedshiftList.append(output) + self.redshift_outputs = tempRedshiftList + del tempRedshiftList + + def _set_parameter_defaults(self): + "Set some default parameters to avoid problems if they are not in the parameter file." + self.enzoParameters['GlobalDir'] = "." + self.enzoParameters['RedshiftDumpName'] = "RedshiftOutput" + self.enzoParameters['RedshiftDumpDir'] = "RD" + self.enzoParameters['DataDumpName'] = "data" + self.enzoParameters['DataDumpDir'] = "DD" + self.enzoParameters['ComovingCoordinates'] = 0 + + def imagine_minimal_splice(self, initial_redshift, final_redshift, decimals=3, filename=None, + redshift_output_string='CosmologyOutputRedshift', start_index=0): + """ + Create imaginary list of redshift outputs to maximally span a redshift interval. + :param decimals (int): The decimal place to which the output redshift will be rounded. + If the decimal place in question is nonzero, the redshift will be rounded up to + ensure continuity of the splice. Default: 3. + :param filename (str): If provided, a file will be written with the redshift outputs in + the form in which they should be given in the enzo parameter file. Default: None. + :param redshift_output_string (str): The parameter accompanying the redshift outputs in the + enzo parameter file. Default: "CosmologyOutputRedshift". + :param start_index (int): The index of the first redshift output. Default: 0. + """ + + z = initial_redshift + outputs = [] + + while z > final_redshift: + rounded = na.round(z, decimals=decimals) + if rounded - z < 0: + rounded += na.power(10.0,(-1.0*decimals)) + z = rounded + + deltaz_max = __deltaz_forward(self.cosmology, z, self.enzoParameters['CosmologyComovingBoxSize']) + outputs.append({'redshift': z, 'deltazMax': deltaz_max}) + z -= deltaz_max + + mylog.info("imagine_maximal_splice: Needed %d data dumps to get from z = %f to %f." % + (len(outputs), initial_redshift, final_redshift)) + + if filename is not None: + mylog.info("Writing redshift dump list to %s." % filename) + f = open(filename,'w') + for q, output in enumerate(outputs): + z_string = "%%s[%%d] = %%.%df" % decimals + f.write(("%s[%d] = %." + str(decimals) + "f\n") % (redshift_output_string, (q+start_index), output['redshift'])) + f.close() + + return outputs + + def create_cosmology_splice(self, minimal=True, deltaz_min=0.0, initial_redshift=None, final_redshift=None): + """ + Create list of datasets to be used for LightCones or LightRays. + :param minimal (bool): if True, the minimum number of datasets is used to connect the initial and final + redshift. If false, the list will contain as many entries as possible within the redshift + interval. Default: True. + :param deltaz_min (float): specifies the minimum delta z between consecutive datasets in the returned + list. Default: 0.0. + :param initial_redshift (float): the initial (highest) redshift in the cosmology splice list. If none + given, the highest redshift dataset present will be used. Default: None. + :param final_redshift (float): the final (lowest) redshift in the cosmology splice list. If none given, + the lowest redshift dataset present will be used. Default: None. + """ + + if initial_redshift is None: initial_redshift = self.InitialRedshift + if final_redshift is None: final_redshift = self.FinalRedshift + + # Calculate maximum delta z for each data dump. + self._calculate_deltaz_max() + + # Calculate minimum delta z for each data dump. + self._calculate_deltaz_min(deltaz_min=deltaz_min) + + cosmology_splice = [] + + # Use minimum number of datasets to go from z_i to z_f. + if minimal: + + z_Tolerance = 1e-3 + z = initial_redshift + + # fill redshift space with datasets + while ((z > final_redshift) and + (na.fabs(z - final_redshift) > z_Tolerance)): + + # For first data dump, choose closest to desired redshift. + if (len(cosmology_splice) == 0): + # Sort data outputs by proximity to current redsfhit. + self.allOutputs.sort(key=lambda obj:na.fabs(z - obj['redshift'])) + cosmology_splice.append(self.allOutputs[0]) + + # Move forward from last slice in stack until z > z_max. + else: + current_slice = cosmology_splice[-1] + while current_slice['next'] is not None and \ + (z < current_slice['next']['redshift'] or \ + na.abs(z - current_slice['next']['redshift']) < z_Tolerance): + current_slice = current_slice['next'] + + if current_slice is cosmology_splice[-1]: + final_redshift = cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax'] + mylog.error("Cosmology splice incomplete due to insufficient data outputs.") + break + else: + cosmology_splice.append(current_slice) + + z = cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax'] + + # Make light ray using maximum number of datasets (minimum spacing). + else: + # Sort data outputs by proximity to current redsfhit. + self.allOutputs.sort(key=lambda obj:na.fabs(initial_redshift - obj['redshift'])) + # For first data dump, choose closest to desired redshift. + cosmology_splice.append(self.allOutputs[0]) + + nextOutput = cosmology_splice[-1]['next'] + while (nextOutput is not None): + if (nextOutput['redshift'] <= final_redshift): + break + if ((cosmology_splice[-1]['redshift'] - nextOutput['redshift']) > cosmology_splice[-1]['deltazMin']): + cosmology_splice.append(nextOutput) + nextOutput = nextOutput['next'] + if (cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax']) > final_redshift: + mylog.error("Cosmology splice incomplete due to insufficient data outputs.") + final_redshift = cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax'] + + mylog.info("create_cosmology_splice: Used %d data dumps to get from z = %f to %f." % + (len(cosmology_splice),initial_redshift,final_redshift)) + + self.allOutputs.sort(key=lambda obj: obj['time']) + return cosmology_splice + + def get_data_by_redshift(self, redshifts, tolerance=None): + """ + : param redshifts: a list of redshifts. + : tolerance: if not None, do not return a dataset unless the redshift is within the tolerance value. + Get datasets for a list of redshifts. + """ + + redshifts = ensure_list(redshifts) + my_datasets = [] + for redshift in redshifts: + self.allOutputs.sort(key=lambda obj:na.fabs(redshift - obj['redshift'])) + if (tolerance is None or na.abs(redshift - self.allOutputs[0]['redshift']) <= tolerance) \ + and self.allOutputs[0] not in my_datasets: + my_datasets.append(self.allOutputs[0]) + else: + mylog.error("No dataset added for z = %f." % redshift) + + self.allOutputs.sort(key=lambda obj: obj['time']) + return my_datasets + + def get_data_by_time(self, times, tolerance=None): + """ + : param redshifts: a list of times. + : tolerance: if not None, do not return a dataset unless the redshift is within the tolerance value. + Get datasets for a list of times. + """ + + times = ensure_list(times) + my_datasets = [] + for my_time in times: + self.allOutputs.sort(key=lambda obj:na.fabs(my_time - obj['time'])) + if (tolerance is None or na.abs(my_time - self.allOutputs[0]['time']) <= tolerance) \ + and self.allOutputs[0] not in my_datasets: + my_datasets.append(self.allOutputs[0]) + else: + mylog.error("No dataset added for z = %f." % my_time) + + self.allOutputs.sort(key=lambda obj: obj['time']) + return my_datasets + + def _calculate_deltaz_max(self): + "Calculate delta z that corresponds to full box length going from z to (z - delta z)." + + d_Tolerance = 1e-4 + max_Iterations = 100 + + targetDistance = self.enzoParameters['CosmologyComovingBoxSize'] + + for output in self.allOutputs: + z = output['redshift'] + + # Calculate delta z that corresponds to the length of the box at a given redshift. + # Use Newton's method to calculate solution. + z1 = z + z2 = z1 - 0.1 # just an initial guess + distance1 = 0.0 + iteration = 1 + + # Convert comoving radial distance into Mpc / h, since that's how box size is stored. + distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] + + while ((na.fabs(distance2-targetDistance)/distance2) > d_Tolerance): + m = (distance2 - distance1) / (z2 - z1) + z1 = z2 + distance1 = distance2 + z2 = ((targetDistance - distance2) / m) + z2 + distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] + iteration += 1 + if (iteration > max_Iterations): + mylog.error("calculate_deltaz_max: Warning - max iterations exceeded for z = %f (delta z = %f)." % + (z,na.fabs(z2-z))) + break + output['deltazMax'] = na.fabs(z2-z) + + def _calculate_deltaz_min(self, deltaz_min=0.0): + "Calculate delta z that corresponds to a single top grid pixel going from z to (z - delta z)." + + d_Tolerance = 1e-4 + max_Iterations = 100 + + targetDistance = self.enzoParameters['CosmologyComovingBoxSize'] / self.enzoParameters['TopGridDimensions'][0] + + for output in self.allOutputs: + z = output['redshift'] + + # Calculate delta z that corresponds to the length of a top grid pixel at a given redshift. + # Use Newton's method to calculate solution. + z1 = z + z2 = z1 - 0.01 # just an initial guess + distance1 = 0.0 + iteration = 1 + + # Convert comoving radial distance into Mpc / h, since that's how box size is stored. + distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] + + while ((na.fabs(distance2 - targetDistance) / distance2) > d_Tolerance): + m = (distance2 - distance1) / (z2 - z1) + z1 = z2 + distance1 = distance2 + z2 = ((targetDistance - distance2) / m) + z2 + distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] + iteration += 1 + if (iteration > max_Iterations): + mylog.error("calculate_deltaz_max: Warning - max iterations exceeded for z = %f (delta z = %f)." % + (z,na.fabs(z2-z))) + break + # Use this calculation or the absolute minimum specified by the user. + output['deltazMin'] = max(na.fabs(z2-z),deltaz_min) + +EnzoParameterDict = {"CosmologyOmegaMatterNow": float, + "CosmologyOmegaLambdaNow": float, + "CosmologyHubbleConstantNow": float, + "CosmologyInitialRedshift": float, + "CosmologyFinalRedshift": float, + "ComovingCoordinates": int, + "InitialTime": float, + "StopTime": float, + "TopGridDimensions": float, + "dtDataDump": float, + "RedshiftDumpName": str, + "RedshiftDumpDir": str, + "DataDumpName": str, + "DataDumpDir": str, + "GlobalDir" : str} + +def __deltaz_forward(cosmology, z, target_distance): + "Calculate deltaz corresponding to moving a comoving distance starting from some redshift." + + d_Tolerance = 1e-4 + max_Iterations = 100 + + # Calculate delta z that corresponds to the length of the box at a given redshift. + # Use Newton's method to calculate solution. + z1 = z + z2 = z1 - 0.1 # just an initial guess + distance1 = 0.0 + iteration = 1 + + # Convert comoving radial distance into Mpc / h, since that's how box size is stored. + distance2 = cosmology.ComovingRadialDistance(z2,z) * cosmology.HubbleConstantNow / 100.0 + + while ((na.fabs(distance2-target_distance)/distance2) > d_Tolerance): + m = (distance2 - distance1) / (z2 - z1) + z1 = z2 + distance1 = distance2 + z2 = ((target_distance - distance2) / m) + z2 + distance2 = cosmology.ComovingRadialDistance(z2,z) * cosmology.HubbleConstantNow / 100.0 + iteration += 1 + if (iteration > max_Iterations): + mylog.error("deltaz_forward: Warning - max iterations exceeded for z = %f (delta z = %f)." % + (z,na.fabs(z2-z))) + break + return na.fabs(z2-z) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/simulation_handler/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/simulation_handler/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('simulation_handler',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/spectral_integrator/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/spectral_integrator/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,33 @@ +""" +API for spectral_integrator + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .spectral_frequency_integrator import \ + SpectralFrequencyIntegrator, \ + create_table_from_textfiles diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/spectral_integrator/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/spectral_integrator/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('spectral_integrator',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,96 @@ +""" +Integrator classes to deal with interpolation and integration of input spectral +bins. Currently only supports Cloudy-style data. + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +from yt.funcs import * +from yt.utilities.linear_interpolators import \ + UnilinearInterpolator, \ + BilinearInterpolator, \ + TrilinearInterpolator + +class SpectralFrequencyIntegrator(object): + def __init__(self, table, field_names, + bounds, ev_bounds): + """ + From a table, interpolate over field_names to get resultant luminosity. + Table must be of the style such that it is ordered by + ``[field_names[0], field_names[1], ev]`` + """ + self.table = table + self.field_names = field_names + + self.bounds = bounds + self.ev_bounds = ev_bounds + self.ev_vals = na.logspace(ev_bounds[0], ev_bounds[1], table.shape[-1]) + + def _get_interpolator(self, ev_min, ev_max): + """ + Integrates from ev_min to ev_max and returns an interpolator. + """ + e_is, e_ie = na.digitize([ev_min, ev_max], self.ev_vals) + bin_table = na.trapz(self.table[...,e_is-1:e_ie], + 2.41799e17* + (self.ev_vals[e_is:e_ie+1]-self.ev_vals[e_is-1:e_is]), + axis=-1) + bin_table = na.log10(bin_table.clip(1e-80,bin_table.max())) + return BilinearFieldInterpolator( + bin_table, self.bounds, self.field_names[:], + truncate=True) + + def add_frequency_bin_field(self, ev_min, ev_max): + """ + Add a new field to the FieldInfoContainer, which is an + integrated bin from *ev_min* to *ev_max*. + + Returns the name of the new field. + """ + interp = self._get_interpolator(ev_min, ev_max) + name = "XRay_%s_%s" % (ev_min, ev_max) + def frequency_bin_field(field, data): + dd = {'NumberDensity' : na.log10(data["NumberDensity"]), + 'Temperature' : na.log10(data["Temperature"])} + return 10**interp(dd) + add_field(name, function=frequency_bin_field, + projection_conversion="cm", + units=r"\rm{ergs}\/\rm{cm}^{-3}\/\rm{s}^{-1}", + projected_units=r"\rm{ergs}\/\rm{cm}^{-2}\/\rm{s}^{-1}") + return name + +def create_table_from_textfiles(pattern, rho_spec, e_spec, T_spec): + """ + This accepts a CLOUDY text file of emissivities and constructs an + interpolation table for spectral integration. + """ + rho_n_bins, rho_min, rho_max = rho_spec + e_n_bins, e_min, e_max = e_spec + T_n_bins, T_min, T_max = T_spec + # The second one is the fast-varying one + rho_is, e_is = na.mgrid[0:rho_n_bins,0:e_n_bins] + table = na.zeros((rho_n_bins, T_n_bins, e_n_bins), dtype='float64') + mylog.info("Parsing Cloudy files") + for i,ri,ei in zip(range(rho_n_bins*e_n_bins), rho_is.ravel(), e_is.ravel()): + table[ri,:,ei] = [float(l.split()[-1]) for l in open(pattern%(i+1)) if l[0] != "#"] + return table + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/star_analysis/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/star_analysis/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,33 @@ +""" +API for star_analysis + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .sfr_spectrum import \ + StarFormationRate, \ + SpectrumBuilder diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/star_analysis/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/star_analysis/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('star_analysis',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/star_analysis/sfr_spectrum.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/star_analysis/sfr_spectrum.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,476 @@ +""" +StarAnalysis - Functions to analyze stars. + +Author: Stephen Skory +Affiliation: UC San Diego / CASS +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 Stephen Skory (and others). 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 . +""" + +import numpy as na +import h5py +import math, itertools + +from yt.funcs import * +from yt.utilities.cosmology import \ + Cosmology, \ + EnzoCosmology + +YEAR = 3.155693e7 # sec / year +LIGHT = 2.997925e10 # cm / s + +class StarFormationRate(object): + def __init__(self, pf, data_source=None, star_mass=None, + star_creation_time=None, volume=None, bins=300): + r"""Calculates the star formation rate for a given population of + star particles. + + Parameters + ---------- + pf : EnzoStaticOutput object + data_source : AMRRegion object, optional + The region from which stars are extracted for analysis. If this + is not supplied, the next three must be, otherwise the next + three do not need to be specified. + star_mass : Ordered array or list of floats + The mass of the stars to be analyzed in units of Msun. + star_creation_time : Ordered array or list of floats + The creation time for the stars in code units. + volume : Float + The volume of the region for the specified list of stars. + bins : Integer + The number of time bins used for binning the stars. Default = 300. + + Examples + -------- + + >>> pf = load("RedshiftOutput0000") + >>> sp = pf.h.sphere([0.5,0.5,0.5], [.1]) + >>> sfr = StarFormationRate(pf, sp) + """ + self._pf = pf + self._data_source = data_source + self.star_mass = star_mass + self.star_creation_time = star_creation_time + self.volume = volume + self.bin_count = bins + # Check to make sure we have the right set of informations. + if data_source is None: + if self.star_mass is None or self.star_creation_time is None or \ + self.volume is None: + mylog.error( + """ + If data_source is not provided, all of these paramters need to be set: + star_mass (array, Msun), + star_creation_time (array, code units), + volume (float, Mpc**3). + """) + return None + self.mode = 'provided' + else: + self.mode = 'data_source' + # Set up for time conversion. + self.cosm = EnzoCosmology(HubbleConstantNow = + (100.0 * self._pf.hubble_constant), + OmegaMatterNow = self._pf.omega_matter, + OmegaLambdaNow = self._pf.omega_lambda, + InitialRedshift = self._pf['CosmologyInitialRedshift']) + # Find the time right now. + self.time_now = self.cosm.ComputeTimeFromRedshift( + self._pf.current_redshift) # seconds + # Build the distribution. + self.build_dist() + + def build_dist(self): + """ + Build the data for plotting. + """ + # Pick out the stars. + if self.mode == 'data_source': + ct = self._data_source["creation_time"] + ct_stars = ct[ct > 0] + mass_stars = self._data_source["ParticleMassMsun"][ct > 0] + elif self.mode == 'provided': + ct_stars = self.star_creation_time + mass_stars = self.star_mass + # Find the oldest stars in units of code time. + tmin= min(ct_stars) + # Multiply the end to prevent numerical issues. + self.time_bins = na.linspace(tmin*0.99, self._pf.current_time, + num = self.bin_count + 1) + # Figure out which bins the stars go into. + inds = na.digitize(ct_stars, self.time_bins) - 1 + # Sum up the stars created in each time bin. + self.mass_bins = na.zeros(self.bin_count + 1, dtype='float64') + for index in na.unique(inds): + self.mass_bins[index] += sum(mass_stars[inds == index]) + # Calculate the cumulative mass sum over time by forward adding. + self.cum_mass_bins = self.mass_bins.copy() + for index in xrange(self.bin_count): + self.cum_mass_bins[index+1] += self.cum_mass_bins[index] + # We will want the time taken between bins. + self.time_bins_dt = self.time_bins[1:] - self.time_bins[:-1] + + def write_out(self, name="StarFormationRate.out"): + r"""Write out the star analysis to a text file *name*. The columns are in + order. + + The columns in the output file are: + 1. Time (yrs) + 2. Look-back time (yrs) + 3. Redshift + 4. Star formation rate in this bin per year (Msol/yr) + 5. Star formation rate in this bin per year per Mpc**3 (Msol/yr/Mpc**3) + 6. Stars formed in this time bin (Msol) + 7. Cumulative stars formed up to this time bin (Msol) + + Parameters + ---------- + name : String + The name of the file to write to. Default = StarFormationRate.out. + + Examples + -------- + >>> sfr.write_out("stars-SFR.out") + """ + fp = open(name, "w") + if self.mode == 'data_source': + try: + vol = self._data_source.volume('mpc') + except AttributeError: + # If we're here, this is probably a HOPHalo object, and we + # can get the volume this way. + ds = self._data_source.get_sphere() + vol = ds.volume('mpc') + elif self.mode == 'provided': + vol = self.volume + tc = self._pf["Time"] + # Use the center of the time_bin, not the left edge. + fp.write("#time\tlookback\tredshift\tMsol/yr\tMsol/yr/Mpc3\tMsol\tcumMsol\t\n") + for i, time in enumerate((self.time_bins[1:] + self.time_bins[:-1])/2.): + line = "%1.5e %1.5e %1.5e %1.5e %1.5e %1.5e %1.5e\n" % \ + (time * tc / YEAR, # Time + (self.time_now - time * tc)/YEAR, # Lookback time + self.cosm.ComputeRedshiftFromTime(time * tc), # Redshift + self.mass_bins[i] / (self.time_bins_dt[i] * tc / YEAR), # Msol/yr + self.mass_bins[i] / (self.time_bins_dt[i] * tc / YEAR) / vol, # Msol/yr/vol + self.mass_bins[i], # Msol in bin + self.cum_mass_bins[i]) # cumulative + fp.write(line) + fp.close() + +CHABRIER = { +"Z0001" : "bc2003_hr_m22_chab_ssp.ised.h5", #/* 0.5% */ +"Z0004" : "bc2003_hr_m32_chab_ssp.ised.h5", #/* 2% */ +"Z004" : "bc2003_hr_m42_chab_ssp.ised.h5", #/* 20% */ +"Z008" : "bc2003_hr_m52_chab_ssp.ised.h5", #/* 40% */ +"Z02" : "bc2003_hr_m62_chab_ssp.ised.h5", #/* solar; 0.02 */ +"Z05" : "bc2003_hr_m72_chab_ssp.ised.h5" #/* 250% */ +} + +SALPETER = { +"Z0001" : "bc2003_hr_m22_salp_ssp.ised.h5", #/* 0.5% */ +"Z0004" : "bc2003_hr_m32_salp_ssp.ised.h5", #/* 2% */ +"Z004" : "bc2003_hr_m42_salp_ssp.ised.h5", #/* 20% */ +"Z008" : "bc2003_hr_m52_salp_ssp.ised.h5", #/* 40% */ +"Z02" : "bc2003_hr_m62_salp_ssp.ised.h5", #/* solar; 0.02 */ +"Z05" : "bc2003_hr_m72_salp_ssp.ised.h5" #/* 250% */ +} + +Zsun = 0.02 + +#/* dividing line of metallicity; linear in log(Z/Zsun) */ +METAL1 = 0.01 # /* in units of Z/Zsun */ +METAL2 = 0.0632 +METAL3 = 0.2828 +METAL4 = 0.6325 +METAL5 = 1.5811 +METALS = na.array([METAL1, METAL2, METAL3, METAL4, METAL5]) + +# Translate METALS array digitize to the table dicts +MtoD = na.array(["Z0001", "Z0004", "Z004", "Z008", "Z02", "Z05"]) + +""" +This spectrum code is based on code from Ken Nagamine, converted from C to Python. +I've also reversed the order of elements in the flux arrays to be in C-ordering, +for faster memory access. +""" + +class SpectrumBuilder(object): + def __init__(self, pf, bcdir="", model="chabrier"): + r"""Initialize the data to build a summed flux spectrum for a + collection of stars using the models of Bruzual & Charlot (2003). + This function loads the necessary data tables into memory and + must be called before analyzing any star particles. + + Parameters + ---------- + pf : EnzoStaticOutput object + bcdir : String + Path to directory containing Bruzual & Charlot h5 fit files. + model : String + Choice of Initial Metalicity Function model, 'chabrier' or + 'salpeter'. Default = 'chabrier'. + + Examples + -------- + >>> pf = load("RedshiftOutput0000") + >>> spec = SpectrumBuilder(pf, "/home/user/bc/", model="salpeter") + """ + self._pf = pf + self.bcdir = bcdir + + if model == "chabrier": + self.model = CHABRIER + elif model == "salpeter": + self.model = SALPETER + # Set up for time conversion. + self.cosm = EnzoCosmology(HubbleConstantNow = + (100.0 * self._pf.hubble_constant), + OmegaMatterNow = self._pf.omega_matter, + OmegaLambdaNow = self._pf.omega_lambda, + InitialRedshift = self._pf['CosmologyInitialRedshift']) + # Find the time right now. + self.time_now = self.cosm.ComputeTimeFromRedshift( + self._pf.current_redshift) # seconds + + # Read the tables. + self.read_bclib() + + def read_bclib(self): + """ + Read in the age and wavelength bins, and the flux bins for each + metallicity. + """ + self.flux = {} + for file in self.model: + fname = self.bcdir + "/" + self.model[file] + fp = h5py.File(fname, 'r') + self.age = fp["agebins"][:] # 1D floats + self.wavelength = fp["wavebins"][:] # 1D floats + self.flux[file] = fp["flam"][:,:] # 2D floats, [agebin, wavebin] + fp.close() + + def calculate_spectrum(self, data_source=None, star_mass=None, + star_creation_time=None, star_metallicity_fraction=None, + star_metallicity_constant=None, min_age=0.): + r"""For the set of stars, calculate the collective spectrum. + Attached to the output are several useful objects: + final_spec: The collective spectrum in units of flux binned in wavelength. + wavelength: The wavelength for the spectrum bins, in Angstroms. + total_mass: Total mass of all the stars. + avg_mass: Average mass of all the stars. + avg_metal: Average metallicity of all the stars. + + Parameters + ---------- + data_source : AMRRegion object, optional + The region from which stars are extracted for analysis. If this is + not specified, the next three parameters must be supplied. + star_mass : Array or list of floats + An array of star masses in Msun units. + star_creation_time : Array or list of floats + An array of star creation times in code units. + star_metallicity_fraction : Array or list of floats + An array of star metallicity fractions, in code + units (which is not Z/Zsun, rather just Z). + star_metallicity_constant : Float + If desired, override the star + metallicity fraction of all the stars to the given value. + min_age : Float + Removes young stars younger than this number (in years) + from the spectrum. Default: 0 (all stars). + + Examples + -------- + >>> sp = pf.h.sphere([0.5,0.5,0.5], [.1]) + >>> spec.calculate_spectrum(data_source=sp, min_age = 1.e6) + """ + # Initialize values + self.final_spec = na.zeros(self.wavelength.size, dtype='float64') + self._data_source = data_source + self.star_mass = star_mass + self.star_creation_time = star_creation_time + self.star_metal = star_metallicity_fraction + self.min_age = min_age + + # Check to make sure we have the right set of data. + if data_source is None: + if self.star_mass is None or self.star_creation_time is None or \ + (star_metallicity_fraction is None and star_metallicity_constant is None): + mylog.error( + """ + If data_source is not provided, all of these paramters need to be set: + star_mass (array, Msun), + star_creation_time (array, code units), + And one of: + star_metallicity_fraction (array, code units). + --OR-- + star_metallicity_constant (float, code units). + """) + return None + if star_metallicity_constant is not None: + self.star_metal = na.ones(self.star_mass.size, dtype='float64') * \ + star_metallicity_constant + else: + # Get the data we need. + ct = self._data_source["creation_time"] + self.star_creation_time = ct[ct > 0] + self.star_mass = self._data_source["ParticleMassMsun"][ct > 0] + if star_metallicity_constant is not None: + self.star_metal = na.ones(self.star_mass.size, dtype='float64') * \ + star_metallicity_constant + else: + self.star_metal = self._data_source["metallicity_fraction"][ct > 0] + # Fix metallicity to units of Zsun. + self.star_metal /= Zsun + # Age of star in years. + dt = (self.time_now - self.star_creation_time * self._pf['Time']) / YEAR + # Remove young stars + sub = dt > self.min_age + self.star_metal = self.star_metal[sub] + dt = dt[sub] + self.star_creation_time = self.star_creation_time[sub] + # Figure out which METALS bin the star goes into. + Mindex = na.digitize(self.star_metal, METALS) + # Replace the indices with strings. + Mname = MtoD[Mindex] + # Figure out which age bin this star goes into. + Aindex = na.digitize(dt, self.age) + # Ratios used for the interpolation. + ratio1 = (dt - self.age[Aindex-1]) / (self.age[Aindex] - self.age[Aindex-1]) + ratio2 = (self.age[Aindex] - dt) / (self.age[Aindex] - self.age[Aindex-1]) + # Sort the stars by metallicity and then by age, which should reduce + # memory access time by a little bit in the loop. + indexes = na.arange(self.star_metal.size) + sort = na.asarray([indexes[i] for i in na.lexsort([indexes, Aindex, Mname])]) + Mname = Mname[sort] + Aindex = Aindex[sort] + ratio1 = ratio1[sort] + ratio2 = ratio2[sort] + self.star_mass = self.star_mass[sort] + self.star_creation_time = self.star_creation_time[sort] + self.star_metal = self.star_metal[sort] + + # Interpolate the flux for each star, adding to the total by weight. + for star in itertools.izip(Mname, Aindex, ratio1, ratio2, self.star_mass): + # Pick the right age bin for the right flux array. + flux = self.flux[star[0]][star[1],:] + # Get the one just before the one above. + flux_1 = self.flux[star[0]][star[1]-1,:] + # interpolate in log(flux), linear in time. + int_flux = star[3] * na.log10(flux_1) + star[2] * na.log10(flux) + # Add this flux to the total, weighted by mass. + self.final_spec += na.power(10., int_flux) * star[4] + # Normalize. + self.total_mass = na.sum(self.star_mass) + self.avg_mass = na.mean(self.star_mass) + tot_metal = sum(self.star_metal * self.star_mass) + self.avg_metal = math.log10(tot_metal / self.total_mass / Zsun) + + # Below is an attempt to do the loop using vectors and matrices, + # however it doesn't appear to be much faster, probably due to all + # the gymnastics that have to be done to do element-by-element + # multiplication for matricies. + # I'm keeping it in here in case I come up with a more + # elegant way that actually is faster. +# for metal_name in MtoD: +# # Pick out our stars in this metallicity bin. +# select = (Mname == metal_name) +# A = Aindex[select] +# if A.size == 0: continue +# r1 = ratio1[select] +# r2 = ratio2[select] +# sm = self.star_mass[select] +# # From the flux array for this metal, and our selection, build +# # a new flux array just for the ages of these stars, in the +# # same order as the selection of stars. +# this_flux = na.matrix(self.flux[metal_name][A]) +# # Make one for the last time step for each star in the same fashion +# # as above. +# this_flux_1 = na.matrix(self.flux[metal_name][A-1]) +# # This is kind of messy, but we're going to multiply this_fluxes +# # by the appropriate ratios and add it together to do the +# # interpolation in log(flux) and linear in time. +# print r1.size +# r1 = na.matrix(r1.tolist()*self.wavelength.size).reshape(self.wavelength.size,r1.size).T +# r2 = na.matrix(r2.tolist()*self.wavelength.size).reshape(self.wavelength.size,r2.size).T +# print this_flux_1.shape, r1.shape +# int_flux = na.multiply(na.log10(this_flux_1),r1) \ +# + na.multiply(na.log10(this_flux),r2) +# # Weight the fluxes by mass. +# sm = na.matrix(sm.tolist()*self.wavelength.size).reshape(self.wavelength.size,sm.size).T +# int_flux = na.multiply(na.power(10., int_flux), sm) +# # Sum along the columns, converting back to an array, adding +# # to the full spectrum. +# self.final_spec += na.array(int_flux.sum(axis=0))[0,:] + + + def write_out(self, name="sum_flux.out"): + r"""Write out the summed flux to a file. + + The output file from this function has two columns: Wavelength + (Angstrom) and Flux (Luminosity per unit wavelength, L_sun Ang^-1, + L_sun = 3.826 * 10^33 ergs s^-1.). + + Parameters + ---------- + name : String + Name of file to write to. Default = "sum_flux.out" + + Examples + -------- + >>> spec.write_out("spec.out") + """ + fp = open(name, 'w') + for i, wave in enumerate(self.wavelength): + fp.write("%1.5e\t%1.5e\n" % (wave, self.final_spec[i])) + fp.close() + + def write_out_SED(self, name="sum_SED.out", flux_norm=5200.): + r"""Write out the summed SED to a file. The file has two columns: + 1) Wavelength (Angstrom) + 2) Relative flux normalized to the flux at *flux_norm*. + It also will attach to the SpectrumBuilder object + an array *f_nu* which is the normalized flux, + identical to the disk output. + + Parameters + ---------- + name : String + Name of file to write to. Default = "sum_SED.out" + flux_norm : Float + Wavelength of the flux to normalize the distribution against. + Default = 5200 Ang. + + Examples + -------- + >>> spec.write_out_SED(name = "SED.out", flux_norm = 6000.) + """ + # find the f_nu closest to flux_norm + fn_wavelength = na.argmin(abs(self.wavelength - flux_norm)) + f_nu = self.final_spec * na.power(self.wavelength, 2.) / LIGHT + # Normalize f_nu + self.f_nu = f_nu / f_nu[fn_wavelength] + # Write out. + fp = open(name, 'w') + for i, wave in enumerate(self.wavelength): + fp.write("%1.5e\t%1.5e\n" % (wave, self.f_nu[i])) + fp.close() + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/two_point_functions/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/two_point_functions/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,33 @@ +""" +API for two_point_functions + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .two_point_functions import \ + TwoPointFunctions, \ + FcnSet diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/two_point_functions/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/two_point_functions/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('two_point_functions',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/analysis_modules/two_point_functions/two_point_functions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/analysis_modules/two_point_functions/two_point_functions.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,856 @@ +""" +Two Point Functions Framework. + +Author: Stephen Skory +Affiliation: UCSD Physics/CASS +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2010 Stephen Skory. 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 . +""" + +from yt.mods import * +#from yt.utilities.math_utils import * +from yt.utilities.performance_counters import yt_counters, time_function +from yt.utilities.parallel_tools.parallel_analysis_interface import ParallelAnalysisInterface, parallel_blocking_call, parallel_root_only + +try: + from yt.extensions.kdtree import * +except ImportError: + mylog.debug("The Fortran kD-Tree did not import correctly.") + +import math, sys, itertools, inspect, types, time +from collections import defaultdict + +sep = 12 + +class TwoPointFunctions(ParallelAnalysisInterface): + def __init__(self, pf, fields, left_edge=None, right_edge=None, + total_values=1000000, comm_size=10000, length_type="lin", + length_number=10, length_range=None, vol_ratio = 1, + salt=0): + r""" Initialize a two point functions object. + + Parameters + ---------- + total_values : Integer + How many total (global) pair calculations to run for each of the + functions specified. Default: 1000000. + comm_size : Integer + How entries are sent during communication. Default: 10000. + length_type : String + Controls the even spacing of the rulers lengths in + logarithmic or linear space, set by "log" or "lin", respectively. + Default: "lin". + length_number : Integer + Sets how many lengths to create, evenly spaced by the above + parameter. Default: 10. + length_range : Float + A min/max pair for the range of values to search the over + the simulational volume. Default: [sqrt(3)dx, 1/2*shortest box edge], + where dx is the smallest grid cell size. + vol_ratio : Integer + How to multiply-assign subvolumes to the parallel + tasks. This number must be an integer factor of the total number of tasks or + very bad things will happen. The default value of 1 will assign one task + to each subvolume, and there will be an equal number of subvolumes as tasks. + A value of 2 will assign two tasks to each subvolume and there will be + one-half as many subvolumes as tasks. + A value equal to the number of parallel tasks will result in each task + owning a complete copy of all the fields data, meaning each task will be + operating on the identical full volume. + Setting it to -1 will automatically adjust it such that each task + owns the entire volume. Default = 1. + salt : Integer + A number that will be added to the random number generator + seed. Use this if a different random series of numbers is desired when + keeping everything else constant from this set: (MPI task count, + number of ruler lengths, ruler min/max, number of functions, + number of point pairs per ruler length). Default = 0. + + Examples + -------- + >>> tpf = TwoPointFunctions(pf, ["x-velocity", "y-velocity", "z-velocity"], + ... total_values=1e5, comm_size=10000, + ... length_number=10, length_range=[1./128, .5], + ... length_type="log") + """ + try: + fKD + except NameError: + raise ImportError("You need to install the Forthon kD-Tree") + self._fsets = [] + self.fields = fields + # MPI stuff. + self.size = self._mpi_get_size() + self.mine = self._mpi_get_rank() + self.vol_ratio = vol_ratio + if self.vol_ratio == -1: + self.vol_ratio = self.size + self.total_values = int(total_values / self.size) + # For communication. + self.recv_hooks = [] + self.send_hooks = [] + self.done_hooks = [] + self.comm_size = min(int(comm_size), self.total_values) + self.pf = pf + self.nlevels = pf.h.max_level + self.period = self.pf.domain_right_edge - self.pf.domain_left_edge + self.min_edge = min(self.period) + self.hierarchy = pf.h + self.center = (pf.domain_right_edge + pf.domain_left_edge)/2.0 + # Figure out the range of ruler lengths. + if length_range == None: + length_range = [math.sqrt(3) * self.pf.h.get_smallest_dx(), + self.min_edge/2.] + else: + if len(length_range) != 2: + raise ValueError("length_range must have two values.") + if length_range[1] <= length_range[0]: + raise ValueError("length_range[1] must be larger than length_range[0]") + if length_range[1] > self.min_edge/2.: + length_range[1] = self.min_edge/2. + mylog.info("Automatically adjusting length_range[1] to half the shortest box edge.") + if length_range[0] == -1 or length_range[0] == -1.: + mylog.info("Automatically adjusting length_range[0] to %1.5e." % \ + (math.sqrt(3) * self.pf.h.get_smallest_dx())) + length_range[0] = math.sqrt(3) * self.pf.h.get_smallest_dx() + # Make the list of ruler lengths. + if length_type == "lin": + self.lengths = na.linspace(length_range[0], length_range[1], + length_number) + elif length_type == "log": + self.lengths = na.logspace(math.log10(length_range[0]), + math.log10(length_range[1]), length_number) + else: + # Something went wrong. + raise SyntaxError("length_type is either \"lin\" or \"log\".") + # Subdivide the volume. + if not left_edge or not right_edge: + self.left_edge = self.pf.domain_left_edge + self.right_edge = self.pf.domain_right_edge + padded, self.LE, self.RE, self.ds = self._partition_hierarchy_3d(padding=0., + rank_ratio = self.vol_ratio) + else: + self.left_edge = left_edge + self.right_edge = right_edge + # We do this twice, first with no 'buffer' to get the unbuffered + # self.LE/RE, and then second to get a buffered self.ds. + padded, self.LE, self.RE, temp = \ + self._partition_region_3d(left_edge, right_edge, + rank_ratio=self.vol_ratio) + padded, temp, temp, self.ds = \ + self._partition_region_3d(left_edge - self.lengths[-1], \ + right_edge + self.lengths[-1], rank_ratio=self.vol_ratio) + mylog.info("LE %s RE %s %s" % (str(self.LE), str(self.RE), str(self.ds))) + self.width = self.ds.right_edge - self.ds.left_edge + self.mt = na.random.mtrand.RandomState(seed = 1234 * self.mine + salt) + + def add_function(self, function, out_labels, sqrt, corr_norm=None): + r"""Add a function to the list that will be evaluated at the + generated pairs of points. + + Parameters + ---------- + function : Function + The two point function of the form fcn(a, b, r1, r2, vec). + out_labels : List of strings + A list of strings labeling the outputs of the function. + sqrt : List of booleans + A list of booleans which when True will square-root the corresponding + element of the output in the text output (write_out_means()). + corr_norm : Float + Used when calculating two point correlations. If set, the output + of the function is divided by this number. Default = None. + + Examples + -------- + >>> f1 = tpf.add_function(function=rms_vel, out_labels=['RMSvdiff'], + ... sqrt=[True]) + """ + fargs = inspect.getargspec(function) + if len(fargs.args) != 5: + raise SyntaxError("The function %s needs five arguments." %\ + function.__name__) + out_labels = list(out_labels) + if len(out_labels) < 1: + raise SyntaxError("Please specify at least one out_labels for function %s." %\ + function.__name__) + sqrt = list(sqrt) + if len(sqrt) != len(out_labels): + raise SyntaxError("Please have the same number of elements in out_labels as in sqrt for function %s." %\ + function.__name__) + self._fsets.append(FcnSet(self, function, self.min_edge, + out_labels, sqrt,corr_norm)) + return self._fsets[-1] + + def __getitem__(self, key): + return self._fsets[key] + + def run_generator(self): + r"""After all the functions have been added, run the generator. + + Examples + -------- + >>> tpf.run_generator() + """ + yt_counters("run_generator") + # We need a function! + if len(self._fsets) == 0: + mylog.error("You need to add at least one function!") + return None + # Do all the startup tasks to get the grid points. + if self.nlevels == 0: + yt_counters("build_sort") + self._build_sort_array() + self.sort_done = False + yt_counters("build_sort") + else: + yt_counters("init_kd_tree") + self._init_kd_tree() + self.sort_done = True + yt_counters("init_kd_tree") + # Store the fields. + self.stored_fields = {} + yt_counters("getting data") + for field in self.fields: + self.stored_fields[field] = self.ds[field].copy() + self.ds.clear_data() + # If the arrays haven't been sorted yet and need to be, do that. + if not self.sort_done: + for field in self.fields: + self.stored_fields[field] = self.stored_fields[field][self.sort] + del self.sort + self.sort_done = True + yt_counters("getting data") + self._build_fields_vals() + yt_counters("big loop over lengths") + t_waiting = 0. + for bigloop, length in enumerate(self.lengths): + self._build_points_array() + if self.mine == 0: + mylog.info("Doing length %1.5e" % length) + # Things stop when this value below equals total_values. + self.generated_points = 0 + self.gen_array = na.zeros(self.size, dtype='int64') + self.comm_cycle_count = 0 + self.final_comm_cycle_count = 0 + self.sent_done = False + self._setup_done_hooks_on_root() + # While everyone else isn't done or I'm not done, we loop. + while self._should_cycle(): + self._setup_recv_arrays() + self._send_arrays() + t0 = time.time() + self._mpi_Request_Waitall(self.send_hooks) + self._mpi_Request_Waitall(self.recv_hooks) + t1 = time.time() + t_waiting += (t1-t0) + if (self.recv_points < -1.).any() or (self.recv_points > 1.).any(): # or \ + #(na.abs(na.log10(na.abs(self.recv_points))) > 20).any(): + raise ValueError("self.recv_points is no good!") + self.points = self.recv_points.copy() + self.fields_vals = self.recv_fields_vals.copy() + self.gen_array = self.recv_gen_array.copy() + self._eval_points(length) + self.gen_array[self.mine] = self.generated_points + self.comm_cycle_count += 1 + if self.generated_points == self.total_values: + self._send_done_to_root() + if self.mine == 0: + mylog.info("Length (%d of %d) %1.5e took %d communication cycles to complete." % \ + (bigloop+1, len(self.lengths), length, self.comm_cycle_count)) + yt_counters("big loop over lengths") + if self.nlevels >= 1: + del fKD.pos, fKD.qv_many, fKD.nn_tags + free_tree(0) # Frees the kdtree object. + yt_counters("allsum") + self._allsum_bin_hits() + mylog.info("Spent %f seconds waiting for communication." % t_waiting) + yt_counters("allsum") + yt_counters("run_generator") + + def _init_kd_tree(self): + """ + Builds the kd tree of grid center points. + """ + # Grid cell centers. + mylog.info("Multigrid: Building kD-Tree.") + xp = self.ds["x"] + yp = self.ds["y"] + zp = self.ds["z"] + fKD.pos = na.asfortranarray(na.empty((3,xp.size), dtype='float64')) + fKD.pos[0, :] = xp[:] + fKD.pos[1, :] = yp[:] + fKD.pos[2, :] = zp[:] + fKD.nn = 1 + fKD.sort = False + fKD.rearrange = True + create_tree(0) + + def _build_sort_array(self): + """ + When running on a unigrid simulation, the kD tree isn't necessary. + But we need to ensure that the points are sorted in the usual manner + allowing values to be found via array indices. + """ + mylog.info("Unigrid: finding cell centers.") + xp = self.ds["x"] + yp = self.ds["y"] + zp = self.ds["z"] + self.sizes = [na.unique(xp).size, na.unique(yp).size, na.unique(zp).size] + self.sort = na.lexsort([zp, yp, xp]) + del xp, yp, zp + self.ds.clear_data() + + def _build_fields_vals(self): + """ + Builds an array to store the field values array. + """ + self.fields_vals = na.empty((self.comm_size, len(self.fields)*2), \ + dtype='float64') + # At the same time build a dict to label the columns. + self.fields_columns = {} + for i,field in enumerate(self.fields): + self.fields_columns[field] = i + + def _build_points_array(self): + """ + Initializes the array that contains the random points as all negatives + to start with. + """ + self.points = na.ones((self.comm_size, 6), dtype='float64') * -1.0 + + def _setup_done_hooks_on_root(self): + """ + Opens non-blocking receives on root pointing to all the other tasks + """ + if self.mine != 0: + return + self.recv_done = {} + for task in xrange(self.size): + if task == self.mine: continue + self.recv_done[task] = na.zeros(1, dtype='int64') + self.done_hooks.append(self._mpi_Irecv_long(self.recv_done[task], \ + task, tag=15)) + + def _send_done_to_root(self): + """ + Tell the root process that I'm done. + """ + # If I've already done this, don't do it again. + if self.sent_done: return + if self.mine !=0: + # I send when I *think* things should finish. + self.send_done = na.ones(1, dtype='int64') * \ + (self.size / self.vol_ratio -1) + self.comm_cycle_count + self.done_hooks.append(self._mpi_Isend_long(self.send_done, \ + 0, tag=15)) + else: + # As root, I need to mark myself! + self.recv_done[0] = na.ones(1, dtype='int64') * \ + (self.size / self.vol_ratio -1) + self.comm_cycle_count + self.sent_done = True + + def _should_cycle(self): + """ + Determine if I should continue cycling the communication. + """ + if self.mine == 0: + # If other tasks aren't finished, this will return False. + status = self._mpi_Request_Testall(self.done_hooks) + # Convolve this with with root's status. + status = status * (self.generated_points == self.total_values) + if status == 1: + # If they are all finished, meaning Testall returns True, + # and root has made its points, we find + # the biggest value in self.recv_done and stop there. + status = max(self.recv_done.values()) + else: + status = 0 + # Broadcast the status from root - we stop only if root thinks we should + # stop. + status = self._mpi_bcast_pickled(status) + if status == 0: return True + if self.comm_cycle_count < status: + return True + # If we've come this far, we're done. + return False + + def _setup_recv_arrays(self): + """ + Creates the recv buffers and calls a non-blocking MPI receive pointing + to the left-hand neighbor. + """ + self.recv_points = na.ones((self.comm_size, 6), dtype='float64') * -1. + self.recv_fields_vals = na.zeros((self.comm_size, len(self.fields)*2), \ + dtype='float64') + self.recv_gen_array = na.zeros(self.size, dtype='int64') + self.recv_hooks.append(self._mpi_Irecv_double(self.recv_points, \ + (self.mine-1)%self.size, tag=10)) + self.recv_hooks.append(self._mpi_Irecv_double(self.recv_fields_vals, \ + (self.mine-1)%self.size, tag=20)) + self.recv_hooks.append(self._mpi_Irecv_long(self.recv_gen_array, \ + (self.mine-1)%self.size, tag=40)) + + def _send_arrays(self): + """ + Send the data arrays to the right-hand neighbor. + """ + self.send_hooks.append(self._mpi_Isend_double(self.points,\ + (self.mine+1)%self.size, tag=10)) + self.send_hooks.append(self._mpi_Isend_double(self.fields_vals,\ + (self.mine+1)%self.size, tag=20)) + self.send_hooks.append(self._mpi_Isend_long(self.gen_array, \ + (self.mine+1)%self.size, tag=40)) + + def _allsum_bin_hits(self): + """ + Add up the hits to all the bins globally for all functions. + """ + for fset in self._fsets: + fset.too_low = self._mpi_allsum(fset.too_low) + fset.too_high = self._mpi_allsum(fset.too_high) + fset.binned = {} + if self.mine == 0: + mylog.info("Function %s had values out of range for these fields:" % \ + fset.function.__name__) + for i,field in enumerate(fset.out_labels): + mylog.info("Field %s had %d values too high and %d too low that were not binned." % \ + (field, fset.too_high[i], fset.too_low[i])) + for length in self.lengths: + fset.length_bin_hits[length] = \ + self._mpi_Allsum_long(fset.length_bin_hits[length]) + # Find out how many were successfully binned. + fset.binned[length] = fset.length_bin_hits[length].sum() + # Normalize the counts. + fset.length_bin_hits[length] = \ + fset.length_bin_hits[length].astype('float64') / \ + fset.binned[length] + # Return it to its original shape. + fset.length_bin_hits[length] = \ + fset.length_bin_hits[length].reshape(fset.bin_number) + + def _pick_random_points(self, length, size): + """ + Picks out size random pairs separated by length *length*. + """ + # First make random points inside this subvolume. + r1 = na.empty((size,3), dtype='float64') + for dim in range(3): + r1[:,dim] = self.mt.uniform(low=self.ds.left_edge[dim], + high=self.ds.right_edge[dim], size=size) + # Next we find the second point, determined by a random + # theta, phi angle. + theta = self.mt.uniform(low=0, high=2.*math.pi, size=size) + phi = self.mt.uniform(low=-math.pi/2., high=math.pi/2., size=size) + r2 = na.empty((size,3), dtype='float64') + r2[:,0] = r1[:,0] + length * na.cos(theta) * na.cos(phi) + r2[:,1] = r1[:,1] + length * na.sin(theta) * na.cos(phi) + r2[:,2] = r1[:,2] + length * na.sin(phi) + # Reflect so it's inside the (full) volume. + r2 %= self.period + return (r1, r2) + + def _find_nearest_cell(self, points): + """ + Finds the closest grid cell for each point in a vectorized manner. + """ + if self.nlevels == 0: + pos = (points - self.ds.left_edge) / self.width + n = (self.sizes[2] * pos[:,2]).astype('int32') + n += self.sizes[2] * (self.sizes[1] * pos[:,1]).astype('int32') + n += self.sizes[2] * self.sizes[1] * (self.sizes[0] * pos[:,0]).astype('int32') + else: + fKD.qv_many = points.T + fKD.nn_tags = na.asfortranarray(na.empty((1, points.shape[0]), dtype='int64')) + find_many_nn_nearest_neighbors() + # The -1 is for fortran counting. + n = fKD.nn_tags[0,:] - 1 + return n + + def _get_fields_vals(self, points): + """ + Given points, return the values for the fields we need for those + points. + """ + # First find the grid data index field. + indices = self._find_nearest_cell(points) + results = na.empty((len(indices), len(self.fields)), dtype='float64') + # Put the field values into the columns of results. + for field in self.fields: + col = self.fields_columns[field] + results[:, col] = self.stored_fields[field][indices] + return results + + + def _eval_points(self, length): + # We need to loop over the points array at least once. Further + # iterations only happen if we have added new points to the array, + # but not as many as we want to, so we need to check again to see if + # we can put more points into the buffer. + added_points = True + while added_points: + # If we need to, add more points to the points array. + if self.generated_points < self.total_values: + # Look for 'empty' slots to put in new pairs. + select = (self.points[:,0] < 0) + ssum = select.sum() + # We'll generate only as many points as we need to/can. + size = min(ssum, self.total_values - self.generated_points) + (new_r1,new_r2) = self._pick_random_points(length, size) + self.generated_points += size + # If size != select.sum(), we need to pad the end of new_r1/r2 + # which is what is effectively happening below. + newpoints = na.ones((ssum, 6), dtype='float64') * -1. + newpoints[:size,:3] = new_r1 + newpoints[:size,3:] = new_r2 + # Now we insert them into self.points. + self.points[select] = newpoints + else: + added_points = False + + # If we have an empty buffer here, we can skip everything below. + if (self.points < 0).all(): + added_points = False # Not strictly required, but clearer. + break + + # Now we have a points array that is either full of unevaluated points, + # or I don't need to make any new points and I'm just processing the + # array. Start by finding the indices of the points I own. + self.points.shape = (self.comm_size*2, 3) # Doesn't make a copy - fast! + select = na.bitwise_or((self.points < self.ds.left_edge).any(axis=1), + (self.points >= self.ds.right_edge).any(axis=1)) + select = na.invert(select) + mypoints = self.points[select] + if mypoints.size > 0: + # Get the fields values. + results = self._get_fields_vals(mypoints) + # Put this into self.fields_vals. + self.fields_vals.shape = (self.comm_size*2, len(self.fields)) + self.fields_vals[select] = results + + # Put our arrays back into their original shapes cheaply! + if mypoints.size > 0: + self.fields_vals.shape = (self.comm_size, len(self.fields)*2) + self.points.shape = (self.comm_size, 6) + + # To run the functions, what is key is that the + # second point in the pair is ours. + second_points = self.points[:,3:] + select = na.bitwise_or((second_points < self.ds.left_edge).any(axis=1), + (second_points >= self.ds.right_edge).any(axis=1)) + select = na.invert(select) + if select.any(): + points_to_eval = self.points[select] + fields_to_eval = self.fields_vals[select] + + # Find the normal vector between our points. + vec = na.abs(points_to_eval[:,:3] - points_to_eval[:,3:]) + norm = na.sqrt(na.sum(na.multiply(vec,vec), axis=1)) + # I wish there was a better way to do this, but I can't find it. + for i, n in enumerate(norm): + vec[i] = na.divide(vec[i], n) + + # Now evaluate the functions. + for fcn_set in self._fsets: + fcn_results = fcn_set._eval_st_fcn(fields_to_eval,points_to_eval, + vec) + fcn_set._bin_results(length, fcn_results) + + # Now clear the buffers at the processed points. + self.points[select] = na.array([-1.]*6, dtype='float64') + + else: + # We didn't clear any points, so we should move on with our + # lives and pass this buffer along. + added_points = False + + @parallel_blocking_call + def write_out_means(self): + r"""Writes out the weighted-average value for each function for + each dimension for each ruler length to a text file. The data is written + to files of the name 'function_name.txt' in the current working + directory. + + Examples + -------- + >>> tpf.write_out_means() + """ + for fset in self._fsets: + fp = self._write_on_root("%s.txt" % fset.function.__name__) + fset._avg_bin_hits() + line = "# length".ljust(sep) + line += "count".ljust(sep) + for dim in fset.dims: + line += ("%s" % fset.out_labels[dim]).ljust(sep) + fp.write(line + "\n") + for length in self.lengths: + line = ("%1.5e" % length).ljust(sep) + line += ("%d" % fset.binned[length]).ljust(sep) + for dim in fset.dims: + if fset.sqrt[dim]: + line += ("%1.5e" % \ + math.sqrt(fset.length_avgs[length][dim])).ljust(sep) + else: + line += ("%1.5e" % \ + fset.length_avgs[length][dim]).ljust(sep) + line += "\n" + fp.write(line) + fp.close() + + @parallel_root_only + def write_out_arrays(self): + r"""Writes out the raw probability bins and the bin edges to an HDF5 file + for each of the functions. The files are named + 'function_name.txt' and saved in the current working directory. + + Examples + -------- + >>> tpf.write_out_arrays() + """ + if self.mine == 0: + for fset in self._fsets: + f = h5py.File("%s.h5" % fset.function.__name__, "w") + bin_names = [] + prob_names = [] + bin_counts = [] + for dim in fset.dims: + f.create_dataset("/bin_edges_%02d_%s" % \ + (dim, fset.out_labels[dim]), \ + data=fset.bin_edges[dim]) + bin_names.append("/bin_edges_%02d_%s" % \ + (dim, fset.out_labels[dim])) + for i,length in enumerate(self.lengths): + f.create_dataset("/prob_bins_%05d" % i, \ + data=fset.length_bin_hits[length]) + prob_names.append("/prob_bins_%05d" % i) + bin_counts.append([fset.too_low.sum(), fset.binned[length], + fset.too_high.sum()]) + f.create_dataset("/bin_edges_names", data=bin_names) + #f.create_dataset("/prob_names", data=prob_names) + f.create_dataset("/lengths", data=self.lengths) + f.create_dataset("/counts", data=bin_counts) + f.close() + + @parallel_root_only + def write_out_correlation(self): + r"""A special output function for doing two point correlation functions. + Outputs the correlation function xi(r) in a text file + 'function_name_corr.txt' in the current working directory. + + Examples + -------- + >>> tpf.write_out_correlation() + """ + for fset in self._fsets: + # Only operate on correlation functions. + if fset.corr_norm == None: continue + fp = self._write_on_root("%s_correlation.txt" % fset.function.__name__) + line = "# length".ljust(sep) + line += "\\xi".ljust(sep) + fp.write(line + "\n") + xi = fset._corr_sum_norm() + for length in self.lengths: + line = ("%1.5e" % length).ljust(sep) + line += ("%1.5e" % xi[length]).ljust(sep) + fp.write(line + "\n") + fp.close() + +class FcnSet(TwoPointFunctions): + def __init__(self,tpf, function, min_edge, out_labels, sqrt, corr_norm): + self.tpf = tpf # The overarching TPF class + self.function = function # Function to eval between the two points. + self.min_edge = min_edge # The length of the minimum edge of the box. + self.out_labels = out_labels # For output. + self.sqrt = sqrt # which columns to sqrt on output. + self.corr_norm = corr_norm # A number used to normalize a correlation function. + # These below are used to track how many times the function returns + # unbinned results. + self.too_low = na.zeros(len(self.out_labels), dtype='int32') + self.too_high = na.zeros(len(self.out_labels), dtype='int32') + + def set_pdf_params(self, bin_type="lin", bin_number=1000, bin_range=None): + r"""Set the parameters used to build the Probability Distribution Function + for each ruler length for this function. The values output by the + function are slotted into the bins described here. + + Parameters + ---------- + bin_type : String + Controls the edges of the bins spaced evenly in + logarithmic or linear space, set by "log" or "lin", respectively. + A single string, or list of strings for N-dim binning. + Default = "lin". + bin_number : Integer + Sets how many bins to create, evenly spaced by the above + parameter. A single integer, or a list of integers for N-dim + binning. Default = 1000. + bin_range : Float + A pair of values giving the range for the bins. + A pair of floats (a list), or a list of pairs for N-dim binning. + Default = None. + + Examples + -------- + >>> f1.set_pdf_params(bin_type='log', bin_range=[5e4, 5.5e13], + ... bin_number=1000) + """ + # This should be called after setSearchParams. + if not hasattr(self.tpf, "lengths"): + mylog.error("Please call setSearchParams() before calling setPDFParams().") + return None + # Make sure they're either all lists or only one is. + input = [bin_type, bin_number, bin_range] + lists = 0 + for thing in input: + if type(thing) == types.ListType: + lists += 1 + if lists > 1 and lists < 3: + mylog.error("Either all the inputs need to be lists, or only one.") + return None + # Make sure they're all the same length if they're lists. + if lists == 3: + first_len = 0 + for thing in input: + if first_len == 0: + first_len = len(thing) + if first_len == 0: + mylog.error("Input cannot be an empty list.") + return None + continue + if first_len != len(thing): + mylog.error("All the inputs need to have the same length.") + return None + # If they are not all lists, put the input into lists for convenience. + if lists == 1: + bin_type, bin_number = [bin_type], [bin_number] + bin_range = [bin_range] + self.bin_type = bin_type + self.bin_number = na.array(bin_number) - 1 + self.dims = range(len(bin_type)) + # Create the dict that stores the arrays to store the bin hits, and + # the arrays themselves. + self.length_bin_hits = {} + for length in self.tpf.lengths: + # It's easier to index flattened, but will be unflattened later. + self.length_bin_hits[length] = na.zeros(self.bin_number, + dtype='int64').flatten() + # Create the bin edges for each dimension. + # self.bins is indexed by dimension + self.bin_edges = {} + for dim in self.dims: + # Error check. + if len(bin_range[dim]) != 2: + raise ValueError("bin_range must have two values.") + if bin_range[dim][1] <= bin_range[dim][0]: + raise ValueError("bin_range[1] must be larger than bin_range[0]") + # Make the edges for this dimension. + if bin_type[dim] == "lin": + self.bin_edges[dim] = na.linspace(bin_range[dim][0], bin_range[dim][1], + bin_number[dim]) + elif bin_type[dim] == "log": + self.bin_edges[dim] = na.logspace(math.log10(bin_range[dim][0]), + math.log10(bin_range[dim][1]), bin_number[dim]) + else: + raise SyntaxError("bin_edges is either \"lin\" or \"log\".") + + def _eval_st_fcn(self, results, points, vec): + """ + Return the value of the function using the provided results. + """ + return self.function(results[:,:len(self.tpf.fields)], + results[:,len(self.tpf.fields):], points[:,:3], points[:,3:], vec) + """ + NOTE - A function looks like: + def stuff(a,b,r1,r2, vec): + return [(a[0] - b[0])/(a[1] + b[1])] + where a and b refer to different points in space and the indices + are for the different fields, which are given when the function is + added. The results need to be a list or array even if it's only one + item. + """ + + def _bin_results(self, length, results): + """ + Add hits to the bins corresponding to these results. length_hit_bins + is flattened, so we need to figure out the offset for this hit by + factoring the sizes of the other dimensions. + """ + hit_bin = na.zeros(results.shape[0], dtype='int64') + multi = 1 + good = na.ones(results.shape[0], dtype='bool') + for dim in range(len(self.out_labels)): + for d1 in range(dim): + multi *= self.bin_edges[d1].size + if dim == 0 and len(self.out_labels)==1: + try: + digi = na.digitize(results, self.bin_edges[dim]) + except ValueError: + # The user probably did something like + # return a * b rather than + # return a[0] * b[0], which will only happen + # for single field functions. + digi = na.digitize(results[0], self.bin_edges[dim]) + else: + digi = na.digitize(results[:,dim], self.bin_edges[dim]) + too_low = (digi == 0) + too_high = (digi == self.bin_edges[dim].size) + self.too_low[dim] += (too_low).sum() + self.too_high[dim] += (too_high).sum() + newgood = na.bitwise_and(na.invert(too_low), na.invert(too_high)) + good = na.bitwise_and(good, newgood) + hit_bin += na.multiply((digi - 1), multi) + digi_bins = na.arange(self.length_bin_hits[length].size+1) + hist, digi_bins = na.histogram(hit_bin[good], digi_bins) + self.length_bin_hits[length] += hist + + def _dim_sum(self, a, dim): + """ + Given a multidimensional array a, this finds the sum over all the + elements leaving the dimension dim untouched. + """ + dims = na.arange(len(a.shape)) + dims = na.flipud(dims) + gt_dims = dims[dims > dim] + lt_dims = dims[dims < dim] + iter_dims = na.concatenate((gt_dims, lt_dims)) + for this_dim in iter_dims: + a = a.sum(axis=this_dim) + return a + + def _avg_bin_hits(self): + """ + For each dimension and length of bin_hits return the weighted average. + """ + self.length_avgs = defaultdict(dict) + for length in self.tpf.lengths: + for dim in self.dims: + self.length_avgs[length][dim] = \ + (self._dim_sum(self.length_bin_hits[length], dim) * \ + ((self.bin_edges[dim][:-1] + self.bin_edges[dim][1:]) / 2.)).sum() + + def _corr_sum_norm(self): + """ + Return the correlations xi for this function. We are tacitly assuming + that all correlation functions are one dimensional. + """ + xi = {} + for length in self.tpf.lengths: + xi[length] = -1 + na.sum(self.length_bin_hits[length] * \ + self.bin_edges[0][:-1]) / self.corr_norm + return xi diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/cmdln.py --- a/yt/cmdln.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1586 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2002-2007 ActiveState Software Inc. -# License: MIT (see LICENSE.txt for license details) -# Author: Trent Mick -# Home: http://trentm.com/projects/cmdln/ - -"""An improvement on Python's standard cmd.py module. - -As with cmd.py, this module provides "a simple framework for writing -line-oriented command intepreters." This module provides a 'RawCmdln' -class that fixes some design flaws in cmd.Cmd, making it more scalable -and nicer to use for good 'cvs'- or 'svn'-style command line interfaces -or simple shells. And it provides a 'Cmdln' class that add -optparse-based option processing. Basically you use it like this: - - import cmdln - - class MySVN(cmdln.Cmdln): - name = "svn" - - @cmdln.alias('stat', 'st') - @cmdln.option('-v', '--verbose', action='store_true' - help='print verbose information') - def do_status(self, subcmd, opts, *paths): - print "handle 'svn status' command" - - #... - - if __name__ == "__main__": - shell = MySVN() - retval = shell.main() - sys.exit(retval) - -See the README.txt or for more -details. -""" - -__version_info__ = (1, 1, 2) -__version__ = '.'.join(map(str, __version_info__)) - -import os -import sys -import re -import cmd -import optparse -from pprint import pprint -import sys - - - - -#---- globals - -LOOP_ALWAYS, LOOP_NEVER, LOOP_IF_EMPTY = range(3) - -# An unspecified optional argument when None is a meaningful value. -_NOT_SPECIFIED = ("Not", "Specified") - -# Pattern to match a TypeError message from a call that -# failed because of incorrect number of arguments (see -# Python/getargs.c). -_INCORRECT_NUM_ARGS_RE = re.compile( - r"(takes [\w ]+ )(\d+)( arguments? \()(\d+)( given\))") - - - -#---- exceptions - -class CmdlnError(Exception): - """A cmdln.py usage error.""" - def __init__(self, msg): - self.msg = msg - def __str__(self): - return self.msg - -class CmdlnUserError(Exception): - """An error by a user of a cmdln-based tool/shell.""" - pass - - - -#---- public methods and classes - -def alias(*aliases): - """Decorator to add aliases for Cmdln.do_* command handlers. - - Example: - class MyShell(cmdln.Cmdln): - @cmdln.alias("!", "sh") - def do_shell(self, argv): - #...implement 'shell' command - """ - def decorate(f): - if not hasattr(f, "aliases"): - f.aliases = [] - f.aliases += aliases - return f - return decorate - - -class RawCmdln(cmd.Cmd): - """An improved (on cmd.Cmd) framework for building multi-subcommand - scripts (think "svn" & "cvs") and simple shells (think "pdb" and - "gdb"). - - A simple example: - - import cmdln - - class MySVN(cmdln.RawCmdln): - name = "svn" - - @cmdln.aliases('stat', 'st') - def do_status(self, argv): - print "handle 'svn status' command" - - if __name__ == "__main__": - shell = MySVN() - retval = shell.main() - sys.exit(retval) - - See for more information. - """ - name = None # if unset, defaults basename(sys.argv[0]) - prompt = None # if unset, defaults to self.name+"> " - version = None # if set, default top-level options include --version - - # Default messages for some 'help' command error cases. - # They are interpolated with one arg: the command. - nohelp = "no help on '%s'" - unknowncmd = "unknown command: '%s'" - - helpindent = '' # string with which to indent help output - - def __init__(self, completekey='tab', - stdin=None, stdout=None, stderr=None): - """Cmdln(completekey='tab', stdin=None, stdout=None, stderr=None) - - The optional argument 'completekey' is the readline name of a - completion key; it defaults to the Tab key. If completekey is - not None and the readline module is available, command completion - is done automatically. - - The optional arguments 'stdin', 'stdout' and 'stderr' specify - alternate input, output and error output file objects; if not - specified, sys.* are used. - - If 'stdout' but not 'stderr' is specified, stdout is used for - error output. This is to provide least surprise for users used - to only the 'stdin' and 'stdout' options with cmd.Cmd. - """ - import sys - if self.name is None: - self.name = os.path.basename(sys.argv[0]) - if self.prompt is None: - self.prompt = self.name+"> " - self._name_str = self._str(self.name) - self._prompt_str = self._str(self.prompt) - if stdin is not None: - self.stdin = stdin - else: - self.stdin = sys.stdin - if stdout is not None: - self.stdout = stdout - else: - self.stdout = sys.stdout - if stderr is not None: - self.stderr = stderr - elif stdout is not None: - self.stderr = stdout - else: - self.stderr = sys.stderr - self.cmdqueue = [] - self.completekey = completekey - self.cmdlooping = False - - def get_optparser(self): - """Hook for subclasses to set the option parser for the - top-level command/shell. - - This option parser is used retrieved and used by `.main()' to - handle top-level options. - - The default implements a single '-h|--help' option. Sub-classes - can return None to have no options at the top-level. Typically - an instance of CmdlnOptionParser should be returned. - """ - version = (self.version is not None - and "%s %s" % (self._name_str, self.version) - or None) - return CmdlnOptionParser(self, version=version) - - def postoptparse(self): - """Hook method executed just after `.main()' parses top-level - options. - - When called `self.options' holds the results of the option parse. - """ - pass - - def main(self, argv=None, loop=LOOP_NEVER): - """A possible mainline handler for a script, like so: - - import cmdln - class MyCmd(cmdln.Cmdln): - name = "mycmd" - ... - - if __name__ == "__main__": - MyCmd().main() - - By default this will use sys.argv to issue a single command to - 'MyCmd', then exit. The 'loop' argument can be use to control - interactive shell behaviour. - - Arguments: - "argv" (optional, default sys.argv) is the command to run. - It must be a sequence, where the first element is the - command name and subsequent elements the args for that - command. - "loop" (optional, default LOOP_NEVER) is a constant - indicating if a command loop should be started (i.e. an - interactive shell). Valid values (constants on this module): - LOOP_ALWAYS start loop and run "argv", if any - LOOP_NEVER run "argv" (or .emptyline()) and exit - LOOP_IF_EMPTY run "argv", if given, and exit; - otherwise, start loop - """ - if argv is None: - import sys - argv = sys.argv - else: - argv = argv[:] # don't modify caller's list - - self.optparser = self.get_optparser() - if self.optparser: # i.e. optparser=None means don't process for opts - try: - self.options, args = self.optparser.parse_args(argv[1:]) - except CmdlnUserError, ex: - msg = "%s: %s\nTry '%s help' for info.\n"\ - % (self.name, ex, self.name) - self.stderr.write(self._str(msg)) - self.stderr.flush() - return 1 - except StopOptionProcessing, ex: - return 0 - else: - self.options, args = None, argv[1:] - self.postoptparse() - - if loop == LOOP_ALWAYS: - if args: - self.cmdqueue.append(args) - return self.cmdloop() - elif loop == LOOP_NEVER: - if args: - return self.cmd(args) - else: - return self.emptyline() - elif loop == LOOP_IF_EMPTY: - if args: - return self.cmd(args) - else: - return self.cmdloop() - - def cmd(self, argv): - """Run one command and exit. - - "argv" is the arglist for the command to run. argv[0] is the - command to run. If argv is an empty list then the - 'emptyline' handler is run. - - Returns the return value from the command handler. - """ - assert isinstance(argv, (list, tuple)), \ - "'argv' is not a sequence: %r" % argv - retval = None - try: - argv = self.precmd(argv) - retval = self.onecmd(argv) - self.postcmd(argv) - except: - if not self.cmdexc(argv): - raise - retval = 1 - return retval - - def _str(self, s): - """Safely convert the given str/unicode to a string for printing.""" - try: - return str(s) - except UnicodeError: - #XXX What is the proper encoding to use here? 'utf-8' seems - # to work better than "getdefaultencoding" (usually - # 'ascii'), on OS X at least. - #import sys - #return s.encode(sys.getdefaultencoding(), "replace") - return s.encode("utf-8", "replace") - - def cmdloop(self, intro=None): - """Repeatedly issue a prompt, accept input, parse into an argv, and - dispatch (via .precmd(), .onecmd() and .postcmd()), passing them - the argv. In other words, start a shell. - - "intro" (optional) is a introductory message to print when - starting the command loop. This overrides the class - "intro" attribute, if any. - """ - self.cmdlooping = True - self.preloop() - if self.use_rawinput and self.completekey: - try: - import readline - self.old_completer = readline.get_completer() - readline.set_completer(self.complete) - readline.parse_and_bind(self.completekey+": complete") - except ImportError: - pass - try: - if intro is None: - intro = self.intro - if intro: - intro_str = self._str(intro) - self.stdout.write(intro_str+'\n') - self.stop = False - retval = None - while not self.stop: - if self.cmdqueue: - argv = self.cmdqueue.pop(0) - assert isinstance(argv, (list, tuple)), \ - "item on 'cmdqueue' is not a sequence: %r" % argv - else: - if self.use_rawinput: - try: - line = raw_input(self._prompt_str) - except EOFError: - line = 'EOF' - else: - self.stdout.write(self._prompt_str) - self.stdout.flush() - line = self.stdin.readline() - if not len(line): - line = 'EOF' - else: - line = line[:-1] # chop '\n' - argv = line2argv(line) - try: - argv = self.precmd(argv) - retval = self.onecmd(argv) - self.postcmd(argv) - except: - if not self.cmdexc(argv): - raise - retval = 1 - self.lastretval = retval - self.postloop() - finally: - if self.use_rawinput and self.completekey: - try: - import readline - readline.set_completer(self.old_completer) - except ImportError: - pass - self.cmdlooping = False - return retval - - def precmd(self, argv): - """Hook method executed just before the command argv is - interpreted, but after the input prompt is generated and issued. - - "argv" is the cmd to run. - - Returns an argv to run (i.e. this method can modify the command - to run). - """ - return argv - - def postcmd(self, argv): - """Hook method executed just after a command dispatch is finished. - - "argv" is the command that was run. - """ - pass - - def cmdexc(self, argv): - """Called if an exception is raised in any of precmd(), onecmd(), - or postcmd(). If True is returned, the exception is deemed to have - been dealt with. Otherwise, the exception is re-raised. - - The default implementation handles CmdlnUserError's, which - typically correspond to user error in calling commands (as - opposed to programmer error in the design of the script using - cmdln.py). - """ - import sys - type, exc, traceback = sys.exc_info() - if isinstance(exc, CmdlnUserError): - msg = "%s %s: %s\nTry '%s help %s' for info.\n"\ - % (self.name, argv[0], exc, self.name, argv[0]) - self.stderr.write(self._str(msg)) - self.stderr.flush() - return True - - def onecmd(self, argv): - if not argv: - return self.emptyline() - self.lastcmd = argv - cmdname = self._get_canonical_cmd_name(argv[0]) - if cmdname: - handler = self._get_cmd_handler(cmdname) - if handler: - return self._dispatch_cmd(handler, argv) - return self.default(argv) - - def _dispatch_cmd(self, handler, argv): - return handler(argv) - - def default(self, argv): - """Hook called to handle a command for which there is no handler. - - "argv" is the command and arguments to run. - - The default implementation writes and error message to stderr - and returns an error exit status. - - Returns a numeric command exit status. - """ - errmsg = self._str(self.unknowncmd % (argv[0],)) - if self.cmdlooping: - self.stderr.write(errmsg+"\n") - else: - self.stderr.write("%s: %s\nTry '%s help' for info.\n" - % (self._name_str, errmsg, self._name_str)) - self.stderr.flush() - return 1 - - def parseline(self, line): - # This is used by Cmd.complete (readline completer function) to - # massage the current line buffer before completion processing. - # We override to drop special '!' handling. - line = line.strip() - if not line: - return None, None, line - elif line[0] == '?': - line = 'help ' + line[1:] - i, n = 0, len(line) - while i < n and line[i] in self.identchars: i = i+1 - cmd, arg = line[:i], line[i:].strip() - return cmd, arg, line - - def helpdefault(self, cmd, known): - """Hook called to handle help on a command for which there is no - help handler. - - "cmd" is the command name on which help was requested. - "known" is a boolean indicating if this command is known - (i.e. if there is a handler for it). - - Returns a return code. - """ - if known: - msg = self._str(self.nohelp % (cmd,)) - if self.cmdlooping: - self.stderr.write(msg + '\n') - else: - self.stderr.write("%s: %s\n" % (self.name, msg)) - else: - msg = self.unknowncmd % (cmd,) - if self.cmdlooping: - self.stderr.write(msg + '\n') - else: - self.stderr.write("%s: %s\n" - "Try '%s help' for info.\n" - % (self.name, msg, self.name)) - self.stderr.flush() - return 1 - - def do_help(self, argv): - """${cmd_name}: give detailed help on a specific sub-command - - Usage: - ${name} help [COMMAND] - """ - if len(argv) > 1: # asking for help on a particular command - doc = None - cmdname = self._get_canonical_cmd_name(argv[1]) or argv[1] - if not cmdname: - return self.helpdefault(argv[1], False) - else: - helpfunc = getattr(self, "help_"+cmdname, None) - if helpfunc: - doc = helpfunc() - else: - handler = self._get_cmd_handler(cmdname) - if handler: - doc = handler.__doc__ - if doc is None: - return self.helpdefault(argv[1], handler != None) - else: # bare "help" command - doc = self.__class__.__doc__ # try class docstring - if doc is None: - # Try to provide some reasonable useful default help. - if self.cmdlooping: prefix = "" - else: prefix = self.name+' ' - doc = """Usage: - %sCOMMAND [ARGS...] - %shelp [COMMAND] - - ${option_list} - ${command_list} - ${help_list} - """ % (prefix, prefix) - cmdname = None - - if doc: # *do* have help content, massage and print that - doc = self._help_reindent(doc) - doc = self._help_preprocess(doc, cmdname) - doc = doc.rstrip() + '\n' # trim down trailing space - self.stdout.write(self._str(doc)) - self.stdout.flush() - do_help.aliases = ["?"] - - def _help_reindent(self, help, indent=None): - """Hook to re-indent help strings before writing to stdout. - - "help" is the help content to re-indent - "indent" is a string with which to indent each line of the - help content after normalizing. If unspecified or None - then the default is use: the 'self.helpindent' class - attribute. By default this is the empty string, i.e. - no indentation. - - By default, all common leading whitespace is removed and then - the lot is indented by 'self.helpindent'. When calculating the - common leading whitespace the first line is ignored -- hence - help content for Conan can be written as follows and have the - expected indentation: - - def do_crush(self, ...): - '''${cmd_name}: crush your enemies, see them driven before you... - - c.f. Conan the Barbarian''' - """ - if indent is None: - indent = self.helpindent - lines = help.splitlines(0) - _dedentlines(lines, skip_first_line=True) - lines = [(indent+line).rstrip() for line in lines] - return '\n'.join(lines) - - def _help_preprocess(self, help, cmdname): - """Hook to preprocess a help string before writing to stdout. - - "help" is the help string to process. - "cmdname" is the canonical sub-command name for which help - is being given, or None if the help is not specific to a - command. - - By default the following template variables are interpolated in - help content. (Note: these are similar to Python 2.4's - string.Template interpolation but not quite.) - - ${name} - The tool's/shell's name, i.e. 'self.name'. - ${option_list} - A formatted table of options for this shell/tool. - ${command_list} - A formatted table of available sub-commands. - ${help_list} - A formatted table of additional help topics (i.e. 'help_*' - methods with no matching 'do_*' method). - ${cmd_name} - The name (and aliases) for this sub-command formatted as: - "NAME (ALIAS1, ALIAS2, ...)". - ${cmd_usage} - A formatted usage block inferred from the command function - signature. - ${cmd_option_list} - A formatted table of options for this sub-command. (This is - only available for commands using the optparse integration, - i.e. using @cmdln.option decorators or manually setting the - 'optparser' attribute on the 'do_*' method.) - - Returns the processed help. - """ - preprocessors = { - "${name}": self._help_preprocess_name, - "${option_list}": self._help_preprocess_option_list, - "${command_list}": self._help_preprocess_command_list, - "${help_list}": self._help_preprocess_help_list, - "${cmd_name}": self._help_preprocess_cmd_name, - "${cmd_usage}": self._help_preprocess_cmd_usage, - "${cmd_option_list}": self._help_preprocess_cmd_option_list, - } - - for marker, preprocessor in preprocessors.items(): - if marker in help: - help = preprocessor(help, cmdname) - return help - - def _help_preprocess_name(self, help, cmdname=None): - return help.replace("${name}", self.name) - - def _help_preprocess_option_list(self, help, cmdname=None): - marker = "${option_list}" - indent, indent_width = _get_indent(marker, help) - suffix = _get_trailing_whitespace(marker, help) - - if self.optparser: - # Setup formatting options and format. - # - Indentation of 4 is better than optparse default of 2. - # C.f. Damian Conway's discussion of this in Perl Best - # Practices. - self.optparser.formatter.indent_increment = 4 - self.optparser.formatter.current_indent = indent_width - block = self.optparser.format_option_help() + '\n' - else: - block = "" - - help = help.replace(indent+marker+suffix, block, 1) - return help - - - def _help_preprocess_command_list(self, help, cmdname=None): - marker = "${command_list}" - indent, indent_width = _get_indent(marker, help) - suffix = _get_trailing_whitespace(marker, help) - - # Find any aliases for commands. - token2canonical = self._get_canonical_map() - aliases = {} - for token, cmdname in token2canonical.items(): - if token == cmdname: continue - aliases.setdefault(cmdname, []).append(token) - - # Get the list of (non-hidden) commands and their - # documentation, if any. - cmdnames = {} # use a dict to strip duplicates - for attr in self.get_names(): - if attr.startswith("do_"): - cmdnames[attr[3:]] = True - cmdnames = cmdnames.keys() - cmdnames.sort() - linedata = [] - for cmdname in cmdnames: - if aliases.get(cmdname): - a = aliases[cmdname] - a.sort() - cmdstr = "%s (%s)" % (cmdname, ", ".join(a)) - else: - cmdstr = cmdname - doc = None - try: - helpfunc = getattr(self, 'help_'+cmdname) - except AttributeError: - handler = self._get_cmd_handler(cmdname) - if handler: - doc = handler.__doc__ - else: - doc = helpfunc() - - # Strip "${cmd_name}: " from the start of a command's doc. Best - # practice dictates that command help strings begin with this, but - # it isn't at all wanted for the command list. - to_strip = "${cmd_name}:" - if doc and doc.startswith(to_strip): - #log.debug("stripping %r from start of %s's help string", - # to_strip, cmdname) - doc = doc[len(to_strip):].lstrip() - linedata.append( (cmdstr, doc) ) - - if linedata: - subindent = indent + ' '*4 - lines = _format_linedata(linedata, subindent, indent_width+4) - block = indent + "Commands:\n" \ - + '\n'.join(lines) + "\n\n" - help = help.replace(indent+marker+suffix, block, 1) - return help - - def _gen_names_and_attrs(self): - # Inheritance says we have to look in class and - # base classes; order is not important. - names = [] - classes = [self.__class__] - while classes: - aclass = classes.pop(0) - if aclass.__bases__: - classes = classes + list(aclass.__bases__) - for name in dir(aclass): - yield (name, getattr(aclass, name)) - - def _help_preprocess_help_list(self, help, cmdname=None): - marker = "${help_list}" - indent, indent_width = _get_indent(marker, help) - suffix = _get_trailing_whitespace(marker, help) - - # Determine the additional help topics, if any. - helpnames = {} - token2cmdname = self._get_canonical_map() - for attrname, attr in self._gen_names_and_attrs(): - if not attrname.startswith("help_"): continue - helpname = attrname[5:] - if helpname not in token2cmdname: - helpnames[helpname] = attr - - if helpnames: - linedata = [(n, a.__doc__ or "") for n, a in helpnames.items()] - linedata.sort() - - subindent = indent + ' '*4 - lines = _format_linedata(linedata, subindent, indent_width+4) - block = (indent - + "Additional help topics (run `%s help TOPIC'):\n" % self.name - + '\n'.join(lines) - + "\n\n") - else: - block = '' - help = help.replace(indent+marker+suffix, block, 1) - return help - - def _help_preprocess_cmd_name(self, help, cmdname=None): - marker = "${cmd_name}" - handler = self._get_cmd_handler(cmdname) - if not handler: - raise CmdlnError("cannot preprocess '%s' into help string: " - "could not find command handler for %r" - % (marker, cmdname)) - s = cmdname - if hasattr(handler, "aliases"): - s += " (%s)" % (", ".join(handler.aliases)) - help = help.replace(marker, s) - return help - - #TODO: this only makes sense as part of the Cmdln class. - # Add hooks to add help preprocessing template vars and put - # this one on that class. - def _help_preprocess_cmd_usage(self, help, cmdname=None): - marker = "${cmd_usage}" - handler = self._get_cmd_handler(cmdname) - if not handler: - raise CmdlnError("cannot preprocess '%s' into help string: " - "could not find command handler for %r" - % (marker, cmdname)) - indent, indent_width = _get_indent(marker, help) - suffix = _get_trailing_whitespace(marker, help) - - # Extract the introspection bits we need. - func = handler.im_func - if func.func_defaults: - func_defaults = list(func.func_defaults) - else: - func_defaults = [] - co_argcount = func.func_code.co_argcount - co_varnames = func.func_code.co_varnames - co_flags = func.func_code.co_flags - CO_FLAGS_ARGS = 4 - CO_FLAGS_KWARGS = 8 - - # Adjust argcount for possible *args and **kwargs arguments. - argcount = co_argcount - if co_flags & CO_FLAGS_ARGS: argcount += 1 - if co_flags & CO_FLAGS_KWARGS: argcount += 1 - - # Determine the usage string. - usage = "%s %s" % (self.name, cmdname) - if argcount <= 2: # handler ::= do_FOO(self, argv) - usage += " [ARGS...]" - elif argcount >= 3: # handler ::= do_FOO(self, subcmd, opts, ...) - argnames = list(co_varnames[3:argcount]) - tail = "" - if co_flags & CO_FLAGS_KWARGS: - name = argnames.pop(-1) - import warnings - # There is no generally accepted mechanism for passing - # keyword arguments from the command line. Could - # *perhaps* consider: arg=value arg2=value2 ... - warnings.warn("argument '**%s' on '%s.%s' command " - "handler will never get values" - % (name, self.__class__.__name__, - func.func_name)) - if co_flags & CO_FLAGS_ARGS: - name = argnames.pop(-1) - tail = "[%s...]" % name.upper() - while func_defaults: - func_defaults.pop(-1) - name = argnames.pop(-1) - tail = "[%s%s%s]" % (name.upper(), (tail and ' ' or ''), tail) - while argnames: - name = argnames.pop(-1) - tail = "%s %s" % (name.upper(), tail) - usage += ' ' + tail - - block_lines = [ - self.helpindent + "Usage:", - self.helpindent + ' '*4 + usage - ] - block = '\n'.join(block_lines) + '\n\n' - - help = help.replace(indent+marker+suffix, block, 1) - return help - - #TODO: this only makes sense as part of the Cmdln class. - # Add hooks to add help preprocessing template vars and put - # this one on that class. - def _help_preprocess_cmd_option_list(self, help, cmdname=None): - marker = "${cmd_option_list}" - handler = self._get_cmd_handler(cmdname) - if not handler: - raise CmdlnError("cannot preprocess '%s' into help string: " - "could not find command handler for %r" - % (marker, cmdname)) - indent, indent_width = _get_indent(marker, help) - suffix = _get_trailing_whitespace(marker, help) - if hasattr(handler, "optparser"): - # Setup formatting options and format. - # - Indentation of 4 is better than optparse default of 2. - # C.f. Damian Conway's discussion of this in Perl Best - # Practices. - handler.optparser.formatter.indent_increment = 4 - handler.optparser.formatter.current_indent = indent_width - block = handler.optparser.format_option_help() + '\n' - else: - block = "" - - help = help.replace(indent+marker+suffix, block, 1) - return help - - def _get_canonical_cmd_name(self, token): - map = self._get_canonical_map() - return map.get(token, None) - - def _get_canonical_map(self): - """Return a mapping of available command names and aliases to - their canonical command name. - """ - cacheattr = "_token2canonical" - if not hasattr(self, cacheattr): - # Get the list of commands and their aliases, if any. - token2canonical = {} - cmd2funcname = {} # use a dict to strip duplicates - for attr in self.get_names(): - if attr.startswith("do_"): cmdname = attr[3:] - elif attr.startswith("_do_"): cmdname = attr[4:] - else: - continue - cmd2funcname[cmdname] = attr - token2canonical[cmdname] = cmdname - for cmdname, funcname in cmd2funcname.items(): # add aliases - func = getattr(self, funcname) - aliases = getattr(func, "aliases", []) - for alias in aliases: - if alias in cmd2funcname: - import warnings - warnings.warn("'%s' alias for '%s' command conflicts " - "with '%s' handler" - % (alias, cmdname, cmd2funcname[alias])) - continue - token2canonical[alias] = cmdname - setattr(self, cacheattr, token2canonical) - return getattr(self, cacheattr) - - def _get_cmd_handler(self, cmdname): - handler = None - try: - handler = getattr(self, 'do_' + cmdname) - except AttributeError: - try: - # Private command handlers begin with "_do_". - handler = getattr(self, '_do_' + cmdname) - except AttributeError: - pass - return handler - - def _do_EOF(self, argv): - # Default EOF handler - # Note: an actual EOF is redirected to this command. - #TODO: separate name for this. Currently it is available from - # command-line. Is that okay? - self.stdout.write('\n') - self.stdout.flush() - self.stop = True - - def emptyline(self): - # Different from cmd.Cmd: don't repeat the last command for an - # emptyline. - if self.cmdlooping: - pass - else: - return self.do_help(["help"]) - - -#---- optparse.py extension to fix (IMO) some deficiencies -# -# See the class _OptionParserEx docstring for details. -# - -class StopOptionProcessing(Exception): - """Indicate that option *and argument* processing should stop - cleanly. This is not an error condition. It is similar in spirit to - StopIteration. This is raised by _OptionParserEx's default "help" - and "version" option actions and can be raised by custom option - callbacks too. - - Hence the typical CmdlnOptionParser (a subclass of _OptionParserEx) - usage is: - - parser = CmdlnOptionParser(mycmd) - parser.add_option("-f", "--force", dest="force") - ... - try: - opts, args = parser.parse_args() - except StopOptionProcessing: - # normal termination, "--help" was probably given - sys.exit(0) - """ - -class _OptionParserEx(optparse.OptionParser): - """An optparse.OptionParser that uses exceptions instead of sys.exit. - - This class is an extension of optparse.OptionParser that differs - as follows: - - Correct (IMO) the default OptionParser error handling to never - sys.exit(). Instead OptParseError exceptions are passed through. - - Add the StopOptionProcessing exception (a la StopIteration) to - indicate normal termination of option processing. - See StopOptionProcessing's docstring for details. - - I'd also like to see the following in the core optparse.py, perhaps - as a RawOptionParser which would serve as a base class for the more - generally used OptionParser (that works as current): - - Remove the implicit addition of the -h|--help and --version - options. They can get in the way (e.g. if want '-?' and '-V' for - these as well) and it is not hard to do: - optparser.add_option("-h", "--help", action="help") - optparser.add_option("--version", action="version") - These are good practices, just not valid defaults if they can - get in the way. - """ - def error(self, msg): - raise optparse.OptParseError(msg) - - def exit(self, status=0, msg=None): - if status == 0: - raise StopOptionProcessing(msg) - else: - #TODO: don't lose status info here - raise optparse.OptParseError(msg) - - - -#---- optparse.py-based option processing support - -class CmdlnOptionParser(_OptionParserEx): - """An optparse.OptionParser class more appropriate for top-level - Cmdln options. For parsing of sub-command options, see - SubCmdOptionParser. - - Changes: - - disable_interspersed_args() by default, because a Cmdln instance - has sub-commands which may themselves have options. - - Redirect print_help() to the Cmdln.do_help() which is better - equiped to handle the "help" action. - - error() will raise a CmdlnUserError: OptionParse.error() is meant - to be called for user errors. Raising a well-known error here can - make error handling clearer. - - Also see the changes in _OptionParserEx. - """ - def __init__(self, cmdln, **kwargs): - self.cmdln = cmdln - kwargs["prog"] = self.cmdln.name - _OptionParserEx.__init__(self, **kwargs) - self.disable_interspersed_args() - - def print_help(self, file=None): - self.cmdln.onecmd(["help"]) - - def error(self, msg): - raise CmdlnUserError(msg) - - -class SubCmdOptionParser(_OptionParserEx): - def set_cmdln_info(self, cmdln, subcmd): - """Called by Cmdln to pass relevant info about itself needed - for print_help(). - """ - self.cmdln = cmdln - self.subcmd = subcmd - - def print_help(self, file=None): - self.cmdln.onecmd(["help", self.subcmd]) - - def error(self, msg): - raise CmdlnUserError(msg) - - -def option(*args, **kwargs): - """Decorator to add an option to the optparser argument of a Cmdln - subcommand. - - Example: - class MyShell(cmdln.Cmdln): - @cmdln.option("-f", "--force", help="force removal") - def do_remove(self, subcmd, opts, *args): - #... - """ - #XXX Is there a possible optimization for many options to not have a - # large stack depth here? - def decorate(f): - if not hasattr(f, "optparser"): - f.optparser = SubCmdOptionParser() - f.optparser.add_option(*args, **kwargs) - return f - return decorate - - -class Cmdln(RawCmdln): - """An improved (on cmd.Cmd) framework for building multi-subcommand - scripts (think "svn" & "cvs") and simple shells (think "pdb" and - "gdb"). - - A simple example: - - import cmdln - - class MySVN(cmdln.Cmdln): - name = "svn" - - @cmdln.aliases('stat', 'st') - @cmdln.option('-v', '--verbose', action='store_true' - help='print verbose information') - def do_status(self, subcmd, opts, *paths): - print "handle 'svn status' command" - - #... - - if __name__ == "__main__": - shell = MySVN() - retval = shell.main() - sys.exit(retval) - - 'Cmdln' extends 'RawCmdln' by providing optparse option processing - integration. See this class' _dispatch_cmd() docstring and - for more information. - """ - def _dispatch_cmd(self, handler, argv): - """Introspect sub-command handler signature to determine how to - dispatch the command. The raw handler provided by the base - 'RawCmdln' class is still supported: - - def do_foo(self, argv): - # 'argv' is the vector of command line args, argv[0] is - # the command name itself (i.e. "foo" or an alias) - pass - - In addition, if the handler has more than 2 arguments option - processing is automatically done (using optparse): - - @cmdln.option('-v', '--verbose', action='store_true') - def do_bar(self, subcmd, opts, *args): - # subcmd = <"bar" or an alias> - # opts = - if opts.verbose: - print "lots of debugging output..." - # args = - for arg in args: - bar(arg) - - TODO: explain that "*args" can be other signatures as well. - - The `cmdln.option` decorator corresponds to an `add_option()` - method call on an `optparse.OptionParser` instance. - - You can declare a specific number of arguments: - - @cmdln.option('-v', '--verbose', action='store_true') - def do_bar2(self, subcmd, opts, bar_one, bar_two): - #... - - and an appropriate error message will be raised/printed if the - command is called with a different number of args. - """ - co_argcount = handler.im_func.func_code.co_argcount - if co_argcount == 2: # handler ::= do_foo(self, argv) - return handler(argv) - elif co_argcount >= 3: # handler ::= do_foo(self, subcmd, opts, ...) - try: - optparser = handler.optparser - except AttributeError: - optparser = handler.im_func.optparser = SubCmdOptionParser() - assert isinstance(optparser, SubCmdOptionParser) - optparser.set_cmdln_info(self, argv[0]) - try: - opts, args = optparser.parse_args(argv[1:]) - except StopOptionProcessing: - #TODO: this doesn't really fly for a replacement of - # optparse.py behaviour, does it? - return 0 # Normal command termination - - try: - return handler(argv[0], opts, *args) - except TypeError, ex: - # Some TypeError's are user errors: - # do_foo() takes at least 4 arguments (3 given) - # do_foo() takes at most 5 arguments (6 given) - # do_foo() takes exactly 5 arguments (6 given) - # Raise CmdlnUserError for these with a suitably - # massaged error message. - import sys - tb = sys.exc_info()[2] # the traceback object - if tb.tb_next is not None: - # If the traceback is more than one level deep, then the - # TypeError do *not* happen on the "handler(...)" call - # above. In that we don't want to handle it specially - # here: it would falsely mask deeper code errors. - raise - msg = ex.args[0] - match = _INCORRECT_NUM_ARGS_RE.search(msg) - if match: - msg = list(match.groups()) - msg[1] = int(msg[1]) - 3 - if msg[1] == 1: - msg[2] = msg[2].replace("arguments", "argument") - msg[3] = int(msg[3]) - 3 - msg = ''.join(map(str, msg)) - raise CmdlnUserError(msg) - else: - raise - else: - raise CmdlnError("incorrect argcount for %s(): takes %d, must " - "take 2 for 'argv' signature or 3+ for 'opts' " - "signature" % (handler.__name__, co_argcount)) - - - -#---- internal support functions - -def _format_linedata(linedata, indent, indent_width): - """Format specific linedata into a pleasant layout. - - "linedata" is a list of 2-tuples of the form: - (, ) - "indent" is a string to use for one level of indentation - "indent_width" is a number of columns by which the - formatted data will be indented when printed. - - The column is held to 15 columns. - """ - lines = [] - WIDTH = 78 - indent_width - SPACING = 2 - NAME_WIDTH_LOWER_BOUND = 13 - NAME_WIDTH_UPPER_BOUND = 16 - NAME_WIDTH = max([len(s) for s,d in linedata]) - if NAME_WIDTH < NAME_WIDTH_LOWER_BOUND: - NAME_WIDTH = NAME_WIDTH_LOWER_BOUND - else: - NAME_WIDTH = NAME_WIDTH_UPPER_BOUND - - DOC_WIDTH = WIDTH - NAME_WIDTH - SPACING - for namestr, doc in linedata: - line = indent + namestr - if len(namestr) <= NAME_WIDTH: - line += ' ' * (NAME_WIDTH + SPACING - len(namestr)) - else: - lines.append(line) - line = indent + ' ' * (NAME_WIDTH + SPACING) - line += _summarize_doc(doc, DOC_WIDTH) - lines.append(line.rstrip()) - return lines - -def _summarize_doc(doc, length=60): - r"""Parse out a short one line summary from the given doclines. - - "doc" is the doc string to summarize. - "length" is the max length for the summary - - >>> _summarize_doc("this function does this") - 'this function does this' - >>> _summarize_doc("this function does this", 10) - 'this fu...' - >>> _summarize_doc("this function does this\nand that") - 'this function does this and that' - >>> _summarize_doc("this function does this\n\nand that") - 'this function does this' - """ - import re - if doc is None: - return "" - assert length > 3, "length <= 3 is absurdly short for a doc summary" - doclines = doc.strip().splitlines(0) - if not doclines: - return "" - - summlines = [] - for i, line in enumerate(doclines): - stripped = line.strip() - if not stripped: - break - summlines.append(stripped) - if len(''.join(summlines)) >= length: - break - - summary = ' '.join(summlines) - if len(summary) > length: - summary = summary[:length-3] + "..." - return summary - - -def line2argv(line): - r"""Parse the given line into an argument vector. - - "line" is the line of input to parse. - - This may get niggly when dealing with quoting and escaping. The - current state of this parsing may not be completely thorough/correct - in this respect. - - >>> from cmdln import line2argv - >>> line2argv("foo") - ['foo'] - >>> line2argv("foo bar") - ['foo', 'bar'] - >>> line2argv("foo bar ") - ['foo', 'bar'] - >>> line2argv(" foo bar") - ['foo', 'bar'] - - Quote handling: - - >>> line2argv("'foo bar'") - ['foo bar'] - >>> line2argv('"foo bar"') - ['foo bar'] - >>> line2argv(r'"foo\"bar"') - ['foo"bar'] - >>> line2argv("'foo bar' spam") - ['foo bar', 'spam'] - >>> line2argv("'foo 'bar spam") - ['foo bar', 'spam'] - - >>> line2argv('some\tsimple\ttests') - ['some', 'simple', 'tests'] - >>> line2argv('a "more complex" test') - ['a', 'more complex', 'test'] - >>> line2argv('a more="complex test of " quotes') - ['a', 'more=complex test of ', 'quotes'] - >>> line2argv('a more" complex test of " quotes') - ['a', 'more complex test of ', 'quotes'] - >>> line2argv('an "embedded \\"quote\\""') - ['an', 'embedded "quote"'] - - # Komodo bug 48027 - >>> line2argv('foo bar C:\\') - ['foo', 'bar', 'C:\\'] - - # Komodo change 127581 - >>> line2argv(r'"\test\slash" "foo bar" "foo\"bar"') - ['\\test\\slash', 'foo bar', 'foo"bar'] - - # Komodo change 127629 - >>> if sys.platform == "win32": - ... line2argv(r'\foo\bar') == ['\\foo\\bar'] - ... line2argv(r'\\foo\\bar') == ['\\\\foo\\\\bar'] - ... line2argv('"foo') == ['foo'] - ... else: - ... line2argv(r'\foo\bar') == ['foobar'] - ... line2argv(r'\\foo\\bar') == ['\\foo\\bar'] - ... try: - ... line2argv('"foo') - ... except ValueError, ex: - ... "not terminated" in str(ex) - True - True - True - """ - import string - line = line.strip() - argv = [] - state = "default" - arg = None # the current argument being parsed - i = -1 - while 1: - i += 1 - if i >= len(line): break - ch = line[i] - - if ch == "\\" and i+1 < len(line): - # escaped char always added to arg, regardless of state - if arg is None: arg = "" - if (sys.platform == "win32" - or state in ("double-quoted", "single-quoted") - ) and line[i+1] not in tuple('"\''): - arg += ch - i += 1 - arg += line[i] - continue - - if state == "single-quoted": - if ch == "'": - state = "default" - else: - arg += ch - elif state == "double-quoted": - if ch == '"': - state = "default" - else: - arg += ch - elif state == "default": - if ch == '"': - if arg is None: arg = "" - state = "double-quoted" - elif ch == "'": - if arg is None: arg = "" - state = "single-quoted" - elif ch in string.whitespace: - if arg is not None: - argv.append(arg) - arg = None - else: - if arg is None: arg = "" - arg += ch - if arg is not None: - argv.append(arg) - if not sys.platform == "win32" and state != "default": - raise ValueError("command line is not terminated: unfinished %s " - "segment" % state) - return argv - - -def argv2line(argv): - r"""Put together the given argument vector into a command line. - - "argv" is the argument vector to process. - - >>> from cmdln import argv2line - >>> argv2line(['foo']) - 'foo' - >>> argv2line(['foo', 'bar']) - 'foo bar' - >>> argv2line(['foo', 'bar baz']) - 'foo "bar baz"' - >>> argv2line(['foo"bar']) - 'foo"bar' - >>> print argv2line(['foo" bar']) - 'foo" bar' - >>> print argv2line(["foo' bar"]) - "foo' bar" - >>> argv2line(["foo'bar"]) - "foo'bar" - """ - escapedArgs = [] - for arg in argv: - if ' ' in arg and '"' not in arg: - arg = '"'+arg+'"' - elif ' ' in arg and "'" not in arg: - arg = "'"+arg+"'" - elif ' ' in arg: - arg = arg.replace('"', r'\"') - arg = '"'+arg+'"' - escapedArgs.append(arg) - return ' '.join(escapedArgs) - - -# Recipe: dedent (0.1) in /Users/trentm/tm/recipes/cookbook -def _dedentlines(lines, tabsize=8, skip_first_line=False): - """_dedentlines(lines, tabsize=8, skip_first_line=False) -> dedented lines - - "lines" is a list of lines to dedent. - "tabsize" is the tab width to use for indent width calculations. - "skip_first_line" is a boolean indicating if the first line should - be skipped for calculating the indent width and for dedenting. - This is sometimes useful for docstrings and similar. - - Same as dedent() except operates on a sequence of lines. Note: the - lines list is modified **in-place**. - """ - DEBUG = False - if DEBUG: - print "dedent: dedent(..., tabsize=%d, skip_first_line=%r)"\ - % (tabsize, skip_first_line) - indents = [] - margin = None - for i, line in enumerate(lines): - if i == 0 and skip_first_line: continue - indent = 0 - for ch in line: - if ch == ' ': - indent += 1 - elif ch == '\t': - indent += tabsize - (indent % tabsize) - elif ch in '\r\n': - continue # skip all-whitespace lines - else: - break - else: - continue # skip all-whitespace lines - if DEBUG: print "dedent: indent=%d: %r" % (indent, line) - if margin is None: - margin = indent - else: - margin = min(margin, indent) - if DEBUG: print "dedent: margin=%r" % margin - - if margin is not None and margin > 0: - for i, line in enumerate(lines): - if i == 0 and skip_first_line: continue - removed = 0 - for j, ch in enumerate(line): - if ch == ' ': - removed += 1 - elif ch == '\t': - removed += tabsize - (removed % tabsize) - elif ch in '\r\n': - if DEBUG: print "dedent: %r: EOL -> strip up to EOL" % line - lines[i] = lines[i][j:] - break - else: - raise ValueError("unexpected non-whitespace char %r in " - "line %r while removing %d-space margin" - % (ch, line, margin)) - if DEBUG: - print "dedent: %r: %r -> removed %d/%d"\ - % (line, ch, removed, margin) - if removed == margin: - lines[i] = lines[i][j+1:] - break - elif removed > margin: - lines[i] = ' '*(removed-margin) + lines[i][j+1:] - break - return lines - -def _dedent(text, tabsize=8, skip_first_line=False): - """_dedent(text, tabsize=8, skip_first_line=False) -> dedented text - - "text" is the text to dedent. - "tabsize" is the tab width to use for indent width calculations. - "skip_first_line" is a boolean indicating if the first line should - be skipped for calculating the indent width and for dedenting. - This is sometimes useful for docstrings and similar. - - textwrap.dedent(s), but don't expand tabs to spaces - """ - lines = text.splitlines(1) - _dedentlines(lines, tabsize=tabsize, skip_first_line=skip_first_line) - return ''.join(lines) - - -def _get_indent(marker, s, tab_width=8): - """_get_indent(marker, s, tab_width=8) -> - (, )""" - # Figure out how much the marker is indented. - INDENT_CHARS = tuple(' \t') - start = s.index(marker) - i = start - while i > 0: - if s[i-1] not in INDENT_CHARS: - break - i -= 1 - indent = s[i:start] - indent_width = 0 - for ch in indent: - if ch == ' ': - indent_width += 1 - elif ch == '\t': - indent_width += tab_width - (indent_width % tab_width) - return indent, indent_width - -def _get_trailing_whitespace(marker, s): - """Return the whitespace content trailing the given 'marker' in string 's', - up to and including a newline. - """ - suffix = '' - start = s.index(marker) + len(marker) - i = start - while i < len(s): - if s[i] in ' \t': - suffix += s[i] - elif s[i] in '\r\n': - suffix += s[i] - if s[i] == '\r' and i+1 < len(s) and s[i+1] == '\n': - suffix += s[i+1] - break - else: - break - i += 1 - return suffix - - - -#---- bash completion support -# Note: This is still experimental. I expect to change this -# significantly. -# -# To get Bash completion for a cmdln.Cmdln class, run the following -# bash command: -# $ complete -C 'python -m cmdln /path/to/script.py CmdlnClass' cmdname -# For example: -# $ complete -C 'python -m cmdln ~/bin/svn.py SVN' svn -# -#TODO: Simplify the above so don't have to given path to script (try to -# find it on PATH, if possible). Could also make class name -# optional if there is only one in the module (common case). - -if __name__ == "__main__" and len(sys.argv) == 6: - def _log(s): - return # no-op, comment out for debugging - from os.path import expanduser - fout = open(expanduser("~/tmp/bashcpln.log"), 'a') - fout.write(str(s) + '\n') - fout.close() - - # Recipe: module_from_path (1.0.1+) - def _module_from_path(path): - import imp, os, sys - path = os.path.expanduser(path) - dir = os.path.dirname(path) or os.curdir - name = os.path.splitext(os.path.basename(path))[0] - sys.path.insert(0, dir) - try: - iinfo = imp.find_module(name, [dir]) - return imp.load_module(name, *iinfo) - finally: - sys.path.remove(dir) - - def _get_bash_cplns(script_path, class_name, cmd_name, - token, preceding_token): - _log('--') - _log('get_cplns(%r, %r, %r, %r, %r)' - % (script_path, class_name, cmd_name, token, preceding_token)) - comp_line = os.environ["COMP_LINE"] - comp_point = int(os.environ["COMP_POINT"]) - _log("COMP_LINE: %r" % comp_line) - _log("COMP_POINT: %r" % comp_point) - - try: - script = _module_from_path(script_path) - except ImportError, ex: - _log("error importing `%s': %s" % (script_path, ex)) - return [] - shell = getattr(script, class_name)() - cmd_map = shell._get_canonical_map() - del cmd_map["EOF"] - - # Determine if completing the sub-command name. - parts = comp_line[:comp_point].split(None, 1) - _log(parts) - if len(parts) == 1 or not (' ' in parts[1] or '\t' in parts[1]): - #TODO: if parts[1].startswith('-'): handle top-level opts - _log("complete sub-command names") - matches = {} - for name, canon_name in cmd_map.items(): - if name.startswith(token): - matches[name] = canon_name - if not matches: - return [] - elif len(matches) == 1: - return matches.keys() - elif len(set(matches.values())) == 1: - return [matches.values()[0]] - else: - return matches.keys() - - # Otherwise, complete options for the given sub-command. - #TODO: refine this so it does the right thing with option args - if token.startswith('-'): - cmd_name = comp_line.split(None, 2)[1] - try: - cmd_canon_name = cmd_map[cmd_name] - except KeyError: - return [] - handler = shell._get_cmd_handler(cmd_canon_name) - optparser = getattr(handler, "optparser", None) - if optparser is None: - optparser = SubCmdOptionParser() - opt_strs = [] - for option in optparser.option_list: - for opt_str in option._short_opts + option._long_opts: - if opt_str.startswith(token): - opt_strs.append(opt_str) - return opt_strs - - return [] - - for cpln in _get_bash_cplns(*sys.argv[1:]): - print cpln - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/command_line.py --- a/yt/command_line.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,579 +0,0 @@ -""" -A means of running standalone commands with a shared set of options. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.mods import * -from yt.funcs import * -from yt.recipes import _fix_pf -import yt.cmdln as cmdln -import optparse, os, os.path, math, sys, time, subprocess - -_common_options = dict( - axis = dict(short="-a", long="--axis", - action="store", type="int", - dest="axis", default=4, - help="Axis (4 for all three)"), - log = dict(short="-l", long="--log", - action="store_true", - dest="takelog", default=True, - help="Take the log of the field?"), - text = dict(short="-t", long="--text", - action="store", type="string", - dest="text", default=None, - help="Textual annotation"), - field = dict(short="-f", long="--field", - action="store", type="string", - dest="field", default="Density", - help="Field to color by"), - weight = dict(short="-g", long="--weight", - action="store", type="string", - dest="weight", default=None, - help="Field to weight projections with"), - cmap = dict(short="", long="--colormap", - action="store", type="string", - dest="cmap", default="jet", - help="Colormap name"), - zlim = dict(short="-z", long="--zlim", - action="store", type="float", - dest="zlim", default=None, - nargs=2, - help="Color limits (min, max)"), - dex = dict(short="", long="--dex", - action="store", type="float", - dest="dex", default=None, - nargs=1, - help="Number of dex above min to display"), - width = dict(short="-w", long="--width", - action="store", type="float", - dest="width", default=1.0, - help="Width in specified units"), - unit = dict(short="-u", long="--unit", - action="store", type="string", - dest="unit", default='1', - help="Desired units"), - center = dict(short="-c", long="--center", - action="store", type="float", - dest="center", default=[0.5, 0.5, 0.5], - nargs=3, - help="Center (-1,-1,-1 for max)"), - bn = dict(short="-b", long="--basename", - action="store", type="string", - dest="basename", default=None, - help="Basename of parameter files"), - output = dict(short="-o", long="--output", - action="store", type="string", - dest="output", default="frames/", - help="Folder in which to place output images"), - outputfn= dict(short="-o", long="--output", - action="store", type="string", - dest="output", default=None, - help="File in which to place output"), - skip = dict(short="-s", long="--skip", - action="store", type="int", - dest="skip", default=1, - help="Skip factor for outputs"), - proj = dict(short="-p", long="--projection", - action="store_true", - dest="projection", default=False, - help="Use a projection rather than a slice"), - maxw = dict(short="", long="--max-width", - action="store", type="float", - dest="max_width", default=1.0, - help="Maximum width in code units"), - minw = dict(short="", long="--min-width", - action="store", type="float", - dest="min_width", default=50, - help="Minimum width in units of smallest dx (default: 50)"), - nframes = dict(short="-n", long="--nframes", - action="store", type="int", - dest="nframes", default=100, - help="Number of frames to generate"), - slabw = dict(short="", long="--slab-width", - action="store", type="float", - dest="slab_width", default=1.0, - help="Slab width in specified units"), - slabu = dict(short="-g", long="--slab-unit", - action="store", type="string", - dest="slab_unit", default='1', - help="Desired units for the slab"), - ptype = dict(short="", long="--particle-type", - action="store", type="int", - dest="ptype", default=2, - help="Particle type to select"), - agecut = dict(short="", long="--age-cut", - action="store", type="float", - dest="age_filter", default=None, - nargs=2, - help="Bounds for the field to select"), - uboxes = dict(short="", long="--unit-boxes", - action="store_true", - dest="unit_boxes", - help="Display helpful unit boxes"), - thresh = dict(short="", long="--threshold", - action="store", type="float", - dest="threshold", default=None, - help="Density threshold"), - dm_only = dict(short="", long="--all-particles", - action="store_false", - dest="dm_only", default=True, - help="Use all particles"), - grids = dict(short="", long="--show-grids", - action="store_true", - dest="grids", default=False, - help="Show the grid boundaries"), - time = dict(short="", long="--time", - action="store_true", - dest="time", default=False, - help="Print time in years on image"), - halos = dict(short="", long="--halos", - action="store", type="string", - dest="halos",default="multiple", - help="Run halo profiler on a 'single' halo or 'multiple' halos."), - halo_radius = dict(short="", long="--halo_radius", - action="store", type="float", - dest="halo_radius",default=0.1, - help="Constant radius for profiling halos if using hop output files with no radius entry. Default: 0.1."), - halo_radius_units = dict(short="", long="--halo_radius_units", - action="store", type="string", - dest="halo_radius_units",default="1", - help="Units for radius used with --halo_radius flag. Default: '1' (code units)."), - halo_hop_style = dict(short="", long="--halo_hop_style", - action="store", type="string", - dest="halo_hop_style",default="new", - help="Style of hop output file. 'new' for yt_hop files and 'old' for enzo_hop files."), - halo_parameter_file = dict(short="", long="--halo_parameter_file", - action="store", type="string", - dest="halo_parameter_file",default=None, - help="HaloProfiler parameter file."), - make_profiles = dict(short="", long="--make_profiles", - action="store_true", default=False, - help="Make profiles with halo profiler."), - make_projections = dict(short="", long="--make_projections", - action="store_true", default=False, - help="Make projections with halo profiler.") - - ) - -def _add_options(parser, *options): - for opt in options: - oo = _common_options[opt].copy() - parser.add_option(oo.pop("short"), oo.pop("long"), **oo) - -def _get_parser(*options): - parser = optparse.OptionParser() - _add_options(parser, *options) - return parser - -def add_cmd_options(options): - opts = [] - for option in options: - vals = _common_options[option].copy() - opts.append(([vals.pop("short"), vals.pop("long")], - vals)) - def apply_options(func): - for args, kwargs in opts: - func = cmdln.option(*args, **kwargs)(func) - return func - return apply_options - -def check_args(func): - @wraps(func) - def arg_iterate(self, subcmd, opts, *args): - if len(args) == 1: - pfs = args - elif len(args) == 2 and opts.basename is not None: - pfs = ["%s%04i" % (opts.basename, r) - for r in range(int(args[0]), int(args[1]), opts.skip) ] - else: pfs = args - for arg in pfs: - func(self, subcmd, opts, arg) - return arg_iterate - -def _get_vcs_type(path): - if os.path.exists(os.path.join(path, ".hg")): - return "hg" - if os.path.exists(os.path.join(path, ".svn")): - return "svn" - return None - -def _get_svn_version(path): - p = subprocess.Popen(["svn", "info", path], stdout = subprocess.PIPE, - stderr = subprocess.STDOUT) - stdout, stderr = p.communicate() - return stdout - -def _update_svn(path): - f = open(os.path.join(path, "yt_updater.log"), "a") - f.write("\n\nUPDATE PROCESS: %s\n\n" % (time.asctime())) - p = subprocess.Popen(["svn", "up", path], stdout = subprocess.PIPE, - stderr = subprocess.STDOUT) - stdout, stderr = p.communicate() - f.write(stdout) - f.write("\n\n") - if p.returncode: - print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) - sys.exit(1) - f.write("Rebuilding modules\n\n") - p = subprocess.Popen([sys.executable, "setup.py", "build_ext", "-i"], cwd=path, - stdout = subprocess.PIPE, stderr = subprocess.STDOUT) - stdout, stderr = p.communicate() - f.write(stdout) - f.write("\n\n") - if p.returncode: - print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) - sys.exit(1) - f.write("Successful!\n") - -def _update_hg(path): - from mercurial import hg, ui, commands - f = open(os.path.join(path, "yt_updater.log"), "a") - u = ui.ui() - u.pushbuffer() - config_fn = os.path.join(path, ".hg", "hgrc") - print "Reading configuration from ", config_fn - u.readconfig(config_fn) - repo = hg.repository(u, path) - commands.pull(u, repo) - f.write(u.popbuffer()) - f.write("\n\n") - u.pushbuffer() - commands.identify(u, repo) - if "+" in u.popbuffer(): - print "Can't rebuild modules by myself." - print "You will have to do this yourself. Here's a sample commands:" - print - print " $ cd %s" % (path) - print " $ hg up" - print " $ %s setup.py develop" % (sys.executable) - sys.exit(1) - f.write("Rebuilding modules\n\n") - p = subprocess.Popen([sys.executable, "setup.py", "build_ext", "-i"], cwd=path, - stdout = subprocess.PIPE, stderr = subprocess.STDOUT) - stdout, stderr = p.communicate() - f.write(stdout) - f.write("\n\n") - if p.returncode: - print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) - sys.exit(1) - f.write("Successful!\n") - -def _get_hg_version(path): - from mercurial import hg, ui, commands - u = ui.ui() - u.pushbuffer() - repo = hg.repository(u, path) - commands.identify(u, repo) - return u.popbuffer() - -_vcs_identifier = dict(svn = _get_svn_version, - hg = _get_hg_version) -_vcs_updater = dict(svn = _update_svn, - hg = _update_hg) - -class YTCommands(cmdln.Cmdln): - name="yt" - - def __init__(self, *args, **kwargs): - cmdln.Cmdln.__init__(self, *args, **kwargs) - cmdln.Cmdln.do_help.aliases.append("h") - - def do_loop(self, subcmd, opts, *args): - """ - Interactive loop - - ${cmd_option_list} - """ - self.cmdloop() - - @cmdln.option("-u", "--update-source", action="store_true", - default = False, - help="Update the yt installation, if able") - def do_instinfo(self, subcmd, opts): - """ - ${cmd_name}: Get some information about the yt installation - - ${cmd_usage} - ${cmd_option_list} - """ - import pkg_resources - yt_provider = pkg_resources.get_provider("yt") - path = os.path.dirname(yt_provider.module_path) - print - print "yt module located at:" - print " %s" % (path) - if "site-packages" not in path: - vc_type = _get_vcs_type(path) - vstring = _vcs_identifier[vc_type](path) - print - print "The current version of the code is:" - print - print "---" - print vstring - print "---" - print - print "This installation CAN be automatically updated." - if opts.update_source: - _vcs_updater[vc_type](path) - print "Updated successfully." - - def do_load(self, subcmd, opts, arg): - """ - Load a single dataset into an IPython instance. - - ${cmd_option_list} - """ - try: - pf = _fix_pf(arg) - except IOError: - print "Could not load file." - sys.exit() - import yt.mods - from IPython.Shell import IPShellEmbed - local_ns = yt.mods.__dict__.copy() - local_ns['pf'] = pf - shell = IPShellEmbed() - shell(local_ns = local_ns, - header = - "\nHi there! Welcome to yt.\n\nWe've loaded your parameter file as 'pf'. Enjoy!" - ) - - @add_cmd_options(['outputfn','bn','thresh','dm_only','skip']) - @check_args - def do_hop(self, subcmd, opts, arg): - """ - Run HOP on one or more datasets - - ${cmd_option_list} - """ - pf = _fix_pf(arg) - kwargs = {'dm_only' : opts.dm_only} - if opts.threshold is not None: kwargs['threshold'] = opts.threshold - hop_list = HaloFinder(pf, **kwargs) - if opts.output is None: fn = "%s.hop" % pf - else: fn = opts.output - hop_list.write_out(fn) - - @add_cmd_options(['make_profiles','make_projections','halo_parameter_file', - 'halos','halo_hop_style','halo_radius','halo_radius_units']) - def do_halos(self, subcmd, opts, arg): - """ - Run HaloProfiler on one dataset. - - ${cmd_option_list} - """ - import yt.extensions.HaloProfiler as HP - kwargs = {'halos': opts.halos, - 'hop_style': opts.halo_hop_style, - 'radius': opts.halo_radius, - 'radius_units': opts.halo_radius_units} - - hp = HP.HaloProfiler(arg,opts.halo_parameter_file,**kwargs) - if opts.make_profiles: - hp.makeProfiles() - if opts.make_projections: - hp.makeProjections() - - @add_cmd_options(["maxw", "minw", "proj", "axis", "field", "weight", - "zlim", "nframes", "output", "cmap", "uboxes", "dex", - "text"]) - def do_zoomin(self, subcmd, opts, arg): - """ - Create a set of zoomin frames - - ${cmd_option_list} - """ - pf = _fix_pf(arg) - min_width = opts.min_width * pf.h.get_smallest_dx() - if opts.axis == 4: - axes = range(3) - else: - axes = [opts.axis] - pc = PlotCollection(pf) - for ax in axes: - if opts.projection: p = pc.add_projection(opts.field, ax, - weight_field=opts.weight) - else: p = pc.add_slice(opts.field, ax) - if opts.unit_boxes: p.modify["units"](factor=8) - if opts.text is not None: - p.modify["text"]( - (0.02, 0.05), opts.text.replace(r"\n", "\n"), - text_args=dict(size="medium", color="w")) - pc.set_width(opts.max_width,'1') - # Check the output directory - if not os.path.isdir(opts.output): - os.mkdir(opts.output) - # Figure out our zoom factor - # Recall that factor^nframes = min_width / max_width - # so factor = (log(min/max)/log(nframes)) - mylog.info("min_width: %0.3e max_width: %0.3e nframes: %0.3e", - min_width, opts.max_width, opts.nframes) - factor=10**(math.log10(min_width/opts.max_width)/opts.nframes) - mylog.info("Zoom factor: %0.3e", factor) - w = 1.0 - for i in range(opts.nframes): - mylog.info("Setting width to %0.3e", w) - mylog.info("Saving frame %06i",i) - pc.set_width(w,"1") - if opts.zlim: - pc.set_zlim(*opts.zlim) - if opts.dex: - pc.set_zlim('min', None, opts.dex) - pc.set_cmap(opts.cmap) - pc.save(os.path.join(opts.output,"%s_frame%06i" % (pf,i))) - w = factor**i - - @add_cmd_options(["width", "unit", "bn", "proj", "center", - "zlim", "axis", "field", "weight", "skip", - "cmap", "output", "grids", "time"]) - @check_args - def do_plot(self, subcmd, opts, arg): - """ - Create a set of images - - ${cmd_usage} - ${cmd_option_list} - """ - pf = _fix_pf(arg) - center = opts.center - if opts.center == (-1,-1,-1): - mylog.info("No center fed in; seeking.") - v, center = pf.h.find_max("Density") - center = na.array(center) - pc=raven.PlotCollection(pf, center=center) - if opts.axis == 4: - axes = range(3) - else: - axes = [opts.axis] - for ax in axes: - mylog.info("Adding plot for axis %i", ax) - if opts.projection: pc.add_projection(opts.field, ax, - weight_field=opts.weight, center=center) - else: pc.add_slice(opts.field, ax, center=center) - if opts.grids: pc.plots[-1].modify["grids"]() - if opts.time: - time = pf['InitialTime']*pf['Time']*pf['years'] - pc.plots[-1].modify["text"]((0.2,0.8), 't = %5.2e yr'%time) - pc.set_width(opts.width, opts.unit) - pc.set_cmap(opts.cmap) - if opts.zlim: pc.set_zlim(*opts.zlim) - if not os.path.isdir(opts.output): os.makedirs(opts.output) - pc.save(os.path.join(opts.output,"%s" % (pf))) - - def do_rpdb(self, subcmd, opts, task): - """ - Connect to a currently running (on localhost) rpd session. - - Commands run with --rpdb will trigger an rpdb session with any - uncaught exceptions. - - ${cmd_usage} - ${cmd_option_list} - """ - import rpdb - rpdb.run_rpdb(int(task)) - - @add_cmd_options(['outputfn','bn','skip']) - @check_args - def do_stats(self, subcmd, opts, arg): - """ - Print stats and maximum density for one or more datasets - - ${cmd_option_list} - """ - pf = _fix_pf(arg) - pf.h.print_stats() - v, c = pf.h.find_max("Density") - print "Maximum density: %0.5e at %s" % (v, c) - if opts.output is not None: - t = pf["InitialTime"] * pf['years'] - open(opts.output, "a").write( - "%s (%0.5e years): %0.5e at %s\n" % (pf, t, v, c)) - - @add_cmd_options([]) - def do_analyze(self, subcmd, opts, arg): - """ - Produce a set of analysis for a given output. This includes - HaloProfiler results with r200, as per the recipe file in the cookbook, - profiles of a number of fields, projections of average Density and - Temperature, and distribution functions for Density and Temperature. - - ${cmd_option_list} - """ - # We will do the following things: - # Halo profiling (default parameters ONLY) - # Projections: Density, Temperature - # Full-box distribution functions - import yt.extensions.HaloProfiler as HP - hp = HP.HaloProfiler(arg) - # Add a filter to remove halos that have no profile points with overdensity - # above 200, and with virial masses less than 1e14 solar masses. - # Also, return the virial mass and radius to be written out to a file. - hp.add_halo_filter(HP.VirialFilter,must_be_virialized=True, - overdensity_field='ActualOverdensity', - virial_overdensity=200, virial_filters=[], - virial_quantities=['TotalMassMsun','RadiusMpc']) - - # Add profile fields. - hp.add_profile('CellVolume',weight_field=None,accumulation=True) - hp.add_profile('TotalMassMsun',weight_field=None,accumulation=True) - hp.add_profile('Density',weight_field=None,accumulation=False) - hp.add_profile('Temperature',weight_field='CellMassMsun',accumulation=False) - hp.make_profiles(filename="FilteredQuantities.out") - - # Add projection fields. - hp.add_projection('Density',weight_field=None) - hp.add_projection('Temperature',weight_field='Density') - hp.add_projection('Metallicity',weight_field='Density') - - # Make projections for all three axes using the filtered halo list and - # save data to hdf5 files. - hp.make_projections(save_cube=True,save_images=True, - halo_list='filtered',axes=[0,1,2]) - - # Now we make full-box projections. - pf = EnzoStaticOutput(arg) - c = 0.5*(pf["DomainRightEdge"] + pf["DomainLeftEdge"]) - pc = PlotCollection(pf, center=c) - for ax in range(3): - pc.add_projection("Density", ax, "Density") - pc.add_projection("Temperature", ax, "Density") - pc.plots[-1].set_cmap("hot") - - # Time to add some phase plots - dd = pf.h.all_data() - ph = pc.add_phase_object(dd, ["Density", "Temperature", "CellMassMsun"], - weight=None) - pc_dummy = PlotCollection(pf, center=c) - pr = pc_dummy.add_profile_object(dd, ["Density", "Temperature"], - weight="CellMassMsun") - ph.modify["line"](pr.data["Density"], pr.data["Temperature"]) - pc.save() - -def run_main(): - for co in ["--parallel", "--paste"]: - if co in sys.argv: del sys.argv[sys.argv.index(co)] - YT = YTCommands() - sys.exit(YT.main()) - -if __name__ == "__main__": run_main() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/convenience.py --- a/yt/convenience.py Mon Aug 30 10:02:07 2010 -0700 +++ b/yt/convenience.py Mon Aug 30 10:48:15 2010 -0700 @@ -24,16 +24,14 @@ """ import glob +import numpy as na +import os, os.path, inspect, types +from functools import wraps # Named imports -import yt.lagos as lagos -import yt.raven as raven from yt.funcs import * -import numpy as na -import os.path, inspect, types -from functools import wraps -from yt.logger import ytLogger as mylog -from yt.fido import output_type_registry +from yt.utilities.parameter_file_storage import \ + output_type_registry def all_pfs(max_depth=1, name_spec="*.hierarchy", **kwargs): """ @@ -48,12 +46,12 @@ list_of_names += glob.glob(os.path.join(*bb)) list_of_names.sort(key=lambda b: os.path.basename(b)) for fn in list_of_names: - yield lagos.EnzoStaticOutput(fn[:-10], **kwargs) + yield load(fn[:-10], **kwargs) def max_spheres(width, unit, **kwargs): """ This calls :func:`~yt.convenience.all_pfs` and then for each parameter file - creates a :class:`~yt.lagos.AMRSphereBase` for each one, + creates a :class:`~yt.data_objects.api.AMRSphereBase` for each one, centered on the point of highest density, with radius *width* in units of *unit*. """ @@ -65,9 +63,9 @@ """ This function attempts to determine the base data type of a filename or other set of arguments by calling - :meth:`yt.lagos.StaticOutput._is_valid` until it finds a + :meth:`yt.data_objects.api.StaticOutput._is_valid` until it finds a match, at which point it returns an instance of the appropriate - :class:`yt.lagos.StaticOutput` subclass. + :class:`yt.data_objects.api.StaticOutput` subclass. """ candidates = [] for n, c in output_type_registry.items(): diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/__init__.py --- a/yt/data_objects/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ b/yt/data_objects/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -1,2 +0,0 @@ -from time_series import * -from analyzer_objects import * diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/analyzer_objects.py --- a/yt/data_objects/analyzer_objects.py Mon Aug 30 10:02:07 2010 -0700 +++ b/yt/data_objects/analyzer_objects.py Mon Aug 30 10:48:15 2010 -0700 @@ -39,7 +39,7 @@ _params = [] def eval(self, pf): - return pf["InitialTime"] * pf["years"] + return pf.current_time * pf["years"] class SliceDataset(AnalysisTask): _params = ['field', 'axis'] @@ -51,11 +51,11 @@ _params = ['field', 'axis', 'center'] def __init__(self, *args, **kwargs): - import yt.raven - self.raven = yt.raven + from yt.visualization.api import PlotCollection + self.PlotCollection = PlotCollection AnalysisTask.__init__(self, *args, **kwargs) def eval(self, pf): - pc = self.raven.PlotCollection(pf, center = self.center) + pc = self.PlotCollection(pf, center = self.center) pc.add_slice(self.field, self.axis) return pc.save()[0] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,87 @@ +""" +API for yt.data_objects + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from grid_patch import \ + AMRGridPatch + +from hierarchy import \ + AMRHierarchy + +from static_output import \ + StaticOutput + +from object_finding_mixin import \ + ObjectFindingMixin + +from particle_io import \ + ParticleIOHandler, \ + particle_handler_registry + +from profiles import \ + EmptyProfileData, \ + BinnedProfile, \ + BinnedProfile1D, \ + BinnedProfile2D, \ + BinnedProfile3D + +# Disabled for now +#from time_series import \ +# TimeSeriesData, \ +# EnzoTimeSeries, \ +# TimeSeriesDataObject +# +#from analyzer_objects import \ +# AnalysisTask + +from data_containers import \ + data_object_registry + +from derived_quantities import \ + quantity_info, \ + add_quantity + +from field_info_container import \ + FieldInfoContainer, \ + FieldInfo, \ + CodeFieldInfoContainer, \ + NeedsGridType, \ + NeedsOriginalGrid, \ + NeedsDataField, \ + NeedsProperty, \ + NeedsParameter, \ + FieldDetector, \ + DerivedField, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType, \ + add_field, \ + derived_field diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/data_containers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/data_containers.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,3302 @@ +""" +Various non-grid data containers. + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +Affiliation: University of Colorado at Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +data_object_registry = {} + +import numpy as na +import math +import weakref +import exceptions + +from yt.funcs import * + +from yt.data_objects.derived_quantities import GridChildMaskWrapper +from yt.data_objects.particle_io import particle_handler_registry +from yt.utilities.amr_utils import find_grids_in_inclined_box, \ + grid_points_in_volume, planar_points_in_volume, VoxelTraversal, \ + QuadTree +from yt.utilities.data_point_utilities import CombineGrids, \ + DataCubeRefine, DataCubeReplace, FillRegion +from yt.utilities.definitions import axis_names, x_dict, y_dict +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelAnalysisInterface +from yt.utilities.linear_interpolators import \ + UnilinearFieldInterpolator, \ + BilinearFieldInterpolator, \ + TrilinearFieldInterpolator + +from .derived_quantities import DerivedQuantityCollection +from .field_info_container import \ + NeedsGridType, \ + NeedsOriginalGrid, \ + NeedsDataField, \ + NeedsProperty, \ + NeedsParameter + +def restore_grid_state(func): + """ + A decorator that takes a function with the API of (self, grid, field) + and ensures that after the function is called, the field_parameters will + be returned to normal. + """ + def save_state(self, grid, field=None): + old_params = grid.field_parameters + old_keys = grid.data.keys() + grid.field_parameters = self.field_parameters + tr = func(self, grid, field) + grid.field_parameters = old_params + grid.data = dict( [(k, grid.data[k]) for k in old_keys] ) + return tr + return save_state + +def cache_mask(func): + """ + For computationally intensive indexing operations, we can cache + between calls. + """ + def check_cache(self, grid): + if isinstance(grid, FakeGridForParticles): + return func(self, grid) + elif grid.id not in self._cut_masks: + cm = func(self, grid) + self._cut_masks[grid.id] = cm + return self._cut_masks[grid.id] + return check_cache + +def cache_point_indices(func): + """ + For computationally intensive indexing operations, we can cache + between calls. + """ + def check_cache(self, grid, use_child_mask=True): + if isinstance(grid, FakeGridForParticles): + return func(self, grid, use_child_mask) + elif grid.id not in self._point_indices: + cm = func(self, grid, use_child_mask) + self._point_indices[grid.id] = cm + return self._point_indices[grid.id] + return check_cache + +def cache_vc_data(func): + """ + For computationally intensive operations, we can cache between + calls. + """ + def check_cache(self, grid, field): + if isinstance(grid, FakeGridForParticles): + return func(self, grid, field) + elif grid.id not in self._vc_data[field]: + vc = func(self, grid, field) + self._vc_data[field][grid.id] = vc + return self._vc_data[field][grid.id] + return check_cache + +class FakeGridForParticles(object): + """ + Mock up a grid to insert particle positions and radii + into for purposes of confinement in an :class:`AMR3DData`. + """ + def __init__(self, grid): + self._corners = grid._corners + self.field_parameters = {} + self.data = {'x':grid['particle_position_x'], + 'y':grid['particle_position_y'], + 'z':grid['particle_position_z'], + 'dx':grid['dx'], + 'dy':grid['dy'], + 'dz':grid['dz']} + self.dds = grid.dds.copy() + self.real_grid = grid + self.child_mask = 1 + self.ActiveDimensions = self.data['x'].shape + def __getitem__(self, field): + if field not in self.data.keys(): + if field == "RadiusCode": + center = self.field_parameters['center'] + tr = na.sqrt( (self['x'] - center[0])**2.0 + + (self['y'] - center[1])**2.0 + + (self['z'] - center[2])**2.0 ) + else: + raise KeyError(field) + else: tr = self.data[field] + return tr + +class AMRData(object): + """ + Generic AMRData container. By itself, will attempt to + generate field, read fields (method defined by derived classes) + and deal with passing back and forth field parameters. + """ + _grids = None + _num_ghost_zones = 0 + _con_args = () + _skip_add = False + + class __metaclass__(type): + def __init__(cls, name, b, d): + type.__init__(cls, name, b, d) + if hasattr(cls, "_type_name") and not cls._skip_add: + data_object_registry[cls._type_name] = cls + + def __init__(self, pf, fields, **kwargs): + """ + Typically this is never called directly, but only due to inheritance. + It associates a :class:`~yt.data_objects.api.StaticOutput` with the class, + sets its initial set of fields, and the remainder of the arguments + are passed as field_parameters. + """ + if pf != None: + self.pf = pf + self.hierarchy = pf.hierarchy + self.hierarchy.objects.append(weakref.proxy(self)) + mylog.debug("Appending object to %s (type: %s)", self.pf, type(self)) + if fields == None: fields = [] + self.fields = ensure_list(fields)[:] + self.data = {} + self.field_parameters = {} + self.__set_default_field_parameters() + self._cut_masks = {} + self._point_indices = {} + self._vc_data = {} + for key, val in kwargs.items(): + self.set_field_parameter(key, val) + + def __set_default_field_parameters(self): + self.set_field_parameter("center",na.zeros(3,dtype='float64')) + self.set_field_parameter("bulk_velocity",na.zeros(3,dtype='float64')) + + def _set_center(self, center): + if center is None: + pass + elif isinstance(center, (types.ListType, types.TupleType, na.ndarray)): + center = na.array(center) + elif center == ("max"): # is this dangerous for race conditions? + center = pf.h.find_max("Density") + elif center.startswith("max_"): + center = pf.h.find_max(center[4:]) + else: + center = na.array(center, dtype='float64') + self.center = center + self.set_field_parameter('center', center) + + def get_field_parameter(self, name, default=None): + """ + This is typically only used by derived field functions, but + it returns parameters used to generate fields. + """ + if self.field_parameters.has_key(name): + return self.field_parameters[name] + else: + return default + + def set_field_parameter(self, name, val): + """ + Here we set up dictionaries that get passed up and down and ultimately + to derived fields. + """ + self.field_parameters[name] = val + + def has_field_parameter(self, name): + """ + Checks if a field parameter is set. + """ + return self.field_parameters.has_key(name) + + def convert(self, datatype): + """ + This will attempt to convert a given unit to cgs from code units. + It either returns the multiplicative factor or throws a KeyError. + """ + return self.pf[datatype] + + def clear_data(self): + """ + Clears out all data from the AMRData instance, freeing memory. + """ + self.data.clear() + if self._grids is not None: + for grid in self._grids: grid.clear_data() + + def clear_cache(self): + """ + Clears out all cache, freeing memory. + """ + for _cm in self._cut_masks: del _cm + for _pi in self._point_indices: del _pi + for _field in self._vc_data: + for _vc in _field: del _vc + + def has_key(self, key): + """ + Checks if a data field already exists. + """ + return self.data.has_key(key) + + def _refresh_data(self): + """ + Wipes data and rereads/regenerates it from the self.fields. + """ + self.clear_data() + self.get_data() + + def keys(self): + return self.data.keys() + + def __getitem__(self, key): + """ + Returns a single field. Will add if necessary. + """ + if not self.data.has_key(key): + if key not in self.fields: + self.fields.append(key) + self.get_data(key) + return self.data[key] + + def __setitem__(self, key, val): + """ + Sets a field to be some other value. + """ + if key not in self.fields: self.fields.append(key) + self.data[key] = val + + def __delitem__(self, key): + """ + Deletes a field + """ + try: + del self.fields[self.fields.index(key)] + except ValueError: + pass + del self.data[key] + + def _generate_field_in_grids(self, fieldName): + pass + + _key_fields = None + def write_out(self, filename, fields=None, format="%0.16e"): + if fields is None: fields=sorted(self.data.keys()) + if self._key_fields is None: raise ValueError + field_order = self._key_fields[:] + for field in field_order: self[field] + field_order += [field for field in fields if field not in field_order] + fid = open(filename,"w") + fid.write("\t".join(["#"] + field_order + ["\n"])) + field_data = na.array([self.data[field] for field in field_order]) + for line in range(field_data.shape[1]): + field_data[:,line].tofile(fid, sep="\t", format=format) + fid.write("\n") + fid.close() + + def save_object(self, name, filename = None): + """ + Save an object. If *filename* is supplied, it will be stored in + a :mod:`shelve` file of that name. Otherwise, it will be stored via + :meth:`yt.data_objects.api.AMRHierarchy.save_object`. + """ + if filename is not None: + ds = shelve.open(filename, protocol=-1) + if name in ds: + mylog.info("Overwriting %s in %s", name, filename) + ds[name] = self + ds.close() + else: + self.hierarchy.save_object(self, name) + + def __reduce__(self): + args = tuple([self.pf._hash(), self._type_name] + + [getattr(self, n) for n in self._con_args] + + [self.field_parameters]) + return (_reconstruct_object, args) + + def __repr__(self): + # We'll do this the slow way to be clear what's going on + s = "%s (%s): " % (self.__class__.__name__, self.pf) + s += ", ".join(["%s=%s" % (i, getattr(self,i)) + for i in self._con_args]) + return s + +class GridPropertiesMixin(object): + + def select_grids(self, level): + """ + Return all grids on a given level. + """ + grids = [g for g in self._grids if g.Level == level] + return grids + + def select_grid_indices(self, level): + return na.where(self.grid_levels == level) + + def __get_grid_left_edge(self): + if self.__grid_left_edge == None: + self.__grid_left_edge = na.array([g.LeftEdge for g in self._grids]) + return self.__grid_left_edge + + def __del_grid_left_edge(self): + del self.__grid_left_edge + self.__grid_left_edge = None + + def __set_grid_left_edge(self, val): + self.__grid_left_edge = val + + __grid_left_edge = None + grid_left_edge = property(__get_grid_left_edge, __set_grid_left_edge, + __del_grid_left_edge) + + def __get_grid_right_edge(self): + if self.__grid_right_edge == None: + self.__grid_right_edge = na.array([g.RightEdge for g in self._grids]) + return self.__grid_right_edge + + def __del_grid_right_edge(self): + del self.__grid_right_edge + self.__grid_right_edge = None + + def __set_grid_right_edge(self, val): + self.__grid_right_edge = val + + __grid_right_edge = None + grid_right_edge = property(__get_grid_right_edge, __set_grid_right_edge, + __del_grid_right_edge) + + def __get_grid_levels(self): + if self.__grid_levels == None: + self.__grid_levels = na.array([g.Level for g in self._grids]) + return self.__grid_levels + + def __del_grid_levels(self): + del self.__grid_levels + self.__grid_levels = None + + def __set_grid_levels(self, val): + self.__grid_levels = val + + __grid_levels = None + grid_levels = property(__get_grid_levels, __set_grid_levels, + __del_grid_levels) + + +class AMR1DData(AMRData, GridPropertiesMixin): + _spatial = False + def __init__(self, pf, fields, **kwargs): + AMRData.__init__(self, pf, fields, **kwargs) + self._grids = None + self._sortkey = None + self._sorted = {} + + def _generate_field_in_grids(self, field, num_ghost_zones=0): + for grid in self._grids: + temp = grid[field] + + def _generate_field(self, field): + if self.pf.field_info.has_key(field): + # First we check the validator + try: + self.pf.field_info[field].check_available(self) + except NeedsGridType, ngt_exception: + # We leave this to be implementation-specific + self._generate_field_in_grids(field, ngt_exception.ghost_zones) + return False + else: + self[field] = self.pf.field_info[field](self) + return True + else: # Can't find the field, try as it might + raise KeyError(field) + + def get_data(self, fields=None, in_grids=False): + if self._grids == None: + self._get_list_of_grids() + points = [] + if not fields: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(fields) + if not self.sort_by in fields_to_get and \ + self.sort_by not in self.data: + fields_to_get.insert(0, self.sort_by) + mylog.debug("Going to obtain %s", fields_to_get) + for field in fields_to_get: + if self.data.has_key(field): + continue + mylog.info("Getting field %s from %s", field, len(self._grids)) + if field not in self.hierarchy.field_list and not in_grids: + if field not in ("dts", "t") and self._generate_field(field): + continue # True means we already assigned it + self[field] = na.concatenate( + [self._get_data_from_grid(grid, field) + for grid in self._grids]) + if not self.data.has_key(field): + continue + if self._sortkey is None: + self._sortkey = na.argsort(self[self.sort_by]) + # We *always* sort the field here if we have not successfully + # generated it above. This way, fields that are grabbed from the + # grids are sorted properly. + self[field] = self[field][self._sortkey] + +class AMROrthoRayBase(AMR1DData): + _key_fields = ['x','y','z','dx','dy','dz'] + _type_name = "ortho_ray" + _con_args = ('axis', 'coords') + def __init__(self, axis, coords, fields=None, pf=None, **kwargs): + """ + Dimensionality is reduced to one, and an ordered list of points at an + (x,y) tuple along *axis* are available. + """ + AMR1DData.__init__(self, pf, fields, **kwargs) + self.axis = axis + self.px_ax = x_dict[self.axis] + self.py_ax = y_dict[self.axis] + self.px_dx = 'd%s'%(axis_names[self.px_ax]) + self.py_dx = 'd%s'%(axis_names[self.py_ax]) + self.px, self.py = coords + self.sort_by = axis_names[self.axis] + self._refresh_data() + + def _get_list_of_grids(self): + # This bugs me, but we will give the tie to the LeftEdge + y = na.where( (self.px >= self.pf.hierarchy.grid_left_edge[:,self.px_ax]) + & (self.px < self.pf.hierarchy.grid_right_edge[:,self.px_ax]) + & (self.py >= self.pf.hierarchy.grid_left_edge[:,self.py_ax]) + & (self.py < self.pf.hierarchy.grid_right_edge[:,self.py_ax])) + self._grids = self.hierarchy.grids[y] + + def _get_data_from_grid(self, grid, field): + # We are orthogonal, so we can feel free to make assumptions + # for the sake of speed. + if grid.id not in self._cut_masks: + gdx = just_one(grid[self.px_dx]) + gdy = just_one(grid[self.py_dx]) + x_coord = int((self.px - grid.LeftEdge[self.px_ax])/gdx) + y_coord = int((self.py - grid.LeftEdge[self.py_ax])/gdy) + sl = [None,None,None] + sl[self.px_ax] = slice(x_coord,x_coord+1,None) + sl[self.py_ax] = slice(y_coord,y_coord+1,None) + sl[self.axis] = slice(None) + self._cut_masks[grid.id] = sl + else: + sl = self._cut_masks[grid.id] + if not iterable(grid[field]): + gf = grid[field] * na.ones(grid.child_mask[sl].shape) + else: + gf = grid[field][sl] + return gf[na.where(grid.child_mask[sl])] + +class AMRRayBase(AMR1DData): + _type_name = "ray" + _con_args = ('start_point', 'end_point') + sort_by = 't' + def __init__(self, start_point, end_point, fields=None, pf=None, **kwargs): + """ + We accept a start point and an end point and then get all the data + between those two. + """ + AMR1DData.__init__(self, pf, fields, **kwargs) + self.start_point = na.array(start_point, dtype='float64') + self.end_point = na.array(end_point, dtype='float64') + self.vec = self.end_point - self.start_point + #self.vec /= na.sqrt(na.dot(self.vec, self.vec)) + self._set_center(self.start_point) + self.set_field_parameter('center', self.start_point) + self._dts, self._ts = {}, {} + #self._refresh_data() + + def _get_list_of_grids(self): + # Get the value of the line at each LeftEdge and RightEdge + LE = self.pf.h.grid_left_edge + RE = self.pf.h.grid_right_edge + p = na.zeros(self.pf.h.num_grids, dtype='bool') + # Check left faces first + for i in range(3): + i1 = (i+1) % 3 + i2 = (i+2) % 3 + vs = self._get_line_at_coord(LE[:,i], i) + p = p | ( ( (LE[:,i1] <= vs[:,i1]) & (RE[:,i1] >= vs[:,i1]) ) \ + & ( (LE[:,i2] <= vs[:,i2]) & (RE[:,i2] >= vs[:,i2]) ) ) + vs = self._get_line_at_coord(RE[:,i], i) + p = p | ( ( (LE[:,i1] <= vs[:,i1]) & (RE[:,i1] >= vs[:,i1]) ) \ + & ( (LE[:,i2] <= vs[:,i2]) & (RE[:,i2] >= vs[:,i2]) ) ) + p = p | ( na.all( LE <= self.start_point, axis=1 ) + & na.all( RE >= self.start_point, axis=1 ) ) + p = p | ( na.all( LE <= self.end_point, axis=1 ) + & na.all( RE >= self.end_point, axis=1 ) ) + self._grids = self.hierarchy.grids[p] + + def _get_line_at_coord(self, v, index): + # t*self.vec + self.start_point = self.end_point + t = (v - self.start_point[index])/self.vec[index] + t = t.reshape((t.shape[0],1)) + return self.start_point + t*self.vec + + def _get_data_from_grid(self, grid, field): + mask = na.logical_and(self._get_cut_mask(grid), + grid.child_mask) + if field == 'dts': return self._dts[grid.id][mask] + if field == 't': return self._ts[grid.id][mask] + return grid[field][mask] + + @cache_mask + def _get_cut_mask(self, grid): + mask = na.zeros(grid.ActiveDimensions, dtype='int') + dts = na.zeros(grid.ActiveDimensions, dtype='float64') + ts = na.zeros(grid.ActiveDimensions, dtype='float64') + VoxelTraversal(mask, ts, dts, grid.LeftEdge, grid.RightEdge, + grid.dds, self.center, self.vec) + self._dts[grid.id] = na.abs(dts) + self._ts[grid.id] = na.abs(ts) + return mask + +class AMR2DData(AMRData, GridPropertiesMixin, ParallelAnalysisInterface): + _key_fields = ['px','py','pdx','pdy'] + """ + Class to represent a set of :class:`AMRData` that's 2-D in nature, and + thus does not have as many actions as the 3-D data types. + """ + _spatial = False + def __init__(self, axis, fields, pf=None, **kwargs): + """ + Prepares the AMR2DData, normal to *axis*. If *axis* is 4, we are not + aligned with any axis. + """ + self.axis = axis + AMRData.__init__(self, pf, fields, **kwargs) + self.field = ensure_list(fields)[0] + self.set_field_parameter("axis",axis) + + def _convert_field_name(self, field): + return field + + #@time_execution + def get_data(self, fields = None): + """ + Iterates over the list of fields and generates/reads them all. + """ + # We get it for the values in fields and coords + # We take a 3-tuple of the coordinate we want to slice through, as well + # as the axis we're slicing along + self._get_list_of_grids() + if not self.has_key('pdx'): + self._generate_coords() + if fields == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(fields) + temp_data = {} + for field in fields_to_get: + if self.data.has_key(field): continue + if field not in self.hierarchy.field_list: + if self._generate_field(field): + continue # A "True" return means we did it + # To ensure that we use data from this object as much as possible, + # we're going to have to set the same thing several times + data = [self._get_data_from_grid(grid, field) + for grid in self._get_grids()] + if len(data) == 0: data = na.array([]) + else: data = na.concatenate(data) + temp_data[field] = data + # Now the next field can use this field + self[field] = temp_data[field] + # We finalize + if temp_data != {}: + temp_data = self._mpi_catdict(temp_data) + # And set, for the next group + for field in temp_data.keys(): + self[field] = temp_data[field] + + + def _generate_field(self, field): + if self.pf.field_info.has_key(field): + # First we check the validator + try: + self.pf.field_info[field].check_available(self) + except NeedsGridType, ngt_exception: + # We leave this to be implementation-specific + self._generate_field_in_grids(field, ngt_exception.ghost_zones) + return False + else: + self[field] = self.pf.field_info[field](self) + return True + else: # Can't find the field, try as it might + raise KeyError(field) + + def _generate_field_in_grids(self, field, num_ghost_zones=0): + for grid in self._grids: + temp = grid[field] + + def interpolate_discretize(self, LE, RE, field, side, log_spacing=True): + """ + This returns a uniform grid of points between *LE* and *RE*, + interpolated using the nearest neighbor method, with *side* points on a + side. + """ + import yt.utilities.delaunay as de + if log_spacing: + zz = na.log10(self[field]) + else: + zz = self[field] + xi, yi = na.array( \ + na.mgrid[LE[0]:RE[0]:side*1j, \ + LE[1]:RE[1]:side*1j], 'float64') + zi = de.Triangulation(self['px'],self['py']).nn_interpolator(zz)\ + [LE[0]:RE[0]:side*1j, \ + LE[1]:RE[1]:side*1j] + if log_spacing: + zi = 10**(zi) + return [xi,yi,zi] + + _okay_to_serialize = True + + def _store_fields(self, fields, node_name = None, force = False): + fields = ensure_list(fields) + if node_name is None: node_name = self._gen_node_name() + for field in fields: + #mylog.debug("Storing %s in node %s", + #self._convert_field_name(field), node_name) + self.hierarchy.save_data(self[field], node_name, + self._convert_field_name(field), force = force, + passthrough = True) + + def _obtain_fields(self, fields, node_name = None): + if not self._okay_to_serialize: return + fields = ensure_list(fields) + if node_name is None: node_name = self._gen_node_name() + for field in fields: + #mylog.debug("Trying to obtain %s from node %s", + #self._convert_field_name(field), node_name) + fdata=self.hierarchy.get_data(node_name, + self._convert_field_name(field)) + if fdata is not None: + #mylog.debug("Got %s from node %s", field, node_name) + self[field] = fdata[:] + return True + + def _deserialize(self, node_name = None): + if not self._okay_to_serialize: return + self._obtain_fields(self._key_fields, node_name) + self._obtain_fields(self.fields, node_name) + + def _serialize(self, node_name = None, force = False): + if not self._okay_to_serialize: return + self._store_fields(self._key_fields, node_name, force) + self._store_fields(self.fields, node_name, force) + +class AMRSliceBase(AMR2DData): + """ + AMRSlice is an orthogonal slice through the data, taking all the points + at the finest resolution available and then indexing them. It is more + appropriately thought of as a slice 'operator' than an object, + however, as its field and coordinate can both change. + """ + + _top_node = "/Slices" + _type_name = "slice" + _con_args = ('axis', 'coord') + #@time_execution + def __init__(self, axis, coord, fields = None, center=None, pf=None, + node_name = False, **kwargs): + """ + Slice along *axis*:ref:`axis-specification`, at the coordinate *coord*. + Optionally supply fields. + """ + AMR2DData.__init__(self, axis, fields, pf, **kwargs) + self._set_center(center) + self.coord = coord + if node_name is False: + self._refresh_data() + else: + if node_name is True: self._deserialize() + else: self._deserialize(node_name) + + def reslice(self, coord): + """ + Change the entire dataset, clearing out the current data and slicing at + a new location. Not terribly useful except for in-place plot changes. + """ + mylog.debug("Setting coordinate to %0.5e" % coord) + self.coord = coord + self._refresh_data() + + def shift(self, val): + """ + Moves the slice coordinate up by either a floating point value, or an + integer number of indices of the finest grid. + """ + if isinstance(val, types.FloatType): + # We add the dx + self.coord += val + elif isinstance(val, types.IntType): + # Here we assume that the grid is the max level + level = self.hierarchy.max_level + self.coord + dx = self.hierarchy.select_grids(level)[0].dds[self.axis] + self.coord += dx * val + else: + raise ValueError(val) + self._refresh_data() + + def _generate_coords(self): + points = [] + for grid in self._get_grids(): + points.append(self._generate_grid_coords(grid)) + if len(points) == 0: points = None + else: points = na.concatenate(points) + t = self._mpi_catarray(points) + self['px'] = t[:,0] + self['py'] = t[:,1] + self['pz'] = t[:,2] + self['pdx'] = t[:,3] + self['pdy'] = t[:,4] + self['pdz'] = t[:,3] # Does not matter! + + # Now we set the *actual* coordinates + self[axis_names[x_dict[self.axis]]] = t[:,0] + self[axis_names[y_dict[self.axis]]] = t[:,1] + self[axis_names[self.axis]] = t[:,2] + + self.ActiveDimensions = (t.shape[0], 1, 1) + + def _get_list_of_grids(self): + goodI = ((self.pf.h.grid_right_edge[:,self.axis] > self.coord) + & (self.pf.h.grid_left_edge[:,self.axis] <= self.coord )) + self._grids = self.pf.h.grids[goodI] # Using sources not hierarchy + + def __cut_mask_child_mask(self, grid): + mask = grid.child_mask.copy() + return mask + + def _generate_grid_coords(self, grid): + xaxis = x_dict[self.axis] + yaxis = y_dict[self.axis] + ds, dx, dy = grid.dds[self.axis], grid.dds[xaxis], grid.dds[yaxis] + wantedIndex = int(((self.coord-grid.LeftEdge[self.axis])/ds)) + sl = [slice(None), slice(None), slice(None)] + sl[self.axis] = slice(wantedIndex, wantedIndex + 1) + #sl.reverse() + sl = tuple(sl) + nx = grid.child_mask.shape[xaxis] + ny = grid.child_mask.shape[yaxis] + mask = self.__cut_mask_child_mask(grid)[sl] + cm = na.where(mask.ravel()== 1) + cmI = na.indices((nx,ny)) + xind = cmI[0,:].ravel() + xpoints = na.ones(cm[0].shape, 'float64') + xpoints *= xind[cm]*dx+(grid.LeftEdge[xaxis] + 0.5*dx) + yind = cmI[1,:].ravel() + ypoints = na.ones(cm[0].shape, 'float64') + ypoints *= yind[cm]*dy+(grid.LeftEdge[yaxis] + 0.5*dy) + zpoints = na.ones(xpoints.shape, 'float64') * self.coord + dx = na.ones(xpoints.shape, 'float64') * dx/2.0 + dy = na.ones(xpoints.shape, 'float64') * dy/2.0 + t = na.array([xpoints, ypoints, zpoints, dx, dy]).swapaxes(0,1) + return t + + @restore_grid_state + def _get_data_from_grid(self, grid, field): + # So what's our index of slicing? This is what we need to figure out + # first, so we can deal with our data in the fastest way. + dx = grid.dds[self.axis] + wantedIndex = int(((self.coord-grid.LeftEdge[self.axis])/dx)) + sl = [slice(None), slice(None), slice(None)] + sl[self.axis] = slice(wantedIndex, wantedIndex + 1) + sl = tuple(sl) + if self.pf.field_info.has_key(field) and self.pf.field_info[field].particle_type: + return grid[field] + elif field in self.pf.field_info and self.pf.field_info[field].not_in_all: + dv = grid[field][sl] + elif not grid.has_key(field): + conv_factor = 1.0 + if self.pf.field_info.has_key(field): + conv_factor = self.pf.field_info[field]._convert_function(self) + dv = self.hierarchy.io._read_data_slice(grid, field, self.axis, wantedIndex) * conv_factor + else: + dv = grid[field] + if dv.size == 1: dv = na.ones(grid.ActiveDimensions)*dv + dv = dv[sl] + mask = self.__cut_mask_child_mask(grid)[sl] + dataVals = dv.ravel()[mask.ravel() == 1] + return dataVals + + def _gen_node_name(self): + return "%s/%s_%s" % \ + (self._top_node, self.axis, self.coord) + + def __get_quantities(self): + if self.__quantities is None: + self.__quantities = DerivedQuantityCollection(self) + return self.__quantities + __quantities = None + quantities = property(__get_quantities) + +class AMRCuttingPlaneBase(AMR2DData): + """ + AMRCuttingPlane is an oblique plane through the data, + defined by a normal vector and a coordinate. It attempts to guess + an 'up' vector, which cannot be overridden, and then it pixelizes + the appropriate data onto the plane without interpolation. + """ + _plane = None + _top_node = "/CuttingPlanes" + _key_fields = AMR2DData._key_fields + ['pz','pdz'] + _type_name = "cutting" + _con_args = ('normal', 'center') + def __init__(self, normal, center, fields = None, node_name = None, + **kwargs): + """ + The Cutting Plane slices at an oblique angle, where we use + the *normal* vector and the *center* to define the viewing plane. + The 'up' direction is guessed at automatically. + """ + AMR2DData.__init__(self, 4, fields, **kwargs) + self._set_center(center) + self.set_field_parameter('center',center) + # Let's set up our plane equation + # ax + by + cz + d = 0 + self._norm_vec = normal/na.sqrt(na.dot(normal,normal)) + self._d = -1.0 * na.dot(self._norm_vec, self.center) + # First we try all three, see which has the best result: + vecs = na.identity(3) + _t = na.cross(self._norm_vec, vecs).sum(axis=1) + ax = _t.argmax() + self._x_vec = na.cross(vecs[ax,:], self._norm_vec).ravel() + self._x_vec /= na.sqrt(na.dot(self._x_vec, self._x_vec)) + self._y_vec = na.cross(self._norm_vec, self._x_vec).ravel() + self._y_vec /= na.sqrt(na.dot(self._y_vec, self._y_vec)) + self._rot_mat = na.array([self._x_vec,self._y_vec,self._norm_vec]) + self._inv_mat = na.linalg.pinv(self._rot_mat) + self.set_field_parameter('cp_x_vec',self._x_vec) + self.set_field_parameter('cp_y_vec',self._y_vec) + self.set_field_parameter('cp_z_vec',self._norm_vec) + if node_name is False: + self._refresh_data() + else: + if node_name is True: self._deserialize() + else: self._deserialize(node_name) + + @property + def normal(self): + return self._norm_vec + + def _get_list_of_grids(self): + # Recall that the projection of the distance vector from a point + # onto the normal vector of a plane is: + # D = (a x_0 + b y_0 + c z_0 + d)/sqrt(a^2+b^2+c^2) + # @todo: Convert to using corners + LE = self.pf.h.grid_left_edge + RE = self.pf.h.grid_right_edge + vertices = na.array([[LE[:,0],LE[:,1],LE[:,2]], + [RE[:,0],RE[:,1],RE[:,2]], + [LE[:,0],LE[:,1],RE[:,2]], + [RE[:,0],RE[:,1],LE[:,2]], + [LE[:,0],RE[:,1],RE[:,2]], + [RE[:,0],LE[:,1],LE[:,2]], + [LE[:,0],RE[:,1],LE[:,2]], + [RE[:,0],LE[:,1],RE[:,2]]]) + # This gives us shape: 8, 3, n_grid + D = na.sum(self._norm_vec.reshape((1,3,1)) * vertices, axis=1) + self._d + self.D = D + self._grids = self.hierarchy.grids[ + na.where(na.logical_not(na.all(D<0,axis=0) | na.all(D>0,axis=0) )) ] + + @cache_mask + def _get_cut_mask(self, grid): + # This is slow. Suggestions for improvement would be great... + ss = grid.ActiveDimensions + D = na.ones(ss) * self._d + x = grid.LeftEdge[0] + grid.dds[0] * \ + (na.arange(grid.ActiveDimensions[0], dtype='float64')+0.5) + y = grid.LeftEdge[1] + grid.dds[1] * \ + (na.arange(grid.ActiveDimensions[1], dtype='float64')+0.5) + z = grid.LeftEdge[2] + grid.dds[2] * \ + (na.arange(grid.ActiveDimensions[2], dtype='float64')+0.5) + D += (x * self._norm_vec[0]).reshape(ss[0],1,1) + D += (y * self._norm_vec[1]).reshape(1,ss[1],1) + D += (z * self._norm_vec[2]).reshape(1,1,ss[2]) + diag_dist = na.sqrt(na.sum(grid.dds**2.0)) + cm = (na.abs(D) <= 0.5*diag_dist) # Boolean + return cm + + def _generate_coords(self): + points = [] + for grid in self._get_grids(): + points.append(self._generate_grid_coords(grid)) + if len(points) == 0: points = None + else: points = na.concatenate(points) + t = self._mpi_catarray(points) + pos = (t[:,0:3] - self.center) + self['px'] = na.dot(pos, self._x_vec) + self['py'] = na.dot(pos, self._y_vec) + self['pz'] = na.dot(pos, self._norm_vec) + self['pdx'] = t[:,3] * 0.5 + self['pdy'] = t[:,3] * 0.5 + self['pdz'] = t[:,3] * 0.5 + + def _generate_grid_coords(self, grid): + pointI = self._get_point_indices(grid) + coords = [grid[ax][pointI].ravel() for ax in 'xyz'] + coords.append(na.ones(coords[0].shape, 'float64') * just_one(grid['dx'])) + return na.array(coords).swapaxes(0,1) + + def _get_data_from_grid(self, grid, field): + if not self.pf.field_info[field].particle_type: + pointI = self._get_point_indices(grid) + if grid[field].size == 1: # dx, dy, dz, cellvolume + t = grid[field] * na.ones(grid.ActiveDimensions) + return t[pointI].ravel() + return grid[field][pointI].ravel() + else: + return grid[field] + + def interpolate_discretize(self, *args, **kwargs): + pass + + @cache_point_indices + def _get_point_indices(self, grid, use_child_mask=True): + k = na.zeros(grid.ActiveDimensions, dtype='bool') + k = (k | self._get_cut_mask(grid)) + if use_child_mask: k = (k & grid.child_mask) + return na.where(k) + + def _gen_node_name(self): + cen_name = ("%s" % (self.center,)).replace(" ","_")[1:-1] + L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1] + return "%s/c%s_L%s" % \ + (self._top_node, cen_name, L_name) + +class AMRFixedResCuttingPlaneBase(AMR2DData): + """ + AMRFixedResCuttingPlaneBase is an oblique plane through the data, + defined by a normal vector and a coordinate. It trilinearly + interpolates the data to a fixed resolution slice. It differs from + the other data objects as it doesn't save the grid data, only the + interpolated data. + """ + _top_node = "/FixedResCuttingPlanes" + _type_name = "fixed_res_cutting" + _con_args = ('normal', 'center', 'width', 'dims') + def __init__(self, normal, center, width, dims, fields = None, + node_name = None, **kwargs): + """ + The fixed resolution Cutting Plane slices at an oblique angle, + where we use the *normal* vector at the *center* to define the + viewing plane. The plane is *width* units wide. The 'up' + direction is guessed at automatically if not given. + """ + # + # Taken from Cutting Plane + # + AMR2DData.__init__(self, 4, fields, **kwargs) + self.center = center + self.width = width + self.dims = dims + self.dds = self.width / self.dims + self.bounds = na.array([0.0,1.0,0.0,1.0]) + + self.set_field_parameter('center', center) + # Let's set up our plane equation + # ax + by + cz + d = 0 + self._norm_vec = normal/na.sqrt(na.dot(normal,normal)) + self._d = -1.0 * na.dot(self._norm_vec, self.center) + # First we try all three, see which has the best result: + vecs = na.identity(3) + _t = na.cross(self._norm_vec, vecs).sum(axis=1) + ax = _t.argmax() + self._x_vec = na.cross(vecs[ax,:], self._norm_vec).ravel() + self._x_vec /= na.sqrt(na.dot(self._x_vec, self._x_vec)) + self._y_vec = na.cross(self._norm_vec, self._x_vec).ravel() + self._y_vec /= na.sqrt(na.dot(self._y_vec, self._y_vec)) + self._rot_mat = na.array([self._x_vec,self._y_vec,self._norm_vec]) + self._inv_mat = na.linalg.pinv(self._rot_mat) + self.set_field_parameter('cp_x_vec',self._x_vec) + self.set_field_parameter('cp_y_vec',self._y_vec) + self.set_field_parameter('cp_z_vec',self._norm_vec) + + # Calculate coordinates of each pixel + _co = self.dds * \ + (na.mgrid[-self.dims/2 : self.dims/2, + -self.dims/2 : self.dims/2] + 0.5) + self._coord = self.center + na.outer(_co[0,:,:], self._x_vec) + \ + na.outer(_co[1,:,:], self._y_vec) + self._pixelmask = na.ones(self.dims*self.dims, dtype='int8') + + if node_name is False: + self._refresh_data() + else: + if node_name is True: self._deserialize() + else: self._deserialize(node_name) + + @property + def normal(self): + return self._norm_vec + + def _get_list_of_grids(self): + # Just like the Cutting Plane but restrict the grids to be + # within width/2 of the center. + vertices = self.hierarchy.gridCorners + # Shape = (8,3,n_grid) + D = na.sum(self._norm_vec.reshape((1,3,1)) * vertices, axis=1) + self._d + valid_grids = na.where(na.logical_not(na.all(D<0,axis=0) | + na.all(D>0,axis=0) ))[0] + # Now restrict these grids to a rect. prism that bounds the slice + sliceCorners = na.array([ \ + self.center + 0.5*self.width * (+self._x_vec + self._y_vec), + self.center + 0.5*self.width * (+self._x_vec - self._y_vec), + self.center + 0.5*self.width * (-self._x_vec - self._y_vec), + self.center + 0.5*self.width * (-self._x_vec + self._y_vec) ]) + sliceLeftEdge = sliceCorners.min(axis=0) + sliceRightEdge = sliceCorners.max(axis=0) + # Check for bounding box and grid overlap + leftOverlap = na.less(self.hierarchy.gridLeftEdge[valid_grids], + sliceRightEdge).all(axis=1) + rightOverlap = na.greater(self.hierarchy.gridRightEdge[valid_grids], + sliceLeftEdge).all(axis=1) + self._grids = self.hierarchy.grids[valid_grids[ + na.where(leftOverlap & rightOverlap)]] + self._grids = self._grids[::-1] + + def _generate_coords(self): + self['px'] = self._coord[:,0].ravel() + self['py'] = self._coord[:,1].ravel() + self['pz'] = self._coord[:,2].ravel() + self['pdx'] = self.dds * 0.5 + self['pdy'] = self.dds * 0.5 + #self['pdz'] = self.dds * 0.5 + + def _get_data_from_grid(self, grid, field): + if not self.pf.field_info[field].particle_type: + pointI = self._get_point_indices(grid) + if len(pointI) == 0: return + vc = self._calc_vertex_centered_data(grid, field) + bds = na.array(zip(grid.LeftEdge, + grid.RightEdge)).ravel() + interp = TrilinearFieldInterpolator(vc, bds, ['x', 'y', 'z']) + self[field][pointI] = interp( \ + dict(x=self._coord[pointI,0], + y=self._coord[pointI,1], + z=self._coord[pointI,2])).ravel() + + # Mark these pixels to speed things up + self._pixelmask[pointI] = 0 + + return + else: + raise SyntaxError("Making a fixed resolution slice with " + "particles isn't supported yet.") + + def reslice(self, normal, center, width): + + # Cleanup + del self._coord + del self._pixelmask + + self.center = center + self.width = width + self.dds = self.width / self.dims + self.set_field_parameter('center', center) + self._norm_vec = normal/na.sqrt(na.dot(normal,normal)) + self._d = -1.0 * na.dot(self._norm_vec, self.center) + # First we try all three, see which has the best result: + vecs = na.identity(3) + _t = na.cross(self._norm_vec, vecs).sum(axis=1) + ax = _t.argmax() + self._x_vec = na.cross(vecs[ax,:], self._norm_vec).ravel() + self._x_vec /= na.sqrt(na.dot(self._x_vec, self._x_vec)) + self._y_vec = na.cross(self._norm_vec, self._x_vec).ravel() + self._y_vec /= na.sqrt(na.dot(self._y_vec, self._y_vec)) + self.set_field_parameter('cp_x_vec',self._x_vec) + self.set_field_parameter('cp_y_vec',self._y_vec) + self.set_field_parameter('cp_z_vec',self._norm_vec) + # Calculate coordinates of each pixel + _co = self.dds * \ + (na.mgrid[-self.dims/2 : self.dims/2, + -self.dims/2 : self.dims/2] + 0.5) + + self._coord = self.center + na.outer(_co[0,:,:], self._x_vec) + \ + na.outer(_co[1,:,:], self._y_vec) + self._pixelmask = na.ones(self.dims*self.dims, dtype='int8') + + self._refresh_data() + return + + #@time_execution + def get_data(self, fields = None): + """ + Iterates over the list of fields and generates/reads them all. + """ + self._get_list_of_grids() + if not self.has_key('pdx'): + self._generate_coords() + if fields == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(fields) + temp_data = {} + _size = self.dims * self.dims + for field in fields_to_get: + if self.data.has_key(field): continue + if field not in self.hierarchy.field_list: + if self._generate_field(field): + continue # A "True" return means we did it + if not self._vc_data.has_key(field): + self._vc_data[field] = {} + self[field] = na.zeros(_size, dtype='float64') + for grid in self._get_grids(): + self._get_data_from_grid(grid, field) + self[field] = self._mpi_allsum(\ + self[field]).reshape([self.dims]*2).transpose() + + def interpolate_discretize(self, *args, **kwargs): + pass + + @cache_vc_data + def _calc_vertex_centered_data(self, grid, field): + #return grid.retrieve_ghost_zones(1, field, smoothed=False) + return grid.get_vertex_centered_data(field) + + def _get_point_indices(self, grid): + if self._pixelmask.max() == 0: return [] + k = planar_points_in_volume(self._coord, self._pixelmask, + grid.LeftEdge, grid.RightEdge, + grid.child_mask, just_one(grid['dx'])) + return k + + def _gen_node_name(self): + cen_name = ("%s" % (self.center,)).replace(" ","_")[1:-1] + L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1] + return "%s/c%s_L%s" % \ + (self._top_node, cen_name, L_name) + +class AMRQuadTreeProjBase(AMR2DData): + _top_node = "/Projections" + _key_fields = AMR2DData._key_fields + ['weight_field'] + _type_name = "quad_proj" + _con_args = ('axis', 'field', 'weight_field') + def __init__(self, axis, field, weight_field = None, + max_level = None, center = None, pf = None, + source=None, node_name = None, field_cuts = None, + preload_style='level', serialize=True,**kwargs): + """ + AMRProj is a projection of a *field* along an *axis*. The field + can have an associated *weight_field*, in which case the values are + multiplied by a weight before being summed, and then divided by the sum + of that weight. + """ + AMR2DData.__init__(self, axis, field, pf, node_name = None, **kwargs) + self.weight_field = weight_field + self._field_cuts = field_cuts + self.serialize = serialize + self._set_center(center) + if center is not None: self.set_field_parameter('center',center) + self._node_name = node_name + self._initialize_source(source) + self.func = na.sum # for the future + self._grids = self.source._grids + if max_level == None: + max_level = self.hierarchy.max_level + if self.source is not None: + max_level = min(max_level, self.source.grid_levels.max()) + self._max_level = max_level + self._weight = weight_field + self.preload_style = preload_style + self._deserialize(node_name) + self._refresh_data() + if self._okay_to_serialize and self.serialize: self._serialize(node_name=self._node_name) + + def _convert_field_name(self, field): + if field == "weight_field": return "weight_field_%s" % self._weight + if field in self._key_fields: return field + return "%s_%s" % (field, self._weight) + + def _initialize_source(self, source = None): + if source is None: + check, source = self._partition_hierarchy_2d(self.axis) + self._check_region = check + #self._okay_to_serialize = (not check) + else: + self._distributed = False + self._okay_to_serialize = False + self._check_region = True + self.source = source + if self._field_cuts is not None: + # Override if field cuts are around; we don't want to serialize! + self._check_region = True + self._okay_to_serialize = False + if self._node_name is not None: + self._node_name = "%s/%s" % (self._top_node,self._node_name) + self._okay_to_serialize = True + + def _get_tree(self, nvals): + xd = self.pf["TopGridDimensions"][x_dict[self.axis]] + yd = self.pf["TopGridDimensions"][y_dict[self.axis]] + return QuadTree(na.array([xd,yd]), nvals) + + def _get_dls(self, grid, fields): + # Place holder for a time when maybe we will not be doing just + # a single dx for every field. + dls = [] + convs = [] + for field in fields + [self._weight]: + if field is None: continue + dls.append(just_one(grid['d%s' % axis_names[self.axis]])) + convs.append(self.pf.units[self.pf.field_info[field].projection_conversion]) + return na.array(dls), na.array(convs) + + def get_data(self, fields = None): + if fields is None: fields = ensure_list(self.fields)[:] + else: fields = ensure_list(fields) + # We need a new tree for every single set of fields we add + self._obtain_fields(fields, self._node_name) + fields = [f for f in fields if f not in self.data] + if len(fields) == 0: return + tree = self._get_tree(len(fields) + int(self._weight is not None)) + coord_data = [] + field_data = [] + dxs = [] + # We do this here, but I am not convinced it should be done here + # It is probably faster, as it consolidates IO, but if we did it in + # _project_level, then it would be more memory conservative + if self.preload_style == 'all': + print "Preloading %s grids and getting %s" % ( + len(self.source._grids), self._get_dependencies(fields)) + self._preload(self.source._grids, + self._get_dependencies(fields), self.hierarchy.io) + # By changing the remove-from-tree method to accumulate, we can avoid + # having to do this by level, and instead do it by CPU file + for level in range(0, self._max_level+1): + if self.preload_style == 'level': + self._preload(self.source.select_grids(level), + self._get_dependencies(fields), self.hierarchy.io) + self._add_level_to_tree(tree, level, fields) + mylog.debug("End of projecting level level %s, memory usage %0.3e", + level, get_memory_usage()/1024.) + # Note that this will briefly double RAM usage + coord_data, field_data, weight_data, dxs = [], [], [], [] + for level in range(0, self._max_level + 1): + npos, nvals, nwvals = tree.get_all_from_level(level, False) + coord_data.append(npos) + if self._weight is not None: nvals /= nwvals + field_data.append(nvals) + weight_data.append(nwvals) + gs = self.source.select_grids(level) + if len(gs) > 0: + ds = gs[0].dds[0] + else: + ds = 0.0 + dxs.append(na.ones(nvals.shape[0], dtype='float64') * ds) + del tree + coord_data = na.concatenate(coord_data, axis=0).transpose() + field_data = na.concatenate(field_data, axis=0).transpose() + weight_data = na.concatenate(weight_data, axis=0).transpose() + dxs = na.concatenate(dxs, axis=0).transpose() + # We now convert to half-widths and center-points + data = {} + data['pdx'] = dxs + ox = self.pf["DomainLeftEdge"][x_dict[self.axis]] + oy = self.pf["DomainLeftEdge"][y_dict[self.axis]] + data['px'] = (coord_data[0,:]+0.5) * data['pdx'] + ox + data['py'] = (coord_data[1,:]+0.5) * data['pdx'] + oy + data['weight_field'] = weight_data + del coord_data + data['pdx'] *= 0.5 + data['pdy'] = data['pdx'] # generalization is out the window! + data['fields'] = field_data + # Now we run the finalizer, which is ignored if we don't need it + data = self._mpi_catdict(data) + field_data = na.vsplit(data.pop('fields'), len(fields)) + for fi, field in enumerate(fields): + self[field] = field_data[fi].ravel() + if self.serialize: self._store_fields(field, self._node_name) + for i in data.keys(): self[i] = data.pop(i) + mylog.info("Projection completed") + + def _add_grid_to_tree(self, tree, grid, fields, zero_out, dls): + # We build up the fields to add + if self._weight is None: + weight_data = na.ones(grid.ActiveDimensions, dtype='float64') + if zero_out: weight_data[grid.child_indices] = 0 + masked_data = [fd.astype('float64') * weight_data + for fd in self._get_data_from_grid(grid, fields)] + wdl = 1.0 + else: + fields_to_get = list(set(fields + [self._weight])) + field_data = dict(zip( + fields_to_get, self._get_data_from_grid(grid, fields_to_get))) + weight_data = field_data[self._weight].copy().astype('float64') + if zero_out: weight_data[grid.child_indices] = 0 + masked_data = [field_data[field].copy().astype('float64') * weight_data + for field in fields] + del field_data + wdl = self.dls[-1] + full_proj = [self.func(field, axis=self.axis) * dl + for field, dl in zip(masked_data, dls)] + weight_proj = self.func(weight_data, axis=self.axis) * wdl + if (self._check_region and not self.source._is_fully_enclosed(grid)) or self._field_cuts is not None: + used_data = self._get_points_in_region(grid).astype('bool') + used_points = na.where(na.logical_or.reduce(used_data, self.axis)) + else: + used_data = na.array([1.0], dtype='bool') + used_points = slice(None) + xind, yind = [arr[used_points].ravel() for arr in na.indices(full_proj[0].shape)] + start_index = grid.get_global_startindex() + xpoints = (xind + (start_index[x_dict[self.axis]])).astype('int64') + ypoints = (yind + (start_index[y_dict[self.axis]])).astype('int64') + to_add = na.array([d[used_points].ravel() for d in full_proj]) + tree.add_array_to_tree(grid.Level, xpoints, ypoints, + to_add, weight_proj[used_points].ravel()) + + def _add_level_to_tree(self, tree, level, fields): + grids_to_project = self.source.select_grids(level) + dls, convs = self._get_dls(grids_to_project[0], fields) + zero_out = (level != self._max_level) + pbar = get_pbar('Projecting level % 2i / % 2i ' \ + % (level, self._max_level), len(grids_to_project)) + for pi, grid in enumerate(grids_to_project): + self._add_grid_to_tree(tree, grid, fields, zero_out, dls) + pbar.update(pi) + grid.clear_data() + pbar.finish() + lt = tree.get_all_from_level(level, False) + return + if self._weight is not None: + field_data = field_data / coord_data[3,:].reshape((1,coord_data.shape[1])) + else: + field_data *= convs[...,na.newaxis] + mylog.info("Level %s done: %s final", \ + level, coord_data.shape[1]) + dx = grids_to_project[0].dds[self.axis] # this is our dl + return coord_data, dx, field_data + + + def _get_points_in_region(self, grid): + pointI = self.source._get_point_indices(grid, use_child_mask=False) + point_mask = na.zeros(grid.ActiveDimensions) + point_mask[pointI] = 1.0 + if self._field_cuts is not None: + for cut in self._field_cuts: + point_mask *= eval(cut) + return point_mask + + @restore_grid_state + def _get_data_from_grid(self, grid, fields): + fields = ensure_list(fields) + if self._check_region: + bad_points = self._get_points_in_region(grid) + else: + bad_points = 1.0 + return [grid[field] * bad_points for field in fields] + + def _gen_node_name(self): + return "%s/%s" % \ + (self._top_node, self.axis) + +class AMRQuadTreeProjBase(AMR2DData): + _top_node = "/Projections" + _key_fields = AMR2DData._key_fields + ['weight_field'] + _type_name = "quad_proj" + _con_args = ('axis', 'field', 'weight_field') + def __init__(self, axis, field, weight_field = None, + max_level = None, center = None, pf = None, + source=None, node_name = None, field_cuts = None, + preload_style='level', serialize=True,**kwargs): + """ + AMRProj is a projection of a *field* along an *axis*. The field + can have an associated *weight_field*, in which case the values are + multiplied by a weight before being summed, and then divided by the sum + of that weight. + """ + AMR2DData.__init__(self, axis, field, pf, node_name = None, **kwargs) + self.weight_field = weight_field + self._field_cuts = field_cuts + self.serialize = serialize + self._set_center(center) + if center is not None: self.set_field_parameter('center',center) + self._node_name = node_name + self._initialize_source(source) + self.func = na.sum # for the future + self._grids = self.source._grids + if max_level == None: + max_level = self.hierarchy.max_level + if self.source is not None: + max_level = min(max_level, self.source.grid_levels.max()) + self._max_level = max_level + self._weight = weight_field + self.preload_style = preload_style + self._deserialize(node_name) + self._refresh_data() + if self._okay_to_serialize and self.serialize: self._serialize(node_name=self._node_name) + + def _convert_field_name(self, field): + if field == "weight_field": return "weight_field_%s" % self._weight + if field in self._key_fields: return field + return "%s_%s" % (field, self._weight) + + def _initialize_source(self, source = None): + if source is None: + check, source = self._partition_hierarchy_2d(self.axis) + self._check_region = check + #self._okay_to_serialize = (not check) + else: + self._distributed = False + self._okay_to_serialize = False + self._check_region = True + self.source = source + if self._field_cuts is not None: + # Override if field cuts are around; we don't want to serialize! + self._check_region = True + self._okay_to_serialize = False + if self._node_name is not None: + self._node_name = "%s/%s" % (self._top_node,self._node_name) + self._okay_to_serialize = True + + def _get_tree(self, nvals): + xd = self.pf.domain_dimensions[x_dict[self.axis]] + yd = self.pf.domain_dimensions[y_dict[self.axis]] + return QuadTree(na.array([xd,yd]), nvals) + + def _get_dls(self, grid, fields): + # Place holder for a time when maybe we will not be doing just + # a single dx for every field. + dls = [] + convs = [] + for field in fields + [self._weight]: + if field is None: continue + dls.append(just_one(grid['d%s' % axis_names[self.axis]])) + convs.append(self.pf.units[self.pf.field_info[field].projection_conversion]) + return na.array(dls), na.array(convs) + + def get_data(self, fields = None): + if fields is None: fields = ensure_list(self.fields)[:] + else: fields = ensure_list(fields) + # We need a new tree for every single set of fields we add + self._obtain_fields(fields, self._node_name) + fields = [f for f in fields if f not in self.data] + if len(fields) == 0: return + tree = self._get_tree(len(fields) + int(self._weight is not None)) + coord_data = [] + field_data = [] + dxs = [] + # We do this here, but I am not convinced it should be done here + # It is probably faster, as it consolidates IO, but if we did it in + # _project_level, then it would be more memory conservative + if self.preload_style == 'all': + print "Preloading %s grids and getting %s" % ( + len(self.source._grids), self._get_dependencies(fields)) + self._preload(self.source._grids, + self._get_dependencies(fields), self.hierarchy.io) + # By changing the remove-from-tree method to accumulate, we can avoid + # having to do this by level, and instead do it by CPU file + for level in range(0, self._max_level+1): + if self.preload_style == 'level': + self._preload(self.source.select_grids(level), + self._get_dependencies(fields), self.hierarchy.io) + self._add_level_to_tree(tree, level, fields) + mylog.debug("End of projecting level level %s, memory usage %0.3e", + level, get_memory_usage()/1024.) + # Note that this will briefly double RAM usage + coord_data, field_data, weight_data, dxs = [], [], [], [] + for level in range(0, self._max_level + 1): + npos, nvals, nwvals = tree.get_all_from_level(level, False) + coord_data.append(npos) + if self._weight is not None: nvals /= nwvals + field_data.append(nvals) + weight_data.append(nwvals) + gs = self.source.select_grids(level) + if len(gs) > 0: + ds = gs[0].dds[0] + else: + ds = 0.0 + dxs.append(na.ones(nvals.shape[0], dtype='float64') * ds) + del tree + coord_data = na.concatenate(coord_data, axis=0).transpose() + field_data = na.concatenate(field_data, axis=0).transpose() + weight_data = na.concatenate(weight_data, axis=0).transpose() + dxs = na.concatenate(dxs, axis=0).transpose() + # We now convert to half-widths and center-points + data = {} + data['pdx'] = dxs + ox = self.pf.domain_left_edge[x_dict[self.axis]] + oy = self.pf.domain_left_edge[y_dict[self.axis]] + data['px'] = (coord_data[0,:]+0.5) * data['pdx'] + ox + data['py'] = (coord_data[1,:]+0.5) * data['pdx'] + oy + data['weight_field'] = weight_data + del coord_data + data['pdx'] *= 0.5 + data['pdy'] = data['pdx'] # generalization is out the window! + data['fields'] = field_data + # Now we run the finalizer, which is ignored if we don't need it + data = self._mpi_catdict(data) + field_data = na.vsplit(data.pop('fields'), len(fields)) + for fi, field in enumerate(fields): + self[field] = field_data[fi].ravel() + if self.serialize: self._store_fields(field, self._node_name) + for i in data.keys(): self[i] = data.pop(i) + mylog.info("Projection completed") + + def _add_grid_to_tree(self, tree, grid, fields, zero_out, dls): + # We build up the fields to add + if self._weight is None: + weight_data = na.ones(grid.ActiveDimensions, dtype='float64') + if zero_out: weight_data[grid.child_indices] = 0 + masked_data = [fd.astype('float64') * weight_data + for fd in self._get_data_from_grid(grid, fields)] + wdl = 1.0 + else: + fields_to_get = list(set(fields + [self._weight])) + field_data = dict(zip( + fields_to_get, self._get_data_from_grid(grid, fields_to_get))) + weight_data = field_data[self._weight].copy().astype('float64') + if zero_out: weight_data[grid.child_indices] = 0 + masked_data = [field_data[field].copy().astype('float64') * weight_data + for field in fields] + del field_data + wdl = self.dls[-1] + full_proj = [self.func(field, axis=self.axis) * dl + for field, dl in zip(masked_data, dls)] + weight_proj = self.func(weight_data, axis=self.axis) * wdl + if (self._check_region and not self.source._is_fully_enclosed(grid)) or self._field_cuts is not None: + used_data = self._get_points_in_region(grid).astype('bool') + used_points = na.where(na.logical_or.reduce(used_data, self.axis)) + else: + used_data = na.array([1.0], dtype='bool') + used_points = slice(None) + xind, yind = [arr[used_points].ravel() for arr in na.indices(full_proj[0].shape)] + start_index = grid.get_global_startindex() + xpoints = (xind + (start_index[x_dict[self.axis]])).astype('int64') + ypoints = (yind + (start_index[y_dict[self.axis]])).astype('int64') + to_add = na.array([d[used_points].ravel() for d in full_proj]) + tree.add_array_to_tree(grid.Level, xpoints, ypoints, + to_add, weight_proj[used_points].ravel()) + + def _add_level_to_tree(self, tree, level, fields): + grids_to_project = self.source.select_grids(level) + dls, convs = self._get_dls(grids_to_project[0], fields) + zero_out = (level != self._max_level) + pbar = get_pbar('Projecting level % 2i / % 2i ' \ + % (level, self._max_level), len(grids_to_project)) + for pi, grid in enumerate(grids_to_project): + self._add_grid_to_tree(tree, grid, fields, zero_out, dls) + pbar.update(pi) + grid.clear_data() + pbar.finish() + lt = tree.get_all_from_level(level, False) + return + if self._weight is not None: + field_data = field_data / coord_data[3,:].reshape((1,coord_data.shape[1])) + else: + field_data *= convs[...,na.newaxis] + mylog.info("Level %s done: %s final", \ + level, coord_data.shape[1]) + dx = grids_to_project[0].dds[self.axis] # this is our dl + return coord_data, dx, field_data + + + def _get_points_in_region(self, grid): + pointI = self.source._get_point_indices(grid, use_child_mask=False) + point_mask = na.zeros(grid.ActiveDimensions) + point_mask[pointI] = 1.0 + if self._field_cuts is not None: + for cut in self._field_cuts: + point_mask *= eval(cut) + return point_mask + + @restore_grid_state + def _get_data_from_grid(self, grid, fields): + fields = ensure_list(fields) + if self._check_region: + bad_points = self._get_points_in_region(grid) + else: + bad_points = 1.0 + return [grid[field] * bad_points for field in fields] + + def _gen_node_name(self): + return "%s/%s" % \ + (self._top_node, self.axis) + + +class AMRProjBase(AMR2DData): + _top_node = "/Projections" + _key_fields = AMR2DData._key_fields + ['weight_field'] + _type_name = "proj" + _con_args = ('axis', 'field', 'weight_field') + def __init__(self, axis, field, weight_field = None, + max_level = None, center = None, pf = None, + source=None, node_name = None, field_cuts = None, + preload_style='level', serialize=True,**kwargs): + """ + AMRProj is a projection of a *field* along an *axis*. The field + can have an associated *weight_field*, in which case the values are + multiplied by a weight before being summed, and then divided by the sum + of that weight. + """ + AMR2DData.__init__(self, axis, field, pf, node_name = None, **kwargs) + self.weight_field = weight_field + self._field_cuts = field_cuts + self.serialize = serialize + self._set_center(center) + if center is not None: self.set_field_parameter('center',center) + self._node_name = node_name + self._initialize_source(source) + self._grids = self.source._grids + if max_level == None: + max_level = self.hierarchy.max_level + if self.source is not None: + max_level = min(max_level, self.source.grid_levels.max()) + self._max_level = max_level + self._weight = weight_field + self.preload_style = preload_style + self.func = na.sum # for the future + self.__retval_coords = {} + self.__retval_fields = {} + self.__retval_coarse = {} + self.__overlap_masks = {} + self._deserialize(node_name) + self._refresh_data() + if self._okay_to_serialize and self.serialize: self._serialize(node_name=self._node_name) + + def _convert_field_name(self, field): + if field == "weight_field": return "weight_field_%s" % self._weight + if field in self._key_fields: return field + return "%s_%s" % (field, self._weight) + + def _initialize_source(self, source = None): + if source is None: + check, source = self._partition_hierarchy_2d(self.axis) + self._check_region = check + #self._okay_to_serialize = (not check) + else: + self._distributed = False + self._okay_to_serialize = False + self._check_region = True + self.source = source + if self._field_cuts is not None: + # Override if field cuts are around; we don't want to serialize! + self._check_region = True + self._okay_to_serialize = False + if self._node_name is not None: + self._node_name = "%s/%s" % (self._top_node,self._node_name) + self._okay_to_serialize = True + + #@time_execution + def __calculate_overlap(self, level): + s = self.source + mylog.info("Generating overlap masks for level %s", level) + i = 0 + pbar = get_pbar("Reading and masking grids ", len(s._grids)) + mylog.debug("Examining level %s", level) + grids = s.select_grid_indices(level) + RE = s.grid_right_edge[grids] + LE = s.grid_left_edge[grids] + for grid in s._grids[grids]: + pbar.update(i) + self.__overlap_masks[grid.id] = \ + grid._generate_overlap_masks(self.axis, LE, RE) + i += 1 + pbar.finish() + mylog.info("Finished calculating overlap.") + + def _get_dls(self, grid, fields): + # Place holder for a time when maybe we will not be doing just + # a single dx for every field. + dls = [] + convs = [] + for field in fields + [self._weight]: + if field is None: continue + dls.append(just_one(grid['d%s' % axis_names[self.axis]])) + convs.append(self.pf.units[self.pf.field_info[field].projection_conversion]) + return na.array(dls), na.array(convs) + + def __project_level(self, level, fields): + grids_to_project = self.source.select_grids(level) + dls, convs = self._get_dls(grids_to_project[0], fields) + zero_out = (level != self._max_level) + pbar = get_pbar('Projecting level % 2i / % 2i ' \ + % (level, self._max_level), len(grids_to_project)) + for pi, grid in enumerate(grids_to_project): + g_coords, g_fields = self._project_grid(grid, fields, zero_out) + self.__retval_coords[grid.id] = g_coords + self.__retval_fields[grid.id] = g_fields + for fi in range(len(fields)): g_fields[fi] *= dls[fi] + if self._weight is not None: g_coords[3] *= dls[-1] + pbar.update(pi) + grid.clear_data() + pbar.finish() + self.__combine_grids_on_level(level) # In-place + if level > 0 and level <= self._max_level: + self.__refine_to_level(level) # In-place + coord_data = [] + field_data = [] + for grid in grids_to_project: + coarse = self.__retval_coords[grid.id][2]==0 # Where childmask = 0 + fine = ~coarse + coord_data.append([pi[fine] for pi in self.__retval_coords[grid.id]]) + field_data.append([pi[fine] for pi in self.__retval_fields[grid.id]]) + self.__retval_coords[grid.id] = [pi[coarse] for pi in self.__retval_coords[grid.id]] + self.__retval_fields[grid.id] = [pi[coarse] for pi in self.__retval_fields[grid.id]] + coord_data = na.concatenate(coord_data, axis=1) + field_data = na.concatenate(field_data, axis=1) + if self._weight is not None: + field_data = field_data / coord_data[3,:].reshape((1,coord_data.shape[1])) + else: + field_data *= convs[...,na.newaxis] + mylog.info("Level %s done: %s final", \ + level, coord_data.shape[1]) + dx = grids_to_project[0].dds[self.axis] # this is our dl + return coord_data, dx, field_data + + def __combine_grids_on_level(self, level): + grids = self.source.select_grids(level) + grids_i = self.source.select_grid_indices(level) + pbar = get_pbar('Combining level % 2i / % 2i ' \ + % (level, self._max_level), len(grids)) + # We have an N^2 check, so we try to be as quick as possible + # and to skip as many as possible + for pi, grid1 in enumerate(grids): + pbar.update(pi) + if self.__retval_coords[grid1.id][0].shape[0] == 0: continue + for grid2 in self.source._grids[grids_i][self.__overlap_masks[grid1.id]]: + if self.__retval_coords[grid2.id][0].shape[0] == 0 \ + or grid1.id == grid2.id: + continue + args = [] # First is source, then destination + args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]] + args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]] + args.append(1) # Refinement factor + args.append(na.ones(args[0].shape, dtype='int64')) + kk = CombineGrids(*args) + goodI = args[-1].astype('bool') + self.__retval_coords[grid2.id] = \ + [coords[goodI] for coords in self.__retval_coords[grid2.id]] + self.__retval_fields[grid2.id] = \ + [fields[goodI] for fields in self.__retval_fields[grid2.id]] + pbar.finish() + + def __refine_to_level(self, level): + grids = self.source.select_grids(level) + grids_up = self.source.select_grid_indices(level - 1) + pbar = get_pbar('Refining to level % 2i / % 2i ' \ + % (level, self._max_level), len(grids)) + for pi, grid1 in enumerate(grids): + pbar.update(pi) + for parent in ensure_list(grid1.Parent): + if parent.id not in self.__overlap_masks: continue + for grid2 in self.source._grids[grids_up][self.__overlap_masks[parent.id]]: + if self.__retval_coords[grid2.id][0].shape[0] == 0: continue + args = [] + args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]] + args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]] + # Refinement factor, which is same in all directions. Note + # that this complicated rounding is because sometimes + # epsilon differences in dds between the grids causes this + # to round to up or down from the expected value. + args.append(int(na.rint(grid2.dds / grid1.dds)[0])) + args.append(na.ones(args[0].shape, dtype='int64')) + kk = CombineGrids(*args) + goodI = args[-1].astype('bool') + self.__retval_coords[grid2.id] = \ + [coords[goodI] for coords in self.__retval_coords[grid2.id]] + self.__retval_fields[grid2.id] = \ + [fields[goodI] for fields in self.__retval_fields[grid2.id]] + for grid1 in self.source.select_grids(level-1): + if not self._check_region and self.__retval_coords[grid1.id][0].size != 0: + mylog.error("Something messed up, and %s still has %s points of data", + grid1, self.__retval_coords[grid1.id][0].size) + mylog.error("You might try setting the ReconstructHierarchy option in [lagos]") + raise ValueError(grid1, self.__retval_coords[grid1.id]) + pbar.finish() + + #@time_execution + def get_data(self, fields = None): + if fields is None: fields = ensure_list(self.fields)[:] + else: fields = ensure_list(fields) + self._obtain_fields(fields, self._node_name) + fields = [f for f in fields if f not in self.data] + if len(fields) == 0: return + coord_data = [] + field_data = [] + dxs = [] + # We do this here, but I am not convinced it should be done here + # It is probably faster, as it consolidates IO, but if we did it in + # _project_level, then it would be more memory conservative + if self.preload_style == 'all': + print "Preloading %s grids and getting %s" % ( + len(self.source._grids), self._get_dependencies(fields)) + self._preload(self.source._grids, + self._get_dependencies(fields), self.hierarchy.io) + for level in range(0, self._max_level+1): + if self.preload_style == 'level': + self._preload(self.source.select_grids(level), + self._get_dependencies(fields), self.hierarchy.io) + self.__calculate_overlap(level) + my_coords, my_dx, my_fields = self.__project_level(level, fields) + coord_data.append(my_coords) + field_data.append(my_fields) + dxs.append(my_dx * na.ones(my_coords.shape[1], dtype='float64')) + if self._check_region and False: + check=self.__cleanup_level(level - 1) + if len(check) > 0: all_data.append(check) + # Now, we should clean up after ourselves... + for grid in self.source.select_grids(level - 1): + del self.__retval_coords[grid.id] + del self.__retval_fields[grid.id] + del self.__overlap_masks[grid.id] + mylog.debug("End of projecting level level %s, memory usage %0.3e", + level, get_memory_usage()/1024.) + coord_data = na.concatenate(coord_data, axis=1) + field_data = na.concatenate(field_data, axis=1) + dxs = na.concatenate(dxs, axis=1) + # We now convert to half-widths and center-points + data = {} + data['pdx'] = dxs + ox = self.pf.domain_left_edge[x_dict[self.axis]] + oy = self.pf.domain_left_edge[y_dict[self.axis]] + data['px'] = (coord_data[0,:]+0.5) * data['pdx'] + ox + data['py'] = (coord_data[1,:]+0.5) * data['pdx'] + oy + data['weight_field'] = coord_data[3,:].copy() + del coord_data + data['pdx'] *= 0.5 + data['pdy'] = data['pdx'] # generalization is out the window! + data['fields'] = field_data + # Now we run the finalizer, which is ignored if we don't need it + data = self._mpi_catdict(data) + field_data = na.vsplit(data.pop('fields'), len(fields)) + for fi, field in enumerate(fields): + self[field] = field_data[fi].ravel() + if self.serialize: self._store_fields(field, self._node_name) + for i in data.keys(): self[i] = data.pop(i) + mylog.info("Projection completed") + + def add_fields(self, fields, weight = "CellMassMsun"): + pass + + def _project_grid(self, grid, fields, zero_out): + # We split this next bit into two sections to try to limit the IO load + # on the system. This way, we perserve grid state (@restore_grid_state + # in _get_data_from_grid *and* we attempt not to load weight data + # independently of the standard field data. + if self._weight is None: + weight_data = na.ones(grid.ActiveDimensions, dtype='float64') + if zero_out: weight_data[grid.child_indices] = 0 + masked_data = [fd.astype('float64') * weight_data + for fd in self._get_data_from_grid(grid, fields)] + else: + fields_to_get = list(set(fields + [self._weight])) + field_data = dict(zip( + fields_to_get, self._get_data_from_grid(grid, fields_to_get))) + weight_data = field_data[self._weight].copy().astype('float64') + if zero_out: weight_data[grid.child_indices] = 0 + masked_data = [field_data[field].copy().astype('float64') * weight_data + for field in fields] + del field_data + # if we zero it out here, then we only have to zero out the weight! + full_proj = [self.func(field, axis=self.axis) for field in masked_data] + weight_proj = self.func(weight_data, axis=self.axis) + if (self._check_region and not self.source._is_fully_enclosed(grid)) or self._field_cuts is not None: + used_data = self._get_points_in_region(grid).astype('bool') + used_points = na.where(na.logical_or.reduce(used_data, self.axis)) + else: + used_data = na.array([1.0], dtype='bool') + used_points = slice(None) + if zero_out: + subgrid_mask = na.logical_and.reduce( + na.logical_or(grid.child_mask, + ~used_data), + self.axis).astype('int64') + else: + subgrid_mask = na.ones(full_proj[0].shape, dtype='int64') + xind, yind = [arr[used_points].ravel() for arr in na.indices(full_proj[0].shape)] + start_index = grid.get_global_startindex() + xpoints = (xind + (start_index[x_dict[self.axis]])).astype('int64') + ypoints = (yind + (start_index[y_dict[self.axis]])).astype('int64') + return ([xpoints, ypoints, + subgrid_mask[used_points].ravel(), + weight_proj[used_points].ravel()], + [data[used_points].ravel() for data in full_proj]) + + def _get_points_in_region(self, grid): + pointI = self.source._get_point_indices(grid, use_child_mask=False) + point_mask = na.zeros(grid.ActiveDimensions) + point_mask[pointI] = 1.0 + if self._field_cuts is not None: + for cut in self._field_cuts: + point_mask *= eval(cut) + return point_mask + + @restore_grid_state + def _get_data_from_grid(self, grid, fields): + fields = ensure_list(fields) + if self._check_region: + bad_points = self._get_points_in_region(grid) + else: + bad_points = 1.0 + return [grid[field] * bad_points for field in fields] + + def _gen_node_name(self): + return "%s/%s" % \ + (self._top_node, self.axis) + +class AMRFixedResProjectionBase(AMR2DData): + _top_node = "/Projections" + _type_name = "fixed_res_proj" + _con_args = ('axis', 'field', 'weight_field') + def __init__(self, axis, level, left_edge, dims, + fields = None, pf=None, **kwargs): + """ + A projection that provides fixed resolution output, + operating in a grid-by-grid fashion. + """ + AMR2DData.__init__(self, axis, fields, pf, **kwargs) + self.left_edge = na.array(left_edge) + self.level = level + self.dds = self.pf.h.select_grids(self.level)[0].dds.copy() + self.dims = na.array([dims]*2) + self.ActiveDimensions = na.array([dims]*3, dtype='int32') + self.right_edge = self.left_edge + self.ActiveDimensions*self.dds + self.global_startindex = na.rint((self.left_edge - self.pf.domain_left_edge) + /self.dds).astype('int64') + self._dls = {} + self.domain_width = na.rint((self.pf.domain_right_edge - + self.pf.domain_left_edge)/self.dds).astype('int64') + + def _get_list_of_grids(self): + if self._grids is not None: return + if na.any(self.left_edge < self.pf.domain_left_edge) or \ + na.any(self.right_edge > self.pf.domain_right_edge): + grids,ind = self.pf.hierarchy.get_periodic_box_grids( + self.left_edge, self.right_edge) + ind = slice(None) + else: + grids,ind = self.pf.hierarchy.get_box_grids( + self.left_edge, self.right_edge) + level_ind = (self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) + sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) + self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)][::-1] + + def _generate_coords(self): + xax = x_dict[self.axis] + yax = y_dict[self.axis] + ci = self.left_edge + self.dds*0.5 + cf = self.left_edge + self.dds*(self.ActiveDimensions-0.5) + cx = na.mgrid[ci[xax]:cf[xax]:self.ActiveDimensions[xax]*1j] + cy = na.mgrid[ci[yax]:cf[yax]:self.ActiveDimensions[yax]*1j] + blank = na.ones( (self.ActiveDimensions[xax], + self.ActiveDimensions[yax]), dtype='float64') + self['px'] = cx[None,:] * blank + self['py'] = cx[:,None] * blank + self['pdx'] = self.dds[xax] + self['pdy'] = self.dds[yax] + + #@time_execution + def get_data(self, fields = None): + """ + Iterates over the list of fields and generates/reads them all. + """ + self._get_list_of_grids() + if not self.has_key('pdx'): + self._generate_coords() + if fields == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(fields) + temp_data = {} + for field in fields_to_get: + self[field] = na.zeros(self.dims, dtype='float64') + dls = self.__setup_dls(fields_to_get) + for i,grid in enumerate(self._get_grids()): + mylog.debug("Getting fields from %s", i) + self._get_data_from_grid(grid, fields_to_get, dls) + for field in fields_to_get: + self[field] = self._mpi_Allsum_double(self[field]) + conv = self.pf.units[self.pf.field_info[field].projection_conversion] + self[field] *= conv + + def __setup_dls(self, fields): + dls = {} + for level in range(self.level+1): + dls[level] = [] + grid = self.select_grids(level)[0] + for field in fields: + if field is None: continue + dls[level].append(float(just_one(grid['d%s' % axis_names[self.axis]]))) + return dls + + def _get_data_from_grid(self, grid, fields, dls): + g_fields = [grid[field] for field in fields] + c_fields = [self[field] for field in fields] + ref_ratio = self.pf.refine_by**(self.level - grid.Level) + FillBuffer(ref_ratio, + grid.get_global_startindex(), self.global_startindex, + c_fields, g_fields, + self.ActiveDimensions, grid.ActiveDimensions, + grid.child_mask, self.domain_width, dls[grid.Level], + self.axis) + +class AMR3DData(AMRData, GridPropertiesMixin): + _key_fields = ['x','y','z','dx','dy','dz'] + """ + Class describing a cluster of data points, not necessarily sharing any + particular attribute. + """ + _spatial = False + _num_ghost_zones = 0 + def __init__(self, center, fields, pf = None, **kwargs): + """ + Returns an instance of AMR3DData, or prepares one. Usually only + used as a base class. Note that *center* is supplied, but only used + for fields and quantities that require it. + """ + AMRData.__init__(self, pf, fields, **kwargs) + self._set_center(center) + self.set_field_parameter("center",center) + self.coords = None + self._grids = None + + def _generate_coords(self): + mylog.info("Generating coords for %s grids", len(self._grids)) + points = [] + for i,grid in enumerate(self._grids): + #grid._generate_coords() + if ( (i%100) == 0): + mylog.info("Working on % 7i / % 7i", i, len(self._grids)) + grid.set_field_parameter("center", self.center) + points.append((na.ones( + grid.ActiveDimensions,dtype='float64')*grid['dx'])\ + [self._get_point_indices(grid)]) + t = na.concatenate([t,points]) + del points + self['dx'] = t + #self['dy'] = t + #self['dz'] = t + mylog.info("Done with coordinates") + + @restore_grid_state + def _generate_grid_coords(self, grid, field=None): + pointI = self._get_point_indices(grid) + dx = na.ones(pointI[0].shape[0], 'float64') * grid.dds[0] + tr = na.array([grid['x'][pointI].ravel(), \ + grid['y'][pointI].ravel(), \ + grid['z'][pointI].ravel(), \ + grid["RadiusCode"][pointI].ravel(), + dx, grid["GridIndices"][pointI].ravel()], 'float64').swapaxes(0,1) + return tr + + def get_data(self, fields=None, in_grids=False, force_particle_read = False): + if self._grids == None: + self._get_list_of_grids() + points = [] + if not fields: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(fields) + mylog.debug("Going to obtain %s", fields_to_get) + for field in fields_to_get: + if self.data.has_key(field): + continue + if field not in self.hierarchy.field_list and not in_grids: + if self._generate_field(field): + continue # True means we already assigned it + # There are a lot of 'ands' here, but I think they are all + # necessary. + if force_particle_read == False and \ + self.pf.field_info.has_key(field) and \ + self.pf.field_info[field].particle_type and \ + self.pf.h.io._particle_reader: + self[field] = self.particles[field] + continue + mylog.info("Getting field %s from %s", field, len(self._grids)) + self[field] = na.concatenate( + [self._get_data_from_grid(grid, field) + for grid in self._grids]) + for field in fields_to_get: + if not self.data.has_key(field): + continue + self[field] = self[field] + + @restore_grid_state + def _get_data_from_grid(self, grid, field): + if field in self.pf.field_info and self.pf.field_info[field].particle_type: + # int64 -> float64 with the first real set of data + if grid.NumberOfParticles == 0: return na.array([], dtype='int64') + pointI = self._get_particle_indices(grid) + if self.pf.field_info[field].vector_field: + f = grid[field] + return na.array([f[i,:][pointI] for i in range(3)]) + if self._is_fully_enclosed(grid): return grid[field].ravel() + return grid[field][pointI].ravel() + if field in self.pf.field_info and self.pf.field_info[field].vector_field: + pointI = self._get_point_indices(grid) + f = grid[field] + return na.array([f[i,:][pointI] for i in range(3)]) + else: + pointI = self._get_point_indices(grid) + if grid[field].size == 1: # dx, dy, dz, cellvolume + t = grid[field] * na.ones(grid.ActiveDimensions, dtype='float64') + return t[pointI].ravel() + return grid[field][pointI].ravel() + + def _flush_data_to_grids(self, field, default_val, dtype='float32'): + """ + A dangerous, thusly underscored, thing to do to a data object, + we can flush back any changes in a given field that have been made + with a default value for the rest of the grid. + """ + i = 0 + for grid in self._grids: + pointI = self._get_point_indices(grid) + np = pointI[0].ravel().size + if grid.has_key(field): + new_field = grid[field] + else: + new_field = na.ones(grid.ActiveDimensions, dtype=dtype) * default_val + new_field[pointI] = self[field][i:i+np] + grid[field] = new_field + i += np + + def _generate_field(self, field): + if self.pf.field_info.has_key(field): + # First we check the validator + try: + self.pf.field_info[field].check_available(self) + except NeedsGridType, ngt_exception: + # We leave this to be implementation-specific + self._generate_field_in_grids(field, ngt_exception.ghost_zones) + return False + else: + self[field] = self.pf.field_info[field](self) + return True + else: # Can't find the field, try as it might + raise KeyError(field) + + def _generate_field_in_grids(self, field, num_ghost_zones=0): + for grid in self._grids: + self.__touch_grid_field(grid, field) + + @restore_grid_state + def __touch_grid_field(self, grid, field): + grid[field] + + def _is_fully_enclosed(self, grid): + return na.all(self._get_cut_mask) + + def _get_point_indices(self, grid, use_child_mask=True): + k = na.zeros(grid.ActiveDimensions, dtype='bool') + k = (k | self._get_cut_mask(grid)) + if use_child_mask: k = (k & grid.child_mask) + return na.where(k) + + def _get_cut_particle_mask(self, grid): + if self._is_fully_enclosed(grid): + return True + fake_grid = FakeGridForParticles(grid) + return self._get_cut_mask(fake_grid) + + def _get_particle_indices(self, grid): + k = na.zeros(grid.NumberOfParticles, dtype='bool') + k = (k | self._get_cut_particle_mask(grid)) + return na.where(k) + + def cut_region(self, field_cuts): + """ + Return an InLineExtractedRegion, where the grid cells are cut on the + fly with a set of field_cuts. + """ + return InLineExtractedRegionBase(self, field_cuts) + + def extract_region(self, indices): + """ + Return an ExtractedRegion where the points contained in it are defined + as the points in `this` data object with the given *indices*. + """ + return ExtractedRegionBase(self, indices) + + def __get_quantities(self): + if self.__quantities is None: + self.__quantities = DerivedQuantityCollection(self) + return self.__quantities + __quantities = None + quantities = property(__get_quantities) + + def extract_connected_sets(self, field, num_levels, min_val, max_val, + log_space=True, cumulative=True, cache=False): + """ + This function will create a set of contour objects, defined + by having connected cell structures, which can then be + studied and used to 'paint' their source grids, thus enabling + them to be plotted. + """ + if log_space: + cons = na.logspace(na.log10(min_val),na.log10(max_val), + num_levels+1) + else: + cons = na.linspace(min_val, max_val, num_levels+1) + contours = {} + if cache: cached_fields = defaultdict(lambda: dict()) + else: cached_fields = None + for level in range(num_levels): + contours[level] = {} + if cumulative: + mv = max_val + else: + mv = cons[level+1] + from yt.analysis_modules.level_sets.api import identify_contours + cids = identify_contours(self, field, cons[level], mv, + cached_fields) + for cid, cid_ind in cids.items(): + contours[level][cid] = self.extract_region(cid_ind) + return cons, contours + + def paint_grids(self, field, value, default_value=None): + """ + This function paints every cell in our dataset with a given *value*. + If default_value is given, the other values for the given in every grid + are discarded and replaced with *default_value*. Otherwise, the field is + mandated to 'know how to exist' in the grid. + + Note that this only paints the cells *in the dataset*, so cells in grids + with child cells are left untouched. + """ + for grid in self._grids: + if default_value != None: + grid[field] = na.ones(grid.ActiveDimensions)*default_value + grid[field][self._get_point_indices(grid)] = value + + _particle_handler = None + + @property + def particles(self): + if self._particle_handler is None: + self._particle_handler = \ + particle_handler_registry[self._type_name](self.pf, self) + return self._particle_handler + +class ExtractedRegionBase(AMR3DData): + """ + ExtractedRegions are arbitrarily defined containers of data, useful + for things like selection along a baryon field. + """ + _type_name = "extracted_region" + _con_args = ('_base_region', '_indices') + def __init__(self, base_region, indices, force_refresh=True, **kwargs): + cen = base_region.get_field_parameter("center") + AMR3DData.__init__(self, center=cen, + fields=None, pf=base_region.pf, **kwargs) + self._base_region = base_region # We don't weakly reference because + # It is not cyclic + if isinstance(indices, types.DictType): + self._indices = indices + self._grids = self._base_region.pf.h.grids[self._indices.keys()] + else: + self._grids = None + self._base_indices = indices + if force_refresh: self._refresh_data() + + def _get_cut_particle_mask(self, grid): + # Override to provide a warning + mylog.warning("Returning all particles from an Extracted Region. This could be incorrect!") + return True + + def _get_list_of_grids(self): + # Okay, so what we're going to want to do is get the pointI from + # region._get_point_indices(grid) for grid in base_region._grids, + # and then construct an array of those, which we will select along indices. + if self._grids != None: return + grid_vals, xi, yi, zi = [], [], [], [] + for grid in self._base_region._grids: + xit,yit,zit = self._base_region._get_point_indices(grid) + grid_vals.append(na.ones(xit.shape, dtype='int') * (grid.id-grid._id_offset)) + xi.append(xit) + yi.append(yit) + zi.append(zit) + grid_vals = na.concatenate(grid_vals)[self._base_indices] + grid_order = na.argsort(grid_vals) + # Note: grid_vals is still unordered + grid_ids = na.unique(grid_vals) + xi = na.concatenate(xi)[self._base_indices][grid_order] + yi = na.concatenate(yi)[self._base_indices][grid_order] + zi = na.concatenate(zi)[self._base_indices][grid_order] + bc = na.bincount(grid_vals) + splits = [] + for i,v in enumerate(bc): + if v > 0: splits.append(v) + splits = na.add.accumulate(splits) + xis, yis, zis = [na.array_split(aa, splits) for aa in [xi,yi,zi]] + self._indices = {} + h = self._base_region.pf.h + for grid_id, x, y, z in zip(grid_ids, xis, yis, zis): + # grid_id needs no offset + ll = h.grids[grid_id].ActiveDimensions.prod() \ + - (na.logical_not(h.grids[grid_id].child_mask)).sum() + # This means we're completely enclosed, except for child masks + if x.size == ll: + self._indices[grid_id] = None + else: + # This will slow things down a bit, but conserve memory + self._indices[grid_id] = \ + na.zeros(h.grids[grid_id].ActiveDimensions, dtype='bool') + self._indices[grid_id][(x,y,z)] = True + self._grids = h.grids[self._indices.keys()] + + def _is_fully_enclosed(self, grid): + if self._indices[grid.id-grid._id_offset] is None or \ + (self._indices[grid.id-grid._id_offset][0].size == + grid.ActiveDimensions.prod()): + return True + return False + + def _get_cut_mask(self, grid): + cm = na.zeros(grid.ActiveDimensions, dtype='bool') + cm[self._get_point_indices(grid, False)] = True + return cm + + __empty_array = na.array([], dtype='bool') + def _get_point_indices(self, grid, use_child_mask=True): + # Yeah, if it's not true, we don't care. + tr = self._indices.get(grid.id-grid._id_offset, self.__empty_array) + if tr is None: tr = na.where(grid.child_mask) + else: tr = na.where(tr) + return tr + + def __repr__(self): + # We'll do this the slow way to be clear what's going on + s = "%s (%s): " % (self.__class__.__name__, self.pf) + s += ", ".join(["%s=%s" % (i, getattr(self,i)) + for i in self._con_args if i != "_indices"]) + return s + + def join(self, other): + ng = {} + gs = set(self._indices.keys() + other._indices.keys()) + for g in gs: + grid = self.pf.h.grids[g] + if g in other._indices and g in self._indices: + # We now join the indices + ind = na.zeros(grid.ActiveDimensions, dtype='bool') + ind[self._indices[g]] = True + ind[other._indices[g]] = True + if ind.prod() == grid.ActiveDimensions.prod(): ind = None + elif g in self._indices: + ind = self._indices[g] + elif g in other._indices: + ind = other._indices[g] + # Okay we have indices + if ind is not None: ind = ind.copy() + ng[g] = ind + gl = self.pf.h.grids[list(gs)] + gc = self.pf.h.grid_collection( + self._base_region.get_field_parameter("center"), gl) + return self.pf.h.extracted_region(gc, ng) + +class InLineExtractedRegionBase(AMR3DData): + """ + In-line extracted regions accept a base region and a set of field_cuts to + determine which points in a grid should be included. + """ + def __init__(self, base_region, field_cuts, **kwargs): + cen = base_region.get_field_parameter("center") + AMR3DData.__init__(self, center=cen, + fields=None, pf=base_region.pf, **kwargs) + self._base_region = base_region # We don't weakly reference because + # It is not cyclic + self._field_cuts = ensure_list(field_cuts)[:] + self._refresh_data() + + def _get_list_of_grids(self): + self._grids = self._base_region._grids + + def _is_fully_enclosed(self, grid): + return False + + @cache_mask + def _get_cut_mask(self, grid): + point_mask = na.ones(grid.ActiveDimensions, dtype='bool') + point_mask *= self._base_region._get_cut_mask(grid) + for cut in self._field_cuts: + point_mask *= eval(cut) + return point_mask + +class AMRCylinderBase(AMR3DData): + """ + We can define a cylinder (or disk) to act as a data object. + """ + _type_name = "disk" + _con_args = ('center', '_norm_vec', '_radius', '_height') + def __init__(self, center, normal, radius, height, fields=None, + pf=None, **kwargs): + """ + By providing a *center*, a *normal*, a *radius* and a *height* we + can define a cylinder of any proportion. Only cells whose centers are + within the cylinder will be selected. + """ + AMR3DData.__init__(self, na.array(center), fields, pf, **kwargs) + self._norm_vec = na.array(normal)/na.sqrt(na.dot(normal,normal)) + self.set_field_parameter("height_vector", self._norm_vec) + self._height = height + self._radius = radius + self._d = -1.0 * na.dot(self._norm_vec, self.center) + self._refresh_data() + + def _get_list_of_grids(self): + H = na.sum(self._norm_vec.reshape((1,3,1)) * self.pf.h.grid_corners, + axis=1) + self._d + D = na.sqrt(na.sum((self.pf.h.grid_corners - + self.center.reshape((1,3,1)))**2.0,axis=1)) + R = na.sqrt(D**2.0-H**2.0) + self._grids = self.hierarchy.grids[ + ( (na.any(na.abs(H)0,axis=0) | (na.all(H<0, axis=0)))) ) + ) ) ] + self._grids = self.hierarchy.grids + + def _is_fully_enclosed(self, grid): + corners = grid._corners.reshape((8,3,1)) + H = na.sum(self._norm_vec.reshape((1,3,1)) * corners, + axis=1) + self._d + D = na.sqrt(na.sum((corners - + self.center.reshape((1,3,1)))**2.0,axis=1)) + R = na.sqrt(D**2.0-H**2.0) + return (na.all(na.abs(H) < self._height, axis=0) \ + and na.all(R < self._radius, axis=0)) + + @cache_mask + def _get_cut_mask(self, grid): + if self._is_fully_enclosed(grid): + return True + else: + h = grid['x'] * self._norm_vec[0] \ + + grid['y'] * self._norm_vec[1] \ + + grid['z'] * self._norm_vec[2] \ + + self._d + d = na.sqrt( + (grid['x'] - self.center[0])**2.0 + + (grid['y'] - self.center[1])**2.0 + + (grid['z'] - self.center[2])**2.0 + ) + r = na.sqrt(d**2.0-h**2.0) + cm = ( (na.abs(h) <= self._height) + & (r <= self._radius)) + return cm + + def volume(self, unit="unitary"): + """ + Return the volume of the cylinder in units of *unit*. + """ + return math.pi * (self._radius)**2. * self._height * pf[unit]**3 + +class AMRInclinedBox(AMR3DData): + _type_name="inclined_box" + _con_args = ('origin','box_vectors') + + def __init__(self, origin, box_vectors, fields=None, + pf=None, **kwargs): + """ + A rectangular prism with arbitrary alignment to the computational + domain. *origin* is the origin of the box, while *box_vectors* is an + array of ordering [ax, ijk] that describes the three vectors that + describe the box. No checks are done to ensure that the box satisfies + a right-hand rule, but if it doesn't, behavior is undefined. + """ + self.origin = na.array(origin) + self.box_vectors = na.array(box_vectors, dtype='float64') + self.box_lengths = (self.box_vectors**2.0).sum(axis=1)**0.5 + center = origin + 0.5*self.box_vectors.sum(axis=0) + AMR3DData.__init__(self, center, fields, pf, **kwargs) + self._setup_rotation_parameters() + self._refresh_data() + + def _setup_rotation_parameters(self): + xv = self.box_vectors[0,:] + yv = self.box_vectors[1,:] + zv = self.box_vectors[2,:] + self._x_vec = xv / na.sqrt(na.dot(xv, xv)) + self._y_vec = yv / na.sqrt(na.dot(yv, yv)) + self._z_vec = zv / na.sqrt(na.dot(zv, zv)) + self._rot_mat = na.array([self._x_vec,self._y_vec,self._z_vec]) + self._inv_mat = na.linalg.pinv(self._rot_mat) + + def _get_list_of_grids(self): + if self._grids is not None: return + GLE = self.pf.h.grid_left_edge + GRE = self.pf.h.grid_right_edge + goodI = find_grids_in_inclined_box(self.box_vectors, self.center, + GLE, GRE) + cgrids = self.pf.h.grids[goodI.astype('bool')] + # find_grids_in_inclined_box seems to be broken. + cgrids = self.pf.h.grids[:] + grids = [] + for i,grid in enumerate(cgrids): + v = grid_points_in_volume(self.box_lengths, self.origin, + self._rot_mat, grid.LeftEdge, + grid.RightEdge, grid.dds, + grid.child_mask, 1) + if v: grids.append(grid) + self._grids = na.array(grids, dtype='object') + + + def _is_fully_enclosed(self, grid): + # This should be written at some point. + # We'd rotate all eight corners into the space of the box, then check to + # see if all are enclosed. + return False + + def _get_cut_mask(self, grid): + if self._is_fully_enclosed(grid): + return True + pm = na.zeros(grid.ActiveDimensions, dtype='int32') + grid_points_in_volume(self.box_lengths, self.origin, + self._rot_mat, grid.LeftEdge, + grid.RightEdge, grid.dds, pm, 0) + return pm + + +class AMRRegionBase(AMR3DData): + """ + AMRRegions are rectangular prisms of data. + """ + _type_name = "region" + _con_args = ('center', 'left_edge', 'right_edge') + _dx_pad = 0.5 + def __init__(self, center, left_edge, right_edge, fields = None, + pf = None, **kwargs): + """ + We create an object with a set of three *left_edge* coordinates, + three *right_edge* coordinates, and a *center* that need not be the + center. + """ + AMR3DData.__init__(self, center, fields, pf, **kwargs) + self.left_edge = left_edge + self.right_edge = right_edge + self._refresh_data() + + def _get_list_of_grids(self): + self._grids, ind = self.pf.hierarchy.get_box_grids(self.left_edge, + self.right_edge) + + def _is_fully_enclosed(self, grid): + return na.all( (grid._corners <= self.right_edge) + & (grid._corners >= self.left_edge)) + + @cache_mask + def _get_cut_mask(self, grid): + if self._is_fully_enclosed(grid): + return True + else: + dxp, dyp, dzp = self._dx_pad * grid.dds + cm = ( (grid['x'] - dxp < self.right_edge[0]) + & (grid['x'] + dxp > self.left_edge[0]) + & (grid['y'] - dyp < self.right_edge[1]) + & (grid['y'] + dyp > self.left_edge[1]) + & (grid['z'] - dzp < self.right_edge[2]) + & (grid['z'] + dzp > self.left_edge[2]) ) + return cm + + def volume(self, unit = "unitary"): + """ + Return the volume of the region in units *unit*. + """ + diff = na.array(self.right_edge) - na.array(self.left_edge) + # Find the full volume + vol = na.prod(diff * self.pf[unit]) + return vol + +class AMRRegionStrictBase(AMRRegionBase): + """ + AMRRegion without any dx padding for cell selection + """ + _type_name = "region_strict" + _dx_pad = 0.0 + +class AMRPeriodicRegionBase(AMR3DData): + """ + AMRRegions are rectangular prisms of data. + """ + _type_name = "periodic_region" + _con_args = ('center', 'left_edge', 'right_edge') + _dx_pad = 0.5 + def __init__(self, center, left_edge, right_edge, fields = None, + pf = None, **kwargs): + """ + We create an object with a set of three *left_edge* coordinates, + three *right_edge* coordinates, and a *center* that need not be the + center. + """ + AMR3DData.__init__(self, center, fields, pf, **kwargs) + self.left_edge = na.array(left_edge) + self.right_edge = na.array(right_edge) + self._refresh_data() + self.offsets = (na.mgrid[-1:1:3j,-1:1:3j,-1:1:3j] * \ + (self.pf.domain_right_edge - + self.pf.domain_left_edge)[:,None,None,None])\ + .transpose().reshape(27,3) # cached and in order + + def _get_list_of_grids(self): + self._grids, ind = self.pf.hierarchy.get_periodic_box_grids(self.left_edge, + self.right_edge) + + def _is_fully_enclosed(self, grid): + for off_x, off_y, off_z in self.offsets: + region_left = [self.left_edge[0]+off_x, + self.left_edge[1]+off_y,self.left_edge[2]+off_z] + region_right = [self.right_edge[0]+off_x, + self.right_edge[1]+off_y,self.right_edge[2]+off_z] + if (na.all((grid._corners <= region_right) & + (grid._corners >= region_left))): + return True + return False + + @cache_mask + def _get_cut_mask(self, grid): + if self._is_fully_enclosed(grid): + return True + else: + cm = na.zeros(grid.ActiveDimensions,dtype='bool') + dxp, dyp, dzp = self._dx_pad * grid.dds + for off_x, off_y, off_z in self.offsets: + cm = cm | ( (grid['x'] - dxp + off_x < self.right_edge[0]) + & (grid['x'] + dxp + off_x > self.left_edge[0]) + & (grid['y'] - dyp + off_y < self.right_edge[1]) + & (grid['y'] + dyp + off_y > self.left_edge[1]) + & (grid['z'] - dzp + off_z < self.right_edge[2]) + & (grid['z'] + dzp + off_z > self.left_edge[2]) ) + return cm + + def volume(self, unit = "unitary"): + """ + Return the volume of the region in units *unit*. + """ + period = self.pf.domain_right_edge - self.pf.domain_left_edge + diff = na.array(self.right_edge) - na.array(self.left_edge) + # Correct for wrap-arounds. + tofix = (diff < 0) + toadd = period[tofix] + diff += toadd + # Find the full volume + vol = na.prod(diff * self.pf[unit]) + return vol + + +class AMRPeriodicRegionStrictBase(AMRPeriodicRegionBase): + """ + AMRPeriodicRegion without any dx padding for cell selection + """ + _type_name = "periodic_region_strict" + _dx_pad = 0.0 + +class AMRGridCollectionBase(AMR3DData): + """ + An arbitrary selection of grids, within which we accept all points. + """ + _type_name = "grid_collection" + _con_args = ("center", "grid_list") + def __init__(self, center, grid_list, fields = None, + pf = None, **kwargs): + """ + By selecting an arbitrary *grid_list*, we can act on those grids. + Child cells are not returned. + """ + AMR3DData.__init__(self, center, fields, pf, **kwargs) + self._grids = na.array(grid_list) + self.grid_list = self._grids + + def _get_list_of_grids(self): + pass + + def _is_fully_enclosed(self, grid): + return True + + @cache_mask + def _get_cut_mask(self, grid): + return na.ones(grid.ActiveDimensions, dtype='bool') + + def _get_point_indices(self, grid, use_child_mask=True): + k = na.ones(grid.ActiveDimensions, dtype='bool') + if use_child_mask: + k[grid.child_indices] = False + pointI = na.where(k == True) + return pointI + +class AMRSphereBase(AMR3DData): + """ + A sphere of points + """ + _type_name = "sphere" + _con_args = ('center', 'radius') + def __init__(self, center, radius, fields = None, pf = None, **kwargs): + """ + The most famous of all the data objects, we define it via a + *center* and a *radius*. + """ + AMR3DData.__init__(self, center, fields, pf, **kwargs) + if radius < self.hierarchy.get_smallest_dx(): + raise YTSphereTooSmall(pf, radius, self.hierarchy.get_smallest_dx()) + self.set_field_parameter('radius',radius) + self.radius = radius + self.DW = self.pf.domain_right_edge - self.pf.domain_left_edge + self._refresh_data() + + def _get_list_of_grids(self, field = None): + grids,ind = self.hierarchy.find_sphere_grids(self.center, self.radius) + # Now we sort by level + grids = grids.tolist() + grids.sort(key=lambda x: (x.Level, x.LeftEdge[0], x.LeftEdge[1], x.LeftEdge[2])) + self._grids = na.array(grids, dtype='object') + + def _is_fully_enclosed(self, grid): + r = na.abs(grid._corners - self.center) + r = na.minimum(r, na.abs(self.DW[None,:]-r)) + corner_radius = na.sqrt((r**2.0).sum(axis=1)) + return na.all(corner_radius <= self.radius) + + @restore_grid_state # Pains me not to decorate with cache_mask here + def _get_cut_mask(self, grid, field=None): + # We have the *property* center, which is not necessarily + # the same as the field_parameter + if self._is_fully_enclosed(grid): + return True # We do not want child masking here + if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)) \ + and grid.id in self._cut_masks: + return self._cut_masks[grid.id] + cm = ( (grid["RadiusCode"]<=self.radius) & grid.child_mask ) + if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)): + self._cut_masks[grid.id] = cm + return cm + + def volume(self, unit = "unitary"): + """ + Return the volume of the sphere in units *unit*. + """ + return 4./3. * math.pi * (self.radius * self.pf[unit])**3.0 + +class AMRFloatCoveringGridBase(AMR3DData): + """ + Covering grids represent fixed-resolution data over a given region. + In order to achieve this goal -- for instance in order to obtain ghost + zones -- grids up to and including the indicated level are included. + No interpolation is done (as that would affect the 'power' on small + scales) on the input data. + """ + _spatial = True + _type_name = "float_covering_grid" + _con_args = ('level', 'left_edge', 'right_edge', 'ActiveDimensions') + def __init__(self, level, left_edge, right_edge, dims, fields = None, + pf = None, num_ghost_zones = 0, use_pbar = True, **kwargs): + """ + The data object returned will consider grids up to *level* in + generating fixed resolution data between *left_edge* and *right_edge* + that is *dims* (3-values) on a side. + """ + AMR3DData.__init__(self, center=None, fields=fields, pf=pf, **kwargs) + self.left_edge = na.array(left_edge) + self.right_edge = na.array(right_edge) + self.level = level + self.ActiveDimensions = na.array(dims) + dds = (self.right_edge-self.left_edge) \ + / self.ActiveDimensions + self.dds = dds + self.data["dx"] = dds[0] + self.data["dy"] = dds[1] + self.data["dz"] = dds[2] + self._num_ghost_zones = num_ghost_zones + self._use_pbar = use_pbar + self._refresh_data() + + def _get_list_of_grids(self): + if self._grids is not None: return + if na.any(self.left_edge < self.pf.domain_left_edge) or \ + na.any(self.right_edge > self.pf.domain_right_edge): + grids,ind = self.pf.hierarchy.get_periodic_box_grids( + self.left_edge, self.right_edge) + ind = slice(None) + else: + grids,ind = self.pf.hierarchy.get_box_grids( + self.left_edge, self.right_edge) + level_ind = na.where(self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) + sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) + self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)][::-1] + + def extract_region(self, indices): + mylog.error("Sorry, dude, do it yourself, it's already in 3-D.") + + def _refresh_data(self): + AMR3DData._refresh_data(self) + self['dx'] = self.dds[0] * na.ones(self.ActiveDimensions, dtype='float64') + self['dy'] = self.dds[1] * na.ones(self.ActiveDimensions, dtype='float64') + self['dz'] = self.dds[2] * na.ones(self.ActiveDimensions, dtype='float64') + + def get_data(self, fields=None): + if self._grids is None: + self._get_list_of_grids() + if fields is None: + fields = self.fields[:] + else: + fields = ensure_list(fields) + obtain_fields = [] + for field in fields: + if self.data.has_key(field): continue + if field not in self.hierarchy.field_list: + try: + #print "Generating", field + self._generate_field(field) + continue + except NeedsOriginalGrid, ngt_exception: + pass + obtain_fields.append(field) + self[field] = na.zeros(self.ActiveDimensions, dtype='float64') -999 + if len(obtain_fields) == 0: return + mylog.debug("Getting fields %s from %s possible grids", + obtain_fields, len(self._grids)) + if self._use_pbar: pbar = \ + get_pbar('Searching grids for values ', len(self._grids)) + for i, grid in enumerate(self._grids): + if self._use_pbar: pbar.update(i) + self._get_data_from_grid(grid, obtain_fields) + if not na.any(self[obtain_fields[0]] == -999): break + if self._use_pbar: pbar.finish() + if na.any(self[obtain_fields[0]] == -999): + # and self.dx < self.hierarchy.grids[0].dx: + print "COVERING PROBLEM", na.where(self[obtain_fields[0]]==-999)[0].size + print na.where(self[obtain_fields[0]]==-999) + raise KeyError + + def _generate_field(self, field): + if self.pf.field_info.has_key(field): + # First we check the validator; this might even raise! + self.pf.field_info[field].check_available(self) + self[field] = self.pf.field_info[field](self) + else: # Can't find the field, try as it might + raise KeyError(field) + + def flush_data(self, field=None): + """ + Any modifications made to the data in this object are pushed back + to the originating grids, except the cells where those grids are both + below the current level `and` have child cells. + """ + self._get_list_of_grids() + # We don't generate coordinates here. + if field == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(field) + for grid in self._grids: + self._flush_data_to_grid(grid, fields_to_get) + + @restore_grid_state + def _get_data_from_grid(self, grid, fields): + ll = int(grid.Level == self.level) + g_dx = grid.dds.ravel() + c_dx = self.dds.ravel() + g_fields = [grid[field] for field in ensure_list(fields)] + c_fields = [self[field] for field in ensure_list(fields)] + DataCubeRefine( + grid.LeftEdge, g_dx, g_fields, grid.child_mask, + self.left_edge, self.right_edge, c_dx, c_fields, + ll, self.pf.domain_left_edge, self.pf.domain_right_edge) + + def _flush_data_to_grid(self, grid, fields): + ll = int(grid.Level == self.level) + g_dx = grid.dds.ravel() + c_dx = self.dds.ravel() + g_fields = [] + for field in ensure_list(fields): + if not grid.has_key(field): grid[field] = \ + na.zeros(grid.ActiveDimensions, dtype=self[field].dtype) + g_fields.append(grid[field]) + c_fields = [self[field] for field in ensure_list(fields)] + DataCubeReplace( + grid.LeftEdge, g_dx, g_fields, grid.child_mask, + self.left_edge, self.right_edge, c_dx, c_fields, + ll, self.pf.domain_left_edge, self.pf.domain_right_edge) + + @property + def LeftEdge(self): + return self.left_edge + + @property + def RightEdge(self): + return self.right_edge + +class AMRSmoothedCoveringGridBase(AMRFloatCoveringGridBase): + _type_name = "smoothed_covering_grid" + def __init__(self, *args, **kwargs): + dlog2 = na.log10(kwargs['dims'])/na.log10(2) + if not na.all(na.floor(dlog2) == na.ceil(dlog2)): + pass # used to warn but I think it is not accurate anymore + #mylog.warning("Must be power of two dimensions") + #raise ValueError + #kwargs['num_ghost_zones'] = 0 + AMRFloatCoveringGridBase.__init__(self, *args, **kwargs) + + def _get_list_of_grids(self): + if na.any(self.left_edge - self.dds < self.pf.domain_left_edge) or \ + na.any(self.right_edge + self.dds > self.pf.domain_right_edge): + grids,ind = self.pf.hierarchy.get_periodic_box_grids( + self.left_edge - self.dds, + self.right_edge + self.dds) + ind = slice(None) + else: + grids,ind = self.pf.hierarchy.get_box_grids( + self.left_edge - self.dds, + self.right_edge + self.dds) + level_ind = na.where(self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) + sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) + self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)] + + def _get_level_array(self, level, fields): + fields = ensure_list(fields) + # We assume refinement by a factor of two + rf = self.pf.refine_by**(self.level - level) + dims = na.maximum(1,self.ActiveDimensions/rf) + 2 + dx = (self.right_edge-self.left_edge)/(dims-2) + x,y,z = (na.mgrid[0:dims[0],0:dims[1],0:dims[2]].astype('float64')-0.5)\ + * dx[0] + x += self.left_edge[0] - dx[0] + y += self.left_edge[1] - dx[1] + z += self.left_edge[2] - dx[2] + offsets = [self['cd%s' % ax]*0.5 for ax in 'xyz'] + bounds = [self.left_edge[0]-offsets[0], self.right_edge[0]+offsets[0], + self.left_edge[1]-offsets[1], self.right_edge[1]+offsets[1], + self.left_edge[2]-offsets[2], self.right_edge[2]+offsets[2]] + fake_grid = {'x':x,'y':y,'z':z,'dx':dx[0],'dy':dx[1],'dz':dx[2]} + for ax in 'xyz': self['cd%s'%ax] = fake_grid['d%s'%ax] + for field in fields: + # Generate the new grid field + interpolator = TrilinearFieldInterpolator( + self[field], bounds, ['x','y','z'], + truncate = True) + self[field] = interpolator(fake_grid) + return fake_grid + + def get_data(self, field=None): + self._get_list_of_grids() + # We don't generate coordinates here. + if field == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(field) + for field in fields_to_get: + grid_count = 0 + if self.data.has_key(field): + continue + mylog.debug("Getting field %s from %s possible grids", + field, len(self._grids)) + if self._use_pbar: pbar = \ + get_pbar('Searching grids for values ', len(self._grids)) + # How do we find out the root grid base dx? + idims = na.array([3,3,3]) + dx = na.minimum((self.right_edge-self.left_edge)/(idims-2), + self.pf.h.grids[0].dds[0]) + idims = na.floor((self.right_edge-self.left_edge)/dx) + 2 + for ax in 'xyz': self['cd%s'%ax] = dx[0] + self[field] = na.zeros(idims,dtype='float64')-999 + for level in range(self.level+1): + for grid in self.select_grids(level): + if self._use_pbar: pbar.update(grid_count) + self._get_data_from_grid(grid, field) + grid_count += 1 + if level < self.level: self._get_level_array(level+1, field) + self[field] = self[field][1:-1,1:-1,1:-1] + if self._use_pbar: pbar.finish() + + @restore_grid_state + def _get_data_from_grid(self, grid, fields): + fields = ensure_list(fields) + g_dx = grid.dds + c_dx = na.array([self['cdx'],self['cdy'],self['cdz']]) + g_fields = [grid[field] for field in fields] + c_fields = [self[field] for field in fields] + total = DataCubeRefine( + grid.LeftEdge, g_dx, g_fields, grid.child_mask, + self.left_edge-c_dx, self.right_edge+c_dx, + c_dx, c_fields, + 1, self.pf.domain_left_edge, self.pf.domain_right_edge) + + def flush_data(self, *args, **kwargs): + raise KeyError("Can't do this") + +class AMRCoveringGridBase(AMR3DData): + _spatial = True + _type_name = "covering_grid" + _con_args = ('level', 'left_edge', 'right_edge', 'ActiveDimensions') + def __init__(self, level, left_edge, dims, fields = None, + pf = None, num_ghost_zones = 0, use_pbar = True, **kwargs): + AMR3DData.__init__(self, center=None, fields=fields, pf=pf, **kwargs) + self.left_edge = na.array(left_edge) + self.level = level + self.dds = self.pf.h.select_grids(self.level)[0].dds.copy() + self.ActiveDimensions = na.array(dims,dtype='int32') + self.right_edge = self.left_edge + self.ActiveDimensions*self.dds + self._num_ghost_zones = num_ghost_zones + self._use_pbar = use_pbar + self.global_startindex = na.rint((self.left_edge-self.pf.domain_left_edge)/self.dds).astype('int64') + self.domain_width = na.rint((self.pf.domain_right_edge - + self.pf.domain_left_edge)/self.dds).astype('int64') + self._refresh_data() + + def _get_list_of_grids(self, buffer = 0.0): + if self._grids is not None: return + if na.any(self.left_edge - buffer < self.pf.domain_left_edge) or \ + na.any(self.right_edge + buffer > self.pf.domain_right_edge): + grids,ind = self.pf.hierarchy.get_periodic_box_grids( + self.left_edge - buffer, + self.right_edge + buffer) + ind = slice(None) + else: + grids,ind = self.pf.hierarchy.get_box_grids( + self.left_edge - buffer, + self.right_edge + buffer) + level_ind = (self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) + sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) + self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)][::-1] + + def _refresh_data(self): + AMR3DData._refresh_data(self) + self['dx'] = self.dds[0] * na.ones(self.ActiveDimensions, dtype='float64') + self['dy'] = self.dds[1] * na.ones(self.ActiveDimensions, dtype='float64') + self['dz'] = self.dds[2] * na.ones(self.ActiveDimensions, dtype='float64') + + def get_data(self, fields=None): + if self._grids is None: + self._get_list_of_grids() + if fields is None: + fields = self.fields[:] + else: + fields = ensure_list(fields) + obtain_fields = [] + for field in fields: + if self.data.has_key(field): continue + if field not in self.hierarchy.field_list: + try: + #print "Generating", field + self._generate_field(field) + continue + except NeedsOriginalGrid, ngt_exception: + pass + obtain_fields.append(field) + self[field] = na.zeros(self.ActiveDimensions, dtype='float64') -999 + if len(obtain_fields) == 0: return + mylog.debug("Getting fields %s from %s possible grids", + obtain_fields, len(self._grids)) + if self._use_pbar: pbar = \ + get_pbar('Searching grids for values ', len(self._grids)) + count = self.ActiveDimensions.prod() + for i, grid in enumerate(self._grids): + if self._use_pbar: pbar.update(i) + count -= self._get_data_from_grid(grid, obtain_fields) + if count <= 0: break + if self._use_pbar: pbar.finish() + if count > 0 or na.any(self[obtain_fields[0]] == -999): + # and self.dx < self.hierarchy.grids[0].dx: + n_bad = na.where(self[obtain_fields[0]]==-999)[0].size + mylog.error("Covering problem: %s cells are uncovered", n_bad) + raise KeyError(n_bad) + + def _generate_field(self, field): + if self.pf.field_info.has_key(field): + # First we check the validator; this might even raise! + self.pf.field_info[field].check_available(self) + self[field] = self.pf.field_info[field](self) + else: # Can't find the field, try as it might + raise KeyError(field) + + def flush_data(self, field=None): + """ + Any modifications made to the data in this object are pushed back + to the originating grids, except the cells where those grids are both + below the current level `and` have child cells. + """ + self._get_list_of_grids() + # We don't generate coordinates here. + if field == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(field) + for grid in self._grids: + self._flush_data_to_grid(grid, fields_to_get) + + @restore_grid_state + def _get_data_from_grid(self, grid, fields): + ll = int(grid.Level == self.level) + ref_ratio = self.pf.refine_by**(self.level - grid.Level) + g_fields = [grid[field] for field in fields] + c_fields = [self[field] for field in fields] + count = FillRegion(ref_ratio, + grid.get_global_startindex(), self.global_startindex, + c_fields, g_fields, + self.ActiveDimensions, grid.ActiveDimensions, + grid.child_mask, self.domain_width, ll, 0) + return count + + def _flush_data_to_grid(self, grid, fields): + ll = int(grid.Level == self.level) + ref_ratio = self.pf.refine_by**(self.level - grid.Level) + g_fields = [] + for field in fields: + if not grid.has_key(field): grid[field] = \ + na.zeros(grid.ActiveDimensions, dtype=self[field].dtype) + g_fields.append(grid[field]) + c_fields = [self[field] for field in fields] + FillRegion(ref_ratio, + grid.get_global_startindex(), self.global_startindex, + c_fields, g_fields, + self.ActiveDimensions, grid.ActiveDimensions, + grid.child_mask, self.domain_width, ll, 1) + + @property + def LeftEdge(self): + return self.left_edge + + @property + def RightEdge(self): + return self.right_edge + +class AMRIntSmoothedCoveringGridBase(AMRCoveringGridBase): + _type_name = "si_covering_grid" + @wraps(AMRCoveringGridBase.__init__) + def __init__(self, *args, **kwargs): + AMRCoveringGridBase.__init__(self, *args, **kwargs) + self._final_start_index = self.global_startindex + + def _get_list_of_grids(self): + buffer = self.pf.h.select_grids(0)[0].dds + AMRCoveringGridBase._get_list_of_grids(self, buffer) + self._grids = self._grids[::-1] + + def get_data(self, field=None): + dx = [self.pf.h.select_grids(l)[0].dds for l in range(self.level+1)] + self._get_list_of_grids() + # We don't generate coordinates here. + if field == None: + fields_to_get = self.fields[:] + else: + fields_to_get = ensure_list(field) + for field in fields_to_get: + grid_count = 0 + if self.data.has_key(field): + continue + mylog.debug("Getting field %s from %s possible grids", + field, len(self._grids)) + if self._use_pbar: pbar = \ + get_pbar('Searching grids for values ', len(self._grids)) + # Note that, thanks to some trickery, we have different dimensions + # on the field than one might think from looking at the dx and the + # L/R edges. + # We jump-start our task here + self._update_level_state(0, field) + for level in range(self.level+1): + for grid in self.select_grids(level): + if self._use_pbar: pbar.update(grid_count) + self._get_data_from_grid(grid, field, level) + grid_count += 1 + if level < self.level: + self._update_level_state(level + 1) + self._refine(1, field) + if self.level > 0: + self[field] = self[field][1:-1,1:-1,1:-1] + if na.any(self[field] == -999): + # and self.dx < self.hierarchy.grids[0].dx: + n_bad = na.where(self[field]==-999)[0].size + mylog.error("Covering problem: %s cells are uncovered", n_bad) + raise KeyError(n_bad) + if self._use_pbar: pbar.finish() + + def _update_level_state(self, level, field = None): + dx = self.pf.h.select_grids(level)[0].dds + for ax, v in zip('xyz', dx): self['cd%s'%ax] = v + LL = self.left_edge - self.pf.domain_left_edge + self._old_global_startindex = self.global_startindex + self.global_startindex = na.rint(LL / dx).astype('int64') - 1 + self.domain_width = na.rint((self.pf.domain_right_edge - + self.pf.domain_left_edge)/dx).astype('int64') + if level == 0 and self.level > 0: + # We use one grid cell at LEAST, plus one buffer on all sides + idims = na.rint((self.right_edge-self.left_edge)/dx).astype('int64') + 2 + self[field] = na.zeros(idims,dtype='float64')-999 + elif level == 0 and self.level == 0: + DLE = self.pf.domain_left_edge + self.global_startindex = na.array(na.floor(LL/ dx), dtype='int64') + idims = na.rint((self.right_edge-self.left_edge)/dx).astype('int64') + self[field] = na.zeros(idims,dtype='float64')-999 + + def _refine(self, dlevel, field): + rf = float(self.pf.refine_by**dlevel) + + old_dims = na.array(self[field].shape) - 1 + old_left = (self._old_global_startindex + 0.5) * rf + old_right = rf*old_dims + old_left + old_bounds = [old_left[0], old_right[0], + old_left[1], old_right[1], + old_left[2], old_right[2]] + + dx = na.array([self['cd%s' % ax] for ax in 'xyz'], dtype='float64') + new_dims = na.rint((self.right_edge-self.left_edge)/dx).astype('int64') + 2 + + # x, y, z are the new bounds + x,y,z = (na.mgrid[0:new_dims[0], 0:new_dims[1], 0:new_dims[2]] + ).astype('float64') + 0.5 + x += self.global_startindex[0] + y += self.global_startindex[1] + z += self.global_startindex[2] + fake_grid = {'x':x,'y':y,'z':z} + + interpolator = TrilinearFieldInterpolator( + self[field], old_bounds, ['x','y','z'], + truncate = True) + self[field] = interpolator(fake_grid) + + def _get_data_from_grid(self, grid, fields, level): + fields = ensure_list(fields) + g_fields = [grid[field] for field in fields] + c_fields = [self[field] for field in fields] + dims = na.array(self[field].shape, dtype='int32') + count = FillRegion(1, + grid.get_global_startindex(), self.global_startindex, + c_fields, g_fields, + dims, grid.ActiveDimensions, + grid.child_mask, self.domain_width, 1, 0) + return count + + def flush_data(self, *args, **kwargs): + raise KeyError("Can't do this") + + +def _reconstruct_object(*args, **kwargs): + pfid = args[0] + dtype = args[1] + field_parameters = args[-1] + # will be much nicer when we can do pfid, *a, fp = args + args, new_args = args[2:-1], [] + for arg in args: + if iterable(arg) and len(arg) == 2 \ + and not isinstance(arg, types.DictType) \ + and isinstance(arg[1], AMRData): + new_args.append(arg[1]) + else: new_args.append(arg) + pfs = ParameterFileStore() + pf = pfs.get_pf_hash(pfid) + cls = getattr(pf.h, dtype) + obj = cls(*new_args) + obj.field_parameters.update(field_parameters) + return pf, obj diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/derived_quantities.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/derived_quantities.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,484 @@ +""" +Quantities that can be derived from Enzo data that may also required additional +arguments. (Standard arguments -- such as the center of a distribution of +points -- are excluded here, and left to the EnzoDerivedFields.) + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +import numpy as na + +from yt.funcs import * + +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelAnalysisInterface +from yt.funcs import \ + get_pbar, wraps + +__CUDA_BLOCK_SIZE = 256 + +quantity_info = {} + +class GridChildMaskWrapper: + def __init__(self, grid, data_source): + self.grid = grid + self.data_source = data_source + def __getattr__(self, attr): + return getattr(self.grid, attr) + def __getitem__(self, item): + return self.data_source._get_data_from_grid(self.grid, item) + +class DerivedQuantity(ParallelAnalysisInterface): + def __init__(self, collection, name, function, + combine_function, units = "", + n_ret = 0, force_unlazy=False): + # We wrap the function with our object + self.__doc__ = function.__doc__ + self.__name__ = name + self.collection = collection + self._data_source = collection.data_source + self.func = function + self.c_func = combine_function + self.n_ret = n_ret + self.force_unlazy = force_unlazy + + def __call__(self, *args, **kwargs): + lazy_reader = kwargs.pop('lazy_reader', True) + preload = kwargs.pop('preload', False) + if preload: + if not lazy_reader: mylog.debug("Turning on lazy_reader because of preload") + lazy_reader = True + e = FieldDetector() + e.NumberOfParticles = 1 + self.func(e, *args, **kwargs) + mylog.debug("Preloading %s", e.requested) + self._preload([g for g in self._get_grid_objs()], e.requested, + self._data_source.pf.h.io) + if lazy_reader and not self.force_unlazy: + return self._call_func_lazy(args, kwargs) + else: + return self._call_func_unlazy(args, kwargs) + + def _call_func_lazy(self, args, kwargs): + self.retvals = [ [] for i in range(self.n_ret)] + for gi,g in enumerate(self._get_grids()): + rv = self.func(GridChildMaskWrapper(g, self._data_source), *args, **kwargs) + for i in range(self.n_ret): self.retvals[i].append(rv[i]) + g.clear_data() + self.retvals = [na.array(self.retvals[i]) for i in range(self.n_ret)] + return self.c_func(self._data_source, *self.retvals) + + def _finalize_parallel(self): + self.retvals = [na.array(self._mpi_catlist(my_list)) for my_list in self.retvals] + + def _call_func_unlazy(self, args, kwargs): + retval = self.func(self._data_source, *args, **kwargs) + return self.c_func(self._data_source, *retval) + +def add_quantity(name, **kwargs): + if 'function' not in kwargs or 'combine_function' not in kwargs: + mylog.error("Not adding field %s because both function and combine_function must be provided" % name) + return + f = kwargs.pop('function') + c = kwargs.pop('combine_function') + quantity_info[name] = (name, f, c, kwargs) + +class DerivedQuantityCollection(object): + functions = quantity_info + def __init__(self, data_source): + self.data_source = data_source + + def __getitem__(self, key): + if key not in self.functions: + raise KeyError(key) + args = self.functions[key][:3] + kwargs = self.functions[key][3] + # Instantiate here, so we can pass it the data object + # Note that this means we instantiate every time we run help, etc + # I have made my peace with this. + return DerivedQuantity(self, *args, **kwargs) + + def keys(self): + return self.functions.keys() + +def _TotalMass(data): + """ + This function takes no arguments and returns the sum of cell masses and + particle masses in the object. + """ + baryon_mass = data["CellMassMsun"].sum() + particle_mass = data["ParticleMassMsun"].sum() + return baryon_mass, particle_mass +def _combTotalMass(data, baryon_mass, particle_mass): + return baryon_mass.sum() + particle_mass.sum() +add_quantity("TotalMass", function=_TotalMass, + combine_function=_combTotalMass, n_ret = 2) + +def _CenterOfMass(data): + """ + This function takes no arguments and returns the location of the center + of mass of the *non-particle* data in the object. + """ + x = (data["x"] * data["CellMassMsun"]).sum() + y = (data["y"] * data["CellMassMsun"]).sum() + z = (data["z"] * data["CellMassMsun"]).sum() + den = data["CellMassMsun"].sum() + return x,y,z, den +def _combCenterOfMass(data, x,y,z, den): + return na.array([x.sum(), y.sum(), z.sum()])/den.sum() +add_quantity("CenterOfMass", function=_CenterOfMass, + combine_function=_combCenterOfMass, n_ret = 4) + +def _WeightedAverageQuantity(data, field, weight): + """ + This function returns an averaged quantity. + + :param field: The field to average + :param weight: The field to weight by + """ + num = (data[field] * data[weight]).sum() + den = data[weight].sum() + return num, den +def _combWeightedAverageQuantity(data, field, weight): + return field.sum()/weight.sum() +add_quantity("WeightedAverageQuantity", function=_WeightedAverageQuantity, + combine_function=_combWeightedAverageQuantity, n_ret = 2) + +def _BulkVelocity(data): + """ + This function returns the mass-weighted average velocity in the object. + """ + xv = (data["x-velocity"] * data["CellMassMsun"]).sum() + yv = (data["y-velocity"] * data["CellMassMsun"]).sum() + zv = (data["z-velocity"] * data["CellMassMsun"]).sum() + w = data["CellMassMsun"].sum() + return xv, yv, zv, w +def _combBulkVelocity(data, xv, yv, zv, w): + w = w.sum() + xv = xv.sum()/w + yv = yv.sum()/w + zv = zv.sum()/w + return na.array([xv, yv, zv]) +add_quantity("BulkVelocity", function=_BulkVelocity, + combine_function=_combBulkVelocity, n_ret=4) + +def _AngularMomentumVector(data): + """ + This function returns the mass-weighted average angular momentum vector. + """ + am = data["SpecificAngularMomentum"]*data["CellMassMsun"] + j_mag = am.sum(axis=1) + return [j_mag] +def _combAngularMomentumVector(data, j_mag): + if len(j_mag.shape) < 2: j_mag = na.expand_dims(j_mag, 0) + L_vec = j_mag.sum(axis=0) + L_vec_norm = L_vec / na.sqrt((L_vec**2.0).sum()) + return L_vec_norm +add_quantity("AngularMomentumVector", function=_AngularMomentumVector, + combine_function=_combAngularMomentumVector, n_ret=1) + +def _BaryonSpinParameter(data): + """ + This function returns the spin parameter for the baryons, but it uses + the particles in calculating enclosed mass. + """ + m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum() + am = data["SpecificAngularMomentum"]*data["CellMassMsun"] + j_mag = am.sum(axis=1) + e_term_pre = na.sum(data["CellMassMsun"]*data["VelocityMagnitude"]**2.0) + weight=data["CellMassMsun"].sum() + return j_mag, m_enc, e_term_pre, weight +def _combBaryonSpinParameter(data, j_mag, m_enc, e_term_pre, weight): + # Because it's a vector field, we have to ensure we have enough dimensions + if len(j_mag.shape) < 2: j_mag = na.expand_dims(j_mag, 0) + W = weight.sum() + M = m_enc.sum() + J = na.sqrt(((j_mag.sum(axis=0))**2.0).sum())/W + E = na.sqrt(e_term_pre.sum()/W) + G = 6.67e-8 # cm^3 g^-1 s^-2 + spin = J * E / (M*1.989e33*G) + return spin +add_quantity("BaryonSpinParameter", function=_BaryonSpinParameter, + combine_function=_combBaryonSpinParameter, n_ret=4) + +def _ParticleSpinParameter(data): + """ + This function returns the spin parameter for the baryons, but it uses + the particles in calculating enclosed mass. + """ + m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum() + am = data["ParticleSpecificAngularMomentum"]*data["ParticleMassMsun"] + if am.size == 0: return (na.zeros((3,), dtype='float64'), m_enc, 0, 0) + j_mag = am.sum(axis=1) + e_term_pre = na.sum(data["ParticleMassMsun"] + *data["ParticleVelocityMagnitude"]**2.0) + weight=data["ParticleMassMsun"].sum() + return j_mag, m_enc, e_term_pre, weight +add_quantity("ParticleSpinParameter", function=_ParticleSpinParameter, + combine_function=_combBaryonSpinParameter, n_ret=4) + +def _IsBound(data, truncate = True, include_thermal_energy = False): + """ + This returns whether or not the object is gravitationally bound + + :param truncate: Should the calculation stop once the ratio of + gravitational:kinetic is 1.0? + :param include_thermal_energy: Should we add the energy from ThermalEnergy + on to the kinetic energy to calculate + binding energy? + """ + # Kinetic energy + bv_x,bv_y,bv_z = data.quantities["BulkVelocity"]() + # One-cell objects are NOT BOUND. + if data["CellMass"].size == 1: return [0.0] + kinetic = 0.5 * (data["CellMass"] * ( + (data["x-velocity"] - bv_x)**2 + + (data["y-velocity"] - bv_y)**2 + + (data["z-velocity"] - bv_z)**2 )).sum() + # Add thermal energy to kinetic energy + if (include_thermal_energy): + thermal = (data["ThermalEnergy"] * data["CellMass"]).sum() + kinetic += thermal + # Gravitational potential energy + # We only divide once here because we have velocity in cgs, but radius is + # in code. + G = 6.67e-8 / data.convert("cm") # cm^3 g^-1 s^-2 + import time + t1 = time.time() + try: + pot = G*_cudaIsBound(data, truncate, kinetic/G) + except (ImportError, AssertionError): + pot = G*PointCombine.FindBindingEnergy(data["CellMass"], + data['x'],data['y'],data['z'], + truncate, kinetic/G) + mylog.info("Boundedness check took %0.3e seconds", time.time()-t1) + return [(pot / kinetic)] +def _combIsBound(data, bound): + return bound +add_quantity("IsBound",function=_IsBound,combine_function=_combIsBound,n_ret=1, + force_unlazy=True) + +def _cudaIsBound(data, truncate, ratio): + bsize = __CUDA_BLOCK_SIZE + import pycuda.driver as cuda + import pycuda.autoinit + import pycuda.gpuarray as gpuarray + my_stream = cuda.Stream() + cuda.init() + assert cuda.Device.count() >= 1 + + mass_scale_factor = 1.0/(data['CellMass'].max()) + m = (data['CellMass'] * mass_scale_factor).astype('float32') + assert(m.size > bsize) + + gsize=int(na.ceil(float(m.size)/bsize)) + assert(gsize > 16) + + # Now the tedious process of rescaling our values... + length_scale_factor = data['dx'].max()/data['dx'].min() + x = ((data['x'] - data['x'].min()) * length_scale_factor).astype('float32') + y = ((data['y'] - data['y'].min()) * length_scale_factor).astype('float32') + z = ((data['z'] - data['z'].min()) * length_scale_factor).astype('float32') + p = na.zeros(z.shape, dtype='float32') + + x_gpu = cuda.mem_alloc(x.size * x.dtype.itemsize) + y_gpu = cuda.mem_alloc(y.size * y.dtype.itemsize) + z_gpu = cuda.mem_alloc(z.size * z.dtype.itemsize) + m_gpu = cuda.mem_alloc(m.size * m.dtype.itemsize) + p_gpu = cuda.mem_alloc(p.size * p.dtype.itemsize) + for ag, a in [(x_gpu, x), (y_gpu, y), (z_gpu, z), (m_gpu, m), (p_gpu, p)]: + cuda.memcpy_htod(ag, a) + source = """ + + extern __shared__ float array[]; + + __global__ void isbound(float *x, float *y, float *z, float *m, + float *p, int *nelem) + { + + /* My index in the array */ + int idx1 = blockIdx.x * blockDim.x + threadIdx.x; + /* Note we are setting a start index */ + int idx2 = blockIdx.y * blockDim.x; + int offset = threadIdx.x; + + /* Here we're just setting up convenience pointers to our + shared array */ + + float* x_data1 = (float*) array; + float* y_data1 = (float*) &x_data1[blockDim.x]; + float* z_data1 = (float*) &y_data1[blockDim.x]; + float* m_data1 = (float*) &z_data1[blockDim.x]; + + float* x_data2 = (float*) &m_data1[blockDim.x]; + float* y_data2 = (float*) &x_data2[blockDim.x]; + float* z_data2 = (float*) &y_data2[blockDim.x]; + float* m_data2 = (float*) &z_data2[blockDim.x]; + + x_data1[offset] = x[idx1]; + y_data1[offset] = y[idx1]; + z_data1[offset] = z[idx1]; + m_data1[offset] = m[idx1]; + + x_data2[offset] = x[idx2 + offset]; + y_data2[offset] = y[idx2 + offset]; + z_data2[offset] = z[idx2 + offset]; + m_data2[offset] = m[idx2 + offset]; + + __syncthreads(); + + float tx, ty, tz; + + float my_p = 0.0; + + if(idx1 < %(p)s) { + for (int i = 0; i < blockDim.x; i++){ + if(i + idx2 < idx1 + 1) continue; + tx = (x_data1[offset]-x_data2[i]); + ty = (y_data1[offset]-y_data2[i]); + tz = (z_data1[offset]-z_data2[i]); + my_p += m_data1[offset]*m_data2[i] / + sqrt(tx*tx+ty*ty+tz*tz); + } + } + p[idx1] += my_p; + __syncthreads(); + } + """ + mod = cuda.SourceModule(source % dict(p=m.size)) + func = mod.get_function('isbound') + mylog.info("Running CUDA functions. May take a while. (%0.5e, %s)", + x.size, gsize) + import pycuda.tools as ct + t1 = time.time() + ret = func(x_gpu, y_gpu, z_gpu, m_gpu, p_gpu, + shared=8*bsize*m.dtype.itemsize, + block=(bsize,1,1), grid=(gsize, gsize), time_kernel=True) + cuda.memcpy_dtoh(p, p_gpu) + p1 = p.sum() + if na.any(na.isnan(p)): raise ValueError + return p1 * (length_scale_factor / (mass_scale_factor**2.0)) + +def _Extrema(data, fields, non_zero = False, filter=None): + """ + This function returns the extrema of a set of fields + + :param fields: A field name, or a list of field names + :param filter: a string to be evaled to serve as a data filter. + """ + # There is a heck of a lot of logic in this. I really wish it were more + # elegant. + fields = ensure_list(fields) + if filter is not None: this_filter = eval(filter) + mins, maxs = [], [] + for field in fields: + if data[field].size < 1: + mins.append(1e90) + maxs.append(-1e90) + continue + if filter is None: + if non_zero: + nz_filter = data[field]>0.0 + if not nz_filter.any(): + mins.append(1e90) + maxs.append(-1e90) + continue + else: + nz_filter = None + mins.append(data[field][nz_filter].min()) + maxs.append(data[field][nz_filter].max()) + else: + if this_filter.any(): + if non_zero: + nz_filter = ((this_filter) & + (data[field][this_filter] > 0.0)) + else: nz_filter = this_filter + mins.append(data[field][nz_filter].min()) + maxs.append(data[field][nz_filter].max()) + else: + mins.append(1e90) + maxs.append(-1e90) + return len(fields), mins, maxs +def _combExtrema(data, n_fields, mins, maxs): + mins, maxs = na.atleast_2d(mins, maxs) + n_fields = mins.shape[1] + return [(na.min(mins[:,i]), na.max(maxs[:,i])) for i in range(n_fields)] +add_quantity("Extrema", function=_Extrema, combine_function=_combExtrema, + n_ret=3) + +def _Action(data, action, combine_action, filter=None): + """ + This function evals the string given by the action arg and uses + the function thrown with the combine_action to combine the values. + A filter can be thrown to be evaled to short-circuit the calculation + if some criterion is not met. + :param action: a string containing the desired action to be evaled. + :param combine_action: the function used to combine the answers when done lazily. + :param filter: a string to be evaled to serve as a data filter. + """ + if filter is not None: + if not eval(filter).any(): return 0, False, combine_action + value = eval(action) + return value, True, combine_action +def _combAction(data, value, valid, combine_action): + return combine_action[0](value[valid]) +add_quantity("Action", function=_Action, combine_function=_combAction, n_ret=3) + +def _MaxLocation(data, field): + """ + This function returns the location of the maximum of a set + of fields. + """ + ma, maxi, mx, my, mz, mg = -1e90, -1, -1, -1, -1, -1 + if data[field].size > 0: + maxi = na.argmax(data[field]) + ma = data[field][maxi] + mx, my, mz = [data[ax][maxi] for ax in 'xyz'] + mg = data["GridIndices"][maxi] + return (ma, maxi, mx, my, mz, mg) +def _combMaxLocation(data, *args): + args = [na.atleast_1d(arg) for arg in args] + i = na.argmax(args[0]) # ma is arg[0] + return [arg[i] for arg in args] +add_quantity("MaxLocation", function=_MaxLocation, + combine_function=_combMaxLocation, n_ret = 6) + +def _TotalQuantity(data, fields): + """ + This function sums up a given field over the entire region + + :param fields: The fields to sum up + """ + fields = ensure_list(fields) + totals = [] + for field in fields: + if data[field].size < 1: + totals.append(0) + continue + totals.append(data[field].sum()) + return len(fields), totals +def _combTotalQuantity(data, n_fields, totals): + totals = na.atleast_2d(totals) + n_fields = totals.shape[1] + return [na.sum(totals[:,i]) for i in range(n_fields)] +add_quantity("TotalQuantity", function=_TotalQuantity, + combine_function=_combTotalQuantity, n_ret=2) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/field_info_container.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/field_info_container.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,406 @@ +""" +The basic field info container resides here. These classes, code specific and +universal, are the means by which we access fields across YT, both derived and +native. + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 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 . +""" + +import types +import numpy as na +import inspect +import copy +import itertools + +from yt.funcs import * + +class FieldInfoContainer(object): # We are all Borg. + """ + This is a generic field container. It contains a list of potential derived + fields, all of which know how to act on a data object and return a value. This + object handles converting units as well as validating the availability of a + given field. + """ + _shared_state = {} + _universal_field_list = {} + def __new__(cls, *args, **kwargs): + self = object.__new__(cls, *args, **kwargs) + self.__dict__ = cls._shared_state + return self + def __getitem__(self, key): + if key in self._universal_field_list: + return self._universal_field_list[key] + raise KeyError + def keys(self): + """ + Return all the field names this object knows about. + """ + return self._universal_field_list.keys() + def __iter__(self): + return self._universal_field_list.iterkeys() + def __setitem__(self, key, val): + self._universal_field_list[key] = val + def has_key(self, key): + return key in self._universal_field_list + def add_field(self, name, function = None, **kwargs): + """ + Add a new field, along with supplemental metadata, to the list of + available fields. This respects a number of arguments, all of which + are passed on to the constructor for + :class:`~yt.data_objects.api.DerivedField`. + """ + if function == None: + if kwargs.has_key("function"): + function = kwargs.pop("function") + else: + # This will fail if it does not exist, + # which is our desired behavior + function = eval("_%s" % name) + self[name] = DerivedField(name, function, **kwargs) +FieldInfo = FieldInfoContainer() +add_field = FieldInfo.add_field + +def derived_field(**kwargs): + def inner_decorator(function): + if 'name' not in kwargs: + kwargs['name'] = function.func_name + kwargs['function'] = function + add_field(**kwargs) + return function + return inner_decorator + +class CodeFieldInfoContainer(FieldInfoContainer): + def __setitem__(self, key, val): + self._field_list[key] = val + def __iter__(self): + return itertools.chain(self._field_list.iterkeys(), + self._universal_field_list.iterkeys()) + def keys(self): + return set(self._field_list.keys() + self._universal_field_list.keys()) + def has_key(self, key): + return key in self._universal_field_list \ + or key in self._field_list + def __getitem__(self, key): + if key in self._field_list: + return self._field_list[key] + if key in self._universal_field_list: + return self._universal_field_list[key] + raise KeyError(key) + +class ValidationException(Exception): + pass + +class NeedsGridType(ValidationException): + def __init__(self, ghost_zones = 0, fields=None): + self.ghost_zones = ghost_zones + self.fields = fields + def __str__(self): + return "(%s, %s)" % (self.ghost_zones, self.fields) + +class NeedsOriginalGrid(NeedsGridType): + def __init__(self): + self.ghost_zones = 0 + +class NeedsDataField(ValidationException): + def __init__(self, missing_fields): + self.missing_fields = missing_fields + def __str__(self): + return "(%s)" % (self.missing_fields) + +class NeedsProperty(ValidationException): + def __init__(self, missing_properties): + self.missing_properties = missing_properties + def __str__(self): + return "(%s)" % (self.missing_properties) + +class NeedsParameter(ValidationException): + def __init__(self, missing_parameters): + self.missing_parameters = missing_parameters + def __str__(self): + return "(%s)" % (self.missing_parameters) + +class FieldDetector(defaultdict): + Level = 1 + NumberOfParticles = 1 + _read_exception = None + def __init__(self, nd = 16, pf = None): + self.nd = nd + self.ActiveDimensions = [nd,nd,nd] + self.LeftEdge = [0.0,0.0,0.0] + self.RightEdge = [1.0,1.0,1.0] + self['dx'] = self['dy'] = self['dz'] = na.array([1.0]) + if pf is None: + pf = defaultdict(lambda: 1) + self.pf = pf + class fake_hierarchy(object): + class fake_io(object): + def _read_data_set(io_self, data, field): + return self._read_data(field) + _read_exception = RuntimeError + io = fake_io() + def get_smallest_dx(self): + return 1.0 + self.hierarchy = fake_hierarchy() + self.requested = [] + self.requested_parameters = [] + defaultdict.__init__(self, lambda: na.ones((nd,nd,nd))) + def __missing__(self, item): + if FieldInfo.has_key(item) and \ + FieldInfo[item]._function.func_name != '': + try: + vv = FieldInfo[item](self) + except NeedsGridType, exc: + ngz = exc.ghost_zones + nfd = FieldDetector(self.nd+ngz*2) + vv = FieldInfo[item](nfd)[ngz:-ngz,ngz:-ngz,ngz:-ngz] + for i in vv.requested: + if i not in self.requested: self.requested.append(i) + for i in vv.requested_parameters: + if i not in self.requested_parameters: self.requested_parameters.append(i) + if vv is not None: + self[item] = vv + return self[item] + self.requested.append(item) + return defaultdict.__missing__(self, item) + + def _read_data(self, field_name): + self.requested.append(field_name) + if FieldInfo.has_key(field_name) and \ + FieldInfo[field_name].particle_type: + self.requested.append(field_name) + return na.ones(self.NumberOfParticles) + return defaultdict.__missing__(self, field_name) + + def get_field_parameter(self, param): + self.requested_parameters.append(param) + if param in ['bulk_velocity','center','height_vector']: + return na.array([0,0,0]) + else: + return 0.0 + _spatial = True + _num_ghost_zones = 0 + id = 1 + def has_field_parameter(self, param): return True + def convert(self, item): return 1 + +class DerivedField(object): + def __init__(self, name, function, + convert_function = None, + particle_convert_function = None, + units = "", projected_units = "", + take_log = True, validators = None, + particle_type = False, vector_field=False, + display_field = True, not_in_all=False, + display_name = None, projection_conversion = "cm"): + """ + This is the base class used to describe a cell-by-cell derived field. + + :param name: is the name of the field. + :param function: is a function handle that defines the field + :param convert_function: must convert to CGS, if it needs to be done + :param units: is a mathtext-formatted string that describes the field + :param projected_units: if we display a projection, what should the units be? + :param take_log: describes whether the field should be logged + :param validators: is a list of :class:`FieldValidator` objects + :param particle_type: is this field based on particles? + :param vector_field: describes the dimensionality of the field + :param display_field: governs its appearance in the dropdowns in reason + :param not_in_all: is used for baryon fields from the data that are not in + all the grids + :param display_name: a name used in the plots + :param projection_conversion: which unit should we multiply by in a + projection? + """ + self.name = name + self._function = function + if validators: + self.validators = ensure_list(validators) + else: + self.validators = [] + self.take_log = take_log + self._units = units + self._projected_units = projected_units + if not convert_function: + convert_function = lambda a: 1.0 + self._convert_function = convert_function + self._particle_convert_function = particle_convert_function + self.particle_type = particle_type + self.vector_field = vector_field + self.projection_conversion = projection_conversion + self.display_field = display_field + self.display_name = display_name + self.not_in_all = not_in_all + + def check_available(self, data): + """ + This raises an exception of the appropriate type if the set of + validation mechanisms are not met, and otherwise returns True. + """ + for validator in self.validators: + validator(data) + # If we don't get an exception, we're good to go + return True + + def get_dependencies(self, *args, **kwargs): + """ + This returns a list of names of fields that this field depends on. + """ + e = FieldDetector(*args, **kwargs) + if self._function.func_name == '': + e.requested.append(self.name) + else: + self(e) + return e + + def get_units(self): + """ + Return a string describing the units. + """ + return self._units + + def get_projected_units(self): + """ + Return a string describing the units if the field has been projected. + """ + return self._projected_units + + def __call__(self, data): + """ + Return the value of the field in a given *data* object. + """ + ii = self.check_available(data) + original_fields = data.keys() # Copy + dd = self._function(self, data) + dd *= self._convert_function(data) + for field_name in data.keys(): + if field_name not in original_fields: + del data[field_name] + return dd + + def get_source(self): + """ + Return a string containing the source of the function (if possible.) + """ + return inspect.getsource(self._function) + + def get_label(self, projected=False): + """ + Return a data label for the given field, inluding units. + """ + name = self.name + if self.display_name is not None: name = self.display_name + data_label = r"$\rm{%s}" % name + if projected: units = self.get_projected_units() + else: units = self.get_units() + if units != "": data_label += r"\/\/ (%s)" % (units) + data_label += r"$" + return data_label + + def particle_convert(self, data): + if self._particle_convert_function is not None: + return self._particle_convert_function(data) + return None + +class FieldValidator(object): + pass + +class ValidateParameter(FieldValidator): + def __init__(self, parameters): + """ + This validator ensures that the parameter file has a given parameter. + """ + FieldValidator.__init__(self) + self.parameters = ensure_list(parameters) + def __call__(self, data): + doesnt_have = [] + for p in self.parameters: + if not data.has_field_parameter(p): + doesnt_have.append(p) + if len(doesnt_have) > 0: + raise NeedsParameter(doesnt_have) + return True + +class ValidateDataField(FieldValidator): + def __init__(self, field): + """ + This validator ensures that the output file has a given data field stored + in it. + """ + FieldValidator.__init__(self) + self.fields = ensure_list(field) + def __call__(self, data): + doesnt_have = [] + if isinstance(data, FieldDetector): return True + for f in self.fields: + if f not in data.hierarchy.field_list: + doesnt_have.append(f) + if len(doesnt_have) > 0: + raise NeedsDataField(doesnt_have) + return True + +class ValidateProperty(FieldValidator): + def __init__(self, prop): + """ + This validator ensures that the data object has a given python attribute. + """ + FieldValidator.__init__(self) + self.prop = ensure_list(prop) + def __call__(self, data): + doesnt_have = [] + for p in self.prop: + if not hasattr(data,p): + doesnt_have.append(p) + if len(doesnt_have) > 0: + raise NeedsProperty(doesnt_have) + return True + +class ValidateSpatial(FieldValidator): + def __init__(self, ghost_zones = 0, fields=None): + """ + This validator ensures that the data handed to the field is of spatial + nature -- that is to say, 3-D. + """ + FieldValidator.__init__(self) + self.ghost_zones = ghost_zones + self.fields = fields + def __call__(self, data): + # When we say spatial information, we really mean + # that it has a three-dimensional data structure + if isinstance(data, FieldDetector): return True + if not data._spatial: + raise NeedsGridType(self.ghost_zones,self.fields) + if self.ghost_zones <= data._num_ghost_zones: + return True + raise NeedsGridType(self.ghost_zones,self.fields) + +class ValidateGridType(FieldValidator): + def __init__(self): + """ + This validator ensures that the data handed to the field is an actual + grid patch, not a covering grid of any kind. + """ + FieldValidator.__init__(self) + def __call__(self, data): + # We need to make sure that it's an actual AMR grid + if isinstance(data, FieldDetector): return True + if data._type_name == 'grid': return True + raise NeedsOriginalGrid() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/grid_patch.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/grid_patch.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,463 @@ +""" +Python-based grid handler, not to be confused with the SWIG-handler + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +import exceptions +import pdb +import numpy as na +import weakref + +from yt.funcs import * + +from yt.utilities.definitions import x_dict, y_dict +from .field_info_container import \ + NeedsGridType, \ + NeedsOriginalGrid, \ + NeedsDataField, \ + NeedsProperty, \ + NeedsParameter + +class AMRGridPatch(object): + _spatial = True + _num_ghost_zones = 0 + _grids = None + _id_offset = 1 + + _type_name = 'grid' + _skip_add = True + _con_args = ('id', 'filename') + + __slots__ = ['data', 'field_parameters', 'id', 'hierarchy', 'pf', + 'ActiveDimensions', 'LeftEdge', 'RightEdge', 'Level', + 'NumberOfParticles', 'Children', 'Parent', + 'start_index', 'filename', '__weakref__', 'dds', + '_child_mask', '_child_indices', '_child_index_mask', + '_parent_id', '_children_ids'] + def __init__(self, id, filename = None, hierarchy = None): + self.data = {} + self.field_parameters = {} + self.id = id + if hierarchy: self.hierarchy = weakref.proxy(hierarchy) + self.pf = self.hierarchy.parameter_file # weakref already + self._child_mask = self._child_indices = self._child_index_mask = None + self.start_index = None + + def get_global_startindex(self): + """ + Return the integer starting index for each dimension at the current + level. + """ + if self.start_index != None: + return self.start_index + if self.Parent == None: + iLE = self.LeftEdge - self.pf.domain_left_edge + start_index = iLE / self.dds + return na.rint(start_index).astype('int64').ravel() + pdx = self.Parent.dds + start_index = (self.Parent.get_global_startindex()) + \ + na.rint((self.LeftEdge - self.Parent.LeftEdge)/pdx) + self.start_index = (start_index*self.pf.refine_by).astype('int64').ravel() + return self.start_index + + + def get_field_parameter(self, name, default=None): + """ + This is typically only used by derived field functions, but + it returns parameters used to generate fields. + """ + if self.field_parameters.has_key(name): + return self.field_parameters[name] + else: + return default + + def set_field_parameter(self, name, val): + """ + Here we set up dictionaries that get passed up and down and ultimately + to derived fields. + """ + self.field_parameters[name] = val + + def has_field_parameter(self, name): + """ + Checks if a field parameter is set. + """ + return self.field_parameters.has_key(name) + + def convert(self, datatype): + """ + This will attempt to convert a given unit to cgs from code units. + It either returns the multiplicative factor or throws a KeyError. + """ + return self.pf[datatype] + + def __repr__(self): + # We'll do this the slow way to be clear what's going on + s = "%s (%s): " % (self.__class__.__name__, self.pf) + s += ", ".join(["%s=%s" % (i, getattr(self,i)) + for i in self._con_args]) + return s + + def _generate_field(self, field): + if self.pf.field_info.has_key(field): + # First we check the validator + try: + self.pf.field_info[field].check_available(self) + except NeedsGridType, ngt_exception: + # This is only going to be raised if n_gz > 0 + n_gz = ngt_exception.ghost_zones + f_gz = ngt_exception.fields + gz_grid = self.retrieve_ghost_zones(n_gz, f_gz, smoothed=True) + temp_array = self.pf.field_info[field](gz_grid) + sl = [slice(n_gz,-n_gz)] * 3 + self[field] = temp_array[sl] + else: + self[field] = self.pf.field_info[field](self) + else: # Can't find the field, try as it might + raise exceptions.KeyError, field + + def has_key(self, key): + return (key in self.data) + + def __getitem__(self, key): + """ + Returns a single field. Will add if necessary. + """ + if not self.data.has_key(key): + self.get_data(key) + return self.data[key] + + def __setitem__(self, key, val): + """ + Sets a field to be some other value. + """ + self.data[key] = val + + def __delitem__(self, key): + """ + Deletes a field + """ + del self.data[key] + + def keys(self): + return self.data.keys() + + def get_data(self, field): + """ + Returns a field or set of fields for a key or set of keys + """ + if not self.data.has_key(field): + if field in self.hierarchy.field_list: + conv_factor = 1.0 + if self.pf.field_info.has_key(field): + conv_factor = self.pf.field_info[field]._convert_function(self) + if self.pf.field_info[field].particle_type and \ + self.NumberOfParticles == 0: + # because this gets upcast to float + self[field] = na.array([],dtype='int64') + return self.data[field] + try: + temp = self.hierarchy.io.pop(self, field) + self[field] = na.multiply(temp, conv_factor, temp) + except self.hierarchy.io._read_exception, exc: + if field in self.pf.field_info: + if self.pf.field_info[field].not_in_all: + self[field] = na.zeros(self.ActiveDimensions, dtype='float64') + else: + raise + else: raise + else: + self._generate_field(field) + return self.data[field] + + def _setup_dx(self): + # So first we figure out what the index is. We don't assume + # that dx=dy=dz , at least here. We probably do elsewhere. + id = self.id - self._id_offset + if self.Parent is not None: + self.dds = self.Parent.dds / self.pf.refine_by + else: + LE, RE = self.hierarchy.grid_left_edge[id,:], \ + self.hierarchy.grid_right_edge[id,:] + self.dds = na.array((RE-LE)/self.ActiveDimensions) + if self.pf.dimensionality < 2: self.dds[1] = 1.0 + if self.pf.dimensionality < 3: self.dds[2] = 1.0 + self.data['dx'], self.data['dy'], self.data['dz'] = self.dds + + @property + def _corners(self): + return na.array([ # Unroll! + [self.LeftEdge[0], self.LeftEdge[1], self.LeftEdge[2]], + [self.RightEdge[0], self.LeftEdge[1], self.LeftEdge[2]], + [self.RightEdge[0], self.RightEdge[1], self.LeftEdge[2]], + [self.RightEdge[0], self.RightEdge[1], self.RightEdge[2]], + [self.LeftEdge[0], self.RightEdge[1], self.RightEdge[2]], + [self.LeftEdge[0], self.LeftEdge[1], self.RightEdge[2]], + [self.RightEdge[0], self.LeftEdge[1], self.RightEdge[2]], + [self.LeftEdge[0], self.RightEdge[1], self.LeftEdge[2]], + ], dtype='float64') + + def _generate_overlap_masks(self, axis, LE, RE): + """ + Generate a mask that shows which cells overlap with arbitrary arrays + *LE* and *RE*) of edges, typically grids, along *axis*. + Use algorithm described at http://www.gamedev.net/reference/articles/article735.asp + """ + x = x_dict[axis] + y = y_dict[axis] + cond = self.RightEdge[x] >= LE[:,x] + cond = na.logical_and(cond, self.LeftEdge[x] <= RE[:,x]) + cond = na.logical_and(cond, self.RightEdge[y] >= LE[:,y]) + cond = na.logical_and(cond, self.LeftEdge[y] <= RE[:,y]) + return cond + + def __repr__(self): + return "AMRGridPatch_%04i" % (self.id) + + def __int__(self): + return self.id + + def clear_data(self): + """ + Clear out the following things: child_mask, child_indices, + all fields, all field parameters. + """ + self._del_child_mask() + self._del_child_indices() + self.data.clear() + self._setup_dx() + + def check_child_masks(self): + return self._child_mask, self._child_indices + + def _prepare_grid(self): + """ + Copies all the appropriate attributes from the hierarchy + """ + # This is definitely the slowest part of generating the hierarchy + # Now we give it pointers to all of its attributes + # Note that to keep in line with Enzo, we have broken PEP-8 + h = self.hierarchy # cache it + my_ind = self.id - self._id_offset + self.ActiveDimensions = h.grid_dimensions[my_ind] + self.LeftEdge = h.grid_left_edge[my_ind] + self.RightEdge = h.grid_right_edge[my_ind] + h.grid_levels[my_ind, 0] = self.Level + # This might be needed for streaming formats + #self.Time = h.gridTimes[my_ind,0] + self.NumberOfParticles = h.grid_particle_count[my_ind,0] + + def __len__(self): + return na.prod(self.ActiveDimensions) + + def find_max(self, field): + """ + Returns value, index of maximum value of *field* in this gird + """ + coord1d=(self[field]*self.child_mask).argmax() + coord=na.unravel_index(coord1d, self[field].shape) + val = self[field][coord] + return val, coord + + def find_min(self, field): + """ + Returns value, index of minimum value of *field* in this gird + """ + coord1d=(self[field]*self.child_mask).argmin() + coord=na.unravel_index(coord1d, self[field].shape) + val = self[field][coord] + return val, coord + + def get_position(self, index): + """ + Returns center position of an *index* + """ + pos = (index + 0.5) * self.dds + self.LeftEdge + return pos + + def clear_all(self): + """ + Clears all datafields from memory and calls + :meth:`clear_derived_quantities`. + """ + for key in self.keys(): + del self.data[key] + del self.data + if hasattr(self,"retVal"): + del self.retVal + self.data = {} + self.clear_derived_quantities() + + def clear_derived_quantities(self): + """ + Clears coordinates, child_indices, child_mask. + """ + # Access the property raw-values here + del self.child_mask + del self.child_ind + + def _set_child_mask(self, newCM): + if self._child_mask != None: + mylog.warning("Overriding child_mask attribute! This is probably unwise!") + self._child_mask = newCM + + def _set_child_indices(self, newCI): + if self._child_indices != None: + mylog.warning("Overriding child_indices attribute! This is probably unwise!") + self._child_indices = newCI + + def _get_child_mask(self): + if self._child_mask == None: + self.__generate_child_mask() + return self._child_mask + + def _get_child_indices(self): + if self._child_indices == None: + self.__generate_child_mask() + return self._child_indices + + def _del_child_indices(self): + try: + del self._child_indices + except AttributeError: + pass + self._child_indices = None + + def _del_child_mask(self): + try: + del self._child_mask + except AttributeError: + pass + self._child_mask = None + + def _get_child_index_mask(self): + if self._child_index_mask is None: + self.__generate_child_index_mask() + return self._child_index_mask + + def _del_child_index_mask(self): + try: + del self._child_index_mask + except AttributeError: + pass + self._child_index_mask = None + + #@time_execution + def __fill_child_mask(self, child, mask, tofill): + rf = self.pf.refine_by + gi, cgi = self.get_global_startindex(), child.get_global_startindex() + startIndex = na.maximum(0, cgi/rf - gi) + endIndex = na.minimum( (cgi+child.ActiveDimensions)/rf - gi, + self.ActiveDimensions) + endIndex += (startIndex == endIndex) + mask[startIndex[0]:endIndex[0], + startIndex[1]:endIndex[1], + startIndex[2]:endIndex[2]] = tofill + + def __generate_child_mask(self): + """ + Generates self.child_mask, which is zero where child grids exist (and + thus, where higher resolution data is available.) + """ + self._child_mask = na.ones(self.ActiveDimensions, 'int32') + for child in self.Children: + self.__fill_child_mask(child, self._child_mask, 0) + self._child_indices = (self._child_mask==0) # bool, possibly redundant + + def __generate_child_index_mask(self): + """ + Generates self.child_index_mask, which is -1 where there is no child, + and otherwise has the ID of the grid that resides there. + """ + self._child_index_mask = na.zeros(self.ActiveDimensions, 'int32') - 1 + for child in self.Children: + self.__fill_child_mask(child, self._child_index_mask, + child.id) + + def _get_coords(self): + if self.__coords == None: self._generate_coords() + return self.__coords + + def _set_coords(self, newC): + if self.__coords != None: + mylog.warning("Overriding coords attribute! This is probably unwise!") + self.__coords = newC + + def _del_coords(self): + del self.__coords + self.__coords = None + + def _generate_coords(self): + """ + Creates self.coords, which is of dimensions (3,ActiveDimensions) + """ + #print "Generating coords" + ind = na.indices(self.ActiveDimensions) + LE = na.reshape(self.LeftEdge,(3,1,1,1)) + self['x'], self['y'], self['z'] = (ind+0.5)*self.dds+LE + + child_mask = property(fget=_get_child_mask, fdel=_del_child_mask) + child_index_mask = property(fget=_get_child_index_mask, fdel=_del_child_index_mask) + child_indices = property(fget=_get_child_indices, fdel = _del_child_indices) + + def retrieve_ghost_zones(self, n_zones, fields, all_levels=False, + smoothed=False): + # We will attempt this by creating a datacube that is exactly bigger + # than the grid by nZones*dx in each direction + nl = self.get_global_startindex() - n_zones + nr = nl + self.ActiveDimensions + 2*n_zones + new_left_edge = nl * self.dds + self.pf.domain_left_edge + new_right_edge = nr * self.dds + self.pf.domain_left_edge + # Something different needs to be done for the root grid, though + level = self.Level + if all_levels: + level = self.hierarchy.max_level + 1 + args = (level, new_left_edge, new_right_edge) + kwargs = {'dims': self.ActiveDimensions + 2*n_zones, + 'num_ghost_zones':n_zones, + 'use_pbar':False, 'fields':fields} + if smoothed: + #cube = self.hierarchy.smoothed_covering_grid( + # level, new_left_edge, new_right_edge, **kwargs) + cube = self.hierarchy.si_covering_grid( + level, new_left_edge, **kwargs) + else: + cube = self.hierarchy.covering_grid( + level, new_left_edge, **kwargs) + return cube + + def get_vertex_centered_data(self, field, smoothed=True): + cg = self.retrieve_ghost_zones(1, field, smoothed=smoothed) + # We have two extra zones in every direction + new_field = na.zeros(self.ActiveDimensions + 1, dtype='float64') + na.add(new_field, cg[field][1: ,1: ,1: ], new_field) + na.add(new_field, cg[field][:-1,1: ,1: ], new_field) + na.add(new_field, cg[field][1: ,:-1,1: ], new_field) + na.add(new_field, cg[field][1: ,1: ,:-1], new_field) + na.add(new_field, cg[field][:-1,1: ,:-1], new_field) + na.add(new_field, cg[field][1: ,:-1,:-1], new_field) + na.add(new_field, cg[field][:-1,:-1,1: ], new_field) + na.add(new_field, cg[field][:-1,:-1,:-1], new_field) + na.multiply(new_field, 0.125, new_field) + return new_field + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/hierarchy.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/hierarchy.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,392 @@ +""" +AMR hierarchy container class + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +import h5py +import numpy as na +import string, re, gc, time, cPickle, pdb +import weakref + +from itertools import chain, izip +from new import classobj + +from yt.funcs import * + +from yt.arraytypes import blankRecordArray +from yt.config import ytcfg +from yt.utilities.definitions import MAXLEVEL +from yt.utilities.io_handler import io_registry +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelAnalysisInterface, parallel_splitter +from object_finding_mixin import \ + ObjectFindingMixin + +from .data_containers import data_object_registry + +class AMRHierarchy(ObjectFindingMixin, ParallelAnalysisInterface): + float_type = 'float64' + + def __init__(self, pf, data_style): + self.parameter_file = weakref.proxy(pf) + self.pf = self.parameter_file + + self._initialize_state_variables() + + mylog.debug("Initializing data storage.") + self._initialize_data_storage() + + mylog.debug("Counting grids.") + self._count_grids() + + # Must be defined in subclass + mylog.debug("Setting up classes.") + self._setup_classes() + + mylog.debug("Counting grids.") + self._initialize_grid_arrays() + + mylog.debug("Parsing hierarchy.") + self._parse_hierarchy() + + mylog.debug("Constructing grid objects.") + self._populate_grid_objects() + + mylog.debug("Initializing data grid data IO") + self._setup_data_io() + + mylog.debug("Detecting fields.") + self._detect_fields() + + mylog.debug("Adding unknown detected fields") + self._setup_unknown_fields() + + mylog.debug("Setting up derived fields") + self._setup_derived_fields() + + mylog.debug("Re-examining hierarchy") + self._initialize_level_stats() + + def _get_parameters(self): + return self.parameter_file.parameters + parameters=property(_get_parameters) + + def select_grids(self, level): + """ + Returns an array of grids at *level*. + """ + return self.grids[self.grid_levels.flat == level] + + def get_levels(self): + for level in range(self.max_level+1): + yield self.select_grids(level) + + def _initialize_state_variables(self): + self._parallel_locking = False + self._data_file = None + self._data_mode = None + self._max_locations = {} + self.num_grids = None + + def _initialize_grid_arrays(self): + mylog.debug("Allocating arrays for %s grids", self.num_grids) + self.grid_dimensions = na.ones((self.num_grids,3), 'int32') + self.grid_left_edge = na.zeros((self.num_grids,3), self.float_type) + self.grid_right_edge = na.ones((self.num_grids,3), self.float_type) + self.grid_levels = na.zeros((self.num_grids,1), 'int32') + self.grid_particle_count = na.zeros((self.num_grids,1), 'int32') + + def _setup_classes(self, dd): + # Called by subclass + self.object_types = [] + self.objects = [] + for name, cls in sorted(data_object_registry.items()): + cname = cls.__name__ + if cname.endswith("Base"): cname = cname[:-4] + self._add_object_class(name, cname, cls, dd) + self.object_types.sort() + + # Now all the object related stuff + + def all_data(self, find_max=False): + pf = self.parameter_file + if find_max: c = self.find_max("Density")[1] + else: c = (pf.domain_right_edge + pf.domain_left_edge)/2.0 + return self.region(c, + pf.domain_left_edge, pf.domain_right_edge) + + def clear_all_data(self): + """ + This routine clears all the data currently being held onto by the grids + and the data io handler. + """ + for g in self.grids: g.clear_data() + self.io.queue.clear() + + def _get_data_reader_dict(self): + dd = { 'pf' : self.parameter_file, # Already weak + 'hierarchy': weakref.proxy(self) } + return dd + + def _initialize_data_storage(self): + if not ytcfg.getboolean('lagos','serialize'): return + fn = self.pf.storage_filename + if fn is None: + if os.path.isfile(os.path.join(self.directory, + "%s.yt" % self.pf.unique_identifier)): + fn = os.path.join(self.directory,"%s.yt" % self.pf.unique_identifier) + else: + fn = os.path.join(self.directory, + "%s.yt" % self.parameter_file.basename) + dir_to_check = os.path.dirname(fn) + # We have four options: + # Writeable, does not exist : create, open as append + # Writeable, does exist : open as append + # Not writeable, does not exist : do not attempt to open + # Not writeable, does exist : open as read-only + exists = os.path.isfile(fn) + if not exists: + writeable = os.access(dir_to_check, os.W_OK) + else: + writeable = os.access(fn, os.W_OK) + writeable = writeable and not ytcfg.getboolean('lagos','onlydeserialize') + # We now have our conditional stuff + self._barrier() + if not writeable and not exists: return + if writeable: + self._data_mode = 'a' + if not exists: self.__create_data_file(fn) + else: + self._data_mode = 'r' + + self.__data_filename = fn + self._data_file = h5py.File(fn, self._data_mode) + + def __create_data_file(self, fn): + # Note that this used to be parallel_root_only; it no longer is, + # because we have better logic to decide who owns the file. + f = h5py.File(fn, 'a') + f.close() + + def _setup_data_io(self): + self.io = io_registry[self.data_style]() + + def _save_data(self, array, node, name, set_attr=None, force=False, passthrough = False): + """ + Arbitrary numpy data will be saved to the region in the datafile + described by *node* and *name*. If data file does not exist, it throws + no error and simply does not save. + """ + + if self._data_mode != 'a': return + if "ArgsError" in dir(h5py.h5): + exception = h5py.h5.ArgsError + else: + exception = h5py.h5.H5Error + try: + node_loc = self._data_file[node] + if name in node_loc.listnames() and force: + mylog.info("Overwriting node %s/%s", node, name) + del self._data_file[node][name] + elif name in node_loc.listnames() and passthrough: + return + except exception: + pass + myGroup = self._data_file['/'] + for q in node.split('/'): + if q: myGroup = myGroup.require_group(q) + arr = myGroup.create_dataset(name,data=array) + if set_attr is not None: + for i, j in set_attr.items(): arr.attrs[i] = j + self._data_file.flush() + + def _reload_data_file(self, *args, **kwargs): + if self._data_file is None: return + self._data_file.close() + del self._data_file + self._data_file = h5py.File(self.__data_filename, self._data_mode) + + def _reset_save_data(self,round_robin=False): + if round_robin: + self.save_data = self._save_data + else: + self.save_data = parallel_splitter(self._save_data, self._reload_data_file) + + save_data = parallel_splitter(_save_data, _reload_data_file) + + def save_object(self, obj, name): + """ + Save an object (*obj*) to the data_file using the Pickle protocol, + under the name *name* on the node /Objects. + """ + s = cPickle.dumps(obj, protocol=-1) + self.save_data(s, "/Objects", name, force = True) + + def load_object(self, name): + """ + Load and return and object from the data_file using the Pickle protocol, + under the name *name* on the node /Objects. + """ + obj = self.get_data("/Objects", name) + if obj is None: + return + obj = cPickle.loads(obj.value) + if iterable(obj) and len(obj) == 2: + obj = obj[1] # Just the object, not the pf + if hasattr(obj, '_fix_pickle'): obj._fix_pickle() + return obj + + def get_data(self, node, name): + """ + Return the dataset with a given *name* located at *node* in the + datafile. + """ + if self._data_file == None: + return None + if node[0] != "/": node = "/%s" % node + + myGroup = self._data_file['/'] + for group in node.split('/'): + if group: + if group not in myGroup.listnames(): + return None + myGroup = myGroup[group] + if name not in myGroup.listnames(): + return None + + full_name = "%s/%s" % (node, name) + try: + return self._data_file[full_name][:] + except TypeError: + return self._data_file[full_name] + + def _close_data_file(self): + if self._data_file: + self._data_file.close() + del self._data_file + self._data_file = None + + def _deserialize_hierarchy(self, harray): + # THIS IS BROKEN AND NEEDS TO BE FIXED + mylog.debug("Cached entry found.") + self.gridDimensions[:] = harray[:,0:3] + self.gridStartIndices[:] = harray[:,3:6] + self.gridEndIndices[:] = harray[:,6:9] + self.gridLeftEdge[:] = harray[:,9:12] + self.gridRightEdge[:] = harray[:,12:15] + self.gridLevels[:] = harray[:,15:16] + self.gridTimes[:] = harray[:,16:17] + self.gridNumberOfParticles[:] = harray[:,17:18] + + def get_smallest_dx(self): + """ + Returns (in code units) the smallest cell size in the simulation. + """ + return self.select_grids(self.grid_levels.max())[0].dds[0] + + def _add_object_class(self, name, class_name, base, dd): + self.object_types.append(name) + obj = classobj(class_name, (base,), dd) + setattr(self, name, obj) + + def _initialize_level_stats(self): + # Now some statistics: + # 0 = number of grids + # 1 = number of cells + # 2 = blank + desc = {'names': ['numgrids','numcells','level'], + 'formats':['Int32']*3} + self.level_stats = blankRecordArray(desc, MAXLEVEL) + self.level_stats['level'] = [i for i in range(MAXLEVEL)] + self.level_stats['numgrids'] = [0 for i in range(MAXLEVEL)] + self.level_stats['numcells'] = [0 for i in range(MAXLEVEL)] + for level in xrange(self.max_level+1): + self.level_stats[level]['numgrids'] = na.sum(self.grid_levels == level) + li = (self.grid_levels[:,0] == level) + self.level_stats[level]['numcells'] = self.grid_dimensions[li,:].prod(axis=1).sum() + + @property + def grid_corners(self): + return na.array([ + [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_left_edge[:,2]], + [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_left_edge[:,2]], + [self.grid_right_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]], + [self.grid_right_edge[:,0], self.grid_right_edge[:,1], self.grid_right_edge[:,2]], + [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_right_edge[:,2]], + [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]], + [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]], + [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]], + ], dtype='float64') + + def print_stats(self): + """ + Prints out (stdout) relevant information about the simulation + """ + for level in xrange(MAXLEVEL): + if (self.level_stats['numgrids'][level]) == 0: + break + print "% 3i\t% 6i\t% 11i" % \ + (level, self.level_stats['numgrids'][level], + self.level_stats['numcells'][level]) + dx = self.select_grids(level)[0].dds[0] + print "-" * 28 + print " \t% 6i\t% 11i" % (self.level_stats['numgrids'].sum(), self.level_stats['numcells'].sum()) + print "\n" + try: + print "z = %0.8f" % (self["CosmologyCurrentRedshift"]) + except: + pass + t_s = self.pf.current_time * self.pf["Time"] + print "t = %0.8e = %0.8e s = %0.8e years" % \ + (self.pf.current_time, \ + t_s, t_s / (365*24*3600.0) ) + print "\nSmallest Cell:" + u=[] + for item in self.parameter_file.units.items(): + u.append((item[1],item[0])) + u.sort() + for unit in u: + print "\tWidth: %0.3e %s" % (dx*unit[0], unit[1]) + + +scanf_regex = {} +scanf_regex['e'] = r"[-+]?\d+\.?\d*?|\.\d+[eE][-+]?\d+?" +scanf_regex['g'] = scanf_regex['e'] +scanf_regex['f'] = scanf_regex['e'] +scanf_regex['F'] = scanf_regex['e'] +#scanf_regex['g'] = r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" +#scanf_regex['f'] = r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" +#scanf_regex['F'] = r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" +scanf_regex['i'] = r"[-+]?(0[xX][\dA-Fa-f]+|0[0-7]*|\d+)" +scanf_regex['d'] = r"[-+]?\d+" +scanf_regex['s'] = r"\S+" + +def constructRegularExpressions(param, toReadTypes): + re_e=r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" + re_i=r"[-+]?(0[xX][\dA-Fa-f]+|0[0-7]*|\d+)" + rs = "^%s\s*=\s*" % (param) + for t in toReadTypes: + rs += "(%s)\s*" % (scanf_regex[t]) + rs +="$" + return re.compile(rs,re.M) + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/object_finding_mixin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/object_finding_mixin.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,168 @@ +""" +AMR hierarchy container class + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +import numpy as na + +from yt.funcs import * + +class ObjectFindingMixin(object): + + def find_ray_grids(self, coord, axis): + """ + Returns the (objects, indices) of grids that an (x,y) ray intersects + along *axis* + """ + # Let's figure out which grids are on the slice + mask=na.ones(self.num_grids) + # So if gRE > coord, we get a mask, if not, we get a zero + # if gLE > coord, we get a zero, if not, mask + # Thus, if the coordinate is between the two edges, we win! + na.choose(na.greater(self.grid_right_edge[:,x_dict[axis]],coord[0]),(0,mask),mask) + na.choose(na.greater(self.grid_left_edge[:,x_dict[axis]],coord[0]),(mask,0),mask) + na.choose(na.greater(self.grid_right_edge[:,y_dict[axis]],coord[1]),(0,mask),mask) + na.choose(na.greater(self.grid_left_edge[:,y_dict[axis]],coord[1]),(mask,0),mask) + ind = na.where(mask == 1) + return self.grids[ind], ind + + def find_max(self, field, finest_levels = 3): + """ + Returns (value, center) of location of maximum for a given field. + """ + if (field, finest_levels) in self._max_locations: + return self._max_locations[(field, finest_levels)] + mg, mc, mv, pos = self.find_max_cell_location(field, finest_levels) + self._max_locations[(field, finest_levels)] = (mv, pos) + return mv, pos + + def find_max_cell_location(self, field, finest_levels = 3): + if finest_levels is not False: + gi = (self.grid_levels >= self.max_level - finest_levels).ravel() + source = self.grid_collection([0.0]*3, self.grids[gi]) + else: + source = self.all_data() + mylog.debug("Searching %s grids for maximum value of %s", + len(source._grids), field) + max_val, maxi, mx, my, mz, mg = \ + source.quantities["MaxLocation"]( field, lazy_reader=True) + max_grid = self.grids[mg] + mc = na.unravel_index(maxi, max_grid.ActiveDimensions) + mylog.info("Max Value is %0.5e at %0.16f %0.16f %0.16f in grid %s at level %s %s", \ + max_val, mx, my, mz, max_grid, max_grid.Level, mc) + self.parameters["Max%sValue" % (field)] = max_val + self.parameters["Max%sPos" % (field)] = "%s" % ((mx,my,mz),) + return max_grid, mc, max_val, na.array((mx,my,mz), dtype='float64') + + def find_min(self, field): + """ + Returns (value, center) of location of minimum for a given field + """ + gI = na.where(self.grid_levels >= 0) # Slow but pedantic + minVal = 1e100 + for grid in self.grids[gI[0]]: + mylog.debug("Checking %s (level %s)", grid.id, grid.Level) + val, coord = grid.find_min(field) + if val < minVal: + minCoord = coord + minVal = val + minGrid = grid + mc = na.array(minCoord) + pos=minGrid.get_position(mc) + mylog.info("Min Value is %0.5e at %0.16f %0.16f %0.16f in grid %s at level %s", \ + minVal, pos[0], pos[1], pos[2], minGrid, minGrid.Level) + self.center = pos + self.parameters["Min%sValue" % (field)] = minVal + self.parameters["Min%sPos" % (field)] = "%s" % (pos) + return minVal, pos + + def find_point(self, coord): + """ + Returns the (objects, indices) of grids containing an (x,y,z) point + """ + mask=na.ones(self.num_grids) + for i in xrange(len(coord)): + na.choose(na.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask) + na.choose(na.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask) + ind = na.where(mask == 1) + return self.grids[ind], ind + + def find_slice_grids(self, coord, axis): + """ + Returns the (objects, indices) of grids that a slice intersects along + *axis* + """ + # Let's figure out which grids are on the slice + mask=na.ones(self.num_grids) + # So if gRE > coord, we get a mask, if not, we get a zero + # if gLE > coord, we get a zero, if not, mask + # Thus, if the coordinate is between the edges, we win! + #ind = na.where( na.logical_and(self.grid_right_edge[:,axis] > coord, \ + #self.grid_left_edge[:,axis] < coord)) + na.choose(na.greater(self.grid_right_edge[:,axis],coord),(0,mask),mask) + na.choose(na.greater(self.grid_left_edge[:,axis],coord),(mask,0),mask) + ind = na.where(mask == 1) + return self.grids[ind], ind + + def find_sphere_grids(self, center, radius): + """ + Returns objects, indices of grids within a sphere + """ + centers = (self.grid_right_edge + self.grid_left_edge)/2.0 + long_axis = na.maximum.reduce(self.grid_right_edge - self.grid_left_edge, 1) + t = na.abs(centers - center) + DW = self.parameter_file["DomainRightEdge"] \ + - self.parameter_file["DomainLeftEdge"] + na.minimum(t, na.abs(DW-t), t) + dist = na.sqrt(na.sum((t**2.0), axis=1)) + gridI = na.where(dist < (radius + long_axis)) + return self.grids[gridI], gridI + + def get_box_grids(self, left_edge, right_edge): + """ + Gets back all the grids between a left edge and right edge + """ + grid_i = na.where((na.all(self.grid_right_edge > left_edge, axis=1) + & na.all(self.grid_left_edge < right_edge, axis=1)) == True) + return self.grids[grid_i], grid_i + + def get_periodic_box_grids(self, left_edge, right_edge): + left_edge = na.array(left_edge) + right_edge = na.array(right_edge) + mask = na.zeros(self.grids.shape, dtype='bool') + dl = self.parameters["DomainLeftEdge"] + dr = self.parameters["DomainRightEdge"] + db = right_edge - left_edge + for off_x in [-1, 0, 1]: + nle = left_edge.copy() + nre = left_edge.copy() + nle[0] = dl[0] + (dr[0]-dl[0])*off_x + left_edge[0] + for off_y in [-1, 0, 1]: + nle[1] = dl[1] + (dr[1]-dl[1])*off_y + left_edge[1] + for off_z in [-1, 0, 1]: + nle[2] = dl[2] + (dr[2]-dl[2])*off_z + left_edge[2] + nre = nle + db + g, gi = self.get_box_grids(nle, nre) + mask[gi] = True + return self.grids[mask], na.where(mask) + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/particle_io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/particle_io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,148 @@ +""" +The particle-IO handler + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2009 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 . +""" + +import numpy as na + +from yt.funcs import * + +particle_handler_registry = defaultdict() + +class ParticleIOHandler(object): + class __metaclass__(type): + def __init__(cls, name, b, d): + type.__init__(cls, name, b, d) + if hasattr(cls, "_source_type"): + particle_handler_registry[cls._source_type] = cls + + _source_type = None + + def __init__(self, pf, source): + self.pf = pf + self.source = source + + def __getitem__(self, key): + return self.get_data(key) + + def get_data(self, fields): + fields = ensure_list(fields) + rvs = self.source.get_data(fields, force_particle_read=True) + if len(fields) == 1: return rvs[0] + return rvs + +particle_handler_registry.default_factory = lambda: ParticleIOHandler + +class ParticleIOHandlerImplemented(ParticleIOHandler): + def get_data(self, fields): + mylog.info("Getting %s using ParticleIO" % str(fields)) + fields = ensure_list(fields) + if not self.pf.h.io._particle_reader: + mylog.info("not self.pf.h.io._particle_reader") + return self.source.get_data(fields) + rtype, args = self._get_args() + count_list, grid_list = [], [] + for grid in self.source._grids: + if grid.NumberOfParticles == 0: continue + grid_list.append(grid) + if self.source._is_fully_enclosed(grid): + count_list.append(grid.NumberOfParticles) + else: + count_list.append(-1) + # region type, left_edge, right_edge, periodic, grid_list + fields_to_read = [] + conv_factors = [] + for field in fields: + f = self.pf.field_info[field] + to_add = f.get_dependencies(pf = self.pf).requested + to_add = list(na.unique(to_add)) + if len(to_add) != 1: raise KeyError + fields_to_read += to_add + if f._particle_convert_function is None: + func = f._convert_function + else: + func = f.particle_convert + conv_factors.append( + na.fromiter((func(g) for g in grid_list), + count=len(grid_list), dtype='float64')) + conv_factors = na.array(conv_factors).transpose() + self.conv_factors = conv_factors + rvs = self.pf.h.io._read_particles( + fields_to_read, rtype, args, grid_list, count_list, + conv_factors) + if len(fields) == 1: return rvs[0] + return rvs + +class ParticleIOHandlerRegion(ParticleIOHandlerImplemented): + periodic = False + _source_type = "region" + + def __init__(self, pf, source): + self.left_edge = source.left_edge + self.right_edge = source.right_edge + ParticleIOHandler.__init__(self, pf, source) + + def _get_args(self): + DLE = na.array(self.pf.domain_left_edge, dtype='float64') + DRE = na.array(self.pf.domain_right_edge, dtype='float64') + args = (na.array(self.left_edge), na.array(self.right_edge), + int(self.periodic), DLE, DRE) + return (0, args) + +class ParticleIOHandlerRegionStrict(ParticleIOHandlerRegion): + _source_type = "region_strict" + +class ParticleIOHandlerPeriodicRegion(ParticleIOHandlerRegion): + periodic = True + _source_type = "periodic_region" + +class ParticleIOHandlerPeriodicRegionStrict(ParticleIOHandlerPeriodicRegion): + _source_type = "periodic_region_strict" + +class ParticleIOHandlerSphere(ParticleIOHandlerImplemented): + _source_type = "sphere" + + def __init__(self, pf, source): + self.center = source.center + self.radius = source.radius + ParticleIOHandler.__init__(self, pf, source) + + def _get_args(self): + return (1, (na.array(self.center, dtype='float64'), self.radius)) + +class ParticleIOHandlerDisk(ParticleIOHandlerImplemented): + _source_type = "disk" + + def __init__(self, pf, source): + self.center = source.center + self.normal = source._norm_vec + self.radius = source._radius + self.height = source._height + ParticleIOHandler.__init__(self, pf, source) + + def _get_args(self): + args = (na.array(self.center, dtype='float64'), + na.array(self.normal, dtype='float64'), + self.radius, self.height) + return (2, args) + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/profiles.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/profiles.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,816 @@ +""" +Profile classes, to deal with generating and obtaining profiles + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Author: Samuel Skillman +Affiliation: CASA, University of Colorado at Boulder +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +import numpy as na + +from yt.funcs import * + +from yt.utilities.data_point_utilities import Bin2DProfile, \ + Bin3DProfile +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + ParallelAnalysisInterface + +_field_mapping = { + "total_mass": ("CellMassMsun", "ParticleMassMsun"), + "hybrid_radius": ("RadiusCode", "ParticleRadiusCode"), + } + +class EmptyProfileData(Exception): + pass + +def preserve_source_parameters(func): + def save_state(*args, **kwargs): + # Temporarily replace the 'field_parameters' for a + # grid with the 'field_parameters' for the data source + prof = args[0] + source = args[1] + if hasattr(source, 'field_parameters'): + old_params = source.field_parameters + source.field_parameters = prof._data_source.field_parameters + tr = func(*args, **kwargs) + source.field_parameters = old_params + else: + tr = func(*args, **kwargs) + return tr + return save_state + +# Note we do not inherit from EnzoData. +# We could, but I think we instead want to deal with the root datasource. +class BinnedProfile(ParallelAnalysisInterface): + def __init__(self, data_source, lazy_reader): + self._data_source = data_source + self.pf = data_source.pf + self._data = {} + self._pdata = {} + self._lazy_reader = lazy_reader + + @property + def hierarchy(self): + return self.pf.hierarchy + + def _get_dependencies(self, fields): + return ParallelAnalysisInterface._get_dependencies( + self, fields + self._get_bin_fields()) + + def _initialize_parallel(self, fields): + g_objs = [g for g in self._get_grid_objs()] + self._preload(g_objs, self._get_dependencies(fields), + self._data_source.hierarchy.io) + + def _lazy_add_fields(self, fields, weight, accumulation): + self._ngrids = 0 + self.__data = {} # final results will go here + self.__weight_data = {} # we need to track the weights as we go + for field in fields: + self.__data[field] = self._get_empty_field() + self.__weight_data[field] = self._get_empty_field() + self.__used = self._get_empty_field().astype('bool') + #pbar = get_pbar('Binning grids', len(self._data_source._grids)) + for gi,grid in enumerate(self._get_grids(fields)): + self._ngrids += 1 + #pbar.update(gi) + try: + args = self._get_bins(grid, check_cut=True) + except EmptyProfileData: + # No bins returned for this grid, so forget it! + continue + for field in fields: + # We get back field values, weight values, used bins + f, w, u = self._bin_field(grid, field, weight, accumulation, + args=args, check_cut=True) + self.__data[field] += f # running total + self.__weight_data[field] += w # running total + self.__used = (self.__used | u) # running 'or' + grid.clear_data() + # When the loop completes the parallel finalizer gets called + #pbar.finish() + ub = na.where(self.__used) + for field in fields: + if weight: # Now, at the end, we divide out. + self.__data[field][ub] /= self.__weight_data[field][ub] + self[field] = self.__data[field] + self["UsedBins"] = self.__used + del self.__data, self.__weight_data, self.__used + + def _finalize_parallel(self): + for key in self.__data: + self.__data[key] = self._mpi_allsum(self.__data[key]) + for key in self.__weight_data: + self.__weight_data[key] = self._mpi_allsum(self.__weight_data[key]) + self.__used = self._mpi_allsum(self.__used) + + def _unlazy_add_fields(self, fields, weight, accumulation): + for field in fields: + f, w, u = self._bin_field(self._data_source, field, weight, + accumulation, self._args, check_cut = False) + if weight: + f[u] /= w[u] + self[field] = f + self["myweight"] = w + self["UsedBins"] = u + + def add_fields(self, fields, weight = "CellMassMsun", accumulation = False, fractional=False): + """ + We accept a list of *fields* which will be binned if *weight* is not + None and otherwise summed. *accumulation* determines whether or not + they will be accumulated from low to high along the appropriate axes. + """ + # Note that the specification has to be the same for all of these + fields = ensure_list(fields) + if self._lazy_reader: + self._lazy_add_fields(fields, weight, accumulation) + else: + self._unlazy_add_fields(fields, weight, accumulation) + if fractional: + for field in fields: + self._data[field] /= self._data[field].sum() + + def keys(self): + return self._data.keys() + + def __getitem__(self, key): + # This raises a KeyError if it doesn't exist + # This is because we explicitly want to add all fields + return self._data[key] + + def __setitem__(self, key, value): + self._data[key] = value + + def _get_field(self, source, this_field, check_cut): + # This is where we will iterate to get all contributions to a field + # which is how we will implement hybrid particle/cell fields + # but... we default to just the field. + data = [] + for field in _field_mapping.get(this_field, (this_field,)): + pointI = None + if check_cut: + # This conditional is so that we can have variable-length + # particle fields. Note that we can't apply the + # is_fully_enclosed to baryon fields, because child cells get + # in the way. + if field in self.pf.field_info \ + and self.pf.field_info[field].particle_type: + if not self._data_source._is_fully_enclosed(source): + pointI = self._data_source._get_particle_indices(source) + else: + pointI = self._data_source._get_point_indices(source) + data.append(source[field][pointI].ravel().astype('float64')) + return na.concatenate(data, axis=0) + + def _fix_pickle(self): + if isinstance(self._data_source, tuple): + self._data_source = self._data_source[1] + +# @todo: Fix accumulation with overriding +class BinnedProfile1D(BinnedProfile): + def __init__(self, data_source, n_bins, bin_field, + lower_bound, upper_bound, + log_space = True, lazy_reader=False, + end_collect=False): + """ + A 'Profile' produces either a weighted (or unweighted) average or a + straight sum of a field in a bin defined by another field. In the case + of a weighted average, we have: p_i = sum( w_i * v_i ) / sum(w_i) + + We accept a *data_source*, which will be binned into *n_bins* + by the field *bin_field* between the *lower_bound* and the + *upper_bound*. These bins may or may not be equally divided + in *log_space*, and the *lazy_reader* flag controls whether we + use a memory conservative approach. If *end_collect* is True, + take all values outside the given bounds and store them in the + 0 and *n_bins*-1 values. + """ + BinnedProfile.__init__(self, data_source, lazy_reader) + self.bin_field = bin_field + self._x_log = log_space + self.end_collect = end_collect + self.n_bins = n_bins + + # Get our bins + if log_space: + func = na.logspace + lower_bound, upper_bound = na.log10(lower_bound), na.log10(upper_bound) + else: + func = na.linspace + + # These are the bin *edges* + self._bins = func(lower_bound, upper_bound, n_bins + 1) + + # These are the bin *left edges*. These are the x-axis values + # we plot in the PlotCollection + self[bin_field] = self._bins + + # If we are not being memory-conservative, grab all the bins + # and the inverse indices right now. + if not lazy_reader: + self._args = self._get_bins(data_source) + + def _get_empty_field(self): + return na.zeros(self[self.bin_field].size, dtype='float64') + + @preserve_source_parameters + def _bin_field(self, source, field, weight, accumulation, + args, check_cut=False): + mi, inv_bin_indices = args # Args has the indices to use as input + # check_cut is set if source != self._data_source + # (i.e., lazy_reader) + source_data = self._get_field(source, field, check_cut)[mi] + if weight: weight_data = self._get_field(source, weight, check_cut)[mi] + binned_field = self._get_empty_field() + weight_field = self._get_empty_field() + used_field = self._get_empty_field() + # Now we perform the actual binning + for bin in inv_bin_indices.keys(): + # temp_field is *all* the points from source that go into this bin + temp_field = source_data[inv_bin_indices[bin]] + if weight: + # now w_i * v_i and store sum(w_i) + weight_field[bin] = weight_data[inv_bin_indices[bin]].sum() + temp_field *= weight_data[inv_bin_indices[bin]] + binned_field[bin] = temp_field.sum() + # inv_bin_indices is a tuple of indices + if inv_bin_indices[bin][0].size > 0: used_field[bin] = 1 + # Fix for laziness, because at the *end* we will be + # summing up all of the histograms and dividing by the + # weights. Accumulation likely doesn't work with weighted + # average fields. + if accumulation: + binned_field = na.add.accumulate(binned_field) + return binned_field, weight_field, used_field.astype("bool") + + @preserve_source_parameters + def _get_bins(self, source, check_cut=False): + source_data = self._get_field(source, self.bin_field, check_cut) + if source_data.size == 0: # Nothing for us here. + raise EmptyProfileData() + # Truncate at boundaries. + if self.end_collect: + mi = na.arange(source_data.size) + else: + mi = na.where( (source_data > self._bins.min()) + & (source_data < self._bins.max())) + sd = source_data[mi] + if sd.size == 0: + raise EmptyProfileData() + # Stick the bins into our fixed bins, set at initialization + bin_indices = na.digitize(sd, self._bins) + if self.end_collect: #limit the range of values to 0 and n_bins-1 + bin_indices = na.minimum(na.maximum(1, bin_indices), self.n_bins) - 1 + else: #throw away outside values + bin_indices -= 1 + + # Now we set up our inverse bin indices + inv_bin_indices = {} + for bin in range(self[self.bin_field].size): + # Which fall into our bin? + inv_bin_indices[bin] = na.where(bin_indices == bin) + return (mi, inv_bin_indices) + + def choose_bins(self, bin_style): + # Depending on the bin_style, choose from bin edges 0...N either: + # both: 0...N, left: 0...N-1, right: 1...N + # center: N bins that are the average (both in linear or log + # space) of each pair of left/right edges + x = self._data[self.bin_field] + if bin_style is 'both': pass + elif bin_style is 'left': x = x[:-1] + elif bin_style is 'right': x = x[1:] + elif bin_style is 'center': + if self._x_log: x=na.log10(x) + x = 0.5*(x[:-1] + x[1:]) + if self._x_log: x=10**x + else: + mylog.error('Did not recognize bin_style') + raise ValueError + return x + + def write_out(self, filename, format="%0.16e", bin_style='left'): + ''' + Write out data in ascii file, using *format* and + *bin_style* (left, right, center, both). + ''' + fid = open(filename,"w") + fields = [field for field in sorted(self._data.keys()) if field != "UsedBins"] + fields.remove(self.bin_field) + fid.write("\t".join(["#"] + [self.bin_field] + fields + ["\n"])) + + field_data = na.array(self.choose_bins(bin_style)) + if bin_style is 'both': + field_data = na.append([field_data], na.array([self._data[field] for field in fields]), axis=0) + else: + field_data = na.append([field_data], na.array([self._data[field][:-1] for field in fields]), axis=0) + + for line in range(field_data.shape[1]): + field_data[:,line].tofile(fid, sep="\t", format=format) + fid.write("\n") + fid.close() + + def write_out_h5(self, filename, group_prefix=None, bin_style='left'): + """ + Write out data in an hdf5 file *filename*. Each profile is + put into a group, named by the axis fields. Optionally a + *group_prefix* can be prepended to the group name. If the + group already exists, it will delete and replace. However, + due to hdf5 functionality, in only unlinks the data, so an + h5repack may be necessary to conserve space. Axes values are + saved in group attributes. Bins will be saved based on + *bin_style* (left, right, center, both). + """ + fid = h5py.File(filename) + fields = [field for field in sorted(self._data.keys()) if (field != "UsedBins" and field != self.bin_field)] + if group_prefix is None: + name = "%s-1d" % (self.bin_field) + else: + name = "%s-%s-1d" % (group_prefix, self.bin_field) + + if name in fid: + mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack") + del fid[name] + group = fid.create_group(name) + group.attrs["x-axis-%s" % self.bin_field] = self.choose_bins(bin_style) + for field in fields: + dset = group.create_dataset("%s" % field, data=self._data[field][:-1]) + fid.close() + + def _get_bin_fields(self): + return [self.bin_field] + +class BinnedProfile2D(BinnedProfile): + def __init__(self, data_source, + x_n_bins, x_bin_field, x_lower_bound, x_upper_bound, x_log, + y_n_bins, y_bin_field, y_lower_bound, y_upper_bound, y_log, + lazy_reader=False, end_collect=False): + """ + A 'Profile' produces either a weighted (or unweighted) average + or a straight sum of a field in a bin defined by two other + fields. In the case of a weighted average, we have: p_i = + sum( w_i * v_i ) / sum(w_i) + + We accept a *data_source*, which will be binned into + *x_n_bins* by the field *x_bin_field* between the + *x_lower_bound* and the *x_upper_bound* and then again binned + into *y_n_bins* by the field *y_bin_field* between the + *y_lower_bound* and the *y_upper_bound*. These bins may or + may not be equally divided in log-space as specified by + *x_log* and *y_log*, and the *lazy_reader* flag controls + whether we use a memory conservative approach. If + *end_collect* is True, take all values outside the given + bounds and store them in the 0 and *n_bins*-1 values. + """ + BinnedProfile.__init__(self, data_source, lazy_reader) + self.x_bin_field = x_bin_field + self.y_bin_field = y_bin_field + self._x_log = x_log + self._y_log = y_log + self.end_collect = end_collect + self.x_n_bins = x_n_bins + self.y_n_bins = y_n_bins + + func = {True:na.logspace, False:na.linspace}[x_log] + bounds = fix_bounds(x_lower_bound, x_upper_bound, x_log) + self._x_bins = func(bounds[0], bounds[1], x_n_bins + 1) + self[x_bin_field] = self._x_bins + + func = {True:na.logspace, False:na.linspace}[y_log] + bounds = fix_bounds(y_lower_bound, y_upper_bound, y_log) + self._y_bins = func(bounds[0], bounds[1], y_n_bins + 1) + self[y_bin_field] = self._y_bins + + if na.any(na.isnan(self[x_bin_field])) \ + or na.any(na.isnan(self[y_bin_field])): + mylog.error("Your min/max values for x, y have given me a nan.") + mylog.error("Usually this means you are asking for log, with a zero bound.") + raise ValueError + if not lazy_reader: + self._args = self._get_bins(data_source) + + def _get_empty_field(self): + return na.zeros((self[self.x_bin_field].size, + self[self.y_bin_field].size), dtype='float64') + + @preserve_source_parameters + def _bin_field(self, source, field, weight, accumulation, + args, check_cut=False): + source_data = self._get_field(source, field, check_cut) + if weight: weight_data = self._get_field(source, weight, check_cut) + else: weight_data = na.ones(source_data.shape, dtype='float64') + self.total_stuff = source_data.sum() + binned_field = self._get_empty_field() + weight_field = self._get_empty_field() + used_field = self._get_empty_field() + mi = args[0] + bin_indices_x = args[1].ravel().astype('int64') + bin_indices_y = args[2].ravel().astype('int64') + source_data = source_data[mi] + weight_data = weight_data[mi] + nx = bin_indices_x.size + #mylog.debug("Binning %s / %s times", source_data.size, nx) + Bin2DProfile(bin_indices_x, bin_indices_y, weight_data, source_data, + weight_field, binned_field, used_field) + if accumulation: # Fix for laziness + if not iterable(accumulation): + raise SyntaxError("Accumulation needs to have length 2") + if accumulation[0]: + binned_field = na.add.accumulate(binned_field, axis=0) + if accumulation[1]: + binned_field = na.add.accumulate(binned_field, axis=1) + return binned_field, weight_field, used_field.astype('bool') + + @preserve_source_parameters + def _get_bins(self, source, check_cut=False): + source_data_x = self._get_field(source, self.x_bin_field, check_cut) + source_data_y = self._get_field(source, self.y_bin_field, check_cut) + if source_data_x.size == 0: + raise EmptyProfileData() + + if self.end_collect: + mi = na.arange(source_data_x.size) + else: + mi = na.where( (source_data_x > self._x_bins.min()) + & (source_data_x < self._x_bins.max()) + & (source_data_y > self._y_bins.min()) + & (source_data_y < self._y_bins.max())) + sd_x = source_data_x[mi] + sd_y = source_data_y[mi] + if sd_x.size == 0 or sd_y.size == 0: + raise EmptyProfileData() + + bin_indices_x = na.digitize(sd_x, self._x_bins) - 1 + bin_indices_y = na.digitize(sd_y, self._y_bins) - 1 + if self.end_collect: + bin_indices_x = na.minimum(na.maximum(1, bin_indices_x), self.x_n_bins) - 1 + bin_indices_y = na.minimum(na.maximum(1, bin_indices_y), self.y_n_bins) - 1 + + # Now we set up our inverse bin indices + return (mi, bin_indices_x, bin_indices_y) + + def choose_bins(self, bin_style): + # Depending on the bin_style, choose from bin edges 0...N either: + # both: 0...N, left: 0...N-1, right: 1...N + # center: N bins that are the average (both in linear or log + # space) of each pair of left/right edges + + x = self._data[self.x_bin_field] + y = self._data[self.y_bin_field] + if bin_style is 'both': + pass + elif bin_style is 'left': + x = x[:-1] + y = y[:-1] + elif bin_style is 'right': + x = x[1:] + y = y[1:] + elif bin_style is 'center': + if self._x_log: x=na.log10(x) + if self._y_log: y=na.log10(y) + x = 0.5*(x[:-1] + x[1:]) + y = 0.5*(y[:-1] + y[1:]) + if self._x_log: x=10**x + if self._y_log: y=10**y + else: + mylog.error('Did not recognize bin_style') + raise ValueError + + return x,y + + def write_out(self, filename, format="%0.16e", bin_style='left'): + """ + Write out the values of x,y,v in ascii to *filename* for every + field in the profile. Optionally a *format* can be specified. + Bins will be saved based on *bin_style* (left, right, center, + both). + """ + fid = open(filename,"w") + fields = [field for field in sorted(self._data.keys()) if field != "UsedBins"] + fid.write("\t".join(["#"] + [self.x_bin_field, self.y_bin_field] + + fields + ["\n"])) + x,y = self.choose_bins(bin_style) + x,y = na.meshgrid(x,y) + field_data = [x.ravel(), y.ravel()] + if bin_style is not 'both': + field_data += [self._data[field][:-1,:-1].ravel() for field in fields + if field not in [self.x_bin_field, self.y_bin_field]] + else: + field_data += [self._data[field].ravel() for field in fields + if field not in [self.x_bin_field, self.y_bin_field]] + + field_data = na.array(field_data) + for line in range(field_data.shape[1]): + field_data[:,line].tofile(fid, sep="\t", format=format) + fid.write("\n") + fid.close() + + def write_out_h5(self, filename, group_prefix=None, bin_style='left'): + """ + Write out data in an hdf5 file. Each profile is put into a + group, named by the axis fields. Optionally a group_prefix + can be prepended to the group name. If the group already + exists, it will delete and replace. However, due to hdf5 + functionality, in only unlinks the data, so an h5repack may be + necessary to conserve space. Axes values are saved in group + attributes. Bins will be saved based on *bin_style* (left, + right, center, both). + """ + fid = h5py.File(filename) + fields = [field for field in sorted(self._data.keys()) if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field)] + if group_prefix is None: + name = "%s-%s-2d" % (self.y_bin_field, self.x_bin_field) + else: + name = "%s-%s-%s-2d" % (group_prefix, self.y_bin_field, self.x_bin_field) + if name in fid: + mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack") + del fid[name] + group = fid.create_group(name) + + xbins, ybins = self.choose_bins(bin_style) + group.attrs["x-axis-%s" % self.x_bin_field] = xbins + group.attrs["y-axis-%s" % self.y_bin_field] = ybins + for field in fields: + dset = group.create_dataset("%s" % field, data=self._data[field][:-1,:-1]) + fid.close() + + def _get_bin_fields(self): + return [self.x_bin_field, self.y_bin_field] + +def fix_bounds(upper, lower, logit): + if logit: return na.log10(upper), na.log10(lower) + return upper, lower + +class BinnedProfile3D(BinnedProfile): + """ + A 'Profile' produces either a weighted (or unweighted) average + or a straight sum of a field in a bin defined by two other + fields. In the case of a weighted average, we have: p_i = + sum( w_i * v_i ) / sum(w_i) + + We accept a *data_source*, which will be binned into + *(x,y,z)_n_bins* by the field *(x,y,z)_bin_field* between the + *(x,y,z)_lower_bound* and the *(x,y,z)_upper_bound*. These bins may or + may not be equally divided in log-space as specified by + *(x,y,z)_log*, and the *lazy_reader* flag controls + whether we use a memory conservative approach. If + *end_collect* is True, take all values outside the given + bounds and store them in the 0 and *n_bins*-1 values. + """ + def __init__(self, data_source, + x_n_bins, x_bin_field, x_lower_bound, x_upper_bound, x_log, + y_n_bins, y_bin_field, y_lower_bound, y_upper_bound, y_log, + z_n_bins, z_bin_field, z_lower_bound, z_upper_bound, z_log, + lazy_reader=False, end_collect=False): + BinnedProfile.__init__(self, data_source, lazy_reader) + self.x_bin_field = x_bin_field + self.y_bin_field = y_bin_field + self.z_bin_field = z_bin_field + self._x_log = x_log + self._y_log = y_log + self._z_log = z_log + self.end_collect = end_collect + self.x_n_bins = x_n_bins + self.y_n_bins = y_n_bins + self.z_n_bins = z_n_bins + + func = {True:na.logspace, False:na.linspace}[x_log] + bounds = fix_bounds(x_lower_bound, x_upper_bound, x_log) + self._x_bins = func(bounds[0], bounds[1], x_n_bins + 1) + self[x_bin_field] = self._x_bins + + func = {True:na.logspace, False:na.linspace}[y_log] + bounds = fix_bounds(y_lower_bound, y_upper_bound, y_log) + self._y_bins = func(bounds[0], bounds[1], y_n_bins + 1) + self[y_bin_field] = self._y_bins + + func = {True:na.logspace, False:na.linspace}[z_log] + bounds = fix_bounds(z_lower_bound, z_upper_bound, z_log) + self._z_bins = func(bounds[0], bounds[1], z_n_bins + 1) + self[z_bin_field] = self._z_bins + + if na.any(na.isnan(self[x_bin_field])) \ + or na.any(na.isnan(self[y_bin_field])) \ + or na.any(na.isnan(self[z_bin_field])): + mylog.error("Your min/max values for x, y or z have given me a nan.") + mylog.error("Usually this means you are asking for log, with a zero bound.") + raise ValueError + if not lazy_reader: + self._args = self._get_bins(data_source) + + def _get_empty_field(self): + return na.zeros((self[self.x_bin_field].size, + self[self.y_bin_field].size, + self[self.z_bin_field].size), dtype='float64') + + @preserve_source_parameters + def _bin_field(self, source, field, weight, accumulation, + args, check_cut=False): + source_data = self._get_field(source, field, check_cut) + weight_data = na.ones(source_data.shape).astype('float64') + if weight: weight_data = self._get_field(source, weight, check_cut) + else: weight_data = na.ones(source_data.shape).astype('float64') + self.total_stuff = source_data.sum() + binned_field = self._get_empty_field() + weight_field = self._get_empty_field() + used_field = self._get_empty_field() + mi = args[0] + bin_indices_x = args[1].ravel().astype('int64') + bin_indices_y = args[2].ravel().astype('int64') + bin_indices_z = args[3].ravel().astype('int64') + source_data = source_data[mi] + weight_data = weight_data[mi] + Bin3DProfile( + bin_indices_x, bin_indices_y, bin_indices_z, + weight_data, source_data, + weight_field, binned_field, used_field) + if accumulation: # Fix for laziness + if not iterable(accumulation): + raise SyntaxError("Accumulation needs to have length 2") + if accumulation[0]: + binned_field = na.add.accumulate(binned_field, axis=0) + if accumulation[1]: + binned_field = na.add.accumulate(binned_field, axis=1) + if accumulation[2]: + binned_field = na.add.accumulate(binned_field, axis=2) + return binned_field, weight_field, used_field.astype('bool') + + @preserve_source_parameters + def _get_bins(self, source, check_cut=False): + source_data_x = self._get_field(source, self.x_bin_field, check_cut) + source_data_y = self._get_field(source, self.y_bin_field, check_cut) + source_data_z = self._get_field(source, self.z_bin_field, check_cut) + if source_data_x.size == 0: + raise EmptyProfileData() + if self.end_collect: + mi = na.arange(source_data_x.size) + else: + mi = ( (source_data_x > self._x_bins.min()) + & (source_data_x < self._x_bins.max()) + & (source_data_y > self._y_bins.min()) + & (source_data_y < self._y_bins.max()) + & (source_data_z > self._z_bins.min()) + & (source_data_z < self._z_bins.max())) + sd_x = source_data_x[mi] + sd_y = source_data_y[mi] + sd_z = source_data_z[mi] + if sd_x.size == 0 or sd_y.size == 0 or sd_z.size == 0: + raise EmptyProfileData() + + bin_indices_x = na.digitize(sd_x, self._x_bins) - 1 + bin_indices_y = na.digitize(sd_y, self._y_bins) - 1 + bin_indices_z = na.digitize(sd_z, self._z_bins) - 1 + if self.end_collect: + bin_indices_x = na.minimum(na.maximum(1, bin_indices_x), self.x_n_bins) - 1 + bin_indices_y = na.minimum(na.maximum(1, bin_indices_y), self.y_n_bins) - 1 + bin_indices_z = na.minimum(na.maximum(1, bin_indices_z), self.z_n_bins) - 1 + + # Now we set up our inverse bin indices + return (mi, bin_indices_x, bin_indices_y, bin_indices_z) + + def choose_bins(self, bin_style): + # Depending on the bin_style, choose from bin edges 0...N either: + # both: 0...N, left: 0...N-1, right: 1...N + # center: N bins that are the average (both in linear or log + # space) of each pair of left/right edges + + x = self._data[self.x_bin_field] + y = self._data[self.y_bin_field] + z = self._data[self.z_bin_field] + if bin_style is 'both': + pass + elif bin_style is 'left': + x = x[:-1] + y = y[:-1] + z = z[:-1] + elif bin_style is 'right': + x = x[1:] + y = y[1:] + z = z[1:] + elif bin_style is 'center': + if self._x_log: x=na.log10(x) + if self._y_log: y=na.log10(y) + if self._z_log: z=na.log10(z) + x = 0.5*(x[:-1] + x[1:]) + y = 0.5*(y[:-1] + y[1:]) + z = 0.5*(z[:-1] + z[1:]) + if self._x_log: x=10**x + if self._y_log: y=10**y + if self._z_log: y=10**z + else: + mylog.error('Did not recognize bin_style') + raise ValueError + + return x,y,z + + def write_out(self, filename, format="%0.16e"): + pass # Will eventually dump HDF5 + + def write_out_h5(self, filename, group_prefix=None, bin_style='left'): + """ + Write out data in an hdf5 file. Each profile is put into a + group, named by the axis fields. Optionally a group_prefix + can be prepended to the group name. If the group already + exists, it will delete and replace. However, due to hdf5 + functionality, in only unlinks the data, so an h5repack may be + necessary to conserve space. Axes values are saved in group + attributes. + """ + fid = h5py.File(filename) + fields = [field for field in sorted(self._data.keys()) + if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field and field != self.z_bin_field)] + if group_prefix is None: + name = "%s-%s-%s-3d" % (self.z_bin_field, self.y_bin_field, self.x_bin_field) + else: + name = "%s-%s-%s-%s-3d" % (group_prefix,self.z_bin_field, self.y_bin_field, self.x_bin_field) + + if name in fid: + mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack") + del fid[name] + group = fid.create_group(name) + + xbins, ybins, zbins= self.choose_bins(bin_style) + group.attrs["x-axis-%s" % self.x_bin_field] = xbins + group.attrs["y-axis-%s" % self.y_bin_field] = ybins + group.attrs["z-axis-%s" % self.z_bin_field] = zbins + + for field in fields: + dset = group.create_dataset("%s" % field, data=self._data[field][:-1,:-1,:-1]) + fid.close() + + + def _get_bin_fields(self): + return [self.x_bin_field, self.y_bin_field, self.z_bin_field] + + def store_profile(self, name, force=False): + """ + By identifying the profile with a fixed, user-input *name* we can + store it in the serialized data section of the hierarchy file. *force* + governs whether or not an existing profile with that name will be + overwritten. + """ + # First we get our data in order + order = [] + set_attr = {'x_bin_field':self.x_bin_field, + 'y_bin_field':self.y_bin_field, + 'z_bin_field':self.z_bin_field, + 'x_bin_values':self[self.x_bin_field], + 'y_bin_values':self[self.y_bin_field], + 'z_bin_values':self[self.z_bin_field], + '_x_log':self._x_log, + '_y_log':self._y_log, + '_z_log':self._z_log, + 'shape': (self[self.x_bin_field].size, + self[self.y_bin_field].size, + self[self.z_bin_field].size), + 'field_order':order } + values = [] + for field in self._data: + if field in set_attr.values(): continue + order.append(field) + values.append(self[field].ravel()) + values = na.array(values).transpose() + self._data_source.hierarchy.save_data(values, "/Profiles", name, + set_attr, force=force) + +class StoredBinnedProfile3D(BinnedProfile3D): + def __init__(self, pf, name): + """ + Given a *pf* parameterfile and the *name* of a stored profile, retrieve + it into a read-only data structure. + """ + self._data = {} + prof_arr = pf.h.get_data("/Profiles", name) + if prof_arr is None: raise KeyError("No such array") + for ax in 'xyz': + for base in ['%s_bin_field', '_%s_log']: + setattr(self, base % ax, prof_arr.getAttr(base % ax)) + for ax in 'xyz': + fn = getattr(self, '%s_bin_field' % ax) + self._data[fn] = prof_arr.getAttr('%s_bin_values' % ax) + shape = prof_arr.getAttr('shape') + for fn, fd in zip(prof_arr.getAttr('field_order'), + prof_arr.read().transpose()): + self._data[fn] = fd.reshape(shape) + + def add_fields(self, *args, **kwargs): + raise RuntimeError("Sorry, you can't add to a stored profile.") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('data_objects',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/static_output.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/static_output.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,171 @@ +""" +Generalized Enzo output objects, both static and time-series. + +Presumably at some point EnzoRun will be absorbed into here. +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 Matthew Turk, J. S. Oishi. 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 . +""" + +import string, re, gc, time, os, os.path, weakref + +from yt.funcs import * + +from yt.config import ytcfg +from yt.utilities.parameter_file_storage import \ + ParameterFileStore, \ + NoParameterShelf, \ + output_type_registry + +# We want to support the movie format in the future. +# When such a thing comes to pass, I'll move all the stuff that is contant up +# to here, and then have it instantiate EnzoStaticOutputs as appropriate. + +_cached_pfs = weakref.WeakValueDictionary() +_pf_store = ParameterFileStore() + +class StaticOutput(object): + class __metaclass__(type): + def __init__(cls, name, b, d): + type.__init__(cls, name, b, d) + output_type_registry[name]=cls + mylog.debug("Registering: %s as %s", name, cls) + + def __new__(cls, filename=None, *args, **kwargs): + if not isinstance(filename, types.StringTypes): + obj = object.__new__(cls) + obj.__init__(filename, *args, **kwargs) + return obj + apath = os.path.abspath(filename) + if not os.path.exists(apath): raise IOError(filename) + if apath not in _cached_pfs: + obj = object.__new__(cls) + obj.__init__(filename, *args, **kwargs) + _cached_pfs[apath] = obj + if ytcfg.getboolean('lagos','serialize'): + try: + _pf_store.check_pf(obj) + except NoParameterShelf: + pass + return _cached_pfs[apath] + + def __init__(self, filename, data_style=None): + """ + Base class for generating new output types. Principally consists of + a *filename* and a *data_style* which will be passed on to children. + """ + self.data_style = data_style + self.parameter_filename = str(filename) + self.basename = os.path.basename(filename) + self.directory = os.path.expanduser(os.path.dirname(filename)) + self.fullpath = os.path.abspath(self.directory) + self._instantiated = time.time() + if len(self.directory) == 0: + self.directory = "." + self.conversion_factors = {} + self.parameters = {} + self._parse_parameter_file() + self._set_units() + # These can be taken out if you so desire + + def __reduce__(self): + args = (self._hash(),) + return (_reconstruct_pf, args) + + def __repr__(self): + return self.basename + + def _hash(self): + s = "%s;%s;%s" % (self.basename, + self.current_time, self.unique_identifier) + try: + import hashlib + return hashlib.md5(s).hexdigest() + except ImportError: + return s.replace(";", "*") + + @classmethod + def _is_valid(cls, *args, **kwargs): + return False + + def __getitem__(self, key): + """ + Returns _units, parameters, or _conversion_factors in that order + """ + for d in [self.units, self.time_units, self.parameters, \ + self.conversion_factors]: + if key in d: return d[key] + raise KeyError(key) + + def keys(self): + """ + Returns a list of possible keys, from _units, parameters and + _conversion_factors + """ + return self.units.keys() \ + + self.time_units.keys() \ + + self.parameters.keys() \ + + self.conversion_factors.keys() + + def __iter__(self): + for ll in [self.units, self.time_units, + self.parameters, self.conversion_factors]: + for i in ll.keys(): yield i + + def get_smallest_appropriate_unit(self, v): + max_nu = 1e30 + good_u = None + for unit in ['mpc','kpc','pc','au','rsun','cm']: + vv = v*self[unit] + if vv < max_nu and vv > 1.0: + good_u = unit + max_nu = v*self[unit] + return good_u + + def has_key(self, key): + """ + Returns true or false + """ + return key in self.units or \ + key in self.time_units or \ + key in self.parameters or \ + key in self.conversion_factors + + def _get_hierarchy(self): + if self.__hierarchy == None: + if self._hierarchy_class == None: + raise RuntimeError("You should not instantiate StaticOutput.") + self.__hierarchy = self._hierarchy_class(self, data_style=self.data_style) + return self.__hierarchy + + def _set_hierarchy(self, newh): + if self.__hierarchy != None: + mylog.warning("Overriding hierarchy attribute! This is probably unwise!") + self.__hierarchy = newh + + __hierarchy = None + hierarchy = property(_get_hierarchy, _set_hierarchy) + h = property(_get_hierarchy, _set_hierarchy) + +def _reconstruct_pf(*args, **kwargs): + pfs = ParameterFileStore() + pf = pfs.get_pf_hash(*args) + return pf + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/time_series.py --- a/yt/data_objects/time_series.py Mon Aug 30 10:02:07 2010 -0700 +++ b/yt/data_objects/time_series.py Mon Aug 30 10:48:15 2010 -0700 @@ -1,4 +1,28 @@ -from yt.lagos import * +""" +Time series analysis functions. + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +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 . +""" + import inspect, functools class TimeSeriesData(object): diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/data_objects/universal_fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/data_objects/universal_fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,822 @@ +""" +The basic field info container resides here. These classes, code specific and +universal, are the means by which we access fields across YT, both derived and +native. + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 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 . +""" + +import types +import numpy as na +import inspect +import copy + +from math import pi + +from yt.funcs import * + +from yt.utilities.amr_utils import CICDeposit_3 +from field_info_container import \ + add_field, \ + ValidateDataField, \ + ValidateGridType, \ + ValidateParameter, \ + ValidateSpatial, \ + NeedsGridType, \ + NeedsOriginalGrid, \ + NeedsDataField, \ + NeedsProperty, \ + NeedsParameter + +mh = 1.67e-24 # g +me = 9.11e-28 # g +sigma_thompson = 6.65e-25 # cm^2 +clight = 3.0e10 # cm/s +kboltz = 1.38e-16 # erg K^-1 +G = 6.67e-8 # cm^3 g^-1 s^-2 + + + +# Note that, despite my newfound efforts to comply with PEP-8, +# I violate it here in order to keep the name/func_name relationship + +def _dx(field, data): + return data.dds[0] + return na.ones(data.ActiveDimensions, dtype='float64') * data.dds[0] +add_field('dx', function=_dx, display_field=False, + validators=[ValidateSpatial(0)]) + +def _dy(field, data): + return data.dds[1] + return na.ones(data.ActiveDimensions, dtype='float64') * data.dds[1] +add_field('dy', function=_dy, display_field=False, + validators=[ValidateSpatial(0)]) + +def _dz(field, data): + return data.dds[2] + return na.ones(data.ActiveDimensions, dtype='float64') * data.dds[2] +add_field('dz', function=_dz, + display_field=False, validators=[ValidateSpatial(0)]) + +def _coordX(field, data): + dim = data.ActiveDimensions[0] + return (na.ones(data.ActiveDimensions, dtype='float64') + * na.arange(data.ActiveDimensions[0])[:,None,None] + +0.5) * data['dx'] + data.LeftEdge[0] +add_field('x', function=_coordX, display_field=False, + validators=[ValidateSpatial(0)]) + +def _coordY(field, data): + dim = data.ActiveDimensions[1] + return (na.ones(data.ActiveDimensions, dtype='float64') + * na.arange(data.ActiveDimensions[1])[None,:,None] + +0.5) * data['dy'] + data.LeftEdge[1] +add_field('y', function=_coordY, display_field=False, + validators=[ValidateSpatial(0)]) + +def _coordZ(field, data): + dim = data.ActiveDimensions[2] + return (na.ones(data.ActiveDimensions, dtype='float64') + * na.arange(data.ActiveDimensions[2])[None,None,:] + +0.5) * data['dz'] + data.LeftEdge[2] +add_field('z', function=_coordZ, display_field=False, + validators=[ValidateSpatial(0)]) + +def _GridLevel(field, data): + return na.ones(data.ActiveDimensions)*(data.Level) +add_field("GridLevel", function=_GridLevel, + validators=[ValidateGridType(), + ValidateSpatial(0)]) + +def _GridIndices(field, data): + return na.ones(data["Ones"].shape)*(data.id-data._id_offset) +add_field("GridIndices", function=_GridIndices, + validators=[ValidateGridType(), + ValidateSpatial(0)], take_log=False) + +def _OnesOverDx(field, data): + return na.ones(data["Ones"].shape, + dtype=data["Density"].dtype)/data['dx'] +add_field("OnesOverDx", function=_OnesOverDx, + display_field=False) + +def _Ones(field, data): + return na.ones(data.ActiveDimensions, dtype='float64') +add_field("Ones", function=_Ones, + validators=[ValidateSpatial(0)], + projection_conversion="unitary", + display_field = False) +add_field("CellsPerBin", function=_Ones, validators=[ValidateSpatial(0)], + display_field = False) + +def _SoundSpeed(field, data): + if data.pf["EOSType"] == 1: + return na.ones(data["Density"].shape, dtype='float64') * \ + data.pf["EOSSoundSpeed"] + return ( data.pf["Gamma"]*data["Pressure"] / \ + data["Density"] )**(1.0/2.0) +add_field("SoundSpeed", function=_SoundSpeed, + units=r"\rm{cm}/\rm{s}") + +def particle_func(p_field, dtype='float64'): + def _Particles(field, data): + io = data.hierarchy.io + if not data.NumberOfParticles > 0: + return na.array([], dtype=dtype) + try: + return io._read_data_set(data, p_field).astype(dtype) + except io._read_exception: + pass + # This is bad. But it's the best idea I have right now. + return data._read_data(p_field.replace("_"," ")).astype(dtype) + return _Particles +for pf in ["type", "mass"] + \ + ["position_%s" % ax for ax in 'xyz']: + pfunc = particle_func("particle_%s" % (pf)) + add_field("particle_%s" % pf, function=pfunc, + validators = [ValidateSpatial(0)], + particle_type=True) + +def _convRetainInt(data): + return 1 +add_field("particle_index", function=particle_func("particle_index", "int64"), + validators = [ValidateSpatial(0)], particle_type=True, + convert_function=_convRetainInt) + +def _get_vel_convert(ax): + def _convert_p_vel(data): + return data.convert("%s-velocity" % ax) + return _convert_p_vel +for ax in 'xyz': + pf = "particle_velocity_%s" % ax + pfunc = particle_func(pf) + cfunc = _get_vel_convert(ax) + add_field(pf, function=pfunc, convert_function=cfunc, + validators = [ValidateSpatial(0)], + particle_type=True) + +for pf in ["creation_time", "dynamical_time", "metallicity_fraction"]: + pfunc = particle_func(pf) + add_field(pf, function=pfunc, + validators = [ValidateSpatial(0), + ValidateDataField(pf)], + particle_type=True) +add_field("particle_mass", function=particle_func("particle_mass"), + validators=[ValidateSpatial(0)], particle_type=True) + +def _ParticleAge(field, data): + current_time = data.pf.current_time + return (current_time - data["creation_time"]) +def _convertParticleAge(data): + return data.convert("years") +add_field("ParticleAge", + function=_ParticleAge, + validators=[ValidateSpatial(0), ValidateDataField("creation_time")], + particle_type=True, convert_function=_convertParticleAge) + +def _ParticleMass(field, data): + particles = data["particle_mass"].astype('float64') * \ + just_one(data["CellVolumeCode"].ravel()) + # Note that we mandate grid-type here, so this is okay + return particles + +def _convertParticleMass(data): + return data.convert("Density")*(data.convert("cm")**3.0) +def _IOLevelParticleMass(grid): + dd = dict(particle_mass = na.ones(1), CellVolumeCode=grid["CellVolumeCode"]) + cf = (_ParticleMass(None, dd) * _convertParticleMass(grid))[0] + return cf +def _convertParticleMassMsun(data): + return data.convert("Density")*((data.convert("cm")**3.0)/1.989e33) +def _IOLevelParticleMassMsun(grid): + dd = dict(particle_mass = na.ones(1), CellVolumeCode=grid["CellVolumeCode"]) + cf = (_ParticleMass(None, dd) * _convertParticleMassMsun(grid))[0] + return cf +add_field("ParticleMass", + function=_ParticleMass, validators=[ValidateSpatial(0)], + particle_type=True, convert_function=_convertParticleMass, + particle_convert_function=_IOLevelParticleMass) +add_field("ParticleMassMsun", + function=_ParticleMass, validators=[ValidateSpatial(0)], + particle_type=True, convert_function=_convertParticleMassMsun, + particle_convert_function=_IOLevelParticleMassMsun) + +def _RadialMachNumber(field, data): + """M{|v|/t_sound}""" + return na.abs(data["RadialVelocity"]) / data["SoundSpeed"] +add_field("RadialMachNumber", function=_RadialMachNumber) + +def _MachNumber(field, data): + """M{|v|/t_sound}""" + return data["VelocityMagnitude"] / data["SoundSpeed"] +add_field("MachNumber", function=_MachNumber) + +def _CourantTimeStep(field, data): + t1 = data['dx'] / ( + data["SoundSpeed"] + \ + abs(data["x-velocity"])) + t2 = data['dy'] / ( + data["SoundSpeed"] + \ + abs(data["y-velocity"])) + t3 = data['dz'] / ( + data["SoundSpeed"] + \ + abs(data["z-velocity"])) + return na.minimum(na.minimum(t1,t2),t3) +def _convertCourantTimeStep(data): + # SoundSpeed and z-velocity are in cm/s, dx is in code + return data.convert("cm") +add_field("CourantTimeStep", function=_CourantTimeStep, + convert_function=_convertCourantTimeStep, + units=r"$\rm{s}$") + +def _ParticleVelocityMagnitude(field, data): + """M{|v|}""" + bulk_velocity = data.get_field_parameter("bulk_velocity") + if bulk_velocity == None: + bulk_velocity = na.zeros(3) + return ( (data["particle_velocity_x"]-bulk_velocity[0])**2.0 + \ + (data["particle_velocity_y"]-bulk_velocity[1])**2.0 + \ + (data["particle_velocity_z"]-bulk_velocity[2])**2.0 )**(1.0/2.0) +add_field("ParticleVelocityMagnitude", function=_ParticleVelocityMagnitude, + particle_type=True, + take_log=False, units=r"\rm{cm}/\rm{s}") + +def _VelocityMagnitude(field, data): + """M{|v|}""" + bulk_velocity = data.get_field_parameter("bulk_velocity") + if bulk_velocity == None: + bulk_velocity = na.zeros(3) + return ( (data["x-velocity"]-bulk_velocity[0])**2.0 + \ + (data["y-velocity"]-bulk_velocity[1])**2.0 + \ + (data["z-velocity"]-bulk_velocity[2])**2.0 )**(1.0/2.0) +add_field("VelocityMagnitude", function=_VelocityMagnitude, + take_log=False, units=r"\rm{cm}/\rm{s}") + +def _TangentialOverVelocityMagnitude(field, data): + return na.abs(data["TangentialVelocity"])/na.abs(data["VelocityMagnitude"]) +add_field("TangentialOverVelocityMagnitude", + function=_TangentialOverVelocityMagnitude, + take_log=False) + +def _TangentialVelocity(field, data): + return na.sqrt(data["VelocityMagnitude"]**2.0 + - data["RadialVelocity"]**2.0) +add_field("TangentialVelocity", + function=_TangentialVelocity, + take_log=False, units=r"\rm{cm}/\rm{s}") + +def _Pressure(field, data): + """M{(Gamma-1.0)*rho*E}""" + return (data.pf["Gamma"] - 1.0) * \ + data["Density"] * data["ThermalEnergy"] +add_field("Pressure", function=_Pressure, units=r"\rm{dyne}/\rm{cm}^{2}") + +def _Entropy(field, data): + return (kboltz/mh) * data["Temperature"] / \ + (data["MeanMolecularWeight"] * data["Density"]**(2./3.)) +add_field("Entropy", units=r"\rm{ergs}\/\rm{cm}^{2}", + function=_Entropy) + +def _Height(field, data): + # We take the dot product of the radius vector with the height-vector + center = data.get_field_parameter("center") + r_vec = na.array([data["x"] - center[0], + data["y"] - center[1], + data["z"] - center[2]]) + h_vec = na.array(data.get_field_parameter("height_vector")) + h_vec = h_vec / na.sqrt(h_vec[0]**2.0+ + h_vec[1]**2.0+ + h_vec[2]**2.0) + height = r_vec[0,:] * h_vec[0] \ + + r_vec[1,:] * h_vec[1] \ + + r_vec[2,:] * h_vec[2] + return na.abs(height) +def _convertHeight(data): + return data.convert("cm") +def _convertHeightAU(data): + return data.convert("au") +add_field("Height", function=_Height, + convert_function=_convertHeight, + validators=[ValidateParameter("height_vector")], + units=r"cm", display_field=False) +add_field("HeightAU", function=_Height, + convert_function=_convertHeightAU, + validators=[ValidateParameter("height_vector")], + units=r"AU", display_field=False) + +def _DiskAngle(field, data): + # We make both r_vec and h_vec into unit vectors + center = data.get_field_parameter("center") + r_vec = na.array([data["x"] - center[0], + data["y"] - center[1], + data["z"] - center[2]]) + r_vec = r_vec/na.sqrt((r_vec**2.0).sum(axis=0)) + h_vec = na.array(data.get_field_parameter("height_vector")) + dp = r_vec[0,:] * h_vec[0] \ + + r_vec[1,:] * h_vec[1] \ + + r_vec[2,:] * h_vec[2] + return na.arccos(dp) +add_field("DiskAngle", function=_DiskAngle, + take_log=False, + validators=[ValidateParameter("height_vector"), + ValidateParameter("center")], + display_field=False) + +def _DynamicalTime(field, data): + """ + The formulation for the dynamical time is: + M{sqrt(3pi/(16*G*rho))} or M{sqrt(3pi/(16G))*rho^-(1/2)} + Note that we return in our natural units already + """ + return (3.0*pi/(16*G*data["Density"]))**(1./2.) +add_field("DynamicalTime", function=_DynamicalTime, + units=r"\rm{s}") + +def JeansMassMsun(field,data): + return (MJ_constant * + ((data["Temperature"]/data["MeanMolecularWeight"])**(1.5)) * + (data["Density"]**(-0.5))) +add_field("JeansMassMsun",function=JeansMassMsun,units=r"\rm{Msun}") + +def _CellMass(field, data): + return data["Density"] * data["CellVolume"] +def _convertCellMassMsun(data): + return 5.027854e-34 # g^-1 +add_field("CellMass", function=_CellMass, units=r"\rm{g}") +add_field("CellMassMsun", units=r"M_{\odot}", + function=_CellMass, + convert_function=_convertCellMassMsun) + +def _CellMassCode(field, data): + return data["Density"] * data["CellVolumeCode"] +def _convertCellMassCode(data): + return 1.0/data.convert("Density") +add_field("CellMassCode", + function=_CellMassCode, + convert_function=_convertCellMassCode) + +def _TotalMass(field,data): + return (data["Density"]+data["Dark_Matter_Density"]) * data["CellVolume"] +add_field("TotalMassMsun", units=r"M_{\odot}", + function=_TotalMass, + convert_function=_convertCellMassMsun) + +def _StarMass(field,data): + return data["star_density"] * data["CellVolume"] +add_field("StarMassMsun", units=r"M_{\odot}", + function=_StarMass, + convert_function=_convertCellMassMsun) + +def _Matter_Density(field,data): + return (data['Density'] + data['Dark_Matter_Density']) +add_field("Matter_Density",function=_Matter_Density,units=r"\rm{g}/\rm{cm^3}") + +def _CellVolume(field, data): + if data['dx'].size == 1: + try: + return data['dx']*data['dy']*data['dx']*\ + na.ones(data.ActiveDimensions, dtype='float64') + except AttributeError: + return data['dx']*data['dy']*data['dx'] + return data["dx"]*data["dy"]*data["dz"] +def _ConvertCellVolumeMpc(data): + return data.convert("mpc")**3.0 +def _ConvertCellVolumeCGS(data): + return data.convert("cm")**3.0 +add_field("CellVolumeCode", units=r"\rm{BoxVolume}^3", + function=_CellVolume) +add_field("CellVolumeMpc", units=r"\rm{Mpc}^3", + function=_CellVolume, + convert_function=_ConvertCellVolumeMpc) +add_field("CellVolume", units=r"\rm{cm}^3", + function=_CellVolume, + convert_function=_ConvertCellVolumeCGS) + +def _XRayEmissivity(field, data): + return ((data["Density"].astype('float64')**2.0) \ + *data["Temperature"]**0.5) +def _convertXRayEmissivity(data): + return 2.168e60 +add_field("XRayEmissivity", function=_XRayEmissivity, + convert_function=_convertXRayEmissivity, + projection_conversion="1") + +def _SZKinetic(field, data): + vel_axis = data.get_field_parameter('axis') + if vel_axis > 2: + raise NeedsParameter(['axis']) + vel = data["%s-velocity" % ({0:'x',1:'y',2:'z'}[vel_axis])] + return (vel*data["Density"]) +def _convertSZKinetic(data): + return 0.88*((sigma_thompson/mh)/clight) +add_field("SZKinetic", function=_SZKinetic, + convert_function=_convertSZKinetic, + validators=[ValidateParameter('axis')]) + +def _SZY(field, data): + return (data["Density"]*data["Temperature"]) +def _convertSZY(data): + conv = (0.88/mh) * (kboltz)/(me * clight*clight) * sigma_thompson + return conv +add_field("SZY", function=_SZY, convert_function=_convertSZY) + +def _AveragedDensity(field, data): + nx, ny, nz = data["Density"].shape + new_field = na.zeros((nx-2,ny-2,nz-2), dtype='float64') + weight_field = na.zeros((nx-2,ny-2,nz-2), dtype='float64') + i_i, j_i, k_i = na.mgrid[0:3,0:3,0:3] + for i,j,k in zip(i_i.ravel(),j_i.ravel(),k_i.ravel()): + sl = [slice(i,nx-(2-i)),slice(j,ny-(2-j)),slice(k,nz-(2-k))] + new_field += data["Density"][sl] * data["CellMass"][sl] + weight_field += data["CellMass"][sl] + # Now some fancy footwork + new_field2 = na.zeros((nx,ny,nz)) + new_field2[1:-1,1:-1,1:-1] = new_field/weight_field + return new_field2 +add_field("AveragedDensity", + function=_AveragedDensity, + validators=[ValidateSpatial(1)]) + +def _DivV(field, data): + # We need to set up stencils + if data.pf["HydroMethod"] == 2: + sl_left = slice(None,-2,None) + sl_right = slice(1,-1,None) + div_fac = 1.0 + else: + sl_left = slice(None,-2,None) + sl_right = slice(2,None,None) + div_fac = 2.0 + ds = div_fac * data['dx'].flat[0] + f = data["x-velocity"][sl_right,1:-1,1:-1]/ds + f -= data["x-velocity"][sl_left ,1:-1,1:-1]/ds + ds = div_fac * data['dy'].flat[0] + f += data["y-velocity"][1:-1,sl_right,1:-1]/ds + f -= data["y-velocity"][1:-1,sl_left ,1:-1]/ds + ds = div_fac * data['dz'].flat[0] + f += data["z-velocity"][1:-1,1:-1,sl_right]/ds + f -= data["z-velocity"][1:-1,1:-1,sl_left ]/ds + new_field = na.zeros(data["x-velocity"].shape, dtype='float64') + new_field[1:-1,1:-1,1:-1] = f + return new_field +def _convertDivV(data): + return data.convert("cm")**-1.0 +add_field("DivV", function=_DivV, + validators=[ValidateSpatial(1, + ["x-velocity","y-velocity","z-velocity"])], + units=r"\rm{s}^{-1}", take_log=False, + convert_function=_convertDivV) + +def _AbsDivV(field, data): + return na.abs(data['DivV']) +add_field("AbsDivV", function=_AbsDivV, + units=r"\rm{s}^{-1}") + +def _Contours(field, data): + return na.ones(data["Density"].shape)*-1 +add_field("Contours", validators=[ValidateSpatial(0)], take_log=False, + display_field=False, function=_Contours) +add_field("tempContours", function=_Contours, + validators=[ValidateSpatial(0), ValidateGridType()], + take_log=False, display_field=False) + +def obtain_velocities(data): + if data.has_field_parameter("bulk_velocity"): + bv = data.get_field_parameter("bulk_velocity") + else: bv = na.zeros(3, dtype='float64') + xv = data["x-velocity"] - bv[0] + yv = data["y-velocity"] - bv[1] + zv = data["z-velocity"] - bv[2] + return xv, yv, zv + +def obtain_rvec(data): + center = data.get_field_parameter('center') + coords = na.array([data['x'],data['y'],data['z']], dtype='float64') + new_shape = tuple([3] + [1]*(len(coords.shape)-1)) + r_vec = coords - na.reshape(center,new_shape) + return r_vec # axis 0 is the x,y,z + +def _SpecificAngularMomentum(field, data): + """ + Calculate the angular velocity. Returns a vector for each cell. + """ + r_vec = obtain_rvec(data) + xv, yv, zv = obtain_velocities(data) + v_vec = na.array([xv,yv,zv], dtype='float64') + return na.cross(r_vec, v_vec, axis=0) +def _convertSpecificAngularMomentum(data): + return data.convert("cm") +add_field("SpecificAngularMomentum", + function=_SpecificAngularMomentum, + convert_function=_convertSpecificAngularMomentum, vector_field=True, + units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter('center')]) +def _convertSpecificAngularMomentumKMSMPC(data): + return data.convert("mpc")/1e5 + +def _SpecificAngularMomentumX(field, data): + xv, yv, zv = obtain_velocities(data) + rv = obtain_rvec(data) + return yv*rv[2,:] - zv*rv[1,:] +def _SpecificAngularMomentumY(field, data): + xv, yv, zv = obtain_velocities(data) + rv = obtain_rvec(data) + return -(xv*rv[2,:] - zv*rv[0,:]) +def _SpecificAngularMomentumZ(field, data): + xv, yv, zv = obtain_velocities(data) + rv = obtain_rvec(data) + return xv*rv[1,:] - yv*rv[0,:] +for ax in 'XYZ': + n = "SpecificAngularMomentum%s" % ax + add_field(n, function=eval("_%s" % n), + convert_function=_convertSpecificAngularMomentum, + units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter("center")]) + +add_field("SpecificAngularMomentumKMSMPC", + function=_SpecificAngularMomentum, + convert_function=_convertSpecificAngularMomentumKMSMPC, vector_field=True, + units=r"\rm{km}\rm{Mpc}/\rm{s}", validators=[ValidateParameter('center')]) +def _AngularMomentum(field, data): + return data["CellMass"] * data["SpecificAngularMomentum"] +add_field("AngularMomentum", function=_AngularMomentum, + units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, + validators=[ValidateParameter('center')]) +def _AngularMomentumMSUNKMSMPC(field, data): + return data["CellMassMsun"] * data["SpecificAngularMomentumKMSMPC"] +add_field("AngularMomentumMSUNKMSMPC", function=_AngularMomentum, + units=r"M_{\odot}\rm{km}\rm{Mpc}/\rm{s}", vector_field=True, + validators=[ValidateParameter('center')]) + +def _AngularMomentumX(field, data): + return data["CellMass"] * data["SpecificAngularMomentumX"] +add_field("AngularMomentumX", function=_AngularMomentumX, + units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, + validators=[ValidateParameter('center')]) +def _AngularMomentumY(field, data): + return data["CellMass"] * data["SpecificAngularMomentumY"] +add_field("AngularMomentumY", function=_AngularMomentumY, + units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, + validators=[ValidateParameter('center')]) +def _AngularMomentumZ(field, data): + return data["CellMass"] * data["SpecificAngularMomentumZ"] +add_field("AngularMomentumZ", function=_AngularMomentumZ, + units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, + validators=[ValidateParameter('center')]) + +def _ParticleSpecificAngularMomentum(field, data): + """ + Calculate the angular of a particle velocity. Returns a vector for each + particle. + """ + if data.has_field_parameter("bulk_velocity"): + bv = data.get_field_parameter("bulk_velocity") + else: bv = na.zeros(3, dtype='float64') + xv = data["particle_velocity_x"] - bv[0] + yv = data["particle_velocity_y"] - bv[1] + zv = data["particle_velocity_z"] - bv[2] + center = data.get_field_parameter('center') + coords = na.array([data['particle_position_x'], + data['particle_position_y'], + data['particle_position_z']], dtype='float64') + new_shape = tuple([3] + [1]*(len(coords.shape)-1)) + r_vec = coords - na.reshape(center,new_shape) + v_vec = na.array([xv,yv,zv], dtype='float64') + return na.cross(r_vec, v_vec, axis=0) +add_field("ParticleSpecificAngularMomentum", + function=_ParticleSpecificAngularMomentum, particle_type=True, + convert_function=_convertSpecificAngularMomentum, vector_field=True, + units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter('center')]) +def _convertSpecificAngularMomentumKMSMPC(data): + return data.convert("mpc")/1e5 +add_field("ParticleSpecificAngularMomentumKMSMPC", + function=_ParticleSpecificAngularMomentum, particle_type=True, + convert_function=_convertSpecificAngularMomentumKMSMPC, vector_field=True, + units=r"\rm{km}\rm{Mpc}/\rm{s}", validators=[ValidateParameter('center')]) +def _ParticleAngularMomentum(field, data): + return data["ParticleMass"] * data["ParticleSpecificAngularMomentum"] +add_field("ParticleAngularMomentum", + function=_ParticleAngularMomentum, units=r"\rm{g}\/\rm{cm}^2/\rm{s}", + particle_type=True, validators=[ValidateParameter('center')]) +def _ParticleAngularMomentumMSUNKMSMPC(field, data): + return data["ParticleMass"] * data["ParticleSpecificAngularMomentumKMSMPC"] +add_field("ParticleAngularMomentumMSUNKMSMPC", + function=_ParticleAngularMomentumMSUNKMSMPC, + units=r"M_{\odot}\rm{km}\rm{Mpc}/\rm{s}", + particle_type=True, validators=[ValidateParameter('center')]) + +def _ParticleRadius(field, data): + center = data.get_field_parameter("center") + DW = data.pf.domain_right_edge - data.pf.domain_left_edge + radius = na.zeros(data["particle_position_x"].shape, dtype='float64') + for i, ax in enumerate('xyz'): + r = na.abs(data["particle_position_%s" % ax] - center[i]) + radius += na.minimum(r, na.abs(DW[i]-r))**2.0 + na.sqrt(radius, radius) + return radius +def _Radius(field, data): + center = data.get_field_parameter("center") + DW = data.pf.domain_right_edge - data.pf.domain_left_edge + radius = na.zeros(data["x"].shape, dtype='float64') + for i, ax in enumerate('xyz'): + r = na.abs(data[ax] - center[i]) + radius += na.minimum(r, na.abs(DW[i]-r))**2.0 + na.sqrt(radius, radius) + return radius +def _ConvertRadiusCGS(data): + return data.convert("cm") +add_field("ParticleRadius", function=_ParticleRadius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiusCGS, units=r"\rm{cm}", + particle_type = True, + display_name = "Particle Radius") +add_field("Radius", function=_Radius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiusCGS, units=r"\rm{cm}") + +def _ConvertRadiusMpc(data): + return data.convert("mpc") +add_field("RadiusMpc", function=_Radius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiusMpc, units=r"\rm{Mpc}", + display_name = "Radius") +add_field("ParticleRadiusMpc", function=_ParticleRadius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiusMpc, units=r"\rm{Mpc}", + particle_type=True, + display_name = "Particle Radius") + +def _ConvertRadiuskpc(data): + return data.convert("kpc") +add_field("ParticleRadiuskpc", function=_ParticleRadius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}", + particle_type=True, + display_name = "Particle Radius") +add_field("Radiuskpc", function=_Radius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}", + display_name = "Radius") + +def _ConvertRadiuskpch(data): + return data.convert("kpch") +add_field("ParticleRadiuskpch", function=_ParticleRadius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}/\rm{h}", + particle_type=True, + display_name = "Particle Radius") +add_field("Radiuskpch", function=_Radius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}/\rm{h}", + display_name = "Radius") + +def _ConvertRadiuspc(data): + return data.convert("pc") +add_field("ParticleRadiuspc", function=_ParticleRadius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiuspc, units=r"\rm{pc}", + particle_type=True, + display_name = "Particle Radius") +add_field("Radiuspc", function=_Radius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiuspc, units=r"\rm{pc}", + display_name="Radius") + +def _ConvertRadiusAU(data): + return data.convert("au") +add_field("ParticleRadiusAU", function=_ParticleRadius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiusAU, units=r"\rm{AU}", + particle_type=True, + display_name = "Particle Radius") +add_field("RadiusAU", function=_Radius, + validators=[ValidateParameter("center")], + convert_function = _ConvertRadiusAU, units=r"\rm{AU}", + display_name = "Radius") + +add_field("ParticleRadiusCode", function=_ParticleRadius, + validators=[ValidateParameter("center")], + particle_type=True, + display_name = "Particle Radius (code)") +add_field("RadiusCode", function=_Radius, + validators=[ValidateParameter("center")], + display_name = "Radius (code)") + +def _RadialVelocity(field, data): + center = data.get_field_parameter("center") + bulk_velocity = data.get_field_parameter("bulk_velocity") + if bulk_velocity == None: + bulk_velocity = na.zeros(3) + new_field = ( (data['x']-center[0])*(data["x-velocity"]-bulk_velocity[0]) + + (data['y']-center[1])*(data["y-velocity"]-bulk_velocity[1]) + + (data['z']-center[2])*(data["z-velocity"]-bulk_velocity[2]) + )/data["RadiusCode"] + if na.any(na.isnan(new_field)): # to fix center = point + new_field[na.isnan(new_field)] = 0.0 + return new_field +def _RadialVelocityABS(field, data): + return na.abs(_RadialVelocity(field, data)) +def _ConvertRadialVelocityKMS(data): + return 1e-5 +add_field("RadialVelocity", function=_RadialVelocity, + units=r"\rm{cm}/\rm{s}", + validators=[ValidateParameter("center")]) +add_field("RadialVelocityABS", function=_RadialVelocityABS, + units=r"\rm{cm}/\rm{s}", + validators=[ValidateParameter("center")]) +add_field("RadialVelocityKMS", function=_RadialVelocity, + convert_function=_ConvertRadialVelocityKMS, units=r"\rm{km}/\rm{s}", + validators=[ValidateParameter("center")]) +add_field("RadialVelocityKMSABS", function=_RadialVelocityABS, + convert_function=_ConvertRadialVelocityKMS, units=r"\rm{km}/\rm{s}", + validators=[ValidateParameter("center")]) + +def _CuttingPlaneVelocityX(field, data): + x_vec, y_vec, z_vec = [data.get_field_parameter("cp_%s_vec" % (ax)) + for ax in 'xyz'] + bulk_velocity = data.get_field_parameter("bulk_velocity") + if bulk_velocity == None: + bulk_velocity = na.zeros(3) + v_vec = na.array([data["%s-velocity" % ax] for ax in 'xyz']) \ + - bulk_velocity[...,na.newaxis] + return na.dot(x_vec, v_vec) +add_field("CuttingPlaneVelocityX", + function=_CuttingPlaneVelocityX, + validators=[ValidateParameter("cp_%s_vec" % ax) + for ax in 'xyz'], units=r"\rm{km}/\rm{s}") +def _CuttingPlaneVelocityY(field, data): + x_vec, y_vec, z_vec = [data.get_field_parameter("cp_%s_vec" % (ax)) + for ax in 'xyz'] + bulk_velocity = data.get_field_parameter("bulk_velocity") + if bulk_velocity == None: + bulk_velocity = na.zeros(3) + v_vec = na.array([data["%s-velocity" % ax] for ax in 'xyz']) \ + - bulk_velocity[...,na.newaxis] + return na.dot(y_vec, v_vec) +add_field("CuttingPlaneVelocityY", + function=_CuttingPlaneVelocityY, + validators=[ValidateParameter("cp_%s_vec" % ax) + for ax in 'xyz'], units=r"\rm{km}/\rm{s}") + +def _MeanMolecularWeight(field,data): + return (data["Density"] / (mh *data["NumberDensity"])) +add_field("MeanMolecularWeight",function=_MeanMolecularWeight,units=r"") + +def _JeansMassMsun(field,data): + MJ_constant = (((5*kboltz)/(G*mh))**(1.5)) * \ + (3/(4*3.1415926535897931))**(0.5) / 1.989e33 + + return (MJ_constant * + ((data["Temperature"]/data["MeanMolecularWeight"])**(1.5)) * + (data["Density"]**(-0.5))) +add_field("JeansMassMsun",function=_JeansMassMsun, + units=r"\rm{M_{\odot}}") + +def _convertDensity(data): + return data.convert("Density") +def _pdensity(field, data): + blank = na.zeros(data.ActiveDimensions, dtype='float32') + if data.NumberOfParticles == 0: return blank + CICDeposit_3(data["particle_position_x"].astype(na.float64), + data["particle_position_y"].astype(na.float64), + data["particle_position_z"].astype(na.float64), + data["particle_mass"].astype(na.float32), + na.int64(data.NumberOfParticles), + blank, na.array(data.LeftEdge).astype(na.float64), + na.array(data.ActiveDimensions).astype(na.int32), + na.float64(data['dx'])) + return blank +add_field("particle_density", function=_pdensity, + validators=[ValidateSpatial(0)], convert_function=_convertDensity, + display_name=r"\mathrm{Particle}\/\mathrm{Density})") + +def _MagneticEnergy(field,data): + """WARNING WARNING WARNING: Units are not yet known to be + correct. Trust the magnitude of this quantity at your own + risk. However, it should just be a multiplicative offset from + reality... + """ + return (data["Bx"]**2 + data["By"]**2 + data["Bz"]**2)/2. +add_field("MagneticEnergy",function=_MagneticEnergy, + units=r"", + validators = [ValidateDataField("Bx"), + ValidateDataField("By"), + ValidateDataField("Bz")]) + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/exceptions.py --- a/yt/exceptions.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -""" -This is a library of yt-defined exceptions - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -# We don't need to import 'exceptions' -#import exceptions - -class YTException(Exception): - def __init__(self, pf = None): - Exception.__init__(self) - self.pf = pf - -# Data access exceptions: - -class YTSphereTooSmall(YTException): - def __init__(self, pf, radius, smallest_cell): - YTException.__init__(self, pf) - self.radius = radius - self.smallest_cell = smallest_cell - - def __str__(self): - return "%0.5e < %0.5e" % (self.radius, self.smallest_cell) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/HierarchySubset.py --- a/yt/extensions/HierarchySubset.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,347 +0,0 @@ -""" -A means of extracting a subset of the hierarchy - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - - -from yt.mods import * -from yt.lagos import AMRGridPatch, StaticOutput, AMRHierarchy -import h5py, os.path - -class DummyHierarchy(object): - pass - -class ConstructedRootGrid(AMRGridPatch): - __slots__ = ['base_grid', 'id', 'base_pf'] - _id_offset = 1 - def __init__(self, base_pf, pf, hierarchy, level, left_edge, right_edge): - """ - This is a fake root grid, constructed by creating a - :class:`yt.lagos.CoveringGridBase` at a given *level* between - *left_edge* and *right_edge*. - """ - self.pf = pf - self.base_pf = base_pf - self.field_parameters = {} - self.NumberOfParticles = 0 - self.id = 1 - self.hierarchy = hierarchy - self._child_mask = self._child_indices = self._child_index_mask = None - self.Level = level - self.LeftEdge = left_edge - self.RightEdge = right_edge - self.start_index = na.min([grid.get_global_startindex() for grid in - base_pf.h.select_grids(level)], axis=0).astype('int64') - self.dds = base_pf.h.select_grids(level)[0].dds.copy() - dims = (self.RightEdge-self.LeftEdge)/self.dds - self.ActiveDimensions = dims - print "Constructing base grid of size %s" % (self.ActiveDimensions) - self.base_grid = base_pf.h.smoothed_covering_grid(level, self.LeftEdge, - self.RightEdge, dims=dims) - self.base_grid.Level = self.base_grid.level - self.data = {} - #self._calculate_child_masks() - self.Parent = None - self.Children = [] - - def get_vertex_centered_data(self, field, smoothed=True): - vc = self.base_pf.h.smoothed_covering_grid(self.base_grid.Level, - self.base_grid.LeftEdge - self.base_grid.dds*0.5, - self.base_grid.RightEdge + self.base_grid.dds*0.5, - dims = self.ActiveDimensions + 1) - return vc[field] - -class AMRExtractedGridProxy(AMRGridPatch): - __slots__ = ['base_grid'] - _id_offset = 1 - def __init__(self, grid_id, base_grid, hierarchy): - # We make a little birdhouse in our soul for the base_grid - # (they're the only bee in our bonnet!) - self.base_grid = base_grid - AMRGridPatch.__init__(self, grid_id, filename = None, hierarchy=hierarchy) - self.Parent = None - self.Children = [] - self.Level = -1 - - def get_vertex_centered_data(self, *args, **kwargs): - return self.base_grid.get_vertex_centered_data(*args, **kwargs) - -class OldExtractedHierarchy(object): - - def __init__(self, pf, min_level, max_level = -1, offset = None, - always_copy=False): - """ - This is a class that extracts a hierarchy from another hierarchy, - filling in regions as necessary. It accepts a parameter file (*pf*), a - *min_level*, a *max_level*, and alternately an *offset*. This class is - typically or exclusively used to extract for the purposes of visualization. - """ - self.pf = pf - self.always_copy = always_copy - self.min_level = min_level - self.int_offset = na.min([grid.get_global_startindex() for grid in - pf.h.select_grids(min_level)], axis=0).astype('float64') - min_left = na.min([grid.LeftEdge for grid in - pf.h.select_grids(min_level)], axis=0).astype('float64') - max_right = na.max([grid.RightEdge for grid in - pf.h.select_grids(min_level)], axis=0).astype('float64') - if offset is None: offset = (max_right + min_left)/2.0 - self.left_edge_offset = offset - self.mult_factor = 2**min_level - self.min_left_edge = self._convert_coords(min_left) - self.max_right_edge = self._convert_coords(max_right) - if max_level == -1: max_level = pf.h.max_level - self.max_level = min(max_level, pf.h.max_level) - self.final_level = self.max_level - self.min_level - if len(self.pf.h.select_grids(self.min_level)) > 0: - self._base_grid = ConstructedRootGrid(self.pf, self.min_level, - min_left, max_right) - else: self._base_grid = None - - def select_level(self, level): - if level == 0 and self._base_grid is not None: - return [self._base_grid] - return self.pf.h.select_grids(self.min_level + level) - - def export_output(self, afile, n, field): - # I prefer dict access, but tables doesn't. - # But h5py does! - time_node = afile.create_group("/time-%s" % n) - time_node.attrs['time'] = self.pf["InitialTime"] - time_node.attrs['numLevels'] = self.pf.h.max_level+1-self.min_level - # Can take a while, so let's get a progressbar - self._export_all_levels(afile, time_node, field) - - def _export_all_levels(self, afile, time_node, field): - pbar = yt.funcs.get_pbar("Exporting levels", self.final_level+1) - for i,grid_set in enumerate(self.get_levels()): - pbar.update(i) - self.export_level(afile, time_node, i, field, grid_set) - pbar.finish() - - def export_level(self, afile, time_node, level, field, grids = None): - level_node = afile.create_group("%s/level-%s" % (time_node,level)) - # Grid objects on this level... - if grids is None: grids = self.pf.h.select_grids(level+self.min_level) - level_node.attrs['delta'] = grids[0].dds*self.mult_factor - level_node.attrs['relativeRefinementFactor'] = na.array([2]*3, dtype='int32') - level_node.attrs['numGrids'] = len(grids) - for i,g in enumerate(grids): - self.export_grid(afile, level_node, g, i, field) - - def _convert_grid(self, grid): - int_origin = (grid.get_global_startindex() \ - - self.int_offset*2**(grid.Level-self.min_level)).astype('int64') - level_int_origin = (grid.LeftEdge - self.left_edge_offset)/grid.dds - origin = self._convert_coords(grid.LeftEdge) - dds = grid.dds * self.mult_factor - return int_origin, level_int_origin, origin, dds - - def export_grid(self, afile, level_node, grid, i, field): - grid_node = afile.create_group("%s/grid-%s" % (level_node,i)) - int_origin, lint, origin, dds = self._convert_grid(grid) - grid_node.attrs['integerOrigin'] = int_origin - grid_node.attrs['origin'] = origin - grid_node.attrs['ghostzoneFlags'] = na.zeros(6, dtype='int32') - grid_node.attrs['numGhostzones'] = na.zeros(3, dtype='int32') - grid_node.attrs['dims'] = grid.ActiveDimensions[::-1].astype('int32') - if not self.always_copy and self.pf.h.data_style == 6 \ - and field in self.pf.h.field_list: - if grid.hierarchy.data_style == -1: # constructed grid - # if we can get conversion in amira we won't need to do this - ff = grid[field].astype('float32') - ff /= self.pf.conversion_factors.get(field, 1.0) - afile.create_dataset("%s/grid-data" % grid_node, data=ff.swapaxes(0,2)) - else: - tfn = os.path.abspath(afile.filename) - gfn = os.path.abspath(grid.filename) - fpn = os.path.commonprefix([tfn, grid.filename]) - fn = grid.filename[len(os.path.commonprefix([tfn, grid.filename])):] - grid_node.attrs['referenceFileName'] = fn - grid_node.attrs['referenceDataPath'] = \ - "/Grid%08i/%s" % (grid.id, field) - else: - # Export our array - afile.create_dataset("%s/grid-data" % grid_node, - data = grid[field].astype('float32').swapaxes(0,2)) - - def _convert_coords(self, val): - return (val - self.left_edge_offset)*self.mult_factor - -class ExtractedHierarchy(AMRHierarchy): - - grid = AMRExtractedGridProxy - - def __init__(self, pf, data_style): - # First we set up our translation between original and extracted - self.data_style = data_style - self.min_level = pf.min_level - self.int_offset = na.min([grid.get_global_startindex() for grid in - pf.base_pf.h.select_grids(pf.min_level)], axis=0).astype('float64') - min_left = na.min([grid.LeftEdge for grid in - pf.base_pf.h.select_grids(pf.min_level)], axis=0).astype('float64') - max_right = na.max([grid.RightEdge for grid in - pf.base_pf.h.select_grids(pf.min_level)], axis=0).astype('float64') - level_dx = pf.base_pf.h.select_grids(pf.min_level)[0].dds[0] - dims = ((max_right-min_left)/level_dx) - max_right += (dims.max() - dims) * level_dx - offset = pf.offset - if offset is None: offset = min_left - self.left_edge_offset = offset - pf.offset = offset - self.mult_factor = 2**pf.min_level - self.min_left_edge = self._convert_coords(min_left) - self.max_right_edge = self._convert_coords(max_right) - self.min_left, self.max_right = min_left, max_right - max_level = pf.max_level - if max_level == -1: max_level = pf.base_pf.h.max_level - self.max_level = min(max_level, pf.base_pf.h.max_level) - self.final_level = self.max_level - self.min_level - - # Now we utilize the existing machinery for generating the appropriate - # arrays of grids, etc etc. - self.base_pf = pf.base_pf - AMRHierarchy.__init__(self, pf, data_style) - - # Now a few cleanups - self.pf.override["DomainRightEdge"] = self.max_right_edge - self.pf.override["DomainLeftEdge"] = self.min_left_edge - for u,v in self.base_pf.units.items(): - self.pf.override[u] = v / self.mult_factor - self.pf.override['unitary'] = 1.0 / (self.pf["DomainRightEdge"] - - self.pf["DomainLeftEdge"]).max() - - def _count_grids(self): - self.num_grids = 1 + sum( ( # 1 is the base grid - len(self.base_pf.h.select_grids(level)) - for level in range(self.min_level+1, self.max_level)) ) - - def _parse_hierarchy(self): - # Here we need to set up the grid info, which for the Enzo hierarchy - # is done like: - # self.grid_dimensions.flat[:] = ei - # self.grid_dimensions -= na.array(si, self.float_type) - # self.grid_dimensions += 1 - # self.grid_left_edge.flat[:] = LE - # self.grid_right_edge.flat[:] = RE - # self.grid_particle_count.flat[:] = np - # self.grids = na.array(self.grids, dtype='object') - # - # For now, we make the presupposition that all of our grids are - # strictly nested and we are not doing any cuts. However, we do - # construct a root grid! - root_level_grids = self.base_pf.h.select_grids(self.min_level) - base_grid = ConstructedRootGrid(self.base_pf, self.pf, self, - self.min_level, self.min_left, self.max_right) - self._fill_grid_arrays(base_grid, 0) - grids = [base_grid] - # We need to ensure we have the correct parentage relationships - # However, we want the parent/child to be to the new proxy grids - # so we need to map between the old ids and the new ids - self.id_map = {} - grid_id = 2 # id 0 is the base grid - for level in range(self.min_level+1, self.max_level): - for grid in self.base_pf.h.select_grids(level): - # This next little bit will have to be changed if we ever move to - # not-strictly-nested AMR hierarchies - parent = self.id_map.get(grid.Parent.id, base_grid) - grids.append(self.grid(grid_id, grid, self)) - parent.Children.append(grids[-1]) - grids[-1].Parent = parent - self.id_map[grid.id] = grids[-1] - # Now we fill in our arrays of values -- note that we - # are filling in values from the base grids, not the newly - # extracted grids. We will perform bulk changes after we - # finish. - self._fill_grid_arrays(grid, grid_id-1) - grid_id += 1 - - self.grid_left_edge = self._convert_coords(self.grid_left_edge) - self.grid_right_edge = self._convert_coords(self.grid_right_edge) - self.grids = na.array(grids, dtype='object') - - def _fill_grid_arrays(self, grid, i): - # This just fills in the grid arrays for a single grid -- - # note that we presuppose here that we are being handed a grid object - # that has these defined; this means we are being handed the *base* - # grid, not the newly extracted one - self.grid_dimensions[i,:] = grid.ActiveDimensions - self.grid_left_edge[i,:] = grid.LeftEdge - self.grid_right_edge[i,:] = grid.RightEdge - self.grid_particle_count[i] = grid.NumberOfParticles - - def _populate_grid_objects(self): - for grid in self.grids: - grid.Level = grid.base_grid.Level - self.pf.min_level - grid._prepare_grid() - grid._setup_dx() - grid.start_index = None - self.max_level -= self.pf.min_level - print "New max level:", self.max_level - - def _convert_coords(self, val): - return (val - self.left_edge_offset)*self.mult_factor - - def _detect_fields(self): - self.field_list = self.base_pf.h.field_list[:] - - def _setup_unknown_fields(self): - pass # Done in the base_h - - def _setup_derived_fields(self): - self.derived_field_list = self.base_pf.h.derived_field_list[:] - - def _initialize_data_storage(self): - self._data_file = None - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - -class ExtractedParameterFile(StaticOutput): - _hierarchy_class = ExtractedHierarchy - data_style = "extracted" - - def __init__(self, base_pf, min_level, max_level = -1, offset = None): - self.base_pf = base_pf - self.min_level = min_level - self.max_level = max_level - self.offset = offset - self.override = {} - - def __repr__(self): - return "extracted_%s" % self.base_pf - - def __getattr__(self, name): - # This won't get called if 'name' is found already - # and we'd like it to raise AttributeError if it's not anywhere - if name in ['h', 'hierarchy']: - return StaticOutput._get_hierarchy(self) - return getattr(self.base_pf, name) - - def __getitem__(self, key): - if key not in self.override: - return self.base_pf[key] - return self.override[key] - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/RayTracer.py --- a/yt/extensions/RayTracer.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -""" -The slowest ray-tracer known to man. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.lagos import * - -class SlowRayTracer(object): - def __init__(self, pf, axis, bounds, res, func, reverse = False): - self.pf = pf - self.axis = axis - self.x_bounds, self.y_bounds = bounds - self.res = res - self.func = func - self.reverse = reverse - self.buff = na.zeros(res, dtype='float64') - self.fill_buff() - - def _trace_single_ray(self, x, y): - ray = self.pf.h.ortho_ray(self.axis, (x, y)) - order = ray[axis_names[self.axis]].argsort() - if self.reverse: order = order[::-1] - return self.func(ray, order) - - def fill_buff(self): - #pb = get_pbar("Ray tracing ", na.prod(self.res)) - xs = na.linspace(self.x_bounds[0], self.x_bounds[1], self.res[0]) - ys = na.linspace(self.y_bounds[0], self.y_bounds[1], self.res[1]) - #counter = 0 - for i, x in enumerate(xs.ravel()): - #counter += 1 - print i - for j, y in enumerate(ys.ravel()): - #pb.update(counter) - self.buff[i,j] = self._trace_single_ray(x,y) - #pb.finish() - - def __getitem__(self, item): - return self.buff[item] - -if __name__ == "__main__": - def raw_proj(ray, order): - return na.sum((ray["Density"]*ray["dx"])[order]) - #return na.sum((ray["Density"]*ray["dx"])[order]) - import yt.logger - yt.logger.disable_stream_logging() - pf = EnzoStaticOutput("/Users/matthewturk/Research/data/galaxy1200.dir/galaxy1200") - srt = SlowRayTracer(pf, 0, ((0.0125,1.0-0.0125),(0.0125,1.0-0.0125)), - (256, 256), raw_proj, reverse=False) - import pylab - pylab.imshow(na.log10(srt.buff), interpolation='nearest', origin='lower') - pylab.savefig("srt_raw_x.png") - pylab.clf() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/SpectralIntegrator.py --- a/yt/extensions/SpectralIntegrator.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -""" -Integrator classes to deal with interpolation and integration of input spectral -bins. Currently only supports Cloudy-style data. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.mods import * - -class SpectralFrequencyIntegrator(object): - def __init__(self, table, field_names, - bounds, ev_bounds): - """ - From a table, interpolate over field_names to get resultant luminosity. - Table must be of the style such that it is ordered by - ``[field_names[0], field_names[1], ev]`` - """ - self.table = table - self.field_names = field_names - - self.bounds = bounds - self.ev_bounds = ev_bounds - self.ev_vals = na.logspace(ev_bounds[0], ev_bounds[1], table.shape[-1]) - - def _get_interpolator(self, ev_min, ev_max): - """ - Integrates from ev_min to ev_max and returns an interpolator. - """ - e_is, e_ie = na.digitize([ev_min, ev_max], self.ev_vals) - bin_table = na.trapz(self.table[...,e_is-1:e_ie], - 2.41799e17* - (self.ev_vals[e_is:e_ie+1]-self.ev_vals[e_is-1:e_is]), - axis=-1) - bin_table = na.log10(bin_table.clip(1e-80,bin_table.max())) - return lagos.BilinearFieldInterpolator( - bin_table, self.bounds, self.field_names[:], - truncate=True) - - def add_frequency_bin_field(self, ev_min, ev_max): - """ - Add a new field to the FieldInfoContainer, which is an - integrated bin from *ev_min* to *ev_max*. - - Returns the name of the new field. - """ - interp = self._get_interpolator(ev_min, ev_max) - name = "XRay_%s_%s" % (ev_min, ev_max) - def frequency_bin_field(field, data): - dd = {'NumberDensity' : na.log10(data["NumberDensity"]), - 'Temperature' : na.log10(data["Temperature"])} - return 10**interp(dd) - add_field(name, function=frequency_bin_field, - projection_conversion="cm", - units=r"\rm{ergs}\/\rm{cm}^{-3}\/\rm{s}^{-1}", - projected_units=r"\rm{ergs}\/\rm{cm}^{-2}\/\rm{s}^{-1}") - return name - -def create_table_from_textfiles(pattern, rho_spec, e_spec, T_spec): - """ - This accepts a CLOUDY text file of emissivities and constructs an - interpolation table for spectral integration. - """ - rho_n_bins, rho_min, rho_max = rho_spec - e_n_bins, e_min, e_max = e_spec - T_n_bins, T_min, T_max = T_spec - # The second one is the fast-varying one - rho_is, e_is = na.mgrid[0:rho_n_bins,0:e_n_bins] - table = na.zeros((rho_n_bins, T_n_bins, e_n_bins), dtype='float64') - mylog.info("Parsing Cloudy files") - for i,ri,ei in zip(range(rho_n_bins*e_n_bins), rho_is.ravel(), e_is.ravel()): - table[ri,:,ei] = [float(l.split()[-1]) for l in open(pattern%(i+1)) if l[0] != "#"] - return table - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/StarAnalysis.py --- a/yt/extensions/StarAnalysis.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,475 +0,0 @@ -""" -StarAnalysis - Functions to analyze stars. - -Author: Stephen Skory -Affiliation: UC San Diego / CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Stephen Skory (and others). 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 . -""" - -import yt.lagos as lagos -from yt.logger import lagosLogger as mylog - -import numpy as na -import h5py - -import math, itertools - -YEAR = 3.155693e7 # sec / year -LIGHT = 2.997925e10 # cm / s - -class StarFormationRate(object): - def __init__(self, pf, data_source=None, star_mass=None, - star_creation_time=None, volume=None, bins=300): - r"""Calculates the star formation rate for a given population of - star particles. - - Parameters - ---------- - pf : EnzoStaticOutput object - data_source : AMRRegion object, optional - The region from which stars are extracted for analysis. If this - is not supplied, the next three must be, otherwise the next - three do not need to be specified. - star_mass : Ordered array or list of floats - The mass of the stars to be analyzed in units of Msun. - star_creation_time : Ordered array or list of floats - The creation time for the stars in code units. - volume : Float - The volume of the region for the specified list of stars. - bins : Integer - The number of time bins used for binning the stars. Default = 300. - - Examples - -------- - - >>> pf = load("RedshiftOutput0000") - >>> sp = pf.h.sphere([0.5,0.5,0.5], [.1]) - >>> sfr = StarFormationRate(pf, sp) - """ - self._pf = pf - self._data_source = data_source - self.star_mass = star_mass - self.star_creation_time = star_creation_time - self.volume = volume - self.bin_count = bins - # Check to make sure we have the right set of informations. - if data_source is None: - if self.star_mass is None or self.star_creation_time is None or \ - self.volume is None: - mylog.error( - """ - If data_source is not provided, all of these paramters need to be set: - star_mass (array, Msun), - star_creation_time (array, code units), - volume (float, Mpc**3). - """) - return None - self.mode = 'provided' - else: - self.mode = 'data_source' - # Set up for time conversion. - self.cosm = lagos.EnzoCosmology(HubbleConstantNow = - (100.0 * self._pf['CosmologyHubbleConstantNow']), - OmegaMatterNow = self._pf['CosmologyOmegaMatterNow'], - OmegaLambdaNow = self._pf['CosmologyOmegaLambdaNow'], - InitialRedshift = self._pf['CosmologyInitialRedshift']) - # Find the time right now. - self.time_now = self.cosm.ComputeTimeFromRedshift( - self._pf["CosmologyCurrentRedshift"]) # seconds - # Build the distribution. - self.build_dist() - - def build_dist(self): - """ - Build the data for plotting. - """ - # Pick out the stars. - if self.mode == 'data_source': - ct = self._data_source["creation_time"] - ct_stars = ct[ct > 0] - mass_stars = self._data_source["ParticleMassMsun"][ct > 0] - elif self.mode == 'provided': - ct_stars = self.star_creation_time - mass_stars = self.star_mass - # Find the oldest stars in units of code time. - tmin= min(ct_stars) - # Multiply the end to prevent numerical issues. - self.time_bins = na.linspace(tmin*0.99, self._pf['InitialTime'], - num = self.bin_count + 1) - # Figure out which bins the stars go into. - inds = na.digitize(ct_stars, self.time_bins) - 1 - # Sum up the stars created in each time bin. - self.mass_bins = na.zeros(self.bin_count + 1, dtype='float64') - for index in na.unique(inds): - self.mass_bins[index] += sum(mass_stars[inds == index]) - # Calculate the cumulative mass sum over time by forward adding. - self.cum_mass_bins = self.mass_bins.copy() - for index in xrange(self.bin_count): - self.cum_mass_bins[index+1] += self.cum_mass_bins[index] - # We will want the time taken between bins. - self.time_bins_dt = self.time_bins[1:] - self.time_bins[:-1] - - def write_out(self, name="StarFormationRate.out"): - r"""Write out the star analysis to a text file *name*. The columns are in - order. - - The columns in the output file are: - 1. Time (yrs) - 2. Look-back time (yrs) - 3. Redshift - 4. Star formation rate in this bin per year (Msol/yr) - 5. Star formation rate in this bin per year per Mpc**3 (Msol/yr/Mpc**3) - 6. Stars formed in this time bin (Msol) - 7. Cumulative stars formed up to this time bin (Msol) - - Parameters - ---------- - name : String - The name of the file to write to. Default = StarFormationRate.out. - - Examples - -------- - >>> sfr.write_out("stars-SFR.out") - """ - fp = open(name, "w") - if self.mode == 'data_source': - try: - vol = self._data_source.volume('mpc') - except AttributeError: - # If we're here, this is probably a HOPHalo object, and we - # can get the volume this way. - ds = self._data_source.get_sphere() - vol = ds.volume('mpc') - elif self.mode == 'provided': - vol = self.volume - tc = self._pf["Time"] - # Use the center of the time_bin, not the left edge. - fp.write("#time\tlookback\tredshift\tMsol/yr\tMsol/yr/Mpc3\tMsol\tcumMsol\t\n") - for i, time in enumerate((self.time_bins[1:] + self.time_bins[:-1])/2.): - line = "%1.5e %1.5e %1.5e %1.5e %1.5e %1.5e %1.5e\n" % \ - (time * tc / YEAR, # Time - (self.time_now - time * tc)/YEAR, # Lookback time - self.cosm.ComputeRedshiftFromTime(time * tc), # Redshift - self.mass_bins[i] / (self.time_bins_dt[i] * tc / YEAR), # Msol/yr - self.mass_bins[i] / (self.time_bins_dt[i] * tc / YEAR) / vol, # Msol/yr/vol - self.mass_bins[i], # Msol in bin - self.cum_mass_bins[i]) # cumulative - fp.write(line) - fp.close() - -CHABRIER = { -"Z0001" : "bc2003_hr_m22_chab_ssp.ised.h5", #/* 0.5% */ -"Z0004" : "bc2003_hr_m32_chab_ssp.ised.h5", #/* 2% */ -"Z004" : "bc2003_hr_m42_chab_ssp.ised.h5", #/* 20% */ -"Z008" : "bc2003_hr_m52_chab_ssp.ised.h5", #/* 40% */ -"Z02" : "bc2003_hr_m62_chab_ssp.ised.h5", #/* solar; 0.02 */ -"Z05" : "bc2003_hr_m72_chab_ssp.ised.h5" #/* 250% */ -} - -SALPETER = { -"Z0001" : "bc2003_hr_m22_salp_ssp.ised.h5", #/* 0.5% */ -"Z0004" : "bc2003_hr_m32_salp_ssp.ised.h5", #/* 2% */ -"Z004" : "bc2003_hr_m42_salp_ssp.ised.h5", #/* 20% */ -"Z008" : "bc2003_hr_m52_salp_ssp.ised.h5", #/* 40% */ -"Z02" : "bc2003_hr_m62_salp_ssp.ised.h5", #/* solar; 0.02 */ -"Z05" : "bc2003_hr_m72_salp_ssp.ised.h5" #/* 250% */ -} - -Zsun = 0.02 - -#/* dividing line of metallicity; linear in log(Z/Zsun) */ -METAL1 = 0.01 # /* in units of Z/Zsun */ -METAL2 = 0.0632 -METAL3 = 0.2828 -METAL4 = 0.6325 -METAL5 = 1.5811 -METALS = na.array([METAL1, METAL2, METAL3, METAL4, METAL5]) - -# Translate METALS array digitize to the table dicts -MtoD = na.array(["Z0001", "Z0004", "Z004", "Z008", "Z02", "Z05"]) - -""" -This spectrum code is based on code from Ken Nagamine, converted from C to Python. -I've also reversed the order of elements in the flux arrays to be in C-ordering, -for faster memory access. -""" - -class SpectrumBuilder(object): - def __init__(self, pf, bcdir="", model="chabrier"): - r"""Initialize the data to build a summed flux spectrum for a - collection of stars using the models of Bruzual & Charlot (2003). - This function loads the necessary data tables into memory and - must be called before analyzing any star particles. - - Parameters - ---------- - pf : EnzoStaticOutput object - bcdir : String - Path to directory containing Bruzual & Charlot h5 fit files. - model : String - Choice of Initial Metalicity Function model, 'chabrier' or - 'salpeter'. Default = 'chabrier'. - - Examples - -------- - >>> pf = load("RedshiftOutput0000") - >>> spec = SpectrumBuilder(pf, "/home/user/bc/", model="salpeter") - """ - self._pf = pf - self.bcdir = bcdir - - if model == "chabrier": - self.model = CHABRIER - elif model == "salpeter": - self.model = SALPETER - # Set up for time conversion. - self.cosm = lagos.EnzoCosmology(HubbleConstantNow = - (100.0 * self._pf['CosmologyHubbleConstantNow']), - OmegaMatterNow = self._pf['CosmologyOmegaMatterNow'], - OmegaLambdaNow = self._pf['CosmologyOmegaLambdaNow'], - InitialRedshift = self._pf['CosmologyInitialRedshift']) - # Find the time right now. - self.time_now = self.cosm.ComputeTimeFromRedshift( - self._pf["CosmologyCurrentRedshift"]) # seconds - - # Read the tables. - self.read_bclib() - - def read_bclib(self): - """ - Read in the age and wavelength bins, and the flux bins for each - metallicity. - """ - self.flux = {} - for file in self.model: - fname = self.bcdir + "/" + self.model[file] - fp = h5py.File(fname, 'r') - self.age = fp["agebins"][:] # 1D floats - self.wavelength = fp["wavebins"][:] # 1D floats - self.flux[file] = fp["flam"][:,:] # 2D floats, [agebin, wavebin] - fp.close() - - def calculate_spectrum(self, data_source=None, star_mass=None, - star_creation_time=None, star_metallicity_fraction=None, - star_metallicity_constant=None, min_age=0.): - r"""For the set of stars, calculate the collective spectrum. - Attached to the output are several useful objects: - final_spec: The collective spectrum in units of flux binned in wavelength. - wavelength: The wavelength for the spectrum bins, in Angstroms. - total_mass: Total mass of all the stars. - avg_mass: Average mass of all the stars. - avg_metal: Average metallicity of all the stars. - - Parameters - ---------- - data_source : AMRRegion object, optional - The region from which stars are extracted for analysis. If this is - not specified, the next three parameters must be supplied. - star_mass : Array or list of floats - An array of star masses in Msun units. - star_creation_time : Array or list of floats - An array of star creation times in code units. - star_metallicity_fraction : Array or list of floats - An array of star metallicity fractions, in code - units (which is not Z/Zsun, rather just Z). - star_metallicity_constant : Float - If desired, override the star - metallicity fraction of all the stars to the given value. - min_age : Float - Removes young stars younger than this number (in years) - from the spectrum. Default: 0 (all stars). - - Examples - -------- - >>> sp = pf.h.sphere([0.5,0.5,0.5], [.1]) - >>> spec.calculate_spectrum(data_source=sp, min_age = 1.e6) - """ - # Initialize values - self.final_spec = na.zeros(self.wavelength.size, dtype='float64') - self._data_source = data_source - self.star_mass = star_mass - self.star_creation_time = star_creation_time - self.star_metal = star_metallicity_fraction - self.min_age = min_age - - # Check to make sure we have the right set of data. - if data_source is None: - if self.star_mass is None or self.star_creation_time is None or \ - (star_metallicity_fraction is None and star_metallicity_constant is None): - mylog.error( - """ - If data_source is not provided, all of these paramters need to be set: - star_mass (array, Msun), - star_creation_time (array, code units), - And one of: - star_metallicity_fraction (array, code units). - --OR-- - star_metallicity_constant (float, code units). - """) - return None - if star_metallicity_constant is not None: - self.star_metal = na.ones(self.star_mass.size, dtype='float64') * \ - star_metallicity_constant - else: - # Get the data we need. - ct = self._data_source["creation_time"] - self.star_creation_time = ct[ct > 0] - self.star_mass = self._data_source["ParticleMassMsun"][ct > 0] - if star_metallicity_constant is not None: - self.star_metal = na.ones(self.star_mass.size, dtype='float64') * \ - star_metallicity_constant - else: - self.star_metal = self._data_source["metallicity_fraction"][ct > 0] - # Fix metallicity to units of Zsun. - self.star_metal /= Zsun - # Age of star in years. - dt = (self.time_now - self.star_creation_time * self._pf['Time']) / YEAR - # Remove young stars - sub = dt > self.min_age - self.star_metal = self.star_metal[sub] - dt = dt[sub] - self.star_creation_time = self.star_creation_time[sub] - # Figure out which METALS bin the star goes into. - Mindex = na.digitize(self.star_metal, METALS) - # Replace the indices with strings. - Mname = MtoD[Mindex] - # Figure out which age bin this star goes into. - Aindex = na.digitize(dt, self.age) - # Ratios used for the interpolation. - ratio1 = (dt - self.age[Aindex-1]) / (self.age[Aindex] - self.age[Aindex-1]) - ratio2 = (self.age[Aindex] - dt) / (self.age[Aindex] - self.age[Aindex-1]) - # Sort the stars by metallicity and then by age, which should reduce - # memory access time by a little bit in the loop. - indexes = na.arange(self.star_metal.size) - sort = na.asarray([indexes[i] for i in na.lexsort([indexes, Aindex, Mname])]) - Mname = Mname[sort] - Aindex = Aindex[sort] - ratio1 = ratio1[sort] - ratio2 = ratio2[sort] - self.star_mass = self.star_mass[sort] - self.star_creation_time = self.star_creation_time[sort] - self.star_metal = self.star_metal[sort] - - # Interpolate the flux for each star, adding to the total by weight. - for star in itertools.izip(Mname, Aindex, ratio1, ratio2, self.star_mass): - # Pick the right age bin for the right flux array. - flux = self.flux[star[0]][star[1],:] - # Get the one just before the one above. - flux_1 = self.flux[star[0]][star[1]-1,:] - # interpolate in log(flux), linear in time. - int_flux = star[3] * na.log10(flux_1) + star[2] * na.log10(flux) - # Add this flux to the total, weighted by mass. - self.final_spec += na.power(10., int_flux) * star[4] - # Normalize. - self.total_mass = na.sum(self.star_mass) - self.avg_mass = na.mean(self.star_mass) - tot_metal = sum(self.star_metal * self.star_mass) - self.avg_metal = math.log10(tot_metal / self.total_mass / Zsun) - - # Below is an attempt to do the loop using vectors and matrices, - # however it doesn't appear to be much faster, probably due to all - # the gymnastics that have to be done to do element-by-element - # multiplication for matricies. - # I'm keeping it in here in case I come up with a more - # elegant way that actually is faster. -# for metal_name in MtoD: -# # Pick out our stars in this metallicity bin. -# select = (Mname == metal_name) -# A = Aindex[select] -# if A.size == 0: continue -# r1 = ratio1[select] -# r2 = ratio2[select] -# sm = self.star_mass[select] -# # From the flux array for this metal, and our selection, build -# # a new flux array just for the ages of these stars, in the -# # same order as the selection of stars. -# this_flux = na.matrix(self.flux[metal_name][A]) -# # Make one for the last time step for each star in the same fashion -# # as above. -# this_flux_1 = na.matrix(self.flux[metal_name][A-1]) -# # This is kind of messy, but we're going to multiply this_fluxes -# # by the appropriate ratios and add it together to do the -# # interpolation in log(flux) and linear in time. -# print r1.size -# r1 = na.matrix(r1.tolist()*self.wavelength.size).reshape(self.wavelength.size,r1.size).T -# r2 = na.matrix(r2.tolist()*self.wavelength.size).reshape(self.wavelength.size,r2.size).T -# print this_flux_1.shape, r1.shape -# int_flux = na.multiply(na.log10(this_flux_1),r1) \ -# + na.multiply(na.log10(this_flux),r2) -# # Weight the fluxes by mass. -# sm = na.matrix(sm.tolist()*self.wavelength.size).reshape(self.wavelength.size,sm.size).T -# int_flux = na.multiply(na.power(10., int_flux), sm) -# # Sum along the columns, converting back to an array, adding -# # to the full spectrum. -# self.final_spec += na.array(int_flux.sum(axis=0))[0,:] - - - def write_out(self, name="sum_flux.out"): - r"""Write out the summed flux to a file. - - The output file from this function has two columns: Wavelength - (Angstrom) and Flux (Luminosity per unit wavelength, L_sun Ang^-1, - L_sun = 3.826 * 10^33 ergs s^-1.). - - Parameters - ---------- - name : String - Name of file to write to. Default = "sum_flux.out" - - Examples - -------- - >>> spec.write_out("spec.out") - """ - fp = open(name, 'w') - for i, wave in enumerate(self.wavelength): - fp.write("%1.5e\t%1.5e\n" % (wave, self.final_spec[i])) - fp.close() - - def write_out_SED(self, name="sum_SED.out", flux_norm=5200.): - r"""Write out the summed SED to a file. The file has two columns: - 1) Wavelength (Angstrom) - 2) Relative flux normalized to the flux at *flux_norm*. - It also will attach to the SpectrumBuilder object - an array *f_nu* which is the normalized flux, - identical to the disk output. - - Parameters - ---------- - name : String - Name of file to write to. Default = "sum_SED.out" - flux_norm : Float - Wavelength of the flux to normalize the distribution against. - Default = 5200 Ang. - - Examples - -------- - >>> spec.write_out_SED(name = "SED.out", flux_norm = 6000.) - """ - # find the f_nu closest to flux_norm - fn_wavelength = na.argmin(abs(self.wavelength - flux_norm)) - f_nu = self.final_spec * na.power(self.wavelength, 2.) / LIGHT - # Normalize f_nu - self.f_nu = f_nu / f_nu[fn_wavelength] - # Write out. - fp = open(name, 'w') - for i, wave in enumerate(self.wavelength): - fp.write("%1.5e\t%1.5e\n" % (wave, self.f_nu[i])) - fp.close() - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/_colormap_data.py --- a/yt/extensions/_colormap_data.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,797 +0,0 @@ -### Auto-generated colormap tables, taken from Matplotlib ### - -from numpy import array -color_map_luts = {} - - -### algae ### - -color_map_luts['algae'] = \ - ( -array([ 0.3125 , 0.30637255, 0.3002451 , 0.29411765, 0.2879902 , - 0.28186275, 0.27573529, 0.26960784, 0.26348039, 0.25735294, - 0.25122549, 0.24509804, 0.23897059, 0.23284314, 0.22671569, - 0.22058824, 0.21446078, 0.20833333, 0.20220588, 0.19607843, - 0.18995098, 0.18382353, 0.17769608, 0.17156863, 0.16544118, - 0.15931373, 0.15318627, 0.14705882, 0.14093137, 0.13480392, - 0.12867647, 0.12254902, 0.11642157, 0.11029412, 0.10416667, - 0.09803922, 0.09191176, 0.08578431, 0.07965686, 0.07352941, - 0.06740196, 0.06127451, 0.05514706, 0.04901961, 0.04289216, - 0.03676471, 0.03063725, 0.0245098 , 0.01838235, 0.0122549 , - 0.00612745, 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0.01960784, 0.03921569, - 0.05882353, 0.07843137, 0.09803922, 0.11764706, 0.1372549 , - 0.15686275, 0.17647059, 0.19607843, 0.21568627, 0.23529412, - 0.25490196, 0.2745098 , 0.29411765, 0.31372549, 0.33333333, - 0.35294118, 0.37254902, 0.39215686, 0.41176471, 0.43137255, - 0.45098039, 0.47058824, 0.49019608, 0.50980392, 0.52941176, - 0.54901961, 0.56862745, 0.58823529, 0.60784314, 0.62745098, - 0.64705882, 0.66666667, 0.68627451, 0.70588235, 0.7254902 , - 0.74509804, 0.76470588, 0.78431373, 0.80392157, 0.82352941, - 0.84313725, 0.8627451 , 0.88235294, 0.90196078, 0.92156863, - 0.94117647, 0.96078431, 0.98039216, 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 0.97564338, 0.94316789, - 0.9106924 , 0.87821691, 0.84574142, 0.81326593, 0.78079044, - 0.74831495, 0.71583946, 0.68336397, 0.65088848, 0.61841299, - 0.5859375 ]), -array([ 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0.00995711, 0.01991422, 0.02987132, - 0.03982843, 0.04978554, 0.05974265, 0.06969975, 0.07965686, - 0.08961397, 0.09957108, 0.10952819, 0.11948529, 0.1294424 , - 0.13939951, 0.14935662, 0.15931373, 0.16927083, 0.17922794, - 0.18918505, 0.19914216, 0.20909926, 0.21905637, 0.22901348, - 0.23897059, 0.2489277 , 0.2588848 , 0.26884191, 0.27879902, - 0.28875613, 0.29871324, 0.30867034, 0.31862745, 0.32858456, - 0.33854167, 0.34849877, 0.35845588, 0.36841299, 0.3783701 , - 0.38832721, 0.39828431, 0.40824142, 0.41819853, 0.42815564, - 0.43811275, 0.44806985, 0.45802696, 0.46798407, 0.47794118, - 0.48789828, 0.49785539, 0.5078125 , 0.51746324, 0.52711397, - 0.53676471, 0.54641544, 0.55606618, 0.56571691, 0.57536765, - 0.58501838, 0.59466912, 0.60431985, 0.61397059, 0.62362132, - 0.63327206, 0.64292279, 0.65257353, 0.66222426, 0.671875 , - 0.68152574, 0.69117647, 0.70082721, 0.71047794, 0.72012868, - 0.72977941, 0.73943015, 0.74908088, 0.75873162, 0.76838235, - 0.77803309, 0.78768382, 0.79733456, 0.80698529, 0.81663603, - 0.82628676, 0.8359375 , 0.84558824, 0.85523897, 0.86488971, - 0.87454044, 0.88419118, 0.89384191, 0.90349265, 0.91314338, - 0.92279412, 0.93244485, 0.94209559, 0.95174632, 0.96139706, - 0.97104779, 0.98069853, 0.99034926, 1. , 0.99019608, - 0.98039216, 0.97058824, 0.96078431, 0.95098039, 0.94117647, - 0.93137255, 0.92156863, 0.91176471, 0.90196078, 0.89215686, - 0.88235294, 0.87254902, 0.8627451 , 0.85294118, 0.84313725, - 0.83333333, 0.82352941, 0.81372549, 0.80392157, 0.79411765, - 0.78431373, 0.7745098 , 0.76470588, 0.75490196, 0.74509804, - 0.73529412, 0.7254902 , 0.71568627, 0.70588235, 0.69607843, - 0.68627451, 0.67647059, 0.66666667, 0.65686275, 0.64705882, - 0.6372549 , 0.62745098, 0.61764706, 0.60784314, 0.59803922, - 0.58823529, 0.57843137, 0.56862745, 0.55882353, 0.54901961, - 0.53921569, 0.52941176, 0.51960784, 0.50980392, 0.5 , - 0.49019608, 0.48039216, 0.47058824, 0.46078431, 0.45098039, - 0.44117647, 0.43137255, 0.42156863, 0.41176471, 0.40196078, - 0.39215686, 0.38235294, 0.37254902, 0.3627451 , 0.35294118, - 0.34313725, 0.33333333, 0.32352941, 0.31372549, 0.30392157, - 0.29411765, 0.28431373, 0.2745098 , 0.26470588, 0.25490196, - 0.24509804, 0.23529412, 0.2254902 , 0.21568627, 0.20588235, - 0.19607843, 0.18627451, 0.17647059, 0.16666667, 0.15686275, - 0.14705882, 0.1372549 , 0.12745098, 0.11764706, 0.10784314, - 0.09803922, 0.08823529, 0.07843137, 0.06862745, 0.05882353, - 0.04901961, 0.03921569, 0.02941176, 0.01960784, 0.00980392, 0. ]), -array([ 3.12500000e-01, 3.23223039e-01, 3.33946078e-01, - 3.44669118e-01, 3.55392157e-01, 3.66115196e-01, - 3.76838235e-01, 3.87561275e-01, 3.98284314e-01, - 4.09007353e-01, 4.19730392e-01, 4.30453431e-01, - 4.41176471e-01, 4.51899510e-01, 4.62622549e-01, - 4.73345588e-01, 4.84068627e-01, 4.94791667e-01, - 5.05514706e-01, 5.16237745e-01, 5.26960784e-01, - 5.37683824e-01, 5.48406863e-01, 5.59129902e-01, - 5.69852941e-01, 5.80575980e-01, 5.91299020e-01, - 6.02022059e-01, 6.12745098e-01, 6.23468137e-01, - 6.34191176e-01, 6.44914216e-01, 6.55637255e-01, - 6.66360294e-01, 6.77083333e-01, 6.87806373e-01, - 6.98529412e-01, 7.09252451e-01, 7.19975490e-01, - 7.30698529e-01, 7.41421569e-01, 7.52144608e-01, - 7.62867647e-01, 7.73590686e-01, 7.84313725e-01, - 7.95036765e-01, 8.05759804e-01, 8.16482843e-01, - 8.27205882e-01, 8.37928922e-01, 8.48651961e-01, - 8.59375000e-01, 8.42524510e-01, 8.25674020e-01, - 8.08823529e-01, 7.91973039e-01, 7.75122549e-01, - 7.58272059e-01, 7.41421569e-01, 7.24571078e-01, - 7.07720588e-01, 6.90870098e-01, 6.74019608e-01, - 6.57169118e-01, 6.40318627e-01, 6.23468137e-01, - 6.06617647e-01, 5.89767157e-01, 5.72916667e-01, - 5.56066176e-01, 5.39215686e-01, 5.22365196e-01, - 5.05514706e-01, 4.88664216e-01, 4.71813725e-01, - 4.54963235e-01, 4.38112745e-01, 4.21262255e-01, - 4.04411765e-01, 3.87561275e-01, 3.70710784e-01, - 3.53860294e-01, 3.37009804e-01, 3.20159314e-01, - 3.03308824e-01, 2.86458333e-01, 2.69607843e-01, - 2.52757353e-01, 2.35906863e-01, 2.19056373e-01, - 2.02205882e-01, 1.85355392e-01, 1.68504902e-01, - 1.51654412e-01, 1.34803922e-01, 1.17953431e-01, - 1.01102941e-01, 8.42524510e-02, 6.74019608e-02, - 5.05514706e-02, 3.37009804e-02, 1.68504902e-02, - 0.00000000e+00, 1.53186275e-03, 3.06372549e-03, - 4.59558824e-03, 6.12745098e-03, 7.65931373e-03, - 9.19117647e-03, 1.07230392e-02, 1.22549020e-02, - 1.37867647e-02, 1.53186275e-02, 1.68504902e-02, - 1.83823529e-02, 1.99142157e-02, 2.14460784e-02, - 2.29779412e-02, 2.45098039e-02, 2.60416667e-02, - 2.75735294e-02, 2.91053922e-02, 3.06372549e-02, - 3.21691176e-02, 3.37009804e-02, 3.52328431e-02, - 3.67647059e-02, 3.82965686e-02, 3.98284314e-02, - 4.13602941e-02, 4.28921569e-02, 4.44240196e-02, - 4.59558824e-02, 4.74877451e-02, 4.90196078e-02, - 5.05514706e-02, 5.20833333e-02, 5.36151961e-02, - 5.51470588e-02, 5.66789216e-02, 5.82107843e-02, - 5.97426471e-02, 6.12745098e-02, 6.28063725e-02, - 6.43382353e-02, 6.58700980e-02, 6.74019608e-02, - 6.89338235e-02, 7.04656863e-02, 7.19975490e-02, - 7.35294118e-02, 7.50612745e-02, 7.65931373e-02, - 7.81250000e-02, 7.73590686e-02, 7.65931373e-02, - 7.58272059e-02, 7.50612745e-02, 7.42953431e-02, - 7.35294118e-02, 7.27634804e-02, 7.19975490e-02, - 7.12316176e-02, 7.04656863e-02, 6.96997549e-02, - 6.89338235e-02, 6.81678922e-02, 6.74019608e-02, - 6.66360294e-02, 6.58700980e-02, 6.51041667e-02, - 6.43382353e-02, 6.35723039e-02, 6.28063725e-02, - 6.20404412e-02, 6.12745098e-02, 6.05085784e-02, - 5.97426471e-02, 5.89767157e-02, 5.82107843e-02, - 5.74448529e-02, 5.66789216e-02, 5.59129902e-02, - 5.51470588e-02, 5.43811275e-02, 5.36151961e-02, - 5.28492647e-02, 5.20833333e-02, 5.13174020e-02, - 5.05514706e-02, 4.97855392e-02, 4.90196078e-02, - 4.82536765e-02, 4.74877451e-02, 4.67218137e-02, - 4.59558824e-02, 4.51899510e-02, 4.44240196e-02, - 4.36580882e-02, 4.28921569e-02, 4.21262255e-02, - 4.13602941e-02, 4.05943627e-02, 3.98284314e-02, - 3.90625000e-02, 3.82965686e-02, 3.75306373e-02, - 3.67647059e-02, 3.59987745e-02, 3.52328431e-02, - 3.44669118e-02, 3.37009804e-02, 3.29350490e-02, - 3.21691176e-02, 3.14031863e-02, 3.06372549e-02, - 2.98713235e-02, 2.91053922e-02, 2.83394608e-02, - 2.75735294e-02, 2.68075980e-02, 2.60416667e-02, - 2.52757353e-02, 2.45098039e-02, 2.37438725e-02, - 2.29779412e-02, 2.22120098e-02, 2.14460784e-02, - 2.06801471e-02, 1.99142157e-02, 1.91482843e-02, - 1.83823529e-02, 1.76164216e-02, 1.68504902e-02, - 1.60845588e-02, 1.53186275e-02, 1.45526961e-02, - 1.37867647e-02, 1.30208333e-02, 1.22549020e-02, - 1.14889706e-02, 1.07230392e-02, 9.95710784e-03, - 9.19117647e-03, 8.42524510e-03, 7.65931373e-03, - 6.89338235e-03, 6.12745098e-03, 5.36151961e-03, - 4.59558824e-03, 3.82965686e-03, 3.06372549e-03, - 2.29779412e-03, 1.53186275e-03, 7.65931373e-04, - 0.00000000e+00]), -array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1.]), - ) - -### gist_stern ### - -color_map_luts['gist_stern'] = \ - ( -array([ 0. , 0.06588235, 0.13176471, 0.19764706, 0.26352941, - 0.32941176, 0.39529412, 0.46326797, 0.53098039, 0.59686274, - 0.68627448, 0.79921568, 0.86509803, 0.93150326, 0.99477124, - 0.97647059, 0.95816995, 0.9398693 , 0.92156865, 0.90326799, - 0.88235296, 0.86274512, 0.84444446, 0.82614381, 0.80784316, - 0.78823532, 0.76732028, 0.74901963, 0.73071897, 0.71241832, - 0.69411767, 0.67581701, 0.63712427, 0.61568633, 0.59738568, - 0.57908502, 0.55843144, 0.53856215, 0.52026149, 0.50196083, - 0.48366016, 0.4653595 , 0.44627454, 0.42483663, 0.40653597, - 0.38823532, 0.36993467, 0.35163401, 0.33019611, 0.31111114, - 0.29281048, 0.27450983, 0.25620917, 0.22692813, 0.19607845, - 0.17777779, 0.15947714, 0.14117648, 0.12235296, 0.1006536 , - 0.08235295, 0.06405229, 0.04575164, 0.02745098, 0.19032622, - 0.25359477, 0.2572549 , 0.26091503, 0.26457516, 0.2682353 , - 0.27189543, 0.27555556, 0.27921569, 0.28287582, 0.28679737, - 0.29411764, 0.29777778, 0.30143791, 0.30509804, 0.30875817, - 0.3124183 , 0.31607843, 0.31973856, 0.32339869, 0.32705882, - 0.33071896, 0.33437909, 0.33803922, 0.34169935, 0.34535948, - 0.34901961, 0.35267974, 0.35633987, 0.36 , 0.36366013, - 0.36732026, 0.37333333, 0.37856209, 0.38222222, 0.38588235, - 0.38954248, 0.39320261, 0.39686275, 0.40052288, 0.40418301, - 0.40784314, 0.41150327, 0.4151634 , 0.41882353, 0.42248366, - 0.42614379, 0.42980392, 0.43346405, 0.43712418, 0.44078431, - 0.44444445, 0.44810458, 0.45254902, 0.45934641, 0.46300654, - 0.46666667, 0.4703268 , 0.47398693, 0.47764706, 0.48130719, - 0.48496732, 0.48862745, 0.49228758, 0.49777777, 0.50352942, - 0.50718956, 0.51084968, 0.51450983, 0.51816994, 0.52183009, - 0.5254902 , 0.52915035, 0.53281046, 0.53647061, 0.54300653, - 0.54771244, 0.55137256, 0.5550327 , 0.55869283, 0.56235295, - 0.56601309, 0.56967321, 0.57333336, 0.57699347, 0.58065362, - 0.58431373, 0.58797388, 0.59163399, 0.59529414, 0.59895426, - 0.6026144 , 0.60627452, 0.60993466, 0.61359479, 0.61725491, - 0.62222224, 0.62849674, 0.63215689, 0.635817 , 0.63947715, - 0.64313726, 0.64679741, 0.65045752, 0.65411767, 0.65777779, - 0.66143793, 0.66509805, 0.66875819, 0.67241832, 0.67607844, - 0.67973858, 0.6833987 , 0.68705885, 0.69071896, 0.69437911, - 0.69803922, 0.70169937, 0.70875816, 0.7129412 , 0.71660132, - 0.72026146, 0.72392158, 0.72758172, 0.73124185, 0.73490197, - 0.73856211, 0.74222223, 0.7466667 , 0.75346406, 0.75712421, - 0.76078431, 0.76444447, 0.76810458, 0.77176473, 0.77542485, - 0.77908499, 0.78274511, 0.78640524, 0.79189544, 0.79764707, - 0.80130721, 0.80496733, 0.80862747, 0.81228759, 0.81594774, - 0.81960784, 0.823268 , 0.82692811, 0.83058826, 0.83424837, - 0.83790852, 0.84156864, 0.84522877, 0.8488889 , 0.85254903, - 0.85620917, 0.85986929, 0.86352943, 0.86718955, 0.87111116, - 0.87843137, 0.88209153, 0.88575164, 0.88941179, 0.8930719 , - 0.89673205, 0.90039217, 0.9040523 , 0.90771243, 0.91137256, - 0.9150327 , 0.91869282, 0.92235296, 0.92601308, 0.92967323, - 0.93333333, 0.93699349, 0.9406536 , 0.94431375, 0.94797386, - 0.95163401, 0.95764708, 0.96287583, 0.96653596, 0.97019609, - 0.97385623, 0.97751635, 0.98117649, 0.98483661, 0.98849676, - 0.99215686]), -array([ 0. , 0.00366013, 0.00732026, 0.01098039, 0.01464052, - 0.01830065, 0.02196078, 0.02562092, 0.02928105, 0.03294118, - 0.0379085 , 0.04418301, 0.04784314, 0.05150327, 0.0551634 , - 0.05882353, 0.06248366, 0.06614379, 0.06980392, 0.07346405, - 0.07712418, 0.08078431, 0.08444444, 0.08810458, 0.09176471, - 0.09542484, 0.09908497, 0.1027451 , 0.10640523, 0.11006536, - 0.11372549, 0.11738562, 0.12444444, 0.12862745, 0.13228758, - 0.13594771, 0.13960784, 0.14326797, 0.14692811, 0.15058824, - 0.15424837, 0.1579085 , 0.16156863, 0.16522876, 0.16888889, - 0.17254902, 0.17620915, 0.17986928, 0.18352941, 0.18718954, - 0.19084967, 0.1945098 , 0.19816994, 0.20366013, 0.20941176, - 0.2130719 , 0.21673203, 0.22039216, 0.22405229, 0.22771242, - 0.23137255, 0.23503268, 0.23869281, 0.24235294, 0.24888888, - 0.25359477, 0.2572549 , 0.26091503, 0.26457516, 0.2682353 , - 0.27189543, 0.27555556, 0.27921569, 0.28287582, 0.28679737, - 0.29411764, 0.29777778, 0.30143791, 0.30509804, 0.30875817, - 0.3124183 , 0.31607843, 0.31973856, 0.32339869, 0.32705882, - 0.33071896, 0.33437909, 0.33803922, 0.34169935, 0.34535948, - 0.34901961, 0.35267974, 0.35633987, 0.36 , 0.36366013, - 0.36732026, 0.37333333, 0.37856209, 0.38222222, 0.38588235, - 0.38954248, 0.39320261, 0.39686275, 0.40052288, 0.40418301, - 0.40784314, 0.41150327, 0.4151634 , 0.41882353, 0.42248366, - 0.42614379, 0.42980392, 0.43346405, 0.43712418, 0.44078431, - 0.44444445, 0.44810458, 0.45254902, 0.45934641, 0.46300654, - 0.46666667, 0.4703268 , 0.47398693, 0.47764706, 0.48130719, - 0.48496732, 0.48862745, 0.49228758, 0.49777777, 0.50352942, - 0.50718956, 0.51084968, 0.51450983, 0.51816994, 0.52183009, - 0.5254902 , 0.52915035, 0.53281046, 0.53647061, 0.54300653, - 0.54771244, 0.55137256, 0.5550327 , 0.55869283, 0.56235295, - 0.56601309, 0.56967321, 0.57333336, 0.57699347, 0.58065362, - 0.58431373, 0.58797388, 0.59163399, 0.59529414, 0.59895426, - 0.6026144 , 0.60627452, 0.60993466, 0.61359479, 0.61725491, - 0.62222224, 0.62849674, 0.63215689, 0.635817 , 0.63947715, - 0.64313726, 0.64679741, 0.65045752, 0.65411767, 0.65777779, - 0.66143793, 0.66509805, 0.66875819, 0.67241832, 0.67607844, - 0.67973858, 0.6833987 , 0.68705885, 0.69071896, 0.69437911, - 0.69803922, 0.70169937, 0.70875816, 0.7129412 , 0.71660132, - 0.72026146, 0.72392158, 0.72758172, 0.73124185, 0.73490197, - 0.73856211, 0.74222223, 0.7466667 , 0.75346406, 0.75712421, - 0.76078431, 0.76444447, 0.76810458, 0.77176473, 0.77542485, - 0.77908499, 0.78274511, 0.78640524, 0.79189544, 0.79764707, - 0.80130721, 0.80496733, 0.80862747, 0.81228759, 0.81594774, - 0.81960784, 0.823268 , 0.82692811, 0.83058826, 0.83424837, - 0.83790852, 0.84156864, 0.84522877, 0.8488889 , 0.85254903, - 0.85620917, 0.85986929, 0.86352943, 0.86718955, 0.87111116, - 0.87843137, 0.88209153, 0.88575164, 0.88941179, 0.8930719 , - 0.89673205, 0.90039217, 0.9040523 , 0.90771243, 0.91137256, - 0.9150327 , 0.91869282, 0.92235296, 0.92601308, 0.92967323, - 0.93333333, 0.93699349, 0.9406536 , 0.94431375, 0.94797386, - 0.95163401, 0.95764708, 0.96287583, 0.96653596, 0.97019609, - 0.97385623, 0.97751635, 0.98117649, 0.98483661, 0.98849676, - 0.99215686]), -array([ 0. , 0.00366013, 0.01071895, 0.01803922, 0.02535948, - 0.03267974, 0.04 , 0.04732026, 0.05464052, 0.06196078, - 0.07189542, 0.08444444, 0.09176471, 0.09908497, 0.10640523, - 0.11372549, 0.12104575, 0.12836601, 0.13568628, 0.14300654, - 0.1503268 , 0.15764706, 0.16496732, 0.17228758, 0.17960784, - 0.18692811, 0.19424837, 0.20156863, 0.20888889, 0.21620915, - 0.22352941, 0.23084967, 0.2449673 , 0.25333333, 0.2606536 , - 0.26797386, 0.27529412, 0.28261438, 0.28993464, 0.2972549 , - 0.30457516, 0.31189543, 0.31921569, 0.32653595, 0.33385621, - 0.34117647, 0.34849673, 0.35581699, 0.36313726, 0.37045752, - 0.37777778, 0.38509804, 0.3924183 , 0.40339869, 0.41490196, - 0.42222222, 0.42954248, 0.43686275, 0.44418301, 0.45150327, - 0.45882353, 0.46614379, 0.47346405, 0.48078431, 0.49385617, - 0.50326797, 0.51058824, 0.5179085 , 0.52522876, 0.53254902, - 0.53986928, 0.54718954, 0.55450981, 0.56183007, 0.56967318, - 0.5843137 , 0.59163399, 0.59895425, 0.60627451, 0.61359477, - 0.62091503, 0.6282353 , 0.63555556, 0.64287582, 0.65019608, - 0.65751634, 0.6648366 , 0.67215686, 0.67947713, 0.68679739, - 0.69411765, 0.70143791, 0.70875817, 0.71607843, 0.72339869, - 0.73071896, 0.74274509, 0.75320262, 0.76052288, 0.76784314, - 0.7751634 , 0.78248366, 0.78980392, 0.79712418, 0.80444445, - 0.81176471, 0.81908497, 0.82640523, 0.83372549, 0.84104575, - 0.84836601, 0.85568628, 0.86300654, 0.8703268 , 0.87764706, - 0.88496732, 0.89228758, 0.90117647, 0.91477124, 0.9220915 , - 0.92941177, 0.93673203, 0.94405229, 0.95137255, 0.95869281, - 0.96601307, 0.97333333, 0.9806536 , 0.99163394, 0.99372556, - 0.979085 , 0.96444453, 0.94901963, 0.93124193, 0.91660131, - 0.90196089, 0.88732027, 0.86928116, 0.85411767, 0.82797401, - 0.80653599, 0.7905883 , 0.77594777, 0.76130724, 0.74509812, - 0.72810461, 0.71346413, 0.69882355, 0.68366025, 0.66562092, - 0.6509805 , 0.63633988, 0.62169944, 0.60392159, 0.58849682, - 0.57385625, 0.55921575, 0.54248372, 0.52601313, 0.51137262, - 0.49019612, 0.46248371, 0.44784313, 0.43320268, 0.41830063, - 0.4000001 , 0.38535946, 0.37071902, 0.35607843, 0.33856216, - 0.32287583, 0.30823533, 0.2935948 , 0.27712421, 0.2603922 , - 0.24575164, 0.23111115, 0.21568625, 0.19790855, 0.18326794, - 0.16862752, 0.15398689, 0.12235305, 0.10509801, 0.09045755, - 0.0732026 , 0.05725492, 0.04261438, 0.02797386, 0.01176472, - 0.00392158, 0.01594769, 0.03372556, 0.06091499, 0.07529416, - 0.08627447, 0.10091509, 0.11555552, 0.13019612, 0.14483659, - 0.15686277, 0.17019608, 0.18483662, 0.20679742, 0.2282353 , - 0.24052291, 0.2551634 , 0.26980398, 0.28444443, 0.29882359, - 0.3098039 , 0.32444452, 0.33908495, 0.35372555, 0.36836601, - 0.38039219, 0.39372551, 0.40836604, 0.42300657, 0.43764708, - 0.45098043, 0.46300654, 0.47764712, 0.49228757, 0.50797404, - 0.53725488, 0.54823538, 0.5626144 , 0.57725499, 0.59189546, - 0.60653602, 0.61882357, 0.63189549, 0.64653601, 0.66117652, - 0.67581707, 0.68941179, 0.70117656, 0.71581701, 0.73045762, - 0.74509804, 0.75973867, 0.77098041, 0.78509813, 0.79973859, - 0.81437916, 0.83607851, 0.8554249 , 0.87006542, 0.88470593, - 0.89934648, 0.9129412 , 0.92470597, 0.93934642, 0.95398703, - 0.96862745]), -array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1.]), - ) - -### hot ### - -color_map_luts['hot'] = \ - ( -array([ 0.0416 , 0.05189484, 0.06218969, 0.07248453, 0.08277938, - 0.09307422, 0.10336906, 0.11366391, 0.12395875, 0.1342536 , - 0.14454844, 0.15484328, 0.16513813, 0.17543297, 0.18572782, - 0.19602266, 0.2063175 , 0.21661235, 0.22690719, 0.23720204, - 0.24749688, 0.25779173, 0.26808657, 0.27838141, 0.28867626, - 0.2989711 , 0.30926595, 0.31956079, 0.32985563, 0.34015048, - 0.35044532, 0.36074017, 0.37103501, 0.38132985, 0.3916247 , - 0.40191954, 0.41221439, 0.42250923, 0.43280407, 0.44309892, - 0.45339376, 0.46368861, 0.47398345, 0.48427829, 0.49457314, - 0.50486798, 0.51516283, 0.52545767, 0.53575251, 0.54604736, - 0.5563422 , 0.56663705, 0.57693189, 0.58722673, 0.59752158, - 0.60781642, 0.61811127, 0.62840611, 0.63870096, 0.6489958 , - 0.65929064, 0.66958549, 0.67988033, 0.69017518, 0.70047002, - 0.71076486, 0.72105971, 0.73135455, 0.7416494 , 0.75194424, - 0.76223908, 0.77253393, 0.78282877, 0.79312362, 0.80341846, - 0.8137133 , 0.82400815, 0.83430299, 0.84459784, 0.85489268, - 0.86518752, 0.87548237, 0.88577721, 0.89607206, 0.9063669 , - 0.91666174, 0.92695659, 0.93725143, 0.94754628, 0.95784112, - 0.96813596, 0.97843081, 0.98872565, 0.9990205 , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , 1. ]), -array([ 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0.00931467, - 0.01960877, 0.02990287, 0.04019697, 0.05049107, 0.06078517, - 0.07107927, 0.08137338, 0.09166748, 0.10196158, 0.11225568, - 0.12254978, 0.13284388, 0.14313798, 0.15343208, 0.16372618, - 0.17402028, 0.18431438, 0.19460849, 0.20490259, 0.21519669, - 0.22549079, 0.23578489, 0.24607899, 0.25637309, 0.26666719, - 0.27696129, 0.28725539, 0.29754949, 0.3078436 , 0.3181377 , - 0.3284318 , 0.3387259 , 0.34902 , 0.3593141 , 0.3696082 , - 0.3799023 , 0.3901964 , 0.4004905 , 0.4107846 , 0.42107871, - 0.43137281, 0.44166691, 0.45196101, 0.46225511, 0.47254921, - 0.48284331, 0.49313741, 0.50343151, 0.51372561, 0.52401971, - 0.53431382, 0.54460792, 0.55490202, 0.56519612, 0.57549022, - 0.58578432, 0.59607842, 0.60637252, 0.61666662, 0.62696072, - 0.63725482, 0.64754893, 0.65784303, 0.66813713, 0.67843123, - 0.68872533, 0.69901943, 0.70931353, 0.71960763, 0.72990173, - 0.74019583, 0.75048993, 0.76078404, 0.77107814, 0.78137224, - 0.79166634, 0.80196044, 0.81225454, 0.82254864, 0.83284274, - 0.84313684, 0.85343094, 0.86372504, 0.87401915, 0.88431325, - 0.89460735, 0.90490145, 0.91519555, 0.92548965, 0.93578375, - 0.94607785, 0.95637195, 0.96666605, 0.97696016, 0.98725426, - 0.99754836, 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , 1. ]), -array([ 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0.01176372, 0.02720491, 0.0426461 , 0.05808729, - 0.07352849, 0.08896968, 0.10441087, 0.11985206, 0.13529325, - 0.15073444, 0.16617564, 0.18161683, 0.19705802, 0.21249921, - 0.2279404 , 0.2433816 , 0.25882279, 0.27426398, 0.28970517, - 0.30514636, 0.32058756, 0.33602875, 0.35146994, 0.36691113, - 0.38235232, 0.39779352, 0.41323471, 0.4286759 , 0.44411709, - 0.45955828, 0.47499947, 0.49044067, 0.50588186, 0.52132305, - 0.53676424, 0.55220543, 0.56764663, 0.58308782, 0.59852901, - 0.6139702 , 0.62941139, 0.64485259, 0.66029378, 0.67573497, - 0.69117616, 0.70661735, 0.72205855, 0.73749974, 0.75294093, - 0.76838212, 0.78382331, 0.79926451, 0.8147057 , 0.83014689, - 0.84558808, 0.86102927, 0.87647046, 0.89191166, 0.90735285, - 0.92279404, 0.93823523, 0.95367642, 0.96911762, 0.98455881, 1. ]), -array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1.]), - ) - -### jet ### - -color_map_luts['jet'] = \ - ( -array([ 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0.00948767, 0.02213789, 0.03478811, 0.04743833, 0.06008855, - 0.07273877, 0.08538899, 0.09803922, 0.11068944, 0.12333966, - 0.13598988, 0.1486401 , 0.16129032, 0.17394054, 0.18659077, - 0.19924099, 0.21189121, 0.22454143, 0.23719165, 0.24984187, - 0.26249209, 0.27514231, 0.28779254, 0.30044276, 0.31309298, - 0.3257432 , 0.33839342, 0.35104364, 0.36369386, 0.37634409, - 0.38899431, 0.40164453, 0.41429475, 0.42694497, 0.43959519, - 0.45224541, 0.46489564, 0.47754586, 0.49019608, 0.5028463 , - 0.51549652, 0.52814674, 0.54079696, 0.55344719, 0.56609741, - 0.57874763, 0.59139785, 0.60404807, 0.61669829, 0.62934851, - 0.64199873, 0.65464896, 0.66729918, 0.6799494 , 0.69259962, - 0.70524984, 0.71790006, 0.73055028, 0.74320051, 0.75585073, - 0.76850095, 0.78115117, 0.79380139, 0.80645161, 0.81910183, - 0.83175206, 0.84440228, 0.8570525 , 0.86970272, 0.88235294, - 0.89500316, 0.90765338, 0.92030361, 0.93295383, 0.94560405, - 0.95825427, 0.97090449, 0.98355471, 0.99620493, 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 0.99910873, 0.98128342, 0.96345811, - 0.9456328 , 0.92780749, 0.90998217, 0.89215686, 0.87433155, - 0.85650624, 0.83868093, 0.82085561, 0.8030303 , 0.78520499, - 0.76737968, 0.74955437, 0.73172906, 0.71390374, 0.69607843, - 0.67825312, 0.66042781, 0.6426025 , 0.62477718, 0.60695187, - 0.58912656, 0.57130125, 0.55347594, 0.53565062, 0.51782531, - 0.5 ]), -array([ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 1.96078431e-03, - 1.76470588e-02, 3.33333333e-02, 4.90196078e-02, - 6.47058824e-02, 8.03921569e-02, 9.60784314e-02, - 1.11764706e-01, 1.27450980e-01, 1.43137255e-01, - 1.58823529e-01, 1.74509804e-01, 1.90196078e-01, - 2.05882353e-01, 2.21568627e-01, 2.37254902e-01, - 2.52941176e-01, 2.68627451e-01, 2.84313725e-01, - 3.00000000e-01, 3.15686275e-01, 3.31372549e-01, - 3.47058824e-01, 3.62745098e-01, 3.78431373e-01, - 3.94117647e-01, 4.09803922e-01, 4.25490196e-01, - 4.41176471e-01, 4.56862745e-01, 4.72549020e-01, - 4.88235294e-01, 5.03921569e-01, 5.19607843e-01, - 5.35294118e-01, 5.50980392e-01, 5.66666667e-01, - 5.82352941e-01, 5.98039216e-01, 6.13725490e-01, - 6.29411765e-01, 6.45098039e-01, 6.60784314e-01, - 6.76470588e-01, 6.92156863e-01, 7.07843137e-01, - 7.23529412e-01, 7.39215686e-01, 7.54901961e-01, - 7.70588235e-01, 7.86274510e-01, 8.01960784e-01, - 8.17647059e-01, 8.33333333e-01, 8.49019608e-01, - 8.64705882e-01, 8.80392157e-01, 8.96078431e-01, - 9.11764706e-01, 9.27450980e-01, 9.43137255e-01, - 9.58823529e-01, 9.74509804e-01, 9.90196078e-01, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, - 1.00000000e+00, 1.00000000e+00, 9.88380537e-01, - 9.73856209e-01, 9.59331881e-01, 9.44807553e-01, - 9.30283224e-01, 9.15758896e-01, 9.01234568e-01, - 8.86710240e-01, 8.72185911e-01, 8.57661583e-01, - 8.43137255e-01, 8.28612927e-01, 8.14088598e-01, - 7.99564270e-01, 7.85039942e-01, 7.70515614e-01, - 7.55991285e-01, 7.41466957e-01, 7.26942629e-01, - 7.12418301e-01, 6.97893972e-01, 6.83369644e-01, - 6.68845316e-01, 6.54320988e-01, 6.39796659e-01, - 6.25272331e-01, 6.10748003e-01, 5.96223675e-01, - 5.81699346e-01, 5.67175018e-01, 5.52650690e-01, - 5.38126362e-01, 5.23602033e-01, 5.09077705e-01, - 4.94553377e-01, 4.80029049e-01, 4.65504720e-01, - 4.50980392e-01, 4.36456064e-01, 4.21931736e-01, - 4.07407407e-01, 3.92883079e-01, 3.78358751e-01, - 3.63834423e-01, 3.49310094e-01, 3.34785766e-01, - 3.20261438e-01, 3.05737110e-01, 2.91212781e-01, - 2.76688453e-01, 2.62164125e-01, 2.47639797e-01, - 2.33115468e-01, 2.18591140e-01, 2.04066812e-01, - 1.89542484e-01, 1.75018155e-01, 1.60493827e-01, - 1.45969499e-01, 1.31445171e-01, 1.16920842e-01, - 1.02396514e-01, 8.78721859e-02, 7.33478577e-02, - 5.88235294e-02, 4.42992012e-02, 2.97748729e-02, - 1.52505447e-02, 7.26216412e-04, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, - 0.00000000e+00]), -array([ 0.5 , 0.51782531, 0.53565062, 0.55347594, 0.57130125, - 0.58912656, 0.60695187, 0.62477718, 0.6426025 , 0.66042781, - 0.67825312, 0.69607843, 0.71390374, 0.73172906, 0.74955437, - 0.76737968, 0.78520499, 0.8030303 , 0.82085561, 0.83868093, - 0.85650624, 0.87433155, 0.89215686, 0.90998217, 0.92780749, - 0.9456328 , 0.96345811, 0.98128342, 0.99910873, 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 1. , 1. , 1. , - 1. , 1. , 0.99620493, 0.98355471, 0.97090449, - 0.95825427, 0.94560405, 0.93295383, 0.92030361, 0.90765338, - 0.89500316, 0.88235294, 0.86970272, 0.8570525 , 0.84440228, - 0.83175206, 0.81910183, 0.80645161, 0.79380139, 0.78115117, - 0.76850095, 0.75585073, 0.74320051, 0.73055028, 0.71790006, - 0.70524984, 0.69259962, 0.6799494 , 0.66729918, 0.65464896, - 0.64199873, 0.62934851, 0.61669829, 0.60404807, 0.59139785, - 0.57874763, 0.56609741, 0.55344719, 0.54079696, 0.52814674, - 0.51549652, 0.5028463 , 0.49019608, 0.47754586, 0.46489564, - 0.45224541, 0.43959519, 0.42694497, 0.41429475, 0.40164453, - 0.38899431, 0.37634409, 0.36369386, 0.35104364, 0.33839342, - 0.3257432 , 0.31309298, 0.30044276, 0.28779254, 0.27514231, - 0.26249209, 0.24984187, 0.23719165, 0.22454143, 0.21189121, - 0.19924099, 0.18659077, 0.17394054, 0.16129032, 0.1486401 , - 0.13598988, 0.12333966, 0.11068944, 0.09803922, 0.08538899, - 0.07273877, 0.06008855, 0.04743833, 0.03478811, 0.02213789, - 0.00948767, 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , - 0. , 0. , 0. , 0. , 0. , 0. ]), -array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., - 1., 1., 1., 1., 1., 1., 1., 1., 1.]), - ) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/clump_tools.py --- a/yt/extensions/clump_tools.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -""" -Clump tools for use with the yt Clump object - -Author: David Collins -Affiliation: Center for Astrophysics and Space Sciences, U C San Diego -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 David Collins. 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 . -""" - -import numpy as na -nar = na.array - -counter = 0 -def recursive_all_clumps(clump,list,level,parentnumber): - """A recursive function to flatten the hierarchy in *clump*. - Not to be called directly: please call return_all_clumps, below.""" - global counter - counter += 1 - clump.number = counter - clump.parentnumber = parentnumber - counter += 1 - list.append(clump) - clump.level = level - if clump.children != None: - for child in clump.children: - x = recursive_all_clumps(child,list,level+1,clump.number) - return list - -def return_all_clumps(clump): - """Flatten the hierarchy defined by *clump*. - Additionally adds three variables to the clump: - level = depth of hierarchy - number = index of clump in the final array - parentnumber = index of this clumps parent - - """ - global counter - counter = 0 - list = [] - level = 0 - clump.level = level - parentnumber=-1 - recursive_all_clumps(clump,list,level,parentnumber) - return list - -def return_bottom_clumps(clump,dbg=0): - """Recursively return clumps at the bottom of the hierarchy. - This gives a list of clumps similar to what one would get from a CLUMPFIND routine""" - global counter - counter = 0 - list = [] - level = 0 - recursive_bottom_clumps(clump,list,dbg,level) - return list -def recursive_bottom_clumps(clump,clump_list, dbg = 0,level=0): - """Loops over a list of clumps (clumps) and fills clump_list with the bottom most. - Recursive. Prints the level and the number of cores to the screen.""" - - global counter - if dbg > 0: - print tabs(level), "l =",level, "n_core",counter - - if ((clump.children is None) or (len(clump.children) == 0)): - counter += 1 - clump_list.append( clump ) - else: - for child in clump.children: - recursive_bottom_clumps(child,clump_list,dbg=dbg,level=level+1) - -def clump_list_sort(clump_list): - """Returns a copy of clump_list, sorted by ascending minimum density. - This eliminates overlap when passing to yt.raven.ClumpContourCallback""" - minDensity = [c['Density'].min() for c in clump_list] - - args = na.argsort(minDensity) - list = nar(clump_list)[args] - reverse = range(list.size-1,-1,-1) - return list[reverse] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/coordinate_transforms.py --- a/yt/extensions/coordinate_transforms.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -""" -Transformations between coordinate systems - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Author: JS Oishi -Organization: UC Berkeley -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 Matthew Turk, J. S. Oishi. 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 . -""" - -from yt.mods import * -from yt.funcs import * - -def spherical_regrid(pf, nr, ntheta, nphi, rmax, fields, - center=None, smoothed=True): - """ - This function takes a parameter file (*pf*) along with the *nr*, *ntheta* - and *nphi* points to generate out to *rmax*, and it grids *fields* onto - those points and returns a dict. *center* if supplied will be the center, - otherwise the most dense point will be chosen. *smoothed* governs whether - regular covering grids or smoothed covering grids will be used. - """ - mylog.warning("This code may produce some artifacts of interpolation") - mylog.warning("See yt/extensions/coordinate_transforms.py for plotting information") - if center is None: center = pf.h.find_max("Density")[1] - fields = ensure_list(fields) - r,theta,phi = na.mgrid[0:rmax:nr*1j, - 0:na.pi:ntheta*1j, - 0:2*na.pi:nphi*1j] - new_grid = dict(r=r, theta=theta, phi=phi) - new_grid['x'] = r*na.sin(theta)*na.cos(phi) + center[0] - new_grid['y'] = r*na.sin(theta)*na.sin(phi) + center[1] - new_grid['z'] = r*na.cos(theta) + center[2] - sphere = pf.h.sphere(center, rmax) - return arbitrary_regrid(new_grid, sphere, fields, smoothed) - -def arbitrary_regrid(new_grid, data_source, fields, smoothed=True): - """ - This function accepts a dict of points 'x', 'y' and 'z' and a data source - from which to interpolate new points, along with a list of fields it needs - to regrid onto those xyz points. It then returns interpolated points. - This has not been well-tested other than for regular spherical regridding. - """ - fields = ensure_list(fields) - new_grid['handled'] = na.zeros(new_grid['x'].shape, dtype='bool') - for field in fields: - new_grid[field] = na.zeros(new_grid['x'].shape, dtype='float64') - grid_order = na.argsort(data_source.gridLevels) - ng = len(data_source._grids) - - for i,grid in enumerate(data_source._grids[grid_order][::-1]): - mylog.info("Regridding grid % 4i / % 4i (%s - %s)", i, ng, grid.id, grid.Level) - cg = grid.retrieve_ghost_zones(1, fields, smoothed=smoothed) - - # makes x0,x1,y0,y1,z0,z1 - bounds = na.concatenate(zip(cg.left_edge, cg.right_edge)) - - - # Now we figure out which of our points are inside this grid - # Note that we're only looking at the grid, not the grid-with-ghost-zones - point_ind = na.ones(new_grid['handled'].shape, dtype='bool') # everything at first - for i,ax in enumerate('xyz'): # i = 0,1,2 ; ax = x, y, z - # &= does a logical_and on the array - point_ind &= ( ( grid.LeftEdge[i] <= new_grid[ax] ) - & ( new_grid[ax] <= grid.RightEdge[i] ) ) - point_ind &= (new_grid['handled'] == False) # only want unhandled points - - # If we don't have any, we can just leave - if point_ind.sum() == 0: continue - - # because of the funky way the interpolator takes points, we have to make a - # new dict of just the points inside this grid - point_grid = {'x' : new_grid['x'][point_ind], - 'y' : new_grid['y'][point_ind], - 'z' : new_grid['z'][point_ind]} - - # Now we know which of the points in new_grid are inside this grid - for field in fields: - interpolator = lagos.TrilinearFieldInterpolator( - cg[field],bounds,['x','y','z']) - new_grid[field][point_ind] = interpolator(point_grid) - - new_grid['handled'][point_ind] = True - - mylog.info("Finished with %s dangling points", - new_grid['handled'].size - new_grid['handled'].sum()) - - return new_grid - -""" -# The following will work to plot through different slices: - -import pylab -for i in range(n_theta): - print "Doing % 3i / % 3i" % (i, n_theta) - pylab.clf() - ax=pylab.subplot(1,1,1, projection="polar", aspect=1.) - ax.pcolormesh(phi[:,i,:], r[:,i,:], - na.log10(sph_grid[field][:,i,:])) - pylab.savefig("polar/latitude_%03i.png" % i) - -for i in range(n_phi): - print "Doing % 3i / % 3i" % (i, n_phi) - pylab.clf() - ax=pylab.subplot(1,1,1, projection="polar", aspect=1.) - ax.pcolormesh(theta[:,:,i], r[:,:,i], - na.log10(sph_grid[field][:,:,i])) - pylab.savefig("polar/longitude_%03i.png" % i) -""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/disk_analysis.py --- a/yt/extensions/disk_analysis.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -""" -A set of utilities for analyzing disks - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.mods import * - -class StackedDiskImage(object): - def __init__(self, pf, center, norm_vec, thickness, width, - nslices = 100, buff_size=(800,800)): - """ - This class implements an AMR data object that will stack up - oblique-slices to generate an image along an arbitrary axis. - """ - self.data = {} - self.pf = pf - self.center = na.array(center) - self.norm_vec = norm_vec/na.sqrt(na.dot(norm_vec,norm_vec)) - self.thickness = thickness - self.width = width - self.nslices = nslices - self.buff_size = buff_size - - def __getitem__(self, key): - if key not in self.data: - self[key] = self.get_data(key) - return self.data[key] - - def __delitem__(self, key): - del self.data[key] - - def __setitem__(self, key, val): - self.data[key] = val - - def __iter__(self): - kk = self.data.keys() - for key in kk: yield key - - def get_data(self, field): - # Needs to be rewritten to get multiple fields - buffer = na.zeros(self.buff_size, dtype='float64') - wsp = (-self.width/2.0, self.width/2.0, - -self.width/2.0, self.width/2.0) - for d in na.mgrid[-self.thickness/2.0:self.thickness/2.0:self.nslices*1j]: - print d, self.thickness/2.0 - center = self.center + self.norm_vec*d - cut = self.pf.h.cutting(self.norm_vec, center) - buff = raven.ObliqueFixedResolutionBuffer( - cut, wsp, self.buff_size) - buffer += buff[field] - return buffer diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_simulation.py --- a/yt/extensions/enzo_simulation.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,572 +0,0 @@ -from yt.logger import lagosLogger as mylog -import yt.lagos as lagos -import yt.funcs as funcs -import numpy as na -import glob -import os - -dt_Tolerance = 1e-3 - -class EnzoSimulation(object): - """ - Super class for performing the same operation over all data dumps in - a simulation from one redshift to another. - """ - def __init__(self, EnzoParameterFile, initial_time=None, final_time=None, initial_redshift=None, final_redshift=None, - links=False, enzo_parameters=None, get_time_outputs=True, get_redshift_outputs=True, get_available_data=False, - get_data_by_force=False): - """ - Initialize an EnzoSimulation object. - :param initial_time (float): the initial time in code units for the dataset list. Default: None. - :param final_time (float): the final time in code units for the dataset list. Default: None. - :param initial_redshift (float): the initial (highest) redshift for the dataset list. Only for - cosmological simulations. Default: None. - :param final_redshift (float): the final (lowest) redshift for the dataset list. Only for cosmological - simulations. Default: None. - :param links (bool): if True, each entry in the dataset list will contain entries, previous and next, that - point to the previous and next entries on the dataset list. Default: False. - :param enzo_parameters (dict): a dictionary specify additional parameters to be retrieved from the - parameter file. The format should be the name of the parameter as the key and the variable type as - the value. For example, {'CosmologyComovingBoxSize':float}. All parameter values will be stored in - the dictionary attribute, enzoParameters. Default: None. - :param get_time_outputs (bool): if False, the time datasets, specified in Enzo with the dtDataDump, will not - be added to the dataset list. Default: True. - :param get_redshift_outputs (bool): if False, the redshift datasets will not be added to the dataset list. Default: True. - :param get_available_data (bool): if True, only datasets that are found to exist at the file path are added - to the list. Default: False. - :param get_data_by_force (bool): if True, time data dumps are not calculated using dtDataDump. Instead, the - the working directory is searched for directories that match the datadumpname keyword. Each dataset - is loaded up to get the time and redshift manually. This is useful with collapse simulations that use - OutputFirstTimeAtLevel or with simulations that make outputs based on cycle numbers. Default: False. - """ - self.EnzoParameterFile = EnzoParameterFile - self.enzoParameters = {} - self.redshift_outputs = [] - self.allOutputs = [] - self.InitialTime = initial_time - self.FinalTime = final_time - self.InitialRedshift = initial_redshift - self.FinalRedshift = final_redshift - self.links = links - self.get_time_outputs = get_time_outputs - self.get_redshift_outputs = get_redshift_outputs - self.get_available_data = get_available_data - - # Add any extra parameters to parameter dict. - if enzo_parameters is None: enzo_parameters = {} - EnzoParameterDict.update(enzo_parameters) - - # Set some parameter defaults. - self._set_parameter_defaults() - - # Read parameters. - self._read_enzo_parameter_file() - - # Get all the appropriate datasets. - self._get_all_outputs(brute_force=get_data_by_force) - - def _calculate_redshift_dump_times(self): - "Calculates time from redshift of redshift dumps." - - for output in self.redshift_outputs: - output['time'] = self.enzo_cosmology.ComputeTimeFromRedshift(output['redshift']) / \ - self.enzo_cosmology.TimeUnits - - def _calculate_time_dumps(self): - "Calculates time dumps and their redshifts if cosmological." - - if self.enzoParameters['dtDataDump'] <= 0.0: return [] - time_outputs = [] - - index = 0 - current_time = self.SimulationInitialTime - while (current_time <= self.FinalTime) or \ - (abs(self.FinalTime - current_time) / self.FinalTime) < dt_Tolerance: - filename = "%s/%s%04d/%s%04d" % (self.enzoParameters['GlobalDir'], - self.enzoParameters['DataDumpDir'],index, - self.enzoParameters['DataDumpName'],index) - - output = {'index':index,'filename':filename,'time':current_time} - if self.enzoParameters['ComovingCoordinates']: - t = self.enzo_cosmology.InitialTime + (self.enzoParameters['dtDataDump'] * self.enzo_cosmology.TimeUnits * index) - output['redshift'] = self.enzo_cosmology.ComputeRedshiftFromTime(t) - - if not self.get_available_data or os.path.exists(filename): - time_outputs.append(output) - - current_time += self.enzoParameters['dtDataDump'] - index += 1 - - return time_outputs - - def _combine_data_outputs(self, brute_force=False): - "Combines redshift and time data into one sorted list." - - # If True, get time dumps just by looking through the working directory. - if brute_force: - time_outputs = self._get_outputs_by_force() - - # Calculate time dumps based on dtDataDump - elif self.enzoParameters.has_key('dtDataDump') and self.get_time_outputs: - time_outputs = self._calculate_time_dumps() - - # Calculate times for redshift dumps. - if self.enzoParameters['ComovingCoordinates'] and self.get_redshift_outputs: - self._calculate_redshift_dump_times() - else: - self.redshift_outputs = [] - - self.allOutputs = self.redshift_outputs + time_outputs - self.allOutputs.sort(key=lambda obj:obj['time']) - - start_index = None - end_index = None - - # Add links to next and previous dataset to each entry. - for q in range(len(self.allOutputs)): - if self.allOutputs[q].has_key('index'): del self.allOutputs[q]['index'] - - if start_index is None: - if self.allOutputs[q]['time'] >= self.InitialTime or \ - abs(self.allOutputs[q]['time'] - self.InitialTime) < \ - self.allOutputs[q]['time'] * dt_Tolerance: - start_index = q - - if end_index is None: - if self.allOutputs[q]['time'] > self.FinalTime: - end_index = q - 1 - if abs(self.allOutputs[q]['time'] - self.FinalTime) < \ - self.allOutputs[q]['time'] * dt_Tolerance: - end_index = q - if q == len(self.allOutputs) - 1: - end_index = q - - for q in range(len(self.allOutputs)): - if self.links and start_index is not None: - if q <= start_index: - self.allOutputs[q]['previous'] = None - else: - self.allOutputs[q]['previous'] = self.allOutputs[q-1] - - if q >= end_index: - self.allOutputs[q]['next'] = None - else: - self.allOutputs[q]['next'] = self.allOutputs[q+1] - - del self.redshift_outputs - - if end_index is None: - end_index = len(self.allOutputs)-1 - - self.allOutputs = self.allOutputs[start_index:end_index+1] - mylog.info("Loaded %s total data outputs." % len(self.allOutputs)) - - def _get_all_outputs(self, brute_force=False): - """ - Get all the datasets in the time/redshift interval requested, or search - the data directory for potential datasets. - """ - - # Check for sufficient starting/ending parameters. - if self.InitialTime is None and self.InitialRedshift is None: - if self.enzoParameters['ComovingCoordinates'] and \ - 'CosmologyInitialRedshift' in self.enzoParameters: - self.InitialRedshift = self.enzoParameters['CosmologyInitialRedshift'] - elif 'InitialTime' in self.enzoParameters: - self.InitialTime = self.enzoParameters['InitialTime'] - else: - mylog.error("Couldn't find parameter for initial time or redshift from parameter file.") - return None - - if self.FinalTime is None and self.FinalRedshift is None: - if self.enzoParameters['ComovingCoordinates'] and \ - 'CosmologyFinalRedshift' in self.enzoParameters: - self.FinalRedshift = self.enzoParameters['CosmologyFinalRedshift'] - elif 'StopTime' in self.enzoParameters: - self.FinalTime = self.enzoParameters['StopTime'] - else: - mylog.error("Couldn't find parameter for final time or redshift from parameter file.") - return None - - # Convert initial/final redshifts to times. - if self.enzoParameters['ComovingCoordinates']: - # Instantiate a cosmology calculator. - self.cosmology = lagos.Cosmology(HubbleConstantNow = - (100.0 * self.enzoParameters['CosmologyHubbleConstantNow']), - OmegaMatterNow = self.enzoParameters['CosmologyOmegaMatterNow'], - OmegaLambdaNow = self.enzoParameters['CosmologyOmegaLambdaNow']) - - # Instantiate EnzoCosmology object for units and time conversions. - self.enzo_cosmology = lagos.EnzoCosmology(HubbleConstantNow = - (100.0 * self.enzoParameters['CosmologyHubbleConstantNow']), - OmegaMatterNow = self.enzoParameters['CosmologyOmegaMatterNow'], - OmegaLambdaNow = self.enzoParameters['CosmologyOmegaLambdaNow'], - InitialRedshift = self.enzoParameters['CosmologyInitialRedshift']) - if self.InitialRedshift is not None: - self.InitialTime = self.enzo_cosmology.ComputeTimeFromRedshift(self.InitialRedshift) / \ - self.enzo_cosmology.TimeUnits - if self.FinalRedshift is not None: - self.FinalTime = self.enzo_cosmology.ComputeTimeFromRedshift(self.FinalRedshift) / \ - self.enzo_cosmology.TimeUnits - - # Get initial time of simulation. - if self.enzoParameters['ComovingCoordinates'] and \ - 'CosmologyInitialRedshift' in self.enzoParameters: - self.SimulationInitialTime = self.enzo_cosmology.InitialTime / self.enzo_cosmology.TimeUnits - elif 'InitialTime' in self.enzoParameters: - self.SimulationInitialTime = self.enzoParameters['InitialTime'] - else: - self.SimulationInitialTime = 0.0 - - # Combine all data dumps in to ordered list. - self._combine_data_outputs(brute_force=brute_force) - - def _get_outputs_by_force(self): - """ - Search for directories matching the data dump keywords. - If found, get dataset times by brute force py opening the pf. - """ - - # look for time dumps. - potential_time_outputs = glob.glob("%s/%s*" % (self.enzoParameters['GlobalDir'], - self.enzoParameters['DataDumpDir'])) - time_outputs = [] - mylog.info("Checking validity of %d potential time dumps." % - len(potential_time_outputs)) - - for output in potential_time_outputs: - index = output[output.find(self.enzoParameters['DataDumpDir']) + - len(self.enzoParameters['DataDumpDir']):] - filename = "%s/%s%s/%s%s" % (self.enzoParameters['GlobalDir'], - self.enzoParameters['DataDumpDir'], index, - self.enzoParameters['DataDumpName'], index) - if os.path.exists(filename): - pf = lagos.EnzoStaticOutput(filename) - if pf is not None: - time_outputs.append({'filename': filename, 'time': pf['InitialTime']}) - if self.enzoParameters['ComovingCoordinates']: - time_outputs[-1]['redshift'] = pf['CosmologyCurrentRedshift'] - del pf - mylog.info("Located %d time dumps." % len(time_outputs)) - return time_outputs - - def _read_enzo_parameter_file(self): - "Reads an Enzo parameter file looking for cosmology and output parameters." - lines = open(self.EnzoParameterFile).readlines() - for line in lines: - if line.find("#") >= 0: # Keep the commented lines - line=line[:line.find("#")] - line=line.strip() - if len(line) < 2: - continue - try: - param, vals = map(str,line.split("=")) - param = param.strip() - vals = vals.strip().split("#", 1)[0].split("//", 1)[0] - except ValueError: - continue - if EnzoParameterDict.has_key(param): - t = map(EnzoParameterDict[param], vals.split()) - if len(t) == 1: - self.enzoParameters[param] = t[0] - else: - self.enzoParameters[param] = t - elif param.startswith("CosmologyOutputRedshift["): - index = param[param.find("[")+1:param.find("]")] - self.redshift_outputs.append({'index':int(index), 'redshift':float(vals)}) - - # Add filenames to redshift outputs. - tempRedshiftList = [] - for output in self.redshift_outputs: - output["filename"] = "%s/%s%04d/%s%04d" % (self.enzoParameters['GlobalDir'], - self.enzoParameters['RedshiftDumpDir'],output['index'], - self.enzoParameters['RedshiftDumpName'],output['index']) - if not self.get_available_data or os.path.exists(output["filename"]): - tempRedshiftList.append(output) - self.redshift_outputs = tempRedshiftList - del tempRedshiftList - - def _set_parameter_defaults(self): - "Set some default parameters to avoid problems if they are not in the parameter file." - self.enzoParameters['GlobalDir'] = "." - self.enzoParameters['RedshiftDumpName'] = "RedshiftOutput" - self.enzoParameters['RedshiftDumpDir'] = "RD" - self.enzoParameters['DataDumpName'] = "data" - self.enzoParameters['DataDumpDir'] = "DD" - self.enzoParameters['ComovingCoordinates'] = 0 - - def imagine_minimal_splice(self, initial_redshift, final_redshift, decimals=3, filename=None, - redshift_output_string='CosmologyOutputRedshift', start_index=0): - """ - Create imaginary list of redshift outputs to maximally span a redshift interval. - :param decimals (int): The decimal place to which the output redshift will be rounded. - If the decimal place in question is nonzero, the redshift will be rounded up to - ensure continuity of the splice. Default: 3. - :param filename (str): If provided, a file will be written with the redshift outputs in - the form in which they should be given in the enzo parameter file. Default: None. - :param redshift_output_string (str): The parameter accompanying the redshift outputs in the - enzo parameter file. Default: "CosmologyOutputRedshift". - :param start_index (int): The index of the first redshift output. Default: 0. - """ - - z = initial_redshift - outputs = [] - - while z > final_redshift: - rounded = na.round(z, decimals=decimals) - if rounded - z < 0: - rounded += na.power(10.0,(-1.0*decimals)) - z = rounded - - deltaz_max = __deltaz_forward(self.cosmology, z, self.enzoParameters['CosmologyComovingBoxSize']) - outputs.append({'redshift': z, 'deltazMax': deltaz_max}) - z -= deltaz_max - - mylog.info("imagine_maximal_splice: Needed %d data dumps to get from z = %f to %f." % - (len(outputs), initial_redshift, final_redshift)) - - if filename is not None: - mylog.info("Writing redshift dump list to %s." % filename) - f = open(filename,'w') - for q, output in enumerate(outputs): - z_string = "%%s[%%d] = %%.%df" % decimals - f.write(("%s[%d] = %." + str(decimals) + "f\n") % (redshift_output_string, (q+start_index), output['redshift'])) - f.close() - - return outputs - - def create_cosmology_splice(self, minimal=True, deltaz_min=0.0, initial_redshift=None, final_redshift=None): - """ - Create list of datasets to be used for LightCones or LightRays. - :param minimal (bool): if True, the minimum number of datasets is used to connect the initial and final - redshift. If false, the list will contain as many entries as possible within the redshift - interval. Default: True. - :param deltaz_min (float): specifies the minimum delta z between consecutive datasets in the returned - list. Default: 0.0. - :param initial_redshift (float): the initial (highest) redshift in the cosmology splice list. If none - given, the highest redshift dataset present will be used. Default: None. - :param final_redshift (float): the final (lowest) redshift in the cosmology splice list. If none given, - the lowest redshift dataset present will be used. Default: None. - """ - - if initial_redshift is None: initial_redshift = self.InitialRedshift - if final_redshift is None: final_redshift = self.FinalRedshift - - # Calculate maximum delta z for each data dump. - self._calculate_deltaz_max() - - # Calculate minimum delta z for each data dump. - self._calculate_deltaz_min(deltaz_min=deltaz_min) - - cosmology_splice = [] - - # Use minimum number of datasets to go from z_i to z_f. - if minimal: - - z_Tolerance = 1e-3 - z = initial_redshift - - # fill redshift space with datasets - while ((z > final_redshift) and - (na.fabs(z - final_redshift) > z_Tolerance)): - - # For first data dump, choose closest to desired redshift. - if (len(cosmology_splice) == 0): - # Sort data outputs by proximity to current redsfhit. - self.allOutputs.sort(key=lambda obj:na.fabs(z - obj['redshift'])) - cosmology_splice.append(self.allOutputs[0]) - - # Move forward from last slice in stack until z > z_max. - else: - current_slice = cosmology_splice[-1] - while current_slice['next'] is not None and \ - (z < current_slice['next']['redshift'] or \ - na.abs(z - current_slice['next']['redshift']) < z_Tolerance): - current_slice = current_slice['next'] - - if current_slice is cosmology_splice[-1]: - final_redshift = cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax'] - mylog.error("Cosmology splice incomplete due to insufficient data outputs.") - break - else: - cosmology_splice.append(current_slice) - - z = cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax'] - - # Make light ray using maximum number of datasets (minimum spacing). - else: - # Sort data outputs by proximity to current redsfhit. - self.allOutputs.sort(key=lambda obj:na.fabs(initial_redshift - obj['redshift'])) - # For first data dump, choose closest to desired redshift. - cosmology_splice.append(self.allOutputs[0]) - - nextOutput = cosmology_splice[-1]['next'] - while (nextOutput is not None): - if (nextOutput['redshift'] <= final_redshift): - break - if ((cosmology_splice[-1]['redshift'] - nextOutput['redshift']) > cosmology_splice[-1]['deltazMin']): - cosmology_splice.append(nextOutput) - nextOutput = nextOutput['next'] - if (cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax']) > final_redshift: - mylog.error("Cosmology splice incomplete due to insufficient data outputs.") - final_redshift = cosmology_splice[-1]['redshift'] - cosmology_splice[-1]['deltazMax'] - - mylog.info("create_cosmology_splice: Used %d data dumps to get from z = %f to %f." % - (len(cosmology_splice),initial_redshift,final_redshift)) - - self.allOutputs.sort(key=lambda obj: obj['time']) - return cosmology_splice - - def get_data_by_redshift(self, redshifts, tolerance=None): - """ - : param redshifts: a list of redshifts. - : tolerance: if not None, do not return a dataset unless the redshift is within the tolerance value. - Get datasets for a list of redshifts. - """ - - redshifts = funcs.ensure_list(redshifts) - my_datasets = [] - for redshift in redshifts: - self.allOutputs.sort(key=lambda obj:na.fabs(redshift - obj['redshift'])) - if (tolerance is None or na.abs(redshift - self.allOutputs[0]['redshift']) <= tolerance) \ - and self.allOutputs[0] not in my_datasets: - my_datasets.append(self.allOutputs[0]) - else: - mylog.error("No dataset added for z = %f." % redshift) - - self.allOutputs.sort(key=lambda obj: obj['time']) - return my_datasets - - def get_data_by_time(self, times, tolerance=None): - """ - : param redshifts: a list of times. - : tolerance: if not None, do not return a dataset unless the redshift is within the tolerance value. - Get datasets for a list of times. - """ - - times = funcs.ensure_list(times) - my_datasets = [] - for my_time in times: - self.allOutputs.sort(key=lambda obj:na.fabs(my_time - obj['time'])) - if (tolerance is None or na.abs(my_time - self.allOutputs[0]['time']) <= tolerance) \ - and self.allOutputs[0] not in my_datasets: - my_datasets.append(self.allOutputs[0]) - else: - mylog.error("No dataset added for z = %f." % my_time) - - self.allOutputs.sort(key=lambda obj: obj['time']) - return my_datasets - - def _calculate_deltaz_max(self): - "Calculate delta z that corresponds to full box length going from z to (z - delta z)." - - d_Tolerance = 1e-4 - max_Iterations = 100 - - targetDistance = self.enzoParameters['CosmologyComovingBoxSize'] - - for output in self.allOutputs: - z = output['redshift'] - - # Calculate delta z that corresponds to the length of the box at a given redshift. - # Use Newton's method to calculate solution. - z1 = z - z2 = z1 - 0.1 # just an initial guess - distance1 = 0.0 - iteration = 1 - - # Convert comoving radial distance into Mpc / h, since that's how box size is stored. - distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] - - while ((na.fabs(distance2-targetDistance)/distance2) > d_Tolerance): - m = (distance2 - distance1) / (z2 - z1) - z1 = z2 - distance1 = distance2 - z2 = ((targetDistance - distance2) / m) + z2 - distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] - iteration += 1 - if (iteration > max_Iterations): - mylog.error("calculate_deltaz_max: Warning - max iterations exceeded for z = %f (delta z = %f)." % - (z,na.fabs(z2-z))) - break - output['deltazMax'] = na.fabs(z2-z) - - def _calculate_deltaz_min(self, deltaz_min=0.0): - "Calculate delta z that corresponds to a single top grid pixel going from z to (z - delta z)." - - d_Tolerance = 1e-4 - max_Iterations = 100 - - targetDistance = self.enzoParameters['CosmologyComovingBoxSize'] / self.enzoParameters['TopGridDimensions'][0] - - for output in self.allOutputs: - z = output['redshift'] - - # Calculate delta z that corresponds to the length of a top grid pixel at a given redshift. - # Use Newton's method to calculate solution. - z1 = z - z2 = z1 - 0.01 # just an initial guess - distance1 = 0.0 - iteration = 1 - - # Convert comoving radial distance into Mpc / h, since that's how box size is stored. - distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] - - while ((na.fabs(distance2 - targetDistance) / distance2) > d_Tolerance): - m = (distance2 - distance1) / (z2 - z1) - z1 = z2 - distance1 = distance2 - z2 = ((targetDistance - distance2) / m) + z2 - distance2 = self.cosmology.ComovingRadialDistance(z2,z) * self.enzoParameters['CosmologyHubbleConstantNow'] - iteration += 1 - if (iteration > max_Iterations): - mylog.error("calculate_deltaz_max: Warning - max iterations exceeded for z = %f (delta z = %f)." % - (z,na.fabs(z2-z))) - break - # Use this calculation or the absolute minimum specified by the user. - output['deltazMin'] = max(na.fabs(z2-z),deltaz_min) - -EnzoParameterDict = {"CosmologyOmegaMatterNow": float, - "CosmologyOmegaLambdaNow": float, - "CosmologyHubbleConstantNow": float, - "CosmologyInitialRedshift": float, - "CosmologyFinalRedshift": float, - "ComovingCoordinates": int, - "InitialTime": float, - "StopTime": float, - "TopGridDimensions": float, - "dtDataDump": float, - "RedshiftDumpName": str, - "RedshiftDumpDir": str, - "DataDumpName": str, - "DataDumpDir": str, - "GlobalDir" : str} - -def __deltaz_forward(cosmology, z, target_distance): - "Calculate deltaz corresponding to moving a comoving distance starting from some redshift." - - d_Tolerance = 1e-4 - max_Iterations = 100 - - # Calculate delta z that corresponds to the length of the box at a given redshift. - # Use Newton's method to calculate solution. - z1 = z - z2 = z1 - 0.1 # just an initial guess - distance1 = 0.0 - iteration = 1 - - # Convert comoving radial distance into Mpc / h, since that's how box size is stored. - distance2 = cosmology.ComovingRadialDistance(z2,z) * cosmology.HubbleConstantNow / 100.0 - - while ((na.fabs(distance2-target_distance)/distance2) > d_Tolerance): - m = (distance2 - distance1) / (z2 - z1) - z1 = z2 - distance1 = distance2 - z2 = ((target_distance - distance2) / m) + z2 - distance2 = cosmology.ComovingRadialDistance(z2,z) * cosmology.HubbleConstantNow / 100.0 - iteration += 1 - if (iteration > max_Iterations): - mylog.error("deltaz_forward: Warning - max iterations exceeded for z = %f (delta z = %f)." % - (z,na.fabs(z2-z))) - break - return na.fabs(z2-z) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/README --- a/yt/extensions/enzo_test/README Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,275 +0,0 @@ -Enzo Regression Test Runner -=========================== - -This is an evolving sketch of how Enzo regression tests might work. They will -be based on a python test runner, called from LCA test, that will output images -as well as success/failure for a set of tests. - -The interface is still evolving, but we're working on both creating something -fun, easy to write tests for, and clear. - -This is still a work in progress! Things might change without notice! - -What Is A Test And How To Write One ------------------------------------ - -A test at its most fundamental level makes some value from one or multiple -outputs from a simulation and then compares those outputs to the outputs from -some previous simulation. - -Each test follows a fixed interface, but we're trying to provide a couple -mechanisms to make test writing easier. To implement a test, you have to -define a python class that subclasses from a particular type of test case. - -Your new test must implement the following interface, or it will fail: - - name - All tests have to have the variable "name" defined in the class - definition. This is a unique key that identifies the test, and it is - used to self-register every test in a global registry. This will play - into filenames, so it's for the best if it doesn't contain spaces or - other unacceptable filename characters. - - setup(self) - If you subclass from the YT test case or another test case base - class that implements setup, this may not be necessary. This is - where all the pre-testing operation occurs, and is useful if you - want to write a bunch of tests that have the same setup. Not return - value is needed. - - run(self) - This is where the testing occurs and some value generated -- this value - can be an array, a number, a string, any Python or NumPy base type. - (For various reasons, YT objects can't be considered results, only - their base components.) When this value is prepared, it needs to be - stored as the property "result" on the object -- for example, you might - do self.result = some_time_average . No return value is needed. - - compare(self, old_result) - This routine compares an existing result against the value computed - from a previous run. It can be assumed that the "old_result" was - constructed in an identical "run" function, so direct comparison can be - made. No return value is needed, but instead it is assumed that in - case of failure an exception that subclasses from - RegressionTestException will be raised -- however, the usage of - operations like compare_array_delta and compare_value_delta is - encouraged because they will handle the appropriate exception raising. - - plot(self) - This function is optional, but it is used to generate an image from a - test. The return value is the filename of the created image. - -Helpful Functions For Test Writing ----------------------------------- - -All test cases supply several base sets of operations: - - * compare_array_delta(array1, array2, tolerance) - This computes - max(abs(array1-array2)/(array1+array2)) - and fails if that is greater than tolerance. Set tolerance to 0.0 for - an exact comparison. - - * compare_value_delta(value1, value2, tolerance) - This computes - abs(value1-value2)/(value1+value2) - and fails if that is greater than tolerance. Set tolerance to 0.0 for - an exact comparison. - -Currently, a few exist: - - SingleOutputTest - This is a test case designed to handle a single test. - - Additional Attributes: - * filename => The parameter file to test - - Additional Methods: - * None - - MultipleOutputTest - This is a test case designed to handle multiple tests. - - Additional Attributes: - * io_log => The IO log from the simulation - - Additional Methods: - * __iter__ => You can iterate over the test case: - for filename in self: - ... - to have it return all the filenames in the IO log. - - YTStaticOutputTest - This test case is designed to work with YT, and provides a couple - additional things that YT can provide. - - Additional Attributes: - * sim_center => The center of the simulation, from the domain left - and right edges. - * max_dens_location => The point of highest density. - - * entire_simulation => A data object containing the entire - simulation. - - Additional Methods: - * pixelize(data_source, field, edges, dims) => - This returns a (dims[0], dims[1]) array constructed from the - variable resolution (projection or slice) data object. Edges - are in code units, (px_min, px_max, py_min, py_max) and default - to the entire domain. dims is a tuple, (Nx, Ny). - - * compare_data_arrays(d1, d2, tolerance) => - yt often stores arrays hanging off dictionaries. This accepts - d1 and d2, which are dictionarys with arrays as values, and - compares all the arrays using compare_array_delta, with - given tolerance. - -Sample Tests ------------- - -There are some example tests in the distribution. But, a simple test case -would also work well. This is a test case using yt to find the maximum density -in the simulation. Note that we don't have to provide a setup function, as -that's taken care of in the base class (YTStaticOutputTest.) - - class TestMaximumDensity(YTStaticOutputTest): - name = "maximum_density" - - def run(self): - # self.pf already exists - value, center = self.pf.h.find_max("Density") - self.result = (value, center) - - def compare(self, old_result): - value, center = self.result - old_value, old_center = old_result - - # We want our old max density to agree with our new max density to - # a relative difference of 1e-7. - self.compare_value_delta(value, old_value, 1e-7) - - # Now we check if our center has moved. - self.compare_value_array(center, old_center, 1e-7) - - def plot(self): - # There's not much to plot, so we just return an empty list. - return [] - -Running Tests -------------- - -Subclasses of RegressionTest are *self-registering*, which means they can be -run. Two classes are provided for running tests. One is the test runner, and -the other is a thin wrapper around a Shelve from the shelve module. To run a -series of tests, you need to instantiate a RegressionTestRunner and then tell -it which tests to run. - -If the runner has a set of results against which to compare, it will do so. -For every test, it will perform the following actions: - - 1. setup() - 2. run() - 3. plot(), store list of filenames in self.plot_list[test_name] - 4. store test.results - 5. test.compare(old_results), if a compare_id is supplied - -If a test is of type SingleOutputTest, or a subclass, this test will be run for -every single output in the IO log. If it is a MultipleOutputTest, only one for -each test will be executed. - -The RegressionTestRunner has a public interface: - - RegressionTestRunner: - __init__(id, compare_id, results_path, io_log) - The id is the unique id for this test case, which will be used for - the name of the results database. The compare_id (optional) is the - id of the results database against which we will compare. The - results_path is the path to the directory in which results sets are - stored, defaulting to the current directory. io_log, defaulting to - "OutputLog", is the IO log from Enzo that lists all of the outputs. - - run_test(name): - The test corresponding to that test name is run. - - run_all_tests() - This runs all of the tests that have been registered. Every time a - test is defined, it is registered -- so this list can get quite - long! But, by selectively importing 'plugin' modules, the full - list of tests can be controlled. - - run_tests_from_file(filename): - Every line in a filename is parsed, and if it matches a test name - in the test registry, it will be run. - -The included sample script run_tests.py will instantiate a test runner, run it -once on a set of outputs, and then run it again comparing against the results -from the first run. This should always succeed, but it gives an idea of how to -go about running tests. - -Test Creation Convenience Functions ------------------------------------ - -Because of the self-registering nature of the tests, we can very conveniently -create new ones just by subclassing. But, subclassing a lot of tests can be a -bit annoying! So the create_test function has been created. - -Going back to our example of the maximum density location function, we could -rewrite it slightly to make it work with the create_test function. We remove -the name and we make our parameter, field, known, but we don't set it. - - class TestMaximumValue(YTStaticOutputTest): - - field = None - - def run(self): - # self.pf already exists - value, center = self.pf.h.find_max(self.field) - self.result = (value, center) - - def compare(self, old_result): - value, center = self.result - old_value, old_center = old_result - - # We want our old max density to agree with our new max density to - # a relative difference of 1e-7. - self.compare_value_delta(value, old_value, 1e-7) - - # Now we check if our center has moved. - self.compare_value_array(center, old_center, 1e-7) - - def plot(self): - # There's not much to plot, so we just return an empty list. - return [] - -Note that it's mostly the same, but we are using self.field to find the maximum -density instead of hard coding it to Density. We also don't specify 'name' so -that this base class won't be registered. We can now use create_test to make a -bunch, setting "field" to anything we want, and naming them anything we want: - - for field in ["Temperature", "x-velocity", "y-velocity", "z-velocity"]: - create_test(TestMaximumValue, "maximum_%s_test" % field, - field = field) - -This makes and then registers tests of the name format given, which are then -accessible through the test runner. See the projection and gas distribution -test creations in hydro_tests.py for a few more examples of how to use this. - -TODO -==== - -This is still fairly bare bones! There are some fun areas we can expand into: - - * We need more tests! More than that, we need tests that know something - about the different test *problems*. We'll need lists of tests to run - for every single problem type. - * Sometimes the results database acts oddly and can't add a new value. - * The source tree needs to be re-organized and this README file turned into - documentation that includes every test in the main distribution. - * Doc strings need to be added to all functions and classes. Comments for - all tests need to be included. - * More explicit test naming and running. - * Generation of HTML pages including all the pages and the results, along - with download links. This should be done with LCA test. - * Plots should be zipped up and removed from the file system. The zipfile - module would work great for this. - * And lots more ... diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/__init__.py --- a/yt/extensions/enzo_test/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -""" -The components of the Enzo testing mechanism - -Author: Matthew Turk -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 . -""" - -import runner, output_tests -from runner import RegressionTestRunner, run_main - -from output_tests import RegressionTest, SingleOutputTest, \ - MultipleOutputTest, YTStaticOutputTest, create_test diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/halo_tests.py --- a/yt/extensions/enzo_test/halo_tests.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -from yt.mods import * -import matplotlib; matplotlib.use("Agg") -import pylab -from output_tests import SingleOutputTest, YTStaticOutputTest, create_test - -class TestHaloCount(YTStaticOutputTest): - threshold = 80.0 - - def run(self): - # Find the haloes using vanilla HOP. - haloes = HaloFinder(self.pf, threshold=self.threshold, dm_only=False) - # We only care about the number of haloes. - self.result = len(haloes) - - def compare(self, old_result): - # The new value should be identical to the old one. - self.compare_value_delta(self.result, old_result, 0) - - def plot(self): - return [] - -create_test(TestHaloCount, "halo_count_test", threshold=80.0) - -class TestHaloComposition(YTStaticOutputTest): - threshold=80.0 - - def run(self): - # Find the haloes using vanilla HOP. - haloes = HaloFinder(self.pf, threshold=self.threshold, dm_only=False) - # The result is a list of the particle IDs, stored - # as sets for easy comparison. - IDs = [] - for halo in haloes: - IDs.append(set(halo["particle_index"])) - self.result = IDs - - def compare(self, old_result): - # All the sets should be identical. - pairs = zip(self.result, old_result) - for pair in pairs: - if len(pair[0] - pair[1]) != 0: - return False - return True - - def plot(self): - return [] - -create_test(TestHaloComposition, "halo_composition_test", threshold=80.0) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/hydro_tests.py --- a/yt/extensions/enzo_test/hydro_tests.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -import matplotlib; matplotlib.use("Agg") -import pylab -from output_tests import SingleOutputTest, YTStaticOutputTest, create_test - -class TestProjection(YTStaticOutputTest): - - field = None - axis = None - - def run(self): - # First we get our flattened projection -- this is the - # Density, px, py, pdx, and pdy - proj = self.pf.h.proj(self.axis, self.field) - # Now let's stick it in a buffer - pixelized_proj = self.pixelize(proj, self.field) - # We just want the values, so this can be stored - # independently of the parameter file. - # The .data attributes strip out everything other than the actual array - # values. - self.result = (proj.data, pixelized_proj.data) - - def compare(self, old_result): - proj, pixelized_proj = self.result - oproj, opixelized_proj = old_result - - self.compare_data_arrays(proj, oproj) - self.compare_array_delta( - pixelized_proj[self.field], - opixelized_proj[self.field], - 1e-7) - - def plot(self): - pylab.clf() - pylab.imshow(self.result[1][self.field], - interpolation='nearest', origin='lower') - fn = "%s_%s_projection.png" % (self.pf, self.field) - pylab.savefig(fn) - return [fn] - -# Now we create all our tests. We are using the create_test -# function, which is a relatively simple function that takes the base class, -# a name, and any parameters that the test requires. -for axis in range(3): - for field in ["Density", "Temperature"]: - create_test(TestProjection, "projection_test_%s_%s" % (axis, field), - field = field, axis = axis) - -class TestGasDistribution(YTStaticOutputTest): - field_x = None - field_y = None - weight = "CellMassMsun" - n_bins = 32 - - def run(self): - # We're NOT going to use the low-level profiling API here, - # because we are avoiding the calculations of min/max, - # as those should be tested in another test. - pc = PlotCollection(self.pf, center=self.sim_center) - p = pc.add_profile_object(self.entire_simulation, - [self.field_x, self.field_y], x_bins = self.n_bins, - weight=self.weight) - # The arrays are all stored in a dictionary hanging off the profile - # object - self.result = p.data._data - - def compare(self, old_result): - self.compare_data_arrays( - self.result, old_result) - - def plot(self): - return [] - -# Now we create all our tests, but we're only going to check the binning -# against Density for now. -for field in ["Temperature", "x-velocity"]: - create_test(TestGasDistribution, "profile_density_test_%s" % field, - field_x = "Density", field_y = field) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/output_tests.py --- a/yt/extensions/enzo_test/output_tests.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,201 +0,0 @@ -from yt.mods import * - -# We first create our dictionary of tests to run. This starts out empty, and -# as tests are imported it will be filled. -class TestRegistry(dict): - def __new__(cls, *p, **k): - if not '_the_instance' in cls.__dict__: - cls._the_instance = dict.__new__(cls) - return cls._the_instance - -test_registry = TestRegistry() - -# The exceptions we raise, related to the character of the failure. - -class RegressionTestException(Exception): - pass - -class ValueDelta(RegressionTestException): - def __init__(self, delta, acceptable): - self.delta = delta - self.acceptable = acceptable - - def __repr__(self): - return "ValueDelta: Delta %0.5e, max of %0.5e" % ( - self.delta, self.acceptable) - -class ArrayDelta(ValueDelta): - def __repr__(self): - return "ArrayDelta: Delta %0.5e, max of %0.5e" % ( - self.delta, self.acceptable) - -class ShapeMismatch(RegressionTestException): - def __init__(self, old_shape, current_shape): - self.old_shape = old_shape - self.current_shape = current_shape - - def __repr__(self): - return "Shape Mismatch: old_buffer %s, current_buffer %0.5e" % ( - self.old_shape, self.current_shape) - -class RegressionTest(object): - name = None - result = None - output_type = None - - class __metaclass__(type): - # This ensures that all the tests are auto-registered if they have a - # name. If they do not have a name, they are considered to be base - # classes to be overridden and implemented by someone else. - def __init__(cls, name, b, d): - type.__init__(cls, name, b, d) - if cls.name is not None: - test_registry[cls.name] = cls - - def setup(self): - """ - This function must be defined if the problem requires additional setup. - Note that for the most part this will be defined in base classes where - subclasses will only implement 'run'. - """ - pass - - def run(self): - """ - This function must generate a result value, of any type, and store it - in self.result. - """ - pass - - def compare(self, old_result): - """ - This function must accept `old_result` and compare it somehow against - the value stored in `self.result`. If the result is a failure, it must - raise an exception. Otherwise it is considered to be a success. - """ - pass - - def plot(self): - """ - This function can optionally plot the contents of `self.result`. - """ - pass - - def compare_array_delta(self, a1, a2, acceptable): - """ - This is a helper function. It accepts two numpy arrays and compares - the maximum relative difference. If the maximum relative difference is - greater than `acceptable` it is considered a failure and an appropriate - exception is raised. - """ - if a1.shape != a2.shape: - raise ShapeMismatch(a1, a2) - delta = na.abs(a1 - a2)/(a1 + a2) - if delta.max() > acceptable: - raise ArrayDelta(delta, acceptable) - return True - - def compare_value_delta(self, v1, v2, acceptable): - """ - This is a helper function. It accepts two floating point values and - calculates the maximum relative different. If the maximum relative - difference is greater than `acceptable` it is considered a failure and - an appropriate exception is raised. - """ - delta = na.abs(v1 - v2)/(v1 + v2) - if delta > acceptable: - raise ValueDelta(delta, acceptable) - return True - -class SingleOutputTest(RegressionTest): - output_type = 'single' - - def __init__(self, filename): - """ - This test mechanism is designed to accept a single filename and - evaluate it, not necessarily utilizing yt's functionality to do so. - """ - self.filename = filename - -class MultipleOutputTest(RegressionTest): - output_type = 'multiple' - - io_log_header = "DATASET WRITTEN" - - def __init__(self, io_log): - """ - This test mechanism is designed to accept an OutputLog file and then - iterate over it, evaluating every single dataset individually. - """ - self.io_log = io_log - - def __iter__(self): - for line in open(self.io_log): - yield line[len(self.io_log_header):].strip() - -def create_test(base, new_name, **attrs): - """ - This function accepts a base class of a test, sets some attributes on it, - and then registers a new test. It's a fast way of registering multiple - tests that share the same testing logic but that differ on a few parameters - or combinations of parameters. - """ - new_name = "%s_%s" % (base.__name__, new_name) - attrs['name'] = new_name - return type(new_name, (base,), attrs) - -class YTStaticOutputTest(SingleOutputTest): - - def setup(self): - self.pf = load(self.filename) - - def pixelize(self, data, field, edges = None, dims = (512, 512)): - """ - This is a helper function that returns a 2D array of the specified - source, in the specified field, at the specified spatial extent. - """ - xax = lagos.x_dict[self.axis] - yax = lagos.y_dict[self.axis] - - if edges is None: - edges = (self.pf["DomainLeftEdge"][xax], - self.pf["DomainRightEdge"][xax], - self.pf["DomainLeftEdge"][yax], - self.pf["DomainRightEdge"][yax]) - frb = raven.FixedResolutionBuffer( data, edges, dims) - frb[field] # To make the pixelization - return frb - - def compare_data_arrays(self, d1, d2, tol = 1e-7): - """ - This is a helper function. It accepts two dictionaries of numpy arrays - and compares the maximum relative difference of every array. If the - maximum relative difference is greater than `acceptable` it is - considered a failure and an appropriate exception is raised. - """ - for field in d1.keys(): - self.compare_array_delta(d1[field], d2[field], tol) - - @property - def sim_center(self): - """ - This returns the center of the domain. - """ - return 0.5*(self.pf["DomainRightEdge"] + self.pf["DomainLeftEdge"]) - - @property - def max_dens_location(self): - """ - This is a helper function to return the location of the most dense - point. - """ - return self.pf.h.find_max("Density")[1] - - @property - def entire_simulation(self): - """ - Return an unsorted array of values that cover the entire domain. - """ - return self.pf.h.all_data() - - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/particle_tests.py --- a/yt/extensions/enzo_test/particle_tests.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -from yt.mods import * -import matplotlib; matplotlib.use("Agg") -import pylab -from output_tests import SingleOutputTest, YTStaticOutputTest, create_test - -class TestParticleUniqueIDs(YTStaticOutputTest): - - def run(self): - # Test to make sure that all the particles have unique IDs. - all = self.pf.h.all_data() - IDs = all["particle_index"] - # Make sure the order is the same every time. - IDs = IDs[IDs.argsort()] - self.result = IDs - - def compare(self, old_result): - # Two things: there should be no repeats in either the new or - # the old, and the two sets should be the same. - if len(old_result) != len(set(old_result)): return False - if len(self.result) != len(set(self.result)): return False - if (self.result != old_result).all(): return False - return True - - def plot(self): - return [] - -create_test(TestParticleUniqueIDs, "particle_unique_ids_test") - -class TestParticleExtrema(YTStaticOutputTest): - - def run(self): - # Tests to make sure there are no particle positions aren't changing - # drastically. This is very unlikely to be a problem. - all = self.pf.h.all_data() - min = na.empty(3,dtype='float64') - max = min.copy() - dims = ["particle_position_x","particle_position_y", - "particle_position_z"] - for i in xrange(3): - min[i] = na.min(all[dims[i]]) - max[i] = na.max(all[dims[i]]) - self.result = (min,max) - - def compare(self, old_result): - min,max = self.result - old_min, old_max = old_result - # The extrema should be very similar. - self.compare_array_delta(min, old_min, 1e-7) - self.compare_array_delta(max, old_max, 1e-7) - # Also, the min/max shouldn't be outside the boundaries. - if (min < self.pf['DomainLeftEdge']).any(): return False - if (max > self.pf['DomainRightEdge']).any(): return False - return True - - def plot(self): - return [] - -create_test(TestParticleExtrema, "particle_extrema_test") - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/run_tests.py --- a/yt/extensions/enzo_test/run_tests.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -from yt.config import ytcfg -ytcfg["yt","loglevel"] = '50' -ytcfg["yt","suppressStreamLogging"] = 'True' - -import hydro_tests # Just importing will register the tests! -import halo_tests -import particle_tests -from runner import RegressionTestRunner - -first_runner = RegressionTestRunner("first") -first_runner.run_all_tests() -second_runner = RegressionTestRunner("second", "first") -second_runner.run_all_tests() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/enzo_test/runner.py --- a/yt/extensions/enzo_test/runner.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -import os, shelve, cPickle, sys -import yt.cmdln as cmdln -from output_tests import test_registry, MultipleOutputTest, \ - RegressionTestException - -class RegressionTestStorage(object): - def __init__(self, id, path = "."): - self.id = id - self._path = os.path.join(path, "results_%s" % self.id) - if not os.path.isdir(self._path): os.mkdir(self._path) - if os.path.isfile(self._path): raise RuntimeError - - def _fn(self, tn): - return os.path.join(self._path, tn) - - def __setitem__(self, test_name, result): - # We have to close our shelf manually, - # as the destructor does not necessarily do this. - # Context managers would be more appropriate. - f = open(self._fn(test_name), "wb") - cPickle.dump(result, f, protocol=-1) - f.close() - - def __getitem__(self, test_name): - f = open(self._fn(test_name), "rb") - tr = cPickle.load(f) - f.close() - return tr - -class RegressionTestRunner(object): - def __init__(self, id, compare_id = None, - results_path = ".", io_log = "OutputLog"): - # This test runner assumes it has been launched with the current - # working directory that of the test case itself. - self.io_log = io_log - self.id = id - if compare_id is not None: - self.old_results = RegressionTestStorage( - compare_id, path=results_path) - else: - self.old_results = None - self.results = RegressionTestStorage(id, path=results_path) - self.plot_list = {} - self.passed_tests = {} - - def run_all_tests(self): - plot_list = [] - for i,name in enumerate(sorted(test_registry)): - self.run_test(name) - return plot_list - - def run_test(self, name): - # We'll also need to call the "compare" operation, - # but for that we'll need a data store. - test = test_registry[name] - plot_list = [] - if test.output_type == 'single': - mot = MultipleOutputTest(self.io_log) - for i,fn in enumerate(mot): - # This next line is to keep the shelve module - # from happily gobbling the disk - #if i > 5: break - test_instance = test(fn) - test_instance.name = "%s_%s" % ( - os.path.basename(fn), test_instance.name ) - self._run(test_instance) - - elif test.output_type == 'multiple': - test_instance = test(self.io_log) - self._run(test_instance) - - def _run(self, test): - print self.id, "Running", test.name, - test.setup() - test.run() - self.plot_list[test.name] = test.plot() - self.results[test.name] = test.result - success = self._compare(test) - if success == True: print "SUCCEEDED" - else: print "FAILED" - self.passed_tests[test.name] = success - - def _compare(self, test): - if self.old_results is None: - return True - old_result = self.old_results[test.name] - try: - test.compare(old_result) - except RegressionTestException, exc: - return str(exc) - return True - - def run_tests_from_file(self, filename): - for line in open(filename): - test_name = line.strip() - if test_name not in test_registry: - if test_name[0] != "#": - print "Test '%s' not recognized, skipping" % (test_name) - continue - print "Running '%s'" % (test_name) - self.run_test(line.strip()) - -class EnzoTestRunnerCommands(cmdln.Cmdln): - name = "enzo_tests" - - def do_store(self, subcmd, opts, name, *test_modules): - """ - ${cmd_name}: Run and store a new dataset. - - ${cmd_usage} - ${cmd_option_list} - """ - sys.path.insert(0, ".") - for fn in test_modules: - if fn.endswith(".py"): fn = fn[:-3] - print "Loading module %s" % (fn) - __import__(fn) - test_runner = RegressionTestRunner(name) - test_runner.run_all_tests() - - def do_compare(self, subcmd, opts, reference, comparison, *test_modules): - """ - ${cmd_name}: Compare a reference dataset against a new dataset. The - new dataset will be run regardless of whether it exists or not. - - ${cmd_usage} - ${cmd_option_list} - """ - sys.path.insert(0, ".") - for fn in test_modules: - if fn.endswith(".py"): fn = fn[:-3] - print "Loading module %s" % (fn) - __import__(fn) - test_runner = RegressionTestRunner(comparison, reference) - test_runner.run_all_tests() - -def run_main(): - etrc = EnzoTestRunnerCommands() - sys.exit(etrc.main()) - -if __name__ == "__main__": - run_main() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/eps_writer.py --- a/yt/extensions/eps_writer.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1043 +0,0 @@ -""" -DualEPS: A class to combine bitmap compression and vector graphics - -Author: John Wise -Date: April 2010 -Affiliation: Princeton -Homepage: http://yt.enzotools.org/ - -Requirements: PyX - -License: - Copyright (C) 2010 John Wise. 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 . -""" -import pyx -from yt.mods import * -from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas -from matplotlib import cm - -class DualEPS: - def __init__(self, figsize=(12,12)): - r"""Initializes the DualEPS class to which we can progressively add layers - of vector graphics and compressed bitmaps. - - Parameters - ---------- - figsize : tuple of floats - The width and height of a single figure in centimeters. - """ - pyx.unit.set(xscale=1.4) - self.figsize = figsize - self.canvas = None - self.colormaps = None - self.axes_drawn = False - - def hello_world(self): - r"""A simple test. - """ - if self.canvas is None: - self.canvas = pyx.canvas.canvas() - p = pyx.path.line(0,0,1,1) - self.canvas.stroke(p) - self.canvas.text(0,0, "Hello world.") - -#============================================================================= - - def axis_box(self, xrange=(0,1), yrange=(0,1), xlabel="", ylabel="", - xlog=False, ylog=False, tickcolor=None, bare_axes=False, - pos=(0,0), xaxis_side=0, yaxis_side=0): - r"""Draws an axis box in the figure. - - Parameters - ---------- - xrange : tuple of floats - The min and max of the x-axis - yrange : tuple of floats - The min and max of the y-axis - xlabel : string - Label for the x-axis - ylabel : string - Label for the y-axis - xlog : boolean - Flag to use a logarithmic x-axis - ylog : boolean - Flag to use a logarithmic y-axis - tickcolor : `pyx.color.*.*` - Color for the tickmarks. Example: pyx.color.cmyk.black - bare_axes : boolean - Set to true to have no annotations or tick marks on all of the - axes. - pos : tuple of floats - (x,y) position in centimeters of the origin in the figure - xaxis_side : integer - Set to 0 for the x-axis annotations to be on the left. Set - to 1 to print them on the right side. - yaxis_side : integer - Set to 0 for the y-axis annotations to be on the bottom. Set - to 1 to print them on the top. - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.save_fig() - """ - if tickcolor is None: - c1 = pyx.graph.axis.painter.regular\ - (tickattrs=[pyx.color.cmyk.black]) - c2 = pyx.graph.axis.painter.regular\ - (tickattrs=[pyx.color.cmyk.black], labelattrs=None) - else: - c1 = pyx.graph.axis.painter.regular(tickattrs=[tickcolor]) - c2 = pyx.graph.axis.painter.regular\ - (tickattrs=[tickcolor], labelattrs=None) - - xticklabels = True - yticklabels = True - if xaxis_side == 0: - xleftlabel = xlabel - xrightlabel = "" - c1x = c1 - c2x = c2 - elif xaxis_side == 1: - xleftlabel = "" - xrightlabel = xlabel - c1x = c2 - c2x = c1 - else: - xticklabels = False - xleftlabel = "" - xrightlabel = "" - c1x = c1 - c2x = c2 - if yaxis_side == 0: - yleftlabel = ylabel - yrightlabel = "" - c1y = c1 - c2y = c2 - elif yaxis_side == 1: - yleftlabel = "" - yrightlabel = ylabel - c1y = c2 - c2y = c1 - else: - yticklabels = False - yleftlabel = "" - yrightlabel = "" - c1y = c1 - c2y = c2 - - if xlog: - if xticklabels: - xaxis = pyx.graph.axis.log(min=xrange[0],max=xrange[1], - title=xleftlabel, painter=c1x) - xaxis2 = pyx.graph.axis.log(min=xrange[0],max=xrange[1], - title=xrightlabel, painter=c2x) - else: - xaxis = pyx.graph.axis.log(min=xrange[0],max=xrange[1], - title=xleftlabel, painter=c1x, - parter=None) - xaxis2 = pyx.graph.axis.log(min=xrange[0],max=xrange[1], - title=xrightlabel, painter=c2x, - parter=None) - else: - if xticklabels: - xaxis = pyx.graph.axis.lin(min=xrange[0],max=xrange[1], - title=xleftlabel, painter=c1x) - xaxis2 = pyx.graph.axis.lin(min=xrange[0],max=xrange[1], - title=xrightlabel, painter=c2x) - else: - xaxis = pyx.graph.axis.lin(min=xrange[0],max=xrange[1], - title=xleftlabel, painter=c1x, - parter=None) - xaxis2 = pyx.graph.axis.lin(min=xrange[0],max=xrange[1], - title=xrightlabel, painter=c2x, - parter=None) - if ylog: - if yticklabels: - yaxis = pyx.graph.axis.log(min=yrange[0],max=yrange[1], - title=yleftlabel, painter=c1y) - yaxis2 = pyx.graph.axis.log(min=yrange[0],max=yrange[1], - title=yrightlabel, painter=c2y) - else: - yaxis = pyx.graph.axis.log(min=yrange[0],max=yrange[1], - title=yleftlabel, painter=c1y, - parter=None) - yaxis2 = pyx.graph.axis.log(min=yrange[0],max=yrange[1], - title=yrightlabel, painter=c2y, - parter=None) - else: - if yticklabels: - yaxis = pyx.graph.axis.lin(min=yrange[0],max=yrange[1], - title=yleftlabel, painter=c1y) - yaxis2 = pyx.graph.axis.lin(min=yrange[0],max=yrange[1], - title=yrightlabel, painter=c2y) - else: - yaxis = pyx.graph.axis.lin(min=yrange[0],max=yrange[1], - title=yleftlabel, painter=c1y, - parter=None) - yaxis2 = pyx.graph.axis.lin(min=yrange[0],max=yrange[1], - title=yrightlabel, painter=c2y, - parter=None) - - if bare_axes: - if ylog: - yaxis = pyx.graph.axis.log(min=yrange[0], max=yrange[1], - title=yleftlabel, parter=None) - yaxis2 = pyx.graph.axis.log(min=yrange[0], max=yrange[1], - title=yrightlabel, parter=None) - else: - yaxis = pyx.graph.axis.lin(min=yrange[0], max=yrange[1], - title=yleftlabel, parter=None) - yaxis2 = pyx.graph.axis.lin(min=yrange[0], max=yrange[1], - title=yrightlabel, parter=None) - if xlog: - xaxis = pyx.graph.axis.log(min=xrange[0], max=xrange[1], - title=xleftlabel, parter=None) - xaxis2 = pyx.graph.axis.log(min=xrange[0], max=xrange[1], - title=xrightlabel, parter=None) - else: - xaxis = pyx.graph.axis.lin(min=xrange[0], max=xrange[1], - title=xleftlabel, parter=None) - xaxis2 = pyx.graph.axis.lin(min=xrange[0], max=xrange[1], - title=xrightlabel, parter=None) - - blank_data = pyx.graph.data.points([(-1,-1),(-0.99,-0.99)], x=1,y=2) - if self.canvas is None: - self.canvas = pyx.graph.graphxy \ - (width=self.figsize[0], height=self.figsize[1], - x=xaxis, y=yaxis, x2=xaxis2, y2=yaxis2, - xpos=pos[0], ypos=pos[1]) - self.canvas.plot(blank_data) - else: - plot = pyx.graph.graphxy \ - (width=self.figsize[0], height=self.figsize[1], - x=xaxis, y=yaxis, x2=xaxis2, y2=yaxis2, - xpos=pos[0], ypos=pos[1]) - plot.plot(blank_data) - self.canvas.insert(plot) - self.axes_drawn = True - -#============================================================================= - - def axis_box_yt(self, plot, units=None, bare_axes=False, **kwargs): - r"""Wrapper around DualEPS.axis_box to automatically fill in the - axis ranges and labels from a yt plot. - - This also accepts any parameters that DualEPS.axis_box takes. - - Parameters - ---------- - plot : `yt.raven.RavenPlot` - yt plot on which the axes are based. - units : string - Unit description that overrides yt's unit description. Only - affects the axis label. - bare_axes : boolean - Set to true to have no annotations or tick marks on all of the - axes. - - Examples - -------- - >>> p = pc.add_slice('Density', 0, use_colorbar=False) - >>> d = DualEPS() - >>> d.axis_box_yt(p) - >>> d.save_fig() - """ - plot._redraw_image() - if isinstance(plot, raven.PlotTypes.VMPlot): - if units == None: - # Determine the best units - astro_units = ['cm', 'rsun', 'au', 'pc', 'kpc', 'Mpc'] - best_fit = 0 - while plot.width*plot.pf[astro_units[best_fit]] > 1e3 and \ - best_fit < len(astro_units): - best_fit += 1 - units = astro_units[best_fit] - _xrange = (0, plot.width * plot.pf[units]) - _yrange = (0, plot.width * plot.pf[units]) - _xlog = False - _ylog = False - if bare_axes: - _xlabel = "" - _ylabel = "" - else: - _xlabel = '%s (%s)' % (lagos.x_names[plot.data.axis], units) - _ylabel = '%s (%s)' % (lagos.y_names[plot.data.axis], units) - _tickcolor = pyx.color.cmyk.white - else: - _xrange = plot._axes.get_xlim() - _yrange = plot._axes.get_ylim() - _xlog = plot._log_x - _ylog = plot._log_y - if bare_axes: - _xlabel = "" - _ylabel = "" - else: - _xlabel = plot._x_label - _ylabel = plot._y_label - _tickcolor = None - self.axis_box(xrange=_xrange, yrange=_yrange, xlabel=_xlabel, - ylabel=_ylabel, tickcolor=_tickcolor, xlog=_xlog, - ylog=_ylog, bare_axes=bare_axes, **kwargs) - -#============================================================================= - - def insert_image(self, filename, pos=(0,0)): - r"""Inserts a JPEG file in the figure. - - Parameters - ---------- - filename : string - Name of the JPEG file - pos : tuple of floats - Position of the origin of the image in centimeters - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.insert_image("image.jpg") - >>> d.save_fig() - """ - image = pyx.bitmap.jpegimage(filename) - if self.canvas is None: - self.canvas = pyx.canvas.canvas() - self.canvas.insert(pyx.bitmap.bitmap(pos[0], pos[1], image, - compressmode=None, - width=self.figsize[0], - height=self.figsize[1])) - -#============================================================================= - - def insert_image_yt(self, plot, pos=(0,0)): - r"""Inserts a bitmap taken from a yt plot. - - Parameters - ---------- - plot : `yt.raven.VMPlot` - yt plot that provides the image - pos : tuple of floats - Position of the origin of the image in centimeters. - - Examples - -------- - >>> p = pc.add_slice('Density', 0, use_colorbar=False) - >>> d = DualEPS() - >>> d.axis_box_yt(p) - >>> d.insert_image_yt(p) - >>> d.save_fig() - - Notes - ----- - For best results, set use_colorbar=False when creating the yt - image. - """ - # We need to remove the colorbar (if necessary), remove the - # axes, and resize the figure to span the entire figure - if plot.colorbar != None and \ - isinstance(plot, raven.PlotTypes.VMPlot): - print "WARNING: Image (slices, projections, etc.) plots must not"\ - "have a colorbar." - print "Removing it." - plot.colorbar = None - if self.canvas is None: - self.canvas = pyx.canvas.canvas() - plot._redraw_image() - _p1 = plot._figure - if isinstance(plot, raven.PlotTypes.ProfilePlot): - # Remove colorbar - _p1.delaxes(_p1.axes[1]) - _p1.axes[0].set_axis_off() # remove axes - _p1.axes[0].set_position([0,0,1,1]) # rescale figure - _p1.set_facecolor('w') # set background color - figure_canvas = FigureCanvas(_p1) - figure_canvas.draw() - size = _p1.get_size_inches() * _p1.dpi - image = pyx.bitmap.image(size[0], size[1], "RGB", - figure_canvas.tostring_rgb()) - figure_canvas.print_png('test.png') - self.canvas.insert(pyx.bitmap.bitmap(pos[0], pos[1], image, - width=self.figsize[0], - height=self.figsize[1])) - -#============================================================================= - - def colorbar(self, name, zrange=(0,1), label="", log=False, tickcolor=None, - orientation="right", pos=[0,0], shrink=1.0): - r"""Places a colorbar adjacent to the current figure. - - Parameters - ---------- - name : string - name of the (matplotlib) colormap to use - zrange : tuple of floats - min and max of the colorbar's range - label : string - colorbar label - log : boolean - Flag to use a logarithmic scale - tickcolor : `pyx.color.*.*` - Color for the tickmarks. Example: pyx.color.cmyk.black - orientation : string - Placement of the colorbar. Can be "left", "right", "top", - or "bottom". - pos : list of floats - (x,y) position of the origin of the colorbar in centimeters. - shrink : float - Factor to shrink the colorbar's size. A value of 1 means the - colorbar will have a height / width of the figure. - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.insert_image("image.jpg") - >>> d.colorbar("hot", xrange=(1e-2, 1e-4), log=True, - label="Density [cm$^{-3}$]") - >>> d.save_fig() - """ - if orientation == "right": - origin = (pos[0]+self.figsize[0]+0.5, pos[1]) - size = (0.1*self.figsize[0], self.figsize[1]) - imsize = (1,256) - elif orientation == "left": - origin = (pos[0]-0.5-0.1*self.figsize[0], pos[1]) - size = (0.1*self.figsize[0], self.figsize[1]) - imsize = (1,256) - elif orientation == "top": - origin = (pos[0], pos[1]+self.figsize[1]+0.5) - imorigin = (pos[0]+self.figsize[0], pos[1]+self.figsize[1]+0.5) - size = (self.figsize[0], 0.1*self.figsize[1]) - imsize = (256,1) - elif orientation == "bottom": - origin = (pos[0], pos[1]-0.5-0.1*self.figsize[1]) - imorigin = (pos[0]+self.figsize[0], pos[1]-0.5-0.1*self.figsize[1]) - size = (self.figsize[0], 0.1*self.figsize[1]) - imsize = (256,1) - else: - print "orientation %s unknown" % orientation - return - - # Scale the colorbar - shift = (0.5*(1.0-shrink)*size[0], 0.5*(1.0-shrink)*size[1]) - size = (size[0] * shrink, size[1] * shrink) - origin = (origin[0] + shift[0], origin[1] + shift[1]) - - # Convert the colormap into a string - x = na.linspace(1,0,256) - cm_string = cm.cmap_d[name](x, bytes=True)[:,0:3].tostring() - - cmap_im = pyx.bitmap.image(imsize[0], imsize[1], "RGB", cm_string) - if orientation == "top" or orientation == "bottom": - imorigin = (imorigin[0] - shift[0], imorigin[1] - shift[1]) - self.canvas.insert(pyx.bitmap.bitmap(imorigin[0], imorigin[1], cmap_im, - width=-size[0], height=size[1])) - else: - self.canvas.insert(pyx.bitmap.bitmap(origin[0], origin[1], cmap_im, - width=size[0], height=size[1])) - - if tickcolor is None: - c1 = pyx.graph.axis.painter.regular\ - (tickattrs=[pyx.color.cmyk.black]) - c2 = pyx.graph.axis.painter.regular\ - (tickattrs=[pyx.color.cmyk.black], labelattrs=None) - else: - c1 = pyx.graph.axis.painter.regular(tickattrs=[tickcolor]) - c2 = pyx.graph.axis.painter.regular(tickattrs=[tickcolor], - labelattrs=None) - if log: - yaxis = pyx.graph.axis.log(min=zrange[0],max=zrange[1], - title=label, painter=c1) - yaxis2 = pyx.graph.axis.log(min=zrange[0],max=zrange[1],parter=None) - else: - yaxis = pyx.graph.axis.lin(min=zrange[0],max=zrange[1], - title=label, painter=c1) - yaxis2 = pyx.graph.axis.lin(min=zrange[0], max=zrange[1], parter=None) - xaxis = pyx.graph.axis.lin(parter=None) - - if orientation == "right": - _colorbar = pyx.graph.graphxy(width=size[0], height=size[1], - xpos=origin[0], ypos=origin[1], - x=xaxis, y=yaxis2, y2=yaxis) - elif orientation == "left": - _colorbar = pyx.graph.graphxy(width=size[0], height=size[1], - xpos=origin[0], ypos=origin[1], - x=xaxis, y2=yaxis2, y=yaxis) - elif orientation == "top": - _colorbar = pyx.graph.graphxy(width=size[0], height=size[1], - xpos=origin[0], ypos=origin[1], - y=xaxis, x=yaxis2, x2=yaxis) - elif orientation == "bottom": - _colorbar = pyx.graph.graphxy(width=size[0], height=size[1], - xpos=origin[0], ypos=origin[1], - y=xaxis, x2=yaxis2, x=yaxis) - - - blank_data = pyx.graph.data.points([(-1e10,-1e10),(-9e10,-9e10)], - x=1, y=2) - _colorbar.plot(blank_data) - self.canvas.insert(_colorbar) - -#============================================================================= - - def colorbar_yt(self, plot, **kwargs): - r"""Wrapper around DualEPS.colorbar to take information from a yt plot. - - Accepts all parameters that DualEPS.colorbar takes. - - Parameters - ---------- - plot : `yt.raven.VMPlot` - yt plot from which the information is taken. - - Examples - -------- - >>> p = pc.add_slice('Density', 0, use_colorbar=False) - >>> d = DualEPS() - >>> d.axis_box_yt(p) - >>> d.insert_image_yt(p) - >>> d.colorbar_yt(p) - >>> d.save_fig() - """ - if plot.cmap != None: - _cmap = plot.cmap.name - else: - _cmap = 'algae' - if isinstance(plot, raven.PlotTypes.VMPlot): - # Taken from yt - proj = "Proj" in plot._type_name and \ - plot.data._weight is None - _zlabel = plot.pf.field_info[plot.axis_names["Z"]].get_label(proj) - print _zlabel - _zlabel = _zlabel.replace("_","\;") - print _zlabel - _zlog = plot.log_field - else: - _zlabel = plot._z_label.replace("_","\;") - _zlog = plot._log_z - _zrange = (plot.norm.vmin, plot.norm.vmax) - self.colorbar(_cmap, zrange=_zrange, label=_zlabel, log=_zlog, **kwargs) - -#============================================================================= - - def circle(self, radius=0.2, loc=(0.5,0.5), - color=pyx.color.cmyk.white, - linewidth=pyx.style.linewidth.normal): - r"""Draws a circle in the current figure. - - Parameters - ---------- - radius : float - Radius of the circle in units of figsize - loc : tuple of floats - Location of the circle's center in units of figsize - color : `pyx.color.*.*` - Color of the circle stroke. Example: pyx.color.cmyk.white - linewidth : `pyx.style.linewidth.*` - Width of the circle stroke width. Example: - pyx.style.linewidth.normal - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.insert_image("image.jpg") - >>> d.circle(radius=0.1, color=pyx.color.cmyk.Red) - >>> d.save_fig() - """ - circle = pyx.path.circle(self.figsize[0]*loc[0], - self.figsize[1]*loc[1], - self.figsize[0]*radius) - self.canvas.stroke(circle, [color, linewidth]) - -#============================================================================= - - def scale_line(self, size=0.2, label="", loc=(0.05,0.08), labelloc="top", - color=pyx.color.cmyk.white, - linewidth=pyx.style.linewidth.normal): - r"""Draws a scale line in the current figure. - - Parameters - ---------- - size : float - Length of the scale line in units of the figure size. - label : string - Annotation label of the scale line. - loc : tuple of floats - Location of the left hand side of the scale line in units of - the figure size. - labelloc : string - Location of the label with respect to the line. Can be - "top" or "bottom" - color : `pyx.color.*.*` - Color of the scale line. Example: pyx.color.cymk.white - linewidth : `pyx.style.linewidth.*` - Width of the scale line. Example: pyx.style.linewidth.normal - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.insert_image("image.jpg") - >>> d.scale_line(size=0.2, label="1 kpc", loc=(0.05, 0.1)) - >>> d.save_fig() - """ - line = pyx.path.line(self.figsize[0]*loc[0], - self.figsize[1]*loc[1], - self.figsize[0]*(loc[0]+size), - self.figsize[1]*loc[1]) - self.canvas.stroke(line, [linewidth, color]) - line = pyx.path.line(self.figsize[0]*loc[0], - self.figsize[1]*(loc[1]-0.1*size), - self.figsize[0]*loc[0], - self.figsize[1]*(loc[1]+0.1*size)) - self.canvas.stroke(line, [linewidth, color]) - line = pyx.path.line(self.figsize[0]*(loc[0]+size), - self.figsize[1]*(loc[1]-0.1*size), - self.figsize[0]*(loc[0]+size), - self.figsize[1]*(loc[1]+0.1*size)) - self.canvas.stroke(line, [linewidth, color]) - - if labelloc == "bottom": - yoff = -0.1*size - valign = pyx.text.valign.top - else: - yoff = +0.1*size - valign = pyx.text.valign.bottom - if label != "": - self.canvas.text(self.figsize[0]*(loc[0]+0.5*size), - self.figsize[1]*(loc[1]+yoff), label, - [color, valign, pyx.text.halign.center]) - -#============================================================================= - - def title_box(self, text, color=pyx.color.cmyk.black, - bgcolor=pyx.color.cmyk.white, loc=(0.02,0.98), - halign=pyx.text.halign.left, - valign=pyx.text.valign.top): - r"""Inserts a box with text in the current figure. - - Parameters - ---------- - text : string - String to insert in the textbox. - color : `pyx.color.*.*` - Color of the text. Example: pyx.color.cmyk.black - bgcolor : `pyx.color.*.*` - Color of the textbox background. Example: pyx.color.cmyk.white - loc : tuple of floats - Location of the textbox origin in units of the figure size. - halign : `pyx.text.halign.*` - Horizontal alignment of the text. Example: pyx.text.halign.left - valign : `pyx.text.valign.*` - Vertical alignment of the text. Example: pyx.text.valign.top - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.insert_image("image.jpg") - >>> d.title_box("Halo 1", loc=(0.05,0.95)) - >>> d.save_fig() - """ - tbox = self.canvas.text(self.figsize[0]*loc[0], - self.figsize[1]*loc[1], - text, [color, valign, halign]) - if bgcolor != None: - tpath = tbox.bbox().enlarged(2*pyx.unit.x_pt).path() - self.canvas.draw(tpath, [pyx.deco.filled([bgcolor]), - pyx.deco.stroked()]) - self.canvas.insert(tbox) - -#============================================================================= - - def save_fig(self, filename="test", format="eps"): - r"""Saves current figure to a file. - - Parameters - ---------- - filename : string - Name of the saved file without the extension. - format : string - Format type. Can be "eps" or "pdf" - - Examples - -------- - >>> d = DualEPS() - >>> d.axis_box(xrange=(0,100), yrange=(1e-3,1), ylog=True) - >>> d.save_fig("image1", format="pdf") - """ - if format =="eps": - self.canvas.writeEPSfile(filename) - elif format == "pdf": - self.canvas.writePDFfile(filename) - else: - print "format %s unknown." % (format) - -#============================================================================= -#============================================================================= -#============================================================================= - -def multiplot(ncol, nrow, yt_plots=None, images=None, xranges=None, - yranges=None, xlabels=None, ylabels=None, colorbars=None, - shrink_cb=0.95, figsize=(8,8), margins=(0,0), titles=None, - savefig=None, yt_nocbar=False, bare_axes=False, - cb_flags=None): - r"""Convenience routine to create a multi-panel figure from yt plots or - JPEGs. The images are first placed from the origin, and then - bottom-to-top and left-to-right. - - Parameters - ---------- - ncol : integer - Number of columns in the figure. - nrow : integer - Number of rows in the figure. - yt_plots : list of `yt.raven.VMPlot` - yt plots to include in the figure. - images : list of strings - JPEG filenames to include in the figure. - xranges : list of tuples - The min and max of the x-axes - yranges : list of tuples - The min and max of the y-axes - xlabels : list of strings - Labels for the x-axes - ylabels : list of strings - Labels for the y-axes - colorbars : list of dicts - Dicts that describe the type of colorbar to be used in each - figure. Use the function return_cmap() to create these dicts. - shrink_cb : float - Factor by which the colorbar is shrunk. - figsize : tuple of floats - The width and height of a single figure in centimeters. - margins : tuple of floats - The horizontal and vertical margins between panels in centimeters. - titles : list of strings - Titles that are placed in textboxes in each panel. - savefig : string - Name of the saved file without the extension. - yt_nocbar : boolean - Flag to indicate whether or not colorbars are created. - bare_axes : boolean - Set to true to have no annotations or tick marks on all of the - axes. - cb_flags : list of booleans - Flags for each plot to have a colorbar or not. - - Examples - -------- - >>> images = ["density.jpg", "hi_density.jpg", "entropy.jpg", - >>> "special.jpg"] - >>> cbs=[] - >>> cbs.append(return_cmap("algae", "Density [cm$^{-3}$]", (0,10), False)) - >>> cbs.append(return_cmap("jet", "HI Density", (0,5), False)) - >>> cbs.append(return_cmap("hot", r"Entropy [K cm$^2$]", (1e-2,1e6), True)) - >>> cbs.append(return_cmap("Spectral", "Stuff$_x$!", (1,300), True)) - >>> - >>> mp = multiplot(2,2, images=images, margins=(0.1,0.1), - >>> titles=["1","2","3","4"], - >>> xlabels=["one","two"], ylabels=None, colorbars=cbs, - >>> shrink_cb=0.95) - >>> mp.scale_line(label="$r_{vir}$", labelloc="top") - >>> mp.save_fig("multiplot") - - Notes - ----- - If given both yt_plots and images, this will get preference to the - yt plots. - """ - # Error check - if images != None: - if len(images) != ncol*nrow: - print "Number of images (%d) doesn't match nrow(%d) x ncol(%d)." %\ - (len(images), nrow, ncol) - return - if yt_plots is None and images is None: - print "Must supply either yt_plots or image filenames." - return - if yt_plots != None and images != None: - print "Given both images and yt plots. Ignoring images." - if yt_plots != None: - _yt = True - else: - _yt = False - - # If no ranges or labels given and given only images, fill them in. - if not _yt: - if xranges is None: - xranges = [] - for i in range(nrow*ncol): xranges.append((0,1)) - if yranges is None: - yranges = [] - for i in range(nrow*ncol): yranges.append((0,1)) - if xlabels is None: - xlabels = [] - for i in range(nrow*ncol): xlabels.append("") - if ylabels is None: - ylabels = [] - for i in range(nrow*ncol): ylabels.append("") - - d = DualEPS(figsize=figsize) - count = 0 - for j in range(nrow): - ypos = j*(figsize[1] + margins[1]) - for i in range(ncol): - xpos = i*(figsize[0] + margins[0]) - index = j*ncol + i - if j == nrow-1: - xaxis = 1 - elif j == 0: - xaxis = 0 - else: - xaxis = -1 - if i == 0: - yaxis = 0 - elif i == ncol-1: - yaxis = 1 - else: - yaxis = -1 - if _yt: - d.insert_image_yt(yt_plots[index], pos=(xpos, ypos)) - d.axis_box_yt(yt_plots[index], pos=(xpos, ypos), - bare_axes=bare_axes, xaxis_side=xaxis, - yaxis_side=yaxis) - else: - d.insert_image(images[index], pos=(xpos,ypos)) - d.axis_box(pos = (xpos, ypos), - xrange=xranges[index], yrange=yranges[index], - xlabel=xlabels[i], ylabel=ylabels[j], - bare_axes=bare_axes, xaxis_side=xaxis, yaxis_side=yaxis) - if titles != None: - if titles[index] != None: - d.title_box(titles[index], - loc=(i+0.05+i*margins[0]/figsize[0], - j+0.98+j*margins[1]/figsize[1])) - - # Insert colorbars after all axes are placed because we want to - # put them on the edges of the bounding box. - bbox = (100.0 * d.canvas.bbox().left().t, - 100.0 * d.canvas.bbox().right().t - d.figsize[0], - 100.0 * d.canvas.bbox().bottom().t, - 100.0 * d.canvas.bbox().top().t - d.figsize[1]) - for j in range(nrow): - ypos0 = j*(figsize[1] + margins[1]) - for i in range(ncol): - xpos0 = i*(figsize[0] + margins[0]) - index = j*ncol + i - if (not _yt and colorbars != None) or (_yt and not yt_nocbar): - if cb_flags != None: - if cb_flags[index] == False: - continue - if _yt or colorbars[index] != None: - if ncol == 1: - orientation = "right" - xpos = bbox[1] - ypos = ypos0 - elif i == 0: - orientation = "left" - xpos = bbox[0] - ypos = ypos0 - elif i+1 == ncol: - orientation = "right" - xpos = bbox[1] - ypos = ypos0 - elif j == 0: - orientation = "bottom" - ypos = bbox[2] - xpos = xpos0 - elif j+1 == nrow: - orientation = "top" - ypos = bbox[3] - xpos = xpos0 - else: - orientation = None # Marker for interior plot - - if orientation != None: - if _yt: - d.colorbar_yt(yt_plots[index], - pos=[xpos,ypos], - shrink=shrink_cb, - orientation=orientation) - else: - d.colorbar(colorbars[index]["cmap"], - zrange=colorbars[index]["range"], - label=colorbars[index]["name"], - log=colorbars[index]["log"], - orientation=orientation, - pos=[xpos,ypos], - shrink=shrink_cb) - - if savefig != None: - d.save_fig(savefig) - - return d - -#============================================================================= - -def multiplot_yt(ncol, nrow, plot_col, **kwargs): - r"""Wrapper for multiplot that takes a yt PlotCollection. - - Accepts all parameters used in multiplot. - - Parameters - ---------- - ncol : integer - Number of columns in the figure. - nrow : integer - Number of rows in the figure. - plot_col : `PlotCollection` - yt PlotCollection that has the plots to be used. - - Examples - -------- - >>> pc = PlotCollection(pf) - >>> p = pc.add_slice('Density',0,use_colorbar=False) - >>> p.set_width(0.1,'kpc') - >>> p1 = pc.add_slice('Temperature',0,use_colorbar=False) - >>> p1.set_width(0.1,'kpc') - >>> p1.set_cmap('hot') - >>> p1 = pc.add_phase_sphere(0.1, 'kpc', ['Radius', 'Density', 'H2I_Fraction'], - >>> weight='CellMassMsun') - >>> p1.set_xlim(1e18,3e20) - >>> p1 = pc.add_phase_sphere(0.1, 'kpc', ['Radius', 'Density', 'Temperature'], - >>> weight='CellMassMsun') - >>> p1.set_xlim(1e18,3e20) - >>> mp = multiplot_yt(2,2,pc,savefig="yt",shrink_cb=0.9, bare_axes=False, - >>> yt_nocbar=False, margins=(0.5,0.5)) - """ - if len(plot_col.plots) < nrow*ncol: - print "Number of plots in PlotCollection is less than nrow(%d) "\ - "x ncol(%d)." % (len(plot_col.plots), nrow, ncol) - return - figure = multiplot(ncol, nrow, yt_plots=plot_col.plots, **kwargs) - return figure - -#============================================================================= - -def single_plot(plot, figsize=(12,12), cb_orient="right", bare_axes=False, - savefig=None, file_format='eps'): - r"""Wrapper for DualEPS routines to create a figure directy from a yt - plot. Calls insert_image_yt, axis_box_yt, and colorbar_yt. - - Parameters - ---------- - plot : `yt.raven.VMPlot` - yt plot that provides the image and metadata - figsize : tuple of floats - Size of the figure in centimeters. - cb_orient : string - Placement of the colorbar. Can be "left", "right", "top", or - "bottom". - bare_axes : boolean - Set to true to have no annotations or tick marks on all of the axes. - savefig : string - Name of the saved file without the extension. - file_format : string - Format type. Can be "eps" or "pdf" - - Examples - -------- - >>> p = pc.add_slice('Density',0,use_colorbar=False) - >>> p.set_width(0.1,'kpc') - >>> single_plot(p, savefig="figure1") - """ - d = DualEPS(figsize=figsize) - d.insert_image_yt(plot) - d.axis_box_yt(plot, bare_axes=bare_axes) - d.colorbar_yt(plot, orientation=cb_orient) - if savefig != None: - d.save_fig(savefig, format=file_format) - return d - -#============================================================================= -def return_cmap(cmap="algae", label="", range=(0,1), log=False): - r"""Returns a dict that describes a colorbar. Exclusively for use with - multiplot. - - Parameters - ---------- - cmap : string - name of the (matplotlib) colormap to use - label : string - colorbar label - range : tuple of floats - min and max of the colorbar's range - log : boolean - Flag to use a logarithmic scale - - Examples - -------- - >>> cb = return_cmap("algae", "Density [cm$^{-3}$]", (0,10), False) - """ - return {'cmap': cmap, 'name': label, 'range': range, 'log': log} - -#============================================================================= - -#if __name__ == "__main__": -# pf = load('/Users/jwise/runs/16Jul09_Pop3/DD0019/output_0019') -# pc = PlotCollection(pf) -# p = pc.add_slice('Density',0,use_colorbar=False) -# p.set_width(0.1,'kpc') -# p1 = pc.add_slice('Temperature',0,use_colorbar=False) -# p1.set_width(0.1,'kpc') -# p1.set_cmap('hot') -# p1 = pc.add_phase_sphere(0.1, 'kpc', ['Radius', 'Density', 'H2I_Fraction'], -# weight='CellMassMsun') -# p1.set_xlim(1e18,3e20) -# p1 = pc.add_phase_sphere(0.1, 'kpc', ['Radius', 'Density', 'Temperature'], -# weight='CellMassMsun') -# p1.set_xlim(1e18,3e20) -# mp = multiplot_yt(2,2,pc,savefig="yt",shrink_cb=0.9, bare_axes=False, -# yt_nocbar=False, margins=(0.5,0.5)) -# #d = DualEPS() -# #d.axis_box(xrange=(0,20.7), yrange=(0,20.7), xlabel='x [kpc]', -# # ylabel='y [kpc]') -# #d.axis_box_yt(p) -# #d.insert_image_yt(p) -# #d.colorbar_yt(p) -# #d.title_box("Halo 1", loc=(0.02,0.02), valign=pyx.text.valign.bottom) -# #d.circle() -# #d.save_fig('yt') -# -# images = ["density.jpg", "density.jpg", "density.jpg", "density.jpg"] -# cbs=[] -# cbs.append(return_cmap("algae", "Density [cm$^{-3}$]", (0,10), False)) -# cbs.append(return_cmap("jet", "HI Density", (0,5), False)) -# cbs.append(return_cmap("hot", r"Entropy [K cm$^2$]", (1e-2,1e6), True)) -# cbs.append(return_cmap("Spectral", "Stuff$_x$!", (1,300), True)) -# -# mp = multiplot(images,2,2, margins=(0.1,0.1), titles=["1","2","3","4"], -# xlabels=["one","two"], ylabels=None, colorbars=cbs, -# shrink_cb=0.95) -# mp.scale_line(label="$r_{vir}$", labelloc="top") -# mp.save_fig("multiplot") - -# d = DualEPS() -# d.axis_box(xrange=(0,250), yrange=(0,250), xlabel="x [pc]", ylabel="y [pc]", -# xlog=False, ylog=False, tickcolor=pyx.color.cmyk.White, -# bare_axes=False, xaxis_side=1, yaxis_side=0) -# d.insert_image("density.jpg") -# d.colorbar("algae", zrange=(1e-2,1e4), log=True, -# label="Density [cm$^{-3}$]", orientation='right') -# d.scale_line(label="$r_{vir}$", labelloc="top") -# d.circle() -# d.title_box(r"$z=17$") -# d.save_fig(format='eps') diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/halo_filters.py --- a/yt/extensions/halo_filters.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -""" -Halo filters to be used with the HaloProfiler. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from yt.logger import lagosLogger as mylog -from copy import deepcopy -import numpy as na - -def VirialFilter(profile,overdensity_field='ActualOverdensity', - virial_overdensity=200.,must_be_virialized=True, - virial_filters=[['TotalMassMsun','>=','1e14']], - virial_quantities=['TotalMassMsun','RadiusMpc'], - virial_index=None): - """ - Filter halos by virial quantities. - Return values are a True or False whether the halo passed the filter, - along with a dictionary of virial quantities for the fields specified in - the virial_quantities keyword. Thresholds for virial quantities are - given with the virial_filters keyword in the following way: - [field, condition, value]. - """ - - fields = deepcopy(virial_quantities) - if virial_filters is None: virial_filters = [] - for vfilter in virial_filters: - if not vfilter[0] in fields: - fields.append(vfilter[0]) - - overDensity = [] - temp_profile = {} - for field in fields: - temp_profile[field] = [] - - for q in range(len(profile[overdensity_field])): - good = True - if (profile[overdensity_field][q] != profile[overdensity_field][q]): - good = False - continue - for field in fields: - if (profile[field][q] != profile[field][q]): - good = False - break - if good: - overDensity.append(profile[overdensity_field][q]) - for field in fields: - temp_profile[field].append(profile[field][q]) - - virial = {} - for field in fields: - virial[field] = 0.0 - - if (not (na.array(overDensity) >= virial_overdensity).any()) and \ - must_be_virialized: - mylog.error("This halo is not virialized!") - return [False, {}] - - if (len(overDensity) < 2): - mylog.error("Skipping halo with no valid points in profile.") - return [False, {}] - - if (overDensity[1] <= virial_overdensity): - index = 0 - elif (overDensity[-1] >= virial_overdensity): - index = -2 - else: - for q in (na.arange(len(overDensity)-2))+2: - if (overDensity[q] < virial_overdensity): - index = q - 1 - break - - if type(virial_index) is list: - virial_index.append(index) - - for field in fields: - if (overDensity[index+1] - overDensity[index]) == 0: - mylog.error("Overdensity profile has slope of zero.") - return [False, {}] - else: - slope = (temp_profile[field][index+1] - temp_profile[field][index]) / \ - (overDensity[index+1] - overDensity[index]) - value = slope * (virial_overdensity - overDensity[index]) + \ - temp_profile[field][index] - virial[field] = value - - for vfilter in virial_filters: - if eval("%s %s %s" % (virial[vfilter[0]],vfilter[1],vfilter[2])): - mylog.debug("(%s %s %s) returned True for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]])) - continue - else: - mylog.debug("(%s %s %s) returned False for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]])) - return [False, {}] - - return [True, dict((q,virial[q]) for q in virial_quantities)] - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/halo_mass_function.py --- a/yt/extensions/halo_mass_function.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,736 +0,0 @@ -""" -halo_mass_function - Halo Mass Function and supporting functions. - -Author: Stephen Skory -Affiliation: UC San Diego / CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Stephen Skory (and others). 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 . -""" - -import yt.lagos as lagos -from yt.logger import lagosLogger as mylog -import numpy as na -import math, time - -class HaloMassFcn(lagos.ParallelAnalysisInterface): - def __init__(self, pf, halo_file=None, omega_matter0=None, omega_lambda0=None, - omega_baryon0=0.05, hubble0=None, sigma8input=0.86, primordial_index=1.0, - this_redshift=None, log_mass_min=None, log_mass_max=None, num_sigma_bins=360, - fitting_function=4, mass_column=5): - """ - Initalize a HaloMassFcn object to analyze the distribution of haloes - as a function of mass. - :param halo_file (str): The filename of the output of the Halo Profiler. - Default=None. - :param omega_matter0 (float): The fraction of the universe made up of - matter (dark and baryonic). Default=None. - :param omega_lambda0 (float): The fraction of the universe made up of - dark energy. Default=None. - :param omega_baryon0 (float): The fraction of the universe made up of - ordinary baryonic matter. This should match the value - used to create the initial conditions, using 'inits'. This is - *not* stored in the enzo datset so it must be checked by hand. - Default=0.05. - :param hubble0 (float): The expansion rate of the universe in units of - 100 km/s/Mpc. Default=None. - :param sigma8input (float): The amplitude of the linear power - spectrum at z=0 as specified by the rms amplitude of mass-fluctuations - in a top-hat sphere of radius 8 Mpc/h. This should match the value - used to create the initial conditions, using 'inits'. This is - *not* stored in the enzo datset so it must be checked by hand. - Default=0.86. - :param primoridal_index (float): This is the index of the mass power - spectrum before modification by the transfer function. A value of 1 - corresponds to the scale-free primordial spectrum. This should match - the value used to make the initial conditions using 'inits'. This is - *not* stored in the enzo datset so it must be checked by hand. - Default=1.0. - :param this_redshift (float): The current redshift. Default=None. - :param log_mass_min (float): The log10 of the mass of the minimum of the - halo mass range. Default=None. - :param log_mass_max (float): The log10 of the mass of the maximum of the - halo mass range. Default=None. - :param num_sigma_bins (float): The number of bins (points) to use for - the calculations and generated fit. Default=360. - :param fitting_function (int): Which fitting function to use. - 1 = Press-schechter, 2 = Jenkins, 3 = Sheth-Tormen, 4 = Warren fit - 5 = Tinker - Default=4. - :param mass_column (int): The column of halo_file that contains the - masses of the haloes. Default=4. - """ - self.pf = pf - self.halo_file = halo_file - self.omega_matter0 = omega_matter0 - self.omega_lambda0 = omega_lambda0 - self.omega_baryon0 = omega_baryon0 - self.hubble0 = hubble0 - self.sigma8input = sigma8input - self.primordial_index = primordial_index - self.this_redshift = this_redshift - self.log_mass_min = log_mass_min - self.log_mass_max = log_mass_max - self.num_sigma_bins = num_sigma_bins - self.fitting_function = fitting_function - self.mass_column = mass_column - - # Determine the run mode. - if halo_file is None: - # We are hand-picking our various cosmological parameters - self.mode = 'single' - else: - # Make the fit using the same cosmological parameters as the dataset. - self.mode = 'haloes' - self.omega_matter0 = self.pf['CosmologyOmegaMatterNow'] - self.omega_lambda0 = self.pf['CosmologyOmegaLambdaNow'] - self.hubble0 = self.pf['CosmologyHubbleConstantNow'] - self.this_redshift = self.pf['CosmologyCurrentRedshift'] - self.read_haloes() - if self.log_mass_min == None: - self.log_mass_min = math.log10(min(self.haloes)) - if self.log_mass_max == None: - self.log_mass_max = math.log10(max(self.haloes)) - - # Input error check. - if self.mode == 'single': - if omega_matter0 == None or omega_lambda0 == None or \ - hubble0 == None or this_redshift == None or log_mass_min == None or\ - log_mass_max == None: - mylog.error("All of these parameters need to be set:") - mylog.error("[omega_matter0, omega_lambda0, \ - hubble0, this_redshift, log_mass_min, log_mass_max]") - mylog.error("[%s,%s,%s,%s,%s,%s]" % (omega_matter0,\ - omega_lambda0, hubble0, this_redshift,\ - log_mass_min, log_mass_max)) - return None - - # Poke the user to make sure they're doing it right. - mylog.info( - """ - Please make sure these are the correct values! They are - not stored in enzo datasets, so must be entered by hand. - sigma8input=%f primordial_index=%f omega_baryon0=%f - """ % (self.sigma8input, self.primordial_index, self.omega_baryon0)) - time.sleep(1) - - # Do the calculations. - self.sigmaM() - self.dndm() - - if self.mode == 'haloes': - self.bin_haloes() - - def write_out(self, prefix='HMF', fit=True, haloes=True): - """ - Writes out the halo mass functions to file(s) with prefix *prefix*. - """ - # First the fit file. - if fit: - fitname = prefix + '-fit.dat' - fp = self._write_on_root(fitname) - line = \ - """#Columns: -#1. log10 of mass (Msolar, NOT Msolar/h) -#2. mass (Msolar/h) -#3. (dn/dM)*dM (differential number density of haloes, per Mpc^3 (NOT h^3/Mpc^3) -#4. cumulative number density of halos (per Mpc^3, NOT h^3/Mpc^3) -""" - fp.write(line) - for i in xrange(self.logmassarray.size - 1): - line = "%e\t%e\t%e\t%e\n" % (self.logmassarray[i], self.massarray[i], - self.dn_M_z[i], self.nofmz_cum[i]) - fp.write(line) - fp.close() - if self.mode == 'haloes' and haloes: - haloname = prefix + '-haloes.dat' - fp = self._write_on_root(haloname) - line = \ - """#Columns: -#1. log10 of mass (Msolar, NOT Msolar/h) -#2. mass (Msolar/h) -#3. cumulative number density of haloes (per Mpc^3, NOT h^3/Mpc^3) -""" - fp.write(line) - for i in xrange(self.logmassarray.size - 1): - line = "%e\t%e\t%e\n" % (self.logmassarray[i], self.massarray[i], - self.dis[i]) - fp.write(line) - fp.close() - - def read_haloes(self): - """ - Read in the virial masses of the haloes. - """ - mylog.info("Reading halo masses from %s" % self.halo_file) - f = open(self.halo_file,'r') - line = f.readline() - if line == "": - self.haloes = na.array([]) - return - while line[0] == '#': - line = f.readline() - self.haloes = [] - while line: - line = line.split() - mass = float(line[self.mass_column]) - if mass > 0: - self.haloes.append(float(line[self.mass_column])) - line = f.readline() - f.close() - self.haloes = na.array(self.haloes) - - def bin_haloes(self): - """ - With the list of virial masses, find the halo mass function. - """ - bins = na.logspace(self.log_mass_min, - self.log_mass_max,self.num_sigma_bins) - avgs = (bins[1:]+bins[:-1])/2. - dis, bins = na.histogram(self.haloes,bins,new=True) - # add right to left - for i,b in enumerate(dis): - dis[self.num_sigma_bins-i-3] += dis[self.num_sigma_bins-i-2] - if i == (self.num_sigma_bins - 3): break - - self.dis = dis / self.pf['CosmologyComovingBoxSize']**3.0 * self.hubble0**3.0 - - def sigmaM(self): - """ - Written by BWO, 2006 (updated 25 January 2007). - Converted to Python by Stephen Skory December 2009. - - This routine takes in cosmological parameters and creates a file (array) with - sigma(M) in it, which is necessary for various press-schechter type - stuff. In principle one can calculate it ahead of time, but it's far, - far faster in the long run to calculate your sigma(M) ahead of time. - - Inputs: cosmology, user must set parameters - - Outputs: four columns of data containing the following information: - - 1) log mass (Msolar) - 2) mass (Msolar/h) - 3) Radius (comoving Mpc/h) - 4) sigma (normalized) using Msun/h as the input - - The arrays output are used later. - """ - - # Set up the transfer function object. - self.TF = TransferFunction(self.omega_matter0, self.omega_baryon0, 0.0, 0, - self.omega_lambda0, self.hubble0, self.this_redshift); - - if self.TF.qwarn: - mylog.error("You should probably fix your cosmology parameters!") - - # output arrays - # 1) log10 of mass (Msolar, NOT Msolar/h) - self.Rarray = na.empty(self.num_sigma_bins,dtype='float64') - # 2) mass (Msolar/h) - self.logmassarray = na.empty(self.num_sigma_bins, dtype='float64') - # 3) spatial scale corresponding to that radius (Mpc/h) - self.massarray = na.empty(self.num_sigma_bins, dtype='float64') - # 4) sigma(M, z=0, where mass is in Msun/h) - self.sigmaarray = na.empty(self.num_sigma_bins, dtype='float64') - - # get sigma_8 normalization - R = 8.0; # in units of Mpc/h (comoving) - - sigma8_unnorm = math.sqrt(self.sigma_squared_of_R(R)); - sigma_normalization = self.sigma8input / sigma8_unnorm; - - rho0 = self.omega_matter0 * 2.78e+11; # in units of h^2 Msolar/Mpc^3 - - # spacing in mass of our sigma calculation - dm = (float(self.log_mass_max) - self.log_mass_min)/self.num_sigma_bins; - - """ - loop over the total number of sigma_bins the user has requested. - For each bin, calculate mass and equivalent radius, and call - sigma_squared_of_R to get the sigma(R) (equivalent to sigma(M)), - normalize by user-specified sigma_8, and then write out. - """ - for i in xrange(self.num_sigma_bins): - - # thislogmass is in units of Msolar, NOT Msolar/h - thislogmass = self.log_mass_min + i*dm - - # mass in units of h^-1 Msolar - thismass = math.pow(10.0, thislogmass) * self.hubble0; - - # radius is in units of h^-1 Mpc (comoving) - thisradius = math.pow( 3.0*thismass / 4.0 / math.pi / rho0, 1.0/3.0 ); - - R = thisradius; # h^-1 Mpc (comoving) - - self.Rarray[i] = thisradius; # h^-1 Mpc (comoving) - self.logmassarray[i] = thislogmass; # Msun (NOT Msun/h) - self.massarray[i] = thismass; # Msun/h - - # get normalized sigma(R) - self.sigmaarray[i] = math.sqrt(self.sigma_squared_of_R(R)) * sigma_normalization; - # All done! - - def dndm(self): - - # constants - set these before calling any functions! - rho0 = self.omega_matter0 * 2.78e+11; # in units of h^2 Msolar/Mpc^3 - self.delta_c0 = 1.69; # critical density for turnaround (Press-Schechter) - - nofmz_cum = 0.0; # keep track of cumulative number density - - # Loop over masses, going BACKWARD, and calculate dn/dm as well as the - # cumulative mass function. - - # output arrays - # 5) (dn/dM)*dM (differential number density of halos, per Mpc^3 (NOT h^3/Mpc^3) - self.dn_M_z = na.empty(self.num_sigma_bins, dtype='float64') - # 6) cumulative number density of halos (per Mpc^3, NOT h^3/Mpc^3) - self.nofmz_cum = na.zeros(self.num_sigma_bins, dtype='float64') - - for j in xrange(self.num_sigma_bins - 1): - i = (self.num_sigma_bins - 2) - j - - thissigma = self.sigmaof_M_z(i, self.this_redshift); - nextsigma = self.sigmaof_M_z(i+1, self.this_redshift); - - # calc dsigmadm - has units of h (since massarray has units of h^-1) - dsigmadm = (nextsigma-thissigma) / (self.massarray[i+1] - self.massarray[i]); - - # calculate dn(M,z) (dn/dM * dM) - # this has units of h^3 since rho0 has units of h^2, dsigmadm - # has units of h, and massarray has units of h^-1 - dn_M_z = -1.0 / thissigma * dsigmadm * rho0 / self.massarray[i] * \ - self.multiplicityfunction(thissigma)*(self.massarray[i+1] - self.massarray[i]); - - # scale by h^4 to get rid of all factors of h - dn_M_z *= math.pow(self.hubble0, 4.0); - - # keep track of cumulative number density - if dn_M_z > 1.0e-20: - nofmz_cum += dn_M_z; - - # Store this. - self.nofmz_cum[i] = nofmz_cum - self.dn_M_z[i] = dn_M_z - - - def sigma_squared_of_R(self, R): - """ - /* calculates sigma^2(R). This is the routine where the magic happens (or - whatever it is that we do here). Integrates the sigma_squared_integrand - parameter from R to infinity. Calls GSL (gnu scientific library) to do - the actual integration. - - Note that R is in h^-1 Mpc (comoving) - */ - """ - self.R = R - result = integrate_inf(self.sigma_squared_integrand) - - sigmasquaredofR = result / 2.0 / math.pi / math.pi - - return sigmasquaredofR; - - def sigma_squared_integrand(self, k): - """ - /* integrand for integral to get sigma^2(R). */ - """ - - Rcom = self.R; # this is R in comoving Mpc/h - - f = k*k*self.PofK(k)*na.power( abs(self.WofK(Rcom,k)), 2.0); - - return f - - def PofK(self, k): - """ - /* returns power spectrum as a function of wavenumber k */ - """ - - thisPofK = na.power(k, self.primordial_index) * na.power( self.TofK(k), 2.0); - - return thisPofK; - - def TofK(self, k): - """ - /* returns transfer function as a function of wavenumber k. */ - """ - - thisTofK = self.TF.TFmdm_onek_hmpc(k); - - return thisTofK; - - def WofK(self, R, k): - """ - returns W(k), which is the fourier transform of the top-hat function. - """ - - x = R*k; - - thisWofK = 3.0 * ( na.sin(x) - x*na.cos(x) ) / (x*x*x); - - return thisWofK; - - def multiplicityfunction(self, sigma): - """ - /* Multiplicity function - this is where the various fitting functions/analytic - theories are different. The various places where I found these fitting functions - are listed below. */ - """ - - nu = self.delta_c0 / sigma; - - if self.fitting_function==1: - # Press-Schechter (This form from Jenkins et al. 2001, MNRAS 321, 372-384, eqtn. 5) - thismult = math.sqrt(2.0/math.pi) * nu * math.exp(-0.5*nu*nu); - - elif self.fitting_function==2: - # Jenkins et al. 2001, MNRAS 321, 372-384, eqtn. 9 - thismult = 0.315 * math.exp( -1.0 * math.pow( abs( math.log(1.0/sigma) + 0.61), 3.8 ) ); - - elif self.fitting_function==3: - # Sheth-Tormen 1999, eqtn 10, using expression from Jenkins et al. 2001, eqtn. 7 - A=0.3222; - a=0.707; - p=0.3; - thismult = A*math.sqrt(2.0*a/math.pi)*(1.0+ math.pow( 1.0/(nu*nu*a), p) )*\ - nu * math.exp(-0.5*a*nu*nu); - - elif self.fitting_function==4: - # LANL fitting function - Warren et al. 2005, astro-ph/0506395, eqtn. 5 - A=0.7234; - a=1.625; - b=0.2538; - c=1.1982; - thismult = A*( math.pow(sigma, -1.0*a) + b)*math.exp(-1.0*c / sigma / sigma ); - - elif self.fitting_function==5: - # Tinker et al. 2008, eqn 3, \Delta=300 # \Delta=200 - A = 0.2 #0.186 - a = 1.52 #1.47 - b = 2.25 #2.57 - c = 1.27 #1.19 - thismult = A * ( math.pow((sigma / b), -a) + 1) * \ - math.exp(-1 * c / sigma / sigma) - - else: - mylog.error("Don't understand this. Fitting function requested is %d\n", - self.fitting_function) - return None - - return thismult - - def sigmaof_M_z(self, sigmabin, redshift): - """ - /* sigma(M, z) */ - """ - - thissigma = self.Dofz(redshift) * self.sigmaarray[sigmabin]; - - return thissigma; - - def Dofz(self, redshift): - """ - /* Growth function */ - """ - - thisDofz = self.gofz(redshift) / self.gofz(0.0) / (1.0+redshift); - - return thisDofz; - - - def gofz(self, redshift): - """ - /* g(z) - I don't think this has any other name*/ - """ - - thisgofz = 2.5 * self.omega_matter_of_z(redshift) / \ - ( math.pow( self.omega_matter_of_z(redshift), 4.0/7.0 ) - \ - self.omega_lambda_of_z(redshift) + \ - ( (1.0 + self.omega_matter_of_z(redshift) / 2.0) * \ - (1.0 + self.omega_lambda_of_z(redshift) / 70.0) )) - - return thisgofz; - - - def omega_matter_of_z(self,redshift): - """ - /* Omega matter as a function of redshift */ - """ - - thisomofz = self.omega_matter0 * math.pow( 1.0+redshift, 3.0) / \ - math.pow( self.Eofz(redshift), 2.0 ); - - return thisomofz; - - def omega_lambda_of_z(self,redshift): - """ - /* Omega lambda as a function of redshift */ - """ - - thisolofz = self.omega_lambda0 / math.pow( self.Eofz(redshift), 2.0 ) - - return thisolofz; - - def Eofz(self, redshift): - """ - /* E(z) - I don't think this has any other name */ - """ - thiseofz = math.sqrt( self.omega_lambda0 \ - + (1.0 - self.omega_lambda0 - self.omega_matter0)*math.pow( 1.0+redshift, 2.0) \ - + self.omega_matter0 * math.pow( 1.0+redshift, 3.0) ); - - return thiseofz; - - -""" -/* Fitting Formulae for CDM + Baryon + Massive Neutrino (MDM) cosmologies. */ -/* Daniel J. Eisenstein & Wayne Hu, Institute for Advanced Study */ - -/* There are two primary routines here, one to set the cosmology, the -other to construct the transfer function for a single wavenumber k. -You should call the former once (per cosmology) and the latter as -many times as you want. */ - -/* TFmdm_set_cosm() -- User passes all the cosmological parameters as - arguments; the routine sets up all of the scalar quantites needed - computation of the fitting formula. The input parameters are: - 1) omega_matter -- Density of CDM, baryons, and massive neutrinos, - in units of the critical density. - 2) omega_baryon -- Density of baryons, in units of critical. - 3) omega_hdm -- Density of massive neutrinos, in units of critical - 4) degen_hdm -- (Int) Number of degenerate massive neutrino species - 5) omega_lambda -- Cosmological constant - 6) hubble -- Hubble constant, in units of 100 km/s/Mpc - 7) redshift -- The redshift at which to evaluate */ - -/* TFmdm_onek_mpc() -- User passes a single wavenumber, in units of Mpc^-1. - Routine returns the transfer function from the Eisenstein & Hu - fitting formula, based on the cosmology currently held in the - internal variables. The routine returns T_cb (the CDM+Baryon - density-weighted transfer function), although T_cbn (the CDM+ - Baryon+Neutrino density-weighted transfer function) is stored - in the global variable tf_cbnu. */ - -/* We also supply TFmdm_onek_hmpc(), which is identical to the previous - routine, but takes the wavenumber in units of h Mpc^-1. */ - -/* We hold the internal scalar quantities in global variables, so that -the user may access them in an external program, via "extern" declarations. */ - -/* Please note that all internal length scales are in Mpc, not h^-1 Mpc! */ -""" - -class TransferFunction(object): - def __init__(self, omega_matter, omega_baryon, omega_hdm, - degen_hdm, omega_lambda, hubble, redshift): - """ - /* This routine takes cosmological parameters and a redshift and sets up - all the internal scalar quantities needed to compute the transfer function. */ - /* INPUT: omega_matter -- Density of CDM, baryons, and massive neutrinos, - in units of the critical density. */ - /* omega_baryon -- Density of baryons, in units of critical. */ - /* omega_hdm -- Density of massive neutrinos, in units of critical */ - /* degen_hdm -- (Int) Number of degenerate massive neutrino species */ - /* omega_lambda -- Cosmological constant */ - /* hubble -- Hubble constant, in units of 100 km/s/Mpc */ - /* redshift -- The redshift at which to evaluate */ - /* OUTPUT: Returns 0 if all is well, 1 if a warning was issued. Otherwise, - sets many global variables for use in TFmdm_onek_mpc() */ - """ - self.qwarn = 0; - self.theta_cmb = 2.728/2.7 # Assuming T_cmb = 2.728 K - - # Look for strange input - if (omega_baryon<0.0): - mylog.error("TFmdm_set_cosm(): Negative omega_baryon set to trace amount.\n") - self.qwarn = 1 - if (omega_hdm<0.0): - mylog.error("TFmdm_set_cosm(): Negative omega_hdm set to trace amount.\n") - self.qwarn = 1; - if (hubble<=0.0): - mylog.error("TFmdm_set_cosm(): Negative Hubble constant illegal.\n") - return None - elif (hubble>2.0): - mylog.error("TFmdm_set_cosm(): Hubble constant should be in units of 100 km/s/Mpc.\n"); - self.qwarn = 1; - if (redshift<=-1.0): - mylog.error("TFmdm_set_cosm(): Redshift < -1 is illegal.\n"); - return None - elif (redshift>99.0): - mylog.error("TFmdm_set_cosm(): Large redshift entered. TF may be inaccurate.\n"); - self.qwarn = 1; - - if (degen_hdm<1): degen_hdm=1; - self.num_degen_hdm = degen_hdm; - # Have to save this for TFmdm_onek_mpc() - # This routine would crash if baryons or neutrinos were zero, - # so don't allow that. - if (omega_baryon<=0): omega_baryon=1e-5; - if (omega_hdm<=0): omega_hdm=1e-5; - - self.omega_curv = 1.0-omega_matter-omega_lambda; - self.omhh = omega_matter*SQR(hubble); - self.obhh = omega_baryon*SQR(hubble); - self.onhh = omega_hdm*SQR(hubble); - self.f_baryon = omega_baryon/omega_matter; - self.f_hdm = omega_hdm/omega_matter; - self.f_cdm = 1.0-self.f_baryon-self.f_hdm; - self.f_cb = self.f_cdm+self.f_baryon; - self.f_bnu = self.f_baryon+self.f_hdm; - - # Compute the equality scale. - self.z_equality = 25000.0*self.omhh/SQR(SQR(self.theta_cmb)) # Actually 1+z_eq - self.k_equality = 0.0746*self.omhh/SQR(self.theta_cmb); - - # Compute the drag epoch and sound horizon - z_drag_b1 = 0.313*math.pow(self.omhh,-0.419)*(1+0.607*math.pow(self.omhh,0.674)); - z_drag_b2 = 0.238*math.pow(self.omhh,0.223); - self.z_drag = 1291*math.pow(self.omhh,0.251)/(1.0+0.659*math.pow(self.omhh,0.828))* \ - (1.0+z_drag_b1*math.pow(self.obhh,z_drag_b2)); - self.y_drag = self.z_equality/(1.0+self.z_drag); - - self.sound_horizon_fit = 44.5*math.log(9.83/self.omhh)/math.sqrt(1.0+10.0*math.pow(self.obhh,0.75)); - - # Set up for the free-streaming & infall growth function - self.p_c = 0.25*(5.0-math.sqrt(1+24.0*self.f_cdm)); - self.p_cb = 0.25*(5.0-math.sqrt(1+24.0*self.f_cb)); - - omega_denom = omega_lambda+SQR(1.0+redshift)*(self.omega_curv+\ - omega_matter*(1.0+redshift)); - self.omega_lambda_z = omega_lambda/omega_denom; - self.omega_matter_z = omega_matter*SQR(1.0+redshift)*(1.0+redshift)/omega_denom; - self.growth_k0 = self.z_equality/(1.0+redshift)*2.5*self.omega_matter_z/ \ - (math.pow(self.omega_matter_z,4.0/7.0)-self.omega_lambda_z+ \ - (1.0+self.omega_matter_z/2.0)*(1.0+self.omega_lambda_z/70.0)); - self.growth_to_z0 = self.z_equality*2.5*omega_matter/(math.pow(omega_matter,4.0/7.0) \ - -omega_lambda + (1.0+omega_matter/2.0)*(1.0+omega_lambda/70.0)); - self.growth_to_z0 = self.growth_k0/self.growth_to_z0; - - # Compute small-scale suppression - self.alpha_nu = self.f_cdm/self.f_cb*(5.0-2.*(self.p_c+self.p_cb))/(5.-4.*self.p_cb)* \ - math.pow(1+self.y_drag,self.p_cb-self.p_c)* \ - (1+self.f_bnu*(-0.553+0.126*self.f_bnu*self.f_bnu))/ \ - (1-0.193*math.sqrt(self.f_hdm*self.num_degen_hdm)+0.169*self.f_hdm*math.pow(self.num_degen_hdm,0.2))* \ - (1+(self.p_c-self.p_cb)/2*(1+1/(3.-4.*self.p_c)/(7.-4.*self.p_cb))/(1+self.y_drag)); - self.alpha_gamma = math.sqrt(self.alpha_nu); - self.beta_c = 1/(1-0.949*self.f_bnu); - # Done setting scalar variables - self.hhubble = hubble # Need to pass Hubble constant to TFmdm_onek_hmpc() - - - def TFmdm_onek_mpc(self, kk): - """ - /* Given a wavenumber in Mpc^-1, return the transfer function for the - cosmology held in the global variables. */ - /* Input: kk -- Wavenumber in Mpc^-1 */ - /* Output: The following are set as global variables: - growth_cb -- the transfer function for density-weighted - CDM + Baryon perturbations. - growth_cbnu -- the transfer function for density-weighted - CDM + Baryon + Massive Neutrino perturbations. */ - /* The function returns growth_cb */ - """ - - self.qq = kk/self.omhh*SQR(self.theta_cmb); - - # Compute the scale-dependent growth functions - self.y_freestream = 17.2*self.f_hdm*(1+0.488*math.pow(self.f_hdm,-7.0/6.0))* \ - SQR(self.num_degen_hdm*self.qq/self.f_hdm); - temp1 = math.pow(self.growth_k0, 1.0-self.p_cb); - temp2 = na.power(self.growth_k0/(1+self.y_freestream),0.7); - self.growth_cb = na.power(1.0+temp2, self.p_cb/0.7)*temp1; - self.growth_cbnu = na.power(na.power(self.f_cb,0.7/self.p_cb)+temp2, self.p_cb/0.7)*temp1; - - # Compute the master function - self.gamma_eff = self.omhh*(self.alpha_gamma+(1-self.alpha_gamma)/ \ - (1+SQR(SQR(kk*self.sound_horizon_fit*0.43)))); - self.qq_eff = self.qq*self.omhh/self.gamma_eff; - - tf_sup_L = na.log(2.71828+1.84*self.beta_c*self.alpha_gamma*self.qq_eff); - tf_sup_C = 14.4+325/(1+60.5*na.power(self.qq_eff,1.11)); - self.tf_sup = tf_sup_L/(tf_sup_L+tf_sup_C*SQR(self.qq_eff)); - - self.qq_nu = 3.92*self.qq*math.sqrt(self.num_degen_hdm/self.f_hdm); - self.max_fs_correction = 1+1.2*math.pow(self.f_hdm,0.64)*math.pow(self.num_degen_hdm,0.3+0.6*self.f_hdm)/ \ - (na.power(self.qq_nu,-1.6)+na.power(self.qq_nu,0.8)); - self.tf_master = self.tf_sup*self.max_fs_correction; - - # Now compute the CDM+HDM+baryon transfer functions - tf_cb = self.tf_master*self.growth_cb/self.growth_k0; - tf_cbnu = self.tf_master*self.growth_cbnu/self.growth_k0; - return tf_cb - - - def TFmdm_onek_hmpc(self, kk): - """ - /* Given a wavenumber in h Mpc^-1, return the transfer function for the - cosmology held in the global variables. */ - /* Input: kk -- Wavenumber in h Mpc^-1 */ - /* Output: The following are set as global variables: - growth_cb -- the transfer function for density-weighted - CDM + Baryon perturbations. - growth_cbnu -- the transfer function for density-weighted - CDM + Baryon + Massive Neutrino perturbations. */ - /* The function returns growth_cb */ - """ - return self.TFmdm_onek_mpc(kk*self.hhubble); - -def SQR(a): - return a*a - -def integrate_inf(fcn, error=1e-7, initial_guess=10): - """ - Integrate a function *fcn* from zero to infinity, stopping when the answer - changes by less than *error*. Hopefully someday we can do something - better than this! - """ - xvals = na.logspace(0,na.log10(initial_guess), initial_guess+1)-.9 - yvals = fcn(xvals) - xdiffs = xvals[1:] - xvals[:-1] - # Trapezoid rule, but with different dxes between values, so na.trapz - # will not work. - areas = (yvals[1:] + yvals[:-1]) * xdiffs / 2.0 - area0 = na.sum(areas) - # Next guess. - next_guess = 10 * initial_guess - xvals = na.logspace(0,na.log10(next_guess), 2*initial_guess**2+1)-.99 - yvals = fcn(xvals) - xdiffs = xvals[1:] - xvals[:-1] - # Trapezoid rule. - areas = (yvals[1:] + yvals[:-1]) * xdiffs / 2.0 - area1 = na.sum(areas) - # Now we refine until the error is smaller than *error*. - diff = area1 - area0 - area_final = area1 - area_last = area1 - one_pow = 3 - while diff > error: - next_guess *= 10 - xvals = na.logspace(0,na.log10(next_guess), one_pow*initial_guess**one_pow+1) - (1 - 0.1**one_pow) - yvals = fcn(xvals) - xdiffs = xvals[1:] - xvals[:-1] - # Trapezoid rule. - areas = (yvals[1:] + yvals[:-1]) * xdiffs / 2.0 - area_next = na.sum(areas) - diff = area_next - area_last - area_last = area_next - one_pow+=1 - return area_last diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/halo_profiler.py --- a/yt/extensions/halo_profiler.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,822 +0,0 @@ -""" -HaloProfiler class and member functions. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -import yt.lagos as lagos -from yt.lagos.HaloFinding import HaloFinder -from yt.logger import lagosLogger as mylog -import yt.raven as raven -from halo_filters import * -import numpy as na -import os -import h5py -import types - -PROFILE_RADIUS_THRESHOLD = 2 - -class HaloProfiler(lagos.ParallelAnalysisInterface): - "Radial profiling, filtering, and projections for halos in cosmological simulations." - def __init__(self, dataset, halos='multiple', halo_list_file='HopAnalysis.out', halo_list_format='yt_hop', - halo_finder_function=HaloFinder, halo_finder_args=None, halo_finder_kwargs=None, - use_density_center=False, density_center_exponent=1.0, use_field_max_center=None, - halo_radius=0.1, radius_units='1', n_profile_bins=50, - profile_output_dir='radial_profiles', projection_output_dir='projections', - projection_width=8.0, projection_width_units='mpc', project_at_level='max', - velocity_center=['bulk', 'halo'], filter_quantities=['id','center']): - """ - Initialize a HaloProfiler object. - :param halos (str): "multiple" for profiling more than one halo. In this mode halos are read in - from a list or identified with a halo finder. In "single" mode, the one and only halo - center is identified automatically as the location of the peak in the density field. - Default: "multiple". - :param halo_list_file (str): name of file containing the list of halos. The HaloProfiler will - look for this file in the data directory. Default: "HopAnalysis.out". - :param halo_list_format (str or dict): the format of the halo list file. "yt_hop" for the format - given by yt's halo finders. "enzo_hop" for the format written by enzo_hop. This keyword - can also be given in the form of a dictionary specifying the column in which various - properties can be found. For example, {"id": 0, "center": [1, 2, 3], "mass": 4, "radius": 5}. - Default: "yt_hop". - :param halo_finder_function (function): If halos is set to multiple and the file given by - halo_list_file does not exit, the halo finding function specified here will be called. - Default: HaloFinder (yt_hop). - :param halo_finder_args (tuple): args given with call to halo finder function. Default: None. - :param halo_finder_kwargs (dict): kwargs given with call to halo finder function. Default: None. - :param use_density_center (bool): re-center halos before performing profiles with an center of mass - weighted by overdensity. This is generally not needed. Default: False. - :param density_center_exponent (float): when use_density_center set to True, this specifies the - exponent, alpha, such that the halo center calculation is weighted by overdensity^alpha. - Default: 1.0. - :param use_field_max_center (str): another alternative for halo re-centering by selecting the - location of the maximum of the field given by this keyword. This is generally not needed. - Default: None. - :param halo_radius (float): if no halo radii are provided in the halo list file, this parameter is - used to specify the radius out to which radial profiles will be made. This keyword is also - used when halos is set to single. Default: 0.1. - :param radius_units (str): the units of halo_radius. Default: "1" (code units). - :param n_profile_bins (int): the number of bins in the radial profiles. Default: 50. - :param profile_output_dir (str): the subdirectory, inside the data directory, in which radial profile - output files will be created. The directory will be created if it does not exist. - Default: "radial_profiles". - :param projection_output_dir (str): the subdirectory, inside the data directory, in which projection - output files will be created. The directory will be created if it does not exist. - Default: "projections". - :param projection_width (float): the width of halo projections. Default: 8.0. - :param projection_width_units (str): the units of projection_width. Default: "mpc". - :param project_at_level (int or "max"): the maximum refinement level to be included in projections. - Default: "max" (maximum level within the dataset). - :param velocity_center (list): the method in which the halo bulk velocity is calculated (used for - calculation of radial and tangential velocities. Valid options are: - - ["bulk", "halo"] (Default): the velocity provided in the halo list - - ["bulk", "sphere"]: the bulk velocity of the sphere centered on the halo center. - - ["max", field]: the velocity of the cell that is the location of the maximum of the field - specified (used only when halos set to single). - :param filter_quantities (list): quantities from the original halo list file to be written out in the - filtered list file. Default: ['id','center']. - """ - - self.dataset = dataset - - self.profile_output_dir = profile_output_dir - self.projection_output_dir = projection_output_dir - self.n_profile_bins = n_profile_bins - self.projection_width = projection_width - self.projection_width_units = projection_width_units - self.project_at_level = project_at_level - self.filter_quantities = filter_quantities - if self.filter_quantities is None: self.filter_quantities = [] - - self.profile_fields = [] - self.projection_fields = [] - - self._halo_filters = [] - self.all_halos = [] - self.filtered_halos = [] - self._projection_halo_list = [] - - # Set halo finder function and parameters, if needed. - self.halo_finder_function = halo_finder_function - self.halo_finder_args = halo_finder_args - if self.halo_finder_args is None: self.halo_finder_args = () - self.halo_finder_kwargs = halo_finder_kwargs - if self.halo_finder_kwargs is None: self.halo_finder_kwargs = {} - - # Set option to get halos from hop or single halo at density maximum. - # multiple: get halos from hop - # single: get single halo from density maximum - self.halos = halos - if not(self.halos is 'multiple' or self.halos is 'single'): - mylog.error("Keyword, halos, must be either 'single' or 'multiple'.") - return None - - # Set halo list format. - # 'yt_hop': yt hop output. - # 'enzo_hop': enzo_hop output. - # dictionary: a dictionary containing fields and their corresponding columns. - self.halo_list_file = halo_list_file - if halo_list_format == 'yt_hop': - self.halo_list_format = {'id':0, 'mass':1, 'center':[7, 8, 9], 'velocity':[10, 11, 12], 'r_max':13} - elif halo_list_format == 'enzo_hop': - self.halo_list_format = {'id':0, 'center':[4, 5, 6]} - elif isinstance(halo_list_format, types.DictType): - self.halo_list_format = halo_list_format - else: - mylog.error("Keyword, halo_list_format, must be 'yt_hop', 'enzo_hop', or a dictionary of custom settings.") - return None - - # Option to recenter sphere on density center. - self.use_density_center = use_density_center - self.density_center_exponent = density_center_exponent - if self.use_density_center: - def _MatterDensityXTotalMass(field, data): - return na.power((data['Matter_Density'] * data['TotalMassMsun']), self.density_center_exponent) - def _Convert_MatterDensityXTotalMass(data): - return 1 - lagos.add_field("MatterDensityXTotalMass", units=r"", - function=_MatterDensityXTotalMass, - convert_function=_Convert_MatterDensityXTotalMass) - - # Option to recenter sphere on the location of a field max. - self.use_field_max_center = use_field_max_center - if self.use_field_max_center is not None: - self.use_density_center = False - - # Look for any field that might need to have the bulk velocity set. - self._need_bulk_velocity = False - for field in [hp['field'] for hp in self.profile_fields]: - if 'Velocity' in field or 'Mach' in field: - self._need_bulk_velocity = True - break - - # Check validity for VelocityCenter parameter which toggles how the - # velocity is zeroed out for radial velocity profiles. - self.velocity_center = velocity_center[:] - if self.velocity_center[0] == 'bulk': - if self.velocity_center[1] == 'halo' and \ - self.halos is 'single': - mylog.error("Parameter, VelocityCenter, must be set to 'bulk sphere' or 'max ' with halos flag set to 'single'.") - return None - if self.velocity_center[1] == 'halo' and \ - self.halo_list_format is 'enzo_hop': - mylog.error("Parameter, VelocityCenter, must be 'bulk sphere' for old style hop output files.") - return None - if not(self.velocity_center[1] == 'halo' or - self.velocity_center[1] == 'sphere'): - mylog.error("Second value of VelocityCenter must be either 'halo' or 'sphere' if first value is 'bulk'.") - return None - elif self.velocity_center[0] == 'max': - if self.halos is 'multiple': - mylog.error("Getting velocity center from a max field value only works with halos='single'.") - return None - else: - mylog.error("First value of parameter, VelocityCenter, must be either 'bulk' or 'max'.") - return None - - # Create dataset object. - self.pf = lagos.EnzoStaticOutput(self.dataset) - self.pf.h - if self.halos is 'single' or not 'r_max' in self.halo_list_format: - self.halo_radius = halo_radius / self.pf[radius_units] - - # Get halo(s). - if self.halos is 'single': - v, center = self.pf.h.find_max('Density') - singleHalo = {} - singleHalo['center'] = center - singleHalo['r_max'] = self.halo_radius * self.pf.units['mpc'] - singleHalo['id'] = 0 - self.all_halos.append(singleHalo) - elif self.halos is 'multiple': - # Get hop data. - self._load_halo_data() - if len(self.all_halos) == 0: - mylog.error("No halos loaded, there will be nothing to do.") - return None - else: - mylog.error("I don't know whether to get halos from hop or from density maximum. This should not have happened.") - return None - - def add_halo_filter(self, function, *args, **kwargs): - "Add a halo filter to the filter list." - - self._halo_filters.append({'function':function, 'args':args, 'kwargs':kwargs}) - - def add_profile(self, field, weight_field=None, accumulation=False): - "Add a field for profiling." - - self.profile_fields.append({'field':field, 'weight_field':weight_field, 'accumulation':accumulation}) - - def add_projection(self, field, weight_field=None): - "Add a field for projection." - - self.projection_fields.append({'field':field, 'weight_field':weight_field}) - - @lagos.parallel_blocking_call - def make_profiles(self, filename=None, prefilters=None, **kwargs): - "Make radial profiles for all halos on the list." - - # Reset filtered halo list. - self.filtered_halos = [] - - # Check to see if the VirialFilter has been added to the filter list. - # If a lower mass cutoff is being used, use it to make a pre-filter. - if prefilters is None: prefilters = [] - virial_prefilter = None - virial_prefilter_safety_factor = 0.5 - all_filter_functions = [hf['function'] for hf in self._halo_filters] - virial_filter = VirialFilter in all_filter_functions - if 'mass' in self.halo_list_format and VirialFilter in all_filter_functions: - vFilter = self._halo_filters[all_filter_functions.index(VirialFilter)] - if vFilter['kwargs'].has_key('virial_filters') and \ - vFilter['kwargs']['virial_filters'] is not None: - all_vqFilters = [vqf[0] for vqf in vFilter['kwargs']['virial_filters']] - if 'TotalMassMsun' in all_vqFilters: - mass_filter = vFilter['kwargs']['virial_filters'][all_vqFilters.index('TotalMassMsun')] - if '>' in mass_filter[1]: - virial_prefilter = "halo['mass'] %s %f * %s" % (mass_filter[1], virial_prefilter_safety_factor, mass_filter[2]) - prefilters.append(virial_prefilter) - elif '<' in mass_filter[1]: - virial_prefilter = "halo['mass'] %s %f * %s" % (mass_filter[1], (1./virial_prefilter_safety_factor), mass_filter[2]) - prefilters.append(virial_prefilter) - - # Add profile fields necessary for calculating virial quantities. - if virial_filter: self._check_for_needed_profile_fields() - - outputDir = "%s/%s" % (self.pf.fullpath, self.profile_output_dir) - self.__check_directory(outputDir) - - # Profile all halos. - for halo in self._get_objs('all_halos', round_robin=True): - - # Apply prefilters to avoid profiling unwanted halos. - filter_result = True - haloQuantities = {} - if prefilters is not None: - for prefilter in prefilters: - if not eval(prefilter): - filter_result = False - break - - if filter_result and len(self.profile_fields) > 0: - - profile_filename = "%s/Halo_%04d_profile.dat" % (outputDir, halo['id']) - - profiledHalo = self._get_halo_profile(halo, profile_filename, virial_filter=virial_filter) - - if profiledHalo is None: - continue - - # Apply filter and keep track of the quantities that are returned. - for hFilter in self._halo_filters: - filter_result, filterQuantities = hFilter['function'](profiledHalo, *hFilter['args'], **hFilter['kwargs']) - - if not filter_result: break - - if filterQuantities is not None: - haloQuantities.update(filterQuantities) - - if filter_result: - for quantity in self.filter_quantities: - if halo.has_key(quantity): haloQuantities[quantity] = halo[quantity] - - self.filtered_halos.append(haloQuantities) - - self.filtered_halos = self._mpi_catlist(self.filtered_halos) - self.filtered_halos.sort(key = lambda a:a['id']) - - if filename is not None: - self._write_filtered_halo_list(filename, **kwargs) - - def _get_halo_profile(self, halo, filename, virial_filter=True, force_write=False): - """ - Profile a single halo and write profile data to a file. - If file already exists, read profile data from file. - Return a dictionary of id, center, and virial quantities if virial_filter is True. - """ - - # Read profile from file if it already exists. - # If not, profile will be None. - profile = self._read_profile(filename) - - # Make profile if necessary. - newProfile = profile is None - if newProfile: - - r_min = 2 * self.pf.h.get_smallest_dx() * self.pf['mpc'] - if (halo['r_max'] / r_min < PROFILE_RADIUS_THRESHOLD): - mylog.error("Skipping halo with r_max / r_min = %f." % (halo['r_max']/r_min)) - return None - - sphere = self.pf.h.sphere(halo['center'], halo['r_max']/self.pf.units['mpc']) - if len(sphere._grids) == 0: return None - new_sphere = False - - if self.use_density_center: - dc_x = sphere.quantities['WeightedAverageQuantity']('x', 'MatterDensityXTotalMass') - dc_y = sphere.quantities['WeightedAverageQuantity']('y', 'MatterDensityXTotalMass') - dc_z = sphere.quantities['WeightedAverageQuantity']('z', 'MatterDensityXTotalMass') - mylog.info("Moving halo center from %s to %s." % (halo['center'], [dc_x, dc_y, dc_z])) - halo['center'] = [dc_x, dc_y, dc_z] - new_sphere = True - - if self.use_field_max_center is not None: - ma, maxi, mx, my, mz, mg = sphere.quantities['MaxLocation'](self.use_field_max_center) - mylog.info("Moving halo center from %s to %s." % (halo['center'], [mx, my, mz])) - halo['center'] = [mx, my, mz] - new_sphere = True - - if new_sphere: - # Temporary solution to memory leak. - for g in self.pf.h.grids: - g.clear_data() - sphere.clear_data() - del sphere - sphere = self.pf.h.sphere(halo['center'], halo['r_max']/self.pf.units['mpc']) - - if self._need_bulk_velocity: - # Set bulk velocity to zero out radial velocity profiles. - if self.velocity_center[0] == 'bulk': - if self.velocity_center[1] == 'halo': - sphere.set_field_parameter('bulk_velocity', halo['velocity']) - elif self.velocity_center[1] == 'sphere': - sphere.set_field_parameter('bulk_velocity', sphere.quantities['BulkVelocity']()) - else: - mylog.error("Invalid parameter: VelocityCenter.") - elif self.velocity_center[0] == 'max': - max_grid, max_cell, max_value, max_location = self.pf.h.find_max_cell_location(self.velocity_center[1]) - sphere.set_field_parameter('bulk_velocity', [max_grid['x-velocity'][max_cell], - max_grid['y-velocity'][max_cell], - max_grid['z-velocity'][max_cell]]) - - profile = lagos.BinnedProfile1D(sphere, self.n_profile_bins, "RadiusMpc", - r_min, halo['r_max'], - log_space=True, lazy_reader=False) - for hp in self.profile_fields: - profile.add_fields(hp['field'], weight=hp['weight_field'], accumulation=hp['accumulation']) - - if virial_filter: - self._add_actual_overdensity(profile) - - if newProfile: - mylog.info("Writing halo %d" % halo['id']) - profile.write_out(filename, format='%0.6e') - elif force_write: - mylog.info("Re-writing halo %d" % halo['id']) - self._write_profile(profile, filename, format='%0.6e') - - if newProfile: - # Temporary solution to memory leak. - for g in self.pf.h.grids: - g.clear_data() - sphere.clear_data() - del sphere - - return profile - - @lagos.parallel_blocking_call - def make_projections(self, axes=[0, 1, 2], halo_list='filtered', save_images=False, save_cube=True): - "Make projections of all halos using specified fields." - - # Get list of halos for projecting. - if halo_list == 'filtered': - self._halo_projection_list = self.filtered_halos - elif halo_list == 'all': - self._halo_projection_list = self.all_halos - elif isinstance(halo_list, types.StringType): - self._halo_projection_list = self._read_halo_list(halo_list) - elif isinstance(halo_list, types.ListType): - self._halo_projection_list = halo_list - else: - mylog.error("Keyword, halo_list', must be 'filtered', 'all', a filename, or an actual list.") - return - - if len(self._halo_projection_list) == 0: - mylog.error("Halo list for projections is empty.") - return - - # Set resolution for fixed resolution output. - if save_cube: - if self.project_at_level == 'max': - proj_level = self.pf.h.max_level - else: - proj_level = int(self.project_at_level) - proj_dx = self.pf.units[self.projection_width_units] / self.pf.parameters['TopGridDimensions'][0] / \ - (self.pf.parameters['RefineBy']**proj_level) - projectionResolution = int(self.projection_width / proj_dx) - - outputDir = "%s/%s" % (self.pf.fullpath, self.projection_output_dir) - self.__check_directory(outputDir) - - center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] + self.pf.parameters['DomainRightEdge'][w]) - for w in range(self.pf.parameters['TopGridRank'])] - - for halo in self._get_objs('_halo_projection_list', round_robin=True): - if halo is None: - continue - # Check if region will overlap domain edge. - # Using non-periodic regions is faster than using periodic ones. - leftEdge = [(halo['center'][w] - 0.5 * self.projection_width/self.pf.units[self.projection_width_units]) - for w in range(len(halo['center']))] - rightEdge = [(halo['center'][w] + 0.5 * self.projection_width/self.pf.units[self.projection_width_units]) - for w in range(len(halo['center']))] - - mylog.info("Projecting halo %04d in region: [%f, %f, %f] to [%f, %f, %f]." % - (halo['id'], leftEdge[0], leftEdge[1], leftEdge[2], rightEdge[0], rightEdge[1], rightEdge[2])) - - need_per = False - for w in range(len(halo['center'])): - if ((leftEdge[w] < self.pf.parameters['DomainLeftEdge'][w]) or - (rightEdge[w] > self.pf.parameters['DomainRightEdge'][w])): - need_per = True - break - - if need_per: - region = self.pf.h.periodic_region(halo['center'], leftEdge, rightEdge) - else: - region = self.pf.h.region(halo['center'], leftEdge, rightEdge) - - # Make projections. - if not isinstance(axes, types.ListType): axes = list([axes]) - for w in axes: - # Create a plot collection. - pc = raven.PlotCollection(self.pf, center=center) - # YT projections do not follow the right-hand rule. - coords = range(3) - del coords[w] - x_axis = coords[0] - y_axis = coords[1] - - for hp in self.projection_fields: - pc.add_projection(hp['field'], w, weight_field=hp['weight_field'], data_source=region) - - # Set x and y limits, shift image if it overlaps domain boundary. - if need_per: - pw = self.projection_width/self.pf.units[self.projection_width_units] - shift_projections(self.pf, pc, halo['center'], center, w) - # Projection has now been shifted to center of box. - proj_left = [center[x_axis]-0.5*pw, center[y_axis]-0.5*pw] - proj_right = [center[x_axis]+0.5*pw, center[y_axis]+0.5*pw] - else: - proj_left = [leftEdge[x_axis], leftEdge[y_axis]] - proj_right = [rightEdge[x_axis], rightEdge[y_axis]] - - pc.set_xlim(proj_left[0], proj_right[0]) - pc.set_ylim(proj_left[1], proj_right[1]) - - # Save projection data to hdf5 file. - if save_cube: - axis_labels = ['x', 'y', 'z'] - dataFilename = "%s/Halo_%04d_%s_data.h5" % \ - (outputDir, halo['id'], axis_labels[w]) - mylog.info("Saving projection data to %s." % dataFilename) - - output = h5py.File(dataFilename, "a") - # Create fixed resolution buffer for each projection and write them out. - for e, hp in enumerate(self.projection_fields): - frb = raven.FixedResolutionBuffer(pc.plots[e].data, (proj_left[0], proj_right[0], proj_left[1], proj_right[1]), - (projectionResolution, projectionResolution), - antialias=False) - dataset_name = "%s_%s" % (hp['field'], hp['weight_field']) - if dataset_name in output.listnames(): del output[dataset_name] - output.create_dataset(dataset_name, data=frb[hp['field']]) - output.close() - - if save_images: - pc.save("%s/Halo_%04d" % (outputDir, halo['id']), force_save=True) - - del region - - def _add_actual_overdensity(self, profile): - "Calculate overdensity from TotalMassMsun and CellVolume fields." - - if 'ActualOverdensity' in profile.keys(): - return - - rho_crit_now = 1.8788e-29 * self.pf['CosmologyHubbleConstantNow']**2.0 * \ - self.pf['CosmologyOmegaMatterNow'] # g cm^-3 - Msun2g = 1.989e33 - rho_crit = rho_crit_now * ((1.0 + self.pf['CosmologyCurrentRedshift'])**3.0) - - profile['ActualOverdensity'] = (Msun2g * profile['TotalMassMsun']) / \ - profile['CellVolume'] / rho_crit - - def _check_for_needed_profile_fields(self): - "Make sure CellVolume and TotalMass fields are added so virial quantities can be calculated." - all_profile_fields = [hp['field'] for hp in self.profile_fields] - if not 'CellVolume' in all_profile_fields: - mylog.info("Adding CellVolume field to so virial quantities can be calculated") - self.add_profile('CellVolume', weight_field=None, accumulation=True) - if not 'TotalMassMsun' in all_profile_fields: - mylog.info("Adding TotalMassMsun field to so virial quantities can be calculated") - self.add_profile('TotalMassMsun', weight_field=None, accumulation=True) - - def _load_halo_data(self, filename=None): - "Read hop output file or run hop if it doesn't exist." - - # Don't run if hop data already loaded. - if self.all_halos: - return - - if filename is None: - filename = self.halo_list_file - - hopFile = "%s/%s" % (self.pf.fullpath, filename) - - if not(os.path.exists(hopFile)): - mylog.info("Hop file not found, running hop to get halos.") - self._run_hop(hopFile) - - self.all_halos = self._read_halo_list(hopFile) - - def _read_halo_list(self, listFile): - """ - Read halo list from aue file. - Allow for columnar data in varying formats. - """ - - def __isE(arg): - parts = arg.lower().split('e') - if len(parts) != 2: return False - return not (True in [q.isalpha() for q in ''.join(parts)]) - - def __get_num(arg): - if __isE(arg): - return float(arg) - if arg != arg.swapcase(): - return arg - return float(arg) - - mylog.info("Reading halo information from %s." % listFile) - haloList = [] - listLines = file(listFile) - - fields = self.halo_list_format.keys() - getID = not 'id' in fields - getR_max = not 'r_max' in fields - - for line in listLines: - line = line.strip() - if not(line.startswith('#')): - halo = {} - onLine = line.split() - for field in fields: - if isinstance(self.halo_list_format[field], types.ListType): - halo[field] = [__get_num(onLine[q]) for q in self.halo_list_format[field]] - else: - halo[field] = __get_num(onLine[self.halo_list_format[field]]) - if getID: halo['id'] = len(haloList) - if getR_max: - halo['r_max'] = self.halo_radius * self.pf.units['mpc'] - else: - halo['r_max'] *= self.pf.units['mpc'] - haloList.append(halo) - - mylog.info("Loaded %d halos." % (len(haloList))) - return haloList - - def _read_profile(self, profileFile): - "Read radial profile from file. Return None if it doesn't have all the fields requested." - - # Check to see if file exists. - if not os.path.exists(profileFile): - return None - - f = open(profileFile, 'r') - lines = f.readlines() - f.close() - - # Get fields from header. - header = lines.pop(0) - header = header.strip() - fields = header.split() - # First string is '#'. - fields.pop(0) - - profile = {} - profile_obj = FakeProfile(self.pf) - for field in fields: - profile[field] = [] - - # Check if all fields needed are present. - all_profile_fields = [hp['field'] for hp in self.profile_fields] - for field in all_profile_fields: - if not field in profile: - return None - - # Fill profile fields, skip bad values. - for line in lines: - line = line.strip() - onLine = line.split() - lineOK = True - for value in onLine: - if value.isalpha(): - lineOK = False - break - if lineOK: - for q, field in enumerate(fields): - profile[field].append(float(onLine[q])) - - for field in fields: - profile[field] = na.array(profile[field]) - - profile_obj._data = profile - - if len(profile[fields[0]]) > 1: - return profile_obj - else: - return None - - @lagos.parallel_blocking_call - def _run_hop(self, hopFile): - "Run hop to get halos." - - hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args, **self.halo_finder_kwargs) - hop_results.write_out(hopFile) - - del hop_results - self.pf.h.clear_all_data() - - @lagos.parallel_root_only - def _write_filtered_halo_list(self, filename, format="%s"): - """ - Write out list of filtered halos along with any quantities - picked up during the filtering process. - """ - - if len(self.filtered_halos) == 0: - mylog.error("No halos in filtered list.") - return - - filename = "%s/%s" % (self.pf.fullpath, filename) - mylog.info("Writing filtered halo list to %s." % filename) - file = open(filename, "w") - fields = [field for field in sorted(self.filtered_halos[0])] - halo_fields = [] - for halo_field in self.filter_quantities: - if halo_field in fields: - fields.remove(halo_field) - halo_fields.append(halo_field) - # Make it so number of fields in header is same as number of data columns. - header_fields = [] - for halo_field in halo_fields: - if isinstance(self.filtered_halos[0][halo_field], types.ListType): - header_fields.extend(["%s[%d]" % (halo_field, q) - for q in range(len(self.filtered_halos[0][halo_field]))]) - else: - header_fields.append(halo_field) - file.write("# ") - file.write("\t".join(header_fields + fields + ["\n"])) - - for halo in self.filtered_halos: - for halo_field in halo_fields: - if isinstance(halo[halo_field], types.ListType): - field_data = na.array(halo[halo_field]) - field_data.tofile(file, sep="\t", format=format) - else: - if halo_field == 'id': - file.write("%04d" % halo[halo_field]) - else: - file.write("%s" % halo[halo_field]) - file.write("\t") - field_data = na.array([halo[field] for field in fields]) - field_data.tofile(file, sep="\t", format=format) - file.write("\n") - file.close() - - def _write_profile(self, profile, filename, format="%0.16e"): - fid = open(filename, "w") - fields = [field for field in sorted(profile.keys()) if field != "UsedBins"] - fid.write("\t".join(["#"] + fields + ["\n"])) - field_data = na.array([profile[field] for field in fields]) - for line in range(field_data.shape[1]): - field_data[:, line].tofile(fid, sep="\t", format=format) - fid.write("\n") - fid.close() - - @lagos.parallel_root_only - def __check_directory(self, outputDir): - if (os.path.exists(outputDir)): - if not(os.path.isdir(outputDir)): - mylog.error("Output directory exists, but is not a directory: %s." % outputDir) - raise IOError(outputDir) - else: - os.mkdir(outputDir) - -def shift_projections(pf, pc, oldCenter, newCenter, axis): - """ - Shift projection data around. - This is necessary when projecting a preiodic region. - """ - offset = [newCenter[q]-oldCenter[q] for q in range(len(oldCenter))] - width = [pf.parameters['DomainRightEdge'][q]-pf.parameters['DomainLeftEdge'][q] for q in range(len(oldCenter))] - - del offset[axis] - del width[axis] - - for plot in pc.plots: - # Get name of data field. - other_fields = {'px':True, 'py':True, 'pdx':True, 'pdy':True, 'weight_field':True} - for pfield in plot.data.data.keys(): - if not(other_fields.has_key(pfield)): - field = pfield - break - - # Shift x and y positions. - plot['px'] += offset[0] - plot['py'] += offset[1] - - # Wrap off-edge cells back around to other side (periodic boundary conditions). - plot['px'][plot['px'] < 0] += width[0] - plot['py'][plot['py'] < 0] += width[1] - plot['px'][plot['px'] > width[0]] -= width[0] - plot['py'][plot['py'] > width[1]] -= width[1] - - # After shifting, some cells have fractional coverage on both sides of the box. - # Find those cells and make copies to be placed on the other side. - - # Cells hanging off the right edge. - add_x_px = plot['px'][plot['px'] + 0.5 * plot['pdx'] > width[0]] - add_x_px -= width[0] - add_x_py = plot['py'][plot['px'] + 0.5 * plot['pdx'] > width[0]] - add_x_pdx = plot['pdx'][plot['px'] + 0.5 * plot['pdx'] > width[0]] - add_x_pdy = plot['pdy'][plot['px'] + 0.5 * plot['pdx'] > width[0]] - add_x_field = plot[field][plot['px'] + 0.5 * plot['pdx'] > width[0]] - add_x_weight_field = plot['weight_field'][plot['px'] + 0.5 * plot['pdx'] > width[0]] - - # Cells hanging off the left edge. - add2_x_px = plot['px'][plot['px'] - 0.5 * plot['pdx'] < 0] - add2_x_px += width[0] - add2_x_py = plot['py'][plot['px'] - 0.5 * plot['pdx'] < 0] - add2_x_pdx = plot['pdx'][plot['px'] - 0.5 * plot['pdx'] < 0] - add2_x_pdy = plot['pdy'][plot['px'] - 0.5 * plot['pdx'] < 0] - add2_x_field = plot[field][plot['px'] - 0.5 * plot['pdx'] < 0] - add2_x_weight_field = plot['weight_field'][plot['px'] - 0.5 * plot['pdx'] < 0] - - # Cells hanging off the top edge. - add_y_px = plot['px'][plot['py'] + 0.5 * plot['pdy'] > width[1]] - add_y_py = plot['py'][plot['py'] + 0.5 * plot['pdy'] > width[1]] - add_y_py -= width[1] - add_y_pdx = plot['pdx'][plot['py'] + 0.5 * plot['pdy'] > width[1]] - add_y_pdy = plot['pdy'][plot['py'] + 0.5 * plot['pdy'] > width[1]] - add_y_field = plot[field][plot['py'] + 0.5 * plot['pdy'] > width[1]] - add_y_weight_field = plot['weight_field'][plot['py'] + 0.5 * plot['pdy'] > width[1]] - - # Cells hanging off the bottom edge. - add2_y_px = plot['px'][plot['py'] - 0.5 * plot['pdy'] < 0] - add2_y_py = plot['py'][plot['py'] - 0.5 * plot['pdy'] < 0] - add2_y_py += width[1] - add2_y_pdx = plot['pdx'][plot['py'] - 0.5 * plot['pdy'] < 0] - add2_y_pdy = plot['pdy'][plot['py'] - 0.5 * plot['pdy'] < 0] - add2_y_field = plot[field][plot['py'] - 0.5 * plot['pdy'] < 0] - add2_y_weight_field = plot['weight_field'][plot['py'] - 0.5 * plot['pdy'] < 0] - - # Add the hanging cells back to the projection data. - plot.data['px'] = na.concatenate([plot['px'], add_x_px, add_y_px, add2_x_px, add2_y_px]) - plot.data['py'] = na.concatenate([plot['py'], add_x_py, add_y_py, add2_x_py, add2_y_py]) - plot.data['pdx'] = na.concatenate([plot['pdx'], add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx]) - plot.data['pdy'] = na.concatenate([plot['pdy'], add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy]) - plot.data[field] = na.concatenate([plot[field], add_x_field, add_y_field, add2_x_field, add2_y_field]) - plot.data['weight_field'] = na.concatenate([plot['weight_field'], - add_x_weight_field, add_y_weight_field, add2_x_weight_field, add2_y_weight_field]) - - # Delete original copies of hanging cells. - del add_x_px, add_y_px, add2_x_px, add2_y_px - del add_x_py, add_y_py, add2_x_py, add2_y_py - del add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx - del add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy - del add_x_field, add_y_field, add2_x_field, add2_y_field - del add_x_weight_field, add_y_weight_field, add2_x_weight_field, add2_y_weight_field - -class FakeProfile(lagos.ParallelAnalysisInterface): - """ - This is used to mimic a profile object when reading profile data from disk. - """ - def __init__(self, pf): - self.pf = pf - self._data = {} - - def __getitem__(self, key): - return self._data[key] - - def keys(self): - return self._data.keys() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/image_panner/__init__.py --- a/yt/extensions/image_panner/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -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 . -""" - -from vm_panner import VariableMeshPanner, WindowedVariableMeshPanner, \ - MultipleWindowVariableMeshPanner, ImageSaver, \ - PanningCeleritasStreamer, NonLocalDataImagePanner diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/image_panner/pan_and_scan_widget.py --- a/yt/extensions/image_panner/pan_and_scan_widget.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,332 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -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 . -""" - -# Major library imports -from vm_panner import VariableMeshPanner -from numpy import linspace, meshgrid, pi, sin, mgrid, zeros - -# Enthought library imports -from enthought.enable.api import Component, ComponentEditor, Window -from enthought.traits.api import HasTraits, Instance, Button, Any, Callable, \ - on_trait_change, Bool, DelegatesTo, List, Enum, Int, Property, Str, \ - cached_property -from enthought.traits.ui.api import \ - Group, View, Item, VGroup, InstanceEditor - -# Chaco imports -from enthought.chaco.api import ArrayPlotData, jet, Plot, HPlotContainer, \ - ColorBar, DataRange1D, DataRange2D, LinearMapper, ImageData, \ - CMapImagePlot, OverlayPlotContainer -from enthought.chaco.tools.api import PanTool, ZoomTool, RangeSelection, \ - RangeSelectionOverlay, RangeSelection -from enthought.chaco.tools.image_inspector_tool import ImageInspectorTool, \ - ImageInspectorOverlay - -if not hasattr(DataRange2D, "_subranges_updated"): - print "You'll need to add _subranges updated to enthought/chaco/data_range_2d.py" - print 'Add this at the correct indentation level:' - print - print ' @on_trait_change("_xrange.updated,_yrange.updated")' - print ' def _subranges_updated(self):' - print ' self.updated = True' - print - raise RuntimeError - -# We like the algae colormap; for now we re-implement it here. - -from enthought.chaco.api import \ - ColorMapper, \ - color_map_functions, color_map_dict, color_map_name_dict - -def algae(range, **traits): - _data = {'red': ((0.0, 80/256., 80/256.), - (0.2, 0.0, 0.0), - (0.4, 0.0, 0.0), - (0.6, 256/256., 256/256.), - (0.95, 256/256., 256/256.), - (1.0, 150/256., 150/256.)), - 'green': ((0.0, 0/256., 0/256.), - (0.2, 0/256., 0/256.), - (0.4, 130/256., 130/256.), - (0.6, 256/256., 256/256.), - (1.0, 0.0, 0.0)), - 'blue': ((0.0, 80/256., 80/256.), - (0.2, 220/256., 220/256.), - (0.4, 0.0, 0.0), - (0.6, 20/256., 20/256.), - (1.0, 0.0, 0.0))} - return ColorMapper.from_segment_map(_data, range=range, **traits) -color_map_functions.append(algae) -color_map_dict[algae] = "algae" -color_map_name_dict["algae"] = algae - -class FunctionImageData(ImageData): - # The function to call with the low and high values of the range. - # It should return an array of values. - func = Callable - - # A reference to a datarange - data_range = Instance(DataRange2D) - - def __init__(self, **kw): - # Explicitly call the AbstractDataSource constructor because - # the ArrayDataSource ctor wants a data array - ImageData.__init__(self, **kw) - self.recalculate() - - @on_trait_change('data_range.updated') - def recalculate(self): - if self.func is not None and self.data_range is not None: - newarray = self.func(self.data_range.low, self.data_range.high) - ImageData.set_data(self, newarray) - else: - self._data = zeros((512,512),dtype=float) - - def set_data(self, *args, **kw): - raise RuntimeError("Cannot set numerical data on a FunctionDataSource") - - def set_mask(self, mask): - raise NotImplementedError - - def remove_mask(self): - raise NotImplementedError - -class ImagePixelizerHelper(object): - index = None - def __init__(self, panner, run_callbacks = False): - self.panner = panner - self.run_callbacks = run_callbacks - - def __call__(self, low, high): - b = self.panner.set_low_high(low, high) - if self.run_callbacks: - self.panner._run_callbacks() - if self.index is not None: - num_x_ticks = b.shape[0] + 1 - num_y_ticks = b.shape[1] + 1 - xs = mgrid[low[0]:high[0]:num_x_ticks*1j] - ys = mgrid[low[1]:high[1]:num_y_ticks*1j] - self.index.set_data( xs, ys ) - return b - -class ZoomedPlotUpdater(object): - fid = None - def __init__(self, panner, zoom_factor=4): - """ - Supply this an a viewport_callback argument to a panner if you want to - update a second panner in a smaller portion at higher resolution. If - you then set the *fid* property, you can also have it update a - FunctionImageData datarange. *panner* is the panner to update (not the - one this is a callback to) and *zoom_factor* is how much to zoom in by. - """ - self.panner = panner - self.zoom_factor = zoom_factor - - def __call__(self, xlim, ylim): - self.panner.xlim = xlim - self.panner.ylim = ylim - self.panner.zoom(self.zoom_factor) - nxlim = self.panner.xlim - nylim = self.panner.ylim - if self.fid is not None: - self.fid.data_range.set_bounds( - (nxlim[0], nylim[0]), (nxlim[1], nylim[1])) - -class VMImagePlot(HasTraits): - plot = Instance(Plot) - fid = Instance(FunctionImageData) - img_plot = Instance(CMapImagePlot) - panner = Instance(VariableMeshPanner) - helper = Instance(ImagePixelizerHelper) - fields = List - - def __init__(self, *args, **kwargs): - super(VMImagePlot, self).__init__(**kwargs) - self.add_trait("field", Enum(*self.fields)) - self.field = self.panner.field - - def _plot_default(self): - pd = ArrayPlotData() - plot = Plot(pd, padding = 0) - self.fid._data = self.panner.buffer - - pd.set_data("imagedata", self.fid) - - img_plot = plot.img_plot("imagedata", colormap=algae, - interpolation='nearest', - xbounds=(0.0, 1.0), - ybounds=(0.0, 1.0))[0] - self.fid.data_range = plot.range2d - self.helper.index = img_plot.index - self.img_plot = img_plot - return plot - - def _field_changed(self, old, new): - self.panner.field = new - self.fid.recalculate() - - def _fid_default(self): - return FunctionImageData(func = self.helper) - - def _helper_default(self): - return ImagePixelizerHelper(self.panner) - - def _panner_changed(self, old, new): - index = self.helper.index - self.helper = ImagePixelizerHelper(new) - self.helper.index = index - self.fid.func = self.helper - self.fid.recalculate() - - def _fields_default(self): - keys = [] - for field in self.panner.source.keys(): - if field not in ['px','py','pdx','pdy', - 'pz','pdz','weight_field']: - keys.append(field) - return keys - -class VariableMeshPannerView(HasTraits): - - plot = Instance(Plot) - spawn_zoom = Button - vm_plot = Instance(VMImagePlot) - use_tools = Bool(True) - full_container = Instance(HPlotContainer) - container = Instance(OverlayPlotContainer) - - traits_view = View( - Group( - Item('full_container', - editor=ComponentEditor(size=(512,512)), - show_label=False), - Item('field', show_label=False), - orientation = "vertical"), - width = 800, height=800, - resizable=True, title="Pan and Scan", - ) - - def _vm_plot_default(self): - return VMImagePlot(panner=self.panner) - - def __init__(self, **kwargs): - super(VariableMeshPannerView, self).__init__(**kwargs) - # Create the plot - self.add_trait("field", DelegatesTo("vm_plot")) - - plot = self.vm_plot.plot - img_plot = self.vm_plot.img_plot - - if self.use_tools: - plot.tools.append(PanTool(img_plot)) - zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) - plot.overlays.append(zoom) - imgtool = ImageInspectorTool(img_plot) - img_plot.tools.append(imgtool) - overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool, - bgcolor="white", border_visible=True) - img_plot.overlays.append(overlay) - - - image_value_range = DataRange1D(self.vm_plot.fid) - cbar_index_mapper = LinearMapper(range=image_value_range) - self.colorbar = ColorBar(index_mapper=cbar_index_mapper, - plot=img_plot, - padding_right=40, - resizable='v', - width=30) - - self.colorbar.tools.append( - PanTool(self.colorbar, constrain_direction="y", constrain=True)) - zoom_overlay = ZoomTool(self.colorbar, axis="index", tool_mode="range", - always_on=True, drag_button="right") - self.colorbar.overlays.append(zoom_overlay) - - # create a range selection for the colorbar - range_selection = RangeSelection(component=self.colorbar) - self.colorbar.tools.append(range_selection) - self.colorbar.overlays.append( - RangeSelectionOverlay(component=self.colorbar, - border_color="white", - alpha=0.8, fill_color="lightgray")) - - # we also want to the range selection to inform the cmap plot of - # the selection, so set that up as well - range_selection.listeners.append(img_plot) - - self.full_container = HPlotContainer(padding=30) - self.container = OverlayPlotContainer(padding=0) - self.full_container.add(self.colorbar) - self.full_container.add(self.container) - self.container.add(self.vm_plot.plot) - -class OutputSelector(HasTraits): - outputs = List - main_plot = Instance(VariableMeshPannerView) - main_panner = Property(depends_on = "pf") - weight_field = Str("Density") - - pf = Any - source = Any - axis = Int(0) - - traits_view = View(VGroup( - Item('output'), - Item('main_plot'), - ) - ) - - def __init__(self, **kwargs): - super(OutputSelector, self).__init__(**kwargs) - self.add_trait("output", Enum(*self.outputs)) - self.output = self.outputs[-1] - self.main_plot - - def _output_default(self): - return self.outputs[0] - - def _output_changed(self, old, new): - # We get a string here - import yt.mods - self.pf = yt.mods.load(new, data_style="enzo_packed_3d") - self.source = yt.mods.projload(self.pf, self.axis, "Density") - self.main_panner.field = self.main_plot.vm_plot.field - self.main_plot.panner = self.main_plot.vm_plot.panner = \ - self.main_plot.vm_plot.helper.panner = self.main_panner - self.main_plot.vm_plot.field = self.main_panner.field - - def _main_plot_default(self): - vmpv = VariableMeshPannerView(panner = self.main_panner) - vmpv.vm_plot.helper.run_callbacks = True - return vmpv - - @cached_property - def _get_main_panner(self): - return self.pf.h.image_panner(self.source, (512, 512), "Density") - -def pan_and_scan_directory(dir_name): - import glob, os - fns = [ fn[:-10] for fn in - glob.glob(os.path.join(dir_name, "**", "*.hierarchy")) ] - selector = OutputSelector(outputs = fns) - return selector diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/image_panner/vm_panner.py --- a/yt/extensions/image_panner/vm_panner.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,495 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -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 . -""" - -import numpy as na -import types, os -from yt.raven import FixedResolutionBuffer, ObliqueFixedResolutionBuffer -from yt.lagos import data_object_registry, AMRProjBase, AMRSliceBase, \ - x_dict, y_dict -from yt.funcs import * - -class VariableMeshPanner(object): - _buffer = None - _hold = False - - def __init__(self, source, size, field, callback = None, - viewport_callback = None): - """ - This class describes a meta-view onto a 2D data interface. You provide - it with a slice or a projection (*source*), a tuple of the x and y - resolution of the final image you want (*size) and a *field* to - display, and then it will generate a new buffer each time you call its - methods for moving the window around and changing its size. *callback* - is a routine called with the new buffer each time the buffer changes - and *viewport_callback* is called with the new *xlim* and *ylim* values - each time the viewport changes. - """ - #if not isinstance(source, (AMRProjBase, AMRSliceBase)): - # raise RuntimeError - if callback is None: - callback = lambda a: None - self.callback = callback - if viewport_callback is None: - viewport_callback = lambda a, b: None - self.viewport_callback = viewport_callback - self.size = size - self.source = source - self.field = field - self.xlim, self.ylim = self.bounds - - def _run_callbacks(self): - if self._hold: return - self.callback(self.buffer) - self.viewport_callback(self.xlim, self.ylim) - - @property - def bounds(self): - if not hasattr(self, 'pf'): self.pf = self.source.pf - DLE, DRE = self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"] - ax = self.source.axis - xax, yax = x_dict[ax], y_dict[ax] - xbounds = DLE[xax], DRE[xax] - ybounds = DLE[yax], DRE[yax] - return (xbounds, ybounds) - - @property - def width(self): - Wx = self.xlim[1] - self.xlim[0] - Wy = self.ylim[1] - self.ylim[0] - return (Wx, Wy) - - def zoom(self, factor): - """ - This zooms the window by *factor*. - """ - Wx, Wy = self.width - centerx = self.xlim[0] + Wx*0.5 - centery = self.ylim[0] + Wy*0.5 - nWx, nWy = Wx/factor, Wy/factor - self.xlim = (centerx - nWx*0.5, centerx + nWx*0.5) - self.ylim = (centery - nWy*0.5, centery + nWy*0.5) - self._run_callbacks() - - def pan(self, deltas): - """ - This accepts a tuple of *deltas*, composed of (delta_x, delta_y) that - will pan the window by those values in absolute coordinates. - """ - self.xlim = (self.xlim[0] + deltas[0], self.xlim[1] + deltas[0]) - self.ylim = (self.ylim[0] + deltas[1], self.ylim[1] + deltas[1]) - self._run_callbacks() - - def pan_x(self, delta): - """ - This pans the window by *delta* in the x direction. - """ - self.pan( (delta, 0.0) ) - - def pan_y(self, delta): - """ - This pans the window by *delta* in the y direction. - """ - self.pan( (0.0, delta) ) - - def pan_rel(self, deltas): - """ - This accepts a tuple of *deltas*, composed of (delta_x, delta_y) that - will pan the window by those values in relative values, relative to the - current window view. - """ - Wx, Wy = self.width - px = deltas[0] * Wx - py = deltas[1] * Wy - self.pan( (px, py) ) - - def pan_rel_x(self, delta): - """ - This pans the window by *delta* in the x direction, where *delta* is - relative to the current window view. - """ - self.pan_rel( (delta, 0.0) ) - - def pan_rel_y(self, delta): - """ - This pans the window by *delta* in the y direction, where *delta* is - relative to the current window view. - """ - self.pan_rel( (0.0, delta) ) - - @property - def buffer(self): - my_bounds = self.xlim + self.ylim # Tuples concatenate - # If the buffer is None, we just kill it regardless. - if self._buffer is None: - self._regenerate_buffer() - elif self._buffer.bounds != my_bounds: - self._regenerate_buffer() - return self._buffer[self.field] - - def _regenerate_buffer(self): - new_buffer = FixedResolutionBuffer( - self.source, self.xlim + self.ylim, - self.size) - self._buffer = new_buffer - - def set_low_high(self, low, high): - """ - This accepts *low* in the format (x_min, y_min) and *high* in the - format (x_max, y_max) and changes the viewport appropriately. In - breaking from tradition, it also returns the buffer. - """ - self.xlim = (low[0], high[0]) - self.ylim = (low[1], high[1]) - return na.log10(self.buffer) - - def set_width(self, width): - """ - This sets the width based on the current center. - """ - if not iterable(width): width = (width, width) - Wx, Wy = self.width - centerx = self.xlim[0] + Wx*0.5 - centery = self.ylim[0] + Wy*0.5 - self.xlim = (centerx - width[0]/2.0, - centerx + width[0]/2.0) - self.ylim = (centery - width[1]/2.0, - centery + width[1]/2.0) - self._run_callbacks() - - def set_limits(self, xlim, ylim): - """ - This accepts a new *xlim* and *ylim*. - """ - self.xlim = xlim - self.ylim = ylim - self._run_callbacks() - - def set_center(self, center): - if len(center) == 2: - centerx, centery = center - elif len(center) == 3: - centerx = center[x_dict[self.source.axis]] - centery = center[y_dict[self.source.axis]] - else: - raise RuntimeError - Wx, Wy = self.width - self.xlim = (centerx - Wx*0.5, centerx + Wx*0.5) - self.ylim = (centery - Wy*0.5, centery + Wy*0.5) - self._run_callbacks() - -data_object_registry["image_panner"] = VariableMeshPanner - -class WindowedVariableMeshPanner(VariableMeshPanner): - - def __init__(self, source, full_size, my_size, start_indices, - field, callback = None): - """ - This image panner accepts a *full_size*, which describes the full size - of the image which it will be displaying a portion of. *my_size* is - the size that this window will be responsible for, and *start_indices* - is a tuple of indices that this window begins at. *field* and - *callback* function as in the vanilla image panner. - """ - self.my_size = my_size - self.start_indices = start_indices - VariableMeshPanner.__init__(self, source, full_size, field, callback) - - def _regenerate_buffer(self): - dx = (self.xlim[1] - self.xlim[0])/self.size[0] - dy = (self.ylim[1] - self.ylim[0])/self.size[1] - my_lim = (self.xlim[0] + dx*self.start_indices[0], - self.xlim[0] + dx*(self.start_indices[0] + self.my_size[0]), - self.ylim[0] + dx*self.start_indices[1], - self.ylim[0] + dx*(self.start_indices[1] + self.my_size[1])) - new_buffer = FixedResolutionBuffer(self.source, my_lim, self.my_size) - self._buffer = new_buffer - -data_object_registry["windowed_image_panner"] = WindowedVariableMeshPanner - -class MultipleWindowVariableMeshPanner(object): - def __init__(self, windows): - """ - This panner is exclusively a controller. It accepts a list of - *windows*, to which it will issue commands. It knows nothing other - than their interfaces. - """ - self.windows = windows - - def zoom(self, factor): - for w in self.windows: w.zoom(factor) - - def pan(self, deltas): - for w in self.windows: w.pan(factor) - - def pan_x(self, delta): - for w in self.windows: w.pan_x(delta) - - def pan_y(self, delta): - for w in self.windows: w.pan_y(delta) - - def pan_rel(self, deltas): - for w in self.windows: w.pan_rel(deltas) - - def pan_rel_x(self, delta): - for w in self.windows: w.pan_rel_x(delta) - - def pan_rel_y(self, delta): - for w in self.windows: w.pan_rel_y(delta) - - def set_limits(self, xlim, ylim): - for w in self.windows: w.set_limits(xlim, ylim) - -class RemoteWindowedVariableMeshController(MultipleWindowVariableMeshPanner): - def __init__(self, source, mec = None): - """ - This panner controls remote windowed panners. It requires a *source*, - which will be pickled and sent to the remote panners, which it will - create as requested. If not supplied with a *mec* (an IPython - MultiEngineClient) it will create one itself. - """ - if mec is None: - from IPython.kernel.client import get_multiengine_client - mec = get_multiengine_client() - self.mec = mec - self.mec.execute("import yt.extensions.image_panner") - self._var_name = "_image_panner_%s" % (id(self)) - self._pf_name = "_pf_%s" % (id(self)) - self._source_name = "_source_%s" % (id(self)) - self.source = source - self.mec.execute("from yt.mods import *") - self.mec.execute("from yt.funcs import iterable") - self.mec.push({self._pf_name: self.pf}) - self.mec.execute("%s.h" % self._pf_name) - self.mec.push({self._source_name: self.source}) - # Now, because the double pickling tosses a PF hash reference inside - # the unpickled object, we work around it a little - self.mec.execute("while iterable(%s): %s = %s[1]" % ( - self._source_name, self._source_name, self._source_name)) - self.windows = [] - - def add_window(self, *args, **kwargs): - """ - This will create a new remote WindowedVariableMeshImagePanner. The - *args* and *kwargs* supplied here will be passed over, but the *source* - argument is implicitly handled by this routine. - """ - engine_id = len(self.windows) - an = "_args_%s" % id(self) - kn = "_kwargs_%s" % id(self) - if 'callback' not in kwargs: - kwargs['callback'] = ImageSaver(engine_id) - self.mec.push({an: args, kn: kwargs}, engine_id) - exec_string = "%s = %s.h.windowed_image_panner(%s, *%s, **%s)" % ( - self._var_name, self._pf_name, self._source_name, an, kn) - self.mec.execute(exec_string, engine_id) - self.windows.append(WindowedVariableMeshPannerProxy( - self.mec, engine_id, self._var_name, id(self))) - -data_object_registry["remote_image_panner"] = RemoteWindowedVariableMeshController - -_wrapped_methods = ["zoom", "pan", "pan_x", "pan_y", "pan_rel", - "pan_rel_x", "pan_rel_y", "set_limits"] - -class WindowedVariableMeshPannerProxy(object): - class __metaclass__(type): - def __new__(cls, name, b, d): - # We add on a bunch of proxy functions - def return_proxy(fname): - def func(self, *args, **kwargs): - vn = "_ret_%s" % self._cid - an = "_args_%s" % self._cid - kn = "_kwargs_%s" % self._cid - self.mec.push({an: args, kn: kwargs}, self.engine_id) - exec_string = "%s = %s.%s(*%s, **%s)" % ( - vn, self._var_name, fname, an, kn) - print "Executing %s on %s" % (exec_string, self.engine_id) - self.mec.execute(exec_string, self.engine_id) - return self.mec.pull(vn, self.engine_id) - return func - new_dict = {} - new_dict.update(d) - for f in _wrapped_methods: - new_dict[f] = return_proxy(f) - return type.__new__(cls, name, b, new_dict) - - def __init__(self, mec, engine_id, var_name, cid): - # mec here is, optionally, an instance of MultiEngineClient - self._var_name = var_name - self._cid = cid - self.engine_id = engine_id - self.mec = mec - - @property - def bounds(self): - vn = "_ret_%s" % self._cid - self.mec.execute("%s = %s.bounds" % (vn, self._var_name), - self.engine_id) - return self.mec.pull(vn, self.engine_id) - - @property - def width(self): - vn = "_ret_%s" % self._cid - self.mec.execute("%s = %s.width" % (vn, self._var_name), - self.engine_id) - return self.mec.pull(vn, self.engine_id) - - @property - def buffer(self): - vn = "_ret_%s" % self._cid - self.mec.execute("%s = %s.buffer" % (vn, self._var_name), - self.engine_id) - return self.mec.pull(vn, self.engine_id) - - def _regenerate_buffer(self): - return - - def _run_callback(self): - self.mec.execute("%s._regenerate_buffer()" % self._var_name, - self.engine_id) - self.mec.execute("%s.callback(%s.buffer)" % ( - self._var_name, self._var_name), self.engine_id) - -class ProxySource(object): - # This proxies only the things we know we need - # Note that we assume we will only have a single engine. - def __init__(self, mec, idnum, source_varname): - self.mec = mec - self.idnum = idnum - self.source_varname = source_varname - self.mec.execute("_tmp_%s = %s.axis" % ( - self.idnum, self.source_varname)) - self.axis = self.mec.pull("_tmp_%s" % self.idnum)[0] - - def keys(self): - self.mec.execute("_tmp_%s = %s.keys()" % ( - self.idnum, self.source_varname)) - keys = self.mec.pull("_tmp_%s" % self.idnum)[0] - dd = dict( (k, None) for k in keys ) - return dd - - @property - def pf(self): - self.mec.execute("_tmp_%s = %s.pf['DomainLeftEdge']" % ( - self.idnum, self.source_varname)) - DLE = self.mec.pull("_tmp_%s" % self.idnum)[0] - self.mec.execute("_tmp_%s = %s.pf['DomainRightEdge']" % ( - self.idnum, self.source_varname)) - DRE = self.mec.pull("_tmp_%s" % self.idnum)[0] - return dict(DomainLeftEdge = DLE, DomainRightEdge = DRE) - -class ProxyFixedResolutionBuffer(dict): - pass - -class NonLocalDataImagePanner(VariableMeshPanner): - def __init__(self, mec, source_varname, size, field, - callback = None, viewport_callback = None): - self.source_varname = source_varname - self._var_name = "_image_panner_%s" % (id(self)) - self.mec = mec - self.mec.execute("import yt.extensions.image_panner") - self.mec.execute("%s = yt.extensions.image_panner.VariableMeshPanner(" % ( - self._var_name) + - "%s, (%s, %s), '%s')" % ( - source_varname, size[0], size[1], field)) - - ps = ProxySource(mec, id(self), source_varname) - self._prfb = ProxyFixedResolutionBuffer() - - VariableMeshPanner.__init__(self, ps, size, field, - callback, viewport_callback) - - def _regenerate_buffer(self): - args = (self.xlim, self.ylim) - self.mec.push({'_tmp_%s' % id(self) : args}, block=False) - self.mec.execute("%s.set_limits(*_tmp_%s)" % (self._var_name, id(self)), - block=False) - self.mec.execute("_tmp_%s = %s.buffer" % (id(self), self._var_name), - block=False) - self._prfb[self.field] = self.mec.pull("_tmp_%s" % (id(self)))[0] - self._prfb.bounds = self.xlim + self.ylim - self._buffer = self._prfb - -class ImageSaver(object): - def __init__(self, tile_id): - """ - This is a sample callback for an image panner that will save to a file - named ``wimage_%03i.png`` where the final variable is specified here as - *tile_id*. - """ - self.tile_id = tile_id - - import matplotlib;matplotlib.use("Agg");import pylab - self.pylab = pylab - self.pylab.clf() - fig = pylab.gcf() - fig.subplots_adjust(left=0.0, bottom=0.0, - right=1.0, top=1.0, - wspace=0.0, hspace=0.0) - fig.set_dpi(100.0) - fig.set_size_inches((5.12, 5.12)) - - def __call__(self, val): - self.pylab.clf() - self.pylab.imshow(na.log10(val), interpolation='nearest') - self.pylab.savefig("wimage_%03i.png" % self.tile_id) - -class PanningCeleritasStreamer(object): - _initialized = False - def __init__(self, tile_id, cmap = "algae", port = 9988, - zlim = (0.0, 1.0), take_log = True): - """ - This is an in-development mechanism for supplying buffers to a - Celeritas server. - """ - self.tile_id = tile_id - self._port = port - self.cmap = cmap - self.zlim = zlim - self.take_log = True - - def initialize(self, shape): - if isinstance(self.cmap, types.StringTypes): - import matplotlib.cm - self.cmap = matplotlib.cm.get_cmap(self.cmap) - - import celeritas_streamer - self.cs = celeritas_streamer.CeleritasStream() - #print "Setting shape: %s and port: %s in %s" % ( - # shape, self._port, os.getpid()) - self.cs.setSize(*shape) - self.cs.setLocalPort(self._port) - self.cs.initialize() - self._initialized = True - - def __call__(self, val): - if not self._initialized: self.initialize(val.shape) - if self.take_log: - vv = na.log10(val) - else: - vv = val.copy() - na.subtract(vv, self.zlim[0], vv) - na.divide(vv, (self.zlim[1]-self.zlim[0]), vv) - new_buf = self.cmap(vv)[:,:,:3] - na.multiply(new_buf, 255.0, new_buf) - new_buf = new_buf.astype('uint8') - self.cs.readFromRGBMemAndSend(new_buf) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/image_writer.py --- a/yt/extensions/image_writer.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,221 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: UCSD -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 . -""" - -import numpy as na -from yt.funcs import * -import _colormap_data as cmd -import yt.amr_utils as au -import types - -def _scale_image(image): - if isinstance(image, na.ndarray) and image.dtype == na.uint8: - return image - if isinstance(image, (types.TupleType, types.ListType)): - image, mi, ma = image - else: - mi, ma = image.min(), image.max() - image = (na.clip((image-mi)/(ma-mi) * 255, 0, 255)).astype('uint8') - return image - -def multi_image_composite(fn, red_channel, blue_channel, - green_channel = None, alpha_channel = None): - r"""Write an image with different color channels corresponding to different - quantities. - - Accepts at least a red and a blue array, of shape (N,N) each, that are - optionally scaled and composited into a final image, written into `fn`. - Can also accept green and alpha. - - Parameters - ---------- - fn : string - Filename to save - red_channel : array_like or tuple of image info - Array, of shape (N,N), to be written into the red channel of the output - image. If not already uint8, will be converted (and scaled) into - uint8. Optionally, you can also specify a tuple that includes scaling - information, in the form of (array_to_plot, min_value_to_scale, - max_value_to_scale). - blue_channel : array_like or tuple of image info - Array, of shape (N,N), to be written into the blue channel of the output - image. If not already uint8, will be converted (and scaled) into - uint8. Optionally, you can also specify a tuple that includes scaling - information, in the form of (array_to_plot, min_value_to_scale, - max_value_to_scale). - green_channel : array_like or tuple of image info, optional - Array, of shape (N,N), to be written into the green channel of the - output image. If not already uint8, will be converted (and scaled) - into uint8. If not supplied, will be left empty. Optionally, you can - also specify a tuple that includes scaling information, in the form of - (array_to_plot, min_value_to_scale, max_value_to_scale). - - alpha_channel : array_like or tuple of image info, optional - Array, of shape (N,N), to be written into the alpha channel of the output - image. If not already uint8, will be converted (and scaled) into uint8. - If not supplied, will be made fully opaque. Optionally, you can also - specify a tuple that includes scaling information, in the form of - (array_to_plot, min_value_to_scale, max_value_to_scale). - - Examples - -------- - - >>> red_channel = na.log10(frb["Temperature"]) - >>> blue_channel = na.log10(frb["Density"]) - >>> multi_image_composite("multi_channel1.png", red_channel, blue_channel) - - """ - red_channel = _scale_image(red_channel) - blue_channel = _scale_image(blue_channel) - if green_channel is None: - green_channel = na.zeros(red_channel.shape, dtype='uint8') - else: - green_channel = _scale_image(green_channel) - if alpha_channel is None: - alpha_channel = na.zeros(red_channel.shape, dtype='uint8') + 255 - else: - alpha_channel = _scale_image(alpha_channel) - image = na.array([red_channel, green_channel, blue_channel, alpha_channel]) - image = image.transpose().copy() # Have to make sure it's contiguous - au.write_png(image, fn) - -def write_bitmap(bitmap_array, filename, max_val = None): - r"""Write out a bitmapped image directly to a PNG file. - - This accepts a three- or four-channel `bitmap_array`. If the image is not - already uint8, it will be scaled and converted. If it is not four channel, a - fourth alpha channel will be added and set to fully opaque. The resultant - image will be directly written to `filename` as a PNG with no colormap - applied. `max_val` is a value used if the array is passed in as anything - other than uint8; it will be the value used for scaling and clipping when the - array is converted. Additionally, the minimum is assumed to be zero; this - makes it primarily suited for the results of volume rendered images, rather - than misaligned projections. - - Parameters - ---------- - bitmap_array : array_like - Array of shape (N,M,3) or (N,M,4), to be written. If it is not already - a uint8 array, it will be scaled and converted to uint8. - filename : string - Filename to save to - max_val : float, optional - The upper limit to clip values to in the output, if converting to uint8. - If `bitmap_array` is already uint8, this will be ignore. - """ - if bitmap_array.dtype != na.uint8: - if max_val is None: max_val = bitmap_array.max() - bitmap_array = na.clip(bitmap_array / max_val, 0.0, 1.0) * 255 - bitmap_array = bitmap_array.astype("uint8") - if len(bitmap_array.shape) != 3 or bitmap_array.shape[-1] not in (3,4): - raise RuntimeError - if bitmap_array.shape[-1] == 3: - s1, s2 = bitmap_array.shape[:2] - alpha_channel = 255*na.ones((s1,s2,1), dtype='uint8') - bitmap_array = na.concatenate([bitmap_array, alpha_channel], axis=-1) - au.write_png(bitmap_array.copy(), filename) - -def write_image(image, filename, color_bounds = None, cmap_name = "algae"): - r"""Write out a floating point array directly to a PNG file, scaling it and - applying a colormap. - - This function will scale an image and directly call libpng to write out a - colormapped version of that image. It is designed for rapid-fire saving of - image buffers generated using `yt.raven.FixedResolutionBuffers` and the like. - - Parameters - ---------- - image : array_like - This is an (unscaled) array of floating point values, shape (N,N,) to - save in a PNG file. - filename : string - Filename to save as. - color_bounds : tuple of floats, optional - The min and max to scale between. Outlying values will be clipped. - cmap_name : string, optional - An acceptable colormap. See either raven.color_maps or - http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps . - - Returns - ------- - scaled_image : uint8 image that has been saved - - Examples - -------- - - >>> proj = pf.h.slice(0, "Density") - >>> frb1 = FixedResolutionBuffer(proj, (0.2, 0.3, 0.4, 0.5), - (1024, 1024)) - >>> write_image(frb1, "saved.png") - """ - if color_bounds is None: - mi = na.nanmin(image[~na.isinf(image)]) - ma = na.nanmax(image[~na.isinf(image)]) - color_bounds = mi, ma - image = (image - color_bounds[0])/(color_bounds[1] - color_bounds[0]) - to_plot = map_to_colors(image, cmap_name) - to_plot = na.clip(to_plot, 0, 255) - au.write_png(to_plot, filename) - return to_plot - -def map_to_colors(buff, cmap_name): - if cmap_name not in cmd.color_map_luts: - print "Your color map was not found in the extracted colormap file." - raise KeyError(cmap_name) - lut = cmd.color_map_luts[cmap_name] - x = na.mgrid[0.0:1.0:lut[0].shape[0]*1j] - shape = buff.shape - mapped = na.dstack( - [(na.interp(buff, x, v)*255) for v in lut ]).astype("uint8") - return mapped.copy("C") - -def strip_colormap_data(fn = "color_map_data.py", - cmaps = ("jet", "algae", "hot", "gist_stern")): - import yt.raven, pprint - import yt.raven.ColorMaps as rcm - f = open(fn, "w") - f.write("### Auto-generated colormap tables, taken from Matplotlib ###\n\n") - f.write("from numpy import array\n") - f.write("color_map_luts = {}\n\n\n") - if cmaps is None: cmaps = yt.raven.ColorMaps - for cmap_name in sorted(cmaps): - print "Stripping", cmap_name - vals = rcm._extract_lookup_table(cmap_name) - f.write("### %s ###\n\n" % (cmap_name)) - f.write("color_map_luts['%s'] = \\\n" % (cmap_name)) - f.write(" (\n") - for v in vals: - f.write(pprint.pformat(v, indent=3)) - f.write(",\n") - f.write(" )\n\n") - f.close() - -def splat_points(image, points_x, points_y, - contribution = None, transposed = False): - if contribution is None: - contribution = 100.0 - val = contribution * 1.0/points_x.size - if transposed: - points_y = 1.0 - points_y - points_x = 1.0 - points_x - im = image.copy() - au.add_points_to_image(im, points_x, points_y, val) - return im diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/LICENSE --- a/yt/extensions/kdtree/LICENSE Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ - -The KDTREE2 software is licensed under the terms of the Academic Free -Software License, listed herein. In addition, users of this software -must give appropriate citation in relevant technical documentation or -journal paper to the author, Matthew B. Kennel, Institute For -Nonlinear Science, preferably via a reference to the www.arxiv.org -repository of this document, {\tt www.arxiv.org e-print: -physics/0408067}. This requirement will be deemed to be advisory and -not mandatory as is necessary to permit the free inclusion of the -present software with any software licensed under the terms of any -version of the GNU General Public License, or GNU Library General -Public License. - - -Academic Free License -Version 1.1 - -This Academic Free License applies to any original work of authorship -(the "Original Work") whose owner (the "Licensor") has placed the -following notice immediately following the copyright notice for the -Original Work: "Licensed under the Academic Free License version 1.1." - -Grant of License. Licensor hereby grants to any person obtaining a -copy of the Original Work ("You") a world-wide, royalty-free, -non-exclusive, perpetual, non-sublicenseable license (1) to use, copy, -modify, merge, publish, perform, distribute and/or sell copies of the -Original Work and derivative works thereof, and (2) under patent -claims owned or controlled by the Licensor that are embodied in the -Original Work as furnished by the Licensor, to make, use, sell and -offer for sale the Original Work and derivative works thereof, subject -to the following conditions. - -Right of Attribution. Redistributions of the Original Work must -reproduce all copyright notices in the Original Work as furnished by -the Licensor, both in the Original Work itself and in any -documentation and/or other materials provided with the distribution of -the Original Work in executable form. - -Exclusions from License Grant. Neither the names of Licensor, nor the -names of any contributors to the Original Work, nor any of their -trademarks or service marks, may be used to endorse or promote -products derived from this Original Work without express prior written -permission of the Licensor. - -WARRANTY AND DISCLAIMERS. LICENSOR WARRANTS THAT THE COPYRIGHT IN AND -TO THE ORIGINAL WORK IS OWNED BY THE LICENSOR OR THAT THE ORIGINAL -WORK IS DISTRIBUTED BY LICENSOR UNDER A VALID CURRENT LICENSE FROM THE -COPYRIGHT OWNER. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY -PRECEEDING SENTENCE, THE ORIGINAL WORK IS PROVIDED UNDER THIS LICENSE -ON AN "AS IS" BASIS, WITHOUT WARRANTY, EITHER EXPRESS OR IMPLIED, -INCLUDING, WITHOUT LIMITATION, THE WARRANTY OF NON-INFRINGEMENT AND -WARRANTIES THAT THE ORIGINAL WORK IS MERCHANTABLE OR FIT FOR A -PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL -WORK IS WITH YOU. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -PART OF THIS LICENSE. NO LICENSE TO ORIGINAL WORK IS GRANTED HEREUNDER -EXCEPT UNDER THIS DISCLAIMER. - -LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL -THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, -SHALL THE LICENSOR BE LIABLE TO ANY PERSON FOR ANY DIRECT, INDIRECT, -SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING -AS A RESULT OF THIS LICENSE OR THE USE OF THE ORIGINAL WORK INCLUDING, -WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, -COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL -DAMAGES OR LOSSES, EVEN IF SUCH PERSON SHALL HAVE BEEN INFORMED OF THE -POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT -APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH -PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH -LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR -LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION -AND LIMITATION MAY NOT APPLY TO YOU. - -License to Source Code. The term "Source Code" means the preferred -form of the Original Work for making modifications to it and all -available documentation describing how to access and modify the -Original Work. Licensor hereby agrees to provide a machine-readable -copy of the Source Code of the Original Work along with each copy of -the Original Work that Licensor distributes. Licensor reserves the -right to satisfy this obligation by placing a machine-readable copy of -the Source Code in an information repository reasonably calculated to -permit inexpensive and convenient access by You for as long as -Licensor continues to distribute the Original Work, and by publishing -the address of that information repository in a notice immediately -following the copyright notice that applies to the Original Work. - -Mutual Termination for Patent Action. This License shall terminate -automatically and You may no longer exercise any of the rights granted -to You by this License if You file a lawsuit in any court alleging -that any OSI Certified open source software that is licensed under any -license containing this "Mutual Termination for Patent Action" clause -infringes any patent claims that are essential to use that software. - -This license is Copyright (C) 2002 Lawrence E. Rosen. All rights -reserved. Permission is hereby granted to copy and distribute this -license without modification. This license may not be modified without -the express written permission of its copyright owner. - - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/Makefile --- a/yt/extensions/kdtree/Makefile Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -# if you want to build this statically, you need to include fKD.f90 to the -# compile line, so pick the first of the two below. Otherwise, eliminate it, -# like the second, for a shared object. - - -fKD: fKD.f90 fKD.v fKD_source.f90 -# Forthon --compile_first fKD_source --no2underscores --with-numpy -g fKD fKD.f90 fKD_source.f90 - Forthon -F gfortran --compile_first fKD_source --no2underscores --with-numpy --fopt "-O3" fKD fKD_source.f90 - -clean: - rm -rf build fKDpy.a fKDpy.so diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/__init__.py --- a/yt/extensions/kdtree/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -from yt.lagos import * - -from fKDpy import * \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/fKD.f90 --- a/yt/extensions/kdtree/fKD.f90 Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,346 +0,0 @@ -subroutine create_tree(treeID) - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer, intent (in), optional :: treeID - - integer :: ID - - if (present(treeID)) then - ID = treeID - else - ID = -1 - end if - - ! create a kd tree object - - if (ID == 1) then - t1%tree2 => kdtree2_create(t1%pos,sort=t1%sort,rearrange=t1%rearrange) - elseif (ID == 2) then - t2%tree2 => kdtree2_create(t2%pos,sort=t2%sort,rearrange=t2%rearrange) - else - tree2 => kdtree2_create(pos,sort=sort,rearrange=rearrange) - end if - - return - -end subroutine create_tree - -subroutine add_tree(treeID) - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: treeID - - if (treeID == 1) then - t1 => Newtree_set() - elseif (treeID == 2) then - t2 => Newtree_set() - end if - - return - -end subroutine add_tree - -subroutine find_nn_nearest_neighbors() - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: k - type(kdtree2_result),allocatable :: results(:) ! nearest neighbors - !integer, parameter :: nn ! number of nearest neighbors found - - allocate(results(nn)) - - call kdtree2_n_nearest(tp=tree2,qv=qv,nn=nn,results=results) - - dist = results%dis - tags = results%idx - - !do k=1,nn - ! print *, "k = ", k, " idx = ", tags(k)," dis = ", dist(k) - ! print *, "x y z", pos(1,results(k)%idx), pos(2,results(k)%idx), pos(3,results(k)%idx) - !enddo - - - deallocate(results) - return - -end subroutine find_nn_nearest_neighbors - -subroutine find_many_nn_nearest_neighbors() - ! Given an input array of query vectors (qv_many), find their - ! nearest neighbors. - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: k, number - type(kdtree2_result),allocatable :: results(:) - - allocate(results(nn)) - - number = size(qv_many,2) - - do k=1, number - qv(:) = qv_many(:,k) - call kdtree2_n_nearest(tp=tree2,qv=qv,nn=nn,results=results) - nn_tags(:, k) = results%idx - end do - - deallocate(results) - return - -end subroutine find_many_nn_nearest_neighbors - -subroutine find_r_nearest() - ! Given an input array of a point (qv), find the number, fortran indices and - ! squared distances to all neighbors within (radius) of (qv). - ! The number of neighbors with indices and radius returned is set by - ! (radius_n), and if this is smaller than (nfound) when returned, - ! there are neighbors missing from the results. - ! Store the results in (dist) and (tags). - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: k - type(kdtree2_result),allocatable :: results(:) ! nearest neighbors - - allocate(results(radius_n)) - nfound = 0 - - ! do it. - call kdtree2_r_nearest(tp=tree2,qv=qv,r2=radius,nfound=nfound,nalloc=radius_n,results=results) - - tags(:) = results%idx - dist(:) = results%dis - - deallocate(results) - return - -end subroutine find_r_nearest - -subroutine find_many_r_nearest(treeID) - ! Given an input array of a points (qv_many), find the number, fortran indices and - ! squared distances to all neighbors within (radius) of (qv). - ! The number of neighbors with indices and radius returned is set by - ! (radius_n), and if this is smaller than (nfound) when returned, - ! there are neighbors missing from the results. - ! Store the results in (dist) and (tags). - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer, intent (in), optional :: treeID - - integer :: ID - integer :: k, number - type(kdtree2_result),allocatable :: results(:) ! nearest neighbors - - - if (present(treeID)) then - ID = treeID - else - ID = -1 - end if - - if (ID==1) then - allocate(results(t1%radius_n)) - number = size(t1%qv_many,2) - do k=1, number - t1%qv(:) = t1%qv_many(:,k) - t1%nfound = t1%nfound_many(k) - call kdtree2_r_nearest(tp=t1%tree2,qv=t1%qv,r2=t1%radius,nfound=t1%nfound,nalloc=t1%radius_n,results=results) - t1%nfound_many(k) = t1%nfound - t1%nn_tags(:, k) = results%idx - t1%nn_dist(:, k) = results%dis - end do - elseif (ID==2) then - allocate(results(t2%radius_n)) - number = size(t2%qv_many,2) - do k=1, number - t2%qv(:) = t2%qv_many(:,k) - t2%nfound = t2%nfound_many(k) - call kdtree2_r_nearest(tp=t2%tree2,qv=t2%qv,r2=t2%radius,nfound=t2%nfound,nalloc=t2%radius_n,results=results) - t2%nfound_many(k) = t2%nfound - t2%nn_tags(:, k) = results%idx - t2%nn_dist(:, k) = results%dis - end do - else - allocate(results(radius_n)) - number = size(qv_many,2) - do k=1, number - qv(:) = qv_many(:,k) - nfound = nfound_many(k) - call kdtree2_r_nearest(tp=tree2,qv=qv,r2=radius,nfound=nfound,nalloc=radius_n,results=results) - nfound_many(k) = nfound - nn_tags(:, k) = results%idx - nn_dist(:, k) = results%dis - end do - end if - - deallocate(results) - return - -end subroutine find_many_r_nearest - -subroutine find_all_nn_nearest_neighbors() - ! for all particles in pos, find their nearest neighbors and return the - ! indexes and distances as big arrays - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: k - type(kdtree2_result),allocatable :: results(:) ! nearest neighbors - - allocate(results(nn)) - - do k=1,nparts - qv(:) = pos(:,k) - call kdtree2_n_nearest(tp=tree2,qv=qv,nn=nn,results=results) - nn_dist(:,k) = results%dis - nn_tags(:,k) = results%idx - end do - - deallocate(results) - return - -end subroutine find_all_nn_nearest_neighbors - -subroutine find_chunk_nearest_neighbors() - ! for a chunk of the full number of particles, find their nearest neighbors - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: k - type(kdtree2_result),allocatable :: results(:) ! nearest neighbors - allocate(results(nn)) - do k=start,finish - qv(:) = pos(:,k) - call kdtree2_n_nearest(tp=tree2,qv=qv,nn=nn,results=results) - chunk_tags(:,k - start + 1) = results%idx - - end do - - deallocate(results) - return - -end subroutine find_chunk_nearest_neighbors - -subroutine chainHOP_tags_dens() - ! for all particles in pos, find their nearest neighbors, and calculate - ! their density. Return only nMerge nearest neighbors. - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer :: k, pj, i - real :: ih2, fNorm, r2, rs - integer, allocatable :: temp_tags(:) - real, allocatable :: temp_dist(:) - type(kdtree2_result),allocatable :: results(:) ! nearest neighbors - allocate(results(nn)) - allocate(temp_tags(nn)) - allocate(temp_dist(nn)) - - do k=1,nparts - qv(:) = pos(:,k) - - call kdtree2_n_nearest(tp=tree2,qv=qv,nn=nn,results=results) - temp_tags(:) = results%idx - temp_dist(:) = results%dis - - ! calculate the density for this particle - ih2 = 4.0/maxval(results%dis) - fNorm = 0.5*sqrt(ih2)*ih2/3.1415926535897931 - do i=1,nn - pj = temp_tags(i) - r2 = temp_dist(i) * ih2 - rs = 2.0 - sqrt(r2) - if (r2 < 1.0) then - rs = (1.0 - 0.75*rs*r2) - else - rs = 0.25*rs*rs*rs - end if - rs = rs * fNorm - dens(k) = dens(k) + rs * mass(pj) - dens(pj) = dens(pj) + rs * mass(k) - end do - - ! record only nMerge nearest neighbors, but skip the first one which - ! is always the self-same particle - ! nn_tags(:,k) = temp_tags(2:nMerge) - end do - - deallocate(results) - deallocate(temp_dist) - deallocate(temp_tags) - return - -end subroutine chainHOP_tags_dens - -subroutine free_tree(treeID) - use kdtree2_module - use fKD_module - use tree_setmodule - use kdtree2module - use tree_nodemodule - use intervalmodule - - integer, intent (in), optional :: treeID - - integer :: ID - - if (present(treeID)) then - ID = treeID - else - ID = -1 - end if - - ! this releases memory for the tree BUT NOT THE ARRAY OF DATA YOU PASSED - ! TO MAKE THE TREE. - if (ID == 1) then - call kdtree2_destroy(t1%tree2) - elseif (ID == 2) then - call kdtree2_destroy(t2%tree2) - else - call kdtree2_destroy(tree2) - end if - - ! The data to make the tree has to be deleted in python BEFORE calling - ! this! -end subroutine free_tree - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/fKD.v --- a/yt/extensions/kdtree/fKD.v Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -fKD - -****** fKD_module vars: -t1 _tree_set -t2 _tree_set -# This contains the objects that any given kD tree might wish to use. -# Not all of these are being used all the time, but they only take memory -# if they're initialized in python. -tags(:) _integer # particle ID tags -dist(:) _real # interparticle spacings -nn_tags(:,:) _integer # for all particles at once, [nth neighbor, index] -chunk_tags(:,:) _integer # for finding only a chunk of the nearest neighbors -nn_dist(:,:) _real -pos(3,:) _real -dens(:) _real -mass(:) _real -qv(3) real -qv_many(3,:) _real -nparts integer -nn integer -nMerge integer # number of nearest neighbors used in chain merging -start integer -finish integer -tree2 _kdtree2 -sort logical /.false./ -rearrange logical /.true./ -radius real # the unsquared radius for radius searches -radius_n integer # the number of results to return -nfound integer # number of neighbors within radius -nfound_many(:) _integer # an array of number of neighbors within radius - -%%%% interval: -lower real -upper real -#real(kdkind) :: lower,upper - - -%%%% tree_node: -# an internal tree node -cut_dim integer -#integer :: cut_dim -# the dimension to cut -cut_val real -#real(kdkind) :: cut_val -# where to cut the dimension -cut_val_left real -cut_val_right real -#real(kdkind) :: cut_val_left, cut_val_right -# improved cutoffs knowing the spread in child boxes. -u integer -l integer -#integer :: l, u -left _tree_node -right _tree_node -#type(tree_node), pointer :: left, right -box(:) _interval -#type(interval), pointer :: box(:) => null() -# child pointers -# Points included in this node are indexes[k] with k \in [l,u] - - -%%%% kdtree2: -# Global information about the tree, one per tree -dimen integer /0/ -n integer /0/ -# dimensionality and total # of points -the_data(:,:) _real -#real(kdkind), pointer :: the_data(:,:) => null() -# pointer to the actual data array -# -# IMPORTANT NOTE: IT IS DIMENSIONED the_data(1:d,1:N) -# which may be opposite of what may be conventional. -# This is, because in Fortran, the memory layout is such that -# the first dimension is in sequential order. Hence, with -# (1:d,1:N), all components of the vector will be in consecutive -# memory locations. The search time is dominated by the -# evaluation of distances in the terminal nodes. Putting all -# vector components in consecutive memory location improves -# memory cache locality, and hence search speed, and may enable -# vectorization on some processors and compilers. -ind(:) _integer -#integer, pointer :: ind(:) => null() -# permuted index into the data, so that indexes[l..u] of some -# bucket represent the indexes of the actual points in that -# bucket. -# do we always sort output results? -sort logical /.false./ -#logical :: sort = .false. -rearrange logical /.false./ -#logical :: rearrange = .false. -rearranged_data(:,:) _real -#real(kdkind), pointer :: rearranged_data(:,:) => null() -# if (rearrange .eqv. .true.) then rearranged_data has been -# created so that rearranged_data(:,i) = the_data(:,ind(i)), -# permitting search to use more cache-friendly rearranged_data, at -# some initial computation and storage cost. -root _tree_node -#type(tree_node), pointer :: root => null() -# root pointer of the tree - - -%%%% tree_set: -# This contains the objects that any given kD tree might wish to use. -# Not all of these are being used all the time, but they only take memory -# if they're initialized in python. -tags(:) _integer # particle ID tags -dist(:) _real # interparticle spacings -nn_tags(:,:) _integer # for all particles at once, [nth neighbor, index] -chunk_tags(:,:) _integer # for finding only a chunk of the nearest neighbors -nn_dist(:,:) _real -pos(3,:) _real -dens(:) _real -mass(:) _real -qv(3) real -qv_many(3,:) _real -nparts integer -nn integer -nMerge integer # number of nearest neighbors used in chain merging -start integer -finish integer -tree2 _kdtree2 -sort logical /.false./ -rearrange logical /.true./ -radius real # the unsquared radius for radius searches -radius_n integer # the number of results to return -nfound integer # number of neighbors within radius -nfound_many(:) _integer # an array of number of neighbors within radius - -***** Subroutines: -find_nn_nearest_neighbors subroutine -create_tree(treeID:integer) subroutine -add_tree(treeID:integer) subroutine -free_tree(treeID:integer) subroutine -find_all_nn_nearest_neighbors subroutine -find_r_nearest subroutine -find_many_r_nearest(treeID:integer) subroutine -find_many_nn_nearest_neighbors subroutine -find_chunk_nearest_neighbors subroutine -chainHOP_tags_dens subroutine diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/fKD_source.f90 --- a/yt/extensions/kdtree/fKD_source.f90 Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1955 +0,0 @@ -! -!(c) Matthew Kennel, Institute for Nonlinear Science (2004) -! -! Licensed under the Academic Free License version 1.1 found in file LICENSE -! with additional provisions found in that same file. -! -! Modified by Stephen Skory, CASS/UCSD (2009), adding periodicity and changes -! so this can be used by as a Python module using Forthon - -module kdtree2_precision_module - - integer, parameter :: sp = kind(0.0) - integer, parameter :: dp = kind(0.0d0) - - private :: sp, dp - - ! - ! You must comment out exactly one - ! of the two lines. If you comment - ! out kdkind = sp then you get single precision - ! and if you comment out kdkind = dp - ! you get double precision. - ! - - integer, parameter :: kdkind = sp - !integer, parameter :: kdkind = dp - public :: kdkind - -end module kdtree2_precision_module - -module kdtree2_priority_queue_module - use kdtree2_precision_module - ! - ! maintain a priority queue (PQ) of data, pairs of 'priority/payload', - ! implemented with a binary heap. This is the type, and the 'dis' field - ! is the priority. - ! - type kdtree2_result - ! a pair of distances, indexes - real(kdkind) :: dis!=0.0 - integer :: idx!=-1 Initializers cause some bugs in compilers. - end type kdtree2_result - ! - ! A heap-based priority queue lets one efficiently implement the following - ! operations, each in log(N) time, as opposed to linear time. - ! - ! 1) add a datum (push a datum onto the queue, increasing its length) - ! 2) return the priority value of the maximum priority element - ! 3) pop-off (and delete) the element with the maximum priority, decreasing - ! the size of the queue. - ! 4) replace the datum with the maximum priority with a supplied datum - ! (of either higher or lower priority), maintaining the size of the - ! queue. - ! - ! - ! In the k-d tree case, the 'priority' is the square distance of a point in - ! the data set to a reference point. The goal is to keep the smallest M - ! distances to a reference point. The tree algorithm searches terminal - ! nodes to decide whether to add points under consideration. - ! - ! A priority queue is useful here because it lets one quickly return the - ! largest distance currently existing in the list. If a new candidate - ! distance is smaller than this, then the new candidate ought to replace - ! the old candidate. In priority queue terms, this means removing the - ! highest priority element, and inserting the new one. - ! - ! Algorithms based on Cormen, Leiserson, Rivest, _Introduction - ! to Algorithms_, 1990, with further optimization by the author. - ! - ! Originally informed by a C implementation by Sriranga Veeraraghavan. - ! - ! This module is not written in the most clear way, but is implemented such - ! for speed, as it its operations will be called many times during searches - ! of large numbers of neighbors. - ! - type pq - ! - ! The priority queue consists of elements - ! priority(1:heap_size), with associated payload(:). - ! - ! There are heap_size active elements. - ! Assumes the allocation is always sufficient. Will NOT increase it - ! to match. - integer :: heap_size = 0 - type(kdtree2_result), pointer :: elems(:) - end type pq - - public :: kdtree2_result - - public :: pq - public :: pq_create - public :: pq_delete, pq_insert - public :: pq_extract_max, pq_max, pq_replace_max, pq_maxpri - private - -contains - - - function pq_create(results_in) result(res) - ! - ! Create a priority queue from ALREADY allocated - ! array pointers for storage. NOTE! It will NOT - ! add any alements to the heap, i.e. any existing - ! data in the input arrays will NOT be used and may - ! be overwritten. - ! - ! usage: - ! real(kdkind), pointer :: x(:) - ! integer, pointer :: k(:) - ! allocate(x(1000),k(1000)) - ! pq => pq_create(x,k) - ! - type(kdtree2_result), target:: results_in(:) - type(pq) :: res - ! - ! - integer :: nalloc - - nalloc = size(results_in,1) - if (nalloc .lt. 1) then - write (*,*) 'PQ_CREATE: error, input arrays must be allocated.' - end if - res%elems => results_in - res%heap_size = 0 - return - end function pq_create - - ! - ! operations for getting parents and left + right children - ! of elements in a binary heap. - ! - -! -! These are written inline for speed. -! -! integer function parent(i) -! integer, intent(in) :: i -! parent = (i/2) -! return -! end function parent - -! integer function left(i) -! integer, intent(in) ::i -! left = (2*i) -! return -! end function left - -! integer function right(i) -! integer, intent(in) :: i -! right = (2*i)+1 -! return -! end function right - -! logical function compare_priority(p1,p2) -! real(kdkind), intent(in) :: p1, p2 -! -! compare_priority = (p1 .gt. p2) -! return -! end function compare_priority - - subroutine heapify(a,i_in) - ! - ! take a heap rooted at 'i' and force it to be in the - ! heap canonical form. This is performance critical - ! and has been tweaked a little to reflect this. - ! - type(pq),pointer :: a - integer, intent(in) :: i_in - ! - integer :: i, l, r, largest - - real(kdkind) :: pri_i, pri_l, pri_r, pri_largest - - - type(kdtree2_result) :: temp - - i = i_in - -bigloop: do - l = 2*i ! left(i) - r = l+1 ! right(i) - ! - ! set 'largest' to the index of either i, l, r - ! depending on whose priority is largest. - ! - ! note that l or r can be larger than the heap size - ! in which case they do not count. - - - ! does left child have higher priority? - if (l .gt. a%heap_size) then - ! we know that i is the largest as both l and r are invalid. - exit - else - pri_i = a%elems(i)%dis - pri_l = a%elems(l)%dis - if (pri_l .gt. pri_i) then - largest = l - pri_largest = pri_l - else - largest = i - pri_largest = pri_i - endif - - ! - ! between i and l we have a winner - ! now choose between that and r. - ! - if (r .le. a%heap_size) then - pri_r = a%elems(r)%dis - if (pri_r .gt. pri_largest) then - largest = r - endif - endif - endif - - if (largest .ne. i) then - ! swap data in nodes largest and i, then heapify - - temp = a%elems(i) - a%elems(i) = a%elems(largest) - a%elems(largest) = temp - ! - ! Canonical heapify() algorithm has tail-ecursive call: - ! - ! call heapify(a,largest) - ! we will simulate with cycle - ! - i = largest - cycle bigloop ! continue the loop - else - return ! break from the loop - end if - enddo bigloop - return - end subroutine heapify - - subroutine pq_max(a,e) - ! - ! return the priority and its payload of the maximum priority element - ! on the queue, which should be the first one, if it is - ! in heapified form. - ! - type(pq),pointer :: a - type(kdtree2_result),intent(out) :: e - - if (a%heap_size .gt. 0) then - e = a%elems(1) - else - write (*,*) 'PQ_MAX: ERROR, heap_size < 1' - stop - endif - return - end subroutine pq_max - - real(kdkind) function pq_maxpri(a) - type(pq), pointer :: a - - if (a%heap_size .gt. 0) then - pq_maxpri = a%elems(1)%dis - else - write (*,*) 'PQ_MAX_PRI: ERROR, heapsize < 1' - stop - endif - return - end function pq_maxpri - - subroutine pq_extract_max(a,e) - ! - ! return the priority and payload of maximum priority - ! element, and remove it from the queue. - ! (equivalent to 'pop()' on a stack) - ! - type(pq),pointer :: a - type(kdtree2_result), intent(out) :: e - - if (a%heap_size .ge. 1) then - ! - ! return max as first element - ! - e = a%elems(1) - - ! - ! move last element to first - ! - a%elems(1) = a%elems(a%heap_size) - a%heap_size = a%heap_size-1 - call heapify(a,1) - return - else - write (*,*) 'PQ_EXTRACT_MAX: error, attempted to pop non-positive PQ' - stop - end if - - end subroutine pq_extract_max - - - real(kdkind) function pq_insert(a,dis,idx) - ! - ! Insert a new element and return the new maximum priority, - ! which may or may not be the same as the old maximum priority. - ! - type(pq),pointer :: a - real(kdkind), intent(in) :: dis - integer, intent(in) :: idx - ! type(kdtree2_result), intent(in) :: e - ! - integer :: i, isparent - real(kdkind) :: parentdis - ! - - ! if (a%heap_size .ge. a%max_elems) then - ! write (*,*) 'PQ_INSERT: error, attempt made to insert element on full PQ' - ! stop - ! else - a%heap_size = a%heap_size + 1 - i = a%heap_size - - do while (i .gt. 1) - isparent = int(i/2) - parentdis = a%elems(isparent)%dis - if (dis .gt. parentdis) then - ! move what was in i's parent into i. - a%elems(i)%dis = parentdis - a%elems(i)%idx = a%elems(isparent)%idx - i = isparent - else - exit - endif - end do - - ! insert the element at the determined position - a%elems(i)%dis = dis - a%elems(i)%idx = idx - - pq_insert = a%elems(1)%dis - return - ! end if - - end function pq_insert - - subroutine pq_adjust_heap(a,i) - type(pq),pointer :: a - integer, intent(in) :: i - ! - ! nominally arguments (a,i), but specialize for a=1 - ! - ! This routine assumes that the trees with roots 2 and 3 are already heaps, i.e. - ! the children of '1' are heaps. When the procedure is completed, the - ! tree rooted at 1 is a heap. - real(kdkind) :: prichild - integer :: parent, child, N - - type(kdtree2_result) :: e - - e = a%elems(i) - - parent = i - child = 2*i - N = a%heap_size - - do while (child .le. N) - if (child .lt. N) then - if (a%elems(child)%dis .lt. a%elems(child+1)%dis) then - child = child+1 - endif - endif - prichild = a%elems(child)%dis - if (e%dis .ge. prichild) then - exit - else - ! move child into parent. - a%elems(parent) = a%elems(child) - parent = child - child = 2*parent - end if - end do - a%elems(parent) = e - return - end subroutine pq_adjust_heap - - - real(kdkind) function pq_replace_max(a,dis,idx) - ! - ! Replace the extant maximum priority element - ! in the PQ with (dis,idx). Return - ! the new maximum priority, which may be larger - ! or smaller than the old one. - ! - type(pq),pointer :: a - real(kdkind), intent(in) :: dis - integer, intent(in) :: idx -! type(kdtree2_result), intent(in) :: e - ! not tested as well! - - integer :: parent, child, N - real(kdkind) :: prichild, prichildp1 - - type(kdtree2_result) :: etmp - - if (.true.) then - N=a%heap_size - if (N .ge. 1) then - parent =1 - child=2 - - loop: do while (child .le. N) - prichild = a%elems(child)%dis - - ! - ! posibly child+1 has higher priority, and if - ! so, get it, and increment child. - ! - - if (child .lt. N) then - prichildp1 = a%elems(child+1)%dis - if (prichild .lt. prichildp1) then - child = child+1 - prichild = prichildp1 - endif - endif - - if (dis .ge. prichild) then - exit loop - ! we have a proper place for our new element, - ! bigger than either children's priority. - else - ! move child into parent. - a%elems(parent) = a%elems(child) - parent = child - child = 2*parent - end if - end do loop - a%elems(parent)%dis = dis - a%elems(parent)%idx = idx - pq_replace_max = a%elems(1)%dis - else - a%elems(1)%dis = dis - a%elems(1)%idx = idx - pq_replace_max = dis - endif - else - ! - ! slower version using elementary pop and push operations. - ! - call pq_extract_max(a,etmp) - etmp%dis = dis - etmp%idx = idx - pq_replace_max = pq_insert(a,dis,idx) - endif - return - end function pq_replace_max - - subroutine pq_delete(a,i) - ! - ! delete item with index 'i' - ! - type(pq),pointer :: a - integer :: i - - if ((i .lt. 1) .or. (i .gt. a%heap_size)) then - write (*,*) 'PQ_DELETE: error, attempt to remove out of bounds element.' - stop - endif - - ! swap the item to be deleted with the last element - ! and shorten heap by one. - a%elems(i) = a%elems(a%heap_size) - a%heap_size = a%heap_size - 1 - - call heapify(a,i) - - end subroutine pq_delete - -end module kdtree2_priority_queue_module - - -module kdtree2_module - use kdtree2_precision_module - use kdtree2_priority_queue_module - use kdtree2module - use tree_nodemodule - use intervalmodule - ! K-D tree routines in Fortran 90 by Matt Kennel. - ! Original program was written in Sather by Steve Omohundro and - ! Matt Kennel. Only the Euclidean metric is supported. - ! - ! - ! This module is identical to 'kd_tree', except that the order - ! of subscripts is reversed in the data file. - ! In otherwords for an embedding of N D-dimensional vectors, the - ! data file is here, in natural Fortran order data(1:D, 1:N) - ! because Fortran lays out columns first, - ! - ! whereas conventionally (C-style) it is data(1:N,1:D) - ! as in the original kd_tree module. - ! - !-------------DATA TYPE, CREATION, DELETION--------------------- - public :: kdkind - public :: kdtree2, kdtree2_result, tree_node, kdtree2_create, kdtree2_destroy - !--------------------------------------------------------------- - !-------------------SEARCH ROUTINES----------------------------- - public :: kdtree2_n_nearest,kdtree2_n_nearest_around_point - ! Return fixed number of nearest neighbors around arbitrary vector, - ! or extant point in dataset, with decorrelation window. - ! - public :: kdtree2_r_nearest, kdtree2_r_nearest_around_point - ! Return points within a fixed ball of arb vector/extant point - ! - public :: kdtree2_sort_results - ! Sort, in order of increasing distance, rseults from above. - ! - public :: kdtree2_r_count, kdtree2_r_count_around_point - ! Count points within a fixed ball of arb vector/extant point - ! - public :: kdtree2_n_nearest_brute_force, kdtree2_r_nearest_brute_force - ! brute force of kdtree2_[n|r]_nearest - !---------------------------------------------------------------- - - - integer, parameter :: bucket_size = 65 - ! The maximum number of points to keep in a terminal node. - -! type interval -! real(kdkind) :: lower,upper -! end type interval -! -! type :: tree_node -! ! an internal tree node -! private -! integer :: cut_dim -! ! the dimension to cut -! real(kdkind) :: cut_val -! ! where to cut the dimension -! real(kdkind) :: cut_val_left, cut_val_right -! ! improved cutoffs knowing the spread in child boxes. -! integer :: l, u -! type(tree_node), pointer :: left, right -! type(interval), pointer :: box(:) => null() -! ! child pointers -! ! Points included in this node are indexes[k] with k \in [l,u] -! -! -! end type tree_node -! -! type :: kdtree2 -! ! Global information about the tree, one per tree -! integer :: dimen=0, n=0 -! ! dimensionality and total # of points -! real(kdkind), pointer :: the_data(:,:) => null() -! ! pointer to the actual data array -! ! -! ! IMPORTANT NOTE: IT IS DIMENSIONED the_data(1:d,1:N) -! ! which may be opposite of what may be conventional. -! ! This is, because in Fortran, the memory layout is such that -! ! the first dimension is in sequential order. Hence, with -! ! (1:d,1:N), all components of the vector will be in consecutive -! ! memory locations. The search time is dominated by the -! ! evaluation of distances in the terminal nodes. Putting all -! ! vector components in consecutive memory location improves -! ! memory cache locality, and hence search speed, and may enable -! ! vectorization on some processors and compilers. -! -! integer, pointer :: ind(:) => null() -! ! permuted index into the data, so that indexes[l..u] of some -! ! bucket represent the indexes of the actual points in that -! ! bucket. -! logical :: sort = .false. -! ! do we always sort output results? -! logical :: rearrange = .false. -! real(kdkind), pointer :: rearranged_data(:,:) => null() -! ! if (rearrange .eqv. .true.) then rearranged_data has been -! ! created so that rearranged_data(:,i) = the_data(:,ind(i)), -! ! permitting search to use more cache-friendly rearranged_data, at -! ! some initial computation and storage cost. -! type(tree_node), pointer :: root => null() -! ! root pointer of the tree -! end type kdtree2 - - type :: tree_search_record - ! - ! One of these is created for each search. - ! - private - ! - ! Many fields are copied from the tree structure, in order to - ! speed up the search. - ! - integer :: dimen - integer :: nn, nfound - real(kdkind) :: ballsize - integer :: centeridx=999, correltime=9999 - ! exclude points within 'correltime' of 'centeridx', iff centeridx >= 0 - integer :: nalloc ! how much allocated for results(:)? - logical :: rearrange ! are the data rearranged or original? - ! did the # of points found overflow the storage provided? - logical :: overflow - real(kdkind), pointer :: qv(:) ! query vector - type(kdtree2_result), pointer :: results(:) ! results - type(pq) :: pq - real(kdkind), pointer :: data(:,:) ! temp pointer to data - integer, pointer :: ind(:) ! temp pointer to indexes - end type tree_search_record - - private - ! everything else is private. - - type(tree_search_record), save, target :: sr ! A GLOBAL VARIABLE for search - -contains - - function kdtree2_create(input_data,dim,sort,rearrange) result (mr) - ! - ! create the actual tree structure, given an input array of data. - ! - ! Note, input data is input_data(1:d,1:N), NOT the other way around. - ! THIS IS THE REVERSE OF THE PREVIOUS VERSION OF THIS MODULE. - ! The reason for it is cache friendliness, improving performance. - ! - ! Optional arguments: If 'dim' is specified, then the tree - ! will only search the first 'dim' components - ! of input_data, otherwise, dim is inferred - ! from SIZE(input_data,1). - ! - ! if sort .eqv. .true. then output results - ! will be sorted by increasing distance. - ! default=.false., as it is faster to not sort. - ! - ! if rearrange .eqv. .true. then an internal - ! copy of the data, rearranged by terminal node, - ! will be made for cache friendliness. - ! default=.true., as it speeds searches, but - ! building takes longer, and extra memory is used. - ! - ! .. Function Return Cut_value .. - type(kdtree2), pointer :: mr - integer, intent(in), optional :: dim - logical, intent(in), optional :: sort - logical, intent(in), optional :: rearrange - ! .. - ! .. Array Arguments .. - real(kdkind), target :: input_data(:,:) - ! - integer :: i - ! .. - allocate (mr) - mr%the_data => input_data - ! pointer assignment - - if (present(dim)) then - mr%dimen = dim - else - mr%dimen = size(input_data,1) - end if - mr%n = size(input_data,2) - - if (mr%dimen > mr%n) then - ! unlikely to be correct - write (*,*) 'KD_TREE_TRANS: likely user error.' - write (*,*) 'KD_TREE_TRANS: You passed in matrix with D=',mr%dimen - write (*,*) 'KD_TREE_TRANS: and N=',mr%n - write (*,*) 'KD_TREE_TRANS: note, that new format is data(1:D,1:N)' - write (*,*) 'KD_TREE_TRANS: with usually N >> D. If N =approx= D, then a k-d tree' - write (*,*) 'KD_TREE_TRANS: is not an appropriate data structure.' - stop - end if - - call build_tree(mr) - - if (present(sort)) then - mr%sort = sort - else - mr%sort = .false. - endif - - if (present(rearrange)) then - mr%rearrange = rearrange - else - mr%rearrange = .true. - endif - - if (mr%rearrange) then - allocate(mr%rearranged_data(mr%dimen,mr%n)) - do i=1,mr%n - mr%rearranged_data(:,i) = mr%the_data(:, & - mr%ind(i)) - enddo - else - nullify(mr%rearranged_data) - endif - - end function kdtree2_create - - subroutine build_tree(tp) - type(kdtree2), pointer :: tp - ! .. - integer :: j - type(tree_node), pointer :: dummy => null() - ! .. - allocate (tp%ind(tp%n)) - forall (j=1:tp%n) - tp%ind(j) = j - end forall - tp%root => build_tree_for_range(tp,1,tp%n, dummy) - end subroutine build_tree - - recursive function build_tree_for_range(tp,l,u,parent) result (res) - ! .. Function Return Cut_value .. - type(tree_node), pointer :: res - ! .. - ! .. Structure Arguments .. - type(kdtree2), pointer :: tp - type(tree_node),pointer :: parent - ! .. - ! .. Scalar Arguments .. - integer, intent (In) :: l, u - ! .. - ! .. Local Scalars .. - integer :: i, c, m, dimen - logical :: recompute - real(kdkind) :: average - -!!$ If (.False.) Then -!!$ If ((l .Lt. 1) .Or. (l .Gt. tp%n)) Then -!!$ Stop 'illegal L value in build_tree_for_range' -!!$ End If -!!$ If ((u .Lt. 1) .Or. (u .Gt. tp%n)) Then -!!$ Stop 'illegal u value in build_tree_for_range' -!!$ End If -!!$ If (u .Lt. l) Then -!!$ Stop 'U is less than L, thats illegal.' -!!$ End If -!!$ Endif -!!$ - ! first compute min and max - dimen = tp%dimen - allocate (res) - allocate(res%box(dimen)) - - ! First, compute an APPROXIMATE bounding box of all points associated with this node. - if ( u < l ) then - ! no points in this box - nullify(res) - return - end if - - if ((u-l)<=bucket_size) then - ! - ! always compute true bounding box for terminal nodes. - ! - do i=1,dimen - call spread_in_coordinate(tp,i,l,u,res%box(i)) - end do - res%cut_dim = 0 - res%cut_val = 0.0 - res%l = l - res%u = u - res%left =>null() - res%right => null() - else - ! - ! modify approximate bounding box. This will be an - ! overestimate of the true bounding box, as we are only recomputing - ! the bounding box for the dimension that the parent split on. - ! - ! Going to a true bounding box computation would significantly - ! increase the time necessary to build the tree, and usually - ! has only a very small difference. This box is not used - ! for searching but only for deciding which coordinate to split on. - ! - do i=1,dimen - recompute=.true. - if (associated(parent)) then - if (i .ne. parent%cut_dim) then - recompute=.false. - end if - endif - if (recompute) then - call spread_in_coordinate(tp,i,l,u,res%box(i)) - else - res%box(i) = parent%box(i) - endif - end do - - - c = maxloc(res%box(1:dimen)%upper-res%box(1:dimen)%lower,1) - ! - ! c is the identity of which coordinate has the greatest spread. - ! - - if (.false.) then - ! select exact median to have fully balanced tree. - m = (l+u)/2 - call select_on_coordinate(tp%the_data,tp%ind,c,m,l,u) - else - ! - ! select point halfway between min and max, as per A. Moore, - ! who says this helps in some degenerate cases, or - ! actual arithmetic average. - ! - if (.true.) then - ! actually compute average - average = sum(tp%the_data(c,tp%ind(l:u))) / real(u-l+1,kdkind) - else - average = (res%box(c)%upper + res%box(c)%lower)/2.0 - endif - - res%cut_val = average - m = select_on_coordinate_value(tp%the_data,tp%ind,c,average,l,u) - endif - - ! moves indexes around - res%cut_dim = c - res%l = l - res%u = u -! res%cut_val = tp%the_data(c,tp%ind(m)) - - res%left => build_tree_for_range(tp,l,m,res) - res%right => build_tree_for_range(tp,m+1,u,res) - - if (associated(res%right) .eqv. .false.) then - res%box = res%left%box - res%cut_val_left = res%left%box(c)%upper - res%cut_val = res%cut_val_left - elseif (associated(res%left) .eqv. .false.) then - res%box = res%right%box - res%cut_val_right = res%right%box(c)%lower - res%cut_val = res%cut_val_right - else - res%cut_val_right = res%right%box(c)%lower - res%cut_val_left = res%left%box(c)%upper - res%cut_val = (res%cut_val_left + res%cut_val_right)/2 - - - ! now remake the true bounding box for self. - ! Since we are taking unions (in effect) of a tree structure, - ! this is much faster than doing an exhaustive - ! search over all points - res%box%upper = max(res%left%box%upper,res%right%box%upper) - res%box%lower = min(res%left%box%lower,res%right%box%lower) - endif - end if - end function build_tree_for_range - - integer function select_on_coordinate_value(v,ind,c,alpha,li,ui) & - result(res) - ! Move elts of ind around between l and u, so that all points - ! <= than alpha (in c cooordinate) are first, and then - ! all points > alpha are second. - - ! - ! Algorithm (matt kennel). - ! - ! Consider the list as having three parts: on the left, - ! the points known to be <= alpha. On the right, the points - ! known to be > alpha, and in the middle, the currently unknown - ! points. The algorithm is to scan the unknown points, starting - ! from the left, and swapping them so that they are added to - ! the left stack or the right stack, as appropriate. - ! - ! The algorithm finishes when the unknown stack is empty. - ! - ! .. Scalar Arguments .. - integer, intent (In) :: c, li, ui - real(kdkind), intent(in) :: alpha - ! .. - real(kdkind) :: v(1:,1:) - integer :: ind(1:) - integer :: tmp - ! .. - integer :: lb, rb - ! - ! The points known to be <= alpha are in - ! [l,lb-1] - ! - ! The points known to be > alpha are in - ! [rb+1,u]. - ! - ! Therefore we add new points into lb or - ! rb as appropriate. When lb=rb - ! we are done. We return the location of the last point <= alpha. - ! - ! - lb = li; rb = ui - - do while (lb < rb) - if ( v(c,ind(lb)) <= alpha ) then - ! it is good where it is. - lb = lb+1 - else - ! swap it with rb. - tmp = ind(lb); ind(lb) = ind(rb); ind(rb) = tmp - rb = rb-1 - endif - end do - - ! now lb .eq. ub - if (v(c,ind(lb)) <= alpha) then - res = lb - else - res = lb-1 - endif - - end function select_on_coordinate_value - - subroutine select_on_coordinate(v,ind,c,k,li,ui) - ! Move elts of ind around between l and u, so that the kth - ! element - ! is >= those below, <= those above, in the coordinate c. - ! .. Scalar Arguments .. - integer, intent (In) :: c, k, li, ui - ! .. - integer :: i, l, m, s, t, u - ! .. - real(kdkind) :: v(:,:) - integer :: ind(:) - ! .. - l = li - u = ui - do while (l=k) u = m - 1 - end do - end subroutine select_on_coordinate - - subroutine spread_in_coordinate(tp,c,l,u,interv) - ! the spread in coordinate 'c', between l and u. - ! - ! Return lower bound in 'smin', and upper in 'smax', - ! .. - ! .. Structure Arguments .. - type(kdtree2), pointer :: tp - type(interval), intent(out) :: interv - ! .. - ! .. Scalar Arguments .. - integer, intent (In) :: c, l, u - ! .. - ! .. Local Scalars .. - real(kdkind) :: last, lmax, lmin, t, smin,smax - integer :: i, ulocal - ! .. - ! .. Local Arrays .. - real(kdkind), pointer :: v(:,:) - integer, pointer :: ind(:) - ! .. - v => tp%the_data(1:,1:) - ind => tp%ind(1:) - smin = v(c,ind(l)) - smax = smin - - ulocal = u - - do i = l + 2, ulocal, 2 - lmin = v(c,ind(i-1)) - lmax = v(c,ind(i)) - if (lmin>lmax) then - t = lmin - lmin = lmax - lmax = t - end if - if (smin>lmin) smin = lmin - if (smaxlast) smin = last - if (smax qv - sr%nn = nn - sr%nfound = 0 - sr%centeridx = -1 - sr%correltime = 0 - sr%overflow = .false. - - sr%results => results - - sr%nalloc = nn ! will be checked - - sr%ind => tp%ind - sr%rearrange = tp%rearrange - if (tp%rearrange) then - sr%Data => tp%rearranged_data - else - sr%Data => tp%the_data - endif - sr%dimen = tp%dimen - - call validate_query_storage(nn) - sr%pq = pq_create(results) - - call search(tp%root) - - if (tp%sort) then - call kdtree2_sort_results(nn, results) - endif -! deallocate(sr%pqp) - return - end subroutine kdtree2_n_nearest - - subroutine kdtree2_n_nearest_around_point(tp,idxin,correltime,nn,results) - ! Find the 'nn' vectors in the tree nearest to point 'idxin', - ! with correlation window 'correltime', returing results in - ! results(:), which must be pre-allocated upon entry. - type(kdtree2), pointer :: tp - integer, intent (In) :: idxin, correltime, nn - type(kdtree2_result), target :: results(:) - - allocate (sr%qv(tp%dimen)) - sr%qv = tp%the_data(:,idxin) ! copy the vector - sr%ballsize = huge(1.0) ! the largest real(kdkind) number - sr%centeridx = idxin - sr%correltime = correltime - - sr%nn = nn - sr%nfound = 0 - - sr%dimen = tp%dimen - sr%nalloc = nn - - sr%results => results - - sr%ind => tp%ind - sr%rearrange = tp%rearrange - - if (sr%rearrange) then - sr%Data => tp%rearranged_data - else - sr%Data => tp%the_data - endif - - call validate_query_storage(nn) - sr%pq = pq_create(results) - - call search(tp%root) - - if (tp%sort) then - call kdtree2_sort_results(nn, results) - endif - deallocate (sr%qv) - return - end subroutine kdtree2_n_nearest_around_point - - subroutine kdtree2_r_nearest(tp,qv,r2,nfound,nalloc,results) - ! find the nearest neighbors to point 'qv', within SQUARED - ! Euclidean distance 'r2'. Upon ENTRY, nalloc must be the - ! size of memory allocated for results(1:nalloc). Upon - ! EXIT, nfound is the number actually found within the ball. - ! - ! Note that if nfound .gt. nalloc then more neighbors were found - ! than there were storage to store. The resulting list is NOT - ! the smallest ball inside norm r^2 - ! - ! Results are NOT sorted unless tree was created with sort option. - type(kdtree2), pointer :: tp - real(kdkind), target, intent (In) :: qv(:) - real(kdkind), intent(in) :: r2 - integer, intent(out) :: nfound - integer, intent (In) :: nalloc - type(kdtree2_result), target :: results(:) - - ! - sr%qv => qv - sr%ballsize = r2 - sr%nn = 0 ! flag for fixed ball search - sr%nfound = 0 - sr%centeridx = -1 - sr%correltime = 0 - - sr%results => results - - call validate_query_storage(nalloc) - sr%nalloc = nalloc - sr%overflow = .false. - sr%ind => tp%ind - sr%rearrange= tp%rearrange - - if (tp%rearrange) then - sr%Data => tp%rearranged_data - else - sr%Data => tp%the_data - endif - sr%dimen = tp%dimen - - ! - !sr%dsl = Huge(sr%dsl) ! set to huge positive values - !sr%il = -1 ! set to invalid indexes - ! - - call search(tp%root) - nfound = sr%nfound - if (tp%sort) then - call kdtree2_sort_results(nfound, results) - endif - - !if (sr%overflow) then - ! write (*,*) 'KD_TREE_TRANS: warning! return from kdtree2_r_nearest found more neighbors' - ! write (*,*) 'KD_TREE_TRANS: than storage was provided for. Answer is NOT smallest ball' - ! write (*,*) 'KD_TREE_TRANS: with that number of neighbors! I.e. it is wrong.' - !endif - - return - end subroutine kdtree2_r_nearest - - subroutine kdtree2_r_nearest_around_point(tp,idxin,correltime,r2,& - nfound,nalloc,results) - ! - ! Like kdtree2_r_nearest, but around a point 'idxin' already existing - ! in the data set. - ! - ! Results are NOT sorted unless tree was created with sort option. - ! - type(kdtree2), pointer :: tp - integer, intent (In) :: idxin, correltime, nalloc - real(kdkind), intent(in) :: r2 - integer, intent(out) :: nfound - type(kdtree2_result), target :: results(:) - ! .. - ! .. Intrinsic Functions .. - intrinsic HUGE - ! .. - allocate (sr%qv(tp%dimen)) - sr%qv = tp%the_data(:,idxin) ! copy the vector - sr%ballsize = r2 - sr%nn = 0 ! flag for fixed r search - sr%nfound = 0 - sr%centeridx = idxin - sr%correltime = correltime - - sr%results => results - - sr%nalloc = nalloc - sr%overflow = .false. - - call validate_query_storage(nalloc) - - ! sr%dsl = HUGE(sr%dsl) ! set to huge positive values - ! sr%il = -1 ! set to invalid indexes - - sr%ind => tp%ind - sr%rearrange = tp%rearrange - - if (tp%rearrange) then - sr%Data => tp%rearranged_data - else - sr%Data => tp%the_data - endif - sr%rearrange = tp%rearrange - sr%dimen = tp%dimen - - ! - !sr%dsl = Huge(sr%dsl) ! set to huge positive values - !sr%il = -1 ! set to invalid indexes - ! - - call search(tp%root) - nfound = sr%nfound - if (tp%sort) then - call kdtree2_sort_results(nfound,results) - endif - - if (sr%overflow) then - write (*,*) 'KD_TREE_TRANS: warning! return from kdtree2_r_nearest found more neighbors' - write (*,*) 'KD_TREE_TRANS: than storage was provided for. Answer is NOT smallest ball' - write (*,*) 'KD_TREE_TRANS: with that number of neighbors! I.e. it is wrong.' - endif - - deallocate (sr%qv) - return - end subroutine kdtree2_r_nearest_around_point - - function kdtree2_r_count(tp,qv,r2) result(nfound) - ! Count the number of neighbors within square distance 'r2'. - type(kdtree2), pointer :: tp - real(kdkind), target, intent (In) :: qv(:) - real(kdkind), intent(in) :: r2 - integer :: nfound - ! .. - ! .. Intrinsic Functions .. - intrinsic HUGE - ! .. - sr%qv => qv - sr%ballsize = r2 - - sr%nn = 0 ! flag for fixed r search - sr%nfound = 0 - sr%centeridx = -1 - sr%correltime = 0 - - nullify(sr%results) ! for some reason, FTN 95 chokes on '=> null()' - - sr%nalloc = 0 ! we do not allocate any storage but that's OK - ! for counting. - sr%ind => tp%ind - sr%rearrange = tp%rearrange - if (tp%rearrange) then - sr%Data => tp%rearranged_data - else - sr%Data => tp%the_data - endif - sr%dimen = tp%dimen - - ! - !sr%dsl = Huge(sr%dsl) ! set to huge positive values - !sr%il = -1 ! set to invalid indexes - ! - sr%overflow = .false. - - call search(tp%root) - - nfound = sr%nfound - - return - end function kdtree2_r_count - - function kdtree2_r_count_around_point(tp,idxin,correltime,r2) & - result(nfound) - ! Count the number of neighbors within square distance 'r2' around - ! point 'idxin' with decorrelation time 'correltime'. - ! - type(kdtree2), pointer :: tp - integer, intent (In) :: correltime, idxin - real(kdkind), intent(in) :: r2 - integer :: nfound - ! .. - ! .. - ! .. Intrinsic Functions .. - intrinsic HUGE - ! .. - allocate (sr%qv(tp%dimen)) - sr%qv = tp%the_data(:,idxin) - sr%ballsize = r2 - - sr%nn = 0 ! flag for fixed r search - sr%nfound = 0 - sr%centeridx = idxin - sr%correltime = correltime - nullify(sr%results) - - sr%nalloc = 0 ! we do not allocate any storage but that's OK - ! for counting. - - sr%ind => tp%ind - sr%rearrange = tp%rearrange - - if (sr%rearrange) then - sr%Data => tp%rearranged_data - else - sr%Data => tp%the_data - endif - sr%dimen = tp%dimen - - ! - !sr%dsl = Huge(sr%dsl) ! set to huge positive values - !sr%il = -1 ! set to invalid indexes - ! - sr%overflow = .false. - - call search(tp%root) - - nfound = sr%nfound - - return - end function kdtree2_r_count_around_point - - - subroutine validate_query_storage(n) - ! - ! make sure we have enough storage for n - ! - integer, intent(in) :: n - - if (size(sr%results,1) .lt. n) then - write (*,*) 'KD_TREE_TRANS: you did not provide enough storage for results(1:n)' - stop - return - endif - - return - end subroutine validate_query_storage - - function square_distance(d, iv,qv) result (res) - ! distance between iv[1:n] and qv[1:n] - ! .. Function Return Value .. - ! re-implemented to improve vectorization. - real(kdkind) :: res - ! .. - ! .. - ! .. Scalar Arguments .. - integer :: d - real :: d_min(d) - ! .. - ! .. Array Arguments .. - real(kdkind) :: iv(:),qv(:) - ! .. - ! .. - ! .. Periodicity added by S Skory - ! res = sum( (iv(1:d)-qv(1:d))**2 ) - d_min = min( abs(iv(1:d) - qv(1:d)) , 1. - abs(iv(1:d) - qv(1:d)) ) - res = sum(d_min(1:d)**2) - end function square_distance - - recursive subroutine search(node) - ! - ! This is the innermost core routine of the kd-tree search. Along - ! with "process_terminal_node", it is the performance bottleneck. - ! - ! This version uses a logically complete secondary search of - ! "box in bounds", whether the sear - ! - type(Tree_node), pointer :: node - ! .. - type(tree_node),pointer :: ncloser, nfarther - ! - integer :: cut_dim, i - ! .. - real(kdkind) :: qval, dis, dis_right, dis_left, dis_node - real(kdkind) :: ballsize - real(kdkind), pointer :: qv(:) - type(interval), pointer :: box(:) - - if ((associated(node%left) .and. associated(node%right)) .eqv. .false.) then - ! we are on a terminal node - if (sr%nn .eq. 0) then - call process_terminal_node_fixedball(node) - else - call process_terminal_node(node) - endif - else - ! we are not on a terminal node - qv => sr%qv(1:) - cut_dim = node%cut_dim - qval = qv(cut_dim) - - - ! Periodic stuff added by S Skory. We have to test to see which - ! node edge is closer, rather than just doing a simple less than or - ! greater than to the cut in this dimension. - dis_left = min( (node%box(cut_dim)%lower - qval)**2, & - (1 - abs(node%box(cut_dim)%lower - qval))**2) - dis_right = min( (node%box(cut_dim)%upper - qval)**2, & - (1 - abs(node%box(cut_dim)%upper - qval))**2) - - - if (qval < node%cut_val) then - !if (dis_left <= dis_right) then - ncloser => node%left - nfarther => node%right - dis_node = (node%cut_val_right - qval)**2 - dis = min(dis_right, dis_node) -! extra = node%cut_val - qval - else - ncloser => node%right - nfarther => node%left - dis_node = (node%cut_val_left - qval)**2 - dis = min(dis_left, dis_node) -! extra = qval- node%cut_val_left - endif - - if (associated(ncloser)) call search(ncloser) - - ! we may need to search the second node. - if (associated(nfarther)) then - ballsize = sr%ballsize -! dis=extra**2 - - if (dis <= ballsize) then - ! - ! we do this separately as going on the first cut dimen is often - ! a good idea. - ! note that if extra**2 < sr%ballsize, then the next - ! check will also be false. - ! - box => node%box(1:) - do i=1,sr%dimen - if (i .ne. cut_dim) then - dis = dis + dis2_from_bnd(qv(i),box(i)%lower,box(i)%upper) - if (dis > ballsize) then - return - endif - endif - end do - - ! - ! if we are still here then we need to search mroe. - ! - call search(nfarther) - endif - endif - end if - end subroutine search - - -! real(kdkind) function dis2_from_bnd(x,amin,amax) result (res) -! real(kdkind), intent(in) :: x, amin,amax -! -! if (x > amax) then -! res = (x-amax)**2; -! return -! else -! if (x < amin) then -! res = (amin-x)**2; -! return -! else -! res = 0.0 -! return -! endif -! endif -! return -! end function dis2_from_bnd - - real(kdkind) function dis2_from_bnd(x,amin,amax) result (res) - ! Periodicity added by S Skory - real(kdkind), intent(in) :: x, amin,amax - real :: dxmax, dxmin - - if ((x < amax) .and. (x > amin)) then - res = 0.0 - return - else - dxmax = (min( abs(x - amax), 1. - abs(x - amax)))**2 - dxmin = (min( abs(x - amin), 1. - abs(x - amin)))**2 - res = min(dxmax, dxmin) - return - endif - return - end function dis2_from_bnd - - logical function box_in_search_range(node, sr) result(res) - ! - ! Return the distance from 'qv' to the CLOSEST corner of node's - ! bounding box - ! for all coordinates outside the box. Coordinates inside the box - ! contribute nothing to the distance. - ! - type(tree_node), pointer :: node - type(tree_search_record), pointer :: sr - - integer :: dimen, i - real(kdkind) :: dis, ballsize - real(kdkind) :: l, u - - dimen = sr%dimen - ballsize = sr%ballsize - dis = 0.0 - res = .true. - do i=1,dimen - l = node%box(i)%lower - u = node%box(i)%upper - dis = dis + (dis2_from_bnd(sr%qv(i),l,u)) - if (dis > ballsize) then - res = .false. - return - endif - end do - res = .true. - return - end function box_in_search_range - - - subroutine process_terminal_node(node) - ! - ! Look for actual near neighbors in 'node', and update - ! the search results on the sr data structure. - ! - type(tree_node), pointer :: node - ! - real(kdkind), pointer :: qv(:) - integer, pointer :: ind(:) - real(kdkind), pointer :: data(:,:) - ! - integer :: dimen, i, indexofi, k, centeridx, correltime - real(kdkind) :: ballsize, sd, newpri - logical :: rearrange - type(pq), pointer :: pqp - real :: sdtemp - ! - ! copy values from sr to local variables - ! - ! - ! Notice, making local pointers with an EXPLICIT lower bound - ! seems to generate faster code. - ! why? I don't know. - qv => sr%qv(1:) - pqp => sr%pq - dimen = sr%dimen - ballsize = sr%ballsize - rearrange = sr%rearrange - ind => sr%ind(1:) - data => sr%Data(1:,1:) - centeridx = sr%centeridx - correltime = sr%correltime - - ! doing_correl = (centeridx >= 0) ! Do we have a decorrelation window? - ! include_point = .true. ! by default include all points - ! search through terminal bucket. - - mainloop: do i = node%l, node%u - if (rearrange) then - sd = 0.0 - do k = 1,dimen - !sd = sd + (data(k,i) - qv(k))**2 - ! Periodicity by S Skory - sdtemp = min( abs(data(k,i) - qv(k)) , 1. - abs(data(k,i) - qv(k))) - sd = sd + sdtemp**2 - if (sd>ballsize) cycle mainloop - end do - indexofi = ind(i) ! only read it if we have not broken out - else - indexofi = ind(i) - sd = 0.0 - do k = 1,dimen - !sd = sd + (data(k,indexofi) - qv(k))**2 - sdtemp = min( abs(data(k,indexofi) - qv(k)), 1. - abs(data(k,indexofi) - qv(k))) - sd = sd + sdtemp**2 - if (sd>ballsize) cycle mainloop - end do - endif - - if (centeridx > 0) then ! doing correlation interval? - if (abs(indexofi-centeridx) < correltime) cycle mainloop - endif - - - ! - ! two choices for any point. The list so far is either undersized, - ! or it is not. - ! - ! If it is undersized, then add the point and its distance - ! unconditionally. If the point added fills up the working - ! list then set the sr%ballsize, maximum distance bound (largest distance on - ! list) to be that distance, instead of the initialized +infinity. - ! - ! If the running list is full size, then compute the - ! distance but break out immediately if it is larger - ! than sr%ballsize, "best squared distance" (of the largest element), - ! as it cannot be a good neighbor. - ! - ! Once computed, compare to best_square distance. - ! if it is smaller, then delete the previous largest - ! element and add the new one. - - if (sr%nfound .lt. sr%nn) then - ! - ! add this point unconditionally to fill list. - ! - sr%nfound = sr%nfound +1 - newpri = pq_insert(pqp,sd,indexofi) - if (sr%nfound .eq. sr%nn) ballsize = newpri - ! we have just filled the working list. - ! put the best square distance to the maximum value - ! on the list, which is extractable from the PQ. - - else - ! - ! now, if we get here, - ! we know that the current node has a squared - ! distance smaller than the largest one on the list, and - ! belongs on the list. - ! Hence we replace that with the current one. - ! - ballsize = pq_replace_max(pqp,sd,indexofi) - endif - end do mainloop - ! - ! Reset sr variables which may have changed during loop - ! - sr%ballsize = ballsize - - end subroutine process_terminal_node - - subroutine process_terminal_node_fixedball(node) - ! - ! Look for actual near neighbors in 'node', and update - ! the search results on the sr data structure, i.e. - ! save all within a fixed ball. - ! - type(tree_node), pointer :: node - ! - real(kdkind), pointer :: qv(:) - integer, pointer :: ind(:) - real(kdkind), pointer :: data(:,:) - ! - integer :: nfound - integer :: dimen, i, indexofi, k - integer :: centeridx, correltime, nn - real(kdkind) :: ballsize, sd - logical :: rearrange - real :: sdtemp - ! - ! copy values from sr to local variables - ! - qv => sr%qv(1:) - dimen = sr%dimen - ballsize = sr%ballsize - rearrange = sr%rearrange - ind => sr%ind(1:) - data => sr%Data(1:,1:) - centeridx = sr%centeridx - correltime = sr%correltime - nn = sr%nn ! number to search for - nfound = sr%nfound - - ! search through terminal bucket. - mainloop: do i = node%l, node%u - - ! - ! two choices for any point. The list so far is either undersized, - ! or it is not. - ! - ! If it is undersized, then add the point and its distance - ! unconditionally. If the point added fills up the working - ! list then set the sr%ballsize, maximum distance bound (largest distance on - ! list) to be that distance, instead of the initialized +infinity. - ! - ! If the running list is full size, then compute the - ! distance but break out immediately if it is larger - ! than sr%ballsize, "best squared distance" (of the largest element), - ! as it cannot be a good neighbor. - ! - ! Once computed, compare to best_square distance. - ! if it is smaller, then delete the previous largest - ! element and add the new one. - - ! which index to the point do we use? - - if (rearrange) then - sd = 0.0 - do k = 1,dimen - !sd = sd + (data(k,i) - qv(k))**2 - ! Periodicity S Skory - sdtemp = min( abs(data(k,i) - qv(k)) , 1. - abs(data(k,i) - qv(k))) - ! print *, "k ", k, " data(k,i) ", data(k,i), " qv(k) ", qv(k), " sdtemp ", sdtemp - sd = sd + sdtemp**2 - if (sd>ballsize) cycle mainloop - end do - indexofi = ind(i) ! only read it if we have not broken out - else - indexofi = ind(i) - sd = 0.0 - do k = 1,dimen - !sd = sd + (data(k,indexofi) - qv(k))**2 - ! Periodicity S Skory - sdtemp = min( abs(data(k,indexofi) - qv(k)), 1. - abs(data(k,indexofi) - qv(k))) - ! print *, "k ", k, " data(k,indexofi) ", data(k,indexofi), " qv(k) ", qv(k), " sdtemp ", sdtemp - sd = sd + sdtemp**2 - if (sd>ballsize) cycle mainloop - end do - endif - - if (centeridx > 0) then ! doing correlation interval? - if (abs(indexofi-centeridx) 1)then - ileft=ileft-1 - value=a(ileft); ivalue=ind(ileft) - else - value=a(iright); ivalue=ind(iright) - a(iright)=a(1); ind(iright)=ind(1) - iright=iright-1 - if (iright == 1) then - a(1)=value;ind(1)=ivalue - return - endif - endif - i=ileft - j=2*ileft - do while (j <= iright) - if(j < iright) then - if(a(j) < a(j+1)) j=j+1 - endif - if(value < a(j)) then - a(i)=a(j); ind(i)=ind(j) - i=j - j=j+j - else - j=iright+1 - endif - end do - a(i)=value; ind(i)=ivalue - end do - end subroutine heapsort - - subroutine heapsort_struct(a,n) - ! - ! Sort a(1:n) in ascending order - ! - ! - integer,intent(in) :: n - type(kdtree2_result),intent(inout) :: a(:) - - ! - ! - type(kdtree2_result) :: value ! temporary value - - integer :: i,j - integer :: ileft,iright - - ileft=n/2+1 - iright=n - - ! do i=1,n - ! ind(i)=i - ! Generate initial idum array - ! end do - - if(n.eq.1) return - - do - if(ileft > 1)then - ileft=ileft-1 - value=a(ileft) - else - value=a(iright) - a(iright)=a(1) - iright=iright-1 - if (iright == 1) then - a(1) = value - return - endif - endif - i=ileft - j=2*ileft - do while (j <= iright) - if(j < iright) then - if(a(j)%dis < a(j+1)%dis) j=j+1 - endif - if(value%dis < a(j)%dis) then - a(i)=a(j); - i=j - j=j+j - else - j=iright+1 - endif - end do - a(i)=value - end do - end subroutine heapsort_struct - -end module kdtree2_module - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/kdtree2-README --- a/yt/extensions/kdtree/kdtree2-README Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -KDTREE 2: Fortran 95 and C++ software to efficiently search for near -neighbors in a multi-dimensional Euclidean space. - -\author{Matthew B. Kennel} - -\affiliation{Institute for Nonlinear Science, - University of California, San Diego} - - \begin{abstract} - Many data-based statistical algorithms require that one find \textit{near - or nearest neighbors} to a given vector among a set of points in that - vector space, usually with Euclidean topology. The k-d data structure - and search algorithms are the generalization of classical binary search - trees to higher dimensional spaces, so that one may locate near neighbors - to an example vector in $O(\log N)$ time instead of the brute-force - $O(N)$ time, with $N$ being the size of the data base. KDTREE2 is - a Fortran 95 module, and a parallel set of C++ classes which implement - tree construction and search routines to find either a set of $m$ - nearest neighbors to an example, or all the neighbors within some - Euclidean distance $r.$ The two versions are independent and function - fully on their own. Considerable care has been taken in the implementation - of the search methods, resulting in substantially higher computational - efficiency (up to an order of magnitude faster) than the author's - previous Internet-distributed version. Architectural improvements - include rearrangement for memory cache-friendly performance, heap-based - priority queues for large $m$searches, and more effective pruning - of search paths by geometrical constraints to avoid wasted effort. - The improvements are the most potent in the more difficult and slowest - cases: larger data base sizes, higher dimensionality manifolds containing - the data set, and larger numbers of neighbors to search for. The C++ - implementation requires the Standard Template Library as well as the - BOOST C++ library be installed. - \end{abstract} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/kdtree/test.py --- a/yt/extensions/kdtree/test.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -from Forthon import * -from fKDpy import * -import numpy,random - -n = 32768 - - -fKD.tags = fzeros((64),'i') -fKD.dist = fzeros((64),'d') -fKD.pos = fzeros((3,n),'d') -fKD.nn = 64 -fKD.nparts = n -fKD.sort = True -fKD.rearrange = True -fKD.qv = numpy.array([16./32, 16./32, 16./32]) - -fp = open('parts.txt','r') -xpos = [] -ypos = [] -zpos = [] -line = fp.readline() -while line: - line = line.split() - xpos.append(float(line[0])) - ypos.append(float(line[1])) - zpos.append(float(line[2])) - line= fp.readline() - -fp.close() - - -for k in range(32): - for j in range(32): - for i in range(32): - fKD.pos[0][i + j*32 + k*1024] = float(i)/32 + 1./64 + 0.0001*random.random() - fKD.pos[1][i + j*32 + k*1024] = float(j)/32 + 1./64 + 0.0001*random.random() - fKD.pos[2][i + j*32 + k*1024] = float(k)/32 + 1./64 + 0.0001*random.random() - - - -#print fKD.pos[0][0],fKD.pos[1][0],fKD.pos[2][0] - -create_tree() - - -find_nn_nearest_neighbors() - -#print 'next' - -#fKD.qv = numpy.array([0., 0., 0.]) - -#find_nn_nearest_neighbors() - - -#print (fKD.tags - 1) -#print fKD.dist - -free_tree() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/light_ray.py --- a/yt/extensions/light_ray.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,372 +0,0 @@ -""" -LightRay class and member functions. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from yt.logger import lagosLogger as mylog -from yt.funcs import * -from mpi4py import MPI -import yt.extensions.EnzoSimulation as ES -import yt.extensions.halo_profiler as HP -import yt.lagos as lagos -import numpy as na -import copy -import h5py - -my_rank = MPI.COMM_WORLD.rank -my_size = MPI.COMM_WORLD.size - -class LightRay(ES.EnzoSimulation): - def __init__(self, EnzoParameterFile, FinalRedshift, InitialRedshift, deltaz_min=0.0, - use_minimum_datasets=True, minimum_coherent_box_fraction=0.0, **kwargs): - - ES.EnzoSimulation.__init__(self, EnzoParameterFile, initial_redshift=InitialRedshift, - final_redshift=FinalRedshift, links=True, - enzo_parameters={'CosmologyComovingBoxSize':float}, **kwargs) - - self.deltaz_min = deltaz_min - self.use_minimum_datasets = use_minimum_datasets - self.minimum_coherent_box_fraction = minimum_coherent_box_fraction - self.dtype = '>f8' - - self.light_ray_solution = [] - self._data = {} - - # Don't use box coherence with maximum dataset depths. - if self.use_minimum_datasets and self.minimum_coherent_box_fraction > 0: - mylog.info("Setting minimum_coherent_box_fraction to 0 with minimal light ray.") - self.minimum_coherent_box_fraction = 0 - - # Get list of datasets for light ray solution. - self.light_ray_solution = self.create_cosmology_splice(minimal=self.use_minimum_datasets, - deltaz_min=self.deltaz_min) - - def _calculate_light_ray_solution(self, seed=None, filename=None): - "Create list of datasets to be added together to make the light ray." - - # Calculate dataset sizes, and get random dataset axes and centers. - na.random.seed(seed) - - # For box coherence, keep track of effective depth travelled. - boxFractionUsed = 0.0 - - for q in range(len(self.light_ray_solution)): - #if self.light_ray_solution[q].has_key('previous'): del self.light_ray_solution[q]['previous'] - #if self.light_ray_solution[q].has_key('next'): del self.light_ray_solution[q]['next'] - if (q == len(self.light_ray_solution) - 1): - z_next = self.FinalRedshift - else: - z_next = self.light_ray_solution[q+1]['redshift'] - - # Calculate fraction of box required for a depth of delta z - self.light_ray_solution[q]['TraversalBoxFraction'] = self.cosmology.ComovingRadialDistance(z_next, self.light_ray_solution[q]['redshift']) * \ - self.enzoParameters['CosmologyHubbleConstantNow'] / self.enzoParameters['CosmologyComovingBoxSize'] - - # Simple error check to make sure more than 100% of box depth is never required. - if (self.light_ray_solution[q]['TraversalBoxFraction'] > 1.0): - mylog.error("Warning: box fraction required to go from z = %f to %f is %f" % - (self.light_ray_solution[q]['redshift'], z_next, - self.light_ray_solution[q]['TraversalBoxFraction'])) - mylog.error("Full box delta z is %f, but it is %f to the next data dump." % - (self.light_ray_solution[q]['deltazMax'], - self.light_ray_solution[q]['redshift']-z_next)) - - # Get dataset axis and center. - # If using box coherence, only get start point and vector if enough of the box has been used, - # or if boxFractionUsed will be greater than 1 after this slice. - if (q == 0) or (self.minimum_coherent_box_fraction == 0) or \ - (boxFractionUsed > self.minimum_coherent_box_fraction) or \ - (boxFractionUsed + self.light_ray_solution[q]['TraversalBoxFraction'] > 1.0): - # Random star point - self.light_ray_solution[q]['start'] = na.random.random(3) - theta = na.pi * na.random.random() - phi = 2 * na.pi * na.random.random() - boxFractionUsed = 0.0 - else: - # Use end point of previous segment and same theta and phi. - self.light_ray_solution[q]['start'] = self.light_ray_solution[q-1]['end'][:] - - self.light_ray_solution[q]['end'] = self.light_ray_solution[q]['start'] + \ - self.light_ray_solution[q]['TraversalBoxFraction'] * na.array([na.cos(phi) * na.sin(theta), - na.sin(phi) * na.sin(theta), - na.cos(theta)]) - boxFractionUsed += self.light_ray_solution[q]['TraversalBoxFraction'] - - if filename is not None: - self._write_light_ray_solution(filename, extra_info={'EnzoParameterFile':self.EnzoParameterFile, 'RandomSeed':seed, - 'InitialRedshift':self.InitialRedshift, 'FinalRedshift':self.FinalRedshift}) - - def make_light_ray(self, seed=None, fields=None, solution_filename=None, data_filename=None, - get_nearest_galaxy=False, **kwargs): - "Create a light ray and get field values for each lixel." - - # Calculate solution. - self._calculate_light_ray_solution(seed=seed, filename=solution_filename) - - # Initialize data structures. - self._data = {} - data = [] - if fields is None: fields = [] - all_fields = [field for field in fields] - all_fields.extend(['dl', 'dredshift', 'redshift']) - if get_nearest_galaxy: - all_fields.extend(['x', 'y', 'z', 'nearest_galaxy', 'nearest_galaxy_mass']) - fields.extend(['x', 'y', 'z']) - - todo = na.arange(my_rank, len(self.light_ray_solution), my_size) - for index in todo: - segment = self.light_ray_solution[index] - mylog.info("Proc %04d: creating ray segment at z = %f." % (my_rank, segment['redshift'])) - if segment['next'] is None: - next_redshift = self.FinalRedshift - else: - next_redshift = segment['next']['redshift'] - - mylog.info("Getting segment at z = %s: %s to %s." % - (segment['redshift'], segment['start'], segment['end'])) - - if get_nearest_galaxy: - halo_list = self._get_halo_list(segment['filename'], **kwargs) - - # Load dataset for segment. - pf = lagos.EnzoStaticOutput(segment['filename']) - - # Break periodic ray into non-periodic segments. - sub_segments = periodic_ray(segment['start'], segment['end']) - - # Prepare data structure for subsegment. - sub_data = {} - sub_data['segment_redshift'] = segment['redshift'] - for field in all_fields: - sub_data[field] = na.array([], dtype=self.dtype) - - # Get data for all subsegments in segment. - for sub_segment in sub_segments: - mylog.info("Getting subsegment: %s to %s." % (list(sub_segment[0]), list(sub_segment[1]))) - sub_ray = pf.h.ray(sub_segment[0], sub_segment[1]) - sub_data['dl'] = na.concatenate([sub_data['dl'], - (sub_ray['dts'] * vector_length(sub_segment[0], sub_segment[1]))]) - for field in fields: - sub_data[field] = na.concatenate([sub_data[field], (sub_ray[field])]) - - sub_ray.clear_data() - del sub_ray - - # Get redshift for each lixel. Assume linear relation between l and z. - sub_data['dredshift'] = (segment['redshift'] - next_redshift) * \ - (sub_data['dl'] / vector_length(segment['start'], segment['end'])) - sub_data['redshift'] = segment['redshift'] - sub_data['dredshift'].cumsum() + sub_data['dredshift'] - - # Calculate distance to nearest object on halo list for each lixel. - if get_nearest_galaxy: - sub_data['nearest_galaxy'], sub_data['nearest_galaxy_mass'] = \ - self._get_nearest_galaxy_distance(sub_data, halo_list) - sub_data['nearest_galaxy'] *= pf.units['mpccm'] - - # Remove empty lixels. - sub_dl_nonzero = sub_data['dl'].nonzero() - for field in all_fields: - sub_data[field] = sub_data[field][sub_dl_nonzero] - del sub_dl_nonzero - - # Convert dl to Mpc comoving. - sub_data['dl'] *= pf.units['cm'] - - # Add segment to list. - data.append(sub_data) - - pf.h.clear_all_data() - del pf - - MPI.COMM_WORLD.Barrier() - if my_rank == 0: - for proc in range(1, my_size): - buf = MPI.COMM_WORLD.recv(source=proc, tag=0) - data += buf - else: - MPI.COMM_WORLD.send(data, dest=0, tag=0) - del data - MPI.COMM_WORLD.Barrier() - - if my_rank == 0: - data.sort(key=lambda a:a['segment_redshift'], reverse=True) - data = self._flatten_ray_data(data, exceptions=['segment_redshift']) - - if data_filename is not None: - self._write_light_ray(data_filename, data) - - self._data = data - return data - - def _flatten_ray_data(self, data, exceptions=None): - "Flatten the list of dicts into one dict." - - if exceptions is None: exceptions = [] - new_data = {} - for datum in data: - for field in [field for field in datum.keys() - if field not in exceptions]: - if new_data.has_key(field): - new_data[field] = na.concatenate([new_data[field], datum[field]]) - else: - new_data[field] = na.copy(datum[field]) - - return new_data - - def _get_halo_list(self, dataset, halo_profiler_kwargs=None, halo_profiler_actions=None, halo_list='all'): - "Load a list of halos for the dataset." - - if halo_profiler_kwargs is None: halo_profiler_kwargs = {} - if halo_profiler_actions is None: halo_profiler_actions = [] - - hp = HP.HaloProfiler(dataset, **halo_profiler_kwargs) - for action in halo_profiler_actions: - if not action.has_key('args'): action['args'] = () - if not action.has_key('kwargs'): action['kwargs'] = {} - action['function'](hp, *action['args'], **action['kwargs']) - - if halo_list == 'all': - return_list = copy.deepcopy(hp.all_halos) - elif halo_list == 'filtered': - return_list = copy.deepcopy(hp.filtered_halos) - else: - mylog.error("Keyword, halo_list, must be either 'all' or 'filtered'.") - return_list = None - - del hp - return return_list - - def _get_nearest_galaxy_distance(self, data, halo_list): - """ - Calculate distance to nearest object in halo list for each lixel in data. - Return list of distances and masses of nearest objects. - """ - - # Create position array from halo list. - halo_centers = na.array(map(lambda halo: halo['center'], halo_list)) - halo_mass = na.array(map(lambda halo: halo['TotalMassMsun'], halo_list)) - - nearest_distance = na.zeros(data['x'].shape) - nearest_mass = na.zeros(data['x'].shape) - for index in xrange(nearest_distance.size): - nearest = na.argmin(periodic_distance(na.array([data['x'][index], data['y'][index], - data['z'][index]]), halo_centers)) - nearest_distance[index] = periodic_distance(na.array([data['x'][index], data['y'][index], - data['z'][index]]), halo_centers[nearest]) - nearest_mass[index] = halo_mass[nearest] - - return (nearest_distance, nearest_mass) - - def _write_light_ray(self, filename, data): - "Write light ray data to hdf5 file." - - mylog.info("Saving light ray data to %s." % filename) - output = h5py.File(filename, 'w') - for field in data.keys(): - output.create_dataset(field, data=data[field], dtype=self.dtype) - output.close() - - def _write_light_ray_solution(self, filename, extra_info=None): - "Write light ray solution to a file." - - if my_rank != 0: return - - mylog.info("Writing light ray solution to %s." % filename) - f = open(filename, 'w') - if extra_info is not None: - for par, val in extra_info.items(): - f.write("%s = %s\n" % (par, val)) - f.write("\nSegment Redshift dl/box Start x y z End x y z Dataset\n") - for q, segment in enumerate(self.light_ray_solution): - f.write("%04d %.6f %.6f % .10f % .10f % .10f % .10f % .10f % .10f %s\n" % \ - (q, segment['redshift'], segment['TraversalBoxFraction'], - segment['start'][0], segment['start'][1], segment['start'][2], - segment['end'][0], segment['end'][1], segment['end'][2], segment['filename'])) - f.close() - -def vector_length(start, end): - "Calculate vector length." - - return na.sqrt(na.power((end - start), 2).sum()) - -def periodic_distance(coord1, coord2): - "Calculate length of shortest vector between to points in periodic domain." - dif = coord1 - coord2 - - dim = na.ones(coord1.shape,dtype=int) - def periodic_bind(num): - pos = na.abs(num % dim) - neg = na.abs(num % -dim) - return na.min([pos,neg],axis=0) - - dif = periodic_bind(dif) - return na.sqrt((dif * dif).sum(axis=-1)) - -def periodic_ray(start, end, left=None, right=None): - "Break up periodic ray into non-periodic segments." - - if left is None: - left = na.zeros(start.shape) - if right is None: - right = na.ones(start.shape) - dim = right - left - - vector = end - start - wall = na.zeros(start.shape) - close = na.zeros(start.shape, dtype=object) - - left_bound = vector < 0 - right_bound = vector > 0 - no_bound = vector == 0.0 - bound = vector != 0.0 - - wall[left_bound] = left[left_bound] - close[left_bound] = na.max - wall[right_bound] = right[right_bound] - close[right_bound] = na.min - wall[no_bound] = na.inf - close[no_bound] = na.min - - segments = [] - this_start = na.copy(start) - this_end = na.copy(end) - t = 0.0 - tolerance = 1e-6 - - while t < 1.0 - tolerance: - nearest = na.array([close[q]([this_end[q], wall[q]]) for q in range(start.size)]) - dt = ((nearest - this_start) / vector)[bound].min() - now = this_start + vector * dt - segments.append([na.copy(this_start), na.copy(now)]) - this_start = na.copy(now) - hit_left = (this_start <= left) & (vector < 0) - if (hit_left).any(): - this_start[hit_left] += dim[hit_left] - this_end[hit_left] += dim[hit_left] - hit_right = (this_start >= right) & (vector > 0) - if (hit_right).any(): - this_start[hit_right] -= dim[hit_right] - this_end[hit_right] -= dim[hit_right] - t += dt - - return segments diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/lightcone/Common_nVolume.py --- a/yt/extensions/lightcone/Common_nVolume.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -""" -Function to calculate volume in common between two n-cubes, with optional -periodic boundary conditions. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -import numpy as na - -def commonNVolume(nCube1,nCube2,periodic=None): - "Return the n-volume in common between the two n-cubes." - - # Check for proper args. - if ((len(na.shape(nCube1)) != 2) or - (na.shape(nCube1)[1] != 2) or - (na.shape(nCube1) != na.shape(nCube2))): - print "Arguments must be 2 (n,2) numpy array." - return 0 - - if ((periodic is not None) and - (na.shape(nCube1) != na.shape(periodic))): - print "periodic argument must be (n,2) numpy array." - return 0 - - nCommon = 1.0 - for q in range(na.shape(nCube1)[0]): - if (periodic is None): - nCommon *= commonSegment(nCube1[q],nCube2[q]) - else: - nCommon *= commonSegment(nCube1[q],nCube2[q],periodic=periodic[q]) - - return nCommon - -def commonSegment(seg1,seg2,periodic=None): - "Return the length of the common segment." - - # Check for proper args. - if ((len(seg1) != 2) or (len(seg2) != 2)): - print "Arguments must be arrays of size 2." - return 0 - - # If not periodic, then this is very easy. - if periodic is None: - seg1.sort() - len1 = seg1[1] - seg1[0] - seg2.sort() - len2 = seg2[1] - seg2[0] - - common = 0.0 - - add = seg1[1] - seg2[0] - if ((add > 0) and (add <= max(len1,len2))): - common += add - add = seg2[1] - seg1[0] - if ((add > 0) and (add <= max(len1,len2))): - common += add - common = min(common,len1,len2) - return common - - # If periodic, it's a little more complicated. - else: - if len(periodic) != 2: - print "periodic array must be of size 2." - return 0 - - seg1.sort() - flen1 = seg1[1] - seg1[0] - len1 = flen1 - int(flen1) - seg2.sort() - flen2 = seg2[1] - seg2[0] - len2 = flen2 - int(flen2) - - periodic.sort() - scale = periodic[1] - periodic[0] - - if (abs(int(flen1)-int(flen2)) >= scale): - return min(flen1,flen2) - - # Adjust for periodicity - seg1[0] = na.mod(seg1[0],scale) + periodic[0] - seg1[1] = seg1[0] + len1 - if (seg1[1] > periodic[1]): seg1[1] -= scale - seg2[0] = na.mod(seg2[0],scale) + periodic[0] - seg2[1] = seg2[0] + len2 - if (seg2[1] > periodic[1]): seg2[1] -= scale - - # create list of non-periodic segments - pseg1 = [] - if (seg1[0] >= seg1[1]): - pseg1.append([seg1[0],periodic[1]]) - pseg1.append([periodic[0],seg1[1]]) - else: - pseg1.append(seg1) - pseg2 = [] - if (seg2[0] >= seg2[1]): - pseg2.append([seg2[0],periodic[1]]) - pseg2.append([periodic[0],seg2[1]]) - else: - pseg2.append(seg2) - - # Add up common segments. - common = min(int(flen1),int(flen2)) - - for subseg1 in pseg1: - for subseg2 in pseg2: - common += commonSegment(subseg1,subseg2) - - return common diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/lightcone/HaloMask.py --- a/yt/extensions/lightcone/HaloMask.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,319 +0,0 @@ -""" -Light cone halo mask functions. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from yt.extensions.halo_profiler import * -from yt.logger import lagosLogger as mylog -from yt.config import ytcfg -import yt.lagos as lagos -import copy -import numpy as na -import h5py - -def light_cone_halo_mask(lightCone, cube_file=None, mask_file=None, **kwargs): - "Make a boolean mask to cut clusters out of light cone projections." - - pixels = int(lightCone.field_of_view_in_arcminutes * 60.0 / - lightCone.image_resolution_in_arcseconds) - - light_cone_mask = [] - - # Loop through files in light cone solution and get virial quantities. - for slice in lightCone.light_cone_solution: - halo_list = _get_halo_list(slice['filename'], **kwargs) - light_cone_mask.append(_make_slice_mask(slice, halo_list, pixels)) - - # Write out cube of masks from each slice. - if cube_file is not None and ytcfg.getint("yt", "__parallel_rank") == 0: - mylog.info("Saving halo mask cube to %s." % cube_file) - output = h5py.File(cube_file, 'a') - output.create_dataset('haloMaskCube', data=na.array(light_cone_mask)) - output.close() - - # Write out final mask. - if mask_file is not None and ytcfg.getint("yt", "__parallel_rank") == 0: - # Final mask is simply the product of the mask from each slice. - mylog.info("Saving halo mask to %s." % mask_file) - finalMask = na.ones(shape=(pixels, pixels)) - for mask in light_cone_mask: - finalMask *= mask - - output = h5py.File(mask_file, 'a') - output.create_dataset('HaloMask', data=na.array(finalMask)) - output.close() - - return light_cone_mask - -def light_cone_halo_map(lightCone, map_file='halo_map.out', **kwargs): - "Make a text list of location of halos in a light cone image with virial quantities." - - haloMap = [] - - # Loop through files in light cone solution and get virial quantities. - for slice in lightCone.light_cone_solution: - halo_list = _get_halo_list(slice['filename'], **kwargs) - haloMap.extend(_make_slice_halo_map(slice, halo_list)) - - # Write out file. - if ytcfg.getint("yt", "__parallel_rank") == 0: - mylog.info("Saving halo map to %s." % map_file) - f = open(map_file, 'w') - f.write("#z x y M [Msun] R [Mpc] R [image]\n") - for halo in haloMap: - f.write("%7.4f %9.6f %9.6f %9.3e %9.3e %9.3e\n" % \ - (halo['redshift'], halo['x'], halo['y'], - halo['mass'], halo['radiusMpc'], halo['radiusImage'])) - f.close() - -def _get_halo_list(dataset, halo_profiler_kwargs=None, halo_profiler_actions=None, halo_list='all'): - "Load a list of halos for the dataset." - - if halo_profiler_kwargs is None: halo_profiler_kwargs = {} - if halo_profiler_actions is None: halo_profiler_actions = [] - - hp = HaloProfiler(dataset, **halo_profiler_kwargs) - for action in halo_profiler_actions: - if not action.has_key('args'): action['args'] = () - if not action.has_key('kwargs'): action['kwargs'] = {} - action['function'](hp, *action['args'], **action['kwargs']) - - if halo_list == 'all': - return_list = copy.deepcopy(hp.all_halos) - elif halo_list == 'filtered': - return_list = copy.deepcopy(hp.filtered_halos) - else: - mylog.error("Keyword, halo_list, must be either 'all' or 'filtered'.") - return_list = None - - del hp - return return_list - -def _make_slice_mask(slice, halo_list, pixels): - "Make halo mask for one slice in light cone solution." - - # Get shifted, tiled halo list. - all_halo_x, all_halo_y, all_halo_radius, all_halo_mass = _make_slice_halo_list(slice, halo_list) - - # Make boolean mask and cut out halos. - dx = slice['WidthBoxFraction'] / pixels - x = [(q + 0.5) * dx for q in range(pixels)] - haloMask = na.ones(shape=(pixels, pixels), dtype=bool) - - # Cut out any pixel that has any part at all in the circle. - for q in range(len(all_halo_radius)): - dif_xIndex = na.array(int(all_halo_x[q]/dx) - na.array(range(pixels))) != 0 - dif_yIndex = na.array(int(all_halo_y[q]/dx) - na.array(range(pixels))) != 0 - - xDistance = (na.abs(x - all_halo_x[q]) - (0.5 * dx)) * dif_xIndex - yDistance = (na.abs(x - all_halo_y[q]) - (0.5 * dx)) * dif_yIndex - - distance = na.array([na.sqrt(w**2 + xDistance**2) for w in yDistance]) - haloMask *= (distance >= all_halo_radius[q]) - - return haloMask - -def _make_slice_halo_map(slice, halo_list): - "Make list of halos for one slice in light cone solution." - - # Get units to convert virial radii back to physical units. - dataset_object = lagos.EnzoStaticOutput(slice['filename']) - Mpc_units = dataset_object.units['mpc'] - del dataset_object - - # Get shifted, tiled halo list. - all_halo_x, all_halo_y, all_halo_radius, all_halo_mass = _make_slice_halo_list(slice, halo_list) - - # Construct list of halos - haloMap = [] - - for q in range(len(all_halo_x)): - # Give radius in both physics units and units of the image (0 to 1). - radiusMpc = all_halo_radius[q] * Mpc_units - radiusImage = all_halo_radius[q] / slice['WidthBoxFraction'] - - haloMap.append({'x':all_halo_x[q]/slice['WidthBoxFraction'], - 'y':all_halo_y[q]/slice['WidthBoxFraction'], - 'redshift':slice['redshift'], - 'radiusMpc':radiusMpc, - 'radiusImage':radiusImage, - 'mass':all_halo_mass[q]}) - - return haloMap - -def _make_slice_halo_list(slice, halo_list): - "Make shifted, tiled list of halos for halo mask and halo map." - - # Make numpy arrays for halo centers and virial radii. - halo_x = [] - halo_y = [] - halo_depth = [] - halo_radius = [] - halo_mass = [] - - # Get units to convert virial radii to code units. - dataset_object = lagos.EnzoStaticOutput(slice['filename']) - Mpc_units = dataset_object.units['mpc'] - del dataset_object - - for halo in halo_list: - if halo is not None: - center = copy.deepcopy(halo['center']) - halo_depth.append(center.pop(slice['ProjectionAxis'])) - halo_x.append(center[0]) - halo_y.append(center[1]) - halo_radius.append(halo['RadiusMpc']/Mpc_units) - halo_mass.append(halo['TotalMassMsun']) - - halo_x = na.array(halo_x) - halo_y = na.array(halo_y) - halo_depth = na.array(halo_depth) - halo_radius = na.array(halo_radius) - halo_mass = na.array(halo_mass) - - # Adjust halo centers along line of sight. - depthCenter = slice['ProjectionCenter'][slice['ProjectionAxis']] - depthLeft = depthCenter - 0.5 * slice['DepthBoxFraction'] - depthRight = depthCenter + 0.5 * slice['DepthBoxFraction'] - - # Make boolean mask to pick out centers in region along line of sight. - # Halos near edges may wrap around to other side. - add_left = (halo_depth + halo_radius) > 1 # should be box width - add_right = (halo_depth - halo_radius) < 0 - - halo_depth = na.concatenate([halo_depth, (halo_depth[add_left]-1), (halo_depth[add_right]+1)]) - halo_x = na.concatenate([halo_x, halo_x[add_left], halo_x[add_right]]) - halo_y = na.concatenate([halo_y, halo_y[add_left], halo_y[add_right]]) - halo_radius = na.concatenate([halo_radius, halo_radius[add_left], halo_radius[add_right]]) - halo_mass = na.concatenate([halo_mass, halo_mass[add_left], halo_mass[add_right]]) - - del add_left, add_right - - # Cut out the halos outside the region of interest. - if (slice['DepthBoxFraction'] < 1): - if (depthLeft < 0): - mask = ((halo_depth + halo_radius >= 0) & (halo_depth - halo_radius <= depthRight)) | \ - ((halo_depth + halo_radius >= depthLeft + 1) & (halo_depth - halo_radius <= 1)) - elif (depthRight > 1): - mask = ((halo_depth + halo_radius >= 0) & (halo_depth - halo_radius <= depthRight - 1)) | \ - ((halo_depth + halo_radius >= depthLeft) & (halo_depth - halo_radius <= 1)) - else: - mask = (halo_depth + halo_radius >= depthLeft) & (halo_depth - halo_radius <= depthRight) - - halo_x = halo_x[mask] - halo_y = halo_y[mask] - halo_radius = halo_radius[mask] - halo_mass = halo_mass[mask] - del mask - del halo_depth - - all_halo_x = na.array([]) - all_halo_y = na.array([]) - all_halo_radius = na.array([]) - all_halo_mass = na.array([]) - - # Tile halos of width box fraction is greater than one. - # Copy original into offset positions to make tiles. - for x in range(int(na.ceil(slice['WidthBoxFraction']))): - for y in range(int(na.ceil(slice['WidthBoxFraction']))): - all_halo_x = na.concatenate([all_halo_x, halo_x+x]) - all_halo_y = na.concatenate([all_halo_y, halo_y+y]) - all_halo_radius = na.concatenate([all_halo_radius, halo_radius]) - all_halo_mass = na.concatenate([all_halo_mass, halo_mass]) - - del halo_x, halo_y, halo_radius, halo_mass - - # Shift centers laterally. - offset = copy.deepcopy(slice['ProjectionCenter']) - del offset[slice['ProjectionAxis']] - - # Shift x and y positions. - all_halo_x -= offset[0] - all_halo_y -= offset[1] - - # Wrap off-edge centers back around to other side (periodic boundary conditions). - all_halo_x[all_halo_x < 0] += na.ceil(slice['WidthBoxFraction']) - all_halo_y[all_halo_y < 0] += na.ceil(slice['WidthBoxFraction']) - - # After shifting, some centers have fractional coverage on both sides of the box. - # Find those centers and make copies to be placed on the other side. - - # Centers hanging off the right edge. - add_x_right = all_halo_x + all_halo_radius > na.ceil(slice['WidthBoxFraction']) - add_x_halo_x = all_halo_x[add_x_right] - add_x_halo_x -= na.ceil(slice['WidthBoxFraction']) - add_x_halo_y = all_halo_y[add_x_right] - add_x_halo_radius = all_halo_radius[add_x_right] - add_x_halo_mass = all_halo_mass[add_x_right] - del add_x_right - - # Centers hanging off the left edge. - add_x_left = all_halo_x - all_halo_radius < 0 - add2_x_halo_x = all_halo_x[add_x_left] - add2_x_halo_x += na.ceil(slice['WidthBoxFraction']) - add2_x_halo_y = all_halo_y[add_x_left] - add2_x_halo_radius = all_halo_radius[add_x_left] - add2_x_halo_mass = all_halo_mass[add_x_left] - del add_x_left - - # Centers hanging off the top edge. - add_y_right = all_halo_y + all_halo_radius > na.ceil(slice['WidthBoxFraction']) - add_y_halo_x = all_halo_x[add_y_right] - add_y_halo_y = all_halo_y[add_y_right] - add_y_halo_y -= na.ceil(slice['WidthBoxFraction']) - add_y_halo_radius = all_halo_radius[add_y_right] - add_y_halo_mass = all_halo_mass[add_y_right] - del add_y_right - - # Centers hanging off the bottom edge. - add_y_left = all_halo_y - all_halo_radius < 0 - add2_y_halo_x = all_halo_x[add_y_left] - add2_y_halo_y = all_halo_y[add_y_left] - add2_y_halo_y += na.ceil(slice['WidthBoxFraction']) - add2_y_halo_radius = all_halo_radius[add_y_left] - add2_y_halo_mass = all_halo_mass[add_y_left] - del add_y_left - - # Add the hanging centers back to the projection data. - all_halo_x = na.concatenate([all_halo_x, add_x_halo_x, add2_x_halo_x, add_y_halo_x, add2_y_halo_x]) - all_halo_y = na.concatenate([all_halo_y, add_x_halo_y, add2_x_halo_y, add_y_halo_y, add2_y_halo_y]) - all_halo_radius = na.concatenate([all_halo_radius, add_x_halo_radius, add2_x_halo_radius, - add_y_halo_radius, add2_y_halo_radius]) - all_halo_mass = na.concatenate([all_halo_mass, add_x_halo_mass, add2_x_halo_mass, - add_y_halo_mass, add2_y_halo_mass]) - - del add_x_halo_x, add_x_halo_y, add_x_halo_radius - del add2_x_halo_x, add2_x_halo_y, add2_x_halo_radius - del add_y_halo_x, add_y_halo_y, add_y_halo_radius - del add2_y_halo_x, add2_y_halo_y, add2_y_halo_radius - - # Cut edges to proper width. - cut_mask = (all_halo_x - all_halo_radius < slice['WidthBoxFraction']) & \ - (all_halo_y - all_halo_radius < slice['WidthBoxFraction']) - all_halo_x = all_halo_x[cut_mask] - all_halo_y = all_halo_y[cut_mask] - all_halo_radius = all_halo_radius[cut_mask] - all_halo_mass = all_halo_mass[cut_mask] - del cut_mask - - return (all_halo_x, all_halo_y, all_halo_radius, all_halo_mass) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/lightcone/LightConeProjection.py --- a/yt/extensions/lightcone/LightConeProjection.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,239 +0,0 @@ -""" -Create randomly centered, tiled projections to be used in light cones. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from yt.extensions.lightcone import * -from yt.logger import lagosLogger as mylog -from yt.config import ytcfg -import yt.lagos as lagos -import yt.raven as raven -import numpy as na -import copy - -@lagos.parallel_blocking_call -def LightConeProjection(lightConeSlice, field, pixels, weight_field=None, save_image=False, name="", node=None, field_cuts=None, - add_redshift_label=False, **kwargs): - "Create a single projection to be added into the light cone stack." - - # Use some projection parameters to seed random number generator to make unique node name. - # We are just saving the projection object, so only the projection axis needs to be considered - # since the lateral shifting and tiling occurs after the projection object is made. - # Likewise, only the DepthBoxFraction needs to be considered. - - # ProjectionAxis - # ProjectionCenter[ProjectionAxis] - # DepthBoxFraction - - # Name node with user specified keyword if given with 'node' keyword. - node_name = "LightCone_%s_%d_%f_%f" % (node, lightConeSlice['ProjectionAxis'], - lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']], - lightConeSlice['DepthBoxFraction']) - - mylog.info("Making projection at z = %f from %s." % (lightConeSlice['redshift'], lightConeSlice['filename'])) - - region_center = [0.5 * (lightConeSlice['object'].parameters['DomainRightEdge'][q] + - lightConeSlice['object'].parameters['DomainLeftEdge'][q]) \ - for q in range(lightConeSlice['object'].parameters['TopGridRank'])] - - # Make the plot collection and put it in the slice so we can delete it cleanly in the same scope - # as where the frb will be deleted. - lightConeSlice['pc'] = raven.PlotCollection(lightConeSlice['object'], center=region_center) - - # 1. The Depth Problem - # Use coordinate field cut in line of sight to cut projection to proper depth. - if field_cuts is None: - these_field_cuts = [] - else: - these_field_cuts = copy.deepcopy(field_cuts) - - if (lightConeSlice['DepthBoxFraction'] < 1): - axis = ('x', 'y', 'z')[lightConeSlice['ProjectionAxis']] - depthLeft = lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']] - 0.5 * lightConeSlice['DepthBoxFraction'] - depthRight = lightConeSlice['ProjectionCenter'][lightConeSlice['ProjectionAxis']] + 0.5 * lightConeSlice['DepthBoxFraction'] - if (depthLeft < 0): - cut_mask = "((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= 0) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= %f)) | ((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= 1))" % \ - (axis, axis, axis, axis, depthRight, axis, axis, (depthLeft+1), axis, axis) - elif (depthRight > 1): - cut_mask = "((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= 0) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= %f)) | ((grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"d%s\"] <= 1))" % \ - (axis, axis, axis, axis, (depthRight-1), axis, axis, depthLeft, axis, axis) - else: - cut_mask = "(grid[\"%s\"] + 0.5*grid[\"d%s\"] >= %f) & (grid[\"%s\"] - 0.5*grid[\"%s\"] <= %f)" % (axis, axis, depthLeft, axis, axis, depthRight) - - these_field_cuts.append(cut_mask) - - # Make projection. - lightConeSlice['pc'].add_projection(field, lightConeSlice['ProjectionAxis'], weight_field=weight_field, field_cuts=these_field_cuts, - node_name=node_name, **kwargs) - - # If parallel: all the processes have the whole projection object, but we only need to do the tiling, shifting, and cutting once. - if ytcfg.getint("yt", "__parallel_rank") == 0: - - # 2. The Tile Problem - # Tile projection to specified width. - - # Original projection data. - original_px = copy.deepcopy(lightConeSlice['pc'].plots[0].data['px']) - original_py = copy.deepcopy(lightConeSlice['pc'].plots[0].data['py']) - original_pdx = copy.deepcopy(lightConeSlice['pc'].plots[0].data['pdx']) - original_pdy = copy.deepcopy(lightConeSlice['pc'].plots[0].data['pdy']) - original_field = copy.deepcopy(lightConeSlice['pc'].plots[0].data[field]) - original_weight_field = copy.deepcopy(lightConeSlice['pc'].plots[0].data['weight_field']) - - # Copy original into offset positions to make tiles. - for x in range(int(na.ceil(lightConeSlice['WidthBoxFraction']))): - for y in range(int(na.ceil(lightConeSlice['WidthBoxFraction']))): - if ((x + y) > 0): - lightConeSlice['pc'].plots[0].data['px'] = na.concatenate([lightConeSlice['pc'].plots[0].data['px'], original_px+x]) - lightConeSlice['pc'].plots[0].data['py'] = na.concatenate([lightConeSlice['pc'].plots[0].data['py'], original_py+y]) - lightConeSlice['pc'].plots[0].data['pdx'] = na.concatenate([lightConeSlice['pc'].plots[0].data['pdx'], original_pdx]) - lightConeSlice['pc'].plots[0].data['pdy'] = na.concatenate([lightConeSlice['pc'].plots[0].data['pdy'], original_pdy]) - lightConeSlice['pc'].plots[0].data[field] = na.concatenate([lightConeSlice['pc'].plots[0].data[field], original_field]) - lightConeSlice['pc'].plots[0].data['weight_field'] = na.concatenate([lightConeSlice['pc'].plots[0].data['weight_field'], original_weight_field]) - - # Delete originals. - del original_px - del original_py - del original_pdx - del original_pdy - del original_field - del original_weight_field - - # 3. The Shift Problem - # Shift projection by random x and y offsets. - - offset = copy.deepcopy(lightConeSlice['ProjectionCenter']) - # Delete depth coordinate. - del offset[lightConeSlice['ProjectionAxis']] - - # Shift x and y positions. - lightConeSlice['pc'].plots[0]['px'] -= offset[0] - lightConeSlice['pc'].plots[0]['py'] -= offset[1] - - # Wrap off-edge cells back around to other side (periodic boundary conditions). - lightConeSlice['pc'].plots[0]['px'][lightConeSlice['pc'].plots[0]['px'] < 0] += na.ceil(lightConeSlice['WidthBoxFraction']) - lightConeSlice['pc'].plots[0]['py'][lightConeSlice['pc'].plots[0]['py'] < 0] += na.ceil(lightConeSlice['WidthBoxFraction']) - - # After shifting, some cells have fractional coverage on both sides of the box. - # Find those cells and make copies to be placed on the other side. - - # Cells hanging off the right edge. - add_x_right = lightConeSlice['pc'].plots[0]['px'] + 0.5 * lightConeSlice['pc'].plots[0]['pdx'] > na.ceil(lightConeSlice['WidthBoxFraction']) - add_x_px = lightConeSlice['pc'].plots[0]['px'][add_x_right] - add_x_px -= na.ceil(lightConeSlice['WidthBoxFraction']) - add_x_py = lightConeSlice['pc'].plots[0]['py'][add_x_right] - add_x_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_x_right] - add_x_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_x_right] - add_x_field = lightConeSlice['pc'].plots[0][field][add_x_right] - add_x_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_x_right] - del add_x_right - - # Cells hanging off the left edge. - add_x_left = lightConeSlice['pc'].plots[0]['px'] - 0.5 * lightConeSlice['pc'].plots[0]['pdx'] < 0 - add2_x_px = lightConeSlice['pc'].plots[0]['px'][add_x_left] - add2_x_px += na.ceil(lightConeSlice['WidthBoxFraction']) - add2_x_py = lightConeSlice['pc'].plots[0]['py'][add_x_left] - add2_x_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_x_left] - add2_x_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_x_left] - add2_x_field = lightConeSlice['pc'].plots[0][field][add_x_left] - add2_x_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_x_left] - del add_x_left - - # Cells hanging off the top edge. - add_y_right = lightConeSlice['pc'].plots[0]['py'] + 0.5 * lightConeSlice['pc'].plots[0]['pdy'] > na.ceil(lightConeSlice['WidthBoxFraction']) - add_y_px = lightConeSlice['pc'].plots[0]['px'][add_y_right] - add_y_py = lightConeSlice['pc'].plots[0]['py'][add_y_right] - add_y_py -= na.ceil(lightConeSlice['WidthBoxFraction']) - add_y_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_y_right] - add_y_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_y_right] - add_y_field = lightConeSlice['pc'].plots[0][field][add_y_right] - add_y_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_y_right] - del add_y_right - - # Cells hanging off the bottom edge. - add_y_left = lightConeSlice['pc'].plots[0]['py'] - 0.5 * lightConeSlice['pc'].plots[0]['pdy'] < 0 - add2_y_px = lightConeSlice['pc'].plots[0]['px'][add_y_left] - add2_y_py = lightConeSlice['pc'].plots[0]['py'][add_y_left] - add2_y_py += na.ceil(lightConeSlice['WidthBoxFraction']) - add2_y_pdx = lightConeSlice['pc'].plots[0]['pdx'][add_y_left] - add2_y_pdy = lightConeSlice['pc'].plots[0]['pdy'][add_y_left] - add2_y_field = lightConeSlice['pc'].plots[0][field][add_y_left] - add2_y_weight_field = lightConeSlice['pc'].plots[0]['weight_field'][add_y_left] - del add_y_left - - # Add the hanging cells back to the projection data. - lightConeSlice['pc'].plots[0].data['px'] = na.concatenate([lightConeSlice['pc'].plots[0]['px'], add_x_px, add_y_px, add2_x_px, add2_y_px]) - lightConeSlice['pc'].plots[0].data['py'] = na.concatenate([lightConeSlice['pc'].plots[0]['py'], add_x_py, add_y_py, add2_x_py, add2_y_py]) - lightConeSlice['pc'].plots[0].data['pdx'] = na.concatenate([lightConeSlice['pc'].plots[0]['pdx'], add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx]) - lightConeSlice['pc'].plots[0].data['pdy'] = na.concatenate([lightConeSlice['pc'].plots[0]['pdy'], add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy]) - lightConeSlice['pc'].plots[0].data[field] = na.concatenate([lightConeSlice['pc'].plots[0][field], add_x_field, add_y_field, add2_x_field, add2_y_field]) - lightConeSlice['pc'].plots[0].data['weight_field'] = na.concatenate([lightConeSlice['pc'].plots[0]['weight_field'], add_x_weight_field, add_y_weight_field, - add2_x_weight_field, add2_y_weight_field]) - - # Delete original copies of hanging cells. - del add_x_px, add_y_px, add2_x_px, add2_y_px - del add_x_py, add_y_py, add2_x_py, add2_y_py - del add_x_pdx, add_y_pdx, add2_x_pdx, add2_y_pdx - del add_x_pdy, add_y_pdy, add2_x_pdy, add2_y_pdy - del add_x_field, add_y_field, add2_x_field, add2_y_field - del add_x_weight_field, add_y_weight_field, add2_x_weight_field, add2_y_weight_field - - # Tiles were made rounding up the width to the nearest integer. - # Cut off the edges to get the specified width. - # Cut in the x direction. - cut_x = lightConeSlice['pc'].plots[0].data['px'] - 0.5 * lightConeSlice['pc'].plots[0].data['pdx'] < lightConeSlice['WidthBoxFraction'] - lightConeSlice['pc'].plots[0].data['px'] = lightConeSlice['pc'].plots[0].data['px'][cut_x] - lightConeSlice['pc'].plots[0].data['py'] = lightConeSlice['pc'].plots[0].data['py'][cut_x] - lightConeSlice['pc'].plots[0].data['pdx'] = lightConeSlice['pc'].plots[0].data['pdx'][cut_x] - lightConeSlice['pc'].plots[0].data['pdy'] = lightConeSlice['pc'].plots[0].data['pdy'][cut_x] - lightConeSlice['pc'].plots[0].data[field] = lightConeSlice['pc'].plots[0].data[field][cut_x] - lightConeSlice['pc'].plots[0].data['weight_field'] = lightConeSlice['pc'].plots[0].data['weight_field'][cut_x] - del cut_x - - # Cut in the y direction. - cut_y = lightConeSlice['pc'].plots[0].data['py'] - 0.5 * lightConeSlice['pc'].plots[0].data['pdy'] < lightConeSlice['WidthBoxFraction'] - lightConeSlice['pc'].plots[0].data['px'] = lightConeSlice['pc'].plots[0].data['px'][cut_y] - lightConeSlice['pc'].plots[0].data['py'] = lightConeSlice['pc'].plots[0].data['py'][cut_y] - lightConeSlice['pc'].plots[0].data['pdx'] = lightConeSlice['pc'].plots[0].data['pdx'][cut_y] - lightConeSlice['pc'].plots[0].data['pdy'] = lightConeSlice['pc'].plots[0].data['pdy'][cut_y] - lightConeSlice['pc'].plots[0].data[field] = lightConeSlice['pc'].plots[0].data[field][cut_y] - lightConeSlice['pc'].plots[0].data['weight_field'] = lightConeSlice['pc'].plots[0].data['weight_field'][cut_y] - del cut_y - - # Save an image if requested. - if save_image: - lightConeSlice['pc'].set_xlim(0, lightConeSlice['WidthBoxFraction']) - lightConeSlice['pc'].set_ylim(0, lightConeSlice['WidthBoxFraction']) - if add_redshift_label: - lightConeSlice['pc'].plots[-1].modify['text']((0.5, 0.03), "z = %.3f" % lightConeSlice['redshift'], dict(color='black',size=50)) - lightConeSlice['pc'].save(name) - - # Create fixed resolution buffer to return back to the light cone object. - # These buffers will be stacked together to make the light cone. - frb = raven.FixedResolutionBuffer(lightConeSlice['pc'].plots[0].data, (0, lightConeSlice['WidthBoxFraction'], 0, lightConeSlice['WidthBoxFraction']), - (pixels, pixels), antialias=False) - - return frb - else: - # If running in parallel and this is not the root process, return None. - return None diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/lightcone/UniqueSolution.py --- a/yt/extensions/lightcone/UniqueSolution.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -""" -Functions to generate unique light cone solutions. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from light_cone import * -from Common_nVolume import * -from yt.logger import lagosLogger as mylog -import numpy as na -import random as rand -import copy -import sys - -def project_unique_light_cones(lightcone, seed_file, field, **kwargs): - "Make light cone projections using list of random seeds in a file." - - seedList = _read_seed_file(seed_file) - - prefix = lightcone.output_prefix - lightcone.calculate_light_cone_solution(seed=0) - lastSeed = None - - for seed in seedList: - if (seed['master'] != lastSeed): - lightcone.rerandomize_light_cone_solution(seed['master'], recycle=False) - lastSeed = seed['master'] - if (seed['recycle'] is not None): - lightcone.rerandomize_light_cone_solution(seed['recycle'], recycle=True) - - lightcone.output_prefix = "%s_%s_%s" % (prefix, seed['master'], seed['recycle']) - lightcone.project_light_cone(field, **kwargs) - -def find_unique_solutions(lightcone1, solutions=100, seed=None, max_overlap=0.25, failures=10, - recycle=True, filename='unique.dat'): - "Find a set of random seeds that will give light cones will minimal volume overlap." - - lightcone2 = copy.deepcopy(lightcone1) - lightcone1.calculate_light_cone_solution(seed=0) - lightcone2.calculate_light_cone_solution(seed=0) - - uniqueSeeds = [] - if recycle: - master = None - newRecycleSeed = None - fails = 0 - recycleFails = 0 - - maxCommon = 0.0 - - # Need to continuall save and reset the state of the random number generator - # since it is being reset by the light cone generator. - if seed is None: - state = None - else: - rand.seed(seed) - state = rand.getstate() - - failDigits = str(int(na.log10(failures))+1) - - while (len(uniqueSeeds) < solutions): - # Create new random seed. - if (recycle and master is not None): - newSeed = master - if state is not None: rand.setstate(state) - newRecycleSeed = rand.randint(1, 1e9) - state = rand.getstate() - else: - if state is not None: rand.setstate(state) - newSeed = rand.randint(1, 1e9) - state = rand.getstate() - if recycle: - master = newSeed - recycleFails = 0 - newRecycleSeed = None - - sys.stderr.write(("Unique solutions: %d, consecutive failures: %"+failDigits+"d, %"+failDigits+"d.\r") % \ - (len(uniqueSeeds), fails, recycleFails)) - - lightcone1.rerandomize_light_cone_solution(newSeed, recycle=False) - if newRecycleSeed is not None: - lightcone1.rerandomize_light_cone_solution(newRecycleSeed, recycle=True) - - # Compare with all other seeds. - testPass = True - for uniqueSeed in uniqueSeeds: - lightcone2.rerandomize_light_cone_solution(uniqueSeed['master'], recycle=False) - if uniqueSeed['recycle'] is not None: - lightcone2.rerandomize_light_cone_solution(uniqueSeed['recycle'], recycle=True) - - common = _compare_solutions(lightcone1.light_cone_solution, lightcone2.light_cone_solution) - - if (common > max_overlap): - testPass = False - break - else: - maxCommon = max(maxCommon, common) - - if testPass: - uniqueSeeds.append({'master':newSeed, 'recycle':newRecycleSeed}) - fails = 0 - recycleFails = 0 - - else: - if recycle: - recycleFails += 1 - else: - fails += 1 - - if (recycleFails >= failures): - sys.stderr.write(("Unique solutions: %d, consecutive failures: %"+failDigits+"d, %"+failDigits+"d.\n") % \ - (len(uniqueSeeds), fails, recycleFails)) - fails += 1 - mylog.info("Max recycled failures reached with master seed %d." % newSeed) - master = None - if (fails >= failures): - sys.stderr.write(("Unique solutions: %d, consecutive failures: %"+failDigits+"d, %"+failDigits+"d.\n") % \ - (len(uniqueSeeds), fails, recycleFails)) - mylog.error("Max consecutive failures reached.") - break - - mylog.info("Created %d unique solutions." % len(uniqueSeeds)) - mylog.info("Maximum common volume is %.2e." % maxCommon) - _write_seed_file(uniqueSeeds, filename) - return uniqueSeeds - -def _compare_solutions(solution1, solution2): - "Calculate common volume between two light cone solutions." - - if (len(solution1) != len(solution2)): - mylog.error("Cannot compare light cone solutions with unequal numbers of slices.") - return -1 - - commonVolume = 0.0 - totalVolume = 0.0 - - # Check that solution volumes are the same. - if((solution1[0]['DepthBoxFraction'] * solution1[0]['WidthBoxFraction']**2) != - (solution2[0]['DepthBoxFraction'] * solution2[0]['WidthBoxFraction']**2)): - mylog.error("Light cone solutions do not have equal volumes, will use the smaller one.") - - for q in range(len(solution1)): - cube1 = na.zeros(shape=(len(solution1[q]['ProjectionCenter']), 2)) - volume1 = 1.0 - for w in range(len(cube1)): - if (w == solution1[q]['ProjectionAxis']): - width = solution1[q]['DepthBoxFraction'] - else: - width = solution1[q]['WidthBoxFraction'] - volume1 *= width - cube1[w] = [solution1[q]['ProjectionCenter'][w] - 0.5 * width, - solution1[q]['ProjectionCenter'][w] + 0.5 * width] - - cube2 = na.zeros(shape=(len(solution2[q]['ProjectionCenter']), 2)) - volume2 = 1.0 - for w in range(len(cube2)): - if (w == solution2[q]['ProjectionAxis']): - width = solution2[q]['DepthBoxFraction'] - else: - width = solution2[q]['WidthBoxFraction'] - volume2 *= width - cube2[w] = [solution2[q]['ProjectionCenter'][w] - 0.5 * width, - solution2[q]['ProjectionCenter'][w] + 0.5 * width] - - totalVolume += min(volume1, volume2) - commonVolume += commonNVolume(cube1, cube2, periodic=na.array([[0, 1], [0, 1], [0, 1]])) - - return (commonVolume/totalVolume) - -def _read_seed_file(filename): - "Read list of random seeds from a file." - - mylog.info("Reading random seed list from %s." % filename) - - seedList = [] - - lines = file(filename) - for line in lines: - if line[0] != '#': - line = line.strip() - onLine = line.split(',') - if (len(onLine) == 1): - seedList.append({'master':onLine[0], 'recycle':None}) - else: - seedList.append({'master':onLine[0], 'recycle':onLine[1]}) - - return seedList - -@rootonly -def _write_seed_file(seedList, filename): - "Write list of random seeds to a file." - - mylog.info("Writing random seed list to %s." % filename) - - f = open(filename, 'w') - for seed in seedList: - if seed['recycle'] is None: - f.write("%s\n" % seed['master']) - else: - f.write("%s, %s\n" % (seed['master'], seed['recycle'])) - f.close() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/lightcone/__init__.py --- a/yt/extensions/lightcone/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -""" -Import stuff for light cone generator. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -import yt.lagos as lagos - -from LightConeProjection import * -from light_cone import * -from HaloMask import * -from UniqueSolution import * diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/lightcone/light_cone.py --- a/yt/extensions/lightcone/light_cone.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,556 +0,0 @@ -""" -LightCone class and member functions. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from yt.extensions.lightcone import * -from yt.extensions.enzo_simulation import * -from yt.logger import lagosLogger as mylog -from yt.config import ytcfg -from yt.funcs import * -from Common_nVolume import * -from HaloMask import * -import copy -import os -import numpy as na - -class LightCone(EnzoSimulation): - def __init__(self, EnzoParameterFile, initial_redshift=1.0, final_redshift=0.0, observer_redshift=0.0, - field_of_view_in_arcminutes=600.0, image_resolution_in_arcseconds=60.0, - use_minimum_datasets=True, deltaz_min=0.0, minimum_coherent_box_fraction=0.0, - output_dir='LC', output_prefix='LightCone', **kwargs): - """ - Initialize a LightCone object. - :param initial_redshift (float): the initial (highest) redshift for the light cone. Default: 1.0. - :param final_redshift (float): the final (lowest) redshift for the light cone. Default: 0.0. - :param observer_redshift (float): the redshift of the observer. Default: 0.0. - :param field_of_view_in_arcminutes (float): the field of view of the image in units of arcminutes. - Default: 600.0. - :param image_resolution_in_arcseconds (float): the size of each image pixel in units of arcseconds. - Default: 60.0. - :param use_minimum_datasets (bool): if True, the minimum number of datasets is used to connect the - initial and final redshift. If false, the light cone solution will contain as many entries - as possible within the redshift interval. Default: True. - :param deltaz_min (float): specifies the minimum :math:`\Delta z` between consecutive datasets in - the returned list. Default: 0.0. - :param minimum_coherent_box_fraction (float): used with use_minimum_datasets set to False, this - parameter specifies the fraction of the total box size to be traversed before rerandomizing - the projection axis and center. This was invented to allow light cones with thin slices to - sample coherent large scale structure, but in practice does not work so well. Try setting - this parameter to 1 and see what happens. Default: 0.0. - :param output_dir (str): the directory in which images and data files will be written. Default: 'LC'. - :param output_prefix (str): the prefix of all images and data files. Default: 'LightCone'. - """ - - self.initial_redshift = initial_redshift - self.final_redshift = final_redshift - self.observer_redshift = observer_redshift - self.field_of_view_in_arcminutes = field_of_view_in_arcminutes - self.image_resolution_in_arcseconds = image_resolution_in_arcseconds - self.use_minimum_datasets = use_minimum_datasets - self.deltaz_min = deltaz_min - self.minimum_coherent_box_fraction = minimum_coherent_box_fraction - self.output_dir = output_dir - self.output_prefix = output_prefix - - self.master_solution = [] # kept to compare with recycled solutions - self.projection_stack = [] - self.projection_weight_field_stack = [] - self.halo_mask = [] - - # Original random seed of the first solution. - self.originalRandomSeed = 0 - - # Parameters for recycling light cone solutions. - self.recycleSolution = False - self.recycleRandomSeed = 0 - - # Initialize EnzoSimulation machinery for getting dataset list. - EnzoSimulation.__init__(self, EnzoParameterFile, initial_redshift=self.initial_redshift, - final_redshift=self.final_redshift, links=True, - enzo_parameters={'CosmologyComovingBoxSize':float}, **kwargs) - - # Calculate number of pixels. - self.pixels = int(self.field_of_view_in_arcminutes * 60.0 / \ - self.image_resolution_in_arcseconds) - - if ytcfg.getint("yt", "__parallel_rank") == 0: - # Create output directory. - if (os.path.exists(self.output_dir)): - if not(os.path.isdir(self.output_dir)): - mylog.error("Output directory exists, but is not a directory: %s." % self.output_dir) - self.output_dir = './' - else: - os.mkdir(self.output_dir) - - # Get list of datasets for light cone solution. - self.light_cone_solution = self.create_cosmology_splice(minimal=self.use_minimum_datasets, - deltaz_min=self.deltaz_min) - - def calculate_light_cone_solution(self, seed=None, filename=None): - """ - Create list of projections to be added together to make the light cone. - :param seed (int): the seed for the random number generator. Any light cone solution - can be reproduced by giving the same random seed. Default: None (each solution - will be distinct). - :param filename (str): if given, a text file detailing the solution will be written out. Default: None. - """ - - # Don't use box coherence with maximum projection depths. - if self.use_minimum_datasets and \ - self.minimum_coherent_box_fraction > 0: - mylog.info("Setting minimum_coherent_box_fraction to 0 with minimal light cone.") - self.minimum_coherent_box_fraction = 0 - - # Make sure recycling flag is off. - self.recycleSolution = False - - # Get rid of old halo mask, if one was there. - self.halo_mask = [] - - if seed is not None: - self.originalRandomSeed = int(seed) - - # Calculate projection sizes, and get random projection axes and centers. - na.random.seed(self.originalRandomSeed) - - # For box coherence, keep track of effective depth travelled. - boxFractionUsed = 0.0 - - for q in range(len(self.light_cone_solution)): - del self.light_cone_solution[q]['previous'] - del self.light_cone_solution[q]['next'] - if (q == len(self.light_cone_solution) - 1): - z_next = self.final_redshift - else: - z_next = self.light_cone_solution[q+1]['redshift'] - - # Calculate fraction of box required for a depth of delta z - self.light_cone_solution[q]['DepthBoxFraction'] = self.cosmology.ComovingRadialDistance(z_next, self.light_cone_solution[q]['redshift']) * \ - self.enzoParameters['CosmologyHubbleConstantNow'] / self.enzoParameters['CosmologyComovingBoxSize'] - - # Simple error check to make sure more than 100% of box depth is never required. - if (self.light_cone_solution[q]['DepthBoxFraction'] > 1.0): - mylog.debug("Warning: box fraction required to go from z = %f to %f is %f" % - (self.light_cone_solution[q]['redshift'], z_next, - self.light_cone_solution[q]['DepthBoxFraction'])) - mylog.debug("Full box delta z is %f, but it is %f to the next data dump." % - (self.light_cone_solution[q]['deltazMax'], - self.light_cone_solution[q]['redshift']-z_next)) - - # Calculate fraction of box required for width corresponding to requested image size. - scale = self.cosmology.AngularScale_1arcsec_kpc(self.observer_redshift, self.light_cone_solution[q]['redshift']) - size = self.field_of_view_in_arcminutes * 60.0 * scale / 1000.0 - boxSizeProper = self.enzoParameters['CosmologyComovingBoxSize'] / (self.enzoParameters['CosmologyHubbleConstantNow'] * - (1.0 + self.light_cone_solution[q]['redshift'])) - self.light_cone_solution[q]['WidthBoxFraction'] = size / boxSizeProper - - # Get projection axis and center. - # If using box coherence, only get random axis and center if enough of the box has been used, - # or if boxFractionUsed will be greater than 1 after this slice. - if (q == 0) or (self.minimum_coherent_box_fraction == 0) or \ - (boxFractionUsed > self.minimum_coherent_box_fraction) or \ - (boxFractionUsed + self.light_cone_solution[q]['DepthBoxFraction'] > 1.0): - # Random axis and center. - self.light_cone_solution[q]['ProjectionAxis'] = na.random.randint(0, 3) - self.light_cone_solution[q]['ProjectionCenter'] = [na.random.random(), na.random.random(), na.random.random()] - boxFractionUsed = 0.0 - else: - # Same axis and center as previous slice, but with depth center shifted. - self.light_cone_solution[q]['ProjectionAxis'] = self.light_cone_solution[q-1]['ProjectionAxis'] - self.light_cone_solution[q]['ProjectionCenter'] = copy.deepcopy(self.light_cone_solution[q-1]['ProjectionCenter']) - self.light_cone_solution[q]['ProjectionCenter'][self.light_cone_solution[q]['ProjectionAxis']] += \ - 0.5 * (self.light_cone_solution[q]['DepthBoxFraction'] + self.light_cone_solution[q-1]['DepthBoxFraction']) - if self.light_cone_solution[q]['ProjectionCenter'][self.light_cone_solution[q]['ProjectionAxis']] >= 1.0: - self.light_cone_solution[q]['ProjectionCenter'][self.light_cone_solution[q]['ProjectionAxis']] -= 1.0 - - boxFractionUsed += self.light_cone_solution[q]['DepthBoxFraction'] - - # Store this as the master solution. - self.master_solution = [copy.deepcopy(q) for q in self.light_cone_solution] - - # Write solution to a file. - if filename is not None: - self._save_light_cone_solution(filename=filename) - - def get_halo_mask(self, mask_file=None, map_file=None, **kwargs): - """ - Gets a halo mask from a file or makes a new one. - :param mask_file (str): specify an hdf5 file to output the halo mask. - :param map_file (str): specify a text file to output the halo map - (locations in image of halos). - """ - - # Get halo map if map_file given. - if map_file is not None and not os.path.exists(map_file): - light_cone_halo_map(self, map_file=map_file, **kwargs) - - # Check if file already exists. - if mask_file is not None and os.path.exists(mask_file): - mylog.info('Reading halo mask from %s.' % mask_file) - input = h5py.File(mask_file, 'r') - self.halo_mask = input['HaloMask'].value - input.close() - - # Otherwise, make a halo mask. - else: - halo_mask_cube = light_cone_halo_mask(self, mask_file=mask_file, **kwargs) - # Collapse cube into final mask. - if ytcfg.getint("yt", "__parallel_rank") == 0: - self.halo_mask = na.ones(shape=(self.pixels, self.pixels), dtype=bool) - for mask in halo_mask_cube: - self.halo_mask *= mask - del halo_mask_cube - - def project_light_cone(self, field, weight_field=None, apply_halo_mask=False, node=None, - save_stack=True, save_slice_images=False, flatten_stack=False, photon_field=False, **kwargs): - """ - Create projections for light cone, then add them together. - :param weight_field (str): the weight field of the projection. This has the same meaning as in standard - projections. Default: None. - :param apply_halo_mask (bool): if True, a boolean mask is apply to the light cone projection. See below for a - description of halo masks. Default: False. - :param node (str): a prefix to be prepended to the node name under which the projection data is serialized. - Default: None. - :param save_stack (bool): if True, the unflatted light cone data including each individual slice is written to - an hdf5 file. Default: True. - :param save_slice_images (bool): save images for each individual projection slice. Default: False. - :param flatten_stack (bool): if True, the light cone stack is continually flattened each time a slice is added - in order to save memory. This is generally not necessary. Default: False. - :param photon_field (bool): if True, the projection data for each slice is decremented by 4 Pi R^2`, where R - is the luminosity distance between the observer and the slice redshift. Default: False. - """ - - # Clear projection stack. - self.projection_stack = [] - self.projection_weight_field_stack = [] - if (self.light_cone_solution[-1].has_key('object')): - del self.light_cone_solution[-1]['object'] - - if not(self.output_dir.endswith("/")): - self.output_dir += "/" - - for q, output in enumerate(self.light_cone_solution): - if node is None: - name = "%s%s_%04d_%04d" % (self.output_dir, self.output_prefix, - q, len(self.light_cone_solution)) - else: - name = "%s%s_%s_%04d_%04d" % (self.output_dir, self.output_prefix, - node, q, len(self.light_cone_solution)) - output['object'] = lagos.EnzoStaticOutput(output['filename']) - frb = LightConeProjection(output, field, self.pixels, weight_field=weight_field, - save_image=save_slice_images, - name=name, node=node, **kwargs) - if ytcfg.getint("yt", "__parallel_rank") == 0: - if photon_field: - # Decrement the flux by the luminosity distance. Assume field in frb is in erg/s/cm^2/Hz - co = lagos.Cosmology(HubbleConstantNow = (100.0 * self.enzoParameters['CosmologyHubbleConstantNow']), - OmegaMatterNow = self.enzoParameters['CosmologyOmegaMatterNow'], - OmegaLambdaNow = self.enzoParameters['CosmologyOmegaLambdaNow']) - dL = self.cosmology.LuminosityDistance(self.observer_redshift, output['redshift']) #in Mpc - boxSizeProper = self.enzoParameters['CosmologyComovingBoxSize'] / (self.enzoParameters['CosmologyHubbleConstantNow'] * - (1.0 + output['redshift'])) - pixelarea = (boxSizeProper/self.pixels)**2 #in proper cm^2 - factor = pixelarea/(4.0*na.pi*dL**2) - mylog.info("Distance to slice = %e" % dL) - frb[field] *= factor #in erg/s/cm^2/Hz on observer's image plane. - - if ytcfg.getint("yt", "__parallel_rank") == 0: - if weight_field is not None: - # Data come back normalized by the weight field. - # Undo that so it can be added up for the light cone. - self.projection_stack.append(frb[field]*frb['weight_field']) - self.projection_weight_field_stack.append(frb['weight_field']) - else: - self.projection_stack.append(frb[field]) - - # Delete the frb. This saves a decent amount of ram. - if (q < len(self.light_cone_solution) - 1): - del frb - - # Flatten stack to save memory. - if flatten_stack and (len(self.projection_stack) > 1): - self.projection_stack = [sum(self.projection_stack)] - if weight_field is not None: - self.projection_weight_field_stack = [sum(self.projection_weight_field_stack)] - - # Delete the plot collection now that the frb is deleted. - del output['pc'] - - # Unless this is the last slice, delete the dataset object. - # The last one will be saved to make the plot collection. - if (q < len(self.light_cone_solution) - 1): - del output['object'] - - if ytcfg.getint("yt", "__parallel_rank") == 0: - # Add up slices to make light cone projection. - if (weight_field is None): - lightConeProjection = sum(self.projection_stack) - else: - lightConeProjection = sum(self.projection_stack) / sum(self.projection_weight_field_stack) - - if node is None: - filename = "%s%s" % (self.output_dir, self.output_prefix) - else: - filename = "%s%s_%s" % (self.output_dir, self.output_prefix, node) - - # Save the last fixed resolution buffer for the plot collection, - # but replace the data with the full light cone projection data. - frb.data[field] = lightConeProjection - - # Write stack to hdf5 file. - if save_stack: - self._save_light_cone_stack(field=field, weight_field=weight_field, filename=filename) - - # Apply halo mask. - if apply_halo_mask: - if len(self.halo_mask) > 0: - mylog.info("Applying halo mask.") - frb.data[field] *= self.halo_mask - else: - mylog.error("No halo mask loaded, call get_halo_mask.") - - # Make a plot collection for the light cone projection. - center = [0.5 * (self.light_cone_solution[-1]['object'].parameters['DomainLeftEdge'][w] + - self.light_cone_solution[-1]['object'].parameters['DomainRightEdge'][w]) - for w in range(self.light_cone_solution[-1]['object'].parameters['TopGridRank'])] - pc = raven.PlotCollection(self.light_cone_solution[-1]['object'], center=center) - pc.add_fixed_resolution_plot(frb, field, **kwargs) - pc.save(filename) - - # Return the plot collection so the user can remake the plot if they want. - return pc - - def rerandomize_light_cone_solution(self, newSeed, recycle=True, filename=None): - """ - When making a projection for a light cone, only randomizations along the line of sight make any - given projection unique, since the lateral shifting and tiling is done after the projection is made. - Therefore, multiple light cones can be made from a single set of projections by introducing different - lateral random shifts and keeping all the original shifts along the line of sight. - This routine will take in a new random seed and rerandomize the parts of the light cone that do not contribute - to creating a unique projection object. Additionally, this routine is built such that if the same random - seed is given for the rerandomizing, the solution will be identical to the original. - - This routine has now been updated to be a general solution rescrambler. If the keyword recycle is set to - True, then it will recycle. Otherwise, it will create a completely new solution. - - :param recycle (bool): if True, the new solution will have the same shift in the line of sight as the original - solution. Since the projections of each slice are serialized and stored for the entire width of the - box (even if the width used is left than the total box), the projection data can be deserialized - instead of being remade from scratch. This can greatly speed up the creation of a large number of light - cone projections. Default: True. - :param filename (str): if given, a text file detailing the solution will be written out. Default: None. - """ - - # Get rid of old halo mask, if one was there. - self.halo_mask = [] - - # Clean pf objects out of light cone solution. - for slice in self.light_cone_solution: - if slice.has_key('object'): - del slice['object'] - - if recycle: - mylog.debug("Recycling solution made with %s with new seed %s." % - (self.originalRandomSeed, newSeed)) - self.recycleRandomSeed = int(newSeed) - else: - mylog.debug("Creating new solution with random seed %s." % newSeed) - self.originalRandomSeed = int(newSeed) - self.recycleRandomSeed = 0 - - self.recycleSolution = recycle - - # Keep track of fraction of volume in common between the original and recycled solution. - commonVolume = 0.0 - totalVolume = 0.0 - - # For box coherence, keep track of effective depth travelled. - boxFractionUsed = 0.0 - - # Seed random number generator with new seed. - na.random.seed(int(newSeed)) - - for q, output in enumerate(self.light_cone_solution): - # It is necessary to make the same number of calls to the random number generator - # so the original solution willbe produced if the same seed is given. - - # Get projection axis and center. - # If using box coherence, only get random axis and center if enough of the box has been used, - # or if boxFractionUsed will be greater than 1 after this slice. - if (q == 0) or (self.minimum_coherent_box_fraction == 0) or \ - (boxFractionUsed > self.minimum_coherent_box_fraction) or \ - (boxFractionUsed + self.light_cone_solution[q]['DepthBoxFraction'] > 1.0): - # Get random projection axis and center. - # If recycling, axis will get thrown away since it is used in creating a unique projection object. - newAxis = na.random.randint(0, 3) - - newCenter = [na.random.random(), na.random.random(), na.random.random()] - boxFractionUsed = 0.0 - else: - # Same axis and center as previous slice, but with depth center shifted. - newAxis = self.light_cone_solution[q-1]['ProjectionAxis'] - newCenter = copy.deepcopy(self.light_cone_solution[q-1]['ProjectionCenter']) - newCenter[newAxis] += \ - 0.5 * (self.light_cone_solution[q]['DepthBoxFraction'] + self.light_cone_solution[q-1]['DepthBoxFraction']) - if newCenter[newAxis] >= 1.0: - newCenter[newAxis] -= 1.0 - - if recycle: - output['ProjectionAxis'] = self.master_solution[q]['ProjectionAxis'] - else: - output['ProjectionAxis'] = newAxis - - boxFractionUsed += self.light_cone_solution[q]['DepthBoxFraction'] - - # Make list of rectangle corners to calculate common volume. - newCube = na.zeros(shape=(len(newCenter), 2)) - oldCube = na.zeros(shape=(len(newCenter), 2)) - for w in range(len(newCenter)): - if (w == self.master_solution[q]['ProjectionAxis']): - oldCube[w] = [self.master_solution[q]['ProjectionCenter'][w] - 0.5 * self.master_solution[q]['DepthBoxFraction'], - self.master_solution[q]['ProjectionCenter'][w] + 0.5 * self.master_solution[q]['DepthBoxFraction']] - else: - oldCube[w] = [self.master_solution[q]['ProjectionCenter'][w] - 0.5 * self.master_solution[q]['WidthBoxFraction'], - self.master_solution[q]['ProjectionCenter'][w] + 0.5 * self.master_solution[q]['WidthBoxFraction']] - - if (w == output['ProjectionAxis']): - if recycle: - newCube[w] = oldCube[w] - else: - newCube[w] = [newCenter[w] - 0.5 * self.master_solution[q]['DepthBoxFraction'], - newCenter[w] + 0.5 * self.master_solution[q]['DepthBoxFraction']] - else: - newCube[w] = [newCenter[w] - 0.5 * self.master_solution[q]['WidthBoxFraction'], - newCenter[w] + 0.5 * self.master_solution[q]['WidthBoxFraction']] - - commonVolume += commonNVolume(oldCube, newCube, periodic=na.array([[0, 1], [0, 1], [0, 1]])) - totalVolume += output['DepthBoxFraction'] * output['WidthBoxFraction']**2 - - # Replace centers for every axis except the line of sight axis. - for w in range(len(newCenter)): - if not(recycle and (w == self.light_cone_solution[q]['ProjectionAxis'])): - self.light_cone_solution[q]['ProjectionCenter'][w] = newCenter[w] - - if recycle: - mylog.debug("Fractional common volume between master and recycled solution is %.2e" % (commonVolume/totalVolume)) - else: - mylog.debug("Fraction of total volume in common with old solution is %.2e." % (commonVolume/totalVolume)) - self.master_solution = [copy.deepcopy(q) for q in self.light_cone_solution] - - # Write solution to a file. - if filename is not None: - self._save_light_cone_solution(filename=filename) - - def restore_master_solution(self): - "Reset the active light cone solution to the master solution." - self.light_cone_solution = [copy.deepcopy(q) for q in self.master_solution] - - @rootonly - def _save_light_cone_solution(self, filename="light_cone.dat"): - "Write out a text file with information on light cone solution." - - mylog.info("Saving light cone solution to %s." % filename) - - f = open(filename, 'w') - if self.recycleSolution: - f.write("Recycled Solution\n") - f.write("OriginalRandomSeed = %s\n" % self.originalRandomSeed) - f.write("RecycleRandomSeed = %s\n" % self.recycleRandomSeed) - else: - f.write("Original Solution\n") - f.write("OriginalRandomSeed = %s\n" % self.originalRandomSeed) - f.write("EnzoParameterFile = %s\n" % self.EnzoParameterFile) - f.write("\n") - for q, output in enumerate(self.light_cone_solution): - f.write("Proj %04d, %s, z = %f, depth/box = %f, width/box = %f, axis = %d, center = %f, %f, %f\n" % - (q, output['filename'], output['redshift'], output['DepthBoxFraction'], output['WidthBoxFraction'], - output['ProjectionAxis'], output['ProjectionCenter'][0], output['ProjectionCenter'][1], output['ProjectionCenter'][2])) - f.close() - - def _save_light_cone_stack(self, field=None, weight_field=None, filename=None, over_write=True): - "Save the light cone projection stack as a 3d array in and hdf5 file." - - # Make list of redshifts to include as a dataset attribute. - redshiftList = na.array([slice['redshift'] for slice in self.light_cone_solution]) - - field_node = "%s_%s" % (field, weight_field) - weight_field_node = "weight_field_%s" % weight_field - - import h5py - if (filename is None): - filename = "%s/%s_data" % (self.output_dir, self.output_prefix) - if not(filename.endswith('.h5')): - filename += ".h5" - - if (len(self.projection_stack) == 0): - mylog.debug("save_light_cone_stack: no projection data loaded.") - return - - mylog.info("Writing light cone data to %s." % filename) - - output = h5py.File(filename, "a") - - node_exists = field_node in output.listnames() - - if node_exists: - if over_write: - mylog.info("Dataset, %s, already exists, overwriting." % field_node) - write_data = True - del output[field_node] - else: - mylog.info("Dataset, %s, already exists in %s, not saving." % (field_node, filename)) - write_data = False - else: - write_data = True - - if write_data: - mylog.info("Saving %s to %s." % (field_node, filename)) - self.projection_stack = na.array(self.projection_stack) - field_dataset = output.create_dataset(field_node, data=self.projection_stack) - field_dataset.attrs['redshifts'] = redshiftList - field_dataset.attrs['observer_redshift'] = na.float(self.observer_redshift) - field_dataset.attrs['field_of_view_in_arcminutes'] = na.float(self.field_of_view_in_arcminutes) - field_dataset.attrs['image_resolution_in_arcseconds'] = na.float(self.image_resolution_in_arcseconds) - - if (len(self.projection_weight_field_stack) > 0): - if node_exists: - if over_write: - mylog.info("Dataset, %s, already exists, overwriting." % weight_field_node) - del output[field_node] - else: - mylog.info("Dataset, %s, already exists in %s, not saving." % (weight_field_node, filename)) - write_data = False - else: - write_data = True - - if write_data: - mylog.info("Saving %s to %s." % (weight_field_node, filename)) - self.projection_weight_field_stack = na.array(self.projection_weight_field_stack) - weight_field_dataset = output.create_dataset(weight_field_node, data=self.projection_weight_field_stack) - weight_field_dataset.attrs['redshifts'] = redshiftList - weight_field_dataset.attrs['observer_redshift'] = na.float(self.observer_redshift) - weight_field_dataset.attrs['field_of_view_in_arcminutes'] = na.float(self.field_of_view_in_arcminutes) - weight_field_dataset.attrs['image_resolution_in_arcseconds'] = na.float(self.image_resolution_in_arcseconds) - - output.close() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/merger_tree.py --- a/yt/extensions/merger_tree.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1158 +0,0 @@ -""" -MergerTree class and member functions. - -Author: Stephen Skory -Affiliation: CASS/UC San Diego, CA -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2010 Stephen Skory. 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 . -""" - -import yt.lagos as lagos -from yt.lagos.HaloFinding import HaloFinder -from yt.logger import lagosLogger as mylog -import yt.extensions.halo_profiler as HP -try: - from yt.extensions.kdtree import * -except ImportError: - mylog.debug("The Fortran kD-Tree did not import correctly.") - -import numpy as na -import os, glob, md5, time, gc, sys -import h5py -import types -import sqlite3 as sql -from collections import defaultdict - -column_types = { -"GlobalHaloID":"INTEGER", -"SnapCurrentTimeIdentifier":"INTEGER", -"SnapZ":"FLOAT", -"SnapHaloID":"INTEGER", -"HaloMass":"FLOAT", -"NumPart":"INTEGER", -"CenMassX":"FLOAT", -"CenMassY":"FLOAT", -"CenMassZ":"FLOAT", -"BulkVelX":"FLOAT", -"BulkVelY":"FLOAT", -"BulkVelZ":"FLOAT", -"MaxRad":"FLOAT", -"ChildHaloID0":"INTEGER", -"ChildHaloFrac0":"FLOAT", -"ChildHaloID1":"INTEGER", -"ChildHaloFrac1":"FLOAT", -"ChildHaloID2":"INTEGER", -"ChildHaloFrac2":"FLOAT", -"ChildHaloID3":"INTEGER", -"ChildHaloFrac3":"FLOAT", -"ChildHaloID4":"INTEGER", -"ChildHaloFrac4":"FLOAT"} - -# In order. -columns = ["GlobalHaloID", "SnapCurrentTimeIdentifier", "SnapZ", -"SnapHaloID", "HaloMass", "NumPart", "CenMassX", "CenMassY", -"CenMassZ", "BulkVelX", "BulkVelY", "BulkVelZ", "MaxRad", -"ChildHaloID0", "ChildHaloFrac0", -"ChildHaloID1", "ChildHaloFrac1", -"ChildHaloID2", "ChildHaloFrac2", -"ChildHaloID3", "ChildHaloFrac3", -"ChildHaloID4", "ChildHaloFrac4"] - -class DatabaseFunctions(object): - # Common database functions so it doesn't have to be repeated. - def _open_database(self): - # open the database. Check to make sure the database file exists. - if not os.path.exists(self.database): - mylog.error("The database file %s cannot be found. Exiting." % \ - self.database) - return False - self.conn = sql.connect(self.database) - self.cursor = self.conn.cursor() - return True - - def _close_database(self): - # close the database cleanly. - self.cursor.close() - self.conn.close() - -class MergerTree(DatabaseFunctions, lagos.ParallelAnalysisInterface): - def __init__(self, restart_files=[], database='halos.db', - halo_finder_function=HaloFinder, halo_finder_threshold=80.0, - FOF_link_length=0.2, dm_only=False, refresh=False, sleep=1, - index=True): - r"""Build a merger tree of halos over a time-ordered set of snapshots. - This will run a halo finder to find the halos first if it hasn't already - been done. The output is a SQLite database file, which may need to - be stored on a different disk than the data snapshots. See the full - documentation for details. - - Parameters - --------- - restart_files : List of strings - A list containing the paths to the forward time-ordered set of - data snapshots. - database : String - Name of SQLite database file. Default = "halos.db". - halo_finder_function : HaloFinder name - The name of the halo finder to use if halo finding is run by - the merger tree. Options: HaloFinder, FOFHaloFinder, parallelHF. - Note that this is not a string, so no quotes. Default = HaloFinder. - halo_finder_threshold : Float - If using HaloFinder or parallelHF, the value of the density threshold - used when halo finding. Default = 80.0. - FOF_link_length : Float - If using FOFHaloFinder, the linking length between particles. - Default = 0.2. - dm_only : Boolean - When halo finding, whether to restrict to only dark matter particles. - Default = False. - refresh : Boolean - True forces the halo finder to run even if the halo data has been - detected on disk. Default = False. - sleep : Float - Due to the nature of the SQLite database and network file systems, - it is crucial that all tasks see the database in the same state at - all times. This parameter specifies how long in seconds the merger - tree waits between checks to ensure the database is synched across - all tasks. Default = 1. - index : Boolean - SQLite databases can have added to them an index which greatly - speeds up future queries of the database, - at the cost of doubling the disk space used by the file. - Default = True. - - Examples: - >>> rf = ['/scratch/user/sim1/DD0000/data0000', - ... '/scratch/user/sim1/DD0001/data0001', - ... '/scratch/user/sim1/DD0002/data0002'] - >>> MergerTree(rf, database = '/home/user/sim1-halos.db', - ... halo_finder_function=parallelHF) - """ - self.restart_files = restart_files # list of enzo restart files - self.with_halos = na.ones(len(restart_files), dtype='bool') - self.database = database # the sqlite database of haloes. - self.halo_finder_function = halo_finder_function # which halo finder to use - self.halo_finder_threshold = halo_finder_threshold # overdensity threshold - self.FOF_link_length= FOF_link_length # For FOF - self.dm_only = dm_only - self.refresh = refresh - self.sleep = sleep # How long to wait between db sync checks. - if self.sleep <= 0.: - self.sleep = 5 - # MPI stuff - self.mine = self._mpi_get_rank() - if self.mine is None: - self.mine = 0 - self.size = self._mpi_get_size() - if self.size is None: - self.size = 1 - # Get to work. - if self.refresh and self.mine == 0: - try: - os.unlink(self.database) - except: - pass - self._barrier() - self._open_create_database() - self._create_halo_table() - self._run_halo_finder_add_to_db() - # Find the h5 file names for all the halos. - for snap in self.restart_files: - self._build_h5_refs(snap) - # Loop over the pairs of snapshots to locate likely neighbors, and - # then use those likely neighbors to compute fractional contributions. - last = None - self.write_values = [] - self.write_values_dict = defaultdict(dict) - for snap, pair in enumerate(zip(self.restart_files[:-1], self.restart_files[1:])): - if not self.with_halos[snap] or not self.with_halos[snap+1]: - continue - self._find_likely_children(pair[0], pair[1]) - # last is the data for the parent dataset, which can be supplied - # as the child from the previous round for all but the first loop. - last = self._compute_child_fraction(pair[0], pair[1], last) - del last - # Now update the database with all the writes. - mylog.info("Updating database with parent-child relationships.") - self._copy_and_update_db() - self._barrier() - mylog.info("Done!") - - def _read_halo_lists(self): - self.halo_lists = [] - for i,file in enumerate(self.halo_files): - hp = HP.HaloProfiler(self.restart_files[i], halo_list_file=file) - self.halo_lists.append(hp.all_halos) - - def _run_halo_finder_add_to_db(self): - for cycle, file in enumerate(self.restart_files): - gc.collect() - pf = lagos.EnzoStaticOutput(file) - # If the halos are already found, skip this data step, unless - # refresh is True. - dir = os.path.dirname(file) - if os.path.exists(os.path.join(dir, 'MergerHalos.out')) and \ - os.path.exists(os.path.join(dir, 'MergerHalos.txt')) and \ - glob.glob(os.path.join(dir, 'MergerHalos*h5')) is not [] and \ - not self.refresh: - pass - else: - # Run the halo finder. - if self.halo_finder_function == yt.lagos.HaloFinding.FOFHaloFinder: - halos = self.halo_finder_function(pf, - link=self.FOF_link_length, dm_only=self.dm_only) - else: - halos = self.halo_finder_function(pf, - threshold=self.halo_finder_threshold, dm_only=self.dm_only) - halos.write_out(os.path.join(dir, 'MergerHalos.out')) - halos.write_particle_lists(os.path.join(dir, 'MergerHalos')) - halos.write_particle_lists_txt(os.path.join(dir, 'MergerHalos')) - if len(halos) == 0: - mylog.info("Dataset %s has no halos." % file) - self.with_halos[cycle] = False - continue - del halos - # Now add halo data to the db if it isn't already there by - # checking the first halo. - currt = pf['CurrentTimeIdentifier'] - line = "SELECT GlobalHaloID from Halos where SnapHaloID=0\ - and SnapCurrentTimeIdentifier=%d;" % currt - self.cursor.execute(line) - result = self.cursor.fetchone() - if result != None: - continue - red = pf['CosmologyCurrentRedshift'] - # Read the halos off the disk using the Halo Profiler tools. - hp = HP.HaloProfiler(file, halo_list_file='MergerHalos.out', - halo_list_format={'id':0, 'mass':1, 'numpart':2, 'center':[7, 8, 9], 'velocity':[10, 11, 12], 'r_max':13}) - if len(hp.all_halos) == 0: - mylog.info("Dataset %s has no halos." % file) - self.with_halos[cycle] = False - continue - mylog.info("Entering halos into database for z=%f" % red) - if self.mine == 0: - for ID,halo in enumerate(hp.all_halos): - numpart = int(halo['numpart']) - values = (None, currt, red, ID, halo['mass'], numpart, - halo['center'][0], halo['center'][1], halo['center'][2], - halo['velocity'][0], halo['velocity'][1], halo['velocity'][2], - halo['r_max'] / pf['mpc'], - -1,0.,-1,0.,-1,0.,-1,0.,-1,0.) - # 23 question marks for 23 data columns. - line = '' - for i in range(23): - line += '?,' - # Pull off the last comma. - line = 'INSERT into Halos VALUES (' + line[:-1] + ')' - self.cursor.execute(line, values) - self.conn.commit() - self._barrier() - del hp - - def _open_create_database(self): - # open the database. This creates the database file on disk if it - # doesn't already exist. Open it first on root, and then on the others. - if self.mine == 0: - self.conn = sql.connect(self.database) - self._barrier() - self._ensure_db_sync() - if self.mine != 0: - self.conn = sql.connect(self.database) - self.cursor = self.conn.cursor() - - def _ensure_db_sync(self): - # If the database becomes out of sync for each task, ostensibly due to - # parallel file system funniness, things will go bad very quickly. - # Therefore, just to be very, very careful, we will ensure that the - # md5 hash of the file is identical across all tasks before proceeding. - self._barrier() - for i in range(5): - try: - file = open(self.database) - except IOError: - # This is to give a little bit of time for the database creation - # to replicate across the file system. - time.sleep(self.sleep) - file = open(self.database) - hash = md5.md5(file.read()).hexdigest() - file.close() - ignore, hashes = self._mpi_info_dict(hash) - hashes = set(hashes.values()) - if len(hashes) == 1: - break - else: - # Wait a little bit for the file system to (hopefully) sync up. - time.sleep(self.sleep) - if len(hashes) == 1: - return - else: - mylog.error("The file system is not properly synchronizing the database.") - raise RunTimeError("Fatal error. Exiting.") - - def _create_halo_table(self): - if self.mine == 0: - # Handle the error if it already exists. - try: - # Create the table that will store the halo data. - line = "CREATE TABLE Halos (GlobalHaloID INTEGER PRIMARY KEY,\ - SnapCurrentTimeIdentifier INTEGER, SnapZ FLOAT, SnapHaloID INTEGER, \ - HaloMass FLOAT,\ - NumPart INTEGER, CenMassX FLOAT, CenMassY FLOAT,\ - CenMassZ FLOAT, BulkVelX FLOAT, BulkVelY FLOAT, BulkVelZ FLOAT,\ - MaxRad FLOAT,\ - ChildHaloID0 INTEGER, ChildHaloFrac0 FLOAT, \ - ChildHaloID1 INTEGER, ChildHaloFrac1 FLOAT, \ - ChildHaloID2 INTEGER, ChildHaloFrac2 FLOAT, \ - ChildHaloID3 INTEGER, ChildHaloFrac3 FLOAT, \ - ChildHaloID4 INTEGER, ChildHaloFrac4 FLOAT);" - self.cursor.execute(line) - self.conn.commit() - except sql.OperationalError: - pass - self._barrier() - - def _find_likely_children(self, parentfile, childfile): - # For each halo in the parent list, identify likely children in the - # list of children. - - # First, read in the locations of the child halos. - child_pf = lagos.EnzoStaticOutput(childfile) - child_t = child_pf['CurrentTimeIdentifier'] - line = "SELECT SnapHaloID, CenMassX, CenMassY, CenMassZ FROM \ - Halos WHERE SnapCurrentTimeIdentifier = %d" % child_t - self.cursor.execute(line) - - mylog.info("Finding likely parents for z=%1.5f child halos." % \ - child_pf["CosmologyCurrentRedshift"]) - - # Build the kdtree for the children by looping over the fetched rows. - child_points = [] - for row in self.cursor: - child_points.append([row[1], row[2], row[3]]) - # Turn it into fortran. - child_points = na.array(child_points) - fKD.pos = na.asfortranarray(child_points.T) - fKD.qv = na.empty(3, dtype='float64') - fKD.dist = na.empty(5, dtype='float64') - fKD.tags = na.empty(5, dtype='int64') - fKD.nn = 5 - fKD.sort = True - fKD.rearrange = True - create_tree(0) - - # Find the parent points from the database. - parent_pf = lagos.EnzoStaticOutput(parentfile) - parent_t = parent_pf['CurrentTimeIdentifier'] - line = "SELECT SnapHaloID, CenMassX, CenMassY, CenMassZ FROM \ - Halos WHERE SnapCurrentTimeIdentifier = %d" % parent_t - self.cursor.execute(line) - - # Loop over the returned rows, and find the likely neighbors for the - # parents. - candidates = {} - for row in self.cursor: - fKD.qv = na.array([row[1], row[2], row[3]]) - find_nn_nearest_neighbors() - NNtags = fKD.tags[:] - 1 - nIDs = [] - for n in NNtags: - nIDs.append(n) - if len(nIDs) < 5: - # We need to fill in fake halos if there aren't enough halos, - # which can happen at high redshifts. - while len(nIDs) < 5: - nIDs.append(-1) - candidates[row[0]] = nIDs - - del fKD.pos, fKD.tags, fKD.dist - free_tree(0) # Frees the kdtree object. - - self.candidates = candidates - - # This stores the masses contributed to each child candidate. - self.child_mass_arr = na.zeros(len(candidates)*5, dtype='float64') - # Records where to put the entries in the above array. - self.child_mass_loc = defaultdict(dict) - for i,halo in enumerate(sorted(candidates)): - for j, child in enumerate(candidates[halo]): - self.child_mass_loc[halo][child] = i*5 + j - - def _build_h5_refs(self, filename): - # For this snapshot, add lists of file names that contain the - # particle info for each halo. - if not hasattr(self, 'h5files'): - self.h5files = defaultdict(dict) - if not hasattr(self, 'names'): - self.names = defaultdict(set) - file_pf = lagos.EnzoStaticOutput(filename) - currt = file_pf['CurrentTimeIdentifier'] - dir = os.path.dirname(filename) - h5txt = os.path.join(dir, 'MergerHalos.txt') - lines = file(h5txt) - names = set([]) - for i,line in enumerate(lines): - # Get rid of the carriage returns and turn it into a list. - line = line.strip().split() - self.h5files[currt][i] = line[1:] - names.update(line[1:]) - self.names[currt].update(line[1:]) - lines.close() - - def _compute_child_fraction(self, parentfile, childfile, last): - # Given a parent and child snapshot, and a list of child candidates, - # compute what fraction of the parent halo goes to each of the children. - - parent_pf = lagos.EnzoStaticOutput(parentfile) - child_pf = lagos.EnzoStaticOutput(childfile) - parent_currt = parent_pf['CurrentTimeIdentifier'] - child_currt = child_pf['CurrentTimeIdentifier'] - - mylog.info("Computing fractional contribututions of particles to z=%1.5f halos." % \ - child_pf['CosmologyCurrentRedshift']) - - if last == None: - # First we're going to read in the particles, haloIDs and masses from - # the parent dataset. - parent_names = list(self.names[parent_currt]) - parent_names.sort() - parent_IDs = na.array([], dtype='int64') - parent_masses = na.array([], dtype='float64') - parent_halos = na.array([], dtype='int32') - for i,pname in enumerate(parent_names): - if i>=self.mine and i%self.size==self.mine: - h5fp = h5py.File(pname) - for group in h5fp: - gID = int(group[4:]) - thisIDs = h5fp[group]['particle_index'][:] - thisMasses = h5fp[group]['ParticleMassMsun'][:] - parent_IDs = na.concatenate((parent_IDs, thisIDs)) - parent_masses = na.concatenate((parent_masses, thisMasses)) - parent_halos = na.concatenate((parent_halos, - na.ones(thisIDs.size, dtype='int32') * gID)) - h5fp.close() - - # Sort the arrays by particle index in ascending order. - sort = parent_IDs.argsort() - parent_IDs = parent_IDs[sort] - parent_masses = parent_masses[sort] - parent_halos = parent_halos[sort] - del sort - else: - # We can use old data and save disk reading. - (parent_IDs, parent_masses, parent_halos) = last - # Used to communicate un-matched particles. - parent_send = na.ones(parent_IDs.size, dtype='bool') - - # Now get the child halo data. - child_names = list(self.names[child_currt]) - child_names.sort() - child_IDs = na.array([], dtype='int64') - child_masses = na.array([], dtype='float64') - child_halos = na.array([], dtype='int32') - for i,cname in enumerate(child_names): - if i>=self.mine and i%self.size==self.mine: - h5fp = h5py.File(cname) - for group in h5fp: - gID = int(group[4:]) - thisIDs = h5fp[group]['particle_index'][:] - thisMasses = h5fp[group]['ParticleMassMsun'][:] - child_IDs = na.concatenate((child_IDs, thisIDs)) - child_masses = na.concatenate((child_masses, thisMasses)) - child_halos = na.concatenate((child_halos, - na.ones(thisIDs.size, dtype='int32') * gID)) - h5fp.close() - - # Sort the arrays by particle index. - sort = child_IDs.argsort() - child_IDs = child_IDs[sort] - child_masses = child_masses[sort] - child_halos = child_halos[sort] - child_send = na.ones(child_IDs.size, dtype='bool') - del sort - - # Parent IDs on the left, child IDs on the right. We skip down both - # columns matching IDs. If they are out of synch, the index(es) is/are - # advanced until they match up again. - left = 0 - right = 0 - while left < parent_IDs.size and right < child_IDs.size: - if parent_IDs[left] == child_IDs[right]: - # They match up, add this relationship. - try: - loc = self.child_mass_loc[parent_halos[left]][child_halos[right]] - except KeyError: - # This happens when a child halo contains a particle from - # a parent halo, but the child is not identified as a - # candidate child halo. So we do nothing and move on with - # our lives. - left += 1 - right += 1 - continue - self.child_mass_arr[loc] += parent_masses[left] - # Mark this pair so we don't send them later. - parent_send[left] = False - child_send[right] = False - left += 1 - right += 1 - continue - if parent_IDs[left] < child_IDs[right]: - # The left is too small, so we need to increase it. - left += 1 - continue - if parent_IDs[left] > child_IDs[right]: - # Right too small. - right += 1 - continue - - # Now we send all the un-matched particles to the root task for one more - # pass. This depends on the assumption that most of the particles do - # not move very much between data dumps, so that not too many particles - # will be dumped on the single task. - parent_IDs_tosend = parent_IDs[parent_send] - parent_masses_tosend = parent_masses[parent_send] - parent_halos_tosend = parent_halos[parent_send] - child_IDs_tosend = child_IDs[child_send] - child_halos_tosend = child_halos[child_send] - - parent_IDs_tosend = self._mpi_concatenate_array_on_root_long(parent_IDs_tosend) - parent_masses_tosend = self._mpi_concatenate_array_on_root_double(parent_masses_tosend) - parent_halos_tosend = self._mpi_concatenate_array_on_root_int(parent_halos_tosend) - child_IDs_tosend = self._mpi_concatenate_array_on_root_long(child_IDs_tosend) - child_halos_tosend = self._mpi_concatenate_array_on_root_int(child_halos_tosend) - - # Resort the received particles. - Psort = parent_IDs_tosend.argsort() - parent_IDs_tosend = parent_IDs_tosend[Psort] - parent_masses_tosend = parent_masses_tosend[Psort] - parent_halos_tosend = parent_halos_tosend[Psort] - Csort = child_IDs_tosend.argsort() - child_IDs_tosend = child_IDs_tosend[Csort] - child_halos_tosend = child_halos_tosend[Csort] - del Psort, Csort - - # Now Again. - if self.mine == 0: - matched = 0 - left = 0 - right = 0 - while left < parent_IDs_tosend.size and right < child_IDs_tosend.size: - if parent_IDs_tosend[left] == child_IDs_tosend[right]: - # They match up, add this relationship. - try: - loc = self.child_mass_loc[parent_halos_tosend[left]][child_halos_tosend[right]] - except KeyError: - # This happens when a child halo contains a particle from - # a parent halo, but the child is not identified as a - # candidate child halo. So we do nothing and move on with - # our lives. - left += 1 - right += 1 - continue - self.child_mass_arr[loc] += parent_masses_tosend[left] - matched += 1 - left += 1 - right += 1 - continue - if parent_IDs_tosend[left] < child_IDs_tosend[right]: - # The left is too small, so we need to increase it. - left += 1 - continue - if parent_IDs_tosend[left] > child_IDs_tosend[right]: - # Right too small. - right += 1 - continue - mylog.info("Clean-up round matched %d of %d parents and %d children." % \ - (matched, parent_IDs_tosend.size, child_IDs_tosend.size)) - - # Now we sum up the contributions globally. - self.child_mass_arr = self._mpi_Allsum_double(self.child_mass_arr) - - # Turn these Msol masses into percentages of the parent. - line = "SELECT HaloMass FROM Halos WHERE SnapCurrentTimeIdentifier=%d \ - ORDER BY SnapHaloID ASC;" % parent_currt - self.cursor.execute(line) - mark = 0 - result = self.cursor.fetchone() - while result: - mass = result[0] - self.child_mass_arr[mark:mark+5] /= mass - mark += 5 - result = self.cursor.fetchone() - - # Get the global ID for the SnapHaloID=0 from the child, this will - # be used to prevent unnecessary SQL reads. - line = "SELECT GlobalHaloID FROM Halos WHERE SnapCurrentTimeIdentifier=%d \ - AND SnapHaloID=0;" % child_currt - self.cursor.execute(line) - baseChildID = self.cursor.fetchone()[0] - - # Now we prepare a big list of writes to put in the database. - for i,parent_halo in enumerate(sorted(self.candidates)): - child_indexes = [] - child_per = [] - for j,child in enumerate(self.candidates[parent_halo]): - if child == -1: - # Account for fake children. - child_indexes.append(-1) - child_per.append(0.) - continue - # We need to get the GlobalHaloID for this child. - child_globalID = baseChildID + child - child_indexes.append(child_globalID) - child_per.append(self.child_mass_arr[i*5 + j]) - # Sort by percentages, desending. - child_per, child_indexes = zip(*sorted(zip(child_per, child_indexes), reverse=True)) - values = [] - for pair in zip(child_indexes, child_per): - values.extend([int(pair[0]), float(pair[1])]) - #values.extend([parent_currt, parent_halo]) - # This has the child ID, child percent listed five times, followed - # by the currt and this parent halo ID (SnapHaloID). - #values = tuple(values) - self.write_values.append(values) - self.write_values_dict[parent_currt][parent_halo] = values - - return (child_IDs, child_masses, child_halos) - - def _copy_and_update_db(self): - """ - Because doing an UPDATE of a SQLite database is really slow, what we'll - do here is basically read in lines from the database, and then insert - the parent-child relationships, writing to a new DB. - """ - temp_name = self.database + '-tmp' - if self.mine == 0: - to_write = [] - # Open the temporary database. - try: - os.remove(temp_name) - except OSError: - pass - temp_conn = sql.connect(temp_name) - temp_cursor = temp_conn.cursor() - line = "CREATE TABLE Halos (GlobalHaloID INTEGER PRIMARY KEY,\ - SnapCurrentTimeIdentifier INTEGER, SnapZ FLOAT, SnapHaloID INTEGER, \ - HaloMass FLOAT,\ - NumPart INTEGER, CenMassX FLOAT, CenMassY FLOAT,\ - CenMassZ FLOAT, BulkVelX FLOAT, BulkVelY FLOAT, BulkVelZ FLOAT,\ - MaxRad FLOAT,\ - ChildHaloID0 INTEGER, ChildHaloFrac0 FLOAT, \ - ChildHaloID1 INTEGER, ChildHaloFrac1 FLOAT, \ - ChildHaloID2 INTEGER, ChildHaloFrac2 FLOAT, \ - ChildHaloID3 INTEGER, ChildHaloFrac3 FLOAT, \ - ChildHaloID4 INTEGER, ChildHaloFrac4 FLOAT);" - temp_cursor.execute(line) - temp_conn.commit() - # Get all the data! - self.cursor.execute("SELECT * FROM Halos;") - results = self.cursor.fetchone() - while results: - results = list(results) - currt = results[1] - hid = results[3] - # If for some reason this halo doesn't have relationships, - # we'll just keep the old results the same. - try: - lookup = self.write_values_dict[currt][hid] - new = tuple(results[:-10] + lookup) - except KeyError: - new = tuple(results) - to_write.append(new) - results = self.cursor.fetchone() - # Now write to the temp database. - # 23 question marks for 23 data columns. - line = '' - for i in range(23): - line += '?,' - # Pull off the last comma. - line = 'INSERT into Halos VALUES (' + line[:-1] + ')' - for insert in to_write: - temp_cursor.execute(line, insert) - temp_conn.commit() - mylog.info("Creating database index.") - line = "CREATE INDEX IF NOT EXISTS HalosIndex ON Halos (" - for name in columns: - line += name +"," - line = line[:-1] + ");" - temp_cursor.execute(line) - temp_cursor.close() - temp_conn.close() - self._close_database() - self._barrier() - if self.mine == 0: - os.rename(temp_name, self.database) - -class MergerTreeConnect(DatabaseFunctions): - def __init__(self, database='halos.db'): - r"""Create a convenience object for accessing data from the halo database. - - Parameters - ---------- - database : String - The name of the halo database to access. Default = 'halos.db'. - - Examples - ------- - >>> mtc = MergerTreeConnect('/home/user/sim1-halos.db') - """ - self.database = database - result = self._open_database() - if not result: - return None - - def close(self): - r"""Cleanly close access to the database. - - Examples - -------- - >>> mtc.close() - """ - # To be more like typical Python open/close. - self._close_database() - - def query(self, string): - r"""Performs a query of the database and returns the results as a list - of tuple(s), even if the result is singular. - - Parameters - ---------- - string : String - The SQL query of the database. - - Examples - ------- - >>> results = mtc.query("SELECT GlobalHaloID from Halos where SnapHaloID = 0 and \ - ... SnapZ = 0;") - """ - # Query the database and return a list of tuples. - if string is None: - mylog.error("You must enter a SQL query.") - return None - items = [] - self.cursor.execute(string) - results = self.cursor.fetchone() - while results: - items.append(results) - results = self.cursor.fetchone() - return items - - def get_GlobalHaloID(self, SnapHaloID, z): - r"""Returns the GlobalHaloID for the given halo. - - Parameters - --------- - SnapHaloID : Integer - The index label for the halo of interest, equivalent to - the first column of the halo finder text output file. - z : Float - The redshift for the halo of interest. The value returned will be - for the halo with SnapHaloID equal to ID (above) with redshift - closest to this value. - - Examples - -------- - >>> this_halo = mtc.get_GlobalHaloID(0, 0.) - """ - string = "SELECT GlobalHaloID,SnapZ FROM Halos WHERE SnapHaloID = %d;" \ - % SnapHaloID - minz = 99999. - # If -1 is returned, something went wrong. - this_halo = -1 - self.cursor.execute(string) - results = self.cursor.fetchone() - while results: - if abs(results[1] - z) < minz: - minz = abs(results[1] - z) - this_halo = results[0] - results = self.cursor.fetchone() - return this_halo - - def get_halo_parents(self, GlobalHaloID): - r"""Returns a list of the parent halos to the given halo, along with - the contribution fractions from parent to child. - - This function returns a list of lists, where each entry in the top list - is [GlobalHaloID, ChildHaloFrac] of the parent halo in relationship - to the given child halo. - - Parameters - ---------- - GlobalHaloID : Integer - The GlobalHaloID of the halo of interest. - - Examples - -------- - >>> parents = mtc.get_halo_parents(1688) - >>> print parents - [[1544, 0.9642857141249418], - [1613, 0.0], - [1614, 0.0], - [1489, 0.0], - [1512, 0.0], - [1519, 0.0], - [1609, 0.0]] - """ - parents = [] - for i in range(5): - string = "SELECT GlobalHaloID, ChildHaloFrac%d FROM Halos\ - WHERE ChildHaloID%d=%d;" % (i, i, GlobalHaloID) - self.cursor.execute(string) - results = self.cursor.fetchone() - while results: - parents.append([results[0], results[1]]) - results = self.cursor.fetchone() - return parents - - def get_direct_parent(self, GlobalHaloID): - r"""Returns the GlobalHaloID of the direct parent of the given halo. - - This is accomplished by identifying the most massive parent halo - that contributes at least 50% of its mass to the given halo. - - Parameters - ---------- - GlobalHaloID : Integer - The GlobalHaloID of the halo of interest. - - Examples - -------- - >>> parent = mtc.get_direct_parent(1688) - >>> print parent - 1544 - """ - parents = self.get_halo_parents(GlobalHaloID) - mass = 0 - ID = None - for parent in parents: - if parent[1] < 0.5: continue - info = self.get_halo_info(parent[0]) - if info['HaloMass'] > mass: - mass = info['HaloMass'] - ID = parent[0] - return ID - - def get_halo_info(self, GlobalHaloID): - r"""Returns all available information for the given GlobalHaloID - in the form of a dict. - - Parameters - ---------- - GlobalHaloID : Integer - The unique index for the halo of interest. - - Examples - -------- - >>> info = mtc.get_halo_info(1544) - >>> print info - {'BulkVelX': -32759799.359999999, - 'BulkVelY': -28740239.109999999, - 'BulkVelZ': -20066000.690000001, - 'CenMassX': 0.23059111360000001, - 'CenMassY': 0.4061139809, - 'CenMassZ': 0.80882763749999997, - 'ChildHaloFrac0': 0.9642857141249418, - 'ChildHaloFrac1': 0.0, - 'ChildHaloFrac2': 0.0, - 'ChildHaloFrac3': 0.0, - 'ChildHaloFrac4': 0.0, - 'ChildHaloID0': 1688, - 'ChildHaloID1': 1712, - 'ChildHaloID2': 1664, - 'ChildHaloID3': 1657, - 'ChildHaloID4': 1634, - 'GlobalHaloID': 1544, - 'HaloMass': 20934692770000.0, - 'MaxRad': 0.01531299899, - 'NumPart': 196, - 'SnapCurrentTimeIdentifier': 1275946788, - 'SnapHaloID': 56, - 'SnapZ': 0.024169713061444002} - """ - string = "SELECT * FROM Halos WHERE GlobalHaloID=%d;" % GlobalHaloID - d = {} - self.cursor.execute(string) - results = self.cursor.fetchone() - for pair in zip(columns, results): - d[pair[0]] = pair[1] - return d - -class Node(object): - def __init__(self, CoM, mass, parentIDs, z, color): - self.CoM = CoM - self.mass = mass - self.parentIDs = parentIDs # In descending order of contribution - self.z = z - self.color = color - -class Link(object): - def __init__(self): - self.childIDs = [] - self.fractions = [] - -class MergerTreeDotOutput(DatabaseFunctions, lagos.ParallelAnalysisInterface): - def __init__(self, halos=None, database='halos.db', - dotfile='MergerTree.gv', current_time=None, link_min=0.2): - r"""Output the merger tree history for a given set of halo(s) in Graphviz - format. - - Parameters - --------- - halos : Integer or list of integers - If current_time below is not specified or is None, this is an integer - or list of integers with the GlobalHaloIDs of the halos to be - tracked. If current_time is specified, this is the SnapHaloIDs - for the halos to be tracked, which is identical to what is in - HopAnalysis.out files (for example). - database : String - The name of the database file. Default = 'halos.db'. - dotfile : String - The name of the file to write to. Default = 'MergerTree.gv' - current_time : Integer - The SnapCurrentTimeIdentifier for the snapshot for the halos to - be tracked. This is identical to the CurrentTimeIdentifier in - Enzo restart files. Default = None. - link_min : Float - When establishing a parent/child relationship, this is the minimum - mass fraction of the parent halo contributed to - the child halo that will be tracked - while building the Graphviz file. Default = 0.2. - - Examples - -------- - >>> MergerTreeDotOutput(halos=182842, database='/home/user/sim1-halos.db', - ... dotfile = 'halo-182842.gv') - """ - self.database = database - self.link_min = link_min - if halos is None: - mylog.error("Please provide at least one halo to start the tree. Exiting.") - return None - result = self._open_database() - if not result: - mylog.warn("The database did not open correctly!") - return None - if type(halos) == types.IntType: - halos = [halos] - if current_time is not None: - halos = self._translate_haloIDs(halos, current_time) - newhalos = set(halos) - # A key is the GlobalHaloID for this halo, and the content is a - # Node object. - self.nodes = {} - # A key is the GlobalHaloID for the parent in the relationship, - # and the content is a Link ojbect. - self.links = defaultdict(Link) - # Record which halos are at the same z level for convenience. - # They key is a z value, and the content a list of co-leveled halo IDs. - self.levels = defaultdict(list) - # For the first set of halos. - self._add_nodes(newhalos) - # Recurse over parents. - while len(newhalos) > 0: - mylog.info("Finding parents for %d children." % len(newhalos)) - newhalos = self._find_parents(newhalos) - self._add_nodes(newhalos) - mylog.info("Writing out %s to disk." % dotfile) - self._open_dot(dotfile) - self._write_nodes() - self._write_links() - self._write_levels() - self._close_dot() - self._close_database() - return None - - def _translate_haloIDs(self, halos, current_time): - # If the input is in the haloID equivalent to SnapHaloID, translate them - # to GlobalHaloIDs. - new_haloIDs=[] - for halo in halos: - line = "SELECT GlobalHaloID FROM Halos WHERE SnapHaloID=? AND \ - SnapCurrentTimeIdentifier=? limit 1;" - values = (halo, current_time) - self.cursor.execute(line, values) - new_haloIDs.append(self.cursor.fetchone()[0]) - return new_haloIDs - - def _find_parents(self, halos): - # Given a set of halos, find their parents and add that to each of their - # node records. At the same time, make a link record for that - # relationship. - # This stores the newly discovered parent halos. - newhalos = set([]) - for halo in halos: - line = "SELECT GlobalHaloID, ChildHaloFrac0,\ - ChildHaloFrac1, ChildHaloFrac2,ChildHaloFrac3, ChildHaloFrac4,\ - ChildHaloID0, ChildHaloID1, ChildHaloID2, \ - ChildHaloID3, ChildHaloID4 \ - FROM Halos WHERE\ - ChildHaloID0=? or ChildHaloID1=? or ChildHaloID2=? or\ - ChildHaloID3=? or ChildHaloID4=?;" - values = (halo, halo, halo, halo, halo) - self.cursor.execute(line, values) - result = self.cursor.fetchone() - while result: - res = list(result) - pID = result[0] - pfracs = res[1:6] - cIDs = res[6:11] - for pair in zip(cIDs, pfracs): - if pair[1] <= self.link_min or pair[0] != halo: - continue - else: - self.nodes[halo].parentIDs.append(pID) - self.links[pID].childIDs.append(halo) - self.links[pID].fractions.append(pair[1]) - newhalos.add(pID) - result = self.cursor.fetchone() - return newhalos - - def _add_nodes(self, newhalos): - # Each call of this function always happens for a set of newhalos that - # are at the same z. To give the halos color we will figure out how - # many halos total were found this z. - # There's probably a way to do this with only one SQL operation. - if len(newhalos) == 0: - return - ahalo = list(newhalos)[0] - line = 'SELECT SnapCurrentTimeIdentifier FROM Halos WHERE GlobalHaloID=?;' - values = (ahalo,) - self.cursor.execute(line, values) - result = self.cursor.fetchone() - # Use currt to get the number. - line = 'SELECT max(SnapHaloID) FROM Halos where SnapCurrentTimeIdentifier=?;' - values = (result[0],) - self.cursor.execute(line, values) - maxID = self.cursor.fetchone()[0] - # For the new halos, create nodes for them. - for halo in newhalos: - line = 'SELECT SnapZ, HaloMass, CenMassX, CenMassY, CenMassZ,\ - SnapHaloID FROM Halos WHERE GlobalHaloID=? limit 1;' - value = (halo,) - self.cursor.execute(line, value) - result = self.cursor.fetchone() - self.nodes[halo] = Node(na.array([result[2],result[3],result[4]]), - result[1], [], result[0], 1. - float(result[5])/(maxID+1)) #+1 to prevent /0 - self.levels[result[0]].append(halo) - - def _open_dot(self, dotfile): - # Write out the opening stuff in the dotfile. - self.dotfile=self._write_on_root(dotfile) - line = 'digraph galaxy {size="10, 10";\n' - line += 'node [style=bold, shape=record];\n' - self.dotfile.write(line) - - def _close_dot(self): - self.dotfile.write("\n};\n") - self.dotfile.close() - - def _write_nodes(self): - # Write out the nodes to the dot file. - self.dotfile.write("{\n") - for halo in self.nodes: - this = self.nodes[halo] - line = '"%d" [label="{%1.3e\\n(%1.3f,%1.3f,%1.3f)}", shape="record",' \ - % (halo, this.mass, this.CoM[0], this.CoM[1], this.CoM[2]) - line += ' color="%0.3f 1. %0.3f"];\n' % (this.color, this.color) - self.dotfile.write(line) - self.dotfile.write("};\n") - - def _write_links(self): - # Write out the links to the dot file. - self.dotfile.write("{\n") - for parent in self.links: - this = self.links[parent] - for child,frac in zip(this.childIDs, this.fractions): - if frac > self.link_min: - line = '"%d"->"%d" [label="%3.2f%%", color="blue", fontsize=10];\n' \ - % (parent, child, frac*100.) - self.dotfile.write(line) - self.dotfile.write("};\n") - - def _write_levels(self): - # Write out the co-leveled halos to the dot file. - for z in self.levels: - this = self.levels[z] - self.dotfile.write("{ rank = same;\n") - line = '"%1.5f"; ' % z - for halo in this: - line += '"%d"; ' % halo - line += "\n};\n" - self.dotfile.write(line) - # Also write out the unlinked boxes for the redshifts. - line = '{"%1.5f" [label="{%1.5f}", shape="record" color="green"];}\n' \ - % (z, z) - -class MergerTreeTextOutput(DatabaseFunctions, lagos.ParallelAnalysisInterface): - def __init__(self, database='halos.db', outfile='MergerTreeDB.txt'): - r"""Dump the contents of the merger tree database to a text file. - This is generally not recommended. - - Parameters - ---------- - database : String - Name of the database to access. Default = 'halos.db'. - outfile : String - Name of the file to write to. Default = 'MergerTreeDB.txt'. - - Examples - -------- - >>> MergerTreeTextOutput(database='/home/user/sim1-halos.db', - ... outfile='halos-db.txt') - """ - self.database = database - self.outfile = outfile - result = self._open_database() - if not result: - mylog.warn("Database file not read correctly!") - return None - self._write_out() - self._close_database() - return None - - def _write_out(self): - # Essentially dump the contents of the database into a text file. - fp = open(self.outfile, "w") - # Make the header line. - spacing = {} - for column in columns: - spacing[column] = (max(15,len(column)+1)) - line = "# " - for column in columns: - line += "%s" % column.ljust(spacing[column]) - line += "\n" - fp.write(line) - # Get the data. - line = "SELECT * FROM Halos ORDER BY SnapZ DESC, SnapHaloID ASC;" - self.cursor.execute(line) - results = self.cursor.fetchone() - # Write out the columns. - while results: - line = " " - for i,column in enumerate(columns): - if column_types[column] == "FLOAT": - this = "%1.6e" % results[i] - line += this.ljust(spacing[column]) - if column_types[column] == "INTEGER": - this = "%d" % results[i] - line += this.ljust(spacing[column]) - line += "\n" - fp.write(line) - results = self.cursor.fetchone() - fp.close() - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/mods.py --- a/yt/extensions/mods.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -""" -Very simple convenience function for importing all the extension modules. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -# -# ALL IMPORTS GO HERE -# - -# First module imports -import halo_profiler as HP -import lightcone as LC -import SpectralIntegrator as SI -import RayTracer as RT -import enzo_simulation as ES - -import HierarchySubset -import disk_analysis -import coordinate_transforms - -# Now individual component imports -from halo_profiler import HaloProfiler -from lightcone import LightCone -from SpectralIntegrator import create_table_from_textfiles, \ - SpectralFrequencyIntegrator -from RayTracer import SlowRayTracer -from HierarchySubset import ExtractedHierarchy - -from disk_analysis import StackedDiskImage -from coordinate_transforms import spherical_regrid, arbitrary_regrid diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_image_viewer.py --- a/yt/extensions/opengl_image_viewer.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,618 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: UCSD -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 . -""" - -# A simple image viewer, soon to be useful for stereo images, using OpenGL. - -import sys -import OpenGL.GL as GL -import OpenGL.GLUT as GLUT -import OpenGL.GLU as GLU -import OpenGL.GL.shaders as shaders -from OpenGL.arrays import vbo, ArrayDatatype -import Image -import glob -import numpy as na -import time - -ESCAPE = '\033' - -class ViewHandler3D(object): - def __init__(self, scene): - # We - self.scene = scene - self.dispatch_table = dict( - q = (scene.translate, (1, 1.0)), - e = (scene.translate, (1, -1.0)), - w = (scene.translate, (2, 1.0)), - s = (scene.translate, (2, -1.0)), - a = (scene.translate, (0, 1.0)), - d = (scene.translate, (0, -1.0)), - - Q = (scene.rotate, (1, 1.0)), - E = (scene.rotate, (1, -1.0)), - W = (scene.rotate, (2, 1.0)), - S = (scene.rotate, (2, -1.0)), - A = (scene.rotate, (0, 1.0)), - D = (scene.rotate, (0, -1.0)), - - ESCAPE = (sys.exit, (0,)) - ) - - def __call__(self, *args): - # We set up our standard handlers, and then anything additional can get - # called if none of our dispatch mechanisms work. - if args[0] in self.dispatch_table: - func, args = self.dispatch_table[args[0]] - func(*args) - # always draw when handling a keypress, even if it's one time too many - self.scene.draw() - -class GenericGLUTScene(object): - - def __init__(self, width, height): - self.init_glut(width, height) - self.init_opengl(width, height) - - def init_glut(self, width, height): - GLUT.glutInit([]) # drop sys.argv - GLUT.glutInitDisplayMode(self._display_mode) - GLUT.glutInitWindowSize(width, height) - GLUT.glutInitWindowPosition(0, 0) - self.window = GLUT.glutCreateWindow(self._title) - GLUT.glutDisplayFunc(self.draw) - #GLUT.glutIdleFunc(self.draw) - GLUT.glutKeyboardFunc(self.keypress_handler) - - def run(self): - GLUT.glutMainLoop() - -class MultiImageDisplayScene(object): - _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) - _title = "Image Display" - def __init__(self): - GenericGLUTScene(512, 512) - self._frames = [] - self._current = -1 - - def add_image(self, obj): - self._frames.append(obj) - - def init_opengl(self, width, height): - GL.glClearColor(0.0, 0.0, 0.0, 0.0) - GL.glClearDepth(1.0) - GL.glDepthFunc(GL.GL_LESS) - GL.glEnable(GL.GL_DEPTH_TEST) - GL.glShadeModel(GL.GL_SMOOTH) - - def draw(self): - - GL.glMatrixMode(GL.GL_MODELVIEW) - GL.glLoadIdentity() - - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - - if self._current >= 0: - self._draw_current() - - GLUT.glutSwapBuffers() - - def _draw_current(self): - self._frames[self._current].draw() - - def keypress_handler(self, *args): - if args[0] == ESCAPE: - sys.exit() - elif len(self._frames) == 0: - # The rest only operate if we have multiple frames - return - elif args[0] == 'n': - self._current = min(self._current + 1, len(self._frames)) - elif args[0] == 'N': - while self._current < len(self._frames) - 1: - self._current += 1 - self.draw() - elif args[0] == 'p': - self._current = max(self._current - 1, 0) - elif args[0] == 'P': - while self._current > 0: - self._current -= 1 - self.draw() - elif args[0] == 't': - for i in xrange(15): - time.sleep(0.05) - self.draw() - self._current += 1 - time.sleep(0.05) - self.draw() - self._current -= 1 - self.draw() # Once more for good measure - -class StereoMultiImageDisplayScene(MultiImageDisplayScene): - _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH | - GLUT.GLUT_STEREO) - - def draw(self): - GL.glDrawBuffer(GL.GL_BACK_LEFT) - - GL.glMatrixMode(GL.GL_MODELVIEW) - GL.glLoadIdentity() - - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - - if self._current >= 0: - self._draw_current_left() - - GLUT.glutSwapBuffers() - - GL.glDrawBuffer(GL.GL_BACK_RIGHT) - - GL.glMatrixMode(GL.GL_MODELVIEW) - GL.glLoadIdentity() - - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - - if self._current >= 0: - self._draw_current_right() - - GLUT.glutSwapBuffers() - - def _draw_current_left(self): - self._frames[self._current].draw_left() - - def _draw_current_right(self): - self._frames[self._current].draw_right() - -class FlatImage(object): - def __init__(self, tex_unit = GL.GL_TEXTURE0): - self.tex_unit = tex_unit - GL.glActiveTexture(self.tex_unit) - self._id = GL.glGenTextures(1) - - def draw(self): - GL.glActiveTexture(self.tex_unit) - GL.glEnable(GL.GL_TEXTURE_2D) - GL.glBindTexture(GL.GL_TEXTURE_2D, self._id) - GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL) - - GL.glColor3f(0.3, 0.5, 1.0) - - GL.glBegin(GL.GL_QUADS) - GL.glVertex3i(-1, -1, -1) - GL.glTexCoord2i(0, 0) - - GL.glVertex3i( 1, -1, -1) - GL.glTexCoord2i(0, 1) - - GL.glVertex3i( 1, 1, -1) - GL.glTexCoord2i(1, 1) - - GL.glVertex3i(-1, 1, -1) - GL.glTexCoord2i(1, 0) - GL.glEnd() - - def upload_image(self, buffer): - ix, iy, nc = buffer.shape - if nc != 4: raise RuntimeError - GL.glActiveTexture(self.tex_unit) - GL.glBindTexture(GL.GL_TEXTURE_2D, self._id) - GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) - GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, ix, iy, 0, GL.GL_RGBA, - GL.GL_UNSIGNED_BYTE, buffer.tostring()) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) - - @classmethod - def from_image_file(cls, fn, tex_unit = GL.GL_TEXTURE0): - buffer = na.array(Image.open(fn)) - print "Uploading buffer", buffer.min(), buffer.max(), buffer.shape, buffer.dtype - obj = cls(tex_unit) - obj.upload_image(buffer) - return obj - -class StereoImagePair(FlatImage): - def __init__(self, tex_unit = GL.GL_TEXTURE0): - self.tex_unit = tex_unit - self.left_image = FlatImage(tex_unit) - self.right_image = FlatImage(tex_unit) - - def draw_left(self): - self.left_image.draw() - - def draw_right(self): - self.right_image.draw() - - def upload_images(self, buffer_left, buffer_right): - self.left_image.upload_image(buffer_left) - self.right_image.upload_image(buffer_right) - - @classmethod - def from_image_files(cls, left_fn, right_fn, tex_unit = GL.GL_TEXTURE0): - print "Uploading pairs from %s and %s" % (left_fn, right_fn) - left_buffer = na.array(Image.open(left_fn)) - right_buffer = na.array(Image.open(right_fn)) - obj = cls(tex_unit) - obj.left_image.upload_image(left_buffer) - obj.right_image.upload_image(right_buffer) - return obj - -_verts = ( (0,0,0), (1,0,0), (1,1,0), (0,1,0), - (0,0,0), (1,0,0), (1,0,1), (0,0,1), - (0,0,0), (0,0,1), (0,1,1), (0,1,0), - (0,1,0), (1,1,0), (1,1,1), (0,1,1), - (1,1,0), (1,0,0), (1,0,1), (1,1,1), - (0,0,1), (0,1,1), (1,1,1), (1,0,1) ) - -class GridObject3DScene(GenericGLUTScene): - _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) - _title = "Grids" - - def _get_grid_vertices(self, offset): - DLE, DRE = self.pf['DomainLeftEdge'], pf['DomainRightEdge'] - DW = DRE - DLE - k = 0 - for g in self.pf.h.grids: - vs = ((g.LeftEdge-DLE)/DW, (g.RightEdge-DLE)/DW) - for vert in _verts: - for i,v in enumerate(vert): - yield vs[v][i] - offset - k += 1 - - def __init__(self, pf, offset = 0.5): - self.pf = pf - GenericGLUTScene.__init__(self, 800, 800) - - num = len(pf.h.grids) * 6 * 4 - self.v = na.fromiter(self._get_grid_vertices(offset), - dtype = 'float32', count = num * 3) - - self.vertices = vbo.VBO(self.v) - self.ng = len(pf.h.grids) - self.ox = self.oy = self.rx = self.ry = self.rz = 0 - self.oz = -4 - - def init_opengl(self, width, height): - # One-time GL setup - GL.glClearColor(1, 1, 1, 1) - GL.glColor3f(1, 0, 0) - GL.glEnable(GL.GL_DEPTH_TEST) - #glEnable(GL_CULL_FACE) - - # Uncomment this line for a wireframe view - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) - - # Simple light setup. On Windows GL_LIGHT0 is enabled by default, - # but this is not the case on Linux or Mac, so remember to always - # include it. - GL.glEnable(GL.GL_LIGHTING) - - def vec(*args): - return (GL.GLfloat * len(args))(*args) - - GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, vec(.5, .5, 1, 0)) - GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, vec(.5, .5, 1, 1)) - GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, vec(1, 1, 1, 1)) - GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, vec(1, 0, .5, 0)) - GL.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, vec(.5, .5, .5, 1)) - GL.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, vec(1, 1, 1, 1)) - - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1)) - GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, vec(1, 1, 1, 1)) - GL.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, 50) - - GL.glViewport(0, 0, width, height) - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - GLU.gluPerspective(60., width / float(height), 1e-3, 10.) - GL.glMatrixMode(GL.GL_MODELVIEW) - - def draw(self): - - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - GL.glLoadIdentity() - GL.glTranslatef(self.ox, self.oy, self.oz) - GL.glRotatef(self.rx, 0, 0, 1) - GL.glRotatef(self.ry, 0, 1, 0) - GL.glRotatef(self.rz, 1, 0, 0) - - self.vertices.bind() - GL.glEnableClientState(GL.GL_VERTEX_ARRAY) - GL.glVertexPointer( 3, GL.GL_FLOAT, 0, self.vertices) - GL.glDrawArrays(GL.GL_QUADS, 0, 4*6*self.ng) - - GL.glDisableClientState(GL.GL_VERTEX_ARRAY) - self.vertices.unbind() - GLUT.glutSwapBuffers() - - def keypress_handler(self, *args): - tfac = 25.0 - rfac = 0.5 - if args[0] == ESCAPE: - sys.exit() - elif args[0] == 'a': - self.ox += 1.0/tfac - elif args[0] == 'd': - self.ox -= 1.0/tfac - elif args[0] == 's': - self.oz -= 1.0/tfac - elif args[0] == 'w': - self.oz += 1.0/tfac - elif args[0] == 'q': - self.oy -= 1.0/tfac - elif args[0] == 'e': - self.oy += 1.0/tfac - # Now, rotations - elif args[0] == 'A': - self.rx -= 1.0/rfac - elif args[0] == 'D': - self.rx += 1.0/rfac - elif args[0] == 'S': - self.rz -= 1.0/rfac - elif args[0] == 'W': - self.rz += 1.0/rfac - elif args[0] == 'Q': - self.ry -= 1.0/rfac - elif args[0] == 'E': - self.ry += 1.0/rfac - self.draw() - -class GridSlice3DScene(GenericGLUTScene): - _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) - _title = "Grids" - - def _get_grid_vertices(self, offset): - for g in self.pf.h.grids: - vs = (g.LeftEdge, g.RightEdge) - for vert in _verts: - for i,v in enumerate(vert): - yield vs[v][i] - offset - - def _setup_grids(self): - self._grid_textures = {} - for g in self.pf.h.grids: - self._upload_grid_textures(g) - - def _upload_grid_textures(self, grid): - ix, iy, iz = grid.ActiveDimensions - - GL.glActiveTexture(GL.GL_TEXTURE0) - id_field = GL.glGenTextures(1) - upload = na.log10(grid["Density"].astype("float32")).copy() - self.mi = min(upload.min(), self.mi) - self.ma = max(upload.max(), self.ma) - #upload = (255*(upload - -31.0) / (-25.0 - -31.0)).astype("uint8") - - GL.glBindTexture(GL.GL_TEXTURE_3D, id_field) - GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) - GL.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_LUMINANCE32F_ARB, iz, iy, ix, 0, - GL.GL_LUMINANCE, GL.GL_FLOAT, upload) - - GL.glActiveTexture(GL.GL_TEXTURE1) - id_mask = GL.glGenTextures(1) - upload = grid.child_mask.astype("float32").copy() - - GL.glBindTexture(GL.GL_TEXTURE_3D, id_mask) - GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) - GL.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_LUMINANCE, iz, iy, ix, 0, - GL.GL_LUMINANCE, GL.GL_FLOAT, upload) - - self._grid_textures[grid.id] = (id_field, id_mask) - - print "Uploaded", grid.id - - def __init__(self, pf, offset = 0.5): - self.offset = offset - self.mi, self.ma = 1e30, -1e30 - self.pf = pf - self.coord = 0.0 - self.tfac = 10.0 - self.rfac = 0.5 - self._setup_keypress_handler() - GenericGLUTScene.__init__(self, 800, 800) - - num = len(pf.h.grids) * 6 * 4 - self.v = na.fromiter(self._get_grid_vertices(offset), - dtype = 'float32', count = num * 3) - - self.vertices = vbo.VBO(self.v) - self.ng = len(pf.h.grids) - self.position = na.zeros(3, dtype='float') - self.rotation = na.zeros(3, dtype='float') - self.position[2] = -2 # Offset backwards a bit - - self._setup_grids() - - def init_opengl(self, width, height): - # One-time GL setup - GL.glClearColor(1, 1, 1, 1) - GL.glColor3f(1, 0, 0) - GL.glEnable(GL.GL_DEPTH_TEST) - - GL.glViewport(0, 0, width, height) - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - GLU.gluPerspective(60., width / float(height), 1e-3, 10.) - GL.glMatrixMode(GL.GL_MODELVIEW) - - # Now we compile our shaders - - self.program = shaders.compileProgram( - shaders.compileShader(''' - void main() { - gl_TexCoord[0]=gl_TextureMatrix[0] * gl_MultiTexCoord0; - gl_TexCoord[1]=gl_TextureMatrix[1] * gl_MultiTexCoord1; - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - } - ''',GL.GL_VERTEX_SHADER), - shaders.compileShader(''' - uniform float ma; - uniform float mi; - uniform sampler3D field; - uniform sampler3D mask; - - void main() { - vec3 pos; - float val; - - pos = vec3(gl_TexCoord[1].xyz); - val = texture3D( mask, pos )[0]; - if(val == 0.0) discard; - - pos = vec3(gl_TexCoord[0].xyz); - val = texture3D( field, pos )[0]; - - float color = (val - mi) / (ma - mi); - - //gl_FragColor = vec4(pos.x, pos.y, pos.z, 1.0); - gl_FragColor = vec4(color, color, color, 1.0); - } - ''',GL.GL_FRAGMENT_SHADER),) - - self.uniform_locations = dict( ( - (v, GL.glGetUniformLocation(self.program, v)) for v in - ['mi','ma','field','mask'] - ) ) - - def draw(self): - - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) - - GL.glLoadIdentity() - GL.glTranslatef(*self.position) - GL.glRotatef(self.rotation[0], 0, 0, 1) - GL.glRotatef(self.rotation[1], 0, 1, 0) - GL.glRotatef(self.rotation[2], 1, 0, 0) - - self.vertices.bind() - GL.glColor3f(0.0, 0.0, 0.0) - GL.glEnableClientState(GL.GL_VERTEX_ARRAY) - GL.glVertexPointer( 3, GL.GL_FLOAT, 0, self.vertices) - GL.glDrawArrays(GL.GL_QUADS, 0, 4*6*self.ng) - GL.glDisableClientState(GL.GL_VERTEX_ARRAY) - self.vertices.unbind() - - # Now, we just want to draw - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) - - # We can just draw a single quad for now - GL.glUseProgram(self.program) - GL.glUniform1i(self.uniform_locations["field"], 0) - GL.glUniform1i(self.uniform_locations["mask"], 1) - GL.glUniform1f(self.uniform_locations["mi"], self.mi) - GL.glUniform1f(self.uniform_locations["ma"], self.ma) - GL.glEnable(GL.GL_TEXTURE_3D) - - t0, t1 = 0.0, 1.0 - for g in self.pf.h.find_slice_grids(self.coord + 0.5, 1)[0]: - LE = g.LeftEdge - self.offset - RE = g.RightEdge - self.offset - off = (self.coord - LE[1]) / (RE[1] - LE[1]) - - GL.glActiveTexture(GL.GL_TEXTURE0) - GL.glBindTexture(GL.GL_TEXTURE_3D, self._grid_textures[g.id][0]) - GL.glEnable(GL.GL_TEXTURE_3D) - - GL.glActiveTexture(GL.GL_TEXTURE1) - GL.glBindTexture(GL.GL_TEXTURE_3D, self._grid_textures[g.id][1]) - GL.glEnable(GL.GL_TEXTURE_3D) - - GL.glBegin(GL.GL_QUADS) - - GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t0, off, t0) - GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t0, off, t0) - GL.glVertex3f(LE[0], self.coord, LE[2]) - - GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t0, off, t1) - GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t0, off, t1) - GL.glVertex3f(RE[0], self.coord, LE[2]) - - GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t1, off, t1) - GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t1, off, t1) - GL.glVertex3f(RE[0], self.coord, RE[2]) - - GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t1, off, t0) - GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t1, off, t0) - GL.glVertex3f(LE[0], self.coord, RE[2]) - - GL.glEnd() - - GL.glUseProgram(0) - - GLUT.glutSwapBuffers() - - def move_slice(self, value): - self.coord += value - - def rotate(self, axis, value): - self.rotation[axis] += value/self.rfac - - def translate(self, axis, value): - self.position[axis] += value/self.tfac - - def _setup_keypress_handler(self): - self.keypress_handler = ViewHandler3D(self) - self.keypress_handler.dispatch_table.update(dict( - y = (self.move_slice, ( 0.05,)), - h = (self.move_slice, (-0.05,)) - )) - -if __name__ == "__main__": - if sys.argv[-2] == '-g': - import yt.mods - pf = yt.mods.load(sys.argv[-1]) - main_scene = GridObject3DScene(pf) - elif sys.argv[-2] == '-s': - import yt.mods - pf = yt.mods.load(sys.argv[-1]) - main_scene = GridSlice3DScene(pf) - else: - fn_list = glob.glob("frames/*.png") - - main_scene = MultiImageDisplayScene() - for fn in sorted(fn_list): - main_scene.add_image(FlatImage.from_image_file(fn)) - main_scene._current = 0 - main_scene.run() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_widgets/calculateRay.vertex.glsl --- a/yt/extensions/opengl_widgets/calculateRay.vertex.glsl Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* Vertex shader to calculate the ray to cast through the volume data. - * The result is passed to the fragment shader using a varying. - * - * This file is part of Visvis. - * Copyright 2009 Almar Klein - */ - -// the dimensions of the data, to determine stepsize -uniform vec3 shape; - -// ratio to tune the number of steps -uniform float stepRatio; - -// varyings to pass to fragment shader -varying vec3 ray; - -void main() -{ - - // First of all, set position. - // (We need to do this because this shader replaces the original shader.) - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - - // Store texture coordinate (also a default thing). - gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz; - - // Calculate the scaling of the modelview matrix so we can correct - // for axes.daspect and scale transforms of the wobject (in case - // of anisotropic data). - // We go from world coordinates to eye coordinates. - vec4 p0 = gl_ModelViewMatrix * vec4(0.0,0.0,0.0,1.0); - vec4 px = gl_ModelViewMatrix * vec4(1.0,0.0,0.0,1.0); - vec4 py = gl_ModelViewMatrix * vec4(0.0,1.0,0.0,1.0); - vec4 pz = gl_ModelViewMatrix * vec4(0.0,0.0,1.0,1.0); - float sx = length(p0.xyz - px.xyz); - float sy = length(p0.xyz - py.xyz); - float sz = length(p0.xyz - pz.xyz); - - // Create a (diagonal) matrix to correct for the scaling - mat4 Ms = mat4(0.0); - Ms[0][0] = 1.0/(sx*sx); - Ms[1][1] = 1.0/(sy*sy); - Ms[2][2] = 1.0/(sz*sz); - Ms[3][3] = 1.0; - - // Calculate ray direction. By correcting for the scaling, the ray is - // expressed in textute coordinates. - // We go from eye coordinates to world/texture coordinates. - vec4 p1 = vec4(0.0, 0.0, 0.0, 1.0) * gl_ModelViewProjectionMatrix * Ms; - vec4 p2 = vec4(0.0, 0.0, 1.0, 1.0) * gl_ModelViewProjectionMatrix * Ms; - ray = (p2.xyz/p2[3]) - (p1.xyz/p1[3]); - - // Normalize ray to unit length. - ray = normalize(ray); - - // Make the ray represent the length of a single voxel. - ray = ray / shape; - ray = ray * 0.58; // 1 over root of three = 0.577 - - // Scale ray to take smaller steps. - ray = ray / stepRatio; - -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_widgets/colormap.fragment.glsl --- a/yt/extensions/opengl_widgets/colormap.fragment.glsl Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -uniform sampler1D colormap; -uniform sampler2D buffer; -void main() -{ - vec2 pos = vec3(gl_TexCoord[0]).xy; - vec4 value = texture2D(buffer, pos); - //gl_FragColor = texture1D(colormap, pos[1]); - gl_FragColor = texture1D(colormap, value[0]); - //gl_FragColor = vec4(1.0, 0.5, 0.3, 1.0); - //gl_FragColor = vec4(value[0], value[1], value[2], 1.0); - //gl_FragColor = vec4(pos[1], 0.0, 0.0, 1.0); -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_widgets/framebuffer.vertex.glsl --- a/yt/extensions/opengl_widgets/framebuffer.vertex.glsl Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -/* Vertex shader to calculate the ray to cast through the volume data. - * The result is passed to the fragment shader using a varying. - * - * This file is part of Visvis. - * Copyright 2009 Almar Klein - */ - -void main() -{ - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz; -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_widgets/mip.fragment.glsl --- a/yt/extensions/opengl_widgets/mip.fragment.glsl Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -/* Fragment shader for Maximum Intensity Projection (MIP) rendering. - * The ray is cast through the volume and we keep track of the - * smalest value. This is the fastest rendermethod available. - * - * This file is part of Visvis. - * Copyright 2009 Almar Klein - */ - -// the 3D texture and colormap texture. -uniform sampler3D texture; -//uniform sampler1D colormap; - -// for window level and window width -uniform vec2 scaleBias; - -// varying calculated by vertex shader -varying vec3 ray; - -uniform vec3 shape; -uniform vec3 position; - -float d2P(vec3 p, vec3 d, vec4 P) -{ - // calculate the distance of a point p to a plane P along direction d. - // plane P is defined as ax + by + cz = d - // line is defined as two points on that line - - // calculate nominator and denominator - float nom = -( dot(P.rgb,p) - P.a ); - float denom = dot(P.rgb,d); - // determine what to return - if (nom*denom<=0.0) - return 9999999.0; // if negative, or ON the plane, return ~inf - else - return nom / denom; // return normally -} - -vec4 getRayAndSteps(vec3 edgeLoc) -{ - // Given the start pos, returns a corrected version of the ray - // and the number of steps combined in a vec4. - - // Check for all six planes how many rays fit from the start point. - // Take the minimum value (not counting negative and 0). - - float smallest = 9999999.0; - smallest = min(smallest, d2P(edgeLoc, ray, vec4(1.0, 0.0, 0.0, 0.0))); - smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 1.0, 0.0, 0.0))); - smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 0.0, 1.0, 0.0))); - smallest = min(smallest, d2P(edgeLoc, ray, vec4(1.0, 0.0, 0.0, 1.0))); - smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 1.0, 0.0, 1.0))); - smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 0.0, 1.0, 1.0))); - - // round-off errors can cause the value to be very large. - // an n of 100.000 is pretty save - if (smallest > 9999.0) - smallest = 1.0; - - // determine amount of steps and correct ray - vec4 result; - float n = ceil(smallest); - result.xyz = ray * (smallest/n); - result[3] = n; - - // done - return result; -} - - -void main() -{ - - // Get current pixel location. - vec3 edgeLoc = vec3(gl_TexCoord[0]); - - // Get ray and steps. - vec4 tmp4 = getRayAndSteps(edgeLoc); - vec3 ray2 = tmp4.zyx; - int n = int(tmp4[3]); - - // Init. Remember that we made sure that the total range of the data is - // mapped between 0 and 1 (also for signed data types). - //float maxval = texture3D(texture, edgeLoc + 1.0*ray2.xyz)[0]; - float maxval = -1e30; - - // Cast ray. For some reason the inner loop is not iterated the whole - // way for large datasets. Thus this ugly hack. If you know how to do - // it better, please let me know! - float val; - vec3 loc; - int i=0; - while (imaxval) - // maxval = val; - } - } - - // Finaly, apply window-level window-width. - maxval = ( maxval + scaleBias[1] ) * scaleBias[0]; - //maxval = (maxval - scale[0]) / (scale[1] - scale[0]); - - //maxval = texture3D(texture, vec3(0.5, 0.5, 0.5))[0]; - - // Apply colormap. - //gl_FragColor = texture1D( colormap, maxval ); - //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - //gl_FragColor = vec4(val,val,val,1.0); - gl_FragColor = vec4(maxval,maxval,maxval,1.0); - //gl_FragColor = vec4(ray2[0],ray2[1],ray2[2],1.0); - //gl_FragColor = vec4(loc[0],loc[1],loc[2],1.0); - //gl_FragColor = vec4(edgeLoc[0],edgeLoc[1],edgeLoc[2],1.0); - //gl_FragColor = vec4(edgeLoc[0],edgeLoc[0],edgeLoc[0],1.0); - //gl_FragColor = vec4(ray[0],ray[1],ray[2],1.0); - - //float mv = max(gl_FragData[1].r, maxval); - //if (mv < gl_FragData[1].r) discard; - //gl_FragData[0] = texture1D( colormap, mv); - //gl_FragData[1] = vec4(mv,mv,mv,mv); - - // Apply a depth? No, does only really make sence for the iso renderer. - //gl_FragDepth = 2.0 -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_widgets/mip_viewer.py --- a/yt/extensions/opengl_widgets/mip_viewer.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,452 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: UCSD -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 . -""" - -# A simple image viewer, soon to be useful for stereo images, using OpenGL. - -import sys, os -import OpenGL.GL as GL -import OpenGL.GLUT as GLUT -import OpenGL.GLU as GLU -import OpenGL.GL.shaders as shaders -from OpenGL.arrays import vbo, ArrayDatatype -import OpenGL.GL.ARB.framebuffer_object as GL_fbo -import Image -import glob -import numpy as na -import time - -from yt.extensions.opengl_image_viewer import ViewHandler3D, GenericGLUTScene -from yt.extensions.image_writer import map_to_colors - -from rendering_contexts import render_fbo, create_fbo, identity_view, \ - translate_view - -ESCAPE = '\033' - -_verts = ( (0,0,0), (1,0,0), (1,1,0), (0,1,0), - (0,0,0), (1,0,0), (1,0,1), (0,0,1), - (0,0,0), (0,0,1), (0,1,1), (0,1,0), - (0,1,0), (1,1,0), (1,1,1), (0,1,1), - (1,1,0), (1,0,0), (1,0,1), (1,1,1), - (0,0,1), (0,1,1), (1,1,1), (1,0,1) ) - -_verts = ( (1,1,0), (0,1,0), (0,1,1), (1,1,1), - (1,0,1), (0,0,1), (0,0,0), (1,0,0), - (1,1,1), (0,1,1), (0,0,1), (1,0,1), - (1,0,0), (0,0,0), (0,1,0), (1,1,0), - (0,1,1), (0,1,0), (0,0,0), (0,0,1), - (1,1,0), (1,1,1), (1,0,1), (1,0,0) ) - -_corner_list = [0,1,2,3, 4,5,6,7, 3,2,6,5, 0,4,7,1, 0,3,5,4, 1,7,6,2] -_corner_vals = [ (0,0,0), (1,0,0), (1,1,0), (0,1,0), - (0,0,1), (0,1,1), (1,1,1), (1,0,1) ] - -_reversed = {2:0,1:1,0:2} - -def _compress(lr, s, i): - - if lr == 0: return 0.5/s[_reversed[i]] - else: return -0.5/s[_reversed[i]] - - -class MIPScene(GenericGLUTScene): - _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) - _title = "MIP" - - gl_state = None - - def _get_brick_vertices(self, offset): - for b in self.hv.bricks: - s = [ [-0.5, -0.5, -0.5], - [b.my_data[0].shape[i] - 1.5 for i in reversed(xrange(3))] ] - for corner in _corner_list: - for i, v in enumerate(_corner_vals[corner]): - yield s[v][i] - - def _get_texture_vertices(self): - vs = [na.zeros(3, dtype='float32'), - na.ones(3, dtype='float32')] - #vs.reverse() - for b in self.hv.bricks: - shape = b.my_data[0].shape - for corner in _corner_list: - for i,v in enumerate(_corner_vals[corner]): - yield vs[v][i] + _compress(v, shape, i) - - def _setup_bricks(self): - self._brick_textures = [] - for g in self.hv.bricks: - self._upload_brick_textures(g) - - def _upload_brick_textures(self, brick): - ix, iy, iz = brick.my_data[0].shape - - GL.glActiveTexture(GL.GL_TEXTURE0) - id_field = GL.glGenTextures(1) - upload = brick.my_data[0].astype("float32") - #upload = (upload - -31.847) / ( -25.948 - -31.847 ) - #mi, ma = -31.847, -25.948 - #mi, ma = -27.2062, -20.9649 - #upload = (upload - mi)/(ma - mi) - self.mi = min(upload.min(), self.mi) - self.ma = max(upload.max(), self.ma) - #upload = (255*(upload - -31.0) / (-25.0 - -31.0)).astype("uint8") - - GL.glActiveTexture(GL.GL_TEXTURE0) - GL.glBindTexture(GL.GL_TEXTURE_3D, id_field) - GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) - GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) - GL.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_LUMINANCE32F_ARB, iz, iy, ix, 0, - GL.GL_LUMINANCE, GL.GL_FLOAT, upload) - - DW = self.hv.pf["DomainRightEdge"] - self.hv.pf["DomainLeftEdge"] - dds = ((brick.RightEdge - brick.LeftEdge) / - (na.array([ix,iy,iz], dtype='float32')-1)) / DW - BLE = brick.LeftEdge / DW - 0.5 - self._brick_textures.append( - (id_field, (ix-1,iy-1,iz-1), dds, BLE)) - - print "Uploaded", len(self._brick_textures) - - def _setup_colormap(self): - - buffer = na.mgrid[0.0:1.0:256j] - colors = map_to_colors(buffer, "algae") - - GL.glActiveTexture(GL.GL_TEXTURE1) - id_cmap = GL.glGenTextures(1) - - GL.glBindTexture(GL.GL_TEXTURE_1D, id_cmap) - GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) - GL.glTexParameterf(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) - GL.glTexParameterf(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) - GL.glTexParameterf(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) - GL.glTexImage1D(GL.GL_TEXTURE_1D, 0, GL.GL_RGBA, 256, 0, - GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, colors) - - self.gl_state["cmap_tex"] = id_cmap - - def __init__(self, hv, offset = 0.5): - self.offset = offset - self.mi, self.ma = 1e30, -1e30 - self.hv = hv - self.coord = 0.0 - self.tfac = 10.0 - self.rfac = 0.5 - self.wireframe = False - self.glda = True - self._setup_keypress_handler() - self.gl_state = {} - GenericGLUTScene.__init__(self, 800, 800) - - num = len(hv.bricks) * 6 * 4 - self.v = na.fromiter(self._get_brick_vertices(offset), - dtype = 'float32', count = num * 3) - self.vertices = vbo.VBO(self.v) - - self.t = na.fromiter(self._get_texture_vertices(), - dtype = 'float32', count = num * 3) - self.tvertices = vbo.VBO(self.t) - - self.ng = len(hv.bricks) - self.position = na.zeros(3, dtype='float') - self.rotation = na.zeros(3, dtype='float') + 30 - self.position[2] = -2 # Offset backwards a bit - - self._setup_bricks() - create_fbo(self.gl_state) - self._setup_colormap() - - def init_opengl(self, width, height): - # One-time GL setup - - self.gl_state["width"] = width - self.gl_state["height"] = height - - self.set_viewport() - - # Now we compile our shaders - self.recompile() - - def set_viewport(self): - if self.wireframe: - GL.glClearColor(1, 1, 1, 1) - else: - GL.glClearColor(0, 0, 0, 1) - GL.glColor3f(1, 0, 0) - GL.glEnable(GL.GL_DEPTH_TEST) - - GL.glViewport(0, 0, self.gl_state["width"], self.gl_state["height"]) - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - GLU.gluPerspective(60., self.gl_state["width"] / float(self.gl_state["height"]), 1e-3, 10.) - GL.glMatrixMode(GL.GL_MODELVIEW) - - def recompile(self): - base = os.path.dirname(__file__) + "/" - self.program = compileProgram( - shaders.compileShader( - open(base+"calculateRay.vertex.glsl").read(), - GL.GL_VERTEX_SHADER), - shaders.compileShader( - open(base+"mip.fragment.glsl").read(), - GL.GL_FRAGMENT_SHADER)) - - def _set_simple_uniform(prog): - GL.glUseProgram(prog) - loc = GL.glGetUniformLocation(prog, 'buffer') - GL.glUniform1i(loc, 0) - loc = GL.glGetUniformLocation(prog, 'colormap') - GL.glUniform1i(loc, 1) - GL.glUseProgram(0) - - self.fbo_program = compileProgram( - shaders.compileShader( - open(base+"framebuffer.vertex.glsl").read(), - GL.GL_VERTEX_SHADER), - shaders.compileShader( - open(base+"colormap.fragment.glsl").read(), - GL.GL_FRAGMENT_SHADER), - callback = _set_simple_uniform) - - self.uniform_locations = dict( ( - (v, GL.glGetUniformLocation(self.program, v)) for v in - ['texture','shape','scaleBias','stepRatio','position'] - ) ) - self.fbo_uniform_locations = dict( ( - (v, GL.glGetUniformLocation(self.fbo_program, v)) for v in - ['colormap','buffer'] - ) ) - - print self.uniform_locations, self.fbo_uniform_locations - - @render_fbo - def _draw_boxes(self): - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - GL.glDisable(GL.GL_DEPTH_TEST) - GL.glEnable(GL.GL_BLEND) - if self.wireframe: - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) - else: - GL.glBlendEquation(GL.GL_MAX) - GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) - GL.glDisable(GL.GL_LINE_STIPPLE) - GL.glDisable(GL.GL_LINE_SMOOTH) - GL.glDisable(GL.GL_POINT_SMOOTH) - GL.glEnable(GL.GL_CULL_FACE) - #GL.glCullFace(GL.GL_FRONT) - GL.glCullFace(GL.GL_BACK) - - GL.glLoadIdentity() - GL.glTranslatef(*self.position) - GL.glRotatef(self.rotation[0], 0, 0, 1) - GL.glRotatef(self.rotation[1], 0, 1, 0) - GL.glRotatef(self.rotation[2], 1, 0, 0) - - GL.glColor3f(0.0, 0.0, 0.0) - GL.glUseProgram(self.program) - scalebias = ( 1.0/(self.ma - self.mi), -self.mi) - GL.glUniform1i(self.uniform_locations["texture"], 0) - GL.glUniform2f(self.uniform_locations["scaleBias"], scalebias[0], scalebias[1]) - GL.glUniform1f(self.uniform_locations["stepRatio"], 1.0) - GL.glUniform3f(self.uniform_locations["position"], *self.position) - - GL.glEnableClientState(GL.GL_VERTEX_ARRAY) - GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) - #GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY_EXT) - - GL.glColor3f(0.0, 0.0, 0.0) - - GL.glActiveTexture(GL.GL_TEXTURE0) - GL.glEnable(GL.GL_TEXTURE_3D) - - self.tvertices.bind() - GL.glTexCoordPointer(3, GL.GL_FLOAT, 0, self.tvertices) - self.vertices.bind() - GL.glVertexPointer(3, GL.GL_FLOAT, 0, self.vertices) - - for i, texinfo in enumerate(self._brick_textures): - tex, shape, width, LE = texinfo - GL.glActiveTexture(GL.GL_TEXTURE0) - GL.glBindTexture(GL.GL_TEXTURE_3D, tex) - GL.glUniform1f(self.uniform_locations["stepRatio"], 0.1) - GL.glUniform3f(self.uniform_locations["shape"], - shape[2], shape[1], shape[0]) - GL.glPushMatrix() - GL.glTranslate(LE[2], LE[1], LE[0]) - GL.glScale(width[2], width[1], width[0]) - if self.glda: - GL.glDrawArrays(GL.GL_QUADS, 24*i, 24) - else: - GL.glBegin(GL.GL_QUADS) - for fi in range(6): - for v in range(4): - #print -LE, width - off = i*72+fi*12+v*3 - qv = self.v[off:off+3] - tv = self.t[off:off+3] - GL.glTexCoord3f(*tv) - GL.glVertex3f(*qv) - GL.glEnd() - GL.glPopMatrix() - GL.glDisableClientState(GL.GL_VERTEX_ARRAY) - GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) - GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY_EXT) - self.vertices.unbind() - self.tvertices.unbind() - GL.glDisable(GL.GL_CULL_FACE) - - def draw(self): - - self._draw_boxes() - - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) - GL.glUseProgram(self.fbo_program) - - GL.glMatrixMode(GL.GL_MODELVIEW) - GL.glLoadIdentity() - - GL.glMatrixMode(GL.GL_PROJECTION) - GL.glLoadIdentity() - - GL.glActiveTexture(GL.GL_TEXTURE0) - GL.glEnable(GL.GL_TEXTURE_2D) - GL.glBindTexture(GL.GL_TEXTURE_2D, self.gl_state["fbo_tex"]) - - GL.glActiveTexture(GL.GL_TEXTURE1) - GL.glEnable(GL.GL_TEXTURE_1D) - GL.glBindTexture(GL.GL_TEXTURE_1D, self.gl_state["cmap_tex"]) - - GL.glUniform1i(self.fbo_uniform_locations["buffer"], 0) - GL.glUniform1i(self.fbo_uniform_locations["colormap"], 1) - - GL.glColor3f(0.3, 0.5, 1.0) - - GL.glBegin(GL.GL_QUADS) - GL.glTexCoord2i(0, 0) - GL.glVertex3i(-1, -1, -1) - - GL.glTexCoord2i(0, 1) - GL.glVertex3i( 1, -1, -1) - - GL.glTexCoord2i(1, 1) - GL.glVertex3i( 1, 1, -1) - - GL.glTexCoord2i(1, 0) - GL.glVertex3i(-1, 1, -1) - GL.glEnd() - - GL.glUseProgram(0) - - GLUT.glutSwapBuffers() - - def move_slice(self, value): - self.coord += value - - def rotate(self, axis, value): - self.rotation[axis] += value/self.rfac - - def reset_view(self): - print "RESETTING" - self.position = na.zeros(3, dtype='float') - self.rotation = na.zeros(3, dtype='float') + 30 - self.position[2] = -2 # Offset backwards a bit - - def translate(self, axis, value): - self.position[axis] += value/self.tfac - - def toggle_wireframe(self): - self.wireframe = not self.wireframe - print "Wireframe:", self.wireframe - - def toggle_glda(self): - self.glda = not self.glda - print "GLDA:", self.glda - - def _setup_keypress_handler(self): - self.keypress_handler = ViewHandler3D(self) - self.keypress_handler.dispatch_table.update(dict( - y = (self.move_slice, ( 0.05,)), - h = (self.move_slice, (-0.05,)), - t = (self.toggle_wireframe, ()), - u = (self.toggle_glda, ()), - i = (self.recompile, ()), - o = (self.reset_view, ()) - )) - -# We override the standard PyOpenGL one because otherwise we can't validate -# multitexture shaders. -def compileProgram(*my_shaders, **kwargs): - """Create a new program, attach my_shaders and validate - - my_shaders -- arbitrary number of my_shaders to attach to the - generated program. - - This convenience function is *not* standard OpenGL, - but it does wind up being fairly useful for demos - and the like. You may wish to copy it to your code - base to guard against PyOpenGL changes. - - Usage: - - shader = compileProgram( - compileShader( source, GL_VERTEX_SHADER ), - compileShader( source2, GL_FRAGMENT_SHADER ), - ) - glUseProgram( shader ) - - Note: - If (and only if) validation of the linked program - *passes* then the passed-in shader objects will be - deleted from the GL. - - returns GLuint shader program reference - raises RuntimeError when a link/validation failure occurs - """ - program = GL.glCreateProgram() - for shader in my_shaders: - GL.glAttachShader(program, shader) - GL.glLinkProgram(program) - # Validation has to occur *after* linking - if 'callback' in kwargs: kwargs['callback'](program) - GL.glValidateProgram( program ) - validation = GL.glGetProgramiv( program, GL.GL_VALIDATE_STATUS ) - if validation == GL.GL_FALSE: - raise RuntimeError( - """Validation failure (%s): %s"""%( - validation, - GL.glGetProgramInfoLog( program ), - )) - link_status = GL.glGetProgramiv( program, GL.GL_LINK_STATUS ) - if link_status == GL.GL_FALSE: - raise RuntimeError( - """Link failure (%s): %s"""%( - link_status, - GL.glGetProgramInfoLog( program ), - )) - for shader in my_shaders: - GL.glDeleteShader(shader) - return shaders.ShaderProgram( program ) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/opengl_widgets/rendering_contexts.py --- a/yt/extensions/opengl_widgets/rendering_contexts.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -""" -Author: Matthew Turk -Affiliation: UCSD -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 . -""" - -import OpenGL.GL as GL -import OpenGL.GLUT as GLUT -import OpenGL.GLU as GLU -import OpenGL.GL.shaders as shaders -from OpenGL.arrays import vbo, ArrayDatatype -import OpenGL.GL.ARB.framebuffer_object as GL_fbo -from functools import wraps - -def render_fbo(func): - @wraps(func) - def fbo_renderer(self, fbo_id = "fbo_id", fbo_depth = "fbo_depth", **kwargs): - GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, - self.gl_state[fbo_id]) - GL_fbo.glBindRenderbuffer(GL_fbo.GL_RENDERBUFFER, - self.gl_state[fbo_depth]) - self.set_viewport() - GL.glPushAttrib(GL.GL_VIEWPORT_BIT) - GL.glViewport(0, 0, self.gl_state["width"], self.gl_state["height"]) - status = GL_fbo.glCheckFramebufferStatus(GL_fbo.GL_FRAMEBUFFER) - assert(status == GL_fbo.GL_FRAMEBUFFER_COMPLETE) - - func(self, **kwargs) - - GL.glPopAttrib(GL.GL_VIEWPORT_BIT) - GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, 0) - - return fbo_renderer - -def create_fbo(gl_state, fbo_id = "fbo_id", fbo_depth = "fbo_depth", - fbo_tex = "fbo_tex"): - GL.glActiveTexture(GL.GL_TEXTURE0) - id_fbo = GL.glGenTextures(1) - id_depth = GL_fbo.glGenRenderbuffers(1) - gl_state[fbo_tex] = id_fbo - gl_state[fbo_depth] = id_depth - gl_state[fbo_id] = GL_fbo.glGenFramebuffers(1) - - GL.glBindTexture(GL.GL_TEXTURE_2D, id_fbo) - GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) - GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) - GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, - gl_state["width"], gl_state["height"], 0, - GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) - - GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, gl_state[fbo_id]) - GL_fbo.glFramebufferTexture2D(GL_fbo.GL_FRAMEBUFFER, - GL_fbo.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, gl_state[fbo_tex], 0) - - GL_fbo.glBindRenderbuffer(GL_fbo.GL_RENDERBUFFER, id_depth) - GL_fbo.glRenderbufferStorage(GL_fbo.GL_RENDERBUFFER, - GL.GL_DEPTH_COMPONENT, gl_state["width"], gl_state["height"]) - GL_fbo.glFramebufferRenderbuffer( - GL_fbo.GL_FRAMEBUFFER, GL_fbo.GL_DEPTH_ATTACHMENT, - GL_fbo.GL_RENDERBUFFER, id_depth) - - GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, 0) - GL_fbo.glBindRenderbuffer(GL_fbo.GL_RENDERBUFFER, 0) - -def identity_view(func): - pass - -def translate_view(func): - pass diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/setup.py --- a/yt/extensions/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#!/usr/bin/env python -import setuptools - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('extensions',parent_package,top_path) - config.make_config_py() # installs __config__.py - config.make_svn_version_py() - config.add_subpackage("lightcone") - config.add_subpackage("volume_rendering") - config.add_subpackage("kdtree") - config.add_subpackage("image_panner") - config.add_subpackage("enzo_test") - config.add_subpackage("opengl_widgets") - return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/CUDARayCast.py --- a/yt/extensions/volume_rendering/CUDARayCast.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -""" -An attempt at putting the ray-casting operation into CUDA - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import sys;sys.path.insert(0,'.') - -from yt.mods import * -import yt.extensions.HierarchySubset as hs -import numpy as na -import h5py, time - -import matplotlib;matplotlib.use("Agg");import pylab - -from yt.extensions.volume_rendering.TransferFunction import ColorTransferFunction - -if __name__ == "__main__": - - # This is boilerplate code for setting up pycuda - import pycuda.driver as cuda - import pycuda.compiler as compiler - import pycuda.autoinit - import pycuda.gpuarray as gpuarray - cuda.init() - assert (cuda.Device.count() >= 1) - - print "Extracting hierarchy." - opf = load("/u/ki/mturk/ki05/MSM96-SIM3-restart-J64/DataDump0081.dir/DataDump0081") - pf = hs.ExtractedParameterFile(opf, 20) - - cpu = {} - gpu = {} - - print "Reading data." - #fn = "DataDump0081_partitioned.h5" - fn = "RedshiftOutput0005_partitioned.h5" - f = h5py.File("/u/ki/mturk/ki05/%s" % fn) - cpu['grid_data'] = f["/PGrids/Data"][:].astype("float32") - cpu['dims'] = f["/PGrids/Dims"][:].astype("int32") - 1 - cpu['left_edge'] = f["/PGrids/LeftEdges"][:].astype("float32") - cpu['right_edge'] = f["/PGrids/RightEdges"][:].astype("float32") - - print "Constructing transfer function." - if "Data" in fn: - mh = na.log10(1.67e-24) - tf = ColorTransferFunction((7.5+mh, 14.0+mh)) - tf.add_gaussian( 8.25+mh, 0.002, [0.2, 0.2, 0.4, 0.1]) - tf.add_gaussian( 9.75+mh, 0.002, [0.0, 0.0, 0.3, 0.1]) - tf.add_gaussian(10.25+mh, 0.004, [0.0, 0.3, 0.0, 0.1]) - tf.add_gaussian(11.50+mh, 0.005, [1.0, 0.0, 0.0, 0.7]) - tf.add_gaussian(12.75+mh, 0.010, [1.0, 1.0, 1.0, 1.0]) - elif "Red" in fn: - tf = ColorTransferFunction((-31, -27)) - tf.add_gaussian(-30.0, 0.05, [1.0, 0.0, 0.0, 0.1]) - tf.add_gaussian(-29.5, 0.03, [0.0, 1.0, 0.0, 0.3]) - tf.add_gaussian(-29.0, 0.05, [0.0, 0.0, 1.0, 0.5]) - tf.add_gaussian(-28.5, 0.05, [1.0, 1.0, 1.0, 1.0]) - else: raise RuntimeError - - cpu['ngrids'] = na.array([cpu['dims'].shape[0]], dtype='int32') - cpu['tf_r'] = tf.red.y.astype("float32") - cpu['tf_g'] = tf.green.y.astype("float32") - cpu['tf_b'] = tf.blue.y.astype("float32") - cpu['tf_a'] = tf.alpha.y.astype("float32") - - cpu['tf_bounds'] = na.array(tf.x_bounds, dtype='float32') - - cpu['v_dir'] = na.array([0.3, 0.5, 0.6], dtype='float32') - - c = na.array([0.47284317, 0.48062515, 0.58282089], dtype='float32') - - print "Getting cutting plane." - cp = pf.h.cutting(cpu['v_dir'], c) - - W = 2000.0/pf['au'] - W = 0.25 - Nvec = 128 - back_c = c - cp._norm_vec * W - front_c = c + cp._norm_vec * W - - px, py = na.mgrid[-W:W:Nvec*1j,-W:W:Nvec*1j] - xv = cp._inv_mat[0,0]*px + cp._inv_mat[0,1]*py + cp.center[0] - yv = cp._inv_mat[1,0]*px + cp._inv_mat[1,1]*py + cp.center[1] - zv = cp._inv_mat[2,0]*px + cp._inv_mat[2,1]*py + cp.center[2] - cpu['v_pos'] = na.array([xv, yv, zv], dtype='float32').transpose() - - cpu['image_r'] = na.zeros((Nvec, Nvec), dtype='float32').ravel() - cpu['image_g'] = na.zeros((Nvec, Nvec), dtype='float32').ravel() - cpu['image_b'] = na.zeros((Nvec, Nvec), dtype='float32').ravel() - cpu['image_a'] = na.zeros((Nvec, Nvec), dtype='float32').ravel() - - print "Generating module" - source = open("yt/extensions/volume_rendering/_cuda_caster.cu").read() - mod = compiler.SourceModule(source) - func = mod.get_function("ray_cast") - - for n, a in cpu.items(): - ss = a.size * a.dtype.itemsize - print "Allocating %0.3e megabytes for %s" % (ss/(1024*1024.), n) - gpu[n] = cuda.to_device(a.ravel('F')) - #pycuda.autoinit.context.synchronize() - - BLOCK_SIZE = 8 - grid_size = Nvec / BLOCK_SIZE - - print "Running ray_cast function." - t1 = time.time() - ret = func(gpu['ngrids'], - gpu['grid_data'], - gpu['dims'], - gpu['left_edge'], - gpu['right_edge'], - gpu['tf_r'], - gpu['tf_g'], - gpu['tf_b'], - gpu['tf_a'], - gpu['tf_bounds'], - gpu['v_dir'], - gpu['v_pos'], - gpu['image_r'], - gpu['image_g'], - gpu['image_b'], - gpu['image_a'], - block=(BLOCK_SIZE,BLOCK_SIZE,1), - grid=(grid_size, grid_size), time_kernel=True) - t2 = time.time() - print "BACK: %0.3e" % (t2-t1) - - mi, ma = 1e300, -1e300 - image = [] - for im in 'rgb': - ii = 'image_%s' % im - sh, dtype = cpu[ii].shape, cpu[ii].dtype - del cpu[ii] - cpu[ii] = cuda.from_device(gpu[ii], sh, dtype).reshape((Nvec,Nvec)) - mi, ma = min(cpu[ii].min(),mi), max(cpu[ii].max(), ma) - image.append(cpu[ii]) - print "Min/max of %s %0.3e %0.3e" % ( - im, image[-1].min(), image[-1].max()) - pylab.clf() - pylab.imshow(image[-1], interpolation='nearest') - pylab.savefig("/u/ki/mturk/public_html/vr6/%s.png" % (ii)) - - image = na.array(image).transpose() - image = (image - mi) / (ma - mi) - pylab.clf() - pylab.imshow(image, interpolation='nearest') - pylab.savefig("/u/ki/mturk/public_html/vr6/image_rgb.png") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/UBVRI.py --- a/yt/extensions/volume_rendering/UBVRI.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -""" -Johnson Filters - -Author: JS Oishi -Affiliation: UC Berkeley -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2010 J.S. Oishi. 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 . -""" - - -import numpy as na - -johnson_filters = dict( - B = dict( - wavelen = na.array([3600, 3650, 3700, 3750, 3800, 3850, 3900, 3950, 4000, - 4050, 4100, 4150, 4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550, 4600, - 4650, 4700, 4750, 4800, 4850, 4900, 4950, 5000, 5050, 5100, 5150, 5200, - 5250, 5300, 5350, 5400, 5450, 5500, 5550], dtype='float64'), - trans = na.array([0.0, 0.0, 0.02, 0.05, 0.11, 0.18, 0.35, 0.55, 0.92, - 0.95, 0.98, 0.99, 1.0, 0.99, 0.98, 0.96, 0.94, 0.91, 0.87, 0.83, 0.79, - 0.74, 0.69, 0.63, 0.58, 0.52, 0.46, 0.41, 0.36, 0.3, 0.25, 0.2, 0.15, - 0.12, 0.09, 0.06, 0.04, 0.02, 0.01, 0.0, ], dtype='float64'), - ), - I = dict( - wavelen = na.array([ 6800, 6850, 6900, 6950, 7000, 7050, 7100, - 7150, 7200, 7250, 7300, 7350, 7400, 7450, 7500, 7550, 7600, 7650, 7700, - 7750, 7800, 7850, 7900, 7950, 8000, 8050, 8100, 8150, 8200, 8250, 8300, - 8350, 8400, 8450, 8500, 8550, 8600, 8650, 8700, 8750, 8800, 8850, 8900, - 8950, 9000, 9050, 9100, 9150, 9200, 9250, 9300, 9350, 9400, 9450, 9500, - 9550, 9600, 9650, 9700, 9750, 9800, 9850, 9900, 9950, 10000, 10050, - 10100, 10150, 10200, 10250, 10300, 10350, 10400, 10450, 10500, 10550, - 10600, 10650, 10700, 10750, 10800, 10850, 10900, 10950, 11000, 11050, - 11100, 11150, 11200, 11250, 11300, 11350, 11400, 11450, 11500, 11550, - 11600, 11650, 11700, 11750, 11800, 11850, ], dtype='float64'), - trans = na.array([ 0.0, 0.0, 0.01, 0.01, 0.01, 0.04, 0.08, 0.13, 0.17, - 0.21, 0.26, 0.3, 0.36, 0.4, 0.44, 0.49, 0.56, 0.6, 0.65, 0.72, 0.76, - 0.84, 0.9, 0.93, 0.96, 0.97, 0.97, 0.98, 0.98, 0.99, 0.99, 0.99, 0.99, - 1.0, 1.0, 1.0, 1.0, 1.0, 0.99, 0.98, 0.98, 0.97, 0.96, 0.94, 0.93, 0.9, - 0.88, 0.86, 0.84, 0.8, 0.76, 0.74, 0.71, 0.68, 0.65, 0.61, 0.58, 0.56, - 0.52, 0.5, 0.47, 0.44, 0.42, 0.39, 0.36, 0.34, 0.32, 0.3, 0.28, 0.26, - 0.24, 0.22, 0.2, 0.19, 0.17, 0.16, 0.15, 0.13, 0.12, 0.11, 0.1, 0.09, - 0.09, 0.08, 0.08, 0.07, 0.06, 0.05, 0.05, 0.04, 0.04, 0.03, 0.03, 0.02, - 0.02, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 0.0, ], dtype='float64'), - ), - R = dict( - wavelen = na.array([ 5200, 5250, 5300, 5350, 5400, 5450, 5500, 5550, 5600, - 5650, 5700, 5750, 5800, 5850, 5900, 5950, 6000, 6050, 6100, 6150, 6200, - 6250, 6300, 6350, 6400, 6450, 6500, 6550, 6600, 6650, 6700, 6750, 6800, - 6850, 6900, 6950, 7000, 7050, 7100, 7150, 7200, 7250, 7300, 7350, 7400, - 7450, 7500, 7550, 7600, 7650, 7700, 7750, 7800, 7850, 7900, 7950, 8000, - 8050, 8100, 8150, 8200, 8250, 8300, 8350, 8400, 8450, 8500, 8550, 8600, - 8650, 8700, 8750, 8800, 8850, 8900, 8950, 9000, 9050, 9100, 9150, 9200, - 9250, 9300, 9350, 9400, 9450, 9500, ], dtype='float64'), - trans = na.array([ 0.0, 0.01, 0.02, 0.04, 0.06, 0.11, 0.18, 0.23, 0.28, - 0.34, 0.4, 0.46, 0.5, 0.55, 0.6, 0.64, 0.69, 0.71, 0.74, 0.77, 0.79, - 0.81, 0.84, 0.86, 0.88, 0.9, 0.91, 0.92, 0.94, 0.95, 0.96, 0.97, 0.98, - 0.99, 0.99, 1.0, 1.0, 0.99, 0.98, 0.96, 0.94, 0.92, 0.9, 0.88, 0.85, - 0.83, 0.8, 0.77, 0.73, 0.7, 0.66, 0.62, 0.57, 0.53, 0.49, 0.45, 0.42, - 0.39, 0.36, 0.34, 0.31, 0.27, 0.22, 0.19, 0.17, 0.15, 0.13, 0.12, 0.11, - 0.1, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04, 0.04, 0.03, 0.03, 0.02, 0.02, - 0.02, 0.01, 0.01, 0.01, 0.01, 0.0, ], dtype='float64'), - ), - U = dict( - wavelen = na.array([ 3000, 3050, 3100, 3150, 3200, 3250, 3300, 3350, 3400, - 3450, 3500, 3550, 3600, 3650, 3700, 3750, 3800, 3850, 3900, 3950, 4000, - 4050, 4100, 4150, ], dtype='float64'), - trans = na.array([ 0.0, 0.04, 0.1, 0.25, 0.61, 0.75, 0.84, 0.88, 0.93, - 0.95, 0.97, 0.99, 1.0, 0.99, 0.97, 0.92, 0.73, 0.56, 0.36, 0.23, 0.05, - 0.03, 0.01, 0.0, ], dtype='float64'),), - V = dict( - wavelen = na.array([ 4600, 4650, 4700, 4750, 4800, 4850, 4900, 4950, 5000, - 5050, 5100, 5150, 5200, 5250, 5300, 5350, 5400, 5450, 5500, 5550, 5600, - 5650, 5700, 5750, 5800, 5850, 5900, 5950, 6000, 6050, 6100, 6150, 6200, - 6250, 6300, 6350, 6400, 6450, 6500, 6550, 6600, 6650, 6700, 6750, 6800, - 6850, 6900, 6950, 7000, 7050, 7100, 7150, 7200, 7250, 7300, 7350, ], - dtype='float64'), - trans = na.array([ 0.0, 0.0, 0.01, 0.01, 0.02, 0.05, 0.11, 0.2, 0.38, - 0.67, 0.78, 0.85, 0.91, 0.94, 0.96, 0.98, 0.98, 0.95, 0.87, 0.79, 0.72, - 0.71, 0.69, 0.65, 0.62, 0.58, 0.52, 0.46, 0.4, 0.34, 0.29, 0.24, 0.2, - 0.17, 0.14, 0.11, 0.08, 0.06, 0.05, 0.03, 0.02, 0.02, 0.01, 0.01, 0.01, - 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.0, ], - dtype='float64'), - ), - ) - -for filter, vals in johnson_filters.items(): - wavelen = vals["wavelen"] - trans = vals["trans"] - vals["Lchar"] = wavelen[na.argmax(trans)] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/__init__.py --- a/yt/extensions/volume_rendering/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -""" -Import the components of the volume rendering extension - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as na - -from transfer_functions import TransferFunction, ColorTransferFunction, \ - PlanckTransferFunction, \ - MultiVariateTransferFunction, \ - ProjectionTransferFunction -from yt.amr_utils import PartitionedGrid, VectorPlane, \ - TransferFunctionProxy -from grid_partitioner import HomogenizedVolume, \ - HomogenizedBrickCollection, \ - export_partitioned_grids, \ - import_partitioned_grids -from image_handling import export_rgba, import_rgba, \ - plot_channel, plot_rgb -from software_sampler import VolumeRendering -from camera import Camera, PerspectiveCamera, StereoPairCamera diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/_cuda_caster.cu --- a/yt/extensions/volume_rendering/_cuda_caster.cu Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,314 +0,0 @@ -/*********************************************************************** -An attempt at putting the ray-casting operation into CUDA -An attempt at putting the ray-casting operation into CUDA - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -***********************************************************************/ - -//extern __shared__ float array[]; - - -#define NUM_SAMPLES 25 -#define VINDEX(A,B,C) tg.data[((((A)+ci[0])*(tg.dims[1]+1)+((B)+ci[1]))*(tg.dims[2]+1)+ci[2]+(C))] - -#define fmin(A, B) ( A * (A < B) + B * (B < A) ) -#define fmax(A, B) ( A * (A > B) + B * (B > A) ) -#define fclip(A, B, C) ( fmax( fmin(A, C), B) ) - -struct transfer_function -{ - float vs[4][256]; - float dbin; - float bounds[2]; -}; - -__shared__ struct transfer_function tf; - -struct grid -{ - float left_edge[3]; - float right_edge[3]; - float dds[3]; - int dims[3]; - float *data; -}; - -__shared__ struct grid tg; - -__device__ float interpolate(float *cache, int *ds, int *ci, float *dp) -{ - int i; - float dv, dm[3]; - for(i=0;i<3;i++)dm[i] = (1.0 - dp[i]); - dv = 0.0; - dv += cache[0] * (dm[0]*dm[1]*dm[2]); - dv += cache[1] * (dm[0]*dm[1]*dp[2]); - dv += cache[2] * (dm[0]*dp[1]*dm[2]); - dv += cache[3] * (dm[0]*dp[1]*dp[2]); - dv += cache[4] * (dp[0]*dm[1]*dm[2]); - dv += cache[5] * (dp[0]*dm[1]*dp[2]); - dv += cache[6] * (dp[0]*dp[1]*dm[2]); - dv += cache[7] * (dp[0]*dp[1]*dp[2]); - return dv; -} - -__device__ void eval_transfer(float dt, float dv, float *rgba, - transfer_function &tf) -{ - int i, bin_id; - float temp, bv, dy, dd, ta; - - bin_id = (int) ((dv - tf.bounds[0]) / tf.dbin); - bv = tf.vs[3][bin_id ]; - dy = tf.vs[3][bin_id+1] - bv; - dd = dv - (tf.bounds[0] + bin_id*tf.dbin); - temp = bv+dd*(dy/tf.dbin); - ta = temp; - for (i = 0; i < 3; i++) - { - bv = tf.vs[i][bin_id ]; - dy = tf.vs[i][bin_id+1]; - dd = dv - (tf.bounds[0] + bin_id*tf.dbin); - temp = bv+dd*(dy/tf.dbin); - rgba[i] += (1.0 - rgba[3])*ta*temp*dt; - } - //rgba[3] += (1.0 - rgba[3])*ta*dt; -} - -__device__ void sample_values(float v_pos[3], float v_dir[3], - float enter_t, float exit_t, int ci[3], float rgba[4], - transfer_function &tf, grid &tg) -{ - float cp[3], dp[3], dt, t, dv; - int dti, i; - float cache[8]; - - cache[0] = VINDEX(0,0,0); - cache[1] = VINDEX(0,0,1); - cache[2] = VINDEX(0,1,0); - cache[3] = VINDEX(0,1,1); - cache[4] = VINDEX(1,0,0); - cache[5] = VINDEX(1,0,1); - cache[6] = VINDEX(1,1,0); - cache[7] = VINDEX(1,1,1); - - dt = (exit_t - enter_t) / (NUM_SAMPLES-1); - for (dti = 0; dti < NUM_SAMPLES - 1; dti++) - { - t = enter_t + dt*dti; - for (i = 0; i < 3; i++) - { - cp[i] = v_pos[i] + t * v_dir[i]; - dp[i] = fclip(fmod(cp[i], tg.dds[i])/tg.dds[i], 0.0, 1.0); - } - dv = interpolate(cache, tg.dims, ci, dp); - eval_transfer(dt, dv, rgba, tf); - } -} - - -/* We need to know several things if we want to ray cast through a grid. - We need the grid spatial information, as well as its values. We also need - the transfer function, which defines what our image will look like. */ - -__global__ void ray_cast(int ngrids, - float *grid_data, - int *dims, - float *left_edge, - float *right_edge, - float *tf_r, - float *tf_g, - float *tf_b, - float *tf_a, - float *tf_bounds, - float *v_dir, - float *av_pos, - float *image_r, - float *image_g, - float *image_b, - float *image_a) -{ - - int cur_ind[3], step[3], x, y, i, direction; - float intersect_t = 1.0, intersect_ts[3]; - float tmax[3]; - float tl, tr, temp_xl, temp_yl, temp_xr, temp_yr; - - int offset; - - //transfer_function tf; - for (i = 0; i < 4; i++) - { - x = 4 * (8 * threadIdx.x + threadIdx.y) + i; - tf.vs[0][x] = tf_r[x]; - tf.vs[1][x] = tf_g[x]; - tf.vs[2][x] = tf_b[x]; - tf.vs[3][x] = tf_a[x]; - } - - tf.bounds[0] = tf_bounds[0]; tf.bounds[1] = tf_bounds[1]; - tf.dbin = (tf.bounds[1] - tf.bounds[0])/255.0; - - /* Set up the grid, just for convenience */ - //grid tg; - int grid_i; - - int tidx = (blockDim.x * gridDim.x) * ( - blockDim.y * blockIdx.y + threadIdx.y) - + (blockDim.x * blockIdx.x + threadIdx.x); - - float rgba[4]; - //rgba[0] = image_r[tidx]; - //rgba[1] = image_g[tidx]; - //rgba[2] = image_b[tidx]; - //rgba[3] = image_a[tidx]; - - float v_pos[3]; - v_pos[0] = av_pos[tidx + 0]; - v_pos[1] = av_pos[tidx + 1]; - v_pos[2] = av_pos[tidx + 2]; - - tg.data = grid_data; - int skip; - for (i = 0; i < 3; i++) - { - step[i] = 0; - step[i] += (v_dir[i] > 0); - step[i] += -1 * (v_dir[i] < 0); - } - - for(grid_i = 0; grid_i < ngrids; grid_i++) { - skip = 0; - - if (threadIdx.x == 0) - { - if (threadIdx.y == 0) tg.dims[0] = dims[3*grid_i + 0]; - if (threadIdx.y == 1) tg.dims[1] = dims[3*grid_i + 1]; - if (threadIdx.y == 2) tg.dims[2] = dims[3*grid_i + 2]; - } - - if (threadIdx.x == 1) - { - if (threadIdx.y == 0) tg.left_edge[0] = left_edge[3*grid_i + 0]; - if (threadIdx.y == 1) tg.left_edge[1] = left_edge[3*grid_i + 1]; - if (threadIdx.y == 2) tg.left_edge[2] = left_edge[3*grid_i + 2]; - } - - if (threadIdx.x == 2) { - if (threadIdx.y == 0) tg.right_edge[0] = right_edge[3*grid_i + 0]; - if (threadIdx.y == 1) tg.right_edge[1] = right_edge[3*grid_i + 1]; - if (threadIdx.y == 2) tg.right_edge[2] = right_edge[3*grid_i + 2]; - } - - if (threadIdx.x == 3) { - if (threadIdx.y == 0) tg.dds[0] = (tg.right_edge[0] - tg.left_edge[0])/tg.dims[0]; - if (threadIdx.y == 1) tg.dds[1] = (tg.right_edge[1] - tg.left_edge[1])/tg.dims[1]; - if (threadIdx.y == 2) tg.dds[2] = (tg.right_edge[2] - tg.left_edge[2])/tg.dims[2]; - } - - /* We integrate our ray */ - - for (i = 0; i < 3; i++) - { - x = (i + 1) % 3; - y = (i + 2) % 3; - - tl = (tg.left_edge[i] - v_pos[i])/v_dir[i]; - temp_xl = (v_pos[i] + tl*v_dir[x]); - temp_yr = (v_pos[i] + tl*v_dir[y]); - - tr = (tg.right_edge[i] - v_pos[i])/v_dir[i]; - temp_xr = (v_pos[x] + tr*v_dir[x]); - temp_yr = (v_pos[y] + tr*v_dir[y]); - - intersect_ts[i] = 1.0; - - intersect_ts[i] += - ( (tg.left_edge[x] <= temp_xl) && - (temp_xl <= tg.right_edge[x]) && - (tg.left_edge[y] <= temp_yl) && - (temp_yl <= tg.right_edge[y]) && - (0.0 <= tl) && (tl < intersect_ts[i]) && (tl < tr) ) * tl; - - intersect_ts[i] += - ( (tg.left_edge[x] <= temp_xr) && - (temp_xr <= tg.right_edge[x]) && - (tg.left_edge[y] <= temp_yr) && - (temp_yr <= tg.right_edge[y]) && - (0.0 <= tr) && (tr < intersect_ts[i]) && (tr < tl) ) * tr; - - intersect_t = ( intersect_ts[i] < intersect_t) * intersect_ts[i]; - - } - - intersect_t *= (!( (tg.left_edge[0] <= v_pos[0]) && - (v_pos[0] <= tg.right_edge[0]) && - (tg.left_edge[0] <= v_pos[0]) && - (v_pos[0] <= tg.right_edge[0]) && - (tg.left_edge[0] <= v_pos[0]) && - (v_pos[0] <= tg.right_edge[0]))); - - skip = ((intersect_t < 0) || (intersect_t > 1.0)); - - for (i = 0; i < 3; i++) - { - cur_ind[i] = (int) floor(((v_pos[i] + intersect_t * v_dir[i]) + - step[i]*1e-7*tg.dds[i] - - tg.left_edge[i])/tg.dds[i]); - tmax[i] = (((cur_ind[i]+step[i])*tg.dds[i])+ - tg.left_edge[i]-v_pos[i])/v_dir[i]; - cur_ind[i] -= ((cur_ind[i] == tg.dims[i]) && (step[i] < 0)); - skip = ((cur_ind[i] < 0) || (cur_ind[i] >= tg.dims[i])); - offset = (step[i] > 0); - tmax[i] = (((cur_ind[i]+offset)*tg.dds[i])+tg.left_edge[i]-v_pos[i])/v_dir[i]; - } - - /* This is the primary grid walking loop */ - while(!( (skip) - ||((cur_ind[0] < 0) || (cur_ind[0] >= tg.dims[0]) - || (cur_ind[1] < 0) || (cur_ind[1] >= tg.dims[1]) - || (cur_ind[2] < 0) || (cur_ind[2] >= tg.dims[2])))) - { - direction = 0; - direction += 2 * (tmax[0] < tmax[1]) * (tmax[0] >= tmax[2]); - direction += 1 * (tmax[0] >= tmax[1]) * (tmax[1] < tmax[2]); - direction += 2 * (tmax[0] >= tmax[1]) * (tmax[1] >= tmax[2]); - sample_values(v_pos, v_dir, intersect_t, tmax[direction], - cur_ind, rgba, tf, tg); - cur_ind[direction] += step[direction]; - intersect_t = tmax[direction]; - tmax[direction] += abs(tg.dds[direction]/v_dir[direction]); - } - - tg.data += (tg.dims[0]+1) * (tg.dims[1]+1) * (tg.dims[2]+1); - - } - - int iy = threadIdx.y + blockDim.y * blockIdx.y; - int ix = threadIdx.x + blockDim.x * blockIdx.x; - __syncthreads(); - - image_r[tidx] = rgba[0]; - image_g[tidx] = rgba[1]; - image_b[tidx] = rgba[2]; - image_a[tidx] = rgba[3]; -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/camera.py --- a/yt/extensions/volume_rendering/camera.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,293 +0,0 @@ -""" -Import the components of the volume rendering extension - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as na -from grid_partitioner import HomogenizedVolume -from transfer_functions import ProjectionTransferFunction -from yt.funcs import * -import yt.amr_utils as au - -class Camera(object): - def __init__(self, center, normal_vector, width, - resolution, transfer_function, - north_vector = None, - volume = None, fields = None, - log_fields = None, - sub_samples = 5, pf = None): - r"""A viewpoint into a volume, for volume rendering. - - The camera represents the eye of an observer, which will be used to - generate ray-cast volume renderings of the domain. - - Parameters - ---------- - center : array_like - The current "center" of the view port -- the focal point for the - camera. - normal_vector : array_like - The vector between the camera position and the center. - width : float or list of floats - The current width of the image. If a single float, the volume is - cubical, but if not, it is front/back, left/right, top/bottom. - resolution : int or list of ints - The number of pixels in each direction. - north_vector : array_like, optional - The "up" direction for the plane of rays. If not specific, calculated - automatically. - volume : `yt.extensions.volume_rendering.HomogenizedVolume`, optional - The volume to ray cast through. Can be specified for finer-grained - control, but otherwise will be automatically generated. - fields : list of fields, optional - This is the list of fields we want to volume render; defaults to - Density. - log_fields : list of bool, optional - Whether we should take the log of the fields before supplying them to - the volume rendering mechanism. - sub_samples : int, optional - The number of samples to take inside every cell per ray. - pf : `~yt.lagos.StaticOutput` - For now, this is a require parameter! But in the future it will become - optional. This is the parameter file to volume render. - - Examples - -------- - - >>> cam = vr.Camera(c, L, W, (N,N), transfer_function = tf, pf = pf) - >>> image = cam.snapshot() - """ - if pf is not None: self.pf = pf - if not iterable(resolution): - resolution = (resolution, resolution) - self.resolution = resolution - self.sub_samples = sub_samples - if not iterable(width): - width = (width, width, width) # front/back, left/right, top/bottom - self.width = width - self.center = center - if fields is None: fields = ["Density"] - self.fields = fields - if transfer_function is None: - transfer_function = ProjectionTransferFunction() - self.transfer_function = transfer_function - self._setup_normalized_vectors(normal_vector, north_vector) - self.log_fields = log_fields - if volume is None: - volume = HomogenizedVolume(fields, pf = self.pf, - log_fields = log_fields) - self.volume = volume - - def _setup_normalized_vectors(self, normal_vector, north_vector): - # Now we set up our various vectors - normal_vector /= na.sqrt( na.dot(normal_vector, normal_vector)) - if north_vector is None: - vecs = na.identity(3) - t = na.cross(normal_vector, vecs).sum(axis=1) - ax = t.argmax() - north_vector = na.cross(vecs[ax,:], normal_vector).ravel() - north_vector /= na.sqrt(na.dot(north_vector, north_vector)) - east_vector = -na.cross(north_vector, normal_vector).ravel() - east_vector /= na.sqrt(na.dot(east_vector, east_vector)) - self.unit_vectors = [north_vector, east_vector, normal_vector] - self.box_vectors = na.array([self.unit_vectors[0]*self.width[0], - self.unit_vectors[1]*self.width[1], - self.unit_vectors[2]*self.width[2]]) - - self.origin = self.center - 0.5*self.width[0]*self.unit_vectors[0] \ - - 0.5*self.width[1]*self.unit_vectors[1] \ - - 0.5*self.width[2]*self.unit_vectors[2] - self.back_center = self.center - 0.5*self.width[0]*self.unit_vectors[2] - self.front_center = self.center + 0.5*self.width[0]*self.unit_vectors[2] - self.inv_mat = na.linalg.pinv(self.unit_vectors) - - def look_at(self, new_center, north_vector = None): - r"""Change the view direction based on a new focal point. - - This will recalculate all the necessary vectors and vector planes related - to a camera to point at a new location. - - Parameters - ---------- - new_center : array_like - The new "center" of the view port -- the focal point for the - camera. - north_vector : array_like, optional - The "up" direction for the plane of rays. If not specific, - calculated automatically. - """ - normal_vector = self.front_center - new_center - self._setup_normalized_vectors(normal_vector, north_vector) - - def get_vector_plane(self, image): - # We should move away from pre-generation of vectors like this and into - # the usage of on-the-fly generation in the VolumeIntegrator module - # We might have a different width and back_center - px = na.linspace(-self.width[0]/2.0, self.width[0]/2.0, - self.resolution[0])[:,None] - py = na.linspace(-self.width[1]/2.0, self.width[1]/2.0, - self.resolution[1])[None,:] - inv_mat = self.inv_mat - bc = self.back_center - positions = na.zeros((self.resolution[0], self.resolution[1], 3), - dtype='float64', order='C') - positions[:,:,0] = inv_mat[0,0]*px+inv_mat[0,1]*py+self.back_center[0] - positions[:,:,1] = inv_mat[1,0]*px+inv_mat[1,1]*py+self.back_center[1] - positions[:,:,2] = inv_mat[2,0]*px+inv_mat[2,1]*py+self.back_center[2] - bounds = (px.min(), px.max(), py.min(), py.max()) - vector_plane = au.VectorPlane(positions, self.box_vectors[2], - self.back_center, bounds, image, - self.unit_vectors[0], - self.unit_vectors[1]) - return vector_plane - - def snapshot(self): - r"""Ray-cast the camera. - - This method instructs the camera to take a snapshot -- i.e., call the ray - caster -- based on its current settings. - - Returns - ------- - image : array - An (N,M,3) array of the final returned values, in float64 form. - """ - image = na.zeros((self.resolution[0], self.resolution[1], 3), - dtype='float64', order='C') - vector_plane = self.get_vector_plane(image) - tfp = au.TransferFunctionProxy(self.transfer_function) # Reset it every time - tfp.ns = self.sub_samples - self.volume.initialize_source() - pbar = get_pbar("Ray casting", - (self.volume.brick_dimensions + 1).prod(axis=-1).sum()) - total_cells = 0 - for brick in self.volume.traverse(self.back_center, self.front_center): - brick.cast_plane(tfp, vector_plane) - total_cells += na.prod(brick.my_data[0].shape) - pbar.update(total_cells) - pbar.finish() - return image - - def zoom(self, factor): - r"""Change the distance to the focal point. - - This will zoom the camera in by some `factor` toward the focal point, - along the current view direction, modifying the left/right and up/down - extents as well. - - Parameters - ---------- - factor : float - The factor by which to reduce the distance to the focal point. - - - Notes - ----- - - You will need to call snapshot() again to get a new image. - - """ - self.width = [w / factor for w in self.width] - self._setup_normalized_vectors( - self.unit_vectors[2], self.unit_vectors[0]) - - def zoomin(self, final, n_steps): - r"""Loop over a zoomin and return snapshots along the way. - - This will yield `n_steps` snapshots until the current view has been - zooming in to a final factor of `final`. - - Parameters - ---------- - final : float - The zoom factor, with respect to current, desired at the end of the - sequence. - n_steps : int - The number of zoom snapshots to make. - - - Examples - -------- - - >>> for i, snapshot in enumerate(cam.zoomin(100.0, 10)): - ... iw.write_bitmap(snapshot, "zoom_%04i.png" % i) - """ - f = final**(1.0/n_steps) - for i in xrange(n_steps): - self.zoom(f) - yield self.snapshot() - - -class PerspectiveCamera(Camera): - def get_vector_plane(self, image): - # We should move away from pre-generation of vectors like this and into - # the usage of on-the-fly generation in the VolumeIntegrator module - # We might have a different width and back_center - px = na.linspace(-self.width[0]/2.0, self.width[0]/2.0, - self.resolution[0])[:,None] - py = na.linspace(-self.width[1]/2.0, self.width[1]/2.0, - self.resolution[1])[None,:] - inv_mat = self.inv_mat - bc = self.back_center - positions = na.zeros((self.resolution[0], self.resolution[1], 3), - dtype='float64', order='C') - positions[:,:,0] = inv_mat[0,0]*px+inv_mat[0,1]*py+self.back_center[0] - positions[:,:,1] = inv_mat[1,0]*px+inv_mat[1,1]*py+self.back_center[1] - positions[:,:,2] = inv_mat[2,0]*px+inv_mat[2,1]*py+self.back_center[2] - bounds = (px.min(), px.max(), py.min(), py.max()) - - # We are likely adding on an odd cutting condition here - vectors = self.front_center - positions - n = vectors * vectors - n = na.sum(n, axis=2)**0.5 - vectors /= n[:,:,None] - print vectors.shape, vectors.dtype, vectors.flags - - vector_plane = au.VectorPlane(positions, vectors, - self.back_center, bounds, image, - self.unit_vectors[0], - self.unit_vectors[1]) - return vector_plane - -class StereoPairCamera(Camera): - def __init__(self, original_camera, relative_separation = 0.005): - self.original_camera = original_camera - self.relative_separation = relative_separation - - def split(self): - oc = self.original_camera - uv = oc.unit_vectors - c = oc.center - fc = oc.front_center - wx, wy, wz = oc.width - left_normal = fc + uv[1] * 0.5*self.relative_separation * wx - c - right_normal = fc - uv[1] * 0.5*self.relative_separation * wx - c - left_camera = Camera(c, left_normal, oc.width, - oc.resolution, oc.transfer_function, uv[0], - oc.volume, oc.fields, oc.log_fields, - oc.sub_samples, oc.pf) - right_camera = Camera(c, right_normal, oc.width, - oc.resolution, oc.transfer_function, uv[0], - oc.volume, oc.fields, oc.log_fields, - oc.sub_samples, oc.pf) - return (left_camera, right_camera) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/grid_partitioner.py --- a/yt/extensions/volume_rendering/grid_partitioner.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,398 +0,0 @@ -""" -Import the components of the volume rendering extension - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as na -from yt.funcs import * -import h5py - -from yt.amr_utils import PartitionedGrid, ProtoPrism, GridFace, \ - grid_points_in_volume, find_grids_in_inclined_box -from yt.lagos import ParallelAnalysisInterface, only_on_root, parallel_root_only -from yt.parallel_tools import DistributedObjectCollection - -# HISTORICAL NOTE OF SOME IMPORT: -# The homogenized brick class should and will be removed. The more general, -# and less fancy-parallel, HomogenizedVolume is the way to go. The HBC is a -# complicated mechanism that was designed for back when we were going to be -# passing bricks all around between processors. - -class HomogenizedVolume(ParallelAnalysisInterface): - bricks = None - def __init__(self, fields = "Density", source = None, pf = None, - log_fields = None): - # Typically, initialized as hanging off a hierarchy. But, not always. - if pf is not None: self.pf = pf - if source is None: source = self.pf.h.all_data() - self.source = source - self.fields = ensure_list(fields) - if log_fields is not None: - log_fields = ensure_list(log_fields) - else: - log_fields = [self.pf.field_info[field].take_log - for field in self.fields] - self.log_fields = log_fields - - def traverse(self, back_point, front_point): - mylog.info("Traversing %s bricks between %s and %s", - len(self.bricks), back_point, front_point) - if self.bricks is None: self.initialize_source() - vec = front_point - back_point - dist = na.minimum( - na.sum((self.brick_left_edges - back_point) * vec, axis=1), - na.sum((self.brick_right_edges - back_point) * vec, axis=1)) - ind = na.argsort(dist) - for b in self.bricks[ind]: - #print b.LeftEdge, b.RightEdge - yield b - - def _partition_grid(self, grid): - - # This is not super efficient, as it re-fills the regions once for each - # field. - vcds = [] - for field, log_field in zip(self.fields, self.log_fields): - vcd = grid.get_vertex_centered_data(field).astype('float64') - if log_field: vcd = na.log10(vcd) - vcds.append(vcd) - - GF = GridFaces(grid.Children + [grid]) - PP = ProtoPrism(grid.id, grid.LeftEdge, grid.RightEdge, GF) - - pgs = [] - for P in PP.sweep(0): - sl = P.get_brick(grid.LeftEdge, grid.dds, grid.child_mask) - if len(sl) == 0: continue - dd = [d[sl[0][0]:sl[0][1]+1, - sl[1][0]:sl[1][1]+1, - sl[2][0]:sl[2][1]+1].copy() for d in vcds] - pgs.append(PartitionedGrid(grid.id, len(self.fields), dd, - P.LeftEdge, P.RightEdge, sl[-1])) - return pgs - - def initialize_source(self, source = None): - if self.bricks is not None and source is not None: - raise NotImplementedError("Sorry, dynamic shuffling of bricks is" + - " not yet supported") - if self.bricks is not None and source is None: return - bricks = [] - self._preload(self.source._grids, self.fields, self.pf.h.io) - pbar = get_pbar("Partitioning ", len(self.source._grids)) - for i, g in enumerate(self.source._grids): - pbar.update(i) - bricks += self._partition_grid(g) - pbar.finish() - bricks = na.array(bricks, dtype='object') - self.initialize_bricks(bricks) - - def initialize_bricks(self, bricks): - NB = len(bricks) - # Now we set up our (local for now) hierarchy. Note that to calculate - # intersection, we only need to do the left edge & right edge. - # - # We're going to double up a little bit here in memory. - self.brick_left_edges = na.zeros( (NB, 3), dtype='float64') - self.brick_right_edges = na.zeros( (NB, 3), dtype='float64') - self.brick_parents = na.zeros( NB, dtype='int64') - self.brick_dimensions = na.zeros( (NB, 3), dtype='int64') - for i,b in enumerate(bricks): - self.brick_left_edges[i,:] = b.LeftEdge - self.brick_right_edges[i,:] = b.RightEdge - self.brick_parents[i] = b.parent_grid_id - self.brick_dimensions[i,:] = b.my_data[0].shape - # Vertex-centered means we subtract one from the shape - self.brick_dimensions -= 1 - self.bricks = na.array(bricks, dtype='object') - - def reflect_across_boundaries(self): - mylog.warning("Note that this doesn't fix ghost zones, so there may be artifacts at domain boundaries!") - nb = [] - # Simplest, clearest iteration ... - for i in [-1, 1]: - for j in [-1, 1]: - for k in [-1, 1]: - for b in self.bricks: - BB = na.array([b.LeftEdge * [i,j,k], b.RightEdge * [i,j,k]]) - LE, RE = na.min(BB, axis=0), na.max(BB, axis=0) - nb.append( - PartitionedGrid(b.parent_grid_id, len(b.my_data), - [md[::i,::j,::k].copy("C") for md in b.my_data], - LE, RE, na.array(b.my_data[0].shape) - 1)) - # Replace old bricks - self.initialize_bricks(nb) - - def store_bricks(self, fn): - import h5py, cPickle - f = h5py.File(fn, "w") - f.create_dataset("/left_edges", data=self.brick_left_edges) - f.create_dataset("/right_edges", data=self.brick_right_edges) - f.create_dataset("/parents", data=self.brick_parents) - f.create_dataset("/dimensions", data=self.brick_dimensions) - f.create_group("/bricks") - for i,b in enumerate(self.bricks): - f.create_group("/bricks/brick_%08i" % i) - for fi,field in enumerate(self.fields): - f.create_dataset("/bricks/brick_%08i/%s" % (i, field), - data=b.my_data[fi]) - f.close() - - def load_bricks(self, fn): - import h5py - f = h5py.File(fn, "r") - self.brick_left_edges = f["/left_edges"][:] - self.brick_right_edges = f["/right_edges"][:] - self.brick_parents = f["/parents"][:] - self.brick_dimensions= f["/dimensions"][:] - bricks = [] - for i,ds in enumerate(sorted(f["/bricks"])): - td = [f["/bricks/%s/%s" % (ds, field)][:] for field in self.fields] - bricks.append(PartitionedGrid( - self.brick_parents[i], len(td), td, - self.brick_left_edges[i,:], - self.brick_right_edges[i,:], - self.brick_dimensions[i,:], - )) - self.bricks = na.array(bricks, dtype='object') - -class HomogenizedBrickCollection(DistributedObjectCollection): - def __init__(self, source): - # The idea here is that we have two sources -- the global_domain - # source, which would be a decomposition of the 3D domain, and a - # local_domain source, which is the set of bricks we want at the end. - self.source = source - self.pf = source.pf - - @classmethod - def load_bricks(self, base_filename): - pass - - def write_my_bricks(self, base_filename): - pass - - def store_bricks(self, base_filename): - pass - - @parallel_root_only - def write_hierarchy(self, base_filename): - pass - - def _partition_grid(self, grid, fields, log_field = None): - fields = ensure_list(fields) - if log_field is None: log_field = [True] * len(fields) - - # This is not super efficient, as it re-fills the regions once for each - # field. - vcds = [] - for i,field in enumerate(fields): - vcd = grid.get_vertex_centered_data(field).astype('float64') - if log_field[i]: vcd = na.log10(vcd) - vcds.append(vcd) - - GF = GridFaces(grid.Children + [grid]) - PP = ProtoPrism(grid.id, grid.LeftEdge, grid.RightEdge, GF) - - pgs = [] - for P in PP.sweep(0): - sl = P.get_brick(grid.LeftEdge, grid.dds, grid.child_mask) - if len(sl) == 0: continue - dd = [d[sl[0][0]:sl[0][1]+1, - sl[1][0]:sl[1][1]+1, - sl[2][0]:sl[2][1]+1].copy() for d in vcds] - pgs.append(PartitionedGrid(grid.id, len(fields), dd, - P.LeftEdge, P.RightEdge, sl[-1])) - return pgs - - def _partition_local_grids(self, fields = "Density", log_field = None): - fields = ensure_list(fields) - bricks = [] - # We preload. - # UNCOMMENT FOR PARALLELISM - #grid_list = list(self._get_grid_objs()) - grid_list = list(self.source._grids) - self._preload(grid_list, fields, self.pf.h.io) - pbar = get_pbar("Partitioning ", len(grid_list)) - # UNCOMMENT FOR PARALLELISM - #for i, g in enumerate(self._get_grids()): - print "THIS MANY GRIDS!", len(grid_list) - for i, g in enumerate(self.source._grids): - pbar.update(i) - bricks += self._partition_grid(g, fields, log_field) - pbar.finish() - bricks = na.array(bricks, dtype='object') - NB = len(bricks) - # Now we set up our (local for now) hierarchy. Note that to calculate - # intersection, we only need to do the left edge & right edge. - # - # We're going to double up a little bit here in memory. - self.brick_left_edges = na.zeros( (NB, 3), dtype='float64') - self.brick_right_edges = na.zeros( (NB, 3), dtype='float64') - self.brick_parents = na.zeros( NB, dtype='int64') - self.brick_dimensions = na.zeros( (NB, 3), dtype='int64') - self.brick_owners = na.ones(NB, dtype='int32') * self._mpi_get_rank() - self._object_owners = self.brick_owners - for i,b in enumerate(bricks): - self.brick_left_edges[i,:] = b.LeftEdge - self.brick_right_edges[i,:] = b.RightEdge - self.brick_parents[i] = b.parent_grid_id - self.brick_dimensions[i,:] = b.my_data[0].shape - # Vertex-centered means we subtract one from the shape - self.brick_dimensions -= 1 - self.bricks = na.array(bricks, dtype='object') - # UNCOMMENT FOR PARALLELISM - #self.join_lists() - - def _get_object_info(self): - # We transpose here for the catdict operation - info_dict = dict(left_edges = self.brick_left_edges.transpose(), - right_edges = self.brick_right_edges.transpose(), - parents = self.brick_parents, - owners = self.brick_owners, - dimensions = self.brick_dimensions.transpose(),) - return info_dict - - def _set_object_info(self, info_dict): - self.brick_left_edges = info_dict.pop("left_edges").transpose() - self.brick_right_edges = info_dict.pop("right_edges").transpose() - self.brick_parents = info_dict.pop("parents") - self.brick_dimensions = info_dict.pop("dimensions").transpose() - self.brick_owners = info_dict.pop("owners") - self._object_owners = self.brick_owners - bricks = self.bricks - self.bricks = na.array([None] * self.brick_owners.size, dtype='object') - # Copy our bricks back in - self.bricks[self.brick_owners == self._mpi_get_rank()] = bricks[:] - - def _create_buffer(self, ind_list): - # Note that we have vertex-centered data, so we add one before taking - # the prod and the sum - total_size = (self.brick_dimensions[ind_list,:] + 1).prod(axis=1).sum() - mylog.debug("Creating buffer for %s bricks (%s)", - len(ind_list), total_size) - my_buffer = na.zeros(total_size, dtype='float64') - return my_buffer - - def _pack_buffer(self, ind_list, my_buffer): - si = 0 - for index in ind_list: - d = self.bricks[index].my_data.ravel() - my_buffer[si:si+d.size] = d[:] - si += d.size - - def _unpack_buffer(self, ind_list, my_buffer): - si = 0 - for index in ind_list: - pgi = self.brick_parents[index] - LE = self.brick_left_edges[index,:].copy() - RE = self.brick_right_edges[index,:].copy() - dims = self.brick_dimensions[index,:].copy() - size = (dims + 1).prod() - data = my_buffer[si:si+size].reshape(dims + 1) - self.bricks[index] = PartitionedGrid( - pgi, data, LE, RE, dims) - si += size - - def _wipe_objects(self, indices): - self.bricks[indices] = None - - def _collect_bricks(self, intersection_source): - if not self._distributed: return - # This entire routine should instead be set up to do: - # alltoall broadcast of the *number* of requested bricks - # non-blocking receives posted for int arrays - # sizes of data calculated - # concatenated data receives posted - # send all data - # get bricks back - # This presupposes that we are using the AMRInclinedBox as a data - # source. If we're not, we ought to be. - needed_brick_i = find_grids_in_inclined_box( - intersection_source.box_vectors, intersection_source.center, - self.brick_left_edges, self.brick_right_edges) - needed_brick_i = na.where(needed_brick_i)[0] - self._collect_objects(needed_brick_i) - - def _initialize_parallel(self): - pass - - def _finalize_parallel(self): - pass - - def get_brick(self, brick_id): - pass - - @property - def _grids(self): - return self.source._grids - -class GridFaces(object): - def __init__(self, grids): - self.faces = [ [], [], [] ] - for grid in grids: - for direction in range(3): - self.faces[direction].append( GridFace(grid, direction, 1) ) - self.faces[direction].append( GridFace(grid, direction, 0) ) - for f in self.faces: - f.sort(key = lambda a: a.coord) - - def __getitem__(self, item): - return self.faces[item] - -def export_partitioned_grids(grid_list, fn, int_type=na.int64, float_type=na.float64): - f = h5py.File(fn, "w") - pbar = get_pbar("Writing Grids", len(grid_list)) - nelem = sum((grid.my_data.size for grid in grid_list)) - ngrids = len(grid_list) - group = f.create_group("/PGrids") - left_edge = na.concatenate([[grid.LeftEdge,] for grid in grid_list]) - f.create_dataset("/PGrids/LeftEdges", data=left_edge, dtype=float_type); del left_edge - right_edge = na.concatenate([[grid.RightEdge,] for grid in grid_list]) - f.create_dataset("/PGrids/RightEdges", data=right_edge, dtype=float_type); del right_edge - dims = na.concatenate([[grid.my_data.shape[:],] for grid in grid_list]) - f.create_dataset("/PGrids/Dims", data=dims, dtype=int_type); del dims - data = na.concatenate([grid.my_data.ravel() for grid in grid_list]) - f.create_dataset("/PGrids/Data", data=data, dtype=float_type); del data - f.close() - pbar.finish() - -def import_partitioned_grids(fn, int_type=na.int64, float_type=na.float64): - f = h5py.File(fn, "r") - n_groups = len(f.listnames()) - grid_list = [] - dims = f["/PGrids/Dims"][:].astype(int_type) - left_edges = f["/PGrids/LeftEdges"][:].astype(float_type) - right_edges = f["/PGrids/RightEdges"][:].astype(float_type) - data = f["/PGrids/Data"][:].astype(float_type) - pbar = get_pbar("Reading Grids", dims.shape[0]) - curpos = 0 - for i in xrange(dims.shape[0]): - gd = dims[i,:] - gle, gre = left_edges[i,:], right_edges[i,:] - gdata = data[curpos:curpos+gd.prod()].reshape(gd) - # Vertex -> Grid, so we -1 from dims in this - grid_list.append(PartitionedGrid(-1, gdata, gle, gre, gd - 1)) - curpos += gd.prod() - pbar.update(i) - pbar.finish() - f.close() - return na.array(grid_list, dtype='object') diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/image_handling.py --- a/yt/extensions/volume_rendering/image_handling.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -""" -Export/Import of volume rendered images. - -Author: Samuel Skillman -Affiliation: University of Colorado at Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2010 Samuel Skillman. 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 . -""" -import numpy as na -import matplotlib; from matplotlib import pylab -from yt.extensions.volume_rendering import * -from yt.funcs import * -import h5py -try: import pyfits -except: pass - -def export_rgba(image, fn, h5=True, fits=False, ): - """ - This function accepts an *image*, of shape (N,M,4) corresponding to r,g,b,a, - and saves to *fn*. If *h5* is True, then it will save in hdf5 format. If - *fits* is True, it will save in fits format. - """ - if h5: - f = h5py.File('%s.h5'%fn, "w") - f.create_dataset("R", data=image[:,:,0]) - f.create_dataset("G", data=image[:,:,1]) - f.create_dataset("B", data=image[:,:,2]) - f.create_dataset("A", data=image[:,:,3]) - f.close() - if fits: - try: - hdu = pyfits.PrimaryHDU(image[:,:,0]) - hdulist = pyfits.HDUList([hdu]) - hdulist.writeto('%s_r.fits'%fn,clobber=True) - hdu = pyfits.PrimaryHDU(image[:,:,1]) - hdulist = pyfits.HDUList([hdu]) - hdulist.writeto('%s_g.fits'%fn,clobber=True) - hdu = pyfits.PrimaryHDU(image[:,:,2]) - hdulist = pyfits.HDUList([hdu]) - hdulist.writeto('%s_b.fits'%fn,clobber=True) - hdu = pyfits.PrimaryHDU(image[:,:,3]) - hdulist = pyfits.HDUList([hdu]) - hdulist.writeto('%s_a.fits'%fn,clobber=True) - except: print 'You do not have pyfits, install before attempting to use fits exporter' - -def import_rgba(name, h5=True): - """ - This function will read back in an HDF5 file, as saved by export_rgba, and - return the frames to the user. *name* is the name of the file to be read - in. - """ - if h5: - f = h5py.File(name, "r") - r = f['R'].value - g = f['G'].value - b = f['B'].value - a = f['A'].value - else: - print 'No support for fits import.' - return na.array([r,g,b,a]).swapaxes(0,2).swapaxes(0,1) - -def plot_channel(image, name, cmap='gist_heat', log=True, dex=3, zero_factor=1.0e-10, - label=None, label_color='w', label_size='large'): - """ - This function will plot a single channel. *image* is an array shaped like - (N,M), *name* is the pefix for the output filename. *cmap* is the name of - the colormap to apply, *log* is whether or not the channel should be - logged. Additionally, you may optionally specify the minimum-value cutoff - for scaling as *dex*, which is taken with respect to the minimum value of - the image. *zero_factor* applies a minimum value to all zero-valued - elements. Optionally, *label*, *label_color* and *label_size* may be - specified. - """ - Nvec = image.shape[0] - image[na.isnan(image)] = 0.0 - ma = image[image>0.0].max() - image[image==0.0] = ma*zero_factor - if log: - mynorm = matplotlib.colors.LogNorm(ma/(10.**dex), ma) - - pylab.clf() - pylab.gcf().set_dpi(100) - pylab.gcf().set_size_inches((Nvec/100.0, Nvec/100.0)) - pylab.gcf().subplots_adjust(left=0.0, right=1.0, bottom=0.0, top=1.0, wspace=0.0, hspace=0.0) - mycm = pylab.cm.get_cmap(cmap) - if log: - pylab.imshow(image,cmap=mycm, norm=mynorm, interpolation='nearest') - else: - pylab.imshow(image,cmap=mycm, interpolation='nearest') - if label is not None: - pylab.text(20, 20,label, color = label_color, size=label_size) - pylab.savefig("%s_%s.png" % (name,cmap)) - pylab.clf() - -def plot_rgb(image, name, label=None, label_color='w', label_size='large'): - """ - This will plot the r,g,b channels of an *image* of shape (N,M,3) or - (N,M,4). *name* is the prefix of the file name, which will be supplemented - with "_rgb.png." *label*, *label_color* and *label_size* may also be - specified. - """ - Nvec = image.shape[0] - image[na.isnan(image)] = 0.0 - if image.shape[2] >= 4: - image = image[:,:,:3] - pylab.clf() - pylab.gcf().set_dpi(100) - pylab.gcf().set_size_inches((Nvec/100.0, Nvec/100.0)) - pylab.gcf().subplots_adjust(left=0.0, right=1.0, bottom=0.0, top=1.0, wspace=0.0, hspace=0.0) - pylab.imshow(image, interpolation='nearest') - if label is not None: - pylab.text(20, 20, label, color = label_color, size=label_size) - pylab.savefig("%s_rgb.png" % name) - pylab.clf() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/multi_texture.py --- a/yt/extensions/volume_rendering/multi_texture.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,302 +0,0 @@ -""" -A first-pass at a VisVis-based interactive viewer. - -Hi Matt, - -You could define your MultiTexture object (which would be a Wobject) and use -multiple visvis.textures.TextureObject instances to represent the sub-textures. -This TextureObject class is not a Wobject, but simply of a wrapper around an -OpenGl texture that handles uploading, updating, etc. - -The MultiTexture object you could derive from BaseTexture or maybe even -Texture3D if your data is 3D. Or maybe just from Wobject if this makes more -sense. Also, the visvis.textures.TextureObjectToVisualize might be used instead -of the TextureObject class. - -I mentioned a lot of texture classes, let's make a small list: - * TextureObject - wraps an OpenGl texture - * TextureObjectToVisualize(TextureObject) - implements intensity scaling - (what is changed with the clim property) - * BaseTexture(Wobject) - the base visvis Wobject class to represent textures. - It *contains* one TextureObjectToVisualize and has several properties to - influence it's appearance. * Texture2D(BaseTexture) - Implementation for 2D - textures. - * Texture3D(BaseTexture) - Implementation for 3D textures. - * YourNewMultiTexture(BaseTexture or ...) - contains multiple - TextureObjectToVisualize or TextureObject instances. - -This is I think the most sensible way to go about this. - -Now in the OnDraw method, you can draw the textures one by one using the same -settings. Or if you want a single draw in which you combine the information -from all textures to determine the final color, you should write a new glsl -shader to which you pass all textures. - -I hope this helps, - Almar -""" -from yt.mods import * -from yt.funcs import * - -import visvis as vv -import visvis.textures as vvt - -import OpenGL.GL as gl -import OpenGL.GL.ARB.shader_objects as gla -import OpenGL.GLU as glu - -import numpy as np - -class MultipleTexture(vv.Wobject): - def __init__(self, parent, data, global_size, renderStyle='mip'): - vv.Wobject.__init__(self, parent) - - self._global_size = global_size - - # create colormap - self._colormap = vvt.Colormap() - - # create glsl program for this texture... - self._program1 = program = vvt.GlslProgram() - - # scale and translation transforms - self._trafo_scale = vv.Transform_Scale() - self._trafo_trans = vv.Transform_Translate() - self.transformations.append(self._trafo_trans) - self.transformations.append(self._trafo_scale) - - data = ensure_list(data) - self._textures = [] - self._quads = {} - for obj in data: - tex = vvt.TextureObjectToVisualize(3, obj) - self._textures.append(tex) - tex.SetData(obj) - self._program1.SetVertexShader(vvt.vshaders['calculateray']) - self._program1.SetFragmentShader(vvt.fshaders['mip']) - self._renderStyle = '' - self.renderStyle = renderStyle - if not self._renderStyle: - self.renderStyle = 'mip' - self._quadlists = None - - def OnDrawShape(self, clr): - gl.glColor(clr[0], clr[1], clr[2], 1.0) - self._DrawQuads() - - def OnDraw(self, fast=False): - # Prepare by setting things to their defaults. This might release some - # memory so result in a bigger chance that the shader is run in - # hardware mode. On ATI, the line and point smoothing should be off - # if you want to use gl_FragCoord. (Yeah, I do not see the connection - # either...) - gl.glPointSize(1) - gl.glLineWidth(1) - gl.glDisable(gl.GL_LINE_STIPPLE) - gl.glDisable(gl.GL_LINE_SMOOTH) - gl.glDisable(gl.GL_POINT_SMOOTH) - - # only draw front-facing parts - gl.glEnable(gl.GL_CULL_FACE) - gl.glCullFace(gl.GL_BACK) - gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE) - gl.glBlendEquation(gl.GL_MAX) - gl.glDisable(gl.GL_DEPTH_TEST) - - if self._program1.IsUsable(): - self._program1.Enable() - - if fast: - self._program1.SetUniformf('stepRatio', [0.4]) - else: - self._program1.SetUniformf('stepRatio', [1.0]) - - self._program1.SetUniformi('texture', [0]) - self._colormap.Enable(1) - self._program1.SetUniformi('colormap', [1]) - - # enable this texture - t1 = time.time() - for i,tex in enumerate(self._textures): - - tex.Enable(0) - - if not tex._shape: - continue - - # fragment shader on - - # bind texture- and help-textures (create if it does not exist) - - # set uniforms: parameters - shape = tex._shape # as in opengl - self._program1.SetUniformf('shape',reversed(list(shape)) ) - - # do the actual drawing - - self._DrawQuads(tex, i) - tex.Disable() - - # clean up - gl.glFlush() - t2 = time.time() - print "Rendering: %0.3e" % (t2-t1) - self._colormap.Disable() - self._program1.Disable() - # - gl.glBlendEquation(gl.GL_FUNC_ADD) - gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) - gl.glDisable(gl.GL_CULL_FACE) - gl.glEnable(gl.GL_LINE_SMOOTH) - gl.glEnable(gl.GL_POINT_SMOOTH) - gl.glEnable(gl.GL_DEPTH_TEST) - - - def _DrawQuads(self, tex, tex_id): - """ Draw the quads of the texture. - This is done in a seperate method to reuse code in - OnDraw() and OnDrawShape(). """ - - # should we draw? - if not tex._shape: - return - - # should we create quads? - if tex_id not in self._quads: - self._CreateQuads(tex, tex_id) - - # get data - tex_coord, ver_coord, ind = self._quads[tex_id] - - # init vertex and texture array - gl.glEnableClientState(gl.GL_VERTEX_ARRAY) - gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) - gl.glVertexPointerf(ver_coord.data) - gl.glTexCoordPointerf(tex_coord.data) - - # draw - gl.glDrawElements(gl.GL_QUADS, len(ind), gl.GL_UNSIGNED_BYTE, ind) - - # disable vertex array - gl.glDisableClientState(gl.GL_VERTEX_ARRAY) - gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY) - - - def _GetLimits(self): - """ _GetLimits() - Get the limits in world coordinates between which the object exists. - """ - - x1, x2 = -0.5, -0.5 + self._global_size[2] - y1, y2 = -0.5, -0.5 + self._global_size[1] - z1, z2 = -0.5, -0.5 + self._global_size[0] - - return vv.Wobject._GetLimits(self, x1, x2, y1, y2, z1, z2) - - - def _CreateQuads(self, tex, tex_id): - axes = self.GetAxes() - if not axes: - return - - # Store daspect so we can detect it changing - self._daspectStored = axes.daspect - - # Note that we could determine the world coordinates and use - # them directly here. However, the way that we do it now (using - # the transformations) is to be preferred, because that way the - # transformations are applied via the ModelView matrix stack, - # and can easily be made undone in the raycaster. - # The -0.5 offset is to center pixels/voxels. This works correctly - # for anisotropic data. - - dr = tex._dataRef - - ss = [s - 1 for s in tex._shape] - - x0 = dr.origin[2] * self._global_size[2] - 0.5 - x1 = x0 + ss[2] * dr.sampling[2] * self._global_size[2] - - y0 = dr.origin[1] * self._global_size[1] - y1 = y0 + ss[1] * dr.sampling[1] * self._global_size[1] - - z0 = dr.origin[0] * self._global_size[0] - z1 = z0 + ss[0] * dr.sampling[0] * self._global_size[0] - - # prepare texture coordinates - t0, t1 = 0, 1 - - # if any axis are flipped, make sure the correct polygons are front - # facing - tmp = 1 - for i in axes.daspect: - if i<0: - tmp*=-1 - if tmp==1: - t0, t1 = t1, t0 - x0, x1 = x1, x0 - y0, y1 = y1, y0 - z0, z1 = z1, z0 - - # using glTexCoord* is the same as glMultiTexCoord*(GL_TEXTURE0) - # Therefore we need to bind the base texture to 0. - - # draw. So we draw the six planes of the cube (well not a cube, - # a 3d rectangle thingy). The inside is only rendered if the - # vertex is facing front, so only 3 planes are rendered at a - # time... - - tex_coord, ver_coord = vvt.points.Pointset(3), vvt.points.Pointset(3) - indices = [0,1,2,3, 4,5,6,7, 3,2,6,5, 0,4,7,1, 0,3,5,4, 1,7,6,2] - - # bottom - tex_coord.Append((t0,t0,t0)); ver_coord.Append((x0, y0, z0)) # 0 - tex_coord.Append((t1,t0,t0)); ver_coord.Append((x1, y0, z0)) # 1 - tex_coord.Append((t1,t1,t0)); ver_coord.Append((x1, y1, z0)) # 2 - tex_coord.Append((t0,t1,t0)); ver_coord.Append((x0, y1, z0)) # 3 - # top - tex_coord.Append((t0,t0,t1)); ver_coord.Append((x0, y0, z1)) # 4 - tex_coord.Append((t0,t1,t1)); ver_coord.Append((x0, y1, z1)) # 5 - tex_coord.Append((t1,t1,t1)); ver_coord.Append((x1, y1, z1)) # 6 - tex_coord.Append((t1,t0,t1)); ver_coord.Append((x1, y0, z1)) # 7 - - # Store quads - self._quads[tex_id] = (tex_coord, ver_coord, na.array(indices,dtype=na.uint8)) - -def visvis_plot(vp): - """ - This function accepts a volume rendering object, which it then tosses into - visvis for plotting. - """ - - vp.partition_grids() - gs = vp.bricks - - mi = min((g.my_data[0].min() for g in gs)) - ma = max((g.my_data[0].max() for g in gs)) - - texes = [] - - ax = vv.gca() - - for i,g in enumerate(gs): - ss = ((g.RightEdge - g.LeftEdge) / (na.array(g.my_data[0].shape)-1)).tolist() - origin = g.LeftEdge.astype("float32").tolist() - dd = (g.my_data[0].astype("float32") - mi)/(ma - mi) - dd = na.clip(dd, 0.0, 1.0) - print ss - texes.append(vv.Aarray(dd, origin = origin, sampling = ss)) - - mtex = MultipleTexture(ax, texes, global_size=vp.pf["TopGridDimensions"]) - - ax.daspectAuto = False - ax.SetLimits() - ax.bgcolor = (0,0,0) - - # set camera - ax.cameraType = '3d' - - # done - ax.Draw() - - return mtex, ax diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/setup.py --- a/yt/extensions/volume_rendering/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#!/usr/bin/env python -import setuptools -import os, sys, os.path - -import os.path - -#os.system("cython -a yt/extensions/volume_rendering/VolumeIntegrator.pyx") - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('volume_rendering',parent_package,top_path) - config.make_config_py() # installs __config__.py - config.make_svn_version_py() - return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/software_sampler.py --- a/yt/extensions/volume_rendering/software_sampler.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ -""" -Import the components of the volume rendering extension - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as na -import h5py -from yt.extensions.volume_rendering import * -from yt.funcs import * -from yt.lagos import data_object_registry, ParallelAnalysisInterface - -# We're going to register this class, but it does not directly inherit from -# AMRData. -class VolumeRendering(ParallelAnalysisInterface): - bricks = None - def __init__(self, normal_vector, width, center, - resolution, transfer_function, - fields = None, whole_box = False, - sub_samples = 5, north_vector = None, - pf = None): - # Now we replicate some of the 'cutting plane' logic - if not iterable(resolution): - resolution = (resolution, resolution) - self.resolution = resolution - self.sub_samples = sub_samples - if not iterable(width): - width = (width, width, width) # front/back, left/right, top/bottom - self.width = width - self.center = center - if fields is None: fields = ["Density"] - self.fields = fields - self.transfer_function = transfer_function - - # Now we set up our various vectors - normal_vector /= na.sqrt( na.dot(normal_vector, normal_vector)) - if north_vector is None: - vecs = na.identity(3) - t = na.cross(normal_vector, vecs).sum(axis=1) - ax = t.argmax() - north_vector = na.cross(vecs[ax,:], normal_vector).ravel() - north_vector /= na.sqrt(na.dot(north_vector, north_vector)) - east_vector = -na.cross(north_vector, normal_vector).ravel() - east_vector /= na.sqrt(na.dot(east_vector, east_vector)) - self.unit_vectors = [north_vector, east_vector, normal_vector] - self.box_vectors = na.array([self.unit_vectors[0]*self.width[0], - self.unit_vectors[1]*self.width[1], - self.unit_vectors[2]*self.width[2]]) - - self.origin = center - 0.5*width[0]*self.unit_vectors[0] \ - - 0.5*width[1]*self.unit_vectors[1] \ - - 0.5*width[2]*self.unit_vectors[2] - self.back_center = center - 0.5*width[0]*self.unit_vectors[2] - self.front_center = center + 0.5*width[0]*self.unit_vectors[2] - - self._initialize_source() - self._construct_vector_array() - - def _initialize_source(self): - check, source, rf = self._partition_hierarchy_2d_inclined( - self.unit_vectors, self.origin, self.width, self.box_vectors) - if check: - self._base_source = self.pf.h.inclined_box( - self.origin, self.box_vectors) - else: - # To avoid doubling-up - self._base_source = source - self.source = source - self.res_fac = rf - # Note that if we want to do this in parallel, with 3D domain decomp - # for the grid/bricks, we can supply self._base_source here. But, - # _distributed can't be overridden in that case. - self._brick_collection = HomogenizedBrickCollection(self.source) - - def ray_cast(self, finalize=True): - if self.bricks is None: self.partition_grids() - # Now we order our bricks - total_cells, LE, RE = 0, [], [] - for b in self.bricks: - LE.append(b.LeftEdge) - RE.append(b.RightEdge) - total_cells += na.prod(b.my_data[0].shape) - LE = na.array(LE) - self.back_center - RE = na.array(RE) - self.back_center - LE = na.sum(LE * self.unit_vectors[2], axis=1) - RE = na.sum(RE * self.unit_vectors[2], axis=1) - dist = na.minimum(LE, RE) - ind = na.argsort(dist) - pbar = get_pbar("Ray casting ", total_cells) - total_cells = 0 - tfp = TransferFunctionProxy(self.transfer_function) - tfp.ns = self.sub_samples - for i, b in enumerate(self.bricks[ind]): - pos = b.cast_plane(tfp, self.vector_plane) - total_cells += na.prod(b.my_data[0].shape) - pbar.update(total_cells) - pbar.finish() - if finalize: self._finalize() - - def _finalize(self): - #im = self._mpi_catdict(dict(image=self.image)).pop('image') - im, f = self._mpi_catrgb((self.image, self.resolution)) - self.image = im - - def dump_image(self, prefix): - fn = "%s.h5" % (self._get_filename(prefix)) - mylog.info("Saving to %s", fn) - f = h5py.File(fn, "w") - f.create_dataset("/image", data=self.image) - - def load_bricks(self, fn): - self.bricks = import_partitioned_grids(fn) - - def save_bricks(self, fn): - # This will need to be modified for parallel - export_partitioned_grids(self.bricks, fn) - - def save_image(self, prefix = None, norm = 1.0): - if norm is not None: - mi, ma = self.image.min(), norm*self.image.max() - print "Normalizing with ", mi, ma - image = (na.clip(self.image, mi, ma) - mi)/(ma - mi) - else: - image = self.image - if prefix is None: prefix = "%s_volume_rendering" % (self.pf) - plot_rgb(image, prefix) - - def partition_grids(self): - log_field = [] - for field in self.fields: - log_field.append(field in self.pf.field_info and - self.pf.field_info[field].take_log) - self._brick_collection._partition_local_grids(self.fields, log_field) - # UNCOMMENT FOR PARALLELISM - #self._brick_collection._collect_bricks(self.source) - self.bricks = self._brick_collection.bricks - - def _construct_vector_array(self): - rx = self.resolution[0] * self.res_fac[0] - ry = self.resolution[1] * self.res_fac[1] - # We should move away from pre-generation of vectors like this and into - # the usage of on-the-fly generation in the VolumeIntegrator module - self.image = na.zeros((rx,ry,3), dtype='float64', order='C') - # We might have a different width and back_center - bl = self.source.box_lengths - px = na.linspace(-bl[0]/2.0, bl[0]/2.0, rx)[:,None] - py = na.linspace(-bl[1]/2.0, bl[1]/2.0, ry)[None,:] - inv_mat = self.source._inv_mat - bc = self.source.origin + 0.5*self.source.box_vectors[0] \ - + 0.5*self.source.box_vectors[1] - vectors = na.zeros((rx, ry, 3), - dtype='float64', order='C') - vectors[:,:,0] = inv_mat[0,0]*px + inv_mat[0,1]*py + bc[0] - vectors[:,:,1] = inv_mat[1,0]*px + inv_mat[1,1]*py + bc[1] - vectors[:,:,2] = inv_mat[2,0]*px + inv_mat[2,1]*py + bc[2] - bounds = (px.min(), px.max(), py.min(), py.max()) - self.vector_plane = VectorPlane(vectors, self.box_vectors[2], - bc, bounds, self.image, - self.source._x_vec, self.source._y_vec) - self.vp_bounds = bounds - self.vectors = vectors - -data_object_registry["volume_rendering"] = VolumeRendering diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/transfer_function_widget.py --- a/yt/extensions/volume_rendering/transfer_function_widget.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,227 +0,0 @@ -""" -Simple transfer function editor - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as na -import cPickle -from transfer_functions import ColorTransferFunction - -from enthought.traits.api import \ - HasTraits, Float, List, Instance, Button, Array, CArray, Range, \ - DelegatesTo, Property, Any, Code, Callable -from enthought.traits.ui.api import \ - View, Item, HSplit, VSplit, ListEditor, InstanceEditor, ValueEditor, \ - HGroup, VGroup, CodeEditor, TextEditor, RangeEditor -from enthought.chaco.api import Plot, ArrayPlotData -from enthought.enable.component_editor import ComponentEditor -import enthought.pyface.api as pyface - -class TFGaussian(HasTraits): - center = Range(low = 'left_edge', - high = 'right_edge') - left_edge = DelegatesTo('tf') - right_edge = DelegatesTo('tf') - - tf = Any - - width = Property - rwidth = Range(0.0, 0.5, 0.05) - - red = Range(0.0, 1.0, 0.5) - green = Range(0.0, 1.0, 0.5) - blue = Range(0.0, 1.0, 0.5) - alpha = Range(0.0, 1.0, 1.0) - - traits_view = View(VGroup( - HGroup( - Item('center', editor=RangeEditor(format='%0.4f')), - Item('rwidth', label='Width', - editor=RangeEditor(format='%0.4f')), - ), - HGroup( - Item('red', editor=RangeEditor(format='%0.4f')), - Item('green', editor=RangeEditor(format='%0.4f')), - Item('blue', editor=RangeEditor(format='%0.4f')), - Item('alpha', editor=RangeEditor(format='%0.4f')) - ), - show_border=True,), - ) - - def _get_width(self): - width = self.rwidth * (self.tf.right_edge - self.tf.left_edge) - return width - - def _center_default(self): - return (self.left_edge + self.right_edge)/2.0 - - def _width_default(self): - return (self.right_edge - self.left_edge)/20.0 - - def _red_changed(self): - self.tf._redraw() - - def _green_changed(self): - self.tf._redraw() - - def _blue_changed(self): - self.tf._redraw() - - def _alpha_changed(self): - self.tf._redraw() - - def _center_changed(self): - self.tf._redraw() - - def _height_changed(self): - self.tf._redraw() - - def _rwidth_changed(self): - self.tf._redraw() - -class TFColors(HasTraits): - gaussians = List(Instance(TFGaussian)) - transfer_function = Instance(ColorTransferFunction) - - left_edge = Float(0.0) - right_edge = Float(10.0) - - add_gaussian = Button - run_routine = Button - save_function = Button - - routine = Callable - - plot_data = Instance(ArrayPlotData) - image_data = Instance(ArrayPlotData) - vr_image_data = Instance(ArrayPlotData) - - plot = Instance(Plot) - image_plot = Instance(Plot) - vr_image_plot = Instance(Plot) - - traits_view = View(VGroup( - HGroup( - VGroup( - Item('image_plot', editor=ComponentEditor(), - show_label=False, resizable=True), - Item('plot', editor=ComponentEditor(), - show_label=False, resizable=True), - ), - Item('vr_image_plot', editor=ComponentEditor(size=(512,512)), - show_label=False, resizable=False, - width=512, height=512)), - Item("gaussians", style='custom', - editor=ListEditor(style='custom'), - show_label=False, - ), - HGroup(Item("left_edge"), Item("right_edge")), - HGroup(Item("add_gaussian", show_label = False), - Item("run_routine", show_label = False), - Item("save_function", show_label = False), - ), - ), - width=960, height=800, - resizable=True) - - def _plot_data_default(self): - return ArrayPlotData(rx = (0.0, 1.0), ry = (0.0, 0.0), - gx = (0.0, 1.0), gy = (0.0, 0.0), - bx = (0.0, 1.0), by = (0.0, 0.0), - ax = (0.0, 1.0), ay = (0.0, 0.0), - lx = (0.0, 1.0), ly = (0.0, 0.0), - ux = (0.0, 1.0), uy = (1.0, 1.0)) - - def _image_data_default(self): - return ArrayPlotData(image_data = na.zeros((40,256,4), dtype='uint8')) - - def _vr_image_data_default(self): - return ArrayPlotData(vr_image_data = na.zeros((512,512,3), dtype='uint8')) - - def _plot_default(self): - p = Plot(self.plot_data) - p.plot( ("rx", "ry"), type='line', color='red') - p.plot( ("gx", "gy"), type='line', color='green') - p.plot( ("bx", "by"), type='line', color='blue') - p.plot( ("ax", "ay"), type='line', color='black') - p.plot( ("lx", "ly"), type='line', color='black') - p.plot( ("ux", "uy"), type='line', color='black') - return p - - def _image_plot_default(self): - plot = Plot(self.image_data, default_origin="top left") - #plot.x_axis.orientation = "top" - img_plot = plot.img_plot("image_data")[0] - - plot.bgcolor = "black" - return plot - - def _vr_image_plot_default(self): - plot = Plot(self.vr_image_data, default_origin="top left", - size=(512,512)) - plot.aspect_ratio = 1.0 - #plot.x_axis.orientation = "top" - img_plot = plot.img_plot("vr_image_data")[0] - - plot.bgcolor = "black" - return plot - - def _add_gaussian_fired(self): - self.gaussians.append(TFGaussian(tf = self)) - - def _redraw(self): - self.transfer_function = ColorTransferFunction( - (self.left_edge, self.right_edge)) - for g in self.gaussians: - self.transfer_function.add_gaussian(g.center, g.width, - (g.red, g.green, g.blue, g.alpha)) - for f, c in zip(self.transfer_function.funcs, "rgba"): - self.plot_data["%sx" % c] = f.x - self.plot_data["%sy" % c] = f.y - - # Now we update the image describing the colors - # This makes the assumption that all the x values are the same - image = na.zeros((40, self.transfer_function.nbins, 4), dtype='uint8') - for i,f in enumerate(self.transfer_function.funcs): - image[:,:,i] = (f.y[None,:] * 255).astype('uint8') - self.image_data["image_data"] = image - - def _run_routine_fired(self): - img_data = self.routine(self.transfer_function) - self.vr_image_data['vr_image_data'] = img_data - - def _save_function_fired(self): - self._redraw() - dlg = pyface.FileDialog( - action='save as', - wildcard="*.ctf", - ) - if dlg.open() == pyface.OK: - print "Saving:", dlg.path - tf = self.transfer_function - f = open(dlg.path, "wb") - cPickle.dump(tf, f) - -if __name__ == "__main__": - tfc = TFColors() - tfc.configure_traits() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/extensions/volume_rendering/transfer_functions.py --- a/yt/extensions/volume_rendering/transfer_functions.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,619 +0,0 @@ -""" -Simple transfer function editor - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -import numpy as na -from matplotlib.cm import get_cmap -from yt.funcs import * -from yt.physical_constants import * - -class TransferFunction(object): - def __init__(self, x_bounds, nbins=256): - r"""A transfer function governs the transmission of emission and - absorption through a volume. - - Transfer functions are defined by boundaries, bins, and the value that - governs transmission through that bin. This is scaled between 0 and 1. - When integrating through a volume. the value through a given cell is - defined by the value calculated in the transfer function. - - Parameters - ---------- - x_bounds : tuple of floats - The min and max for the transfer function. Values below or above - these values are discarded. - nbins : int - How many bins to calculate; in betwee, linear interpolation is - used, so low values are typically fine. - - Notes - ----- - Typically, raw transfer functions are not generated unless particular - and specific control over the integration is desired. Usually either - color transfer functions, where the color values are calculated from - color tables, or multivariate transfer functions are used. - """ - self.pass_through = 0 - self.nbins = nbins - self.x_bounds = x_bounds - self.x = na.linspace(x_bounds[0], x_bounds[1], nbins).astype('float64') - self.y = na.zeros(nbins, dtype='float64') - - def add_gaussian(self, location, width, height): - r"""Add a Gaussian distribution to the transfer function. - - Typically, when rendering isocontours, a Guassian distribution is the - easiest way to draw out features. The spread provides a softness. - The values are calculated as :math:`f(x) = h \exp{-(x-x_0)^2 / w}`. - - Parameters - ---------- - location : float - The centroid of the Gaussian (:math:`x_0` in the above equation.) - width : float - The relative width (:math:`w` in the above equation.) - height : float - The peak height (:math:`h` in the above equation.) Note that while - values greater 1.0 will be accepted, the values of the transmission - function are clipped at 1.0. - - Examples - -------- - - >>> tf = TransferFunction( (-10.0, -5.0) ) - >>> tf.add_gaussian(-9.0, 0.01, 1.0) - """ - vals = height * na.exp(-(self.x - location)**2.0/width) - self.y = na.clip(na.maximum(vals, self.y), 0.0, 1.0) - - def add_line(self, start, stop): - r"""Add a line between two points to the transmission function. - - This will accept a starting point in (x,y) and an ending point in (x,y) - and set the values of the transmission function between those x-values - to be along the line connecting the y values. - - Parameters - ---------- - start : tuple of floats - (x0, y0), the starting point. x0 is between the bounds of the - transfer function and y0 must be between 0.0 and 1.0. - stop : tuple of floats - (x1, y1), the ending point. x1 is between the bounds of the - transfer function and y1 must be between 0.0 and 1.0. - - Examples - -------- - This will set the transfer function to be linear from 0.0 to 1.0, - across the bounds of the function. - - >>> tf = TransferFunction( (-10.0, -5.0) ) - >>> tf.add_line( (-10.0, 0.0), (-5.0, 1.0) ) - """ - x0, y0 = start - x1, y1 = stop - slope = (y1-y0)/(x1-x0) - vals = na.zeros(self.x.shape, 'float64') - vals[(self.x >= x0) & (self.x <= x1)] = \ - slope * (self.x - x0) + y0 - self.y = na.clip(na.maximum(vals, self.y), 0.0, 1.0) - - def add_step(self, start, stop, value): - r"""Adds a step function to the transfer function. - - This accepts a `start` and a `stop`, and then in between those points the - transfer function is set to the maximum of the transfer function and - the `value`. - - Parameters - ---------- - start : float - This is the beginning of the step function; must be within domain - of the transfer function. - stop : float - This is the ending of the step function; must be within domain - of the transfer function. - value : float - The value the transfer function will be set to between `start` and - `stop`. Note that the transfer function will *actually* be set to - max(y, value) where y is the existing value of the transfer - function. - - Examples - -------- - Note that in this example, we have added a step function, but the - Gaussian that already exists will "win" where it exceeds 0.5. - - >>> tf = TransferFunction( (-10.0, -5.0) ) - >>> tf.add_gaussian(-7.0, 0.01, 1.0) - >>> tf.add_step(-8.0, -6.0, 0.5) - """ - vals = na.zeros(self.x.shape, 'float64') - vals[(self.x >= start) & (self.x <= stop)] = value - self.y = na.clip(na.maximum(vals, self.y), 0.0, 1.0) - - def add_filtered_planck(self, wavelength, trans): - vals = na.zeros(self.x.shape, 'float64') - nu = clight/(wavelength*1e-8) - nu = nu[::-1] - - for i,logT in enumerate(self.x): - T = 10**logT - # Black body at this nu, T - Bnu = ((2.0 * hcgs * nu**3) / clight**2.0) / \ - (na.exp(hcgs * nu / (kboltz * T)) - 1.0) - # transmission - f = Bnu * trans[::-1] - # integrate transmission over nu - vals[i] = na.trapz(f,nu) - - # normalize by total transmission over filter - self.y = vals/trans.sum() #/na.trapz(trans[::-1],nu) - #self.y = na.clip(na.maximum(vals, self.y), 0.0, 1.0) - - def plot(self, filename): - r"""Save an image file of the transfer function. - - This function loads up matplotlib, plots the transfer function and saves. - - Parameters - ---------- - filename : string - The file to save out the plot as. - - Examples - -------- - - >>> tf = TransferFunction( (-10.0, -5.0) ) - >>> tf.add_gaussian(-9.0, 0.01, 1.0) - >>> tf.plot("sample.png") - """ - import matplotlib;matplotlib.use("Agg");import pylab - pylab.clf() - pylab.plot(self.x, self.y, 'xk-') - pylab.xlim(*self.x_bounds) - pylab.ylim(0.0, 1.0) - pylab.savefig(filename) - -class MultiVariateTransferFunction(object): - def __init__(self): - r"""This object constructs a set of field tables that allow for - multiple field variables to control the integration through a volme. - - The integration through a volume typically only utilizes a single field - variable (for instance, Density) to set up and control the values - returned at the end of the integration. For things like isocontours, - this is fine. However, more complicated schema are possible by using - this object. For instance, density-weighted emission that produces - colors based on the temperature of the fluid. - """ - self.n_field_tables = 0 - self.tables = [] # Tables are interpolation tables - self.field_ids = [0] * 6 # This correlates fields with tables - self.weight_field_ids = [-1] * 6 # This correlates - self.field_table_ids = [0] * 6 - self.weight_table_ids = [-1] * 6 - - def add_field_table(self, table, field_id, weight_field_id = -1, - weight_table_id = -1): - r"""This accepts a table describing integration. - - A "field table" is a tabulated set of values that govern the - integration through a given field. These are defined not only by the - transmission coefficient, interpolated from the table itself, but the - `field_id` that describes which of several fields the integration - coefficient is to be calculated from. - - Parameters - ---------- - table : `TransferFunction` - The integration table to be added to the set of tables used during - the integration. - field_id : int - Each volume has an associated set of fields. This identifies which - of those fields will be used to calculate the integration - coefficient from this table. - weight_field_id : int, optional - If specified, the value of the field this identifies will be - multiplied against the integration coefficient. - weight_table_id : int, optional - If specified, the value from the *table* this identifies will be - multiplied against the integration coefficient. - - Notes - ----- - This can be rather complicated. It's recommended that if you are - interested in manipulating this in detail that you examine the source - code, specifically the function FIT_get_value in - yt/_amr_utils/VolumeIntegrator.pyx. - - Examples - -------- - This example shows how to link a new transfer function against field 0. - Note that this by itself does not link a *channel* for integration - against a field. This is because the weighting system does not mandate - that all tables contribute to a channel, only that they contribute a - value which may be used by other field tables. - - >>> mv = MultiVariateTransferFunction() - >>> tf = TransferFunction( (-10.0, -5.0) ) - >>> tf.add_gaussian( -7.0, 0.01, 1.0) - >>> mv.add_field_table(tf, 0) - """ - self.tables.append(table) - self.field_ids[self.n_field_tables] = field_id - self.weight_field_ids[self.n_field_tables] = weight_field_id - self.weight_table_ids[self.n_field_tables] = weight_table_id - self.n_field_tables += 1 - - def link_channels(self, table_id, channels = 0): - r"""Link an image channel to a field table. - - Once a field table has been added, it can be linked against a channel (any - one of the six -- red, green, blue, red absorption, green absorption, blue - absorption) and then the value calculated for that field table will be - added to the integration for that channel. Not all tables must be linked - against channels. - - Parameters - ---------- - table_id : int - The 0-indexed table to link. - channels : int or list of ints - The channel or channels to link with this table's calculated value. - - - Examples - -------- - This example shows how to link a new transfer function against field 0, and - then link that table against all three RGB channels. Typically an - absorption (or 'alpha') channel is also linked. - - >>> mv = MultiVariateTransferFunction() - >>> tf = TransferFunction( (-10.0, -5.0) ) - >>> tf.add_gaussian( -7.0, 0.01, 1.0) - >>> mv.add_field_table(tf, 0) - >>> mv.link_channels(0, [0,1,2]) - """ - channels = ensure_list(channels) - for c in channels: - self.field_table_ids[c] = table_id - -class ColorTransferFunction(MultiVariateTransferFunction): - def __init__(self, x_bounds, nbins=256): - r"""A complete set of transfer functions for standard color-mapping. - - This is the best and easiest way to set up volume rendering. It - creates field tables for all three colors, their alphas, and has - support for sampling color maps and adding independent color values at - all locations. It will correctly set up the - `MultiVariateTransferFunction`. - - Parameters - ---------- - x_bounds : tuple of floats - The min and max for the transfer function. Values below or above - these values are discarded. - nbins : int - How many bins to calculate; in betwee, linear interpolation is - used, so low values are typically fine. - """ - MultiVariateTransferFunction.__init__(self) - self.x_bounds = x_bounds - self.nbins = nbins - # This is all compatibility and convenience. - self.red = TransferFunction(x_bounds, nbins) - self.green = TransferFunction(x_bounds, nbins) - self.blue = TransferFunction(x_bounds, nbins) - self.alpha = TransferFunction(x_bounds, nbins) - self.funcs = (self.red, self.green, self.blue, self.alpha) - - # Now we do the multivariate stuff - # We assign to Density, but do not weight - for i,tf in enumerate(self.funcs[:3]): - self.add_field_table(tf, 0, weight_table_id = 3) - self.link_channels(i, i) - self.add_field_table(self.funcs[3], 0) - # We don't have a fifth table, so the value will *always* be zero. - self.link_channels(4, [3,4,5]) - - def add_gaussian(self, location, width, height): - r"""Add a Gaussian distribution to the transfer function. - - Typically, when rendering isocontours, a Guassian distribution is the - easiest way to draw out features. The spread provides a softness. - The values are calculated as :math:`f(x) = h \exp{-(x-x_0)^2 / w}`. - - Parameters - ---------- - location : float - The centroid of the Gaussian (:math:`x_0` in the above equation.) - width : float - The relative width (:math:`w` in the above equation.) - height : list of 4 float - The peak height (:math:`h` in the above equation.) Note that while - values greater 1.0 will be accepted, the values of the transmission - function are clipped at 1.0. This must be a list, and it is in the - order of (red, green, blue, alpha). - - Examples - -------- - This adds a red spike. - - >>> tf = ColorTransferFunction( (-10.0, -5.0) ) - >>> tf.add_gaussian(-9.0, 0.01, [1.0, 0.0, 0.0, 1.0]) - """ - for tf, v in zip(self.funcs, height): - tf.add_gaussian(location, width, v) - - def add_step(self, start, stop, value): - r"""Adds a step function to the transfer function. - - This accepts a `start` and a `stop`, and then in between those points the - transfer function is set to the maximum of the transfer function and - the `value`. - - Parameters - ---------- - start : float - This is the beginning of the step function; must be within domain - of the transfer function. - stop : float - This is the ending of the step function; must be within domain - of the transfer function. - value : list of 4 floats - The value the transfer function will be set to between `start` and - `stop`. Note that the transfer function will *actually* be set to - max(y, value) where y is the existing value of the transfer - function. This must be a list, and it is in the order of (red, - green, blue, alpha). - - - Examples - -------- - This adds a step function that will produce a white value at > -6.0. - - >>> tf = ColorTransferFunction( (-10.0, -5.0) ) - >>> tf.add_step(-6.0, -5.0, [1.0, 1.0, 1.0, 1.0]) - """ - for tf, v in zip(self.funcs, value): - tf.add_step(start, stop, v) - - def plot(self, filename): - r"""Save an image file of the transfer function. - - This function loads up matplotlib, plots all of the constituent - transfer functions and saves. - - Parameters - ---------- - filename : string - The file to save out the plot as. - - Examples - -------- - - >>> tf = ColorTransferFunction( (-10.0, -5.0) ) - >>> tf.add_layers(8) - >>> tf.plot("sample.png") - """ - from matplotlib import pyplot - from matplotlib.ticker import FuncFormatter - pyplot.clf() - ax = pyplot.axes() - i_data = na.zeros((self.alpha.x.size, self.funcs[0].y.size, 3)) - i_data[:,:,0] = na.outer(na.ones(self.alpha.x.size), self.funcs[0].y) - i_data[:,:,1] = na.outer(na.ones(self.alpha.x.size), self.funcs[1].y) - i_data[:,:,2] = na.outer(na.ones(self.alpha.x.size), self.funcs[2].y) - ax.imshow(i_data, origin='lower') - ax.fill_between(na.arange(self.alpha.y.size), self.alpha.x.size * self.alpha.y, y2=self.alpha.x.size, color='white') - ax.set_xlim(0, self.alpha.x.size) - xticks = na.arange(na.ceil(self.alpha.x[0]), na.floor(self.alpha.x[-1]) + 1, 1) - self.alpha.x[0] - xticks *= self.alpha.x.size / (self.alpha.x[-1] - self.alpha.x[0]) - ax.xaxis.set_ticks(xticks) - def x_format(x, pos): - return "%.1f" % (x * (self.alpha.x[-1] - self.alpha.x[0]) / (self.alpha.x.size) + self.alpha.x[0]) - ax.xaxis.set_major_formatter(FuncFormatter(x_format)) - yticks = na.linspace(0,1,5) * self.alpha.y.size - ax.yaxis.set_ticks(yticks) - def y_format(y, pos): - return (y / self.alpha.y.size) - ax.yaxis.set_major_formatter(FuncFormatter(y_format)) - ax.set_ylabel("Transmission") - ax.set_xlabel("Value") - pyplot.savefig(filename) - - def sample_colormap(self, v, w, alpha=None, colormap="gist_stern"): - r"""Add a Gaussian based on an existing colormap. - - Constructing pleasing Gaussians in a transfer function can pose some - challenges, so this function will add a single Gaussian whose colors - are taken from a colormap scaled between the bounds of the transfer - function. As with `TransferFunction.add_gaussian`, the value is - calculated as :math:`f(x) = h \exp{-(x-x_0)^2 / w}` but with the height - for each color calculated from the colormap. - - Parameters - ---------- - v : float - The value at which the Gaussian is to be added. - w : float - The relative width (:math:`w` in the above equation.) - alpha : float, optional - The alpha value height for the Gaussian - colormap : string, optional - An acceptable colormap. See either raven.color_maps or - http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps . - - See Also - -------- - ColorTransferFunction.add_layers : Many-at-a-time adder - - Examples - -------- - - >>> tf = ColorTransferFunction( (-10.0, -5.0) ) - >>> tf.sample_colormap(-7.0, 0.01, 'algae') - """ - rel = (v - self.x_bounds[0])/(self.x_bounds[1] - self.x_bounds[0]) - cmap = get_cmap(colormap) - r,g,b,a = cmap(rel) - if alpha is None: alpha = a - self.add_gaussian(v, w, [r,g,b,alpha]) - print "Adding gaussian at %s with width %s and colors %s" % ( - v, w, (r,g,b,alpha)) - - def add_layers(self, N, w=None, mi=None, ma=None, alpha = None, - colormap="gist_stern"): - r"""Add a set of Gaussians based on an existing colormap. - - Constructing pleasing Gaussians in a transfer function can pose some - challenges, so this function will add several evenly-spaced Gaussians - whose colors are taken from a colormap scaled between the bounds of the - transfer function. For each Gaussian to be added, - `ColorTransferFunction.sample_colormap` is called. - - Parameters - ---------- - N : int - How many Gaussians to add - w : float - The relative width of each Gaussian. If not included, it is - calculated as 0.001 * (max_val - min_val) / N - mi : float, optional - If only a subset of the data range is to have the Gaussians added, - this is the minimum for that subset - ma : float, optional - If only a subset of the data range is to have the Gaussians added, - this is the maximum for that subset - alpha : list of floats, optional - The alpha value height for each Gaussian. If not supplied, it is - calculated as the logspace between -2.0 and 0.0. - colormap : string, optional - An acceptable colormap. See either raven.color_maps or - http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps . - - See Also - -------- - ColorTransferFunction.sample_colormap : Single Gaussian adder - - Examples - -------- - - >>> tf = ColorTransferFunction( (-10.0, -5.0) ) - >>> tf.add_layers(8) - """ - dist = (self.x_bounds[1] - self.x_bounds[0]) - if mi is None: mi = self.x_bounds[0] + dist/(10.0*N) - if ma is None: ma = self.x_bounds[1] - dist/(10.0*N) - if w is None: w = 0.001 * (ma-mi)/N - if alpha is None: alpha = na.logspace(-2.0, 0.0, N) - for v, a in zip(na.mgrid[mi:ma:N*1j], alpha): - self.sample_colormap(v, w, a, colormap=colormap) - -class ProjectionTransferFunction(MultiVariateTransferFunction): - def __init__(self, x_bounds = (-1e60, 1e60)): - r"""A transfer function that defines a simple projection. - - To generate an interpolated, off-axis projection through a dataset, - this transfer function should be used. It will create a very simple - table that merely sums along each ray. Note that the end product will - need to be scaled by the total width through which the rays were cast, - a piece of information inacessible to the transfer function. - - Parameters - ---------- - x_boudns : tuple of floats, optional - If any of your values lie outside this range, they will be - truncated. - - Notes - ----- - When you use this transfer function, you may need to explicitly disable - logging of fields. - - """ - MultiVariateTransferFunction.__init__(self) - self.x_bounds = x_bounds - self.nbins = 2 - self.linear_mapping = TransferFunction(x_bounds, 2) - self.linear_mapping.pass_through = 1 - self.add_field_table(self.linear_mapping, 0) - self.alpha = TransferFunction(x_bounds, 2) - self.alpha.y *= 0.0 - self.alpha.y += 1.0 - self.add_field_table(self.alpha, 0) - self.link_channels(0, [0,1,2]) # same emission for all rgb - self.link_channels(2, [3,4,5]) # this will remove absorption - -class PlanckTransferFunction(MultiVariateTransferFunction): - def __init__(self, T_bounds, rho_bounds, nbins=256, - red='R', green='V', blue='B', - anorm = 1e6): - """ - This sets up a planck function for multivariate emission and - absorption. We assume that the emission is black body, which is then - convolved with appropriate Johnson filters for *red*, *green* and - *blue*. *T_bounds* and *rho_bounds* define the limits of tabulated - emission and absorption functions. *anorm* is a "fudge factor" that - defines the somewhat arbitrary normalization to the scattering - approximation: because everything is done largely unit-free, and is - really not terribly accurate anyway, feel free to adjust this to change - the relative amount of reddenning. Maybe in some future version this - will be unitful. - """ - MultiVariateTransferFunction.__init__(self) - mscat = -1 - from UBVRI import johnson_filters - for i, f in enumerate([red, green, blue]): - jf = johnson_filters[f] - tf = TransferFunction(T_bounds) - tf.add_filtered_planck(jf['wavelen'], jf['trans']) - self.add_field_table(tf, 0, 1) - self.link_channels(i, i) # 0 => 0, 1 => 1, 2 => 2 - mscat = max(mscat, jf["Lchar"]**-4) - - for i, f in enumerate([red, green, blue]): - # Now we set up the scattering - scat = (johnson_filters[f]["Lchar"]**-4 / mscat)*anorm - tf = TransferFunction(rho_bounds) - print "Adding: %s with relative scattering %s" % (f, scat) - tf.y *= 0.0; tf.y += scat - self.add_field_table(tf, 1, weight_field_id = 1) - self.link_channels(i+3, i+3) - - self._normalize() - - def _normalize(self): - fmax = na.array([f.y for f in self.tables[:3]]) - normal = fmax.max(axis=0) - for f in self.tables[:3]: - f.y = f.y/normal - -if __name__ == "__main__": - tf = ColorTransferFunction((-20, -5)) - tf.add_gaussian(-16.0, 0.4, [0.2, 0.3, 0.1]) - tf.add_gaussian(-14.0, 0.8, [0.4, 0.1, 0.2]) - tf.add_gaussian(-10.0, 1.0, [0.0, 0.0, 1.0]) - tf.plot("tf.png") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/FileHandling.py --- a/yt/fido/FileHandling.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -""" -All file-handling takes place in here. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - - -from yt.fido import * - -def copy_output(basename, new_location, extra_files=None): - if extra_files == None: extra_files = [] - copy_glob("%s*" % (basename), new_location) - for file in extra_files: - copy_glob(file, location) - return os.path.join(new_location, os.path.basename(basename)) - -def move_output(basename, new_location, extra_files=None): - if extra_files == None: extra_files = [] - move_glob("%s*" % (basename), new_location) - for file in extra_files: - move_glob(file, location) - -def delete_output(basename, extra_files=None): - if extra_files == None: extra_files = [] - delete_glob("%s*" % os.path.normpath(filename), location) - for file in extra_files: - delete_glob(file) - -def bury_output(filename, new_prefix = None, new_location=None, extra_files=None): - if extra_files == None: extra_files = [] - if not new_location: - dirname = NewDirectoryPattern % filename - if not new_prefix: new_prefix = os.getcwd() - new_location = os.path.abspath(os.path.join(new_prefix, dirname)) - move_glob("%s*" % filename, new_location) - for file in extra_files: - move_glob(file, new_location) - return os.path.join(new_location, filename) - -def digup_output(filename, new_location=None, extra_files=None): - if extra_files == None: extra_files = [] - if not new_location: - new_location = get_parent_dir(filename) - else: - # Make sure we have no relative references - new_location = os.path.normpath(new_location) - print "%s*" % (filename), new_location - move_glob("%s*" % filename, new_location) - -def copy_glob(glob_pattern, new_location): - if not os.path.isdir(new_location): - os.makedirs(new_location) - for file in glob.glob(glob_pattern): - mylog.debug("Copying %s to %s", file, new_location) - shutil.copy(file, new_location) - -def move_glob(glob_pattern, new_location): - if not os.path.isdir(new_location): - os.makedirs(new_location) - # This is slower than dumping to shell. - # But, I trust it. And it should work on boh - # BSD and GNU util systems. - for file in glob.glob(glob_pattern): - if os.path.abspath(file) == os.path.abspath(new_location): continue - nl = os.path.join(new_location, os.path.basename(file)) - mylog.debug("Moving %s to %s", file, nl) - shutil.move(file, nl) - -def delete_glob(glob_pattern): - for file in glob.glob(glob_pattern): - print "Removing %s" % (file) - shutil.unlink(file) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/OutputCollection.py --- a/yt/fido/OutputCollection.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,180 +0,0 @@ -""" -Handling of sets of outputs. - -We don't do any instantiation, or touching of lagos, etc. - -Very simple nowadays. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.fido import * - -from stat import ST_CTIME - -class OutputCollection: - def __init__(self, title): - self.title = title - self.output_names = na.array(()) - self.output_time_ids = na.array((), dtype='int64') - self.output_times = na.array((), dtype='float64') - - def read_in(self, filename): - self._last_read_filename = filename - lines = open(filename).readlines() - output_lines = [line for line in lines if line.startswith("Output:")] - outputs = [line.split(":")[1] for line in output_lines] - output_time_ids = [int(line.split(":")[2]) for line in output_lines] - output_times = [float(line.split(":")[3]) for line in output_lines] - - self.output_names = na.array(outputs) - self.output_time_ids = na.array(output_time_ids, dtype='int64') - self.output_times = na.array(output_times, dtype='float64') - - def write_out(self): - path=ytcfg.get("fido","rundir") - if not os.path.isdir(path): os.makedirs(path) - fn = os.path.join(path, "runF_%s" % (self.title)) - f = open(fn, "w") - for i, output in enumerate(self.output_names): - f.write("Output:%s:%s:%s\n" % ( \ - os.path.abspath(output), \ - self.output_time_ids[i], \ - self.output_times[i])) - f.close() - - def sort(self): - order = na.argsort(self.output_times) - self.output_names = self.output_names[order] - self.output_times = self.output_times[order] - self.output_time_ids = self.output_time_ids[order] - - def add_output(self, filename): - # We're passing in *just* filenames here. So, we simply snag the - # two appropriate lines in the parameter file. - if filename in self.output_names: return - time = get_parameter_line(filename, "InitialTime").split()[-1] - # Implement exception catching - try: - timeID = get_parameter_line(filename, "CurrentTimeIdentifier").split()[-1] - except: - timeID = int(os.stat(filename)[ST_CTIME]) - self.output_names = \ - na.array(self.output_names.tolist() + [filename]) - self.output_time_ids = \ - na.array(self.output_time_ids.tolist() + [int(timeID)], dtype='int64') - self.output_times = \ - na.array(self.output_times.tolist() + [float(time)], dtype='float64') - self.sort() - - def get_before(self, time): - return na.where(self.output_times <= time)[0] - - def get_after(self, time): - return na.where(self.output_times > time)[0] - - def __delitem__(self, key): - if isinstance(key, types.StringType): - id = self.index(key) - elif isinstance(key, types.IntType): - id = key - self.output_names = na.array(self.output_names[:id].tolist() \ - + self.output_names[id+1:].tolist()) - self.output_times = na.array(self.output_times[:id].tolist() \ - + self.output_times[id+1:].tolist()) - self.output_time_ids = na.array(self.output_time_ids[:id].tolist() \ - + self.output_time_ids[id+1:].tolist()) - - def __getitem__(self, key): - """ - Based on the type of input, we either return based on index or - basename. - """ - if isinstance(key, types.StringType): - index = self.index(key) - elif isinstance(key, types.IntType): - index = key - # This fails, but I don't know how to fix it. - a = (self.output_names[index], \ - self.output_times[index], \ - self.output_time_ids[index] ) - return a - - def index(self, key): - t = os.path.basename(key) - # Find out the index - index = None - for i in range(self.output_names.shape[0]): - if os.path.basename(self.output_names[i]) \ - == os.path.basename(t): - index = i - break - if index == None: - raise KeyError - return index - - def __repr__(self): - return self.title - - def __len__(self): - return len(self.output_names) - - def __iter__(self): - for i in range(len(self)): - yield self.output_names[i] - - def keys(self): - return self.output_names.tolist() - - def __convert_args(self, args, kwargs, my_dict): - new_args = list(args)[:] - new_kwargs = {} - for j, arg in enumerate(args): - if isinstance(arg, types.StringType): - new_args[j] = arg % myDict - for key in kwargs.keys(): - if isinstance(kwargs[key], types.StringType): - new_kwargs[key] = kwargs[key] % myDict - return new_args, new_kwargs - - def run_functions(self, function, args = None, kwargs = None): - if args is None: args = [] - if kwargs is None: kwargs = {} - import yt.lagos as lagos # We import *here* so that we only import if we need it - for i,o in enumerate(self): - # Now we format string the various args and kwargs - myDict = {'fn':str(o), 'index':i, 'time':self.output_times[i], - 'timeID':self.output_time_ids[i]} - newa, newk = self.__convert_args(args, kwargs) - print args, kwargs - function(*newa, **newk) - -def GrabCollections(path=None): - if not path: path=ytcfg.get("fido","rundir") - if not os.path.isdir(path): os.makedirs(path) - ocs = [] - for file in glob.glob(os.path.join(path,"runF_*")): - title=os.path.basename(file) - if title.startswith("runF_"): title = title[5:] - ocs.append(OutputCollection(title)) - ocs[-1].read_in(file) - return ocs diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/OutputWatcher.py --- a/yt/fido/OutputWatcher.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -""" -Output-watcher - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.fido import * - -class Watcher: - def __init__(self, title=None, path=".", new_prefix="", oc=None, - process=None, function_handler = None): - self.original_path = os.getcwd() - os.chdir(path) - if title == None: title = os.path.basename(os.getcwd()) - if oc == None: oc = OutputCollection(title) - self.title = title - self.oc = oc - self.process = process - self.new_prefix = new_prefix - self.skip_files = [] # Forward compatible - self.function_handler = None - if function_handler != None: - self.function_handler = function_handler() - - def run(self, run_once=False): - mylog.info("Entering main Fido loop (CTRL-C or touch 'stopFido' to end)") - wb = ytcfg.getfloat("fido","WaitBetween") - while not self.check_for_stop(): - nn = self.check_for_output() - for bn in sorted(nn): - new_name = bury_output(bn, new_prefix=self.new_prefix) - self.handle_output(new_name) - if run_once: break - try: - time.sleep(wb) - except KeyboardInterrupt: - sys.exit() - - def handle_output(self, filename): - # First, add it to the OutputCollection - self.oc.add_output(filename) - self.oc.write_out() - if self.function_handler == None: return - # Now, we pass it to our function handler - pid = os.fork() - if pid: - mylog.debug("Waiting on pid %s", pid) - newpid, exit = os.waitpid(pid,0) - mylog.debug("Exit status %s from PID %s", exit, newpid) - else: - mylog.info("Forked process reporting for duty!") - self.function_handler(filename) - sys.exit() - - def check_for_output(self): - new_files = [] - if os.path.isfile(NEW_OUTPUT_CREATED): - os.unlink(NEW_OUTPUT_CREATED) - # So something is created! Now let's snag it - # We insert our additional glob patterns here - files_found = glob.glob("*.hierarchy") #\ - #[glob.glob(pat) for pat in GlobPatterns] - for file in [fn for fn in files_found if fn not in self.skip_files]: - #if self.oc.has_key(os.path.basename(file[:-10])): continue - new_files.append(file.rsplit(".",1)[0]) - mylog.info("Found output %s", new_files[-1]) - return new_files - - def check_for_stop(self): - if os.path.exists("stopFido"): - # We should log this rather than print it - mylog.info("Stopping fido") - os.unlink("stopFido") - return 1 - if self.process: - pp = self.process.poll() - if pp != None: - mylog.info("Process has died; stopping fido") - return 1 - return 0 - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/ParameterFileStorage.py --- a/yt/fido/ParameterFileStorage.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,215 +0,0 @@ -""" -A simple SQLite interface to grabbing and storing parameter files - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.config import ytcfg -from yt.fido import * -from yt.funcs import * -from yt.lagos.ParallelTools import parallel_simple_proxy -import csv -import os.path -from itertools import islice - -output_type_registry = {} -_field_names = ('hash','bn','fp','tt','ctid','class_name','last_seen') - -class NoParameterShelf(Exception): - pass - -class UnknownStaticOutputType(Exception): - def __init__(self, name): - self.name = name - - def __str__(self): - return "%s" % self.name - - def __repr__(self): - return "%s" % self.name - -class ParameterFileStore(object): - - _shared_state = {} - _distributed = True - _processing = False - _owner = 0 - - def __new__(cls, *p, **k): - self = object.__new__(cls, *p, **k) - self.__dict__ = cls._shared_state - return self - - def __init__(self, in_memory = False): - """ - This class is designed to be a semi-persistent storage for parameter - files. By identifying each parameter file with a unique hash, objects - can be stored independently of parameter files -- when an object is - loaded, the parameter file is as well, based on the hash. For - storage concerns, only a few hundred will be retained in cache. - """ - if ytcfg.getboolean("yt", "StoreParameterFiles"): - self._read_only = False - self.init_db() - self._records = self.read_db() - else: - self._read_only = True - self._records = {} - - @parallel_simple_proxy - def init_db(self): - """ - This function ensures that the storage database exists and can be used. - """ - dbn = self._get_db_name() - dbdir = os.path.dirname(dbn) - try: - if not os.path.isdir(dbdir): os.mkdir(dbdir) - except OSError: - raise NoParameterShelf() - open(dbn, 'ab') # make sure it exists, allow to close - # Now we read in all our records and return them - # these will be broadcast - - def _get_db_name(self): - base_file_name = ytcfg.get("yt","ParameterFileStore") - if not os.access(os.path.expanduser("~/"), os.W_OK): - return os.path.abspath(base_file_name) - return os.path.expanduser("~/.yt/%s" % base_file_name) - - def get_pf_hash(self, hash): - """ - This returns a parameter file based on a hash. - """ - return self._convert_pf(self._records[hash]) - - def get_pf_ctid(self, ctid): - """ - This returns a parameter file based on a CurrentTimeIdentifier. - """ - for h in self._records: - if self._records[h]['ctid'] == ctid: - return self._convert_pf(self._records[h]) - - def _adapt_pf(self, pf): - """ - This turns a parameter file into a CSV entry - """ - return dict(bn=pf.basename, - fp=pf.fullpath, - tt=pf["InitialTime"], - ctid=pf["CurrentTimeIdentifier"], - class_name=pf.__class__.__name__, - last_seen=pf._instantiated) - - def _convert_pf(self, pf_dict): - """ - This turns a CSV entry into a parameter file - """ - bn = pf_dict['bn'] - fp = pf_dict['fp'] - fn = os.path.join(fp, bn) - class_name = pf_dict['class_name'] - if class_name not in output_type_registry: - raise UnknownStaticOutputType(class_name) - mylog.info("Checking %s", fn) - if os.path.exists(fn): - pf = output_type_registry[class_name](os.path.join(fp, bn)) - else: - raise IOError - # This next one is to ensure that we manually update the last_seen - # record *now*, for during write_out. - self._records[pf._hash()]['last_seen'] = pf._instantiated - return pf - - def check_pf(self, pf): - """ - This will ensure that the parameter file (*pf*) handed to it is - recorded in the storage unit. In doing so, it will update path - and "last_seen" information. - """ - hash = pf._hash() - if hash not in self._records: - self.insert_pf(pf) - return - pf_dict = self._records[hash] - self._records[hash]['last_seen'] = pf._instantiated - if pf_dict['bn'] != pf.basename \ - or pf_dict['fp'] != pf.fullpath: - self.wipe_hash(hash) - self.insert_pf(pf) - - def insert_pf(self, pf): - """ - This will insert a new *pf* and flush the database to disk. - """ - self._records[pf._hash()] = self._adapt_pf(pf) - self.flush_db() - - def wipe_hash(self, hash): - """ - This removes a *hash* corresponding to a parameter file from the - storage. - """ - if hash not in self._records: return - del self._records[hash] - self.flush_db() - - def flush_db(self): - """ - This flushes the storage to disk. - """ - if self._read_only: return - self._write_out() - self.read_db() - - @parallel_simple_proxy - def _write_out(self): - if self._read_only: return - fn = self._get_db_name() - f = open("%s.tmp" % fn, 'wb') - w = csv.DictWriter(f, _field_names) - maxn = ytcfg.getint("yt","MaximumStoredPFs") # number written - for h,v in islice(sorted(self._records.items(), - key=lambda a: -a[1]['last_seen']), 0, maxn): - v['hash'] = h - w.writerow(v) - f.close() - os.rename("%s.tmp" % fn, fn) - - @parallel_simple_proxy - def read_db(self): - """ - This will read the storage device from disk. - """ - f=open(self._get_db_name(), 'rb') - vals = csv.DictReader(f, _field_names) - db = {} - for v in vals: - db[v.pop('hash')] = v - if v['last_seen'] is None: - v['last_seen'] = 0.0 - else: v['last_seen'] = float(v['last_seen']) - return db - -class ObjectStorage(object): - pass diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/RunStandalones.py --- a/yt/fido/RunStandalones.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,259 +0,0 @@ -""" -This file contains the standalone scripts and their code - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -import optparse -import os, os.path, sys, re, time -from yt.fido import * -import exceptions - -def select_output(collection = None): - if not collection: collection = select_collection() - for i, o in enumerate(collection): - print "%s\t %s" % (i+1,o) - print - loki = int(raw_input("Which output do you want?"))-1 - return collection[loki-1] - -def select_collection(): - cs = GrabCollections() - for i, o in enumerate(cs): - print "%s\t %s" % (i+1,o) - print - loki = int(raw_input("Which collection do you want?"))-1 - return cs[loki-1] - -import optparse - -class FidoAction: - """ - This class defines the skeleton of every action's options. - """ - def __init__(self): - self.parser = optparse.OptionParser( - description=self.description, - version="SVN") - - def SetupParser(self): - pass - - def _guess_collection(self, createNew = False): - tryTitle=os.path.basename(os.getcwd()) - gc = GrabCollections() - for c in gc: - if c.title == tryTitle: - self.oc = c - return - self.oc = None - if createNew: - Import().PerformAction() - self._guess_collection(createNew=False) - - def _parse_args(self): - self.SetupParser() - self.opts, self.args = self.parser.parse_args() - - def PerformAction(self): - pass - - def CleanUp(self): - pass - -class Bury(FidoAction): - description = "Bury an output in a subdirectory" - def __init__(self): - FidoAction.__init__(self) - self._parse_args() - self._guess_collection() - if not self.oc: - # Should we import here? - raise KeyError, "Needs to be imported before you can bury." - - def PerformAction(self): - for bn in self.args: - newName = bury_output(bn) - self.oc.add_output(newName) - self.oc.write_out() - -class DigUp(FidoAction): - description = "Un-bury an output" - def __init__(self): - FidoAction.__init__(self) - self._parse_args() - self._guess_collection() - if not self.oc: - # Should we import here? - raise KeyError, "Needs to be imported before you can bury." - - def SetupParser(self): - self.parser.add_option("-d", "--dest", - action='store', type='string', - dest='new_location', default=os.getcwd()) - - def PerformAction(self): - for bn in self.args: - b = bn - if b.endswith('.dir/'): - b = os.path.join(b, b[:-5]) - elif b.endswith('.dir'): - b = os.path.join(b, b[:-4]) - b = os.path.basename(b) - print b - toGlob = self.oc[b][0] - digup_output(toGlob, new_location=self.opts.new_location) - del self.oc[b] - self.oc.write_out() - -class Branch(FidoAction): - description = "Un-bury an output" - def __init__(self): - FidoAction.__init__(self) - self._parse_args() - if self.opts.new_location == None: - print "You must supply a location for the branching." - print "See --help ." - print - raise KeyError - self._guess_collection() - if not self.oc: - # Should we import here? - raise KeyError, "Needs to be imported before you can branch." - - def SetupParser(self): - self.parser.add_option("-d", "--newdir", - action='store', type='string', - dest='new_location', default=None) - self.parser.add_option("-m", "--metadatastring", - action='store', type='string', - dest='md', default=None) - - def PerformAction(self): - bn = self.args[-1] # only do the last one - # First we copy, then we modify the MDS. Note that we don't need to - # create a new OC. - b = bn - if b.endswith('/'): b = os.path.basename(b) - if b.endswith('.dir'): b = os.path.join(b, b[:-4]) - #print "Copying %s to %s" % (b, self.opts.new_location) - newName=copy_outputs(b, self.opts.new_location) - print newName - #Okay, now that we've copied it... - #First we update the CurrentTimeIdentifier string - expr=re.compile("CurrentTimeIdentifier\s*=\s*[0-9]*$",re.M) - pfContents = open(newName).read() - newId = time.time() - new_pf=expr.sub("CurrentTimeIdentifier = %i" % (newId), pfContents) - expr=re.compile("MetaDataString\s*=\s*.*$",re.M) - if self.opts.md == None: self.opts.md = os.path.basename( - os.path.dirname( - os.path.abspath(newName))) - new_pf=expr.sub("MetaDataString = %s" % (self.opts.md),new_pf) - open(newName,"w").write(new_pf) - -class Import(FidoAction): - description = "Import an existing set of buried outputs" - _matches = ["*.dir/*.hierarchy", "*Dir/*.hierarchy", "RD*/*.hierarchy", - "DD*/*.hierarchy", "moving*/*.hierarchy", "star*/*.hierarchy", - "*.hierarchy"] - def __init__(self, current_path = None, title = None): - if current_path is None: current_path = os.getcwd() - self.current_path = current_path - FidoAction.__init__(self) - self._parse_args() - self._guess_collection() - if title is None: - if self.oc is not None: title = self.oc.title - else: title = os.path.basename(current_path) - self.title = title - if self.oc is None: - self.oc=OutputCollection(self.title) - open(NEW_OUTPUT_CREATED,"w").close() - - def PerformAction(self): - patterns = [os.path.join(self.current_path, m) for m in self._matches] - for p in patterns: - for i in glob.glob(p): self.oc.add_output(os.path.abspath(i[:-10])) - Giles = Watcher(title=self.title, oc=self.oc) - Giles.run(True) - self.oc.write_out() - -class FidoStandalone(FidoAction): - description = "Run Fido, all by itself." - def __init__(self): - FidoAction.__init__(self) - self._parse_args() - self._guess_collection() - self.title = os.path.basename(os.getcwd()) - if self.oc != None: self.title = self.oc.title - - def SetupParser(self): - self.parser.add_option("-s", "--submit", - action='store_true', - dest='submit', default=False) - self.parser.add_option("-c", "--cfg", - action='store', type='string', - dest='cfgFile', default=None) - self.parser.add_option("-p", "--newpath", - action='store', type='string', - dest='new_prefix', default=None) - - def PerformAction(self): - if self.opts.cfgFile != None: func=self.MakePlots - else: func = None - Giles = Watcher(title=self.title, oc=self.oc, function_handler=func, - new_prefix=self.opts.new_prefix) - Giles.run() - self.oc.write_out() - - def MakePlots(self): - import yt.lagos as lagos - import yt.raven as raven - import yt.raven.deliveration as deliverator - imagePath = ytcfg.get("raven", "imagePath", raw=True) - imageSkel = ytcfg.get("raven", "imageSkel", raw=True) - def fidoPlots(fn): - pf = lagos.EnzoStaticOutput(fn) - md = pf["MetaDataString"].strip().rstrip() - if md == "(null)": - fido.error("MetaDataString undefined in parameter file; either use it, or write your own durn function!") - raise KeyError - if self.opts.cfgFile != None: - RunID = -1 - if self.opts.submit: - httpPrefix = ytcfg.get("raven", "httpPrefix", raw=True) - RunID, Response = deliverator.SubmitRun(md, ytcfg.get("Deliverator","user")) - imageDir = imagePath % pf - if not os.path.isdir(imageDir): - os.makedirs(imageDir) - prefix = os.path.join(imageDir, imageSkel) - raven.MakePlots(pf, self.opts.cfgFile, prefix, RunID) - return - return fidoPlots - -def runAction(): - pg = os.path.basename(sys.argv[0]) - acts = {'fbury':Bury, 'fdigup':DigUp, - 'fbranch':Branch, 'fimport':Import, - 'fido':FidoStandalone} - acts[pg]().PerformAction() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/__init__.py --- a/yt/fido/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -""" -Fido is a module for moving and storing data. It is designed to watch for -outputs, as well as transparent archiving them during and after a simulation -run. Additionally, function handlers can be called to deal with output upon -its creation. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.logger import fidoLogger as mylog -from yt.config import ytcfg -from yt.arraytypes import * - -import os, os.path, shutil, time, sys, glob, types - -OTHERFILES=["rates.out","cool_rates.out"] -NEW_OUTPUT_CREATED = ytcfg.get("fido","NewOutputCreated") -GlobPatterns = ytcfg.get("fido","GlobPatterns").split(",") -NewDirectoryPattern = ytcfg.get("fido","NewDirectoryPattern",raw=True) - -# Let's define some useful functions. Maybe these should go elsewhere? - -def get_parameter_line(filename, parameter): - f = open(filename) - lines = filter(lambda a: a.startswith(parameter), f) - if len(lines) == 0: - raise KeyError(parameter) - elif len(lines) > 1: - raise KeyError, "More than one line matches that parameter!" - else: - return lines[0] - -def get_parent_dir(filename): - return os.path.normpath( \ - os.path.split(os.path.dirname(os.path.abspath(filename)))[0]) - -from OutputCollection import * -from FileHandling import * -from OutputWatcher import * -from RunStandalones import * -from ParameterFileStorage import * diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/setup.py --- a/yt/fido/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#!/usr/bin/env python -import setuptools - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('fido',parent_package,top_path) - config.make_config_py() # installs __config__.py - config.make_svn_version_py() - return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/fido/share_data.py --- a/yt/fido/share_data.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -""" -A simple, Enzo-aware interface to drop.io based on another drop.io API. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.config import ytcfg -from yt.mods import * -import zipfile, tempfile, glob, os, stat -from dropio.client import DropIoClient - -API_KEY = ytcfg.get("yt", "dropiokey") - -class SharedDataProduct(object): - _upload_filename = None - _temp_file = None - def upload(self, drop_file_name, drop_name = None): - self._create_archive() - # This is where our drop.io API calls go - client = DropIoClient(API_KEY) - if drop_name is None: - drop = client.create_drop - else: - drop = client.get_drop(drop_name) - if drop is None: drop = client.create_drop(drop_name) - drop_name = drop.name - for asset in client.get_asset_list(drop_name): - if asset.name != drop_file_name: continue - print "FOUND THE DROP FILE NAME IN THE ASSET LIST" - client.delete_asset(drop_name, drop_file_name) - fsize = os.stat(self._temp_file.name)[stat.ST_SIZE] - print "Uploading. Total size is %0.2fMB." % (fsize/(1024*1024)) - print "This may take a considerable amount of time." - asset = client.create_file( - drop_name, self._temp_file.name, - remote_file_name = drop_file_name) - return asset - - def _create_archive(self): - self._temp_file = tempfile.NamedTemporaryFile(mode="wb") - zf = zipfile.ZipFile(self._temp_file, mode='w') - for arcname, fn in self._filenames(): - # Note that this defaults to zipfile.ZIP_STORED as a compression - # method. This might be the safest method, as some platforms have - # trouble with zlib. - print "Adding", arcname, fn - zf.write(fn, arcname) - zf.close() - self._temp_file.flush() - -class SharedStaticOutput(SharedDataProduct): - def __init__(self, pf): - self.pf = pf - - def _filenames(self): - gpatt = glob.glob("%s/%s*" % ( self.pf.fullpath, self.pf.basename)) - arcprefix = os.path.basename(self.pf.fullpath) - print arcprefix - for fn in sorted(gpatt): - aname = os.path.join(arcprefix, os.path.basename(fn)) - yield aname, fn - -class SharedDataStore(SharedDataProduct): - pass diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.frontends + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/chombo/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/chombo/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +""" +API for yt.frontends.chombo + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +Affiliation: MSU +Homepage: http://yt.Chombotools.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 . + +""" + +from .data_structures import \ + ChomboGrid, \ + ChomboHierarchy, \ + ChomboStaticOutput + +from .fields import \ + ChomboFieldContainer, \ + ChomboFieldInfo, \ + add_chombo_field + +from .io import \ + IOHandlerChomboHDF5 diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/chombo/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/chombo/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,221 @@ +""" +Data structures for Chombo. + +Author: Matthew Turk +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2010 Matthew Turk, J. S. Oishi. 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 . +""" + +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 + +from .fields import ChomboFieldContainer + +class ChomboGrid(AMRGridPatch): + _id_offset = 0 + __slots__ = ["_level_id", "stop_index"] + def __init__(self, id, hierarchy, level, start, stop): + AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename, + hierarchy = hierarchy) + self.Parent = [] + self.Children = [] + self.Level = level + self.start_index = start.copy()#.transpose() + self.stop_index = stop.copy()#.transpose() + self.ActiveDimensions = stop - start + 1 + + def _setup_dx(self): + # So first we figure out what the index is. We don't assume + # that dx=dy=dz , at least here. We probably do elsewhere. + id = self.id - self._id_offset + if len(self.Parent) > 0: + self.dds = self.Parent[0].dds / self.pf.refine_by + else: + LE, RE = self.hierarchy.grid_left_edge[id,:], \ + self.hierarchy.grid_right_edge[id,:] + self.dds = na.array((RE-LE)/self.ActiveDimensions) + if self.pf.dimensionality < 2: self.dds[1] = 1.0 + if self.pf.dimensionality < 3: self.dds[2] = 1.0 + self.data['dx'], self.data['dy'], self.data['dz'] = self.dds + +class ChomboHierarchy(AMRHierarchy): + + grid = ChomboGrid + + def __init__(self,pf,data_style='chombo_hdf5'): + self.data_style = data_style + self.field_info = ChomboFieldContainer() + self.field_indexes = {} + self.parameter_file = weakref.proxy(pf) + # for now, the hierarchy file is the parameter file! + self.hierarchy_filename = self.parameter_file.parameter_filename + self.directory = os.path.dirname(self.hierarchy_filename) + self._fhandle = h5py.File(self.hierarchy_filename) + + self.float_type = self._fhandle['/level_0']['data:datatype=0'].dtype.name + self._levels = self._fhandle.listnames()[1:] + AMRHierarchy.__init__(self,pf,data_style) + + self._fhandle.close() + + def _initialize_data_storage(self): + pass + + def _detect_fields(self): + ncomp = int(self._fhandle['/'].attrs['num_components']) + self.field_list = [c[1] for c in self._fhandle['/'].attrs.listitems()[-ncomp:]] + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _count_grids(self): + self.num_grids = 0 + for lev in self._levels: + self.num_grids += self._fhandle[lev]['Processors'].len() + + def _parse_hierarchy(self): + f = self._fhandle # shortcut + + # this relies on the first Group in the H5 file being + # 'Chombo_global' + levels = f.listnames()[1:] + self.grids = [] + i = 0 + for lev in levels: + level_number = int(re.match('level_(\d+)',lev).groups()[0]) + boxes = f[lev]['boxes'].value + dx = f[lev].attrs['dx'] + for level_id, box in enumerate(boxes): + si = na.array([box['lo_%s' % ax] for ax in 'ijk']) + ei = na.array([box['hi_%s' % ax] for ax in 'ijk']) + pg = self.grid(len(self.grids),self,level=level_number, + start = si, stop = ei) + self.grids.append(pg) + self.grids[-1]._level_id = level_id + self.grid_left_edge[i] = dx*si.astype(self.float_type) + self.grid_right_edge[i] = dx*(ei.astype(self.float_type) + 1) + self.grid_particle_count[i] = 0 + self.grid_dimensions[i] = ei - si + 1 + i += 1 + self.grids = na.array(self.grids, dtype='object') + + def _populate_grid_objects(self): + for g in self.grids: + g._prepare_grid() + g._setup_dx() + + for g in self.grids: + g.Children = self._get_grid_children(g) + for g1 in g.Children: + g1.Parent.append(g) + self.max_level = self.grid_levels.max() + + def _setup_unknown_fields(self): + pass + + def _setup_derived_fields(self): + self.derived_field_list = [] + + def _get_grid_children(self, grid): + mask = na.zeros(self.num_grids, dtype='bool') + grids, grid_ind = self.get_box_grids(grid.LeftEdge, grid.RightEdge) + mask[grid_ind] = True + return [g for g in self.grids[mask] if g.Level == grid.Level + 1] + +class ChomboStaticOutput(StaticOutput): + _hierarchy_class = ChomboHierarchy + _fieldinfo_class = ChomboFieldContainer + + def __init__(self, filename, data_style='chombo_hdf5', + storage_filename = None): + StaticOutput.__init__(self,filename,data_style) + self.storage_filename = storage_filename + + self.field_info = self._fieldinfo_class() + # hardcoded for now + self.current_time = 0.0 + # These should be explicitly obtained from the file, but for now that + # will wait until a reorganization of the source tree and better + # generalization. + self.dimensionality = 3 + self.refine_by = 2 + + def _set_units(self): + """ + Generates the conversion to various physical _units based on the parameter file + """ + self.units = {} + self.time_units = {} + if len(self.parameters) == 0: + self._parse_parameter_file() + self._setup_nounits_units() + self.conversion_factors = defaultdict(lambda: 1.0) + self.time_units['1'] = 1 + self.units['1'] = 1.0 + self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() + seconds = 1 #self["Time"] + self.time_units['years'] = seconds / (365*3600*24.0) + self.time_units['days'] = seconds / (3600*24.0) + for key in yt2orionFieldsDict: + self.conversion_factors[key] = 1.0 + + def _setup_nounits_units(self): + z = 0 + mylog.warning("Setting 1.0 in code units to be 1.0 cm") + if not self.has_key("TimeUnits"): + mylog.warning("No time units. Setting 1.0 = 1 second.") + self.conversion_factors["Time"] = 1.0 + for unit in mpc_conversion.keys(): + self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] + + + def _parse_parameter_file(self): + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[ST_CTIME]) + self.domain_left_edge = na.array([0.,0.,0.]) + self.domain_right_edge = self.__calc_right_edge() + + + def __calc_right_edge(self): + fileh = h5py.File(self.parameter_filename,'r') + dx0 = fileh['/level_0'].attrs['dx'] + RE = dx0*((na.array(fileh['/level_0'].attrs['prob_domain']))[3:] + 1) + fileh.close() + return RE + + @classmethod + def _is_valid(self, *args, **kwargs): + try: + fileh = h5py.File(args[0],'r') + if (fileh.listnames())[0] == 'Chombo_global': + return True + except: + pass + return False + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/chombo/definitions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/chombo/definitions.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,25 @@ +""" +Various definitions for various other modules and routines + +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-20010 J.S. Oishi. 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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/chombo/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/chombo/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,113 @@ +""" +Chombo-specific fields + +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2009-2010 J. S. Oishi, 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 . +""" + +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields + +class ChomboFieldContainer(CodeFieldInfoContainer): + _shared_state = {} + _field_list = {} +ChomboFieldInfo = ChomboFieldContainer() +add_chombo_field = ChomboFieldInfo.add_field + +add_field = add_chombo_field + +add_field("density", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("density")], + units=r"\rm{g}/\rm{cm}^3") + +ChomboFieldInfo["density"]._projected_units =r"\rm{g}/\rm{cm}^2" + +add_field("X-momentum", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("X-Momentum")], + units=r"",display_name=r"B_x") +ChomboFieldInfo["X-momentum"]._projected_units=r"" + +add_field("Y-momentum", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("Y-Momentum")], + units=r"",display_name=r"B_y") +ChomboFieldInfo["Y-momentum"]._projected_units=r"" + +add_field("Z-momentum", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("Z-Momentum")], + units=r"",display_name=r"B_z") +ChomboFieldInfo["Z-momentum"]._projected_units=r"" + +add_field("X-magnfield", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("X-Magnfield")], + units=r"",display_name=r"B_x") +ChomboFieldInfo["X-magnfield"]._projected_units=r"" + +add_field("Y-magnfield", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("Y-Magnfield")], + units=r"",display_name=r"B_y") +ChomboFieldInfo["Y-magnfield"]._projected_units=r"" + +add_field("Z-magnfield", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("Z-Magnfield")], + units=r"",display_name=r"B_z") +ChomboFieldInfo["Z-magnfield"]._projected_units=r"" + +def _MagneticEnergy(field,data): + return (data["X-magnfield"]**2 + + data["Y-magnfield"]**2 + + data["Z-magnfield"]**2)/2. +add_field("MagneticEnergy", function=_MagneticEnergy, take_log=True, + units=r"",display_name=r"B^2/8\pi") +ChomboFieldInfo["MagneticEnergy"]._projected_units=r"" + +def _xVelocity(field, data): + """generate x-velocity from x-momentum and density + + """ + return data["X-momentum"]/data["density"] +add_field("x-velocity",function=_xVelocity, take_log=False, + units=r'\rm{cm}/\rm{s}') + +def _yVelocity(field,data): + """generate y-velocity from y-momentum and density + + """ + #try: + # return data["xvel"] + #except KeyError: + return data["Y-momentum"]/data["density"] +add_field("y-velocity",function=_yVelocity, take_log=False, + units=r'\rm{cm}/\rm{s}') + +def _zVelocity(field,data): + """generate z-velocity from z-momentum and density + + """ + return data["Z-momentum"]/data["density"] +add_field("z-velocity",function=_zVelocity, take_log=False, + units=r'\rm{cm}/\rm{s}') + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/chombo/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/chombo/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,68 @@ +""" +The data-file handling functions + +Author: Matthew Turk +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-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 . +""" +from yt.utilities.io_handler import \ + BaseIOHandler + +class IOHandlerChomboHDF5(BaseIOHandler): + _data_style = "chombo_hdf5" + _offset_string = 'data:offsets=0' + _data_string = 'data:datatype=0' + + def _field_dict(self,fhandle): + ncomp = int(fhandle['/'].attrs['num_components']) + temp = fhandle['/'].attrs.listitems()[-ncomp:] + val, keys = zip(*temp) + val = [int(re.match('component_(\d+)',v).groups()[0]) for v in val] + return dict(zip(keys,val)) + + def _read_field_names(self,grid): + fhandle = h5py.File(grid.filename,'r') + ncomp = int(fhandle['/'].attrs['num_components']) + + return [c[1] for c in f['/'].attrs.listitems()[-ncomp:]] + + def _read_data_set(self,grid,field): + fhandle = h5py.File(grid.hierarchy.hierarchy_filename,'r') + + field_dict = self._field_dict(fhandle) + lstring = 'level_%i' % grid.Level + lev = fhandle[lstring] + dims = grid.ActiveDimensions + boxsize = dims.prod() + + grid_offset = lev[self._offset_string][grid._level_id] + start = grid_offset+field_dict[field]*boxsize + stop = start + boxsize + data = lev[self._data_string][start:stop] + + return data.reshape(dims, order='F') + + + def _read_data_slice(self, grid, field, axis, coord): + sl = [slice(None), slice(None), slice(None)] + sl[axis] = slice(coord, coord + 1) + return self._read_data_set(grid,field)[sl] + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/chombo/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/chombo/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('chombo',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,55 @@ +""" +API for yt.frontends.enzo + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .data_structures import \ + EnzoGrid, \ + EnzoGridInMemory, \ + EnzoHierarchy, \ + EnzoHierarchyInMemory, \ + EnzoHierarchy1D, \ + EnzoHierarchy2D, \ + EnzoStaticOutput, \ + EnzoStaticOutputInMemory + +from .fields import \ + EnzoFieldContainer, \ + EnzoFieldInfo, \ + add_enzo_field, \ + add_enzo_1d_field, \ + add_enzo_2d_field + +from .io import \ + IOHandlerEnzoHDF4, \ + IOHandlerEnzoHDF4_2D, \ + IOHandlerEnzoHDF5, \ + IOHandlerPackedHDF5, \ + IOHandlerInMemory, \ + IOHandlerPacked2D, \ + IOHandlerPacked1D diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,936 @@ +""" +Data structures for Enzo + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-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 . +""" + +import h5py +import numpy as na +import os +import stat +import string +import re + +from itertools import izip + +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 +from yt.utilities.definitions import mpc_conversion +from yt.utilities import hdf5_light_reader +from yt.utilities.logger import ytLogger as mylog + +from .definitions import parameterDict +from .fields import EnzoFieldContainer, add_enzo_field + +from yt.utilities.parallel_tools.parallel_analysis_interface import \ + parallel_blocking_call + +class EnzoGrid(AMRGridPatch): + """ + Class representing a single Enzo Grid instance. + """ + + __slots__ = [] + def __init__(self, id, hierarchy): + """ + Returns an instance of EnzoGrid with *id*, associated with + *filename* and *hierarchy*. + """ + #All of the field parameters will be passed to us as needed. + AMRGridPatch.__init__(self, id, filename = None, hierarchy = hierarchy) + self._children_ids = [] + self._parent_id = -1 + self.Level = -1 + + def _guess_properties_from_parent(self): + """ + We know that our grid boundary occurs on the cell boundary of our + parent. This can be a very expensive process, but it is necessary + in some hierarchys, where yt is unable to generate a completely + space-filling tiling of grids, possibly due to the finite accuracy in a + standard Enzo hierarchy file. + """ + rf = self.pf.refine_by + my_ind = self.id - self._id_offset + le = self.LeftEdge + self.dds = self.Parent.dds/rf + ParentLeftIndex = na.rint((self.LeftEdge-self.Parent.LeftEdge)/self.Parent.dds) + self.start_index = rf*(ParentLeftIndex + self.Parent.get_global_startindex()).astype('int64') + self.LeftEdge = self.Parent.LeftEdge + self.Parent.dds * ParentLeftIndex + self.RightEdge = self.LeftEdge + self.ActiveDimensions*self.dds + self.hierarchy.grid_left_edge[my_ind,:] = self.LeftEdge + self.hierarchy.grid_right_edge[my_ind,:] = self.RightEdge + self._child_mask = None + self._child_index_mask = None + self._child_indices = None + self._setup_dx() + + def set_filename(self, filename): + """ + Intelligently set the filename. + """ + if self.hierarchy._strip_path: + self.filename = os.path.join(self.hierarchy.directory, + os.path.basename(filename)) + elif filename[0] == os.path.sep: + self.filename = filename + else: + self.filename = os.path.join(self.hierarchy.directory, filename) + return + + def __repr__(self): + return "EnzoGrid_%04i" % (self.id) + + @property + def Parent(self): + if self._parent_id == -1: return None + return self.hierarchy.grids[self._parent_id - self._id_offset] + + @property + def Children(self): + return [self.hierarchy.grids[cid - self._id_offset] + for cid in self._children_ids] + +class EnzoGridInMemory(EnzoGrid): + __slots__ = ['proc_num'] + def set_filename(self, filename): + pass + +class EnzoHierarchy(AMRHierarchy): + + _strip_path = False + grid = EnzoGrid + + def __init__(self, pf, data_style): + + self.data_style = data_style + self.hierarchy_filename = os.path.abspath( + "%s.hierarchy" % (pf.parameter_filename)) + harray_fn = self.hierarchy_filename[:-9] + "harrays" + if os.path.exists(harray_fn): + try: + harray_fp = h5py.File(harray_fn) + self.num_grids = harray_fp["/Level"].len() + except IOError: + pass + elif os.path.getsize(self.hierarchy_filename) == 0: + raise IOError(-1,"File empty", self.hierarchy_filename) + self.directory = os.path.dirname(self.hierarchy_filename) + + # For some reason, r8 seems to want Float64 + if pf.has_key("CompilerPrecision") \ + and pf["CompilerPrecision"] == "r4": + self.float_type = 'float32' + else: + self.float_type = 'float64' + + AMRHierarchy.__init__(self, pf, data_style) + # sync it back + self.parameter_file.data_style = self.data_style + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _count_grids(self): + test_grid = test_grid_id = None + self.num_stars = 0 + for line in rlines(open(self.hierarchy_filename, "rb")): + if line.startswith("BaryonFileName") or \ + line.startswith("ParticleFileName") or \ + line.startswith("FileName "): + test_grid = line.split("=")[-1].strip().rstrip() + if line.startswith("NumberOfStarParticles"): + self.num_stars = int(line.split("=")[-1]) + if line.startswith("Grid "): + self.num_grids = test_grid_id = int(line.split("=")[-1]) + break + self._guess_data_style(self.pf.dimensionality, test_grid, test_grid_id) + + def _guess_data_style(self, rank, test_grid, test_grid_id): + if test_grid[0] != os.path.sep: + test_grid = os.path.join(self.directory, test_grid) + if not os.path.exists(test_grid): + test_grid = os.path.join(self.directory, + os.path.basename(test_grid)) + mylog.debug("Your data uses the annoying hardcoded path.") + self._strip_path = True + if self.data_style is not None: return + try: + a = SD.SD(test_grid) + self.data_style = 'enzo_hdf4' + mylog.debug("Detected HDF4") + except: + list_of_sets = hdf5_light_reader.ReadListOfDatasets(test_grid, "/") + if len(list_of_sets) == 0 and rank == 3: + mylog.debug("Detected packed HDF5") + self.data_style = 'enzo_packed_3d' + elif len(list_of_sets) > 0 and rank == 3: + mylog.debug("Detected unpacked HDF5") + self.data_style = 'enzo_hdf5' + elif len(list_of_sets) == 0 and rank == 2: + mylog.debug("Detect packed 2D") + self.data_style = 'enzo_packed_2d' + elif len(list_of_sets) == 0 and rank == 1: + mylog.debug("Detect packed 1D") + self.data_style = 'enzo_packed_1d' + else: + raise TypeError + + # Sets are sorted, so that won't work! + def _parse_hierarchy(self): + def _next_token_line(token, f): + line = f.readline() + while token not in line: + line = f.readline() + return line.split()[2:] + if os.path.exists(self.hierarchy_filename[:-9] + "harrays"): + if self._parse_binary_hierarchy(): return + t1 = time.time() + pattern = r"Pointer: Grid\[(\d*)\]->NextGrid(Next|This)Level = (\d*)\s+$" + patt = re.compile(pattern) + f = open(self.hierarchy_filename, "rb") + self.grids = [self.grid(1, self)] + self.grids[0].Level = 0 + si, ei, LE, RE, fn, np = [], [], [], [], [], [] + all = [si, ei, LE, RE, fn] + f.readline() # Blank at top + for grid_id in xrange(self.num_grids): + # We will unroll this list + si.append(_next_token_line("GridStartIndex", f)) + ei.append(_next_token_line("GridEndIndex", f)) + LE.append(_next_token_line("GridLeftEdge", f)) + RE.append(_next_token_line("GridRightEdge", f)) + nb = int(_next_token_line("NumberOfBaryonFields", f)[0]) + fn.append(["-1"]) + if nb > 0: fn[-1] = _next_token_line("BaryonFileName", f) + np.append(int(_next_token_line("NumberOfParticles", f)[0])) + if nb == 0 and np[-1] > 0: fn[-1] = _next_token_line("FileName", f) + line = f.readline() + while len(line) > 2: + if line.startswith("Pointer:"): + vv = patt.findall(line)[0] + self.__pointer_handler(vv) + line = f.readline() + continue + params = line.split() + line = f.readline() + self._fill_arrays(ei, si, LE, RE, np) + self.grids = na.array(self.grids, dtype='object') + self.filenames = fn + self._store_binary_hierarchy() + t2 = time.time() + + def _fill_arrays(self, ei, si, LE, RE, np): + self.grid_dimensions.flat[:] = ei + self.grid_dimensions -= na.array(si, self.float_type) + self.grid_dimensions += 1 + self.grid_left_edge.flat[:] = LE + self.grid_right_edge.flat[:] = RE + self.grid_particle_count.flat[:] = np + + def __pointer_handler(self, m): + sgi = int(m[2])-1 + if sgi == -1: return # if it's 0, then we're done with that lineage + # Okay, so, we have a pointer. We make a new grid, with an id of the length+1 + # (recall, Enzo grids are 1-indexed) + self.grids.append(self.grid(len(self.grids)+1, self)) + # We'll just go ahead and make a weakref to cache + second_grid = self.grids[sgi] # zero-indexed already + first_grid = self.grids[int(m[0])-1] + if m[1] == "Next": + first_grid._children_ids.append(second_grid.id) + second_grid._parent_id = first_grid.id + second_grid.Level = first_grid.Level + 1 + elif m[1] == "This": + if first_grid.Parent is not None: + first_grid.Parent._children_ids.append(second_grid.id) + second_grid._parent_id = first_grid._parent_id + second_grid.Level = first_grid.Level + self.grid_levels[sgi] = second_grid.Level + + _bn = "%s.cpu%%04i" + def _parse_binary_hierarchy(self): + mylog.info("Getting the binary hierarchy") + try: + f = h5py.File(self.hierarchy_filename[:-9] + "harrays") + except h5py.h5.H5Error: + return False + self.grid_dimensions[:] = f["/ActiveDimensions"][:] + self.grid_left_edge[:] = f["/LeftEdges"][:] + self.grid_right_edge[:] = f["/RightEdges"][:] + self.grid_particle_count[:,0] = f["/NumberOfParticles"][:] + levels = f["/Level"][:] + parents = f["/ParentIDs"][:] + procs = f["/Processor"][:] + grids = [] + self.filenames = [] + grids = [self.grid(gi+1, self) for gi in xrange(self.num_grids)] + giter = izip(grids, levels, procs, parents) + bn = self._bn % (self.pf) + pmap = [(bn % P,) for P in xrange(procs.max()+1)] + for grid,L,P,Pid in giter: + grid.Level = L + grid._parent_id = Pid + if Pid > -1: + grids[Pid-1]._children_ids.append(grid.id) + self.filenames.append(pmap[P]) + self.grids = na.array(grids, dtype='object') + f.close() + mylog.info("Finished with binary hierarchy reading") + return True + + @parallel_blocking_call + def _store_binary_hierarchy(self): + # We don't do any of the logic here, we just check if the data file + # is open... + if self._data_file is None: return + if self._data_mode == 'r': return + if self.data_style != "enzo_packed_3d": return + mylog.info("Storing the binary hierarchy") + try: + f = h5py.File(self.hierarchy_filename[:-9] + "harrays", "w") + except IOError: + return + f.create_dataset("/LeftEdges", data=self.grid_left_edge) + f.create_dataset("/RightEdges", data=self.grid_right_edge) + parents, procs, levels = [], [], [] + for i,g in enumerate(self.grids): + if g.Parent is not None: + parents.append(g.Parent.id) + else: + parents.append(-1) + procs.append(int(self.filenames[i][0][-4:])) + levels.append(g.Level) + + parents = na.array(parents, dtype='int64') + procs = na.array(procs, dtype='int64') + levels = na.array(levels, dtype='int64') + f.create_dataset("/ParentIDs", data=parents) + f.create_dataset("/Processor", data=procs) + f.create_dataset("/Level", data=levels) + + f.create_dataset("/ActiveDimensions", data=self.grid_dimensions) + f.create_dataset("/NumberOfParticles", data=self.grid_particle_count[:,0]) + + f.close() + + def _rebuild_top_grids(self, level = 0): + #for level in xrange(self.max_level+1): + mylog.info("Rebuilding grids on level %s", level) + cmask = (self.grid_levels.flat == (level + 1)) + cmsum = cmask.sum() + mask = na.zeros(self.num_grids, dtype='bool') + for grid in self.select_grids(level): + mask[:] = 0 + LE = self.grid_left_edge[grid.id - grid._id_offset] + RE = self.grid_right_edge[grid.id - grid._id_offset] + grids, grid_i = self.get_box_grids(LE, RE) + mask[grid_i] = 1 + grid._children_ids = [] + cgrids = self.grids[ ( mask * cmask).astype('bool') ] + mylog.info("%s: %s / %s", grid, len(cgrids), cmsum) + for cgrid in cgrids: + grid._children_ids.append(cgrid.id) + cgrid._parent_id = grid.id + mylog.info("Finished rebuilding") + + def _populate_grid_objects(self): + for g,f in izip(self.grids, self.filenames): + g._prepare_grid() + g._setup_dx() + g.set_filename(f[0]) + #if g.Parent is not None: g._guess_properties_from_parent() + del self.filenames # No longer needed. + self.max_level = self.grid_levels.max() + + def _detect_fields(self): + self.field_list = [] + # Do this only on the root processor to save disk work. + if self._mpi_get_rank() == 0 or self._mpi_get_rank() == None: + field_list = self.get_data("/", "DataFields") + if field_list is None: + mylog.info("Gathering a field list (this may take a moment.)") + field_list = set() + random_sample = self._generate_random_grids() + for grid in random_sample: + if not hasattr(grid, 'filename'): continue + try: + gf = self.io._read_field_names(grid) + except self.io._read_exception: + mylog.debug("Grid %s is a bit funky?", grid.id) + continue + mylog.debug("Grid %s has: %s", grid.id, gf) + field_list = field_list.union(gf) + else: + field_list = None + field_list = self._mpi_bcast_pickled(field_list) + self.save_data(list(field_list),"/","DataFields",passthrough=True) + self.field_list = list(field_list) + + def _setup_unknown_fields(self): + for field in self.field_list: + if field in self.parameter_file.field_info: continue + mylog.info("Adding %s to list of fields", field) + cf = None + if self.parameter_file.has_key(field): + def external_wrapper(f): + def _convert_function(data): + return data.convert(f) + return _convert_function + cf = external_wrapper(field) + add_enzo_field(field, lambda a, b: None, + convert_function=cf, take_log=False) + + def _setup_derived_fields(self): + self.derived_field_list = [] + for field in self.parameter_file.field_info: + try: + fd = self.parameter_file.field_info[field].get_dependencies( + pf = self.parameter_file) + except: + continue + available = na.all([f in self.field_list for f in fd.requested]) + if available: self.derived_field_list.append(field) + for field in self.field_list: + if field not in self.derived_field_list: + self.derived_field_list.append(field) + + def _generate_random_grids(self): + if self.num_grids > 40: + starter = na.random.randint(0, 20) + random_sample = na.mgrid[starter:len(self.grids)-1:20j].astype("int32") + mylog.debug("Checking grids: %s", random_sample.tolist()) + else: + random_sample = na.mgrid[0:max(len(self.grids)-1,1)].astype("int32") + return self.grids[(random_sample,)] + + def find_particles_by_type(self, ptype, max_num=None, additional_fields=None): + """ + Returns a structure of arrays with all of the particles' + positions, velocities, masses, types, IDs, and attributes for + a particle type **ptype** for a maximum of **max_num** + particles. If non-default particle fields are used, provide + them in **additional_fields**. + """ + # Not sure whether this routine should be in the general HierarchyType. + if self.grid_particle_count.sum() == 0: + mylog.info("Data contains no particles."); + return None + if additional_fields is None: + additional_fields = ['metallicity_fraction', 'creation_time', + 'dynamical_time'] + pfields = [f for f in self.field_list if f.startswith('particle_')] + nattr = self.parameter_file['NumberOfParticleAttributes'] + if nattr > 0: + pfields += additional_fields[:nattr] + # Find where the particles reside and count them + if max_num is None: max_num = 1e100 + total = 0 + pstore = [] + for level in range(self.max_level, -1, -1): + for grid in self.select_grids(level): + index = na.where(grid['particle_type'] == ptype)[0] + total += len(index) + pstore.append(index) + if total >= max_num: break + if total >= max_num: break + result = None + if total > 0: + result = {} + for p in pfields: + result[p] = na.zeros(total, 'float64') + # Now we retrieve data for each field + ig = count = 0 + for level in range(self.max_level, -1, -1): + for grid in self.select_grids(level): + nidx = len(pstore[ig]) + if nidx > 0: + for p in pfields: + result[p][count:count+nidx] = grid[p][pstore[ig]] + count += nidx + ig += 1 + if count >= total: break + if count >= total: break + # Crop data if retrieved more than max_num + if count > max_num: + for p in pfields: + result[p] = result[p][0:max_num] + return result + + +class EnzoHierarchyInMemory(EnzoHierarchy): + + grid = EnzoGridInMemory + _enzo = None + + @property + def enzo(self): + if self._enzo is None: + import enzo + self._enzo = enzo + return self._enzo + + def __init__(self, pf, data_style = None): + self.data_style = data_style + self.float_type = 'float64' + self.parameter_file = weakref.proxy(pf) # for _obtain_enzo + self.float_type = self.enzo.hierarchy_information["GridLeftEdge"].dtype + self.directory = os.getcwd() + AMRHierarchy.__init__(self, pf, data_style) + + def _initialize_data_storage(self): + pass + + def _count_grids(self): + self.num_grids = self.enzo.hierarchy_information["GridDimensions"].shape[0] + + def _parse_hierarchy(self): + self._copy_hierarchy_structure() + mylog.debug("Copying reverse tree") + reverse_tree = self.enzo.hierarchy_information["GridParentIDs"].ravel().tolist() + # Initial setup: + mylog.debug("Reconstructing parent-child relationships") + self.grids = [] + # We enumerate, so it's 0-indexed id and 1-indexed pid + self.filenames = ["-1"] * self.num_grids + for id,pid in enumerate(reverse_tree): + self.grids.append(self.grid(id+1, self)) + self.grids[-1].Level = self.grid_levels[id] + if pid > 0: + self.grids[-1]._parent_id = pid + self.grids[pid-1]._children_ids.append(self.grids[-1].id) + self.max_level = self.grid_levels.max() + mylog.debug("Preparing grids") + for i, grid in enumerate(self.grids): + if (i%1e4) == 0: mylog.debug("Prepared % 7i / % 7i grids", i, self.num_grids) + grid.filename = None + grid._prepare_grid() + grid.proc_num = self.grid_procs[i,0] + self.grids = na.array(self.grids, dtype='object') + mylog.debug("Prepared") + + def _initialize_grid_arrays(self): + EnzoHierarchy._initialize_grid_arrays(self) + self.grid_procs = na.zeros((self.num_grids,1),'int32') + + def _copy_hierarchy_structure(self): + # Dimensions are important! + self.grid_dimensions[:] = self.enzo.hierarchy_information["GridEndIndices"][:] + self.grid_dimensions -= self.enzo.hierarchy_information["GridStartIndices"][:] + self.grid_dimensions += 1 + self.grid_left_edge[:] = self.enzo.hierarchy_information["GridLeftEdge"][:] + self.grid_right_edge[:] = self.enzo.hierarchy_information["GridRightEdge"][:] + self.grid_levels[:] = self.enzo.hierarchy_information["GridLevels"][:] + self.grid_procs = self.enzo.hierarchy_information["GridProcs"].copy() + self.grid_particle_count[:] = self.enzo.hierarchy_information["GridNumberOfParticles"][:] + + def save_data(self, *args, **kwargs): + pass + +class EnzoHierarchy1D(EnzoHierarchy): + + def _fill_arrays(self, ei, si, LE, RE, np): + self.grid_dimensions[:,:1] = ei + self.grid_dimensions[:,:1] -= na.array(si, self.float_type) + self.grid_dimensions += 1 + self.grid_left_edge[:,:1] = LE + self.grid_right_edge[:,:1] = RE + self.grid_particle_count.flat[:] = np + self.grid_left_edge[:,1:] = 0.0 + self.grid_right_edge[:,1:] = 1.0 + self.grid_dimensions[:,1:] = 1 + +class EnzoHierarchy2D(EnzoHierarchy): + + def _fill_arrays(self, ei, si, LE, RE, np): + self.grid_dimensions[:,:2] = ei + self.grid_dimensions[:,:2] -= na.array(si, self.float_type) + self.grid_dimensions += 1 + self.grid_left_edge[:,:2] = LE + self.grid_right_edge[:,:2] = RE + self.grid_particle_count.flat[:] = np + self.grid_left_edge[:,2] = 0.0 + self.grid_right_edge[:,2] = 1.0 + self.grid_dimensions[:,2] = 1 + +class EnzoStaticOutput(StaticOutput): + """ + Enzo-specific output, set at a fixed time. + """ + _hierarchy_class = EnzoHierarchy + _fieldinfo_class = EnzoFieldContainer + def __init__(self, filename, data_style=None, + parameter_override = None, + conversion_override = None, + storage_filename = None): + """ + This class is a stripped down class that simply reads and parses + *filename* without looking at the hierarchy. *data_style* gets passed + to the hierarchy to pre-determine the style of data-output. However, + it is not strictly necessary. Optionally you may specify a + *parameter_override* dictionary that will override anything in the + paarmeter file and a *conversion_override* dictionary that consists + of {fieldname : conversion_to_cgs} that will override the #DataCGS. + """ + if parameter_override is None: parameter_override = {} + self.__parameter_override = parameter_override + if conversion_override is None: conversion_override = {} + self.__conversion_override = conversion_override + self.storage_filename = storage_filename + + StaticOutput.__init__(self, filename, data_style) + if "InitialTime" not in self.parameters: + self.current_time = 0.0 + rp = os.path.join(self.directory, "rates.out") + if os.path.exists(rp): + try: + self.rates = EnzoTable(rp, rates_out_key) + except: + pass + cp = os.path.join(self.directory, "cool_rates.out") + if os.path.exists(cp): + try: + self.cool = EnzoTable(cp, cool_out_key) + except: + pass + + # Now fixes for different types of Hierarchies + # This includes changing the fieldinfo class! + if self["TopGridRank"] == 1: self._setup_1d() + elif self["TopGridRank"] == 2: self._setup_2d() + + self.field_info = self._fieldinfo_class() + + def _setup_1d(self): + self._hierarchy_class = EnzoHierarchy1D + self._fieldinfo_class = Enzo1DFieldContainer + self.domain_left_edge = \ + na.concatenate([self["DomainLeftEdge"], [0.0, 0.0]]) + self.domain_right_edge = \ + na.concatenate([self["DomainRightEdge"], [1.0, 1.0]]) + + def _setup_2d(self): + self._hierarchy_class = EnzoHierarchy2D + self._fieldinfo_class = Enzo2DFieldContainer + self.domain_left_edge = \ + na.concatenate([self["DomainLeftEdge"], [0.0]]) + self.domain_right_edge = \ + na.concatenate([self["DomainRightEdge"], [1.0]]) + + def get_parameter(self,parameter,type=None): + """ + Gets a parameter not in the parameterDict. + """ + if self.parameters.has_key(parameter): + return self.parameters[parameter] + + # Let's read the file + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[stat.ST_CTIME]) + lines = open(self.parameter_filename).readlines() + for lineI, line in enumerate(lines): + if line.find("#") >= 1: # Keep the commented lines + line=line[:line.find("#")] + line=line.strip().rstrip() + if len(line) < 2: + continue + try: + param, vals = map(string.strip,map(string.rstrip, + line.split("="))) + except ValueError: + mylog.error("ValueError: '%s'", line) + if parameter == param: + if type is None: + t = vals.split() + else: + t = map(type, vals.split()) + if len(t) == 1: + self.parameters[param] = t[0] + else: + self.parameters[param] = t + if param.endswith("Units") and not param.startswith("Temperature"): + dataType = param[:-5] + self.conversion_factors[dataType] = self.parameters[param] + return self.parameters[parameter] + + return "" + + def _parse_parameter_file(self): + """ + Parses the parameter file and establishes the various + dictionaries. + """ + # Let's read the file + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[stat.ST_CTIME]) + lines = open(self.parameter_filename).readlines() + for lineI, line in enumerate(lines): + if line.find("#") >= 1: # Keep the commented lines + line=line[:line.find("#")] + line=line.strip().rstrip() + if len(line) < 2: + continue + try: + param, vals = map(string.strip,map(string.rstrip, + line.split("="))) + except ValueError: + mylog.error("ValueError: '%s'", line) + if parameterDict.has_key(param): + t = map(parameterDict[param], vals.split()) + if len(t) == 1: + self.parameters[param] = t[0] + else: + self.parameters[param] = t + if param.endswith("Units") and not param.startswith("Temperature"): + dataType = param[:-5] + self.conversion_factors[dataType] = self.parameters[param] + elif param.startswith("#DataCGS"): + # Assume of the form: #DataCGSConversionFactor[7] = 2.38599e-26 g/cm^3 + if lines[lineI-1].find("Label") >= 0: + kk = lineI-1 + elif lines[lineI-2].find("Label") >= 0: + kk = lineI-2 + dataType = lines[kk].split("=")[-1].rstrip().strip() + convFactor = float(line.split("=")[-1].split()[0]) + self.conversion_factors[dataType] = convFactor + elif param.startswith("#CGSConversionFactor"): + dataType = param[20:].rstrip() + convFactor = float(line.split("=")[-1]) + self.conversion_factors[dataType] = convFactor + elif param.startswith("DomainLeftEdge"): + self.domain_left_edge = \ + self.parameters["DomainLeftEdge"] = \ + na.array([float(i) for i in vals.split()]) + elif param.startswith("DomainRightEdge"): + self.domain_right_edge = \ + self.parameters["DomainRightEdge"] = \ + na.array([float(i) for i in vals.split()]) + for p, v in self.__parameter_override.items(): + self.parameters[p] = v + for p, v in self.__conversion_override.items(): + self.conversion_factors[p] = v + self.refine_by = self.parameters["RefineBy"] + self.dimensionality = self.parameters["TopGridRank"] + self.domain_dimensions = self.parameters["TopGridDimensions"] + self.current_time = self.parameters["InitialTime"] + if "CurrentTimeIdentifier" in self.parameters: + self.unique_identifier = self.parameters["CurrentTimeIdentifier"] + if self.parameters["ComovingCoordinates"]: + self.cosmological_simulation = 0 + self.current_redshift = self.parameters["CosmologyCurrentRedshift"] + self.omega_lambda = self.parameters["CosmologyOmegaLambdaNow"] + self.omega_matter = self.parameters["CosmologyOmegaMatterNow"] + self.hubble_constant = self.parameters["CosmologyHubbleConstantNow"] + else: + self.current_redshift = self.omega_lambda = self.omega_matter = \ + self.hubble_constant = self.cosmological_simulation = 0.0 + + def _set_units(self): + """ + Generates the conversion to various physical _units based on the parameter file + """ + self.units = {} + self.time_units = {} + if len(self.parameters) == 0: + self._parse_parameter_file() + if "EOSType" not in self.parameters: self.parameters["EOSType"] = -1 + if self["ComovingCoordinates"]: + self._setup_comoving_units() + elif self.has_key("LengthUnit"): + # 'Why share when we can reinvent incompatibly?' + self.parameters["LengthUnits"] = self["LengthUnit"] + self._setup_getunits_units() + elif self.has_key("LengthUnits"): + self._setup_getunits_units() + else: + self._setup_nounits_units() + self.time_units['1'] = 1 + self.units['1'] = 1 + self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() + seconds = self["Time"] + self.time_units['years'] = seconds / (365*3600*24.0) + self.time_units['days'] = seconds / (3600*24.0) + + def _setup_comoving_units(self): + z = self["CosmologyCurrentRedshift"] + h = self["CosmologyHubbleConstantNow"] + boxcm_cal = self["CosmologyComovingBoxSize"] + boxcm_uncal = boxcm_cal / h + box_proper = boxcm_uncal/(1+z) + self.units['aye'] = (1.0 + self["CosmologyInitialRedshift"])/(z + 1.0) + if not self.has_key("Time"): + cu = self.cosmology_get_units() + self.conversion_factors["Time"] = cu['utim'] + for unit in mpc_conversion: + self.units[unit] = mpc_conversion[unit] * box_proper + self.units[unit+'h'] = mpc_conversion[unit] * box_proper * h + self.units[unit+'cm'] = mpc_conversion[unit] * boxcm_uncal + self.units[unit+'hcm'] = mpc_conversion[unit] * boxcm_cal + + def _setup_getunits_units(self): + # We are given LengthUnits, which is number of cm per box length + # So we convert that to box-size in Mpc + box_proper = 3.24077e-25 * self["LengthUnits"] + self.units['aye'] = 1.0 + for unit in mpc_conversion.keys(): + self.units[unit] = mpc_conversion[unit] * box_proper + if not self.has_key("TimeUnits"): + self.conversion_factors["Time"] = self["LengthUnits"] / self["x-velocity"] + + def _setup_nounits_units(self): + z = 0 + mylog.warning("Setting 1.0 in code units to be 1.0 cm") + if not self.has_key("TimeUnits"): + mylog.warning("No time units. Setting 1.0 = 1 second.") + self.conversion_factors["Time"] = 1.0 + for unit in mpc_conversion.keys(): + self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] + + def cosmology_get_units(self): + """ + Return an Enzo-fortran style dictionary of units to feed into custom + routines. This is typically only necessary if you are interacting + with fortran code. + """ + k = {} + k["utim"] = 2.52e17/na.sqrt(self.omega_matter)\ + / self.hubble_constant \ + / (1+self.parameters["CosmologyInitialRedshift"])**1.5 + k["urho"] = 1.88e-29 * self.omega_matter \ + * self.hubble_constant**2 \ + * (1.0 + self.current_redshift)**3 + k["uxyz"] = 3.086e24 * \ + self.parameters["CosmologyComovingBoxSize"] / \ + self.hubble_constant / \ + (1.0 + self.current_redshift) + k["uaye"] = 1.0/(1.0 + self.parameters["CosmologyInitialRedshift"]) + k["uvel"] = 1.225e7*self.parameters["CosmologyComovingBoxSize"] \ + *na.sqrt(self.omega_matter) \ + *na.sqrt(1+ self.parameters["CosmologyInitialRedshift"]) + k["utem"] = 1.88e6 * (self.parameters["CosmologyComovingBoxSize"]**2) \ + * self.omega_matter \ + * (1.0 + self.parameters["CosmologyInitialRedshift"]) + k["aye"] = (1.0 + self.parameters["CosmologyInitialRedshift"]) / \ + (1.0 + self.current_redshift) + return k + + @classmethod + def _is_valid(cls, *args, **kwargs): + return os.path.exists("%s.hierarchy" % args[0]) + +class EnzoStaticOutputInMemory(EnzoStaticOutput): + _hierarchy_class = EnzoHierarchyInMemory + _data_style = 'enzo_inline' + + def __new__(cls, *args, **kwargs): + obj = object.__new__(cls) + obj.__init__(*args, **kwargs) + return obj + + def __init__(self, parameter_override=None, conversion_override=None): + if parameter_override is None: parameter_override = {} + self.__parameter_override = parameter_override + if conversion_override is None: conversion_override = {} + self.__conversion_override = conversion_override + + StaticOutput.__init__(self, "InMemoryParameterFile", self._data_style) + + self.field_info = self._fieldinfo_class() + + def _parse_parameter_file(self): + enzo = self._obtain_enzo() + self.basename = "cycle%08i" % ( + enzo.yt_parameter_file["NumberOfPythonCalls"]) + self.parameters['CurrentTimeIdentifier'] = time.time() + self.parameters.update(enzo.yt_parameter_file) + self.conversion_factors.update(enzo.conversion_factors) + for i in self.parameters: + if isinstance(self.parameters[i], types.TupleType): + self.parameters[i] = na.array(self.parameters[i]) + if i.endswith("Units") and not i.startswith("Temperature"): + dataType = i[:-5] + self.conversion_factors[dataType] = self.parameters[i] + for i in self.conversion_factors: + if isinstance(self.conversion_factors[i], types.TupleType): + self.conversion_factors[i] = na.array(self.conversion_factors[i]) + for p, v in self.__parameter_override.items(): + self.parameters[p] = v + for p, v in self.__conversion_override.items(): + self.conversion_factors[p] = v + + def _obtain_enzo(self): + import enzo; return enzo + + @classmethod + def _is_valid(cls, *args, **kwargs): + return False + +# These next two functions are taken from +# http://www.reddit.com/r/Python/comments/6hj75/reverse_file_iterator/c03vms4 +# Credit goes to "Brian" on Reddit + +def rblocks(f, blocksize=4096): + """Read file as series of blocks from end of file to start. + + The data itself is in normal order, only the order of the blocks is reversed. + ie. "hello world" -> ["ld","wor", "lo ", "hel"] + Note that the file must be opened in binary mode. + """ + if 'b' not in f.mode.lower(): + raise Exception("File must be opened using binary mode.") + size = os.stat(f.name).st_size + fullblocks, lastblock = divmod(size, blocksize) + + # The first(end of file) block will be short, since this leaves + # the rest aligned on a blocksize boundary. This may be more + # efficient than having the last (first in file) block be short + f.seek(-lastblock,2) + yield f.read(lastblock) + + for i in range(fullblocks-1,-1, -1): + f.seek(i * blocksize) + yield f.read(blocksize) + +def rlines(f, keepends=False): + """Iterate through the lines of a file in reverse order. + + If keepends is true, line endings are kept as part of the line. + """ + buf = '' + for block in rblocks(f): + buf = block + buf + lines = buf.splitlines(keepends) + # Return all lines except the first (since may be partial) + if lines: + lines.reverse() + buf = lines.pop() # Last line becomes end of new first line. + for line in lines: + yield line + yield buf # First line. + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/definitions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/definitions.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,58 @@ +""" +Definitions specific to Enzo + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ + +License: + Copyright (C) 2007-2009 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 . +""" + +parameterDict = {"CosmologyCurrentRedshift": float, + "CosmologyComovingBoxSize": float, + "CosmologyOmegaMatterNow": float, + "CosmologyOmegaLambdaNow": float, + "CosmologyHubbleConstantNow": float, + "CosmologyInitialRedshift": float, + "DualEnergyFormalismEta1": float, + "DualEnergyFormalismEta2": float, + "MetaDataString": str, + "HydroMethod": int, + "DualEnergyFormalism": int, + "InitialTime": float, + "ComovingCoordinates": int, + "DensityUnits": float, + "LengthUnits": float, + "LengthUnit": float, + "TemperatureUnits": float, + "TimeUnits": float, + "GravitationalConstant": float, + "Gamma": float, + "MultiSpecies": int, + "CompilerPrecision": str, + "CurrentTimeIdentifier": int, + "RefineBy": int, + "BoundaryConditionName": str, + "TopGridRank": int, + "TopGridDimensions": int, + "EOSSoundSpeed": float, + "EOSType": int, + "NumberOfParticleAttributes": int, + } + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,463 @@ +""" +Fields specific to Enzo + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-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 . +""" + +import numpy as na + +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields +from yt.utilities.physical_constants import \ + mh +import yt.utilities.amr_utils as amr_utils + +class EnzoFieldContainer(CodeFieldInfoContainer): + """ + This is a container for Enzo-specific fields. + """ + _shared_state = {} + _field_list = {} +EnzoFieldInfo = EnzoFieldContainer() +add_enzo_field = EnzoFieldInfo.add_field + +add_field = add_enzo_field + +_speciesList = ["HI","HII","Electron", + "HeI","HeII","HeIII", + "H2I","H2II","HM", + "DI","DII","HDI","Metal","PreShock"] +_speciesMass = {"HI":1.0,"HII":1.0,"Electron":1.0, + "HeI":4.0,"HeII":4.0,"HeIII":4.0, + "H2I":2.0,"H2II":2.0,"HM":1.0, + "DI":2.0,"DII":2.0,"HDI":3.0} + +def _SpeciesComovingDensity(field, data): + sp = field.name.split("_")[0] + "_Density" + ef = (1.0 + data.pf.current_redshift)**3.0 + return data[sp]/ef +def _SpeciesFraction(field, data): + sp = field.name.split("_")[0] + "_Density" + return data[sp]/data["Density"] +def _SpeciesNumberDensity(field, data): + species = field.name.split("_")[0] + sp = field.name.split("_")[0] + "_Density" + return data[sp]/_speciesMass[species] +def _ConvertNumberDensity(data): + return 1.0/mh + +for species in _speciesList: + add_field("%s_Fraction" % species, + function=_SpeciesFraction, + validators=ValidateDataField("%s_Density" % species)) + add_field("Comoving_%s_Density" % species, + function=_SpeciesComovingDensity, + validators=ValidateDataField("%s_Density" % species)) + if _speciesMass.has_key(species): + add_field("%s_NumberDensity" % species, + function=_SpeciesNumberDensity, + convert_function=_ConvertNumberDensity, + validators=ValidateDataField("%s_Density" % species)) + +def _Metallicity(field, data): + return data["Metal_Fraction"] +def _ConvertMetallicity(data): + return 49.0196 # 1 / 0.0204 +add_field("Metallicity", units=r"Z_{\rm{\odot}}", + function=_Metallicity, + convert_function=_ConvertMetallicity, + validators=ValidateDataField("Metal_Density"), + projection_conversion="1") + +def _Metallicity3(field, data): + return data["SN_Colour"]/data["Density"] +add_field("Metallicity3", units=r"Z_{\rm{\odot}}", + function=_Metallicity3, + convert_function=_ConvertMetallicity, + validators=ValidateDataField("SN_Colour"), + projection_conversion="1") + +def _Cooling_Time(field, data): + return data["Cooling_Time"] +add_field("Cooling_Time", units=r"\rm{s}", + function=_Cooling_Time, + validators=ValidateDataField("Cooling_Time"), + projection_conversion="1") + +def _ThermalEnergy(field, data): + if data.pf["HydroMethod"] == 2: + return data["Total_Energy"] + else: + if data.pf["DualEnergyFormalism"]: + return data["GasEnergy"] + else: + return data["Total_Energy"] - 0.5*( + data["x-velocity"]**2.0 + + data["y-velocity"]**2.0 + + data["z-velocity"]**2.0 ) +add_field("ThermalEnergy", function=_ThermalEnergy, + units=r"\rm{ergs}/\rm{cm^3}") + +def _KineticEnergy(field, data): + return 0.5*data["Density"] * ( data["x-velocity"]**2.0 + + data["y-velocity"]**2.0 + + data["z-velocity"]**2.0 ) +add_field("KineticEnergy",function=_KineticEnergy, + units = r"\rm{ergs}/\rm{cm^3}") +# This next section is the energy field section +# Note that we have aliases that manually unconvert themselves. +# This is because numerous code branches use Gas_Energy or GasEnergy +# indiscriminately -- this is almost fixed with LCA1.5, but not everyone is +# moving to that branch. So, because the actual function doesn't get called +# *unless* it's an alias, we simply de-convert -- since the input data is +# already converted to cgs. + +def _convertEnergy(data): + return data.convert("x-velocity")**2.0 + +def _GasEnergy(field, data): + return data["Gas_Energy"] / _convertEnergy(data) +add_field("GasEnergy", function=_GasEnergy, + units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) + +def _Gas_Energy(field, data): + return data["GasEnergy"] / _convertEnergy(data) +add_field("Gas_Energy", function=_Gas_Energy, + units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) + +def _TotalEnergy(field, data): + return data["Total_Energy"] / _convertEnergy(data) +add_field("TotalEnergy", function=_TotalEnergy, + display_name = "\mathrm{Total}\/\mathrm{Energy}", + units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) + +def _Total_Energy(field, data): + return data["TotalEnergy"] / _convertEnergy(data) +add_field("Total_Energy", function=_Total_Energy, + display_name = "\mathrm{Total}\/\mathrm{Energy}", + units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) + +def _NumberDensity(field, data): + # We can assume that we at least have Density + # We should actually be guaranteeing the presence of a .shape attribute, + # but I am not currently implementing that + fieldData = na.zeros(data["Density"].shape, + dtype = data["Density"].dtype) + if data.pf["MultiSpecies"] == 0: + if data.has_field_parameter("mu"): + mu = data.get_field_parameter("mu") + else: + mu = 0.6 + fieldData += data["Density"] / mu + if data.pf["MultiSpecies"] > 0: + fieldData += data["HI_Density"] / 1.0 + fieldData += data["HII_Density"] / 1.0 + fieldData += data["HeI_Density"] / 4.0 + fieldData += data["HeII_Density"] / 4.0 + fieldData += data["HeIII_Density"] / 4.0 + fieldData += data["Electron_Density"] / 1.0 + if data.pf["MultiSpecies"] > 1: + fieldData += data["HM_Density"] / 1.0 + fieldData += data["H2I_Density"] / 2.0 + fieldData += data["H2II_Density"] / 2.0 + if data.pf["MultiSpecies"] > 2: + fieldData += data["DI_Density"] / 2.0 + fieldData += data["DII_Density"] / 2.0 + fieldData += data["HDI_Density"] / 3.0 + return fieldData +add_field("NumberDensity", units=r"\rm{cm}^{-3}", + function=_NumberDensity, + convert_function=_ConvertNumberDensity) + +def _ComovingDensity(field,data): + ef = (1.0 + data.pf.current_redshift)**3.0 + return data["Density"]/ef +add_field("ComovingDensity", function=_ComovingDensity, units=r"\rm{g}/\rm{cm}^3") + +def Overdensity(field,data): + return (data['Density'] + data['Dark_Matter_Density']) / \ + (rho_crit_now * (data.pf.hubble_constant**2) * ((1+data.pf.current_redshift)**3)) +add_field("Overdensity",function=Overdensity,units=r"") + +# Now we add all the fields that we want to control, but we give a null function +# This is every Enzo field we can think of. This will be installation-dependent, + +# removed: "Gas_Energy","Total_Energy", +# these are now aliases for each other + +_default_fields = ["Density","Temperature", + "x-velocity","y-velocity","z-velocity", + "x-momentum","y-momentum","z-momentum"] +# else: +# _default_fields = ["Density","Temperature","Gas_Energy","Total_Energy", +# "x-velocity","y-velocity","z-velocity"] +_default_fields += [ "%s_Density" % sp for sp in _speciesList ] + +for field in _default_fields: + add_field(field, function=lambda a, b: None, take_log=True, + validators=[ValidateDataField(field)], units=r"\rm{g}/\rm{cm}^3") +EnzoFieldInfo["x-velocity"].projection_conversion='1' +EnzoFieldInfo["y-velocity"].projection_conversion='1' +EnzoFieldInfo["z-velocity"].projection_conversion='1' + +# Now we override + +def _convertDensity(data): + return data.convert("Density") +for field in ["Density"] + [ "%s_Density" % sp for sp in _speciesList ]: + EnzoFieldInfo[field]._units = r"\rm{g}/\rm{cm}^3" + EnzoFieldInfo[field]._projected_units = r"\rm{g}/\rm{cm}^2" + EnzoFieldInfo[field]._convert_function=_convertDensity + +add_field("Dark_Matter_Density", function=lambda a,b: None, + convert_function=_convertDensity, + validators=[ValidateDataField("Dark_Matter_Density"), + ValidateSpatial(0)], + display_name = "Dark\ Matter\ Density", + not_in_all = True) + +EnzoFieldInfo["Temperature"]._units = r"\rm{K}" +EnzoFieldInfo["Temperature"].units = r"K" + +def _convertVelocity(data): + return data.convert("x-velocity") +for ax in ['x','y','z']: + f = EnzoFieldInfo["%s-velocity" % ax] + f._units = r"\rm{cm}/\rm{s}" + f._convert_function = _convertVelocity + f.take_log = False + +def _pdensity(field, data): + blank = na.zeros(data.ActiveDimensions, dtype='float32') + if data.NumberOfParticles == 0: return blank + amr_utils.CICDeposit_3(data["particle_position_x"].astype(na.float64), + data["particle_position_y"].astype(na.float64), + data["particle_position_z"].astype(na.float64), + data["particle_mass"].astype(na.float32), + data["particle_mass"].size, + blank, na.array(data.LeftEdge).astype(na.float64), + na.array(data.ActiveDimensions).astype(na.int32), + na.float64(data['dx'])) + return blank +add_field("particle_density", function=_pdensity, + validators=[ValidateSpatial(0)], convert_function=_convertDensity) + +def _spdensity(field, data): + blank = na.zeros(data.ActiveDimensions, dtype='float32') + if data.NumberOfParticles == 0: return blank + filter = data['creation_time'] > 0.0 + if not filter.any(): return blank + amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), + data["particle_position_y"][filter].astype(na.float64), + data["particle_position_z"][filter].astype(na.float64), + data["particle_mass"][filter].astype(na.float32), + na.int64(na.where(filter)[0].size), + blank, na.array(data.LeftEdge).astype(na.float64), + na.array(data.ActiveDimensions).astype(na.int32), + na.float64(data['dx'])) + return blank +add_field("star_density", function=_spdensity, + validators=[ValidateSpatial(0)], convert_function=_convertDensity) + +def _dmpdensity(field, data): + blank = na.zeros(data.ActiveDimensions, dtype='float32') + if data.NumberOfParticles == 0: return blank + filter = data['creation_time'] <= 0.0 + if not filter.any(): return blank + amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), + data["particle_position_y"][filter].astype(na.float64), + data["particle_position_z"][filter].astype(na.float64), + data["particle_mass"][filter].astype(na.float32), + na.int64(na.where(filter)[0].size), + blank, na.array(data.LeftEdge).astype(na.float64), + na.array(data.ActiveDimensions).astype(na.int32), + na.float64(data['dx'])) + return blank +add_field("dm_density", function=_dmpdensity, + validators=[ValidateSpatial(0)], convert_function=_convertDensity) + +def _star_field(field, data): + """ + Create a grid field for star quantities, weighted by star mass. + """ + particle_field = field.name[5:] + top = na.zeros(data.ActiveDimensions, dtype='float32') + if data.NumberOfParticles == 0: return top + filter = data['creation_time'] > 0.0 + if not filter.any(): return top + particle_field_data = data[particle_field][filter] * data['particle_mass'][filter] + amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), + data["particle_position_y"][filter].astype(na.float64), + data["particle_position_z"][filter].astype(na.float64), + particle_field_data.astype(na.float32), + na.int64(na.where(filter)[0].size), + top, na.array(data.LeftEdge).astype(na.float64), + na.array(data.ActiveDimensions).astype(na.int32), + na.float64(data['dx'])) + del particle_field_data + + bottom = na.zeros(data.ActiveDimensions, dtype='float32') + amr_utils.CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), + data["particle_position_y"][filter].astype(na.float64), + data["particle_position_z"][filter].astype(na.float64), + data["particle_mass"][filter].astype(na.float32), + na.int64(na.where(filter)[0].size), + bottom, na.array(data.LeftEdge).astype(na.float64), + na.array(data.ActiveDimensions).astype(na.int32), + na.float64(data['dx'])) + top[bottom == 0] = 0.0 + bnz = bottom.nonzero() + top[bnz] /= bottom[bnz] + return top + +add_field('star_metallicity_fraction', function=_star_field, + validators=[ValidateSpatial(0)]) +add_field('star_creation_time', function=_star_field, + validators=[ValidateSpatial(0)]) +add_field('star_dynamical_time', function=_star_field, + validators=[ValidateSpatial(0)]) + +def _StarMetallicity(field, data): + return data['star_metallicity_fraction'] +add_field('StarMetallicity', units=r"Z_{\rm{\odot}}", + function=_StarMetallicity, + convert_function=_ConvertMetallicity, + projection_conversion="1") + +def _StarCreationTime(field, data): + return data['star_creation_time'] +def _ConvertEnzoTimeYears(data): + return data.pf.time_units['years'] +add_field('StarCreationTimeYears', units=r"\mathrm{yr}", + function=_StarCreationTime, + convert_function=_ConvertEnzoTimeYears, + projection_conversion="1") + +def _StarDynamicalTime(field, data): + return data['star_dynamical_time'] +add_field('StarDynamicalTimeYears', units=r"\mathrm{yr}", + function=_StarDynamicalTime, + convert_function=_ConvertEnzoTimeYears, + projection_conversion="1") + +def _StarAge(field, data): + star_age = na.zeros(data['StarCreationTimeYears'].shape) + with_stars = data['StarCreationTimeYears'] > 0 + star_age[with_stars] = data.pf.time_units['years'] * \ + data.pf.current_time - \ + data['StarCreationTimeYears'][with_stars] + return star_age +add_field('StarAgeYears', units=r"\mathrm{yr}", + function=_StarAge, + projection_conversion="1") + +def _IsStarParticle(field, data): + is_star = (data['creation_time'] > 0).astype('float64') + return is_star +add_field('IsStarParticle', function=_IsStarParticle, + particle_type = True) + +# +# Now we do overrides for 2D fields +# + +class Enzo2DFieldContainer(CodeFieldInfoContainer): + _shared_state = {} + _field_list = EnzoFieldContainer._field_list.copy() +# We make a copy of the dict from the other, so we +# can now update it... +Enzo2DFieldInfo = Enzo2DFieldContainer() +add_enzo_2d_field = Enzo2DFieldInfo.add_field + +def _CellArea(field, data): + if data['dx'].size == 1: + try: + return data['dx']*data['dy']*\ + na.ones(data.ActiveDimensions, dtype='float64') + except AttributeError: + return data['dx']*data['dy'] + return data["dx"]*data["dy"] +def _ConvertCellAreaMpc(data): + return data.convert("mpc")**2.0 +def _ConvertCellAreaCGS(data): + return data.convert("cm")**2.0 +add_enzo_2d_field("CellAreaCode", units=r"\rm{BoxArea}^2", + function=_CellArea) +add_enzo_2d_field("CellAreaMpc", units=r"\rm{Mpc}^2", + function=_CellArea, + convert_function=_ConvertCellAreaMpc) +add_enzo_2d_field("CellArea", units=r"\rm{cm}^2", + function=_CellArea, + convert_function=_ConvertCellAreaCGS) + +for a in ["Code", "Mpc", ""]: + Enzo2DFieldInfo["CellVolume%s" % a] = \ + Enzo2DFieldInfo["CellArea%s" % a] + +def _zvel(field, data): + return na.zeros(data["x-velocity"].shape, + dtype='float64') +add_enzo_2d_field("z-velocity", function=_zvel) + + +# +# Now we do overrides for 1D fields +# + +class Enzo1DFieldContainer(CodeFieldInfoContainer): + _shared_state = {} + _field_list = EnzoFieldContainer._field_list.copy() +# We make a copy of the dict from the other, so we +# can now update it... +Enzo1DFieldInfo = Enzo1DFieldContainer() +add_enzo_1d_field = Enzo1DFieldInfo.add_field + +def _CellLength(field, data): + return data["dx"] +def _ConvertCellLengthMpc(data): + return data.convert("mpc") +def _ConvertCellLengthCGS(data): + return data.convert("cm") +add_enzo_1d_field("CellLengthCode", units=r"\rm{BoxArea}^2", + function=_CellLength) +add_enzo_1d_field("CellLengthMpc", units=r"\rm{Mpc}^2", + function=_CellLength, + convert_function=_ConvertCellLengthMpc) +add_enzo_1d_field("CellLength", units=r"\rm{cm}^2", + function=_CellLength, + convert_function=_ConvertCellLengthCGS) + +for a in ["Code", "Mpc", ""]: + Enzo1DFieldInfo["CellVolume%s" % a] = \ + Enzo1DFieldInfo["CellLength%s" % a] + +def _yvel(field, data): + return na.zeros(data["x-velocity"].shape, + dtype='float64') +add_enzo_1d_field("z-velocity", function=_zvel) +add_enzo_1d_field("y-velocity", function=_yvel) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,274 @@ +""" +Enzo-specific IO functions + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +from collections import defaultdict + +import exceptions +import os + +from yt.utilities import hdf5_light_reader +from yt.utilities.io_handler import \ + BaseIOHandler, _axis_ids +from yt.utilities.logger import ytLogger as mylog + +class IOHandlerEnzoHDF4(BaseIOHandler): + + _data_style = "enzo_hdf4" + + def modify(self, field): + return field.swapaxes(0,2) + + def _read_field_names(self, grid): + """ + Returns a list of fields associated with the filename + Should *only* be called as EnzoGridInstance.getFields, never as getFields(object) + """ + return SD.SD(grid.filename).datasets().keys() + + def _read_data_set(self, grid, field): + """ + Returns after having obtained or generated a field. Should throw an + exception. Should only be called as EnzoGridInstance.readData() + + @param field: field to read + @type field: string + """ + return SD.SD(grid.filename).select(field).get() + + def _read_data_slice(self, grid, field, axis, coord): + """ + Reads a slice through the HDF4 data + + @param grid: Grid to slice + @type grid: L{EnzoGrid} + @param field: field to get + @type field: string + @param sl: region to get + @type sl: SliceType + """ + sl = [slice(None), slice(None), slice(None)] + sl[axis] = slice(coord, coord + 1) + sl = tuple(reversed(sl)) + return SD.SD(grid.filename).select(field)[sl].swapaxes(0,2) + + @property + def _read_exception(self): + return SD.HDF4Error + +class IOHandlerEnzoHDF4_2D(IOHandlerEnzoHDF4): + + _data_style = "enzo_hdf4_2d" + + def _read_data_set(self, grid, field): + t = SD.SD(grid.filename).select(field).get()[:,:,None] + return t.swapaxes(0,1) + + def _read_data_slice(self, grid, field, axis, coord): + t = SD.SD(grid.filename).select(field).get() + return t.transpose() + + def modify(self, field): + return field + +class IOHandlerEnzoHDF5(BaseIOHandler): + + _data_style = "enzo_hdf5" + _particle_reader = True + + def _read_field_names(self, grid): + """ + Returns a list of fields associated with the filename + Should *only* be called as EnzoGridInstance.getFields, never as getFields(object) + """ + return hdf5_light_reader.ReadListOfDatasets(grid.filename, "/") + + def _read_data_set(self, grid, field): + return hdf5_light_reader.ReadData(grid.filename, "/%s" % field).swapaxes(0,2) + + def _read_data_slice(self, grid, field, axis, coord): + """ + Reads a slice through the HDF5 data + + @param grid: Grid to slice + @type grid: L{EnzoGrid} + @param field: field to get + @type field: string + @param axis: axis to slice along + @param coord: coord to slice at + """ + axis = {0:2,1:1,2:0}[axis] + t = hdf5_light_reader.ReadDataSlice(grid.filename, "/%s" % + (field), axis, coord).transpose() + return t + + def modify(self, field): + return field.swapaxes(0,2) + + @property + def _read_exception(self): + return (exceptions.KeyError, hdf5_light_reader.ReadingError) + + def _read_particles(self, fields, rtype, args, grid_list, enclosed, + conv_factors): + filenames = [g.filename for g in grid_list] + ids = [g.id for g in grid_list] + return hdf5_light_reader.ReadParticles( + rtype, fields, filenames, ids, conv_factors, args, 0) + +class IOHandlerPackedHDF5(BaseIOHandler): + + _data_style = "enzo_packed_3d" + _particle_reader = True + + def _read_particles(self, fields, rtype, args, grid_list, enclosed, + conv_factors): + filenames = [g.filename for g in grid_list] + ids = [g.id for g in grid_list] + filenames, ids, conv_factors = zip(*sorted(zip(filenames, ids, conv_factors))) + return hdf5_light_reader.ReadParticles( + rtype, fields, list(filenames), list(ids), conv_factors, args, 1) + + def modify(self, field): + return field.swapaxes(0,2) + + def preload(self, grids, sets): + # We need to deal with files first + files_keys = defaultdict(lambda: []) + pf_field_list = grids[0].pf.h.field_list + sets = [dset for dset in list(sets) if dset in pf_field_list] + for g in grids: files_keys[g.filename].append(g) + exc = self._read_exception + for file in files_keys: + mylog.debug("Starting read %s (%s)", file, sets) + nodes = [g.id for g in files_keys[file]] + nodes.sort() + # We want to pass on any error we might expect -- the preload + # phase should be non-fatal in all cases, and instead dump back to + # the grids. + data = hdf5_light_reader.ReadMultipleGrids(file, nodes, sets) + mylog.debug("Read %s items from %s", len(data), os.path.basename(file)) + for gid in data: self.queue[gid].update(data[gid]) + mylog.debug("Finished read of %s", sets) + + def _read_data_set(self, grid, field): + return hdf5_light_reader.ReadData(grid.filename, + "/Grid%08i/%s" % (grid.id, field)).swapaxes(0,2) + + def _read_data_slice(self, grid, field, axis, coord): + axis = _axis_ids[axis] + return hdf5_light_reader.ReadDataSlice(grid.filename, "/Grid%08i/%s" % + (grid.id, field), axis, coord).transpose() + + def _read_field_names(self, grid): + return hdf5_light_reader.ReadListOfDatasets( + grid.filename, "/Grid%08i" % grid.id) + + @property + def _read_exception(self): + return (exceptions.KeyError, hdf5_light_reader.ReadingError) + +class IOHandlerInMemory(BaseIOHandler): + + _data_style = "enzo_inline" + + def __init__(self, ghost_zones=3): + import enzo + self.enzo = enzo + self.grids_in_memory = enzo.grid_data + self.old_grids_in_memory = enzo.old_grid_data + self.my_slice = (slice(ghost_zones,-ghost_zones), + slice(ghost_zones,-ghost_zones), + slice(ghost_zones,-ghost_zones)) + BaseIOHandler.__init__(self) + + def _read_data_set(self, grid, field): + if grid.id not in self.grids_in_memory: raise KeyError + tr = self.grids_in_memory[grid.id][field] + # If it's particles, we copy. + if len(tr.shape) == 1: return tr.copy() + # New in-place unit conversion breaks if we don't copy first + return tr.swapaxes(0,2)[self.my_slice].copy() + # We don't do this, because we currently do not interpolate + coef1 = max((grid.Time - t1)/(grid.Time - t2), 0.0) + coef2 = 1.0 - coef1 + t1 = enzo.yt_parameter_file["InitialTime"] + t2 = enzo.hierarchy_information["GridOldTimes"][grid.id] + return (coef1*self.grids_in_memory[grid.id][field] + \ + coef2*self.old_grids_in_memory[grid.id][field])\ + [self.my_slice] + + def modify(self, field): + return field.swapaxes(0,2) + + def _read_field_names(self, grid): + return self.grids_in_memory[grid.id].keys() + + def _read_data_slice(self, grid, field, axis, coord): + sl = [slice(3,-3), slice(3,-3), slice(3,-3)] + sl[axis] = slice(coord + 3, coord + 4) + sl = tuple(reversed(sl)) + tr = self.grids_in_memory[grid.id][field][sl].swapaxes(0,2) + # In-place unit conversion requires we return a copy + return tr.copy() + + @property + def _read_exception(self): + return KeyError + +class IOHandlerPacked2D(IOHandlerPackedHDF5): + + _data_style = "enzo_packed_2d" + _particle_reader = False + + def _read_data_set(self, grid, field): + return hdf5_light_reader.ReadData(grid.filename, + "/Grid%08i/%s" % (grid.id, field)).transpose()[:,:,None] + + def modify(self, field): + pass + + def _read_data_slice(self, grid, field, axis, coord): + t = hdf5_light_reader.ReadData(grid.filename, "/Grid%08i/%s" % + (grid.id, field)).transpose() + return t + + +class IOHandlerPacked1D(IOHandlerPackedHDF5): + + _data_style = "enzo_packed_1d" + _particle_reader = False + + def _read_data_set(self, grid, field): + return hdf5_light_reader.ReadData(grid.filename, + "/Grid%08i/%s" % (grid.id, field)).transpose()[:,None,None] + + def modify(self, field): + pass + + def _read_data_slice(self, grid, field, axis, coord): + t = hdf5_light_reader.ReadData(grid.filename, "/Grid%08i/%s" % + (grid.id, field)) + return t + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/misc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/misc.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,25 @@ +""" +Miscellaneous functions that are Enzo-specific + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2009 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 . +""" + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/enzo/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/enzo/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('enzo',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/flash/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/flash/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.frontends.flash + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/flash/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/flash/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +""" +API for yt.frontends.flash + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .data_structures import \ + FLASHGrid, \ + FLASHHierarchy, \ + FLASHStaticOutput + +from .fields import \ + FLASHFieldContainer, \ + FLASHFieldInfo, \ + add_flash_field + +from .io import \ + IOHandlerFLASH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/flash/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/flash/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,232 @@ +""" +FLASH-specific data structures + +Author: Matthew Turk +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 . +""" + +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 + +from .fields import FLASHFieldContainer + +class FLASHGrid(AMRGridPatch): + _id_offset = 1 + #__slots__ = ["_level_id", "stop_index"] + def __init__(self, id, hierarchy, level): + AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename, + hierarchy = hierarchy) + self.Parent = None + self.Children = [] + self.Level = level + + def __repr__(self): + return "FLASHGrid_%04i (%s)" % (self.id, self.ActiveDimensions) + +class FLASHHierarchy(AMRHierarchy): + + grid = FLASHGrid + _handle = None + + def __init__(self,pf,data_style='chombo_hdf5'): + self.data_style = data_style + self.field_info = FLASHFieldContainer() + self.field_indexes = {} + self.parameter_file = weakref.proxy(pf) + # for now, the hierarchy file is the parameter file! + self.hierarchy_filename = self.parameter_file.parameter_filename + self.directory = os.path.dirname(self.hierarchy_filename) + self._handle = h5py.File(self.hierarchy_filename) + + self.float_type = na.float64 + AMRHierarchy.__init__(self,pf,data_style) + + self._handle.close() + self._handle = None + + def _initialize_data_storage(self): + pass + + def _detect_fields(self): + ncomp = self._handle["/unknown names"].shape[0] + self.field_list = [s.strip() for s in self._handle["/unknown names"][:].flat] + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _count_grids(self): + try: + self.num_grids = self.parameter_file._find_parameter( + "integer", "globalnumblocks", True, self._handle) + except KeyError: + self.num_grids = self._handle["/simulation parameters"][0][0] + + def _parse_hierarchy(self): + f = self._handle # shortcut + pf = self.parameter_file # shortcut + + self.grid_left_edge[:] = f["/bounding box"][:,:,0] + self.grid_right_edge[:] = f["/bounding box"][:,:,1] + # Move this to the parameter file + try: + nxb = pf._find_parameter("integer", "nxb", True, f) + nyb = pf._find_parameter("integer", "nyb", True, f) + nzb = pf._find_parameter("integer", "nzb", True, f) + except KeyError: + nxb, nyb, nzb = [int(f["/simulation parameters"]['n%sb' % ax]) + for ax in 'xyz'] + self.grid_dimensions[:] *= (nxb, nyb, nzb) + # particle count will need to be fixed somehow: + # by getting access to the particle file we can get the number of + # particles in each brick. but how do we handle accessing the + # particle file? + + # This will become redundant, as _prepare_grid will reset it to its + # current value. Note that FLASH uses 1-based indexing for refinement + # levels, but we do not, so we reduce the level by 1. + self.grid_levels.flat[:] = f["/refine level"][:][:] - 1 + g = [self.grid(i+1, self, self.grid_levels[i,0]) + for i in xrange(self.num_grids)] + self.grids = na.array(g, dtype='object') + + def _populate_grid_objects(self): + # We only handle 3D data, so offset is 7 (nfaces+1) + + offset = 7 + ii = na.argsort(self.grid_levels.flat) + gid = self._handle["/gid"][:] + for g in self.grids[ii].flat: + gi = g.id - g._id_offset + # FLASH uses 1-indexed group info + g.Children = [self.grids[i - 1] for i in gid[gi,7:] if i > -1] + for g1 in g.Children: + g1.Parent = g + g._prepare_grid() + g._setup_dx() + self.max_level = self.grid_levels.max() + + def _setup_unknown_fields(self): + for field in self.field_list: + if field in self.parameter_file.field_info: continue + mylog.info("Adding %s to list of fields", field) + cf = None + if self.parameter_file.has_key(field): + def external_wrapper(f): + def _convert_function(data): + return data.convert(f) + return _convert_function + cf = external_wrapper(field) + add_field(field, lambda a, b: None, + convert_function=cf, take_log=False) + + def _setup_derived_fields(self): + self.derived_field_list = [] + +class FLASHStaticOutput(StaticOutput): + _hierarchy_class = FLASHHierarchy + _fieldinfo_class = FLASHFieldContainer + _handle = None + + def __init__(self, filename, data_style='flash_hdf5', + storage_filename = None): + StaticOutput.__init__(self, filename, data_style) + self.storage_filename = storage_filename + + self.field_info = self._fieldinfo_class() + # These should be explicitly obtained from the file, but for now that + # will wait until a reorganization of the source tree and better + # generalization. + self.dimensionality = 3 + self.refine_by = 2 + self.parameters["HydroMethod"] = 'flash' # always PPM DE + self.parameters["Time"] = 1. # default unit is 1... + self._set_units() + + def _set_units(self): + """ + Generates the conversion to various physical _units based on the parameter file + """ + self.units = {} + self.time_units = {} + if len(self.parameters) == 0: + self._parse_parameter_file() + self._setup_nounits_units() + self.conversion_factors = defaultdict(lambda: 1.0) + self.time_units['1'] = 1 + self.units['1'] = 1.0 + self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() + seconds = 1 #self["Time"] + self.time_units['years'] = seconds / (365*3600*24.0) + self.time_units['days'] = seconds / (3600*24.0) + for key in yt2orionFieldsDict: + self.conversion_factors[key] = 1.0 + + def _setup_nounits_units(self): + z = 0 + mylog.warning("Setting 1.0 in code units to be 1.0 cm") + if not self.has_key("TimeUnits"): + mylog.warning("No time units. Setting 1.0 = 1 second.") + self.conversion_factors["Time"] = 1.0 + for unit in mpc_conversion.keys(): + self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] + + def _find_parameter(self, ptype, pname, scalar = False, handle = None): + # We're going to implement handle caching eventually + if handle is None: handle = self._handle + if handle is None: + handle = h5py.File(self.parameter_filename, "r") + nn = "/%s %s" % (ptype, + {False: "runtime parameters", True: "scalars"}[scalar]) + for tpname, pval in handle[nn][:]: + if tpname.strip() == pname: + return pval + raise KeyError(pname) + + def _parse_parameter_file(self): + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[ST_CTIME]) + self._handle = h5py.File(self.parameter_filename, "r") + self.domain_left_edge = na.array( + [self._find_parameter("real", "%smin" % ax) for ax in 'xyz']) + self.domain_right_edge = na.array( + [self._find_parameter("real", "%smax" % ax) for ax in 'xyz']) + self.current_time = \ + float(self._find_parameter("real", "time", scalar=True)) + self._handle.close() + + @classmethod + def _is_valid(self, *args, **kwargs): + try: + fileh = h5py.File(args[0],'r') + if "bounding box" in fileh["/"].keys(): + return True + except: + pass + return False + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/flash/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/flash/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,126 @@ +""" +FLASH-specific fields + +Author: Matthew Turk +Affiliation: UCSD +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2010 Matthew Turk, John ZuHone. 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 . +""" + +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields + +class FLASHFieldContainer(CodeFieldInfoContainer): + _shared_state = {} + _field_list = {} +FLASHFieldInfo = FLASHFieldContainer() +add_flash_field = FLASHFieldInfo.add_field + +add_field = add_flash_field + +# Common fields in FLASH: (Thanks to John ZuHone for this list) +# +# dens gas mass density (g/cc) -- +# eint internal energy (ergs/g) -- +# ener total energy (ergs/g), with 0.5*v^2 -- +# gamc gamma defined as ratio of specific heats, no units +# game gamma defined as in , no units +# gpol gravitational potential from the last timestep (ergs/g) +# gpot gravitational potential from the current timestep (ergs/g) +# grac gravitational acceleration from the current timestep (cm s^-2) +# pden particle mass density (usually dark matter) (g/cc) +# pres pressure (erg/cc) +# temp temperature (K) -- +# velx velocity x (cm/s) -- +# vely velocity y (cm/s) -- +# velz velocity z (cm/s) -- + +translation_dict = {"x-velocity": "velx", + "y-velocity": "vely", + "z-velocity": "velz", + "Density": "dens", + "Total_Energy": "ener", + "Gas_Energy": "eint", + "Temperature": "temp", + } + +def _generate_translation(mine, theirs): + add_field(theirs, function=lambda a, b: b[mine], take_log=True) + +for f,v in translation_dict.items(): + if v not in FLASHFieldInfo: + add_field(v, function=lambda a,b: None, take_log=False, + validators = [ValidateDataField(v)]) + #print "Setting up translator from %s to %s" % (v, f) + _generate_translation(v, f) + +add_field("gamc", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("gamc")], + units = r"\rm{ratio\/of\/specific\/heats}") + +add_field("game", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("game")], + units = r"\rm{ratio\/of\/specific\/heats}") + +add_field("gpot", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("gpot")], + units = r"\rm{ergs\//\/g}") + +add_field("gpol", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("gpol")], + units = r"\rm{ergs\//\/g}") + +add_field("grac", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("grac")], + units = r"\rm{cm\/s^{-2}}") + +add_field("pden", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("pden")], + units = r"\rm{g}\//\/\rm{cm}^{3}") + +add_field("pres", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("pres")], + units = r"\rm{erg}\//\/\rm{cm}^{3}") + +add_field("magx", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("magx")], + units = r"\rm{G}") + +add_field("magy", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("magy")], + units = r"\rm{G}") + +add_field("magz", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("magz")], + units = r"\rm{G}") + +add_field("magp", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("magp")], + units = r"\rm{erg}\//\/\rm{cm}^{3}") + +add_field("divb", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("divb")], + units = r"\rm{G}\/\rm{cm}") + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/flash/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/flash/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,46 @@ +""" +FLASH-specific IO functions + +Author: Matthew Turk +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 . +""" + +from yt.utilities.io_handler import \ + BaseIOHandler + +class IOHandlerFLASH(BaseIOHandler): + _data_style = "flash_hdf5" + + def __init__(self, *args, **kwargs): + BaseIOHandler.__init__(self, *args, **kwargs) + + def _read_data_set(self, grid, field): + f = h5py.File(grid.pf.parameter_filename, "r") + tr = f["/%s" % field][grid.id - grid._id_offset,:,:,:].transpose() + return tr.astype("float64") + + def _read_data_slice(self, grid, field, axis, coord): + sl = [slice(None), slice(None), slice(None)] + sl[axis] = slice(coord, coord + 1) + f = h5py.File(grid.pf.parameter_filename, "r") + tr = f["/%s" % field][grid.id - grid._id_offset].transpose()[sl] + return tr.astype("float64") + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/flash/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/flash/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('flash',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/gadget/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/gadget/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.frontends.gadget + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/gadget/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/gadget/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +""" +API for yt.frontends.gadget + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .data_structures import \ + GadgetGrid, \ + GadgetHierarchy, \ + GadgetStaticOutput + +from .fields import \ + GadgetFieldContainer, \ + GadgetFieldInfo, \ + add_gadget_field + +from .io import \ + IOHandlerGadget diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/gadget/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/gadget/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,330 @@ +""" +Data structures for Gadget. + +Author: Matthew Turk +Affiliation: UCSD +Author: Chris Moody +Affiliation: UCSC +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-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 . +""" + +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 + +from .fields import GadgetFieldContainer + +class GadgetGrid(AMRGridPatch): + + _id_offset = 0 + + def __init__(self, id, filename, hierarchy, **kwargs): + AMRGridPatch.__init__(self, id, hierarchy = hierarchy) + self.id = id + self.filename = filename + self.Children = [] #grid objects + self.Parent = None + self.Level = 0 + self.LeftEdge = [0,0,0] + self.RightEdge = [0,0,0] + self.IsLeaf = False + self.N = 0 + self.Address = '' + self.NumberOfParticles = self.N + self.ActiveDimensions = na.array([0,0,0]) + self._id_offset = 0 + self.start_index = na.array([0,0,0]) + + for key,val in kwargs.items(): + if key in dir(self): + #if it's one of the predefined values + setattr(self,key,val) + + #def __repr__(self): + # return "GadgetGrid_%04i" % (self.Address) + + def get_global_startindex(self): + return self.start_index + + def _prepare_grid(self): + #all of this info is already included in the snapshots + pass + #h = self.hierarchy + #h.grid_levels[self.Address,0]=self.Level + #h.grid_left_edge[self.Address,:]=self.LeftEdge[:] + #h.grid_right_edge[self.Address,:]=self.RightEdge[:] + + def _setup_dx(self): + # So first we figure out what the index is. We don't assume + # that dx=dy=dz , at least here. We probably do elsewhere. + id = self.id + LE, RE = self.LeftEdge,self.RightEdge + self.dds = na.array((RE-LE)/self.ActiveDimensions) + if self.pf.dimensionality < 2: self.dds[1] = 1.0 + if self.pf.dimensionality < 3: self.dds[2] = 1.0 + self.data['dx'], self.data['dy'], self.data['dz'] = self.dds + +class GadgetHierarchy(AMRHierarchy): + grid = GadgetGrid + + def __init__(self, pf, data_style='gadget_hdf5'): + self.field_info = GadgetFieldContainer() + self.directory = os.path.dirname(pf.parameter_filename) + self.data_style = data_style + self._handle = h5py.File(pf.parameter_filename) + AMRHierarchy.__init__(self, pf, data_style) + self._handle.close() + + def _initialize_data_storage(self): + pass + + def _detect_fields(self): + #example string: + #"(S'VEL'\np1\nS'ID'\np2\nS'MASS'\np3\ntp4\n." + #fields are surrounded with ' + fields_string=self._handle['root'].attrs['fieldnames'] + #splits=fields_string.split("'") + #pick out the odd fields + #fields= [splits[j] for j in range(1,len(splits),2)] + self.field_list = cPickle.loads(fields_string) + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _count_grids(self): + fh = self._handle #shortcut + #nodes in the hdf5 file are the same as grids + #in yt + #the num of levels and total nodes is already saved + self._levels = self.pf._get_param('maxlevel') + self.num_grids = self.pf._get_param('numnodes') + + def _parse_hierarchy(self): + #for every box, define a self.grid(level,edge1,edge2) + #with particle counts, dimensions + f = self._handle #shortcut + + root = f['root'] + grids,numnodes = self._walk_nodes(None,root,[]) + dims = [self.pf.max_grid_size for grid in grids] + LE = [grid.LeftEdge for grid in grids] + RE = [grid.RightEdge for grid in grids] + levels = [grid.Level for grid in grids] + counts = [(grid.N if grid.IsLeaf else 0) for grid in grids] + self.grids = na.array(grids,dtype='object') + self.grid_dimensions[:] = na.array(dims, dtype='int64') + self.grid_left_edge[:] = na.array(LE, dtype='float64') + self.grid_right_edge[:] = na.array(RE, dtype='float64') + self.grid_levels.flat[:] = na.array(levels, dtype='int32') + self.grid_particle_count.flat[:] = na.array(counts, dtype='int32') + + def _walk_nodes(self,parent,node,grids,idx=0): + pi = cPickle.loads + loc = node.attrs['h5address'] + + kwargs = {} + kwargs['Address'] = loc + kwargs['Parent'] = parent + kwargs['Axis'] = self.pf._get_param('divideaxis',location=loc) + kwargs['Level'] = self.pf._get_param('level',location=loc) + kwargs['LeftEdge'] = self.pf._get_param('leftedge',location=loc) + kwargs['RightEdge'] = self.pf._get_param('rightedge',location=loc) + kwargs['IsLeaf'] = self.pf._get_param('isleaf',location=loc) + kwargs['N'] = self.pf._get_param('n',location=loc) + kwargs['NumberOfParticles'] = self.pf._get_param('n',location=loc) + dx = self.pf._get_param('dx',location=loc) + dy = self.pf._get_param('dy',location=loc) + dz = self.pf._get_param('dz',location=loc) + divdims = na.array([1,1,1]) + if not kwargs['IsLeaf']: + divdims[kwargs['Axis']] = 2 + kwargs['ActiveDimensions'] = divdims + #Active dimensions: + #This is the number of childnodes, along with dimensiolaity + #ie, binary tree can be (2,1,1) but octree is (2,2,2) + + idx+=1 + #pdb.set_trace() + children = [] + if not kwargs['IsLeaf']: + for child in node.values(): + children,idx=self._walk_nodes(node,child,children,idx=idx) + + kwargs['Children'] = children + grid = self.grid(idx,self.pf.parameter_filename,self,**kwargs) + grids += children + grids += [grid,] + return grids,idx + + def _populate_grid_objects(self): + for g in self.grids: + g._prepare_grid() + self.max_level = cPickle.loads(self._handle['root'].attrs['maxlevel']) + + def _setup_unknown_fields(self): + pass + + def _setup_derived_fields(self): + self.derived_field_list = [] + + def _get_grid_children(self, grid): + #given a grid, use it's address to find subchildren + pass + +class GadgetHierarchyOld(AMRHierarchy): + #Kept here to compare for the time being + grid = GadgetGrid + + def __init__(self, pf, data_style): + self.directory = pf.fullpath + self.data_style = data_style + AMRHierarchy.__init__(self, pf, data_style) + + def _count_grids(self): + # We actually construct our octree here! + # ...but we do read in our particles, it seems. + LE = na.zeros(3, dtype='float64') + RE = na.ones(3, dtype='float64') + base_grid = ProtoGadgetGrid(0, LE, RE, self.pf.particles) + self.proto_grids = base_grid.refine(8) + self.num_grids = len(self.proto_grids) + self.max_level = max( (g.level for g in self.proto_grids) ) + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _parse_hierarchy(self): + grids = [] + # We need to fill in dims, LE, RE, level, count + dims, LE, RE, levels, counts = [], [], [], [], [] + self.proto_grids.sort(key = lambda a: a.level) + for i, pg in enumerate(self.proto_grids): + g = self.grid(i, self, pg) + pg.real_grid = g + grids.append(g) + dims.append(g.ActiveDimensions) + LE.append(g.LeftEdge) + RE.append(g.RightEdge) + levels.append(g.Level) + counts.append(g.NumberOfParticles) + del self.proto_grids + self.grids = na.array(grids, dtype='object') + self.grid_dimensions[:] = na.array(dims, dtype='int64') + self.grid_left_edge[:] = na.array(LE, dtype='float64') + self.grid_right_edge[:] = na.array(RE, dtype='float64') + self.grid_levels.flat[:] = na.array(levels, dtype='int32') + self.grid_particle_count.flat[:] = na.array(counts, dtype='int32') + + def _populate_grid_objects(self): + # We don't need to do anything here + for g in self.grids: g._setup_dx() + + def _detect_fields(self): + self.field_list = ['particle_position_%s' % ax for ax in 'xyz'] + + def _setup_unknown_fields(self): + pass + + def _setup_derived_fields(self): + self.derived_field_list = [] + +class GadgetStaticOutput(StaticOutput): + _hierarchy_class = GadgetHierarchy + _fieldinfo_class = GadgetFieldContainer + def __init__(self, h5filename,storage_filename=None) : + StaticOutput.__init__(self, h5filename, 'gadget_hdf5') + self.storage_filename = storage_filename #Don't know what this is + self.field_info = self._fieldinfo_class() + x = self._get_param('maxlevel')**2 + self.max_grid_size = (x,x,x) + self.current_time = 0.0 + # These should be explicitly obtained from the file, but for now that + # will wait until a reorganization of the source tree and better + # generalization. + self.dimensionality = 3 + self.refine_by = 2 + self.domain_left_edge = self.leftedge + self.domain_right_edge = self.rightedge + + + def _parse_parameter_file(self): + # read the units in from the hdf5 file + #fill in self.units dict + #fill in self.time_units dict (keys: 'days','years', '1') + + #import all of the parameter file params + #this is NOT originally from the gadget snapshot but instead + #from the paramfile starting the sim + skips = ('TITLE','CLASS','VERSION') #these are just hdf5 crap + fh = h5py.File(self.parameter_filename) + for kw in fh['root'].attrs.keys(): + if any([skip in kw for skip in skips]): + continue + val = fh['root'].attrs[kw] + if type(val)==type(''): + try: val = cPickle.loads(val) + except: pass + #also, includes unit info + setattr(self,kw,val) + + def _get_param(self,kw,location='/root'): + fh = h5py.File(self.parameter_filename) + val = fh[location].attrs[kw] + try: val = cPickle.loads(val) + except: pass + return val + + def _set_units(self): + #check out the unit params from _parse_parameter_file and use them + #code below is all filler + self.units = {} + self.time_units = {} + self.conversion_factors = defaultdict(lambda: 1.0) + self.time_units['1'] = 1 + self.units['1'] = 1.0 + self.units['unitary'] = 1.0 + self.units['cm'] = 1.0 + seconds = 1 #self["Time"] + self.time_units['years'] = seconds / (365*3600*24.0) + self.time_units['days'] = seconds / (3600*24.0) + for key in yt2orionFieldsDict: + self.conversion_factors[key] = 1.0 + + + @classmethod + def _is_valid(cls, *args, **kwargs): + # check for a /root to exist in the h5 file + try: + h5f=h5py.File(self.h5filename) + valid = 'root' in h5f.items()[0] + h5f.close() + return valid + except: + pass + return False + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/gadget/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/gadget/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,97 @@ +""" +Gadget-specific fields + +Author: Christopher E Moody +Affiliation: UC Santa Cruz +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2010 Christopher E Moody, 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 . +""" + +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields + +class GadgetFieldContainer(CodeFieldInfoContainer): + _shared_state = {} + _field_list = {} +GadgetFieldInfo = GadgetFieldContainer() +add_gadget_field = GadgetFieldInfo.add_field + +add_field = add_gadget_field + +translation_dict = {"Position": "POS", + "Velocity": "VEL", + "ID": "ID", + "Mass":"MASS" + } + +#for f,v in translation_dict.items(): +# add_field(f, function=lambda a,b: None, take_log=True, +# validators = [ValidateDataField(v)], +# units=r"\rm{cm}") +# add_field(v, function=lambda a,b: None, take_log=True, +# validators = [ValidateDataField(v)], +# units=r"\rm{cm}") + + +add_field("Density", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("POS")], + units=r"\rm{cm}") + +add_field("VEL", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("VEL")], + units=r"") + +add_field("ID", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("ID")], + units=r"") + +add_field("MASS", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("MASS")], + units=r"\rm{g}") + +add_field("U", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("U")], + units=r"") + +add_field("NE", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("NE")], + units=r"") + +add_field("POT", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("POT")], + units=r"") + +add_field("ACCE", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("ACCE")], + units=r"") + +add_field("ENDT", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("ENDT")], + units=r"") + +add_field("TSTP", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("TSTP")], + units=r"") + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/gadget/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/gadget/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,51 @@ +""" +Gadget-specific data-file handling function + +Author: Christopher E Moody +Affiliation: UC Santa Cruz +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2010 Christopher E Moody, 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 . +""" + +from yt.utilities.io_handler import \ + BaseIOHandler + +class IOHandlerGadget(BaseIOHandler): + _data_style = 'gadget_hdf5' + def _read_data_set(self, grid, field): + adr = grid.Address + fh = h5py.File(grid.filename,mode='r') + if 'particles' in fh[adr].keys(): + adr2 = adr+'/particles' + return fh[adr2][field] + return None + def _read_field_names(self,grid): + adr = grid.Address + fh = h5py.File(grid.filename,mode='r') + rets = cPickle.loads(fh['/root'].attrs['fieldnames']) + return rets + + def _read_data_slice(self,grid, field, axis, coord): + adr = grid.Address + fh = h5py.File(grid.filename,mode='r') + if 'particles' in fh[adr].keys(): + adr2 = adr+'/particles' + return fh[adr2][field][coord,axis] + return None + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/gadget/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/gadget/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('gadget',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.frontends.orion + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +""" +API for yt.frontends.orion + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .data_structures import \ + OrionGrid, \ + OrionHierarchy, \ + OrionStaticOutput + +from .fields import \ + OrionFieldContainer, \ + OrionFieldInfo, \ + add_orion_field + +from .io import \ + IOHandlerNative diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,596 @@ +""" +Data structures for Orion. + +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2010 J. S. Oishi. 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 . +""" + +import re +import os +import weakref +import numpy as na + +from collections import \ + defaultdict +from string import \ + strip, \ + rstrip +from stat import \ + ST_CTIME + +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 +from yt.utilities.definitions import \ + mpc_conversion + +from definitions import \ + orion2enzoDict, \ + parameterDict, \ + yt2orionFieldsDict, \ + orion_FAB_header_pattern + +from fields import \ + OrionFieldContainer, \ + add_field + + +class OrionGrid(AMRGridPatch): + _id_offset = 0 + def __init__(self, LeftEdge, RightEdge, index, level, filename, offset, dimensions,start,stop,paranoia=False,**kwargs): + AMRGridPatch.__init__(self, index,**kwargs) + self.filename = filename + self._offset = offset + self._paranoid = paranoia + + # should error check this + self.ActiveDimensions = (dimensions.copy()).astype('int32')#.transpose() + self.start_index = start.copy()#.transpose() + self.stop_index = stop.copy()#.transpose() + self.LeftEdge = LeftEdge.copy() + self.RightEdge = RightEdge.copy() + self.index = index + self.Level = level + + def get_global_startindex(self): + return self.start_index + + def _prepare_grid(self): + """ + Copies all the appropriate attributes from the hierarchy + """ + # This is definitely the slowest part of generating the hierarchy + # Now we give it pointers to all of its attributes + # Note that to keep in line with Enzo, we have broken PEP-8 + h = self.hierarchy # cache it + #self.StartIndices = h.gridStartIndices[self.id] + #self.EndIndices = h.gridEndIndices[self.id] + h.grid_levels[self.id,0] = self.Level + h.grid_left_edge[self.id,:] = self.LeftEdge[:] + h.grid_right_edge[self.id,:] = self.RightEdge[:] + #self.Time = h.gridTimes[self.id,0] + #self.NumberOfParticles = h.gridNumberOfParticles[self.id,0] + self.field_indexes = h.field_indexes + self.Children = h.gridTree[self.id] + pIDs = h.gridReverseTree[self.id] + if len(pIDs) > 0: + self.Parent = [weakref.proxy(h.grids[pID]) for pID in pIDs] + else: + self.Parent = None + + def _setup_dx(self): + # So first we figure out what the index is. We don't assume + # that dx=dy=dz , at least here. We probably do elsewhere. + id = self.id - self._id_offset + if self.Parent is not None: + self.dds = self.Parent[0].dds / self.pf.refine_by + else: + LE, RE = self.hierarchy.grid_left_edge[id,:], \ + self.hierarchy.grid_right_edge[id,:] + self.dds = na.array((RE-LE)/self.ActiveDimensions) + if self.pf.dimensionality < 2: self.dds[1] = 1.0 + if self.pf.dimensionality < 3: self.dds[2] = 1.0 + self.data['dx'], self.data['dy'], self.data['dz'] = self.dds + + def __repr__(self): + return "OrionGrid_%04i" % (self.id) + +class OrionHierarchy(AMRHierarchy): + grid = OrionGrid + def __init__(self, pf, data_style='orion_native'): + self.field_info = OrionFieldContainer() + self.field_indexes = {} + self.parameter_file = weakref.proxy(pf) + header_filename = os.path.join(pf.fullplotdir,'Header') + self.directory = pf.fullpath + self.data_style = data_style + #self._setup_classes() + + self.readGlobalHeader(header_filename,self.parameter_file.paranoid_read) # also sets up the grid objects + self.__cache_endianness(self.levels[-1].grids[-1]) + AMRHierarchy.__init__(self,pf, self.data_style) + self._setup_data_io() + self._setup_field_list() + self._populate_hierarchy() + + def readGlobalHeader(self,filename,paranoid_read): + """ + read the global header file for an Orion plotfile output. + """ + counter = 0 + header_file = open(filename,'r') + self.__global_header_lines = header_file.readlines() + + # parse the file + self.orion_version = self.__global_header_lines[0].rstrip() + self.n_fields = int(self.__global_header_lines[1]) + + counter = self.n_fields+2 + self.field_list = [] + for i,line in enumerate(self.__global_header_lines[2:counter]): + self.field_list.append(line.rstrip()) + + # this is unused...eliminate it? + #for f in self.field_indexes: + # self.field_list.append(orion2ytFieldsDict.get(f,f)) + + self.dimension = int(self.__global_header_lines[counter]) + if self.dimension != 3: + raise RunTimeError("Orion must be in 3D to use yt.") + counter += 1 + self.Time = float(self.__global_header_lines[counter]) + counter += 1 + self.finest_grid_level = int(self.__global_header_lines[counter]) + self.n_levels = self.finest_grid_level + 1 + counter += 1 + # quantities with _unnecessary are also stored in the inputs + # file and are not needed. they are read in and stored in + # case in the future we want to enable a "backwards" way of + # taking the data out of the Header file and using it to fill + # in in the case of a missing inputs file + self.domainLeftEdge_unnecessary = na.array(map(float,self.__global_header_lines[counter].split())) + counter += 1 + self.domainRightEdge_unnecessary = na.array(map(float,self.__global_header_lines[counter].split())) + counter += 1 + self.refinementFactor_unnecessary = self.__global_header_lines[counter].split() #na.array(map(int,self.__global_header_lines[counter].split())) + counter += 1 + self.globalIndexSpace_unnecessary = self.__global_header_lines[counter] + #domain_re.search(self.__global_header_lines[counter]).groups() + counter += 1 + self.timestepsPerLevel_unnecessary = self.__global_header_lines[counter] + counter += 1 + self.dx = na.zeros((self.n_levels,3)) + for i,line in enumerate(self.__global_header_lines[counter:counter+self.n_levels]): + self.dx[i] = na.array(map(float,line.split())) + counter += self.n_levels + self.geometry = int(self.__global_header_lines[counter]) + if self.geometry != 0: + raise RunTimeError("yt only supports cartesian coordinates.") + counter += 1 + + # this is just to debug. eventually it should go away. + linebreak = int(self.__global_header_lines[counter]) + if linebreak != 0: + raise RunTimeError("INTERNAL ERROR! This should be a zero.") + counter += 1 + + # each level is one group with ngrids on it. each grid has 3 lines of 2 reals + self.levels = [] + grid_counter = 0 + file_finder_pattern = r"FabOnDisk: (\w+_D_[0-9]{4}) (\d+)\n" + re_file_finder = re.compile(file_finder_pattern) + dim_finder_pattern = r"\(\((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\) \(\d+,\d+,\d+\)\)\n" + re_dim_finder = re.compile(dim_finder_pattern) + data_files_pattern = r"Level_[\d]/" + data_files_finder = re.compile(data_files_pattern) + + for level in range(0,self.n_levels): + tmp = self.__global_header_lines[counter].split() + # should this be grid_time or level_time?? + lev,ngrids,grid_time = int(tmp[0]),int(tmp[1]),float(tmp[2]) + counter += 1 + nsteps = int(self.__global_header_lines[counter]) + counter += 1 + self.levels.append(OrionLevel(lev,ngrids)) + # open level header, extract file names and offsets for + # each grid + # read slightly out of order here: at the end of the lo,hi + # pairs for x,y,z is a *list* of files types in the Level + # directory. each type has Header and a number of data + # files (one per processor) + tmp_offset = counter + 3*ngrids + nfiles = 0 + key_off = 0 + files = {} # dict(map(lambda a: (a,[]),self.field_list)) + offsets = {} # dict(map(lambda a: (a,[]),self.field_list)) + while nfiles+tmp_offset < len(self.__global_header_lines) and data_files_finder.match(self.__global_header_lines[nfiles+tmp_offset]): + filen = os.path.join(self.parameter_file.fullplotdir, \ + self.__global_header_lines[nfiles+tmp_offset].strip()) + # open each "_H" header file, and get the number of + # components within it + level_header_file = open(filen+'_H','r').read() + start_stop_index = re_dim_finder.findall(level_header_file) # just take the last one + grid_file_offset = re_file_finder.findall(level_header_file) + ncomp_this_file = int(level_header_file.split('\n')[2]) + for i in range(ncomp_this_file): + key = self.field_list[i+key_off] + f,o = zip(*grid_file_offset) + files[key] = f + offsets[key] = o + self.field_indexes[key] = i + key_off += ncomp_this_file + nfiles += 1 + # convert dict of lists to list of dicts + fn = [] + off = [] + lead_path = os.path.join(self.parameter_file.fullplotdir,'Level_%i'%level) + for i in range(ngrids): + fi = [os.path.join(lead_path,files[key][i]) for key in self.field_list] + of = [int(offsets[key][i]) for key in self.field_list] + fn.append(dict(zip(self.field_list,fi))) + off.append(dict(zip(self.field_list,of))) + + for grid in range(0,ngrids): + gfn = fn[grid] # filename of file containing this grid + gfo = off[grid] # offset within that file + xlo,xhi = map(float,self.__global_header_lines[counter].split()) + counter+=1 + ylo,yhi = map(float,self.__global_header_lines[counter].split()) + counter+=1 + zlo,zhi = map(float,self.__global_header_lines[counter].split()) + counter+=1 + lo = na.array([xlo,ylo,zlo]) + hi = na.array([xhi,yhi,zhi]) + dims,start,stop = self.__calculate_grid_dimensions(start_stop_index[grid]) + self.levels[-1].grids.append(self.grid(lo,hi,grid_counter,level,gfn, gfo, dims,start,stop,paranoia=paranoid_read,hierarchy=self)) + grid_counter += 1 # this is global, and shouldn't be reset + # for each level + + # already read the filenames above... + counter+=nfiles + self.num_grids = grid_counter + self.float_type = 'float64' + + self.maxLevel = self.n_levels - 1 + self.max_level = self.n_levels - 1 + header_file.close() + + def __cache_endianness(self,test_grid): + """ + Cache the endianness and bytes perreal of the grids by using a + test grid and assuming that all grids have the same + endianness. This is a pretty safe assumption since Orion uses + one file per processor, and if you're running on a cluster + with different endian processors, then you're on your own! + """ + # open the test file & grab the header + inFile = open(os.path.expanduser(test_grid.filename[self.field_list[0]]),'rb') + header = inFile.readline() + inFile.close() + header.strip() + + # parse it. the patter is in OrionDefs.py + headerRe = re.compile(orion_FAB_header_pattern) + bytesPerReal,endian,start,stop,centerType,nComponents = headerRe.search(header).groups() + self._bytesPerReal = int(bytesPerReal) + if self._bytesPerReal == int(endian[0]): + dtype = '<' + elif self._bytesPerReal == int(endian[-1]): + dtype = '>' + else: + raise ValueError("FAB header is neither big nor little endian. Perhaps the file is corrupt?") + + dtype += ('f%i' % self._bytesPerReal) # always a floating point + self._dtype = dtype + + def __calculate_grid_dimensions(self,start_stop): + start = na.array(map(int,start_stop[0].split(','))) + stop = na.array(map(int,start_stop[1].split(','))) + dimension = stop - start + 1 + return dimension,start,stop + + def _populate_grid_objects(self): + mylog.debug("Creating grid objects") + self.grids = na.concatenate([level.grids for level in self.levels]) + self.grid_levels = na.concatenate([level.ngrids*[level.level] for level in self.levels]) + self.grid_levels = self.grid_levels.reshape((self.num_grids,1)) + grid_dcs = na.concatenate([level.ngrids*[self.dx[level.level]] for level in self.levels],axis=0) + self.grid_dxs = grid_dcs[:,0].reshape((self.num_grids,1)) + self.grid_dys = grid_dcs[:,1].reshape((self.num_grids,1)) + self.grid_dzs = grid_dcs[:,2].reshape((self.num_grids,1)) + left_edges = [] + right_edges = [] + dims = [] + for level in self.levels: + left_edges += [g.LeftEdge for g in level.grids] + right_edges += [g.RightEdge for g in level.grids] + dims += [g.ActiveDimensions for g in level.grids] + self.grid_left_edge = na.array(left_edges) + self.grid_right_edge = na.array(right_edges) + self.grid_dimensions = na.array(dims) + self.gridReverseTree = [] * self.num_grids + self.gridReverseTree = [ [] for i in range(self.num_grids)] + self.gridTree = [ [] for i in range(self.num_grids)] + mylog.debug("Done creating grid objects") + + def _populate_hierarchy(self): + self.__setup_grid_tree() + #self._setup_grid_corners() + for i, grid in enumerate(self.grids): + if (i%1e4) == 0: mylog.debug("Prepared % 7i / % 7i grids", i, self.num_grids) + grid._prepare_grid() + grid._setup_dx() + + def __setup_grid_tree(self): + for i, grid in enumerate(self.grids): + children = self._get_grid_children(grid) + for child in children: + self.gridReverseTree[child.id].append(i) + self.gridTree[i].append(weakref.proxy(child)) + + def _setup_classes(self): + dd = self._get_data_reader_dict() + dd["field_indexes"] = self.field_indexes + AMRHierarchy._setup_classes(self, dd) + #self._add_object_class('grid', "OrionGrid", OrionGridBase, dd) + self.object_types.sort() + + def _get_grid_children(self, grid): + mask = na.zeros(self.num_grids, dtype='bool') + grids, grid_ind = self.get_box_grids(grid.LeftEdge, grid.RightEdge) + mask[grid_ind] = True + mask = na.logical_and(mask, (self.grid_levels == (grid.Level+1)).flat) + return self.grids[mask] + + def _setup_field_list(self): + self.derived_field_list = [] + for field in self.field_info: + try: + fd = self.field_info[field].get_dependencies(pf = self.parameter_file) + except: + continue + available = na.all([f in self.field_list for f in fd.requested]) + if available: self.derived_field_list.append(field) + for field in self.field_list: + if field not in self.derived_field_list: + self.derived_field_list.append(field) + + def _count_grids(self): + """this is already provided in + + """ + pass + + def _initialize_grid_arrays(self): + mylog.debug("Allocating arrays for %s grids", self.num_grids) + self.grid_dimensions = na.ones((self.num_grids,3), 'int32') + self.grid_left_edge = na.zeros((self.num_grids,3), self.float_type) + self.grid_right_edge = na.ones((self.num_grids,3), self.float_type) + self.grid_levels = na.zeros((self.num_grids,1), 'int32') + self.grid_particle_count = na.zeros((self.num_grids,1), 'int32') + + def _parse_hierarchy(self): + pass + + def _detect_fields(self): + pass + + def _setup_unknown_fields(self): + for field in self.field_list: + if field in self.parameter_file.field_info: continue + mylog.info("Adding %s to list of fields", field) + cf = None + if self.parameter_file.has_key(field): + def external_wrapper(f): + def _convert_function(data): + return data.convert(f) + return _convert_function + cf = external_wrapper(field) + add_field(field, lambda a, b: None, + convert_function=cf, take_log=False) + + + def _setup_derived_fields(self): + pass + + def _initialize_state_variables(self): + """override to not re-initialize num_grids in AMRHierarchy.__init__ + + """ + self._parallel_locking = False + self._data_file = None + self._data_mode = None + self._max_locations = {} + +class OrionLevel: + def __init__(self,level,ngrids): + self.level = level + self.ngrids = ngrids + self.grids = [] + + +class OrionStaticOutput(StaticOutput): + """ + This class is a stripped down class that simply reads and parses + *filename*, without looking at the Orion hierarchy. + """ + _hierarchy_class = OrionHierarchy + _fieldinfo_class = OrionFieldContainer + + def __init__(self, plotname, paramFilename=None, fparamFilename=None, + data_style='orion_native', paranoia=False, + storage_filename = None): + """need to override for Orion file structure. + + the paramfile is usually called "inputs" + and there may be a fortran inputs file usually called "probin" + plotname here will be a directory name + as per BoxLib, data_style will be one of + * Native + * IEEE (not implemented in yt) + * ASCII (not implemented in yt) + + """ + self.storage_filename = storage_filename + self.paranoid_read = paranoia + self.parameter_filename = paramFilename + self.fparameter_filename = fparamFilename + self.__ipfn = paramFilename + + self.fparameters = {} + + StaticOutput.__init__(self, plotname.rstrip("/"), + data_style='orion_native') + self.field_info = self._fieldinfo_class() + self._parse_header_file() + + # These should maybe not be hardcoded? + self.parameters["HydroMethod"] = 'orion' # always PPM DE + self.parameters["Time"] = 1. # default unit is 1... + self.parameters["DualEnergyFormalism"] = 0 # always off. + self.parameters["EOSType"] = -1 # default + if self.fparameters.has_key("mu"): + self.parameters["mu"] = self.fparameters["mu"] + + def _localize(self, f, default): + if f is None: + return os.path.join(self.directory, default) + return f + + @classmethod + def _is_valid(cls, *args, **kwargs): + # fill our args + pname = args[0].rstrip("/") + dn = os.path.dirname(pname) + if len(args) > 1: kwargs['paramFilename'] = args[1] + pfname = kwargs.get("paramFilename", os.path.join(dn, "inputs")) + return os.path.exists(os.path.join(pfname)) + + def _parse_parameter_file(self): + """ + Parses the parameter file and establishes the various + dictionaries. + """ + self.fullplotdir = os.path.abspath(self.parameter_filename) + self.parameter_filename = self._localize( + self.__ipfn, 'inputs') + self.fparameter_filename = self._localize( + self.fparameter_filename, 'probin') + if os.path.isfile(self.fparameter_filename): + self._parse_fparameter_file() + # Let's read the file + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[ST_CTIME]) + lines = open(self.parameter_filename).readlines() + for lineI, line in enumerate(lines): + if line.find("#") >= 1: # Keep the commented lines... + line=line[:line.find("#")] + line=line.strip().rstrip() + if len(line) < 2 or line.find("#") == 0: # ...but skip comments + continue + try: + param, vals = map(strip,map(rstrip,line.split("="))) + except ValueError: + mylog.error("ValueError: '%s'", line) + if orion2enzoDict.has_key(param): + paramName = orion2enzoDict[param] + t = map(parameterDict[paramName], vals.split()) + if len(t) == 1: + self.parameters[paramName] = t[0] + else: + if paramName == "RefineBy": + self.parameters[paramName] = t[0] + else: + self.parameters[paramName] = t + + elif param.startswith("geometry.prob_hi"): + self.domain_right_edge = \ + na.array([float(i) for i in vals.split()]) + elif param.startswith("geometry.prob_lo"): + self.domain_left_edge = \ + na.array([float(i) for i in vals.split()]) + + def _parse_fparameter_file(self): + """ + Parses the fortran parameter file for Orion. Most of this will + be useless, but this is where it keeps mu = mass per + particle/m_hydrogen. + """ + lines = open(self.fparameter_filename).readlines() + for line in lines: + if line.count("=") == 1: + param, vals = map(strip,map(rstrip,line.split("="))) + if vals.count("'") == 0: + t = map(float,[a.replace('D','e').replace('d','e') for a in vals.split()]) # all are floating point. + else: + t = vals.split() + if len(t) == 1: + self.fparameters[param] = t[0] + else: + self.fparameters[param] = t + + def _parse_header_file(self): + """ + Parses the BoxLib header file to get any parameters stored + there. Hierarchy information is read out of this file in + OrionHierarchy. + + Currently, only Time is read here. + """ + header_file = open(os.path.join(self.fullplotdir,'Header')) + lines = header_file.readlines() + header_file.close() + n_fields = int(lines[1]) + self.current_time = float(lines[3+n_fields]) + + + def _set_units(self): + """ + Generates the conversion to various physical _units based on the parameter file + """ + self.units = {} + self.time_units = {} + if len(self.parameters) == 0: + self._parse_parameter_file() + self._setup_nounits_units() + self.conversion_factors = defaultdict(lambda: 1.0) + self.time_units['1'] = 1 + self.units['1'] = 1.0 + self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() + seconds = 1 #self["Time"] + self.time_units['years'] = seconds / (365*3600*24.0) + self.time_units['days'] = seconds / (3600*24.0) + for key in yt2orionFieldsDict: + self.conversion_factors[key] = 1.0 + + def _setup_nounits_units(self): + z = 0 + mylog.warning("Setting 1.0 in code units to be 1.0 cm") + if not self.has_key("TimeUnits"): + mylog.warning("No time units. Setting 1.0 = 1 second.") + self.conversion_factors["Time"] = 1.0 + for unit in mpc_conversion.keys(): + self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/definitions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/definitions.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,72 @@ +""" +Various definitions for various other modules and routines + +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-20010 J.S. Oishi. 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 . + +""" +from yt.funcs import * + +# TODO: get rid of enzo parameters we do not need +parameterDict = {"CosmologyCurrentRedshift": float, + "CosmologyComovingBoxSize": float, + "CosmologyOmegaMatterNow": float, + "CosmologyOmegaLambdaNow": float, + "CosmologyHubbleConstantNow": float, + "CosmologyInitialRedshift": float, + "DualEnergyFormalismEta1": float, + "DualEnergyFormalismEta2": float, + "MetaDataString": str, + "HydroMethod": int, + "DualEnergyFormalism": int, + "InitialTime": float, + "ComovingCoordinates": int, + "DensityUnits": float, + "LengthUnits": float, + "LengthUnit": float, + "TemperatureUnits": float, + "TimeUnits": float, + "GravitationalConstant": float, + "Gamma": float, + "MultiSpecies": int, + "CompilerPrecision": str, + "CurrentTimeIdentifier": int, + "RefineBy": int, + "BoundaryConditionName": str, + "TopGridRank": int, + "TopGridDimensions": int, + "EOSSoundSpeed": float, + "EOSType": int, + "NumberOfParticleAttributes": int, + } + + +# converts the Orion inputs file name to the Enzo/yt name expected +# throughout the code. key is Orion name, value is Enzo/yt equivalent +orion2enzoDict = {"amr.n_cell": "TopGridRank", + "materials.gamma": "Gamma", + "amr.ref_ratio": "RefineBy" + } + +yt2orionFieldsDict = {} +orion2ytFieldsDict = {} + +orion_FAB_header_pattern = r"^FAB \(\((\d+), \([0-9 ]+\)\),\(\d+, \(([0-9 ]+)\)\)\)\(\((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\)\) (\d+)\n" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,144 @@ +""" +Orion-specific fields + +Author: J. S. Oishi +Affiliation: UC Berkeley +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2008-2010 J. S. Oishi, 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 . +""" +from yt.utilities.physical_constants import \ + mh, kboltz +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields + +class OrionFieldContainer(CodeFieldInfoContainer): + """ + All Orion-specific fields are stored in here. + """ + _shared_state = {} + _field_list = {} +OrionFieldInfo = OrionFieldContainer() +add_orion_field = OrionFieldInfo.add_field + + +add_field = add_orion_field + +# def _convertDensity(data): +# return data.convert("Density") +add_field("density", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("density")], + units=r"\rm{g}/\rm{cm}^3") +OrionFieldInfo["density"]._projected_units =r"\rm{g}/\rm{cm}^2" +#OrionFieldInfo["density"]._convert_function=_convertDensity + +add_field("eden", function=lambda a,b: None, take_log=True, + validators = [ValidateDataField("eden")], + units=r"\rm{erg}/\rm{cm}^3") + +add_field("xmom", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("xmom")], + units=r"\rm{g}/\rm{cm^2\ s}") + +add_field("ymom", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("ymom")], + units=r"\rm{gm}/\rm{cm^2\ s}") + +add_field("zmom", function=lambda a,b: None, take_log=False, + validators = [ValidateDataField("zmom")], + units=r"\rm{g}/\rm{cm^2\ s}") + +translation_dict = {"x-velocity": "xvel", + "y-velocity": "yvel", + "z-velocity": "zvel", + "Density": "density", + "Total_Energy": "eden", + "Temperature": "temperature", + "x-momentum": "xmom", + "y-momentum": "ymom", + "z-momentum": "zmom" + } + +def _generate_translation(mine, theirs): + add_field(theirs, function=lambda a, b: b[mine], take_log=True) + +for f,v in translation_dict.items(): + if v not in OrionFieldInfo: + add_field(v, function=lambda a,b: None, take_log=False, + validators = [ValidateDataField(v)]) + #print "Setting up translator from %s to %s" % (v, f) + _generate_translation(v, f) + +def _xVelocity(field, data): + """generate x-velocity from x-momentum and density + + """ + return data["xmom"]/data["density"] +add_field("x-velocity",function=_xVelocity, take_log=False, + units=r'\rm{cm}/\rm{s}') + +def _yVelocity(field,data): + """generate y-velocity from y-momentum and density + + """ + #try: + # return data["xvel"] + #except KeyError: + return data["ymom"]/data["density"] +add_field("y-velocity",function=_yVelocity, take_log=False, + units=r'\rm{cm}/\rm{s}') + +def _zVelocity(field,data): + """generate z-velocity from z-momentum and density + + """ + return data["zmom"]/data["density"] +add_field("z-velocity",function=_zVelocity, take_log=False, + units=r'\rm{cm}/\rm{s}') + +def _ThermalEnergy(field, data): + """generate thermal (gas energy). Dual Energy Formalism was + implemented by Stella, but this isn't how it's called, so I'll + leave that commented out for now. + """ + #if data.pf["DualEnergyFormalism"]: + # return data["Gas_Energy"] + #else: + return data["Total_Energy"] - 0.5 * data["density"] * ( + data["x-velocity"]**2.0 + + data["y-velocity"]**2.0 + + data["z-velocity"]**2.0 ) +add_field("ThermalEnergy", function=_ThermalEnergy, + units=r"\rm{ergs}/\rm{cm^3}") + +def _Pressure(field,data): + """M{(Gamma-1.0)*e, where e is thermal energy density + NB: this will need to be modified for radiation + """ + return (data.pf["Gamma"] - 1.0)*data["ThermalEnergy"] +add_field("Pressure", function=_Pressure, units=r"\rm{dyne}/\rm{cm}^{2}") + +def _Temperature(field,data): + return (data.pf["Gamma"]-1.0)*data.pf["mu"]*mh*data["ThermalEnergy"]/(kboltz*data["Density"]) +add_field("Temperature",function=_Temperature,units=r"\rm{Kelvin}",take_log=False) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,129 @@ +""" +Orion data-file handling functions + +Author: Matthew Turk +Author: J. S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-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 . +""" + +import os +import numpy as na +from yt.utilities.io_handler import \ + BaseIOHandler + +from definitions import \ + yt2orionFieldsDict + +class IOHandlerNative(BaseIOHandler): + + _data_style = "orion_native" + + def modify(self, field): + return field.swapaxes(0,2) + + def _read_data_set(self,grid,field): + """ + reads packed multiFABs output by BoxLib in "NATIVE" format. + + """ + filen = os.path.expanduser(grid.filename[field]) + off = grid._offset[field] + inFile = open(filen,'rb') + inFile.seek(off) + header = inFile.readline() + header.strip() + + if grid._paranoid: + mylog.warn("Orion Native reader: Paranoid read mode.") + headerRe = re.compile(orion_FAB_header_pattern) + bytesPerReal,endian,start,stop,centerType,nComponents = headerRe.search(header).groups() + + # we will build up a dtype string, starting with endian + # check endianness (this code is ugly. fix?) + bytesPerReal = int(bytesPerReal) + if bytesPerReal == int(endian[0]): + dtype = '<' + elif bytesPerReal == int(endian[-1]): + dtype = '>' + else: + raise ValueError("FAB header is neither big nor little endian. Perhaps the file is corrupt?") + + dtype += ('f%i'% bytesPerReal) #always a floating point + + # determine size of FAB + start = na.array(map(int,start.split(','))) + stop = na.array(map(int,stop.split(','))) + + gridSize = stop - start + 1 + + error_count = 0 + if (start != grid.start).any(): + print "Paranoia Error: Cell_H and %s do not agree on grid start." %grid.filename + error_count += 1 + if (stop != grid.stop).any(): + print "Paranoia Error: Cell_H and %s do not agree on grid stop." %grid.filename + error_count += 1 + if (gridSize != grid.ActiveDimensions).any(): + print "Paranoia Error: Cell_H and %s do not agree on grid dimensions." %grid.filename + error_count += 1 + if bytesPerReal != grid.hierarchy._bytesPerReal: + print "Paranoia Error: Cell_H and %s do not agree on bytes per real number." %grid.filename + error_count += 1 + if (bytesPerReal == grid.hierarchy._bytesPerReal and dtype != grid.hierarchy._dtype): + print "Paranoia Error: Cell_H and %s do not agree on endianness." %grid.filename + error_count += 1 + + if error_count > 0: + raise RunTimeError("Paranoia unveiled %i differences between Cell_H and %s." % (error_count, grid.filename)) + + else: + start = grid.start_index + stop = grid.stop_index + dtype = grid.hierarchy._dtype + bytesPerReal = grid.hierarchy._bytesPerReal + + nElements = grid.ActiveDimensions.prod() + + # one field has nElements*bytesPerReal bytes and is located + # nElements*bytesPerReal*field_index from the offset location + if yt2orionFieldsDict.has_key(field): + fieldname = yt2orionFieldsDict[field] + else: + fieldname = field + field_index = grid.field_indexes[fieldname] + inFile.seek(int(nElements*bytesPerReal*field_index),1) + field = na.fromfile(inFile,count=nElements,dtype=dtype) + field = field.reshape(grid.ActiveDimensions[::-1]).swapaxes(0,2) + + # we can/should also check against the max and min in the header file + + inFile.close() + return field + + def _read_data_slice(self, grid, field, axis, coord): + """wishful thinking? + """ + sl = [slice(None), slice(None), slice(None)] + sl[axis] = slice(coord, coord + 1) + #sl = tuple(reversed(sl)) + return self._read_data_set(grid,field)[sl] + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/orion/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/orion/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('orion',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.frontends.ramses + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/_ramses_reader.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/_ramses_reader.cpp Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,11494 @@ +/* Generated by Cython 0.13.beta0 on Thu Aug 26 14:34:14 2010 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#else + +#include /* For offsetof */ +#ifndef offsetof +#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif + +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif + +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif + +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif + +#if PY_VERSION_HEX < 0x02040000 + #define METH_COEXIST 0 + #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) + #define PyDict_Contains(d,o) PySequence_Contains(d,o) +#endif + +#if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #define PY_SSIZE_T_MAX INT_MAX + #define PY_SSIZE_T_MIN INT_MIN + #define PY_FORMAT_SIZE_T "" + #define PyInt_FromSsize_t(z) PyInt_FromLong(z) + #define PyInt_AsSsize_t(o) PyInt_AsLong(o) + #define PyNumber_Index(o) PyNumber_Int(o) + #define PyIndex_Check(o) PyNumber_Check(o) + #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) + #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) + #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, + #define PyType_Modified(t) + + typedef struct { + void *buf; + PyObject *obj; + Py_ssize_t len; + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + void *internal; + } Py_buffer; + + #define PyBUF_SIMPLE 0 + #define PyBUF_WRITABLE 0x0001 + #define PyBUF_FORMAT 0x0004 + #define PyBUF_ND 0x0008 + #define PyBUF_STRIDES (0x0010 | PyBUF_ND) + #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) + #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) + #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) + #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) + +#endif + +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#endif + +#if PY_MAJOR_VERSION >= 3 + #define Py_TPFLAGS_CHECKTYPES 0 + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif + +#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PyBytesObject PyStringObject + #define PyBytes_Type PyString_Type + #define PyBytes_Check PyString_Check + #define PyBytes_CheckExact PyString_CheckExact + #define PyBytes_FromString PyString_FromString + #define PyBytes_FromStringAndSize PyString_FromStringAndSize + #define PyBytes_FromFormat PyString_FromFormat + #define PyBytes_DecodeEscape PyString_DecodeEscape + #define PyBytes_AsString PyString_AsString + #define PyBytes_AsStringAndSize PyString_AsStringAndSize + #define PyBytes_Size PyString_Size + #define PyBytes_AS_STRING PyString_AS_STRING + #define PyBytes_GET_SIZE PyString_GET_SIZE + #define PyBytes_Repr PyString_Repr + #define PyBytes_Concat PyString_Concat + #define PyBytes_ConcatAndDel PyString_ConcatAndDel + #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) + #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) +#endif + +#ifndef PySet_CheckExact +# define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask +#endif + +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) +#endif + +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) +#else + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) +#endif + +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_NAMESTR(n) ((char *)(n)) + #define __Pyx_DOCSTR(n) ((char *)(n)) +#else + #define __Pyx_NAMESTR(n) (n) + #define __Pyx_DOCSTR(n) (n) +#endif + +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) +#define _USE_MATH_DEFINES +#endif +#include +#define __PYX_HAVE_API__yt__frontends__ramses___ramses_reader +#include "stdlib.h" +#include "stdio.h" +#include "numpy/arrayobject.h" +#include "numpy/ufuncobject.h" +#include +#include +#include "string" +#include "RAMSES_typedefs.h" +#include "RAMSES_info.hh" +#include "RAMSES_amr_data.hh" + +/* inline attribute */ +#ifndef CYTHON_INLINE + #if defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +/* unused attribute */ +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || defined(__INTEL_COMPILER) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif + +typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ + + +/* Type Conversion Predeclarations */ + +#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) +#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) + +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); + +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) + + +#ifdef __GNUC__ +/* Test for GCC > 2.95 */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else /* __GNUC__ > 2 ... */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ > 2 ... */ +#else /* __GNUC__ */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ */ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +#if !defined(CYTHON_CCOMPLEX) + #if defined(__cplusplus) + #define CYTHON_CCOMPLEX 1 + #elif defined(_Complex_I) + #define CYTHON_CCOMPLEX 1 + #else + #define CYTHON_CCOMPLEX 0 + #endif +#endif + +#if CYTHON_CCOMPLEX + #ifdef __cplusplus + #include + #else + #include + #endif +#endif + +#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__) + #undef _Complex_I + #define _Complex_I 1.0fj +#endif + +static const char *__pyx_f[] = { + "_ramses_reader.pyx", + "numpy.pxd", +}; + +typedef npy_int8 __pyx_t_5numpy_int8_t; + +typedef npy_int16 __pyx_t_5numpy_int16_t; + +typedef npy_int32 __pyx_t_5numpy_int32_t; + +typedef npy_int64 __pyx_t_5numpy_int64_t; + +typedef npy_uint8 __pyx_t_5numpy_uint8_t; + +typedef npy_uint16 __pyx_t_5numpy_uint16_t; + +typedef npy_uint32 __pyx_t_5numpy_uint32_t; + +typedef npy_uint64 __pyx_t_5numpy_uint64_t; + +typedef npy_float32 __pyx_t_5numpy_float32_t; + +typedef npy_float64 __pyx_t_5numpy_float64_t; + +typedef npy_long __pyx_t_5numpy_int_t; + +typedef npy_longlong __pyx_t_5numpy_long_t; + +typedef npy_intp __pyx_t_5numpy_intp_t; + +typedef npy_uintp __pyx_t_5numpy_uintp_t; + +typedef npy_ulong __pyx_t_5numpy_uint_t; + +typedef npy_ulonglong __pyx_t_5numpy_ulong_t; + +typedef npy_double __pyx_t_5numpy_float_t; + +typedef npy_double __pyx_t_5numpy_double_t; + +typedef npy_longdouble __pyx_t_5numpy_longdouble_t; + +#if CYTHON_CCOMPLEX + #ifdef __cplusplus + typedef ::std::complex< float > __pyx_t_float_complex; + #else + typedef float _Complex __pyx_t_float_complex; + #endif +#else + typedef struct { float real, imag; } __pyx_t_float_complex; +#endif + +#if CYTHON_CCOMPLEX + #ifdef __cplusplus + typedef ::std::complex< double > __pyx_t_double_complex; + #else + typedef double _Complex __pyx_t_double_complex; + #endif +#else + typedef struct { double real, imag; } __pyx_t_double_complex; +#endif + +/* Type declarations */ + +typedef npy_cfloat __pyx_t_5numpy_cfloat_t; + +typedef npy_cdouble __pyx_t_5numpy_cdouble_t; + +typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; + +typedef npy_cdouble __pyx_t_5numpy_complex_t; + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":371 + * vector[vector[double]] m_var_array + * + * cdef class RAMSES_tree_proxy: # <<<<<<<<<<<<<< + * cdef string *snapshot_name + * cdef snapshot *rsnap + */ + +struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy { + PyObject_HEAD + std::string *snapshot_name; + RAMSES::snapshot *rsnap; + RAMSES::AMR::RAMSES_tree **trees; + RAMSES::HYDRO::RAMSES_hydro_data ***hydro_datas; + int **loaded; + PyObject *field_ind; + PyObject *field_names; + int ndomains; + int nfields; +}; + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":694 + * return to_fill + * + * cdef class ProtoSubgrid: # <<<<<<<<<<<<<< + * cdef np.int64_t *signature[3] + * cdef np.int64_t left_edge[3] + */ + +struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid { + PyObject_HEAD + __pyx_t_5numpy_int64_t *signature[3]; + __pyx_t_5numpy_int64_t left_edge[3]; + __pyx_t_5numpy_int64_t right_edge[3]; + __pyx_t_5numpy_int64_t dimensions[3]; + __pyx_t_5numpy_float64_t efficiency; + PyObject *sigs; + PyObject *grid_file_locations; + PyObject *dd; +}; + +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif + +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); + end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; + } + #define __Pyx_RefNannySetupContext(name) void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) + #define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0) +#else + #define __Pyx_RefNannySetupContext(name) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) +#endif /* CYTHON_REFNANNY */ +#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0) +#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0) + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, PyObject* kw_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ + +static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (PyList_Append(L, x) < 0) return NULL; + Py_INCREF(Py_None); + return Py_None; /* this is just to have an accurate signature */ + } + else { + PyObject *r, *m; + m = __Pyx_GetAttrString(L, "append"); + if (!m) return NULL; + r = PyObject_CallFunctionObjArgs(m, x, NULL); + Py_DECREF(m); + return r; + } +} + + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} + + +#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_List_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { + if (likely(o != Py_None)) { + if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Tuple_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { + if (likely(o != Py_None)) { + if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + + +#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { + PyObject *r; + if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { + r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + } + else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + } + else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) { + r = PySequence_GetItem(o, i); + } + else { + r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); + } + return r; +} + +#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_SetItemInt_Fast(o, i, v) : \ + __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) + +static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { + int r; + if (!j) return -1; + r = PyObject_SetItem(o, j, v); + Py_DECREF(j); + return r; +} + +static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { + if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { + Py_INCREF(v); + Py_DECREF(PyList_GET_ITEM(o, i)); + PyList_SET_ITEM(o, i, v); + return 1; + } + else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && (likely(i >= 0))) + return PySequence_SetItem(o, i, v); + else { + PyObject *j = PyInt_FromSsize_t(i); + return __Pyx_SetItemInt_Generic(o, j, v); + } +} + +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ + +/* Run-time type information about structs used with buffers */ +struct __Pyx_StructField_; + +typedef struct { + const char* name; /* for error messages only */ + struct __Pyx_StructField_* fields; + size_t size; /* sizeof(type) */ + char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */ +} __Pyx_TypeInfo; + +typedef struct __Pyx_StructField_ { + __Pyx_TypeInfo* type; + const char* name; + size_t offset; +} __Pyx_StructField; + +typedef struct { + __Pyx_StructField* field; + size_t parent_offset; +} __Pyx_BufFmt_StackElem; + + +static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); +static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); +static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ +#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); /*proto*/ +#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) + +static void __Pyx_RaiseBufferFallbackError(void); /*proto*/ + +static CYTHON_INLINE int __Pyx_div_int(int, int); /* proto */ + +#define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) +#define __Pyx_BufPtrStrided3d(type, buf, i0, s0, i1, s1, i2, s2) (type)((char*)buf + i0 * s0 + i1 * s1 + i2 * s2) + +static CYTHON_INLINE __pyx_t_5numpy_int64_t __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /* proto */ + +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); + +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/ +#if PY_MAJOR_VERSION < 3 +static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); +static void __Pyx_ReleaseBuffer(Py_buffer *view); +#else +#define __Pyx_GetBuffer PyObject_GetBuffer +#define __Pyx_ReleaseBuffer PyBuffer_Release +#endif + +Py_ssize_t __Pyx_zeros[] = {0, 0, 0}; +Py_ssize_t __Pyx_minusones[] = {-1, -1, -1}; + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ + +static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/ +#if PY_MAJOR_VERSION >= 3 +static PyObject* __pyx_print = 0; +static PyObject* __pyx_print_kwargs = 0; +#endif + +static CYTHON_INLINE long __Pyx_pow_long(long, long); /* proto */ + +static CYTHON_INLINE npy_int64 __Pyx_PyInt_from_py_npy_int64(PyObject *); + +static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int64(npy_int64); + +#if CYTHON_CCOMPLEX + #ifdef __cplusplus + #define __Pyx_CREAL(z) ((z).real()) + #define __Pyx_CIMAG(z) ((z).imag()) + #else + #define __Pyx_CREAL(z) (__real__(z)) + #define __Pyx_CIMAG(z) (__imag__(z)) + #endif +#else + #define __Pyx_CREAL(z) ((z).real) + #define __Pyx_CIMAG(z) ((z).imag) +#endif + +#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX + #define __Pyx_SET_CREAL(z,x) ((z).real(x)) + #define __Pyx_SET_CIMAG(z,y) ((z).imag(y)) +#else + #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x) + #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y) +#endif + +static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); + +#if CYTHON_CCOMPLEX + #define __Pyx_c_eqf(a, b) ((a)==(b)) + #define __Pyx_c_sumf(a, b) ((a)+(b)) + #define __Pyx_c_difff(a, b) ((a)-(b)) + #define __Pyx_c_prodf(a, b) ((a)*(b)) + #define __Pyx_c_quotf(a, b) ((a)/(b)) + #define __Pyx_c_negf(a) (-(a)) + #ifdef __cplusplus + #define __Pyx_c_is_zerof(z) ((z)==(float)0) + #define __Pyx_c_conjf(z) (::std::conj(z)) + /*#define __Pyx_c_absf(z) (::std::abs(z))*/ + #else + #define __Pyx_c_is_zerof(z) ((z)==0) + #define __Pyx_c_conjf(z) (conjf(z)) + /*#define __Pyx_c_absf(z) (cabsf(z))*/ + #endif +#else + static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex); + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex); + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex); + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex); + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex); + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex); + static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex); + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex); + /*static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);*/ +#endif + +static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); + +#if CYTHON_CCOMPLEX + #define __Pyx_c_eq(a, b) ((a)==(b)) + #define __Pyx_c_sum(a, b) ((a)+(b)) + #define __Pyx_c_diff(a, b) ((a)-(b)) + #define __Pyx_c_prod(a, b) ((a)*(b)) + #define __Pyx_c_quot(a, b) ((a)/(b)) + #define __Pyx_c_neg(a) (-(a)) + #ifdef __cplusplus + #define __Pyx_c_is_zero(z) ((z)==(double)0) + #define __Pyx_c_conj(z) (::std::conj(z)) + /*#define __Pyx_c_abs(z) (::std::abs(z))*/ + #else + #define __Pyx_c_is_zero(z) ((z)==0) + #define __Pyx_c_conj(z) (conj(z)) + /*#define __Pyx_c_abs(z) (cabs(z))*/ + #endif +#else + static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex); + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex); + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex); + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex); + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex); + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex); + static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex); + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex); + /*static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);*/ +#endif + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict); /*proto*/ + +static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ + +static void __Pyx_AddTraceback(const char *funcname); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ +/* Module declarations from libc.stdlib */ + +/* Module declarations from cpython.buffer */ + +/* Module declarations from cpython.ref */ + +/* Module declarations from libc.stdio */ + +/* Module declarations from cpython.object */ + +/* Module declarations from numpy */ + +/* Module declarations from numpy */ + +static PyTypeObject *__pyx_ptype_5numpy_dtype = 0; +static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0; +static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0; +static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0; +static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *, PyObject *); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *, PyObject *, PyObject *); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *, PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ +static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/ +static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *, PyObject *); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *); /*proto*/ +/* Module declarations from cython */ + +/* Module declarations from yt.frontends.ramses._ramses_reader */ + +static PyTypeObject *__pyx_ptype_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy = 0; +static PyTypeObject *__pyx_ptype_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid = 0; +static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64max(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /*proto*/ +static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64min(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /*proto*/ +static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t = { "int32_t", NULL, sizeof(__pyx_t_5numpy_int32_t), 'I' }; +static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t = { "float64_t", NULL, sizeof(__pyx_t_5numpy_float64_t), 'R' }; +static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t = { "int64_t", NULL, sizeof(__pyx_t_5numpy_int64_t), 'I' }; +#define __Pyx_MODULE_NAME "yt.frontends.ramses._ramses_reader" +int __pyx_module_is_main_yt__frontends__ramses___ramses_reader = 0; + +/* Implementation of yt.frontends.ramses._ramses_reader */ +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_RuntimeError; +static char __pyx_k_1[] = "READING FROM DISK"; +static char __pyx_k_2[] = "get_absolute_position"; +static char __pyx_k_3[] = "ndarray is not C contiguous"; +static char __pyx_k_4[] = "ndarray is not Fortran contiguous"; +static char __pyx_k_5[] = "Non-native byte order not supported"; +static char __pyx_k_6[] = "unknown dtype code in numpy.pxd (%d)"; +static char __pyx_k_7[] = "Format string allocated too short, see comment in numpy.pxd"; +static char __pyx_k_8[] = "Format string allocated too short."; +static char __pyx_k_9[] = "\nWrapping code for Oliver Hahn's RamsesRead++\n\nAuthor: Matthew Turk \nAffiliation: UCSD\nAuthor: Oliver Hahn \nAffiliation: KIPAC / Stanford\nHomepage: http://yt.enzotools.org/\nLicense:\n Copyright (C) 2010 Matthew Turk. All Rights Reserved.\n\n This file is part of yt.\n\n yt is free software; you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation; either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see .\n"; +static char __pyx_k__B[] = "B"; +static char __pyx_k__F[] = "F"; +static char __pyx_k__H[] = "H"; +static char __pyx_k__I[] = "I"; +static char __pyx_k__L[] = "L"; +static char __pyx_k__O[] = "O"; +static char __pyx_k__Q[] = "Q"; +static char __pyx_k__b[] = "b"; +static char __pyx_k__d[] = "d"; +static char __pyx_k__f[] = "f"; +static char __pyx_k__g[] = "g"; +static char __pyx_k__h[] = "h"; +static char __pyx_k__i[] = "i"; +static char __pyx_k__l[] = "l"; +static char __pyx_k__q[] = "q"; +static char __pyx_k__x[] = "x"; +static char __pyx_k__y[] = "y"; +static char __pyx_k__z[] = "z"; +static char __pyx_k__H0[] = "H0"; +static char __pyx_k__Zd[] = "Zd"; +static char __pyx_k__Zf[] = "Zf"; +static char __pyx_k__Zg[] = "Zg"; +static char __pyx_k__dd[] = "dd"; +static char __pyx_k__fn[] = "fn"; +static char __pyx_k__np[] = "np"; +static char __pyx_k__nx[] = "nx"; +static char __pyx_k__buf[] = "buf"; +static char __pyx_k__end[] = "end"; +static char __pyx_k__obj[] = "obj"; +static char __pyx_k__aexp[] = "aexp"; +static char __pyx_k__base[] = "base"; +static char __pyx_k__data[] = "data"; +static char __pyx_k__ncpu[] = "ncpu"; +static char __pyx_k__ndim[] = "ndim"; +static char __pyx_k__next[] = "next"; +static char __pyx_k__ones[] = "ones"; +static char __pyx_k__read[] = "read"; +static char __pyx_k__sigs[] = "sigs"; +static char __pyx_k__time[] = "time"; +static char __pyx_k__begin[] = "begin"; +static char __pyx_k__c_str[] = "c_str"; +static char __pyx_k__descr[] = "descr"; +static char __pyx_k__dtype[] = "dtype"; +static char __pyx_k__empty[] = "empty"; +static char __pyx_k__field[] = "field"; +static char __pyx_k__int32[] = "int32"; +static char __pyx_k__int64[] = "int64"; +static char __pyx_k__level[] = "level"; +static char __pyx_k__names[] = "names"; +static char __pyx_k__numpy[] = "numpy"; +static char __pyx_k__order[] = "order"; +static char __pyx_k__range[] = "range"; +static char __pyx_k__rsnap[] = "rsnap"; +static char __pyx_k__shape[] = "shape"; +static char __pyx_k__trees[] = "trees"; +static char __pyx_k__zeros[] = "zeros"; +static char __pyx_k__boxlen[] = "boxlen"; +static char __pyx_k__domain[] = "domain"; +static char __pyx_k__fields[] = "fields"; +static char __pyx_k__filled[] = "filled"; +static char __pyx_k__format[] = "format"; +static char __pyx_k__loaded[] = "loaded"; +static char __pyx_k__unit_d[] = "unit_d"; +static char __pyx_k__unit_l[] = "unit_l"; +static char __pyx_k__unit_t[] = "unit_t"; +static char __pyx_k__argsort[] = "argsort"; +static char __pyx_k__float64[] = "float64"; +static char __pyx_k__grid_id[] = "grid_id"; +static char __pyx_k__m_nvars[] = "m_nvars"; +static char __pyx_k__nfields[] = "nfields"; +static char __pyx_k__omega_b[] = "omega_b"; +static char __pyx_k__omega_k[] = "omega_k"; +static char __pyx_k__omega_l[] = "omega_l"; +static char __pyx_k__omega_m[] = "omega_m"; +static char __pyx_k__strides[] = "strides"; +static char __pyx_k__varname[] = "varname"; +static char __pyx_k____main__[] = "__main__"; +static char __pyx_k____test__[] = "__test__"; +static char __pyx_k__itemsize[] = "itemsize"; +static char __pyx_k__levelmax[] = "levelmax"; +static char __pyx_k__levelmin[] = "levelmin"; +static char __pyx_k__m_header[] = "m_header"; +static char __pyx_k__ndomains[] = "ndomains"; +static char __pyx_k__ngridmax[] = "ngridmax"; +static char __pyx_k__readonly[] = "readonly"; +static char __pyx_k__type_num[] = "type_num"; +static char __pyx_k__byteorder[] = "byteorder"; +static char __pyx_k__field_ind[] = "field_ind"; +static char __pyx_k__grid_dims[] = "grid_dims"; +static char __pyx_k__is_finest[] = "is_finest"; +static char __pyx_k__left_edge[] = "left_edge"; +static char __pyx_k__signature[] = "signature"; +static char __pyx_k__ValueError[] = "ValueError"; +static char __pyx_k__child_mask[] = "child_mask"; +static char __pyx_k__dimensions[] = "dimensions"; +static char __pyx_k__efficiency[] = "efficiency"; +static char __pyx_k__get_domain[] = "get_domain"; +static char __pyx_k__get_parent[] = "get_parent"; +static char __pyx_k__left_edges[] = "left_edges"; +static char __pyx_k__left_index[] = "left_index"; +static char __pyx_k__m_maxlevel[] = "m_maxlevel"; +static char __pyx_k__m_varnames[] = "m_varnames"; +static char __pyx_k__ref_factor[] = "ref_factor"; +static char __pyx_k__right_edge[] = "right_edge"; +static char __pyx_k__suboffsets[] = "suboffsets"; +static char __pyx_k__field_names[] = "field_names"; +static char __pyx_k__grid_levels[] = "grid_levels"; +static char __pyx_k__hydro_datas[] = "hydro_datas"; +static char __pyx_k__m_var_array[] = "m_var_array"; +static char __pyx_k__right_edges[] = "right_edges"; +static char __pyx_k__start_index[] = "start_index"; +static char __pyx_k__RuntimeError[] = "RuntimeError"; +static char __pyx_k__domain_index[] = "domain_index"; +static char __pyx_k__m_AMR_levels[] = "m_AMR_levels"; +static char __pyx_k__nstep_coarse[] = "nstep_coarse"; +static char __pyx_k__ensure_loaded[] = "ensure_loaded"; +static char __pyx_k__snapshot_name[] = "snapshot_name"; +static char __pyx_k__top_grid_dims[] = "top_grid_dims"; +static char __pyx_k__grid_dimensions[] = "grid_dimensions"; +static char __pyx_k__grid_pos_double[] = "grid_pos_double"; +static char __pyx_k__component_grid_info[] = "component_grid_info"; +static char __pyx_k__grid_file_locations[] = "grid_file_locations"; +static PyObject *__pyx_kp_s_1; +static PyObject *__pyx_n_s_2; +static PyObject *__pyx_kp_u_3; +static PyObject *__pyx_kp_u_4; +static PyObject *__pyx_kp_u_5; +static PyObject *__pyx_kp_u_6; +static PyObject *__pyx_kp_u_7; +static PyObject *__pyx_kp_u_8; +static PyObject *__pyx_n_s__F; +static PyObject *__pyx_n_s__H0; +static PyObject *__pyx_n_s__RuntimeError; +static PyObject *__pyx_n_s__ValueError; +static PyObject *__pyx_n_s____main__; +static PyObject *__pyx_n_s____test__; +static PyObject *__pyx_n_s__aexp; +static PyObject *__pyx_n_s__argsort; +static PyObject *__pyx_n_s__base; +static PyObject *__pyx_n_s__begin; +static PyObject *__pyx_n_s__boxlen; +static PyObject *__pyx_n_s__buf; +static PyObject *__pyx_n_s__byteorder; +static PyObject *__pyx_n_s__c_str; +static PyObject *__pyx_n_s__child_mask; +static PyObject *__pyx_n_s__component_grid_info; +static PyObject *__pyx_n_s__data; +static PyObject *__pyx_n_s__dd; +static PyObject *__pyx_n_s__descr; +static PyObject *__pyx_n_s__dimensions; +static PyObject *__pyx_n_s__domain; +static PyObject *__pyx_n_s__domain_index; +static PyObject *__pyx_n_s__dtype; +static PyObject *__pyx_n_s__efficiency; +static PyObject *__pyx_n_s__empty; +static PyObject *__pyx_n_s__end; +static PyObject *__pyx_n_s__ensure_loaded; +static PyObject *__pyx_n_s__field; +static PyObject *__pyx_n_s__field_ind; +static PyObject *__pyx_n_s__field_names; +static PyObject *__pyx_n_s__fields; +static PyObject *__pyx_n_s__filled; +static PyObject *__pyx_n_s__float64; +static PyObject *__pyx_n_s__fn; +static PyObject *__pyx_n_s__format; +static PyObject *__pyx_n_s__get_domain; +static PyObject *__pyx_n_s__get_parent; +static PyObject *__pyx_n_s__grid_dimensions; +static PyObject *__pyx_n_s__grid_dims; +static PyObject *__pyx_n_s__grid_file_locations; +static PyObject *__pyx_n_s__grid_id; +static PyObject *__pyx_n_s__grid_levels; +static PyObject *__pyx_n_s__grid_pos_double; +static PyObject *__pyx_n_s__hydro_datas; +static PyObject *__pyx_n_s__int32; +static PyObject *__pyx_n_s__int64; +static PyObject *__pyx_n_s__is_finest; +static PyObject *__pyx_n_s__itemsize; +static PyObject *__pyx_n_s__left_edge; +static PyObject *__pyx_n_s__left_edges; +static PyObject *__pyx_n_s__left_index; +static PyObject *__pyx_n_s__level; +static PyObject *__pyx_n_s__levelmax; +static PyObject *__pyx_n_s__levelmin; +static PyObject *__pyx_n_s__loaded; +static PyObject *__pyx_n_s__m_AMR_levels; +static PyObject *__pyx_n_s__m_header; +static PyObject *__pyx_n_s__m_maxlevel; +static PyObject *__pyx_n_s__m_nvars; +static PyObject *__pyx_n_s__m_var_array; +static PyObject *__pyx_n_s__m_varnames; +static PyObject *__pyx_n_s__names; +static PyObject *__pyx_n_s__ncpu; +static PyObject *__pyx_n_s__ndim; +static PyObject *__pyx_n_s__ndomains; +static PyObject *__pyx_n_s__next; +static PyObject *__pyx_n_s__nfields; +static PyObject *__pyx_n_s__ngridmax; +static PyObject *__pyx_n_s__np; +static PyObject *__pyx_n_s__nstep_coarse; +static PyObject *__pyx_n_s__numpy; +static PyObject *__pyx_n_s__nx; +static PyObject *__pyx_n_s__obj; +static PyObject *__pyx_n_s__omega_b; +static PyObject *__pyx_n_s__omega_k; +static PyObject *__pyx_n_s__omega_l; +static PyObject *__pyx_n_s__omega_m; +static PyObject *__pyx_n_s__ones; +static PyObject *__pyx_n_s__order; +static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__read; +static PyObject *__pyx_n_s__readonly; +static PyObject *__pyx_n_s__ref_factor; +static PyObject *__pyx_n_s__right_edge; +static PyObject *__pyx_n_s__right_edges; +static PyObject *__pyx_n_s__rsnap; +static PyObject *__pyx_n_s__shape; +static PyObject *__pyx_n_s__signature; +static PyObject *__pyx_n_s__sigs; +static PyObject *__pyx_n_s__snapshot_name; +static PyObject *__pyx_n_s__start_index; +static PyObject *__pyx_n_s__strides; +static PyObject *__pyx_n_s__suboffsets; +static PyObject *__pyx_n_s__time; +static PyObject *__pyx_n_s__top_grid_dims; +static PyObject *__pyx_n_s__trees; +static PyObject *__pyx_n_s__type_num; +static PyObject *__pyx_n_s__unit_d; +static PyObject *__pyx_n_s__unit_l; +static PyObject *__pyx_n_s__unit_t; +static PyObject *__pyx_n_s__varname; +static PyObject *__pyx_n_s__x; +static PyObject *__pyx_n_s__y; +static PyObject *__pyx_n_s__z; +static PyObject *__pyx_n_s__zeros; +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; +static PyObject *__pyx_int_3; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_int_15; + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":36 + * cimport cython + * + * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): # <<<<<<<<<<<<<< + * if i0 > i1: return i0 + * return i1 + */ + +static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64max(__pyx_t_5numpy_int64_t __pyx_v_i0, __pyx_t_5numpy_int64_t __pyx_v_i1) { + __pyx_t_5numpy_int64_t __pyx_r; + int __pyx_t_1; + __Pyx_RefNannySetupContext("i64max"); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":37 + * + * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): + * if i0 > i1: return i0 # <<<<<<<<<<<<<< + * return i1 + * + */ + __pyx_t_1 = (__pyx_v_i0 > __pyx_v_i1); + if (__pyx_t_1) { + __pyx_r = __pyx_v_i0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":38 + * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): + * if i0 > i1: return i0 + * return i1 # <<<<<<<<<<<<<< + * + * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): + */ + __pyx_r = __pyx_v_i1; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":40 + * return i1 + * + * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): # <<<<<<<<<<<<<< + * if i0 < i1: return i0 + * return i1 + */ + +static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64min(__pyx_t_5numpy_int64_t __pyx_v_i0, __pyx_t_5numpy_int64_t __pyx_v_i1) { + __pyx_t_5numpy_int64_t __pyx_r; + int __pyx_t_1; + __Pyx_RefNannySetupContext("i64min"); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":41 + * + * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): + * if i0 < i1: return i0 # <<<<<<<<<<<<<< + * return i1 + * + */ + __pyx_t_1 = (__pyx_v_i0 < __pyx_v_i1); + if (__pyx_t_1) { + __pyx_r = __pyx_v_i0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":42 + * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): + * if i0 < i1: return i0 + * return i1 # <<<<<<<<<<<<<< + * + * cdef extern from "" namespace "std": + */ + __pyx_r = __pyx_v_i1; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":380 + * cdef int **loaded + * + * cdef public object field_ind # <<<<<<<<<<<<<< + * cdef public object field_names + * + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannySetupContext("__get__"); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + __pyx_r = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannySetupContext("__set__"); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannySetupContext("__del__"); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":381 + * + * cdef public object field_ind + * cdef public object field_names # <<<<<<<<<<<<<< + * + * # We will store this here so that we have a record, independent of the + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannySetupContext("__get__"); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + __pyx_r = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannySetupContext("__set__"); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannySetupContext("__del__"); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":387 + * cdef int ndomains, nfields + * + * def __cinit__(self, char *fn): # <<<<<<<<<<<<<< + * cdef int idomain, ifield, ii + * cdef RAMSES_tree *local_tree + */ + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_fn; + int __pyx_v_idomain; + int __pyx_v_ifield; + int __pyx_v_ii; + RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; + RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; + std::string *__pyx_v_field_name; + int __pyx_r; + long __pyx_t_1; + int __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fn,0}; + __Pyx_RefNannySetupContext("__cinit__"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[1] = {0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fn); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_fn = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_fn) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_fn = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_fn) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.__cinit__"); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":391 + * cdef RAMSES_tree *local_tree + * cdef RAMSES_hydro_data *local_hydro_data + * self.snapshot_name = new string(fn) # <<<<<<<<<<<<<< + * self.rsnap = new snapshot(deref(self.snapshot_name), version3) + * # We now have to get our field names to fill our array + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name = new std::string(__pyx_v_fn); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":392 + * cdef RAMSES_hydro_data *local_hydro_data + * self.snapshot_name = new string(fn) + * self.rsnap = new snapshot(deref(self.snapshot_name), version3) # <<<<<<<<<<<<<< + * # We now have to get our field names to fill our array + * self.trees = \ + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap = new RAMSES::snapshot((*((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name), RAMSES::version3); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":394 + * self.rsnap = new snapshot(deref(self.snapshot_name), version3) + * # We now have to get our field names to fill our array + * self.trees = \ # <<<<<<<<<<<<<< + * malloc(sizeof(RAMSES_tree*) * self.rsnap.m_header.ncpu) + * self.hydro_datas = \ + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees = ((RAMSES::AMR::RAMSES_tree **)malloc(((sizeof(RAMSES::AMR::RAMSES_tree *)) * ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":396 + * self.trees = \ + * malloc(sizeof(RAMSES_tree*) * self.rsnap.m_header.ncpu) + * self.hydro_datas = \ # <<<<<<<<<<<<<< + * malloc(sizeof(RAMSES_hydro_data**) * self.rsnap.m_header.ncpu) + * self.ndomains = self.rsnap.m_header.ncpu + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas = ((RAMSES::HYDRO::RAMSES_hydro_data ***)malloc(((sizeof(RAMSES::HYDRO::RAMSES_hydro_data **)) * ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":398 + * self.hydro_datas = \ + * malloc(sizeof(RAMSES_hydro_data**) * self.rsnap.m_header.ncpu) + * self.ndomains = self.rsnap.m_header.ncpu # <<<<<<<<<<<<<< + * #for ii in range(self.ndomains): self.trees[ii] = NULL + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->ndomains = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":400 + * self.ndomains = self.rsnap.m_header.ncpu + * #for ii in range(self.ndomains): self.trees[ii] = NULL + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): # <<<<<<<<<<<<<< + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) + */ + __pyx_t_1 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu + 1); + for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_idomain = __pyx_t_2; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":402 + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) # <<<<<<<<<<<<<< + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + */ + __pyx_v_local_tree = new RAMSES::AMR::RAMSES_tree((*((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap), __pyx_v_idomain, ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax, 0); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":403 + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) + * local_tree.read() # <<<<<<<<<<<<<< + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * self.hydro_datas[idomain - 1] = \ + */ + __pyx_v_local_tree->read(); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":404 + * self.rsnap.m_header.levelmax, 0) + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) # <<<<<<<<<<<<<< + * self.hydro_datas[idomain - 1] = \ + * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) + */ + __pyx_v_local_hydro_data = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":405 + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * self.hydro_datas[idomain - 1] = \ # <<<<<<<<<<<<<< + * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) + * for ii in range(local_hydro_data.m_nvars): + */ + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_idomain - 1)]) = ((RAMSES::HYDRO::RAMSES_hydro_data **)malloc(((sizeof(RAMSES::HYDRO::RAMSES_hydro_data *)) * __pyx_v_local_hydro_data->m_nvars))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":407 + * self.hydro_datas[idomain - 1] = \ + * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) + * for ii in range(local_hydro_data.m_nvars): # <<<<<<<<<<<<<< + * self.hydro_datas[idomain - 1][ii] = \ + * new RAMSES_hydro_data(deref(local_tree)) + */ + __pyx_t_3 = __pyx_v_local_hydro_data->m_nvars; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_ii = __pyx_t_4; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":408 + * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) + * for ii in range(local_hydro_data.m_nvars): + * self.hydro_datas[idomain - 1][ii] = \ # <<<<<<<<<<<<<< + * new RAMSES_hydro_data(deref(local_tree)) + * self.trees[idomain - 1] = local_tree + */ + ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_idomain - 1)])[__pyx_v_ii]) = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":410 + * self.hydro_datas[idomain - 1][ii] = \ + * new RAMSES_hydro_data(deref(local_tree)) + * self.trees[idomain - 1] = local_tree # <<<<<<<<<<<<<< + * # We do not delete anything + * if idomain < self.rsnap.m_header.ncpu: del local_hydro_data + */ + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[(__pyx_v_idomain - 1)]) = __pyx_v_local_tree; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":412 + * self.trees[idomain - 1] = local_tree + * # We do not delete anything + * if idomain < self.rsnap.m_header.ncpu: del local_hydro_data # <<<<<<<<<<<<<< + * # Only once, we read all the field names + * self.nfields = local_hydro_data.m_nvars + */ + __pyx_t_5 = (__pyx_v_idomain < ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu); + if (__pyx_t_5) { + delete __pyx_v_local_hydro_data; + goto __pyx_L10; + } + __pyx_L10:; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":414 + * if idomain < self.rsnap.m_header.ncpu: del local_hydro_data + * # Only once, we read all the field names + * self.nfields = local_hydro_data.m_nvars # <<<<<<<<<<<<<< + * cdef string *field_name + * self.field_names = [] + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->nfields = __pyx_v_local_hydro_data->m_nvars; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":416 + * self.nfields = local_hydro_data.m_nvars + * cdef string *field_name + * self.field_names = [] # <<<<<<<<<<<<<< + * self.field_ind = {} + * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) + */ + __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":417 + * cdef string *field_name + * self.field_names = [] + * self.field_ind = {} # <<<<<<<<<<<<<< + * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) + * for idomain in range(self.ndomains): + */ + __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":418 + * self.field_names = [] + * self.field_ind = {} + * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) # <<<<<<<<<<<<<< + * for idomain in range(self.ndomains): + * self.loaded[idomain] = malloc( + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded = ((int **)malloc(((sizeof(int)) * __pyx_v_local_hydro_data->m_nvars))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":419 + * self.field_ind = {} + * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) + * for idomain in range(self.ndomains): # <<<<<<<<<<<<<< + * self.loaded[idomain] = malloc( + * sizeof(int) * local_hydro_data.m_nvars) + */ + __pyx_t_2 = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->ndomains; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_2; __pyx_t_4+=1) { + __pyx_v_idomain = __pyx_t_4; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":420 + * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) + * for idomain in range(self.ndomains): + * self.loaded[idomain] = malloc( # <<<<<<<<<<<<<< + * sizeof(int) * local_hydro_data.m_nvars) + * for ifield in range(local_hydro_data.m_nvars): + */ + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_idomain]) = ((int *)malloc(((sizeof(int)) * __pyx_v_local_hydro_data->m_nvars))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":422 + * self.loaded[idomain] = malloc( + * sizeof(int) * local_hydro_data.m_nvars) + * for ifield in range(local_hydro_data.m_nvars): # <<<<<<<<<<<<<< + * self.loaded[idomain][ifield] = 0 + * for ifield in range(local_hydro_data.m_nvars): + */ + __pyx_t_3 = __pyx_v_local_hydro_data->m_nvars; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_3; __pyx_t_7+=1) { + __pyx_v_ifield = __pyx_t_7; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":423 + * sizeof(int) * local_hydro_data.m_nvars) + * for ifield in range(local_hydro_data.m_nvars): + * self.loaded[idomain][ifield] = 0 # <<<<<<<<<<<<<< + * for ifield in range(local_hydro_data.m_nvars): + * field_name = &(local_hydro_data.m_varnames[ifield]) + */ + ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_idomain])[__pyx_v_ifield]) = 0; + } + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":424 + * for ifield in range(local_hydro_data.m_nvars): + * self.loaded[idomain][ifield] = 0 + * for ifield in range(local_hydro_data.m_nvars): # <<<<<<<<<<<<<< + * field_name = &(local_hydro_data.m_varnames[ifield]) + * # Does this leak? + */ + __pyx_t_3 = __pyx_v_local_hydro_data->m_nvars; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_3; __pyx_t_2+=1) { + __pyx_v_ifield = __pyx_t_2; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":425 + * self.loaded[idomain][ifield] = 0 + * for ifield in range(local_hydro_data.m_nvars): + * field_name = &(local_hydro_data.m_varnames[ifield]) # <<<<<<<<<<<<<< + * # Does this leak? + * self.field_names.append(field_name.c_str()) + */ + __pyx_v_field_name = (&(__pyx_v_local_hydro_data->m_varnames[__pyx_v_ifield])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":427 + * field_name = &(local_hydro_data.m_varnames[ifield]) + * # Does this leak? + * self.field_names.append(field_name.c_str()) # <<<<<<<<<<<<<< + * self.field_ind[self.field_names[-1]] = ifield + * # This all needs to be cleaned up in the deallocator + */ + __pyx_t_6 = PyBytes_FromString(__pyx_v_field_name->c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_8 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names, ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 427; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":428 + * # Does this leak? + * self.field_names.append(field_name.c_str()) + * self.field_ind[self.field_names[-1]] = ifield # <<<<<<<<<<<<<< + * # This all needs to be cleaned up in the deallocator + * del local_hydro_data + */ + __pyx_t_8 = PyInt_FromLong(__pyx_v_ifield); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + if (PyObject_SetItem(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, __pyx_t_6, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":430 + * self.field_ind[self.field_names[-1]] = ifield + * # This all needs to be cleaned up in the deallocator + * del local_hydro_data # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + delete __pyx_v_local_hydro_data; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.__cinit__"); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":432 + * del local_hydro_data + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * cdef int idomain, ifield + * for idomain in range(self.ndomains): + */ + +static void __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy___dealloc__(PyObject *__pyx_v_self) { + int __pyx_v_idomain; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("__dealloc__"); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":434 + * def __dealloc__(self): + * cdef int idomain, ifield + * for idomain in range(self.ndomains): # <<<<<<<<<<<<<< + * #for ifield in range(self.nfields): + * # if self.hydro_datas[idomain][ifield] != NULL: + */ + __pyx_t_1 = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->ndomains; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_idomain = __pyx_t_2; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":438 + * # if self.hydro_datas[idomain][ifield] != NULL: + * # del self.hydro_datas[idomain][ifield] + * if self.trees[idomain] != NULL: # <<<<<<<<<<<<<< + * del self.trees[idomain] + * free(self.hydro_datas[idomain]) + */ + __pyx_t_3 = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[__pyx_v_idomain]) != NULL); + if (__pyx_t_3) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":439 + * # del self.hydro_datas[idomain][ifield] + * if self.trees[idomain] != NULL: + * del self.trees[idomain] # <<<<<<<<<<<<<< + * free(self.hydro_datas[idomain]) + * free(self.loaded[idomain]) + */ + delete (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[__pyx_v_idomain]); + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":440 + * if self.trees[idomain] != NULL: + * del self.trees[idomain] + * free(self.hydro_datas[idomain]) # <<<<<<<<<<<<<< + * free(self.loaded[idomain]) + * free(self.trees) + */ + free((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_idomain])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":441 + * del self.trees[idomain] + * free(self.hydro_datas[idomain]) + * free(self.loaded[idomain]) # <<<<<<<<<<<<<< + * free(self.trees) + * free(self.hydro_datas) + */ + free((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_idomain])); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":442 + * free(self.hydro_datas[idomain]) + * free(self.loaded[idomain]) + * free(self.trees) # <<<<<<<<<<<<<< + * free(self.hydro_datas) + * free(self.loaded) + */ + free(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":443 + * free(self.loaded[idomain]) + * free(self.trees) + * free(self.hydro_datas) # <<<<<<<<<<<<<< + * free(self.loaded) + * if self.snapshot_name != NULL: del self.snapshot_name + */ + free(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":444 + * free(self.trees) + * free(self.hydro_datas) + * free(self.loaded) # <<<<<<<<<<<<<< + * if self.snapshot_name != NULL: del self.snapshot_name + * if self.rsnap != NULL: del self.rsnap + */ + free(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":445 + * free(self.hydro_datas) + * free(self.loaded) + * if self.snapshot_name != NULL: del self.snapshot_name # <<<<<<<<<<<<<< + * if self.rsnap != NULL: del self.rsnap + * + */ + __pyx_t_3 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name != NULL); + if (__pyx_t_3) { + delete ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":446 + * free(self.loaded) + * if self.snapshot_name != NULL: del self.snapshot_name + * if self.rsnap != NULL: del self.rsnap # <<<<<<<<<<<<<< + * + * def count_zones(self): + */ + __pyx_t_3 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap != NULL); + if (__pyx_t_3) { + delete ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap; + goto __pyx_L9; + } + __pyx_L9:; + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":448 + * if self.rsnap != NULL: del self.rsnap + * + * def count_zones(self): # <<<<<<<<<<<<<< + * # We need to do simulation domains here + * + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_count_zones(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_count_zones(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + unsigned int __pyx_v_idomain; + unsigned int __pyx_v_ilevel; + RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; + RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; + RAMSES::AMR::RAMSES_level *__pyx_v_local_level; + RAMSES::AMR::RAMSES_tree::iterator __pyx_v_grid_it; + RAMSES::AMR::RAMSES_tree::iterator __pyx_v_grid_end; + PyObject *__pyx_v_cell_count; + int __pyx_v_local_count; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + long __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + long __pyx_t_5; + unsigned int __pyx_t_6; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("count_zones"); + __pyx_v_cell_count = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":459 + * # All the loop-local pointers must be declared up here + * + * cell_count = [] # <<<<<<<<<<<<<< + * cdef int local_count = 0 + * for ilevel in range(self.rsnap.m_header.levelmax + 1): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 459; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_v_cell_count)); + __pyx_v_cell_count = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":460 + * + * cell_count = [] + * cdef int local_count = 0 # <<<<<<<<<<<<<< + * for ilevel in range(self.rsnap.m_header.levelmax + 1): + * cell_count.append(0) + */ + __pyx_v_local_count = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":461 + * cell_count = [] + * cdef int local_count = 0 + * for ilevel in range(self.rsnap.m_header.levelmax + 1): # <<<<<<<<<<<<<< + * cell_count.append(0) + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + */ + __pyx_t_2 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax + 1); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_ilevel = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":462 + * cdef int local_count = 0 + * for ilevel in range(self.rsnap.m_header.levelmax + 1): + * cell_count.append(0) # <<<<<<<<<<<<<< + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + */ + if (unlikely(__pyx_v_cell_count == Py_None)) { + PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_cell_count), __pyx_int_0); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":463 + * for ilevel in range(self.rsnap.m_header.levelmax + 1): + * cell_count.append(0) + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): # <<<<<<<<<<<<<< + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) + */ + __pyx_t_2 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu + 1); + for (__pyx_t_3 = 1; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_idomain = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":465 + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) # <<<<<<<<<<<<<< + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + */ + __pyx_v_local_tree = new RAMSES::AMR::RAMSES_tree((*((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap), __pyx_v_idomain, ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax, 0); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":466 + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) + * local_tree.read() # <<<<<<<<<<<<<< + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * for ilevel in range(local_tree.m_maxlevel + 1): + */ + __pyx_v_local_tree->read(); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":467 + * self.rsnap.m_header.levelmax, 0) + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) # <<<<<<<<<<<<<< + * for ilevel in range(local_tree.m_maxlevel + 1): + * local_count = 0 + */ + __pyx_v_local_hydro_data = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":468 + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * for ilevel in range(local_tree.m_maxlevel + 1): # <<<<<<<<<<<<<< + * local_count = 0 + * local_level = &local_tree.m_AMR_levels[ilevel] + */ + __pyx_t_5 = (__pyx_v_local_tree->m_maxlevel + 1); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_ilevel = __pyx_t_6; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":469 + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * for ilevel in range(local_tree.m_maxlevel + 1): + * local_count = 0 # <<<<<<<<<<<<<< + * local_level = &local_tree.m_AMR_levels[ilevel] + * grid_it = local_tree.begin(ilevel) + */ + __pyx_v_local_count = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":470 + * for ilevel in range(local_tree.m_maxlevel + 1): + * local_count = 0 + * local_level = &local_tree.m_AMR_levels[ilevel] # <<<<<<<<<<<<<< + * grid_it = local_tree.begin(ilevel) + * grid_end = local_tree.end(ilevel) + */ + __pyx_v_local_level = (&(__pyx_v_local_tree->m_AMR_levels[__pyx_v_ilevel])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":471 + * local_count = 0 + * local_level = &local_tree.m_AMR_levels[ilevel] + * grid_it = local_tree.begin(ilevel) # <<<<<<<<<<<<<< + * grid_end = local_tree.end(ilevel) + * while grid_it != grid_end: + */ + __pyx_v_grid_it = __pyx_v_local_tree->begin(__pyx_v_ilevel); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":472 + * local_level = &local_tree.m_AMR_levels[ilevel] + * grid_it = local_tree.begin(ilevel) + * grid_end = local_tree.end(ilevel) # <<<<<<<<<<<<<< + * while grid_it != grid_end: + * local_count += (grid_it.get_domain() == idomain) + */ + __pyx_v_grid_end = __pyx_v_local_tree->end(__pyx_v_ilevel); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":473 + * grid_it = local_tree.begin(ilevel) + * grid_end = local_tree.end(ilevel) + * while grid_it != grid_end: # <<<<<<<<<<<<<< + * local_count += (grid_it.get_domain() == idomain) + * grid_it.next() + */ + while (1) { + __pyx_t_7 = (__pyx_v_grid_it != __pyx_v_grid_end); + if (!__pyx_t_7) break; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":474 + * grid_end = local_tree.end(ilevel) + * while grid_it != grid_end: + * local_count += (grid_it.get_domain() == idomain) # <<<<<<<<<<<<<< + * grid_it.next() + * cell_count[ilevel] += local_count + */ + __pyx_v_local_count += (__pyx_v_grid_it.get_domain() == __pyx_v_idomain); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":475 + * while grid_it != grid_end: + * local_count += (grid_it.get_domain() == idomain) + * grid_it.next() # <<<<<<<<<<<<<< + * cell_count[ilevel] += local_count + * del local_tree, local_hydro_data + */ + __pyx_v_grid_it.next(); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":476 + * local_count += (grid_it.get_domain() == idomain) + * grid_it.next() + * cell_count[ilevel] += local_count # <<<<<<<<<<<<<< + * del local_tree, local_hydro_data + * + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_local_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_cell_count), __pyx_v_ilevel, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_cell_count), __pyx_v_ilevel, __pyx_t_9, sizeof(unsigned int)+1, PyLong_FromUnsignedLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":477 + * grid_it.next() + * cell_count[ilevel] += local_count + * del local_tree, local_hydro_data # <<<<<<<<<<<<<< + * + * return cell_count + */ + delete __pyx_v_local_tree; + delete __pyx_v_local_hydro_data; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":479 + * del local_tree, local_hydro_data + * + * return cell_count # <<<<<<<<<<<<<< + * + * def ensure_loaded(self, char *varname, int domain_index): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_cell_count)); + __pyx_r = ((PyObject *)__pyx_v_cell_count); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.count_zones"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_cell_count); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":481 + * return cell_count + * + * def ensure_loaded(self, char *varname, int domain_index): # <<<<<<<<<<<<<< + * # this domain_index must be zero-indexed + * cdef int varindex = self.field_ind[varname] + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_ensure_loaded(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_ensure_loaded(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_varname; + int __pyx_v_domain_index; + int __pyx_v_varindex; + std::string *__pyx_v_field_name; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__varname,&__pyx_n_s__domain_index,0}; + __Pyx_RefNannySetupContext("ensure_loaded"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__varname); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__domain_index); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("ensure_loaded", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "ensure_loaded") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_varname = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_domain_index = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_varname = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_domain_index = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("ensure_loaded", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.ensure_loaded"); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":483 + * def ensure_loaded(self, char *varname, int domain_index): + * # this domain_index must be zero-indexed + * cdef int varindex = self.field_ind[varname] # <<<<<<<<<<<<<< + * cdef string *field_name = new string(varname) + * if self.loaded[domain_index][varindex] == 1: + */ + __pyx_t_1 = PyBytes_FromString(__pyx_v_varname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_varindex = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":484 + * # this domain_index must be zero-indexed + * cdef int varindex = self.field_ind[varname] + * cdef string *field_name = new string(varname) # <<<<<<<<<<<<<< + * if self.loaded[domain_index][varindex] == 1: + * return + */ + __pyx_v_field_name = new std::string(__pyx_v_varname); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":485 + * cdef int varindex = self.field_ind[varname] + * cdef string *field_name = new string(varname) + * if self.loaded[domain_index][varindex] == 1: # <<<<<<<<<<<<<< + * return + * print "READING FROM DISK", varname, domain_index, varindex + */ + __pyx_t_4 = (((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_domain_index])[__pyx_v_varindex]) == 1); + if (__pyx_t_4) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":486 + * cdef string *field_name = new string(varname) + * if self.loaded[domain_index][varindex] == 1: + * return # <<<<<<<<<<<<<< + * print "READING FROM DISK", varname, domain_index, varindex + * self.hydro_datas[domain_index][varindex].read(deref(field_name)) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":487 + * if self.loaded[domain_index][varindex] == 1: + * return + * print "READING FROM DISK", varname, domain_index, varindex # <<<<<<<<<<<<<< + * self.hydro_datas[domain_index][varindex].read(deref(field_name)) + * self.loaded[domain_index][varindex] = 1 + */ + __pyx_t_2 = PyBytes_FromString(__pyx_v_varname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_domain_index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyInt_FromLong(__pyx_v_varindex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_5 = 0; + if (__Pyx_Print(0, __pyx_t_6, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":488 + * return + * print "READING FROM DISK", varname, domain_index, varindex + * self.hydro_datas[domain_index][varindex].read(deref(field_name)) # <<<<<<<<<<<<<< + * self.loaded[domain_index][varindex] = 1 + * del field_name + */ + ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_domain_index])[__pyx_v_varindex])->read((*__pyx_v_field_name)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":489 + * print "READING FROM DISK", varname, domain_index, varindex + * self.hydro_datas[domain_index][varindex].read(deref(field_name)) + * self.loaded[domain_index][varindex] = 1 # <<<<<<<<<<<<<< + * del field_name + * + */ + ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_domain_index])[__pyx_v_varindex]) = 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":490 + * self.hydro_datas[domain_index][varindex].read(deref(field_name)) + * self.loaded[domain_index][varindex] = 1 + * del field_name # <<<<<<<<<<<<<< + * + * def clear_tree(self, char *varname, int domain_index): + */ + delete __pyx_v_field_name; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.ensure_loaded"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":492 + * del field_name + * + * def clear_tree(self, char *varname, int domain_index): # <<<<<<<<<<<<<< + * # this domain_index must be zero-indexed + * # We delete and re-create + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_clear_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_clear_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_varname; + int __pyx_v_domain_index; + int __pyx_v_varindex; + std::string *__pyx_v_field_name; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__varname,&__pyx_n_s__domain_index,0}; + __Pyx_RefNannySetupContext("clear_tree"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__varname); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__domain_index); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("clear_tree", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "clear_tree") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_varname = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_domain_index = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_varname = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_domain_index = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("clear_tree", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.clear_tree"); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":495 + * # this domain_index must be zero-indexed + * # We delete and re-create + * cdef int varindex = self.field_ind[varname] # <<<<<<<<<<<<<< + * cdef string *field_name = new string(varname) + * if self.loaded[domain_index][varindex] == 0: return + */ + __pyx_t_1 = PyBytes_FromString(__pyx_v_varname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_varindex = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":496 + * # We delete and re-create + * cdef int varindex = self.field_ind[varname] + * cdef string *field_name = new string(varname) # <<<<<<<<<<<<<< + * if self.loaded[domain_index][varindex] == 0: return + * del self.hydro_datas[domain_index][varindex] + */ + __pyx_v_field_name = new std::string(__pyx_v_varname); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":497 + * cdef int varindex = self.field_ind[varname] + * cdef string *field_name = new string(varname) + * if self.loaded[domain_index][varindex] == 0: return # <<<<<<<<<<<<<< + * del self.hydro_datas[domain_index][varindex] + * self.hydro_datas[domain_index - 1][varindex] = \ + */ + __pyx_t_4 = (((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_domain_index])[__pyx_v_varindex]) == 0); + if (__pyx_t_4) { + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":498 + * cdef string *field_name = new string(varname) + * if self.loaded[domain_index][varindex] == 0: return + * del self.hydro_datas[domain_index][varindex] # <<<<<<<<<<<<<< + * self.hydro_datas[domain_index - 1][varindex] = \ + * new RAMSES_hydro_data(deref(self.trees[domain_index])) + */ + delete ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_domain_index])[__pyx_v_varindex]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":499 + * if self.loaded[domain_index][varindex] == 0: return + * del self.hydro_datas[domain_index][varindex] + * self.hydro_datas[domain_index - 1][varindex] = \ # <<<<<<<<<<<<<< + * new RAMSES_hydro_data(deref(self.trees[domain_index])) + * self.loaded[domain_index][varindex] = 0 + */ + ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_domain_index - 1)])[__pyx_v_varindex]) = new RAMSES::HYDRO::RAMSES_hydro_data((*(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[__pyx_v_domain_index]))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":501 + * self.hydro_datas[domain_index - 1][varindex] = \ + * new RAMSES_hydro_data(deref(self.trees[domain_index])) + * self.loaded[domain_index][varindex] = 0 # <<<<<<<<<<<<<< + * del field_name + * + */ + ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_domain_index])[__pyx_v_varindex]) = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":502 + * new RAMSES_hydro_data(deref(self.trees[domain_index])) + * self.loaded[domain_index][varindex] = 0 + * del field_name # <<<<<<<<<<<<<< + * + * def get_file_info(self): + */ + delete __pyx_v_field_name; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.clear_tree"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":504 + * del field_name + * + * def get_file_info(self): # <<<<<<<<<<<<<< + * header_info = {} + * header_info["ncpu"] = self.rsnap.m_header.ncpu + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_get_file_info(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_get_file_info(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_v_header_info; + PyArrayObject *__pyx_v_top_grid_dims = 0; + int __pyx_v_i; + Py_buffer __pyx_bstruct_top_grid_dims; + Py_ssize_t __pyx_bstride_0_top_grid_dims = 0; + Py_ssize_t __pyx_bshape_0_top_grid_dims = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyArrayObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("get_file_info"); + __pyx_v_header_info = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_bstruct_top_grid_dims.buf = NULL; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":505 + * + * def get_file_info(self): + * header_info = {} # <<<<<<<<<<<<<< + * header_info["ncpu"] = self.rsnap.m_header.ncpu + * header_info["ndim"] = self.rsnap.m_header.ndim + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_v_header_info)); + __pyx_v_header_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":506 + * def get_file_info(self): + * header_info = {} + * header_info["ncpu"] = self.rsnap.m_header.ncpu # <<<<<<<<<<<<<< + * header_info["ndim"] = self.rsnap.m_header.ndim + * header_info["levelmin"] = self.rsnap.m_header.levelmin + */ + __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__ncpu), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":507 + * header_info = {} + * header_info["ncpu"] = self.rsnap.m_header.ncpu + * header_info["ndim"] = self.rsnap.m_header.ndim # <<<<<<<<<<<<<< + * header_info["levelmin"] = self.rsnap.m_header.levelmin + * header_info["levelmax"] = self.rsnap.m_header.levelmax + */ + __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ndim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__ndim), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 507; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":508 + * header_info["ncpu"] = self.rsnap.m_header.ncpu + * header_info["ndim"] = self.rsnap.m_header.ndim + * header_info["levelmin"] = self.rsnap.m_header.levelmin # <<<<<<<<<<<<<< + * header_info["levelmax"] = self.rsnap.m_header.levelmax + * header_info["ngridmax"] = self.rsnap.m_header.ngridmax + */ + __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__levelmin), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 508; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":509 + * header_info["ndim"] = self.rsnap.m_header.ndim + * header_info["levelmin"] = self.rsnap.m_header.levelmin + * header_info["levelmax"] = self.rsnap.m_header.levelmax # <<<<<<<<<<<<<< + * header_info["ngridmax"] = self.rsnap.m_header.ngridmax + * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse + */ + __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__levelmax), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":510 + * header_info["levelmin"] = self.rsnap.m_header.levelmin + * header_info["levelmax"] = self.rsnap.m_header.levelmax + * header_info["ngridmax"] = self.rsnap.m_header.ngridmax # <<<<<<<<<<<<<< + * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse + * header_info["boxlen"] = self.rsnap.m_header.boxlen + */ + __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ngridmax); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__ngridmax), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":511 + * header_info["levelmax"] = self.rsnap.m_header.levelmax + * header_info["ngridmax"] = self.rsnap.m_header.ngridmax + * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse # <<<<<<<<<<<<<< + * header_info["boxlen"] = self.rsnap.m_header.boxlen + * header_info["time"] = self.rsnap.m_header.time + */ + __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.nstep_coarse); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__nstep_coarse), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":512 + * header_info["ngridmax"] = self.rsnap.m_header.ngridmax + * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse + * header_info["boxlen"] = self.rsnap.m_header.boxlen # <<<<<<<<<<<<<< + * header_info["time"] = self.rsnap.m_header.time + * header_info["aexp"] = self.rsnap.m_header.aexp + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.boxlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__boxlen), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":513 + * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse + * header_info["boxlen"] = self.rsnap.m_header.boxlen + * header_info["time"] = self.rsnap.m_header.time # <<<<<<<<<<<<<< + * header_info["aexp"] = self.rsnap.m_header.aexp + * header_info["H0"] = self.rsnap.m_header.H0 + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.time); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__time), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":514 + * header_info["boxlen"] = self.rsnap.m_header.boxlen + * header_info["time"] = self.rsnap.m_header.time + * header_info["aexp"] = self.rsnap.m_header.aexp # <<<<<<<<<<<<<< + * header_info["H0"] = self.rsnap.m_header.H0 + * header_info["omega_m"] = self.rsnap.m_header.omega_m + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.aexp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__aexp), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":515 + * header_info["time"] = self.rsnap.m_header.time + * header_info["aexp"] = self.rsnap.m_header.aexp + * header_info["H0"] = self.rsnap.m_header.H0 # <<<<<<<<<<<<<< + * header_info["omega_m"] = self.rsnap.m_header.omega_m + * header_info["omega_l"] = self.rsnap.m_header.omega_l + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.H0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__H0), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":516 + * header_info["aexp"] = self.rsnap.m_header.aexp + * header_info["H0"] = self.rsnap.m_header.H0 + * header_info["omega_m"] = self.rsnap.m_header.omega_m # <<<<<<<<<<<<<< + * header_info["omega_l"] = self.rsnap.m_header.omega_l + * header_info["omega_k"] = self.rsnap.m_header.omega_k + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_m); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_m), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":517 + * header_info["H0"] = self.rsnap.m_header.H0 + * header_info["omega_m"] = self.rsnap.m_header.omega_m + * header_info["omega_l"] = self.rsnap.m_header.omega_l # <<<<<<<<<<<<<< + * header_info["omega_k"] = self.rsnap.m_header.omega_k + * header_info["omega_b"] = self.rsnap.m_header.omega_b + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_l), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":518 + * header_info["omega_m"] = self.rsnap.m_header.omega_m + * header_info["omega_l"] = self.rsnap.m_header.omega_l + * header_info["omega_k"] = self.rsnap.m_header.omega_k # <<<<<<<<<<<<<< + * header_info["omega_b"] = self.rsnap.m_header.omega_b + * header_info["unit_l"] = self.rsnap.m_header.unit_l + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_k), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":519 + * header_info["omega_l"] = self.rsnap.m_header.omega_l + * header_info["omega_k"] = self.rsnap.m_header.omega_k + * header_info["omega_b"] = self.rsnap.m_header.omega_b # <<<<<<<<<<<<<< + * header_info["unit_l"] = self.rsnap.m_header.unit_l + * header_info["unit_d"] = self.rsnap.m_header.unit_d + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_b), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 519; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":520 + * header_info["omega_k"] = self.rsnap.m_header.omega_k + * header_info["omega_b"] = self.rsnap.m_header.omega_b + * header_info["unit_l"] = self.rsnap.m_header.unit_l # <<<<<<<<<<<<<< + * header_info["unit_d"] = self.rsnap.m_header.unit_d + * header_info["unit_t"] = self.rsnap.m_header.unit_t + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.unit_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__unit_l), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":521 + * header_info["omega_b"] = self.rsnap.m_header.omega_b + * header_info["unit_l"] = self.rsnap.m_header.unit_l + * header_info["unit_d"] = self.rsnap.m_header.unit_d # <<<<<<<<<<<<<< + * header_info["unit_t"] = self.rsnap.m_header.unit_t + * + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.unit_d); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__unit_d), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":522 + * header_info["unit_l"] = self.rsnap.m_header.unit_l + * header_info["unit_d"] = self.rsnap.m_header.unit_d + * header_info["unit_t"] = self.rsnap.m_header.unit_t # <<<<<<<<<<<<<< + * + * # Now we grab some from the trees + */ + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.unit_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__unit_t), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":525 + * + * # Now we grab some from the trees + * cdef np.ndarray[np.int32_t, ndim=1] top_grid_dims = np.zeros(3, "int32") # <<<<<<<<<<<<<< + * cdef int i + * for i in range(3): + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + __Pyx_INCREF(((PyObject *)__pyx_n_s__int32)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__int32)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__int32)); + __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_top_grid_dims, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + __pyx_v_top_grid_dims = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_top_grid_dims.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_bstride_0_top_grid_dims = __pyx_bstruct_top_grid_dims.strides[0]; + __pyx_bshape_0_top_grid_dims = __pyx_bstruct_top_grid_dims.shape[0]; + } + } + __pyx_t_4 = 0; + __pyx_v_top_grid_dims = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":527 + * cdef np.ndarray[np.int32_t, ndim=1] top_grid_dims = np.zeros(3, "int32") + * cdef int i + * for i in range(3): # <<<<<<<<<<<<<< + * # Note that nx is really boundary conditions. We always have 2. + * top_grid_dims[i] = self.trees[0].m_header.nx[i] + */ + for (__pyx_t_5 = 0; __pyx_t_5 < 3; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":529 + * for i in range(3): + * # Note that nx is really boundary conditions. We always have 2. + * top_grid_dims[i] = self.trees[0].m_header.nx[i] # <<<<<<<<<<<<<< + * top_grid_dims[i] = 2 + * header_info["nx"] = top_grid_dims + */ + __pyx_t_6 = __pyx_v_i; + __pyx_t_7 = -1; + if (__pyx_t_6 < 0) { + __pyx_t_6 += __pyx_bshape_0_top_grid_dims; + if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0; + } else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_7 = 0; + if (unlikely(__pyx_t_7 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_7); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_6, __pyx_bstride_0_top_grid_dims) = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[0])->m_header.nx[__pyx_v_i]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":530 + * # Note that nx is really boundary conditions. We always have 2. + * top_grid_dims[i] = self.trees[0].m_header.nx[i] + * top_grid_dims[i] = 2 # <<<<<<<<<<<<<< + * header_info["nx"] = top_grid_dims + * + */ + __pyx_t_7 = __pyx_v_i; + __pyx_t_8 = -1; + if (__pyx_t_7 < 0) { + __pyx_t_7 += __pyx_bshape_0_top_grid_dims; + if (unlikely(__pyx_t_7 < 0)) __pyx_t_8 = 0; + } else if (unlikely(__pyx_t_7 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_8 = 0; + if (unlikely(__pyx_t_8 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_8); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_7, __pyx_bstride_0_top_grid_dims) = 2; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":531 + * top_grid_dims[i] = self.trees[0].m_header.nx[i] + * top_grid_dims[i] = 2 + * header_info["nx"] = top_grid_dims # <<<<<<<<<<<<<< + * + * return header_info + */ + if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__nx), ((PyObject *)__pyx_v_top_grid_dims)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":533 + * header_info["nx"] = top_grid_dims + * + * return header_info # <<<<<<<<<<<<<< + * + * def fill_hierarchy_arrays(self, + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_header_info)); + __pyx_r = ((PyObject *)__pyx_v_header_info); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_top_grid_dims); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.get_file_info"); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_top_grid_dims); + __pyx_L2:; + __Pyx_DECREF(__pyx_v_header_info); + __Pyx_XDECREF((PyObject *)__pyx_v_top_grid_dims); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":535 + * return header_info + * + * def fill_hierarchy_arrays(self, # <<<<<<<<<<<<<< + * np.ndarray[np.int32_t, ndim=1] top_grid_dims, + * np.ndarray[np.float64_t, ndim=2] left_edges, + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_fill_hierarchy_arrays(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_fill_hierarchy_arrays(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyArrayObject *__pyx_v_top_grid_dims = 0; + PyArrayObject *__pyx_v_left_edges = 0; + PyArrayObject *__pyx_v_right_edges = 0; + PyArrayObject *__pyx_v_grid_levels = 0; + PyArrayObject *__pyx_v_grid_file_locations = 0; + PyArrayObject *__pyx_v_child_mask = 0; + unsigned int __pyx_v_idomain; + unsigned int __pyx_v_ilevel; + RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; + RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; + RAMSES::AMR::RAMSES_tree::iterator __pyx_v_grid_it; + RAMSES::AMR::RAMSES_tree::iterator __pyx_v_grid_end; + RAMSES::AMR::RAMSES_tree::iterator __pyx_v_father_it; + RAMSES::AMR::vec __pyx_v_gvec; + int __pyx_v_grid_ind; + int __pyx_v_grid_aind; + unsigned int __pyx_v_parent_ind; + int __pyx_v_ci; + double __pyx_v_grid_half_width; + __pyx_t_5numpy_int32_t __pyx_v_rr; + PyObject *__pyx_v_cell_count; + PyObject *__pyx_v_level_cell_counts; + Py_buffer __pyx_bstruct_right_edges; + Py_ssize_t __pyx_bstride_0_right_edges = 0; + Py_ssize_t __pyx_bstride_1_right_edges = 0; + Py_ssize_t __pyx_bshape_0_right_edges = 0; + Py_ssize_t __pyx_bshape_1_right_edges = 0; + Py_buffer __pyx_bstruct_grid_levels; + Py_ssize_t __pyx_bstride_0_grid_levels = 0; + Py_ssize_t __pyx_bstride_1_grid_levels = 0; + Py_ssize_t __pyx_bshape_0_grid_levels = 0; + Py_ssize_t __pyx_bshape_1_grid_levels = 0; + Py_buffer __pyx_bstruct_grid_file_locations; + Py_ssize_t __pyx_bstride_0_grid_file_locations = 0; + Py_ssize_t __pyx_bstride_1_grid_file_locations = 0; + Py_ssize_t __pyx_bshape_0_grid_file_locations = 0; + Py_ssize_t __pyx_bshape_1_grid_file_locations = 0; + Py_buffer __pyx_bstruct_child_mask; + Py_ssize_t __pyx_bstride_0_child_mask = 0; + Py_ssize_t __pyx_bstride_1_child_mask = 0; + Py_ssize_t __pyx_bshape_0_child_mask = 0; + Py_ssize_t __pyx_bshape_1_child_mask = 0; + Py_buffer __pyx_bstruct_top_grid_dims; + Py_ssize_t __pyx_bstride_0_top_grid_dims = 0; + Py_ssize_t __pyx_bshape_0_top_grid_dims = 0; + Py_buffer __pyx_bstruct_left_edges; + Py_ssize_t __pyx_bstride_0_left_edges = 0; + Py_ssize_t __pyx_bstride_1_left_edges = 0; + Py_ssize_t __pyx_bshape_0_left_edges = 0; + Py_ssize_t __pyx_bshape_1_left_edges = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + long __pyx_t_2; + unsigned int __pyx_t_3; + long __pyx_t_4; + unsigned int __pyx_t_5; + long __pyx_t_6; + int __pyx_t_7; + long __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + long __pyx_t_11; + int __pyx_t_12; + long __pyx_t_13; + int __pyx_t_14; + long __pyx_t_15; + int __pyx_t_16; + long __pyx_t_17; + int __pyx_t_18; + long __pyx_t_19; + int __pyx_t_20; + long __pyx_t_21; + int __pyx_t_22; + long __pyx_t_23; + int __pyx_t_24; + PyObject *__pyx_t_25 = NULL; + PyObject *__pyx_t_26 = NULL; + __pyx_t_5numpy_int64_t __pyx_t_27; + long __pyx_t_28; + int __pyx_t_29; + long __pyx_t_30; + int __pyx_t_31; + long __pyx_t_32; + int __pyx_t_33; + int __pyx_t_34; + int __pyx_t_35; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__top_grid_dims,&__pyx_n_s__left_edges,&__pyx_n_s__right_edges,&__pyx_n_s__grid_levels,&__pyx_n_s__grid_file_locations,&__pyx_n_s__child_mask,0}; + __Pyx_RefNannySetupContext("fill_hierarchy_arrays"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[6] = {0,0,0,0,0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__top_grid_dims); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edges); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edges); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_levels); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_file_locations); + if (likely(values[4])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 5: + values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_mask); + if (likely(values[5])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "fill_hierarchy_arrays") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_top_grid_dims = ((PyArrayObject *)values[0]); + __pyx_v_left_edges = ((PyArrayObject *)values[1]); + __pyx_v_right_edges = ((PyArrayObject *)values[2]); + __pyx_v_grid_levels = ((PyArrayObject *)values[3]); + __pyx_v_grid_file_locations = ((PyArrayObject *)values[4]); + __pyx_v_child_mask = ((PyArrayObject *)values[5]); + } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_top_grid_dims = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); + __pyx_v_left_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); + __pyx_v_right_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); + __pyx_v_grid_levels = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); + __pyx_v_grid_file_locations = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); + __pyx_v_child_mask = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.fill_hierarchy_arrays"); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_v_cell_count = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_level_cell_counts = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_bstruct_top_grid_dims.buf = NULL; + __pyx_bstruct_left_edges.buf = NULL; + __pyx_bstruct_right_edges.buf = NULL; + __pyx_bstruct_grid_levels.buf = NULL; + __pyx_bstruct_grid_file_locations.buf = NULL; + __pyx_bstruct_child_mask.buf = NULL; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_top_grid_dims), __pyx_ptype_5numpy_ndarray, 1, "top_grid_dims", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edges), __pyx_ptype_5numpy_ndarray, 1, "left_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 537; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edges), __pyx_ptype_5numpy_ndarray, 1, "right_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_levels), __pyx_ptype_5numpy_ndarray, 1, "grid_levels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_file_locations), __pyx_ptype_5numpy_ndarray, 1, "grid_file_locations", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 540; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_mask), __pyx_ptype_5numpy_ndarray, 1, "child_mask", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_top_grid_dims, (PyObject*)__pyx_v_top_grid_dims, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_top_grid_dims = __pyx_bstruct_top_grid_dims.strides[0]; + __pyx_bshape_0_top_grid_dims = __pyx_bstruct_top_grid_dims.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edges, (PyObject*)__pyx_v_left_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_left_edges = __pyx_bstruct_left_edges.strides[0]; __pyx_bstride_1_left_edges = __pyx_bstruct_left_edges.strides[1]; + __pyx_bshape_0_left_edges = __pyx_bstruct_left_edges.shape[0]; __pyx_bshape_1_left_edges = __pyx_bstruct_left_edges.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edges, (PyObject*)__pyx_v_right_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_right_edges = __pyx_bstruct_right_edges.strides[0]; __pyx_bstride_1_right_edges = __pyx_bstruct_right_edges.strides[1]; + __pyx_bshape_0_right_edges = __pyx_bstruct_right_edges.shape[0]; __pyx_bshape_1_right_edges = __pyx_bstruct_right_edges.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_levels, (PyObject*)__pyx_v_grid_levels, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_grid_levels = __pyx_bstruct_grid_levels.strides[0]; __pyx_bstride_1_grid_levels = __pyx_bstruct_grid_levels.strides[1]; + __pyx_bshape_0_grid_levels = __pyx_bstruct_grid_levels.shape[0]; __pyx_bshape_1_grid_levels = __pyx_bstruct_grid_levels.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_file_locations, (PyObject*)__pyx_v_grid_file_locations, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[0]; __pyx_bstride_1_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[1]; + __pyx_bshape_0_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[0]; __pyx_bshape_1_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_mask, (PyObject*)__pyx_v_child_mask, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_child_mask = __pyx_bstruct_child_mask.strides[0]; __pyx_bstride_1_child_mask = __pyx_bstruct_child_mask.strides[1]; + __pyx_bshape_0_child_mask = __pyx_bstruct_child_mask.shape[0]; __pyx_bshape_1_child_mask = __pyx_bstruct_child_mask.shape[1]; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":553 + * cdef tree_iterator grid_it, grid_end, father_it + * cdef vec[double] gvec + * cdef int grid_ind = 0, grid_aind = 0 # <<<<<<<<<<<<<< + * cdef unsigned parent_ind + * cdef bint ci + */ + __pyx_v_grid_ind = 0; + __pyx_v_grid_aind = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":560 + * + * cdef np.int32_t rr + * cell_count = [] # <<<<<<<<<<<<<< + * level_cell_counts = {} + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_v_cell_count)); + __pyx_v_cell_count = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":561 + * cdef np.int32_t rr + * cell_count = [] + * level_cell_counts = {} # <<<<<<<<<<<<<< + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_v_level_cell_counts)); + __pyx_v_level_cell_counts = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":562 + * cell_count = [] + * level_cell_counts = {} + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): # <<<<<<<<<<<<<< + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) + */ + __pyx_t_2 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu + 1); + for (__pyx_t_3 = 1; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_idomain = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":564 + * for idomain in range(1, self.rsnap.m_header.ncpu + 1): + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) # <<<<<<<<<<<<<< + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + */ + __pyx_v_local_tree = new RAMSES::AMR::RAMSES_tree((*((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap), __pyx_v_idomain, ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax, 0); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":565 + * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + * self.rsnap.m_header.levelmax, 0) + * local_tree.read() # <<<<<<<<<<<<<< + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * for ilevel in range(local_tree.m_maxlevel + 1): + */ + __pyx_v_local_tree->read(); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":566 + * self.rsnap.m_header.levelmax, 0) + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) # <<<<<<<<<<<<<< + * for ilevel in range(local_tree.m_maxlevel + 1): + * # this gets overwritten for every domain, which is okay + */ + __pyx_v_local_hydro_data = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":567 + * local_tree.read() + * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + * for ilevel in range(local_tree.m_maxlevel + 1): # <<<<<<<<<<<<<< + * # this gets overwritten for every domain, which is okay + * level_cell_counts[ilevel] = grid_ind + */ + __pyx_t_4 = (__pyx_v_local_tree->m_maxlevel + 1); + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { + __pyx_v_ilevel = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":569 + * for ilevel in range(local_tree.m_maxlevel + 1): + * # this gets overwritten for every domain, which is okay + * level_cell_counts[ilevel] = grid_ind # <<<<<<<<<<<<<< + * #grid_half_width = self.rsnap.m_header.boxlen / \ + * grid_half_width = 1.0 / \ + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_grid_ind); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_level_cell_counts), __pyx_v_ilevel, __pyx_t_1, sizeof(unsigned int)+1, PyLong_FromUnsignedLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":572 + * #grid_half_width = self.rsnap.m_header.boxlen / \ + * grid_half_width = 1.0 / \ + * (2**(ilevel) * top_grid_dims[0]) # <<<<<<<<<<<<<< + * grid_it = local_tree.begin(ilevel) + * grid_end = local_tree.end(ilevel) + */ + __pyx_t_6 = 0; + __pyx_t_7 = -1; + if (__pyx_t_6 < 0) { + __pyx_t_6 += __pyx_bshape_0_top_grid_dims; + if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0; + } else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_top_grid_dims)) __pyx_t_7 = 0; + if (unlikely(__pyx_t_7 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_7); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = (__Pyx_pow_long(2, __pyx_v_ilevel) * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_top_grid_dims.buf, __pyx_t_6, __pyx_bstride_0_top_grid_dims))); + if (unlikely(__pyx_t_8 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 571; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_grid_half_width = (1.0 / __pyx_t_8); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":573 + * grid_half_width = 1.0 / \ + * (2**(ilevel) * top_grid_dims[0]) + * grid_it = local_tree.begin(ilevel) # <<<<<<<<<<<<<< + * grid_end = local_tree.end(ilevel) + * while grid_it != grid_end: + */ + __pyx_v_grid_it = __pyx_v_local_tree->begin(__pyx_v_ilevel); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":574 + * (2**(ilevel) * top_grid_dims[0]) + * grid_it = local_tree.begin(ilevel) + * grid_end = local_tree.end(ilevel) # <<<<<<<<<<<<<< + * while grid_it != grid_end: + * if grid_it.get_domain() != idomain: + */ + __pyx_v_grid_end = __pyx_v_local_tree->end(__pyx_v_ilevel); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":575 + * grid_it = local_tree.begin(ilevel) + * grid_end = local_tree.end(ilevel) + * while grid_it != grid_end: # <<<<<<<<<<<<<< + * if grid_it.get_domain() != idomain: + * grid_ind += 1 + */ + while (1) { + __pyx_t_9 = (__pyx_v_grid_it != __pyx_v_grid_end); + if (!__pyx_t_9) break; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":576 + * grid_end = local_tree.end(ilevel) + * while grid_it != grid_end: + * if grid_it.get_domain() != idomain: # <<<<<<<<<<<<<< + * grid_ind += 1 + * grid_it.next() + */ + __pyx_t_9 = (__pyx_v_grid_it.get_domain() != __pyx_v_idomain); + if (__pyx_t_9) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":577 + * while grid_it != grid_end: + * if grid_it.get_domain() != idomain: + * grid_ind += 1 # <<<<<<<<<<<<<< + * grid_it.next() + * continue + */ + __pyx_v_grid_ind += 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":578 + * if grid_it.get_domain() != idomain: + * grid_ind += 1 + * grid_it.next() # <<<<<<<<<<<<<< + * continue + * gvec = local_tree.grid_pos_double(grid_it) + */ + __pyx_v_grid_it.next(); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":579 + * grid_ind += 1 + * grid_it.next() + * continue # <<<<<<<<<<<<<< + * gvec = local_tree.grid_pos_double(grid_it) + * left_edges[grid_aind, 0] = gvec.x - grid_half_width + */ + goto __pyx_L10_continue; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":580 + * grid_it.next() + * continue + * gvec = local_tree.grid_pos_double(grid_it) # <<<<<<<<<<<<<< + * left_edges[grid_aind, 0] = gvec.x - grid_half_width + * left_edges[grid_aind, 1] = gvec.y - grid_half_width + */ + __pyx_v_gvec = __pyx_v_local_tree->grid_pos(__pyx_v_grid_it); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":581 + * continue + * gvec = local_tree.grid_pos_double(grid_it) + * left_edges[grid_aind, 0] = gvec.x - grid_half_width # <<<<<<<<<<<<<< + * left_edges[grid_aind, 1] = gvec.y - grid_half_width + * left_edges[grid_aind, 2] = gvec.z - grid_half_width + */ + __pyx_t_7 = __pyx_v_grid_aind; + __pyx_t_8 = 0; + __pyx_t_10 = -1; + if (__pyx_t_7 < 0) { + __pyx_t_7 += __pyx_bshape_0_left_edges; + if (unlikely(__pyx_t_7 < 0)) __pyx_t_10 = 0; + } else if (unlikely(__pyx_t_7 >= __pyx_bshape_0_left_edges)) __pyx_t_10 = 0; + if (__pyx_t_8 < 0) { + __pyx_t_8 += __pyx_bshape_1_left_edges; + if (unlikely(__pyx_t_8 < 0)) __pyx_t_10 = 1; + } else if (unlikely(__pyx_t_8 >= __pyx_bshape_1_left_edges)) __pyx_t_10 = 1; + if (unlikely(__pyx_t_10 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_10); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_7, __pyx_bstride_0_left_edges, __pyx_t_8, __pyx_bstride_1_left_edges) = (__pyx_v_gvec.x - __pyx_v_grid_half_width); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":582 + * gvec = local_tree.grid_pos_double(grid_it) + * left_edges[grid_aind, 0] = gvec.x - grid_half_width + * left_edges[grid_aind, 1] = gvec.y - grid_half_width # <<<<<<<<<<<<<< + * left_edges[grid_aind, 2] = gvec.z - grid_half_width + * right_edges[grid_aind, 0] = gvec.x + grid_half_width + */ + __pyx_t_10 = __pyx_v_grid_aind; + __pyx_t_11 = 1; + __pyx_t_12 = -1; + if (__pyx_t_10 < 0) { + __pyx_t_10 += __pyx_bshape_0_left_edges; + if (unlikely(__pyx_t_10 < 0)) __pyx_t_12 = 0; + } else if (unlikely(__pyx_t_10 >= __pyx_bshape_0_left_edges)) __pyx_t_12 = 0; + if (__pyx_t_11 < 0) { + __pyx_t_11 += __pyx_bshape_1_left_edges; + if (unlikely(__pyx_t_11 < 0)) __pyx_t_12 = 1; + } else if (unlikely(__pyx_t_11 >= __pyx_bshape_1_left_edges)) __pyx_t_12 = 1; + if (unlikely(__pyx_t_12 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_12); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_10, __pyx_bstride_0_left_edges, __pyx_t_11, __pyx_bstride_1_left_edges) = (__pyx_v_gvec.y - __pyx_v_grid_half_width); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":583 + * left_edges[grid_aind, 0] = gvec.x - grid_half_width + * left_edges[grid_aind, 1] = gvec.y - grid_half_width + * left_edges[grid_aind, 2] = gvec.z - grid_half_width # <<<<<<<<<<<<<< + * right_edges[grid_aind, 0] = gvec.x + grid_half_width + * right_edges[grid_aind, 1] = gvec.y + grid_half_width + */ + __pyx_t_12 = __pyx_v_grid_aind; + __pyx_t_13 = 2; + __pyx_t_14 = -1; + if (__pyx_t_12 < 0) { + __pyx_t_12 += __pyx_bshape_0_left_edges; + if (unlikely(__pyx_t_12 < 0)) __pyx_t_14 = 0; + } else if (unlikely(__pyx_t_12 >= __pyx_bshape_0_left_edges)) __pyx_t_14 = 0; + if (__pyx_t_13 < 0) { + __pyx_t_13 += __pyx_bshape_1_left_edges; + if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1; + } else if (unlikely(__pyx_t_13 >= __pyx_bshape_1_left_edges)) __pyx_t_14 = 1; + if (unlikely(__pyx_t_14 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_14); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_12, __pyx_bstride_0_left_edges, __pyx_t_13, __pyx_bstride_1_left_edges) = (__pyx_v_gvec.z - __pyx_v_grid_half_width); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":584 + * left_edges[grid_aind, 1] = gvec.y - grid_half_width + * left_edges[grid_aind, 2] = gvec.z - grid_half_width + * right_edges[grid_aind, 0] = gvec.x + grid_half_width # <<<<<<<<<<<<<< + * right_edges[grid_aind, 1] = gvec.y + grid_half_width + * right_edges[grid_aind, 2] = gvec.z + grid_half_width + */ + __pyx_t_14 = __pyx_v_grid_aind; + __pyx_t_15 = 0; + __pyx_t_16 = -1; + if (__pyx_t_14 < 0) { + __pyx_t_14 += __pyx_bshape_0_right_edges; + if (unlikely(__pyx_t_14 < 0)) __pyx_t_16 = 0; + } else if (unlikely(__pyx_t_14 >= __pyx_bshape_0_right_edges)) __pyx_t_16 = 0; + if (__pyx_t_15 < 0) { + __pyx_t_15 += __pyx_bshape_1_right_edges; + if (unlikely(__pyx_t_15 < 0)) __pyx_t_16 = 1; + } else if (unlikely(__pyx_t_15 >= __pyx_bshape_1_right_edges)) __pyx_t_16 = 1; + if (unlikely(__pyx_t_16 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_16); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 584; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_14, __pyx_bstride_0_right_edges, __pyx_t_15, __pyx_bstride_1_right_edges) = (__pyx_v_gvec.x + __pyx_v_grid_half_width); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":585 + * left_edges[grid_aind, 2] = gvec.z - grid_half_width + * right_edges[grid_aind, 0] = gvec.x + grid_half_width + * right_edges[grid_aind, 1] = gvec.y + grid_half_width # <<<<<<<<<<<<<< + * right_edges[grid_aind, 2] = gvec.z + grid_half_width + * grid_levels[grid_aind, 0] = ilevel + */ + __pyx_t_16 = __pyx_v_grid_aind; + __pyx_t_17 = 1; + __pyx_t_18 = -1; + if (__pyx_t_16 < 0) { + __pyx_t_16 += __pyx_bshape_0_right_edges; + if (unlikely(__pyx_t_16 < 0)) __pyx_t_18 = 0; + } else if (unlikely(__pyx_t_16 >= __pyx_bshape_0_right_edges)) __pyx_t_18 = 0; + if (__pyx_t_17 < 0) { + __pyx_t_17 += __pyx_bshape_1_right_edges; + if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1; + } else if (unlikely(__pyx_t_17 >= __pyx_bshape_1_right_edges)) __pyx_t_18 = 1; + if (unlikely(__pyx_t_18 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_18); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_16, __pyx_bstride_0_right_edges, __pyx_t_17, __pyx_bstride_1_right_edges) = (__pyx_v_gvec.y + __pyx_v_grid_half_width); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":586 + * right_edges[grid_aind, 0] = gvec.x + grid_half_width + * right_edges[grid_aind, 1] = gvec.y + grid_half_width + * right_edges[grid_aind, 2] = gvec.z + grid_half_width # <<<<<<<<<<<<<< + * grid_levels[grid_aind, 0] = ilevel + * # Now the harder part + */ + __pyx_t_18 = __pyx_v_grid_aind; + __pyx_t_19 = 2; + __pyx_t_20 = -1; + if (__pyx_t_18 < 0) { + __pyx_t_18 += __pyx_bshape_0_right_edges; + if (unlikely(__pyx_t_18 < 0)) __pyx_t_20 = 0; + } else if (unlikely(__pyx_t_18 >= __pyx_bshape_0_right_edges)) __pyx_t_20 = 0; + if (__pyx_t_19 < 0) { + __pyx_t_19 += __pyx_bshape_1_right_edges; + if (unlikely(__pyx_t_19 < 0)) __pyx_t_20 = 1; + } else if (unlikely(__pyx_t_19 >= __pyx_bshape_1_right_edges)) __pyx_t_20 = 1; + if (unlikely(__pyx_t_20 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_20); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 586; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_18, __pyx_bstride_0_right_edges, __pyx_t_19, __pyx_bstride_1_right_edges) = (__pyx_v_gvec.z + __pyx_v_grid_half_width); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":587 + * right_edges[grid_aind, 1] = gvec.y + grid_half_width + * right_edges[grid_aind, 2] = gvec.z + grid_half_width + * grid_levels[grid_aind, 0] = ilevel # <<<<<<<<<<<<<< + * # Now the harder part + * father_it = grid_it.get_parent() + */ + __pyx_t_20 = __pyx_v_grid_aind; + __pyx_t_21 = 0; + __pyx_t_22 = -1; + if (__pyx_t_20 < 0) { + __pyx_t_20 += __pyx_bshape_0_grid_levels; + if (unlikely(__pyx_t_20 < 0)) __pyx_t_22 = 0; + } else if (unlikely(__pyx_t_20 >= __pyx_bshape_0_grid_levels)) __pyx_t_22 = 0; + if (__pyx_t_21 < 0) { + __pyx_t_21 += __pyx_bshape_1_grid_levels; + if (unlikely(__pyx_t_21 < 0)) __pyx_t_22 = 1; + } else if (unlikely(__pyx_t_21 >= __pyx_bshape_1_grid_levels)) __pyx_t_22 = 1; + if (unlikely(__pyx_t_22 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_22); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_grid_levels.buf, __pyx_t_20, __pyx_bstride_0_grid_levels, __pyx_t_21, __pyx_bstride_1_grid_levels) = __pyx_v_ilevel; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":589 + * grid_levels[grid_aind, 0] = ilevel + * # Now the harder part + * father_it = grid_it.get_parent() # <<<<<<<<<<<<<< + * grid_file_locations[grid_aind, 0] = idomain + * grid_file_locations[grid_aind, 1] = grid_ind - level_cell_counts[ilevel] + */ + __pyx_v_father_it = __pyx_v_grid_it.get_parent(); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":590 + * # Now the harder part + * father_it = grid_it.get_parent() + * grid_file_locations[grid_aind, 0] = idomain # <<<<<<<<<<<<<< + * grid_file_locations[grid_aind, 1] = grid_ind - level_cell_counts[ilevel] + * parent_ind = father_it.get_absolute_position() + */ + __pyx_t_22 = __pyx_v_grid_aind; + __pyx_t_23 = 0; + __pyx_t_24 = -1; + if (__pyx_t_22 < 0) { + __pyx_t_22 += __pyx_bshape_0_grid_file_locations; + if (unlikely(__pyx_t_22 < 0)) __pyx_t_24 = 0; + } else if (unlikely(__pyx_t_22 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_24 = 0; + if (__pyx_t_23 < 0) { + __pyx_t_23 += __pyx_bshape_1_grid_file_locations; + if (unlikely(__pyx_t_23 < 0)) __pyx_t_24 = 1; + } else if (unlikely(__pyx_t_23 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_24 = 1; + if (unlikely(__pyx_t_24 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_24); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_22, __pyx_bstride_0_grid_file_locations, __pyx_t_23, __pyx_bstride_1_grid_file_locations) = ((__pyx_t_5numpy_int64_t)__pyx_v_idomain); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":591 + * father_it = grid_it.get_parent() + * grid_file_locations[grid_aind, 0] = idomain + * grid_file_locations[grid_aind, 1] = grid_ind - level_cell_counts[ilevel] # <<<<<<<<<<<<<< + * parent_ind = father_it.get_absolute_position() + * if ilevel > 0: + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_grid_ind); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_25 = __Pyx_GetItemInt(((PyObject *)__pyx_v_level_cell_counts), __pyx_v_ilevel, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_25) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_25); + __pyx_t_26 = PyNumber_Subtract(__pyx_t_1, __pyx_t_25); if (unlikely(!__pyx_t_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_26); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; + __pyx_t_27 = __Pyx_PyInt_from_py_npy_int64(__pyx_t_26); if (unlikely((__pyx_t_27 == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0; + __pyx_t_24 = __pyx_v_grid_aind; + __pyx_t_28 = 1; + __pyx_t_29 = -1; + if (__pyx_t_24 < 0) { + __pyx_t_24 += __pyx_bshape_0_grid_file_locations; + if (unlikely(__pyx_t_24 < 0)) __pyx_t_29 = 0; + } else if (unlikely(__pyx_t_24 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_29 = 0; + if (__pyx_t_28 < 0) { + __pyx_t_28 += __pyx_bshape_1_grid_file_locations; + if (unlikely(__pyx_t_28 < 0)) __pyx_t_29 = 1; + } else if (unlikely(__pyx_t_28 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_29 = 1; + if (unlikely(__pyx_t_29 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_29); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_24, __pyx_bstride_0_grid_file_locations, __pyx_t_28, __pyx_bstride_1_grid_file_locations) = __pyx_t_27; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":592 + * grid_file_locations[grid_aind, 0] = idomain + * grid_file_locations[grid_aind, 1] = grid_ind - level_cell_counts[ilevel] + * parent_ind = father_it.get_absolute_position() # <<<<<<<<<<<<<< + * if ilevel > 0: + * # We calculate the REAL parent index + */ + __pyx_v_parent_ind = __pyx_v_father_it.get_absolute_position(); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":593 + * grid_file_locations[grid_aind, 1] = grid_ind - level_cell_counts[ilevel] + * parent_ind = father_it.get_absolute_position() + * if ilevel > 0: # <<<<<<<<<<<<<< + * # We calculate the REAL parent index + * grid_file_locations[grid_aind, 2] = \ + */ + __pyx_t_9 = (__pyx_v_ilevel > 0); + if (__pyx_t_9) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":596 + * # We calculate the REAL parent index + * grid_file_locations[grid_aind, 2] = \ + * level_cell_counts[ilevel - 1] + parent_ind # <<<<<<<<<<<<<< + * else: + * grid_file_locations[grid_aind, 2] = -1 + */ + __pyx_t_30 = (__pyx_v_ilevel - 1); + __pyx_t_26 = __Pyx_GetItemInt(((PyObject *)__pyx_v_level_cell_counts), __pyx_t_30, sizeof(long), PyInt_FromLong); if (!__pyx_t_26) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_26); + __pyx_t_25 = PyLong_FromUnsignedLong(__pyx_v_parent_ind); if (unlikely(!__pyx_t_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_25); + __pyx_t_1 = PyNumber_Add(__pyx_t_26, __pyx_t_25); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0; + __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; + __pyx_t_27 = __Pyx_PyInt_from_py_npy_int64(__pyx_t_1); if (unlikely((__pyx_t_27 == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":595 + * if ilevel > 0: + * # We calculate the REAL parent index + * grid_file_locations[grid_aind, 2] = \ # <<<<<<<<<<<<<< + * level_cell_counts[ilevel - 1] + parent_ind + * else: + */ + __pyx_t_29 = __pyx_v_grid_aind; + __pyx_t_30 = 2; + __pyx_t_31 = -1; + if (__pyx_t_29 < 0) { + __pyx_t_29 += __pyx_bshape_0_grid_file_locations; + if (unlikely(__pyx_t_29 < 0)) __pyx_t_31 = 0; + } else if (unlikely(__pyx_t_29 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_31 = 0; + if (__pyx_t_30 < 0) { + __pyx_t_30 += __pyx_bshape_1_grid_file_locations; + if (unlikely(__pyx_t_30 < 0)) __pyx_t_31 = 1; + } else if (unlikely(__pyx_t_30 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_31 = 1; + if (unlikely(__pyx_t_31 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_31); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_29, __pyx_bstride_0_grid_file_locations, __pyx_t_30, __pyx_bstride_1_grid_file_locations) = __pyx_t_27; + goto __pyx_L13; + } + /*else*/ { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":598 + * level_cell_counts[ilevel - 1] + parent_ind + * else: + * grid_file_locations[grid_aind, 2] = -1 # <<<<<<<<<<<<<< + * for ci in range(8): + * rr = grid_it.is_finest(ci) + */ + __pyx_t_31 = __pyx_v_grid_aind; + __pyx_t_32 = 2; + __pyx_t_33 = -1; + if (__pyx_t_31 < 0) { + __pyx_t_31 += __pyx_bshape_0_grid_file_locations; + if (unlikely(__pyx_t_31 < 0)) __pyx_t_33 = 0; + } else if (unlikely(__pyx_t_31 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_33 = 0; + if (__pyx_t_32 < 0) { + __pyx_t_32 += __pyx_bshape_1_grid_file_locations; + if (unlikely(__pyx_t_32 < 0)) __pyx_t_33 = 1; + } else if (unlikely(__pyx_t_32 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_33 = 1; + if (unlikely(__pyx_t_33 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_33); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_31, __pyx_bstride_0_grid_file_locations, __pyx_t_32, __pyx_bstride_1_grid_file_locations) = -1; + } + __pyx_L13:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":599 + * else: + * grid_file_locations[grid_aind, 2] = -1 + * for ci in range(8): # <<<<<<<<<<<<<< + * rr = grid_it.is_finest(ci) + * child_mask[grid_aind, ci] = rr + */ + for (__pyx_t_9 = 0; __pyx_t_9 < 8; __pyx_t_9+=1) { + __pyx_v_ci = __pyx_t_9; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":600 + * grid_file_locations[grid_aind, 2] = -1 + * for ci in range(8): + * rr = grid_it.is_finest(ci) # <<<<<<<<<<<<<< + * child_mask[grid_aind, ci] = rr + * grid_ind += 1 + */ + __pyx_v_rr = ((__pyx_t_5numpy_int32_t)__pyx_v_grid_it.is_finest(__pyx_v_ci)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":601 + * for ci in range(8): + * rr = grid_it.is_finest(ci) + * child_mask[grid_aind, ci] = rr # <<<<<<<<<<<<<< + * grid_ind += 1 + * grid_aind += 1 + */ + __pyx_t_33 = __pyx_v_grid_aind; + __pyx_t_34 = __pyx_v_ci; + __pyx_t_35 = -1; + if (__pyx_t_33 < 0) { + __pyx_t_33 += __pyx_bshape_0_child_mask; + if (unlikely(__pyx_t_33 < 0)) __pyx_t_35 = 0; + } else if (unlikely(__pyx_t_33 >= __pyx_bshape_0_child_mask)) __pyx_t_35 = 0; + if (__pyx_t_34 < 0) { + __pyx_t_34 += __pyx_bshape_1_child_mask; + if (unlikely(__pyx_t_34 < 0)) __pyx_t_35 = 1; + } else if (unlikely(__pyx_t_34 >= __pyx_bshape_1_child_mask)) __pyx_t_35 = 1; + if (unlikely(__pyx_t_35 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_35); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_child_mask.buf, __pyx_t_33, __pyx_bstride_0_child_mask, __pyx_t_34, __pyx_bstride_1_child_mask) = __pyx_v_rr; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":602 + * rr = grid_it.is_finest(ci) + * child_mask[grid_aind, ci] = rr + * grid_ind += 1 # <<<<<<<<<<<<<< + * grid_aind += 1 + * grid_it.next() + */ + __pyx_v_grid_ind += 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":603 + * child_mask[grid_aind, ci] = rr + * grid_ind += 1 + * grid_aind += 1 # <<<<<<<<<<<<<< + * grid_it.next() + * del local_tree, local_hydro_data + */ + __pyx_v_grid_aind += 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":604 + * grid_ind += 1 + * grid_aind += 1 + * grid_it.next() # <<<<<<<<<<<<<< + * del local_tree, local_hydro_data + * + */ + __pyx_v_grid_it.next(); + __pyx_L10_continue:; + } + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":605 + * grid_aind += 1 + * grid_it.next() + * del local_tree, local_hydro_data # <<<<<<<<<<<<<< + * + * def read_oct_grid(self, char *field, int level, int domain, int grid_id): + */ + delete __pyx_v_local_tree; + delete __pyx_v_local_hydro_data; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_25); + __Pyx_XDECREF(__pyx_t_26); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_levels); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_mask); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_top_grid_dims); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.fill_hierarchy_arrays"); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_levels); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_mask); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_top_grid_dims); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); + __pyx_L2:; + __Pyx_DECREF(__pyx_v_cell_count); + __Pyx_DECREF(__pyx_v_level_cell_counts); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":607 + * del local_tree, local_hydro_data + * + * def read_oct_grid(self, char *field, int level, int domain, int grid_id): # <<<<<<<<<<<<<< + * + * self.ensure_loaded(field, domain - 1) + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_read_oct_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_read_oct_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_field; + int __pyx_v_level; + int __pyx_v_domain; + int __pyx_v_grid_id; + int __pyx_v_varindex; + int __pyx_v_i; + PyArrayObject *__pyx_v_tr = 0; + double *__pyx_v_data; + RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; + RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; + Py_buffer __pyx_bstruct_tr; + Py_ssize_t __pyx_bstride_0_tr = 0; + Py_ssize_t __pyx_bstride_1_tr = 0; + Py_ssize_t __pyx_bstride_2_tr = 0; + Py_ssize_t __pyx_bshape_0_tr = 0; + Py_ssize_t __pyx_bshape_1_tr = 0; + Py_ssize_t __pyx_bshape_2_tr = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyArrayObject *__pyx_t_6 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__field,&__pyx_n_s__level,&__pyx_n_s__domain,&__pyx_n_s__grid_id,0}; + __Pyx_RefNannySetupContext("read_oct_grid"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[4] = {0,0,0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__domain); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_id); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read_oct_grid") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_field = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_level = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_domain = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_domain == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_grid_id = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_field = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_domain = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_domain == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_grid_id = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.read_oct_grid"); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_bstruct_tr.buf = NULL; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":609 + * def read_oct_grid(self, char *field, int level, int domain, int grid_id): + * + * self.ensure_loaded(field, domain - 1) # <<<<<<<<<<<<<< + * cdef int varindex = self.field_ind[field] + * cdef int i + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__ensure_loaded); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyInt_FromLong((__pyx_v_domain - 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":610 + * + * self.ensure_loaded(field, domain - 1) + * cdef int varindex = self.field_ind[field] # <<<<<<<<<<<<<< + * cdef int i + * + */ + __pyx_t_3 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_4 = PyObject_GetItem(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_3)); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_varindex = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":613 + * cdef int i + * + * cdef np.ndarray[np.float64_t, ndim=3] tr = np.empty((2,2,2), dtype='float64', # <<<<<<<<<<<<<< + * order='F') + * cdef tree_iterator grid_it, grid_end + */ + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + __Pyx_INCREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + __Pyx_INCREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__float64)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_3, __pyx_t_1, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = ((PyArrayObject *)__pyx_t_2); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_tr, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) { + __pyx_v_tr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_tr.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_bstride_0_tr = __pyx_bstruct_tr.strides[0]; __pyx_bstride_1_tr = __pyx_bstruct_tr.strides[1]; __pyx_bstride_2_tr = __pyx_bstruct_tr.strides[2]; + __pyx_bshape_0_tr = __pyx_bstruct_tr.shape[0]; __pyx_bshape_1_tr = __pyx_bstruct_tr.shape[1]; __pyx_bshape_2_tr = __pyx_bstruct_tr.shape[2]; + } + } + __pyx_t_6 = 0; + __pyx_v_tr = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":616 + * order='F') + * cdef tree_iterator grid_it, grid_end + * cdef double* data = tr.data # <<<<<<<<<<<<<< + * + * cdef RAMSES_tree *local_tree = self.trees[domain - 1] + */ + __pyx_v_data = ((double *)__pyx_v_tr->data); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":618 + * cdef double* data = tr.data + * + * cdef RAMSES_tree *local_tree = self.trees[domain - 1] # <<<<<<<<<<<<<< + * cdef RAMSES_hydro_data *local_hydro_data = self.hydro_datas[domain - 1][varindex] + * + */ + __pyx_v_local_tree = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[(__pyx_v_domain - 1)]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":619 + * + * cdef RAMSES_tree *local_tree = self.trees[domain - 1] + * cdef RAMSES_hydro_data *local_hydro_data = self.hydro_datas[domain - 1][varindex] # <<<<<<<<<<<<<< + * + * #inline ValueType_& cell_value( const typename TreeType_::iterator& it, + */ + __pyx_v_local_hydro_data = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_domain - 1)])[__pyx_v_varindex]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":629 + * #} + * + * for i in range(8): # <<<<<<<<<<<<<< + * data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] + * return tr + */ + for (__pyx_t_5 = 0; __pyx_t_5 < 8; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":630 + * + * for i in range(8): + * data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] # <<<<<<<<<<<<<< + * return tr + * + */ + (__pyx_v_data[__pyx_v_i]) = ((__pyx_v_local_hydro_data->m_var_array[__pyx_v_level])[((8 * __pyx_v_grid_id) + __pyx_v_i)]); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":631 + * for i in range(8): + * data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] + * return tr # <<<<<<<<<<<<<< + * + * def read_grid(self, char *field, + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_tr)); + __pyx_r = ((PyObject *)__pyx_v_tr); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tr); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.read_oct_grid"); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tr); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_tr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":633 + * return tr + * + * def read_grid(self, char *field, # <<<<<<<<<<<<<< + * np.ndarray[np.int64_t, ndim=1] start_index, + * np.ndarray[np.int32_t, ndim=1] grid_dims, + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_read_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_read_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_field; + PyArrayObject *__pyx_v_start_index = 0; + PyArrayObject *__pyx_v_grid_dims = 0; + PyArrayObject *__pyx_v_data = 0; + PyArrayObject *__pyx_v_filled = 0; + int __pyx_v_level; + int __pyx_v_ref_factor; + PyObject *__pyx_v_component_grid_info = 0; + int __pyx_v_varindex; + RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; + RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; + int __pyx_v_gi; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_k; + int __pyx_v_domain; + int __pyx_v_offset; + int __pyx_v_ir; + int __pyx_v_jr; + int __pyx_v_kr; + int __pyx_v_offi; + int __pyx_v_offj; + int __pyx_v_offk; + int __pyx_v_odind; + __pyx_t_5numpy_int64_t __pyx_v_di; + __pyx_t_5numpy_int64_t __pyx_v_dj; + __pyx_t_5numpy_int64_t __pyx_v_dk; + PyArrayObject *__pyx_v_ogrid_info; + PyArrayObject *__pyx_v_og_start_index; + __pyx_t_5numpy_float64_t __pyx_v_temp_data; + __pyx_t_5numpy_int64_t __pyx_v_end_index[3]; + int __pyx_v_to_fill; + Py_buffer __pyx_bstruct_grid_dims; + Py_ssize_t __pyx_bstride_0_grid_dims = 0; + Py_ssize_t __pyx_bshape_0_grid_dims = 0; + Py_buffer __pyx_bstruct_og_start_index; + Py_ssize_t __pyx_bstride_0_og_start_index = 0; + Py_ssize_t __pyx_bshape_0_og_start_index = 0; + Py_buffer __pyx_bstruct_ogrid_info; + Py_ssize_t __pyx_bstride_0_ogrid_info = 0; + Py_ssize_t __pyx_bshape_0_ogrid_info = 0; + Py_buffer __pyx_bstruct_filled; + Py_ssize_t __pyx_bstride_0_filled = 0; + Py_ssize_t __pyx_bstride_1_filled = 0; + Py_ssize_t __pyx_bstride_2_filled = 0; + Py_ssize_t __pyx_bshape_0_filled = 0; + Py_ssize_t __pyx_bshape_1_filled = 0; + Py_ssize_t __pyx_bshape_2_filled = 0; + Py_buffer __pyx_bstruct_data; + Py_ssize_t __pyx_bstride_0_data = 0; + Py_ssize_t __pyx_bstride_1_data = 0; + Py_ssize_t __pyx_bstride_2_data = 0; + Py_ssize_t __pyx_bshape_0_data = 0; + Py_ssize_t __pyx_bshape_1_data = 0; + Py_ssize_t __pyx_bshape_2_data = 0; + Py_buffer __pyx_bstruct_start_index; + Py_ssize_t __pyx_bstride_0_start_index = 0; + Py_ssize_t __pyx_bshape_0_start_index = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + Py_ssize_t __pyx_t_7; + PyArrayObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + long __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + long __pyx_t_15; + PyArrayObject *__pyx_t_16 = NULL; + long __pyx_t_17; + long __pyx_t_18; + int __pyx_t_19; + long __pyx_t_20; + int __pyx_t_21; + int __pyx_t_22; + int __pyx_t_23; + long __pyx_t_24; + long __pyx_t_25; + int __pyx_t_26; + long __pyx_t_27; + long __pyx_t_28; + long __pyx_t_29; + int __pyx_t_30; + long __pyx_t_31; + long __pyx_t_32; + long __pyx_t_33; + long __pyx_t_34; + int __pyx_t_35; + int __pyx_t_36; + int __pyx_t_37; + int __pyx_t_38; + int __pyx_t_39; + int __pyx_t_40; + int __pyx_t_41; + int __pyx_t_42; + int __pyx_t_43; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__field,&__pyx_n_s__start_index,&__pyx_n_s__grid_dims,&__pyx_n_s__data,&__pyx_n_s__filled,&__pyx_n_s__level,&__pyx_n_s__ref_factor,&__pyx_n_s__component_grid_info,0}; + __Pyx_RefNannySetupContext("read_grid"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[8] = {0,0,0,0,0,0,0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start_index); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_dims); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filled); + if (likely(values[4])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 5: + values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); + if (likely(values[5])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 6: + values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref_factor); + if (likely(values[6])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 7: + values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__component_grid_info); + if (likely(values[7])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read_grid") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_field = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_start_index = ((PyArrayObject *)values[1]); + __pyx_v_grid_dims = ((PyArrayObject *)values[2]); + __pyx_v_data = ((PyArrayObject *)values[3]); + __pyx_v_filled = ((PyArrayObject *)values[4]); + __pyx_v_level = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_ref_factor = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_ref_factor == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_component_grid_info = values[7]; + } else if (PyTuple_GET_SIZE(__pyx_args) != 8) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_field = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_start_index = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); + __pyx_v_grid_dims = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); + __pyx_v_data = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); + __pyx_v_filled = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); + __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_ref_factor = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 6)); if (unlikely((__pyx_v_ref_factor == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_component_grid_info = PyTuple_GET_ITEM(__pyx_args, 7); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.read_grid"); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_v_ogrid_info = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_og_start_index = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_bstruct_ogrid_info.buf = NULL; + __pyx_bstruct_og_start_index.buf = NULL; + __pyx_bstruct_start_index.buf = NULL; + __pyx_bstruct_grid_dims.buf = NULL; + __pyx_bstruct_data.buf = NULL; + __pyx_bstruct_filled.buf = NULL; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_start_index), __pyx_ptype_5numpy_ndarray, 1, "start_index", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_dims), __pyx_ptype_5numpy_ndarray, 1, "grid_dims", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_filled), __pyx_ptype_5numpy_ndarray, 1, "filled", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_start_index, (PyObject*)__pyx_v_start_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_start_index = __pyx_bstruct_start_index.strides[0]; + __pyx_bshape_0_start_index = __pyx_bstruct_start_index.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_dims, (PyObject*)__pyx_v_grid_dims, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_grid_dims = __pyx_bstruct_grid_dims.strides[0]; + __pyx_bshape_0_grid_dims = __pyx_bstruct_grid_dims.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bstride_2_data = __pyx_bstruct_data.strides[2]; + __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; __pyx_bshape_2_data = __pyx_bstruct_data.shape[2]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_filled, (PyObject*)__pyx_v_filled, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_filled = __pyx_bstruct_filled.strides[0]; __pyx_bstride_1_filled = __pyx_bstruct_filled.strides[1]; __pyx_bstride_2_filled = __pyx_bstruct_filled.strides[2]; + __pyx_bshape_0_filled = __pyx_bstruct_filled.shape[0]; __pyx_bshape_1_filled = __pyx_bstruct_filled.shape[1]; __pyx_bshape_2_filled = __pyx_bstruct_filled.shape[2]; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":640 + * int level, int ref_factor, + * component_grid_info): + * cdef int varindex = self.field_ind[field] # <<<<<<<<<<<<<< + * cdef RAMSES_tree *local_tree = NULL + * cdef RAMSES_hydro_data *local_hydro_data = NULL + */ + __pyx_t_1 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_varindex = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":641 + * component_grid_info): + * cdef int varindex = self.field_ind[field] + * cdef RAMSES_tree *local_tree = NULL # <<<<<<<<<<<<<< + * cdef RAMSES_hydro_data *local_hydro_data = NULL + * + */ + __pyx_v_local_tree = NULL; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":642 + * cdef int varindex = self.field_ind[field] + * cdef RAMSES_tree *local_tree = NULL + * cdef RAMSES_hydro_data *local_hydro_data = NULL # <<<<<<<<<<<<<< + * + * cdef int gi, i, j, k, domain, offset + */ + __pyx_v_local_hydro_data = NULL; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":652 + * cdef np.float64_t temp_data + * cdef np.int64_t end_index[3] + * cdef int to_fill = 0 # <<<<<<<<<<<<<< + * # Note that indexing into a cell is: + * # (k*2 + j)*2 + i + */ + __pyx_v_to_fill = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":655 + * # Note that indexing into a cell is: + * # (k*2 + j)*2 + i + * for i in range(3): # <<<<<<<<<<<<<< + * end_index[i] = start_index[i] + grid_dims[i] + * for gi in range(len(component_grid_info)): + */ + for (__pyx_t_3 = 0; __pyx_t_3 < 3; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":656 + * # (k*2 + j)*2 + i + * for i in range(3): + * end_index[i] = start_index[i] + grid_dims[i] # <<<<<<<<<<<<<< + * for gi in range(len(component_grid_info)): + * ogrid_info = component_grid_info[gi] + */ + __pyx_t_4 = __pyx_v_i; + __pyx_t_5 = -1; + if (__pyx_t_4 < 0) { + __pyx_t_4 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_4 < 0)) __pyx_t_5 = 0; + } else if (unlikely(__pyx_t_4 >= __pyx_bshape_0_start_index)) __pyx_t_5 = 0; + if (unlikely(__pyx_t_5 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_5); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = __pyx_v_i; + __pyx_t_6 = -1; + if (__pyx_t_5 < 0) { + __pyx_t_5 += __pyx_bshape_0_grid_dims; + if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0; + } else if (unlikely(__pyx_t_5 >= __pyx_bshape_0_grid_dims)) __pyx_t_6 = 0; + if (unlikely(__pyx_t_6 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_6); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + (__pyx_v_end_index[__pyx_v_i]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_4, __pyx_bstride_0_start_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_grid_dims.buf, __pyx_t_5, __pyx_bstride_0_grid_dims))); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":657 + * for i in range(3): + * end_index[i] = start_index[i] + grid_dims[i] + * for gi in range(len(component_grid_info)): # <<<<<<<<<<<<<< + * ogrid_info = component_grid_info[gi] + * domain = ogrid_info[0] + */ + __pyx_t_7 = PyObject_Length(__pyx_v_component_grid_info); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_7; __pyx_t_3+=1) { + __pyx_v_gi = __pyx_t_3; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":658 + * end_index[i] = start_index[i] + grid_dims[i] + * for gi in range(len(component_grid_info)): + * ogrid_info = component_grid_info[gi] # <<<<<<<<<<<<<< + * domain = ogrid_info[0] + * #print "Loading", domain, ogrid_info + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_component_grid_info, __pyx_v_gi, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = ((PyArrayObject *)__pyx_t_2); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ogrid_info); + __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_ogrid_info, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_6 < 0)) { + PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_ogrid_info, (PyObject*)__pyx_v_ogrid_info, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11); + } + } + __pyx_bstride_0_ogrid_info = __pyx_bstruct_ogrid_info.strides[0]; + __pyx_bshape_0_ogrid_info = __pyx_bstruct_ogrid_info.shape[0]; + if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_ogrid_info)); + __pyx_v_ogrid_info = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":659 + * for gi in range(len(component_grid_info)): + * ogrid_info = component_grid_info[gi] + * domain = ogrid_info[0] # <<<<<<<<<<<<<< + * #print "Loading", domain, ogrid_info + * self.ensure_loaded(field, domain - 1) + */ + __pyx_t_12 = 0; + __pyx_t_6 = -1; + if (__pyx_t_12 < 0) { + __pyx_t_12 += __pyx_bshape_0_ogrid_info; + if (unlikely(__pyx_t_12 < 0)) __pyx_t_6 = 0; + } else if (unlikely(__pyx_t_12 >= __pyx_bshape_0_ogrid_info)) __pyx_t_6 = 0; + if (unlikely(__pyx_t_6 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_6); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_domain = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_ogrid_info.buf, __pyx_t_12, __pyx_bstride_0_ogrid_info)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":661 + * domain = ogrid_info[0] + * #print "Loading", domain, ogrid_info + * self.ensure_loaded(field, domain - 1) # <<<<<<<<<<<<<< + * local_tree = self.trees[domain - 1] + * local_hydro_data = self.hydro_datas[domain - 1][varindex] + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__ensure_loaded); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_13 = PyInt_FromLong((__pyx_v_domain - 1)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_13); + __pyx_t_1 = 0; + __pyx_t_13 = 0; + __pyx_t_13 = PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":662 + * #print "Loading", domain, ogrid_info + * self.ensure_loaded(field, domain - 1) + * local_tree = self.trees[domain - 1] # <<<<<<<<<<<<<< + * local_hydro_data = self.hydro_datas[domain - 1][varindex] + * offset = ogrid_info[1] + */ + __pyx_v_local_tree = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[(__pyx_v_domain - 1)]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":663 + * self.ensure_loaded(field, domain - 1) + * local_tree = self.trees[domain - 1] + * local_hydro_data = self.hydro_datas[domain - 1][varindex] # <<<<<<<<<<<<<< + * offset = ogrid_info[1] + * og_start_index = ogrid_info[3:] + */ + __pyx_v_local_hydro_data = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_domain - 1)])[__pyx_v_varindex]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":664 + * local_tree = self.trees[domain - 1] + * local_hydro_data = self.hydro_datas[domain - 1][varindex] + * offset = ogrid_info[1] # <<<<<<<<<<<<<< + * og_start_index = ogrid_info[3:] + * for i in range(2*ref_factor): + */ + __pyx_t_15 = 1; + __pyx_t_6 = -1; + if (__pyx_t_15 < 0) { + __pyx_t_15 += __pyx_bshape_0_ogrid_info; + if (unlikely(__pyx_t_15 < 0)) __pyx_t_6 = 0; + } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_ogrid_info)) __pyx_t_6 = 0; + if (unlikely(__pyx_t_6 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_6); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_offset = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_ogrid_info.buf, __pyx_t_15, __pyx_bstride_0_ogrid_info)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":665 + * local_hydro_data = self.hydro_datas[domain - 1][varindex] + * offset = ogrid_info[1] + * og_start_index = ogrid_info[3:] # <<<<<<<<<<<<<< + * for i in range(2*ref_factor): + * di = i + og_start_index[0] * ref_factor + */ + __pyx_t_13 = PySequence_GetSlice(((PyObject *)__pyx_v_ogrid_info), 3, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_16 = ((PyArrayObject *)__pyx_t_13); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_og_start_index); + __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_og_start_index, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_6 < 0)) { + PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_og_start_index, (PyObject*)__pyx_v_og_start_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9); + } + } + __pyx_bstride_0_og_start_index = __pyx_bstruct_og_start_index.strides[0]; + __pyx_bshape_0_og_start_index = __pyx_bstruct_og_start_index.shape[0]; + if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_16 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_og_start_index)); + __pyx_v_og_start_index = ((PyArrayObject *)__pyx_t_13); + __pyx_t_13 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":666 + * offset = ogrid_info[1] + * og_start_index = ogrid_info[3:] + * for i in range(2*ref_factor): # <<<<<<<<<<<<<< + * di = i + og_start_index[0] * ref_factor + * if di < start_index[0] or di >= end_index[0]: continue + */ + __pyx_t_17 = (2 * __pyx_v_ref_factor); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_17; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":667 + * og_start_index = ogrid_info[3:] + * for i in range(2*ref_factor): + * di = i + og_start_index[0] * ref_factor # <<<<<<<<<<<<<< + * if di < start_index[0] or di >= end_index[0]: continue + * ir = (i / ref_factor) + */ + __pyx_t_18 = 0; + __pyx_t_19 = -1; + if (__pyx_t_18 < 0) { + __pyx_t_18 += __pyx_bshape_0_og_start_index; + if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 0; + } else if (unlikely(__pyx_t_18 >= __pyx_bshape_0_og_start_index)) __pyx_t_19 = 0; + if (unlikely(__pyx_t_19 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_19); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 667; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_di = (__pyx_v_i + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_og_start_index.buf, __pyx_t_18, __pyx_bstride_0_og_start_index)) * __pyx_v_ref_factor)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":668 + * for i in range(2*ref_factor): + * di = i + og_start_index[0] * ref_factor + * if di < start_index[0] or di >= end_index[0]: continue # <<<<<<<<<<<<<< + * ir = (i / ref_factor) + * for j in range(2 * ref_factor): + */ + __pyx_t_20 = 0; + __pyx_t_19 = -1; + if (__pyx_t_20 < 0) { + __pyx_t_20 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_20 < 0)) __pyx_t_19 = 0; + } else if (unlikely(__pyx_t_20 >= __pyx_bshape_0_start_index)) __pyx_t_19 = 0; + if (unlikely(__pyx_t_19 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_19); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_21 = (__pyx_v_di < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_20, __pyx_bstride_0_start_index))); + if (!__pyx_t_21) { + __pyx_t_22 = (__pyx_v_di >= (__pyx_v_end_index[0])); + __pyx_t_23 = __pyx_t_22; + } else { + __pyx_t_23 = __pyx_t_21; + } + if (__pyx_t_23) { + goto __pyx_L10_continue; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":669 + * di = i + og_start_index[0] * ref_factor + * if di < start_index[0] or di >= end_index[0]: continue + * ir = (i / ref_factor) # <<<<<<<<<<<<<< + * for j in range(2 * ref_factor): + * dj = j + og_start_index[1] * ref_factor + */ + if (unlikely(__pyx_v_ref_factor == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_ref_factor == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_i))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_ir = __Pyx_div_int(__pyx_v_i, __pyx_v_ref_factor); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":670 + * if di < start_index[0] or di >= end_index[0]: continue + * ir = (i / ref_factor) + * for j in range(2 * ref_factor): # <<<<<<<<<<<<<< + * dj = j + og_start_index[1] * ref_factor + * if dj < start_index[1] or dj >= end_index[1]: continue + */ + __pyx_t_24 = (2 * __pyx_v_ref_factor); + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_24; __pyx_t_19+=1) { + __pyx_v_j = __pyx_t_19; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":671 + * ir = (i / ref_factor) + * for j in range(2 * ref_factor): + * dj = j + og_start_index[1] * ref_factor # <<<<<<<<<<<<<< + * if dj < start_index[1] or dj >= end_index[1]: continue + * jr = (j / ref_factor) + */ + __pyx_t_25 = 1; + __pyx_t_26 = -1; + if (__pyx_t_25 < 0) { + __pyx_t_25 += __pyx_bshape_0_og_start_index; + if (unlikely(__pyx_t_25 < 0)) __pyx_t_26 = 0; + } else if (unlikely(__pyx_t_25 >= __pyx_bshape_0_og_start_index)) __pyx_t_26 = 0; + if (unlikely(__pyx_t_26 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_26); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_dj = (__pyx_v_j + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_og_start_index.buf, __pyx_t_25, __pyx_bstride_0_og_start_index)) * __pyx_v_ref_factor)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":672 + * for j in range(2 * ref_factor): + * dj = j + og_start_index[1] * ref_factor + * if dj < start_index[1] or dj >= end_index[1]: continue # <<<<<<<<<<<<<< + * jr = (j / ref_factor) + * for k in range(2 * ref_factor): + */ + __pyx_t_27 = 1; + __pyx_t_26 = -1; + if (__pyx_t_27 < 0) { + __pyx_t_27 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_27 < 0)) __pyx_t_26 = 0; + } else if (unlikely(__pyx_t_27 >= __pyx_bshape_0_start_index)) __pyx_t_26 = 0; + if (unlikely(__pyx_t_26 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_26); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_23 = (__pyx_v_dj < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_27, __pyx_bstride_0_start_index))); + if (!__pyx_t_23) { + __pyx_t_21 = (__pyx_v_dj >= (__pyx_v_end_index[1])); + __pyx_t_22 = __pyx_t_21; + } else { + __pyx_t_22 = __pyx_t_23; + } + if (__pyx_t_22) { + goto __pyx_L13_continue; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":673 + * dj = j + og_start_index[1] * ref_factor + * if dj < start_index[1] or dj >= end_index[1]: continue + * jr = (j / ref_factor) # <<<<<<<<<<<<<< + * for k in range(2 * ref_factor): + * dk = k + og_start_index[2] * ref_factor + */ + if (unlikely(__pyx_v_ref_factor == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_ref_factor == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_j))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_jr = __Pyx_div_int(__pyx_v_j, __pyx_v_ref_factor); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":674 + * if dj < start_index[1] or dj >= end_index[1]: continue + * jr = (j / ref_factor) + * for k in range(2 * ref_factor): # <<<<<<<<<<<<<< + * dk = k + og_start_index[2] * ref_factor + * if dk < start_index[2] or dk >= end_index[2]: continue + */ + __pyx_t_28 = (2 * __pyx_v_ref_factor); + for (__pyx_t_26 = 0; __pyx_t_26 < __pyx_t_28; __pyx_t_26+=1) { + __pyx_v_k = __pyx_t_26; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":675 + * jr = (j / ref_factor) + * for k in range(2 * ref_factor): + * dk = k + og_start_index[2] * ref_factor # <<<<<<<<<<<<<< + * if dk < start_index[2] or dk >= end_index[2]: continue + * kr = (k / ref_factor) + */ + __pyx_t_29 = 2; + __pyx_t_30 = -1; + if (__pyx_t_29 < 0) { + __pyx_t_29 += __pyx_bshape_0_og_start_index; + if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_29 >= __pyx_bshape_0_og_start_index)) __pyx_t_30 = 0; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_dk = (__pyx_v_k + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_og_start_index.buf, __pyx_t_29, __pyx_bstride_0_og_start_index)) * __pyx_v_ref_factor)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":676 + * for k in range(2 * ref_factor): + * dk = k + og_start_index[2] * ref_factor + * if dk < start_index[2] or dk >= end_index[2]: continue # <<<<<<<<<<<<<< + * kr = (k / ref_factor) + * offi = di - start_index[0] + */ + __pyx_t_31 = 2; + __pyx_t_30 = -1; + if (__pyx_t_31 < 0) { + __pyx_t_31 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_31 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_31 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_22 = (__pyx_v_dk < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_31, __pyx_bstride_0_start_index))); + if (!__pyx_t_22) { + __pyx_t_23 = (__pyx_v_dk >= (__pyx_v_end_index[2])); + __pyx_t_21 = __pyx_t_23; + } else { + __pyx_t_21 = __pyx_t_22; + } + if (__pyx_t_21) { + goto __pyx_L16_continue; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":677 + * dk = k + og_start_index[2] * ref_factor + * if dk < start_index[2] or dk >= end_index[2]: continue + * kr = (k / ref_factor) # <<<<<<<<<<<<<< + * offi = di - start_index[0] + * offj = dj - start_index[1] + */ + if (unlikely(__pyx_v_ref_factor == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_ref_factor == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_k))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_kr = __Pyx_div_int(__pyx_v_k, __pyx_v_ref_factor); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":678 + * if dk < start_index[2] or dk >= end_index[2]: continue + * kr = (k / ref_factor) + * offi = di - start_index[0] # <<<<<<<<<<<<<< + * offj = dj - start_index[1] + * offk = dk - start_index[2] + */ + __pyx_t_32 = 0; + __pyx_t_30 = -1; + if (__pyx_t_32 < 0) { + __pyx_t_32 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_32 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_32 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_offi = (__pyx_v_di - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_32, __pyx_bstride_0_start_index))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":679 + * kr = (k / ref_factor) + * offi = di - start_index[0] + * offj = dj - start_index[1] # <<<<<<<<<<<<<< + * offk = dk - start_index[2] + * #print offi, filled.shape[0], + */ + __pyx_t_33 = 1; + __pyx_t_30 = -1; + if (__pyx_t_33 < 0) { + __pyx_t_33 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_33 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_33 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_offj = (__pyx_v_dj - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_33, __pyx_bstride_0_start_index))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":680 + * offi = di - start_index[0] + * offj = dj - start_index[1] + * offk = dk - start_index[2] # <<<<<<<<<<<<<< + * #print offi, filled.shape[0], + * #print offj, filled.shape[1], + */ + __pyx_t_34 = 2; + __pyx_t_30 = -1; + if (__pyx_t_34 < 0) { + __pyx_t_34 += __pyx_bshape_0_start_index; + if (unlikely(__pyx_t_34 < 0)) __pyx_t_30 = 0; + } else if (unlikely(__pyx_t_34 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; + if (unlikely(__pyx_t_30 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_30); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_offk = (__pyx_v_dk - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_34, __pyx_bstride_0_start_index))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":684 + * #print offj, filled.shape[1], + * #print offk, filled.shape[2] + * if filled[offi, offj, offk] == 1: continue # <<<<<<<<<<<<<< + * + * odind = (kr*2 + jr)*2 + ir + */ + __pyx_t_30 = __pyx_v_offi; + __pyx_t_35 = __pyx_v_offj; + __pyx_t_36 = __pyx_v_offk; + __pyx_t_37 = -1; + if (__pyx_t_30 < 0) { + __pyx_t_30 += __pyx_bshape_0_filled; + if (unlikely(__pyx_t_30 < 0)) __pyx_t_37 = 0; + } else if (unlikely(__pyx_t_30 >= __pyx_bshape_0_filled)) __pyx_t_37 = 0; + if (__pyx_t_35 < 0) { + __pyx_t_35 += __pyx_bshape_1_filled; + if (unlikely(__pyx_t_35 < 0)) __pyx_t_37 = 1; + } else if (unlikely(__pyx_t_35 >= __pyx_bshape_1_filled)) __pyx_t_37 = 1; + if (__pyx_t_36 < 0) { + __pyx_t_36 += __pyx_bshape_2_filled; + if (unlikely(__pyx_t_36 < 0)) __pyx_t_37 = 2; + } else if (unlikely(__pyx_t_36 >= __pyx_bshape_2_filled)) __pyx_t_37 = 2; + if (unlikely(__pyx_t_37 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_37); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_21 = ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_filled.buf, __pyx_t_30, __pyx_bstride_0_filled, __pyx_t_35, __pyx_bstride_1_filled, __pyx_t_36, __pyx_bstride_2_filled)) == 1); + if (__pyx_t_21) { + goto __pyx_L16_continue; + goto __pyx_L19; + } + __pyx_L19:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":686 + * if filled[offi, offj, offk] == 1: continue + * + * odind = (kr*2 + jr)*2 + ir # <<<<<<<<<<<<<< + * temp_data = local_hydro_data.m_var_array[ + * level][8*offset + odind] + */ + __pyx_v_odind = ((((__pyx_v_kr * 2) + __pyx_v_jr) * 2) + __pyx_v_ir); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":688 + * odind = (kr*2 + jr)*2 + ir + * temp_data = local_hydro_data.m_var_array[ + * level][8*offset + odind] # <<<<<<<<<<<<<< + * data[offi, offj, offk] = temp_data + * filled[offi, offj, offk] = 1 + */ + __pyx_v_temp_data = ((__pyx_v_local_hydro_data->m_var_array[__pyx_v_level])[((8 * __pyx_v_offset) + __pyx_v_odind)]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":689 + * temp_data = local_hydro_data.m_var_array[ + * level][8*offset + odind] + * data[offi, offj, offk] = temp_data # <<<<<<<<<<<<<< + * filled[offi, offj, offk] = 1 + * to_fill += 1 + */ + __pyx_t_37 = __pyx_v_offi; + __pyx_t_38 = __pyx_v_offj; + __pyx_t_39 = __pyx_v_offk; + __pyx_t_40 = -1; + if (__pyx_t_37 < 0) { + __pyx_t_37 += __pyx_bshape_0_data; + if (unlikely(__pyx_t_37 < 0)) __pyx_t_40 = 0; + } else if (unlikely(__pyx_t_37 >= __pyx_bshape_0_data)) __pyx_t_40 = 0; + if (__pyx_t_38 < 0) { + __pyx_t_38 += __pyx_bshape_1_data; + if (unlikely(__pyx_t_38 < 0)) __pyx_t_40 = 1; + } else if (unlikely(__pyx_t_38 >= __pyx_bshape_1_data)) __pyx_t_40 = 1; + if (__pyx_t_39 < 0) { + __pyx_t_39 += __pyx_bshape_2_data; + if (unlikely(__pyx_t_39 < 0)) __pyx_t_40 = 2; + } else if (unlikely(__pyx_t_39 >= __pyx_bshape_2_data)) __pyx_t_40 = 2; + if (unlikely(__pyx_t_40 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_40); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_data.buf, __pyx_t_37, __pyx_bstride_0_data, __pyx_t_38, __pyx_bstride_1_data, __pyx_t_39, __pyx_bstride_2_data) = __pyx_v_temp_data; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":690 + * level][8*offset + odind] + * data[offi, offj, offk] = temp_data + * filled[offi, offj, offk] = 1 # <<<<<<<<<<<<<< + * to_fill += 1 + * return to_fill + */ + __pyx_t_40 = __pyx_v_offi; + __pyx_t_41 = __pyx_v_offj; + __pyx_t_42 = __pyx_v_offk; + __pyx_t_43 = -1; + if (__pyx_t_40 < 0) { + __pyx_t_40 += __pyx_bshape_0_filled; + if (unlikely(__pyx_t_40 < 0)) __pyx_t_43 = 0; + } else if (unlikely(__pyx_t_40 >= __pyx_bshape_0_filled)) __pyx_t_43 = 0; + if (__pyx_t_41 < 0) { + __pyx_t_41 += __pyx_bshape_1_filled; + if (unlikely(__pyx_t_41 < 0)) __pyx_t_43 = 1; + } else if (unlikely(__pyx_t_41 >= __pyx_bshape_1_filled)) __pyx_t_43 = 1; + if (__pyx_t_42 < 0) { + __pyx_t_42 += __pyx_bshape_2_filled; + if (unlikely(__pyx_t_42 < 0)) __pyx_t_43 = 2; + } else if (unlikely(__pyx_t_42 >= __pyx_bshape_2_filled)) __pyx_t_43 = 2; + if (unlikely(__pyx_t_43 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_43); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_filled.buf, __pyx_t_40, __pyx_bstride_0_filled, __pyx_t_41, __pyx_bstride_1_filled, __pyx_t_42, __pyx_bstride_2_filled) = 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":691 + * data[offi, offj, offk] = temp_data + * filled[offi, offj, offk] = 1 + * to_fill += 1 # <<<<<<<<<<<<<< + * return to_fill + * + */ + __pyx_v_to_fill += 1; + __pyx_L16_continue:; + } + __pyx_L13_continue:; + } + __pyx_L10_continue:; + } + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":692 + * filled[offi, offj, offk] = 1 + * to_fill += 1 + * return to_fill # <<<<<<<<<<<<<< + * + * cdef class ProtoSubgrid: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_13 = PyInt_FromLong(__pyx_v_to_fill); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_r = __pyx_t_13; + __pyx_t_13 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dims); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_og_start_index); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ogrid_info); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_filled); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_start_index); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy.read_grid"); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dims); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_og_start_index); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ogrid_info); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_filled); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_start_index); + __pyx_L2:; + __Pyx_DECREF((PyObject *)__pyx_v_ogrid_info); + __Pyx_DECREF((PyObject *)__pyx_v_og_start_index); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":699 + * cdef np.int64_t right_edge[3] + * cdef np.int64_t dimensions[3] + * cdef public np.float64_t efficiency # <<<<<<<<<<<<<< + * cdef public object sigs + * cdef public object grid_file_locations + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_10efficiency___get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_10efficiency___get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__"); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.ProtoSubgrid.efficiency.__get__"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_10efficiency___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_10efficiency___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __pyx_t_5numpy_float64_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__"); + __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_1 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.ProtoSubgrid.efficiency.__set__"); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":700 + * cdef np.int64_t dimensions[3] + * cdef public np.float64_t efficiency + * cdef public object sigs # <<<<<<<<<<<<<< + * cdef public object grid_file_locations + * cdef public object dd + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannySetupContext("__get__"); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + __pyx_r = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannySetupContext("__set__"); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannySetupContext("__del__"); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":701 + * cdef public np.float64_t efficiency + * cdef public object sigs + * cdef public object grid_file_locations # <<<<<<<<<<<<<< + * cdef public object dd + * + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannySetupContext("__get__"); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + __pyx_r = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannySetupContext("__set__"); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannySetupContext("__del__"); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":702 + * cdef public object sigs + * cdef public object grid_file_locations + * cdef public object dd # <<<<<<<<<<<<<< + * + * @cython.boundscheck(False) + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannySetupContext("__get__"); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + __pyx_r = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannySetupContext("__set__"); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannySetupContext("__del__"); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":706 + * @cython.boundscheck(False) + * @cython.wraparound(False) + * def __cinit__(self, # <<<<<<<<<<<<<< + * np.ndarray[np.int64_t, ndim=1] left_index, + * np.ndarray[np.int64_t, ndim=1] dimensions, + */ + +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyArrayObject *__pyx_v_left_index = 0; + PyArrayObject *__pyx_v_dimensions = 0; + PyArrayObject *__pyx_v_left_edges = 0; + PyArrayObject *__pyx_v_right_edges = 0; + PyArrayObject *__pyx_v_grid_dimensions = 0; + PyArrayObject *__pyx_v_grid_file_locations = 0; + int __pyx_v_i; + int __pyx_v_ng; + int __pyx_v_l0; + int __pyx_v_l1; + int __pyx_v_l2; + int __pyx_v_i0; + int __pyx_v_i1; + int __pyx_v_i2; + __pyx_t_5numpy_int64_t __pyx_v_temp_l[3]; + __pyx_t_5numpy_int64_t __pyx_v_temp_r[3]; + __pyx_t_5numpy_float64_t __pyx_v_efficiency; + int __pyx_v_gi; + PyArrayObject *__pyx_v_sig0; + PyArrayObject *__pyx_v_sig1; + PyArrayObject *__pyx_v_sig2; + int __pyx_v_used; + long __pyx_v_nnn; + Py_buffer __pyx_bstruct_right_edges; + Py_ssize_t __pyx_bstride_0_right_edges = 0; + Py_ssize_t __pyx_bstride_1_right_edges = 0; + Py_ssize_t __pyx_bshape_0_right_edges = 0; + Py_ssize_t __pyx_bshape_1_right_edges = 0; + Py_buffer __pyx_bstruct_left_index; + Py_ssize_t __pyx_bstride_0_left_index = 0; + Py_ssize_t __pyx_bshape_0_left_index = 0; + Py_buffer __pyx_bstruct_dimensions; + Py_ssize_t __pyx_bstride_0_dimensions = 0; + Py_ssize_t __pyx_bshape_0_dimensions = 0; + Py_buffer __pyx_bstruct_grid_file_locations; + Py_ssize_t __pyx_bstride_0_grid_file_locations = 0; + Py_ssize_t __pyx_bstride_1_grid_file_locations = 0; + Py_ssize_t __pyx_bshape_0_grid_file_locations = 0; + Py_ssize_t __pyx_bshape_1_grid_file_locations = 0; + Py_buffer __pyx_bstruct_grid_dimensions; + Py_ssize_t __pyx_bstride_0_grid_dimensions = 0; + Py_ssize_t __pyx_bstride_1_grid_dimensions = 0; + Py_ssize_t __pyx_bshape_0_grid_dimensions = 0; + Py_ssize_t __pyx_bshape_1_grid_dimensions = 0; + Py_buffer __pyx_bstruct_sig1; + Py_ssize_t __pyx_bstride_0_sig1 = 0; + Py_ssize_t __pyx_bshape_0_sig1 = 0; + Py_buffer __pyx_bstruct_sig2; + Py_ssize_t __pyx_bstride_0_sig2 = 0; + Py_ssize_t __pyx_bshape_0_sig2 = 0; + Py_buffer __pyx_bstruct_sig0; + Py_ssize_t __pyx_bstride_0_sig0 = 0; + Py_ssize_t __pyx_bshape_0_sig0 = 0; + Py_buffer __pyx_bstruct_left_edges; + Py_ssize_t __pyx_bstride_0_left_edges = 0; + Py_ssize_t __pyx_bstride_1_left_edges = 0; + Py_ssize_t __pyx_bshape_0_left_edges = 0; + Py_ssize_t __pyx_bshape_1_left_edges = 0; + int __pyx_r; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + long __pyx_t_8; + long __pyx_t_9; + long __pyx_t_10; + int __pyx_t_11; + int __pyx_t_12; + long __pyx_t_13; + long __pyx_t_14; + int __pyx_t_15; + int __pyx_t_16; + long __pyx_t_17; + long __pyx_t_18; + long __pyx_t_19; + int __pyx_t_20; + int __pyx_t_21; + long __pyx_t_22; + long __pyx_t_23; + int __pyx_t_24; + int __pyx_t_25; + long __pyx_t_26; + long __pyx_t_27; + long __pyx_t_28; + int __pyx_t_29; + int __pyx_t_30; + long __pyx_t_31; + long __pyx_t_32; + int __pyx_t_33; + int __pyx_t_34; + int __pyx_t_35; + int __pyx_t_36; + int __pyx_t_37; + int __pyx_t_38; + int __pyx_t_39; + int __pyx_t_40; + PyObject *__pyx_t_41 = NULL; + PyObject *__pyx_t_42 = NULL; + PyArrayObject *__pyx_t_43 = NULL; + PyObject *__pyx_t_44 = NULL; + PyObject *__pyx_t_45 = NULL; + PyObject *__pyx_t_46 = NULL; + int __pyx_t_47; + int __pyx_t_48; + long __pyx_t_49; + __pyx_t_5numpy_int64_t __pyx_t_50; + int __pyx_t_51; + int __pyx_t_52; + long __pyx_t_53; + int __pyx_t_54; + long __pyx_t_55; + __pyx_t_5numpy_int64_t __pyx_t_56; + int __pyx_t_57; + int __pyx_t_58; + long __pyx_t_59; + int __pyx_t_60; + long __pyx_t_61; + __pyx_t_5numpy_int64_t __pyx_t_62; + int __pyx_t_63; + int __pyx_t_64; + long __pyx_t_65; + int __pyx_t_66; + int __pyx_t_67; + int __pyx_t_68; + long __pyx_t_69; + long __pyx_t_70; + long __pyx_t_71; + int __pyx_t_72; + long __pyx_t_73; + int __pyx_t_74; + long __pyx_t_75; + int __pyx_t_76; + long __pyx_t_77; + PyObject *__pyx_t_78 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__left_index,&__pyx_n_s__dimensions,&__pyx_n_s__left_edges,&__pyx_n_s__right_edges,&__pyx_n_s__grid_dimensions,&__pyx_n_s__grid_file_locations,0}; + __Pyx_RefNannySetupContext("__cinit__"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[6] = {0,0,0,0,0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_index); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dimensions); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edges); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edges); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_dimensions); + if (likely(values[4])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 5: + values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_file_locations); + if (likely(values[5])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_left_index = ((PyArrayObject *)values[0]); + __pyx_v_dimensions = ((PyArrayObject *)values[1]); + __pyx_v_left_edges = ((PyArrayObject *)values[2]); + __pyx_v_right_edges = ((PyArrayObject *)values[3]); + __pyx_v_grid_dimensions = ((PyArrayObject *)values[4]); + __pyx_v_grid_file_locations = ((PyArrayObject *)values[5]); + } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_left_index = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); + __pyx_v_dimensions = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); + __pyx_v_left_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); + __pyx_v_right_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); + __pyx_v_grid_dimensions = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); + __pyx_v_grid_file_locations = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.ProtoSubgrid.__cinit__"); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_v_sig0 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_sig1 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_sig2 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_bstruct_sig0.buf = NULL; + __pyx_bstruct_sig1.buf = NULL; + __pyx_bstruct_sig2.buf = NULL; + __pyx_bstruct_left_index.buf = NULL; + __pyx_bstruct_dimensions.buf = NULL; + __pyx_bstruct_left_edges.buf = NULL; + __pyx_bstruct_right_edges.buf = NULL; + __pyx_bstruct_grid_dimensions.buf = NULL; + __pyx_bstruct_grid_file_locations.buf = NULL; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_index), __pyx_ptype_5numpy_ndarray, 1, "left_index", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dimensions), __pyx_ptype_5numpy_ndarray, 1, "dimensions", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edges), __pyx_ptype_5numpy_ndarray, 1, "left_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edges), __pyx_ptype_5numpy_ndarray, 1, "right_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_dimensions), __pyx_ptype_5numpy_ndarray, 1, "grid_dimensions", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_file_locations), __pyx_ptype_5numpy_ndarray, 1, "grid_file_locations", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_index, (PyObject*)__pyx_v_left_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_left_index = __pyx_bstruct_left_index.strides[0]; + __pyx_bshape_0_left_index = __pyx_bstruct_left_index.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dimensions, (PyObject*)__pyx_v_dimensions, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_dimensions = __pyx_bstruct_dimensions.strides[0]; + __pyx_bshape_0_dimensions = __pyx_bstruct_dimensions.shape[0]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edges, (PyObject*)__pyx_v_left_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_left_edges = __pyx_bstruct_left_edges.strides[0]; __pyx_bstride_1_left_edges = __pyx_bstruct_left_edges.strides[1]; + __pyx_bshape_0_left_edges = __pyx_bstruct_left_edges.shape[0]; __pyx_bshape_1_left_edges = __pyx_bstruct_left_edges.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edges, (PyObject*)__pyx_v_right_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_right_edges = __pyx_bstruct_right_edges.strides[0]; __pyx_bstride_1_right_edges = __pyx_bstruct_right_edges.strides[1]; + __pyx_bshape_0_right_edges = __pyx_bstruct_right_edges.shape[0]; __pyx_bshape_1_right_edges = __pyx_bstruct_right_edges.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_dimensions, (PyObject*)__pyx_v_grid_dimensions, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_grid_dimensions = __pyx_bstruct_grid_dimensions.strides[0]; __pyx_bstride_1_grid_dimensions = __pyx_bstruct_grid_dimensions.strides[1]; + __pyx_bshape_0_grid_dimensions = __pyx_bstruct_grid_dimensions.shape[0]; __pyx_bshape_1_grid_dimensions = __pyx_bstruct_grid_dimensions.shape[1]; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_file_locations, (PyObject*)__pyx_v_grid_file_locations, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_bstride_0_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[0]; __pyx_bstride_1_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[1]; + __pyx_bshape_0_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[0]; __pyx_bshape_1_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[1]; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":714 + * np.ndarray[np.int64_t, ndim=2] grid_file_locations): + * # This also includes the shrinking step. + * cdef int i, ci, ng = left_edges.shape[0] # <<<<<<<<<<<<<< + * cdef np.ndarray temp_arr + * cdef int l0, r0, l1, r1, l2, r2, i0, i1, i2 + */ + __pyx_v_ng = (__pyx_v_left_edges->dimensions[0]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":719 + * cdef np.int64_t temp_l[3], temp_r[3], ncells + * cdef np.float64_t efficiency + * self.sigs = [] # <<<<<<<<<<<<<< + * for i in range(3): + * temp_l[i] = left_index[i] + dimensions[i] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":720 + * cdef np.float64_t efficiency + * self.sigs = [] + * for i in range(3): # <<<<<<<<<<<<<< + * temp_l[i] = left_index[i] + dimensions[i] + * temp_r[i] = left_index[i] + */ + for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":721 + * self.sigs = [] + * for i in range(3): + * temp_l[i] = left_index[i] + dimensions[i] # <<<<<<<<<<<<<< + * temp_r[i] = left_index[i] + * self.signature[i] = NULL + */ + __pyx_t_3 = __pyx_v_i; + __pyx_t_4 = __pyx_v_i; + (__pyx_v_temp_l[__pyx_v_i]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_3, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_4, __pyx_bstride_0_dimensions))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":722 + * for i in range(3): + * temp_l[i] = left_index[i] + dimensions[i] + * temp_r[i] = left_index[i] # <<<<<<<<<<<<<< + * self.signature[i] = NULL + * for gi in range(ng): + */ + __pyx_t_5 = __pyx_v_i; + (__pyx_v_temp_r[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_5, __pyx_bstride_0_left_index)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":723 + * temp_l[i] = left_index[i] + dimensions[i] + * temp_r[i] = left_index[i] + * self.signature[i] = NULL # <<<<<<<<<<<<<< + * for gi in range(ng): + * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ + */ + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->signature[__pyx_v_i]) = NULL; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":724 + * temp_r[i] = left_index[i] + * self.signature[i] = NULL + * for gi in range(ng): # <<<<<<<<<<<<<< + * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ + * right_edges[gi,0] < left_index[0] or \ + */ + __pyx_t_2 = __pyx_v_ng; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_2; __pyx_t_6+=1) { + __pyx_v_gi = __pyx_t_6; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":725 + * self.signature[i] = NULL + * for gi in range(ng): + * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ # <<<<<<<<<<<<<< + * right_edges[gi,0] < left_index[0] or \ + * left_edges[gi,1] > left_index[1]+dimensions[1] or \ + */ + __pyx_t_7 = __pyx_v_gi; + __pyx_t_8 = 0; + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_11 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_7, __pyx_bstride_0_left_edges, __pyx_t_8, __pyx_bstride_1_left_edges)) > ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_9, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_10, __pyx_bstride_0_dimensions)))); + if (!__pyx_t_11) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":726 + * for gi in range(ng): + * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ + * right_edges[gi,0] < left_index[0] or \ # <<<<<<<<<<<<<< + * left_edges[gi,1] > left_index[1]+dimensions[1] or \ + * right_edges[gi,1] < left_index[1] or \ + */ + __pyx_t_12 = __pyx_v_gi; + __pyx_t_13 = 0; + __pyx_t_14 = 0; + __pyx_t_15 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_12, __pyx_bstride_0_right_edges, __pyx_t_13, __pyx_bstride_1_right_edges)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_14, __pyx_bstride_0_left_index))); + if (!__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":727 + * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ + * right_edges[gi,0] < left_index[0] or \ + * left_edges[gi,1] > left_index[1]+dimensions[1] or \ # <<<<<<<<<<<<<< + * right_edges[gi,1] < left_index[1] or \ + * left_edges[gi,2] > left_index[2]+dimensions[2] or \ + */ + __pyx_t_16 = __pyx_v_gi; + __pyx_t_17 = 1; + __pyx_t_18 = 1; + __pyx_t_19 = 1; + __pyx_t_20 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_16, __pyx_bstride_0_left_edges, __pyx_t_17, __pyx_bstride_1_left_edges)) > ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_18, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_19, __pyx_bstride_0_dimensions)))); + if (!__pyx_t_20) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":728 + * right_edges[gi,0] < left_index[0] or \ + * left_edges[gi,1] > left_index[1]+dimensions[1] or \ + * right_edges[gi,1] < left_index[1] or \ # <<<<<<<<<<<<<< + * left_edges[gi,2] > left_index[2]+dimensions[2] or \ + * right_edges[gi,2] < left_index[2]: + */ + __pyx_t_21 = __pyx_v_gi; + __pyx_t_22 = 1; + __pyx_t_23 = 1; + __pyx_t_24 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_21, __pyx_bstride_0_right_edges, __pyx_t_22, __pyx_bstride_1_right_edges)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_23, __pyx_bstride_0_left_index))); + if (!__pyx_t_24) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":729 + * left_edges[gi,1] > left_index[1]+dimensions[1] or \ + * right_edges[gi,1] < left_index[1] or \ + * left_edges[gi,2] > left_index[2]+dimensions[2] or \ # <<<<<<<<<<<<<< + * right_edges[gi,2] < left_index[2]: + * #print "Skipping grid", gi, "which lies outside out box" + */ + __pyx_t_25 = __pyx_v_gi; + __pyx_t_26 = 2; + __pyx_t_27 = 2; + __pyx_t_28 = 2; + __pyx_t_29 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_25, __pyx_bstride_0_left_edges, __pyx_t_26, __pyx_bstride_1_left_edges)) > ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_27, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_28, __pyx_bstride_0_dimensions)))); + if (!__pyx_t_29) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":730 + * right_edges[gi,1] < left_index[1] or \ + * left_edges[gi,2] > left_index[2]+dimensions[2] or \ + * right_edges[gi,2] < left_index[2]: # <<<<<<<<<<<<<< + * #print "Skipping grid", gi, "which lies outside out box" + * continue + */ + __pyx_t_30 = __pyx_v_gi; + __pyx_t_31 = 2; + __pyx_t_32 = 2; + __pyx_t_33 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_30, __pyx_bstride_0_right_edges, __pyx_t_31, __pyx_bstride_1_right_edges)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_32, __pyx_bstride_0_left_index))); + __pyx_t_34 = __pyx_t_33; + } else { + __pyx_t_34 = __pyx_t_29; + } + __pyx_t_29 = __pyx_t_34; + } else { + __pyx_t_29 = __pyx_t_24; + } + __pyx_t_24 = __pyx_t_29; + } else { + __pyx_t_24 = __pyx_t_20; + } + __pyx_t_20 = __pyx_t_24; + } else { + __pyx_t_20 = __pyx_t_15; + } + __pyx_t_15 = __pyx_t_20; + } else { + __pyx_t_15 = __pyx_t_11; + } + if (__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":732 + * right_edges[gi,2] < left_index[2]: + * #print "Skipping grid", gi, "which lies outside out box" + * continue # <<<<<<<<<<<<<< + * for i in range(3): + * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) + */ + goto __pyx_L8_continue; + goto __pyx_L10; + } + __pyx_L10:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":733 + * #print "Skipping grid", gi, "which lies outside out box" + * continue + * for i in range(3): # <<<<<<<<<<<<<< + * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) + * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) + */ + for (__pyx_t_35 = 0; __pyx_t_35 < 3; __pyx_t_35+=1) { + __pyx_v_i = __pyx_t_35; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":734 + * continue + * for i in range(3): + * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) # <<<<<<<<<<<<<< + * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) + * for i in range(3): + */ + __pyx_t_36 = __pyx_v_gi; + __pyx_t_37 = __pyx_v_i; + (__pyx_v_temp_l[__pyx_v_i]) = __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64min((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_36, __pyx_bstride_0_left_edges, __pyx_t_37, __pyx_bstride_1_left_edges)), (__pyx_v_temp_l[__pyx_v_i])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":735 + * for i in range(3): + * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) + * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) # <<<<<<<<<<<<<< + * for i in range(3): + * self.left_edge[i] = i64max(temp_l[i], left_index[i]) + */ + __pyx_t_38 = __pyx_v_gi; + __pyx_t_39 = __pyx_v_i; + (__pyx_v_temp_r[__pyx_v_i]) = __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64max((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_38, __pyx_bstride_0_right_edges, __pyx_t_39, __pyx_bstride_1_right_edges)), (__pyx_v_temp_r[__pyx_v_i])); + } + __pyx_L8_continue:; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":736 + * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) + * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) + * for i in range(3): # <<<<<<<<<<<<<< + * self.left_edge[i] = i64max(temp_l[i], left_index[i]) + * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) + */ + for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":737 + * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) + * for i in range(3): + * self.left_edge[i] = i64max(temp_l[i], left_index[i]) # <<<<<<<<<<<<<< + * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) + * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] + */ + __pyx_t_6 = __pyx_v_i; + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[__pyx_v_i]) = __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64max((__pyx_v_temp_l[__pyx_v_i]), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_6, __pyx_bstride_0_left_index))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":738 + * for i in range(3): + * self.left_edge[i] = i64max(temp_l[i], left_index[i]) + * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) # <<<<<<<<<<<<<< + * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] + * if self.dimensions[i] <= 0: + */ + __pyx_t_35 = __pyx_v_i; + __pyx_t_40 = __pyx_v_i; + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[__pyx_v_i]) = __pyx_f_2yt_9frontends_6ramses_14_ramses_reader_i64min((__pyx_v_temp_r[__pyx_v_i]), ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_35, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_40, __pyx_bstride_0_dimensions)))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":739 + * self.left_edge[i] = i64max(temp_l[i], left_index[i]) + * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) + * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] # <<<<<<<<<<<<<< + * if self.dimensions[i] <= 0: + * self.efficiency = -1.0 + */ + (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]) = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[__pyx_v_i]) - (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[__pyx_v_i])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":740 + * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) + * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] + * if self.dimensions[i] <= 0: # <<<<<<<<<<<<<< + * self.efficiency = -1.0 + * return + */ + __pyx_t_15 = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]) <= 0); + if (__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":741 + * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] + * if self.dimensions[i] <= 0: + * self.efficiency = -1.0 # <<<<<<<<<<<<<< + * return + * self.sigs.append(np.zeros(self.dimensions[i], 'int64')) + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency = (-1.0); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":742 + * if self.dimensions[i] <= 0: + * self.efficiency = -1.0 + * return # <<<<<<<<<<<<<< + * self.sigs.append(np.zeros(self.dimensions[i], 'int64')) + * #print self.sigs[0].size, self.sigs[1].size, self.sigs[2].size + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":743 + * self.efficiency = -1.0 + * return + * self.sigs.append(np.zeros(self.dimensions[i], 'int64')) # <<<<<<<<<<<<<< + * #print self.sigs[0].size, self.sigs[1].size, self.sigs[2].size + * + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_41 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_41); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_42 = PyTuple_New(2); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_42); + PyTuple_SET_ITEM(__pyx_t_42, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_n_s__int64)); + PyTuple_SET_ITEM(__pyx_t_42, 1, ((PyObject *)__pyx_n_s__int64)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__int64)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_41, __pyx_t_42, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_41); __pyx_t_41 = 0; + __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; + __pyx_t_42 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, __pyx_t_1); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 743; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_42); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":750 + * # pass. + * cdef np.ndarray[np.int64_t, ndim=1] sig0, sig1, sig2 + * sig0 = self.sigs[0] # <<<<<<<<<<<<<< + * sig1 = self.sigs[1] + * sig2 = self.sigs[2] + */ + __pyx_t_42 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_42) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_42); + if (!(likely(((__pyx_t_42) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_42, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_43 = ((PyArrayObject *)__pyx_t_42); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig0); + __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig0, (PyObject*)__pyx_t_43, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_2 < 0)) { + PyErr_Fetch(&__pyx_t_44, &__pyx_t_45, &__pyx_t_46); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig0, (PyObject*)__pyx_v_sig0, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_44); Py_XDECREF(__pyx_t_45); Py_XDECREF(__pyx_t_46); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_44, __pyx_t_45, __pyx_t_46); + } + } + __pyx_bstride_0_sig0 = __pyx_bstruct_sig0.strides[0]; + __pyx_bshape_0_sig0 = __pyx_bstruct_sig0.shape[0]; + if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_43 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_sig0)); + __pyx_v_sig0 = ((PyArrayObject *)__pyx_t_42); + __pyx_t_42 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":751 + * cdef np.ndarray[np.int64_t, ndim=1] sig0, sig1, sig2 + * sig0 = self.sigs[0] + * sig1 = self.sigs[1] # <<<<<<<<<<<<<< + * sig2 = self.sigs[2] + * efficiency = 0.0 + */ + __pyx_t_42 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_42) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_42); + if (!(likely(((__pyx_t_42) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_42, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_43 = ((PyArrayObject *)__pyx_t_42); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig1); + __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig1, (PyObject*)__pyx_t_43, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_2 < 0)) { + PyErr_Fetch(&__pyx_t_46, &__pyx_t_45, &__pyx_t_44); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig1, (PyObject*)__pyx_v_sig1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_46); Py_XDECREF(__pyx_t_45); Py_XDECREF(__pyx_t_44); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_46, __pyx_t_45, __pyx_t_44); + } + } + __pyx_bstride_0_sig1 = __pyx_bstruct_sig1.strides[0]; + __pyx_bshape_0_sig1 = __pyx_bstruct_sig1.shape[0]; + if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_43 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_sig1)); + __pyx_v_sig1 = ((PyArrayObject *)__pyx_t_42); + __pyx_t_42 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":752 + * sig0 = self.sigs[0] + * sig1 = self.sigs[1] + * sig2 = self.sigs[2] # <<<<<<<<<<<<<< + * efficiency = 0.0 + * cdef int used + */ + __pyx_t_42 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_42) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_42); + if (!(likely(((__pyx_t_42) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_42, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_43 = ((PyArrayObject *)__pyx_t_42); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig2); + __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig2, (PyObject*)__pyx_t_43, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_2 < 0)) { + PyErr_Fetch(&__pyx_t_44, &__pyx_t_45, &__pyx_t_46); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig2, (PyObject*)__pyx_v_sig2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_44); Py_XDECREF(__pyx_t_45); Py_XDECREF(__pyx_t_46); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_44, __pyx_t_45, __pyx_t_46); + } + } + __pyx_bstride_0_sig2 = __pyx_bstruct_sig2.strides[0]; + __pyx_bshape_0_sig2 = __pyx_bstruct_sig2.shape[0]; + if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_43 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_sig2)); + __pyx_v_sig2 = ((PyArrayObject *)__pyx_t_42); + __pyx_t_42 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":753 + * sig1 = self.sigs[1] + * sig2 = self.sigs[2] + * efficiency = 0.0 # <<<<<<<<<<<<<< + * cdef int used + * self.grid_file_locations = [] + */ + __pyx_v_efficiency = 0.0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":755 + * efficiency = 0.0 + * cdef int used + * self.grid_file_locations = [] # <<<<<<<<<<<<<< + * for gi in range(ng): + * used = 0 + */ + __pyx_t_42 = PyList_New(0); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_42)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_42)); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations = ((PyObject *)__pyx_t_42); + __pyx_t_42 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":756 + * cdef int used + * self.grid_file_locations = [] + * for gi in range(ng): # <<<<<<<<<<<<<< + * used = 0 + * nnn = 0 + */ + __pyx_t_2 = __pyx_v_ng; + for (__pyx_t_47 = 0; __pyx_t_47 < __pyx_t_2; __pyx_t_47+=1) { + __pyx_v_gi = __pyx_t_47; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":757 + * self.grid_file_locations = [] + * for gi in range(ng): + * used = 0 # <<<<<<<<<<<<<< + * nnn = 0 + * for l0 in range(grid_dimensions[gi, 0]): + */ + __pyx_v_used = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":758 + * for gi in range(ng): + * used = 0 + * nnn = 0 # <<<<<<<<<<<<<< + * for l0 in range(grid_dimensions[gi, 0]): + * i0 = left_edges[gi, 0] + l0 + */ + __pyx_v_nnn = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":759 + * used = 0 + * nnn = 0 + * for l0 in range(grid_dimensions[gi, 0]): # <<<<<<<<<<<<<< + * i0 = left_edges[gi, 0] + l0 + * if i0 < self.left_edge[0]: continue + */ + __pyx_t_48 = __pyx_v_gi; + __pyx_t_49 = 0; + __pyx_t_50 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_dimensions.buf, __pyx_t_48, __pyx_bstride_0_grid_dimensions, __pyx_t_49, __pyx_bstride_1_grid_dimensions)); + for (__pyx_t_51 = 0; __pyx_t_51 < __pyx_t_50; __pyx_t_51+=1) { + __pyx_v_l0 = __pyx_t_51; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":760 + * nnn = 0 + * for l0 in range(grid_dimensions[gi, 0]): + * i0 = left_edges[gi, 0] + l0 # <<<<<<<<<<<<<< + * if i0 < self.left_edge[0]: continue + * if i0 >= self.right_edge[0]: break + */ + __pyx_t_52 = __pyx_v_gi; + __pyx_t_53 = 0; + __pyx_v_i0 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_52, __pyx_bstride_0_left_edges, __pyx_t_53, __pyx_bstride_1_left_edges)) + __pyx_v_l0); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":761 + * for l0 in range(grid_dimensions[gi, 0]): + * i0 = left_edges[gi, 0] + l0 + * if i0 < self.left_edge[0]: continue # <<<<<<<<<<<<<< + * if i0 >= self.right_edge[0]: break + * for l1 in range(grid_dimensions[gi, 1]): + */ + __pyx_t_15 = (__pyx_v_i0 < (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[0])); + if (__pyx_t_15) { + goto __pyx_L18_continue; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":762 + * i0 = left_edges[gi, 0] + l0 + * if i0 < self.left_edge[0]: continue + * if i0 >= self.right_edge[0]: break # <<<<<<<<<<<<<< + * for l1 in range(grid_dimensions[gi, 1]): + * i1 = left_edges[gi, 1] + l1 + */ + __pyx_t_15 = (__pyx_v_i0 >= (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[0])); + if (__pyx_t_15) { + goto __pyx_L19_break; + goto __pyx_L21; + } + __pyx_L21:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":763 + * if i0 < self.left_edge[0]: continue + * if i0 >= self.right_edge[0]: break + * for l1 in range(grid_dimensions[gi, 1]): # <<<<<<<<<<<<<< + * i1 = left_edges[gi, 1] + l1 + * if i1 < self.left_edge[1]: continue + */ + __pyx_t_54 = __pyx_v_gi; + __pyx_t_55 = 1; + __pyx_t_56 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_dimensions.buf, __pyx_t_54, __pyx_bstride_0_grid_dimensions, __pyx_t_55, __pyx_bstride_1_grid_dimensions)); + for (__pyx_t_57 = 0; __pyx_t_57 < __pyx_t_56; __pyx_t_57+=1) { + __pyx_v_l1 = __pyx_t_57; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":764 + * if i0 >= self.right_edge[0]: break + * for l1 in range(grid_dimensions[gi, 1]): + * i1 = left_edges[gi, 1] + l1 # <<<<<<<<<<<<<< + * if i1 < self.left_edge[1]: continue + * if i1 >= self.right_edge[1]: break + */ + __pyx_t_58 = __pyx_v_gi; + __pyx_t_59 = 1; + __pyx_v_i1 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_58, __pyx_bstride_0_left_edges, __pyx_t_59, __pyx_bstride_1_left_edges)) + __pyx_v_l1); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":765 + * for l1 in range(grid_dimensions[gi, 1]): + * i1 = left_edges[gi, 1] + l1 + * if i1 < self.left_edge[1]: continue # <<<<<<<<<<<<<< + * if i1 >= self.right_edge[1]: break + * for l2 in range(grid_dimensions[gi, 2]): + */ + __pyx_t_15 = (__pyx_v_i1 < (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[1])); + if (__pyx_t_15) { + goto __pyx_L22_continue; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":766 + * i1 = left_edges[gi, 1] + l1 + * if i1 < self.left_edge[1]: continue + * if i1 >= self.right_edge[1]: break # <<<<<<<<<<<<<< + * for l2 in range(grid_dimensions[gi, 2]): + * i2 = left_edges[gi, 2] + l2 + */ + __pyx_t_15 = (__pyx_v_i1 >= (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[1])); + if (__pyx_t_15) { + goto __pyx_L23_break; + goto __pyx_L25; + } + __pyx_L25:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":767 + * if i1 < self.left_edge[1]: continue + * if i1 >= self.right_edge[1]: break + * for l2 in range(grid_dimensions[gi, 2]): # <<<<<<<<<<<<<< + * i2 = left_edges[gi, 2] + l2 + * if i2 < self.left_edge[2]: continue + */ + __pyx_t_60 = __pyx_v_gi; + __pyx_t_61 = 2; + __pyx_t_62 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_dimensions.buf, __pyx_t_60, __pyx_bstride_0_grid_dimensions, __pyx_t_61, __pyx_bstride_1_grid_dimensions)); + for (__pyx_t_63 = 0; __pyx_t_63 < __pyx_t_62; __pyx_t_63+=1) { + __pyx_v_l2 = __pyx_t_63; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":768 + * if i1 >= self.right_edge[1]: break + * for l2 in range(grid_dimensions[gi, 2]): + * i2 = left_edges[gi, 2] + l2 # <<<<<<<<<<<<<< + * if i2 < self.left_edge[2]: continue + * if i2 >= self.right_edge[2]: break + */ + __pyx_t_64 = __pyx_v_gi; + __pyx_t_65 = 2; + __pyx_v_i2 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_64, __pyx_bstride_0_left_edges, __pyx_t_65, __pyx_bstride_1_left_edges)) + __pyx_v_l2); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":769 + * for l2 in range(grid_dimensions[gi, 2]): + * i2 = left_edges[gi, 2] + l2 + * if i2 < self.left_edge[2]: continue # <<<<<<<<<<<<<< + * if i2 >= self.right_edge[2]: break + * i = i0 - self.left_edge[0] + */ + __pyx_t_15 = (__pyx_v_i2 < (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[2])); + if (__pyx_t_15) { + goto __pyx_L26_continue; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":770 + * i2 = left_edges[gi, 2] + l2 + * if i2 < self.left_edge[2]: continue + * if i2 >= self.right_edge[2]: break # <<<<<<<<<<<<<< + * i = i0 - self.left_edge[0] + * sig0[i] += 1 + */ + __pyx_t_15 = (__pyx_v_i2 >= (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[2])); + if (__pyx_t_15) { + goto __pyx_L27_break; + goto __pyx_L29; + } + __pyx_L29:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":771 + * if i2 < self.left_edge[2]: continue + * if i2 >= self.right_edge[2]: break + * i = i0 - self.left_edge[0] # <<<<<<<<<<<<<< + * sig0[i] += 1 + * i = i1 - self.left_edge[1] + */ + __pyx_v_i = (__pyx_v_i0 - (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[0])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":772 + * if i2 >= self.right_edge[2]: break + * i = i0 - self.left_edge[0] + * sig0[i] += 1 # <<<<<<<<<<<<<< + * i = i1 - self.left_edge[1] + * sig1[i] += 1 + */ + __pyx_t_66 = __pyx_v_i; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig0.buf, __pyx_t_66, __pyx_bstride_0_sig0) += 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":773 + * i = i0 - self.left_edge[0] + * sig0[i] += 1 + * i = i1 - self.left_edge[1] # <<<<<<<<<<<<<< + * sig1[i] += 1 + * i = i2 - self.left_edge[2] + */ + __pyx_v_i = (__pyx_v_i1 - (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[1])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":774 + * sig0[i] += 1 + * i = i1 - self.left_edge[1] + * sig1[i] += 1 # <<<<<<<<<<<<<< + * i = i2 - self.left_edge[2] + * sig2[i] += 1 + */ + __pyx_t_67 = __pyx_v_i; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig1.buf, __pyx_t_67, __pyx_bstride_0_sig1) += 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":775 + * i = i1 - self.left_edge[1] + * sig1[i] += 1 + * i = i2 - self.left_edge[2] # <<<<<<<<<<<<<< + * sig2[i] += 1 + * efficiency += 1 + */ + __pyx_v_i = (__pyx_v_i2 - (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[2])); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":776 + * sig1[i] += 1 + * i = i2 - self.left_edge[2] + * sig2[i] += 1 # <<<<<<<<<<<<<< + * efficiency += 1 + * used = 1 + */ + __pyx_t_68 = __pyx_v_i; + *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig2.buf, __pyx_t_68, __pyx_bstride_0_sig2) += 1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":777 + * i = i2 - self.left_edge[2] + * sig2[i] += 1 + * efficiency += 1 # <<<<<<<<<<<<<< + * used = 1 + * if used == 1: + */ + __pyx_v_efficiency += 1.0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":778 + * sig2[i] += 1 + * efficiency += 1 + * used = 1 # <<<<<<<<<<<<<< + * if used == 1: + * grid_file_locations[gi,3] = left_edges[gi, 0] + */ + __pyx_v_used = 1; + __pyx_L26_continue:; + } + __pyx_L27_break:; + __pyx_L22_continue:; + } + __pyx_L23_break:; + __pyx_L18_continue:; + } + __pyx_L19_break:; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":779 + * efficiency += 1 + * used = 1 + * if used == 1: # <<<<<<<<<<<<<< + * grid_file_locations[gi,3] = left_edges[gi, 0] + * grid_file_locations[gi,4] = left_edges[gi, 1] + */ + __pyx_t_15 = (__pyx_v_used == 1); + if (__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":780 + * used = 1 + * if used == 1: + * grid_file_locations[gi,3] = left_edges[gi, 0] # <<<<<<<<<<<<<< + * grid_file_locations[gi,4] = left_edges[gi, 1] + * grid_file_locations[gi,5] = left_edges[gi, 2] + */ + __pyx_t_51 = __pyx_v_gi; + __pyx_t_69 = 0; + __pyx_t_57 = __pyx_v_gi; + __pyx_t_70 = 3; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_57, __pyx_bstride_0_grid_file_locations, __pyx_t_70, __pyx_bstride_1_grid_file_locations) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_51, __pyx_bstride_0_left_edges, __pyx_t_69, __pyx_bstride_1_left_edges)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":781 + * if used == 1: + * grid_file_locations[gi,3] = left_edges[gi, 0] + * grid_file_locations[gi,4] = left_edges[gi, 1] # <<<<<<<<<<<<<< + * grid_file_locations[gi,5] = left_edges[gi, 2] + * self.grid_file_locations.append(grid_file_locations[gi,:]) + */ + __pyx_t_63 = __pyx_v_gi; + __pyx_t_71 = 1; + __pyx_t_72 = __pyx_v_gi; + __pyx_t_73 = 4; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_72, __pyx_bstride_0_grid_file_locations, __pyx_t_73, __pyx_bstride_1_grid_file_locations) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_63, __pyx_bstride_0_left_edges, __pyx_t_71, __pyx_bstride_1_left_edges)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":782 + * grid_file_locations[gi,3] = left_edges[gi, 0] + * grid_file_locations[gi,4] = left_edges[gi, 1] + * grid_file_locations[gi,5] = left_edges[gi, 2] # <<<<<<<<<<<<<< + * self.grid_file_locations.append(grid_file_locations[gi,:]) + * + */ + __pyx_t_74 = __pyx_v_gi; + __pyx_t_75 = 2; + __pyx_t_76 = __pyx_v_gi; + __pyx_t_77 = 5; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_76, __pyx_bstride_0_grid_file_locations, __pyx_t_77, __pyx_bstride_1_grid_file_locations) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_74, __pyx_bstride_0_left_edges, __pyx_t_75, __pyx_bstride_1_left_edges)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":783 + * grid_file_locations[gi,4] = left_edges[gi, 1] + * grid_file_locations[gi,5] = left_edges[gi, 2] + * self.grid_file_locations.append(grid_file_locations[gi,:]) # <<<<<<<<<<<<<< + * + * self.dd = np.ones(3, dtype='int64') + */ + __pyx_t_42 = PyInt_FromLong(__pyx_v_gi); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_42); + __pyx_t_1 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_41 = PyTuple_New(2); if (unlikely(!__pyx_t_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_41); + PyTuple_SET_ITEM(__pyx_t_41, 0, __pyx_t_42); + __Pyx_GIVEREF(__pyx_t_42); + PyTuple_SET_ITEM(__pyx_t_41, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_42 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_grid_file_locations), __pyx_t_41); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_41); __pyx_t_41 = 0; + __pyx_t_41 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations, __pyx_t_1); if (unlikely(!__pyx_t_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_41); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_41); __pyx_t_41 = 0; + goto __pyx_L30; + } + __pyx_L30:; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":785 + * self.grid_file_locations.append(grid_file_locations[gi,:]) + * + * self.dd = np.ones(3, dtype='int64') # <<<<<<<<<<<<<< + * for i in range(3): + * efficiency /= self.dimensions[i] + */ + __pyx_t_41 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_41); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_41, __pyx_n_s__ones); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_41); __pyx_t_41 = 0; + __pyx_t_41 = PyTuple_New(1); if (unlikely(!__pyx_t_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_41); + __Pyx_INCREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_41, 0, __pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + __pyx_t_42 = PyDict_New(); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_42)); + if (PyDict_SetItem(__pyx_t_42, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int64)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_78 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_41, ((PyObject *)__pyx_t_42)); if (unlikely(!__pyx_t_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_78); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_41); __pyx_t_41 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_42)); __pyx_t_42 = 0; + __Pyx_GIVEREF(__pyx_t_78); + __Pyx_GOTREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + __Pyx_DECREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd = __pyx_t_78; + __pyx_t_78 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":786 + * + * self.dd = np.ones(3, dtype='int64') + * for i in range(3): # <<<<<<<<<<<<<< + * efficiency /= self.dimensions[i] + * self.dd[i] = self.dimensions[i] + */ + for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":787 + * self.dd = np.ones(3, dtype='int64') + * for i in range(3): + * efficiency /= self.dimensions[i] # <<<<<<<<<<<<<< + * self.dd[i] = self.dimensions[i] + * #print "Efficiency is %0.3e" % (efficiency) + */ + __pyx_v_efficiency /= (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":788 + * for i in range(3): + * efficiency /= self.dimensions[i] + * self.dd[i] = self.dimensions[i] # <<<<<<<<<<<<<< + * #print "Efficiency is %0.3e" % (efficiency) + * self.efficiency = efficiency + */ + __pyx_t_78 = __Pyx_PyInt_to_py_npy_int64((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i])); if (unlikely(!__pyx_t_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_78); + if (__Pyx_SetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd, __pyx_v_i, __pyx_t_78, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_78); __pyx_t_78 = 0; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":790 + * self.dd[i] = self.dimensions[i] + * #print "Efficiency is %0.3e" % (efficiency) + * self.efficiency = efficiency # <<<<<<<<<<<<<< + * + * @cython.boundscheck(False) + */ + ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency = __pyx_v_efficiency; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_41); + __Pyx_XDECREF(__pyx_t_42); + __Pyx_XDECREF(__pyx_t_78); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_index); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dimensions); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig1); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig2); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig0); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.ProtoSubgrid.__cinit__"); + __pyx_r = -1; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_index); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dimensions); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig1); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig2); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig0); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); + __pyx_L2:; + __Pyx_DECREF((PyObject *)__pyx_v_sig0); + __Pyx_DECREF((PyObject *)__pyx_v_sig1); + __Pyx_DECREF((PyObject *)__pyx_v_sig2); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":794 + * @cython.boundscheck(False) + * @cython.wraparound(False) + * def find_split(self): # <<<<<<<<<<<<<< + * # First look for zeros + * cdef int i, center, ax + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_find_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_find_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + int __pyx_v_i; + int __pyx_v_center; + int __pyx_v_ax; + PyArrayObject *__pyx_v_axes; + __pyx_t_5numpy_int64_t __pyx_v_strength; + __pyx_t_5numpy_int64_t __pyx_v_zcstrength; + __pyx_t_5numpy_int64_t __pyx_v_zcp; + PyArrayObject *__pyx_v_sig; + long __pyx_v_axi; + long __pyx_v_zca; + __pyx_t_5numpy_int64_t *__pyx_v_sig2d; + Py_buffer __pyx_bstruct_axes; + Py_ssize_t __pyx_bstride_0_axes = 0; + Py_ssize_t __pyx_bshape_0_axes = 0; + Py_buffer __pyx_bstruct_sig; + Py_ssize_t __pyx_bstride_0_sig = 0; + Py_ssize_t __pyx_bshape_0_sig = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyArrayObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + long __pyx_t_9; + long __pyx_t_10; + PyArrayObject *__pyx_t_11 = NULL; + __pyx_t_5numpy_int64_t __pyx_t_12; + int __pyx_t_13; + int __pyx_t_14; + int __pyx_t_15; + int __pyx_t_16; + int __pyx_t_17; + long __pyx_t_18; + long __pyx_t_19; + int __pyx_t_20; + long __pyx_t_21; + __Pyx_RefNannySetupContext("find_split"); + __pyx_v_axes = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_sig = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_bstruct_axes.buf = NULL; + __pyx_bstruct_sig.buf = NULL; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":799 + * cdef np.ndarray[ndim=1, dtype=np.int64_t] axes + * cdef np.int64_t strength, zcstrength, zcp + * axes = np.argsort(self.dd)[::-1] # <<<<<<<<<<<<<< + * cdef np.ndarray[np.int64_t] sig + * for axi in range(3): + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__argsort); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + __Pyx_GIVEREF(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); + __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetItem(__pyx_t_3, __pyx_t_1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((PyArrayObject *)__pyx_t_2); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_axes); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_axes, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_axes, (PyObject*)__pyx_v_axes, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8); + } + } + __pyx_bstride_0_axes = __pyx_bstruct_axes.strides[0]; + __pyx_bshape_0_axes = __pyx_bstruct_axes.shape[0]; + if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_axes)); + __pyx_v_axes = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":801 + * axes = np.argsort(self.dd)[::-1] + * cdef np.ndarray[np.int64_t] sig + * for axi in range(3): # <<<<<<<<<<<<<< + * ax = axes[axi] + * center = self.dimensions[ax] / 2 + */ + for (__pyx_t_9 = 0; __pyx_t_9 < 3; __pyx_t_9+=1) { + __pyx_v_axi = __pyx_t_9; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":802 + * cdef np.ndarray[np.int64_t] sig + * for axi in range(3): + * ax = axes[axi] # <<<<<<<<<<<<<< + * center = self.dimensions[ax] / 2 + * sig = self.sigs[ax] + */ + __pyx_t_10 = __pyx_v_axi; + __pyx_v_ax = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_axes.buf, __pyx_t_10, __pyx_bstride_0_axes)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":803 + * for axi in range(3): + * ax = axes[axi] + * center = self.dimensions[ax] / 2 # <<<<<<<<<<<<<< + * sig = self.sigs[ax] + * for i in range(self.dimensions[ax]): + */ + __pyx_v_center = __Pyx_div___pyx_t_5numpy_int64_t((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]), 2); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":804 + * ax = axes[axi] + * center = self.dimensions[ax] / 2 + * sig = self.sigs[ax] # <<<<<<<<<<<<<< + * for i in range(self.dimensions[ax]): + * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: + */ + __pyx_t_2 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, __pyx_v_ax, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_11 = ((PyArrayObject *)__pyx_t_2); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_v_sig, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6); + } + } + __pyx_bstride_0_sig = __pyx_bstruct_sig.strides[0]; + __pyx_bshape_0_sig = __pyx_bstruct_sig.shape[0]; + if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 804; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_sig)); + __pyx_v_sig = ((PyArrayObject *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":805 + * center = self.dimensions[ax] / 2 + * sig = self.sigs[ax] + * for i in range(self.dimensions[ax]): # <<<<<<<<<<<<<< + * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: + * #print "zero: %s (%s)" % (i, self.dimensions[ax]) + */ + __pyx_t_12 = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]); + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_12; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":806 + * sig = self.sigs[ax] + * for i in range(self.dimensions[ax]): + * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: # <<<<<<<<<<<<<< + * #print "zero: %s (%s)" % (i, self.dimensions[ax]) + * return 0, ax, i + */ + __pyx_t_13 = __pyx_v_i; + __pyx_t_14 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_13, __pyx_bstride_0_sig)) == 0); + if (__pyx_t_14) { + __pyx_t_15 = (__pyx_v_i > 0); + if (__pyx_t_15) { + __pyx_t_16 = (__pyx_v_i < ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1)); + __pyx_t_17 = __pyx_t_16; + } else { + __pyx_t_17 = __pyx_t_15; + } + __pyx_t_15 = __pyx_t_17; + } else { + __pyx_t_15 = __pyx_t_14; + } + if (__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":808 + * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: + * #print "zero: %s (%s)" % (i, self.dimensions[ax]) + * return 0, ax, i # <<<<<<<<<<<<<< + * zcstrength = 0 + * zcp = 0 + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong(__pyx_v_ax); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + } + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":809 + * #print "zero: %s (%s)" % (i, self.dimensions[ax]) + * return 0, ax, i + * zcstrength = 0 # <<<<<<<<<<<<<< + * zcp = 0 + * zca = -1 + */ + __pyx_v_zcstrength = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":810 + * return 0, ax, i + * zcstrength = 0 + * zcp = 0 # <<<<<<<<<<<<<< + * zca = -1 + * cdef int temp + */ + __pyx_v_zcp = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":811 + * zcstrength = 0 + * zcp = 0 + * zca = -1 # <<<<<<<<<<<<<< + * cdef int temp + * cdef np.int64_t *sig2d + */ + __pyx_v_zca = -1; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":814 + * cdef int temp + * cdef np.int64_t *sig2d + * for axi in range(3): # <<<<<<<<<<<<<< + * ax = axes[axi] + * sig = self.sigs[ax] + */ + for (__pyx_t_9 = 0; __pyx_t_9 < 3; __pyx_t_9+=1) { + __pyx_v_axi = __pyx_t_9; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":815 + * cdef np.int64_t *sig2d + * for axi in range(3): + * ax = axes[axi] # <<<<<<<<<<<<<< + * sig = self.sigs[ax] + * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) + */ + __pyx_t_18 = __pyx_v_axi; + __pyx_v_ax = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_axes.buf, __pyx_t_18, __pyx_bstride_0_axes)); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":816 + * for axi in range(3): + * ax = axes[axi] + * sig = self.sigs[ax] # <<<<<<<<<<<<<< + * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) + * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 + */ + __pyx_t_3 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, __pyx_v_ax, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_11 = ((PyArrayObject *)__pyx_t_3); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig); + __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); + if (unlikely(__pyx_t_5 < 0)) { + PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_v_sig, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { + Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); + __Pyx_RaiseBufferFallbackError(); + } else { + PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8); + } + } + __pyx_bstride_0_sig = __pyx_bstruct_sig.strides[0]; + __pyx_bshape_0_sig = __pyx_bstruct_sig.shape[0]; + if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_sig)); + __pyx_v_sig = ((PyArrayObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":817 + * ax = axes[axi] + * sig = self.sigs[ax] + * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) # <<<<<<<<<<<<<< + * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 + * for i in range(1, self.dimensions[ax] - 1): + */ + __pyx_v_sig2d = ((__pyx_t_5numpy_int64_t *)malloc(((sizeof(__pyx_t_5numpy_int64_t)) * (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax])))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":818 + * sig = self.sigs[ax] + * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) + * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 # <<<<<<<<<<<<<< + * for i in range(1, self.dimensions[ax] - 1): + * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] + */ + (__pyx_v_sig2d[0]) = 0; + (__pyx_v_sig2d[((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1)]) = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":819 + * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) + * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 + * for i in range(1, self.dimensions[ax] - 1): # <<<<<<<<<<<<<< + * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] + * for i in range(1, self.dimensions[ax] - 1): + */ + __pyx_t_12 = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1); + for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_12; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":820 + * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 + * for i in range(1, self.dimensions[ax] - 1): + * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] # <<<<<<<<<<<<<< + * for i in range(1, self.dimensions[ax] - 1): + * if sig2d[i] * sig2d[i+1] <= 0: + */ + __pyx_t_19 = (__pyx_v_i - 1); + __pyx_t_20 = __pyx_v_i; + __pyx_t_21 = (__pyx_v_i + 1); + (__pyx_v_sig2d[__pyx_v_i]) = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_19, __pyx_bstride_0_sig)) - (2 * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_20, __pyx_bstride_0_sig)))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_21, __pyx_bstride_0_sig))); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":821 + * for i in range(1, self.dimensions[ax] - 1): + * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] + * for i in range(1, self.dimensions[ax] - 1): # <<<<<<<<<<<<<< + * if sig2d[i] * sig2d[i+1] <= 0: + * strength = labs(sig2d[i] - sig2d[i+1]) + */ + __pyx_t_12 = ((((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1); + for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_12; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":822 + * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] + * for i in range(1, self.dimensions[ax] - 1): + * if sig2d[i] * sig2d[i+1] <= 0: # <<<<<<<<<<<<<< + * strength = labs(sig2d[i] - sig2d[i+1]) + * if (strength > zcstrength) or \ + */ + __pyx_t_15 = (((__pyx_v_sig2d[__pyx_v_i]) * (__pyx_v_sig2d[(__pyx_v_i + 1)])) <= 0); + if (__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":823 + * for i in range(1, self.dimensions[ax] - 1): + * if sig2d[i] * sig2d[i+1] <= 0: + * strength = labs(sig2d[i] - sig2d[i+1]) # <<<<<<<<<<<<<< + * if (strength > zcstrength) or \ + * (strength == zcstrength and (abs(center - i) < + */ + __pyx_v_strength = labs(((__pyx_v_sig2d[__pyx_v_i]) - (__pyx_v_sig2d[(__pyx_v_i + 1)]))); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":824 + * if sig2d[i] * sig2d[i+1] <= 0: + * strength = labs(sig2d[i] - sig2d[i+1]) + * if (strength > zcstrength) or \ # <<<<<<<<<<<<<< + * (strength == zcstrength and (abs(center - i) < + * abs(center - zcp))): + */ + __pyx_t_15 = (__pyx_v_strength > __pyx_v_zcstrength); + if (!__pyx_t_15) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":825 + * strength = labs(sig2d[i] - sig2d[i+1]) + * if (strength > zcstrength) or \ + * (strength == zcstrength and (abs(center - i) < # <<<<<<<<<<<<<< + * abs(center - zcp))): + * zcstrength = strength + */ + __pyx_t_14 = (__pyx_v_strength == __pyx_v_zcstrength); + if (__pyx_t_14) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":826 + * if (strength > zcstrength) or \ + * (strength == zcstrength and (abs(center - i) < + * abs(center - zcp))): # <<<<<<<<<<<<<< + * zcstrength = strength + * zcp = i + */ + __pyx_t_17 = (abs((__pyx_v_center - __pyx_v_i)) < abs((__pyx_v_center - __pyx_v_zcp))); + __pyx_t_16 = __pyx_t_17; + } else { + __pyx_t_16 = __pyx_t_14; + } + __pyx_t_14 = __pyx_t_16; + } else { + __pyx_t_14 = __pyx_t_15; + } + if (__pyx_t_14) { + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":827 + * (strength == zcstrength and (abs(center - i) < + * abs(center - zcp))): + * zcstrength = strength # <<<<<<<<<<<<<< + * zcp = i + * zca = ax + */ + __pyx_v_zcstrength = __pyx_v_strength; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":828 + * abs(center - zcp))): + * zcstrength = strength + * zcp = i # <<<<<<<<<<<<<< + * zca = ax + * free(sig2d) + */ + __pyx_v_zcp = __pyx_v_i; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":829 + * zcstrength = strength + * zcp = i + * zca = ax # <<<<<<<<<<<<<< + * free(sig2d) + * #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) + */ + __pyx_v_zca = __pyx_v_ax; + goto __pyx_L17; + } + __pyx_L17:; + goto __pyx_L16; + } + __pyx_L16:; + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":830 + * zcp = i + * zca = ax + * free(sig2d) # <<<<<<<<<<<<<< + * #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) + * return 1, ax, zcp + */ + free(__pyx_v_sig2d); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":832 + * free(sig2d) + * #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) + * return 1, ax, zcp # <<<<<<<<<<<<<< + * + * @cython.boundscheck(False) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyInt_FromLong(__pyx_v_ax); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64(__pyx_v_zcp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_axes); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.ProtoSubgrid.find_split"); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_axes); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig); + __pyx_L2:; + __Pyx_DECREF((PyObject *)__pyx_v_axes); + __Pyx_DECREF((PyObject *)__pyx_v_sig); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":836 + * @cython.boundscheck(False) + * @cython.wraparound(False) + * def get_properties(self): # <<<<<<<<<<<<<< + * cdef np.ndarray[np.int64_t, ndim=2] tr = np.empty((3,3), dtype='int64') + * cdef int i + */ + +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_get_properties(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_get_properties(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyArrayObject *__pyx_v_tr = 0; + int __pyx_v_i; + Py_buffer __pyx_bstruct_tr; + Py_ssize_t __pyx_bstride_0_tr = 0; + Py_ssize_t __pyx_bstride_1_tr = 0; + Py_ssize_t __pyx_bshape_0_tr = 0; + Py_ssize_t __pyx_bshape_1_tr = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyArrayObject *__pyx_t_5 = NULL; + int __pyx_t_6; + long __pyx_t_7; + int __pyx_t_8; + long __pyx_t_9; + int __pyx_t_10; + long __pyx_t_11; + int __pyx_t_12; + __Pyx_RefNannySetupContext("get_properties"); + __pyx_bstruct_tr.buf = NULL; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":837 + * @cython.wraparound(False) + * def get_properties(self): + * cdef np.ndarray[np.int64_t, ndim=2] tr = np.empty((3,3), dtype='int64') # <<<<<<<<<<<<<< + * cdef int i + * for i in range(3): + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + __Pyx_INCREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int64)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_2, __pyx_t_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = ((PyArrayObject *)__pyx_t_4); + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_tr, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { + __pyx_v_tr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_tr.buf = NULL; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } else {__pyx_bstride_0_tr = __pyx_bstruct_tr.strides[0]; __pyx_bstride_1_tr = __pyx_bstruct_tr.strides[1]; + __pyx_bshape_0_tr = __pyx_bstruct_tr.shape[0]; __pyx_bshape_1_tr = __pyx_bstruct_tr.shape[1]; + } + } + __pyx_t_5 = 0; + __pyx_v_tr = ((PyArrayObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":839 + * cdef np.ndarray[np.int64_t, ndim=2] tr = np.empty((3,3), dtype='int64') + * cdef int i + * for i in range(3): # <<<<<<<<<<<<<< + * tr[0,i] = self.left_edge[i] + * tr[1,i] = self.right_edge[i] + */ + for (__pyx_t_6 = 0; __pyx_t_6 < 3; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":840 + * cdef int i + * for i in range(3): + * tr[0,i] = self.left_edge[i] # <<<<<<<<<<<<<< + * tr[1,i] = self.right_edge[i] + * tr[2,i] = self.dimensions[i] + */ + __pyx_t_7 = 0; + __pyx_t_8 = __pyx_v_i; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_tr.buf, __pyx_t_7, __pyx_bstride_0_tr, __pyx_t_8, __pyx_bstride_1_tr) = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[__pyx_v_i]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":841 + * for i in range(3): + * tr[0,i] = self.left_edge[i] + * tr[1,i] = self.right_edge[i] # <<<<<<<<<<<<<< + * tr[2,i] = self.dimensions[i] + * return tr + */ + __pyx_t_9 = 1; + __pyx_t_10 = __pyx_v_i; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_tr.buf, __pyx_t_9, __pyx_bstride_0_tr, __pyx_t_10, __pyx_bstride_1_tr) = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[__pyx_v_i]); + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":842 + * tr[0,i] = self.left_edge[i] + * tr[1,i] = self.right_edge[i] + * tr[2,i] = self.dimensions[i] # <<<<<<<<<<<<<< + * return tr + */ + __pyx_t_11 = 2; + __pyx_t_12 = __pyx_v_i; + *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_tr.buf, __pyx_t_11, __pyx_bstride_0_tr, __pyx_t_12, __pyx_bstride_1_tr) = (((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]); + } + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":843 + * tr[1,i] = self.right_edge[i] + * tr[2,i] = self.dimensions[i] + * return tr # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_tr)); + __pyx_r = ((PyObject *)__pyx_v_tr); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tr); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("yt.frontends.ramses._ramses_reader.ProtoSubgrid.get_properties"); + __pyx_r = NULL; + goto __pyx_L2; + __pyx_L0:; + __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tr); + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_tr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":188 + * # experimental exception made for __getbuffer__ and __releasebuffer__ + * # -- the details of this may change. + * def __getbuffer__(ndarray self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fullfill the PEP. + */ + +static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_pf_5numpy_7ndarray___getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_v_copy_shape; + int __pyx_v_i; + int __pyx_v_ndim; + int __pyx_v_endian_detector; + int __pyx_v_little_endian; + int __pyx_v_t; + char *__pyx_v_f; + PyArray_Descr *__pyx_v_descr = 0; + int __pyx_v_offset; + int __pyx_v_hasfields; + int __pyx_r; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + char *__pyx_t_9; + __Pyx_RefNannySetupContext("__getbuffer__"); + if (__pyx_v_info == NULL) return 0; + __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(__pyx_v_info->obj); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":194 + * # of flags + * cdef int copy_shape, i, ndim + * cdef int endian_detector = 1 # <<<<<<<<<<<<<< + * cdef bint little_endian = ((&endian_detector)[0] != 0) + * + */ + __pyx_v_endian_detector = 1; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":195 + * cdef int copy_shape, i, ndim + * cdef int endian_detector = 1 + * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< + * + * ndim = PyArray_NDIM(self) + */ + __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":197 + * cdef bint little_endian = ((&endian_detector)[0] != 0) + * + * ndim = PyArray_NDIM(self) # <<<<<<<<<<<<<< + * + * if sizeof(npy_intp) != sizeof(Py_ssize_t): + */ + __pyx_v_ndim = PyArray_NDIM(((PyArrayObject *)__pyx_v_self)); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":199 + * ndim = PyArray_NDIM(self) + * + * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< + * copy_shape = 1 + * else: + */ + __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":200 + * + * if sizeof(npy_intp) != sizeof(Py_ssize_t): + * copy_shape = 1 # <<<<<<<<<<<<<< + * else: + * copy_shape = 0 + */ + __pyx_v_copy_shape = 1; + goto __pyx_L5; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":202 + * copy_shape = 1 + * else: + * copy_shape = 0 # <<<<<<<<<<<<<< + * + * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) + */ + __pyx_v_copy_shape = 0; + } + __pyx_L5:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":204 + * copy_shape = 0 + * + * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) # <<<<<<<<<<<<<< + * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): + * raise ValueError(u"ndarray is not C contiguous") + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":205 + * + * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) + * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): # <<<<<<<<<<<<<< + * raise ValueError(u"ndarray is not C contiguous") + * + */ + __pyx_t_2 = (!PyArray_CHKFLAGS(((PyArrayObject *)__pyx_v_self), NPY_C_CONTIGUOUS)); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":206 + * if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS) + * and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)): + * raise ValueError(u"ndarray is not C contiguous") # <<<<<<<<<<<<<< + * + * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_kp_u_3)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_u_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_3)); + __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":208 + * raise ValueError(u"ndarray is not C contiguous") + * + * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) # <<<<<<<<<<<<<< + * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): + * raise ValueError(u"ndarray is not Fortran contiguous") + */ + __pyx_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS); + if (__pyx_t_3) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":209 + * + * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) + * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): # <<<<<<<<<<<<<< + * raise ValueError(u"ndarray is not Fortran contiguous") + * + */ + __pyx_t_1 = (!PyArray_CHKFLAGS(((PyArrayObject *)__pyx_v_self), NPY_F_CONTIGUOUS)); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (__pyx_t_2) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":210 + * if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS) + * and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)): + * raise ValueError(u"ndarray is not Fortran contiguous") # <<<<<<<<<<<<<< + * + * info.buf = PyArray_DATA(self) + */ + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_kp_u_4)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_u_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_4)); + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":212 + * raise ValueError(u"ndarray is not Fortran contiguous") + * + * info.buf = PyArray_DATA(self) # <<<<<<<<<<<<<< + * info.ndim = ndim + * if copy_shape: + */ + __pyx_v_info->buf = PyArray_DATA(((PyArrayObject *)__pyx_v_self)); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":213 + * + * info.buf = PyArray_DATA(self) + * info.ndim = ndim # <<<<<<<<<<<<<< + * if copy_shape: + * # Allocate new buffer for strides and shape info. This is allocated + */ + __pyx_v_info->ndim = __pyx_v_ndim; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":214 + * info.buf = PyArray_DATA(self) + * info.ndim = ndim + * if copy_shape: # <<<<<<<<<<<<<< + * # Allocate new buffer for strides and shape info. This is allocated + * # as one block, strides first. + */ + if (__pyx_v_copy_shape) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":217 + * # Allocate new buffer for strides and shape info. This is allocated + * # as one block, strides first. + * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) # <<<<<<<<<<<<<< + * info.shape = info.strides + ndim + * for i in range(ndim): + */ + __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * __pyx_v_ndim) * 2))); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":218 + * # as one block, strides first. + * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) + * info.shape = info.strides + ndim # <<<<<<<<<<<<<< + * for i in range(ndim): + * info.strides[i] = PyArray_STRIDES(self)[i] + */ + __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":219 + * info.strides = stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) + * info.shape = info.strides + ndim + * for i in range(ndim): # <<<<<<<<<<<<<< + * info.strides[i] = PyArray_STRIDES(self)[i] + * info.shape[i] = PyArray_DIMS(self)[i] + */ + __pyx_t_6 = __pyx_v_ndim; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":220 + * info.shape = info.strides + ndim + * for i in range(ndim): + * info.strides[i] = PyArray_STRIDES(self)[i] # <<<<<<<<<<<<<< + * info.shape[i] = PyArray_DIMS(self)[i] + * else: + */ + (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(((PyArrayObject *)__pyx_v_self))[__pyx_v_i]); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":221 + * for i in range(ndim): + * info.strides[i] = PyArray_STRIDES(self)[i] + * info.shape[i] = PyArray_DIMS(self)[i] # <<<<<<<<<<<<<< + * else: + * info.strides = PyArray_STRIDES(self) + */ + (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(((PyArrayObject *)__pyx_v_self))[__pyx_v_i]); + } + goto __pyx_L8; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":223 + * info.shape[i] = PyArray_DIMS(self)[i] + * else: + * info.strides = PyArray_STRIDES(self) # <<<<<<<<<<<<<< + * info.shape = PyArray_DIMS(self) + * info.suboffsets = NULL + */ + __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(((PyArrayObject *)__pyx_v_self))); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":224 + * else: + * info.strides = PyArray_STRIDES(self) + * info.shape = PyArray_DIMS(self) # <<<<<<<<<<<<<< + * info.suboffsets = NULL + * info.itemsize = PyArray_ITEMSIZE(self) + */ + __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(((PyArrayObject *)__pyx_v_self))); + } + __pyx_L8:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":225 + * info.strides = PyArray_STRIDES(self) + * info.shape = PyArray_DIMS(self) + * info.suboffsets = NULL # <<<<<<<<<<<<<< + * info.itemsize = PyArray_ITEMSIZE(self) + * info.readonly = not PyArray_ISWRITEABLE(self) + */ + __pyx_v_info->suboffsets = NULL; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":226 + * info.shape = PyArray_DIMS(self) + * info.suboffsets = NULL + * info.itemsize = PyArray_ITEMSIZE(self) # <<<<<<<<<<<<<< + * info.readonly = not PyArray_ISWRITEABLE(self) + * + */ + __pyx_v_info->itemsize = PyArray_ITEMSIZE(((PyArrayObject *)__pyx_v_self)); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":227 + * info.suboffsets = NULL + * info.itemsize = PyArray_ITEMSIZE(self) + * info.readonly = not PyArray_ISWRITEABLE(self) # <<<<<<<<<<<<<< + * + * cdef int t + */ + __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(((PyArrayObject *)__pyx_v_self))); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":230 + * + * cdef int t + * cdef char* f = NULL # <<<<<<<<<<<<<< + * cdef dtype descr = self.descr + * cdef list stack + */ + __pyx_v_f = NULL; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":231 + * cdef int t + * cdef char* f = NULL + * cdef dtype descr = self.descr # <<<<<<<<<<<<<< + * cdef list stack + * cdef int offset + */ + __Pyx_INCREF(((PyObject *)((PyArrayObject *)__pyx_v_self)->descr)); + __pyx_v_descr = ((PyArrayObject *)__pyx_v_self)->descr; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":235 + * cdef int offset + * + * cdef bint hasfields = PyDataType_HASFIELDS(descr) # <<<<<<<<<<<<<< + * + * if not hasfields and not copy_shape: + */ + __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":237 + * cdef bint hasfields = PyDataType_HASFIELDS(descr) + * + * if not hasfields and not copy_shape: # <<<<<<<<<<<<<< + * # do not call releasebuffer + * info.obj = None + */ + __pyx_t_2 = (!__pyx_v_hasfields); + if (__pyx_t_2) { + __pyx_t_3 = (!__pyx_v_copy_shape); + __pyx_t_1 = __pyx_t_3; + } else { + __pyx_t_1 = __pyx_t_2; + } + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":239 + * if not hasfields and not copy_shape: + * # do not call releasebuffer + * info.obj = None # <<<<<<<<<<<<<< + * else: + * # need to call releasebuffer + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); + __pyx_v_info->obj = Py_None; + goto __pyx_L11; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":242 + * else: + * # need to call releasebuffer + * info.obj = self # <<<<<<<<<<<<<< + * + * if not hasfields: + */ + __Pyx_INCREF(__pyx_v_self); + __Pyx_GIVEREF(__pyx_v_self); + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); + __pyx_v_info->obj = __pyx_v_self; + } + __pyx_L11:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":244 + * info.obj = self + * + * if not hasfields: # <<<<<<<<<<<<<< + * t = descr.type_num + * if ((descr.byteorder == '>' and little_endian) or + */ + __pyx_t_1 = (!__pyx_v_hasfields); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":245 + * + * if not hasfields: + * t = descr.type_num # <<<<<<<<<<<<<< + * if ((descr.byteorder == '>' and little_endian) or + * (descr.byteorder == '<' and not little_endian)): + */ + __pyx_v_t = __pyx_v_descr->type_num; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":246 + * if not hasfields: + * t = descr.type_num + * if ((descr.byteorder == '>' and little_endian) or # <<<<<<<<<<<<<< + * (descr.byteorder == '<' and not little_endian)): + * raise ValueError(u"Non-native byte order not supported") + */ + __pyx_t_1 = (__pyx_v_descr->byteorder == '>'); + if (__pyx_t_1) { + __pyx_t_2 = __pyx_v_little_endian; + } else { + __pyx_t_2 = __pyx_t_1; + } + if (!__pyx_t_2) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":247 + * t = descr.type_num + * if ((descr.byteorder == '>' and little_endian) or + * (descr.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< + * raise ValueError(u"Non-native byte order not supported") + * if t == NPY_BYTE: f = "b" + */ + __pyx_t_1 = (__pyx_v_descr->byteorder == '<'); + if (__pyx_t_1) { + __pyx_t_3 = (!__pyx_v_little_endian); + __pyx_t_8 = __pyx_t_3; + } else { + __pyx_t_8 = __pyx_t_1; + } + __pyx_t_1 = __pyx_t_8; + } else { + __pyx_t_1 = __pyx_t_2; + } + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":248 + * if ((descr.byteorder == '>' and little_endian) or + * (descr.byteorder == '<' and not little_endian)): + * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< + * if t == NPY_BYTE: f = "b" + * elif t == NPY_UBYTE: f = "B" + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_kp_u_5)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_u_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_5)); + __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L13; + } + __pyx_L13:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":249 + * (descr.byteorder == '<' and not little_endian)): + * raise ValueError(u"Non-native byte order not supported") + * if t == NPY_BYTE: f = "b" # <<<<<<<<<<<<<< + * elif t == NPY_UBYTE: f = "B" + * elif t == NPY_SHORT: f = "h" + */ + __pyx_t_1 = (__pyx_v_t == NPY_BYTE); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__b; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":250 + * raise ValueError(u"Non-native byte order not supported") + * if t == NPY_BYTE: f = "b" + * elif t == NPY_UBYTE: f = "B" # <<<<<<<<<<<<<< + * elif t == NPY_SHORT: f = "h" + * elif t == NPY_USHORT: f = "H" + */ + __pyx_t_1 = (__pyx_v_t == NPY_UBYTE); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__B; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":251 + * if t == NPY_BYTE: f = "b" + * elif t == NPY_UBYTE: f = "B" + * elif t == NPY_SHORT: f = "h" # <<<<<<<<<<<<<< + * elif t == NPY_USHORT: f = "H" + * elif t == NPY_INT: f = "i" + */ + __pyx_t_1 = (__pyx_v_t == NPY_SHORT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__h; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":252 + * elif t == NPY_UBYTE: f = "B" + * elif t == NPY_SHORT: f = "h" + * elif t == NPY_USHORT: f = "H" # <<<<<<<<<<<<<< + * elif t == NPY_INT: f = "i" + * elif t == NPY_UINT: f = "I" + */ + __pyx_t_1 = (__pyx_v_t == NPY_USHORT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__H; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":253 + * elif t == NPY_SHORT: f = "h" + * elif t == NPY_USHORT: f = "H" + * elif t == NPY_INT: f = "i" # <<<<<<<<<<<<<< + * elif t == NPY_UINT: f = "I" + * elif t == NPY_LONG: f = "l" + */ + __pyx_t_1 = (__pyx_v_t == NPY_INT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__i; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":254 + * elif t == NPY_USHORT: f = "H" + * elif t == NPY_INT: f = "i" + * elif t == NPY_UINT: f = "I" # <<<<<<<<<<<<<< + * elif t == NPY_LONG: f = "l" + * elif t == NPY_ULONG: f = "L" + */ + __pyx_t_1 = (__pyx_v_t == NPY_UINT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__I; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":255 + * elif t == NPY_INT: f = "i" + * elif t == NPY_UINT: f = "I" + * elif t == NPY_LONG: f = "l" # <<<<<<<<<<<<<< + * elif t == NPY_ULONG: f = "L" + * elif t == NPY_LONGLONG: f = "q" + */ + __pyx_t_1 = (__pyx_v_t == NPY_LONG); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__l; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":256 + * elif t == NPY_UINT: f = "I" + * elif t == NPY_LONG: f = "l" + * elif t == NPY_ULONG: f = "L" # <<<<<<<<<<<<<< + * elif t == NPY_LONGLONG: f = "q" + * elif t == NPY_ULONGLONG: f = "Q" + */ + __pyx_t_1 = (__pyx_v_t == NPY_ULONG); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__L; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":257 + * elif t == NPY_LONG: f = "l" + * elif t == NPY_ULONG: f = "L" + * elif t == NPY_LONGLONG: f = "q" # <<<<<<<<<<<<<< + * elif t == NPY_ULONGLONG: f = "Q" + * elif t == NPY_FLOAT: f = "f" + */ + __pyx_t_1 = (__pyx_v_t == NPY_LONGLONG); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__q; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":258 + * elif t == NPY_ULONG: f = "L" + * elif t == NPY_LONGLONG: f = "q" + * elif t == NPY_ULONGLONG: f = "Q" # <<<<<<<<<<<<<< + * elif t == NPY_FLOAT: f = "f" + * elif t == NPY_DOUBLE: f = "d" + */ + __pyx_t_1 = (__pyx_v_t == NPY_ULONGLONG); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__Q; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":259 + * elif t == NPY_LONGLONG: f = "q" + * elif t == NPY_ULONGLONG: f = "Q" + * elif t == NPY_FLOAT: f = "f" # <<<<<<<<<<<<<< + * elif t == NPY_DOUBLE: f = "d" + * elif t == NPY_LONGDOUBLE: f = "g" + */ + __pyx_t_1 = (__pyx_v_t == NPY_FLOAT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__f; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":260 + * elif t == NPY_ULONGLONG: f = "Q" + * elif t == NPY_FLOAT: f = "f" + * elif t == NPY_DOUBLE: f = "d" # <<<<<<<<<<<<<< + * elif t == NPY_LONGDOUBLE: f = "g" + * elif t == NPY_CFLOAT: f = "Zf" + */ + __pyx_t_1 = (__pyx_v_t == NPY_DOUBLE); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__d; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":261 + * elif t == NPY_FLOAT: f = "f" + * elif t == NPY_DOUBLE: f = "d" + * elif t == NPY_LONGDOUBLE: f = "g" # <<<<<<<<<<<<<< + * elif t == NPY_CFLOAT: f = "Zf" + * elif t == NPY_CDOUBLE: f = "Zd" + */ + __pyx_t_1 = (__pyx_v_t == NPY_LONGDOUBLE); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__g; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":262 + * elif t == NPY_DOUBLE: f = "d" + * elif t == NPY_LONGDOUBLE: f = "g" + * elif t == NPY_CFLOAT: f = "Zf" # <<<<<<<<<<<<<< + * elif t == NPY_CDOUBLE: f = "Zd" + * elif t == NPY_CLONGDOUBLE: f = "Zg" + */ + __pyx_t_1 = (__pyx_v_t == NPY_CFLOAT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__Zf; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":263 + * elif t == NPY_LONGDOUBLE: f = "g" + * elif t == NPY_CFLOAT: f = "Zf" + * elif t == NPY_CDOUBLE: f = "Zd" # <<<<<<<<<<<<<< + * elif t == NPY_CLONGDOUBLE: f = "Zg" + * elif t == NPY_OBJECT: f = "O" + */ + __pyx_t_1 = (__pyx_v_t == NPY_CDOUBLE); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__Zd; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":264 + * elif t == NPY_CFLOAT: f = "Zf" + * elif t == NPY_CDOUBLE: f = "Zd" + * elif t == NPY_CLONGDOUBLE: f = "Zg" # <<<<<<<<<<<<<< + * elif t == NPY_OBJECT: f = "O" + * else: + */ + __pyx_t_1 = (__pyx_v_t == NPY_CLONGDOUBLE); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__Zg; + goto __pyx_L14; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":265 + * elif t == NPY_CDOUBLE: f = "Zd" + * elif t == NPY_CLONGDOUBLE: f = "Zg" + * elif t == NPY_OBJECT: f = "O" # <<<<<<<<<<<<<< + * else: + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + */ + __pyx_t_1 = (__pyx_v_t == NPY_OBJECT); + if (__pyx_t_1) { + __pyx_v_f = __pyx_k__O; + goto __pyx_L14; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":267 + * elif t == NPY_OBJECT: f = "O" + * else: + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< + * info.format = f + * return + */ + __pyx_t_5 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_6), __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L14:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":268 + * else: + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * info.format = f # <<<<<<<<<<<<<< + * return + * else: + */ + __pyx_v_info->format = __pyx_v_f; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":269 + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * info.format = f + * return # <<<<<<<<<<<<<< + * else: + * info.format = stdlib.malloc(_buffer_format_string_len) + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L12; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":271 + * return + * else: + * info.format = stdlib.malloc(_buffer_format_string_len) # <<<<<<<<<<<<<< + * info.format[0] = '^' # Native data types, manual alignment + * offset = 0 + */ + __pyx_v_info->format = ((char *)malloc(255)); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":272 + * else: + * info.format = stdlib.malloc(_buffer_format_string_len) + * info.format[0] = '^' # Native data types, manual alignment # <<<<<<<<<<<<<< + * offset = 0 + * f = _util_dtypestring(descr, info.format + 1, + */ + (__pyx_v_info->format[0]) = '^'; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":273 + * info.format = stdlib.malloc(_buffer_format_string_len) + * info.format[0] = '^' # Native data types, manual alignment + * offset = 0 # <<<<<<<<<<<<<< + * f = _util_dtypestring(descr, info.format + 1, + * info.format + _buffer_format_string_len, + */ + __pyx_v_offset = 0; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":276 + * f = _util_dtypestring(descr, info.format + 1, + * info.format + _buffer_format_string_len, + * &offset) # <<<<<<<<<<<<<< + * f[0] = 0 # Terminate format string + * + */ + __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f = __pyx_t_9; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":277 + * info.format + _buffer_format_string_len, + * &offset) + * f[0] = 0 # Terminate format string # <<<<<<<<<<<<<< + * + * def __releasebuffer__(ndarray self, Py_buffer* info): + */ + (__pyx_v_f[0]) = 0; + } + __pyx_L12:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("numpy.ndarray.__getbuffer__"); + __pyx_r = -1; + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL; + goto __pyx_L2; + __pyx_L0:; + if (__pyx_v_info->obj == Py_None) { + __Pyx_GOTREF(Py_None); + __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL; + } + __pyx_L2:; + __Pyx_XDECREF((PyObject *)__pyx_v_descr); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":279 + * f[0] = 0 # Terminate format string + * + * def __releasebuffer__(ndarray self, Py_buffer* info): # <<<<<<<<<<<<<< + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) + */ + +static CYTHON_UNUSED void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ +static CYTHON_UNUSED void __pyx_pf_5numpy_7ndarray___releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { + int __pyx_t_1; + __Pyx_RefNannySetupContext("__releasebuffer__"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":280 + * + * def __releasebuffer__(ndarray self, Py_buffer* info): + * if PyArray_HASFIELDS(self): # <<<<<<<<<<<<<< + * stdlib.free(info.format) + * if sizeof(npy_intp) != sizeof(Py_ssize_t): + */ + __pyx_t_1 = PyArray_HASFIELDS(((PyArrayObject *)__pyx_v_self)); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":281 + * def __releasebuffer__(ndarray self, Py_buffer* info): + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) # <<<<<<<<<<<<<< + * if sizeof(npy_intp) != sizeof(Py_ssize_t): + * stdlib.free(info.strides) + */ + free(__pyx_v_info->format); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":282 + * if PyArray_HASFIELDS(self): + * stdlib.free(info.format) + * if sizeof(npy_intp) != sizeof(Py_ssize_t): # <<<<<<<<<<<<<< + * stdlib.free(info.strides) + * # info.shape was stored after info.strides in the same block + */ + __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t))); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":283 + * stdlib.free(info.format) + * if sizeof(npy_intp) != sizeof(Py_ssize_t): + * stdlib.free(info.strides) # <<<<<<<<<<<<<< + * # info.shape was stored after info.strides in the same block + * + */ + free(__pyx_v_info->strides); + goto __pyx_L6; + } + __pyx_L6:; + + __Pyx_RefNannyFinishContext(); +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":756 + * ctypedef npy_cdouble complex_t + * + * cdef inline object PyArray_MultiIterNew1(a): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(1, a) + * + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) { + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew1"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":757 + * + * cdef inline object PyArray_MultiIterNew1(a): + * return PyArray_MultiIterNew(1, a) # <<<<<<<<<<<<<< + * + * cdef inline object PyArray_MultiIterNew2(a, b): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":759 + * return PyArray_MultiIterNew(1, a) + * + * cdef inline object PyArray_MultiIterNew2(a, b): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(2, a, b) + * + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew2"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":760 + * + * cdef inline object PyArray_MultiIterNew2(a, b): + * return PyArray_MultiIterNew(2, a, b) # <<<<<<<<<<<<<< + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":762 + * return PyArray_MultiIterNew(2, a, b) + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(3, a, b, c) + * + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) { + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew3"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":763 + * + * cdef inline object PyArray_MultiIterNew3(a, b, c): + * return PyArray_MultiIterNew(3, a, b, c) # <<<<<<<<<<<<<< + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":765 + * return PyArray_MultiIterNew(3, a, b, c) + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(4, a, b, c, d) + * + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) { + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew4"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":766 + * + * cdef inline object PyArray_MultiIterNew4(a, b, c, d): + * return PyArray_MultiIterNew(4, a, b, c, d) # <<<<<<<<<<<<<< + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":768 + * return PyArray_MultiIterNew(4, a, b, c, d) + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): # <<<<<<<<<<<<<< + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) { + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("PyArray_MultiIterNew5"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":769 + * + * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e): + * return PyArray_MultiIterNew(5, a, b, c, d, e) # <<<<<<<<<<<<<< + * + * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":771 + * return PyArray_MultiIterNew(5, a, b, c, d, e) + * + * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL: # <<<<<<<<<<<<<< + * # Recursive utility function used in __getbuffer__ to get format + * # string. The new location in the format string is returned. + */ + +static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) { + PyArray_Descr *__pyx_v_child; + int __pyx_v_endian_detector; + int __pyx_v_little_endian; + PyObject *__pyx_v_fields; + PyObject *__pyx_v_childname; + PyObject *__pyx_v_new_offset; + PyObject *__pyx_v_t; + char *__pyx_r; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + char *__pyx_t_10; + __Pyx_RefNannySetupContext("_util_dtypestring"); + __pyx_v_child = ((PyArray_Descr *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_fields = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); + __pyx_v_childname = Py_None; __Pyx_INCREF(Py_None); + __pyx_v_new_offset = Py_None; __Pyx_INCREF(Py_None); + __pyx_v_t = Py_None; __Pyx_INCREF(Py_None); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":778 + * cdef int delta_offset + * cdef tuple i + * cdef int endian_detector = 1 # <<<<<<<<<<<<<< + * cdef bint little_endian = ((&endian_detector)[0] != 0) + * cdef tuple fields + */ + __pyx_v_endian_detector = 1; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":779 + * cdef tuple i + * cdef int endian_detector = 1 + * cdef bint little_endian = ((&endian_detector)[0] != 0) # <<<<<<<<<<<<<< + * cdef tuple fields + * + */ + __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":782 + * cdef tuple fields + * + * for childname in descr.names: # <<<<<<<<<<<<<< + * fields = descr.fields[childname] + * child, new_offset = fields + */ + if (likely(((PyObject *)__pyx_v_descr->names) != Py_None)) { + __pyx_t_1 = 0; __pyx_t_2 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_2); + } else { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + for (;;) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; + __Pyx_DECREF(__pyx_v_childname); + __pyx_v_childname = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":783 + * + * for childname in descr.names: + * fields = descr.fields[childname] # <<<<<<<<<<<<<< + * child, new_offset = fields + * + */ + __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_v_fields)); + __pyx_v_fields = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":784 + * for childname in descr.names: + * fields = descr.fields[childname] + * child, new_offset = fields # <<<<<<<<<<<<<< + * + * if (end - f) - (new_offset - offset[0]) < 15: + */ + if (likely(((PyObject *)__pyx_v_fields) != Py_None) && likely(PyTuple_GET_SIZE(((PyObject *)__pyx_v_fields)) == 2)) { + PyObject* tuple = ((PyObject *)__pyx_v_fields); + __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_v_child)); + __pyx_v_child = ((PyArray_Descr *)__pyx_t_3); + __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_v_new_offset); + __pyx_v_new_offset = __pyx_t_4; + __pyx_t_4 = 0; + } else { + __Pyx_UnpackTupleError(((PyObject *)__pyx_v_fields), 2); + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":786 + * child, new_offset = fields + * + * if (end - f) - (new_offset - offset[0]) < 15: # <<<<<<<<<<<<<< + * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") + * + */ + __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":787 + * + * if (end - f) - (new_offset - offset[0]) < 15: + * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") # <<<<<<<<<<<<<< + * + * if ((child.byteorder == '>' and little_endian) or + */ + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_kp_u_7)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_u_7)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_7)); + __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":789 + * raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd") + * + * if ((child.byteorder == '>' and little_endian) or # <<<<<<<<<<<<<< + * (child.byteorder == '<' and not little_endian)): + * raise ValueError(u"Non-native byte order not supported") + */ + __pyx_t_6 = (__pyx_v_child->byteorder == '>'); + if (__pyx_t_6) { + __pyx_t_7 = __pyx_v_little_endian; + } else { + __pyx_t_7 = __pyx_t_6; + } + if (!__pyx_t_7) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":790 + * + * if ((child.byteorder == '>' and little_endian) or + * (child.byteorder == '<' and not little_endian)): # <<<<<<<<<<<<<< + * raise ValueError(u"Non-native byte order not supported") + * # One could encode it in the format string and have Cython + */ + __pyx_t_6 = (__pyx_v_child->byteorder == '<'); + if (__pyx_t_6) { + __pyx_t_8 = (!__pyx_v_little_endian); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_6; + } + __pyx_t_6 = __pyx_t_9; + } else { + __pyx_t_6 = __pyx_t_7; + } + if (__pyx_t_6) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":791 + * if ((child.byteorder == '>' and little_endian) or + * (child.byteorder == '<' and not little_endian)): + * raise ValueError(u"Non-native byte order not supported") # <<<<<<<<<<<<<< + * # One could encode it in the format string and have Cython + * # complain instead, BUT: < and > in format strings also imply + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_kp_u_5)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_5)); + __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":801 + * + * # Output padding bytes + * while offset[0] < new_offset: # <<<<<<<<<<<<<< + * f[0] = 120 # "x"; pad byte + * f += 1 + */ + while (1) { + __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 801; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!__pyx_t_6) break; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":802 + * # Output padding bytes + * while offset[0] < new_offset: + * f[0] = 120 # "x"; pad byte # <<<<<<<<<<<<<< + * f += 1 + * offset[0] += 1 + */ + (__pyx_v_f[0]) = 120; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":803 + * while offset[0] < new_offset: + * f[0] = 120 # "x"; pad byte + * f += 1 # <<<<<<<<<<<<<< + * offset[0] += 1 + * + */ + __pyx_v_f += 1; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":804 + * f[0] = 120 # "x"; pad byte + * f += 1 + * offset[0] += 1 # <<<<<<<<<<<<<< + * + * offset[0] += child.itemsize + */ + (__pyx_v_offset[0]) += 1; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":806 + * offset[0] += 1 + * + * offset[0] += child.itemsize # <<<<<<<<<<<<<< + * + * if not PyDataType_HASFIELDS(child): + */ + (__pyx_v_offset[0]) += __pyx_v_child->elsize; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":808 + * offset[0] += child.itemsize + * + * if not PyDataType_HASFIELDS(child): # <<<<<<<<<<<<<< + * t = child.type_num + * if end - f < 5: + */ + __pyx_t_6 = (!PyDataType_HASFIELDS(__pyx_v_child)); + if (__pyx_t_6) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":809 + * + * if not PyDataType_HASFIELDS(child): + * t = child.type_num # <<<<<<<<<<<<<< + * if end - f < 5: + * raise RuntimeError(u"Format string allocated too short.") + */ + __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_v_t); + __pyx_v_t = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":810 + * if not PyDataType_HASFIELDS(child): + * t = child.type_num + * if end - f < 5: # <<<<<<<<<<<<<< + * raise RuntimeError(u"Format string allocated too short.") + * + */ + __pyx_t_6 = ((__pyx_v_end - __pyx_v_f) < 5); + if (__pyx_t_6) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":811 + * t = child.type_num + * if end - f < 5: + * raise RuntimeError(u"Format string allocated too short.") # <<<<<<<<<<<<<< + * + * # Until ticket #99 is fixed, use integers to avoid warnings + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_kp_u_8)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_u_8)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_8)); + __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L10; + } + __pyx_L10:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":814 + * + * # Until ticket #99 is fixed, use integers to avoid warnings + * if t == NPY_BYTE: f[0] = 98 #"b" # <<<<<<<<<<<<<< + * elif t == NPY_UBYTE: f[0] = 66 #"B" + * elif t == NPY_SHORT: f[0] = 104 #"h" + */ + __pyx_t_5 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 98; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":815 + * # Until ticket #99 is fixed, use integers to avoid warnings + * if t == NPY_BYTE: f[0] = 98 #"b" + * elif t == NPY_UBYTE: f[0] = 66 #"B" # <<<<<<<<<<<<<< + * elif t == NPY_SHORT: f[0] = 104 #"h" + * elif t == NPY_USHORT: f[0] = 72 #"H" + */ + __pyx_t_3 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 66; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":816 + * if t == NPY_BYTE: f[0] = 98 #"b" + * elif t == NPY_UBYTE: f[0] = 66 #"B" + * elif t == NPY_SHORT: f[0] = 104 #"h" # <<<<<<<<<<<<<< + * elif t == NPY_USHORT: f[0] = 72 #"H" + * elif t == NPY_INT: f[0] = 105 #"i" + */ + __pyx_t_5 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 104; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":817 + * elif t == NPY_UBYTE: f[0] = 66 #"B" + * elif t == NPY_SHORT: f[0] = 104 #"h" + * elif t == NPY_USHORT: f[0] = 72 #"H" # <<<<<<<<<<<<<< + * elif t == NPY_INT: f[0] = 105 #"i" + * elif t == NPY_UINT: f[0] = 73 #"I" + */ + __pyx_t_3 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 72; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":818 + * elif t == NPY_SHORT: f[0] = 104 #"h" + * elif t == NPY_USHORT: f[0] = 72 #"H" + * elif t == NPY_INT: f[0] = 105 #"i" # <<<<<<<<<<<<<< + * elif t == NPY_UINT: f[0] = 73 #"I" + * elif t == NPY_LONG: f[0] = 108 #"l" + */ + __pyx_t_5 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 105; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":819 + * elif t == NPY_USHORT: f[0] = 72 #"H" + * elif t == NPY_INT: f[0] = 105 #"i" + * elif t == NPY_UINT: f[0] = 73 #"I" # <<<<<<<<<<<<<< + * elif t == NPY_LONG: f[0] = 108 #"l" + * elif t == NPY_ULONG: f[0] = 76 #"L" + */ + __pyx_t_3 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 73; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":820 + * elif t == NPY_INT: f[0] = 105 #"i" + * elif t == NPY_UINT: f[0] = 73 #"I" + * elif t == NPY_LONG: f[0] = 108 #"l" # <<<<<<<<<<<<<< + * elif t == NPY_ULONG: f[0] = 76 #"L" + * elif t == NPY_LONGLONG: f[0] = 113 #"q" + */ + __pyx_t_5 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 108; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":821 + * elif t == NPY_UINT: f[0] = 73 #"I" + * elif t == NPY_LONG: f[0] = 108 #"l" + * elif t == NPY_ULONG: f[0] = 76 #"L" # <<<<<<<<<<<<<< + * elif t == NPY_LONGLONG: f[0] = 113 #"q" + * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" + */ + __pyx_t_3 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 76; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":822 + * elif t == NPY_LONG: f[0] = 108 #"l" + * elif t == NPY_ULONG: f[0] = 76 #"L" + * elif t == NPY_LONGLONG: f[0] = 113 #"q" # <<<<<<<<<<<<<< + * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" + * elif t == NPY_FLOAT: f[0] = 102 #"f" + */ + __pyx_t_5 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 113; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":823 + * elif t == NPY_ULONG: f[0] = 76 #"L" + * elif t == NPY_LONGLONG: f[0] = 113 #"q" + * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" # <<<<<<<<<<<<<< + * elif t == NPY_FLOAT: f[0] = 102 #"f" + * elif t == NPY_DOUBLE: f[0] = 100 #"d" + */ + __pyx_t_3 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 81; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":824 + * elif t == NPY_LONGLONG: f[0] = 113 #"q" + * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" + * elif t == NPY_FLOAT: f[0] = 102 #"f" # <<<<<<<<<<<<<< + * elif t == NPY_DOUBLE: f[0] = 100 #"d" + * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" + */ + __pyx_t_5 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 824; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 102; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":825 + * elif t == NPY_ULONGLONG: f[0] = 81 #"Q" + * elif t == NPY_FLOAT: f[0] = 102 #"f" + * elif t == NPY_DOUBLE: f[0] = 100 #"d" # <<<<<<<<<<<<<< + * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" + * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf + */ + __pyx_t_3 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 100; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":826 + * elif t == NPY_FLOAT: f[0] = 102 #"f" + * elif t == NPY_DOUBLE: f[0] = 100 #"d" + * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" # <<<<<<<<<<<<<< + * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf + * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd + */ + __pyx_t_5 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 103; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":827 + * elif t == NPY_DOUBLE: f[0] = 100 #"d" + * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" + * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf # <<<<<<<<<<<<<< + * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd + * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg + */ + __pyx_t_3 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 90; + (__pyx_v_f[1]) = 102; + __pyx_v_f += 1; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":828 + * elif t == NPY_LONGDOUBLE: f[0] = 103 #"g" + * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf + * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd # <<<<<<<<<<<<<< + * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg + * elif t == NPY_OBJECT: f[0] = 79 #"O" + */ + __pyx_t_5 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 90; + (__pyx_v_f[1]) = 100; + __pyx_v_f += 1; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":829 + * elif t == NPY_CFLOAT: f[0] = 90; f[1] = 102; f += 1 # Zf + * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd + * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg # <<<<<<<<<<<<<< + * elif t == NPY_OBJECT: f[0] = 79 #"O" + * else: + */ + __pyx_t_3 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 90; + (__pyx_v_f[1]) = 103; + __pyx_v_f += 1; + goto __pyx_L11; + } + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":830 + * elif t == NPY_CDOUBLE: f[0] = 90; f[1] = 100; f += 1 # Zd + * elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg + * elif t == NPY_OBJECT: f[0] = 79 #"O" # <<<<<<<<<<<<<< + * else: + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + */ + __pyx_t_5 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + (__pyx_v_f[0]) = 79; + goto __pyx_L11; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":832 + * elif t == NPY_OBJECT: f[0] = 79 #"O" + * else: + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) # <<<<<<<<<<<<<< + * f += 1 + * else: + */ + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_6), __pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L11:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":833 + * else: + * raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t) + * f += 1 # <<<<<<<<<<<<<< + * else: + * # Cython ignores struct boundary information ("T{...}"), + */ + __pyx_v_f += 1; + goto __pyx_L9; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":837 + * # Cython ignores struct boundary information ("T{...}"), + * # so don't output it + * f = _util_dtypestring(child, f, end, offset) # <<<<<<<<<<<<<< + * return f + * + */ + __pyx_t_10 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f = __pyx_t_10; + } + __pyx_L9:; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":838 + * # so don't output it + * f = _util_dtypestring(child, f, end, offset) + * return f # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_f; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("numpy._util_dtypestring"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF((PyObject *)__pyx_v_child); + __Pyx_DECREF(__pyx_v_fields); + __Pyx_DECREF(__pyx_v_childname); + __Pyx_DECREF(__pyx_v_new_offset); + __Pyx_DECREF(__pyx_v_t); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":953 + * + * + * cdef inline void set_array_base(ndarray arr, object base): # <<<<<<<<<<<<<< + * cdef PyObject* baseptr + * if base is None: + */ + +static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) { + PyObject *__pyx_v_baseptr; + int __pyx_t_1; + __Pyx_RefNannySetupContext("set_array_base"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":955 + * cdef inline void set_array_base(ndarray arr, object base): + * cdef PyObject* baseptr + * if base is None: # <<<<<<<<<<<<<< + * baseptr = NULL + * else: + */ + __pyx_t_1 = (__pyx_v_base == Py_None); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":956 + * cdef PyObject* baseptr + * if base is None: + * baseptr = NULL # <<<<<<<<<<<<<< + * else: + * Py_INCREF(base) # important to do this before decref below! + */ + __pyx_v_baseptr = NULL; + goto __pyx_L3; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":958 + * baseptr = NULL + * else: + * Py_INCREF(base) # important to do this before decref below! # <<<<<<<<<<<<<< + * baseptr = base + * Py_XDECREF(arr.base) + */ + Py_INCREF(__pyx_v_base); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":959 + * else: + * Py_INCREF(base) # important to do this before decref below! + * baseptr = base # <<<<<<<<<<<<<< + * Py_XDECREF(arr.base) + * arr.base = baseptr + */ + __pyx_v_baseptr = ((PyObject *)__pyx_v_base); + } + __pyx_L3:; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":960 + * Py_INCREF(base) # important to do this before decref below! + * baseptr = base + * Py_XDECREF(arr.base) # <<<<<<<<<<<<<< + * arr.base = baseptr + * + */ + Py_XDECREF(__pyx_v_arr->base); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":961 + * baseptr = base + * Py_XDECREF(arr.base) + * arr.base = baseptr # <<<<<<<<<<<<<< + * + * cdef inline object get_array_base(ndarray arr): + */ + __pyx_v_arr->base = __pyx_v_baseptr; + + __Pyx_RefNannyFinishContext(); +} + +/* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":963 + * arr.base = baseptr + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * if arr.base is NULL: + * return None + */ + +static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) { + PyObject *__pyx_r = NULL; + int __pyx_t_1; + __Pyx_RefNannySetupContext("get_array_base"); + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":964 + * + * cdef inline object get_array_base(ndarray arr): + * if arr.base is NULL: # <<<<<<<<<<<<<< + * return None + * else: + */ + __pyx_t_1 = (__pyx_v_arr->base == NULL); + if (__pyx_t_1) { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":965 + * cdef inline object get_array_base(ndarray arr): + * if arr.base is NULL: + * return None # <<<<<<<<<<<<<< + * else: + * return arr.base + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":967 + * return None + * else: + * return arr.base # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_arr->base)); + __pyx_r = ((PyObject *)__pyx_v_arr->base); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)o); + p->field_ind = Py_None; Py_INCREF(Py_None); + p->field_names = Py_None; Py_INCREF(Py_None); + if (__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy___cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy(PyObject *o) { + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *p = (struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy___dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(p->field_ind); + Py_XDECREF(p->field_names); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *p = (struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)o; + if (p->field_ind) { + e = (*v)(p->field_ind, a); if (e) return e; + } + if (p->field_names) { + e = (*v)(p->field_names, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy(PyObject *o) { + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *p = (struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy *)o; + PyObject* tmp; + tmp = ((PyObject*)p->field_ind); + p->field_ind = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->field_names); + p->field_names = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_ind(PyObject *o, void *x) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___get__(o); +} + +static int __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_ind(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___set__(o, v); + } + else { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_9field_ind___del__(o); + } +} + +static PyObject *__pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_names(PyObject *o, void *x) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___get__(o); +} + +static int __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_names(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___set__(o, v); + } + else { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_11field_names___del__(o); + } +} + +static PyMethodDef __pyx_methods_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy[] = { + {__Pyx_NAMESTR("count_zones"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_count_zones, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("ensure_loaded"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_ensure_loaded, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("clear_tree"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_clear_tree, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_file_info"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_get_file_info, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("fill_hierarchy_arrays"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_fill_hierarchy_arrays, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_oct_grid"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_read_oct_grid, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_grid"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_read_grid, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy[] = { + {(char *)"field_ind", __pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_ind, __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_ind, 0, 0}, + {(char *)"field_names", __pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_names, __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_17RAMSES_tree_proxy_field_names, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_RAMSES_tree_proxy = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*nb_long*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_RAMSES_tree_proxy = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_RAMSES_tree_proxy = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_RAMSES_tree_proxy = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +PyTypeObject __pyx_type_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("yt.frontends.ramses._ramses_reader.RAMSES_tree_proxy"), /*tp_name*/ + sizeof(struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*tp_compare*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_RAMSES_tree_proxy, /*tp_as_number*/ + &__pyx_tp_as_sequence_RAMSES_tree_proxy, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_RAMSES_tree_proxy, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_RAMSES_tree_proxy, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy, /*tp_traverse*/ + __pyx_tp_clear_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)o); + p->sigs = Py_None; Py_INCREF(Py_None); + p->grid_file_locations = Py_None; Py_INCREF(Py_None); + p->dd = Py_None; Py_INCREF(Py_None); + if (__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid___cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid(PyObject *o) { + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *p = (struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)o; + Py_XDECREF(p->sigs); + Py_XDECREF(p->grid_file_locations); + Py_XDECREF(p->dd); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *p = (struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)o; + if (p->sigs) { + e = (*v)(p->sigs, a); if (e) return e; + } + if (p->grid_file_locations) { + e = (*v)(p->grid_file_locations, a); if (e) return e; + } + if (p->dd) { + e = (*v)(p->dd, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid(PyObject *o) { + struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *p = (struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid *)o; + PyObject* tmp; + tmp = ((PyObject*)p->sigs); + p->sigs = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->grid_file_locations); + p->grid_file_locations = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->dd); + p->dd = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_efficiency(PyObject *o, void *x) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_10efficiency___get__(o); +} + +static int __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_efficiency(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_10efficiency___set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_sigs(PyObject *o, void *x) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___get__(o); +} + +static int __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_sigs(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___set__(o, v); + } + else { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_4sigs___del__(o); + } +} + +static PyObject *__pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_grid_file_locations(PyObject *o, void *x) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___get__(o); +} + +static int __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_grid_file_locations(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___set__(o, v); + } + else { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_19grid_file_locations___del__(o); + } +} + +static PyObject *__pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_dd(PyObject *o, void *x) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___get__(o); +} + +static int __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_dd(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___set__(o, v); + } + else { + return __pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_2dd___del__(o); + } +} + +static PyMethodDef __pyx_methods_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid[] = { + {__Pyx_NAMESTR("find_split"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_find_split, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_properties"), (PyCFunction)__pyx_pf_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_get_properties, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid[] = { + {(char *)"efficiency", __pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_efficiency, __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_efficiency, 0, 0}, + {(char *)"sigs", __pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_sigs, __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_sigs, 0, 0}, + {(char *)"grid_file_locations", __pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_grid_file_locations, __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_grid_file_locations, 0, 0}, + {(char *)"dd", __pyx_getprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_dd, __pyx_setprop_2yt_9frontends_6ramses_14_ramses_reader_12ProtoSubgrid_dd, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_ProtoSubgrid = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*nb_long*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_ProtoSubgrid = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_ProtoSubgrid = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_ProtoSubgrid = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +PyTypeObject __pyx_type_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("yt.frontends.ramses._ramses_reader.ProtoSubgrid"), /*tp_name*/ + sizeof(struct __pyx_obj_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*tp_compare*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_ProtoSubgrid, /*tp_as_number*/ + &__pyx_tp_as_sequence_ProtoSubgrid, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_ProtoSubgrid, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_ProtoSubgrid, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid, /*tp_traverse*/ + __pyx_tp_clear_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + __Pyx_NAMESTR("_ramses_reader"), + __Pyx_DOCSTR(__pyx_k_9), /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, + {&__pyx_n_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 1}, + {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0}, + {&__pyx_kp_u_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 1, 0, 0}, + {&__pyx_kp_u_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 1, 0, 0}, + {&__pyx_kp_u_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 1, 0, 0}, + {&__pyx_kp_u_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 1, 0, 0}, + {&__pyx_kp_u_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 1, 0, 0}, + {&__pyx_n_s__F, __pyx_k__F, sizeof(__pyx_k__F), 0, 0, 1, 1}, + {&__pyx_n_s__H0, __pyx_k__H0, sizeof(__pyx_k__H0), 0, 0, 1, 1}, + {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1}, + {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, + {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, + {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, + {&__pyx_n_s__aexp, __pyx_k__aexp, sizeof(__pyx_k__aexp), 0, 0, 1, 1}, + {&__pyx_n_s__argsort, __pyx_k__argsort, sizeof(__pyx_k__argsort), 0, 0, 1, 1}, + {&__pyx_n_s__base, __pyx_k__base, sizeof(__pyx_k__base), 0, 0, 1, 1}, + {&__pyx_n_s__begin, __pyx_k__begin, sizeof(__pyx_k__begin), 0, 0, 1, 1}, + {&__pyx_n_s__boxlen, __pyx_k__boxlen, sizeof(__pyx_k__boxlen), 0, 0, 1, 1}, + {&__pyx_n_s__buf, __pyx_k__buf, sizeof(__pyx_k__buf), 0, 0, 1, 1}, + {&__pyx_n_s__byteorder, __pyx_k__byteorder, sizeof(__pyx_k__byteorder), 0, 0, 1, 1}, + {&__pyx_n_s__c_str, __pyx_k__c_str, sizeof(__pyx_k__c_str), 0, 0, 1, 1}, + {&__pyx_n_s__child_mask, __pyx_k__child_mask, sizeof(__pyx_k__child_mask), 0, 0, 1, 1}, + {&__pyx_n_s__component_grid_info, __pyx_k__component_grid_info, sizeof(__pyx_k__component_grid_info), 0, 0, 1, 1}, + {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1}, + {&__pyx_n_s__dd, __pyx_k__dd, sizeof(__pyx_k__dd), 0, 0, 1, 1}, + {&__pyx_n_s__descr, __pyx_k__descr, sizeof(__pyx_k__descr), 0, 0, 1, 1}, + {&__pyx_n_s__dimensions, __pyx_k__dimensions, sizeof(__pyx_k__dimensions), 0, 0, 1, 1}, + {&__pyx_n_s__domain, __pyx_k__domain, sizeof(__pyx_k__domain), 0, 0, 1, 1}, + {&__pyx_n_s__domain_index, __pyx_k__domain_index, sizeof(__pyx_k__domain_index), 0, 0, 1, 1}, + {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1}, + {&__pyx_n_s__efficiency, __pyx_k__efficiency, sizeof(__pyx_k__efficiency), 0, 0, 1, 1}, + {&__pyx_n_s__empty, __pyx_k__empty, sizeof(__pyx_k__empty), 0, 0, 1, 1}, + {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1}, + {&__pyx_n_s__ensure_loaded, __pyx_k__ensure_loaded, sizeof(__pyx_k__ensure_loaded), 0, 0, 1, 1}, + {&__pyx_n_s__field, __pyx_k__field, sizeof(__pyx_k__field), 0, 0, 1, 1}, + {&__pyx_n_s__field_ind, __pyx_k__field_ind, sizeof(__pyx_k__field_ind), 0, 0, 1, 1}, + {&__pyx_n_s__field_names, __pyx_k__field_names, sizeof(__pyx_k__field_names), 0, 0, 1, 1}, + {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1}, + {&__pyx_n_s__filled, __pyx_k__filled, sizeof(__pyx_k__filled), 0, 0, 1, 1}, + {&__pyx_n_s__float64, __pyx_k__float64, sizeof(__pyx_k__float64), 0, 0, 1, 1}, + {&__pyx_n_s__fn, __pyx_k__fn, sizeof(__pyx_k__fn), 0, 0, 1, 1}, + {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1}, + {&__pyx_n_s__get_domain, __pyx_k__get_domain, sizeof(__pyx_k__get_domain), 0, 0, 1, 1}, + {&__pyx_n_s__get_parent, __pyx_k__get_parent, sizeof(__pyx_k__get_parent), 0, 0, 1, 1}, + {&__pyx_n_s__grid_dimensions, __pyx_k__grid_dimensions, sizeof(__pyx_k__grid_dimensions), 0, 0, 1, 1}, + {&__pyx_n_s__grid_dims, __pyx_k__grid_dims, sizeof(__pyx_k__grid_dims), 0, 0, 1, 1}, + {&__pyx_n_s__grid_file_locations, __pyx_k__grid_file_locations, sizeof(__pyx_k__grid_file_locations), 0, 0, 1, 1}, + {&__pyx_n_s__grid_id, __pyx_k__grid_id, sizeof(__pyx_k__grid_id), 0, 0, 1, 1}, + {&__pyx_n_s__grid_levels, __pyx_k__grid_levels, sizeof(__pyx_k__grid_levels), 0, 0, 1, 1}, + {&__pyx_n_s__grid_pos_double, __pyx_k__grid_pos_double, sizeof(__pyx_k__grid_pos_double), 0, 0, 1, 1}, + {&__pyx_n_s__hydro_datas, __pyx_k__hydro_datas, sizeof(__pyx_k__hydro_datas), 0, 0, 1, 1}, + {&__pyx_n_s__int32, __pyx_k__int32, sizeof(__pyx_k__int32), 0, 0, 1, 1}, + {&__pyx_n_s__int64, __pyx_k__int64, sizeof(__pyx_k__int64), 0, 0, 1, 1}, + {&__pyx_n_s__is_finest, __pyx_k__is_finest, sizeof(__pyx_k__is_finest), 0, 0, 1, 1}, + {&__pyx_n_s__itemsize, __pyx_k__itemsize, sizeof(__pyx_k__itemsize), 0, 0, 1, 1}, + {&__pyx_n_s__left_edge, __pyx_k__left_edge, sizeof(__pyx_k__left_edge), 0, 0, 1, 1}, + {&__pyx_n_s__left_edges, __pyx_k__left_edges, sizeof(__pyx_k__left_edges), 0, 0, 1, 1}, + {&__pyx_n_s__left_index, __pyx_k__left_index, sizeof(__pyx_k__left_index), 0, 0, 1, 1}, + {&__pyx_n_s__level, __pyx_k__level, sizeof(__pyx_k__level), 0, 0, 1, 1}, + {&__pyx_n_s__levelmax, __pyx_k__levelmax, sizeof(__pyx_k__levelmax), 0, 0, 1, 1}, + {&__pyx_n_s__levelmin, __pyx_k__levelmin, sizeof(__pyx_k__levelmin), 0, 0, 1, 1}, + {&__pyx_n_s__loaded, __pyx_k__loaded, sizeof(__pyx_k__loaded), 0, 0, 1, 1}, + {&__pyx_n_s__m_AMR_levels, __pyx_k__m_AMR_levels, sizeof(__pyx_k__m_AMR_levels), 0, 0, 1, 1}, + {&__pyx_n_s__m_header, __pyx_k__m_header, sizeof(__pyx_k__m_header), 0, 0, 1, 1}, + {&__pyx_n_s__m_maxlevel, __pyx_k__m_maxlevel, sizeof(__pyx_k__m_maxlevel), 0, 0, 1, 1}, + {&__pyx_n_s__m_nvars, __pyx_k__m_nvars, sizeof(__pyx_k__m_nvars), 0, 0, 1, 1}, + {&__pyx_n_s__m_var_array, __pyx_k__m_var_array, sizeof(__pyx_k__m_var_array), 0, 0, 1, 1}, + {&__pyx_n_s__m_varnames, __pyx_k__m_varnames, sizeof(__pyx_k__m_varnames), 0, 0, 1, 1}, + {&__pyx_n_s__names, __pyx_k__names, sizeof(__pyx_k__names), 0, 0, 1, 1}, + {&__pyx_n_s__ncpu, __pyx_k__ncpu, sizeof(__pyx_k__ncpu), 0, 0, 1, 1}, + {&__pyx_n_s__ndim, __pyx_k__ndim, sizeof(__pyx_k__ndim), 0, 0, 1, 1}, + {&__pyx_n_s__ndomains, __pyx_k__ndomains, sizeof(__pyx_k__ndomains), 0, 0, 1, 1}, + {&__pyx_n_s__next, __pyx_k__next, sizeof(__pyx_k__next), 0, 0, 1, 1}, + {&__pyx_n_s__nfields, __pyx_k__nfields, sizeof(__pyx_k__nfields), 0, 0, 1, 1}, + {&__pyx_n_s__ngridmax, __pyx_k__ngridmax, sizeof(__pyx_k__ngridmax), 0, 0, 1, 1}, + {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1}, + {&__pyx_n_s__nstep_coarse, __pyx_k__nstep_coarse, sizeof(__pyx_k__nstep_coarse), 0, 0, 1, 1}, + {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1}, + {&__pyx_n_s__nx, __pyx_k__nx, sizeof(__pyx_k__nx), 0, 0, 1, 1}, + {&__pyx_n_s__obj, __pyx_k__obj, sizeof(__pyx_k__obj), 0, 0, 1, 1}, + {&__pyx_n_s__omega_b, __pyx_k__omega_b, sizeof(__pyx_k__omega_b), 0, 0, 1, 1}, + {&__pyx_n_s__omega_k, __pyx_k__omega_k, sizeof(__pyx_k__omega_k), 0, 0, 1, 1}, + {&__pyx_n_s__omega_l, __pyx_k__omega_l, sizeof(__pyx_k__omega_l), 0, 0, 1, 1}, + {&__pyx_n_s__omega_m, __pyx_k__omega_m, sizeof(__pyx_k__omega_m), 0, 0, 1, 1}, + {&__pyx_n_s__ones, __pyx_k__ones, sizeof(__pyx_k__ones), 0, 0, 1, 1}, + {&__pyx_n_s__order, __pyx_k__order, sizeof(__pyx_k__order), 0, 0, 1, 1}, + {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__read, __pyx_k__read, sizeof(__pyx_k__read), 0, 0, 1, 1}, + {&__pyx_n_s__readonly, __pyx_k__readonly, sizeof(__pyx_k__readonly), 0, 0, 1, 1}, + {&__pyx_n_s__ref_factor, __pyx_k__ref_factor, sizeof(__pyx_k__ref_factor), 0, 0, 1, 1}, + {&__pyx_n_s__right_edge, __pyx_k__right_edge, sizeof(__pyx_k__right_edge), 0, 0, 1, 1}, + {&__pyx_n_s__right_edges, __pyx_k__right_edges, sizeof(__pyx_k__right_edges), 0, 0, 1, 1}, + {&__pyx_n_s__rsnap, __pyx_k__rsnap, sizeof(__pyx_k__rsnap), 0, 0, 1, 1}, + {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, + {&__pyx_n_s__signature, __pyx_k__signature, sizeof(__pyx_k__signature), 0, 0, 1, 1}, + {&__pyx_n_s__sigs, __pyx_k__sigs, sizeof(__pyx_k__sigs), 0, 0, 1, 1}, + {&__pyx_n_s__snapshot_name, __pyx_k__snapshot_name, sizeof(__pyx_k__snapshot_name), 0, 0, 1, 1}, + {&__pyx_n_s__start_index, __pyx_k__start_index, sizeof(__pyx_k__start_index), 0, 0, 1, 1}, + {&__pyx_n_s__strides, __pyx_k__strides, sizeof(__pyx_k__strides), 0, 0, 1, 1}, + {&__pyx_n_s__suboffsets, __pyx_k__suboffsets, sizeof(__pyx_k__suboffsets), 0, 0, 1, 1}, + {&__pyx_n_s__time, __pyx_k__time, sizeof(__pyx_k__time), 0, 0, 1, 1}, + {&__pyx_n_s__top_grid_dims, __pyx_k__top_grid_dims, sizeof(__pyx_k__top_grid_dims), 0, 0, 1, 1}, + {&__pyx_n_s__trees, __pyx_k__trees, sizeof(__pyx_k__trees), 0, 0, 1, 1}, + {&__pyx_n_s__type_num, __pyx_k__type_num, sizeof(__pyx_k__type_num), 0, 0, 1, 1}, + {&__pyx_n_s__unit_d, __pyx_k__unit_d, sizeof(__pyx_k__unit_d), 0, 0, 1, 1}, + {&__pyx_n_s__unit_l, __pyx_k__unit_l, sizeof(__pyx_k__unit_l), 0, 0, 1, 1}, + {&__pyx_n_s__unit_t, __pyx_k__unit_t, sizeof(__pyx_k__unit_t), 0, 0, 1, 1}, + {&__pyx_n_s__varname, __pyx_k__varname, sizeof(__pyx_k__varname), 0, 0, 1, 1}, + {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1}, + {&__pyx_n_s__y, __pyx_k__y, sizeof(__pyx_k__y), 0, 0, 1, 1}, + {&__pyx_n_s__z, __pyx_k__z, sizeof(__pyx_k__z), 0, 0, 1, 1}, + {&__pyx_n_s__zeros, __pyx_k__zeros, sizeof(__pyx_k__zeros), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC init_ramses_reader(void); /*proto*/ +PyMODINIT_FUNC init_ramses_reader(void) +#else +PyMODINIT_FUNC PyInit__ramses_reader(void); /*proto*/ +PyMODINIT_FUNC PyInit__ramses_reader(void) +#endif +{ + PyObject *__pyx_t_1 = NULL; + #if CYTHON_REFNANNY + void* __pyx_refnanny = NULL; + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); + if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); + } + __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__ramses_reader(void)", __LINE__, __FILE__); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #ifdef __pyx_binding_PyCFunctionType_USED + if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_ramses_reader"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_9), 0, PYTHON_API_VERSION); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if PY_MAJOR_VERSION < 3 + Py_INCREF(__pyx_m); + #endif + __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + /*--- Initialize various global constants etc. ---*/ + if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_module_is_main_yt__frontends__ramses___ramses_reader) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + /*--- Builtin init code ---*/ + if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Global init code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "RAMSES_tree_proxy", (PyObject *)&__pyx_type_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy = &__pyx_type_2yt_9frontends_6ramses_14_ramses_reader_RAMSES_tree_proxy; + if (PyType_Ready(&__pyx_type_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "ProtoSubgrid", (PyObject *)&__pyx_type_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid = &__pyx_type_2yt_9frontends_6ramses_14_ramses_reader_ProtoSubgrid; + /*--- Type import code ---*/ + __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Function import code ---*/ + /*--- Execution code ---*/ + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":32 + * from libc.stdlib cimport malloc, free, abs, calloc, labs + * + * import numpy as np # <<<<<<<<<<<<<< + * cimport numpy as np + * cimport cython + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/matthewturk/ytdays2010/yt/yt/frontends/ramses/_ramses_reader.pyx":1 + * """ # <<<<<<<<<<<<<< + * Wrapping code for Oliver Hahn's RamsesRead++ + * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + + /* "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Cython/Includes/numpy.pxd":963 + * arr.base = baseptr + * + * cdef inline object get_array_base(ndarray arr): # <<<<<<<<<<<<<< + * if arr.base is NULL: + * return None + */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + if (__pyx_m) { + __Pyx_AddTraceback("init yt.frontends.ramses._ramses_reader"); + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init yt.frontends.ramses._ramses_reader"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif +} + +/* Runtime support code */ + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) + PyErr_SetObject(PyExc_NameError, name); + return result; +} + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *number, *more_or_less; + + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + number = (num_expected == 1) ? "" : "s"; + PyErr_Format(PyExc_TypeError, + #if PY_VERSION_HEX < 0x02050000 + "%s() takes %s %d positional argument%s (%d given)", + #else + "%s() takes %s %zd positional argument%s (%zd given)", + #endif + func_name, more_or_less, num_expected, number, num_found); +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + /* unexpected keyword found */ + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + + + +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + +static CYTHON_INLINE int __Pyx_IsLittleEndian(void) { + unsigned int n = 1; + return *(unsigned char*)(&n) != 0; +} + +typedef struct { + __Pyx_StructField root; + __Pyx_BufFmt_StackElem* head; + size_t fmt_offset; + int new_count, enc_count; + int is_complex; + char enc_type; + char packmode; +} __Pyx_BufFmt_Context; + +static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, + __Pyx_BufFmt_StackElem* stack, + __Pyx_TypeInfo* type) { + stack[0].field = &ctx->root; + stack[0].parent_offset = 0; + ctx->root.type = type; + ctx->root.name = "buffer dtype"; + ctx->root.offset = 0; + ctx->head = stack; + ctx->head->field = &ctx->root; + ctx->fmt_offset = 0; + ctx->head->parent_offset = 0; + ctx->packmode = '@'; + ctx->new_count = 1; + ctx->enc_count = 0; + ctx->enc_type = 0; + ctx->is_complex = 0; + while (type->typegroup == 'S') { + ++ctx->head; + ctx->head->field = type->fields; + ctx->head->parent_offset = 0; + type = type->fields->type; + } +} + +static int __Pyx_BufFmt_ParseNumber(const char** ts) { + int count; + const char* t = *ts; + if (*t < '0' || *t > '9') { + return -1; + } else { + count = *t++ - '0'; + while (*t >= '0' && *t < '9') { + count *= 10; + count += *t++ - '0'; + } + } + *ts = t; + return count; +} + +static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { + char msg[] = {ch, 0}; + PyErr_Format(PyExc_ValueError, "Unexpected format string character: '%s'", msg); +} + +static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { + switch (ch) { + case 'b': return "'char'"; + case 'B': return "'unsigned char'"; + case 'h': return "'short'"; + case 'H': return "'unsigned short'"; + case 'i': return "'int'"; + case 'I': return "'unsigned int'"; + case 'l': return "'long'"; + case 'L': return "'unsigned long'"; + case 'q': return "'long long'"; + case 'Q': return "'unsigned long long'"; + case 'f': return (is_complex ? "'complex float'" : "'float'"); + case 'd': return (is_complex ? "'complex double'" : "'double'"); + case 'g': return (is_complex ? "'complex long double'" : "'long double'"); + case 'T': return "a struct"; + case 'O': return "Python object"; + case 'P': return "a pointer"; + case 0: return "end"; + default: return "unparseable format string"; + } +} + +static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) { + switch (ch) { + case '?': case 'c': case 'b': case 'B': return 1; + case 'h': case 'H': return 2; + case 'i': case 'I': case 'l': case 'L': return 4; + case 'q': case 'Q': return 8; + case 'f': return (is_complex ? 8 : 4); + case 'd': return (is_complex ? 16 : 8); + case 'g': { + PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g').."); + return 0; + } + case 'O': case 'P': return sizeof(void*); + default: + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; + } +} + +static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) { + switch (ch) { + case 'c': case 'b': case 'B': return 1; + case 'h': case 'H': return sizeof(short); + case 'i': case 'I': return sizeof(int); + case 'l': case 'L': return sizeof(long); + #ifdef HAVE_LONG_LONG + case 'q': case 'Q': return sizeof(PY_LONG_LONG); + #endif + case 'f': return sizeof(float) * (is_complex ? 2 : 1); + case 'd': return sizeof(double) * (is_complex ? 2 : 1); + case 'g': return sizeof(long double) * (is_complex ? 2 : 1); + case 'O': case 'P': return sizeof(void*); + default: { + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; + } + } +} + +typedef struct { char c; short x; } __Pyx_st_short; +typedef struct { char c; int x; } __Pyx_st_int; +typedef struct { char c; long x; } __Pyx_st_long; +typedef struct { char c; float x; } __Pyx_st_float; +typedef struct { char c; double x; } __Pyx_st_double; +typedef struct { char c; long double x; } __Pyx_st_longdouble; +typedef struct { char c; void *x; } __Pyx_st_void_p; +#ifdef HAVE_LONG_LONG +typedef struct { char c; PY_LONG_LONG x; } __Pyx_s_long_long; +#endif + +static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { + switch (ch) { + case '?': case 'c': case 'b': case 'B': return 1; + case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short); + case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); + case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); +#ifdef HAVE_LONG_LONG + case 'q': case 'Q': return sizeof(__Pyx_s_long_long) - sizeof(PY_LONG_LONG); +#endif + case 'f': return sizeof(__Pyx_st_float) - sizeof(float); + case 'd': return sizeof(__Pyx_st_double) - sizeof(double); + case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double); + case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*); + default: + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; + } +} + +static size_t __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { + switch (ch) { + case 'c': case 'b': case 'h': case 'i': case 'l': case 'q': return 'I'; + case 'B': case 'H': case 'I': case 'L': case 'Q': return 'U'; + case 'f': case 'd': case 'g': return (is_complex ? 'C' : 'R'); + case 'O': return 'O'; + case 'P': return 'P'; + default: { + __Pyx_BufFmt_RaiseUnexpectedChar(ch); + return 0; + } + } +} + +static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) { + if (ctx->head == NULL || ctx->head->field == &ctx->root) { + const char* expected; + const char* quote; + if (ctx->head == NULL) { + expected = "end"; + quote = ""; + } else { + expected = ctx->head->field->type->name; + quote = "'"; + } + PyErr_Format(PyExc_ValueError, + "Buffer dtype mismatch, expected %s%s%s but got %s", + quote, expected, quote, + __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex)); + } else { + __Pyx_StructField* field = ctx->head->field; + __Pyx_StructField* parent = (ctx->head - 1)->field; + PyErr_Format(PyExc_ValueError, + "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'", + field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex), + parent->type->name, field->name); + } +} + +static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { + char group; + size_t size, offset; + if (ctx->enc_type == 0) return 0; + group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex); + do { + __Pyx_StructField* field = ctx->head->field; + __Pyx_TypeInfo* type = field->type; + + if (ctx->packmode == '@' || ctx->packmode == '^') { + size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex); + } else { + size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); + } + if (ctx->packmode == '@') { + int align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); + int align_mod_offset; + if (align_at == 0) return -1; + align_mod_offset = ctx->fmt_offset % align_at; + if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; + } + + if (type->size != size || type->typegroup != group) { + if (type->typegroup == 'C' && type->fields != NULL) { + /* special case -- treat as struct rather than complex number */ + size_t parent_offset = ctx->head->parent_offset + field->offset; + ++ctx->head; + ctx->head->field = type->fields; + ctx->head->parent_offset = parent_offset; + continue; + } + + __Pyx_BufFmt_RaiseExpected(ctx); + return -1; + } + + offset = ctx->head->parent_offset + field->offset; + if (ctx->fmt_offset != offset) { + PyErr_Format(PyExc_ValueError, + "Buffer dtype mismatch; next field is at offset %"PY_FORMAT_SIZE_T"d " + "but %"PY_FORMAT_SIZE_T"d expected", ctx->fmt_offset, offset); + return -1; + } + + ctx->fmt_offset += size; + + --ctx->enc_count; /* Consume from buffer string */ + + /* Done checking, move to next field, pushing or popping struct stack if needed */ + while (1) { + if (field == &ctx->root) { + ctx->head = NULL; + if (ctx->enc_count != 0) { + __Pyx_BufFmt_RaiseExpected(ctx); + return -1; + } + break; /* breaks both loops as ctx->enc_count == 0 */ + } + ctx->head->field = ++field; + if (field->type == NULL) { + --ctx->head; + field = ctx->head->field; + continue; + } else if (field->type->typegroup == 'S') { + size_t parent_offset = ctx->head->parent_offset + field->offset; + if (field->type->fields->type == NULL) continue; /* empty struct */ + field = field->type->fields; + ++ctx->head; + ctx->head->field = field; + ctx->head->parent_offset = parent_offset; + break; + } else { + break; + } + } + } while (ctx->enc_count); + ctx->enc_type = 0; + ctx->is_complex = 0; + return 0; +} + +static int __Pyx_BufFmt_FirstPack(__Pyx_BufFmt_Context* ctx) { + if (ctx->enc_type != 0 || ctx->packmode != '@') { + PyErr_SetString(PyExc_ValueError, "Buffer packing mode currently only allowed at beginning of format string (this is a defect)"); + return -1; + } + return 0; +} + +static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) { + int got_Z = 0; + while (1) { + switch(*ts) { + case 0: + if (ctx->enc_type != 0 && ctx->head == NULL) { + __Pyx_BufFmt_RaiseExpected(ctx); + return NULL; + } + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + if (ctx->head != NULL) { + __Pyx_BufFmt_RaiseExpected(ctx); + return NULL; + } + return ts; + case ' ': + case 10: + case 13: + ++ts; + break; + case '<': + if (!__Pyx_IsLittleEndian()) { + PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler"); + return NULL; + } + if (__Pyx_BufFmt_FirstPack(ctx) == -1) return NULL; + ctx->packmode = '='; + ++ts; + break; + case '>': + case '!': + if (__Pyx_IsLittleEndian()) { + PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler"); + return NULL; + } + if (__Pyx_BufFmt_FirstPack(ctx) == -1) return NULL; + ctx->packmode = '='; + ++ts; + break; + case '=': + case '@': + case '^': + if (__Pyx_BufFmt_FirstPack(ctx) == -1) return NULL; + ctx->packmode = *ts++; + break; + case 'T': /* substruct */ + { + int i; + const char* ts_after_sub; + int struct_count = ctx->new_count; + ctx->new_count = 1; + ++ts; + if (*ts != '{') { + PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'"); + return NULL; + } + ++ts; + ts_after_sub = ts; + for (i = 0; i != struct_count; ++i) { + ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts); + if (!ts_after_sub) return NULL; + } + ts = ts_after_sub; + } + break; + case '}': /* end of substruct; either repeat or move on */ + ++ts; + return ts; + case 'x': + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->fmt_offset += ctx->new_count; + ctx->new_count = 1; + ctx->enc_count = 0; + ctx->enc_type = 0; + ++ts; + break; + case 'Z': + got_Z = 1; + ++ts; + if (*ts != 'f' && *ts != 'd' && *ts != 'g') { + __Pyx_BufFmt_RaiseUnexpectedChar('Z'); + return NULL; + } /* fall through */ + case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I': + case 'l': case 'L': case 'q': case 'Q': + case 'f': case 'd': case 'g': + case 'O': + if (ctx->enc_type == *ts && got_Z == ctx->is_complex) { + /* Continue pooling same type */ + ctx->enc_count += ctx->new_count; + } else { + /* New type */ + if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL; + ctx->enc_count = ctx->new_count; + ctx->enc_type = *ts; + ctx->is_complex = got_Z; + } + ++ts; + ctx->new_count = 1; + got_Z = 0; + break; + default: + { + ctx->new_count = __Pyx_BufFmt_ParseNumber(&ts); + if (ctx->new_count == -1) { /* First char was not a digit */ + char msg[2] = { *ts, 0 }; + PyErr_Format(PyExc_ValueError, + "Does not understand character buffer dtype format string ('%s')", msg); + return NULL; + } + } + + } + } +} + +static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) { + buf->buf = NULL; + buf->obj = NULL; + buf->strides = __Pyx_zeros; + buf->shape = __Pyx_zeros; + buf->suboffsets = __Pyx_minusones; +} + +static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack) { + if (obj == Py_None) { + __Pyx_ZeroBuffer(buf); + return 0; + } + buf->buf = NULL; + if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail; + if (buf->ndim != nd) { + PyErr_Format(PyExc_ValueError, + "Buffer has wrong number of dimensions (expected %d, got %d)", + nd, buf->ndim); + goto fail; + } + if (!cast) { + __Pyx_BufFmt_Context ctx; + __Pyx_BufFmt_Init(&ctx, stack, dtype); + if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail; + } + if ((unsigned)buf->itemsize != dtype->size) { + PyErr_Format(PyExc_ValueError, + "Item size of buffer (%"PY_FORMAT_SIZE_T"d byte%s) does not match size of '%s' (%"PY_FORMAT_SIZE_T"d byte%s)", + buf->itemsize, (buf->itemsize > 1) ? "s" : "", + dtype->name, + dtype->size, (dtype->size > 1) ? "s" : ""); + goto fail; + } + if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; + return 0; +fail:; + __Pyx_ZeroBuffer(buf); + return -1; +} + +static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) { + if (info->buf == NULL) return; + if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL; + __Pyx_ReleaseBuffer(info); +} +static void __Pyx_RaiseBufferIndexError(int axis) { + PyErr_Format(PyExc_IndexError, + "Out of bounds on buffer access (axis %d)", axis); +} + + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} + +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} + + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact) +{ + if (!type) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (none_allowed && obj == Py_None) return 1; + else if (exact) { + if (Py_TYPE(obj) == type) return 1; + } + else { + if (PyObject_TypeCheck(obj, type)) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%s' has incorrect type (expected %s, got %s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +static void __Pyx_RaiseBufferFallbackError(void) { + PyErr_Format(PyExc_ValueError, + "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!"); +} + + +static CYTHON_INLINE int __Pyx_div_int(int a, int b) { + int q = a / b; + int r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +static CYTHON_INLINE __pyx_t_5numpy_int64_t __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_5numpy_int64_t a, __pyx_t_5numpy_int64_t b) { + __pyx_t_5numpy_int64_t q = a / b; + __pyx_t_5numpy_int64_t r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + #if PY_VERSION_HEX < 0x02050000 + "need more than %d value%s to unpack", (int)index, + #else + "need more than %zd value%s to unpack", index, + #endif + (index == 1) ? "" : "s"); +} + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + #if PY_VERSION_HEX < 0x02050000 + "too many values to unpack (expected %d)", (int)expected); + #else + "too many values to unpack (expected %zd)", expected); + #endif +} + +static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { + if (t == Py_None) { + __Pyx_RaiseNoneNotIterableError(); + } else if (PyTuple_GET_SIZE(t) < index) { + __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); + } else { + __Pyx_RaiseTooManyValuesError(index); + } +} + +#if PY_MAJOR_VERSION < 3 +static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { + #if PY_VERSION_HEX >= 0x02060000 + if (Py_TYPE(obj)->tp_flags & Py_TPFLAGS_HAVE_NEWBUFFER) + return PyObject_GetBuffer(obj, view, flags); + #endif + if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pf_5numpy_7ndarray___getbuffer__(obj, view, flags); + else { + PyErr_Format(PyExc_TypeError, "'%100s' does not have the buffer interface", Py_TYPE(obj)->tp_name); + return -1; + } +} + +static void __Pyx_ReleaseBuffer(Py_buffer *view) { + PyObject* obj = view->obj; + if (obj) { +if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) __pyx_pf_5numpy_7ndarray___releasebuffer__(obj, view); + Py_DECREF(obj); + view->obj = NULL; + } +} + +#endif + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { + PyObject *py_import = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!py_import) + goto bad; + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, NULL); +bad: + Py_XDECREF(empty_list); + Py_XDECREF(py_import); + Py_XDECREF(empty_dict); + return module; +} + +#if PY_MAJOR_VERSION < 3 +static PyObject *__Pyx_GetStdout(void) { + PyObject *f = PySys_GetObject((char *)"stdout"); + if (!f) { + PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); + } + return f; +} + +static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) { + PyObject* v; + int i; + + if (!f) { + if (!(f = __Pyx_GetStdout())) + return -1; + } + for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) { + if (PyFile_SoftSpace(f, 1)) { + if (PyFile_WriteString(" ", f) < 0) + return -1; + } + v = PyTuple_GET_ITEM(arg_tuple, i); + if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0) + return -1; + if (PyString_Check(v)) { + char *s = PyString_AsString(v); + Py_ssize_t len = PyString_Size(v); + if (len > 0 && + isspace(Py_CHARMASK(s[len-1])) && + s[len-1] != ' ') + PyFile_SoftSpace(f, 0); + } + } + if (newline) { + if (PyFile_WriteString("\n", f) < 0) + return -1; + PyFile_SoftSpace(f, 0); + } + return 0; +} + +#else /* Python 3 has a print function */ + +static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) { + PyObject* kwargs = 0; + PyObject* result = 0; + PyObject* end_string; + if (unlikely(!__pyx_print)) { + __pyx_print = __Pyx_GetAttrString(__pyx_b, "print"); + if (!__pyx_print) + return -1; + } + if (stream) { + kwargs = PyDict_New(); + if (unlikely(!kwargs)) + return -1; + if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0)) + goto bad; + if (!newline) { + end_string = PyUnicode_FromStringAndSize(" ", 1); + if (unlikely(!end_string)) + goto bad; + if (PyDict_SetItemString(kwargs, "end", end_string) < 0) { + Py_DECREF(end_string); + goto bad; + } + Py_DECREF(end_string); + } + } else if (!newline) { + if (unlikely(!__pyx_print_kwargs)) { + __pyx_print_kwargs = PyDict_New(); + if (unlikely(!__pyx_print_kwargs)) + return -1; + end_string = PyUnicode_FromStringAndSize(" ", 1); + if (unlikely(!end_string)) + return -1; + if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) { + Py_DECREF(end_string); + return -1; + } + Py_DECREF(end_string); + } + kwargs = __pyx_print_kwargs; + } + result = PyObject_Call(__pyx_print, arg_tuple, kwargs); + if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs)) + Py_DECREF(kwargs); + if (!result) + return -1; + Py_DECREF(result); + return 0; +bad: + if (kwargs != __pyx_print_kwargs) + Py_XDECREF(kwargs); + return -1; +} + +#endif + +static CYTHON_INLINE long __Pyx_pow_long(long b, long e) { + long t = b; + switch (e) { + case 3: + t *= b; + case 2: + t *= b; + case 1: + return t; + case 0: + return 1; + } + if (unlikely(e<0)) return 0; + t = 1; + while (likely(e)) { + t *= (b * (e&1)) | ((~e)&1); /* 1 or b */ + b *= b; + e >>= 1; + } + return t; +} + +static CYTHON_INLINE npy_int64 __Pyx_PyInt_from_py_npy_int64(PyObject* x) { + const npy_int64 neg_one = (npy_int64)-1, const_zero = (npy_int64)0; + const int is_unsigned = const_zero < neg_one; + if (sizeof(npy_int64) == sizeof(char)) { + if (is_unsigned) + return (npy_int64)__Pyx_PyInt_AsUnsignedChar(x); + else + return (npy_int64)__Pyx_PyInt_AsSignedChar(x); + } else if (sizeof(npy_int64) == sizeof(short)) { + if (is_unsigned) + return (npy_int64)__Pyx_PyInt_AsUnsignedShort(x); + else + return (npy_int64)__Pyx_PyInt_AsSignedShort(x); + } else if (sizeof(npy_int64) == sizeof(int)) { + if (is_unsigned) + return (npy_int64)__Pyx_PyInt_AsUnsignedInt(x); + else + return (npy_int64)__Pyx_PyInt_AsSignedInt(x); + } else if (sizeof(npy_int64) == sizeof(long)) { + if (is_unsigned) + return (npy_int64)__Pyx_PyInt_AsUnsignedLong(x); + else + return (npy_int64)__Pyx_PyInt_AsSignedLong(x); + } else if (sizeof(npy_int64) == sizeof(PY_LONG_LONG)) { + if (is_unsigned) + return (npy_int64)__Pyx_PyInt_AsUnsignedLongLong(x); + else + return (npy_int64)__Pyx_PyInt_AsSignedLongLong(x); + } else { + npy_int64 val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_VERSION_HEX < 0x03000000 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } + return (npy_int64)-1; + } +} + +static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int64(npy_int64 val) { + const npy_int64 neg_one = (npy_int64)-1, const_zero = (npy_int64)0; + const int is_unsigned = const_zero < neg_one; + if ((sizeof(npy_int64) == sizeof(char)) || + (sizeof(npy_int64) == sizeof(short))) { + return PyInt_FromLong((long)val); + } else if ((sizeof(npy_int64) == sizeof(int)) || + (sizeof(npy_int64) == sizeof(long))) { + if (is_unsigned) + return PyLong_FromUnsignedLong((unsigned long)val); + else + return PyInt_FromLong((long)val); + } else if (sizeof(npy_int64) == sizeof(PY_LONG_LONG)) { + if (is_unsigned) + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); + else + return PyLong_FromLongLong((PY_LONG_LONG)val); + } else { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + return _PyLong_FromByteArray(bytes, sizeof(npy_int64), + little, !is_unsigned); + } +} + +#if CYTHON_CCOMPLEX + #ifdef __cplusplus + static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { + return ::std::complex< float >(x, y); + } + #else + static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { + return x + y*(__pyx_t_float_complex)_Complex_I; + } + #endif +#else + static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) { + __pyx_t_float_complex z; + z.real = x; + z.imag = y; + return z; + } +#endif + +#if CYTHON_CCOMPLEX +#else + static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) { + return (a.real == b.real) && (a.imag == b.imag); + } + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + z.real = a.real + b.real; + z.imag = a.imag + b.imag; + return z; + } + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + z.real = a.real - b.real; + z.imag = a.imag - b.imag; + return z; + } + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + z.real = a.real * b.real - a.imag * b.imag; + z.imag = a.real * b.imag + a.imag * b.real; + return z; + } + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) { + __pyx_t_float_complex z; + float denom = b.real * b.real + b.imag * b.imag; + z.real = (a.real * b.real + a.imag * b.imag) / denom; + z.imag = (a.imag * b.real - a.real * b.imag) / denom; + return z; + } + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) { + __pyx_t_float_complex z; + z.real = -a.real; + z.imag = -a.imag; + return z; + } + static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) { + return (a.real == 0) && (a.imag == 0); + } + static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) { + __pyx_t_float_complex z; + z.real = a.real; + z.imag = -a.imag; + return z; + } +/* + static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) { +#if HAVE_HYPOT + return hypotf(z.real, z.imag); +#else + return sqrtf(z.real*z.real + z.imag*z.imag); +#endif + } +*/ +#endif + +#if CYTHON_CCOMPLEX + #ifdef __cplusplus + static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { + return ::std::complex< double >(x, y); + } + #else + static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { + return x + y*(__pyx_t_double_complex)_Complex_I; + } + #endif +#else + static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) { + __pyx_t_double_complex z; + z.real = x; + z.imag = y; + return z; + } +#endif + +#if CYTHON_CCOMPLEX +#else + static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) { + return (a.real == b.real) && (a.imag == b.imag); + } + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + z.real = a.real + b.real; + z.imag = a.imag + b.imag; + return z; + } + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + z.real = a.real - b.real; + z.imag = a.imag - b.imag; + return z; + } + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + z.real = a.real * b.real - a.imag * b.imag; + z.imag = a.real * b.imag + a.imag * b.real; + return z; + } + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) { + __pyx_t_double_complex z; + double denom = b.real * b.real + b.imag * b.imag; + z.real = (a.real * b.real + a.imag * b.imag) / denom; + z.imag = (a.imag * b.real - a.real * b.imag) / denom; + return z; + } + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) { + __pyx_t_double_complex z; + z.real = -a.real; + z.imag = -a.imag; + return z; + } + static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) { + return (a.real == 0) && (a.imag == 0); + } + static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) { + __pyx_t_double_complex z; + z.real = a.real; + z.imag = -a.imag; + return z; + } +/* + static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) { +#if HAVE_HYPOT + return hypot(z.real, z.imag); +#else + return sqrt(z.real*z.real + z.imag*z.imag); +#endif + } +*/ +#endif + +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + /* First, check the traceback argument, replacing None with NULL. */ + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + /* Next, replace a missing value with None */ + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + #if PY_VERSION_HEX < 0x02050000 + if (!PyClass_Check(type)) + #else + if (!PyType_Check(type)) + #endif + { + /* Raising an instance. The value should be a dummy. */ + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + /* Normalize to raise , */ + Py_DECREF(value); + value = type; + #if PY_VERSION_HEX < 0x02050000 + if (PyInstance_Check(type)) { + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + Py_INCREF(type); + } + else { + type = 0; + PyErr_SetString(PyExc_TypeError, + "raise: exception must be an old-style class or instance"); + goto raise_error; + } + #else + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + #endif + } + + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} + +#else /* Python 3+ */ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (!PyExceptionClass_Check(type)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + + PyErr_SetObject(type, value); + + if (tb) { + PyThreadState *tstate = PyThreadState_GET(); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } + } + +bad: + return; +} +#endif + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { + const unsigned char neg_one = (unsigned char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned char" : + "value too large to convert to unsigned char"); + } + return (unsigned char)-1; + } + return (unsigned char)val; + } + return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { + const unsigned short neg_one = (unsigned short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned short" : + "value too large to convert to unsigned short"); + } + return (unsigned short)-1; + } + return (unsigned short)val; + } + return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { + const unsigned int neg_one = (unsigned int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned int" : + "value too large to convert to unsigned int"); + } + return (unsigned int)-1; + } + return (unsigned int)val; + } + return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { + const char neg_one = (char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to char" : + "value too large to convert to char"); + } + return (char)-1; + } + return (char)val; + } + return (char)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { + const short neg_one = (short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to short" : + "value too large to convert to short"); + } + return (short)-1; + } + return (short)val; + } + return (short)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { + const signed char neg_one = (signed char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed char" : + "value too large to convert to signed char"); + } + return (signed char)-1; + } + return (signed char)val; + } + return (signed char)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { + const signed short neg_one = (signed short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed short" : + "value too large to convert to signed short"); + } + return (signed short)-1; + } + return (signed short)val; + } + return (signed short)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { + const signed int neg_one = (signed int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed int" : + "value too large to convert to signed int"); + } + return (signed int)-1; + } + return (signed int)val; + } + return (signed int)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { + const unsigned long neg_one = (unsigned long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return PyLong_AsUnsignedLong(x); + } else { + return PyLong_AsLong(x); + } + } else { + unsigned long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned long)-1; + val = __Pyx_PyInt_AsUnsignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { + const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return PyLong_AsUnsignedLongLong(x); + } else { + return PyLong_AsLongLong(x); + } + } else { + unsigned PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsUnsignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { + const long neg_one = (long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return PyLong_AsUnsignedLong(x); + } else { + return PyLong_AsLong(x); + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (long)-1; + val = __Pyx_PyInt_AsLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { + const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return PyLong_AsUnsignedLongLong(x); + } else { + return PyLong_AsLongLong(x); + } + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { + const signed long neg_one = (signed long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return PyLong_AsUnsignedLong(x); + } else { + return PyLong_AsLong(x); + } + } else { + signed long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed long)-1; + val = __Pyx_PyInt_AsSignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { + const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return PyLong_AsUnsignedLongLong(x); + } else { + return PyLong_AsLongLong(x); + } + } else { + signed PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsSignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +#ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, + long size, int strict) +{ + PyObject *py_module = 0; + PyObject *result = 0; + PyObject *py_name = 0; + char warning[200]; + + py_module = __Pyx_ImportModule(module_name); + if (!py_module) + goto bad; + #if PY_MAJOR_VERSION < 3 + py_name = PyString_FromString(class_name); + #else + py_name = PyUnicode_FromString(class_name); + #endif + if (!py_name) + goto bad; + result = PyObject_GetAttr(py_module, py_name); + Py_DECREF(py_name); + py_name = 0; + Py_DECREF(py_module); + py_module = 0; + if (!result) + goto bad; + if (!PyType_Check(result)) { + PyErr_Format(PyExc_TypeError, + "%s.%s is not a type object", + module_name, class_name); + goto bad; + } + if (!strict && ((PyTypeObject *)result)->tp_basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility", + module_name, class_name); + #if PY_VERSION_HEX < 0x02050000 + PyErr_Warn(NULL, warning); + #else + PyErr_WarnEx(NULL, warning, 0); + #endif + } + else if (((PyTypeObject *)result)->tp_basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%s.%s has the wrong size, try recompiling", + module_name, class_name); + goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(py_module); + Py_XDECREF(result); + return 0; +} +#endif + +#ifndef __PYX_HAVE_RT_ImportModule +#define __PYX_HAVE_RT_ImportModule +static PyObject *__Pyx_ImportModule(const char *name) { + PyObject *py_name = 0; + PyObject *py_module = 0; + + #if PY_MAJOR_VERSION < 3 + py_name = PyString_FromString(name); + #else + py_name = PyUnicode_FromString(name); + #endif + if (!py_name) + goto bad; + py_module = PyImport_Import(py_name); + Py_DECREF(py_name); + return py_module; +bad: + Py_XDECREF(py_name); + return 0; +} +#endif + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(const char *funcname) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 0; + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(__pyx_filename); + #else + py_srcfile = PyUnicode_FromString(__pyx_filename); + #endif + if (!py_srcfile) goto bad; + if (__pyx_clineno) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + py_code = PyCode_New( + 0, /*int argcount,*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*int kwonlyargcount,*/ + #endif + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + __pyx_lineno, /*int firstlineno,*/ + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + if (!py_code) goto bad; + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = __pyx_lineno; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else /* Python 3+ has unicode identifiers */ + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +/* Type Conversion Functions */ + +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} + +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { + PyNumberMethods *m; + const char *name = NULL; + PyObject *res = NULL; +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return Py_INCREF(x), x; + m = Py_TYPE(x)->tp_as_number; +#if PY_VERSION_HEX < 0x03000000 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } +#else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } +#endif + if (res) { +#if PY_VERSION_HEX < 0x03000000 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%s__ returned non-%s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject* x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} + +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { +#if PY_VERSION_HEX < 0x02050000 + if (ival <= LONG_MAX) + return PyInt_FromLong((long)ival); + else { + unsigned char *bytes = (unsigned char *) &ival; + int one = 1; int little = (int)*(unsigned char*)&one; + return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); + } +#else + return PyInt_FromSize_t(ival); +#endif +} + +static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { + unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); + if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { + return (size_t)-1; + } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to size_t"); + return (size_t)-1; + } + return (size_t)val; +} + + +#endif /* Py_PYTHON_H */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/_ramses_reader.pyx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/_ramses_reader.pyx Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,843 @@ +""" +Wrapping code for Oliver Hahn's RamsesRead++ + +Author: Matthew Turk +Affiliation: UCSD +Author: Oliver Hahn +Affiliation: KIPAC / Stanford +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 . +""" + +# Cython wrapping code for Oliver Hahn's RAMSES reader +from cython.operator cimport dereference as deref, preincrement as inc +from libc.stdlib cimport malloc, free, abs, calloc, labs + +import numpy as np +cimport numpy as np +cimport cython + +cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): + if i0 > i1: return i0 + return i1 + +cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): + if i0 < i1: return i0 + return i1 + +cdef extern from "" namespace "std": + cdef cppclass vector[T]: + cppclass iterator: + T operator*() + iterator operator++() + bint operator==(iterator) + bint operator!=(iterator) + vector() + void push_back(T&) + T& operator[](int) + T& at(int) + iterator begin() + iterator end() + +cdef extern from "" namespace "std": + cdef cppclass map[A,B]: + pass + +cdef extern from "string" namespace "std": + cdef cppclass string: + string(char *cstr) + char *c_str() + string operator*() + +cdef extern from "RAMSES_typedefs.h": + pass + +cdef extern from "RAMSES_info.hh" namespace "RAMSES": + enum codeversion: + version1 + version2 + version3 + + cdef cppclass snapshot: + string m_filename + codeversion m_version + cppclass info_data: + unsigned ncpu + unsigned ndim + unsigned levelmin + unsigned levelmax + unsigned ngridmax + unsigned nstep_coarse + double boxlen + double time + double aexp + double H0 + double omega_m + double omega_l + double omega_k + double omega_b + double unit_l + double unit_d + double unit_t + + info_data m_header + vector[double] ind_min + vector[double] ind_max + + snapshot(string info_filename, codeversion ver) + + unsigned get_snapshot_num() + unsigned getdomain_bykey( double key ) + + #void hilbert3d(vector[double] &x, vector[double] &y, vector[double] &z, + # vector[double] &order, unsigned bit_length) + +cdef extern from "RAMSES_amr_data.hh" namespace "RAMSES::AMR": + cdef cppclass vec[real_t]: + real_t x, y, z + vec( real_t x_, real_t y_, real_t z_) + vec ( vec& v) + vec ( ) + + # This class definition is out of date. I have unrolled the template + # below. + cdef cppclass cell_locally_essential[id_t, real_t]: + id_t m_neighbor[6] + id_t m_father + id_t m_son[8] + real_t m_xg[3] + id_t m_cpu + + char m_pos + + cell_locally_essential() + + bint is_refined(int ison) + + cdef cppclass RAMSES_cell: + unsigned m_neighbour[6] + unsigned m_father + unsigned m_son[8] + float m_xg[3] + unsigned m_cpu + + char m_pos + + RAMSES_cell() + + bint is_refined(int ison) + + cdef cppclass cell_simple[id_t, real_t]: + id_t m_son[1] + real_t m_xg[3] + id_t m_cpu + + char m_pos + cell_simple() + bint is_refined(int ison) + + # AMR level implementation + + # This class definition is out of date. I have unrolled the template + # below. + cdef cppclass level[Cell_]: + unsigned m_ilevel + vector[Cell_] m_level_cells + double m_xc[8] + double m_yc[8] + double m_zc[8] + + # I skipped the typedefs here + + double m_dx + unsigned m_nx + level (unsigned ilevel) + + void register_cell( Cell_ cell ) + vector[Cell_].iterator begin() + vector[Cell_].iterator end() + + Cell_& operator[]( unsigned i) + unsigned size() + + cdef cppclass RAMSES_level: + unsigned m_ilevel + vector[RAMSES_cell] m_level_cells + double m_xc[8] + double m_yc[8] + double m_zc[8] + + # I skipped the typedefs here + + double m_dx + unsigned m_nx + RAMSES_level (unsigned ilevel) + + void register_cell( RAMSES_cell cell ) + vector[RAMSES_cell].iterator begin() + vector[RAMSES_cell].iterator end() + + RAMSES_cell& operator[]( unsigned i) + unsigned size() + + # This class definition is out of date. I have unrolled the template + # below. + cdef cppclass tree[Cell_, Level_]: + cppclass header: + vector[int] nx + vector[int] nout + vector[int] nsteps + int ncpu + int ndim + int nlevelmax + int ngridmax + int nboundary + int ngrid_current + double boxlen + vector[double] tout + vector[double] aout + vector[double] dtold + vector[double] dtnew + vector[double] cosm + vector[double] timing + double t + double mass_sph + + vector[Level_] m_AMR_levels + vector[unsigned] mheadl, m_numbl, m_taill + + int m_cpu + int m_minlevel + int m_maxlevel + string m_fname + unsigned m_ncoarse + header m_header + + # This is from later on in the .hh file ... I don't think we need them + # typedef proto_iterator const_iterator; + # typedef proto_iterator iterator; + + tree (snapshot &snap, int cpu, int maxlevel, int minlevel = 1) + + cppclass tree_iterator "RAMSES::AMR::RAMSES_tree::iterator": + tree_iterator operator*() + RAMSES_cell operator*() + tree_iterator begin() + tree_iterator end() + tree_iterator to_parent() + tree_iterator get_parent() + void next() + bint operator!=(tree_iterator other) + unsigned get_cell_father() + bint is_finest(int ison) + int get_absolute_position() + int get_domain() + + cdef cppclass RAMSES_tree: + # This is, strictly speaking, not a header. But, I believe it is + # going to work alright. + cppclass header: + vector[int] nx + vector[int] nout + vector[int] nsteps + int ncpu + int ndim + int nlevelmax + int ngridmax + int nboundary + int ngrid_current + double boxlen + vector[double] tout + vector[double] aout + vector[double] dtold + vector[double] dtnew + vector[double] cosm + vector[double] timing + double t + double mass_sph + + vector[RAMSES_level] m_AMR_levels + vector[unsigned] mheadl, m_numbl, m_taill + + int m_cpu + int m_minlevel + int m_maxlevel + string m_fname + unsigned m_ncoarse + header m_header + + unsigned size() + + # This is from later on in the .hh file ... I don't think we need them + # typedef proto_iterator const_iterator; + # typedef proto_iterator iterator; + + RAMSES_tree(snapshot &snap, int cpu, int maxlevel, int minlevel) + void read() + + tree_iterator begin(int ilevel) + tree_iterator end(int ilevel) + + tree_iterator begin() + tree_iterator end() + + vec[double] cell_pos_double "cell_pos" (tree_iterator it, unsigned ind) + vec[double] grid_pos_double "grid_pos" (tree_iterator it) + vec[float] cell_pos_float "cell_pos" (tree_iterator it, unsigned ind) + vec[float] grid_pos_float "grid_pos" (tree_iterator it) + +cdef extern from "RAMSES_amr_data.hh" namespace "RAMSES::HYDRO": + enum hydro_var: + density + velocity_x + velocity_y + velocity_z + pressure + metallicit + + char ramses_hydro_variables[][64] + + # There are a number of classes here that we could wrap and utilize. + # However, I will only wrap the methods I know we need. + + # I have no idea if this will work. + cdef cppclass TreeTypeIterator[TreeType_]: + pass + + # This class definition is out of date. I have unrolled the template + # below. + cdef cppclass data[TreeType_, Real_]: + cppclass header: + unsigned ncpu + unsigned nvar + unsigned ndim + unsigned nlevelmax + unsigned nboundary + double gamma + string m_fname + header m_header + + # I don't want to implement proto_data, so we put this here + Real_& cell_value(TreeTypeIterator[TreeType_] &it, int ind) + + unsigned m_nvars + vector[string] m_varnames + map[string, unsigned] m_var_name_map + + data(TreeType_ &AMRtree) + #_OutputIterator get_var_names[_OutputIterator](_OutputIterator names) + void read(string varname) + + cdef cppclass RAMSES_hydro_data: + cppclass header: + unsigned ncpu + unsigned nvar + unsigned ndim + unsigned nlevelmax + unsigned nboundary + double gamma + string m_fname + header m_header + + # I don't want to implement proto_data, so we put this here + double cell_value (tree_iterator &it, int ind) + + unsigned m_nvars + vector[string] m_varnames + map[string, unsigned] m_var_name_map + + RAMSES_hydro_data(RAMSES_tree &AMRtree) + #_OutputIterator get_var_names[_OutputIterator](_OutputIterator names) + void read(string varname) + + vector[vector[double]] m_var_array + +cdef class RAMSES_tree_proxy: + cdef string *snapshot_name + cdef snapshot *rsnap + + cdef RAMSES_tree** trees + cdef RAMSES_hydro_data*** hydro_datas + + cdef int **loaded + + cdef public object field_ind + cdef public object field_names + + # We will store this here so that we have a record, independent of the + # header, of how many things we have allocated + cdef int ndomains, nfields + + def __cinit__(self, char *fn): + cdef int idomain, ifield, ii + cdef RAMSES_tree *local_tree + cdef RAMSES_hydro_data *local_hydro_data + self.snapshot_name = new string(fn) + self.rsnap = new snapshot(deref(self.snapshot_name), version3) + # We now have to get our field names to fill our array + self.trees = \ + malloc(sizeof(RAMSES_tree*) * self.rsnap.m_header.ncpu) + self.hydro_datas = \ + malloc(sizeof(RAMSES_hydro_data**) * self.rsnap.m_header.ncpu) + self.ndomains = self.rsnap.m_header.ncpu + #for ii in range(self.ndomains): self.trees[ii] = NULL + for idomain in range(1, self.rsnap.m_header.ncpu + 1): + local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + self.rsnap.m_header.levelmax, 0) + local_tree.read() + local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + self.hydro_datas[idomain - 1] = \ + malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) + for ii in range(local_hydro_data.m_nvars): + self.hydro_datas[idomain - 1][ii] = \ + new RAMSES_hydro_data(deref(local_tree)) + self.trees[idomain - 1] = local_tree + # We do not delete anything + if idomain < self.rsnap.m_header.ncpu: del local_hydro_data + # Only once, we read all the field names + self.nfields = local_hydro_data.m_nvars + cdef string *field_name + self.field_names = [] + self.field_ind = {} + self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) + for idomain in range(self.ndomains): + self.loaded[idomain] = malloc( + sizeof(int) * local_hydro_data.m_nvars) + for ifield in range(local_hydro_data.m_nvars): + self.loaded[idomain][ifield] = 0 + for ifield in range(local_hydro_data.m_nvars): + field_name = &(local_hydro_data.m_varnames[ifield]) + # Does this leak? + self.field_names.append(field_name.c_str()) + self.field_ind[self.field_names[-1]] = ifield + # This all needs to be cleaned up in the deallocator + del local_hydro_data + + def __dealloc__(self): + cdef int idomain, ifield + for idomain in range(self.ndomains): + #for ifield in range(self.nfields): + # if self.hydro_datas[idomain][ifield] != NULL: + # del self.hydro_datas[idomain][ifield] + if self.trees[idomain] != NULL: + del self.trees[idomain] + free(self.hydro_datas[idomain]) + free(self.loaded[idomain]) + free(self.trees) + free(self.hydro_datas) + free(self.loaded) + if self.snapshot_name != NULL: del self.snapshot_name + if self.rsnap != NULL: del self.rsnap + + def count_zones(self): + # We need to do simulation domains here + + cdef unsigned idomain, ilevel + cdef RAMSES_tree *local_tree + cdef RAMSES_hydro_data *local_hydro_data + cdef RAMSES_level *local_level + cdef tree_iterator grid_it, grid_end + + # All the loop-local pointers must be declared up here + + cell_count = [] + cdef int local_count = 0 + for ilevel in range(self.rsnap.m_header.levelmax + 1): + cell_count.append(0) + for idomain in range(1, self.rsnap.m_header.ncpu + 1): + local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + self.rsnap.m_header.levelmax, 0) + local_tree.read() + local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + for ilevel in range(local_tree.m_maxlevel + 1): + local_count = 0 + local_level = &local_tree.m_AMR_levels[ilevel] + grid_it = local_tree.begin(ilevel) + grid_end = local_tree.end(ilevel) + while grid_it != grid_end: + local_count += (grid_it.get_domain() == idomain) + grid_it.next() + cell_count[ilevel] += local_count + del local_tree, local_hydro_data + + return cell_count + + def ensure_loaded(self, char *varname, int domain_index): + # this domain_index must be zero-indexed + cdef int varindex = self.field_ind[varname] + cdef string *field_name = new string(varname) + if self.loaded[domain_index][varindex] == 1: + return + print "READING FROM DISK", varname, domain_index, varindex + self.hydro_datas[domain_index][varindex].read(deref(field_name)) + self.loaded[domain_index][varindex] = 1 + del field_name + + def clear_tree(self, char *varname, int domain_index): + # this domain_index must be zero-indexed + # We delete and re-create + cdef int varindex = self.field_ind[varname] + cdef string *field_name = new string(varname) + if self.loaded[domain_index][varindex] == 0: return + del self.hydro_datas[domain_index][varindex] + self.hydro_datas[domain_index - 1][varindex] = \ + new RAMSES_hydro_data(deref(self.trees[domain_index])) + self.loaded[domain_index][varindex] = 0 + del field_name + + def get_file_info(self): + header_info = {} + header_info["ncpu"] = self.rsnap.m_header.ncpu + header_info["ndim"] = self.rsnap.m_header.ndim + header_info["levelmin"] = self.rsnap.m_header.levelmin + header_info["levelmax"] = self.rsnap.m_header.levelmax + header_info["ngridmax"] = self.rsnap.m_header.ngridmax + header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse + header_info["boxlen"] = self.rsnap.m_header.boxlen + header_info["time"] = self.rsnap.m_header.time + header_info["aexp"] = self.rsnap.m_header.aexp + header_info["H0"] = self.rsnap.m_header.H0 + header_info["omega_m"] = self.rsnap.m_header.omega_m + header_info["omega_l"] = self.rsnap.m_header.omega_l + header_info["omega_k"] = self.rsnap.m_header.omega_k + header_info["omega_b"] = self.rsnap.m_header.omega_b + header_info["unit_l"] = self.rsnap.m_header.unit_l + header_info["unit_d"] = self.rsnap.m_header.unit_d + header_info["unit_t"] = self.rsnap.m_header.unit_t + + # Now we grab some from the trees + cdef np.ndarray[np.int32_t, ndim=1] top_grid_dims = np.zeros(3, "int32") + cdef int i + for i in range(3): + # Note that nx is really boundary conditions. We always have 2. + top_grid_dims[i] = self.trees[0].m_header.nx[i] + top_grid_dims[i] = 2 + header_info["nx"] = top_grid_dims + + return header_info + + def fill_hierarchy_arrays(self, + np.ndarray[np.int32_t, ndim=1] top_grid_dims, + np.ndarray[np.float64_t, ndim=2] left_edges, + np.ndarray[np.float64_t, ndim=2] right_edges, + np.ndarray[np.int32_t, ndim=2] grid_levels, + np.ndarray[np.int64_t, ndim=2] grid_file_locations, + np.ndarray[np.int32_t, ndim=2] child_mask): + # We need to do simulation domains here + + cdef unsigned idomain, ilevel + + # All the loop-local pointers must be declared up here + cdef RAMSES_tree *local_tree + cdef RAMSES_hydro_data *local_hydro_data + cdef unsigned father + + cdef tree_iterator grid_it, grid_end, father_it + cdef vec[double] gvec + cdef int grid_ind = 0, grid_aind = 0 + cdef unsigned parent_ind + cdef bint ci + + cdef double grid_half_width + + cdef np.int32_t rr + cell_count = [] + level_cell_counts = {} + for idomain in range(1, self.rsnap.m_header.ncpu + 1): + local_tree = new RAMSES_tree(deref(self.rsnap), idomain, + self.rsnap.m_header.levelmax, 0) + local_tree.read() + local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) + for ilevel in range(local_tree.m_maxlevel + 1): + # this gets overwritten for every domain, which is okay + level_cell_counts[ilevel] = grid_ind + #grid_half_width = self.rsnap.m_header.boxlen / \ + grid_half_width = 1.0 / \ + (2**(ilevel) * top_grid_dims[0]) + grid_it = local_tree.begin(ilevel) + grid_end = local_tree.end(ilevel) + while grid_it != grid_end: + if grid_it.get_domain() != idomain: + grid_ind += 1 + grid_it.next() + continue + gvec = local_tree.grid_pos_double(grid_it) + left_edges[grid_aind, 0] = gvec.x - grid_half_width + left_edges[grid_aind, 1] = gvec.y - grid_half_width + left_edges[grid_aind, 2] = gvec.z - grid_half_width + right_edges[grid_aind, 0] = gvec.x + grid_half_width + right_edges[grid_aind, 1] = gvec.y + grid_half_width + right_edges[grid_aind, 2] = gvec.z + grid_half_width + grid_levels[grid_aind, 0] = ilevel + # Now the harder part + father_it = grid_it.get_parent() + grid_file_locations[grid_aind, 0] = idomain + grid_file_locations[grid_aind, 1] = grid_ind - level_cell_counts[ilevel] + parent_ind = father_it.get_absolute_position() + if ilevel > 0: + # We calculate the REAL parent index + grid_file_locations[grid_aind, 2] = \ + level_cell_counts[ilevel - 1] + parent_ind + else: + grid_file_locations[grid_aind, 2] = -1 + for ci in range(8): + rr = grid_it.is_finest(ci) + child_mask[grid_aind, ci] = rr + grid_ind += 1 + grid_aind += 1 + grid_it.next() + del local_tree, local_hydro_data + + def read_oct_grid(self, char *field, int level, int domain, int grid_id): + + self.ensure_loaded(field, domain - 1) + cdef int varindex = self.field_ind[field] + cdef int i + + cdef np.ndarray[np.float64_t, ndim=3] tr = np.empty((2,2,2), dtype='float64', + order='F') + cdef tree_iterator grid_it, grid_end + cdef double* data = tr.data + + cdef RAMSES_tree *local_tree = self.trees[domain - 1] + cdef RAMSES_hydro_data *local_hydro_data = self.hydro_datas[domain - 1][varindex] + + #inline ValueType_& cell_value( const typename TreeType_::iterator& it, + # int ind ) + #{ + # unsigned ipos = it.get_absolute_position(); + # unsigned ilevel = it.get_level();//-m_minlevel; + # return (m_var_array[ilevel])[m_twotondim*ipos+ind]; + #} + + for i in range(8): + data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] + return tr + + def read_grid(self, char *field, + np.ndarray[np.int64_t, ndim=1] start_index, + np.ndarray[np.int32_t, ndim=1] grid_dims, + np.ndarray[np.float64_t, ndim=3] data, + np.ndarray[np.int32_t, ndim=3] filled, + int level, int ref_factor, + component_grid_info): + cdef int varindex = self.field_ind[field] + cdef RAMSES_tree *local_tree = NULL + cdef RAMSES_hydro_data *local_hydro_data = NULL + + cdef int gi, i, j, k, domain, offset + cdef int ir, jr, kr + cdef int offi, offj, offk, odind + cdef np.int64_t di, dj, dk + cdef np.ndarray[np.int64_t, ndim=1] ogrid_info + cdef np.ndarray[np.int64_t, ndim=1] og_start_index + cdef np.float64_t temp_data + cdef np.int64_t end_index[3] + cdef int to_fill = 0 + # Note that indexing into a cell is: + # (k*2 + j)*2 + i + for i in range(3): + end_index[i] = start_index[i] + grid_dims[i] + for gi in range(len(component_grid_info)): + ogrid_info = component_grid_info[gi] + domain = ogrid_info[0] + #print "Loading", domain, ogrid_info + self.ensure_loaded(field, domain - 1) + local_tree = self.trees[domain - 1] + local_hydro_data = self.hydro_datas[domain - 1][varindex] + offset = ogrid_info[1] + og_start_index = ogrid_info[3:] + for i in range(2*ref_factor): + di = i + og_start_index[0] * ref_factor + if di < start_index[0] or di >= end_index[0]: continue + ir = (i / ref_factor) + for j in range(2 * ref_factor): + dj = j + og_start_index[1] * ref_factor + if dj < start_index[1] or dj >= end_index[1]: continue + jr = (j / ref_factor) + for k in range(2 * ref_factor): + dk = k + og_start_index[2] * ref_factor + if dk < start_index[2] or dk >= end_index[2]: continue + kr = (k / ref_factor) + offi = di - start_index[0] + offj = dj - start_index[1] + offk = dk - start_index[2] + #print offi, filled.shape[0], + #print offj, filled.shape[1], + #print offk, filled.shape[2] + if filled[offi, offj, offk] == 1: continue + + odind = (kr*2 + jr)*2 + ir + temp_data = local_hydro_data.m_var_array[ + level][8*offset + odind] + data[offi, offj, offk] = temp_data + filled[offi, offj, offk] = 1 + to_fill += 1 + return to_fill + +cdef class ProtoSubgrid: + cdef np.int64_t *signature[3] + cdef np.int64_t left_edge[3] + cdef np.int64_t right_edge[3] + cdef np.int64_t dimensions[3] + cdef public np.float64_t efficiency + cdef public object sigs + cdef public object grid_file_locations + cdef public object dd + + @cython.boundscheck(False) + @cython.wraparound(False) + def __cinit__(self, + np.ndarray[np.int64_t, ndim=1] left_index, + np.ndarray[np.int64_t, ndim=1] dimensions, + np.ndarray[np.int64_t, ndim=2] left_edges, + np.ndarray[np.int64_t, ndim=2] right_edges, + np.ndarray[np.int64_t, ndim=2] grid_dimensions, + np.ndarray[np.int64_t, ndim=2] grid_file_locations): + # This also includes the shrinking step. + cdef int i, ci, ng = left_edges.shape[0] + cdef np.ndarray temp_arr + cdef int l0, r0, l1, r1, l2, r2, i0, i1, i2 + cdef np.int64_t temp_l[3], temp_r[3], ncells + cdef np.float64_t efficiency + self.sigs = [] + for i in range(3): + temp_l[i] = left_index[i] + dimensions[i] + temp_r[i] = left_index[i] + self.signature[i] = NULL + for gi in range(ng): + if left_edges[gi,0] > left_index[0]+dimensions[0] or \ + right_edges[gi,0] < left_index[0] or \ + left_edges[gi,1] > left_index[1]+dimensions[1] or \ + right_edges[gi,1] < left_index[1] or \ + left_edges[gi,2] > left_index[2]+dimensions[2] or \ + right_edges[gi,2] < left_index[2]: + #print "Skipping grid", gi, "which lies outside out box" + continue + for i in range(3): + temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) + temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) + for i in range(3): + self.left_edge[i] = i64max(temp_l[i], left_index[i]) + self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) + self.dimensions[i] = self.right_edge[i] - self.left_edge[i] + if self.dimensions[i] <= 0: + self.efficiency = -1.0 + return + self.sigs.append(np.zeros(self.dimensions[i], 'int64')) + #print self.sigs[0].size, self.sigs[1].size, self.sigs[2].size + + # My guess is that this whole loop could be done more efficiently. + # However, this is clear and straightforward, so it is a good first + # pass. + cdef np.ndarray[np.int64_t, ndim=1] sig0, sig1, sig2 + sig0 = self.sigs[0] + sig1 = self.sigs[1] + sig2 = self.sigs[2] + efficiency = 0.0 + cdef int used + self.grid_file_locations = [] + for gi in range(ng): + used = 0 + nnn = 0 + for l0 in range(grid_dimensions[gi, 0]): + i0 = left_edges[gi, 0] + l0 + if i0 < self.left_edge[0]: continue + if i0 >= self.right_edge[0]: break + for l1 in range(grid_dimensions[gi, 1]): + i1 = left_edges[gi, 1] + l1 + if i1 < self.left_edge[1]: continue + if i1 >= self.right_edge[1]: break + for l2 in range(grid_dimensions[gi, 2]): + i2 = left_edges[gi, 2] + l2 + if i2 < self.left_edge[2]: continue + if i2 >= self.right_edge[2]: break + i = i0 - self.left_edge[0] + sig0[i] += 1 + i = i1 - self.left_edge[1] + sig1[i] += 1 + i = i2 - self.left_edge[2] + sig2[i] += 1 + efficiency += 1 + used = 1 + if used == 1: + grid_file_locations[gi,3] = left_edges[gi, 0] + grid_file_locations[gi,4] = left_edges[gi, 1] + grid_file_locations[gi,5] = left_edges[gi, 2] + self.grid_file_locations.append(grid_file_locations[gi,:]) + + self.dd = np.ones(3, dtype='int64') + for i in range(3): + efficiency /= self.dimensions[i] + self.dd[i] = self.dimensions[i] + #print "Efficiency is %0.3e" % (efficiency) + self.efficiency = efficiency + + @cython.boundscheck(False) + @cython.wraparound(False) + def find_split(self): + # First look for zeros + cdef int i, center, ax + cdef np.ndarray[ndim=1, dtype=np.int64_t] axes + cdef np.int64_t strength, zcstrength, zcp + axes = np.argsort(self.dd)[::-1] + cdef np.ndarray[np.int64_t] sig + for axi in range(3): + ax = axes[axi] + center = self.dimensions[ax] / 2 + sig = self.sigs[ax] + for i in range(self.dimensions[ax]): + if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: + #print "zero: %s (%s)" % (i, self.dimensions[ax]) + return 0, ax, i + zcstrength = 0 + zcp = 0 + zca = -1 + cdef int temp + cdef np.int64_t *sig2d + for axi in range(3): + ax = axes[axi] + sig = self.sigs[ax] + sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) + sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 + for i in range(1, self.dimensions[ax] - 1): + sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] + for i in range(1, self.dimensions[ax] - 1): + if sig2d[i] * sig2d[i+1] <= 0: + strength = labs(sig2d[i] - sig2d[i+1]) + if (strength > zcstrength) or \ + (strength == zcstrength and (abs(center - i) < + abs(center - zcp))): + zcstrength = strength + zcp = i + zca = ax + free(sig2d) + #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) + return 1, ax, zcp + + @cython.boundscheck(False) + @cython.wraparound(False) + def get_properties(self): + cdef np.ndarray[np.int64_t, ndim=2] tr = np.empty((3,3), dtype='int64') + cdef int i + for i in range(3): + tr[0,i] = self.left_edge[i] + tr[1,i] = self.right_edge[i] + tr[2,i] = self.dimensions[i] + return tr diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +""" +API for yt.frontends.ramses + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .data_structures import \ + RAMSESGrid, \ + RAMSESHierarchy, \ + RAMSESStaticOutput + +from .fields import \ + RAMSESFieldContainer, \ + RAMSESFieldInfo, \ + add_ramses_field + +from .io import \ + IOHandlerRAMSES diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,385 @@ +""" +RAMSES-specific data structures + +Author: Matthew Turk +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 . +""" + +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 _ramses_reader +from .fields import RAMSESFieldContainer + +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 RAMSESGrid(AMRGridPatch): + _id_offset = 0 + #__slots__ = ["_level_id", "stop_index"] + def __init__(self, id, hierarchy, level, locations, start_index): + AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename, + hierarchy = hierarchy) + self.Level = level + self.Parent = [] + self.Children = [] + self.locations = locations + self.start_index = start_index.copy() + + def _setup_dx(self): + # So first we figure out what the index is. We don't assume + # that dx=dy=dz , at least here. We probably do elsewhere. + id = self.id - self._id_offset + if len(self.Parent) > 0: + self.dds = self.Parent[0].dds / self.pf.refine_by + else: + LE, RE = self.hierarchy.grid_left_edge[id,:], \ + self.hierarchy.grid_right_edge[id,:] + self.dds = na.array((RE-LE)/self.ActiveDimensions) + if self.pf.dimensionality < 2: self.dds[1] = 1.0 + if self.pf.dimensionality < 3: self.dds[2] = 1.0 + self.data['dx'], self.data['dy'], self.data['dz'] = self.dds + + def get_global_startindex(self): + """ + Return the integer starting index for each dimension at the current + level. + """ + if self.start_index != None: + return self.start_index + if len(self.Parent) == 0: + start_index = self.LeftEdge / self.dds + return na.rint(start_index).astype('int64').ravel() + pdx = self.Parent[0].dds + start_index = (self.Parent[0].get_global_startindex()) + \ + na.rint((self.LeftEdge - self.Parent[0].LeftEdge)/pdx) + self.start_index = (start_index*self.pf.refine_by).astype('int64').ravel() + return self.start_index + + def __repr__(self): + return "RAMSESGrid_%04i (%s)" % (self.id, self.ActiveDimensions) + +class RAMSESHierarchy(AMRHierarchy): + + grid = RAMSESGrid + _handle = None + + def __init__(self,pf,data_style='ramses'): + self.data_style = data_style + self.field_info = RAMSESFieldContainer() + self.parameter_file = weakref.proxy(pf) + # for now, the hierarchy file is the parameter file! + self.hierarchy_filename = self.parameter_file.parameter_filename + self.directory = os.path.dirname(self.hierarchy_filename) + self.tree_proxy = pf.ramses_tree + + self.float_type = na.float64 + AMRHierarchy.__init__(self,pf,data_style) + + def _initialize_data_storage(self): + pass + + def _detect_fields(self): + self.field_list = self.tree_proxy.field_names[:] + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _count_grids(self): + # We have to do all the patch-coalescing here. + level_info = self.tree_proxy.count_zones() + num_ogrids = sum(level_info) + ogrid_left_edge = na.zeros((num_ogrids,3), dtype='float64') + ogrid_right_edge = na.zeros((num_ogrids,3), dtype='float64') + ogrid_levels = na.zeros((num_ogrids,1), dtype='int32') + ogrid_file_locations = na.zeros((num_ogrids,6), dtype='int64') + ochild_masks = na.zeros((num_ogrids, 8), dtype='int32') + self.tree_proxy.fill_hierarchy_arrays( + self.pf.domain_dimensions, + ogrid_left_edge, ogrid_right_edge, + ogrid_levels, ogrid_file_locations, ochild_masks) + # Now we can rescale + mi, ma = ogrid_left_edge.min(), ogrid_right_edge.max() + DL = self.pf.domain_left_edge + DR = self.pf.domain_right_edge + ogrid_left_edge = (ogrid_left_edge - mi)/(ma - mi) * (DR - DL) + DL + ogrid_right_edge = (ogrid_right_edge - mi)/(ma - mi) * (DR - DL) + DL + #import pdb;pdb.set_trace() + # We now have enough information to run the patch coalescing + self.proto_grids = [] + for level in xrange(len(level_info)): + if level_info[level] == 0: continue + ggi = (ogrid_levels == level).ravel() + mylog.info("Re-gridding level %s: %s octree grids", level, ggi.sum()) + nd = self.pf.domain_dimensions * 2**level + dims = na.ones((ggi.sum(), 3), dtype='int64') * 2 + fl = ogrid_file_locations[ggi,:] + # Now our initial protosubgrid + #if level == 6: raise RuntimeError + # We want grids that cover no more than MAX_EDGE cells in every direction + MAX_EDGE = 128 + psgs = [] + left_index = na.rint((ogrid_left_edge[ggi,:]) * nd).astype('int64') + right_index = left_index + 2 + lefts = [na.mgrid[0:nd[i]:MAX_EDGE] for i in range(3)] + #lefts = zip(*[l.ravel() for l in lefts]) + pbar = get_pbar("Re-gridding ", lefts[0].size) + min_ind = na.min(left_index, axis=0) + max_ind = na.max(right_index, axis=0) + for i,dli in enumerate(lefts[0]): + pbar.update(i) + if min_ind[0] > dli + nd[0]: continue + if max_ind[0] < dli: continue + idim = min(nd[0] - dli, MAX_EDGE) + gdi = ((dli <= right_index[:,0]) + & (dli + idim >= left_index[:,0])) + if not na.any(gdi): continue + for dlj in lefts[1]: + if min_ind[1] > dlj + nd[1]: continue + if max_ind[1] < dlj: continue + idim = min(nd[1] - dlj, MAX_EDGE) + gdj = ((dlj <= right_index[:,1]) + & (dlj + idim >= left_index[:,1]) + & (gdi)) + if not na.any(gdj): continue + for dlk in lefts[2]: + if min_ind[2] > dlk + nd[2]: continue + if max_ind[2] < dlk: continue + idim = min(nd[2] - dlk, MAX_EDGE) + gdk = ((dlk <= right_index[:,2]) + & (dlk + idim >= left_index[:,2]) + & (gdj)) + if not na.any(gdk): continue + left = na.array([dli, dlj, dlk]) + domain_left = left.ravel() + initial_left = na.zeros(3, dtype='int64') + domain_left + idims = na.ones(3, dtype='int64') * na.minimum(nd - domain_left, MAX_EDGE) + # We want to find how many grids are inside. + dleft_index = left_index[gdk,:] + dright_index = right_index[gdk,:] + ddims = dims[gdk,:] + dfl = fl[gdk,:] + psg = _ramses_reader.ProtoSubgrid(initial_left, idims, + dleft_index, dright_index, ddims, dfl) + #print "Gridding from %s to %s + %s" % ( + # initial_left, initial_left, idims) + if psg.efficiency <= 0: continue + self.num_deep = 0 + psgs.extend(self._recursive_patch_splitting( + psg, idims, initial_left, + dleft_index, dright_index, ddims, dfl)) + #psgs.extend([psg]) + pbar.finish() + self.proto_grids.append(psgs) + sums = na.zeros(3, dtype='int64') + mylog.info("Final grid count: %s", len(self.proto_grids[level])) + if len(self.proto_grids[level]) == 1: continue + for g in self.proto_grids[level]: + sums += [s.sum() for s in g.sigs] + assert(na.all(sums == dims.prod(axis=1).sum())) + self.num_grids = sum(len(l) for l in self.proto_grids) + + num_deep = 0 + + @num_deep_inc + def _recursive_patch_splitting(self, psg, dims, ind, + left_index, right_index, gdims, fl): + min_eff = 0.1 # This isn't always respected. + if self.num_deep > 40: + # If we've recursed more than 100 times, we give up. + psg.efficiency = min_eff + return [psg] + if psg.efficiency > min_eff or psg.efficiency < 0.0: + return [psg] + tt, ax, fp = psg.find_split() + if (fp % 2) != 0: + if dims[ax] != fp + 1: + fp += 1 + else: + fp -= 1 + #print " " * self.num_deep + "Got ax", ax, "fp", fp + dims_l = dims.copy() + dims_l[ax] = fp + li_l = ind.copy() + if na.any(dims_l <= 0): return [psg] + L = _ramses_reader.ProtoSubgrid( + li_l, dims_l, left_index, right_index, gdims, fl) + #print " " * self.num_deep + "L", tt, L.efficiency + if L.efficiency > 1.0: raise RuntimeError + if L.efficiency <= 0.0: L = [] + elif L.efficiency < min_eff: + L = self._recursive_patch_splitting(L, dims_l, li_l, + left_index, right_index, gdims, fl) + else: + L = [L] + dims_r = dims.copy() + dims_r[ax] -= fp + li_r = ind.copy() + li_r[ax] += fp + if na.any(dims_r <= 0): return [psg] + R = _ramses_reader.ProtoSubgrid( + li_r, dims_r, left_index, right_index, gdims, fl) + #print " " * self.num_deep + "R", tt, R.efficiency + if R.efficiency > 1.0: raise RuntimeError + if R.efficiency <= 0.0: R = [] + elif R.efficiency < min_eff: + R = self._recursive_patch_splitting(R, dims_r, li_r, + left_index, right_index, gdims, fl) + else: + R = [R] + return L + R + + def _parse_hierarchy(self): + # We have important work to do + grids = [] + gi = 0 + for level, grid_list in enumerate(self.proto_grids): + for g in grid_list: + fl = g.grid_file_locations + props = g.get_properties() + self.grid_left_edge[gi,:] = props[0,:] / (2.0**(level+1)) + self.grid_right_edge[gi,:] = props[1,:] / (2.0**(level+1)) + self.grid_dimensions[gi,:] = props[2,:] + self.grid_levels[gi,:] = level + grids.append(self.grid(gi, self, level, fl, props[0,:])) + gi += 1 + self.grids = na.array(grids, dtype='object') + + def _get_grid_parents(self, grid, LE, RE): + mask = na.zeros(self.num_grids, dtype='bool') + grids, grid_ind = self.get_box_grids(LE, RE) + mask[grid_ind] = True + mask = na.logical_and(mask, (self.grid_levels == (grid.Level-1)).flat) + return self.grids[mask] + + def _populate_grid_objects(self): + for gi,g in enumerate(self.grids): + parents = self._get_grid_parents(g, + self.grid_left_edge[gi,:], + self.grid_right_edge[gi,:]) + if len(parents) > 0: + g.Parent.extend(parents.tolist()) + for p in parents: p.Children.append(g) + g._prepare_grid() + g._setup_dx() + self.max_level = self.grid_levels.max() + + def _setup_unknown_fields(self): + for field in self.field_list: + if field in self.parameter_file.field_info: continue + mylog.info("Adding %s to list of fields", field) + cf = None + if self.parameter_file.has_key(field): + def external_wrapper(f): + def _convert_function(data): + return data.convert(f) + return _convert_function + cf = external_wrapper(field) + add_field(field, lambda a, b: None, + convert_function=cf, take_log=False) + + def _setup_derived_fields(self): + self.derived_field_list = [] + + def _setup_data_io(self): + self.io = io_registry[self.data_style](self.tree_proxy) + +class RAMSESStaticOutput(StaticOutput): + _hierarchy_class = RAMSESHierarchy + _fieldinfo_class = RAMSESFieldContainer + _handle = None + + def __init__(self, filename, data_style='ramses', + storage_filename = None): + StaticOutput.__init__(self, filename, data_style) + self.storage_filename = storage_filename + + self.field_info = self._fieldinfo_class() + # hardcoded for now + self.current_time = 0.0 + # These should be explicitly obtained from the file, but for now that + # will wait until a reorganization of the source tree and better + # generalization. + self.dimensionality = 3 + self.refine_by = 2 + self.parameters["HydroMethod"] = 'ramses' + self.parameters["Time"] = 1. # default unit is 1... + + def __repr__(self): + return self.basename.rsplit(".", 1)[0] + + def _set_units(self): + """ + Generates the conversion to various physical _units based on the parameter file + """ + self.units = {} + self.time_units = {} + if len(self.parameters) == 0: + self._parse_parameter_file() + self._setup_nounits_units() + self.conversion_factors = defaultdict(lambda: 1.0) + self.time_units['1'] = 1 + self.units['1'] = 1.0 + self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() + seconds = 1 #self["Time"] + self.time_units['years'] = seconds / (365*3600*24.0) + self.time_units['days'] = seconds / (3600*24.0) + for key in yt2orionFieldsDict: + self.conversion_factors[key] = 1.0 + + def _setup_nounits_units(self): + z = 0 + mylog.warning("Setting 1.0 in code units to be 1.0 cm") + if not self.has_key("TimeUnits"): + mylog.warning("No time units. Setting 1.0 = 1 second.") + self.conversion_factors["Time"] = 1.0 + for unit in mpc_conversion.keys(): + self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] + + def _parse_parameter_file(self): + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[ST_CTIME]) + self.ramses_tree = _ramses_reader.RAMSES_tree_proxy(self.parameter_filename) + rheader = self.ramses_tree.get_file_info() + self.parameters.update(rheader) + self.domain_right_edge = na.ones(3, dtype='float64') \ + * rheader['boxlen'] + self.domain_left_edge = na.zeros(3, dtype='float64') + self.domain_dimensions = na.ones(3, dtype='int32') * 2 + + @classmethod + def _is_valid(self, *args, **kwargs): + if not os.path.basename(args[0]).startswith("info_"): return False + fn = args[0].replace("info_", "amr_").replace(".txt", ".out00001") + print fn + return os.path.exists(fn) + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,61 @@ +""" +RAMSES-specific fields + +Author: Matthew Turk +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 . +""" + +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields + +class RAMSESFieldContainer(CodeFieldInfoContainer): + _shared_state = {} + _field_list = {} +RAMSESFieldInfo = RAMSESFieldContainer() +add_ramses_field = RAMSESFieldInfo.add_field + +add_field = add_ramses_field + +translation_dict = {"Density":"density", + "x-velocity":"velocity_x", + "y-velocity":"velocity_y", + "z-velocity":"velocity_z", + "Pressure":"pressure", + "Metallicity":"metallicity", + } + +def _generate_translation(mine, theirs): + add_field(theirs, function=lambda a, b: b[mine], take_log=True) + +for f,v in translation_dict.items(): + if v not in RAMSESFieldInfo: + add_field(v, function=lambda a,b: None, take_log=False, + validators = [ValidateDataField(v)]) + #print "Setting up translator from %s to %s" % (v, f) + _generate_translation(v, f) + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,57 @@ +""" +RAMSES-specific IO + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +from yt.utilities.io_handler import \ + BaseIOHandler + +class IOHandlerRAMSES(BaseIOHandler): + _data_style = "ramses" + + def __init__(self, ramses_tree, *args, **kwargs): + self.ramses_tree = ramses_tree + BaseIOHandler.__init__(self, *args, **kwargs) + + def _read_data_set(self, grid, field): + tr = na.zeros(grid.ActiveDimensions, dtype='float64') + filled = na.zeros(grid.ActiveDimensions, dtype='int32') + to_fill = grid.ActiveDimensions.prod() + grids = [grid] + l_delta = 0 + while to_fill > 0 and len(grids) > 0: + next_grids = [] + for g in grids: + to_fill -= self.ramses_tree.read_grid(field, + grid.get_global_startindex(), grid.ActiveDimensions, + tr, filled, g.Level, 2**l_delta, g.locations) + next_grids += g.Parent + grids = next_grids + l_delta += 1 + return tr + + def _read_data_slice(self, grid, field, axis, coord): + sl = [slice(None), slice(None), slice(None)] + sl[axis] = slice(coord, coord + 1) + return self._read_data_set(grid, field)[sl] + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/FortranUnformatted_IO.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/FortranUnformatted_IO.hh Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,291 @@ +/* + FortranUnformatted_IO.hh + This file contains a C++ class for access to FORTRAN unformatted files + + Copyright (C) 2008 Oliver Hahn, ojha@gmx.de + + It 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. + + Foobar 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 Foobar. If not, see . +*/ + +#ifndef __FORTRAN_UNFORMATTED_HH +#define __FORTRAN_UNFORMATTED_HH + +#include +#include +#include +#include +#include +#include + +#define DEFAULT_ADDLEN 4 + +//! A class to perform IO on FORTRAN unformatted files +/*! FortranUnformatted provides sequential read access to FORTRAN + unformatted files. + */ +class FortranUnformatted{ + +protected: + std::string m_filename; //!< the file name + std::fstream m_ifs; //!< STL ifstream object + int m_addlen; //!< number of bytes in pre-/suffix data of FORTRAN unformatted data + +public: + + //! constructor for FortranUnformatted + /*! simple constructor for FortranUnformatted + * @param filename the name of the FORTRAN unformatted file to be opened for IO + * @param mode a combination of std::ios_base::openmode determining the mode in which the files are openend + * @param addlen the number of bytes which are pre- & postpended to unformatted arrays giving their size (default=4) + */ + explicit FortranUnformatted( std::string filename, std::ios_base::openmode mode = std::ios_base::in, int addlen=DEFAULT_ADDLEN ) + : m_filename( filename ), + m_ifs( m_filename.c_str(), mode|std::ios::binary ), + m_addlen( addlen ) + { + if(!m_ifs.good() || !m_ifs.is_open() ) + throw std::runtime_error("FortranUnformatted : unable to open file \'" + +m_filename+"\'for read access"); + m_ifs.exceptions ( std::fstream::eofbit | std::fstream::failbit + | std::fstream::badbit ); + } + + //! read data from FORTRAN unformatted file + /*! read a scalar from FORTRAN unformatted file. If the data is not scalar + (i.e. an array) or the function is called with a template parameter of + a different size than the stored data, a std::runtime_error is thrown. + \param r reference to the return value + */ + template< typename T > void read( T& r ) + { + unsigned n1,n2; + + try{ + m_ifs.read( (char*)&n1, m_addlen ); + m_ifs.read( (char*)&r, sizeof(T) ); + m_ifs.read( (char*)&n2, m_addlen ); + }catch(...){ + throw; + } + + if( n1 != sizeof(T) || n1 != n2 ){ + throw std::runtime_error("FortranUnformatted::read : invalid type"\ + " conversion when reading FORTRAN unformatted."); + } + } + + //! write a single variable, arbitrary type to the Fortran unformatted file + /*! + * @param w the variable, arbitrary type + */ + template< typename T > void write( T& w ) + { + unsigned n1 = sizeof(T); + + try{ + m_ifs.write( (char*)&n1, m_addlen ); + m_ifs.write( (char*)&w, n1 ); + m_ifs.write( (char*)&n1, m_addlen ); + }catch(...){ + throw; + } + } + + + //! write a range of a container data object given by iterators + /*! + * @param begin iterator pointing to the beginning of the range + * @param end iterator pointing to the end of the range + */ + template< typename _InputIterator > + void write( _InputIterator begin, _InputIterator end ) + { + _InputIterator it(begin); + unsigned nelem = std::distance(begin,end); + unsigned sz = sizeof(*begin); + unsigned totsz = sz*nelem; + + try{ + m_ifs.write( (char*)&totsz, m_addlen ); + while( it!=end ){ + m_ifs.write( (char*)&(*it), sz ); + ++it; + } + m_ifs.write( (char*)&totsz, m_addlen ); + }catch(...){ + throw; + } + } + + //! read masked data + /*! this function reads data but discards all those for which the iterator + * mask is not set to a 'true' bit. It is necessary that the mask iterator + * can be increased the same number of times as there is data to be read. + * @param mask an iterator which is increased for each element read from the file and determines rejection or not + * @param data an output iterator to which the data is written + */ + template< typename basetype, typename _InputIterator, typename _OutputIterator > + _InputIterator read( _InputIterator mask, _OutputIterator data ) + { + _InputIterator oldmask = mask; + std::vector temp; + typename std::vector::iterator temp_it; + + unsigned n1,n2; + try{ + m_ifs.read( (char*)&n1, m_addlen ); + temp.resize(n1/sizeof(basetype)); + m_ifs.read( (char*)&temp[0], n1 ); + + for( temp_it = temp.begin(); temp_it!=temp.end(); ++temp_it ){ + //... copy data if masked - this also performs a type conversion if needed ...// + if( *mask ) + *data = *temp_it; + oldmask = mask++; + if( mask == oldmask ) break; + } + //std::copy(temp.begin(),temp.end(), data); + + m_ifs.read( (char*)&n2, m_addlen ); + + }catch(...){ + throw std::runtime_error("FortranUnformatted::read : error reading FORTRAN unformatted."); + } + if( n1!=n2 ) + throw std::runtime_error("FortranUnformatted::read : invalid type conversion when"\ + " reading FORTRAN unformatted."); + + return mask; + } + + + //! read data + /*! this function reads data from a Fortran unformatted file and writes it to + * an output iterator. + * @param data an output iterator to which the data is written + */ + template< typename basetype, typename _OutputIterator > + _OutputIterator read( _OutputIterator data ) + { + std::vector temp; + typename std::vector temp_it; + + unsigned n1,n2; + try{ + m_ifs.read( (char*)&n1, m_addlen ); + temp.resize(n1/sizeof(basetype)); + m_ifs.read( (char*)&temp[0], n1 ); + //... copy data - this also performs a type conversion if needed ...// + std::copy(temp.begin(),temp.end(), data); + m_ifs.read( (char*)&n2, m_addlen ); + + }catch(...){ + throw std::runtime_error("FortranUnformatted::read : error reading FORTRAN unformatted."); + } + if( n1!=n2 ) + throw std::runtime_error("FortranUnformatted::read : invalid type conversion when"\ + " reading FORTRAN unformatted."); + + + return data; + } + + //! check if beyond end-of-file + bool eof( void ) + { + bool bcheck; + try{ + bcheck = (m_ifs.peek()==EOF); + }catch(...){ + m_ifs.clear(); + return true; + } + return bcheck; + } + + //! skip ahead in FORTRAN unformatted file + /*! skips n datasets ahead in FORTRAN unformatted file. Equivalent to + * n READ(X) without argument in FORTRAN + * @param n number of entries to skip ahead (scalar or arrays) + */ + void skip_n( unsigned n ) + { + unsigned ndone = 0; + while( ndone < n ){ + int n1, n2; + try{ + m_ifs.read( (char*)&n1, m_addlen ); + m_ifs.seekg( n1, std::ios::cur ); + m_ifs.read( (char*)&n2, m_addlen ); + }catch(...){ + throw std::runtime_error("FortranUnformatted::skip_n : error seeking in FORTRAN unformatted file."); + } + ++ndone; + } + } + + //! just a std::streampos + typedef std::streampos streampos; + + //! wrapper for the std::ifstream::tellg() function + streampos tellg( void ) + { return m_ifs.tellg(); } + + //! wrapper for the std::ifstream::seekg() function + void seekg( streampos pos ) + { m_ifs.seekg( pos ); /*, std::ios::beg );*/ } + + + //! jump to dataset in FORTRAN unformatted files + /*! moves past the nth WRITE(X) operation from the beginning in a FORTRAN + * unformatted file + * @param n number of entries to skip (scalar or arrays) + * @sa skip_n() + */ + void skip_n_from_start( unsigned n ) + { + m_ifs.seekg(0,std::ios::beg); + skip_n( n ); + } + + //! skip ahead in FORTRAN unformatted file + /*! skips to next dataset in FORTRAN unformatted file. Equivalent to a + * READ(X) without argument in FORTRAN + * @sa skip_n + */ + void skip( void ) + { + skip_n(1); + } + + //! rewind file + /*! rewinds the file to the beginning + */ + void rewind( void ) + { + m_ifs.seekg(0,std::ios::beg); + } + + + + /*template< typename T > + friend FortranUnformatted& operator>> (FortranUnformatted &is, T& data); + + template< typename T > + friend FortranUnformatted& operator>> (FortranUnformatted &is, std::vector& data);*/ +}; + + + +#endif //__FORTRAN_UNFORMATTED_HH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/RAMSES_amr_data.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/RAMSES_amr_data.hh Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,970 @@ +/* + This file is part of libRAMSES++ + a C++ library to access snapshot files + generated by the simulation code RAMSES by R. Teyssier + + Copyright (C) 2008-09 Oliver Hahn, ojha@gmx.de + + This program 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 . +*/ + +#ifndef __RAMSES_AMR_DATA_HH +#define __RAMSES_AMR_DATA_HH + +#include +#include +#include +#include +#include +#include +#include + +#include "FortranUnformatted_IO.hh" +#include "RAMSES_info.hh" +#include "RAMSES_amr_data.hh" + +#ifndef FIX +#define FIX(x) ((int)((x)+0.5)) +#endif + +#define ACC_NL(cpu,lvl) ((cpu)+m_header.ncpu*(lvl)) +#define ACC_NLIT(cpu,lvl) ((cpu)+m_plevel->m_header.ncpu*(lvl)) +#define ACC_NB(cpu,lvl) ((cpu)+m_header.nboundary*(lvl)) + +#define LENGTH_POINTERLISTS 4096 +#define ENDPOINT ((unsigned)(-1)) + +namespace RAMSES{ +namespace AMR{ + +/**************************************************************************************\ + *** auxiliary datatypes ************************************************************** +\**************************************************************************************/ + +template< typename real_t> +struct vec{ + real_t x,y,z; + + vec( real_t x_, real_t y_, real_t z_ ) + : x(x_),y(y_),z(z_) + { } + + vec( const vec& v ) + : x(v.x),y(v.y),z(v.z) + { } + + vec( void ) + : x(0.0), y(0.0), z(0.0) + { } +}; + +/**************************************************************************************\ + *** AMR cell base types ************************************************************** +\**************************************************************************************/ + +template +class cell_locally_essential{ +public: + id_t m_neighbour[6]; + id_t m_father; + id_t m_son[8]; + real_t m_xg[3]; + id_t m_cpu; + + char m_pos; + + cell_locally_essential(){} + + bool is_refined( int ison ) const + { return ((int)m_son[ison]!=-1); } +}; + +template +class cell_simple{ +public: + id_t m_son[1]; + real_t m_xg[3]; + id_t m_cpu; + + char m_pos; + + cell_simple(){} + + bool is_refined( int ison=0 ) const + { return ((int)m_son[0]!=-1); } +}; + + +//.... some type traits that are used to distinguish what data needs to be read ....// +template struct is_locally_essential +{ enum { check=false }; }; + +template<> struct is_locally_essential > +{ enum { check=true }; }; + +template<> struct is_locally_essential > +{ enum { check=false }; }; + + +/**************************************************************************************\ + *** AMR level class definition, subsumes a collection of AMR cells ******************* +\**************************************************************************************/ + +//! AMR level implementation +template< typename Cell_ > +class level{ +public: + unsigned m_ilevel; + std::vector< Cell_ > m_level_cells; + + double m_xc[8]; //!< relative x-offsets of the 8 children for current refinement level + double m_yc[8]; //!< relative y-offsets of the 8 children for current refinement level + double m_zc[8]; //!< relative z-offsets of the 8 children for current refinement level + + typedef typename std::vector< Cell_ >::iterator iterator; + typedef typename std::vector< Cell_ >::const_iterator const_iterator; + + double m_dx; + unsigned m_nx; + + level( unsigned ilevel ) + : m_ilevel( ilevel ) + { + m_dx = pow(0.5,ilevel+1); + m_nx = (unsigned)(1.0/m_dx); + + for( unsigned k=1; k<=8; k++ ) + { + //... initialize positions of son cell centres + //... relative to parent cell centre + unsigned + iz=(k-1)/4, + iy=(k-1-4*iz)/2, + ix=(k-1-2*iy-4*iz); + m_xc[k-1]=((double)ix-0.5f)*m_dx; + m_yc[k-1]=((double)iy-0.5f)*m_dx; + m_zc[k-1]=((double)iz-0.5f)*m_dx; + } + } + + void register_cell( const Cell_ & cell ) + { m_level_cells.push_back( cell ); } + + const_iterator begin( void ) const{ return m_level_cells.begin(); } + iterator begin( void ){ return m_level_cells.begin(); } + + const_iterator end( void ) const{ return m_level_cells.end(); } + iterator end( void ){ return m_level_cells.end(); } + + Cell_& operator[]( unsigned i ) + { return m_level_cells[i]; } + + unsigned size( void ) { return m_level_cells.size(); } +}; + + +/**************************************************************************************\ + *** constants ************************************************************************ +\**************************************************************************************/ + +//! neighbour cell access pattern +const static int nbor_cell_map[6][8] = +{ + {1,0,3,2,5,4,7,6}, + {1,0,3,2,5,4,7,6}, + {2,3,0,1,6,7,4,5}, + {2,3,0,1,6,7,4,5}, + {4,5,6,7,0,1,2,3}, + {4,5,6,7,0,1,2,3} +}; + + +/**************************************************************************************\ + *** AMR tree class implements the hierarchy of AMR levels with links ***************** +\**************************************************************************************/ + +/*! + * @class tree + * @brief encapsulates the hierarchical AMR structure data from a RAMSES simulation snapshot + * + * This class provides low-level read access to RAMSES amr_XXXXX.out files. + * Data from a given list of computational domains can be read and is + * stored in internal datastructures. + * Access to hydrodynamical variables stored in the cells is provided + * through member functions of class RAMSES_hydro_level and iterators + * provided by this class + * @sa RAMSES_hydro_level + */ +template< class Cell_, class Level_ > +class tree +{ + +public: + + //! header amr meta-data structure, for details see also RAMSES source code (file amr/init_amr.f90) + struct header{ + std::vector< int > nx; //!< base mesh resolution [3-vector] + std::vector< int > nout; //!< 3 element vector: [noutput2, iout2, ifout2] + std::vector< int > nsteps; //!< 2 element vector: [nstep, nstep_coarse] + int ncpu; //!< number of CPUs (=computational domains) in the simulation + int ndim; //!< number of spatial dimensions + int nlevelmax; //!< maximum refinement level allowed + int ngridmax; //!< maxmium number of grid cells stored per CPU + int nboundary; //!< number of boundary cells (=ghost cells) + int ngrid_current; //!< currently active grid cells + double boxlen; //!< length of the simulation box + std::vector tout; //!< output times (1..noutput) + std::vector aout; //!< output times given as expansion factors (1..noutput) + std::vector dtold; //!< old time steps (1..nlevelmax) + std::vector dtnew; //!< next time steps (1..nlevelmax) + std::vector stat; //!< some diagnostic snapshot meta data: [const, mass_tot0, rho_tot] + std::vector cosm; //!< cosmological meta data: [omega_m, omega_l, omega_k, omega_b, h0, aexp_ini, boxlen_ini) + std::vector timing; //!< timing information: [aexp, hexp, aexp_old, epot_tot_int, epot_tot_old] + double t; //!< time stamp of snapshot + double mass_sph; //!< mass threshold used to flag for cell refinement + }; + + std::vector< Level_ > m_AMR_levels; //! STL vector holding the AMR level hierarchy + + std::vector + m_headl, //!< head indices, point to first active cell + m_numbl, //!< number of active cells + m_taill; //!< tail indices, point to last active cell + + int m_cpu; //! index of computational domain being accessed + int m_minlevel; //! lowest refinement level to be loaded + int m_maxlevel; //! highest refinement level to be loaded + std::string m_fname; //! the snapshot filename amr_XXXXX.out + unsigned m_ncoarse; //! number of coarse grids + struct header m_header; //! the header meta data + + +protected: + + //! prototypical grid iterator + /*! iterates through cells on one level, provides access to neighbours, parents, children + */ + template< typename TreePointer_, typename Index_=unsigned > + class proto_iterator{ + public: + + friend class tree; + + typedef Index_ value_type; + typedef Index_& reference; + typedef Index_* pointer; + + protected: + + Index_ + m_ilevel, //!< refinement level on which we iteratre + m_icpu; //!< domain on which we iterate + + typedef typename std::vector< Cell_ >::const_iterator Iterator_; + Iterator_ m_cell_it; //!< basis iterator that steps through cells on one level + TreePointer_ m_ptree; //!< pointer to associated tree object + + + //! low_level construtor that should only be used from within AMR_tree + proto_iterator( unsigned level_, unsigned cpu_, Iterator_ it_, TreePointer_ ptree_ ) + : m_ilevel(level_), m_icpu(cpu_), m_cell_it(it_), m_ptree( ptree_ ) + { } + + public: + + //! this is either the copy-constructor or a constructor for implicit type conversion + template< typename X > + proto_iterator( proto_iterator &it ) + : m_ilevel( it.m_ilevel ), m_icpu( it.m_icpu ), m_cell_it( it.m_cell_it ), m_ptree( it.m_ptree ) + { } + + //! empty constructor, doesn't initialize anything + proto_iterator() + : m_ilevel(0), m_icpu(0), m_ptree(NULL) + { } + + //! test for equality between two proto_iterator instantiations + template< typename X > + inline bool operator==( const proto_iterator& x ) const + { return m_cell_it==x.m_cell_it; } + + //! test for inequality between two proto_iterator instantiations + template< typename X > + inline bool operator!=( const proto_iterator& x ) const + { return m_cell_it!=x.m_cell_it; } + + //! iterate forward, prefix + inline proto_iterator& operator++() + { ++m_cell_it; return *this; } + + //! iterate forward, postfix + inline proto_iterator operator++(int) + { proto_iterator it(*this); operator++(); return it; } + + inline void next(void) { operator++(); } + + //! iterate backward, prefix + inline proto_iterator& operator--() + { --m_cell_it; return *this; } + + //! iterate backward, postfix + inline proto_iterator operator--(int) + { proto_iterator it(*this); operator--(); return it; } + + //! iterate several forward + inline proto_iterator operator+=(int i) + { proto_iterator it(*this); m_cell_it+=i; return it; } + + //! iterate several backward + inline proto_iterator operator-=(int i) + { proto_iterator it(*this); m_cell_it-=i; return it; } + + //! assign two proto_iterators, this will fail if no typecast between X and TreePoint_ exists + template< typename X > + inline proto_iterator& operator=(const proto_iterator& x) + { m_cell_it = x.m_cell_it; m_ilevel = x.m_ilevel; m_icpu = x.m_icpu; m_ptree = x.m_ptree; return *this; } + + //! iterator dereferencing, returns an array index + inline Cell_ operator*() const + { return *m_cell_it; } + + inline Index_ get_cell_father() const { return (*m_cell_it).m_father; } + inline bool is_finest(int ison) { return !((*m_cell_it).is_refined(ison)); } + + //! move iterator to a child grid + /*! + * @param ind index of the child grid in the parent oct (0..7) + * @return iterator pointing to child grid if it exists, otherwise 'end' of currrent level + */ + //template< typename X > + inline proto_iterator& to_child( int ind ) + { + if( !(*m_cell_it).is_refined(ind) ) + return (*this = m_ptree->end( m_ilevel )); + ++m_ilevel; + m_cell_it = m_ptree->m_AMR_levels[m_ilevel].begin()+(*m_cell_it).m_son[ind]; + return *this; + } + + + //! get an iterator to a child grid + /*! + * @param ind index of the child grid in the parent oct (0..7) + * @return iterator pointing to child grid if it exists, otherwise 'end' of currrent level + */ + //template< typename X > + inline proto_iterator get_child( int ind ) const + { + proto_iterator it(*this); + it.to_child( ind ); + return it; + } + + inline char get_child_from_pos( double x, double y, double z ) const + { + bool bx,by,bz; + bx = x > (*m_cell_it).m_xg[0]; + by = y > (*m_cell_it).m_xg[1]; + bz = z > (*m_cell_it).m_xg[2]; + + //std::cerr << "(" << bx << ", " << by << ", " << bz << ")\n"; + + return (char)bx+2*((char)by+2*(char)bz); + } + + + //! move iterator to the parent grid + /*! + * @return iterator pointing to the parent grid if it exists, 'end' of the current level otherwise + */ + + inline proto_iterator& to_parent( void ) + { + if( m_ilevel==0 ) + return (*this = m_ptree->end( m_ilevel )); + --m_ilevel; + m_cell_it = m_ptree->m_AMR_levels[m_ilevel].begin()+(*m_cell_it).m_father; + return *this; + } + + //! query whether a given child cell is refined + inline bool is_refined( int i ) const + { + return (*m_cell_it).is_refined(i); + } + + //! get an iterator to the parent grid + /*! + * @return iterator pointing to the parent grid if it exists, 'end' of the current level otherwise + */ + inline proto_iterator get_parent( void ) const + { + proto_iterator it(*this); + it.to_parent(); + return it; + } + + //! move iterator to spatial neighbour grid + /*! + * @param ind index of neighbour (0..5) + * @return iterator pointing to neighbour grid if it exists, otherwise 'end' of currrent level + */ + inline proto_iterator& to_neighbour( int ind ) + { + unsigned icell = nbor_cell_map[ind][(int)(*m_cell_it).m_pos]; + m_cell_it = m_ptree->m_AMR_levels[m_ilevel-1].begin()+(*m_cell_it).m_neighbour[ind]; + + if( !(*m_cell_it).is_refined(icell) ) + return (*this = m_ptree->end(m_ilevel)); + + m_cell_it = m_ptree->m_AMR_levels[m_ilevel].begin()+(*m_cell_it).m_son[icell]; + return *this; + } + + //! get an iterator to spatial neighbour grid + /*! + * @param ind index of neighbour (0..5) + * @return iterator pointing to neighbour grid if it exists, otherwise 'end' of currrent level + */ + inline proto_iterator& get_neighbour( int ind ) + { + proto_iterator it(*this); + it.to_neighbour(ind); + return it; + } + + inline Index_ get_level( void ) const + { return m_ilevel; } + + inline int get_domain( void ) const + { return (*m_cell_it).m_cpu; } + + inline int get_absolute_position( void ) const + { + return (unsigned)(std::distance(m_ptree->m_AMR_levels[m_ilevel].begin(),m_cell_it)); + } + + + }; + +public: + + typedef proto_iterator const_iterator; + typedef proto_iterator iterator; + + + +protected: + + //! read header meta data from amr snapshot file + void read_header( void ); + + + + //! generate the amr_XXXXX.out filename for a given computational domain + /*! @param icpu index of comutational domain (base 1) + */ + std::string gen_fname( int icpu ); + + //! generate the amr_XXXXX.out filename from the path to the info_XXXXX.out file + std::string rename_info2amr( const std::string& info ); + + + #define R_SQR(x) ((x)*(x)) + + template< typename Real_ > + inline bool ball_intersection( const vec& xg, double dx2, const vec& xc, Real_ r2 ) + { + Real_ dmin = 0, bmin, bmax; + + //.. x ..// + bmin = xg.x-dx2; + bmax = xg.x+dx2; + if( xc.x < bmin ) dmin += R_SQR(xc.x - bmin ); else + if( xc.x > bmax ) dmin += R_SQR(xc.x - bmax ); + + //.. y ..// + bmin = xg.y-dx2; + bmax = xg.y+dx2; + if( xc.y < bmin ) dmin += R_SQR(xc.y - bmin ); else + if( xc.y > bmax ) dmin += R_SQR(xc.y - bmax ); + + //.. x ..// + bmin = xg.z-dx2; + bmax = xg.z+dx2; + if( xc.z < bmin ) dmin += R_SQR(xc.z - bmin ); else + if( xc.z > bmax ) dmin += R_SQR(xc.z - bmax ); + + if( dmin <= r2 ) return true; + return false; + } + + template< typename Real_ > + inline bool shell_intersection( const vec& xg, double dx2, const vec& xc, Real_ r1_2, Real_ r2_2 ) + { + Real_ dmax = 0, dmin = 0, a, b, bmin, bmax; + if( r1_2 > r2_2 ) std::swap(r1_2,r2_2); + + //.. x ..// + bmin = xg.x-dx2; + bmax = xg.x+dx2; + a = R_SQR( xc.x - bmin ); + b = R_SQR( xc.x - bmax ); + dmax += std::max( a, b ); + if( xc.x < bmin ) dmin += a; else + if( xc.x > bmax ) dmin += b; + + //.. y ..// + bmin = xg.y-dx2; + bmax = xg.y+dx2; + a = R_SQR( xc.y - bmin ); + b = R_SQR( xc.y - bmax ); + dmax += std::max( a, b ); + if( xc.y < bmin ) dmin += a; else + if( xc.y > bmax ) dmin += b; + + //.. z ..// + bmin = xg.z-dx2; + bmax = xg.z+dx2; + a = R_SQR( xc.z - bmin ); + b = R_SQR( xc.z - bmax ); + dmax += std::max( a, b ); + if( xc.z < bmin ) dmin += a; else + if( xc.z > bmax ) dmin += b; + + + if( dmin <= r2_2 && r1_2 <= dmax ) return true; + return false; + } + + template< typename Real_ > + inline bool sphere_intersection( const vec& xg, double dx2, const vec& xc, Real_ r2 ) + { + Real_ dmax = 0, dmin = 0, a, b, bmin, bmax; + + //.. x ..// + bmin = xg.x-dx2; + bmax = xg.x+dx2; + a = R_SQR( xc.x - bmin ); + b = R_SQR( xc.x - bmax ); + dmax += std::max( a, b ); + if( xc.x < bmin ) dmin += a; else + if( xc.x > bmax ) dmin += b; + + //.. y ..// + bmin = xg.y-dx2; + bmax = xg.y+dx2; + a = R_SQR( xc.y - bmin ); + b = R_SQR( xc.y - bmax ); + dmax += std::max( a, b ); + if( xc.y < bmin ) dmin += a; else + if( xc.y > bmax ) dmin += b; + + //.. z ..// + bmin = xg.z-dx2; + bmax = xg.z+dx2; + a = R_SQR( xc.z - bmin ); + b = R_SQR( xc.z - bmax ); + dmax += std::max( a, b ); + if( xc.z < bmin ) dmin += a; else + if( xc.z > bmax ) dmin += b; + + + if( dmin <= r2 && r2 <= dmax ) return true; + return false; + } + + #undef R_SQR + +public: + + //! low-level constructor - should not be called from outside because then you can really screw up things + /*! + * @param snap the associated RAMSES::snapshot object + * @param cpu domain for which to read the AMR tree + * @param maxlevel maximum refinement level to consider + * @param minlevel minimum refinement level to consider (default=1) + */ + tree( RAMSES::snapshot& snap, int cpu, int maxlevel, int minlevel=1 ) + : m_cpu( cpu ), m_minlevel( minlevel ), m_maxlevel( maxlevel ), m_fname( rename_info2amr(snap.m_filename) ) + { + read_header(); + + if( cpu > m_header.ncpu || cpu <= 0) + throw std::runtime_error("RAMSES_particle_data: expect to read from out of range CPU."); + + } + + //! perform the read operation of AMR data + void read( void ); + + //! end const_iterator for given refinement level + const_iterator end( int ilevel ) const + { + if( ilevel <= m_maxlevel ) + return const_iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).end(), this ); + else + return const_iterator( ilevel, m_cpu, m_AMR_levels.at(0).end(), this ); + } + + //! end iterator for given refinement level + iterator end( int ilevel ) + { + if( ilevel <= m_maxlevel ) + return iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).end(), this ); + else + return iterator( ilevel, m_cpu, m_AMR_levels.at(0).end(), this ); + } + + //! begin const_iterator for given refinement level + const_iterator begin( int ilevel ) const + { + if( ilevel <= m_maxlevel ) + return const_iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).begin(), this ); + else + return this->end(ilevel); + } + + //! begin iterator for given refinement level + iterator begin( int ilevel ) + { + if( ilevel <= m_maxlevel ) + return iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).begin(), this ); + else + return this->end(ilevel); + } + + + //! return the center of a child cell associated with a grid iterator + /*! + * @param it grid iterator + * @param ind sub-cell index (0..7) + * @return vec vector containing the coordinates + */ + template< typename Real_ > + inline vec cell_pos( const iterator& it, unsigned ind ) + { + vec pos; + pos.x = (*it).m_xg[0]+m_AMR_levels[it.m_ilevel].m_xc[ind]; + pos.y = (*it).m_xg[1]+m_AMR_levels[it.m_ilevel].m_yc[ind]; + pos.z = (*it).m_xg[2]+m_AMR_levels[it.m_ilevel].m_zc[ind]; + return pos; + } + + //! return the center of the grid associated with a grid iterator + /*! + * @param it grid iterator + * @return vec vector containing the coordinates + */ + template< typename Real_ > + inline vec grid_pos( const iterator& it ) + { + vec pos; + pos.x = (*it).m_xg[0]; + pos.y = (*it).m_xg[1]; + pos.z = (*it).m_xg[2]; + return pos; + } + + template< typename Real_ > + inline bool ball_intersects_grid( const iterator& it, const vec& xc, Real_ r2 ) + { + Real_ dx2 = 0.5/pow(2,it.get_level()); + vec xg = grid_pos(it); + return ball_intersection( xg, dx2, xc, r2 ); + } + + template< typename Real_ > + inline bool ball_intersects_cell( const iterator& it, char ind, const vec& xc, Real_ r2 ) + { + Real_ dx2 = 0.5/pow(2,it.get_level()+1); + vec xg = cell_pos(it,ind); + return ball_intersection( xg, dx2, xc, r2 ); + } + + template< typename Real_ > + inline bool shell_intersects_grid( iterator& it, const vec& xc, Real_ r1_2, Real_ r2_2 ) + { + Real_ dx2 = 0.5/pow(2,it.get_level()); + vec xg = grid_pos(it); + return shell_intersection( xg, dx2, xc, r1_2, r2_2 ); + } + + template< typename Real_ > + inline bool shell_intersects_cell( iterator& it, char ind, const vec& xc, Real_ r1_2, Real_ r2_2 ) + { + Real_ dx2 = 0.5/pow(2,it.get_level()+1); + vec xg = cell_pos(it,ind); + return shell_intersection( xg, dx2, xc, r1_2, r2_2 ); + } + + template< typename Real_ > + inline bool sphere_intersects_grid( const iterator& it, const vec& xc, Real_ r2 ) + { + Real_ dx2 = 0.5/pow(2,it.get_level()); + vec xg = grid_pos(it); + return sphere_intersection( xg, dx2, xc, r2 ); + } + + template< typename Real_ > + inline bool sphere_intersects_cell( const iterator& it, char ind, const vec& xc, Real_ r2 ) + { + Real_ dx2 = 0.5/pow(2,it.get_level()+1); + vec xg = cell_pos(it,ind); + return sphere_intersection( xg, dx2, xc, r2 ); + } + +}; + +/**************************************************************************************\ +\**************************************************************************************/ + +template< class Cell_, class Level_ > +void tree::read_header( void ) +{ + FortranUnformatted ff( gen_fname(m_cpu) ); + + //-- read header data --// + + ff.read( m_header.ncpu ); + ff.read( m_header.ndim ); + ff.read( std::back_inserter(m_header.nx) ); + ff.read( m_header.nlevelmax ); + ff.read( m_header.ngridmax ); + ff.read( m_header.nboundary ); + ff.read( m_header.ngrid_current ); + ff.read( m_header.boxlen ); + + ff.read( std::back_inserter(m_header.nout) ); + ff.read( std::back_inserter(m_header.tout) ); + ff.read( std::back_inserter(m_header.aout) ); + ff.read( m_header.t ); + ff.read( std::back_inserter(m_header.dtold) ); + ff.read( std::back_inserter(m_header.dtnew) ); + ff.read( std::back_inserter(m_header.nsteps) ); + ff.read( std::back_inserter(m_header.stat) ); + ff.read( std::back_inserter(m_header.cosm) ); + ff.read( std::back_inserter(m_header.timing) ); + ff.read( m_header.mass_sph ); + + m_ncoarse = m_header.nx[0]*m_header.nx[1]*m_header.nx[2]; +} + +/**************************************************************************************\ +\**************************************************************************************/ + +template< class Cell_, class Level_ > +std::string tree::gen_fname( int icpu ) +{ + std::string fname; + char ext[32]; + fname = m_fname; + fname.erase(fname.rfind('.')+1); + sprintf(ext,"out%05d",icpu); + fname.append(std::string(ext)); + return fname; +} + +/**************************************************************************************\ +\**************************************************************************************/ + +template< class Cell_, class Level_ > +std::string tree::rename_info2amr( const std::string& info ) +{ + std::string amr; + unsigned ii = info.rfind("info"); + amr = info.substr(0,ii)+"amr" + info.substr(ii+4, 6) + ".out00001"; + return amr; +} + +/**************************************************************************************\ +\**************************************************************************************/ + +template< class Cell_, class Level_ > +void tree::read( void ) +{ + // indexing map used to associate RAMSES internal cell IDs with new IDs + std::map m_ind_grid_map; + + std::vector cell_cpu; + std::vector cell_level; + std::vector itmp; + + + typename std::vector< Level_ >::iterator amr_level_it; + + FortranUnformatted ff( gen_fname( m_cpu ) ); + + //.. skip header entries ..// + ff.skip_n_from_start( 19 ); //.. skip header + + //+ headl + taill + ff.read( std::back_inserter(m_headl) ); + ff.read( std::back_inserter(m_taill) ); + ff.read( std::back_inserter(m_numbl) ); + + //.. skip numbtot + ff.skip_n( 1 ); + + std::vector ngridbound; + if( m_header.nboundary > 0 ){ + ff.skip_n( 2 ); //.. skip headb and tailb + ff.read( std::back_inserter(ngridbound) ); //.. read numbb + } + + ff.skip_n( 6 ); //..skip (1)free_mem+(2)ordering+(3)bound_key+ + //.. (4)coarse_son+(5)coarse_flag1+(6)coarse_cpu_map + + + if( /*m_minlevel < 1 ||*/ m_maxlevel > m_header.nlevelmax || m_minlevel > m_maxlevel ) + throw std::runtime_error("RAMSES_amr_level::read_level : requested level is invalid."); + + + m_ind_grid_map.insert( std::pair(0,ENDPOINT) ); + + FortranUnformatted::streampos spos = ff.tellg(); + + m_minlevel = 0; + + //... create indexing map ...// + for( int ilvl = 0; ilvl<=std::min(m_maxlevel+1, m_header.nlevelmax); ++ilvl ){ + unsigned gridoff = 0; + for( int icpu=0; icpu= m_header.ncpu && ngridbound[ACC_NB(icpu-m_header.ncpu,ilvl)] == 0 ) + continue; + + if( ilvl >= m_minlevel ){ + std::vector ind_grid; + ff.read( std::back_inserter(ind_grid) ); + for( unsigned i=0; i(ind_grid[i],gridoff++) ); + } + ind_grid.clear(); + }else + ff.skip(); + + ff.skip_n( 3+3+6+8+8+8 ); + } + if( ff.eof() ){ + //std::cerr << "eof reached in fortran read operation\n"; + m_maxlevel = ilvl;//+1; + break; + } + } + + ff.seekg( spos ); + + m_AMR_levels.clear(); + + + //... loop over levels ...// + for( int ilvl = 0; ilvl<=m_maxlevel; ++ilvl ){ + m_AMR_levels.push_back( Level_(ilvl) ); + Level_ &currlvl = m_AMR_levels.back(); + + for( int icpu=0; icpu= m_header.ncpu && ngridbound[ACC_NB(icpu-m_header.ncpu,ilvl)] == 0 ) + continue; + + if( ilvl >= m_minlevel ){ + unsigned gridoff = currlvl.size(); + + std::vector ind_grid; + ff.read( std::back_inserter(ind_grid) ); + for( unsigned i=0; i ftmp; + ff.read( std::back_inserter(ftmp) ); + for( unsigned j=0; j( std::back_inserter(ftmp) ); + for( unsigned j=0; j( std::back_inserter(ftmp) ); + for( unsigned j=0; j::check ){ + ff.read( std::back_inserter(itmp) ); + for( unsigned j=0; j::check ) + { + for( unsigned k=0; k<6; ++k ){ + ff.read( std::back_inserter(itmp) ); + for( unsigned j=0; j( std::back_inserter(itmp) ); + for( unsigned k=0; k. +*/ + +#ifndef __RAMSES_HYDRO_DATA_HH +#define __RAMSES_HYDRO_DATA_HH + +#include +#include +#include +#include +#include + +#include "FortranUnformatted_IO.hh" +#include "RAMSES_info.hh" +#include "RAMSES_amr_data.hh" + +namespace RAMSES{ +namespace HYDRO{ + +//! internal hydro variable indices +enum hydro_var +{ + density = 1, + velocity_x = 2, + velocity_y = 3, + velocity_z = 4, + pressure = 5, + metallicity = 6 +}; + +//! names of possible variables stored in a RAMSES hydro file +const char ramses_hydro_variables[][64] = { + {"density"}, + {"velocity_x"}, + {"velocity_y"}, + {"velocity_z"}, + {"pressure"}, + {"metallicity"} }; + + +/**************************************************************************************\ +\**************************************************************************************/ + +/*! + * @class RAMSES::HYDRO::proto_data + * @brief base class for all things hydro + * + * This class provides the base class for all cell based variables defined + * on the AMR mesh, accessible through the tree data structure. + * @sa RAMSES::HYDRO::data, RAMSES::HYDRO::empty_data + */ +template< typename TreeType_, typename ValueType_=double > +class proto_data{ + +public: + std::vector< std::vector > m_var_array; +protected: + TreeType_& m_tree; //!< reference to underlying AMR tree structure + unsigned m_cpu; //!< the computational domain + unsigned + m_minlevel, //!< maximum refinement level to be read from file + m_maxlevel; //!< minimum refinement level to be read from file + unsigned m_twotondim;//!< 2**ndim + unsigned m_ilevel; //!< the refinement level + + //! array holding the actual data + +public: + + //! constructor for the base class of all hydro data objects + /*! + * @param AMRtree reference to the underlying AMR tree data structure object + */ + explicit proto_data( TreeType_& AMRtree ) + : m_tree(AMRtree), m_cpu( AMRtree.m_cpu ), + m_minlevel( AMRtree.m_minlevel ), m_maxlevel( AMRtree.m_maxlevel ), + m_twotondim( (unsigned)(pow(2, AMRtree.m_header.ndim)+0.5) ) + { } + + //! access the value of the cells associated with the oct designated by the iterator + /*! + * @param it the grid iterator pointing to the current oct + * @param ind index of the child cell of the current oct (0..7) + */ + inline ValueType_& cell_value( const typename TreeType_::iterator& it, int ind ) + { + unsigned ipos = it.get_absolute_position(); + unsigned ilevel = it.get_level();//-m_minlevel; + return (m_var_array[ilevel])[m_twotondim*ipos+ind]; + } + + //! access the value of the cells associated with the oct designated by the iterator + /*! + * @param it the grid iterator pointing to the current oct + * @param ind index of the child cell of the current oct (0..7) + */ + inline ValueType_& operator()( const typename TreeType_::iterator& it, int ind ) + { return cell_value(it,ind); } + + + //! combines all elements of this instance with that of another using a binary operator + /*! + * @param o the other data object with which to combine the elements + * @param op the binary operator to be used in combining elements + */ + template + void combine_with( const proto_data& o, const BinaryOperator_& op ) + { + if( m_minlevel != o.m_minlevel || m_maxlevel != o.m_maxlevel + || m_twotondim != o.m_twotondim || &m_tree != &o.m_tree + || m_var_array.size() != o.m_var_array.size() ){ + std::cerr << "this #levels=" << m_var_array.size() << ", other #levels=" << o.m_var_array.size() << std::endl; + throw std::runtime_error("Error: trying to combine incompatible mesh data."); + } + + for( unsigned ilvl=0; ilvl +class empty_data : public proto_data{ + +public: + + //! constructor for an empty hydro variable defined on the AMR mesh + /*! + * @param AMRtree the underlying hierarchical tree data structure + * @param v the value with which the variable should be initialized, default is a (double) zero. + */ + explicit empty_data( TreeType_& AMRtree, ValueType_ v=(ValueType_)0.0 ) + : proto_data(AMRtree) + { + this->m_var_array.assign( this->m_maxlevel+1, std::vector() ); + + for( unsigned ilvl = this->m_minlevel; ilvl<=this->m_maxlevel; ++ilvl ){ + typename TreeType_::iterator grid_it = this->m_tree.begin( ilvl ); + while( grid_it != this->m_tree.end(ilvl) ){ + + for( unsigned j=0;jm_twotondim;++j ) + this->m_var_array[ilvl].push_back( v ); + + ++grid_it; + } + } + } + + + //! write the new hydro variable to a RAMSES compatible output file + /*! + * writes the hydro variable to a RAMSES compatible output file named + * after the convention + * (path)/(basename)_(DOMAIN).out(snap_num) + * + * @param path the path where to store the files + * @param basename the filename base string to prepend to the domain number + * @param snap_num the number of the snapshot (default is zero). + */ + void save( std::string path, std::string basename, unsigned snap_num=0 ) + { + char fullname[256]; + sprintf(fullname,"%s/%s_%05d.out%05d",path.c_str(),basename.c_str(), snap_num, this->m_tree.m_cpu ); + std::ofstream ofs( fullname, std::ios::binary|std::ios::trunc ); + + + typename TreeType_::iterator it; + unsigned ncpu = this->m_tree.m_header.ncpu; + + //std::cerr << "ncpu = " << ncpu << std::endl; + + for( unsigned ilvl = 0; ilvl<=this->m_maxlevel; ++ilvl ){ + std::vector< std::vector > + temp1 (ncpu, std::vector() ), + temp2 (ncpu, std::vector() ), + temp3 (ncpu, std::vector() ), + temp4 (ncpu, std::vector() ), + temp5 (ncpu, std::vector() ), + temp6 (ncpu, std::vector() ), + temp7 (ncpu, std::vector() ), + temp8 (ncpu, std::vector() ); + + it = this->m_tree.begin(ilvl); + + while( it!= this->m_tree.end(ilvl) ) + { + temp1[ it.get_domain()-1 ].push_back( (*this)(it,0) ); + temp2[ it.get_domain()-1 ].push_back( (*this)(it,1) ); + temp3[ it.get_domain()-1 ].push_back( (*this)(it,2) ); + temp4[ it.get_domain()-1 ].push_back( (*this)(it,3) ); + temp5[ it.get_domain()-1 ].push_back( (*this)(it,4) ); + temp6[ it.get_domain()-1 ].push_back( (*this)(it,5) ); + temp7[ it.get_domain()-1 ].push_back( (*this)(it,6) ); + temp8[ it.get_domain()-1 ].push_back( (*this)(it,7) ); + ++it; + } + + + for( unsigned icpu = 0; icpu 0 ) + { + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp1[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp2[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp3[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp4[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp5[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp6[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp7[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + + ofs.write( (char*)&nn, sizeof(unsigned) ); + ofs.write( (char*)&temp8[icpu][0], nn ); + ofs.write( (char*)&nn, sizeof(unsigned) ); + } + } + } + } + + //! reads an additional from a RAMSES compatible (single var) output file + /*! + * @param basename the base string used for the variable + */ + void read( std::string basename ) + { + char fullname[256]; + sprintf(fullname,"%s_%05d.out%05d",basename.c_str(), this->m_tree.m_header.nout[0], this->m_tree.m_cpu ); + std::ifstream ifs( fullname, std::ios::binary ); + + for( unsigned ilvl = this->m_minlevel; ilvl<=this->m_maxlevel; ++ilvl ){ + unsigned nn = this->m_var_array[ilvl].size() * sizeof(ValueType_); + unsigned nnfile; + ifs.read( (char*)&nnfile, sizeof(unsigned) ); + if( nn != nnfile ){ + std::cerr << "Error: dimension mismatch between AMR tree and file data!" << std::endl; + std::cerr << " found " << nnfile << ", expected " << nn << " in file \'" << fullname << "\'" << std::endl; + return; + } + ifs.read( (char*)&this->m_var_array[ilvl][0], nn ); + ifs.read( (char*)&nn, sizeof(unsigned) ); + } + ifs.close(); + } + +}; + + +/**************************************************************************************\ +\**************************************************************************************/ + +/*! + * @class data + * @brief encapsulates hydro data from a RAMSES simulation snapshot + * + * This class provides low-level read access to RAMSES hydro_XXXXX.out files. + * Data from a given list of computational domains can be read and is + * stored in internal datastructures. + * Access to cell position and threaded tree structure of the cell is provided + * through the member functions of class RAMSES_amr_level. + * @sa RAMSES_amr_level + */ +template< typename TreeType_, typename Real_=double > +class data : public proto_data{ + +public: + struct header{ + unsigned ncpu; //!< number of CPUs in simulation + unsigned nvar; //!< number of hydrodynamic variables + unsigned ndim; //!< number of spatial dimensions + unsigned nlevelmax; //!< maximum allowed refinement level + unsigned nboundary; //!< number of boundary regions + double gamma; //!< adiabatic exponent + }; + + + std::string m_fname; //!< the file name + struct header m_header; //!< header meta data + + const unsigned m_nvars; //!< number of variables stored in file + + std::vector m_varnames; //!< names of the variables stored in file + std::map m_var_name_map; //!< a hash table for variable name to internal variable index + + +protected: + + //! generates a hydro_XXXX filename for specified cpu + std::string gen_fname( int icpu ); + + //! generate hydro_XXXXX filename from info filename + std::string rename_info2hydro( const std::string& info ); + + //! generate hydro_XXXXX filename from amr filename + std::string rename_amr2hydro( const std::string& info ); + + //! read header data containing meta information + void read_header( void ); + + //! get internal index for given variable string identifier + /*! + * @param varname the string identifier of the hydro variable + * @return internal variable index + */ + int get_var_idx( const std::string& varname ) + { + int ivar; + std::map::iterator mit; + if( (mit=m_var_name_map.find(varname)) != m_var_name_map.end() ) + ivar = (*mit).second; + else + throw std::runtime_error("RAMSES::HYDRO::data::get_var_idx :"\ + " Error, cannot find variable named \'"+varname+"\'"); + return ivar; + } + + //! perform read operation of one hydro variable (internal use) + /*! + * users should always call the read( std::string ) member function + * and read variables through their string identifiers + * @param var the index of the hydro variable + */ + void read( unsigned var ); + +public: + + //! constructor for hydro data + /*! + * @param AMRtree reference to the underlying tree object + */ + explicit data( TreeType_& AMRtree ) + : proto_data( AMRtree ), + m_fname( rename_amr2hydro(AMRtree.m_fname) ), + m_nvars( 6 ) + { + read_header(); + + if( this->m_cpu > m_header.ncpu || this->m_cpu < 1 ) + throw std::runtime_error("RAMSES::HYDRO::data : expect to read from out of range CPU."); + + if( this->m_minlevel < 0 || this->m_maxlevel >= m_header.nlevelmax ) + throw std::runtime_error("RAMSES::HYDRO::data : requested level is invalid."); + + //m_twotondim = (unsigned)(pow(2,m_header.ndim)+0.5); + + for( unsigned i=0; i( ramses_hydro_variables[i], i+1 ) ); + m_varnames.push_back( ramses_hydro_variables[i] ); + } + } + + //! retrieve the names of variables available in the hydro data source + /*! Variables have an internal index but are accessed through their name, given as a string + * hydro data files may contain different variables depending on the kind of simulation run. + * @param names An output iterator to which std::string designating available variables are sent + * @return Final position of the output iterator + */ + template< typename _OutputIterator > + _OutputIterator get_var_names( _OutputIterator names ) + { + std::vector::iterator it( m_varnames.begin() ); + while( it != m_varnames.end() ){ + *names = *it; + ++it; ++names; + } + return names; + } + + //! perform read operation of one hydro variable + /*! + * @param varname the string identifier of the hydro variable + */ + void read( std::string varname ) + { this->read( get_var_idx( varname ) ); } + +}; + + +template< typename TreeType_, typename Real_ > +void data::read_header( void ) +{ + FortranUnformatted ff( gen_fname( this->m_cpu ) ); + + //-- read header data --// + ff.read( m_header.ncpu ); + ff.read( m_header.nvar ); + ff.read( m_header.ndim ); + ff.read( m_header.nlevelmax ); + ff.read( m_header.nboundary ); + ff.read( m_header.gamma ); +} + + +template< typename TreeType_, typename Real_ > +void data::read( unsigned var ) +{ + this->m_var_array.clear(); + //int twotondim = (int)(pow(2,m_header.ndim)+0.5); + + FortranUnformatted ff( gen_fname( this->m_cpu ) ); + + //.. skip header entries ..// + ff.skip_n_from_start( 6 ); //.. skip header + + if( var < 1 || var > m_header.nvar ) + throw std::runtime_error("RAMSES::HYDRO::data::read : requested variable is invalid in file \'"+m_fname+"\'."); + + this->m_var_array.clear(); + + for( unsigned ilvl = 0; ilvl<=this->m_maxlevel; ++ilvl ){ + + this->m_var_array.push_back( std::vector() ); + + for( unsigned icpu = 0; icpu= this->m_minlevel ){ + if( file_ilevel != ilvl+1 ) + throw std::runtime_error("RAMSES::HYDRO::data::read : corrupted file " \ + "or file seek failure in file \'"+m_fname+"\'."); + + + std::vector tmp; + for( unsigned i=0; im_twotondim; ++i ) + { + ff.skip_n( var-1 ); + ff.read( std::back_inserter(tmp) ); + ff.skip_n( m_header.nvar-var ); + } + //.. reorder array to increase data locality..// + this->m_var_array.reserve( tmp.size() ); + for( unsigned i=0; im_twotondim; ++j ){ + (this->m_var_array.back()).push_back( tmp[i+j*file_ncache] ); + } + } + }else{ + ff.skip_n( this->m_twotondim*m_header.nvar ); + } + } + } +} + + +template< typename TreeType_, typename Real_ > +std::string data::gen_fname( int icpu ) +{ + std::string fname; + char ext[32]; + fname = m_fname; + fname.erase(fname.rfind('.')+1); + sprintf(ext,"out%05d",icpu); + fname.append(std::string(ext)); + return fname; +} + + +template< typename TreeType_, typename Real_ > +std::string data::rename_info2hydro( const std::string& info ) +{ + std::string amr; + unsigned ii = info.rfind("info"); + amr = info.substr(0,ii)+"hydro" + info.substr(ii+4, 6) + ".out00001"; + return amr; +} + + +template< typename TreeType_, typename Real_ > +std::string data::rename_amr2hydro( const std::string& info ) +{ + std::string amr; + unsigned ii = info.rfind("amr"); + amr = info.substr(0,ii)+"hydro" + info.substr(ii+3, 6) + ".out00001"; + return amr; +} + +/**************************************************************************************\ +\**************************************************************************************/ + + +/*! + * @class RAMSES::HYDRO::multi_domain_data + * @brief encapsulates hydro data from multiple computational domain + * + * This class provides high-level data access to bundled domain data, Bundling + * of domain data is useful when analysis of snapshots is performed in parallel + * but on a number of cores different than that used for the RAMSES simulation. + */ +template< typename TreeType_, typename DataType_, typename ValueType_=double > +class multi_domain_data +{ + public: + + unsigned m_ndomains; //!< number of domains bundled + RAMSES::snapshot &m_rsnap; //!< reference to the underlying snapshot object + std::vector m_data; //!< vector of bundled data objects + std::vector m_ptrees; //!< vector of bundled tree objects + + public: + + //! constructor for bundled multi-domain hydro variables + /*! + * @param rsnap reference to the underlying snapshot object + * @param ptrees vector of trees to be bundled + */ + multi_domain_data( RAMSES::snapshot& rsnap, std::vector ptrees ) + : m_ndomains( ptrees.size() ), m_rsnap(rsnap), m_ptrees( ptrees ) + { + for( unsigned idom=0; idom + void combine_with( const multi_domain_data& o, const BinaryOperator& op ) + { + if( m_data.size() != o.m_data.size() ) + throw std::runtime_error("Error: trying to combine incompatible multi_domain_data."); + + for( unsigned i=0; i + m_data[i]->combine_with( *o.m_data[i], op ); + } + + + //! bracket operator to access bundled multi-domain data + /*! + * @param idomain the domain index (1 based) + * @param it tree iterator pointing to the grid in the tree to be accessed + * @param CellIndex index of the cell in the grid + */ + ValueType_& operator() ( unsigned idomain, const typename TreeType_::iterator& it, char CellIndex ) + { + if( idomain >= m_data.size() ){ + std::cerr << "out of range domain: " << idomain << " >= " << m_data.size() << std::endl; + idomain=0; + } + + return m_data[idomain]->cell_value(it,CellIndex); + } + + + //! bracket operator to access bundled multi-domain data (const) + /*! + * @param idomain the domain index (1 based) + * @param it tree const_iterator pointing to the grid in the tree to be accessed + * @param CellIndex index of the cell in the grid + */ + ValueType_& operator() ( unsigned idomain, const typename TreeType_::const_iterator& it, char CellIndex ) + { + if( idomain >= m_data.size() ){ + std::cerr << "out of range domain: " << idomain << " >= " << m_data.size() << std::endl; + idomain=0; + } + return m_data[idomain]->cell_value(it,CellIndex); + } + + //! destructor for bundled multi-domain data + ~multi_domain_data() + { + for( unsigned idom=0; idomread(var_name); + } + } + + //! TBD + unsigned size( void ){ return m_data.size(); } + + //! TBD + unsigned size( unsigned idom ) { return m_data.at(idom)->size(); } +}; + +/**************************************************************************************\ +\**************************************************************************************/ + + +} // namespace HYDRO +} // namespace RAMSES + +#endif //__RAMSES_HYDRO_DATA_HH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/RAMSES_info.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/RAMSES_info.hh Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,334 @@ +/* + This file is part of libRAMSES++ + a C++ library to access snapshot files + generated by the simulation code RAMSES by R. Teyssier + + Copyright (C) 2008-09 Oliver Hahn, ojha@gmx.de + + This program 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 . +*/ + +#ifndef __READ_INFO_HH +#define __READ_INFO_HH + +#include +#include +#include +#include +#include +#include + +namespace RAMSES{ + +#define btest(var,pos) ((var) & (1<<(pos))) + +//! the file format version of RAMSES +enum codeversion{ + version1, version2, version3 +}; + +const int state_diagram[12][2][8] = +{ + { { 1, 2, 3, 2, 4, 5, 3, 5}, { 0, 1, 3, 2, 7, 6, 4, 5} }, + { { 2, 6, 0, 7, 8, 8, 0, 7}, { 0, 7, 1, 6, 3, 4, 2, 5} }, + { { 0, 9,10, 9, 1, 1,11,11}, { 0, 3, 7, 4, 1, 2, 6, 5} }, + { { 6, 0, 6,11, 9, 0, 9, 8}, { 2, 3, 1, 0, 5, 4, 6, 7} }, + { {11,11, 0, 7, 5, 9, 0, 7}, { 4, 3, 5, 2, 7, 0, 6, 1} }, + { { 4, 4, 8, 8, 0, 6,10, 6}, { 6, 5, 1, 2, 7, 4, 0, 3} }, + { { 5, 7, 5, 3, 1, 1,11,11}, { 4, 7, 3, 0, 5, 6, 2, 1} }, + { { 6, 1, 6,10, 9, 4, 9,10}, { 6, 7, 5, 4, 1, 0, 2, 3} }, + { {10, 3, 1, 1,10, 3, 5, 9}, { 2, 5, 3, 4, 1, 6, 0, 7} }, + { { 4, 4, 8, 8, 2, 7, 2, 3}, { 2, 1, 5, 6, 3, 0, 4, 7} }, + { { 7, 2,11, 2, 7, 5, 8, 5}, { 4, 5, 7, 6, 3, 2, 0, 1} }, + { {10, 3, 2, 6,10, 3, 4, 4}, { 6, 1, 7, 0, 5, 2, 4, 3} } +}; + +/**************************************************************************************\ +\**************************************************************************************/ + +/*! + * @class RAMSES_snapshot + * @brief class providing access to general information about a RAMSES simulation snapshot + */ +class snapshot{ + +protected: + + //! c++ input file stream for stream access to the RAMSES info_XXXXX.txt file + std::ifstream m_ifs; + +public: + + //! path and name of the info_XXXXX.txt file of a RAMSES snapshot + std::string m_filename; + + //! the RAMSES version, takes care of changes in file format + codeversion m_version; + + //! the simulation meta data stored in the info file + struct info_data{ + unsigned ncpu; //!< the number of CPUs (and thus computational domains) in this simulation + unsigned ndim; //!< the number of spatial dimensions + unsigned levelmin; //!< minimum refinement level (this refinement is thus present everywhere) + unsigned levelmax; //!< maximum refinement level allowed + unsigned ngridmax; //!< maximum number of grid cells stored per CPU + unsigned nstep_coarse; //!< number of coarse time steps performed up to this snapshot + double boxlen; //!< the length of the simulation box in internal units + double time; //!< time stamp of the snapshot + double aexp; //!< cosmological expansion factor of the current snapshot + double H0; //!< value of the Hubble constant for this simulation + double omega_m; //!< value of the total matter density parameter for this simulation + double omega_l; //!< value of the cosmological constant density parameter for this simulation + double omega_k; //!< value of the curvature density parameter for this simulation + double omega_b; //!< value of the baryonic (i.e. collisional) matter density parameter for this simulation + double unit_l; //!< internal length unit + double unit_d; //!< internal density unit + double unit_t; //!< internal time unit + }; + + //! header data entailing time stamp and parameters of the simulation snapshot + struct info_data m_header; + + //! minimum hilbert ordering indices for each domain + std::vector ind_min; + + //! maximum hilbert ordering indices for each domain + std::vector ind_max; + +protected: + + //! tokenize a string + /*! + * @param str input string + * @param tokens reference to an STL vector containing all substrings after return + */ + void tokenize( const std::string& str, std::vector& tokens ) + { + std::string buf; + std::stringstream ss(str); + while( ss >> buf ) + tokens.push_back( buf ); + } + + //! templated type conversion for string to arbitrary types that can be read from STL stringstreams + /*! + * @param str input string + * @param ret reference to the template parameter type return value + */ + template + inline void convert( const std::string& str, T& ret ) + { + std::stringstream ss(str); + ss >> ret; + } + + //! reads the right-most substring of a line + /*! + * ¶m rhs reference to return value + */ + template + void read_line_rhs( T& rhs ) + { + std::vector split_buf; + std::string buf; + std::getline( m_ifs, buf ); + + tokenize( buf, split_buf ); + convert( split_buf[split_buf.size()-1], rhs ); + } + + //! skip a line in the text input file + void skip_line( void ) + { + std::string buf; + std::getline( m_ifs, buf ); + } + + //! parse the RAMSES snapshot info file + void parse_file( void ) + { + read_line_rhs( m_header.ncpu ); + read_line_rhs( m_header.ndim ); + read_line_rhs( m_header.levelmin ); + read_line_rhs( m_header.levelmax ); + read_line_rhs( m_header.ngridmax ); + read_line_rhs( m_header.nstep_coarse ); + skip_line(); + read_line_rhs( m_header.boxlen ); + read_line_rhs( m_header.time ); + read_line_rhs( m_header.aexp ); + read_line_rhs( m_header.H0 ); + read_line_rhs( m_header.omega_m ); + read_line_rhs( m_header.omega_l ); + read_line_rhs( m_header.omega_k ); + read_line_rhs( m_header.omega_b ); + read_line_rhs( m_header.unit_l ); + read_line_rhs( m_header.unit_d ); + read_line_rhs( m_header.unit_t ); + skip_line(); + skip_line(); + skip_line(); + + for( unsigned i=0; i split_buf; + std::string buf; + std::getline( m_ifs, buf ); + tokenize( buf, split_buf ); + + double imin, imax; + unsigned domain; + + convert( split_buf[0], domain ); + + if( domain != i+1 ) + throw std::runtime_error("RAMSES_snapshot::parse_file : corrupt info file\'"+m_filename+"\'."); + + convert( split_buf[1], imin ); + convert( split_buf[2], imax ); + + ind_min.push_back( imin ); + ind_max.push_back( imax ); + + } + + + } + + inline unsigned locate( const double x, const std::vector& vx ) + { + long unsigned ju,jm,jl; + bool ascnd=(vx[vx.size()-1]>=vx[0]); + jl = 0; + ju = vx.size()-1; + while( ju-jl > 1 ) { + jm = (ju+jl)>>1; + if( x >= vx[jm] == ascnd ) + jl = jm; + else + ju = jm; + } + return std::max((long unsigned)0,std::min((long unsigned)(vx.size()-2),(long unsigned)jl)); + } + +public: + + //! constructor for a RAMSES snapshot meta data object + /*! + * @param info_filename path and name of the info_XXXXX.txt file of the RAMSES simulation + */ + snapshot( std::string info_filename, codeversion ver=RAMSES::version1 ) + : m_ifs( info_filename.c_str(), std::ios::in ), m_filename( info_filename ), + m_version( ver ) + { + if(!m_ifs.good()) + throw std::runtime_error("RAMSES_snapshot : cannot open file \'"+m_filename+"\' for read access."); + m_ifs.exceptions ( std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit ); + + parse_file(); + } + + + unsigned get_snapshot_num( void ) + { + unsigned ii = m_filename.rfind("info"), num; + std::string tmp( m_filename.substr(ii+5,5) ); + sscanf(tmp.c_str(),"%d",&num); + return num; + } + + unsigned getdomain_bykey( double key ) + { + unsigned i = locate( key, ind_min ); + return i+1; + } + + +}; + + +inline void hilbert3d( + const std::vector& x, + const std::vector& y, + const std::vector& z, + std::vector& order, + unsigned bit_length ) +{ + std::vector i_bit_mask(3*bit_length, false ); + std::vector x_bit_mask(1*bit_length, false ); + std::vector y_bit_mask(1*bit_length, false ); + std::vector z_bit_mask(1*bit_length, false ); + + unsigned npoints = x.size(); + double lx = pow(2.0,bit_length); + + for( unsigned ip=0; ip=0; --i ) + { + b2 = i_bit_mask[3*i+2]; + b1 = i_bit_mask[3*i+1]; + b0 = i_bit_mask[3*i+0]; + + sdigit = b2*4+b1*2+b0; + nstate = state_diagram[cstate][0][sdigit]; + hdigit = state_diagram[cstate][1][sdigit]; + + i_bit_mask[3*i+2] = btest(hdigit,2); + i_bit_mask[3*i+1] = btest(hdigit,1); + i_bit_mask[3*i+0] = btest(hdigit,0); + + cstate = nstate; + } + + order[ip] = 0.0; + for( unsigned i=0; i<3*bit_length; ++i ) + { + b0 = i_bit_mask[i]; + order[ip] += (double)b0*pow(2.0,i); + } + + } +} + + +#undef btest + +} + + +#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/RAMSES_particle_data.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/RAMSES_particle_data.hh Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,650 @@ +/* + This file is part of libRAMSES++ + a C++ library to access snapshot files + generated by the simulation code RAMSES by R. Teyssier + + Copyright (C) 2008-09 Oliver Hahn, ojha@gmx.de + + This program 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 . +*/ + +#ifndef __RAMSES_PARTICLE_DATA_HH +#define __RAMSES_PARTICLE_DATA_HH + +#include +#include +#include +#include +#include +#include +#include + +#include "RAMSES_info.hh" +#include "FortranUnformatted_IO.hh" +#include "data_iterators.hh" + +namespace RAMSES{ +namespace PART{ + +//! particle type identifiers returned by RAMSES_particle_data::ptype() +enum ptype_bits { + RAMSES_DM_BIT = 0, + RAMSES_STAR_BIT = 1, + RAMSES_DEBRIS_BIT = 2 +}; + +//! particle type identifiers, can be combined with logical or +enum ptype { + ptype_dm = 1L << RAMSES_DM_BIT, //!< selects dark matter particles + ptype_star = 1L << RAMSES_STAR_BIT, //!< selects star particles + ptype_debris = 1L << RAMSES_DEBRIS_BIT, //!< selects debris particles +}; + +//... zero age of a particle is assumed if age is smaller than this number +const double zero_age = 1.0e-8; + + +//... content of RAMSES particle data files is fixed, available fields +//... are described in the following two fields + + +//! possible variable names in RAMSES particle files in version 1 and 2 files +const char ramses_particle_variables_v12[][64] = { + {"position_x"}, + {"position_y"}, + {"position_z"}, + {"velocity_x"}, + {"velocity_y"}, + {"velocity_z"}, + {"mass"}, + {"age"}, + {"metallicity"}, + {"particle_ID"}, + {"refinement_level"} }; + +//! possible variable names in RAMSES particle files in version 3 files +const char ramses_particle_variables_v3[][64] = { + {"position_x"}, + {"position_y"}, + {"position_z"}, + {"velocity_x"}, + {"velocity_y"}, + {"velocity_z"}, + {"mass"}, + {"particle_ID"}, + {"refinement_level"}, + {"age"}, + {"metallicity"} }; + + +/**************************************************************************************\ +\**************************************************************************************/ + +/*! + * @class RAMSES::PARTICLE::data + * @brief encapsulates particle data from a RAMSES simulation snapshot + * + * This class provides low-level read access to RAMSES particle files. + * Data from a given list of computational domains can be read and is + *stored in internal datastructures. + */ +class data { +protected: + const RAMSES::snapshot *m_pRAMSESsnap; //!< pointer to RAMSES snapshot meta-information + std::string m_fname; //!< path/filename of the .info file + int m_cpu; //!< IDs of computational domains from which data is to be read. + unsigned m_nvars; //!< number of variables available in file + std::vector m_nvar_stride; //!< access offset to variable locations in file + std::vector m_vardim; //!< spatial dimension of a variable + std::vector m_varnames; //!< names of the variables + + //! a hash table for variable name to internal variable index + std::map m_var_name_map; + + //! particle file header meta data + struct header{ + std::vector< int > localseed; //!< local seed used to generate star particles + int ncpu; //!< number of CPUs in the simulation + int ndim; //!< number of spatial dimensions + int nstar_tot; //!< total number of star particles + int nsink; //!< number of sink particles + int npart; //!< number of particles + int npart_dm; //!< number of dark matter particles + int npart_star; //!< number of star particles + int npart_debris; //!< number of debris particles + double mstar_tot; //!< total stellar mass + double mstar_lost; //!< stellar mass lost + }; + + struct header m_header; //!< particle file header data + + + //! generate the part_XXXXX.oYYYYY filename for a given CPU ID + std::string gen_fname( int icpu ); + + //! generate the part_XXXXX.oYYYYY filename from the info_XXXXX.oYYYYY filename. + std::string rename_info2part( const std::string& info ); + + //! Read header from particle files and determine total number of particles. + void read_header( void ); + +public: + + //! constructor for a RAMSES particle data interface + /*! The constructor checks the validity of the requested computational + * domains and reads the particle header data to determine the total + * number of particles. + * @param snap reference to the underlying snapshot object + * @param cpu the domain number + */ + data( const RAMSES::snapshot& snap, int cpu ) + : m_pRAMSESsnap( &snap ), + m_fname( rename_info2part(snap.m_filename) ), + m_cpu( cpu ) + { + m_header.npart_dm = 0; + m_header.npart_star = 0; + m_header.npart_debris = 0, + + read_header(); + + //... compute offsets of variable arrays in file and access hash map ...// + m_nvar_stride.push_back(0); + + + switch( m_pRAMSESsnap->m_version ) + { + case RAMSES::version1: + case RAMSES::version2: + + if( m_header.nstar_tot > 0 ) + { + //... file contains star particles ...// + m_nvars = 11; + for( unsigned i=0; i( ramses_particle_variables_v12[i], i ) ); + m_varnames.push_back( ramses_particle_variables_v12[i] ); + } + } + else + { + //... file contains only DM particles, then some fields are not available + m_nvars = 9; + for( unsigned i=0,j=0; i( ramses_particle_variables_v12[j], i ) ); + m_varnames.push_back( ramses_particle_variables_v12[j] ); + } + } + + break; + + case RAMSES::version3: + + if( m_header.nstar_tot > 0 ) + //... file contains star particles ...// + m_nvars = 11; + else + //... file contains only DM particles, then last fields are not available + m_nvars = 9; + + for( unsigned i=0; i( ramses_particle_variables_v3[i], i ) ); + m_varnames.push_back( ramses_particle_variables_v3[i] ); + } + + break; + + + default: + throw std::runtime_error("RAMSES::PART::data: cannot handle data for this RAMSES version."); + } + + //... check if supplied range of domains is valid ...// + if( m_cpu < 1 || m_cpu > m_header.ncpu ) + throw std::runtime_error("RAMSES::PART::data: attempt to read from out of range CPU."); + } + + + //=== implementation of interface derived compatible to multi variable data source skeleton ===// + //=== see file README.devel, section 1, for details on the interface skeleton ===// + + //! retrieve the names of variables available in the particle data source + /*! Variables have an internal index but are accessed through their name, given as a string + * Particle data files may contain different variables depending on the kind of simulation run. + * @param names An output iterator to which std::string designating available variables are sent + * @return Final position of the output iterator + */ + template< typename _OutputIterator > + _OutputIterator get_var_names( _OutputIterator names ) + { + std::vector::iterator it( m_varnames.begin() ); + while( it != m_varnames.end() ){ + *names = *it; + ++it; ++names; + } + return names; + } + +protected: + + //! return the internal index for a variable of specified name + /*! throws a runtime_error exception if variable name does not exist + * @param varname string designating the variable + * @return internal index of variable + */ + int get_var_idx( const std::string& varname ) + { + int ivar; + std::map::iterator mit; + if( (mit=m_var_name_map.find(varname)) != m_var_name_map.end() ) + ivar = (*mit).second; + else + throw std::runtime_error("RAMSES::PART::data::get_var_idx :"\ + " Error, cannot find variable named \'"+varname+"\'"); + return ivar; + } + + + //! get spatial dimensionality of a variable + int get_var_dim( int ivar ) + { return m_vardim[ivar]; } + + +public: + + //! get spatial dimensionality of a variable + int get_var_dim( const std::string& varname ) + { return m_vardim[get_var_idx(varname)]; } + + + //! retrieve data of specified variable from data source using a mask access pattern + /*! The data for the specified variable, fixing a spatial dimension, is sent to an + * output iterator. For each read operation, the mask iterator is checked + * and the data is discarded if it points to 'false' + * @param varname name of the variable to be retrieved + * @param mask input iterator supplying the mask access pattern + * @param val output iterator to which the retrieved data is sent + * @return final position of the mask iterator + */ + template< typename _Basetype, typename _InputIterator, typename _OutputIterator > + _InputIterator get_var( const std::string& varname, _InputIterator mask, _OutputIterator val ) + { + unsigned ivar = get_var_idx( varname ); + FortranUnformatted ff( gen_fname(m_cpu) ); + //.. skip header and particle position entries ..// + ff.skip_n_from_start( 8+m_nvar_stride[ivar] ); + mask=ff.read<_Basetype, _InputIterator, _OutputIterator>(mask,val); + + return mask; + } + + + //! retrieve data of specified variable from data source + /*! The data for the specified variable, fixing a spatial dimension, is sent to an + * output iterator. + * @param varname name of the variable to be retrieved + * @param val output iterator to which the retrieved data is sent + * @return final position of the mask iterator + */ + template< typename _Basetype, typename _OutputIterator > + _OutputIterator get_var( const std::string& varname, _OutputIterator val ) + { + unsigned ivar = get_var_idx( varname ); + FortranUnformatted ff( gen_fname(m_cpu) ); + //.. skip header and particle position entries ..// + ff.skip_n_from_start( 8+m_nvar_stride[ivar] ); + ff.read<_Basetype, _OutputIterator>(val); + + return val; + } + + + + //=== the following member functions are simply copied from the skeleton ===// + + + //! generate bit mask for specified particle type + /*! returns a particle type identifier for the given particle index + * this is determined from the age and ID of the particle. Return + * value is RAMSES_PTYPE_DM for dark matter particles (age=0,ID>0), + * RAMSES_PTYPE_STAR for star particles (age>0,ID>0) and + * RAMSES PTYPE_DEBRIS for debris type (SN remnant) particles + * (age>0,ID=0). + * @param ptype particle type, i.e. RAMSES_PTYPE_DM, RAMSES_PTYPE_STAR or RAMSES_PTYPE_DEBRIS + * @param age_first + * @param age_last + * @param ids_first + * @param mask + * @return particle mask iterator + */ + template + _OutputIterator mask_particle_type( int ptype, + const _InputIterator1& age_first, const _InputIterator1& age_last, + const _InputIterator2& ids_first, _OutputIterator mask ) + { + _InputIterator1 age_it=age_first; + _InputIterator2 ids_it=ids_first; + + switch( ptype ) + { + case ptype_dm: + while( age_it != age_last ) + { + if( fabs(*age_it) <= zero_age ) + *mask = true; + else + *mask = false; + ++mask; ++age_it; + } + break; + + case ptype_star: + while( age_it != age_last ) + { + if( fabs(*age_it) > zero_age && (*ids_it) > 0) + *mask = true; + else + *mask = false; + ++mask; ++age_it; ++ids_it; + } + break; + + case ptype_debris: + while( age_it != age_last ) + { + if( fabs(*age_it) > zero_age && (*ids_it) == 0) + *mask = true; + else + *mask = false; + ++mask; ++age_it; ++ids_it; + } + break; + + default: throw std::runtime_error("get_particle_type_mask: Error, invalid particle type."); + } + + return mask; + } + + + + + //! generate bit mask for a specified bounding region + /*! Checks whether data points lie within a given region. The _BoundingRegion class object + * must return true or false for a call of 'region(x,y,z)' if the point (x,y,z) + * does or does not lie in the desired region. + * @param region A region object used for querying whether points lie in a desired subspace. + * @param x_first Input iterator pointing on first x-coordinate + * @param x_last Input iterator pointing behind last x-coordinate + * @param y_first Input iterator pointing on first y-coordinate + * @param z_first Input iterator pointing on first z-coordinate + * @param mask Output iterator to which true/false values are written + * @return Final state of mask iterator + */ + template + _OutputIterator mask_region( _BoundingRegion region, + const _InputIterator& x_first, const _InputIterator& x_last, + const _InputIterator& y_first, const _InputIterator& z_first, + _OutputIterator mask ) + { + _InputIterator xit=x_first, yit=y_first, zit=z_first; + + while( xit != x_last ) + { + *mask = region( *xit, *yit, *zit ); + ++mask; ++xit; ++yit; ++zit; + } + + return mask; + } + +}; + +/**************************************************************************************\ +\**************************************************************************************/ + +#define R_CHECK_BIT(var,pos) ((var) & (1<<(pos))) + +template< typename Real_, typename IDType_ > +inline bool is_of_type( Real_ age, IDType_ id, int ptype ) +{ + //if( ptype==ptype_star ) + if( R_CHECK_BIT( ptype, RAMSES_STAR_BIT ) ) + if( fabs(age)>zero_age && id > 0 ) + return true; + //else return false; + + //if( ptype==ptype_dm ) + if( R_CHECK_BIT( ptype, RAMSES_DM_BIT ) ) + if( fabs(age)<=zero_age ) + return true; + //else return false; + + //if( ptype==ptype_debris ) + if( R_CHECK_BIT( ptype, RAMSES_DEBRIS_BIT ) ) + if( fabs(age) > zero_age && id == 0 ) + return true; + return false; +} + +#undef R_CHECK_BIT + +/**************************************************************************************\ +\**************************************************************************************/ + +inline std::string data::gen_fname( int icpu ) +{ + std::string fname; + char ext[32]; + fname = m_fname; + fname.erase(fname.rfind('.')+1); + sprintf(ext,"out%05d",icpu); + fname.append(std::string(ext)); + return fname; +} + +/**************************************************************************************\ +\**************************************************************************************/ + +inline void data::read_header( void ) +{ + FortranUnformatted ff( gen_fname(m_cpu) ); + + //-- read header data --// + ff.read( m_header.ncpu ); + ff.read( m_header.ndim ); + ff.read( m_header.npart ); + ff.read( std::back_inserter(m_header.localseed) ); + ff.read( m_header.nstar_tot ); + ff.read( m_header.mstar_tot ); + ff.read( m_header.mstar_lost ); + ff.read( m_header.nsink ); + +} + +/**************************************************************************************\ +\**************************************************************************************/ + +inline std::string data::rename_info2part( const std::string& info ) +{ + std::string amr; + unsigned ii = info.rfind("info"); + amr = info.substr(0,ii)+"part" + info.substr(ii+4, 6) + ".out00001"; + return amr; +} + +/**************************************************************************************\ +\**************************************************************************************/ + +/*! + * @class RAMSES::PART::multi_domain_data + * @brief encapsulates particle data from multiple computational domain + * + * This class provides high-level data access to bundled domain data, Bundling + * of domain data is useful when analysis of snapshots is performed in parallel + * but on a number of cores different than that used for the RAMSES simulation. + */ +template< typename TreeType_, typename ValueType_=double > +class multi_domain_data +{ + protected: + unsigned m_ndomains; //!< number of domains bundled + RAMSES::snapshot &m_rsnap; //!< reference to the underlying snapshot object + std::vector< std::vector > m_data; //!< vector of bundled data objects + std::vector m_ptrees; //!< vector of bundled tree objects + + public: + + //! constructor for bundled multi-domain particle data + /*! + * @param rsnap reference to the underlying snapshot object + * @param ptrees vector of trees to be bundled + */ + multi_domain_data( RAMSES::snapshot& rsnap, std::vector ptrees ) + : m_ndomains( ptrees.size() ), m_rsnap(rsnap), m_ptrees( ptrees ) + { } + + + //! access a particle in a specific domain + /*! + * @param idomain the domain ID + * @param ind the particle index + */ + ValueType_& operator() ( unsigned idomain, unsigned ind ) + { + return m_data[idomain][ind]; + } + + //! access the vector of particle of a specific domain + /*! + * @param idomain the domain ID + */ + std::vector& operator() ( unsigned idomain ) + { + return m_data[idomain]; + } + + //! bundled read functions, reads in multi-domain data + void get_var( std::string var_name ) + { + m_data.clear(); + for( unsigned idom=0; idomm_cpu ); + m_data.push_back( std::vector() ); + local_data.get_var(var_name, std::back_inserter(m_data.back()) ); + } + } + + //! get the pointer to the vector of particles of a specific domain + std::vector* get_vpointer( unsigned idomain ) + { + return &m_data[idomain]; + } + + //! TBD + unsigned size( void ){ return m_data.size(); } + + //! TBD + unsigned size( unsigned idom ) { return m_data.at(idom).size(); } +}; + + +}// namespace PARTICLE + +/**************************************************************************************\ +\**************************************************************************************/ + +namespace GEOM{ + +/**************************************************************************************\ +\**************************************************************************************/ + +//! TBD +class bounding_sphere{ + protected: + double + xc, //!< TBD + yc, //!< TBD + zc, //!< TBD + r, //!< TBD + r2; //!< TBD + + public: + //! TBD + bounding_sphere( double _xc, double _yc, double _zc, double _r ) + : xc(_xc), yc(_yc), zc(_zc), r(_r), r2(r*r) + { } + + //! TBD + inline bool operator()( double x, double y, double z ) + { + double dx(x-xc),dy(y-yc),dz(z-zc); + return dx*dx+dy*dy+dz*dz < r2; + } +}; + +/**************************************************************************************\ +\**************************************************************************************/ +//! TBD +class bounding_box{ + protected: + double + xc, //!< TBD + yc, //!< TBD + zc, //!< TBD + Lx, //!< TBD + Ly, //!< TBD + Lz, //!< TBD + Lx2, //!< TBD + Ly2, //!< TBD + Lz2; //!< TBD + public: + //! TBD + bounding_box( double _xc, double _yc, double _zc, double _Lx, double _Ly, double _Lz ) + : xc(_xc), yc(_yc), zc(_zc), Lx(_Lx), Ly(_Ly), Lz(_Lz), Lx2(0.5*Lx), Ly2(0.5*Ly), Lz2(0.5*Lz) + { } + + //! TBD + inline bool operator()( double x, double y, double z ) + { + double dx(x-xc),dy(y-yc),dz(z-zc); + return fabs(dx). +*/ + +#ifndef __RAMSES_POISSON_DATA_HH +#define __RAMSES_POISSON_DATA_HH + +#include +#include +#include +#include +#include + +#include "FortranUnformatted_IO.hh" +#include "RAMSES_info.hh" +#include "RAMSES_amr_data.hh" + +namespace RAMSES{ +namespace POISSON{ + + +/*! + * @class data + * @brief encapsulates hydro data from a RAMSES simulation snapshot + * + * This class provides low-level read access to RAMSES hydro_XXXXX.out files. + * Data from a given list of computational domains can be read and is + * stored in internal datastructures. + * Access to cell position and threaded tree structure of the cell is provided + * through the member functions of class RAMSES_amr_level. + * @sa RAMSES_amr_level + */ +template< typename TreeType_, typename Real_=double > +class data : public RAMSES::HYDRO::proto_data{ + +public: + + //! the poisson file header structure + struct header{ + unsigned ncpu; //!< number of CPUs in simulation + unsigned ndim; //!< number of spatial dimensions + unsigned nlevelmax; //!< maximum allowed refinement level + unsigned nboundary; //!< number of boundary regions + }; + + + std::string m_fname; //!< the file name + struct header m_header; //!< header meta data + +protected: + //! generates a poisson_XXXX filename for specified cpu + std::string gen_fname( int icpu ); + + //! generate poisson_XXXXX filename from info filename + std::string rename_info2poisson( const std::string& info ); + + //! generate poisson_XXXXX filename from amr filename + std::string rename_amr2poisson( const std::string& info ); + + //! read header data containing meta information + void read_header( void ); + + //! perform read operation of poisson variables (internal use) + /*! + * + */ + void read( void ); + +public: + + //! constructor for poisson solver gravity data + /*! + * @param AMRtree underlying AMR hierarchical tree data structure + */ + explicit data( TreeType_& AMRtree ) + : proto_data( AMRtree ), + m_fname( rename_amr2poisson(AMRtree.m_fname) ) + { + read_header(); + + if( this->m_cpu > m_header.ncpu || this->m_cpu < 1 ) + throw std::runtime_error("RAMSES::POISSON::data : expect to read from out of range CPU."); + + if( this->m_minlevel < 0 || this->m_maxlevel >= m_header.nlevelmax ) + throw std::runtime_error("RAMSES::POISSON::data : requested level is invalid."); + } + + //! access the value of the cells associated with the oct designated by the iterator + /*! + * @param it the grid iterator pointing to the current oct + * @param ind index of the child cell of the current oct (0..7) + * @param idir the cartesian direction of the force vector (0..2) + */ + inline ValueType_& cell_value( const typename TreeType_::iterator& it, int ind, int idir ) + { + unsigned ipos = it.get_absolute_position(); + unsigned ilevel = it.get_level();//-m_minlevel; + return (m_var_array[ilevel])[3*(m_twotondim*ipos+ind)+idir]; + } + + //! access the value of the cells associated with the oct designated by the iterator + /*! + * a call to this function will always fail since the poisson files contain only forces so far + * @param it the grid iterator pointing to the current oct + * @param ind index of the child cell of the current oct (0..7) + */ + inline ValueType_& cell_value( const typename TreeType_::iterator& it, int ind ) + { + throw std::runtime_error("You should not call this two variable cell_value(.,.) function for forces!"); + return (m_var_array[ilevel])[3*(m_twotondim*ipos+ind)]; + } + + //! access the value of the cells associated with the oct designated by the iterator + /*! + * @param it the grid iterator pointing to the current oct + * @param ind index of the child cell of the current oct (0..7) + * @param idir the cartesian direction of the force vector (0..2) + */ + inline ValueType_& operator()( const typename TreeType_::iterator& it, int ind, int idir ) + { return cell_value(it,ind,idir); } + +}; + + +template< typename TreeType_, typename Real_ > +void data::read_header( void ) +{ + FortranUnformatted ff( gen_fname( this->m_cpu ) ); + + //-- read header data --// + ff.read( m_header.ncpu ); + ff.read( m_header.ndim ); + ff.read( m_header.nlevelmax ); + ff.read( m_header.nboundary ); +} + + +template< typename TreeType_, typename Real_ > +void data::read( void ) +{ + this->m_var_array.clear(); + //int twotondim = (int)(pow(2,m_header.ndim)+0.5); + + FortranUnformatted ff( gen_fname( this->m_cpu ) ); + + //.. skip header entries ..// + ff.skip_n_from_start( 4 ); //.. skip header + + this->m_var_array.clear(); + + for( unsigned ilvl = 0; ilvl<=this->m_maxlevel; ++ilvl ){ + + this->m_var_array.push_back( std::vector() ); + + for( unsigned icpu = 0; icpu= this->m_minlevel ){ + if( file_ilevel != ilvl+1 ) + throw std::runtime_error("RAMSES::POISSON::data::read : corrupted file " \ + "or file seek failure in file \'"+m_fname+"\'."); + + + std::vector tmpx,tmpy,tmpz; + for( unsigned i=0; im_twotondim; ++i ) + { + ff.read( std::back_inserter(tmpx) ); //.. x-force + ff.read( std::back_inserter(tmpy) ); //.. y-force + ff.read( std::back_inserter(tmpz) ); //.. z-force + } + //.. reorder array to increase data locality..// + this->m_var_array.reserve( 3*tmpx.size() ); + for( unsigned i=0; im_twotondim; ++j ){ + //... interleave directional data ...// + (this->m_var_array.back()).push_back( tmpx[i+j*file_ncache] ); + (this->m_var_array.back()).push_back( tmpy[i+j*file_ncache] ); + (this->m_var_array.back()).push_back( tmpz[i+j*file_ncache] ); + } + } + }else{ + ff.skip_n( this->m_twotondim*3 ); + } + } + } +} + + +template< typename TreeType_, typename Real_ > +std::string data::gen_fname( int icpu ) +{ + std::string fname; + char ext[32]; + fname = m_fname; + fname.erase(fname.rfind('.')+1); + sprintf(ext,"out%05d",icpu); + fname.append(std::string(ext)); + return fname; +} + + +template< typename TreeType_, typename Real_ > +std::string data::rename_info2hydro( const std::string& info ) +{ + std::string amr; + unsigned ii = info.rfind("info"); + amr = info.substr(0,ii)+"poisson" + info.substr(ii+4, 6) + ".out00001"; + return amr; +} + + +template< typename TreeType_, typename Real_ > +std::string data::rename_amr2hydro( const std::string& info ) +{ + std::string amr; + unsigned ii = info.rfind("amr"); + amr = info.substr(0,ii)+"poisson" + info.substr(ii+3, 6) + ".out00001"; + return amr; +} + + +} // namespace POISSON +} // namespace RAMSES + + +#endif // .. __RAMSES_POISSON_DATA_HH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/RAMSES_typedefs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/RAMSES_typedefs.h Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include + +#include "RAMSES_amr_data.hh" +#include "RAMSES_hydro_data.hh" + +//... define the RAMSES base cell type to be of cell_locally_essential type +//... - this type allows moving between refinement levels +namespace RAMSES { + namespace AMR{ + typedef RAMSES::AMR::cell_locally_essential RAMSES_cell; + typedef RAMSES::AMR::level RAMSES_level; + typedef RAMSES::AMR::tree< RAMSES_cell, RAMSES::AMR::level< RAMSES_cell > > RAMSES_tree; + } + namespace HYDRO { + typedef RAMSES::HYDRO::data< RAMSES::AMR::RAMSES_tree > RAMSES_hydro_data; + } +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/README Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,9 @@ +These are Header Files written by Oliver Hahn for reading RAMSES data. They do +not need to be installed, as they full contain the entire RamsesRead++ library. + +The library may also be downloaded independently from: + + http://www.exp-astro.phys.ethz.ch/hahn/RamsesTools/ + +Author: Oliver Hahn +Minor Modifications: Matthew Turk diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/ramses_headers/data_iterators.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/ramses_headers/data_iterators.hh Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,74 @@ +#ifndef __DATA_ITERATORS_HH +#define __DATA_ITERATORS_HH + +#include +/*template +class conditional_iterator +: public _Container::iterator +{ + + +};*/ + +//! TBD +template +class conditional_back_insert_iterator +: public std::iterator +{ + protected: + _Container* container; //!< TBD + _InputIterator cond_iterator; //!< TBD + + public: + //! TBD + typedef _Container container_type; + + //! TBD + conditional_back_insert_iterator(_Container& __x,const _InputIterator& __i, int __prealloc=0) + : container(&__x), cond_iterator(__i) + { + if( __prealloc > 0 ) + __x.reserve( __x.size()+__prealloc); + } + + /*conditional_back_insert_iterator( const conditional_back_insert_iterator& __it ) + : container( __it.container ), cond_iterator( __it.cond_iterator ) + { }*/ + + //! TBD + conditional_back_insert_iterator& + operator=( typename _Container::const_reference __value ) + { + if( *cond_iterator ) + container->push_back(__value); + ++cond_iterator; + return *this; + } + + //! TBD + conditional_back_insert_iterator& + operator*() + { return *this; } + + //! TBD + conditional_back_insert_iterator& + operator++() + { return *this; } + + //! TBD + conditional_back_insert_iterator& + operator++(int) + { return *this; } +}; + + +//! TBD +template +inline conditional_back_insert_iterator<_Container, _InputIterator> +conditional_back_inserter(_Container& __x, const _InputIterator& __i, int __prealloc=0) +{ return conditional_back_insert_iterator<_Container,_InputIterator>(__x,__i,__prealloc); } + + + + +#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/ramses/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/ramses/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,13 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('ramses',parent_package,top_path) + config.add_extension("_ramses_reader", + ["yt/frontends/ramses/_ramses_reader.cpp"], + include_dirs=["yt/frontends/ramses/ramses_headers/"]) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import setuptools + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('frontends',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + config.add_subpackage("chombo") + config.add_subpackage("enzo") + config.add_subpackage("flash") + config.add_subpackage("orion") + config.add_subpackage("ramses") + config.add_subpackage("tiger") + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/tiger/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/tiger/__init__.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.frontends.tiger + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/tiger/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/tiger/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,42 @@ +""" +API for yt.frontends.tiger + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" + +from .data_structures import \ + TigerGrid, \ + TigerHierarchy, \ + TigerStaticOutput + +from .fields import \ + TigerFieldContainer, \ + TigerFieldInfo, \ + add_tiger_field + +from .io import \ + IOHandlerTiger diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/tiger/data_structures.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/tiger/data_structures.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,204 @@ +""" +TIGER-specific data structures + +Author: Matthew Turk +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 . +""" + +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 + +from .fields import TigerFieldContainer + +class TigerGrid(AMRGridPatch): + _id_offset = 0 + + def __init__(self, id, hierarchy, left_edge, right_edge, left_dims, right_dims): + AMRGridPatch.__init__(self, id, hierarchy = hierarchy) + self.LeftEdge = left_edge + self.RightEdge = right_edge + self.Level = 0 + self.NumberOfParticles = 0 + self.left_dims = na.array(left_dims, dtype='int32') + self.right_dims = na.array(right_dims, dtype='int32') + self.ActiveDimensions = self.right_dims - self.left_dims + self.Parent = None + self.Children = [] + + @property + def child_mask(self): + return na.ones(self.ActiveDimensions, dtype='int32') + + def __repr__(self): + return "TigerGrid_%04i (%s)" % (self.id, self.ActiveDimensions) + +class TigerHierarchy(AMRHierarchy): + + grid = TigerGrid + + def __init__(self, pf, data_style): + self.directory = pf.fullpath + self.data_style = data_style + AMRHierarchy.__init__(self, pf, data_style) + + def _count_grids(self): + # Tiger is unigrid + self.ngdims = [i/j for i,j in + izip(self.pf.root_size, self.pf.max_grid_size)] + self.num_grids = na.prod(self.ngdims) + self.max_level = 0 + + def _setup_classes(self): + dd = self._get_data_reader_dict() + AMRHierarchy._setup_classes(self, dd) + self.object_types.sort() + + def _parse_hierarchy(self): + grids = [] + # We need to fill in dims, LE, RE, level, count + dims, LE, RE, levels, counts = [], [], [], [], [] + DLE = self.pf.domain_left_edge + DRE = self.pf.domain_right_edge + DW = DRE - DLE + gds = DW / self.ngdims + rd = [self.pf.root_size[i]-self.pf.max_grid_size[i] for i in range(3)] + glx, gly, glz = na.mgrid[DLE[0]:DRE[0]-gds[0]:self.ngdims[0]*1j, + DLE[1]:DRE[1]-gds[1]:self.ngdims[1]*1j, + DLE[2]:DRE[2]-gds[2]:self.ngdims[2]*1j] + gdx, gdy, gdz = na.mgrid[0:rd[0]:self.ngdims[0]*1j, + 0:rd[1]:self.ngdims[1]*1j, + 0:rd[2]:self.ngdims[2]*1j] + LE, RE, levels, counts = [], [], [], [] + i = 0 + for glei, gldi in izip(izip(glx.flat, gly.flat, glz.flat), + izip(gdx.flat, gdy.flat, gdz.flat)): + gld = na.array(gldi) + gle = na.array(glei) + gre = gle + gds + g = self.grid(i, self, gle, gre, gld, gld+self.pf.max_grid_size) + grids.append(g) + dims.append(self.pf.max_grid_size) + LE.append(g.LeftEdge) + RE.append(g.RightEdge) + levels.append(g.Level) + counts.append(g.NumberOfParticles) + i += 1 + self.grids = na.array(grids, dtype='object') + self.grid_dimensions[:] = na.array(dims, dtype='int64') + self.grid_left_edge[:] = na.array(LE, dtype='float64') + self.grid_right_edge[:] = na.array(RE, dtype='float64') + self.grid_levels.flat[:] = na.array(levels, dtype='int32') + self.grid_particle_count.flat[:] = na.array(counts, dtype='int32') + + def _populate_grid_objects(self): + # We don't need to do anything here + for g in self.grids: g._setup_dx() + + def _detect_fields(self): + self.file_mapping = {"Density" : "rhob", + "Temperature" : "temp"} + + @property + def field_list(self): + return self.file_mapping.keys() + + def _setup_unknown_fields(self): + for field in self.field_list: + add_tiger_field(field, lambda a, b: None) + + def _setup_derived_fields(self): + self.derived_field_list = [] + +class TigerStaticOutput(StaticOutput): + _hierarchy_class = TigerHierarchy + _fieldinfo_class = TigerFieldContainer + + def __init__(self, rhobname, root_size, max_grid_size=128, + data_style='tiger', storage_filename = None): + StaticOutput.__init__(self, rhobname, data_style) + self.storage_filename = storage_filename + self.basename = rhobname[:-4] + if not os.path.exists(self.basename + "rhob"): + print "%s doesn't exist, don't know how to handle this!" % ( + self.basename + "rhob") + raise IOError + if not iterable(root_size): root_size = (root_size,) * 3 + self.root_size = root_size + if not iterable(max_grid_size): max_grid_size = (max_grid_size,) * 3 + self.max_grid_size = max_grid_size + + self.field_info = self._fieldinfo_class() + + # We assume that we have basename + "rhob" and basename + "temp" + # to get at our various parameters. + + # First we get our our header: + + header = [ + ('i', 'dummy0'), + ('f', 'ZR'), + ('f', 'OMEGA0'), + ('f', 'FLAM0'), + ('f', 'OMEGAB'), + ('f', 'H0'), + ('f', 'BOXL0'), + ('i', 'dummy1'), + ] + + h_fmt, h_key = zip(*header) + header_string = "".join(h_fmt) + + fs = open(self.basename + "rhob") + header_raw = read_struct(fs, header_string) + self.parameters.update(dict(zip(h_key, header_raw))) + + if "InitialTime" not in self.parameters: + self.current_time = 0.0 + self.unique_identifier = \ + int(os.stat(self.parameter_filename)[ST_CTIME]) + self.parameters['TopGridDimensions'] = root_size + self.parameters['TopGridRank'] = 3 + self.units["Density"] = 1.0 + self.parameters['RefineBy'] = 2 + + def _set_units(self): + self.domain_left_edge = na.zeros(3, dtype='float64') + self.domain_right_edge = na.ones(3, dtype='float64') + self.units = {} + self.time_units = {} + self.time_units['1'] = 1 + self.units['1'] = 1.0 + self.units['cm'] = 1.0 # This is just plain false + self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() + + def _parse_parameter_file(self): + pass + + @classmethod + def _is_valid(self, *args, **kwargs): + return os.path.exists(args[0] + "rhob") + + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/tiger/fields.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/tiger/fields.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,43 @@ +""" +Tiger-specific fields + +Author: Matthew Turk +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 . +""" + +from yt.data_objects.field_info_container import \ + CodeFieldInfoContainer, \ + ValidateParameter, \ + ValidateDataField, \ + ValidateProperty, \ + ValidateSpatial, \ + ValidateGridType +import yt.data_objects.universal_fields + +class TigerFieldContainer(CodeFieldInfoContainer): + """ + This is a container for Tiger-specific fields. + """ + _shared_state = {} + _field_list = {} +TigerFieldInfo = TigerFieldContainer() +add_tiger_field = TigerFieldInfo.add_field + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/tiger/io.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/tiger/io.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,53 @@ +""" +TIGER-specific IO functions + +Author: Matthew Turk +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 . +""" + +from yt.utilities.io_handler import \ + BaseIOHandler + +class IOHandlerTiger(BaseIOHandler): + _data_style = "tiger" + _offset = 36 + + def __init__(self, *args, **kwargs): + BaseIOHandler.__init__(self, *args, **kwargs) + self._memmaps = {} + + def _read_data_set(self, grid, field): + fn = grid.pf.basename + grid.hierarchy.file_mapping[field] + LD = na.array(grid.left_dims, dtype='int64') + SS = na.array(grid.ActiveDimensions, dtype='int64') + RS = na.array(grid.pf.root_size, dtype='int64') + data = au.read_tiger_section(fn, LD, SS, RS).astype("float64") + return data + + def _read_data_slice(self, grid, field, axis, coord): + fn = grid.pf.basename + grid.hierarchy.file_mapping[field] + LD = na.array(grid.left_dims, dtype='int64').copy() + SS = na.array(grid.ActiveDimensions, dtype='int64').copy() + RS = na.array(grid.pf.root_size, dtype='int64').copy() + LD[axis] += coord + SS[axis] = 1 + data = au.read_tiger_section(fn, LD, SS, RS).astype("float64") + return data diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/frontends/tiger/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/frontends/tiger/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('tiger',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/funcs.py --- a/yt/funcs.py Mon Aug 30 10:02:07 2010 -0700 +++ b/yt/funcs.py Mon Aug 30 10:48:15 2010 -0700 @@ -23,12 +23,14 @@ along with this program. If not, see . """ -import time, types, signal, inspect, traceback, sys, pdb, rpdb, os +import time, types, signal, inspect, traceback, sys, pdb, os import warnings, struct -import progressbar as pb from math import floor, ceil -from yt.logger import ytLogger as mylog -from yt.exceptions import * + +from yt.utilities.exceptions import * +from yt.utilities.logger import ytLogger as mylog +import yt.utilities.progressbar as pb +import yt.utilities.rpdb as rpdb # Some compatibility functions. In the long run, these *should* disappear as # we move toward newer python versions. Most were implemented to get things @@ -413,6 +415,13 @@ print "Traceback pasted to http://paste.enzotools.org/show/%s" % (ret) print +_ss = "fURbBUUBE0cLXgETJnZgJRMXVhVGUQpQAUBuehQMUhJWRFFRAV1ERAtBXw1dAxMLXT4zXBFfABNN\nC0ZEXw1YUURHCxMXVlFERwxWCQw=\n" +def _rdbeta(key): + import itertools, base64 + enc_s = base64.decodestring(_ss) + dec_s = ''.join([ chr(ord(a) ^ ord(b)) for a, b in zip(enc_s, itertools.cycle(key)) ]) + print dec_s + # If we recognize one of the arguments on the command line as indicating a # different mechanism for handling tracebacks, we attach one of those handlers # and remove the argument from sys.argv. diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/api.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,29 @@ +""" +API for yt.visualization.opengl_widgets + +Author: Matthew Turk +Affiliation: UCSD +Author: J.S. Oishi +Affiliation: KIPAC/SLAC/Stanford +Author: Britton Smith +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 . + +""" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/calculateRay.vertex.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/calculateRay.vertex.glsl Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,63 @@ +/* Vertex shader to calculate the ray to cast through the volume data. + * The result is passed to the fragment shader using a varying. + * + * This file is part of Visvis. + * Copyright 2009 Almar Klein + */ + +// the dimensions of the data, to determine stepsize +uniform vec3 shape; + +// ratio to tune the number of steps +uniform float stepRatio; + +// varyings to pass to fragment shader +varying vec3 ray; + +void main() +{ + + // First of all, set position. + // (We need to do this because this shader replaces the original shader.) + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + + // Store texture coordinate (also a default thing). + gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz; + + // Calculate the scaling of the modelview matrix so we can correct + // for axes.daspect and scale transforms of the wobject (in case + // of anisotropic data). + // We go from world coordinates to eye coordinates. + vec4 p0 = gl_ModelViewMatrix * vec4(0.0,0.0,0.0,1.0); + vec4 px = gl_ModelViewMatrix * vec4(1.0,0.0,0.0,1.0); + vec4 py = gl_ModelViewMatrix * vec4(0.0,1.0,0.0,1.0); + vec4 pz = gl_ModelViewMatrix * vec4(0.0,0.0,1.0,1.0); + float sx = length(p0.xyz - px.xyz); + float sy = length(p0.xyz - py.xyz); + float sz = length(p0.xyz - pz.xyz); + + // Create a (diagonal) matrix to correct for the scaling + mat4 Ms = mat4(0.0); + Ms[0][0] = 1.0/(sx*sx); + Ms[1][1] = 1.0/(sy*sy); + Ms[2][2] = 1.0/(sz*sz); + Ms[3][3] = 1.0; + + // Calculate ray direction. By correcting for the scaling, the ray is + // expressed in textute coordinates. + // We go from eye coordinates to world/texture coordinates. + vec4 p1 = vec4(0.0, 0.0, 0.0, 1.0) * gl_ModelViewProjectionMatrix * Ms; + vec4 p2 = vec4(0.0, 0.0, 1.0, 1.0) * gl_ModelViewProjectionMatrix * Ms; + ray = (p2.xyz/p2[3]) - (p1.xyz/p1[3]); + + // Normalize ray to unit length. + ray = normalize(ray); + + // Make the ray represent the length of a single voxel. + ray = ray / shape; + ray = ray * 0.58; // 1 over root of three = 0.577 + + // Scale ray to take smaller steps. + ray = ray / stepRatio; + +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/colormap.fragment.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/colormap.fragment.glsl Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +uniform sampler1D colormap; +uniform sampler2D buffer; +void main() +{ + vec2 pos = vec3(gl_TexCoord[0]).xy; + vec4 value = texture2D(buffer, pos); + //gl_FragColor = texture1D(colormap, pos[1]); + gl_FragColor = texture1D(colormap, value[0]); + //gl_FragColor = vec4(1.0, 0.5, 0.3, 1.0); + //gl_FragColor = vec4(value[0], value[1], value[2], 1.0); + //gl_FragColor = vec4(pos[1], 0.0, 0.0, 1.0); +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/framebuffer.vertex.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/framebuffer.vertex.glsl Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +/* Vertex shader to calculate the ray to cast through the volume data. + * The result is passed to the fragment shader using a varying. + * + * This file is part of Visvis. + * Copyright 2009 Almar Klein + */ + +void main() +{ + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz; +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/mip.fragment.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/mip.fragment.glsl Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,135 @@ +/* Fragment shader for Maximum Intensity Projection (MIP) rendering. + * The ray is cast through the volume and we keep track of the + * smalest value. This is the fastest rendermethod available. + * + * This file is part of Visvis. + * Copyright 2009 Almar Klein + */ + +// the 3D texture and colormap texture. +uniform sampler3D texture; +//uniform sampler1D colormap; + +// for window level and window width +uniform vec2 scaleBias; + +// varying calculated by vertex shader +varying vec3 ray; + +uniform vec3 shape; +uniform vec3 position; + +float d2P(vec3 p, vec3 d, vec4 P) +{ + // calculate the distance of a point p to a plane P along direction d. + // plane P is defined as ax + by + cz = d + // line is defined as two points on that line + + // calculate nominator and denominator + float nom = -( dot(P.rgb,p) - P.a ); + float denom = dot(P.rgb,d); + // determine what to return + if (nom*denom<=0.0) + return 9999999.0; // if negative, or ON the plane, return ~inf + else + return nom / denom; // return normally +} + +vec4 getRayAndSteps(vec3 edgeLoc) +{ + // Given the start pos, returns a corrected version of the ray + // and the number of steps combined in a vec4. + + // Check for all six planes how many rays fit from the start point. + // Take the minimum value (not counting negative and 0). + + float smallest = 9999999.0; + smallest = min(smallest, d2P(edgeLoc, ray, vec4(1.0, 0.0, 0.0, 0.0))); + smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 1.0, 0.0, 0.0))); + smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 0.0, 1.0, 0.0))); + smallest = min(smallest, d2P(edgeLoc, ray, vec4(1.0, 0.0, 0.0, 1.0))); + smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 1.0, 0.0, 1.0))); + smallest = min(smallest, d2P(edgeLoc, ray, vec4(0.0, 0.0, 1.0, 1.0))); + + // round-off errors can cause the value to be very large. + // an n of 100.000 is pretty save + if (smallest > 9999.0) + smallest = 1.0; + + // determine amount of steps and correct ray + vec4 result; + float n = ceil(smallest); + result.xyz = ray * (smallest/n); + result[3] = n; + + // done + return result; +} + + +void main() +{ + + // Get current pixel location. + vec3 edgeLoc = vec3(gl_TexCoord[0]); + + // Get ray and steps. + vec4 tmp4 = getRayAndSteps(edgeLoc); + vec3 ray2 = tmp4.zyx; + int n = int(tmp4[3]); + + // Init. Remember that we made sure that the total range of the data is + // mapped between 0 and 1 (also for signed data types). + //float maxval = texture3D(texture, edgeLoc + 1.0*ray2.xyz)[0]; + float maxval = -1e30; + + // Cast ray. For some reason the inner loop is not iterated the whole + // way for large datasets. Thus this ugly hack. If you know how to do + // it better, please let me know! + float val; + vec3 loc; + int i=0; + while (imaxval) + // maxval = val; + } + } + + // Finaly, apply window-level window-width. + maxval = ( maxval + scaleBias[1] ) * scaleBias[0]; + //maxval = (maxval - scale[0]) / (scale[1] - scale[0]); + + //maxval = texture3D(texture, vec3(0.5, 0.5, 0.5))[0]; + + // Apply colormap. + //gl_FragColor = texture1D( colormap, maxval ); + //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); + //gl_FragColor = vec4(val,val,val,1.0); + gl_FragColor = vec4(maxval,maxval,maxval,1.0); + //gl_FragColor = vec4(ray2[0],ray2[1],ray2[2],1.0); + //gl_FragColor = vec4(loc[0],loc[1],loc[2],1.0); + //gl_FragColor = vec4(edgeLoc[0],edgeLoc[1],edgeLoc[2],1.0); + //gl_FragColor = vec4(edgeLoc[0],edgeLoc[0],edgeLoc[0],1.0); + //gl_FragColor = vec4(ray[0],ray[1],ray[2],1.0); + + //float mv = max(gl_FragData[1].r, maxval); + //if (mv < gl_FragData[1].r) discard; + //gl_FragData[0] = texture1D( colormap, mv); + //gl_FragData[1] = vec4(mv,mv,mv,mv); + + // Apply a depth? No, does only really make sence for the iso renderer. + //gl_FragDepth = 2.0 +} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/mip_viewer.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/mip_viewer.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,463 @@ +""" +Author: Matthew Turk +Affiliation: UCSD +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 . +""" + +# A simple image viewer, soon to be useful for stereo images, using OpenGL. + +import sys, os +import OpenGL.GL as GL +import OpenGL.GLUT as GLUT +import OpenGL.GLU as GLU +import OpenGL.GL.shaders as shaders +from OpenGL.arrays import vbo, ArrayDatatype +import OpenGL.GL.ARB.framebuffer_object as GL_fbo +import Image +import glob +import numpy as na +import time + +from small_apps import ViewHandler3D, GenericGLUTScene +from yt.visualization.image_writer import map_to_colors + +from rendering_contexts import render_fbo, create_fbo, identity_view, \ + translate_view +from yt.visualization.volume_rendering.api import \ + HomogenizedVolume + +ESCAPE = '\033' + +_verts = ( (0,0,0), (1,0,0), (1,1,0), (0,1,0), + (0,0,0), (1,0,0), (1,0,1), (0,0,1), + (0,0,0), (0,0,1), (0,1,1), (0,1,0), + (0,1,0), (1,1,0), (1,1,1), (0,1,1), + (1,1,0), (1,0,0), (1,0,1), (1,1,1), + (0,0,1), (0,1,1), (1,1,1), (1,0,1) ) + +_verts = ( (1,1,0), (0,1,0), (0,1,1), (1,1,1), + (1,0,1), (0,0,1), (0,0,0), (1,0,0), + (1,1,1), (0,1,1), (0,0,1), (1,0,1), + (1,0,0), (0,0,0), (0,1,0), (1,1,0), + (0,1,1), (0,1,0), (0,0,0), (0,0,1), + (1,1,0), (1,1,1), (1,0,1), (1,0,0) ) + +_corner_list = [0,1,2,3, 4,5,6,7, 3,2,6,5, 0,4,7,1, 0,3,5,4, 1,7,6,2] +_corner_vals = [ (0,0,0), (1,0,0), (1,1,0), (0,1,0), + (0,0,1), (0,1,1), (1,1,1), (1,0,1) ] + +_reversed = {2:0,1:1,0:2} + +def _compress(lr, s, i): + + if lr == 0: return 0.5/s[_reversed[i]] + else: return -0.5/s[_reversed[i]] + + +class MIPScene(GenericGLUTScene): + _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) + _title = "MIP" + + gl_state = None + + def _get_brick_vertices(self, offset): + for b in self.hv.bricks: + s = [ [-0.5, -0.5, -0.5], + [b.my_data[0].shape[i] - 1.5 for i in reversed(xrange(3))] ] + for corner in _corner_list: + for i, v in enumerate(_corner_vals[corner]): + yield s[v][i] + + def _get_texture_vertices(self): + vs = [na.zeros(3, dtype='float32'), + na.ones(3, dtype='float32')] + #vs.reverse() + for b in self.hv.bricks: + shape = b.my_data[0].shape + for corner in _corner_list: + for i,v in enumerate(_corner_vals[corner]): + yield vs[v][i] + _compress(v, shape, i) + + def _setup_bricks(self): + self._brick_textures = [] + for g in self.hv.bricks: + self._upload_brick_textures(g) + + def _upload_brick_textures(self, brick): + ix, iy, iz = brick.my_data[0].shape + + GL.glActiveTexture(GL.GL_TEXTURE0) + id_field = GL.glGenTextures(1) + upload = brick.my_data[0].astype("float32") + #upload = (upload - -31.847) / ( -25.948 - -31.847 ) + #mi, ma = -31.847, -25.948 + #mi, ma = -27.2062, -20.9649 + #upload = (upload - mi)/(ma - mi) + self.mi = min(upload.min(), self.mi) + self.ma = max(upload.max(), self.ma) + #upload = (255*(upload - -31.0) / (-25.0 - -31.0)).astype("uint8") + + GL.glActiveTexture(GL.GL_TEXTURE0) + GL.glBindTexture(GL.GL_TEXTURE_3D, id_field) + GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) + GL.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_LUMINANCE32F_ARB, iz, iy, ix, 0, + GL.GL_LUMINANCE, GL.GL_FLOAT, upload) + + DW = self.hv.pf.domain_right_edge - self.hv.pf.domain_left_edge + dds = ((brick.RightEdge - brick.LeftEdge) / + (na.array([ix,iy,iz], dtype='float32')-1)) / DW + BLE = brick.LeftEdge / DW - 0.5 + self._brick_textures.append( + (id_field, (ix-1,iy-1,iz-1), dds, BLE)) + + print "Uploaded", len(self._brick_textures) + + def _setup_colormap(self): + + buffer = na.mgrid[0.0:1.0:256j] + colors = map_to_colors(buffer, "algae") + + GL.glActiveTexture(GL.GL_TEXTURE1) + id_cmap = GL.glGenTextures(1) + + GL.glBindTexture(GL.GL_TEXTURE_1D, id_cmap) + GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) + GL.glTexParameterf(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) + GL.glTexParameterf(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) + GL.glTexParameterf(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) + GL.glTexImage1D(GL.GL_TEXTURE_1D, 0, GL.GL_RGBA, 256, 0, + GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, colors) + + self.gl_state["cmap_tex"] = id_cmap + + def __init__(self, hv, offset = 0.5): + self.offset = offset + self.mi, self.ma = 1e30, -1e30 + self.hv = hv + self.coord = 0.0 + self.tfac = 10.0 + self.rfac = 0.5 + self.wireframe = False + self.glda = True + self._setup_keypress_handler() + self.gl_state = {} + GenericGLUTScene.__init__(self, 800, 800) + + num = len(hv.bricks) * 6 * 4 + self.v = na.fromiter(self._get_brick_vertices(offset), + dtype = 'float32', count = num * 3) + self.vertices = vbo.VBO(self.v) + + self.t = na.fromiter(self._get_texture_vertices(), + dtype = 'float32', count = num * 3) + self.tvertices = vbo.VBO(self.t) + + self.ng = len(hv.bricks) + self.position = na.zeros(3, dtype='float') + self.rotation = na.zeros(3, dtype='float') + 30 + self.position[2] = -2 # Offset backwards a bit + + self._setup_bricks() + create_fbo(self.gl_state) + self._setup_colormap() + + def init_opengl(self, width, height): + # One-time GL setup + + self.gl_state["width"] = width + self.gl_state["height"] = height + + self.set_viewport() + + # Now we compile our shaders + self.recompile() + + def set_viewport(self): + if self.wireframe: + GL.glClearColor(1, 1, 1, 1) + else: + GL.glClearColor(0, 0, 0, 1) + GL.glColor3f(1, 0, 0) + GL.glEnable(GL.GL_DEPTH_TEST) + + GL.glViewport(0, 0, self.gl_state["width"], self.gl_state["height"]) + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + GLU.gluPerspective(60., self.gl_state["width"] / float(self.gl_state["height"]), 1e-3, 10.) + GL.glMatrixMode(GL.GL_MODELVIEW) + + def recompile(self): + base = os.path.dirname(__file__) + "/" + self.program = compileProgram( + shaders.compileShader( + open(base+"calculateRay.vertex.glsl").read(), + GL.GL_VERTEX_SHADER), + shaders.compileShader( + open(base+"mip.fragment.glsl").read(), + GL.GL_FRAGMENT_SHADER)) + + def _set_simple_uniform(prog): + GL.glUseProgram(prog) + loc = GL.glGetUniformLocation(prog, 'buffer') + GL.glUniform1i(loc, 0) + loc = GL.glGetUniformLocation(prog, 'colormap') + GL.glUniform1i(loc, 1) + GL.glUseProgram(0) + + self.fbo_program = compileProgram( + shaders.compileShader( + open(base+"framebuffer.vertex.glsl").read(), + GL.GL_VERTEX_SHADER), + shaders.compileShader( + open(base+"colormap.fragment.glsl").read(), + GL.GL_FRAGMENT_SHADER), + callback = _set_simple_uniform) + + self.uniform_locations = dict( ( + (v, GL.glGetUniformLocation(self.program, v)) for v in + ['texture','shape','scaleBias','stepRatio','position'] + ) ) + self.fbo_uniform_locations = dict( ( + (v, GL.glGetUniformLocation(self.fbo_program, v)) for v in + ['colormap','buffer'] + ) ) + + print self.uniform_locations, self.fbo_uniform_locations + + @render_fbo + def _draw_boxes(self): + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + GL.glDisable(GL.GL_DEPTH_TEST) + GL.glEnable(GL.GL_BLEND) + if self.wireframe: + GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) + else: + GL.glBlendEquation(GL.GL_MAX) + GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) + GL.glDisable(GL.GL_LINE_STIPPLE) + GL.glDisable(GL.GL_LINE_SMOOTH) + GL.glDisable(GL.GL_POINT_SMOOTH) + GL.glEnable(GL.GL_CULL_FACE) + #GL.glCullFace(GL.GL_FRONT) + GL.glCullFace(GL.GL_BACK) + + GL.glLoadIdentity() + GL.glTranslatef(*self.position) + GL.glRotatef(self.rotation[0], 0, 0, 1) + GL.glRotatef(self.rotation[1], 0, 1, 0) + GL.glRotatef(self.rotation[2], 1, 0, 0) + + GL.glColor3f(0.0, 0.0, 0.0) + GL.glUseProgram(self.program) + scalebias = ( 1.0/(self.ma - self.mi), -self.mi) + GL.glUniform1i(self.uniform_locations["texture"], 0) + GL.glUniform2f(self.uniform_locations["scaleBias"], scalebias[0], scalebias[1]) + GL.glUniform1f(self.uniform_locations["stepRatio"], 1.0) + GL.glUniform3f(self.uniform_locations["position"], *self.position) + + GL.glEnableClientState(GL.GL_VERTEX_ARRAY) + GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) + #GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY_EXT) + + GL.glColor3f(0.0, 0.0, 0.0) + + GL.glActiveTexture(GL.GL_TEXTURE0) + GL.glEnable(GL.GL_TEXTURE_3D) + + self.tvertices.bind() + GL.glTexCoordPointer(3, GL.GL_FLOAT, 0, self.tvertices) + self.vertices.bind() + GL.glVertexPointer(3, GL.GL_FLOAT, 0, self.vertices) + + for i, texinfo in enumerate(self._brick_textures): + tex, shape, width, LE = texinfo + GL.glActiveTexture(GL.GL_TEXTURE0) + GL.glBindTexture(GL.GL_TEXTURE_3D, tex) + GL.glUniform1f(self.uniform_locations["stepRatio"], 0.1) + GL.glUniform3f(self.uniform_locations["shape"], + shape[2], shape[1], shape[0]) + GL.glPushMatrix() + GL.glTranslate(LE[2], LE[1], LE[0]) + GL.glScale(width[2], width[1], width[0]) + if self.glda: + GL.glDrawArrays(GL.GL_QUADS, 24*i, 24) + else: + GL.glBegin(GL.GL_QUADS) + for fi in range(6): + for v in range(4): + #print -LE, width + off = i*72+fi*12+v*3 + qv = self.v[off:off+3] + tv = self.t[off:off+3] + GL.glTexCoord3f(*tv) + GL.glVertex3f(*qv) + GL.glEnd() + GL.glPopMatrix() + GL.glDisableClientState(GL.GL_VERTEX_ARRAY) + GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) + GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY_EXT) + self.vertices.unbind() + self.tvertices.unbind() + GL.glDisable(GL.GL_CULL_FACE) + + def draw(self): + + self._draw_boxes() + + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + GL.glUseProgram(self.fbo_program) + + GL.glMatrixMode(GL.GL_MODELVIEW) + GL.glLoadIdentity() + + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + + GL.glActiveTexture(GL.GL_TEXTURE0) + GL.glEnable(GL.GL_TEXTURE_2D) + GL.glBindTexture(GL.GL_TEXTURE_2D, self.gl_state["fbo_tex"]) + + GL.glActiveTexture(GL.GL_TEXTURE1) + GL.glEnable(GL.GL_TEXTURE_1D) + GL.glBindTexture(GL.GL_TEXTURE_1D, self.gl_state["cmap_tex"]) + + GL.glUniform1i(self.fbo_uniform_locations["buffer"], 0) + GL.glUniform1i(self.fbo_uniform_locations["colormap"], 1) + + GL.glColor3f(0.3, 0.5, 1.0) + + GL.glBegin(GL.GL_QUADS) + GL.glTexCoord2i(0, 0) + GL.glVertex3i(-1, -1, -1) + + GL.glTexCoord2i(0, 1) + GL.glVertex3i( 1, -1, -1) + + GL.glTexCoord2i(1, 1) + GL.glVertex3i( 1, 1, -1) + + GL.glTexCoord2i(1, 0) + GL.glVertex3i(-1, 1, -1) + GL.glEnd() + + GL.glUseProgram(0) + + GLUT.glutSwapBuffers() + + def move_slice(self, value): + self.coord += value + + def rotate(self, axis, value): + self.rotation[axis] += value/self.rfac + + def reset_view(self): + print "RESETTING" + self.position = na.zeros(3, dtype='float') + self.rotation = na.zeros(3, dtype='float') + 30 + self.position[2] = -2 # Offset backwards a bit + + def translate(self, axis, value): + self.position[axis] += value/self.tfac + + def toggle_wireframe(self): + self.wireframe = not self.wireframe + print "Wireframe:", self.wireframe + + def toggle_glda(self): + self.glda = not self.glda + print "GLDA:", self.glda + + def _setup_keypress_handler(self): + self.keypress_handler = ViewHandler3D(self) + self.keypress_handler.dispatch_table.update(dict( + y = (self.move_slice, ( 0.05,)), + h = (self.move_slice, (-0.05,)), + t = (self.toggle_wireframe, ()), + u = (self.toggle_glda, ()), + i = (self.recompile, ()), + o = (self.reset_view, ()) + )) + +# We override the standard PyOpenGL one because otherwise we can't validate +# multitexture shaders. +def compileProgram(*my_shaders, **kwargs): + """Create a new program, attach my_shaders and validate + + my_shaders -- arbitrary number of my_shaders to attach to the + generated program. + + This convenience function is *not* standard OpenGL, + but it does wind up being fairly useful for demos + and the like. You may wish to copy it to your code + base to guard against PyOpenGL changes. + + Usage: + + shader = compileProgram( + compileShader( source, GL_VERTEX_SHADER ), + compileShader( source2, GL_FRAGMENT_SHADER ), + ) + glUseProgram( shader ) + + Note: + If (and only if) validation of the linked program + *passes* then the passed-in shader objects will be + deleted from the GL. + + returns GLuint shader program reference + raises RuntimeError when a link/validation failure occurs + """ + program = GL.glCreateProgram() + for shader in my_shaders: + GL.glAttachShader(program, shader) + GL.glLinkProgram(program) + # Validation has to occur *after* linking + if 'callback' in kwargs: kwargs['callback'](program) + GL.glValidateProgram( program ) + validation = GL.glGetProgramiv( program, GL.GL_VALIDATE_STATUS ) + if validation == GL.GL_FALSE: + raise RuntimeError( + """Validation failure (%s): %s"""%( + validation, + GL.glGetProgramInfoLog( program ), + )) + link_status = GL.glGetProgramiv( program, GL.GL_LINK_STATUS ) + if link_status == GL.GL_FALSE: + raise RuntimeError( + """Link failure (%s): %s"""%( + link_status, + GL.glGetProgramInfoLog( program ), + )) + for shader in my_shaders: + GL.glDeleteShader(shader) + return shaders.ShaderProgram( program ) + +if __name__ == "__main__": + import yt.convenience, yt.frontends.enzo.api + pf = yt.convenience.load(sys.argv[-1]) + print pf + hv = HomogenizedVolume(pf = pf, fields=["Density"], log_fields=[True]) + hv.initialize_source() + mip = MIPScene(hv) + mip.run() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/rendering_contexts.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/rendering_contexts.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,88 @@ +""" +Author: Matthew Turk +Affiliation: UCSD +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 . +""" + +import OpenGL.GL as GL +import OpenGL.GLUT as GLUT +import OpenGL.GLU as GLU +import OpenGL.GL.shaders as shaders +from OpenGL.arrays import vbo, ArrayDatatype +import OpenGL.GL.ARB.framebuffer_object as GL_fbo +from functools import wraps + +def render_fbo(func): + @wraps(func) + def fbo_renderer(self, fbo_id = "fbo_id", fbo_depth = "fbo_depth", **kwargs): + GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, + self.gl_state[fbo_id]) + GL_fbo.glBindRenderbuffer(GL_fbo.GL_RENDERBUFFER, + self.gl_state[fbo_depth]) + self.set_viewport() + GL.glPushAttrib(GL.GL_VIEWPORT_BIT) + GL.glViewport(0, 0, self.gl_state["width"], self.gl_state["height"]) + status = GL_fbo.glCheckFramebufferStatus(GL_fbo.GL_FRAMEBUFFER) + assert(status == GL_fbo.GL_FRAMEBUFFER_COMPLETE) + + func(self, **kwargs) + + GL.glPopAttrib(GL.GL_VIEWPORT_BIT) + GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, 0) + + return fbo_renderer + +def create_fbo(gl_state, fbo_id = "fbo_id", fbo_depth = "fbo_depth", + fbo_tex = "fbo_tex"): + GL.glActiveTexture(GL.GL_TEXTURE0) + id_fbo = GL.glGenTextures(1) + id_depth = GL_fbo.glGenRenderbuffers(1) + gl_state[fbo_tex] = id_fbo + gl_state[fbo_depth] = id_depth + gl_state[fbo_id] = GL_fbo.glGenFramebuffers(1) + + GL.glBindTexture(GL.GL_TEXTURE_2D, id_fbo) + GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) + GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, + gl_state["width"], gl_state["height"], 0, + GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) + + GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, gl_state[fbo_id]) + GL_fbo.glFramebufferTexture2D(GL_fbo.GL_FRAMEBUFFER, + GL_fbo.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, gl_state[fbo_tex], 0) + + GL_fbo.glBindRenderbuffer(GL_fbo.GL_RENDERBUFFER, id_depth) + GL_fbo.glRenderbufferStorage(GL_fbo.GL_RENDERBUFFER, + GL.GL_DEPTH_COMPONENT, gl_state["width"], gl_state["height"]) + GL_fbo.glFramebufferRenderbuffer( + GL_fbo.GL_FRAMEBUFFER, GL_fbo.GL_DEPTH_ATTACHMENT, + GL_fbo.GL_RENDERBUFFER, id_depth) + + GL_fbo.glBindFramebuffer(GL_fbo.GL_FRAMEBUFFER, 0) + GL_fbo.glBindRenderbuffer(GL_fbo.GL_RENDERBUFFER, 0) + +def identity_view(func): + pass + +def translate_view(func): + pass diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,12 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +import os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('opengl_widgets',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/opengl_widgets/small_apps.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/opengl_widgets/small_apps.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,618 @@ +""" +Author: Matthew Turk +Affiliation: UCSD +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 . +""" + +# A simple image viewer, soon to be useful for stereo images, using OpenGL. + +import sys +import OpenGL.GL as GL +import OpenGL.GLUT as GLUT +import OpenGL.GLU as GLU +import OpenGL.GL.shaders as shaders +from OpenGL.arrays import vbo, ArrayDatatype +import Image +import glob +import numpy as na +import time + +ESCAPE = '\033' + +class ViewHandler3D(object): + def __init__(self, scene): + # We + self.scene = scene + self.dispatch_table = dict( + q = (scene.translate, (1, 1.0)), + e = (scene.translate, (1, -1.0)), + w = (scene.translate, (2, 1.0)), + s = (scene.translate, (2, -1.0)), + a = (scene.translate, (0, 1.0)), + d = (scene.translate, (0, -1.0)), + + Q = (scene.rotate, (1, 1.0)), + E = (scene.rotate, (1, -1.0)), + W = (scene.rotate, (2, 1.0)), + S = (scene.rotate, (2, -1.0)), + A = (scene.rotate, (0, 1.0)), + D = (scene.rotate, (0, -1.0)), + + ESCAPE = (sys.exit, (0,)) + ) + + def __call__(self, *args): + # We set up our standard handlers, and then anything additional can get + # called if none of our dispatch mechanisms work. + if args[0] in self.dispatch_table: + func, args = self.dispatch_table[args[0]] + func(*args) + # always draw when handling a keypress, even if it's one time too many + self.scene.draw() + +class GenericGLUTScene(object): + + def __init__(self, width, height): + self.init_glut(width, height) + self.init_opengl(width, height) + + def init_glut(self, width, height): + GLUT.glutInit([]) # drop sys.argv + GLUT.glutInitDisplayMode(self._display_mode) + GLUT.glutInitWindowSize(width, height) + GLUT.glutInitWindowPosition(0, 0) + self.window = GLUT.glutCreateWindow(self._title) + GLUT.glutDisplayFunc(self.draw) + #GLUT.glutIdleFunc(self.draw) + GLUT.glutKeyboardFunc(self.keypress_handler) + + def run(self): + GLUT.glutMainLoop() + +class MultiImageDisplayScene(object): + _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) + _title = "Image Display" + def __init__(self): + GenericGLUTScene(512, 512) + self._frames = [] + self._current = -1 + + def add_image(self, obj): + self._frames.append(obj) + + def init_opengl(self, width, height): + GL.glClearColor(0.0, 0.0, 0.0, 0.0) + GL.glClearDepth(1.0) + GL.glDepthFunc(GL.GL_LESS) + GL.glEnable(GL.GL_DEPTH_TEST) + GL.glShadeModel(GL.GL_SMOOTH) + + def draw(self): + + GL.glMatrixMode(GL.GL_MODELVIEW) + GL.glLoadIdentity() + + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + + if self._current >= 0: + self._draw_current() + + GLUT.glutSwapBuffers() + + def _draw_current(self): + self._frames[self._current].draw() + + def keypress_handler(self, *args): + if args[0] == ESCAPE: + sys.exit() + elif len(self._frames) == 0: + # The rest only operate if we have multiple frames + return + elif args[0] == 'n': + self._current = min(self._current + 1, len(self._frames)) + elif args[0] == 'N': + while self._current < len(self._frames) - 1: + self._current += 1 + self.draw() + elif args[0] == 'p': + self._current = max(self._current - 1, 0) + elif args[0] == 'P': + while self._current > 0: + self._current -= 1 + self.draw() + elif args[0] == 't': + for i in xrange(15): + time.sleep(0.05) + self.draw() + self._current += 1 + time.sleep(0.05) + self.draw() + self._current -= 1 + self.draw() # Once more for good measure + +class StereoMultiImageDisplayScene(MultiImageDisplayScene): + _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH | + GLUT.GLUT_STEREO) + + def draw(self): + GL.glDrawBuffer(GL.GL_BACK_LEFT) + + GL.glMatrixMode(GL.GL_MODELVIEW) + GL.glLoadIdentity() + + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + + if self._current >= 0: + self._draw_current_left() + + GLUT.glutSwapBuffers() + + GL.glDrawBuffer(GL.GL_BACK_RIGHT) + + GL.glMatrixMode(GL.GL_MODELVIEW) + GL.glLoadIdentity() + + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + + if self._current >= 0: + self._draw_current_right() + + GLUT.glutSwapBuffers() + + def _draw_current_left(self): + self._frames[self._current].draw_left() + + def _draw_current_right(self): + self._frames[self._current].draw_right() + +class FlatImage(object): + def __init__(self, tex_unit = GL.GL_TEXTURE0): + self.tex_unit = tex_unit + GL.glActiveTexture(self.tex_unit) + self._id = GL.glGenTextures(1) + + def draw(self): + GL.glActiveTexture(self.tex_unit) + GL.glEnable(GL.GL_TEXTURE_2D) + GL.glBindTexture(GL.GL_TEXTURE_2D, self._id) + GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL) + + GL.glColor3f(0.3, 0.5, 1.0) + + GL.glBegin(GL.GL_QUADS) + GL.glVertex3i(-1, -1, -1) + GL.glTexCoord2i(0, 0) + + GL.glVertex3i( 1, -1, -1) + GL.glTexCoord2i(0, 1) + + GL.glVertex3i( 1, 1, -1) + GL.glTexCoord2i(1, 1) + + GL.glVertex3i(-1, 1, -1) + GL.glTexCoord2i(1, 0) + GL.glEnd() + + def upload_image(self, buffer): + ix, iy, nc = buffer.shape + if nc != 4: raise RuntimeError + GL.glActiveTexture(self.tex_unit) + GL.glBindTexture(GL.GL_TEXTURE_2D, self._id) + GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) + GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, ix, iy, 0, GL.GL_RGBA, + GL.GL_UNSIGNED_BYTE, buffer.tostring()) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) + GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) + + @classmethod + def from_image_file(cls, fn, tex_unit = GL.GL_TEXTURE0): + buffer = na.array(Image.open(fn)) + print "Uploading buffer", buffer.min(), buffer.max(), buffer.shape, buffer.dtype + obj = cls(tex_unit) + obj.upload_image(buffer) + return obj + +class StereoImagePair(FlatImage): + def __init__(self, tex_unit = GL.GL_TEXTURE0): + self.tex_unit = tex_unit + self.left_image = FlatImage(tex_unit) + self.right_image = FlatImage(tex_unit) + + def draw_left(self): + self.left_image.draw() + + def draw_right(self): + self.right_image.draw() + + def upload_images(self, buffer_left, buffer_right): + self.left_image.upload_image(buffer_left) + self.right_image.upload_image(buffer_right) + + @classmethod + def from_image_files(cls, left_fn, right_fn, tex_unit = GL.GL_TEXTURE0): + print "Uploading pairs from %s and %s" % (left_fn, right_fn) + left_buffer = na.array(Image.open(left_fn)) + right_buffer = na.array(Image.open(right_fn)) + obj = cls(tex_unit) + obj.left_image.upload_image(left_buffer) + obj.right_image.upload_image(right_buffer) + return obj + +_verts = ( (0,0,0), (1,0,0), (1,1,0), (0,1,0), + (0,0,0), (1,0,0), (1,0,1), (0,0,1), + (0,0,0), (0,0,1), (0,1,1), (0,1,0), + (0,1,0), (1,1,0), (1,1,1), (0,1,1), + (1,1,0), (1,0,0), (1,0,1), (1,1,1), + (0,0,1), (0,1,1), (1,1,1), (1,0,1) ) + +class GridObject3DScene(GenericGLUTScene): + _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) + _title = "Grids" + + def _get_grid_vertices(self, offset): + DLE, DRE = self.pf.domain_left_edge, pf.domain_right_edge + DW = DRE - DLE + k = 0 + for g in self.pf.h.grids: + vs = ((g.LeftEdge-DLE)/DW, (g.RightEdge-DLE)/DW) + for vert in _verts: + for i,v in enumerate(vert): + yield vs[v][i] - offset + k += 1 + + def __init__(self, pf, offset = 0.5): + self.pf = pf + GenericGLUTScene.__init__(self, 800, 800) + + num = len(pf.h.grids) * 6 * 4 + self.v = na.fromiter(self._get_grid_vertices(offset), + dtype = 'float32', count = num * 3) + + self.vertices = vbo.VBO(self.v) + self.ng = len(pf.h.grids) + self.ox = self.oy = self.rx = self.ry = self.rz = 0 + self.oz = -4 + + def init_opengl(self, width, height): + # One-time GL setup + GL.glClearColor(1, 1, 1, 1) + GL.glColor3f(1, 0, 0) + GL.glEnable(GL.GL_DEPTH_TEST) + #glEnable(GL_CULL_FACE) + + # Uncomment this line for a wireframe view + GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) + + # Simple light setup. On Windows GL_LIGHT0 is enabled by default, + # but this is not the case on Linux or Mac, so remember to always + # include it. + GL.glEnable(GL.GL_LIGHTING) + + def vec(*args): + return (GL.GLfloat * len(args))(*args) + + GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, vec(.5, .5, 1, 0)) + GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, vec(.5, .5, 1, 1)) + GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, vec(1, 1, 1, 1)) + GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, vec(1, 0, .5, 0)) + GL.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, vec(.5, .5, .5, 1)) + GL.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, vec(1, 1, 1, 1)) + + GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1)) + GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, vec(1, 1, 1, 1)) + GL.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, 50) + + GL.glViewport(0, 0, width, height) + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + GLU.gluPerspective(60., width / float(height), 1e-3, 10.) + GL.glMatrixMode(GL.GL_MODELVIEW) + + def draw(self): + + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + GL.glLoadIdentity() + GL.glTranslatef(self.ox, self.oy, self.oz) + GL.glRotatef(self.rx, 0, 0, 1) + GL.glRotatef(self.ry, 0, 1, 0) + GL.glRotatef(self.rz, 1, 0, 0) + + self.vertices.bind() + GL.glEnableClientState(GL.GL_VERTEX_ARRAY) + GL.glVertexPointer( 3, GL.GL_FLOAT, 0, self.vertices) + GL.glDrawArrays(GL.GL_QUADS, 0, 4*6*self.ng) + + GL.glDisableClientState(GL.GL_VERTEX_ARRAY) + self.vertices.unbind() + GLUT.glutSwapBuffers() + + def keypress_handler(self, *args): + tfac = 25.0 + rfac = 0.5 + if args[0] == ESCAPE: + sys.exit() + elif args[0] == 'a': + self.ox += 1.0/tfac + elif args[0] == 'd': + self.ox -= 1.0/tfac + elif args[0] == 's': + self.oz -= 1.0/tfac + elif args[0] == 'w': + self.oz += 1.0/tfac + elif args[0] == 'q': + self.oy -= 1.0/tfac + elif args[0] == 'e': + self.oy += 1.0/tfac + # Now, rotations + elif args[0] == 'A': + self.rx -= 1.0/rfac + elif args[0] == 'D': + self.rx += 1.0/rfac + elif args[0] == 'S': + self.rz -= 1.0/rfac + elif args[0] == 'W': + self.rz += 1.0/rfac + elif args[0] == 'Q': + self.ry -= 1.0/rfac + elif args[0] == 'E': + self.ry += 1.0/rfac + self.draw() + +class GridSlice3DScene(GenericGLUTScene): + _display_mode = (GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) + _title = "Grids" + + def _get_grid_vertices(self, offset): + for g in self.pf.h.grids: + vs = (g.LeftEdge, g.RightEdge) + for vert in _verts: + for i,v in enumerate(vert): + yield vs[v][i] - offset + + def _setup_grids(self): + self._grid_textures = {} + for g in self.pf.h.grids: + self._upload_grid_textures(g) + + def _upload_grid_textures(self, grid): + ix, iy, iz = grid.ActiveDimensions + + GL.glActiveTexture(GL.GL_TEXTURE0) + id_field = GL.glGenTextures(1) + upload = na.log10(grid["Density"].astype("float32")).copy() + self.mi = min(upload.min(), self.mi) + self.ma = max(upload.max(), self.ma) + #upload = (255*(upload - -31.0) / (-25.0 - -31.0)).astype("uint8") + + GL.glBindTexture(GL.GL_TEXTURE_3D, id_field) + GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) + GL.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_LUMINANCE32F_ARB, iz, iy, ix, 0, + GL.GL_LUMINANCE, GL.GL_FLOAT, upload) + + GL.glActiveTexture(GL.GL_TEXTURE1) + id_mask = GL.glGenTextures(1) + upload = grid.child_mask.astype("float32").copy() + + GL.glBindTexture(GL.GL_TEXTURE_3D, id_mask) + GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) + GL.glTexParameterf(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) + GL.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_LUMINANCE, iz, iy, ix, 0, + GL.GL_LUMINANCE, GL.GL_FLOAT, upload) + + self._grid_textures[grid.id] = (id_field, id_mask) + + print "Uploaded", grid.id + + def __init__(self, pf, offset = 0.5): + self.offset = offset + self.mi, self.ma = 1e30, -1e30 + self.pf = pf + self.coord = 0.0 + self.tfac = 10.0 + self.rfac = 0.5 + self._setup_keypress_handler() + GenericGLUTScene.__init__(self, 800, 800) + + num = len(pf.h.grids) * 6 * 4 + self.v = na.fromiter(self._get_grid_vertices(offset), + dtype = 'float32', count = num * 3) + + self.vertices = vbo.VBO(self.v) + self.ng = len(pf.h.grids) + self.position = na.zeros(3, dtype='float') + self.rotation = na.zeros(3, dtype='float') + self.position[2] = -2 # Offset backwards a bit + + self._setup_grids() + + def init_opengl(self, width, height): + # One-time GL setup + GL.glClearColor(1, 1, 1, 1) + GL.glColor3f(1, 0, 0) + GL.glEnable(GL.GL_DEPTH_TEST) + + GL.glViewport(0, 0, width, height) + GL.glMatrixMode(GL.GL_PROJECTION) + GL.glLoadIdentity() + GLU.gluPerspective(60., width / float(height), 1e-3, 10.) + GL.glMatrixMode(GL.GL_MODELVIEW) + + # Now we compile our shaders + + self.program = shaders.compileProgram( + shaders.compileShader(''' + void main() { + gl_TexCoord[0]=gl_TextureMatrix[0] * gl_MultiTexCoord0; + gl_TexCoord[1]=gl_TextureMatrix[1] * gl_MultiTexCoord1; + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + } + ''',GL.GL_VERTEX_SHADER), + shaders.compileShader(''' + uniform float ma; + uniform float mi; + uniform sampler3D field; + uniform sampler3D mask; + + void main() { + vec3 pos; + float val; + + pos = vec3(gl_TexCoord[1].xyz); + val = texture3D( mask, pos )[0]; + if(val == 0.0) discard; + + pos = vec3(gl_TexCoord[0].xyz); + val = texture3D( field, pos )[0]; + + float color = (val - mi) / (ma - mi); + + //gl_FragColor = vec4(pos.x, pos.y, pos.z, 1.0); + gl_FragColor = vec4(color, color, color, 1.0); + } + ''',GL.GL_FRAGMENT_SHADER),) + + self.uniform_locations = dict( ( + (v, GL.glGetUniformLocation(self.program, v)) for v in + ['mi','ma','field','mask'] + ) ) + + def draw(self): + + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) + + GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) + + GL.glLoadIdentity() + GL.glTranslatef(*self.position) + GL.glRotatef(self.rotation[0], 0, 0, 1) + GL.glRotatef(self.rotation[1], 0, 1, 0) + GL.glRotatef(self.rotation[2], 1, 0, 0) + + self.vertices.bind() + GL.glColor3f(0.0, 0.0, 0.0) + GL.glEnableClientState(GL.GL_VERTEX_ARRAY) + GL.glVertexPointer( 3, GL.GL_FLOAT, 0, self.vertices) + GL.glDrawArrays(GL.GL_QUADS, 0, 4*6*self.ng) + GL.glDisableClientState(GL.GL_VERTEX_ARRAY) + self.vertices.unbind() + + # Now, we just want to draw + GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) + + # We can just draw a single quad for now + GL.glUseProgram(self.program) + GL.glUniform1i(self.uniform_locations["field"], 0) + GL.glUniform1i(self.uniform_locations["mask"], 1) + GL.glUniform1f(self.uniform_locations["mi"], self.mi) + GL.glUniform1f(self.uniform_locations["ma"], self.ma) + GL.glEnable(GL.GL_TEXTURE_3D) + + t0, t1 = 0.0, 1.0 + for g in self.pf.h.find_slice_grids(self.coord + 0.5, 1)[0]: + LE = g.LeftEdge - self.offset + RE = g.RightEdge - self.offset + off = (self.coord - LE[1]) / (RE[1] - LE[1]) + + GL.glActiveTexture(GL.GL_TEXTURE0) + GL.glBindTexture(GL.GL_TEXTURE_3D, self._grid_textures[g.id][0]) + GL.glEnable(GL.GL_TEXTURE_3D) + + GL.glActiveTexture(GL.GL_TEXTURE1) + GL.glBindTexture(GL.GL_TEXTURE_3D, self._grid_textures[g.id][1]) + GL.glEnable(GL.GL_TEXTURE_3D) + + GL.glBegin(GL.GL_QUADS) + + GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t0, off, t0) + GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t0, off, t0) + GL.glVertex3f(LE[0], self.coord, LE[2]) + + GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t0, off, t1) + GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t0, off, t1) + GL.glVertex3f(RE[0], self.coord, LE[2]) + + GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t1, off, t1) + GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t1, off, t1) + GL.glVertex3f(RE[0], self.coord, RE[2]) + + GL.glMultiTexCoord3f(GL.GL_TEXTURE0, t1, off, t0) + GL.glMultiTexCoord3f(GL.GL_TEXTURE1, t1, off, t0) + GL.glVertex3f(LE[0], self.coord, RE[2]) + + GL.glEnd() + + GL.glUseProgram(0) + + GLUT.glutSwapBuffers() + + def move_slice(self, value): + self.coord += value + + def rotate(self, axis, value): + self.rotation[axis] += value/self.rfac + + def translate(self, axis, value): + self.position[axis] += value/self.tfac + + def _setup_keypress_handler(self): + self.keypress_handler = ViewHandler3D(self) + self.keypress_handler.dispatch_table.update(dict( + y = (self.move_slice, ( 0.05,)), + h = (self.move_slice, (-0.05,)) + )) + +if __name__ == "__main__": + if sys.argv[-2] == '-g': + import yt.mods + pf = yt.mods.load(sys.argv[-1]) + main_scene = GridObject3DScene(pf) + elif sys.argv[-2] == '-s': + import yt.mods + pf = yt.mods.load(sys.argv[-1]) + main_scene = GridSlice3DScene(pf) + else: + fn_list = glob.glob("frames/*.png") + + main_scene = MultiImageDisplayScene() + for fn in sorted(fn_list): + main_scene.add_image(FlatImage.from_image_file(fn)) + main_scene._current = 0 + main_scene.run() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/plot_editors.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/plot_editors.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,128 @@ +""" +Figure editors for the Traits GUI + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2009 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 . +""" + +import sys, matplotlib +# We want matplotlib to use a wxPython backend +matplotlib.use('QT4Agg') +from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas +from matplotlib.figure import Figure +from matplotlib.axes import Axes + +from enthought.traits.api import Any, Instance +from enthought.traits.ui.qt4.editor import Editor +from enthought.traits.ui.qt4.basic_editor_factory import BasicEditorFactory + +from enthought.pyface.action.api import ActionController + +from enthought.traits.ui.menu import \ + Menu, Action, Separator, OKCancelButtons, OKButton + +from matplotlib.backend_bases import Event as MPLEvent + +class _MPLFigureEditor(Editor): + """ Snagged from Gael's tutorial """ + + scrollable = True + mpl_control = Instance(FigureCanvas) + + def init(self, parent): + self.control = self._create_canvas(parent) + self.set_tooltip() + + def update_editor(self): + pass + + def _create_canvas(self, parent): + """ Create the MPL canvas. """ + # The panel lets us add additional controls. + panel = wx.Panel(parent, -1) + sizer = wx.BoxSizer(wx.VERTICAL) + panel.SetSizer(sizer) + # matplotlib commands to create a canvas + self.mpl_control = FigureCanvas(panel, -1, self.value) + sizer.Add(self.mpl_control, 1, wx.LEFT | wx.TOP | wx.GROW | wx.SHAPED) + self.value.canvas.SetMinSize((10,8)) + return panel + +class MPLFigureEditor(BasicEditorFactory): + klass = _MPLFigureEditor + +class MPLAction(Action): + event = Instance(MPLEvent) + +class _MPLVMPlotEditor(_MPLFigureEditor, ActionController): + + def _create_canvas(self, parent): + panel = _MPLFigureEditor._create_canvas(self, parent) + self.mpl_control.mpl_connect("button_press_event", self.on_click) + return panel + + def on_click(self, event): + if not event.inaxes: return + if event.button == 3: + my_menu = Menu(MPLAction(name="Recenter", action="object.recenter", + event=event), + MPLAction(name="Yo!", action="object.do_something", + event=event)) + wxmenu = my_menu.create_menu(self.mpl_control, self) + self.mpl_control.PopupMenuXY(wxmenu) + + def perform ( self, action ): + """ + This is largely taken/modified from the TreeEditor _perform method. + """ + object = self.object + method_name = action.action + info = self.ui.info + handler = self.ui.handler + event = action.event + + if method_name.find( '.' ) >= 0: + if method_name.find( '(' ) < 0: + method_name += '(event)' + try: + eval( method_name, globals(), + { 'object': object, + 'editor': self, + 'info': info, + 'event': event, + 'handler': handler } ) + except: + # fixme: Should the exception be logged somewhere? + print sys.exc_info() + + return + + method = getattr( handler, method_name, None ) + if method is not None: + method( info, object ) + return + + if action.on_perform is not None: + action.on_perform( object ) + +class MPLVMPlotEditor(BasicEditorFactory): + klass = _MPLVMPlotEditor + diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/reason_v2.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/reason_v2.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,479 @@ +""" +New version of Reason, using a TraitsUI-based approach + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2009 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 . +""" + +from yt.mods import * +from yt.utilities.definitions import \ + x_dict, \ + y_dict +#pf = EnzoStaticOutput("/Users/matthewturk/Research/data/galaxy1200.dir/galaxy1200") + +from enthought.traits.api import \ + HasTraits, List, Instance, Str, Float, Any, Code, PythonValue, Int, CArray, \ + Property, Enum, cached_property, DelegatesTo, Callable, Array, \ + Button +from enthought.traits.ui.api import \ + Group, VGroup, HGroup, Tabbed, View, Item, ShellEditor, InstanceEditor, ListStrEditor, \ + ListEditor, VSplit, VFlow, HSplit, VFold, ValueEditor, TreeEditor, TreeNode, RangeEditor, \ + EnumEditor, Handler, Controller, DNDEditor +from enthought.traits.ui.menu import \ + Menu, Action, Separator, OKCancelButtons, OKButton +from enthought.pyface.action.api import \ + ActionController +from enthought.tvtk.pyface.scene_editor import SceneEditor +from enthought.tvtk.pyface.api import \ + DecoratedScene +from enthought.tvtk.pyface.scene_model import SceneModel + +from plot_editors import Figure, MPLFigureEditor, MPLVMPlotEditor, Axes + +from yt.visualization.plot_types import VMPlot, ProjectionPlot, SlicePlot + +import traceback +from tvtk_interface import \ + HierarchyImporter, YTScene + +class PlotCreationHandler(Controller): + main_window = Instance(HasTraits) + pnode = Instance(HasTraits) + + format = Str + plot_type = Any + + def close(self, info, is_ok): + if not is_ok: + super(Controller, self).close(info, True) + return + spt = self.plot_type(plot_spec=self.model, pf=self.pnode.pf, + name=self.format % (self.model.axis)) + self.pnode.data_objects.append(spt) + self.main_window.plot_frame_tabs.append(spt) + spt.plot + +class VTKSceneCreationHandler(PlotCreationHandler): + importer = Instance(HierarchyImporter) + + def close(self, info, is_ok): + if is_ok: + yt_scene = YTScene(importer=self.importer, + scene=SceneModel()) + spt = VTKDataObject(name = "VTK: %s" % self.pnode.pf, + scene=yt_scene.scene, + yt_scene=yt_scene) + self.pnode.data_objects.append(spt) + self.main_window.plot_frame_tabs.append(spt) + super(Controller, self).close(info, True) + return True + + +class DataObject(HasTraits): + name = Str + +class VTKDataObject(DataObject): + yt_scene = Instance(YTScene) + scene = DelegatesTo("yt_scene") + add_contours = Button + add_isocontour = Button + add_x_plane = Button + add_y_plane = Button + add_z_plane = Button + edit_camera = Button + edit_operators = Button + edit_pipeline = Button + center_on_max = Button + operators = DelegatesTo("yt_scene") + traits_view = View( + Item("scene", editor = + SceneEditor(scene_class=DecoratedScene), + resizable=True, show_label=False), + HGroup(Item("add_contours", show_label=False), + Item("add_isocontour", show_label=False), + Item("add_x_plane", show_label=False), + Item("add_y_plane", show_label=False), + Item("add_z_plane", show_label=False), + Item("edit_camera", show_label=False), + Item("edit_operators", show_label=False), + Item("edit_pipeline", show_label=False), + Item("center_on_max", show_label=False), + ), + ) + + operators_edit = View( + Item("operators", style='custom', show_label=False, + editor=ListEditor(editor=InstanceEditor(), + use_notebook=True), + name="Edit Operators"), + height=500.0, width=500.0, resizable=True) + + def _edit_camera_fired(self): + self.yt_scene.camera_path.edit_traits() + + def _edit_operators_fired(self): + self.edit_traits(view='operators_edit') + + def _edit_pipeline_fired(self): + from enthought.tvtk.pipeline.browser import PipelineBrowser + pb = PipelineBrowser(self.scene) + pb.show() + + def _add_contours_fired(self): + self.yt_scene.add_contour() + + def _add_isocontour_fired(self): + self.yt_scene.add_isocontour() + + def _add_x_plane_fired(self): + self.yt_scene.add_x_plane() + + def _add_y_plane_fired(self): + self.yt_scene.add_y_plane() + + def _add_z_plane_fired(self): + self.yt_scene.add_z_plane() + + def _center_on_max_fired(self): + self.yt_scene.do_center_on_max() + +class ParameterFile(HasTraits): + pf = Instance(EnzoStaticOutput) + data_objects = List(Instance(DataObject)) + name = Str + + def _name_default(self): + return str(self.pf) + + def do_slice(self): + cons_view = View( + Item('axis'), + Item('center'), + Item('field', editor=EnumEditor(name='field_list')), + buttons=OKCancelButtons, title="Slicer: %s" % self.pf) + ps = SlicePlotSpec(pf=self.pf) + hand = PlotCreationHandler(main_window=mw, pnode=self, model=ps, + plot_type=SlicePlotTab, format="Slice: %s") + ps.edit_traits(cons_view, handler=hand) + + def do_proj(self): + cons_view = View( + Item('axis'), + Item('field', editor=EnumEditor(name='field_list')), + Item('weight_field', editor=EnumEditor(name='none_field_list')), + buttons=OKCancelButtons, title="Projector: %s" % self.pf) + ps = ProjPlotSpec(pf=self.pf) + hand = PlotCreationHandler(main_window=mw, pnode=self, model=ps, + plot_type=ProjPlotTab, format="Proj: %s") + ps.edit_traits(cons_view, handler=hand) + + def do_vtk(self): + from tvtk_interface import HierarchyImporter, \ + HierarchyImportHandler + importer = HierarchyImporter(pf=self.pf, max_level=self.pf.h.max_level) + importer.edit_traits(handler = VTKSceneCreationHandler( + main_window=mw, pnode=self, importer = importer)) + +class ParameterFileCollection(HasTraits): + parameter_files = List(Instance(ParameterFile)) + name = Str + collection = Any + + def _parameter_files_default(self): + my_list = [] + for f in self.collection: + try: + pf = EnzoStaticOutput(f) + my_list.append( + ParameterFile(pf=pf, + data_objects = [])) + except IOError: pass + return my_list + + def _name_default(self): + return str(self.collection) + +class ParameterFileCollectionList(HasTraits): + parameter_file_collections = List(Instance(ParameterFileCollection)) + + def _parameter_file_collections_default(self): + return [ParameterFileCollection(collection=c) + for c in fido.GrabCollections()] + +class DataObjectList(HasTraits): + data_objects = List(Str) + + traits_view = View( + Item('data_objects', show_label=False, + editor=ListStrEditor()) + ) + + def _data_objects_default(self): + return ['a','b','c'] + +class PlotFrameTab(DataObject): + figure = Instance(Figure) + +class VMPlotSpec(HasTraits): + pf = Instance(EnzoStaticOutput) + field = Str('Density') + field_list = Property(depends_on = 'pf') + + center = Array(shape=(3,), dtype='float64') + axis = Enum(0,1,2) + + @cached_property + def _get_field_list(self): + fl = self.pf.h.field_list + df = self.pf.h.derived_field_list + fl.sort(); df.sort() + return fl + df + + def _center_default(self): + return self.pf.h.find_max("Density")[1] + +class SlicePlotSpec(VMPlotSpec): + pass + +class ProjPlotSpec(VMPlotSpec): + weight_field = Str("None") + none_field_list = Property(depends_on = 'field_list') + + @cached_property + def _get_none_field_list(self): + return ["None"] + self.field_list + +class VMPlotTab(PlotFrameTab): + pf = Instance(EnzoStaticOutput) + figure = Instance(Figure, args=()) + field = DelegatesTo('plot_spec') + field_list = DelegatesTo('plot_spec') + plot = Instance(VMPlot) + axes = Instance(Axes) + disp_width = Float(1.0) + unit = Str('unitary') + min_width = Property(Float, depends_on=['pf','unit']) + max_width = Property(Float, depends_on=['pf','unit']) + unit_list = Property(depends_on = 'pf') + smallest_dx = Property(depends_on = 'pf') + + traits_view = View(VGroup( + HGroup(Item('figure', editor=MPLVMPlotEditor(), + show_label=False)), + HGroup(Item('disp_width', + editor=RangeEditor(format="%0.2e", + low_name='min_width', high_name='max_width', + mode='logslider', enter_set=True), + show_label=False, width=400.0), + Item('unit', + editor=EnumEditor(name='unit_list')),), + HGroup(Item('field', + editor=EnumEditor(name='field_list')), + )), + resizable=True) + + def __init__(self, **traits): + super(VMPlotTab, self).__init__(**traits) + self.axes = self.figure.add_subplot(111, aspect='equal') + + def _field_changed(self, old, new): + self.plot.switch_z(new) + self._redraw() + + @cached_property + def _get_min_width(self): + return 50.0*self.smallest_dx*self.pf[self.unit] + + @cached_property + def _get_max_width(self): + return self.pf['unitary']*self.pf[self.unit] + + @cached_property + def _get_smallest_dx(self): + return self.pf.h.get_smallest_dx() + + @cached_property + def _get_unit_list(self): + return self.pf.units.keys() + + def _unit_changed(self, old, new): + self.disp_width = self.disp_width * self.pf[new]/self.pf[old] + + def _disp_width_changed(self, old, new): + self.plot.set_width(new, self.unit) + self._redraw() + + def _redraw(self): + self.figure.canvas.draw() + + def recenter(self, event): + xp, yp = event.xdata, event.ydata + dx = abs(self.plot.xlim[0] - self.plot.xlim[1])/self.plot.pix[0] + dy = abs(self.plot.ylim[0] - self.plot.ylim[1])/self.plot.pix[1] + x = (dx * xp) + self.plot.xlim[0] + y = (dy * yp) + self.plot.ylim[0] + xi = x_dict[self.axis] + yi = y_dict[self.axis] + cc = self.center[:] + cc[xi] = x; cc[yi] = y + self.plot.data.center = cc[:] + self.plot.data.set_field_parameter('center', cc.copy()) + self.center = cc + +class SlicePlotTab(VMPlotTab): + plot_spec = Instance(SlicePlotSpec) + + axis = DelegatesTo('plot_spec') + center = DelegatesTo('plot_spec') + + plot = Instance(SlicePlot) + + def _plot_default(self): + coord = self.center[self.axis] + sl = self.pf.h.slice(self.axis, coord, center=self.center[:]) + sp = SlicePlot(sl, self.field, self.figure, self.axes) + self.figure.canvas.draw() + return sp + + def _center_changed(self, old, new): + #traceback.print_stack() + if na.all(na.abs(old - new) == 0.0): return + print na.abs(old-new) + print "Re-slicing", old, new + pp = self.center + self.plot.data.reslice(pp[self.axis]) + self.plot._refresh_display_width() + self.figure.canvas.draw() + +class ProjPlotTab(VMPlotTab): + plot_spec = Instance(ProjPlotSpec) + + axis = DelegatesTo('plot_spec') + center = DelegatesTo('plot_spec') + weight_field = DelegatesTo('plot_spec') + + plot = Instance(ProjectionPlot) + + def _plot_default(self): + self.field = self.field[:] + self.weight_field = self.weight_field[:] + wf = self.weight_field + if str(wf) == "None": wf = None + proj = self.pf.h.proj(self.axis, self.field, wf, + center=self.center[:]) + pp = ProjectionPlot(proj, self.field, self.figure, self.axes) + self.figure.canvas.draw() + return pp + + def _center_changed(self, old, new): + self.plot._refresh_display_width() + +class SphereWrapper(DataObject): + radius = Float + unit = Str + +class MainWindow(HasTraits): + parameter_file_collections = Instance(ParameterFileCollectionList) + parameter_files = Instance(ParameterFileCollection) + plot_frame_tabs = List(Instance(DataObject)) + open_parameterfile = Button + shell = PythonValue + + def _shell_default(self): + return globals() + notebook_editor = ListEditor(editor=InstanceEditor(editable=True), + use_notebook=True) + + traits_view = View(VSplit( + HSplit(VGroup( + Item('parameter_file_collections', + width=120.0, height=500.0, + show_label=False, + editor = TreeEditor(editable=False, + nodes=[ + TreeNode(node_for=[ParameterFileCollectionList], + children='parameter_file_collections', + label="=Data Collections"), + TreeNode(node_for=[ParameterFileCollection], + children='parameter_files', + label="name", + view=View()), + TreeNode(node_for=[ParameterFile], + children='data_objects', + label="name", + menu = Menu(Action(name='Slice', + action='object.do_slice'), + Action(name='Project', + action='object.do_proj'), + Action(name='VTK', + action='object.do_vtk')), + view=View()), + TreeNode(node_for=[DataObject], + children='', + label="name"), + ], show_icons=False),), + Item('open_parameterfile', show_label=False)), + Item('plot_frame_tabs', style='custom', + editor = notebook_editor, + show_label=False, height=500.0, width=500.0), + ), + HGroup( + #Item('shell', editor=ShellEditor(share=True), + #show_label=False, height=120.0), + ), + ), + resizable=True, width=800.0, height=660.0, + title="reason v2 [prototype]") + + def _open_parameterfile_fired(self): + print "OPENING" + + def _parameter_file_collections_default(self): + return ParameterFileCollectionList() + +class YTScript(HasTraits): + code = Code + traits_view = View(Item('code', show_label=False), + height=0.8, width=0.8, resizable=True, + buttons=OKCancelButtons) + +class ObjectViewer(HasTraits): + to_view=Any + traits_view = View( + Item('to_view', editor=ValueEditor(), show_label=False), + resizable=True, height=0.8, width=0.8) + +def view_object(obj): + ObjectViewer(to_view=obj).edit_traits() + +def run_script(): + my_script = YTScript() + my_script.edit_traits() + return my_script + +class event_mock(object): + inaxes = True + button = 3 + +dol = DataObjectList() +mw = MainWindow(plot_frame_tabs = []) +mw.edit_traits() +#mw.edit_traits() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/setup.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import setuptools +import os, sys, os.path + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('gui',parent_package,top_path) + config.make_config_py() # installs __config__.py + config.make_svn_version_py() + return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/gui/tvtk_interface.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yt/gui/tvtk_interface.py Mon Aug 30 10:48:15 2010 -0700 @@ -0,0 +1,692 @@ +""" +This is the preliminary interface to VTK. Note that as of VTK 5.2, it still +requires a patchset prepared here: +http://yt.enzotools.org/files/vtk_composite_data.zip + +Author: Matthew Turk +Affiliation: KIPAC/SLAC/Stanford +Homepage: http://yt.enzotools.org/ +License: + Copyright (C) 2007-2009 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 . +""" + +from enthought.tvtk.tools import ivtk +from enthought.tvtk.api import tvtk +from enthought.traits.api import \ + Float, HasTraits, Instance, Range, Any, Delegate, Tuple, File, Int, Str, \ + CArray, List, Button, Bool, Property, cached_property +from enthought.traits.ui.api import View, Item, HGroup, VGroup, TableEditor, \ + Handler, Controller, RangeEditor, EnumEditor, InstanceEditor +from enthought.traits.ui.menu import \ + Menu, Action, Separator, OKCancelButtons, OKButton +from enthought.traits.ui.table_column import ObjectColumn +from enthought.tvtk.pyface.api import DecoratedScene + +import enthought.pyface.api as pyface + +#from yt.reason import * +import sys +import numpy as na +import time, pickle, os, os.path +from yt.funcs import * +from yt.extensions.HierarchySubset import \ + ExtractedHierarchy, ExtractedParameterFile + +#from enthought.tvtk.pyface.ui.wx.wxVTKRenderWindowInteractor \ + #import wxVTKRenderWindowInteractor + +from enthought.mayavi.core.lut_manager import LUTManager + +#wxVTKRenderWindowInteractor.USE_STEREO = 1 + +class TVTKMapperWidget(HasTraits): + alpha = Float(1.0) + post_call = Any + lut_manager = Instance(LUTManager) + + def _alpha_changed(self, old, new): + self.lut_manager.lut.alpha_range = (new, new) + self.post_call() + +class MappingPlane(TVTKMapperWidget): + plane = Instance(tvtk.Plane) + _coord_redit = editor=RangeEditor(format="%0.2e", + low_name='vmin', high_name='vmax', + auto_set=False, enter_set=True) + auto_set = Bool(False) + traits_view = View(Item('coord', editor=_coord_redit), + Item('auto_set'), + Item('alpha', editor=RangeEditor( + low=0.0, high=1.0, + enter_set=True, auto_set=False)), + Item('lut_manager', show_label=False, + editor=InstanceEditor(), style='custom')) + vmin = Float + vmax = Float + + def _auto_set_changed(self, old, new): + if new is True: + self._coord_redit.auto_set = True + self._coord_redit.enter_set = False + else: + self._coord_redit.auto_set = False + self._coord_redit.enter_set = True + + def __init__(self, vmin, vmax, vdefault, **traits): + HasTraits.__init__(self, **traits) + self.vmin = vmin + self.vmax = vmax + trait = Range(float(vmin), float(vmax), value=vdefault) + self.add_trait("coord", trait) + self.coord = vdefault + + def _coord_changed(self, old, new): + orig = self.plane.origin[:] + orig[self.axis] = new + self.plane.origin = orig + self.post_call() + +class MappingMarchingCubes(TVTKMapperWidget): + operator = Instance(tvtk.MarchingCubes) + mapper = Instance(tvtk.HierarchicalPolyDataMapper) + vmin = Float + vmax = Float + auto_set = Bool(False) + _val_redit = RangeEditor(format="%0.2f", + low_name='vmin', high_name='vmax', + auto_set=False, enter_set=True) + traits_view = View(Item('value', editor=_val_redit), + Item('auto_set'), + Item('alpha', editor=RangeEditor( + low=0.0, high=1.0, + enter_set=True, auto_set=False,)), + Item('lut_manager', show_label=False, + editor=InstanceEditor(), style='custom')) + + def __init__(self, vmin, vmax, vdefault, **traits): + HasTraits.__init__(self, **traits) + self.vmin = vmin + self.vmax = vmax + trait = Range(float(vmin), float(vmax), value=vdefault) + self.add_trait("value", trait) + self.value = vdefault + + def _auto_set_changed(self, old, new): + if new is True: + self._val_redit.auto_set = True + self._val_redit.enter_set = False + else: + self._val_redit.auto_set = False + self._val_redit.enter_set = True + + def _value_changed(self, old, new): + self.operator.set_value(0, new) + self.post_call() + +class MappingIsoContour(MappingMarchingCubes): + operator = Instance(tvtk.ContourFilter) + +class CameraPosition(HasTraits): + position = CArray(shape=(3,), dtype='float64') + focal_point = CArray(shape=(3,), dtype='float64') + view_up = CArray(shape=(3,), dtype='float64') + clipping_range = CArray(shape=(2,), dtype='float64') + distance = Float + num_steps = Int(10) + orientation_wxyz = CArray(shape=(4,), dtype='float64') + +class CameraControl(HasTraits): + # Traits + positions = List(CameraPosition) + yt_scene = Instance('YTScene') + center = Delegate('yt_scene') + scene = Delegate('yt_scene') + camera = Instance(tvtk.OpenGLCamera) + reset_position = Instance(CameraPosition) + fps = Float(25.0) + export_filename = 'frames' + periodic = Bool + + # UI elements + snapshot = Button() + play = Button() + export_frames = Button() + reset_path = Button() + recenter = Button() + save_path = Button() + load_path = Button() + export_path = Button() + + table_def = TableEditor( + columns = [ ObjectColumn(name='position'), + ObjectColumn(name='focal_point'), + ObjectColumn(name='view_up'), + ObjectColumn(name='clipping_range'), + ObjectColumn(name='num_steps') ], + reorderable=True, deletable=True, + sortable=True, sort_model=True, + show_toolbar=True, + selection_mode='row', + selected = 'reset_position' + ) + + default_view = View( + VGroup( + HGroup( + Item('camera', show_label=False), + Item('recenter', show_label=False), + label='Camera'), + HGroup( + Item('snapshot', show_label=False), + Item('play', show_label=False), + Item('export_frames',show_label=False), + Item('reset_path', show_label=False), + Item('save_path', show_label=False), + Item('load_path', show_label=False), + Item('export_path', show_label=False), + Item('export_filename'), + Item('periodic'), + Item('fps'), + label='Playback'), + VGroup( + Item('positions', show_label=False, + editor=table_def), + label='Camera Path'), + ), + resizable=True, title="Camera Path Editor", + ) + + def _reset_position_changed(self, old, new): + if new is None: return + cam = self.scene.camera + cam.position = new.position + cam.focal_point = new.focal_point + cam.view_up = new.view_up + cam.clipping_range = new.clipping_range + self.scene.render() + + def __init__(self, **traits): + HasTraits.__init__(self, **traits) + + def take_snapshot(self): + cam = self.scene.camera + self.positions.append(CameraPosition( + position=cam.position, + focal_point=cam.focal_point, + view_up=cam.view_up, + clipping_range=cam.clipping_range, + distance=cam.distance, + orientation_wxyz=cam.orientation_wxyz)) + + def _export_path_fired(self): + dlg = pyface.FileDialog( + action='save as', + wildcard="*.cpath", + ) + if dlg.open() == pyface.OK: + print "Saving:", dlg.path + self.export_camera_path(dlg.path) + + def export_camera_path(self, fn): + to_dump = dict(positions=[], focal_points=[], + view_ups=[], clipping_ranges=[], + distances=[], orientation_wxyzs=[]) + def _write(cam): + to_dump['positions'].append(cam.position) + to_dump['focal_points'].append(cam.focal_point) + to_dump['view_ups'].append(cam.view_up) + to_dump['clipping_ranges'].append(cam.clipping_range) + to_dump['distances'].append(cam.distance) + to_dump['orientation_wxyzs'].append(cam.orientation_wxyz) + self.step_through(0.0, callback=_write) + pickle.dump(to_dump, open(fn, "wb")) + + def _save_path_fired(self): + dlg = pyface.FileDialog( + action='save as', + wildcard="*.cpath", + ) + if dlg.open() == pyface.OK: + print "Saving:", dlg.path + self.dump_camera_path(dlg.path) + + def dump_camera_path(self, fn): + to_dump = dict(positions=[], focal_points=[], + view_ups=[], clipping_ranges=[], + distances=[], orientation_wxyzs=[], + num_stepss=[]) + for p in self.positions: + to_dump['positions'].append(p.position) + to_dump['focal_points'].append(p.focal_point) + to_dump['view_ups'].append(p.view_up) + to_dump['clipping_ranges'].append(p.clipping_range) + to_dump['distances'].append(p.distance) + to_dump['num_stepss'].append(p.num_steps) # stupid s + to_dump['orientation_wxyzs'].append(p.orientation_wxyz) + pickle.dump(to_dump, open(fn, "wb")) + + def _load_path_fired(self): + dlg = pyface.FileDialog( + action='open', + wildcard="*.cpath", + ) + if dlg.open() == pyface.OK: + print "Loading:", dlg.path + self.load_camera_path(dlg.path) + + def load_camera_path(self, fn): + to_use = pickle.load(open(fn, "rb")) + self.positions = [] + for i in range(len(to_use['positions'])): + dd = {} + for kw in to_use: + # Strip the s + dd[kw[:-1]] = to_use[kw][i] + self.positions.append( + CameraPosition(**dd)) + + def _recenter_fired(self): + self.camera.focal_point = self.center + self.scene.render() + + def _snapshot_fired(self): + self.take_snapshot() + + def _play_fired(self): + self.step_through() + + def _export_frames_fired(self): + self.step_through(save_frames=True) + + def _reset_path_fired(self): + self.positions = [] + + def step_through(self, pause = 1.0, callback=None, save_frames=False): + cam = self.scene.camera + frame_counter=0 + if self.periodic: + cyclic_pos = self.positions + [self.positions[0]] + else: + cyclic_pos = self.positions + for i in range(len(cyclic_pos)-1): + pos1 = cyclic_pos[i] + pos2 = cyclic_pos[i+1] + r = pos1.num_steps + for p in range(pos1.num_steps): + po = _interpolate(pos1.position, pos2.position, p, r) + fp = _interpolate(pos1.focal_point, pos2.focal_point, p, r) + vu = _interpolate(pos1.view_up, pos2.view_up, p, r) + cr = _interpolate(pos1.clipping_range, pos2.clipping_range, p, r) + _set_cpos(cam, po, fp, vu, cr) + self.scene.render() + if callback is not None: callback(cam) + if save_frames: + self.scene.save("%s_%0.5d.png" % (self.export_filename,frame_counter)) + else: + time.sleep(pause * 1.0/self.fps) + frame_counter += 1 + +def _interpolate(q1, q2, p, r): + return q1 + p*(q2 - q1)/float(r) + +def _set_cpos(cam, po, fp, vu, cr): + cam.position = po + cam.focal_point = fp + cam.view_up = vu + cam.clipping_range = cr + +class HierarchyImporter(HasTraits): + pf = Any + min_grid_level = Int(0) + max_level = Int(1) + number_of_levels = Range(0, 13) + max_import_levels = Property(depends_on='min_grid_level') + field = Str("Density") + field_list = List + center_on_max = Bool(True) + center = CArray(shape = (3,), dtype = 'float64') + cache = Bool(True) + smoothed = Bool(True) + show_grids = Bool(True) + + def _field_list_default(self): + fl = self.pf.h.field_list + df = self.pf.h.derived_field_list + fl.sort(); df.sort() + return fl + df + + default_view = View(Item('min_grid_level', + editor=RangeEditor(low=0, + high_name='max_level')), + Item('number_of_levels', + editor=RangeEditor(low=1, + high_name='max_import_levels')), + Item('field', editor=EnumEditor(name='field_list')), + Item('center_on_max'), + Item('center', enabled_when='not object.center_on_max'), + Item('smoothed'), + Item('cache', label='Pre-load data'), + Item('show_grids'), + buttons=OKCancelButtons) + + def _center_default(self): + return [0.5,0.5,0.5] + + @cached_property + def _get_max_import_levels(self): + return min(13, self.pf.h.max_level - self.min_grid_level + 1) + +class HierarchyImportHandler(Controller): + importer = Instance(HierarchyImporter) + + + def close(self, info, is_ok): + if is_ok: + yt_scene = YTScene( + importer=self.importer) + super(Controller, self).close(info, True) + return + + +class YTScene(HasTraits): + + # Traits + importer = Instance(HierarchyImporter) + pf = Delegate("importer") + min_grid_level = Delegate("importer") + number_of_levels = Delegate("importer") + field = Delegate("importer") + center = CArray(shape = (3,), dtype = 'float64') + center_on_max = Delegate("importer") + smoothed = Delegate("importer") + cache = Delegate("importer") + show_grids = Delegate("importer") + + camera_path = Instance(CameraControl) + #window = Instance(ivtk.IVTKWithCrustAndBrowser) + #python_shell = Delegate('window') + #scene = Delegate('window') + scene = Instance(HasTraits) + operators = List(HasTraits) + + # State variables + _grid_boundaries_actor = None + + # Views + def _window_default(self): + # Should experiment with passing in a pipeline browser + # that has two root objects -- one for TVTKBases, i.e. the render + # window, and one that accepts our objects + return ivtk.IVTKWithCrustAndBrowser(size=(800,600), stereo=1) + + def _camera_path_default(self): + return CameraControl(yt_scene=self, camera=self.scene.camera) + + def __init__(self, **traits): + HasTraits.__init__(self, **traits) + max_level = min(self.pf.h.max_level, + self.min_grid_level + self.number_of_levels - 1) + self.extracted_pf = ExtractedParameterFile(self.pf, + self.min_grid_level, max_level, offset=None) + self.extracted_hierarchy = self.extracted_pf.h + self._hdata_set = tvtk.HierarchicalBoxDataSet() + self._ugs = [] + self._grids = [] + self._min_val = 1e60 + self._max_val = -1e60 + gid = 0 + if self.cache: + for grid_set in self.extracted_hierarchy.get_levels(): + for grid in grid_set: + grid[self.field] + for l, grid_set in enumerate(self.extracted_hierarchy.get_levels()): + gid = self._add_level(grid_set, l, gid) + if self.show_grids: + self.toggle_grid_boundaries() + + def _center_default(self): + return self.extracted_hierarchy._convert_coords( + [0.5, 0.5, 0.5]) + + def do_center_on_max(self): + self.center = self.extracted_hierarchy._convert_coords( + self.pf.h.find_max("Density")[1]) + self.scene.camera.focal_point = self.center + + def _add_level(self, grid_set, level, gid): + for grid in grid_set: + self._hdata_set.set_refinement_ratio(level, 2) + gid = self._add_grid(grid, gid, level) + return gid + + def _add_grid(self, grid, gid, level=0): + mylog.debug("Adding grid %s on level %s (%s)", + grid.id, level, grid.Level) + if grid in self._grids: return + self._grids.append(grid) + + scalars = grid.get_vertex_centered_data(self.field, smoothed=self.smoothed) + + left_index = grid.get_global_startindex() + origin = grid.LeftEdge + dds = grid.dds + right_index = left_index + scalars.shape - 1 + ug = tvtk.UniformGrid(origin=origin, spacing=dds, + dimensions=grid.ActiveDimensions+1) + if self.field not in self.pf.field_info or \ + self.pf.field_info[self.field].take_log: + scalars = na.log10(scalars) + ug.point_data.scalars = scalars.transpose().ravel() + ug.point_data.scalars.name = self.field + if grid.Level != self.min_grid_level + self.number_of_levels - 1: + ug.cell_visibility_array = grid.child_mask.transpose().ravel() + else: + ug.cell_visibility_array = na.ones( + grid.ActiveDimensions, dtype='int').ravel() + self._ugs.append((grid,ug)) + self._hdata_set.set_data_set(level, gid, left_index, right_index, ug) + + self._min_val = min(self._min_val, scalars.min()) + self._max_val = max(self._max_val, scalars.max()) + + gid += 1 + return gid + + def _add_data_to_ug(self, field): + for g, ug in self._ugs: + scalars_temp = grid.get_vertex_centered_data(field, smoothed=self.smoothed) + ii = ug.point_data.add_array(scalars_temp.transpose().ravel()) + ug.point_data.get_array(ii).name = field + + def zoom(self, dist, unit='1'): + vec = self.scene.camera.focal_point - \ + self.scene.camera.position + self.scene.camera.position += \ + vec * dist/self._grids[0].pf[unit] + self.scene.render() + + def toggle_grid_boundaries(self): + if self._grid_boundaries_actor is None: + # We don't need to track this stuff right now. + ocf = tvtk.OutlineCornerFilter( + executive=tvtk.CompositeDataPipeline(), + corner_factor = 0.5) + ocf.input = self._hdata_set + ocm = tvtk.HierarchicalPolyDataMapper( + input_connection = ocf.output_port) + self._grid_boundaries_actor = tvtk.Actor(mapper = ocm) + self.scene.add_actor(self._grid_boundaries_actor) + else: + self._grid_boundaries_actor.visibility = \ + (not self._grid_boundaries_actor.visibility) + + def _add_sphere(self, origin=(0.0,0.0,0.0), normal=(0,1,0)): + sphere = tvtk.Sphere(center=origin, radius=0.25) + cutter = tvtk.Cutter(executive = tvtk.CompositeDataPipeline(), + cut_function = sphere) + cutter.input = self._hdata_set + lut_manager = LUTManager(data_name=self.field, scene=self.scene) + smap = tvtk.HierarchicalPolyDataMapper( + scalar_range=(self._min_val, self._max_val), + lookup_table=lut_manager.lut, + input_connection = cutter.output_port) + sactor = tvtk.Actor(mapper=smap) + self.scene.add_actors(sactor) + return sphere, lut_manager + + def _add_plane(self, origin=(0.0,0.0,0.0), normal=(0,1,0)): + plane = tvtk.Plane(origin=origin, normal=normal) + cutter = tvtk.Cutter(executive = tvtk.CompositeDataPipeline(), + cut_function = plane) + cutter.input = self._hdata_set + lut_manager = LUTManager(data_name=self.field, scene=self.scene) + smap = tvtk.HierarchicalPolyDataMapper( + scalar_range=(self._min_val, self._max_val), + lookup_table=lut_manager.lut, + input_connection = cutter.output_port) + sactor = tvtk.Actor(mapper=smap) + self.scene.add_actors(sactor) + return plane, lut_manager + + def add_plane(self, origin=(0.0,0.0,0.0), normal=(0,1,0)): + self.operators.append(self._add_plane(origin, normal)) + return self.operators[-1] + + def _add_axis_plane(self, axis): + normal = [0,0,0] + normal[axis] = 1 + np, lut_manager = self._add_plane(self.center, normal=normal) + LE = self.extracted_hierarchy.min_left_edge + RE = self.extracted_hierarchy.max_right_edge + self.operators.append(MappingPlane( + vmin=LE[axis], vmax=RE[axis], + vdefault = self.center[axis], + post_call = self.scene.render, + plane = np, axis=axis, coord=0.0, + lut_manager = lut_manager, + scene=self.scene)) + + def add_x_plane(self): + self._add_axis_plane(0) + return self.operators[-1] + + def add_y_plane(self): + self._add_axis_plane(1) + return self.operators[-1] + + def add_z_plane(self): + self._add_axis_plane(2) + return self.operators[-1] + + def add_contour(self, val=None): + if val is None: + if self._min_val != self._min_val: + self._min_val = 1.0 + val = (self._max_val+self._min_val) * 0.5 + cubes = tvtk.MarchingCubes( + executive = tvtk.CompositeDataPipeline()) + cubes.input = self._hdata_set + cubes.set_value(0, val) + lut_manager = LUTManager(data_name=self.field, scene=self.scene) + cube_mapper = tvtk.HierarchicalPolyDataMapper( + input_connection = cubes.output_port, + lookup_table=lut_manager.lut) + cube_mapper.color_mode = 'map_scalars' + cube_mapper.scalar_range = (self._min_val, self._max_val) + cube_actor = tvtk.Actor(mapper=cube_mapper) + self.scene.add_actors(cube_actor) + self.operators.append(MappingMarchingCubes(operator=cubes, + vmin=self._min_val, vmax=self._max_val, + vdefault=val, + mapper = cube_mapper, + post_call = self.scene.render, + lut_manager = lut_manager, + scene=self.scene)) + return self.operators[-1] + + def add_isocontour(self, val=None): + if val is None: val = (self._max_val+self._min_val) * 0.5 + isocontour = tvtk.ContourFilter( + executive = tvtk.CompositeDataPipeline()) + isocontour.input = self._hdata_set + isocontour.generate_values(1, (val, val)) + lut_manager = LUTManager(data_name=self.field, scene=self.scene) + isocontour_normals = tvtk.PolyDataNormals( + executive=tvtk.CompositeDataPipeline()) + isocontour_normals.input_connection = isocontour.output_port + iso_mapper = tvtk.HierarchicalPolyDataMapper( + input_connection = isocontour_normals.output_port, + lookup_table=lut_manager.lut) + iso_mapper.scalar_range = (self._min_val, self._max_val) + iso_actor = tvtk.Actor(mapper=iso_mapper) + self.scene.add_actors(iso_actor) + self.operators.append(MappingIsoContour(operator=isocontour, + vmin=self._min_val, vmax=self._max_val, + vdefault=val, + mapper = iso_mapper, + post_call = self.scene.render, + lut_manager = lut_manager, + scene=self.scene)) + return self.operators[-1] + + def display_points(self): + dd = self.pf.h.all_data() + points = tvtk.Points() + good = (dd["creation_time"] > 0.0) + points.data = na.array([ dd["particle_position_%s" % ax][good] for ax in 'xyz' ]).transpose() + mass = na.log10(dd["ParticleAge"][good]) + self.conn = tvtk.CellArray() + for i in xrange(mass.shape[0]): + self.conn.insert_next_cell(1) + self.conn.insert_cell_point(i) + self.points = points + self.pd = tvtk.PolyData(points = self.points, verts = self.conn) + self.pd.point_data.scalars = mass + lut = tvtk.LookupTable() + self.pdm = tvtk.PolyDataMapper(input = self.pd, + lookup_table = lut) + self.pdm.scalar_range = (mass.min(), mass.max()) + self.pdm.scalar_mode = 'use_point_data' + self.point_actor = tvtk.Actor(mapper = self.pdm) + self.scene.add_actor(self.point_actor) + +def get_all_parents(grid): + parents = [] + if len(grid.Parents) == 0: return grid + for parent in grid.Parents: parents.append(get_all_parents(parent)) + return list(set(parents)) + +def run_vtk(): + gui = pyface.GUI() + importer = HierarchyImporter() + importer.edit_traits(handler = HierarchyImportHandler( + importer = importer)) + #ehds.edit_traits() + gui.start_event_loop() + + +if __name__=="__main__": + print "This code probably won't work. But if you want to give it a try," + print "you need:" + print + print "VTK (CVS)" + print "Mayavi2 (from Enthought)" + print + print "If you have 'em, give it a try!" + print + run_vtk() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/BaseDataTypes.py --- a/yt/lagos/BaseDataTypes.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3050 +0,0 @@ -""" -Various non-grid data containers. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Author: Britton Smith -Affiliation: University of Colorado at Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -data_object_registry = {} - -from yt.lagos import * -from yt.amr_utils import QuadTree -import math - -def restore_grid_state(func): - """ - A decorator that takes a function with the API of (self, grid, field) - and ensures that after the function is called, the field_parameters will - be returned to normal. - """ - def save_state(self, grid, field=None): - old_params = grid.field_parameters - old_keys = grid.data.keys() - grid.field_parameters = self.field_parameters - tr = func(self, grid, field) - grid.field_parameters = old_params - grid.data = dict( [(k, grid.data[k]) for k in old_keys] ) - return tr - return save_state - -def cache_mask(func): - """ - For computationally intensive indexing operations, we can cache - between calls. - """ - def check_cache(self, grid): - if isinstance(grid, FakeGridForParticles): - return func(self, grid) - elif grid.id not in self._cut_masks: - cm = func(self, grid) - self._cut_masks[grid.id] = cm - return self._cut_masks[grid.id] - return check_cache - -def cache_point_indices(func): - """ - For computationally intensive indexing operations, we can cache - between calls. - """ - def check_cache(self, grid, use_child_mask=True): - if isinstance(grid, FakeGridForParticles): - return func(self, grid, use_child_mask) - elif grid.id not in self._point_indices: - cm = func(self, grid, use_child_mask) - self._point_indices[grid.id] = cm - return self._point_indices[grid.id] - return check_cache - -def cache_vc_data(func): - """ - For computationally intensive operations, we can cache between - calls. - """ - def check_cache(self, grid, field): - if isinstance(grid, FakeGridForParticles): - return func(self, grid, field) - elif grid.id not in self._vc_data[field]: - vc = func(self, grid, field) - self._vc_data[field][grid.id] = vc - return self._vc_data[field][grid.id] - return check_cache - -class FakeGridForParticles(object): - """ - Mock up a grid to insert particle positions and radii - into for purposes of confinement in an :class:`AMR3DData`. - """ - def __init__(self, grid): - self._corners = grid._corners - self.field_parameters = {} - self.data = {'x':grid['particle_position_x'], - 'y':grid['particle_position_y'], - 'z':grid['particle_position_z'], - 'dx':grid['dx'], - 'dy':grid['dy'], - 'dz':grid['dz']} - self.dds = grid.dds.copy() - self.real_grid = grid - self.child_mask = 1 - self.ActiveDimensions = self.data['x'].shape - def __getitem__(self, field): - if field not in self.data.keys(): - if field == "RadiusCode": - center = self.field_parameters['center'] - tr = na.sqrt( (self['x'] - center[0])**2.0 + - (self['y'] - center[1])**2.0 + - (self['z'] - center[2])**2.0 ) - else: - raise KeyError(field) - else: tr = self.data[field] - return tr - -class AMRData(object): - """ - Generic AMRData container. By itself, will attempt to - generate field, read fields (method defined by derived classes) - and deal with passing back and forth field parameters. - """ - _grids = None - _num_ghost_zones = 0 - _con_args = () - _skip_add = False - - class __metaclass__(type): - def __init__(cls, name, b, d): - type.__init__(cls, name, b, d) - if hasattr(cls, "_type_name") and not cls._skip_add: - data_object_registry[cls._type_name] = cls - - def __init__(self, pf, fields, **kwargs): - """ - Typically this is never called directly, but only due to inheritance. - It associates a :class:`~yt.lagos.StaticOutput` with the class, - sets its initial set of fields, and the remainder of the arguments - are passed as field_parameters. - """ - if pf != None: - self.pf = pf - self.hierarchy = pf.hierarchy - self.hierarchy.objects.append(weakref.proxy(self)) - mylog.debug("Appending object to %s (type: %s)", self.pf, type(self)) - if fields == None: fields = [] - self.fields = ensure_list(fields)[:] - self.data = {} - self.field_parameters = {} - self.__set_default_field_parameters() - self._cut_masks = {} - self._point_indices = {} - self._vc_data = {} - for key, val in kwargs.items(): - self.set_field_parameter(key, val) - - def __set_default_field_parameters(self): - self.set_field_parameter("center",na.zeros(3,dtype='float64')) - self.set_field_parameter("bulk_velocity",na.zeros(3,dtype='float64')) - - def _set_center(self, center): - if center is None: - pass - elif isinstance(center, (types.ListType, types.TupleType, na.ndarray)): - center = na.array(center) - elif center == ("max"): # is this dangerous for race conditions? - center = pf.h.find_max("Density") - elif center.startswith("max_"): - center = pf.h.find_max(center[4:]) - else: - center = na.array(center, dtype='float64') - self.center = center - self.set_field_parameter('center', center) - - def get_field_parameter(self, name, default=None): - """ - This is typically only used by derived field functions, but - it returns parameters used to generate fields. - """ - if self.field_parameters.has_key(name): - return self.field_parameters[name] - else: - return default - - def set_field_parameter(self, name, val): - """ - Here we set up dictionaries that get passed up and down and ultimately - to derived fields. - """ - self.field_parameters[name] = val - - def has_field_parameter(self, name): - """ - Checks if a field parameter is set. - """ - return self.field_parameters.has_key(name) - - def convert(self, datatype): - """ - This will attempt to convert a given unit to cgs from code units. - It either returns the multiplicative factor or throws a KeyError. - """ - return self.pf[datatype] - - def clear_data(self): - """ - Clears out all data from the AMRData instance, freeing memory. - """ - self.data.clear() - if self._grids is not None: - for grid in self._grids: grid.clear_data() - - def clear_cache(self): - """ - Clears out all cache, freeing memory. - """ - for _cm in self._cut_masks: del _cm - for _pi in self._point_indices: del _pi - for _field in self._vc_data: - for _vc in _field: del _vc - - def has_key(self, key): - """ - Checks if a data field already exists. - """ - return self.data.has_key(key) - - def _refresh_data(self): - """ - Wipes data and rereads/regenerates it from the self.fields. - """ - self.clear_data() - self.get_data() - - def keys(self): - return self.data.keys() - - def __getitem__(self, key): - """ - Returns a single field. Will add if necessary. - """ - if not self.data.has_key(key): - if key not in self.fields: - self.fields.append(key) - self.get_data(key) - return self.data[key] - - def __setitem__(self, key, val): - """ - Sets a field to be some other value. - """ - if key not in self.fields: self.fields.append(key) - self.data[key] = val - - def __delitem__(self, key): - """ - Deletes a field - """ - try: - del self.fields[self.fields.index(key)] - except ValueError: - pass - del self.data[key] - - def _generate_field_in_grids(self, fieldName): - pass - - _key_fields = None - def write_out(self, filename, fields=None, format="%0.16e"): - if fields is None: fields=sorted(self.data.keys()) - if self._key_fields is None: raise ValueError - field_order = self._key_fields[:] - for field in field_order: self[field] - field_order += [field for field in fields if field not in field_order] - fid = open(filename,"w") - fid.write("\t".join(["#"] + field_order + ["\n"])) - field_data = na.array([self.data[field] for field in field_order]) - for line in range(field_data.shape[1]): - field_data[:,line].tofile(fid, sep="\t", format=format) - fid.write("\n") - fid.close() - - def save_object(self, name, filename = None): - """ - Save an object. If *filename* is supplied, it will be stored in - a :mod:`shelve` file of that name. Otherwise, it will be stored via - :meth:`yt.lagos.AMRHierarchy.save_object`. - """ - if filename is not None: - ds = shelve.open(filename, protocol=-1) - if name in ds: - mylog.info("Overwriting %s in %s", name, filename) - ds[name] = self - ds.close() - else: - self.hierarchy.save_object(self, name) - - def __reduce__(self): - args = tuple([self.pf._hash(), self._type_name] + - [getattr(self, n) for n in self._con_args] + - [self.field_parameters]) - return (_reconstruct_object, args) - - def __repr__(self): - # We'll do this the slow way to be clear what's going on - s = "%s (%s): " % (self.__class__.__name__, self.pf) - s += ", ".join(["%s=%s" % (i, getattr(self,i)) - for i in self._con_args]) - return s - -class GridPropertiesMixin(object): - - def select_grids(self, level): - """ - Return all grids on a given level. - """ - grids = [g for g in self._grids if g.Level == level] - return grids - - def select_grid_indices(self, level): - return na.where(self.grid_levels == level) - - def __get_grid_left_edge(self): - if self.__grid_left_edge == None: - self.__grid_left_edge = na.array([g.LeftEdge for g in self._grids]) - return self.__grid_left_edge - - def __del_grid_left_edge(self): - del self.__grid_left_edge - self.__grid_left_edge = None - - def __set_grid_left_edge(self, val): - self.__grid_left_edge = val - - __grid_left_edge = None - grid_left_edge = property(__get_grid_left_edge, __set_grid_left_edge, - __del_grid_left_edge) - - def __get_grid_right_edge(self): - if self.__grid_right_edge == None: - self.__grid_right_edge = na.array([g.RightEdge for g in self._grids]) - return self.__grid_right_edge - - def __del_grid_right_edge(self): - del self.__grid_right_edge - self.__grid_right_edge = None - - def __set_grid_right_edge(self, val): - self.__grid_right_edge = val - - __grid_right_edge = None - grid_right_edge = property(__get_grid_right_edge, __set_grid_right_edge, - __del_grid_right_edge) - - def __get_grid_levels(self): - if self.__grid_levels == None: - self.__grid_levels = na.array([g.Level for g in self._grids]) - return self.__grid_levels - - def __del_grid_levels(self): - del self.__grid_levels - self.__grid_levels = None - - def __set_grid_levels(self, val): - self.__grid_levels = val - - __grid_levels = None - grid_levels = property(__get_grid_levels, __set_grid_levels, - __del_grid_levels) - - -class AMR1DData(AMRData, GridPropertiesMixin): - _spatial = False - def __init__(self, pf, fields, **kwargs): - AMRData.__init__(self, pf, fields, **kwargs) - self._grids = None - self._sortkey = None - self._sorted = {} - - def _generate_field_in_grids(self, field, num_ghost_zones=0): - for grid in self._grids: - temp = grid[field] - - def _generate_field(self, field): - if self.pf.field_info.has_key(field): - # First we check the validator - try: - self.pf.field_info[field].check_available(self) - except NeedsGridType, ngt_exception: - # We leave this to be implementation-specific - self._generate_field_in_grids(field, ngt_exception.ghost_zones) - return False - else: - self[field] = self.pf.field_info[field](self) - return True - else: # Can't find the field, try as it might - raise exceptions.KeyError(field) - - def get_data(self, fields=None, in_grids=False): - if self._grids == None: - self._get_list_of_grids() - points = [] - if not fields: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(fields) - if not self.sort_by in fields_to_get and \ - self.sort_by not in self.data: - fields_to_get.insert(0, self.sort_by) - mylog.debug("Going to obtain %s", fields_to_get) - for field in fields_to_get: - if self.data.has_key(field): - continue - mylog.info("Getting field %s from %s", field, len(self._grids)) - if field not in self.hierarchy.field_list and not in_grids: - if field not in ("dts", "t") and self._generate_field(field): - continue # True means we already assigned it - self[field] = na.concatenate( - [self._get_data_from_grid(grid, field) - for grid in self._grids]) - if not self.data.has_key(field): - continue - if self._sortkey is None: - self._sortkey = na.argsort(self[self.sort_by]) - # We *always* sort the field here if we have not successfully - # generated it above. This way, fields that are grabbed from the - # grids are sorted properly. - self[field] = self[field][self._sortkey] - -class AMROrthoRayBase(AMR1DData): - _key_fields = ['x','y','z','dx','dy','dz'] - _type_name = "ortho_ray" - _con_args = ('axis', 'coords') - def __init__(self, axis, coords, fields=None, pf=None, **kwargs): - """ - Dimensionality is reduced to one, and an ordered list of points at an - (x,y) tuple along *axis* are available. - """ - AMR1DData.__init__(self, pf, fields, **kwargs) - self.axis = axis - self.px_ax = x_dict[self.axis] - self.py_ax = y_dict[self.axis] - self.px_dx = 'd%s'%(axis_names[self.px_ax]) - self.py_dx = 'd%s'%(axis_names[self.py_ax]) - self.px, self.py = coords - self.sort_by = axis_names[self.axis] - self._refresh_data() - - def _get_list_of_grids(self): - # This bugs me, but we will give the tie to the LeftEdge - y = na.where( (self.px >= self.pf.hierarchy.grid_left_edge[:,self.px_ax]) - & (self.px < self.pf.hierarchy.grid_right_edge[:,self.px_ax]) - & (self.py >= self.pf.hierarchy.grid_left_edge[:,self.py_ax]) - & (self.py < self.pf.hierarchy.grid_right_edge[:,self.py_ax])) - self._grids = self.hierarchy.grids[y] - - def _get_data_from_grid(self, grid, field): - # We are orthogonal, so we can feel free to make assumptions - # for the sake of speed. - if grid.id not in self._cut_masks: - gdx = just_one(grid[self.px_dx]) - gdy = just_one(grid[self.py_dx]) - x_coord = int((self.px - grid.LeftEdge[self.px_ax])/gdx) - y_coord = int((self.py - grid.LeftEdge[self.py_ax])/gdy) - sl = [None,None,None] - sl[self.px_ax] = slice(x_coord,x_coord+1,None) - sl[self.py_ax] = slice(y_coord,y_coord+1,None) - sl[self.axis] = slice(None) - self._cut_masks[grid.id] = sl - else: - sl = self._cut_masks[grid.id] - if not iterable(grid[field]): - gf = grid[field] * na.ones(grid.child_mask[sl].shape) - else: - gf = grid[field][sl] - return gf[na.where(grid.child_mask[sl])] - -class AMRRayBase(AMR1DData): - _type_name = "ray" - _con_args = ('start_point', 'end_point') - sort_by = 't' - def __init__(self, start_point, end_point, fields=None, pf=None, **kwargs): - """ - We accept a start point and an end point and then get all the data - between those two. - """ - AMR1DData.__init__(self, pf, fields, **kwargs) - self.start_point = na.array(start_point, dtype='float64') - self.end_point = na.array(end_point, dtype='float64') - self.vec = self.end_point - self.start_point - #self.vec /= na.sqrt(na.dot(self.vec, self.vec)) - self._set_center(self.start_point) - self.set_field_parameter('center', self.start_point) - self._dts, self._ts = {}, {} - #self._refresh_data() - - def _get_list_of_grids(self): - # Get the value of the line at each LeftEdge and RightEdge - LE = self.pf.h.grid_left_edge - RE = self.pf.h.grid_right_edge - p = na.zeros(self.pf.h.num_grids, dtype='bool') - # Check left faces first - for i in range(3): - i1 = (i+1) % 3 - i2 = (i+2) % 3 - vs = self._get_line_at_coord(LE[:,i], i) - p = p | ( ( (LE[:,i1] <= vs[:,i1]) & (RE[:,i1] >= vs[:,i1]) ) \ - & ( (LE[:,i2] <= vs[:,i2]) & (RE[:,i2] >= vs[:,i2]) ) ) - vs = self._get_line_at_coord(RE[:,i], i) - p = p | ( ( (LE[:,i1] <= vs[:,i1]) & (RE[:,i1] >= vs[:,i1]) ) \ - & ( (LE[:,i2] <= vs[:,i2]) & (RE[:,i2] >= vs[:,i2]) ) ) - p = p | ( na.all( LE <= self.start_point, axis=1 ) - & na.all( RE >= self.start_point, axis=1 ) ) - p = p | ( na.all( LE <= self.end_point, axis=1 ) - & na.all( RE >= self.end_point, axis=1 ) ) - self._grids = self.hierarchy.grids[p] - - def _get_line_at_coord(self, v, index): - # t*self.vec + self.start_point = self.end_point - t = (v - self.start_point[index])/self.vec[index] - t = t.reshape((t.shape[0],1)) - return self.start_point + t*self.vec - - def _get_data_from_grid(self, grid, field): - mask = na.logical_and(self._get_cut_mask(grid), - grid.child_mask) - if field == 'dts': return self._dts[grid.id][mask] - if field == 't': return self._ts[grid.id][mask] - return grid[field][mask] - - @cache_mask - def _get_cut_mask(self, grid): - mask = na.zeros(grid.ActiveDimensions, dtype='int') - dts = na.zeros(grid.ActiveDimensions, dtype='float64') - ts = na.zeros(grid.ActiveDimensions, dtype='float64') - from yt.amr_utils import VoxelTraversal - VoxelTraversal(mask, ts, dts, grid.LeftEdge, grid.RightEdge, - grid.dds, self.center, self.vec) - self._dts[grid.id] = na.abs(dts) - self._ts[grid.id] = na.abs(ts) - return mask - -class AMR2DData(AMRData, GridPropertiesMixin, ParallelAnalysisInterface): - _key_fields = ['px','py','pdx','pdy'] - """ - Class to represent a set of :class:`AMRData` that's 2-D in nature, and - thus does not have as many actions as the 3-D data types. - """ - _spatial = False - def __init__(self, axis, fields, pf=None, **kwargs): - """ - Prepares the AMR2DData, normal to *axis*. If *axis* is 4, we are not - aligned with any axis. - """ - self.axis = axis - AMRData.__init__(self, pf, fields, **kwargs) - self.field = ensure_list(fields)[0] - self.set_field_parameter("axis",axis) - - def _convert_field_name(self, field): - return field - - #@time_execution - def get_data(self, fields = None): - """ - Iterates over the list of fields and generates/reads them all. - """ - # We get it for the values in fields and coords - # We take a 3-tuple of the coordinate we want to slice through, as well - # as the axis we're slicing along - self._get_list_of_grids() - if not self.has_key('pdx'): - self._generate_coords() - if fields == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(fields) - temp_data = {} - for field in fields_to_get: - if self.data.has_key(field): continue - if field not in self.hierarchy.field_list: - if self._generate_field(field): - continue # A "True" return means we did it - # To ensure that we use data from this object as much as possible, - # we're going to have to set the same thing several times - data = [self._get_data_from_grid(grid, field) - for grid in self._get_grids()] - if len(data) == 0: data = na.array([]) - else: data = na.concatenate(data) - temp_data[field] = data - # Now the next field can use this field - self[field] = temp_data[field] - # We finalize - if temp_data != {}: - temp_data = self._mpi_catdict(temp_data) - # And set, for the next group - for field in temp_data.keys(): - self[field] = temp_data[field] - - - def _generate_field(self, field): - if self.pf.field_info.has_key(field): - # First we check the validator - try: - self.pf.field_info[field].check_available(self) - except NeedsGridType, ngt_exception: - # We leave this to be implementation-specific - self._generate_field_in_grids(field, ngt_exception.ghost_zones) - return False - else: - self[field] = self.pf.field_info[field](self) - return True - else: # Can't find the field, try as it might - raise exceptions.KeyError(field) - - def _generate_field_in_grids(self, field, num_ghost_zones=0): - for grid in self._grids: - temp = grid[field] - - def interpolate_discretize(self, LE, RE, field, side, log_spacing=True): - """ - This returns a uniform grid of points between *LE* and *RE*, - interpolated using the nearest neighbor method, with *side* points on a - side. - """ - import yt.raven.delaunay as de - if log_spacing: - zz = na.log10(self[field]) - else: - zz = self[field] - xi, yi = na.array( \ - na.mgrid[LE[0]:RE[0]:side*1j, \ - LE[1]:RE[1]:side*1j], 'float64') - zi = de.Triangulation(self['px'],self['py']).nn_interpolator(zz)\ - [LE[0]:RE[0]:side*1j, \ - LE[1]:RE[1]:side*1j] - if log_spacing: - zi = 10**(zi) - return [xi,yi,zi] - - _okay_to_serialize = True - - def _store_fields(self, fields, node_name = None, force = False): - fields = ensure_list(fields) - if node_name is None: node_name = self._gen_node_name() - for field in fields: - #mylog.debug("Storing %s in node %s", - #self._convert_field_name(field), node_name) - self.hierarchy.save_data(self[field], node_name, - self._convert_field_name(field), force = force, - passthrough = True) - - def _obtain_fields(self, fields, node_name = None): - if not self._okay_to_serialize: return - fields = ensure_list(fields) - if node_name is None: node_name = self._gen_node_name() - for field in fields: - #mylog.debug("Trying to obtain %s from node %s", - #self._convert_field_name(field), node_name) - fdata=self.hierarchy.get_data(node_name, - self._convert_field_name(field)) - if fdata is not None: - #mylog.debug("Got %s from node %s", field, node_name) - self[field] = fdata[:] - return True - - def _deserialize(self, node_name = None): - if not self._okay_to_serialize: return - self._obtain_fields(self._key_fields, node_name) - self._obtain_fields(self.fields, node_name) - - def _serialize(self, node_name = None, force = False): - if not self._okay_to_serialize: return - self._store_fields(self._key_fields, node_name, force) - self._store_fields(self.fields, node_name, force) - -class AMRSliceBase(AMR2DData): - """ - AMRSlice is an orthogonal slice through the data, taking all the points - at the finest resolution available and then indexing them. It is more - appropriately thought of as a slice 'operator' than an object, - however, as its field and coordinate can both change. - """ - - _top_node = "/Slices" - _type_name = "slice" - _con_args = ('axis', 'coord') - #@time_execution - def __init__(self, axis, coord, fields = None, center=None, pf=None, - node_name = False, **kwargs): - """ - Slice along *axis*:ref:`axis-specification`, at the coordinate *coord*. - Optionally supply fields. - """ - AMR2DData.__init__(self, axis, fields, pf, **kwargs) - self._set_center(center) - self.coord = coord - if node_name is False: - self._refresh_data() - else: - if node_name is True: self._deserialize() - else: self._deserialize(node_name) - - def reslice(self, coord): - """ - Change the entire dataset, clearing out the current data and slicing at - a new location. Not terribly useful except for in-place plot changes. - """ - mylog.debug("Setting coordinate to %0.5e" % coord) - self.coord = coord - self._refresh_data() - - def shift(self, val): - """ - Moves the slice coordinate up by either a floating point value, or an - integer number of indices of the finest grid. - """ - if isinstance(val, types.FloatType): - # We add the dx - self.coord += val - elif isinstance(val, types.IntType): - # Here we assume that the grid is the max level - level = self.hierarchy.max_level - self.coord - dx = self.hierarchy.select_grids(level)[0].dds[self.axis] - self.coord += dx * val - else: - raise ValueError(val) - self._refresh_data() - - def _generate_coords(self): - points = [] - for grid in self._get_grids(): - points.append(self._generate_grid_coords(grid)) - if len(points) == 0: points = None - else: points = na.concatenate(points) - t = self._mpi_catarray(points) - self['px'] = t[:,0] - self['py'] = t[:,1] - self['pz'] = t[:,2] - self['pdx'] = t[:,3] - self['pdy'] = t[:,4] - self['pdz'] = t[:,3] # Does not matter! - - # Now we set the *actual* coordinates - self[axis_names[x_dict[self.axis]]] = t[:,0] - self[axis_names[y_dict[self.axis]]] = t[:,1] - self[axis_names[self.axis]] = t[:,2] - - self.ActiveDimensions = (t.shape[0], 1, 1) - - def _get_list_of_grids(self): - goodI = ((self.pf.h.grid_right_edge[:,self.axis] > self.coord) - & (self.pf.h.grid_left_edge[:,self.axis] <= self.coord )) - self._grids = self.pf.h.grids[goodI] # Using sources not hierarchy - - def __cut_mask_child_mask(self, grid): - mask = grid.child_mask.copy() - return mask - - def _generate_grid_coords(self, grid): - xaxis = x_dict[self.axis] - yaxis = y_dict[self.axis] - ds, dx, dy = grid.dds[self.axis], grid.dds[xaxis], grid.dds[yaxis] - wantedIndex = int(((self.coord-grid.LeftEdge[self.axis])/ds)) - sl = [slice(None), slice(None), slice(None)] - sl[self.axis] = slice(wantedIndex, wantedIndex + 1) - #sl.reverse() - sl = tuple(sl) - nx = grid.child_mask.shape[xaxis] - ny = grid.child_mask.shape[yaxis] - mask = self.__cut_mask_child_mask(grid)[sl] - cm = na.where(mask.ravel()== 1) - cmI = na.indices((nx,ny)) - xind = cmI[0,:].ravel() - xpoints = na.ones(cm[0].shape, 'float64') - xpoints *= xind[cm]*dx+(grid.LeftEdge[xaxis] + 0.5*dx) - yind = cmI[1,:].ravel() - ypoints = na.ones(cm[0].shape, 'float64') - ypoints *= yind[cm]*dy+(grid.LeftEdge[yaxis] + 0.5*dy) - zpoints = na.ones(xpoints.shape, 'float64') * self.coord - dx = na.ones(xpoints.shape, 'float64') * dx/2.0 - dy = na.ones(xpoints.shape, 'float64') * dy/2.0 - t = na.array([xpoints, ypoints, zpoints, dx, dy]).swapaxes(0,1) - return t - - @restore_grid_state - def _get_data_from_grid(self, grid, field): - # So what's our index of slicing? This is what we need to figure out - # first, so we can deal with our data in the fastest way. - dx = grid.dds[self.axis] - wantedIndex = int(((self.coord-grid.LeftEdge[self.axis])/dx)) - sl = [slice(None), slice(None), slice(None)] - sl[self.axis] = slice(wantedIndex, wantedIndex + 1) - sl = tuple(sl) - if self.pf.field_info.has_key(field) and self.pf.field_info[field].particle_type: - return grid[field] - elif field in self.pf.field_info and self.pf.field_info[field].not_in_all: - dv = grid[field][sl] - elif not grid.has_key(field): - conv_factor = 1.0 - if self.pf.field_info.has_key(field): - conv_factor = self.pf.field_info[field]._convert_function(self) - dv = self.hierarchy.io._read_data_slice(grid, field, self.axis, wantedIndex) * conv_factor - else: - dv = grid[field] - if dv.size == 1: dv = na.ones(grid.ActiveDimensions)*dv - dv = dv[sl] - mask = self.__cut_mask_child_mask(grid)[sl] - dataVals = dv.ravel()[mask.ravel() == 1] - return dataVals - - def _gen_node_name(self): - return "%s/%s_%s" % \ - (self._top_node, self.axis, self.coord) - - def __get_quantities(self): - if self.__quantities is None: - self.__quantities = DerivedQuantityCollection(self) - return self.__quantities - __quantities = None - quantities = property(__get_quantities) - -class AMRCuttingPlaneBase(AMR2DData): - """ - AMRCuttingPlane is an oblique plane through the data, - defined by a normal vector and a coordinate. It attempts to guess - an 'up' vector, which cannot be overridden, and then it pixelizes - the appropriate data onto the plane without interpolation. - """ - _plane = None - _top_node = "/CuttingPlanes" - _key_fields = AMR2DData._key_fields + ['pz','pdz'] - _type_name = "cutting" - _con_args = ('normal', 'center') - def __init__(self, normal, center, fields = None, node_name = None, - **kwargs): - """ - The Cutting Plane slices at an oblique angle, where we use - the *normal* vector and the *center* to define the viewing plane. - The 'up' direction is guessed at automatically. - """ - AMR2DData.__init__(self, 4, fields, **kwargs) - self._set_center(center) - self.set_field_parameter('center',center) - # Let's set up our plane equation - # ax + by + cz + d = 0 - self._norm_vec = normal/na.sqrt(na.dot(normal,normal)) - self._d = -1.0 * na.dot(self._norm_vec, self.center) - # First we try all three, see which has the best result: - vecs = na.identity(3) - _t = na.cross(self._norm_vec, vecs).sum(axis=1) - ax = _t.argmax() - self._x_vec = na.cross(vecs[ax,:], self._norm_vec).ravel() - self._x_vec /= na.sqrt(na.dot(self._x_vec, self._x_vec)) - self._y_vec = na.cross(self._norm_vec, self._x_vec).ravel() - self._y_vec /= na.sqrt(na.dot(self._y_vec, self._y_vec)) - self._rot_mat = na.array([self._x_vec,self._y_vec,self._norm_vec]) - self._inv_mat = na.linalg.pinv(self._rot_mat) - self.set_field_parameter('cp_x_vec',self._x_vec) - self.set_field_parameter('cp_y_vec',self._y_vec) - self.set_field_parameter('cp_z_vec',self._norm_vec) - if node_name is False: - self._refresh_data() - else: - if node_name is True: self._deserialize() - else: self._deserialize(node_name) - - @property - def normal(self): - return self._norm_vec - - def _get_list_of_grids(self): - # Recall that the projection of the distance vector from a point - # onto the normal vector of a plane is: - # D = (a x_0 + b y_0 + c z_0 + d)/sqrt(a^2+b^2+c^2) - # @todo: Convert to using corners - LE = self.pf.h.grid_left_edge - RE = self.pf.h.grid_right_edge - vertices = na.array([[LE[:,0],LE[:,1],LE[:,2]], - [RE[:,0],RE[:,1],RE[:,2]], - [LE[:,0],LE[:,1],RE[:,2]], - [RE[:,0],RE[:,1],LE[:,2]], - [LE[:,0],RE[:,1],RE[:,2]], - [RE[:,0],LE[:,1],LE[:,2]], - [LE[:,0],RE[:,1],LE[:,2]], - [RE[:,0],LE[:,1],RE[:,2]]]) - # This gives us shape: 8, 3, n_grid - D = na.sum(self._norm_vec.reshape((1,3,1)) * vertices, axis=1) + self._d - self.D = D - self._grids = self.hierarchy.grids[ - na.where(na.logical_not(na.all(D<0,axis=0) | na.all(D>0,axis=0) )) ] - - @cache_mask - def _get_cut_mask(self, grid): - # This is slow. Suggestions for improvement would be great... - ss = grid.ActiveDimensions - D = na.ones(ss) * self._d - x = grid.LeftEdge[0] + grid.dds[0] * \ - (na.arange(grid.ActiveDimensions[0], dtype='float64')+0.5) - y = grid.LeftEdge[1] + grid.dds[1] * \ - (na.arange(grid.ActiveDimensions[1], dtype='float64')+0.5) - z = grid.LeftEdge[2] + grid.dds[2] * \ - (na.arange(grid.ActiveDimensions[2], dtype='float64')+0.5) - D += (x * self._norm_vec[0]).reshape(ss[0],1,1) - D += (y * self._norm_vec[1]).reshape(1,ss[1],1) - D += (z * self._norm_vec[2]).reshape(1,1,ss[2]) - diag_dist = na.sqrt(na.sum(grid.dds**2.0)) - cm = (na.abs(D) <= 0.5*diag_dist) # Boolean - return cm - - def _generate_coords(self): - points = [] - for grid in self._get_grids(): - points.append(self._generate_grid_coords(grid)) - if len(points) == 0: points = None - else: points = na.concatenate(points) - t = self._mpi_catarray(points) - pos = (t[:,0:3] - self.center) - self['px'] = na.dot(pos, self._x_vec) - self['py'] = na.dot(pos, self._y_vec) - self['pz'] = na.dot(pos, self._norm_vec) - self['pdx'] = t[:,3] * 0.5 - self['pdy'] = t[:,3] * 0.5 - self['pdz'] = t[:,3] * 0.5 - - def _generate_grid_coords(self, grid): - pointI = self._get_point_indices(grid) - coords = [grid[ax][pointI].ravel() for ax in 'xyz'] - coords.append(na.ones(coords[0].shape, 'float64') * just_one(grid['dx'])) - return na.array(coords).swapaxes(0,1) - - def _get_data_from_grid(self, grid, field): - if not self.pf.field_info[field].particle_type: - pointI = self._get_point_indices(grid) - if grid[field].size == 1: # dx, dy, dz, cellvolume - t = grid[field] * na.ones(grid.ActiveDimensions) - return t[pointI].ravel() - return grid[field][pointI].ravel() - else: - return grid[field] - - def interpolate_discretize(self, *args, **kwargs): - pass - - @cache_point_indices - def _get_point_indices(self, grid, use_child_mask=True): - k = na.zeros(grid.ActiveDimensions, dtype='bool') - k = (k | self._get_cut_mask(grid)) - if use_child_mask: k = (k & grid.child_mask) - return na.where(k) - - def _gen_node_name(self): - cen_name = ("%s" % (self.center,)).replace(" ","_")[1:-1] - L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1] - return "%s/c%s_L%s" % \ - (self._top_node, cen_name, L_name) - -class AMRFixedResCuttingPlaneBase(AMR2DData): - """ - AMRFixedResCuttingPlaneBase is an oblique plane through the data, - defined by a normal vector and a coordinate. It trilinearly - interpolates the data to a fixed resolution slice. It differs from - the other data objects as it doesn't save the grid data, only the - interpolated data. - """ - _top_node = "/FixedResCuttingPlanes" - _type_name = "fixed_res_cutting" - _con_args = ('normal', 'center', 'width', 'dims') - def __init__(self, normal, center, width, dims, fields = None, - node_name = None, **kwargs): - """ - The fixed resolution Cutting Plane slices at an oblique angle, - where we use the *normal* vector at the *center* to define the - viewing plane. The plane is *width* units wide. The 'up' - direction is guessed at automatically if not given. - """ - # - # Taken from Cutting Plane - # - AMR2DData.__init__(self, 4, fields, **kwargs) - self.center = center - self.width = width - self.dims = dims - self.dds = self.width / self.dims - self.bounds = na.array([0.0,1.0,0.0,1.0]) - - self.set_field_parameter('center', center) - # Let's set up our plane equation - # ax + by + cz + d = 0 - self._norm_vec = normal/na.sqrt(na.dot(normal,normal)) - self._d = -1.0 * na.dot(self._norm_vec, self.center) - # First we try all three, see which has the best result: - vecs = na.identity(3) - _t = na.cross(self._norm_vec, vecs).sum(axis=1) - ax = _t.argmax() - self._x_vec = na.cross(vecs[ax,:], self._norm_vec).ravel() - self._x_vec /= na.sqrt(na.dot(self._x_vec, self._x_vec)) - self._y_vec = na.cross(self._norm_vec, self._x_vec).ravel() - self._y_vec /= na.sqrt(na.dot(self._y_vec, self._y_vec)) - self._rot_mat = na.array([self._x_vec,self._y_vec,self._norm_vec]) - self._inv_mat = na.linalg.pinv(self._rot_mat) - self.set_field_parameter('cp_x_vec',self._x_vec) - self.set_field_parameter('cp_y_vec',self._y_vec) - self.set_field_parameter('cp_z_vec',self._norm_vec) - - # Calculate coordinates of each pixel - _co = self.dds * \ - (na.mgrid[-self.dims/2 : self.dims/2, - -self.dims/2 : self.dims/2] + 0.5) - self._coord = self.center + na.outer(_co[0,:,:], self._x_vec) + \ - na.outer(_co[1,:,:], self._y_vec) - self._pixelmask = na.ones(self.dims*self.dims, dtype='int8') - - if node_name is False: - self._refresh_data() - else: - if node_name is True: self._deserialize() - else: self._deserialize(node_name) - - @property - def normal(self): - return self._norm_vec - - def _get_list_of_grids(self): - # Just like the Cutting Plane but restrict the grids to be - # within width/2 of the center. - vertices = self.hierarchy.gridCorners - # Shape = (8,3,n_grid) - D = na.sum(self._norm_vec.reshape((1,3,1)) * vertices, axis=1) + self._d - valid_grids = na.where(na.logical_not(na.all(D<0,axis=0) | - na.all(D>0,axis=0) ))[0] - # Now restrict these grids to a rect. prism that bounds the slice - sliceCorners = na.array([ \ - self.center + 0.5*self.width * (+self._x_vec + self._y_vec), - self.center + 0.5*self.width * (+self._x_vec - self._y_vec), - self.center + 0.5*self.width * (-self._x_vec - self._y_vec), - self.center + 0.5*self.width * (-self._x_vec + self._y_vec) ]) - sliceLeftEdge = sliceCorners.min(axis=0) - sliceRightEdge = sliceCorners.max(axis=0) - # Check for bounding box and grid overlap - leftOverlap = na.less(self.hierarchy.gridLeftEdge[valid_grids], - sliceRightEdge).all(axis=1) - rightOverlap = na.greater(self.hierarchy.gridRightEdge[valid_grids], - sliceLeftEdge).all(axis=1) - self._grids = self.hierarchy.grids[valid_grids[ - na.where(leftOverlap & rightOverlap)]] - self._grids = self._grids[::-1] - - def _generate_coords(self): - self['px'] = self._coord[:,0].ravel() - self['py'] = self._coord[:,1].ravel() - self['pz'] = self._coord[:,2].ravel() - self['pdx'] = self.dds * 0.5 - self['pdy'] = self.dds * 0.5 - #self['pdz'] = self.dds * 0.5 - - def _get_data_from_grid(self, grid, field): - if not self.pf.field_info[field].particle_type: - pointI = self._get_point_indices(grid) - if len(pointI) == 0: return - vc = self._calc_vertex_centered_data(grid, field) - bds = na.array(zip(grid.LeftEdge, - grid.RightEdge)).ravel() - interp = TrilinearFieldInterpolator(vc, bds, ['x', 'y', 'z']) - self[field][pointI] = interp( \ - dict(x=self._coord[pointI,0], - y=self._coord[pointI,1], - z=self._coord[pointI,2])).ravel() - - # Mark these pixels to speed things up - self._pixelmask[pointI] = 0 - - return - else: - raise SyntaxError("Making a fixed resolution slice with " - "particles isn't supported yet.") - - def reslice(self, normal, center, width): - - # Cleanup - del self._coord - del self._pixelmask - - self.center = center - self.width = width - self.dds = self.width / self.dims - self.set_field_parameter('center', center) - self._norm_vec = normal/na.sqrt(na.dot(normal,normal)) - self._d = -1.0 * na.dot(self._norm_vec, self.center) - # First we try all three, see which has the best result: - vecs = na.identity(3) - _t = na.cross(self._norm_vec, vecs).sum(axis=1) - ax = _t.argmax() - self._x_vec = na.cross(vecs[ax,:], self._norm_vec).ravel() - self._x_vec /= na.sqrt(na.dot(self._x_vec, self._x_vec)) - self._y_vec = na.cross(self._norm_vec, self._x_vec).ravel() - self._y_vec /= na.sqrt(na.dot(self._y_vec, self._y_vec)) - self.set_field_parameter('cp_x_vec',self._x_vec) - self.set_field_parameter('cp_y_vec',self._y_vec) - self.set_field_parameter('cp_z_vec',self._norm_vec) - # Calculate coordinates of each pixel - _co = self.dds * \ - (na.mgrid[-self.dims/2 : self.dims/2, - -self.dims/2 : self.dims/2] + 0.5) - - self._coord = self.center + na.outer(_co[0,:,:], self._x_vec) + \ - na.outer(_co[1,:,:], self._y_vec) - self._pixelmask = na.ones(self.dims*self.dims, dtype='int8') - - self._refresh_data() - return - - #@time_execution - def get_data(self, fields = None): - """ - Iterates over the list of fields and generates/reads them all. - """ - self._get_list_of_grids() - if not self.has_key('pdx'): - self._generate_coords() - if fields == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(fields) - temp_data = {} - _size = self.dims * self.dims - for field in fields_to_get: - if self.data.has_key(field): continue - if field not in self.hierarchy.field_list: - if self._generate_field(field): - continue # A "True" return means we did it - if not self._vc_data.has_key(field): - self._vc_data[field] = {} - self[field] = na.zeros(_size, dtype='float64') - for grid in self._get_grids(): - self._get_data_from_grid(grid, field) - self[field] = self._mpi_allsum(self[field]).reshape([self.dims]*2).transpose() - - def interpolate_discretize(self, *args, **kwargs): - pass - - @cache_vc_data - def _calc_vertex_centered_data(self, grid, field): - #return grid.retrieve_ghost_zones(1, field, smoothed=False) - return grid.get_vertex_centered_data(field) - - def _get_point_indices(self, grid): - if self._pixelmask.max() == 0: return [] - k = amr_utils.planar_points_in_volume( - self._coord, self._pixelmask, - grid.LeftEdge, grid.RightEdge, - grid.child_mask, just_one(grid['dx'])) - return k - - def _gen_node_name(self): - cen_name = ("%s" % (self.center,)).replace(" ","_")[1:-1] - L_name = ("%s" % self._norm_vec).replace(" ","_")[1:-1] - return "%s/c%s_L%s" % \ - (self._top_node, cen_name, L_name) - -class AMRQuadTreeProjBase(AMR2DData): - _top_node = "/Projections" - _key_fields = AMR2DData._key_fields + ['weight_field'] - _type_name = "quad_proj" - _con_args = ('axis', 'field', 'weight_field') - def __init__(self, axis, field, weight_field = None, - max_level = None, center = None, pf = None, - source=None, node_name = None, field_cuts = None, - preload_style='level', serialize=True,**kwargs): - """ - AMRProj is a projection of a *field* along an *axis*. The field - can have an associated *weight_field*, in which case the values are - multiplied by a weight before being summed, and then divided by the sum - of that weight. - """ - AMR2DData.__init__(self, axis, field, pf, node_name = None, **kwargs) - self.weight_field = weight_field - self._field_cuts = field_cuts - self.serialize = serialize - self._set_center(center) - if center is not None: self.set_field_parameter('center',center) - self._node_name = node_name - self._initialize_source(source) - self.func = na.sum # for the future - self._grids = self.source._grids - if max_level == None: - max_level = self.hierarchy.max_level - if self.source is not None: - max_level = min(max_level, self.source.grid_levels.max()) - self._max_level = max_level - self._weight = weight_field - self.preload_style = preload_style - self._deserialize(node_name) - self._refresh_data() - if self._okay_to_serialize and self.serialize: self._serialize(node_name=self._node_name) - - def _convert_field_name(self, field): - if field == "weight_field": return "weight_field_%s" % self._weight - if field in self._key_fields: return field - return "%s_%s" % (field, self._weight) - - def _initialize_source(self, source = None): - if source is None: - check, source = self._partition_hierarchy_2d(self.axis) - self._check_region = check - #self._okay_to_serialize = (not check) - else: - self._distributed = False - self._okay_to_serialize = False - self._check_region = True - self.source = source - if self._field_cuts is not None: - # Override if field cuts are around; we don't want to serialize! - self._check_region = True - self._okay_to_serialize = False - if self._node_name is not None: - self._node_name = "%s/%s" % (self._top_node,self._node_name) - self._okay_to_serialize = True - - def _get_tree(self, nvals): - xd = self.pf["TopGridDimensions"][x_dict[self.axis]] - yd = self.pf["TopGridDimensions"][y_dict[self.axis]] - return QuadTree(na.array([xd,yd]), nvals) - - def _get_dls(self, grid, fields): - # Place holder for a time when maybe we will not be doing just - # a single dx for every field. - dls = [] - convs = [] - for field in fields + [self._weight]: - if field is None: continue - dls.append(just_one(grid['d%s' % axis_names[self.axis]])) - convs.append(self.pf.units[self.pf.field_info[field].projection_conversion]) - return na.array(dls), na.array(convs) - - def get_data(self, fields = None): - if fields is None: fields = ensure_list(self.fields)[:] - else: fields = ensure_list(fields) - # We need a new tree for every single set of fields we add - self._obtain_fields(fields, self._node_name) - fields = [f for f in fields if f not in self.data] - if len(fields) == 0: return - tree = self._get_tree(len(fields) + int(self._weight is not None)) - coord_data = [] - field_data = [] - dxs = [] - # We do this here, but I am not convinced it should be done here - # It is probably faster, as it consolidates IO, but if we did it in - # _project_level, then it would be more memory conservative - if self.preload_style == 'all': - print "Preloading %s grids and getting %s" % ( - len(self.source._grids), self._get_dependencies(fields)) - self._preload(self.source._grids, - self._get_dependencies(fields), self.hierarchy.io) - # By changing the remove-from-tree method to accumulate, we can avoid - # having to do this by level, and instead do it by CPU file - for level in range(0, self._max_level+1): - if self.preload_style == 'level': - self._preload(self.source.select_grids(level), - self._get_dependencies(fields), self.hierarchy.io) - self._add_level_to_tree(tree, level, fields) - mylog.debug("End of projecting level level %s, memory usage %0.3e", - level, get_memory_usage()/1024.) - # Note that this will briefly double RAM usage - coord_data, field_data, weight_data, dxs = [], [], [], [] - for level in range(0, self._max_level + 1): - npos, nvals, nwvals = tree.get_all_from_level(level, False) - coord_data.append(npos) - if self._weight is not None: nvals /= nwvals - field_data.append(nvals) - weight_data.append(nwvals) - gs = self.source.select_grids(level) - if len(gs) > 0: - ds = gs[0].dds[0] - else: - ds = 0.0 - dxs.append(na.ones(nvals.shape[0], dtype='float64') * ds) - del tree - coord_data = na.concatenate(coord_data, axis=0).transpose() - field_data = na.concatenate(field_data, axis=0).transpose() - weight_data = na.concatenate(weight_data, axis=0).transpose() - dxs = na.concatenate(dxs, axis=0).transpose() - # We now convert to half-widths and center-points - data = {} - data['pdx'] = dxs - ox = self.pf["DomainLeftEdge"][x_dict[self.axis]] - oy = self.pf["DomainLeftEdge"][y_dict[self.axis]] - data['px'] = (coord_data[0,:]+0.5) * data['pdx'] + ox - data['py'] = (coord_data[1,:]+0.5) * data['pdx'] + oy - data['weight_field'] = weight_data - del coord_data - data['pdx'] *= 0.5 - data['pdy'] = data['pdx'] # generalization is out the window! - data['fields'] = field_data - # Now we run the finalizer, which is ignored if we don't need it - data = self._mpi_catdict(data) - field_data = na.vsplit(data.pop('fields'), len(fields)) - for fi, field in enumerate(fields): - self[field] = field_data[fi].ravel() - if self.serialize: self._store_fields(field, self._node_name) - for i in data.keys(): self[i] = data.pop(i) - mylog.info("Projection completed") - - def _add_grid_to_tree(self, tree, grid, fields, zero_out, dls): - # We build up the fields to add - if self._weight is None: - weight_data = na.ones(grid.ActiveDimensions, dtype='float64') - if zero_out: weight_data[grid.child_indices] = 0 - masked_data = [fd.astype('float64') * weight_data - for fd in self._get_data_from_grid(grid, fields)] - wdl = 1.0 - else: - fields_to_get = list(set(fields + [self._weight])) - field_data = dict(zip( - fields_to_get, self._get_data_from_grid(grid, fields_to_get))) - weight_data = field_data[self._weight].copy().astype('float64') - if zero_out: weight_data[grid.child_indices] = 0 - masked_data = [field_data[field].copy().astype('float64') * weight_data - for field in fields] - del field_data - wdl = self.dls[-1] - full_proj = [self.func(field, axis=self.axis) * dl - for field, dl in zip(masked_data, dls)] - weight_proj = self.func(weight_data, axis=self.axis) * wdl - if (self._check_region and not self.source._is_fully_enclosed(grid)) or self._field_cuts is not None: - used_data = self._get_points_in_region(grid).astype('bool') - used_points = na.where(na.logical_or.reduce(used_data, self.axis)) - else: - used_data = na.array([1.0], dtype='bool') - used_points = slice(None) - xind, yind = [arr[used_points].ravel() for arr in na.indices(full_proj[0].shape)] - start_index = grid.get_global_startindex() - xpoints = (xind + (start_index[x_dict[self.axis]])).astype('int64') - ypoints = (yind + (start_index[y_dict[self.axis]])).astype('int64') - to_add = na.array([d[used_points].ravel() for d in full_proj]) - tree.add_array_to_tree(grid.Level, xpoints, ypoints, - to_add, weight_proj[used_points].ravel()) - - def _add_level_to_tree(self, tree, level, fields): - grids_to_project = self.source.select_grids(level) - dls, convs = self._get_dls(grids_to_project[0], fields) - zero_out = (level != self._max_level) - pbar = get_pbar('Projecting level % 2i / % 2i ' \ - % (level, self._max_level), len(grids_to_project)) - for pi, grid in enumerate(grids_to_project): - self._add_grid_to_tree(tree, grid, fields, zero_out, dls) - pbar.update(pi) - grid.clear_data() - pbar.finish() - lt = tree.get_all_from_level(level, False) - return - if self._weight is not None: - field_data = field_data / coord_data[3,:].reshape((1,coord_data.shape[1])) - else: - field_data *= convs[...,na.newaxis] - mylog.info("Level %s done: %s final", \ - level, coord_data.shape[1]) - dx = grids_to_project[0].dds[self.axis] # this is our dl - return coord_data, dx, field_data - - - def _get_points_in_region(self, grid): - pointI = self.source._get_point_indices(grid, use_child_mask=False) - point_mask = na.zeros(grid.ActiveDimensions) - point_mask[pointI] = 1.0 - if self._field_cuts is not None: - for cut in self._field_cuts: - point_mask *= eval(cut) - return point_mask - - @restore_grid_state - def _get_data_from_grid(self, grid, fields): - fields = ensure_list(fields) - if self._check_region: - bad_points = self._get_points_in_region(grid) - else: - bad_points = 1.0 - return [grid[field] * bad_points for field in fields] - - def _gen_node_name(self): - return "%s/%s" % \ - (self._top_node, self.axis) - -class AMRProjBase(AMR2DData): - _top_node = "/Projections" - _key_fields = AMR2DData._key_fields + ['weight_field'] - _type_name = "proj" - _con_args = ('axis', 'field', 'weight_field') - def __init__(self, axis, field, weight_field = None, - max_level = None, center = None, pf = None, - source=None, node_name = None, field_cuts = None, - preload_style='level', serialize=True,**kwargs): - """ - AMRProj is a projection of a *field* along an *axis*. The field - can have an associated *weight_field*, in which case the values are - multiplied by a weight before being summed, and then divided by the sum - of that weight. - """ - AMR2DData.__init__(self, axis, field, pf, node_name = None, **kwargs) - self.weight_field = weight_field - self._field_cuts = field_cuts - self.serialize = serialize - self._set_center(center) - if center is not None: self.set_field_parameter('center',center) - self._node_name = node_name - self._initialize_source(source) - self._grids = self.source._grids - if max_level == None: - max_level = self.hierarchy.max_level - if self.source is not None: - max_level = min(max_level, self.source.grid_levels.max()) - self._max_level = max_level - self._weight = weight_field - self.preload_style = preload_style - self.func = na.sum # for the future - self.__retval_coords = {} - self.__retval_fields = {} - self.__retval_coarse = {} - self.__overlap_masks = {} - self._deserialize(node_name) - self._refresh_data() - if self._okay_to_serialize and self.serialize: self._serialize(node_name=self._node_name) - - def _convert_field_name(self, field): - if field == "weight_field": return "weight_field_%s" % self._weight - if field in self._key_fields: return field - return "%s_%s" % (field, self._weight) - - def _initialize_source(self, source = None): - if source is None: - check, source = self._partition_hierarchy_2d(self.axis) - self._check_region = check - #self._okay_to_serialize = (not check) - else: - self._distributed = False - self._okay_to_serialize = False - self._check_region = True - self.source = source - if self._field_cuts is not None: - # Override if field cuts are around; we don't want to serialize! - self._check_region = True - self._okay_to_serialize = False - if self._node_name is not None: - self._node_name = "%s/%s" % (self._top_node,self._node_name) - self._okay_to_serialize = True - - #@time_execution - def __calculate_overlap(self, level): - s = self.source - mylog.info("Generating overlap masks for level %s", level) - i = 0 - pbar = get_pbar("Reading and masking grids ", len(s._grids)) - mylog.debug("Examining level %s", level) - grids = s.select_grid_indices(level) - RE = s.grid_right_edge[grids] - LE = s.grid_left_edge[grids] - for grid in s._grids[grids]: - pbar.update(i) - self.__overlap_masks[grid.id] = \ - grid._generate_overlap_masks(self.axis, LE, RE) - i += 1 - pbar.finish() - mylog.info("Finished calculating overlap.") - - def __get_dls(self, grid, fields): - # Place holder for a time when maybe we will not be doing just - # a single dx for every field. - dls = [] - convs = [] - for field in fields + [self._weight]: - if field is None: continue - dls.append(just_one(grid['d%s' % axis_names[self.axis]])) - convs.append(self.pf.units[self.pf.field_info[field].projection_conversion]) - return na.array(dls), na.array(convs) - - def __project_level(self, level, fields): - grids_to_project = self.source.select_grids(level) - dls, convs = self.__get_dls(grids_to_project[0], fields) - zero_out = (level != self._max_level) - pbar = get_pbar('Projecting level % 2i / % 2i ' \ - % (level, self._max_level), len(grids_to_project)) - for pi, grid in enumerate(grids_to_project): - g_coords, g_fields = self._project_grid(grid, fields, zero_out) - self.__retval_coords[grid.id] = g_coords - self.__retval_fields[grid.id] = g_fields - for fi in range(len(fields)): g_fields[fi] *= dls[fi] - if self._weight is not None: g_coords[3] *= dls[-1] - pbar.update(pi) - grid.clear_data() - pbar.finish() - self.__combine_grids_on_level(level) # In-place - if level > 0 and level <= self._max_level: - self.__refine_to_level(level) # In-place - coord_data = [] - field_data = [] - for grid in grids_to_project: - coarse = self.__retval_coords[grid.id][2]==0 # Where childmask = 0 - fine = ~coarse - coord_data.append([pi[fine] for pi in self.__retval_coords[grid.id]]) - field_data.append([pi[fine] for pi in self.__retval_fields[grid.id]]) - self.__retval_coords[grid.id] = [pi[coarse] for pi in self.__retval_coords[grid.id]] - self.__retval_fields[grid.id] = [pi[coarse] for pi in self.__retval_fields[grid.id]] - coord_data = na.concatenate(coord_data, axis=1) - field_data = na.concatenate(field_data, axis=1) - if self._weight is not None: - field_data = field_data / coord_data[3,:].reshape((1,coord_data.shape[1])) - else: - field_data *= convs[...,na.newaxis] - mylog.info("Level %s done: %s final", \ - level, coord_data.shape[1]) - dx = grids_to_project[0].dds[self.axis] # this is our dl - return coord_data, dx, field_data - - def __combine_grids_on_level(self, level): - grids = self.source.select_grids(level) - grids_i = self.source.select_grid_indices(level) - pbar = get_pbar('Combining level % 2i / % 2i ' \ - % (level, self._max_level), len(grids)) - # We have an N^2 check, so we try to be as quick as possible - # and to skip as many as possible - for pi, grid1 in enumerate(grids): - pbar.update(pi) - if self.__retval_coords[grid1.id][0].shape[0] == 0: continue - for grid2 in self.source._grids[grids_i][self.__overlap_masks[grid1.id]]: - if self.__retval_coords[grid2.id][0].shape[0] == 0 \ - or grid1.id == grid2.id: - continue - args = [] # First is source, then destination - args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]] - args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]] - args.append(1) # Refinement factor - args.append(na.ones(args[0].shape, dtype='int64')) - kk = PointCombine.CombineGrids(*args) - goodI = args[-1].astype('bool') - self.__retval_coords[grid2.id] = \ - [coords[goodI] for coords in self.__retval_coords[grid2.id]] - self.__retval_fields[grid2.id] = \ - [fields[goodI] for fields in self.__retval_fields[grid2.id]] - pbar.finish() - - def __refine_to_level(self, level): - grids = self.source.select_grids(level) - grids_up = self.source.select_grid_indices(level - 1) - pbar = get_pbar('Refining to level % 2i / % 2i ' \ - % (level, self._max_level), len(grids)) - for pi, grid1 in enumerate(grids): - pbar.update(pi) - for parent in ensure_list(grid1.Parent): - if parent.id not in self.__overlap_masks: continue - for grid2 in self.source._grids[grids_up][self.__overlap_masks[parent.id]]: - if self.__retval_coords[grid2.id][0].shape[0] == 0: continue - args = [] - args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]] - args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]] - # Refinement factor, which is same in all directions. Note - # that this complicated rounding is because sometimes - # epsilon differences in dds between the grids causes this - # to round to up or down from the expected value. - args.append(int(na.rint(grid2.dds / grid1.dds)[0])) - args.append(na.ones(args[0].shape, dtype='int64')) - kk = PointCombine.CombineGrids(*args) - goodI = args[-1].astype('bool') - self.__retval_coords[grid2.id] = \ - [coords[goodI] for coords in self.__retval_coords[grid2.id]] - self.__retval_fields[grid2.id] = \ - [fields[goodI] for fields in self.__retval_fields[grid2.id]] - for grid1 in self.source.select_grids(level-1): - if not self._check_region and self.__retval_coords[grid1.id][0].size != 0: - mylog.error("Something messed up, and %s still has %s points of data", - grid1, self.__retval_coords[grid1.id][0].size) - mylog.error("You might try setting the ReconstructHierarchy option in [lagos]") - raise ValueError(grid1, self.__retval_coords[grid1.id]) - pbar.finish() - - #@time_execution - def get_data(self, fields = None): - if fields is None: fields = ensure_list(self.fields)[:] - else: fields = ensure_list(fields) - self._obtain_fields(fields, self._node_name) - fields = [f for f in fields if f not in self.data] - if len(fields) == 0: return - coord_data = [] - field_data = [] - dxs = [] - # We do this here, but I am not convinced it should be done here - # It is probably faster, as it consolidates IO, but if we did it in - # _project_level, then it would be more memory conservative - if self.preload_style == 'all': - print "Preloading %s grids and getting %s" % ( - len(self.source._grids), self._get_dependencies(fields)) - self._preload(self.source._grids, - self._get_dependencies(fields), self.hierarchy.io) - for level in range(0, self._max_level+1): - if self.preload_style == 'level': - self._preload(self.source.select_grids(level), - self._get_dependencies(fields), self.hierarchy.io) - self.__calculate_overlap(level) - my_coords, my_dx, my_fields = self.__project_level(level, fields) - coord_data.append(my_coords) - field_data.append(my_fields) - dxs.append(my_dx * na.ones(my_coords.shape[1], dtype='float64')) - if self._check_region and False: - check=self.__cleanup_level(level - 1) - if len(check) > 0: all_data.append(check) - # Now, we should clean up after ourselves... - for grid in self.source.select_grids(level - 1): - del self.__retval_coords[grid.id] - del self.__retval_fields[grid.id] - del self.__overlap_masks[grid.id] - mylog.debug("End of projecting level level %s, memory usage %0.3e", - level, get_memory_usage()/1024.) - coord_data = na.concatenate(coord_data, axis=1) - field_data = na.concatenate(field_data, axis=1) - dxs = na.concatenate(dxs, axis=1) - # We now convert to half-widths and center-points - data = {} - data['pdx'] = dxs - ox = self.pf["DomainLeftEdge"][x_dict[self.axis]] - oy = self.pf["DomainLeftEdge"][y_dict[self.axis]] - data['px'] = (coord_data[0,:]+0.5) * data['pdx'] + ox - data['py'] = (coord_data[1,:]+0.5) * data['pdx'] + oy - data['weight_field'] = coord_data[3,:].copy() - del coord_data - data['pdx'] *= 0.5 - data['pdy'] = data['pdx'] # generalization is out the window! - data['fields'] = field_data - # Now we run the finalizer, which is ignored if we don't need it - data = self._mpi_catdict(data) - field_data = na.vsplit(data.pop('fields'), len(fields)) - for fi, field in enumerate(fields): - self[field] = field_data[fi].ravel() - if self.serialize: self._store_fields(field, self._node_name) - for i in data.keys(): self[i] = data.pop(i) - mylog.info("Projection completed") - - def add_fields(self, fields, weight = "CellMassMsun"): - pass - - def _project_grid(self, grid, fields, zero_out): - # We split this next bit into two sections to try to limit the IO load - # on the system. This way, we perserve grid state (@restore_grid_state - # in _get_data_from_grid *and* we attempt not to load weight data - # independently of the standard field data. - if self._weight is None: - weight_data = na.ones(grid.ActiveDimensions, dtype='float64') - if zero_out: weight_data[grid.child_indices] = 0 - masked_data = [fd.astype('float64') * weight_data - for fd in self._get_data_from_grid(grid, fields)] - else: - fields_to_get = list(set(fields + [self._weight])) - field_data = dict(zip( - fields_to_get, self._get_data_from_grid(grid, fields_to_get))) - weight_data = field_data[self._weight].copy().astype('float64') - if zero_out: weight_data[grid.child_indices] = 0 - masked_data = [field_data[field].copy().astype('float64') * weight_data - for field in fields] - del field_data - # if we zero it out here, then we only have to zero out the weight! - full_proj = [self.func(field, axis=self.axis) for field in masked_data] - weight_proj = self.func(weight_data, axis=self.axis) - if (self._check_region and not self.source._is_fully_enclosed(grid)) or self._field_cuts is not None: - used_data = self._get_points_in_region(grid).astype('bool') - used_points = na.where(na.logical_or.reduce(used_data, self.axis)) - else: - used_data = na.array([1.0], dtype='bool') - used_points = slice(None) - if zero_out: - subgrid_mask = na.logical_and.reduce( - na.logical_or(grid.child_mask, - ~used_data), - self.axis).astype('int64') - else: - subgrid_mask = na.ones(full_proj[0].shape, dtype='int64') - xind, yind = [arr[used_points].ravel() for arr in na.indices(full_proj[0].shape)] - start_index = grid.get_global_startindex() - xpoints = (xind + (start_index[x_dict[self.axis]])).astype('int64') - ypoints = (yind + (start_index[y_dict[self.axis]])).astype('int64') - return ([xpoints, ypoints, - subgrid_mask[used_points].ravel(), - weight_proj[used_points].ravel()], - [data[used_points].ravel() for data in full_proj]) - - def _get_points_in_region(self, grid): - pointI = self.source._get_point_indices(grid, use_child_mask=False) - point_mask = na.zeros(grid.ActiveDimensions) - point_mask[pointI] = 1.0 - if self._field_cuts is not None: - for cut in self._field_cuts: - point_mask *= eval(cut) - return point_mask - - @restore_grid_state - def _get_data_from_grid(self, grid, fields): - fields = ensure_list(fields) - if self._check_region: - bad_points = self._get_points_in_region(grid) - else: - bad_points = 1.0 - return [grid[field] * bad_points for field in fields] - - def _gen_node_name(self): - return "%s/%s" % \ - (self._top_node, self.axis) - -class AMRFixedResProjectionBase(AMR2DData): - _top_node = "/Projections" - _type_name = "fixed_res_proj" - _con_args = ('axis', 'field', 'weight_field') - def __init__(self, axis, level, left_edge, dims, - fields = None, pf=None, **kwargs): - """ - A projection that provides fixed resolution output, - operating in a grid-by-grid fashion. - """ - AMR2DData.__init__(self, axis, fields, pf, **kwargs) - self.left_edge = na.array(left_edge) - self.level = level - self.dds = self.pf.h.select_grids(self.level)[0].dds.copy() - self.dims = na.array([dims]*2) - self.ActiveDimensions = na.array([dims]*3, dtype='int32') - self.right_edge = self.left_edge + self.ActiveDimensions*self.dds - self.global_startindex = na.rint((self.left_edge - self.pf["DomainLeftEdge"]) - /self.dds).astype('int64') - self._dls = {} - self.domain_width = na.rint((self.pf["DomainRightEdge"] - - self.pf["DomainLeftEdge"])/self.dds).astype('int64') - - def _get_list_of_grids(self): - if self._grids is not None: return - if na.any(self.left_edge < self.pf["DomainLeftEdge"]) or \ - na.any(self.right_edge > self.pf["DomainRightEdge"]): - grids,ind = self.pf.hierarchy.get_periodic_box_grids( - self.left_edge, self.right_edge) - ind = slice(None) - else: - grids,ind = self.pf.hierarchy.get_box_grids( - self.left_edge, self.right_edge) - level_ind = (self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) - sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) - self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)][::-1] - - def _generate_coords(self): - xax = x_dict[self.axis] - yax = y_dict[self.axis] - ci = self.left_edge + self.dds*0.5 - cf = self.left_edge + self.dds*(self.ActiveDimensions-0.5) - cx = na.mgrid[ci[xax]:cf[xax]:self.ActiveDimensions[xax]*1j] - cy = na.mgrid[ci[yax]:cf[yax]:self.ActiveDimensions[yax]*1j] - blank = na.ones( (self.ActiveDimensions[xax], - self.ActiveDimensions[yax]), dtype='float64') - self['px'] = cx[None,:] * blank - self['py'] = cx[:,None] * blank - self['pdx'] = self.dds[xax] - self['pdy'] = self.dds[yax] - - #@time_execution - def get_data(self, fields = None): - """ - Iterates over the list of fields and generates/reads them all. - """ - self._get_list_of_grids() - if not self.has_key('pdx'): - self._generate_coords() - if fields == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(fields) - temp_data = {} - for field in fields_to_get: - self[field] = na.zeros(self.dims, dtype='float64') - dls = self.__setup_dls(fields_to_get) - for i,grid in enumerate(self._get_grids()): - mylog.debug("Getting fields from %s", i) - self._get_data_from_grid(grid, fields_to_get, dls) - for field in fields_to_get: - self[field] = self._mpi_Allsum_double(self[field]) - conv = self.pf.units[self.pf.field_info[field].projection_conversion] - self[field] *= conv - - def __setup_dls(self, fields): - dls = {} - for level in range(self.level+1): - dls[level] = [] - grid = self.select_grids(level)[0] - for field in fields: - if field is None: continue - dls[level].append(float(just_one(grid['d%s' % axis_names[self.axis]]))) - return dls - - def _get_data_from_grid(self, grid, fields, dls): - g_fields = [grid[field] for field in fields] - c_fields = [self[field] for field in fields] - ref_ratio = self.pf["RefineBy"]**(self.level - grid.Level) - PointCombine.FillBuffer(ref_ratio, - grid.get_global_startindex(), self.global_startindex, - c_fields, g_fields, - self.ActiveDimensions, grid.ActiveDimensions, - grid.child_mask, self.domain_width, dls[grid.Level], - self.axis) - -class AMR3DData(AMRData, GridPropertiesMixin): - _key_fields = ['x','y','z','dx','dy','dz'] - """ - Class describing a cluster of data points, not necessarily sharing any - particular attribute. - """ - _spatial = False - _num_ghost_zones = 0 - def __init__(self, center, fields, pf = None, **kwargs): - """ - Returns an instance of AMR3DData, or prepares one. Usually only - used as a base class. Note that *center* is supplied, but only used - for fields and quantities that require it. - """ - AMRData.__init__(self, pf, fields, **kwargs) - self._set_center(center) - self.set_field_parameter("center",center) - self.coords = None - self._grids = None - - def _generate_coords(self): - mylog.info("Generating coords for %s grids", len(self._grids)) - points = [] - for i,grid in enumerate(self._grids): - #grid._generate_coords() - if ( (i%100) == 0): - mylog.info("Working on % 7i / % 7i", i, len(self._grids)) - grid.set_field_parameter("center", self.center) - points.append((na.ones( - grid.ActiveDimensions,dtype='float64')*grid['dx'])\ - [self._get_point_indices(grid)]) - t = na.concatenate([t,points]) - del points - self['dx'] = t - #self['dy'] = t - #self['dz'] = t - mylog.info("Done with coordinates") - - @restore_grid_state - def _generate_grid_coords(self, grid, field=None): - pointI = self._get_point_indices(grid) - dx = na.ones(pointI[0].shape[0], 'float64') * grid.dds[0] - tr = na.array([grid['x'][pointI].ravel(), \ - grid['y'][pointI].ravel(), \ - grid['z'][pointI].ravel(), \ - grid["RadiusCode"][pointI].ravel(), - dx, grid["GridIndices"][pointI].ravel()], 'float64').swapaxes(0,1) - return tr - - def get_data(self, fields=None, in_grids=False, force_particle_read = False): - if self._grids == None: - self._get_list_of_grids() - points = [] - if not fields: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(fields) - mylog.debug("Going to obtain %s", fields_to_get) - for field in fields_to_get: - if self.data.has_key(field): - continue - # There are a lot of 'ands' here, but I think they are all - # necessary. - if force_particle_read == False and \ - self.pf.field_info.has_key(field) and \ - self.pf.field_info[field].particle_type and \ - self.pf.h.io._particle_reader: - self[field] = self.particles[field] - continue - mylog.info("Getting field %s from %s", field, len(self._grids)) - if field not in self.hierarchy.field_list and not in_grids: - if self._generate_field(field): - continue # True means we already assigned it - self[field] = na.concatenate( - [self._get_data_from_grid(grid, field) - for grid in self._grids]) - for field in fields_to_get: - if not self.data.has_key(field): - continue - self[field] = self[field] - - @restore_grid_state - def _get_data_from_grid(self, grid, field): - if field in self.pf.field_info and self.pf.field_info[field].particle_type: - # int64 -> float64 with the first real set of data - if grid.NumberOfParticles == 0: return na.array([], dtype='int64') - pointI = self._get_particle_indices(grid) - if self.pf.field_info[field].vector_field: - f = grid[field] - return na.array([f[i,:][pointI] for i in range(3)]) - if self._is_fully_enclosed(grid): return grid[field].ravel() - return grid[field][pointI].ravel() - if field in self.pf.field_info and self.pf.field_info[field].vector_field: - pointI = self._get_point_indices(grid) - f = grid[field] - return na.array([f[i,:][pointI] for i in range(3)]) - else: - pointI = self._get_point_indices(grid) - if grid[field].size == 1: # dx, dy, dz, cellvolume - t = grid[field] * na.ones(grid.ActiveDimensions, dtype='float64') - return t[pointI].ravel() - return grid[field][pointI].ravel() - - def _flush_data_to_grids(self, field, default_val, dtype='float32'): - """ - A dangerous, thusly underscored, thing to do to a data object, - we can flush back any changes in a given field that have been made - with a default value for the rest of the grid. - """ - i = 0 - for grid in self._grids: - pointI = self._get_point_indices(grid) - np = pointI[0].ravel().size - if grid.has_key(field): - new_field = grid[field] - else: - new_field = na.ones(grid.ActiveDimensions, dtype=dtype) * default_val - new_field[pointI] = self[field][i:i+np] - grid[field] = new_field - i += np - - def _generate_field(self, field): - if self.pf.field_info.has_key(field): - # First we check the validator - try: - self.pf.field_info[field].check_available(self) - except NeedsGridType, ngt_exception: - # We leave this to be implementation-specific - self._generate_field_in_grids(field, ngt_exception.ghost_zones) - return False - else: - self[field] = self.pf.field_info[field](self) - return True - else: # Can't find the field, try as it might - raise exceptions.KeyError(field) - - def _generate_field_in_grids(self, field, num_ghost_zones=0): - for grid in self._grids: - self.__touch_grid_field(grid, field) - - @restore_grid_state - def __touch_grid_field(self, grid, field): - grid[field] - - def _is_fully_enclosed(self, grid): - return na.all(self._get_cut_mask) - - def _get_point_indices(self, grid, use_child_mask=True): - k = na.zeros(grid.ActiveDimensions, dtype='bool') - k = (k | self._get_cut_mask(grid)) - if use_child_mask: k = (k & grid.child_mask) - return na.where(k) - - def _get_cut_particle_mask(self, grid): - if self._is_fully_enclosed(grid): - return True - fake_grid = FakeGridForParticles(grid) - return self._get_cut_mask(fake_grid) - - def _get_particle_indices(self, grid): - k = na.zeros(grid.NumberOfParticles, dtype='bool') - k = (k | self._get_cut_particle_mask(grid)) - return na.where(k) - - def cut_region(self, field_cuts): - """ - Return an InLineExtractedRegion, where the grid cells are cut on the - fly with a set of field_cuts. - """ - return InLineExtractedRegionBase(self, field_cuts) - - def extract_region(self, indices): - """ - Return an ExtractedRegion where the points contained in it are defined - as the points in `this` data object with the given *indices*. - """ - return ExtractedRegionBase(self, indices) - - def __get_quantities(self): - if self.__quantities is None: - self.__quantities = DerivedQuantityCollection(self) - return self.__quantities - __quantities = None - quantities = property(__get_quantities) - - def extract_connected_sets(self, field, num_levels, min_val, max_val, - log_space=True, cumulative=True, cache=False): - """ - This function will create a set of contour objects, defined - by having connected cell structures, which can then be - studied and used to 'paint' their source grids, thus enabling - them to be plotted. - """ - if log_space: - cons = na.logspace(na.log10(min_val),na.log10(max_val), - num_levels+1) - else: - cons = na.linspace(min_val, max_val, num_levels+1) - contours = {} - if cache: cached_fields = defaultdict(lambda: dict()) - else: cached_fields = None - for level in range(num_levels): - contours[level] = {} - if cumulative: - mv = max_val - else: - mv = cons[level+1] - cids = identify_contours(self, field, cons[level], mv, - cached_fields) - for cid, cid_ind in cids.items(): - contours[level][cid] = self.extract_region(cid_ind) - return cons, contours - - def paint_grids(self, field, value, default_value=None): - """ - This function paints every cell in our dataset with a given *value*. - If default_value is given, the other values for the given in every grid - are discarded and replaced with *default_value*. Otherwise, the field is - mandated to 'know how to exist' in the grid. - - Note that this only paints the cells *in the dataset*, so cells in grids - with child cells are left untouched. - """ - for grid in self._grids: - if default_value != None: - grid[field] = na.ones(grid.ActiveDimensions)*default_value - grid[field][self._get_point_indices(grid)] = value - - _particle_handler = None - - @property - def particles(self): - if self._particle_handler is None: - self._particle_handler = \ - particle_handler_registry[self._type_name](self.pf, self) - return self._particle_handler - -class ExtractedRegionBase(AMR3DData): - """ - ExtractedRegions are arbitrarily defined containers of data, useful - for things like selection along a baryon field. - """ - _type_name = "extracted_region" - _con_args = ('_base_region', '_indices') - def __init__(self, base_region, indices, force_refresh=True, **kwargs): - cen = base_region.get_field_parameter("center") - AMR3DData.__init__(self, center=cen, - fields=None, pf=base_region.pf, **kwargs) - self._base_region = base_region # We don't weakly reference because - # It is not cyclic - if isinstance(indices, types.DictType): - self._indices = indices - self._grids = self._base_region.pf.h.grids[self._indices.keys()] - else: - self._grids = None - self._base_indices = indices - if force_refresh: self._refresh_data() - - def _get_cut_particle_mask(self, grid): - # Override to provide a warning - mylog.warning("Returning all particles from an Extracted Region. This could be incorrect!") - return True - - def _get_list_of_grids(self): - # Okay, so what we're going to want to do is get the pointI from - # region._get_point_indices(grid) for grid in base_region._grids, - # and then construct an array of those, which we will select along indices. - if self._grids != None: return - grid_vals, xi, yi, zi = [], [], [], [] - for grid in self._base_region._grids: - xit,yit,zit = self._base_region._get_point_indices(grid) - grid_vals.append(na.ones(xit.shape, dtype='int') * (grid.id-grid._id_offset)) - xi.append(xit) - yi.append(yit) - zi.append(zit) - grid_vals = na.concatenate(grid_vals)[self._base_indices] - grid_order = na.argsort(grid_vals) - # Note: grid_vals is still unordered - grid_ids = na.unique(grid_vals) - xi = na.concatenate(xi)[self._base_indices][grid_order] - yi = na.concatenate(yi)[self._base_indices][grid_order] - zi = na.concatenate(zi)[self._base_indices][grid_order] - bc = na.bincount(grid_vals) - splits = [] - for i,v in enumerate(bc): - if v > 0: splits.append(v) - splits = na.add.accumulate(splits) - xis, yis, zis = [na.array_split(aa, splits) for aa in [xi,yi,zi]] - self._indices = {} - h = self._base_region.pf.h - for grid_id, x, y, z in zip(grid_ids, xis, yis, zis): - # grid_id needs no offset - ll = h.grids[grid_id].ActiveDimensions.prod() \ - - (na.logical_not(h.grids[grid_id].child_mask)).sum() - # This means we're completely enclosed, except for child masks - if x.size == ll: - self._indices[grid_id] = None - else: - # This will slow things down a bit, but conserve memory - self._indices[grid_id] = \ - na.zeros(h.grids[grid_id].ActiveDimensions, dtype='bool') - self._indices[grid_id][(x,y,z)] = True - self._grids = h.grids[self._indices.keys()] - - def _is_fully_enclosed(self, grid): - if self._indices[grid.id-grid._id_offset] is None or \ - (self._indices[grid.id-grid._id_offset][0].size == - grid.ActiveDimensions.prod()): - return True - return False - - def _get_cut_mask(self, grid): - cm = na.zeros(grid.ActiveDimensions, dtype='bool') - cm[self._get_point_indices(grid, False)] = True - return cm - - __empty_array = na.array([], dtype='bool') - def _get_point_indices(self, grid, use_child_mask=True): - # Yeah, if it's not true, we don't care. - tr = self._indices.get(grid.id-grid._id_offset, self.__empty_array) - if tr is None: tr = na.where(grid.child_mask) - else: tr = na.where(tr) - return tr - - def __repr__(self): - # We'll do this the slow way to be clear what's going on - s = "%s (%s): " % (self.__class__.__name__, self.pf) - s += ", ".join(["%s=%s" % (i, getattr(self,i)) - for i in self._con_args if i != "_indices"]) - return s - - def join(self, other): - ng = {} - gs = set(self._indices.keys() + other._indices.keys()) - for g in gs: - grid = self.pf.h.grids[g] - if g in other._indices and g in self._indices: - # We now join the indices - ind = na.zeros(grid.ActiveDimensions, dtype='bool') - ind[self._indices[g]] = True - ind[other._indices[g]] = True - if ind.prod() == grid.ActiveDimensions.prod(): ind = None - elif g in self._indices: - ind = self._indices[g] - elif g in other._indices: - ind = other._indices[g] - # Okay we have indices - if ind is not None: ind = ind.copy() - ng[g] = ind - gl = self.pf.h.grids[list(gs)] - gc = self.pf.h.grid_collection( - self._base_region.get_field_parameter("center"), gl) - return self.pf.h.extracted_region(gc, ng) - -class InLineExtractedRegionBase(AMR3DData): - """ - In-line extracted regions accept a base region and a set of field_cuts to - determine which points in a grid should be included. - """ - def __init__(self, base_region, field_cuts, **kwargs): - cen = base_region.get_field_parameter("center") - AMR3DData.__init__(self, center=cen, - fields=None, pf=base_region.pf, **kwargs) - self._base_region = base_region # We don't weakly reference because - # It is not cyclic - self._field_cuts = ensure_list(field_cuts)[:] - self._refresh_data() - - def _get_list_of_grids(self): - self._grids = self._base_region._grids - - def _is_fully_enclosed(self, grid): - return False - - @cache_mask - def _get_cut_mask(self, grid): - point_mask = na.ones(grid.ActiveDimensions, dtype='bool') - point_mask *= self._base_region._get_cut_mask(grid) - for cut in self._field_cuts: - point_mask *= eval(cut) - return point_mask - -class AMRCylinderBase(AMR3DData): - """ - We can define a cylinder (or disk) to act as a data object. - """ - _type_name = "disk" - _con_args = ('center', '_norm_vec', '_radius', '_height') - def __init__(self, center, normal, radius, height, fields=None, - pf=None, **kwargs): - """ - By providing a *center*, a *normal*, a *radius* and a *height* we - can define a cylinder of any proportion. Only cells whose centers are - within the cylinder will be selected. - """ - AMR3DData.__init__(self, na.array(center), fields, pf, **kwargs) - self._norm_vec = na.array(normal)/na.sqrt(na.dot(normal,normal)) - self.set_field_parameter("height_vector", self._norm_vec) - self._height = height - self._radius = radius - self._d = -1.0 * na.dot(self._norm_vec, self.center) - self._refresh_data() - - def _get_list_of_grids(self): - H = na.sum(self._norm_vec.reshape((1,3,1)) * self.pf.h.grid_corners, - axis=1) + self._d - D = na.sqrt(na.sum((self.pf.h.grid_corners - - self.center.reshape((1,3,1)))**2.0,axis=1)) - R = na.sqrt(D**2.0-H**2.0) - self._grids = self.hierarchy.grids[ - ( (na.any(na.abs(H)0,axis=0) | (na.all(H<0, axis=0)))) ) - ) ) ] - self._grids = self.hierarchy.grids - - def _is_fully_enclosed(self, grid): - corners = grid._corners.reshape((8,3,1)) - H = na.sum(self._norm_vec.reshape((1,3,1)) * corners, - axis=1) + self._d - D = na.sqrt(na.sum((corners - - self.center.reshape((1,3,1)))**2.0,axis=1)) - R = na.sqrt(D**2.0-H**2.0) - return (na.all(na.abs(H) < self._height, axis=0) \ - and na.all(R < self._radius, axis=0)) - - @cache_mask - def _get_cut_mask(self, grid): - if self._is_fully_enclosed(grid): - return True - else: - h = grid['x'] * self._norm_vec[0] \ - + grid['y'] * self._norm_vec[1] \ - + grid['z'] * self._norm_vec[2] \ - + self._d - d = na.sqrt( - (grid['x'] - self.center[0])**2.0 - + (grid['y'] - self.center[1])**2.0 - + (grid['z'] - self.center[2])**2.0 - ) - r = na.sqrt(d**2.0-h**2.0) - cm = ( (na.abs(h) <= self._height) - & (r <= self._radius)) - return cm - - def volume(self, unit="unitary"): - """ - Return the volume of the cylinder in units of *unit*. - """ - return math.pi * (self._radius)**2. * self._height * pf[unit]**3 - -class AMRInclinedBox(AMR3DData): - _type_name="inclined_box" - _con_args = ('origin','box_vectors') - - def __init__(self, origin, box_vectors, fields=None, - pf=None, **kwargs): - """ - A rectangular prism with arbitrary alignment to the computational - domain. *origin* is the origin of the box, while *box_vectors* is an - array of ordering [ax, ijk] that describes the three vectors that - describe the box. No checks are done to ensure that the box satisfies - a right-hand rule, but if it doesn't, behavior is undefined. - """ - self.origin = na.array(origin) - self.box_vectors = na.array(box_vectors, dtype='float64') - self.box_lengths = (self.box_vectors**2.0).sum(axis=1)**0.5 - center = origin + 0.5*self.box_vectors.sum(axis=0) - AMR3DData.__init__(self, center, fields, pf, **kwargs) - self._setup_rotation_parameters() - self._refresh_data() - - def _setup_rotation_parameters(self): - xv = self.box_vectors[0,:] - yv = self.box_vectors[1,:] - zv = self.box_vectors[2,:] - self._x_vec = xv / na.sqrt(na.dot(xv, xv)) - self._y_vec = yv / na.sqrt(na.dot(yv, yv)) - self._z_vec = zv / na.sqrt(na.dot(zv, zv)) - self._rot_mat = na.array([self._x_vec,self._y_vec,self._z_vec]) - self._inv_mat = na.linalg.pinv(self._rot_mat) - - def _get_list_of_grids(self): - if self._grids is not None: return - GLE = self.pf.h.grid_left_edge - GRE = self.pf.h.grid_right_edge - goodI = amr_utils.find_grids_in_inclined_box( - self.box_vectors, self.center, GLE, GRE) - cgrids = self.pf.h.grids[goodI.astype('bool')] - # find_grids_in_inclined_box seems to be broken. - cgrids = self.pf.h.grids[:] - grids = [] - for i,grid in enumerate(cgrids): - v = amr_utils.grid_points_in_volume(self.box_lengths, self.origin, - self._rot_mat, grid.LeftEdge, grid.RightEdge, grid.dds, - grid.child_mask, 1) - if v: grids.append(grid) - self._grids = na.array(grids, dtype='object') - - - def _is_fully_enclosed(self, grid): - # This should be written at some point. - # We'd rotate all eight corners into the space of the box, then check to - # see if all are enclosed. - return False - - def _get_cut_mask(self, grid): - if self._is_fully_enclosed(grid): - return True - pm = na.zeros(grid.ActiveDimensions, dtype='int32') - amr_utils.grid_points_in_volume(self.box_lengths, self.origin, - self._rot_mat, grid.LeftEdge, grid.RightEdge, grid.dds, pm, 0) - return pm - - -class AMRRegionBase(AMR3DData): - """ - AMRRegions are rectangular prisms of data. - """ - _type_name = "region" - _con_args = ('center', 'left_edge', 'right_edge') - _dx_pad = 0.5 - def __init__(self, center, left_edge, right_edge, fields = None, - pf = None, **kwargs): - """ - We create an object with a set of three *left_edge* coordinates, - three *right_edge* coordinates, and a *center* that need not be the - center. - """ - AMR3DData.__init__(self, center, fields, pf, **kwargs) - self.left_edge = left_edge - self.right_edge = right_edge - self._refresh_data() - - def _get_list_of_grids(self): - self._grids, ind = self.pf.hierarchy.get_box_grids(self.left_edge, - self.right_edge) - - def _is_fully_enclosed(self, grid): - return na.all( (grid._corners <= self.right_edge) - & (grid._corners >= self.left_edge)) - - @cache_mask - def _get_cut_mask(self, grid): - if self._is_fully_enclosed(grid): - return True - else: - dxp, dyp, dzp = self._dx_pad * grid.dds - cm = ( (grid['x'] - dxp < self.right_edge[0]) - & (grid['x'] + dxp > self.left_edge[0]) - & (grid['y'] - dyp < self.right_edge[1]) - & (grid['y'] + dyp > self.left_edge[1]) - & (grid['z'] - dzp < self.right_edge[2]) - & (grid['z'] + dzp > self.left_edge[2]) ) - return cm - - def volume(self, unit = "unitary"): - """ - Return the volume of the region in units *unit*. - """ - diff = na.array(self.right_edge) - na.array(self.left_edge) - # Find the full volume - vol = na.prod(diff * self.pf[unit]) - return vol - -class AMRRegionStrictBase(AMRRegionBase): - """ - AMRRegion without any dx padding for cell selection - """ - _type_name = "region_strict" - _dx_pad = 0.0 - -class AMRPeriodicRegionBase(AMR3DData): - """ - AMRRegions are rectangular prisms of data. - """ - _type_name = "periodic_region" - _con_args = ('center', 'left_edge', 'right_edge') - _dx_pad = 0.5 - def __init__(self, center, left_edge, right_edge, fields = None, - pf = None, **kwargs): - """ - We create an object with a set of three *left_edge* coordinates, - three *right_edge* coordinates, and a *center* that need not be the - center. - """ - AMR3DData.__init__(self, center, fields, pf, **kwargs) - self.left_edge = na.array(left_edge) - self.right_edge = na.array(right_edge) - self._refresh_data() - self.offsets = (na.mgrid[-1:1:3j,-1:1:3j,-1:1:3j] * \ - (self.pf["DomainRightEdge"] - - self.pf["DomainLeftEdge"])[:,None,None,None])\ - .transpose().reshape(27,3) # cached and in order - - def _get_list_of_grids(self): - self._grids, ind = self.pf.hierarchy.get_periodic_box_grids(self.left_edge, - self.right_edge) - - def _is_fully_enclosed(self, grid): - for off_x, off_y, off_z in self.offsets: - region_left = [self.left_edge[0]+off_x, - self.left_edge[1]+off_y,self.left_edge[2]+off_z] - region_right = [self.right_edge[0]+off_x, - self.right_edge[1]+off_y,self.right_edge[2]+off_z] - if (na.all((grid._corners <= region_right) & - (grid._corners >= region_left))): - return True - return False - - @cache_mask - def _get_cut_mask(self, grid): - if self._is_fully_enclosed(grid): - return True - else: - cm = na.zeros(grid.ActiveDimensions,dtype='bool') - dxp, dyp, dzp = self._dx_pad * grid.dds - for off_x, off_y, off_z in self.offsets: - cm = cm | ( (grid['x'] - dxp + off_x < self.right_edge[0]) - & (grid['x'] + dxp + off_x > self.left_edge[0]) - & (grid['y'] - dyp + off_y < self.right_edge[1]) - & (grid['y'] + dyp + off_y > self.left_edge[1]) - & (grid['z'] - dzp + off_z < self.right_edge[2]) - & (grid['z'] + dzp + off_z > self.left_edge[2]) ) - return cm - - def volume(self, unit = "unitary"): - """ - Return the volume of the region in units *unit*. - """ - period = self.pf["DomainRightEdge"] - self.pf["DomainLeftEdge"] - diff = na.array(self.right_edge) - na.array(self.left_edge) - # Correct for wrap-arounds. - tofix = (diff < 0) - toadd = period[tofix] - diff += toadd - # Find the full volume - vol = na.prod(diff * self.pf[unit]) - return vol - - -class AMRPeriodicRegionStrictBase(AMRPeriodicRegionBase): - """ - AMRPeriodicRegion without any dx padding for cell selection - """ - _type_name = "periodic_region_strict" - _dx_pad = 0.0 - -class AMRGridCollectionBase(AMR3DData): - """ - An arbitrary selection of grids, within which we accept all points. - """ - _type_name = "grid_collection" - _con_args = ("center", "grid_list") - def __init__(self, center, grid_list, fields = None, - pf = None, **kwargs): - """ - By selecting an arbitrary *grid_list*, we can act on those grids. - Child cells are not returned. - """ - AMR3DData.__init__(self, center, fields, pf, **kwargs) - self._grids = na.array(grid_list) - self.grid_list = self._grids - - def _get_list_of_grids(self): - pass - - def _is_fully_enclosed(self, grid): - return True - - @cache_mask - def _get_cut_mask(self, grid): - return na.ones(grid.ActiveDimensions, dtype='bool') - - def _get_point_indices(self, grid, use_child_mask=True): - k = na.ones(grid.ActiveDimensions, dtype='bool') - if use_child_mask: - k[grid.child_indices] = False - pointI = na.where(k == True) - return pointI - -class AMRSphereBase(AMR3DData): - """ - A sphere of points - """ - _type_name = "sphere" - _con_args = ('center', 'radius') - def __init__(self, center, radius, fields = None, pf = None, **kwargs): - """ - The most famous of all the data objects, we define it via a - *center* and a *radius*. - """ - AMR3DData.__init__(self, center, fields, pf, **kwargs) - if radius < self.hierarchy.get_smallest_dx(): - raise YTSphereTooSmall(pf, radius, self.hierarchy.get_smallest_dx()) - self.set_field_parameter('radius',radius) - self.radius = radius - self.DW = self.pf["DomainRightEdge"] - self.pf["DomainLeftEdge"] - self._refresh_data() - - def _get_list_of_grids(self, field = None): - grids,ind = self.hierarchy.find_sphere_grids(self.center, self.radius) - # Now we sort by level - grids = grids.tolist() - grids.sort(key=lambda x: (x.Level, x.LeftEdge[0], x.LeftEdge[1], x.LeftEdge[2])) - self._grids = na.array(grids, dtype='object') - - def _is_fully_enclosed(self, grid): - r = na.abs(grid._corners - self.center) - r = na.minimum(r, na.abs(self.DW[None,:]-r)) - corner_radius = na.sqrt((r**2.0).sum(axis=1)) - return na.all(corner_radius <= self.radius) - - @restore_grid_state # Pains me not to decorate with cache_mask here - def _get_cut_mask(self, grid, field=None): - # We have the *property* center, which is not necessarily - # the same as the field_parameter - if self._is_fully_enclosed(grid): - return True # We do not want child masking here - if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)) \ - and grid.id in self._cut_masks: - return self._cut_masks[grid.id] - cm = ( (grid["RadiusCode"]<=self.radius) & grid.child_mask ) - if not isinstance(grid, (FakeGridForParticles, GridChildMaskWrapper)): - self._cut_masks[grid.id] = cm - return cm - - def volume(self, unit = "unitary"): - """ - Return the volume of the sphere in units *unit*. - """ - return 4./3. * math.pi * (self.radius * self.pf[unit])**3.0 - -class AMRFloatCoveringGridBase(AMR3DData): - """ - Covering grids represent fixed-resolution data over a given region. - In order to achieve this goal -- for instance in order to obtain ghost - zones -- grids up to and including the indicated level are included. - No interpolation is done (as that would affect the 'power' on small - scales) on the input data. - """ - _spatial = True - _type_name = "float_covering_grid" - _con_args = ('level', 'left_edge', 'right_edge', 'ActiveDimensions') - def __init__(self, level, left_edge, right_edge, dims, fields = None, - pf = None, num_ghost_zones = 0, use_pbar = True, **kwargs): - """ - The data object returned will consider grids up to *level* in - generating fixed resolution data between *left_edge* and *right_edge* - that is *dims* (3-values) on a side. - """ - AMR3DData.__init__(self, center=None, fields=fields, pf=pf, **kwargs) - self.left_edge = na.array(left_edge) - self.right_edge = na.array(right_edge) - self.level = level - self.ActiveDimensions = na.array(dims) - dds = (self.right_edge-self.left_edge) \ - / self.ActiveDimensions - self.dds = dds - self.data["dx"] = dds[0] - self.data["dy"] = dds[1] - self.data["dz"] = dds[2] - self._num_ghost_zones = num_ghost_zones - self._use_pbar = use_pbar - self._refresh_data() - - def _get_list_of_grids(self): - if self._grids is not None: return - if na.any(self.left_edge < self.pf["DomainLeftEdge"]) or \ - na.any(self.right_edge > self.pf["DomainRightEdge"]): - grids,ind = self.pf.hierarchy.get_periodic_box_grids( - self.left_edge, self.right_edge) - ind = slice(None) - else: - grids,ind = self.pf.hierarchy.get_box_grids( - self.left_edge, self.right_edge) - level_ind = na.where(self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) - sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) - self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)][::-1] - - def extract_region(self, indices): - mylog.error("Sorry, dude, do it yourself, it's already in 3-D.") - - def _refresh_data(self): - AMR3DData._refresh_data(self) - self['dx'] = self.dds[0] * na.ones(self.ActiveDimensions, dtype='float64') - self['dy'] = self.dds[1] * na.ones(self.ActiveDimensions, dtype='float64') - self['dz'] = self.dds[2] * na.ones(self.ActiveDimensions, dtype='float64') - - def get_data(self, fields=None): - if self._grids is None: - self._get_list_of_grids() - if fields is None: - fields = self.fields[:] - else: - fields = ensure_list(fields) - obtain_fields = [] - for field in fields: - if self.data.has_key(field): continue - if field not in self.hierarchy.field_list: - try: - #print "Generating", field - self._generate_field(field) - continue - except NeedsOriginalGrid, ngt_exception: - pass - obtain_fields.append(field) - self[field] = na.zeros(self.ActiveDimensions, dtype='float64') -999 - if len(obtain_fields) == 0: return - mylog.debug("Getting fields %s from %s possible grids", - obtain_fields, len(self._grids)) - if self._use_pbar: pbar = \ - get_pbar('Searching grids for values ', len(self._grids)) - for i, grid in enumerate(self._grids): - if self._use_pbar: pbar.update(i) - self._get_data_from_grid(grid, obtain_fields) - if not na.any(self[obtain_fields[0]] == -999): break - if self._use_pbar: pbar.finish() - if na.any(self[obtain_fields[0]] == -999): - # and self.dx < self.hierarchy.grids[0].dx: - print "COVERING PROBLEM", na.where(self[obtain_fields[0]]==-999)[0].size - print na.where(self[obtain_fields[0]]==-999) - raise KeyError - - def _generate_field(self, field): - if self.pf.field_info.has_key(field): - # First we check the validator; this might even raise! - self.pf.field_info[field].check_available(self) - self[field] = self.pf.field_info[field](self) - else: # Can't find the field, try as it might - raise exceptions.KeyError(field) - - def flush_data(self, field=None): - """ - Any modifications made to the data in this object are pushed back - to the originating grids, except the cells where those grids are both - below the current level `and` have child cells. - """ - self._get_list_of_grids() - # We don't generate coordinates here. - if field == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(field) - for grid in self._grids: - self._flush_data_to_grid(grid, fields_to_get) - - @restore_grid_state - def _get_data_from_grid(self, grid, fields): - ll = int(grid.Level == self.level) - g_dx = grid.dds.ravel() - c_dx = self.dds.ravel() - g_fields = [grid[field] for field in ensure_list(fields)] - c_fields = [self[field] for field in ensure_list(fields)] - PointCombine.DataCubeRefine( - grid.LeftEdge, g_dx, g_fields, grid.child_mask, - self.left_edge, self.right_edge, c_dx, c_fields, - ll, self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]) - - def _flush_data_to_grid(self, grid, fields): - ll = int(grid.Level == self.level) - g_dx = grid.dds.ravel() - c_dx = self.dds.ravel() - g_fields = [] - for field in ensure_list(fields): - if not grid.has_key(field): grid[field] = \ - na.zeros(grid.ActiveDimensions, dtype=self[field].dtype) - g_fields.append(grid[field]) - c_fields = [self[field] for field in ensure_list(fields)] - PointCombine.DataCubeReplace( - grid.LeftEdge, g_dx, g_fields, grid.child_mask, - self.left_edge, self.right_edge, c_dx, c_fields, - ll, self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]) - - @property - def LeftEdge(self): - return self.left_edge - - @property - def RightEdge(self): - return self.right_edge - -class AMRSmoothedCoveringGridBase(AMRFloatCoveringGridBase): - _type_name = "smoothed_covering_grid" - def __init__(self, *args, **kwargs): - dlog2 = na.log10(kwargs['dims'])/na.log10(2) - if not na.all(na.floor(dlog2) == na.ceil(dlog2)): - pass # used to warn but I think it is not accurate anymore - #mylog.warning("Must be power of two dimensions") - #raise ValueError - #kwargs['num_ghost_zones'] = 0 - AMRFloatCoveringGridBase.__init__(self, *args, **kwargs) - - def _get_list_of_grids(self): - if na.any(self.left_edge - self.dds < self.pf["DomainLeftEdge"]) or \ - na.any(self.right_edge + self.dds > self.pf["DomainRightEdge"]): - grids,ind = self.pf.hierarchy.get_periodic_box_grids( - self.left_edge - self.dds, - self.right_edge + self.dds) - ind = slice(None) - else: - grids,ind = self.pf.hierarchy.get_box_grids( - self.left_edge - self.dds, - self.right_edge + self.dds) - level_ind = na.where(self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) - sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) - self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)] - - def _get_level_array(self, level, fields): - fields = ensure_list(fields) - # We assume refinement by a factor of two - rf = self.pf["RefineBy"]**(self.level - level) - dims = na.maximum(1,self.ActiveDimensions/rf) + 2 - dx = (self.right_edge-self.left_edge)/(dims-2) - x,y,z = (na.mgrid[0:dims[0],0:dims[1],0:dims[2]].astype('float64')-0.5)\ - * dx[0] - x += self.left_edge[0] - dx[0] - y += self.left_edge[1] - dx[1] - z += self.left_edge[2] - dx[2] - offsets = [self['cd%s' % ax]*0.5 for ax in 'xyz'] - bounds = [self.left_edge[0]-offsets[0], self.right_edge[0]+offsets[0], - self.left_edge[1]-offsets[1], self.right_edge[1]+offsets[1], - self.left_edge[2]-offsets[2], self.right_edge[2]+offsets[2]] - fake_grid = {'x':x,'y':y,'z':z,'dx':dx[0],'dy':dx[1],'dz':dx[2]} - for ax in 'xyz': self['cd%s'%ax] = fake_grid['d%s'%ax] - for field in fields: - # Generate the new grid field - interpolator = TrilinearFieldInterpolator( - self[field], bounds, ['x','y','z'], - truncate = True) - self[field] = interpolator(fake_grid) - return fake_grid - - def get_data(self, field=None): - self._get_list_of_grids() - # We don't generate coordinates here. - if field == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(field) - for field in fields_to_get: - grid_count = 0 - if self.data.has_key(field): - continue - mylog.debug("Getting field %s from %s possible grids", - field, len(self._grids)) - if self._use_pbar: pbar = \ - get_pbar('Searching grids for values ', len(self._grids)) - # How do we find out the root grid base dx? - idims = na.array([3,3,3]) - dx = na.minimum((self.right_edge-self.left_edge)/(idims-2), - self.pf.h.grids[0].dds[0]) - idims = na.floor((self.right_edge-self.left_edge)/dx) + 2 - for ax in 'xyz': self['cd%s'%ax] = dx[0] - self[field] = na.zeros(idims,dtype='float64')-999 - for level in range(self.level+1): - for grid in self.select_grids(level): - if self._use_pbar: pbar.update(grid_count) - self._get_data_from_grid(grid, field) - grid_count += 1 - if level < self.level: self._get_level_array(level+1, field) - self[field] = self[field][1:-1,1:-1,1:-1] - if self._use_pbar: pbar.finish() - - @restore_grid_state - def _get_data_from_grid(self, grid, fields): - fields = ensure_list(fields) - g_dx = grid.dds - c_dx = na.array([self['cdx'],self['cdy'],self['cdz']]) - g_fields = [grid[field] for field in fields] - c_fields = [self[field] for field in fields] - total = PointCombine.DataCubeRefine( - grid.LeftEdge, g_dx, g_fields, grid.child_mask, - self.left_edge-c_dx, self.right_edge+c_dx, - c_dx, c_fields, - 1, self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]) - - def flush_data(self, *args, **kwargs): - raise KeyError("Can't do this") - -class AMRCoveringGridBase(AMR3DData): - _spatial = True - _type_name = "covering_grid" - _con_args = ('level', 'left_edge', 'right_edge', 'ActiveDimensions') - def __init__(self, level, left_edge, dims, fields = None, - pf = None, num_ghost_zones = 0, use_pbar = True, **kwargs): - AMR3DData.__init__(self, center=None, fields=fields, pf=pf, **kwargs) - self.left_edge = na.array(left_edge) - self.level = level - self.dds = self.pf.h.select_grids(self.level)[0].dds.copy() - self.ActiveDimensions = na.array(dims,dtype='int32') - self.right_edge = self.left_edge + self.ActiveDimensions*self.dds - self._num_ghost_zones = num_ghost_zones - self._use_pbar = use_pbar - self.global_startindex = na.rint((self.left_edge-self.pf["DomainLeftEdge"])/self.dds).astype('int64') - self.domain_width = na.rint((self.pf["DomainRightEdge"] - - self.pf["DomainLeftEdge"])/self.dds).astype('int64') - self._refresh_data() - - def _get_list_of_grids(self, buffer = 0.0): - if self._grids is not None: return - if na.any(self.left_edge - buffer < self.pf["DomainLeftEdge"]) or \ - na.any(self.right_edge + buffer > self.pf["DomainRightEdge"]): - grids,ind = self.pf.hierarchy.get_periodic_box_grids( - self.left_edge - buffer, - self.right_edge + buffer) - ind = slice(None) - else: - grids,ind = self.pf.hierarchy.get_box_grids( - self.left_edge - buffer, - self.right_edge + buffer) - level_ind = (self.pf.hierarchy.grid_levels.ravel()[ind] <= self.level) - sort_ind = na.argsort(self.pf.h.grid_levels.ravel()[ind][level_ind]) - self._grids = self.pf.hierarchy.grids[ind][level_ind][(sort_ind,)][::-1] - - def _refresh_data(self): - AMR3DData._refresh_data(self) - self['dx'] = self.dds[0] * na.ones(self.ActiveDimensions, dtype='float64') - self['dy'] = self.dds[1] * na.ones(self.ActiveDimensions, dtype='float64') - self['dz'] = self.dds[2] * na.ones(self.ActiveDimensions, dtype='float64') - - def get_data(self, fields=None): - if self._grids is None: - self._get_list_of_grids() - if fields is None: - fields = self.fields[:] - else: - fields = ensure_list(fields) - obtain_fields = [] - for field in fields: - if self.data.has_key(field): continue - if field not in self.hierarchy.field_list: - try: - #print "Generating", field - self._generate_field(field) - continue - except NeedsOriginalGrid, ngt_exception: - pass - obtain_fields.append(field) - self[field] = na.zeros(self.ActiveDimensions, dtype='float64') -999 - if len(obtain_fields) == 0: return - mylog.debug("Getting fields %s from %s possible grids", - obtain_fields, len(self._grids)) - if self._use_pbar: pbar = \ - get_pbar('Searching grids for values ', len(self._grids)) - count = self.ActiveDimensions.prod() - for i, grid in enumerate(self._grids): - if self._use_pbar: pbar.update(i) - count -= self._get_data_from_grid(grid, obtain_fields) - if count <= 0: break - if self._use_pbar: pbar.finish() - if count > 0 or na.any(self[obtain_fields[0]] == -999): - # and self.dx < self.hierarchy.grids[0].dx: - n_bad = na.where(self[obtain_fields[0]]==-999)[0].size - mylog.error("Covering problem: %s cells are uncovered", n_bad) - raise KeyError(n_bad) - - def _generate_field(self, field): - if self.pf.field_info.has_key(field): - # First we check the validator; this might even raise! - self.pf.field_info[field].check_available(self) - self[field] = self.pf.field_info[field](self) - else: # Can't find the field, try as it might - raise exceptions.KeyError(field) - - def flush_data(self, field=None): - """ - Any modifications made to the data in this object are pushed back - to the originating grids, except the cells where those grids are both - below the current level `and` have child cells. - """ - self._get_list_of_grids() - # We don't generate coordinates here. - if field == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(field) - for grid in self._grids: - self._flush_data_to_grid(grid, fields_to_get) - - @restore_grid_state - def _get_data_from_grid(self, grid, fields): - ll = int(grid.Level == self.level) - ref_ratio = self.pf["RefineBy"]**(self.level - grid.Level) - g_fields = [grid[field] for field in fields] - c_fields = [self[field] for field in fields] - count = PointCombine.FillRegion(ref_ratio, - grid.get_global_startindex(), self.global_startindex, - c_fields, g_fields, - self.ActiveDimensions, grid.ActiveDimensions, - grid.child_mask, self.domain_width, ll, 0) - return count - - def _flush_data_to_grid(self, grid, fields): - ll = int(grid.Level == self.level) - ref_ratio = self.pf["RefineBy"]**(self.level - grid.Level) - g_fields = [] - for field in fields: - if not grid.has_key(field): grid[field] = \ - na.zeros(grid.ActiveDimensions, dtype=self[field].dtype) - g_fields.append(grid[field]) - c_fields = [self[field] for field in fields] - PointCombine.FillRegion(ref_ratio, - grid.get_global_startindex(), self.global_startindex, - c_fields, g_fields, - self.ActiveDimensions, grid.ActiveDimensions, - grid.child_mask, self.domain_width, ll, 1) - - @property - def LeftEdge(self): - return self.left_edge - - @property - def RightEdge(self): - return self.right_edge - -class AMRIntSmoothedCoveringGridBase(AMRCoveringGridBase): - _type_name = "si_covering_grid" - @wraps(AMRCoveringGridBase.__init__) - def __init__(self, *args, **kwargs): - AMRCoveringGridBase.__init__(self, *args, **kwargs) - self._final_start_index = self.global_startindex - - def _get_list_of_grids(self): - buffer = self.pf.h.select_grids(0)[0].dds - AMRCoveringGridBase._get_list_of_grids(self, buffer) - self._grids = self._grids[::-1] - - def get_data(self, field=None): - dx = [self.pf.h.select_grids(l)[0].dds for l in range(self.level+1)] - self._get_list_of_grids() - # We don't generate coordinates here. - if field == None: - fields_to_get = self.fields[:] - else: - fields_to_get = ensure_list(field) - for field in fields_to_get: - grid_count = 0 - if self.data.has_key(field): - continue - mylog.debug("Getting field %s from %s possible grids", - field, len(self._grids)) - if self._use_pbar: pbar = \ - get_pbar('Searching grids for values ', len(self._grids)) - # Note that, thanks to some trickery, we have different dimensions - # on the field than one might think from looking at the dx and the - # L/R edges. - # We jump-start our task here - self._update_level_state(0, field) - for level in range(self.level+1): - for grid in self.select_grids(level): - if self._use_pbar: pbar.update(grid_count) - self._get_data_from_grid(grid, field, level) - grid_count += 1 - if level < self.level: - self._update_level_state(level + 1) - self._refine(1, field) - if self.level > 0: - self[field] = self[field][1:-1,1:-1,1:-1] - if na.any(self[field] == -999): - # and self.dx < self.hierarchy.grids[0].dx: - n_bad = na.where(self[field]==-999)[0].size - mylog.error("Covering problem: %s cells are uncovered", n_bad) - raise KeyError(n_bad) - if self._use_pbar: pbar.finish() - - def _update_level_state(self, level, field = None): - dx = self.pf.h.select_grids(level)[0].dds - for ax, v in zip('xyz', dx): self['cd%s'%ax] = v - LL = self.left_edge - self.pf["DomainLeftEdge"] - self._old_global_startindex = self.global_startindex - self.global_startindex = na.rint(LL / dx).astype('int64') - 1 - self.domain_width = na.rint((self.pf["DomainRightEdge"] - - self.pf["DomainLeftEdge"])/dx).astype('int64') - if level == 0 and self.level > 0: - # We use one grid cell at LEAST, plus one buffer on all sides - idims = na.rint((self.right_edge-self.left_edge)/dx).astype('int64') + 2 - self[field] = na.zeros(idims,dtype='float64')-999 - elif level == 0 and self.level == 0: - DLE = self.pf["DomainLeftEdge"] - self.global_startindex = na.array(na.floor(LL/ dx), dtype='int64') - idims = na.rint((self.right_edge-self.left_edge)/dx).astype('int64') - self[field] = na.zeros(idims,dtype='float64')-999 - - def _refine(self, dlevel, field): - rf = float(self.pf["RefineBy"]**dlevel) - - old_dims = na.array(self[field].shape) - 1 - old_left = (self._old_global_startindex + 0.5) * rf - old_right = rf*old_dims + old_left - old_bounds = [old_left[0], old_right[0], - old_left[1], old_right[1], - old_left[2], old_right[2]] - - dx = na.array([self['cd%s' % ax] for ax in 'xyz'], dtype='float64') - new_dims = na.rint((self.right_edge-self.left_edge)/dx).astype('int64') + 2 - - # x, y, z are the new bounds - x,y,z = (na.mgrid[0:new_dims[0], 0:new_dims[1], 0:new_dims[2]] - ).astype('float64') + 0.5 - x += self.global_startindex[0] - y += self.global_startindex[1] - z += self.global_startindex[2] - fake_grid = {'x':x,'y':y,'z':z} - - interpolator = TrilinearFieldInterpolator( - self[field], old_bounds, ['x','y','z'], - truncate = True) - self[field] = interpolator(fake_grid) - - def _get_data_from_grid(self, grid, fields, level): - fields = ensure_list(fields) - g_fields = [grid[field] for field in fields] - c_fields = [self[field] for field in fields] - dims = na.array(self[field].shape, dtype='int32') - count = PointCombine.FillRegion(1, - grid.get_global_startindex(), self.global_startindex, - c_fields, g_fields, - dims, grid.ActiveDimensions, - grid.child_mask, self.domain_width, 1, 0) - return count - - def flush_data(self, *args, **kwargs): - raise KeyError("Can't do this") - - -def _reconstruct_object(*args, **kwargs): - pfid = args[0] - dtype = args[1] - field_parameters = args[-1] - # will be much nicer when we can do pfid, *a, fp = args - args, new_args = args[2:-1], [] - for arg in args: - if iterable(arg) and len(arg) == 2 \ - and not isinstance(arg, types.DictType) \ - and isinstance(arg[1], AMRData): - new_args.append(arg[1]) - else: new_args.append(arg) - pfs = ParameterFileStore() - pf = pfs.get_pf_hash(pfid) - cls = getattr(pf.h, dtype) - obj = cls(*new_args) - obj.field_parameters.update(field_parameters) - return pf, obj diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/BaseGridType.py --- a/yt/lagos/BaseGridType.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,746 +0,0 @@ -""" -Python-based grid handler, not to be confused with the SWIG-handler - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * -#import yt.enki, gc -from yt.funcs import * - -import pdb - -class AMRGridPatch(object): - _spatial = True - _num_ghost_zones = 0 - _grids = None - _id_offset = 1 - - _type_name = 'grid' - _skip_add = True - _con_args = ('id', 'filename') - - __slots__ = ['data', 'field_parameters', 'id', 'hierarchy', 'pf', - 'ActiveDimensions', 'LeftEdge', 'RightEdge', 'Level', - 'NumberOfParticles', 'Children', 'Parent', - 'start_index', 'filename', '__weakref__', 'dds', - '_child_mask', '_child_indices', '_child_index_mask', - '_parent_id', '_children_ids'] - def __init__(self, id, filename = None, hierarchy = None): - self.data = {} - self.field_parameters = {} - self.id = id - if hierarchy: self.hierarchy = weakref.proxy(hierarchy) - self.pf = self.hierarchy.parameter_file # weakref already - self._child_mask = self._child_indices = self._child_index_mask = None - self.start_index = None - - def get_global_startindex(self): - """ - Return the integer starting index for each dimension at the current - level. - """ - if self.start_index != None: - return self.start_index - if self.Parent == None: - iLE = self.LeftEdge - self.pf["DomainLeftEdge"] - start_index = iLE / self.dds - return na.rint(start_index).astype('int64').ravel() - pdx = self.Parent.dds - start_index = (self.Parent.get_global_startindex()) + \ - na.rint((self.LeftEdge - self.Parent.LeftEdge)/pdx) - self.start_index = (start_index*self.pf["RefineBy"]).astype('int64').ravel() - return self.start_index - - - def get_field_parameter(self, name, default=None): - """ - This is typically only used by derived field functions, but - it returns parameters used to generate fields. - """ - if self.field_parameters.has_key(name): - return self.field_parameters[name] - else: - return default - - def set_field_parameter(self, name, val): - """ - Here we set up dictionaries that get passed up and down and ultimately - to derived fields. - """ - self.field_parameters[name] = val - - def has_field_parameter(self, name): - """ - Checks if a field parameter is set. - """ - return self.field_parameters.has_key(name) - - def convert(self, datatype): - """ - This will attempt to convert a given unit to cgs from code units. - It either returns the multiplicative factor or throws a KeyError. - """ - return self.pf[datatype] - - def __repr__(self): - # We'll do this the slow way to be clear what's going on - s = "%s (%s): " % (self.__class__.__name__, self.pf) - s += ", ".join(["%s=%s" % (i, getattr(self,i)) - for i in self._con_args]) - return s - - def _generate_field(self, field): - if self.pf.field_info.has_key(field): - # First we check the validator - try: - self.pf.field_info[field].check_available(self) - except NeedsGridType, ngt_exception: - # This is only going to be raised if n_gz > 0 - n_gz = ngt_exception.ghost_zones - f_gz = ngt_exception.fields - gz_grid = self.retrieve_ghost_zones(n_gz, f_gz, smoothed=True) - temp_array = self.pf.field_info[field](gz_grid) - sl = [slice(n_gz,-n_gz)] * 3 - self[field] = temp_array[sl] - else: - self[field] = self.pf.field_info[field](self) - else: # Can't find the field, try as it might - raise exceptions.KeyError, field - - def has_key(self, key): - return (key in self.data) - - def __getitem__(self, key): - """ - Returns a single field. Will add if necessary. - """ - if not self.data.has_key(key): - self.get_data(key) - return self.data[key] - - def __setitem__(self, key, val): - """ - Sets a field to be some other value. - """ - self.data[key] = val - - def __delitem__(self, key): - """ - Deletes a field - """ - del self.data[key] - - def keys(self): - return self.data.keys() - - def get_data(self, field): - """ - Returns a field or set of fields for a key or set of keys - """ - if not self.data.has_key(field): - if field in self.hierarchy.field_list: - conv_factor = 1.0 - if self.pf.field_info.has_key(field): - conv_factor = self.pf.field_info[field]._convert_function(self) - if self.pf.field_info[field].particle_type and \ - self.NumberOfParticles == 0: - # because this gets upcast to float - self[field] = na.array([],dtype='int64') - return self.data[field] - try: - temp = self.hierarchy.io.pop(self, field) - self[field] = na.multiply(temp, conv_factor, temp) - except self.hierarchy.io._read_exception, exc: - if field in self.pf.field_info: - if self.pf.field_info[field].not_in_all: - self[field] = na.zeros(self.ActiveDimensions, dtype='float64') - else: - raise - else: raise - else: - self._generate_field(field) - return self.data[field] - - def _setup_dx(self): - # So first we figure out what the index is. We don't assume - # that dx=dy=dz , at least here. We probably do elsewhere. - id = self.id - self._id_offset - if self.Parent is not None: - self.dds = self.Parent.dds / self.pf["RefineBy"] - else: - LE, RE = self.hierarchy.grid_left_edge[id,:], \ - self.hierarchy.grid_right_edge[id,:] - self.dds = na.array((RE-LE)/self.ActiveDimensions) - if self.pf["TopGridRank"] < 2: self.dds[1] = 1.0 - if self.pf["TopGridRank"] < 3: self.dds[2] = 1.0 - self.data['dx'], self.data['dy'], self.data['dz'] = self.dds - - @property - def _corners(self): - return na.array([ # Unroll! - [self.LeftEdge[0], self.LeftEdge[1], self.LeftEdge[2]], - [self.RightEdge[0], self.LeftEdge[1], self.LeftEdge[2]], - [self.RightEdge[0], self.RightEdge[1], self.LeftEdge[2]], - [self.RightEdge[0], self.RightEdge[1], self.RightEdge[2]], - [self.LeftEdge[0], self.RightEdge[1], self.RightEdge[2]], - [self.LeftEdge[0], self.LeftEdge[1], self.RightEdge[2]], - [self.RightEdge[0], self.LeftEdge[1], self.RightEdge[2]], - [self.LeftEdge[0], self.RightEdge[1], self.LeftEdge[2]], - ], dtype='float64') - - def _generate_overlap_masks(self, axis, LE, RE): - """ - Generate a mask that shows which cells overlap with arbitrary arrays - *LE* and *RE*) of edges, typically grids, along *axis*. - Use algorithm described at http://www.gamedev.net/reference/articles/article735.asp - """ - x = x_dict[axis] - y = y_dict[axis] - cond = self.RightEdge[x] >= LE[:,x] - cond = na.logical_and(cond, self.LeftEdge[x] <= RE[:,x]) - cond = na.logical_and(cond, self.RightEdge[y] >= LE[:,y]) - cond = na.logical_and(cond, self.LeftEdge[y] <= RE[:,y]) - return cond - - def __repr__(self): - return "AMRGridPatch_%04i" % (self.id) - - def __int__(self): - return self.id - - def clear_data(self): - """ - Clear out the following things: child_mask, child_indices, - all fields, all field parameters. - """ - self._del_child_mask() - self._del_child_indices() - self.data.clear() - self._setup_dx() - - def check_child_masks(self): - return self._child_mask, self._child_indices - - def _prepare_grid(self): - """ - Copies all the appropriate attributes from the hierarchy - """ - # This is definitely the slowest part of generating the hierarchy - # Now we give it pointers to all of its attributes - # Note that to keep in line with Enzo, we have broken PEP-8 - h = self.hierarchy # cache it - my_ind = self.id - self._id_offset - self.ActiveDimensions = h.grid_dimensions[my_ind] - self.LeftEdge = h.grid_left_edge[my_ind] - self.RightEdge = h.grid_right_edge[my_ind] - h.grid_levels[my_ind, 0] = self.Level - # This might be needed for streaming formats - #self.Time = h.gridTimes[my_ind,0] - self.NumberOfParticles = h.grid_particle_count[my_ind,0] - - def __len__(self): - return na.prod(self.ActiveDimensions) - - def find_max(self, field): - """ - Returns value, index of maximum value of *field* in this gird - """ - coord1d=(self[field]*self.child_mask).argmax() - coord=na.unravel_index(coord1d, self[field].shape) - val = self[field][coord] - return val, coord - - def find_min(self, field): - """ - Returns value, index of minimum value of *field* in this gird - """ - coord1d=(self[field]*self.child_mask).argmin() - coord=na.unravel_index(coord1d, self[field].shape) - val = self[field][coord] - return val, coord - - def get_position(self, index): - """ - Returns center position of an *index* - """ - pos = (index + 0.5) * self.dds + self.LeftEdge - return pos - - def clear_all(self): - """ - Clears all datafields from memory and calls - :meth:`clear_derived_quantities`. - """ - for key in self.keys(): - del self.data[key] - del self.data - if hasattr(self,"retVal"): - del self.retVal - self.data = {} - self.clear_derived_quantities() - - def clear_derived_quantities(self): - """ - Clears coordinates, child_indices, child_mask. - """ - # Access the property raw-values here - del self.child_mask - del self.child_ind - - def _set_child_mask(self, newCM): - if self._child_mask != None: - mylog.warning("Overriding child_mask attribute! This is probably unwise!") - self._child_mask = newCM - - def _set_child_indices(self, newCI): - if self._child_indices != None: - mylog.warning("Overriding child_indices attribute! This is probably unwise!") - self._child_indices = newCI - - def _get_child_mask(self): - if self._child_mask == None: - self.__generate_child_mask() - return self._child_mask - - def _get_child_indices(self): - if self._child_indices == None: - self.__generate_child_mask() - return self._child_indices - - def _del_child_indices(self): - try: - del self._child_indices - except AttributeError: - pass - self._child_indices = None - - def _del_child_mask(self): - try: - del self._child_mask - except AttributeError: - pass - self._child_mask = None - - def _get_child_index_mask(self): - if self._child_index_mask is None: - self.__generate_child_index_mask() - return self._child_index_mask - - def _del_child_index_mask(self): - try: - del self._child_index_mask - except AttributeError: - pass - self._child_index_mask = None - - #@time_execution - def __fill_child_mask(self, child, mask, tofill): - rf = self.pf["RefineBy"] - gi, cgi = self.get_global_startindex(), child.get_global_startindex() - startIndex = na.maximum(0, cgi/rf - gi) - endIndex = na.minimum( (cgi+child.ActiveDimensions)/rf - gi, - self.ActiveDimensions) - endIndex += (startIndex == endIndex) - mask[startIndex[0]:endIndex[0], - startIndex[1]:endIndex[1], - startIndex[2]:endIndex[2]] = tofill - - def __generate_child_mask(self): - """ - Generates self.child_mask, which is zero where child grids exist (and - thus, where higher resolution data is available.) - """ - self._child_mask = na.ones(self.ActiveDimensions, 'int32') - for child in self.Children: - self.__fill_child_mask(child, self._child_mask, 0) - self._child_indices = (self._child_mask==0) # bool, possibly redundant - - def __generate_child_index_mask(self): - """ - Generates self.child_index_mask, which is -1 where there is no child, - and otherwise has the ID of the grid that resides there. - """ - self._child_index_mask = na.zeros(self.ActiveDimensions, 'int32') - 1 - for child in self.Children: - self.__fill_child_mask(child, self._child_index_mask, - child.id) - - def _get_coords(self): - if self.__coords == None: self._generate_coords() - return self.__coords - - def _set_coords(self, newC): - if self.__coords != None: - mylog.warning("Overriding coords attribute! This is probably unwise!") - self.__coords = newC - - def _del_coords(self): - del self.__coords - self.__coords = None - - def _generate_coords(self): - """ - Creates self.coords, which is of dimensions (3,ActiveDimensions) - """ - #print "Generating coords" - ind = na.indices(self.ActiveDimensions) - LE = na.reshape(self.LeftEdge,(3,1,1,1)) - self['x'], self['y'], self['z'] = (ind+0.5)*self.dds+LE - - child_mask = property(fget=_get_child_mask, fdel=_del_child_mask) - child_index_mask = property(fget=_get_child_index_mask, fdel=_del_child_index_mask) - child_indices = property(fget=_get_child_indices, fdel = _del_child_indices) - - def retrieve_ghost_zones(self, n_zones, fields, all_levels=False, - smoothed=False): - # We will attempt this by creating a datacube that is exactly bigger - # than the grid by nZones*dx in each direction - nl = self.get_global_startindex() - n_zones - nr = nl + self.ActiveDimensions + 2*n_zones - new_left_edge = nl * self.dds + self.pf["DomainLeftEdge"] - new_right_edge = nr * self.dds + self.pf["DomainLeftEdge"] - # Something different needs to be done for the root grid, though - level = self.Level - if all_levels: - level = self.hierarchy.max_level + 1 - args = (level, new_left_edge, new_right_edge) - kwargs = {'dims': self.ActiveDimensions + 2*n_zones, - 'num_ghost_zones':n_zones, - 'use_pbar':False, 'fields':fields} - if smoothed: - #cube = self.hierarchy.smoothed_covering_grid( - # level, new_left_edge, new_right_edge, **kwargs) - cube = self.hierarchy.si_covering_grid( - level, new_left_edge, **kwargs) - else: - cube = self.hierarchy.covering_grid( - level, new_left_edge, **kwargs) - return cube - - def get_vertex_centered_data(self, field, smoothed=True): - cg = self.retrieve_ghost_zones(1, field, smoothed=smoothed) - # We have two extra zones in every direction - new_field = na.zeros(self.ActiveDimensions + 1, dtype='float64') - na.add(new_field, cg[field][1: ,1: ,1: ], new_field) - na.add(new_field, cg[field][:-1,1: ,1: ], new_field) - na.add(new_field, cg[field][1: ,:-1,1: ], new_field) - na.add(new_field, cg[field][1: ,1: ,:-1], new_field) - na.add(new_field, cg[field][:-1,1: ,:-1], new_field) - na.add(new_field, cg[field][1: ,:-1,:-1], new_field) - na.add(new_field, cg[field][:-1,:-1,1: ], new_field) - na.add(new_field, cg[field][:-1,:-1,:-1], new_field) - na.multiply(new_field, 0.125, new_field) - return new_field - -class EnzoGrid(AMRGridPatch): - """ - Class representing a single Enzo Grid instance. - """ - - __slots__ = [] - def __init__(self, id, hierarchy): - """ - Returns an instance of EnzoGrid with *id*, associated with - *filename* and *hierarchy*. - """ - #All of the field parameters will be passed to us as needed. - AMRGridPatch.__init__(self, id, filename = None, hierarchy = hierarchy) - self._children_ids = [] - self._parent_id = -1 - self.Level = -1 - - def _guess_properties_from_parent(self): - """ - We know that our grid boundary occurs on the cell boundary of our - parent. This can be a very expensive process, but it is necessary - in some hierarchys, where yt is unable to generate a completely - space-filling tiling of grids, possibly due to the finite accuracy in a - standard Enzo hierarchy file. - """ - rf = self.pf["RefineBy"] - my_ind = self.id - self._id_offset - le = self.LeftEdge - self.dds = self.Parent.dds/rf - ParentLeftIndex = na.rint((self.LeftEdge-self.Parent.LeftEdge)/self.Parent.dds) - self.start_index = rf*(ParentLeftIndex + self.Parent.get_global_startindex()).astype('int64') - self.LeftEdge = self.Parent.LeftEdge + self.Parent.dds * ParentLeftIndex - self.RightEdge = self.LeftEdge + self.ActiveDimensions*self.dds - self.hierarchy.grid_left_edge[my_ind,:] = self.LeftEdge - self.hierarchy.grid_right_edge[my_ind,:] = self.RightEdge - self._child_mask = None - self._child_index_mask = None - self._child_indices = None - self._setup_dx() - - def set_filename(self, filename): - """ - Intelligently set the filename. - """ - if self.hierarchy._strip_path: - self.filename = os.path.join(self.hierarchy.directory, - os.path.basename(filename)) - elif filename[0] == os.path.sep: - self.filename = filename - else: - self.filename = os.path.join(self.hierarchy.directory, filename) - return - - def __repr__(self): - return "EnzoGrid_%04i" % (self.id) - - @property - def Parent(self): - if self._parent_id == -1: return None - return self.hierarchy.grids[self._parent_id - self._id_offset] - - @property - def Children(self): - return [self.hierarchy.grids[cid - self._id_offset] - for cid in self._children_ids] - -class EnzoGridInMemory(EnzoGrid): - __slots__ = ['proc_num'] - def set_filename(self, filename): - pass - -class OrionGrid(AMRGridPatch): - _id_offset = 0 - def __init__(self, LeftEdge, RightEdge, index, level, filename, offset, dimensions,start,stop,paranoia=False,**kwargs): - AMRGridPatch.__init__(self, index,**kwargs) - self.filename = filename - self._offset = offset - self._paranoid = paranoia - - # should error check this - self.ActiveDimensions = (dimensions.copy()).astype('int32')#.transpose() - self.start_index = start.copy()#.transpose() - self.stop_index = stop.copy()#.transpose() - self.LeftEdge = LeftEdge.copy() - self.RightEdge = RightEdge.copy() - self.index = index - self.Level = level - - def get_global_startindex(self): - return self.start_index - - def _prepare_grid(self): - """ - Copies all the appropriate attributes from the hierarchy - """ - # This is definitely the slowest part of generating the hierarchy - # Now we give it pointers to all of its attributes - # Note that to keep in line with Enzo, we have broken PEP-8 - h = self.hierarchy # cache it - #self.StartIndices = h.gridStartIndices[self.id] - #self.EndIndices = h.gridEndIndices[self.id] - h.grid_levels[self.id,0] = self.Level - h.grid_left_edge[self.id,:] = self.LeftEdge[:] - h.grid_right_edge[self.id,:] = self.RightEdge[:] - #self.Time = h.gridTimes[self.id,0] - #self.NumberOfParticles = h.gridNumberOfParticles[self.id,0] - self.field_indexes = h.field_indexes - self.Children = h.gridTree[self.id] - pIDs = h.gridReverseTree[self.id] - if len(pIDs) > 0: - self.Parent = [weakref.proxy(h.grids[pID]) for pID in pIDs] - else: - self.Parent = None - - def _setup_dx(self): - # So first we figure out what the index is. We don't assume - # that dx=dy=dz , at least here. We probably do elsewhere. - id = self.id - self._id_offset - if self.Parent is not None: - self.dds = self.Parent[0].dds / self.pf["RefineBy"] - else: - LE, RE = self.hierarchy.grid_left_edge[id,:], \ - self.hierarchy.grid_right_edge[id,:] - self.dds = na.array((RE-LE)/self.ActiveDimensions) - if self.pf["TopGridRank"] < 2: self.dds[1] = 1.0 - if self.pf["TopGridRank"] < 3: self.dds[2] = 1.0 - self.data['dx'], self.data['dy'], self.data['dz'] = self.dds - - def __repr__(self): - return "OrionGrid_%04i" % (self.id) - -class GadgetGrid(AMRGridPatch): - - _id_offset = 0 - - def __init__(self, id, filename, hierarchy, **kwargs): - AMRGridPatch.__init__(self, id, hierarchy = hierarchy) - self.id = id - self.filename = filename - self.Children = [] #grid objects - self.Parent = None - self.Level = 0 - self.LeftEdge = [0,0,0] - self.RightEdge = [0,0,0] - self.IsLeaf = False - self.N = 0 - self.Address = '' - self.NumberOfParticles = self.N - self.ActiveDimensions = na.array([0,0,0]) - self._id_offset = 0 - self.start_index = na.array([0,0,0]) - - for key,val in kwargs.items(): - if key in dir(self): - #if it's one of the predefined values - setattr(self,key,val) - - #def __repr__(self): - # return "GadgetGrid_%04i" % (self.Address) - - def get_global_startindex(self): - return self.start_index - - def _prepare_grid(self): - #all of this info is already included in the snapshots - pass - #h = self.hierarchy - #h.grid_levels[self.Address,0]=self.Level - #h.grid_left_edge[self.Address,:]=self.LeftEdge[:] - #h.grid_right_edge[self.Address,:]=self.RightEdge[:] - - def _setup_dx(self): - # So first we figure out what the index is. We don't assume - # that dx=dy=dz , at least here. We probably do elsewhere. - id = self.id - LE, RE = self.LeftEdge,self.RightEdge - self.dds = na.array((RE-LE)/self.ActiveDimensions) - if self.pf["TopGridRank"] < 2: self.dds[1] = 1.0 - if self.pf["TopGridRank"] < 3: self.dds[2] = 1.0 - self.data['dx'], self.data['dy'], self.data['dz'] = self.dds - - - - -class ChomboGrid(AMRGridPatch): - _id_offset = 0 - __slots__ = ["_level_id", "stop_index"] - def __init__(self, id, hierarchy, level, start, stop): - AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename, - hierarchy = hierarchy) - self.Parent = [] - self.Children = [] - self.Level = level - self.start_index = start.copy()#.transpose() - self.stop_index = stop.copy()#.transpose() - self.ActiveDimensions = stop - start + 1 - - def _setup_dx(self): - # So first we figure out what the index is. We don't assume - # that dx=dy=dz , at least here. We probably do elsewhere. - id = self.id - self._id_offset - if len(self.Parent) > 0: - self.dds = self.Parent[0].dds / self.pf["RefineBy"] - else: - LE, RE = self.hierarchy.grid_left_edge[id,:], \ - self.hierarchy.grid_right_edge[id,:] - self.dds = na.array((RE-LE)/self.ActiveDimensions) - if self.pf["TopGridRank"] < 2: self.dds[1] = 1.0 - if self.pf["TopGridRank"] < 3: self.dds[2] = 1.0 - self.data['dx'], self.data['dy'], self.data['dz'] = self.dds - - -class TigerGrid(AMRGridPatch): - _id_offset = 0 - - def __init__(self, id, hierarchy, left_edge, right_edge, left_dims, right_dims): - AMRGridPatch.__init__(self, id, hierarchy = hierarchy) - self.LeftEdge = left_edge - self.RightEdge = right_edge - self.Level = 0 - self.NumberOfParticles = 0 - self.left_dims = na.array(left_dims, dtype='int32') - self.right_dims = na.array(right_dims, dtype='int32') - self.ActiveDimensions = self.right_dims - self.left_dims - self.Parent = None - self.Children = [] - - @property - def child_mask(self): - return na.ones(self.ActiveDimensions, dtype='int32') - - def __repr__(self): - return "TigerGrid_%04i (%s)" % (self.id, self.ActiveDimensions) - - -class FLASHGrid(AMRGridPatch): - _id_offset = 1 - #__slots__ = ["_level_id", "stop_index"] - def __init__(self, id, hierarchy, level): - AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename, - hierarchy = hierarchy) - self.Parent = None - self.Children = [] - self.Level = level - - def __repr__(self): - return "FLASHGrid_%04i (%s)" % (self.id, self.ActiveDimensions) - -class RAMSESGrid(AMRGridPatch): - _id_offset = 0 - #__slots__ = ["_level_id", "stop_index"] - def __init__(self, id, hierarchy, level, locations, start_index): - AMRGridPatch.__init__(self, id, filename = hierarchy.hierarchy_filename, - hierarchy = hierarchy) - self.Level = level - self.Parent = [] - self.Children = [] - self.locations = locations - self.start_index = start_index.copy() - - def _setup_dx(self): - # So first we figure out what the index is. We don't assume - # that dx=dy=dz , at least here. We probably do elsewhere. - id = self.id - self._id_offset - if len(self.Parent) > 0: - self.dds = self.Parent[0].dds / self.pf["RefineBy"] - else: - LE, RE = self.hierarchy.grid_left_edge[id,:], \ - self.hierarchy.grid_right_edge[id,:] - self.dds = na.array((RE-LE)/self.ActiveDimensions) - if self.pf["TopGridRank"] < 2: self.dds[1] = 1.0 - if self.pf["TopGridRank"] < 3: self.dds[2] = 1.0 - self.data['dx'], self.data['dy'], self.data['dz'] = self.dds - - def get_global_startindex(self): - """ - Return the integer starting index for each dimension at the current - level. - """ - if self.start_index != None: - return self.start_index - if len(self.Parent) == 0: - start_index = self.LeftEdge / self.dds - return na.rint(start_index).astype('int64').ravel() - pdx = self.Parent[0].dds - start_index = (self.Parent[0].get_global_startindex()) + \ - na.rint((self.LeftEdge - self.Parent[0].LeftEdge)/pdx) - self.start_index = (start_index*self.pf["RefineBy"]).astype('int64').ravel() - return self.start_index - - def __repr__(self): - return "RAMSESGrid_%04i (%s)" % (self.id, self.ActiveDimensions) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/ChomboFields.py --- a/yt/lagos/ChomboFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -""" -Chombo-specific fields - -Author: J. S. Oishi -Affiliation: UC Berkeley -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 J. S. Oishi, 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 . -""" - -from UniversalFields import * -class ChomboFieldContainer(CodeFieldInfoContainer): - _shared_state = {} - _field_list = {} -ChomboFieldInfo = ChomboFieldContainer() -add_chombo_field = ChomboFieldInfo.add_field - -add_field = add_chombo_field - -add_field("density", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("density")], - units=r"\rm{g}/\rm{cm}^3") - -ChomboFieldInfo["density"]._projected_units =r"\rm{g}/\rm{cm}^2" - -add_field("X-momentum", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("X-Momentum")], - units=r"",display_name=r"B_x") -ChomboFieldInfo["X-momentum"]._projected_units=r"" - -add_field("Y-momentum", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("Y-Momentum")], - units=r"",display_name=r"B_y") -ChomboFieldInfo["Y-momentum"]._projected_units=r"" - -add_field("Z-momentum", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("Z-Momentum")], - units=r"",display_name=r"B_z") -ChomboFieldInfo["Z-momentum"]._projected_units=r"" - -add_field("X-magnfield", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("X-Magnfield")], - units=r"",display_name=r"B_x") -ChomboFieldInfo["X-magnfield"]._projected_units=r"" - -add_field("Y-magnfield", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("Y-Magnfield")], - units=r"",display_name=r"B_y") -ChomboFieldInfo["Y-magnfield"]._projected_units=r"" - -add_field("Z-magnfield", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("Z-Magnfield")], - units=r"",display_name=r"B_z") -ChomboFieldInfo["Z-magnfield"]._projected_units=r"" - -def _MagneticEnergy(field,data): - return (data["X-magnfield"]**2 + - data["Y-magnfield"]**2 + - data["Z-magnfield"]**2)/2. -add_field("MagneticEnergy", function=_MagneticEnergy, take_log=True, - units=r"",display_name=r"B^2/8\pi") -ChomboFieldInfo["MagneticEnergy"]._projected_units=r"" - -def _xVelocity(field, data): - """generate x-velocity from x-momentum and density - - """ - return data["X-momentum"]/data["density"] -add_field("x-velocity",function=_xVelocity, take_log=False, - units=r'\rm{cm}/\rm{s}') - -def _yVelocity(field,data): - """generate y-velocity from y-momentum and density - - """ - #try: - # return data["xvel"] - #except KeyError: - return data["Y-momentum"]/data["density"] -add_field("y-velocity",function=_yVelocity, take_log=False, - units=r'\rm{cm}/\rm{s}') - -def _zVelocity(field,data): - """generate z-velocity from z-momentum and density - - """ - return data["Z-momentum"]/data["density"] -add_field("z-velocity",function=_zVelocity, take_log=False, - units=r'\rm{cm}/\rm{s}') - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/ClusterFiles.py --- a/yt/lagos/ClusterFiles.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,252 +0,0 @@ -""" -Some functions to include the output from enzo_anyl, and generate it if need -be. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -@todo: Create an AnalyzeCluster file from a given set of parameters, and a -hierarchy file. -@todo: Run enzo_anyl and parse the resultant data. -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * -import types, exceptions - -ACOtranslation = { - 'r' : 'bin central radius (Mpc)', - 'R' : 'bin outer radius (Mpc)', - 'rho' : 'd_gas (Ms/Mpc^3)', - 'v_rms' : 'v_rms_gas_3d (km/s)', - 'T' : 'temp_gas_mass_weighted (K)', - 'v_r' : 'vr_gas (km/s)', - 'v_r_rms' : 'vr_rms_gas (km/s)', - 'T_cool' : 'T_cool (s)', - 'T_dyn' : 'T_dyn (s)', - 'm_enc' : 'm_gas (Ms)', - 'mu' : 'mu (mh) mean mass per particle' - } - -CFfieldInfo = {} -CFfieldInfo["T"] = (None, r"$T (\rm{K})$", False) -CFfieldInfo["m_enc"] = (None, r"$M_{\rm{enc}} (M_\odot)$", True) -CFfieldInfo["v_r"] = (None, r"$v_r (km/s)$", True) -CFfieldInfo["H2I fraction"] = (None, r"$\rho({\rm{H}}_2) / \rho$", True) - -class AnalyzeClusterOutput: - # This is a class for storing the results of enzo_anyl runs - def __init__(self, filename, id=None): - """ - We receive a filename, and then parse it to get the key of columns, and - then parse the columns to get the array of values - """ - self.filename = filename - if isinstance(filename, types.StringType): # For the __add__ method - self.lines = open(self.filename).readlines() - self.parseKey() - self.parseData() - elif isinstance(filename, types.DictType): - self.filename = id - ks = filename.keys() - ks.sort() - numBins = filename[ks[0]].shape[0] - self.data = na.zeros((len(ks), numBins), 'float64') - self.columns = {} - self.rcolumns = {} - i = 0 - for column in ks: - #print column, self.data.shape, self.data[i,:].shape, filename[column].shape - self.data[i,:] = filename[column] - self.columns[i] = column - self.rcolumns[column] = i - i += 1 - - def __getitem__(self, item): - if isinstance(item, types.StringType): - if self.rcolumns.has_key(item): - i = self.rcolumns[item] - elif ACOtranslation.has_key(item): - return self[ACOtranslation[item]] - else: - return self.generateField(item) - #print item, i - else: - i = int(item) - return self.data[i] - - def generateField(self, item): - if CFfieldInfo.has_key(item): - return CFfieldInfo[item][0](self) - raise KeyError - - def parseKey(self): - """ - Scans, grabs the column names - """ - self.columns = {} - self.rcolumns = {} - index = self.lines.index("# COLUMN DESCRIPTION\n") - for line in self.lines[index+1:]: - if line.rstrip() == "#": - break - col, name = line[1:].strip().split(" ",1) - col = int(col) - 1 - self.columns[col] = name.strip().rstrip() - self.rcolumns[name.strip().rstrip()] = col - - def parseData(self): - """ - Parse the data into self.data - - @todo: Convert to use a regular expression and counting the number of - matches - """ - numBins = 0 - for line in self.lines: - if line[0] != "#" and len(line.strip()) > 0: - numBins += 1 - self.data = na.zeros((len(self.columns), numBins), 'float64') - i = 0 - nc = len(self.columns) - for line in self.lines: - if line[0] != "#" and len(line.strip()) > 0: - self.data[:,i] = map(float, line.split()[:nc]) - i += 1 - - def outputHippo(self, filename): - """ - This outputs the columns in a format that HippoDraw can read easily - """ - fs = "\t".join(["%0.15e"] * len(self.columns)) + "\n" - f = open(filename,"w") - # Dicts are unsorted, so we do this. Could probably be better. - fields = [] - keys = self.columns.keys() - keys.sort() - for key in keys: - fields.append(self.columns[key]) - header = "\t".join(fields) + "\n" - f.write(header) - for i in xrange(self.data.shape[1]): - f.write(fs % tuple(self.data[:,i])) - f.close() - - def __add__(self, other): - """ - This will add all non-duplicated columns. - - @note: We kind of have to do this the slow way, to ensure that no - double-columning goes on. I couldn't come up with a better way than - this. Maybe I will, some day. But for now, it works! Hooray! - """ - comb = AnalyzeClusterOutput(None) - comb.columns = self.columns.copy() - comb.rcolumns = self.rcolumns.copy() - cols = other.columns.keys() - offset = len(comb.columns) # 0-indexed - i = offset - for col in cols: - if other.columns[col] not in self.columns.values(): - comb.columns[i] = other.columns[col] - comb.rcolumns[other.columns[col]] = i - i += 1 - comb.data = na.zeros((len(comb.columns), self.data.shape[1]), 'float64') - comb.data[:len(self.columns),:] = self.data - i = offset - for col in cols: - if other.columns[col] not in self.columns.values(): - comb.data[i,:] = other.data[col,:] # data is zero-indexed - i += 1 - #print comb.data[offset:,:].shape, other.data[1:,:].shape - #comb.data[offset:,:] = other.data[1:,:] - return comb - -def cfCS(self): - # Assume gamma = 5./3. - k = 1.380e-16 # ergs / K - cs = na.sqrt((5./3. * k * self["T"] * self["NumberDensity"] \ - / self["RhoCGS"])) \ - / 1.0e5 - return cs -CFfieldInfo["cs"] = (cfCS, r"$c_s (\rm{km / s})$", False) - -def cfMu(self): - # This is in case mu craps out in enzo_anyl - # mu = mass / num particles - # mu = density / number density - return (self["RhoCGS"] / self["NumberDensity"]) / 1.67e-24 -CFfieldInfo["Mu"] = (cfMu, r"$\mu$", False) - -def cfMach(self): - return abs(self["v_r"]/self["cs"]) -CFfieldInfo["Mach"] = (cfMach, r"$\rm{Radial Mach Number}$", False) - -def cfTurbMach(self): - return abs(self["vr_rms_gas (km/s)"]/self["cs"]) -CFfieldInfo["TurbMach"] = (cfTurbMach, r"$\rm{Turbulent Mach Number}$", False) - -def cfRAU(self): - return self["r"] * mpc_conversion["au"] -CFfieldInfo["RAU"] = (cfRAU, r"$R (\rm{AU})$", True) - -def cfRpc(self): - return self["r"] * mpc_conversion["pc"] -CFfieldInfo["Rpc"] = (cfRpc, r"$R (\rm{pc})$", True) - -def cfRhoCGS(self): - return self["rho"] * 6.769e-41 -CFfieldInfo["RhoCGS"] = (cfRhoCGS, r"$\rho (\rm{g} \rm{cm}^{-3})$", True) - -def cfCoolDynComp(self): - return self["T_cool"]/self["T_dyn"] -CFfieldInfo["CoolDynComp"] = (cfCoolDynComp, r"$T_{\rm{cool}} / T_{\rm{dyn}}$", True) - -def cfH2INorm(self): - return self["H2I fraction"]/0.76 -CFfieldInfo["H2I fraction Norm"] = (cfH2INorm, r"$\rm{H}_2 \rm{fraction}$", True) - -def cfNumberDensity(self): - t= (self["RhoCGS"] / mh) * (\ - (self["HI fraction"] + self["HII fraction"] + self["H- fraction"]) / 1.0 \ - + (self["HeI fraction"] + self["HeII fraction"] + self["HeIII fraction"]) / 4.0 \ - + (self["H2I fraction"] + self["H2II fraction"]) / 2.0 \ - + (self["e- fraction"])) #\ - #+ (self["DI fraction"] + self["DII fraction"])/2.0 + self["HDI fraction"]/3.0 ) - #return (self["RhoCGS"]/mh) * self["H2I fraction"] / 2.0 - return t -CFfieldInfo["NumberDensity"] = (cfNumberDensity, r"$n (\rm{cm}^{-3})$", True) - -def cfMassAccretionRate(self): - # Mdot = 4*pi*r^2 * rho * v_r - # Convert v_r into Mpc/s, then use rho in M_sun / Mpc^3, r^2 in Mpc - vr = na.abs(self["v_r"] * 1.02268e-12) # goes to Mpc/year - Mdot = self["d_gas (Ms/Mpc^3)"] * 4 * 3.1415926 * \ - (self["bin central radius (Mpc)"]**2.0) * vr - return Mdot -CFfieldInfo["MassAccretionRate"] = (cfMassAccretionRate, r"$\dot{M} (M_\odot / \rm{year})$", True) - -def cfMassAccretionTime(self): - MTime = (self["m_enc"] / self["MassAccretionRate"]) - return MTime -CFfieldInfo["MassAccretionTime"] = (cfMassAccretionTime, "Years", True) - -def cfVRoverVCirc(self): - return na.abs(self["v_r"])/na.abs(self["vcirc_gas (km/s)"]) -CFfieldInfo["VRoverVCirc"] = (cfVRoverVCirc, None, True) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/ContourFinder.py --- a/yt/lagos/ContourFinder.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,324 +0,0 @@ -""" -This module contains a routine to search for topologically connected sets - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * -from itertools import chain - -class GridConsiderationQueue: - def __init__(self, white_list, priority_func=None): - """ - This class exists to serve the contour finder. It ensures that - we can create a cascading set of queue dependencies, and if - a grid is touched again ahead of time we can bump it to the top - of the queue again. It like has few uses. - """ - self.to_consider = [] - self.considered = set() - self.n = 0 - self.white_list = set(white_list) - self.priority_func = priority_func - - def add(self, grids, force=False): - if not hasattr(grids,'size'): - grids = ensure_list(grids) - i = self.n - to_check = self.white_list.intersection(grids) - if not force: to_check.difference_update(self.considered) - for g in sorted(to_check, key=self.priority_func): - try: - # We only delete from subsequent checks - del self.to_consider[self.to_consider.index(g, i)] - self.to_consider.insert(i,g) - i += 1 - except ValueError: - self.to_consider.append(g) - - def __iter__(self): - return self - - def next(self): - if self.n >= len(self.to_consider): - raise StopIteration - tr = self.to_consider[self.n] - self.considered.add(tr) - self.n += 1 - return tr - - def progress(self): - return self.n, len(self.to_consider) - -# We want an algorithm that deals with growing a given contour to *all* the -# cells in a grid. - -def old_identify_contours(data_source, field, min_val, max_val, cached_fields=None): - """ - Given a *data_source*, we will search for topologically connected sets - in *field* between *min_val* and *max_val*. - """ - if cached_fields is None: cached_fields = defaultdict(lambda: dict()) - maxn_cells = na.sum([g.ActiveDimensions.prod() for g in data_source._grids]) - contour_ind = na.where( (data_source[field] > min_val) - & (data_source[field] < max_val))[0] - np = contour_ind.size - if np == 0: - return {} - cur_max_id = maxn_cells - np - contour_ids = na.arange(maxn_cells, cur_max_id, -1) + 1 # Minimum of 1 - data_source["tempContours"] = na.ones(data_source[field].shape, dtype='int32')*-1 - mylog.info("Contouring over %s cells with %s candidates", contour_ids[0],np) - data_source["tempContours"][contour_ind] = contour_ids[:] - data_source._flush_data_to_grids("tempContours", -1, dtype='int32') - my_queue = GridConsiderationQueue(white_list = data_source._grids, - priority_func = lambda g: -1*g["tempContours"].max()) - my_queue.add(data_source._grids) - for i,grid in enumerate(my_queue): - mylog.info("Examining %s of %s", *my_queue.progress()) - max_before = grid["tempContours"].max() - to_get = ["tempContours"] - if field in cached_fields[grid.id] and \ - not na.any( (cached_fields[grid.id][field] > min_val) - & (cached_fields[grid.id][field] < max_val)): - continue - for f in [field, "GridIndices"]: - if f not in cached_fields[grid.id]: to_get.append(f) - cg = grid.retrieve_ghost_zones(1,to_get) - for f in [field, "GridIndices"]: - if f in cached_fields[grid.id]: - cg.data[f] = cached_fields[grid.id][f] - else: - cached_fields[grid.id][f] = cg[f] - local_ind = na.where( (cg[field] > min_val) - & (cg[field] < max_val) - & (cg["tempContours"] == -1) ) - if local_ind[0].size > 0: - kk = na.arange(cur_max_id, cur_max_id-local_ind[0].size, -1) - cg["tempContours"][local_ind] = kk[:] - cur_max_id -= local_ind[0].size - fd = cg["tempContours"].astype('int64') - fd_original = fd.copy() - if na.all(fd > -1): - fd[:] = fd.max() - else: - xi_u,yi_u,zi_u = na.where(fd > -1) - cor_order = na.argsort(-1*fd[(xi_u,yi_u,zi_u)]) - xi = xi_u[cor_order] - yi = yi_u[cor_order] - zi = zi_u[cor_order] - while PointCombine.FindContours(fd, xi, yi, zi) < 0: pass - cg["tempContours"] = fd.copy().astype('float64') - cg.flush_data("tempContours") - my_queue.add(cg._grids) - force_ind = na.unique(cg["GridIndices"][na.where( - (cg["tempContours"] > fd_original) - & (cg["GridIndices"] != grid.id-grid._id_offset) )]) - if len(force_ind) > 0: - my_queue.add(data_source.hierarchy.grids[force_ind.astype('int32')], force=True) - for ax in 'xyz': - if not iterable(grid['d%s'%ax]): - grid['d%s'%ax] = grid['d%s'%ax]*na.ones(grid.ActiveDimensions) - del data_source.data["tempContours"] # Force a reload from the grids - data_source.get_data("tempContours", in_grids=True) - i = 0 - contour_ind = {} - for contour_id in na.unique(data_source["tempContours"]): - if contour_id == -1: continue - contour_ind[i] = na.where(data_source["tempContours"] == contour_id) - mylog.debug("Contour id %s has %s cells", i, contour_ind[i][0].size) - i += 1 - mylog.info("Identified %s contours between %0.5e and %0.5e", - len(contour_ind.keys()),min_val,max_val) - for grid in chain(data_source._grids, cg._grids): - grid.data.pop("tempContours", None) - del data_source.data["tempContours"] - return contour_ind - -def check_neighbors(data_object, field="Contours"): - """ - This method is a means of error checking in the contour finder. - """ - n_bad = na.zeros(1, dtype='int32') - for cid in na.unique(data_object[field]): - if cid == -1: continue - ids = na.where(data_object[field] == cid) - mx = data_object['x'][ids].copy() - my = data_object['y'][ids].copy() - mz = data_object['z'][ids].copy() - mdx = data_object['dx'][ids].copy() - mdy = data_object['dy'][ids].copy() - mdz = data_object['dz'][ids].copy() - grid_ids_m = data_object['GridIndices'][ids].copy() - grid_levels_m = data_object['GridLevel'][ids].copy() - mp = mx.size - ids = na.where( (data_object[field] != cid) - & (data_object[field] >= 0 )) - nx = data_object['x'][ids].copy() - ny = data_object['y'][ids].copy() - nz = data_object['z'][ids].copy() - ndx = data_object['dx'][ids].copy() - ndy = data_object['dy'][ids].copy() - ndz = data_object['dz'][ids].copy() - grid_ids_n = data_object['GridIndices'][ids].copy() - grid_levels_n = data_object['GridLevel'][ids].copy() - np = nx.size - weave.inline(check_cell_distance, - ['mx','my','mz','mdx','mdy','mdz','mp', - 'nx','ny','nz','ndx','ndy','ndz','np','n_bad', - 'grid_ids_m', 'grid_levels_m', 'grid_ids_n', 'grid_levels_n'], - compiler='gcc', type_converters=converters.blitz, - auto_downcast=0, verbose=2) - return n_bad[0] - -check_cell_distance = \ -r""" -using namespace std; -int i, j, k; -long double cell_dist, rad_m, rad_n; -k=0; -for(i=0;i 1.01 * (rad_n/2.0+rad_m/2.0)) continue; - if(fabsl(mx(i)-nx(j))>(mdx(i)+ndx(j))/2.0) continue; - if(fabsl(my(i)-ny(j))>(mdy(i)+ndy(j))/2.0) continue; - if(fabsl(mz(i)-nz(j))>(mdz(i)+ndz(j))/2.0) continue; - k++; - break; - cout << cell_dist << "\t" << 1.01*(rad_n/2.0+rad_m/2.0) << "\t"; - cout << grid_ids_m(i) << "\t" << grid_ids_n(j) << endl; - } -} -n_bad(0) += k; -""" - -def coalesce_join_tree(jtree1): - joins = defaultdict(set) - nj = jtree1.shape[0] - for i1 in range(nj): - current_new = jtree1[i1, 0] - current_old = jtree1[i1, 1] - for i2 in range(nj): - if jtree1[i2, 1] == current_new: - current_new = max(current_new, jtree1[i2, 0]) - jtree1[i1, 0] = current_new - for i1 in range(nj): - joins[jtree1[i1, 0]].update([jtree1[i1, 1], jtree1[i1, 0]]) - updated = -1 - while updated != 0: - keys = list(reversed(sorted(joins.keys()))) - updated = 0 - for k1 in keys + keys[::-1]: - if k1 not in joins: continue - s1 = joins[k1] - for k2 in keys + keys[::-1]: - if k2 >= k1: continue - if k2 not in joins: continue - s2 = joins[k2] - if k2 in s1: - s1.update(joins.pop(k2)) - updated += 1 - elif not s1.isdisjoint(s2): - s1.update(joins.pop(k2)) - s1.update([k2]) - updated += 1 - return joins - -def identify_contours(data_source, field, min_val, max_val, - cached_fields=None): - cur_max_id = na.sum([g.ActiveDimensions.prod() for g in data_source._grids]) - pbar = get_pbar("First pass", len(data_source._grids)) - grids = sorted(data_source._grids, key=lambda g: -g.Level) - total_contours = 0 - tree = [] - for gi,grid in enumerate(grids): - pbar.update(gi+1) - cm = data_source._get_cut_mask(grid) - if cm is True: cm = na.ones(grid.ActiveDimensions, dtype='bool') - local_ind = na.where( (grid[field] > min_val) - & (grid[field] < max_val) & cm ) - if local_ind[0].size == 0: continue - kk = na.arange(cur_max_id, cur_max_id-local_ind[0].size, -1) - grid["tempContours"] = na.ones(grid.ActiveDimensions, dtype='int64') * -1 - grid["tempContours"][local_ind] = kk[:] - cur_max_id -= local_ind[0].size - xi_u,yi_u,zi_u = na.where(grid["tempContours"] > -1) - cor_order = na.argsort(-1*grid["tempContours"][(xi_u,yi_u,zi_u)]) - fd_orig = grid["tempContours"].copy() - xi = xi_u[cor_order] - yi = yi_u[cor_order] - zi = zi_u[cor_order] - while PointCombine.FindContours(grid["tempContours"], xi, yi, zi) < 0: - pass - total_contours += na.unique(grid["tempContours"][grid["tempContours"] > -1]).size - new_contours = na.unique(grid["tempContours"][grid["tempContours"] > -1]).tolist() - tree += zip(new_contours, new_contours) - pbar.finish() - pbar = get_pbar("Calculating joins ", len(data_source._grids)) - grid_set = set() - for gi,grid in enumerate(grids): - pbar.update(gi) - cg = grid.retrieve_ghost_zones(1, "tempContours", smoothed=False) - grid_set.update(set(cg._grids)) - fd = cg["tempContours"].astype('int64') - tree += amr_utils.construct_boundary_relationships(fd) - pbar.finish() - sort_new = na.array(list(set(tree)), dtype='int64') - mylog.info("Coalescing %s joins", sort_new.shape[0]) - joins = coalesce_join_tree(sort_new) - pbar = get_pbar("Joining ", len(joins)) - # This process could and should be done faster - for i, new in enumerate(sorted(joins.keys())): - pbar.update(i) - old_set = joins[new] - for old in old_set: - if old == new: continue - i1 = (data_source["tempContours"] == old) - data_source["tempContours"][i1] = new - pbar.finish() - data_source._flush_data_to_grids("tempContours", -1, dtype='int64') - del data_source.data["tempContours"] # Force a reload from the grids - data_source.get_data("tempContours", in_grids=True) - contour_ind = {} - i = 0 - for contour_id in na.unique(data_source["tempContours"]): - if contour_id == -1: continue - contour_ind[i] = na.where(data_source["tempContours"] == contour_id) - mylog.debug("Contour id %s has %s cells", i, contour_ind[i][0].size) - i += 1 - mylog.info("Identified %s contours between %0.5e and %0.5e", - len(contour_ind.keys()),min_val,max_val) - for grid in chain(grid_set): - grid.data.pop("tempContours", None) - del data_source.data["tempContours"] - return contour_ind diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/Cosmology.py --- a/yt/lagos/Cosmology.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -""" -Cosmology calculator based on http://www.kempner.net/cosmic.php. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -import numpy as na - -c_kms = 2.99792458e5 # c in km/s -G = 6.67259e-8 # cgs -kmPerMpc = 3.08567758e19 - -class Cosmology(object): - def __init__(self, HubbleConstantNow = 71.0, - OmegaMatterNow = 0.27, - OmegaLambdaNow = 0.73, - OmegaCurvatureNow = 0.0): - self.HubbleConstantNow = HubbleConstantNow - self.OmegaMatterNow = OmegaMatterNow - self.OmegaLambdaNow = OmegaLambdaNow - self.OmegaCurvatureNow = OmegaCurvatureNow - - def HubbleDistance(self): - return (c_kms / self.HubbleConstantNow) - - def ComovingRadialDistance(self,z_i,z_f): - return self.HubbleDistance() * \ - romberg(self.InverseExpansionFactor,z_i,z_f) - - def ComovingTransverseDistance(self,z_i,z_f): - if (self.OmegaCurvatureNow > 0): - return (self.HubbleDistance() / na.sqrt(self.OmegaCurvatureNow) * - na.sinh(na.sqrt(self.OmegaCurvatureNow) * - self.ComovingRadialDistance(z_i,z_f) / - self.HubbleDistance())) - elif (self.OmegaCurvatureNow < 0): - return (self.HubbleDistance() / na.sqrt(na.fabs(self.OmegaCurvatureNow)) * - sin(na.sqrt(na.fabs(self.OmegaCurvatureNow)) * - self.ComovingRadialDistance(z_i,z_f) / self.HubbleDistance())) - else: - return self.ComovingRadialDistance(z_i,z_f) - - def ComovingVolume(self,z_i,z_f): - if (self.OmegaCurvatureNow > 0): - return (2 * na.pi * na.power(self.HubbleDistance(), 3) / self.OmegaCurvatureNow * - (self.ComovingTransverseDistance(z_i,z_f) / self.HubbleDistance() * - na.sqrt(1 + self.OmegaCurvatureNow * - sqr(self.ComovingTransverseDistance(z_i,z_f) / - self.HubbleDistance())) - - ana.sinh(na.fabs(self.OmegaCurvatureNow) * - self.ComovingTransverseDistance(z_i,z_f) / - self.HubbleDistance()) / na.sqrt(self.OmegaCurvatureNow)) / 1e9) - elif (self.OmegaCurvatureNow < 0): - return (2 * na.pi * na.power(self.HubbleDistance(), 3) / - na.fabs(self.OmegaCurvatureNow) * - (self.ComovingTransverseDistance(z_i,z_f) / self.HubbleDistance() * - na.sqrt(1 + self.OmegaCurvatureNow * - sqr(self.ComovingTransverseDistance(z_i,z_f) / - self.HubbleDistance())) - - asin(na.fabs(self.OmegaCurvatureNow) * - self.ComovingTransverseDistance(z_i,z_f) / - self.HubbleDistance()) / - na.sqrt(na.fabs(self.OmegaCurvatureNow))) / 1e9) - else: - return (4 * na.pi * na.power(self.ComovingTransverseDistance(z_i,z_f), 3) / - 3 / 1e9) - - def AngularDiameterDistance(self,z_i,z_f): - return (self.ComovingTransverseDistance(0,z_f) / (1 + z_f) - - self.ComovingTransverseDistance(0,z_i) / (1 + z_i)) - - def LuminosityDistance(self,z_i,z_f): - return (self.ComovingTransverseDistance(0,z_f) * (1 + z_f) - - self.ComovingTransverseDistance(0,z_i) * (1 + z_i)) - - def LookbackTime(self,z_i,z_f): - return (romberg(self.AgeIntegrand,z_i,z_f) / self.HubbleConstantNow * kmPerMpc) - - def UniverseAge(self,z): - return (romberg(self.AgeIntegrand,z,1000) / self.HubbleConstantNow * kmPerMpc) - - def AngularScale_1arcsec_kpc(self,z_i,z_f): - return (self.AngularDiameterDistance(z_i,z_f) / 648. * na.pi) - - def CriticalDensity(self,z): - return (3.0 / 8.0 / na.pi * sqr(self.HubbleConstantNow / kmPerMpc) / G * - (self.OmegaLambdaNow + ((1 + z)**3.0) * self.OmegaMatterNow)) - - def AgeIntegrand(self,z): - return (1 / (z + 1) / self.ExpansionFactor(z)) - - def ExpansionFactor(self,z): - return na.sqrt(self.OmegaMatterNow * ((1 + z)**3.0) + - self.OmegaCurvatureNow * na.sqrt(1 + z) + - self.OmegaLambdaNow) - - def InverseExpansionFactor(self,z): - return 1 / self.ExpansionFactor(z) - - def PathLengthFunction(self,z): - return ((1 + z)**2) * self.InverseExpansionFactor(z) - - def PathLength(self, z_i, z_f): - return romberg(self.PathLengthFunction, z_i, z_f) - -def sqr(x): - return (x**2.0) - -def romberg(f, a, b, eps=1e-8): - """Approximate the definite integral of f from a to b by Romberg's method. - eps is the desired accuracy.""" - R = [[0.5 * (b - a) * (f(a) + f(b))]] # R[0][0] - n = 1 - while True: - h = float(b - a) / 2 ** n - R.append([None] * (n + 1)) # Add an empty row. - # for proper limits - R[n][0] = 0.5*R[n-1][0] + h*sum(f(a+(2*k-1)*h) for k in xrange(1, 2**(n-1)+1)) - for m in xrange(1, n+1): - R[n][m] = R[n][m-1] + (R[n][m-1] - R[n-1][m-1]) / (4 ** m - 1) - if abs(R[n][n-1] - R[n][n]) < eps: - return R[n][n] - n += 1 diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/DataReadingFuncs.py --- a/yt/lagos/DataReadingFuncs.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,566 +0,0 @@ -""" -The data-file handling functions - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" -from yt.lagos import * -import yt.amr_utils as au -import exceptions -import cPickle - -_axis_ids = {0:2,1:1,2:0} - -io_registry = {} - -class BaseIOHandler(object): - - _data_style = None - _particle_reader = False - - class __metaclass__(type): - def __init__(cls, name, b, d): - type.__init__(cls, name, b, d) - if hasattr(cls, "_data_style"): - io_registry[cls._data_style] = cls - - def __init__(self): - self.queue = defaultdict(dict) - - # We need a function for reading a list of sets - # and a function for *popping* from a queue all the appropriate sets - - def preload(self, grids, sets): - pass - - def pop(self, grid, field): - if grid.id in self.queue and field in self.queue[grid.id]: - return self.modify(self.queue[grid.id].pop(field)) - else: - # We only read the one set and do not store it if it isn't pre-loaded - return self._read_data_set(grid, field) - - def peek(self, grid, field): - return self.queue[grid.id].get(field, None) - - def push(self, grid, field, data): - if grid.id in self.queue and field in self.queue[grid.id]: - raise ValueError - self.queue[grid][field] = data - - # Now we define our interface - def _read_data_set(self, grid, field): - pass - - def _read_data_slice(self, grid, field, axis, coord): - pass - - def _read_field_names(self, grid): - pass - - @property - def _read_exception(self): - return None - -class IOHandlerEnzoHDF4(BaseIOHandler): - - _data_style = "enzo_hdf4" - - def modify(self, field): - return field.swapaxes(0,2) - - def _read_field_names(self, grid): - """ - Returns a list of fields associated with the filename - Should *only* be called as EnzoGridInstance.getFields, never as getFields(object) - """ - return SD.SD(grid.filename).datasets().keys() - - def _read_data_set(self, grid, field): - """ - Returns after having obtained or generated a field. Should throw an - exception. Should only be called as EnzoGridInstance.readData() - - @param field: field to read - @type field: string - """ - return SD.SD(grid.filename).select(field).get() - - def _read_data_slice(self, grid, field, axis, coord): - """ - Reads a slice through the HDF4 data - - @param grid: Grid to slice - @type grid: L{EnzoGrid} - @param field: field to get - @type field: string - @param sl: region to get - @type sl: SliceType - """ - sl = [slice(None), slice(None), slice(None)] - sl[axis] = slice(coord, coord + 1) - sl = tuple(reversed(sl)) - return SD.SD(grid.filename).select(field)[sl].swapaxes(0,2) - - @property - def _read_exception(self): - return SD.HDF4Error - -class IOHandlerEnzoHDF4_2D(IOHandlerEnzoHDF4): - - _data_style = "enzo_hdf4_2d" - - def _read_data_set(self, grid, field): - t = SD.SD(grid.filename).select(field).get()[:,:,None] - return t.swapaxes(0,1) - - def _read_data_slice(self, grid, field, axis, coord): - t = SD.SD(grid.filename).select(field).get() - return t.transpose() - - def modify(self, field): - return field - -class IOHandlerEnzoHDF5(BaseIOHandler): - - _data_style = "enzo_hdf5" - _particle_reader = True - - def _read_field_names(self, grid): - """ - Returns a list of fields associated with the filename - Should *only* be called as EnzoGridInstance.getFields, never as getFields(object) - """ - return HDF5LightReader.ReadListOfDatasets(grid.filename, "/") - - def _read_data_set(self, grid, field): - return HDF5LightReader.ReadData(grid.filename, "/%s" % field).swapaxes(0,2) - - def _read_data_slice(self, grid, field, axis, coord): - """ - Reads a slice through the HDF5 data - - @param grid: Grid to slice - @type grid: L{EnzoGrid} - @param field: field to get - @type field: string - @param axis: axis to slice along - @param coord: coord to slice at - """ - axis = {0:2,1:1,2:0}[axis] - t = HDF5LightReader.ReadDataSlice(grid.filename, "/%s" % - (field), axis, coord).transpose() - return t - - def modify(self, field): - return field.swapaxes(0,2) - - @property - def _read_exception(self): - return (exceptions.KeyError, HDF5LightReader.ReadingError) - - def _read_particles(self, fields, rtype, args, grid_list, enclosed, - conv_factors): - filenames = [g.filename for g in grid_list] - ids = [g.id for g in grid_list] - return HDF5LightReader.ReadParticles( - rtype, fields, filenames, ids, conv_factors, args, 0) - -class IOHandlerExtracted(BaseIOHandler): - - _data_style = 'extracted' - - def _read_data_set(self, grid, field): - return (grid.base_grid[field] / grid.base_grid.convert(field)) - - def _read_data_slice(self, grid, field, axis, coord): - sl = [slice(None), slice(None), slice(None)] - sl[axis] = slice(coord, coord + 1) - return grid.base_grid[field][tuple(sl)] / grid.base_grid.convert(field) - -class IOHandlerPackedHDF5(BaseIOHandler): - - _data_style = "enzo_packed_3d" - _particle_reader = True - - def _read_particles(self, fields, rtype, args, grid_list, enclosed, - conv_factors): - filenames = [g.filename for g in grid_list] - ids = [g.id for g in grid_list] - filenames, ids, conv_factors = zip(*sorted(zip(filenames, ids, conv_factors))) - return HDF5LightReader.ReadParticles( - rtype, fields, list(filenames), list(ids), conv_factors, args, 1) - - def modify(self, field): - return field.swapaxes(0,2) - - def preload(self, grids, sets): - # We need to deal with files first - files_keys = defaultdict(lambda: []) - pf_field_list = grids[0].pf.h.field_list - sets = [dset for dset in list(sets) if dset in pf_field_list] - for g in grids: files_keys[g.filename].append(g) - exc = self._read_exception - for file in files_keys: - mylog.debug("Starting read %s (%s)", file, sets) - nodes = [g.id for g in files_keys[file]] - nodes.sort() - # We want to pass on any error we might expect -- the preload - # phase should be non-fatal in all cases, and instead dump back to - # the grids. - data = HDF5LightReader.ReadMultipleGrids(file, nodes, sets) - mylog.debug("Read %s items from %s", len(data), os.path.basename(file)) - for gid in data: self.queue[gid].update(data[gid]) - mylog.debug("Finished read of %s", sets) - - def _read_data_set(self, grid, field): - return HDF5LightReader.ReadData(grid.filename, - "/Grid%08i/%s" % (grid.id, field)).swapaxes(0,2) - - def _read_data_slice(self, grid, field, axis, coord): - axis = _axis_ids[axis] - return HDF5LightReader.ReadDataSlice(grid.filename, "/Grid%08i/%s" % - (grid.id, field), axis, coord).transpose() - - def _read_field_names(self, grid): - return HDF5LightReader.ReadListOfDatasets( - grid.filename, "/Grid%08i" % grid.id) - - @property - def _read_exception(self): - return (exceptions.KeyError, HDF5LightReader.ReadingError) - -class IOHandlerInMemory(BaseIOHandler): - - _data_style = "enzo_inline" - - def __init__(self, ghost_zones=3): - import enzo - self.enzo = enzo - self.grids_in_memory = enzo.grid_data - self.old_grids_in_memory = enzo.old_grid_data - self.my_slice = (slice(ghost_zones,-ghost_zones), - slice(ghost_zones,-ghost_zones), - slice(ghost_zones,-ghost_zones)) - BaseIOHandler.__init__(self) - - def _read_data_set(self, grid, field): - if grid.id not in self.grids_in_memory: raise KeyError - tr = self.grids_in_memory[grid.id][field] - # If it's particles, we copy. - if len(tr.shape) == 1: return tr.copy() - # New in-place unit conversion breaks if we don't copy first - return tr.swapaxes(0,2)[self.my_slice].copy() - # We don't do this, because we currently do not interpolate - coef1 = max((grid.Time - t1)/(grid.Time - t2), 0.0) - coef2 = 1.0 - coef1 - t1 = enzo.yt_parameter_file["InitialTime"] - t2 = enzo.hierarchy_information["GridOldTimes"][grid.id] - return (coef1*self.grids_in_memory[grid.id][field] + \ - coef2*self.old_grids_in_memory[grid.id][field])\ - [self.my_slice] - - def modify(self, field): - return field.swapaxes(0,2) - - def _read_field_names(self, grid): - return self.grids_in_memory[grid.id].keys() - - def _read_data_slice(self, grid, field, axis, coord): - sl = [slice(3,-3), slice(3,-3), slice(3,-3)] - sl[axis] = slice(coord + 3, coord + 4) - sl = tuple(reversed(sl)) - tr = self.grids_in_memory[grid.id][field][sl].swapaxes(0,2) - # In-place unit conversion requires we return a copy - return tr.copy() - - @property - def _read_exception(self): - return KeyError - -class IOHandlerNative(BaseIOHandler): - - _data_style = "orion_native" - - def modify(self, field): - return field.swapaxes(0,2) - - def _read_data_set(self,grid,field): - """ - reads packed multiFABs output by BoxLib in "NATIVE" format. - - """ - filen = os.path.expanduser(grid.filename[field]) - off = grid._offset[field] - inFile = open(filen,'rb') - inFile.seek(off) - header = inFile.readline() - header.strip() - - if grid._paranoid: - mylog.warn("Orion Native reader: Paranoid read mode.") - headerRe = re.compile(orion_FAB_header_pattern) - bytesPerReal,endian,start,stop,centerType,nComponents = headerRe.search(header).groups() - - # we will build up a dtype string, starting with endian - # check endianness (this code is ugly. fix?) - bytesPerReal = int(bytesPerReal) - if bytesPerReal == int(endian[0]): - dtype = '<' - elif bytesPerReal == int(endian[-1]): - dtype = '>' - else: - raise ValueError("FAB header is neither big nor little endian. Perhaps the file is corrupt?") - - dtype += ('f%i'% bytesPerReal) #always a floating point - - # determine size of FAB - start = na.array(map(int,start.split(','))) - stop = na.array(map(int,stop.split(','))) - - gridSize = stop - start + 1 - - error_count = 0 - if (start != grid.start).any(): - print "Paranoia Error: Cell_H and %s do not agree on grid start." %grid.filename - error_count += 1 - if (stop != grid.stop).any(): - print "Paranoia Error: Cell_H and %s do not agree on grid stop." %grid.filename - error_count += 1 - if (gridSize != grid.ActiveDimensions).any(): - print "Paranoia Error: Cell_H and %s do not agree on grid dimensions." %grid.filename - error_count += 1 - if bytesPerReal != grid.hierarchy._bytesPerReal: - print "Paranoia Error: Cell_H and %s do not agree on bytes per real number." %grid.filename - error_count += 1 - if (bytesPerReal == grid.hierarchy._bytesPerReal and dtype != grid.hierarchy._dtype): - print "Paranoia Error: Cell_H and %s do not agree on endianness." %grid.filename - error_count += 1 - - if error_count > 0: - raise RunTimeError("Paranoia unveiled %i differences between Cell_H and %s." % (error_count, grid.filename)) - - else: - start = grid.start_index - stop = grid.stop_index - dtype = grid.hierarchy._dtype - bytesPerReal = grid.hierarchy._bytesPerReal - - nElements = grid.ActiveDimensions.prod() - - # one field has nElements*bytesPerReal bytes and is located - # nElements*bytesPerReal*field_index from the offset location - if yt2orionFieldsDict.has_key(field): - fieldname = yt2orionFieldsDict[field] - else: - fieldname = field - field_index = grid.field_indexes[fieldname] - inFile.seek(int(nElements*bytesPerReal*field_index),1) - field = na.fromfile(inFile,count=nElements,dtype=dtype) - field = field.reshape(grid.ActiveDimensions[::-1]).swapaxes(0,2) - - # we can/should also check against the max and min in the header file - - inFile.close() - return field - - def _read_data_slice(self, grid, field, axis, coord): - """wishful thinking? - """ - sl = [slice(None), slice(None), slice(None)] - sl[axis] = slice(coord, coord + 1) - #sl = tuple(reversed(sl)) - return self._read_data_set(grid,field)[sl] - - -class IOHandlerPacked2D(IOHandlerPackedHDF5): - - _data_style = "enzo_packed_2d" - _particle_reader = False - - def _read_data_set(self, grid, field): - return HDF5LightReader.ReadData(grid.filename, - "/Grid%08i/%s" % (grid.id, field)).transpose()[:,:,None] - - def modify(self, field): - pass - - def _read_data_slice(self, grid, field, axis, coord): - t = HDF5LightReader.ReadData(grid.filename, "/Grid%08i/%s" % - (grid.id, field)).transpose() - return t - - -class IOHandlerPacked1D(IOHandlerPackedHDF5): - - _data_style = "enzo_packed_1d" - _particle_reader = False - - def _read_data_set(self, grid, field): - return HDF5LightReader.ReadData(grid.filename, - "/Grid%08i/%s" % (grid.id, field)).transpose()[:,None,None] - - def modify(self, field): - pass - - def _read_data_slice(self, grid, field, axis, coord): - t = HDF5LightReader.ReadData(grid.filename, "/Grid%08i/%s" % - (grid.id, field)) - return t - -class IOHandlerGadget(BaseIOHandler): - _data_style = 'gadget_hdf5' - def _read_data_set(self, grid, field): - adr = grid.Address - fh = h5py.File(grid.filename,mode='r') - if 'particles' in fh[adr].keys(): - adr2 = adr+'/particles' - return fh[adr2][field] - return None - def _read_field_names(self,grid): - adr = grid.Address - fh = h5py.File(grid.filename,mode='r') - rets = cPickle.loads(fh['/root'].attrs['fieldnames']) - return rets - - def _read_data_slice(self,grid, field, axis, coord): - adr = grid.Address - fh = h5py.File(grid.filename,mode='r') - if 'particles' in fh[adr].keys(): - adr2 = adr+'/particles' - return fh[adr2][field][coord,axis] - return None -# -# Chombo readers -# - -class IOHandlerChomboHDF5(BaseIOHandler): - _data_style = "chombo_hdf5" - _offset_string = 'data:offsets=0' - _data_string = 'data:datatype=0' - - def _field_dict(self,fhandle): - ncomp = int(fhandle['/'].attrs['num_components']) - temp = fhandle['/'].attrs.listitems()[-ncomp:] - val, keys = zip(*temp) - val = [int(re.match('component_(\d+)',v).groups()[0]) for v in val] - return dict(zip(keys,val)) - - def _read_field_names(self,grid): - fhandle = h5py.File(grid.filename,'r') - ncomp = int(fhandle['/'].attrs['num_components']) - - return [c[1] for c in f['/'].attrs.listitems()[-ncomp:]] - - def _read_data_set(self,grid,field): - fhandle = h5py.File(grid.hierarchy.hierarchy_filename,'r') - - field_dict = self._field_dict(fhandle) - lstring = 'level_%i' % grid.Level - lev = fhandle[lstring] - dims = grid.ActiveDimensions - boxsize = dims.prod() - - grid_offset = lev[self._offset_string][grid._level_id] - start = grid_offset+field_dict[field]*boxsize - stop = start + boxsize - data = lev[self._data_string][start:stop] - - return data.reshape(dims, order='F') - - - def _read_data_slice(self, grid, field, axis, coord): - sl = [slice(None), slice(None), slice(None)] - sl[axis] = slice(coord, coord + 1) - return self._read_data_set(grid,field)[sl] - -class IOHandlerTiger(BaseIOHandler): - _data_style = "tiger" - _offset = 36 - - def __init__(self, *args, **kwargs): - BaseIOHandler.__init__(self, *args, **kwargs) - self._memmaps = {} - - def _read_data_set(self, grid, field): - fn = grid.pf.basename + grid.hierarchy.file_mapping[field] - LD = na.array(grid.left_dims, dtype='int64') - SS = na.array(grid.ActiveDimensions, dtype='int64') - RS = na.array(grid.pf.root_size, dtype='int64') - data = au.read_tiger_section(fn, LD, SS, RS).astype("float64") - return data - - def _read_data_slice(self, grid, field, axis, coord): - fn = grid.pf.basename + grid.hierarchy.file_mapping[field] - LD = na.array(grid.left_dims, dtype='int64').copy() - SS = na.array(grid.ActiveDimensions, dtype='int64').copy() - RS = na.array(grid.pf.root_size, dtype='int64').copy() - LD[axis] += coord - SS[axis] = 1 - data = au.read_tiger_section(fn, LD, SS, RS).astype("float64") - return data - -class IOHandlerFLASH(BaseIOHandler): - _data_style = "flash_hdf5" - - def __init__(self, *args, **kwargs): - BaseIOHandler.__init__(self, *args, **kwargs) - - def _read_data_set(self, grid, field): - f = h5py.File(grid.pf.parameter_filename, "r") - tr = f["/%s" % field][grid.id - grid._id_offset,:,:,:].transpose() - return tr.astype("float64") - - def _read_data_slice(self, grid, field, axis, coord): - sl = [slice(None), slice(None), slice(None)] - sl[axis] = slice(coord, coord + 1) - f = h5py.File(grid.pf.parameter_filename, "r") - tr = f["/%s" % field][grid.id - grid._id_offset].transpose()[sl] - return tr.astype("float64") - -class IOHandlerRAMSES(BaseIOHandler): - _data_style = "ramses" - - def __init__(self, ramses_tree, *args, **kwargs): - self.ramses_tree = ramses_tree - BaseIOHandler.__init__(self, *args, **kwargs) - - def _read_data_set(self, grid, field): - tr = na.zeros(grid.ActiveDimensions, dtype='float64') - filled = na.zeros(grid.ActiveDimensions, dtype='int32') - to_fill = grid.ActiveDimensions.prod() - grids = [grid] - l_delta = 0 - while to_fill > 0 and len(grids) > 0: - next_grids = [] - for g in grids: - to_fill -= self.ramses_tree.read_grid(field, - grid.get_global_startindex(), grid.ActiveDimensions, - tr, filled, g.Level, 2**l_delta, g.locations) - next_grids += g.Parent - grids = next_grids - l_delta += 1 - return tr - - def _read_data_slice(self, grid, field, axis, coord): - sl = [slice(None), slice(None), slice(None)] - sl[axis] = slice(coord, coord + 1) - return self._read_data_set(grid, field)[sl] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/DerivedQuantities.py --- a/yt/lagos/DerivedQuantities.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,479 +0,0 @@ -""" -Quantities that can be derived from Enzo data that may also required additional -arguments. (Standard arguments -- such as the center of a distribution of -points -- are excluded here, and left to the EnzoDerivedFields.) - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * -from yt.funcs import get_pbar, wraps -import math - -__CUDA_BLOCK_SIZE = 256 - -quantity_info = {} - -class GridChildMaskWrapper: - def __init__(self, grid, data_source): - self.grid = grid - self.data_source = data_source - def __getattr__(self, attr): - return getattr(self.grid, attr) - def __getitem__(self, item): - return self.data_source._get_data_from_grid(self.grid, item) - -class DerivedQuantity(ParallelAnalysisInterface): - def __init__(self, collection, name, function, - combine_function, units = "", - n_ret = 0, force_unlazy=False): - # We wrap the function with our object - self.__doc__ = function.__doc__ - self.__name__ = name - self.collection = collection - self._data_source = collection.data_source - self.func = function - self.c_func = combine_function - self.n_ret = n_ret - self.force_unlazy = force_unlazy - - def __call__(self, *args, **kwargs): - lazy_reader = kwargs.pop('lazy_reader', True) - preload = kwargs.pop('preload', False) - if preload: - if not lazy_reader: mylog.debug("Turning on lazy_reader because of preload") - lazy_reader = True - e = FieldDetector() - e.NumberOfParticles = 1 - self.func(e, *args, **kwargs) - mylog.debug("Preloading %s", e.requested) - self._preload([g for g in self._get_grid_objs()], e.requested, - self._data_source.pf.h.io) - if lazy_reader and not self.force_unlazy: - return self._call_func_lazy(args, kwargs) - else: - return self._call_func_unlazy(args, kwargs) - - def _call_func_lazy(self, args, kwargs): - self.retvals = [ [] for i in range(self.n_ret)] - for gi,g in enumerate(self._get_grids()): - rv = self.func(GridChildMaskWrapper(g, self._data_source), *args, **kwargs) - for i in range(self.n_ret): self.retvals[i].append(rv[i]) - g.clear_data() - self.retvals = [na.array(self.retvals[i]) for i in range(self.n_ret)] - return self.c_func(self._data_source, *self.retvals) - - def _finalize_parallel(self): - self.retvals = [na.array(self._mpi_catlist(my_list)) for my_list in self.retvals] - - def _call_func_unlazy(self, args, kwargs): - retval = self.func(self._data_source, *args, **kwargs) - return self.c_func(self._data_source, *retval) - -def add_quantity(name, **kwargs): - if 'function' not in kwargs or 'combine_function' not in kwargs: - mylog.error("Not adding field %s because both function and combine_function must be provided" % name) - return - f = kwargs.pop('function') - c = kwargs.pop('combine_function') - quantity_info[name] = (name, f, c, kwargs) - -class DerivedQuantityCollection(object): - functions = quantity_info - def __init__(self, data_source): - self.data_source = data_source - - def __getitem__(self, key): - if key not in self.functions: - raise KeyError(key) - args = self.functions[key][:3] - kwargs = self.functions[key][3] - # Instantiate here, so we can pass it the data object - # Note that this means we instantiate every time we run help, etc - # I have made my peace with this. - return DerivedQuantity(self, *args, **kwargs) - - def keys(self): - return self.functions.keys() - -def _TotalMass(data): - """ - This function takes no arguments and returns the sum of cell masses and - particle masses in the object. - """ - baryon_mass = data["CellMassMsun"].sum() - particle_mass = data["ParticleMassMsun"].sum() - return baryon_mass, particle_mass -def _combTotalMass(data, baryon_mass, particle_mass): - return baryon_mass.sum() + particle_mass.sum() -add_quantity("TotalMass", function=_TotalMass, - combine_function=_combTotalMass, n_ret = 2) - -def _CenterOfMass(data): - """ - This function takes no arguments and returns the location of the center - of mass of the *non-particle* data in the object. - """ - x = (data["x"] * data["CellMassMsun"]).sum() - y = (data["y"] * data["CellMassMsun"]).sum() - z = (data["z"] * data["CellMassMsun"]).sum() - den = data["CellMassMsun"].sum() - return x,y,z, den -def _combCenterOfMass(data, x,y,z, den): - return na.array([x.sum(), y.sum(), z.sum()])/den.sum() -add_quantity("CenterOfMass", function=_CenterOfMass, - combine_function=_combCenterOfMass, n_ret = 4) - -def _WeightedAverageQuantity(data, field, weight): - """ - This function returns an averaged quantity. - - :param field: The field to average - :param weight: The field to weight by - """ - num = (data[field] * data[weight]).sum() - den = data[weight].sum() - return num, den -def _combWeightedAverageQuantity(data, field, weight): - return field.sum()/weight.sum() -add_quantity("WeightedAverageQuantity", function=_WeightedAverageQuantity, - combine_function=_combWeightedAverageQuantity, n_ret = 2) - -def _BulkVelocity(data): - """ - This function returns the mass-weighted average velocity in the object. - """ - xv = (data["x-velocity"] * data["CellMassMsun"]).sum() - yv = (data["y-velocity"] * data["CellMassMsun"]).sum() - zv = (data["z-velocity"] * data["CellMassMsun"]).sum() - w = data["CellMassMsun"].sum() - return xv, yv, zv, w -def _combBulkVelocity(data, xv, yv, zv, w): - w = w.sum() - xv = xv.sum()/w - yv = yv.sum()/w - zv = zv.sum()/w - return na.array([xv, yv, zv]) -add_quantity("BulkVelocity", function=_BulkVelocity, - combine_function=_combBulkVelocity, n_ret=4) - -def _AngularMomentumVector(data): - """ - This function returns the mass-weighted average angular momentum vector. - """ - am = data["SpecificAngularMomentum"]*data["CellMassMsun"] - j_mag = am.sum(axis=1) - return [j_mag] -def _combAngularMomentumVector(data, j_mag): - if len(j_mag.shape) < 2: j_mag = na.expand_dims(j_mag, 0) - L_vec = j_mag.sum(axis=0) - L_vec_norm = L_vec / na.sqrt((L_vec**2.0).sum()) - return L_vec_norm -add_quantity("AngularMomentumVector", function=_AngularMomentumVector, - combine_function=_combAngularMomentumVector, n_ret=1) - -def _BaryonSpinParameter(data): - """ - This function returns the spin parameter for the baryons, but it uses - the particles in calculating enclosed mass. - """ - m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum() - am = data["SpecificAngularMomentum"]*data["CellMassMsun"] - j_mag = am.sum(axis=1) - e_term_pre = na.sum(data["CellMassMsun"]*data["VelocityMagnitude"]**2.0) - weight=data["CellMassMsun"].sum() - return j_mag, m_enc, e_term_pre, weight -def _combBaryonSpinParameter(data, j_mag, m_enc, e_term_pre, weight): - # Because it's a vector field, we have to ensure we have enough dimensions - if len(j_mag.shape) < 2: j_mag = na.expand_dims(j_mag, 0) - W = weight.sum() - M = m_enc.sum() - J = na.sqrt(((j_mag.sum(axis=0))**2.0).sum())/W - E = na.sqrt(e_term_pre.sum()/W) - G = 6.67e-8 # cm^3 g^-1 s^-2 - spin = J * E / (M*1.989e33*G) - return spin -add_quantity("BaryonSpinParameter", function=_BaryonSpinParameter, - combine_function=_combBaryonSpinParameter, n_ret=4) - -def _ParticleSpinParameter(data): - """ - This function returns the spin parameter for the baryons, but it uses - the particles in calculating enclosed mass. - """ - m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum() - am = data["ParticleSpecificAngularMomentum"]*data["ParticleMassMsun"] - if am.size == 0: return (na.zeros((3,), dtype='float64'), m_enc, 0, 0) - j_mag = am.sum(axis=1) - e_term_pre = na.sum(data["ParticleMassMsun"] - *data["ParticleVelocityMagnitude"]**2.0) - weight=data["ParticleMassMsun"].sum() - return j_mag, m_enc, e_term_pre, weight -add_quantity("ParticleSpinParameter", function=_ParticleSpinParameter, - combine_function=_combBaryonSpinParameter, n_ret=4) - -def _IsBound(data, truncate = True, include_thermal_energy = False): - """ - This returns whether or not the object is gravitationally bound - - :param truncate: Should the calculation stop once the ratio of - gravitational:kinetic is 1.0? - :param include_thermal_energy: Should we add the energy from ThermalEnergy - on to the kinetic energy to calculate - binding energy? - """ - # Kinetic energy - bv_x,bv_y,bv_z = data.quantities["BulkVelocity"]() - # One-cell objects are NOT BOUND. - if data["CellMass"].size == 1: return [0.0] - kinetic = 0.5 * (data["CellMass"] * ( - (data["x-velocity"] - bv_x)**2 - + (data["y-velocity"] - bv_y)**2 - + (data["z-velocity"] - bv_z)**2 )).sum() - # Add thermal energy to kinetic energy - if (include_thermal_energy): - thermal = (data["ThermalEnergy"] * data["CellMass"]).sum() - kinetic += thermal - # Gravitational potential energy - # We only divide once here because we have velocity in cgs, but radius is - # in code. - G = 6.67e-8 / data.convert("cm") # cm^3 g^-1 s^-2 - import time - t1 = time.time() - try: - pot = G*_cudaIsBound(data, truncate, kinetic/G) - except (ImportError, AssertionError): - pot = G*PointCombine.FindBindingEnergy(data["CellMass"], - data['x'],data['y'],data['z'], - truncate, kinetic/G) - mylog.info("Boundedness check took %0.3e seconds", time.time()-t1) - return [(pot / kinetic)] -def _combIsBound(data, bound): - return bound -add_quantity("IsBound",function=_IsBound,combine_function=_combIsBound,n_ret=1, - force_unlazy=True) - -def _cudaIsBound(data, truncate, ratio): - bsize = __CUDA_BLOCK_SIZE - import pycuda.driver as cuda - import pycuda.autoinit - import pycuda.gpuarray as gpuarray - my_stream = cuda.Stream() - cuda.init() - assert cuda.Device.count() >= 1 - - mass_scale_factor = 1.0/(data['CellMass'].max()) - m = (data['CellMass'] * mass_scale_factor).astype('float32') - assert(m.size > bsize) - - gsize=int(math.ceil(float(m.size)/bsize)) - assert(gsize > 16) - - # Now the tedious process of rescaling our values... - length_scale_factor = data['dx'].max()/data['dx'].min() - x = ((data['x'] - data['x'].min()) * length_scale_factor).astype('float32') - y = ((data['y'] - data['y'].min()) * length_scale_factor).astype('float32') - z = ((data['z'] - data['z'].min()) * length_scale_factor).astype('float32') - p = na.zeros(z.shape, dtype='float32') - - x_gpu = cuda.mem_alloc(x.size * x.dtype.itemsize) - y_gpu = cuda.mem_alloc(y.size * y.dtype.itemsize) - z_gpu = cuda.mem_alloc(z.size * z.dtype.itemsize) - m_gpu = cuda.mem_alloc(m.size * m.dtype.itemsize) - p_gpu = cuda.mem_alloc(p.size * p.dtype.itemsize) - for ag, a in [(x_gpu, x), (y_gpu, y), (z_gpu, z), (m_gpu, m), (p_gpu, p)]: - cuda.memcpy_htod(ag, a) - source = """ - - extern __shared__ float array[]; - - __global__ void isbound(float *x, float *y, float *z, float *m, - float *p, int *nelem) - { - - /* My index in the array */ - int idx1 = blockIdx.x * blockDim.x + threadIdx.x; - /* Note we are setting a start index */ - int idx2 = blockIdx.y * blockDim.x; - int offset = threadIdx.x; - - /* Here we're just setting up convenience pointers to our - shared array */ - - float* x_data1 = (float*) array; - float* y_data1 = (float*) &x_data1[blockDim.x]; - float* z_data1 = (float*) &y_data1[blockDim.x]; - float* m_data1 = (float*) &z_data1[blockDim.x]; - - float* x_data2 = (float*) &m_data1[blockDim.x]; - float* y_data2 = (float*) &x_data2[blockDim.x]; - float* z_data2 = (float*) &y_data2[blockDim.x]; - float* m_data2 = (float*) &z_data2[blockDim.x]; - - x_data1[offset] = x[idx1]; - y_data1[offset] = y[idx1]; - z_data1[offset] = z[idx1]; - m_data1[offset] = m[idx1]; - - x_data2[offset] = x[idx2 + offset]; - y_data2[offset] = y[idx2 + offset]; - z_data2[offset] = z[idx2 + offset]; - m_data2[offset] = m[idx2 + offset]; - - __syncthreads(); - - float tx, ty, tz; - - float my_p = 0.0; - - if(idx1 < %(p)s) { - for (int i = 0; i < blockDim.x; i++){ - if(i + idx2 < idx1 + 1) continue; - tx = (x_data1[offset]-x_data2[i]); - ty = (y_data1[offset]-y_data2[i]); - tz = (z_data1[offset]-z_data2[i]); - my_p += m_data1[offset]*m_data2[i] / - sqrt(tx*tx+ty*ty+tz*tz); - } - } - p[idx1] += my_p; - __syncthreads(); - } - """ - mod = cuda.SourceModule(source % dict(p=m.size)) - func = mod.get_function('isbound') - mylog.info("Running CUDA functions. May take a while. (%0.5e, %s)", - x.size, gsize) - import pycuda.tools as ct - t1 = time.time() - ret = func(x_gpu, y_gpu, z_gpu, m_gpu, p_gpu, - shared=8*bsize*m.dtype.itemsize, - block=(bsize,1,1), grid=(gsize, gsize), time_kernel=True) - cuda.memcpy_dtoh(p, p_gpu) - p1 = p.sum() - if na.any(na.isnan(p)): raise ValueError - return p1 * (length_scale_factor / (mass_scale_factor**2.0)) - -def _Extrema(data, fields, non_zero = False, filter=None): - """ - This function returns the extrema of a set of fields - - :param fields: A field name, or a list of field names - :param filter: a string to be evaled to serve as a data filter. - """ - # There is a heck of a lot of logic in this. I really wish it were more - # elegant. - fields = ensure_list(fields) - if filter is not None: this_filter = eval(filter) - mins, maxs = [], [] - for field in fields: - if data[field].size < 1: - mins.append(1e90) - maxs.append(-1e90) - continue - if filter is None: - if non_zero: - nz_filter = data[field]>0.0 - if not nz_filter.any(): - mins.append(1e90) - maxs.append(-1e90) - continue - else: - nz_filter = None - mins.append(data[field][nz_filter].min()) - maxs.append(data[field][nz_filter].max()) - else: - if this_filter.any(): - if non_zero: - nz_filter = ((this_filter) & - (data[field][this_filter] > 0.0)) - else: nz_filter = this_filter - mins.append(data[field][nz_filter].min()) - maxs.append(data[field][nz_filter].max()) - else: - mins.append(1e90) - maxs.append(-1e90) - return len(fields), mins, maxs -def _combExtrema(data, n_fields, mins, maxs): - mins, maxs = na.atleast_2d(mins, maxs) - n_fields = mins.shape[1] - return [(na.min(mins[:,i]), na.max(maxs[:,i])) for i in range(n_fields)] -add_quantity("Extrema", function=_Extrema, combine_function=_combExtrema, - n_ret=3) - -def _Action(data, action, combine_action, filter=None): - """ - This function evals the string given by the action arg and uses - the function thrown with the combine_action to combine the values. - A filter can be thrown to be evaled to short-circuit the calculation - if some criterion is not met. - :param action: a string containing the desired action to be evaled. - :param combine_action: the function used to combine the answers when done lazily. - :param filter: a string to be evaled to serve as a data filter. - """ - if filter is not None: - if not eval(filter).any(): return 0, False, combine_action - value = eval(action) - return value, True, combine_action -def _combAction(data, value, valid, combine_action): - return combine_action[0](value[valid]) -add_quantity("Action", function=_Action, combine_function=_combAction, n_ret=3) - -def _MaxLocation(data, field): - """ - This function returns the location of the maximum of a set - of fields. - """ - ma, maxi, mx, my, mz, mg = -1e90, -1, -1, -1, -1, -1 - if data[field].size > 0: - maxi = na.argmax(data[field]) - ma = data[field][maxi] - mx, my, mz = [data[ax][maxi] for ax in 'xyz'] - mg = data["GridIndices"][maxi] - return (ma, maxi, mx, my, mz, mg) -def _combMaxLocation(data, *args): - args = [na.atleast_1d(arg) for arg in args] - i = na.argmax(args[0]) # ma is arg[0] - return [arg[i] for arg in args] -add_quantity("MaxLocation", function=_MaxLocation, - combine_function=_combMaxLocation, n_ret = 6) - -def _TotalQuantity(data, fields): - """ - This function sums up a given field over the entire region - - :param fields: The fields to sum up - """ - fields = ensure_list(fields) - totals = [] - for field in fields: - if data[field].size < 1: - totals.append(0) - continue - totals.append(data[field].sum()) - return len(fields), totals -def _combTotalQuantity(data, n_fields, totals): - totals = na.atleast_2d(totals) - n_fields = totals.shape[1] - return [na.sum(totals[:,i]) for i in range(n_fields)] -add_quantity("TotalQuantity", function=_TotalQuantity, - combine_function=_combTotalQuantity, n_ret=2) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/EnzoCosmology.py --- a/yt/lagos/EnzoCosmology.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +0,0 @@ -""" -Conversion functions between time and redshift healthily jacked from Enzo. - -Author: Britton Smith -Affiliation: CASA/University of CO, Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -import numpy as na - -kmPerMpc = 3.08567758e19 - -class EnzoCosmology(object): - def __init__(self, HubbleConstantNow = 71.0, - OmegaMatterNow = 0.27, - OmegaLambdaNow = 0.73, - OmegaCurvatureNow = 0.0, - InitialRedshift = 99.0): - self.HubbleConstantNow = HubbleConstantNow - self.OmegaMatterNow = OmegaMatterNow - self.OmegaLambdaNow = OmegaLambdaNow - self.OmegaCurvatureNow = OmegaCurvatureNow - self.InitialRedshift = InitialRedshift - self.InitialTime = self.ComputeTimeFromRedshift(self.InitialRedshift) - self.TimeUnits = self.ComputeTimeUnits() - - def ComputeTimeUnits(self): - """ - Taken from CosmologyGetUnits.C in Enzo. - """ - # Changed 2.52e17 to 2.52e19 because H_0 is in km/s/Mpc, - # instead of 100 km/s/Mpc. - return 2.52e19 / na.sqrt(self.OmegaMatterNow) / \ - self.HubbleConstantNow / na.power(1 + self.InitialRedshift,1.5) - - def ComputeRedshiftFromTime(self,time): - """ - Compute the redshift from time after the big bang. This is based on - Enzo's CosmologyComputeExpansionFactor.C, but altered to use physical - units. - """ - - OmegaCurvatureNow = 1.0 - self.OmegaMatterNow - self.OmegaLambdaNow - - OMEGA_TOLERANCE = 1e-5 - ETA_TOLERANCE = 1.0e-10 - - # Convert the time to Time * H0. - - TimeHubble0 = time * self.HubbleConstantNow / kmPerMpc - - # 1) For a flat universe with OmegaMatterNow = 1, it's easy. - - if ((na.fabs(self.OmegaMatterNow-1) < OMEGA_TOLERANCE) and - (self.OmegaLambdaNow < OMEGA_TOLERANCE)): - a = na.power(time/self.InitialTime,2.0/3.0) - - # 2) For OmegaMatterNow < 1 and OmegaLambdaNow == 0 see - # Peebles 1993, eq. 13-3, 13-10. - # Actually, this is a little tricky since we must solve an equation - # of the form eta - na.sinh(eta) + x = 0.. - - if ((self.OmegaMatterNow < 1) and - (self.OmegaLambdaNow < OMEGA_TOLERANCE)): - x = 2*TimeHubble0*na.power(1.0 - self.OmegaMatterNow, 1.5) / \ - self.OmegaMatterNow; - - # Compute eta in a three step process, first from a third-order - # Taylor expansion of the formula above, then use that in a fifth-order - # approximation. Then finally, iterate on the formula itself, solving for - # eta. This works well because parts 1 & 2 are an excellent approximation - # when x is small and part 3 converges quickly when x is large. - - eta = na.power(6*x,1.0/3.0) # part 1 - eta = na.power(120*x/(20+eta*eta),1.0/3.0) # part 2 - for i in range(40): # part 3 - eta_old = eta - eta = na.arcsinh(eta + x) - if (na.fabs(eta-eta_old) < ETA_TOLERANCE): - break - if (i == 39): - print "No convergence after %d iterations." % i - - # Now use eta to compute the expansion factor (eq. 13-10, part 2). - - a = self.OmegaMatterNow/(2.0*(1.0 - self.OmegaMatterNow))*\ - (na.cosh(eta) - 1.0) - - # 3) For OmegaMatterNow > 1 and OmegaLambdaNow == 0, use sin/cos. - # Easy, but skip it for now. - - if ((self.OmegaMatterNow > 1) and - (self.OmegaLambdaNow < OMEGA_TOLERANCE)): - print "Never implemented in Enzo, not implemented here." - return 0 - - # 4) For flat universe, with non-zero OmegaLambdaNow, see eq. 13-20. - - if ((na.fabs(OmegaCurvatureNow) < OMEGA_TOLERANCE) and - (self.OmegaLambdaNow > OMEGA_TOLERANCE)): - a = na.power(self.OmegaMatterNow / (1 - self.OmegaMatterNow),1.0/3.0) * \ - na.power(na.sinh(1.5 * na.sqrt(1.0 - self.OmegaMatterNow)*\ - TimeHubble0),2.0/3.0) - - - redshift = (1.0/a) - 1.0 - - return redshift - - def ComputeTimeFromRedshift(self,z): - """ - Compute the time from redshift. This is based on Enzo's - CosmologyComputeTimeFromRedshift.C, but altered to use physical units. - """ - OmegaCurvatureNow = 1.0 - self.OmegaMatterNow - self.OmegaLambdaNow - - # 1) For a flat universe with OmegaMatterNow = 1, things are easy. - - if ((self.OmegaMatterNow == 1.0) and (self.OmegaLambdaNow == 0.0)): - TimeHubble0 = 2.0/3.0/na.power(1+z,1.5) - - # 2) For OmegaMatterNow < 1 and OmegaLambdaNow == 0 see - # Peebles 1993, eq. 13-3, 13-10. - - if ((self.OmegaMatterNow < 1) and (self.OmegaLambdaNow == 0)): - eta = na.arccosh(1 + 2*(1-self.OmegaMatterNow)/self.OmegaMatterNow/(1+z)) - TimeHubble0 = self.OmegaMatterNow/(2*na.power(1.0-self.OmegaMatterNow, 1.5))*\ - (na.sinh(eta) - eta) - - # 3) For OmegaMatterNow > 1 and OmegaLambdaNow == 0, use sin/cos. - - if ((self.OmegaMatterNow > 1) and (self.OmegaLambdaNow == 0)): - eta = na.acos(1 - 2*(1-self.OmegaMatterNow)/self.OmegaMatterNow/(1+z)) - TimeHubble0 = self.OmegaMatterNow/(2*na.power(1.0-self.OmegaMatterNow, 1.5))*\ - (eta - na.sin(eta)) - - # 4) For flat universe, with non-zero OmegaLambdaNow, see eq. 13-20. - - if ((na.fabs(OmegaCurvatureNow) < 1.0e-3) and (self.OmegaLambdaNow != 0)): - TimeHubble0 = 2.0/3.0/na.sqrt(1-self.OmegaMatterNow)*\ - na.arcsinh(na.sqrt((1-self.OmegaMatterNow)/self.OmegaMatterNow)/ \ - na.power(1+z,1.5)) - - # Now convert from Time * H0 to time. - - time = TimeHubble0 / (self.HubbleConstantNow/kmPerMpc) - - return time diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/EnzoDefs.py --- a/yt/lagos/EnzoDefs.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -""" -Various definitions for various other modules and routines - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ - -@todo: Move into yt.Defs, along with enki.EnkiDefs -License: - Copyright (C) 2007-2009 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 . -""" - -# The number of levels we expect to have at most -MAXLEVEL=48 - -# Number of levels to toss back to check for maximum -NUMTOCHECK=2 - -axis_labels = [('y','z'),('x','z'),('x','y')] -axis_names = {0: 'x', 1: 'y', 2: 'z', 4:''} -inv_axis_names = {'x':0,'y':1,'z':2} - -vm_axis_names = {0:'x', 1:'y', 2:'z', 3:'dx', 4:'dy'} - -# The appropriate axes for which way we are slicing -x_dict = [1,0,0] -y_dict = [2,2,1] - -x_names = ['y','x','x'] -y_names = ['z','z','y'] - -mh = 1.67e-24 -mu = 1.22 - -# All the parameters we read from the parameter file, along with how to convert -# them from a string -parameterDict = {"CosmologyCurrentRedshift": float, - "CosmologyComovingBoxSize": float, - "CosmologyOmegaMatterNow": float, - "CosmologyOmegaLambdaNow": float, - "CosmologyHubbleConstantNow": float, - "CosmologyInitialRedshift": float, - "DualEnergyFormalismEta1": float, - "DualEnergyFormalismEta2": float, - "MetaDataString": str, - "HydroMethod": int, - "DualEnergyFormalism": int, - "InitialTime": float, - "ComovingCoordinates": int, - "DensityUnits": float, - "LengthUnits": float, - "LengthUnit": float, - "TemperatureUnits": float, - "TimeUnits": float, - "GravitationalConstant": float, - "Gamma": float, - "MultiSpecies": int, - "CompilerPrecision": str, - "CurrentTimeIdentifier": int, - "RefineBy": int, - "BoundaryConditionName": str, - "TopGridRank": int, - "TopGridDimensions": int, - "EOSSoundSpeed": float, - "EOSType": int, - "NumberOfParticleAttributes": int, - } - -mpc_conversion = {'mpc' : 1e0, - 'kpc' : 1e3, - 'pc' : 1e6, - 'au' : 2.063e11, - 'rsun' : 4.43664e13, - 'cm' : 3.0857e24, - 'miles' : 1.917e19} - -axis_labels = [('y','z'),('x','z'),('x','y')] diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/EnzoFields.py --- a/yt/lagos/EnzoFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,452 +0,0 @@ -""" -Fields applicable only to Enzo - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from UniversalFields import * -from yt.amr_utils import CICDeposit_3 - -rho_crit_now = 1.8788e-29 # times h^2 - -class EnzoFieldContainer(CodeFieldInfoContainer): - """ - This is a container for Enzo-specific fields. - """ - _shared_state = {} - _field_list = {} -EnzoFieldInfo = EnzoFieldContainer() -add_enzo_field = EnzoFieldInfo.add_field - -add_field = add_enzo_field - -_speciesList = ["HI","HII","Electron", - "HeI","HeII","HeIII", - "H2I","H2II","HM", - "DI","DII","HDI","Metal","PreShock"] -_speciesMass = {"HI":1.0,"HII":1.0,"Electron":1.0, - "HeI":4.0,"HeII":4.0,"HeIII":4.0, - "H2I":2.0,"H2II":2.0,"HM":1.0, - "DI":2.0,"DII":2.0,"HDI":3.0} - -def _SpeciesComovingDensity(field, data): - sp = field.name.split("_")[0] + "_Density" - ef = (1.0 + data.pf["CosmologyCurrentRedshift"])**3.0 - return data[sp]/ef -def _SpeciesFraction(field, data): - sp = field.name.split("_")[0] + "_Density" - return data[sp]/data["Density"] -def _SpeciesNumberDensity(field, data): - species = field.name.split("_")[0] - sp = field.name.split("_")[0] + "_Density" - return data[sp]/_speciesMass[species] -def _ConvertNumberDensity(data): - return 1.0/mh - -for species in _speciesList: - add_field("%s_Fraction" % species, - function=_SpeciesFraction, - validators=ValidateDataField("%s_Density" % species)) - add_field("Comoving_%s_Density" % species, - function=_SpeciesComovingDensity, - validators=ValidateDataField("%s_Density" % species)) - if _speciesMass.has_key(species): - add_field("%s_NumberDensity" % species, - function=_SpeciesNumberDensity, - convert_function=_ConvertNumberDensity, - validators=ValidateDataField("%s_Density" % species)) - -def _Metallicity(field, data): - return data["Metal_Fraction"] -def _ConvertMetallicity(data): - return 49.0196 # 1 / 0.0204 -add_field("Metallicity", units=r"Z_{\rm{\odot}}", - function=_Metallicity, - convert_function=_ConvertMetallicity, - validators=ValidateDataField("Metal_Density"), - projection_conversion="1") - -def _Metallicity3(field, data): - return data["SN_Colour"]/data["Density"] -add_field("Metallicity3", units=r"Z_{\rm{\odot}}", - function=_Metallicity3, - convert_function=_ConvertMetallicity, - validators=ValidateDataField("SN_Colour"), - projection_conversion="1") - -def _Cooling_Time(field, data): - return data["Cooling_Time"] -add_field("Cooling_Time", units=r"\rm{s}", - function=_Cooling_Time, - validators=ValidateDataField("Cooling_Time"), - projection_conversion="1") - -def _ThermalEnergy(field, data): - if data.pf["HydroMethod"] == 2: - return data["Total_Energy"] - else: - if data.pf["DualEnergyFormalism"]: - return data["GasEnergy"] - else: - return data["Total_Energy"] - 0.5*( - data["x-velocity"]**2.0 - + data["y-velocity"]**2.0 - + data["z-velocity"]**2.0 ) -add_field("ThermalEnergy", function=_ThermalEnergy, - units=r"\rm{ergs}/\rm{cm^3}") - -def _KineticEnergy(field, data): - return 0.5*data["Density"] * ( data["x-velocity"]**2.0 - + data["y-velocity"]**2.0 - + data["z-velocity"]**2.0 ) -add_field("KineticEnergy",function=_KineticEnergy, - units = r"\rm{ergs}/\rm{cm^3}") -# This next section is the energy field section -# Note that we have aliases that manually unconvert themselves. -# This is because numerous code branches use Gas_Energy or GasEnergy -# indiscriminately -- this is almost fixed with LCA1.5, but not everyone is -# moving to that branch. So, because the actual function doesn't get called -# *unless* it's an alias, we simply de-convert -- since the input data is -# already converted to cgs. - -def _convertEnergy(data): - return data.convert("x-velocity")**2.0 - -def _GasEnergy(field, data): - return data["Gas_Energy"] / _convertEnergy(data) -add_field("GasEnergy", function=_GasEnergy, - units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) - -def _Gas_Energy(field, data): - return data["GasEnergy"] / _convertEnergy(data) -add_field("Gas_Energy", function=_Gas_Energy, - units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) - -def _TotalEnergy(field, data): - return data["Total_Energy"] / _convertEnergy(data) -add_field("TotalEnergy", function=_TotalEnergy, - display_name = "\mathrm{Total}\/\mathrm{Energy}", - units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) - -def _Total_Energy(field, data): - return data["TotalEnergy"] / _convertEnergy(data) -add_field("Total_Energy", function=_Total_Energy, - display_name = "\mathrm{Total}\/\mathrm{Energy}", - units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy) - -def _NumberDensity(field, data): - # We can assume that we at least have Density - # We should actually be guaranteeing the presence of a .shape attribute, - # but I am not currently implementing that - fieldData = na.zeros(data["Density"].shape, - dtype = data["Density"].dtype) - if data.pf["MultiSpecies"] == 0: - if data.has_field_parameter("mu"): - mu = data.get_field_parameter("mu") - else: - mu = 0.6 - fieldData += data["Density"] / mu - if data.pf["MultiSpecies"] > 0: - fieldData += data["HI_Density"] / 1.0 - fieldData += data["HII_Density"] / 1.0 - fieldData += data["HeI_Density"] / 4.0 - fieldData += data["HeII_Density"] / 4.0 - fieldData += data["HeIII_Density"] / 4.0 - fieldData += data["Electron_Density"] / 1.0 - if data.pf["MultiSpecies"] > 1: - fieldData += data["HM_Density"] / 1.0 - fieldData += data["H2I_Density"] / 2.0 - fieldData += data["H2II_Density"] / 2.0 - if data.pf["MultiSpecies"] > 2: - fieldData += data["DI_Density"] / 2.0 - fieldData += data["DII_Density"] / 2.0 - fieldData += data["HDI_Density"] / 3.0 - return fieldData -add_field("NumberDensity", units=r"\rm{cm}^{-3}", - function=_NumberDensity, - convert_function=_ConvertNumberDensity) - -def _ComovingDensity(field,data): - ef = (1.0 + data.pf["CosmologyCurrentRedshift"])**3.0 - return data["Density"]/ef -add_field("ComovingDensity", function=_ComovingDensity, units=r"\rm{g}/\rm{cm}^3") - -def Overdensity(field,data): - return (data['Density'] + data['Dark_Matter_Density']) / \ - (rho_crit_now * (data.pf['CosmologyHubbleConstantNow']**2) * ((1+data.pf['CosmologyCurrentRedshift'])**3)) -add_field("Overdensity",function=Overdensity,units=r"") - -# Now we add all the fields that we want to control, but we give a null function -# This is every Enzo field we can think of. This will be installation-dependent, - -# removed: "Gas_Energy","Total_Energy", -# these are now aliases for each other - -_default_fields = ["Density","Temperature", - "x-velocity","y-velocity","z-velocity", - "x-momentum","y-momentum","z-momentum"] -# else: -# _default_fields = ["Density","Temperature","Gas_Energy","Total_Energy", -# "x-velocity","y-velocity","z-velocity"] -_default_fields += [ "%s_Density" % sp for sp in _speciesList ] - -for field in _default_fields: - add_field(field, function=lambda a, b: None, take_log=True, - validators=[ValidateDataField(field)], units=r"\rm{g}/\rm{cm}^3") -EnzoFieldInfo["x-velocity"].projection_conversion='1' -EnzoFieldInfo["y-velocity"].projection_conversion='1' -EnzoFieldInfo["z-velocity"].projection_conversion='1' - -# Now we override - -def _convertDensity(data): - return data.convert("Density") -for field in ["Density"] + [ "%s_Density" % sp for sp in _speciesList ]: - EnzoFieldInfo[field]._units = r"\rm{g}/\rm{cm}^3" - EnzoFieldInfo[field]._projected_units = r"\rm{g}/\rm{cm}^2" - EnzoFieldInfo[field]._convert_function=_convertDensity - -add_field("Dark_Matter_Density", function=lambda a,b: None, - convert_function=_convertDensity, - validators=[ValidateDataField("Dark_Matter_Density"), - ValidateSpatial(0)], - display_name = "Dark\ Matter\ Density", - not_in_all = True) - -EnzoFieldInfo["Temperature"]._units = r"\rm{K}" -EnzoFieldInfo["Temperature"].units = r"K" - -def _convertVelocity(data): - return data.convert("x-velocity") -for ax in ['x','y','z']: - f = EnzoFieldInfo["%s-velocity" % ax] - f._units = r"\rm{cm}/\rm{s}" - f._convert_function = _convertVelocity - f.take_log = False - -def _pdensity(field, data): - blank = na.zeros(data.ActiveDimensions, dtype='float32', order="FORTRAN") - if data.NumberOfParticles == 0: return blank - cic_deposit.cic_deposit(data["particle_position_x"], - data["particle_position_y"], - data["particle_position_z"], 3, - data["particle_mass"], - blank, data.LeftEdge, data['dx']) - return blank -add_field("particle_density", function=_pdensity, - validators=[ValidateSpatial(0)], convert_function=_convertDensity) - -def _spdensity_pyx(field, data): - blank = na.zeros(data.ActiveDimensions, dtype='float32') - if data.NumberOfParticles == 0: return blank - filter = data['creation_time'] > 0.0 - if not filter.any(): return blank - CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), - data["particle_position_y"][filter].astype(na.float64), - data["particle_position_z"][filter].astype(na.float64), - data["particle_mass"][filter].astype(na.float32), - na.int64(na.where(filter)[0].size), - blank, na.array(data.LeftEdge).astype(na.float64), - na.array(data.ActiveDimensions).astype(na.int32), - na.float64(data['dx'])) - return blank -add_field("star_density_pyx", function=_spdensity_pyx, - validators=[ValidateSpatial(0)], convert_function=_convertDensity) - -def _dmpdensity_pyx(field, data): - blank = na.zeros(data.ActiveDimensions, dtype='float32') - if data.NumberOfParticles == 0: return blank - filter = data['creation_time'] <= 0.0 - if not filter.any(): return blank - CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), - data["particle_position_y"][filter].astype(na.float64), - data["particle_position_z"][filter].astype(na.float64), - data["particle_mass"][filter].astype(na.float32), - na.int64(na.where(filter)[0].size), - blank, na.array(data.LeftEdge).astype(na.float64), - na.array(data.ActiveDimensions).astype(na.int32), - na.float64(data['dx'])) - return blank -add_field("dm_density_pyx", function=_dmpdensity_pyx, - validators=[ValidateSpatial(0)], convert_function=_convertDensity) - -def _star_field(field, data): - """ - Create a grid field for star quantities, weighted by star mass. - """ - particle_field = field.name[5:] - top = na.zeros(data.ActiveDimensions, dtype='float32') - if data.NumberOfParticles == 0: return top - filter = data['creation_time'] > 0.0 - if not filter.any(): return top - particle_field_data = data[particle_field][filter] * data['particle_mass'][filter] - CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), - data["particle_position_y"][filter].astype(na.float64), - data["particle_position_z"][filter].astype(na.float64), - particle_field_data.astype(na.float32), - na.int64(na.where(filter)[0].size), - top, na.array(data.LeftEdge).astype(na.float64), - na.array(data.ActiveDimensions).astype(na.int32), - na.float64(data['dx'])) - del particle_field_data - - bottom = na.zeros(data.ActiveDimensions, dtype='float32') - CICDeposit_3(data["particle_position_x"][filter].astype(na.float64), - data["particle_position_y"][filter].astype(na.float64), - data["particle_position_z"][filter].astype(na.float64), - data["particle_mass"][filter].astype(na.float32), - na.int64(na.where(filter)[0].size), - bottom, na.array(data.LeftEdge).astype(na.float64), - na.array(data.ActiveDimensions).astype(na.int32), - na.float64(data['dx'])) - - top[bottom == 0] = 0.0 - bnz = bottom.nonzero() - top[bnz] /= bottom[bnz] - return top - -add_field('star_metallicity_fraction', function=_star_field, - validators=[ValidateSpatial(0)]) -add_field('star_creation_time', function=_star_field, - validators=[ValidateSpatial(0)]) -add_field('star_dynamical_time', function=_star_field, - validators=[ValidateSpatial(0)]) - -def _StarMetallicity(field, data): - return data['star_metallicity_fraction'] -add_field('StarMetallicity', units=r"Z_{\rm{\odot}}", - function=_StarMetallicity, - convert_function=_ConvertMetallicity, - projection_conversion="1") - -def _StarCreationTime(field, data): - return data['star_creation_time'] -def _ConvertEnzoTimeYears(data): - return data.pf.time_units['years'] -add_field('StarCreationTimeYears', units=r"\mathrm{yr}", - function=_StarCreationTime, - convert_function=_ConvertEnzoTimeYears, - projection_conversion="1") - -def _StarDynamicalTime(field, data): - return data['star_dynamical_time'] -add_field('StarDynamicalTimeYears', units=r"\mathrm{yr}", - function=_StarDynamicalTime, - convert_function=_ConvertEnzoTimeYears, - projection_conversion="1") - -def _StarAge(field, data): - star_age = na.zeros(data['StarCreationTimeYears'].shape) - with_stars = data['StarCreationTimeYears'] > 0 - star_age[with_stars] = data.pf.time_units['years'] * \ - data.pf["InitialTime"] - \ - data['StarCreationTimeYears'][with_stars] - return star_age -add_field('StarAgeYears', units=r"\mathrm{yr}", - function=_StarAge, - projection_conversion="1") - -def _IsStarParticle(field, data): - is_star = (data['creation_time'] > 0).astype('float64') - return is_star -add_field('IsStarParticle', function=_IsStarParticle, - particle_type = True) - -# -# Now we do overrides for 2D fields -# - -class Enzo2DFieldContainer(CodeFieldInfoContainer): - _shared_state = {} - _field_list = EnzoFieldContainer._field_list.copy() -# We make a copy of the dict from the other, so we -# can now update it... -Enzo2DFieldInfo = Enzo2DFieldContainer() -add_enzo_2d_field = Enzo2DFieldInfo.add_field - -def _CellArea(field, data): - if data['dx'].size == 1: - try: - return data['dx']*data['dy']*\ - na.ones(data.ActiveDimensions, dtype='float64') - except AttributeError: - return data['dx']*data['dy'] - return data["dx"]*data["dy"] -def _ConvertCellAreaMpc(data): - return data.convert("mpc")**2.0 -def _ConvertCellAreaCGS(data): - return data.convert("cm")**2.0 -add_enzo_2d_field("CellAreaCode", units=r"\rm{BoxArea}^2", - function=_CellArea) -add_enzo_2d_field("CellAreaMpc", units=r"\rm{Mpc}^2", - function=_CellArea, - convert_function=_ConvertCellAreaMpc) -add_enzo_2d_field("CellArea", units=r"\rm{cm}^2", - function=_CellArea, - convert_function=_ConvertCellAreaCGS) - -for a in ["Code", "Mpc", ""]: - Enzo2DFieldInfo["CellVolume%s" % a] = \ - Enzo2DFieldInfo["CellArea%s" % a] - -def _zvel(field, data): - return na.zeros(data["x-velocity"].shape, - dtype='float64') -add_enzo_2d_field("z-velocity", function=_zvel) - - -# -# Now we do overrides for 1D fields -# - -class Enzo1DFieldContainer(CodeFieldInfoContainer): - _shared_state = {} - _field_list = EnzoFieldContainer._field_list.copy() -# We make a copy of the dict from the other, so we -# can now update it... -Enzo1DFieldInfo = Enzo1DFieldContainer() -add_enzo_1d_field = Enzo1DFieldInfo.add_field - -def _CellLength(field, data): - return data["dx"] -def _ConvertCellLengthMpc(data): - return data.convert("mpc") -def _ConvertCellLengthCGS(data): - return data.convert("cm") -add_enzo_1d_field("CellLengthCode", units=r"\rm{BoxArea}^2", - function=_CellLength) -add_enzo_1d_field("CellLengthMpc", units=r"\rm{Mpc}^2", - function=_CellLength, - convert_function=_ConvertCellLengthMpc) -add_enzo_1d_field("CellLength", units=r"\rm{cm}^2", - function=_CellLength, - convert_function=_ConvertCellLengthCGS) - -for a in ["Code", "Mpc", ""]: - Enzo1DFieldInfo["CellVolume%s" % a] = \ - Enzo1DFieldInfo["CellLength%s" % a] - -def _yvel(field, data): - return na.zeros(data["x-velocity"].shape, - dtype='float64') -add_enzo_1d_field("z-velocity", function=_zvel) -add_enzo_1d_field("y-velocity", function=_yvel) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/EnzoRateData.py --- a/yt/lagos/EnzoRateData.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -""" -Some functions to include chemistry stuff, -although it should work for generalized -tables, if fed the appropriate key. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -rates_out_key = \ - [ "tgas", \ - "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9", "k10", "k11", \ - "k12", "k13", "k14", "k15", "k16", "k17", "k18", "k19", "k21", "k22",\ - "k23", "k50", "k51", "k52", "k53", "k54", "k55", "k56", \ - "k13_1", "k13_2", "k13_3", "k13_4", "k13_5", "k13_6", "k13_7" ] - -cool_out_key = \ - [ "tgas", \ - "ceHI", "ceHeI", "ceHeII", "ciHI", "ciHeI", "ciHeIS", "ciHeII",\ - "reHII", "reHeII1", "reHeII2", "reHeIII", "brem", "comp", \ - "gphdl", "gpldl", "cieco", "vibh", "hyd01k", "rotl", "roth", \ - "h2k01", "hdlte", "hdlow", "hdc_1", "hdc_2", "hdc_3", "hdc_4", \ - "hdc_5"] - -from yt.lagos import * -#from numarray import * -#import numarray.nd_image as nd -import PointCombine -import types, exceptions - -class EnzoTable: - # This is a class for storing tables of data from enzo. - # Specifically, we will be storing chemical rates and cooling rates - def __init__(self, filename, key): - # We get fed the filename and a table that is the key to the column names - self.cols = {} - self.invcols = {} - for i in range(len(key)): - self.cols[key[i]] = i - self.invcols[i] = key[i] - self.filename = filename - self.readTable() - def clearAll(self): - try: - del self.columns - except: - pass - try: - del self.params - except: - pass - def readTable(self): - self.clearAll() - lines = open(self.filename).readlines() - # We may have comment lines, which we need to strip out - # There may be a more elegant way to do this - # We assume that all unit lines have only one value - # This is slow, due to the stripping and splitting, but it shouldn't be - # a huge portion of the whole runtime - i = 0 - self.params = {} - toArray = [] - for line in lines: - if line.strip()[0] == "#": - # It's a comment/unit line - p, v = line[1:].split("=") - self.params[p.replace(" ","")[1:]] = float(v) - else: - toArray.append(map(float, line.split())) - self.columns = na.array(toArray, 'float64') - mylog.debug("Found %s bins of rate values", self.columns.shape[0]) - def __getitem__(self, item): - ## This WILL get cleaned up, but it does what I want for now - x_vals = [] - toReshape = None - if isinstance(item, types.TupleType): - if isinstance(item[0], types.FloatType) or \ - isinstance(item[0], types.IntType): - x_vals.append(float(item[0])) - elif isinstance(item[0], na.ndarray): - toReshape = item[0].shape - x_vals = (item[0].ravel()) - colsToReturn = [] - for col in item[1:]: - if isinstance(col, types.StringType): - colsToReturn.append(self.cols[col]) - else: - colsToReturn.append(int(col)) - elif isinstance(item, types.FloatType) or \ - isinstance(item, types.IntType): - x_vals.append(float(item)) - colsToReturn=arange(1,len(self.cols)) - elif isinstance(item, na.ndarray): - toReshape = item.shape - x_vals = item.ravel() - colsToReturn=arange(1,len(self.cols)) - elif isinstance(item, types.ListType): - colsToReturn=arange(1,len(self.cols)) - elif isinstance(item, types.StringType): - return self.columns[:,self.cols[item]] - else: - raise exceptions.TypeError() - colsToReturn = na.array(colsToReturn,'int32') - valsToReturn = na.zeros((len(x_vals),len(colsToReturn)),'float64') - x_axis = self.columns[:,0] - x_vals_arr = na.array(x_vals, 'float64') - PointCombine.Interpolate(x_axis, self.columns, x_vals_arr, valsToReturn, colsToReturn) - if toReshape != None: - if len(colsToReturn == 1): - valsToReturn = na.reshape(valsToReturn, toReshape) - else: - newShape = list(toReshape) - newShape.append(len(colsToReturn)) - valsToReturn = na.reshape(valsToReturn, newShape) - return valsToReturn diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/EnzoRunType.py --- a/yt/lagos/EnzoRunType.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,390 +0,0 @@ -""" -Handling of sets of EnzoHierarchy objects - -Largely deprecated. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * -import ConfigParser, time, os, sys - -class EnzoRun: - """ - A class that is used to hold the information about an entire Enzo - Simulation. This includes all of the datadumps, the parameter file, - and possibly even the initial conditions. - """ - def __init__(self, metaData, outputs=None, runFilename=None, classType=EnzoHierarchy, timeID=None, getPFs = True): - """ - We're going to try to avoid setting too many of the parameters here, - as many will be changed on and off. However, we can definitely set all - of the parameters that are fixed from the initial conditions -- things - like root grid conditions, problem type, and so on. While these *may* - change during the run (for instance, changing to SN problem type) they - won't do so without quite a bit of effort on the part of the user, and - we thus don't quite have to care about them too much. - - This is primarily a storage container. If we open it up, and add to - it all of our datadumps, we can snag lots of fun information from them - all. - - @param metaData: text describing the run as a whole. - @type metaData: string - @keyword outputs: outputs to add to the run - @type outputs: list of L{EnzoHierarchies} - """ - if outputs == None: outputs = [] - self.metaData = metaData - self.classType = classType - self.outputs = obj.array(outputs) # Object array of EnzoHierarchies - self.timesteps = na.zeros(shape=self.outputs.shape, dtype=nT.Float64) # Timesteps - self.runFilename = runFilename - self.gotRuns = False - if runFilename != None and getPFs: - self.Import(runFilename) - if not timeID: - timeID = int(time.time()) - self.timeID = timeID - - def promoteType(self, outputID): - if hasattr(self.outputs[outputID], "grids"): - return - pp = self.outputs[outputID] - pf_name = os.path.join(pp.fullpath, pp.basename) - self.outputs[outputID] = EnzoHierarchy(pf_name) - del pp - - def demoteType(self, outputID): - if not hasattr(self.outputs[outputID], "grids"): - return - pp = self.outputs[outputID] - pf_name = os.path.join(pp.fullpath, pp.basename) - self.outputs[outputID] = EnzoParameterFile(pf_name) - del pp - - def sortOutputs(self): - """ - Sorts outputs, solely by the time at which they were created. - - Note that this may not be what we want -- we may actually want the time - in the simulation at which they were dumped. - """ - order = na.argsort(self.timesteps) - self.outputs = self.outputs[order] - self.timesteps = self.timesteps[order] - - def addOutput(self, hierarchy): - """ - Add an output. Also, sorts. - - @param hierarchy: either a single hierarchy or a list of hierarchies - @type hierarchy: L{EnzoHierarchy} - """ - if not isinstance(hierarchy, types.ListType): - hierarchy = [hierarchy] - # Our arrays are both one-d, so we'll just extend them - t = [] - for h in hierarchy: - t.append(h["InitialTime"]) - self.outputs = obj.array(self.outputs.tolist() + hierarchy) - self.timesteps=na.array(self.timesteps.tolist() + t,dtype=nT.Float64) - self.sortOutputs() - self.gotRuns = True - - def addOutputByFilename(self, filename, hdf_version=4): - """ - Feed it a list of parameter files, andi t will add 'em all - - @param filename: either a single filename or a list of filenames - @keyword hdf_version: version of hdf to use - @type hdf_version: int - """ - if not isinstance(filename, types.ListType): - filename = [filename] - k = [] - for fn in filename: - mylog.debug("Adding %s to EnzoRun '%s'", fn, self.metaData) - k.append(self.classType(fn, hdf_version=hdf_version)) - k[-1].run = self - self.addOutput(k) - - def getCommandLine(self): - return "./enzo_red_i9_r16" - - def getTime(self): - return time.ctime(float(self.timeID)) - - - def runFunction(self, func, args, fmt_string = None): - """ - Here we can call runFunction, feeding it a function and some arguments. - - The function will be called with every EnzoHierarchy as the first - argument, and the *args as the rest of the arguments. - - @param func: function handler to be called for every EnzoHierarchy - note that it will be called as such: - func(EnzoHierarchy, [fmt_string % index], *args) - @type func: function - @param args: a list of arguments to pass in - @type args: list - @param fmt_string: this is an optional argument, which will be %'d - against the index of the parameter file. Note that - it is only %'d against the *index*, so even if the - thing is called DataDump1042, if it's the first one, it'll get 0. - @type fmt_string: string - """ - if not isinstance(args, types.ListType): - args = [args] - for i in range(self.outputs.shape[0]): - pid = os.fork() - if pid: - newpid, exit = os.wait() - mylog.info("Exit status %s from PID %s", exit, newpid) - else: - mylog.debug("Forked process reporting for duty") - self.promoteType(i) - a = [self.outputs[i]] - if fmt_string != None: - s = fmt_string % i - a += [s] - a += args - mylog.debug("Calling %s on %s", func.func_name, a[0].parameterFilename) - func(*a) - mylog.debug("Done calling %s, now dying", func.func_name) - sys.exit() - - def getBefore(self, time): - return na.where(self.timesteps <= time)[0] - - def getAfter(self, time): - return na.where(self.timesteps > time)[0] - - def removeOutput(self, key): - pp = self[key] - id = self.index(key) - # Okay, I know this sucks, but, it seems to be the only way, since - # concatenate doesn't want to work with ObjectArrays - newOutputs = obj.array(self.outputs[:id].tolist() + self.outputs[id+1:].tolist()) - newTimesteps = obj.array(self.timesteps[:id].tolist() + self.timesteps[id+1:].tolist()) - self.outputs = newOutputs - self.timesteps = newTimesteps - del pp, newOutputs, newTimesteps - - def removeOutputFiles(self, outputID): - """ - This function handles things a bit more simply than - removeOutputFilesByGrid, in that it tosses everything over to fido. - This *deletes* files. Note that this can be DANGEROUS. Use with care. - - @param outputID: the ID or basename of the parameter file to toast - @type outputID: int or string - """ - import yt.fido - mylog.info("Deleting %s" % (self[outputID].fullpath)) - #yt.fido.deleteFiles(self.outputs[outputID].fullpath, \ - #os.path.basename(self.outputs[outputID].parameterFilename)) - yt.fido.deleteOutput(self[outputID].fullpath) - - def moveOutput(self, outputID, dest): - """ - This moves a data directory tree to another location. This assumes the - data is already buried. - - @param outputID: the output we want to move - @type outputID: integer - @param dest: the basename of the new location - @type dest: string - """ - import yt.fido - pf = self[outputID] - mylog.info("Moving %s to %s", os.path.basename(pf.fullpath), \ - dest) - pf.fullpath = yt.fido.moveOutput(pf.fullpath, os.path.abspath(dest)) - - def moveOutputFiles(self, outputID, dest): - import yt.fido - pf = self[outputID] - mylog.info("Moving %s to %s", os.path.basename(pf.fullpath), \ - dest) - yt.fido.moveFiles(os.path.abspath(dest), \ - os.path.basename(pf.parameterFilename), \ - extraFiles = [], wd=pf.directory) - - def removeOutputFilesByGrid(self, outputID): - """ - This function deletes all the files associated with a given parameter - file, and then the instance itself. I am of two minds here; do we want - to execute the costly operation of removing each file associated with - the hierarchy instance, or do we want to just kill 'em all off via a - system command? - - @param outputID: the ID of the parameter file to toast - @type outputID: int - @deprecated: Use removeOutputFiles - """ - run = self.outputs[outputID] - for grid in run.grids: - mylog.debug("Deleting %s", grid.filename) - os.unlink(grid.filename) - mylog.debug("Deleting parameter file %s", run.parameterFilename) - os.unlink(run.parameterFilename) - mylog.debug("Deleting hierarchy %s", run.hierarchyFilename) - os.unlink(run.hierarchyFilename) - mylog.debug("Deleting boundary %s", run.boundaryFilename) - os.unlink(run.boundaryFilename) - mylog.debug("Deleting boundary.hdf %s", run.boundaryFilename+".hdf") - os.unlink(run.boundaryFilename+".hdf") - mylog.debug("Deleted everything, I think") - - def Export(self, nn): - """ - This function returns a ConfigParser object that describes the enough - that it can be resurrected at a later date. - - @return: ConfigParser - """ - cfg = ConfigParser.ConfigParser() - if os.path.exists(nn): - cfg.read(nn) - if not cfg.has_section("RunInformation"): - cfg.add_section("RunInformation") - cfg.set("RunInformation","MetaData",self.metaData) - cfg.set("RunInformation","User", os.getenv("USER")) - cfg.set("RunInformation","ExportTime", time.ctime()) - # Hm, I guess that's all we need for the metadata... - # Now the question, really, is going to be how do we handle the data - # listings? - self.UpdateOutputs(cfg) - return cfg - - def Import(self, filename): - """ - Here we read in an EnzoRun file and import the parameter files - @param filename: the run filename - @type filename: string - """ - cc = ConfigParser.ConfigParser() - cc.read(filename) - self.metaData = cc.get("RunInformation","MetaData") - new_outputs = [] - for sec in cc.sections(): - if sec.startswith("Output"): - # Okay, so it's an output, now what? - d = cc.get(sec,"Directory") - f = cc.get(sec,"Basename") - new_outputs.append(os.path.join(d,f)) - self.gotRuns = True - self.addOutputByFilename(new_outputs) - - def UpdateOutputs(self, cfg): - """ - This function accepts a filename, and will update the ConfigParser - object corresponding to that filename, ensuring that all outputs I{currently} - associated with the run instance are in the file. (It does this by - I{deleting} the [Outputs] section, by the way, and re-initializing it.) - @param cfg: The filename or ConfigParser object to update - @type cfg: string or instantiated ConfigParser - """ - if isinstance(cfg, types.StringType): - # We open the file, and we will write to it when done - cc = ConfigParser.ConfigParser() - cc.read(cfg) - toWrite = True - else: - # Assume it is a ConfigParser object, and let exception get thrown - # otherwise. - cc = cfg - toWrite = False - for sec in cc.sections(): - if sec.startswith("Output"): - cc.remove_section(sec) - num = self.outputs.shape[0] - otherParams=ytcfg.get("Fido","OtherParamsToStore").split(",") - for i in range(num): - n = "Output%04i" % (i) - cc.add_section(n) - cc.set(n,"CurrentTimeIdentifier",self.outputs[i]["CurrentTimeIdentifier"]) - cc.set(n,"Directory",self.outputs[i].fullpath) - cc.set(n,"Basename",self.outputs[i].basename) - for op in otherParams: - if self.outputs[i].has_key(op): - cc.set(n,op,self.outputs[i][op]) - if toWrite: - cc.write(cfg) - # We return *nothing*, because we either modify the ConfigParser in - # place or we update and write out - - def __getitem__(self, key): - """ - Based on the type of input, we either return based on index or - basename. - """ - if isinstance(key, types.StringType): - index = self.index(key) - elif isinstance(key, types.IntType): - index = key - return self.outputs[index] - - def index(self, key): - t = os.path.basename(key) - # Find out the index - index = None - for i in range(self.outputs.shape[0]): - if self.outputs[i].basename == t: - index = i - break - if index == None: - raise KeyError - return index - - def getOutputs(self): - if not self.gotRuns: - self.Import(self.runFilename) - return self.outputs.tolist() - - def __xattrs__(self, mode="default"): - return("metaData", "getTime()") - - def __repr__(self): - return self.metaData - - def __len__(self): - if not self.gotRuns: - self.Import(self.runFilename) - return self.outputs.shape[0] - - def __iter__(self): - if not self.gotRuns: - self.Import(self.runFilename) - for i in range(len(self)): - yield self.outputs[i] - - def keys(self): - """ - Returns a list of parameterfile basenames - """ - keys = [] - for i in range(self.outputs.shape[0]): - keys.append(self.outputs[i].basename) - return keys diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/FLASHFields.py --- a/yt/lagos/FLASHFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -""" -Chombo-specific fields - -Author: J. S. Oishi -Affiliation: UC Berkeley -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 J. S. Oishi, 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 . -""" - -from UniversalFields import * -class FLASHFieldContainer(CodeFieldInfoContainer): - _shared_state = {} - _field_list = {} -FLASHFieldInfo = FLASHFieldContainer() -add_flash_field = FLASHFieldInfo.add_field - -add_field = add_flash_field - -# Common fields in FLASH: (Thanks to John ZuHone for this list) -# -# dens gas mass density (g/cc) -- -# eint internal energy (ergs/g) -- -# ener total energy (ergs/g), with 0.5*v^2 -- -# gamc gamma defined as ratio of specific heats, no units -# game gamma defined as in , no units -# gpol gravitational potential from the last timestep (ergs/g) -# gpot gravitational potential from the current timestep (ergs/g) -# grac gravitational acceleration from the current timestep (cm s^-2) -# pden particle mass density (usually dark matter) (g/cc) -# pres pressure (erg/cc) -# temp temperature (K) -- -# velx velocity x (cm/s) -- -# vely velocity y (cm/s) -- -# velz velocity z (cm/s) -- - -translation_dict = {"x-velocity": "velx", - "y-velocity": "vely", - "z-velocity": "velz", - "Density": "dens", - "Total_Energy": "ener", - "Gas_Energy": "eint", - "Temperature": "temp", - } - -def _generate_translation(mine, theirs): - add_field(theirs, function=lambda a, b: b[mine], take_log=True) - -for f,v in translation_dict.items(): - if v not in FLASHFieldInfo: - add_field(v, function=lambda a,b: None, take_log=False, - validators = [ValidateDataField(v)]) - #print "Setting up translator from %s to %s" % (v, f) - _generate_translation(v, f) - -add_field("gamc", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("gamc")], - units = r"\rm{ratio\/of\/specific\/heats}") - -add_field("game", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("game")], - units = r"\rm{ratio\/of\/specific\/heats}") - -add_field("gpot", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("gpot")], - units = r"\rm{ergs\//\/g}") - -add_field("gpol", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("gpol")], - units = r"\rm{ergs\//\/g}") - -add_field("grac", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("grac")], - units = r"\rm{cm\/s^{-2}}") - -add_field("pden", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("pden")], - units = r"\rm{g}\//\/\rm{cm}^{3}") - -add_field("pres", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("pres")], - units = r"\rm{erg}\//\/\rm{cm}^{3}") - -add_field("magx", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("magx")], - units = r"\rm{G}") - -add_field("magy", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("magy")], - units = r"\rm{G}") - -add_field("magz", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("magz")], - units = r"\rm{G}") - -add_field("magp", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("magp")], - units = r"\rm{erg}\//\/\rm{cm}^{3}") - -add_field("divb", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("divb")], - units = r"\rm{G}\/\rm{cm}") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/GadgetFields.py --- a/yt/lagos/GadgetFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -""" -Gadget-specific fields - -Author: Christopher E Moody -Affiliation: UC Santa Cruz -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2010 Christopher E Moody, 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 . -""" - -from UniversalFields import * -class GadgetFieldContainer(CodeFieldInfoContainer): - _shared_state = {} - _field_list = {} -GadgetFieldInfo = GadgetFieldContainer() -add_gadget_field = GadgetFieldInfo.add_field - -add_field = add_gadget_field - -translation_dict = {"Position": "POS", - "Velocity": "VEL", - "ID": "ID", - "Mass":"MASS" - } - -#for f,v in translation_dict.items(): -# add_field(f, function=lambda a,b: None, take_log=True, -# validators = [ValidateDataField(v)], -# units=r"\rm{cm}") -# add_field(v, function=lambda a,b: None, take_log=True, -# validators = [ValidateDataField(v)], -# units=r"\rm{cm}") - - -add_field("Density", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("POS")], - units=r"\rm{cm}") - -add_field("VEL", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("VEL")], - units=r"") - -add_field("ID", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("ID")], - units=r"") - -add_field("MASS", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("MASS")], - units=r"\rm{g}") - -add_field("U", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("U")], - units=r"") - -add_field("NE", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("NE")], - units=r"") - -add_field("POT", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("POT")], - units=r"") - -add_field("ACCE", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("ACCE")], - units=r"") - -add_field("ENDT", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("ENDT")], - units=r"") - -add_field("TSTP", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("TSTP")], - units=r"") - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/HDF5LightReader.c --- a/yt/lagos/HDF5LightReader.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1782 +0,0 @@ -/************************************************************************ -* Copyright (C) 2007-2009 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 . -* -************************************************************************/ - - -// -// HDF5_LightReader -// A module for light-weight reading of HDF5 files -// - -#include "Python.h" - -#include -#include -#include -#include -#include "hdf5.h" - -#include "numpy/ndarrayobject.h" - -#ifndef npy_float128 -#define npy_float128 npy_longdouble -#endif - - -static PyObject *_hdf5ReadError; -herr_t iterate_dataset(hid_t loc_id, const char *name, void *nodelist); - -/* Structures for particle reading */ - -typedef struct particle_validation_ { - int total_valid_particles; - int particles_to_check; - int nread; - int stride_size; - int *mask; - int update_count; - int nfields; - char **field_names; - PyArrayObject *conv_factors; - PyArrayObject **return_values; - int *npy_types; - int (*count_func)(struct particle_validation_ *data); - int (*count_func_float)(struct particle_validation_ *data); - int (*count_func_double)(struct particle_validation_ *data); - int (*count_func_longdouble)(struct particle_validation_ *data); - void *validation_reqs; - void *particle_position[3]; - hid_t file_id; - char filename[1024]; -} particle_validation; - -typedef struct region_validation_ { - /* These cannot contain any pointers */ - npy_float64 left_edge[3]; - npy_float64 right_edge[3]; - npy_float64 period[3]; - int periodic; -} region_validation; - -typedef struct sphere_validation_ { - /* These cannot contain any pointers */ - npy_float64 center[3]; - npy_float64 radius; -} sphere_validation; - -typedef struct cylinder_validation_ { - /* These cannot contain any pointers */ - npy_float64 center[3]; - npy_float64 normal[3]; - npy_float64 radius; - npy_float64 height; -} cylinder_validation; - -/* Forward declarations */ -int setup_validator_region(particle_validation *data, PyObject *InputData); -int setup_validator_sphere(particle_validation *data, PyObject *InputData); -int setup_validator_cylinder(particle_validation *data, PyObject *InputData); -int run_validators(particle_validation *pv, char *filename, - int grid_id, const int read, const int packed, - int grid_index); - -/* Different data type validators */ - -int count_particles_region_FLOAT(particle_validation *data); -int count_particles_region_DOUBLE(particle_validation *data); -int count_particles_region_LONGDOUBLE(particle_validation *data); - -int count_particles_sphere_FLOAT(particle_validation *data); -int count_particles_sphere_DOUBLE(particle_validation *data); -int count_particles_sphere_LONGDOUBLE(particle_validation *data); - -int count_particles_cylinder_FLOAT(particle_validation *data); -int count_particles_cylinder_DOUBLE(particle_validation *data); -int count_particles_cylinder_LONGDOUBLE(particle_validation *data); - -int get_my_desc_type(hid_t native_type_id){ - - /* - http://terra.rice.edu/comp.res/apps/h/hdf5/docs/RM_H5T.html#Datatype-GetNativeType - - hid_t H5Tget_native_type(hid_t type_id, H5T_direction_t direction ) returns - from the following list: - H5T_NATIVE_CHAR NPY_?? - H5T_NATIVE_SHORT NPY_SHORT - H5T_NATIVE_INT NPY_INT - H5T_NATIVE_LONG NPY_LONG - H5T_NATIVE_LLONG NPY_LONGLONG - - H5T_NATIVE_UCHAR NPY_?? - H5T_NATIVE_USHORT NPY_USHORT - H5T_NATIVE_UINT NPY_UINT - H5T_NATIVE_ULONG NPY_ULONG - H5T_NATIVE_ULLONG NPY_ULONGLONG - - H5T_NATIVE_FLOAT NPY_FLOAT - H5T_NATIVE_DOUBLE NPY_DOUBLE - H5T_NATIVE_LDOUBLE NPY_LONGDOUBLE - */ - - if(H5Tequal(native_type_id, H5T_NATIVE_SHORT ) > 0){return NPY_SHORT;} - else if(H5Tequal(native_type_id, H5T_NATIVE_INT ) > 0){return NPY_INT;} - else if(H5Tequal(native_type_id, H5T_NATIVE_LONG ) > 0){return NPY_LONG;} - else if(H5Tequal(native_type_id, H5T_NATIVE_LLONG ) > 0){return NPY_LONGLONG;} - else if(H5Tequal(native_type_id, H5T_NATIVE_USHORT ) > 0){return NPY_USHORT;} - else if(H5Tequal(native_type_id, H5T_NATIVE_UINT ) > 0){return NPY_UINT;} - else if(H5Tequal(native_type_id, H5T_NATIVE_ULONG ) > 0){return NPY_ULONG;} - else if(H5Tequal(native_type_id, H5T_NATIVE_ULLONG ) > 0){return NPY_ULONGLONG;} - else if(H5Tequal(native_type_id, H5T_NATIVE_FLOAT ) > 0){return NPY_FLOAT;} - else if(H5Tequal(native_type_id, H5T_NATIVE_DOUBLE ) > 0){return NPY_DOUBLE;} - else if(H5Tequal(native_type_id, H5T_NATIVE_LDOUBLE ) > 0){return NPY_LONGDOUBLE;} - else {return -1;} - -} - -static PyObject * -Py_ReadHDF5DataSet(PyObject *obj, PyObject *args) -{ - char *filename, *nodename; - - char *dspacename = NULL; - hsize_t *my_dims = NULL; - hsize_t *my_max_dims = NULL; - npy_intp *dims = NULL; - hid_t file_id, datatype_id, native_type_id, dataset, dataspace, dsetr, - memspace; - herr_t my_error; - htri_t file_exists; - size_t type_size; - int my_rank, i; - H5E_auto_t err_func; - void *err_datastream; - PyArrayObject *my_array = NULL; - file_id = datatype_id = native_type_id = dataset = 0; - dataspace = 0; - - if (!PyArg_ParseTuple(args, "ss|s", - &filename, &nodename, &dspacename)) - return PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Invalid parameters."); - - /* How portable is this? */ - if (access(filename, R_OK) < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: %s does not exist, or no read permissions\n", - filename); - goto _fail; - } - - file_exists = H5Fis_hdf5(filename); - if (file_exists == 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: %s is not an HDF5 file", filename); - goto _fail; - } - - file_id = H5Fopen (filename, H5F_ACC_RDONLY, H5P_DEFAULT); - - if (file_id < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unable to open %s", filename); - goto _fail; - } - - dsetr = -1; - if(dspacename != NULL){ - /*fprintf(stderr, "Getting dspace %s\n", dspacename);*/ - dsetr = H5Dopen(file_id, dspacename); - } - - /* We turn off error reporting briefly, because it turns out that - reading datasets with group names is more forgiving than finding - datasets with group names using the high-level interface. */ - - H5Eget_auto(&err_func, &err_datastream); - H5Eset_auto(NULL, NULL); - dataset = H5Dopen(file_id, nodename); - H5Eset_auto(err_func, err_datastream); - - if(dataset < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unable to open dataset (%s, %s).", - filename, nodename); - goto _fail; - } - - if(dsetr >= 0) { - hdset_reg_ref_t reference[1]; - my_error = H5Dread(dsetr, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, - H5P_DEFAULT, reference); - if(my_error < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unable to read particle reference (%s, %s, %s).", - filename, nodename, dspacename); - goto _fail; - } - H5Dclose(dsetr); - dataspace = H5Rget_region(file_id, H5R_DATASET_REGION, reference); - if(dataspace < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unable to dereference particle dataspace (%s, %s).", - filename, nodename); - goto _fail; - } - my_rank = 1; - /* How do we keep this from leaking in failures? */ - my_dims = malloc(sizeof(hsize_t) * my_rank); - my_max_dims = malloc(sizeof(hsize_t) * my_rank); - my_dims[0] = my_max_dims[0] = H5Sget_select_npoints(dataspace); - } else { - dataspace = H5Dget_space(dataset); - if(dataspace < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unable to open dataspace (%s, %s).", - filename, nodename); - goto _fail; - } - my_rank = H5Sget_simple_extent_ndims( dataspace ); - if(my_rank < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Problem getting dataset rank (%s, %s).", - filename, nodename); - goto _fail; - } - - /* How do we keep this from leaking in failures? */ - my_dims = malloc(sizeof(hsize_t) * my_rank); - my_max_dims = malloc(sizeof(hsize_t) * my_rank); - my_error = H5Sget_simple_extent_dims( dataspace, my_dims, my_max_dims ); - if(my_error < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Problem getting dataset dimensions (%s, %s).", - filename, nodename); - goto _fail; - } - } - dims = malloc(my_rank * sizeof(npy_intp)); - for (i = 0; i < my_rank; i++) dims[i] = (npy_intp) my_dims[i]; - - datatype_id = H5Dget_type(dataset); - native_type_id = H5Tget_native_type(datatype_id, H5T_DIR_ASCEND); - type_size = H5Tget_size(native_type_id); - - /* Behavior here is intentionally undefined for non-native types */ - - int my_desc_type = get_my_desc_type(native_type_id); - if (my_desc_type == -1) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unrecognized datatype. Use a more advanced reader."); - goto _fail; - } - - my_array = (PyArrayObject *) PyArray_SimpleNewFromDescr(my_rank, dims, - PyArray_DescrFromType(my_desc_type)); - if (!my_array) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unable to create NumPy array."); - - goto _fail; - } - memspace = H5Screate_simple(my_rank, my_dims, NULL); - /*fprintf(stderr, "Total Selected: %s %d %d %d\n", - dspacename, - (int) H5Sget_select_npoints(memspace), - (int) H5Sget_select_npoints(dataspace), - (int) my_rank);*/ - - H5Dread(dataset, native_type_id, memspace, dataspace, H5P_DEFAULT, my_array->data); - - PyArray_UpdateFlags(my_array, NPY_OWNDATA | my_array->flags); - PyObject *return_value = Py_BuildValue("N", my_array); - - H5Sclose(dataspace); - H5Sclose(memspace); - H5Dclose(dataset); - H5Tclose(native_type_id); - H5Tclose(datatype_id); - H5Fclose(file_id); - free(my_dims); - free(my_max_dims); - free(dims); - - return return_value; - - _fail: - Py_XDECREF(my_array); - if(!(file_id <= 0)&&(H5Iget_ref(file_id))) H5Fclose(file_id); - if(!(dataset <= 0)&&(H5Iget_ref(dataset))) H5Dclose(dataset); - if(!(dataspace <= 0)&&(H5Iget_ref(dataspace))) H5Sclose(dataspace); - if(!(native_type_id <= 0)&&(H5Iget_ref(native_type_id))) H5Tclose(native_type_id); - if(!(datatype_id <= 0)&&(H5Iget_ref(datatype_id))) H5Tclose(datatype_id); - if(my_dims != NULL) free(my_dims); - if(my_max_dims != NULL) free(my_max_dims); - if(dims != NULL) free(dims); - return NULL; -} - -static PyObject * -Py_ReadHDF5DataSetSlice(PyObject *obj, PyObject *args) -{ - char *filename, *nodename; - - hsize_t *my_dims = NULL; - hsize_t *my_max_dims = NULL; - npy_intp *dims = NULL; - hid_t file_id, datatype_id, native_type_id, dataset, dataspace, memspace; - herr_t my_error; - htri_t file_exists; - int my_rank, i, axis, coord; - H5E_auto_t err_func; - void *err_datastream; - PyArrayObject *my_array = NULL; - file_id = datatype_id = native_type_id = dataset = dataspace = memspace = 0; - - if (!PyArg_ParseTuple(args, "ssII", - &filename, &nodename, &axis, &coord)) - return PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Invalid parameters."); - - /* How portable is this? */ - if (access(filename, R_OK) < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: %s does not exist, or no read permissions\n", - filename); - goto _fail; - } - - file_exists = H5Fis_hdf5(filename); - if (file_exists == 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: %s is not an HDF5 file", filename); - goto _fail; - } - - file_id = H5Fopen (filename, H5F_ACC_RDONLY, H5P_DEFAULT); - - if (file_id < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Unable to open %s", filename); - goto _fail; - } - - /* We turn off error reporting briefly, because it turns out that - reading datasets with group names is more forgiving than finding - datasets with group names using the high-level interface. */ - - H5Eget_auto(&err_func, &err_datastream); - H5Eset_auto(NULL, NULL); - dataset = H5Dopen(file_id, nodename); - H5Eset_auto(err_func, err_datastream); - - if(dataset < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Unable to open dataset (%s, %s).", - filename, nodename); - goto _fail; - } - dataspace = H5Dget_space(dataset); - if(dataspace < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Unable to open dataspace (%s, %s).", - filename, nodename); - goto _fail; - } - - my_rank = H5Sget_simple_extent_ndims( dataspace ); - if(my_rank!=3) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Sorry, I only know how to slice 3D into 2D."); - goto _fail; - } - - /* How do we keep this from leaking in failures? */ - my_dims = malloc(sizeof(hsize_t) * my_rank); - my_max_dims = malloc(sizeof(hsize_t) * my_rank); - my_error = H5Sget_simple_extent_dims( dataspace, my_dims, my_max_dims ); - if(my_error < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Problem getting dataset info (%s, %s).", - filename, nodename); - goto _fail; - } - - dims = malloc(my_rank * sizeof(npy_intp)); - for (i = 0; i < my_rank; i++) dims[i] = (npy_intp) my_dims[i]; - - datatype_id = H5Dget_type(dataset); - native_type_id = H5Tget_native_type(datatype_id, H5T_DIR_ASCEND); - - /* Behavior here is intentionally undefined for non-native types */ - - int my_desc_type = get_my_desc_type(native_type_id); - if (my_desc_type == -1) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Unrecognized datatype. Use a more advanced reader."); - goto _fail; - } - - /* Okay, now let's figure out what the dataspaces will look like */ - - hsize_t slice_coords[3] = {0, 0, 0}; - slice_coords[axis] = coord; - hsize_t slice_blocks[3] = {dims[0], dims[1], dims[2]}; - slice_blocks[axis] = 1; - - my_error = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, slice_coords, NULL, - slice_blocks, NULL); - if(my_error) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Problem selecting hyperslab."); - goto _fail; - } - - hsize_t slice_dims[2]; - int j = 0; - for (i=0;i<3;i++)if(i!=axis)slice_dims[j++]=dims[i]; - memspace = H5Screate_simple(2,slice_dims,NULL); - - npy_intp slice_dims_i[2] = {slice_dims[0], slice_dims[1]}; - my_array = (PyArrayObject *) PyArray_SimpleNewFromDescr(2, slice_dims_i, - PyArray_DescrFromType(my_desc_type)); - if (!my_array) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSetSlice: Unable to create NumPy array."); - goto _fail; - } - - my_error = H5Dread(dataset, native_type_id, memspace, dataspace, H5P_DEFAULT, - my_array->data); - - PyArray_UpdateFlags(my_array, NPY_OWNDATA | my_array->flags); - PyObject *return_value = Py_BuildValue("N", my_array); - - H5Fclose(file_id); - H5Dclose(dataset); - H5Sclose(dataspace); - H5Sclose(memspace); - H5Tclose(native_type_id); - H5Tclose(datatype_id); - free(my_dims); - free(my_max_dims); - free(dims); - - return return_value; - - _fail: - Py_XDECREF(my_array); - if(!(file_id <= 0)&&(H5Iget_ref(file_id))) H5Fclose(file_id); - if(!(dataset <= 0)&&(H5Iget_ref(dataset))) H5Dclose(dataset); - if(!(dataspace <= 0)&&(H5Iget_ref(dataspace))) H5Sclose(dataspace); - if(!(memspace <= 0)&&(H5Iget_ref(memspace))) H5Sclose(memspace); - if(!(native_type_id <= 0)&&(H5Iget_ref(native_type_id))) H5Tclose(native_type_id); - if(!(datatype_id <= 0)&&(H5Iget_ref(datatype_id))) H5Tclose(datatype_id); - if(my_dims != NULL) free(my_dims); - if(my_max_dims != NULL) free(my_max_dims); - if(dims != NULL) free(dims); - return NULL; - -} - -static PyObject * -Py_ReadListOfDatasets(PyObject *obj, PyObject *args) -{ - char *filename, *nodename; - - hid_t file_id; - herr_t my_error; - htri_t file_exists; - file_id = 0; - - if (!PyArg_ParseTuple(args, "ss", - &filename, &nodename)) - return PyErr_Format(_hdf5ReadError, - "ReadListOfDatasets: Invalid parameters."); - - /* How portable is this? */ - if (access(filename, R_OK) < 0) { - PyErr_Format(_hdf5ReadError, - "ReadListOfDatasets: %s does not exist, or no read permissions\n", - filename); - goto _fail; - } - - file_exists = H5Fis_hdf5(filename); - if (file_exists == 0) { - PyErr_Format(_hdf5ReadError, - "ReadListOfDatasets: %s is not an HDF5 file", filename); - goto _fail; - } - - file_id = H5Fopen (filename, H5F_ACC_RDONLY, H5P_DEFAULT); - PyObject *nodelist = PyList_New(0); - if (nodelist == NULL) { - PyErr_Format(_hdf5ReadError, - "ReadListOfDatasets: List couldn't be made!"); - goto _fail; - } - - my_error = H5Giterate(file_id, nodename, NULL, iterate_dataset, (void *) nodelist); - H5Fclose(file_id); - if (my_error) { - PyErr_Format(_hdf5ReadError, - "ReadListOfDatasets: Problem iterating over HDF5 set."); - goto _fail; - } - - PyObject *return_value = Py_BuildValue("N", nodelist); - return return_value; - - _fail: - Py_XDECREF(nodelist); - if(!(file_id <= 0)&&(H5Iget_ref(file_id))) H5Fclose(file_id); - return NULL; - -} - -herr_t iterate_dataset(hid_t loc_id, const char *name, void *nodelist) -{ - H5G_stat_t statbuf; - PyObject* node_name; - - H5Gget_objinfo(loc_id, name, 0, &statbuf); - if (statbuf.type == H5G_DATASET) { - node_name = PyString_FromString(name); - if (node_name == NULL) {return -1;} - if (PyList_Append((PyObject *)nodelist, node_name)) {return -1;} - } - return 0; -}; - -PyArrayObject* get_array_from_nodename(char *nodename, hid_t rootnode); - -static PyObject * -Py_ReadMultipleGrids(PyObject *obj, PyObject *args) -{ - // Process: - // - Create dict to hold data - // - Open each top-level node in order - // - For each top-level node create a dictionary - // - Insert new dict in top-level dict - // - Read each dataset, insert into dict - - // Format arguments - - char *filename = NULL; - PyObject *grid_ids = NULL; - PyObject *set_names = NULL; - Py_ssize_t num_sets = 0; - Py_ssize_t num_grids = 0; - - if (!PyArg_ParseTuple(args, "sOO", - &filename, &grid_ids, &set_names)) - return PyErr_Format(_hdf5ReadError, - "ReadMultipleGrids: Invalid parameters."); - - num_grids = PyList_Size(grid_ids); - num_sets = PyList_Size(set_names); - PyObject *grids_dict = PyDict_New(); // New reference - PyObject *grid_key = NULL; - PyObject *grid_data = NULL; - PyObject *oset_name = NULL; - PyArrayObject *cur_data = NULL; - char *set_name; - hid_t file_id, grid_node; - file_id = grid_node = 0; - int i, n; - long id; - char grid_node_name[13]; // Grid + 8 + \0 - - /* Similar to the way Enzo does it, we're going to set the file access - property to store bigger bits in RAM. */ - - file_id = H5Fopen (filename, H5F_ACC_RDONLY, H5P_DEFAULT); - - if (file_id < 0) { - PyErr_Format(_hdf5ReadError, - "ReadMultipleGrids: Unable to open %s", filename); - goto _fail; - } - - for(i = 0; i < num_grids; i++) { - grid_key = PyList_GetItem(grid_ids, i); - id = PyInt_AsLong(grid_key); - sprintf(grid_node_name, "Grid%08li", id); - grid_data = PyDict_New(); // New reference - PyDict_SetItem(grids_dict, grid_key, grid_data); - grid_node = H5Gopen(file_id, grid_node_name); - if (grid_node < 0) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Error opening (%s, %s)", - filename, grid_node_name); - goto _fail; - } - for(n = 0; n < num_sets; n++) { - // This points to the in-place internal char* - oset_name = PyList_GetItem(set_names, n); - set_name = PyString_AsString(oset_name); - cur_data = get_array_from_nodename(set_name, grid_node); - if (cur_data != NULL) { - PyDict_SetItem(grid_data, oset_name, (PyObject *) cur_data); - } - Py_XDECREF(cur_data); // still one left - } - // We just want the one reference from the grids_dict value set - Py_DECREF(grid_data); - H5Gclose(grid_node); - } - - H5Fclose(file_id); - PyObject *return_value = Py_BuildValue("N", grids_dict); - return return_value; - - _fail: - - if(!(file_id <= 0)&&(H5Iget_ref(file_id))) H5Fclose(file_id); - if(!(grid_node <= 0)&&(H5Iget_ref(grid_node))) H5Gclose(grid_node); - Py_XDECREF(grid_data); - PyDict_Clear(grids_dict); // Should catch the sub-dictionaries - return NULL; - -} - -PyArrayObject* get_array_from_nodename(char *nodename, hid_t rootnode) -{ - - H5E_auto_t err_func; - void *err_datastream; - herr_t my_error; - hsize_t *my_dims = NULL; - hsize_t *my_max_dims = NULL; - npy_intp *dims = NULL; - int my_rank, i; - size_t type_size; - PyArrayObject *my_array = NULL; - hid_t datatype_id, native_type_id, dataset, dataspace; - datatype_id = native_type_id = dataset = dataspace = 0; - - H5Eget_auto(&err_func, &err_datastream); - H5Eset_auto(NULL, NULL); - dataset = H5Dopen(rootnode, nodename); - H5Eset_auto(err_func, err_datastream); - - if(dataset < 0) goto _fail; - - dataspace = H5Dget_space(dataset); - if(dataspace < 0) goto _fail; - - my_rank = H5Sget_simple_extent_ndims( dataspace ); - if(my_rank < 0) goto _fail; - - my_dims = malloc(sizeof(hsize_t) * my_rank); - my_max_dims = malloc(sizeof(hsize_t) * my_rank); - my_error = H5Sget_simple_extent_dims( dataspace, my_dims, my_max_dims ); - if(my_error < 0) goto _fail; - - dims = malloc(my_rank * sizeof(npy_intp)); - for (i = 0; i < my_rank; i++) dims[i] = (npy_intp) my_dims[i]; - - datatype_id = H5Dget_type(dataset); - native_type_id = H5Tget_native_type(datatype_id, H5T_DIR_ASCEND); - type_size = H5Tget_size(native_type_id); - - /* Behavior here is intentionally undefined for non-native types */ - - int my_desc_type = get_my_desc_type(native_type_id); - if (my_desc_type == -1) { - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unrecognized datatype. Use a more advanced reader."); - goto _fail; - } - - // Increments the refcount - my_array = (PyArrayObject *) PyArray_SimpleNewFromDescr(my_rank, dims, - PyArray_DescrFromType(my_desc_type)); - if (!my_array) goto _fail; - - H5Dread(dataset, native_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, my_array->data); - H5Sclose(dataspace); - H5Dclose(dataset); - H5Tclose(native_type_id); - H5Tclose(datatype_id); - free(my_dims); - free(my_max_dims); - free(dims); - - PyArray_UpdateFlags(my_array, NPY_OWNDATA | my_array->flags); - return my_array; - - _fail: - if(!(dataset <= 0)&&(H5Iget_ref(dataset))) H5Dclose(dataset); - if(!(dataspace <= 0)&&(H5Iget_ref(dataspace))) H5Sclose(dataspace); - if(!(native_type_id <= 0)&&(H5Iget_ref(native_type_id))) H5Tclose(native_type_id); - if(!(datatype_id <= 0)&&(H5Iget_ref(datatype_id))) H5Tclose(datatype_id); - if(my_dims != NULL) free(my_dims); - if(my_max_dims != NULL) free(my_max_dims); - if(dims != NULL) free(dims); - return NULL; -} - -static PyObject * -Py_ReadParticles(PyObject *obj, PyObject *args) -{ - // Process: - // - Interpret arguments: - // - List of filenames - // - List of grid ids (this is Enzo HDF5-specific) - // - List of conversion factors for particles - // - Validation arguments - // - List of true/false for validation - // - Set up validation scheme - // - Iterate over grids, counting - // - Allocate array - // - Iterate over grids, turning on and off dataspace - - int source_type, ig, id, i, ifield, packed; - Py_ssize_t ngrids, nfields; - - PyObject *field_list, *filename_list, *grid_ids, *oconv_factors, *vargs; - PyArrayObject *conv_factors = NULL; - int stride_size = 10000000; - particle_validation pv; - - /* We explicitly initialize pointers to NULL to aid with failure handling */ - - vargs = field_list = filename_list = grid_ids = NULL; - pv.mask = NULL; - pv.field_names = NULL; - pv.validation_reqs = NULL; - pv.particle_position[0] = pv.particle_position[1] = pv.particle_position[2] = NULL; - pv.return_values = NULL; - pv.npy_types = NULL; - pv.file_id = -1; - - /* Set initial values for pv */ - pv.stride_size = stride_size; - pv.total_valid_particles = pv.particles_to_check = pv.nread = pv.nfields = 0; - - if (!PyArg_ParseTuple(args, "iOOOOOi", - &source_type, /* This is a non-public API, so we just take ints */ - &field_list, &filename_list, &grid_ids, &oconv_factors, &vargs, - &packed)) - return PyErr_Format(_hdf5ReadError, - "ReadParticles: Invalid parameters."); - - if (!PyList_Check(field_list)) { - PyErr_Format(_hdf5ReadError, - "ReadParticles: field_list is not a list!\n"); - goto _fail; - } - nfields = PyList_Size(field_list); - pv.nfields = nfields; - - if (!PyList_Check(filename_list)) { - PyErr_Format(_hdf5ReadError, - "ReadParticles: filename_list is not a list!\n"); - goto _fail; - } - ngrids = PyList_Size(filename_list); - - if (!PyList_Check(grid_ids) - || (PyList_Size(grid_ids) != ngrids)) { - PyErr_Format(_hdf5ReadError, - "ReadParticles: grid_ids is not a list of correct length!\n"); - goto _fail; - } - - conv_factors = (PyArrayObject *) PyArray_FromAny(oconv_factors, - PyArray_DescrFromType(NPY_FLOAT64), 2, 2, - 0, NULL); - if( (conv_factors == NULL) || - !(PyArray_DIM(conv_factors, 0) == ngrids) || - !(PyArray_DIM(conv_factors, 1) == nfields) ) { - PyErr_Format(_hdf5ReadError, - "ReadParticles: conv_factors is not an array of (ngrids, nfields)"); - goto _fail; - } - - if (!PyTuple_Check(vargs)) { - PyErr_Format(_hdf5ReadError, - "ReadParticles: vargs is not a tuple!\n"); - goto _fail; - } - - /* We've now parsed all our arguments and it is time to set up the - validator */ - - /* First initialize our particle_validation structure */ - - pv.mask = (int*) malloc(sizeof(int) * stride_size); - - switch(source_type) { - case 0: - /* Region type */ - setup_validator_region(&pv, vargs); - break; - case 1: - /* Sphere type */ - setup_validator_sphere(&pv, vargs); - break; - case 2: - /* Cylinder type */ - setup_validator_cylinder(&pv, vargs); - break; - default: - PyErr_Format(_hdf5ReadError, - "Unrecognized data source.\n"); - goto _fail; - break; - } - - /* Okay, now we open our files and stride over each grid in the files. */ - - PyObject *temp = NULL; - char *filename = NULL; - pv.update_count = 1; - pv.conv_factors = conv_factors; - - for (ig = 0; ig < ngrids ; ig++) { - temp = PyList_GetItem(filename_list, ig); - filename = PyString_AsString(temp); - temp = PyList_GetItem(grid_ids, ig); - id = PyInt_AsLong(temp); - //fprintf(stderr, "Counting from grid %d\n", id); - if(run_validators(&pv, filename, id, 0, packed, ig) < 0) { - goto _fail; - } - } - if(pv.file_id >= 0) { - H5Fclose(pv.file_id); - pv.file_id = -1; - strncpy(pv.filename, "Expired filename", 1023); - } - /* Now we know how big to make our array, hooray. */ - pv.update_count = 0; - - pv.return_values = (PyArrayObject**) malloc( - sizeof(PyArrayObject*) * nfields); - pv.npy_types = (int *) malloc(sizeof(int) * nfields); - pv.field_names = (char **) malloc( - sizeof(char *) * nfields); - for (ifield = 0; ifield < nfields; ifield++) { - pv.return_values[ifield] = NULL; - pv.npy_types[ifield] = -999; - pv.field_names[ifield] = PyString_AsString(PyList_GetItem(field_list, ifield)); - } - - /* Now we know how many particles we want. */ - - for (ig = 0; ig < ngrids ; ig++) { - /* We should have some logic here to read the entire thing - in a stride, without checking particle positions, - if it's fully-enclosed. */ - temp = PyList_GetItem(filename_list, ig); - filename = PyString_AsString(temp); - temp = PyList_GetItem(grid_ids, ig); - id = PyInt_AsLong(temp); - //fprintf(stderr, "Reading from grid %d\n", id); - if(run_validators(&pv, filename, id, 1, packed, ig) < 0) { - goto _fail; - } - } - if(pv.file_id >= 0) {H5Fclose(pv.file_id); pv.file_id = -1;} - - /* Let's pack up our return values */ - PyObject *my_list = PyList_New(pv.nfields); - for (i = 0; i < pv.nfields ; i++){ - PyList_SET_ITEM(my_list, i, (PyObject *) pv.return_values[i]); - } - PyObject *return_value = Py_BuildValue("N", my_list); - - /* Now we do some finalization */ - free(pv.mask); - free(pv.field_names); - free(pv.return_values); /* Has to happen after packing our return value */ - free(pv.npy_types); - for (i = 0; i<3; i++) { - free(pv.particle_position[i]); - } - Py_DECREF(conv_factors); - free(pv.validation_reqs); - /* We don't need to free pv */ - if(!(pv.file_id <= 0)&&(H5Iget_ref(pv.file_id))) H5Fclose(pv.file_id); - - return return_value; - - _fail: - - if(pv.mask != NULL) free(pv.mask); - if(pv.field_names != NULL) { - for (i = 0; ivalidation_reqs = (void *) rv; - - for (i = 0; i < 3; i++){ - rv->left_edge[i] = *(npy_float64*) PyArray_GETPTR1(left_edge, i); - rv->right_edge[i] = *(npy_float64*) PyArray_GETPTR1(right_edge, i); - } - - rv->periodic = PyInt_AsLong(operiodic); - if(rv->periodic == 1) { - PyArrayObject *domain_left_edge = (PyArrayObject *) PyTuple_GetItem(InputData, 3); - PyArrayObject *domain_right_edge = (PyArrayObject *) PyTuple_GetItem(InputData, 4); - for (i = 0; i < 3; i++){ - DW = (*(npy_float64*) PyArray_GETPTR1(domain_right_edge, i)) - - (*(npy_float64*) PyArray_GETPTR1(domain_left_edge, i)); - rv->period[i] = DW; - //fprintf(stderr, "Setting period equal to %lf\n", rv->period[i]); - } - } - - data->count_func = NULL; - data->count_func_float = count_particles_region_FLOAT; - data->count_func_double = count_particles_region_DOUBLE; - data->count_func_longdouble = count_particles_region_LONGDOUBLE; - - /* We need to insert more periodic logic here */ - - return 1; -} - -int setup_validator_sphere(particle_validation *data, PyObject *InputData) -{ - int i; - /* These are borrowed references */ - PyArrayObject *center = (PyArrayObject *) PyTuple_GetItem(InputData, 0); - PyObject *radius = (PyObject *) PyTuple_GetItem(InputData, 1); - - /* This will get freed in the finalization of particle validation */ - sphere_validation *sv = (sphere_validation *) - malloc(sizeof(sphere_validation)); - data->validation_reqs = (void *) sv; - - for (i = 0; i < 3; i++){ - sv->center[i] = *(npy_float64*) PyArray_GETPTR1(center, i); - } - - sv->radius = (npy_float64) PyFloat_AsDouble(radius); - - data->count_func = NULL; - data->count_func_float = count_particles_sphere_FLOAT; - data->count_func_double = count_particles_sphere_DOUBLE; - data->count_func_longdouble = count_particles_sphere_LONGDOUBLE; - - return 1; -} - -int setup_validator_cylinder(particle_validation *data, PyObject *InputData) -{ - int i; - /* These are borrowed references */ - PyArrayObject *center = (PyArrayObject *) PyTuple_GetItem(InputData, 0); - PyArrayObject *normal = (PyArrayObject *) PyTuple_GetItem(InputData, 1); - PyObject *radius = (PyObject *) PyTuple_GetItem(InputData, 2); - PyObject *height = (PyObject *) PyTuple_GetItem(InputData, 3); - - /* This will get freed in the finalization of particle validation */ - cylinder_validation *cv = (cylinder_validation *) - malloc(sizeof(cylinder_validation)); - data->validation_reqs = (void *) cv; - - for (i = 0; i < 3; i++){ - cv->center[i] = *(npy_float64*) PyArray_GETPTR1(center, i); - } - - for (i = 0; i < 3; i++){ - cv->normal[i] = *(npy_float64*) PyArray_GETPTR1(normal, i); - } - - cv->radius = (npy_float64) PyFloat_AsDouble(radius); - cv->height = (npy_float64) PyFloat_AsDouble(height); - - data->count_func = NULL; - data->count_func_float = count_particles_cylinder_FLOAT; - data->count_func_double = count_particles_cylinder_DOUBLE; - data->count_func_longdouble = count_particles_cylinder_LONGDOUBLE; - - return 1; -} - - -int run_validators(particle_validation *pv, char *filename, - int grid_id, const int read, const int packed, - int grid_index) -{ - int i, ifield, p_ind; - hid_t file_id; - hid_t dataset_x, dataset_y, dataset_z; - hid_t dataspace, memspace; - hid_t datatype_id, native_type_id; - hid_t rdatatype_id, rnative_type_id; - char name_x[255], name_y[255], name_z[255]; - hsize_t num_part_this_grid; - hsize_t current_pos = 0; - hsize_t num_particles_to_read = 0; - hid_t *dataset_read; - dataset_read = NULL; - npy_float64 *cfactors = NULL; - - cfactors = (npy_float64*) malloc(pv->nfields * sizeof(npy_float64)); - - for (ifield = 0; ifield < pv->nfields; ifield++){ - cfactors[ifield] = *(npy_float64 *) PyArray_GETPTR2( - pv->conv_factors, grid_index, ifield); - } - - /* We set these to -1 to identify which haven't been used */ - file_id = dataset_x = dataset_y = dataset_z = -1; - dataspace = memspace = datatype_id = native_type_id = -1; - rdatatype_id = rnative_type_id = -1; - - if (packed == 1) { - snprintf(name_x, 254, "/Grid%08d/particle_position_x", grid_id); - snprintf(name_y, 254, "/Grid%08d/particle_position_y", grid_id); - snprintf(name_z, 254, "/Grid%08d/particle_position_z", grid_id); - } else { - snprintf(name_x, 254, "/particle_position_x"); - snprintf(name_y, 254, "/particle_position_y"); - snprintf(name_z, 254, "/particle_position_z"); - } - - /* First we open the file */ - - - if(strncmp(filename, pv->filename, 1023) != 0) { - //fprintf(stderr, "Comparison failed: %s , %s\n", filename, pv->filename); - if(pv->file_id >= 0) H5Fclose(pv->file_id); - pv->file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); - strncpy(pv->filename, filename, 1023); - //fprintf(stderr, "Setting: %s , %s\n", filename, pv->filename); - } - file_id = pv->file_id; - if (file_id < 0) { - PyErr_Format(_hdf5ReadError, - "run_validators: Unable to open %s (%d)", filename, read); - goto _fail; - } - - /* Figure out the size of our array */ - - /* Note that we are using one dimension, not multiple. If you're using - Enzo data with multiple particle dimensions, well, I'm afraid I can't help you. - Just now, at least. */ - - dataset_x = H5Dopen(file_id, name_x); - dataset_y = H5Dopen(file_id, name_y); - dataset_z = H5Dopen(file_id, name_z); - - dataspace = H5Dget_space(dataset_x); - num_part_this_grid = H5Sget_simple_extent_npoints(dataspace); - - /* Let's get the information about the datatype now */ - datatype_id = H5Dget_type(dataset_x); - native_type_id = H5Tget_native_type(datatype_id, H5T_DIR_ASCEND); - - /* If the count function is not set, set it and allocate arrays */ - if(pv->count_func == NULL){ - int typesize = 0; - if(H5Tequal(native_type_id, H5T_NATIVE_FLOAT) > 0) { - pv->count_func = pv->count_func_float; - typesize = sizeof(float); - } else if (H5Tequal(native_type_id, H5T_NATIVE_DOUBLE) > 0 ) { - pv->count_func = pv->count_func_double; - typesize = sizeof(double); - } else if (H5Tequal(native_type_id, H5T_NATIVE_LDOUBLE) > 0 ) { - pv->count_func = pv->count_func_longdouble; - typesize = sizeof(long double); - } else { - H5Tclose(datatype_id); H5Tclose(native_type_id); - PyErr_Format(_hdf5ReadError, - "ReadHDF5DataSet: Unrecognized particle position array type"); - goto _fail; - } - /* We allocate arrays here */ - for(i = 0; i < 3; i++) - pv->particle_position[i] = malloc(pv->stride_size * typesize); - } - - if(read == 1) { - /* We allocate space for the to-read datasets */ - dataset_read = (hid_t*) malloc(pv->nfields * sizeof(hid_t)); - for (i = 0; i < pv->nfields; i++) { - char toread[255]; - if (packed == 1) { - snprintf(toread, 255, "/Grid%08d/%s", grid_id, pv->field_names[i]); - } else { - snprintf(toread, 255, "/%s", pv->field_names[i]); - } - - dataset_read[i] = H5Dopen(file_id, toread); - /* We know how many particles we will want, so we allocate our - output arrays */ - if(pv->return_values[i] == NULL){ - /* Get the data type */ - npy_intp dims = pv->total_valid_particles; - rdatatype_id = H5Dget_type(dataset_read[i]); - rnative_type_id = H5Tget_native_type(rdatatype_id, H5T_DIR_ASCEND); - pv->npy_types[i] = get_my_desc_type(rnative_type_id); - //fprintf(stderr, "Allocating array of size %d\n", (int) dims); - pv->return_values[i] = (PyArrayObject *) - PyArray_SimpleNewFromDescr( - 1, &dims, PyArray_DescrFromType(pv->npy_types[i])); - H5Tclose(rnative_type_id); - H5Tclose(rdatatype_id); - } - } - } - - /* Now we create an in-memory dataspace */ - - /* We begin our iteration over the strides here */ - while(current_pos < num_part_this_grid) { - num_particles_to_read = ( - (current_pos + pv->stride_size >= num_part_this_grid) ? - num_part_this_grid - current_pos : pv->stride_size ); - pv->particles_to_check = num_particles_to_read; - - memspace = H5Screate_simple(1, &num_particles_to_read, NULL); - - H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, ¤t_pos, NULL, - &num_particles_to_read, NULL); - H5Dread(dataset_x, native_type_id, memspace, dataspace, H5P_DEFAULT, - pv->particle_position[0]); - H5Dread(dataset_y, native_type_id, memspace, dataspace, H5P_DEFAULT, - pv->particle_position[1]); - H5Dread(dataset_z, native_type_id, memspace, dataspace, H5P_DEFAULT, - pv->particle_position[2]); - - hsize_t read_here = pv->count_func(pv); - - if((read == 1) && (read_here > 0)) { - /* First we select the dataspace */ - H5Sselect_none(dataspace); - int num_copied = 0; - hsize_t *coords = malloc(sizeof(hsize_t) * read_here); - for(i = 0 ; i < num_particles_to_read ; i++) { - /* This might be quite slow */ - if(pv->mask[i] == 1){ - coords[num_copied++] = current_pos + i; - } - } - H5Sselect_elements(dataspace, H5S_SELECT_SET, read_here, coords); - H5Sset_extent_simple(memspace, 1, &read_here, &read_here); - free(coords); - for (ifield = 0; ifield < pv->nfields; ifield++){ - rdatatype_id = H5Dget_type(dataset_read[ifield]); - rnative_type_id = H5Tget_native_type(rdatatype_id, H5T_DIR_ASCEND); - H5Dread(dataset_read[ifield], rnative_type_id, - memspace, dataspace, H5P_DEFAULT, - (void*) PyArray_GETPTR1(pv->return_values[ifield], pv->nread)); - H5Tclose(rnative_type_id); - H5Tclose(rdatatype_id); - /* Now we multiply our fields by the appropriate conversion factor */ - if (cfactors[ifield] != 1.0) { - for(p_ind = 0; p_ind < read_here; p_ind++) - if (pv->npy_types[ifield] == NPY_FLOAT) { // floats - *(npy_float32 *) PyArray_GETPTR1( - pv->return_values[ifield], p_ind + pv->nread) - *= cfactors[ifield]; - } else if (pv->npy_types[ifield] == NPY_DOUBLE) { // doubles - *(npy_float64 *) PyArray_GETPTR1( - pv->return_values[ifield], p_ind + pv->nread) - *= cfactors[ifield]; - } else if (pv->npy_types[ifield] == NPY_LONGDOUBLE) { - *(npy_float128 *) PyArray_GETPTR1 ( - pv->return_values[ifield], p_ind + pv->nread) - *= cfactors[ifield]; - } else if (pv->npy_types[ifield] == NPY_INT) { - *(npy_int *) PyArray_GETPTR1 ( - pv->return_values[ifield], p_ind + pv->nread) - *= cfactors[ifield]; - } else if (pv->npy_types[ifield] == NPY_LONG) { - *(npy_long *) PyArray_GETPTR1 ( - pv->return_values[ifield], p_ind + pv->nread) - *= cfactors[ifield]; - } - } - } - pv->nread += read_here; - } - - current_pos += num_particles_to_read; - } - - H5Dclose(dataset_x); - H5Dclose(dataset_y); - H5Dclose(dataset_z); - H5Sclose(dataspace); - H5Sclose(memspace); - H5Tclose(datatype_id); - H5Tclose(native_type_id); - free(cfactors); - - if (read == 1) { - for (i = 0; i < pv->nfields; i++) { - H5Dclose(dataset_read[i]); - } - free(dataset_read); - } - - //H5Fclose(file_id); // We don't do this here, because we cache out file_id - - return 1; - - _fail: - /* Now the nasty business of closing our HDF5 references */ - if(cfactors!=NULL)free(cfactors); - if(!(dataset_x <= 0)&&(H5Iget_ref(dataset_x))) H5Dclose(dataset_x); - if(!(dataset_y <= 0)&&(H5Iget_ref(dataset_y))) H5Dclose(dataset_y); - if(!(dataset_z <= 0)&&(H5Iget_ref(dataset_z))) H5Dclose(dataset_z); - if(!(dataspace <= 0)&&(H5Iget_ref(dataspace))) H5Sclose(dataspace); - if(!(memspace <= 0)&&(H5Iget_ref(memspace))) H5Sclose(memspace); - if(!(native_type_id <= 0)&&(H5Iget_ref(native_type_id))) H5Tclose(native_type_id); - if(!(datatype_id <= 0)&&(H5Iget_ref(datatype_id))) H5Tclose(datatype_id); - if ((read == 1) && (dataset_read != NULL)) { - for (i = 0; i < pv->nfields; i++) { - if(!(dataset_read[i] <= 0)&&(H5Iget_ref(dataset_read[i]))) - H5Dclose(dataset_read[i]); - } - free(dataset_read); - } - //if(!(file_id <= 0)&&(H5Iget_ref(file_id))) H5Fclose(file_id); - - return 0; -} - -/* Hate to do copy-pasta here, but I think it is necessary */ - -int count_particles_region_FLOAT(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - region_validation *vdata; - - vdata = (region_validation*) data->validation_reqs; - - float **particle_data = (float **) data->particle_position; - - float *particle_position_x = particle_data[0]; - float *particle_position_y = particle_data[1]; - float *particle_position_z = particle_data[2]; - float tempx, tempy, tempz; - - if (vdata->periodic == 0) { - for (ind = 0; ind < data->particles_to_check; ind++) { - if ( (particle_position_x[ind] >= vdata->left_edge[0]) - && (particle_position_x[ind] <= vdata->right_edge[0]) - && (particle_position_y[ind] >= vdata->left_edge[1]) - && (particle_position_y[ind] <= vdata->right_edge[1]) - && (particle_position_z[ind] >= vdata->left_edge[2]) - && (particle_position_z[ind] <= vdata->right_edge[2])) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - } else { - for (ind = 0; ind < data->particles_to_check; ind++) { - tempx = particle_position_x[ind]; - tempy = particle_position_y[ind]; - tempz = particle_position_z[ind]; - if ( (tempx < vdata->left_edge[0]) && (tempx < vdata->right_edge[0]) ) { - tempx += vdata->period[0]; - } else if ( (tempx > vdata->left_edge[0]) && (tempx > vdata->right_edge[0]) ) { - tempx -= vdata->period[0]; - } - if ( (tempy < vdata->left_edge[1]) && (tempy < vdata->right_edge[1]) ) { - tempy += vdata->period[1]; - } else if ( (tempy > vdata->left_edge[1]) && (tempy > vdata->right_edge[1]) ) { - tempy -= vdata->period[1]; - } - if ( (tempz < vdata->left_edge[2]) && (tempz < vdata->right_edge[2]) ) { - tempz += vdata->period[2]; - } else if ( (tempz > vdata->left_edge[2]) && (tempz > vdata->right_edge[2]) ) { - tempz -= vdata->period[2]; - } - if ( (tempx >= vdata->left_edge[0]) - && (tempx <= vdata->right_edge[0]) - && (tempy >= vdata->left_edge[1]) - && (tempy <= vdata->right_edge[1]) - && (tempz >= vdata->left_edge[2]) - && (tempz <= vdata->right_edge[2])) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - } - return n; -} - -int count_particles_region_DOUBLE(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - region_validation *vdata; - - vdata = (region_validation*) data->validation_reqs; - - double **particle_data = (double **) data->particle_position; - - double *particle_position_x = particle_data[0]; - double *particle_position_y = particle_data[1]; - double *particle_position_z = particle_data[2]; - double tempx, tempy, tempz; - - if (vdata->periodic == 0) { - for (ind = 0; ind < data->particles_to_check; ind++) { - if ( (particle_position_x[ind] >= vdata->left_edge[0]) - && (particle_position_x[ind] <= vdata->right_edge[0]) - && (particle_position_y[ind] >= vdata->left_edge[1]) - && (particle_position_y[ind] <= vdata->right_edge[1]) - && (particle_position_z[ind] >= vdata->left_edge[2]) - && (particle_position_z[ind] <= vdata->right_edge[2])) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - } else { - for (ind = 0; ind < data->particles_to_check; ind++) { - tempx = particle_position_x[ind]; - tempy = particle_position_y[ind]; - tempz = particle_position_z[ind]; - if ( (tempx < vdata->left_edge[0]) && (tempx < vdata->right_edge[0]) ) { - tempx += vdata->period[0]; - } else if ( (tempx > vdata->left_edge[0]) && (tempx > vdata->right_edge[0]) ) { - tempx -= vdata->period[0]; - } - if ( (tempy < vdata->left_edge[1]) && (tempy < vdata->right_edge[1]) ) { - tempy += vdata->period[1]; - } else if ( (tempy > vdata->left_edge[1]) && (tempy > vdata->right_edge[1]) ) { - tempy -= vdata->period[1]; - } - if ( (tempz < vdata->left_edge[2]) && (tempz < vdata->right_edge[2]) ) { - tempz += vdata->period[2]; - } else if ( (tempz > vdata->left_edge[2]) && (tempz > vdata->right_edge[2]) ) { - tempz -= vdata->period[2]; - } - if ( (tempx >= vdata->left_edge[0]) - && (tempx <= vdata->right_edge[0]) - && (tempy >= vdata->left_edge[1]) - && (tempy <= vdata->right_edge[1]) - && (tempz >= vdata->left_edge[2]) - && (tempz <= vdata->right_edge[2])) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - } - return n; -} - -int count_particles_region_LONGDOUBLE(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - region_validation *vdata; - - vdata = (region_validation*) data->validation_reqs; - - long double **particle_data = (long double **) data->particle_position; - - long double *particle_position_x = particle_data[0]; - long double *particle_position_y = particle_data[1]; - long double *particle_position_z = particle_data[2]; - long double tempx, tempy, tempz; - - if (vdata->periodic == 0) { - for (ind = 0; ind < data->particles_to_check; ind++) { - if ( (particle_position_x[ind] >= vdata->left_edge[0]) - && (particle_position_x[ind] <= vdata->right_edge[0]) - && (particle_position_y[ind] >= vdata->left_edge[1]) - && (particle_position_y[ind] <= vdata->right_edge[1]) - && (particle_position_z[ind] >= vdata->left_edge[2]) - && (particle_position_z[ind] <= vdata->right_edge[2])) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - } else { - for (ind = 0; ind < data->particles_to_check; ind++) { - tempx = particle_position_x[ind]; - tempy = particle_position_y[ind]; - tempz = particle_position_z[ind]; - if ( (tempx < vdata->left_edge[0]) && (tempx < vdata->right_edge[0]) ) { - tempx += vdata->period[0]; - } else if ( (tempx > vdata->left_edge[0]) && (tempx > vdata->right_edge[0]) ) { - tempx -= vdata->period[0]; - } - if ( (tempy < vdata->left_edge[1]) && (tempy < vdata->right_edge[1]) ) { - tempy += vdata->period[1]; - } else if ( (tempy > vdata->left_edge[1]) && (tempy > vdata->right_edge[1]) ) { - tempy -= vdata->period[1]; - } - if ( (tempz < vdata->left_edge[2]) && (tempz < vdata->right_edge[2]) ) { - tempz += vdata->period[2]; - } else if ( (tempz > vdata->left_edge[2]) && (tempz > vdata->right_edge[2]) ) { - tempz -= vdata->period[2]; - } - if ( (tempx >= vdata->left_edge[0]) - && (tempx <= vdata->right_edge[0]) - && (tempy >= vdata->left_edge[1]) - && (tempy <= vdata->right_edge[1]) - && (tempz >= vdata->left_edge[2]) - && (tempz <= vdata->right_edge[2])) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - } - return n; -} - -int count_particles_sphere_FLOAT(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - sphere_validation *vdata; - - vdata = (sphere_validation*) data->validation_reqs; - - float **particle_data = (float **) data->particle_position; - - float *particle_position_x = particle_data[0]; - float *particle_position_y = particle_data[1]; - float *particle_position_z = particle_data[2]; - float tempr; - - double pradius; - - for (ind = 0; ind < data->particles_to_check; ind++) { - pradius = 0.0; - tempr = (particle_position_x[ind] - vdata->center[0]); pradius += tempr*tempr; - tempr = (particle_position_y[ind] - vdata->center[1]); pradius += tempr*tempr; - tempr = (particle_position_z[ind] - vdata->center[2]); pradius += tempr*tempr; - pradius = pow(pradius, 0.5); - if (pradius <= vdata->radius) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - return n; -} - -int count_particles_sphere_DOUBLE(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - sphere_validation *vdata; - - vdata = (sphere_validation*) data->validation_reqs; - - double **particle_data = (double **) data->particle_position; - - double *particle_position_x = particle_data[0]; - double *particle_position_y = particle_data[1]; - double *particle_position_z = particle_data[2]; - double tempr; - - double pradius; - - for (ind = 0; ind < data->particles_to_check; ind++) { - pradius = 0.0; - tempr = (particle_position_x[ind] - vdata->center[0]); pradius += tempr*tempr; - tempr = (particle_position_y[ind] - vdata->center[1]); pradius += tempr*tempr; - tempr = (particle_position_z[ind] - vdata->center[2]); pradius += tempr*tempr; - pradius = pow(pradius, 0.5); - if (pradius <= vdata->radius) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - return n; -} - -int count_particles_sphere_LONGDOUBLE(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - sphere_validation *vdata; - - vdata = (sphere_validation*) data->validation_reqs; - - long double **particle_data = (long double **) data->particle_position; - - long double *particle_position_x = particle_data[0]; - long double *particle_position_y = particle_data[1]; - long double *particle_position_z = particle_data[2]; - long double tempr; - - long double pradius; - - for (ind = 0; ind < data->particles_to_check; ind++) { - pradius = 0.0; - tempr = (particle_position_x[ind] - vdata->center[0]); pradius += tempr*tempr; - tempr = (particle_position_y[ind] - vdata->center[1]); pradius += tempr*tempr; - tempr = (particle_position_z[ind] - vdata->center[2]); pradius += tempr*tempr; - pradius = pow(pradius, 0.5); - if (pradius <= vdata->radius) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - return n; -} - -int count_particles_cylinder_FLOAT(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - cylinder_validation *vdata; - - vdata = (cylinder_validation*) data->validation_reqs; - - float **particle_data = (float **) data->particle_position; - - float *particle_position_x = particle_data[0]; - float *particle_position_y = particle_data[1]; - float *particle_position_z = particle_data[2]; - float temph, tempd, d; - - d = -1. * (vdata->normal[0] * vdata->center[0] + - vdata->normal[1] * vdata->center[1] + - vdata->normal[2] * vdata->center[2]); - - double pradius, ph, pd; - - for (ind = 0; ind < data->particles_to_check; ind++) { - pradius = 0.0; ph = 0.0; pd = 0.0; - - temph = (particle_position_x[ind] * vdata->normal[0]); ph += temph; - temph = (particle_position_y[ind] * vdata->normal[1]); ph += temph; - temph = (particle_position_z[ind] * vdata->normal[2]); ph += temph; - ph += d; - - tempd = (particle_position_x[ind] - vdata->center[0]); pd += tempd*tempd; - tempd = (particle_position_y[ind] - vdata->center[1]); pd += tempd*tempd; - tempd = (particle_position_z[ind] - vdata->center[2]); pd += tempd*tempd; - - pradius = pow(pd - ph*ph, 0.5); - if ((pradius <= vdata->radius) && (fabs(ph) <= vdata->height)) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - return n; -} - -int count_particles_cylinder_DOUBLE(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - cylinder_validation *vdata; - - vdata = (cylinder_validation*) data->validation_reqs; - - double **particle_data = (double **) data->particle_position; - - double *particle_position_x = particle_data[0]; - double *particle_position_y = particle_data[1]; - double *particle_position_z = particle_data[2]; - double temph, tempd, d; - - d = -1. * (vdata->normal[0] * vdata->center[0] + - vdata->normal[1] * vdata->center[1] + - vdata->normal[2] * vdata->center[2]); - - double pradius, ph, pd; - - for (ind = 0; ind < data->particles_to_check; ind++) { - pradius = 0.0; ph = 0.0; pd = 0.0; - - temph = (particle_position_x[ind] * vdata->normal[0]); ph += temph; - temph = (particle_position_y[ind] * vdata->normal[1]); ph += temph; - temph = (particle_position_z[ind] * vdata->normal[2]); ph += temph; - ph += d; - - tempd = (particle_position_x[ind] - vdata->center[0]); pd += tempd*tempd; - tempd = (particle_position_y[ind] - vdata->center[1]); pd += tempd*tempd; - tempd = (particle_position_z[ind] - vdata->center[2]); pd += tempd*tempd; - - pradius = pow(pd - ph*ph, 0.5); - if ((pradius <= vdata->radius) && (fabs(ph) <= vdata->height)) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - return n; -} - -int count_particles_cylinder_LONGDOUBLE(particle_validation *data) -{ - /* Our data comes packed in a struct, off which our pointers all hang */ - - /* First is our validation requirements, which are a set of three items: */ - - int ind, n=0; - cylinder_validation *vdata; - - vdata = (cylinder_validation*) data->validation_reqs; - - long double **particle_data = (long double **) data->particle_position; - - long double *particle_position_x = particle_data[0]; - long double *particle_position_y = particle_data[1]; - long double *particle_position_z = particle_data[2]; - long double temph, tempd, d; - - d = -1. * (vdata->normal[0] * vdata->center[0] + - vdata->normal[1] * vdata->center[1] + - vdata->normal[2] * vdata->center[2]); - - long double pradius, ph, pd; - - for (ind = 0; ind < data->particles_to_check; ind++) { - pradius = 0.0; ph = 0.0; pd = 0.0; - - temph = (particle_position_x[ind] * vdata->normal[0]); ph += temph; - temph = (particle_position_y[ind] * vdata->normal[1]); ph += temph; - temph = (particle_position_z[ind] * vdata->normal[2]); ph += temph; - ph += d; - - tempd = (particle_position_x[ind] - vdata->center[0]); pd += tempd*tempd; - tempd = (particle_position_y[ind] - vdata->center[1]); pd += tempd*tempd; - tempd = (particle_position_z[ind] - vdata->center[2]); pd += tempd*tempd; - - pradius = pow(pd - ph*ph, 0.5); - if ((pradius <= vdata->radius) && (fabsl(ph) <= vdata->height)) { - if(data->update_count == 1) data->total_valid_particles++; - data->mask[ind] = 1; - n++; - } else { - data->mask[ind] = 0; - } - } - return n; -} - -static PyMethodDef _hdf5LightReaderMethods[] = { - {"ReadData", Py_ReadHDF5DataSet, METH_VARARGS}, - {"ReadDataSlice", Py_ReadHDF5DataSetSlice, METH_VARARGS}, - {"ReadListOfDatasets", Py_ReadListOfDatasets, METH_VARARGS}, - {"ReadMultipleGrids", Py_ReadMultipleGrids, METH_VARARGS}, - {"ReadParticles", Py_ReadParticles, METH_VARARGS}, - {NULL, NULL} -}; - -#ifdef MS_WIN32 -__declspec(dllexport) -#endif - -void initHDF5LightReader(void) -{ - PyObject *m, *d; - m = Py_InitModule("HDF5LightReader", _hdf5LightReaderMethods); - d = PyModule_GetDict(m); - _hdf5ReadError = PyErr_NewException("HDF5LightReader.ReadingError", NULL, NULL); - PyDict_SetItemString(d, "ReadingError", _hdf5ReadError); - import_array(); -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/HaloFinding.py --- a/yt/lagos/HaloFinding.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1848 +0,0 @@ -""" -HOP-output data handling - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Author: Stephen Skory -Affiliation: UCSD Physics/CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.lagos import * -from yt.math_utils import * -from yt.lagos.hop.EnzoHop import RunHOP -try: - from yt.lagos.parallelHOP.parallelHOP import * -except ImportError: - mylog.debug("ParallelHOP not imported.") - -try: - from yt.lagos.fof.EnzoFOF import RunFOF -except ImportError: - pass -from yt.performance_counters import yt_counters, time_function - -from kd import * -from yt.funcs import * -import math, sys, itertools, gc, random -from collections import defaultdict - -TINY = 1.e-40 - -class Halo(object): - """ - A data source that returns particle information about the members of a - HOP-identified halo. - """ - __metaclass__ = ParallelDummy # This will proxy up our methods - _distributed = False - _processing = False - _owner = 0 - indices = None - dont_wrap = ["get_sphere", "write_particle_list"] - extra_wrap = ["__getitem__"] - - def __init__(self, halo_list, id, indices = None, size=None, CoM=None, - max_dens_point=None, group_total_mass=None, max_radius=None, bulk_vel=None, - tasks=None, rms_vel=None): - self._max_dens = halo_list._max_dens - self.id = id - self.data = halo_list._data_source - if indices is not None: - self.indices = halo_list._base_indices[indices] - else: - self.indices = None - # We assume that if indices = None, the instantiator has OTHER plans - # for us -- i.e., setting it somehow else - self.size = size - self.CoM = CoM - self.max_dens_point = max_dens_point - self.group_total_mass = group_total_mass - self.max_radius = max_radius - self.bulk_vel = bulk_vel - self.tasks = tasks - self.rms_vel = rms_vel - self.bin_count = None - self.overdensity = None - - def center_of_mass(self): - r"""Calculate and return the center of mass. - - The center of mass of the halo is directly calculated and returned. - - Examples - -------- - >>> com = halos[0].center_of_mass() - """ - c_vec = self.maximum_density_location() - na.array([0.5,0.5,0.5]) - pm = self["ParticleMassMsun"] - cx = (self["particle_position_x"] - c_vec[0]) - cy = (self["particle_position_y"] - c_vec[1]) - cz = (self["particle_position_z"] - c_vec[2]) - com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) - return (com*pm).sum(axis=1)/pm.sum() + c_vec - - def maximum_density(self): - r"""Return the HOP-identified maximum density. Not applicable to - FOF halos. - - Return the HOP-identified maximum density. Not applicable to FOF halos. - - Examples - -------- - >>> max_dens = halos[0].maximum_density() - """ - return self._max_dens[self.id][0] - - def maximum_density_location(self): - r"""Return the location HOP identified as maximally dense. Not - applicable to FOF halos. - - Return the location HOP identified as maximally dense. - - Examples - -------- - >>> max_dens_loc = halos[0].maximum_density_location() - """ - return na.array([ - self._max_dens[self.id][1], - self._max_dens[self.id][2], - self._max_dens[self.id][3]]) - - def total_mass(self): - r"""Returns the total mass in solar masses of the halo. - - Returns the total mass in solar masses of just the particles in the - halo. - - Examples - -------- - >>> halos[0].total_mass() - """ - return self["ParticleMassMsun"].sum() - - def bulk_velocity(self): - r"""Returns the mass-weighted average velocity in cm/s. - - This calculates and returns the mass-weighted average velocity of just - the particles in the halo in cm/s. - - Examples - -------- - >>> bv = halos[0].bulk_velocity() - """ - pm = self["ParticleMassMsun"] - vx = (self["particle_velocity_x"] * pm).sum() - vy = (self["particle_velocity_y"] * pm).sum() - vz = (self["particle_velocity_z"] * pm).sum() - return na.array([vx,vy,vz])/pm.sum() - - def rms_velocity(self): - r"""Returns the mass-weighted RMS velocity for the halo - particles in cgs units. - - Calculate and return the mass-weighted RMS velocity for just the - particles in the halo. The bulk velocity of the halo is subtracted - before computation. - - Examples - -------- - >>> rms_vel = halos[0].rms_velocity() - """ - bv = self.bulk_velocity() - pm = self["ParticleMassMsun"] - sm = pm.sum() - vx = (self["particle_velocity_x"] - bv[0]) * pm/sm - vy = (self["particle_velocity_y"] - bv[1]) * pm/sm - vz = (self["particle_velocity_z"] - bv[2]) * pm/sm - s = vx**2. + vy**2. + vz**2. - ms = na.mean(s) - return na.sqrt(ms) * pm.size - - def maximum_radius(self, center_of_mass=True): - r"""Returns the maximum radius in the halo for all particles, - either from the point of maximum density or from the - center of mass. - - The maximum radius from the most dense point is calculated. This - accounts for periodicity. - - Parameters - ---------- - center_of_mass : bool - True chooses the center of mass when calculating the maximum radius. - False chooses from the maximum density location for HOP halos - (it has no effect for FOF halos). - Default = True. - - Examples - -------- - >>> radius = halos[0].maximum_radius() - """ - if center_of_mass: center = self.center_of_mass() - else: center = self.maximum_density_location() - rx = na.abs(self["particle_position_x"]-center[0]) - ry = na.abs(self["particle_position_y"]-center[1]) - rz = na.abs(self["particle_position_z"]-center[2]) - DW = self.data.pf["DomainRightEdge"] - self.data.pf["DomainLeftEdge"] - r = na.sqrt(na.minimum(rx, DW[0]-rx)**2.0 - + na.minimum(ry, DW[1]-ry)**2.0 - + na.minimum(rz, DW[2]-rz)**2.0) - return r.max() - - def __getitem__(self, key): - if ytcfg.getboolean("yt","inline") == False: - return self.data[key][self.indices] - else: - return self.data[key][self.indices] - - def get_sphere(self, center_of_mass=True): - r"""Returns a sphere source. - - This will generate a new, empty sphere source centered on this halo, - with the maximum radius of the halo. - - Parameters - ---------- - center_of_mass : bool, optional - True chooses the center of mass when calculating the maximum radius. - False chooses from the maximum density location for HOP halos - (it has no effect for FOF halos). - Default = True. - - Returns - ------- - sphere : `yt.lagos.AMRSphereBase` - The empty data source. - - Examples - -------- - >>> sp = halos[0].get_sphere() - """ - if center_of_mass: center = self.center_of_mass() - else: center = self.maximum_density_location() - radius = self.maximum_radius() - # A bit of a long-reach here... - sphere = self.data.hierarchy.sphere( - center, radius=radius) - return sphere - - def get_size(self): - return self.indices.size - - def write_particle_list(self, handle): - self._processing = True - gn = "Halo%08i" % (self.id) - handle.create_group("/%s" % gn) - for field in ["particle_position_%s" % ax for ax in 'xyz'] \ - + ["particle_velocity_%s" % ax for ax in 'xyz'] \ - + ["particle_index"] + ["ParticleMassMsun"]: - handle.create_dataset("/%s/%s" % (gn, field), data=self[field]) - if 'creation_time' in self.data.pf.h.field_list: - handle.create_dataset("/%s/creation_time" % gn, - data=self['creation_time']) - n = handle["/%s" % gn] - # set attributes on n - self._processing = False - - def virial_mass(self, virial_overdensity=200., bins=300): - r"""Return the virial mass of the halo in Msun, using only the particles - in the halo (no baryonic information used). - - The virial mass is calculated, using the built in `Halo.virial_info` - functionality. The mass is then returned. - - Parameters - ---------- - virial_overdensity : float - The overdensity threshold compared to the universal average when - calculating the virial mass. Default = 200. - bins : int - The number of spherical bins used to calculate overdensities. - Default = 300. - - Returns - ------- - mass : float - The virial mass in solar masses of the particles in the halo. -1 - if not virialized. - - Examples - -------- - >>> vm = halos[0].virial_mass() - """ - self.virial_info(bins=bins) - vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) - if vir_bin != -1: - return self.mass_bins[vir_bin] - else: - return -1 - - - def virial_radius(self, virial_overdensity=200., bins=300): - r"""Return the virial radius of the halo in code units. - - The virial radius of the halo is calculated, using only the particles - in the halo (no baryonic information used). Returns -1 if the halo is - not virialized. - - Parameters - ---------- - virial_overdensity : float - The overdensity threshold compared to the universal average when - calculating the virial radius. Default = 200. - bins : integer - The number of spherical bins used to calculate overdensities. - Default = 300. - - Returns - ------- - radius : float - The virial raius in code units of the particles in the halo. -1 - if not virialized. - - Examples - -------- - >>> vr = halos[0].virial_radius() - """ - self.virial_info(bins=bins) - vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) - if vir_bin != -1: - return self.radial_bins[vir_bin] - else: - return -1 - - def virial_bin(self, virial_overdensity=200., bins=300): - r"""Returns the bin index of the virial radius of the halo. Generally, - it is better to call virial_radius instead, which calls this function - automatically. - """ - self.virial_info(bins=bins) - over = (self.overdensity > virial_overdensity) - if (over == True).any(): - vir_bin = max(na.arange(bins+1)[over]) - return vir_bin - else: - return -1 - - def virial_info(self, bins=300): - r"""Calculates the virial information for the halo. Generally, it is - better to call virial_radius or virial_mass instead, which calls this - function automatically. - """ - # Skip if we've already calculated for this number of bins. - if self.bin_count == bins and self.overdensity is not None: - return None - self.bin_count = bins - # Cosmology - h = self.data.pf['CosmologyHubbleConstantNow'] - Om_matter = self.data.pf['CosmologyOmegaMatterNow'] - z = self.data.pf['CosmologyCurrentRedshift'] - rho_crit_now = 1.8788e-29 * h**2.0 * Om_matter # g cm^-3 - Msun2g = 1.989e33 - rho_crit = rho_crit_now * ((1.0 + z)**3.0) - - # Get some pertinent information about the halo. - self.mass_bins = na.zeros(self.bin_count+1, dtype='float64') - dist = na.empty(self.indices.size, dtype='float64') - cen = self.center_of_mass() - period = self.data.pf["DomainRightEdge"] - \ - self.data.pf["DomainLeftEdge"] - mark = 0 - # Find the distances to the particles. I don't like this much, but I - # can't see a way to eliminate a loop like this, either here or in - # yt.math. - for pos in izip(self["particle_position_x"], self["particle_position_y"], - self["particle_position_z"]): - dist[mark] = periodic_dist(cen, pos, period) - mark += 1 - # Set up the radial bins. - # Multiply min and max to prevent issues with digitize below. - self.radial_bins = na.logspace(math.log10(min(dist)*.99 + TINY), - math.log10(max(dist)*1.01 + 2*TINY), num=self.bin_count+1) - # Find out which bin each particle goes into, and add the particle - # mass to that bin. - inds = na.digitize(dist, self.radial_bins) - 1 - if self["particle_position_x"].size > 1: - for index in na.unique(inds): - self.mass_bins[index] += sum(self["ParticleMassMsun"][inds==index]) - # Now forward sum the masses in the bins. - for i in xrange(self.bin_count): - self.mass_bins[i+1] += self.mass_bins[i] - # Calculate the over densities in the bins. - self.overdensity = self.mass_bins * Msun2g / \ - (4./3. * math.pi * rho_crit * \ - (self.radial_bins * self.data.pf["cm"])**3.0) - - -class HOPHalo(Halo): - pass - -class parallelHOPHalo(Halo,ParallelAnalysisInterface): - dont_wrap = ["maximum_density","maximum_density_location", - "center_of_mass","total_mass","bulk_velocity","maximum_radius", - "get_size","get_sphere", "write_particle_list","__getitem__", - "virial_info", "virial_bin", "virial_mass", "virial_radius", - "rms_velocity"] - - def maximum_density(self): - r"""Return the HOP-identified maximum density. - - Return the HOP-identified maximum density. - - Examples - -------- - >>> max_dens = halos[0].maximum_density() - """ - if self.max_dens_point is not None: - return self.max_dens_point[0] - max = self._mpi_allmax(self._max_dens[self.id][0]) - return max - - def maximum_density_location(self): - r"""Return the location HOP identified as maximally dense. - - Return the location HOP identified as maximally dense. - - Examples - -------- - >>> max_dens_loc = halos[0].maximum_density_location() - """ - if self.max_dens_point is not None: - return self.max_dens_point[1:] - # If I own the maximum density, my location is globally correct. - max_dens = self.maximum_density() - if self._max_dens[self.id][0] == max_dens: - value = na.array([ - self._max_dens[self.id][1], - self._max_dens[self.id][2], - self._max_dens[self.id][3]]) - else: - value = na.array([0,0,0]) - # This works, and isn't appropriate but for now will be fine... - value = self._mpi_allsum(value) - return value - - def center_of_mass(self): - r"""Calculate and return the center of mass. - - The center of mass of the halo is directly calculated and returned. - - Examples - -------- - >>> com = halos[0].center_of_mass() - """ - # If it's precomputed, we save time! - if self.CoM is not None: - return self.CoM - # This need to be called by all tasks, but not all will end up using - # it. - c_vec = self.maximum_density_location() - na.array([0.5,0.5,0.5]) - if self.indices is not None: - pm = self["ParticleMassMsun"] - cx = (self["particle_position_x"] - c_vec[0]) - cy = (self["particle_position_y"] - c_vec[1]) - cz = (self["particle_position_z"] - c_vec[2]) - com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) - my_mass = pm.sum() - my_com = ((com*pm).sum(axis=1)/my_mass + c_vec) * my_mass - else: - my_mass = 0. - my_com = na.array([0.,0.,0.]) - global_mass = self._mpi_allsum(my_mass) - global_com = self._mpi_allsum(my_com) - return global_com / global_mass - - def total_mass(self): - r"""Returns the total mass in solar masses of the halo. - - Returns the total mass in solar masses of just the particles in the - halo. - - Examples - -------- - >>> halos[0].total_mass() - """ - if self.group_total_mass is not None: - return self.group_total_mass - if self.indices is not None: - my_mass = self["ParticleMassMsun"].sum() - else: - my_mass = 0. - global_mass = self._mpi_allsum(float(my_mass)) - return global_mass - - def bulk_velocity(self): - r"""Returns the mass-weighted average velocity in cm/s. - - This calculates and returns the mass-weighted average velocity of just - the particles in the halo in cm/s. - - Examples - -------- - >>> bv = halos[0].bulk_velocity() - """ - if self.bulk_vel is not None: - return self.bulk_vel - # Unf. this cannot be reasonably computed inside of parallelHOP because - # we don't pass velocities in. - if self.indices is not None: - pm = self["ParticleMassMsun"] - vx = (self["particle_velocity_x"] * pm).sum() - vy = (self["particle_velocity_y"] * pm).sum() - vz = (self["particle_velocity_z"] * pm).sum() - pm = pm.sum() - else: - pm = 0. - vx = 0. - vy = 0. - vz = 0. - bv = na.array([vx,vy,vz,pm]) - global_bv = self._mpi_allsum(bv) - return global_bv[:3]/global_bv[3] - - def rms_velocity(self): - r"""Returns the mass-weighted RMS velocity for the halo - particles in cgs units. - - Calculate and return the mass-weighted RMS velocity for just the - particles in the halo. The bulk velocity of the halo is subtracted - before computation. - - Examples - -------- - >>> rms_vel = halos[0].rms_velocity() - """ - if self.rms_vel is not None: - return self.rms_vel - bv = self.bulk_velocity() - pm = self["ParticleMassMsun"] - sm = pm.sum() - if self.indices is not None: - vx = (self["particle_velocity_x"] - bv[0]) * pm/sm - vy = (self["particle_velocity_y"] - bv[1]) * pm/sm - vz = (self["particle_velocity_z"] - bv[2]) * pm/sm - s = vx**2 + vy**2 + vz**2 - s = na.sum(s) - size = vx.size - ss = na.array([s, float(size)]) - else: - ss = na.array([0.,0.]) - global_ss = self._mpi_allsum(ss) - ms = global_ss[0] / global_ss[1] - return na.sqrt(ms) * global_ss[1] - - def maximum_radius(self, center_of_mass=True): - r"""Returns the maximum radius in the halo for all particles, - either from the point of maximum density or from the - center of mass. - - The maximum radius from the most dense point is calculated. This - accounts for periodicity. - - Parameters - ---------- - center_of_mass : bool - True chooses the center of mass when calculating the maximum radius. - False chooses from the maximum density location for HOP halos - (it has no effect for FOF halos). - Default = True. - - Examples - -------- - >>> radius = halos[0].maximum_radius() - """ - if self.max_radius is not None: - return self.max_radius - if center_of_mass: center = self.center_of_mass() - else: center = self.maximum_density_location() - DW = self.data.pf["DomainRightEdge"] - self.data.pf["DomainLeftEdge"] - if self.indices is not None: - rx = na.abs(self["particle_position_x"]-center[0]) - ry = na.abs(self["particle_position_y"]-center[1]) - rz = na.abs(self["particle_position_z"]-center[2]) - r = na.sqrt(na.minimum(rx, DW[0]-rx)**2.0 - + na.minimum(ry, DW[1]-ry)**2.0 - + na.minimum(rz, DW[2]-rz)**2.0) - my_max = r.max() - - else: - my_max = 0. - return self._mpi_allmax(my_max) - - def get_size(self): - if self.size is not None: - return self.size - if self.indices is not None: - my_size = self.indices.size - else: - my_size = 0 - global_size = self._mpi_allsum(my_size) - return global_size - - def __getitem__(self, key): - if ytcfg.getboolean("yt","inline") == False: - return self.data[key][self.indices] - else: - return self.data[key][self.indices] - - def virial_mass(self, virial_overdensity=200., bins=300): - r"""Return the virial mass of the halo in Msun, using only the particles - in the halo (no baryonic information used). - - The virial mass is calculated, using the built in `Halo.virial_info` - functionality. The mass is then returned. - - Parameters - ---------- - virial_overdensity : float - The overdensity threshold compared to the universal average when - calculating the virial mass. Default = 200. - bins : int - The number of spherical bins used to calculate overdensities. - Default = 300. - - Returns - ------- - mass : float - The virial mass in solar masses of the particles in the halo. -1 - if not virialized. - - Examples - -------- - >>> vm = halos[0].virial_mass() - """ - self.virial_info(bins=bins) - vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) - if vir_bin != -1: - return self.mass_bins[vir_bin] - else: - return -1 - - - def virial_radius(self, virial_overdensity=200., bins=300): - r"""Return the virial radius of the halo in code units. - - The virial radius of the halo is calculated, using only the particles - in the halo (no baryonic information used). Returns -1 if the halo is - not virialized. - - Parameters - ---------- - virial_overdensity : float - The overdensity threshold compared to the universal average when - calculating the virial radius. Default = 200. - bins : integer - The number of spherical bins used to calculate overdensities. - Default = 300. - - Returns - ------- - radius : float - The virial raius in code units of the particles in the halo. -1 - if not virialized. - - Examples - -------- - >>> vr = halos[0].virial_radius() - """ - self.virial_info(bins=bins) - vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins) - if vir_bin != -1: - return self.radial_bins[vir_bin] - else: - return -1 - - def virial_bin(self, virial_overdensity=200., bins=300): - r"""Returns the bin index of the virial radius of the halo. Generally, - it is better to call virial_radius instead, which calls this function - automatically. - """ - self.virial_info(bins=bins) - over = (self.overdensity > virial_overdensity) - if (over == True).any(): - vir_bin = max(na.arange(bins+1)[over]) - return vir_bin - else: - return -1 - - def virial_info(self, bins=300): - r"""Calculates the virial information for the halo. Generally, it is - better to call virial_radius or virial_mass instead, which calls this - function automatically. - """ - # Skip if we've already calculated for this number of bins. - if self.bin_count == bins and self.overdensity is not None: - return None - # Do this for all because all will use it. - self.bin_count = bins - period = self.data.pf["DomainRightEdge"] - \ - self.data.pf["DomainLeftEdge"] - self.mass_bins = na.zeros(self.bin_count+1, dtype='float64') - cen = self.center_of_mass() - # Cosmology - h = self.data.pf['CosmologyHubbleConstantNow'] - Om_matter = self.data.pf['CosmologyOmegaMatterNow'] - z = self.data.pf['CosmologyCurrentRedshift'] - rho_crit_now = 1.8788e-29 * h**2.0 * Om_matter # g cm^-3 - Msun2g = 1.989e33 - rho_crit = rho_crit_now * ((1.0 + z)**3.0) - # If I own some of this halo operate on the particles. - if self.indices is not None: - # Get some pertinent information about the halo. - dist = na.empty(self.indices.size, dtype='float64') - mark = 0 - # Find the distances to the particles. I don't like this much, but I - # can't see a way to eliminate a loop like this, either here or in - # yt.math. - for pos in izip(self["particle_position_x"], self["particle_position_y"], - self["particle_position_z"]): - dist[mark] = periodic_dist(cen, pos, period) - mark += 1 - dist_min, dist_max = min(dist), max(dist) - # If I don't have this halo, make some dummy values. - else: - dist_min = max(period) - dist_max = 0.0 - # In this parallel case, we're going to find the global dist extrema - # and built identical bins on all tasks. - dist_min = self._mpi_allmin(dist_min) - dist_max = self._mpi_allmax(dist_max) - # Set up the radial bins. - # Multiply min and max to prevent issues with digitize below. - self.radial_bins = na.logspace(math.log10(dist_min*.99 + TINY), - math.log10(dist_max*1.01 + 2*TINY), num=self.bin_count+1) - if self.indices is not None and self.indices.size > 1: - # Find out which bin each particle goes into, and add the particle - # mass to that bin. - inds = na.digitize(dist, self.radial_bins) - 1 - for index in na.unique(inds): - self.mass_bins[index] += sum(self["ParticleMassMsun"][inds==index]) - # Now forward sum the masses in the bins. - for i in xrange(self.bin_count): - self.mass_bins[i+1] += self.mass_bins[i] - # Sum up the mass_bins globally - self.mass_bins = self._mpi_Allsum_double(self.mass_bins) - # Calculate the over densities in the bins. - self.overdensity = self.mass_bins * Msun2g / \ - (4./3. * math.pi * rho_crit * \ - (self.radial_bins * self.data.pf["cm"])**3.0) - - -class FOFHalo(Halo): - - def center_of_mass(self): - r"""Calculate and return the center of mass. - - The center of mass of the halo is directly calculated and returned. - - Examples - -------- - >>> com = halos[0].center_of_mass() - """ - pm = self["ParticleMassMsun"] - cx = self["particle_position_x"] - cy = self["particle_position_y"] - cz = self["particle_position_z"] - c_vec = na.array([cx[0],cy[0],cz[0]]) - na.array([0.5,0.5,0.5]) - cx = cx - c_vec[0] - cy = cy - c_vec[1] - cz = cz - c_vec[2] - com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) - com = (pm * com).sum(axis=1)/pm.sum() + c_vec - return com - - def maximum_density(self): - r"""Not implemented.""" - return -1 - - def maximum_density_location(self): - r"""Not implemented.""" - return self.center_of_mass() - -class HaloList(object): - - _fields = ["particle_position_%s" % ax for ax in 'xyz'] - - def __init__(self, data_source, dm_only = True): - """ - Run hop on *data_source* with a given density *threshold*. If - *dm_only* is set, only run it on the dark matter particles, otherwise - on all particles. Returns an iterable collection of *HopGroup* items. - """ - self._data_source = data_source - self.dm_only = dm_only - self._groups = [] - self._max_dens = {} - self.__obtain_particles() - self._run_finder() - mylog.info("Parsing outputs") - self._parse_output() - mylog.debug("Finished. (%s)", len(self)) - - def __obtain_particles(self): - if self.dm_only: ii = self._get_dm_indices() - else: ii = slice(None) - self.particle_fields = {} - for field in self._fields: - if ytcfg.getboolean("yt","inline") == False: - tot_part = self._data_source[field].size - if field == "particle_index": - self.particle_fields[field] = self._data_source[field][ii].astype('int64') - else: - self.particle_fields[field] = self._data_source[field][ii].astype('float64') - else: - tot_part = self._data_source[field].size - if field == "particle_index": - self.particle_fields[field] = self._data_source[field][ii].astype('int64') - else: - self.particle_fields[field] = self._data_source[field][ii].astype('float64') - self._base_indices = na.arange(tot_part)[ii] - - def _get_dm_indices(self): - if 'creation_time' in self._data_source.hierarchy.field_list: - mylog.debug("Differentiating based on creation time") - return (self._data_source["creation_time"] < 0) - elif 'particle_type' in self._data_source.hierarchy.field_list: - mylog.debug("Differentiating based on particle type") - return (self._data_source["particle_type"] == 1) - else: - mylog.warning("No particle_type, no creation_time, so not distinguishing.") - return slice(None) - - - def _parse_output(self): - unique_ids = na.unique(self.tags) - counts = na.bincount(self.tags+1) - sort_indices = na.argsort(self.tags) - grab_indices = na.indices(self.tags.shape).ravel()[sort_indices] - dens = self.densities[sort_indices] - cp = 0 - for i in unique_ids: - cp_c = cp + counts[i+1] - if i == -1: - cp += counts[i+1] - continue - group_indices = grab_indices[cp:cp_c] - self._groups.append(self._halo_class(self, i, group_indices)) - md_i = na.argmax(dens[cp:cp_c]) - px, py, pz = [self.particle_fields['particle_position_%s'%ax][group_indices] - for ax in 'xyz'] - self._max_dens[i] = (dens[cp:cp_c][md_i], px[md_i], py[md_i], pz[md_i]) - cp += counts[i+1] - - def __len__(self): - return len(self._groups) - - def __iter__(self): - for i in self._groups: yield i - - def __getitem__(self, key): - return self._groups[key] - - def nearest_neighbors_3D(self, haloID, num_neighbors=7, search_radius=.2): - r"""For a halo its nearest neighbors in 3D using the kd tree. - - This will calculate the nearest neighbors of a halo, using the kD tree. - Returns a list of the neighbors distances and ID with format - [distance,haloID]. - - Parameters - ---------- - haloID : integer - The halo to find neighbors for. - num_neighbors : integer - How many neighbors to search for. Default = 7. - search_radius : float - How far away to look for neighbors in code units. Default = 0.2. - - Examples - -------- - >>> neighbors = halos.nearest_neighbors_3D(0) - """ - period = self.pf['DomainRightEdge'] - self.pf['DomainLeftEdge'] - # Initialize the dataset of points from all the haloes - dataset = [] - for group in self: - p = Point() - p.data = group.center_of_mass().tolist() - p.haloID = group.id - dataset.append(p) - mylog.info('Building kd tree...') - kd = buildKdHyperRectTree(dataset[:],2*num_neighbors) - # make the neighbors object - neighbors = Neighbors() - neighbors.k = num_neighbors - neighbors.points = [] - neighbors.minDistanceSquared = search_radius * search_radius - mylog.info('Finding nearest neighbors...') - getKNN(self[haloID].center_of_mass().tolist(), kd, neighbors,0., period.tolist()) - # convert the data in order to return something less perverse than a - # Neighbors object, also root the distances - n_points = [] - for n in neighbors.points: - n_points.append([math.sqrt(n[0]),n[1].haloID]) - return n_points - - def nearest_neighbors_2D(self, haloID, num_neighbors=7, search_radius=.2, - proj_dim=0): - r"""For a halo its nearest neighbors in 2D using the kd tree. - - This will strip a dimension from consideration in the kD-tree, and then - calculate all the nearest projected neighbors of a halo. Returns a - list of the neighbors distances and ID with format [distance,haloID]. - - Parameters - ---------- - haloID : int - The halo to find neighbors for. - num_neighbors : int - How many neighbors to search for. Default = 7. - search_radius : float - How far away to look for neighbors in code units. Default = 0.2. - proj_dim : int - Which dimension (0, 1, or 2) to project the halos into 2D. - Default = 0. - - Examples - -------- - >>> neighbors = halos.nearest_neighbors_2D(0) - """ - # Set up a vector to multiply other vectors by to project along proj_dim - vec = na.array([1.,1.,1.]) - vec[proj_dim] = 0. - period = self.pf['DomainRightEdge'] - self.pf['DomainLeftEdge'] - period = period * vec - # Initialize the dataset of points from all the haloes - dataset = [] - for group in self: - p = Point() - cm = group.center_of_mass() * vec - p.data = cm.tolist() - p.haloID = group.id - dataset.append(p) - mylog.info('Building kd tree...') - kd = buildKdHyperRectTree(dataset[:],2*num_neighbors) - # make the neighbors object - neighbors = Neighbors() - neighbors.k = num_neighbors - neighbors.points = [] - neighbors.minDistanceSquared = search_radius * search_radius - mylog.info('Finding nearest neighbors...') - cm = self[haloID].center_of_mass() * vec - getKNN(cm.tolist(), kd, neighbors,0., period.tolist()) - # convert the data in order to return something less perverse than a - # Neighbors object, also root the distances - n_points = [] - for n in neighbors.points: - n_points.append([math.sqrt(n[0]),n[1].haloID]) - return n_points - - def write_out(self, filename): - r"""Write out standard halo information to a text file. - - Parameters - ---------- - filename : String - The name of the file to write to. - - Examples - -------- - >>> halos.write_out("HopAnalysis.out") - """ - if hasattr(filename, 'write'): - f = filename - else: - f = open(filename,"w") - f.write("# HALOS FOUND WITH %s\n" % (self._name)) - f.write("\t".join(["# Group","Mass","# part","max dens" - "x","y","z", "center-of-mass", - "x","y","z", - "vx","vy","vz","max_r","rms_v","\n"])) - for group in self: - f.write("%10i\t" % group.id) - f.write("%0.9e\t" % group.total_mass()) - f.write("%10i\t" % group.get_size()) - f.write("%0.9e\t" % group.maximum_density()) - f.write("\t".join(["%0.9e" % v for v in group.maximum_density_location()])) - f.write("\t") - f.write("\t".join(["%0.9e" % v for v in group.center_of_mass()])) - f.write("\t") - f.write("\t".join(["%0.9e" % v for v in group.bulk_velocity()])) - f.write("\t") - f.write("%0.9e\t" % group.maximum_radius()) - f.write("%0.9e\t" % group.rms_velocity()) - f.write("\n") - f.flush() - f.close() - - def write_particle_lists_txt(self, prefix, fp=None): - r"""Write out the names of the HDF5 files containing halo particle data - to a text file. Needed in particular for parallel analysis output. - - Parameters - ---------- - prefix : String - The prefix for the name of the file. - - Examples - -------- - >>> halos.write_particle_lists_txt("halo-parts") - """ - if hasattr(fp, 'write'): - f = fp - else: - f = open("%s.txt" % prefix,"w") - for group in self: - if group.tasks is not None: - fn = "" - for task in group.tasks: - fn += "%s.h5 " % self._get_filename(prefix, rank=task) - elif self._distributed: - fn = "%s.h5" % self._get_filename(prefix, rank=group._owner) - else: - fn = "%s.h5" % self._get_filename(prefix) - gn = "Halo%08i" % (group.id) - f.write("%s %s\n" % (gn, fn)) - f.flush() - f.close() - -class HOPHaloList(HaloList): - - _name = "HOP" - _halo_class = HOPHalo - _fields = ["particle_position_%s" % ax for ax in 'xyz'] + \ - ["ParticleMassMsun"] - - def __init__(self, data_source, threshold=160.0, dm_only=True): - """ - Run hop on *data_source* with a given density *threshold*. If - *dm_only* is set, only run it on the dark matter particles, otherwise - on all particles. Returns an iterable collection of *HopGroup* items. - """ - self.threshold = threshold - mylog.info("Initializing HOP") - HaloList.__init__(self, data_source, dm_only) - - def _run_finder(self): - self.densities, self.tags = \ - RunHOP(self.particle_fields["particle_position_x"], - self.particle_fields["particle_position_y"], - self.particle_fields["particle_position_z"], - self.particle_fields["ParticleMassMsun"], - self.threshold) - self.particle_fields["densities"] = self.densities - self.particle_fields["tags"] = self.tags - - def write_out(self, filename="HopAnalysis.out"): - r"""Write out standard halo information to a text file. - - Parameters - ---------- - filename : String - The name of the file to write to. Default = "HopAnalysis.out". - - Examples - -------- - >>> halos.write_out("HopAnalysis.out") - """ - HaloList.write_out(self, filename) - -class FOFHaloList(HaloList): - _name = "FOF" - _halo_class = FOFHalo - - def __init__(self, data_source, link=0.2, dm_only=True): - self.link = link - mylog.info("Initializing FOF") - HaloList.__init__(self, data_source, dm_only) - - def _run_finder(self): - self.tags = \ - RunFOF(self.particle_fields["particle_position_x"], - self.particle_fields["particle_position_y"], - self.particle_fields["particle_position_z"], - self.link) - self.densities = na.ones(self.tags.size, dtype='float64') * -1 - self.particle_fields["densities"] = self.densities - self.particle_fields["tags"] = self.tags - - def write_out(self, filename="FOFAnalysis.out"): - r"""Write out standard halo information to a text file. - - Parameters - ---------- - filename : String - The name of the file to write to. Default = "FOFAnalysis.out". - - Examples - -------- - >>> halos.write_out("FOFAnalysis.out") - """ - HaloList.write_out(self, filename) - -class parallelHOPHaloList(HaloList,ParallelAnalysisInterface): - _name = "parallelHOP" - _halo_class = parallelHOPHalo - _fields = ["particle_position_%s" % ax for ax in 'xyz'] + \ - ["ParticleMassMsun", "particle_index"] - - def __init__(self, data_source, padding, num_neighbors, bounds, total_mass, - period, threshold=160.0, dm_only=True, rearrange=True, premerge=True): - """ - Run hop on *data_source* with a given density *threshold*. If - *dm_only* is set, only run it on the dark matter particles, otherwise - on all particles. Returns an iterable collection of *HopGroup* items. - """ - self.threshold = threshold - self.num_neighbors = num_neighbors - self.bounds = bounds - self.total_mass = total_mass - self.rearrange = rearrange - self.period = period - self._data_source = data_source - self.premerge = premerge - mylog.info("Initializing HOP") - HaloList.__init__(self, data_source, dm_only) - - def _run_finder(self): - yt_counters("Reading Data") - # Test to make sure the particle IDs aren't suspicious. - exit = False - if (self.particle_fields["particle_index"] < 0).any(): - mylog.error("Negative values in particle_index field. Parallel HOP will fail.") - exit = True - if na.unique(self.particle_fields["particle_index"]).size != \ - self.particle_fields["particle_index"].size: - mylog.error("Non-unique values in particle_index field. Parallel HOP will fail.") - exit = True - self._mpi_exit_test(exit) - obj = RunParallelHOP(self.period, self.padding, - self.num_neighbors, self.bounds, - self.particle_fields["particle_position_x"], - self.particle_fields["particle_position_y"], - self.particle_fields["particle_position_z"], - self.particle_fields["particle_index"], - self.particle_fields["ParticleMassMsun"]/self.total_mass, - self.threshold, rearrange=self.rearrange, premerge=self.premerge) - self.densities, self.tags = obj.density, obj.chainID - # I'm going to go ahead and delete self.densities because it's not - # actually being used. I'm not going to remove it altogether because - # it may be useful to someone someday. - del self.densities - self.group_count = obj.group_count - self.group_sizes = obj.group_sizes - if self.group_count == 0: - mylog.info("There are no halos found.") - return - self.CoM = obj.CoM - self.Tot_M = obj.Tot_M * self.total_mass - self.max_dens_point = obj.max_dens_point - self.max_radius = obj.max_radius - # Precompute the bulk velocity in parallel. - yt_counters("Precomp bulk vel.") - self.bulk_vel = na.zeros((self.group_count, 3), dtype='float64') - yt_counters("bulk vel. reading data") - pm = self.particle_fields["ParticleMassMsun"] - if ytcfg.getboolean("yt","inline") == False: - xv = self._data_source["particle_velocity_x"][self._base_indices] - yv = self._data_source["particle_velocity_y"][self._base_indices] - zv = self._data_source["particle_velocity_z"][self._base_indices] - else: - xv = self._data_source["particle_velocity_x"][self._base_indices] - yv = self._data_source["particle_velocity_y"][self._base_indices] - zv = self._data_source["particle_velocity_z"][self._base_indices] - yt_counters("bulk vel. reading data") - yt_counters("bulk vel. computing") - select = (self.tags >= 0) - calc = len(na.where(select == True)[0]) - if calc: - vel = na.empty((calc, 3), dtype='float64') - ms = pm[select] - vel[:,0] = xv[select] * ms - vel[:,1] = yv[select] * ms - vel[:,2] = zv[select] * ms - subchain = self.tags[select] - sort = subchain.argsort() - vel = vel[sort] - sort_subchain = subchain[sort] - uniq_subchain = na.unique(sort_subchain) - diff_subchain = na.ediff1d(sort_subchain) - marks = (diff_subchain > 0) - marks = na.arange(calc)[marks] + 1 - marks = na.concatenate(([0], marks, [calc])) - for i, u in enumerate(uniq_subchain): - self.bulk_vel[u] = na.sum(vel[marks[i]:marks[i+1]], axis=0) - del vel, subchain, sort_subchain - del diff_subchain - # Bring it together, and divide by the previously computed total mass - # of each halo. - self.bulk_vel = self._mpi_Allsum_double(self.bulk_vel) - for groupID in xrange(self.group_count): - self.bulk_vel[groupID] = self.bulk_vel[groupID] / self.Tot_M[groupID] - yt_counters("bulk vel. computing") - # Now calculate the RMS velocity of the groups in parallel, very - # similarly to the bulk velocity and re-using some of the arrays. - yt_counters("rms vel computing") - rms_vel_temp = na.zeros((self.group_count,2), dtype='float64') - if calc: - vel = na.empty((calc, 3), dtype='float64') - vel[:,0] = xv[select] * ms - vel[:,1] = yv[select] * ms - vel[:,2] = zv[select] * ms - vel = vel[sort] - for i, u in enumerate(uniq_subchain): - # This finds the sum locally. - rms_vel_temp[u][0] = na.sum(((vel[marks[i]:marks[i+1]] - \ - self.bulk_vel[u]) / self.Tot_M[u])**2.) - # I could use self.group_sizes... - rms_vel_temp[u][1] = marks[i+1] - marks[i] - del vel, marks, uniq_subchain - # Bring it together. - rms_vel_temp = self._mpi_Allsum_double(rms_vel_temp) - self.rms_vel = na.empty(self.group_count, dtype='float64') - for groupID in xrange(self.group_count): - # Here we do the Mean and the Root. - self.rms_vel[groupID] = \ - na.sqrt(rms_vel_temp[groupID][0] / rms_vel_temp[groupID][1]) * \ - self.group_sizes[groupID] - del rms_vel_temp - yt_counters("rms vel computing") - self.taskID = obj.mine - self.halo_taskmap = obj.halo_taskmap # A defaultdict. - del obj - yt_counters("Precomp bulk vel.") - - def _parse_output(self): - yt_counters("Final Grouping") - """ - Each task will make an entry for all groups, but it may be empty. - """ - unique_ids = na.unique(self.tags) - counts = na.bincount((self.tags+1).tolist()) - sort_indices = na.argsort(self.tags) - grab_indices = na.indices(self.tags.shape).ravel()[sort_indices] - del sort_indices - cp = 0 - index = 0 - # We want arrays for parallel HOP - self._groups = na.empty(self.group_count, dtype='object') - self._max_dens = na.empty((self.group_count, 4), dtype='float64') - if self.group_count == 0: - mylog.info("There are no halos found.") - return - for i in unique_ids: - if i == -1: - cp += counts[i+1] - continue - # If there is a gap in the unique_ids, make empty groups to - # fill it in. - while index < i: - self._groups[index] = self._halo_class(self, index, \ - size=self.group_sizes[index], CoM=self.CoM[index], \ - max_dens_point=self.max_dens_point[index], \ - group_total_mass=self.Tot_M[index], max_radius=self.max_radius[index], - bulk_vel=self.bulk_vel[index], tasks=self.halo_taskmap[index], - rms_vel=self.rms_vel[index]) - # I don't own this halo - self._do_not_claim_object(self._groups[index]) - self._max_dens[index] = [self.max_dens_point[index][0], self.max_dens_point[index][1], \ - self.max_dens_point[index][2], self.max_dens_point[index][3]] - index += 1 - cp_c = cp + counts[i+1] - group_indices = grab_indices[cp:cp_c] - self._groups[index] = self._halo_class(self, i, group_indices, \ - size=self.group_sizes[i], CoM=self.CoM[i], \ - max_dens_point=self.max_dens_point[i], \ - group_total_mass=self.Tot_M[i], max_radius=self.max_radius[i], - bulk_vel=self.bulk_vel[i], tasks=self.halo_taskmap[index], - rms_vel=self.rms_vel[i]) - # This halo may be owned by many, including this task - self._claim_object(self._groups[index]) - self._max_dens[index] = [self.max_dens_point[i][0], self.max_dens_point[i][1], \ - self.max_dens_point[i][2], self.max_dens_point[i][3]] - cp += counts[i+1] - index += 1 - # If there are missing groups at the end, add them. - while index < self.group_count: - self._groups[index] = self._halo_class(self, index, \ - size=self.group_sizes[index], CoM=self.CoM[index], \ - max_dens_point=self.max_dens_point[i], \ - group_total_mass=self.Tot_M[index], max_radius=self.max_radius[index], - bulk_vel=self.bulk_vel[index], tasks=self.halo_taskmap[index], - rms_vel=self.rms_vel[index]) - self._do_not_claim_object(self._groups[index]) - self._max_dens[index] = [self.max_dens_point[index][0], self.max_dens_point[index][1], \ - self.max_dens_point[index][2], self.max_dens_point[index][3]] - index += 1 - # Clean up - del self.max_dens_point, self.max_radius, self.bulk_vel - del self.halo_taskmap, self.tags, self.rms_vel - del grab_indices, unique_ids, counts - try: - del group_indices - except UnboundLocalError: - pass - - def __len__(self): - return self.group_count - - def write_out(self, filename="parallelHopAnalysis.out"): - r"""Write out standard halo information to a text file. - - Parameters - ---------- - filename : String - The name of the file to write to. - Default = "parallelHopAnalysis.out". - - Examples - -------- - >>> halos.write_out("parallelHopAnalysis.out") - """ - HaloList.write_out(self, filename) - -class GenericHaloFinder(HaloList, ParallelAnalysisInterface): - def __init__(self, pf, dm_only=True, padding=0.0): - self.pf = pf - self.hierarchy = pf.h - self.center = (pf["DomainRightEdge"] + pf["DomainLeftEdge"])/2.0 - - def _parse_halolist(self, threshold_adjustment): - groups, max_dens, hi = [], {}, 0 - LE, RE = self.bounds - for halo in self._groups: - this_max_dens = halo.maximum_density_location() - # if the most dense particle is in the box, keep it - if na.all((this_max_dens >= LE) & (this_max_dens <= RE)): - # Now we add the halo information to OURSELVES, taken from the - # self.hop_list - # We need to mock up the HOPHaloList thingie, so we need to set: - # self._max_dens - max_dens_temp = list(self._max_dens[halo.id])[0] / threshold_adjustment - max_dens[hi] = [max_dens_temp] + list(self._max_dens[halo.id])[1:4] - groups.append(self._halo_class(self, hi)) - groups[-1].indices = halo.indices - self._claim_object(groups[-1]) - hi += 1 - del self._groups, self._max_dens # explicit >> implicit - self._groups = groups - self._max_dens = max_dens - - def _join_halolists(self): - # First we get the total number of halos the entire collection - # has identified - # Note I have added a new method here to help us get information - # about processors and ownership and so forth. - # _mpi_info_dict returns a dict of {proc: whatever} where whatever is - # what is fed in on each proc. - mine, halo_info = self._mpi_info_dict(len(self)) - nhalos = sum(halo_info.values()) - # Figure out our offset - my_first_id = sum([v for k,v in halo_info.items() if k < mine]) - # Fix our max_dens - max_dens = {} - for i,m in self._max_dens.items(): max_dens[i+my_first_id] = m - self._max_dens = max_dens - for halo in self._groups: - halo._max_dens = self._max_dens - # sort the list by the size of the groups - # Now we add ghost halos and reassign all the IDs - # Note: we already know which halos we own! - after = my_first_id + len(self._groups) - # One single fake halo, not owned, does the trick - self._groups = [self._halo_class(self, i) for i in range(my_first_id)] + \ - self._groups + \ - [self._halo_class(self, i) for i in range(after, nhalos)] - id = 0 - for proc in sorted(halo_info.keys()): - for halo in self._groups[id:id+halo_info[proc]]: - halo.id = id - halo._distributed = self._distributed - halo._owner = proc - id += 1 - def haloCmp(h1,h2): - c = cmp(h1.total_mass(),h2.total_mass()) - if c != 0: - return -1 * c - if c == 0: - return cmp(h1.center_of_mass()[0],h2.center_of_mass()[0]) - self._groups.sort(haloCmp) - sorted_max_dens = {} - for i, halo in enumerate(self._groups): - if halo.id in self._max_dens: - sorted_max_dens[i] = self._max_dens[halo.id] - halo.id = i - self._max_dens = sorted_max_dens - for i, halo in enumerate(self._groups): - halo._max_dens = self._max_dens - - def _reposition_particles(self, bounds): - # This only does periodicity. We do NOT want to deal with anything - # else. The only reason we even do periodicity is the - LE, RE = bounds - dw = self.pf["DomainRightEdge"] - self.pf["DomainLeftEdge"] - for i, ax in enumerate('xyz'): - arr = self._data_source["particle_position_%s" % ax] - arr[arr < LE[i]-self.padding] += dw[i] - arr[arr > RE[i]+self.padding] -= dw[i] - - def write_out(self, filename): - r"""Write out standard halo information to a text file. - - Parameters - ---------- - filename : String - The name of the file to write to. - - Examples - -------- - >>> halos.write_out("HopAnalysis.out") - """ - f = self._write_on_root(filename) - HaloList.write_out(self, f) - - def write_particle_lists_txt(self, prefix): - r"""Write out the names of the HDF5 files containing halo particle data - to a text file. - - This function wirtes out the names of all the HDF5 files that would - contain halo particle data. Only the root processor writes out. - - Parameters - ---------- - prefix : String - The prefix for the name of the file. - - Examples - -------- - >>> halos.write_particle_lists_txt("halo-parts") - """ - f = self._write_on_root("%s.txt" % prefix) - HaloList.write_particle_lists_txt(self, prefix, fp=f) - - @parallel_blocking_call - def write_particle_lists(self, prefix): - r"""Write out the particle data for halos to HDF5 files. - - This function will accept a filename prefix, and for every halo it will - write out an HDF5 file containing the positions, velocities, indices - and masses of the constituent particles. However, if the halo finder - is run in parallel, halos will only be written out on the processors to - which they belong. See `Halo.write_particle_lists_txt` for how to - track these halos globally across files. - - Parameters - ---------- - prefix : String - The prefix for the name(s) of the HDF5 files. - - Examples - -------- - >>> halos.write_particle_lists("halo-parts") - """ - fn = "%s.h5" % self._get_filename(prefix) - f = h5py.File(fn, "w") - for halo in self._groups: - if not self._is_mine(halo): continue - halo.write_particle_list(f) - -class parallelHF(GenericHaloFinder, parallelHOPHaloList): - def __init__(self, pf, threshold=160, dm_only=True, resize=True, rearrange=True,\ - fancy_padding=True, safety=1.5, premerge=True, sample=0.03): - r"""Parallel HOP halo finder. - - Halos are built by: - 1. Calculating a density for each particle based on a smoothing kernel. - 2. Recursively linking particles to other particles from lower density - particles to higher. - 3. Geometrically proximate chains are identified and - 4. merged into final halos following merging rules. - - Lower thresholds generally produce more halos, and the largest halos - become larger. Also, halos become more filamentary and over-connected. - - This is very similar to HOP, but it does not produce precisely the - same halos due to unavoidable numerical differences. - - Skory et al. "Parallel HOP: A Scalable Halo Finder for Massive - Cosmological Data Sets." arXiv (2010) 1001.3411 - - Parameters - ---------- - pf : EnzoStaticOutput object - threshold : float - The density threshold used when building halos. Default = 160.0. - dm_only : bool - If True, only dark matter particles are used when building halos. - Default = False. - resize : bool - Turns load-balancing on or off. Default = True. - rearrange : bool - Turns on faster nearest neighbor searches at the cost of increased - memory usage. Default = True. - fancy_padding : bool - True calculates padding independently for each face of each - subvolume. Default = True. - safety : float - Due to variances in inter-particle spacing in the volume, the - padding may need to be increased above the raw calculation. - This number is multiplied to the calculated padding, and values - >1 increase the padding. Default = 1.5. - premerge : bool - True merges chains in two steps (rather than one with False), which - can speed up halo finding by 25% or more. However, True can result - in small (<<1%) variations in the final halo masses when compared - to False. Default = True. - sample : float - The fraction of the full dataset on which load-balancing is - performed. Default = 0.03. - - Examples - ------- - >>> pf = load("RedshiftOutput0000") - >>> halos = parallelHF(pf) - """ - GenericHaloFinder.__init__(self, pf, dm_only, padding=0.0) - self.padding = 0.0 - self.num_neighbors = 65 - self.safety = safety - self.sample = sample - period = pf["DomainRightEdge"] - pf["DomainLeftEdge"] - topbounds = na.array([[0., 0., 0.], period]) - # Cut up the volume evenly initially, with no padding. - padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) - # also get the total mass of particles - yt_counters("Reading Data") - # Adaptive subregions by bisection. - ds_names = ["particle_position_x","particle_position_y","particle_position_z"] - if ytcfg.getboolean("yt","inline") == False and \ - resize and self._mpi_get_size() != 1: - random.seed(self._mpi_get_rank()) - cut_list = self._partition_hierarchy_3d_bisection_list() - root_points = self._subsample_points() - self.bucket_bounds = [] - if self._mpi_get_rank() == 0: - self._recursive_divide(root_points, topbounds, 0, cut_list) - self.bucket_bounds = self._mpi_bcast_pickled(self.bucket_bounds) - my_bounds = self.bucket_bounds[self._mpi_get_rank()] - LE, RE = my_bounds[0], my_bounds[1] - self._data_source = self.hierarchy.region_strict([0.]*3, LE, RE) - # If this isn't parallel, define the region as an AMRRegionStrict so - # particle IO works. - if self._mpi_get_size() == 1: - self._data_source = self.hierarchy.periodic_region_strict([0.5]*3, LE, RE) - # get the average spacing between particles for this region - # The except is for the serial case, where the full box is what we want. - if ytcfg.getboolean("yt","inline") == False: - data = self._data_source["particle_position_x"] - else: - data = self._data_source["particle_position_x"] - try: - l = self._data_source.right_edge - self._data_source.left_edge - except AttributeError: - l = pf["DomainRightEdge"] - pf["DomainLeftEdge"] - vol = l[0] * l[1] * l[2] - full_vol = vol - if not fancy_padding: - avg_spacing = (float(vol) / data.size)**(1./3.) - # padding is a function of inter-particle spacing, this is an - # approximation, but it's OK with the safety factor - padding = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing - self.padding = (na.ones(3,dtype='float64')*padding, na.ones(3,dtype='float64')*padding) - mylog.info('padding %s avg_spacing %f vol %f local_parts %d' % \ - (str(self.padding), avg_spacing, vol, data.size)) - # Another approach to padding, perhaps more accurate. - elif fancy_padding and self._distributed: - LE_padding, RE_padding = na.empty(3,dtype='float64'), na.empty(3,dtype='float64') - avg_spacing = (float(vol) / data.size)**(1./3.) - base_padding = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing - for dim in xrange(3): - if ytcfg.getboolean("yt","inline") == False: - data = self._data_source[ds_names[dim]] - else: - data = self._data_source[ds_names[dim]] - num_bins = 1000 - width = self._data_source.right_edge[dim] - self._data_source.left_edge[dim] - area = (self._data_source.right_edge[(dim+1)%3] - self._data_source.left_edge[(dim+1)%3]) * \ - (self._data_source.right_edge[(dim+2)%3] - self._data_source.left_edge[(dim+2)%3]) - bin_width = base_padding - num_bins = int(math.ceil(width / bin_width)) - bins = na.arange(num_bins+1, dtype='float64') * bin_width + self._data_source.left_edge[dim] - counts, bins = na.histogram(data, bins, new=True) - # left side. - start = 0 - count = counts[0] - while count < self.num_neighbors: - start += 1 - count += counts[start] - # Get the avg spacing in just this boundary. - vol = area * (bins[start+1] - bins[0]) - avg_spacing = (float(vol) / count)**(1./3.) - LE_padding[dim] = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing - # right side. - start = -1 - count = counts[-1] - while count < self.num_neighbors: - start -= 1 - count += counts[start] - vol = area * (bins[-1] - bins[start-1]) - avg_spacing = (float(vol) / count)**(1./3.) - RE_padding[dim] = (self.num_neighbors)**(1./3.) * self.safety * avg_spacing - self.padding = (LE_padding, RE_padding) - del bins, counts - mylog.info('fancy_padding %s avg_spacing %f full_vol %f local_parts %d %s' % \ - (str(self.padding), avg_spacing, full_vol, data.size, str(self._data_source))) - # Now we get the full box mass after we have the final composition of - # subvolumes. - if ytcfg.getboolean("yt","inline") == False: - total_mass = self._mpi_allsum((self._data_source["ParticleMassMsun"].astype('float64')).sum()) - else: - total_mass = self._mpi_allsum((self._data_source["ParticleMassMsun"].astype('float64')).sum()) - if not self._distributed: - self.padding = (na.zeros(3,dtype='float64'), na.zeros(3,dtype='float64')) - self.bounds = (LE, RE) - (LE_padding, RE_padding) = self.padding - parallelHOPHaloList.__init__(self, self._data_source, self.padding, \ - self.num_neighbors, self.bounds, total_mass, period, \ - threshold=threshold, dm_only=dm_only, rearrange=rearrange, premerge=premerge) - self._join_halolists() - yt_counters("Final Grouping") - - def _subsample_points(self): - # Read in a random subset of the points in each domain, and then - # collect them on the root task. - xp = self._data_source["particle_position_x"] - n_parts = self._mpi_allsum(xp.size) - local_parts = xp.size - random_points = int(self.sample * n_parts) - # We want to get a representative selection of random particles in - # each subvolume. - adjust = float(local_parts) / ( float(n_parts) / self._mpi_get_size()) - n_random = int(adjust * float(random_points) / self._mpi_get_size()) - mylog.info("Reading in %d random particles." % n_random) - # Get unique random particles. - my_points = na.empty((n_random, 3), dtype='float64') - uni = na.array(random.sample(xrange(xp.size), n_random)) - uni = uni[uni.argsort()] - my_points[:,0] = xp[uni] - del xp - self._data_source.clear_data() - my_points[:,1] = self._data_source["particle_position_y"][uni] - self._data_source.clear_data() - my_points[:,2] = self._data_source["particle_position_z"][uni] - self._data_source.clear_data() - del uni - # Collect them on the root task. - mine, sizes = self._mpi_info_dict(n_random) - if mine == 0: - tot_random = sum(sizes.values()) - root_points = na.empty((tot_random, 3), dtype='float64') - root_points.shape = (1, 3*tot_random) - else: - root_points = na.empty([]) - my_points.shape = (1, n_random*3) - root_points = self._mpi_concatenate_array_on_root_double(my_points[0]) - del my_points - if mine == 0: - root_points.shape = (tot_random, 3) - return root_points - - def _recursive_divide(self, points, bounds, level, cut_list): - dim = cut_list[level][0] - parts = points.shape[0] - num_bins = 1000 - width = bounds[1][dim] - bounds[0][dim] - bin_width = width / num_bins - bins = na.arange(num_bins+1, dtype='float64') * bin_width + bounds[0][dim] - counts, bins = na.histogram(points[:,dim], bins) - # Find the bin that passes the cut points. - midpoints = [bounds[0][dim]] - sum = 0 - bin = 0 - for step in xrange(1,cut_list[level][1]): - while sum < ((parts*step)/cut_list[level][1]): - lastsum = sum - sum += counts[bin] - bin += 1 - # Bin edges - left_edge = bins[bin-1] - right_edge = bins[bin] - # Find a better approx of the midpoint cut line using a linear approx. - a = float(sum - lastsum) / (right_edge - left_edge) - midpoints.append(left_edge + (0.5 - (float(lastsum) / parts / 2)) / a) - midpoints.append(bounds[1][dim]) - - # Split the points & update the bounds. - subpoints = [] - subbounds = [] - for pair in zip(midpoints[:-1],midpoints[1:]): - select = na.bitwise_and(points[:,dim] >= pair[0], - points[:,dim] < pair[1]) - subpoints.append(points[select]) - nb = bounds.copy() - nb[0][dim] = pair[0] - nb[1][dim] = pair[1] - subbounds.append(nb) - # If we're at the maxlevel, make a bucket. Otherwise, recurse down. - maxlevel = len(cut_list) - 1 - for pair in zip(subpoints, subbounds): - if level == maxlevel: - self.bucket_bounds.append(pair[1]) - else: - self._recursive_divide(pair[0], pair[1], level+1, cut_list) - - def _join_halolists(self): - if self.group_count == 0: - mylog.info("There are no halos found.") - return - ms = -self.Tot_M.copy() - del self.Tot_M - Cx = self.CoM[:,0].copy() - sorted = na.lexsort([Cx, ms]) - del Cx, ms - self._groups = self._groups[sorted] - self._max_dens = self._max_dens[sorted] - for i in xrange(self.group_count): - self._groups[i].id = i - del sorted, self.group_sizes, self.CoM - - -class HOPHaloFinder(GenericHaloFinder, HOPHaloList): - def __init__(self, pf, threshold=160, dm_only=True, padding=0.02): - r"""HOP halo finder. - - Halos are built by: - 1. Calculating a density for each particle based on a smoothing kernel. - 2. Recursively linking particles to other particles from lower density - particles to higher. - 3. Geometrically proximate chains are identified and - 4. merged into final halos following merging rules. - - Lower thresholds generally produce more halos, and the largest halos - become larger. Also, halos become more filamentary and over-connected. - - Eisenstein and Hut. "HOP: A New Group-Finding Algorithm for N-Body - Simulations." ApJ (1998) vol. 498 pp. 137-142 - - Parameters - ---------- - pf : EnzoStaticOutput object - threshold : float - The density threshold used when building halos. Default = 160.0. - dm_only : bool - If True, only dark matter particles are used when building halos. - Default = False. - padding : float - When run in parallel, the finder needs to surround each subvolume - with duplicated particles for halo finidng to work. This number - must be no smaller than the radius of the largest halo in the box - in code units. Default = 0.02. - - Examples - ------- - >>> pf = load("RedshiftOutput0000") - >>> halos = HaloFinder(pf) - """ - GenericHaloFinder.__init__(self, pf, dm_only, padding) - - # do it once with no padding so the total_mass is correct (no duplicated particles) - self.padding = 0.0 - padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) - # For scaling the threshold, note that it's a passthrough - if dm_only: - select = self._get_dm_indices() - total_mass = self._mpi_allsum((self._data_source["ParticleMassMsun"][select]).sum()) - else: - total_mass = self._mpi_allsum(self._data_source["ParticleMassMsun"].sum()) - # MJT: Note that instead of this, if we are assuming that the particles - # are all on different processors, we should instead construct an - # object representing the entire domain and sum it "lazily" with - # Derived Quantities. - self.padding = padding #* pf["unitary"] # This should be clevererer - padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) - self.bounds = (LE, RE) - # reflect particles around the periodic boundary - #self._reposition_particles((LE, RE)) - if dm_only: - select = self._get_dm_indices() - sub_mass = self._data_source["ParticleMassMsun"][select].sum() - else: - sub_mass = self._data_source["ParticleMassMsun"].sum() - HOPHaloList.__init__(self, self._data_source, threshold*total_mass/sub_mass, dm_only) - self._parse_halolist(total_mass/sub_mass) - self._join_halolists() - -class FOFHaloFinder(GenericHaloFinder, FOFHaloList): - def __init__(self, pf, link=0.2, dm_only=True, padding=0.02): - r"""Friends-of-friends halo finder. - - Halos are found by linking together all pairs of particles closer than - some distance from each other. Particles may have multiple links, - and halos are found by recursively linking together all such pairs. - - Larger linking lengths produce more halos, and the largest halos - become larger. Also, halos become more filamentary and over-connected. - - Davis et al. "The evolution of large-scale structure in a universe - dominated by cold dark matter." ApJ (1985) vol. 292 pp. 371-394 - - Parameters - ---------- - pf : EnzoStaticOutput object - link : float - The interparticle distance (compared to the overall average) - used to build the halos. Default = 0.2. - dm_only : bool - If True, only dark matter particles are used when building halos. - Default = False. - padding : float - When run in parallel, the finder needs to surround each subvolume - with duplicated particles for halo finidng to work. This number - must be no smaller than the radius of the largest halo in the box - in code units. Default = 0.02. - - Examples - ------- - >>> pf = load("RedshiftOutput0000") - >>> halos = FOFHaloFinder(pf) - """ - self.pf = pf - self.hierarchy = pf.h - self.center = (pf["DomainRightEdge"] + pf["DomainLeftEdge"])/2.0 - self.padding = 0.0 #* pf["unitary"] # This should be clevererer - # get the total number of particles across all procs, with no padding - padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) - n_parts = self._mpi_allsum(self._data_source["particle_position_x"].size) - # get the average spacing between particles - l = pf["DomainRightEdge"] - pf["DomainLeftEdge"] - vol = l[0] * l[1] * l[2] - avg_spacing = (float(vol) / n_parts)**(1./3.) - self.padding = padding - padded, LE, RE, self._data_source = self._partition_hierarchy_3d(padding=self.padding) - self.bounds = (LE, RE) - # reflect particles around the periodic boundary - #self._reposition_particles((LE, RE)) - # here is where the FOF halo finder is run - FOFHaloList.__init__(self, self._data_source, link * avg_spacing, dm_only) - self._parse_halolist(1.) - self._join_halolists() - -HaloFinder = HOPHaloFinder diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/HelperFunctions.py --- a/yt/lagos/HelperFunctions.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,162 +0,0 @@ -""" -A collection of helper functions, most generally for things -that SciPy doesn't have that I expected it to - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * - -class UnilinearFieldInterpolator: - def __init__(self, table, boundaries, field_names, truncate=False): - self.table = table.astype('float64') - self.truncate = truncate - x0, x1 = boundaries - self.x_name = field_names - self.x_bins = na.linspace(x0, x1, table.shape[0]).astype('float64') - - def __call__(self, data_object): - orig_shape = data_object[self.x_name].shape - x_vals = data_object[self.x_name].ravel().astype('float64') - - x_i = (na.digitize(x_vals, self.x_bins) - 1).astype('int32') - if na.any((x_i == -1) | (x_i == len(self.x_bins)-1)): - if not self.truncate: - mylog.error("Sorry, but your values are outside" + \ - " the table! Dunno what to do, so dying.") - mylog.error("Error was in: %s", data_object) - raise ValueError - else: - x_i = na.minimum(na.maximum(x_i,0), len(self.x_bins)-2) - - my_vals = na.zeros(x_vals.shape, dtype='float64') - amr_utils.UnilinearlyInterpolate(self.table, x_vals, self.x_bins, x_i, my_vals) - return my_vals.reshape(orig_shape) - -class BilinearFieldInterpolator: - def __init__(self, table, boundaries, field_names, truncate=False): - self.table = table.astype('float64') - self.truncate = truncate - x0, x1, y0, y1 = boundaries - self.x_name, self.y_name = field_names - self.x_bins = na.linspace(x0, x1, table.shape[0]).astype('float64') - self.y_bins = na.linspace(y0, y1, table.shape[1]).astype('float64') - - def __call__(self, data_object): - orig_shape = data_object[self.x_name].shape - x_vals = data_object[self.x_name].ravel().astype('float64') - y_vals = data_object[self.y_name].ravel().astype('float64') - - x_i = (na.digitize(x_vals, self.x_bins) - 1).astype('int32') - y_i = (na.digitize(y_vals, self.y_bins) - 1).astype('int32') - if na.any((x_i == -1) | (x_i == len(self.x_bins)-1)) \ - or na.any((y_i == -1) | (y_i == len(self.y_bins)-1)): - if not self.truncate: - mylog.error("Sorry, but your values are outside" + \ - " the table! Dunno what to do, so dying.") - mylog.error("Error was in: %s", data_object) - raise ValueError - else: - x_i = na.minimum(na.maximum(x_i,0), len(self.x_bins)-2) - y_i = na.minimum(na.maximum(y_i,0), len(self.y_bins)-2) - - my_vals = na.zeros(x_vals.shape, dtype='float64') - amr_utils.BilinearlyInterpolate(self.table, - x_vals, y_vals, self.x_bins, self.y_bins, - x_i, y_i, my_vals) - return my_vals.reshape(orig_shape) - -class TrilinearFieldInterpolator: - def __init__(self, table, boundaries, field_names, truncate = False): - self.table = table.astype('float64') - self.truncate = truncate - x0, x1, y0, y1, z0, z1 = boundaries - self.x_name, self.y_name, self.z_name = field_names - self.x_bins = na.linspace(x0, x1, table.shape[0]).astype('float64') - self.y_bins = na.linspace(y0, y1, table.shape[1]).astype('float64') - self.z_bins = na.linspace(z0, z1, table.shape[2]).astype('float64') - - def __call__(self, data_object): - orig_shape = data_object[self.x_name].shape - x_vals = data_object[self.x_name].ravel().astype('float64') - y_vals = data_object[self.y_name].ravel().astype('float64') - z_vals = data_object[self.z_name].ravel().astype('float64') - - x_i = na.digitize(x_vals, self.x_bins) - 1 - y_i = na.digitize(y_vals, self.y_bins) - 1 - z_i = na.digitize(z_vals, self.z_bins) - 1 - if na.any((x_i == -1) | (x_i == len(self.x_bins)-1)) \ - or na.any((y_i == -1) | (y_i == len(self.y_bins)-1)) \ - or na.any((z_i == -1) | (z_i == len(self.z_bins)-1)): - if not self.truncate: - mylog.error("Sorry, but your values are outside" + \ - " the table! Dunno what to do, so dying.") - mylog.error("Error was in: %s", data_object) - raise ValueError - else: - x_i = na.minimum(na.maximum(x_i,0), len(self.x_bins)-2) - y_i = na.minimum(na.maximum(y_i,0), len(self.y_bins)-2) - z_i = na.minimum(na.maximum(z_i,0), len(self.z_bins)-2) - - my_vals = na.zeros(x_vals.shape, dtype='float64') - amr_utils.TrilinearlyInterpolate(self.table, - x_vals, y_vals, z_vals, - self.x_bins, self.y_bins, self.z_bins, - x_i, y_i, z_i, my_vals) - return my_vals.reshape(orig_shape) - - # Use notation from Paul Bourke's page on interpolation - # http://local.wasp.uwa.edu.au/~pbourke/other/interpolation/ - x = (x_vals - self.x_bins[x_i]) / (self.x_bins[x_i+1] - self.x_bins[x_i]) - y = (y_vals - self.y_bins[y_i]) / (self.y_bins[y_i+1] - self.y_bins[y_i]) - z = (z_vals - self.z_bins[z_i]) / (self.z_bins[z_i+1] - self.z_bins[z_i]) - xm = (self.x_bins[x_i+1] - x_vals) / (self.x_bins[x_i+1] - self.x_bins[x_i]) - ym = (self.y_bins[y_i+1] - y_vals) / (self.y_bins[y_i+1] - self.y_bins[y_i]) - zm = (self.z_bins[z_i+1] - z_vals) / (self.z_bins[z_i+1] - self.z_bins[z_i]) - if na.any(na.isnan(self.table)): - raise ValueError - if na.any(na.isnan(x) | na.isnan(y) | na.isnan(z)): - raise ValueError - if na.any(na.isnan(xm) | na.isnan(ym) | na.isnan(zm)): - raise ValueError - my_vals = self.table[x_i ,y_i ,z_i ] * (xm*ym*zm) - my_vals += self.table[x_i+1,y_i ,z_i ] * (x *ym*zm) - my_vals += self.table[x_i ,y_i+1,z_i ] * (xm*y *zm) - my_vals += self.table[x_i ,y_i ,z_i+1] * (xm*ym*z ) - my_vals += self.table[x_i+1,y_i ,z_i+1] * (x *ym*z ) - my_vals += self.table[x_i ,y_i+1,z_i+1] * (xm*y *z ) - my_vals += self.table[x_i+1,y_i+1,z_i ] * (x *y *zm) - my_vals += self.table[x_i+1,y_i+1,z_i+1] * (x *y *z ) - return my_vals.reshape(orig_shape) - -def get_centers(pf, filename, center_cols, radius_col, unit='1'): - """ - Return an iterator over EnzoSphere objects generated from the appropriate - columns in *filename*. Optionally specify the *unit* radius is in. - """ - sp_list = [] - for line in open(filename): - if line.startswith("#"): continue - vals = line.split() - x,y,z = [float(vals[i]) for i in center_cols] - r = float(vals[radius_col]) - yield pf.h.sphere([x,y,z], r/pf[unit]) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/HierarchyType.py --- a/yt/lagos/HierarchyType.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1863 +0,0 @@ -""" -AMR hierarchy container class - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * -from yt.funcs import * -import string, re, gc, time, cPickle, pdb -from itertools import chain, izip -try: - import yt.ramses_reader as ramses_reader -except ImportError: - mylog.warning("Ramses Reader not imported") - -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 AMRHierarchy(ObjectFindingMixin, ParallelAnalysisInterface): - float_type = 'float64' - - def __init__(self, pf, data_style): - self.parameter_file = weakref.proxy(pf) - self.pf = self.parameter_file - - self._initialize_state_variables() - - mylog.debug("Initializing data storage.") - self._initialize_data_storage() - - mylog.debug("Counting grids.") - self._count_grids() - - # Must be defined in subclass - mylog.debug("Setting up classes.") - self._setup_classes() - - mylog.debug("Counting grids.") - self._initialize_grid_arrays() - - mylog.debug("Parsing hierarchy.") - self._parse_hierarchy() - - mylog.debug("Constructing grid objects.") - self._populate_grid_objects() - - mylog.debug("Initializing data grid data IO") - self._setup_data_io() - - mylog.debug("Detecting fields.") - self._detect_fields() - - mylog.debug("Adding unknown detected fields") - self._setup_unknown_fields() - - mylog.debug("Setting up derived fields") - self._setup_derived_fields() - - mylog.debug("Re-examining hierarchy") - self._initialize_level_stats() - - def _get_parameters(self): - return self.parameter_file.parameters - parameters=property(_get_parameters) - - def select_grids(self, level): - """ - Returns an array of grids at *level*. - """ - return self.grids[self.grid_levels.flat == level] - - def get_levels(self): - for level in range(self.max_level+1): - yield self.select_grids(level) - - def _initialize_state_variables(self): - self._parallel_locking = False - self._data_file = None - self._data_mode = None - self._max_locations = {} - self.num_grids = None - - def _initialize_grid_arrays(self): - mylog.debug("Allocating arrays for %s grids", self.num_grids) - self.grid_dimensions = na.ones((self.num_grids,3), 'int32') - self.grid_left_edge = na.zeros((self.num_grids,3), self.float_type) - self.grid_right_edge = na.ones((self.num_grids,3), self.float_type) - self.grid_levels = na.zeros((self.num_grids,1), 'int32') - self.grid_particle_count = na.zeros((self.num_grids,1), 'int32') - - def _setup_classes(self, dd): - # Called by subclass - self.object_types = [] - self.objects = [] - for name, cls in sorted(data_object_registry.items()): - cname = cls.__name__ - if cname.endswith("Base"): cname = cname[:-4] - self._add_object_class(name, cname, cls, dd) - self.object_types.sort() - - # Now all the object related stuff - - def all_data(self, find_max=False): - pf = self.parameter_file - if find_max: c = self.find_max("Density")[1] - else: c = (pf["DomainRightEdge"] + pf["DomainLeftEdge"])/2.0 - return self.region(c, - pf["DomainLeftEdge"], pf["DomainRightEdge"]) - - def clear_all_data(self): - """ - This routine clears all the data currently being held onto by the grids - and the data io handler. - """ - for g in self.grids: g.clear_data() - self.io.queue.clear() - - def _get_data_reader_dict(self): - dd = { 'pf' : self.parameter_file, # Already weak - 'hierarchy': weakref.proxy(self) } - return dd - - def _initialize_data_storage(self): - if not ytcfg.getboolean('lagos','serialize'): return - fn = self.pf.storage_filename - if fn is None: - if os.path.isfile(os.path.join(self.directory, - "%s.yt" % self.pf["CurrentTimeIdentifier"])): - fn = os.path.join(self.directory,"%s.yt" % self.pf["CurrentTimeIdentifier"]) - else: - fn = os.path.join(self.directory, - "%s.yt" % self.parameter_file.basename) - dir_to_check = os.path.dirname(fn) - # We have four options: - # Writeable, does not exist : create, open as append - # Writeable, does exist : open as append - # Not writeable, does not exist : do not attempt to open - # Not writeable, does exist : open as read-only - exists = os.path.isfile(fn) - if not exists: - writeable = os.access(dir_to_check, os.W_OK) - else: - writeable = os.access(fn, os.W_OK) - writeable = writeable and not ytcfg.getboolean('lagos','onlydeserialize') - # We now have our conditional stuff - self._barrier() - if not writeable and not exists: return - if writeable: - self._data_mode = 'a' - if not exists: self.__create_data_file(fn) - else: - self._data_mode = 'r' - - self.__data_filename = fn - self._data_file = h5py.File(fn, self._data_mode) - - def __create_data_file(self, fn): - # Note that this used to be parallel_root_only; it no longer is, - # because we have better logic to decide who owns the file. - f = h5py.File(fn, 'a') - f.close() - - def _setup_data_io(self): - self.io = io_registry[self.data_style]() - - def _save_data(self, array, node, name, set_attr=None, force=False, passthrough = False): - """ - Arbitrary numpy data will be saved to the region in the datafile - described by *node* and *name*. If data file does not exist, it throws - no error and simply does not save. - """ - - if self._data_mode != 'a': return - if "ArgsError" in dir(h5py.h5): - exception = h5py.h5.ArgsError - else: - exception = h5py.h5.H5Error - try: - node_loc = self._data_file[node] - if name in node_loc.listnames() and force: - mylog.info("Overwriting node %s/%s", node, name) - del self._data_file[node][name] - elif name in node_loc.listnames() and passthrough: - return - except exception: - pass - myGroup = self._data_file['/'] - for q in node.split('/'): - if q: myGroup = myGroup.require_group(q) - arr = myGroup.create_dataset(name,data=array) - if set_attr is not None: - for i, j in set_attr.items(): arr.attrs[i] = j - self._data_file.flush() - - def _reload_data_file(self, *args, **kwargs): - if self._data_file is None: return - self._data_file.close() - del self._data_file - self._data_file = h5py.File(self.__data_filename, self._data_mode) - - def _reset_save_data(self,round_robin=False): - if round_robin: - self.save_data = self._save_data - else: - self.save_data = parallel_splitter(self._save_data, self._reload_data_file) - - save_data = parallel_splitter(_save_data, _reload_data_file) - - def save_object(self, obj, name): - """ - Save an object (*obj*) to the data_file using the Pickle protocol, - under the name *name* on the node /Objects. - """ - s = cPickle.dumps(obj, protocol=-1) - self.save_data(s, "/Objects", name, force = True) - - def load_object(self, name): - """ - Load and return and object from the data_file using the Pickle protocol, - under the name *name* on the node /Objects. - """ - obj = self.get_data("/Objects", name) - if obj is None: - return - obj = cPickle.loads(obj.value) - if iterable(obj) and len(obj) == 2: - obj = obj[1] # Just the object, not the pf - if hasattr(obj, '_fix_pickle'): obj._fix_pickle() - return obj - - def get_data(self, node, name): - """ - Return the dataset with a given *name* located at *node* in the - datafile. - """ - if self._data_file == None: - return None - if node[0] != "/": node = "/%s" % node - - myGroup = self._data_file['/'] - for group in node.split('/'): - if group: - if group not in myGroup.listnames(): - return None - myGroup = myGroup[group] - if name not in myGroup.listnames(): - return None - - full_name = "%s/%s" % (node, name) - try: - return self._data_file[full_name][:] - except TypeError: - return self._data_file[full_name] - - def _close_data_file(self): - if self._data_file: - self._data_file.close() - del self._data_file - self._data_file = None - - def _deserialize_hierarchy(self, harray): - # THIS IS BROKEN AND NEEDS TO BE FIXED - mylog.debug("Cached entry found.") - self.gridDimensions[:] = harray[:,0:3] - self.gridStartIndices[:] = harray[:,3:6] - self.gridEndIndices[:] = harray[:,6:9] - self.gridLeftEdge[:] = harray[:,9:12] - self.gridRightEdge[:] = harray[:,12:15] - self.gridLevels[:] = harray[:,15:16] - self.gridTimes[:] = harray[:,16:17] - self.gridNumberOfParticles[:] = harray[:,17:18] - - def get_smallest_dx(self): - """ - Returns (in code units) the smallest cell size in the simulation. - """ - return self.select_grids(self.grid_levels.max())[0].dds[0] - - def _add_object_class(self, name, class_name, base, dd): - self.object_types.append(name) - obj = classobj(class_name, (base,), dd) - setattr(self, name, obj) - - def _initialize_level_stats(self): - # Now some statistics: - # 0 = number of grids - # 1 = number of cells - # 2 = blank - desc = {'names': ['numgrids','numcells','level'], - 'formats':['Int32']*3} - self.level_stats = blankRecordArray(desc, MAXLEVEL) - self.level_stats['level'] = [i for i in range(MAXLEVEL)] - self.level_stats['numgrids'] = [0 for i in range(MAXLEVEL)] - self.level_stats['numcells'] = [0 for i in range(MAXLEVEL)] - for level in xrange(self.max_level+1): - self.level_stats[level]['numgrids'] = na.sum(self.grid_levels == level) - li = (self.grid_levels[:,0] == level) - self.level_stats[level]['numcells'] = self.grid_dimensions[li,:].prod(axis=1).sum() - - @property - def grid_corners(self): - return na.array([ - [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_left_edge[:,2]], - [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_left_edge[:,2]], - [self.grid_right_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]], - [self.grid_right_edge[:,0], self.grid_right_edge[:,1], self.grid_right_edge[:,2]], - [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_right_edge[:,2]], - [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]], - [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]], - [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]], - ], dtype='float64') - - def print_stats(self): - """ - Prints out (stdout) relevant information about the simulation - """ - for level in xrange(MAXLEVEL): - if (self.level_stats['numgrids'][level]) == 0: - break - print "% 3i\t% 6i\t% 11i" % \ - (level, self.level_stats['numgrids'][level], - self.level_stats['numcells'][level]) - dx = self.select_grids(level)[0].dds[0] - print "-" * 28 - print " \t% 6i\t% 11i" % (self.level_stats['numgrids'].sum(), self.level_stats['numcells'].sum()) - print "\n" - try: - print "z = %0.8f" % (self["CosmologyCurrentRedshift"]) - except: - pass - t_s = self.pf["InitialTime"] * self.pf["Time"] - print "t = %0.8e = %0.8e s = %0.8e years" % \ - (self.pf["InitialTime"], \ - t_s, t_s / (365*24*3600.0) ) - print "\nSmallest Cell:" - u=[] - for item in self.parameter_file.units.items(): - u.append((item[1],item[0])) - u.sort() - for unit in u: - print "\tWidth: %0.3e %s" % (dx*unit[0], unit[1]) - - -class EnzoHierarchy(AMRHierarchy): - - _strip_path = False - grid = EnzoGrid - - def __init__(self, pf, data_style): - - self.data_style = data_style - self.hierarchy_filename = os.path.abspath( - "%s.hierarchy" % (pf.parameter_filename)) - harray_fn = self.hierarchy_filename[:-9] + "harrays" - if os.path.exists(harray_fn): - try: - harray_fp = h5py.File(harray_fn) - self.num_grids = harray_fp["/Level"].len() - except IOError: - pass - elif os.path.getsize(self.hierarchy_filename) == 0: - raise IOError(-1,"File empty", self.hierarchy_filename) - self.directory = os.path.dirname(self.hierarchy_filename) - - # For some reason, r8 seems to want Float64 - if pf.has_key("CompilerPrecision") \ - and pf["CompilerPrecision"] == "r4": - self.float_type = 'float32' - else: - self.float_type = 'float64' - - AMRHierarchy.__init__(self, pf, data_style) - # sync it back - self.parameter_file.data_style = self.data_style - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _count_grids(self): - test_grid = test_grid_id = None - self.num_stars = 0 - for line in rlines(open(self.hierarchy_filename, "rb")): - if line.startswith("BaryonFileName") or \ - line.startswith("ParticleFileName") or \ - line.startswith("FileName "): - test_grid = line.split("=")[-1].strip().rstrip() - if line.startswith("NumberOfStarParticles"): - self.num_stars = int(line.split("=")[-1]) - if line.startswith("Grid "): - self.num_grids = test_grid_id = int(line.split("=")[-1]) - break - self._guess_data_style(self.pf["TopGridRank"], test_grid, test_grid_id) - - def _guess_data_style(self, rank, test_grid, test_grid_id): - if test_grid[0] != os.path.sep: - test_grid = os.path.join(self.directory, test_grid) - if not os.path.exists(test_grid): - test_grid = os.path.join(self.directory, - os.path.basename(test_grid)) - mylog.debug("Your data uses the annoying hardcoded path.") - self._strip_path = True - if self.data_style is not None: return - try: - a = SD.SD(test_grid) - self.data_style = 'enzo_hdf4' - mylog.debug("Detected HDF4") - except: - list_of_sets = HDF5LightReader.ReadListOfDatasets(test_grid, "/") - if len(list_of_sets) == 0 and rank == 3: - mylog.debug("Detected packed HDF5") - self.data_style = 'enzo_packed_3d' - elif len(list_of_sets) > 0 and rank == 3: - mylog.debug("Detected unpacked HDF5") - self.data_style = 'enzo_hdf5' - elif len(list_of_sets) == 0 and rank == 2: - mylog.debug("Detect packed 2D") - self.data_style = 'enzo_packed_2d' - elif len(list_of_sets) == 0 and rank == 1: - mylog.debug("Detect packed 1D") - self.data_style = 'enzo_packed_1d' - else: - raise TypeError - - # Sets are sorted, so that won't work! - def _parse_hierarchy(self): - def _next_token_line(token, f): - line = f.readline() - while token not in line: - line = f.readline() - return line.split()[2:] - if os.path.exists(self.hierarchy_filename[:-9] + "harrays"): - if self._parse_binary_hierarchy(): return - t1 = time.time() - pattern = r"Pointer: Grid\[(\d*)\]->NextGrid(Next|This)Level = (\d*)\s+$" - patt = re.compile(pattern) - f = open(self.hierarchy_filename, "rb") - self.grids = [self.grid(1, self)] - self.grids[0].Level = 0 - si, ei, LE, RE, fn, np = [], [], [], [], [], [] - all = [si, ei, LE, RE, fn] - f.readline() # Blank at top - for grid_id in xrange(self.num_grids): - # We will unroll this list - si.append(_next_token_line("GridStartIndex", f)) - ei.append(_next_token_line("GridEndIndex", f)) - LE.append(_next_token_line("GridLeftEdge", f)) - RE.append(_next_token_line("GridRightEdge", f)) - nb = int(_next_token_line("NumberOfBaryonFields", f)[0]) - fn.append(["-1"]) - if nb > 0: fn[-1] = _next_token_line("BaryonFileName", f) - np.append(int(_next_token_line("NumberOfParticles", f)[0])) - if nb == 0 and np[-1] > 0: fn[-1] = _next_token_line("FileName", f) - line = f.readline() - while len(line) > 2: - if line.startswith("Pointer:"): - vv = patt.findall(line)[0] - self.__pointer_handler(vv) - line = f.readline() - continue - params = line.split() - line = f.readline() - self._fill_arrays(ei, si, LE, RE, np) - self.grids = na.array(self.grids, dtype='object') - self.filenames = fn - self._store_binary_hierarchy() - t2 = time.time() - - def _fill_arrays(self, ei, si, LE, RE, np): - self.grid_dimensions.flat[:] = ei - self.grid_dimensions -= na.array(si, self.float_type) - self.grid_dimensions += 1 - self.grid_left_edge.flat[:] = LE - self.grid_right_edge.flat[:] = RE - self.grid_particle_count.flat[:] = np - - def __pointer_handler(self, m): - sgi = int(m[2])-1 - if sgi == -1: return # if it's 0, then we're done with that lineage - # Okay, so, we have a pointer. We make a new grid, with an id of the length+1 - # (recall, Enzo grids are 1-indexed) - self.grids.append(self.grid(len(self.grids)+1, self)) - # We'll just go ahead and make a weakref to cache - second_grid = self.grids[sgi] # zero-indexed already - first_grid = self.grids[int(m[0])-1] - if m[1] == "Next": - first_grid._children_ids.append(second_grid.id) - second_grid._parent_id = first_grid.id - second_grid.Level = first_grid.Level + 1 - elif m[1] == "This": - if first_grid.Parent is not None: - first_grid.Parent._children_ids.append(second_grid.id) - second_grid._parent_id = first_grid._parent_id - second_grid.Level = first_grid.Level - self.grid_levels[sgi] = second_grid.Level - - _bn = "%s.cpu%%04i" - def _parse_binary_hierarchy(self): - mylog.info("Getting the binary hierarchy") - try: - f = h5py.File(self.hierarchy_filename[:-9] + "harrays") - except h5py.h5.H5Error: - return False - self.grid_dimensions[:] = f["/ActiveDimensions"][:] - self.grid_left_edge[:] = f["/LeftEdges"][:] - self.grid_right_edge[:] = f["/RightEdges"][:] - self.grid_particle_count[:,0] = f["/NumberOfParticles"][:] - levels = f["/Level"][:] - parents = f["/ParentIDs"][:] - procs = f["/Processor"][:] - grids = [] - self.filenames = [] - grids = [self.grid(gi+1, self) for gi in xrange(self.num_grids)] - giter = izip(grids, levels, procs, parents) - bn = self._bn % (self.pf) - pmap = [(bn % P,) for P in xrange(procs.max()+1)] - for grid,L,P,Pid in giter: - grid.Level = L - grid._parent_id = Pid - if Pid > -1: - grids[Pid-1]._children_ids.append(grid.id) - self.filenames.append(pmap[P]) - self.grids = na.array(grids, dtype='object') - f.close() - mylog.info("Finished with binary hierarchy reading") - return True - - @parallel_blocking_call - def _store_binary_hierarchy(self): - # We don't do any of the logic here, we just check if the data file - # is open... - if self._data_file is None: return - if self._data_mode == 'r': return - if self.data_style != "enzo_packed_3d": return - mylog.info("Storing the binary hierarchy") - try: - f = h5py.File(self.hierarchy_filename[:-9] + "harrays", "w") - except IOError: - return - f.create_dataset("/LeftEdges", data=self.grid_left_edge) - f.create_dataset("/RightEdges", data=self.grid_right_edge) - parents, procs, levels = [], [], [] - for i,g in enumerate(self.grids): - if g.Parent is not None: - parents.append(g.Parent.id) - else: - parents.append(-1) - procs.append(int(self.filenames[i][0][-4:])) - levels.append(g.Level) - - parents = na.array(parents, dtype='int64') - procs = na.array(procs, dtype='int64') - levels = na.array(levels, dtype='int64') - f.create_dataset("/ParentIDs", data=parents) - f.create_dataset("/Processor", data=procs) - f.create_dataset("/Level", data=levels) - - f.create_dataset("/ActiveDimensions", data=self.grid_dimensions) - f.create_dataset("/NumberOfParticles", data=self.grid_particle_count[:,0]) - - f.close() - - def _rebuild_top_grids(self, level = 0): - #for level in xrange(self.max_level+1): - mylog.info("Rebuilding grids on level %s", level) - cmask = (self.grid_levels.flat == (level + 1)) - cmsum = cmask.sum() - mask = na.zeros(self.num_grids, dtype='bool') - for grid in self.select_grids(level): - mask[:] = 0 - LE = self.grid_left_edge[grid.id - grid._id_offset] - RE = self.grid_right_edge[grid.id - grid._id_offset] - grids, grid_i = self.get_box_grids(LE, RE) - mask[grid_i] = 1 - grid._children_ids = [] - cgrids = self.grids[ ( mask * cmask).astype('bool') ] - mylog.info("%s: %s / %s", grid, len(cgrids), cmsum) - for cgrid in cgrids: - grid._children_ids.append(cgrid.id) - cgrid._parent_id = grid.id - mylog.info("Finished rebuilding") - - def _populate_grid_objects(self): - for g,f in izip(self.grids, self.filenames): - g._prepare_grid() - g._setup_dx() - g.set_filename(f[0]) - #if g.Parent is not None: g._guess_properties_from_parent() - del self.filenames # No longer needed. - self.max_level = self.grid_levels.max() - - def _detect_fields(self): - self.field_list = [] - # Do this only on the root processor to save disk work. - if self._mpi_get_rank() == 0 or self._mpi_get_rank() == None: - field_list = self.get_data("/", "DataFields") - if field_list is None: - mylog.info("Gathering a field list (this may take a moment.)") - field_list = set() - random_sample = self._generate_random_grids() - for grid in random_sample: - if not hasattr(grid, 'filename'): continue - try: - gf = self.io._read_field_names(grid) - except self.io._read_exception: - mylog.debug("Grid %s is a bit funky?", grid.id) - continue - mylog.debug("Grid %s has: %s", grid.id, gf) - field_list = field_list.union(gf) - else: - field_list = None - field_list = self._mpi_bcast_pickled(field_list) - self.save_data(list(field_list),"/","DataFields",passthrough=True) - self.field_list = list(field_list) - - def _setup_unknown_fields(self): - for field in self.field_list: - if field in self.parameter_file.field_info: continue - mylog.info("Adding %s to list of fields", field) - cf = None - if self.parameter_file.has_key(field): - def external_wrapper(f): - def _convert_function(data): - return data.convert(f) - return _convert_function - cf = external_wrapper(field) - add_field(field, lambda a, b: None, - convert_function=cf, take_log=False) - - def _setup_derived_fields(self): - self.derived_field_list = [] - for field in self.parameter_file.field_info: - try: - fd = self.parameter_file.field_info[field].get_dependencies( - pf = self.parameter_file) - except: - continue - available = na.all([f in self.field_list for f in fd.requested]) - if available: self.derived_field_list.append(field) - for field in self.field_list: - if field not in self.derived_field_list: - self.derived_field_list.append(field) - - def _generate_random_grids(self): - if self.num_grids > 40: - starter = na.random.randint(0, 20) - random_sample = na.mgrid[starter:len(self.grids)-1:20j].astype("int32") - mylog.debug("Checking grids: %s", random_sample.tolist()) - else: - random_sample = na.mgrid[0:max(len(self.grids)-1,1)].astype("int32") - return self.grids[(random_sample,)] - - def find_particles_by_type(self, ptype, max_num=None, additional_fields=None): - """ - Returns a structure of arrays with all of the particles' - positions, velocities, masses, types, IDs, and attributes for - a particle type **ptype** for a maximum of **max_num** - particles. If non-default particle fields are used, provide - them in **additional_fields**. - """ - # Not sure whether this routine should be in the general HierarchyType. - if self.grid_particle_count.sum() == 0: - mylog.info("Data contains no particles."); - return None - if additional_fields is None: - additional_fields = ['metallicity_fraction', 'creation_time', - 'dynamical_time'] - pfields = [f for f in self.field_list if f.startswith('particle_')] - nattr = self.parameter_file['NumberOfParticleAttributes'] - if nattr > 0: - pfields += additional_fields[:nattr] - # Find where the particles reside and count them - if max_num is None: max_num = 1e100 - total = 0 - pstore = [] - for level in range(self.max_level, -1, -1): - for grid in self.select_grids(level): - index = na.where(grid['particle_type'] == ptype)[0] - total += len(index) - pstore.append(index) - if total >= max_num: break - if total >= max_num: break - result = None - if total > 0: - result = {} - for p in pfields: - result[p] = na.zeros(total, 'float64') - # Now we retrieve data for each field - ig = count = 0 - for level in range(self.max_level, -1, -1): - for grid in self.select_grids(level): - nidx = len(pstore[ig]) - if nidx > 0: - for p in pfields: - result[p][count:count+nidx] = grid[p][pstore[ig]] - count += nidx - ig += 1 - if count >= total: break - if count >= total: break - # Crop data if retrieved more than max_num - if count > max_num: - for p in pfields: - result[p] = result[p][0:max_num] - return result - - -class EnzoHierarchyInMemory(EnzoHierarchy): - - grid = EnzoGridInMemory - _enzo = None - - @property - def enzo(self): - if self._enzo is None: - import enzo - self._enzo = enzo - return self._enzo - - def __init__(self, pf, data_style = None): - self.data_style = data_style - self.float_type = 'float64' - self.parameter_file = weakref.proxy(pf) # for _obtain_enzo - self.float_type = self.enzo.hierarchy_information["GridLeftEdge"].dtype - self.directory = os.getcwd() - AMRHierarchy.__init__(self, pf, data_style) - - def _initialize_data_storage(self): - pass - - def _count_grids(self): - self.num_grids = self.enzo.hierarchy_information["GridDimensions"].shape[0] - - def _parse_hierarchy(self): - self._copy_hierarchy_structure() - mylog.debug("Copying reverse tree") - reverse_tree = self.enzo.hierarchy_information["GridParentIDs"].ravel().tolist() - # Initial setup: - mylog.debug("Reconstructing parent-child relationships") - self.grids = [] - # We enumerate, so it's 0-indexed id and 1-indexed pid - self.filenames = ["-1"] * self.num_grids - for id,pid in enumerate(reverse_tree): - self.grids.append(self.grid(id+1, self)) - self.grids[-1].Level = self.grid_levels[id] - if pid > 0: - self.grids[-1]._parent_id = pid - self.grids[pid-1]._children_ids.append(self.grids[-1].id) - self.max_level = self.grid_levels.max() - mylog.debug("Preparing grids") - for i, grid in enumerate(self.grids): - if (i%1e4) == 0: mylog.debug("Prepared % 7i / % 7i grids", i, self.num_grids) - grid.filename = None - grid._prepare_grid() - grid.proc_num = self.grid_procs[i,0] - self.grids = na.array(self.grids, dtype='object') - mylog.debug("Prepared") - - def _initialize_grid_arrays(self): - EnzoHierarchy._initialize_grid_arrays(self) - self.grid_procs = na.zeros((self.num_grids,1),'int32') - - def _copy_hierarchy_structure(self): - # Dimensions are important! - self.grid_dimensions[:] = self.enzo.hierarchy_information["GridEndIndices"][:] - self.grid_dimensions -= self.enzo.hierarchy_information["GridStartIndices"][:] - self.grid_dimensions += 1 - self.grid_left_edge[:] = self.enzo.hierarchy_information["GridLeftEdge"][:] - self.grid_right_edge[:] = self.enzo.hierarchy_information["GridRightEdge"][:] - self.grid_levels[:] = self.enzo.hierarchy_information["GridLevels"][:] - self.grid_procs = self.enzo.hierarchy_information["GridProcs"].copy() - self.grid_particle_count[:] = self.enzo.hierarchy_information["GridNumberOfParticles"][:] - - def save_data(self, *args, **kwargs): - pass - -class EnzoHierarchy1D(EnzoHierarchy): - - def _fill_arrays(self, ei, si, LE, RE, np): - self.grid_dimensions[:,:1] = ei - self.grid_dimensions[:,:1] -= na.array(si, self.float_type) - self.grid_dimensions += 1 - self.grid_left_edge[:,:1] = LE - self.grid_right_edge[:,:1] = RE - self.grid_particle_count.flat[:] = np - self.grid_left_edge[:,1:] = 0.0 - self.grid_right_edge[:,1:] = 1.0 - self.grid_dimensions[:,1:] = 1 - -class EnzoHierarchy2D(EnzoHierarchy): - - def _fill_arrays(self, ei, si, LE, RE, np): - self.grid_dimensions[:,:2] = ei - self.grid_dimensions[:,:2] -= na.array(si, self.float_type) - self.grid_dimensions += 1 - self.grid_left_edge[:,:2] = LE - self.grid_right_edge[:,:2] = RE - self.grid_particle_count.flat[:] = np - self.grid_left_edge[:,2] = 0.0 - self.grid_right_edge[:,2] = 1.0 - self.grid_dimensions[:,2] = 1 - -scanf_regex = {} -scanf_regex['e'] = r"[-+]?\d+\.?\d*?|\.\d+[eE][-+]?\d+?" -scanf_regex['g'] = scanf_regex['e'] -scanf_regex['f'] = scanf_regex['e'] -scanf_regex['F'] = scanf_regex['e'] -#scanf_regex['g'] = r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" -#scanf_regex['f'] = r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" -#scanf_regex['F'] = r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" -scanf_regex['i'] = r"[-+]?(0[xX][\dA-Fa-f]+|0[0-7]*|\d+)" -scanf_regex['d'] = r"[-+]?\d+" -scanf_regex['s'] = r"\S+" - -def constructRegularExpressions(param, toReadTypes): - re_e=r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" - re_i=r"[-+]?(0[xX][\dA-Fa-f]+|0[0-7]*|\d+)" - rs = "^%s\s*=\s*" % (param) - for t in toReadTypes: - rs += "(%s)\s*" % (scanf_regex[t]) - rs +="$" - return re.compile(rs,re.M) - -# These next two functions are taken from -# http://www.reddit.com/r/Python/comments/6hj75/reverse_file_iterator/c03vms4 -# Credit goes to "Brian" on Reddit - -def rblocks(f, blocksize=4096): - """Read file as series of blocks from end of file to start. - - The data itself is in normal order, only the order of the blocks is reversed. - ie. "hello world" -> ["ld","wor", "lo ", "hel"] - Note that the file must be opened in binary mode. - """ - if 'b' not in f.mode.lower(): - raise Exception("File must be opened using binary mode.") - size = os.stat(f.name).st_size - fullblocks, lastblock = divmod(size, blocksize) - - # The first(end of file) block will be short, since this leaves - # the rest aligned on a blocksize boundary. This may be more - # efficient than having the last (first in file) block be short - f.seek(-lastblock,2) - yield f.read(lastblock) - - for i in range(fullblocks-1,-1, -1): - f.seek(i * blocksize) - yield f.read(blocksize) - -def rlines(f, keepends=False): - """Iterate through the lines of a file in reverse order. - - If keepends is true, line endings are kept as part of the line. - """ - buf = '' - for block in rblocks(f): - buf = block + buf - lines = buf.splitlines(keepends) - # Return all lines except the first (since may be partial) - if lines: - lines.reverse() - buf = lines.pop() # Last line becomes end of new first line. - for line in lines: - yield line - yield buf # First line. - -class OrionHierarchy(AMRHierarchy): - grid = OrionGrid - def __init__(self, pf, data_style='orion_native'): - self.field_info = OrionFieldContainer() - self.field_indexes = {} - self.parameter_file = weakref.proxy(pf) - header_filename = os.path.join(pf.fullplotdir,'Header') - self.directory = pf.fullpath - self.data_style = data_style - #self._setup_classes() - - self.readGlobalHeader(header_filename,self.parameter_file.paranoid_read) # also sets up the grid objects - self.__cache_endianness(self.levels[-1].grids[-1]) - AMRHierarchy.__init__(self,pf, self.data_style) - self._setup_data_io() - self._setup_field_list() - self._populate_hierarchy() - - def readGlobalHeader(self,filename,paranoid_read): - """ - read the global header file for an Orion plotfile output. - """ - counter = 0 - header_file = open(filename,'r') - self.__global_header_lines = header_file.readlines() - - # parse the file - self.orion_version = self.__global_header_lines[0].rstrip() - self.n_fields = int(self.__global_header_lines[1]) - - counter = self.n_fields+2 - self.field_list = [] - for i,line in enumerate(self.__global_header_lines[2:counter]): - self.field_list.append(line.rstrip()) - - # this is unused...eliminate it? - #for f in self.field_indexes: - # self.field_list.append(orion2ytFieldsDict.get(f,f)) - - self.dimension = int(self.__global_header_lines[counter]) - if self.dimension != 3: - raise RunTimeError("Orion must be in 3D to use yt.") - counter += 1 - self.Time = float(self.__global_header_lines[counter]) - counter += 1 - self.finest_grid_level = int(self.__global_header_lines[counter]) - self.n_levels = self.finest_grid_level + 1 - counter += 1 - # quantities with _unnecessary are also stored in the inputs - # file and are not needed. they are read in and stored in - # case in the future we want to enable a "backwards" way of - # taking the data out of the Header file and using it to fill - # in in the case of a missing inputs file - self.domainLeftEdge_unnecessary = na.array(map(float,self.__global_header_lines[counter].split())) - counter += 1 - self.domainRightEdge_unnecessary = na.array(map(float,self.__global_header_lines[counter].split())) - counter += 1 - self.refinementFactor_unnecessary = self.__global_header_lines[counter].split() #na.array(map(int,self.__global_header_lines[counter].split())) - counter += 1 - self.globalIndexSpace_unnecessary = self.__global_header_lines[counter] - #domain_re.search(self.__global_header_lines[counter]).groups() - counter += 1 - self.timestepsPerLevel_unnecessary = self.__global_header_lines[counter] - counter += 1 - self.dx = na.zeros((self.n_levels,3)) - for i,line in enumerate(self.__global_header_lines[counter:counter+self.n_levels]): - self.dx[i] = na.array(map(float,line.split())) - counter += self.n_levels - self.geometry = int(self.__global_header_lines[counter]) - if self.geometry != 0: - raise RunTimeError("yt only supports cartesian coordinates.") - counter += 1 - - # this is just to debug. eventually it should go away. - linebreak = int(self.__global_header_lines[counter]) - if linebreak != 0: - raise RunTimeError("INTERNAL ERROR! This should be a zero.") - counter += 1 - - # each level is one group with ngrids on it. each grid has 3 lines of 2 reals - self.levels = [] - grid_counter = 0 - file_finder_pattern = r"FabOnDisk: (\w+_D_[0-9]{4}) (\d+)\n" - re_file_finder = re.compile(file_finder_pattern) - dim_finder_pattern = r"\(\((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\) \(\d+,\d+,\d+\)\)\n" - re_dim_finder = re.compile(dim_finder_pattern) - data_files_pattern = r"Level_[\d]/" - data_files_finder = re.compile(data_files_pattern) - - for level in range(0,self.n_levels): - tmp = self.__global_header_lines[counter].split() - # should this be grid_time or level_time?? - lev,ngrids,grid_time = int(tmp[0]),int(tmp[1]),float(tmp[2]) - counter += 1 - nsteps = int(self.__global_header_lines[counter]) - counter += 1 - self.levels.append(OrionLevel(lev,ngrids)) - # open level header, extract file names and offsets for - # each grid - # read slightly out of order here: at the end of the lo,hi - # pairs for x,y,z is a *list* of files types in the Level - # directory. each type has Header and a number of data - # files (one per processor) - tmp_offset = counter + 3*ngrids - nfiles = 0 - key_off = 0 - files = {} # dict(map(lambda a: (a,[]),self.field_list)) - offsets = {} # dict(map(lambda a: (a,[]),self.field_list)) - while nfiles+tmp_offset < len(self.__global_header_lines) and data_files_finder.match(self.__global_header_lines[nfiles+tmp_offset]): - filen = os.path.join(self.parameter_file.fullplotdir, \ - self.__global_header_lines[nfiles+tmp_offset].strip()) - # open each "_H" header file, and get the number of - # components within it - level_header_file = open(filen+'_H','r').read() - start_stop_index = re_dim_finder.findall(level_header_file) # just take the last one - grid_file_offset = re_file_finder.findall(level_header_file) - ncomp_this_file = int(level_header_file.split('\n')[2]) - for i in range(ncomp_this_file): - key = self.field_list[i+key_off] - f,o = zip(*grid_file_offset) - files[key] = f - offsets[key] = o - self.field_indexes[key] = i - key_off += ncomp_this_file - nfiles += 1 - # convert dict of lists to list of dicts - fn = [] - off = [] - lead_path = os.path.join(self.parameter_file.fullplotdir,'Level_%i'%level) - for i in range(ngrids): - fi = [os.path.join(lead_path,files[key][i]) for key in self.field_list] - of = [int(offsets[key][i]) for key in self.field_list] - fn.append(dict(zip(self.field_list,fi))) - off.append(dict(zip(self.field_list,of))) - - for grid in range(0,ngrids): - gfn = fn[grid] # filename of file containing this grid - gfo = off[grid] # offset within that file - xlo,xhi = map(float,self.__global_header_lines[counter].split()) - counter+=1 - ylo,yhi = map(float,self.__global_header_lines[counter].split()) - counter+=1 - zlo,zhi = map(float,self.__global_header_lines[counter].split()) - counter+=1 - lo = na.array([xlo,ylo,zlo]) - hi = na.array([xhi,yhi,zhi]) - dims,start,stop = self.__calculate_grid_dimensions(start_stop_index[grid]) - self.levels[-1].grids.append(self.grid(lo,hi,grid_counter,level,gfn, gfo, dims,start,stop,paranoia=paranoid_read,hierarchy=self)) - grid_counter += 1 # this is global, and shouldn't be reset - # for each level - - # already read the filenames above... - counter+=nfiles - self.num_grids = grid_counter - self.float_type = 'float64' - - self.maxLevel = self.n_levels - 1 - self.max_level = self.n_levels - 1 - header_file.close() - - def __cache_endianness(self,test_grid): - """ - Cache the endianness and bytes perreal of the grids by using a - test grid and assuming that all grids have the same - endianness. This is a pretty safe assumption since Orion uses - one file per processor, and if you're running on a cluster - with different endian processors, then you're on your own! - """ - # open the test file & grab the header - inFile = open(os.path.expanduser(test_grid.filename[self.field_list[0]]),'rb') - header = inFile.readline() - inFile.close() - header.strip() - - # parse it. the patter is in OrionDefs.py - headerRe = re.compile(orion_FAB_header_pattern) - bytesPerReal,endian,start,stop,centerType,nComponents = headerRe.search(header).groups() - self._bytesPerReal = int(bytesPerReal) - if self._bytesPerReal == int(endian[0]): - dtype = '<' - elif self._bytesPerReal == int(endian[-1]): - dtype = '>' - else: - raise ValueError("FAB header is neither big nor little endian. Perhaps the file is corrupt?") - - dtype += ('f%i' % self._bytesPerReal) # always a floating point - self._dtype = dtype - - def __calculate_grid_dimensions(self,start_stop): - start = na.array(map(int,start_stop[0].split(','))) - stop = na.array(map(int,start_stop[1].split(','))) - dimension = stop - start + 1 - return dimension,start,stop - - def _populate_grid_objects(self): - mylog.debug("Creating grid objects") - self.grids = na.concatenate([level.grids for level in self.levels]) - self.grid_levels = na.concatenate([level.ngrids*[level.level] for level in self.levels]) - self.grid_levels = self.grid_levels.reshape((self.num_grids,1)) - grid_dcs = na.concatenate([level.ngrids*[self.dx[level.level]] for level in self.levels],axis=0) - self.grid_dxs = grid_dcs[:,0].reshape((self.num_grids,1)) - self.grid_dys = grid_dcs[:,1].reshape((self.num_grids,1)) - self.grid_dzs = grid_dcs[:,2].reshape((self.num_grids,1)) - left_edges = [] - right_edges = [] - dims = [] - for level in self.levels: - left_edges += [g.LeftEdge for g in level.grids] - right_edges += [g.RightEdge for g in level.grids] - dims += [g.ActiveDimensions for g in level.grids] - self.grid_left_edge = na.array(left_edges) - self.grid_right_edge = na.array(right_edges) - self.grid_dimensions = na.array(dims) - self.gridReverseTree = [] * self.num_grids - self.gridReverseTree = [ [] for i in range(self.num_grids)] - self.gridTree = [ [] for i in range(self.num_grids)] - mylog.debug("Done creating grid objects") - - def _populate_hierarchy(self): - self.__setup_grid_tree() - #self._setup_grid_corners() - for i, grid in enumerate(self.grids): - if (i%1e4) == 0: mylog.debug("Prepared % 7i / % 7i grids", i, self.num_grids) - grid._prepare_grid() - grid._setup_dx() - - def __setup_grid_tree(self): - for i, grid in enumerate(self.grids): - children = self._get_grid_children(grid) - for child in children: - self.gridReverseTree[child.id].append(i) - self.gridTree[i].append(weakref.proxy(child)) - - def _setup_classes(self): - dd = self._get_data_reader_dict() - dd["field_indexes"] = self.field_indexes - AMRHierarchy._setup_classes(self, dd) - #self._add_object_class('grid', "OrionGrid", OrionGridBase, dd) - self.object_types.sort() - - def _get_grid_children(self, grid): - mask = na.zeros(self.num_grids, dtype='bool') - grids, grid_ind = self.get_box_grids(grid.LeftEdge, grid.RightEdge) - mask[grid_ind] = True - mask = na.logical_and(mask, (self.grid_levels == (grid.Level+1)).flat) - return self.grids[mask] - - def _setup_field_list(self): - self.derived_field_list = [] - for field in self.field_info: - try: - fd = self.field_info[field].get_dependencies(pf = self.parameter_file) - except: - continue - available = na.all([f in self.field_list for f in fd.requested]) - if available: self.derived_field_list.append(field) - for field in self.field_list: - if field not in self.derived_field_list: - self.derived_field_list.append(field) - - def _count_grids(self): - """this is already provided in - - """ - pass - - def _initialize_grid_arrays(self): - mylog.debug("Allocating arrays for %s grids", self.num_grids) - self.grid_dimensions = na.ones((self.num_grids,3), 'int32') - self.grid_left_edge = na.zeros((self.num_grids,3), self.float_type) - self.grid_right_edge = na.ones((self.num_grids,3), self.float_type) - self.grid_levels = na.zeros((self.num_grids,1), 'int32') - self.grid_particle_count = na.zeros((self.num_grids,1), 'int32') - - def _parse_hierarchy(self): - pass - - def _detect_fields(self): - pass - - def _setup_unknown_fields(self): - for field in self.field_list: - if field in self.parameter_file.field_info: continue - mylog.info("Adding %s to list of fields", field) - cf = None - if self.parameter_file.has_key(field): - def external_wrapper(f): - def _convert_function(data): - return data.convert(f) - return _convert_function - cf = external_wrapper(field) - add_field(field, lambda a, b: None, - convert_function=cf, take_log=False) - - - def _setup_derived_fields(self): - pass - - def _initialize_state_variables(self): - """override to not re-initialize num_grids in AMRHierarchy.__init__ - - """ - self._parallel_locking = False - self._data_file = None - self._data_mode = None - self._max_locations = {} - -class OrionLevel: - def __init__(self,level,ngrids): - self.level = level - self.ngrids = ngrids - self.grids = [] - - -class GadgetHierarchy(AMRHierarchy): - grid = GadgetGrid - - def __init__(self, pf, data_style='gadget_hdf5'): - self.field_info = GadgetFieldContainer() - self.directory = os.path.dirname(pf.parameter_filename) - self.data_style = data_style - self._handle = h5py.File(pf.parameter_filename) - AMRHierarchy.__init__(self, pf, data_style) - self._handle.close() - - def _initialize_data_storage(self): - pass - - def _detect_fields(self): - #example string: - #"(S'VEL'\np1\nS'ID'\np2\nS'MASS'\np3\ntp4\n." - #fields are surrounded with ' - fields_string=self._handle['root'].attrs['fieldnames'] - #splits=fields_string.split("'") - #pick out the odd fields - #fields= [splits[j] for j in range(1,len(splits),2)] - self.field_list = cPickle.loads(fields_string) - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _count_grids(self): - fh = self._handle #shortcut - #nodes in the hdf5 file are the same as grids - #in yt - #the num of levels and total nodes is already saved - self._levels = self.pf._get_param('maxlevel') - self.num_grids = self.pf._get_param('numnodes') - - def _parse_hierarchy(self): - #for every box, define a self.grid(level,edge1,edge2) - #with particle counts, dimensions - f = self._handle #shortcut - - root = f['root'] - grids,numnodes = self._walk_nodes(None,root,[]) - dims = [self.pf.max_grid_size for grid in grids] - LE = [grid.LeftEdge for grid in grids] - RE = [grid.RightEdge for grid in grids] - levels = [grid.Level for grid in grids] - counts = [(grid.N if grid.IsLeaf else 0) for grid in grids] - self.grids = na.array(grids,dtype='object') - self.grid_dimensions[:] = na.array(dims, dtype='int64') - self.grid_left_edge[:] = na.array(LE, dtype='float64') - self.grid_right_edge[:] = na.array(RE, dtype='float64') - self.grid_levels.flat[:] = na.array(levels, dtype='int32') - self.grid_particle_count.flat[:] = na.array(counts, dtype='int32') - - def _walk_nodes(self,parent,node,grids,idx=0): - pi = cPickle.loads - loc = node.attrs['h5address'] - - kwargs = {} - kwargs['Address'] = loc - kwargs['Parent'] = parent - kwargs['Axis'] = self.pf._get_param('divideaxis',location=loc) - kwargs['Level'] = self.pf._get_param('level',location=loc) - kwargs['LeftEdge'] = self.pf._get_param('leftedge',location=loc) - kwargs['RightEdge'] = self.pf._get_param('rightedge',location=loc) - kwargs['IsLeaf'] = self.pf._get_param('isleaf',location=loc) - kwargs['N'] = self.pf._get_param('n',location=loc) - kwargs['NumberOfParticles'] = self.pf._get_param('n',location=loc) - dx = self.pf._get_param('dx',location=loc) - dy = self.pf._get_param('dy',location=loc) - dz = self.pf._get_param('dz',location=loc) - divdims = na.array([1,1,1]) - if not kwargs['IsLeaf']: - divdims[kwargs['Axis']] = 2 - kwargs['ActiveDimensions'] = divdims - #Active dimensions: - #This is the number of childnodes, along with dimensiolaity - #ie, binary tree can be (2,1,1) but octree is (2,2,2) - - idx+=1 - #pdb.set_trace() - children = [] - if not kwargs['IsLeaf']: - for child in node.values(): - children,idx=self._walk_nodes(node,child,children,idx=idx) - - kwargs['Children'] = children - grid = self.grid(idx,self.pf.parameter_filename,self,**kwargs) - grids += children - grids += [grid,] - return grids,idx - - def _populate_grid_objects(self): - for g in self.grids: - g._prepare_grid() - self.max_level = cPickle.loads(self._handle['root'].attrs['maxlevel']) - - def _setup_unknown_fields(self): - pass - - def _setup_derived_fields(self): - self.derived_field_list = [] - - def _get_grid_children(self, grid): - #given a grid, use it's address to find subchildren - pass - -class GadgetHierarchyOld(AMRHierarchy): - #Kept here to compare for the time being - grid = GadgetGrid - - def __init__(self, pf, data_style): - self.directory = pf.fullpath - self.data_style = data_style - AMRHierarchy.__init__(self, pf, data_style) - - def _count_grids(self): - # We actually construct our octree here! - # ...but we do read in our particles, it seems. - LE = na.zeros(3, dtype='float64') - RE = na.ones(3, dtype='float64') - base_grid = ProtoGadgetGrid(0, LE, RE, self.pf.particles) - self.proto_grids = base_grid.refine(8) - self.num_grids = len(self.proto_grids) - self.max_level = max( (g.level for g in self.proto_grids) ) - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _parse_hierarchy(self): - grids = [] - # We need to fill in dims, LE, RE, level, count - dims, LE, RE, levels, counts = [], [], [], [], [] - self.proto_grids.sort(key = lambda a: a.level) - for i, pg in enumerate(self.proto_grids): - g = self.grid(i, self, pg) - pg.real_grid = g - grids.append(g) - dims.append(g.ActiveDimensions) - LE.append(g.LeftEdge) - RE.append(g.RightEdge) - levels.append(g.Level) - counts.append(g.NumberOfParticles) - del self.proto_grids - self.grids = na.array(grids, dtype='object') - self.grid_dimensions[:] = na.array(dims, dtype='int64') - self.grid_left_edge[:] = na.array(LE, dtype='float64') - self.grid_right_edge[:] = na.array(RE, dtype='float64') - self.grid_levels.flat[:] = na.array(levels, dtype='int32') - self.grid_particle_count.flat[:] = na.array(counts, dtype='int32') - - def _populate_grid_objects(self): - # We don't need to do anything here - for g in self.grids: g._setup_dx() - - def _detect_fields(self): - self.field_list = ['particle_position_%s' % ax for ax in 'xyz'] - - def _setup_unknown_fields(self): - pass - - def _setup_derived_fields(self): - self.derived_field_list = [] - -class ChomboHierarchy(AMRHierarchy): - - grid = ChomboGrid - - def __init__(self,pf,data_style='chombo_hdf5'): - self.data_style = data_style - self.field_info = ChomboFieldContainer() - self.field_indexes = {} - self.parameter_file = weakref.proxy(pf) - # for now, the hierarchy file is the parameter file! - self.hierarchy_filename = self.parameter_file.parameter_filename - self.directory = os.path.dirname(self.hierarchy_filename) - self._fhandle = h5py.File(self.hierarchy_filename) - - self.float_type = self._fhandle['/level_0']['data:datatype=0'].dtype.name - self._levels = self._fhandle.listnames()[1:] - AMRHierarchy.__init__(self,pf,data_style) - - self._fhandle.close() - - def _initialize_data_storage(self): - pass - - def _detect_fields(self): - ncomp = int(self._fhandle['/'].attrs['num_components']) - self.field_list = [c[1] for c in self._fhandle['/'].attrs.listitems()[-ncomp:]] - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _count_grids(self): - self.num_grids = 0 - for lev in self._levels: - self.num_grids += self._fhandle[lev]['Processors'].len() - - def _parse_hierarchy(self): - f = self._fhandle # shortcut - - # this relies on the first Group in the H5 file being - # 'Chombo_global' - levels = f.listnames()[1:] - self.grids = [] - i = 0 - for lev in levels: - level_number = int(re.match('level_(\d+)',lev).groups()[0]) - boxes = f[lev]['boxes'].value - dx = f[lev].attrs['dx'] - for level_id, box in enumerate(boxes): - si = na.array([box['lo_%s' % ax] for ax in 'ijk']) - ei = na.array([box['hi_%s' % ax] for ax in 'ijk']) - pg = self.grid(len(self.grids),self,level=level_number, - start = si, stop = ei) - self.grids.append(pg) - self.grids[-1]._level_id = level_id - self.grid_left_edge[i] = dx*si.astype(self.float_type) - self.grid_right_edge[i] = dx*(ei.astype(self.float_type) + 1) - self.grid_particle_count[i] = 0 - self.grid_dimensions[i] = ei - si + 1 - i += 1 - self.grids = na.array(self.grids, dtype='object') - - def _populate_grid_objects(self): - for g in self.grids: - g._prepare_grid() - g._setup_dx() - - for g in self.grids: - g.Children = self._get_grid_children(g) - for g1 in g.Children: - g1.Parent.append(g) - self.max_level = self.grid_levels.max() - - def _setup_unknown_fields(self): - pass - - def _setup_derived_fields(self): - self.derived_field_list = [] - - def _get_grid_children(self, grid): - mask = na.zeros(self.num_grids, dtype='bool') - grids, grid_ind = self.get_box_grids(grid.LeftEdge, grid.RightEdge) - mask[grid_ind] = True - return [g for g in self.grids[mask] if g.Level == grid.Level + 1] - -class TigerHierarchy(AMRHierarchy): - - grid = TigerGrid - - def __init__(self, pf, data_style): - self.directory = pf.fullpath - self.data_style = data_style - AMRHierarchy.__init__(self, pf, data_style) - - def _count_grids(self): - # Tiger is unigrid - self.ngdims = [i/j for i,j in - izip(self.pf.root_size, self.pf.max_grid_size)] - self.num_grids = na.prod(self.ngdims) - self.max_level = 0 - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _parse_hierarchy(self): - grids = [] - # We need to fill in dims, LE, RE, level, count - dims, LE, RE, levels, counts = [], [], [], [], [] - DLE = self.pf["DomainLeftEdge"] - DRE = self.pf["DomainRightEdge"] - DW = DRE - DLE - gds = DW / self.ngdims - rd = [self.pf.root_size[i]-self.pf.max_grid_size[i] for i in range(3)] - glx, gly, glz = na.mgrid[DLE[0]:DRE[0]-gds[0]:self.ngdims[0]*1j, - DLE[1]:DRE[1]-gds[1]:self.ngdims[1]*1j, - DLE[2]:DRE[2]-gds[2]:self.ngdims[2]*1j] - gdx, gdy, gdz = na.mgrid[0:rd[0]:self.ngdims[0]*1j, - 0:rd[1]:self.ngdims[1]*1j, - 0:rd[2]:self.ngdims[2]*1j] - LE, RE, levels, counts = [], [], [], [] - i = 0 - for glei, gldi in izip(izip(glx.flat, gly.flat, glz.flat), - izip(gdx.flat, gdy.flat, gdz.flat)): - gld = na.array(gldi) - gle = na.array(glei) - gre = gle + gds - g = self.grid(i, self, gle, gre, gld, gld+self.pf.max_grid_size) - grids.append(g) - dims.append(self.pf.max_grid_size) - LE.append(g.LeftEdge) - RE.append(g.RightEdge) - levels.append(g.Level) - counts.append(g.NumberOfParticles) - i += 1 - self.grids = na.array(grids, dtype='object') - self.grid_dimensions[:] = na.array(dims, dtype='int64') - self.grid_left_edge[:] = na.array(LE, dtype='float64') - self.grid_right_edge[:] = na.array(RE, dtype='float64') - self.grid_levels.flat[:] = na.array(levels, dtype='int32') - self.grid_particle_count.flat[:] = na.array(counts, dtype='int32') - - def _populate_grid_objects(self): - # We don't need to do anything here - for g in self.grids: g._setup_dx() - - def _detect_fields(self): - self.file_mapping = {"Density" : "rhob", - "Temperature" : "temp"} - - @property - def field_list(self): - return self.file_mapping.keys() - - def _setup_unknown_fields(self): - for field in self.field_list: - add_tiger_field(field, lambda a, b: None) - - def _setup_derived_fields(self): - self.derived_field_list = [] - -class FLASHHierarchy(AMRHierarchy): - - grid = FLASHGrid - _handle = None - - def __init__(self,pf,data_style='chombo_hdf5'): - self.data_style = data_style - self.field_info = FLASHFieldContainer() - self.field_indexes = {} - self.parameter_file = weakref.proxy(pf) - # for now, the hierarchy file is the parameter file! - self.hierarchy_filename = self.parameter_file.parameter_filename - self.directory = os.path.dirname(self.hierarchy_filename) - self._handle = h5py.File(self.hierarchy_filename) - - self.float_type = na.float64 - AMRHierarchy.__init__(self,pf,data_style) - - self._handle.close() - self._handle = None - - def _initialize_data_storage(self): - pass - - def _detect_fields(self): - ncomp = self._handle["/unknown names"].shape[0] - self.field_list = [s.strip() for s in self._handle["/unknown names"][:].flat] - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _count_grids(self): - try: - self.num_grids = self.parameter_file._find_parameter( - "integer", "globalnumblocks", True, self._handle) - except KeyError: - self.num_grids = self._handle["/simulation parameters"][0][0] - - def _parse_hierarchy(self): - f = self._handle # shortcut - pf = self.parameter_file # shortcut - - self.grid_left_edge[:] = f["/bounding box"][:,:,0] - self.grid_right_edge[:] = f["/bounding box"][:,:,1] - # Move this to the parameter file - try: - nxb = pf._find_parameter("integer", "nxb", True, f) - nyb = pf._find_parameter("integer", "nyb", True, f) - nzb = pf._find_parameter("integer", "nzb", True, f) - except KeyError: - nxb, nyb, nzb = [int(f["/simulation parameters"]['n%sb' % ax]) - for ax in 'xyz'] - self.grid_dimensions[:] *= (nxb, nyb, nzb) - # particle count will need to be fixed somehow: - # by getting access to the particle file we can get the number of - # particles in each brick. but how do we handle accessing the - # particle file? - - # This will become redundant, as _prepare_grid will reset it to its - # current value. Note that FLASH uses 1-based indexing for refinement - # levels, but we do not, so we reduce the level by 1. - self.grid_levels.flat[:] = f["/refine level"][:][:] - 1 - g = [self.grid(i+1, self, self.grid_levels[i,0]) - for i in xrange(self.num_grids)] - self.grids = na.array(g, dtype='object') - - def _populate_grid_objects(self): - # We only handle 3D data, so offset is 7 (nfaces+1) - - offset = 7 - ii = na.argsort(self.grid_levels.flat) - gid = self._handle["/gid"][:] - for g in self.grids[ii].flat: - gi = g.id - g._id_offset - # FLASH uses 1-indexed group info - g.Children = [self.grids[i - 1] for i in gid[gi,7:] if i > -1] - for g1 in g.Children: - g1.Parent = g - g._prepare_grid() - g._setup_dx() - self.max_level = self.grid_levels.max() - - def _setup_unknown_fields(self): - for field in self.field_list: - if field in self.parameter_file.field_info: continue - mylog.info("Adding %s to list of fields", field) - cf = None - if self.parameter_file.has_key(field): - def external_wrapper(f): - def _convert_function(data): - return data.convert(f) - return _convert_function - cf = external_wrapper(field) - add_field(field, lambda a, b: None, - convert_function=cf, take_log=False) - - def _setup_derived_fields(self): - self.derived_field_list = [] - -class RAMSESHierarchy(AMRHierarchy): - - grid = RAMSESGrid - _handle = None - - def __init__(self,pf,data_style='ramses'): - self.data_style = data_style - self.field_info = RAMSESFieldContainer() - self.parameter_file = weakref.proxy(pf) - # for now, the hierarchy file is the parameter file! - self.hierarchy_filename = self.parameter_file.parameter_filename - self.directory = os.path.dirname(self.hierarchy_filename) - self.tree_proxy = pf.ramses_tree - - self.float_type = na.float64 - AMRHierarchy.__init__(self,pf,data_style) - - def _initialize_data_storage(self): - pass - - def _detect_fields(self): - self.field_list = self.tree_proxy.field_names[:] - - def _setup_classes(self): - dd = self._get_data_reader_dict() - AMRHierarchy._setup_classes(self, dd) - self.object_types.sort() - - def _count_grids(self): - # We have to do all the patch-coalescing here. - level_info = self.tree_proxy.count_zones() - num_ogrids = sum(level_info) - ogrid_left_edge = na.zeros((num_ogrids,3), dtype='float64') - ogrid_right_edge = na.zeros((num_ogrids,3), dtype='float64') - ogrid_levels = na.zeros((num_ogrids,1), dtype='int32') - ogrid_file_locations = na.zeros((num_ogrids,6), dtype='int64') - ochild_masks = na.zeros((num_ogrids, 8), dtype='int32') - self.tree_proxy.fill_hierarchy_arrays( - self.pf["TopGridDimensions"], - ogrid_left_edge, ogrid_right_edge, - ogrid_levels, ogrid_file_locations, ochild_masks) - # Now we can rescale - mi, ma = ogrid_left_edge.min(), ogrid_right_edge.max() - DL = self.pf["DomainLeftEdge"] - DR = self.pf["DomainRightEdge"] - ogrid_left_edge = (ogrid_left_edge - mi)/(ma - mi) * (DR - DL) + DL - ogrid_right_edge = (ogrid_right_edge - mi)/(ma - mi) * (DR - DL) + DL - #import pdb;pdb.set_trace() - # We now have enough information to run the patch coalescing - self.proto_grids = [] - for level in xrange(len(level_info)): - if level_info[level] == 0: continue - ggi = (ogrid_levels == level).ravel() - mylog.info("Re-gridding level %s: %s octree grids", level, ggi.sum()) - nd = self.pf["TopGridDimensions"] * 2**level - dims = na.ones((ggi.sum(), 3), dtype='int64') * 2 - fl = ogrid_file_locations[ggi,:] - # Now our initial protosubgrid - #if level == 6: raise RuntimeError - # We want grids that cover no more than MAX_EDGE cells in every direction - MAX_EDGE = 128 - psgs = [] - left_index = na.rint((ogrid_left_edge[ggi,:]) * nd).astype('int64') - right_index = left_index + 2 - lefts = [na.mgrid[0:nd[i]:MAX_EDGE] for i in range(3)] - #lefts = zip(*[l.ravel() for l in lefts]) - pbar = get_pbar("Re-gridding ", lefts[0].size) - min_ind = na.min(left_index, axis=0) - max_ind = na.max(right_index, axis=0) - for i,dli in enumerate(lefts[0]): - pbar.update(i) - if min_ind[0] > dli + nd[0]: continue - if max_ind[0] < dli: continue - idim = min(nd[0] - dli, MAX_EDGE) - gdi = ((dli <= right_index[:,0]) - & (dli + idim >= left_index[:,0])) - if not na.any(gdi): continue - for dlj in lefts[1]: - if min_ind[1] > dlj + nd[1]: continue - if max_ind[1] < dlj: continue - idim = min(nd[1] - dlj, MAX_EDGE) - gdj = ((dlj <= right_index[:,1]) - & (dlj + idim >= left_index[:,1]) - & (gdi)) - if not na.any(gdj): continue - for dlk in lefts[2]: - if min_ind[2] > dlk + nd[2]: continue - if max_ind[2] < dlk: continue - idim = min(nd[2] - dlk, MAX_EDGE) - gdk = ((dlk <= right_index[:,2]) - & (dlk + idim >= left_index[:,2]) - & (gdj)) - if not na.any(gdk): continue - left = na.array([dli, dlj, dlk]) - domain_left = left.ravel() - initial_left = na.zeros(3, dtype='int64') + domain_left - idims = na.ones(3, dtype='int64') * na.minimum(nd - domain_left, MAX_EDGE) - # We want to find how many grids are inside. - dleft_index = left_index[gdk,:] - dright_index = right_index[gdk,:] - ddims = dims[gdk,:] - dfl = fl[gdk,:] - psg = ramses_reader.ProtoSubgrid(initial_left, idims, - dleft_index, dright_index, ddims, dfl) - #print "Gridding from %s to %s + %s" % ( - # initial_left, initial_left, idims) - if psg.efficiency <= 0: continue - self.num_deep = 0 - psgs.extend(self._recursive_patch_splitting( - psg, idims, initial_left, - dleft_index, dright_index, ddims, dfl)) - #psgs.extend([psg]) - pbar.finish() - self.proto_grids.append(psgs) - sums = na.zeros(3, dtype='int64') - mylog.info("Final grid count: %s", len(self.proto_grids[level])) - if len(self.proto_grids[level]) == 1: continue - for g in self.proto_grids[level]: - sums += [s.sum() for s in g.sigs] - assert(na.all(sums == dims.prod(axis=1).sum())) - self.num_grids = sum(len(l) for l in self.proto_grids) - - num_deep = 0 - - @num_deep_inc - def _recursive_patch_splitting(self, psg, dims, ind, - left_index, right_index, gdims, fl): - min_eff = 0.1 # This isn't always respected. - if self.num_deep > 40: - # If we've recursed more than 100 times, we give up. - psg.efficiency = min_eff - return [psg] - if psg.efficiency > min_eff or psg.efficiency < 0.0: - return [psg] - tt, ax, fp = psg.find_split() - if (fp % 2) != 0: - if dims[ax] != fp + 1: - fp += 1 - else: - fp -= 1 - #print " " * self.num_deep + "Got ax", ax, "fp", fp - dims_l = dims.copy() - dims_l[ax] = fp - li_l = ind.copy() - if na.any(dims_l <= 0): return [psg] - L = ramses_reader.ProtoSubgrid( - li_l, dims_l, left_index, right_index, gdims, fl) - #print " " * self.num_deep + "L", tt, L.efficiency - if L.efficiency > 1.0: raise RuntimeError - if L.efficiency <= 0.0: L = [] - elif L.efficiency < min_eff: - L = self._recursive_patch_splitting(L, dims_l, li_l, - left_index, right_index, gdims, fl) - else: - L = [L] - dims_r = dims.copy() - dims_r[ax] -= fp - li_r = ind.copy() - li_r[ax] += fp - if na.any(dims_r <= 0): return [psg] - R = ramses_reader.ProtoSubgrid( - li_r, dims_r, left_index, right_index, gdims, fl) - #print " " * self.num_deep + "R", tt, R.efficiency - if R.efficiency > 1.0: raise RuntimeError - if R.efficiency <= 0.0: R = [] - elif R.efficiency < min_eff: - R = self._recursive_patch_splitting(R, dims_r, li_r, - left_index, right_index, gdims, fl) - else: - R = [R] - return L + R - - def _parse_hierarchy(self): - # We have important work to do - grids = [] - gi = 0 - for level, grid_list in enumerate(self.proto_grids): - for g in grid_list: - fl = g.grid_file_locations - props = g.get_properties() - self.grid_left_edge[gi,:] = props[0,:] / (2.0**(level+1)) - self.grid_right_edge[gi,:] = props[1,:] / (2.0**(level+1)) - self.grid_dimensions[gi,:] = props[2,:] - self.grid_levels[gi,:] = level - grids.append(self.grid(gi, self, level, fl, props[0,:])) - gi += 1 - self.grids = na.array(grids, dtype='object') - - def _get_grid_parents(self, grid, LE, RE): - mask = na.zeros(self.num_grids, dtype='bool') - grids, grid_ind = self.get_box_grids(LE, RE) - mask[grid_ind] = True - mask = na.logical_and(mask, (self.grid_levels == (grid.Level-1)).flat) - return self.grids[mask] - - def _populate_grid_objects(self): - for gi,g in enumerate(self.grids): - parents = self._get_grid_parents(g, - self.grid_left_edge[gi,:], - self.grid_right_edge[gi,:]) - if len(parents) > 0: - g.Parent.extend(parents.tolist()) - for p in parents: p.Children.append(g) - g._prepare_grid() - g._setup_dx() - self.max_level = self.grid_levels.max() - - def _setup_unknown_fields(self): - for field in self.field_list: - if field in self.parameter_file.field_info: continue - mylog.info("Adding %s to list of fields", field) - cf = None - if self.parameter_file.has_key(field): - def external_wrapper(f): - def _convert_function(data): - return data.convert(f) - return _convert_function - cf = external_wrapper(field) - add_field(field, lambda a, b: None, - convert_function=cf, take_log=False) - - def _setup_derived_fields(self): - self.derived_field_list = [] - - def _setup_data_io(self): - self.io = io_registry[self.data_style](self.tree_proxy) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/OrionDefs.py --- a/yt/lagos/OrionDefs.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -""" -Various definitions for various other modules and routines - -@author: U{JS Oishi} -@organization: U{UC Berkeley} -@contact: U{jsoishi@astro.berkeley.edu} - -@todo: Move into yt.Defs, along with enki.EnkiDefs -@license: - Copyright (C) 2008-2009 J.S. Oishi. 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 . - -""" -from yt.funcs import * -### this assumes EnzoDefs.py has *already* been imported - -# converts the Orion inputs file name to the Enzo/yt name expected -# throughout the code. key is Orion name, value is Enzo/yt equivalent -orion2enzoDict = {"amr.n_cell": "TopGridRank", - "materials.gamma": "Gamma", - "amr.ref_ratio": "RefineBy" - } - -yt2orionFieldsDict = {} -orion2ytFieldsDict = {} - -orion_FAB_header_pattern = r"^FAB \(\((\d+), \([0-9 ]+\)\),\(\d+, \(([0-9 ]+)\)\)\)\(\((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\) \((\d+,\d+,\d+)\)\) (\d+)\n" diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/OrionFields.py --- a/yt/lagos/OrionFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -""" -Orion-specific fields - -Author: J. S. Oishi -Affiliation: UC Berkeley -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 J. S. Oishi, 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 . -""" - - -from UniversalFields import * - -add_field = add_orion_field - -# def _convertDensity(data): -# return data.convert("Density") -add_field("density", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("density")], - units=r"\rm{g}/\rm{cm}^3") -OrionFieldInfo["density"]._projected_units =r"\rm{g}/\rm{cm}^2" -#OrionFieldInfo["density"]._convert_function=_convertDensity - -add_field("eden", function=lambda a,b: None, take_log=True, - validators = [ValidateDataField("eden")], - units=r"\rm{erg}/\rm{cm}^3") - -add_field("xmom", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("xmom")], - units=r"\rm{g}/\rm{cm^2\ s}") - -add_field("ymom", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("ymom")], - units=r"\rm{gm}/\rm{cm^2\ s}") - -add_field("zmom", function=lambda a,b: None, take_log=False, - validators = [ValidateDataField("zmom")], - units=r"\rm{g}/\rm{cm^2\ s}") - -translation_dict = {"x-velocity": "xvel", - "y-velocity": "yvel", - "z-velocity": "zvel", - "Density": "density", - "Total_Energy": "eden", - "Temperature": "temperature", - "x-momentum": "xmom", - "y-momentum": "ymom", - "z-momentum": "zmom" - } - -def _generate_translation(mine, theirs): - add_field(theirs, function=lambda a, b: b[mine], take_log=True) - -for f,v in translation_dict.items(): - if v not in OrionFieldInfo: - add_field(v, function=lambda a,b: None, take_log=False, - validators = [ValidateDataField(v)]) - #print "Setting up translator from %s to %s" % (v, f) - _generate_translation(v, f) - -def _xVelocity(field, data): - """generate x-velocity from x-momentum and density - - """ - return data["xmom"]/data["density"] -add_field("x-velocity",function=_xVelocity, take_log=False, - units=r'\rm{cm}/\rm{s}') - -def _yVelocity(field,data): - """generate y-velocity from y-momentum and density - - """ - #try: - # return data["xvel"] - #except KeyError: - return data["ymom"]/data["density"] -add_field("y-velocity",function=_yVelocity, take_log=False, - units=r'\rm{cm}/\rm{s}') - -def _zVelocity(field,data): - """generate z-velocity from z-momentum and density - - """ - return data["zmom"]/data["density"] -add_field("z-velocity",function=_zVelocity, take_log=False, - units=r'\rm{cm}/\rm{s}') - -def _ThermalEnergy(field, data): - """generate thermal (gas energy). Dual Energy Formalism was - implemented by Stella, but this isn't how it's called, so I'll - leave that commented out for now. - """ - #if data.pf["DualEnergyFormalism"]: - # return data["Gas_Energy"] - #else: - return data["Total_Energy"] - 0.5 * data["density"] * ( - data["x-velocity"]**2.0 - + data["y-velocity"]**2.0 - + data["z-velocity"]**2.0 ) -add_field("ThermalEnergy", function=_ThermalEnergy, - units=r"\rm{ergs}/\rm{cm^3}") - -def _Pressure(field,data): - """M{(Gamma-1.0)*e, where e is thermal energy density - NB: this will need to be modified for radiation - """ - return (data.pf["Gamma"] - 1.0)*data["ThermalEnergy"] -add_field("Pressure", function=_Pressure, units=r"\rm{dyne}/\rm{cm}^{2}") - -def _Temperature(field,data): - return (data.pf["Gamma"]-1.0)*data.pf["mu"]*mh*data["ThermalEnergy"]/(kboltz*data["Density"]) -add_field("Temperature",function=_Temperature,units=r"\rm{Kelvin}",take_log=False) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/OutputTypes.py --- a/yt/lagos/OutputTypes.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,995 +0,0 @@ -""" -Generalized Enzo output objects, both static and time-series. - -Presumably at some point EnzoRun will be absorbed into here. -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 Matthew Turk, J. S. Oishi. 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 . -""" - -from yt.lagos import * -from yt.fido import ParameterFileStore, NoParameterShelf -from yt.funcs import * -import string, re, gc, time, os, os.path - -# We want to support the movie format in the future. -# When such a thing comes to pass, I'll move all the stuff that is contant up -# to here, and then have it instantiate EnzoStaticOutputs as appropriate. - -_cached_pfs = weakref.WeakValueDictionary() -_pf_store = ParameterFileStore() - -class StaticOutput(object): - class __metaclass__(type): - def __init__(cls, name, b, d): - type.__init__(cls, name, b, d) - output_type_registry[name]=cls - mylog.debug("Registering: %s as %s", name, cls) - - def __new__(cls, filename=None, *args, **kwargs): - if not isinstance(filename, types.StringTypes): - obj = object.__new__(cls) - obj.__init__(filename, *args, **kwargs) - return obj - apath = os.path.abspath(filename) - if not os.path.exists(apath): raise IOError(filename) - if apath not in _cached_pfs: - obj = object.__new__(cls) - obj.__init__(filename, *args, **kwargs) - _cached_pfs[apath] = obj - if ytcfg.getboolean('lagos','serialize'): - try: - _pf_store.check_pf(obj) - except NoParameterShelf: - pass - return _cached_pfs[apath] - - def __init__(self, filename, data_style=None): - """ - Base class for generating new output types. Principally consists of - a *filename* and a *data_style* which will be passed on to children. - """ - self.data_style = data_style - self.parameter_filename = str(filename) - self.basename = os.path.basename(filename) - self.directory = os.path.expanduser(os.path.dirname(filename)) - self.fullpath = os.path.abspath(self.directory) - self._instantiated = time.time() - if len(self.directory) == 0: - self.directory = "." - self.conversion_factors = {} - self.parameters = {} - self._parse_parameter_file() - self._set_units() - # These can be taken out if you so desire - - def __reduce__(self): - args = (self._hash(),) - return (_reconstruct_pf, args) - - def __repr__(self): - return self.basename - - def _hash(self): - s = "%s;%s;%s" % (self.basename, - self["InitialTime"], self["CurrentTimeIdentifier"]) - try: - import hashlib - return hashlib.md5(s).hexdigest() - except ImportError: - return s.replace(";", "*") - - @classmethod - def _is_valid(cls, *args, **kwargs): - return False - - def __getitem__(self, key): - """ - Returns _units, parameters, or _conversion_factors in that order - """ - for d in [self.units, self.time_units, self.parameters, \ - self.conversion_factors]: - if key in d: return d[key] - raise KeyError(key) - - def keys(self): - """ - Returns a list of possible keys, from _units, parameters and - _conversion_factors - """ - return self.units.keys() \ - + self.time_units.keys() \ - + self.parameters.keys() \ - + self.conversion_factors.keys() - - def __iter__(self): - for ll in [self.units, self.time_units, - self.parameters, self.conversion_factors]: - for i in ll.keys(): yield i - - def get_smallest_appropriate_unit(self, v): - max_nu = 1e30 - good_u = None - for unit in ['mpc','kpc','pc','au','rsun','cm']: - vv = v*self[unit] - if vv < max_nu and vv > 1.0: - good_u = unit - max_nu = v*self[unit] - return good_u - - def has_key(self, key): - """ - Returns true or false - """ - return key in self.units or \ - key in self.time_units or \ - key in self.parameters or \ - key in self.conversion_factors - - def _get_hierarchy(self): - if self.__hierarchy == None: - if self._hierarchy_class == None: - raise RuntimeError("You should not instantiate StaticOutput.") - self.__hierarchy = self._hierarchy_class(self, data_style=self.data_style) - return self.__hierarchy - - def _set_hierarchy(self, newh): - if self.__hierarchy != None: - mylog.warning("Overriding hierarchy attribute! This is probably unwise!") - self.__hierarchy = newh - - __hierarchy = None - hierarchy = property(_get_hierarchy, _set_hierarchy) - h = property(_get_hierarchy, _set_hierarchy) - - -class EnzoStaticOutput(StaticOutput): - """ - Enzo-specific output, set at a fixed time. - """ - _hierarchy_class = EnzoHierarchy - _fieldinfo_class = EnzoFieldContainer - def __init__(self, filename, data_style=None, - parameter_override = None, - conversion_override = None, - storage_filename = None): - """ - This class is a stripped down class that simply reads and parses - *filename* without looking at the hierarchy. *data_style* gets passed - to the hierarchy to pre-determine the style of data-output. However, - it is not strictly necessary. Optionally you may specify a - *parameter_override* dictionary that will override anything in the - paarmeter file and a *conversion_override* dictionary that consists - of {fieldname : conversion_to_cgs} that will override the #DataCGS. - """ - if parameter_override is None: parameter_override = {} - self.__parameter_override = parameter_override - if conversion_override is None: conversion_override = {} - self.__conversion_override = conversion_override - self.storage_filename = storage_filename - - StaticOutput.__init__(self, filename, data_style) - if "InitialTime" not in self.parameters: - self.parameters["InitialTime"] = 0.0 - rp = os.path.join(self.directory, "rates.out") - if os.path.exists(rp): - try: - self.rates = EnzoTable(rp, rates_out_key) - except: - pass - cp = os.path.join(self.directory, "cool_rates.out") - if os.path.exists(cp): - try: - self.cool = EnzoTable(cp, cool_out_key) - except: - pass - - # Now fixes for different types of Hierarchies - # This includes changing the fieldinfo class! - if self["TopGridRank"] == 1: self._setup_1d() - elif self["TopGridRank"] == 2: self._setup_2d() - - self.field_info = self._fieldinfo_class() - - def _setup_1d(self): - self._hierarchy_class = EnzoHierarchy1D - self._fieldinfo_class = Enzo1DFieldContainer - self.parameters["DomainLeftEdge"] = \ - na.concatenate([self["DomainLeftEdge"], [0.0, 0.0]]) - self.parameters["DomainRightEdge"] = \ - na.concatenate([self["DomainRightEdge"], [1.0, 1.0]]) - - def _setup_2d(self): - self._hierarchy_class = EnzoHierarchy2D - self._fieldinfo_class = Enzo2DFieldContainer - self.parameters["DomainLeftEdge"] = \ - na.concatenate([self["DomainLeftEdge"], [0.0]]) - self.parameters["DomainRightEdge"] = \ - na.concatenate([self["DomainRightEdge"], [1.0]]) - - def get_parameter(self,parameter,type=None): - """ - Gets a parameter not in the parameterDict. - """ - if self.parameters.has_key(parameter): - return self.parameters[parameter] - - # Let's read the file - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - lines = open(self.parameter_filename).readlines() - for lineI, line in enumerate(lines): - if line.find("#") >= 1: # Keep the commented lines - line=line[:line.find("#")] - line=line.strip().rstrip() - if len(line) < 2: - continue - try: - param, vals = map(strip,map(rstrip,line.split("="))) - except ValueError: - mylog.error("ValueError: '%s'", line) - if parameter == param: - if type is None: - t = vals.split() - else: - t = map(type, vals.split()) - if len(t) == 1: - self.parameters[param] = t[0] - else: - self.parameters[param] = t - if param.endswith("Units") and not param.startswith("Temperature"): - dataType = param[:-5] - self.conversion_factors[dataType] = self.parameters[param] - return self.parameters[parameter] - - return "" - - def _parse_parameter_file(self): - """ - Parses the parameter file and establishes the various - dictionaries. - """ - # Let's read the file - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - lines = open(self.parameter_filename).readlines() - for lineI, line in enumerate(lines): - if line.find("#") >= 1: # Keep the commented lines - line=line[:line.find("#")] - line=line.strip().rstrip() - if len(line) < 2: - continue - try: - param, vals = map(strip,map(rstrip,line.split("="))) - except ValueError: - mylog.error("ValueError: '%s'", line) - if parameterDict.has_key(param): - t = map(parameterDict[param], vals.split()) - if len(t) == 1: - self.parameters[param] = t[0] - else: - self.parameters[param] = t - if param.endswith("Units") and not param.startswith("Temperature"): - dataType = param[:-5] - self.conversion_factors[dataType] = self.parameters[param] - elif param.startswith("#DataCGS"): - # Assume of the form: #DataCGSConversionFactor[7] = 2.38599e-26 g/cm^3 - if lines[lineI-1].find("Label") >= 0: - kk = lineI-1 - elif lines[lineI-2].find("Label") >= 0: - kk = lineI-2 - dataType = lines[kk].split("=")[-1].rstrip().strip() - convFactor = float(line.split("=")[-1].split()[0]) - self.conversion_factors[dataType] = convFactor - elif param.startswith("#CGSConversionFactor"): - dataType = param[20:].rstrip() - convFactor = float(line.split("=")[-1]) - self.conversion_factors[dataType] = convFactor - elif param.startswith("DomainLeftEdge"): - self.parameters["DomainLeftEdge"] = \ - na.array([float(i) for i in vals.split()]) - elif param.startswith("DomainRightEdge"): - self.parameters["DomainRightEdge"] = \ - na.array([float(i) for i in vals.split()]) - for p, v in self.__parameter_override.items(): - self.parameters[p] = v - for p, v in self.__conversion_override.items(): - self.conversion_factors[p] = v - - def _set_units(self): - """ - Generates the conversion to various physical _units based on the parameter file - """ - self.units = {} - self.time_units = {} - if len(self.parameters) == 0: - self._parse_parameter_file() - if "EOSType" not in self.parameters: self.parameters["EOSType"] = -1 - if self["ComovingCoordinates"]: - self._setup_comoving_units() - elif self.has_key("LengthUnit"): - # 'Why share when we can reinvent incompatibly?' - self.parameters["LengthUnits"] = self["LengthUnit"] - self._setup_getunits_units() - elif self.has_key("LengthUnits"): - self._setup_getunits_units() - else: - self._setup_nounits_units() - self.time_units['1'] = 1 - self.units['1'] = 1 - self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() - seconds = self["Time"] - self.time_units['years'] = seconds / (365*3600*24.0) - self.time_units['days'] = seconds / (3600*24.0) - - def _setup_comoving_units(self): - z = self["CosmologyCurrentRedshift"] - h = self["CosmologyHubbleConstantNow"] - boxcm_cal = self["CosmologyComovingBoxSize"] - boxcm_uncal = boxcm_cal / h - box_proper = boxcm_uncal/(1+z) - self.units['aye'] = (1.0 + self["CosmologyInitialRedshift"])/(z + 1.0) - if not self.has_key("Time"): - cu = self.cosmology_get_units() - self.conversion_factors["Time"] = cu['utim'] - for unit in mpc_conversion: - self.units[unit] = mpc_conversion[unit] * box_proper - self.units[unit+'h'] = mpc_conversion[unit] * box_proper * h - self.units[unit+'cm'] = mpc_conversion[unit] * boxcm_uncal - self.units[unit+'hcm'] = mpc_conversion[unit] * boxcm_cal - - def _setup_getunits_units(self): - # We are given LengthUnits, which is number of cm per box length - # So we convert that to box-size in Mpc - box_proper = 3.24077e-25 * self["LengthUnits"] - self.units['aye'] = 1.0 - for unit in mpc_conversion.keys(): - self.units[unit] = mpc_conversion[unit] * box_proper - if not self.has_key("TimeUnits"): - self.conversion_factors["Time"] = self["LengthUnits"] / self["x-velocity"] - - def _setup_nounits_units(self): - z = 0 - mylog.warning("Setting 1.0 in code units to be 1.0 cm") - if not self.has_key("TimeUnits"): - mylog.warning("No time units. Setting 1.0 = 1 second.") - self.conversion_factors["Time"] = 1.0 - for unit in mpc_conversion.keys(): - self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] - - def cosmology_get_units(self): - """ - Return an Enzo-fortran style dictionary of units to feed into custom - routines. This is typically only necessary if you are interacting - with fortran code. - """ - k = {} - k["utim"] = 2.52e17/na.sqrt(self.parameters["CosmologyOmegaMatterNow"])\ - / self.parameters["CosmologyHubbleConstantNow"] \ - / (1+self.parameters["CosmologyInitialRedshift"])**1.5 - k["urho"] = 1.88e-29 * self.parameters["CosmologyOmegaMatterNow"] \ - * self.parameters["CosmologyHubbleConstantNow"]**2 \ - * (1.0 + self.parameters["CosmologyCurrentRedshift"])**3 - k["uxyz"] = 3.086e24 * \ - self.parameters["CosmologyComovingBoxSize"] / \ - self.parameters["CosmologyHubbleConstantNow"] / \ - (1.0 + self.parameters["CosmologyCurrentRedshift"]) - k["uaye"] = 1.0/(1.0 + self.parameters["CosmologyInitialRedshift"]) - k["uvel"] = 1.225e7*self.parameters["CosmologyComovingBoxSize"] \ - *na.sqrt(self.parameters["CosmologyOmegaMatterNow"]) \ - *na.sqrt(1+ self.parameters["CosmologyInitialRedshift"]) - k["utem"] = 1.88e6 * (self.parameters["CosmologyComovingBoxSize"]**2) \ - * self.parameters["CosmologyOmegaMatterNow"] \ - * (1.0 + self.parameters["CosmologyInitialRedshift"]) - k["aye"] = (1.0 + self.parameters["CosmologyInitialRedshift"]) / \ - (1.0 + self.parameters["CosmologyCurrentRedshift"]) - return k - - @classmethod - def _is_valid(cls, *args, **kwargs): - return os.path.exists("%s.hierarchy" % args[0]) - -# We set our default output type to EnzoStaticOutput - -output_type_registry[None] = EnzoStaticOutput - -class EnzoStaticOutputInMemory(EnzoStaticOutput): - _hierarchy_class = EnzoHierarchyInMemory - _data_style = 'enzo_inline' - - def __new__(cls, *args, **kwargs): - obj = object.__new__(cls) - obj.__init__(*args, **kwargs) - return obj - - def __init__(self, parameter_override=None, conversion_override=None): - if parameter_override is None: parameter_override = {} - self.__parameter_override = parameter_override - if conversion_override is None: conversion_override = {} - self.__conversion_override = conversion_override - - StaticOutput.__init__(self, "InMemoryParameterFile", self._data_style) - - self.field_info = self._fieldinfo_class() - - def _parse_parameter_file(self): - enzo = self._obtain_enzo() - self.basename = "cycle%08i" % ( - enzo.yt_parameter_file["NumberOfPythonCalls"]) - self.parameters['CurrentTimeIdentifier'] = time.time() - self.parameters.update(enzo.yt_parameter_file) - self.conversion_factors.update(enzo.conversion_factors) - for i in self.parameters: - if isinstance(self.parameters[i], types.TupleType): - self.parameters[i] = na.array(self.parameters[i]) - if i.endswith("Units") and not i.startswith("Temperature"): - dataType = i[:-5] - self.conversion_factors[dataType] = self.parameters[i] - for i in self.conversion_factors: - if isinstance(self.conversion_factors[i], types.TupleType): - self.conversion_factors[i] = na.array(self.conversion_factors[i]) - for p, v in self.__parameter_override.items(): - self.parameters[p] = v - for p, v in self.__conversion_override.items(): - self.conversion_factors[p] = v - - def _obtain_enzo(self): - import enzo; return enzo - - @classmethod - def _is_valid(cls, *args, **kwargs): - return False - -class OrionStaticOutput(StaticOutput): - """ - This class is a stripped down class that simply reads and parses - *filename*, without looking at the Orion hierarchy. - """ - _hierarchy_class = OrionHierarchy - _fieldinfo_class = OrionFieldContainer - - def __init__(self, plotname, paramFilename=None, fparamFilename=None, - data_style='orion_native', paranoia=False, - storage_filename = None): - """need to override for Orion file structure. - - the paramfile is usually called "inputs" - and there may be a fortran inputs file usually called "probin" - plotname here will be a directory name - as per BoxLib, data_style will be one of - * Native - * IEEE (not implemented in yt) - * ASCII (not implemented in yt) - - """ - self.storage_filename = storage_filename - self.paranoid_read = paranoia - self.parameter_filename = paramFilename - self.fparameter_filename = fparamFilename - self.__ipfn = paramFilename - - self.fparameters = {} - - StaticOutput.__init__(self, plotname.rstrip("/"), - data_style='orion_native') - self.field_info = self._fieldinfo_class() - self._parse_header_file() - - # These should maybe not be hardcoded? - self.parameters["HydroMethod"] = 'orion' # always PPM DE - self.parameters["Time"] = 1. # default unit is 1... - self.parameters["DualEnergyFormalism"] = 0 # always off. - self.parameters["EOSType"] = -1 # default - if self.fparameters.has_key("mu"): - self.parameters["mu"] = self.fparameters["mu"] - - def _localize(self, f, default): - if f is None: - return os.path.join(self.directory, default) - return f - - @classmethod - def _is_valid(cls, *args, **kwargs): - # fill our args - pname = args[0].rstrip("/") - dn = os.path.dirname(pname) - if len(args) > 1: kwargs['paramFilename'] = args[1] - pfname = kwargs.get("paramFilename", os.path.join(dn, "inputs")) - return os.path.exists(os.path.join(pfname)) - - def _parse_parameter_file(self): - """ - Parses the parameter file and establishes the various - dictionaries. - """ - self.fullplotdir = os.path.abspath(self.parameter_filename) - self.parameter_filename = self._localize( - self.__ipfn, 'inputs') - self.fparameter_filename = self._localize( - self.fparameter_filename, 'probin') - if os.path.isfile(self.fparameter_filename): - self._parse_fparameter_file() - # Let's read the file - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - lines = open(self.parameter_filename).readlines() - for lineI, line in enumerate(lines): - if line.find("#") >= 1: # Keep the commented lines... - line=line[:line.find("#")] - line=line.strip().rstrip() - if len(line) < 2 or line.find("#") == 0: # ...but skip comments - continue - try: - param, vals = map(strip,map(rstrip,line.split("="))) - except ValueError: - mylog.error("ValueError: '%s'", line) - if orion2enzoDict.has_key(param): - paramName = orion2enzoDict[param] - t = map(parameterDict[paramName], vals.split()) - if len(t) == 1: - self.parameters[paramName] = t[0] - else: - if paramName == "RefineBy": - self.parameters[paramName] = t[0] - else: - self.parameters[paramName] = t - - elif param.startswith("geometry.prob_hi"): - self.parameters["DomainRightEdge"] = \ - na.array([float(i) for i in vals.split()]) - elif param.startswith("geometry.prob_lo"): - self.parameters["DomainLeftEdge"] = \ - na.array([float(i) for i in vals.split()]) - - def _parse_fparameter_file(self): - """ - Parses the fortran parameter file for Orion. Most of this will - be useless, but this is where it keeps mu = mass per - particle/m_hydrogen. - """ - lines = open(self.fparameter_filename).readlines() - for line in lines: - if line.count("=") == 1: - param, vals = map(strip,map(rstrip,line.split("="))) - if vals.count("'") == 0: - t = map(float,[a.replace('D','e').replace('d','e') for a in vals.split()]) # all are floating point. - else: - t = vals.split() - if len(t) == 1: - self.fparameters[param] = t[0] - else: - self.fparameters[param] = t - - def _parse_header_file(self): - """ - Parses the BoxLib header file to get any parameters stored - there. Hierarchy information is read out of this file in - OrionHierarchy. - - Currently, only Time is read here. - """ - header_file = open(os.path.join(self.fullplotdir,'Header')) - lines = header_file.readlines() - header_file.close() - n_fields = int(lines[1]) - self.parameters["InitialTime"] = float(lines[3+n_fields]) - - - def _set_units(self): - """ - Generates the conversion to various physical _units based on the parameter file - """ - self.units = {} - self.time_units = {} - if len(self.parameters) == 0: - self._parse_parameter_file() - self._setup_nounits_units() - self.conversion_factors = defaultdict(lambda: 1.0) - self.time_units['1'] = 1 - self.units['1'] = 1.0 - self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() - seconds = 1 #self["Time"] - self.time_units['years'] = seconds / (365*3600*24.0) - self.time_units['days'] = seconds / (3600*24.0) - for key in yt2orionFieldsDict: - self.conversion_factors[key] = 1.0 - - def _setup_nounits_units(self): - z = 0 - mylog.warning("Setting 1.0 in code units to be 1.0 cm") - if not self.has_key("TimeUnits"): - mylog.warning("No time units. Setting 1.0 = 1 second.") - self.conversion_factors["Time"] = 1.0 - for unit in mpc_conversion.keys(): - self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] - -def _reconstruct_pf(*args, **kwargs): - pfs = ParameterFileStore() - pf = pfs.get_pf_hash(*args) - return pf - -class GadgetStaticOutput(StaticOutput): - _hierarchy_class = GadgetHierarchy - _fieldinfo_class = GadgetFieldContainer - def __init__(self, h5filename,storage_filename=None) : - StaticOutput.__init__(self, h5filename, 'gadget_hdf5') - self.storage_filename = storage_filename #Don't know what this is - self.field_info = self._fieldinfo_class() - x = self._get_param('maxlevel')**2 - self.max_grid_size = (x,x,x) - self.parameters["InitialTime"] = 0.0 - # These should be explicitly obtained from the file, but for now that - # will wait until a reorganization of the source tree and better - # generalization. - self.parameters["TopGridRank"] = 3 - self.parameters["RefineBy"] = 2 - self.parameters["DomainLeftEdge"] = self.leftedge - self.parameters["DomainRightEdge"] = self.rightedge - - - def _parse_parameter_file(self): - # read the units in from the hdf5 file - #fill in self.units dict - #fill in self.time_units dict (keys: 'days','years', '1') - - #import all of the parameter file params - #this is NOT originally from the gadget snapshot but instead - #from the paramfile starting the sim - skips = ('TITLE','CLASS','VERSION') #these are just hdf5 crap - fh = h5py.File(self.parameter_filename) - for kw in fh['root'].attrs.keys(): - if any([skip in kw for skip in skips]): - continue - val = fh['root'].attrs[kw] - if type(val)==type(''): - try: val = cPickle.loads(val) - except: pass - #also, includes unit info - setattr(self,kw,val) - - def _get_param(self,kw,location='/root'): - fh = h5py.File(self.parameter_filename) - val = fh[location].attrs[kw] - try: val = cPickle.loads(val) - except: pass - return val - - def _set_units(self): - #check out the unit params from _parse_parameter_file and use them - #code below is all filler - self.units = {} - self.time_units = {} - self.conversion_factors = defaultdict(lambda: 1.0) - self.time_units['1'] = 1 - self.units['1'] = 1.0 - self.units['unitary'] = 1.0 - self.units['cm'] = 1.0 - seconds = 1 #self["Time"] - self.time_units['years'] = seconds / (365*3600*24.0) - self.time_units['days'] = seconds / (3600*24.0) - for key in yt2orionFieldsDict: - self.conversion_factors[key] = 1.0 - - - @classmethod - def _is_valid(cls, *args, **kwargs): - # check for a /root to exist in the h5 file - try: - h5f=h5py.File(self.h5filename) - valid = 'root' in h5f.items()[0] - h5f.close() - return valid - except: - pass - return False - -class ChomboStaticOutput(StaticOutput): - _hierarchy_class = ChomboHierarchy - _fieldinfo_class = ChomboFieldContainer - - def __init__(self, filename, data_style='chombo_hdf5', - storage_filename = None): - StaticOutput.__init__(self,filename,data_style) - self.storage_filename = storage_filename - - self.field_info = self._fieldinfo_class() - # hardcoded for now - self.parameters["InitialTime"] = 0.0 - # These should be explicitly obtained from the file, but for now that - # will wait until a reorganization of the source tree and better - # generalization. - self.parameters["TopGridRank"] = 3 - self.parameters["RefineBy"] = 2 - - def _set_units(self): - """ - Generates the conversion to various physical _units based on the parameter file - """ - self.units = {} - self.time_units = {} - if len(self.parameters) == 0: - self._parse_parameter_file() - self._setup_nounits_units() - self.conversion_factors = defaultdict(lambda: 1.0) - self.time_units['1'] = 1 - self.units['1'] = 1.0 - self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() - seconds = 1 #self["Time"] - self.time_units['years'] = seconds / (365*3600*24.0) - self.time_units['days'] = seconds / (3600*24.0) - for key in yt2orionFieldsDict: - self.conversion_factors[key] = 1.0 - - def _setup_nounits_units(self): - z = 0 - mylog.warning("Setting 1.0 in code units to be 1.0 cm") - if not self.has_key("TimeUnits"): - mylog.warning("No time units. Setting 1.0 = 1 second.") - self.conversion_factors["Time"] = 1.0 - for unit in mpc_conversion.keys(): - self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] - - - def _parse_parameter_file(self): - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - self.parameters["DomainLeftEdge"] = na.array([0.,0.,0.]) - self.parameters["DomainRightEdge"] = self.__calc_right_edge() - - - def __calc_right_edge(self): - fileh = h5py.File(self.parameter_filename,'r') - dx0 = fileh['/level_0'].attrs['dx'] - RE = dx0*((na.array(fileh['/level_0'].attrs['prob_domain']))[3:] + 1) - fileh.close() - return RE - - @classmethod - def _is_valid(self, *args, **kwargs): - try: - fileh = h5py.File(args[0],'r') - if (fileh.listnames())[0] == 'Chombo_global': - return True - except: - pass - return False - -class TigerStaticOutput(StaticOutput): - _hierarchy_class = TigerHierarchy - _fieldinfo_class = TigerFieldContainer - - def __init__(self, rhobname, root_size, max_grid_size=128, - data_style='tiger', storage_filename = None): - StaticOutput.__init__(self, rhobname, data_style) - self.storage_filename = storage_filename - self.basename = rhobname[:-4] - if not os.path.exists(self.basename + "rhob"): - print "%s doesn't exist, don't know how to handle this!" % ( - self.basename + "rhob") - raise IOError - if not iterable(root_size): root_size = (root_size,) * 3 - self.root_size = root_size - if not iterable(max_grid_size): max_grid_size = (max_grid_size,) * 3 - self.max_grid_size = max_grid_size - - self.field_info = self._fieldinfo_class() - - # We assume that we have basename + "rhob" and basename + "temp" - # to get at our various parameters. - - # First we get our our header: - - header = [ - ('i', 'dummy0'), - ('f', 'ZR'), - ('f', 'OMEGA0'), - ('f', 'FLAM0'), - ('f', 'OMEGAB'), - ('f', 'H0'), - ('f', 'BOXL0'), - ('i', 'dummy1'), - ] - - h_fmt, h_key = zip(*header) - header_string = "".join(h_fmt) - - fs = open(self.basename + "rhob") - header_raw = read_struct(fs, header_string) - self.parameters.update(dict(zip(h_key, header_raw))) - - if "InitialTime" not in self.parameters: - self.parameters["InitialTime"] = 0.0 - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - self.parameters['TopGridDimensions'] = root_size - self.parameters['TopGridRank'] = 3 - self.units["Density"] = 1.0 - self.parameters['RefineBy'] = 2 - - def _set_units(self): - self.parameters["DomainLeftEdge"] = na.zeros(3, dtype='float64') - self.parameters["DomainRightEdge"] = na.ones(3, dtype='float64') - self.units = {} - self.time_units = {} - self.time_units['1'] = 1 - self.units['1'] = 1.0 - self.units['cm'] = 1.0 # This is just plain false - self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() - - def _parse_parameter_file(self): - pass - - @classmethod - def _is_valid(self, *args, **kwargs): - return os.path.exists(args[0] + "rhob") - -class FLASHStaticOutput(StaticOutput): - _hierarchy_class = FLASHHierarchy - _fieldinfo_class = FLASHFieldContainer - _handle = None - - def __init__(self, filename, data_style='flash_hdf5', - storage_filename = None): - StaticOutput.__init__(self, filename, data_style) - self.storage_filename = storage_filename - - self.field_info = self._fieldinfo_class() - # These should be explicitly obtained from the file, but for now that - # will wait until a reorganization of the source tree and better - # generalization. - self.parameters["TopGridRank"] = 3 - self.parameters["RefineBy"] = 2 - self.parameters["HydroMethod"] = 'flash' # always PPM DE - self.parameters["Time"] = 1. # default unit is 1... - self._set_units() - - def _set_units(self): - """ - Generates the conversion to various physical _units based on the parameter file - """ - self.units = {} - self.time_units = {} - if len(self.parameters) == 0: - self._parse_parameter_file() - self._setup_nounits_units() - self.conversion_factors = defaultdict(lambda: 1.0) - self.time_units['1'] = 1 - self.units['1'] = 1.0 - self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() - seconds = 1 #self["Time"] - self.time_units['years'] = seconds / (365*3600*24.0) - self.time_units['days'] = seconds / (3600*24.0) - for key in yt2orionFieldsDict: - self.conversion_factors[key] = 1.0 - - def _setup_nounits_units(self): - z = 0 - mylog.warning("Setting 1.0 in code units to be 1.0 cm") - if not self.has_key("TimeUnits"): - mylog.warning("No time units. Setting 1.0 = 1 second.") - self.conversion_factors["Time"] = 1.0 - for unit in mpc_conversion.keys(): - self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] - - def _find_parameter(self, ptype, pname, scalar = False, handle = None): - # We're going to implement handle caching eventually - if handle is None: handle = self._handle - if handle is None: - handle = h5py.File(self.parameter_filename, "r") - nn = "/%s %s" % (ptype, - {False: "runtime parameters", True: "scalars"}[scalar]) - for tpname, pval in handle[nn][:]: - if tpname.strip() == pname: - return pval - raise KeyError(pname) - - def _parse_parameter_file(self): - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - self._handle = h5py.File(self.parameter_filename, "r") - self.parameters["DomainLeftEdge"] = na.array( - [self._find_parameter("real", "%smin" % ax) for ax in 'xyz']) - self.parameters["DomainRightEdge"] = na.array( - [self._find_parameter("real", "%smax" % ax) for ax in 'xyz']) - self.parameters["InitialTime"] = \ - float(self._find_parameter("real", "time", scalar=True)) - self._handle.close() - - @classmethod - def _is_valid(self, *args, **kwargs): - try: - fileh = h5py.File(args[0],'r') - if "bounding box" in fileh["/"].keys(): - return True - except: - pass - return False - -class RAMSESStaticOutput(StaticOutput): - _hierarchy_class = RAMSESHierarchy - _fieldinfo_class = RAMSESFieldContainer - _handle = None - - def __init__(self, filename, data_style='ramses', - storage_filename = None): - StaticOutput.__init__(self, filename, data_style) - self.storage_filename = storage_filename - - self.field_info = self._fieldinfo_class() - # hardcoded for now - self.parameters["InitialTime"] = 0.0 - # These should be explicitly obtained from the file, but for now that - # will wait until a reorganization of the source tree and better - # generalization. - self.parameters["TopGridRank"] = 3 - self.parameters["RefineBy"] = 2 - self.parameters["HydroMethod"] = 'ramses' - self.parameters["Time"] = 1. # default unit is 1... - - def __repr__(self): - return self.basename.rsplit(".", 1)[0] - - def _set_units(self): - """ - Generates the conversion to various physical _units based on the parameter file - """ - self.units = {} - self.time_units = {} - if len(self.parameters) == 0: - self._parse_parameter_file() - self._setup_nounits_units() - self.conversion_factors = defaultdict(lambda: 1.0) - self.time_units['1'] = 1 - self.units['1'] = 1.0 - self.units['unitary'] = 1.0 / (self["DomainRightEdge"] - self["DomainLeftEdge"]).max() - seconds = 1 #self["Time"] - self.time_units['years'] = seconds / (365*3600*24.0) - self.time_units['days'] = seconds / (3600*24.0) - for key in yt2orionFieldsDict: - self.conversion_factors[key] = 1.0 - - def _setup_nounits_units(self): - z = 0 - mylog.warning("Setting 1.0 in code units to be 1.0 cm") - if not self.has_key("TimeUnits"): - mylog.warning("No time units. Setting 1.0 = 1 second.") - self.conversion_factors["Time"] = 1.0 - for unit in mpc_conversion.keys(): - self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"] - - def _parse_parameter_file(self): - self.parameters["CurrentTimeIdentifier"] = \ - int(os.stat(self.parameter_filename)[ST_CTIME]) - import yt.ramses_reader as rr - self.ramses_tree = rr.RAMSES_tree_proxy(self.parameter_filename) - rheader = self.ramses_tree.get_file_info() - self.parameters.update(rheader) - self.parameters["DomainRightEdge"] = na.ones(3, dtype='float64') \ - * rheader['boxlen'] - self.parameters["DomainLeftEdge"] = na.zeros(3, dtype='float64') - self.parameters["TopGridDimensions"] = na.ones(3, dtype='int32') * 2 - - @classmethod - def _is_valid(self, *args, **kwargs): - if not os.path.basename(args[0]).startswith("info_"): return False - fn = args[0].replace("info_", "amr_").replace(".txt", ".out00001") - print fn - return os.path.exists(fn) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/ParallelTools.py --- a/yt/lagos/ParallelTools.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1522 +0,0 @@ -""" -Parallel data mapping techniques for yt - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.lagos import * -from yt.funcs import * -import yt.logger, logging -import itertools, sys, cStringIO, cPickle - -exe_name = os.path.basename(sys.executable) -# At import time, we determined whether or not we're being run in parallel. -if exe_name in \ - ["mpi4py", "embed_enzo", - "python"+sys.version[:3]+"-mpi"] \ - or "--parallel" in sys.argv or '_parallel' in dir(sys) \ - or any(["ipengine" in arg for arg in sys.argv]): - from mpi4py import MPI - parallel_capable = (MPI.COMM_WORLD.size > 1) - if parallel_capable: - mylog.info("Parallel computation enabled: %s / %s", - MPI.COMM_WORLD.rank, MPI.COMM_WORLD.size) - ytcfg["yt","__parallel_rank"] = str(MPI.COMM_WORLD.rank) - ytcfg["yt","__parallel_size"] = str(MPI.COMM_WORLD.size) - ytcfg["yt","__parallel"] = "True" - if exe_name == "embed_enzo": ytcfg["yt","inline"] = "True" - # I believe we do not need to turn this off manually - #ytcfg["yt","StoreParameterFiles"] = "False" - # Now let's make sure we have the right options set. - if MPI.COMM_WORLD.rank > 0: - if ytcfg.getboolean("lagos","serialize"): - ytcfg["lagos","onlydeserialize"] = "True" - if ytcfg.getboolean("yt","LogFile"): - ytcfg["yt","LogFile"] = "False" - yt.logger.disable_file_logging() - f = logging.Formatter("P%03i %s" % (MPI.COMM_WORLD.rank, - yt.logger.fstring)) - yt.logger.rootLogger.handlers[0].setFormatter(f) - if ytcfg.getint("yt","LogLevel") < 20: - yt.logger.ytLogger.warning( - "Log Level is set low -- this could affect parallel performance!") -else: - parallel_capable = False - -class ObjectIterator(object): - """ - This is a generalized class that accepts a list of objects and then - attempts to intelligently iterate over them. - """ - def __init__(self, pobj, just_list = False, attr='_grids'): - self.pobj = pobj - if hasattr(pobj, attr) and getattr(pobj, attr) is not None: - gs = getattr(pobj, attr) - else: - gs = getattr(pobj._data_source, attr) - if hasattr(gs[0], 'proc_num'): - # This one sort of knows about MPI, but not quite - self._objs = [g for g in gs if g.proc_num == - ytcfg.getint('yt','__parallel_rank')] - self._use_all = True - else: - self._objs = gs - if hasattr(self._objs[0], 'filename'): - self._objs = sorted(self._objs, key = lambda g: g.filename) - self._use_all = False - self.ng = len(self._objs) - self.just_list = just_list - - def __iter__(self): - for obj in self._objs: yield obj - -class ParallelObjectIterator(ObjectIterator): - """ - This takes an object, *pobj*, that implements ParallelAnalysisInterface, - and then does its thing, calling initliaze and finalize on the object. - """ - def __init__(self, pobj, just_list = False, attr='_grids', - round_robin=False): - ObjectIterator.__init__(self, pobj, just_list, attr=attr) - self._offset = MPI.COMM_WORLD.rank - self._skip = MPI.COMM_WORLD.size - # Note that we're doing this in advance, and with a simple means - # of choosing them; more advanced methods will be explored later. - if self._use_all: - self.my_obj_ids = na.arange(len(self._objs)) - else: - if not round_robin: - self.my_obj_ids = na.array_split( - na.arange(len(self._objs)), self._skip)[self._offset] - else: - self.my_obj_ids = na.arange(len(self._objs))[self._offset::self._skip] - - def __iter__(self): - for gid in self.my_obj_ids: - yield self._objs[gid] - if not self.just_list: self.pobj._finalize_parallel() - -def parallel_simple_proxy(func): - """ - This is a decorator that broadcasts the result of computation on a single - processor to all other processors. To do so, it uses the _processing and - _distributed flags in the object to check for blocks. Meant only to be - used on objects that subclass :class:`~yt.lagos.ParallelAnalysisInterface`. - """ - if not parallel_capable: return func - @wraps(func) - def single_proc_results(self, *args, **kwargs): - retval = None - if self._processing or not self._distributed: - return func(self, *args, **kwargs) - if self._owner == MPI.COMM_WORLD.rank: - self._processing = True - retval = func(self, *args, **kwargs) - self._processing = False - retval = MPI.COMM_WORLD.bcast(retval, root=self._owner) - MPI.COMM_WORLD.Barrier() - return retval - return single_proc_results - -class ParallelDummy(type): - """ - This is a base class that, on instantiation, replaces all attributes that - don't start with ``_`` with :func:`~yt.lagos.parallel_simple_proxy`-wrapped - attributes. Used as a metaclass. - """ - def __init__(cls, name, bases, d): - super(ParallelDummy, cls).__init__(name, bases, d) - skip = d.pop("dont_wrap", []) - extra = d.pop("extra_wrap", []) - for attrname in d: - if attrname.startswith("_") or attrname in skip: - if attrname not in extra: continue - attr = getattr(cls, attrname) - if type(attr) == types.MethodType: - setattr(cls, attrname, parallel_simple_proxy(attr)) - -def parallel_passthrough(func): - """ - If we are not run in parallel, this function passes the input back as - output; otherwise, the function gets called. Used as a decorator. - """ - @wraps(func) - def passage(self, data): - if not self._distributed: return data - return func(self, data) - return passage - -def parallel_blocking_call(func): - """ - This decorator blocks on entry and exit of a function. - """ - @wraps(func) - def barrierize(*args, **kwargs): - mylog.debug("Entering barrier before %s", func.func_name) - MPI.COMM_WORLD.Barrier() - retval = func(*args, **kwargs) - mylog.debug("Entering barrier after %s", func.func_name) - MPI.COMM_WORLD.Barrier() - return retval - if parallel_capable: - return barrierize - else: - return func - -def parallel_splitter(f1, f2): - """ - This function returns either the function *f1* or *f2* depending on whether - or not we're the root processor. Mainly used in class definitions. - """ - @wraps(f1) - def in_order(*args, **kwargs): - MPI.COMM_WORLD.Barrier() - if MPI.COMM_WORLD.rank == 0: - f1(*args, **kwargs) - MPI.COMM_WORLD.Barrier() - if MPI.COMM_WORLD.rank != 0: - f2(*args, **kwargs) - MPI.COMM_WORLD.Barrier() - if not parallel_capable: return f1 - return in_order - -def parallel_root_only(func): - """ - This decorator blocks and calls the function on the root processor, - but does not broadcast results to the other processors. - """ - @wraps(func) - def root_only(*args, **kwargs): - if MPI.COMM_WORLD.rank == 0: - try: - func(*args, **kwargs) - all_clear = 1 - except: - traceback.print_last() - all_clear = 0 - else: - all_clear = None - MPI.COMM_WORLD.Barrier() - all_clear = MPI.COMM_WORLD.bcast(all_clear, root=0) - if not all_clear: raise RuntimeError - if parallel_capable: return root_only - return func - -class ParallelAnalysisInterface(object): - """ - This is an interface specification providing several useful utility - functions for analyzing something in parallel. - """ - _grids = None - _distributed = parallel_capable - - def _get_objs(self, attr, *args, **kwargs): - if self._distributed: - rr = kwargs.pop("round_robin", False) - self._initialize_parallel(*args, **kwargs) - return ParallelObjectIterator(self, attr=attr, - round_robin=rr) - return ObjectIterator(self, attr=attr) - - def _get_grids(self, *args, **kwargs): - if self._distributed: - self._initialize_parallel(*args, **kwargs) - return ParallelObjectIterator(self, attr='_grids') - return ObjectIterator(self, attr='_grids') - - def _get_grid_objs(self): - if self._distributed: - return ParallelObjectIterator(self, True, attr='_grids') - return ObjectIterator(self, True, attr='_grids') - - def _initialize_parallel(self): - pass - - def _finalize_parallel(self): - pass - - def _partition_hierarchy_2d(self, axis): - if not self._distributed: - return False, self.hierarchy.grid_collection(self.center, self.hierarchy.grids) - - xax, yax = x_dict[axis], y_dict[axis] - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 2) - mi = MPI.COMM_WORLD.rank - cx, cy = na.unravel_index(mi, cc) - x = na.mgrid[0:1:(cc[0]+1)*1j][cx:cx+2] - y = na.mgrid[0:1:(cc[1]+1)*1j][cy:cy+2] - - DLE, DRE = self.pf["DomainLeftEdge"].copy(), self.pf["DomainRightEdge"].copy() - LE = na.ones(3, dtype='float64') * DLE - RE = na.ones(3, dtype='float64') * DRE - LE[xax] = x[0] * (DRE[xax]-DLE[xax]) + DLE[xax] - RE[xax] = x[1] * (DRE[xax]-DLE[xax]) + DLE[xax] - LE[yax] = y[0] * (DRE[yax]-DLE[yax]) + DLE[yax] - RE[yax] = y[1] * (DRE[yax]-DLE[yax]) + DLE[yax] - mylog.debug("Dimensions: %s %s", LE, RE) - - reg = self.hierarchy.region_strict(self.center, LE, RE) - return True, reg - - def _partition_hierarchy_2d_inclined(self, unit_vectors, origin, widths, - box_vectors, resolution = (1.0, 1.0)): - if not self._distributed: - ib = self.hierarchy.inclined_box(origin, box_vectors) - return False, ib, resolution - # We presuppose that unit_vectors is already unitary. If it's not, - # caveat emptor. - uv = na.array(unit_vectors) - inv_mat = na.linalg.pinv(uv) - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 2) - mi = MPI.COMM_WORLD.rank - cx, cy = na.unravel_index(mi, cc) - resolution = (1.0/cc[0], 1.0/cc[1]) - # We are rotating with respect to the *origin*, not the back center, - # so we go from 0 .. width. - px = na.mgrid[0.0:1.0:(cc[0]+1)*1j][cx] * widths[0] - py = na.mgrid[0.0:1.0:(cc[1]+1)*1j][cy] * widths[1] - nxo = inv_mat[0,0]*px + inv_mat[0,1]*py + origin[0] - nyo = inv_mat[1,0]*px + inv_mat[1,1]*py + origin[1] - nzo = inv_mat[2,0]*px + inv_mat[2,1]*py + origin[2] - nbox_vectors = na.array( - [unit_vectors[0] * widths[0]/cc[0], - unit_vectors[1] * widths[1]/cc[1], - unit_vectors[2] * widths[2]], - dtype='float64') - norigin = na.array([nxo, nyo, nzo]) - box = self.hierarchy.inclined_box(norigin, nbox_vectors) - return True, box, resolution - - def _partition_hierarchy_3d(self, padding=0.0, rank_ratio = 1): - LE, RE = self.pf["DomainLeftEdge"].copy(), self.pf["DomainRightEdge"].copy() - if not self._distributed: - return False, LE, RE, self.hierarchy.all_data() - elif ytcfg.getboolean("yt", "inline"): - # At this point, we want to identify the root grid tile to which - # this processor is assigned. - # The only way I really know how to do this is to get the level-0 - # grid that belongs to this processor. - grids = self.pf.h.select_grids(0) - root_grids = [g for g in grids - if g.proc_num == MPI.COMM_WORLD.rank] - if len(root_grids) != 1: raise RuntimeError - #raise KeyError - LE = root_grids[0].LeftEdge - RE = root_grids[0].RightEdge - return True, LE, RE, self.hierarchy.region(self.center, LE, RE) - - cc = MPI.Compute_dims(MPI.COMM_WORLD.size / rank_ratio, 3) - mi = MPI.COMM_WORLD.rank % (MPI.COMM_WORLD.size / rank_ratio) - cx, cy, cz = na.unravel_index(mi, cc) - x = na.mgrid[LE[0]:RE[0]:(cc[0]+1)*1j][cx:cx+2] - y = na.mgrid[LE[1]:RE[1]:(cc[1]+1)*1j][cy:cy+2] - z = na.mgrid[LE[2]:RE[2]:(cc[2]+1)*1j][cz:cz+2] - - LE = na.array([x[0], y[0], z[0]], dtype='float64') - RE = na.array([x[1], y[1], z[1]], dtype='float64') - - if padding > 0: - return True, \ - LE, RE, self.hierarchy.periodic_region_strict(self.center, LE-padding, RE+padding) - - return False, LE, RE, self.hierarchy.region_strict(self.center, LE, RE) - - def _partition_region_3d(self, left_edge, right_edge, padding=0.0, - rank_ratio = 1): - """ - Given a region, it subdivides it into smaller regions for parallel - analysis. - """ - LE, RE = left_edge[:], right_edge[:] - if not self._distributed: - return LE, RE, re - - cc = MPI.Compute_dims(MPI.COMM_WORLD.size / rank_ratio, 3) - mi = MPI.COMM_WORLD.rank % (MPI.COMM_WORLD.size / rank_ratio) - cx, cy, cz = na.unravel_index(mi, cc) - x = na.mgrid[LE[0]:RE[0]:(cc[0]+1)*1j][cx:cx+2] - y = na.mgrid[LE[1]:RE[1]:(cc[1]+1)*1j][cy:cy+2] - z = na.mgrid[LE[2]:RE[2]:(cc[2]+1)*1j][cz:cz+2] - - LE = na.array([x[0], y[0], z[0]], dtype='float64') - RE = na.array([x[1], y[1], z[1]], dtype='float64') - - if padding > 0: - return True, \ - LE, RE, self.hierarchy.periodic_region(self.center, LE-padding, - RE+padding) - - return False, LE, RE, self.hierarchy.region(self.center, LE, RE) - - def _partition_hierarchy_3d_bisection_list(self): - """ - Returns an array that is used to drive _partition_hierarchy_3d_bisection, - below. - """ - - def factor(n): - if n == 1: return [1] - i = 2 - limit = n**0.5 - while i <= limit: - if n % i == 0: - ret = factor(n/i) - ret.append(i) - return ret - i += 1 - return [n] - - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 3) - si = MPI.COMM_WORLD.size - - factors = factor(si) - xyzfactors = [factor(cc[0]), factor(cc[1]), factor(cc[2])] - - # Each entry of cuts is a two element list, that is: - # [cut dim, number of cuts] - cuts = [] - # The higher cuts are in the beginning. - # We're going to do our best to make the cuts cyclic, i.e. x, then y, - # then z, etc... - lastdim = 0 - for f in factors: - nextdim = (lastdim + 1) % 3 - while True: - if f in xyzfactors[nextdim]: - cuts.append([nextdim, f]) - topop = xyzfactors[nextdim].index(f) - temp = xyzfactors[nextdim].pop(topop) - lastdim = nextdim - break - nextdim = (nextdim + 1) % 3 - return cuts - - - def _partition_hierarchy_3d_bisection(self, axis, bins, counts, top_bounds = None,\ - old_group = None, old_comm = None, cut=None, old_cc=None): - """ - Partition the volume into evenly weighted subvolumes using the distribution - in counts. The bisection happens in the MPI communicator group old_group. - You may need to set "MPI_COMM_MAX" and "MPI_GROUP_MAX" environment - variables. - """ - counts = counts.astype('int64') - if not self._distributed: - LE, RE = self.pf["DomainLeftEdge"].copy(), self.pf["DomainRightEdge"].copy() - return False, LE, RE, self.hierarchy.grid_collection(self.center, self.hierarchy.grids) - - # First time through the world is the current group. - if old_group == None or old_comm == None: - old_group = MPI.COMM_WORLD.Get_group() - old_comm = MPI.COMM_WORLD - - # Figure out the gridding based on the deepness of cuts. - if old_cc is None: - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 3) - else: - cc = old_cc - cc[cut[0]] /= cut[1] - # Set the boundaries of the full bounding box for this group. - if top_bounds == None: - LE, RE = self.pf["DomainLeftEdge"].copy(), self.pf["DomainRightEdge"].copy() - else: - LE, RE = top_bounds - - ra = old_group.Get_rank() # In this group, not WORLD, unless it's the first time. - - # First find the total number of particles in my group. - parts = old_comm.allreduce(int(counts.sum()), op=MPI.SUM) - # Now the full sum in the bins along this axis in this group. - full_counts = na.empty(counts.size, dtype='int64') - old_comm.Allreduce([counts, MPI.LONG], [full_counts, MPI.LONG], op=MPI.SUM) - # Find the bin that passes the cut points. - midpoints = [LE[axis]] - sum = 0 - bin = 0 - for step in xrange(1,cut[1]): - while sum < ((parts*step)/cut[1]): - lastsum = sum - sum += full_counts[bin] - bin += 1 - # Bin edges - left_edge = bins[bin-1] - right_edge = bins[bin] - # Find a better approx of the midpoint cut line using a linear approx. - a = float(sum - lastsum) / (right_edge - left_edge) - midpoints.append(left_edge + (0.5 - (float(lastsum) / parts / 2)) / a) - #midpoint = (left_edge + right_edge) / 2. - midpoints.append(RE[axis]) - # Now we need to split the members of this group into chunks. - # The values that go into the _ranks are the ranks of the tasks - # in *this* communicator group, which go zero to size - 1. They are not - # the same as the global ranks! - groups = {} - ranks = {} - old_group_size = old_group.Get_size() - for step in xrange(cut[1]): - groups[step] = na.arange(step*old_group_size/cut[1], (step+1)*old_group_size/cut[1]) - # [ (start, stop, step), ] - ranks[step] = [ (groups[step][0], groups[step][-1], 1), ] - - # Based on where we are, adjust our LE or RE, depending on axis. At the - # same time assign the new MPI group membership. - for step in xrange(cut[1]): - if ra in groups[step]: - LE[axis] = midpoints[step] - RE[axis] = midpoints[step+1] - new_group = old_group.Range_incl(ranks[step]) - new_comm = old_comm.Create(new_group) - - if old_cc is not None: - old_group.Free() - old_comm.Free() - - new_top_bounds = (LE,RE) - - # Using the new boundaries, regrid. - mi = new_comm.rank - cx, cy, cz = na.unravel_index(mi, cc) - x = na.mgrid[LE[0]:RE[0]:(cc[0]+1)*1j][cx:cx+2] - y = na.mgrid[LE[1]:RE[1]:(cc[1]+1)*1j][cy:cy+2] - z = na.mgrid[LE[2]:RE[2]:(cc[2]+1)*1j][cz:cz+2] - - my_LE = na.array([x[0], y[0], z[0]], dtype='float64') - my_RE = na.array([x[1], y[1], z[1]], dtype='float64') - - # Return a new subvolume and associated stuff. - return new_group, new_comm, my_LE, my_RE, new_top_bounds, cc,\ - self.hierarchy.region_strict(self.center, my_LE, my_RE) - - def _partition_hierarchy_3d_weighted_1d(self, weight=None, bins=None, padding=0.0, axis=0, min_sep=.1): - LE, RE = self.pf["DomainLeftEdge"].copy(), self.pf["DomainRightEdge"].copy() - if not self._distributed: - return False, LE, RE, self.hierarchy.grid_collection(self.center, self.hierarchy.grids) - - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 3) - mi = MPI.COMM_WORLD.rank - si = MPI.COMM_WORLD.size - cx, cy, cz = na.unravel_index(mi, cc) - - gridx = na.mgrid[LE[0]:RE[0]:(cc[0]+1)*1j] - gridy = na.mgrid[LE[1]:RE[1]:(cc[1]+1)*1j] - gridz = na.mgrid[LE[2]:RE[2]:(cc[2]+1)*1j] - - x = gridx[cx:cx+2] - y = gridy[cy:cy+2] - z = gridz[cz:cz+2] - - LE = na.array([x[0], y[0], z[0]], dtype='float64') - RE = na.array([x[1], y[1], z[1]], dtype='float64') - - # Default to normal if we don't have a weight, or our subdivisions are - # not enough to warrant this procedure. - if weight is None or cc[axis] < 1: - if padding > 0: - return True, \ - LE, RE, self.hierarchy.periodic_region_strict(self.center, LE-padding, RE+padding) - - return False, LE, RE, self.hierarchy.region_strict(self.center, LE, RE) - - # Find the densest subvolumes globally - local_weight = na.zeros((si, weight.size),dtype='float64') - local_weight[mi,:] = weight - weights = self._mpi_allsum(local_weight) - avg_weight = weights.mean() - weights = weights.max(axis=0) - - moved_count = 0 - moved = {} - w_copy = weights.copy() - - if mi == 0: - print 'w_copy',w_copy,'gridx',gridx - - while moved_count < (cc[axis]-1): - con = False - # Find the current peak - hi_mark = na.argmax(w_copy) - # If this peak isn't high enough, we're done - height = w_copy[hi_mark] - if height < 10.*avg_weight: - if mi == 0: - print 'breaking',moved_count, height, avg_weight - break - # If this mark is too close to a previous one, avg this one out - # and restart a search. - new_cen = (bins[hi_mark] + bins[hi_mark+1])/2. - if mi==0: - print 'moved',moved - for source in moved: - if mi == 0: - print 'moved',abs(moved[source] - new_cen) - if abs(moved[source] - new_cen) < min_sep: - w_copy[hi_mark] = avg_weight - if mi == 0: - print 'continued' - con = True - if con: - continue - # Find the lowest value entry - lo_mark = na.argmin(w_copy) - # Record this as a new mapping. - moved[(bins[lo_mark] + bins[lo_mark+1])/2.] = (bins[hi_mark] + bins[hi_mark+1])/2. - # Fix the values so they're not pulled again. - w_copy[hi_mark] = avg_weight - w_copy[lo_mark] = avg_weight - moved_count += 1 - - # Now for each key in moved, we move the axis closest to that value to - # the value in the dict. - temp_gridx = [] - for source in moved: - tomove = na.argmin(abs(gridx - source)) - temp_gridx.append(moved[source]) - gridx[tomove] = -1. - - for g in gridx: - if g >= 0.: - temp_gridx.append(g) - - temp_gridx.sort() - gridx = na.array(temp_gridx) - if mi == 0: - print 'gridx',gridx,'len=',len(gridx) - x = gridx[cx:cx+2] - y = gridy[cy:cy+2] - z = gridz[cz:cz+2] - - LE = na.array([x[0], y[0], z[0]], dtype='float64') - RE = na.array([x[1], y[1], z[1]], dtype='float64') - - if padding > 0: - return True, \ - LE, RE, self.hierarchy.periodic_region_strict(self.center, LE-padding, RE+padding) - - return False, LE, RE, self.hierarchy.region_strict(self.center, LE, RE) - - - - def _partition_hierarchy_3d_weighted(self, weight=None, padding=0.0, agg=8.): - LE, RE = self.pf["DomainLeftEdge"].copy(), self.pf["DomainRightEdge"].copy() - if not self._distributed: - return False, LE, RE, self.hierarchy.grid_collection(self.center, self.hierarchy.grids) - - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 3) - mi = MPI.COMM_WORLD.rank - cx, cy, cz = na.unravel_index(mi, cc) - - gridx = na.mgrid[LE[0]:RE[0]:(cc[0]+1)*1j] - gridy = na.mgrid[LE[1]:RE[1]:(cc[1]+1)*1j] - gridz = na.mgrid[LE[2]:RE[2]:(cc[2]+1)*1j] - - x = gridx[cx:cx+2] - y = gridy[cy:cy+2] - z = gridz[cz:cz+2] - - LE = na.array([x[0], y[0], z[0]], dtype='float64') - RE = na.array([x[1], y[1], z[1]], dtype='float64') - - old_vol = ((RE - LE)**2).sum() - - # Default to normal if we don't have a weight, or our subdivisions are - # not enough to warrant this procedure. - if weight is None or cc[0] < 2 or cc[1] < 2 or cc[2] < 2: - if padding > 0: - return True, \ - LE, RE, self.hierarchy.periodic_region_strict(self.center, LE-padding, RE+padding) - - return False, LE, RE, self.hierarchy.region_strict(self.center, LE, RE) - - # Build the matrix of weights. - weights = na.zeros(cc, dtype='float64') - weights[cx,cy,cz] = weight - weights = self._mpi_allsum(weights) - weights = weights / weights.sum() - - # Figure out the sums of weights along the axes - xface = weights.sum(axis=0) - yface = weights.sum(axis=1) - zface = weights.sum(axis=2) - - xedge = yface.sum(axis=1) - yedge = xface.sum(axis=1) - zedge = xface.sum(axis=0) - - # Get a polynomial fit to each axis weight distribution - xcen = gridx[:-1] - xcen += xcen[1]/2. - ycen = gridy[:-1] - ycen += ycen[1]/2. - zcen = gridz[:-1] - zcen += zcen[1]/2. - - xfit = na.polyfit(xcen, xedge, 3) - yfit = na.polyfit(ycen, yedge, 3) - zfit = na.polyfit(zcen, zedge, 3) - - # Find the normalized weights with trapizoidal integration - # We also apply an aggression factor to the values to make the - # boundaries shift more. - div_count = int(1. / padding) - divs = na.arange(div_count+1, dtype='float64') / div_count - xvals = na.polyval(xfit, divs) - for i,xv in enumerate(xvals): - if xv > xedge.mean(): xvals[i] *= agg - yvals = na.polyval(yfit, divs) - for i,yv in enumerate(yvals): - if yv > yedge.mean(): yvals[i] *= agg - zvals = na.polyval(zfit, divs) - for i,zv in enumerate(zvals): - if zv > zedge.mean(): zvals[i] *= agg - xnorm = na.trapz(xvals, x=divs) - ynorm = na.trapz(yvals, x=divs) - znorm = na.trapz(zvals, x=divs) - - # We want to start the integration from the side of the axis where - # the highest density is, so that it gets small regions. - xstart = float(na.argmax(xedge))/2. - if xstart > 0.5: xstart = div_count - else: xstart = 0 - - ystart = float(na.argmax(yedge))/2. - if ystart > 0.5: ystart = div_count - else: ystart = 0 - - zstart = float(na.argmax(zedge))/2. - if zstart > 0.5: zstart = div_count - else: zstart = 0 - - - # Find the boundaries. We are assured that none of the boundaries are - # too small because each step of div is big enough because it's set - # by the padding. - nextx = 1./xedge.size - nexty = 1./yedge.size - nextz = 1./zedge.size - boundx = [0.] - boundy = [0.] - boundz = [0.] - donex, doney, donez = False, False, False - for i in xrange(div_count): - if xstart == 0: - xi = 0 - xv = i - xa = i - else: - xi = div_count - i - xf = div_count - xa = xi - if (na.trapz(xvals[xi:xf], x=divs[xi:xf])/xnorm) >= nextx and not donex: - boundx.append(divs[xa]) - if len(boundx) == cc[0]: - donex = True - nextx += 1./xedge.size - if ystart == 0: - yi = 0 - yf = i - ya = i - else: - yi = div_count - i - yf = div_count - ya = yi - if (na.trapz(yvals[yi:yf], x=divs[yi:yf])/ynorm) >= nexty and not doney: - boundy.append(divs[ya]) - if len(boundy) == cc[1]: - doney = True - nexty += 1./yedge.size - if zstart == 0: - zi = 0 - zf = i - za = i - else: - zi = div_count - i - zf = div_count - za = zi - if (na.trapz(zvals[zi:zf], x=divs[zi:zf])/znorm) >= nextz and not donez: - boundz.append(divs[za]) - if len(boundz) == cc[2]: - donez = True - nextz += 1./zedge.size - - boundx.sort() - boundy.sort() - boundz.sort() - - # Check for problems, fatally for now because I'm the only one using this - # and I don't mind that, it will help me fix things. - if len(boundx) < cc[0] or len(boundy) < cc[1] or len(boundz) < cc[2]: - print 'weighted stuff broken.' - print 'cc', cc - print len(boundx), len(boundy), len(boundz) - sys.exit() - - boundx.append(1.) - boundy.append(1.) - boundz.append(1.) - - if mi == 0: - print 'x',boundx - print 'y',boundy - print 'z',boundz - - # Update the boundaries - new_LE = na.array([boundx[cx], boundy[cy], boundz[cz]], dtype='float64') - new_RE = na.array([boundx[cx+1], boundy[cy+1], boundz[cz+1]], dtype='float64') - - new_vol = ((new_RE - new_LE) **2).sum() - print 'P%04d weight %f old_vol %f new_vol %f ratio %f' % \ - (mi, weight, old_vol, new_vol, new_vol/old_vol) - - if padding > 0: - return True, \ - new_LE, new_RE, self.hierarchy.periodic_region_strict(self.center, new_LE-padding, new_RE+padding) - - return False, new_LE, new_RE, self.hierarchy.region_strict(self.center, new_LE, new_RE) - - - def _mpi_find_neighbor_3d(self, shift): - """ Given a shift array, 1x3 long, find the task ID - of that neighbor. For example, shift=[1,0,0] finds the neighbor - immediately to the right in the positive x direction. Each task - has 26 neighbors, of which some may be itself depending on the number - and arrangement of tasks. - """ - if not self._distributed: return 0 - shift = na.array(shift) - cc = na.array(MPI.Compute_dims(MPI.COMM_WORLD.size, 3)) - mi = MPI.COMM_WORLD.rank - si = MPI.COMM_WORLD.size - # store some facts about myself - mi_cx,mi_cy,mi_cz = na.unravel_index(mi,cc) - mi_ar = na.array([mi_cx,mi_cy,mi_cz]) - # these are identical on all tasks - # should these be calculated once and stored? - #dLE = na.empty((si,3), dtype='float64') # positions not needed yet... - #dRE = na.empty((si,3), dtype='float64') - tasks = na.empty((cc[0],cc[1],cc[2]), dtype='int64') - - for i in range(si): - cx,cy,cz = na.unravel_index(i,cc) - tasks[cx,cy,cz] = i - #x = na.mgrid[LE[0]:RE[0]:(cc[0]+1)*1j][cx:cx+2] - #y = na.mgrid[LE[1]:RE[1]:(cc[1]+1)*1j][cy:cy+2] - #z = na.mgrid[LE[2]:RE[2]:(cc[2]+1)*1j][cz:cz+2] - #dLE[i, :] = na.array([x[0], y[0], z[0]], dtype='float64') - #dRE[i, :] = na.array([x[1], y[1], z[1]], dtype='float64') - - # find the neighbor - ne = (mi_ar + shift) % cc - ne = tasks[ne[0],ne[1],ne[2]] - return ne - - - def _barrier(self): - if not self._distributed: return - mylog.debug("Opening MPI Barrier on %s", MPI.COMM_WORLD.rank) - MPI.COMM_WORLD.Barrier() - - def _mpi_exit_test(self, data=False): - # data==True -> exit. data==False -> no exit - mine, statuses = self._mpi_info_dict(data) - if True in statuses.values(): - raise RunTimeError("Fatal error. Exiting.") - return None - - @parallel_passthrough - def _mpi_catrgb(self, data): - self._barrier() - data, final = data - if MPI.COMM_WORLD.rank == 0: - cc = MPI.Compute_dims(MPI.COMM_WORLD.size, 2) - nsize = final[0]/cc[0], final[1]/cc[1] - new_image = na.zeros((final[0], final[1], 6), dtype='float64') - new_image[0:nsize[0],0:nsize[1],:] = data[:] - for i in range(1,MPI.COMM_WORLD.size): - cy, cx = na.unravel_index(i, cc) - mylog.debug("Receiving image from % into bits %s:%s, %s:%s", - i, nsize[0]*cx,nsize[0]*(cx+1), - nsize[1]*cy,nsize[1]*(cy+1)) - buf = _recv_array(source=i, tag=0).reshape( - (nsize[0],nsize[1],6)) - new_image[nsize[0]*cy:nsize[0]*(cy+1), - nsize[1]*cx:nsize[1]*(cx+1),:] = buf[:] - data = new_image - else: - _send_array(data.ravel(), dest=0, tag=0) - data = MPI.COMM_WORLD.bcast(data) - return (data, final) - - @parallel_passthrough - def _mpi_catdict(self, data): - field_keys = data.keys() - field_keys.sort() - size = data[field_keys[0]].shape[-1] - # MPI_Scan is an inclusive scan - sizes = MPI.COMM_WORLD.alltoall( [size]*MPI.COMM_WORLD.size ) - offsets = na.add.accumulate([0] + sizes)[:-1] - arr_size = MPI.COMM_WORLD.allreduce(size, op=MPI.SUM) - for key in field_keys: - dd = data[key] - rv = _alltoallv_array(dd, arr_size, offsets, sizes) - data[key] = rv - return data - - @parallel_passthrough - def _mpi_joindict(self, data): - self._barrier() - if MPI.COMM_WORLD.rank == 0: - for i in range(1,MPI.COMM_WORLD.size): - data.update(MPI.COMM_WORLD.recv(source=i, tag=0)) - else: - MPI.COMM_WORLD.send(data, dest=0, tag=0) - data = MPI.COMM_WORLD.bcast(data, root=0) - self._barrier() - return data - - @parallel_passthrough - def _mpi_joindict_unpickled_double(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1,MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - keys = na.empty(size, dtype='int64') - values = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Recv([keys, MPI.LONG], i, 0) - MPI.COMM_WORLD.Recv([values, MPI.DOUBLE], i, 0) - for i,key in enumerate(keys): - data[key] = values[i] - # Now convert root's data to arrays. - size = len(data) - root_keys = na.empty(size, dtype='int64') - root_values = na.empty(size, dtype='float64') - count = 0 - for key in data: - root_keys[count] = key - root_values[count] = data[key] - count += 1 - else: - MPI.COMM_WORLD.send(len(data), 0, 0) - keys = na.empty(len(data), dtype='int64') - values = na.empty(len(data), dtype='float64') - count = 0 - for key in data: - keys[count] = key - values[count] = data[key] - count += 1 - MPI.COMM_WORLD.Send([keys, MPI.LONG], 0, 0) - MPI.COMM_WORLD.Send([values, MPI.DOUBLE], 0, 0) - # Now send it back as arrays. - size = MPI.COMM_WORLD.bcast(size, root=0) - if MPI.COMM_WORLD.rank != 0: - del keys, values - root_keys = na.empty(size, dtype='int64') - root_values = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Bcast([root_keys, MPI.LONG], root=0) - MPI.COMM_WORLD.Bcast([root_values, MPI.DOUBLE], root=0) - # Convert back to a dict. - del data - data = dict(itertools.izip(root_keys, root_values)) - return data - - @parallel_passthrough - def _mpi_joindict_unpickled_long(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1,MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - keys = na.empty(size, dtype='int64') - values = na.empty(size, dtype='int64') - MPI.COMM_WORLD.Recv([keys, MPI.LONG], i, 0) - MPI.COMM_WORLD.Recv([values, MPI.LONG], i, 0) - for i,key in enumerate(keys): - data[key] = values[i] - # Now convert root's data to arrays. - size = len(data) - root_keys = na.empty(size, dtype='int64') - root_values = na.empty(size, dtype='int64') - count = 0 - for key in data: - root_keys[count] = key - root_values[count] = data[key] - count += 1 - else: - MPI.COMM_WORLD.send(len(data), 0, 0) - keys = na.empty(len(data), dtype='int64') - values = na.empty(len(data), dtype='int64') - count = 0 - for key in data: - keys[count] = key - values[count] = data[key] - count += 1 - MPI.COMM_WORLD.Send([keys, MPI.LONG], 0, 0) - MPI.COMM_WORLD.Send([values, MPI.LONG], 0, 0) - # Now send it back as arrays. - size = MPI.COMM_WORLD.bcast(size, root=0) - if MPI.COMM_WORLD.rank != 0: - del keys, values - root_keys = na.empty(size, dtype='int64') - root_values = na.empty(size, dtype='int64') - MPI.COMM_WORLD.Bcast([root_keys, MPI.LONG], root=0) - MPI.COMM_WORLD.Bcast([root_values, MPI.LONG], root=0) - # Convert back to a dict. - del data - data = dict(itertools.izip(root_keys,root_values)) - return data - - @parallel_passthrough - def _mpi_concatenate_array_long(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1, MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - new_data = na.empty(size, dtype='int64') - MPI.COMM_WORLD.Recv([new_data, MPI.LONG], i, 0) - data = na.concatenate((data, new_data)) - size = data.size - del new_data - else: - MPI.COMM_WORLD.send(data.size, 0, 0) - MPI.COMM_WORLD.Send([data, MPI.LONG], 0, 0) - # Now we distribute the full array. - size = MPI.COMM_WORLD.bcast(size, root=0) - if MPI.COMM_WORLD.rank != 0: - del data - data = na.empty(size, dtype='int64') - MPI.COMM_WORLD.Bcast([data, MPI.LONG], root=0) - return data - - @parallel_passthrough - def _mpi_concatenate_array_double(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1, MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - new_data = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Recv([new_data, MPI.DOUBLE], i, 0) - data = na.concatenate((data, new_data)) - size = data.size - del new_data - else: - MPI.COMM_WORLD.send(data.size, 0, 0) - MPI.COMM_WORLD.Send([data, MPI.DOUBLE], 0, 0) - # Now we distribute the full array. - size = MPI.COMM_WORLD.bcast(size, root=0) - if MPI.COMM_WORLD.rank != 0: - del data - data = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Bcast([data, MPI.DOUBLE], root=0) - return data - - @parallel_passthrough - def _mpi_concatenate_array_on_root_double(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1, MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - new_data = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Recv([new_data, MPI.DOUBLE], i, 0) - data = na.concatenate((data, new_data)) - else: - MPI.COMM_WORLD.send(data.size, 0, 0) - MPI.COMM_WORLD.Send([data, MPI.DOUBLE], 0, 0) - return data - - @parallel_passthrough - def _mpi_concatenate_array_on_root_int(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1, MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - new_data = na.empty(size, dtype='int32') - MPI.COMM_WORLD.Recv([new_data, MPI.INT], i, 0) - data = na.concatenate((data, new_data)) - else: - MPI.COMM_WORLD.send(data.size, 0, 0) - MPI.COMM_WORLD.Send([data, MPI.INT], 0, 0) - return data - - @parallel_passthrough - def _mpi_concatenate_array_on_root_long(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - for i in range(1, MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - new_data = na.empty(size, dtype='int64') - MPI.COMM_WORLD.Recv([new_data, MPI.LONG], i, 0) - data = na.concatenate((data, new_data)) - else: - MPI.COMM_WORLD.send(data.size, 0, 0) - MPI.COMM_WORLD.Send([data, MPI.LONG], 0, 0) - return data - - @parallel_passthrough - def _mpi_minimum_array_long(self, data): - """ - Specifically for parallelHOP. For the identical array on each task, - it merges the arrays together, taking the lower value at each index. - """ - self._barrier() - size = data.size # They're all the same size, of course - if MPI.COMM_WORLD.rank == 0: - new_data = na.empty(size, dtype='int64') - for i in range(1, MPI.COMM_WORLD.size): - MPI.COMM_WORLD.Recv([new_data, MPI.LONG], i, 0) - data = na.minimum(data, new_data) - del new_data - else: - MPI.COMM_WORLD.Send([data, MPI.LONG], 0, 0) - # Redistribute from root - MPI.COMM_WORLD.Bcast([data, MPI.LONG], root=0) - return data - - @parallel_passthrough - def _mpi_bcast_long_dict_unpickled(self, data): - self._barrier() - size = 0 - if MPI.COMM_WORLD.rank == 0: - size = len(data) - size = MPI.COMM_WORLD.bcast(size, root=0) - root_keys = na.empty(size, dtype='int64') - root_values = na.empty(size, dtype='int64') - if MPI.COMM_WORLD.rank == 0: - count = 0 - for key in data: - root_keys[count] = key - root_values[count] = data[key] - count += 1 - MPI.COMM_WORLD.Bcast([root_keys, MPI.LONG], root=0) - MPI.COMM_WORLD.Bcast([root_values, MPI.LONG], root=0) - if MPI.COMM_WORLD.rank != 0: - data = {} - for i,key in enumerate(root_keys): - data[key] = root_values[i] - return data - - @parallel_passthrough - def _mpi_maxdict(self, data): - """ - For each key in data, find the maximum value across all tasks, and - then broadcast it back. - """ - self._barrier() - if MPI.COMM_WORLD.rank == 0: - for i in range(1,MPI.COMM_WORLD.size): - temp_data = MPI.COMM_WORLD.recv(source=i, tag=0) - for key in temp_data: - try: - old_value = data[key] - except KeyError: - # This guarantees the new value gets added. - old_value = None - if old_value < temp_data[key]: - data[key] = temp_data[key] - else: - MPI.COMM_WORLD.send(data, dest=0, tag=0) - data = MPI.COMM_WORLD.bcast(data, root=0) - self._barrier() - return data - - def _mpi_maxdict_dict(self, data): - """ - Similar to above, but finds maximums for dicts of dicts. This is - specificaly for a part of chainHOP. - """ - if not self._distributed: - top_keys = [] - bot_keys = [] - vals = [] - for top_key in data: - for bot_key in data[top_key]: - top_keys.append(top_key) - bot_keys.append(bot_key) - vals.append(data[top_key][bot_key]) - top_keys = na.array(top_keys, dtype='int64') - bot_keys = na.array(bot_keys, dtype='int64') - vals = na.array(vals, dtype='float64') - return (top_keys, bot_keys, vals) - self._barrier() - size = 0 - top_keys = [] - bot_keys = [] - vals = [] - for top_key in data: - for bot_key in data[top_key]: - top_keys.append(top_key) - bot_keys.append(bot_key) - vals.append(data[top_key][bot_key]) - top_keys = na.array(top_keys, dtype='int64') - bot_keys = na.array(bot_keys, dtype='int64') - vals = na.array(vals, dtype='float64') - del data - if MPI.COMM_WORLD.rank == 0: - for i in range(1,MPI.COMM_WORLD.size): - size = MPI.COMM_WORLD.recv(source=i, tag=0) - mylog.info('Global Hash Table Merge %d of %d size %d' % \ - (i,MPI.COMM_WORLD.size, size)) - recv_top_keys = na.empty(size, dtype='int64') - recv_bot_keys = na.empty(size, dtype='int64') - recv_vals = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Recv([recv_top_keys, MPI.LONG], source=i, tag=0) - MPI.COMM_WORLD.Recv([recv_bot_keys, MPI.LONG], source=i, tag=0) - MPI.COMM_WORLD.Recv([recv_vals, MPI.DOUBLE], source=i, tag=0) - top_keys = na.concatenate([top_keys, recv_top_keys]) - bot_keys = na.concatenate([bot_keys, recv_bot_keys]) - vals = na.concatenate([vals, recv_vals]) -# for j, top_key in enumerate(top_keys): -# if j%1000 == 0: mylog.info(j) -# # Make sure there's an entry for top_key in data -# try: -# test = data[top_key] -# except KeyError: -# data[top_key] = {} -# try: -# old_value = data[top_key][bot_keys[j]] -# except KeyError: -# # This guarantees the new value gets added. -# old_value = None -# if old_value < vals[j]: -# data[top_key][bot_keys[j]] = vals[j] - else: -# top_keys = [] -# bot_keys = [] -# vals = [] -# for top_key in data: -# for bot_key in data[top_key]: -# top_keys.append(top_key) -# bot_keys.append(bot_key) -# vals.append(data[top_key][bot_key]) -# top_keys = na.array(top_keys, dtype='int64') -# bot_keys = na.array(bot_keys, dtype='int64') -# vals = na.array(vals, dtype='float64') - size = top_keys.size - MPI.COMM_WORLD.send(size, dest=0, tag=0) - MPI.COMM_WORLD.Send([top_keys, MPI.LONG], dest=0, tag=0) - MPI.COMM_WORLD.Send([bot_keys, MPI.LONG], dest=0, tag=0) - MPI.COMM_WORLD.Send([vals, MPI.DOUBLE], dest=0, tag=0) - # Getting ghetto here, we're going to decompose the dict into arrays, - # send that, and then reconstruct it. When data is too big the pickling - # of the dict fails. - if MPI.COMM_WORLD.rank == 0: -# data = defaultdict(dict) -# for i,top_key in enumerate(top_keys): -# try: -# old = data[top_key][bot_keys[i]] -# except KeyError: -# old = None -# if old < vals[i]: -# data[top_key][bot_keys[i]] = vals[i] -# top_keys = [] -# bot_keys = [] -# vals = [] -# for top_key in data: -# for bot_key in data[top_key]: -# top_keys.append(top_key) -# bot_keys.append(bot_key) -# vals.append(data[top_key][bot_key]) -# del data -# top_keys = na.array(top_keys, dtype='int64') -# bot_keys = na.array(bot_keys, dtype='int64') -# vals = na.array(vals, dtype='float64') - size = top_keys.size - # Broadcast them using array methods - size = MPI.COMM_WORLD.bcast(size, root=0) - if MPI.COMM_WORLD.rank != 0: - top_keys = na.empty(size, dtype='int64') - bot_keys = na.empty(size, dtype='int64') - vals = na.empty(size, dtype='float64') - MPI.COMM_WORLD.Bcast([top_keys,MPI.LONG], root=0) - MPI.COMM_WORLD.Bcast([bot_keys,MPI.LONG], root=0) - MPI.COMM_WORLD.Bcast([vals, MPI.DOUBLE], root=0) - return (top_keys, bot_keys, vals) - - @parallel_passthrough - def __mpi_recvlist(self, data): - # First we receive, then we make a new list. - data = ensure_list(data) - for i in range(1,MPI.COMM_WORLD.size): - buf = ensure_list(MPI.COMM_WORLD.recv(source=i, tag=0)) - data += buf - return data - - @parallel_passthrough - def _mpi_catlist(self, data): - self._barrier() - if MPI.COMM_WORLD.rank == 0: - data = self.__mpi_recvlist(data) - else: - MPI.COMM_WORLD.send(data, dest=0, tag=0) - mylog.debug("Opening MPI Broadcast on %s", MPI.COMM_WORLD.rank) - data = MPI.COMM_WORLD.bcast(data, root=0) - self._barrier() - return data - - @parallel_passthrough - def __mpi_recvarrays(self, data): - # First we receive, then we make a new list. - for i in range(1,MPI.COMM_WORLD.size): - buf = _recv_array(source=i, tag=0) - if buf is not None: - if data is None: data = buf - else: data = na.concatenate([data, buf]) - return data - - @parallel_passthrough - def _mpi_catarray(self, data): - self._barrier() - if MPI.COMM_WORLD.rank == 0: - data = self.__mpi_recvarrays(data) - else: - _send_array(data, dest=0, tag=0) - mylog.debug("Opening MPI Broadcast on %s", MPI.COMM_WORLD.rank) - data = _bcast_array(data, root=0) - self._barrier() - return data - - @parallel_passthrough - def _mpi_bcast_pickled(self, data): - self._barrier() - data = MPI.COMM_WORLD.bcast(data, root=0) - return data - - def _should_i_write(self): - if not self._distributed: return True - return (MPI.COMM_WORLD == 0) - - def _preload(self, grids, fields, io_handler): - # This will preload if it detects we are parallel capable and - # if so, we load *everything* that we need. Use with some care. - mylog.debug("Preloading %s from %s grids", fields, len(grids)) - if not self._distributed: return - io_handler.preload(grids, fields) - - @parallel_passthrough - def _mpi_double_array_max(self,data): - """ - Finds the na.maximum of a distributed array and returns the result - back to all. The array should be the same length on all tasks! - """ - self._barrier() - if MPI.COMM_WORLD.rank == 0: - recv_data = na.empty(data.size, dtype='float64') - for i in xrange(1, MPI.COMM_WORLD.size): - MPI.COMM_WORLD.Recv([recv_data, MPI.DOUBLE], source=i, tag=0) - data = na.maximum(data, recv_data) - else: - MPI.COMM_WORLD.Send([data, MPI.DOUBLE], dest=0, tag=0) - MPI.COMM_WORLD.Bcast([data, MPI.DOUBLE], root=0) - return data - - @parallel_passthrough - def _mpi_allsum(self, data): - self._barrier() - # We use old-school pickling here on the assumption the arrays are - # relatively small ( < 1e7 elements ) - return MPI.COMM_WORLD.allreduce(data, op=MPI.SUM) - - @parallel_passthrough - def _mpi_Allsum_double(self, data): - self._barrier() - # Non-pickling float allsum of a float array, data. - temp = data.copy() - MPI.COMM_WORLD.Allreduce([temp, MPI.DOUBLE], [data, MPI.DOUBLE], op=MPI.SUM) - del temp - return data - - @parallel_passthrough - def _mpi_Allsum_long(self, data): - self._barrier() - # Non-pickling float allsum of an int array, data. - temp = data.copy() - MPI.COMM_WORLD.Allreduce([temp, MPI.LONG], [data, MPI.LONG], op=MPI.SUM) - del temp - return data - - @parallel_passthrough - def _mpi_allmax(self, data): - self._barrier() - return MPI.COMM_WORLD.allreduce(data, op=MPI.MAX) - - @parallel_passthrough - def _mpi_allmin(self, data): - self._barrier() - return MPI.COMM_WORLD.allreduce(data, op=MPI.MIN) - - ### - # Non-blocking stuff. - ### - - def _mpi_Irecv_long(self, data, source, tag=0): - if not self._distributed: return -1 - return MPI.COMM_WORLD.Irecv([data, MPI.LONG], source, tag) - - def _mpi_Irecv_double(self, data, source, tag=0): - if not self._distributed: return -1 - return MPI.COMM_WORLD.Irecv([data, MPI.DOUBLE], source, tag) - - def _mpi_Isend_long(self, data, dest, tag=0): - if not self._distributed: return -1 - return MPI.COMM_WORLD.Isend([data, MPI.LONG], dest, tag) - - def _mpi_Isend_double(self, data, dest, tag=0): - if not self._distributed: return -1 - return MPI.COMM_WORLD.Isend([data, MPI.DOUBLE], dest, tag) - - def _mpi_Request_Waitall(self, hooks): - if not self._distributed: return - MPI.Request.Waitall(hooks) - - def _mpi_Request_Waititer(self, hooks): - for i in xrange(len(hooks)): - req = MPI.Request.Waitany(hooks) - yield req - - def _mpi_Request_Testall(self, hooks): - """ - This returns False if any of the request hooks are un-finished, - and True if they are all finished. - """ - if not self._distributed: return True - return MPI.Request.Testall(hooks) - - ### - # End non-blocking stuff. - ### - - def _mpi_get_size(self): - if not self._distributed: return 1 - return MPI.COMM_WORLD.size - - def _mpi_get_rank(self): - if not self._distributed: return 0 - return MPI.COMM_WORLD.rank - - def _mpi_info_dict(self, info): - if not self._distributed: return 0, {0:info} - self._barrier() - data = None - if MPI.COMM_WORLD.rank == 0: - data = {0:info} - for i in range(1, MPI.COMM_WORLD.size): - data[i] = MPI.COMM_WORLD.recv(source=i, tag=0) - else: - MPI.COMM_WORLD.send(info, dest=0, tag=0) - mylog.debug("Opening MPI Broadcast on %s", MPI.COMM_WORLD.rank) - data = MPI.COMM_WORLD.bcast(data, root=0) - self._barrier() - return MPI.COMM_WORLD.rank, data - - def _get_dependencies(self, fields): - deps = [] - fi = self.pf.field_info - for field in fields: - deps += ensure_list(fi[field].get_dependencies(pf=self.pf).requested) - return list(set(deps)) - - def _claim_object(self, obj): - if not self._distributed: return - obj._owner = MPI.COMM_WORLD.rank - obj._distributed = True - - def _do_not_claim_object(self, obj): - if not self._distributed: return - obj._owner = -1 - obj._distributed = True - - def _write_on_root(self, fn): - if not self._distributed: return open(fn, "w") - if MPI.COMM_WORLD.rank == 0: - return open(fn, "w") - else: - return cStringIO.StringIO() - - def _get_filename(self, prefix, rank=None): - if not self._distributed: return prefix - if rank == None: - return "%s_%04i" % (prefix, MPI.COMM_WORLD.rank) - else: - return "%s_%04i" % (prefix, rank) - - def _is_mine(self, obj): - if not obj._distributed: return True - return (obj._owner == MPI.COMM_WORLD.rank) - -__tocast = 'c' - -def _send_array(arr, dest, tag = 0): - if not isinstance(arr, na.ndarray): - MPI.COMM_WORLD.send((None,None), dest=dest, tag=tag) - MPI.COMM_WORLD.send(arr, dest=dest, tag=tag) - return - tmp = arr.view(__tocast) # Cast to CHAR - # communicate type and shape - MPI.COMM_WORLD.send((arr.dtype.str, arr.shape), dest=dest, tag=tag) - MPI.COMM_WORLD.Send([arr, MPI.CHAR], dest=dest, tag=tag) - del tmp - -def _recv_array(source, tag = 0): - dt, ne = MPI.COMM_WORLD.recv(source=source, tag=tag) - if dt is None and ne is None: - return MPI.COMM_WORLD.recv(source=source, tag=tag) - arr = na.empty(ne, dtype=dt) - tmp = arr.view(__tocast) - MPI.COMM_WORLD.Recv([tmp, MPI.CHAR], source=source, tag=tag) - return arr - -def _bcast_array(arr, root = 0): - if MPI.COMM_WORLD.rank == root: - tmp = arr.view(__tocast) # Cast to CHAR - MPI.COMM_WORLD.bcast((arr.dtype.str, arr.shape), root=root) - else: - dt, ne = MPI.COMM_WORLD.bcast(None, root=root) - arr = na.empty(ne, dtype=dt) - tmp = arr.view(__tocast) - MPI.COMM_WORLD.Bcast([tmp, MPI.CHAR], root=root) - return arr - -def _alltoallv_array(send, total_size, offsets, sizes): - if len(send.shape) > 1: - recv = [] - for i in range(send.shape[0]): - recv.append(_alltoallv_array(send[i,:].copy(), total_size, offsets, sizes)) - recv = na.array(recv) - return recv - offset = offsets[MPI.COMM_WORLD.rank] - tmp_send = send.view(__tocast) - recv = na.empty(total_size, dtype=send.dtype) - recv[offset:offset+send.size] = send[:] - dtr = send.dtype.itemsize / tmp_send.dtype.itemsize # > 1 - soff = [0] * MPI.COMM_WORLD.size - ssize = [tmp_send.size] * MPI.COMM_WORLD.size - roff = [off * dtr for off in offsets] - rsize = [siz * dtr for siz in sizes] - tmp_recv = recv.view(__tocast) - MPI.COMM_WORLD.Alltoallv((tmp_send, (ssize, soff), MPI.CHAR), - (tmp_recv, (rsize, roff), MPI.CHAR)) - return recv - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/ParticleIO.py --- a/yt/lagos/ParticleIO.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -""" -The particle-IO handler - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -from yt.funcs import * -from yt.lagos import * - -particle_handler_registry = defaultdict() - -class ParticleIOHandler(object): - class __metaclass__(type): - def __init__(cls, name, b, d): - type.__init__(cls, name, b, d) - if hasattr(cls, "_source_type"): - particle_handler_registry[cls._source_type] = cls - - _source_type = None - - def __init__(self, pf, source): - self.pf = pf - self.source = source - - def __getitem__(self, key): - return self.get_data(key) - - def get_data(self, fields): - fields = ensure_list(fields) - rvs = self.source.get_data(fields, force_particle_read=True) - if len(fields) == 1: return rvs[0] - return rvs - -particle_handler_registry.default_factory = lambda: ParticleIOHandler - -class ParticleIOHandlerImplemented(ParticleIOHandler): - def get_data(self, fields): - mylog.info("Getting %s using ParticleIO" % str(fields)) - fields = ensure_list(fields) - if not self.pf.h.io._particle_reader: - mylog.info("not self.pf.h.io._particle_reader") - return self.source.get_data(fields) - rtype, args = self._get_args() - count_list, grid_list = [], [] - for grid in self.source._grids: - if grid.NumberOfParticles == 0: continue - grid_list.append(grid) - if self.source._is_fully_enclosed(grid): - count_list.append(grid.NumberOfParticles) - else: - count_list.append(-1) - # region type, left_edge, right_edge, periodic, grid_list - fields_to_read = [] - conv_factors = [] - for field in fields: - f = self.pf.field_info[field] - to_add = f.get_dependencies(pf = self.pf).requested - to_add = list(na.unique(to_add)) - if len(to_add) != 1: raise KeyError - fields_to_read += to_add - if f._particle_convert_function is None: - func = f._convert_function - else: - func = f.particle_convert - conv_factors.append( - na.fromiter((func(g) for g in grid_list), - count=len(grid_list), dtype='float64')) - conv_factors = na.array(conv_factors).transpose() - self.conv_factors = conv_factors - rvs = self.pf.h.io._read_particles( - fields_to_read, rtype, args, grid_list, count_list, - conv_factors) - if len(fields) == 1: return rvs[0] - return rvs - -class ParticleIOHandlerRegion(ParticleIOHandlerImplemented): - periodic = False - _source_type = "region" - - def __init__(self, pf, source): - self.left_edge = source.left_edge - self.right_edge = source.right_edge - ParticleIOHandler.__init__(self, pf, source) - - def _get_args(self): - DLE = na.array(self.pf["DomainLeftEdge"], dtype='float64') - DRE = na.array(self.pf["DomainRightEdge"], dtype='float64') - args = (na.array(self.left_edge), na.array(self.right_edge), - int(self.periodic), DLE, DRE) - return (0, args) - -class ParticleIOHandlerRegionStrict(ParticleIOHandlerRegion): - _source_type = "region_strict" - -class ParticleIOHandlerPeriodicRegion(ParticleIOHandlerRegion): - periodic = True - _source_type = "periodic_region" - -class ParticleIOHandlerPeriodicRegionStrict(ParticleIOHandlerPeriodicRegion): - _source_type = "periodic_region_strict" - -class ParticleIOHandlerSphere(ParticleIOHandlerImplemented): - _source_type = "sphere" - - def __init__(self, pf, source): - self.center = source.center - self.radius = source.radius - ParticleIOHandler.__init__(self, pf, source) - - def _get_args(self): - return (1, (na.array(self.center, dtype='float64'), self.radius)) - -class ParticleIOHandlerDisk(ParticleIOHandlerImplemented): - _source_type = "disk" - - def __init__(self, pf, source): - self.center = source.center - self.normal = source._norm_vec - self.radius = source._radius - self.height = source._height - ParticleIOHandler.__init__(self, pf, source) - - def _get_args(self): - args = (na.array(self.center, dtype='float64'), - na.array(self.normal, dtype='float64'), - self.radius, self.height) - return (2, args) - \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/PointCombine.c --- a/yt/lagos/PointCombine.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1720 +0,0 @@ -/************************************************************************ -* Copyright (C) 2007-2009 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 . -* -************************************************************************/ - - -// -// PointCombine -// A module for merging points from different grids, in various ways. -// Used for projections, interpolations, and binning profiles. -// - -#include "Python.h" - -#include -#include -#include -#include - -#include "numpy/ndarrayobject.h" - -#define max(A,B) ((A) > (B) ? (A) : (B)) -#define min(A,B) ((A) < (B) ? (A) : (B)) - -static PyObject *_combineGridsError; - -static PyObject * -Py_CombineGrids(PyObject *obj, PyObject *args) -{ - PyObject *ogrid_src_x, *ogrid_src_y, *ogrid_src_vals, - *ogrid_src_mask, *ogrid_src_wgt, *ogrid_used_mask; - PyObject *ogrid_dst_x, *ogrid_dst_y, *ogrid_dst_vals, - *ogrid_dst_mask, *ogrid_dst_wgt; - - PyArrayObject *grid_src_x, *grid_src_y, **grid_src_vals, - *grid_src_mask, *grid_src_wgt, *grid_used_mask; - PyArrayObject *grid_dst_x, *grid_dst_y, **grid_dst_vals, - *grid_dst_mask, *grid_dst_wgt; - - grid_src_x = grid_src_y = //grid_src_vals = - grid_src_mask = grid_src_wgt = grid_used_mask = - grid_dst_x = grid_dst_y = //grid_dst_vals = - grid_dst_mask = grid_dst_wgt = NULL; - - int NumArrays, src_len, dst_len, refinement_factor; - NumArrays = 0; - - if (!PyArg_ParseTuple(args, "OOOOOOOOOOiO", - &ogrid_src_x, &ogrid_src_y, - &ogrid_src_mask, &ogrid_src_wgt, &ogrid_src_vals, - &ogrid_dst_x, &ogrid_dst_y, - &ogrid_dst_mask, &ogrid_dst_wgt, &ogrid_dst_vals, - &refinement_factor, &ogrid_used_mask)) - return PyErr_Format(_combineGridsError, - "CombineGrids: Invalid parameters."); - - /* First the regular source arrays */ - - grid_src_x = (PyArrayObject *) PyArray_FromAny(ogrid_src_x, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - src_len = PyArray_SIZE(grid_src_x); - - grid_src_y = (PyArrayObject *) PyArray_FromAny(ogrid_src_y, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(PyArray_SIZE(grid_src_y) != src_len) { - PyErr_Format(_combineGridsError, - "CombineGrids: src_x and src_y must be the same shape."); - goto _fail; - } - - grid_src_mask = (PyArrayObject *) PyArray_FromAny(ogrid_src_mask, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(PyArray_SIZE(grid_src_mask) != src_len) { - PyErr_Format(_combineGridsError, - "CombineGrids: src_x and src_mask must be the same shape."); - goto _fail; - } - - grid_src_wgt = (PyArrayObject *) PyArray_FromAny(ogrid_src_wgt, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((grid_src_wgt == NULL) || (PyArray_SIZE(grid_src_wgt) != src_len)) { - PyErr_Format(_combineGridsError, - "CombineGrids: src_x and src_wgt must be the same shape."); - goto _fail; - } - - grid_used_mask = (PyArrayObject *) PyArray_FromAny(ogrid_used_mask, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((grid_used_mask == NULL) || (PyArray_SIZE(grid_used_mask) != src_len)) { - PyErr_Format(_combineGridsError, - "CombineGrids: src_x and used_mask must be the same shape."); - goto _fail; - } - - grid_dst_x = (PyArrayObject *) PyArray_FromAny(ogrid_dst_x, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - dst_len = PyArray_SIZE(grid_dst_x); - - grid_dst_y = (PyArrayObject *) PyArray_FromAny(ogrid_dst_y, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(PyArray_SIZE(grid_dst_y) != dst_len) { - PyErr_Format(_combineGridsError, - "CombineGrids: dst_x and dst_y must be the same shape."); - goto _fail; - } - - grid_dst_mask = (PyArrayObject *) PyArray_FromAny(ogrid_dst_mask, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(PyArray_SIZE(grid_dst_mask) != dst_len) { - PyErr_Format(_combineGridsError, - "CombineGrids: dst_x and dst_mask must be the same shape."); - goto _fail; - } - - grid_dst_wgt = (PyArrayObject *) PyArray_FromAny(ogrid_dst_wgt, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((grid_dst_wgt == NULL) || (PyArray_SIZE(grid_dst_wgt) != dst_len)) { - PyErr_Format(_combineGridsError, - "CombineGrids: dst_x and dst_wgt must be the same shape."); - goto _fail; - } - - /* Now we do our lists of values */ - NumArrays = PySequence_Length(ogrid_src_vals); - if (NumArrays < 1) { - PyErr_Format(_combineGridsError, - "CombineGrids: You have to pass me lists of things."); - goto _fail; - } - if (!(PySequence_Length(ogrid_dst_vals) == NumArrays)) { - PyErr_Format(_combineGridsError, - "CombineGrids: Sorry, but your lists of values are different lengths."); - goto _fail; - } - - grid_src_vals = malloc(NumArrays * sizeof(PyArrayObject*)); - grid_dst_vals = malloc(NumArrays * sizeof(PyArrayObject*)); - npy_float64 **src_vals = malloc(NumArrays * sizeof(npy_float64*)); - npy_float64 **dst_vals = malloc(NumArrays * sizeof(npy_float64*)); - PyObject *temp_object; - int i; - for (i = 0; i < NumArrays; i++) { - temp_object = PySequence_GetItem(ogrid_src_vals, i); - grid_src_vals[i] = (PyArrayObject *) PyArray_FromAny( - temp_object, - PyArray_DescrFromType(NPY_FLOAT64), 1, 0, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - src_vals[i] = (npy_float64 *) PyArray_GETPTR1(grid_src_vals[i],0); - Py_DECREF(temp_object); - - temp_object = PySequence_GetItem(ogrid_dst_vals, i); - grid_dst_vals[i] = (PyArrayObject *) PyArray_FromAny( - temp_object, - PyArray_DescrFromType(NPY_FLOAT64), 1, 0, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - dst_vals[i] = (npy_float64 *) PyArray_GETPTR1(grid_dst_vals[i],0); - Py_DECREF(temp_object); - } - - /* Now we're all set to call our sub-function. */ - - npy_int64 *src_x = (npy_int64 *) PyArray_GETPTR1(grid_src_x,0); - npy_int64 *src_y = (npy_int64 *) PyArray_GETPTR1(grid_src_y,0); - npy_float64 *src_wgt = (npy_float64 *) PyArray_GETPTR1(grid_src_wgt,0); - npy_int64 *src_mask = (npy_int64 *) PyArray_GETPTR1(grid_src_mask,0); - npy_int64 *src_used_mask = (npy_int64 *) PyArray_GETPTR1(grid_used_mask,0); - - npy_int64 *dst_x = (npy_int64 *) PyArray_GETPTR1(grid_dst_x,0); - npy_int64 *dst_y = (npy_int64 *) PyArray_GETPTR1(grid_dst_y,0); - npy_float64 *dst_wgt = (npy_float64 *) PyArray_GETPTR1(grid_dst_wgt,0); - npy_int64 *dst_mask = (npy_int64 *) PyArray_GETPTR1(grid_dst_mask,0); - - int si, di, x_off, y_off; - npy_int64 fine_x, fine_y, init_x, init_y; - int num_found = 0; - - for (si = 0; si < src_len; si++) { - if (src_used_mask[si] == 0) continue; - init_x = refinement_factor * src_x[si]; - init_y = refinement_factor * src_y[si]; - for (x_off = 0; x_off < refinement_factor; x_off++) { - for(y_off = 0; y_off < refinement_factor; y_off++) { - fine_x = init_x + x_off; - fine_y = init_y + y_off; - for (di = 0; di < dst_len; di++) { - if ((fine_x == dst_x[di]) && - (fine_y == dst_y[di])) { - num_found++; - dst_wgt[di] += src_wgt[si]; - dst_mask[di] = ((src_mask[si] && dst_mask[di]) || - ((refinement_factor != 1) && (dst_mask[di]))); - // So if they are on the same level, then take the logical and - // otherwise, set it to the destination mask - src_used_mask[si] = 0; - for (i = 0; i < NumArrays; i++) { - dst_vals[i][di] += src_vals[i][si]; - } - if (refinement_factor == 1) break; - } - } - } - } - } - - Py_DECREF(grid_src_x); - Py_DECREF(grid_src_y); - Py_DECREF(grid_src_mask); - Py_DECREF(grid_src_wgt); - Py_DECREF(grid_used_mask); - - Py_DECREF(grid_dst_x); - Py_DECREF(grid_dst_y); - Py_DECREF(grid_dst_mask); - Py_DECREF(grid_dst_wgt); - - if (NumArrays > 0){ - for (i = 0; i < NumArrays; i++) { - Py_DECREF(grid_src_vals[i]); - Py_DECREF(grid_dst_vals[i]); - } - } - - free(grid_src_vals); - free(grid_dst_vals); - free(src_vals); - free(dst_vals); - - PyObject *onum_found = PyInt_FromLong((long)num_found); - return onum_found; - -_fail: - Py_XDECREF(grid_src_x); - Py_XDECREF(grid_src_y); - Py_XDECREF(grid_src_wgt); - Py_XDECREF(grid_src_mask); - Py_XDECREF(grid_used_mask); - - Py_XDECREF(grid_dst_x); - Py_XDECREF(grid_dst_y); - Py_XDECREF(grid_dst_wgt); - Py_XDECREF(grid_dst_mask); - if (NumArrays > 0){ - for (i = 0; i < NumArrays; i++) { - Py_XDECREF(grid_src_vals[i]); - Py_XDECREF(grid_dst_vals[i]); - } - } - return NULL; - -} - -static PyObject *_profile2DError; - -static PyObject *Py_Bin2DProfile(PyObject *obj, PyObject *args) -{ - int i, j; - PyObject *obins_x, *obins_y, *owsource, *obsource, *owresult, *obresult, *oused; - PyArrayObject *bins_x, *bins_y, *wsource, *bsource, *wresult, *bresult, *used; - bins_x = bins_y = wsource = bsource = wresult = bresult = used = NULL; - - if (!PyArg_ParseTuple(args, "OOOOOOO", - &obins_x, &obins_y, &owsource, &obsource, - &owresult, &obresult, &oused)) - return PyErr_Format(_profile2DError, - "Bin2DProfile: Invalid parameters."); - i = 0; - - bins_x = (PyArrayObject *) PyArray_FromAny(obins_x, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_IN_ARRAY, NULL); - if(bins_x==NULL) { - PyErr_Format(_profile2DError, - "Bin2DProfile: One dimension required for bins_x."); - goto _fail; - } - - bins_y = (PyArrayObject *) PyArray_FromAny(obins_y, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((bins_y==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(bins_y))) { - PyErr_Format(_profile2DError, - "Bin2DProfile: One dimension required for bins_y, same size as bins_x."); - goto _fail; - } - - wsource = (PyArrayObject *) PyArray_FromAny(owsource, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((wsource==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(wsource))) { - PyErr_Format(_profile2DError, - "Bin2DProfile: One dimension required for wsource, same size as bins_x."); - goto _fail; - } - - bsource = (PyArrayObject *) PyArray_FromAny(obsource, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((bsource==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(bsource))) { - PyErr_Format(_profile2DError, - "Bin2DProfile: One dimension required for bsource, same size as bins_x."); - goto _fail; - } - - wresult = (PyArrayObject *) PyArray_FromAny(owresult, - PyArray_DescrFromType(NPY_FLOAT64), 2,2, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(wresult==NULL){ - PyErr_Format(_profile2DError, - "Bin2DProfile: Two dimensions required for wresult."); - goto _fail; - } - - bresult = (PyArrayObject *) PyArray_FromAny(obresult, - PyArray_DescrFromType(NPY_FLOAT64), 2,2, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((bresult==NULL) ||(PyArray_SIZE(wresult) != PyArray_SIZE(bresult)) - || (PyArray_DIM(bresult,0) != PyArray_DIM(wresult,0))){ - PyErr_Format(_profile2DError, - "Bin2DProfile: Two dimensions required for bresult, same shape as wresult."); - goto _fail; - } - - used = (PyArrayObject *) PyArray_FromAny(oused, - PyArray_DescrFromType(NPY_FLOAT64), 2,2, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((used==NULL) ||(PyArray_SIZE(used) != PyArray_SIZE(wresult)) - || (PyArray_DIM(used,0) != PyArray_DIM(wresult,0))){ - PyErr_Format(_profile2DError, - "Bin2DProfile: Two dimensions required for used, same shape as wresult."); - goto _fail; - } - - npy_float64 wval, bval; - int n; - - for(n=0; ndimensions[0]; n++) { - i = *(npy_int64*)PyArray_GETPTR1(bins_x, n); - j = *(npy_int64*)PyArray_GETPTR1(bins_y, n); - bval = *(npy_float64*)PyArray_GETPTR1(bsource, n); - wval = *(npy_float64*)PyArray_GETPTR1(wsource, n); - *(npy_float64*)PyArray_GETPTR2(wresult, i, j) += wval; - *(npy_float64*)PyArray_GETPTR2(bresult, i, j) += wval*bval; - *(npy_float64*)PyArray_GETPTR2(used, i, j) = 1.0; - } - - Py_DECREF(bins_x); - Py_DECREF(bins_y); - Py_DECREF(wsource); - Py_DECREF(bsource); - Py_DECREF(wresult); - Py_DECREF(bresult); - Py_DECREF(used); - - PyObject *onum_found = PyInt_FromLong((long)1); - return onum_found; - - _fail: - Py_XDECREF(bins_x); - Py_XDECREF(bins_y); - Py_XDECREF(wsource); - Py_XDECREF(bsource); - Py_XDECREF(wresult); - Py_XDECREF(bresult); - Py_XDECREF(used); - return NULL; - -} - -static PyObject *_profile3DError; - -static PyObject *Py_Bin3DProfile(PyObject *obj, PyObject *args) -{ - int i, j, k; - PyObject *obins_x, *obins_y, *obins_z, *owsource, *obsource, *owresult, - *obresult, *oused; - PyArrayObject *bins_x, *bins_y, *bins_z, *wsource, *bsource, *wresult, - *bresult, *used; - bins_x = bins_y = bins_z = wsource = bsource = wresult = bresult = used = NULL; - - if (!PyArg_ParseTuple(args, "OOOOOOOO", - &obins_x, &obins_y, &obins_z, &owsource, &obsource, - &owresult, &obresult, &oused)) - return PyErr_Format(_profile3DError, - "Bin3DProfile: Invalid parameters."); - i = 0; - - bins_x = (PyArrayObject *) PyArray_FromAny(obins_x, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_IN_ARRAY, NULL); - if(bins_x==NULL) { - PyErr_Format(_profile3DError, - "Bin3DProfile: One dimension required for bins_x."); - goto _fail; - } - - bins_y = (PyArrayObject *) PyArray_FromAny(obins_y, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((bins_y==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(bins_y))) { - PyErr_Format(_profile3DError, - "Bin3DProfile: One dimension required for bins_y, same size as bins_x."); - goto _fail; - } - - bins_z = (PyArrayObject *) PyArray_FromAny(obins_z, - PyArray_DescrFromType(NPY_INT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((bins_z==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(bins_z))) { - PyErr_Format(_profile3DError, - "Bin3DProfile: One dimension required for bins_z, same size as bins_x."); - goto _fail; - } - - wsource = (PyArrayObject *) PyArray_FromAny(owsource, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((wsource==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(wsource))) { - PyErr_Format(_profile3DError, - "Bin3DProfile: One dimension required for wsource, same size as bins_x."); - goto _fail; - } - - bsource = (PyArrayObject *) PyArray_FromAny(obsource, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_IN_ARRAY, NULL); - if((bsource==NULL) || (PyArray_SIZE(bins_x) != PyArray_SIZE(bsource))) { - PyErr_Format(_profile3DError, - "Bin3DProfile: One dimension required for bsource, same size as bins_x."); - goto _fail; - } - - wresult = (PyArrayObject *) PyArray_FromAny(owresult, - PyArray_DescrFromType(NPY_FLOAT64), 3,3, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(wresult==NULL){ - PyErr_Format(_profile3DError, - "Bin3DProfile: Two dimensions required for wresult."); - goto _fail; - } - - bresult = (PyArrayObject *) PyArray_FromAny(obresult, - PyArray_DescrFromType(NPY_FLOAT64), 3,3, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((bresult==NULL) ||(PyArray_SIZE(wresult) != PyArray_SIZE(bresult)) - || (PyArray_DIM(bresult,0) != PyArray_DIM(wresult,0))){ - PyErr_Format(_profile3DError, - "Bin3DProfile: Two dimensions required for bresult, same shape as wresult."); - goto _fail; - } - - used = (PyArrayObject *) PyArray_FromAny(oused, - PyArray_DescrFromType(NPY_FLOAT64), 3,3, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((used==NULL) ||(PyArray_SIZE(used) != PyArray_SIZE(wresult)) - || (PyArray_DIM(used,0) != PyArray_DIM(wresult,0))){ - PyErr_Format(_profile3DError, - "Bin3DProfile: Two dimensions required for used, same shape as wresult."); - goto _fail; - } - - npy_float64 wval, bval; - int n; - - for(n=0; ndimensions[0]; n++) { - i = *(npy_int64*)PyArray_GETPTR1(bins_x, n); - j = *(npy_int64*)PyArray_GETPTR1(bins_y, n); - k = *(npy_int64*)PyArray_GETPTR1(bins_z, n); - bval = *(npy_float64*)PyArray_GETPTR1(bsource, n); - wval = *(npy_float64*)PyArray_GETPTR1(wsource, n); - *(npy_float64*)PyArray_GETPTR3(wresult, i, j, k) += wval; - *(npy_float64*)PyArray_GETPTR3(bresult, i, j, k) += wval*bval; - *(npy_float64*)PyArray_GETPTR3(used, i, j, k) = 1.0; - } - - Py_DECREF(bins_x); - Py_DECREF(bins_y); - Py_DECREF(bins_z); - Py_DECREF(wsource); - Py_DECREF(bsource); - Py_DECREF(wresult); - Py_DECREF(bresult); - Py_DECREF(used); - - PyObject *onum_found = PyInt_FromLong((long)1); - return onum_found; - - _fail: - Py_XDECREF(bins_x); - Py_XDECREF(bins_y); - Py_XDECREF(bins_z); - Py_XDECREF(wsource); - Py_XDECREF(bsource); - Py_XDECREF(wresult); - Py_XDECREF(bresult); - Py_XDECREF(used); - return NULL; - -} - -static PyObject *_dataCubeError; - -static PyObject *DataCubeGeneric(PyObject *obj, PyObject *args, - void (*to_call)(PyArrayObject* c_data, npy_int64 xc, - npy_int64 yc, npy_int64 zc, - PyArrayObject* g_data, npy_int64 xg, - npy_int64 yg, npy_int64 zg)) -{ - /* Standard boilerplate unpacking... */ - - /* - rf (py_int) i - grid_leftedge (npy_float64 COERCE) O - dx_grid (npy_float64 COERCE) O - griddata (npy_float64 array) O - childmask (npy_bool array) O - cube_leftedge (npy_float64 COERCE) O - cube_rightedge (npy_float64 COERCE) O - dx_cube (npy_float64 COERCE) O - cubedata (npy_float64 array) O - lastlevel (py_int) i - */ - - - int ll, i, n; - - PyObject *og_le, *og_dx, *og_data, *og_cm, - *oc_le, *oc_re, *oc_dx, *oc_data, *odr_edge, *odl_edge; - PyArrayObject *g_le, *g_dx, *g_cm, - *c_le, *c_re, *c_dx, *dr_edge, *dl_edge; - g_dx=g_cm=c_le=c_re=c_dx=NULL; - PyArrayObject **g_data, **c_data; - g_data = c_data = NULL; - npy_int *ag_cm; - npy_float64 ag_le[3], ag_dx[3], - ac_le[3], ac_re[3], ac_dx[3], - adl_edge[3], adr_edge[3]; - Py_ssize_t n_fields = 0; - - if (!PyArg_ParseTuple(args, "OOOOOOOOiOO", - &og_le, &og_dx, &og_data, &og_cm, - &oc_le, &oc_re, &oc_dx, &oc_data, - &ll, &odl_edge, &odr_edge)) - return PyErr_Format(_dataCubeError, - "DataCubeGeneric: Invalid parameters."); - - /* First the regular source arrays */ - - g_le = (PyArrayObject *) PyArray_FromAny(og_le, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((g_le==NULL) || (PyArray_SIZE(g_le) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for g_le."); - goto _fail; - } - for(i=0;i<3;i++)ag_le[i]=*(npy_float64*)PyArray_GETPTR1(g_le,i); - - g_dx = (PyArrayObject *) PyArray_FromAny(og_dx, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((g_dx==NULL) || (PyArray_SIZE(g_dx) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for g_dx."); - goto _fail; - } - for(i=0;i<3;i++)ag_dx[i]=*(npy_float64*)PyArray_GETPTR1(g_dx,i); - - g_cm = (PyArrayObject *) PyArray_FromAny(og_cm, - PyArray_DescrFromType(NPY_INT), 3, 3, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((g_cm==NULL) || (g_cm->nd != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three dimensions required for g_cm."); - goto _fail; - } - ag_cm = (npy_int*) g_cm->data; - - /* Now the cube */ - - c_le = (PyArrayObject *) PyArray_FromAny(oc_le, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((c_le==NULL) || (PyArray_SIZE(c_le) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for c_le."); - goto _fail; - } - for(i=0;i<3;i++)ac_le[i]=*(npy_float64*)PyArray_GETPTR1(c_le,i); - - c_re = (PyArrayObject *) PyArray_FromAny(oc_re, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((c_re==NULL) || (PyArray_SIZE(c_re) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for c_re."); - goto _fail; - } - for(i=0;i<3;i++)ac_re[i]=*(npy_float64*)PyArray_GETPTR1(c_re,i); - - c_dx = (PyArrayObject *) PyArray_FromAny(oc_dx, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((c_dx==NULL) || (PyArray_SIZE(c_dx) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for c_dx."); - goto _fail; - } - for(i=0;i<3;i++)ac_dx[i]=*(npy_float64*)PyArray_GETPTR1(c_dx,i); - - if (!PyList_Check(oc_data)){ - PyErr_Format(_dataCubeError, - "CombineGrids: c_data must be a list of arrays!"); - goto _fail; - } - - dl_edge = (PyArrayObject *) PyArray_FromAny(odl_edge, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((dl_edge==NULL) || (PyArray_SIZE(dl_edge) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for dl_edge."); - goto _fail; - } - for(i=0;i<3;i++)adl_edge[i]=*(npy_float64*)PyArray_GETPTR1(dl_edge,i); - - dr_edge = (PyArrayObject *) PyArray_FromAny(odr_edge, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((dr_edge==NULL) || (PyArray_SIZE(dr_edge) != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three values, one dimension required for dr_edge."); - goto _fail; - } - for(i=0;i<3;i++)adr_edge[i]=*(npy_float64*)PyArray_GETPTR1(dr_edge,i); - - n_fields = PyList_Size(oc_data); - if(n_fields == 0) { - PyErr_Format(_dataCubeError, - "CombineGrids: Length zero for c_data is invalid."); - goto _fail; - } - - PyObject *tc_data; - c_data = (PyArrayObject**) - malloc(sizeof(PyArrayObject*)*n_fields); - for (n=0;nnd != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three dimensions required for c_data[%i].",n); - goto _fail; - } - } - - if ((!PyList_Check(og_data)) || - (PyList_Size(og_data) != n_fields)){ - PyErr_Format(_dataCubeError, - "CombineGrids: g_data must be a list of arrays same length as c_data!"); - goto _fail; - } - - PyObject *tg_data; - g_data = (PyArrayObject**) - malloc(sizeof(PyArrayObject*)*n_fields); - for (n=0;nnd != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three dimensions required for g_data[%i].",n); - goto _fail; - } - } - - /* And let's begin */ - - npy_int64 xg, yg, zg, xc, yc, zc, cmax_x, cmax_y, cmax_z, - cmin_x, cmin_y, cmin_z, cm, pxl, pyl, pzl; - long int total=0; - - int p_niter[3] = {1,1,1}; - int itc; - npy_float64 ac_le_p[3][3]; - npy_float64 ac_re_p[3][3]; - npy_float64 ag_re[3]; - /* This is for checking for periodic boundary conditions. - Manually set the right edge to be offset from the left. */ - for(i=0;i<3;i++){ag_re[i] = ag_le[i]+ag_dx[i]*(g_data[0]->dimensions[i]+1);} - - for(i=0;i<3;i++){ac_le_p[i][0] = ac_le[i]; ac_re_p[i][0] = ac_re[i];} - for(i=0;i<3;i++) { - itc = 1; - if (ac_le[i] < adl_edge[i]) { - ac_le_p[i][itc ] = adr_edge[i] - (adl_edge[i] - ac_le[i]); - ac_re_p[i][itc++] = adr_edge[i] + (ac_re[i] - adl_edge[i]); - } - if (ac_re[i] > adr_edge[i]) { - ac_le_p[i][itc ] = ac_le[i] - (adr_edge[i] - adl_edge[i]); - ac_re_p[i][itc++] = adl_edge[i] + (ac_re[i] - adr_edge[i]); - } - p_niter[i] = itc; - } - npy_intp nx, ny, nz; - /* This is easier than doing a lookup every loop */ - nx = PyArray_DIM(c_data[0], 0); - ny = PyArray_DIM(c_data[0], 1); - nz = PyArray_DIM(c_data[0], 2); - npy_int64 xg_min, yg_min, zg_min; - npy_int64 xg_max, yg_max, zg_max; - - /* Periodic iterations, *if necessary* */ - for (pxl = 0; pxl < p_niter[0]; pxl++) { - xg_min = max(floor((ac_le_p[0][pxl]-ag_le[0])/ag_dx[0]) - 1, 0); - xg_max = min(ceil((ac_re_p[0][pxl]-ag_le[0])/ag_dx[0]) + 1, - g_data[0]->dimensions[0]); - for (xg = xg_min; xg < xg_max; xg++) { - /* If we're off the destination cell boundary, skip */ - if (ag_le[0]+ag_dx[0]*xg > ac_re_p[0][pxl]) continue; - if (ag_le[0]+ag_dx[0]*(xg+1) < ac_le_p[0][pxl]) continue; - /* Floor to the source edge */ - cmin_x = max(floorl((ag_le[0]+ag_dx[0]*xg - ac_le_p[0][pxl])/ac_dx[0]),0); - cmax_x = min( ceill((ag_le[0]+ag_dx[0]*(xg+1) - ac_le_p[0][pxl])/ac_dx[0]),nx); - if(cmin_x==cmax_x)continue; - for (pyl = 0; pyl < p_niter[1]; pyl++) { - yg_min = max(floor((ac_le_p[1][pyl]-ag_le[1])/ag_dx[1]) - 1, 0); - yg_max = min(ceil((ac_re_p[1][pyl]-ag_le[1])/ag_dx[1]), - g_data[0]->dimensions[1]); - for (yg = yg_min; yg < yg_max; yg++) { - if (ag_le[1]+ag_dx[1]*yg > ac_re_p[1][pyl]) continue; - if (ag_le[1]+ag_dx[1]*(yg+1) < ac_le_p[1][pyl]) continue; - cmin_y = max(floorl((ag_le[1]+ag_dx[1]*yg - ac_le_p[1][pyl])/ac_dx[1]),0); - cmax_y = min( ceill((ag_le[1]+ag_dx[1]*(yg+1) - ac_le_p[1][pyl])/ac_dx[1]),ny); - if(cmin_y==cmax_y)continue; - for (pzl = 0; pzl < p_niter[2]; pzl++) { - zg_min = max(floor((ac_le_p[2][pzl]-ag_le[2])/ag_dx[2]) - 1, 0); - zg_max = min(ceil((ac_re_p[2][pzl]-ag_le[2])/ag_dx[2]), - g_data[0]->dimensions[2]); - for (zg = zg_min; zg < zg_max; zg++) { - cm = *(npy_int *)PyArray_GETPTR3(g_cm,xg,yg,zg); - if ((!ll) && (cm == 0)) continue; - if (ag_le[2]+ag_dx[2]*zg > ac_re_p[2][pzl]) continue; - if (ag_le[2]+ag_dx[2]*(zg+1) < ac_le_p[2][pzl]) continue; - cmin_z = max(floorl((ag_le[2]+ag_dx[2]*zg - ac_le_p[2][pzl])/ac_dx[2]),0); - cmax_z = min( ceill((ag_le[2]+ag_dx[2]*(zg+1) - ac_le_p[2][pzl])/ac_dx[2]),nz); - if(cmin_z==cmax_z)continue; - for (xc = cmin_x; xc < cmax_x ; xc++) { - for (yc = cmin_y; yc < cmax_y ; yc++) { - for (zc = cmin_z; zc < cmax_z ; zc++) { - for(n=0;n val1, or grid -> covering grid - *(npy_float64*) PyArray_GETPTR3(c_data,xc,yc,zc) = - *(npy_float64*) PyArray_GETPTR3(g_data,xg,yg,zg); -} - -static void dcReplace(PyArrayObject* c_data, npy_int64 xc, npy_int64 yc, npy_int64 zc, - PyArrayObject* g_data, npy_int64 xg, npy_int64 yg, npy_int64 zg) -{ - // c_data used to be val1, g_data used to be val2 - // so we go val1 -> val2, or covering grid -> grid - *(npy_float64*) PyArray_GETPTR3(g_data,xg,yg,zg) = - *(npy_float64*) PyArray_GETPTR3(c_data,xc,yc,zc); -} - -static PyObject * -Py_DataCubeRefine(PyObject *obj, PyObject *args) -{ - PyObject* to_return = DataCubeGeneric(obj, args, dcRefine); - return to_return; -} - -static PyObject * -Py_DataCubeReplace(PyObject *obj, PyObject *args) -{ - PyObject* to_return = DataCubeGeneric(obj, args, dcReplace); - return to_return; -} - -static PyObject *Py_FillRegion(PyObject *obj, PyObject *args) -{ - PyObject *oc_data, *og_data, - *oc_start, *og_start, - *oc_dims, *og_dims, *omask; - PyObject *tg_data, *tc_data, *dw_data; - oc_data = og_data = oc_start = og_start = oc_dims = og_dims = omask = NULL; - tg_data = tc_data = dw_data = NULL; - PyArrayObject **g_data, **c_data, *mask, - *g_start, *c_start, *c_dims, *g_dims, *dwa; - mask = g_start = c_start = c_dims = g_dims = NULL; - g_data = c_data = NULL; - int refratio, ll, direction, n; - npy_int64 gxs, gys, gzs, gxe, gye, gze; - npy_int64 cxs, cys, czs, cxe, cye, cze; - npy_int64 ixs, iys, izs, ixe, iye, ize; - npy_int64 gxi, gyi, gzi, cxi, cyi, czi; - npy_int64 cdx, cdy, cdz; - npy_int64 dw[3]; - int i; - npy_int64 ci, cj, ck, ri, rj, rk; - int total = 0; - void (*to_call)(PyArrayObject* c_data, npy_int64 xc, - npy_int64 yc, npy_int64 zc, - PyArrayObject* g_data, npy_int64 xg, - npy_int64 yg, npy_int64 zg); - if (!PyArg_ParseTuple(args, "iOOOOOOOOii", - &refratio, &og_start, &oc_start, - &oc_data, &og_data, - &oc_dims, &og_dims, &omask, &dw_data, &ll, &direction)) - return PyErr_Format(_dataCubeError, - "DataCubeGeneric: Invalid parameters."); - - if (direction == 0) to_call = dcRefine; - else if (direction == 1) to_call = dcReplace; - - g_start = (PyArrayObject *) PyArray_FromAny(og_start, - PyArray_DescrFromType(NPY_INT64), 1, 1, 0, NULL); - if(g_start == NULL){ - PyErr_Format(_dataCubeError, "FillRegion: g_start invalid."); - goto _fail; - } - - c_start = (PyArrayObject *) PyArray_FromAny(oc_start, - PyArray_DescrFromType(NPY_INT64), 1, 1, 0, NULL); - if(c_start == NULL){ - PyErr_Format(_dataCubeError, "FillRegion: c_start invalid."); - goto _fail; - } - - g_dims = (PyArrayObject *) PyArray_FromAny(og_dims, - PyArray_DescrFromType(NPY_INT32), 1, 1, 0, NULL); - if(g_dims == NULL){ - PyErr_Format(_dataCubeError, "FillRegion: g_dims invalid."); - goto _fail; - } - - c_dims = (PyArrayObject *) PyArray_FromAny(oc_dims, - PyArray_DescrFromType(NPY_INT32), 1, 1, 0, NULL); - if(c_dims == NULL){ - PyErr_Format(_dataCubeError, "FillRegion: c_dims invalid."); - goto _fail; - } - - mask = (PyArrayObject *) PyArray_FromAny(omask, - PyArray_DescrFromType(NPY_INT32), 3, 3, 0, NULL); - if(mask == NULL){ - PyErr_Format(_dataCubeError, "FillRegion: mask invalid."); - goto _fail; - } - - dwa = (PyArrayObject *) PyArray_FromAny(dw_data, - PyArray_DescrFromType(NPY_INT64), 1, 1, 0, NULL); - if(dwa == NULL){ - PyErr_Format(_dataCubeError, "FillRegion: domain width invalid."); - goto _fail; - } - for (i=0;i<3;i++)dw[i] = *(npy_int64*) PyArray_GETPTR1(dwa, i); - - int n_fields = PyList_Size(oc_data); - if(n_fields == 0) { - PyErr_Format(_dataCubeError, - "CombineGrids: Length zero for c_data is invalid."); - goto _fail; - } - if (!PyList_Check(og_data) || (PyList_Size(og_data) != n_fields)){ - PyErr_Format(_dataCubeError, - "CombineGrids: g_data must be a list of arrays same length as c_data!"); - goto _fail; - } - - c_data = (PyArrayObject**) - malloc(sizeof(PyArrayObject*)*n_fields); - g_data = (PyArrayObject**) - malloc(sizeof(PyArrayObject*)*n_fields); - for (n=0;nnd != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three dimensions required for g_data[%i].",n); - goto _fail; - } - tc_data = (PyObject *) PyList_GetItem(oc_data, n); - c_data[n] = (PyArrayObject *) PyArray_FromAny(tc_data, - PyArray_DescrFromType(NPY_FLOAT64), 3, 3, - NPY_UPDATEIFCOPY, NULL); - if((c_data[n]==NULL) || (c_data[n]->nd != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three dimensions required for c_data[%i].",n); - goto _fail; - } - } - - /* g[xyz][se] are the start and end index in integers - of the grid, at its refinement level */ - gxs = *(npy_int64 *) PyArray_GETPTR1(og_start, 0); - gys = *(npy_int64 *) PyArray_GETPTR1(og_start, 1); - gzs = *(npy_int64 *) PyArray_GETPTR1(og_start, 2); - gxe = gxs + *(npy_int32 *) PyArray_GETPTR1(og_dims, 0); - gye = gys + *(npy_int32 *) PyArray_GETPTR1(og_dims, 1); - gze = gzs + *(npy_int32 *) PyArray_GETPTR1(og_dims, 2); - - /* c[xyz][se] are the start and end index in integers - of the covering grid, at its refinement level */ - cxs = *(npy_int64 *) PyArray_GETPTR1(oc_start, 0); - cys = *(npy_int64 *) PyArray_GETPTR1(oc_start, 1); - czs = *(npy_int64 *) PyArray_GETPTR1(oc_start, 2); - - /* cd[xyz] are the dimensions of the covering grid */ - cdx = (*(npy_int32 *) PyArray_GETPTR1(oc_dims, 0)); - cdy = (*(npy_int32 *) PyArray_GETPTR1(oc_dims, 1)); - cdz = (*(npy_int32 *) PyArray_GETPTR1(oc_dims, 2)); - cxe = (cxs + cdx - 1); - cye = (cys + cdy - 1); - cze = (czs + cdz - 1); - - /* It turns out that C89 doesn't define a mechanism for choosing the sign - of the remainder. - */ - //fprintf(stderr, "ci == %d, cxi == %d, dw[0] == %d\n", (int) ci, (int) cxi, (int) dw[0]); - for(cxi=cxs;cxi<=cxe;cxi++) { - ci = (cxi % dw[0]); - ci = (ci < 0) ? ci + dw[0] : ci; - if ( ci < gxs*refratio || ci >= gxe*refratio) continue; - gxi = floor(ci / refratio) - gxs; - for(cyi=cys;cyi<=cye;cyi++) { - cj = cyi % dw[1]; - cj = (cj < 0) ? cj + dw[1] : cj; - if ( cj < gys*refratio || cj >= gye*refratio) continue; - gyi = floor(cj / refratio) - gys; - for(czi=czs;czi<=cze;czi++) { - ck = czi % dw[2]; - ck = (ck < 0) ? ck + dw[2] : ck; - if ( ck < gzs*refratio || ck >= gze*refratio) continue; - gzi = floor(ck / refratio) - gzs; - if ((ll) || (*(npy_int32*)PyArray_GETPTR3(mask, gxi,gyi,gzi) > 0)) - { - for(n=0;nnd != 3)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Three dimensions required for g_data[%i].",n); - goto _fail; - } - tc_data = (PyObject *) PyList_GetItem(oc_data, n); - c_data[n] = (PyArrayObject *) PyArray_FromAny(tc_data, - PyArray_DescrFromType(NPY_FLOAT64), 2, 2, - NPY_UPDATEIFCOPY, NULL); - if((c_data[n]==NULL) || (c_data[n]->nd != 2)) { - PyErr_Format(_dataCubeError, - "CombineGrids: Two dimensions required for c_data[%i].",n); - goto _fail; - } - } - - /* g[xyz][se] are the start and end index in integers - of the grid, at its refinement level */ - gxs = *(npy_int64 *) PyArray_GETPTR1(og_start, 0); - gys = *(npy_int64 *) PyArray_GETPTR1(og_start, 1); - gzs = *(npy_int64 *) PyArray_GETPTR1(og_start, 2); - gxe = gxs + *(npy_int32 *) PyArray_GETPTR1(og_dims, 0); - gye = gys + *(npy_int32 *) PyArray_GETPTR1(og_dims, 1); - gze = gzs + *(npy_int32 *) PyArray_GETPTR1(og_dims, 2); - - /* c[xyz][se] are the start and end index in integers - of the covering grid, at its refinement level */ - cxs = *(npy_int64 *) PyArray_GETPTR1(oc_start, 0); - cys = *(npy_int64 *) PyArray_GETPTR1(oc_start, 1); - czs = *(npy_int64 *) PyArray_GETPTR1(oc_start, 2); - - /* cd[xyz] are the dimensions of the covering grid */ - cdx = (*(npy_int32 *) PyArray_GETPTR1(oc_dims, 0)); - cdy = (*(npy_int32 *) PyArray_GETPTR1(oc_dims, 1)); - cdz = (*(npy_int32 *) PyArray_GETPTR1(oc_dims, 2)); - cxe = (cxs + cdx - 1); - cye = (cys + cdy - 1); - cze = (czs + cdz - 1); - - /* It turns out that C89 doesn't define a mechanism for choosing the sign - of the remainder. - */ - int x_loc, y_loc; // For access into the buffer - for(cxi=cxs;cxi<=cxe;cxi++) { - ci = (cxi % dw[0]); - ci = (ci < 0) ? ci + dw[0] : ci; - if ( ci < gxs*refratio || ci >= gxe*refratio) continue; - gxi = floor(ci / refratio) - gxs; - for(cyi=cys;cyi<=cye;cyi++) { - cj = cyi % dw[1]; - cj = (cj < 0) ? cj + dw[1] : cj; - if ( cj < gys*refratio || cj >= gye*refratio) continue; - gyi = floor(cj / refratio) - gys; - for(czi=czs;czi<=cze;czi++) { - ck = czi % dw[2]; - ck = (ck < 0) ? ck + dw[2] : ck; - if ( ck < gzs*refratio || ck >= gze*refratio) continue; - gzi = floor(ck / refratio) - gzs; - if (*(npy_int32*)PyArray_GETPTR3(mask, gxi,gyi,gzi) > 0) - { - switch (axis) { - case 0: x_loc = cyi-cys; y_loc = czi-czs; break; - case 1: x_loc = cxi-cxs; y_loc = czi-czs; break; - case 2: x_loc = cxi-cys; y_loc = cyi-cys; break; - } - for(n=0;nnd != 3)) { - PyErr_Format(_findContoursError, - "FindContours: Three dimensions required for con_ids."); - goto _fail; - } - - xi = (PyArrayObject *) PyArray_FromAny(oxi, - PyArray_DescrFromType(NPY_INT64), 1, 1, - 0, NULL); - if(xi==NULL) { - PyErr_Format(_findContoursError, - "Bin2DProfile: One dimension required for xi."); - goto _fail; - } - - yi = (PyArrayObject *) PyArray_FromAny(oyi, - PyArray_DescrFromType(NPY_INT64), 1, 1, - 0, NULL); - if((yi==NULL) || (PyArray_SIZE(xi) != PyArray_SIZE(yi))) { - PyErr_Format(_findContoursError, - "Bin2DProfile: One dimension required for yi, same size as xi."); - goto _fail; - } - - zi = (PyArrayObject *) PyArray_FromAny(ozi, - PyArray_DescrFromType(NPY_INT64), 1, 1, - 0, NULL); - if((zi==NULL) || (PyArray_SIZE(xi) != PyArray_SIZE(zi))) { - PyErr_Format(_findContoursError, - "Bin2DProfile: One dimension required for zi, same size as xi."); - goto _fail; - } - - for(n=0;ndimensions[0];n++) { - i=*(npy_int64 *)PyArray_GETPTR1(xi,n); - j=*(npy_int64 *)PyArray_GETPTR1(yi,n); - k=*(npy_int64 *)PyArray_GETPTR1(zi,n); - status = process_neighbors(con_ids, i, j, k, 1); - if(status < 0) break; - } - - Py_DECREF(con_ids); - Py_DECREF(xi); - Py_DECREF(yi); - Py_DECREF(zi); - - PyObject *retval = PyInt_FromLong(status); - return retval; - - _fail: - Py_XDECREF(con_ids); - Py_XDECREF(xi); - Py_XDECREF(yi); - Py_XDECREF(zi); - return NULL; -} - -int process_neighbors(PyArrayObject *con_ids, npy_int64 i, npy_int64 j, - npy_int64 k, int first) -{ - npy_int64 off_i, off_j, off_k; - int spawn_check, status; - int mi, mj, mk; - static int stack_depth; - if (first == 1) stack_depth = 0; - else stack_depth++; - if (stack_depth > 10000) return -1; - npy_int64 *fd_off, *fd_ijk; - mi = con_ids->dimensions[0]; - mj = con_ids->dimensions[1]; - mk = con_ids->dimensions[2]; - fd_ijk = ((npy_int64*)PyArray_GETPTR3(con_ids, i, j, k)); - //if(*fd_ijk == -1){return ((npy_int64)*fd_ijk);} - do { - spawn_check = 0; - for (off_i=max(i-1,0);off_i<=min(i+1,mi-1);off_i++) - for (off_j=max(j-1,0);off_j<=min(j+1,mj-1);off_j++) - for (off_k=max(k-1,0);off_k<=min(k+1,mk-1);off_k++) { - if((off_i==i)&&(off_j==j)&&(off_k==k)) continue; - fd_off = ((npy_int64*)PyArray_GETPTR3(con_ids, off_i, off_j, off_k)); - if(*fd_off == -1) continue; - if(*fd_off > *fd_ijk){ - *fd_ijk = *fd_off; - spawn_check += 1; - } - if(*fd_off < *fd_ijk){ - *fd_off = *fd_ijk; - status = process_neighbors(con_ids, off_i, off_j, off_k, 0); - if (*fd_off != *fd_ijk) spawn_check += 1; - *fd_ijk = *fd_off; - if (status < 0) return -1; - } - } - } while (spawn_check > 0); - stack_depth -= 1; - return 1; -} - -static PyObject *_interpolateError; - -static void -Interpolate(long num_axis_points, npy_float64 *axis, PyArrayObject* table, - PyArrayObject *desiredvals, long num_columns, npy_int32 *columns, - PyArrayObject *outputvals) -{ - //int table_rows = table->dimensions[0]; - int num_desireds = desiredvals->dimensions[0]; - - npy_int axis_ind, col_ind; - npy_int32 column; - npy_int64 desired_num; - - npy_float64 desired; - - npy_float64 logtem0 = log10(axis[0]); - npy_float64 logtem9 = log10(axis[num_axis_points-1]); - npy_float64 dlogtem = (logtem9-logtem0)/(num_axis_points-1); - npy_float64 t1, t2, tdef, ki, kip; - npy_float64 *t; - - for (desired_num = 0 ; desired_num < num_desireds ; desired_num++) { - t = (npy_float64*)PyArray_GETPTR1(desiredvals, desired_num); - desired = log10l(*t); - axis_ind = min(num_axis_points-1, - max(0,(int)((desired-logtem0)/dlogtem)+1)); - t1 = (logtem0 + (axis_ind-1)*dlogtem); - t2 = (logtem0 + (axis_ind+0)*dlogtem); - tdef = t2 - t1; - for (column = 0 ; column < num_columns ; column++) { - col_ind = (npy_int) columns[column]; - ki = *(npy_float64*)PyArray_GETPTR2(table, (npy_int) (axis_ind-1), col_ind); - kip = *(npy_float64*)PyArray_GETPTR2(table, (npy_int) (axis_ind+0), col_ind); - *(npy_float64*) PyArray_GETPTR2(outputvals, desired_num, column) = - ki+(desired-t1)*(kip-ki)/tdef; - } - } - return; -} - -static PyObject * -Py_Interpolate(PyObject *obj, PyObject *args) -{ - PyObject *oaxis, *otable, *odesired, *ooutputvals, *ocolumns; - PyArrayObject *axis, *table, *desired, *outputvals, *columns; - - if (!PyArg_ParseTuple(args, "OOOOO", - &oaxis, &otable, &odesired, &ooutputvals, &ocolumns)) - return PyErr_Format(_interpolateError, - "Interpolate: Invalid parameters."); - - /* Align, Byteswap, Contiguous, Typeconvert */ - axis = (PyArrayObject *) PyArray_FromAny(oaxis , PyArray_DescrFromType(NPY_FLOAT64), 1, 0, NPY_ENSURECOPY | NPY_UPDATEIFCOPY, NULL ); - table = (PyArrayObject *) PyArray_FromAny(otable , PyArray_DescrFromType(NPY_FLOAT64), 1, 0, NPY_ENSURECOPY | NPY_UPDATEIFCOPY, NULL ); - desired = (PyArrayObject *) PyArray_FromAny(odesired , PyArray_DescrFromType(NPY_FLOAT64), 1, 0, NPY_ENSURECOPY | NPY_UPDATEIFCOPY, NULL ); - outputvals = (PyArrayObject *) PyArray_FromAny(ooutputvals , PyArray_DescrFromType(NPY_FLOAT64), 1, 0, NPY_ENSURECOPY | NPY_UPDATEIFCOPY, NULL ); - columns = (PyArrayObject *) PyArray_FromAny(ocolumns , PyArray_DescrFromType(NPY_INT32), 1, 0, NPY_ENSURECOPY | NPY_UPDATEIFCOPY, NULL ); - - if (!axis || !table || !desired || !outputvals || !columns) { - PyErr_Format(_interpolateError, - "Interpolate: error converting array inputs."); - goto _fail; - } - - if (columns->dimensions[0] != outputvals->dimensions[1]) { - PyErr_Format(_interpolateError, - "Interpolate: number of columns requested must match number " - "of columns in output buffer. %i", (int) columns->dimensions[0]); - goto _fail; - } - - Interpolate(axis->dimensions[0], - (npy_float64 *) PyArray_GETPTR1(axis, 0), - table, desired, - columns->dimensions[0], - (npy_int32 *) PyArray_GETPTR1(columns, 0), - outputvals); - Py_DECREF(axis); - Py_DECREF(table); - Py_DECREF(desired); - Py_DECREF(outputvals); - Py_DECREF(columns); - - /* Align, Byteswap, Contiguous, Typeconvert */ - return Py_None; - - _fail: - Py_XDECREF(axis); - Py_XDECREF(table); - Py_XDECREF(desired); - Py_XDECREF(outputvals); - Py_XDECREF(columns); - - - return NULL; -} - -static PyObject *_findBindingEnergyError; - -static PyObject * -Py_FindBindingEnergy(PyObject *obj, PyObject *args) -{ - PyObject *omass, *ox, *oy, *oz; - PyArrayObject *mass, *x, *y, *z; - x=y=z=mass=NULL; - int truncate; - double kinetic_energy; - - if (!PyArg_ParseTuple(args, "OOOOid", - &omass, &ox, &oy, &oz, &truncate, &kinetic_energy)) - return PyErr_Format(_findBindingEnergyError, - "FindBindingEnergy: Invalid parameters."); - - mass = (PyArrayObject *) PyArray_FromAny(omass, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((mass==NULL) || (mass->nd != 1)) { - PyErr_Format(_findBindingEnergyError, - "FindBindingEnergy: One dimension required for mass."); - goto _fail; - } - - x = (PyArrayObject *) PyArray_FromAny(ox, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((x==NULL) || (x->nd != 1) - || (PyArray_SIZE(x) != PyArray_SIZE(mass))) { - PyErr_Format(_findBindingEnergyError, - "FindBindingEnergy: x must be same size as mass."); - goto _fail; - } - - y = (PyArrayObject *) PyArray_FromAny(oy, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((y==NULL) || (y->nd != 1) - || (PyArray_SIZE(y) != PyArray_SIZE(mass))) { - PyErr_Format(_findBindingEnergyError, - "FindBindingEnergy: y must be same size as mass."); - goto _fail; - } - - z = (PyArrayObject *) PyArray_FromAny(oz, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((z==NULL) || (z->nd != 1) - || (PyArray_SIZE(z) != PyArray_SIZE(mass))) { - PyErr_Format(_findBindingEnergyError, - "FindBindingEnergy: z must be same size as mass."); - goto _fail; - } - - /* Do the work here. */ - int q_outer, q_inner, n_q = PyArray_SIZE(mass); - double this_potential, total_potential; - total_potential = 0; - npy_float64 mass_o, x_o, y_o, z_o; - npy_float64 mass_i, x_i, y_i, z_i; - - /* progress bar stuff */ - float totalWork = 0.5 * (pow(n_q,2.0) - n_q); - float workDone = 0; - int every_cells = floor(n_q / 100); - int until_output = 1; - for (q_outer = 0; q_outer < n_q - 1; q_outer++) { - this_potential = 0; - mass_o = *(npy_float64*) PyArray_GETPTR1(mass, q_outer); - x_o = *(npy_float64*) PyArray_GETPTR1(x, q_outer); - y_o = *(npy_float64*) PyArray_GETPTR1(y, q_outer); - z_o = *(npy_float64*) PyArray_GETPTR1(z, q_outer); - for (q_inner = q_outer+1; q_inner < n_q; q_inner++) { - mass_i = *(npy_float64*) PyArray_GETPTR1(mass, q_inner); - x_i = *(npy_float64*) PyArray_GETPTR1(x, q_inner); - y_i = *(npy_float64*) PyArray_GETPTR1(y, q_inner); - z_i = *(npy_float64*) PyArray_GETPTR1(z, q_inner); - this_potential += mass_o * mass_i / - sqrtl( (x_i-x_o)*(x_i-x_o) - + (y_i-y_o)*(y_i-y_o) - + (z_i-z_o)*(z_i-z_o) ); - } - total_potential += this_potential; - workDone += n_q - q_outer - 1; - until_output -= 1; - if(until_output == 0){ - fprintf(stderr,"Calculating Potential for %i cells: %.2f%%\t(pe/ke = %e)\r", - n_q,((100*workDone)/totalWork),(total_potential/kinetic_energy)); - fflush(stdout); fflush(stderr); - until_output = every_cells; - } - if ((truncate == 1) && (total_potential > kinetic_energy)){ - fprintf(stderr, "Truncating!\r"); - break; - } - } - fprintf(stderr,"\n"); - fflush(stdout); fflush(stderr); - - Py_DECREF(mass); - Py_DECREF(x); - Py_DECREF(y); - Py_DECREF(z); - - PyObject *status = PyFloat_FromDouble(total_potential); - return status; - - _fail: - Py_XDECREF(mass); - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(z); - return NULL; -} - -static PyObject *_outputFloatsToFileError; - -static PyObject * -Py_OutputFloatsToFile(PyObject *obj, PyObject *args) -{ - PyObject *oarray; - PyArrayObject *array; - char *filename, *header = NULL; - npy_intp i, j, imax, jmax; - - if (!PyArg_ParseTuple(args, "Os|s", &oarray, &filename, &header)) - return PyErr_Format(_outputFloatsToFileError, - "OutputFloatsToFile: Invalid parameters."); - - array = (PyArrayObject *) PyArray_FromAny(oarray, - PyArray_DescrFromType(NPY_FLOAT64), 2, 2, - 0, NULL); - if(array==NULL){ - PyErr_Format(_outputFloatsToFileError, - "OutputFloatsToFile: Failure to convert array ( nd == 2 ?)"); - goto _fail; - } - - FILE *to_write = fopen(filename, "w"); - if(to_write == NULL){ - PyErr_Format(_outputFloatsToFileError, - "OutputFloatsToFile: Unable to open %s for writing.", filename); - goto _fail; - } - - if(header!=NULL)fprintf(to_write,"%s\n", header); - - imax = PyArray_DIM(array, 0); - jmax = PyArray_DIM(array, 1); - for(i=0;i -Affiliation: KIPAC/SLAC/Stanford -Author: Samuel Skillman -Affiliation: CASA, University of Colorado at Boulder -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.lagos import * - -_field_mapping = { - "total_mass": ("CellMassMsun", "ParticleMassMsun"), - "hybrid_radius": ("RadiusCode", "ParticleRadiusCode"), - } - -class EmptyProfileData(Exception): - pass - -def preserve_source_parameters(func): - def save_state(*args, **kwargs): - # Temporarily replace the 'field_parameters' for a - # grid with the 'field_parameters' for the data source - prof = args[0] - source = args[1] - if hasattr(source, 'field_parameters'): - old_params = source.field_parameters - source.field_parameters = prof._data_source.field_parameters - tr = func(*args, **kwargs) - source.field_parameters = old_params - else: - tr = func(*args, **kwargs) - return tr - return save_state - -# Note we do not inherit from EnzoData. -# We could, but I think we instead want to deal with the root datasource. -class BinnedProfile(ParallelAnalysisInterface): - def __init__(self, data_source, lazy_reader): - self._data_source = data_source - self.pf = data_source.pf - self._data = {} - self._pdata = {} - self._lazy_reader = lazy_reader - - @property - def hierarchy(self): - return self.pf.hierarchy - - def _get_dependencies(self, fields): - return ParallelAnalysisInterface._get_dependencies( - self, fields + self._get_bin_fields()) - - def _initialize_parallel(self, fields): - g_objs = [g for g in self._get_grid_objs()] - self._preload(g_objs, self._get_dependencies(fields), - self._data_source.hierarchy.io) - - def _lazy_add_fields(self, fields, weight, accumulation): - self._ngrids = 0 - self.__data = {} # final results will go here - self.__weight_data = {} # we need to track the weights as we go - for field in fields: - self.__data[field] = self._get_empty_field() - self.__weight_data[field] = self._get_empty_field() - self.__used = self._get_empty_field().astype('bool') - #pbar = get_pbar('Binning grids', len(self._data_source._grids)) - for gi,grid in enumerate(self._get_grids(fields)): - self._ngrids += 1 - #pbar.update(gi) - try: - args = self._get_bins(grid, check_cut=True) - except EmptyProfileData: - # No bins returned for this grid, so forget it! - continue - for field in fields: - # We get back field values, weight values, used bins - f, w, u = self._bin_field(grid, field, weight, accumulation, - args=args, check_cut=True) - self.__data[field] += f # running total - self.__weight_data[field] += w # running total - self.__used = (self.__used | u) # running 'or' - grid.clear_data() - # When the loop completes the parallel finalizer gets called - #pbar.finish() - ub = na.where(self.__used) - for field in fields: - if weight: # Now, at the end, we divide out. - self.__data[field][ub] /= self.__weight_data[field][ub] - self[field] = self.__data[field] - self["UsedBins"] = self.__used - del self.__data, self.__weight_data, self.__used - - def _finalize_parallel(self): - for key in self.__data: - self.__data[key] = self._mpi_allsum(self.__data[key]) - for key in self.__weight_data: - self.__weight_data[key] = self._mpi_allsum(self.__weight_data[key]) - self.__used = self._mpi_allsum(self.__used) - - def _unlazy_add_fields(self, fields, weight, accumulation): - for field in fields: - f, w, u = self._bin_field(self._data_source, field, weight, - accumulation, self._args, check_cut = False) - if weight: - f[u] /= w[u] - self[field] = f - self["myweight"] = w - self["UsedBins"] = u - - def add_fields(self, fields, weight = "CellMassMsun", accumulation = False, fractional=False): - """ - We accept a list of *fields* which will be binned if *weight* is not - None and otherwise summed. *accumulation* determines whether or not - they will be accumulated from low to high along the appropriate axes. - """ - # Note that the specification has to be the same for all of these - fields = ensure_list(fields) - if self._lazy_reader: - self._lazy_add_fields(fields, weight, accumulation) - else: - self._unlazy_add_fields(fields, weight, accumulation) - if fractional: - for field in fields: - self._data[field] /= self._data[field].sum() - - def keys(self): - return self._data.keys() - - def __getitem__(self, key): - # This raises a KeyError if it doesn't exist - # This is because we explicitly want to add all fields - return self._data[key] - - def __setitem__(self, key, value): - self._data[key] = value - - def _get_field(self, source, this_field, check_cut): - # This is where we will iterate to get all contributions to a field - # which is how we will implement hybrid particle/cell fields - # but... we default to just the field. - data = [] - for field in _field_mapping.get(this_field, (this_field,)): - pointI = None - if check_cut: - # This conditional is so that we can have variable-length - # particle fields. Note that we can't apply the - # is_fully_enclosed to baryon fields, because child cells get - # in the way. - if field in self.pf.field_info \ - and self.pf.field_info[field].particle_type: - if not self._data_source._is_fully_enclosed(source): - pointI = self._data_source._get_particle_indices(source) - else: - pointI = self._data_source._get_point_indices(source) - data.append(source[field][pointI].ravel().astype('float64')) - return na.concatenate(data, axis=0) - - def _fix_pickle(self): - if isinstance(self._data_source, tuple): - self._data_source = self._data_source[1] - -# @todo: Fix accumulation with overriding -class BinnedProfile1D(BinnedProfile): - def __init__(self, data_source, n_bins, bin_field, - lower_bound, upper_bound, - log_space = True, lazy_reader=False, - end_collect=False): - """ - A 'Profile' produces either a weighted (or unweighted) average or a - straight sum of a field in a bin defined by another field. In the case - of a weighted average, we have: p_i = sum( w_i * v_i ) / sum(w_i) - - We accept a *data_source*, which will be binned into *n_bins* - by the field *bin_field* between the *lower_bound* and the - *upper_bound*. These bins may or may not be equally divided - in *log_space*, and the *lazy_reader* flag controls whether we - use a memory conservative approach. If *end_collect* is True, - take all values outside the given bounds and store them in the - 0 and *n_bins*-1 values. - """ - BinnedProfile.__init__(self, data_source, lazy_reader) - self.bin_field = bin_field - self._x_log = log_space - self.end_collect = end_collect - self.n_bins = n_bins - - # Get our bins - if log_space: - func = na.logspace - lower_bound, upper_bound = na.log10(lower_bound), na.log10(upper_bound) - else: - func = na.linspace - - # These are the bin *edges* - self._bins = func(lower_bound, upper_bound, n_bins + 1) - - # These are the bin *left edges*. These are the x-axis values - # we plot in the PlotCollection - self[bin_field] = self._bins - - # If we are not being memory-conservative, grab all the bins - # and the inverse indices right now. - if not lazy_reader: - self._args = self._get_bins(data_source) - - def _get_empty_field(self): - return na.zeros(self[self.bin_field].size, dtype='float64') - - @preserve_source_parameters - def _bin_field(self, source, field, weight, accumulation, - args, check_cut=False): - mi, inv_bin_indices = args # Args has the indices to use as input - # check_cut is set if source != self._data_source - # (i.e., lazy_reader) - source_data = self._get_field(source, field, check_cut)[mi] - if weight: weight_data = self._get_field(source, weight, check_cut)[mi] - binned_field = self._get_empty_field() - weight_field = self._get_empty_field() - used_field = self._get_empty_field() - # Now we perform the actual binning - for bin in inv_bin_indices.keys(): - # temp_field is *all* the points from source that go into this bin - temp_field = source_data[inv_bin_indices[bin]] - if weight: - # now w_i * v_i and store sum(w_i) - weight_field[bin] = weight_data[inv_bin_indices[bin]].sum() - temp_field *= weight_data[inv_bin_indices[bin]] - binned_field[bin] = temp_field.sum() - # inv_bin_indices is a tuple of indices - if inv_bin_indices[bin][0].size > 0: used_field[bin] = 1 - # Fix for laziness, because at the *end* we will be - # summing up all of the histograms and dividing by the - # weights. Accumulation likely doesn't work with weighted - # average fields. - if accumulation: - binned_field = na.add.accumulate(binned_field) - return binned_field, weight_field, used_field.astype("bool") - - @preserve_source_parameters - def _get_bins(self, source, check_cut=False): - source_data = self._get_field(source, self.bin_field, check_cut) - if source_data.size == 0: # Nothing for us here. - raise EmptyProfileData() - # Truncate at boundaries. - if self.end_collect: - mi = na.arange(source_data.size) - else: - mi = na.where( (source_data > self._bins.min()) - & (source_data < self._bins.max())) - sd = source_data[mi] - if sd.size == 0: - raise EmptyProfileData() - # Stick the bins into our fixed bins, set at initialization - bin_indices = na.digitize(sd, self._bins) - if self.end_collect: #limit the range of values to 0 and n_bins-1 - bin_indices = na.minimum(na.maximum(1, bin_indices), self.n_bins) - 1 - else: #throw away outside values - bin_indices -= 1 - - # Now we set up our inverse bin indices - inv_bin_indices = {} - for bin in range(self[self.bin_field].size): - # Which fall into our bin? - inv_bin_indices[bin] = na.where(bin_indices == bin) - return (mi, inv_bin_indices) - - def choose_bins(self, bin_style): - # Depending on the bin_style, choose from bin edges 0...N either: - # both: 0...N, left: 0...N-1, right: 1...N - # center: N bins that are the average (both in linear or log - # space) of each pair of left/right edges - x = self._data[self.bin_field] - if bin_style is 'both': pass - elif bin_style is 'left': x = x[:-1] - elif bin_style is 'right': x = x[1:] - elif bin_style is 'center': - if self._x_log: x=na.log10(x) - x = 0.5*(x[:-1] + x[1:]) - if self._x_log: x=10**x - else: - mylog.error('Did not recognize bin_style') - raise ValueError - return x - - def write_out(self, filename, format="%0.16e", bin_style='left'): - ''' - Write out data in ascii file, using *format* and - *bin_style* (left, right, center, both). - ''' - fid = open(filename,"w") - fields = [field for field in sorted(self._data.keys()) if field != "UsedBins"] - fields.remove(self.bin_field) - fid.write("\t".join(["#"] + [self.bin_field] + fields + ["\n"])) - - field_data = na.array(self.choose_bins(bin_style)) - if bin_style is 'both': - field_data = na.append([field_data], na.array([self._data[field] for field in fields]), axis=0) - else: - field_data = na.append([field_data], na.array([self._data[field][:-1] for field in fields]), axis=0) - - for line in range(field_data.shape[1]): - field_data[:,line].tofile(fid, sep="\t", format=format) - fid.write("\n") - fid.close() - - def write_out_h5(self, filename, group_prefix=None, bin_style='left'): - """ - Write out data in an hdf5 file *filename*. Each profile is - put into a group, named by the axis fields. Optionally a - *group_prefix* can be prepended to the group name. If the - group already exists, it will delete and replace. However, - due to hdf5 functionality, in only unlinks the data, so an - h5repack may be necessary to conserve space. Axes values are - saved in group attributes. Bins will be saved based on - *bin_style* (left, right, center, both). - """ - fid = h5py.File(filename) - fields = [field for field in sorted(self._data.keys()) if (field != "UsedBins" and field != self.bin_field)] - if group_prefix is None: - name = "%s-1d" % (self.bin_field) - else: - name = "%s-%s-1d" % (group_prefix, self.bin_field) - - if name in fid: - mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack") - del fid[name] - group = fid.create_group(name) - group.attrs["x-axis-%s" % self.bin_field] = self.choose_bins(bin_style) - for field in fields: - dset = group.create_dataset("%s" % field, data=self._data[field][:-1]) - fid.close() - - def _get_bin_fields(self): - return [self.bin_field] - -class BinnedProfile2D(BinnedProfile): - def __init__(self, data_source, - x_n_bins, x_bin_field, x_lower_bound, x_upper_bound, x_log, - y_n_bins, y_bin_field, y_lower_bound, y_upper_bound, y_log, - lazy_reader=False, end_collect=False): - """ - A 'Profile' produces either a weighted (or unweighted) average - or a straight sum of a field in a bin defined by two other - fields. In the case of a weighted average, we have: p_i = - sum( w_i * v_i ) / sum(w_i) - - We accept a *data_source*, which will be binned into - *x_n_bins* by the field *x_bin_field* between the - *x_lower_bound* and the *x_upper_bound* and then again binned - into *y_n_bins* by the field *y_bin_field* between the - *y_lower_bound* and the *y_upper_bound*. These bins may or - may not be equally divided in log-space as specified by - *x_log* and *y_log*, and the *lazy_reader* flag controls - whether we use a memory conservative approach. If - *end_collect* is True, take all values outside the given - bounds and store them in the 0 and *n_bins*-1 values. - """ - BinnedProfile.__init__(self, data_source, lazy_reader) - self.x_bin_field = x_bin_field - self.y_bin_field = y_bin_field - self._x_log = x_log - self._y_log = y_log - self.end_collect = end_collect - self.x_n_bins = x_n_bins - self.y_n_bins = y_n_bins - - func = {True:na.logspace, False:na.linspace}[x_log] - bounds = fix_bounds(x_lower_bound, x_upper_bound, x_log) - self._x_bins = func(bounds[0], bounds[1], x_n_bins + 1) - self[x_bin_field] = self._x_bins - - func = {True:na.logspace, False:na.linspace}[y_log] - bounds = fix_bounds(y_lower_bound, y_upper_bound, y_log) - self._y_bins = func(bounds[0], bounds[1], y_n_bins + 1) - self[y_bin_field] = self._y_bins - - if na.any(na.isnan(self[x_bin_field])) \ - or na.any(na.isnan(self[y_bin_field])): - mylog.error("Your min/max values for x, y have given me a nan.") - mylog.error("Usually this means you are asking for log, with a zero bound.") - raise ValueError - if not lazy_reader: - self._args = self._get_bins(data_source) - - def _get_empty_field(self): - return na.zeros((self[self.x_bin_field].size, - self[self.y_bin_field].size), dtype='float64') - - @preserve_source_parameters - def _bin_field(self, source, field, weight, accumulation, - args, check_cut=False): - source_data = self._get_field(source, field, check_cut) - if weight: weight_data = self._get_field(source, weight, check_cut) - else: weight_data = na.ones(source_data.shape, dtype='float64') - self.total_stuff = source_data.sum() - binned_field = self._get_empty_field() - weight_field = self._get_empty_field() - used_field = self._get_empty_field() - mi = args[0] - bin_indices_x = args[1].ravel().astype('int64') - bin_indices_y = args[2].ravel().astype('int64') - source_data = source_data[mi] - weight_data = weight_data[mi] - nx = bin_indices_x.size - #mylog.debug("Binning %s / %s times", source_data.size, nx) - PointCombine.Bin2DProfile(bin_indices_x, bin_indices_y, weight_data, source_data, - weight_field, binned_field, used_field) - if accumulation: # Fix for laziness - if not iterable(accumulation): - raise SyntaxError("Accumulation needs to have length 2") - if accumulation[0]: - binned_field = na.add.accumulate(binned_field, axis=0) - if accumulation[1]: - binned_field = na.add.accumulate(binned_field, axis=1) - return binned_field, weight_field, used_field.astype('bool') - - @preserve_source_parameters - def _get_bins(self, source, check_cut=False): - source_data_x = self._get_field(source, self.x_bin_field, check_cut) - source_data_y = self._get_field(source, self.y_bin_field, check_cut) - if source_data_x.size == 0: - raise EmptyProfileData() - - if self.end_collect: - mi = na.arange(source_data_x.size) - else: - mi = na.where( (source_data_x > self._x_bins.min()) - & (source_data_x < self._x_bins.max()) - & (source_data_y > self._y_bins.min()) - & (source_data_y < self._y_bins.max())) - sd_x = source_data_x[mi] - sd_y = source_data_y[mi] - if sd_x.size == 0 or sd_y.size == 0: - raise EmptyProfileData() - - bin_indices_x = na.digitize(sd_x, self._x_bins) - 1 - bin_indices_y = na.digitize(sd_y, self._y_bins) - 1 - if self.end_collect: - bin_indices_x = na.minimum(na.maximum(1, bin_indices_x), self.x_n_bins) - 1 - bin_indices_y = na.minimum(na.maximum(1, bin_indices_y), self.y_n_bins) - 1 - - # Now we set up our inverse bin indices - return (mi, bin_indices_x, bin_indices_y) - - def choose_bins(self, bin_style): - # Depending on the bin_style, choose from bin edges 0...N either: - # both: 0...N, left: 0...N-1, right: 1...N - # center: N bins that are the average (both in linear or log - # space) of each pair of left/right edges - - x = self._data[self.x_bin_field] - y = self._data[self.y_bin_field] - if bin_style is 'both': - pass - elif bin_style is 'left': - x = x[:-1] - y = y[:-1] - elif bin_style is 'right': - x = x[1:] - y = y[1:] - elif bin_style is 'center': - if self._x_log: x=na.log10(x) - if self._y_log: y=na.log10(y) - x = 0.5*(x[:-1] + x[1:]) - y = 0.5*(y[:-1] + y[1:]) - if self._x_log: x=10**x - if self._y_log: y=10**y - else: - mylog.error('Did not recognize bin_style') - raise ValueError - - return x,y - - def write_out(self, filename, format="%0.16e", bin_style='left'): - """ - Write out the values of x,y,v in ascii to *filename* for every - field in the profile. Optionally a *format* can be specified. - Bins will be saved based on *bin_style* (left, right, center, - both). - """ - fid = open(filename,"w") - fields = [field for field in sorted(self._data.keys()) if field != "UsedBins"] - fid.write("\t".join(["#"] + [self.x_bin_field, self.y_bin_field] - + fields + ["\n"])) - x,y = self.choose_bins(bin_style) - x,y = na.meshgrid(x,y) - field_data = [x.ravel(), y.ravel()] - if bin_style is not 'both': - field_data += [self._data[field][:-1,:-1].ravel() for field in fields - if field not in [self.x_bin_field, self.y_bin_field]] - else: - field_data += [self._data[field].ravel() for field in fields - if field not in [self.x_bin_field, self.y_bin_field]] - - field_data = na.array(field_data) - for line in range(field_data.shape[1]): - field_data[:,line].tofile(fid, sep="\t", format=format) - fid.write("\n") - fid.close() - - def write_out_h5(self, filename, group_prefix=None, bin_style='left'): - """ - Write out data in an hdf5 file. Each profile is put into a - group, named by the axis fields. Optionally a group_prefix - can be prepended to the group name. If the group already - exists, it will delete and replace. However, due to hdf5 - functionality, in only unlinks the data, so an h5repack may be - necessary to conserve space. Axes values are saved in group - attributes. Bins will be saved based on *bin_style* (left, - right, center, both). - """ - fid = h5py.File(filename) - fields = [field for field in sorted(self._data.keys()) if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field)] - if group_prefix is None: - name = "%s-%s-2d" % (self.y_bin_field, self.x_bin_field) - else: - name = "%s-%s-%s-2d" % (group_prefix, self.y_bin_field, self.x_bin_field) - if name in fid: - mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack") - del fid[name] - group = fid.create_group(name) - - xbins, ybins = self.choose_bins(bin_style) - group.attrs["x-axis-%s" % self.x_bin_field] = xbins - group.attrs["y-axis-%s" % self.y_bin_field] = ybins - for field in fields: - dset = group.create_dataset("%s" % field, data=self._data[field][:-1,:-1]) - fid.close() - - def _get_bin_fields(self): - return [self.x_bin_field, self.y_bin_field] - -def fix_bounds(upper, lower, logit): - if logit: return na.log10(upper), na.log10(lower) - return upper, lower - -class BinnedProfile3D(BinnedProfile): - """ - A 'Profile' produces either a weighted (or unweighted) average - or a straight sum of a field in a bin defined by two other - fields. In the case of a weighted average, we have: p_i = - sum( w_i * v_i ) / sum(w_i) - - We accept a *data_source*, which will be binned into - *(x,y,z)_n_bins* by the field *(x,y,z)_bin_field* between the - *(x,y,z)_lower_bound* and the *(x,y,z)_upper_bound*. These bins may or - may not be equally divided in log-space as specified by - *(x,y,z)_log*, and the *lazy_reader* flag controls - whether we use a memory conservative approach. If - *end_collect* is True, take all values outside the given - bounds and store them in the 0 and *n_bins*-1 values. - """ - def __init__(self, data_source, - x_n_bins, x_bin_field, x_lower_bound, x_upper_bound, x_log, - y_n_bins, y_bin_field, y_lower_bound, y_upper_bound, y_log, - z_n_bins, z_bin_field, z_lower_bound, z_upper_bound, z_log, - lazy_reader=False, end_collect=False): - BinnedProfile.__init__(self, data_source, lazy_reader) - self.x_bin_field = x_bin_field - self.y_bin_field = y_bin_field - self.z_bin_field = z_bin_field - self._x_log = x_log - self._y_log = y_log - self._z_log = z_log - self.end_collect = end_collect - self.x_n_bins = x_n_bins - self.y_n_bins = y_n_bins - self.z_n_bins = z_n_bins - - func = {True:na.logspace, False:na.linspace}[x_log] - bounds = fix_bounds(x_lower_bound, x_upper_bound, x_log) - self._x_bins = func(bounds[0], bounds[1], x_n_bins + 1) - self[x_bin_field] = self._x_bins - - func = {True:na.logspace, False:na.linspace}[y_log] - bounds = fix_bounds(y_lower_bound, y_upper_bound, y_log) - self._y_bins = func(bounds[0], bounds[1], y_n_bins + 1) - self[y_bin_field] = self._y_bins - - func = {True:na.logspace, False:na.linspace}[z_log] - bounds = fix_bounds(z_lower_bound, z_upper_bound, z_log) - self._z_bins = func(bounds[0], bounds[1], z_n_bins + 1) - self[z_bin_field] = self._z_bins - - if na.any(na.isnan(self[x_bin_field])) \ - or na.any(na.isnan(self[y_bin_field])) \ - or na.any(na.isnan(self[z_bin_field])): - mylog.error("Your min/max values for x, y or z have given me a nan.") - mylog.error("Usually this means you are asking for log, with a zero bound.") - raise ValueError - if not lazy_reader: - self._args = self._get_bins(data_source) - - def _get_empty_field(self): - return na.zeros((self[self.x_bin_field].size, - self[self.y_bin_field].size, - self[self.z_bin_field].size), dtype='float64') - - @preserve_source_parameters - def _bin_field(self, source, field, weight, accumulation, - args, check_cut=False): - source_data = self._get_field(source, field, check_cut) - weight_data = na.ones(source_data.shape).astype('float64') - if weight: weight_data = self._get_field(source, weight, check_cut) - else: weight_data = na.ones(source_data.shape).astype('float64') - self.total_stuff = source_data.sum() - binned_field = self._get_empty_field() - weight_field = self._get_empty_field() - used_field = self._get_empty_field() - mi = args[0] - bin_indices_x = args[1].ravel().astype('int64') - bin_indices_y = args[2].ravel().astype('int64') - bin_indices_z = args[3].ravel().astype('int64') - source_data = source_data[mi] - weight_data = weight_data[mi] - PointCombine.Bin3DProfile( - bin_indices_x, bin_indices_y, bin_indices_z, - weight_data, source_data, - weight_field, binned_field, used_field) - if accumulation: # Fix for laziness - if not iterable(accumulation): - raise SyntaxError("Accumulation needs to have length 2") - if accumulation[0]: - binned_field = na.add.accumulate(binned_field, axis=0) - if accumulation[1]: - binned_field = na.add.accumulate(binned_field, axis=1) - if accumulation[2]: - binned_field = na.add.accumulate(binned_field, axis=2) - return binned_field, weight_field, used_field.astype('bool') - - @preserve_source_parameters - def _get_bins(self, source, check_cut=False): - source_data_x = self._get_field(source, self.x_bin_field, check_cut) - source_data_y = self._get_field(source, self.y_bin_field, check_cut) - source_data_z = self._get_field(source, self.z_bin_field, check_cut) - if source_data_x.size == 0: - raise EmptyProfileData() - if self.end_collect: - mi = na.arange(source_data_x.size) - else: - mi = ( (source_data_x > self._x_bins.min()) - & (source_data_x < self._x_bins.max()) - & (source_data_y > self._y_bins.min()) - & (source_data_y < self._y_bins.max()) - & (source_data_z > self._z_bins.min()) - & (source_data_z < self._z_bins.max())) - sd_x = source_data_x[mi] - sd_y = source_data_y[mi] - sd_z = source_data_z[mi] - if sd_x.size == 0 or sd_y.size == 0 or sd_z.size == 0: - raise EmptyProfileData() - - bin_indices_x = na.digitize(sd_x, self._x_bins) - 1 - bin_indices_y = na.digitize(sd_y, self._y_bins) - 1 - bin_indices_z = na.digitize(sd_z, self._z_bins) - 1 - if self.end_collect: - bin_indices_x = na.minimum(na.maximum(1, bin_indices_x), self.x_n_bins) - 1 - bin_indices_y = na.minimum(na.maximum(1, bin_indices_y), self.y_n_bins) - 1 - bin_indices_z = na.minimum(na.maximum(1, bin_indices_z), self.z_n_bins) - 1 - - # Now we set up our inverse bin indices - return (mi, bin_indices_x, bin_indices_y, bin_indices_z) - - def choose_bins(self, bin_style): - # Depending on the bin_style, choose from bin edges 0...N either: - # both: 0...N, left: 0...N-1, right: 1...N - # center: N bins that are the average (both in linear or log - # space) of each pair of left/right edges - - x = self._data[self.x_bin_field] - y = self._data[self.y_bin_field] - z = self._data[self.z_bin_field] - if bin_style is 'both': - pass - elif bin_style is 'left': - x = x[:-1] - y = y[:-1] - z = z[:-1] - elif bin_style is 'right': - x = x[1:] - y = y[1:] - z = z[1:] - elif bin_style is 'center': - if self._x_log: x=na.log10(x) - if self._y_log: y=na.log10(y) - if self._z_log: z=na.log10(z) - x = 0.5*(x[:-1] + x[1:]) - y = 0.5*(y[:-1] + y[1:]) - z = 0.5*(z[:-1] + z[1:]) - if self._x_log: x=10**x - if self._y_log: y=10**y - if self._z_log: y=10**z - else: - mylog.error('Did not recognize bin_style') - raise ValueError - - return x,y,z - - def write_out(self, filename, format="%0.16e"): - pass # Will eventually dump HDF5 - - def write_out_h5(self, filename, group_prefix=None, bin_style='left'): - """ - Write out data in an hdf5 file. Each profile is put into a - group, named by the axis fields. Optionally a group_prefix - can be prepended to the group name. If the group already - exists, it will delete and replace. However, due to hdf5 - functionality, in only unlinks the data, so an h5repack may be - necessary to conserve space. Axes values are saved in group - attributes. - """ - fid = h5py.File(filename) - fields = [field for field in sorted(self._data.keys()) - if (field != "UsedBins" and field != self.x_bin_field and field != self.y_bin_field and field != self.z_bin_field)] - if group_prefix is None: - name = "%s-%s-%s-3d" % (self.z_bin_field, self.y_bin_field, self.x_bin_field) - else: - name = "%s-%s-%s-%s-3d" % (group_prefix,self.z_bin_field, self.y_bin_field, self.x_bin_field) - - if name in fid: - mylog.info("Profile file is getting larger since you are attempting to overwrite a profile. You may want to repack") - del fid[name] - group = fid.create_group(name) - - xbins, ybins, zbins= self.choose_bins(bin_style) - group.attrs["x-axis-%s" % self.x_bin_field] = xbins - group.attrs["y-axis-%s" % self.y_bin_field] = ybins - group.attrs["z-axis-%s" % self.z_bin_field] = zbins - - for field in fields: - dset = group.create_dataset("%s" % field, data=self._data[field][:-1,:-1,:-1]) - fid.close() - - - def _get_bin_fields(self): - return [self.x_bin_field, self.y_bin_field, self.z_bin_field] - - def store_profile(self, name, force=False): - """ - By identifying the profile with a fixed, user-input *name* we can - store it in the serialized data section of the hierarchy file. *force* - governs whether or not an existing profile with that name will be - overwritten. - """ - # First we get our data in order - order = [] - set_attr = {'x_bin_field':self.x_bin_field, - 'y_bin_field':self.y_bin_field, - 'z_bin_field':self.z_bin_field, - 'x_bin_values':self[self.x_bin_field], - 'y_bin_values':self[self.y_bin_field], - 'z_bin_values':self[self.z_bin_field], - '_x_log':self._x_log, - '_y_log':self._y_log, - '_z_log':self._z_log, - 'shape': (self[self.x_bin_field].size, - self[self.y_bin_field].size, - self[self.z_bin_field].size), - 'field_order':order } - values = [] - for field in self._data: - if field in set_attr.values(): continue - order.append(field) - values.append(self[field].ravel()) - values = na.array(values).transpose() - self._data_source.hierarchy.save_data(values, "/Profiles", name, - set_attr, force=force) - -class StoredBinnedProfile3D(BinnedProfile3D): - def __init__(self, pf, name): - """ - Given a *pf* parameterfile and the *name* of a stored profile, retrieve - it into a read-only data structure. - """ - self._data = {} - prof_arr = pf.h.get_data("/Profiles", name) - if prof_arr is None: raise KeyError("No such array") - for ax in 'xyz': - for base in ['%s_bin_field', '_%s_log']: - setattr(self, base % ax, prof_arr.getAttr(base % ax)) - for ax in 'xyz': - fn = getattr(self, '%s_bin_field' % ax) - self._data[fn] = prof_arr.getAttr('%s_bin_values' % ax) - shape = prof_arr.getAttr('shape') - for fn, fd in zip(prof_arr.getAttr('field_order'), - prof_arr.read().transpose()): - self._data[fn] = fd.reshape(shape) - - def add_fields(self, *args, **kwargs): - raise RuntimeError("Sorry, you can't add to a stored profile.") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/RAMSESFields.py --- a/yt/lagos/RAMSESFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -""" -RAMSES-specific fields - -Author: Matthew Turk -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 . -""" - -from UniversalFields import * -class RAMSESFieldContainer(CodeFieldInfoContainer): - _shared_state = {} - _field_list = {} -RAMSESFieldInfo = RAMSESFieldContainer() -add_ramses_field = RAMSESFieldInfo.add_field - -add_field = add_ramses_field - -translation_dict = {"Density":"density", - "x-velocity":"velocity_x", - "y-velocity":"velocity_y", - "z-velocity":"velocity_z", - "Pressure":"pressure", - "Metallicity":"metallicity", - } - -def _generate_translation(mine, theirs): - add_field(theirs, function=lambda a, b: b[mine], take_log=True) - -for f,v in translation_dict.items(): - if v not in RAMSESFieldInfo: - add_field(v, function=lambda a,b: None, take_log=False, - validators = [ValidateDataField(v)]) - #print "Setting up translator from %s to %s" % (v, f) - _generate_translation(v, f) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/UniversalFields.py --- a/yt/lagos/UniversalFields.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,807 +0,0 @@ -""" -The basic field info container resides here. These classes, code specific and -universal, are the means by which we access fields across YT, both derived and -native. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -import types -import numpy as na -import inspect -import copy - -from math import pi - -from yt.funcs import * -from field_info_container import * - -from yt.amr_utils import CICDeposit_3 - -mh = 1.67e-24 # g -me = 9.11e-28 # g -sigma_thompson = 6.65e-25 # cm^2 -clight = 3.0e10 # cm/s -kboltz = 1.38e-16 # erg K^-1 -G = 6.67e-8 # cm^3 g^-1 s^-2 - - - -# Note that, despite my newfound efforts to comply with PEP-8, -# I violate it here in order to keep the name/func_name relationship - -def _dx(field, data): - return data.dds[0] - return na.ones(data.ActiveDimensions, dtype='float64') * data.dds[0] -add_field('dx', function=_dx, display_field=False, - validators=[ValidateSpatial(0)]) - -def _dy(field, data): - return data.dds[1] - return na.ones(data.ActiveDimensions, dtype='float64') * data.dds[1] -add_field('dy', function=_dy, display_field=False, - validators=[ValidateSpatial(0)]) - -def _dz(field, data): - return data.dds[2] - return na.ones(data.ActiveDimensions, dtype='float64') * data.dds[2] -add_field('dz', function=_dz, - display_field=False, validators=[ValidateSpatial(0)]) - -def _coordX(field, data): - dim = data.ActiveDimensions[0] - return (na.ones(data.ActiveDimensions, dtype='float64') - * na.arange(data.ActiveDimensions[0])[:,None,None] - +0.5) * data['dx'] + data.LeftEdge[0] -add_field('x', function=_coordX, display_field=False, - validators=[ValidateSpatial(0)]) - -def _coordY(field, data): - dim = data.ActiveDimensions[1] - return (na.ones(data.ActiveDimensions, dtype='float64') - * na.arange(data.ActiveDimensions[1])[None,:,None] - +0.5) * data['dy'] + data.LeftEdge[1] -add_field('y', function=_coordY, display_field=False, - validators=[ValidateSpatial(0)]) - -def _coordZ(field, data): - dim = data.ActiveDimensions[2] - return (na.ones(data.ActiveDimensions, dtype='float64') - * na.arange(data.ActiveDimensions[2])[None,None,:] - +0.5) * data['dz'] + data.LeftEdge[2] -add_field('z', function=_coordZ, display_field=False, - validators=[ValidateSpatial(0)]) - -def _GridLevel(field, data): - return na.ones(data.ActiveDimensions)*(data.Level) -add_field("GridLevel", function=_GridLevel, - validators=[ValidateGridType(), - ValidateSpatial(0)]) - -def _GridIndices(field, data): - return na.ones(data["Ones"].shape)*(data.id-data._id_offset) -add_field("GridIndices", function=_GridIndices, - validators=[ValidateGridType(), - ValidateSpatial(0)], take_log=False) - -def _OnesOverDx(field, data): - return na.ones(data["Ones"].shape, - dtype=data["Density"].dtype)/data['dx'] -add_field("OnesOverDx", function=_OnesOverDx, - display_field=False) - -def _Ones(field, data): - return na.ones(data.ActiveDimensions, dtype='float64') -add_field("Ones", function=_Ones, - validators=[ValidateSpatial(0)], - projection_conversion="unitary", - display_field = False) -add_field("CellsPerBin", function=_Ones, validators=[ValidateSpatial(0)], - display_field = False) - -def _SoundSpeed(field, data): - if data.pf["EOSType"] == 1: - return na.ones(data["Density"].shape, dtype='float64') * \ - data.pf["EOSSoundSpeed"] - return ( data.pf["Gamma"]*data["Pressure"] / \ - data["Density"] )**(1.0/2.0) -add_field("SoundSpeed", function=_SoundSpeed, - units=r"\rm{cm}/\rm{s}") - -def particle_func(p_field, dtype='float64'): - def _Particles(field, data): - io = data.hierarchy.io - if not data.NumberOfParticles > 0: - return na.array([], dtype=dtype) - try: - return io._read_data_set(data, p_field).astype(dtype) - except io._read_exception: - pass - # This is bad. But it's the best idea I have right now. - return data._read_data(p_field.replace("_"," ")).astype(dtype) - return _Particles -for pf in ["type", "mass"] + \ - ["position_%s" % ax for ax in 'xyz']: - pfunc = particle_func("particle_%s" % (pf)) - add_field("particle_%s" % pf, function=pfunc, - validators = [ValidateSpatial(0)], - particle_type=True) - -def _convRetainInt(data): - return 1 -add_field("particle_index", function=particle_func("particle_index", "int64"), - validators = [ValidateSpatial(0)], particle_type=True, - convert_function=_convRetainInt) - -def _get_vel_convert(ax): - def _convert_p_vel(data): - return data.convert("%s-velocity" % ax) - return _convert_p_vel -for ax in 'xyz': - pf = "particle_velocity_%s" % ax - pfunc = particle_func(pf) - cfunc = _get_vel_convert(ax) - add_field(pf, function=pfunc, convert_function=cfunc, - validators = [ValidateSpatial(0)], - particle_type=True) - -for pf in ["creation_time", "dynamical_time", "metallicity_fraction"]: - pfunc = particle_func(pf) - add_field(pf, function=pfunc, - validators = [ValidateSpatial(0), - ValidateDataField(pf)], - particle_type=True) -add_field("particle_mass", function=particle_func("particle_mass"), - validators=[ValidateSpatial(0)], particle_type=True) - -def _ParticleAge(field, data): - current_time = data.pf["InitialTime"] - return (current_time - data["creation_time"]) -def _convertParticleAge(data): - return data.convert("years") -add_field("ParticleAge", - function=_ParticleAge, validators=[ValidateSpatial(0)], - particle_type=True, convert_function=_convertParticleAge) - -def _ParticleMass(field, data): - particles = data["particle_mass"].astype('float64') * \ - just_one(data["CellVolumeCode"].ravel()) - # Note that we mandate grid-type here, so this is okay - return particles - -def _convertParticleMass(data): - return data.convert("Density")*(data.convert("cm")**3.0) -def _IOLevelParticleMass(grid): - dd = dict(particle_mass = na.ones(1), CellVolumeCode=grid["CellVolumeCode"]) - cf = (_ParticleMass(None, dd) * _convertParticleMass(grid))[0] - return cf -def _convertParticleMassMsun(data): - return data.convert("Density")*((data.convert("cm")**3.0)/1.989e33) -def _IOLevelParticleMassMsun(grid): - dd = dict(particle_mass = na.ones(1), CellVolumeCode=grid["CellVolumeCode"]) - cf = (_ParticleMass(None, dd) * _convertParticleMassMsun(grid))[0] - return cf -add_field("ParticleMass", - function=_ParticleMass, validators=[ValidateSpatial(0)], - particle_type=True, convert_function=_convertParticleMass, - particle_convert_function=_IOLevelParticleMass) -add_field("ParticleMassMsun", - function=_ParticleMass, validators=[ValidateSpatial(0)], - particle_type=True, convert_function=_convertParticleMassMsun, - particle_convert_function=_IOLevelParticleMassMsun) - -def _RadialMachNumber(field, data): - """M{|v|/t_sound}""" - return na.abs(data["RadialVelocity"]) / data["SoundSpeed"] -add_field("RadialMachNumber", function=_RadialMachNumber) - -def _MachNumber(field, data): - """M{|v|/t_sound}""" - return data["VelocityMagnitude"] / data["SoundSpeed"] -add_field("MachNumber", function=_MachNumber) - -def _CourantTimeStep(field, data): - t1 = data['dx'] / ( - data["SoundSpeed"] + \ - abs(data["x-velocity"])) - t2 = data['dy'] / ( - data["SoundSpeed"] + \ - abs(data["y-velocity"])) - t3 = data['dz'] / ( - data["SoundSpeed"] + \ - abs(data["z-velocity"])) - return na.minimum(na.minimum(t1,t2),t3) -def _convertCourantTimeStep(data): - # SoundSpeed and z-velocity are in cm/s, dx is in code - return data.convert("cm") -add_field("CourantTimeStep", function=_CourantTimeStep, - convert_function=_convertCourantTimeStep, - units=r"$\rm{s}$") - -def _ParticleVelocityMagnitude(field, data): - """M{|v|}""" - bulk_velocity = data.get_field_parameter("bulk_velocity") - if bulk_velocity == None: - bulk_velocity = na.zeros(3) - return ( (data["particle_velocity_x"]-bulk_velocity[0])**2.0 + \ - (data["particle_velocity_y"]-bulk_velocity[1])**2.0 + \ - (data["particle_velocity_z"]-bulk_velocity[2])**2.0 )**(1.0/2.0) -add_field("ParticleVelocityMagnitude", function=_ParticleVelocityMagnitude, - particle_type=True, - take_log=False, units=r"\rm{cm}/\rm{s}") - -def _VelocityMagnitude(field, data): - """M{|v|}""" - bulk_velocity = data.get_field_parameter("bulk_velocity") - if bulk_velocity == None: - bulk_velocity = na.zeros(3) - return ( (data["x-velocity"]-bulk_velocity[0])**2.0 + \ - (data["y-velocity"]-bulk_velocity[1])**2.0 + \ - (data["z-velocity"]-bulk_velocity[2])**2.0 )**(1.0/2.0) -add_field("VelocityMagnitude", function=_VelocityMagnitude, - take_log=False, units=r"\rm{cm}/\rm{s}") - -def _TangentialOverVelocityMagnitude(field, data): - return na.abs(data["TangentialVelocity"])/na.abs(data["VelocityMagnitude"]) -add_field("TangentialOverVelocityMagnitude", - function=_TangentialOverVelocityMagnitude, - take_log=False) - -def _TangentialVelocity(field, data): - return na.sqrt(data["VelocityMagnitude"]**2.0 - - data["RadialVelocity"]**2.0) -add_field("TangentialVelocity", - function=_TangentialVelocity, - take_log=False, units=r"\rm{cm}/\rm{s}") - -def _Pressure(field, data): - """M{(Gamma-1.0)*rho*E}""" - return (data.pf["Gamma"] - 1.0) * \ - data["Density"] * data["ThermalEnergy"] -add_field("Pressure", function=_Pressure, units=r"\rm{dyne}/\rm{cm}^{2}") - -def _Entropy(field, data): - return (kboltz/mh) * data["Temperature"] / \ - (data["MeanMolecularWeight"] * data["Density"]**(2./3.)) -add_field("Entropy", units=r"\rm{ergs}\/\rm{cm}^{2}", - function=_Entropy) - -def _Height(field, data): - # We take the dot product of the radius vector with the height-vector - center = data.get_field_parameter("center") - r_vec = na.array([data["x"] - center[0], - data["y"] - center[1], - data["z"] - center[2]]) - h_vec = na.array(data.get_field_parameter("height_vector")) - h_vec = h_vec / na.sqrt(h_vec[0]**2.0+ - h_vec[1]**2.0+ - h_vec[2]**2.0) - height = r_vec[0,:] * h_vec[0] \ - + r_vec[1,:] * h_vec[1] \ - + r_vec[2,:] * h_vec[2] - return na.abs(height) -def _convertHeight(data): - return data.convert("cm") -def _convertHeightAU(data): - return data.convert("au") -add_field("Height", function=_Height, - convert_function=_convertHeight, - validators=[ValidateParameter("height_vector")], - units=r"cm", display_field=False) -add_field("HeightAU", function=_Height, - convert_function=_convertHeightAU, - validators=[ValidateParameter("height_vector")], - units=r"AU", display_field=False) - -def _DiskAngle(field, data): - # We make both r_vec and h_vec into unit vectors - center = data.get_field_parameter("center") - r_vec = na.array([data["x"] - center[0], - data["y"] - center[1], - data["z"] - center[2]]) - r_vec = r_vec/na.sqrt((r_vec**2.0).sum(axis=0)) - h_vec = na.array(data.get_field_parameter("height_vector")) - dp = r_vec[0,:] * h_vec[0] \ - + r_vec[1,:] * h_vec[1] \ - + r_vec[2,:] * h_vec[2] - return na.arccos(dp) -add_field("DiskAngle", function=_DiskAngle, - take_log=False, - validators=[ValidateParameter("height_vector"), - ValidateParameter("center")], - display_field=False) - -def _DynamicalTime(field, data): - """ - The formulation for the dynamical time is: - M{sqrt(3pi/(16*G*rho))} or M{sqrt(3pi/(16G))*rho^-(1/2)} - Note that we return in our natural units already - """ - return (3.0*pi/(16*G*data["Density"]))**(1./2.) -add_field("DynamicalTime", function=_DynamicalTime, - units=r"\rm{s}") - -def JeansMassMsun(field,data): - return (MJ_constant * - ((data["Temperature"]/data["MeanMolecularWeight"])**(1.5)) * - (data["Density"]**(-0.5))) -add_field("JeansMassMsun",function=JeansMassMsun,units=r"\rm{Msun}") - -def _CellMass(field, data): - return data["Density"] * data["CellVolume"] -def _convertCellMassMsun(data): - return 5.027854e-34 # g^-1 -add_field("CellMass", function=_CellMass, units=r"\rm{g}") -add_field("CellMassMsun", units=r"M_{\odot}", - function=_CellMass, - convert_function=_convertCellMassMsun) - -def _CellMassCode(field, data): - return data["Density"] * data["CellVolumeCode"] -def _convertCellMassCode(data): - return 1.0/data.convert("Density") -add_field("CellMassCode", - function=_CellMassCode, - convert_function=_convertCellMassCode) - -def _TotalMass(field,data): - return (data["Density"]+data["Dark_Matter_Density"]) * data["CellVolume"] -add_field("TotalMassMsun", units=r"M_{\odot}", - function=_TotalMass, - convert_function=_convertCellMassMsun) - -def _StarMass(field,data): - return data["star_density_pyx"] * data["CellVolume"] -add_field("StarMassMsun", units=r"M_{\odot}", - function=_StarMass, - convert_function=_convertCellMassMsun) - -def _Matter_Density(field,data): - return (data['Density'] + data['Dark_Matter_Density']) -add_field("Matter_Density",function=_Matter_Density,units=r"\rm{g}/\rm{cm^3}") - -def _CellVolume(field, data): - if data['dx'].size == 1: - try: - return data['dx']*data['dy']*data['dx']*\ - na.ones(data.ActiveDimensions, dtype='float64') - except AttributeError: - return data['dx']*data['dy']*data['dx'] - return data["dx"]*data["dy"]*data["dz"] -def _ConvertCellVolumeMpc(data): - return data.convert("mpc")**3.0 -def _ConvertCellVolumeCGS(data): - return data.convert("cm")**3.0 -add_field("CellVolumeCode", units=r"\rm{BoxVolume}^3", - function=_CellVolume) -add_field("CellVolumeMpc", units=r"\rm{Mpc}^3", - function=_CellVolume, - convert_function=_ConvertCellVolumeMpc) -add_field("CellVolume", units=r"\rm{cm}^3", - function=_CellVolume, - convert_function=_ConvertCellVolumeCGS) - -def _XRayEmissivity(field, data): - return ((data["Density"].astype('float64')**2.0) \ - *data["Temperature"]**0.5) -def _convertXRayEmissivity(data): - return 2.168e60 -add_field("XRayEmissivity", function=_XRayEmissivity, - convert_function=_convertXRayEmissivity, - projection_conversion="1") - -def _SZKinetic(field, data): - vel_axis = data.get_field_parameter('axis') - if vel_axis > 2: - raise NeedsParameter(['axis']) - vel = data["%s-velocity" % ({0:'x',1:'y',2:'z'}[vel_axis])] - return (vel*data["Density"]) -def _convertSZKinetic(data): - return 0.88*((sigma_thompson/mh)/clight) -add_field("SZKinetic", function=_SZKinetic, - convert_function=_convertSZKinetic, - validators=[ValidateParameter('axis')]) - -def _SZY(field, data): - return (data["Density"]*data["Temperature"]) -def _convertSZY(data): - conv = (0.88/mh) * (kboltz)/(me * clight*clight) * sigma_thompson - return conv -add_field("SZY", function=_SZY, convert_function=_convertSZY) - -def _AveragedDensity(field, data): - nx, ny, nz = data["Density"].shape - new_field = na.zeros((nx-2,ny-2,nz-2), dtype='float64') - weight_field = na.zeros((nx-2,ny-2,nz-2), dtype='float64') - i_i, j_i, k_i = na.mgrid[0:3,0:3,0:3] - for i,j,k in zip(i_i.ravel(),j_i.ravel(),k_i.ravel()): - sl = [slice(i,nx-(2-i)),slice(j,ny-(2-j)),slice(k,nz-(2-k))] - new_field += data["Density"][sl] * data["CellMass"][sl] - weight_field += data["CellMass"][sl] - # Now some fancy footwork - new_field2 = na.zeros((nx,ny,nz)) - new_field2[1:-1,1:-1,1:-1] = new_field/weight_field - return new_field2 -add_field("AveragedDensity", - function=_AveragedDensity, - validators=[ValidateSpatial(1)]) - -def _DivV(field, data): - # We need to set up stencils - if data.pf["HydroMethod"] == 2: - sl_left = slice(None,-2,None) - sl_right = slice(1,-1,None) - div_fac = 1.0 - else: - sl_left = slice(None,-2,None) - sl_right = slice(2,None,None) - div_fac = 2.0 - ds = div_fac * data['dx'].flat[0] - f = data["x-velocity"][sl_right,1:-1,1:-1]/ds - f -= data["x-velocity"][sl_left ,1:-1,1:-1]/ds - ds = div_fac * data['dy'].flat[0] - f += data["y-velocity"][1:-1,sl_right,1:-1]/ds - f -= data["y-velocity"][1:-1,sl_left ,1:-1]/ds - ds = div_fac * data['dz'].flat[0] - f += data["z-velocity"][1:-1,1:-1,sl_right]/ds - f -= data["z-velocity"][1:-1,1:-1,sl_left ]/ds - new_field = na.zeros(data["x-velocity"].shape, dtype='float64') - new_field[1:-1,1:-1,1:-1] = f - return new_field -def _convertDivV(data): - return data.convert("cm")**-1.0 -add_field("DivV", function=_DivV, - validators=[ValidateSpatial(1, - ["x-velocity","y-velocity","z-velocity"])], - units=r"\rm{s}^{-1}", take_log=False, - convert_function=_convertDivV) - -def _AbsDivV(field, data): - return na.abs(data['DivV']) -add_field("AbsDivV", function=_AbsDivV, - units=r"\rm{s}^{-1}") - -def _Contours(field, data): - return na.ones(data["Density"].shape)*-1 -add_field("Contours", validators=[ValidateSpatial(0)], take_log=False, - display_field=False, function=_Contours) -add_field("tempContours", function=_Contours, - validators=[ValidateSpatial(0), ValidateGridType()], - take_log=False, display_field=False) - -def obtain_velocities(data): - if data.has_field_parameter("bulk_velocity"): - bv = data.get_field_parameter("bulk_velocity") - else: bv = na.zeros(3, dtype='float64') - xv = data["x-velocity"] - bv[0] - yv = data["y-velocity"] - bv[1] - zv = data["z-velocity"] - bv[2] - return xv, yv, zv - -def obtain_rvec(data): - center = data.get_field_parameter('center') - coords = na.array([data['x'],data['y'],data['z']], dtype='float64') - new_shape = tuple([3] + [1]*(len(coords.shape)-1)) - r_vec = coords - na.reshape(center,new_shape) - return r_vec # axis 0 is the x,y,z - -def _SpecificAngularMomentum(field, data): - """ - Calculate the angular velocity. Returns a vector for each cell. - """ - r_vec = obtain_rvec(data) - xv, yv, zv = obtain_velocities(data) - v_vec = na.array([xv,yv,zv], dtype='float64') - return na.cross(r_vec, v_vec, axis=0) -def _convertSpecificAngularMomentum(data): - return data.convert("cm") -add_field("SpecificAngularMomentum", - function=_SpecificAngularMomentum, - convert_function=_convertSpecificAngularMomentum, vector_field=True, - units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter('center')]) -def _convertSpecificAngularMomentumKMSMPC(data): - return data.convert("mpc")/1e5 - -def _SpecificAngularMomentumX(field, data): - xv, yv, zv = obtain_velocities(data) - rv = obtain_rvec(data) - return yv*rv[2,:] - zv*rv[1,:] -def _SpecificAngularMomentumY(field, data): - xv, yv, zv = obtain_velocities(data) - rv = obtain_rvec(data) - return -(xv*rv[2,:] - zv*rv[0,:]) -def _SpecificAngularMomentumZ(field, data): - xv, yv, zv = obtain_velocities(data) - rv = obtain_rvec(data) - return xv*rv[1,:] - yv*rv[0,:] -for ax in 'XYZ': - n = "SpecificAngularMomentum%s" % ax - add_field(n, function=eval("_%s" % n), - convert_function=_convertSpecificAngularMomentum, - units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter("center")]) - -add_field("SpecificAngularMomentumKMSMPC", - function=_SpecificAngularMomentum, - convert_function=_convertSpecificAngularMomentumKMSMPC, vector_field=True, - units=r"\rm{km}\rm{Mpc}/\rm{s}", validators=[ValidateParameter('center')]) -def _AngularMomentum(field, data): - return data["CellMass"] * data["SpecificAngularMomentum"] -add_field("AngularMomentum", function=_AngularMomentum, - units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, - validators=[ValidateParameter('center')]) -def _AngularMomentumMSUNKMSMPC(field, data): - return data["CellMassMsun"] * data["SpecificAngularMomentumKMSMPC"] -add_field("AngularMomentumMSUNKMSMPC", function=_AngularMomentum, - units=r"M_{\odot}\rm{km}\rm{Mpc}/\rm{s}", vector_field=True, - validators=[ValidateParameter('center')]) - -def _AngularMomentumX(field, data): - return data["CellMass"] * data["SpecificAngularMomentumX"] -add_field("AngularMomentumX", function=_AngularMomentumX, - units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, - validators=[ValidateParameter('center')]) -def _AngularMomentumY(field, data): - return data["CellMass"] * data["SpecificAngularMomentumY"] -add_field("AngularMomentumY", function=_AngularMomentumY, - units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, - validators=[ValidateParameter('center')]) -def _AngularMomentumZ(field, data): - return data["CellMass"] * data["SpecificAngularMomentumZ"] -add_field("AngularMomentumZ", function=_AngularMomentumZ, - units=r"\rm{g}\/\rm{cm}^2/\rm{s}", vector_field=True, - validators=[ValidateParameter('center')]) - -def _ParticleSpecificAngularMomentum(field, data): - """ - Calculate the angular of a particle velocity. Returns a vector for each - particle. - """ - if data.has_field_parameter("bulk_velocity"): - bv = data.get_field_parameter("bulk_velocity") - else: bv = na.zeros(3, dtype='float64') - xv = data["particle_velocity_x"] - bv[0] - yv = data["particle_velocity_y"] - bv[1] - zv = data["particle_velocity_z"] - bv[2] - center = data.get_field_parameter('center') - coords = na.array([data['particle_position_x'], - data['particle_position_y'], - data['particle_position_z']], dtype='float64') - new_shape = tuple([3] + [1]*(len(coords.shape)-1)) - r_vec = coords - na.reshape(center,new_shape) - v_vec = na.array([xv,yv,zv], dtype='float64') - return na.cross(r_vec, v_vec, axis=0) -add_field("ParticleSpecificAngularMomentum", - function=_ParticleSpecificAngularMomentum, particle_type=True, - convert_function=_convertSpecificAngularMomentum, vector_field=True, - units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter('center')]) -def _convertSpecificAngularMomentumKMSMPC(data): - return data.convert("mpc")/1e5 -add_field("ParticleSpecificAngularMomentumKMSMPC", - function=_ParticleSpecificAngularMomentum, particle_type=True, - convert_function=_convertSpecificAngularMomentumKMSMPC, vector_field=True, - units=r"\rm{km}\rm{Mpc}/\rm{s}", validators=[ValidateParameter('center')]) -def _ParticleAngularMomentum(field, data): - return data["ParticleMass"] * data["ParticleSpecificAngularMomentum"] -add_field("ParticleAngularMomentum", - function=_ParticleAngularMomentum, units=r"\rm{g}\/\rm{cm}^2/\rm{s}", - particle_type=True, validators=[ValidateParameter('center')]) -def _ParticleAngularMomentumMSUNKMSMPC(field, data): - return data["ParticleMass"] * data["ParticleSpecificAngularMomentumKMSMPC"] -add_field("ParticleAngularMomentumMSUNKMSMPC", - function=_ParticleAngularMomentumMSUNKMSMPC, - units=r"M_{\odot}\rm{km}\rm{Mpc}/\rm{s}", - particle_type=True, validators=[ValidateParameter('center')]) - -def _ParticleRadius(field, data): - center = data.get_field_parameter("center") - DW = data.pf["DomainRightEdge"] - data.pf["DomainLeftEdge"] - radius = na.zeros(data["particle_position_x"].shape, dtype='float64') - for i, ax in enumerate('xyz'): - r = na.abs(data["particle_position_%s" % ax] - center[i]) - radius += na.minimum(r, na.abs(DW[i]-r))**2.0 - na.sqrt(radius, radius) - return radius -def _Radius(field, data): - center = data.get_field_parameter("center") - DW = data.pf["DomainRightEdge"] - data.pf["DomainLeftEdge"] - radius = na.zeros(data["x"].shape, dtype='float64') - for i, ax in enumerate('xyz'): - r = na.abs(data[ax] - center[i]) - radius += na.minimum(r, na.abs(DW[i]-r))**2.0 - na.sqrt(radius, radius) - return radius -def _ConvertRadiusCGS(data): - return data.convert("cm") -add_field("ParticleRadius", function=_ParticleRadius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiusCGS, units=r"\rm{cm}", - particle_type = True, - display_name = "Particle Radius") -add_field("Radius", function=_Radius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiusCGS, units=r"\rm{cm}") - -def _ConvertRadiusMpc(data): - return data.convert("mpc") -add_field("RadiusMpc", function=_Radius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiusMpc, units=r"\rm{Mpc}", - display_name = "Radius") -add_field("ParticleRadiusMpc", function=_ParticleRadius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiusMpc, units=r"\rm{Mpc}", - particle_type=True, - display_name = "Particle Radius") - -def _ConvertRadiuskpc(data): - return data.convert("kpc") -add_field("ParticleRadiuskpc", function=_ParticleRadius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}", - particle_type=True, - display_name = "Particle Radius") -add_field("Radiuskpc", function=_Radius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}", - display_name = "Radius") - -def _ConvertRadiuskpch(data): - return data.convert("kpch") -add_field("ParticleRadiuskpch", function=_ParticleRadius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}/\rm{h}", - particle_type=True, - display_name = "Particle Radius") -add_field("Radiuskpch", function=_Radius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}/\rm{h}", - display_name = "Radius") - -def _ConvertRadiuspc(data): - return data.convert("pc") -add_field("ParticleRadiuspc", function=_ParticleRadius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiuspc, units=r"\rm{pc}", - particle_type=True, - display_name = "Particle Radius") -add_field("Radiuspc", function=_Radius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiuspc, units=r"\rm{pc}", - display_name="Radius") - -def _ConvertRadiusAU(data): - return data.convert("au") -add_field("ParticleRadiusAU", function=_ParticleRadius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiusAU, units=r"\rm{AU}", - particle_type=True, - display_name = "Particle Radius") -add_field("RadiusAU", function=_Radius, - validators=[ValidateParameter("center")], - convert_function = _ConvertRadiusAU, units=r"\rm{AU}", - display_name = "Radius") - -add_field("ParticleRadiusCode", function=_ParticleRadius, - validators=[ValidateParameter("center")], - particle_type=True, - display_name = "Particle Radius (code)") -add_field("RadiusCode", function=_Radius, - validators=[ValidateParameter("center")], - display_name = "Radius (code)") - -def _RadialVelocity(field, data): - center = data.get_field_parameter("center") - bulk_velocity = data.get_field_parameter("bulk_velocity") - if bulk_velocity == None: - bulk_velocity = na.zeros(3) - new_field = ( (data['x']-center[0])*(data["x-velocity"]-bulk_velocity[0]) - + (data['y']-center[1])*(data["y-velocity"]-bulk_velocity[1]) - + (data['z']-center[2])*(data["z-velocity"]-bulk_velocity[2]) - )/data["RadiusCode"] - if na.any(na.isnan(new_field)): # to fix center = point - new_field[na.isnan(new_field)] = 0.0 - return new_field -def _RadialVelocityABS(field, data): - return na.abs(_RadialVelocity(field, data)) -def _ConvertRadialVelocityKMS(data): - return 1e-5 -add_field("RadialVelocity", function=_RadialVelocity, - units=r"\rm{cm}/\rm{s}", - validators=[ValidateParameter("center")]) -add_field("RadialVelocityABS", function=_RadialVelocityABS, - units=r"\rm{cm}/\rm{s}", - validators=[ValidateParameter("center")]) -add_field("RadialVelocityKMS", function=_RadialVelocity, - convert_function=_ConvertRadialVelocityKMS, units=r"\rm{km}/\rm{s}", - validators=[ValidateParameter("center")]) -add_field("RadialVelocityKMSABS", function=_RadialVelocityABS, - convert_function=_ConvertRadialVelocityKMS, units=r"\rm{km}/\rm{s}", - validators=[ValidateParameter("center")]) - -def _CuttingPlaneVelocityX(field, data): - x_vec, y_vec, z_vec = [data.get_field_parameter("cp_%s_vec" % (ax)) - for ax in 'xyz'] - bulk_velocity = data.get_field_parameter("bulk_velocity") - if bulk_velocity == None: - bulk_velocity = na.zeros(3) - v_vec = na.array([data["%s-velocity" % ax] for ax in 'xyz']) \ - - bulk_velocity[...,na.newaxis] - return na.dot(x_vec, v_vec) -add_field("CuttingPlaneVelocityX", - function=_CuttingPlaneVelocityX, - validators=[ValidateParameter("cp_%s_vec" % ax) - for ax in 'xyz'], units=r"\rm{km}/\rm{s}") -def _CuttingPlaneVelocityY(field, data): - x_vec, y_vec, z_vec = [data.get_field_parameter("cp_%s_vec" % (ax)) - for ax in 'xyz'] - bulk_velocity = data.get_field_parameter("bulk_velocity") - if bulk_velocity == None: - bulk_velocity = na.zeros(3) - v_vec = na.array([data["%s-velocity" % ax] for ax in 'xyz']) \ - - bulk_velocity[...,na.newaxis] - return na.dot(y_vec, v_vec) -add_field("CuttingPlaneVelocityY", - function=_CuttingPlaneVelocityY, - validators=[ValidateParameter("cp_%s_vec" % ax) - for ax in 'xyz'], units=r"\rm{km}/\rm{s}") - -def _MeanMolecularWeight(field,data): - return (data["Density"] / (mh *data["NumberDensity"])) -add_field("MeanMolecularWeight",function=_MeanMolecularWeight,units=r"") - -def _JeansMassMsun(field,data): - MJ_constant = (((5*kboltz)/(G*mh))**(1.5)) * \ - (3/(4*3.1415926535897931))**(0.5) / 1.989e33 - - return (MJ_constant * - ((data["Temperature"]/data["MeanMolecularWeight"])**(1.5)) * - (data["Density"]**(-0.5))) -add_field("JeansMassMsun",function=_JeansMassMsun, - units=r"\rm{M_{\odot}}") - -def _convertDensity(data): - return data.convert("Density") -def _pdensity_pyx(field, data): - blank = na.zeros(data.ActiveDimensions, dtype='float32') - if data.NumberOfParticles == 0: return blank - CICDeposit_3(data["particle_position_x"].astype(na.float64), - data["particle_position_y"].astype(na.float64), - data["particle_position_z"].astype(na.float64), - data["particle_mass"].astype(na.float32), - na.int64(data.NumberOfParticles), - blank, na.array(data.LeftEdge).astype(na.float64), - na.array(data.ActiveDimensions).astype(na.int32), - na.float64(data['dx'])) - return blank -add_field("particle_density_pyx", function=_pdensity_pyx, - validators=[ValidateSpatial(0)], convert_function=_convertDensity, - display_name=r"\mathrm{Particle}\/\mathrm{Density})") - -def _MagneticEnergy(field,data): - """WARNING WARNING WARNING: Units are not yet known to be - correct. Trust the magnitude of this quantity at your own - risk. However, it should just be a multiplicative offset from - reality... - """ - return (data["Bx"]**2 + data["By"]**2 + data["Bz"]**2)/2. -add_field("MagneticEnergy",function=_MagneticEnergy, - units=r"") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/__init__.py --- a/yt/lagos/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -""" -Lagos -===== - -Lagos defines a set of class structures for Enzo data handling. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.config import ytcfg -from yt.logger import lagosLogger as mylog - -try: - from pyhdf_np import SD # NumPy - import pyhdf_np.error # NumPy -except: - mylog.debug("No HDF4 support") - -import warnings -try: - import h5py - if not hasattr(h5py.h5, "ArgsError"): - h5py.h5.ArgsError = h5py.h5.H5Error -except ImportError: - ytcfg["lagos", "serialize"] = "False" - mylog.warning("No h5py. Data serialization disabled.") - -from yt.arraytypes import * -import weakref -from new import classobj -from string import strip, rstrip -from math import ceil, floor, log10, pi -import os, os.path, types, exceptions, re -from stat import ST_CTIME -import shelve - -import time - -import yt.amr_utils as amr_utils - -from Cosmology import * -from EnzoCosmology import * - -# Now we import all the subfiles - -from HelperFunctions import * -import PointCombine -import HDF5LightReader -from EnzoDefs import * -from OrionDefs import * - -from ParallelTools import * -# Now our fields -#from DerivedFields import * -from field_info_container import * -from UniversalFields import * -from EnzoFields import * -from OrionFields import * -from ChomboFields import * -from FLASHFields import * -from RAMSESFields import * -from GadgetFields import * -fieldInfo = EnzoFieldInfo - -# NOT the same as fieldInfo.add_field -# We by-default add universal fields. -add_field = FieldInfo.add_field - -from yt.fido import ParameterFileStore, output_type_registry - -from DerivedQuantities import DerivedQuantityCollection, GridChildMaskWrapper -from DataReadingFuncs import * -from ClusterFiles import * -from ContourFinder import * -from clump_handling import * -from ParticleIO import * -from BaseDataTypes import * -from BaseGridType import * -from EnzoRateData import * -from object_finding_mixin import * -from HierarchyType import * -from OutputTypes import * -from Profiles import * - -from HaloFinding import * - -from two_point_functions import * - -# We load plugins. Keep in mind, this can be fairly dangerous - -# the primary purpose is to allow people to have a set of functions -# that get used every time that they don't have to *define* every time. -# This way, other command-line tools can be used very simply. -# Unfortunately, for now, I think the easiest and simplest way of doing -# this is also the most dangerous way. -if ytcfg.getboolean("lagos","loadfieldplugins"): - my_plugin_name = ytcfg.get("lagos","pluginfilename") - # We assume that it is with respect to the $HOME/.yt directory - fn = os.path.expanduser("~/.yt/%s" % my_plugin_name) - if os.path.isfile(fn): - mylog.info("Loading plugins from %s", fn) - execfile(fn) - -log_fields = [] # @todo: GET RID OF THIS diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/clump_handling.py --- a/yt/lagos/clump_handling.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,290 +0,0 @@ -""" -Clump finding helper classes - -Author: Britton Smith -Affiliation: University of Colorado at Boulder -License: - Copyright (C) 2008-2009 Britton Smith. 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 . -""" - -from yt.lagos import * -import numpy as na -import copy - -class Clump(object): - children = None - def __init__(self, data, parent, field, cached_fields = None, function=None, clump_info=None): - self.parent = parent - self.data = data - self.field = field - self.min_val = self.data[field].min() - self.max_val = self.data[field].max() - self.cached_fields = cached_fields - - # List containing characteristics about clumps that are to be written - # out by the write routines. - if clump_info is None: - self.set_default_clump_info() - else: - # Clump info will act the same if add_info_item is called before or after clump finding. - self.clump_info = copy.deepcopy(clump_info) - - # Function determining whether a clump is valid and should be kept. - self.default_function = 'self.data.quantities["IsBound"](truncate=True,include_thermal_energy=True) > 1.0' - if function is None: - self.function = self.default_function - else: - self.function = function - - # Return value of validity function, saved so it does not have to be calculated again. - self.function_value = None - - def add_info_item(self,quantity,format): - "Adds an entry to clump_info list and tells children to do the same." - - self.clump_info.append({'quantity':quantity, 'format':format}) - if self.children is None: return - for child in self.children: - child.add_info_item(quantity,format) - - def set_default_clump_info(self): - "Defines default entries in the clump_info array." - - # add_info_item is recursive so this function does not need to be. - self.clump_info = [] - - # Number of cells. - self.add_info_item('self.data["CellMassMsun"].size','"Cells: %d" % value') - # Gas mass in solar masses. - self.add_info_item('self.data["CellMassMsun"].sum()','"Mass: %e Msolar" % value') - # Volume-weighted Jeans mass. - self.add_info_item('self.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellVolume")', - '"Jeans Mass (vol-weighted): %.6e Msolar" % value') - # Mass-weighted Jeans mass. - self.add_info_item('self.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellMassMsun")', - '"Jeans Mass (mass-weighted): %.6e Msolar" % value') - # Max level. - self.add_info_item('self.data["GridLevel"].max()','"Max grid level: %d" % value') - # Minimum number density. - self.add_info_item('self.data["NumberDensity"].min()','"Min number density: %.6e cm^-3" % value') - # Maximum number density. - self.add_info_item('self.data["NumberDensity"].max()','"Max number density: %.6e cm^-3" % value') - - def clear_clump_info(self): - "Clears the clump_info array and passes the instruction to its children." - - self.clump_info = [] - if self.children is None: return - for child in self.children: - child.clear_clump_info() - - def write_info(self,level,f_ptr): - "Writes information for clump using the list of items in clump_info." - - for item in self.clump_info: - # Call if callable, otherwise do an eval. - if callable(item['quantity']): - value = item['quantity']() - else: - value = eval(item['quantity']) - output = eval(item['format']) - f_ptr.write("%s%s" % ('\t'*level,output)) - f_ptr.write("\n") - - def find_children(self, min_val, max_val = None): - if self.children is not None: - print "Wiping out existing children clumps." - self.children = [] - if max_val is None: max_val = self.max_val - contour_info = identify_contours(self.data, self.field, min_val, max_val, - self.cached_fields) - for cid in contour_info: - new_clump = self.data.extract_region(contour_info[cid]) - self.children.append(Clump(new_clump, self, self.field, - self.cached_fields,function=self.function, - clump_info=self.clump_info)) - - def pass_down(self,operation): - "Performs an operation on a clump with an exec and passes the instruction down to clump children." - - # Call if callable, otherwise do an exec. - if callable(operation): - operation() - else: - exec(operation) - - for child in self.children: - child.pass_down(operation) - - def _isValid(self): - "Perform user specified function to determine if child clumps should be kept." - - # Only call function if it has not been already. - if self.function_value is None: - self.function_value = eval(self.function) - - return self.function_value - - def __reduce__(self): - return (_reconstruct_clump, - (self.parent, self.field, self.min_val, self.max_val, - self.function_value, self.children, self.data, self.clump_info, self.function)) - - def __getitem__(self,request): - return self.data[request] - -def _reconstruct_clump(parent, field, mi, ma, function_value, children, data, clump_info, - function=None): - obj = object.__new__(Clump) - if iterable(parent): parent = parent[1] - if children is None: children = [] - obj.parent, obj.field, obj.min_val, obj.max_val, obj.function_value, obj.children, obj.clump_info, obj.function = \ - parent, field, mi, ma, function_value, children, clump_info, function - # Now we override, because the parent/child relationship seems a bit - # unreliable in the unpickling - for child in children: child.parent = obj - obj.data = data[1] # Strip out the PF - if obj.parent is None: return (data[0], obj) - return obj - -def find_clumps(clump, min_val, max_val, d_clump): - print "Finding clumps: min: %e, max: %e, step: %f" % (min_val, max_val, d_clump) - if min_val >= max_val: return - clump.find_children(min_val) - - if (len(clump.children) == 1): - find_clumps(clump, min_val*d_clump, max_val, d_clump) - - elif (len(clump.children) > 0): - these_children = [] - print "Investigating %d children." % len(clump.children) - for child in clump.children: - find_clumps(child, min_val*d_clump, max_val, d_clump) - if ((child.children is not None) and (len(child.children) > 0)): - these_children.append(child) - elif (child._isValid()): - these_children.append(child) - else: - print "Eliminating invalid, childless clump with %d cells." % len(child.data["CellMassMsun"]) - if (len(these_children) > 1): - print "%d of %d children survived." % (len(these_children),len(clump.children)) - clump.children = these_children - elif (len(these_children) == 1): - print "%d of %d children survived, linking its children to parent." % (len(these_children),len(clump.children)) - clump.children = these_children[0].children - else: - print "%d of %d children survived, erasing children." % (len(these_children),len(clump.children)) - clump.children = [] - -def get_lowest_clumps(clump, clump_list=None): - "Return a list of all clumps at the bottom of the hierarchy." - - if clump_list is None: clump_list = [] - if clump.children is None or len(clump.children) == 0: - clump_list.append(clump) - if clump.children is not None and len(clump.children) > 0: - for child in clump.children: - get_lowest_clumps(child, clump_list=clump_list) - - return clump_list - -def write_clump_hierarchy(clump,level,f_ptr): - for q in range(level): - f_ptr.write("\t") - f_ptr.write("Clump at level %d:\n" % level) - clump.write_info(level,f_ptr) - f_ptr.write("\n") - f_ptr.flush() - if ((clump.children is not None) and (len(clump.children) > 0)): - for child in clump.children: - write_clump_hierarchy(child,(level+1),f_ptr) - -def write_clumps(clump,level,f_ptr): - if ((clump.children is None) or (len(clump.children) == 0)): - f_ptr.write("%sClump:\n" % ("\t"*level)) - clump.write_info(level,f_ptr) - f_ptr.write("\n") - f_ptr.flush() - if ((clump.children is not None) and (len(clump.children) > 0)): - for child in clump.children: - write_clumps(child,0,f_ptr) - -# Old clump info writing routines. -def write_old_clump_hierarchy(clump,level,f_ptr): - for q in range(level): - f_ptr.write("\t") - f_ptr.write("Clump at level %d:\n" % level) - clump.write_info(level,f_ptr) - write_old_clump_info(clump,level,f_ptr) - f_ptr.write("\n") - f_ptr.flush() - if ((clump.children is not None) and (len(clump.children) > 0)): - for child in clump.children: - write_clump_hierarchy(child,(level+1),f_ptr) - -def write_old_clumps(clump,level,f_ptr): - if ((clump.children is None) or (len(clump.children) == 0)): - f_ptr.write("%sClump:\n" % ("\t"*level)) - write_old_clump_info(clump,level,f_ptr) - f_ptr.write("\n") - f_ptr.flush() - if ((clump.children is not None) and (len(clump.children) > 0)): - for child in clump.children: - write_clumps(child,0,f_ptr) - -__clump_info_template = \ -""" -%(tl)sCells: %(num_cells)s -%(tl)sMass: %(total_mass).6e Msolar -%(tl)sJeans Mass (vol-weighted): %(jeans_mass_vol).6e Msolar -%(tl)sJeans Mass (mass-weighted): %(jeans_mass_mass).6e Msolar -%(tl)sMax grid level: %(max_level)s -%(tl)sMin number density: %(min_density).6e cm^-3 -%(tl)sMax number density: %(max_density).6e cm^-3 - -""" - -def write_old_clump_info(clump,level,f_ptr): - fmt_dict = {'tl': "\t" * level} - fmt_dict['num_cells'] = clump.data["CellMassMsun"].size, - fmt_dict['total_mass'] = clump.data["CellMassMsun"].sum() - fmt_dict['jeans_mass_vol'] = clump.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellVolume") - fmt_dict['jeans_mass_mass'] = clump.data.quantities["WeightedAverageQuantity"]("JeansMassMsun","CellMassMsun") - fmt_dict['max_level'] = clump.data["GridLevel"].max() - fmt_dict['min_density'] = clump.data["NumberDensity"].min() - fmt_dict['max_density'] = clump.data["NumberDensity"].max() - f_ptr.write(__clump_info_template % fmt_dict) - -# Recipes for various clump calculations. -recipes = {} - -# Distance from clump center of mass to center of mass of top level object. -def _DistanceToMainClump(master,units='pc'): - masterCOM = master.data.quantities['CenterOfMass']() - pass_command = "self.masterCOM = [%.10f, %.10f, %.10f]" % (masterCOM[0], - masterCOM[1], - masterCOM[2]) - master.pass_down(pass_command) - master.pass_down("self.com = self.data.quantities['CenterOfMass']()") - - quantity = "((self.com[0]-self.masterCOM[0])**2 + (self.com[1]-self.masterCOM[1])**2 + (self.com[2]-self.masterCOM[2])**2)**(0.5)*self.data.pf.units['%s']" % units - format = "%s%s%s" % ("'Distance from center: %.6e ",units,"' % value") - - master.add_info_item(quantity,format) - -recipes['DistanceToMainClump'] = _DistanceToMainClump diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/enzo_routines/cic_deposit.f --- a/yt/lagos/enzo_routines/cic_deposit.f Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -c======================================================================= -c////////////////////// SUBROUTINE CIC_DEPOSIT \\\\\\\\\\\\\\\\\\\\\\\ -c - subroutine cic_deposit(posx, posy, posz, ndim, npositions, - & mass, field, leftedge, - & dim1, dim2, dim3, cellsize) -c -c PERFORMS 1/2/3D CLOUD-IN-CELL INTERPOLATION FROM FIELD TO SUMFIELD -c -c written by: Greg Bryan -c date: January, 1998 -c modified1: -c -c PURPOSE: This routine performs a three-dimension, second-order -c interpolation from field to sumfield (without clearing sumfield -c first) at the positions specified. -c -c INPUTS: -c ndim - dimensionality -c cellsize - the cell size of field -c dim1,2,3 - real dimensions of field -c leftedge - the left edge(s) of field -c npositions - number of particles -c posx,y,z - particle positions -c sumfield - 1D field (length npositions) of masses -c -c OUTPUT ARGUMENTS: -c field - field to be deposited to -c -c EXTERNALS: -c -c LOCALS: -c -c----------------------------------------------------------------------- -c - implicit NONE -c -c----------------------------------------------------------------------- -c -c argument declarations -c - integer dim1, dim2, dim3, npositions, ndim - real*8 posx(npositions), posy(npositions), posz(npositions), - & leftedge(3) - real mass(npositions), field(dim1, dim2, dim3), cellsize -CF2PY INTENT(INOUT) :: field(dim1, dim2, dim3) -CF2PY INTENT(HIDE),DEPEND(field) :: dim1=shape(field,0) -CF2PY INTENT(HIDE),DEPEND(field) :: dim2=shape(field,1) -CF2PY INTENT(HIDE),DEPEND(field) :: dim3=shape(field,2) -CF@PY INTENT(HIDE),DEPEND(posx) :: nposition=len(posx) -CF2PY INTENT(IN) :: posx(nposition), posy(nposition), posz(npositions) -CF2PY INTENT(IN) :: mass(npositions), cellsize, leftedge(3) -CF2PY INTENT(IN) :: ndim -c -c locals -c - integer iii, jjj, kkk - integer i1, j1, k1, n - real xpos, ypos, zpos, dx, dy, dz, fact - real*8 edge1, edge2, edge3, half - parameter (half = 0.5001) -c -c\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////////// -c======================================================================= -c - -! write(0,*) npositions, leftedge, dim1, dim2, dim3, cellsize - - fact = 1.0/cellsize - edge1 = real(dim1) - half - edge2 = real(dim2) - half - edge3 = real(dim3) - half -c -c 1D -c - if (ndim .eq. 1) then -c - do n=1, npositions -c -c Compute the position of the central cell -c - xpos = min(max((posx(n) - leftedge(1))*fact, half), edge1) -c -c Convert this into an integer index -c - i1 = int(xpos + 0.5) -c -c Compute the weights -c - dx = real(i1) + 0.5 - xpos -c -c Interpolate from field into sumfield -c - field(i1 ,1,1) = field(i1 ,1,1) + mass(n)*dx - field(i1+1,1,1) = field(i1+1,1,1) + mass(n)*(1.0-dx) -c - enddo -c - endif -c -c 2D -c - if (ndim .eq. 2) then -c - do n=1, npositions -c -c Compute the position of the central cell -c - xpos = min(max((posx(n) - leftedge(1))*fact, half), edge1) - ypos = min(max((posy(n) - leftedge(2))*fact, half), edge2) -c -c Convert this into an integer index -c - i1 = int(xpos + 0.5) - j1 = int(ypos + 0.5) -c -c Compute the weights -c - dx = real(i1) + 0.5 - xpos - dy = real(j1) + 0.5 - ypos -c -c Interpolate from field into sumfield -c - field(i1 ,j1 ,1) = field(i1 ,j1 ,1) + - & mass(n)* dx * dy - field(i1+1,j1 ,1) = field(i1+1,j1 ,1) + - & mass(n)*(1.0-dx)* dy - field(i1 ,j1+1,1) = field(i1 ,j1+1,1) + - & mass(n)* dx *(1.0-dy) - field(i1+1,j1+1,1) = field(i1+1,j1+1,1) + - & mass(n)*(1.0-dx)*(1.0-dy) -c - enddo -c - endif -c -c 3D -c - if (ndim .eq. 3) then -c - do n=1, npositions -c -c Compute the position of the central cell -c - xpos = min(max((posx(n) - leftedge(1))*fact, half), edge1) - ypos = min(max((posy(n) - leftedge(2))*fact, half), edge2) - zpos = min(max((posz(n) - leftedge(3))*fact, half), edge3) -c -c Convert this into an integer index -c - i1 = int(xpos + 0.5) - j1 = int(ypos + 0.5) - k1 = int(zpos + 0.5) -c -c Compute the weights -c - dx = real(i1) + 0.5 - xpos - dy = real(j1) + 0.5 - ypos - dz = real(k1) + 0.5 - zpos -c -c Interpolate from field into sumfield -c - field(i1 ,j1 ,k1 ) = field(i1 ,j1 ,k1 ) + - & mass(n)* dx * dy * dz - field(i1+1,j1 ,k1 ) = field(i1+1,j1 ,k1 ) + - & mass(n)*(1.0-dx)* dy * dz - field(i1 ,j1+1,k1 ) = field(i1 ,j1+1,k1 ) + - & mass(n)* dx *(1.0-dy)* dz - field(i1+1,j1+1,k1 ) = field(i1+1,j1+1,k1 ) + - & mass(n)*(1.0-dx)*(1.0-dy)* dz - field(i1 ,j1 ,k1+1) = field(i1 ,j1 ,k1+1) + - & mass(n)* dx * dy *(1.0-dz) - field(i1+1,j1 ,k1+1) = field(i1+1,j1 ,k1+1) + - & mass(n)*(1.0-dx)* dy *(1.0-dz) - field(i1 ,j1+1,k1+1) = field(i1 ,j1+1,k1+1) + - & mass(n)* dx *(1.0-dy)*(1.0-dz) - field(i1+1,j1+1,k1+1) = field(i1+1,j1+1,k1+1) + - & mass(n)*(1.0-dx)*(1.0-dy)*(1.0-dz) -c - enddo - -! do kkk=1,dim3 -! write(0,'("K = ",i2)') kkk -! do jjj=1,dim2 -! write(0,'((14(1pe8.1)))')(field(iii,jjj,kkk),iii=1,dim1) -! end do -! end do - - endif - - return - end diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/enzo_routines/cic_deposit.pyf --- a/yt/lagos/enzo_routines/cic_deposit.pyf Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -! -*- f90 -*- -! Note: the context of this file is case sensitive. - -python module cic_deposit ! in - interface ! in :cic_deposit - subroutine cic_deposit(posx,posy,posz,ndim,npositions,mass,field,leftedge,dim1,dim2,dim3,cellsize) ! in :cic_deposit:cic_deposit.f - real*8 dimension(npositions),intent(in) :: posx - real*8 dimension(npositions),intent(in),depend(npositions) :: posy - real*8 dimension(npositions),intent(in),depend(npositions) :: posz - integer intent(in) :: ndim - integer optional,check(len(posx)>=npositions),depend(posx) :: npositions=len(posx) - real dimension(npositions),intent(in),depend(npositions) :: mass - real dimension(dim1,dim2,dim3),intent(inout) :: field - real*8 dimension(3),intent(in) :: leftedge - integer optional,intent(hide),check(shape(field,0)==dim1),depend(field) :: dim1=shape(field,0) - integer optional,intent(hide),check(shape(field,1)==dim2),depend(field) :: dim2=shape(field,1) - integer optional,intent(hide),check(shape(field,2)==dim3),depend(field) :: dim3=shape(field,2) - real intent(in) :: cellsize - end subroutine cic_deposit - end interface -end python module cic_deposit - -! This file was auto-generated with f2py (version:2_4422). -! See http://cens.ioc.ee/projects/f2py2e/ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/field_info_container.py --- a/yt/lagos/field_info_container.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,432 +0,0 @@ -""" -The basic field info container resides here. These classes, code specific and -universal, are the means by which we access fields across YT, both derived and -native. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -import types -import numpy as na -import inspect -import copy -import itertools - -from yt.funcs import * - -class FieldInfoContainer(object): # We are all Borg. - """ - This is a generic field container. It contains a list of potential derived - fields, all of which know how to act on a data object and return a value. This - object handles converting units as well as validating the availability of a - given field. - """ - _shared_state = {} - _universal_field_list = {} - def __new__(cls, *args, **kwargs): - self = object.__new__(cls, *args, **kwargs) - self.__dict__ = cls._shared_state - return self - def __getitem__(self, key): - if key in self._universal_field_list: - return self._universal_field_list[key] - raise KeyError - def keys(self): - """ - Return all the field names this object knows about. - """ - return self._universal_field_list.keys() - def __iter__(self): - return self._universal_field_list.iterkeys() - def __setitem__(self, key, val): - self._universal_field_list[key] = val - def has_key(self, key): - return key in self._universal_field_list - def add_field(self, name, function = None, **kwargs): - """ - Add a new field, along with supplemental metadata, to the list of - available fields. This respects a number of arguments, all of which - are passed on to the constructor for :class:`~yt.lagos.DerivedField`. - """ - if function == None: - if kwargs.has_key("function"): - function = kwargs.pop("function") - else: - # This will fail if it does not exist, - # which is our desired behavior - function = eval("_%s" % name) - self[name] = DerivedField(name, function, **kwargs) -FieldInfo = FieldInfoContainer() -add_field = FieldInfo.add_field - -def derived_field(**kwargs): - def inner_decorator(function): - if 'name' not in kwargs: - kwargs['name'] = function.func_name - kwargs['function'] = function - add_field(**kwargs) - return function - return inner_decorator - -class CodeFieldInfoContainer(FieldInfoContainer): - def __setitem__(self, key, val): - self._field_list[key] = val - def __iter__(self): - return itertools.chain(self._field_list.iterkeys(), - self._universal_field_list.iterkeys()) - def keys(self): - return set(self._field_list.keys() + self._universal_field_list.keys()) - def has_key(self, key): - return key in self._universal_field_list \ - or key in self._field_list - def __getitem__(self, key): - if key in self._field_list: - return self._field_list[key] - if key in self._universal_field_list: - return self._universal_field_list[key] - raise KeyError(key) - -class OrionFieldContainer(CodeFieldInfoContainer): - """ - All Orion-specific fields are stored in here. - """ - _shared_state = {} - _field_list = {} -OrionFieldInfo = OrionFieldContainer() -add_orion_field = OrionFieldInfo.add_field - -class GadgetFieldContainer(CodeFieldInfoContainer): - """ - This is a container for Gadget-specific fields. - """ - _shared_state = {} - _field_list = {} -GadgetFieldInfo = GadgetFieldContainer() -add_gadget_field = GadgetFieldInfo.add_field - -class TigerFieldContainer(CodeFieldInfoContainer): - """ - This is a container for Tiger-specific fields. - """ - _shared_state = {} - _field_list = {} -TigerFieldInfo = TigerFieldContainer() -add_tiger_field = TigerFieldInfo.add_field - -class ValidationException(Exception): - pass - -class NeedsGridType(ValidationException): - def __init__(self, ghost_zones = 0, fields=None): - self.ghost_zones = ghost_zones - self.fields = fields - def __str__(self): - return "(%s, %s)" % (self.ghost_zones, self.fields) - -class NeedsOriginalGrid(NeedsGridType): - def __init__(self): - self.ghost_zones = 0 - -class NeedsDataField(ValidationException): - def __init__(self, missing_fields): - self.missing_fields = missing_fields - def __str__(self): - return "(%s)" % (self.missing_fields) - -class NeedsProperty(ValidationException): - def __init__(self, missing_properties): - self.missing_properties = missing_properties - def __str__(self): - return "(%s)" % (self.missing_properties) - -class NeedsParameter(ValidationException): - def __init__(self, missing_parameters): - self.missing_parameters = missing_parameters - def __str__(self): - return "(%s)" % (self.missing_parameters) - -class FieldDetector(defaultdict): - Level = 1 - NumberOfParticles = 1 - _read_exception = None - def __init__(self, nd = 16, pf = None): - self.nd = nd - self.ActiveDimensions = [nd,nd,nd] - self.LeftEdge = [0.0,0.0,0.0] - self.RightEdge = [1.0,1.0,1.0] - self['dx'] = self['dy'] = self['dz'] = na.array([1.0]) - if pf is None: - pf = defaultdict(lambda: 1) - self.pf = pf - class fake_hierarchy(object): - class fake_io(object): - def _read_data_set(io_self, data, field): - return self._read_data(field) - _read_exception = RuntimeError - io = fake_io() - def get_smallest_dx(self): - return 1.0 - self.hierarchy = fake_hierarchy() - self.requested = [] - self.requested_parameters = [] - defaultdict.__init__(self, lambda: na.ones((nd,nd,nd))) - def __missing__(self, item): - if FieldInfo.has_key(item) and \ - FieldInfo[item]._function.func_name != '': - try: - vv = FieldInfo[item](self) - except NeedsGridType, exc: - ngz = exc.ghost_zones - nfd = FieldDetector(self.nd+ngz*2) - vv = FieldInfo[item](nfd)[ngz:-ngz,ngz:-ngz,ngz:-ngz] - for i in vv.requested: - if i not in self.requested: self.requested.append(i) - for i in vv.requested_parameters: - if i not in self.requested_parameters: self.requested_parameters.append(i) - if vv is not None: - self[item] = vv - return self[item] - self.requested.append(item) - return defaultdict.__missing__(self, item) - - def _read_data(self, field_name): - self.requested.append(field_name) - if FieldInfo.has_key(field_name) and \ - FieldInfo[field_name].particle_type: - self.requested.append(field_name) - return na.ones(self.NumberOfParticles) - return defaultdict.__missing__(self, field_name) - - def get_field_parameter(self, param): - self.requested_parameters.append(param) - if param in ['bulk_velocity','center','height_vector']: - return na.array([0,0,0]) - else: - return 0.0 - _spatial = True - _num_ghost_zones = 0 - id = 1 - def has_field_parameter(self, param): return True - def convert(self, item): return 1 - -class DerivedField(object): - def __init__(self, name, function, - convert_function = None, - particle_convert_function = None, - units = "", projected_units = "", - take_log = True, validators = None, - particle_type = False, vector_field=False, - display_field = True, not_in_all=False, - display_name = None, projection_conversion = "cm"): - """ - This is the base class used to describe a cell-by-cell derived field. - - :param name: is the name of the field. - :param function: is a function handle that defines the field - :param convert_function: must convert to CGS, if it needs to be done - :param units: is a mathtext-formatted string that describes the field - :param projected_units: if we display a projection, what should the units be? - :param take_log: describes whether the field should be logged - :param validators: is a list of :class:`FieldValidator` objects - :param particle_type: is this field based on particles? - :param vector_field: describes the dimensionality of the field - :param display_field: governs its appearance in the dropdowns in reason - :param not_in_all: is used for baryon fields from the data that are not in - all the grids - :param display_name: a name used in the plots - :param projection_conversion: which unit should we multiply by in a - projection? - """ - self.name = name - self._function = function - if validators: - self.validators = ensure_list(validators) - else: - self.validators = [] - self.take_log = take_log - self._units = units - self._projected_units = projected_units - if not convert_function: - convert_function = lambda a: 1.0 - self._convert_function = convert_function - self._particle_convert_function = particle_convert_function - self.particle_type = particle_type - self.vector_field = vector_field - self.projection_conversion = projection_conversion - self.display_field = display_field - self.display_name = display_name - self.not_in_all = not_in_all - - def check_available(self, data): - """ - This raises an exception of the appropriate type if the set of - validation mechanisms are not met, and otherwise returns True. - """ - for validator in self.validators: - validator(data) - # If we don't get an exception, we're good to go - return True - - def get_dependencies(self, *args, **kwargs): - """ - This returns a list of names of fields that this field depends on. - """ - e = FieldDetector(*args, **kwargs) - if self._function.func_name == '': - e.requested.append(self.name) - else: - self(e) - return e - - def get_units(self): - """ - Return a string describing the units. - """ - return self._units - - def get_projected_units(self): - """ - Return a string describing the units if the field has been projected. - """ - return self._projected_units - - def __call__(self, data): - """ - Return the value of the field in a given *data* object. - """ - ii = self.check_available(data) - original_fields = data.keys() # Copy - dd = self._function(self, data) - dd *= self._convert_function(data) - for field_name in data.keys(): - if field_name not in original_fields: - del data[field_name] - return dd - - def get_source(self): - """ - Return a string containing the source of the function (if possible.) - """ - return inspect.getsource(self._function) - - def get_label(self, projected=False): - """ - Return a data label for the given field, inluding units. - """ - name = self.name - if self.display_name is not None: name = self.display_name - data_label = r"$\rm{%s}" % name - if projected: units = self.get_projected_units() - else: units = self.get_units() - if units != "": data_label += r"\/\/ (%s)" % (units) - data_label += r"$" - return data_label - - def particle_convert(self, data): - if self._particle_convert_function is not None: - return self._particle_convert_function(data) - return None - -class FieldValidator(object): - pass - -class ValidateParameter(FieldValidator): - def __init__(self, parameters): - """ - This validator ensures that the parameter file has a given parameter. - """ - FieldValidator.__init__(self) - self.parameters = ensure_list(parameters) - def __call__(self, data): - doesnt_have = [] - for p in self.parameters: - if not data.has_field_parameter(p): - doesnt_have.append(p) - if len(doesnt_have) > 0: - raise NeedsParameter(doesnt_have) - return True - -class ValidateDataField(FieldValidator): - def __init__(self, field): - """ - This validator ensures that the output file has a given data field stored - in it. - """ - FieldValidator.__init__(self) - self.fields = ensure_list(field) - def __call__(self, data): - doesnt_have = [] - if isinstance(data, FieldDetector): return True - for f in self.fields: - if f not in data.hierarchy.field_list: - doesnt_have.append(f) - if len(doesnt_have) > 0: - raise NeedsDataField(doesnt_have) - return True - -class ValidateProperty(FieldValidator): - def __init__(self, prop): - """ - This validator ensures that the data object has a given python attribute. - """ - FieldValidator.__init__(self) - self.prop = ensure_list(prop) - def __call__(self, data): - doesnt_have = [] - for p in self.prop: - if not hasattr(data,p): - doesnt_have.append(p) - if len(doesnt_have) > 0: - raise NeedsProperty(doesnt_have) - return True - -class ValidateSpatial(FieldValidator): - def __init__(self, ghost_zones = 0, fields=None): - """ - This validator ensures that the data handed to the field is of spatial - nature -- that is to say, 3-D. - """ - FieldValidator.__init__(self) - self.ghost_zones = ghost_zones - self.fields = fields - def __call__(self, data): - # When we say spatial information, we really mean - # that it has a three-dimensional data structure - if isinstance(data, FieldDetector): return True - if not data._spatial: - raise NeedsGridType(self.ghost_zones,self.fields) - if self.ghost_zones <= data._num_ghost_zones: - return True - raise NeedsGridType(self.ghost_zones,self.fields) - -class ValidateGridType(FieldValidator): - def __init__(self): - """ - This validator ensures that the data handed to the field is an actual - grid patch, not a covering grid of any kind. - """ - FieldValidator.__init__(self) - def __call__(self, data): - # We need to make sure that it's an actual AMR grid - if isinstance(data, FieldDetector): return True - if data._type_name == 'grid': return True - raise NeedsOriginalGrid() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/EnzoFOF.c --- a/yt/lagos/fof/EnzoFOF.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -/************************************************************************ -* Copyright (C) 2008-2009 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 . -* -************************************************************************/ - -// -// EnzoFOF -// A module for running friends-of-friends halo finding on a set of particles -// - -#include "Python.h" -#include -#include -#include -#include -#include "kd.h" -#include "tipsydefs.h" - -#include "numpy/ndarrayobject.h" - - -static PyObject *_FOFerror; - -static PyObject * -Py_EnzoFOF(PyObject *obj, PyObject *args) -{ - PyObject *oxpos, *oypos, *ozpos; - - PyArrayObject *xpos, *ypos, *zpos; - xpos=ypos=zpos=NULL; - float link = 0.2; - - int i; - - if (!PyArg_ParseTuple(args, "OOO|f", - &oxpos, &oypos, &ozpos, &link)) - return PyErr_Format(_FOFerror, - "EnzoFOF: Invalid parameters."); - - /* First the regular source arrays */ - - xpos = (PyArrayObject *) PyArray_FromAny(oxpos, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(!xpos){ - PyErr_Format(_FOFerror, - "EnzoFOF: xpos didn't work."); - goto _fail; - } - int num_particles = PyArray_SIZE(xpos); - - ypos = (PyArrayObject *) PyArray_FromAny(oypos, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((!ypos)||(PyArray_SIZE(ypos) != num_particles)) { - PyErr_Format(_FOFerror, - "EnzoFOF: xpos and ypos must be the same length."); - goto _fail; - } - - zpos = (PyArrayObject *) PyArray_FromAny(ozpos, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((!zpos)||(PyArray_SIZE(zpos) != num_particles)) { - PyErr_Format(_FOFerror, - "EnzoFOF: xpos and zpos must be the same length."); - goto _fail; - } - - /* let's get started with the FOF stuff */ - - KDFOF kd; - int nBucket,j; - float fPeriod[3],fEps; - int nMembers,nGroup,bVerbose=1; - int sec,usec; - - /* linking length */ - fprintf(stdout, "Link length is %f\n", link); - fEps = link; - - nBucket = 16; - nMembers = 8; - - for (j=0;j<3;++j) fPeriod[j] = 1.0; - - /* initialize the kd FOF structure */ - - kdInitFoF(&kd,nBucket,fPeriod); - - /* kdReadTipsyFoF(kd,stdin,bDark,bGas,bStar); */ - - /* Copy positions into kd structure. */ - - fprintf(stdout, "Filling in %d particles\n", num_particles); - kd->nActive = num_particles; - kd->p = (PARTICLEFOF *)malloc(kd->nActive*sizeof(PARTICLEFOF)); - assert(kd->p != NULL); - for (i = 0; i < num_particles; i++) { - kd->p[i].iOrder = i; - kd->p[i].r[0] = (float)(*(npy_float64*) PyArray_GETPTR1(xpos, i)); - kd->p[i].r[1] = (float)(*(npy_float64*) PyArray_GETPTR1(ypos, i)); - kd->p[i].r[2] = (float)(*(npy_float64*) PyArray_GETPTR1(zpos, i)); - } - - kdBuildTreeFoF(kd); - kdTimeFoF(kd,&sec,&usec); - nGroup = kdFoF(kd,fEps); - kdTimeFoF(kd,&sec,&usec); - if (bVerbose) printf("Number of initial groups:%d\n",nGroup); - nGroup = kdTooSmallFoF(kd,nMembers); - if (bVerbose) { - printf("Number of groups:%d\n",nGroup); - printf("FOF CPU TIME: %d.%06d secs\n",sec,usec); - } - kdOrderFoF(kd); - - /* kdOutGroupFoF(kd,ach); */ - - // Now we need to get the groupID, realID. - // This will give us the index into the original array. - // Additionally, note that we don't really need to tie the index - // back to the ID in this code, as we can do that back in the python code. - // All we need to do is group information. - - // Tags are in kd->p[i].iGroup - PyArrayObject *particle_group_id = (PyArrayObject *) - PyArray_SimpleNewFromDescr(1, PyArray_DIMS(xpos), - PyArray_DescrFromType(NPY_INT32)); - - for (i = 0; i < num_particles; i++) { - // group tag is in kd->p[i].iGroup - *(npy_int32*)(PyArray_GETPTR1(particle_group_id, i)) = - (npy_int32) kd->p[i].iGroup; - } - - kdFinishFoF(kd); - - PyArray_UpdateFlags(particle_group_id, NPY_OWNDATA | particle_group_id->flags); - PyObject *return_value = Py_BuildValue("N", particle_group_id); - - Py_DECREF(xpos); - Py_DECREF(ypos); - Py_DECREF(zpos); - - /* We don't need this, as it's done in kdFinish - if(kd->p!=NULL)free(kd->p); - */ - - return return_value; - -_fail: - Py_XDECREF(xpos); - Py_XDECREF(ypos); - Py_XDECREF(zpos); - - if(kd->p!=NULL)free(kd->p); - - return NULL; - -} - -static PyMethodDef _FOFMethods[] = { - {"RunFOF", Py_EnzoFOF, METH_VARARGS}, - {NULL, NULL} /* Sentinel */ -}; - -/* platform independent*/ -#ifdef MS_WIN32 -__declspec(dllexport) -#endif - -void initEnzoFOF(void) -{ - PyObject *m, *d; - m = Py_InitModule("EnzoFOF", _FOFMethods); - d = PyModule_GetDict(m); - _FOFerror = PyErr_NewException("EnzoFOF.FOFerror", NULL, NULL); - PyDict_SetItemString(d, "error", _FOFerror); - import_array(); -} - -/* - * Local Variables: - * mode: C - * c-file-style: "python" - * End: - */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/README --- a/yt/lagos/fof/README Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ - - - FOF v1.1 - - A Group Finder for N-body Simulations - - October 26, 1994 - -Changes from v1.0: - o Fixed bug in tree building, this bug only affected cases where - a very small "bucket" size was chosen and the number of particles - was not a power of two. - -Included are: - README - Makefile - cat1/fof.1 - kd.c - kd.h - main.c - man1/fof.1 - tipsydefs.h - -For detailed information read the man page (either cat1/fof.1 or -man1/fof.1). - -To build: - - > make - -To get further information contact: - - hpccsoft@astro.washington.edu - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/__init__.py --- a/yt/lagos/fof/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -from yt.lagos import * - -from EnzoFOF import * diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/fof_main.c --- a/yt/lagos/fof/fof_main.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "kd.h" - - -void usage(void) -{ - fprintf(stderr,"USAGE:\n"); - fprintf(stderr,"fof -e \n"); - fprintf(stderr," [-m ] [-dgs] [-v]\n"); - fprintf(stderr," [-o ] [-p ]\n"); - fprintf(stderr," [-px ] [-py ] [-pz ]\n"); - fprintf(stderr,"Input taken from stdin in tipsy binary format.\n"); - fprintf(stderr,"SEE MAN PAGE: fof(1) for more information.\n"); - exit(1); - } - -void main(int argc,char **argv) -{ - KDFOF kd; - int nBucket,i,j; - char ach[80]; - float fPeriod[3],fEps; - int bDark,bGas,bStar; - int nMembers,nGroup,bVerbose; - int sec,usec; - char *p; - - nBucket = 16; - nMembers = 8; - bDark = 1; - bGas = 1; - bStar = 1; - bVerbose = 0; - strcpy(ach,"fof"); - i = 1; - for (j=0;j<3;++j) fPeriod[j] = HUGE; - while (i < argc) { - if (!strcmp(argv[i],"-e")) { - ++i; - fEps = atof(argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-m")) { - ++i; - nMembers = atoi(argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-o")) { - ++i; - strcpy(ach,argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-p")) { - ++i; - fPeriod[0] = atof(argv[i]); - fPeriod[1] = atof(argv[i]); - fPeriod[2] = atof(argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-px")) { - ++i; - fPeriod[0] = atof(argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-py")) { - ++i; - fPeriod[1] = atof(argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-pz")) { - ++i; - fPeriod[2] = atof(argv[i]); - ++i; - } - else if (!strcmp(argv[i],"-v")) { - bVerbose = 1; - ++i; - } - else if (*argv[i] == '-') { - p = argv[i]; - ++p; - if (*p == 'd' || *p == 'g' || *p == 's') { - bDark = 0; - bGas = 0; - bStar = 0; - } - else usage(); - while (isalpha(*p)) { - switch (*p) { - case 'd': - bDark = 1; - break; - case 'g': - bGas = 1; - break; - case 's': - bStar = 1; - break; - default: - usage(); - } - ++p; - } - ++i; - } - else usage(); - } - kdInitFoF(&kd,nBucket,fPeriod); - kdReadTipsyFoF(kd,stdin,bDark,bGas,bStar); - kdBuildTreeFoF(kd); - kdTimeFoF(kd,&sec,&usec); - nGroup = kdFoF(kd,fEps); - kdTimeFoF(kd,&sec,&usec); - if (bVerbose) printf("Number of initial groups:%d\n",nGroup); - nGroup = kdTooSmallFoF(kd,nMembers); - if (bVerbose) { - printf("Number of groups:%d\n",nGroup); - printf("FOF CPU TIME: %d.%06d secs\n",sec,usec); - } - kdOrderFoF(kd); - strcat(ach,".grp"); - kdOutGroupFoF(kd,ach); - kdFinishFoF(kd); - } - - - - - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/kd.c --- a/yt/lagos/fof/kd.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,444 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "kd.h" -#include "tipsydefs.h" - - -void kdTimeFoF(KDFOF kd,int *puSecond,int *puMicro) -{ - struct rusage ru; - - getrusage(0,&ru); - *puMicro = ru.ru_utime.tv_usec - kd->uMicro; - *puSecond = ru.ru_utime.tv_sec - kd->uSecond; - if (*puMicro < 0) { - *puMicro += 1000000; - *puSecond -= 1; - } - kd->uSecond = ru.ru_utime.tv_sec; - kd->uMicro = ru.ru_utime.tv_usec; - } - - -int kdInitFoF(KDFOF *pkd,int nBucket,float *fPeriod) -{ - KDFOF kd; - int j; - - kd = (KDFOF)malloc(sizeof(struct kdContext)); - assert(kd != NULL); - kd->nBucket = nBucket; - for (j=0;j<3;++j) kd->fPeriod[j] = fPeriod[j]; - kd->p = NULL; - kd->kdNodes = NULL; - *pkd = kd; - return(1); - } - - -void kdReadTipsyFoF(KDFOF kd,FILE *fp,int bDark,int bGas,int bStar) -{ - int i,j,nCnt; - struct dump h; - struct gas_particle gp; - struct dark_particle dp; - struct star_particle sp; - - fread(&h,sizeof(struct dump),1,fp); - kd->nParticles = h.nbodies; - kd->nDark = h.ndark; - kd->nGas = h.nsph; - kd->nStar = h.nstar; - kd->fTime = h.time; - kd->nActive = 0; - if (bDark) kd->nActive += kd->nDark; - if (bGas) kd->nActive += kd->nGas; - if (bStar) kd->nActive += kd->nStar; - kd->bDark = bDark; - kd->bGas = bGas; - kd->bStar = bStar; - /* - ** Allocate particles. - */ - kd->p = (PARTICLEFOF *)malloc(kd->nActive*sizeof(PARTICLEFOF)); - assert(kd->p != NULL); - /* - ** Read Stuff! - */ - nCnt = 0; - for (i=0;ip[nCnt].iOrder = nCnt; - for (j=0;j<3;++j) kd->p[nCnt].r[j] = gp.pos[j]; - ++nCnt; - } - } - for (i=0;ip[nCnt].iOrder = nCnt; - for (j=0;j<3;++j) kd->p[nCnt].r[j] = dp.pos[j]; - ++nCnt; - } - } - for (i=0;ip[nCnt].iOrder = nCnt; - for (j=0;j<3;++j) kd->p[nCnt].r[j] = sp.pos[j]; - ++nCnt; - } - } - } - - -void kdSelectFoF(KDFOF kd,int d,int k,int l,int r) -{ - PARTICLEFOF *p,t; - double v; - int i,j; - - p = kd->p; - while (r > l) { - v = p[k].r[d]; - t = p[r]; - p[r] = p[k]; - p[k] = t; - i = l - 1; - j = r; - while (1) { - while (i < j) if (p[++i].r[d] >= v) break; - while (i < j) if (p[--j].r[d] <= v) break; - t = p[i]; - p[i] = p[j]; - p[j] = t; - if (j <= i) break; - } - p[j] = p[i]; - p[i] = p[r]; - p[r] = t; - if (i >= k) r = i - 1; - if (i <= k) l = i + 1; - } - } - - -void kdCombineFoF(KDNFOF *p1,KDNFOF *p2,KDNFOF *pOut) -{ - int j; - - /* - ** Combine the bounds. - */ - for (j=0;j<3;++j) { - if (p2->bnd.fMin[j] < p1->bnd.fMin[j]) - pOut->bnd.fMin[j] = p2->bnd.fMin[j]; - else - pOut->bnd.fMin[j] = p1->bnd.fMin[j]; - if (p2->bnd.fMax[j] > p1->bnd.fMax[j]) - pOut->bnd.fMax[j] = p2->bnd.fMax[j]; - else - pOut->bnd.fMax[j] = p1->bnd.fMax[j]; - } - } - - -void kdUpPassFoF(KDFOF kd,int iCell) -{ - KDNFOF *c; - int l,u,pj,j; - - c = kd->kdNodes; - if (c[iCell].iDim != -1) { - l = LOWERFOF(iCell); - u = UPPERFOF(iCell); - kdUpPassFoF(kd,l); - kdUpPassFoF(kd,u); - kdCombineFoF(&c[l],&c[u],&c[iCell]); - } - else { - l = c[iCell].pLower; - u = c[iCell].pUpper; - for (j=0;j<3;++j) { - c[iCell].bnd.fMin[j] = kd->p[u].r[j]; - c[iCell].bnd.fMax[j] = kd->p[u].r[j]; - } - for (pj=l;pjp[pj].r[j] < c[iCell].bnd.fMin[j]) - c[iCell].bnd.fMin[j] = kd->p[pj].r[j]; - if (kd->p[pj].r[j] > c[iCell].bnd.fMax[j]) - c[iCell].bnd.fMax[j] = kd->p[pj].r[j]; - } - } - } - } - -void kdBuildTreeFoF(KDFOF kd) -{ - int l,n,i,d,m,j,diff; - KDNFOF *c; - BNDFOF bnd; - - n = kd->nActive; - kd->nLevels = 1; - l = 1; - while (n > kd->nBucket) { - n = n>>1; - l = l<<1; - ++kd->nLevels; - } - kd->nSplit = l; - kd->nNodes = l<<1; - if (kd->kdNodes != NULL) free(kd->kdNodes); - kd->kdNodes = (KDNFOF *)malloc(kd->nNodes*sizeof(KDNFOF)); - assert(kd->kdNodes != NULL); - /* - ** Calculate Bounds. - */ - for (j=0;j<3;++j) { - bnd.fMin[j] = kd->p[0].r[j]; - bnd.fMax[j] = kd->p[0].r[j]; - } - for (i=1;inActive;++i) { - for (j=0;j<3;++j) { - if (bnd.fMin[j] > kd->p[i].r[j]) - bnd.fMin[j] = kd->p[i].r[j]; - else if (bnd.fMax[j] < kd->p[i].r[j]) - bnd.fMax[j] = kd->p[i].r[j]; - } - } - /* - ** Set up ROOTFOF node - */ - c = kd->kdNodes; - c[ROOTFOF].pLower = 0; - c[ROOTFOF].pUpper = kd->nActive-1; - c[ROOTFOF].bnd = bnd; - i = ROOTFOF; - while (1) { - assert(c[i].pUpper - c[i].pLower + 1 > 0); - if (i < kd->nSplit && (c[i].pUpper - c[i].pLower) > 0) { - d = 0; - for (j=1;j<3;++j) { - if (c[i].bnd.fMax[j]-c[i].bnd.fMin[j] > - c[i].bnd.fMax[d]-c[i].bnd.fMin[d]) d = j; - } - c[i].iDim = d; - - m = (c[i].pLower + c[i].pUpper)/2; - kdSelectFoF(kd,d,m,c[i].pLower,c[i].pUpper); - - c[i].fSplit = kd->p[m].r[d]; - c[LOWERFOF(i)].bnd = c[i].bnd; - c[LOWERFOF(i)].bnd.fMax[d] = c[i].fSplit; - c[LOWERFOF(i)].pLower = c[i].pLower; - c[LOWERFOF(i)].pUpper = m; - c[UPPERFOF(i)].bnd = c[i].bnd; - c[UPPERFOF(i)].bnd.fMin[d] = c[i].fSplit; - c[UPPERFOF(i)].pLower = m+1; - c[UPPERFOF(i)].pUpper = c[i].pUpper; - diff = (m-c[i].pLower+1)-(c[i].pUpper-m); - assert(diff == 0 || diff == 1); - i = LOWERFOF(i); - } - else { - c[i].iDim = -1; - SETNEXTFOF(i); - if (i == ROOTFOF) break; - } - } - kdUpPassFoF(kd,ROOTFOF); - } - - -int kdFoF(KDFOF kd,float fEps) -{ - PARTICLEFOF *p; - KDNFOF *c; - int pi,pj,pn,cp; - - int iGroup; - - int *Fifo,iHead,iTail,nFifo; - float fEps2; - float dx,dy,dz,x,y,z,lx,ly,lz,sx,sy,sz,fDist2; - - p = kd->p; - c = kd->kdNodes; - lx = kd->fPeriod[0]; - ly = kd->fPeriod[1]; - lz = kd->fPeriod[2]; - fEps2 = fEps*fEps; - for (pn=0;pnnActive;++pn) p[pn].iGroup = 0; - nFifo = kd->nActive; - Fifo = (int *)malloc(nFifo*sizeof(int)); - assert(Fifo != NULL); - iHead = 0; - iTail = 0; - iGroup = 0; - for (pn=0;pnnActive;++pn) { - if (p[pn].iGroup) continue; - ++iGroup; - /* - ** Mark it and add to the do-fifo. - */ - p[pn].iGroup = iGroup; - Fifo[iTail++] = pn; - if (iTail == nFifo) iTail = 0; - while (iHead != iTail) { - pi = Fifo[iHead++]; - if (iHead == nFifo) iHead = 0; - /* - ** Now do an fEps-Ball Gather! - */ - x = p[pi].r[0]; - y = p[pi].r[1]; - z = p[pi].r[2]; - cp = ROOTFOF; - while (1) { - INTERSECTFOF(c,cp,fEps2,lx,ly,lz,x,y,z,sx,sy,sz); - /* - ** We have an intersection to test. - */ - if (c[cp].iDim >= 0) { - cp = LOWERFOF(cp); - continue; - } - else { - for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { - if (p[pj].iGroup) continue; - dx = sx - p[pj].r[0]; - dy = sy - p[pj].r[1]; - dz = sz - p[pj].r[2]; - fDist2 = dx*dx + dy*dy + dz*dz; - if (fDist2 < fEps2) { - /* - ** Mark it and add to the do-fifo. - */ - p[pj].iGroup = iGroup; - Fifo[iTail++] = pj; - if (iTail == nFifo) iTail = 0; - } - } - SETNEXTFOF(cp); - if (cp == ROOTFOF) break; - continue; - } - ContainedCell: - for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { - if (p[pj].iGroup) continue; - /* - ** Mark it and add to the do-fifo. - */ - p[pj].iGroup = iGroup; - Fifo[iTail++] = pj; - if (iTail == nFifo) iTail = 0; - } - GetNextCell: - SETNEXTFOF(cp); - if (cp == ROOTFOF) break; - } - } - } - free(Fifo); - kd->nGroup = iGroup+1; - return(kd->nGroup-1); - } - - -int kdTooSmallFoF(KDFOF kd,int nMembers) -{ - int *pnMembers,*pMap; - int i,pi,nGroup; - - pnMembers = (int *)malloc(kd->nGroup*sizeof(int)); - assert(pnMembers != NULL); - pMap = (int *)malloc(kd->nGroup*sizeof(int)); - assert(pMap != NULL); - for (i=0;inGroup;++i) pnMembers[i] = 0; - for (pi=0;pinActive;++pi) { - ++pnMembers[kd->p[pi].iGroup]; - } - for (i=1;inGroup;++i) { - if (pnMembers[i] < nMembers) { - pnMembers[i] = 0; - } - } - /* - ** Create a remapping! - */ - pMap[0] = 0; - nGroup = 1; - for (i=1;inGroup;++i) { - pMap[i] = nGroup; - if (pnMembers[i] == 0) { - pMap[i] = -1; /* was 0 */ - } - else { - ++nGroup; - } - } - /* - ** Remap the groups. - */ - for (pi=0;pinActive;++pi) { - kd->p[pi].iGroup = pMap[kd->p[pi].iGroup]; - } - free(pMap); - free(pnMembers); - kd->nGroup = nGroup; - return(nGroup-1); - } - - -int CmpParticlesFoF(const void *v1,const void *v2) -{ - PARTICLEFOF *p1 = (PARTICLEFOF *)v1; - PARTICLEFOF *p2 = (PARTICLEFOF *)v2; - return(p1->iOrder - p2->iOrder); - } - -void kdOrderFoF(KDFOF kd) -{ - qsort(kd->p,kd->nActive,sizeof(PARTICLEFOF),CmpParticlesFoF); - } - - -void kdOutGroupFoF(KDFOF kd,char *pszFile) -{ - FILE *fp; - int i,iCnt; - - fp = fopen(pszFile,"w"); - assert(fp != NULL); - fprintf(fp,"%d\n",kd->nParticles); - iCnt = 0; - for (i=0;inGas;++i) { - if (kd->bGas) fprintf(fp,"%d\n",kd->p[iCnt++].iGroup); - else fprintf(fp,"0\n"); - } - for (i=0;inDark;++i) { - if (kd->bDark) fprintf(fp,"%d\n",kd->p[iCnt++].iGroup); - else fprintf(fp,"0\n"); - } - for (i=0;inStar;++i) { - if (kd->bStar) fprintf(fp,"%d\n",kd->p[iCnt++].iGroup); - else fprintf(fp,"0\n"); - } - fclose(fp); - } - - -void kdFinishFoF(KDFOF kd) -{ - free(kd->p); - free(kd->kdNodes); - free(kd); - } - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/kd.h --- a/yt/lagos/fof/kd.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -#ifndef KDFOF_HINCLUDED -#define KDFOF_HINCLUDED - -#define ROOTFOF 1 -#define LOWERFOF(i) (i<<1) -#define UPPERFOF(i) ((i<<1)+1) -#define PARENTFOF(i) (i>>1) -#define SIBLINGFOF(i) ((i&1)?i-1:i+1) -#define SETNEXTFOF(i)\ -{\ - while (i&1) i=i>>1;\ - ++i;\ - } - -#define DARKFOF 1 -#define GASFOF 2 -#define STARFOF 4 - -#define KDFOF_ORDERTEMP 256 - -typedef struct Particle { - float r[3]; - int iGroup; - int iOrder; - } PARTICLEFOF; - -typedef struct bndBound { - float fMin[3]; - float fMax[3]; - } BNDFOF; - -typedef struct kdNode { - float fSplit; - BNDFOF bnd; - int iDim; - int pLower; - int pUpper; - } KDNFOF; - -typedef struct kdContext { - int nBucket; - int nParticles; - int nDark; - int nGas; - int nStar; - int bDark; - int bGas; - int bStar; - int nActive; - float fTime; - float fPeriod[3]; - int nLevels; - int nNodes; - int nSplit; - PARTICLEFOF *p; - KDNFOF *kdNodes; - int nGroup; - int uSecond; - int uMicro; - } * KDFOF; - - -#define INTERSECTFOF(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz)\ -{\ - float dx,dy,dz,dx1,dy1,dz1,fDist2,fMax2;\ - dx = c[cp].bnd.fMin[0]-x;\ - dx1 = x-c[cp].bnd.fMax[0];\ - dy = c[cp].bnd.fMin[1]-y;\ - dy1 = y-c[cp].bnd.fMax[1];\ - dz = c[cp].bnd.fMin[2]-z;\ - dz1 = z-c[cp].bnd.fMax[2];\ - if (dx > 0.0) {\ - if (dx1+lx < dx) {\ - dx1 += lx;\ - dx -= lx;\ - sx = x+lx;\ - fDist2 = dx1*dx1;\ - fMax2 = dx*dx;\ - }\ - else {\ - sx = x;\ - fDist2 = dx*dx;\ - fMax2 = dx1*dx1;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else if (dx1 > 0.0) {\ - if (dx+lx < dx1) {\ - dx += lx;\ - dx1 -= lx;\ - sx = x-lx;\ - fDist2 = dx*dx;\ - fMax2 = dx1*dx1;\ - }\ - else {\ - sx = x;\ - fDist2 = dx1*dx1;\ - fMax2 = dx*dx;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else {\ - sx = x;\ - fDist2 = 0.0;\ - if (dx < dx1) fMax2 = dx*dx;\ - else fMax2 = dx1*dx1;\ - }\ - if (dy > 0.0) {\ - if (dy1+ly < dy) {\ - dy1 += ly;\ - dy -= ly;\ - sy = y+ly;\ - fDist2 += dy1*dy1;\ - fMax2 += dy*dy;\ - }\ - else {\ - sy = y;\ - fDist2 += dy*dy;\ - fMax2 += dy1*dy1;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else if (dy1 > 0.0) {\ - if (dy+ly < dy1) {\ - dy += ly;\ - dy1 -= ly;\ - sy = y-ly;\ - fDist2 += dy*dy;\ - fMax2 += dy1*dy1;\ - }\ - else {\ - sy = y;\ - fDist2 += dy1*dy1;\ - fMax2 += dy*dy;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else {\ - sy = y;\ - if (dy < dy1) fMax2 += dy*dy;\ - else fMax2 += dy1*dy1;\ - }\ - if (dz > 0.0) {\ - if (dz1+lz < dz) {\ - dz1 += lz;\ - dz -= lz;\ - sz = z+lz;\ - fDist2 += dz1*dz1;\ - fMax2 += dz*dz;\ - }\ - else {\ - sz = z;\ - fDist2 += dz*dz;\ - fMax2 += dz1*dz1;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else if (dz1 > 0.0) {\ - if (dz+lz < dz1) {\ - dz += lz;\ - dz1 -= lz;\ - sz = z-lz;\ - fDist2 += dz*dz;\ - fMax2 += dz1*dz1;\ - }\ - else {\ - sz = z;\ - fDist2 += dz1*dz1;\ - fMax2 += dz*dz;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else {\ - sz = z;\ - if (dz < dz1) fMax2 += dz*dz;\ - else fMax2 += dz1*dz1;\ - }\ - if (fMax2 < fBall2) goto ContainedCell;\ - } - - -void kdTimeFoF(KDFOF,int *,int *); -int kdInitFoF(KDFOF *,int,float *); -void kdReadTipsyFoF(KDFOF,FILE *,int,int,int); -void kdBuildTreeFoF(KDFOF); -int kdFoF(KDFOF,float); -int kdTooSmallFoF(KDFOF,int); -void kdOrderFoF(KDFOF); -void kdOutGroupFoF(KDFOF,char *); -void kdFinishFoF(KDFOF); - -#endif - - - - - - - - - - - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/setup.py --- a/yt/lagos/fof/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#!/usr/bin/env python -import setuptools -import os, sys, os.path - -import os.path - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('fof',parent_package,top_path) - config.make_config_py() # installs __config__.py - config.make_svn_version_py() - config.add_extension("EnzoFOF", sources= - ["EnzoFOF.c", - "kd.c"], - libraries=["m"]) - return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/fof/tipsydefs.h --- a/yt/lagos/fof/tipsydefs.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -#ifndef _TIPSYDEFS_H -#define _TIPSYDEFS_H -#define MAXDIM 3 -#define forever for(;;) - -typedef float Real; - -struct gas_particle { - Real mass; - Real pos[MAXDIM]; - Real vel[MAXDIM]; - Real rho; - Real temp; - Real hsmooth; - Real metals ; - Real phi ; -} ; - -struct dark_particle { - Real mass; - Real pos[MAXDIM]; - Real vel[MAXDIM]; - Real eps; - Real phi ; -} ; - -struct star_particle { - Real mass; - Real pos[MAXDIM]; - Real vel[MAXDIM]; - Real metals ; - Real tform ; - Real eps; - Real phi ; -} ; - -struct dump { - double time ; - int nbodies ; - int ndim ; - int nsph ; - int ndark ; - int nstar ; -} ; - -#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/EnzoHop.c --- a/yt/lagos/hop/EnzoHop.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,448 +0,0 @@ -/************************************************************************ -* Copyright (C) 2008-2009 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 . -* -************************************************************************/ - -// -// EnzoHop -// A module for running HOP halo finding on a set of particles -// - -#include "Python.h" -#include "structmember.h" -#include -#include -#include -#include -#include "kd.h" -#include "hop.h" -#include "hop_numpy.h" - -#include "numpy/ndarrayobject.h" - -void initgrouplist(Grouplist *g); -void hop_main(KD kd, HC *my_comm, float densthres); -void regroup_main(float dens_outer, HC *my_comm); -static PyObject *_HOPerror; - -int convert_particle_arrays( - PyObject *oxpos, PyObject *oypos, PyObject *ozpos, PyObject *omass, - PyArrayObject **xpos, PyArrayObject **ypos, PyArrayObject **zpos, - PyArrayObject **mass) -{ - - /* First the regular source arrays */ - - *xpos = (PyArrayObject *) PyArray_FromAny(oxpos, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if(!*xpos){ - PyErr_Format(_HOPerror, - "EnzoHop: xpos didn't work."); - return -1; - } - int num_particles = PyArray_SIZE(*xpos); - - *ypos = (PyArrayObject *) PyArray_FromAny(oypos, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((!*ypos)||(PyArray_SIZE(*ypos) != num_particles)) { - PyErr_Format(_HOPerror, - "EnzoHop: xpos and ypos must be the same length."); - return -1; - } - - *zpos = (PyArrayObject *) PyArray_FromAny(ozpos, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((!*zpos)||(PyArray_SIZE(*zpos) != num_particles)) { - PyErr_Format(_HOPerror, - "EnzoHop: xpos and zpos must be the same length."); - return -1; - } - - *mass = (PyArrayObject *) PyArray_FromAny(omass, - PyArray_DescrFromType(NPY_FLOAT64), 1, 1, - NPY_INOUT_ARRAY | NPY_UPDATEIFCOPY, NULL); - if((!*mass)||(PyArray_SIZE(*mass) != num_particles)) { - PyErr_Format(_HOPerror, - "EnzoHop: xpos and mass must be the same length."); - return -1; - } - - return num_particles; - -} - - -static PyObject * -Py_EnzoHop(PyObject *obj, PyObject *args) -{ - PyObject *oxpos, *oypos, *ozpos, - *omass; - - PyArrayObject *xpos, *ypos, *zpos, - *mass; - xpos=ypos=zpos=mass=NULL; - npy_float64 totalmass = 0.0; - float normalize_to = 1.0; - float thresh = 160.0; - - int i; - - if (!PyArg_ParseTuple(args, "OOOO|ff", - &oxpos, &oypos, &ozpos, &omass, &thresh, &normalize_to)) - return PyErr_Format(_HOPerror, - "EnzoHop: Invalid parameters."); - - int num_particles = convert_particle_arrays( - oxpos, oypos, ozpos, omass, - &xpos, &ypos, &zpos, &mass); - if (num_particles < 0) goto _fail; - - for(i = 0; i < num_particles; i++) - totalmass+=*(npy_float64*)PyArray_GETPTR1(mass,i); - totalmass /= normalize_to; - - /* initialize the kd hop structure */ - - KD kd; - int nBucket = 16, kdcount = 0; - kdInit(&kd, nBucket); - kd->nActive = num_particles; - kd->p = malloc(sizeof(PARTICLE)*num_particles); - if (kd->p == NULL) { - fprintf(stderr, "failed allocating particles.\n"); - goto _fail; - } - - /* Copy positions into kd structure. */ - PyArrayObject *particle_density = (PyArrayObject *) - PyArray_SimpleNewFromDescr(1, PyArray_DIMS(xpos), - PyArray_DescrFromType(NPY_FLOAT64)); - - fprintf(stdout, "Copying arrays for %d particles\n", num_particles); - kd->np_masses = (npy_float64*) mass->data; - kd->np_pos[0] = (npy_float64*) xpos->data; - kd->np_pos[1] = (npy_float64*) ypos->data; - kd->np_pos[2] = (npy_float64*) zpos->data; - kd->np_densities = (npy_float64*) particle_density->data; - kd->totalmass = totalmass; - for (i = 0; i < num_particles; i++) kd->p[i].np_index = i; - - HC my_comm; - my_comm.s = newslice(); - my_comm.gl = (Grouplist*)malloc(sizeof(Grouplist)); - if(my_comm.gl == NULL) { - fprintf(stderr, "failed allocating Grouplist\n"); - goto _fail; - } - initgrouplist(my_comm.gl); - - fprintf(stderr, "Calling hop... %d %0.3e\n",num_particles,thresh); - hop_main(kd, &my_comm, thresh); - - fprintf(stderr, "Calling regroup...\n"); - regroup_main(thresh, &my_comm); - - // Now we need to get the groupID, realID and the density. - // This will give us the index into the original array. - // Additionally, note that we don't really need to tie the index - // back to the ID in this code, as we can do that back in the python code. - // All we need to do is provide density and group information. - - // Tags (as per writetagsf77) are in gl.s->ntag+1 and there are gl.s->numlist of them. - PyArrayObject *particle_group_id = (PyArrayObject *) - PyArray_SimpleNewFromDescr(1, PyArray_DIMS(xpos), - PyArray_DescrFromType(NPY_INT32)); - - for (i = 0; i < num_particles; i++) { - // tag is in gl.s->ntag[i+1] - *(npy_int32*)(PyArray_GETPTR1(particle_group_id, i)) = - (npy_int32) my_comm.s->ntag[i+1]; - } - - kdFinish(kd); - free(my_comm.gl); - free_slice(my_comm.s); - - PyArray_UpdateFlags(particle_density, NPY_OWNDATA | particle_density->flags); - PyArray_UpdateFlags(particle_group_id, NPY_OWNDATA | particle_group_id->flags); - PyObject *return_value = Py_BuildValue("NN", particle_density, particle_group_id); - - Py_DECREF(xpos); - Py_DECREF(ypos); - Py_DECREF(zpos); - Py_DECREF(mass); - - /* We don't need this, as it's done in kdFinish - if(kd->p!=NULL)free(kd->p); - */ - - return return_value; - -_fail: - Py_XDECREF(xpos); - Py_XDECREF(ypos); - Py_XDECREF(zpos); - Py_XDECREF(mass); - - if(kd->p!=NULL)free(kd->p); - - return NULL; - -} - -static PyMethodDef _HOPMethods[] = { - {"RunHOP", Py_EnzoHop, METH_VARARGS}, - {NULL, NULL} /* Sentinel */ -}; - -/* platform independent*/ -#ifdef MS_WIN32 -__declspec(dllexport) -#endif - -// -// Now a fun wrapper class for the kD-tree -// - -typedef struct { - PyObject_HEAD - KD kd; - PyArrayObject *xpos, *ypos, *zpos; - PyArrayObject *mass, *densities; - int num_particles; -} kDTreeType; - -static int -kDTreeType_init(kDTreeType *self, PyObject *args, PyObject *kwds) -{ - int nBuckets = 16, i; - float normalize_to = 1.0; - static char *kwlist[] = {"xpos", "ypos", "zpos", "mass", - "nbuckets", "norm", NULL}; - PyObject *oxpos, *oypos, *ozpos, - *omass; - self->xpos=self->ypos=self->zpos=self->mass=NULL; - - - if (! PyArg_ParseTupleAndKeywords(args, kwds, "OOOO|if", kwlist, - &oxpos, &oypos, &ozpos, &omass, - &nBuckets, &normalize_to)) - return -1; /* Should this give an error? */ - - kdInit(&self->kd, nBuckets); - - self->num_particles = convert_particle_arrays( - oxpos, oypos, ozpos, omass, - &self->xpos, &self->ypos, &self->zpos, &self->mass); - - self->kd->nActive = self->num_particles; - self->kd->p = malloc(sizeof(PARTICLE)*self->num_particles); - if (self->kd->p == NULL) { - fprintf(stderr, "failed allocating particles.\n"); - goto _fail; - } - - /* Now we set up our Density array */ - self->densities = (PyArrayObject *) - PyArray_SimpleNewFromDescr(1, PyArray_DIMS(self->xpos), - PyArray_DescrFromType(NPY_FLOAT64)); - - npy_float64 totalmass = 0.0; - for(i= 0; i < self->num_particles; i++) { - self->kd->p[i].np_index = i; - *(npy_float64*)(PyArray_GETPTR1(self->densities, i)) = 0.0; - totalmass+=*(npy_float64*)PyArray_GETPTR1(self->mass,i); - } - totalmass /= normalize_to; - - - self->kd->np_masses = (npy_float64 *)self->mass->data; - self->kd->np_pos[0] = (npy_float64 *)self->xpos->data; - self->kd->np_pos[1] = (npy_float64 *)self->ypos->data; - self->kd->np_pos[2] = (npy_float64 *)self->zpos->data; - self->kd->np_densities = (npy_float64 *)self->densities->data; - self->kd->totalmass = totalmass; - - PrepareKD(self->kd); - kdBuildTree(self->kd); - - return 0; - - _fail: - Py_XDECREF(self->xpos); - Py_XDECREF(self->ypos); - Py_XDECREF(self->zpos); - Py_XDECREF(self->mass); - - if(self->kd->p!=NULL)free(self->kd->p); - - return -1; -} - -static void -kDTreeType_dealloc(kDTreeType *self) -{ - kdFinish(self->kd); - Py_XDECREF(self->xpos); - Py_XDECREF(self->ypos); - Py_XDECREF(self->zpos); - Py_XDECREF(self->mass); - - self->ob_type->tp_free((PyObject*)self); -} - -static PyObject * -kDTreeType_up_pass(kDTreeType *self, PyObject *args) { - int iCell; - - if (!PyArg_ParseTuple(args, "i", &iCell)) - return PyErr_Format(_HOPerror, - "kDTree.up_pass: invalid parameters."); - - if(iCell >= self->num_particles) - return PyErr_Format(_HOPerror, - "kDTree.up_pass: iCell cannot be >= num_particles!"); - - kdUpPass(self->kd, iCell); - return Py_None; -} - -static PyObject * -kDTreeType_median_jst(kDTreeType *self, PyObject *args) { - int d, l, u; - - if (!PyArg_ParseTuple(args, "iii", &d, &l, &u)) - return PyErr_Format(_HOPerror, - "kDTree.median_jst: invalid parameters."); - - if(d >= 3) - return PyErr_Format(_HOPerror, - "kDTree.median_jst: d cannot be >= 3!"); - - if(l >= self->num_particles) - return PyErr_Format(_HOPerror, - "kDTree.median_jst: l cannot be >= num_particles!"); - - if(u >= self->num_particles) - return PyErr_Format(_HOPerror, - "kDTree.median_jst: u cannot be >= num_particles!"); - - int median = kdMedianJst(self->kd, d, l, u); - - PyObject *omedian = PyInt_FromLong((long)median); - return omedian; -} - -static PyMemberDef kDTreeType_members[] = { - { "xpos", T_OBJECT, offsetof(kDTreeType, xpos), 0, - "The xposition array."}, - { "ypos", T_OBJECT, offsetof(kDTreeType, ypos), 0, - "The yposition array."}, - { "zpos", T_OBJECT, offsetof(kDTreeType, zpos), 0, - "The zposition array."}, - { "mass", T_OBJECT, offsetof(kDTreeType, mass), 0, - "The mass array."}, - { "densities", T_OBJECT, offsetof(kDTreeType, densities), 0, - "The density array."}, - { "num_particles", T_INT, offsetof(kDTreeType, num_particles), 0, - "The number of particles"}, - { NULL } -}; - -static PyMethodDef -kDTreeType_methods[] = { - { "up_pass", (PyCFunction) kDTreeType_up_pass, METH_VARARGS, - "Pass up something or another, I'm not really sure."}, - { "median_jst", (PyCFunction) kDTreeType_median_jst, METH_VARARGS, - "Use the JST Median algorithm on two points along a dimension."}, - // typically there would be more here... - - { NULL } -}; - -static PyTypeObject -kDTreeTypeDict = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - "kDTree", /* tp_name */ - sizeof(kDTreeType), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)kDTreeType_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "kDTree object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - kDTreeType_methods, /* tp_methods */ - kDTreeType_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)kDTreeType_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -void initEnzoHop(void) -{ - PyObject *m, *d; - m = Py_InitModule("EnzoHop", _HOPMethods); - d = PyModule_GetDict(m); - _HOPerror = PyErr_NewException("EnzoHop.HOPerror", NULL, NULL); - PyDict_SetItemString(d, "error", _HOPerror); - - kDTreeTypeDict.tp_new = PyType_GenericNew; - if (PyType_Ready(&kDTreeTypeDict) < 0) { - return; - } - - Py_INCREF(&kDTreeTypeDict); - PyModule_AddObject(m, "kDTree", (PyObject*)&kDTreeTypeDict); - - import_array(); -} - -/* - * Local Variables: - * mode: C - * c-file-style: "python" - * End: - */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/Merger.py --- a/yt/lagos/hop/Merger.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,421 +0,0 @@ -# Merger.py. Written by Stephen Skory & Rick Wagner, August 2006. - -# figures the 'family tree,' and outputs in GraphViz format, the galaxy -# merger history for a series of files that list the particles & the group that -# they are assigned to. - -# this file only contains functions that are used by the output of fastBuildMerge.py. - -# June 2008, converted/upgraded for use in Matthew Turk's enzo analyzer yt by Stephen Skory - -# define the Group class for the list of groups, which contains -# the group id, a list of the particles in that group, the numerical -# order of the group, the percentage of the groups particles that go to the -# ether (no group), and the percentage of the group that comes from no group. -class Group: - - - def __init__(self, id, particles, orderIndex, toEther, fromEther, flag): - self.id = id - self.particles = particles - self.orderIndex = orderIndex - # these are fields to track how much of each group comes and goes to the - # ether - self.toEther = toEther - self.fromEther = fromEther - # the flag says whether or not this group is linked to the final, - # interesting group(s). - self.flag = flag - -# the heavy lifting. This takes in a parentGroup and sees how many of its particles -# go to the childGroup. -# DEPRECIATED, replaced by pushListCount. I've left it here because it's still functional and -# a lot simpler to understand than pushListCount. If you want to use it, uncomment out the line -# where it's used in buildLinks, and comment out the pushListCount line. This is a whole bunch slower -# than pushListCount, so I don't know why you would want to do that. - - def isParent(self, childGroup): - - n = 0 - for particleNumber in self.particles: - if childGroup.particles.count(particleNumber): - #return True - n+=1 - - return n - -# this function takes two lists which have both been sorted in increasing order. This is a way to -# take the O(n^2) matching and make it roughly O(2n). Since most of the time most particles go from -# one group to the next, a step down one list will get the same next particle in the other list, so -# most of the time we can move down both lists simultaneously. When one entry is bigger than the other, -# we use findNextMatch to see how far to move the second list until it matches the first, or -# surpasses the first (in which case we then move the first list until it catches up with the second, -# ad naseum). -def pushListCount(list1, list2): - - - count = 0 - i = 0 - j = 0 - - while (i < len(list1)) and (j < len(list2)): - #print 'list1['+str(i)+']='+str(list1[i])+' list2['+str(j)+']='+str(list2[j]) - if list1[i] == list2[j]: - i += 1 - j += 1 - count += 1 - #print 'Matched first try' - else: - if (i <= len(list1) -1) and (j <= len(list2) -1): - value = min(list1[i], list2[j]) - #print str(value) - if value == list1[i]: - #print 'First list smaller' - nextindex = findNextMatch(i+1, list2[j], list1) - if nextindex > -1: - if nextindex == 1.5: # special case - j += 1 - i += 1 - else: - i = nextindex + 1 - j += 1 - count += 1 - if nextindex < -1: - i = -1 * nextindex - j += 1 - if (j == len(list2)) or (i == len(list1)): - break - if nextindex == -1: - #print "Got minus one on second list, nextindex= " + str(nextindex) - break - - if value == list2[j]: - #print 'Second list smaller' - nextindex = findNextMatch(j+1, list1[i], list2) - if nextindex > -1: - if nextindex == 1.5: # special case - j += 1 - i +=1 - else: - j = nextindex +1 - i += 1 - count += 1 - if nextindex < -1: - j = -1 * nextindex - i += 1 - if nextindex == 1: - j = nextindex + 1 - i += 1 - if (j == len(list2)) or (i == len(list1)): - break - if nextindex == -1: - #print "Got minus one on first list, nextindex= " + str(nextindex) - break - #print 'count: ' + str(count) - - return count - -def findNextMatch(startIndex, value, thislist): - #print "looking for " + str(value) + ', startindex= ' + str(startIndex) - outval = -1 - for i in range(startIndex, len(thislist)): - #print 'thislist[' + str(i) +'] = ' +str(thislist[i]) - if thislist[i] == value: - outval = i - break - if thislist[i] > value: - outval = -1 * i - if outval == -1: # this in case i=1, which isn't a problem unless outval=-1 *is* the value we want - # this happens if the second item in each list matches - outval = 1.5 - break - #print 'found match for ' + str(value) + ' at index: ' + str(outval) - - return outval - - - -# add yt.hop particles into the Group structure -def convertGroups(snapshot,orderIndex,hardmaxgroup): - from yt.lagos import mylog - # ytHopResults is the stuff from yt containing the results of hop. - # orderIndex is the index for this snapshot - # hardmaxgroup is some reasonable limit for the number of galaxies looked at for each - # time step. - - groups = [] - particles = [] - # set up the percent fields for later... - toEther = 100 - fromEther = 100 - pcount = 0 # counts how many particles are groups for that particular time step - flag = 0 # zero means not assoc with final group, one means yes. - - # loop over the groups - for i,group in enumerate(snapshot): - # don't go past hardmaxgroup - if (i >= hardmaxgroup): - break - # add it to our groups as a Group - groups.append(Group(i,group["particle_index"],orderIndex,toEther,fromEther,flag)) - pcount += len(group["particle_index"]) - - string = "There are " + str(pcount) + " particles in orderIndex " + str(orderIndex) + "." - mylog.info(string) - return(groups) - - -# from the yt.hop output, add to the positions dict the central position and group index for this -# snapshot -def convertPositions(snapshot,orderIndex,positions,hardmaxgroup): - from yt.lagos import mylog - # loop over the hop groups - for i,group in enumerate(snapshot): - # if we're trying to read in too many groups, we're done so we leave - if (i >= hardmaxgroup): - break - center = group.maximum_density_location() - positions[orderIndex,i] = (center[0],center[1],center[2]) - - string = 'There are ' + str(len(snapshot)) + ' groups in orderIndex ' + str(orderIndex) - mylog.info(string) - - return (positions) - -# add yt.hop particles into the Group structure, but for selected groups, for the -# last time step, which is the first inspected. -def convertGroupsSelected(snapshot,orderIndex,indices): - from yt.lagos import mylog - # ytHopResults is the stuff from yt containing the results of hop. - # orderIndex is the index for this snapshot - # hardmaxgroup is some reasonable limit for the number of galaxies looked at for each - # time step. - - groups = [] - particles = [] - # set up the percent fields for later... - toEther = 100 - fromEther = 100 - pcount = 0 # counts how many particles are groups for that particular time step - flag = 0 # zero means not assoc with final group, one means yes. - - # loop over the selected groups - for index in indices: - # pick out the one group - group = snapshot[index] - - # add it to our groups as a Group - groups.append(Group(index,group["particle_index"],orderIndex,toEther,fromEther,flag)) - pcount += len(group["particle_index"]) - - string = "There are " + str(pcount) + " particles in orderIndex " + str(orderIndex) + "." - mylog.info(string) - return(groups) - -# from the yt.hop output, add to the positions dict the central position and group index for this -# snapshot, but only chosen groups, which is what we want at the final data dump -def convertPositionsSelected(snapshot,orderIndex,positions,indices): - from yt.lagos import mylog - - # loop over the selected groups - for index in indices: - group = snapshot[index] - center = group.maximum_density_location() - positions[orderIndex,index] = (center[0],center[1],center[2]) - - string = 'There are ' + str(len(indices)) +' groups in orderIndex ' + str(orderIndex) - mylog.info(string) - - return (positions) - - - -# this does three things: -# 1. Builds the links list, which contains the parentGroup.id and childGroup.id -# of the matched pair, along with the number of particles that are transferred. -# 2. Calculates what percentage of the parentGroup is transferred to the child -# groups. This is then subtracted from 100 to give how much of the group goes to -# the ether. -# 3. Similarly, calculates what percentage of the child group comes from the -# ether. -def buildLinks(parentGroups, childGroups,positions): - from yt.lagos import mylog - links = [] - childPercents = {} - - for parentGroup in parentGroups: - parentPercent = 0 - for childGroup in childGroups: - number = 0 # this will be the number of particles that go from the parent - # group to the child group. - # Below we calculate the distance between the groups, taking the periodic - # boundary conditions into account. - dist_x = abs(positions[parentGroup.orderIndex,parentGroup.id][0] - positions[childGroup.orderIndex,childGroup.id][0]) - if dist_x > 0.5: - dist_x = 1 - dist_x - dist_y = abs(positions[parentGroup.orderIndex,parentGroup.id][1] - positions[childGroup.orderIndex,childGroup.id][1]) - if dist_y > 0.5: - dist_y = 1 - dist_y - dist_z = abs(positions[parentGroup.orderIndex,parentGroup.id][2] - positions[childGroup.orderIndex,childGroup.id][2]) - if dist_z > 0.5: - dist_z = 1 - dist_z - dist = (dist_x**2 + dist_y**2 + dist_z**2)**0.5 - # If the childgroup isn't flagged, or if the two groups are too far away, - # the groups don't get checked; number stays equal to zero; and - # we move to the next parentgroup. - if (childGroup.flag == 1) and (dist <= 0.1): - string = 'checking parentGroup (' + str(len(parentGroup.particles)) + '): ' + str(parentGroup.orderIndex) + '.' + str(parentGroup.id) + \ - ' with childGroup (' + str(len(childGroup.particles)) + '): ' + str(childGroup.orderIndex) + '.' + str(childGroup.id) - mylog.info(string) - #number = parentGroup.isParent(childGroup) - number = pushListCount(parentGroup.particles,childGroup.particles) - #string = 'number: ' + str(number) - #mylog.info(string) - # create an entry in the childPercents dictionary if it's not already - # there - if childPercents.has_key(childGroup.id) != 1: - childPercents[childGroup.id] = 0 - - # If the number of particles from the parentgroup goes to the child group, - # above some threshold, add this link to the links list; calculate how much - # of the parent group went to the child group and add that to any existing total - # of particles leaving the parent group; add the particles going to the child - # group to it's percentage of particles not coming from the ether; and finally - # flag the parentgroup as part of the lineage for future checking. - if (number/float(len(parentGroup.particles)))*100 > 50: - links.append([parentGroup.id,childGroup.id,number]) - string = 'parentGroup: ' + str(parentGroup.orderIndex) + '.' + str(parentGroup.id) + \ - ' | childGroup: ' + str(childGroup.orderIndex) + '.' + str(childGroup.id) + \ - ' | %% transferred: %2.2f%%' % (number/float(len(parentGroup.particles)) * 100) - mylog.info(string) - parentPercent += (number/float(len(parentGroup.particles))*100) - childPercents[childGroup.id] += (number/float(len(childGroup.particles))*100) - parentGroup.flag = 1 - # End loop over childGroups. - # if any of the particles from the parent group went to a child group, - # change the parent groups toEther to reflect this. - if parentPercent > 0: - parentPercent = 100 - parentPercent - parentGroup.toEther = parentPercent - - # go over the childgroups and see how much of the particles came from - # the ether. - for childGroup in childGroups: - if childPercents[childGroup.id] > 0: - childPercents[childGroup.id] = 100 - childPercents[childGroup.id] - childGroup.fromEther = childPercents[childGroup.id] - - return (links,parentGroups,childGroups) - -# The functions below just write out simple blocks that GraphViz needs. -def writeTop(fopen): - - line = 'digraph galaxy {size="40,40";\n' - fopen.write(line) - -def writeClose(fopen): - - line = '};\n' - fopen.write(line) - -def writeOpen(fopen): - - line = '{\n' - fopen.write(line) - -def writeNode(fopen): - - line = 'node [color=lightblue, style=bold, shape=record];\n' - fopen.write(line) - -# In order to keep the boxes for the haloes on the same level, GraphViz needs -# to be told which boxes are all on the same level. -# Mar 2007, added lines for redshift levels. -def writeLevels(fopen, Groups, redshift): - - line = '{ rank = same;\n' - fopen.write(line) - - line = '"' + str(redshift) + '";' - fopen.write(line) - - for Group in Groups: - if (Group.toEther != 100) or (Group.fromEther != 100): - line = '"' + str(Group.orderIndex) + '.' + str(Group.id) + '";' - fopen.write(line) - - line = "\n};\n" - - fopen.write(line) - - -# Each box (node) has four bits of information: -# 1. For all but the top nodes, the percentage of the particles that come from -# the ether. -# 2. The number of particles in it. -# 3. The center of that group in (0,0,0)->(1,1,1) coordinates -# 4. The all but the bottom notes, the percentage of the particles that go to -# the ether. - -def writeLabels(fopen, Groups, gPositions, switch): - - # switch = 0: very top node, beginning of time - # switch = 1: intermediate node, many - # switch = 2: very bottom node, singular (usually), the last in time - - groupLength = len(Groups) - - if switch == 0: - for Group in Groups: - if (Group.toEther != 100) or (Group.fromEther != 100): - color = 1 - float(Group.id)/float(groupLength) - line = '"' + str(Group.orderIndex) + '.' + str(Group.id) + '" [label="{' + str(len(Group.particles)) - # write the position triplet for the group - line += '\\n(%1.3f,' % float(gPositions[Group.orderIndex,Group.id][0]) - line += '%1.3f,' % float(gPositions[Group.orderIndex,Group.id][1]) - line += '%1.3f)' % float(gPositions[Group.orderIndex,Group.id][2]) - line += '| %2.2f%%}", shape="record",' % Group.toEther - line += 'color="%1.3f ' % color - line += '1.0 %1.3f"];\n' % color - fopen.write(line) - - if switch == 1: - for Group in Groups: - if (Group.toEther != 100) or (Group.fromEther != 100): - color = 1 - float(Group.id)/float(groupLength) - line = '"' + str(Group.orderIndex) + '.' + str(Group.id) - line += '" [label="{%2.2f%%| {' % Group.fromEther - line += str(len(Group.particles)) - # write the position triplet for the group - line += '\\n(%1.3f,' % float(gPositions[Group.orderIndex,Group.id][0]) - line += '%1.3f,' % float(gPositions[Group.orderIndex,Group.id][1]) - line += '%1.3f)' % float(gPositions[Group.orderIndex,Group.id][2]) - line +='}|%2.2f%%}", shape="record"' % Group.toEther - line += ', color="%1.3f ' % color - line += '1.0 %1.3f"];\n' % color - fopen.write(line) - - if switch == 2: - for Group in Groups: - if (Group.toEther != 100) or (Group.fromEther != 100): - color = 1 - float(Group.id)/float(groupLength) - line = '"' + str(Group.orderIndex) + '.' + str(Group.id) - line += '" [label="{%2.2f%%|' % Group.fromEther - line += str(len(Group.particles)) - # write the position triplet for the group - line += '\\n(%1.3f,' % float(gPositions[Group.orderIndex,Group.id][0]) - line += '%1.3f,' % float(gPositions[Group.orderIndex,Group.id][1]) - line += '%1.3f)' % float(gPositions[Group.orderIndex,Group.id][2]) - line += '}", shape="record", color="%1.3f ' % color - line += '1.0 %1.3f"];\n' % color - fopen.write(line) - -# write out the GraphViz links that connect two groups. -def writeLinks(fopen, links, parentGroups, childGroups): - - for parentGroup in parentGroups: - for link in links: - if str(parentGroup.id) == str(link[0]): - line = '"' + str(parentGroup.orderIndex) + '.' + str(link[0]) + '"->"' + str(parentGroup.orderIndex+1) + '.' + str(link[1])+\ - '"[label="%2.2f%%",color="blue", fontsize=10];\n' % (link[2]/float(len(parentGroup.particles)) * 100) - fopen.write(line) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/NewHopOutput.py --- a/yt/lagos/hop/NewHopOutput.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,425 +0,0 @@ -""" -HOP-output data handling - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford - -Author: Stephen Skory -Affiliation: UC San Diego - -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Matthew Turk, Stephen Skory. 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 . -""" - -## -## This is a temporary file, modified by Stephen Skory, -## to start work toward supporting parallel HOP studies -## - -from yt.lagos.hop import * -from numpy import * - -class HopList(object): - def __init__(self, data_source, threshold=160.0, - dm_only = True): - """ - Run hop on *data_source* with a given density *threshold*. If - *dm_only* is set, only run it on the dark matter particles, otherwise - on all particles. Returns an iterable collection of *HopGroup* items. - """ - self.data_source = data_source - self.dm_only = dm_only - self.threshold = threshold - self._groups = [] - self._groups2 = {} - self._max_dens = {} - self._max_dens2 = {} - mylog.info("Initializing HOP") - self.__obtain_particles() - #self.__enlarge_data() - #self.__slice_data() - #self.__run_hops() - #self.__reduce_data() - self.__run_hop() - mylog.info("Parsing outputs") - #self.__parse_outputs() - self.__parse_output() - #self.__glue_outputs() - mylog.debug("Finished. (%s)", len(self)) - - def __obtain_particles(self): - if self.dm_only: ii = self.__get_dm_indices() - else: ii = slice(None) - self.particle_fields = {} - for field in ["particle_position_%s" % ax for ax in 'xyz'] + \ - ["ParticleMassMsun"]: - tot_part = self.data_source[field].size - self.particle_fields[field] = self.data_source[field][ii] - self._base_indices = na.arange(tot_part)[ii] - - def __enlarge_data(self): - """ - Take the data fields and reflect them around the sides of the - box, using periodicity. - """ - sizetemp = self.particle_fields["particle_position_x"].size - self.tempx = [i for i in range(3*sizetemp)] - self.tempy = [i for i in range(3*sizetemp)] - self.tempz = [i for i in range(3*sizetemp)] - self.tempm = [i for i in range(3*sizetemp)] - self.tracking = [i for i in range(3*sizetemp)] - # reverse below 0, straight up between 0 and 1, reverse above 1 - for part,i in enumerate(self.particle_fields["particle_position_x"]): - self.tempx[sizetemp - 1 - part] = -i - self.tempx[sizetemp + part] = i - self.tempx[3*sizetemp - 1 - part] = 2 - i - self.tracking[sizetemp - 1 - part] = part - self.tracking[sizetemp + part] = part - self.tracking[3*sizetemp - 1 - part] = part - for part,i in enumerate(self.particle_fields["particle_position_y"]): - self.tempy[sizetemp - 1 - part] = -i - self.tempy[sizetemp + part] = i - self.tempy[3*sizetemp - 1 - part] = 2 - i - for part,i in enumerate(self.particle_fields["particle_position_z"]): - self.tempz[sizetemp - 1 - part] = -i - self.tempz[sizetemp + part] = i - self.tempz[3*sizetemp - 1 - part] = 2 - i - for part,i in enumerate(self.particle_fields["ParticleMassMsun"]): - self.tempm[sizetemp - 1 - part] = i - self.tempm[sizetemp + part] = i - self.tempm[3*sizetemp -1 - part] = i - - def __slice_data(self): - """ - Cut up the particle data into subboxes, depending on *cuts* and the over-sampling - parameter *padding*. This also enlarges the box such that the particles run - from 0 to 1, which may not be neccesary. - """ - cuts = 3 - padding = 0.2 - self.temp2x = {} - self.temp2y = {} - self.temp2z = {} - self.temp2m = {} - self.tracking2 = {} - # loop over the sub-boxes - for i in range(cuts): - for j in range(cuts): - for k in range(cuts): - x_t = [] - y_t = [] - z_t = [] - m_t = [] - t_t = {} - # define the edges - xleft = (1.0 * i)/cuts - padding - xright = (1.0 * (i+1))/cuts + padding - yleft = (1.0 * j)/cuts - padding - yright = (1.0 * (j+1))/cuts + padding - zleft = (1.0 * k)/cuts - padding - zright = (1.0 * (k+1))/cuts + padding - # loop over the temporary expanded fields, test to see if they're in the sub-box - # and then re-map to a unit sized box, we'll have inclusive boundary on the left, - # exclusive on the right - jj = 0 - for part,ii in enumerate(self.tempx): - if ((ii >= xleft) and (ii < xright) and (self.tempy[part] >= yleft) and \ - (self.tempy[part] < yright) and (self.tempz[part] >= zleft) and \ - (self.tempz[part] < zright)): - x_t.append((ii-xleft)*(1.0/(xright-xleft))) - y_t.append((self.tempy[part]-yleft)*(1.0/(yright-yleft))) - z_t.append((self.tempz[part]-zleft)*(1.0/(zright-zleft))) - m_t.append(self.tempm[part]) - t_t[jj] = self.tracking[part] # put real ID in t_t at jj - jj += 1 - # save them to their position in the dict - self.temp2x[((i*cuts) + j)*cuts + k] = array(x_t) - self.temp2y[((i*cuts) + j)*cuts + k] = array(y_t) - self.temp2z[((i*cuts) + j)*cuts + k] = array(z_t) - self.temp2m[((i*cuts) + j)*cuts + k] = array(m_t) - self.tracking2[((i*cuts) + j)*cuts + k] = t_t - - def __reduce_data(self): - """ - Take the boxes after HOP has handled them and make them small, to their true size. - """ - cuts = 3 - padding = 0.2 - # loop over the sub-boxes - for i in range(cuts): - for j in range(cuts): - for k in range(cuts): - xleft = (1.0 * i)/cuts - padding - xright = (1.0 * (i+1))/cuts + padding - yleft = (1.0 * j)/cuts - padding - yright = (1.0 * (j+1))/cuts + padding - zleft = (1.0 * k)/cuts - padding - zright = (1.0 * (k+1))/cuts + padding - # we're going to reduce the values of the particles to their true position - # with some going negative, of course - self.temp2x[((i*cuts) + j)*cuts + k] = self.temp2x[((i*cuts) + j)*cuts + k]*(xright-xleft)+xleft - self.temp2y[((i*cuts) + j)*cuts + k] = self.temp2y[((i*cuts) + j)*cuts + k]*(yright-yleft)+yleft - self.temp2z[((i*cuts) + j)*cuts + k] = self.temp2z[((i*cuts) + j)*cuts + k]*(zright-zleft)+zleft - - def __run_hops(self): - """ - Run HOP on the different boxes. - """ - cuts = 3 - padding = 0.2 - nParts = self.particle_fields["particle_position_x"].size - dens_fix = 1. / (2*padding + 1./cuts)**3 - self.densities2 = {} - self.tags2 = {} - for i in range(cuts): - for j in range(cuts): - for k in range(cuts): - print "run_hops %d" % (((i*cuts) + j)*cuts + k) - size = float(self.temp2x[((i*cuts) + j)*cuts + k].size) - print "size %d" % size - self.densities2[((i*cuts) + j)*cuts + k], self.tags2[((i*cuts) + j)*cuts + k] = \ - RunHOP(self.temp2x[((i*cuts) + j)*cuts + k], - self.temp2y[((i*cuts) + j)*cuts + k], - self.temp2z[((i*cuts) + j)*cuts + k], - self.temp2m[((i*cuts) + j)*cuts + k], - self.threshold,size/nParts*dens_fix) - - def __run_hop(self): - self.densities, self.tags = \ - RunHOP(self.particle_fields["particle_position_x"], - self.particle_fields["particle_position_y"], - self.particle_fields["particle_position_z"], - self.particle_fields["ParticleMassMsun"], - self.threshold, 1.0) - self.particle_fields["densities"] = self.densities - self.particle_fields["tags"] = self.tags - - def __get_dm_indices(self): - if 'creation_time' in self.data_source.hierarchy.field_list: - mylog.debug("Differentiating based on creation time") - return (self.data_source["creation_time"] < 0) - elif 'particle_type' in self.data_source.hierarchy.field_list: - mylog.debug("Differentiating based on particle type") - return (self.data_source["particle_type"] == 1) - else: - mylog.warning("No particle_type, no creation_time, so not distinguishing.") - return slice(None) - - def __parse_outputs(self): - cuts = 3 - for i in range(cuts): - for j in range(cuts): - for k in range(cuts): - self._groups2[((i*cuts) + j)*cuts + k] = [] - self._max_dens2[((i*cuts) + j)*cuts + k] = [] - unique_ids = na.unique(self.tags2[((i*cuts) + j)*cuts + k]) - counts = na.bincount(self.tags2[((i*cuts) + j)*cuts + k]+1) - sort_indices = na.argsort(self.tags2[((i*cuts) + j)*cuts + k]) - grab_indices = na.indices(self.tags2[((i*cuts) + j)*cuts + k].shape).ravel()[sort_indices] - dens = self.densities2[((i*cuts) + j)*cuts + k][sort_indices] - cp = 0 - print 'uids %d' % (unique_ids.size) - for ii in unique_ids: - cp_c = cp + counts[ii+1] - if ii == -1: - cp += counts[ii+1] - continue - group_indices = grab_indices[cp:cp_c] - md_i = na.argmax(dens[cp:cp_c]) - px = self.temp2x[((i*cuts) + j)*cuts + k][group_indices] - py = self.temp2y[((i*cuts) + j)*cuts + k][group_indices] - pz = self.temp2z[((i*cuts) + j)*cuts + k][group_indices] - max_dens = (dens[cp:cp_c][md_i], px[md_i], py[md_i], pz[md_i]) - # as a shortcut, if the most dense particle is in the current box, we keep the group - if ((math.floor(max_dens[1]*cuts) == i) and (math.floor(max_dens[2]*cuts) == j) \ - and (math.floor(max_dens[3]*cuts) == k)): - # I think this will make the group_indices correct in the overall 'real' sense - temp_real_indices = arange(group_indices.size) - for gg,gi in enumerate(group_indices): - temp_real_indices[gg] = self.tracking2[((i*cuts) + j)*cuts + k][gi] - self._groups2[((i*cuts) + j)*cuts + k].append(HopGroup(self,ii, temp_real_indices)) - self._max_dens2[((i*cuts) + j)*cuts + k].append(max_dens) - cp += counts[ii+1] - for i in range(cuts**3): - print '%d groups2 %d' % (i,len(self._groups2[i])) - - def __glue_outputs(self): - cuts = 3 - ii = 0 - iii = 0 - for i in range(cuts): - for j in range(cuts): - for k in range(cuts): - print '%d len = %d' % (((i*cuts) + j)*cuts + k,len(self._groups2[((i*cuts) + j)*cuts + k])) - for group2 in self._groups2[((i*cuts) + j)*cuts + k]: - self._groups.append(HopGroup(self,iii,group2.indices)) - iii += 1 - for dens in self._max_dens2[((i*cuts) + j)*cuts + k]: - self._max_dens[ii] = dens - ii += 1 - - def __parse_output(self): - unique_ids = na.unique(self.tags) - counts = na.bincount(self.tags+1) - sort_indices = na.argsort(self.tags) - grab_indices = na.indices(self.tags.shape).ravel()[sort_indices] - dens = self.densities[sort_indices] - cp = 0 - for i in unique_ids: - cp_c = cp + counts[i+1] - if i == -1: - cp += counts[i+1] - continue - group_indices = grab_indices[cp:cp_c] - self._groups.append(HopGroup(self, i, group_indices)) - md_i = na.argmax(dens[cp:cp_c]) - px, py, pz = [self.particle_fields['particle_position_%s'%ax][group_indices] - for ax in 'xyz'] - self._max_dens[i] = (dens[cp:cp_c][md_i], - px[md_i], py[md_i], pz[md_i]) - cp += counts[i+1] - - def __len__(self): - return len(self._groups) - - def __iter__(self): - return HopIterator(self) - - def __getitem__(self, key): - return self._groups[key] - - def write_out(self, filename="HopAnalysis.out"): - """ - Write out standard HOP information to *filename*. - """ - f = open(filename,"w") - f.write("\t".join(["# Group","Mass","# part","max dens" - "x","y","z", "center-of-mass", - "x","y","z", - "vx","vy","vz","max_r","\n"])) - for group in self: - f.write("%10i\t" % group.id) - f.write("%0.9e\t" % group.total_mass()) - f.write("%10i\t" % group.indices.size) - f.write("%0.9e\t" % group.maximum_density()) - f.write("\t".join(["%0.9e" % v for v in group.maximum_density_location()])) - f.write("\t") - f.write("\t".join(["%0.9e" % v for v in group.center_of_mass()])) - f.write("\t") - f.write("\t".join(["%0.9e" % v for v in group.bulk_velocity()])) - f.write("\t") - f.write("%0.9e\t" % group.maximum_radius()) - f.write("\n") - f.close() - -class HopIterator(object): - def __init__(self, hop): - self.hop = hop - self.index = -1 - - def next(self): - self.index += 1 - if self.index == len(self.hop): raise StopIteration - return self.hop[self.index] - -class HopGroup(object): - """ - A data source that returns particle information about the members of a - HOP-identified halo. - """ - def __init__(self, hop_output, id, indices): - self.hop_output = hop_output - self.id = id - self.data = hop_output.data_source - self.indices = hop_output._base_indices[indices] - - def center_of_mass(self): - """ - Calculate and return the center of mass. - """ - c_vec = self.maximum_density_location() - na.array([0.5,0.5,0.5]) - pm = self["ParticleMassMsun"] - cx = (self["particle_position_x"] - c_vec[0]) - cy = (self["particle_position_y"] - c_vec[1]) - cz = (self["particle_position_z"] - c_vec[2]) - com = na.array([v-na.floor(v) for v in [cx,cy,cz]]) - return (com*pm).sum(axis=1)/pm.sum() + c_vec - - def maximum_density(self): - """ - Return the HOP-identified maximum density. - """ - return self.hop_output._max_dens[self.id][0] - - def maximum_density_location(self): - """ - Return the location HOP identified as maximally dense. - """ - return na.array([ - self.hop_output._max_dens[self.id][1], - self.hop_output._max_dens[self.id][2], - self.hop_output._max_dens[self.id][3]]) - - def total_mass(self): - """ - Returns the total mass in solar masses of the halo. - """ - return self["ParticleMassMsun"].sum() - - def bulk_velocity(self): - """ - Returns the mass-weighted average velocity. - """ - pm = self["ParticleMassMsun"] - vx = (self["particle_velocity_x"] * pm).sum() - vy = (self["particle_velocity_y"] * pm).sum() - vz = (self["particle_velocity_z"] * pm).sum() - return na.array([vx,vy,vz])/pm.sum() - - def maximum_radius(self, center_of_mass=True): - """ - Returns the maximum radius in the halo for all particles, - either from the point of maximum density or from the (default) - *center_of_mass*. - """ - if center_of_mass: center = self.center_of_mass() - else: center = self.maximum_density_location() - rx = na.abs(self["particle_position_x"]-center[0]) - ry = na.abs(self["particle_position_y"]-center[1]) - rz = na.abs(self["particle_position_z"]-center[2]) - r = na.sqrt(na.minimum(rx, 1.0-rx)**2.0 - + na.minimum(ry, 1.0-ry)**2.0 - + na.minimum(rz, 1.0-rz)**2.0) - return r.max() - - def __getitem__(self, key): - return self.data[key][self.indices] - - def get_sphere(self, center_of_mass=True): - """ - Returns an EnzoSphere centered on either the point of maximum density - or the *center_of_mass*, with the maximum radius of the halo. - """ - if center_of_mass: center = self.center_of_mass() - else: center = self.maximum_density_location() - radius = self.maximum_radius() - # A bit of a long-reach here... - sphere = self.hop_output.data_source.hierarchy.sphere( - center, radius=radius) - return sphere diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/README --- a/yt/lagos/hop/README Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -Matthew Turk -May 2008 - -This code (described below) has been modified to be wrapped as a shared library -callable from Python, as a part of the yt toolkit. - -Stephen Skory -May/June 2007 - -This is a new implementation of hop for enzo datasets, to replace the -fragile 'enzohop.' enzohop uses the enzo grid functionality to extract -the particle data from the HDF5 datasets. newhop uses plain HDF5 C++ calls -to extract the data, which is then fed into the hop mechanism. As far as I -know, this version is fine with 64 bit integers/floats, which enzohop isn't. - -There are a few versions of newhop which build on datastar just fine. I -haven't tested it on other machines. The default build 'newhop' is for -packed datasets and will include both stars and dm in the grouping. -THe other versions are for non-packed datasets, or if you want to only -consider dm particles for grouping. Hop doesn't like datasets with too -many particles, (I've never done tests, but I know that 20 million -particles give hop problems) so sometimes dm-only is the only way to go. diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/__init__.py --- a/yt/lagos/hop/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -from yt.lagos import * - -from EnzoHop import * -from Merger import * diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/hop.h --- a/yt/lagos/hop/hop.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#include "slice.h" -//#define free(A) if(A==NULL)fprintf(stderr,"FREEING DOUBLE\n");fprintf(stderr,"Freeing "#A" ("__FILE__":%d)\n",__LINE__);free(A); - -/* ----------------------------------------------------------------------- */ -/* The following structures track all the information about the groups */ - -typedef struct groupstruct { - int npart; /* Number of particles in the group */ - int npartcum; /* Cumulative number of particles */ - int nread; /* Number read so far, also a utility field */ - double compos[3], comvel[3];/* Lists of group CoM position and velocities */ - double comtemp[3]; /* Temporary CoM position */ - int idmerge; /* The new group ID # after merging. Not necessarily - unique! */ - int rootgroup; /* The fully traced group id */ -} Group; /* Type Group is defined */ - -typedef struct groupliststruct { - int npart; /* Number of particles in the simulation */ - int ngroups; /* Number of groups in list */ - int nnewgroups; /* Number of groups after relabeling */ - int npartingroups; /* Number of particles in groups */ - Group *list; /* List of groups, zero-offset */ -} Grouplist; /* Type Grouplist is defined */ - - -typedef struct hopComm { - int ngroups; - int nb; - float *gdensity; - float *g1vec; - float *g2vec; - float *fdensity; - Grouplist *gl; - Slice *s; -} HC; diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/hop_hop.c --- a/yt/lagos/hop/hop_hop.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,940 +0,0 @@ -/* HOP.C -- Daniel Eisenstein, 1997 -Based on a paper by Daniel Eisenstein & Piet Hut, -"HOP: A New Group-Finding Algorithm for N-body Simulations." -See the included documentation or view it at -http://www.sns.ias.edu/~eisenste/hop/hop_doc.html */ - -/* main() was customized from that of SMOOTH v2.0.1, by Joachim Stadel - and the NASA HPCC ESS at the University of Washington Dept. of Astronomy. */ -/* PrepareKD() is a code fragment from the same program. */ -/* ssort() is a C-translation of the Slatec FORTRAN routine of - R.E. Jones and J.A. Wisniewski (SNLA) */ -/* The other routines were written by DJE. */ - -/* Version 1.0 (12/15/97) -- Original Release */ - -#include -#include -#include -#include -#include -#include -#include "kd.h" -#include "hop.h" -#include "smooth.h" -#include "hop_numpy.h" - -//#include "macros_and_parameters.h" -#define ISYM "d" -#define GSYM "g" -#define FSYM "f" - -/* To give info to the user: INFORM("info"); */ -#define INFORM(string) printf(string); fflush(stdout) - -int SnapNumber; - -int ReadSimulationFile(KD, FILE *); - -void smDensityTH(SMX smx,int pi,int nSmooth,int *pList,float *fList); - -void smHop(SMX smx,int pi,int nSmooth,int *pList,float *fList); -void FindGroups(SMX smx); -void SortGroups(SMX smx); - -void MergeGroupsHash(SMX smx); -void smMergeHash(SMX smx,int pi,int nSmooth,int *pList,float *fList); -void ReSizeSMX(SMX smx, int nSmooth); - -void PrepareKD(KD kd); -void binOutHop(SMX smx, HC *my_comm, float densthres); -void outGroupMerge(SMX smx, HC *my_comm); - -/* void main(int argc,char **argv) */ -void hop_main(KD kd, HC *my_comm, float densthres) -{ - /* KD kd; */ - SMX smx; - int nBucket,nSmooth,i,j; - FILE *fp, *fpb; - char ach[80],achFile[80], *inputfile, *densfile; - float fPeriod[3]; - int bDensity,bGroup,bSym,bMerge,nDens,nHop,nMerge,bTopHat; - float fDensThresh; - - nBucket = 16; - nSmooth = 64; - nDens = 64; - nHop = -1; -/* fDensThresh = 3.0; */ - fDensThresh = -1.0; - bDensity = 3; - bGroup = 3; - bMerge = 3; - bSym = 1; - bTopHat = 0; - strcpy(achFile,"output_hop"); - inputfile = NULL; - i = 1; -/* for (j=0;j<3;++j) fPeriod[j] = HUGE; */ - for (j=0;j<3;++j) fPeriod[j] = 1.0; - nMerge = 4; - - - if (nHop<0) nHop=nDens; - if (bDensity==0) nSmooth = nHop+1; - else nSmooth = nDens+1; - /* When smSmooth() is asked for nSmooth particles, it seems to - generally return nSmooth-1 particles, including primary itself. - Hence, when we want nDens or nSmooth particles (including the - primary) we should ask for one more. By convention, I've chosen - to have nMerge reflect the number *not* including the primary, - so in this case we need to ask for two more! */ - - assert(!bMerge || nMergenHop = nHop; - smx->nDens = nDens; - smx->nMerge = nMerge; - smx->nGroups = 0; - smx->fDensThresh = fDensThresh; - - INFORM("Building Tree...\n"); - kdBuildTree(kd); - - if (bDensity) { - INFORM("Finding Densities...\n"); - if (bTopHat) smSmooth(smx,smDensityTH); - else if (bSym) smSmooth(smx,smDensitySym); - else smSmooth(smx,smDensity); - } /* Else, we've read them */ - if (bGroup) { - INFORM("Finding Densest Neighbors...\n"); - if (bDensity && nHop=nSmooth) { - nSmooth = nHop+1; - ReSizeSMX(smx,nSmooth); - } - smSmooth(smx,smHop); - } - } - - INFORM("Grouping...\n"); - if (bGroup) FindGroups(smx); - if (bGroup) SortGroups(smx); - - if (bMerge) { - INFORM("Merging Groups...\n"); - MergeGroupsHash(smx); - } - - kdOrder(kd); - INFORM("Writing Output...\n"); - - if (bMerge&2) { - smx->nSmooth=nSmooth; /* Restore this for output */ - outGroupMerge(smx, my_comm); - } - if (bMerge) free(smx->hash); - - if (bGroup&2) { - binOutHop(smx, my_comm, densthres); - } - if (bGroup) {free(smx->densestingroup); free(smx->nmembers);} - smFinish(smx); - //kdFinish(kd); - INFORM("All Done!"); - return; -} - - -/* ============================================================= */ -/* ===================== New Density Routine =================== */ -/* ============================================================= */ - -void smDensityTH(SMX smx,int pi,int nSmooth,int *pList,float *fList) -/* Find density only using top-hat kernal. */ -{ -#ifdef DIFFERENT_MASSES - int j; - float totalmass; - for (j=0,totalmass=0.0; jkd, pList[j]); - NP_DENS(smx->kd, pi) = totalmass*0.75*M_1_PI/ - smx->pfBall2[pi]/sqrt(smx->pfBall2[pi]); -#else - /* This case is simple: the total mass is nSmooth times the mass - per particle */ - NP_DENS(smx->kd, pi) = (nSmooth)*smx->kd->fMass*0.75*M_1_PI/ - smx->pfBall2[pi]/sqrt(smx->pfBall2[pi]); -#endif - return; -} - -/* ============================================================= */ -/* ================== Hop to Neighbors/Form Groups ============= */ -/* ============================================================= */ - -void smHop(SMX smx,int pi,int nSmooth,int *pList,float *fList) -/* Look at the nHop nearest particles and find the one with the -highest density. Store its ID number in iHop as -1-ID (to make it negative) */ -/* nSmooth tends to be the expected value (smx->nSmooth-1) but can vary plus -or minus 1 (at least). */ -/* If Merging is turned off, nMerge should be huge so as to avoid extra -sorting below */ -{ - int i,max, search, didsort; - float maxden; - void ssort(float X[], int Y[], int N, int KFLAG); - - /* If the density is less than the threshold requirement, then assign 0 */ - if (NP_DENS(smx->kd, pi)fDensThresh) { - smx->kd->p[pi].iHop = 0; - return; - } - - /* If we have exactly the right number, then it doesn't matter how - we search them. Otherwise, we need to sort first. */ - /* We can destroy pList and fList if we want. fList holds the square radii*/ - - search = smx->nHop; - if (smx->nHop>nSmooth) search = nSmooth; /* Very rare exception */ - - if (smx->nHopnMerge+2kd, pList[i])>maxden) { - max = i; - maxden = NP_DENS(smx->kd, pList[i]); - } - } - smx->kd->p[pi].iHop = -1-pList[max]; - - /* check to see if the particle we link to doesn't link back - to ourselves, pi. If it does, connect this particle (pi) to itself. - This can only happen if pList[max] < pi*/ - if (pList[max] < pi) { - if (smx->kd->p[pList[max]].iHop == -1-pi) { - smx->kd->p[pi].iHop = -1-pi; - } - } - - /* If a sort was done, then we can save time in the Merge step by - recording the new Ball radius. */ - /* Place the new radius in between the two boundary because occasionally - the floating point math comes out strange when comparing two floats */ - if (didsort && smx->nMerge+2pfBall2[pi] = 0.5*(fList[smx->nMerge+1]+fList[smx->nMerge]); - return; -} - -/* ----------------------------------------------------------------- */ - -void FindGroups(SMX smx) -/* Number the maxima. Trace each particle uphill to a maximum. */ -/* The local maxima were stored as in iHop as -1-ID (negative numbers); -now we will store group number as positive numbers (1..n) in the same spot */ -/* Zero is left as an error condition */ -/* The particles MUST be left in the BuildTree order, for that is how the -iHop tracing is done */ -/* Allocate space for densestingroup, from 0 to nGroups -(inclusive) and store the particle number of the maxima, which is the -densest particle in the group. Ditto for nmembers[], the number of -particles in the group */ -{ - int j, ng, current, localmax; - PARTICLE *p; - - smx->nGroups = 0; - /* First look for maxima, where particle ID = iHop. Number the groups */ - for (j=0, p=smx->kd->p;jkd->nActive;j++,p++) - if (p->iHop == -1-j) { /* Was p->iOrder */ - /* Yes, it's a maximum */ - smx->nGroups++; - /* p->iHop = smx->nGroups; */ - } - - /* Now catalog the maxima, before numbering the groups */ - smx->densestingroup = (int *)malloc((size_t)((smx->nGroups+1)*sizeof(int))); - assert(smx->densestingroup!=NULL); - smx->nmembers = (int *)malloc((size_t)(sizeof(int)*(smx->nGroups+1))); - assert(smx->nmembers!=NULL); - - ng = 0; - for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) - if (p->iHop== -1-j) { - /* It's a maximum */ - ng++; - smx->densestingroup[ng] = p->iOrder; - p->iHop = ng; - } - - /* Now take the remaining particles and trace up to a maximum */ - for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) { - if (p->iHop>=0) continue; /* It's a maximum or an error */ - localmax = -1-p->iHop; - while (smx->kd->p[localmax].iHop<0) - localmax = -1-smx->kd->p[localmax].iHop; - ng = smx->kd->p[localmax].iHop; - /* Now assign this group number to the whole lineage! */ - /* Note that errors (iHop=0) will propagate */ - current = -1-p->iHop; - p->iHop = ng; - while (smx->kd->p[current].iHop<0) { - localmax = -1-smx->kd->p[current].iHop; - smx->kd->p[current].iHop = ng; - current = localmax; - } - } - return; -} - -/* ----------------------------------------------------------------- */ - -void SortGroups(SMX smx) -/* Renumber the groups in order of number of members. */ -/* Move the group numbering from unit offset to zero offset */ -/* Move error condition (group=0) to (group=-1) */ -/* Store the number of members and most dense particle in each group */ -{ - int j, *indx, *irank, *ip; - PARTICLE *p; - void make_rank_table(int n, int *ivect, int *rank); - - indx = (int *)malloc((size_t)(sizeof(int)*(smx->nGroups+1))); - assert(indx!=NULL); - irank = (int *)malloc((size_t)(sizeof(int)*(smx->nGroups+1))); - assert(irank!=NULL); - - /* Count the number of members in each group */ - for (j=0;j<=smx->nGroups;j++) smx->nmembers[j]=0; - for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) - smx->nmembers[p->iHop]++; - - make_rank_table(smx->nGroups, smx->nmembers,irank); - - for (j=1;j<=smx->nGroups;j++) irank[j] = smx->nGroups-irank[j]; - irank[0] = -1; /* Move old 0's to new -1's */ - /* irank[j] is the new group number of group j: zero-offset, ordered - large to small */ - - /* Relabel all the particles */ - for (j=0,p=smx->kd->p;jkd->nActive;j++,p++) - p->iHop = irank[p->iHop]; - - /* Sort the nmembers and densestingroup lists to reflect the new ordering */ - /* Use indx as a temp space */ - for (j=1;j<=smx->nGroups;j++) indx[irank[j]]=smx->densestingroup[j]; - ip = smx->densestingroup; - smx->densestingroup = indx; - indx = ip; - /* Number of error (old_group=0) is in nmembers[0]; move it to [nGroups] */ - for (j=1;j<=smx->nGroups;j++) indx[irank[j]]=smx->nmembers[j]; - indx[smx->nGroups]=smx->nmembers[0]; - free(smx->nmembers); - smx->nmembers = indx; - - free(irank); - /* Note that the memory allocated to indx is now used by smx->densestingroup - and so it should not be free'd. */ - return; -} - -/* ================================================================== */ -/* ========================== Group Merging ========================= */ -/* ================================================================== */ - -void MergeGroupsHash(SMX smx) -/* We're going to look through the particles looking for boundary particles, -defined as particles with close neighbors of a different group, and store -the most dense boundary point (average of the two points) */ -/* The matrix of boundaries is stored in a hash table */ -/* SortGroups() should be called previous to this, so that all the -particles are in the assumed group numbering, i.e. 0 to ngroup-1, with --1 being unattached. The tags are not altered */ -/* In smHop, if nMerge+2 was smaller than nSmooth, we set the new radius -for searching. If not, we left the old radius alone. Either way, we're -ready to go. */ -{ - int j, k, g, next, newgroup; - - ReSizeSMX(smx, smx->nMerge+2); /* Alter the smoothing scale on smx */ - smx->nHashLength = smx->nGroups*10+1; - smx->hash = (Boundary *)malloc(smx->nHashLength*sizeof(Boundary)); - assert(smx->hash!=NULL); - for (j=0;jnHashLength;j++) { - smx->hash[j].nGroup1 = -1; - smx->hash[j].nGroup2 = -1; - smx->hash[j].fDensity = -1.0; - } /* Mark the slot as unused */ - - smReSmooth(smx,smMergeHash); /* Record all the boundary particles */ - return; -} - -/* ----------------------------------------------------------------- */ - -void smMergeHash(SMX smx,int pi,int nSmooth,int *pList,float *fList) -/* Look at the list for groups which are not that of the particle */ -/* If found, and if density is high enough, then mark it as a boundary */ -/* by recording it in the hash table */ -{ - int j,group; - float averdensity; - int g1,g2,count; - unsigned long hashpoint; - Boundary *hp; - int search; - void ssort(float X[], int Y[], int N, int KFLAG); - - group = smx->kd->p[pi].iHop; - if (group==(-1)) return; /* This particle isn't in a group */ - - /* It seems that BallGather doesn't always get the right number of - particles....*/ - search = nSmooth; - if (nSmooth>smx->nMerge+1) { - ssort(fList-1,pList-1,nSmooth,2); - search = smx->nMerge+1; - } - for (j=0;jkd->p[pList[j]].iHop; - if (g2==-1 || g2==group) continue; /* Same group or unassigned */ - /* It's in a different group; we need to connect the two */ - if (groupkd, pi) + - NP_DENS(smx->kd, pList[j])); - hashpoint = (g1+1)*g2; /* Avoid multiplying by 0 */ - hashpoint = hashpoint % smx->nHashLength; - hp = smx->hash+hashpoint; - count = 0; - for (;;) { - if (hp->nGroup1==(-1)) { /* Empty slot */ - hp->nGroup1 = g1; - hp->nGroup2 = g2; - hp->fDensity = averdensity; - break; - } - if (hp->nGroup1==g1 && hp->nGroup2==g2) { - /* We've seen this pair of groups before */ - if (hp->fDensity > averdensity) break; - else { - hp->fDensity = averdensity; - break; - } - } - /* Else, this slot was full, go to the next one */ - hp++; - if (hp>=smx->hash+smx->nHashLength) hp = smx->hash; - if (++count>1000) { - fprintf(stderr,"Hash Table is too full.\n"); - exit(1); - } - } - /* Look at the next particle */ - } - return; -} - - -/* ----------------------------------------------------------------- */ - -void ReSizeSMX(SMX smx, int nSmooth) -/* Set a new smoothing length, resizing the arrays which depend on this, -but leaving the particle information intact. */ -/* However, because we won't always have resized pfBall2 (the search -radius) correctly, we won't reduce the size of the fList and pList -arrays */ -{ - PQ_STATIC; - if (nSmooth>smx->nSmooth) { /* We're increasing the size */ - smx->nListSize = nSmooth+RESMOOTH_SAFE; - free(smx->fList); - smx->fList = (float *)malloc(smx->nListSize*sizeof(float)); - assert(smx->fList != NULL); - free(smx->pList); - smx->pList = (int *)malloc(smx->nListSize*sizeof(int)); - assert(smx->pList != NULL); - } - smx->nSmooth=nSmooth; - free(smx->pq); - smx->pq = (PQ *)malloc(nSmooth*sizeof(PQ)); - assert(smx->pq != NULL); - PQ_INIT(smx->pq,nSmooth); - return; -} - -/* ===================================================================== */ -/* ===================== Input/Output, Binary and ASCII ================ */ -/* ===================================================================== */ - -void PrepareKD(KD kd) -/* This labels all the particles and finds the min/max of the positions */ -/* It used to appear in kd.c within kdReadTipsy(), but it seems so general -that I'll spare the user the trouble of including it in any custom input -routines */ -{ - BND bnd; - int i, j; - - /* Label the particles, so that we can restore the order at the end */ - for (i=0;inActive;i++) { - kd->p[i].iOrder=i; - } - /* - ** Calculate Bounds. - */ - for (j=0;j<3;++j) { - bnd.fMin[j] = NP_POS(kd, 0, j); - bnd.fMax[j] = NP_POS(kd, 0, j); - } - for (i=1;inActive;++i) { - for (j=0;j<3;++j) { - if (bnd.fMin[j] > NP_POS(kd, i, j)) - bnd.fMin[j] = NP_POS(kd, i, j); - else if (bnd.fMax[j] < NP_POS(kd, i, j)) - bnd.fMax[j] = NP_POS(kd, i, j); - } - } - kd->bnd = bnd; - return; -} - -void binOutHop(SMX smx, HC *my_comm, float densthres) -/* Write Group tag for each particle. Particles should be ordered. */ -/* Binary file: nActive, nGroups, list of Groups */ -{ - int j,dummy; - /* FILE *blahfp = fopen("Part-PreMergeGroup.txt","w"); *//* S Skory */ - Grouplist *g = my_comm->gl; - Slice *s = my_comm->s; - - g->npart = s->numlist = s->numpart = smx->kd->nActive; - g->ngroups = smx->nGroups; - s->ntag = ivector(1,s->numlist); - //s->ID = ivector(1,s->numlist); - for (j=0;jkd->nActive;j++) { - //s->ID[1+j] = smx->kd->p[j].iID; /* S Skory's addition */ - if (NP_DENS(smx->kd,j) < densthres) s->ntag[j+1] = -1; - else s->ntag[j+1] = smx->kd->p[j].iHop; - - } - - /* Here I'm going to add on the end of the file the real particle IDs for all the particles - added above, in the same order as above. S Skory */ - return; -} - -/* ----------------------------------------------------------------- */ - -void outGroupMerge(SMX smx, HC *my_comm) -/* Write an ASCII file with information on the groups and group merging */ -/* Start the boundary list with the only ### line */ -/* Groups should be ordered before calling this (else densities will be wrong)*/ -{ - int j, den; - Boundary *hp; - - my_comm->gdensity = vector(0,smx->nGroups-1); - for (j=0;jnGroups;j++) { - den = smx->densestingroup[j]; - my_comm->gdensity[j]=NP_DENS(smx->kd, den); - } - int nb = 0; - for (j=0, hp=smx->hash;jnHashLength; j++,hp++) - if (hp->nGroup1>=0)nb++; - my_comm->ngroups = smx->nGroups; - my_comm->nb = nb; - my_comm->g1vec = vector(0,nb); - my_comm->g2vec = vector(0,nb); - my_comm->fdensity = vector(0,smx->nHashLength); - nb = 0; - for (j=0, hp=smx->hash;jnHashLength; j++,hp++) - if (hp->nGroup1>=0){ - my_comm->g1vec[nb] = hp->nGroup1; - my_comm->g2vec[nb] = hp->nGroup2; - my_comm->fdensity[nb++] = hp->fDensity; - } - return; -} - - -/* ================================================================== */ -/* ======================= Sorting ================================== */ -/* ================================================================== */ - -typedef struct index_struct { - float value; - int index; -} *ptrindex; - -int cmp_index(const void *a, const void *b) -{ - if ( ((ptrindex)a)->value<((ptrindex)b)->value) return -1; - else if ( ((ptrindex)a)->value>((ptrindex)b)->value) return 1; - else return 0; -} - -void make_rank_table(int n, int *ivect, int *rank) -/* Given a vector of integers ivect[1..n], construct a rank table rank[1..n] -so that rank[j] contains the ordering of element j, with rank[j]=n indicating -that the jth element was the highest, and rank[j]=1 indicating that it -was the lowest. Storage for rank[] should be declared externally */ -/* I don't think this routine is particularly fast, but it's a -miniscule fraction of the runtime */ -{ - int j; - ptrindex sortvect; - - sortvect = (ptrindex)malloc(n*sizeof(struct index_struct)); - for (j=0;j T) { - X[IJ] = X[I]; - X[I] = T; - T = X[IJ]; - } - L = J; - - /* If last element of array is less than than T, interchange with T */ - - if (X[J] < T) { - X[IJ] = X[J]; - X[J] = T; - T = X[IJ]; - - /* If first element of array is greater than T, interchange with T */ - - if (X[I] > T) { - X[IJ] = X[I]; - X[I] = T; - T = X[IJ]; - } - } - - /* Find an element in the second half of the array which is smaller */ - /* than T */ - -line40: L = L-1; - if (X[L] > T) goto line40; - - /* Find an element in the first half of the array which is greater */ - /* than T */ - -line50: K = K+1; - if (X[K] < T) goto line50; - - /* Interchange these elements */ - - if (K <= L) { - TT = X[L]; - X[L] = X[K]; - X[K] = TT; - goto line40; - } - - /* Save upper and lower subscripts of the array yet to be sorted */ - - if (L-I > J-K) { - IL[M] = I; - IU[M] = L; - I = K; - M = M+1; - } else { - IL[M] = K; - IU[M] = J; - J = L; - M = M+1; - } - goto line70; - - /* Begin again on another portion of the unsorted array */ - -line60: M = M-1; - if (M == 0) goto line190; - I = IL[M]; - J = IU[M]; - -line70: if (J-I >= 1) goto line30; - if (I == 1) goto line20; - I = I-1; - -line80: I = I+1; - if (I == J) goto line60; - T = X[I+1]; - if (X[I] <= T) goto line80; - K = I; - -line90: X[K+1] = X[K]; - K = K-1; - if (T < X[K]) goto line90; - X[K+1] = T; - goto line80; - - /* Sort X and carry Y along */ - -line100: M = 1; - I = 1; - J = NN; - R = 0.375E0; - -line110: if (I == J) goto line150; - if (R <= 0.5898437E0) - R = R+3.90625E-2; - else R = R-0.21875E0; - -line120: K = I; - - /* Select a central element of the array and save it in location T */ - - IJ = I + (int)((J-I)*R); - T = X[IJ]; - TY = Y[IJ]; - - /* If first element of array is greater than T, interchange with T */ - - if (X[I] > T) { - X[IJ] = X[I]; - X[I] = T; - T = X[IJ]; - Y[IJ] = Y[I]; - Y[I] = TY; - TY = Y[IJ]; - } - L = J; -; - /* If last element of array is less than T, interchange with T */ - - if (X[J] < T) { - X[IJ] = X[J]; - X[J] = T; - T = X[IJ]; - Y[IJ] = Y[J]; - Y[J] = TY; - TY = Y[IJ]; - - /* If first element of array is greater than T, interchange with T */ - - if (X[I] > T) { - X[IJ] = X[I]; - X[I] = T; - T = X[IJ]; - Y[IJ] = Y[I]; - Y[I] = TY; - TY = Y[IJ]; - } - } - - /* Find an element in the second half of the array which is smaller */ - /* than T */ - -line130: L = L-1; - if (X[L] > T) goto line130; - - /* Find an element in the first half of the array which is greater */ - /* than T */ - -line140: K = K+1; - if (X[K] < T) goto line140; - - /* Interchange these elements */ - - if (K <= L) { - TT = X[L]; - X[L] = X[K]; - X[K] = TT; - TTY = Y[L]; - Y[L] = Y[K]; - Y[K] = TTY; - goto line130; - } - - /* Save upper and lower subscripts of the array yet to be sorted */ - - if (L-I > J-K) { - IL[M] = I; - IU[M] = L; - I = K; - M = M+1; - } else { - IL[M] = K; - IU[M] = J; - J = L; - M = M+1; - } - goto line160; - - /* Begin again on another portion of the unsorted array */ - -line150: M = M-1; - if (M == 0) goto line190; - I = IL[M]; - J = IU[M]; - -line160: if (J-I >= 1) goto line120; - if (I == 1) goto line110; - I = I-1; - -line170: I = I+1; - if (I == J) goto line150; - T = X[I+1]; - TY = Y[I+1]; - if (X[I] <= T) goto line170; - K = I; - -line180: X[K+1] = X[K]; - Y[K+1] = Y[K]; - K = K-1; - if (T < X[K]) goto line180; - X[K+1] = T; - Y[K+1] = TY; - goto line170; - - /* Clean up */ - -line190: if (KFLAG <= -1) - for (I=1; I<=NN; I++) - X[I] = -X[I]; - - return; -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/hop_kd.c --- a/yt/lagos/hop/hop_kd.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ -/* KD.C */ -/* This was written by Joachim Stadel and the NASA HPCC ESS at -the University of Washington Department of Astronomy as part of -the SMOOTH program, v2.0.1. -URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ - -/* DJE--I have removed all the subroutines not used by HOP, notably -the input and output routines. */ - -/* HOP Version 1.0 (12/15/97) -- Original Release */ - -#include -#include -#include -#include -#include -#include -#include "kd.h" -#include "hop_numpy.h" -//#include "macros_and_parameters.h" -/* #include "tipsydefs.h" */ /* Don't need this, since I removed kdReadTipsy()*/ - - -#define MAX_ROOT_ITTR 32 - - -void kdTime(KD kd,int *puSecond,int *puMicro) -{ - struct rusage ru; - - getrusage(0,&ru); - *puMicro = ru.ru_utime.tv_usec - kd->uMicro; - *puSecond = ru.ru_utime.tv_sec - kd->uSecond; - if (*puMicro < 0) { - *puMicro += 1000000; - *puSecond -= 1; - } - kd->uSecond = ru.ru_utime.tv_sec; - kd->uMicro = ru.ru_utime.tv_usec; - } - - -int kdInit(KD *pkd,int nBucket) -{ - KD kd; - - kd = (KD)malloc(sizeof(struct kdContext)); - assert(kd != NULL); - kd->nBucket = nBucket; - kd->kdNodes = NULL; - *pkd = kd; - return(1); - } - -/* - ** JST's Median Algorithm - */ -int kdMedianJst(KD kd,int d,int l,int u) -{ - npy_float64 fm; - int i,k,m; - PARTICLE *p,t; - - p = kd->p; - k = (l+u)/2; - m = k; - while (l < u) { - m = (l+u)/2; - fm = NP_POS(kd, m, d); - t = p[m]; - p[m] = p[u]; - p[u] = t; - i = u-1; - m = l; - while (NP_POS(kd, m, d) < fm) ++m; - while (m < i) { - while (NP_POS(kd, i, d) >= fm) if (--i == m) break; - /* - ** Swap - */ - t = p[m]; - p[m] = p[i]; - p[i] = t; - --i; - while (NP_POS(kd, m, d) < fm) ++m; - } - t = p[m]; - p[m] = p[u]; - p[u] = t; - if (k <= m) u = m-1; - if (k >= m) l = m+1; - } - return(m); - } - - -void kdCombine(KDN *p1,KDN *p2,KDN *pOut) -{ - int j; - - /* - ** Combine the bounds. - */ - for (j=0;j<3;++j) { - if (p2->bnd.fMin[j] < p1->bnd.fMin[j]) - pOut->bnd.fMin[j] = p2->bnd.fMin[j]; - else - pOut->bnd.fMin[j] = p1->bnd.fMin[j]; - if (p2->bnd.fMax[j] > p1->bnd.fMax[j]) - pOut->bnd.fMax[j] = p2->bnd.fMax[j]; - else - pOut->bnd.fMax[j] = p1->bnd.fMax[j]; - } - } - - -void kdUpPass(KD kd,int iCell) -{ - KDN *c; - int l,u,pj,j; - - c = kd->kdNodes; - if (c[iCell].iDim != -1) { - l = LOWER(iCell); - u = UPPER(iCell); - kdUpPass(kd,l); - kdUpPass(kd,u); - kdCombine(&c[l],&c[u],&c[iCell]); - } - else { - l = c[iCell].pLower; - u = c[iCell].pUpper; - for (j=0;j<3;++j) { - c[iCell].bnd.fMin[j] = NP_POS(kd, u, j); - c[iCell].bnd.fMax[j] = NP_POS(kd, u, j); - } - for (pj=l;pj c[iCell].bnd.fMax[j]) - c[iCell].bnd.fMax[j] = NP_POS(kd, pj, j); - } - } - } - } - -int kdBuildTree(KD kd) -{ - int l,n,i,d,m,j,ct; - KDN *c; - - n = kd->nActive; - kd->nLevels = 1; - l = 1; - while (n > kd->nBucket) { - n = n>>1; - l = l<<1; - ++kd->nLevels; - } - kd->nSplit = l; - kd->nNodes = l<<1; - kd->kdNodes = (KDN *)malloc(kd->nNodes*sizeof(KDN)); - assert(kd->kdNodes != NULL); - /* - ** Set up ROOT node - */ - c = kd->kdNodes; - c[ROOT].pLower = 0; - c[ROOT].pUpper = kd->nActive-1; - c[ROOT].bnd = kd->bnd; - i = ROOT; - ct = ROOT; - SETNEXT(ct); - while (1) { - if (i < kd->nSplit) { - d = 0; - for (j=1;j<3;++j) { - if (c[i].bnd.fMax[j]-c[i].bnd.fMin[j] > - c[i].bnd.fMax[d]-c[i].bnd.fMin[d]) d = j; - } - c[i].iDim = d; - m = kdMedianJst(kd,d,c[i].pLower,c[i].pUpper); - c[i].fSplit = NP_POS(kd, m, d); - c[LOWER(i)].bnd = c[i].bnd; - c[LOWER(i)].bnd.fMax[d] = c[i].fSplit; - c[LOWER(i)].pLower = c[i].pLower; - c[LOWER(i)].pUpper = m-1; - c[UPPER(i)].bnd = c[i].bnd; - c[UPPER(i)].bnd.fMin[d] = c[i].fSplit; - c[UPPER(i)].pLower = m; - c[UPPER(i)].pUpper = c[i].pUpper; - i = LOWER(i); - } - else { - c[i].iDim = -1; - SETNEXT(i); - if (i == ct) break; - } - } - kdUpPass(kd,ROOT); - return(1); - } - - -int cmpParticles(const void *v1,const void *v2) -{ - PARTICLE *p1=(PARTICLE *)v1,*p2=(PARTICLE *)v2; - - return(p1->iOrder - p2->iOrder); - } - - -void kdOrder(KD kd) -{ - qsort(kd->p,kd->nActive,sizeof(PARTICLE),cmpParticles); - } - -void kdFinish(KD kd) -{ - if(kd->p!=NULL)free(kd->p); - if(kd->kdNodes!=NULL)free(kd->kdNodes); - free(kd); - } - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/hop_numpy.h --- a/yt/lagos/hop/hop_numpy.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#ifndef _NUMPY_HOP_H -#include "Python.h" -#include "numpy/ndarrayobject.h" - -#define NP_DENS(kd, in) \ - kd->np_densities[kd->p[in].np_index] -#define NP_POS(kd, in, dim) \ - kd->np_pos[dim][kd->p[in].np_index] -#define NP_MASS(kd, in) \ - (kd->np_masses[kd->p[in].np_index]/kd->totalmass) - -#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/hop_regroup.c --- a/yt/lagos/hop/hop_regroup.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,726 +0,0 @@ -/* REGROUP.C, Daniel Eisenstein, 1997 */ -/* Based on a paper by Daniel Eisenstein & Piet Hut, -"HOP: A New Group-Finding Algorithm for N-body Simulations." -See the included documentation or view it at -http://www.sns.ias.edu/~eisenste/hop/hop_doc.html */ - -/* Version 1.0 (12/15/97) -- Original Release */ - -#include "slice.h" -#include -#include -#include -#include -#include -#include -//#include "macros_and_parameters.h" -#include "hop.h" - -#define ISYM "d" -#define GSYM "g" -#define FSYM "f" - -/* #define MINDENS (-FLT_MAX/3.0) */ -#define MINDENS (-1.e+30/3.0) -/* This is the most negative density that can be accomodated. Note -that MINDENS*2.0 is referenced in the code and so must be properly -represented by the machine. There's no reason for this to be close to -the actual minimum of the density. */ - -#define INFORM(pstr) printf(pstr); fflush(stdout) -/* Used for messages, e.g. INFORM("Doing this"); */ - -#define UNBOUND -2 /* The tag marker for unbound particles */ - -/* ----------------------------------------------------------------------- */ -/* Prototypes */ -void initgrouplist(Grouplist *g); -void readtags(Slice *s, Grouplist *g, char *fname); -void densitycut(Slice *s, char *fname, float densthresh); -void writegmerge(Slice *s, Grouplist *gl, char *fname, float pt, float mt); -void readgmerge(Slice *s, Grouplist *gl, char *fname); -void merge_groups_boundaries(Slice *s, Grouplist *gl, char *fname, - float peakdensthresh, float saddledensthresh, float densthresh, HC *my_comm); -void translatetags(Slice *s, Grouplist *gl); -void writetags(Slice *s, Grouplist *gl, char *fname); -void writetagsf77(Slice *s, Grouplist *gl, char *fname); -void count_membership(Slice *s, Grouplist *g); -void sort_groups(Slice *s, Grouplist *gl, int mingroupsize, char *fname); - -/* ----------------------------------------------------------------------- */ -/* We use the following structure to handle the user interface: */ - -typedef struct controlstruct { - char *tagname; /* Input file for group tags */ - char *densname; /* Input file for density file */ - char *gmergename; /* Input file for group boundary specifications, OR - input file for group merging data */ - char *outsizename; /* Output file for size output*/ - char *outtagname; /* Output file for group tags */ - char *outgmergename; /* Output file for group merging */ - - int qdenscut; /* =1 if we're making a density cut, =0 otherwise */ - float densthresh; /* The outer density threshold (delta_outer)*/ - - int qgbound; /* =1 if we are to read the boundaries file and - determine the merging.*/ - float peak_thresh; /* Density threshold for peak (delta_peak) */ - float saddle_thresh; /* Density threshold for merging (delta_saddle) */ - int qgmerge_given; /* =1 if we are to use a group translation from file */ - - int mingroupsize; /* The minimum group size we follow */ - int qoutput; /* =1 if we are to write the tags */ - int qf77; /* =1 if binary output if in f77 format */ - int qpipe; /* =1 if we are to write the output tags to stdout */ - int qsort; /* =1 if we are to sort */ - - /* The following aren't used in the present version, but I included - them in case the user wants to customize the program: */ - char *dataname; /* Input file for particle data */ - int qunbind; /* =1 if we are to unbind at all */ -} Controls; /* Type Controls is defined */ - -/* ====================================================================== */ -/* ===================== User Interface ================================= */ -/* ====================================================================== */ - -void parsecommandline(float dens_outer, Controls *c) -{ - int narg, qmerge; - char *outname, *rootname; - narg = 1; - rootname = c->dataname = c->densname = c->gmergename = c->tagname = - outname = c->outsizename = c->outtagname = c->outgmergename = NULL; - c->qdenscut = -1; - qmerge = 1; - c->qgmerge_given = 0; - - c->qunbind = 0; - c->qoutput = 1; - c->qsort = 1; - c->qpipe = 0; - c->qf77 = 0; - - c->mingroupsize = -1; - if (2.0*MINDENS>=MINDENS || MINDENS>=0) - myerror("MINDENS seems to be illegal."); - /* Need MINDENS<0 and 2*MINDENS to be machine-representable */ - c->densthresh = 2.0*MINDENS; - c->saddle_thresh = 2.0*MINDENS; - c->peak_thresh = 2.0*MINDENS; - - /* GLB: hard-code some parameters. */ - - c->peak_thresh = 3.0*dens_outer; - c->saddle_thresh = 2.5*dens_outer; - c->densthresh = dens_outer; - c->qdenscut = 1; - rootname = "output_hop"; - - /* Get the input files ready */ - if (c->qdenscut==-1) { - /* Neither -douter nor -nodens was chosen. */ - mywarn("Outer density threshold left unspecified. Skipping this cut."); - c->qdenscut = 0; - } else if (c->qdenscut==1) { - /* We have a chosen density. Need to figure out the density file. */ - if (c->densname==NULL) { - if (rootname==NULL) - myerror("No density file name or root has been specified."); - c->densname = (char *)malloc(80); - strcpy(c->densname,rootname); strcat(c->densname, ".den"); - } - } else c->densname = NULL; /* We have no reason to read it */ - - if (c->tagname==NULL) { - if (rootname==NULL) - myerror("No .hop file name or root has been specified."); - c->tagname = (char *)malloc(80); - strcpy(c->tagname,rootname); strcat(c->tagname, ".hop"); - } - - if (qmerge==1) { - if (c->qgmerge_given==0) { - /* We need to have a .gbound file */ - c->qgbound = 1; - if (c->saddle_threshpeak_threshgmergename==NULL) { - if (rootname==NULL) - myerror("No .gbound file name or root has been specified."); - c->gmergename = (char *)malloc(80); - strcpy(c->gmergename,rootname); - strcat(c->gmergename, ".gbound"); - } - } else c->qgbound = 0; /* We know c->mergename is ready to go */ - } else c->gmergename = NULL; /* No reason to read it */ - - /* Get the output files ready */ - /* If a default name wasn't given, we'll assume zregroup */ - if (outname==NULL) { - outname = (char *)malloc(20); - strcpy(outname,"zregroup"); - } - /* Primary tag output: */ - if (c->qoutput) { /* Need to figure out where we're sending the output */ - if (c->qpipe&&c->outtagname) - myerror("Conflicting instructions--gave specific output name and told to pipe."); - if (c->qpipe>0) mywarn("Writing tags to stdout."); - if (c->qpipe) c->outtagname = NULL; /* Our signal to send to stdout */ - else if (c->outtagname==NULL) { - c->outtagname = (char *)malloc(80); - strcpy(c->outtagname, outname); - strcat(c->outtagname, ".tag"); - } /* Otherwise the name was set by the user */ - } else { - /* We're not outputing tags */ - if (c->qpipe) myerror("Conflicting instructions--told to pipe and not to output."); - } - - if (c->qsort) { - if (c->qpipe>=0) { /* The user didn't specify quiet */ - c->outsizename = (char *)malloc(80); - strcpy(c->outsizename, outname); - strcat(c->outsizename, ".size"); - } - } - - if (c->qpipe>=0) { /* The user didn't specify quiet */ - c->outgmergename = (char *)malloc(80); - strcpy(c->outgmergename, outname); - strcat(c->outgmergename, ".gmerge"); - } - - if (c->mingroupsize >= 0 && !c->qsort) - myerror("Imposition of a certain group size occurs within the sort routine."); - if (c->qsort && c->mingroupsize < 0) { - mywarn("No minimum group size specified. Assuming 10 particles."); - c->mingroupsize = 10; - } - - if (c->densthreshdensthresh=MINDENS; - /* This is our default--a very negative number */ - - return; -} - -/* ====================================================================== */ -/* ============================== MAIN() ================================ */ -/* ====================================================================== */ - -/* void main(int argc, char *argv[]) */ -void regroup_main(float dens_outer, HC *my_comm) -{ - Grouplist *gl = my_comm->gl; - Slice *s = my_comm->s; - FILE *f; - Controls c; - - /* parsecommandline(argc, argv, &c); */ - parsecommandline(dens_outer, &c); - - //initgrouplist(gl); - //s=newslice(); - - /* We need to read the tag file and perhaps perform a density cut */ - // We don't read anymore (mjt) - //readtags(s,gl,c.tagname); - - // We cut in advance now (mjt) - //if (c.qdenscut) densitycut(s,c.densname,c.densthresh); - - /* Next do the merging of the input groups */ - if (c.qgbound) { - /* We're going to read a .gbound file and merge groups */ - merge_groups_boundaries(s,gl,c.gmergename, - c.peak_thresh, c.saddle_thresh, c.densthresh, my_comm); - /* Renumber the groups from large to small; remove any tiny ones */ - //if (c.qsort) sort_groups(s, gl, c.mingroupsize, c.outsizename); - if (c.qsort) sort_groups(s, gl, c.mingroupsize, NULL); - //writegmerge(s, gl, c.outgmergename, c.peak_thresh, c.saddle_thresh); - translatetags(s,gl); - } - else if (c.qgmerge_given) { - /* We're going to read a .gmerge file and merge groups as it says */ - readgmerge(s, gl, c.gmergename); - translatetags(s, gl); - } /* Else we'll use the tags as given by the original .hop file */ - - /* If one wants to manipulate the groups any more, this is a good - place to do it. For example, you might want to remove unbound particles: - if (c.qunbind) { - get_particle_data(s, gl, c.dataname); - unbind_particles(s, gl, c.mingroupsize); - } - */ - - /* Write the output */ - /*if (c.qoutput) { - if (c.qf77) writetagsf77(s, gl, c.outtagname); - else writetags(s, gl, c.outtagname); - }*/ - - //free_slice(s); - return; -} - -/* ================================================================= */ -/* =================== Initialization Routines ===================== */ -/* ================================================================= */ - -void initgrouplist(Grouplist *g) -/* Just make sure this stuff is zero */ -{ - g->list = NULL; - g->npartingroups = g->npart = g->ngroups = 0; g->nnewgroups = 0; - return; -} - -void readtags(Slice *s, Grouplist *g, char *fname) -/* Read the tag file named fname into s->ntag[] */ -/* Groups need not be sorted, but must be numbered from 0 to ngroups-1 */ -{ - FILE *f; - - if ((f=fopen(fname,"r"))==NULL) myerror("Input tag file not found."); - if (fread(&(g->npart),sizeof(int),1,f)!=1) myerror("Tag file read error."); - if (fread(&(g->ngroups),sizeof(int),1,f)!=1) myerror("Tag file read error."); - fprintf(stderr,"Number of particles: %"ISYM". Number of groups: %"ISYM".\n", - g->npart, g->ngroups); - - s->numpart = g->npart; - s->numlist = g->npart; - s->ntag = ivector(1,s->numlist); - //s->ID = ivector(1,s->numlist); - fread(s->ntag+1, sizeof(int), s->numlist, f); /* Read in all the tags */ - //fread(s->ID+1, sizeof(int), s->numlist,f); /* Read in the real particle IDs. S Skory */ - fclose(f); - - return; -} - -/* ========================== Density Cut ======================== */ - -#define MAXBLOCK 65536 /* Read the file 256k at a time */ - -void densitycut(Slice *s, char *fname, float densthresh) -/* Read the density file and change the tag on any particle with density -less than densthresh to -1, thus removing them from groups */ -/* This will leave some groups with no particles, which is fine */ -/* We read the file in segments, so as to reduce memory consumption */ -{ - FILE *f; - int j, numread, npart, block; /* block was a float by mistake */ - float density[MAXBLOCK]; - - if ((f=fopen(fname,"r"))==NULL) - myerror("Density file not found."); - npart = 0; fread(&npart,sizeof(int),1,f); - if (npart!=s->numpart) - mywarn("Density file doesn't match slice description."); - - numread = 0; - block = MAXBLOCK; /* Start off big */ - while (numreadntag[numread+j]=(-1); /* s->ntag is unit-offset */ - numread+=block; - } - fclose(f); - return; -} - -/* ====================== Read/Write .gmerge files ======================= */ -/* The gmerge file is just a map from the old (pre-regroup) group numbers -to the new (post-regroup) group numbers. Of course, there are more "old" -groups than "new" groups, since the point of regroup() is to merge groups. */ - -void writegmerge(Slice *s, Grouplist *gl, char *fname, float pt, float mt) -/* Write the translation between old groups and new groups, ASCII */ -{ - FILE *f; - int j; - Group *gr; - - if (fname==NULL) return; /* We've been told not to write anything */ - - if ((f=fopen(fname,"w"))==NULL) myerror("Can't open gmerge file for write."); - fprintf(f,"%"ISYM"\n%"ISYM"\n%"ISYM"\n", gl->npart, gl->ngroups, gl->nnewgroups); - fprintf(f,"%"FSYM"\n%"FSYM"\n", pt, mt); - for (j=0,gr=gl->list;jngroups;j++,gr++) - fprintf(f,"%"ISYM" %"ISYM"\n", j, gr->idmerge); - fclose(f); - return; -} - -void readgmerge(Slice *s, Grouplist *gl, char *fname) -/* Read the translation between old groups and new groups, ASCII */ -/* Also, set up gl->list for translation */ -{ - FILE *f; - int j, dummy; - Group *gr; - float pt, mt; - - if ((f=fopen(fname,"r"))==NULL) myerror("Can't open gmerge read file."); - if (fscanf(f,"%"ISYM"\n%"ISYM"\n%"ISYM"\n", &(gl->npart), &(gl->ngroups), - &(gl->nnewgroups))!=3) myerror("Error in header of gmerge file."); - if (gl->npart!=s->numpart) myerror("Number of particles in gmerge file doesn't match that of tags file."); - fscanf(f,"%"FSYM" %"FSYM"\n", &pt, &mt); - - if (gl->list!=NULL) free(gl->list); - gl->list = (Group *)malloc((size_t)(gl->ngroups *sizeof(Group))); - if (gl->list==NULL) myerror("Error in allocating gl->list."); - - for (j=0,gr=gl->list; jngroups; j++,gr++) { - if (fscanf(f,"%"ISYM" %"ISYM"\n", &dummy, &(gr->idmerge))!=2 || dummy!=j) - myerror("Error in reading gmerge file."); - gr->npart = -1; /* We're not setting this */ - } - fclose(f); - return; -} - -/* ====================== GROUP MERGING BY BOUNDARIES ================ */ - -void merge_groups_boundaries(Slice *s, Grouplist *gl, char *mergename, - float peakdensthresh, float saddledensthresh, float densthresh, - HC *my_comm) -/* Read in the gmerge file and decide which groups are to be merged. -Groups are numbered 0 to ngroups-1. Groups with boundaries greater -than saddledensthresh are merged. Groups with maximum densities -less than peakdensthresh are merged to the group with -maxdensity above peakdensthresh with which it shares the highest -density border. */ -/* Only groups with maximum densities above peakdensthresh can be group -centers. */ -/* Allocate space for the grouplist and store the merging results in -the idmerge field. */ -/* I think this will work even if saddledensthreshgdensity; - ngroups = my_comm->ngroups; - - if (densthreshngroups = ngroups; - if (gl->list!=NULL) free(gl->list); - gl->list = (Group *)malloc((size_t)(gl->ngroups *sizeof(Group))); - fprintf(stderr,"ngroups = %d\n",ngroups); - if (gl->list==NULL) myerror("Error in allocating gl->list."); - for (j=0,gr=gl->list;jngroups;j++,gr++) { - /* If group is too underdense, it cannot be a group center */ - if (gdensity[j]idmerge=(-1);} - else {gr->idmerge = j;} - gr->npart = -1; /* Not doing anything with this */ - densestbound[j] = 2.0*MINDENS; /* Initialize */ - densestboundgroup[j] = -1; /* Initialize */ - } - - /* Now step through the list of boundaries */ - /* If a boundary is between two groups with max densities above - peakdensthresh and if the boundary is above saddledensthresh, then - merge the groups (keeping the lower number of the two). */ - /* If one of the groups is above peakdensthresh and the other is - below, and if the boundary density is higher than any seen previously - for the lower density group, then record this information */ - /* If neither group is above peakdensthresh, skip the boundary */ - - /* make few arrays to eliminate the need to write a file to disk. The entries in - the arrays should be no larger than my_comm->nb. - Skory. - */ - int *g1temp,*g2temp; - float *denstemp; - g1temp = (int *)malloc(sizeof(int) * my_comm->nb); - g2temp = (int *)malloc(sizeof(int) * my_comm->nb); - denstemp = (float *)malloc(sizeof(float) * my_comm->nb); - - int temppos = 0; - for(j=0;j<(my_comm->nb);j++) { - g1 = my_comm->g1vec[j]; - g2 = my_comm->g2vec[j]; - dens = my_comm->fdensity[j]; - if (gdensity[g1]densthresh && gdensity[g2]>densthresh && - dens>densthresh) { - g1temp[temppos] = g1; - g2temp[temppos] = g2; - denstemp[temppos] = dens; - temppos += 1; - } - continue; /* group isn't dense enough */ - } - if (gdensity[g1]>=peakdensthresh && gdensity[g2]>=peakdensthresh) - if (denslist[g1].idmerge) - g1=gl->list[g1].idmerge; - while (g2!=gl->list[g2].idmerge) - g2=gl->list[g2].idmerge; - if (g1list[g2].idmerge=g1; - else gl->list[g1].idmerge=g2; - continue; /* Go to the next boundary */ - } - /* Else one is above peakdensthresh, the other below. */ - /* Make the high one g1 */ - if (gdensity[g1]densestbound[g2]) { - /* It's the densest boundary yet */ - densestbound[g2] = dens; - densestboundgroup[g2] = g1; - } - } /* Get the next boundary line */ - - - /* Now the fringe groups are connected to the proper group - (>peakdensthresh) with the largest boundary. But we want to look - through the boundaries between fringe groups to propagate this - along. Connections are only as good as their smallest boundary */ - /* Keep the density of the connection in densestbound, and the - proper group it leads to in densestboundgroup */ - do { - changes = 0; - for (j=0;jdensestbound[g1]) { - dummy[0] = g2; g2=g1; g1=dummy[0]; - } - if (dens>densestbound[g2]&&densestbound[g1]>densestbound[g2]) { - changes++; - if (densngroups;j++) { - if (densestbound[j]>=densthresh) - gl->list[j].idmerge = densestboundgroup[j]; - } - /* Now we want to number the newly merged groups */ - /* The center groups are given negative numbers <-1 */ - for (j=0,gl->nnewgroups=0; jngroups; j++) - if (gl->list[j].idmerge==j) { - gl->list[j].idmerge = -2-(gl->nnewgroups++); - } - - /* Now trace each group through until a negative number is reached */ - for (j=0; jngroups; j++) { - if (gl->list[j].idmerge<0) continue; - g1 = j; - while ((g1=gl->list[g1].idmerge)>=0); - g2 = j; - do gl->list[g2].idmerge = g1; - while ((g2=gl->list[g2].idmerge)>=0); - } - - /* Finally, renumber the groups 0..N-1 */ - for (j=0,gr=gl->list;jngroups;j++,gr++) - gr->idmerge = -2-gr->idmerge; /* Keep -1 -> -1 */ - - - /* And delete the tempfile */ - remove(tempfilename); - free_vector(gdensity,0,ngroups-1); - free_vector(densestbound,0,ngroups-1); - free_ivector(densestboundgroup,0,ngroups-1); - return; -} - -/* ======================================================================= */ -/* =============== Update the tags and write them out ==================== */ -/* ======================================================================= */ - -void translatetags(Slice *s, Grouplist *gl) -/* Alter s->ntag to have the new groups. Reset gl so as to reflect the -new number of groups. */ -{ - int j; - - - for (j=1;j<=s->numlist;j++) - if (s->ntag[j]>=0) { - s->ntag[j] = gl->list[s->ntag[j]].idmerge; - } - /* Otherwise, translate the unbound particles */ - else if (s->ntag[j]<-1) - s->ntag[j] = UNBOUND - gl->list[UNBOUND-s->ntag[j]].idmerge; - free(gl->list); - gl->list = NULL; - gl->ngroups = gl->nnewgroups; - return; -} - -void writetags(Slice *s, Grouplist *gl, char *fname) -/* Write s->ntag to file */ -/* If fname==NULL, write to stdout */ -{ - FILE *f; - - - if (fname!=NULL) { - if ((f=fopen(fname,"w"))==NULL) myerror("Error opening new tag file."); - } else f=stdout; - fwrite(&(s->numpart),sizeof(int),1,f); - printf("writetags: s->numpart = %d gl->ngroups = %d\n", - s->numpart, gl->ngroups); - fwrite(&(gl->ngroups),sizeof(int),1,f); - fwrite(s->ntag+1,sizeof(int),s->numlist,f); - //fwrite(s->ID+1,sizeof(int),s->numlist,f); /* S Skory */ - fclose(f); - - return; -} - -void writetagsf77(Slice *s, Grouplist *gl, char *fname) -/* Write s->ntag to file */ -/* If fname==NULL, write to stdout */ -/* Use a format readable for FORTRAN unformatted read commands */ -{ - FILE *f; - int dummy; - if (fname!=NULL) { - if ((f=fopen(fname,"w"))==NULL) myerror("Error opening new tag file."); - } else f=stdout; - dummy = 8; fwrite(&dummy,sizeof(int),1,f); - fwrite(&(s->numpart),sizeof(int),1,f); - fwrite(&(gl->ngroups),sizeof(int),1,f); - fwrite(&dummy,sizeof(int),1,f); - dummy = s->numlist*sizeof(int); fwrite(&dummy,sizeof(int),1,f); - fwrite(s->ntag+1,sizeof(int),s->numlist,f); - fwrite(&dummy,sizeof(int),1,f); - fclose(f); - return; -} - -/* ====================================================================== */ -/* ========================== Sorting the Groups ======================== */ -/* ====================================================================== */ - -void sort_groups(Slice *s, Grouplist *gl, int mingroupsize, char *fname) -/* Sort the groups, as labeled by the idmerge field not their original -number, from largest to smallest. Alter the idmerge field to this new -numbering, setting any below mingroupsize to -1. */ -/* If fname!=NULL, write a little output file listing the group sizes */ -{ - FILE *f; - int j,k, *order, partingroup, igr, *newnum, nmergedgroups; - float *gsize; - Group *c; - void make_index_table(int n, float *fvect, int *index); - - nmergedgroups = gl->nnewgroups; - gsize = vector(0,nmergedgroups-1); - order = ivector(1,nmergedgroups); - newnum = ivector(0,nmergedgroups-1); - - /* First we need to find the number of particles in each group */ - for (j=0,c=gl->list;jngroups;j++,c++) c->npart=0; - - for (j=1;j<=s->numlist;j++) { /* Look through all the particles */ - igr = s->ntag[j]; - if (igr>=0) - if (igrngroups) gl->list[igr].npart++; - else myerror("Group tag is out of bounds."); - } - /* Now combine these to find the number in the new groups */ - for (j=0;jlist;jngroups;j++,c++) - if (c->idmerge>=0 && c->idmergeidmerge]+=c->npart; - else if (c->idmerge>=nmergedgroups) - myerror("Group idmerge is out of bounds."); - - make_index_table(nmergedgroups, gsize-1, order); - /* But remember that order[] thinks that gsize is unit-offset */ - for (j=nmergedgroups,k=0;j>0; j--,k++) - if (gsize[order[j]-1]>mingroupsize-0.5) newnum[order[j]-1]=k; - else break; /* All of the rest are too small */ - - gl->nnewgroups = k; - for (;j>0;j--) newnum[order[j]-1]=(-1); - /* Newnum[] holds the new sorted number for merged group j */ - - /* Now assign sorted group numbers to idmerge */ - partingroup = 0; - for (j=0,c=gl->list;jngroups;j++,c++) - if (c->idmerge>=0) - if ((c->idmerge = newnum[c->idmerge])>=0) - partingroup+=c->npart; - - /* Output the .size file, if inputed name isn't NULL */ - if (fname!=NULL) { - f = fopen(fname,"w"); - fprintf(f,"%"ISYM"\n%"ISYM"\n%"ISYM"\n", s->numpart, partingroup, gl->nnewgroups); - for (j=0;jnnewgroups;j++) - fprintf(f,"%"ISYM" %"ISYM"\n", j, (int)gsize[order[nmergedgroups-j]-1]); - fclose(f); - } - free_ivector(order,1,nmergedgroups); - free_vector(gsize,0,nmergedgroups-1); - free_ivector(newnum,0,nmergedgroups-1); - return; -} - -/* ======================== Sorting ============================ */ - -typedef struct index_struct { - float value; - int index; -} *ptrindex; - -int cmp_index_regroup(const void *a, const void *b) -{ - if ( ((ptrindex)a)->value<((ptrindex)b)->value) return -1; - else if ( ((ptrindex)a)->value>((ptrindex)b)->value) return 1; - else return 0; -} - -void make_index_table(int n, float *fvect, int *index) -/* Given a vector of floats fvect[1..n], construct a index table index[1..n] -so that index[j] contains the ID number of the jth lowest element. -Storage for index[] should be declared externally */ -/* This isn't fast, but it takes a tiny fraction of the runtime */ -{ - int j; - ptrindex sortvect; - - sortvect = (ptrindex)malloc(n*sizeof(struct index_struct)); - for (j=0;jpid = NULL; s->offset = 0; - s->px = s->py = s->pz = s->vx = s->vy = s->vz = NULL; - s->ntag = NULL; - //s->ID = NULL; /* S Skory */ - s->numpart = s->numlist = 0; - return s; -} - -void free_tags(Slice *s) -/* Free the tag vector */ -{ - if (s->ntag!=NULL) { - free_ivector(s->ntag, 1, s->numlist); - s->ntag=NULL; - //free_ivector(s->ID, 1, s->numlist); /* S Skory */ - //s->ID=NULL; - } - return; -} - -void free_data(Slice *s) -/* Free all the data vectors */ -{ - if (s->pid!=NULL) {free(s->pid); s->pid=NULL;} - if (s->px!=NULL) {free_vector(s->px,1,s->numlist); s->px=NULL;} - if (s->py!=NULL) {free_vector(s->py,1,s->numlist); s->py=NULL;} - if (s->pz!=NULL) {free_vector(s->pz,1,s->numlist); s->pz=NULL;} - if (s->vx!=NULL) {free_vector(s->vx,1,s->numlist); s->vx=NULL;} - if (s->vy!=NULL) {free_vector(s->vy,1,s->numlist); s->vy=NULL;} - if (s->vz!=NULL) {free_vector(s->vz,1,s->numlist); s->vz=NULL;} - return; -} - -void free_slice(Slice *s) -/* Free the space associated with the vectors in the given Slice */ -/* Then free the Slice variable itself */ -{ - free_tags(s); - free_data(s); - free(s); - return; -} - -/* =================================================================== */ - -int f77write(FILE *f, void *p, int len) -/* len is number of bytes to be written from p[0..len-1] */ -/* Return 0 if successful, 1 if not */ -{ - if (fwrite(&len,sizeof(int),1,f)!=1) return 1; - if (fwrite(p,1,len,f)!=len) return 1; - if (fwrite(&len,sizeof(int),1,f)!=1) return 1; - return 0; -} - -int f77read(FILE *f, void *p, int maxbytes) -/* Read a FORTRAN style block from the given file */ -/* maxbytes is the amount of space the pointer p points to */ -/* Space must be allocated to read the whole block into p */ -/* Return amount read, scream if there's a problem */ -/* Reading is done ZERO-OFFSET */ -{ - int size, size2; - if (fread(&size,sizeof(int),1,f)!=1) - myerror("f77read(): Error reading begin delimiter."); - if (size>maxbytes) - myerror("f77read(): Block delimiter exceeds size of storage."); - if (sizenumpart = sizeheader[0]; - s->numblocks = sizeheader[1]; - s->numperblock = sizeheader[0]/sizeheader[1]; - if (s->numpart != s->numblocks*(s->numperblock)) - myerror("Number of blocks not an even divisor of number of particles."); - - s->z = header[0]; - s->boxsize = header[1]*1000.0; /* We use kpc, not Mpc */ - s->physsize = s->boxsize/(1.0+s->z); /* We use kpc, not Mpc */ - s->velscale = 100.0*header[1]*sqrt(3.0/8.0/PI)/(1.0+s->z); - /* To go from data to pec vel */ - s->omega = header[4]; - if (header[6]!=0.0) myerror("HDM component listed in header."); - s->lambda = header[7]; - s->h0 = header[8]; - s->sigma8 = header[9]; /* At z=0 */ - - /* Now find some computed quantities. */ - s->a = 1.0/(1.0+s->z); - s->curv = 1.0-s->omega-s->lambda; - s->gamma = s->omega*(s->h0); - s->specn = 1.0; - s->hubb = 0.1*sqrt(s->omega/CUBE(s->a)+s->curv/SQR(s->a)+s->lambda)*(s->a); - - /* The following assume Omega = 1 */ - s->masspart = RHOCRIT/s->numpart*CUBE(s->boxsize); - s->growth = s->a; - s->t = HTIME*(s->h0)*pow(s->a, 1.5); - return 0; -} - -void normalizedata(Slice *s, int conp, int conv) -/* Put raw data into comoving h^-1 kpc and km/s units */ -{ - int j; - float velnorm; - if (conp) { - for (j=1;j<=s->numlist;j++) s->px[j] *= s->boxsize; - for (j=1;j<=s->numlist;j++) s->py[j] *= s->boxsize; - for (j=1;j<=s->numlist;j++) s->pz[j] *= s->boxsize; - } - - if (conv) { - for (j=1;j<=s->numlist;j++) s->vx[j] *= s->velscale; - for (j=1;j<=s->numlist;j++) s->vy[j] *= s->velscale; - for (j=1;j<=s->numlist;j++) s->vz[j] *= s->velscale; - } - return; -} - -/* ================================================================ */ - -int read_alldata(FILE *f, FILE *ftag, Slice *s, int conp, int conv) -/* Read all the data, including the tags if ftag!=NULL. */ -/* Store positions and velocities unless conp or conv = 0 */ -/* Assume that the data file header has been skipped, but read the -tag file header. */ -{ - int block; - float *dummylist; - - dummylist = NULL; - if (!conp || !conv) dummylist = vector(1,s->numperblock); - if (s->pid!=NULL) - mywarn("Non-NULL s->pid[] passed to read_alldata(). Ignoring..."); - - s->numlist=s->numpart; - if (conp) { - s->px=vector(1,s->numlist); - s->py=vector(1,s->numlist); - s->pz=vector(1,s->numlist); - } - if (conv) { - s->vx=vector(1,s->numlist); - s->vy=vector(1,s->numlist); - s->vz=vector(1,s->numlist); - } - if (ftag!=NULL) { - s->ntag = ivector(1,s->numlist); - s->ID = ivector(1,s->numlist); /* S Skory */ - } - - - printf("Reading data..."); - for (block=0;blocknumblocks;block++) { - /* Read the three position blocks */ - if (conp) { /* Store the data */ - f77read(f, s->px+s->numperblock*block+1, s->numperblock*sizeof(float)); - f77read(f, s->py+s->numperblock*block+1, s->numperblock*sizeof(float)); - f77read(f, s->pz+s->numperblock*block+1, s->numperblock*sizeof(float)); - } else { /* Don't store the data */ - f77read(f, dummylist+1, s->numperblock*sizeof(float)); - f77read(f, dummylist+1, s->numperblock*sizeof(float)); - f77read(f, dummylist+1, s->numperblock*sizeof(float)); - } - /* Now read the three velocity blocks */ - if (conv) { /* Store the data */ - f77read(f, s->vx+s->numperblock*block+1, s->numperblock*sizeof(float)); - f77read(f, s->vy+s->numperblock*block+1, s->numperblock*sizeof(float)); - f77read(f, s->vz+s->numperblock*block+1, s->numperblock*sizeof(float)); - } else { /* Don't store the data */ - f77read(f, dummylist+1, s->numperblock*sizeof(float)); - f77read(f, dummylist+1, s->numperblock*sizeof(float)); - f77read(f, dummylist+1, s->numperblock*sizeof(float)); - } - if (block%8==1) {printf("."); fflush(stdout);} - } - if (dummylist!=NULL) free_vector(dummylist, 1, s->numperblock); - normalizedata(s,conp,conv); - - if (ftag!=NULL) { - printf("tags..."); fflush(stdout); - readalltags(ftag, s); - } - - printf("done!"); fflush(stdout); - return 0; -} - -int read_partdata(FILE *f, FILE *ftag, Slice *s) -/* Read one block (128k particles) of data into Slice s. Allocate needed -storage, erasing and freeing previous storage. */ -/* This cannot be done with s->pid!=NULL, so s->pid is ignored and s->numlist -is reset to BLOCKSIZE */ -/* Unlike other routines, this stores both positions and velocities in -all cases (since the storage requirements are already small */ -/* If ftag==NULL, don't read the tag file. Otherwise do read it. */ -{ - if (s->pid!=NULL) - mywarn("Non-trivial pid[] not supported with incremental reads"); - /* If we need to reallocate memory, do it. Otherwise, just write over */ - if (s->px==NULL || s->vx==NULL || s->numlist!=s->numperblock) { - if (s->px!=NULL) free_vector(s->px,1,s->numlist); - if (s->py!=NULL) free_vector(s->py,1,s->numlist); - if (s->pz!=NULL) free_vector(s->pz,1,s->numlist); - if (s->vx!=NULL) free_vector(s->vx,1,s->numlist); - if (s->vy!=NULL) free_vector(s->vy,1,s->numlist); - if (s->vz!=NULL) free_vector(s->vz,1,s->numlist); - if (ftag!=NULL && s->ntag!=NULL) { - free_ivector(s->ntag, 1, s->numlist); - free_ivector(s->ID, 1, s->numlist); /* S Skory */ - } - s->numlist = s->numperblock; - s->px = vector(1,s->numlist); - s->py = vector(1,s->numlist); - s->pz = vector(1,s->numlist); - s->vx = vector(1,s->numlist); - s->vy = vector(1,s->numlist); - s->vz = vector(1,s->numlist); - if (ftag!=NULL) { - s->ntag = ivector(1, s->numlist); - s->ID = ivector(1, s->numlist); /* S Skory */ - } - s->offset=0; - /* fprintf(stderr, "Reallocating data arrays.\n"); */ - } - else s->offset+=s->numlist; - - f77read(f,s->px+1,sizeof(float)*s->numlist); - f77read(f,s->py+1,sizeof(float)*s->numlist); - f77read(f,s->pz+1,sizeof(float)*s->numlist); - f77read(f,s->vx+1,sizeof(float)*s->numlist); - f77read(f,s->vy+1,sizeof(float)*s->numlist); - f77read(f,s->vz+1,sizeof(float)*s->numlist); - - if (ftag!=NULL) readtag(ftag, s->numlist, s->ntag); - normalizedata(s,1,1); - return 0; -} - -/* =============================================================== */ - -int readtag(FILE *f, int numread, int *ntag) -/* Read numread values from FILE f and put the values in ntag */ -/* Return 0 if successful, 1 if not */ -/* The storage ntag[1..numread] must exist */ -/* Note: the first 8 bytes of the tag file contain the number of particles -and the number of groups. These must be skipped before calling this routine. */ -{ - if (fread(ntag+1, sizeof(int), numread, f)!=numread) - myerror("Error in reading tag file."); - return 0; -} - -int skiptagheader(FILE *f, Slice *s) -/* Read the first 8 bytes from the tag file. Check that the first int equals -the number of particles. Return the second, which is the number of groups */ -{ - int dummy[2]; - if (fread(&dummy, sizeof(int), 2, f)!=2) myerror("Error in reading tag file."); - if (s->numpart!=0 && dummy[0]!=s->numpart) - myerror("First number in tag file doesn't match expected number of particles."); - s->numgroups = dummy[1]; - return dummy[1]; -} - -int readalltags(FILE *f, Slice *s) -/* Read the whole tag file. Allocate memory as needed */ -/* Return the number of groups */ -{ - int dummy[2]; - if (s->ntag==NULL || s->numlist!=s->numpart) { - if (s->ntag!=NULL) { - free_ivector(s->ntag, 1, s->numlist); - free_ivector(s->ID, 1, s->numlist); /* S Skory */ - } - s->numlist = s->numpart; - s->ntag = ivector(1, s->numlist); - s->ID = ivector(1, s->numlist); - } - if (fread(&dummy, sizeof(int), 2, f)!=2) myerror("Error 1 in reading tag file."); - if (dummy[0]!=s->numpart) - myerror("First int of tag file doesn't match numpart."); - s->numgroups = dummy[1]; - - if (fread(s->ntag+1, sizeof(int), s->numlist, f)!=s->numlist) - myerror("Couldn't read entire tag file."); - return dummy[1]; -} - -#endif - -/* ===================== Warnings and Errors =========================== */ - -/* Print a message and die */ -void myerror(char *message) -{ - fprintf(stderr, "%s\n", message); - exit(1); return; -} - -/* Just print a message */ -void mywarn(char *message) -{ - fprintf(stderr, "%s\n", message); - fflush(NULL); /* Flush everything, so we know where we are */ - return; -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/hop_smooth.c --- a/yt/lagos/hop/hop_smooth.c Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,476 +0,0 @@ -/* SMOOTH.C */ -/* This was written by Joachim Stadel and the NASA HPCC ESS at -the University of Washington Department of Astronomy as part of -the SMOOTH program, v2.0.1. -URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ - -/* DJE--I have removed unneeded subroutines, notably those having -to do with velocity field reconstructions (because they refer to -particle data that I chose not to store) and output routines -(because I wanted binary output). Also, the density subroutine -was slightly customized to reduce memory consumption in -the case of equal mass particles. */ - -/* HOP Version 1.0 (12/15/97) -- Original Release */ - -#include -#include -#include -#include -#include "smooth.h" -#include "kd.h" -#include "hop_numpy.h" - -#define ISYM "d" -#define GSYM "g" - -//#include "macros_and_parameters.h" - -#define IMARK 1 /* All particles are marked to be included */ - -int smInit(SMX *psmx,KD kd,int nSmooth,float *fPeriod) -{ - SMX smx; - PQ_STATIC; - int pi,j; - fprintf(stderr,"nSmooth = %d kd->nActive = %d\n", nSmooth, kd->nActive); - assert(nSmooth <= kd->nActive); - smx = (SMX)malloc(sizeof(struct smContext)); - assert(smx != NULL); - smx->kd = NULL; - - smx->kd = kd; - smx->nSmooth = nSmooth; - smx->pq = (PQ *)malloc(nSmooth*sizeof(PQ)); - assert(smx->pq != NULL); - PQ_INIT(smx->pq,nSmooth); - smx->pfBall2 = (float *)malloc((kd->nActive+1)*sizeof(int)); - assert(smx->pfBall2 != NULL); - smx->iMark = (char *)malloc(kd->nActive*sizeof(char)); - assert(smx->iMark); - smx->nListSize = smx->nSmooth+RESMOOTH_SAFE; - smx->fList = (float *)malloc(smx->nListSize*sizeof(float)); - assert(smx->fList != NULL); - smx->pList = (int *)malloc(smx->nListSize*sizeof(int)); - assert(smx->pList != NULL); - /* - ** Set for Periodic Boundary Conditions. - */ - for (j=0;j<3;++j) smx->fPeriod[j] = fPeriod[j]; - /* - ** Initialize arrays for calculated quantities.--DJE - */ - for (pi=0;pikd->nActive;++pi) { - NP_DENS(smx->kd, pi) = 0.0; - smx->kd->p[pi].iHop = 0; - } - *psmx = smx; - return(1); - } - - -void smFinish(SMX smx) -{ - free(smx->pfBall2); - free(smx->iMark); - free(smx->pq); - free(smx); - } - - -void smBallSearch(SMX smx,float fBall2,float *ri) -{ - KDN *c; - PARTICLE *p; - int cell,cp,ct,pj; - float fDist2,dx,dy,dz,lx,ly,lz,sx,sy,sz,x,y,z; - PQ *pq; - PQ_STATIC; - - c = smx->kd->kdNodes; - p = smx->kd->p; - pq = smx->pqHead; - x = ri[0]; - y = ri[1]; - z = ri[2]; - lx = smx->fPeriod[0]; - ly = smx->fPeriod[1]; - lz = smx->fPeriod[2]; - cell = ROOT; - /* - ** First find the "local" Bucket. - ** This could mearly be the closest bucket to ri[3]. - */ - while (cell < smx->kd->nSplit) { - if (ri[c[cell].iDim] < c[cell].fSplit) cell = LOWER(cell); - else cell = UPPER(cell); - } - /* - ** Now start the search from the bucket given by cell! - */ - for (pj=c[cell].pLower;pj<=c[cell].pUpper;++pj) { - dx = x - NP_POS(smx->kd, pj, 0); - dy = y - NP_POS(smx->kd, pj, 1); - dz = z - NP_POS(smx->kd, pj, 2); - fDist2 = dx*dx + dy*dy + dz*dz; - if (fDist2 < fBall2) { - if (smx->iMark[pj]) continue; - smx->iMark[pq->p] = 0; - smx->iMark[pj] = 1; - pq->fKey = fDist2; - pq->p = pj; - pq->ax = 0.0; - pq->ay = 0.0; - pq->az = 0.0; - PQ_REPLACE(pq); - fBall2 = pq->fKey; - } - } - while (cell != ROOT) { - cp = SIBLING(cell); - ct = cp; - SETNEXT(ct); - while (1) { - INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz); - /* - ** We have an intersection to test. - */ - if (cp < smx->kd->nSplit) { - cp = LOWER(cp); - continue; - } - else { - for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { - dx = sx - NP_POS(smx->kd, pj, 0); - dy = sy - NP_POS(smx->kd, pj, 1); - dz = sz - NP_POS(smx->kd, pj, 2); - fDist2 = dx*dx + dy*dy + dz*dz; - if (fDist2 < fBall2) { - if (smx->iMark[pj]) continue; - smx->iMark[pq->p] = 0; - smx->iMark[pj] = 1; - pq->fKey = fDist2; - pq->p = pj; - pq->ax = sx - x; - pq->ay = sy - y; - pq->az = sz - z; - PQ_REPLACE(pq); - fBall2 = pq->fKey; - } - } - } - GetNextCell: - SETNEXT(cp); - if (cp == ct) break; - } - cell = PARENT(cell); - } - smx->pqHead = pq; - } - - -int smBallGather(SMX smx,float fBall2,float *ri) -{ - KDN *c; - PARTICLE *p; - int pj,nCnt,cp,nSplit; - float dx,dy,dz,x,y,z,lx,ly,lz,sx,sy,sz,fDist2; - - c = smx->kd->kdNodes; - p = smx->kd->p; - nSplit = smx->kd->nSplit; - lx = smx->fPeriod[0]; - ly = smx->fPeriod[1]; - lz = smx->fPeriod[2]; - x = ri[0]; - y = ri[1]; - z = ri[2]; - nCnt = 0; - cp = ROOT; - while (1) { - INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz); - /* - ** We have an intersection to test. - */ - if (cp < nSplit) { - cp = LOWER(cp); - continue; - } - else { - for (pj=c[cp].pLower;pj<=c[cp].pUpper;++pj) { - dx = sx - NP_POS(smx->kd, pj, 0); - dy = sy - NP_POS(smx->kd, pj, 1); - dz = sz - NP_POS(smx->kd, pj, 2); - fDist2 = dx*dx + dy*dy + dz*dz; - if (fDist2 < fBall2) { - smx->fList[nCnt] = fDist2; - smx->pList[nCnt++] = pj; - /* Insert debugging flag here */ - if (nCnt > smx->nListSize) { - fprintf(stderr,"nCnt too big.\n"); - } - } - } - } - GetNextCell: - SETNEXT(cp); - if (cp == ROOT) break; - } - assert(nCnt <= smx->nListSize); - return(nCnt); - } - - -void smSmooth(SMX smx,void (*fncSmooth)(SMX,int,int,int *,float *)) -{ - KDN *c; - PARTICLE *p; - PQ *pq,*pqLast; - PQ_STATIC; - int cell; - int pi,pin,pj,pNext,nCnt,nSmooth; - float dx,dy,dz,x,y,z,h2,ax,ay,az; - float temp_ri[3]; - - - for (pi=0;pikd->nActive;++pi) { - if (IMARK) smx->pfBall2[pi] = -1.0; - else smx->pfBall2[pi] = 1.0; /* pretend it is already done! */ - } - smx->pfBall2[smx->kd->nActive] = -1.0; /* stop condition */ - for (pi=0;pikd->nActive;++pi) { - smx->iMark[pi] = 0; - } - pqLast = &smx->pq[smx->nSmooth-1]; - c = smx->kd->kdNodes; - p = smx->kd->p; - nSmooth = smx->nSmooth; - /* - ** Initialize Priority Queue. - */ - pin = 0; - pNext = 1; - ax = 0.0; - ay = 0.0; - az = 0.0; - for (pq=smx->pq,pj=0;pq<=pqLast;++pq,++pj) { - smx->iMark[pj] = 1; - pq->p = pj; - pq->ax = ax; - pq->ay = ay; - pq->az = az; - } - while (1) { - if (smx->pfBall2[pin] >= 0) { - /* - ** Find next particle which is not done, and load the - ** priority queue with nSmooth number of particles. - */ - while (smx->pfBall2[pNext] >= 0) ++pNext; - /* - ** Check if we are really finished. - */ - if (pNext == smx->kd->nActive) break; - pi = pNext; - ++pNext; - x = NP_POS(smx->kd, pi, 0); - y = NP_POS(smx->kd, pi, 1); - z = NP_POS(smx->kd, pi, 2); - /* printf("%"ISYM": %"GSYM" %"GSYM" %"GSYM"\n", pi, x, y, z); */ - /* - ** First find the "local" Bucket. - ** This could mearly be the closest bucket to ri[3]. - */ - cell = ROOT; - while (cell < smx->kd->nSplit) { - if (NP_POS(smx->kd, pi, c[cell].iDim) < c[cell].fSplit) - cell = LOWER(cell); - else - cell = UPPER(cell); - } - /* - ** Remove everything from the queue. - */ - smx->pqHead = NULL; - for (pq=smx->pq;pq<=pqLast;++pq) smx->iMark[pq->p] = 0; - /* - ** Add everything from pj up to and including pj+nSmooth-1. - */ - pj = c[cell].pLower; - if (pj > smx->kd->nActive - nSmooth) - pj = smx->kd->nActive - nSmooth; - for (pq=smx->pq;pq<=pqLast;++pq) { - smx->iMark[pj] = 1; - dx = x - NP_POS(smx->kd, pj, 0); - dy = y - NP_POS(smx->kd, pj, 1); - dz = z - NP_POS(smx->kd, pj, 2); - pq->fKey = dx*dx + dy*dy + dz*dz; - pq->p = pj++; - pq->ax = 0.0; - pq->ay = 0.0; - pq->az = 0.0; - } - PQ_BUILD(smx->pq,nSmooth,smx->pqHead); - } - else { - /* - ** Calculate the priority queue using the previous particles! - */ - pi = pin; - x = NP_POS(smx->kd, pi, 0); - y = NP_POS(smx->kd, pi, 1); - z = NP_POS(smx->kd, pi, 2); - smx->pqHead = NULL; - for (pq=smx->pq;pq<=pqLast;++pq) { - pq->ax -= ax; - pq->ay -= ay; - pq->az -= az; - dx = x + pq->ax - NP_POS(smx->kd, pq->p, 0); - dy = y + pq->ay - NP_POS(smx->kd, pq->p, 1); - dz = z + pq->az - NP_POS(smx->kd, pq->p, 2); - pq->fKey = dx*dx + dy*dy + dz*dz; - } - PQ_BUILD(smx->pq,nSmooth,smx->pqHead); - ax = 0.0; - ay = 0.0; - az = 0.0; - } - temp_ri[0] = NP_POS(smx->kd, pi, 0); - temp_ri[1] = NP_POS(smx->kd, pi, 1); - temp_ri[2] = NP_POS(smx->kd, pi, 2); - smBallSearch(smx,smx->pqHead->fKey,temp_ri); - smx->pfBall2[pi] = smx->pqHead->fKey; - /* - ** Pick next particle, 'pin'. - ** Create fList and pList for function 'fncSmooth'. - */ - pin = pi; - nCnt = 0; - h2 = smx->pqHead->fKey; - for (pq=smx->pq;pq<=pqLast;++pq) { - if (pq == smx->pqHead) continue; - smx->pList[nCnt] = pq->p; - smx->fList[nCnt++] = pq->fKey; - if (smx->pfBall2[pq->p] >= 0) continue; - if (pq->fKey < h2) { - pin = pq->p; - h2 = pq->fKey; - ax = pq->ax; - ay = pq->ay; - az = pq->az; - } - } - (*fncSmooth)(smx,pi,nCnt,smx->pList,smx->fList); - } - } - - -void smReSmooth(SMX smx,void (*fncSmooth)(SMX,int,int,int *,float *)) -{ - PARTICLE *p; - int pi,nSmooth; - float temp_ri[3]; - - p = smx->kd->p; - for (pi=0;pikd->nActive;++pi) { - if (IMARK == 0) continue; - /* - ** Do a Ball Gather at the radius of the most distant particle - ** which is smDensity sets in smx->pBall[pi]. - */ - temp_ri[0] = NP_POS(smx->kd, pi, 0); - temp_ri[1] = NP_POS(smx->kd, pi, 1); - temp_ri[2] = NP_POS(smx->kd, pi, 2); - nSmooth = smBallGather(smx,smx->pfBall2[pi],temp_ri); - (*fncSmooth)(smx,pi,nSmooth,smx->pList,smx->fList); - } - } - - -void smDensity(SMX smx,int pi,int nSmooth,int *pList,float *fList) -{ - float ih2,r2,rs,fDensity; - int i,pj; - - ih2 = 4.0/smx->pfBall2[pi]; - fDensity = 0.0; - for (i=0;ikd, pj); -#else - fDensity += rs*smx->kd->fMass; -#endif - } - NP_DENS(smx->kd, pi) = M_1_PI*sqrt(ih2)*ih2*fDensity; - } - - -void smDensitySym(SMX smx,int pi,int nSmooth,int *pList,float *fList) -{ - float fNorm,ih2,r2,rs; - int i,pj; - - ih2 = 4.0/smx->pfBall2[pi]; - fNorm = 0.5*M_1_PI*sqrt(ih2)*ih2; - for (i=0;ikd, pi) += rs*NP_MASS(smx->kd, pj); - NP_DENS(smx->kd, pj) += rs*NP_MASS(smx->kd, pi); -#else - smx->kd->p[pi].fDensity += rs*smx->kd->fMass; - smx->kd->p[pj].fDensity += rs*smx->kd->fMass; -#endif - } - } - -/* I'm not using the following function, but I left it here in case someone -wants the densities outputted in Tipsy format. But you're probably better -off just fetching the smooth() program from the HPCC web site... */ - -void smOutDensity(SMX smx,FILE *fp) -{ - int i,iCnt; - - fprintf(fp,"%"ISYM"\n",smx->kd->nParticles); - iCnt = 0; - for (i=0;ikd->nGas;++i) { - if (smx->kd->bGas) { - if (IMARK) - fprintf(fp,"%.8"GSYM"\n",NP_DENS(smx->kd, iCnt)); - else fprintf(fp,"0\n"); - ++iCnt; - } - else fprintf(fp,"0\n"); - } - for (i=0;ikd->nDark;++i) { - if (smx->kd->bDark) { - if (IMARK) - fprintf(fp,"%.8"GSYM"\n",NP_DENS(smx->kd, iCnt)); - else fprintf(fp,"0\n"); - ++iCnt; - } - else fprintf(fp,"0\n"); - } - for (i=0;ikd->nStar;++i) { - if (smx->kd->bStar) { - if (IMARK) - fprintf(fp,"%.8"GSYM"\n",NP_DENS(smx->kd, iCnt)); - else fprintf(fp,"0\n"); - ++iCnt; - } - else fprintf(fp,"0\n"); - } -} - - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/kd.h --- a/yt/lagos/hop/kd.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -/* KD.H */ -/* This was written by Joachim Stadel and the NASA HPCC ESS at -the University of Washington Department of Astronomy as part of -the SMOOTH program, v2.0.1. -URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ - -/* DJE--I have made a few alterations to the PARTICLE structure -in order to reduce memory consumption. */ - -/* HOP Version 1.0 (12/15/97) -- Original Release */ - -/* GLB--set different masses on */ - -#define DIFFERENT_MASSES - -//#include "macros_and_parameters.h" - -#ifndef KD_HINCLUDED -#define KD_HINCLUDED - -#include "Python.h" -#include "numpy/ndarrayobject.h" - -#define ROOT 1 -#define LOWER(i) (i<<1) -#define UPPER(i) ((i<<1)+1) -#define PARENT(i) (i>>1) -#define SIBLING(i) ((i&1)?i-1:i+1) -#define SETNEXT(i)\ -{\ - while (i&1) i=i>>1;\ - ++i;\ - } - -#define DARK 1 -#define GAS 2 -#define STAR 4 - -typedef struct Particle { - int np_index; - int iHop; - int iOrder; -#if 0 - float r[3]; - float fDensity; - // int iID; /* the real ID of the particle S. Skory */ - int iHop; /* DJE: The number of the highest-density neighbor; - Later, the group number. */ -#ifdef DIFFERENT_MASSES - float fMass; -#endif - /* DJE: The following are unused and cost too much memory to keep */ - /* float v[3]; */ - /* float fMass; */ - /* int iMark; */ - /* float vMean[3]; */ - /* float fVelDisp2; */ -#endif - } PARTICLE; - -typedef struct bndBound { - float fMin[3]; - float fMax[3]; - } BND; - -typedef struct kdNode { - float fSplit; - BND bnd; - int iDim; - int pLower; - int pUpper; - } KDN; - -typedef struct kdContext { - int nBucket; - int nParticles; - int nDark; - int nGas; - int nStar; - int bDark; - int bGas; - int bStar; - int nActive; - float fTime; - BND bnd; - int nLevels; - int nNodes; - int nSplit; - float fMass; /* DJE: If all particles have the same mass */ - PARTICLE *p; - KDN *kdNodes; - int uSecond; - int uMicro; - npy_float64 *np_densities; - npy_float64 *np_pos[3]; - npy_float64 *np_masses; - float totalmass; - } * KD; - - -#define INTERSECT(c,cp,fBall2,lx,ly,lz,x,y,z,sx,sy,sz)\ -{\ - float dx,dy,dz,dx1,dy1,dz1,fDist2;\ - dx = c[cp].bnd.fMin[0]-x;\ - dx1 = x-c[cp].bnd.fMax[0];\ - dy = c[cp].bnd.fMin[1]-y;\ - dy1 = y-c[cp].bnd.fMax[1];\ - dz = c[cp].bnd.fMin[2]-z;\ - dz1 = z-c[cp].bnd.fMax[2];\ - if (dx > 0.0) {\ - dx1 += lx;\ - if (dx1 < dx) {\ - fDist2 = dx1*dx1;\ - sx = x+lx;\ - }\ - else {\ - fDist2 = dx*dx;\ - sx = x;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else if (dx1 > 0.0) {\ - dx += lx;\ - if (dx < dx1) {\ - fDist2 = dx*dx;\ - sx = x-lx;\ - }\ - else {\ - fDist2 = dx1*dx1;\ - sx = x;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else {\ - fDist2 = 0.0;\ - sx = x;\ - }\ - if (dy > 0.0) {\ - dy1 += ly;\ - if (dy1 < dy) {\ - fDist2 += dy1*dy1;\ - sy = y+ly;\ - }\ - else {\ - fDist2 += dy*dy;\ - sy = y;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else if (dy1 > 0.0) {\ - dy += ly;\ - if (dy < dy1) {\ - fDist2 += dy*dy;\ - sy = y-ly;\ - }\ - else {\ - fDist2 += dy1*dy1;\ - sy = y;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else {\ - sy = y;\ - }\ - if (dz > 0.0) {\ - dz1 += lz;\ - if (dz1 < dz) {\ - fDist2 += dz1*dz1;\ - sz = z+lz;\ - }\ - else {\ - fDist2 += dz*dz;\ - sz = z;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else if (dz1 > 0.0) {\ - dz += lz;\ - if (dz < dz1) {\ - fDist2 += dz*dz;\ - sz = z-lz;\ - }\ - else {\ - fDist2 += dz1*dz1;\ - sz = z;\ - }\ - if (fDist2 > fBall2) goto GetNextCell;\ - }\ - else {\ - sz = z;\ - }\ - } - - -void kdTime(KD,int *,int *); -int kdInit(KD *,int); -int kdReadTipsy(KD,FILE *,int,int,int); -void kdInMark(KD,char *); -int kdBuildTree(KD); -void kdOrder(KD); -void kdFinish(KD); - -#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/setup.py --- a/yt/lagos/hop/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#!/usr/bin/env python -import setuptools -import os, sys, os.path - -import os.path - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('hop',parent_package,top_path) - config.make_config_py() # installs __config__.py - config.make_svn_version_py() - config.add_extension("EnzoHop", sources= - ["EnzoHop.c", - "hop_hop.c", - "hop_kd.c", - "hop_regroup.c", - "hop_slice.c", - "hop_smooth.c",]) - return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/slice.h --- a/yt/lagos/hop/slice.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* SLICE.H, Daniel Eisenstein, 1997 */ -/* Based on a paper by Daniel Eisenstein & Piet Hut, -"HOP: A New Group-Finding Algorithm for N-body Simulations." -See the included documentation or view it at -http://www.sns.ias.edu/~eisenste/hop/hop_doc.html */ - -/* Version 1.0 (12/15/97) -- Original Release */ - -#ifndef NBODYUTIL_H -#define NBODYUTIL_H - -#define RHOCRIT 277.5 /* in h^2 Msun/kpc^3 */ -#define HTIME 9.7776 /* in h^-1 Gyr */ -#define GNEWT 4.51e-6 /* in kpc^3/Msun/Gyr^2, h cancels */ -#define KMS 0.975 /* to convert from kpc/Gyr to km/s */ - -#define PI 3.141592654 -#define ROOT2 1.414213562 -#define ROOTPI2 1.253314137 /* sqrt(Pi/2) */ - -#include -#include -#include -//#include "macros_and_parameters.h" - -/* Structure to hold data from one time slice and info about the slice */ -/* This needn't hold all of the points; it might just hold some subset */ -/* Hence, data vectors are just given as arrays here */ -/* Usage: pid[] Array goes from 0 to pid[0]. pid is NULL if the particle -numbering is just the trivial mapping. Kinematic arrays go from 1 to numlist -and can be NULL if the data hasn't been read. Numlist==pid[0] often */ - -typedef struct slicestruct { -#ifdef NOT_USED - /* First, some generic stuff about the simulation */ - float omega, lambda, curv; - float h0; /* H_0 = 100 km/s/Mpc * h0 */ - float specn, gamma; /* The spectral index and BBKS PS Gamma */ - float sigma8; /* At z=0 */ - - /* Next, some information about this slice in particular */ - float z, a, t, growth; - /* a=1 at z=0, g=a at early times */ - float hubb; /* This is a*H(z), but without h0. So it's 0.1 km/s/kpc - redshifted appropriately. This is used to relate - comoving positions and peculiar velocities */ - - /* Now some information about the data */ - int numblocks; /* Number of blocks in the data file */ - int numperblock; /* Number of particles per block */ - float masspart; /* Mass per particle in h^-1 Msun */ - float boxsize; /* Comoving size of box in h^-1 kpc */ - float physsize; /* Physical Size in h^-1 kpc */ - float velscale; /* To turn raw velocity data into peculiar vel in km/s*/ -#endif - - int numpart; /* Total number of particles in the simulation */ - /* Now the data itself */ - int *pid; /* The id number of the particle */ - /* pid[0] holds the number of particles in the list */ - int offset; /* If pid==NULL, then the arrays are consecutively - numbered, starting from offset+1 */ - int numlist; /* Length of arrays below, set when allocated */ - float *px, *py, *pz, *vx, *vy, *vz; /* The kinematic information */ - - /* And here's the group tag information */ - int *ntag; /* Only stored for the numlist above */ - //int *ID; /* The real, true ID of the particle. S Skory */ - int numgroups; /* The number of groups read out of the tag file */ -} Slice; /* Type Slice is defined */ - -/* Prototypes */ -Slice *newslice(); -void free_tags(Slice *s); -void free_data(Slice *s); -void free_slice(Slice *s); -int f77write(FILE *f, void *p, int len); -int f77read(FILE *f, void *p, int len); -float *vector(long nl, long nh); -int *ivector(long nl, long nh); -void free_vector(float *v, long nl, long nh); -void free_ivector(int *v, long nl, long nh); - -void myerror(char *message); -void mywarn(char *message); - -int read_header(FILE *f, Slice *s); -void normalizedata(Slice *s, int conp, int conv); -int read_alldata(FILE *f, FILE *ftag, Slice *s, int conp, int conv); -int read_partdata(FILE *f, FILE *ftag, Slice *s); - -int readtag(FILE *f, int numread, int *ntag); -int skiptagheader(FILE *f, Slice *s); -int readalltags(FILE *f, Slice *s); - - -#endif /* NBODYUTIL_H */ diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/hop/smooth.h --- a/yt/lagos/hop/smooth.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/* SMOOTH.H */ -/* This was written by Joachim Stadel and the NASA HPCC ESS at -the University of Washington Department of Astronomy as part of -the SMOOTH program, v2.0.1. -URL: http://www-hpcc.astro.washington.edu/tools/SMOOTH */ - -/* DJE--I have made a few additions to the SMX structure -in order to store information necessary for HOP. I have also -added the Boundary structure. */ - -/* HOP Version 1.0 (12/15/97) -- Original Release */ - -#ifndef SMOOTH_HINCLUDED -#define SMOOTH_HINCLUDED - -#include "kd.h" -//#include "macros_and_parameters.h" - -#define RESMOOTH_SAFE 30 - -/* DJE: Define this structure to hold the boundary data. */ -typedef struct boundarystruct { - int nGroup1, nGroup2; /* The two groups involved, ordered such - that nGroup1>1];\ - (pq)[PQ_j].pqFromExt = &(pq)[(PQ_j+(n))>>1];\ - }\ - } - - -#define PQ_BUILD(pq,n,q)\ -{\ - for (PQ_j=(n)-1;PQ_j>0;--PQ_j) {\ - PQ_i = (PQ_j<<1);\ - if (PQ_i < (n)) PQ_t = (pq)[PQ_i].pqWinner;\ - else PQ_t = &(pq)[PQ_i-(n)];\ - ++PQ_i;\ - if (PQ_i < (n)) PQ_lt = (pq)[PQ_i].pqWinner;\ - else PQ_lt = &(pq)[PQ_i-(n)];\ - if (PQ_t->fKey < PQ_lt->fKey) {\ - (pq)[PQ_j].pqLoser = PQ_t;\ - (pq)[PQ_j].pqWinner = PQ_lt;\ - }\ - else {\ - (pq)[PQ_j].pqLoser = PQ_lt;\ - (pq)[PQ_j].pqWinner = PQ_t;\ - }\ - }\ - (q) = (pq)[1].pqWinner;\ - } - - -#define PQ_REPLACE(q)\ -{\ - PQ_t = (q)->pqFromExt;\ - while (PQ_t) {\ - if (PQ_t->pqLoser->fKey > (q)->fKey) {\ - PQ_lt = PQ_t->pqLoser;\ - PQ_t->pqLoser = (q);\ - (q) = PQ_lt;\ - }\ - PQ_t = PQ_t->pqFromInt;\ - }\ - } - - - -int smInit(SMX *,KD,int,float *); -void smFinish(SMX); -void smBallSearch(SMX,float,float *); -int smBallGather(SMX,float,float *); -void smSmooth(SMX,void (*)(SMX,int,int,int *,float *)); -void smReSmooth(SMX,void (*)(SMX,int,int,int *,float *)); -void smDensity(SMX,int,int,int *,float *); -void smDensitySym(SMX,int,int,int *,float *); -void smMeanVel(SMX,int,int,int *,float *); -void smMeanVelSym(SMX,int,int,int *,float *); -void smVelDisp(SMX,int,int,int *,float *); -void smVelDispSym(SMX,int,int,int *,float *); -void smNull(SMX,int,int,int *,float *); -void smOutDensity(SMX,FILE *); -void smOutMeanVel(SMX,FILE *); -void smOutVelDisp(SMX,FILE *); -void smOutPhase(SMX,FILE *); -void smOutMach(SMX,FILE *); -void smOutSpeed(SMX,FILE *); - -#endif - - - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/kd.py --- a/yt/lagos/kd.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ -""" -Python kD Tree - -Author: Michael Knight -Affiliation: ? -Note: Code is based on , -with periodicity added and a few other cosmetic changes. There is no contact -infomation on that page, and this code's license is a bit uncertain. -Author: Stephen Skory -Affiliation: UCSD Physics/CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -from yt.lagos import * - -from bisect import insort - -class Point:pass - -class Node: - - def _printOut(self,depth = 0): - """ - iteratively print out the kd tree nodes, depth really isn't a user-set - parameter. - """ - for i in range(0,depth): - print "....", - print "point count =", self.pointCount, "rect =", \ - self.hyperRect._nodeToString(), '\n' #"points =",self.points - if (self.leftChild is not None): - for i in range(0,depth): - print "....", - print "left: " - self.leftChild._printOut(depth+1) - if (self.rightChild is not None): - for i in range(0,depth): - print "....", - print "right: " - self.rightChild._printOut(depth+1) - - def _buildBoundingHyperRect(self,points): - self.hyperRect = HyperRect() - self.hyperRect._buildBoundingHyperRect(points) - -def getFastDistance(a,b,period): - """ - returns the square of the distance between points a and b, - using periodic boundary conditions 'period'. - """ - dim = len(b); - total = 0; - for i in range(0,dim): - delta = min(abs(a[i] - b[i]), period[i] - abs(a[i] - b[i])); - total = total + (delta *delta) - return total - -class Neighbors: - - def _addNeighbors(self,node,query,period): - """ - for each point in this node, calculate the distance to the query point, - if it's close enough add it to the list .points using insort - """ - for i in range(0,node.pointCount): - dist = getFastDistance(node.points[i].data,query,period) - if (dist < self.minDistanceSquared): - item = [dist,node.points[i]] - insort(self.points,item) - if (len(self.points) > self.k): - self.points = self.points[0:self.k] - - if (len(self.points) == self.k): - self.minDistanceSquared = self.points[self.k-1][0] - return; - -class HyperRect: - def _buildBoundingHyperRect(self,points): - """ - find the extremities of the hypercube. - """ - self.k = len(points[0].data) - self.dims = range(0,self.k) - high = points[0].data[:] - low = points[0].data[:] - for i in range(0,len(points)): - for j in self.dims: - point = points[i].data[j] - if (high[j] < point): - high[j] = point - if (low[j] > point): - low[j] = point - self.high = high - self.low = low - return - - def _getWidestDimension(self): - """ - get the widest dimension of the points in order to find the dimension - to bisect. - """ - widest =0 - widestDim =-1 - for i in self.dims: - width = self.high[i] - self.low[i] - if (width > widest): - widestDim =i - widest = width - self.widest = widest; - self.widestDim = widestDim; - return self.widestDim - - def _getWidestDimensionWidth(self): # I don't know why this is here. - return self.widest - - def _nodeToString(self): - return "high =",self.high,"low =",self.low, - - def _getMinDistance(self,query,period): - """ - find the minimum distance squared to a corner of the hypercube - from the query point using periodicity. - """ - total = 0.0 - for i in self.dims: - delta = 0.0 - min_high = min(abs(query[i] - self.high[i]), \ - period[i] - abs(query[i] - self.high[i])) - min_low = min(abs(query[i] - self.low[i]), \ - period[i] - abs(query[i] - self.low[i])) - delta = min(min_low,min_high) - total = total + (delta*delta) - return total; - -def buildKdHyperRectTree(points,rootMin=3): - """ - Recursively build the kdTree, adding nodes as needed until all have no more - than rootMin points. The final nodes are called leafs, which contain the - point data. - """ - if (points is None or len(points) ==0): - return None - n = Node() # make a new node - n._buildBoundingHyperRect(points) # build the hyper rect for these points - # this will find the top left and botom - # right of all given points. - - leaf = False - # If the size of points is small enough, this node is a leaf - if len(points) <= rootMin: - leaf = True - splitDim = -1 - - if (not leaf): - # get the widest dimension to split n to maximize splitting affect - splitDim = n.hyperRect._getWidestDimension() - # do we have a bunch of children at the same point? - if (n.hyperRect._getWidestDimensionWidth() == 0.0): - left = True - #init the node - n.pointCount = len(points) - n.points = None - n.leftChild = None - n.rightChild = None - n.points = None - - if (leaf or len(points)==0): - n.points = points # we are a leaf so just store all points in the rect - else: - # sort by the best split dimension - temp = [] - for index,p in enumerate(points): - insort(temp,[p.data[splitDim],index]) - temp2 = points[:] - for index,t in enumerate(temp): - temp2[index] = points[t[1]] - points = temp2[:] - del temp, temp2 - #points.sort(key=lambda points: points.data[splitDim]) - median = len(points)/2 # get the median - # and split left for smaller values in splitDim, right for larger - n.leftChild = buildKdHyperRectTree(points[0:(median+1)], rootMin) - if (median+1 < len(points)): - n.rightChild = buildKdHyperRectTree(points[median+1:], rootMin) - return n; - -def getKNN(query,node, neighbors,distanceSquared,period): - """ - Recursively walk the kd tree, limited by *distanceSquared* to the extrema of - the hypercubes, only finding distances to the query point in leaf nodes. - *neighbors* is a Neighbors object, and needs to be initialized bofore - calling this. *period* is a list or array of the period for each dimension - of the hypercube. - """ - - # test to see if the query point is inside this node - # <= and >= on both ends is okay, it's better to be inclusive and it - # prevents problems with particles on boundaries - for i in node.hyperRect.dims: - if query[i] <= node.hyperRect.high[i] and \ - query[i] >= node.hyperRect.low[i]: - inside = True - else: - inside = False - break - - # if this node is close enough (the distances are calculated in the previous - # iteration), or if the query point is inside the node, continue on - if True or inside: - # leafs don't have children, so this tests to see if this node - # is a leaf, and if it is a leaf, calculate distances to the query point - if (node.leftChild is None): - # add to neighbors.points - neighbors._addNeighbors(node,query,period) - # if this node is not a leaf, find out the distance to its children, - # and then continue the iteration down the kd tree. - else: - distLeft = node.leftChild.hyperRect._getMinDistance(query,period) - distRight = node.rightChild.hyperRect._getMinDistance(query,period) - if (distLeft < distRight): - getKNN(query,node.leftChild,neighbors,distLeft,period) - getKNN(query,node.rightChild,neighbors,distRight,period) - else: - getKNN(query,node.rightChild,neighbors,distRight,period) - getKNN(query,node.leftChild,neighbors,distLeft,period) diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/object_finding_mixin.py --- a/yt/lagos/object_finding_mixin.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -""" -AMR hierarchy container class - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -from yt.arraytypes import * -from yt.logger import lagosLogger as mylog -from EnzoDefs import NUMTOCHECK - -class ObjectFindingMixin(object): - - def find_ray_grids(self, coord, axis): - """ - Returns the (objects, indices) of grids that an (x,y) ray intersects - along *axis* - """ - # Let's figure out which grids are on the slice - mask=na.ones(self.num_grids) - # So if gRE > coord, we get a mask, if not, we get a zero - # if gLE > coord, we get a zero, if not, mask - # Thus, if the coordinate is between the two edges, we win! - na.choose(na.greater(self.grid_right_edge[:,x_dict[axis]],coord[0]),(0,mask),mask) - na.choose(na.greater(self.grid_left_edge[:,x_dict[axis]],coord[0]),(mask,0),mask) - na.choose(na.greater(self.grid_right_edge[:,y_dict[axis]],coord[1]),(0,mask),mask) - na.choose(na.greater(self.grid_left_edge[:,y_dict[axis]],coord[1]),(mask,0),mask) - ind = na.where(mask == 1) - return self.grids[ind], ind - - def find_max(self, field, finest_levels = True): - """ - Returns (value, center) of location of maximum for a given field. - """ - if (field, finest_levels) in self._max_locations: - return self._max_locations[(field, finest_levels)] - mg, mc, mv, pos = self.find_max_cell_location(field, finest_levels) - self._max_locations[(field, finest_levels)] = (mv, pos) - return mv, pos - - def find_max_cell_location(self, field, finest_levels = True): - if finest_levels is True: - gi = (self.grid_levels >= self.max_level - NUMTOCHECK).ravel() - source = self.grid_collection([0.0]*3, self.grids[gi]) - else: - source = self.all_data() - mylog.debug("Searching %s grids for maximum value of %s", - len(source._grids), field) - max_val, maxi, mx, my, mz, mg = \ - source.quantities["MaxLocation"]( field, lazy_reader=True) - max_grid = self.grids[mg] - mc = na.unravel_index(maxi, max_grid.ActiveDimensions) - mylog.info("Max Value is %0.5e at %0.16f %0.16f %0.16f in grid %s at level %s %s", \ - max_val, mx, my, mz, max_grid, max_grid.Level, mc) - self.parameters["Max%sValue" % (field)] = max_val - self.parameters["Max%sPos" % (field)] = "%s" % ((mx,my,mz),) - return max_grid, mc, max_val, na.array((mx,my,mz), dtype='float64') - - def find_min(self, field): - """ - Returns (value, center) of location of minimum for a given field - """ - gI = na.where(self.grid_levels >= 0) # Slow but pedantic - minVal = 1e100 - for grid in self.grids[gI[0]]: - mylog.debug("Checking %s (level %s)", grid.id, grid.Level) - val, coord = grid.find_min(field) - if val < minVal: - minCoord = coord - minVal = val - minGrid = grid - mc = na.array(minCoord) - pos=minGrid.get_position(mc) - mylog.info("Min Value is %0.5e at %0.16f %0.16f %0.16f in grid %s at level %s", \ - minVal, pos[0], pos[1], pos[2], minGrid, minGrid.Level) - self.center = pos - self.parameters["Min%sValue" % (field)] = minVal - self.parameters["Min%sPos" % (field)] = "%s" % (pos) - return minVal, pos - - def find_point(self, coord): - """ - Returns the (objects, indices) of grids containing an (x,y,z) point - """ - mask=na.ones(self.num_grids) - for i in xrange(len(coord)): - na.choose(na.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask) - na.choose(na.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask) - ind = na.where(mask == 1) - return self.grids[ind], ind - - def find_slice_grids(self, coord, axis): - """ - Returns the (objects, indices) of grids that a slice intersects along - *axis* - """ - # Let's figure out which grids are on the slice - mask=na.ones(self.num_grids) - # So if gRE > coord, we get a mask, if not, we get a zero - # if gLE > coord, we get a zero, if not, mask - # Thus, if the coordinate is between the edges, we win! - #ind = na.where( na.logical_and(self.grid_right_edge[:,axis] > coord, \ - #self.grid_left_edge[:,axis] < coord)) - na.choose(na.greater(self.grid_right_edge[:,axis],coord),(0,mask),mask) - na.choose(na.greater(self.grid_left_edge[:,axis],coord),(mask,0),mask) - ind = na.where(mask == 1) - return self.grids[ind], ind - - def find_sphere_grids(self, center, radius): - """ - Returns objects, indices of grids within a sphere - """ - centers = (self.grid_right_edge + self.grid_left_edge)/2.0 - long_axis = na.maximum.reduce(self.grid_right_edge - self.grid_left_edge, 1) - t = na.abs(centers - center) - DW = self.parameter_file["DomainRightEdge"] \ - - self.parameter_file["DomainLeftEdge"] - na.minimum(t, na.abs(DW-t), t) - dist = na.sqrt(na.sum((t**2.0), axis=1)) - gridI = na.where(dist < (radius + long_axis)) - return self.grids[gridI], gridI - - def get_box_grids(self, left_edge, right_edge): - """ - Gets back all the grids between a left edge and right edge - """ - grid_i = na.where((na.all(self.grid_right_edge > left_edge, axis=1) - & na.all(self.grid_left_edge < right_edge, axis=1)) == True) - return self.grids[grid_i], grid_i - - def get_periodic_box_grids(self, left_edge, right_edge): - left_edge = na.array(left_edge) - right_edge = na.array(right_edge) - mask = na.zeros(self.grids.shape, dtype='bool') - dl = self.parameters["DomainLeftEdge"] - dr = self.parameters["DomainRightEdge"] - db = right_edge - left_edge - for off_x in [-1, 0, 1]: - nle = left_edge.copy() - nre = left_edge.copy() - nle[0] = dl[0] + (dr[0]-dl[0])*off_x + left_edge[0] - for off_y in [-1, 0, 1]: - nle[1] = dl[1] + (dr[1]-dl[1])*off_y + left_edge[1] - for off_z in [-1, 0, 1]: - nle[2] = dl[2] + (dr[2]-dl[2])*off_z + left_edge[2] - nre = nle + db - g, gi = self.get_box_grids(nle, nre) - mask[gi] = True - return self.grids[mask], na.where(mask) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/parallelHOP/__init__.py --- a/yt/lagos/parallelHOP/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -from yt.lagos import * - -from parallelHOP import * diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/parallelHOP/parallelHOP.py --- a/yt/lagos/parallelHOP/parallelHOP.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1500 +0,0 @@ -""" -A implementation of the HOP algorithm that runs in parallel. - -Author: Stephen Skory -Affiliation: UCSD/CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 Stephen Skory. 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 . -""" - -from collections import defaultdict -import itertools, sys - -from yt.lagos import * -from yt.funcs import * -from yt.performance_counters import yt_counters, time_function -try: - from yt.extensions.kdtree import * -except ImportError: - mylog.debug("The Fortran kD-Tree did not import correctly.") - -class RunParallelHOP(ParallelAnalysisInterface): - def __init__(self,period, padding, num_neighbors, bounds, - xpos, ypos, zpos, index, mass, threshold=160.0, rearrange=True, - premerge=True): - self.threshold = threshold - self.rearrange = rearrange - self.premerge = premerge - self.saddlethresh = 2.5 * threshold - self.peakthresh = 3 * threshold - self.period = period - self.padding = padding - self.num_neighbors = num_neighbors - self.bounds = bounds - self.xpos = xpos - self.ypos = ypos - self.zpos = zpos - self.real_size = len(self.xpos) - self.index = na.array(index, dtype='int64') - self.mass = mass - self.padded_particles = [] - self.nMerge = 4 - yt_counters("chainHOP") - self.max_mem = 0 - self.__max_memory() - self._chain_hop() - yt_counters("chainHOP") - - def _global_bounds_neighbors(self): - """ - Build a dict of the boundaries of all the tasks, and figure out which - tasks are our geometric neighbors. - """ - self.neighbors = set([]) - self.mine, global_bounds = self._mpi_info_dict(self.bounds) - my_LE, my_RE = self.bounds - # Put the vertices into a big list, each row is - # array[x,y,z, taskID] - vertices = [] - my_vertices = [] - for taskID in global_bounds: - thisLE, thisRE = global_bounds[taskID] - if self.mine != taskID: - vertices.append(na.array([thisLE[0], thisLE[1], thisLE[2], taskID])) - vertices.append(na.array([thisLE[0], thisLE[1], thisRE[2], taskID])) - vertices.append(na.array([thisLE[0], thisRE[1], thisLE[2], taskID])) - vertices.append(na.array([thisRE[0], thisLE[1], thisLE[2], taskID])) - vertices.append(na.array([thisLE[0], thisRE[1], thisRE[2], taskID])) - vertices.append(na.array([thisRE[0], thisLE[1], thisRE[2], taskID])) - vertices.append(na.array([thisRE[0], thisRE[1], thisLE[2], taskID])) - vertices.append(na.array([thisRE[0], thisRE[1], thisRE[2], taskID])) - if self.mine == taskID: - my_vertices.append(na.array([thisLE[0], thisLE[1], thisLE[2]])) - my_vertices.append(na.array([thisLE[0], thisLE[1], thisRE[2]])) - my_vertices.append(na.array([thisLE[0], thisRE[1], thisLE[2]])) - my_vertices.append(na.array([thisRE[0], thisLE[1], thisLE[2]])) - my_vertices.append(na.array([thisLE[0], thisRE[1], thisRE[2]])) - my_vertices.append(na.array([thisRE[0], thisLE[1], thisRE[2]])) - my_vertices.append(na.array([thisRE[0], thisRE[1], thisLE[2]])) - my_vertices.append(na.array([thisRE[0], thisRE[1], thisRE[2]])) - # Find the neighbors we share corners with. Yes, this is lazy with - # a double loop, but it works and this is definitely not a performance - # bottleneck. - for my_vertex in my_vertices: - for vertex in vertices: - if vertex[3] in self.neighbors: continue - # If the corners touch, it's easy. This is the case if resizing - # (load-balancing) is turned off. - if (my_vertex % self.period == vertex[0:3] % self.period).all(): - self.neighbors.add(int(vertex[3])) - continue - # Also test to see if the distance to this corner is within - # max_padding, which is more likely the case with load-balancing - # turned on. - dx = min( na.fabs(my_vertex[0] - vertex[0]), \ - self.period[0] - na.fabs(my_vertex[0] - vertex[0])) - dy = min( na.fabs(my_vertex[1] - vertex[1]), \ - self.period[1] - na.fabs(my_vertex[1] - vertex[1])) - dz = min( na.fabs(my_vertex[2] - vertex[2]), \ - self.period[2] - na.fabs(my_vertex[2] - vertex[2])) - d = na.sqrt(dx*dx + dy*dy + dz*dz) - if d <= self.max_padding: - self.neighbors.add(int(vertex[3])) - # Faces and edges. - for dim in range(3): - dim1 = (dim + 1) % 3 - dim2 = (dim + 2) % 3 - left_face = my_LE[dim] - right_face = my_RE[dim] - for taskID in global_bounds: - if taskID == self.mine or taskID in self.neighbors: continue - thisLE, thisRE = global_bounds[taskID] - max1 = max(my_LE[dim1], thisLE[dim1]) - max2 = max(my_LE[dim2], thisLE[dim2]) - min1 = min(my_RE[dim1], thisRE[dim1]) - min2 = min(my_RE[dim2], thisRE[dim2]) - # Faces. - # First, faces that touch directly. - if (thisRE[dim] == left_face or thisRE[dim]%self.period[dim] == left_face) and \ - max1 <= min1 and max2 <= min2: - self.neighbors.add(taskID) - continue - elif (thisLE[dim] == right_face or thisLE[dim] == right_face%self.period[dim]) and \ - max1 <= min1 and max2 <= min2: - self.neighbors.add(taskID) - continue - # If an intervening subvolume has a width less than the padding - # (rare, but possible), a neighbor may not actually touch, so - # we need to account for that. - if (abs(thisRE[dim] - left_face) <= self.max_padding or \ - abs(thisRE[dim]%self.period[dim] - left_face) <= self.max_padding) and \ - max1 <= min1 and max2 <= min2: - self.neighbors.add(taskID) - continue - elif (abs(thisLE[dim] - right_face) <= self.max_padding or \ - abs(thisLE[dim] - right_face%self.period[dim]) <= self.max_padding) and \ - max1 <= min1 and max2 <= min2: - self.neighbors.add(taskID) - continue - # Edges. - # First, edges that touch. - elif (my_LE[dim] == (thisRE[dim]%self.period[dim]) and \ - my_LE[dim1] == (thisRE[dim1]%self.period[dim1]) and \ - max2 <= min2) or \ - (my_LE[dim] == (thisRE[dim]%self.period[dim]) and \ - my_LE[dim2] == (thisRE[dim2]%self.period[dim2]) and \ - max1 <= min1): - self.neighbors.add(taskID) - continue - elif ((my_RE[dim]%self.period[dim]) == thisLE[dim] and \ - (my_RE[dim1]%self.period[dim1]) == thisLE[dim1] and \ - max2 <= min2) or \ - ((my_RE[dim]%self.period[dim]) == thisLE[dim] and \ - (my_RE[dim2]%self.period[dim2]) == thisLE[dim2] and \ - max1 <= min1): - self.neighbors.add(taskID) - continue - # Now edges that don't touch, but are close. - if (abs(my_LE[dim] - thisRE[dim]%self.period[dim]) <= self.max_padding and \ - abs(my_LE[dim1] - thisRE[dim1]%self.period[dim1]) <= self.max_padding and \ - max2 <= min2) or \ - (abs(my_LE[dim] - thisRE[dim]%self.period[dim]) <= self.max_padding and \ - abs(my_LE[dim2] - thisRE[dim2]%self.period[dim2]) <= self.max_padding and \ - max1 <= min1): - self.neighbors.add(taskID) - continue - elif (abs(my_RE[dim]%self.period[dim] - thisLE[dim]) <= self.max_padding and \ - abs(my_RE[dim1]%self.period[dim1] - thisLE[dim1]) <= self.max_padding and \ - max2 <= min2) or \ - (abs(my_RE[dim]%self.period[dim] - thisLE[dim]) <= self.max_padding and \ - abs(my_RE[dim2]%self.period[dim2] - thisLE[dim2]) <= self.max_padding and \ - max1 <= min1): - self.neighbors.add(taskID) - continue - # Now we build a global dict of neighbor sets, and if a remote task - # lists us as their neighbor, we add them as our neighbor. This is - # probably not needed because the stuff above should be symmetric, - # but it isn't a big issue. - self.mine, global_neighbors = self._mpi_info_dict(self.neighbors) - for taskID in global_neighbors: - if taskID == self.mine: continue - if self.mine in global_neighbors[taskID]: - self.neighbors.add(taskID) - # We can remove ourselves from the set if it got added somehow. - self.neighbors.discard(self.mine) - # Clean up. - del global_neighbors, global_bounds, vertices, my_vertices - - def _global_padding(self, round): - """ - Find the maximum padding of all our neighbors, used to send our - annulus data. - """ - if round == 'first': - max_pad = na.max(self.padding) - self.mine, self.global_padding = self._mpi_info_dict(max_pad) - self.max_padding = max(self.global_padding.itervalues()) - elif round == 'second': - self.max_padding = 0. - for neighbor in self.neighbors: - self.max_padding = na.maximum(self.global_padding[neighbor], \ - self.max_padding) - - def _communicate_padding_data(self): - """ - Send the particles each of my neighbors need to build up their padding. - """ - yt_counters("Communicate discriminated padding") - # First build a global dict of the padded boundaries of all the tasks. - (LE, RE) = self.bounds - (LE_padding, RE_padding) = self.padding - temp_LE = LE - LE_padding - temp_RE = RE + RE_padding - expanded_bounds = (temp_LE, temp_RE) - self.mine, global_exp_bounds = self._mpi_info_dict(expanded_bounds) - send_real_indices = {} - send_points = {} - send_mass = {} - send_size = {} - # This will reduce the size of the loop over particles. - yt_counters("Picking padding data to send.") - send_count = len(na.where(self.is_inside_annulus == True)[0]) - points = na.empty((send_count, 3), dtype='float64') - points[:,0] = self.xpos[self.is_inside_annulus] - points[:,1] = self.ypos[self.is_inside_annulus] - points[:,2] = self.zpos[self.is_inside_annulus] - real_indices = self.index[self.is_inside_annulus].astype('int64') - mass = self.mass[self.is_inside_annulus].astype('float64') - # Make the arrays to send. - shift_points = points.copy() - for neighbor in self.neighbors: - temp_LE, temp_RE = global_exp_bounds[neighbor] - for i in xrange(3): - left = ((points[:,i] < temp_LE[i]) * (points[:,i] < temp_RE[i])) * self.period[i] - right = ((points[:,i] > temp_LE[i]) * (points[:,i] > temp_RE[i])) * self.period[i] - shift_points[:,i] = points[:,i] + left - right - is_inside = ( (shift_points >= temp_LE).all(axis=1) * \ - (shift_points < temp_RE).all(axis=1) ) - send_real_indices[neighbor] = real_indices[is_inside].copy() - send_points[neighbor] = shift_points[is_inside].copy() - send_mass[neighbor] = mass[is_inside].copy() - send_size[neighbor] = len(na.where(is_inside == True)[0]) - del points, shift_points, mass, real_indices - yt_counters("Picking padding data to send.") - # Communicate the sizes to send. - self.mine, global_send_count = self._mpi_info_dict(send_size) - del send_size - # Initialize the arrays to receive data. - yt_counters("Initalizing recv arrays.") - recv_real_indices = {} - recv_points = {} - recv_mass = {} - recv_size = 0 - for opp_neighbor in self.neighbors: - opp_size = global_send_count[opp_neighbor][self.mine] - recv_real_indices[opp_neighbor] = na.empty(opp_size, dtype='int64') - recv_points[opp_neighbor] = na.empty((opp_size, 3), dtype='float64') - recv_mass[opp_neighbor] = na.empty(opp_size, dtype='float64') - recv_size += opp_size - yt_counters("Initalizing recv arrays.") - # Setup the receiving slots. - yt_counters("MPI stuff.") - hooks = [] - for opp_neighbor in self.neighbors: - hooks.append(self._mpi_Irecv_long(recv_real_indices[opp_neighbor], opp_neighbor)) - hooks.append(self._mpi_Irecv_double(recv_points[opp_neighbor], opp_neighbor)) - hooks.append(self._mpi_Irecv_double(recv_mass[opp_neighbor], opp_neighbor)) - # Let's wait here to be absolutely sure that all the receive buffers - # have been created before any sending happens! - self._barrier() - # Now we send the data. - for neighbor in self.neighbors: - hooks.append(self._mpi_Isend_long(send_real_indices[neighbor], neighbor)) - hooks.append(self._mpi_Isend_double(send_points[neighbor], neighbor)) - hooks.append(self._mpi_Isend_double(send_mass[neighbor], neighbor)) - # Now we use the data, after all the comms are done. - self._mpi_Request_Waitall(hooks) - yt_counters("MPI stuff.") - yt_counters("Processing padded data.") - del send_real_indices, send_points, send_mass - # Now we add the data to ourselves. - self.index_pad = na.empty(recv_size, dtype='int64') - self.xpos_pad = na.empty(recv_size, dtype='float64') - self.ypos_pad = na.empty(recv_size, dtype='float64') - self.zpos_pad = na.empty(recv_size, dtype='float64') - self.mass_pad = na.empty(recv_size, dtype='float64') - so_far = 0 - for opp_neighbor in self.neighbors: - opp_size = global_send_count[opp_neighbor][self.mine] - self.index_pad[so_far:so_far+opp_size] = recv_real_indices[opp_neighbor] - # Clean up immediately to reduce peak memory usage. - del recv_real_indices[opp_neighbor] - self.xpos_pad[so_far:so_far+opp_size] = recv_points[opp_neighbor][:,0] - self.ypos_pad[so_far:so_far+opp_size] = recv_points[opp_neighbor][:,1] - self.zpos_pad[so_far:so_far+opp_size] = recv_points[opp_neighbor][:,2] - del recv_points[opp_neighbor] - self.mass_pad[so_far:so_far+opp_size] = recv_mass[opp_neighbor] - del recv_mass[opp_neighbor] - so_far += opp_size - yt_counters("Processing padded data.") - # The KDtree node search wants the particles to be in the full box, - # not the expanded dimensions of shifted (<0 or >1 generally) volume, - # so we fix the positions of particles here. - yt_counters("Flipping coordinates around the periodic boundary.") - self.xpos_pad = self.xpos_pad % self.period[0] - self.ypos_pad = self.ypos_pad % self.period[1] - self.zpos_pad = self.zpos_pad % self.period[2] - yt_counters("Flipping coordinates around the periodic boundary.") - self.size = self.index.size + self.index_pad.size - # Now that we have the full size, initialize the chainID array - self.chainID = na.ones(self.size,dtype='int64') * -1 - # Clean up explicitly, but these should be empty dicts by now. - del recv_real_indices, hooks, recv_points, recv_mass - yt_counters("Communicate discriminated padding") - - def _init_kd_tree(self): - """ - Set up the data objects that get passed to the kD-tree code. - """ - yt_counters("init kd tree") - # Yes, we really do need to initialize this many arrays. - # They're deleted in _parallelHOP. - fKD.dens = na.asfortranarray(na.zeros(self.size, dtype='float64')) - fKD.mass = na.concatenate((self.mass, self.mass_pad)) - fKD.pos = na.asfortranarray(na.empty((3, self.size), dtype='float64')) - # This actually copies the data into the fortran space. - fKD.pos[0, :] = na.concatenate((self.xpos, self.xpos_pad)) - fKD.pos[1, :] = na.concatenate((self.ypos, self.ypos_pad)) - fKD.pos[2, :] = na.concatenate((self.zpos, self.zpos_pad)) - fKD.qv = na.asfortranarray(na.empty(3, dtype='float64')) - fKD.nn = self.num_neighbors - # Plus 2 because we're looking for that neighbor, but only keeping - # nMerge + 1 neighbor tags, skipping ourselves. - fKD.nMerge = self.nMerge + 2 - fKD.nparts = self.size - fKD.sort = True # Slower, but needed in _connect_chains - fKD.rearrange = self.rearrange # True is faster, but uses more memory - # Now call the fortran. - create_tree(0) - self.__max_memory() - yt_counters("init kd tree") - - def _is_inside(self, round): - """ - There are three classes of particles. - 1. Particles inside the 'real' region of each subvolume. - 2. Particles ouside, added in the 'padding' for purposes of having - correct particle densities in the real region. - 3. Particles that are one padding distance inside the edges of the - real region. The chainIDs of these particles are communicated - to the neighboring tasks so chains can be merged into groups. - The input *round* is either 'first' or 'second.' First is before the - padded particles have been communicated, and second after. - """ - # Test to see if the points are in the 'real' region - (LE, RE) = self.bounds - if round == 'first': - points = na.empty((self.real_size, 3), dtype='float64') - points[:,0] = self.xpos - points[:,1] = self.ypos - points[:,2] = self.zpos - self.is_inside = ( (points >= LE).all(axis=1) * \ - (points < RE).all(axis=1) ) - elif round == 'second': - self.is_inside = ( (fKD.pos.T >= LE).all(axis=1) * \ - (fKD.pos.T < RE).all(axis=1) ) - # Below we find out which particles are in the `annulus', one padding - # distance inside the boundaries. First we find the particles outside - # this inner boundary. - temp_LE = LE + self.max_padding - temp_RE = RE - self.max_padding - if round == 'first': - inner = na.invert( (points >= temp_LE).all(axis=1) * \ - (points < temp_RE).all(axis=1) ) - elif round == 'second' or round == 'third': - inner = na.invert( (fKD.pos.T >= temp_LE).all(axis=1) * \ - (fKD.pos.T < temp_RE).all(axis=1) ) - if round == 'first': - del points - # After inverting the logic above, we want points that are both - # inside the real region, but within one padding of the boundary, - # and this will do it. - self.is_inside_annulus = na.bitwise_and(self.is_inside, inner) - del inner - # Below we make a mapping of real particle index->local ID - # Unf. this has to be a dict, because any task can have - # particles of any particle_index, which means that if it were an - # array every task would probably end up having this array be as long - # as the full number of particles. - # We can skip this the first two times around. - if round == 'third': - temp = na.arange(self.size) - my_part = na.bitwise_or(na.invert(self.is_inside), self.is_inside_annulus) - my_part = na.bitwise_and(my_part, (self.chainID != -1)) - catted_indices = na.concatenate( - (self.index, self.index_pad))[my_part] - self.rev_index = dict.fromkeys(catted_indices) - self.rev_index.update(itertools.izip(catted_indices, temp[my_part])) - del my_part, temp, catted_indices - self.__max_memory() - - def _densestNN(self): - """ - For all particles, find their densest nearest neighbor. It is done in - chunks to keep the memory usage down. - The first search of nearest neighbors (done earlier) did not return all - num_neighbor neighbors, so we need to do it again, but we're not - keeping the all of this data, just using it. - """ - yt_counters("densestNN") - self.densestNN = na.empty(self.size,dtype='int64') - # We find nearest neighbors in chunks. - chunksize = 10000 - fKD.chunk_tags = na.asfortranarray(na.empty((self.num_neighbors, chunksize), dtype='int64')) - start = 1 # Fortran counting! - finish = 0 - while finish < self.size: - finish = min(finish+chunksize,self.size) - # Call the fortran. start and finish refer to the data locations - # in fKD.pos, and specify the range of particles to find nearest - # neighbors - fKD.start = start - fKD.finish = finish - find_chunk_nearest_neighbors() - chunk_NNtags = (fKD.chunk_tags[:,:finish-start+1] - 1).transpose() - # Find the densest nearest neighbors by referencing the already - # calculated density. - n_dens = na.take(self.density,chunk_NNtags) - max_loc = na.argmax(n_dens,axis=1) - for i in xrange(finish - start + 1): # +1 for fortran counting. - j = start + i - 1 # -1 for fortran counting. - self.densestNN[j] = chunk_NNtags[i,max_loc[i]] - start = finish + 1 - yt_counters("densestNN") - self.__max_memory() - del chunk_NNtags, max_loc, n_dens - - def _build_chains(self): - """ - Build the first round of particle chains. If the particle is too low in - density, move on. - """ - yt_counters("build_chains") - chainIDmax = 0 - self.densest_in_chain = na.ones(10000, dtype='float64') * -1 # chainID->density, one to one - self.densest_in_chain_real_index = na.ones(10000, dtype='int64') * -1 # chainID->real_index, one to one - for i in xrange(int(self.size)): - # If it's already in a group, move on, or if this particle is - # in the padding, move on because chains can only terminate in - # the padding, not begin, or if this particle is too low in - # density, move on. - if self.chainID[i] > -1 or not self.is_inside[i] or \ - self.density[i] < self.threshold: - continue - chainIDnew = self._recurse_links(i, chainIDmax) - # If the new chainID returned is the same as we entered, the chain - # has been named chainIDmax, so we need to start a new chain - # in the next loop. - if chainIDnew == chainIDmax: - chainIDmax += 1 - self.padded_particles = na.array(self.padded_particles, dtype='int64') - self.densest_in_chain = self.__clean_up_array(self.densest_in_chain) - self.densest_in_chain_real_index = self.__clean_up_array(self.densest_in_chain_real_index) - yt_counters("build_chains") - self.__max_memory() - return chainIDmax - - def _recurse_links(self, pi, chainIDmax): - """ - Recurse up the chain to a) a self-highest density particle, - b) a particle that already has a chainID, then turn it back around - assigning that chainID to where we came from. If c) which - is a particle in the padding, terminate the chain right then - and there, because chains only go one particle deep into the padding. - """ - nn = self.densestNN[pi] - inside = self.is_inside[pi] - nn_chainID = self.chainID[nn] - # Linking to an already chainID-ed particle (don't make links from - # padded particles!) - if nn_chainID > -1 and inside: - self.chainID[pi] = nn_chainID - return nn_chainID - # If pi is a self-most dense particle or inside the padding, end/create - # a new chain. - elif nn == pi or not inside: - self.chainID[pi] = chainIDmax - self.densest_in_chain = self.__add_to_array(self.densest_in_chain, - chainIDmax, self.density[pi], 'float64') - if pi < self.real_size: - self.densest_in_chain_real_index = self.__add_to_array(self.densest_in_chain_real_index, - chainIDmax, self.index[pi], 'int64') - else: - self.densest_in_chain_real_index = self.__add_to_array(self.densest_in_chain_real_index, - chainIDmax, self.index_pad[pi-self.real_size], 'int64') - # if this is a padded particle, record it for later - if not inside: - self.padded_particles.append(pi) - return chainIDmax - # Otherwise, recursively link to nearest neighbors. - else: - chainIDnew = self._recurse_links(nn, chainIDmax) - self.chainID[pi] = chainIDnew - return chainIDnew - - def _recurse_preconnected_links(self, chain_map, thisID): - if min(thisID, min(chain_map[thisID])) == thisID: - return thisID - else: - return self._recurse_preconnected_links(chain_map, min(chain_map[thisID])) - - def _preconnect_chains(self, chain_count): - """ - In each subvolume, chains that share a boundary that both have high - enough peak densities are prelinked in order to reduce the size of the - global chain objects. This is very similar to _connect_chains(). - """ - # First we'll sort them, which will be used below. - mylog.info("Locally sorting chains...") - yt_counters("preconnect_chains") - yt_counters("local chain sorting.") - sort = self.densest_in_chain.argsort() - sort = na.flipud(sort) - map = na.empty(sort.size,dtype='int64') - map[sort] = na.arange(sort.size) - self.densest_in_chain = self.densest_in_chain[sort] - self.densest_in_chain_real_index = self.densest_in_chain_real_index[sort] - del sort - for i,chID in enumerate(self.chainID): - if chID == -1: continue - self.chainID[i] = map[chID] - del map - yt_counters("local chain sorting.") - mylog.info("Preconnecting %d chains..." % chain_count) - chain_map = defaultdict(set) - for i in xrange(max(self.chainID)+1): - chain_map[i].add(i) - # Plus 2 because we're looking for that neighbor, but only keeping - # nMerge + 1 neighbor tags, skipping ourselves. - fKD.dist = na.empty(self.nMerge+2, dtype='float64') - fKD.tags = na.empty(self.nMerge+2, dtype='int64') - # We can change this here to make the searches faster. - fKD.nn = self.nMerge+2 - yt_counters("preconnect kd tree search.") - for i in xrange(self.size): - # Don't consider this particle if it's not part of a chain. - if self.chainID[i] < 0: continue - chainID_i = self.chainID[i] - # If this particle is in the padding, don't make a connection. - if not self.is_inside[i]: continue - # Find this particle's chain max_dens. - part_max_dens = self.densest_in_chain[chainID_i] - # We're only connecting >= peakthresh chains now. - if part_max_dens < self.peakthresh: continue - # Loop over nMerge closest nearest neighbors. - fKD.qv = fKD.pos[:, i] - find_nn_nearest_neighbors() - NNtags = fKD.tags[:] - 1 - same_count = 0 - for j in xrange(int(self.nMerge+1)): - thisNN = NNtags[j+1] # Don't consider ourselves at NNtags[0] - thisNN_chainID = self.chainID[thisNN] - # If our neighbor is in the same chain, move on. - # Move on if these chains are already connected: - if chainID_i == thisNN_chainID or \ - thisNN_chainID in chain_map[chainID_i]: - same_count += 1 - continue - # Everything immediately below is for - # neighboring particles with a chainID. - if thisNN_chainID >= 0: - # Find thisNN's chain's max_dens. - thisNN_max_dens = self.densest_in_chain[thisNN_chainID] - # We're only linking peakthresh chains - if thisNN_max_dens < self.peakthresh: continue - # Calculate the two groups boundary density. - boundary_density = (self.density[thisNN] + self.density[i]) / 2. - # Don't connect if the boundary is too low. - if boundary_density < self.saddlethresh: continue - # Mark these chains as related. - chain_map[thisNN_chainID].add(chainID_i) - chain_map[chainID_i].add(thisNN_chainID) - if same_count == self.nMerge + 1: - # All our neighbors are in the same chain already, so - # we don't need to search again. - self.search_again[i] = False - try: - del NNtags - except UnboundLocalError: - pass - yt_counters("preconnect kd tree search.") - # Recursively jump links until we get to a chain whose densest - # link is to itself. At that point we've found the densest chain - # in this set of sets and we keep a record of that. - yt_counters("preconnect pregrouping.") - final_chain_map = na.empty(max(self.chainID)+1, dtype='int64') - removed = 0 - for i in xrange(max(self.chainID)+1): - j = chain_count - i - 1 - densest_link = self._recurse_preconnected_links(chain_map, j) - final_chain_map[j] = densest_link - if j != densest_link: - removed += 1 - self.densest_in_chain[j] = -1 - self.densest_in_chain_real_index[j] = -1 - del chain_map - for i in xrange(self.size): - if self.chainID[i] != -1: - self.chainID[i] = final_chain_map[self.chainID[i]] - del final_chain_map - # Now make the chainID assignments consecutive. - map = na.empty(self.densest_in_chain.size, dtype='int64') - dic_new = na.empty(chain_count - removed, dtype='float64') - dicri_new = na.empty(chain_count - removed, dtype='int64') - new = 0 - for i,dic in enumerate(self.densest_in_chain): - if dic > 0: - map[i] = new - dic_new[new] = dic - dicri_new[new] = self.densest_in_chain_real_index[i] - new += 1 - else: - map[i] = -1 - for i in range(self.size): - if self.chainID[i] != -1: - self.chainID[i] = map[self.chainID[i]] - del map - self.densest_in_chain = dic_new.copy() - del dic_new - self.densest_in_chain_real_index = dicri_new.copy() - del dicri_new - self.__max_memory() - yt_counters("preconnect pregrouping.") - mylog.info("Preconnected %d chains." % removed) - yt_counters("preconnect_chains") - - return chain_count - removed - - def _globally_assign_chainIDs(self, chain_count): - """ - Convert local chainIDs into globally unique chainIDs. - """ - yt_counters("globally_assign_chainIDs") - # First find out the number of chains on each processor. - self.mine, chain_info = self._mpi_info_dict(chain_count) - self.nchains = sum(chain_info.values()) - # Figure out our offset. - self.my_first_id = sum([v for k,v in chain_info.iteritems() if k < self.mine]) - # Change particle IDs, -1 always means no chain assignment. - select = (self.chainID != -1) - select = select * self.my_first_id - self.chainID += select - del select - yt_counters("globally_assign_chainIDs") - - def _create_global_densest_in_chain(self): - """ - With the globally unique chainIDs, update densest_in_chain. - """ - yt_counters("create_global_densest_in_chain") - # Shift the values over effectively by concatenating them in the same - # order as the values have been shifted in _globally_assign_chainIDs() - yt_counters("global chain MPI stuff.") - self.densest_in_chain = self._mpi_concatenate_array_double(self.densest_in_chain) - self.densest_in_chain_real_index = self._mpi_concatenate_array_long(self.densest_in_chain_real_index) - yt_counters("global chain MPI stuff.") - # Sort the chains by density here. This is an attempt to make it such - # that the merging stuff in a few steps happens in the same order - # all the time. - mylog.info("Sorting chains...") - yt_counters("global chain sorting.") - sort = self.densest_in_chain.argsort() - sort = na.flipud(sort) - map = na.empty(sort.size,dtype='int64') - map[sort] =na.arange(sort.size) - self.densest_in_chain = self.densest_in_chain[sort] - self.densest_in_chain_real_index = self.densest_in_chain_real_index[sort] - del sort - for i,chID in enumerate(self.chainID): - if chID == -1: continue - self.chainID[i] = map[chID] - del map - yt_counters("global chain sorting.") - # For some reason chains that share the most-dense particle are not - # being linked, so we link them 'by hand' here. - mylog.info("Pre-linking chains 'by hand'...") - yt_counters("global chain hand-linking.") - # If there are no repeats, we can skip this mess entirely. - uniq = na.unique(self.densest_in_chain_real_index) - if uniq.size != self.densest_in_chain_real_index.size: - # Find only the real particle indices that are repeated to reduce - # the dict workload below. - dicri = self.densest_in_chain_real_index[self.densest_in_chain_real_index.argsort()] - diff = na.ediff1d(dicri) - diff = (diff == 0) # Picks out the places where the ids are equal - diff = na.concatenate((diff, [False])) # Makes it the same length - # This has only the repeated IDs. Sets are faster at searches than - # arrays. - dicri = set(dicri[diff]) - reverse = defaultdict(set) - # Here we find a reverse mapping of real particle ID to chainID - for chainID, real_index in enumerate(self.densest_in_chain_real_index): - if real_index in dicri: - reverse[real_index].add(chainID) - del dicri, diff - # If the real index has len(set)>1, there are multiple chains that need - # to be linked - tolink = defaultdict(set) - for real in reverse: - if len(reverse[real]) > 1: - # Unf. can't slice a set, so this will have to do. - tolink[min(reverse[real])] = reverse[real] - tolink[min(reverse[real])].discard(min(reverse[real])) - del reverse - # Now we will remove the other chains from the dicts and re-assign - # particles to their new chainID. - fix_map = {} - for tokeep in tolink: - for remove in tolink[tokeep]: - fix_map[remove] = tokeep - self.densest_in_chain[remove] = -1.0 - self.densest_in_chain_real_index[remove] = -1 - for i, chainID in enumerate(self.chainID): - try: - new = fix_map[chainID] - except KeyError: - continue - self.chainID[i] = new - del tolink, fix_map - del uniq - yt_counters("global chain hand-linking.") - yt_counters("create_global_densest_in_chain") - - def _communicate_uphill_info(self): - """ - Communicate the links to the correct neighbors from uphill_info. - """ - yt_counters("communicate_uphill_info") - # Find out how many particles we're going to receive, and make arrays - # of the right size and type to store them. - to_recv_count = 0 - temp_indices = dict.fromkeys(self.neighbors) - temp_chainIDs = dict.fromkeys(self.neighbors) - for opp_neighbor in self.neighbors: - opp_size = self.global_padded_count[opp_neighbor] - to_recv_count += opp_size - temp_indices[opp_neighbor] = na.empty(opp_size, dtype='int64') - temp_chainIDs[opp_neighbor] = na.empty(opp_size, dtype='int64') - # The arrays we'll actually keep around... - self.recv_real_indices = na.empty(to_recv_count, dtype='int64') - self.recv_chainIDs = na.empty(to_recv_count, dtype='int64') - # Set up the receives, but don't actually use them. - hooks = [] - for opp_neighbor in self.neighbors: - hooks.append(self._mpi_Irecv_long(temp_indices[opp_neighbor], opp_neighbor)) - hooks.append(self._mpi_Irecv_long(temp_chainIDs[opp_neighbor], opp_neighbor)) - # Make sure all the receive buffers are set before continuing. - self._barrier() - # Send padded particles to our neighbors. - for neighbor in self.neighbors: - hooks.append(self._mpi_Isend_long(self.uphill_real_indices, neighbor)) - hooks.append(self._mpi_Isend_long(self.uphill_chainIDs, neighbor)) - # Now actually use the data once it's good to go. - self._mpi_Request_Waitall(hooks) - self.__max_memory() - so_far = 0 - for opp_neighbor in self.neighbors: - opp_size = self.global_padded_count[opp_neighbor] - # Only save the part of the buffer that we want to the right places - # in the full listing. - self.recv_real_indices[so_far:(so_far + opp_size)] = \ - temp_indices[opp_neighbor][0:opp_size] - self.recv_chainIDs[so_far:(so_far + opp_size)] = \ - temp_chainIDs[opp_neighbor][0:opp_size] - so_far += opp_size - # Clean up. - del temp_indices, temp_chainIDs, hooks - yt_counters("communicate_uphill_info") - - def _recurse_global_chain_links(self, chainID_translate_map_global, chainID, seen): - """ - Step up the global chain links until we reach the self-densest chain, - very similarly to the recursion of particles to densest nearest - neighbors. - """ - new_chainID = chainID_translate_map_global[chainID] - if new_chainID == chainID: - return int(chainID) - elif new_chainID in seen: - # Bad things are about to happen if this condition is met! The - # padding probably needs to be increased (using the safety factor). - mylog.info('seen %s' % str(seen)) - for s in seen: - mylog.info('%d %d' % (s, chainID_translate_map_global[s])) - else: - seen.append(new_chainID) - return self._recurse_global_chain_links(chainID_translate_map_global, new_chainID, seen) - - def _connect_chains_across_tasks(self): - """ - Using the uphill links of chains, chains are linked across boundaries. - Chains that link to a remote chain are recorded, and a complete dict - of chain connections is created, globally. Then chainIDs are - reassigned recursively, assigning the ID of the most dense chainID - to every chain that links to it. - """ - yt_counters("connect_chains_across_tasks") - # Remote (lower dens) chain -> local (higher) chain. - chainID_translate_map_local = na.arange(self.nchains) - # Build the stuff to send. - self.uphill_real_indices = na.concatenate(( - self.index, self.index_pad))[self.padded_particles] - self.uphill_chainIDs = self.chainID[self.padded_particles] - del self.padded_particles - # Now we make a global dict of how many particles each task is - # sending. - self.global_padded_count = {self.mine:self.uphill_chainIDs.size} - self.global_padded_count = self._mpi_joindict(self.global_padded_count) - # Send/receive 'em. - self._communicate_uphill_info() - del self.global_padded_count - self.__max_memory() - # Fix the IDs to localIDs. - for i,real_index in enumerate(self.recv_real_indices): - try: - localID = self.rev_index[real_index] - # We don't want to update the chainIDs of my padded particles. - # Remember we are supposed to be only considering particles - # in my *real* region, that are padded in my neighbor. - if not self.is_inside[localID]: - # Make it negative so we can skip it below. - self.recv_real_indices[i] = -1 - continue - self.recv_real_indices[i] = localID - except KeyError: - # This is probably a particle we don't even own, so we want - # to ignore it. - self.recv_real_indices[i] = -1 - continue - # Now relate the local chainIDs to the received chainIDs - for i,localID in enumerate(self.recv_real_indices): - # If the 'new' chainID is different that what we already have, - # we need to record it, but we skip particles that were assigned - # -1 above. Also, since links are supposed to go only uphill, - # ensure that they are being recorded that way below. - if localID != -1 and self.chainID[localID] != -1: - if self.recv_chainIDs[i] != self.chainID[localID] and \ - self.densest_in_chain[self.chainID[localID]] >= self.densest_in_chain[self.recv_chainIDs[i]] and \ - self.densest_in_chain[self.chainID[localID]] != -1.0 and \ - self.densest_in_chain[self.recv_chainIDs[i]] != -1.0: - chainID_translate_map_local[self.recv_chainIDs[i]] = \ - self.chainID[localID] - self.__max_memory() - # In chainID_translate_map_local, chains may - # 'point' to only one chain, but a chain may have many that point to - # it. Therefore each key (a chain) in this dict is unique, but the items - # the keys point to are not necessarily unique. - chainID_translate_map_global = \ - self._mpi_minimum_array_long(chainID_translate_map_local) - # Loop over chains, smallest to largest density, recursively until - # we reach a self-assigned chain. Then we assign that final chainID to - # the *current* one only. - seen = [] - for key, density in enumerate(self.densest_in_chain): - if density == -1: continue # Skip 'deleted' chains - seen = [] - seen.append(key) - new_chainID = \ - self._recurse_global_chain_links(chainID_translate_map_global, key, seen) - chainID_translate_map_global[key] = new_chainID - # At the same time, remove chains from densest_in_chain that have - # been reassigned. - if key != new_chainID: - self.densest_in_chain[key] = -1.0 - self.densest_in_chain_real_index[key] = -1 - # Also fix nchains to keep up. - self.nchains -= 1 - self.__max_memory() - # Convert local particles to their new chainID - for i in xrange(int(self.size)): - old_chainID = self.chainID[i] - if old_chainID == -1: continue - new_chainID = chainID_translate_map_global[old_chainID] - self.chainID[i] = new_chainID - del chainID_translate_map_local, self.recv_chainIDs - del self.recv_real_indices, self.uphill_real_indices, self.uphill_chainIDs - del seen, chainID_translate_map_global - yt_counters("connect_chains_across_tasks") - - def _communicate_annulus_chainIDs(self): - """ - Transmit all of our chainID-ed particles that are within self.padding - of the boundaries to all of our neighbors. Tests show that this is - faster than trying to figure out which of the neighbors to send the data - to. - """ - yt_counters("communicate_annulus_chainIDs") - # Pick the particles in the annulus. - real_indices = na.concatenate( - (self.index, self.index_pad))[self.is_inside_annulus] - chainIDs = self.chainID[self.is_inside_annulus] - # We're done with this here. - del self.is_inside_annulus - # Eliminate un-assigned particles. - select = (chainIDs != -1) - real_indices = real_indices[select] - chainIDs = chainIDs[select] - send_count = real_indices.size - # Here distribute the counts globally. Unfortunately, it's a barrier(), - # but there's so many places in this that need to be globally synched - # that it's not worth the effort right now to make this one spot better. - global_annulus_count = {self.mine:send_count} - global_annulus_count = self._mpi_joindict(global_annulus_count) - # Set up the receiving arrays. - recv_real_indices = dict.fromkeys(self.neighbors) - recv_chainIDs = dict.fromkeys(self.neighbors) - for opp_neighbor in self.neighbors: - opp_size = global_annulus_count[opp_neighbor] - recv_real_indices[opp_neighbor] = na.empty(opp_size, dtype='int64') - recv_chainIDs[opp_neighbor] = na.empty(opp_size, dtype='int64') - # Set up the receving hooks. - hooks = [] - for opp_neighbor in self.neighbors: - hooks.append(self._mpi_Irecv_long(recv_real_indices[opp_neighbor], opp_neighbor)) - hooks.append(self._mpi_Irecv_long(recv_chainIDs[opp_neighbor], opp_neighbor)) - # Make sure the recv buffers are set before continuing. - self._barrier() - # Now we send them. - for neighbor in self.neighbors: - hooks.append(self._mpi_Isend_long(real_indices, neighbor)) - hooks.append(self._mpi_Isend_long(chainIDs, neighbor)) - # Now we use them when they're nice and ripe. - self._mpi_Request_Waitall(hooks) - self.__max_memory() - for opp_neighbor in self.neighbors: - opp_size = global_annulus_count[opp_neighbor] - # Update our local data. - for i,real_index in enumerate(recv_real_indices[opp_neighbor][0:opp_size]): - try: - localID = self.rev_index[real_index] - # We are only updating our particles that are in our - # padding, so to be rigorous we will skip particles - # that are in our real region. - if self.is_inside[localID]: - continue - self.chainID[localID] = recv_chainIDs[opp_neighbor][i] - except KeyError: - # We ignore data that's not for us. - continue - # Clean up. - del recv_real_indices, recv_chainIDs, real_indices, chainIDs, select - del hooks, global_annulus_count - # We're done with this here. - del self.rev_index - yt_counters("communicate_annulus_chainIDs") - - - def _connect_chains(self): - """ - With the set of particle chains, build a mapping of connected chainIDs - by finding the highest boundary density neighbor for each chain. Some - chains will have no neighbors! - """ - yt_counters("connect_chains") - self.chain_densest_n = {} # chainID -> {chainIDs->boundary dens} - # Plus 2 because we're looking for that neighbor, but only keeping - # nMerge + 1 neighbor tags, skipping ourselves. - fKD.dist = na.empty(self.nMerge+2, dtype='float64') - fKD.tags = na.empty(self.nMerge+2, dtype='int64') - # We can change this here to make the searches faster. - fKD.nn = self.nMerge+2 - for i in xrange(int(self.size)): - # Don't consider this particle if it's not part of a chain. - if self.chainID[i] < 0: continue - # If this particle is in the padding, don't make a connection. - if not self.is_inside[i]: continue - # Make sure that we should search this particle again. - if not self.search_again[i]: continue - # Find this particle's chain max_dens. - part_max_dens = self.densest_in_chain[self.chainID[i]] - # Make sure we're skipping deleted chains. - if part_max_dens == -1.0: continue - # Loop over nMerge closest nearest neighbors. - fKD.qv = fKD.pos[:, i] - find_nn_nearest_neighbors() - NNtags = fKD.tags[:] - 1 - for j in xrange(int(self.nMerge+1)): - thisNN = NNtags[j+1] # Don't consider ourselves at NNtags[0] - thisNN_chainID = self.chainID[thisNN] - # If our neighbor is in the same chain, move on. - if self.chainID[i] == thisNN_chainID: continue - # Everything immediately below is for - # neighboring particles with a chainID. - if thisNN_chainID >= 0: - # Find thisNN's chain's max_dens. - thisNN_max_dens = self.densest_in_chain[thisNN_chainID] - if thisNN_max_dens == -1.0: continue - # Calculate the two groups boundary density. - boundary_density = (self.density[thisNN] + self.density[i]) / 2. - # Find out who's denser. - if thisNN_max_dens >= part_max_dens: - higher_chain = thisNN_chainID - lower_chain = self.chainID[i] - else: - higher_chain = self.chainID[i] - lower_chain = thisNN_chainID - # Make sure that the higher density chain has an entry. - try: - test = self.chain_densest_n[int(higher_chain)] - except KeyError: - self.chain_densest_n[int(higher_chain)] = {} - # See if this boundary density is higher than - # previously recorded for this pair of chains. - # Links only go one direction. - try: - old = self.chain_densest_n[int(higher_chain)][int(lower_chain)] - if old < boundary_density: - # make this the new densest boundary between this pair - self.chain_densest_n[int(higher_chain)][int(lower_chain)] = \ - boundary_density - except KeyError: - # we haven't seen this pairing before, record this as the - # new densest boundary between chains - self.chain_densest_n[int(higher_chain)][int(lower_chain)] = \ - boundary_density - else: - continue - try: - del point, NNtags, results - except UnboundLocalError: - pass - self.__max_memory() - yt_counters("connect_chains") - - def _make_global_chain_densest_n(self): - """ - We want to record the maximum boundary density between all chains on - all tasks. - """ - yt_counters("make_global_chain_densest_n") - (self.top_keys, self.bot_keys, self.vals) = \ - self._mpi_maxdict_dict(self.chain_densest_n) - self.__max_memory() - del self.chain_densest_n - yt_counters("make_global_chain_densest_n") - - def _build_groups(self): - """ - With the collection of possible chain links, build groups. - """ - yt_counters("build_groups") - # We need to find out which pairs of self.top_keys, self.bot_keys are - # both < self.peakthresh, and create arrays that will store this - # relationship. - both = na.bitwise_and((self.densest_in_chain[self.top_keys] < self.peakthresh), - (self.densest_in_chain[self.bot_keys] < self.peakthresh)) - g_high = self.top_keys[both] - g_low = self.bot_keys[both] - g_dens = self.vals[both] - del both - self.reverse_map = na.ones(self.densest_in_chain.size) * -1 - densestbound = na.ones(self.densest_in_chain.size) * -1.0 - for i, gl in enumerate(g_low): - if g_dens[i] > densestbound[gl]: - densestbound[gl] = g_dens[i] - groupID = 0 - # First assign a group to all chains with max_dens above peakthresh. - # The initial groupIDs will be assigned with decending peak density. - # This guarantees that the group with the smaller groupID is the - # higher chain, as in chain_high below. - for chainID,density in enumerate(self.densest_in_chain): - if density == -1.0: continue - if self.densest_in_chain[chainID] >= self.peakthresh: - self.reverse_map[chainID] = groupID - groupID += 1 - group_equivalancy_map = na.empty(groupID, dtype='object') - for i in xrange(groupID): - group_equivalancy_map[i] = set([]) - # Loop over all of the chain linkages. - for i,chain_high in enumerate(self.top_keys): - chain_low = self.bot_keys[i] - dens = self.vals[i] - max_dens_high = self.densest_in_chain[chain_high] - max_dens_low = self.densest_in_chain[chain_low] - if max_dens_high == -1.0 or max_dens_low == -1.0: continue - # If neither are peak density groups, mark them for later - # consideration. - if max_dens_high < self.peakthresh and \ - max_dens_low < self.peakthresh: - # This step is now done vectorized above, with the g_dens - # stuff. - continue - # If both are peak density groups, and have a boundary density - # that is high enough, make them into a group, otherwise - # move onto another linkage. - if max_dens_high >= self.peakthresh and \ - max_dens_low >= self.peakthresh: - if dens < self.saddlethresh: - continue - else: - group_high = self.reverse_map[chain_high] - group_low = self.reverse_map[chain_low] - if group_high == -1 or group_low == -1: continue - # Both are already identified as groups, so we need - # to re-assign the less dense group to the denser - # groupID. - if group_low != group_high: - group_equivalancy_map[group_low].add(group_high) - group_equivalancy_map[group_high].add(group_low) - continue - # Else, one is above peakthresh, the other below - # find out if this is the densest boundary seen so far for - # the lower chain. - group_high = self.reverse_map[chain_high] - if group_high == -1: continue - if dens >= densestbound[chain_low]: - densestbound[chain_low] = dens - self.reverse_map[chain_low] = group_high - self.__max_memory() - del self.top_keys, self.bot_keys, self.vals - # Now refactor group_equivalancy_map back into reverse_map. The group - # mapping may be more than one link long, so we need to do it - # recursively. The best way to think about this is a field full of - # rabbit holes. The holes are connected at nexuses at the surface. - # Each groupID (key) in group_equivalancy_map represents a hole, and - # the values the nexuses are the tunnels lead to. The tunnels are two-way, - # and when you go through it, you block the passage through that - # tunnel in that direction, so you don't repeat yourself later. You can - # go back through that tunnel, but your search ends there because all - # the other tunnels have been closed at the old nexus. In this fashion your search - # spreads out like the water shooting out of the ground in 'Caddy - # Shack.' - Set_list = [] - # We only want the holes that are modulo mine. - keys = na.arange(groupID, dtype='int64') - size = self._mpi_get_size() - select = (keys % size == self.mine) - groupIDs = keys[select] - mine_groupIDs = set([]) # Records only ones modulo mine. - not_mine_groupIDs = set([]) # All the others. - # Declare these to prevent Errors when they're del-ed below, in case - # this task doesn't create them in the loop, for whatever reason. - current_sets, new_mine, new_other = [], [], [] - new_set, final_set, to_add_set, liter = set([]), set([]), set([]), set([]) - to_add_set = set([]) - for groupID in groupIDs: - if groupID in mine_groupIDs: - continue - mine_groupIDs.add(groupID) - current_sets = [] - new_set = group_equivalancy_map[groupID] - final_set = new_set.copy() - while len(new_set) > 0: - to_add_set = set([]) - liter = new_set.difference(mine_groupIDs).difference(not_mine_groupIDs) - new_mine, new_other = [], [] - for link_gID in liter: - to_add_set.update(group_equivalancy_map[link_gID]) - if link_gID % size == self.mine: - new_mine.append(link_gID) - else: - new_other.append(link_gID) - mine_groupIDs.update(new_mine) - not_mine_groupIDs.update(new_other) - final_set.update(to_add_set) - new_set = to_add_set - # Make sure it's not empty - final_set.add(groupID) - Set_list.append(final_set) - self.__max_memory() - del group_equivalancy_map, final_set, keys, select, groupIDs, current_sets - del mine_groupIDs, not_mine_groupIDs, new_set, to_add_set, liter - # Convert this list of sets into a look-up table - lookup = na.ones(self.densest_in_chain.size, dtype='int64') * (self.densest_in_chain.size + 2) - for i,item in enumerate(Set_list): - item_min = min(item) - for groupID in item: - lookup[groupID] = item_min - self.__max_memory() - del Set_list - # To bring it all together, find the minimum values at each entry - # globally. - lookup = self._mpi_minimum_array_long(lookup) - # Now apply this to reverse_map - for chainID,groupID in enumerate(self.reverse_map): - if groupID == -1: - continue - if lookup[groupID] != (self.densest_in_chain.size + 2): - self.reverse_map[chainID] = lookup[groupID] - del lookup - """ - Now the fringe chains are connected to the proper group - (>peakthresh) with the largest boundary. But we want to look - through the boundaries between fringe groups to propagate this - along. Connections are only as good as their smallest boundary - """ - changes = 1 - while changes: - changes = 0 - for j,dens in enumerate(g_dens): - chain_high = g_high[j] - chain_low = g_low[j] - # If the density of this boundary and the densestbound of - # the other chain is higher than a chain's densestbound, then - # replace it. We also don't want to link to un-assigned - # neighbors, and we can skip neighbors we're already assigned to. - if dens >= densestbound[chain_low] and \ - densestbound[chain_high] > densestbound[chain_low] and \ - self.reverse_map[chain_high] != -1 and \ - self.reverse_map[chain_low] != self.reverse_map[chain_high]: - changes += 1 - if dens < densestbound[chain_high]: - densestbound[chain_low] = dens - else: - densestbound[chain_low] = densestbound[chain_high] - self.reverse_map[chain_low] = self.reverse_map[chain_high] - self.__max_memory() - del g_high, g_low, g_dens, densestbound - # Now we have to find the unique groupIDs, since they may have been - # merged. - temp = list(set(self.reverse_map)) - # Remove -1 from the list. - try: - temp.pop(temp.index(-1)) - except ValueError: - # There are no groups, probably. - pass - # Make a secondary map to make the IDs consecutive. - values = na.arange(len(temp)) - secondary_map = dict(itertools.izip(temp, values)) - del values - # Update reverse_map - for chain, map in enumerate(self.reverse_map): - # Don't attempt to fix non-assigned chains. - if map == -1: continue - self.reverse_map[chain] = secondary_map[map] - group_count = len(temp) - del secondary_map, temp - yt_counters("build_groups") - self.__max_memory() - return group_count - - def _translate_groupIDs(self, group_count): - """ - Using the maps, convert the particle chainIDs into their locally-final - groupIDs. - """ - yt_counters("translate_groupIDs") - self.I_own = set([]) - for i in xrange(int(self.size)): - # Don't translate non-affiliated particles. - if self.chainID[i] == -1: continue - # We want to remove the group tag from padded particles, - # so when we return it to HaloFinding, there is no duplication. - if self.is_inside[i]: - self.chainID[i] = self.reverse_map[self.chainID[i]] - self.I_own.add(self.chainID[i]) - else: - self.chainID[i] = -1 - del self.is_inside - # Create a densest_in_group, analogous to densest_in_chain. - keys = na.arange(group_count) - vals = na.zeros(group_count) - self.densest_in_group = dict(itertools.izip(keys,vals)) - self.densest_in_group_real_index = self.densest_in_group.copy() - del keys, vals - for chainID,max_dens in enumerate(self.densest_in_chain): - if max_dens == -1.0: continue - groupID = self.reverse_map[chainID] - if groupID == -1: continue - if self.densest_in_group[groupID] < max_dens: - self.densest_in_group[groupID] = max_dens - self.densest_in_group_real_index[groupID] = self.densest_in_chain_real_index[chainID] - del self.densest_in_chain, self.densest_in_chain_real_index, self.reverse_map - del self.densest_in_group - yt_counters("translate_groupIDs") - - def _precompute_group_info(self): - yt_counters("Precomp.") - """ - For all groups, compute the various global properties, except bulk - velocity, to save time in HaloFinding.py (fewer barriers!). - """ - select = (self.chainID != -1) - calc = len(na.where(select == True)[0]) - loc = na.empty((calc, 3), dtype='float64') - loc[:, 0] = na.concatenate((self.xpos, self.xpos_pad))[select] - loc[:, 1] = na.concatenate((self.ypos, self.ypos_pad))[select] - loc[:, 2] = na.concatenate((self.zpos, self.zpos_pad))[select] - self.__max_memory() - del self.xpos_pad, self.ypos_pad, self.zpos_pad - subchain = self.chainID[select] - # First we need to find the maximum density point for all groups. - # I think this will be faster than several vector operations that need - # to pull the entire chainID array out of memory several times. - yt_counters("max dens point") - max_dens_point = na.zeros((self.group_count,4),dtype='float64') - for i,part in enumerate(na.arange(self.size)[select]): - groupID = self.chainID[part] - if part < self.real_size: - real_index = self.index[part] - else: - real_index = self.index_pad[part - self.real_size] - if real_index == self.densest_in_group_real_index[groupID]: - max_dens_point[groupID] = na.array([self.density[part], \ - loc[i, 0], loc[i, 1], loc[i, 2]]) - del self.index, self.index_pad, self.densest_in_group_real_index - # Now we broadcast this, effectively, with an allsum. Even though - # some groups are on multiple tasks, there is only one densest_in_chain - # and only that task contributed above. - self.max_dens_point = self._mpi_Allsum_double(max_dens_point) - del max_dens_point - yt_counters("max dens point") - # Now CoM. - yt_counters("CoM") - CoM_M = na.zeros((self.group_count,3),dtype='float64') - Tot_M = na.zeros(self.group_count, dtype='float64') - #c_vec = self.max_dens_point[:,1:4][subchain] - na.array([0.5,0.5,0.5]) - if calc: - c_vec = self.max_dens_point[:,1:4][subchain] - na.array([0.5,0.5,0.5]) - size = na.bincount(self.chainID[select]).astype('int64') - else: - # This task has no particles in groups! - size = na.zeros(self.group_count, dtype='int64') - # In case this task doesn't have all the groups, add trailing zeros. - if size.size != self.group_count: - size = na.concatenate((size, na.zeros(self.group_count - size.size, dtype='int64'))) - if calc: - cc = loc - c_vec - cc = cc - na.floor(cc) - ms = na.concatenate((self.mass, self.mass_pad))[select] - # Most of the time, the masses will be all the same, and we can try - # to save some effort. - ms_u = na.unique(ms) - if ms_u.size == 1: - single = True - Tot_M = size.astype('float64') * ms_u - del ms_u - else: - single = False - del ms_u - cc[:,0] = cc[:,0] * ms - cc[:,1] = cc[:,1] * ms - cc[:,2] = cc[:,2] * ms - sort = subchain.argsort() - cc = cc[sort] - sort_subchain = subchain[sort] - uniq_subchain = na.unique(sort_subchain) - diff_subchain = na.ediff1d(sort_subchain) - marks = (diff_subchain > 0) - marks = na.arange(calc)[marks] + 1 - marks = na.concatenate(([0], marks, [calc])) - for i, u in enumerate(uniq_subchain): - CoM_M[u] = na.sum(cc[marks[i]:marks[i+1]], axis=0) - if not single: - for i,groupID in enumerate(subchain): - Tot_M[groupID] += ms[i] - del cc, ms - for groupID in xrange(int(self.group_count)): - # Don't divide by zero. - if groupID in self.I_own: - CoM_M[groupID] /= Tot_M[groupID] - CoM_M[groupID] += self.max_dens_point[groupID,1:4] - na.array([0.5,0.5,0.5]) - CoM_M[groupID] *= Tot_M[groupID] - # Now we find their global values - self.group_sizes = self._mpi_Allsum_long(size) - CoM_M = self._mpi_Allsum_double(CoM_M) - self.Tot_M = self._mpi_Allsum_double(Tot_M) - self.CoM = na.empty((self.group_count,3), dtype='float64') - for groupID in xrange(int(self.group_count)): - self.CoM[groupID] = CoM_M[groupID] / self.Tot_M[groupID] - yt_counters("CoM") - self.__max_memory() - # Now we find the maximum radius for all groups. - yt_counters("max radius") - max_radius = na.zeros(self.group_count, dtype='float64') - if calc: - com = self.CoM[subchain] - rad = na.fabs(com - loc) - dist = (na.minimum(rad, self.period - rad)**2.).sum(axis=1) - dist = dist[sort] - for i, u in enumerate(uniq_subchain): - max_radius[u] = na.max(dist[marks[i]:marks[i+1]]) - # Find the maximum across all tasks. - mylog.info('Fraction of particles in this region in groups: %f' % (float(calc)/self.size)) - self.max_radius = self._mpi_double_array_max(max_radius) - self.max_radius = na.sqrt(self.max_radius) - yt_counters("max radius") - yt_counters("Precomp.") - self.__max_memory() - del select, loc, subchain, CoM_M, Tot_M, size, max_radius - if calc: - del c_vec - del sort_subchain, uniq_subchain, diff_subchain, marks, dist, sort - del rad, com - - def _chain_hop(self): - self._global_padding('first') - self._global_bounds_neighbors() - self._global_padding('second') - self._is_inside('first') - mylog.info('Distributing padded particles...') - self._communicate_padding_data() - mylog.info('Building kd tree for %d particles...' % \ - self.size) - self._init_kd_tree() - # Mark particles in as being in/out of the domain. - self._is_inside('second') - # Loop over the particles to find NN for each. - mylog.info('Finding nearest neighbors/density...') - yt_counters("chainHOP_tags_dens") - chainHOP_tags_dens() - yt_counters("chainHOP_tags_dens") - self.density = fKD.dens.copy() - # Now each particle has NNtags, and a local self density. - # Let's find densest NN - mylog.info('Finding densest nearest neighbors...') - self._densestNN() - # Build the chain of links. - mylog.info('Building particle chains...') - chain_count = self._build_chains() - # This array tracks whether or not relationships for this particle - # need to be examined twice, in preconnect_chains and in connect_chains - self.search_again = na.ones(self.size, dtype='bool') - if self.premerge: - chain_count = self._preconnect_chains(chain_count) - mylog.info('Gobally assigning chainIDs...') - self._globally_assign_chainIDs(chain_count) - mylog.info('Globally finding densest in chains...') - self._create_global_densest_in_chain() - mylog.info('Building chain connections across tasks...') - self._is_inside('third') - self._connect_chains_across_tasks() - mylog.info('Communicating connected chains...') - self._communicate_annulus_chainIDs() - mylog.info('Connecting %d chains into groups...' % self.nchains) - self._connect_chains() - del fKD.dens, fKD.mass, fKD.dens - del fKD.pos, fKD.chunk_tags - free_tree(0) # Frees the kdtree object. - del self.densestNN - mylog.info('Communicating group links globally...') - self._make_global_chain_densest_n() - mylog.info('Building final groups...') - group_count = self._build_groups() - self.group_count = group_count - mylog.info('Remapping particles to final groups...') - self._translate_groupIDs(group_count) - mylog.info('Precomputing info for %d groups...' % group_count) - self._precompute_group_info() - mylog.info("All done! Max Memory = %d MB" % self.max_mem) - # We need to fix chainID and density because HaloFinding is expecting - # an array only as long as the real data. - self.chainID = self.chainID[:self.real_size] - self.density = self.density[:self.real_size] - # We'll make this a global object, which can be used to write a text - # file giving the names of hdf5 files the particles for each halo. - self.mine, self.I_own = self._mpi_info_dict(self.I_own) - self.halo_taskmap = defaultdict(set) - for taskID in self.I_own: - for groupID in self.I_own[taskID]: - self.halo_taskmap[groupID].add(taskID) - del self.I_own - del self.mass, self.xpos, self.ypos, self.zpos - - def __add_to_array(self, arr, key, value, type): - """ - In an effort to replace the functionality of a dict with an array, in - order to save memory, this function adds items to an array. If the - array is not long enough, it is resized and filled with 'bad' values.""" - - try: - arr[key] = value - except IndexError: - arr = na.concatenate((arr, na.ones(10000, dtype=type)*-1)) - arr[key] = value - return arr - - def __clean_up_array(self, arr): - good = (arr != -1) - return arr[good] - - def __max_memory(self): - my_mem = get_memory_usage() - self.max_mem = max(my_mem, self.max_mem) \ No newline at end of file diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/parallelHOP/run.py --- a/yt/lagos/parallelHOP/run.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -from yt.config import ytcfg - -ytcfg["yt","time_functions"] = "True" - -from yt.mods import * - -yt_counters("Full Time") - -yt_counters("yt Hierarchy") -pf = load('data0005') - -pf.h -yt_counters("yt Hierarchy") - -h = yt.lagos.HaloFinding.parallelHF(pf, threshold=160.0, safety=2.5, \ -dm_only=False,resize=True, fancy_padding=True, rearrange=True) - -yt_counters("Writing Data") -h.write_out('dist-chain.out') -h.write_particle_lists_txt("chain") -h.write_particle_lists("chain") -yt_counters("Writing Data") - -yt_counters("Full Time") diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/setup.py --- a/yt/lagos/setup.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -#!/usr/bin/env python -import setuptools -import os, sys - -def check_for_hdf5(): - # First up: HDF5_DIR in environment - if "HDF5_DIR" in os.environ: - hdf5_dir = os.environ["HDF5_DIR"] - hdf5_inc = os.path.join(hdf5_dir, "include") - hdf5_lib = os.path.join(hdf5_dir, "lib") - print "HDF5_LOCATION: HDF5_DIR: %s, %s" % (hdf5_inc, hdf5_lib) - return (hdf5_inc, hdf5_lib) - # Next up, we try hdf5.cfg - elif os.path.exists("hdf5.cfg"): - hdf5_dir = open("hdf5.cfg").read().strip() - hdf5_inc = os.path.join(hdf5_dir, "include") - hdf5_lib = os.path.join(hdf5_dir, "lib") - print "HDF5_LOCATION: hdf5.cfg: %s, %s" % (hdf5_inc, hdf5_lib) - return (hdf5_inc, hdf5_lib) - # Now we see if ctypes can help us: - try: - import ctypes.util - hdf5_libfile = ctypes.util.find_library("hdf5") - if hdf5_libfile is not None and os.path.isfile(hdf5_libfile): - # Now we've gotten a library, but we'll need to figure out the - # includes if this is going to work. It feels like there is a - # better way to pull off two directory names. - hdf5_dir = os.path.dirname(os.path.dirname(hdf5_libfile)) - if os.path.isdir(os.path.join(hdf5_dir, "include")) and \ - os.path.isfile(os.path.join(hdf5_dir, "include", "hdf5.h")): - hdf5_inc = os.path.join(hdf5_dir, "include") - hdf5_lib = os.path.join(hdf5_dir, "lib") - print "HDF5_LOCATION: HDF5 found in: %s, %s" % (hdf5_inc, hdf5_lib) - return hdf5_inc, hdf5_lib - except ImportError: - pass - print "Reading HDF5 location from hdf5.cfg failed." - print "Please place the base directory of your HDF5 install in hdf5.cfg and restart." - print "(ex: \"echo '/usr/local/' > hdf5.cfg\" )" - sys.exit(1) - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - config = Configuration('lagos',parent_package,top_path) - config.make_config_py() # installs __config__.py - config.make_svn_version_py() - config.add_extension("PointCombine", "yt/lagos/PointCombine.c", libraries=["m"]) - config.add_subpackage("hop") - config.add_subpackage("fof") - config.add_subpackage("parallelHOP") - hdf5_inc, hdf5_lib = check_for_hdf5() - include_dirs=[hdf5_inc] - library_dirs=[hdf5_lib] - config.add_extension("HDF5LightReader", "yt/lagos/HDF5LightReader.c", - define_macros=[("H5_USE_16_API",True)], - libraries=["m","hdf5"], - library_dirs=library_dirs, include_dirs=include_dirs) - return config diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/lagos/two_point_functions.py --- a/yt/lagos/two_point_functions.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,854 +0,0 @@ -""" -Two Point Functions Framework. - -Author: Stephen Skory -Affiliation: UCSD Physics/CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2010 Stephen Skory. 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 . -""" - -from yt.lagos import * -from yt.math_utils import * -from yt.performance_counters import yt_counters, time_function -try: - from yt.extensions.kdtree import * -except ImportError: - mylog.debug("The Fortran kD-Tree did not import correctly.") - -import math, sys, itertools, inspect, types, time -from collections import defaultdict - -sep = 12 - -class TwoPointFunctions(ParallelAnalysisInterface): - def __init__(self, pf, fields, left_edge=None, right_edge=None, - total_values=1000000, comm_size=10000, length_type="lin", - length_number=10, length_range=None, vol_ratio = 1, - salt=0): - r""" Initialize a two point functions object. - - Parameters - ---------- - total_values : Integer - How many total (global) pair calculations to run for each of the - functions specified. Default: 1000000. - comm_size : Integer - How entries are sent during communication. Default: 10000. - length_type : String - Controls the even spacing of the rulers lengths in - logarithmic or linear space, set by "log" or "lin", respectively. - Default: "lin". - length_number : Integer - Sets how many lengths to create, evenly spaced by the above - parameter. Default: 10. - length_range : Float - A min/max pair for the range of values to search the over - the simulational volume. Default: [sqrt(3)dx, 1/2*shortest box edge], - where dx is the smallest grid cell size. - vol_ratio : Integer - How to multiply-assign subvolumes to the parallel - tasks. This number must be an integer factor of the total number of tasks or - very bad things will happen. The default value of 1 will assign one task - to each subvolume, and there will be an equal number of subvolumes as tasks. - A value of 2 will assign two tasks to each subvolume and there will be - one-half as many subvolumes as tasks. - A value equal to the number of parallel tasks will result in each task - owning a complete copy of all the fields data, meaning each task will be - operating on the identical full volume. - Setting it to -1 will automatically adjust it such that each task - owns the entire volume. Default = 1. - salt : Integer - A number that will be added to the random number generator - seed. Use this if a different random series of numbers is desired when - keeping everything else constant from this set: (MPI task count, - number of ruler lengths, ruler min/max, number of functions, - number of point pairs per ruler length). Default = 0. - - Examples - -------- - >>> tpf = TwoPointFunctions(pf, ["x-velocity", "y-velocity", "z-velocity"], - ... total_values=1e5, comm_size=10000, - ... length_number=10, length_range=[1./128, .5], - ... length_type="log") - """ - try: - fKD - except NameError: - raise ImportError("You need to install the Forthon kD-Tree") - self._fsets = [] - self.fields = fields - # MPI stuff. - self.size = self._mpi_get_size() - self.mine = self._mpi_get_rank() - self.vol_ratio = vol_ratio - if self.vol_ratio == -1: - self.vol_ratio = self.size - self.total_values = int(total_values / self.size) - # For communication. - self.recv_hooks = [] - self.send_hooks = [] - self.done_hooks = [] - self.comm_size = min(int(comm_size), self.total_values) - self.pf = pf - self.nlevels = pf.h.max_level - self.period = self.pf['DomainRightEdge'] - self.pf['DomainLeftEdge'] - self.min_edge = min(self.period) - self.hierarchy = pf.h - self.center = (pf["DomainRightEdge"] + pf["DomainLeftEdge"])/2.0 - # Figure out the range of ruler lengths. - if length_range == None: - length_range = [math.sqrt(3) * self.pf.h.get_smallest_dx(), - self.min_edge/2.] - else: - if len(length_range) != 2: - raise ValueError("length_range must have two values.") - if length_range[1] <= length_range[0]: - raise ValueError("length_range[1] must be larger than length_range[0]") - if length_range[1] > self.min_edge/2.: - length_range[1] = self.min_edge/2. - mylog.info("Automatically adjusting length_range[1] to half the shortest box edge.") - if length_range[0] == -1 or length_range[0] == -1.: - mylog.info("Automatically adjusting length_range[0] to %1.5e." % \ - (math.sqrt(3) * self.pf.h.get_smallest_dx())) - length_range[0] = math.sqrt(3) * self.pf.h.get_smallest_dx() - # Make the list of ruler lengths. - if length_type == "lin": - self.lengths = na.linspace(length_range[0], length_range[1], - length_number) - elif length_type == "log": - self.lengths = na.logspace(math.log10(length_range[0]), - math.log10(length_range[1]), length_number) - else: - # Something went wrong. - raise SyntaxError("length_type is either \"lin\" or \"log\".") - # Subdivide the volume. - if not left_edge or not right_edge: - self.left_edge = self.pf['DomainLeftEdge'] - self.right_edge = self.pf['DomainRightEdge'] - padded, self.LE, self.RE, self.ds = self._partition_hierarchy_3d(padding=0., - rank_ratio = self.vol_ratio) - else: - self.left_edge = left_edge - self.right_edge = right_edge - # We do this twice, first with no 'buffer' to get the unbuffered - # self.LE/RE, and then second to get a buffered self.ds. - padded, self.LE, self.RE, temp = \ - self._partition_region_3d(left_edge, right_edge, - rank_ratio=self.vol_ratio) - padded, temp, temp, self.ds = \ - self._partition_region_3d(left_edge - self.lengths[-1], \ - right_edge + self.lengths[-1], rank_ratio=self.vol_ratio) - mylog.info("LE %s RE %s %s" % (str(self.LE), str(self.RE), str(self.ds))) - self.width = self.ds.right_edge - self.ds.left_edge - self.mt = na.random.mtrand.RandomState(seed = 1234 * self.mine + salt) - - def add_function(self, function, out_labels, sqrt, corr_norm=None): - r"""Add a function to the list that will be evaluated at the - generated pairs of points. - - Parameters - ---------- - function : Function - The two point function of the form fcn(a, b, r1, r2, vec). - out_labels : List of strings - A list of strings labeling the outputs of the function. - sqrt : List of booleans - A list of booleans which when True will square-root the corresponding - element of the output in the text output (write_out_means()). - corr_norm : Float - Used when calculating two point correlations. If set, the output - of the function is divided by this number. Default = None. - - Examples - -------- - >>> f1 = tpf.add_function(function=rms_vel, out_labels=['RMSvdiff'], - ... sqrt=[True]) - """ - fargs = inspect.getargspec(function) - if len(fargs.args) != 5: - raise SyntaxError("The function %s needs five arguments." %\ - function.__name__) - out_labels = list(out_labels) - if len(out_labels) < 1: - raise SyntaxError("Please specify at least one out_labels for function %s." %\ - function.__name__) - sqrt = list(sqrt) - if len(sqrt) != len(out_labels): - raise SyntaxError("Please have the same number of elements in out_labels as in sqrt for function %s." %\ - function.__name__) - self._fsets.append(FcnSet(self, function, self.min_edge, - out_labels, sqrt,corr_norm)) - return self._fsets[-1] - - def __getitem__(self, key): - return self._fsets[key] - - def run_generator(self): - r"""After all the functions have been added, run the generator. - - Examples - -------- - >>> tpf.run_generator() - """ - yt_counters("run_generator") - # We need a function! - if len(self._fsets) == 0: - mylog.error("You need to add at least one function!") - return None - # Do all the startup tasks to get the grid points. - if self.nlevels == 0: - yt_counters("build_sort") - self._build_sort_array() - self.sort_done = False - yt_counters("build_sort") - else: - yt_counters("init_kd_tree") - self._init_kd_tree() - self.sort_done = True - yt_counters("init_kd_tree") - # Store the fields. - self.stored_fields = {} - yt_counters("getting data") - for field in self.fields: - self.stored_fields[field] = self.ds[field].copy() - self.ds.clear_data() - # If the arrays haven't been sorted yet and need to be, do that. - if not self.sort_done: - for field in self.fields: - self.stored_fields[field] = self.stored_fields[field][self.sort] - del self.sort - self.sort_done = True - yt_counters("getting data") - self._build_fields_vals() - yt_counters("big loop over lengths") - t_waiting = 0. - for bigloop, length in enumerate(self.lengths): - self._build_points_array() - if self.mine == 0: - mylog.info("Doing length %1.5e" % length) - # Things stop when this value below equals total_values. - self.generated_points = 0 - self.gen_array = na.zeros(self.size, dtype='int64') - self.comm_cycle_count = 0 - self.final_comm_cycle_count = 0 - self.sent_done = False - self._setup_done_hooks_on_root() - # While everyone else isn't done or I'm not done, we loop. - while self._should_cycle(): - self._setup_recv_arrays() - self._send_arrays() - t0 = time.time() - self._mpi_Request_Waitall(self.send_hooks) - self._mpi_Request_Waitall(self.recv_hooks) - t1 = time.time() - t_waiting += (t1-t0) - if (self.recv_points < -1.).any() or (self.recv_points > 1.).any(): # or \ - #(na.abs(na.log10(na.abs(self.recv_points))) > 20).any(): - raise ValueError("self.recv_points is no good!") - self.points = self.recv_points.copy() - self.fields_vals = self.recv_fields_vals.copy() - self.gen_array = self.recv_gen_array.copy() - self._eval_points(length) - self.gen_array[self.mine] = self.generated_points - self.comm_cycle_count += 1 - if self.generated_points == self.total_values: - self._send_done_to_root() - if self.mine == 0: - mylog.info("Length (%d of %d) %1.5e took %d communication cycles to complete." % \ - (bigloop+1, len(self.lengths), length, self.comm_cycle_count)) - yt_counters("big loop over lengths") - if self.nlevels >= 1: - del fKD.pos, fKD.qv_many, fKD.nn_tags - free_tree(0) # Frees the kdtree object. - yt_counters("allsum") - self._allsum_bin_hits() - mylog.info("Spent %f seconds waiting for communication." % t_waiting) - yt_counters("allsum") - yt_counters("run_generator") - - def _init_kd_tree(self): - """ - Builds the kd tree of grid center points. - """ - # Grid cell centers. - mylog.info("Multigrid: Building kD-Tree.") - xp = self.ds["x"] - yp = self.ds["y"] - zp = self.ds["z"] - fKD.pos = na.asfortranarray(na.empty((3,xp.size), dtype='float64')) - fKD.pos[0, :] = xp[:] - fKD.pos[1, :] = yp[:] - fKD.pos[2, :] = zp[:] - fKD.nn = 1 - fKD.sort = False - fKD.rearrange = True - create_tree(0) - - def _build_sort_array(self): - """ - When running on a unigrid simulation, the kD tree isn't necessary. - But we need to ensure that the points are sorted in the usual manner - allowing values to be found via array indices. - """ - mylog.info("Unigrid: finding cell centers.") - xp = self.ds["x"] - yp = self.ds["y"] - zp = self.ds["z"] - self.sizes = [na.unique(xp).size, na.unique(yp).size, na.unique(zp).size] - self.sort = na.lexsort([zp, yp, xp]) - del xp, yp, zp - self.ds.clear_data() - - def _build_fields_vals(self): - """ - Builds an array to store the field values array. - """ - self.fields_vals = na.empty((self.comm_size, len(self.fields)*2), \ - dtype='float64') - # At the same time build a dict to label the columns. - self.fields_columns = {} - for i,field in enumerate(self.fields): - self.fields_columns[field] = i - - def _build_points_array(self): - """ - Initializes the array that contains the random points as all negatives - to start with. - """ - self.points = na.ones((self.comm_size, 6), dtype='float64') * -1.0 - - def _setup_done_hooks_on_root(self): - """ - Opens non-blocking receives on root pointing to all the other tasks - """ - if self.mine != 0: - return - self.recv_done = {} - for task in xrange(self.size): - if task == self.mine: continue - self.recv_done[task] = na.zeros(1, dtype='int64') - self.done_hooks.append(self._mpi_Irecv_long(self.recv_done[task], \ - task, tag=15)) - - def _send_done_to_root(self): - """ - Tell the root process that I'm done. - """ - # If I've already done this, don't do it again. - if self.sent_done: return - if self.mine !=0: - # I send when I *think* things should finish. - self.send_done = na.ones(1, dtype='int64') * \ - (self.size / self.vol_ratio -1) + self.comm_cycle_count - self.done_hooks.append(self._mpi_Isend_long(self.send_done, \ - 0, tag=15)) - else: - # As root, I need to mark myself! - self.recv_done[0] = na.ones(1, dtype='int64') * \ - (self.size / self.vol_ratio -1) + self.comm_cycle_count - self.sent_done = True - - def _should_cycle(self): - """ - Determine if I should continue cycling the communication. - """ - if self.mine == 0: - # If other tasks aren't finished, this will return False. - status = self._mpi_Request_Testall(self.done_hooks) - # Convolve this with with root's status. - status = status * (self.generated_points == self.total_values) - if status == 1: - # If they are all finished, meaning Testall returns True, - # and root has made its points, we find - # the biggest value in self.recv_done and stop there. - status = max(self.recv_done.values()) - else: - status = 0 - # Broadcast the status from root - we stop only if root thinks we should - # stop. - status = self._mpi_bcast_pickled(status) - if status == 0: return True - if self.comm_cycle_count < status: - return True - # If we've come this far, we're done. - return False - - def _setup_recv_arrays(self): - """ - Creates the recv buffers and calls a non-blocking MPI receive pointing - to the left-hand neighbor. - """ - self.recv_points = na.ones((self.comm_size, 6), dtype='float64') * -1. - self.recv_fields_vals = na.zeros((self.comm_size, len(self.fields)*2), \ - dtype='float64') - self.recv_gen_array = na.zeros(self.size, dtype='int64') - self.recv_hooks.append(self._mpi_Irecv_double(self.recv_points, \ - (self.mine-1)%self.size, tag=10)) - self.recv_hooks.append(self._mpi_Irecv_double(self.recv_fields_vals, \ - (self.mine-1)%self.size, tag=20)) - self.recv_hooks.append(self._mpi_Irecv_long(self.recv_gen_array, \ - (self.mine-1)%self.size, tag=40)) - - def _send_arrays(self): - """ - Send the data arrays to the right-hand neighbor. - """ - self.send_hooks.append(self._mpi_Isend_double(self.points,\ - (self.mine+1)%self.size, tag=10)) - self.send_hooks.append(self._mpi_Isend_double(self.fields_vals,\ - (self.mine+1)%self.size, tag=20)) - self.send_hooks.append(self._mpi_Isend_long(self.gen_array, \ - (self.mine+1)%self.size, tag=40)) - - def _allsum_bin_hits(self): - """ - Add up the hits to all the bins globally for all functions. - """ - for fset in self._fsets: - fset.too_low = self._mpi_allsum(fset.too_low) - fset.too_high = self._mpi_allsum(fset.too_high) - fset.binned = {} - if self.mine == 0: - mylog.info("Function %s had values out of range for these fields:" % \ - fset.function.__name__) - for i,field in enumerate(fset.out_labels): - mylog.info("Field %s had %d values too high and %d too low that were not binned." % \ - (field, fset.too_high[i], fset.too_low[i])) - for length in self.lengths: - fset.length_bin_hits[length] = \ - self._mpi_Allsum_long(fset.length_bin_hits[length]) - # Find out how many were successfully binned. - fset.binned[length] = fset.length_bin_hits[length].sum() - # Normalize the counts. - fset.length_bin_hits[length] = \ - fset.length_bin_hits[length].astype('float64') / \ - fset.binned[length] - # Return it to its original shape. - fset.length_bin_hits[length] = \ - fset.length_bin_hits[length].reshape(fset.bin_number) - - def _pick_random_points(self, length, size): - """ - Picks out size random pairs separated by length *length*. - """ - # First make random points inside this subvolume. - r1 = na.empty((size,3), dtype='float64') - for dim in range(3): - r1[:,dim] = self.mt.uniform(low=self.ds.left_edge[dim], - high=self.ds.right_edge[dim], size=size) - # Next we find the second point, determined by a random - # theta, phi angle. - theta = self.mt.uniform(low=0, high=2.*math.pi, size=size) - phi = self.mt.uniform(low=-math.pi/2., high=math.pi/2., size=size) - r2 = na.empty((size,3), dtype='float64') - r2[:,0] = r1[:,0] + length * na.cos(theta) * na.cos(phi) - r2[:,1] = r1[:,1] + length * na.sin(theta) * na.cos(phi) - r2[:,2] = r1[:,2] + length * na.sin(phi) - # Reflect so it's inside the (full) volume. - r2 %= self.period - return (r1, r2) - - def _find_nearest_cell(self, points): - """ - Finds the closest grid cell for each point in a vectorized manner. - """ - if self.nlevels == 0: - pos = (points - self.ds.left_edge) / self.width - n = (self.sizes[2] * pos[:,2]).astype('int32') - n += self.sizes[2] * (self.sizes[1] * pos[:,1]).astype('int32') - n += self.sizes[2] * self.sizes[1] * (self.sizes[0] * pos[:,0]).astype('int32') - else: - fKD.qv_many = points.T - fKD.nn_tags = na.asfortranarray(na.empty((1, points.shape[0]), dtype='int64')) - find_many_nn_nearest_neighbors() - # The -1 is for fortran counting. - n = fKD.nn_tags[0,:] - 1 - return n - - def _get_fields_vals(self, points): - """ - Given points, return the values for the fields we need for those - points. - """ - # First find the grid data index field. - indices = self._find_nearest_cell(points) - results = na.empty((len(indices), len(self.fields)), dtype='float64') - # Put the field values into the columns of results. - for field in self.fields: - col = self.fields_columns[field] - results[:, col] = self.stored_fields[field][indices] - return results - - - def _eval_points(self, length): - # We need to loop over the points array at least once. Further - # iterations only happen if we have added new points to the array, - # but not as many as we want to, so we need to check again to see if - # we can put more points into the buffer. - added_points = True - while added_points: - # If we need to, add more points to the points array. - if self.generated_points < self.total_values: - # Look for 'empty' slots to put in new pairs. - select = (self.points[:,0] < 0) - ssum = select.sum() - # We'll generate only as many points as we need to/can. - size = min(ssum, self.total_values - self.generated_points) - (new_r1,new_r2) = self._pick_random_points(length, size) - self.generated_points += size - # If size != select.sum(), we need to pad the end of new_r1/r2 - # which is what is effectively happening below. - newpoints = na.ones((ssum, 6), dtype='float64') * -1. - newpoints[:size,:3] = new_r1 - newpoints[:size,3:] = new_r2 - # Now we insert them into self.points. - self.points[select] = newpoints - else: - added_points = False - - # If we have an empty buffer here, we can skip everything below. - if (self.points < 0).all(): - added_points = False # Not strictly required, but clearer. - break - - # Now we have a points array that is either full of unevaluated points, - # or I don't need to make any new points and I'm just processing the - # array. Start by finding the indices of the points I own. - self.points.shape = (self.comm_size*2, 3) # Doesn't make a copy - fast! - select = na.bitwise_or((self.points < self.ds.left_edge).any(axis=1), - (self.points >= self.ds.right_edge).any(axis=1)) - select = na.invert(select) - mypoints = self.points[select] - if mypoints.size > 0: - # Get the fields values. - results = self._get_fields_vals(mypoints) - # Put this into self.fields_vals. - self.fields_vals.shape = (self.comm_size*2, len(self.fields)) - self.fields_vals[select] = results - - # Put our arrays back into their original shapes cheaply! - if mypoints.size > 0: - self.fields_vals.shape = (self.comm_size, len(self.fields)*2) - self.points.shape = (self.comm_size, 6) - - # To run the functions, what is key is that the - # second point in the pair is ours. - second_points = self.points[:,3:] - select = na.bitwise_or((second_points < self.ds.left_edge).any(axis=1), - (second_points >= self.ds.right_edge).any(axis=1)) - select = na.invert(select) - if select.any(): - points_to_eval = self.points[select] - fields_to_eval = self.fields_vals[select] - - # Find the normal vector between our points. - vec = na.abs(points_to_eval[:,:3] - points_to_eval[:,3:]) - norm = na.sqrt(na.sum(na.multiply(vec,vec), axis=1)) - # I wish there was a better way to do this, but I can't find it. - for i, n in enumerate(norm): - vec[i] = na.divide(vec[i], n) - - # Now evaluate the functions. - for fcn_set in self._fsets: - fcn_results = fcn_set._eval_st_fcn(fields_to_eval,points_to_eval, - vec) - fcn_set._bin_results(length, fcn_results) - - # Now clear the buffers at the processed points. - self.points[select] = na.array([-1.]*6, dtype='float64') - - else: - # We didn't clear any points, so we should move on with our - # lives and pass this buffer along. - added_points = False - - @parallel_blocking_call - def write_out_means(self): - r"""Writes out the weighted-average value for each function for - each dimension for each ruler length to a text file. The data is written - to files of the name 'function_name.txt' in the current working - directory. - - Examples - -------- - >>> tpf.write_out_means() - """ - for fset in self._fsets: - fp = self._write_on_root("%s.txt" % fset.function.__name__) - fset._avg_bin_hits() - line = "# length".ljust(sep) - line += "count".ljust(sep) - for dim in fset.dims: - line += ("%s" % fset.out_labels[dim]).ljust(sep) - fp.write(line + "\n") - for length in self.lengths: - line = ("%1.5e" % length).ljust(sep) - line += ("%d" % fset.binned[length]).ljust(sep) - for dim in fset.dims: - if fset.sqrt[dim]: - line += ("%1.5e" % \ - math.sqrt(fset.length_avgs[length][dim])).ljust(sep) - else: - line += ("%1.5e" % \ - fset.length_avgs[length][dim]).ljust(sep) - line += "\n" - fp.write(line) - fp.close() - - @parallel_root_only - def write_out_arrays(self): - r"""Writes out the raw probability bins and the bin edges to an HDF5 file - for each of the functions. The files are named - 'function_name.txt' and saved in the current working directory. - - Examples - -------- - >>> tpf.write_out_arrays() - """ - if self.mine == 0: - for fset in self._fsets: - f = h5py.File("%s.h5" % fset.function.__name__, "w") - bin_names = [] - prob_names = [] - bin_counts = [] - for dim in fset.dims: - f.create_dataset("/bin_edges_%02d_%s" % \ - (dim, fset.out_labels[dim]), \ - data=fset.bin_edges[dim]) - bin_names.append("/bin_edges_%02d_%s" % \ - (dim, fset.out_labels[dim])) - for i,length in enumerate(self.lengths): - f.create_dataset("/prob_bins_%05d" % i, \ - data=fset.length_bin_hits[length]) - prob_names.append("/prob_bins_%05d" % i) - bin_counts.append([fset.too_low.sum(), fset.binned[length], - fset.too_high.sum()]) - f.create_dataset("/bin_edges_names", data=bin_names) - #f.create_dataset("/prob_names", data=prob_names) - f.create_dataset("/lengths", data=self.lengths) - f.create_dataset("/counts", data=bin_counts) - f.close() - - @parallel_root_only - def write_out_correlation(self): - r"""A special output function for doing two point correlation functions. - Outputs the correlation function xi(r) in a text file - 'function_name_corr.txt' in the current working directory. - - Examples - -------- - >>> tpf.write_out_correlation() - """ - for fset in self._fsets: - # Only operate on correlation functions. - if fset.corr_norm == None: continue - fp = self._write_on_root("%s_correlation.txt" % fset.function.__name__) - line = "# length".ljust(sep) - line += "\\xi".ljust(sep) - fp.write(line + "\n") - xi = fset._corr_sum_norm() - for length in self.lengths: - line = ("%1.5e" % length).ljust(sep) - line += ("%1.5e" % xi[length]).ljust(sep) - fp.write(line + "\n") - fp.close() - -class FcnSet(TwoPointFunctions): - def __init__(self,tpf, function, min_edge, out_labels, sqrt, corr_norm): - self.tpf = tpf # The overarching TPF class - self.function = function # Function to eval between the two points. - self.min_edge = min_edge # The length of the minimum edge of the box. - self.out_labels = out_labels # For output. - self.sqrt = sqrt # which columns to sqrt on output. - self.corr_norm = corr_norm # A number used to normalize a correlation function. - # These below are used to track how many times the function returns - # unbinned results. - self.too_low = na.zeros(len(self.out_labels), dtype='int32') - self.too_high = na.zeros(len(self.out_labels), dtype='int32') - - def set_pdf_params(self, bin_type="lin", bin_number=1000, bin_range=None): - r"""Set the parameters used to build the Probability Distribution Function - for each ruler length for this function. The values output by the - function are slotted into the bins described here. - - Parameters - ---------- - bin_type : String - Controls the edges of the bins spaced evenly in - logarithmic or linear space, set by "log" or "lin", respectively. - A single string, or list of strings for N-dim binning. - Default = "lin". - bin_number : Integer - Sets how many bins to create, evenly spaced by the above - parameter. A single integer, or a list of integers for N-dim - binning. Default = 1000. - bin_range : Float - A pair of values giving the range for the bins. - A pair of floats (a list), or a list of pairs for N-dim binning. - Default = None. - - Examples - -------- - >>> f1.set_pdf_params(bin_type='log', bin_range=[5e4, 5.5e13], - ... bin_number=1000) - """ - # This should be called after setSearchParams. - if not hasattr(self.tpf, "lengths"): - mylog.error("Please call setSearchParams() before calling setPDFParams().") - return None - # Make sure they're either all lists or only one is. - input = [bin_type, bin_number, bin_range] - lists = 0 - for thing in input: - if type(thing) == types.ListType: - lists += 1 - if lists > 1 and lists < 3: - mylog.error("Either all the inputs need to be lists, or only one.") - return None - # Make sure they're all the same length if they're lists. - if lists == 3: - first_len = 0 - for thing in input: - if first_len == 0: - first_len = len(thing) - if first_len == 0: - mylog.error("Input cannot be an empty list.") - return None - continue - if first_len != len(thing): - mylog.error("All the inputs need to have the same length.") - return None - # If they are not all lists, put the input into lists for convenience. - if lists == 1: - bin_type, bin_number = [bin_type], [bin_number] - bin_range = [bin_range] - self.bin_type = bin_type - self.bin_number = na.array(bin_number) - 1 - self.dims = range(len(bin_type)) - # Create the dict that stores the arrays to store the bin hits, and - # the arrays themselves. - self.length_bin_hits = {} - for length in self.tpf.lengths: - # It's easier to index flattened, but will be unflattened later. - self.length_bin_hits[length] = na.zeros(self.bin_number, - dtype='int64').flatten() - # Create the bin edges for each dimension. - # self.bins is indexed by dimension - self.bin_edges = {} - for dim in self.dims: - # Error check. - if len(bin_range[dim]) != 2: - raise ValueError("bin_range must have two values.") - if bin_range[dim][1] <= bin_range[dim][0]: - raise ValueError("bin_range[1] must be larger than bin_range[0]") - # Make the edges for this dimension. - if bin_type[dim] == "lin": - self.bin_edges[dim] = na.linspace(bin_range[dim][0], bin_range[dim][1], - bin_number[dim]) - elif bin_type[dim] == "log": - self.bin_edges[dim] = na.logspace(math.log10(bin_range[dim][0]), - math.log10(bin_range[dim][1]), bin_number[dim]) - else: - raise SyntaxError("bin_edges is either \"lin\" or \"log\".") - - def _eval_st_fcn(self, results, points, vec): - """ - Return the value of the function using the provided results. - """ - return self.function(results[:,:len(self.tpf.fields)], - results[:,len(self.tpf.fields):], points[:,:3], points[:,3:], vec) - """ - NOTE - A function looks like: - def stuff(a,b,r1,r2, vec): - return [(a[0] - b[0])/(a[1] + b[1])] - where a and b refer to different points in space and the indices - are for the different fields, which are given when the function is - added. The results need to be a list or array even if it's only one - item. - """ - - def _bin_results(self, length, results): - """ - Add hits to the bins corresponding to these results. length_hit_bins - is flattened, so we need to figure out the offset for this hit by - factoring the sizes of the other dimensions. - """ - hit_bin = na.zeros(results.shape[0], dtype='int64') - multi = 1 - good = na.ones(results.shape[0], dtype='bool') - for dim in range(len(self.out_labels)): - for d1 in range(dim): - multi *= self.bin_edges[d1].size - if dim == 0 and len(self.out_labels)==1: - try: - digi = na.digitize(results, self.bin_edges[dim]) - except ValueError: - # The user probably did something like - # return a * b rather than - # return a[0] * b[0], which will only happen - # for single field functions. - digi = na.digitize(results[0], self.bin_edges[dim]) - else: - digi = na.digitize(results[:,dim], self.bin_edges[dim]) - too_low = (digi == 0) - too_high = (digi == self.bin_edges[dim].size) - self.too_low[dim] += (too_low).sum() - self.too_high[dim] += (too_high).sum() - newgood = na.bitwise_and(na.invert(too_low), na.invert(too_high)) - good = na.bitwise_and(good, newgood) - hit_bin += na.multiply((digi - 1), multi) - digi_bins = na.arange(self.length_bin_hits[length].size+1) - hist, digi_bins = na.histogram(hit_bin[good], digi_bins) - self.length_bin_hits[length] += hist - - def _dim_sum(self, a, dim): - """ - Given a multidimensional array a, this finds the sum over all the - elements leaving the dimension dim untouched. - """ - dims = na.arange(len(a.shape)) - dims = na.flipud(dims) - gt_dims = dims[dims > dim] - lt_dims = dims[dims < dim] - iter_dims = na.concatenate((gt_dims, lt_dims)) - for this_dim in iter_dims: - a = a.sum(axis=this_dim) - return a - - def _avg_bin_hits(self): - """ - For each dimension and length of bin_hits return the weighted average. - """ - self.length_avgs = defaultdict(dict) - for length in self.tpf.lengths: - for dim in self.dims: - self.length_avgs[length][dim] = \ - (self._dim_sum(self.length_bin_hits[length], dim) * \ - ((self.bin_edges[dim][:-1] + self.bin_edges[dim][1:]) / 2.)).sum() - - def _corr_sum_norm(self): - """ - Return the correlations xi for this function. We are tacitly assuming - that all correlation functions are one dimensional. - """ - xi = {} - for length in self.tpf.lengths: - xi[length] = -1 + na.sum(self.length_bin_hits[length] * \ - self.bin_edges[0][:-1]) / self.corr_norm - return xi diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/logger.py --- a/yt/logger.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -""" -Logging facility for yt -Will initialize everything, and associate one with each module - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2007-2009 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 . -""" - -import logging, os -import logging.handlers as handlers -from yt.config import ytcfg - -# This next bit is grabbed from: -# http://stackoverflow.com/questions/384076/how-can-i-make-the-python-logging-output-to-be-colored -def add_coloring_to_emit_ansi(fn): - # add methods we need to the class - def new(*args): - levelno = args[1].levelno - if(levelno>=50): - color = '\x1b[31m' # red - elif(levelno>=40): - color = '\x1b[31m' # red - elif(levelno>=30): - color = '\x1b[33m' # yellow - elif(levelno>=20): - color = '\x1b[32m' # green - elif(levelno>=10): - color = '\x1b[35m' # pink - else: - color = '\x1b[0m' # normal - args[1].msg = color + args[1].msg + '\x1b[0m' # normal - #print "after" - return fn(*args) - return new - -if ytcfg.getboolean("yt","coloredlogs"): - logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit) - -level = min(max(ytcfg.getint("yt", "loglevel"), 0), 50) -fstring = "%(name)-10s %(levelname)-10s %(asctime)s %(message)s" -logging.basicConfig( - format=fstring, - level=level -) - -f = logging.Formatter("%(levelname)-10s %(asctime)s %(message)s") - -rootLogger = logging.getLogger() - -ytLogger = logging.getLogger("yt") -ytLogger.debug("Set log level to %s", level) - -fidoLogger = logging.getLogger("yt.fido") -ravenLogger = logging.getLogger("yt.raven") -lagosLogger = logging.getLogger("yt.lagos") -enkiLogger = logging.getLogger("yt.enki") -deliveratorLogger = logging.getLogger("yt.deliverator") -reasonLogger = logging.getLogger("yt.reason") - -# Maybe some day we'll make this more configurable... unfortunately, for now, -# we preserve thread-safety by opening in the current directory. - -mb = 10*1024*1024 -bc = 10 - -loggers = [] -file_handlers = [] - -if ytcfg.getboolean("yt","logfile") and os.access(".", os.W_OK): - log_file_name = ytcfg.get("yt","LogFileName") - ytFileHandler = handlers.RotatingFileHandler(log_file_name, - maxBytes=mb, backupCount=bc) - k = logging.Formatter(fstring) - ytFileHandler.setFormatter(k) - ytLogger.addHandler(ytFileHandler) - loggers.append(ytLogger) - file_handlers.append(ytFileHandler) - -def disable_stream_logging(): - # We just remove the root logger's handlers - for handler in rootLogger.handlers: - if isinstance(handler, logging.StreamHandler): - rootLogger.removeHandler(handler) - -def disable_file_logging(): - for logger, handler in zip(loggers, file_handlers): - logger.removeHandler(handler) - -if ytcfg.getboolean("yt","suppressStreamLogging"): - disable_stream_logging() diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/math_utils.py --- a/yt/math_utils.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,411 +0,0 @@ -""" -Commonly used mathematical functions. - -Author: Matthew Turk -Affiliation: UCSD Physics/CASS -Author: Stephen Skory -Affiliation: UCSD Physics/CASS -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2008-2009 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 . -""" - -import numpy as na -import math - -def periodic_dist(a, b, period): - r"""Find the Euclidian periodic distance between two points. - - Parameters - ---------- - a : array or list - An array or list of floats. - - b : array of list - An array or list of floats. - - period : float or array or list - If the volume is symmetrically periodic, this can be a single float, - otherwise an array or list of floats giving the periodic size of the - volume for each dimension. - - Examples - -------- - >>> a = na.array([0.1, 0.1, 0.1]) - >>> b = na.array([0.9, 0,9, 0.9]) - >>> period = 1. - >>> dist = periodic_dist(a, b, 1.) - >>> dist - 0.3464102 - """ - a = na.array(a) - b = na.array(b) - if a.size != b.size: RunTimeError("Arrays must be the same shape.") - c = na.empty((2, a.size), dtype="float64") - c[0,:] = abs(a - b) - c[1,:] = period - abs(a - b) - d = na.amin(c, axis=0)**2 - return math.sqrt(d.sum()) - -def rotate_vector_3D(a, dim, angle): - r"""Rotates the elements of an array around an axis by some angle. - - Given an array of 3D vectors a, this rotates them around a coordinate axis - by a clockwise angle. An alternative way to think about it is the - coordinate axes are rotated counterclockwise, which changes the directions - of the vectors accordingly. - - Parameters - ---------- - a : array - An array of 3D vectors with dimension Nx3. - - dim : integer - A integer giving the axis around which the vectors will be rotated. - (x, y, z) = (0, 1, 2). - - angle : float - The angle in radians through which the vectors will be rotated - clockwise. - - Examples - -------- - >>> a = na.array([[1, 1, 0], [1, 0, 1], [0, 1, 1], [1, 1, 1], [3, 4, 5]]) - >>> b = rotate_vector_3D(a, 2, na.pi/2) - >>> print b - [[ 1.00000000e+00 -1.00000000e+00 0.00000000e+00] - [ 6.12323400e-17 -1.00000000e+00 1.00000000e+00] - [ 1.00000000e+00 6.12323400e-17 1.00000000e+00] - [ 1.00000000e+00 -1.00000000e+00 1.00000000e+00] - [ 4.00000000e+00 -3.00000000e+00 5.00000000e+00]] - - """ - mod = False - if len(a.shape) == 1: - mod = True - a = na.array([a]) - if a.shape[1] !=3: - raise SyntaxError("The second dimension of the array a must be == 3!") - if dim == 0: - R = na.array([[1, 0,0], - [0, na.cos(angle), na.sin(angle)], - [0, -na.sin(angle), na.cos(angle)]]) - elif dim == 1: - R = na.array([[na.cos(angle), 0, -na.sin(angle)], - [0, 1, 0], - [na.sin(angle), 0, na.cos(angle)]]) - elif dim == 2: - R = na.array([[na.cos(angle), na.sin(angle), 0], - [-na.sin(angle), na.cos(angle), 0], - [0, 0, 1]]) - else: - raise SyntaxError("dim must be 0, 1, or 2!") - if mod: - return na.dot(R, a.T).T[0] - else: - return na.dot(R, a.T).T - - -def modify_reference_frame(CoM, L, P, V): - r"""Rotates and translates data into a new reference frame to make - calculations easier. - - This is primarily useful for calculations of halo data. - The data is translated into the center of mass frame. - Next, it is rotated such that the angular momentum vector for the data - is aligned with the z-axis. Put another way, if one calculates the angular - momentum vector on the data that comes out of this function, it will - always be along the positive z-axis. - If the center of mass is re-calculated, it will be at the origin. - - Parameters - ---------- - CoM : array - The center of mass in 3D. - - L : array - The angular momentum vector. - - P : array - The positions of the data to be modified (i.e. particle or grid cell - postions). The array should be Nx3. - - V : array - The velocities of the data to be modified (i.e. particle or grid cell - velocities). The array should be Nx3. - - Returns - ------- - L : array - The angular momentum vector equal to [0, 0, 1] modulo machine error. - - P : array - The modified positional data. - - V : array - The modified velocity data. - - Examples - -------- - >>> CoM = na.array([0.5, 0.5, 0.5]) - >>> L = na.array([1, 0, 0]) - >>> P = na.array([[1, 0.5, 0.5], [0, 0.5, 0.5], [0.5, 0.5, 0.5], [0, 0, 0]]) - >>> V = p.copy() - >>> LL, PP, VV = modify_reference_frame(CoM, L, P, V) - >>> LL - array([ 6.12323400e-17, 0.00000000e+00, 1.00000000e+00]) - >>> PP - array([[ 3.06161700e-17, 0.00000000e+00, 5.00000000e-01], - [ -3.06161700e-17, 0.00000000e+00, -5.00000000e-01], - [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], - [ 5.00000000e-01, -5.00000000e-01, -5.00000000e-01]]) - >>> VV - array([[ -5.00000000e-01, 5.00000000e-01, 1.00000000e+00], - [ -5.00000000e-01, 5.00000000e-01, 3.06161700e-17], - [ -5.00000000e-01, 5.00000000e-01, 5.00000000e-01], - [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]]) - - """ - if (L == na.array([0, 0, 1.])).all(): - # Whew! Nothing to do! - return L, P, V - # First translate the positions to center of mass reference frame. - P = P - CoM - # Now find the angle between modified L and the x-axis. - LL = L.copy() - LL[2] = 0. - theta = na.arccos(na.inner(LL, [1.,0,0])/na.inner(LL,LL)**.5) - if L[1] < 0: - theta = -theta - # Now rotate all the position, velocity, and L vectors by this much around - # the z axis. - P = rotate_vector_3D(P, 2, theta) - V = rotate_vector_3D(V, 2, theta) - L = rotate_vector_3D(L, 2, theta) - # Now find the angle between L and the z-axis. - theta = na.arccos(na.inner(L, [0,0,1])/na.inner(L,L)**.5) - # This time we rotate around the y axis. - P = rotate_vector_3D(P, 1, theta) - V = rotate_vector_3D(V, 1, theta) - L = rotate_vector_3D(L, 1, theta) - return L, P, V - -def compute_rotational_velocity(CoM, L, P, V): - r"""Computes the rotational velocity for some data around an axis. - - This is primarily for halo computations. - Given some data, this computes the circular rotational velocity of each - point (particle) in reference to the axis defined by the angular momentum - vector. - This is accomplished by converting the reference frame of the center of - mass of the halo. - - Parameters - ---------- - CoM : array - The center of mass in 3D. - - L : array - The angular momentum vector. - - P : array - The positions of the data to be modified (i.e. particle or grid cell - postions). The array should be Nx3. - - V : array - The velocities of the data to be modified (i.e. particle or grid cell - velocities). The array should be Nx3. - - Returns - ------- - v : array - An array N elements long that gives the circular rotational velocity - for each datum (particle). - - Examples - -------- - >>> CoM = na.array([0, 0, 0]) - >>> L = na.array([0, 0, 1]) - >>> P = na.array([[1, 0, 0], [1, 1, 1], [0, 0, 1], [1, 1, 0]]) - >>> V = na.array([[0, 1, 10], [-1, -1, -1], [1, 1, 1], [1, -1, -1]]) - >>> circV = compute_rotational_velocity(CoM, L, P, V) - >>> circV - array([ 1. , 0. , 0. , 1.41421356]) - - """ - # First we translate into the simple coordinates. - L, P, V = modify_reference_frame(CoM, L, P, V) - # Find the vector in the plane of the galaxy for each position point - # that is perpendicular to the radial vector. - radperp = na.cross([0, 0, 1], P) - # Find the component of the velocity along the radperp vector. - # Unf., I don't think there's a better way to do this. - res = na.empty(V.shape[0], dtype='float64') - for i, rp in enumerate(radperp): - temp = na.dot(rp, V[i]) / na.dot(rp, rp) * rp - res[i] = na.dot(temp, temp)**0.5 - return res - -def compute_parallel_velocity(CoM, L, P, V): - r"""Computes the parallel velocity for some data around an axis. - - This is primarily for halo computations. - Given some data, this computes the velocity component along the angular - momentum vector. - This is accomplished by converting the reference frame of the center of - mass of the halo. - - Parameters - ---------- - CoM : array - The center of mass in 3D. - - L : array - The angular momentum vector. - - P : array - The positions of the data to be modified (i.e. particle or grid cell - postions). The array should be Nx3. - - V : array - The velocities of the data to be modified (i.e. particle or grid cell - velocities). The array should be Nx3. - - Returns - ------- - v : array - An array N elements long that gives the parallel velocity for - each datum (particle). - - Examples - -------- - >>> CoM = na.array([0, 0, 0]) - >>> L = na.array([0, 0, 1]) - >>> P = na.array([[1, 0, 0], [1, 1, 1], [0, 0, 1], [1, 1, 0]]) - >>> V = na.array([[0, 1, 10], [-1, -1, -1], [1, 1, 1], [1, -1, -1]]) - >>> paraV = compute_parallel_velocity(CoM, L, P, V) - >>> paraV - array([10, -1, 1, -1]) - - """ - # First we translate into the simple coordinates. - L, P, V = modify_reference_frame(CoM, L, P, V) - # And return just the z-axis velocities. - return V[:,2] - -def compute_radial_velocity(CoM, L, P, V): - r"""Computes the radial velocity for some data around an axis. - - This is primarily for halo computations. - Given some data, this computes the radial velocity component for the data. - This is accomplished by converting the reference frame of the center of - mass of the halo. - - Parameters - ---------- - CoM : array - The center of mass in 3D. - - L : array - The angular momentum vector. - - P : array - The positions of the data to be modified (i.e. particle or grid cell - postions). The array should be Nx3. - - V : array - The velocities of the data to be modified (i.e. particle or grid cell - velocities). The array should be Nx3. - - Returns - ------- - v : array - An array N elements long that gives the radial velocity for - each datum (particle). - - Examples - -------- - >>> CoM = na.array([0, 0, 0]) - >>> L = na.array([0, 0, 1]) - >>> P = na.array([[1, 0, 0], [1, 1, 1], [0, 0, 1], [1, 1, 0]]) - >>> V = na.array([[0, 1, 10], [-1, -1, -1], [1, 1, 1], [1, -1, -1]]) - >>> radV = compute_radial_velocity(CoM, L, P, V) - >>> radV - array([ 1. , 1.41421356 , 0. , 0.]) - - """ - # First we translate into the simple coordinates. - L, P, V = modify_reference_frame(CoM, L, P, V) - # We find the tangential velocity by dotting the velocity vector - # with the cylindrical radial vector for this point. - # Unf., I don't think there's a better way to do this. - P[:,2] = 0 - res = na.empty(V.shape[0], dtype='float64') - for i, rad in enumerate(P): - temp = na.dot(rad, V[i]) / na.dot(rad, rad) * rad - res[i] = na.dot(temp, temp)**0.5 - return res - -def compute_cylindrical_radius(CoM, L, P, V): - r"""Compute the radius for some data around an axis in cylindrical - coordinates. - - This is primarily for halo computations. - Given some data, this computes the cylindrical radius for each point. - This is accomplished by converting the reference frame of the center of - mass of the halo. - - Parameters - ---------- - CoM : array - The center of mass in 3D. - - L : array - The angular momentum vector. - - P : array - The positions of the data to be modified (i.e. particle or grid cell - postions). The array should be Nx3. - - V : array - The velocities of the data to be modified (i.e. particle or grid cell - velocities). The array should be Nx3. - - Returns - ------- - cyl_r : array - An array N elements long that gives the radial velocity for - each datum (particle). - - Examples - -------- - >>> CoM = na.array([0, 0, 0]) - >>> L = na.array([0, 0, 1]) - >>> P = na.array([[1, 0, 0], [1, 1, 1], [0, 0, 1], [1, 1, 0]]) - >>> V = na.array([[0, 1, 10], [-1, -1, -1], [1, 1, 1], [1, -1, -1]]) - >>> cyl_r = compute_cylindrical_radius(CoM, L, P, V) - >>> cyl_r - array([ 1. , 1.41421356, 0. , 1.41421356]) - """ - # First we translate into the simple coordinates. - L, P, V = modify_reference_frame(CoM, L, P, V) - # Demote all the positions to the z=0 plane, which makes the distance - # calculation very easy. - P[:,2] = 0 - return na.sqrt((P * P).sum(axis=1)) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/mods.py --- a/yt/mods.py Mon Aug 30 10:02:07 2010 -0700 +++ b/yt/mods.py Mon Aug 30 10:48:15 2010 -0700 @@ -24,68 +24,60 @@ along with this program. If not, see . """ +from __future__ import absolute_import + # # ALL IMPORTS GO HERE # # First module imports -import yt.lagos as lagos -import yt.raven as raven -import yt.fido as fido import numpy as na -# We do a bunch of standard imports import sys, types, os, glob, cPickle -from logger import ytLogger as mylog -from performance_counters import yt_counters, time_function -# Now individual component imports from lagos -from yt.lagos import \ - EnzoStaticOutput, OrionStaticOutput, TigerStaticOutput, \ - FLASHStaticOutput, \ +from yt.funcs import * +from yt.utilities.logger import ytLogger as mylog +from yt.utilities.performance_counters import yt_counters, time_function + +from yt.data_objects.api import \ BinnedProfile1D, BinnedProfile2D, BinnedProfile3D, \ - derived_field, \ - add_field, FieldInfo, EnzoFieldInfo, Enzo2DFieldInfo, OrionFieldInfo, \ - GadgetFieldInfo, TigerFieldInfo, ChomboFieldInfo, FLASHFieldInfo, \ - Clump, write_clump_hierarchy, find_clumps, write_clumps, \ - get_lowest_clumps, \ - HaloFinder, HOPHaloFinder, FOFHaloFinder, parallelHF, \ - axis_names, x_dict, y_dict, TwoPointFunctions, FcnSet + data_object_registry, \ + derived_field, add_field, FieldInfo, \ + ValidateParameter, ValidateDataField, ValidateProperty, \ + ValidateSpatial, ValidateGridType -# This is a temporary solution -- in the future, we will allow the user to -# select this via ytcfg. +from yt.frontends.enzo.api import \ + EnzoStaticOutput, EnzoStaticOutputInMemory, EnzoFieldInfo, \ + add_enzo_field, add_enzo_1d_field, add_enzo_2d_field -fieldInfo = EnzoFieldInfo +from yt.frontends.orion.api import \ + OrionStaticOutput, OrionFieldInfo, add_orion_field -# Now individual component imports from raven -from yt.raven import PlotCollection, PlotCollectionInteractive, \ - get_multi_plot, FixedResolutionBuffer, ObliqueFixedResolutionBuffer, \ - AnnuliProfiler -from yt.raven.Callbacks import callback_registry +from yt.frontends.flash.api import \ + FLASHStaticOutput, FLASHFieldInfo, add_flash_field + +from yt.frontends.tiger.api import \ + TigerStaticOutput, TigerFieldInfo, add_tiger_field + +from yt.frontends.ramses.api import \ + RAMSESStaticOutput, RAMSESFieldInfo, add_ramses_field + +from yt.frontends.chombo.api import \ + ChomboStaticOutput, ChomboFieldInfo, add_chombo_field + +# Import our analysis modules +#import yt.analysis_modules.api as analysis +from yt.analysis_modules.halo_finding.api import \ + HaloFinder + +from yt.utilities.definitions import \ + axis_names, x_dict, y_dict + +# Now individual component imports from the visualization API +from yt.visualization.api import \ + PlotCollection, PlotCollectionInteractive, \ + get_multi_plot, FixedResolutionBuffer, ObliqueFixedResolutionBuffer, \ + callback_registry for name, cls in callback_registry.items(): exec("%s = cls" % name) -# Optional component imports from raven -try: - from yt.raven import VolumeRenderingDataCube, \ - VolumeRendering3DProfile, HaloMassesPositionPlot -except ImportError: - pass - -import yt.raven.PlotInterface as plots - -# Individual imports from Fido -from yt.fido import GrabCollections, OutputCollection - -import yt.funcs - from yt.convenience import all_pfs, max_spheres, load, projload - -# Some convenience functions to ease our time running scripts -# from the command line - -def get_pf(): - return EnzoStaticOutput(sys.argv[-1]) - -def get_pc(): - return PlotCollection(EnzoStaticOutput(sys.argv[-1])) - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/parallel_tools/__init__.py --- a/yt/parallel_tools/__init__.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -""" -Tools for parallelism. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -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 . -""" - -from yt.lagos.ParallelTools import ParallelAnalysisInterface -from distributed_object_collection import DistributedObjectCollection diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/parallel_tools/distributed_object_collection.py --- a/yt/parallel_tools/distributed_object_collection.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -""" -A simple distributed object mechanism, for storing array-heavy objects. -Meant to be subclassed. - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -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 . -""" - -import numpy as na -from yt.funcs import * -from yt.parallel_tools import ParallelAnalysisInterface -from itertools import izip - -class DistributedObjectCollection(ParallelAnalysisInterface): - valid = True - - def _get_object_info(self): - pass - - def _set_object_info(self): - pass - - def join_lists(self): - info_dict = self._get_object_info() - info_dict = self._mpi_catdict(info_dict) - self._set_object_info(info_dict) - - def _collect_objects(self, desired_indices): - # We figure out which indices belong to which processor, - # then we pack them up, and we send a list to each processor. - request_count = [] - owners = self._object_owners[desired_indices] - mylog.debug("Owner list: %s", na.unique1d(owners)) - # Even if we have a million bricks, this should not take long. - s = self._mpi_get_size() - m = self._mpi_get_rank() - requests = dict( ( (i, []) for i in xrange(s) ) ) - for i, p in izip(desired_indices, owners): - requests[p].append(i) - for p in sorted(requests): - requests[p] = na.array(requests[p], dtype='int64') - request_count.append(len(requests[p])) - size = len(request_count) - mylog.debug("Requesting: %s", request_count) - request_count = na.array(request_count, dtype='int64') - # Now we distribute our requests to all the processors. - # This is two-pass. One to get the length of the arrays. The second - # pass is to get the actual indices themselves. - request_count = self._mpi_joindict({m : request_count}) - # Now we have our final array of requests, with arrangement - # (Nproc,Nproc). First index corresponds to requesting proc, second to - # sending. So [them,us] = 5 means we owe 5, whereas [us, them] means - # we are owed. - send_hooks = [] - dsend_buffers, dsend_hooks = [], [] - recv_hooks, recv_buffers = [], [] - drecv_buffers, drecv_hooks = [], [] - # We post our index-list and data receives from each processor. - mylog.debug("Posting data buffer receives") - proc_hooks = {} - for p, request_from in request_count.items(): - if p == m: continue - size = request_from[m] - #if size == 0: continue - # We post receives of the grids we *asked* for. - # Note that indices into this are not necessarily processor ids. - # So we store. This has to go before the appends or it's an - # off-by-one. - mylog.debug("Setting up index buffer of size %s for receive from %s", - size, p) - proc_hooks[len(drecv_buffers)] = p - drecv_buffers.append(self._create_buffer(requests[p])) - drecv_hooks.append(self._mpi_Irecv_double(drecv_buffers[-1], p, 1)) - recv_buffers.append(na.zeros(size, dtype='int64')) - # Our index list goes on 0, our buffer goes on 1. We know how big - # the index list will be, now. - recv_hooks.append(self._mpi_Irecv_long(recv_buffers[-1], p, 0)) - # Send our index lists into hte waiting buffers - mylog.debug("Sending index lists") - for p, ind_list in requests.items(): - if p == m: continue - if len(ind_list) == 0: continue - # Now, we actually send our index lists. - send_hooks.append(self._mpi_Isend_long(ind_list, p, 0)) - # Now we post receives for all of the data buffers. - mylog.debug("Sending data") - for i in self._mpi_Request_Waititer(recv_hooks): - # We get back the index, which here is identical to the processor - # number doing the send. At this point, we can post our receives. - p = proc_hooks[i] - mylog.debug("Processing from %s", p) - ind_list = recv_buffers[i] - dsend_buffers.append(self._create_buffer(ind_list)) - self._pack_buffer(ind_list, dsend_buffers[-1]) - dsend_hooks.append(self._mpi_Isend_double( - dsend_buffers[-1], p, 1)) - mylog.debug("Waiting on data receives: %s", len(drecv_hooks)) - for i in self._mpi_Request_Waititer(drecv_hooks): - mylog.debug("Unpacking from %s", proc_hooks[i]) - # Now we have to unpack our buffers - # Our key into this is actually the request for the processor - # number. - p = proc_hooks[i] - self._unpack_buffer(requests[p], drecv_buffers[i]) - mylog.debug("Finalizing sends: %s", len(dsend_hooks)) - for i in self._mpi_Request_Waititer(dsend_hooks): - continue - - def _create_buffer(self, ind_list): - pass - - def _pack_buffer(self, ind_list): - pass - - def _unpack_buffer(self, ind_list, my_buffer): - pass - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/performance_counters.py --- a/yt/performance_counters.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -""" -Minimalist performance counting for yt - -Author: Matthew Turk -Affiliation: KIPAC/SLAC/Stanford -Homepage: http://yt.enzotools.org/ -License: - Copyright (C) 2009 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 . -""" - -from yt.config import ytcfg -from yt.funcs import * -import time -from datetime import datetime as dt -from bisect import insort -import atexit - -class PerformanceCounters(object): - _shared_state = {} - def __new__(cls, *args, **kwargs): - self = object.__new__(cls, *args, **kwargs) - self.__dict__ = cls._shared_state - return self - - def __init__(self): - self.counters = defaultdict(lambda: 0.0) - self.counting = defaultdict(lambda: False) - self.starttime = defaultdict(lambda: 0) - self.endtime = defaultdict(lambda: 0) - self._on = ytcfg.getboolean("yt", "time_functions") - self.exit() - - def __call__(self, name): - if not self._on: return - if self.counting[name]: - self.counters[name] = time.time() - self.counters[name] - self.counting[name] = False - self.endtime[name] = dt.now() - else: - self.counters[name] = time.time() - self.counting[name] = True - self.starttime[name] = dt.now() - - def call_func(self, func): - if not self._on: return func - @wraps(func) - def func_wrapper(*args, **kwargs): - self(func.func_name) - func(*args, **kwargs) - self(func.func_name) - return func_wrapper - - def print_stats(self): - mylog.info("Current counter status:\n") - times = [] - for i in self.counters: - insort(times, [self.starttime[i], i, 1]) # 1 for 'on' - if not self.counting[i]: - insort(times, [self.endtime[i], i, 0]) # 0 for 'off' - shifts = {} - order = [] - endtimes = {} - shift = 0 - multi = 5 - for i in times: - # a starting entry - if i[2] == 1: - shifts[i[1]] = shift - order.append(i[1]) - shift += 1 - if i[2] == 0: - shift -= 1 - endtimes[i[1]] = self.counters[i[1]] - line = '' - for i in order: - if self.counting[i]: - line = "%s%s%i : %s : still running\n" % (line, " "*shifts[i]*multi, shifts[i], i) - else: - line = "%s%s%i : %s : %0.3e\n" % (line, " "*shifts[i]*multi, shifts[i], i, self.counters[i]) - mylog.info("\n" + line) - - def exit(self): - if self._on: - atexit.register(self.print_stats) - -yt_counters = PerformanceCounters() -time_function = yt_counters.call_func diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/physical_constants.py --- a/yt/physical_constants.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -# -# Physical Constants and Units Conversion Factors -# - -# Masses -mass_hydrogen_cgs = 1.67e-24 # g -mass_electron_cgs = 9.11e-28 # g -# Velocities -speed_of_light_cgs = 2.99792458e10 # cm/s, exact - -# Cross Sections -cross_section_thompson_cgs = 6.65e-25 # cm^2 - -# Physical Constants -boltzmann_constant_cgs = 1.3806504e-16 # erg K^-1 -gravitational_constant_cgs = 6.67428e-8 # cm^3 g^-1 s^-2 -planck_constant_cgs = 6.62606896e-27 # erg s -rho_crit_now = 1.8788e-29 # g times h^2 (critical mass for closure, Cosmology) - -# Misc. Approximations -mass_mean_atomic_cosmology = 1.22 -mass_mean_atomic_galactic = 2.3 - -# Conversion Factors: X au * mpc_per_au = Y au -# length -mpc_per_mpc = 1 -mpc_per_kpc = 1e-3 -mpc_per_pc = 1e-6 -mpc_per_au = 4.847e-12 -mpc_per_rsun = 2.253e-14 -mpc_per_miles = 5.216e-20 -mpc_per_cm = 3.24e-25 -km_per_pc = 1.3806504e13 -km_per_m = 1e-3 -km_per_cm = 1e-5 - -m_per_fpc = 0.0324077649 - -au_per_mpc = 2.063e11 -rsun_per_mpc = 4.43664e13 -miles_per_mpc = 1.917e19 -cm_per_mpc = 3.0857e24 -cm_per_km = 1e5 -pc_per_km = 3.24e-14 -pc_per_cm = 3.24e-19 -#Short cuts -G = gravitational_constant_cgs -me = mass_electron_cgs -mp = mass_hydrogen_cgs -clight = speed_of_light_cgs -kboltz = boltzmann_constant_cgs -hcgs = planck_constant_cgs -sigma_thompson = cross_section_thompson_cgs diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/progressbar.py --- a/yt/progressbar.py Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,368 +0,0 @@ -#!/usr/bin/python -# -*- coding: iso-8859-1 -*- -# -# progressbar - Text progressbar library for python. -# Copyright (c) 2005 Nilton Volpato -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -"""Text progressbar library for python. - -This library provides a text mode progressbar. This is tipically used -to display the progress of a long running operation, providing a -visual clue that processing is underway. - -The ProgressBar class manages the progress, and the format of the line -is given by a number of widgets. A widget is an object that may -display diferently depending on the state of the progress. There are -three types of widget: -- a string, which always shows itself; -- a ProgressBarWidget, which may return a diferent value every time -it's update method is called; and -- a ProgressBarWidgetHFill, which is like ProgressBarWidget, except it -expands to fill the remaining width of the line. - -The progressbar module is very easy to use, yet very powerful. And -automatically supports features like auto-resizing when available. -""" - -__author__ = "Nilton Volpato" -__author_email__ = "first-name dot last-name @ gmail.com" -__date__ = "2006-05-07" -__version__ = "2.2" - -# Changelog -# -# 2006-05-07: v2.2 fixed bug in windows -# 2005-12-04: v2.1 autodetect terminal width, added start method -# 2005-12-04: v2.0 everything is now a widget (wow!) -# 2005-12-03: v1.0 rewrite using widgets -# 2005-06-02: v0.5 rewrite -# 2004-??-??: v0.1 first version - - -import sys, time -from array import array -try: - from fcntl import ioctl - import termios -except ImportError: - pass -import signal - -class ProgressBarWidget(object): - """This is an element of ProgressBar formatting. - - The ProgressBar object will call it's update value when an update - is needed. It's size may change between call, but the results will - not be good if the size changes drastically and repeatedly. - """ - def update(self, pbar): - """Returns the string representing the widget. - - The parameter pbar is a reference to the calling ProgressBar, - where one can access attributes of the class for knowing how - the update must be made. - - At least this function must be overriden.""" - pass - -class ProgressBarWidgetHFill(object): - """This is a variable width element of ProgressBar formatting. - - The ProgressBar object will call it's update value, informing the - width this object must the made. This is like TeX \\hfill, it will - expand to fill the line. You can use more than one in the same - line, and they will all have the same width, and together will - fill the line. - """ - def update(self, pbar, width): - """Returns the string representing the widget. - - The parameter pbar is a reference to the calling ProgressBar, - where one can access attributes of the class for knowing how - the update must be made. The parameter width is the total - horizontal width the widget must have. - - At least this function must be overriden.""" - pass - - -class ETA(ProgressBarWidget): - "Widget for the Estimated Time of Arrival" - def format_time(self, seconds): - return time.strftime('%H:%M:%S', time.gmtime(seconds)) - def update(self, pbar): - if pbar.currval == 0: - return 'ETA: --:--:--' - elif pbar.finished: - return 'Time: %s' % self.format_time(pbar.seconds_elapsed) - else: - elapsed = pbar.seconds_elapsed - eta = elapsed * pbar.maxval / pbar.currval - elapsed - return 'ETA: %s' % self.format_time(eta) - -class FileTransferSpeed(ProgressBarWidget): - "Widget for showing the transfer speed (useful for file transfers)." - def __init__(self): - self.fmt = '%6.2f %s' - self.units = ['B','K','M','G','T','P'] - def update(self, pbar): - if pbar.seconds_elapsed < 2e-6:#== 0: - bps = 0.0 - else: - bps = float(pbar.currval) / pbar.seconds_elapsed - spd = bps - for u in self.units: - if spd < 1000: - break - spd /= 1000 - return self.fmt % (spd, u+'/s') - -class RotatingMarker(ProgressBarWidget): - "A rotating marker for filling the bar of progress." - def __init__(self, markers='|/-\\'): - self.markers = markers - self.curmark = -1 - def update(self, pbar): - if pbar.finished: - return self.markers[0] - self.curmark = (self.curmark + 1)%len(self.markers) - return self.markers[self.curmark] - -class Percentage(ProgressBarWidget): - "Just the percentage done." - def update(self, pbar): - return '%3d%%' % pbar.percentage() - -class Bar(ProgressBarWidgetHFill): - "The bar of progress. It will strech to fill the line." - def __init__(self, marker='#', left='|', right='|'): - self.marker = marker - self.left = left - self.right = right - def _format_marker(self, pbar): - if isinstance(self.marker, (str, unicode)): - return self.marker - else: - return self.marker.update(pbar) - def update(self, pbar, width): - percent = pbar.percentage() - cwidth = width - len(self.left) - len(self.right) - marked_width = int(percent * cwidth / 100) - m = self._format_marker(pbar) - bar = (self.left + (m*marked_width).ljust(cwidth) + self.right) - return bar - -class ReverseBar(Bar): - "The reverse bar of progress, or bar of regress. :)" - def update(self, pbar, width): - percent = pbar.percentage() - cwidth = width - len(self.left) - len(self.right) - marked_width = int(percent * cwidth / 100) - m = self._format_marker(pbar) - bar = (self.left + (m*marked_width).rjust(cwidth) + self.right) - return bar - -default_widgets = [Percentage(), ' ', Bar()] -class ProgressBar(object): - """This is the ProgressBar class, it updates and prints the bar. - - The term_width parameter may be an integer. Or None, in which case - it will try to guess it, if it fails it will default to 80 columns. - - The simple use is like this: - >>> pbar = ProgressBar().start() - >>> for i in xrange(100): - ... # do something - ... pbar.update(i+1) - ... - >>> pbar.finish() - - But anything you want to do is possible (well, almost anything). - You can supply different widgets of any type in any order. And you - can even write your own widgets! There are many widgets already - shipped and you should experiment with them. - - When implementing a widget update method you may access any - attribute or function of the ProgressBar object calling the - widget's update method. The most important attributes you would - like to access are: - - currval: current value of the progress, 0 <= currval <= maxval - - maxval: maximum (and final) value of the progress - - finished: True if the bar is have finished (reached 100%), False o/w - - start_time: first time update() method of ProgressBar was called - - seconds_elapsed: seconds elapsed since start_time - - percentage(): percentage of the progress (this is a method) - """ - def __init__(self, maxval=100, widgets=default_widgets, term_width=None, - fd=sys.stderr): - assert maxval > 0 - self.maxval = maxval - self.widgets = widgets - self.fd = fd - self.signal_set = False - if term_width is None: - try: - self.handle_resize(None,None) - signal.signal(signal.SIGWINCH, self.handle_resize) - self.signal_set = True - except: - self.term_width = 79 - else: - self.term_width = term_width - - self.currval = 0 - self.finished = False - self.prev_percentage = -1 - self.start_time = None - self.seconds_elapsed = 0 - - def handle_resize(self, signum, frame): - h,w=array('h', ioctl(self.fd,termios.TIOCGWINSZ,'\0'*8))[:2] - self.term_width = w - - def percentage(self): - "Returns the percentage of the progress." - return self.currval*100.0 / self.maxval - - def _format_widgets(self): - r = [] - hfill_inds = [] - num_hfill = 0 - currwidth = 0 - for i, w in enumerate(self.widgets): - if isinstance(w, ProgressBarWidgetHFill): - r.append(w) - hfill_inds.append(i) - num_hfill += 1 - elif isinstance(w, (str, unicode)): - r.append(w) - currwidth += len(w) - else: - weval = w.update(self) - currwidth += len(weval) - r.append(weval) - for iw in hfill_inds: - r[iw] = r[iw].update(self, (self.term_width-currwidth)/num_hfill) - return r - - def _format_line(self): - return ''.join(self._format_widgets()).ljust(self.term_width) - - def _need_update(self): - return int(self.percentage()) != int(self.prev_percentage) - - def update(self, value): - "Updates the progress bar to a new value." - assert 0 <= value <= self.maxval - self.currval = value - if not self._need_update() or self.finished: - return - if not self.start_time: - self.start_time = time.time() - self.seconds_elapsed = time.time() - self.start_time - self.prev_percentage = self.percentage() - if value != self.maxval: - self.fd.write(self._format_line() + '\r') - else: - self.finished = True - self.fd.write(self._format_line() + '\n') - - def start(self): - """Start measuring time, and prints the bar at 0%. - - It returns self so you can use it like this: - >>> pbar = ProgressBar().start() - >>> for i in xrange(100): - ... # do something - ... pbar.update(i+1) - ... - >>> pbar.finish() - """ - self.update(0) - return self - - def finish(self): - """Used to tell the progress is finished.""" - self.update(self.maxval) - if self.signal_set: - signal.signal(signal.SIGWINCH, signal.SIG_DFL) - - - - - - -if __name__=='__main__': - import os - - def example1(): - widgets = ['Test: ', Percentage(), ' ', Bar(marker=RotatingMarker()), - ' ', ETA(), ' ', FileTransferSpeed()] - pbar = ProgressBar(widgets=widgets, maxval=10000000).start() - for i in range(1000000): - # do something - pbar.update(10*i+1) - pbar.finish() - print - - def example2(): - class CrazyFileTransferSpeed(FileTransferSpeed): - "It's bigger between 45 and 80 percent" - def update(self, pbar): - if 45 < pbar.percentage() < 80: - return 'Bigger Now ' + FileTransferSpeed.update(self,pbar) - else: - return FileTransferSpeed.update(self,pbar) - - widgets = [CrazyFileTransferSpeed(),' <<<', Bar(), '>>> ', Percentage(),' ', ETA()] - pbar = ProgressBar(widgets=widgets, maxval=10000000) - # maybe do something - pbar.start() - for i in range(2000000): - # do something - pbar.update(5*i+1) - pbar.finish() - print - - def example3(): - widgets = [Bar('>'), ' ', ETA(), ' ', ReverseBar('<')] - pbar = ProgressBar(widgets=widgets, maxval=10000000).start() - for i in range(1000000): - # do something - pbar.update(10*i+1) - pbar.finish() - print - - def example4(): - widgets = ['Test: ', Percentage(), ' ', - Bar(marker='0',left='[',right=']'), - ' ', ETA(), ' ', FileTransferSpeed()] - pbar = ProgressBar(widgets=widgets, maxval=500) - pbar.start() - for i in range(100,500+1,50): - time.sleep(0.2) - pbar.update(i) - pbar.finish() - print - - - example1() - example2() - example3() - example4() - diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/FortranUnformatted_IO.hh --- a/yt/ramses_headers/FortranUnformatted_IO.hh Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +0,0 @@ -/* - FortranUnformatted_IO.hh - This file contains a C++ class for access to FORTRAN unformatted files - - Copyright (C) 2008 Oliver Hahn, ojha@gmx.de - - It 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. - - Foobar 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 Foobar. If not, see . -*/ - -#ifndef __FORTRAN_UNFORMATTED_HH -#define __FORTRAN_UNFORMATTED_HH - -#include -#include -#include -#include -#include -#include - -#define DEFAULT_ADDLEN 4 - -//! A class to perform IO on FORTRAN unformatted files -/*! FortranUnformatted provides sequential read access to FORTRAN - unformatted files. - */ -class FortranUnformatted{ - -protected: - std::string m_filename; //!< the file name - std::fstream m_ifs; //!< STL ifstream object - int m_addlen; //!< number of bytes in pre-/suffix data of FORTRAN unformatted data - -public: - - //! constructor for FortranUnformatted - /*! simple constructor for FortranUnformatted - * @param filename the name of the FORTRAN unformatted file to be opened for IO - * @param mode a combination of std::ios_base::openmode determining the mode in which the files are openend - * @param addlen the number of bytes which are pre- & postpended to unformatted arrays giving their size (default=4) - */ - explicit FortranUnformatted( std::string filename, std::ios_base::openmode mode = std::ios_base::in, int addlen=DEFAULT_ADDLEN ) - : m_filename( filename ), - m_ifs( m_filename.c_str(), mode|std::ios::binary ), - m_addlen( addlen ) - { - if(!m_ifs.good() || !m_ifs.is_open() ) - throw std::runtime_error("FortranUnformatted : unable to open file \'" - +m_filename+"\'for read access"); - m_ifs.exceptions ( std::fstream::eofbit | std::fstream::failbit - | std::fstream::badbit ); - } - - //! read data from FORTRAN unformatted file - /*! read a scalar from FORTRAN unformatted file. If the data is not scalar - (i.e. an array) or the function is called with a template parameter of - a different size than the stored data, a std::runtime_error is thrown. - \param r reference to the return value - */ - template< typename T > void read( T& r ) - { - unsigned n1,n2; - - try{ - m_ifs.read( (char*)&n1, m_addlen ); - m_ifs.read( (char*)&r, sizeof(T) ); - m_ifs.read( (char*)&n2, m_addlen ); - }catch(...){ - throw; - } - - if( n1 != sizeof(T) || n1 != n2 ){ - throw std::runtime_error("FortranUnformatted::read : invalid type"\ - " conversion when reading FORTRAN unformatted."); - } - } - - //! write a single variable, arbitrary type to the Fortran unformatted file - /*! - * @param w the variable, arbitrary type - */ - template< typename T > void write( T& w ) - { - unsigned n1 = sizeof(T); - - try{ - m_ifs.write( (char*)&n1, m_addlen ); - m_ifs.write( (char*)&w, n1 ); - m_ifs.write( (char*)&n1, m_addlen ); - }catch(...){ - throw; - } - } - - - //! write a range of a container data object given by iterators - /*! - * @param begin iterator pointing to the beginning of the range - * @param end iterator pointing to the end of the range - */ - template< typename _InputIterator > - void write( _InputIterator begin, _InputIterator end ) - { - _InputIterator it(begin); - unsigned nelem = std::distance(begin,end); - unsigned sz = sizeof(*begin); - unsigned totsz = sz*nelem; - - try{ - m_ifs.write( (char*)&totsz, m_addlen ); - while( it!=end ){ - m_ifs.write( (char*)&(*it), sz ); - ++it; - } - m_ifs.write( (char*)&totsz, m_addlen ); - }catch(...){ - throw; - } - } - - //! read masked data - /*! this function reads data but discards all those for which the iterator - * mask is not set to a 'true' bit. It is necessary that the mask iterator - * can be increased the same number of times as there is data to be read. - * @param mask an iterator which is increased for each element read from the file and determines rejection or not - * @param data an output iterator to which the data is written - */ - template< typename basetype, typename _InputIterator, typename _OutputIterator > - _InputIterator read( _InputIterator mask, _OutputIterator data ) - { - _InputIterator oldmask = mask; - std::vector temp; - typename std::vector::iterator temp_it; - - unsigned n1,n2; - try{ - m_ifs.read( (char*)&n1, m_addlen ); - temp.resize(n1/sizeof(basetype)); - m_ifs.read( (char*)&temp[0], n1 ); - - for( temp_it = temp.begin(); temp_it!=temp.end(); ++temp_it ){ - //... copy data if masked - this also performs a type conversion if needed ...// - if( *mask ) - *data = *temp_it; - oldmask = mask++; - if( mask == oldmask ) break; - } - //std::copy(temp.begin(),temp.end(), data); - - m_ifs.read( (char*)&n2, m_addlen ); - - }catch(...){ - throw std::runtime_error("FortranUnformatted::read : error reading FORTRAN unformatted."); - } - if( n1!=n2 ) - throw std::runtime_error("FortranUnformatted::read : invalid type conversion when"\ - " reading FORTRAN unformatted."); - - return mask; - } - - - //! read data - /*! this function reads data from a Fortran unformatted file and writes it to - * an output iterator. - * @param data an output iterator to which the data is written - */ - template< typename basetype, typename _OutputIterator > - _OutputIterator read( _OutputIterator data ) - { - std::vector temp; - typename std::vector temp_it; - - unsigned n1,n2; - try{ - m_ifs.read( (char*)&n1, m_addlen ); - temp.resize(n1/sizeof(basetype)); - m_ifs.read( (char*)&temp[0], n1 ); - //... copy data - this also performs a type conversion if needed ...// - std::copy(temp.begin(),temp.end(), data); - m_ifs.read( (char*)&n2, m_addlen ); - - }catch(...){ - throw std::runtime_error("FortranUnformatted::read : error reading FORTRAN unformatted."); - } - if( n1!=n2 ) - throw std::runtime_error("FortranUnformatted::read : invalid type conversion when"\ - " reading FORTRAN unformatted."); - - - return data; - } - - //! check if beyond end-of-file - bool eof( void ) - { - bool bcheck; - try{ - bcheck = (m_ifs.peek()==EOF); - }catch(...){ - m_ifs.clear(); - return true; - } - return bcheck; - } - - //! skip ahead in FORTRAN unformatted file - /*! skips n datasets ahead in FORTRAN unformatted file. Equivalent to - * n READ(X) without argument in FORTRAN - * @param n number of entries to skip ahead (scalar or arrays) - */ - void skip_n( unsigned n ) - { - unsigned ndone = 0; - while( ndone < n ){ - int n1, n2; - try{ - m_ifs.read( (char*)&n1, m_addlen ); - m_ifs.seekg( n1, std::ios::cur ); - m_ifs.read( (char*)&n2, m_addlen ); - }catch(...){ - throw std::runtime_error("FortranUnformatted::skip_n : error seeking in FORTRAN unformatted file."); - } - ++ndone; - } - } - - //! just a std::streampos - typedef std::streampos streampos; - - //! wrapper for the std::ifstream::tellg() function - streampos tellg( void ) - { return m_ifs.tellg(); } - - //! wrapper for the std::ifstream::seekg() function - void seekg( streampos pos ) - { m_ifs.seekg( pos ); /*, std::ios::beg );*/ } - - - //! jump to dataset in FORTRAN unformatted files - /*! moves past the nth WRITE(X) operation from the beginning in a FORTRAN - * unformatted file - * @param n number of entries to skip (scalar or arrays) - * @sa skip_n() - */ - void skip_n_from_start( unsigned n ) - { - m_ifs.seekg(0,std::ios::beg); - skip_n( n ); - } - - //! skip ahead in FORTRAN unformatted file - /*! skips to next dataset in FORTRAN unformatted file. Equivalent to a - * READ(X) without argument in FORTRAN - * @sa skip_n - */ - void skip( void ) - { - skip_n(1); - } - - //! rewind file - /*! rewinds the file to the beginning - */ - void rewind( void ) - { - m_ifs.seekg(0,std::ios::beg); - } - - - - /*template< typename T > - friend FortranUnformatted& operator>> (FortranUnformatted &is, T& data); - - template< typename T > - friend FortranUnformatted& operator>> (FortranUnformatted &is, std::vector& data);*/ -}; - - - -#endif //__FORTRAN_UNFORMATTED_HH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/RAMSES_amr_data.hh --- a/yt/ramses_headers/RAMSES_amr_data.hh Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,970 +0,0 @@ -/* - This file is part of libRAMSES++ - a C++ library to access snapshot files - generated by the simulation code RAMSES by R. Teyssier - - Copyright (C) 2008-09 Oliver Hahn, ojha@gmx.de - - This program 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 . -*/ - -#ifndef __RAMSES_AMR_DATA_HH -#define __RAMSES_AMR_DATA_HH - -#include -#include -#include -#include -#include -#include -#include - -#include "FortranUnformatted_IO.hh" -#include "RAMSES_info.hh" -#include "RAMSES_amr_data.hh" - -#ifndef FIX -#define FIX(x) ((int)((x)+0.5)) -#endif - -#define ACC_NL(cpu,lvl) ((cpu)+m_header.ncpu*(lvl)) -#define ACC_NLIT(cpu,lvl) ((cpu)+m_plevel->m_header.ncpu*(lvl)) -#define ACC_NB(cpu,lvl) ((cpu)+m_header.nboundary*(lvl)) - -#define LENGTH_POINTERLISTS 4096 -#define ENDPOINT ((unsigned)(-1)) - -namespace RAMSES{ -namespace AMR{ - -/**************************************************************************************\ - *** auxiliary datatypes ************************************************************** -\**************************************************************************************/ - -template< typename real_t> -struct vec{ - real_t x,y,z; - - vec( real_t x_, real_t y_, real_t z_ ) - : x(x_),y(y_),z(z_) - { } - - vec( const vec& v ) - : x(v.x),y(v.y),z(v.z) - { } - - vec( void ) - : x(0.0), y(0.0), z(0.0) - { } -}; - -/**************************************************************************************\ - *** AMR cell base types ************************************************************** -\**************************************************************************************/ - -template -class cell_locally_essential{ -public: - id_t m_neighbour[6]; - id_t m_father; - id_t m_son[8]; - real_t m_xg[3]; - id_t m_cpu; - - char m_pos; - - cell_locally_essential(){} - - bool is_refined( int ison ) const - { return ((int)m_son[ison]!=-1); } -}; - -template -class cell_simple{ -public: - id_t m_son[1]; - real_t m_xg[3]; - id_t m_cpu; - - char m_pos; - - cell_simple(){} - - bool is_refined( int ison=0 ) const - { return ((int)m_son[0]!=-1); } -}; - - -//.... some type traits that are used to distinguish what data needs to be read ....// -template struct is_locally_essential -{ enum { check=false }; }; - -template<> struct is_locally_essential > -{ enum { check=true }; }; - -template<> struct is_locally_essential > -{ enum { check=false }; }; - - -/**************************************************************************************\ - *** AMR level class definition, subsumes a collection of AMR cells ******************* -\**************************************************************************************/ - -//! AMR level implementation -template< typename Cell_ > -class level{ -public: - unsigned m_ilevel; - std::vector< Cell_ > m_level_cells; - - double m_xc[8]; //!< relative x-offsets of the 8 children for current refinement level - double m_yc[8]; //!< relative y-offsets of the 8 children for current refinement level - double m_zc[8]; //!< relative z-offsets of the 8 children for current refinement level - - typedef typename std::vector< Cell_ >::iterator iterator; - typedef typename std::vector< Cell_ >::const_iterator const_iterator; - - double m_dx; - unsigned m_nx; - - level( unsigned ilevel ) - : m_ilevel( ilevel ) - { - m_dx = pow(0.5,ilevel+1); - m_nx = (unsigned)(1.0/m_dx); - - for( unsigned k=1; k<=8; k++ ) - { - //... initialize positions of son cell centres - //... relative to parent cell centre - unsigned - iz=(k-1)/4, - iy=(k-1-4*iz)/2, - ix=(k-1-2*iy-4*iz); - m_xc[k-1]=((double)ix-0.5f)*m_dx; - m_yc[k-1]=((double)iy-0.5f)*m_dx; - m_zc[k-1]=((double)iz-0.5f)*m_dx; - } - } - - void register_cell( const Cell_ & cell ) - { m_level_cells.push_back( cell ); } - - const_iterator begin( void ) const{ return m_level_cells.begin(); } - iterator begin( void ){ return m_level_cells.begin(); } - - const_iterator end( void ) const{ return m_level_cells.end(); } - iterator end( void ){ return m_level_cells.end(); } - - Cell_& operator[]( unsigned i ) - { return m_level_cells[i]; } - - unsigned size( void ) { return m_level_cells.size(); } -}; - - -/**************************************************************************************\ - *** constants ************************************************************************ -\**************************************************************************************/ - -//! neighbour cell access pattern -const static int nbor_cell_map[6][8] = -{ - {1,0,3,2,5,4,7,6}, - {1,0,3,2,5,4,7,6}, - {2,3,0,1,6,7,4,5}, - {2,3,0,1,6,7,4,5}, - {4,5,6,7,0,1,2,3}, - {4,5,6,7,0,1,2,3} -}; - - -/**************************************************************************************\ - *** AMR tree class implements the hierarchy of AMR levels with links ***************** -\**************************************************************************************/ - -/*! - * @class tree - * @brief encapsulates the hierarchical AMR structure data from a RAMSES simulation snapshot - * - * This class provides low-level read access to RAMSES amr_XXXXX.out files. - * Data from a given list of computational domains can be read and is - * stored in internal datastructures. - * Access to hydrodynamical variables stored in the cells is provided - * through member functions of class RAMSES_hydro_level and iterators - * provided by this class - * @sa RAMSES_hydro_level - */ -template< class Cell_, class Level_ > -class tree -{ - -public: - - //! header amr meta-data structure, for details see also RAMSES source code (file amr/init_amr.f90) - struct header{ - std::vector< int > nx; //!< base mesh resolution [3-vector] - std::vector< int > nout; //!< 3 element vector: [noutput2, iout2, ifout2] - std::vector< int > nsteps; //!< 2 element vector: [nstep, nstep_coarse] - int ncpu; //!< number of CPUs (=computational domains) in the simulation - int ndim; //!< number of spatial dimensions - int nlevelmax; //!< maximum refinement level allowed - int ngridmax; //!< maxmium number of grid cells stored per CPU - int nboundary; //!< number of boundary cells (=ghost cells) - int ngrid_current; //!< currently active grid cells - double boxlen; //!< length of the simulation box - std::vector tout; //!< output times (1..noutput) - std::vector aout; //!< output times given as expansion factors (1..noutput) - std::vector dtold; //!< old time steps (1..nlevelmax) - std::vector dtnew; //!< next time steps (1..nlevelmax) - std::vector stat; //!< some diagnostic snapshot meta data: [const, mass_tot0, rho_tot] - std::vector cosm; //!< cosmological meta data: [omega_m, omega_l, omega_k, omega_b, h0, aexp_ini, boxlen_ini) - std::vector timing; //!< timing information: [aexp, hexp, aexp_old, epot_tot_int, epot_tot_old] - double t; //!< time stamp of snapshot - double mass_sph; //!< mass threshold used to flag for cell refinement - }; - - std::vector< Level_ > m_AMR_levels; //! STL vector holding the AMR level hierarchy - - std::vector - m_headl, //!< head indices, point to first active cell - m_numbl, //!< number of active cells - m_taill; //!< tail indices, point to last active cell - - int m_cpu; //! index of computational domain being accessed - int m_minlevel; //! lowest refinement level to be loaded - int m_maxlevel; //! highest refinement level to be loaded - std::string m_fname; //! the snapshot filename amr_XXXXX.out - unsigned m_ncoarse; //! number of coarse grids - struct header m_header; //! the header meta data - - -protected: - - //! prototypical grid iterator - /*! iterates through cells on one level, provides access to neighbours, parents, children - */ - template< typename TreePointer_, typename Index_=unsigned > - class proto_iterator{ - public: - - friend class tree; - - typedef Index_ value_type; - typedef Index_& reference; - typedef Index_* pointer; - - protected: - - Index_ - m_ilevel, //!< refinement level on which we iteratre - m_icpu; //!< domain on which we iterate - - typedef typename std::vector< Cell_ >::const_iterator Iterator_; - Iterator_ m_cell_it; //!< basis iterator that steps through cells on one level - TreePointer_ m_ptree; //!< pointer to associated tree object - - - //! low_level construtor that should only be used from within AMR_tree - proto_iterator( unsigned level_, unsigned cpu_, Iterator_ it_, TreePointer_ ptree_ ) - : m_ilevel(level_), m_icpu(cpu_), m_cell_it(it_), m_ptree( ptree_ ) - { } - - public: - - //! this is either the copy-constructor or a constructor for implicit type conversion - template< typename X > - proto_iterator( proto_iterator &it ) - : m_ilevel( it.m_ilevel ), m_icpu( it.m_icpu ), m_cell_it( it.m_cell_it ), m_ptree( it.m_ptree ) - { } - - //! empty constructor, doesn't initialize anything - proto_iterator() - : m_ilevel(0), m_icpu(0), m_ptree(NULL) - { } - - //! test for equality between two proto_iterator instantiations - template< typename X > - inline bool operator==( const proto_iterator& x ) const - { return m_cell_it==x.m_cell_it; } - - //! test for inequality between two proto_iterator instantiations - template< typename X > - inline bool operator!=( const proto_iterator& x ) const - { return m_cell_it!=x.m_cell_it; } - - //! iterate forward, prefix - inline proto_iterator& operator++() - { ++m_cell_it; return *this; } - - //! iterate forward, postfix - inline proto_iterator operator++(int) - { proto_iterator it(*this); operator++(); return it; } - - inline void next(void) { operator++(); } - - //! iterate backward, prefix - inline proto_iterator& operator--() - { --m_cell_it; return *this; } - - //! iterate backward, postfix - inline proto_iterator operator--(int) - { proto_iterator it(*this); operator--(); return it; } - - //! iterate several forward - inline proto_iterator operator+=(int i) - { proto_iterator it(*this); m_cell_it+=i; return it; } - - //! iterate several backward - inline proto_iterator operator-=(int i) - { proto_iterator it(*this); m_cell_it-=i; return it; } - - //! assign two proto_iterators, this will fail if no typecast between X and TreePoint_ exists - template< typename X > - inline proto_iterator& operator=(const proto_iterator& x) - { m_cell_it = x.m_cell_it; m_ilevel = x.m_ilevel; m_icpu = x.m_icpu; m_ptree = x.m_ptree; return *this; } - - //! iterator dereferencing, returns an array index - inline Cell_ operator*() const - { return *m_cell_it; } - - inline Index_ get_cell_father() const { return (*m_cell_it).m_father; } - inline bool is_finest(int ison) { return !((*m_cell_it).is_refined(ison)); } - - //! move iterator to a child grid - /*! - * @param ind index of the child grid in the parent oct (0..7) - * @return iterator pointing to child grid if it exists, otherwise 'end' of currrent level - */ - //template< typename X > - inline proto_iterator& to_child( int ind ) - { - if( !(*m_cell_it).is_refined(ind) ) - return (*this = m_ptree->end( m_ilevel )); - ++m_ilevel; - m_cell_it = m_ptree->m_AMR_levels[m_ilevel].begin()+(*m_cell_it).m_son[ind]; - return *this; - } - - - //! get an iterator to a child grid - /*! - * @param ind index of the child grid in the parent oct (0..7) - * @return iterator pointing to child grid if it exists, otherwise 'end' of currrent level - */ - //template< typename X > - inline proto_iterator get_child( int ind ) const - { - proto_iterator it(*this); - it.to_child( ind ); - return it; - } - - inline char get_child_from_pos( double x, double y, double z ) const - { - bool bx,by,bz; - bx = x > (*m_cell_it).m_xg[0]; - by = y > (*m_cell_it).m_xg[1]; - bz = z > (*m_cell_it).m_xg[2]; - - //std::cerr << "(" << bx << ", " << by << ", " << bz << ")\n"; - - return (char)bx+2*((char)by+2*(char)bz); - } - - - //! move iterator to the parent grid - /*! - * @return iterator pointing to the parent grid if it exists, 'end' of the current level otherwise - */ - - inline proto_iterator& to_parent( void ) - { - if( m_ilevel==0 ) - return (*this = m_ptree->end( m_ilevel )); - --m_ilevel; - m_cell_it = m_ptree->m_AMR_levels[m_ilevel].begin()+(*m_cell_it).m_father; - return *this; - } - - //! query whether a given child cell is refined - inline bool is_refined( int i ) const - { - return (*m_cell_it).is_refined(i); - } - - //! get an iterator to the parent grid - /*! - * @return iterator pointing to the parent grid if it exists, 'end' of the current level otherwise - */ - inline proto_iterator get_parent( void ) const - { - proto_iterator it(*this); - it.to_parent(); - return it; - } - - //! move iterator to spatial neighbour grid - /*! - * @param ind index of neighbour (0..5) - * @return iterator pointing to neighbour grid if it exists, otherwise 'end' of currrent level - */ - inline proto_iterator& to_neighbour( int ind ) - { - unsigned icell = nbor_cell_map[ind][(int)(*m_cell_it).m_pos]; - m_cell_it = m_ptree->m_AMR_levels[m_ilevel-1].begin()+(*m_cell_it).m_neighbour[ind]; - - if( !(*m_cell_it).is_refined(icell) ) - return (*this = m_ptree->end(m_ilevel)); - - m_cell_it = m_ptree->m_AMR_levels[m_ilevel].begin()+(*m_cell_it).m_son[icell]; - return *this; - } - - //! get an iterator to spatial neighbour grid - /*! - * @param ind index of neighbour (0..5) - * @return iterator pointing to neighbour grid if it exists, otherwise 'end' of currrent level - */ - inline proto_iterator& get_neighbour( int ind ) - { - proto_iterator it(*this); - it.to_neighbour(ind); - return it; - } - - inline Index_ get_level( void ) const - { return m_ilevel; } - - inline int get_domain( void ) const - { return (*m_cell_it).m_cpu; } - - inline int get_absolute_position( void ) const - { - return (unsigned)(std::distance(m_ptree->m_AMR_levels[m_ilevel].begin(),m_cell_it)); - } - - - }; - -public: - - typedef proto_iterator const_iterator; - typedef proto_iterator iterator; - - - -protected: - - //! read header meta data from amr snapshot file - void read_header( void ); - - - - //! generate the amr_XXXXX.out filename for a given computational domain - /*! @param icpu index of comutational domain (base 1) - */ - std::string gen_fname( int icpu ); - - //! generate the amr_XXXXX.out filename from the path to the info_XXXXX.out file - std::string rename_info2amr( const std::string& info ); - - - #define R_SQR(x) ((x)*(x)) - - template< typename Real_ > - inline bool ball_intersection( const vec& xg, double dx2, const vec& xc, Real_ r2 ) - { - Real_ dmin = 0, bmin, bmax; - - //.. x ..// - bmin = xg.x-dx2; - bmax = xg.x+dx2; - if( xc.x < bmin ) dmin += R_SQR(xc.x - bmin ); else - if( xc.x > bmax ) dmin += R_SQR(xc.x - bmax ); - - //.. y ..// - bmin = xg.y-dx2; - bmax = xg.y+dx2; - if( xc.y < bmin ) dmin += R_SQR(xc.y - bmin ); else - if( xc.y > bmax ) dmin += R_SQR(xc.y - bmax ); - - //.. x ..// - bmin = xg.z-dx2; - bmax = xg.z+dx2; - if( xc.z < bmin ) dmin += R_SQR(xc.z - bmin ); else - if( xc.z > bmax ) dmin += R_SQR(xc.z - bmax ); - - if( dmin <= r2 ) return true; - return false; - } - - template< typename Real_ > - inline bool shell_intersection( const vec& xg, double dx2, const vec& xc, Real_ r1_2, Real_ r2_2 ) - { - Real_ dmax = 0, dmin = 0, a, b, bmin, bmax; - if( r1_2 > r2_2 ) std::swap(r1_2,r2_2); - - //.. x ..// - bmin = xg.x-dx2; - bmax = xg.x+dx2; - a = R_SQR( xc.x - bmin ); - b = R_SQR( xc.x - bmax ); - dmax += std::max( a, b ); - if( xc.x < bmin ) dmin += a; else - if( xc.x > bmax ) dmin += b; - - //.. y ..// - bmin = xg.y-dx2; - bmax = xg.y+dx2; - a = R_SQR( xc.y - bmin ); - b = R_SQR( xc.y - bmax ); - dmax += std::max( a, b ); - if( xc.y < bmin ) dmin += a; else - if( xc.y > bmax ) dmin += b; - - //.. z ..// - bmin = xg.z-dx2; - bmax = xg.z+dx2; - a = R_SQR( xc.z - bmin ); - b = R_SQR( xc.z - bmax ); - dmax += std::max( a, b ); - if( xc.z < bmin ) dmin += a; else - if( xc.z > bmax ) dmin += b; - - - if( dmin <= r2_2 && r1_2 <= dmax ) return true; - return false; - } - - template< typename Real_ > - inline bool sphere_intersection( const vec& xg, double dx2, const vec& xc, Real_ r2 ) - { - Real_ dmax = 0, dmin = 0, a, b, bmin, bmax; - - //.. x ..// - bmin = xg.x-dx2; - bmax = xg.x+dx2; - a = R_SQR( xc.x - bmin ); - b = R_SQR( xc.x - bmax ); - dmax += std::max( a, b ); - if( xc.x < bmin ) dmin += a; else - if( xc.x > bmax ) dmin += b; - - //.. y ..// - bmin = xg.y-dx2; - bmax = xg.y+dx2; - a = R_SQR( xc.y - bmin ); - b = R_SQR( xc.y - bmax ); - dmax += std::max( a, b ); - if( xc.y < bmin ) dmin += a; else - if( xc.y > bmax ) dmin += b; - - //.. z ..// - bmin = xg.z-dx2; - bmax = xg.z+dx2; - a = R_SQR( xc.z - bmin ); - b = R_SQR( xc.z - bmax ); - dmax += std::max( a, b ); - if( xc.z < bmin ) dmin += a; else - if( xc.z > bmax ) dmin += b; - - - if( dmin <= r2 && r2 <= dmax ) return true; - return false; - } - - #undef R_SQR - -public: - - //! low-level constructor - should not be called from outside because then you can really screw up things - /*! - * @param snap the associated RAMSES::snapshot object - * @param cpu domain for which to read the AMR tree - * @param maxlevel maximum refinement level to consider - * @param minlevel minimum refinement level to consider (default=1) - */ - tree( RAMSES::snapshot& snap, int cpu, int maxlevel, int minlevel=1 ) - : m_cpu( cpu ), m_minlevel( minlevel ), m_maxlevel( maxlevel ), m_fname( rename_info2amr(snap.m_filename) ) - { - read_header(); - - if( cpu > m_header.ncpu || cpu <= 0) - throw std::runtime_error("RAMSES_particle_data: expect to read from out of range CPU."); - - } - - //! perform the read operation of AMR data - void read( void ); - - //! end const_iterator for given refinement level - const_iterator end( int ilevel ) const - { - if( ilevel <= m_maxlevel ) - return const_iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).end(), this ); - else - return const_iterator( ilevel, m_cpu, m_AMR_levels.at(0).end(), this ); - } - - //! end iterator for given refinement level - iterator end( int ilevel ) - { - if( ilevel <= m_maxlevel ) - return iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).end(), this ); - else - return iterator( ilevel, m_cpu, m_AMR_levels.at(0).end(), this ); - } - - //! begin const_iterator for given refinement level - const_iterator begin( int ilevel ) const - { - if( ilevel <= m_maxlevel ) - return const_iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).begin(), this ); - else - return this->end(ilevel); - } - - //! begin iterator for given refinement level - iterator begin( int ilevel ) - { - if( ilevel <= m_maxlevel ) - return iterator( ilevel, m_cpu, m_AMR_levels.at(ilevel).begin(), this ); - else - return this->end(ilevel); - } - - - //! return the center of a child cell associated with a grid iterator - /*! - * @param it grid iterator - * @param ind sub-cell index (0..7) - * @return vec vector containing the coordinates - */ - template< typename Real_ > - inline vec cell_pos( const iterator& it, unsigned ind ) - { - vec pos; - pos.x = (*it).m_xg[0]+m_AMR_levels[it.m_ilevel].m_xc[ind]; - pos.y = (*it).m_xg[1]+m_AMR_levels[it.m_ilevel].m_yc[ind]; - pos.z = (*it).m_xg[2]+m_AMR_levels[it.m_ilevel].m_zc[ind]; - return pos; - } - - //! return the center of the grid associated with a grid iterator - /*! - * @param it grid iterator - * @return vec vector containing the coordinates - */ - template< typename Real_ > - inline vec grid_pos( const iterator& it ) - { - vec pos; - pos.x = (*it).m_xg[0]; - pos.y = (*it).m_xg[1]; - pos.z = (*it).m_xg[2]; - return pos; - } - - template< typename Real_ > - inline bool ball_intersects_grid( const iterator& it, const vec& xc, Real_ r2 ) - { - Real_ dx2 = 0.5/pow(2,it.get_level()); - vec xg = grid_pos(it); - return ball_intersection( xg, dx2, xc, r2 ); - } - - template< typename Real_ > - inline bool ball_intersects_cell( const iterator& it, char ind, const vec& xc, Real_ r2 ) - { - Real_ dx2 = 0.5/pow(2,it.get_level()+1); - vec xg = cell_pos(it,ind); - return ball_intersection( xg, dx2, xc, r2 ); - } - - template< typename Real_ > - inline bool shell_intersects_grid( iterator& it, const vec& xc, Real_ r1_2, Real_ r2_2 ) - { - Real_ dx2 = 0.5/pow(2,it.get_level()); - vec xg = grid_pos(it); - return shell_intersection( xg, dx2, xc, r1_2, r2_2 ); - } - - template< typename Real_ > - inline bool shell_intersects_cell( iterator& it, char ind, const vec& xc, Real_ r1_2, Real_ r2_2 ) - { - Real_ dx2 = 0.5/pow(2,it.get_level()+1); - vec xg = cell_pos(it,ind); - return shell_intersection( xg, dx2, xc, r1_2, r2_2 ); - } - - template< typename Real_ > - inline bool sphere_intersects_grid( const iterator& it, const vec& xc, Real_ r2 ) - { - Real_ dx2 = 0.5/pow(2,it.get_level()); - vec xg = grid_pos(it); - return sphere_intersection( xg, dx2, xc, r2 ); - } - - template< typename Real_ > - inline bool sphere_intersects_cell( const iterator& it, char ind, const vec& xc, Real_ r2 ) - { - Real_ dx2 = 0.5/pow(2,it.get_level()+1); - vec xg = cell_pos(it,ind); - return sphere_intersection( xg, dx2, xc, r2 ); - } - -}; - -/**************************************************************************************\ -\**************************************************************************************/ - -template< class Cell_, class Level_ > -void tree::read_header( void ) -{ - FortranUnformatted ff( gen_fname(m_cpu) ); - - //-- read header data --// - - ff.read( m_header.ncpu ); - ff.read( m_header.ndim ); - ff.read( std::back_inserter(m_header.nx) ); - ff.read( m_header.nlevelmax ); - ff.read( m_header.ngridmax ); - ff.read( m_header.nboundary ); - ff.read( m_header.ngrid_current ); - ff.read( m_header.boxlen ); - - ff.read( std::back_inserter(m_header.nout) ); - ff.read( std::back_inserter(m_header.tout) ); - ff.read( std::back_inserter(m_header.aout) ); - ff.read( m_header.t ); - ff.read( std::back_inserter(m_header.dtold) ); - ff.read( std::back_inserter(m_header.dtnew) ); - ff.read( std::back_inserter(m_header.nsteps) ); - ff.read( std::back_inserter(m_header.stat) ); - ff.read( std::back_inserter(m_header.cosm) ); - ff.read( std::back_inserter(m_header.timing) ); - ff.read( m_header.mass_sph ); - - m_ncoarse = m_header.nx[0]*m_header.nx[1]*m_header.nx[2]; -} - -/**************************************************************************************\ -\**************************************************************************************/ - -template< class Cell_, class Level_ > -std::string tree::gen_fname( int icpu ) -{ - std::string fname; - char ext[32]; - fname = m_fname; - fname.erase(fname.rfind('.')+1); - sprintf(ext,"out%05d",icpu); - fname.append(std::string(ext)); - return fname; -} - -/**************************************************************************************\ -\**************************************************************************************/ - -template< class Cell_, class Level_ > -std::string tree::rename_info2amr( const std::string& info ) -{ - std::string amr; - unsigned ii = info.rfind("info"); - amr = info.substr(0,ii)+"amr" + info.substr(ii+4, 6) + ".out00001"; - return amr; -} - -/**************************************************************************************\ -\**************************************************************************************/ - -template< class Cell_, class Level_ > -void tree::read( void ) -{ - // indexing map used to associate RAMSES internal cell IDs with new IDs - std::map m_ind_grid_map; - - std::vector cell_cpu; - std::vector cell_level; - std::vector itmp; - - - typename std::vector< Level_ >::iterator amr_level_it; - - FortranUnformatted ff( gen_fname( m_cpu ) ); - - //.. skip header entries ..// - ff.skip_n_from_start( 19 ); //.. skip header - - //+ headl + taill - ff.read( std::back_inserter(m_headl) ); - ff.read( std::back_inserter(m_taill) ); - ff.read( std::back_inserter(m_numbl) ); - - //.. skip numbtot - ff.skip_n( 1 ); - - std::vector ngridbound; - if( m_header.nboundary > 0 ){ - ff.skip_n( 2 ); //.. skip headb and tailb - ff.read( std::back_inserter(ngridbound) ); //.. read numbb - } - - ff.skip_n( 6 ); //..skip (1)free_mem+(2)ordering+(3)bound_key+ - //.. (4)coarse_son+(5)coarse_flag1+(6)coarse_cpu_map - - - if( /*m_minlevel < 1 ||*/ m_maxlevel > m_header.nlevelmax || m_minlevel > m_maxlevel ) - throw std::runtime_error("RAMSES_amr_level::read_level : requested level is invalid."); - - - m_ind_grid_map.insert( std::pair(0,ENDPOINT) ); - - FortranUnformatted::streampos spos = ff.tellg(); - - m_minlevel = 0; - - //... create indexing map ...// - for( int ilvl = 0; ilvl<=std::min(m_maxlevel+1, m_header.nlevelmax); ++ilvl ){ - unsigned gridoff = 0; - for( int icpu=0; icpu= m_header.ncpu && ngridbound[ACC_NB(icpu-m_header.ncpu,ilvl)] == 0 ) - continue; - - if( ilvl >= m_minlevel ){ - std::vector ind_grid; - ff.read( std::back_inserter(ind_grid) ); - for( unsigned i=0; i(ind_grid[i],gridoff++) ); - } - ind_grid.clear(); - }else - ff.skip(); - - ff.skip_n( 3+3+6+8+8+8 ); - } - if( ff.eof() ){ - //std::cerr << "eof reached in fortran read operation\n"; - m_maxlevel = ilvl;//+1; - break; - } - } - - ff.seekg( spos ); - - m_AMR_levels.clear(); - - - //... loop over levels ...// - for( int ilvl = 0; ilvl<=m_maxlevel; ++ilvl ){ - m_AMR_levels.push_back( Level_(ilvl) ); - Level_ &currlvl = m_AMR_levels.back(); - - for( int icpu=0; icpu= m_header.ncpu && ngridbound[ACC_NB(icpu-m_header.ncpu,ilvl)] == 0 ) - continue; - - if( ilvl >= m_minlevel ){ - unsigned gridoff = currlvl.size(); - - std::vector ind_grid; - ff.read( std::back_inserter(ind_grid) ); - for( unsigned i=0; i ftmp; - ff.read( std::back_inserter(ftmp) ); - for( unsigned j=0; j( std::back_inserter(ftmp) ); - for( unsigned j=0; j( std::back_inserter(ftmp) ); - for( unsigned j=0; j::check ){ - ff.read( std::back_inserter(itmp) ); - for( unsigned j=0; j::check ) - { - for( unsigned k=0; k<6; ++k ){ - ff.read( std::back_inserter(itmp) ); - for( unsigned j=0; j( std::back_inserter(itmp) ); - for( unsigned k=0; k. -*/ - -#ifndef __RAMSES_HYDRO_DATA_HH -#define __RAMSES_HYDRO_DATA_HH - -#include -#include -#include -#include -#include - -#include "FortranUnformatted_IO.hh" -#include "RAMSES_info.hh" -#include "RAMSES_amr_data.hh" - -namespace RAMSES{ -namespace HYDRO{ - -//! internal hydro variable indices -enum hydro_var -{ - density = 1, - velocity_x = 2, - velocity_y = 3, - velocity_z = 4, - pressure = 5, - metallicity = 6 -}; - -//! names of possible variables stored in a RAMSES hydro file -const char ramses_hydro_variables[][64] = { - {"density"}, - {"velocity_x"}, - {"velocity_y"}, - {"velocity_z"}, - {"pressure"}, - {"metallicity"} }; - - -/**************************************************************************************\ -\**************************************************************************************/ - -/*! - * @class RAMSES::HYDRO::proto_data - * @brief base class for all things hydro - * - * This class provides the base class for all cell based variables defined - * on the AMR mesh, accessible through the tree data structure. - * @sa RAMSES::HYDRO::data, RAMSES::HYDRO::empty_data - */ -template< typename TreeType_, typename ValueType_=double > -class proto_data{ - -public: - std::vector< std::vector > m_var_array; -protected: - TreeType_& m_tree; //!< reference to underlying AMR tree structure - unsigned m_cpu; //!< the computational domain - unsigned - m_minlevel, //!< maximum refinement level to be read from file - m_maxlevel; //!< minimum refinement level to be read from file - unsigned m_twotondim;//!< 2**ndim - unsigned m_ilevel; //!< the refinement level - - //! array holding the actual data - -public: - - //! constructor for the base class of all hydro data objects - /*! - * @param AMRtree reference to the underlying AMR tree data structure object - */ - explicit proto_data( TreeType_& AMRtree ) - : m_tree(AMRtree), m_cpu( AMRtree.m_cpu ), - m_minlevel( AMRtree.m_minlevel ), m_maxlevel( AMRtree.m_maxlevel ), - m_twotondim( (unsigned)(pow(2, AMRtree.m_header.ndim)+0.5) ) - { } - - //! access the value of the cells associated with the oct designated by the iterator - /*! - * @param it the grid iterator pointing to the current oct - * @param ind index of the child cell of the current oct (0..7) - */ - inline ValueType_& cell_value( const typename TreeType_::iterator& it, int ind ) - { - unsigned ipos = it.get_absolute_position(); - unsigned ilevel = it.get_level();//-m_minlevel; - return (m_var_array[ilevel])[m_twotondim*ipos+ind]; - } - - //! access the value of the cells associated with the oct designated by the iterator - /*! - * @param it the grid iterator pointing to the current oct - * @param ind index of the child cell of the current oct (0..7) - */ - inline ValueType_& operator()( const typename TreeType_::iterator& it, int ind ) - { return cell_value(it,ind); } - - - //! combines all elements of this instance with that of another using a binary operator - /*! - * @param o the other data object with which to combine the elements - * @param op the binary operator to be used in combining elements - */ - template - void combine_with( const proto_data& o, const BinaryOperator_& op ) - { - if( m_minlevel != o.m_minlevel || m_maxlevel != o.m_maxlevel - || m_twotondim != o.m_twotondim || &m_tree != &o.m_tree - || m_var_array.size() != o.m_var_array.size() ){ - std::cerr << "this #levels=" << m_var_array.size() << ", other #levels=" << o.m_var_array.size() << std::endl; - throw std::runtime_error("Error: trying to combine incompatible mesh data."); - } - - for( unsigned ilvl=0; ilvl -class empty_data : public proto_data{ - -public: - - //! constructor for an empty hydro variable defined on the AMR mesh - /*! - * @param AMRtree the underlying hierarchical tree data structure - * @param v the value with which the variable should be initialized, default is a (double) zero. - */ - explicit empty_data( TreeType_& AMRtree, ValueType_ v=(ValueType_)0.0 ) - : proto_data(AMRtree) - { - this->m_var_array.assign( this->m_maxlevel+1, std::vector() ); - - for( unsigned ilvl = this->m_minlevel; ilvl<=this->m_maxlevel; ++ilvl ){ - typename TreeType_::iterator grid_it = this->m_tree.begin( ilvl ); - while( grid_it != this->m_tree.end(ilvl) ){ - - for( unsigned j=0;jm_twotondim;++j ) - this->m_var_array[ilvl].push_back( v ); - - ++grid_it; - } - } - } - - - //! write the new hydro variable to a RAMSES compatible output file - /*! - * writes the hydro variable to a RAMSES compatible output file named - * after the convention - * (path)/(basename)_(DOMAIN).out(snap_num) - * - * @param path the path where to store the files - * @param basename the filename base string to prepend to the domain number - * @param snap_num the number of the snapshot (default is zero). - */ - void save( std::string path, std::string basename, unsigned snap_num=0 ) - { - char fullname[256]; - sprintf(fullname,"%s/%s_%05d.out%05d",path.c_str(),basename.c_str(), snap_num, this->m_tree.m_cpu ); - std::ofstream ofs( fullname, std::ios::binary|std::ios::trunc ); - - - typename TreeType_::iterator it; - unsigned ncpu = this->m_tree.m_header.ncpu; - - //std::cerr << "ncpu = " << ncpu << std::endl; - - for( unsigned ilvl = 0; ilvl<=this->m_maxlevel; ++ilvl ){ - std::vector< std::vector > - temp1 (ncpu, std::vector() ), - temp2 (ncpu, std::vector() ), - temp3 (ncpu, std::vector() ), - temp4 (ncpu, std::vector() ), - temp5 (ncpu, std::vector() ), - temp6 (ncpu, std::vector() ), - temp7 (ncpu, std::vector() ), - temp8 (ncpu, std::vector() ); - - it = this->m_tree.begin(ilvl); - - while( it!= this->m_tree.end(ilvl) ) - { - temp1[ it.get_domain()-1 ].push_back( (*this)(it,0) ); - temp2[ it.get_domain()-1 ].push_back( (*this)(it,1) ); - temp3[ it.get_domain()-1 ].push_back( (*this)(it,2) ); - temp4[ it.get_domain()-1 ].push_back( (*this)(it,3) ); - temp5[ it.get_domain()-1 ].push_back( (*this)(it,4) ); - temp6[ it.get_domain()-1 ].push_back( (*this)(it,5) ); - temp7[ it.get_domain()-1 ].push_back( (*this)(it,6) ); - temp8[ it.get_domain()-1 ].push_back( (*this)(it,7) ); - ++it; - } - - - for( unsigned icpu = 0; icpu 0 ) - { - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp1[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp2[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp3[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp4[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp5[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp6[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp7[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - - ofs.write( (char*)&nn, sizeof(unsigned) ); - ofs.write( (char*)&temp8[icpu][0], nn ); - ofs.write( (char*)&nn, sizeof(unsigned) ); - } - } - } - } - - //! reads an additional from a RAMSES compatible (single var) output file - /*! - * @param basename the base string used for the variable - */ - void read( std::string basename ) - { - char fullname[256]; - sprintf(fullname,"%s_%05d.out%05d",basename.c_str(), this->m_tree.m_header.nout[0], this->m_tree.m_cpu ); - std::ifstream ifs( fullname, std::ios::binary ); - - for( unsigned ilvl = this->m_minlevel; ilvl<=this->m_maxlevel; ++ilvl ){ - unsigned nn = this->m_var_array[ilvl].size() * sizeof(ValueType_); - unsigned nnfile; - ifs.read( (char*)&nnfile, sizeof(unsigned) ); - if( nn != nnfile ){ - std::cerr << "Error: dimension mismatch between AMR tree and file data!" << std::endl; - std::cerr << " found " << nnfile << ", expected " << nn << " in file \'" << fullname << "\'" << std::endl; - return; - } - ifs.read( (char*)&this->m_var_array[ilvl][0], nn ); - ifs.read( (char*)&nn, sizeof(unsigned) ); - } - ifs.close(); - } - -}; - - -/**************************************************************************************\ -\**************************************************************************************/ - -/*! - * @class data - * @brief encapsulates hydro data from a RAMSES simulation snapshot - * - * This class provides low-level read access to RAMSES hydro_XXXXX.out files. - * Data from a given list of computational domains can be read and is - * stored in internal datastructures. - * Access to cell position and threaded tree structure of the cell is provided - * through the member functions of class RAMSES_amr_level. - * @sa RAMSES_amr_level - */ -template< typename TreeType_, typename Real_=double > -class data : public proto_data{ - -public: - struct header{ - unsigned ncpu; //!< number of CPUs in simulation - unsigned nvar; //!< number of hydrodynamic variables - unsigned ndim; //!< number of spatial dimensions - unsigned nlevelmax; //!< maximum allowed refinement level - unsigned nboundary; //!< number of boundary regions - double gamma; //!< adiabatic exponent - }; - - - std::string m_fname; //!< the file name - struct header m_header; //!< header meta data - - const unsigned m_nvars; //!< number of variables stored in file - - std::vector m_varnames; //!< names of the variables stored in file - std::map m_var_name_map; //!< a hash table for variable name to internal variable index - - -protected: - - //! generates a hydro_XXXX filename for specified cpu - std::string gen_fname( int icpu ); - - //! generate hydro_XXXXX filename from info filename - std::string rename_info2hydro( const std::string& info ); - - //! generate hydro_XXXXX filename from amr filename - std::string rename_amr2hydro( const std::string& info ); - - //! read header data containing meta information - void read_header( void ); - - //! get internal index for given variable string identifier - /*! - * @param varname the string identifier of the hydro variable - * @return internal variable index - */ - int get_var_idx( const std::string& varname ) - { - int ivar; - std::map::iterator mit; - if( (mit=m_var_name_map.find(varname)) != m_var_name_map.end() ) - ivar = (*mit).second; - else - throw std::runtime_error("RAMSES::HYDRO::data::get_var_idx :"\ - " Error, cannot find variable named \'"+varname+"\'"); - return ivar; - } - - //! perform read operation of one hydro variable (internal use) - /*! - * users should always call the read( std::string ) member function - * and read variables through their string identifiers - * @param var the index of the hydro variable - */ - void read( unsigned var ); - -public: - - //! constructor for hydro data - /*! - * @param AMRtree reference to the underlying tree object - */ - explicit data( TreeType_& AMRtree ) - : proto_data( AMRtree ), - m_fname( rename_amr2hydro(AMRtree.m_fname) ), - m_nvars( 6 ) - { - read_header(); - - if( this->m_cpu > m_header.ncpu || this->m_cpu < 1 ) - throw std::runtime_error("RAMSES::HYDRO::data : expect to read from out of range CPU."); - - if( this->m_minlevel < 0 || this->m_maxlevel >= m_header.nlevelmax ) - throw std::runtime_error("RAMSES::HYDRO::data : requested level is invalid."); - - //m_twotondim = (unsigned)(pow(2,m_header.ndim)+0.5); - - for( unsigned i=0; i( ramses_hydro_variables[i], i+1 ) ); - m_varnames.push_back( ramses_hydro_variables[i] ); - } - } - - //! retrieve the names of variables available in the hydro data source - /*! Variables have an internal index but are accessed through their name, given as a string - * hydro data files may contain different variables depending on the kind of simulation run. - * @param names An output iterator to which std::string designating available variables are sent - * @return Final position of the output iterator - */ - template< typename _OutputIterator > - _OutputIterator get_var_names( _OutputIterator names ) - { - std::vector::iterator it( m_varnames.begin() ); - while( it != m_varnames.end() ){ - *names = *it; - ++it; ++names; - } - return names; - } - - //! perform read operation of one hydro variable - /*! - * @param varname the string identifier of the hydro variable - */ - void read( std::string varname ) - { this->read( get_var_idx( varname ) ); } - -}; - - -template< typename TreeType_, typename Real_ > -void data::read_header( void ) -{ - FortranUnformatted ff( gen_fname( this->m_cpu ) ); - - //-- read header data --// - ff.read( m_header.ncpu ); - ff.read( m_header.nvar ); - ff.read( m_header.ndim ); - ff.read( m_header.nlevelmax ); - ff.read( m_header.nboundary ); - ff.read( m_header.gamma ); -} - - -template< typename TreeType_, typename Real_ > -void data::read( unsigned var ) -{ - this->m_var_array.clear(); - //int twotondim = (int)(pow(2,m_header.ndim)+0.5); - - FortranUnformatted ff( gen_fname( this->m_cpu ) ); - - //.. skip header entries ..// - ff.skip_n_from_start( 6 ); //.. skip header - - if( var < 1 || var > m_header.nvar ) - throw std::runtime_error("RAMSES::HYDRO::data::read : requested variable is invalid in file \'"+m_fname+"\'."); - - this->m_var_array.clear(); - - for( unsigned ilvl = 0; ilvl<=this->m_maxlevel; ++ilvl ){ - - this->m_var_array.push_back( std::vector() ); - - for( unsigned icpu = 0; icpu= this->m_minlevel ){ - if( file_ilevel != ilvl+1 ) - throw std::runtime_error("RAMSES::HYDRO::data::read : corrupted file " \ - "or file seek failure in file \'"+m_fname+"\'."); - - - std::vector tmp; - for( unsigned i=0; im_twotondim; ++i ) - { - ff.skip_n( var-1 ); - ff.read( std::back_inserter(tmp) ); - ff.skip_n( m_header.nvar-var ); - } - //.. reorder array to increase data locality..// - this->m_var_array.reserve( tmp.size() ); - for( unsigned i=0; im_twotondim; ++j ){ - (this->m_var_array.back()).push_back( tmp[i+j*file_ncache] ); - } - } - }else{ - ff.skip_n( this->m_twotondim*m_header.nvar ); - } - } - } -} - - -template< typename TreeType_, typename Real_ > -std::string data::gen_fname( int icpu ) -{ - std::string fname; - char ext[32]; - fname = m_fname; - fname.erase(fname.rfind('.')+1); - sprintf(ext,"out%05d",icpu); - fname.append(std::string(ext)); - return fname; -} - - -template< typename TreeType_, typename Real_ > -std::string data::rename_info2hydro( const std::string& info ) -{ - std::string amr; - unsigned ii = info.rfind("info"); - amr = info.substr(0,ii)+"hydro" + info.substr(ii+4, 6) + ".out00001"; - return amr; -} - - -template< typename TreeType_, typename Real_ > -std::string data::rename_amr2hydro( const std::string& info ) -{ - std::string amr; - unsigned ii = info.rfind("amr"); - amr = info.substr(0,ii)+"hydro" + info.substr(ii+3, 6) + ".out00001"; - return amr; -} - -/**************************************************************************************\ -\**************************************************************************************/ - - -/*! - * @class RAMSES::HYDRO::multi_domain_data - * @brief encapsulates hydro data from multiple computational domain - * - * This class provides high-level data access to bundled domain data, Bundling - * of domain data is useful when analysis of snapshots is performed in parallel - * but on a number of cores different than that used for the RAMSES simulation. - */ -template< typename TreeType_, typename DataType_, typename ValueType_=double > -class multi_domain_data -{ - public: - - unsigned m_ndomains; //!< number of domains bundled - RAMSES::snapshot &m_rsnap; //!< reference to the underlying snapshot object - std::vector m_data; //!< vector of bundled data objects - std::vector m_ptrees; //!< vector of bundled tree objects - - public: - - //! constructor for bundled multi-domain hydro variables - /*! - * @param rsnap reference to the underlying snapshot object - * @param ptrees vector of trees to be bundled - */ - multi_domain_data( RAMSES::snapshot& rsnap, std::vector ptrees ) - : m_ndomains( ptrees.size() ), m_rsnap(rsnap), m_ptrees( ptrees ) - { - for( unsigned idom=0; idom - void combine_with( const multi_domain_data& o, const BinaryOperator& op ) - { - if( m_data.size() != o.m_data.size() ) - throw std::runtime_error("Error: trying to combine incompatible multi_domain_data."); - - for( unsigned i=0; i - m_data[i]->combine_with( *o.m_data[i], op ); - } - - - //! bracket operator to access bundled multi-domain data - /*! - * @param idomain the domain index (1 based) - * @param it tree iterator pointing to the grid in the tree to be accessed - * @param CellIndex index of the cell in the grid - */ - ValueType_& operator() ( unsigned idomain, const typename TreeType_::iterator& it, char CellIndex ) - { - if( idomain >= m_data.size() ){ - std::cerr << "out of range domain: " << idomain << " >= " << m_data.size() << std::endl; - idomain=0; - } - - return m_data[idomain]->cell_value(it,CellIndex); - } - - - //! bracket operator to access bundled multi-domain data (const) - /*! - * @param idomain the domain index (1 based) - * @param it tree const_iterator pointing to the grid in the tree to be accessed - * @param CellIndex index of the cell in the grid - */ - ValueType_& operator() ( unsigned idomain, const typename TreeType_::const_iterator& it, char CellIndex ) - { - if( idomain >= m_data.size() ){ - std::cerr << "out of range domain: " << idomain << " >= " << m_data.size() << std::endl; - idomain=0; - } - return m_data[idomain]->cell_value(it,CellIndex); - } - - //! destructor for bundled multi-domain data - ~multi_domain_data() - { - for( unsigned idom=0; idomread(var_name); - } - } - - //! TBD - unsigned size( void ){ return m_data.size(); } - - //! TBD - unsigned size( unsigned idom ) { return m_data.at(idom)->size(); } -}; - -/**************************************************************************************\ -\**************************************************************************************/ - - -} // namespace HYDRO -} // namespace RAMSES - -#endif //__RAMSES_HYDRO_DATA_HH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/RAMSES_info.hh --- a/yt/ramses_headers/RAMSES_info.hh Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,334 +0,0 @@ -/* - This file is part of libRAMSES++ - a C++ library to access snapshot files - generated by the simulation code RAMSES by R. Teyssier - - Copyright (C) 2008-09 Oliver Hahn, ojha@gmx.de - - This program 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 . -*/ - -#ifndef __READ_INFO_HH -#define __READ_INFO_HH - -#include -#include -#include -#include -#include -#include - -namespace RAMSES{ - -#define btest(var,pos) ((var) & (1<<(pos))) - -//! the file format version of RAMSES -enum codeversion{ - version1, version2, version3 -}; - -const int state_diagram[12][2][8] = -{ - { { 1, 2, 3, 2, 4, 5, 3, 5}, { 0, 1, 3, 2, 7, 6, 4, 5} }, - { { 2, 6, 0, 7, 8, 8, 0, 7}, { 0, 7, 1, 6, 3, 4, 2, 5} }, - { { 0, 9,10, 9, 1, 1,11,11}, { 0, 3, 7, 4, 1, 2, 6, 5} }, - { { 6, 0, 6,11, 9, 0, 9, 8}, { 2, 3, 1, 0, 5, 4, 6, 7} }, - { {11,11, 0, 7, 5, 9, 0, 7}, { 4, 3, 5, 2, 7, 0, 6, 1} }, - { { 4, 4, 8, 8, 0, 6,10, 6}, { 6, 5, 1, 2, 7, 4, 0, 3} }, - { { 5, 7, 5, 3, 1, 1,11,11}, { 4, 7, 3, 0, 5, 6, 2, 1} }, - { { 6, 1, 6,10, 9, 4, 9,10}, { 6, 7, 5, 4, 1, 0, 2, 3} }, - { {10, 3, 1, 1,10, 3, 5, 9}, { 2, 5, 3, 4, 1, 6, 0, 7} }, - { { 4, 4, 8, 8, 2, 7, 2, 3}, { 2, 1, 5, 6, 3, 0, 4, 7} }, - { { 7, 2,11, 2, 7, 5, 8, 5}, { 4, 5, 7, 6, 3, 2, 0, 1} }, - { {10, 3, 2, 6,10, 3, 4, 4}, { 6, 1, 7, 0, 5, 2, 4, 3} } -}; - -/**************************************************************************************\ -\**************************************************************************************/ - -/*! - * @class RAMSES_snapshot - * @brief class providing access to general information about a RAMSES simulation snapshot - */ -class snapshot{ - -protected: - - //! c++ input file stream for stream access to the RAMSES info_XXXXX.txt file - std::ifstream m_ifs; - -public: - - //! path and name of the info_XXXXX.txt file of a RAMSES snapshot - std::string m_filename; - - //! the RAMSES version, takes care of changes in file format - codeversion m_version; - - //! the simulation meta data stored in the info file - struct info_data{ - unsigned ncpu; //!< the number of CPUs (and thus computational domains) in this simulation - unsigned ndim; //!< the number of spatial dimensions - unsigned levelmin; //!< minimum refinement level (this refinement is thus present everywhere) - unsigned levelmax; //!< maximum refinement level allowed - unsigned ngridmax; //!< maximum number of grid cells stored per CPU - unsigned nstep_coarse; //!< number of coarse time steps performed up to this snapshot - double boxlen; //!< the length of the simulation box in internal units - double time; //!< time stamp of the snapshot - double aexp; //!< cosmological expansion factor of the current snapshot - double H0; //!< value of the Hubble constant for this simulation - double omega_m; //!< value of the total matter density parameter for this simulation - double omega_l; //!< value of the cosmological constant density parameter for this simulation - double omega_k; //!< value of the curvature density parameter for this simulation - double omega_b; //!< value of the baryonic (i.e. collisional) matter density parameter for this simulation - double unit_l; //!< internal length unit - double unit_d; //!< internal density unit - double unit_t; //!< internal time unit - }; - - //! header data entailing time stamp and parameters of the simulation snapshot - struct info_data m_header; - - //! minimum hilbert ordering indices for each domain - std::vector ind_min; - - //! maximum hilbert ordering indices for each domain - std::vector ind_max; - -protected: - - //! tokenize a string - /*! - * @param str input string - * @param tokens reference to an STL vector containing all substrings after return - */ - void tokenize( const std::string& str, std::vector& tokens ) - { - std::string buf; - std::stringstream ss(str); - while( ss >> buf ) - tokens.push_back( buf ); - } - - //! templated type conversion for string to arbitrary types that can be read from STL stringstreams - /*! - * @param str input string - * @param ret reference to the template parameter type return value - */ - template - inline void convert( const std::string& str, T& ret ) - { - std::stringstream ss(str); - ss >> ret; - } - - //! reads the right-most substring of a line - /*! - * ¶m rhs reference to return value - */ - template - void read_line_rhs( T& rhs ) - { - std::vector split_buf; - std::string buf; - std::getline( m_ifs, buf ); - - tokenize( buf, split_buf ); - convert( split_buf[split_buf.size()-1], rhs ); - } - - //! skip a line in the text input file - void skip_line( void ) - { - std::string buf; - std::getline( m_ifs, buf ); - } - - //! parse the RAMSES snapshot info file - void parse_file( void ) - { - read_line_rhs( m_header.ncpu ); - read_line_rhs( m_header.ndim ); - read_line_rhs( m_header.levelmin ); - read_line_rhs( m_header.levelmax ); - read_line_rhs( m_header.ngridmax ); - read_line_rhs( m_header.nstep_coarse ); - skip_line(); - read_line_rhs( m_header.boxlen ); - read_line_rhs( m_header.time ); - read_line_rhs( m_header.aexp ); - read_line_rhs( m_header.H0 ); - read_line_rhs( m_header.omega_m ); - read_line_rhs( m_header.omega_l ); - read_line_rhs( m_header.omega_k ); - read_line_rhs( m_header.omega_b ); - read_line_rhs( m_header.unit_l ); - read_line_rhs( m_header.unit_d ); - read_line_rhs( m_header.unit_t ); - skip_line(); - skip_line(); - skip_line(); - - for( unsigned i=0; i split_buf; - std::string buf; - std::getline( m_ifs, buf ); - tokenize( buf, split_buf ); - - double imin, imax; - unsigned domain; - - convert( split_buf[0], domain ); - - if( domain != i+1 ) - throw std::runtime_error("RAMSES_snapshot::parse_file : corrupt info file\'"+m_filename+"\'."); - - convert( split_buf[1], imin ); - convert( split_buf[2], imax ); - - ind_min.push_back( imin ); - ind_max.push_back( imax ); - - } - - - } - - inline unsigned locate( const double x, const std::vector& vx ) - { - long unsigned ju,jm,jl; - bool ascnd=(vx[vx.size()-1]>=vx[0]); - jl = 0; - ju = vx.size()-1; - while( ju-jl > 1 ) { - jm = (ju+jl)>>1; - if( x >= vx[jm] == ascnd ) - jl = jm; - else - ju = jm; - } - return std::max((long unsigned)0,std::min((long unsigned)(vx.size()-2),(long unsigned)jl)); - } - -public: - - //! constructor for a RAMSES snapshot meta data object - /*! - * @param info_filename path and name of the info_XXXXX.txt file of the RAMSES simulation - */ - snapshot( std::string info_filename, codeversion ver=RAMSES::version1 ) - : m_ifs( info_filename.c_str(), std::ios::in ), m_filename( info_filename ), - m_version( ver ) - { - if(!m_ifs.good()) - throw std::runtime_error("RAMSES_snapshot : cannot open file \'"+m_filename+"\' for read access."); - m_ifs.exceptions ( std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit ); - - parse_file(); - } - - - unsigned get_snapshot_num( void ) - { - unsigned ii = m_filename.rfind("info"), num; - std::string tmp( m_filename.substr(ii+5,5) ); - sscanf(tmp.c_str(),"%d",&num); - return num; - } - - unsigned getdomain_bykey( double key ) - { - unsigned i = locate( key, ind_min ); - return i+1; - } - - -}; - - -inline void hilbert3d( - const std::vector& x, - const std::vector& y, - const std::vector& z, - std::vector& order, - unsigned bit_length ) -{ - std::vector i_bit_mask(3*bit_length, false ); - std::vector x_bit_mask(1*bit_length, false ); - std::vector y_bit_mask(1*bit_length, false ); - std::vector z_bit_mask(1*bit_length, false ); - - unsigned npoints = x.size(); - double lx = pow(2.0,bit_length); - - for( unsigned ip=0; ip=0; --i ) - { - b2 = i_bit_mask[3*i+2]; - b1 = i_bit_mask[3*i+1]; - b0 = i_bit_mask[3*i+0]; - - sdigit = b2*4+b1*2+b0; - nstate = state_diagram[cstate][0][sdigit]; - hdigit = state_diagram[cstate][1][sdigit]; - - i_bit_mask[3*i+2] = btest(hdigit,2); - i_bit_mask[3*i+1] = btest(hdigit,1); - i_bit_mask[3*i+0] = btest(hdigit,0); - - cstate = nstate; - } - - order[ip] = 0.0; - for( unsigned i=0; i<3*bit_length; ++i ) - { - b0 = i_bit_mask[i]; - order[ip] += (double)b0*pow(2.0,i); - } - - } -} - - -#undef btest - -} - - -#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/RAMSES_particle_data.hh --- a/yt/ramses_headers/RAMSES_particle_data.hh Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,650 +0,0 @@ -/* - This file is part of libRAMSES++ - a C++ library to access snapshot files - generated by the simulation code RAMSES by R. Teyssier - - Copyright (C) 2008-09 Oliver Hahn, ojha@gmx.de - - This program 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 . -*/ - -#ifndef __RAMSES_PARTICLE_DATA_HH -#define __RAMSES_PARTICLE_DATA_HH - -#include -#include -#include -#include -#include -#include -#include - -#include "RAMSES_info.hh" -#include "FortranUnformatted_IO.hh" -#include "data_iterators.hh" - -namespace RAMSES{ -namespace PART{ - -//! particle type identifiers returned by RAMSES_particle_data::ptype() -enum ptype_bits { - RAMSES_DM_BIT = 0, - RAMSES_STAR_BIT = 1, - RAMSES_DEBRIS_BIT = 2 -}; - -//! particle type identifiers, can be combined with logical or -enum ptype { - ptype_dm = 1L << RAMSES_DM_BIT, //!< selects dark matter particles - ptype_star = 1L << RAMSES_STAR_BIT, //!< selects star particles - ptype_debris = 1L << RAMSES_DEBRIS_BIT, //!< selects debris particles -}; - -//... zero age of a particle is assumed if age is smaller than this number -const double zero_age = 1.0e-8; - - -//... content of RAMSES particle data files is fixed, available fields -//... are described in the following two fields - - -//! possible variable names in RAMSES particle files in version 1 and 2 files -const char ramses_particle_variables_v12[][64] = { - {"position_x"}, - {"position_y"}, - {"position_z"}, - {"velocity_x"}, - {"velocity_y"}, - {"velocity_z"}, - {"mass"}, - {"age"}, - {"metallicity"}, - {"particle_ID"}, - {"refinement_level"} }; - -//! possible variable names in RAMSES particle files in version 3 files -const char ramses_particle_variables_v3[][64] = { - {"position_x"}, - {"position_y"}, - {"position_z"}, - {"velocity_x"}, - {"velocity_y"}, - {"velocity_z"}, - {"mass"}, - {"particle_ID"}, - {"refinement_level"}, - {"age"}, - {"metallicity"} }; - - -/**************************************************************************************\ -\**************************************************************************************/ - -/*! - * @class RAMSES::PARTICLE::data - * @brief encapsulates particle data from a RAMSES simulation snapshot - * - * This class provides low-level read access to RAMSES particle files. - * Data from a given list of computational domains can be read and is - *stored in internal datastructures. - */ -class data { -protected: - const RAMSES::snapshot *m_pRAMSESsnap; //!< pointer to RAMSES snapshot meta-information - std::string m_fname; //!< path/filename of the .info file - int m_cpu; //!< IDs of computational domains from which data is to be read. - unsigned m_nvars; //!< number of variables available in file - std::vector m_nvar_stride; //!< access offset to variable locations in file - std::vector m_vardim; //!< spatial dimension of a variable - std::vector m_varnames; //!< names of the variables - - //! a hash table for variable name to internal variable index - std::map m_var_name_map; - - //! particle file header meta data - struct header{ - std::vector< int > localseed; //!< local seed used to generate star particles - int ncpu; //!< number of CPUs in the simulation - int ndim; //!< number of spatial dimensions - int nstar_tot; //!< total number of star particles - int nsink; //!< number of sink particles - int npart; //!< number of particles - int npart_dm; //!< number of dark matter particles - int npart_star; //!< number of star particles - int npart_debris; //!< number of debris particles - double mstar_tot; //!< total stellar mass - double mstar_lost; //!< stellar mass lost - }; - - struct header m_header; //!< particle file header data - - - //! generate the part_XXXXX.oYYYYY filename for a given CPU ID - std::string gen_fname( int icpu ); - - //! generate the part_XXXXX.oYYYYY filename from the info_XXXXX.oYYYYY filename. - std::string rename_info2part( const std::string& info ); - - //! Read header from particle files and determine total number of particles. - void read_header( void ); - -public: - - //! constructor for a RAMSES particle data interface - /*! The constructor checks the validity of the requested computational - * domains and reads the particle header data to determine the total - * number of particles. - * @param snap reference to the underlying snapshot object - * @param cpu the domain number - */ - data( const RAMSES::snapshot& snap, int cpu ) - : m_pRAMSESsnap( &snap ), - m_fname( rename_info2part(snap.m_filename) ), - m_cpu( cpu ) - { - m_header.npart_dm = 0; - m_header.npart_star = 0; - m_header.npart_debris = 0, - - read_header(); - - //... compute offsets of variable arrays in file and access hash map ...// - m_nvar_stride.push_back(0); - - - switch( m_pRAMSESsnap->m_version ) - { - case RAMSES::version1: - case RAMSES::version2: - - if( m_header.nstar_tot > 0 ) - { - //... file contains star particles ...// - m_nvars = 11; - for( unsigned i=0; i( ramses_particle_variables_v12[i], i ) ); - m_varnames.push_back( ramses_particle_variables_v12[i] ); - } - } - else - { - //... file contains only DM particles, then some fields are not available - m_nvars = 9; - for( unsigned i=0,j=0; i( ramses_particle_variables_v12[j], i ) ); - m_varnames.push_back( ramses_particle_variables_v12[j] ); - } - } - - break; - - case RAMSES::version3: - - if( m_header.nstar_tot > 0 ) - //... file contains star particles ...// - m_nvars = 11; - else - //... file contains only DM particles, then last fields are not available - m_nvars = 9; - - for( unsigned i=0; i( ramses_particle_variables_v3[i], i ) ); - m_varnames.push_back( ramses_particle_variables_v3[i] ); - } - - break; - - - default: - throw std::runtime_error("RAMSES::PART::data: cannot handle data for this RAMSES version."); - } - - //... check if supplied range of domains is valid ...// - if( m_cpu < 1 || m_cpu > m_header.ncpu ) - throw std::runtime_error("RAMSES::PART::data: attempt to read from out of range CPU."); - } - - - //=== implementation of interface derived compatible to multi variable data source skeleton ===// - //=== see file README.devel, section 1, for details on the interface skeleton ===// - - //! retrieve the names of variables available in the particle data source - /*! Variables have an internal index but are accessed through their name, given as a string - * Particle data files may contain different variables depending on the kind of simulation run. - * @param names An output iterator to which std::string designating available variables are sent - * @return Final position of the output iterator - */ - template< typename _OutputIterator > - _OutputIterator get_var_names( _OutputIterator names ) - { - std::vector::iterator it( m_varnames.begin() ); - while( it != m_varnames.end() ){ - *names = *it; - ++it; ++names; - } - return names; - } - -protected: - - //! return the internal index for a variable of specified name - /*! throws a runtime_error exception if variable name does not exist - * @param varname string designating the variable - * @return internal index of variable - */ - int get_var_idx( const std::string& varname ) - { - int ivar; - std::map::iterator mit; - if( (mit=m_var_name_map.find(varname)) != m_var_name_map.end() ) - ivar = (*mit).second; - else - throw std::runtime_error("RAMSES::PART::data::get_var_idx :"\ - " Error, cannot find variable named \'"+varname+"\'"); - return ivar; - } - - - //! get spatial dimensionality of a variable - int get_var_dim( int ivar ) - { return m_vardim[ivar]; } - - -public: - - //! get spatial dimensionality of a variable - int get_var_dim( const std::string& varname ) - { return m_vardim[get_var_idx(varname)]; } - - - //! retrieve data of specified variable from data source using a mask access pattern - /*! The data for the specified variable, fixing a spatial dimension, is sent to an - * output iterator. For each read operation, the mask iterator is checked - * and the data is discarded if it points to 'false' - * @param varname name of the variable to be retrieved - * @param mask input iterator supplying the mask access pattern - * @param val output iterator to which the retrieved data is sent - * @return final position of the mask iterator - */ - template< typename _Basetype, typename _InputIterator, typename _OutputIterator > - _InputIterator get_var( const std::string& varname, _InputIterator mask, _OutputIterator val ) - { - unsigned ivar = get_var_idx( varname ); - FortranUnformatted ff( gen_fname(m_cpu) ); - //.. skip header and particle position entries ..// - ff.skip_n_from_start( 8+m_nvar_stride[ivar] ); - mask=ff.read<_Basetype, _InputIterator, _OutputIterator>(mask,val); - - return mask; - } - - - //! retrieve data of specified variable from data source - /*! The data for the specified variable, fixing a spatial dimension, is sent to an - * output iterator. - * @param varname name of the variable to be retrieved - * @param val output iterator to which the retrieved data is sent - * @return final position of the mask iterator - */ - template< typename _Basetype, typename _OutputIterator > - _OutputIterator get_var( const std::string& varname, _OutputIterator val ) - { - unsigned ivar = get_var_idx( varname ); - FortranUnformatted ff( gen_fname(m_cpu) ); - //.. skip header and particle position entries ..// - ff.skip_n_from_start( 8+m_nvar_stride[ivar] ); - ff.read<_Basetype, _OutputIterator>(val); - - return val; - } - - - - //=== the following member functions are simply copied from the skeleton ===// - - - //! generate bit mask for specified particle type - /*! returns a particle type identifier for the given particle index - * this is determined from the age and ID of the particle. Return - * value is RAMSES_PTYPE_DM for dark matter particles (age=0,ID>0), - * RAMSES_PTYPE_STAR for star particles (age>0,ID>0) and - * RAMSES PTYPE_DEBRIS for debris type (SN remnant) particles - * (age>0,ID=0). - * @param ptype particle type, i.e. RAMSES_PTYPE_DM, RAMSES_PTYPE_STAR or RAMSES_PTYPE_DEBRIS - * @param age_first - * @param age_last - * @param ids_first - * @param mask - * @return particle mask iterator - */ - template - _OutputIterator mask_particle_type( int ptype, - const _InputIterator1& age_first, const _InputIterator1& age_last, - const _InputIterator2& ids_first, _OutputIterator mask ) - { - _InputIterator1 age_it=age_first; - _InputIterator2 ids_it=ids_first; - - switch( ptype ) - { - case ptype_dm: - while( age_it != age_last ) - { - if( fabs(*age_it) <= zero_age ) - *mask = true; - else - *mask = false; - ++mask; ++age_it; - } - break; - - case ptype_star: - while( age_it != age_last ) - { - if( fabs(*age_it) > zero_age && (*ids_it) > 0) - *mask = true; - else - *mask = false; - ++mask; ++age_it; ++ids_it; - } - break; - - case ptype_debris: - while( age_it != age_last ) - { - if( fabs(*age_it) > zero_age && (*ids_it) == 0) - *mask = true; - else - *mask = false; - ++mask; ++age_it; ++ids_it; - } - break; - - default: throw std::runtime_error("get_particle_type_mask: Error, invalid particle type."); - } - - return mask; - } - - - - - //! generate bit mask for a specified bounding region - /*! Checks whether data points lie within a given region. The _BoundingRegion class object - * must return true or false for a call of 'region(x,y,z)' if the point (x,y,z) - * does or does not lie in the desired region. - * @param region A region object used for querying whether points lie in a desired subspace. - * @param x_first Input iterator pointing on first x-coordinate - * @param x_last Input iterator pointing behind last x-coordinate - * @param y_first Input iterator pointing on first y-coordinate - * @param z_first Input iterator pointing on first z-coordinate - * @param mask Output iterator to which true/false values are written - * @return Final state of mask iterator - */ - template - _OutputIterator mask_region( _BoundingRegion region, - const _InputIterator& x_first, const _InputIterator& x_last, - const _InputIterator& y_first, const _InputIterator& z_first, - _OutputIterator mask ) - { - _InputIterator xit=x_first, yit=y_first, zit=z_first; - - while( xit != x_last ) - { - *mask = region( *xit, *yit, *zit ); - ++mask; ++xit; ++yit; ++zit; - } - - return mask; - } - -}; - -/**************************************************************************************\ -\**************************************************************************************/ - -#define R_CHECK_BIT(var,pos) ((var) & (1<<(pos))) - -template< typename Real_, typename IDType_ > -inline bool is_of_type( Real_ age, IDType_ id, int ptype ) -{ - //if( ptype==ptype_star ) - if( R_CHECK_BIT( ptype, RAMSES_STAR_BIT ) ) - if( fabs(age)>zero_age && id > 0 ) - return true; - //else return false; - - //if( ptype==ptype_dm ) - if( R_CHECK_BIT( ptype, RAMSES_DM_BIT ) ) - if( fabs(age)<=zero_age ) - return true; - //else return false; - - //if( ptype==ptype_debris ) - if( R_CHECK_BIT( ptype, RAMSES_DEBRIS_BIT ) ) - if( fabs(age) > zero_age && id == 0 ) - return true; - return false; -} - -#undef R_CHECK_BIT - -/**************************************************************************************\ -\**************************************************************************************/ - -inline std::string data::gen_fname( int icpu ) -{ - std::string fname; - char ext[32]; - fname = m_fname; - fname.erase(fname.rfind('.')+1); - sprintf(ext,"out%05d",icpu); - fname.append(std::string(ext)); - return fname; -} - -/**************************************************************************************\ -\**************************************************************************************/ - -inline void data::read_header( void ) -{ - FortranUnformatted ff( gen_fname(m_cpu) ); - - //-- read header data --// - ff.read( m_header.ncpu ); - ff.read( m_header.ndim ); - ff.read( m_header.npart ); - ff.read( std::back_inserter(m_header.localseed) ); - ff.read( m_header.nstar_tot ); - ff.read( m_header.mstar_tot ); - ff.read( m_header.mstar_lost ); - ff.read( m_header.nsink ); - -} - -/**************************************************************************************\ -\**************************************************************************************/ - -inline std::string data::rename_info2part( const std::string& info ) -{ - std::string amr; - unsigned ii = info.rfind("info"); - amr = info.substr(0,ii)+"part" + info.substr(ii+4, 6) + ".out00001"; - return amr; -} - -/**************************************************************************************\ -\**************************************************************************************/ - -/*! - * @class RAMSES::PART::multi_domain_data - * @brief encapsulates particle data from multiple computational domain - * - * This class provides high-level data access to bundled domain data, Bundling - * of domain data is useful when analysis of snapshots is performed in parallel - * but on a number of cores different than that used for the RAMSES simulation. - */ -template< typename TreeType_, typename ValueType_=double > -class multi_domain_data -{ - protected: - unsigned m_ndomains; //!< number of domains bundled - RAMSES::snapshot &m_rsnap; //!< reference to the underlying snapshot object - std::vector< std::vector > m_data; //!< vector of bundled data objects - std::vector m_ptrees; //!< vector of bundled tree objects - - public: - - //! constructor for bundled multi-domain particle data - /*! - * @param rsnap reference to the underlying snapshot object - * @param ptrees vector of trees to be bundled - */ - multi_domain_data( RAMSES::snapshot& rsnap, std::vector ptrees ) - : m_ndomains( ptrees.size() ), m_rsnap(rsnap), m_ptrees( ptrees ) - { } - - - //! access a particle in a specific domain - /*! - * @param idomain the domain ID - * @param ind the particle index - */ - ValueType_& operator() ( unsigned idomain, unsigned ind ) - { - return m_data[idomain][ind]; - } - - //! access the vector of particle of a specific domain - /*! - * @param idomain the domain ID - */ - std::vector& operator() ( unsigned idomain ) - { - return m_data[idomain]; - } - - //! bundled read functions, reads in multi-domain data - void get_var( std::string var_name ) - { - m_data.clear(); - for( unsigned idom=0; idomm_cpu ); - m_data.push_back( std::vector() ); - local_data.get_var(var_name, std::back_inserter(m_data.back()) ); - } - } - - //! get the pointer to the vector of particles of a specific domain - std::vector* get_vpointer( unsigned idomain ) - { - return &m_data[idomain]; - } - - //! TBD - unsigned size( void ){ return m_data.size(); } - - //! TBD - unsigned size( unsigned idom ) { return m_data.at(idom).size(); } -}; - - -}// namespace PARTICLE - -/**************************************************************************************\ -\**************************************************************************************/ - -namespace GEOM{ - -/**************************************************************************************\ -\**************************************************************************************/ - -//! TBD -class bounding_sphere{ - protected: - double - xc, //!< TBD - yc, //!< TBD - zc, //!< TBD - r, //!< TBD - r2; //!< TBD - - public: - //! TBD - bounding_sphere( double _xc, double _yc, double _zc, double _r ) - : xc(_xc), yc(_yc), zc(_zc), r(_r), r2(r*r) - { } - - //! TBD - inline bool operator()( double x, double y, double z ) - { - double dx(x-xc),dy(y-yc),dz(z-zc); - return dx*dx+dy*dy+dz*dz < r2; - } -}; - -/**************************************************************************************\ -\**************************************************************************************/ -//! TBD -class bounding_box{ - protected: - double - xc, //!< TBD - yc, //!< TBD - zc, //!< TBD - Lx, //!< TBD - Ly, //!< TBD - Lz, //!< TBD - Lx2, //!< TBD - Ly2, //!< TBD - Lz2; //!< TBD - public: - //! TBD - bounding_box( double _xc, double _yc, double _zc, double _Lx, double _Ly, double _Lz ) - : xc(_xc), yc(_yc), zc(_zc), Lx(_Lx), Ly(_Ly), Lz(_Lz), Lx2(0.5*Lx), Ly2(0.5*Ly), Lz2(0.5*Lz) - { } - - //! TBD - inline bool operator()( double x, double y, double z ) - { - double dx(x-xc),dy(y-yc),dz(z-zc); - return fabs(dx). -*/ - -#ifndef __RAMSES_POISSON_DATA_HH -#define __RAMSES_POISSON_DATA_HH - -#include -#include -#include -#include -#include - -#include "FortranUnformatted_IO.hh" -#include "RAMSES_info.hh" -#include "RAMSES_amr_data.hh" - -namespace RAMSES{ -namespace POISSON{ - - -/*! - * @class data - * @brief encapsulates hydro data from a RAMSES simulation snapshot - * - * This class provides low-level read access to RAMSES hydro_XXXXX.out files. - * Data from a given list of computational domains can be read and is - * stored in internal datastructures. - * Access to cell position and threaded tree structure of the cell is provided - * through the member functions of class RAMSES_amr_level. - * @sa RAMSES_amr_level - */ -template< typename TreeType_, typename Real_=double > -class data : public RAMSES::HYDRO::proto_data{ - -public: - - //! the poisson file header structure - struct header{ - unsigned ncpu; //!< number of CPUs in simulation - unsigned ndim; //!< number of spatial dimensions - unsigned nlevelmax; //!< maximum allowed refinement level - unsigned nboundary; //!< number of boundary regions - }; - - - std::string m_fname; //!< the file name - struct header m_header; //!< header meta data - -protected: - //! generates a poisson_XXXX filename for specified cpu - std::string gen_fname( int icpu ); - - //! generate poisson_XXXXX filename from info filename - std::string rename_info2poisson( const std::string& info ); - - //! generate poisson_XXXXX filename from amr filename - std::string rename_amr2poisson( const std::string& info ); - - //! read header data containing meta information - void read_header( void ); - - //! perform read operation of poisson variables (internal use) - /*! - * - */ - void read( void ); - -public: - - //! constructor for poisson solver gravity data - /*! - * @param AMRtree underlying AMR hierarchical tree data structure - */ - explicit data( TreeType_& AMRtree ) - : proto_data( AMRtree ), - m_fname( rename_amr2poisson(AMRtree.m_fname) ) - { - read_header(); - - if( this->m_cpu > m_header.ncpu || this->m_cpu < 1 ) - throw std::runtime_error("RAMSES::POISSON::data : expect to read from out of range CPU."); - - if( this->m_minlevel < 0 || this->m_maxlevel >= m_header.nlevelmax ) - throw std::runtime_error("RAMSES::POISSON::data : requested level is invalid."); - } - - //! access the value of the cells associated with the oct designated by the iterator - /*! - * @param it the grid iterator pointing to the current oct - * @param ind index of the child cell of the current oct (0..7) - * @param idir the cartesian direction of the force vector (0..2) - */ - inline ValueType_& cell_value( const typename TreeType_::iterator& it, int ind, int idir ) - { - unsigned ipos = it.get_absolute_position(); - unsigned ilevel = it.get_level();//-m_minlevel; - return (m_var_array[ilevel])[3*(m_twotondim*ipos+ind)+idir]; - } - - //! access the value of the cells associated with the oct designated by the iterator - /*! - * a call to this function will always fail since the poisson files contain only forces so far - * @param it the grid iterator pointing to the current oct - * @param ind index of the child cell of the current oct (0..7) - */ - inline ValueType_& cell_value( const typename TreeType_::iterator& it, int ind ) - { - throw std::runtime_error("You should not call this two variable cell_value(.,.) function for forces!"); - return (m_var_array[ilevel])[3*(m_twotondim*ipos+ind)]; - } - - //! access the value of the cells associated with the oct designated by the iterator - /*! - * @param it the grid iterator pointing to the current oct - * @param ind index of the child cell of the current oct (0..7) - * @param idir the cartesian direction of the force vector (0..2) - */ - inline ValueType_& operator()( const typename TreeType_::iterator& it, int ind, int idir ) - { return cell_value(it,ind,idir); } - -}; - - -template< typename TreeType_, typename Real_ > -void data::read_header( void ) -{ - FortranUnformatted ff( gen_fname( this->m_cpu ) ); - - //-- read header data --// - ff.read( m_header.ncpu ); - ff.read( m_header.ndim ); - ff.read( m_header.nlevelmax ); - ff.read( m_header.nboundary ); -} - - -template< typename TreeType_, typename Real_ > -void data::read( void ) -{ - this->m_var_array.clear(); - //int twotondim = (int)(pow(2,m_header.ndim)+0.5); - - FortranUnformatted ff( gen_fname( this->m_cpu ) ); - - //.. skip header entries ..// - ff.skip_n_from_start( 4 ); //.. skip header - - this->m_var_array.clear(); - - for( unsigned ilvl = 0; ilvl<=this->m_maxlevel; ++ilvl ){ - - this->m_var_array.push_back( std::vector() ); - - for( unsigned icpu = 0; icpu= this->m_minlevel ){ - if( file_ilevel != ilvl+1 ) - throw std::runtime_error("RAMSES::POISSON::data::read : corrupted file " \ - "or file seek failure in file \'"+m_fname+"\'."); - - - std::vector tmpx,tmpy,tmpz; - for( unsigned i=0; im_twotondim; ++i ) - { - ff.read( std::back_inserter(tmpx) ); //.. x-force - ff.read( std::back_inserter(tmpy) ); //.. y-force - ff.read( std::back_inserter(tmpz) ); //.. z-force - } - //.. reorder array to increase data locality..// - this->m_var_array.reserve( 3*tmpx.size() ); - for( unsigned i=0; im_twotondim; ++j ){ - //... interleave directional data ...// - (this->m_var_array.back()).push_back( tmpx[i+j*file_ncache] ); - (this->m_var_array.back()).push_back( tmpy[i+j*file_ncache] ); - (this->m_var_array.back()).push_back( tmpz[i+j*file_ncache] ); - } - } - }else{ - ff.skip_n( this->m_twotondim*3 ); - } - } - } -} - - -template< typename TreeType_, typename Real_ > -std::string data::gen_fname( int icpu ) -{ - std::string fname; - char ext[32]; - fname = m_fname; - fname.erase(fname.rfind('.')+1); - sprintf(ext,"out%05d",icpu); - fname.append(std::string(ext)); - return fname; -} - - -template< typename TreeType_, typename Real_ > -std::string data::rename_info2hydro( const std::string& info ) -{ - std::string amr; - unsigned ii = info.rfind("info"); - amr = info.substr(0,ii)+"poisson" + info.substr(ii+4, 6) + ".out00001"; - return amr; -} - - -template< typename TreeType_, typename Real_ > -std::string data::rename_amr2hydro( const std::string& info ) -{ - std::string amr; - unsigned ii = info.rfind("amr"); - amr = info.substr(0,ii)+"poisson" + info.substr(ii+3, 6) + ".out00001"; - return amr; -} - - -} // namespace POISSON -} // namespace RAMSES - - -#endif // .. __RAMSES_POISSON_DATA_HH diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/RAMSES_typedefs.h --- a/yt/ramses_headers/RAMSES_typedefs.h Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#include -#include -#include -#include -#include - -#include "RAMSES_amr_data.hh" -#include "RAMSES_hydro_data.hh" - -//... define the RAMSES base cell type to be of cell_locally_essential type -//... - this type allows moving between refinement levels -namespace RAMSES { - namespace AMR{ - typedef RAMSES::AMR::cell_locally_essential RAMSES_cell; - typedef RAMSES::AMR::level RAMSES_level; - typedef RAMSES::AMR::tree< RAMSES_cell, RAMSES::AMR::level< RAMSES_cell > > RAMSES_tree; - } - namespace HYDRO { - typedef RAMSES::HYDRO::data< RAMSES::AMR::RAMSES_tree > RAMSES_hydro_data; - } -} diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/README --- a/yt/ramses_headers/README Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -These are Header Files written by Oliver Hahn for reading RAMSES data. They do -not need to be installed, as they full contain the entire RamsesRead++ library. - -The library may also be downloaded independently from: - - http://www.exp-astro.phys.ethz.ch/hahn/RamsesTools/ - -Author: Oliver Hahn -Minor Modifications: Matthew Turk diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_headers/data_iterators.hh --- a/yt/ramses_headers/data_iterators.hh Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -#ifndef __DATA_ITERATORS_HH -#define __DATA_ITERATORS_HH - -#include -/*template -class conditional_iterator -: public _Container::iterator -{ - - -};*/ - -//! TBD -template -class conditional_back_insert_iterator -: public std::iterator -{ - protected: - _Container* container; //!< TBD - _InputIterator cond_iterator; //!< TBD - - public: - //! TBD - typedef _Container container_type; - - //! TBD - conditional_back_insert_iterator(_Container& __x,const _InputIterator& __i, int __prealloc=0) - : container(&__x), cond_iterator(__i) - { - if( __prealloc > 0 ) - __x.reserve( __x.size()+__prealloc); - } - - /*conditional_back_insert_iterator( const conditional_back_insert_iterator& __it ) - : container( __it.container ), cond_iterator( __it.cond_iterator ) - { }*/ - - //! TBD - conditional_back_insert_iterator& - operator=( typename _Container::const_reference __value ) - { - if( *cond_iterator ) - container->push_back(__value); - ++cond_iterator; - return *this; - } - - //! TBD - conditional_back_insert_iterator& - operator*() - { return *this; } - - //! TBD - conditional_back_insert_iterator& - operator++() - { return *this; } - - //! TBD - conditional_back_insert_iterator& - operator++(int) - { return *this; } -}; - - -//! TBD -template -inline conditional_back_insert_iterator<_Container, _InputIterator> -conditional_back_inserter(_Container& __x, const _InputIterator& __i, int __prealloc=0) -{ return conditional_back_insert_iterator<_Container,_InputIterator>(__x,__i,__prealloc); } - - - - -#endif diff -r 6c264cec3712aa6845fa3d5238d0dc5ba8d8fb86 -r ee593344cc89ff4da9614be57a24e9570cd5fe60 yt/ramses_reader.cpp --- a/yt/ramses_reader.cpp Mon Aug 30 10:02:07 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11701 +0,0 @@ -/* Generated by Cython 0.13.beta0 on Tue Aug 10 15:34:03 2010 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#else - -#include /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif - -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif - -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif - -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif - -#if PY_VERSION_HEX < 0x02040000 - #define METH_COEXIST 0 - #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) - #define PyDict_Contains(d,o) PySequence_Contains(d,o) -#endif - -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) PyInt_AsLong(o) - #define PyNumber_Index(o) PyNumber_Int(o) - #define PyIndex_Check(o) PyNumber_Check(o) - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - -#endif - -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" -#endif - -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif - -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif - -#ifndef PySet_CheckExact -# define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif - -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif - -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - -#ifdef __cplusplus -#define __PYX_EXTERN_C extern "C" -#else -#define __PYX_EXTERN_C extern -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include -#define __PYX_HAVE_API__yt__ramses_reader -#include "stdlib.h" -#include "stdio.h" -#include "numpy/arrayobject.h" -#include "numpy/ufuncobject.h" -#include -#include -#include "string" -#include "RAMSES_typedefs.h" -#include "RAMSES_info.hh" -#include "RAMSES_amr_data.hh" - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || defined(__INTEL_COMPILER) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) - - -#ifdef __GNUC__ -/* Test for GCC > 2.95 */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#else /* __GNUC__ > 2 ... */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -#if !defined(CYTHON_CCOMPLEX) - #if defined(__cplusplus) - #define CYTHON_CCOMPLEX 1 - #elif defined(_Complex_I) - #define CYTHON_CCOMPLEX 1 - #else - #define CYTHON_CCOMPLEX 0 - #endif -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #include - #else - #include - #endif -#endif - -#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__) - #undef _Complex_I - #define _Complex_I 1.0fj -#endif - -static const char *__pyx_f[] = { - "ramses_reader.pyx", - "numpy.pxd", -}; - -typedef npy_int8 __pyx_t_5numpy_int8_t; - -typedef npy_int16 __pyx_t_5numpy_int16_t; - -typedef npy_int32 __pyx_t_5numpy_int32_t; - -typedef npy_int64 __pyx_t_5numpy_int64_t; - -typedef npy_uint8 __pyx_t_5numpy_uint8_t; - -typedef npy_uint16 __pyx_t_5numpy_uint16_t; - -typedef npy_uint32 __pyx_t_5numpy_uint32_t; - -typedef npy_uint64 __pyx_t_5numpy_uint64_t; - -typedef npy_float32 __pyx_t_5numpy_float32_t; - -typedef npy_float64 __pyx_t_5numpy_float64_t; - -typedef npy_long __pyx_t_5numpy_int_t; - -typedef npy_longlong __pyx_t_5numpy_long_t; - -typedef npy_intp __pyx_t_5numpy_intp_t; - -typedef npy_uintp __pyx_t_5numpy_uintp_t; - -typedef npy_ulong __pyx_t_5numpy_uint_t; - -typedef npy_ulonglong __pyx_t_5numpy_ulong_t; - -typedef npy_double __pyx_t_5numpy_float_t; - -typedef npy_double __pyx_t_5numpy_double_t; - -typedef npy_longdouble __pyx_t_5numpy_longdouble_t; - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< float > __pyx_t_float_complex; - #else - typedef float _Complex __pyx_t_float_complex; - #endif -#else - typedef struct { float real, imag; } __pyx_t_float_complex; -#endif - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - typedef ::std::complex< double > __pyx_t_double_complex; - #else - typedef double _Complex __pyx_t_double_complex; - #endif -#else - typedef struct { double real, imag; } __pyx_t_double_complex; -#endif - -/* Type declarations */ - -typedef npy_cfloat __pyx_t_5numpy_cfloat_t; - -typedef npy_cdouble __pyx_t_5numpy_cdouble_t; - -typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; - -typedef npy_cdouble __pyx_t_5numpy_complex_t; - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":370 - * vector[vector[double]] m_var_array - * - * cdef class RAMSES_tree_proxy: # <<<<<<<<<<<<<< - * cdef string *snapshot_name - * cdef snapshot *rsnap - */ - -struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy { - PyObject_HEAD - std::string *snapshot_name; - RAMSES::snapshot *rsnap; - RAMSES::AMR::RAMSES_tree **trees; - RAMSES::HYDRO::RAMSES_hydro_data ***hydro_datas; - int *loaded; - PyObject *field_ind; - PyObject *field_names; - int ndomains; - int nfields; -}; - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":659 - * return to_fill - * - * cdef class ProtoSubgrid: # <<<<<<<<<<<<<< - * cdef np.int64_t *signature[3] - * cdef np.int64_t left_edge[3] - */ - -struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid { - PyObject_HEAD - __pyx_t_5numpy_int64_t *signature[3]; - __pyx_t_5numpy_int64_t left_edge[3]; - __pyx_t_5numpy_int64_t right_edge[3]; - __pyx_t_5numpy_int64_t dimensions[3]; - __pyx_t_5numpy_float64_t efficiency; - PyObject *sigs; - PyObject *grid_file_locations; - PyObject *dd; -}; - -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif - -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); - end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; - } - #define __Pyx_RefNannySetupContext(name) void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) - #define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0) -#else - #define __Pyx_RefNannySetupContext(name) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0) -#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, PyObject* kw_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ - -static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { - if (likely(PyList_CheckExact(L))) { - if (PyList_Append(L, x) < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; /* this is just to have an accurate signature */ - } - else { - PyObject *r, *m; - m = __Pyx_GetAttrString(L, "append"); - if (!m) return NULL; - r = PyObject_CallFunctionObjArgs(m, x, NULL); - Py_DECREF(m); - return r; - } -} - - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} - - -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - - -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { - PyObject *r; - if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { - r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - } - else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - } - else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) { - r = PySequence_GetItem(o, i); - } - else { - r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); - } - return r; -} - -#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_SetItemInt_Fast(o, i, v) : \ - __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) - -static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { - int r; - if (!j) return -1; - r = PyObject_SetItem(o, j, v); - Py_DECREF(j); - return r; -} - -static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { - if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { - Py_INCREF(v); - Py_DECREF(PyList_GET_ITEM(o, i)); - PyList_SET_ITEM(o, i, v); - return 1; - } - else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && (likely(i >= 0))) - return PySequence_SetItem(o, i, v); - else { - PyObject *j = PyInt_FromSsize_t(i); - return __Pyx_SetItemInt_Generic(o, j, v); - } -} - -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact); /*proto*/ - -/* Run-time type information about structs used with buffers */ -struct __Pyx_StructField_; - -typedef struct { - const char* name; /* for error messages only */ - struct __Pyx_StructField_* fields; - size_t size; /* sizeof(type) */ - char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject */ -} __Pyx_TypeInfo; - -typedef struct __Pyx_StructField_ { - __Pyx_TypeInfo* type; - const char* name; - size_t offset; -} __Pyx_StructField; - -typedef struct { - __Pyx_StructField* field; - size_t parent_offset; -} __Pyx_BufFmt_StackElem; - - -static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack); -static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info); -static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/ -#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1) - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ -#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0) - -static void __Pyx_RaiseBufferFallbackError(void); /*proto*/ - -static CYTHON_INLINE int __Pyx_div_int(int, int); /* proto */ - -#define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) -#define __Pyx_BufPtrStrided3d(type, buf, i0, s0, i1, s1, i2, s2) (type)((char*)buf + i0 * s0 + i1 * s1 + i2 * s2) - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __Pyx_div___pyx_t_5numpy_int64_t(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /* proto */ - -static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/ -#if PY_MAJOR_VERSION < 3 -static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags); -static void __Pyx_ReleaseBuffer(Py_buffer *view); -#else -#define __Pyx_GetBuffer PyObject_GetBuffer -#define __Pyx_ReleaseBuffer PyBuffer_Release -#endif - -Py_ssize_t __Pyx_zeros[] = {0, 0, 0}; -Py_ssize_t __Pyx_minusones[] = {-1, -1, -1}; - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ - -static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/ -#if PY_MAJOR_VERSION >= 3 -static PyObject* __pyx_print = 0; -static PyObject* __pyx_print_kwargs = 0; -#endif - -static CYTHON_INLINE long __Pyx_pow_long(long, long); /* proto */ - -static CYTHON_INLINE npy_int64 __Pyx_PyInt_from_py_npy_int64(PyObject *); - -static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_int64(npy_int64); - -#if CYTHON_CCOMPLEX - #ifdef __cplusplus - #define __Pyx_CREAL(z) ((z).real()) - #define __Pyx_CIMAG(z) ((z).imag()) - #else - #define __Pyx_CREAL(z) (__real__(z)) - #define __Pyx_CIMAG(z) (__imag__(z)) - #endif -#else - #define __Pyx_CREAL(z) ((z).real) - #define __Pyx_CIMAG(z) ((z).imag) -#endif - -#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX - #define __Pyx_SET_CREAL(z,x) ((z).real(x)) - #define __Pyx_SET_CIMAG(z,y) ((z).imag(y)) -#else - #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x) - #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y) -#endif - -static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float); - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eqf(a, b) ((a)==(b)) - #define __Pyx_c_sumf(a, b) ((a)+(b)) - #define __Pyx_c_difff(a, b) ((a)-(b)) - #define __Pyx_c_prodf(a, b) ((a)*(b)) - #define __Pyx_c_quotf(a, b) ((a)/(b)) - #define __Pyx_c_negf(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zerof(z) ((z)==(float)0) - #define __Pyx_c_conjf(z) (::std::conj(z)) - /*#define __Pyx_c_absf(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zerof(z) ((z)==0) - #define __Pyx_c_conjf(z) (conjf(z)) - /*#define __Pyx_c_absf(z) (cabsf(z))*/ - #endif -#else - static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex); - static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex); - static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex); - /*static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);*/ -#endif - -static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double); - -#if CYTHON_CCOMPLEX - #define __Pyx_c_eq(a, b) ((a)==(b)) - #define __Pyx_c_sum(a, b) ((a)+(b)) - #define __Pyx_c_diff(a, b) ((a)-(b)) - #define __Pyx_c_prod(a, b) ((a)*(b)) - #define __Pyx_c_quot(a, b) ((a)/(b)) - #define __Pyx_c_neg(a) (-(a)) - #ifdef __cplusplus - #define __Pyx_c_is_zero(z) ((z)==(double)0) - #define __Pyx_c_conj(z) (::std::conj(z)) - /*#define __Pyx_c_abs(z) (::std::abs(z))*/ - #else - #define __Pyx_c_is_zero(z) ((z)==0) - #define __Pyx_c_conj(z) (conj(z)) - /*#define __Pyx_c_abs(z) (cabs(z))*/ - #endif -#else - static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex); - static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex); - static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex); - /*static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);*/ -#endif - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict); /*proto*/ - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static void __Pyx_AddTraceback(const char *funcname); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ -/* Module declarations from libc.stdlib */ - -/* Module declarations from cpython.buffer */ - -/* Module declarations from cpython.ref */ - -/* Module declarations from libc.stdio */ - -/* Module declarations from cpython.object */ - -/* Module declarations from numpy */ - -/* Module declarations from numpy */ - -static PyTypeObject *__pyx_ptype_5numpy_dtype = 0; -static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0; -static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0; -static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0; -static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0; -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *, PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *, PyObject *, PyObject *, PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/ -static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *, PyObject *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *); /*proto*/ -/* Module declarations from cython */ - -/* Module declarations from yt.ramses_reader */ - -static PyTypeObject *__pyx_ptype_2yt_13ramses_reader_RAMSES_tree_proxy = 0; -static PyTypeObject *__pyx_ptype_2yt_13ramses_reader_ProtoSubgrid = 0; -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_13ramses_reader_i64max(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /*proto*/ -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_13ramses_reader_i64min(__pyx_t_5numpy_int64_t, __pyx_t_5numpy_int64_t); /*proto*/ -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t = { "float64_t", NULL, sizeof(__pyx_t_5numpy_float64_t), 'R' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t = { "int32_t", NULL, sizeof(__pyx_t_5numpy_int32_t), 'I' }; -static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t = { "int64_t", NULL, sizeof(__pyx_t_5numpy_int64_t), 'I' }; -#define __Pyx_MODULE_NAME "yt.ramses_reader" -int __pyx_module_is_main_yt__ramses_reader = 0; - -/* Implementation of yt.ramses_reader */ -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_RuntimeError; -static char __pyx_k_1[] = "READING FROM DISK"; -static char __pyx_k_2[] = "get_absolute_position"; -static char __pyx_k_3[] = "ndarray is not C contiguous"; -static char __pyx_k_4[] = "ndarray is not Fortran contiguous"; -static char __pyx_k_5[] = "Non-native byte order not supported"; -static char __pyx_k_6[] = "unknown dtype code in numpy.pxd (%d)"; -static char __pyx_k_7[] = "Format string allocated too short, see comment in numpy.pxd"; -static char __pyx_k_8[] = "Format string allocated too short."; -static char __pyx_k_9[] = "\nWrapping code for Oliver Hahn's RamsesRead++\n\nAuthor: Matthew Turk \nAffiliation: UCSD\nAuthor: Oliver Hahn \nAffiliation: KIPAC / Stanford\nHomepage: http://yt.enzotools.org/\nLicense:\n Copyright (C) 2010 Matthew Turk. All Rights Reserved.\n\n This file is part of yt.\n\n yt is free software; you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation; either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see .\n"; -static char __pyx_k__B[] = "B"; -static char __pyx_k__F[] = "F"; -static char __pyx_k__H[] = "H"; -static char __pyx_k__I[] = "I"; -static char __pyx_k__L[] = "L"; -static char __pyx_k__O[] = "O"; -static char __pyx_k__Q[] = "Q"; -static char __pyx_k__b[] = "b"; -static char __pyx_k__d[] = "d"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__g[] = "g"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__l[] = "l"; -static char __pyx_k__q[] = "q"; -static char __pyx_k__x[] = "x"; -static char __pyx_k__y[] = "y"; -static char __pyx_k__z[] = "z"; -static char __pyx_k__H0[] = "H0"; -static char __pyx_k__Zd[] = "Zd"; -static char __pyx_k__Zf[] = "Zf"; -static char __pyx_k__Zg[] = "Zg"; -static char __pyx_k__dd[] = "dd"; -static char __pyx_k__fn[] = "fn"; -static char __pyx_k__np[] = "np"; -static char __pyx_k__zc[] = "zc"; -static char __pyx_k__zs[] = "zs"; -static char __pyx_k__buf[] = "buf"; -static char __pyx_k__end[] = "end"; -static char __pyx_k__obj[] = "obj"; -static char __pyx_k__aexp[] = "aexp"; -static char __pyx_k__base[] = "base"; -static char __pyx_k__data[] = "data"; -static char __pyx_k__ncpu[] = "ncpu"; -static char __pyx_k__ndim[] = "ndim"; -static char __pyx_k__next[] = "next"; -static char __pyx_k__ones[] = "ones"; -static char __pyx_k__read[] = "read"; -static char __pyx_k__sigs[] = "sigs"; -static char __pyx_k__size[] = "size"; -static char __pyx_k__time[] = "time"; -static char __pyx_k__begin[] = "begin"; -static char __pyx_k__c_str[] = "c_str"; -static char __pyx_k__descr[] = "descr"; -static char __pyx_k__dtype[] = "dtype"; -static char __pyx_k__empty[] = "empty"; -static char __pyx_k__field[] = "field"; -static char __pyx_k__int64[] = "int64"; -static char __pyx_k__level[] = "level"; -static char __pyx_k__names[] = "names"; -static char __pyx_k__numpy[] = "numpy"; -static char __pyx_k__order[] = "order"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__rsnap[] = "rsnap"; -static char __pyx_k__shape[] = "shape"; -static char __pyx_k__trees[] = "trees"; -static char __pyx_k__zeros[] = "zeros"; -static char __pyx_k__boxlen[] = "boxlen"; -static char __pyx_k__domain[] = "domain"; -static char __pyx_k__fields[] = "fields"; -static char __pyx_k__filled[] = "filled"; -static char __pyx_k__format[] = "format"; -static char __pyx_k__loaded[] = "loaded"; -static char __pyx_k__unit_d[] = "unit_d"; -static char __pyx_k__unit_l[] = "unit_l"; -static char __pyx_k__unit_t[] = "unit_t"; -static char __pyx_k__argsort[] = "argsort"; -static char __pyx_k__float64[] = "float64"; -static char __pyx_k__grid_id[] = "grid_id"; -static char __pyx_k__m_nvars[] = "m_nvars"; -static char __pyx_k__nfields[] = "nfields"; -static char __pyx_k__omega_b[] = "omega_b"; -static char __pyx_k__omega_k[] = "omega_k"; -static char __pyx_k__omega_l[] = "omega_l"; -static char __pyx_k__omega_m[] = "omega_m"; -static char __pyx_k__strides[] = "strides"; -static char __pyx_k__varname[] = "varname"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__itemsize[] = "itemsize"; -static char __pyx_k__levelmax[] = "levelmax"; -static char __pyx_k__levelmin[] = "levelmin"; -static char __pyx_k__m_header[] = "m_header"; -static char __pyx_k__ndomains[] = "ndomains"; -static char __pyx_k__ngridmax[] = "ngridmax"; -static char __pyx_k__readonly[] = "readonly"; -static char __pyx_k__type_num[] = "type_num"; -static char __pyx_k__byteorder[] = "byteorder"; -static char __pyx_k__field_ind[] = "field_ind"; -static char __pyx_k__grid_dims[] = "grid_dims"; -static char __pyx_k__is_finest[] = "is_finest"; -static char __pyx_k__left_edge[] = "left_edge"; -static char __pyx_k__signature[] = "signature"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__child_mask[] = "child_mask"; -static char __pyx_k__dimensions[] = "dimensions"; -static char __pyx_k__efficiency[] = "efficiency"; -static char __pyx_k__get_parent[] = "get_parent"; -static char __pyx_k__left_edges[] = "left_edges"; -static char __pyx_k__left_index[] = "left_index"; -static char __pyx_k__m_maxlevel[] = "m_maxlevel"; -static char __pyx_k__m_varnames[] = "m_varnames"; -static char __pyx_k__ref_factor[] = "ref_factor"; -static char __pyx_k__right_edge[] = "right_edge"; -static char __pyx_k__suboffsets[] = "suboffsets"; -static char __pyx_k__field_names[] = "field_names"; -static char __pyx_k__grid_levels[] = "grid_levels"; -static char __pyx_k__hydro_datas[] = "hydro_datas"; -static char __pyx_k__m_var_array[] = "m_var_array"; -static char __pyx_k__right_edges[] = "right_edges"; -static char __pyx_k__start_index[] = "start_index"; -static char __pyx_k__RuntimeError[] = "RuntimeError"; -static char __pyx_k__domain_index[] = "domain_index"; -static char __pyx_k__m_AMR_levels[] = "m_AMR_levels"; -static char __pyx_k__nstep_coarse[] = "nstep_coarse"; -static char __pyx_k__ensure_loaded[] = "ensure_loaded"; -static char __pyx_k__snapshot_name[] = "snapshot_name"; -static char __pyx_k__grid_dimensions[] = "grid_dimensions"; -static char __pyx_k__grid_pos_double[] = "grid_pos_double"; -static char __pyx_k__component_grid_info[] = "component_grid_info"; -static char __pyx_k__grid_file_locations[] = "grid_file_locations"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_n_s_2; -static PyObject *__pyx_kp_u_3; -static PyObject *__pyx_kp_u_4; -static PyObject *__pyx_kp_u_5; -static PyObject *__pyx_kp_u_6; -static PyObject *__pyx_kp_u_7; -static PyObject *__pyx_kp_u_8; -static PyObject *__pyx_n_s__F; -static PyObject *__pyx_n_s__H0; -static PyObject *__pyx_n_s__RuntimeError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__aexp; -static PyObject *__pyx_n_s__argsort; -static PyObject *__pyx_n_s__base; -static PyObject *__pyx_n_s__begin; -static PyObject *__pyx_n_s__boxlen; -static PyObject *__pyx_n_s__buf; -static PyObject *__pyx_n_s__byteorder; -static PyObject *__pyx_n_s__c_str; -static PyObject *__pyx_n_s__child_mask; -static PyObject *__pyx_n_s__component_grid_info; -static PyObject *__pyx_n_s__data; -static PyObject *__pyx_n_s__dd; -static PyObject *__pyx_n_s__descr; -static PyObject *__pyx_n_s__dimensions; -static PyObject *__pyx_n_s__domain; -static PyObject *__pyx_n_s__domain_index; -static PyObject *__pyx_n_s__dtype; -static PyObject *__pyx_n_s__efficiency; -static PyObject *__pyx_n_s__empty; -static PyObject *__pyx_n_s__end; -static PyObject *__pyx_n_s__ensure_loaded; -static PyObject *__pyx_n_s__field; -static PyObject *__pyx_n_s__field_ind; -static PyObject *__pyx_n_s__field_names; -static PyObject *__pyx_n_s__fields; -static PyObject *__pyx_n_s__filled; -static PyObject *__pyx_n_s__float64; -static PyObject *__pyx_n_s__fn; -static PyObject *__pyx_n_s__format; -static PyObject *__pyx_n_s__get_parent; -static PyObject *__pyx_n_s__grid_dimensions; -static PyObject *__pyx_n_s__grid_dims; -static PyObject *__pyx_n_s__grid_file_locations; -static PyObject *__pyx_n_s__grid_id; -static PyObject *__pyx_n_s__grid_levels; -static PyObject *__pyx_n_s__grid_pos_double; -static PyObject *__pyx_n_s__hydro_datas; -static PyObject *__pyx_n_s__int64; -static PyObject *__pyx_n_s__is_finest; -static PyObject *__pyx_n_s__itemsize; -static PyObject *__pyx_n_s__left_edge; -static PyObject *__pyx_n_s__left_edges; -static PyObject *__pyx_n_s__left_index; -static PyObject *__pyx_n_s__level; -static PyObject *__pyx_n_s__levelmax; -static PyObject *__pyx_n_s__levelmin; -static PyObject *__pyx_n_s__loaded; -static PyObject *__pyx_n_s__m_AMR_levels; -static PyObject *__pyx_n_s__m_header; -static PyObject *__pyx_n_s__m_maxlevel; -static PyObject *__pyx_n_s__m_nvars; -static PyObject *__pyx_n_s__m_var_array; -static PyObject *__pyx_n_s__m_varnames; -static PyObject *__pyx_n_s__names; -static PyObject *__pyx_n_s__ncpu; -static PyObject *__pyx_n_s__ndim; -static PyObject *__pyx_n_s__ndomains; -static PyObject *__pyx_n_s__next; -static PyObject *__pyx_n_s__nfields; -static PyObject *__pyx_n_s__ngridmax; -static PyObject *__pyx_n_s__np; -static PyObject *__pyx_n_s__nstep_coarse; -static PyObject *__pyx_n_s__numpy; -static PyObject *__pyx_n_s__obj; -static PyObject *__pyx_n_s__omega_b; -static PyObject *__pyx_n_s__omega_k; -static PyObject *__pyx_n_s__omega_l; -static PyObject *__pyx_n_s__omega_m; -static PyObject *__pyx_n_s__ones; -static PyObject *__pyx_n_s__order; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__read; -static PyObject *__pyx_n_s__readonly; -static PyObject *__pyx_n_s__ref_factor; -static PyObject *__pyx_n_s__right_edge; -static PyObject *__pyx_n_s__right_edges; -static PyObject *__pyx_n_s__rsnap; -static PyObject *__pyx_n_s__shape; -static PyObject *__pyx_n_s__signature; -static PyObject *__pyx_n_s__sigs; -static PyObject *__pyx_n_s__size; -static PyObject *__pyx_n_s__snapshot_name; -static PyObject *__pyx_n_s__start_index; -static PyObject *__pyx_n_s__strides; -static PyObject *__pyx_n_s__suboffsets; -static PyObject *__pyx_n_s__time; -static PyObject *__pyx_n_s__trees; -static PyObject *__pyx_n_s__type_num; -static PyObject *__pyx_n_s__unit_d; -static PyObject *__pyx_n_s__unit_l; -static PyObject *__pyx_n_s__unit_t; -static PyObject *__pyx_n_s__varname; -static PyObject *__pyx_n_s__x; -static PyObject *__pyx_n_s__y; -static PyObject *__pyx_n_s__z; -static PyObject *__pyx_n_s__zc; -static PyObject *__pyx_n_s__zeros; -static PyObject *__pyx_n_s__zs; -static PyObject *__pyx_int_0; -static PyObject *__pyx_int_2; -static PyObject *__pyx_int_3; -static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_int_15; - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":36 - * cimport cython - * - * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): # <<<<<<<<<<<<<< - * if i0 > i1: return i0 - * return i1 - */ - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_13ramses_reader_i64max(__pyx_t_5numpy_int64_t __pyx_v_i0, __pyx_t_5numpy_int64_t __pyx_v_i1) { - __pyx_t_5numpy_int64_t __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("i64max"); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":37 - * - * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): - * if i0 > i1: return i0 # <<<<<<<<<<<<<< - * return i1 - * - */ - __pyx_t_1 = (__pyx_v_i0 > __pyx_v_i1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_i0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":38 - * cdef inline np.int64_t i64max(np.int64_t i0, np.int64_t i1): - * if i0 > i1: return i0 - * return i1 # <<<<<<<<<<<<<< - * - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - */ - __pyx_r = __pyx_v_i1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":40 - * return i1 - * - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): # <<<<<<<<<<<<<< - * if i0 < i1: return i0 - * return i1 - */ - -static CYTHON_INLINE __pyx_t_5numpy_int64_t __pyx_f_2yt_13ramses_reader_i64min(__pyx_t_5numpy_int64_t __pyx_v_i0, __pyx_t_5numpy_int64_t __pyx_v_i1) { - __pyx_t_5numpy_int64_t __pyx_r; - int __pyx_t_1; - __Pyx_RefNannySetupContext("i64min"); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":41 - * - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - * if i0 < i1: return i0 # <<<<<<<<<<<<<< - * return i1 - * - */ - __pyx_t_1 = (__pyx_v_i0 < __pyx_v_i1); - if (__pyx_t_1) { - __pyx_r = __pyx_v_i0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":42 - * cdef inline np.int64_t i64min(np.int64_t i0, np.int64_t i1): - * if i0 < i1: return i0 - * return i1 # <<<<<<<<<<<<<< - * - * cdef extern from "" namespace "std": - */ - __pyx_r = __pyx_v_i1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":379 - * cdef int *loaded - * - * cdef public object field_ind # <<<<<<<<<<<<<< - * cdef public object field_names - * - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_9field_ind___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_9field_ind___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - __pyx_r = ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_9field_ind___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_9field_ind___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_9field_ind___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_9field_ind___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":380 - * - * cdef public object field_ind - * cdef public object field_names # <<<<<<<<<<<<<< - * - * # We will store this here so that we have a record, independent of the - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_11field_names___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_11field_names___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - __pyx_r = ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_11field_names___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_11field_names___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_11field_names___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_11field_names___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":386 - * cdef int ndomains, nfields - * - * def __cinit__(self, char *fn): # <<<<<<<<<<<<<< - * cdef int idomain, ifield, ii - * cdef RAMSES_tree *local_tree - */ - -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_fn; - int __pyx_v_idomain; - int __pyx_v_ifield; - int __pyx_v_ii; - RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; - RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; - std::string *__pyx_v_field_name; - int __pyx_r; - long __pyx_t_1; - int __pyx_t_2; - unsigned int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fn,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[1] = {0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fn); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_fn = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_fn) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_fn = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_fn) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":390 - * cdef RAMSES_tree *local_tree - * cdef RAMSES_hydro_data *local_hydro_data - * self.snapshot_name = new string(fn) # <<<<<<<<<<<<<< - * self.rsnap = new snapshot(deref(self.snapshot_name), version3) - * # We now have to get our field names to fill our array - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name = new std::string(__pyx_v_fn); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":391 - * cdef RAMSES_hydro_data *local_hydro_data - * self.snapshot_name = new string(fn) - * self.rsnap = new snapshot(deref(self.snapshot_name), version3) # <<<<<<<<<<<<<< - * # We now have to get our field names to fill our array - * self.trees = \ - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap = new RAMSES::snapshot((*((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name), RAMSES::version3); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":393 - * self.rsnap = new snapshot(deref(self.snapshot_name), version3) - * # We now have to get our field names to fill our array - * self.trees = \ # <<<<<<<<<<<<<< - * malloc(sizeof(RAMSES_tree*) * self.rsnap.m_header.ncpu) - * self.hydro_datas = \ - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees = ((RAMSES::AMR::RAMSES_tree **)malloc(((sizeof(RAMSES::AMR::RAMSES_tree *)) * ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":395 - * self.trees = \ - * malloc(sizeof(RAMSES_tree*) * self.rsnap.m_header.ncpu) - * self.hydro_datas = \ # <<<<<<<<<<<<<< - * malloc(sizeof(RAMSES_hydro_data**) * self.rsnap.m_header.ncpu) - * self.ndomains = self.rsnap.m_header.ncpu - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas = ((RAMSES::HYDRO::RAMSES_hydro_data ***)malloc(((sizeof(RAMSES::HYDRO::RAMSES_hydro_data **)) * ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":397 - * self.hydro_datas = \ - * malloc(sizeof(RAMSES_hydro_data**) * self.rsnap.m_header.ncpu) - * self.ndomains = self.rsnap.m_header.ncpu # <<<<<<<<<<<<<< - * #for ii in range(self.ndomains): self.trees[ii] = NULL - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->ndomains = ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":399 - * self.ndomains = self.rsnap.m_header.ncpu - * #for ii in range(self.ndomains): self.trees[ii] = NULL - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): # <<<<<<<<<<<<<< - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) - */ - __pyx_t_1 = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu + 1); - for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_idomain = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":401 - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) # <<<<<<<<<<<<<< - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - */ - __pyx_v_local_tree = new RAMSES::AMR::RAMSES_tree((*((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap), __pyx_v_idomain, ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax, 0); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":402 - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) - * local_tree.read() # <<<<<<<<<<<<<< - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * self.hydro_datas[idomain - 1] = \ - */ - __pyx_v_local_tree->read(); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":403 - * self.rsnap.m_header.levelmax, 0) - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) # <<<<<<<<<<<<<< - * self.hydro_datas[idomain - 1] = \ - * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) - */ - __pyx_v_local_hydro_data = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":404 - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * self.hydro_datas[idomain - 1] = \ # <<<<<<<<<<<<<< - * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) - * del local_hydro_data - */ - (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_idomain - 1)]) = ((RAMSES::HYDRO::RAMSES_hydro_data **)malloc(((sizeof(RAMSES::HYDRO::RAMSES_hydro_data *)) * __pyx_v_local_hydro_data->m_nvars))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":406 - * self.hydro_datas[idomain - 1] = \ - * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) - * del local_hydro_data # <<<<<<<<<<<<<< - * for ii in range(local_hydro_data.m_nvars): - * self.hydro_datas[idomain - 1][ii] = \ - */ - delete __pyx_v_local_hydro_data; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":407 - * malloc(sizeof(RAMSES_hydro_data*) * local_hydro_data.m_nvars) - * del local_hydro_data - * for ii in range(local_hydro_data.m_nvars): # <<<<<<<<<<<<<< - * self.hydro_datas[idomain - 1][ii] = \ - * new RAMSES_hydro_data(deref(local_tree)) - */ - __pyx_t_3 = __pyx_v_local_hydro_data->m_nvars; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_ii = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":408 - * del local_hydro_data - * for ii in range(local_hydro_data.m_nvars): - * self.hydro_datas[idomain - 1][ii] = \ # <<<<<<<<<<<<<< - * new RAMSES_hydro_data(deref(local_tree)) - * self.trees[idomain - 1] = local_tree - */ - ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_idomain - 1)])[__pyx_v_ii]) = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":410 - * self.hydro_datas[idomain - 1][ii] = \ - * new RAMSES_hydro_data(deref(local_tree)) - * self.trees[idomain - 1] = local_tree # <<<<<<<<<<<<<< - * # We do not delete anything - * # Only once, we read all the field names - */ - (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[(__pyx_v_idomain - 1)]) = __pyx_v_local_tree; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":413 - * # We do not delete anything - * # Only once, we read all the field names - * self.nfields = local_hydro_data.m_nvars # <<<<<<<<<<<<<< - * cdef string *field_name - * self.field_names = [] - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->nfields = __pyx_v_local_hydro_data->m_nvars; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":415 - * self.nfields = local_hydro_data.m_nvars - * cdef string *field_name - * self.field_names = [] # <<<<<<<<<<<<<< - * self.field_ind = {} - * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) - */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names); - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names = ((PyObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":416 - * cdef string *field_name - * self.field_names = [] - * self.field_ind = {} # <<<<<<<<<<<<<< - * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) - * for ifield in range(local_hydro_data.m_nvars): - */ - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind); - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind = ((PyObject *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":417 - * self.field_names = [] - * self.field_ind = {} - * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) # <<<<<<<<<<<<<< - * for ifield in range(local_hydro_data.m_nvars): - * field_name = &(local_hydro_data.m_varnames[ifield]) - */ - ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded = ((int *)malloc(((sizeof(int)) * __pyx_v_local_hydro_data->m_nvars))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":418 - * self.field_ind = {} - * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) - * for ifield in range(local_hydro_data.m_nvars): # <<<<<<<<<<<<<< - * field_name = &(local_hydro_data.m_varnames[ifield]) - * # Does this leak? - */ - __pyx_t_3 = __pyx_v_local_hydro_data->m_nvars; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_3; __pyx_t_2+=1) { - __pyx_v_ifield = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":419 - * self.loaded = malloc(sizeof(int) * local_hydro_data.m_nvars) - * for ifield in range(local_hydro_data.m_nvars): - * field_name = &(local_hydro_data.m_varnames[ifield]) # <<<<<<<<<<<<<< - * # Does this leak? - * self.field_names.append(field_name.c_str()) - */ - __pyx_v_field_name = (&(__pyx_v_local_hydro_data->m_varnames[__pyx_v_ifield])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":421 - * field_name = &(local_hydro_data.m_varnames[ifield]) - * # Does this leak? - * self.field_names.append(field_name.c_str()) # <<<<<<<<<<<<<< - * self.field_ind[self.field_names[-1]] = ifield - * self.loaded[ifield] = 0 - */ - __pyx_t_5 = PyBytes_FromString(__pyx_v_field_name->c_str()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names, ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":422 - * # Does this leak? - * self.field_names.append(field_name.c_str()) - * self.field_ind[self.field_names[-1]] = ifield # <<<<<<<<<<<<<< - * self.loaded[ifield] = 0 - * # This all needs to be cleaned up in the deallocator - */ - __pyx_t_6 = PyInt_FromLong(__pyx_v_ifield); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_names, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - if (PyObject_SetItem(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, __pyx_t_5, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":423 - * self.field_names.append(field_name.c_str()) - * self.field_ind[self.field_names[-1]] = ifield - * self.loaded[ifield] = 0 # <<<<<<<<<<<<<< - * # This all needs to be cleaned up in the deallocator - * - */ - (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_ifield]) = 0; - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.__cinit__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":426 - * # This all needs to be cleaned up in the deallocator - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * cdef int idomain, ifield - * for idomain in range(self.ndomains): - */ - -static void __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy___dealloc__(PyObject *__pyx_v_self) { - int __pyx_v_idomain; - int __pyx_v_ifield; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - __Pyx_RefNannySetupContext("__dealloc__"); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":428 - * def __dealloc__(self): - * cdef int idomain, ifield - * for idomain in range(self.ndomains): # <<<<<<<<<<<<<< - * for ifield in range(self.nfields): - * if self.hydro_datas[idomain][ifield] != NULL: - */ - __pyx_t_1 = ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->ndomains; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_idomain = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":429 - * cdef int idomain, ifield - * for idomain in range(self.ndomains): - * for ifield in range(self.nfields): # <<<<<<<<<<<<<< - * if self.hydro_datas[idomain][ifield] != NULL: - * del self.hydro_datas[idomain][ifield] - */ - __pyx_t_3 = ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->nfields; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_ifield = __pyx_t_4; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":430 - * for idomain in range(self.ndomains): - * for ifield in range(self.nfields): - * if self.hydro_datas[idomain][ifield] != NULL: # <<<<<<<<<<<<<< - * del self.hydro_datas[idomain][ifield] - * if self.trees[idomain] != NULL: - */ - __pyx_t_5 = (((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_idomain])[__pyx_v_ifield]) != NULL); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":431 - * for ifield in range(self.nfields): - * if self.hydro_datas[idomain][ifield] != NULL: - * del self.hydro_datas[idomain][ifield] # <<<<<<<<<<<<<< - * if self.trees[idomain] != NULL: - * del self.trees[idomain] - */ - delete ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_idomain])[__pyx_v_ifield]); - goto __pyx_L9; - } - __pyx_L9:; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":432 - * if self.hydro_datas[idomain][ifield] != NULL: - * del self.hydro_datas[idomain][ifield] - * if self.trees[idomain] != NULL: # <<<<<<<<<<<<<< - * del self.trees[idomain] - * free(self.hydro_datas[idomain]) - */ - __pyx_t_5 = ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[__pyx_v_idomain]) != NULL); - if (__pyx_t_5) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":433 - * del self.hydro_datas[idomain][ifield] - * if self.trees[idomain] != NULL: - * del self.trees[idomain] # <<<<<<<<<<<<<< - * free(self.hydro_datas[idomain]) - * free(self.trees) - */ - delete (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[__pyx_v_idomain]); - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":434 - * if self.trees[idomain] != NULL: - * del self.trees[idomain] - * free(self.hydro_datas[idomain]) # <<<<<<<<<<<<<< - * free(self.trees) - * free(self.hydro_datas) - */ - free((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_idomain])); - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":435 - * del self.trees[idomain] - * free(self.hydro_datas[idomain]) - * free(self.trees) # <<<<<<<<<<<<<< - * free(self.hydro_datas) - * free(self.loaded) - */ - free(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":436 - * free(self.hydro_datas[idomain]) - * free(self.trees) - * free(self.hydro_datas) # <<<<<<<<<<<<<< - * free(self.loaded) - * if self.snapshot_name != NULL: del self.snapshot_name - */ - free(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":437 - * free(self.trees) - * free(self.hydro_datas) - * free(self.loaded) # <<<<<<<<<<<<<< - * if self.snapshot_name != NULL: del self.snapshot_name - * if self.rsnap != NULL: del self.rsnap - */ - free(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":438 - * free(self.hydro_datas) - * free(self.loaded) - * if self.snapshot_name != NULL: del self.snapshot_name # <<<<<<<<<<<<<< - * if self.rsnap != NULL: del self.rsnap - * - */ - __pyx_t_5 = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name != NULL); - if (__pyx_t_5) { - delete ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->snapshot_name; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":439 - * free(self.loaded) - * if self.snapshot_name != NULL: del self.snapshot_name - * if self.rsnap != NULL: del self.rsnap # <<<<<<<<<<<<<< - * - * def count_zones(self): - */ - __pyx_t_5 = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap != NULL); - if (__pyx_t_5) { - delete ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap; - goto __pyx_L12; - } - __pyx_L12:; - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":441 - * if self.rsnap != NULL: del self.rsnap - * - * def count_zones(self): # <<<<<<<<<<<<<< - * # We need to do simulation domains here - * - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_count_zones(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_count_zones(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - unsigned int __pyx_v_idomain; - unsigned int __pyx_v_ilevel; - RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; - RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; - RAMSES::AMR::RAMSES_level *__pyx_v_local_level; - PyObject *__pyx_v_cell_count; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - long __pyx_t_2; - unsigned int __pyx_t_3; - int __pyx_t_4; - long __pyx_t_5; - unsigned int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - __Pyx_RefNannySetupContext("count_zones"); - __pyx_v_cell_count = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":451 - * # All the loop-local pointers must be declared up here - * - * cell_count = [] # <<<<<<<<<<<<<< - * for ilevel in range(self.rsnap.m_header.levelmax + 1): - * cell_count.append(0) - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_cell_count)); - __pyx_v_cell_count = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":452 - * - * cell_count = [] - * for ilevel in range(self.rsnap.m_header.levelmax + 1): # <<<<<<<<<<<<<< - * cell_count.append(0) - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - */ - __pyx_t_2 = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax + 1); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_ilevel = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":453 - * cell_count = [] - * for ilevel in range(self.rsnap.m_header.levelmax + 1): - * cell_count.append(0) # <<<<<<<<<<<<<< - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - */ - if (unlikely(__pyx_v_cell_count == Py_None)) { - PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = PyList_Append(((PyObject *)__pyx_v_cell_count), __pyx_int_0); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":454 - * for ilevel in range(self.rsnap.m_header.levelmax + 1): - * cell_count.append(0) - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): # <<<<<<<<<<<<<< - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) - */ - __pyx_t_2 = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu + 1); - for (__pyx_t_3 = 1; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_idomain = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":456 - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) # <<<<<<<<<<<<<< - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - */ - __pyx_v_local_tree = new RAMSES::AMR::RAMSES_tree((*((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap), __pyx_v_idomain, ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax, 0); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":457 - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) - * local_tree.read() # <<<<<<<<<<<<<< - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * for ilevel in range(local_tree.m_maxlevel + 1): - */ - __pyx_v_local_tree->read(); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":458 - * self.rsnap.m_header.levelmax, 0) - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) # <<<<<<<<<<<<<< - * for ilevel in range(local_tree.m_maxlevel + 1): - * local_level = &local_tree.m_AMR_levels[ilevel] - */ - __pyx_v_local_hydro_data = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":459 - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * for ilevel in range(local_tree.m_maxlevel + 1): # <<<<<<<<<<<<<< - * local_level = &local_tree.m_AMR_levels[ilevel] - * cell_count[ilevel] += local_level.size() - */ - __pyx_t_5 = (__pyx_v_local_tree->m_maxlevel + 1); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_ilevel = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":460 - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * for ilevel in range(local_tree.m_maxlevel + 1): - * local_level = &local_tree.m_AMR_levels[ilevel] # <<<<<<<<<<<<<< - * cell_count[ilevel] += local_level.size() - * del local_tree, local_hydro_data - */ - __pyx_v_local_level = (&(__pyx_v_local_tree->m_AMR_levels[__pyx_v_ilevel])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":461 - * for ilevel in range(local_tree.m_maxlevel + 1): - * local_level = &local_tree.m_AMR_levels[ilevel] - * cell_count[ilevel] += local_level.size() # <<<<<<<<<<<<<< - * del local_tree, local_hydro_data - * - */ - __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_local_level->size()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_cell_count), __pyx_v_ilevel, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_cell_count), __pyx_v_ilevel, __pyx_t_8, sizeof(unsigned int)+1, PyLong_FromUnsignedLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":462 - * local_level = &local_tree.m_AMR_levels[ilevel] - * cell_count[ilevel] += local_level.size() - * del local_tree, local_hydro_data # <<<<<<<<<<<<<< - * - * return cell_count - */ - delete __pyx_v_local_tree; - delete __pyx_v_local_hydro_data; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":464 - * del local_tree, local_hydro_data - * - * return cell_count # <<<<<<<<<<<<<< - * - * def ensure_loaded(self, char *varname, int domain_index): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_cell_count)); - __pyx_r = ((PyObject *)__pyx_v_cell_count); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.count_zones"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_cell_count); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":466 - * return cell_count - * - * def ensure_loaded(self, char *varname, int domain_index): # <<<<<<<<<<<<<< - * # this domain_index must be zero-indexed - * cdef int varindex = self.field_ind[varname] - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_ensure_loaded(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_ensure_loaded(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_varname; - int __pyx_v_domain_index; - int __pyx_v_varindex; - std::string *__pyx_v_field_name; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__varname,&__pyx_n_s__domain_index,0}; - __Pyx_RefNannySetupContext("ensure_loaded"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__varname); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__domain_index); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("ensure_loaded", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "ensure_loaded") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_varname = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_domain_index = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_varname = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_domain_index = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("ensure_loaded", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.ensure_loaded"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":468 - * def ensure_loaded(self, char *varname, int domain_index): - * # this domain_index must be zero-indexed - * cdef int varindex = self.field_ind[varname] # <<<<<<<<<<<<<< - * cdef string *field_name = new string(varname) - * if self.loaded[varindex] == 1: return - */ - __pyx_t_1 = PyBytes_FromString(__pyx_v_varname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_varindex = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":469 - * # this domain_index must be zero-indexed - * cdef int varindex = self.field_ind[varname] - * cdef string *field_name = new string(varname) # <<<<<<<<<<<<<< - * if self.loaded[varindex] == 1: return - * print "READING FROM DISK", varname - */ - __pyx_v_field_name = new std::string(__pyx_v_varname); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":470 - * cdef int varindex = self.field_ind[varname] - * cdef string *field_name = new string(varname) - * if self.loaded[varindex] == 1: return # <<<<<<<<<<<<<< - * print "READING FROM DISK", varname - * self.hydro_datas[domain_index][varindex].read(deref(field_name)) - */ - __pyx_t_4 = ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_varindex]) == 1); - if (__pyx_t_4) { - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":471 - * cdef string *field_name = new string(varname) - * if self.loaded[varindex] == 1: return - * print "READING FROM DISK", varname # <<<<<<<<<<<<<< - * self.hydro_datas[domain_index][varindex].read(deref(field_name)) - * self.loaded[varindex] = 1 - */ - __pyx_t_2 = PyBytes_FromString(__pyx_v_varname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - if (__Pyx_Print(0, __pyx_t_1, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":472 - * if self.loaded[varindex] == 1: return - * print "READING FROM DISK", varname - * self.hydro_datas[domain_index][varindex].read(deref(field_name)) # <<<<<<<<<<<<<< - * self.loaded[varindex] = 1 - * del field_name - */ - ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_domain_index])[__pyx_v_varindex])->read((*__pyx_v_field_name)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":473 - * print "READING FROM DISK", varname - * self.hydro_datas[domain_index][varindex].read(deref(field_name)) - * self.loaded[varindex] = 1 # <<<<<<<<<<<<<< - * del field_name - * - */ - (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_varindex]) = 1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":474 - * self.hydro_datas[domain_index][varindex].read(deref(field_name)) - * self.loaded[varindex] = 1 - * del field_name # <<<<<<<<<<<<<< - * - * def clear_tree(self, char *varname, int domain_index): - */ - delete __pyx_v_field_name; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.ensure_loaded"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":476 - * del field_name - * - * def clear_tree(self, char *varname, int domain_index): # <<<<<<<<<<<<<< - * # this domain_index must be zero-indexed - * # We delete and re-create - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_clear_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_clear_tree(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_varname; - int __pyx_v_domain_index; - int __pyx_v_varindex; - std::string *__pyx_v_field_name; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__varname,&__pyx_n_s__domain_index,0}; - __Pyx_RefNannySetupContext("clear_tree"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__varname); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__domain_index); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("clear_tree", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "clear_tree") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_varname = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_domain_index = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_varname = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_varname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_domain_index = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_domain_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("clear_tree", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.clear_tree"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":479 - * # this domain_index must be zero-indexed - * # We delete and re-create - * cdef int varindex = self.field_ind[varname] # <<<<<<<<<<<<<< - * cdef string *field_name = new string(varname) - * if self.loaded[varindex] == 0: return - */ - __pyx_t_1 = PyBytes_FromString(__pyx_v_varname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_varindex = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":480 - * # We delete and re-create - * cdef int varindex = self.field_ind[varname] - * cdef string *field_name = new string(varname) # <<<<<<<<<<<<<< - * if self.loaded[varindex] == 0: return - * del self.hydro_datas[domain_index][varindex] - */ - __pyx_v_field_name = new std::string(__pyx_v_varname); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":481 - * cdef int varindex = self.field_ind[varname] - * cdef string *field_name = new string(varname) - * if self.loaded[varindex] == 0: return # <<<<<<<<<<<<<< - * del self.hydro_datas[domain_index][varindex] - * self.hydro_datas[domain_index - 1][varindex] = \ - */ - __pyx_t_4 = ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_varindex]) == 0); - if (__pyx_t_4) { - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":482 - * cdef string *field_name = new string(varname) - * if self.loaded[varindex] == 0: return - * del self.hydro_datas[domain_index][varindex] # <<<<<<<<<<<<<< - * self.hydro_datas[domain_index - 1][varindex] = \ - * new RAMSES_hydro_data(deref(self.trees[domain_index])) - */ - delete ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[__pyx_v_domain_index])[__pyx_v_varindex]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":483 - * if self.loaded[varindex] == 0: return - * del self.hydro_datas[domain_index][varindex] - * self.hydro_datas[domain_index - 1][varindex] = \ # <<<<<<<<<<<<<< - * new RAMSES_hydro_data(deref(self.trees[domain_index])) - * self.loaded[varindex] = 0 - */ - ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_domain_index - 1)])[__pyx_v_varindex]) = new RAMSES::HYDRO::RAMSES_hydro_data((*(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[__pyx_v_domain_index]))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":485 - * self.hydro_datas[domain_index - 1][varindex] = \ - * new RAMSES_hydro_data(deref(self.trees[domain_index])) - * self.loaded[varindex] = 0 # <<<<<<<<<<<<<< - * del field_name - * - */ - (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->loaded[__pyx_v_varindex]) = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":486 - * new RAMSES_hydro_data(deref(self.trees[domain_index])) - * self.loaded[varindex] = 0 - * del field_name # <<<<<<<<<<<<<< - * - * def get_file_info(self): - */ - delete __pyx_v_field_name; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.clear_tree"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":488 - * del field_name - * - * def get_file_info(self): # <<<<<<<<<<<<<< - * header_info = {} - * header_info["ncpu"] = self.rsnap.m_header.ncpu - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_get_file_info(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_get_file_info(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_v_header_info; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("get_file_info"); - __pyx_v_header_info = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":489 - * - * def get_file_info(self): - * header_info = {} # <<<<<<<<<<<<<< - * header_info["ncpu"] = self.rsnap.m_header.ncpu - * header_info["ndim"] = self.rsnap.m_header.ndim - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_header_info)); - __pyx_v_header_info = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":490 - * def get_file_info(self): - * header_info = {} - * header_info["ncpu"] = self.rsnap.m_header.ncpu # <<<<<<<<<<<<<< - * header_info["ndim"] = self.rsnap.m_header.ndim - * header_info["levelmin"] = self.rsnap.m_header.levelmin - */ - __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__ncpu), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":491 - * header_info = {} - * header_info["ncpu"] = self.rsnap.m_header.ncpu - * header_info["ndim"] = self.rsnap.m_header.ndim # <<<<<<<<<<<<<< - * header_info["levelmin"] = self.rsnap.m_header.levelmin - * header_info["levelmax"] = self.rsnap.m_header.levelmax - */ - __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ndim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__ndim), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 491; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":492 - * header_info["ncpu"] = self.rsnap.m_header.ncpu - * header_info["ndim"] = self.rsnap.m_header.ndim - * header_info["levelmin"] = self.rsnap.m_header.levelmin # <<<<<<<<<<<<<< - * header_info["levelmax"] = self.rsnap.m_header.levelmax - * header_info["ngridmax"] = self.rsnap.m_header.ngridmax - */ - __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__levelmin), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":493 - * header_info["ndim"] = self.rsnap.m_header.ndim - * header_info["levelmin"] = self.rsnap.m_header.levelmin - * header_info["levelmax"] = self.rsnap.m_header.levelmax # <<<<<<<<<<<<<< - * header_info["ngridmax"] = self.rsnap.m_header.ngridmax - * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse - */ - __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__levelmax), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":494 - * header_info["levelmin"] = self.rsnap.m_header.levelmin - * header_info["levelmax"] = self.rsnap.m_header.levelmax - * header_info["ngridmax"] = self.rsnap.m_header.ngridmax # <<<<<<<<<<<<<< - * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse - * header_info["boxlen"] = self.rsnap.m_header.boxlen - */ - __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ngridmax); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__ngridmax), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 494; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":495 - * header_info["levelmax"] = self.rsnap.m_header.levelmax - * header_info["ngridmax"] = self.rsnap.m_header.ngridmax - * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse # <<<<<<<<<<<<<< - * header_info["boxlen"] = self.rsnap.m_header.boxlen - * header_info["time"] = self.rsnap.m_header.time - */ - __pyx_t_1 = PyLong_FromUnsignedLong(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.nstep_coarse); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__nstep_coarse), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 495; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":496 - * header_info["ngridmax"] = self.rsnap.m_header.ngridmax - * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse - * header_info["boxlen"] = self.rsnap.m_header.boxlen # <<<<<<<<<<<<<< - * header_info["time"] = self.rsnap.m_header.time - * header_info["aexp"] = self.rsnap.m_header.aexp - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.boxlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__boxlen), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":497 - * header_info["nstep_coarse"] = self.rsnap.m_header.nstep_coarse - * header_info["boxlen"] = self.rsnap.m_header.boxlen - * header_info["time"] = self.rsnap.m_header.time # <<<<<<<<<<<<<< - * header_info["aexp"] = self.rsnap.m_header.aexp - * header_info["H0"] = self.rsnap.m_header.H0 - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.time); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__time), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 497; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":498 - * header_info["boxlen"] = self.rsnap.m_header.boxlen - * header_info["time"] = self.rsnap.m_header.time - * header_info["aexp"] = self.rsnap.m_header.aexp # <<<<<<<<<<<<<< - * header_info["H0"] = self.rsnap.m_header.H0 - * header_info["omega_m"] = self.rsnap.m_header.omega_m - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.aexp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__aexp), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":499 - * header_info["time"] = self.rsnap.m_header.time - * header_info["aexp"] = self.rsnap.m_header.aexp - * header_info["H0"] = self.rsnap.m_header.H0 # <<<<<<<<<<<<<< - * header_info["omega_m"] = self.rsnap.m_header.omega_m - * header_info["omega_l"] = self.rsnap.m_header.omega_l - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.H0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__H0), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":500 - * header_info["aexp"] = self.rsnap.m_header.aexp - * header_info["H0"] = self.rsnap.m_header.H0 - * header_info["omega_m"] = self.rsnap.m_header.omega_m # <<<<<<<<<<<<<< - * header_info["omega_l"] = self.rsnap.m_header.omega_l - * header_info["omega_k"] = self.rsnap.m_header.omega_k - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_m); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_m), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":501 - * header_info["H0"] = self.rsnap.m_header.H0 - * header_info["omega_m"] = self.rsnap.m_header.omega_m - * header_info["omega_l"] = self.rsnap.m_header.omega_l # <<<<<<<<<<<<<< - * header_info["omega_k"] = self.rsnap.m_header.omega_k - * header_info["omega_b"] = self.rsnap.m_header.omega_b - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_l), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":502 - * header_info["omega_m"] = self.rsnap.m_header.omega_m - * header_info["omega_l"] = self.rsnap.m_header.omega_l - * header_info["omega_k"] = self.rsnap.m_header.omega_k # <<<<<<<<<<<<<< - * header_info["omega_b"] = self.rsnap.m_header.omega_b - * header_info["unit_l"] = self.rsnap.m_header.unit_l - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_k), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":503 - * header_info["omega_l"] = self.rsnap.m_header.omega_l - * header_info["omega_k"] = self.rsnap.m_header.omega_k - * header_info["omega_b"] = self.rsnap.m_header.omega_b # <<<<<<<<<<<<<< - * header_info["unit_l"] = self.rsnap.m_header.unit_l - * header_info["unit_d"] = self.rsnap.m_header.unit_d - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.omega_b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__omega_b), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 503; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":504 - * header_info["omega_k"] = self.rsnap.m_header.omega_k - * header_info["omega_b"] = self.rsnap.m_header.omega_b - * header_info["unit_l"] = self.rsnap.m_header.unit_l # <<<<<<<<<<<<<< - * header_info["unit_d"] = self.rsnap.m_header.unit_d - * header_info["unit_t"] = self.rsnap.m_header.unit_t - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.unit_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__unit_l), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":505 - * header_info["omega_b"] = self.rsnap.m_header.omega_b - * header_info["unit_l"] = self.rsnap.m_header.unit_l - * header_info["unit_d"] = self.rsnap.m_header.unit_d # <<<<<<<<<<<<<< - * header_info["unit_t"] = self.rsnap.m_header.unit_t - * return header_info - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.unit_d); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__unit_d), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":506 - * header_info["unit_l"] = self.rsnap.m_header.unit_l - * header_info["unit_d"] = self.rsnap.m_header.unit_d - * header_info["unit_t"] = self.rsnap.m_header.unit_t # <<<<<<<<<<<<<< - * return header_info - * - */ - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.unit_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(((PyObject *)__pyx_v_header_info), ((PyObject *)__pyx_n_s__unit_t), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":507 - * header_info["unit_d"] = self.rsnap.m_header.unit_d - * header_info["unit_t"] = self.rsnap.m_header.unit_t - * return header_info # <<<<<<<<<<<<<< - * - * def fill_hierarchy_arrays(self, - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_header_info)); - __pyx_r = ((PyObject *)__pyx_v_header_info); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.get_file_info"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_header_info); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":509 - * return header_info - * - * def fill_hierarchy_arrays(self, # <<<<<<<<<<<<<< - * np.ndarray[np.float64_t, ndim=2] left_edges, - * np.ndarray[np.float64_t, ndim=2] right_edges, - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_fill_hierarchy_arrays(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_fill_hierarchy_arrays(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_left_edges = 0; - PyArrayObject *__pyx_v_right_edges = 0; - PyArrayObject *__pyx_v_grid_levels = 0; - PyArrayObject *__pyx_v_grid_file_locations = 0; - PyArrayObject *__pyx_v_child_mask = 0; - unsigned int __pyx_v_idomain; - unsigned int __pyx_v_ilevel; - RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; - RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; - RAMSES::AMR::RAMSES_tree::iterator __pyx_v_grid_it; - RAMSES::AMR::RAMSES_tree::iterator __pyx_v_grid_end; - RAMSES::AMR::RAMSES_tree::iterator __pyx_v_father_it; - RAMSES::AMR::vec __pyx_v_gvec; - int __pyx_v_grid_ind; - unsigned int __pyx_v_parent_ind; - int __pyx_v_ci; - double __pyx_v_grid_half_width; - __pyx_t_5numpy_int32_t __pyx_v_rr; - PyObject *__pyx_v_cell_count; - PyObject *__pyx_v_level_cell_counts; - Py_buffer __pyx_bstruct_right_edges; - Py_ssize_t __pyx_bstride_0_right_edges = 0; - Py_ssize_t __pyx_bstride_1_right_edges = 0; - Py_ssize_t __pyx_bshape_0_right_edges = 0; - Py_ssize_t __pyx_bshape_1_right_edges = 0; - Py_buffer __pyx_bstruct_grid_levels; - Py_ssize_t __pyx_bstride_0_grid_levels = 0; - Py_ssize_t __pyx_bstride_1_grid_levels = 0; - Py_ssize_t __pyx_bshape_0_grid_levels = 0; - Py_ssize_t __pyx_bshape_1_grid_levels = 0; - Py_buffer __pyx_bstruct_grid_file_locations; - Py_ssize_t __pyx_bstride_0_grid_file_locations = 0; - Py_ssize_t __pyx_bstride_1_grid_file_locations = 0; - Py_ssize_t __pyx_bshape_0_grid_file_locations = 0; - Py_ssize_t __pyx_bshape_1_grid_file_locations = 0; - Py_buffer __pyx_bstruct_child_mask; - Py_ssize_t __pyx_bstride_0_child_mask = 0; - Py_ssize_t __pyx_bstride_1_child_mask = 0; - Py_ssize_t __pyx_bshape_0_child_mask = 0; - Py_ssize_t __pyx_bshape_1_child_mask = 0; - Py_buffer __pyx_bstruct_left_edges; - Py_ssize_t __pyx_bstride_0_left_edges = 0; - Py_ssize_t __pyx_bstride_1_left_edges = 0; - Py_ssize_t __pyx_bshape_0_left_edges = 0; - Py_ssize_t __pyx_bshape_1_left_edges = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - long __pyx_t_2; - unsigned int __pyx_t_3; - long __pyx_t_4; - unsigned int __pyx_t_5; - long __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - long __pyx_t_10; - int __pyx_t_11; - long __pyx_t_12; - int __pyx_t_13; - long __pyx_t_14; - int __pyx_t_15; - long __pyx_t_16; - int __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - long __pyx_t_20; - int __pyx_t_21; - long __pyx_t_22; - int __pyx_t_23; - PyObject *__pyx_t_24 = NULL; - PyObject *__pyx_t_25 = NULL; - __pyx_t_5numpy_int64_t __pyx_t_26; - long __pyx_t_27; - int __pyx_t_28; - long __pyx_t_29; - int __pyx_t_30; - long __pyx_t_31; - int __pyx_t_32; - int __pyx_t_33; - int __pyx_t_34; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__left_edges,&__pyx_n_s__right_edges,&__pyx_n_s__grid_levels,&__pyx_n_s__grid_file_locations,&__pyx_n_s__child_mask,0}; - __Pyx_RefNannySetupContext("fill_hierarchy_arrays"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[5] = {0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edges); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edges); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_levels); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_file_locations); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_mask); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "fill_hierarchy_arrays") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_left_edges = ((PyArrayObject *)values[0]); - __pyx_v_right_edges = ((PyArrayObject *)values[1]); - __pyx_v_grid_levels = ((PyArrayObject *)values[2]); - __pyx_v_grid_file_locations = ((PyArrayObject *)values[3]); - __pyx_v_child_mask = ((PyArrayObject *)values[4]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_left_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_right_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_grid_levels = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_grid_file_locations = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_child_mask = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fill_hierarchy_arrays", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.fill_hierarchy_arrays"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_cell_count = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_level_cell_counts = ((PyObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_left_edges.buf = NULL; - __pyx_bstruct_right_edges.buf = NULL; - __pyx_bstruct_grid_levels.buf = NULL; - __pyx_bstruct_grid_file_locations.buf = NULL; - __pyx_bstruct_child_mask.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edges), __pyx_ptype_5numpy_ndarray, 1, "left_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edges), __pyx_ptype_5numpy_ndarray, 1, "right_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_levels), __pyx_ptype_5numpy_ndarray, 1, "grid_levels", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_file_locations), __pyx_ptype_5numpy_ndarray, 1, "grid_file_locations", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_mask), __pyx_ptype_5numpy_ndarray, 1, "child_mask", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edges, (PyObject*)__pyx_v_left_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edges = __pyx_bstruct_left_edges.strides[0]; __pyx_bstride_1_left_edges = __pyx_bstruct_left_edges.strides[1]; - __pyx_bshape_0_left_edges = __pyx_bstruct_left_edges.shape[0]; __pyx_bshape_1_left_edges = __pyx_bstruct_left_edges.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edges, (PyObject*)__pyx_v_right_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edges = __pyx_bstruct_right_edges.strides[0]; __pyx_bstride_1_right_edges = __pyx_bstruct_right_edges.strides[1]; - __pyx_bshape_0_right_edges = __pyx_bstruct_right_edges.shape[0]; __pyx_bshape_1_right_edges = __pyx_bstruct_right_edges.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_levels, (PyObject*)__pyx_v_grid_levels, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_levels = __pyx_bstruct_grid_levels.strides[0]; __pyx_bstride_1_grid_levels = __pyx_bstruct_grid_levels.strides[1]; - __pyx_bshape_0_grid_levels = __pyx_bstruct_grid_levels.shape[0]; __pyx_bshape_1_grid_levels = __pyx_bstruct_grid_levels.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_file_locations, (PyObject*)__pyx_v_grid_file_locations, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[0]; __pyx_bstride_1_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[1]; - __pyx_bshape_0_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[0]; __pyx_bshape_1_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_child_mask, (PyObject*)__pyx_v_child_mask, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 509; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_child_mask = __pyx_bstruct_child_mask.strides[0]; __pyx_bstride_1_child_mask = __pyx_bstruct_child_mask.strides[1]; - __pyx_bshape_0_child_mask = __pyx_bstruct_child_mask.shape[0]; __pyx_bshape_1_child_mask = __pyx_bstruct_child_mask.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":526 - * cdef tree_iterator grid_it, grid_end, father_it - * cdef vec[double] gvec - * cdef int grid_ind = 0 # <<<<<<<<<<<<<< - * cdef unsigned parent_ind - * cdef bint ci - */ - __pyx_v_grid_ind = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":533 - * - * cdef np.int32_t rr - * cell_count = [] # <<<<<<<<<<<<<< - * level_cell_counts = {} - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_cell_count)); - __pyx_v_cell_count = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":534 - * cdef np.int32_t rr - * cell_count = [] - * level_cell_counts = {} # <<<<<<<<<<<<<< - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_v_level_cell_counts)); - __pyx_v_level_cell_counts = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":535 - * cell_count = [] - * level_cell_counts = {} - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): # <<<<<<<<<<<<<< - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) - */ - __pyx_t_2 = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.ncpu + 1); - for (__pyx_t_3 = 1; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_idomain = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":537 - * for idomain in range(1, self.rsnap.m_header.ncpu + 1): - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) # <<<<<<<<<<<<<< - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - */ - __pyx_v_local_tree = new RAMSES::AMR::RAMSES_tree((*((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap), __pyx_v_idomain, ((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.levelmax, 0); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":538 - * local_tree = new RAMSES_tree(deref(self.rsnap), idomain, - * self.rsnap.m_header.levelmax, 0) - * local_tree.read() # <<<<<<<<<<<<<< - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * for ilevel in range(local_tree.m_maxlevel + 1): - */ - __pyx_v_local_tree->read(); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":539 - * self.rsnap.m_header.levelmax, 0) - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) # <<<<<<<<<<<<<< - * for ilevel in range(local_tree.m_maxlevel + 1): - * # this gets overwritten for every domain, which is okay - */ - __pyx_v_local_hydro_data = new RAMSES::HYDRO::RAMSES_hydro_data((*__pyx_v_local_tree)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":540 - * local_tree.read() - * local_hydro_data = new RAMSES_hydro_data(deref(local_tree)) - * for ilevel in range(local_tree.m_maxlevel + 1): # <<<<<<<<<<<<<< - * # this gets overwritten for every domain, which is okay - * level_cell_counts[ilevel] = grid_ind - */ - __pyx_t_4 = (__pyx_v_local_tree->m_maxlevel + 1); - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_ilevel = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":542 - * for ilevel in range(local_tree.m_maxlevel + 1): - * # this gets overwritten for every domain, which is okay - * level_cell_counts[ilevel] = grid_ind # <<<<<<<<<<<<<< - * grid_half_width = self.rsnap.m_header.boxlen / (2**(ilevel + 1)) - * grid_it = local_tree.begin(ilevel) - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_grid_ind); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_level_cell_counts), __pyx_v_ilevel, __pyx_t_1, sizeof(unsigned int)+1, PyLong_FromUnsignedLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 542; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":543 - * # this gets overwritten for every domain, which is okay - * level_cell_counts[ilevel] = grid_ind - * grid_half_width = self.rsnap.m_header.boxlen / (2**(ilevel + 1)) # <<<<<<<<<<<<<< - * grid_it = local_tree.begin(ilevel) - * grid_end = local_tree.end(ilevel) - */ - __pyx_t_6 = __Pyx_pow_long(2, (__pyx_v_ilevel + 1)); - if (unlikely(__pyx_t_6 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_grid_half_width = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->rsnap->m_header.boxlen / __pyx_t_6); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":544 - * level_cell_counts[ilevel] = grid_ind - * grid_half_width = self.rsnap.m_header.boxlen / (2**(ilevel + 1)) - * grid_it = local_tree.begin(ilevel) # <<<<<<<<<<<<<< - * grid_end = local_tree.end(ilevel) - * while grid_it != grid_end: - */ - __pyx_v_grid_it = __pyx_v_local_tree->begin(__pyx_v_ilevel); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":545 - * grid_half_width = self.rsnap.m_header.boxlen / (2**(ilevel + 1)) - * grid_it = local_tree.begin(ilevel) - * grid_end = local_tree.end(ilevel) # <<<<<<<<<<<<<< - * while grid_it != grid_end: - * gvec = local_tree.grid_pos_double(grid_it) - */ - __pyx_v_grid_end = __pyx_v_local_tree->end(__pyx_v_ilevel); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":546 - * grid_it = local_tree.begin(ilevel) - * grid_end = local_tree.end(ilevel) - * while grid_it != grid_end: # <<<<<<<<<<<<<< - * gvec = local_tree.grid_pos_double(grid_it) - * left_edges[grid_ind, 0] = gvec.x - grid_half_width - */ - while (1) { - __pyx_t_7 = (__pyx_v_grid_it != __pyx_v_grid_end); - if (!__pyx_t_7) break; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":547 - * grid_end = local_tree.end(ilevel) - * while grid_it != grid_end: - * gvec = local_tree.grid_pos_double(grid_it) # <<<<<<<<<<<<<< - * left_edges[grid_ind, 0] = gvec.x - grid_half_width - * left_edges[grid_ind, 1] = gvec.y - grid_half_width - */ - __pyx_v_gvec = __pyx_v_local_tree->grid_pos(__pyx_v_grid_it); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":548 - * while grid_it != grid_end: - * gvec = local_tree.grid_pos_double(grid_it) - * left_edges[grid_ind, 0] = gvec.x - grid_half_width # <<<<<<<<<<<<<< - * left_edges[grid_ind, 1] = gvec.y - grid_half_width - * left_edges[grid_ind, 2] = gvec.z - grid_half_width - */ - __pyx_t_8 = __pyx_v_grid_ind; - __pyx_t_6 = 0; - __pyx_t_9 = -1; - if (__pyx_t_8 < 0) { - __pyx_t_8 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 0; - } else if (unlikely(__pyx_t_8 >= __pyx_bshape_0_left_edges)) __pyx_t_9 = 0; - if (__pyx_t_6 < 0) { - __pyx_t_6 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_6 < 0)) __pyx_t_9 = 1; - } else if (unlikely(__pyx_t_6 >= __pyx_bshape_1_left_edges)) __pyx_t_9 = 1; - if (unlikely(__pyx_t_9 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_9); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_8, __pyx_bstride_0_left_edges, __pyx_t_6, __pyx_bstride_1_left_edges) = (__pyx_v_gvec.x - __pyx_v_grid_half_width); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":549 - * gvec = local_tree.grid_pos_double(grid_it) - * left_edges[grid_ind, 0] = gvec.x - grid_half_width - * left_edges[grid_ind, 1] = gvec.y - grid_half_width # <<<<<<<<<<<<<< - * left_edges[grid_ind, 2] = gvec.z - grid_half_width - * right_edges[grid_ind, 0] = gvec.x + grid_half_width - */ - __pyx_t_9 = __pyx_v_grid_ind; - __pyx_t_10 = 1; - __pyx_t_11 = -1; - if (__pyx_t_9 < 0) { - __pyx_t_9 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_9 < 0)) __pyx_t_11 = 0; - } else if (unlikely(__pyx_t_9 >= __pyx_bshape_0_left_edges)) __pyx_t_11 = 0; - if (__pyx_t_10 < 0) { - __pyx_t_10 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_10 < 0)) __pyx_t_11 = 1; - } else if (unlikely(__pyx_t_10 >= __pyx_bshape_1_left_edges)) __pyx_t_11 = 1; - if (unlikely(__pyx_t_11 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_11); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 549; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_9, __pyx_bstride_0_left_edges, __pyx_t_10, __pyx_bstride_1_left_edges) = (__pyx_v_gvec.y - __pyx_v_grid_half_width); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":550 - * left_edges[grid_ind, 0] = gvec.x - grid_half_width - * left_edges[grid_ind, 1] = gvec.y - grid_half_width - * left_edges[grid_ind, 2] = gvec.z - grid_half_width # <<<<<<<<<<<<<< - * right_edges[grid_ind, 0] = gvec.x + grid_half_width - * right_edges[grid_ind, 1] = gvec.y + grid_half_width - */ - __pyx_t_11 = __pyx_v_grid_ind; - __pyx_t_12 = 2; - __pyx_t_13 = -1; - if (__pyx_t_11 < 0) { - __pyx_t_11 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_11 < 0)) __pyx_t_13 = 0; - } else if (unlikely(__pyx_t_11 >= __pyx_bshape_0_left_edges)) __pyx_t_13 = 0; - if (__pyx_t_12 < 0) { - __pyx_t_12 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_12 < 0)) __pyx_t_13 = 1; - } else if (unlikely(__pyx_t_12 >= __pyx_bshape_1_left_edges)) __pyx_t_13 = 1; - if (unlikely(__pyx_t_13 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_13); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_11, __pyx_bstride_0_left_edges, __pyx_t_12, __pyx_bstride_1_left_edges) = (__pyx_v_gvec.z - __pyx_v_grid_half_width); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":551 - * left_edges[grid_ind, 1] = gvec.y - grid_half_width - * left_edges[grid_ind, 2] = gvec.z - grid_half_width - * right_edges[grid_ind, 0] = gvec.x + grid_half_width # <<<<<<<<<<<<<< - * right_edges[grid_ind, 1] = gvec.y + grid_half_width - * right_edges[grid_ind, 2] = gvec.z + grid_half_width - */ - __pyx_t_13 = __pyx_v_grid_ind; - __pyx_t_14 = 0; - __pyx_t_15 = -1; - if (__pyx_t_13 < 0) { - __pyx_t_13 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_13 < 0)) __pyx_t_15 = 0; - } else if (unlikely(__pyx_t_13 >= __pyx_bshape_0_right_edges)) __pyx_t_15 = 0; - if (__pyx_t_14 < 0) { - __pyx_t_14 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_14 < 0)) __pyx_t_15 = 1; - } else if (unlikely(__pyx_t_14 >= __pyx_bshape_1_right_edges)) __pyx_t_15 = 1; - if (unlikely(__pyx_t_15 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_15); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_13, __pyx_bstride_0_right_edges, __pyx_t_14, __pyx_bstride_1_right_edges) = (__pyx_v_gvec.x + __pyx_v_grid_half_width); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":552 - * left_edges[grid_ind, 2] = gvec.z - grid_half_width - * right_edges[grid_ind, 0] = gvec.x + grid_half_width - * right_edges[grid_ind, 1] = gvec.y + grid_half_width # <<<<<<<<<<<<<< - * right_edges[grid_ind, 2] = gvec.z + grid_half_width - * grid_levels[grid_ind, 0] = ilevel - */ - __pyx_t_15 = __pyx_v_grid_ind; - __pyx_t_16 = 1; - __pyx_t_17 = -1; - if (__pyx_t_15 < 0) { - __pyx_t_15 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_15 < 0)) __pyx_t_17 = 0; - } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_right_edges)) __pyx_t_17 = 0; - if (__pyx_t_16 < 0) { - __pyx_t_16 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_16 < 0)) __pyx_t_17 = 1; - } else if (unlikely(__pyx_t_16 >= __pyx_bshape_1_right_edges)) __pyx_t_17 = 1; - if (unlikely(__pyx_t_17 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_17); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_15, __pyx_bstride_0_right_edges, __pyx_t_16, __pyx_bstride_1_right_edges) = (__pyx_v_gvec.y + __pyx_v_grid_half_width); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":553 - * right_edges[grid_ind, 0] = gvec.x + grid_half_width - * right_edges[grid_ind, 1] = gvec.y + grid_half_width - * right_edges[grid_ind, 2] = gvec.z + grid_half_width # <<<<<<<<<<<<<< - * grid_levels[grid_ind, 0] = ilevel - * # Now the harder part - */ - __pyx_t_17 = __pyx_v_grid_ind; - __pyx_t_18 = 2; - __pyx_t_19 = -1; - if (__pyx_t_17 < 0) { - __pyx_t_17 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_17 < 0)) __pyx_t_19 = 0; - } else if (unlikely(__pyx_t_17 >= __pyx_bshape_0_right_edges)) __pyx_t_19 = 0; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 1; - } else if (unlikely(__pyx_t_18 >= __pyx_bshape_1_right_edges)) __pyx_t_19 = 1; - if (unlikely(__pyx_t_19 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_19); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_17, __pyx_bstride_0_right_edges, __pyx_t_18, __pyx_bstride_1_right_edges) = (__pyx_v_gvec.z + __pyx_v_grid_half_width); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":554 - * right_edges[grid_ind, 1] = gvec.y + grid_half_width - * right_edges[grid_ind, 2] = gvec.z + grid_half_width - * grid_levels[grid_ind, 0] = ilevel # <<<<<<<<<<<<<< - * # Now the harder part - * father_it = grid_it.get_parent() - */ - __pyx_t_19 = __pyx_v_grid_ind; - __pyx_t_20 = 0; - __pyx_t_21 = -1; - if (__pyx_t_19 < 0) { - __pyx_t_19 += __pyx_bshape_0_grid_levels; - if (unlikely(__pyx_t_19 < 0)) __pyx_t_21 = 0; - } else if (unlikely(__pyx_t_19 >= __pyx_bshape_0_grid_levels)) __pyx_t_21 = 0; - if (__pyx_t_20 < 0) { - __pyx_t_20 += __pyx_bshape_1_grid_levels; - if (unlikely(__pyx_t_20 < 0)) __pyx_t_21 = 1; - } else if (unlikely(__pyx_t_20 >= __pyx_bshape_1_grid_levels)) __pyx_t_21 = 1; - if (unlikely(__pyx_t_21 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_21); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_grid_levels.buf, __pyx_t_19, __pyx_bstride_0_grid_levels, __pyx_t_20, __pyx_bstride_1_grid_levels) = __pyx_v_ilevel; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":556 - * grid_levels[grid_ind, 0] = ilevel - * # Now the harder part - * father_it = grid_it.get_parent() # <<<<<<<<<<<<<< - * grid_file_locations[grid_ind, 0] = idomain - * grid_file_locations[grid_ind, 1] = grid_ind - level_cell_counts[ilevel] - */ - __pyx_v_father_it = __pyx_v_grid_it.get_parent(); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":557 - * # Now the harder part - * father_it = grid_it.get_parent() - * grid_file_locations[grid_ind, 0] = idomain # <<<<<<<<<<<<<< - * grid_file_locations[grid_ind, 1] = grid_ind - level_cell_counts[ilevel] - * parent_ind = father_it.get_absolute_position() - */ - __pyx_t_21 = __pyx_v_grid_ind; - __pyx_t_22 = 0; - __pyx_t_23 = -1; - if (__pyx_t_21 < 0) { - __pyx_t_21 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_21 < 0)) __pyx_t_23 = 0; - } else if (unlikely(__pyx_t_21 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_23 = 0; - if (__pyx_t_22 < 0) { - __pyx_t_22 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_22 < 0)) __pyx_t_23 = 1; - } else if (unlikely(__pyx_t_22 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_23 = 1; - if (unlikely(__pyx_t_23 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_23); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_21, __pyx_bstride_0_grid_file_locations, __pyx_t_22, __pyx_bstride_1_grid_file_locations) = ((__pyx_t_5numpy_int64_t)__pyx_v_idomain); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":558 - * father_it = grid_it.get_parent() - * grid_file_locations[grid_ind, 0] = idomain - * grid_file_locations[grid_ind, 1] = grid_ind - level_cell_counts[ilevel] # <<<<<<<<<<<<<< - * parent_ind = father_it.get_absolute_position() - * if ilevel > 0: - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_grid_ind); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_24 = __Pyx_GetItemInt(((PyObject *)__pyx_v_level_cell_counts), __pyx_v_ilevel, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_24) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_24); - __pyx_t_25 = PyNumber_Subtract(__pyx_t_1, __pyx_t_24); if (unlikely(!__pyx_t_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_25); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_26 = __Pyx_PyInt_from_py_npy_int64(__pyx_t_25); if (unlikely((__pyx_t_26 == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; - __pyx_t_23 = __pyx_v_grid_ind; - __pyx_t_27 = 1; - __pyx_t_28 = -1; - if (__pyx_t_23 < 0) { - __pyx_t_23 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_23 < 0)) __pyx_t_28 = 0; - } else if (unlikely(__pyx_t_23 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_28 = 0; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_28 = 1; - } else if (unlikely(__pyx_t_27 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_28 = 1; - if (unlikely(__pyx_t_28 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_28); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_23, __pyx_bstride_0_grid_file_locations, __pyx_t_27, __pyx_bstride_1_grid_file_locations) = __pyx_t_26; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":559 - * grid_file_locations[grid_ind, 0] = idomain - * grid_file_locations[grid_ind, 1] = grid_ind - level_cell_counts[ilevel] - * parent_ind = father_it.get_absolute_position() # <<<<<<<<<<<<<< - * if ilevel > 0: - * # We calculate the REAL parent index - */ - __pyx_v_parent_ind = __pyx_v_father_it.get_absolute_position(); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":560 - * grid_file_locations[grid_ind, 1] = grid_ind - level_cell_counts[ilevel] - * parent_ind = father_it.get_absolute_position() - * if ilevel > 0: # <<<<<<<<<<<<<< - * # We calculate the REAL parent index - * grid_file_locations[grid_ind, 2] = \ - */ - __pyx_t_7 = (__pyx_v_ilevel > 0); - if (__pyx_t_7) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":563 - * # We calculate the REAL parent index - * grid_file_locations[grid_ind, 2] = \ - * level_cell_counts[ilevel - 1] + parent_ind # <<<<<<<<<<<<<< - * else: - * grid_file_locations[grid_ind, 2] = -1 - */ - __pyx_t_29 = (__pyx_v_ilevel - 1); - __pyx_t_25 = __Pyx_GetItemInt(((PyObject *)__pyx_v_level_cell_counts), __pyx_t_29, sizeof(long), PyInt_FromLong); if (!__pyx_t_25) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_25); - __pyx_t_24 = PyLong_FromUnsignedLong(__pyx_v_parent_ind); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_24); - __pyx_t_1 = PyNumber_Add(__pyx_t_25, __pyx_t_24); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0; - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_26 = __Pyx_PyInt_from_py_npy_int64(__pyx_t_1); if (unlikely((__pyx_t_26 == (npy_int64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":562 - * if ilevel > 0: - * # We calculate the REAL parent index - * grid_file_locations[grid_ind, 2] = \ # <<<<<<<<<<<<<< - * level_cell_counts[ilevel - 1] + parent_ind - * else: - */ - __pyx_t_28 = __pyx_v_grid_ind; - __pyx_t_29 = 2; - __pyx_t_30 = -1; - if (__pyx_t_28 < 0) { - __pyx_t_28 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_28 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_30 = 0; - if (__pyx_t_29 < 0) { - __pyx_t_29 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 1; - } else if (unlikely(__pyx_t_29 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_30 = 1; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_28, __pyx_bstride_0_grid_file_locations, __pyx_t_29, __pyx_bstride_1_grid_file_locations) = __pyx_t_26; - goto __pyx_L12; - } - /*else*/ { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":565 - * level_cell_counts[ilevel - 1] + parent_ind - * else: - * grid_file_locations[grid_ind, 2] = -1 # <<<<<<<<<<<<<< - * for ci in range(8): - * rr = grid_it.is_finest(ci) - */ - __pyx_t_30 = __pyx_v_grid_ind; - __pyx_t_31 = 2; - __pyx_t_32 = -1; - if (__pyx_t_30 < 0) { - __pyx_t_30 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_30 < 0)) __pyx_t_32 = 0; - } else if (unlikely(__pyx_t_30 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_32 = 0; - if (__pyx_t_31 < 0) { - __pyx_t_31 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_31 < 0)) __pyx_t_32 = 1; - } else if (unlikely(__pyx_t_31 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_32 = 1; - if (unlikely(__pyx_t_32 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_32); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_30, __pyx_bstride_0_grid_file_locations, __pyx_t_31, __pyx_bstride_1_grid_file_locations) = -1; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":566 - * else: - * grid_file_locations[grid_ind, 2] = -1 - * for ci in range(8): # <<<<<<<<<<<<<< - * rr = grid_it.is_finest(ci) - * child_mask[grid_ind, ci] = rr - */ - for (__pyx_t_7 = 0; __pyx_t_7 < 8; __pyx_t_7+=1) { - __pyx_v_ci = __pyx_t_7; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":567 - * grid_file_locations[grid_ind, 2] = -1 - * for ci in range(8): - * rr = grid_it.is_finest(ci) # <<<<<<<<<<<<<< - * child_mask[grid_ind, ci] = rr - * grid_ind += 1 - */ - __pyx_v_rr = ((__pyx_t_5numpy_int32_t)__pyx_v_grid_it.is_finest(__pyx_v_ci)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":568 - * for ci in range(8): - * rr = grid_it.is_finest(ci) - * child_mask[grid_ind, ci] = rr # <<<<<<<<<<<<<< - * grid_ind += 1 - * grid_it.next() - */ - __pyx_t_32 = __pyx_v_grid_ind; - __pyx_t_33 = __pyx_v_ci; - __pyx_t_34 = -1; - if (__pyx_t_32 < 0) { - __pyx_t_32 += __pyx_bshape_0_child_mask; - if (unlikely(__pyx_t_32 < 0)) __pyx_t_34 = 0; - } else if (unlikely(__pyx_t_32 >= __pyx_bshape_0_child_mask)) __pyx_t_34 = 0; - if (__pyx_t_33 < 0) { - __pyx_t_33 += __pyx_bshape_1_child_mask; - if (unlikely(__pyx_t_33 < 0)) __pyx_t_34 = 1; - } else if (unlikely(__pyx_t_33 >= __pyx_bshape_1_child_mask)) __pyx_t_34 = 1; - if (unlikely(__pyx_t_34 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_34); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_child_mask.buf, __pyx_t_32, __pyx_bstride_0_child_mask, __pyx_t_33, __pyx_bstride_1_child_mask) = __pyx_v_rr; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":569 - * rr = grid_it.is_finest(ci) - * child_mask[grid_ind, ci] = rr - * grid_ind += 1 # <<<<<<<<<<<<<< - * grid_it.next() - * del local_tree, local_hydro_data - */ - __pyx_v_grid_ind += 1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":570 - * child_mask[grid_ind, ci] = rr - * grid_ind += 1 - * grid_it.next() # <<<<<<<<<<<<<< - * del local_tree, local_hydro_data - * - */ - __pyx_v_grid_it.next(); - } - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":571 - * grid_ind += 1 - * grid_it.next() - * del local_tree, local_hydro_data # <<<<<<<<<<<<<< - * - * def read_oct_grid(self, char *field, int level, int domain, int grid_id): - */ - delete __pyx_v_local_tree; - delete __pyx_v_local_hydro_data; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_24); - __Pyx_XDECREF(__pyx_t_25); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_levels); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.fill_hierarchy_arrays"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_levels); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_child_mask); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); - __pyx_L2:; - __Pyx_DECREF(__pyx_v_cell_count); - __Pyx_DECREF(__pyx_v_level_cell_counts); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":573 - * del local_tree, local_hydro_data - * - * def read_oct_grid(self, char *field, int level, int domain, int grid_id): # <<<<<<<<<<<<<< - * - * self.ensure_loaded(field, domain - 1) - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_read_oct_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_read_oct_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_field; - int __pyx_v_level; - int __pyx_v_domain; - int __pyx_v_grid_id; - int __pyx_v_varindex; - int __pyx_v_i; - PyArrayObject *__pyx_v_tr = 0; - double *__pyx_v_data; - RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; - RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; - Py_buffer __pyx_bstruct_tr; - Py_ssize_t __pyx_bstride_0_tr = 0; - Py_ssize_t __pyx_bstride_1_tr = 0; - Py_ssize_t __pyx_bstride_2_tr = 0; - Py_ssize_t __pyx_bshape_0_tr = 0; - Py_ssize_t __pyx_bshape_1_tr = 0; - Py_ssize_t __pyx_bshape_2_tr = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyArrayObject *__pyx_t_6 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__field,&__pyx_n_s__level,&__pyx_n_s__domain,&__pyx_n_s__grid_id,0}; - __Pyx_RefNannySetupContext("read_oct_grid"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[4] = {0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__domain); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_id); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read_oct_grid") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_field = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_level = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_domain = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_domain == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_grid_id = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_field = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_domain = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_domain == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_grid_id = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_grid_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("read_oct_grid", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.read_oct_grid"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_bstruct_tr.buf = NULL; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":575 - * def read_oct_grid(self, char *field, int level, int domain, int grid_id): - * - * self.ensure_loaded(field, domain - 1) # <<<<<<<<<<<<<< - * cdef int varindex = self.field_ind[field] - * cdef int i - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__ensure_loaded); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_3 = PyInt_FromLong((__pyx_v_domain - 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":576 - * - * self.ensure_loaded(field, domain - 1) - * cdef int varindex = self.field_ind[field] # <<<<<<<<<<<<<< - * cdef int i - * - */ - __pyx_t_3 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyObject_GetItem(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_3)); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_varindex = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":579 - * cdef int i - * - * cdef np.ndarray[np.float64_t, ndim=3] tr = np.empty((2,2,2), dtype='float64', # <<<<<<<<<<<<<< - * order='F') - * cdef tree_iterator grid_it, grid_end - */ - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __Pyx_INCREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__float64)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__order), ((PyObject *)__pyx_n_s__F)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_3, __pyx_t_1, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_tr, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) { - __pyx_v_tr = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_tr.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } else {__pyx_bstride_0_tr = __pyx_bstruct_tr.strides[0]; __pyx_bstride_1_tr = __pyx_bstruct_tr.strides[1]; __pyx_bstride_2_tr = __pyx_bstruct_tr.strides[2]; - __pyx_bshape_0_tr = __pyx_bstruct_tr.shape[0]; __pyx_bshape_1_tr = __pyx_bstruct_tr.shape[1]; __pyx_bshape_2_tr = __pyx_bstruct_tr.shape[2]; - } - } - __pyx_t_6 = 0; - __pyx_v_tr = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":582 - * order='F') - * cdef tree_iterator grid_it, grid_end - * cdef double* data = tr.data # <<<<<<<<<<<<<< - * - * cdef RAMSES_tree *local_tree = self.trees[domain - 1] - */ - __pyx_v_data = ((double *)__pyx_v_tr->data); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":584 - * cdef double* data = tr.data - * - * cdef RAMSES_tree *local_tree = self.trees[domain - 1] # <<<<<<<<<<<<<< - * cdef RAMSES_hydro_data *local_hydro_data = self.hydro_datas[domain - 1][varindex] - * - */ - __pyx_v_local_tree = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[(__pyx_v_domain - 1)]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":585 - * - * cdef RAMSES_tree *local_tree = self.trees[domain - 1] - * cdef RAMSES_hydro_data *local_hydro_data = self.hydro_datas[domain - 1][varindex] # <<<<<<<<<<<<<< - * - * #inline ValueType_& cell_value( const typename TreeType_::iterator& it, - */ - __pyx_v_local_hydro_data = ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_domain - 1)])[__pyx_v_varindex]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":595 - * #} - * - * for i in range(8): # <<<<<<<<<<<<<< - * data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] - * return tr - */ - for (__pyx_t_5 = 0; __pyx_t_5 < 8; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":596 - * - * for i in range(8): - * data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] # <<<<<<<<<<<<<< - * return tr - * - */ - (__pyx_v_data[__pyx_v_i]) = ((__pyx_v_local_hydro_data->m_var_array[__pyx_v_level])[((8 * __pyx_v_grid_id) + __pyx_v_i)]); - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":597 - * for i in range(8): - * data[i] = local_hydro_data.m_var_array[level][8*grid_id+i] - * return tr # <<<<<<<<<<<<<< - * - * def read_grid(self, char *field, - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_tr)); - __pyx_r = ((PyObject *)__pyx_v_tr); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tr); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.read_oct_grid"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_tr); - __pyx_L2:; - __Pyx_XDECREF((PyObject *)__pyx_v_tr); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":599 - * return tr - * - * def read_grid(self, char *field, # <<<<<<<<<<<<<< - * np.ndarray[np.int64_t, ndim=1] start_index, - * np.ndarray[np.int32_t, ndim=1] grid_dims, - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_read_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_17RAMSES_tree_proxy_read_grid(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_field; - PyArrayObject *__pyx_v_start_index = 0; - PyArrayObject *__pyx_v_grid_dims = 0; - PyArrayObject *__pyx_v_data = 0; - PyArrayObject *__pyx_v_filled = 0; - int __pyx_v_level; - int __pyx_v_ref_factor; - PyObject *__pyx_v_component_grid_info = 0; - int __pyx_v_varindex; - RAMSES::AMR::RAMSES_tree *__pyx_v_local_tree; - RAMSES::HYDRO::RAMSES_hydro_data *__pyx_v_local_hydro_data; - int __pyx_v_gi; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_k; - int __pyx_v_domain; - int __pyx_v_offset; - int __pyx_v_ir; - int __pyx_v_jr; - int __pyx_v_kr; - int __pyx_v_offi; - int __pyx_v_offj; - int __pyx_v_offk; - __pyx_t_5numpy_int64_t __pyx_v_di; - __pyx_t_5numpy_int64_t __pyx_v_dj; - __pyx_t_5numpy_int64_t __pyx_v_dk; - PyArrayObject *__pyx_v_ogrid_info; - PyArrayObject *__pyx_v_og_start_index; - __pyx_t_5numpy_float64_t __pyx_v_temp_data; - __pyx_t_5numpy_int64_t __pyx_v_end_index[3]; - int __pyx_v_to_fill; - PyObject *__pyx_v_odind; - Py_buffer __pyx_bstruct_grid_dims; - Py_ssize_t __pyx_bstride_0_grid_dims = 0; - Py_ssize_t __pyx_bshape_0_grid_dims = 0; - Py_buffer __pyx_bstruct_og_start_index; - Py_ssize_t __pyx_bstride_0_og_start_index = 0; - Py_ssize_t __pyx_bshape_0_og_start_index = 0; - Py_buffer __pyx_bstruct_ogrid_info; - Py_ssize_t __pyx_bstride_0_ogrid_info = 0; - Py_ssize_t __pyx_bshape_0_ogrid_info = 0; - Py_buffer __pyx_bstruct_filled; - Py_ssize_t __pyx_bstride_0_filled = 0; - Py_ssize_t __pyx_bstride_1_filled = 0; - Py_ssize_t __pyx_bstride_2_filled = 0; - Py_ssize_t __pyx_bshape_0_filled = 0; - Py_ssize_t __pyx_bshape_1_filled = 0; - Py_ssize_t __pyx_bshape_2_filled = 0; - Py_buffer __pyx_bstruct_data; - Py_ssize_t __pyx_bstride_0_data = 0; - Py_ssize_t __pyx_bstride_1_data = 0; - Py_ssize_t __pyx_bstride_2_data = 0; - Py_ssize_t __pyx_bshape_0_data = 0; - Py_ssize_t __pyx_bshape_1_data = 0; - Py_ssize_t __pyx_bshape_2_data = 0; - Py_buffer __pyx_bstruct_start_index; - Py_ssize_t __pyx_bstride_0_start_index = 0; - Py_ssize_t __pyx_bshape_0_start_index = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - Py_ssize_t __pyx_t_7; - PyArrayObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - long __pyx_t_12; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - long __pyx_t_15; - PyArrayObject *__pyx_t_16 = NULL; - long __pyx_t_17; - long __pyx_t_18; - int __pyx_t_19; - long __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - long __pyx_t_24; - long __pyx_t_25; - int __pyx_t_26; - long __pyx_t_27; - long __pyx_t_28; - long __pyx_t_29; - int __pyx_t_30; - long __pyx_t_31; - long __pyx_t_32; - long __pyx_t_33; - long __pyx_t_34; - int __pyx_t_35; - int __pyx_t_36; - int __pyx_t_37; - int __pyx_t_38; - int __pyx_t_39; - int __pyx_t_40; - int __pyx_t_41; - int __pyx_t_42; - int __pyx_t_43; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__field,&__pyx_n_s__start_index,&__pyx_n_s__grid_dims,&__pyx_n_s__data,&__pyx_n_s__filled,&__pyx_n_s__level,&__pyx_n_s__ref_factor,&__pyx_n_s__component_grid_info,0}; - __Pyx_RefNannySetupContext("read_grid"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[8] = {0,0,0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__field); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start_index); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_dims); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__data); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filled); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__level); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref_factor); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 7: - values[7] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__component_grid_info); - if (likely(values[7])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read_grid") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_field = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_start_index = ((PyArrayObject *)values[1]); - __pyx_v_grid_dims = ((PyArrayObject *)values[2]); - __pyx_v_data = ((PyArrayObject *)values[3]); - __pyx_v_filled = ((PyArrayObject *)values[4]); - __pyx_v_level = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_ref_factor = __Pyx_PyInt_AsInt(values[6]); if (unlikely((__pyx_v_ref_factor == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_component_grid_info = values[7]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 8) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_field = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_field) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_start_index = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_grid_dims = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_data = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_filled = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_level = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 5)); if (unlikely((__pyx_v_level == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_ref_factor = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 6)); if (unlikely((__pyx_v_ref_factor == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_component_grid_info = PyTuple_GET_ITEM(__pyx_args, 7); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("read_grid", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.read_grid"); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_ogrid_info = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_og_start_index = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_odind = Py_None; __Pyx_INCREF(Py_None); - __pyx_bstruct_ogrid_info.buf = NULL; - __pyx_bstruct_og_start_index.buf = NULL; - __pyx_bstruct_start_index.buf = NULL; - __pyx_bstruct_grid_dims.buf = NULL; - __pyx_bstruct_data.buf = NULL; - __pyx_bstruct_filled.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_start_index), __pyx_ptype_5numpy_ndarray, 1, "start_index", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_dims), __pyx_ptype_5numpy_ndarray, 1, "grid_dims", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), __pyx_ptype_5numpy_ndarray, 1, "data", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 602; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_filled), __pyx_ptype_5numpy_ndarray, 1, "filled", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_start_index, (PyObject*)__pyx_v_start_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_start_index = __pyx_bstruct_start_index.strides[0]; - __pyx_bshape_0_start_index = __pyx_bstruct_start_index.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_dims, (PyObject*)__pyx_v_grid_dims, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_dims = __pyx_bstruct_grid_dims.strides[0]; - __pyx_bshape_0_grid_dims = __pyx_bstruct_grid_dims.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_data, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_data = __pyx_bstruct_data.strides[0]; __pyx_bstride_1_data = __pyx_bstruct_data.strides[1]; __pyx_bstride_2_data = __pyx_bstruct_data.strides[2]; - __pyx_bshape_0_data = __pyx_bstruct_data.shape[0]; __pyx_bshape_1_data = __pyx_bstruct_data.shape[1]; __pyx_bshape_2_data = __pyx_bstruct_data.shape[2]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_filled, (PyObject*)__pyx_v_filled, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_filled = __pyx_bstruct_filled.strides[0]; __pyx_bstride_1_filled = __pyx_bstruct_filled.strides[1]; __pyx_bstride_2_filled = __pyx_bstruct_filled.strides[2]; - __pyx_bshape_0_filled = __pyx_bstruct_filled.shape[0]; __pyx_bshape_1_filled = __pyx_bstruct_filled.shape[1]; __pyx_bshape_2_filled = __pyx_bstruct_filled.shape[2]; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":606 - * int level, int ref_factor, - * component_grid_info): - * cdef int varindex = self.field_ind[field] # <<<<<<<<<<<<<< - * cdef RAMSES_tree *local_tree = NULL - * cdef RAMSES_hydro_data *local_hydro_data = NULL - */ - __pyx_t_1 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->field_ind, ((PyObject *)__pyx_t_1)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_varindex = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":607 - * component_grid_info): - * cdef int varindex = self.field_ind[field] - * cdef RAMSES_tree *local_tree = NULL # <<<<<<<<<<<<<< - * cdef RAMSES_hydro_data *local_hydro_data = NULL - * - */ - __pyx_v_local_tree = NULL; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":608 - * cdef int varindex = self.field_ind[field] - * cdef RAMSES_tree *local_tree = NULL - * cdef RAMSES_hydro_data *local_hydro_data = NULL # <<<<<<<<<<<<<< - * - * cdef int gi, i, j, k, domain, offset - */ - __pyx_v_local_hydro_data = NULL; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":618 - * cdef np.float64_t temp_data - * cdef np.int64_t end_index[3] - * cdef int to_fill = 0 # <<<<<<<<<<<<<< - * # Note that indexing into a cell is: - * # (k*2 + j)*2 + i - */ - __pyx_v_to_fill = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":621 - * # Note that indexing into a cell is: - * # (k*2 + j)*2 + i - * for i in range(3): # <<<<<<<<<<<<<< - * end_index[i] = start_index[i] + grid_dims[i] - * for gi in range(len(component_grid_info)): - */ - for (__pyx_t_3 = 0; __pyx_t_3 < 3; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":622 - * # (k*2 + j)*2 + i - * for i in range(3): - * end_index[i] = start_index[i] + grid_dims[i] # <<<<<<<<<<<<<< - * for gi in range(len(component_grid_info)): - * ogrid_info = component_grid_info[gi] - */ - __pyx_t_4 = __pyx_v_i; - __pyx_t_5 = -1; - if (__pyx_t_4 < 0) { - __pyx_t_4 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_4 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_4 >= __pyx_bshape_0_start_index)) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 622; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = __pyx_v_i; - __pyx_t_6 = -1; - if (__pyx_t_5 < 0) { - __pyx_t_5 += __pyx_bshape_0_grid_dims; - if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0; - } else if (unlikely(__pyx_t_5 >= __pyx_bshape_0_grid_dims)) __pyx_t_6 = 0; - if (unlikely(__pyx_t_6 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_6); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 622; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_end_index[__pyx_v_i]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_4, __pyx_bstride_0_start_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_grid_dims.buf, __pyx_t_5, __pyx_bstride_0_grid_dims))); - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":623 - * for i in range(3): - * end_index[i] = start_index[i] + grid_dims[i] - * for gi in range(len(component_grid_info)): # <<<<<<<<<<<<<< - * ogrid_info = component_grid_info[gi] - * domain = ogrid_info[0] - */ - __pyx_t_7 = PyObject_Length(__pyx_v_component_grid_info); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 623; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_7; __pyx_t_3+=1) { - __pyx_v_gi = __pyx_t_3; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":624 - * end_index[i] = start_index[i] + grid_dims[i] - * for gi in range(len(component_grid_info)): - * ogrid_info = component_grid_info[gi] # <<<<<<<<<<<<<< - * domain = ogrid_info[0] - * self.ensure_loaded(field, domain - 1) - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_component_grid_info, __pyx_v_gi, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ogrid_info); - __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_ogrid_info, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_6 < 0)) { - PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_ogrid_info, (PyObject*)__pyx_v_ogrid_info, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11); - } - } - __pyx_bstride_0_ogrid_info = __pyx_bstruct_ogrid_info.strides[0]; - __pyx_bshape_0_ogrid_info = __pyx_bstruct_ogrid_info.shape[0]; - if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 624; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_ogrid_info)); - __pyx_v_ogrid_info = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":625 - * for gi in range(len(component_grid_info)): - * ogrid_info = component_grid_info[gi] - * domain = ogrid_info[0] # <<<<<<<<<<<<<< - * self.ensure_loaded(field, domain - 1) - * local_tree = self.trees[domain - 1] - */ - __pyx_t_12 = 0; - __pyx_t_6 = -1; - if (__pyx_t_12 < 0) { - __pyx_t_12 += __pyx_bshape_0_ogrid_info; - if (unlikely(__pyx_t_12 < 0)) __pyx_t_6 = 0; - } else if (unlikely(__pyx_t_12 >= __pyx_bshape_0_ogrid_info)) __pyx_t_6 = 0; - if (unlikely(__pyx_t_6 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_6); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_domain = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_ogrid_info.buf, __pyx_t_12, __pyx_bstride_0_ogrid_info)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":626 - * ogrid_info = component_grid_info[gi] - * domain = ogrid_info[0] - * self.ensure_loaded(field, domain - 1) # <<<<<<<<<<<<<< - * local_tree = self.trees[domain - 1] - * local_hydro_data = self.hydro_datas[domain - 1][varindex] - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__ensure_loaded); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyBytes_FromString(__pyx_v_field); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_13 = PyInt_FromLong((__pyx_v_domain - 1)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_13); - __Pyx_GIVEREF(__pyx_t_13); - __pyx_t_1 = 0; - __pyx_t_13 = 0; - __pyx_t_13 = PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":627 - * domain = ogrid_info[0] - * self.ensure_loaded(field, domain - 1) - * local_tree = self.trees[domain - 1] # <<<<<<<<<<<<<< - * local_hydro_data = self.hydro_datas[domain - 1][varindex] - * offset = ogrid_info[1] - */ - __pyx_v_local_tree = (((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->trees[(__pyx_v_domain - 1)]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":628 - * self.ensure_loaded(field, domain - 1) - * local_tree = self.trees[domain - 1] - * local_hydro_data = self.hydro_datas[domain - 1][varindex] # <<<<<<<<<<<<<< - * offset = ogrid_info[1] - * og_start_index = ogrid_info[3:] - */ - __pyx_v_local_hydro_data = ((((struct __pyx_obj_2yt_13ramses_reader_RAMSES_tree_proxy *)__pyx_v_self)->hydro_datas[(__pyx_v_domain - 1)])[__pyx_v_varindex]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":629 - * local_tree = self.trees[domain - 1] - * local_hydro_data = self.hydro_datas[domain - 1][varindex] - * offset = ogrid_info[1] # <<<<<<<<<<<<<< - * og_start_index = ogrid_info[3:] - * for i in range(2*ref_factor): - */ - __pyx_t_15 = 1; - __pyx_t_6 = -1; - if (__pyx_t_15 < 0) { - __pyx_t_15 += __pyx_bshape_0_ogrid_info; - if (unlikely(__pyx_t_15 < 0)) __pyx_t_6 = 0; - } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_ogrid_info)) __pyx_t_6 = 0; - if (unlikely(__pyx_t_6 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_6); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_offset = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_ogrid_info.buf, __pyx_t_15, __pyx_bstride_0_ogrid_info)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":630 - * local_hydro_data = self.hydro_datas[domain - 1][varindex] - * offset = ogrid_info[1] - * og_start_index = ogrid_info[3:] # <<<<<<<<<<<<<< - * for i in range(2*ref_factor): - * di = i + og_start_index[0] * ref_factor - */ - __pyx_t_13 = PySequence_GetSlice(((PyObject *)__pyx_v_ogrid_info), 3, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_16 = ((PyArrayObject *)__pyx_t_13); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_og_start_index); - __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_og_start_index, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_6 < 0)) { - PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_og_start_index, (PyObject*)__pyx_v_og_start_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9); - } - } - __pyx_bstride_0_og_start_index = __pyx_bstruct_og_start_index.strides[0]; - __pyx_bshape_0_og_start_index = __pyx_bstruct_og_start_index.shape[0]; - if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_16 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_og_start_index)); - __pyx_v_og_start_index = ((PyArrayObject *)__pyx_t_13); - __pyx_t_13 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":631 - * offset = ogrid_info[1] - * og_start_index = ogrid_info[3:] - * for i in range(2*ref_factor): # <<<<<<<<<<<<<< - * di = i + og_start_index[0] * ref_factor - * if di < start_index[0] or di >= end_index[0]: continue - */ - __pyx_t_17 = (2 * __pyx_v_ref_factor); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_17; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":632 - * og_start_index = ogrid_info[3:] - * for i in range(2*ref_factor): - * di = i + og_start_index[0] * ref_factor # <<<<<<<<<<<<<< - * if di < start_index[0] or di >= end_index[0]: continue - * ir = (i / ref_factor) - */ - __pyx_t_18 = 0; - __pyx_t_19 = -1; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_bshape_0_og_start_index; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_19 = 0; - } else if (unlikely(__pyx_t_18 >= __pyx_bshape_0_og_start_index)) __pyx_t_19 = 0; - if (unlikely(__pyx_t_19 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_19); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_di = (__pyx_v_i + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_og_start_index.buf, __pyx_t_18, __pyx_bstride_0_og_start_index)) * __pyx_v_ref_factor)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":633 - * for i in range(2*ref_factor): - * di = i + og_start_index[0] * ref_factor - * if di < start_index[0] or di >= end_index[0]: continue # <<<<<<<<<<<<<< - * ir = (i / ref_factor) - * for j in range(2 * ref_factor): - */ - __pyx_t_20 = 0; - __pyx_t_19 = -1; - if (__pyx_t_20 < 0) { - __pyx_t_20 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_20 < 0)) __pyx_t_19 = 0; - } else if (unlikely(__pyx_t_20 >= __pyx_bshape_0_start_index)) __pyx_t_19 = 0; - if (unlikely(__pyx_t_19 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_19); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_21 = (__pyx_v_di < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_20, __pyx_bstride_0_start_index))); - if (!__pyx_t_21) { - __pyx_t_22 = (__pyx_v_di >= (__pyx_v_end_index[0])); - __pyx_t_23 = __pyx_t_22; - } else { - __pyx_t_23 = __pyx_t_21; - } - if (__pyx_t_23) { - goto __pyx_L10_continue; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":634 - * di = i + og_start_index[0] * ref_factor - * if di < start_index[0] or di >= end_index[0]: continue - * ir = (i / ref_factor) # <<<<<<<<<<<<<< - * for j in range(2 * ref_factor): - * dj = j + og_start_index[1] * ref_factor - */ - if (unlikely(__pyx_v_ref_factor == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_ref_factor == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_i))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_ir = __Pyx_div_int(__pyx_v_i, __pyx_v_ref_factor); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":635 - * if di < start_index[0] or di >= end_index[0]: continue - * ir = (i / ref_factor) - * for j in range(2 * ref_factor): # <<<<<<<<<<<<<< - * dj = j + og_start_index[1] * ref_factor - * if dj < start_index[1] or dj >= end_index[1]: continue - */ - __pyx_t_24 = (2 * __pyx_v_ref_factor); - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_24; __pyx_t_19+=1) { - __pyx_v_j = __pyx_t_19; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":636 - * ir = (i / ref_factor) - * for j in range(2 * ref_factor): - * dj = j + og_start_index[1] * ref_factor # <<<<<<<<<<<<<< - * if dj < start_index[1] or dj >= end_index[1]: continue - * jr = (j / ref_factor) - */ - __pyx_t_25 = 1; - __pyx_t_26 = -1; - if (__pyx_t_25 < 0) { - __pyx_t_25 += __pyx_bshape_0_og_start_index; - if (unlikely(__pyx_t_25 < 0)) __pyx_t_26 = 0; - } else if (unlikely(__pyx_t_25 >= __pyx_bshape_0_og_start_index)) __pyx_t_26 = 0; - if (unlikely(__pyx_t_26 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_26); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dj = (__pyx_v_j + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_og_start_index.buf, __pyx_t_25, __pyx_bstride_0_og_start_index)) * __pyx_v_ref_factor)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":637 - * for j in range(2 * ref_factor): - * dj = j + og_start_index[1] * ref_factor - * if dj < start_index[1] or dj >= end_index[1]: continue # <<<<<<<<<<<<<< - * jr = (j / ref_factor) - * for k in range(2 * ref_factor): - */ - __pyx_t_27 = 1; - __pyx_t_26 = -1; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_26 = 0; - } else if (unlikely(__pyx_t_27 >= __pyx_bshape_0_start_index)) __pyx_t_26 = 0; - if (unlikely(__pyx_t_26 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_26); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_23 = (__pyx_v_dj < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_27, __pyx_bstride_0_start_index))); - if (!__pyx_t_23) { - __pyx_t_21 = (__pyx_v_dj >= (__pyx_v_end_index[1])); - __pyx_t_22 = __pyx_t_21; - } else { - __pyx_t_22 = __pyx_t_23; - } - if (__pyx_t_22) { - goto __pyx_L13_continue; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":638 - * dj = j + og_start_index[1] * ref_factor - * if dj < start_index[1] or dj >= end_index[1]: continue - * jr = (j / ref_factor) # <<<<<<<<<<<<<< - * for k in range(2 * ref_factor): - * dk = k + og_start_index[2] * ref_factor - */ - if (unlikely(__pyx_v_ref_factor == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_ref_factor == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_j))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_jr = __Pyx_div_int(__pyx_v_j, __pyx_v_ref_factor); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":639 - * if dj < start_index[1] or dj >= end_index[1]: continue - * jr = (j / ref_factor) - * for k in range(2 * ref_factor): # <<<<<<<<<<<<<< - * dk = k + og_start_index[2] * ref_factor - * if dk < start_index[2] or dk >= end_index[2]: continue - */ - __pyx_t_28 = (2 * __pyx_v_ref_factor); - for (__pyx_t_26 = 0; __pyx_t_26 < __pyx_t_28; __pyx_t_26+=1) { - __pyx_v_k = __pyx_t_26; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":640 - * jr = (j / ref_factor) - * for k in range(2 * ref_factor): - * dk = k + og_start_index[2] * ref_factor # <<<<<<<<<<<<<< - * if dk < start_index[2] or dk >= end_index[2]: continue - * kr = (k / ref_factor) - */ - __pyx_t_29 = 2; - __pyx_t_30 = -1; - if (__pyx_t_29 < 0) { - __pyx_t_29 += __pyx_bshape_0_og_start_index; - if (unlikely(__pyx_t_29 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_29 >= __pyx_bshape_0_og_start_index)) __pyx_t_30 = 0; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dk = (__pyx_v_k + ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_og_start_index.buf, __pyx_t_29, __pyx_bstride_0_og_start_index)) * __pyx_v_ref_factor)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":641 - * for k in range(2 * ref_factor): - * dk = k + og_start_index[2] * ref_factor - * if dk < start_index[2] or dk >= end_index[2]: continue # <<<<<<<<<<<<<< - * kr = (k / ref_factor) - * offi = di - start_index[0] - */ - __pyx_t_31 = 2; - __pyx_t_30 = -1; - if (__pyx_t_31 < 0) { - __pyx_t_31 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_31 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_31 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 641; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_22 = (__pyx_v_dk < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_31, __pyx_bstride_0_start_index))); - if (!__pyx_t_22) { - __pyx_t_23 = (__pyx_v_dk >= (__pyx_v_end_index[2])); - __pyx_t_21 = __pyx_t_23; - } else { - __pyx_t_21 = __pyx_t_22; - } - if (__pyx_t_21) { - goto __pyx_L16_continue; - goto __pyx_L18; - } - __pyx_L18:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":642 - * dk = k + og_start_index[2] * ref_factor - * if dk < start_index[2] or dk >= end_index[2]: continue - * kr = (k / ref_factor) # <<<<<<<<<<<<<< - * offi = di - start_index[0] - * offj = dj - start_index[1] - */ - if (unlikely(__pyx_v_ref_factor == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_ref_factor == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_k))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_kr = __Pyx_div_int(__pyx_v_k, __pyx_v_ref_factor); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":643 - * if dk < start_index[2] or dk >= end_index[2]: continue - * kr = (k / ref_factor) - * offi = di - start_index[0] # <<<<<<<<<<<<<< - * offj = dj - start_index[1] - * offk = dk - start_index[2] - */ - __pyx_t_32 = 0; - __pyx_t_30 = -1; - if (__pyx_t_32 < 0) { - __pyx_t_32 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_32 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_32 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_offi = (__pyx_v_di - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_32, __pyx_bstride_0_start_index))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":644 - * kr = (k / ref_factor) - * offi = di - start_index[0] - * offj = dj - start_index[1] # <<<<<<<<<<<<<< - * offk = dk - start_index[2] - * #print offi, filled.shape[0], - */ - __pyx_t_33 = 1; - __pyx_t_30 = -1; - if (__pyx_t_33 < 0) { - __pyx_t_33 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_33 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_33 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_offj = (__pyx_v_dj - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_33, __pyx_bstride_0_start_index))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":645 - * offi = di - start_index[0] - * offj = dj - start_index[1] - * offk = dk - start_index[2] # <<<<<<<<<<<<<< - * #print offi, filled.shape[0], - * #print offj, filled.shape[1], - */ - __pyx_t_34 = 2; - __pyx_t_30 = -1; - if (__pyx_t_34 < 0) { - __pyx_t_34 += __pyx_bshape_0_start_index; - if (unlikely(__pyx_t_34 < 0)) __pyx_t_30 = 0; - } else if (unlikely(__pyx_t_34 >= __pyx_bshape_0_start_index)) __pyx_t_30 = 0; - if (unlikely(__pyx_t_30 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_30); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_offk = (__pyx_v_dk - (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_start_index.buf, __pyx_t_34, __pyx_bstride_0_start_index))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":649 - * #print offj, filled.shape[1], - * #print offk, filled.shape[2] - * if filled[offi, offj, offk] == 1: continue # <<<<<<<<<<<<<< - * - * odind = (kr*2 + jr)*2 + ir - */ - __pyx_t_30 = __pyx_v_offi; - __pyx_t_35 = __pyx_v_offj; - __pyx_t_36 = __pyx_v_offk; - __pyx_t_37 = -1; - if (__pyx_t_30 < 0) { - __pyx_t_30 += __pyx_bshape_0_filled; - if (unlikely(__pyx_t_30 < 0)) __pyx_t_37 = 0; - } else if (unlikely(__pyx_t_30 >= __pyx_bshape_0_filled)) __pyx_t_37 = 0; - if (__pyx_t_35 < 0) { - __pyx_t_35 += __pyx_bshape_1_filled; - if (unlikely(__pyx_t_35 < 0)) __pyx_t_37 = 1; - } else if (unlikely(__pyx_t_35 >= __pyx_bshape_1_filled)) __pyx_t_37 = 1; - if (__pyx_t_36 < 0) { - __pyx_t_36 += __pyx_bshape_2_filled; - if (unlikely(__pyx_t_36 < 0)) __pyx_t_37 = 2; - } else if (unlikely(__pyx_t_36 >= __pyx_bshape_2_filled)) __pyx_t_37 = 2; - if (unlikely(__pyx_t_37 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_37); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_21 = ((*__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_filled.buf, __pyx_t_30, __pyx_bstride_0_filled, __pyx_t_35, __pyx_bstride_1_filled, __pyx_t_36, __pyx_bstride_2_filled)) == 1); - if (__pyx_t_21) { - goto __pyx_L16_continue; - goto __pyx_L19; - } - __pyx_L19:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":651 - * if filled[offi, offj, offk] == 1: continue - * - * odind = (kr*2 + jr)*2 + ir # <<<<<<<<<<<<<< - * temp_data = local_hydro_data.m_var_array[ - * level][8*offset + odind] - */ - __pyx_t_13 = PyInt_FromLong(((((__pyx_v_kr * 2) + __pyx_v_jr) * 2) + __pyx_v_ir)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 651; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_v_odind); - __pyx_v_odind = __pyx_t_13; - __pyx_t_13 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":653 - * odind = (kr*2 + jr)*2 + ir - * temp_data = local_hydro_data.m_var_array[ - * level][8*offset + odind] # <<<<<<<<<<<<<< - * data[offi, offj, offk] = temp_data - * filled[offi, offj, offk] = 1 - */ - __pyx_t_13 = PyInt_FromLong((8 * __pyx_v_offset)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_14 = PyNumber_Add(__pyx_t_13, __pyx_v_odind); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_37 = __Pyx_PyInt_AsInt(__pyx_t_14); if (unlikely((__pyx_t_37 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_temp_data = ((__pyx_v_local_hydro_data->m_var_array[__pyx_v_level])[__pyx_t_37]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":654 - * temp_data = local_hydro_data.m_var_array[ - * level][8*offset + odind] - * data[offi, offj, offk] = temp_data # <<<<<<<<<<<<<< - * filled[offi, offj, offk] = 1 - * to_fill += 1 - */ - __pyx_t_37 = __pyx_v_offi; - __pyx_t_38 = __pyx_v_offj; - __pyx_t_39 = __pyx_v_offk; - __pyx_t_40 = -1; - if (__pyx_t_37 < 0) { - __pyx_t_37 += __pyx_bshape_0_data; - if (unlikely(__pyx_t_37 < 0)) __pyx_t_40 = 0; - } else if (unlikely(__pyx_t_37 >= __pyx_bshape_0_data)) __pyx_t_40 = 0; - if (__pyx_t_38 < 0) { - __pyx_t_38 += __pyx_bshape_1_data; - if (unlikely(__pyx_t_38 < 0)) __pyx_t_40 = 1; - } else if (unlikely(__pyx_t_38 >= __pyx_bshape_1_data)) __pyx_t_40 = 1; - if (__pyx_t_39 < 0) { - __pyx_t_39 += __pyx_bshape_2_data; - if (unlikely(__pyx_t_39 < 0)) __pyx_t_40 = 2; - } else if (unlikely(__pyx_t_39 >= __pyx_bshape_2_data)) __pyx_t_40 = 2; - if (unlikely(__pyx_t_40 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_40); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_bstruct_data.buf, __pyx_t_37, __pyx_bstride_0_data, __pyx_t_38, __pyx_bstride_1_data, __pyx_t_39, __pyx_bstride_2_data) = __pyx_v_temp_data; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":655 - * level][8*offset + odind] - * data[offi, offj, offk] = temp_data - * filled[offi, offj, offk] = 1 # <<<<<<<<<<<<<< - * to_fill += 1 - * return to_fill - */ - __pyx_t_40 = __pyx_v_offi; - __pyx_t_41 = __pyx_v_offj; - __pyx_t_42 = __pyx_v_offk; - __pyx_t_43 = -1; - if (__pyx_t_40 < 0) { - __pyx_t_40 += __pyx_bshape_0_filled; - if (unlikely(__pyx_t_40 < 0)) __pyx_t_43 = 0; - } else if (unlikely(__pyx_t_40 >= __pyx_bshape_0_filled)) __pyx_t_43 = 0; - if (__pyx_t_41 < 0) { - __pyx_t_41 += __pyx_bshape_1_filled; - if (unlikely(__pyx_t_41 < 0)) __pyx_t_43 = 1; - } else if (unlikely(__pyx_t_41 >= __pyx_bshape_1_filled)) __pyx_t_43 = 1; - if (__pyx_t_42 < 0) { - __pyx_t_42 += __pyx_bshape_2_filled; - if (unlikely(__pyx_t_42 < 0)) __pyx_t_43 = 2; - } else if (unlikely(__pyx_t_42 >= __pyx_bshape_2_filled)) __pyx_t_43 = 2; - if (unlikely(__pyx_t_43 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_43); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_int32_t *, __pyx_bstruct_filled.buf, __pyx_t_40, __pyx_bstride_0_filled, __pyx_t_41, __pyx_bstride_1_filled, __pyx_t_42, __pyx_bstride_2_filled) = 1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":656 - * data[offi, offj, offk] = temp_data - * filled[offi, offj, offk] = 1 - * to_fill += 1 # <<<<<<<<<<<<<< - * return to_fill - * - */ - __pyx_v_to_fill += 1; - __pyx_L16_continue:; - } - __pyx_L13_continue:; - } - __pyx_L10_continue:; - } - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":657 - * filled[offi, offj, offk] = 1 - * to_fill += 1 - * return to_fill # <<<<<<<<<<<<<< - * - * cdef class ProtoSubgrid: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_14 = PyInt_FromLong(__pyx_v_to_fill); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_r = __pyx_t_14; - __pyx_t_14 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dims); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_og_start_index); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ogrid_info); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_filled); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_start_index); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.ramses_reader.RAMSES_tree_proxy.read_grid"); - __pyx_r = NULL; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dims); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_og_start_index); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ogrid_info); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_filled); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_data); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_start_index); - __pyx_L2:; - __Pyx_DECREF((PyObject *)__pyx_v_ogrid_info); - __Pyx_DECREF((PyObject *)__pyx_v_og_start_index); - __Pyx_DECREF(__pyx_v_odind); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":664 - * cdef np.int64_t right_edge[3] - * cdef np.int64_t dimensions[3] - * cdef public np.float64_t efficiency # <<<<<<<<<<<<<< - * cdef public object sigs - * cdef public object grid_file_locations - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_10efficiency___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_10efficiency___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("yt.ramses_reader.ProtoSubgrid.efficiency.__get__"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_10efficiency___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_10efficiency___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __pyx_t_5numpy_float64_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__"); - __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_1 == (npy_float64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("yt.ramses_reader.ProtoSubgrid.efficiency.__set__"); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":665 - * cdef np.int64_t dimensions[3] - * cdef public np.float64_t efficiency - * cdef public object sigs # <<<<<<<<<<<<<< - * cdef public object grid_file_locations - * cdef public object dd - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_4sigs___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_4sigs___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - __pyx_r = ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_4sigs___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_4sigs___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_4sigs___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_4sigs___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":666 - * cdef public np.float64_t efficiency - * cdef public object sigs - * cdef public object grid_file_locations # <<<<<<<<<<<<<< - * cdef public object dd - * - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_19grid_file_locations___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_19grid_file_locations___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - __pyx_r = ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_19grid_file_locations___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_19grid_file_locations___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_19grid_file_locations___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_19grid_file_locations___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":667 - * cdef public object sigs - * cdef public object grid_file_locations - * cdef public object dd # <<<<<<<<<<<<<< - * - * #@cython.boundscheck(False) - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_2dd___get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_2dd___get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannySetupContext("__get__"); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - __pyx_r = ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_2dd___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_2dd___set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannySetupContext("__set__"); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_2dd___del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_2dd___del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannySetupContext("__del__"); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":671 - * #@cython.boundscheck(False) - * #@cython.wraparound(False) - * def __cinit__(self, # <<<<<<<<<<<<<< - * np.ndarray[np.int64_t, ndim=1] left_index, - * np.ndarray[np.int64_t, ndim=1] dimensions, - */ - -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_2yt_13ramses_reader_12ProtoSubgrid___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_left_index = 0; - PyArrayObject *__pyx_v_dimensions = 0; - PyArrayObject *__pyx_v_left_edges = 0; - PyArrayObject *__pyx_v_right_edges = 0; - PyArrayObject *__pyx_v_grid_dimensions = 0; - PyArrayObject *__pyx_v_grid_file_locations = 0; - int __pyx_v_i; - int __pyx_v_ng; - int __pyx_v_l0; - int __pyx_v_l1; - int __pyx_v_l2; - int __pyx_v_i0; - int __pyx_v_i1; - int __pyx_v_i2; - __pyx_t_5numpy_int64_t __pyx_v_temp_l[3]; - __pyx_t_5numpy_int64_t __pyx_v_temp_r[3]; - __pyx_t_5numpy_float64_t __pyx_v_efficiency; - int __pyx_v_gi; - PyArrayObject *__pyx_v_sig0; - PyArrayObject *__pyx_v_sig1; - PyArrayObject *__pyx_v_sig2; - int __pyx_v_used; - long __pyx_v_nnn; - Py_buffer __pyx_bstruct_right_edges; - Py_ssize_t __pyx_bstride_0_right_edges = 0; - Py_ssize_t __pyx_bstride_1_right_edges = 0; - Py_ssize_t __pyx_bshape_0_right_edges = 0; - Py_ssize_t __pyx_bshape_1_right_edges = 0; - Py_buffer __pyx_bstruct_left_index; - Py_ssize_t __pyx_bstride_0_left_index = 0; - Py_ssize_t __pyx_bshape_0_left_index = 0; - Py_buffer __pyx_bstruct_dimensions; - Py_ssize_t __pyx_bstride_0_dimensions = 0; - Py_ssize_t __pyx_bshape_0_dimensions = 0; - Py_buffer __pyx_bstruct_grid_file_locations; - Py_ssize_t __pyx_bstride_0_grid_file_locations = 0; - Py_ssize_t __pyx_bstride_1_grid_file_locations = 0; - Py_ssize_t __pyx_bshape_0_grid_file_locations = 0; - Py_ssize_t __pyx_bshape_1_grid_file_locations = 0; - Py_buffer __pyx_bstruct_grid_dimensions; - Py_ssize_t __pyx_bstride_0_grid_dimensions = 0; - Py_ssize_t __pyx_bstride_1_grid_dimensions = 0; - Py_ssize_t __pyx_bshape_0_grid_dimensions = 0; - Py_ssize_t __pyx_bshape_1_grid_dimensions = 0; - Py_buffer __pyx_bstruct_sig1; - Py_ssize_t __pyx_bstride_0_sig1 = 0; - Py_ssize_t __pyx_bshape_0_sig1 = 0; - Py_buffer __pyx_bstruct_sig2; - Py_ssize_t __pyx_bstride_0_sig2 = 0; - Py_ssize_t __pyx_bshape_0_sig2 = 0; - Py_buffer __pyx_bstruct_sig0; - Py_ssize_t __pyx_bstride_0_sig0 = 0; - Py_ssize_t __pyx_bshape_0_sig0 = 0; - Py_buffer __pyx_bstruct_left_edges; - Py_ssize_t __pyx_bstride_0_left_edges = 0; - Py_ssize_t __pyx_bstride_1_left_edges = 0; - Py_ssize_t __pyx_bshape_0_left_edges = 0; - Py_ssize_t __pyx_bshape_1_left_edges = 0; - int __pyx_r; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - long __pyx_t_8; - int __pyx_t_9; - long __pyx_t_10; - long __pyx_t_11; - int __pyx_t_12; - long __pyx_t_13; - int __pyx_t_14; - long __pyx_t_15; - int __pyx_t_16; - long __pyx_t_17; - int __pyx_t_18; - long __pyx_t_19; - long __pyx_t_20; - int __pyx_t_21; - long __pyx_t_22; - int __pyx_t_23; - long __pyx_t_24; - int __pyx_t_25; - long __pyx_t_26; - int __pyx_t_27; - long __pyx_t_28; - long __pyx_t_29; - int __pyx_t_30; - long __pyx_t_31; - int __pyx_t_32; - long __pyx_t_33; - int __pyx_t_34; - int __pyx_t_35; - int __pyx_t_36; - int __pyx_t_37; - int __pyx_t_38; - int __pyx_t_39; - int __pyx_t_40; - int __pyx_t_41; - PyObject *__pyx_t_42 = NULL; - PyObject *__pyx_t_43 = NULL; - PyArrayObject *__pyx_t_44 = NULL; - PyObject *__pyx_t_45 = NULL; - PyObject *__pyx_t_46 = NULL; - PyObject *__pyx_t_47 = NULL; - int __pyx_t_48; - long __pyx_t_49; - int __pyx_t_50; - __pyx_t_5numpy_int64_t __pyx_t_51; - int __pyx_t_52; - long __pyx_t_53; - int __pyx_t_54; - long __pyx_t_55; - int __pyx_t_56; - __pyx_t_5numpy_int64_t __pyx_t_57; - int __pyx_t_58; - long __pyx_t_59; - int __pyx_t_60; - long __pyx_t_61; - int __pyx_t_62; - __pyx_t_5numpy_int64_t __pyx_t_63; - int __pyx_t_64; - long __pyx_t_65; - int __pyx_t_66; - int __pyx_t_67; - int __pyx_t_68; - int __pyx_t_69; - long __pyx_t_70; - long __pyx_t_71; - long __pyx_t_72; - long __pyx_t_73; - int __pyx_t_74; - long __pyx_t_75; - int __pyx_t_76; - long __pyx_t_77; - int __pyx_t_78; - PyObject *__pyx_t_79 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__left_index,&__pyx_n_s__dimensions,&__pyx_n_s__left_edges,&__pyx_n_s__right_edges,&__pyx_n_s__grid_dimensions,&__pyx_n_s__grid_file_locations,0}; - __Pyx_RefNannySetupContext("__cinit__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[6] = {0,0,0,0,0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_index); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dimensions); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__left_edges); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__right_edges); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_dimensions); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grid_file_locations); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_left_index = ((PyArrayObject *)values[0]); - __pyx_v_dimensions = ((PyArrayObject *)values[1]); - __pyx_v_left_edges = ((PyArrayObject *)values[2]); - __pyx_v_right_edges = ((PyArrayObject *)values[3]); - __pyx_v_grid_dimensions = ((PyArrayObject *)values[4]); - __pyx_v_grid_file_locations = ((PyArrayObject *)values[5]); - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_left_index = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 0)); - __pyx_v_dimensions = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 1)); - __pyx_v_left_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 2)); - __pyx_v_right_edges = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 3)); - __pyx_v_grid_dimensions = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 4)); - __pyx_v_grid_file_locations = ((PyArrayObject *)PyTuple_GET_ITEM(__pyx_args, 5)); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("yt.ramses_reader.ProtoSubgrid.__cinit__"); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_v_sig0 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_sig1 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_sig2 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_sig0.buf = NULL; - __pyx_bstruct_sig1.buf = NULL; - __pyx_bstruct_sig2.buf = NULL; - __pyx_bstruct_left_index.buf = NULL; - __pyx_bstruct_dimensions.buf = NULL; - __pyx_bstruct_left_edges.buf = NULL; - __pyx_bstruct_right_edges.buf = NULL; - __pyx_bstruct_grid_dimensions.buf = NULL; - __pyx_bstruct_grid_file_locations.buf = NULL; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_index), __pyx_ptype_5numpy_ndarray, 1, "left_index", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dimensions), __pyx_ptype_5numpy_ndarray, 1, "dimensions", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_left_edges), __pyx_ptype_5numpy_ndarray, 1, "left_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_right_edges), __pyx_ptype_5numpy_ndarray, 1, "right_edges", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_dimensions), __pyx_ptype_5numpy_ndarray, 1, "grid_dimensions", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grid_file_locations), __pyx_ptype_5numpy_ndarray, 1, "grid_file_locations", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_index, (PyObject*)__pyx_v_left_index, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_index = __pyx_bstruct_left_index.strides[0]; - __pyx_bshape_0_left_index = __pyx_bstruct_left_index.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_dimensions, (PyObject*)__pyx_v_dimensions, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_dimensions = __pyx_bstruct_dimensions.strides[0]; - __pyx_bshape_0_dimensions = __pyx_bstruct_dimensions.shape[0]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_left_edges, (PyObject*)__pyx_v_left_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_left_edges = __pyx_bstruct_left_edges.strides[0]; __pyx_bstride_1_left_edges = __pyx_bstruct_left_edges.strides[1]; - __pyx_bshape_0_left_edges = __pyx_bstruct_left_edges.shape[0]; __pyx_bshape_1_left_edges = __pyx_bstruct_left_edges.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_right_edges, (PyObject*)__pyx_v_right_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_right_edges = __pyx_bstruct_right_edges.strides[0]; __pyx_bstride_1_right_edges = __pyx_bstruct_right_edges.strides[1]; - __pyx_bshape_0_right_edges = __pyx_bstruct_right_edges.shape[0]; __pyx_bshape_1_right_edges = __pyx_bstruct_right_edges.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_dimensions, (PyObject*)__pyx_v_grid_dimensions, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_dimensions = __pyx_bstruct_grid_dimensions.strides[0]; __pyx_bstride_1_grid_dimensions = __pyx_bstruct_grid_dimensions.strides[1]; - __pyx_bshape_0_grid_dimensions = __pyx_bstruct_grid_dimensions.shape[0]; __pyx_bshape_1_grid_dimensions = __pyx_bstruct_grid_dimensions.shape[1]; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_grid_file_locations, (PyObject*)__pyx_v_grid_file_locations, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_bstride_0_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[0]; __pyx_bstride_1_grid_file_locations = __pyx_bstruct_grid_file_locations.strides[1]; - __pyx_bshape_0_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[0]; __pyx_bshape_1_grid_file_locations = __pyx_bstruct_grid_file_locations.shape[1]; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":679 - * np.ndarray[np.int64_t, ndim=2] grid_file_locations): - * # This also includes the shrinking step. - * cdef int i, ci, ng = left_edges.shape[0] # <<<<<<<<<<<<<< - * cdef np.ndarray temp_arr - * cdef int l0, r0, l1, r1, l2, r2, i0, i1, i2 - */ - __pyx_v_ng = (__pyx_v_left_edges->dimensions[0]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":684 - * cdef np.int64_t temp_l[3], temp_r[3], ncells - * cdef np.float64_t efficiency - * self.sigs = [] # <<<<<<<<<<<<<< - * for i in range(3): - * temp_l[i] = left_index[i] + dimensions[i] - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":685 - * cdef np.float64_t efficiency - * self.sigs = [] - * for i in range(3): # <<<<<<<<<<<<<< - * temp_l[i] = left_index[i] + dimensions[i] - * temp_r[i] = left_index[i] - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":686 - * self.sigs = [] - * for i in range(3): - * temp_l[i] = left_index[i] + dimensions[i] # <<<<<<<<<<<<<< - * temp_r[i] = left_index[i] - * self.signature[i] = NULL - */ - __pyx_t_3 = __pyx_v_i; - __pyx_t_4 = -1; - if (__pyx_t_3 < 0) { - __pyx_t_3 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_3 < 0)) __pyx_t_4 = 0; - } else if (unlikely(__pyx_t_3 >= __pyx_bshape_0_left_index)) __pyx_t_4 = 0; - if (unlikely(__pyx_t_4 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_4); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = __pyx_v_i; - __pyx_t_5 = -1; - if (__pyx_t_4 < 0) { - __pyx_t_4 += __pyx_bshape_0_dimensions; - if (unlikely(__pyx_t_4 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_4 >= __pyx_bshape_0_dimensions)) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_temp_l[__pyx_v_i]) = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_3, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_4, __pyx_bstride_0_dimensions))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":687 - * for i in range(3): - * temp_l[i] = left_index[i] + dimensions[i] - * temp_r[i] = left_index[i] # <<<<<<<<<<<<<< - * self.signature[i] = NULL - * for gi in range(ng): - */ - __pyx_t_5 = __pyx_v_i; - __pyx_t_6 = -1; - if (__pyx_t_5 < 0) { - __pyx_t_5 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_5 < 0)) __pyx_t_6 = 0; - } else if (unlikely(__pyx_t_5 >= __pyx_bshape_0_left_index)) __pyx_t_6 = 0; - if (unlikely(__pyx_t_6 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_6); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_temp_r[__pyx_v_i]) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_5, __pyx_bstride_0_left_index)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":688 - * temp_l[i] = left_index[i] + dimensions[i] - * temp_r[i] = left_index[i] - * self.signature[i] = NULL # <<<<<<<<<<<<<< - * for gi in range(ng): - * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ - */ - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->signature[__pyx_v_i]) = NULL; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":689 - * temp_r[i] = left_index[i] - * self.signature[i] = NULL - * for gi in range(ng): # <<<<<<<<<<<<<< - * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ - * right_edges[gi,0] < left_index[0] or \ - */ - __pyx_t_2 = __pyx_v_ng; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_2; __pyx_t_6+=1) { - __pyx_v_gi = __pyx_t_6; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":690 - * self.signature[i] = NULL - * for gi in range(ng): - * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ # <<<<<<<<<<<<<< - * right_edges[gi,0] < left_index[0] or \ - * left_edges[gi,1] > left_index[1]+dimensions[1] or \ - */ - __pyx_t_7 = __pyx_v_gi; - __pyx_t_8 = 0; - __pyx_t_9 = -1; - if (__pyx_t_7 < 0) { - __pyx_t_7 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_7 < 0)) __pyx_t_9 = 0; - } else if (unlikely(__pyx_t_7 >= __pyx_bshape_0_left_edges)) __pyx_t_9 = 0; - if (__pyx_t_8 < 0) { - __pyx_t_8 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_8 < 0)) __pyx_t_9 = 1; - } else if (unlikely(__pyx_t_8 >= __pyx_bshape_1_left_edges)) __pyx_t_9 = 1; - if (unlikely(__pyx_t_9 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_9); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = 0; - __pyx_t_9 = -1; - if (__pyx_t_10 < 0) { - __pyx_t_10 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_10 < 0)) __pyx_t_9 = 0; - } else if (unlikely(__pyx_t_10 >= __pyx_bshape_0_left_index)) __pyx_t_9 = 0; - if (unlikely(__pyx_t_9 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_9); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_11 = 0; - __pyx_t_9 = -1; - if (__pyx_t_11 < 0) { - __pyx_t_11 += __pyx_bshape_0_dimensions; - if (unlikely(__pyx_t_11 < 0)) __pyx_t_9 = 0; - } else if (unlikely(__pyx_t_11 >= __pyx_bshape_0_dimensions)) __pyx_t_9 = 0; - if (unlikely(__pyx_t_9 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_9); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_12 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_7, __pyx_bstride_0_left_edges, __pyx_t_8, __pyx_bstride_1_left_edges)) > ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_10, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_11, __pyx_bstride_0_dimensions)))); - if (!__pyx_t_12) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":691 - * for gi in range(ng): - * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ - * right_edges[gi,0] < left_index[0] or \ # <<<<<<<<<<<<<< - * left_edges[gi,1] > left_index[1]+dimensions[1] or \ - * right_edges[gi,1] < left_index[1] or \ - */ - __pyx_t_9 = __pyx_v_gi; - __pyx_t_13 = 0; - __pyx_t_14 = -1; - if (__pyx_t_9 < 0) { - __pyx_t_9 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_9 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_9 >= __pyx_bshape_0_right_edges)) __pyx_t_14 = 0; - if (__pyx_t_13 < 0) { - __pyx_t_13 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 1; - } else if (unlikely(__pyx_t_13 >= __pyx_bshape_1_right_edges)) __pyx_t_14 = 1; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = 0; - __pyx_t_14 = -1; - if (__pyx_t_15 < 0) { - __pyx_t_15 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_15 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_15 >= __pyx_bshape_0_left_index)) __pyx_t_14 = 0; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_16 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_9, __pyx_bstride_0_right_edges, __pyx_t_13, __pyx_bstride_1_right_edges)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_15, __pyx_bstride_0_left_index))); - if (!__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":692 - * if left_edges[gi,0] > left_index[0]+dimensions[0] or \ - * right_edges[gi,0] < left_index[0] or \ - * left_edges[gi,1] > left_index[1]+dimensions[1] or \ # <<<<<<<<<<<<<< - * right_edges[gi,1] < left_index[1] or \ - * left_edges[gi,2] > left_index[2]+dimensions[2] or \ - */ - __pyx_t_14 = __pyx_v_gi; - __pyx_t_17 = 1; - __pyx_t_18 = -1; - if (__pyx_t_14 < 0) { - __pyx_t_14 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_14 < 0)) __pyx_t_18 = 0; - } else if (unlikely(__pyx_t_14 >= __pyx_bshape_0_left_edges)) __pyx_t_18 = 0; - if (__pyx_t_17 < 0) { - __pyx_t_17 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_17 < 0)) __pyx_t_18 = 1; - } else if (unlikely(__pyx_t_17 >= __pyx_bshape_1_left_edges)) __pyx_t_18 = 1; - if (unlikely(__pyx_t_18 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_18); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_19 = 1; - __pyx_t_18 = -1; - if (__pyx_t_19 < 0) { - __pyx_t_19 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_19 < 0)) __pyx_t_18 = 0; - } else if (unlikely(__pyx_t_19 >= __pyx_bshape_0_left_index)) __pyx_t_18 = 0; - if (unlikely(__pyx_t_18 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_18); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_20 = 1; - __pyx_t_18 = -1; - if (__pyx_t_20 < 0) { - __pyx_t_20 += __pyx_bshape_0_dimensions; - if (unlikely(__pyx_t_20 < 0)) __pyx_t_18 = 0; - } else if (unlikely(__pyx_t_20 >= __pyx_bshape_0_dimensions)) __pyx_t_18 = 0; - if (unlikely(__pyx_t_18 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_18); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_21 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_14, __pyx_bstride_0_left_edges, __pyx_t_17, __pyx_bstride_1_left_edges)) > ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_19, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_20, __pyx_bstride_0_dimensions)))); - if (!__pyx_t_21) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":693 - * right_edges[gi,0] < left_index[0] or \ - * left_edges[gi,1] > left_index[1]+dimensions[1] or \ - * right_edges[gi,1] < left_index[1] or \ # <<<<<<<<<<<<<< - * left_edges[gi,2] > left_index[2]+dimensions[2] or \ - * right_edges[gi,2] < left_index[2]: - */ - __pyx_t_18 = __pyx_v_gi; - __pyx_t_22 = 1; - __pyx_t_23 = -1; - if (__pyx_t_18 < 0) { - __pyx_t_18 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_18 < 0)) __pyx_t_23 = 0; - } else if (unlikely(__pyx_t_18 >= __pyx_bshape_0_right_edges)) __pyx_t_23 = 0; - if (__pyx_t_22 < 0) { - __pyx_t_22 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_22 < 0)) __pyx_t_23 = 1; - } else if (unlikely(__pyx_t_22 >= __pyx_bshape_1_right_edges)) __pyx_t_23 = 1; - if (unlikely(__pyx_t_23 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_23); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_24 = 1; - __pyx_t_23 = -1; - if (__pyx_t_24 < 0) { - __pyx_t_24 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_24 < 0)) __pyx_t_23 = 0; - } else if (unlikely(__pyx_t_24 >= __pyx_bshape_0_left_index)) __pyx_t_23 = 0; - if (unlikely(__pyx_t_23 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_23); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_25 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_18, __pyx_bstride_0_right_edges, __pyx_t_22, __pyx_bstride_1_right_edges)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_24, __pyx_bstride_0_left_index))); - if (!__pyx_t_25) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":694 - * left_edges[gi,1] > left_index[1]+dimensions[1] or \ - * right_edges[gi,1] < left_index[1] or \ - * left_edges[gi,2] > left_index[2]+dimensions[2] or \ # <<<<<<<<<<<<<< - * right_edges[gi,2] < left_index[2]: - * #print "Skipping grid", gi, "which lies outside out box" - */ - __pyx_t_23 = __pyx_v_gi; - __pyx_t_26 = 2; - __pyx_t_27 = -1; - if (__pyx_t_23 < 0) { - __pyx_t_23 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_23 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_23 >= __pyx_bshape_0_left_edges)) __pyx_t_27 = 0; - if (__pyx_t_26 < 0) { - __pyx_t_26 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_26 < 0)) __pyx_t_27 = 1; - } else if (unlikely(__pyx_t_26 >= __pyx_bshape_1_left_edges)) __pyx_t_27 = 1; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_28 = 2; - __pyx_t_27 = -1; - if (__pyx_t_28 < 0) { - __pyx_t_28 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_28 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_28 >= __pyx_bshape_0_left_index)) __pyx_t_27 = 0; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_29 = 2; - __pyx_t_27 = -1; - if (__pyx_t_29 < 0) { - __pyx_t_29 += __pyx_bshape_0_dimensions; - if (unlikely(__pyx_t_29 < 0)) __pyx_t_27 = 0; - } else if (unlikely(__pyx_t_29 >= __pyx_bshape_0_dimensions)) __pyx_t_27 = 0; - if (unlikely(__pyx_t_27 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_27); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_30 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_23, __pyx_bstride_0_left_edges, __pyx_t_26, __pyx_bstride_1_left_edges)) > ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_28, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_29, __pyx_bstride_0_dimensions)))); - if (!__pyx_t_30) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":695 - * right_edges[gi,1] < left_index[1] or \ - * left_edges[gi,2] > left_index[2]+dimensions[2] or \ - * right_edges[gi,2] < left_index[2]: # <<<<<<<<<<<<<< - * #print "Skipping grid", gi, "which lies outside out box" - * continue - */ - __pyx_t_27 = __pyx_v_gi; - __pyx_t_31 = 2; - __pyx_t_32 = -1; - if (__pyx_t_27 < 0) { - __pyx_t_27 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_27 < 0)) __pyx_t_32 = 0; - } else if (unlikely(__pyx_t_27 >= __pyx_bshape_0_right_edges)) __pyx_t_32 = 0; - if (__pyx_t_31 < 0) { - __pyx_t_31 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_31 < 0)) __pyx_t_32 = 1; - } else if (unlikely(__pyx_t_31 >= __pyx_bshape_1_right_edges)) __pyx_t_32 = 1; - if (unlikely(__pyx_t_32 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_32); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_33 = 2; - __pyx_t_32 = -1; - if (__pyx_t_33 < 0) { - __pyx_t_33 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_33 < 0)) __pyx_t_32 = 0; - } else if (unlikely(__pyx_t_33 >= __pyx_bshape_0_left_index)) __pyx_t_32 = 0; - if (unlikely(__pyx_t_32 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_32); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_34 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_27, __pyx_bstride_0_right_edges, __pyx_t_31, __pyx_bstride_1_right_edges)) < (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_33, __pyx_bstride_0_left_index))); - __pyx_t_35 = __pyx_t_34; - } else { - __pyx_t_35 = __pyx_t_30; - } - __pyx_t_30 = __pyx_t_35; - } else { - __pyx_t_30 = __pyx_t_25; - } - __pyx_t_25 = __pyx_t_30; - } else { - __pyx_t_25 = __pyx_t_21; - } - __pyx_t_21 = __pyx_t_25; - } else { - __pyx_t_21 = __pyx_t_16; - } - __pyx_t_16 = __pyx_t_21; - } else { - __pyx_t_16 = __pyx_t_12; - } - if (__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":697 - * right_edges[gi,2] < left_index[2]: - * #print "Skipping grid", gi, "which lies outside out box" - * continue # <<<<<<<<<<<<<< - * for i in range(3): - * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) - */ - goto __pyx_L8_continue; - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":698 - * #print "Skipping grid", gi, "which lies outside out box" - * continue - * for i in range(3): # <<<<<<<<<<<<<< - * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) - * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) - */ - for (__pyx_t_32 = 0; __pyx_t_32 < 3; __pyx_t_32+=1) { - __pyx_v_i = __pyx_t_32; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":699 - * continue - * for i in range(3): - * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) # <<<<<<<<<<<<<< - * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) - * for i in range(3): - */ - __pyx_t_36 = __pyx_v_gi; - __pyx_t_37 = __pyx_v_i; - __pyx_t_38 = -1; - if (__pyx_t_36 < 0) { - __pyx_t_36 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_36 < 0)) __pyx_t_38 = 0; - } else if (unlikely(__pyx_t_36 >= __pyx_bshape_0_left_edges)) __pyx_t_38 = 0; - if (__pyx_t_37 < 0) { - __pyx_t_37 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_37 < 0)) __pyx_t_38 = 1; - } else if (unlikely(__pyx_t_37 >= __pyx_bshape_1_left_edges)) __pyx_t_38 = 1; - if (unlikely(__pyx_t_38 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_38); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_temp_l[__pyx_v_i]) = __pyx_f_2yt_13ramses_reader_i64min((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_36, __pyx_bstride_0_left_edges, __pyx_t_37, __pyx_bstride_1_left_edges)), (__pyx_v_temp_l[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":700 - * for i in range(3): - * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) - * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) # <<<<<<<<<<<<<< - * for i in range(3): - * self.left_edge[i] = i64max(temp_l[i], left_index[i]) - */ - __pyx_t_38 = __pyx_v_gi; - __pyx_t_39 = __pyx_v_i; - __pyx_t_40 = -1; - if (__pyx_t_38 < 0) { - __pyx_t_38 += __pyx_bshape_0_right_edges; - if (unlikely(__pyx_t_38 < 0)) __pyx_t_40 = 0; - } else if (unlikely(__pyx_t_38 >= __pyx_bshape_0_right_edges)) __pyx_t_40 = 0; - if (__pyx_t_39 < 0) { - __pyx_t_39 += __pyx_bshape_1_right_edges; - if (unlikely(__pyx_t_39 < 0)) __pyx_t_40 = 1; - } else if (unlikely(__pyx_t_39 >= __pyx_bshape_1_right_edges)) __pyx_t_40 = 1; - if (unlikely(__pyx_t_40 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_40); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_temp_r[__pyx_v_i]) = __pyx_f_2yt_13ramses_reader_i64max((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_right_edges.buf, __pyx_t_38, __pyx_bstride_0_right_edges, __pyx_t_39, __pyx_bstride_1_right_edges)), (__pyx_v_temp_r[__pyx_v_i])); - } - __pyx_L8_continue:; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":701 - * temp_l[i] = i64min(left_edges[gi,i], temp_l[i]) - * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) - * for i in range(3): # <<<<<<<<<<<<<< - * self.left_edge[i] = i64max(temp_l[i], left_index[i]) - * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":702 - * temp_r[i] = i64max(right_edges[gi,i], temp_r[i]) - * for i in range(3): - * self.left_edge[i] = i64max(temp_l[i], left_index[i]) # <<<<<<<<<<<<<< - * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) - * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] - */ - __pyx_t_6 = __pyx_v_i; - __pyx_t_32 = -1; - if (__pyx_t_6 < 0) { - __pyx_t_6 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_6 < 0)) __pyx_t_32 = 0; - } else if (unlikely(__pyx_t_6 >= __pyx_bshape_0_left_index)) __pyx_t_32 = 0; - if (unlikely(__pyx_t_32 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_32); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[__pyx_v_i]) = __pyx_f_2yt_13ramses_reader_i64max((__pyx_v_temp_l[__pyx_v_i]), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_6, __pyx_bstride_0_left_index))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":703 - * for i in range(3): - * self.left_edge[i] = i64max(temp_l[i], left_index[i]) - * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) # <<<<<<<<<<<<<< - * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] - * if self.dimensions[i] <= 0: - */ - __pyx_t_32 = __pyx_v_i; - __pyx_t_40 = -1; - if (__pyx_t_32 < 0) { - __pyx_t_32 += __pyx_bshape_0_left_index; - if (unlikely(__pyx_t_32 < 0)) __pyx_t_40 = 0; - } else if (unlikely(__pyx_t_32 >= __pyx_bshape_0_left_index)) __pyx_t_40 = 0; - if (unlikely(__pyx_t_40 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_40); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_40 = __pyx_v_i; - __pyx_t_41 = -1; - if (__pyx_t_40 < 0) { - __pyx_t_40 += __pyx_bshape_0_dimensions; - if (unlikely(__pyx_t_40 < 0)) __pyx_t_41 = 0; - } else if (unlikely(__pyx_t_40 >= __pyx_bshape_0_dimensions)) __pyx_t_41 = 0; - if (unlikely(__pyx_t_41 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_41); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[__pyx_v_i]) = __pyx_f_2yt_13ramses_reader_i64min((__pyx_v_temp_r[__pyx_v_i]), ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_index.buf, __pyx_t_32, __pyx_bstride_0_left_index)) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_dimensions.buf, __pyx_t_40, __pyx_bstride_0_dimensions)))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":704 - * self.left_edge[i] = i64max(temp_l[i], left_index[i]) - * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) - * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] # <<<<<<<<<<<<<< - * if self.dimensions[i] <= 0: - * self.efficiency = -1.0 - */ - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]) = ((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[__pyx_v_i]) - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[__pyx_v_i])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":705 - * self.right_edge[i] = i64min(temp_r[i], left_index[i] + dimensions[i]) - * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] - * if self.dimensions[i] <= 0: # <<<<<<<<<<<<<< - * self.efficiency = -1.0 - * return - */ - __pyx_t_16 = ((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]) <= 0); - if (__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":706 - * self.dimensions[i] = self.right_edge[i] - self.left_edge[i] - * if self.dimensions[i] <= 0: - * self.efficiency = -1.0 # <<<<<<<<<<<<<< - * return - * self.sigs.append(np.zeros(self.dimensions[i], 'int64')) - */ - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency = (-1.0); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":707 - * if self.dimensions[i] <= 0: - * self.efficiency = -1.0 - * return # <<<<<<<<<<<<<< - * self.sigs.append(np.zeros(self.dimensions[i], 'int64')) - * #print self.sigs[0].size, self.sigs[1].size, self.sigs[2].size - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":708 - * self.efficiency = -1.0 - * return - * self.sigs.append(np.zeros(self.dimensions[i], 'int64')) # <<<<<<<<<<<<<< - * #print self.sigs[0].size, self.sigs[1].size, self.sigs[2].size - * - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_42 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_42); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_43 = PyTuple_New(2); if (unlikely(!__pyx_t_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_43); - PyTuple_SET_ITEM(__pyx_t_43, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__int64)); - PyTuple_SET_ITEM(__pyx_t_43, 1, ((PyObject *)__pyx_n_s__int64)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__int64)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_42, __pyx_t_43, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; - __Pyx_DECREF(__pyx_t_43); __pyx_t_43 = 0; - __pyx_t_43 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, __pyx_t_1); if (unlikely(!__pyx_t_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_43); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_43); __pyx_t_43 = 0; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":715 - * # pass. - * cdef np.ndarray[np.int64_t, ndim=1] sig0, sig1, sig2 - * sig0 = self.sigs[0] # <<<<<<<<<<<<<< - * sig1 = self.sigs[1] - * sig2 = self.sigs[2] - */ - __pyx_t_43 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_43) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_43); - if (!(likely(((__pyx_t_43) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_43, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_44 = ((PyArrayObject *)__pyx_t_43); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig0); - __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig0, (PyObject*)__pyx_t_44, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_2 < 0)) { - PyErr_Fetch(&__pyx_t_45, &__pyx_t_46, &__pyx_t_47); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig0, (PyObject*)__pyx_v_sig0, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_45); Py_XDECREF(__pyx_t_46); Py_XDECREF(__pyx_t_47); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_45, __pyx_t_46, __pyx_t_47); - } - } - __pyx_bstride_0_sig0 = __pyx_bstruct_sig0.strides[0]; - __pyx_bshape_0_sig0 = __pyx_bstruct_sig0.shape[0]; - if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_44 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_sig0)); - __pyx_v_sig0 = ((PyArrayObject *)__pyx_t_43); - __pyx_t_43 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":716 - * cdef np.ndarray[np.int64_t, ndim=1] sig0, sig1, sig2 - * sig0 = self.sigs[0] - * sig1 = self.sigs[1] # <<<<<<<<<<<<<< - * sig2 = self.sigs[2] - * efficiency = 0.0 - */ - __pyx_t_43 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_43) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_43); - if (!(likely(((__pyx_t_43) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_43, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_44 = ((PyArrayObject *)__pyx_t_43); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig1); - __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig1, (PyObject*)__pyx_t_44, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_2 < 0)) { - PyErr_Fetch(&__pyx_t_47, &__pyx_t_46, &__pyx_t_45); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig1, (PyObject*)__pyx_v_sig1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_47); Py_XDECREF(__pyx_t_46); Py_XDECREF(__pyx_t_45); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_47, __pyx_t_46, __pyx_t_45); - } - } - __pyx_bstride_0_sig1 = __pyx_bstruct_sig1.strides[0]; - __pyx_bshape_0_sig1 = __pyx_bstruct_sig1.shape[0]; - if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_44 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_sig1)); - __pyx_v_sig1 = ((PyArrayObject *)__pyx_t_43); - __pyx_t_43 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":717 - * sig0 = self.sigs[0] - * sig1 = self.sigs[1] - * sig2 = self.sigs[2] # <<<<<<<<<<<<<< - * efficiency = 0.0 - * cdef int used - */ - __pyx_t_43 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_43) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_43); - if (!(likely(((__pyx_t_43) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_43, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_44 = ((PyArrayObject *)__pyx_t_43); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig2); - __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig2, (PyObject*)__pyx_t_44, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_2 < 0)) { - PyErr_Fetch(&__pyx_t_45, &__pyx_t_46, &__pyx_t_47); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig2, (PyObject*)__pyx_v_sig2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_45); Py_XDECREF(__pyx_t_46); Py_XDECREF(__pyx_t_47); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_45, __pyx_t_46, __pyx_t_47); - } - } - __pyx_bstride_0_sig2 = __pyx_bstruct_sig2.strides[0]; - __pyx_bshape_0_sig2 = __pyx_bstruct_sig2.shape[0]; - if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_44 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_sig2)); - __pyx_v_sig2 = ((PyArrayObject *)__pyx_t_43); - __pyx_t_43 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":718 - * sig1 = self.sigs[1] - * sig2 = self.sigs[2] - * efficiency = 0.0 # <<<<<<<<<<<<<< - * cdef int used - * self.grid_file_locations = [] - */ - __pyx_v_efficiency = 0.0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":720 - * efficiency = 0.0 - * cdef int used - * self.grid_file_locations = [] # <<<<<<<<<<<<<< - * for gi in range(ng): - * used = 0 - */ - __pyx_t_43 = PyList_New(0); if (unlikely(!__pyx_t_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_43)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_43)); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations = ((PyObject *)__pyx_t_43); - __pyx_t_43 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":721 - * cdef int used - * self.grid_file_locations = [] - * for gi in range(ng): # <<<<<<<<<<<<<< - * used = 0 - * nnn = 0 - */ - __pyx_t_2 = __pyx_v_ng; - for (__pyx_t_41 = 0; __pyx_t_41 < __pyx_t_2; __pyx_t_41+=1) { - __pyx_v_gi = __pyx_t_41; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":722 - * self.grid_file_locations = [] - * for gi in range(ng): - * used = 0 # <<<<<<<<<<<<<< - * nnn = 0 - * for l0 in range(grid_dimensions[gi, 0]): - */ - __pyx_v_used = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":723 - * for gi in range(ng): - * used = 0 - * nnn = 0 # <<<<<<<<<<<<<< - * for l0 in range(grid_dimensions[gi, 0]): - * i0 = left_edges[gi, 0] + l0 - */ - __pyx_v_nnn = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":724 - * used = 0 - * nnn = 0 - * for l0 in range(grid_dimensions[gi, 0]): # <<<<<<<<<<<<<< - * i0 = left_edges[gi, 0] + l0 - * if i0 < self.left_edge[0]: continue - */ - __pyx_t_48 = __pyx_v_gi; - __pyx_t_49 = 0; - __pyx_t_50 = -1; - if (__pyx_t_48 < 0) { - __pyx_t_48 += __pyx_bshape_0_grid_dimensions; - if (unlikely(__pyx_t_48 < 0)) __pyx_t_50 = 0; - } else if (unlikely(__pyx_t_48 >= __pyx_bshape_0_grid_dimensions)) __pyx_t_50 = 0; - if (__pyx_t_49 < 0) { - __pyx_t_49 += __pyx_bshape_1_grid_dimensions; - if (unlikely(__pyx_t_49 < 0)) __pyx_t_50 = 1; - } else if (unlikely(__pyx_t_49 >= __pyx_bshape_1_grid_dimensions)) __pyx_t_50 = 1; - if (unlikely(__pyx_t_50 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_50); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_51 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_dimensions.buf, __pyx_t_48, __pyx_bstride_0_grid_dimensions, __pyx_t_49, __pyx_bstride_1_grid_dimensions)); - for (__pyx_t_50 = 0; __pyx_t_50 < __pyx_t_51; __pyx_t_50+=1) { - __pyx_v_l0 = __pyx_t_50; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":725 - * nnn = 0 - * for l0 in range(grid_dimensions[gi, 0]): - * i0 = left_edges[gi, 0] + l0 # <<<<<<<<<<<<<< - * if i0 < self.left_edge[0]: continue - * if i0 >= self.right_edge[0]: break - */ - __pyx_t_52 = __pyx_v_gi; - __pyx_t_53 = 0; - __pyx_t_54 = -1; - if (__pyx_t_52 < 0) { - __pyx_t_52 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_52 < 0)) __pyx_t_54 = 0; - } else if (unlikely(__pyx_t_52 >= __pyx_bshape_0_left_edges)) __pyx_t_54 = 0; - if (__pyx_t_53 < 0) { - __pyx_t_53 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_53 < 0)) __pyx_t_54 = 1; - } else if (unlikely(__pyx_t_53 >= __pyx_bshape_1_left_edges)) __pyx_t_54 = 1; - if (unlikely(__pyx_t_54 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_54); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_i0 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_52, __pyx_bstride_0_left_edges, __pyx_t_53, __pyx_bstride_1_left_edges)) + __pyx_v_l0); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":726 - * for l0 in range(grid_dimensions[gi, 0]): - * i0 = left_edges[gi, 0] + l0 - * if i0 < self.left_edge[0]: continue # <<<<<<<<<<<<<< - * if i0 >= self.right_edge[0]: break - * for l1 in range(grid_dimensions[gi, 1]): - */ - __pyx_t_16 = (__pyx_v_i0 < (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[0])); - if (__pyx_t_16) { - goto __pyx_L18_continue; - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":727 - * i0 = left_edges[gi, 0] + l0 - * if i0 < self.left_edge[0]: continue - * if i0 >= self.right_edge[0]: break # <<<<<<<<<<<<<< - * for l1 in range(grid_dimensions[gi, 1]): - * i1 = left_edges[gi, 1] + l1 - */ - __pyx_t_16 = (__pyx_v_i0 >= (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[0])); - if (__pyx_t_16) { - goto __pyx_L19_break; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":728 - * if i0 < self.left_edge[0]: continue - * if i0 >= self.right_edge[0]: break - * for l1 in range(grid_dimensions[gi, 1]): # <<<<<<<<<<<<<< - * i1 = left_edges[gi, 1] + l1 - * if i1 < self.left_edge[1]: continue - */ - __pyx_t_54 = __pyx_v_gi; - __pyx_t_55 = 1; - __pyx_t_56 = -1; - if (__pyx_t_54 < 0) { - __pyx_t_54 += __pyx_bshape_0_grid_dimensions; - if (unlikely(__pyx_t_54 < 0)) __pyx_t_56 = 0; - } else if (unlikely(__pyx_t_54 >= __pyx_bshape_0_grid_dimensions)) __pyx_t_56 = 0; - if (__pyx_t_55 < 0) { - __pyx_t_55 += __pyx_bshape_1_grid_dimensions; - if (unlikely(__pyx_t_55 < 0)) __pyx_t_56 = 1; - } else if (unlikely(__pyx_t_55 >= __pyx_bshape_1_grid_dimensions)) __pyx_t_56 = 1; - if (unlikely(__pyx_t_56 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_56); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_57 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_dimensions.buf, __pyx_t_54, __pyx_bstride_0_grid_dimensions, __pyx_t_55, __pyx_bstride_1_grid_dimensions)); - for (__pyx_t_56 = 0; __pyx_t_56 < __pyx_t_57; __pyx_t_56+=1) { - __pyx_v_l1 = __pyx_t_56; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":729 - * if i0 >= self.right_edge[0]: break - * for l1 in range(grid_dimensions[gi, 1]): - * i1 = left_edges[gi, 1] + l1 # <<<<<<<<<<<<<< - * if i1 < self.left_edge[1]: continue - * if i1 >= self.right_edge[1]: break - */ - __pyx_t_58 = __pyx_v_gi; - __pyx_t_59 = 1; - __pyx_t_60 = -1; - if (__pyx_t_58 < 0) { - __pyx_t_58 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_58 < 0)) __pyx_t_60 = 0; - } else if (unlikely(__pyx_t_58 >= __pyx_bshape_0_left_edges)) __pyx_t_60 = 0; - if (__pyx_t_59 < 0) { - __pyx_t_59 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_59 < 0)) __pyx_t_60 = 1; - } else if (unlikely(__pyx_t_59 >= __pyx_bshape_1_left_edges)) __pyx_t_60 = 1; - if (unlikely(__pyx_t_60 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_60); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_i1 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_58, __pyx_bstride_0_left_edges, __pyx_t_59, __pyx_bstride_1_left_edges)) + __pyx_v_l1); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":730 - * for l1 in range(grid_dimensions[gi, 1]): - * i1 = left_edges[gi, 1] + l1 - * if i1 < self.left_edge[1]: continue # <<<<<<<<<<<<<< - * if i1 >= self.right_edge[1]: break - * for l2 in range(grid_dimensions[gi, 2]): - */ - __pyx_t_16 = (__pyx_v_i1 < (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[1])); - if (__pyx_t_16) { - goto __pyx_L22_continue; - goto __pyx_L24; - } - __pyx_L24:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":731 - * i1 = left_edges[gi, 1] + l1 - * if i1 < self.left_edge[1]: continue - * if i1 >= self.right_edge[1]: break # <<<<<<<<<<<<<< - * for l2 in range(grid_dimensions[gi, 2]): - * i2 = left_edges[gi, 2] + l2 - */ - __pyx_t_16 = (__pyx_v_i1 >= (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[1])); - if (__pyx_t_16) { - goto __pyx_L23_break; - goto __pyx_L25; - } - __pyx_L25:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":732 - * if i1 < self.left_edge[1]: continue - * if i1 >= self.right_edge[1]: break - * for l2 in range(grid_dimensions[gi, 2]): # <<<<<<<<<<<<<< - * i2 = left_edges[gi, 2] + l2 - * if i2 < self.left_edge[2]: continue - */ - __pyx_t_60 = __pyx_v_gi; - __pyx_t_61 = 2; - __pyx_t_62 = -1; - if (__pyx_t_60 < 0) { - __pyx_t_60 += __pyx_bshape_0_grid_dimensions; - if (unlikely(__pyx_t_60 < 0)) __pyx_t_62 = 0; - } else if (unlikely(__pyx_t_60 >= __pyx_bshape_0_grid_dimensions)) __pyx_t_62 = 0; - if (__pyx_t_61 < 0) { - __pyx_t_61 += __pyx_bshape_1_grid_dimensions; - if (unlikely(__pyx_t_61 < 0)) __pyx_t_62 = 1; - } else if (unlikely(__pyx_t_61 >= __pyx_bshape_1_grid_dimensions)) __pyx_t_62 = 1; - if (unlikely(__pyx_t_62 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_62); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_63 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_dimensions.buf, __pyx_t_60, __pyx_bstride_0_grid_dimensions, __pyx_t_61, __pyx_bstride_1_grid_dimensions)); - for (__pyx_t_62 = 0; __pyx_t_62 < __pyx_t_63; __pyx_t_62+=1) { - __pyx_v_l2 = __pyx_t_62; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":733 - * if i1 >= self.right_edge[1]: break - * for l2 in range(grid_dimensions[gi, 2]): - * i2 = left_edges[gi, 2] + l2 # <<<<<<<<<<<<<< - * if i2 < self.left_edge[2]: continue - * if i2 >= self.right_edge[2]: break - */ - __pyx_t_64 = __pyx_v_gi; - __pyx_t_65 = 2; - __pyx_t_66 = -1; - if (__pyx_t_64 < 0) { - __pyx_t_64 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_64 < 0)) __pyx_t_66 = 0; - } else if (unlikely(__pyx_t_64 >= __pyx_bshape_0_left_edges)) __pyx_t_66 = 0; - if (__pyx_t_65 < 0) { - __pyx_t_65 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_65 < 0)) __pyx_t_66 = 1; - } else if (unlikely(__pyx_t_65 >= __pyx_bshape_1_left_edges)) __pyx_t_66 = 1; - if (unlikely(__pyx_t_66 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_66); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_i2 = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_64, __pyx_bstride_0_left_edges, __pyx_t_65, __pyx_bstride_1_left_edges)) + __pyx_v_l2); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":734 - * for l2 in range(grid_dimensions[gi, 2]): - * i2 = left_edges[gi, 2] + l2 - * if i2 < self.left_edge[2]: continue # <<<<<<<<<<<<<< - * if i2 >= self.right_edge[2]: break - * i = i0 - self.left_edge[0] - */ - __pyx_t_16 = (__pyx_v_i2 < (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[2])); - if (__pyx_t_16) { - goto __pyx_L26_continue; - goto __pyx_L28; - } - __pyx_L28:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":735 - * i2 = left_edges[gi, 2] + l2 - * if i2 < self.left_edge[2]: continue - * if i2 >= self.right_edge[2]: break # <<<<<<<<<<<<<< - * i = i0 - self.left_edge[0] - * sig0[i] += 1 - */ - __pyx_t_16 = (__pyx_v_i2 >= (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->right_edge[2])); - if (__pyx_t_16) { - goto __pyx_L27_break; - goto __pyx_L29; - } - __pyx_L29:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":736 - * if i2 < self.left_edge[2]: continue - * if i2 >= self.right_edge[2]: break - * i = i0 - self.left_edge[0] # <<<<<<<<<<<<<< - * sig0[i] += 1 - * i = i1 - self.left_edge[1] - */ - __pyx_v_i = (__pyx_v_i0 - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[0])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":737 - * if i2 >= self.right_edge[2]: break - * i = i0 - self.left_edge[0] - * sig0[i] += 1 # <<<<<<<<<<<<<< - * i = i1 - self.left_edge[1] - * sig1[i] += 1 - */ - __pyx_t_66 = __pyx_v_i; - __pyx_t_67 = -1; - if (__pyx_t_66 < 0) { - __pyx_t_66 += __pyx_bshape_0_sig0; - if (unlikely(__pyx_t_66 < 0)) __pyx_t_67 = 0; - } else if (unlikely(__pyx_t_66 >= __pyx_bshape_0_sig0)) __pyx_t_67 = 0; - if (unlikely(__pyx_t_67 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_67); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig0.buf, __pyx_t_66, __pyx_bstride_0_sig0) += 1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":738 - * i = i0 - self.left_edge[0] - * sig0[i] += 1 - * i = i1 - self.left_edge[1] # <<<<<<<<<<<<<< - * sig1[i] += 1 - * i = i2 - self.left_edge[2] - */ - __pyx_v_i = (__pyx_v_i1 - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[1])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":739 - * sig0[i] += 1 - * i = i1 - self.left_edge[1] - * sig1[i] += 1 # <<<<<<<<<<<<<< - * i = i2 - self.left_edge[2] - * sig2[i] += 1 - */ - __pyx_t_67 = __pyx_v_i; - __pyx_t_68 = -1; - if (__pyx_t_67 < 0) { - __pyx_t_67 += __pyx_bshape_0_sig1; - if (unlikely(__pyx_t_67 < 0)) __pyx_t_68 = 0; - } else if (unlikely(__pyx_t_67 >= __pyx_bshape_0_sig1)) __pyx_t_68 = 0; - if (unlikely(__pyx_t_68 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_68); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig1.buf, __pyx_t_67, __pyx_bstride_0_sig1) += 1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":740 - * i = i1 - self.left_edge[1] - * sig1[i] += 1 - * i = i2 - self.left_edge[2] # <<<<<<<<<<<<<< - * sig2[i] += 1 - * efficiency += 1 - */ - __pyx_v_i = (__pyx_v_i2 - (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->left_edge[2])); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":741 - * sig1[i] += 1 - * i = i2 - self.left_edge[2] - * sig2[i] += 1 # <<<<<<<<<<<<<< - * efficiency += 1 - * used = 1 - */ - __pyx_t_68 = __pyx_v_i; - __pyx_t_69 = -1; - if (__pyx_t_68 < 0) { - __pyx_t_68 += __pyx_bshape_0_sig2; - if (unlikely(__pyx_t_68 < 0)) __pyx_t_69 = 0; - } else if (unlikely(__pyx_t_68 >= __pyx_bshape_0_sig2)) __pyx_t_69 = 0; - if (unlikely(__pyx_t_69 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_69); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig2.buf, __pyx_t_68, __pyx_bstride_0_sig2) += 1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":742 - * i = i2 - self.left_edge[2] - * sig2[i] += 1 - * efficiency += 1 # <<<<<<<<<<<<<< - * used = 1 - * if used == 1: - */ - __pyx_v_efficiency += 1.0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":743 - * sig2[i] += 1 - * efficiency += 1 - * used = 1 # <<<<<<<<<<<<<< - * if used == 1: - * grid_file_locations[gi,3] = left_edges[gi, 0] - */ - __pyx_v_used = 1; - __pyx_L26_continue:; - } - __pyx_L27_break:; - __pyx_L22_continue:; - } - __pyx_L23_break:; - __pyx_L18_continue:; - } - __pyx_L19_break:; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":744 - * efficiency += 1 - * used = 1 - * if used == 1: # <<<<<<<<<<<<<< - * grid_file_locations[gi,3] = left_edges[gi, 0] - * grid_file_locations[gi,4] = left_edges[gi, 1] - */ - __pyx_t_16 = (__pyx_v_used == 1); - if (__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":745 - * used = 1 - * if used == 1: - * grid_file_locations[gi,3] = left_edges[gi, 0] # <<<<<<<<<<<<<< - * grid_file_locations[gi,4] = left_edges[gi, 1] - * grid_file_locations[gi,5] = left_edges[gi, 2] - */ - __pyx_t_50 = __pyx_v_gi; - __pyx_t_70 = 0; - __pyx_t_56 = -1; - if (__pyx_t_50 < 0) { - __pyx_t_50 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_50 < 0)) __pyx_t_56 = 0; - } else if (unlikely(__pyx_t_50 >= __pyx_bshape_0_left_edges)) __pyx_t_56 = 0; - if (__pyx_t_70 < 0) { - __pyx_t_70 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_70 < 0)) __pyx_t_56 = 1; - } else if (unlikely(__pyx_t_70 >= __pyx_bshape_1_left_edges)) __pyx_t_56 = 1; - if (unlikely(__pyx_t_56 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_56); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_56 = __pyx_v_gi; - __pyx_t_71 = 3; - __pyx_t_62 = -1; - if (__pyx_t_56 < 0) { - __pyx_t_56 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_56 < 0)) __pyx_t_62 = 0; - } else if (unlikely(__pyx_t_56 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_62 = 0; - if (__pyx_t_71 < 0) { - __pyx_t_71 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_71 < 0)) __pyx_t_62 = 1; - } else if (unlikely(__pyx_t_71 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_62 = 1; - if (unlikely(__pyx_t_62 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_62); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_56, __pyx_bstride_0_grid_file_locations, __pyx_t_71, __pyx_bstride_1_grid_file_locations) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_50, __pyx_bstride_0_left_edges, __pyx_t_70, __pyx_bstride_1_left_edges)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":746 - * if used == 1: - * grid_file_locations[gi,3] = left_edges[gi, 0] - * grid_file_locations[gi,4] = left_edges[gi, 1] # <<<<<<<<<<<<<< - * grid_file_locations[gi,5] = left_edges[gi, 2] - * self.grid_file_locations.append(grid_file_locations[gi,:]) - */ - __pyx_t_62 = __pyx_v_gi; - __pyx_t_72 = 1; - __pyx_t_69 = -1; - if (__pyx_t_62 < 0) { - __pyx_t_62 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_62 < 0)) __pyx_t_69 = 0; - } else if (unlikely(__pyx_t_62 >= __pyx_bshape_0_left_edges)) __pyx_t_69 = 0; - if (__pyx_t_72 < 0) { - __pyx_t_72 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_72 < 0)) __pyx_t_69 = 1; - } else if (unlikely(__pyx_t_72 >= __pyx_bshape_1_left_edges)) __pyx_t_69 = 1; - if (unlikely(__pyx_t_69 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_69); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_69 = __pyx_v_gi; - __pyx_t_73 = 4; - __pyx_t_74 = -1; - if (__pyx_t_69 < 0) { - __pyx_t_69 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_69 < 0)) __pyx_t_74 = 0; - } else if (unlikely(__pyx_t_69 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_74 = 0; - if (__pyx_t_73 < 0) { - __pyx_t_73 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_73 < 0)) __pyx_t_74 = 1; - } else if (unlikely(__pyx_t_73 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_74 = 1; - if (unlikely(__pyx_t_74 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_74); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_69, __pyx_bstride_0_grid_file_locations, __pyx_t_73, __pyx_bstride_1_grid_file_locations) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_62, __pyx_bstride_0_left_edges, __pyx_t_72, __pyx_bstride_1_left_edges)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":747 - * grid_file_locations[gi,3] = left_edges[gi, 0] - * grid_file_locations[gi,4] = left_edges[gi, 1] - * grid_file_locations[gi,5] = left_edges[gi, 2] # <<<<<<<<<<<<<< - * self.grid_file_locations.append(grid_file_locations[gi,:]) - * - */ - __pyx_t_74 = __pyx_v_gi; - __pyx_t_75 = 2; - __pyx_t_76 = -1; - if (__pyx_t_74 < 0) { - __pyx_t_74 += __pyx_bshape_0_left_edges; - if (unlikely(__pyx_t_74 < 0)) __pyx_t_76 = 0; - } else if (unlikely(__pyx_t_74 >= __pyx_bshape_0_left_edges)) __pyx_t_76 = 0; - if (__pyx_t_75 < 0) { - __pyx_t_75 += __pyx_bshape_1_left_edges; - if (unlikely(__pyx_t_75 < 0)) __pyx_t_76 = 1; - } else if (unlikely(__pyx_t_75 >= __pyx_bshape_1_left_edges)) __pyx_t_76 = 1; - if (unlikely(__pyx_t_76 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_76); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_76 = __pyx_v_gi; - __pyx_t_77 = 5; - __pyx_t_78 = -1; - if (__pyx_t_76 < 0) { - __pyx_t_76 += __pyx_bshape_0_grid_file_locations; - if (unlikely(__pyx_t_76 < 0)) __pyx_t_78 = 0; - } else if (unlikely(__pyx_t_76 >= __pyx_bshape_0_grid_file_locations)) __pyx_t_78 = 0; - if (__pyx_t_77 < 0) { - __pyx_t_77 += __pyx_bshape_1_grid_file_locations; - if (unlikely(__pyx_t_77 < 0)) __pyx_t_78 = 1; - } else if (unlikely(__pyx_t_77 >= __pyx_bshape_1_grid_file_locations)) __pyx_t_78 = 1; - if (unlikely(__pyx_t_78 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_78); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_grid_file_locations.buf, __pyx_t_76, __pyx_bstride_0_grid_file_locations, __pyx_t_77, __pyx_bstride_1_grid_file_locations) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_left_edges.buf, __pyx_t_74, __pyx_bstride_0_left_edges, __pyx_t_75, __pyx_bstride_1_left_edges)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":748 - * grid_file_locations[gi,4] = left_edges[gi, 1] - * grid_file_locations[gi,5] = left_edges[gi, 2] - * self.grid_file_locations.append(grid_file_locations[gi,:]) # <<<<<<<<<<<<<< - * - * self.dd = np.ones(3, dtype='int64') - */ - __pyx_t_43 = PyInt_FromLong(__pyx_v_gi); if (unlikely(!__pyx_t_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_43); - __pyx_t_1 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_42 = PyTuple_New(2); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_42); - PyTuple_SET_ITEM(__pyx_t_42, 0, __pyx_t_43); - __Pyx_GIVEREF(__pyx_t_43); - PyTuple_SET_ITEM(__pyx_t_42, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_43 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_v_grid_file_locations), __pyx_t_42); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; - __pyx_t_42 = __Pyx_PyObject_Append(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->grid_file_locations, __pyx_t_1); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_42); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; - goto __pyx_L30; - } - __pyx_L30:; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":750 - * self.grid_file_locations.append(grid_file_locations[gi,:]) - * - * self.dd = np.ones(3, dtype='int64') # <<<<<<<<<<<<<< - * for i in range(3): - * efficiency /= self.dimensions[i] - */ - __pyx_t_42 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_42); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_42, __pyx_n_s__ones); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; - __pyx_t_42 = PyTuple_New(1); if (unlikely(!__pyx_t_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_42); - __Pyx_INCREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_42, 0, __pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - __pyx_t_43 = PyDict_New(); if (unlikely(!__pyx_t_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_43)); - if (PyDict_SetItem(__pyx_t_43, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__int64)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_79 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_42, ((PyObject *)__pyx_t_43)); if (unlikely(!__pyx_t_79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_79); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_42); __pyx_t_42 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_43)); __pyx_t_43 = 0; - __Pyx_GIVEREF(__pyx_t_79); - __Pyx_GOTREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - __Pyx_DECREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd = __pyx_t_79; - __pyx_t_79 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":751 - * - * self.dd = np.ones(3, dtype='int64') - * for i in range(3): # <<<<<<<<<<<<<< - * efficiency /= self.dimensions[i] - * self.dd[i] = self.dimensions[i] - */ - for (__pyx_t_2 = 0; __pyx_t_2 < 3; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":752 - * self.dd = np.ones(3, dtype='int64') - * for i in range(3): - * efficiency /= self.dimensions[i] # <<<<<<<<<<<<<< - * self.dd[i] = self.dimensions[i] - * #print "Efficiency is %0.3e" % (efficiency) - */ - __pyx_v_efficiency /= (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i]); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":753 - * for i in range(3): - * efficiency /= self.dimensions[i] - * self.dd[i] = self.dimensions[i] # <<<<<<<<<<<<<< - * #print "Efficiency is %0.3e" % (efficiency) - * self.efficiency = efficiency - */ - __pyx_t_79 = __Pyx_PyInt_to_py_npy_int64((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_i])); if (unlikely(!__pyx_t_79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_79); - if (__Pyx_SetItemInt(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd, __pyx_v_i, __pyx_t_79, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_79); __pyx_t_79 = 0; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":755 - * self.dd[i] = self.dimensions[i] - * #print "Efficiency is %0.3e" % (efficiency) - * self.efficiency = efficiency # <<<<<<<<<<<<<< - * - * def find_split(self): - */ - ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->efficiency = __pyx_v_efficiency; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_42); - __Pyx_XDECREF(__pyx_t_43); - __Pyx_XDECREF(__pyx_t_79); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_index); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig1); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig2); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig0); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("yt.ramses_reader.ProtoSubgrid.__cinit__"); - __pyx_r = -1; - goto __pyx_L2; - __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_right_edges); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_index); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_file_locations); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_grid_dimensions); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig1); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig2); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig0); - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_left_edges); - __pyx_L2:; - __Pyx_DECREF((PyObject *)__pyx_v_sig0); - __Pyx_DECREF((PyObject *)__pyx_v_sig1); - __Pyx_DECREF((PyObject *)__pyx_v_sig2); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":757 - * self.efficiency = efficiency - * - * def find_split(self): # <<<<<<<<<<<<<< - * # First look for zeros - * cdef int i, center, ax - */ - -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_find_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pf_2yt_13ramses_reader_12ProtoSubgrid_find_split(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - int __pyx_v_i; - int __pyx_v_center; - int __pyx_v_ax; - PyArrayObject *__pyx_v_axes; - __pyx_t_5numpy_int64_t __pyx_v_strength; - __pyx_t_5numpy_int64_t __pyx_v_zcstrength; - __pyx_t_5numpy_int64_t __pyx_v_zcp; - PyArrayObject *__pyx_v_sig; - long __pyx_v_axi; - long __pyx_v_zca; - __pyx_t_5numpy_int64_t *__pyx_v_sig2d; - Py_buffer __pyx_bstruct_axes; - Py_ssize_t __pyx_bstride_0_axes = 0; - Py_ssize_t __pyx_bshape_0_axes = 0; - Py_buffer __pyx_bstruct_sig; - Py_ssize_t __pyx_bstride_0_sig = 0; - Py_ssize_t __pyx_bshape_0_sig = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyArrayObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - long __pyx_t_9; - long __pyx_t_10; - PyArrayObject *__pyx_t_11 = NULL; - __pyx_t_5numpy_int64_t __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - long __pyx_t_19; - long __pyx_t_20; - int __pyx_t_21; - long __pyx_t_22; - __Pyx_RefNannySetupContext("find_split"); - __pyx_v_axes = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_v_sig = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); - __pyx_bstruct_axes.buf = NULL; - __pyx_bstruct_sig.buf = NULL; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":762 - * cdef np.ndarray[ndim=1, dtype=np.int64_t] axes - * cdef np.int64_t strength, zcstrength, zcp - * axes = np.argsort(self.dd)[::-1] # <<<<<<<<<<<<<< - * cdef np.ndarray[np.int64_t] sig - * for axi in range(3): - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__argsort); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - __Pyx_GIVEREF(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dd); - __pyx_t_3 = PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetItem(__pyx_t_3, __pyx_t_1); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_axes); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_axes, (PyObject*)__pyx_t_4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_axes, (PyObject*)__pyx_v_axes, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8); - } - } - __pyx_bstride_0_axes = __pyx_bstruct_axes.strides[0]; - __pyx_bshape_0_axes = __pyx_bstruct_axes.shape[0]; - if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_axes)); - __pyx_v_axes = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":764 - * axes = np.argsort(self.dd)[::-1] - * cdef np.ndarray[np.int64_t] sig - * for axi in range(3): # <<<<<<<<<<<<<< - * ax = axes[axi] - * center = self.dimensions[ax] / 2 - */ - for (__pyx_t_9 = 0; __pyx_t_9 < 3; __pyx_t_9+=1) { - __pyx_v_axi = __pyx_t_9; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":765 - * cdef np.ndarray[np.int64_t] sig - * for axi in range(3): - * ax = axes[axi] # <<<<<<<<<<<<<< - * center = self.dimensions[ax] / 2 - * sig = self.sigs[ax] - */ - __pyx_t_10 = __pyx_v_axi; - __pyx_t_5 = -1; - if (__pyx_t_10 < 0) { - __pyx_t_10 += __pyx_bshape_0_axes; - if (unlikely(__pyx_t_10 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_10 >= __pyx_bshape_0_axes)) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_ax = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_axes.buf, __pyx_t_10, __pyx_bstride_0_axes)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":766 - * for axi in range(3): - * ax = axes[axi] - * center = self.dimensions[ax] / 2 # <<<<<<<<<<<<<< - * sig = self.sigs[ax] - * for i in range(self.dimensions[ax]): - */ - __pyx_v_center = __Pyx_div___pyx_t_5numpy_int64_t((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]), 2); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":767 - * ax = axes[axi] - * center = self.dimensions[ax] / 2 - * sig = self.sigs[ax] # <<<<<<<<<<<<<< - * for i in range(self.dimensions[ax]): - * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: - */ - __pyx_t_2 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, __pyx_v_ax, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_11 = ((PyArrayObject *)__pyx_t_2); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_v_sig, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_6); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_8, __pyx_t_7, __pyx_t_6); - } - } - __pyx_bstride_0_sig = __pyx_bstruct_sig.strides[0]; - __pyx_bshape_0_sig = __pyx_bstruct_sig.shape[0]; - if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_sig)); - __pyx_v_sig = ((PyArrayObject *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":768 - * center = self.dimensions[ax] / 2 - * sig = self.sigs[ax] - * for i in range(self.dimensions[ax]): # <<<<<<<<<<<<<< - * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: - * #print "zero: %s (%s)" % (i, self.dimensions[ax]) - */ - __pyx_t_12 = (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]); - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_12; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":769 - * sig = self.sigs[ax] - * for i in range(self.dimensions[ax]): - * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: # <<<<<<<<<<<<<< - * #print "zero: %s (%s)" % (i, self.dimensions[ax]) - * return 'zs', ax, i - */ - __pyx_t_13 = __pyx_v_i; - __pyx_t_14 = -1; - if (__pyx_t_13 < 0) { - __pyx_t_13 += __pyx_bshape_0_sig; - if (unlikely(__pyx_t_13 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_13 >= __pyx_bshape_0_sig)) __pyx_t_14 = 0; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = ((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_13, __pyx_bstride_0_sig)) == 0); - if (__pyx_t_15) { - __pyx_t_16 = (__pyx_v_i > 0); - if (__pyx_t_16) { - __pyx_t_17 = (__pyx_v_i < ((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1)); - __pyx_t_18 = __pyx_t_17; - } else { - __pyx_t_18 = __pyx_t_16; - } - __pyx_t_16 = __pyx_t_18; - } else { - __pyx_t_16 = __pyx_t_15; - } - if (__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":771 - * if sig[i] == 0 and i > 0 and i < self.dimensions[ax] - 1: - * #print "zero: %s (%s)" % (i, self.dimensions[ax]) - * return 'zs', ax, i # <<<<<<<<<<<<<< - * zcstrength = 0 - * zcp = 0 - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyInt_FromLong(__pyx_v_ax); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_n_s__zs)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__zs)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zs)); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - goto __pyx_L9; - } - __pyx_L9:; - } - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":772 - * #print "zero: %s (%s)" % (i, self.dimensions[ax]) - * return 'zs', ax, i - * zcstrength = 0 # <<<<<<<<<<<<<< - * zcp = 0 - * zca = -1 - */ - __pyx_v_zcstrength = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":773 - * return 'zs', ax, i - * zcstrength = 0 - * zcp = 0 # <<<<<<<<<<<<<< - * zca = -1 - * cdef int temp - */ - __pyx_v_zcp = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":774 - * zcstrength = 0 - * zcp = 0 - * zca = -1 # <<<<<<<<<<<<<< - * cdef int temp - * cdef np.int64_t *sig2d - */ - __pyx_v_zca = -1; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":777 - * cdef int temp - * cdef np.int64_t *sig2d - * for axi in range(3): # <<<<<<<<<<<<<< - * ax = axes[axi] - * sig = self.sigs[ax] - */ - for (__pyx_t_9 = 0; __pyx_t_9 < 3; __pyx_t_9+=1) { - __pyx_v_axi = __pyx_t_9; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":778 - * cdef np.int64_t *sig2d - * for axi in range(3): - * ax = axes[axi] # <<<<<<<<<<<<<< - * sig = self.sigs[ax] - * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) - */ - __pyx_t_19 = __pyx_v_axi; - __pyx_t_5 = -1; - if (__pyx_t_19 < 0) { - __pyx_t_19 += __pyx_bshape_0_axes; - if (unlikely(__pyx_t_19 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_19 >= __pyx_bshape_0_axes)) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_ax = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_axes.buf, __pyx_t_19, __pyx_bstride_0_axes)); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":779 - * for axi in range(3): - * ax = axes[axi] - * sig = self.sigs[ax] # <<<<<<<<<<<<<< - * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) - * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 - */ - __pyx_t_3 = __Pyx_GetItemInt(((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->sigs, __pyx_v_ax, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_11 = ((PyArrayObject *)__pyx_t_3); - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - __Pyx_SafeReleaseBuffer(&__pyx_bstruct_sig); - __pyx_t_5 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack); - if (unlikely(__pyx_t_5 < 0)) { - PyErr_Fetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_sig, (PyObject*)__pyx_v_sig, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int64_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { - Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); - __Pyx_RaiseBufferFallbackError(); - } else { - PyErr_Restore(__pyx_t_6, __pyx_t_7, __pyx_t_8); - } - } - __pyx_bstride_0_sig = __pyx_bstruct_sig.strides[0]; - __pyx_bshape_0_sig = __pyx_bstruct_sig.shape[0]; - if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_sig)); - __pyx_v_sig = ((PyArrayObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":780 - * ax = axes[axi] - * sig = self.sigs[ax] - * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) # <<<<<<<<<<<<<< - * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 - * for i in range(1, self.dimensions[ax] - 1): - */ - __pyx_v_sig2d = ((__pyx_t_5numpy_int64_t *)malloc(((sizeof(__pyx_t_5numpy_int64_t)) * (((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax])))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":781 - * sig = self.sigs[ax] - * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) - * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 # <<<<<<<<<<<<<< - * for i in range(1, self.dimensions[ax] - 1): - * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] - */ - (__pyx_v_sig2d[0]) = 0; - (__pyx_v_sig2d[((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1)]) = 0; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":782 - * sig2d = malloc(sizeof(np.int64_t) * self.dimensions[ax]) - * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 - * for i in range(1, self.dimensions[ax] - 1): # <<<<<<<<<<<<<< - * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] - * for i in range(1, self.dimensions[ax] - 1): - */ - __pyx_t_12 = ((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1); - for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_12; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":783 - * sig2d[0] = sig2d[self.dimensions[ax]-1] = 0 - * for i in range(1, self.dimensions[ax] - 1): - * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] # <<<<<<<<<<<<<< - * for i in range(1, self.dimensions[ax] - 1): - * if sig2d[i] * sig2d[i+1] <= 0: - */ - __pyx_t_20 = (__pyx_v_i - 1); - __pyx_t_14 = -1; - if (__pyx_t_20 < 0) { - __pyx_t_20 += __pyx_bshape_0_sig; - if (unlikely(__pyx_t_20 < 0)) __pyx_t_14 = 0; - } else if (unlikely(__pyx_t_20 >= __pyx_bshape_0_sig)) __pyx_t_14 = 0; - if (unlikely(__pyx_t_14 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_14); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_14 = __pyx_v_i; - __pyx_t_21 = -1; - if (__pyx_t_14 < 0) { - __pyx_t_14 += __pyx_bshape_0_sig; - if (unlikely(__pyx_t_14 < 0)) __pyx_t_21 = 0; - } else if (unlikely(__pyx_t_14 >= __pyx_bshape_0_sig)) __pyx_t_21 = 0; - if (unlikely(__pyx_t_21 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_21); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_22 = (__pyx_v_i + 1); - __pyx_t_21 = -1; - if (__pyx_t_22 < 0) { - __pyx_t_22 += __pyx_bshape_0_sig; - if (unlikely(__pyx_t_22 < 0)) __pyx_t_21 = 0; - } else if (unlikely(__pyx_t_22 >= __pyx_bshape_0_sig)) __pyx_t_21 = 0; - if (unlikely(__pyx_t_21 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_21); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - (__pyx_v_sig2d[__pyx_v_i]) = (((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_20, __pyx_bstride_0_sig)) - (2 * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_14, __pyx_bstride_0_sig)))) + (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_bstruct_sig.buf, __pyx_t_22, __pyx_bstride_0_sig))); - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":784 - * for i in range(1, self.dimensions[ax] - 1): - * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] - * for i in range(1, self.dimensions[ax] - 1): # <<<<<<<<<<<<<< - * if sig2d[i] * sig2d[i+1] <= 0: - * strength = labs(sig2d[i] - sig2d[i+1]) - */ - __pyx_t_12 = ((((struct __pyx_obj_2yt_13ramses_reader_ProtoSubgrid *)__pyx_v_self)->dimensions[__pyx_v_ax]) - 1); - for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_12; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":785 - * sig2d[i] = sig[i-1] - 2*sig[i] + sig[i+1] - * for i in range(1, self.dimensions[ax] - 1): - * if sig2d[i] * sig2d[i+1] <= 0: # <<<<<<<<<<<<<< - * strength = labs(sig2d[i] - sig2d[i+1]) - * if (strength > zcstrength) or \ - */ - __pyx_t_16 = (((__pyx_v_sig2d[__pyx_v_i]) * (__pyx_v_sig2d[(__pyx_v_i + 1)])) <= 0); - if (__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":786 - * for i in range(1, self.dimensions[ax] - 1): - * if sig2d[i] * sig2d[i+1] <= 0: - * strength = labs(sig2d[i] - sig2d[i+1]) # <<<<<<<<<<<<<< - * if (strength > zcstrength) or \ - * (strength == zcstrength and (abs(center - i) < - */ - __pyx_v_strength = labs(((__pyx_v_sig2d[__pyx_v_i]) - (__pyx_v_sig2d[(__pyx_v_i + 1)]))); - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":787 - * if sig2d[i] * sig2d[i+1] <= 0: - * strength = labs(sig2d[i] - sig2d[i+1]) - * if (strength > zcstrength) or \ # <<<<<<<<<<<<<< - * (strength == zcstrength and (abs(center - i) < - * abs(center - zcp))): - */ - __pyx_t_16 = (__pyx_v_strength > __pyx_v_zcstrength); - if (!__pyx_t_16) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":788 - * strength = labs(sig2d[i] - sig2d[i+1]) - * if (strength > zcstrength) or \ - * (strength == zcstrength and (abs(center - i) < # <<<<<<<<<<<<<< - * abs(center - zcp))): - * zcstrength = strength - */ - __pyx_t_15 = (__pyx_v_strength == __pyx_v_zcstrength); - if (__pyx_t_15) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":789 - * if (strength > zcstrength) or \ - * (strength == zcstrength and (abs(center - i) < - * abs(center - zcp))): # <<<<<<<<<<<<<< - * zcstrength = strength - * zcp = i - */ - __pyx_t_18 = (abs((__pyx_v_center - __pyx_v_i)) < abs((__pyx_v_center - __pyx_v_zcp))); - __pyx_t_17 = __pyx_t_18; - } else { - __pyx_t_17 = __pyx_t_15; - } - __pyx_t_15 = __pyx_t_17; - } else { - __pyx_t_15 = __pyx_t_16; - } - if (__pyx_t_15) { - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":790 - * (strength == zcstrength and (abs(center - i) < - * abs(center - zcp))): - * zcstrength = strength # <<<<<<<<<<<<<< - * zcp = i - * zca = ax - */ - __pyx_v_zcstrength = __pyx_v_strength; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":791 - * abs(center - zcp))): - * zcstrength = strength - * zcp = i # <<<<<<<<<<<<<< - * zca = ax - * free(sig2d) - */ - __pyx_v_zcp = __pyx_v_i; - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":792 - * zcstrength = strength - * zcp = i - * zca = ax # <<<<<<<<<<<<<< - * free(sig2d) - * #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) - */ - __pyx_v_zca = __pyx_v_ax; - goto __pyx_L17; - } - __pyx_L17:; - goto __pyx_L16; - } - __pyx_L16:; - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":793 - * zcp = i - * zca = ax - * free(sig2d) # <<<<<<<<<<<<<< - * #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) - * return 'zc', ax, zcp - */ - free(__pyx_v_sig2d); - } - - /* "/Users/matthewturk/yt/yt/yt/ramses_reader.pyx":795 - * free(sig2d) - * #print "zcp: %s (%s)" % (zcp, self.dimensions[ax]) - * return 'zc', ax, zcp # <<<<<<<<<<<<<< - * - * def get_properties(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyInt_FromLong(__pyx_v_ax); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyInt_to_py_npy_int64(__pyx_v_zcp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_n_s__zc)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__zc)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__zc)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r =