Module pysdrlib.base.io
Functions
def b2t(buff, width, otype)-
Expand source code
def b2t(buff, width, otype): """Offset binary to two's compliment""" out = np.empty_like(buff, dtype=otype) out = buff - (2**(width-1)) return outOffset binary to two's compliment
def m2t(buff, width, otype)-
Expand source code
def m2t(buff, width, otype): """Sign Magnitude to two's compliment""" out = np.copy(buff).astype(otype) m1 = buff >= (2**(width-1)) out[m1] = (2**(width-1)) - buff[m1] return outSign Magnitude to two's compliment
def o2t(buff, width, otype)-
Expand source code
def o2t(buff, width, otype): """One's compliment to two's compliment""" out = np.copy(buff).astype(otype) m1 = buff >= (2**(width-1)) out[m1] = buff[m1] - (2**width-1) return outOne's compliment to two's compliment
Classes
class ComplexFormat-
Expand source code
class ComplexFormat(Format): """Format subclass for complex numbers""" BASE: type = None # type: ignore @classmethod def read(cls, io, count): raise NotImplementedError()Format subclass for complex numbers
Ancestors
Subclasses
Class variables
var BASE : type
Static methods
def read(io, count)
Inherited members
class Format-
Expand source code
class Format: SIZE = 0 @classmethod def read(cls, io, count): raise NotImplementedError() @classmethod def write(cls, io, data): io.write(data.tobytes()) @classmethod def bits(cls): """Return size of format in bits""" return cls.SIZE @classmethod def bytes(cls): """Return size of format in bytes""" return cls.SIZE // 8 @classmethod def _read(cls, io, count, dtype): return np.frombuffer(io.read(int(cls.bytes()*count)), dtype=dtype)Subclasses
Class variables
var SIZE
Static methods
def bits()-
Return size of format in bits
def bytes()-
Return size of format in bytes
def read(io, count)def write(io, data)
class cf128-
Expand source code
class cf128(ComplexFormat): """Complex float128 (f64, f64)""" SIZE = 128 BASE = f64 @classmethod def read(cls, io, count): return cls.BASE.read(io, count*2).view(dtype=np.complex128)Complex float128 (f64, f64)
Ancestors
Class variables
var BASE : type-
Eq. to C float64_t
var SIZE
Static methods
def read(io, count)
Inherited members
class cf32-
Expand source code
class cf32(ComplexFormat): """Complex float32 (f16, f16)""" SIZE = 32 BASE = f16 @classmethod def read(cls, io, count): return cls.BASE.read(io, count*2).astype(np.float32).view(dtype=np.complex64)Complex float32 (f16, f16)
Ancestors
Class variables
var BASE : type-
Eq. to C float16_t
var SIZE
Static methods
def read(io, count)
Inherited members
class cf64-
Expand source code
class cf64(ComplexFormat): """Complex float64 (f32, f32)""" SIZE = 64 BASE = f32 @classmethod def read(cls, io, count): return cls.BASE.read(io, count*2).view(dtype=np.complex64)Complex float64 (f32, f32)
Ancestors
Class variables
var BASE : type-
Eq. to C float32_t
var SIZE
Static methods
def read(io, count)
Inherited members
class ci16_t-
Expand source code
class ci16_t(ComplexFormat): """Complex int16 (i8, i8)""" SIZE = 16 BASE = i8_t @classmethod def read(cls, io, count): return cls.BASE.read(io, count*2).astype(np.float32).view(dtype=np.complex64)Complex int16 (i8, i8)
Ancestors
Class variables
var BASE : type-
Two's compliment int8, Eq. to C int8_t
var SIZE
Static methods
def read(io, count)
Inherited members
class ci32_t-
Expand source code
class ci32_t(ComplexFormat): """Complex int32 (i16, i16)""" SIZE = 32 BASE = i16_t @classmethod def read(cls, io, count): return cls.BASE.read(io, count*2).astype(np.float32).view(dtype=np.complex64)Complex int32 (i16, i16)
Ancestors
Class variables
var BASE : type-
Two's compliment int16, Eq. to C int16_t
var SIZE
Static methods
def read(io, count)
Inherited members
class ci8_t-
Expand source code
class ci8_t(ComplexFormat): """Complex int8 (i4, i4)""" SIZE = 8 BASE = i4_t @classmethod def read(cls, io, count): return cls.BASE.read(io, count*2).astype(np.float32).view(dtype=np.complex64)Complex int8 (i4, i4)
Ancestors
Class variables
var BASE : type-
Two's compliment int4
var SIZE
Static methods
def read(io, count)
Inherited members
class f16-
Expand source code
class f16(Format): """Eq. to C float16_t""" SIZE = 16 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.float16)Eq. to C float16_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class f32-
Expand source code
class f32(Format): """Eq. to C float32_t""" SIZE = 32 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.float32)Eq. to C float32_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class f64-
Expand source code
class f64(Format): """Eq. to C float64_t""" SIZE = 32 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.float64)Eq. to C float64_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i16_o-
Expand source code
class i16_o(Format): """One's compliment int16""" SIZE = 16 @classmethod def read(cls, io, count): buff = cls._read(io, count, dtype=np.uint16) out = (buff + (buff >> 15)) return out.astype(np.int16) # return o2t(buff, cls.SIZE, np.int16)One's compliment int16
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i16_t-
Expand source code
class i16_t(Format): """Two's compliment int16, Eq. to C int16_t""" SIZE = 16 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.int16)Two's compliment int16, Eq. to C int16_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i32_t-
Expand source code
class i32_t(Format): """Two's compliment int32, Eq. to C int32_t""" SIZE = 32 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.int32)Two's compliment int32, Eq. to C int32_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i4_o-
Expand source code
class i4_o(Format): """One's compliment int4""" SIZE = 4 @classmethod def read(cls, io, count): _bytes = cls._read(io, count//2, dtype=np.uint8) buff = np.empty(count, dtype=np.int8) buff[::2] = (_bytes & 0b10000000) | ((_bytes & 0b01110000) >> 4) buff[1::2] = ((_bytes & 0b00001000) << 3) (_bytes & 0b00000111) out = (buff + (buff >> 7)) return out.astype(np.int8)One's compliment int4
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i4_t-
Expand source code
class i4_t(Format): """Two's compliment int4""" SIZE = 4 @classmethod def read(cls, io, count): # TODO: test signed bit logic _bytes = cls._read(io, count//2, dtype=np.uint8) buff = np.empty(count, dtype=np.int8) buff[::2] = (_bytes & 0b10000000) | ((_bytes & 0b01110000) >> 4) buff[1::2] = ((_bytes & 0b00001000) << 3) (_bytes & 0b00000111) return buffTwo's compliment int4
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i8_o-
Expand source code
class i8_o(Format): """One's compliment int8""" SIZE = 8 @classmethod def read(cls, io, count): buff = cls._read(io, count, dtype=np.uint8) out = (buff + (buff >> 7)) return out.astype(np.int8) # return o2t(buff, cls.SIZE, np.int8)One's compliment int8
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class i8_t-
Expand source code
class i8_t(Format): """Two's compliment int8, Eq. to C int8_t""" SIZE = 8 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.int8)Two's compliment int8, Eq. to C int8_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class ui16_t-
Expand source code
class ui16_t(Format): """Two's compliment uint16, Eq. to C uint16_t""" SIZE = 8 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.uint16)Two's compliment uint16, Eq. to C uint16_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class ui32_t-
Expand source code
class ui32_t(Format): """Two's compliment uint32, Eq. to C int32_t""" SIZE = 8 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.uint32)Two's compliment uint32, Eq. to C int32_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members
class ui8_t-
Expand source code
class ui8_t(Format): """Two's compliment uint8, Eq. to C uint8_t""" SIZE = 8 @classmethod def read(cls, io, count): return cls._read(io, count, dtype=np.uint8)Two's compliment uint8, Eq. to C uint8_t
Ancestors
Class variables
var SIZE
Static methods
def read(io, count)
Inherited members