Permalink
Browse files

Major code cleanup thanks to pyflakes.

Ran pyflakes on the code, cleaned up a lot of fluff.
  • Loading branch information...
1 parent 74527af commit 4b43f10eb92646705e5268f3f4dfe6f8e82132e6 @mathuin committed Feb 28, 2012
Showing with 30 additions and 70 deletions.
  1. +1 −1 BuildMaps.py
  2. +3 −8 BuildRegion.py
  3. +0 −1 BuildTile.py
  4. +0 −5 PrepRegion.py
  5. +0 −3 bathy.py
  6. +19 −23 clidt.py
  7. +1 −1 crust.py
  8. +2 −3 ore.py
  9. +1 −10 region.py
  10. +0 −5 terrain.py
  11. +2 −9 tile.py
  12. +1 −1 tree.py
View
@@ -6,7 +6,7 @@
import sys
sys.path.append('..')
from utils import cleanmkdir
-from pymclevel import mclevel, box
+from pymclevel import mclevel
import argparse
def center(name):
View
@@ -2,24 +2,19 @@
import logging
logging.basicConfig(level=logging.WARNING)
-from region import Region
from tile import Tile
-from utils import setspawnandsave, materialNamed, names
+from utils import setspawnandsave
import sys
import argparse
import os
import yaml
-try:
- from yaml import CLoader as Loader, CDumper as Dumper
-except ImportError:
- from yaml import Loader, Dumper
from multiprocessing import Pool
from itertools import product
from tree import Tree, treeObjs
-from ore import Ore, oreObjs, oreDQ
+from ore import Ore, oreObjs
sys.path.append('..')
-from pymclevel import mclevel, box
+from pymclevel import mclevel
def main(argv):
"""Builds a region."""
View
@@ -4,7 +4,6 @@
import logging
logging.basicConfig(level=logging.WARNING)
-from region import Region
from tile import Tile
import sys
View
@@ -2,15 +2,10 @@
import logging
logging.basicConfig(level=logging.WARNING)
-from region import Region
import sys
import argparse
import os
import yaml
-try:
- from yaml import CLoader as Loader, CDumper as Dumper
-except ImportError:
- from yaml import Loader, Dumper
def main(argv):
"""Rebuilds maps on broken regions."""
View
@@ -1,8 +1,5 @@
# bathy
-from numpy import zeros, uint8
-from itertools import product
-from math import hypot
from osgeo import gdal
def getBathy(deptharray, maxdepth, geotrans, projection):
View
@@ -1,14 +1,13 @@
# OpenCL/IDT module
-import numpy as n
+import numpy as np
from itertools import product
-from random import randint, uniform
from invdisttree import Invdisttree
-from multiprocessing import Pool
try:
import pyopencl as cl
import pyopencl.array as cla
+ hasCL = True
except ImportError:
- pass
+ hasCL = False
class CLIDT:
"""Use OpenCL or Invdisttree to solve the IDT problem."""
@@ -28,10 +27,10 @@ def genindices(self, arrayin):
# need to split if it's too long!
splitlist = tuple([x for x in xrange(CLIDT.indexmaxsize, arrayin.shape[0], CLIDT.indexmaxsize)])
indexinc = 0
- for chunk in n.vsplit(arrayin, splitlist):
- chunkarr = cla.to_device(self.queue, n.asarray(chunk, dtype=n.int32))
+ for chunk in np.vsplit(arrayin, splitlist):
+ chunkarr = cla.to_device(self.queue, np.asarray(chunk, dtype=np.int32))
template = cla.empty_like(chunkarr)
- event = self.program.trim(self.queue, chunkarr.shape, None, chunkarr.data, template.data, n.int32(self.split))
+ event = self.program.trim(self.queue, chunkarr.shape, None, chunkarr.data, template.data, np.int32(self.split))
event.wait()
for index, elem in enumerate(template.get()):
splitkey = tuple([x for x in elem],)
@@ -44,50 +43,47 @@ def genindices(self, arrayin):
return retval
def __init__(self, coords, values, base, wantCL=True, split=None, nnear=None, majority=True):
- self.coords = n.asarray(coords, dtype=n.int32)
- self.values = n.asarray(values, dtype=n.int32)
- self.base = n.asarray(base, dtype=n.int32)
+ self.coords = np.asarray(coords, dtype=np.int32)
+ self.values = np.asarray(values, dtype=np.int32)
+ self.base = np.asarray(base, dtype=np.int32)
(lencoords, null) = self.coords.shape
(lenvalues,) = self.values.shape
(lenbase, null) = self.base.shape
assert lencoords == lenvalues, "lencoords does not equal lenvalues"
self.wantCL = wantCL
- if self.wantCL == True:
+ if hasCL == True and self.wantCL == True:
if split == None:
self.split = CLIDT.OpenCLmaxsize
else:
self.split = split
try:
- import pyopencl as cl
- import pyopencl.array as cla
self.ctx = cl.create_some_context()
self.queue = cl.CommandQueue(self.ctx)
filestr = ''.join(open('idt.cl', 'r').readlines())
self.program = cl.Program(self.ctx, filestr).build()
self.coordindices = self.genindices(self.coords)
self.baseindices = self.genindices(self.base)
self.canCL = True
- except ImportError:
- # prolly should be specific here
- print "warning: unable to import pyopencl, defaulting to Invdisttree"
+ except:
+ print "warning: unable to use pyopencl, defaulting to Invdisttree"
self.canCL = False
if nnear == None:
- self.nnear = n.int32(CLIDT.nnear)
+ self.nnear = np.int32(CLIDT.nnear)
else:
- self.nnear = n.int32(nnear)
+ self.nnear = np.int32(nnear)
- self.usemajority = n.int32(1 if majority else 0)
+ self.usemajority = np.int32(1 if majority else 0)
def build(self, coords, values, base):
(lenbase, null) = base.shape
(lencoords, null) = coords.shape
coords_array = cla.to_device(self.queue, coords)
values_array = cla.to_device(self.queue, values)
base_array = cla.to_device(self.queue, base)
- template_array = cla.zeros(self.queue, (lenbase), dtype=n.int32)
- event = self.program.nearest(self.queue, base.shape, None, coords_array.data, values_array.data, base_array.data, template_array.data, n.int32(lencoords), self.nnear, self.usemajority)
+ template_array = cla.zeros(self.queue, (lenbase), dtype=np.int32)
+ event = self.program.nearest(self.queue, base.shape, None, coords_array.data, values_array.data, base_array.data, template_array.data, np.int32(lencoords), self.nnear, self.usemajority)
event.wait()
return template_array.get()
@@ -96,7 +92,7 @@ def __call__(self):
# build output array
if self.wantCL and self.canCL:
(lenbase, null) = self.base.shape
- retval = n.zeros((lenbase), dtype=n.int32)
+ retval = np.zeros((lenbase), dtype=np.int32)
for key, value in self.baseindices.items():
(a, b) = key
cindices = []
@@ -110,7 +106,7 @@ def __call__(self):
retval[value] = self.build(coords, values, base)
else:
IDT = Invdisttree(self.coords, self.values)
- retval = n.asarray(IDT(self.base, self.nnear, majority=(self.usemajority==1)), dtype=n.int32)
+ retval = np.asarray(IDT(self.base, self.nnear, majority=(self.usemajority==1)), dtype=np.int32)
return retval
def __del__(self):
View
@@ -1,7 +1,7 @@
# crust module
from itertools import product
from random import randint, uniform
-from newclidt import CLIDT
+from clidt import CLIDT
class Crust:
"""Smoothly irregular crust between the surface and the underlying stone."""
View
5 ore.py
@@ -1,10 +1,10 @@
# ore module
from __future__ import division
from random import randint
-from math import pi, ceil
+from math import pi
from scipy.special import cbrt
from itertools import product
-from utils import materialNamed, names
+from utils import materialNamed
# http://www.minecraftforum.net/topic/25886-elites-of-minecraft-the-miner-first-ore-loss-calculated/ (must be logged in)
@@ -58,7 +58,6 @@ def placeoreintile(tile):
oreobjs = dict([(ore.name, ore) for ore in oreObjs])
tile.ores = dict([(name, list()) for name in oreobjs])
- oreblocks = []
for ore in oreobjs:
extent = cbrt(oreobjs[ore].size)*2
maxy = pow(2,oreobjs[ore].depth)
View
@@ -7,15 +7,9 @@
import os
import urllib2
import yaml
-try:
- from yaml import CLoader as Loader, CDumper as Dumper
-except ImportError:
- from yaml import Loader, Dumper
import logging
logging.basicConfig(level=logging.INFO)
-#logging.getLogger('suds.client').setLevel(logging.DEBUG)
-from time import sleep, clock
-from tempfile import NamedTemporaryFile
+from time import sleep
import zipfile
import tarfile
from utils import cleanmkdir
@@ -29,8 +23,6 @@
from bathy import getBathy
from crust import Crust
import numpy
-from itertools import product
-from random import uniform, randint
#
from clidt import CLIDT
@@ -413,7 +405,6 @@ def downloadfile(self, layerID, downloadURL):
requestID = result[startPos:endPos]
print " request ID is %s" % requestID
- downloadDict = {'downloadID': requestID}
sleep(5)
while True:
dsPage = urllib2.urlopen("http://extract.cr.usgs.gov/axis2/services/DownloadService/getDownloadStatus?downloadID=%s" % requestID)
View
@@ -1,11 +1,6 @@
from random import random, choice
from utils import materialNamed, height
from schematic import Schematic
-import yaml
-try:
- from yaml import CLoader as Loader, CDumper as Dumper
-except ImportError:
- from yaml import Loader, Dumper
class Terrain:
"""Base class for landcover definitions."""
View
11 tile.py
@@ -4,27 +4,20 @@
from __future__ import division
import yaml
-try:
- from yaml import CLoader as Loader, CDumper as Dumper
-except ImportError:
- from yaml import Loader, Dumper
from region import Region
import os
from itertools import product
-import numpy
from utils import cleanmkdir, setspawnandsave
-from random import randint
from osgeo import gdal
-from osgeo.gdalconst import GDT_Int16, GA_ReadOnly
+from osgeo.gdalconst import GA_ReadOnly
import sys
sys.path.append('..')
from pymclevel import mclevel, box
from terrain import Terrain
from tree import Tree, treeObjs
-from ore import Ore, oreObjs, oreDQ
-from scipy.special import cbrt
+from ore import Ore
class Tile:
"""Tiles are the base render object. or something."""
View
@@ -91,7 +91,7 @@ def placetreeintile(tile, tree, mcx, mcy, mcz):
tile.trees[tree].append(coords)
else:
# plant it now!
- (blocks, datas) = treeobjs[tree](coords)
+ (blocks, datas) = treeObjs[tree](coords)
[ tile.world.setBlockAt(x, y, z, materialNamed(block)) for (x, y, z, block) in blocks if block != 'Air' ]
[ tile.world.setBlockDataAt(x, y, z, data) for (x, y, z, data) in datas if data != 0 ]

0 comments on commit 4b43f10

Please sign in to comment.