本文整理汇总了Python中obspy.UTCDateTime方法的典型用法代码示例。如果您正苦于以下问题:Python obspy.UTCDateTime方法的具体用法?Python obspy.UTCDateTime怎么用?Python obspy.UTCDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy
的用法示例。
在下文中一共展示了obspy.UTCDateTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_stn_availability
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def write_stn_availability(self, stn_ava_data):
"""
Write out csv files (split by julian day) containing station
availability data.
Parameters
----------
stn_ava_data : pandas DataFrame object
Contains station availability information
"""
stn_ava_data.index = times = pd.to_datetime(stn_ava_data.index)
datelist = [time.date() for time in times]
for date in datelist:
to_write = stn_ava_data[stn_ava_data.index.date == date]
to_write.index = [UTCDateTime(idx) for idx in to_write.index]
date = UTCDateTime(date)
fname = self.run / "{}_{}_{}_StationAvailability".format(self.name,
date.year,
str(date.julday).zfill(3))
fname = str(fname.with_suffix(".csv"))
to_write.to_csv(fname)
示例2: printCatalog
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def printCatalog(rtable, ftable, opt):
"""
Prints flat catalog to text file
rtable: Repeater table
ftable: Families table
opt: Options object describing station/run parameters
Note: Time in text file corresponds to current trigger time by alignment
"""
with open('{}{}/catalog.txt'.format(opt.outputPath, opt.groupName), 'w') as f:
startTimes = rtable.cols.startTime[:]
windowStarts = rtable.cols.windowStart[:]
for cnum in range(ftable.attrs.nClust):
fam = np.fromstring(ftable[cnum]['members'], dtype=int, sep=' ')
for i in np.argsort(startTimes[fam]):
f.write("{0} {1}\n".format(cnum,(UTCDateTime(startTimes[fam][i]) +
windowStarts[fam][i]/opt.samprate).isoformat()))
示例3: printTriggerCatalog
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def printTriggerCatalog(ttable, opt):
"""
Prints flat catalog of all triggers to text file
ttable: Triggers table
opt: Options object describing station/run parameters
Note: Time in text file corresponds to original STA/LTA trigger time
"""
with open('{}{}/triggers.txt'.format(opt.outputPath, opt.groupName), 'w') as f:
startTimes = ttable.cols.startTimeMPL[:]
for i in np.argsort(startTimes):
f.write("{0}\n".format((UTCDateTime(matplotlib.dates.num2date(
startTimes[i]))+opt.ptrig).isoformat()))
示例4: printOrphanCatalog
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def printOrphanCatalog(otable, opt):
"""
Prints flat catalog of current orphans to text file
otable: Orphans table
opt: Options object describing station/run parameters
Note: Time in text file corresponds to original STA/LTA trigger time
"""
with open('{}{}/orphancatalog.txt'.format(opt.outputPath, opt.groupName), 'w') as f:
startTimes = otable.cols.startTime[:]
for i in np.argsort(startTimes):
f.write("{0}\n".format((UTCDateTime(startTimes[i])+opt.ptrig).isoformat()))
示例5: printJunk
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def printJunk(jtable, opt):
"""
Prints flat catalog of contents of junk table to text file for debugging
jtable: Junk table
opt: Options object describing station/run parameters
Note: Time in text file corresponds to original STA/LTA trigger time
"""
with open('{}{}/junk.txt'.format(opt.outputPath, opt.groupName), 'w') as f:
startTimes = jtable.cols.startTime[:]
jtype = jtable.cols.isjunk[:]
for i in np.argsort(startTimes):
f.write("{0} - {1}\n".format((
UTCDateTime(startTimes[i])+opt.ptrig).isoformat(),jtype[i]))
示例6: test_check_adj_consistency
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def test_check_adj_consistency():
array = np.zeros(10)
adj1 = AdjointSource(
"cc_traveltime_misfit", 0, 1.0, 17, 40, "BHZ", adjoint_source=array,
network="II", station="AAK", location="",
starttime=UTCDateTime(1990, 1, 1))
adj2 = deepcopy(adj1)
sa.check_adj_consistency(adj1, adj2)
adj2 = deepcopy(adj1)
adj2.component = "HHZ"
with pytest.raises(ValueError) as errmsg:
sa.check_adj_consistency(adj1, adj2)
adj2 = deepcopy(adj1)
adj2.dt *= 2
with pytest.raises(ValueError) as errmsg:
sa.check_adj_consistency(adj1, adj2)
assert "DeltaT of current adjoint source" in str(errmsg)
adj2 = deepcopy(adj1)
adj2.starttime += 1
with pytest.raises(ValueError) as errmsg:
sa.check_adj_consistency(adj1, adj2)
assert "Start time of current adjoint source" in str(errmsg)
示例7: test_dump_adjsrc
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def test_dump_adjsrc():
array = np.array([1., 2., 3., 4., 5.])
adj = AdjointSource(
"cc_traveltime_misfit", 2.0, 1.0, 17, 40, "BHZ",
adjoint_source=array, network="II", station="AAK",
location="", starttime=UTCDateTime(1990, 1, 1))
station_info = {"latitude": 1.0, "longitude": 2.0, "depth_in_m": 3.0,
"elevation_in_m": 4.0}
adj_array, adj_path, parameters = sa.dump_adjsrc(adj, station_info)
npt.assert_array_almost_equal(adj_array, array)
for key in station_info:
npt.assert_almost_equal(station_info[key], parameters[key])
assert adj_path == "II_AAK_BHZ"
npt.assert_almost_equal(parameters["misfit"], 2.0)
npt.assert_almost_equal(parameters["dt"], 1.0)
npt.assert_almost_equal(parameters["min_period"], 17.0)
npt.assert_almost_equal(parameters["max_period"], 40.0)
assert parameters["adjoint_source_type"] == "cc_traveltime_misfit"
assert parameters["station_id"] == "II.AAK"
assert parameters["component"], "BHZ"
assert UTCDateTime(parameters["starttime"]) == UTCDateTime(1990, 1, 1)
assert parameters["units"] == "m"
示例8: test_load_to_adjsrc
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def test_load_to_adjsrc():
array = np.array([1., 2., 3., 4., 5.])
adj = AdjointSource(
"cc_traveltime_misfit", 2.0, 1.0, 17, 40, "BHZ",
adjoint_source=array, network="II", station="AAK",
location="", starttime=UTCDateTime(1990, 1, 1))
station_info = {"latitude": 1.0, "longitude": 2.0, "depth_in_m": 3.0,
"elevation_in_m": 4.0}
adj_array, adj_path, parameters = sa.dump_adjsrc(adj, station_info)
# ensemble a faked adjoint source from hdf5
hdf5_adj = namedtuple("HDF5Adj", ['data', 'parameters'])
hdf5_adj.data = array
hdf5_adj.parameters = parameters
# load and check
loaded_adj, loaded_station_info = sa.load_to_adjsrc(hdf5_adj)
adjoint_equal(loaded_adj, adj)
for k in station_info:
npt.assert_almost_equal(station_info[k], loaded_station_info[k])
assert loaded_station_info["station"] == "AAK"
assert loaded_station_info["network"] == "II"
assert loaded_station_info["location"] == ""
示例9: construct_3_component_adjsrc
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def construct_3_component_adjsrc(network="II", station="AAK", location=""):
array = np.array([1., 2., 3., 4., 5.])
adjz = AdjointSource(
"cc_traveltime_misfit", 2.0, 1.0, 40, 100, "MXZ",
adjoint_source=array, network=network, station=station,
location=location, starttime=UTCDateTime(1990, 1, 1))
adjr = deepcopy(adjz)
adjr.adjoint_source = 2 * array
adjr.component = "MXR"
adjt = deepcopy(adjz)
adjt.adjoint_source = 3 * array
adjt.component = "MXT"
return [adjr, adjt, adjz]
示例10: test_convert_adjs_to_trace
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def test_convert_adjs_to_trace():
array = np.array([1., 2., 3., 4., 5.])
starttime = UTCDateTime(1990, 1, 1)
adj = AdjointSource(
"cc_traveltime_misfit", 0, 1.0, 17, 40, "BHZ", adjoint_source=array,
network="II", station="AAK", location="",
starttime=starttime)
tr, meta = pa.convert_adj_to_trace(adj)
npt.assert_allclose(tr.data, array)
assert tr.stats.starttime == starttime
npt.assert_almost_equal(tr.stats.delta, 1.0)
assert tr.id == "II.AAK..BHZ"
assert meta["adj_src_type"] == "cc_traveltime_misfit"
npt.assert_almost_equal(meta["misfit"], 0.0)
npt.assert_almost_equal(meta["min_period"], 17.0)
npt.assert_almost_equal(meta["max_period"], 40.0)
示例11: test_convert_adjs_to_stream
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def test_convert_adjs_to_stream():
array = np.array([1., 2., 3., 4., 5.])
starttime = UTCDateTime(1990, 1, 1)
adjsrcs = get_sample_adjsrcs(array, starttime)
true_keys = ["II.AAK..BHZ", "II.AAK..BHR", "II.AAK..BHT"]
st, meta = pa.convert_adjs_to_stream(adjsrcs)
assert len(meta) == 3
keys = meta.keys()
assert set(keys) == set(true_keys)
for m in meta.itervalues():
assert m["adj_src_type"] == "cc_traveltime_misfit"
npt.assert_almost_equal(m["misfit"], 0.0)
npt.assert_almost_equal(m["min_period"], 17.0)
npt.assert_almost_equal(m["max_period"], 40.0)
for tr, trid in zip(st, true_keys):
assert tr.id == trid
npt.assert_allclose(tr.data, array)
npt.assert_almost_equal(tr.stats.delta, 1.0)
assert tr.stats.starttime == starttime
示例12: get_pdf
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def get_pdf(stream, sigma=0.1):
trace = stream[0]
start_time = trace.stats.starttime
x_time = trace.times(reftime=start_time)
stream.pdf = np.zeros([3008, 2])
stream.phase = []
for i, phase in enumerate(['P', 'S']):
if stream.picks.get(phase):
stream.phase.append(phase)
else:
stream.phase.append('')
continue
phase_pdf = np.zeros((len(x_time),))
for pick in stream.picks[phase]:
pick_time = UTCDateTime(pick.time) - start_time
pick_pdf = ss.norm.pdf(x_time, pick_time, sigma)
if pick_pdf.max():
phase_pdf += pick_pdf / pick_pdf.max()
stream.pdf[:, i] = phase_pdf
return stream
示例13: add_events_to_asdf_file
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def add_events_to_asdf_file(self, f):
cat = obspy.core.event.Catalog()
for key, res_id in self._events.items():
event = obspy.core.event.Event(
resource_id=res_id,
origins=[
obspy.core.event.Origin(
time=obspy.UTCDateTime(key[3]),
longitude=key[1],
latitude=key[0],
depth=key[2],
)
],
)
cat.append(event)
f.add_quakeml(cat)
示例14: _empty
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def _empty(self, w_beg, w_end):
"""
Create an empty set of arrays to write to .scanmseed ; used where there
is no data available to run _compute() .
Parameters
----------
w_beg : UTCDateTime object
Start time to create empty arrays
w_end : UTCDateTime object
End time to create empty arrays
Returns
-------
daten, max_coa, max_coa_norm, coord : array-like
Empty arrays with the correct shape to write to .scanmseed as if
they were coastream outputs from _compute()
"""
tmp = np.arange(w_beg + self.pre_pad,
w_end - self.post_pad + (1 / self.sampling_rate),
1 / self.sampling_rate)
daten = [x.datetime for x in tmp]
max_coa = max_coa_norm = np.full(len(daten), 0)
coord = np.full((len(daten), 3), 0)
return daten, max_coa, max_coa_norm, coord
示例15: write_coal4D
# 需要导入模块: import obspy [as 别名]
# 或者: from obspy import UTCDateTime [as 别名]
def write_coal4D(self, map_4d, event_name, start_time, end_time):
"""
Writes 4-D coalescence grid to a binary numpy file.
Parameters
----------
map_4d : array-like
4-D coalescence grid output by _compute()
event_name : str
event_id for file naming
start_time : UTCDateTime
start time of 4-D coalescence map
end_time : UTCDateTime
end time of 4-D coalescence map
"""
start_time = UTCDateTime(start_time)
end_time = UTCDateTime(end_time)
subdir = "4d_coal_grids"
util.make_directories(self.run, subdir=subdir)
filestr = "{}_{}_{}_{}".format(self.name, event_name, start_time,
end_time)
fname = self.run / subdir / filestr
fname = fname.with_suffix(".coal4D")
np.save(str(fname), map_4d)