Coverage for /opt/obspy/update-docs/src/obspy/obspy/segy/pack : 89%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- #------------------------------------------------------------------- # Filename: unpack.py # Purpose: Routines for unpacking SEG Y data formats. # Author: Lion Krischer # Email: krischer@geophysik.uni-muenchen.de # # Copyright (C) 2010 Lion Krischer #--------------------------------------------------------------------- Functions that will all take a file pointer and the sample count and return a NumPy array with the unpacked values. """
# Get the system byteorder. else: BYTEORDER = '>'
""" Packs 4 byte IBM floating points. This will only work if the host system internally uses little endian byteorders. """ # Check the dtype and raise exception otherwise! raise WrongDtypeException # Calculate the values. The theory is explained in # http://www.codeproject.com/KB/applications/libnumber.aspx
# Calculate the signs. # Negative numbers are encoded as sign bit 1, positive ones as bit 0.
# Make absolute values.
# Store the zeros and add an offset for numerical stability, # they will be set to zero later on again
# Calculate the exponent for the IBM data format.
# Now calculate the fraction using single precision. (16.0 ** (np.require(exponent, 'float32') - 64))
# Normalization. # Find numbers smaller than 1/16 but not zero. fraction[non_normalized] *= 16 exponent[non_normalized] -= 1
# If the fraction is one, change it to 1/16 and increase the exponent by # one.
# Times 2^24 to be able to get a long. # Convert to unsigned long.
# Use 8 bit integers to be able to store every byte separately.
# The first bit is the sign and the following 7 are the exponent. # All following 24 bit are the fraction. 16), 'uint8') 8), 'uint8')
# Depending on the endianness store the data different. # big endian. # little endian> # Should not happen. else: raise Exception # Write the zeros again. # Write to file.
""" Packs 4 byte integers. """ # Check the dtype and raise exception otherwise! raise WrongDtypeException # Swap the byteorder if necessary. # Write the file.
""" Packs 2 byte integers. """ # Check the dtype and raise exception otherwise! raise WrongDtypeException # Swap the byteorder if necessary. # Write the file.
raise NotImplementedError
""" Packs 4 byte IEEE floating points. """ # Check the dtype and raise exception otherwise! raise WrongDtypeException # Swap the byteorder if necessary. # Write the file.
raise NotImplementedError |