seisflows.tools.specfem
Utilities to interact with, manipulate or call on the external solver, i.e., SPECFEM2D/3D/3D_GLOBE
Module Contents
Functions
|
Determines names of sources by applying wildcard rule to user-supplied |
|
Reads and returns parameters from a SPECFEM or SeisFlows parameter file |
|
Overwrites parameter value to a SPECFEM Par_file. |
|
SPECFEM2D doesn't follow standard formatting when defining its internal |
|
Set velocity model values in a SPECFEM2D Par_file, see getpar_vel_model |
|
Reads Fortran-style unformatted binary data into numpy array. |
|
Writes Fortran style binary files. Data are written as single precision |
- seisflows.tools.specfem.check_source_names(path_specfem_data, source_prefix, ntask=None)
Determines names of sources by applying wildcard rule to user-supplied input files. Source names are only provided up to PAR.NTASK and are returned in alphabetical order.
Note
SeisFlows expects sources to be stored in the DATA/ directory with a prefix and a source name, e.g., {source_prefix}_{source_name} which would evaluate to something like CMTSOLUTION_001
- Parameters
path_specfem_data (str) – path to a
source_prefix (str) – type of SPECFEM input source, e.g., CMTSOLUTION
- Parma ntask
if provided, curtails the list of sources up to ntask. If None, returns all files found matching the wildcard
- Return type
list
- Returns
alphabetically ordered list of source names up to PAR.NTASK
- seisflows.tools.specfem.getpar(key, file, delim='=', match_partial=False)
Reads and returns parameters from a SPECFEM or SeisFlows parameter file Assumes the parameter file is formatted in the following way:
# comment comment comment {key} {delim} VAL
- Parameters
key (str) – case-insensitive key to match in par_file. must be EXACT match
file (str) – The SPECFEM Par_file to match against
delim (str) – delimiter between parameters and values within the file. default is ‘=’, which matches for SPECFEM2D and SPECFEM3D_Cartesian
match_partial (bool) – allow partial key matches, e.g., allow key=’tit’ to return value for ‘title’. Defaults to False as this can have unintended consequences
- Return type
tuple (str, str, int)
- Returns
a tuple of the key, value and line number (indexed from 0). The key will match exactly how it looks in the Par_file The value will be returned as a string, regardless of its expected type IF no matches found, returns (None, None, None)
- seisflows.tools.specfem.setpar(key, val, file, delim='=', match_partial=False)
Overwrites parameter value to a SPECFEM Par_file.
- Parameters
key (str) – case-insensitive key to match in par_file. must be EXACT match
val (str) – value to OVERWRITE to the given key
file (str) – The SPECFEM Par_file to match against
delim (str) – delimiter between parameters and values within the file. default is ‘=’, which matches for SPECFEM2D and SPECFEM3D_Cartesian
match_partial (bool) – allow partial key matches, e.g., allow key=’tit’ to return value for ‘title’. Defaults to False as this can have unintended consequences
- seisflows.tools.specfem.getpar_vel_model(file)
SPECFEM2D doesn’t follow standard formatting when defining its internal velocity models so we need a special function to address this specifically. Velocity models are ASSUMED to be formatted in the following way in the SPECFEM2D Par_file (with any number of comment lines in between)
nbmodels = 4 1 1 2700.d0 3000.d0 1732.051d0 0 0 9999 9999 0 0 0 0 0 0 2 1 2500.d0 2700.d0 0 0 0 9999 9999 0 0 0 0 0 0 3 1 2200.d0 2500.d0 1443.375d0 0 0 9999 9999 0 0 0 0 0 0 4 1 2200.d0 2200.d0 1343.375d0 0 0 9999 9999 0 0 0 0 0 0 TOMOGRAPHY_FILE = ./DATA/tomo_file.xyz
- Parameters
file (str) – The SPECFEM Par_file to match against
- Return type
list of str
- Returns
list of all the layers of the velocity model as strings
- seisflows.tools.specfem.setpar_vel_model(file, model)
Set velocity model values in a SPECFEM2D Par_file, see getpar_vel_model for more information.
Deletes the old model from the Par_file, writes the new model in the same place, and then changes the value of ‘nbmodels’
- Parameters
file (str) – The SPECFEM Par_file to match against
model (list of str) – input model
- Return type
list of str
- Returns
list of all the layers of the velocity model as strings, e.g.: model = [“1 1 2700.d0 3000.d0 1732.051d0 0 0 9999 9999 0 0 0 0 0 0”,
”2 1 2500.d0 2700.d0 0 0 0 9999 9999 0 0 0 0 0 0”]
- seisflows.tools.specfem.read_fortran_binary(filename)
Reads Fortran-style unformatted binary data into numpy array.
Note
The FORTRAN runtime system embeds the record boundaries in the data by inserting an INTEGER*4 byte count at the beginning and end of each unformatted sequential record during an unformatted sequential WRITE. see: https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnc4/index.html
- Parameters
filename (str) – full path to the Fortran unformatted binary file to read
- Return type
np.array
- Returns
numpy array with data with data read in as type Float32
- seisflows.tools.specfem.write_fortran_binary(arr, filename)
Writes Fortran style binary files. Data are written as single precision floating point numbers.
Note
FORTRAN unformatted binaries are bounded by an INT*4 byte count. This function mimics that behavior by tacking on the boundary data. https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnc4/index.html
- Parameters
arr (np.array) – data array to write as Fortran binary
filename (str) – full path to file that should be written in format unformatted Fortran binary