本文整理汇总了Python中numpy.right_shift函数的典型用法代码示例。如果您正苦于以下问题:Python right_shift函数的具体用法?Python right_shift怎么用?Python right_shift使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了right_shift函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: take_still
def take_still(self, pic_path):
#TODO push the spi specifics into config paramters
with pylepton.Lepton("/dev/spidev0.1") as l:
a,_ = l.capture()
cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
np.right_shift(a, 8, a)
cv2.imwrite(pic_path, np.uint8(a))
开发者ID:srik901,项目名称:thermal,代码行数:7,代码来源:cameras.py
示例2: get_mask
def get_mask(modQA, dilate=7):
""" Return a mask image from an input QA band from M[OY]D09G[AQ]
Args:
modQA (ndarray): input QA/QC band image
dilate (int, optional): pixels around aerosols and clouds to buffer
Returns:
mask (ndarray): output mask image with only good observations masked
Porting note:
MATLAB's 'bitshift' shifts to the left
"""
# Identify land from water
land = (np.mod(np.right_shift(modQA, 3) + 6, 8) / 7).astype(np.uint8)
# Identify cloud
cloud = (np.mod(modQA, 8) | # unsure!
np.mod(np.right_shift(modQA, 8), 4) | # cirrus == '00' (none)
np.mod(np.right_shift(modQA, 10), 2) | # cloud mask == '0'
np.mod(np.right_shift(modQA, 13), 2)) > 0 # adjacent to cloud
cloud_buffer = scipy.ndimage.morphology.binary_dilation(
cloud, structure=np.ones((dilate, dilate)))
return ((cloud_buffer == 0) * land)
开发者ID:ceholden,项目名称:NRTwarn,代码行数:26,代码来源:prep_MODIS.py
示例3: _split
def _split(data, flip=False):
'''
Helper function to take the 16-bit integer saved in the neural data file
and map it back to the three fields of the message type (see docs on
communication protocol for details)
Parameters
----------
data : np.ndarray
Integer data and timestamps as stored in the neural data file when messages were sent during experiment
Returns
-------
np.ndarray
Raw message data split into the fields (type, aux, "payload")
'''
# If the data is a 1D array, extract the timestamps and the raw event codes
if len(data.shape) < 2:
data = np.array(data[data['chan'] == 257][['ts', 'unit']].tolist())
msgs = data[:,1].astype(np.int16)
if not flip:
msgs = ~msgs # bit-flip the binary messages
msgtype = np.right_shift(np.bitwise_and(msgs, msgtype_mask), 8).astype(np.uint8)
auxdata = np.right_shift(np.bitwise_and(msgs, auxdata_mask), 8).astype(np.uint8)
rawdata = np.bitwise_and(msgs, rawdata_mask)
return np.vstack([data[:,0], msgtype, auxdata, rawdata]).T
开发者ID:carmenalab,项目名称:brain-python-interface,代码行数:27,代码来源:parse.py
示例4: unpack_4byte_IBM
def unpack_4byte_IBM(file, count, endian='>'):
"""
Unpacks 4 byte IBM floating points.
"""
# Read as 4 byte integer so bit shifting works.
data = np.fromstring(file.read(count * 4), dtype='int32')
# Swap the byteorder if necessary.
if BYTEORDER != endian:
data = data.byteswap()
# See http://mail.scipy.org/pipermail/scipy-user/2009-January/019392.html
# XXX: Might need check for values out of range:
# http://bytes.com/topic/c/answers/
# 221981-c-code-converting-ibm-370-floating-point-ieee-754-a
sign = np.bitwise_and(np.right_shift(data, 31), 0x01)
sign = np.require(sign, 'float32')
exponent = np.bitwise_and(np.right_shift(data, 24), 0x7f)
mantissa = np.bitwise_and(data, 0x00ffffff)
# Force single precision.
mantissa = np.require(mantissa, 'float32')
mantissa /= 0x1000000
# Do the following calculation in a weird way to avoid autocasting to
# float64.
# data = (1.0 - 2.0 * sign) * mantissa * 16.0 ** (exponent - 64.0)
sign *= -2.0
sign += 1.0
mantissa *= 16.0 ** (exponent - 64)
mantissa *= sign
return mantissa
开发者ID:rvbelefonte,项目名称:Rockfish,代码行数:28,代码来源:unpack.py
示例5: decode
def decode(data):
"""
Decode the binary data into event time (absolute, highest precision),
channel number and special bit. See HH documentation about the details.
"""
if len(data) == 0:
return np.zeros((0, 3), dtype='u8')
t0 = time.time()
length = data.shape[0]
print '* decode {} events... '.format(length),
event_time = np.bitwise_and(data, 2**25-1)
channel = np.bitwise_and(np.right_shift(data, 25), 2**6 - 1)
special = np.bitwise_and(np.right_shift(data, 31), 1)
# we want to convert time that is supplemented by overflows into absolute
# time in ps -- this requires 64 bit precision! ('u8')
ret = np.zeros((length, 3), dtype='u8')
ret[:,0] = event_time
ret[:,1] = channel
ret[:,2] = special
t1 = time.time() - t0
print 'done ({:.2f} s).'.format(t1)
return ret
开发者ID:AdriaanRol,项目名称:measurement,代码行数:27,代码来源:HH_analysis_test_DEPRECATED.py
示例6: writeframesraw
def writeframesraw(self, data):
nframes = len(data) // (self._nchannels)
if self._wFormatTag == WAVE_FORMAT_PCM and 2 == self._sampwidth:
data_to_write = np.multiply(data, 0x7fff)
data_to_write.astype(np.int16).tofile(self._file)
elif self._wFormatTag == WAVE_FORMAT_PCM and 4 == self._sampwidth:
data_to_write = np.multiply(data, 0x7fffffff)
data_to_write.astype(np.int32).tofile(self._file)
elif self._wFormatTag == WAVE_FORMAT_PCM and 3 == self._sampwidth:
data = np.multiply(data, 0x7fffffff)
data = data.astype(np.int32)
bytes = np.zeros(data.size * 3, dtype=np.uint8)
bytes[0::3] = np.right_shift(data, 8)
bytes[1::3] = np.right_shift(data, 16)
bytes[2::3] = np.right_shift(data, 24)
bytes.tofile(self._file)
elif self._wFormatTag == WAVE_FORMAT_IEEE_FLOAT and 4 == self._sampwidth:
data.tofile(self._file)
else:
print 'oops'
self._datawritten = self._datawritten + (len(data) * self._sampwidth)
self._nframeswritten = self._nframeswritten + nframes
开发者ID:MaximOtto,项目名称:wavepy,代码行数:30,代码来源:pywav.py
示例7: testIntOps
def testIntOps(self):
for dtype in self.int_types:
self._testBinary(
gen_math_ops._truncate_div,
np.array([3, 3, -1, -9, -8], dtype=dtype),
np.array([2, -2, 7, 2, -4], dtype=dtype),
expected=np.array([1, -1, 0, -4, 2], dtype=dtype))
self._testSymmetricBinary(
bitwise_ops.bitwise_and,
np.array([0b1, 0b101, 0b1000], dtype=dtype),
np.array([0b0, 0b101, 0b1001], dtype=dtype),
expected=np.array([0b0, 0b101, 0b1000], dtype=dtype))
self._testSymmetricBinary(
bitwise_ops.bitwise_or,
np.array([0b1, 0b101, 0b1000], dtype=dtype),
np.array([0b0, 0b101, 0b1001], dtype=dtype),
expected=np.array([0b1, 0b101, 0b1001], dtype=dtype))
lhs = np.array([0, 5, 3, 14], dtype=dtype)
rhs = np.array([5, 0, 7, 11], dtype=dtype)
self._testBinary(
bitwise_ops.left_shift, lhs, rhs,
expected=np.left_shift(lhs, rhs))
self._testBinary(
bitwise_ops.right_shift, lhs, rhs,
expected=np.right_shift(lhs, rhs))
if dtype in [np.int8, np.int16, np.int32, np.int64]:
lhs = np.array([-1, -5, -3, -14], dtype=dtype)
rhs = np.array([5, 0, 1, 11], dtype=dtype)
self._testBinary(
bitwise_ops.right_shift, lhs, rhs,
expected=np.right_shift(lhs, rhs))
开发者ID:craffel,项目名称:tensorflow,代码行数:33,代码来源:binary_ops_test.py
示例8: amagacolor
def amagacolor(secret, red, green, blue):
red = np.left_shift(np.right_shift(red,2),2)
green = np.left_shift(np.right_shift(green,2),2)
blue = np.left_shift(np.right_shift(blue,2),2)
secretred,secretgreen,secretblue = separaimatge(secret,2,2,2)
return red+secretred, green+secretgreen, blue+secretblue
开发者ID:Extintor,项目名称:piva,代码行数:7,代码来源:p3script2.py
示例9: countBits
def countBits(values):
# bit shifting routines are in numpy 1.4
from numpy import array, left_shift, right_shift
v = array(values).astype('uint32')
# Bit counting for a 32 bit unsigned integer.
# there is a fully generic version of this method at
# http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
# Binary magic numbers method, also found in pages 187-188 of Software Optimization Guide for AMD Athlon 64 and Opteron Processors.
# The C version is:
# v = v - ((v >> 1) & 0x55555555); # reuse input as temporary
# v = (v & 0x33333333) + ((v >> 2) & 0x33333333); # temp
# c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; # count
fives = int('0x55555555', base=16)
threes = int('0x33333333', base=16)
effs = int('0xF0F0F0F', base=16)
ones = int('0x1010101', base=16)
v = v - ( (right_shift(v, 1)) & fives); # reuse input as temporary
v = (v & threes) + ( (right_shift(v,2)) & threes); # temp
c = right_shift(((v + (right_shift(v,4)) & effs) * ones), 24); # count
return c
开发者ID:Vsalinas91,项目名称:lmatools,代码行数:26,代码来源:LMA_h5_write.py
示例10: rearrange_bits
def rearrange_bits(array):
# Do bit rearrangement for the 10-bit lytro raw format
# Normalize output to 1.0 as float64
t0 = array[0::5]
t1 = array[1::5]
t2 = array[2::5]
t3 = array[3::5]
lsb = array[4::5]
t0 = np.left_shift(t0, 2) + np.bitwise_and(lsb, 3)
t1 = np.left_shift(t1, 2) + np.right_shift(np.bitwise_and(lsb, 12), 2)
t2 = np.left_shift(t2, 2) + np.right_shift(np.bitwise_and(lsb, 48), 4)
t3 = np.left_shift(t3, 2) + np.right_shift(np.bitwise_and(lsb, 192), 6)
image = np.zeros(LYTRO_ILLUM_IMAGE_SIZE, dtype=np.uint16)
image[:, 0::4] = t0.reshape(
(LYTRO_ILLUM_IMAGE_SIZE[0], LYTRO_ILLUM_IMAGE_SIZE[1] // 4)
)
image[:, 1::4] = t1.reshape(
(LYTRO_ILLUM_IMAGE_SIZE[0], LYTRO_ILLUM_IMAGE_SIZE[1] // 4)
)
image[:, 2::4] = t2.reshape(
(LYTRO_ILLUM_IMAGE_SIZE[0], LYTRO_ILLUM_IMAGE_SIZE[1] // 4)
)
image[:, 3::4] = t3.reshape(
(LYTRO_ILLUM_IMAGE_SIZE[0], LYTRO_ILLUM_IMAGE_SIZE[1] // 4)
)
# Normalize data to 1.0 as 64-bit float.
# Division is by 1023 as the Lytro Illum saves 10-bit raw data.
return np.divide(image, 1023.0).astype(np.float64)
开发者ID:imageio,项目名称:imageio,代码行数:31,代码来源:lytro.py
示例11: runCode
def runCode():
while True:
global pixdata, json_data, image, multiplicationFactor
FileName = "output.png"
with Lepton() as l:
a, _ = l.capture()
cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX) # extend contrast
np.right_shift(a, 8, a) # fit data into 8 bits
cv2.imwrite(FileName, np.uint8(a))
image = Image.open(FileName)
imageOrigin = Image.open(FileName)
image = image.convert('RGB')
pixdata = image.load()
analyze()
imageOrigin = imageOrigin.resize((80 * multiplicationFactor, 60 * multiplicationFactor))
imageOrigin.save(FileName)
with open(FileName, 'rb') as f:
imdata = f.read()
f.close()
json_blobs = json.dumps(blobs, default=obj_dict)
outjson = {
"blobs": json.loads(json_blobs),
"img": imdata.encode('base64'),
"multiplicationFactor": multiplicationFactor
}
json_data = json.dumps(outjson)
开发者ID:SaranshPK,项目名称:HumanTracking,代码行数:30,代码来源:LeptonServer.py
示例12: load_packed_data_3_32
def load_packed_data_3_32(infile, sample, readlen):
start = (sample // 3) * 4
offset = sample % 3
start, offset
infile.seek(start)
# we need another word in case offset != 0
needed = int(np.ceil(readlen * 3 / 4) * 4) + 4
inbuf = infile.read(needed)
indata = np.fromstring(inbuf, 'uint32', len(inbuf) // 4)
if len(indata) < needed:
return None
unpacked = np.zeros(len(indata) * 3, dtype=np.int16)
# By using strides the unpacked data can be loaded with no additional copies
np.bitwise_and(indata, 0x3ff, out = unpacked[0::3])
# hold the shifted bits in it's own array to avoid an allocation
tmp = np.right_shift(indata, 10)
np.bitwise_and(tmp, 0x3ff, out = unpacked[1::3])
np.right_shift(indata, 20, out = tmp)
np.bitwise_and(tmp, 0x3ff, out = unpacked[2::3])
return unpacked[offset:offset + readlen]
开发者ID:happycube,项目名称:ld-decode,代码行数:27,代码来源:lddutils.py
示例13: cloudMask
def cloudMask(tiffFolder):
"""
The cloudMask includes pixels identified as cloud, shadow, or snow in the Quality Assessment band (BQA).
Masked pixels have a value of 0 and clear pixels have a value of 1. If there is no BQA, invoke Fmask.
"""
return_value = True;
inputTiffName=os.path.join(tiffFolder,os.path.basename(tiffFolder)) + "_BQA.TIF"
print "In cloudMask checking for: " +inputTiffName
outputTiffName=os.path.join(tiffFolder,os.path.basename(tiffFolder)) + "_MTLFmask.TIF"
if os.path.exists(inputTiffName):
[maskArray, geoTiffAtts]= LSFGeoTIFF.ReadableLSFGeoTIFF.fromFile(inputTiffName).asGeoreferencedArray()
# USGS documentation
# shown here: https://landsat.usgs.gov/collectionqualityband
# for example, decimal 2800 = binary 0000101011110000 which would be:
# bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
# 0 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0
# high confidence cloud, bits 4, 5, and 6.
cloud=np.equal(np.right_shift(np.bitwise_and(maskArray, 112), 4), 7)
# high confidence cloud shadow, bits 7 and 8
shadow=np.equal(np.right_shift(np.bitwise_and(maskArray, 496), 7), 3)
# high confidence snow/ice, bits 9 and 10.
snow=np.equal(np.right_shift(np.bitwise_and(maskArray, 1536), 9), 3)
# if cloud, shadow, or snow mask is set for a pixel, mask it in newMask
newMask = np.logical_not(np.logical_or(np.logical_or(cloud,shadow),snow))
LSFGeoTIFF.Unsigned8BitLSFGeoTIFF.fromArray(newMask, geoTiffAtts).write(outputTiffName)
else:
print "Begin Fmask processing " + str(datetime.datetime.now())
return_value = runFmask(tiffFolder,fmaskShellCall)
print "End Fmask processing " + str(datetime.datetime.now())
return return_value
开发者ID:nemac,项目名称:landsatfact-data,代码行数:31,代码来源:rasterAnalysis_GDAL.py
示例14: process_t3records
def process_t3records(t3records, time_bit=10, dtime_bit=15,
ch_bit=6, special_bit=True, ovcfunc=None):
"""Extract the different fields from the raw t3records array (.ht3).
Returns:
3 arrays representing detectors, timestamps and nanotimes.
"""
if special_bit:
ch_bit += 1
assert ch_bit <= 8
assert dtime_bit <= 16
detectors = np.bitwise_and(
np.right_shift(t3records, time_bit + dtime_bit), 2**ch_bit - 1).astype('uint8')
nanotimes = np.bitwise_and(
np.right_shift(t3records, time_bit), 2**dtime_bit - 1).astype('uint16')
assert time_bit <= 16
dt = np.dtype([('low16', 'uint16'), ('high16', 'uint16')])
t3records_low16 = np.frombuffer(t3records, dt)['low16'] # View
timestamps = t3records_low16.astype(np.int64) # Copy
np.bitwise_and(timestamps, 2**time_bit - 1, out=timestamps)
overflow_ch = 2**ch_bit - 1
overflow = 2**time_bit
if ovcfunc is None:
ovcfunc = _correct_overflow
ovcfunc(timestamps, detectors, overflow_ch, overflow)
return detectors, timestamps, nanotimes
开发者ID:lampo808,项目名称:phconvert,代码行数:30,代码来源:pqreader.py
示例15: _dec10216
def _dec10216(inbuf):
inbuf = np.fromstring(inbuf, dtype=np.uint8)
arr10 = inbuf.astype(np.uint16)
arr16 = np.zeros((len(arr10) / 5 * 4,), dtype=np.uint16)
arr10_len = (len(arr16) * 5) / 4
arr10 = arr10[:arr10_len] # adjust size
"""
/*
* pack 4 10-bit words in 5 bytes into 4 16-bit words
*
* 0 1 2 3 4 5
* 01234567890123456789012345678901234567890
* 0 1 2 3 4
*/
ip = &in_buffer[i];
op = &out_buffer[j];
op[0] = ip[0]*4 + ip[1]/64;
op[1] = (ip[1] & 0x3F)*16 + ip[2]/16;
op[2] = (ip[2] & 0x0F)*64 + ip[3]/4;
op[3] = (ip[3] & 0x03)*256 +ip[4];
"""
arr16.flat[::4] = np.left_shift(arr10[::5], 2) + \
np.right_shift((arr10[1::5]), 6)
arr16.flat[1::4] = np.left_shift((arr10[1::5] & 63), 4) + \
np.right_shift((arr10[2::5]), 4)
arr16.flat[2::4] = np.left_shift(arr10[2::5] & 15, 6) + \
np.right_shift((arr10[3::5]), 2)
arr16.flat[3::4] = np.left_shift(arr10[3::5] & 3, 8) + \
arr10[4::5]
return arr16.tostring()
开发者ID:metno,项目名称:mipp,代码行数:30,代码来源:convert.py
示例16: capture
def capture(flip_v = False, device = "/dev/spidev0.1"):
with Lepton(device) as l:
a,_ = l.capture()
if flip_v:
cv2.flip(a,0,a)
cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
np.right_shift(a, 8, a)
return np.uint8(a)
开发者ID:DevinMui,项目名称:FLIR,代码行数:8,代码来源:flir.py
示例17: lcls2float
def lcls2float(t):
if isinstance(t, numpy.ndarray):
t0 = numpy.right_shift(t.astype(numpy.uint64), numpy.uint64(32))
else:
t0 = numpy.right_shift(numpy.uint64(t), numpy.uint64(32))
t1 = numpy.bitwise_and(numpy.uint64(t), numpy.uint64(0x00000000fffffffff))
t2 = t0 + t1*1.e-9
return t2
开发者ID:FilipeMaia,项目名称:hummingbird,代码行数:8,代码来源:lclstime.py
示例18: GetImage
def GetImage(raw_values):
STORED_IMAGE_NAME = "DetectionImage.jpg"
#img = get_raw_values() # Get raw image values
cv2.normalize(raw_values, raw_values, 0, 65535, cv2.NORM_MINMAX) # Normalize image
np.right_shift(raw_values,8,raw_values) # Shift to 8 bit array
cv2.imwrite(STORED_IMAGE_NAME, np.uint8(raw_values)) # Write the image to file
simplecv_img = Image(STORED_IMAGE_NAME) # Take the image from file as SIMPLECV image
return simplecv_img
开发者ID:GintasTr,项目名称:MCS_Software,代码行数:8,代码来源:Hot_Spot_Detection_V2.py
示例19: capture
def capture(flip_v = False, device = "/dev/spidev0.0"):
with Lepton(device) as l:
lepton_buf,_ = l.capture()
if flip_v:
cv2.flip(lepton_buf,0,lepton_buf)
cv2.normalize(lepton_buf, lepton_buf, 0, 65535, cv2.NORM_MINMAX)
np.right_shift(lepton_buf, 8, lepton_buf)
return np.uint8(lepton_buf)
开发者ID:stevealbertwong,项目名称:pylepton,代码行数:8,代码来源:gimme5_v1.py
示例20: test_shift
def test_shift(self):
from numpy import left_shift, right_shift, dtype
assert (left_shift([5, 1], [2, 13]) == [20, 2 ** 13]).all()
assert (right_shift(10, range(5)) == [10, 5, 2, 1, 0]).all()
bool_ = dtype("bool").type
assert left_shift(bool(1), 3) == left_shift(1, 3)
assert right_shift(bool(1), 3) == right_shift(1, 3)
开发者ID:Qointum,项目名称:pypy,代码行数:8,代码来源:test_ufuncs.py
注:本文中的numpy.right_shift函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论