HinetPy.win32 module
Process seismic waveform data in win32 format.
- HinetPy.win32.extract_sac(data, ctable, suffix='SAC', outdir='.', pmax=8640000, filter_by_id=None, filter_by_name=None, filter_by_component=None, with_sacpz=False, processes=None)
Extract data as SAC format files.
This function calls the
win2sac_32
command, available in the Hi-net win32tools package, to convert data files from win32 format to SAC fomrat. It can also extract the channel information as SAC polezero files.Note that the
win2sac_32
command always remove the instrument sensitivity from waveform data, and multiply the data by 1.0e9. Thus, the extracted SAC files are not in digital counts, but velocity in nm/s, or acceleration in nm/s/s. Due to the same reason, the extracted SAC polezero files does not keep the sensitivity in the “CONSTANT” of SAC polezero files.- Parameters:
data (str) – win32 file to be processed.
ctable (str) – Channel table file.
suffix (str) – Suffix of output SAC files. Defaults to
SAC
.outdir (str) – Output directory. Defaults to current directory.
pmax (int) – Maximum number of data points for one channel. Defaults to 8640000. If one channel has more than 8640000 data points (i.e., longer than one day for a 100 Hz sampling rate), you MUST increase
pmax
.filter_by_id (list or str) – Filter channels by ID. It can be a list of IDs or a wildcard.
filter_by_name (list or str) – Filter channels by name. It can be a list of names or a wildcard.
filter_by_component (list or str) – Filter channels by component. It can be a list of component names or a wildcard.
with_sacpz (bool) – Aslo extract SAC PZ files. By default, the suffix is
.SAC_PZ
and the channel sensitivity is not kept in the “CONSTANT”.processes (None or int) – Number of processes to speed up data extraction parallelly.
None
means using all CPUs.deprecated: (..) – 0.7.0: Parameter
with_pz
is deprecated. Usewith_sacpz
instead.
Examples
Extract all channels with default settings:
>>> extract_sac("0101_201001010000_5.cnt", "0101_20100101.ch")
Extract all channels with a specified suffix and output directory:
>>> extract_sac( ... "0101_201001010000_5.cnt", ... "0101_20100101.ch", ... suffix="", ... outdir="20100101000", ... )
Extract only specified channels:
>>> extract_sac( ... "0101_201001010000_5.cnt", ... "0101_20100101.ch", ... filter_by_name="N.NA*", ... filter_by_component="[NE]", ... )
- HinetPy.win32.extract_sacpz(ctable, suffix='SAC_PZ', outdir='.', keep_sensitivity=False, filter_by_chid=None, filter_by_name=None, filter_by_component=None, processes=None)
Extract instrumental responses in SAC polezero format from a channel table.
Warning
The function only works for Hi-net instrumental responses.
RESP files of the F-net network can be downloaded from F-net website.
- Parameters:
ctable (str) – Channel table file.
suffix (str) – Suffix of SAC PZ files. Defaults to
SAC_PZ
.outdir (str) – Output directory. Defaults to current directory.
keep_sensitivity (bool) – The
win2sac_32
program automatically removes sensitivity from waveform data during the win32-to-SAC format conversion. So the generated polezero file should omit the sensitivity.filter_by_id (list or str) – Filter channels by ID. It can be a list of IDs or a wildcard.
filter_by_name (list or str) – Filter channels by name. It can be a list of names or a wildcard.
filter_by_component (list or str) – Filter channels by component. It can be a list of component names or a wildcard.
processes (None or int) – Number of processes to speed up data extraction parallelly.
None
means using all CPUs.
Examples
Extract all channels with default settings:
>>> extract_sacpz("0101_20100101.ch")
Extract all channels with a specified suffix and output directory:
>>> extract_sacpz("0101_20100101.ch", suffix="", outdir="20100101000")
Extract only specified channels:
>>> extract_sacpz( ... "0101_20100101.ch", filter_by_name="N.NA*", filter_by_component="[NE]" ... )
- HinetPy.win32.extract_pz(ctable, **kwargs)
Extract instrumental responses in SAC polezero format from a channel table.
Deprecated since version 0.7.0:
extract_pz()
is deprecated. Useextract_sacpz()
instead.
- HinetPy.win32.read_ctable(ctable)
Read a channel table file.
- HinetPy.win32.merge(data, total_data, force_sort=False)
Merge multiple win32 files into one large win32 file.
The function calls the
catwin32
command, available in the Hi-net win32tools package, to merge multiple win32 files into one large win32 file.By default, the
catwin32
command simply concatenates all files in the order they are passed. So the files must be sorted by their start time before being passed. If your files are named by starttime like201304040203.cnt
, you can usedata=sorted(glob.glob("20130404*.cnt"))
to pass the sorted list of files. Otherwise, you have to useforce_sort=True
, forcingcatwin32
to sort all files by starttime before merging. However, the sorting process is very time consuming. Do NOT setforce_sort=True
unless necessary.- Parameters:
Examples
For win32 files that are named by starttime (e.g.
201304040203.cnt
), sorting win32 files using Python’s built-insorted()
function is preferred:>>> data = sorted(glob.glob("20130404*.cnt")) >>> merge(data, "outdir/final.cnt")
If win32 files are randomly named, you should use
force_sort=True
to forcecatwin32
to sort all data by time before merging.>>> data = ["001.cnt", "002.cnt", "003.cnt"] >>> merge(data, "final.cnt", force_sort=True)
You can also use wildcard to specify the win32 files to be merged. The function will sort the matched files for you automatically.
>>> merge("20130404*.cnt", "final.cnt")