def read_event_list(sfile): config = get_config() sfile_dir = os.path.join(config['CATALOG_ROOT'], sfile) sfile_list = get_dir_list(sfile_dir) print(f'reading events from {sfile_dir}') events = parallel(par=get_event, file_list=sfile_list) print(f'read {len(events)} events from {sfile}') return events
def read_dataset(dataset): """ Returns TFRecord Dataset from TFRecord directory. :param str dataset_dir: Directory contains TFRecords. :rtype: tf.data.Dataset :return: A Dataset. """ config = utils.get_config() dataset_dir = os.path.join(config['DATASET_ROOT'], dataset) file_list = utils.get_dir_list(dataset_dir) dataset = tf.data.TFRecordDataset(file_list) dataset = dataset.map(example_proto.sequence_example_parser, num_parallel_calls=mp.cpu_count()) return dataset
def read_event_list(sfile_dir): """ Returns event list from sfile directory. :param str sfile_dir: Directory contains SEISAN sfile. :rtype: list :return: list of event. """ config = utils.get_config() sfile_dir = os.path.join(config['CATALOG_ROOT'], sfile_dir) sfile_list = utils.get_dir_list(sfile_dir) print(f'Reading events from {sfile_dir}') event_list = utils.parallel(sfile_list, func=get_event) flatten = itertools.chain.from_iterable events = list(flatten(flatten(event_list))) print(f'Read {len(events)} events\n') return events
from obspy import read from seisnn.io import write_pkl from seisnn.utils import get_dir_list from seisnn.plot import plot_dataset pick_pkl = "/mnt/tf_data/catalog/new_pick.dataset" predict_pkl_dir = "/mnt/tf_data/dataset/2018_02_18_predict" predict_pkl_list = get_dir_list(predict_pkl_dir) new_pick = [] try: for i, pkl in enumerate(predict_pkl_list): trace = read(pkl).traces[0] start_time = trace.stats.starttime for p in trace.picks: if p.evaluation_mode == "automatic": if not p.evaluation_status == "confirmed" and not p.evaluation_status == "rejected": pick_time = p.time - start_time plot_dataset(trace, xlim=(pick_time - 2, pick_time + 4)) key_in = input("Confirmed pick? [y/N]") if key_in == "y" or key_in == "Y": print("Current file... %d out of %d" % (i, len(predict_pkl_list))) p.evaluation_mode = "manual" p.evaluation_status = "reviewed" new_pick.append(p) if i % 100 == 0: print("Current file... %d out of %d" % (i, len(predict_pkl_list)))
def read_dataset(dataset_dir): file_list = get_dir_list(dataset_dir) dataset = tf.data.TFRecordDataset(file_list) dataset = dataset.map(sequence_example_parser, num_parallel_calls=cpu_count()) return dataset
import os from obspy import read from tqdm import tqdm from seisnn.io import read_pkl from seisnn.utils import get_dir_list from seisnn.flow import get_exist_picks pkl_dir = "/mnt/tf_data/dataset/2018_02_18_predict" pkl_list = get_dir_list(pkl_dir) pkl_output_dir = pkl_dir + "_updated" pick_pkl = "/mnt/tf_data/catalog/new_pick.dataset" pick_list = read_pkl(pick_pkl) os.makedirs(pkl_output_dir, exist_ok=True) with tqdm(total=len(pkl_list)) as pbar: for i, pkl in enumerate(pkl_list): trace = read(pkl).traces[0] new_picks = get_exist_picks(trace, pick_list) trace.picks.extend(new_picks) time_stamp = trace.stats.starttime.isoformat() trace.write(pkl_output_dir + '/' + time_stamp + trace.get_id() + ".dataset", format="PICKLE") pbar.update()