Esempio n. 1
0
def ascii_specfem2d(**kwargs):
    """ Reads seismic traces from text files
    """
    files = glob(solver='specfem2d', **kwargs)
    t = _np.loadtxt(files[0])[:,0]
    h = Struct()
    h['t0'] = t[0]
    h['nr'] = len(files)
    h['ns'] = 1
    h['dt'] = _np.mean(_np.diff(t))
    h['nt'] = len(t)

    # read data
    s = _np.zeros((h['nt'], h['nr']))
    i = 0
    for file in files:
        s[:, i] = _np.loadtxt(file)[:, 1]
        i += 1

    # keep track of file names
    h.files = []
    for file in files:
        file = basename(file)
        h.files.append(file)

    return s, h
Esempio n. 2
0
    def apply(self, func, arrays, input, inplace=True):
        """ Applies function to multi-component data
        """
        if inplace:
            output = Struct(arrays[0])
        else:
            output = Struct()

        for channel in self.channels:
            args = [array[channel] for array in arrays] + input
            output[channel] = func(*args)

        return output
Esempio n. 3
0
    def load(self, prefix=''):
        """ Reads seismic data from disk
        """
        h = Struct()
        f = Struct()

        for channel in self.channels:
            f[channel], h[channel] = self.reader(prefix=prefix,
                                                 channel=channel)

        # check headers
        h = self.check_headers(h)

        return f, h
Esempio n. 4
0
def _vars(obj):
    """Returns an object's __dict__ with private variables removed"""
    mydict = {}
    for key, val in vars(obj).items():
        if key[0] != '_':
            mydict[key] = val
    return Struct(mydict)
Esempio n. 5
0
File: io.py Progetto: mpbl/seisflows
    def scan(self, fmtlist, origin=0, contiguous=1):
        """
        Take a list of formats:
            [[fmt, origin, offset, description], [...], ...]
        and returns a dictionary:
            {description: value, ...}
        """
        # reads binary file
        self.file.seek(origin)

        position = 0
        h = Struct()

        for item in fmtlist:
            fmt = item[0]
            length = item[1]
            offset = item[2]
            name = item[3]

            if not contiguous:
                self.file.seek(offset - position, 1)
                position = offset + mysize(fmt)

            # if length is 1:
            #   h[name] = self.read(fmt,length)[0]
            # else:
            #   h[name] = self.read(fmt,length)
            h[name] = self.read(fmt, length)[0]

        return h
Esempio n. 6
0
    def load(self, prefix=None, suffix=None):
        """ Reads seismic data from disk
        """
        kwargs = dict()
        if prefix != None:
            kwargs['prefix'] = prefix
        if suffix != None:
            kwargs['suffix'] = suffix

        f = Struct()
        h = Struct()
        for channel in self.channels:
            f[channel], h[channel] = self.reader(channel=channel, **kwargs)

        # check headers
        h = self.check_headers(h)

        return f, h
Esempio n. 7
0
    def check_mesh_properties(self, path=None, parameters=None):
        if not hasattr(self, '_mesh_properties'):
            if not path:
                path = PATH.MODEL_INIT

            if not parameters:
                parameters = self.parameters

            nproc = 0
            ngll = []
            while True:
                dummy = loadbin(path, nproc, parameters[0])
                ngll += [len(dummy)]
                nproc += 1
                if not exists('%s/proc%06d_%s.bin' %
                              (path, nproc, parameters[0])):
                    break

            self._mesh_properties = Struct([['nproc', nproc], ['ngll', ngll]])

        return self._mesh_properties
Esempio n. 8
0
from seisflows.tools.code import Struct
globals()['PBS'] = Struct()
globals()['SLURM'] = Struct()
globals()['SPECFEM'] = Struct()

###

WarningOverwrite = """
WARNING: Data from previous workflow found in working directory.

To delete data and start a new workflow type:
  sfclean; sfrun

To resume existing workflow type:
  sfresume
"""

ReceiverError_SPECFEM = """
ERROR READING RECEIVERS

    Error reading receivers.

"""

SourceError_SPECFEM = """
ERROR READING SOURCES

    In DIRECTORY, there must be one or more files matching WILDCARD.

    DIRECTORY:  "%s"
    WILDCARD:  "%s"