本文整理汇总了Python中numpy.sctype2char函数的典型用法代码示例。如果您正苦于以下问题:Python sctype2char函数的具体用法?Python sctype2char怎么用?Python sctype2char使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sctype2char函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __new__
def __new__(cls, data, typecode=None, copy=0, savespace=0,
mask=numpy.ma.nomask, fill_value=None, grid=None,
axes=None, attributes=None, id=None, copyaxes=1, dtype=None, order=False,**kargs):
"""createVariable (self, data, typecode=None, copy=0, savespace=0,
mask=None, fill_value=None, grid=None,
axes=None, attributes=None, id=None, dtype=None, order=False)
The savespace argument is ignored, for backward compatibility only.
"""
# Compatibility: assuming old typecode, map to new
if dtype is None and typecode is not None:
dtype = typeconv.convtypecode2(typecode)
typecode = sctype2char(dtype)
if type(data) is types.TupleType:
data = list(data)
if isinstance(data, AbstractVariable):
if not isinstance(data, TransientVariable):
data = data.subSlice()
if isinstance(data, numpy.ma.MaskedArray):
try:
if fill_value is None: fill_value = data.fill_value
except:
pass
ncopy = (copy!=0)
if mask is None:
try:
mask = data.mask
except Exception,err:
mask = numpy.ma.nomask
开发者ID:MartinDix,项目名称:cdat_lite_test,代码行数:29,代码来源:tvariable.py
示例2: run
def run(self):
from vsi.io.image import imread
import voxel_globe.meta.models as models
self.create_image_collection()
filenames = glob(os.path.join(self.ingest_dir, '*'))
filenames.sort()
image_index=0
for index,filename in enumerate(filenames):
img = imread(filename)
if img is None: #If not an image
continue #NEXT!
image_index += 1
self.task.update_state(state='PROCESSING',
meta={'stage':'File %s (%d of %d)' % (filename, index,
len(filenames))})
pixel_format = sctype2char(img.dtype())
self.zoomify_add_image(filename, img.shape()[1], img.shape()[0],
img.bands(), pixel_format)
return self.image_collection.id
开发者ID:andyneff,项目名称:voxel_globe,代码行数:29,代码来源:tasks.py
示例3: test_imread_flatten
def test_imread_flatten():
# a color image is flattened and returned as float32
img = imread(os.path.join(data_dir, 'color.png'), flatten=True)
assert img.dtype == np.float32
img = imread(os.path.join(data_dir, 'camera.png'), flatten=True)
# check that flattening does not occur for an image that is grey already.
assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
开发者ID:deads,项目名称:scikits.image,代码行数:7,代码来源:test_imread.py
示例4: simple_vectorize
def simple_vectorize(fn,num_outputs=1,output_type=object,doc=''):
"""
Simplify creation of numpy.vectorize(fn) objects where all outputs
have the same typecode.
"""
from numpy import vectorize,sctype2char
# This function exists because I cannot figure out how I am
# supposed to stop vectorize() calling fn one extra time at the
# start. (It's supposed to call an extra time at the start to
# determine the output types UNLESS the output types are
# specified.)
vfn = vectorize(fn,doc=doc)
# stop vectorize calling fn an extra time at the start
# (works for our current numpy (1.1.1))
vfn.nout=num_outputs # number of outputs of fn
output_typecode = sctype2char(output_type)
vfn.otypes=output_typecode*num_outputs # typecodes of outputs of fn
import inspect
try:
fn_code = fn.func_code if hasattr(fn,'func_code') else fn.__call__.func_code
except:
raise TypeError("Couldn't find code of %s"%fn)
fn_args = inspect.getargs(fn_code)[0]
extra = 1 if fn_args[0]=='self' else 0
vfn.lastcallargs=len(fn_args)-extra # num args of fn
return vfn
开发者ID:jesuscript,项目名称:TopographicaSVN,代码行数:30,代码来源:cf.py
示例5: simple_vectorize
def simple_vectorize(fn,num_outputs=1,output_type=object,doc=''):
"""
Wrapper for Numpy.vectorize to make it work properly with different Numpy versions.
"""
# Numpy.vectorize returns a callable object that applies the given
# fn to a list or array. By default, Numpy.vectorize will call
# the supplied fn an extra time to determine the output types,
# which is a big problem for any function with side effects.
# Supplying arguments is supposed to avoid the problem, but as of
# Numpy 1.6.1 (and apparently since at least 1.1.1) this feature
# was broken:
#
# $ ./topographica -c "def f(x): print x" -c "import numpy" -c "numpy.vectorize(f,otypes=numpy.sctype2char(object)*1)([3,4])"
# 3
# 3
# 4
#
# Numpy 1.7.0 seems to fix the problem:
# $ ./topographica -c "def f(x): print x" -c "import numpy" -c "numpy.vectorize(f,otypes=numpy.sctype2char(object)*1)([3,4])"
# 3
# 4
#
# To make it work with all versions of Numpy, we use
# numpy.vectorize as-is for versions > 1.7.0, and a nasty hack for
# previous versions.
# Simple Numpy 1.7.0 version:
if int(np.version.version[0]) >= 1 and int(np.version.version[2]) >= 7:
return np.vectorize(fn,otypes=np.sctype2char(output_type)*num_outputs, doc=doc)
# Otherwise, we have to mess with Numpy's internal data structures to make it work.
vfn = np.vectorize(fn,doc=doc)
vfn.nout=num_outputs # number of outputs of fn
output_typecode = np.sctype2char(output_type)
vfn.otypes=output_typecode*num_outputs # typecodes of outputs of fn
import inspect
try:
fn_code = fn.func_code if hasattr(fn,'func_code') else fn.__call__.func_code
except:
raise TypeError("Couldn't find code of %s"%fn)
fn_args = inspect.getargs(fn_code)[0]
extra = 1 if fn_args[0]=='self' else 0
vfn.lastcallargs=len(fn_args)-extra # num args of fn
return vfn
开发者ID:qqkong,项目名称:topographica,代码行数:47,代码来源:cf.py
示例6: test_imread_flatten
def test_imread_flatten():
# a color image is flattened
img = imread(os.path.join(data_dir, "color.png"), flatten=True)
assert img.ndim == 2
assert img.dtype == np.float64
img = imread(os.path.join(data_dir, "camera.png"), flatten=True)
# check that flattening does not occur for an image that is grey already.
assert np.sctype2char(img.dtype) in np.typecodes["AllInteger"]
开发者ID:RADIO-PROJECT-EU,项目名称:HumanPatternRecognition,代码行数:8,代码来源:test_pil.py
示例7: _mpi_dtype_from_intervals
def _mpi_dtype_from_intervals(larr, glb_intervals):
local_intervals = _massage_indices(larr.distribution, glb_intervals)
blocklengths = [stop-start for (start, stop) in local_intervals]
displacements = [start for (start, _) in local_intervals]
mpidtype = MPI.__TypeDict__[np.sctype2char(larr.dtype)]
newtype = mpidtype.Create_indexed(blocklengths, displacements)
newtype.Commit()
return newtype
开发者ID:RaoUmer,项目名称:distarray,代码行数:8,代码来源:localarray.py
示例8: define_weather_dtype
def define_weather_dtype(filename):
f = open(filename,'rU')
names = re.split(r',\s*',f.readline().strip())
# print names, len(names)
formats = [np.sctype2char(np.float),]*len(names)
for index in weather_dtype_dict:
formats[index] = weather_dtype_dict[index]
# print formats
return np.format_parser(formats,names,[])
开发者ID:qutang,项目名称:learn-py,代码行数:9,代码来源:weather_exercise.py
示例9: asarray
def asarray(data, typecode=None, dtype=None):
"""asarray(data, typecode=None, dtype=None) is equivalent to array(data, dtype=None, copy=0)
Returns data if dtype is None or data is a MaskedArray of the same dtype.
typecode arg is for backward compatibility.
"""
dtype = _convdtype(dtype, typecode)
if isinstance(data, AbstractVariable) and (dtype is None or sctype2char(dtype) == data.dtype.char):
return data
else:
return TransientVariable(data, dtype=dtype, copy=0)
开发者ID:AZed,项目名称:uvcdat,代码行数:10,代码来源:MV2.py
示例10: test_imageio_flatten
def test_imageio_flatten():
# a color image is flattened (as_gray in .16)
with expected_warnings(['`flatten` has been deprecated']):
img = imread(os.path.join(data_dir, 'color.png'), flatten=True)
assert img.ndim == 2
assert img.dtype == np.float64
with expected_warnings(['`flatten` has been deprecated']):
img = imread(os.path.join(data_dir, 'camera.png'), flatten=True)
# check that flattening does not occur for an image that is grey already.
assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
开发者ID:jmetz,项目名称:scikit-image,代码行数:10,代码来源:test_imageio.py
示例11: main
def main():
fname = ""
if len(sys.argv) < 2:
usage()
sys.exit(1)
else:
fname = sys.argv[1]
f = ad.file(fname)
print "File info:"
print " %-18s %d" % ("of variables:", f.nvars)
print " %-18s %d - %d" % ("time steps:", f.current_step, f.last_step)
print " %-18s %d" % ("file size:", f.file_size)
print " %-18s %d" % ("bp version:", f.version)
print ""
for k in sorted(f.var.keys()):
v = f.var[k]
print " %-17s %-12s %d*%s" % (np.typename(np.sctype2char(v.dtype)), v.name, v.nsteps, v.dims)
开发者ID:pnorbert,项目名称:adiosvm,代码行数:20,代码来源:bpls.py
示例12: MakeParallelAtoms
def MakeParallelAtoms(atoms, nCells, cell=None, pbc=None,
distribute=True):
"""Build parallel simulation from serial lists of atoms.
Call simultaneously on all processors. Each processor having
atoms should pass a list of atoms as the first argument, or None
if this processor does not contribute with any atoms. If the
cell and/or pbc arguments are given, they must be given on
all processors, and be identical. If it is not given, a supercell
is attempted to be extracted from the atoms on the processor with
lowest rank.
This is the preferred method for creating parallel simulations.
"""
import cPickle, cStringIO
mpi = asap3.mpi
#comm = mpi.world.duplicate()
comm = mpi.world
# Sanity check: is the node layout reasonable
nNodes = nCells[0] * nCells[1] * nCells[2]
if nNodes != comm.size:
raise RuntimeError("Wrong number of CPUs: %d != %d*%d*%d" %
(comm.size, nCells[0], nCells[1], nCells[2]))
t1 = np.zeros((3,))
t2 = np.zeros((3,))
comm.min(t1)
comm.max(t2)
if (t1[0] != t2[0] or t1[1] != t2[1] or t1[2] != t2[2]):
raise RuntimeError, "CPU layout inconsistent."
# If pbc and/or cell are given, they may be shorthands in need of
# expansion.
if pbc:
try:
plen = len(pbc)
except TypeError:
# It is a scalar, interpret as a boolean.
if pbc:
pbc = (1,1,1)
else:
pbc = (0,0,0)
else:
if plen != 3:
raise ValueError, "pbc must be a scalar or a 3-sequence."
if cell:
cell = array(cell) # Make sure it is a numeric array.
if cell.shape == (3,):
cell = array([[cell[0], 0, 0],
[0, cell[1], 0],
[0, 0, cell[2]]])
elif cell.shape != (3,3):
raise ValueError, "Unit cell must be a 3x3 matrix or a 3-vector."
# Find the lowest CPU with atoms, and let that one distribute
# which data it has. All other CPUs check for consistency.
if atoms is None:
hasdata = None
mynum = comm.size
else:
hasdata = {}
for name in atoms.arrays.keys():
datatype = np.sctype2char(atoms.arrays[name])
shape = atoms.arrays[name].shape[1:]
hasdata[name] = (datatype, shape)
mynum = comm.rank
if pbc is None:
pbc = atoms.get_pbc()
if cell is None:
cell = atoms.get_cell()
root = comm.min(mynum) # The first CPU with atoms
# Now send hasdata, cell and pbc to all other CPUs
package = cPickle.dumps((hasdata, cell, pbc), 2)
package = comm.broadcast_string(package, root)
rootdata, rootcell, rootpbc = cPickle.loads(package)
if rootdata is None or len(rootdata) == 0:
raise ValueError, "No data from 'root' atoms. Empty atoms?!?"
# Check for consistent cell and pbc arguments
if cell is not None:
if rootcell is None:
raise TypeError, "Cell given on another processor than the atoms."
if (cell.ravel() - rootcell.ravel()).max() > 1e-12:
raise ValueError, "Inconsistent cell specification."
else:
cell = rootcell # May still be None
if pbc is not None:
if rootpbc is None:
raise TypeError, "PBC given on another processor than the atoms."
if (pbc != rootpbc).any():
raise ValueError, "Inconsistent pbc specification."
else:
pbc = rootpbc
# Check for consistent atoms data
if hasdata is not None:
if hasdata != rootdata:
raise ValueError, "Atoms do not contain the sama data on different processors."
if "positions" not in rootdata:
#.........这里部分代码省略.........
开发者ID:auag92,项目名称:n2dm,代码行数:101,代码来源:ParallelListOfAtoms.py
示例13: __init__
def __init__(self,data, typecode=None, copy=1, savespace=0,
mask=numpy.ma.nomask, fill_value=None, grid=None,
axes=None, attributes=None, id=None, copyaxes=1, dtype=None,
order=False, no_update_from=False,**kargs):
"""createVariable (self, data, typecode=None, copy=0, savespace=0,
mask=None, fill_value=None, grid=None,
axes=None, attributes=None, id=None, dtype=None, order=False)
The savespace argument is ignored, for backward compatibility only.
"""
# tile index, None means no mosaic
self.tileIndex = None
# Compatibility: assuming old typecode, map to new
if dtype is None and typecode is not None:
dtype = typeconv.convtypecode2(typecode)
typecode = sctype2char(dtype)
if type(data) is types.TupleType:
data = list(data)
AbstractVariable.__init__ (self)
if isinstance(data, AbstractVariable):
if not isinstance(data, TransientVariable):
data = data.subSlice()
## if attributes is None: attributes = data.attributes
if axes is None and not no_update_from:
axes = map(lambda x: x[0], data.getDomain())
if grid is None and not no_update_from:
grid = data.getGrid()
if (grid is not None) and (not isinstance(grid, AbstractRectGrid)) \
and (not grid.checkAxes(axes)):
grid = grid.reconcile(axes) # Make sure grid and axes are consistent
ncopy = (copy!=0)
# Initialize the geometry
if grid is not None:
copyaxes=0 # Otherwise grid axes won't match domain.
if axes is not None:
self.initDomain(axes, copyaxes=copyaxes) # Note: clobbers the grid, so set the grid after.
if grid is not None:
self.setGrid(grid)
# Initialize attributes
fv = self.fill_value
if attributes is not None:
for key, value in attributes.items():
if (key in ['shape','flat','imaginary','real'] or key[0]=='_') and key not in ['_FillValue']:
raise CDMSError, 'Bad key in attributes: ' + key
elif key == 'missing_value':
#ignore if fill value given explicitly
if fill_value is None:
fv = value
elif key not in ['scale_factor','add_offset']:
setattr(self, key, value)
# Sync up missing_value attribute and the fill value.
self.missing_value = fv
if id is not None:
if type(id) is not types.StringType:
raise CDMSError, 'id must be a string'
self.id = id
elif hasattr(data,'id'):
self.id = data.id
if self.id is None:
TransientVariable.variable_count = TransientVariable.variable_count + 1
self.id = 'variable_' + str(TransientVariable.variable_count)
self.name = getattr(self, 'name', self.id)
开发者ID:MartinDix,项目名称:cdat_lite_test,代码行数:71,代码来源:tvariable.py
示例14: markError
x1 = uf+1.0
x2 = 1.0-ud
x11 = -uf
x12 = MV2.absolute(ud)
x3 = uf+x2
x4 = 1.0+ud
x5 = uf-1
x6 = ud*uf
x7 = ud/x2
x8=1/uf
x9 = 3*ud
x10=uf**3
x13 = MV2.add.reduce(uf)
x14 = MV2.add.reduce(ud)
x15 = x9.astype(numpy.float32)
if not x15.dtype.char==numpy.sctype2char(numpy.float32): markError('astype error')
## arrayrange(start, stop=None, step=1, typecode=None, axis=None, attributes=None, id=None)
## Just like range() except it returns a variable whose type can be specfied
## by the keyword argument typecode. The axis of the result variable may be specified.
xarange = MV2.arange(16., axis=ulat)
## masked_array(a, mask=None, fill_value=None, axes=None, attributes=None, id=None)
## masked_array(a, mask=None) =
## array(a, mask=mask, copy=0, fill_value=fill_value)
## Use fill_value(a) if None.
xmarray = MV2.masked_array(ud)
## masked_object(data, value, copy=1, savespace=0)
## Create array masked where exactly data equal to value
开发者ID:MartinDix,项目名称:cdat_lite_test,代码行数:30,代码来源:cdtest11.py
示例15: test_other_type
def test_other_type(self):
assert_equal(np.sctype2char(float), 'd')
assert_equal(np.sctype2char(list), 'O')
assert_equal(np.sctype2char(np.ndarray), 'O')
开发者ID:Horta,项目名称:numpy,代码行数:4,代码来源:test_numerictypes.py
示例16: test_array_instance
def test_array_instance(self):
assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd')
开发者ID:Horta,项目名称:numpy,代码行数:2,代码来源:test_numerictypes.py
示例17: test_scalar_type
def test_scalar_type(self):
assert_equal(np.sctype2char(np.double), 'd')
assert_equal(np.sctype2char(np.int_), 'l')
assert_equal(np.sctype2char(np.unicode_), 'U')
assert_equal(np.sctype2char(np.bytes_), 'S')
开发者ID:Horta,项目名称:numpy,代码行数:5,代码来源:test_numerictypes.py
示例18: markError
if bounds is None: markError('getBounds')
if axis0.getCalendar()!=cdtime.MixedCalendar: markError('getCalendar')
val = axis1.getValue()
if not numpy.ma.allequal(axis1.getValue(),axis1[:]): markError('getValue')
if not axis0.isTime(): markError('isTime')
if not axis1.isLatitude(): markError('isLatitude')
if not axis2.isLongitude(): markError('isLongitude')
#
# mf 20010405 if this PASSES it's an error
#
if axis2.isCircular(): markError('isCircular')
if len(axis2)!=17: markError('Axis length')
saxis = axis2.subAxis(1,-1)
if not numpy.ma.allequal(saxis[:],axis2[1:-1]): markError('subAxis',saxis[:])
if axis1.typecode()!=numpy.sctype2char(numpy.float): markError('Axis typecode')
if axis2.shape!=(17,): markError('Axis shape')
# Axis set: bounds, calendar
savebounds = copy.copy(bounds)
bounds[0,0]=-90.0
axis1.setBounds(bounds)
nbounds = axis1.getBounds()
if not numpy.ma.allequal(bounds,nbounds): markError('Axis setBounds')
axis0.setCalendar(cdtime.NoLeapCalendar)
if axis0.getCalendar()!=cdtime.NoLeapCalendar: markError('setCalendar')
gaussaxis = cdms2.createGaussianAxis(32)
try:
testaxis = cdms2.createGaussianAxis(31)
except:
markError('Gaussian axis with odd number of latitudes')
开发者ID:NCPP,项目名称:uvcdat-devel,代码行数:31,代码来源:cdtest06.py
示例19: __init__
def __init__(
self,
data,
typecode=None,
copy=1,
savespace=0,
mask=numpy.ma.nomask,
fill_value=None,
grid=None,
axes=None,
attributes=None,
id=None,
copyaxes=1,
dtype=None,
order=False,
no_update_from=False,
**kargs
):
"""createVariable (self, data, typecode=None, copy=0, savespace=0,
mask=None, fill_value=None, grid=None,
axes=None, attributes=None, id=None, dtype=None, order=False)
The savespace argument is ignored, for backward compatibility only.
"""
# tile index, None means no mosaic
self.tileIndex = None
# Compatibility: assuming old typecode, map to new
if dtype is None and typecode is not None:
dtype = typeconv.convtypecode2(typecode)
typecode = sctype2char(dtype)
if type(data) is types.TupleType:
data = list(data)
AbstractVariable.__init__(self)
if isinstance(data, AbstractVariable):
if not isinstance(data, TransientVariable):
data = data.subSlice()
## if attributes is None: attributes = data.attributes
if axes is None and not no_update_from:
axes = map(lambda x: x[0], data.getDomain())
if grid is None and not no_update_from:
grid = data.getGrid()
if (grid is not None) and (not isinstance(grid, AbstractRectGrid)) and (not grid.checkAxes(axes)):
grid = grid.reconcile(axes) # Make sure grid and axes are consistent
ncopy = copy != 0
# Initialize the geometry
if grid is not None:
copyaxes = 0 # Otherwise grid axes won't match domain.
if axes is not None:
self.initDomain(axes, copyaxes=copyaxes) # Note: clobbers the grid, so set the grid after.
if grid is not None:
self.setGrid(grid)
# Initialize attributes
fv = self.fill_value
if attributes is not None:
for key, value in attributes.items():
if (key in ["shape", "flat", "imaginary", "real"] or key[0] == "_") and key not in ["_FillValue"]:
raise CDMSError, "Bad key in attributes: " + key
elif key == "missing_value":
# ignore if fill value given explicitly
if fill_value is None:
fv = value
elif key not in ["scale_factor", "add_offset"]:
setattr(self, key, value)
# Sync up missing_value attribute and the fill value.
self.missing_value = fv
if id is not None:
if not isinstance(id, (unicode, str)):
raise CDMSError, "id must be a string"
self.id = id
elif hasattr(data, "id"):
self.id = data.id
if self.id is None:
TransientVariable.variable_count = TransientVariable.variable_count + 1
self.id = "variable_" + str(TransientVariable.variable_count)
self.name = getattr(self, "name", self.id)
# MPI data members
self.__mpiComm = None
if HAVE_MPI:
self.__mpiComm = MPI.COMM_WORLD
self.__mpiWindows = {}
self.__mpiType = self.__getMPIType()
开发者ID:arulalant,项目名称:uvcdat,代码行数:90,代码来源:tvariable.py
示例20:
CdChar = CDML.CdChar
CdByte = CDML.CdByte
CdShort = CDML.CdShort
CdInt = CDML.CdInt
CdLong = CDML.CdLong
CdFloat = CDML.CdFloat
CdDouble = CDML.CdDouble
CdString = CDML.CdString
CdFromObject = CDML.CdFromObject
CdAny = CDML.CdAny
CdDatatypes = [CdChar,CdByte,CdShort,CdInt,CdLong,CdFloat,CdDouble,CdString]
CdScalar = CDML.CdScalar
CdArray = CDML.CdArray
NumericToCdType = {numpy.sctype2char(numpy.float32):CdFloat,
numpy.sctype2char(numpy.float):CdDouble,
numpy.sctype2char(numpy.int16):CdShort,
numpy.sctype2char(numpy.int32):CdInt,
numpy.sctype2char(numpy.int):CdLong,
numpy.sctype2char(numpy.intc):CdLong,
numpy.sctype2char(numpy.int8):CdByte,
'c':CdChar,
'B':'B',
'H':'H',
'L':'L',
'q':'q',
'Q':'Q',
'S':'S'
}
开发者ID:metocean,项目名称:cdms,代码行数:30,代码来源:cdmsNode.py
注:本文中的numpy.sctype2char函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论