# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
return guess_azimuth_from_name(channel_name), \ guess_dip_from_name(channel_name)
num.dot(enus[0], enus[1]), num.dot(enus[1], enus[2]), num.dot(enus[2], enus[0])])
# holy camoly.. enus[0] = mkvec(1, 0, 0) enus[1] = mkvec(0, 1, 0) enus[2] = mkvec(0, 0, 1)
self, name=name, azimuth=float_or_none(azimuth), dip=float_or_none(dip), gain=float(gain))
def ned(self): if None in (self.azimuth, self.dip): return None
n = math.cos(self.azimuth*d2r)*math.cos(self.dip*d2r) e = math.sin(self.azimuth*d2r)*math.cos(self.dip*d2r) d = math.sin(self.dip*d2r) return mkvec(n, e, d)
def enu(self): return None
def __str__(self): return '%s %f %f %g' % (self.name, self.azimuth, self.dip, self.gain)
lat=0.0, lon=0.0, elevation=0.0, depth=0.0, north_shift=0.0, east_shift=0.0, name='', channels=None):
self, network=network, station=station, location=location, lat=float(lat), lon=float(lon), elevation=float(elevation), depth=float(depth), north_shift=float(north_shift), east_shift=float(east_shift), name=name or '', channels=channels or [])
return copy.deepcopy(self)
if event.depth is None: logger.warn('No event depth given: using 0 m.') dd = 0.0 - self.depth else: dd = event.depth - self.depth
self.dist_m = math.sqrt(dd**2 + surface_dist**2) else:
orthodrome.r2d
return set(ch.name for ch in self.channels)
self.channels.remove(ch)
angle = wrap(self.backazimuth + 180., -180., 180.) in_channels = [self.get_channel(name) for name in in_channel_names] out_channels = [ Channel(out_channel_names[0], wrap(self.backazimuth+180., -180., 180.), 0., 1.), Channel(out_channel_names[1], wrap(self.backazimuth+270., -180., 180.), 0., 1.)] return angle, in_channels, out_channels
self, to, in_channel_names, out_channel_names, use_gains=False):
# create orthogonal vectors for missing components, such that this # won't break projections when components are missing.
else: vec /= ch.gain
raise ChannelsNotOrthogonal( 'components are not orthogonal: station %s.%s.%s, ' 'channels %s, %s, %s' % (self.nsl() + tuple(in_channel_names)))
out_channels = [ Channel(out_channel_names[0], 0., 0., 1.), Channel(out_channel_names[1], 90., 0., 1.), Channel(out_channel_names[2], 0., 90., 1.)]
Channel(out_channel_names[0], 90., 0., 1.), Channel(out_channel_names[1], 0., 0., 1.), Channel(out_channel_names[2], 0., -90., 1.)]
cg, out_channels=out_channels, **kwargs))
except ChannelsNotOrthogonal as e: logger.warning(str(e))
self, out_channels=('R', 'T', 'U'), backazimuth=None, **kwargs):
Channel( out_channels[0], wrap(backazimuth+180., -180., 180.), 0., 1.), Channel( out_channels[1], wrap(backazimuth+270., -180., 180.), 0., 1.), Channel( out_channels[2], 0., -90., 1.)]
[math.cos(phi), -math.sin(phi), 0.0], [0.0, 0.0, 1.0]])
self, in_channels, out_channels=('E', 'N', 'U'), **kwargs):
self, in_channels, out_channels=('N', 'E', 'D'), **kwargs):
return self._projection_to('ned', in_channels, out_channels, **kwargs)
self, in_channels=('E', 'N', 'U'), out_channels=('X', 'Y', 'Z'), **kwargs):
m, out_channels, in_channels = self._projection_to( 'enu', out_channels, in_channels, **kwargs)
return num.linalg.inv(m), in_channels, out_channels
self, in_channels=('N', 'E', 'D'), out_channels=('X', 'Y', 'Z'), **kwargs):
m, out_channels, in_channels = self._projection_to( 'ned', out_channels, in_channels, **kwargs)
return num.linalg.inv(m), in_channels, out_channels
return '.'.join((self.network, self.station, self.location))
logger.warn( 'Station %s.%s.%s has a non-zero Cartesian offset. Such ' 'offsets cannot be saved in the basic station file format. ' 'Effective lat/lons are saved only. Please save the stations ' 'in YAML format to preserve the reference-and-offset ' 'coordinates.' % self.nsl())
nsl, self.effective_lat, self.effective_lon, self.elevation, self.depth, self.name)
'''Write stations file.
:param stations: list of :py:class:`Station` objects :param filename: filename as str '''
cha.name, azimuth, dip, cha.gain))
'''Write stations file in YAML format.
:param stations: list of :py:class:`Station` objects :param filename: filename as str '''
dump_all(stations, filename=filename)
return None else:
continue return 'yaml' else:
return 'basic'
'''Read stations file.
:param filename: filename :returns: list of :py:class:`Station` objects '''
from pyrocko import guts stations = [ st for st in guts.load_all(filename=filename) if isinstance(st, Station)]
return stations
continue
else: name = toks[5].rstrip()
net, sta, loc, lat, lon, elevation=elevation, depth=depth, name=name)
toks[0], float_or_none(toks[1]), float_or_none(toks[2]), float(toks[3])) logger.warning( 'redefined channel! (line: %i, file: %s)' % (iline + 1, filename)) else:
else: logger.warning('skipping invalid station/channel definition ' '(line: %i, file: %s' % (iline + 1, filename))
else: from pyrocko.io.io_common import FileLoadError raise FileLoadError('unknown event file format: %s' % format)
station_template = ''' <Placemark> <name>%(network)s.%(station)s.%(location)s</name> <description></description> <styleUrl>#msn_S</styleUrl> <Point> <coordinates>%(elon)f,%(elat)f,%(elevation)f</coordinates> </Point> </Placemark> '''
f = open(filename, 'w') f.write('<?xml version="1.0" encoding="UTF-8"?>\n') f.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n') f.write('<Document>\n') f.write(''' <Style id="sh_S"> <IconStyle> <scale>1.3</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/paddle/S.png</href> </Icon> <hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/> </IconStyle> <ListStyle> <ItemIcon> <href>http://maps.google.com/mapfiles/kml/paddle/S-lv.png</href> </ItemIcon> </ListStyle> </Style> <Style id="sn_S"> <IconStyle> <scale>1.1</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/paddle/S.png</href> </Icon> <hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/> </IconStyle> <ListStyle> <ItemIcon> <href>http://maps.google.com/mapfiles/kml/paddle/S-lv.png</href> </ItemIcon> </ListStyle> </Style> <StyleMap id="msn_S"> <Pair> <key>normal</key> <styleUrl>#sn_S</styleUrl> </Pair> <Pair> <key>highlight</key> <styleUrl>#sh_S</styleUrl> </Pair> </StyleMap> ''') for obj in objects:
if isinstance(obj, Station): d = obj.__dict__.copy() d['elat'], d['elon'] = obj.effective_latlon f.write(station_template % d)
f.write('</Document>') f.write('</kml>\n') f.close() |