本文整理汇总了Python中obspy.core.UTCDateTime方法的典型用法代码示例。如果您正苦于以下问题:Python core.UTCDateTime方法的具体用法?Python core.UTCDateTime怎么用?Python core.UTCDateTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core
的用法示例。
在下文中一共展示了core.UTCDateTime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_data
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def _load_data(seedid, day, data, data_format, key='data',
**prep_kw):
"""Load preprocessed or raw data"""
from obspy import UTCDateTime as UTC
from yam.util import _seedid2meta
from yam.correlate import get_data, preprocess
smeta = _seedid2meta(seedid)
day = UTC(day)
if key == 'data':
obj = get_data(smeta, data, data_format, day,
overlap=0, edge=0, trim_and_merge=True)
return obj
stream = get_data(smeta, data, data_format, day,
overlap=0, edge=60, trim_and_merge=False)
preprocess(stream, day, **prep_kw)
return stream
示例2: create_obs_network
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def create_obs_network(self):
obs_stations = self.read_stations()
if obs_stations:
obs_network = obspy.core.inventory.Network(
self.experiment_t[0]['net_code_s'])
obs_network.alternate_code = \
self.experiment_t[0]['experiment_id_s']
obs_network.description = self.experiment_t[0]['longname_s']
start_time, end_time = self.get_network_date()
obs_network.start_date = UTCDateTime(start_time)
obs_network.end_date = UTCDateTime(end_time)
obs_network.total_number_of_stations = self.total_number_stations
obs_network.stations = obs_stations
return obs_network
else:
return
示例3: output
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def output(self):
'''
Generate data wrapper for USGS geomagnetic data
@return geomagnetic data wrapper
'''
observatory_list = self.ap_paramList[0]()
# USGS Edge server
base_url = 'cwbpub.cr.usgs.gov'
factory = EdgeFactory(host=base_url, port=2060)
data_dict = OrderedDict()
for observatory in observatory_list:
ret_data = factory.get_timeseries( observatory=observatory,
interval=self.interval,
type=self.data_type,
channels=self.channels,
starttime=UTCDateTime(self.start_time),
endtime=UTCDateTime(self.end_time))
obs_data = OrderedDict()
for label, trace in zip(self.channels, ret_data):
time = pd.to_datetime(trace.stats['starttime'].datetime) + pd.to_timedelta(trace.times(),unit='s')
obs_data[label] = pd.Series(trace.data,time)
data_dict[observatory] = pd.DataFrame(obs_data)
return TableWrapper(data_dict, default_columns=self.channels)
示例4: _read_dict
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def _read_dict(group):
"""Read a single stretching dictionary from group"""
res = {'attrs': {}}
for key, val in group.attrs.items():
res['attrs'][key] = val
for key, val in group.items():
if key not in ('attrs'):
res[key] = val[:]
res['times'] = [UTC(t) for t in res['times']]
res['group'] = group.name
return res
示例5: _get_data_files
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def _get_data_files(data):
"""
Construct a glob expression from the data expression and return file names
"""
from obspy import UTCDateTime as UTC
kw = dict(network='*', station='*', location='*', channel='*',
t=UTC('2211-11-11 11:11:11'))
dataglob = data.format(**kw)
dataglob = dataglob.replace('22', '*').replace('11', '*')
fnames = glob.glob(dataglob)
return fnames
示例6: create_obs_station
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def create_obs_station(self, station_list, sta_code, array_name,
start_date, end_date, sta_longitude,
sta_latitude, sta_elevation, deployment):
obs_station = obspy.core.inventory.Station(sta_code,
latitude=sta_latitude,
longitude=sta_longitude,
start_date=start_date,
end_date=end_date,
elevation=sta_elevation)
obs_station.creation_date = UTCDateTime(station_list[deployment][0]
['deploy_time/epoch_l'])
obs_station.termination_date = UTCDateTime(station_list[deployment][0]
['pickup_time/epoch_l'])
extra = AttribDict({
'PH5Array': {
'value': str(array_name)[8:],
'namespace': self.manager.iris_custom_ns,
'type': 'attribute'
}
})
obs_station.extra = extra
obs_station.site = obspy.core.inventory.Site(
name=station_list[deployment][0]['location/description_s'])
return obs_station
示例7: fetch_usgs
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def fetch_usgs(out_path,
date,
stn,
type='variation',
interval='second',
he=False,
out_template='{stn}{date:%Y%m%d}v{suffix}.{suffix}'):
"""
Fetch USGS magnetometer data for *date* at *stn*. Store the data
in IAGA2002 format and return the file name (*out_template* serves
as a template). Limit to data *type* and *interval*. If *he*, then
include the H and E channels in the output (that is, local
magnetic north and east components).
"""
out_fname = os.path.join(out_path,
out_template.format(stn=stn.lower(),
date=date,
suffix=interval[:3]))
input_factory = geomagio.edge.EdgeFactory()
timeseries = input_factory.get_timeseries(
observatory = stn,
channels = ('H', 'E', 'Z', 'F'),
type = type,
interval = interval,
starttime = UTCDateTime('{date:%Y-%m-%d}T00:00:00Z'.format(date=date)),
endtime = UTCDateTime('{date:%Y-%m-%d}T23:59:59Z'.format(date=date)))
if all([NP.isnan(trace).all() for trace in timeseries.traces]):
raise ValueError('no data for {} on {:%Y-%m-%d} found'.format(stn, date))
# convert from HEZF channels to XYZF channels
algorithm = XYZAlgorithm(informat='obs', outformat='geo')
xyzf = algorithm.process(timeseries)
with open(out_fname, 'w') as fid:
output_factory = geomagio.iaga2002.IAGA2002Factory()
output_factory.write_file(
channels = ('H', 'E', 'X', 'Y', 'Z', 'F') if he else ('X', 'Y', 'Z', 'F'),
fh = fid,
timeseries = xyzf)
return out_fname
示例8: start_correlate
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def start_correlate(io,
filter_inventory=None,
startdate='1990-01-01', enddate='2020-01-01',
njobs=None,
keep_correlations=False,
stack='1d',
**kwargs):
"""
Start correlation
:param io: |io|
:param filter_inventory: filter inventory with its select method,
specified dict is passed to |Inventory.select|
:param str startdate,enddate: start and end date as strings
:param njobs: number of cores to use for computation, days are computed
parallel, this might consume much memory, default: None -- use all
available cores
:param keep_correlations,stack,\*\*kwargs: all other kwargs are passed to
`~yam.correlate.correlate()` function
"""
if filter_inventory:
log.debug('filter inventory')
io['inventory'] = io['inventory'].select(**filter_inventory)
log.info('start preprocessing and correlation')
tasks = list(IterTime(UTC(startdate), UTC(enddate)))
# check for existing days
# Not perfect yet:
# If a day exits for one combination and not for another station
# combination, it will be marked as done
done_tasks = None
if stack is not None:
key2 = kwargs['outkey'] + '_s' + stack
done_tasks = [UTC(t[-16:-6]) for t in
_get_existent(io['stack'], key2, 4)]
if keep_correlations:
key2 = kwargs['outkey']
done_tasks2 = [UTC(t[-16:-6]) for t in
_get_existent(io['corr'], key2, 4)]
if done_tasks is None:
done_tasks = done_tasks2
else:
done_tasks = [t for t in done_tasks if t in done_tasks2]
tasks = _todo_tasks(tasks, done_tasks)
kwargs.update({'keep_correlations': keep_correlations, 'stack': stack})
do_work = functools.partial(correlate, io, **kwargs)
start_parallel_jobs(tasks, do_work, _write_stream, njobs=njobs)
log.info('finished preprocessing and correlation')
示例9: load
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def load(io, key, seedid=None, day=None, do='return', prep_kw={},
fname=None, format=None):
"""
Load object and do something with it
:param io: io
:param key: key of object to load
(key inside HDF5 file, or one of data, prepdata, stations)
:param seedid: seed id of a channel (for data or prepdata)
:param day: |UTC| object with day (for data or prepdata)
:param do: specifies what to do with the object, default is ``'return'``
which simply returns the object, other possible values are
``'print'`` -- print object (used by print command),
``'load'`` -- load object in IPython session (used by load command),
``'export'`` -- export correlations to different file format
(used by export command)
:param dict prep_kw: options passed to preprocess (for prepdata only)
:param fname: file name (for export command)
:param format: target format (for export command)
"""
if key == 'stations':
obj = io['inventory']
elif key in ('data', 'prepdata'):
if seedid is None or day is None:
msg = 'seedid and day must be given for data or prepdata'
raise ParseError(msg)
if key == 'prepdata':
prep_keys = ('remove_response', 'remove_response_options',
'filter', 'normalization',
'time_norm_options', 'spectral_whitening_options',
'downsample')
prep_kw = {k: prep_kw.get(k) for k in prep_keys}
obj = _load_data(seedid, day, io['data'], io.get('data_format'),
key, inventory=io['inventory'], **prep_kw)
else:
is_stretch = 't' in _analyze_key(key)
fname_in = _get_fname(io, key)
if is_stretch:
obj = read_dicts(fname_in, key)
if do == 'print':
obj = '\n\n'.join(str(o) for o in obj)
else:
obj = obspy.read(fname_in, 'H5', group=key, headonly=do == 'print')
if do == 'print':
obj = obj.__str__(extended=True)
if do == 'print':
print(obj)
elif do == 'load':
_start_ipy(obj)
elif do == 'return':
return obj
elif do == 'export':
print(obj)
obspyh5.set_index()
obj.write(fname, format)
obspyh5.set_index(INDEX)
else:
raise
示例10: __init__
# 需要导入模块: from obspy import core [as 别名]
# 或者: from obspy.core import UTCDateTime [as 别名]
def __init__(self, network_list=None, reportnum_list=None,
station_list=None, location_list=None, channel_list=None,
component_list=None, receiver_list=None, array_list=None,
minlatitude=None, maxlatitude=None, minlongitude=None,
maxlongitude=None, latitude=None, longitude=None,
minradius=None, maxradius=None, start_time=None,
end_time=None):
self.network_list = network_list
self.reportnum_list = reportnum_list
self.station_list = station_list
self.location_list = location_list
self.channel_list = channel_list
self.component_list = component_list
self.receiver_list = receiver_list
self.array_list = array_list
self.minlatitude = minlatitude
self.maxlatitude = maxlatitude
self.minlongitude = minlongitude
self.maxlongitude = maxlongitude
self.latitude = latitude
self.longitude = longitude
self.minradius = minradius
self.maxradius = maxradius
self.start_time = start_time
self.end_time = end_time
self.ph5_station_id_list = [] # updated by PH5toStationXMLParser
# assign default values
if not self.network_list:
self.network_list = ["*"]
if not self.reportnum_list:
self.reportnum_list = ["*"]
if not self.station_list:
self.station_list = ["*"]
if not self.location_list:
self.location_list = ["*"]
if not self.channel_list:
self.channel_list = ["*"]
if not self.component_list:
self.component_list = ["*"]
if not self.receiver_list:
self.receiver_list = ["*"]
if not self.array_list:
self.array_list = ["*"]
if self.start_time:
self.start_time = UTCDateTime(start_time)
if self.end_time:
self.end_time = UTCDateTime(end_time)