### Execute Main VELEST Inversion Workflow Source: https://context7.com/saeedsltm/pyvelest/llms.txt Orchestrates the full inversion process, including parameter configuration, synthetic model generation, VELEST execution, and result visualization. ```python from PyVelest import main start = main() start.extract_topo() start.clean() start.write_par() start.plot_data() start.plot_path() start.mk_syn_model() start.run_velest() start.analyse_velest_res() start.mk_report() start.plot_final() ``` -------------------------------- ### Generate VELEST Input Files Source: https://context7.com/saeedsltm/pyvelest/llms.txt Converts NORDIC phase data into VELEST-compatible CNV format and generates station and initial model files. It automatically determines the reference station based on data quality metrics. ```python from PyNordicRW import Read_Nordic from PyNordic2CNV import Nordic2CNV from PyGetRefSta import PRD d = Read_Nordic(nordic_inp) ce = Nordic2CNV(d) PRD(inp_file=nordic_inp, sta_inp='station.sta', falg_plot=False) ``` -------------------------------- ### Execute VELEST Inversions Source: https://context7.com/saeedsltm/pyvelest/llms.txt Automates the execution of VELEST inversions for multiple synthetic models. It iterates through generated model files, updates control parameters, and manages output files. ```python def run_velest(self): print "+++ Run VELEST ..." self.synthvel_files = glob.glob(path.join('tmp', self.project_nm, 'synthvel', '*.mod')) for m, c in zip(self.synthvel_files, range(len(self.synthvel_files))): system('velest > /dev/null') ``` -------------------------------- ### Running VELEST Inversions Source: https://context7.com/saeedsltm/pyvelest/llms.txt Executes VELEST for each synthetic model and collects results. Runs inversions in batch mode with automatic file management. ```APIDOC ## Running VELEST Inversions ### Description Executes VELEST for each synthetic model and collects results. Runs inversions in batch mode with automatic file management. ### Method N/A (Internal function called via start.run_velest()) ### Endpoint N/A ### Parameters - **self.project_nm** (string) - The name of the project. - **self.synthvel_files** (list) - List of paths to synthetic velocity model files. ### Request Example ```python # Called via start.run_velest() # Models are saved to velout/{project_name}/ import glob from os import path def run_velest(self): print "+++ Run VELEST ..." # Find all synthetic models self.synthvel_files = glob.glob(path.join('tmp', self.project_nm, 'synthvel', '*.mod')) for m, c in zip(self.synthvel_files, range(len(self.synthvel_files))): # Modify control file for each model # Run VELEST system('velest > /dev/null') ``` ### Response Outputs are saved to `velout/{project_name}/`. #### Success Response (200) - **velest{n}.out** (file) - Main VELEST output file for the n-th model. - **final_loc{n}.cnv** (file) - Final hypocenter locations for the n-th model. - **stations_corr{n}.sta** (file) - Station corrections for the n-th model. #### Response Example N/A (File outputs) ``` -------------------------------- ### Generate Synthetic Velocity Models Source: https://context7.com/saeedsltm/pyvelest/llms.txt Generates random velocity models for inversion testing by perturbing an initial model. It supports normal and uniform distributions using NumPy and saves outputs in the VELEST format. ```python from numpy import random, array # For normal distribution velocity perturbation: vel = array([random.normal(i, vel_dev * (1.0 / j), nmod) for i, j in zip(pvel, pdmp)]).T # For uniform distribution: vel = array([random.uniform(i - vel_dev * (1.0 / j), i + vel_dev * (1.0 / j), nmod) for i, j in zip(pvel, pdmp)]).T ``` -------------------------------- ### Calculate Vp/Vs Ratio with PyVpVs Source: https://context7.com/saeedsltm/pyvelest/llms.txt Computes the Vp/Vs ratio using the Wadati diagram method. It includes an outlier detection function using statsmodels to improve regression accuracy. ```python from statsmodels.formula.api import ols def outlier(x, y, r=0.5): regression = ols("data ~ x", data=dict(data=y, x=x)).fit() test = regression.outlier_test() outliers_ind = list((i for i, t in enumerate(test.iloc[:, 2]) if t < r)) good_id = list(set(range(len(x))) - set(outliers_ind)) return good_id, outliers_ind ``` -------------------------------- ### Damping Parameter Test - PyCheck Source: https://context7.com/saeedsltm/pyvelest/llms.txt Tests various damping parameters (origin time, epicenter, depth, velocity, station correction) to find optimal values using trade-off curves. ```APIDOC ## Damping Parameter Test - PyCheck ### Description Tests various damping parameters (origin time, epicenter, depth, velocity, station correction) to find optimal values using trade-off curves. ### Method N/A (Command-line execution) ### Endpoint N/A ### Parameters Interactive prompts guide the user: - **Project name**: Name of the inversion project. - **Best inversion id number**: The ID of the best inversion to analyze. - **Which damping parameter**: Selection for the parameter to test (e.g., 1 for Origin Time, 4 for Velocity Damping). - **Damping range**: Specifies the start, end, and step for the damping parameter sweep (e.g., `1, 100, 10`). ### Request Example ```bash # Run from root directory python PyCheck.py # Select option: 2 (Perform damping test) # Interactive prompts: Enter project name: my_inversion Enter best inversion id number: 15 Which damping parameter: 4 (Velocity Damping) Damping range: (1, 100, 10) ``` ### Response Generates a trade-off curve plot (e.g., TIFF) showing model variance vs. data variance for the tested damping parameter. #### Success Response (200) - **Check-Test/{project}/[Parameter]_Damping_Test.tiff**: Image file containing the trade-off curve. #### Response Example N/A (Image file output) ``` -------------------------------- ### Read and Write NORDIC Seismic Files Source: https://context7.com/saeedsltm/pyvelest/llms.txt Utilizes PyNordicRW to read seismic phase data from NORDIC files into Python dictionaries for processing and write them back to the original format. ```python from PyNordicRW import Read_Nordic, Write_Nordic nordic_data = Read_Nordic('select.out') for event_id in nordic_data: header = nordic_data[event_id]['HEADER'] phases = nordic_data[event_id]['PHASE'] Write_Nordic(inp=nordic_data, output='output.out') ``` -------------------------------- ### Parse VELEST Output File Source: https://context7.com/saeedsltm/pyvelest/llms.txt Reads a VELEST output file to extract velocity model adjustments and data variables. It parses the file line by line, identifying specific markers for velocity models and data variables. ```python def read_velestout(inp='velest.out'): model_var = [] data_var = [] with open(inp) as f: for l in f: if 'Velocity model 1' in l: pass if 'DATVAR=' in l: data_var.append(float(l.split()[1])) return data_var, model_var ``` -------------------------------- ### Perform Seismic Coordinate Conversions Source: https://context7.com/saeedsltm/pyvelest/llms.txt Utility functions to convert distances between kilometers and degrees based on a spherical Earth model. These are essential for mapping seismic station coordinates. ```python from numpy import pi def k2d(kilometer, radius=6371): return kilometer / (2.0 * radius * pi / 360.0) def d2k(degrees, radius=6371): return degrees * (2.0 * radius * pi / 360.0) ``` -------------------------------- ### Analyzing VELEST Results Source: https://context7.com/saeedsltm/pyvelest/llms.txt Parses VELEST output files to extract RMS residuals, velocity adjustments, and identifies the minimum (best) model based on convergence criteria. ```APIDOC ## Analyzing VELEST Results ### Description Parses VELEST output files to extract RMS residuals, velocity adjustments, and identifies the minimum (best) model based on convergence criteria. ### Method N/A (Internal function called via start.analyse_velest_res()) ### Endpoint N/A ### Parameters - **self.rms_res** (list) - Stores RMS residuals per iteration. - **self.avg_abs_adj** (list) - Stores average absolute adjustments for origin time, location. - **self.vel_adj** (list) - Stores velocity adjustments per layer. - **self.minmod** (dict) - Dictionary mapping model index to a metric for minimum model selection. ### Request Example ```python # Called via start.analyse_velest_res() # Extracts data from velout/{project_name}/velest*.out from numpy import median, where import operator # Key metrics extracted: self.rms_res = [] # RMS residuals per iteration self.avg_abs_adj = [] # Origin time, location adjustments self.vel_adj = [] # Velocity adjustments per layer # Outlier removal function: def reject_outliers(data, m=2.): d = abs(data - median(data)) mdev = median(d) s = d / mdev if mdev else 0. inx = where(s < m) good_data = data[inx] return good_data # Minimum model identified by lowest mean RMS: self.ind = sorted(self.minmod.items(), key=operator.itemgetter(1))[0][0] print '+++ Minimum model id:', self.ind + 1 ``` ### Response Extracted metrics and the index of the minimum model. #### Success Response (200) - **self.ind** (integer) - Index of the identified minimum model. #### Response Example ``` +++ Minimum model id: 15 ``` ``` -------------------------------- ### NORDIC Format Reader - PyNordicRW Source: https://context7.com/saeedsltm/pyvelest/llms.txt Reads SEISAN NORDIC format seismic phase files into structured Python dictionaries for processing. ```APIDOC ## NORDIC Format Reader - PyNordicRW ### Description Reads SEISAN NORDIC format seismic phase files into structured Python dictionaries for processing. ### Method - **Read_Nordic(filepath)**: Reads a NORDIC file. - **Write_Nordic(inp, output)**: Writes data to a NORDIC file. ### Endpoint N/A (Python library functions) ### Parameters #### Read_Nordic - **filepath** (string) - Path to the NORDIC file to read. #### Write_Nordic - **inp** (dict) - The input data dictionary to write. - **output** (string) - Path for the output NORDIC file. ### Request Example ```python from PyNordicRW import Read_Nordic, Write_Nordic # Read NORDIC file nordic_data = Read_Nordic('select.out') # Access event data: for event_id in nordic_data: header = nordic_data[event_id]['HEADER'] phases = nordic_data[event_id]['PHASE'] # Header information lat = header['L1']['Lat'] lon = header['L1']['Lon'] depth = header['L1']['Dep'] rms = header['L1']['RMS'] # Phase data for station in phases: p_arrivals = phases[station]['P'] s_arrivals = phases[station]['S'] for phase_type in p_arrivals: arrival_time = p_arrivals[phase_type]['Sec'] weight = p_arrivals[phase_type]['WI'] distance = p_arrivals[phase_type]['DIS'] # Write back to NORDIC format Write_Nordic(inp=nordic_data, output='output.out') ``` ### Response - **Read_Nordic**: Returns a dictionary containing parsed NORDIC file data. - **Write_Nordic**: Creates a NORDIC format file. #### Success Response (200) N/A (Function execution) #### Response Example ```json { "event_id_1": { "HEADER": { "L1": { "Lat": 34.5, "Lon": -118.0, "Dep": 10.5, "RMS": 0.5 } }, "PHASE": { "STA1": { "P": { "P": { "Sec": 10.2, "WI": 1.0, "DIS": 100.5 } } } } } } ``` ``` -------------------------------- ### Synthetic Velocity Model Generation Source: https://context7.com/saeedsltm/pyvelest/llms.txt Generates random synthetic velocity models for inversion testing by perturbing the initial model within specified bounds. Supports both uniform and normal distributions. ```APIDOC ## Synthetic Velocity Model Generation ### Description Generates random synthetic velocity models for inversion testing by perturbing the initial model within specified bounds. Supports both uniform and normal distributions. ### Method N/A (Internal function called via start.mk_syn_model()) ### Endpoint N/A ### Parameters #### Configuration (from par/syntvel.dat) - **vel_mode** (string) - Distribution type (n=normal, u=uniform) - **dep_mode** (string) - Distribution type for depth - **vel_min** (float) - Minimum velocity value - **vel_max** (float) - Maximum velocity value - **vel_dev** (float) - Velocity deviation for distribution - **dep_dev** (float) - Depth deviation for distribution - **nmod** (integer) - Number of synthetic models to generate - **vpvs** (float) - Vp/Vs ratio - **velmod_name** (string) - Base name for velocity model files ### Request Example ```python # Example of model generation logic: from numpy import random, array # For normal distribution velocity perturbation: vel = array([random.normal(i, vel_dev * (1.0 / j), nmod) for i, j in zip(pvel, pdmp)]).T # For uniform distribution: vel = array([random.uniform(i - vel_dev * (1.0 / j), i + vel_dev * (1.0 / j), nmod) for i, j in zip(pvel, pdmp)]).T ``` ### Response Models are saved to `tmp/{project_name}/synthvel/` in VELEST format. #### Success Response (200) N/A (File generation) #### Response Example ``` Model: model_1.mod 8 vel,depth,vdamp,phase(f5.2,5x,f7.2,2x,f7.3,3x,a1) 5.20 0.00 1.000 P-VELOCITY MODEL 5.50 5.00 1.000 6.10 15.00 1.000 ... ``` ``` -------------------------------- ### Analyze VELEST Results Source: https://context7.com/saeedsltm/pyvelest/llms.txt Parses VELEST output files to extract RMS residuals and adjustments. Includes utility functions for outlier rejection to identify the most stable model. ```python def reject_outliers(data, m=2.): d = abs(data - median(data)) mdev = median(d) s = d / mdev if mdev else 0. inx = where(s < m) good_data = data[inx] return good_data, good_data_ind, bad_data, bad_data_ind ``` -------------------------------- ### Filter Seismic Events with PySelect2D Source: https://context7.com/saeedsltm/pyvelest/llms.txt Filters NORDIC format seismic data based on spatial, temporal, and quality criteria. It requires a configuration file (select2D.par) to define limits for magnitude, depth, RMS, and gap. ```python # Run from the tools/ directory # python PySelect2D.py # Input NORDIC file name: collect.out # Output: select.out (filtered events in NORDIC format) ``` -------------------------------- ### Filter Data Outliers Source: https://context7.com/saeedsltm/pyvelest/llms.txt Removes outliers from a dataset using the Median Absolute Deviation (MAD) method. It returns both the filtered data and the indices of the good and bad data points. ```python from numpy import median, where, abs def reject_outliers(data, m=2.): d = abs(data - median(data)) mdev = median(d) s = d / mdev if mdev else 0. inx = where(s < m) good_data = data[inx] good_data_ind = where(s < m) inx = where(s > m) bad_data = data[inx] bad_data_ind = where(s > m) return good_data, good_data_ind[0], bad_data, bad_data_ind[0] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.