本文整理汇总了Python中smtk.parsers.base_database_parser.get_float函数的典型用法代码示例。如果您正苦于以下问题:Python get_float函数的具体用法?Python get_float怎么用?Python get_float使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_float函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _parse_component_data
def _parse_component_data(self, wfid, proc_data):
"""
Parses the information for each component
"""
filter_params = {
'Type': proc_data['comp_ordered.filter_type'],
'Order': proc_data['comp_ordered.filter_order'],
'Passes': get_int(
proc_data['comp_ordered.filter_number_of_passes']),
'NRoll': get_int(proc_data['comp_ordered.nroll']),
'High-Cut': get_float(proc_data['comp_ordered.high_cut_freq']),
'Low-Cut': get_float(proc_data['comp_ordered.low_cut_freq'])}
intensity_measures = {
# All m - convert to cm
'PGA': get_float(proc_data['comp_ordered.pga']),
'PGV': get_float(proc_data['comp_ordered.pgv']),
'PGD': get_float(proc_data['comp_ordered.pgd'])
}
for imkey in intensity_measures.keys():
if intensity_measures[imkey]:
intensity_measures[imkey] = 100.0 * intensity_measures[imkey]
comp = Component(wfid,
proc_data['comp_ordered.orientation'],
ims=intensity_measures,
longest_period=None,
waveform_filter=filter_params,
baseline=proc_data['comp_ordered.baseline_correction'])
return comp
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:31,代码来源:sigma_database_parser.py
示例2: _parse_site_data
def _parse_site_data(self, metadata):
"""
Parses the site metadata. Coordinates in western hemisphere
are returned as negative values.
"""
try:
altitude = get_float(metadata["ALTITUD (msnm)"])
except:
altitude = 0
site = RecordSite(
"|".join([metadata["INSTITUCION RESPONSABLE"],
metadata["CLAVE DE LA ESTACION"]]),
metadata["CLAVE DE LA ESTACION"],
metadata["NOMBRE DE LA ESTACION"],
-get_float(metadata["COORDENADAS DE LA ESTACION"].split(" ")[3]),
get_float(metadata["COORDENADAS DE LA ESTACION"].split(" ")[0]),
altitude)
if "UNAM" in metadata["INSTITUCION RESPONSABLE"]:
site.network_code = "UNAM"
elif "CICESE" in metadata["INSTITUCION RESPONSABLE"]:
site.network_code = "CICESE"
else:
site.network_code = "unknown"
try:
site.morphology = metadata["TIPO DE SUELO"]
except:
site.morphology = None
site.instrument_type = metadata["MODELO DEL ACELEROGRAFO"]
return site
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:34,代码来源:asa_database_parser.py
示例3: _parse_focal_mechanism
def _parse_focal_mechanism(self, eq_id, eq_name, metadata):
"""
Parses the focal mechanism returning an instance of FocalMechanism
"""
nodal_planes = GCMTNodalPlanes()
nodal_planes.nodal_plane_1 = {
'strike': get_float(metadata['event.strike1']),
'dip': get_float(metadata['event.dip1']),
'rake': get_float(metadata['event.slip1'])
}
nodal_planes.nodal_plane_2 = {
'strike': get_float(metadata['event.strike2']),
'dip': get_float(metadata['event.dip2']),
'rake': get_float(metadata['event.slip2'])
}
principal_axes = GCMTPrincipalAxes()
principal_axes.t_axes = {
'eigenvalue': None,
'plunge': get_float(metadata['event.t_axes_plg']),
'azimuth': get_float(metadata['event.t_axes_az'])}
principal_axes.p_axes = {
'eigenvalue': None,
'plunge': get_float(metadata['event.p_axes_plg']),
'azimuth': get_float(metadata['event.p_axes_az'])}
principal_axes.b_axes = {
'eigenvalue': None,
'plunge': None,
'azimuth': None}
return FocalMechanism(eq_id, eq_name, nodal_planes, principal_axes,
mechanism_type=metadata['event.fault_mechanism.name'])
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:32,代码来源:sigma_database_parser.py
示例4: _parse_distance_data
def _parse_distance_data(self, metadata, file_str, eqk):
"""
Parses the event metadata to return an instance of the :class:
smtk.sm_database.RecordDistance. Coordinates in western hemisphere
are converted to negative values.
"""
epi_lon = -get_float(
metadata["COORDENADAS DEL EPICENTRO"].split(" ")[3])
epi_lat = get_float(
metadata["COORDENADAS DEL EPICENTRO"].split(" ")[0])
sta_lon = -get_float(
metadata["COORDENADAS DE LA ESTACION"].split(" ")[3])
sta_lat = get_float(
metadata["COORDENADAS DE LA ESTACION"].split(" ")[0])
p = Point(longitude=epi_lon, latitude=epi_lat)
repi = p.distance(Point(longitude=sta_lon, latitude=sta_lat))
# No hypocentral distance in file - calculate from event
rhypo = sqrt(repi ** 2. + eqk.depth ** 2.)
azimuth = Point(epi_lon, epi_lat, eqk.depth).azimuth(
Point(sta_lon, sta_lat))
dists = RecordDistance(repi, rhypo)
dists.azimuth = azimuth
return dists
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:28,代码来源:asa_database_parser.py
示例5: _parse_rupture
def _parse_rupture(self, eq_id, metadata):
"""
"""
return Rupture(eq_id,
get_float(metadata['event.fault_rupture_length']),
get_float(metadata['event.fault_rupture_width']),
get_float(metadata['event.fault_rupture_depth']))
开发者ID:luisera,项目名称:gmpe-smtk,代码行数:8,代码来源:sigma_database_parser.py
示例6: _parse_distance_data
def _parse_distance_data(self, metadata):
"""
Parses the distance data
"""
return RecordDistance(get_float(metadata['distance_repi']),
get_float(metadata['distance_rhyp']),
rjb = get_float(metadata['distance_rjb']),
rrup = get_float(metadata['distance_rrup']),
r_x = None,
flag = get_int(metadata['distance_flag']))
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:10,代码来源:sigma_database_parser.py
示例7: _build_spectra_hdf5_from_row
def _build_spectra_hdf5_from_row(self, output_file, row, periods,
scalar_fields, spectra_fields, component,
damping, units):
"""
"""
fle = h5py.File(output_file, "w-")
ts_grp = fle.create_group("Time Series")
ims_grp = fle.create_group("IMS")
h_grp = ims_grp.create_group("H")
scalar_grp = h_grp.create_group("Scalar")
# Create Scalar values
for f_attr, imt in scalar_fields:
dset = scalar_grp.create_dataset(imt, (1,), dtype="f")
dset.attrs["Component"] = component
input_units = re.search('\((.*?)\)', f_attr).group(1)
if imt == "PGA":
# Convert acceleration from reported units to cm/s/s
dset.attrs["Units"] = "cm/s/s"
dset[:] = utils.convert_accel_units(get_float(row[f_attr]),
input_units)
else:
# For other values take direct from spreadsheet
# Units should be given in parenthesis from fieldname
dset.attrs["Units"] = input_units
dset[:] = get_float(row[f_attr])
spectra_grp = h_grp.create_group("Spectra")
rsp_grp = spectra_grp.create_group("Response")
# Setup periods dataset
per_dset = rsp_grp.create_dataset("Periods",
(len(periods),),
dtype="f")
per_dset.attrs["High Period"] = np.max(periods)
per_dset.attrs["Low Period"] = np.min(periods)
per_dset.attrs["Number Periods"] = len(periods)
per_dset[:] = periods
# Get response spectra
spectra = np.array([get_float(row[f_attr])
for f_attr in spectra_fields])
acc_grp = rsp_grp.create_group("Acceleration")
comp_grp = acc_grp.create_group(component)
spectra_dset = comp_grp.create_dataset("damping_{:s}".format(damping),
(len(spectra),),
dtype="f")
spectra_dset.attrs["Units"] = "cm/s/s"
spectra_dset[:] = utils.convert_accel_units(spectra, units)
fle.close()
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:48,代码来源:sm_database_builder.py
示例8: parse_metadata
def parse_metadata(self, metadata, file_str):
"""
Parses the metadata dictionary
"""
# Waveform id
wfid = metadata['waveform_sourceid']
# Get event information
event = self._parse_event_data(metadata)
# Get distance information
distances = self._parse_distance_data(metadata)
# Get site data
site = self._parse_site_data(metadata)
# Get processing data
x_comp, y_comp, z_comp = self._parse_processing_data(wfid, metadata)
# Create and return record
rec_file = os.path.join(file_str + "/" + file_str)
return GroundMotionRecord(wfid,
[rec_file + self.XCOMP_STR,
rec_file + self.YCOMP_STR,
rec_file + self.ZCOMP_STR],
event,
distances,
site,
x_comp,
y_comp,
vertical=z_comp,
ims=None,
longest_period=get_float(metadata['up4horiz_components']),
spectra_file=[rec_file + self.XSPEC_STR,
rec_file + self.YSPEC_STR,
rec_file + self.ZSPEC_STR])
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:32,代码来源:sigma_database_parser.py
示例9: _parse_site_data
def _parse_site_data(self, metadata):
"""
Returns the site data as an instance of the :class:
smtk.sm_database.RecordSite
"""
site = RecordSite(metadata["Station Sequence Number"],
metadata["Station ID No."],
metadata["Station ID No."],
get_float(metadata["Station Longitude"]),
get_float(metadata["Station Latitude"]),
0.0, # Elevation data not given
get_float(metadata["Preferred Vs30 (m/s)"]),
network_code=metadata["Owner"])
site.nehrp = metadata["Preferred NEHRP Based on Vs30"]
site.vs30_measured_type = metadata["Measured/Inferred Class"]
if site.vs30_measured_type in ["0", "5"]:
site.vs30_measured = True
else:
site.vs30_measured = False
site.vs30_uncertainty = get_float(
metadata["Sigma of Vs30 (in natural log Units)"])
site.z1pt0 = get_float(metadata["Z1 (m)"])
site.z1pt5 = get_float(metadata["Z1.5 (m)"])
site.z2pt5 = get_float(metadata["Z2.5 (m)"])
# Implement default values for z1pt0 and z2pt5
if site.z1pt0 is None:
site.z1pt0 = rcfg.vs30_to_z1pt0_as08(site.vs30)
if site.z2pt5 is None:
site.z2pt5 = rcfg.z1pt0_to_z2pt5(site.z1pt0)
site.arc_location = metadata["Forearc/Backarc for subduction events"]
site.instrument_type = metadata["Type of Recording"]
return site
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:32,代码来源:simple_flatfile_parser.py
示例10: _parse_event_data
def _parse_event_data(self, metadata):
"""
"""
# Get datetime
if len(metadata['event.datetime']) > 20:
eq_datetime = datetime.strptime(metadata['event.datetime'],
"%Y-%m-%d %H:%M:%S.%f")
else:
eq_datetime = datetime.strptime(metadata['event.datetime'],
"%Y-%m-%d %H:%M:%S")
# Event ID and Name
if metadata['event.unid']:
eq_id = metadata['event.unid']
else:
eq_id = eq_datetime.isoformat()
eq_name = metadata['event.name']
# Get focal mechanism
focal_mech = self._parse_focal_mechanism(eq_id, eq_name, metadata)
# Get preferred magnitude
pref_mag = Magnitude(get_float(metadata['event.pref_mag']),
metadata['event.pref_mag_type'])
# Get magnitude list
mag_list = []
for kstr in ['0', '1', '2', '3', '4']:
mag_list.append(Magnitude(
get_float(metadata['event.magnitudes/' + kstr + '.value']),
metadata['event.magnitudes/' + kstr + '.magtype']))
eqk = Earthquake(eq_id, eq_name, eq_datetime,
get_float(metadata['event.longitude']),
get_float(metadata['event.latitude']),
get_float(metadata['event.focaldepth']),
pref_mag,
focal_mech,
metadata['event.country.name'])
eqk.magnitude_list = mag_list
# Get Rupture data
eqk.rupture = self._parse_rupture(eq_id, eq_name, pref_mag, metadata)
return eqk
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:42,代码来源:sigma_database_parser.py
示例11: _parse_site_data
def _parse_site_data(self, metadata):
"""
Parse the site data
"""
site = RecordSite(
metadata['station.oid'],
metadata['station.name'],
metadata['station.code'],
get_float(metadata['station.longitude']),
get_float(metadata['station.latitude']),
get_float(metadata['station.altitude']),
vs30=get_float(metadata['station.vs30']),
vs30_measured=get_int(metadata['station.vs30_measured']),
network_code=metadata['station.agency.name'],
country=metadata['station.country.name'])
site.vs30_measured_type = metadata['station.vs30_measured_type']
site.instrument_type = metadata['recording_type']
site.digitiser = metadata['digitalizer']
site.building_structure = metadata['station.building_struct.name']
site.number_floors = get_int(metadata['station.number_of_floor'])
site.floor = metadata['station.installed_on_floor']
site.ec8 = metadata['station.ec8']
return site
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:23,代码来源:sigma_database_parser.py
示例12: _get_focal_mechanism
def _get_focal_mechanism(self, eq_id, eq_name, metadata):
"""
Returns the focal mechanism information as an instance of the
:class: smtk.sigma_database.FocalMechanism
"""
nodal_planes = GCMTNodalPlanes()
strike = get_float(metadata["Strike (deg)"])
if strike is None:
strike = 0.0
dip = get_float(metadata["Dip (deg)"])
if dip is None:
dip = 90.0
nodal_planes.nodal_plane_1 = {
"strike": strike,
"dip": dip,
"rake": get_float(metadata["Rake Angle (deg)"])}
nodal_planes.nodal_plane2 = {"strike": None,
"dip": None,
"rake": None}
principal_axes = GCMTPrincipalAxes()
return FocalMechanism(eq_id, eq_name, nodal_planes, principal_axes,
mechanism_type=metadata["Mechanism Based on Rake Angle"])
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:23,代码来源:simple_flatfile_parser.py
示例13: _parse_distance_data
def _parse_distance_data(self, event, site, metadata):
"""
Read in the distance related metadata and return an instance of the
:class: smtk.sm_database.RecordDistance
"""
# Compute various distance metrics
# Add calculation of Repi, Rhypo from event and station localizations
# (latitudes, longitudes, depth, elevation)?
target_site = Mesh(np.array([site.longitude]),
np.array([site.latitude]),
np.array([-site.altitude / 1000.0]))
# Warning ratio fixed to 1.5
ratio=1.5
surface_modeled = rcfg.create_planar_surface(
Point(event.longitude, event.latitude, event.depth),
event.mechanism.nodal_planes.nodal_plane_1['strike'],
event.mechanism.nodal_planes.nodal_plane_1['dip'],
event.rupture.area,
ratio)
hypocenter = rcfg.get_hypocentre_on_planar_surface(
surface_modeled,
event.rupture.hypo_loc)
# Rhypo
Rhypo = get_float(metadata["Hypocentral Distance (km)"])
if Rhypo is None:
Rhypo = hypocenter.distance_to_mesh(target_site)
# Repi
Repi = get_float(metadata["Epicentral Distance (km)"])
if Repi is None:
Repi= hypocenter.distance_to_mesh(target_site, with_depths=False)
# Rrup
Rrup = get_float(metadata["Rupture Distance (km)"])
if Rrup is None:
Rrup = surface_modeled.get_min_distance(target_site)
# Rjb
Rjb = get_float(metadata["Joyner-Boore Distance (km)"])
if Rjb is None:
Rjb = surface_modeled.get_joyner_boore_distance(target_site)
# Need to check if Rx and Ry0 are consistant with the other metrics
# when those are coming from the flatfile?
# Rx
Rx = surface_modeled.get_rx_distance(target_site)
# Ry0
Ry0 = surface_modeled.get_ry0_distance(target_site)
distance = RecordDistance(
repi = float(Repi),
rhypo = float(Rhypo),
rjb = float(Rjb),
rrup = float(Rrup),
r_x = float(Rx),
ry0 = float(Ry0))
distance.azimuth = get_float(metadata["Source to Site Azimuth (deg)"])
distance.hanging_wall = get_float(metadata["FW/HW Indicator"])
return distance
开发者ID:preinh,项目名称:gmpe-smtk,代码行数:56,代码来源:simple_flatfile_parser_sara.py
示例14: _sanitise
def _sanitise(self, row, reader):
"""
If all of the strong motion values are negative the record is null
and should be removed
"""
iml_vals = []
for fname in reader.fieldnames:
if fname.startswith("SA(") or fname in SCALAR_LIST:
# Ground motion value
iml = get_float(row[fname])
if iml:
iml_vals.append(iml)
else:
iml_vals.append(-999.0)
# If all ground motion values are negative then the record is null
# return false
if np.all(np.array(iml_vals) < 0.0):
return False
else:
return True
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:20,代码来源:general_flatfile_parser.py
示例15: _parse_processing_data
def _parse_processing_data(self, wfid, metadata):
"""
Parses the information for each component
"""
filter_params1 = {
'Type': FILTER_TYPE[metadata["Type of Filter"]] ,
'Order': None,
'Passes': get_int(metadata['npass']),
'NRoll': get_int(metadata['nroll']),
'High-Cut': get_float(metadata["LP-H1 (Hz)"]),
'Low-Cut': get_float(metadata["HP-H1 (Hz)"])}
filter_params2 = {
'Type': FILTER_TYPE[metadata["Type of Filter"]] ,
'Order': None,
'Passes': get_int(metadata['npass']),
'NRoll': get_int(metadata['nroll']),
'High-Cut': get_float(metadata["LP-H2 (Hz)"]),
'Low-Cut': get_float(metadata["HP-H2 (Hz)"])}
intensity_measures = {
# All m - convert to cm
'PGA': None,
'PGV': None,
'PGD': None
}
lup1 = 1. / get_float(metadata["Lowest Usable Freq - H1 (Hz)"])
lup2 = 1. / get_float(metadata["Lowest Usable Freq - H2 (Hz)"])
xcomp = Component(wfid, "1",
ims=intensity_measures,
longest_period=lup1,
waveform_filter=filter_params1,
units=metadata["Unit"])
ycomp = Component(wfid, "2",
ims=intensity_measures,
longest_period=lup2,
waveform_filter=filter_params2,
units=metadata["Unit"])
return xcomp, ycomp, None
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:39,代码来源:simple_flatfile_parser.py
示例16: _parse_distance_data
def _parse_distance_data(self, event, site, metadata):
"""
Read in the distance related metadata and return an instance of the
:class: smtk.sm_database.RecordDistance
"""
# Compute various distance metrics
# Add calculation of Repi, Rhypo from event and station localizations
# (latitudes, longitudes, depth, elevation)?
target_site = Mesh(np.array([site.longitude]),
np.array([site.latitude]),
np.array([-site.altitude / 1000.0]))
# Warning ratio fixed to 1.5
ratio=1.5
if not event.rupture.area:
event.rupture.area = WC1994().get_median_area(event.magnitude.value,
None)
surface_modeled = rcfg.create_planar_surface(
Point(event.longitude, event.latitude, event.depth),
event.mechanism.nodal_planes.nodal_plane_1['strike'],
event.mechanism.nodal_planes.nodal_plane_1['dip'],
event.rupture.area,
ratio)
hypocenter = rcfg.get_hypocentre_on_planar_surface(
surface_modeled,
event.rupture.hypo_loc)
try:
surface_modeled._create_mesh()
except:
dip = surface_modeled.get_dip()
dip_dir = (surface_modeled.get_strike() - 90.) % 360.
ztor = surface_modeled.top_left.depth
d_x = ztor * np.tan(np.radians(90.0 - dip))
top_left_surface = surface_modeled.top_left.point_at(d_x,
-ztor,
dip_dir)
top_left_surface.depth = 0.
top_right_surface = surface_modeled.top_right.point_at(d_x,
-ztor,
dip_dir)
top_right_surface.depth = 0.
surface_modeled = SimpleFaultSurface.from_fault_data(
Line([top_left_surface, top_right_surface]),
surface_modeled.top_left.depth,
surface_modeled.bottom_left.depth,
surface_modeled.get_dip(),
1.0)
# Rhypo
Rhypo, Repi, Rrup, Rjb, Ry0 = tuple(map(
get_positive_float, [metadata[key] for key in [
"Hypocentral Distance (km)", "Epicentral Distance (km)",
"Rupture Distance (km)", "Joyner-Boore Distance (km)",
"Ry0 (km)"]]))
Rx = get_float(metadata["Rx (km)"]) # Rx can be negative
#Rhypo = get_float(metadata["Hypocentral Distance (km)"])
if Rhypo is None or Rhypo < 0.0:
Rhypo = hypocenter.distance_to_mesh(target_site)
# Repi
#Repi = get_float(metadata["Epicentral Distance (km)"])
if Repi is None or Repi < 0.0:
Repi= hypocenter.distance_to_mesh(target_site, with_depths=False)
# Rrup
#Rrup = get_float(metadata["Rupture Distance (km)"])
if Rrup is None or Rrup < 0.0:
Rrup = surface_modeled.get_min_distance(target_site)[0]
# Rjb
#Rjb = get_float(metadata["Joyner-Boore Distance (km)"])
if Rjb is None or Rjb < 0.0:
Rjb = surface_modeled.get_joyner_boore_distance(
target_site)[0]
# Need to check if Rx and Ry0 are consistant with the other metrics
# when those are coming from the flatfile?
# Rx
#Rx = get_float(metadata["Rx (km)"])
if Rx is None or Rx < 0.0:
Rx = surface_modeled.get_rx_distance(target_site)[0]
# Ry0
Ry0 = get_float(metadata["Ry0 (km)"])
if Ry0 is None or Ry0 < 0.0:
Ry0 = surface_modeled.get_ry0_distance(target_site)[0]
distance = RecordDistance(
repi = Repi,
rhypo = Rhypo,
rjb = Rjb,
rrup = Rrup,
r_x = Rx,
ry0 = Ry0)
distance.azimuth = get_float(metadata["Source to Site Azimuth (deg)"])
#distance.hanging_wall = get_float(metadata["FW/HW Indicator"])
if metadata["FW/HW Indicator"] == "HW":
distance.hanging_wall = True
elif metadata["FW/HW Indicator"] == "FW":
distance.hanging_wall = False
else:
pass
return distance
#.........这里部分代码省略.........
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:101,代码来源:general_flatfile_parser.py
示例17: _parse_time_history
def _parse_time_history(self, ifile, component2parse):
"""
Parses the time history and returns the time history of the specified
component. All 3 components are provided in every ASA file. Note that
components are defined with various names, and are not always
given in the same order
"""
# The components are definied using the following names
comp_names = {'X': ['ENE', 'N90E', 'N90E;', 'N90W', 'N90W;',
'S90E', 'S90W', 'E--W', 'S9OE'],
'Y': ['ENN', 'N00E', 'N00E;', 'NOOE;', 'N00W',
'NOOW;', 'S00E', 'S00W', 'N--S', 'NOOE'],
'V': ['ENZ', 'V', 'V;+', '+V', 'Z', 'VERT']}
# Read component names, which are given on line 107
o = open(ifile, "r", encoding='iso-8859-1')
r = o.readlines()
components = list(r[107].split())
# Check if any component names are repeated
if any(components.count(x) > 1 for x in components):
raise ValueError(
"Some components %s in record %s have the same name"
% (components, ifile))
# Check if more than 3 components are given
if len(components) > 3:
raise ValueError(
"More than 3 components %s in record %s"
% (components, ifile))
# Get acceleration data from correct column
column = None
for i in comp_names[component2parse]:
if i == components[0]:
column = 0
try:
accel = np.genfromtxt(ifile, skip_header=109,
usecols=column, delimiter='', encoding='iso-8859-1')
except:
raise ValueError(
"Check %s has 3 equal length time-series columns"
% ifile)
break
elif i == components[1]:
column = 1
try:
accel = np.genfromtxt(ifile, skip_header=109,
usecols=column, delimiter='', encoding='iso-8859-1')
except:
raise ValueError(
"Check %s has 3 equal length time-series columns"
% ifile)
break
elif i == components[2]:
column = 2
try:
accel = np.genfromtxt(ifile, skip_header=109,
usecols=column, delimiter='', encoding='iso-8859-1')
except:
raise ValueError(
"Check %s has 3 equal length time-series columns"
% ifile)
break
if column is None:
raise ValueError(
"None of the components %s were found to be \n\
the %s component of file %s" %
(components, component2parse, ifile))
# Build the metadata dictionary again
metadata = _get_metadata_from_file(ifile)
# Get units
units_provided = metadata["UNIDADES DE LOS DATOS"]
units = units_provided[units_provided.find("(") + 1:
units_provided.find(")")]
# Get time step, naming is not consistent so allow for variation
for i in metadata:
if 'INTERVALO DE MUESTREO, C1' in i:
self.time_step = get_float(metadata[i].split("/")[1])
# Get number of time steps, use len(accel) because
# sometimes "NUM. TOTAL DE MUESTRAS, C1-C6" is wrong
self.number_steps = len(accel)
output = {
"Acceleration": convert_accel_units(accel, self.units),
"Time": get_time_vector(self.time_step, self.number_steps),
"Time-step": self.time_step,
"Number Steps": self.number_steps,
"Units": self.units,
"PGA": max(abs(accel)),
"PGD": None
}
return output
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:98,代码来源:asa_database_parser.py
示例18: _parse_event
def _parse_event(self, metadata, file_str):
"""
Parses the event metadata to return an instance of the :class:
smtk.sm_database.Earthquake. Coordinates in western hemisphere
are returned as negative values.
"""
months = {'ENERO': 1, 'FEBRERO': 2, 'MARZO': 3, 'ABRIL': 4, 'MAYO': 5,
'JUNIO': 6, 'JULIO': 7, 'AGOSTO': 8, 'SEPTIEMBRE': 9,
'OCTUBURE': 10, 'NOVIEMBRE': 11, 'DICIEMBRE': 12}
months_abrev = {'ENE': 1, 'FEB': 2, 'MAR': 3, 'ABR': 4, 'MAY': 5,
'JUN': 6, 'JUL': 7, 'AGO': 8, 'SEP': 9,
'OCT': 10, 'NOV': 11, 'DIC': 12}
# Date and time
if 'CICESE' in metadata["INSTITUCION RESPONSABLE"]:
year, month, day = (
get_int(metadata["FECHA DEL SISMO (GMT)"][-4:]),
months[metadata["FECHA DEL SISMO (GMT)"].split()[2]],
get_int(metadata["FECHA DEL SISMO (GMT)"][:2]))
elif 'CIRES' in metadata["INSTITUCION RESPONSABLE"]:
year, month, day = (
get_int('20'+metadata["FECHA DEL SISMO (GMT)"][-2:]),
months_abrev[metadata["FECHA DEL SISMO (GMT)"].split('/')[1]],
get_int(metadata["FECHA DEL SISMO (GMT)"][:2]))
# UNAM data, which is not always indicated in "INSTITUCION RESPONSABLE"
else:
year, month, day = (
get_int(metadata["FECHA DEL SISMO [GMT]"].split("/")[0]),
get_int(metadata["FECHA DEL SISMO [GMT]"].split("/")[1]),
get_int(metadata["FECHA DEL SISMO [GMT]"].split("/")[2]))
# Get event time, naming is not consistent (e.g. 07.1, 00, 17,1)
for i in metadata:
if 'HORA EPICENTRO (GMT)' in i:
hour, minute, second = (get_int(metadata[i].split(":")[0]),
get_int(metadata[i].split(":")[1]),
int(float(metadata[i].split(":")[2].
replace("0", "", 1).
replace(",", "."))))
try:
eq_datetime = datetime(year, month, day, hour, minute, second)
except:
raise ValueError("Record %s is missing event time" % file_str)
# Event ID - No EVID, so use the date and time of the event
eq_id = str(eq_datetime).replace(" ", "_")
# Event Name
eq_name = None
# Get magnitudes, below are the different types given in ASA files
moment_mag = None
surface_mag = None
body_mag = None
c_mag = None
l_mag = None
e_mag = None
a_mag = None
m_mag = None
mag_list = []
mag = metadata["MAGNITUD(ES)"].split("/")
for i in range(0, len(mag)):
if mag[i][0:2] == "":
continue
if mag[i][0:2] == "Mw":
m_w = get_float(mag[i][3:])
moment_mag = Magnitude(m_w, "Mw")
mag_list.append(moment_mag)
if mag[i][0:2] == "Ms":
m_s = get_float(mag[i][3:])
surface_mag = Magnitude(m_s, "Ms")
mag_list.append(surface_mag)
if mag[i][0:2] == "Mb":
m_b = get_float(mag[i][3:])
body_mag = Magnitude(m_b, "Mb")
mag_list.append(body_mag)
if mag[i][0:2] == "Mc":
m = get_float(mag[i][3:])
c_mag = Magnitude(m, "Mc")
mag_list.append(c_mag)
if mag[i][0:2] == "Ml":
m = get_float(mag[i][3:])
l_mag = Magnitude(m, "Ml")
mag_list.append(l_mag)
if mag[i][0:2] == "Me" or mag[i][0:2] == "ME":
m = get_float(mag[i][3:])
e_mag = Magnitude(m, "Me")
mag_list.append(e_mag)
if mag[i][0:2] == "Ma":
m = get_float(mag[i][3:])
a_mag = Magnitude(m, "Ma")
mag_list.append(a_mag)
if mag[i][0:2] == "M=":
m = get_float(mag[i][2:])
m_mag = Magnitude(m, "M")
mag_list.append(m_mag)
#.........这里部分代码省略.........
开发者ID:GEMScienceTools,项目名称:gmpe-smtk,代码行数:101,代码来源:asa_database_parser.py
示例19: _parse_event_data
def _parse_event_data(self, metadata):
"""
Read in the distance related metadata and return an instance of the
:class: smtk.sm_database.Earthquake
"""
metadata["MODY"] = metadata["MODY"].zfill(4)
metadata["HRMN"] = metadata["HRMN"].zfill(4)
# Date and Time
year = get_int(metadata["YEAR"])
month = get_int(metadata["MODY"][:2])
day = get_int(metadata["MODY"][2:])
hour = get_int(metadata["HRMN"][:2])
minute = get_int(metadata["HRMN"][2:])
eq_datetime = datetime(year, month, day, hour, minute)
# Event ID and Name
eq_id = metadata["EQID"]
eq_name = metadata["Earthquake Name"]
# Focal Mechanism
focal_mechanism = self._get_focal_mechanism(eq_id, eq_name, metadata)
focal_mechanism.scalar_moment = get_float(metadata["Mo (dyne.cm)"]) *\
1E-7
# Read magnitude
pref_mag = Magnitude(get_float(metadata["Earthquake Magnitude"]),
metadata["Magnitude Type"],
sigma=get_float(metadata["Uncertainty"]))
# Create Earthquake Class
eqk = Earthquake(eq_id, eq_name, eq_datetime,
get_float(metadata["Hypocenter Longitude (deg)"]),
get_float(metadata["Hypocenter Latitude (deg)"]),
get_float(metadata["Hypocenter Depth (km)"]),
pref_mag,
focal_mechanism,
metadata["Country"])
hypo_loc = (0.5, 0.7) # Hypocentre Location
msr=WC1994()
# Warning rake set to 0.0 in scaling relationship
area = msr.get_median_area(pref_mag.value,0.0)
aspect_ratio = 1.5 # Assumed Fixed
width_model = np.sqrt(area / aspect_ratio)
length_model = aspect_ratio * width_model
ztor_model = eqk.depth - width_model / 2.
if ztor_model < 0:
ztor_model = 0.0
length = get_float(metadata["Fault Rupture Length (km)"])
if length is None:
length = length_model
width = get_float(metadata["Fault Rupture Width (km)"])
if width is None:
width = width_model
ztor = get_float(metadata["Depth to Top Of Fault Rupture Model"])
if ztor is None:
ztor=ztor_model
# Rupture
eqk.rupture = Rupture(eq_id,
eq_name,
pref_mag,
length,
width,
ztor)
# get_float(metadata["Fault Rupture Length (km)"]),
# get_float(metadata["Fault Rupture Width (km)"]),
# get_float(metadata["Depth to Top Of Fault Rupture Model"]))
eqk.rupture.get_area()
return eqk
开发者ID:g-weatherill,项目名称:gmpe-smtk,代码行数:66,代码来源:simple_flatfile_parser.py
注:本文中的smtk.parsers.base_database_parser.get_float函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论