本文整理汇总了Python中obspy.UTCDateTime.isoformat方法的典型用法代码示例。如果您正苦于以下问题:Python UTCDateTime.isoformat方法的具体用法?Python UTCDateTime.isoformat怎么用?Python UTCDateTime.isoformat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.UTCDateTime
的用法示例。
在下文中一共展示了UTCDateTime.isoformat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import isoformat [as 别名]
#.........这里部分代码省略.........
counter = parse_func(data, samp_int, path, counter, options.format,
options.verbose, options.ignore_links)
if not data:
print("No waveform data found.")
return
if options.write:
write_npz(options.write, data, samp_int)
# Loop through this dictionary
ids = data.keys()
# restrict plotting of results to given ids
if options.ids:
options.ids = options.ids.split(',')
ids = filter(lambda x: x in options.ids, ids)
ids = sorted(ids)[::-1]
labels = [""] * len(ids)
print
for _i, _id in enumerate(ids):
labels[_i] = ids[_i]
data[_id].sort()
startend = np.array(data[_id])
if len(startend) == 0:
continue
# restrict plotting of results to given start/endtime
if options.starttime:
startend = startend[startend[:, 1] > options.starttime]
if len(startend) == 0:
continue
if options.starttime:
startend = startend[startend[:, 0] < options.endtime]
if len(startend) == 0:
continue
if _id not in samp_int:
warnings.warn('Problem with _id=%s, skipping' % _id)
continue
startend_compressed = compressStartend(startend, 1000)
offset = np.ones(len(startend)) * _i # generate list of y values
ax.xaxis_date()
if not options.nox:
ax.plot_date(startend[:, 0], offset, 'x', linewidth=2)
ax.hlines(offset[:len(startend_compressed)], startend_compressed[:, 0],
startend_compressed[:, 1], 'b', linewidth=2, zorder=3)
# find the gaps
diffs = startend[1:, 0] - startend[:-1, 1] # currend.start - last.end
gapsum = diffs[diffs > 0].sum()
timerange = startend[:, 1].max() - startend[:, 0].min()
perc = (timerange - gapsum) / timerange
labels[_i] = labels[_i] + "\n%.1f%%" % (perc * 100)
gap_indices = diffs > 1.8 * samp_int[_id]
gap_indices = np.concatenate((gap_indices, [False]))
if any(gap_indices):
# dont handle last endtime as start of gap
gaps_start = startend[gap_indices, 1]
gaps_end = startend[np.roll(gap_indices, 1), 0]
if not options.nogaps and any(gap_indices):
rects = [Rectangle((start_, offset[0] - 0.4),
end_ - start_, 0.8)
for start_, end_ in zip(gaps_start, gaps_end)]
ax.add_collection(PatchCollection(rects, color="r"))
if options.print_gaps:
for start_, end_ in zip(gaps_start, gaps_end):
start_, end_ = num2date((start_, end_))
start_ = UTCDateTime(start_.isoformat())
end_ = UTCDateTime(end_.isoformat())
print "%s %s %s %.3f" % (_id, start_, end_, end_ - start_)
# Pretty format the plot
ax.set_ylim(0 - 0.5, _i + 0.5)
ax.set_yticks(np.arange(_i + 1))
ax.set_yticklabels(labels, family="monospace", ha="right")
# set x-axis limits according to given start/endtime
if options.starttime:
ax.set_xlim(left=options.starttime, auto=None)
if options.endtime:
ax.set_xlim(right=options.endtime, auto=None)
fig.autofmt_xdate() # rotate date
plt.subplots_adjust(left=0.2)
if options.output is None:
plt.show()
else:
fig.set_dpi(72)
height = len(ids) * 0.5
height = max(4, height)
fig.set_figheight(height)
# tight_layout() only available from matplotlib >= 1.1
try:
plt.tight_layout()
days = ax.get_xlim()
days = days[1] - days[0]
width = max(6, days / 30.)
width = min(width, height * 4)
fig.set_figwidth(width)
plt.subplots_adjust(top=1, bottom=0, left=0, right=1)
plt.tight_layout()
except:
pass
fig.savefig(options.output)
sys.stdout.write('\n')
示例2: analyze_parsed_data
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import isoformat [as 别名]
#.........这里部分代码省略.........
_samp_int = np.array([])
if len(startend) == 0:
if not (starttime and endtime):
continue
gap_info.append((starttime, endtime))
if print_gaps:
print("%s %s %s %.3f" % (
_id, starttime, endtime, endtime - starttime))
continue
# restrict plotting of results to given start/end time
if starttime or endtime:
indices = np.ones(len(startend), dtype=np.bool_)
if starttime:
indices &= startend[:, 1] > starttime
if endtime:
indices &= startend[:, 0] < endtime
startend = startend[indices]
_samp_int = _samp_int[indices]
if len(startend) == 0:
# if both start and endtime are given, add it to gap info
if starttime and endtime:
gap_info.append((starttime, endtime))
continue
data_start = startend[:, 0].min()
data_end = startend[:, 1].max()
timerange_start = starttime or data_start
timerange_end = endtime or data_end
timerange = timerange_end - timerange_start
if timerange == 0.0:
msg = 'Zero sample long data for _id=%s, skipping' % _id
warnings.warn(msg)
continue
startend_compressed = compress_start_end(startend.copy(), 1000,
merge_overlaps=True)
info["data_starts"] = startend[:, 0]
info["data_startends_compressed"] = startend_compressed
# find the gaps
# currend.start - last.end
diffs = startend[1:, 0] - startend[:-1, 1]
gapsum = diffs[diffs > 0].sum()
# if start- and/or endtime is specified, add missing data at
# start/end to gap sum
has_gap = False
gap_at_start = (
starttime and
data_start > starttime and
data_start - starttime)
gap_at_end = (
endtime and
endtime > data_end and
endtime - data_end)
if gap_at_start:
gapsum += gap_at_start
has_gap = True
if gap_at_end:
gapsum += gap_at_end
has_gap = True
info["percentage"] = (timerange - gapsum) / timerange * 100
# define a gap as over 0.8 delta after expected sample time
gap_indices = diffs > 0.8 * _samp_int[:-1]
gap_indices = np.append(gap_indices, False)
# define an overlap as over 0.8 delta before expected sample time
overlap_indices = diffs < -0.8 * _samp_int[:-1]
overlap_indices = np.append(overlap_indices, False)
has_gap |= any(gap_indices)
has_gap |= any(overlap_indices)
if has_gap:
# don't handle last end time as start of gap
gaps_start = startend[gap_indices, 1]
gaps_end = startend[np.roll(gap_indices, 1), 0]
overlaps_end = startend[overlap_indices, 1]
overlaps_start = startend[np.roll(overlap_indices, 1), 0]
# but now, manually add start/end for gaps at start/end of user
# specified start/end times
if gap_at_start:
gaps_start = np.append(gaps_start, starttime)
gaps_end = np.append(gaps_end, data_start)
if gap_at_end:
gaps_start = np.append(gaps_start, data_end)
gaps_end = np.append(gaps_end, endtime)
_starts = np.concatenate((gaps_start, overlaps_end))
_ends = np.concatenate((gaps_end, overlaps_start))
sort_order = np.argsort(_starts)
_starts = _starts[sort_order]
_ends = _ends[sort_order]
for start_, end_ in zip(_starts, _ends):
if print_gaps:
start__, end__ = num2date((start_, end_))
start__ = UTCDateTime(start__.isoformat())
end__ = UTCDateTime(end__.isoformat())
print("{} {} {} {:.3f}".format(
_id, start__, end__, end__ - start__))
if start_ < end_:
gap_info.append((start_, end_))
else:
overlap_info.append((start_, end_))
示例3: main
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import isoformat [as 别名]
#.........这里部分代码省略.........
ax.plot(startend[:, 0], offset, 'x', linewidth=2)
ax.hlines(offset[:len(startend_compressed)], startend_compressed[:, 0],
startend_compressed[:, 1], 'b', linewidth=2, zorder=3)
# find the gaps
diffs = startend[1:, 0] - startend[:-1, 1] # currend.start - last.end
gapsum = diffs[diffs > 0].sum()
# if start- and/or endtime is specified, add missing data at start/end
# to gap sum
has_gap = False
gap_at_start = (
args.start_time and
data_start > args.start_time and
data_start - args.start_time)
gap_at_end = (
args.end_time and
args.end_time > data_end and
args.end_time - data_end)
if args.start_time and gap_at_start:
gapsum += gap_at_start
has_gap = True
if args.end_time and gap_at_end:
gapsum += gap_at_end
has_gap = True
perc = (timerange - gapsum) / timerange
labels[_i] = labels[_i] + "\n%.1f%%" % (perc * 100)
gap_indices = diffs > 1.8 * _samp_int[:-1]
gap_indices = np.append(gap_indices, False)
has_gap |= any(gap_indices)
if has_gap:
# don't handle last end time as start of gap
gaps_start = startend[gap_indices, 1]
gaps_end = startend[np.roll(gap_indices, 1), 0]
if args.start_time and gap_at_start:
gaps_start = np.append(gaps_start, args.start_time)
gaps_end = np.append(gaps_end, data_start)
if args.end_time and gap_at_end:
gaps_start = np.append(gaps_start, data_end)
gaps_end = np.append(gaps_end, args.end_time)
if not args.no_gaps:
rects = [Rectangle((start_, offset[0] - 0.4), end_ - start_,
0.8)
for start_, end_ in zip(gaps_start, gaps_end)]
ax.add_collection(PatchCollection(rects, color="r"))
if args.print_gaps:
for start_, end_ in zip(gaps_start, gaps_end):
start_, end_ = num2date((start_, end_))
start_ = UTCDateTime(start_.isoformat())
end_ = UTCDateTime(end_.isoformat())
if args.verbose or not args.quiet:
print("%s %s %s %.3f" % (_id, start_, end_,
end_ - start_))
# Pretty format the plot
ax.set_ylim(0 - 0.5, len(ids) - 0.5)
ax.set_yticks(np.arange(len(ids)))
ax.set_yticklabels(labels, family="monospace", ha="right")
fig.autofmt_xdate() # rotate date
ax.xaxis_date()
# set custom formatters to always show date in first tick
formatter = ObsPyAutoDateFormatter(ax.xaxis.get_major_locator())
formatter.scaled[1 / 24.] = \
FuncFormatter(decimal_seconds_format_date_first_tick)
formatter.scaled.pop(1/(24.*60.))
ax.xaxis.set_major_formatter(formatter)
plt.subplots_adjust(left=0.2)
# set x-axis limits according to given start/end time
if args.start_time and args.end_time:
ax.set_xlim(left=args.start_time, right=args.end_time)
elif args.start_time:
ax.set_xlim(left=args.start_time, auto=None)
elif args.end_time:
ax.set_xlim(right=args.end_time, auto=None)
else:
left, right = ax.xaxis.get_data_interval()
x_axis_range = right - left
ax.set_xlim(left - 0.05 * x_axis_range, right + 0.05 * x_axis_range)
if args.output is None:
plt.show()
else:
fig.set_dpi(72)
height = len(ids) * 0.5
height = max(4, height)
fig.set_figheight(height)
plt.tight_layout()
if not args.start_time or not args.end_time:
days = ax.get_xlim()
days = days[1] - days[0]
else:
days = args.end_time - args.start_time
width = max(6, days / 30.)
width = min(width, height * 4)
fig.set_figwidth(width)
plt.subplots_adjust(top=1, bottom=0, left=0, right=1)
plt.tight_layout()
fig.savefig(args.output)
if args.verbose and not args.quiet:
sys.stdout.write('\n')
示例4: main
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import isoformat [as 别名]
#.........这里部分代码省略.........
if not data:
print("No waveform data found.")
return
if args.write:
write_npz(args.write, data, samp_int)
# Loop through this dictionary
ids = list(data.keys())
# Handle deprecated argument
if args.ids and not args.id:
args.id = args.ids.split(',')
# restrict plotting of results to given ids
if args.id:
ids = [x for x in ids if x in args.id]
ids = sorted(ids)[::-1]
labels = [""] * len(ids)
print('\n')
for _i, _id in enumerate(ids):
labels[_i] = ids[_i]
data[_id].sort()
startend = np.array(data[_id])
if len(startend) == 0:
continue
# restrict plotting of results to given start/end time
if args.start_time:
startend = startend[startend[:, 1] > args.start_time]
if len(startend) == 0:
continue
if args.start_time:
startend = startend[startend[:, 0] < args.end_time]
if len(startend) == 0:
continue
timerange = startend[:, 1].max() - startend[:, 0].min()
if timerange == 0.0:
warnings.warn('Zero sample long data for _id=%s, skipping' % _id)
continue
startend_compressed = compressStartend(startend, 1000)
offset = np.ones(len(startend)) * _i # generate list of y values
ax.xaxis_date()
if not args.no_x:
ax.plot_date(startend[:, 0], offset, 'x', linewidth=2)
ax.hlines(offset[:len(startend_compressed)], startend_compressed[:, 0],
startend_compressed[:, 1], 'b', linewidth=2, zorder=3)
# find the gaps
diffs = startend[1:, 0] - startend[:-1, 1] # currend.start - last.end
gapsum = diffs[diffs > 0].sum()
perc = (timerange - gapsum) / timerange
labels[_i] = labels[_i] + "\n%.1f%%" % (perc * 100)
gap_indices = diffs > 1.8 * np.array(samp_int[_id][:-1])
gap_indices = np.concatenate((gap_indices, [False]))
if any(gap_indices):
# don't handle last end time as start of gap
gaps_start = startend[gap_indices, 1]
gaps_end = startend[np.roll(gap_indices, 1), 0]
if not args.no_gaps and any(gap_indices):
rects = [Rectangle((start_, offset[0] - 0.4),
end_ - start_, 0.8)
for start_, end_ in zip(gaps_start, gaps_end)]
ax.add_collection(PatchCollection(rects, color="r"))
if args.print_gaps:
for start_, end_ in zip(gaps_start, gaps_end):
start_, end_ = num2date((start_, end_))
start_ = UTCDateTime(start_.isoformat())
end_ = UTCDateTime(end_.isoformat())
print("%s %s %s %.3f" % (_id, start_, end_, end_ - start_))
# Pretty format the plot
ax.set_ylim(0 - 0.5, _i + 0.5)
ax.set_yticks(np.arange(_i + 1))
ax.set_yticklabels(labels, family="monospace", ha="right")
# set x-axis limits according to given start/end time
if args.start_time:
ax.set_xlim(left=args.start_time, auto=None)
if args.end_time:
ax.set_xlim(right=args.end_time, auto=None)
fig.autofmt_xdate() # rotate date
plt.subplots_adjust(left=0.2)
if args.output is None:
plt.show()
else:
fig.set_dpi(72)
height = len(ids) * 0.5
height = max(4, height)
fig.set_figheight(height)
# tight_layout() only available from matplotlib >= 1.1
try:
plt.tight_layout()
days = ax.get_xlim()
days = days[1] - days[0]
width = max(6, days / 30.)
width = min(width, height * 4)
fig.set_figwidth(width)
plt.subplots_adjust(top=1, bottom=0, left=0, right=1)
plt.tight_layout()
except:
pass
fig.savefig(args.output)
sys.stdout.write('\n')