pypaw package

Submodules

pypaw.adjoint module

Class that calculate adjoint source using asdf

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.adjoint.AdjointASDF(path, param, verbose=False)[source]

Bases: pypaw.procbase.ProcASDFBase

Adjoint Source ASDF

static load_adjoint_config(config)[source]

Load config into pyadjoint.Config :param param: :return:

load_windows(winfile)[source]

load window json file

Parameters:winfile
Returns:
pypaw.adjoint.adjoint_wrapper(obsd_station_group, synt_station_group, config=None, obsd_tag=None, synt_tag=None, windows=None, event=None, adj_src_type='multitaper_misfit', interp_delta=None, interp_npts=None, figure_mode=False, figure_dir=False, adjoint_src_flag=True)[source]

Function wrapper for pyasdf.

Parameters:
  • obsd_station_group – observed station group, which contains seismogram(stream) and station information(inventory)
  • synt_station_group – synthetic station group. Same as obsd_station_group
  • config (pyadjoint.Config) – config object for adjoint source
  • obsd_tag (str) – observed seismogram tag, used for extracting the seismogram in observed asdf file
  • synt_tag (str) – synthetic seismogram tag, used for extracting the seismogram in synthetic asdf file
  • windows (list) – windows for this station group. Two dimension list. The first dimension is different channels, the second dimension is windows for this channel, like [[chan1_win1, chan1_win2], [chan2_win1,], ...]
  • event (obspy.Inventory) – event information
  • adj_src_type (st) – adjoint source type, currently support: 1) “cc_traveltime_misfit” 2) “multitaper_misfit” 3) “waveform_misfit”
  • adjoint_src_flag (bool) – calcualte adjoint source, put this to true. If false, only make measurements but no adjoint sources.
  • figure_mode (bool) – plot figures for adjoint source or not
  • figure_dir (str) – output figure directory
Returns:

adjoint sources for pyasdf write out(reshaped)

pypaw.adjoint_prepro module

Class that handles the whole preprocessing workflow, including:
  1. signal processing
  2. window selection
  3. adjoint sources
copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.adjoint_prepro.AdjPreASDF(path, param, components=['Z', 'R', 'T'], verbose=False)[source]

Bases: pypaw.procbase.ProcASDFBase

pypaw.adjoint_prepro.func_wrapper(obsd_station_group, synt_station_group, obsd_tag=None, synt_tag=None, event=None, param=None, _verbose=False, figure_mode=False, figure_dir=None)[source]

combo function, including: 1) observed data signal processing 2) synthetic data signal processing 3) window selection based on a pair of data 4) adjoint source constructor

pypaw.adjoint_prepro.load_adjoint_config(param)[source]
pypaw.adjoint_prepro.load_window_config(param)[source]

pypaw.adjoint_util module

Methods that contains utils for adjoint sources

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
pypaw.adjoint_util.calculate_chan_weight(adjsrcs, windows_sta)[source]

Calcualte window weights based on adjoint sources and windows

Parameters:
  • adjsrcs
  • windows_sta
Returns:

pypaw.adjoint_util.ensemble_fake_adj(stream, time_offset=0.0)[source]

Ensemble fake adjoint sources from stream, for test purpose

pypaw.adjoint_util.reshape_adj(adjsrcs, time_offset, staxml)[source]

Reshape adjsrcs to a certain structure required by pyasdf writer

pypaw.adjoint_util.smart_transform_window(windows)[source]

Smart tranfer window object to dict if it is type of pyflex.Window

Parameters:windows
Returns:

pypaw.convert module

Methods that contains utils for adjoint sources

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.convert.ConvertASDF(path, verbose=False, status_bar=False)[source]

Bases: object

static clean_output(output_fn)[source]
static print_info(waveform_files, tag, staxml_files, quakemlfile, output_fn, create_simple_inv)[source]
run()[source]
pypaw.convert.create_simple_inventory(network, station, latitude=None, longitude=None, elevation=None, depth=None, start_date=None, end_date=None, location_code='S3')[source]

Create simple inventory for synthetic data

pypaw.convert.write_stream_to_sac(stream, outputdir, tag='')[source]

pypaw.procbase module

Parent class for general asdf processing. Wraps things like MPI and parallel I/O so they are invisible to users.

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.procbase.ProcASDFBase(path, param, verbose=False)[source]

Bases: object

check_input_file(filename)[source]

Check existance of input file. If not, raise ValueError

check_output_file(filename, remove_flag=True)[source]

Check existance of output file. If directory of output file not exists, raise ValueError; If output file exists, remove it

static clean_memory(asdf_ds)[source]

Delete asdf dataset

detect_env()[source]

Detect environment, mpi or not

Returns:
load_asdf(filename, mode='a')[source]

Load asdf file

Parameters:
  • filename
  • mode
Returns:

print_info(dict_obj, extra_info='')[source]

Print dict. You can use it to print out information for path and param

Parameters:
  • dict_obj
  • extra_info
Returns:

smart_run()[source]

Job launch method

Returns:

pypaw.process module

Parent class for singal processing asdf file and handles parallel I/O so they are invisible to users.

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.process.ProcASDF(path, param, verbose=False)[source]

Bases: pypaw.procbase.ProcASDFBase

pypaw.process.process_wrapper(stream, inv, param=None)[source]

Process function wrapper for pyasdf

Parameters:
  • stream
  • inv
  • param
Returns:

pypaw.utils module

Parent class for singal processing asdf file and handles parallel I/O so they are invisible to users.

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.utils.JSONObject(d)[source]

Bases: object

pypaw.utils.drawProgressBar(percent, user_text='', barLen=20)[source]

Draw status progress bars in terminal. Not recommendded used for job scripts(will create thousands of lines of output)

pypaw.utils.is_mpi_env()[source]

Test if current environment is MPI or not

pypaw.utils.isclose(a, b, rel_tol=1e-09, abs_tol=0.0)[source]

Compare two numbers see if they are close to each other to a tolerance level

pypaw.utils.read_json_file(parfile, obj_hook=True)[source]

Hook json to an JSONObject instance

pypaw.utils.read_yaml_file(filename)[source]
pypaw.utils.smart_check_path(path, mpi_mode=True, comm=None)[source]
pypaw.utils.smart_mkdir(dirname, mpi_mode=True, comm=None)[source]
pypaw.utils.smart_read_json(json_file, mpi_mode=True, comm=None, object_hook=False)[source]

read json file under mpi and multi-processing environment. Hook it to an JSONObject(not the conventional way to read it as object)

pypaw.utils.smart_read_yaml(yaml_file, mpi_mode=True, comm=None)[source]

Read yaml file into python dict, in mpi_mode or not

pypaw.utils.smart_remove_file(filename, mpi_mode=True, comm=None)[source]
pypaw.utils.timing(f)[source]

pypaw.window module

Class for window selection on asdf file and handles parallel I/O so they are invisible to users.

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.window.WindowASDF(path, param, components=['Z', 'R', 'T'], verbose=False)[source]

Bases: pypaw.procbase.ProcASDFBase

static load_window_config(param)[source]
pypaw.window.window_wrapper(obsd_station_group, synt_station_group, config_dict=None, obsd_tag=None, synt_tag=None, event=None, figure_mode=False, figure_dir=None, _verbose=False)[source]

Wrapper for asdf I/O

pypaw.write_window module

Methods for write out windows

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)
class pypaw.write_window.WindowEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

Bases: json.encoder.JSONEncoder

default(obj)[source]
pypaw.write_window.get_json_content(window)[source]
pypaw.write_window.write_window_json(results, outputdir)[source]

Module contents

copyright:Wenjie Lei (lei@princeton.edu), 2016
license:GNU General Public License, Version 3 (http://www.gnu.org/copyleft/gpl.html)