aurora.sandbox package¶
Subpackages¶
- aurora.sandbox.io_helpers package
Submodules¶
aurora.sandbox.debug_mt_metadata_issue_85 module¶
This module contains a test that should be moved into mt_metadata TODO: Make this a test in mt_metadata
- aurora.sandbox.debug_mt_metadata_issue_85.test_can_add_location()[source]¶
20220624: This mini test is being factored out of the normal tests. Want to assign location. The location lands in the station_group but not in the run_group. Reported this conundrum https://github.com/kujaku11/mt_metadata/issues/85
When I close and reopen the file, I cannot find the latitude I set anywhere.
aurora.sandbox.mth5_channel_summary_helpers module¶
This module contains methods to help make mth5 files. TODO: Review and move to make_mth5 if relevant
- aurora.sandbox.mth5_channel_summary_helpers.channel_summary_to_make_mth5(df: DataFrame, network='', channel_nomenclature=None, verbose=False)[source]¶
Makes a dataframe that can be passed to make_mth5.
Context is say you have a station_xml that has come from somewhere and you want to make an mth5 from it, with all the relevant data. Then you should use make_mth5. But make_mth5 wants a df with a particular schema (which should be written down somewhere!) This method returns a dataframe with the schema that MakeMTH5() expects. Specifically, there is one row for each channel-run combination.
This method could be an option for output format of mth5.channel_summary()
TODO: Add support for channel_nomenclature
This method could be an option for output format of mth5.channel_summary()
- Parameters:
- Returns:
out_df – The make_mth5 formatted dataframe
- Return type:
pd.DataFrame
aurora.sandbox.mth5_helpers module¶
This module contains utility functions for working with MTH5 files. TODO: Review and move to mth5 if relevant
Background: This module was inside of mth5/clients/helper_functions.py on branch issue_76_make_mth5_factoring
Some of these functions are handy, and should eventually be merged into mth5. I would also like to use some of these functions from time-to-time, so I am putting them here for now, until we can decide what to move to mth5 and what to keep in aurora (and what to throw out).
- aurora.sandbox.mth5_helpers.augmented_channel_summary(mth5_object, df=None)[source]¶
Adds column “n_filters” to mth5 channel summary.
This function was used when debugging and wide scale testing at IRIS/Earthscope.
Development Notes: TODO: Consider supporting a list of keyeords that tell what columns to add
- Parameters:
df (channel summary dataframe) –
- Returns:
df – Same as input but with new column
- Return type:
pd.Dataframe
- aurora.sandbox.mth5_helpers.build_request_df(network_id, station_id, channels=None, start=None, end=None, time_period_dict={}, mth5_version='0.2.0') DataFrame [source]¶
- Given some information about an earthscope dataset, format the dataset description
into a request_df dataframe.
- Parameters:
network_id (string) – Two-character network identifier string fro FDSN.
station_id (string) – Short identifier code used by FDSN, e.g. CAS04, NVR11
channels (list or None) – 3-character channel identifiers, e.g. [“LQ2”, “MFZ”], support for wildcards of the form [”F”, “Q”,] is experimental Does not support wildcards of the form [“*”,]
start (string) – ISO-8601 representation of a timestamp
end (string) – ISO-8601 representation of a timestamp
time_period_dict (dict) – Keyed by same values as channels, this gives explicit start/end times for each of the channels
mth5_version (str) – From [“0.1.0”, “0.2.0”]
- Returns:
request_df – A formatted dataframe that can be passed to mth5.clients.FDSN to request metdata or data.
- Return type:
pd.DataFrame
- aurora.sandbox.mth5_helpers.enrich_channel_summary(mth5_object, df, keyword)[source]¶
Operates on a channel summary df and adds some information in a new column.
- Parameters:
mth5_object (mth5.mth5.MTH5) –
df (pd.DataFrame) – A channel summary dataframe
keyword (str) – supported keywords are [“num_filters”,] “num_filters” computes the number of filters associated with each row (channel-run) and adds that “num_filters” column of df
- Returns:
df – The channel summary df with the new column
- Return type:
pd.DataFrame
- aurora.sandbox.mth5_helpers.get_channel_summary(h5_path)[source]¶
Gets a channel summary from an mth5; TODO: This can be replaced by methods in mth5.
- Parameters:
h5_path (pathlib.Path) – Where is the h5
- Returns:
channel_summary_df – channel summary from mth5
- Return type:
pd.DataFrame
aurora.sandbox.obspy_helpers module¶
This module contains helper functions for working with obspy objects.
Development Notes - TODO: Most of this could likely be moved into MTH5
- aurora.sandbox.obspy_helpers.align_streams(streams, clock_start)[source]¶
Shift stream timestamps so that they are aligned.
This is a hack around to handle data that are asynchronously sampled. It should not be used in general. It is only appropriate for datasets that have been tested with it. PKD, SAO only at this point.
- Parameters:
streams (iterable of types obspy.core.stream.Stream) –
clock_start (obspy UTCDateTime) – this is a reference time that we set the first sample to be
- Return type:
streams
- aurora.sandbox.obspy_helpers.make_channel_labels_fdsn_compliant(streams)[source]¶
Renames channels to FDSN compliant channel names.
Workaround because NCEDC channel nomenclature is not FDSN Compliant for PKD, SAO Specifically, re-assign non-conventional channel labels Q2 –> Q1 Q3 –> Q2 T1 –> F1 T2 –> F2 T3 –> F3
- Parameters:
streams (iterable of types obspy.core.stream.Stream) –
- Returns:
streams – Same as input but updated with new channel names.
- Return type:
iterable of types obspy.core.stream.Stream
aurora.sandbox.plot_helpers module¶
This module contains some plotting helper functions.
Most of these were used in initial development and should be replaced by methods in MTpy. TODO: review which of these can be replaced with methods in MTpy-v2
- aurora.sandbox.plot_helpers.cast_angular_frequency_to_period_or_hertz(w, units)[source]¶
Converts angular frequency to period or Hertz
- Parameters:
w (numpy array) – Angular frequencies (radians per second)
units (str) – Requested output units (“period” or “frequency”)
- Returns:
x_axis – Same as input but units are now the requested ones.
- Return type:
np.ndarray
- aurora.sandbox.plot_helpers.plot_complex_response(frequency: ndarray, complex_response: ndarray, show: bool | None = True, linewidth: float | None = 3, make: str | None = None, model: str | None = None, yamp: str | None = None)[source]¶
Plots amplitude and phase of a complex response as a function of frequency.
Development Notes: ToDo: add methods for supporting instrument object but for now take as kwargs
- Parameters:
frequency – numpy array of frequencies at which complex response is defined
complex_response – numpy array of full complex valued response function
- Returns:
- aurora.sandbox.plot_helpers.plot_response_pz(w_obs=None, resp_obs=None, zpk_obs=None, zpk_pred=None, w_values=None, xlim=None, title=None, x_units='Period')[source]¶
Plots the pole zero response.
This function was contributed by Ben Murphy at USGS 2021-03-17: there are some issues encountered when using this function to plot generic resposnes, looks like the x-axis gets out of order when using frequency as the axis …
- Parameters:
w_obs (numpy array) – Angular frequencies from lab observations, for example a fap calibration table
resp_obs (numpy array) – Complex valued response associated with lab observation
zpk_obs (scipy.signal.ltisys.ZerosPolesGainContinuous) – Pole-Zero object representing the lab observation
zpk_pred (scipy.signal.ltisys.ZerosPolesGainContinuous) – Pole-Zero object representing the model
w_values (numpy array) – Angular frequencies at which to evaluate zpk_pred and zpk_obs
xlim –
title (string) – Title for the plot
x_units (string) – One of [“Period” , “frequency”], case insensitve
- aurora.sandbox.plot_helpers.plot_tf_obj(tf_obj, out_filename=None, show=True)[source]¶
Plot the transfer function object in terms of apparent resistivity and phase.
- Development Notes:
This function is only used in the processing pipeline to give some QC plots
TODO: Get plotter from MTpy or elsewhere. See Issue #209 https://github.com/simpeg/aurora/issues/209 :param tf_obj: The transfer function values packed into an object :type tf_obj: aurora.transfer_function.TTFZ.TTFZ :param out_filename: Where to save the file. No png is saved if this is False :type out_filename: string
aurora.sandbox.triage_metadata module¶
This module contains various helper functions that were used to fix errors in metadata.
- aurora.sandbox.triage_metadata.triage_missing_coil_hollister(experiment: Experiment) Experiment [source]¶
Fixes missing metadata for Hollister station
One-off for hollister missing hy metadata in NCEDC archive.
- Parameters:
experiment –
- aurora.sandbox.triage_metadata.triage_mt_units_electric_field(experiment: Experiment) Experiment [source]¶
Updates an mth5 experiment with filter information
One-off example of adding a filter to an mth5 in the case where the electric field data are given in V/m, but they were expected in mV/km. This adds the correct filter to the metadata so that the calibrated data have units of mV/km.
- Parameters:
experiment (mt_metadata.timeseries.Experiment) – mt_metadata representation of station XML
- Returns:
experiment – Updated experiment with additional filter to make electric field into MT Units (mV/km)
- Return type:
mt_metadata.timeseries.Experiment
- aurora.sandbox.triage_metadata.triage_mt_units_magnetic_field(experiment: Experiment) Experiment [source]¶
Updates an mth5 experiment with filter information
One-off example of adding a filter to an mth5 in the case where the magnetic field data are given in T, but they were expected in nT. This adds the correct filter to the metadata so that the calibrated data have units of nT.
- Parameters:
experiment (mt_metadata.timeseries.Experiment) – mt_metadata representation of station XML
- Returns:
experiment – Updated experiment with additional filter to make magnetic field into MT Units (nT)
- Return type:
mt_metadata.timeseries.Experiment
- aurora.sandbox.triage_metadata.triage_run_id(expected_run_id: str, run_obj: RunGroup) None [source]¶
Fixes metadata from an old version of MTH5.
This situation was encountered during the Musgraves processing for 2023 HPC workshop. The MTH5 files being used were from a previous era, and the run_object metadata did not contain the expected value for run_id.
- Parameters:
expected_run_id (string) – The expected name of the run
run_obj (mth5.groups.run.RunGroup) – The run object that should have correct name.