Beispiel #1
0
def test_meca_spec_1d_array():
    """
    Test supplying a 1D numpy array containing focal mechanisms and locations
    to the spec parameter.
    """
    fig = Figure()
    # supply focal mechanisms to meca as a 1D numpy array, here we are using
    # the Harvard CMT zero trace convention but the focal mechanism
    # parameters may be specified any of the available conventions. Since we
    # are not using a dict or dataframe the convention and component should
    # be specified.
    focal_mechanism = [
        -127.40,  # longitude
        40.87,  # latitude
        12,  # depth
        -3.19,  # mrr
        0.16,  # mtt
        3.03,  # mff
        -1.02,  # mrt
        -3.93,  # mrf
        -0.02,  # mtf
        23,  # exponent
        0,  # plot_lon, 0 to plot at event location
        0,  # plot_lat, 0 to plot at event location
    ]
    focal_mech_array = np.asarray(focal_mechanism)
    fig.meca(
        focal_mech_array,
        convention="mt",
        component="full",
        region=[-128, -127, 40, 41],
        scale="2c",
        projection="M14c",
    )
    return fig
Beispiel #2
0
def test_meca_loc_array():
    """
    Test supplying lists and np.ndarrays as the event location (longitude,
    latitude, and depth).
    """
    fig = Figure()
    # specify focal mechanisms
    focal_mechanisms = dict(strike=[327, 350],
                            dip=[41, 50],
                            rake=[68, 90],
                            magnitude=[3, 2])
    # longitude, latitude, and depth may be specified as an int, float,
    # list, or 1d numpy array
    longitude = np.array([-123.3, -124.4])
    latitude = np.array([48.4, 48.2])
    depth = [12.0, 11.0]  # to test mixed data types as inputs
    scale = "2c"
    fig.meca(
        focal_mechanisms,
        scale,
        longitude,
        latitude,
        depth,
        region=[-125, -122, 47, 49],
        projection="M14c",
    )
    return fig
Beispiel #3
0
def test_meca_gcmt_convention():
    """
    Test plotting beachballs using the global CMT convention.
    """
    fig = Figure()
    # specify focal mechanisms
    focal_mechanisms = dict(
        strike1=180,
        dip1=18,
        rake1=-88,
        strike2=0,
        dip2=72,
        rake2=-90,
        mantissa=5.5,
        exponent=0,
    )
    fig.meca(
        spec=focal_mechanisms,
        scale="1c",
        longitude=239.384,
        latitude=34.556,
        depth=12,
        convention="gcmt",
        region=[239, 240, 34, 35.2],
        projection="m2.5c",
        frame=True,
    )
    return fig
Beispiel #4
0
def test_meca_spec_file():
    """
    Test supplying a file containing focal mechanisms and locations to the
    `spec` argument.
    """

    fig = Figure()

    focal_mechanism = [-127.43, 40.81, 12, -3.19, 1.16, 3.93, -1.02, -3.93, -1.02, 23]

    # writes temp file to pass to gmt
    with GMTTempFile() as temp:
        with open(temp.name, mode="w") as temp_file:
            temp_file.write(" ".join([str(x) for x in focal_mechanism]))
        # supply focal mechanisms to meca as a file
        fig.meca(
            temp.name,
            convention="mt",
            component="full",
            region=[-128, -127, 40, 41],
            scale="2c",
            projection="M14c",
        )

    return fig
Beispiel #5
0
def test_meca_spec_dataframe():
    """
    Test supplying a pandas DataFrame containing focal mechanisms and locations
    to the `spec` argument.
    """

    fig = Figure()

    # supply focal mechanisms to meca as a dataframe
    focal_mechanisms = dict(
        strike=[324, 353],
        dip=[20.6, 40],
        rake=[83, 90],
        magnitude=[3.4, 2.9],
        longitude=[-124, -124.4],
        latitude=[48.1, 48.2],
        depth=[12, 11.0],
    )
    spec_dataframe = pd.DataFrame(data=focal_mechanisms)

    fig.meca(spec_dataframe,
             region=[-125, -122, 47, 49],
             scale="2c",
             projection="M14c")

    return fig
Beispiel #6
0
def test_meca_spec_dict_list():
    """
    Test supplying a dictionary containing a list of focal mechanism to the
    `spec` argument.
    """

    fig = Figure()

    # supply focal mechanisms as a dict of lists
    focal_mechanisms = dict(strike=[330, 350],
                            dip=[30, 50],
                            rake=[90, 90],
                            magnitude=[3, 2])

    fig.meca(
        focal_mechanisms,
        longitude=[-124.3, -124.4],
        latitude=[48.1, 48.2],
        depth=[12.0, 11.0],
        region=[-125, -122, 47, 49],
        scale="2c",
        projection="M14c",
    )

    return fig
Beispiel #7
0
def test_meca_spec_dictionary():
    """
    Test supplying a dictionary containing a single focal mechanism to the spec
    parameter.
    """
    fig = Figure()
    # Right lateral strike slip focal mechanism
    fig.meca(
        dict(strike=0, dip=90, rake=0, magnitude=5),
        longitude=0,
        latitude=5,
        depth=0,
        scale="2.5c",
        region=[-1, 1, 4, 6],
        projection="M14c",
        frame=2,
    )
    return fig
Beispiel #8
0
def test_meca_spec_2d_array():
    """
    Test supplying a 2D numpy array containing focal mechanisms and
    locations to the `spec` argument.
    """

    fig = Figure()

    # supply focal mechanisms to meca as a 2D numpy array, here we are using
    # the GCMT convention but the focal mechanism parameters may be
    # specified any of the available conventions. Since we are not using a
    # dict or dataframe the convention and component should be specified.
    focal_mechanisms = [
        [
            -127.40,  # longitude
            40.87,  # latitude
            12,  # depth
            170,  # strike1
            20,  # dip1
            -110,  # rake1
            11,  # strike2
            71,  # dip2
            -83,  # rake2
            5.1,  # mantissa
            23,  # exponent
            0,  # plot_lon, 0 means we want to plot at the event location
            0,  # plot_lat
        ],
        [-127.50, 40.88, 12.0, 168, 40, -115, 20, 54, -70, 4.0, 23, 0, 0],
    ]
    focal_mechs_array = np.asarray(focal_mechanisms)

    fig.meca(
        focal_mechs_array,
        convention="gcmt",
        region=[-128, -127, 40, 41],
        scale="2c",
        projection="M14c",
    )

    return fig
Beispiel #9
0
# Set up standard map look
fig = Figure()
fig.coast(projection=projection, region=region, resolution="h",
          shorelines=[f"1/1.5p,{coast}", f"2/1p,{coast}"], 
          frame=frame, land=land, water=water, lakes=lakes,
		  area_thresh=10000)

# Plot moment tensors which should be in a file in the psmeca format from GCMT
# lon lat depth mrr mtt mpp mrt mrp mtp iexp name 
if moment_tensors and mt_fid:
	# Make the colormap to shade MTs by depth
	depths = np.loadtxt(mt_fid, usecols=2, dtype=float)
	makecpt(cmap=mt_cmap, series=[min(depths), max(depths), 1])
	
	mts = fig.meca(mt_fid, scale=mt_scale, convention="mt", component="dc",
				   C=True, verbose=True, L="1p/black")

	if mt_colorbar:
		fig.colorbar(position="n.95/.825+w-2c/.45c", frame='af+l"depth [km]"')

# Scalebar, need to use config to set the pen thickness of the scale
with config(MAP_TICK_PEN_PRIMARY=1.5):
	fig.basemap(region=region, projection=projection, #frame=["WSne", "gfa"],
				map_scale=map_scale)

# Landmark text
fig.text(textfiles=landmarks_fid)

# Plot the whole of Alaska as an inset to give context
if inset:
	with fig.inset(position="n0/.75+w5c/4c", margin=0):
Beispiel #10
0
            "sum_06_08_deep.txt")
    fig.contour(data=deep, levels=20, pen=deep_sse_pen, annotation=(20, "+f8"))

if seismicity:
    fig.plot(data=seis_fid, style="a", color="white",
             pen="1.,black")  # style='c'

if moment_tensors and mt_fid:
    mts = open(mt_fid, "r").readlines()
    for mt in mts[1:]:
        _, _, lat, lon, strike, dip, rake, *_ = mt.split(",")
        *_, ml, mw, m0 = mt.split(",")
        fig.meca(dict(strike=float(strike),
                      dip=float(dip),
                      rake=float(rake),
                      magnitude=float(mw) / 2),
                 scale="1c",
                 longitude=float(lon),
                 latitude=float(lat),
                 depth=0)

# Plot the locations of the 1947 Tsunami earthquakes
if tsunami_eq:
    # M 7.0 Gisborne, Mar 26 1947 (Offshore Poverty Bay)
    # Markersize taken from normalized earthquake list
    fig.plot(x=178.8,
             y=-38.85,
             style="a0.4099c",
             color="mediumpurple1",
             pen="1,black")
    # M 6.9 Gisborne, May 17 1947 (Offshore Tolaga Bay)
    fig.plot(x=178.87,