mth5.io.usgs_ascii package

Submodules

mth5.io.usgs_ascii.usgs_ascii module

Created on Thu Aug 27 16:54:09 2020

author

Jared Peacock

license

MIT

class mth5.io.usgs_ascii.usgs_ascii.USGSascii(fn=None, **kwargs)[source]

Bases: AsciiMetadata

Read and write USGS ascii formatted time series.

Attributes

Description

ts

Pandas dataframe holding the time series data

fn

Full path to .asc file

station_dir

Full path to station directory

meta_notes

Notes of how the station was collected

Example
>>> zc = Z3DCollection()
>>> fn_list = zc.get_time_blocks(z3d_path)
>>> zm = USGSasc()
>>> zm.SurveyID = 'iMUSH'
>>> zm.get_z3d_db(fn_list[0])
>>> zm.read_mtft24_cfg()
>>> zm.CoordinateSystem = 'Geomagnetic North'
>>> zm.SurveyID = 'MT'
>>> zm.write_asc_file(str_fmt='%15.7e')
>>> zm.write_station_info_metadata()
property ex
property ey
property hx

HX

property hy
property hz
read(fn=None)[source]

Read in a USGS ascii file and fill attributes accordingly.

Parameters

fn (string) – full path to .asc file to be read in

to_run_ts()[source]

Get xarray for run

write(save_fn=None, chunk_size=1024, str_fmt='%15.7e', full=True, compress=False, save_dir=None, compress_type='zip', convert_electrics=True)[source]

Write an ascii file in the USGS ascii format.

Parameters
  • save_fn (string) – full path to file name to save the merged ascii to

  • chunck_size (int) – chunck size to write file in blocks, larger numbers are typically slower.

  • str_fmt (string) – format of the data as written

  • full (boolean [ True | False ]) – write out the complete file, mostly for testing.

  • compress (boolean [ True | False ]) – compress file

  • compress_type (boolean [ zip | gzip ]) – compress file using zip or gzip

mth5.io.usgs_ascii.usgs_ascii.read_ascii(fn)[source]

read USGS ASCII formatted file

Parameters

fn (TYPE) – DESCRIPTION

Returns

DESCRIPTION

Return type

TYPE

Module contents

class mth5.io.usgs_ascii.AsciiMetadata(fn=None, **kwargs)[source]

Bases: object

Container for all the important metadata in a USGS ascii file.

Attributes

Description

survey_id

Survey name

site_id

Site name

run_id

Run number

site_latitude

Site latitude in decimal degrees WGS84

site_longitude

Site longitude in decimal degrees WGS84

site_elevation

Site elevation according to national map meters

start

Start time of station YYYY-MM-DDThh:mm:ss UTC

end

Stop time of station YYYY-MM-DDThh:mm:ss UTC

sample_rate

Sampling rate samples/second

n_samples

Number of samples

n_channels

Number of channels

coordinate_system

[ Geographic North | Geomagnetic North ]

chn_settings

Channel settings, see below

missing_data_flag

Missing data value

Chn_settings

Keys

Description

ChnNum

site_id+channel number

ChnID

Component [ ex | ey | hx | hy | hz ]

InstrumentID

Data logger + sensor number

Azimuth

Setup angle of componet in degrees relative to coordinate_system

Dipole_Length

Dipole length in meters

property elevation

get elevation from national map

property end
property file_size
property fn
get_component_info(comp)[source]
Parameters

comp (TYPE) – DESCRIPTION

Returns

DESCRIPTION

Return type

TYPE

property latitude
property longitude
property n_channels
property n_samples
read_metadata(fn=None, meta_lines=None)[source]

Read in a meta from the raw string or file. Populate all metadata as attributes.

Parameters
  • fn (string) – full path to USGS ascii file

  • meta_lines (list) – lines of metadata to read

property run_id
property run_metadata
property sample_rate
property site_id
property start
property station_metadata
property survey_id
property survey_metadata
write_metadata(chn_list=['Ex', 'Ey', 'Hx', 'Hy', 'Hz'])[source]

Write out metadata in the format of USGS ascii.

return

list of metadate lines.

Note

meant to use ‘

‘.join(lines) to write out in a file.

class mth5.io.usgs_ascii.USGSascii(fn=None, **kwargs)[source]

Bases: AsciiMetadata

Read and write USGS ascii formatted time series.

Attributes

Description

ts

Pandas dataframe holding the time series data

fn

Full path to .asc file

station_dir

Full path to station directory

meta_notes

Notes of how the station was collected

Example
>>> zc = Z3DCollection()
>>> fn_list = zc.get_time_blocks(z3d_path)
>>> zm = USGSasc()
>>> zm.SurveyID = 'iMUSH'
>>> zm.get_z3d_db(fn_list[0])
>>> zm.read_mtft24_cfg()
>>> zm.CoordinateSystem = 'Geomagnetic North'
>>> zm.SurveyID = 'MT'
>>> zm.write_asc_file(str_fmt='%15.7e')
>>> zm.write_station_info_metadata()
property ex
property ey
property hx

HX

property hy
property hz
read(fn=None)[source]

Read in a USGS ascii file and fill attributes accordingly.

Parameters

fn (string) – full path to .asc file to be read in

to_run_ts()[source]

Get xarray for run

write(save_fn=None, chunk_size=1024, str_fmt='%15.7e', full=True, compress=False, save_dir=None, compress_type='zip', convert_electrics=True)[source]

Write an ascii file in the USGS ascii format.

Parameters
  • save_fn (string) – full path to file name to save the merged ascii to

  • chunck_size (int) – chunck size to write file in blocks, larger numbers are typically slower.

  • str_fmt (string) – format of the data as written

  • full (boolean [ True | False ]) – write out the complete file, mostly for testing.

  • compress (boolean [ True | False ]) – compress file

  • compress_type (boolean [ zip | gzip ]) – compress file using zip or gzip

class mth5.io.usgs_ascii.USGSasciiCollection(file_path=None, **kwargs)[source]

Bases: Collection

Collection of USGS ASCII files.

>>> from mth5.io.usgs_ascii import USGSasciiCollection
>>> lc = USGSasciiCollection(r"/path/to/ascii/files")
>>> run_dict = lc.get_runs(1)
assign_run_names(df, zeros=4)[source]

Assign run names based on start and end times, checks if a file has the same start time as the last end time.

Run names are assigned as sr{sample_rate}_{run_number:0{zeros}}. Only if the run name is not assigned already.

Parameters
  • df (pandas.DataFrame) – Dataframe with the appropriate columns

  • zeros (int, optional) – number of zeros in run name, defaults to 4

Returns

Dataframe with run names

Return type

pandas.DataFrame

to_dataframe(sample_rates=[4], run_name_zeros=4, calibration_path=None)[source]

Create a data frame of each TXT file in a given directory.

Note

If a run name is already present it will not be overwritten

Parameters
  • sample_rates (int or list, optional) – sample rate to get, defaults to [4]

  • run_name_zeros (int, optional) – number of zeros to assing to the run name, defaults to 4

  • calibration_path (string or Path, optional) – path to calibration files, defaults to None

Returns

Dataframe with information of each TXT file in the given directory.

Return type

pandas.DataFrame

Example
>>> from mth5.io.usgs_ascii import USGSasciiCollection
>>> lc = USGSasciiCollection("/path/to/ascii/files")
>>> ascii_df = lc.to_dataframe()
mth5.io.usgs_ascii.read_ascii(fn)[source]

read USGS ASCII formatted file

Parameters

fn (TYPE) – DESCRIPTION

Returns

DESCRIPTION

Return type

TYPE