seismic.traveltime package

Submodules

seismic.traveltime.cluster_grid module

Description:

Define a 3D grid discretization of the Earth

CreationDate:

2/09/2018

Developer:
class seismic.traveltime.cluster_grid.Grid2(ndis=2, param_file=None)[source]

Bases: object

A non-uniform Grid Model of Earth for eventsource–>station rays clustering and sorting.

Reference to the inversion Fortran code model parameter file param1x1 in this directory:
  • Global: 5x5 degree and a list of 1+16 depths

  • Region: 1x1 degree and a list of 1+29 depths

constructor for a non-uniform Grid. Please modify the parameters in this method according to your desired Grid attributes. :param ndis: 2, 4 (define the ref discretization by 2 or 4)

find_block_number(lat, lon, z)[source]

find the index-number of an events/station in a non-uniform grid each spatial point (lat, lon, z) is mapped to a uniq block_number.

Parameters
  • lat – latitude (-90,90)

  • lon – longitude (0,360)

  • z – depth meter

Returns

a tuple of 4 block number AND and the block’s centre coordinate(int_block_n, xc,yc, zcm)

generate_grid3D()[source]

Loop over all the reference depths, both regional and global depth list.

Returns

pandas dataframe

generate_latlong_grid(depthmeters=0.0)[source]

create a csv file containing: (block_number, lat,long, depthm=0, xc,yc,zc)

Returns

Pandas data frame

get_depth_index(z, dep_meters)[source]

given a point with depth z meters, and a np-array of refined depth in meters, find the index which z fall into.

Parameters
  • z – an event depth in meters

  • dep_meters – an array of numbers corresponding to a refined depth discretization.

Returns

depth index and the cell block centre depth in metres.

is_point_in_region(lat, lon)[source]

test if the event or station point is in the region box?

Parameters
  • lat – latitude

  • lon – longitude

Returns

boolean T or F

show_properties()[source]

print the properties of the grid definition

class seismic.traveltime.cluster_grid.UniformGrid(nx=360, ny=180, dz=10000)[source]

Bases: object

This is the original (simple) uniform grid model for Earth.

It is replaced by the more generic non-uniform model defined above as class Grid2

constructor for Grid. Define 3D cell properties :param nx: integer number of cells in longitude (360) :param ny: lattitude cells (180) :param dz: depth in meteres (default=10KM)

find_block_number(lat, lon, z)[source]

find the 3D-block number in this grid

Parameters
  • lat – lattitude

  • lon – longitude

  • z – elevation

Returns

int block number

seismic.traveltime.events_stations_rays_visualization2 module

seismic.traveltime.events_stations_rays_visualization2.plot1(mypdf)[source]
Parameters

mypdf – which dataframe to view in the following??

Returns

seismic.traveltime.events_stations_rays_visualization2.plot_geopandas(mypdf)[source]

Geopandas and Maps :param mypdf: :return:

seismic.traveltime.events_stations_rays_visualization2.plot_gmt(mypdf)[source]

GMT-python plotting map figure saved into PNG file. But not displaying on screen

Require to conda install gmt-python module in anaconda python gmt version-6 will be installed. :param mypdf: :return:

seismic.traveltime.events_stations_rays_visualization2.plot_rays(mypdf)[source]
Parameters

mypdf

Returns

seismic.traveltime.events_stations_rays_visualization2.read_csv2pdf(csvfile)[source]

Read in a csv file into a pandas dataframe. Make sure the column names match the csv files. delimiter/separator is whitespace or comma

seismic.traveltime.events_stations_rays_visualization2.sort_plus(inputcsv=None)[source]

seismic.traveltime.gather_events module

Parse multiple events xml files to gather all seismic events-arrivals (Refactored From the original seismic.cluster.cluster.py)

output CSV files containing the following columns:

['source_block', 'station_block', 'residual', 'event_number',
 SOURCE_LONGITUDE, SOURCE_LATITUDE, 'source_depth', STATION_LONGITUDE, STATION_LATITUDE,
 'observed_tt', 'calculated_locations2degrees', xml_distance, STATION_CODE, 'SNR', 'P_or_S']

How to Run:

export ELLIPCORR=/g/data1a/ha3/fxz547/Githubz/passive-seismic/ellip-corr/
cd  passive-seismic/tempworks
# python ../seismic/traveltime/gather_events.py  -v DEBUG gather /g/data/ha3/fxz547/Githubz/passive-seismic/testdata/
# python ../seismic/traveltime/gather_events.py  -v DEBUG gather /g/data/ha3/fxz547/Githubz/passive-seismic/some_events_xml/
#  OR
#<fzhang@ubuntu16qos>/Softlab/Githubz/passive-seismic/tempworks (master)
# $ python2 ../seismic/traveltime/gather_events.py  -v DEBUG gather ./events_xmls_test
class seismic.traveltime.gather_events.ArrivalWriter(rank, wave_type, output_file)[source]

Bases: object

Convenience class for writing arrival data

close()[source]
write(cluster_info)[source]
seismic.traveltime.gather_events.getSNR(arrival)[source]

From the arrival get the SNR value. This algorithm depend on how the snr value is coded in the xml file :param arrival: :return: a float SNR value

seismic.traveltime.gather_events.get_paths_from_csv(csvfile)[source]

Parse a text/csv file to extract a list of paths, where events xml files are stored, to be gathered.

Parameters

csvfile – csv file

Returns

list_of_paths

seismic.traveltime.gather_events.process_event(event, stations, grid, wave_type, counter)[source]
Parameters
  • event – obspy.core.event.Event class instance

  • stations – dict stations dict

  • grid – can be None; Grid class instance

  • wave_type – str Wave type to generate inversion inputs. See gather function.

  • counter – int event counter in this process

seismic.traveltime.gather_events.process_many_events(event_xmls, grid, stations, wave_type, output_file, seed=1)[source]
seismic.traveltime.gather_events.recursive_glob(dirname, ext='*.xml')[source]

Under the dirname recursively find all files with extension ext. Return a list of the full-path to the files of interest.

See: https://stackoverflow.com/a/2186565/3321542

Parameters
  • dirname – a single dir OR a list of dirs.

  • ext – eg, “.xml”

Returns

a list of path2files

seismic.traveltime.mpiops module

seismic.traveltime.mpiops.array_split(arr, process=None)[source]

Convenience function for splitting array elements across MPI processes

Parameters
  • arr (ndarray) – Numpy array

  • process (int) – Process for which array members are required. If None, MPI.comm.rank is used instead. (optional)

:return List corresponding to array members in a process. :rtype: list

seismic.traveltime.mpiops.run_once(f, *args, **kwargs)[source]

Run a function on one node and then broadcast result to all.

Parameters
  • f (str) – The function to be evaluated. Can take arbitrary arguments and return anything or nothing

  • args (str) – Other positional arguments to pass on to f (optional)

  • kwargs (str) – Other named arguments to pass on to f (optional)

Returns

The value returned by f.

Return type

unknown

seismic.traveltime.parametrisation module

Class for parsing Alexei’s tomographic parametrisation file as an object.

Created on Wed Apr 03 13:52:28 2019

@author: Marcus W. Haynes

class seismic.traveltime.parametrisation.grid(in_file='param')[source]

Bases: object

extract_1D(lon, lat, values, ref=None, method='linear')[source]

Extracts arbitrary 1D vertical seismic velocity profiles from an inversion model.

Input::
  • lon - float or list of desired longitude locations.

  • lat - float or list of desired latitude locations.

  • values - array of inversion values corresponding to the grid class.

  • ref [optional] - the reference model to convert velocity perturbations to absolute values, if desired. Needs to be a 2D array with depth in first column and velocity in second column.

  • method [optional] - method used to interpolate values to location

save()[source]

Write the parametrisation file to disk

seismic.traveltime.parse_param module

Created on Wed Oct 31 14:15:44 2018

@author: u81234

class seismic.traveltime.parse_param.grid3[source]

Bases: object

parse_parametrisation(param_file='./example_param.txt')[source]

Reads in the local and global grid parameters from an external parametrisation file (by default we load ‘./param’)

seismic.traveltime.plotviews module

class seismic.traveltime.plotviews.Region(upperlat, bottomlat, leftlon, rightlon)

Bases: tuple

Create new instance of Region(upperlat, bottomlat, leftlon, rightlon)

property bottomlat

Alias for field number 1

property leftlon

Alias for field number 2

property rightlon

Alias for field number 3

property upperlat

Alias for field number 0

seismic.traveltime.pslog module

class seismic.traveltime.pslog.ElapsedFormatter[source]

Bases: object

format(record)[source]
seismic.traveltime.pslog.configure(verbosity)[source]
seismic.traveltime.pslog.warn_with_traceback(message, category, filename, lineno, line=None)[source]

copied from: http://stackoverflow.com/questions/22373927/get-traceback-of-warnings

seismic.traveltime.sort_rays module

Description:

Read in event-arrival seismic rays and sort them according to a discretization model of Earth.

The input file header assumed to be:

col_names=[‘source_block’, ‘station_block’, ‘residual’, ‘event_number’,’source_longitude’,’source_latitude’,’source_depth’, ‘station_longitude’,’station_latitude’, ‘observed_tt’, ‘locations2degrees’, ‘station_code’,’SNR’, ‘P_or_S’]

The output CSV file will be feed into an inversion program which will derive travel-time tomography images.

Developer:

fei.zhang@ga.gov.au

seismic.traveltime.sort_rays.apply_filters(csv_data, phase)[source]

Apply filters to the rows (rays) according to phase P or S. Remove un-reliable data. :param csv_data: input pandas dataframe :param phase: P or S :return: pandas dataframe

seismic.traveltime.sort_rays.compute_ellipticity_corr(arrival_phase, ev_latitude, ev_longitude, ev_depth_km, sta_latitude, sta_longitude, degrees_to_source)[source]

Utility function to compute ellipticity correction.

Parameters
  • arrival_phase – P or S

  • ev_latitude – event lat

  • ev_longitude – event long

  • ev_depth_km – event depth in km

  • sta_latitude – station lat

  • sta_longitude – station long

  • degrees_to_source – degree to source

Returns

ellipticity correction float value

seismic.traveltime.sort_rays.filter_S_by_P(inpdf, pevents_csv)[source]

Filter the S picks by P events :param inpdf: input pdf :param pevents_csv: Pevents csv file with 3 columns: [‘#eventID’, ‘net’,’sta’] :return: a new csv pdf after the filtering

seismic.traveltime.sort_rays.get_columns_dict(jsonfile)[source]
seismic.traveltime.sort_rays.is_manual_pick(x)[source]
seismic.traveltime.sort_rays.is_ray_in(ray_id, P_RAYS_ID_LIST)[source]

check if an ray_id is in the P_RAYS_ID_LIST :param ray_id: “net_sta_evtid” :param P_RAYS_ID_LIST: a sequence of Ray_id of P waves. :return: 1 if in; 0 if not in

seismic.traveltime.sort_rays.sort(input_file, sorted_file, residual_cutoff)[source]

Sort and filter the arrivals based on the source and station block number. There are two stages of filtering:

  • Filter based on the arrival time residual value: defult value for the cutoff is 5 for P-Wave, 10 for S-Wave

  • Filter based on median of observed travel time.

If there are multiple source and station block combinations, we keep the row corresponding to the median observed travel time (observed_tt).

Parameters
  • input_file – output file from the gather stage (eg, outfile_P.csv)

  • sorted_file – str, optional optional sorted output file path. Default: sorted.csv.

  • residual_cutoff – float residual seconds, arrivals are rejected if the residual is larger than the cutoff

Returns

A pandas df

seismic.traveltime.sort_rays.sort2(input_file, sorted_file, residual_cutoff)[source]

Sort and filter the arrivals based on the source and station block number. If there are multiple source and station block combinations, the row corresponding to the highest SNR value is kept. (This function is for experiment only, not used.)

Parameters
  • input_file – output file from the gather stage (eg, outfile_P.csv)

  • sorted_file – str, optionaloptional sorted output file path. Default: sorted.csv.

  • residual_cutoff – float arrivals are rejected if the residual is larger than the cutoff.

Returns

pandas_df

seismic.traveltime.sort_rays.sort_csv_in_grid(inputcsv, outputcsv, phase, mygrid, column_name_map)[source]

Read in a csv file, re-grid each row according to a given Grid model. Write into output csv file with re-calculated block_numbers re-named columns

Parameters
  • inputcsv – path to an input csv file

  • outputcsv – path to output file

  • phase – P or S

  • mygrid – instance of Earth Grid model

  • column_name_map – column map dictionary as in csv_columns.json file

Returns

outfile

seismic.traveltime.sort_rays.translate_csv(in_csvfile, out_csvfile)[source]

Read in a csv file, re-grid each row according to a new Grid model. Write into another csv file with re-calculated block_numbers and six new columns of Grid cell centers.

Parameters
  • in_csvfile – path to an input csv file

  • out_csvfile – path to an output csv file

Returns

out_csvfile

seismic.traveltime.zone_rays module

class seismic.traveltime.zone_rays.Region(upperlat, bottomlat, leftlon, rightlon)

Bases: tuple

Create new instance of Region(upperlat, bottomlat, leftlon, rightlon)

property bottomlat

Alias for field number 1

property leftlon

Alias for field number 2

property rightlon

Alias for field number 3

property upperlat

Alias for field number 0

Module contents