Пример #1
0
def diff_apparent_dv_plot(adv_dict,
                          period_b_start, period_b_stop,
                          period_a_start, period_a_stop,
                          inter_points=1000,
                          catalog=None,
                          save_file_name=None,
                          ax=None,
                          use_gridspec=False,
                          shrink=1,
                          coord_sys='geo'):
    """ Differential apparent velocity change plot

    This function does plot the differential apparent velocity change
    that occurred between two time periods of interest.
    The apparent velocity change is first averaged over the two specified
    time period. The differential values are computed for all the stations
    available at that time and they are interpolated on a regular grid
    taking into account their position.
    In case a catalog that reports geo information about important events is
    passed, all of them falling between ``period_b_stop`` and
    ``period_a_start`` are also marked on the plot.

    :type adv_dict: dictionary
    :param adv_dict: Dictionary that caonins the apparent dv DataFrame
        produced by, e.g.,
        :py:func:`~miic.core.macro.inversion_with_missed_data_macro`, and the
        points (stations) geographical infromation.
    :type period_b_start: :py:class:`~datetime.datetime`
    :param period_b_start: Stating day for the first period
    :type period_b_stop: :py:class:`~datetime.datetime`
    :param period_b_stop: Ending day of the first period
    :type period_a_start: :py:class:`~datetime.datetime`
    :param period_a_start: Stating day for the second period
    :type period_a_stop: :py:class:`~datetime.datetime`
    :param period_a_stop: Ending day of the second period
    :type inter_points: int
    :param inter_points: Interpolation points
    :type catalog: :py:class:`~pandas.DataFrame`
    :param catalog: This DataFrame is supposed to have a Multiindex where
        level=0 reports the day corresponding to each event and the level=1
        reports a generic marker (e.g. an increasing index) for the different
        locations interested by the event. Each location must be specified at
        least in four columns: 's_x' 's_y' -> coordinates of the starting point
                               'e_x' 'e_y' -> coordinates of the ending point
    :type save_file_name: str
    :param save_file_name: Filename where to save the produced figure.
    """

    check_state = adv_check(adv_dict)

    # Check if the dv dictionary is "correct"
    if check_state['is_incomplete']:
        print "Error: Incomplete dv"
        print "Possible errors:"
        for key in check_state:
            if key is not 'is_incomplete':
                print "%s: %s" % (key, check_state[key])
        raise ValueError

    apparent_dv = adv_dict['apparent_dv']
    stations_info = adv_dict['points_geo_info']

    dv_before = apparent_dv.ix[period_b_start:period_b_stop].mean(axis=0)

    dv_after = apparent_dv.ix[period_a_start:period_a_stop].mean(axis=0)

    mask = (np.isnan(dv_before) | np.isnan(dv_after))

    # Geo coordinates for the stations
    xpt = stations_info[~mask]['easting']
    ypt = stations_info[~mask]['northing']

    if coord_sys == 'geo':
        # Local projection that is valid for small areas
        xpt = np.array(xpt.tolist()) - xpt.mean()
        xpt *= np.pi / 180 * np.cos(np.mean(ypt) * np.pi / 180) * 6371
        ypt = np.array(ypt.tolist()) - ypt.mean()
        ypt *= np.pi / 180 * 6371

    elif coord_sys == 'utm':
        # Correct the coordinates to work with km
        xpt = xpt.astype('float64') / 1000
        ypt = ypt.astype('float64') / 1000

    else:
        raise ValueError

    # Differential apparent dv
    zpt = dv_after[~mask] - dv_before[~mask]

    # Construct the grid
    xg = np.linspace(np.nanmin(xpt), np.nanmax(xpt), inter_points)
    yg = np.linspace(np.nanmin(ypt), np.nanmax(ypt), inter_points)
    xgrid, ygrid = np.meshgrid(xg, yg)

    # Do the interpolation
    F = plt.mlab.griddata(xpt, ypt, zpt.values, xgrid, ygrid, interp='nn')

    # Create symmetric color scale
    vmax = F.max()
    vmin = F.min()
    mmax = max(abs(vmax), abs(vmin))

    # It a catalog is passed check if there are events in between the
    # two selected periods
    if catalog is not None:
        events = catalog.ix[period_b_stop:period_a_start]

    if ax is None:
        f = plt.figure(figsize=(12, 6), dpi=300)
        ax = f.add_subplot(111)
    else:
        f = ax.get_figure()

    ax.axes.set_aspect('equal')

    plt.imshow(F, interpolation='none',
               extent=(xg[0], xg[-1], yg[0], yg[-1]),
               origin='lower', cmap='jet_r',
               vmax=mmax, vmin= -mmax, axes=ax)
    plt.hold('on')
    plt.scatter(xpt, ypt, c=zpt, cmap='jet_r',
                vmax=mmax, vmin= -mmax,
                marker='v', s=50, label='stations',
                edgecolors='k')

    if catalog is not None:
        for (_, fs) in events.iterrows():
            plt.plot(np.array([fs['s_x'], fs['e_x']]).astype('float64') / 1000,
                     np.array([fs['s_y'], fs['e_y']]).astype('float64') / 1000,
                     lw=1, color='k', marker='o', markerfacecolor='w',
                     markeredgewidth=1, markeredgecolor='k',
                     markersize=5, label='fissure')

    plt.title('Differential apparent velocity change')
    plt.xlabel('easting (Km)')
    plt.ylabel('northing (Km)')
    plt.setp(plt.gca().get_xticklabels(), rotation=45, ha='right')

    plt.colorbar(format='%-6.5f', ax=ax,
                 use_gridspec=use_gridspec, shrink=shrink)

    plt.legend(scatterpoints=1)

    if save_file_name is not None:
        f.savefig(save_file_name)
Пример #2
0
def diff_apparent_dv_plot(adv_dict,
                          period_b_start,
                          period_b_stop,
                          period_a_start,
                          period_a_stop,
                          inter_points=1000,
                          catalog=None,
                          save_file_name=None,
                          ax=None,
                          use_gridspec=False,
                          shrink=1,
                          coord_sys='geo'):
    """ Differential apparent velocity change plot

    This function does plot the differential apparent velocity change
    that occurred between two time periods of interest.
    The apparent velocity change is first averaged over the two specified
    time period. The differential values are computed for all the stations
    available at that time and they are interpolated on a regular grid
    taking into account their position.
    In case a catalog that reports geo information about important events is
    passed, all of them falling between ``period_b_stop`` and
    ``period_a_start`` are also marked on the plot.

    :type adv_dict: dictionary
    :param adv_dict: Dictionary that caonins the apparent dv DataFrame
        produced by, e.g.,
        :py:func:`~miic.core.macro.inversion_with_missed_data_macro`, and the
        points (stations) geographical infromation.
    :type period_b_start: :py:class:`~datetime.datetime`
    :param period_b_start: Stating day for the first period
    :type period_b_stop: :py:class:`~datetime.datetime`
    :param period_b_stop: Ending day of the first period
    :type period_a_start: :py:class:`~datetime.datetime`
    :param period_a_start: Stating day for the second period
    :type period_a_stop: :py:class:`~datetime.datetime`
    :param period_a_stop: Ending day of the second period
    :type inter_points: int
    :param inter_points: Interpolation points
    :type catalog: :py:class:`~pandas.DataFrame`
    :param catalog: This DataFrame is supposed to have a Multiindex where
        level=0 reports the day corresponding to each event and the level=1
        reports a generic marker (e.g. an increasing index) for the different
        locations interested by the event. Each location must be specified at
        least in four columns: 's_x' 's_y' -> coordinates of the starting point
                               'e_x' 'e_y' -> coordinates of the ending point
    :type save_file_name: str
    :param save_file_name: Filename where to save the produced figure.
    """

    check_state = adv_check(adv_dict)

    # Check if the dv dictionary is "correct"
    if check_state['is_incomplete']:
        print "Error: Incomplete dv"
        print "Possible errors:"
        for key in check_state:
            if key is not 'is_incomplete':
                print "%s: %s" % (key, check_state[key])
        raise ValueError

    apparent_dv = adv_dict['apparent_dv']
    stations_info = adv_dict['points_geo_info']

    dv_before = apparent_dv.ix[period_b_start:period_b_stop].mean(axis=0)

    dv_after = apparent_dv.ix[period_a_start:period_a_stop].mean(axis=0)

    mask = (np.isnan(dv_before) | np.isnan(dv_after))

    # Geo coordinates for the stations
    xpt = stations_info[~mask]['easting']
    ypt = stations_info[~mask]['northing']

    if coord_sys == 'geo':
        # Local projection that is valid for small areas
        xpt = np.array(xpt.tolist()) - xpt.mean()
        xpt *= np.pi / 180 * np.cos(np.mean(ypt) * np.pi / 180) * 6371
        ypt = np.array(ypt.tolist()) - ypt.mean()
        ypt *= np.pi / 180 * 6371

    elif coord_sys == 'utm':
        # Correct the coordinates to work with km
        xpt = xpt.astype('float64') / 1000
        ypt = ypt.astype('float64') / 1000

    else:
        raise ValueError

    # Differential apparent dv
    zpt = dv_after[~mask] - dv_before[~mask]

    # Construct the grid
    xg = np.linspace(np.nanmin(xpt), np.nanmax(xpt), inter_points)
    yg = np.linspace(np.nanmin(ypt), np.nanmax(ypt), inter_points)
    xgrid, ygrid = np.meshgrid(xg, yg)

    # Do the interpolation
    F = plt.mlab.griddata(xpt, ypt, zpt.values, xgrid, ygrid, interp='nn')

    # Create symmetric color scale
    vmax = F.max()
    vmin = F.min()
    mmax = max(abs(vmax), abs(vmin))

    # It a catalog is passed check if there are events in between the
    # two selected periods
    if catalog is not None:
        events = catalog.ix[period_b_stop:period_a_start]

    if ax is None:
        f = plt.figure(figsize=(12, 6), dpi=300)
        ax = f.add_subplot(111)
    else:
        f = ax.get_figure()

    ax.axes.set_aspect('equal')

    plt.imshow(F,
               interpolation='none',
               extent=(xg[0], xg[-1], yg[0], yg[-1]),
               origin='lower',
               cmap='jet_r',
               vmax=mmax,
               vmin=-mmax,
               axes=ax)
    plt.hold('on')
    plt.scatter(xpt,
                ypt,
                c=zpt,
                cmap='jet_r',
                vmax=mmax,
                vmin=-mmax,
                marker='v',
                s=50,
                label='stations',
                edgecolors='k')

    if catalog is not None:
        for (_, fs) in events.iterrows():
            plt.plot(np.array([fs['s_x'], fs['e_x']]).astype('float64') / 1000,
                     np.array([fs['s_y'], fs['e_y']]).astype('float64') / 1000,
                     lw=1,
                     color='k',
                     marker='o',
                     markerfacecolor='w',
                     markeredgewidth=1,
                     markeredgecolor='k',
                     markersize=5,
                     label='fissure')

    plt.title('Differential apparent velocity change')
    plt.xlabel('easting (Km)')
    plt.ylabel('northing (Km)')
    plt.setp(plt.gca().get_xticklabels(), rotation=45, ha='right')

    plt.colorbar(format='%-6.5f',
                 ax=ax,
                 use_gridspec=use_gridspec,
                 shrink=shrink)

    plt.legend(scatterpoints=1)

    if save_file_name is not None:
        f.savefig(save_file_name)
Пример #3
0
def apparent_dv_plot(adv_dict,
                     time_stamp,
                     inter_points=1000,
                     save_file_name=None,
                     ax=None,
                     use_gridspec=False,
                     shrink=1,
                     coord_sys='geo'):
    """ Apparent velocity change plot

    This function does plot the apparent velocity change that occurred at
    a certain time of interest.
    The dv values available at that time are interpolated on a regular grid
    taking into account their position as specified by ``stations_info``
    parameter.

    :type apparent_dv: :py:class:`~pandas.DataFrame`
    :param apparent_dv: Apparent dv DataFrame produced by, e.g.,
        :py:func:`~miic.core.macro.inversion_with_missed_data_macro`
    :type stations_info: :py:class:`~pandas.DataFrame`
    :param stations_info: Stations geo information. This DataFrame is supposed
        to have the stations names as index and, at least, two columns:
        'easting' and 'nothing'.
    :type time_stamp: :py:class:`~datetime.datetime`
    :param time_stamp: Day of interest
    :type inter_points: int
    :param inter_points: Interpolation points
    :type save_file_name: str
    :param save_file_name: Filename where to save the produced figure.
    """

    check_state = adv_check(adv_dict)

    # Check if the dv dictionary is "correct"
    if check_state['is_incomplete']:
        print "Error: Incomplete dv"
        print "Possible errors:"
        for key in check_state:
            if key is not 'is_incomplete':
                print "%s: %s" % (key, check_state[key])
        raise ValueError

    dv = adv_dict['apparent_dv'].ix[time_stamp]
    stations_info = adv_dict['points_geo_info']

    mask = dv.isnull()

    # Geo coordinates for the stations
    xpt = stations_info[~mask]['easting']
    ypt = stations_info[~mask]['northing']

    if coord_sys == 'geo':
        # Local projection that is valid for small areas
        xpt = np.array(xpt.tolist()) - xpt.mean()
        xpt *= np.pi / 180 * np.cos(np.mean(ypt) * np.pi / 180) * 6371
        ypt = np.array(ypt.tolist()) - ypt.mean()
        ypt *= np.pi / 180 * 6371

    elif coord_sys == 'utm':
        # Correct the coordinates to work with km
        xpt = xpt.astype('float64') / 1000
        ypt = ypt.astype('float64') / 1000

    else:
        raise ValueError

    # Differential apparent dv
    zpt = dv[~mask]

    # Construct the grid
    xg = np.linspace(np.nanmin(xpt), np.nanmax(xpt), inter_points)
    yg = np.linspace(np.nanmin(ypt), np.nanmax(ypt), inter_points)
    xgrid, ygrid = np.meshgrid(xg, yg)

    # Do the interpolation
    F = plt.mlab.griddata(xpt, ypt, zpt.values, xgrid, ygrid, interp='nn')

    # Create symmetric color scale
    vmax = F.max()
    vmin = F.min()
    mmax = max(abs(vmax), abs(vmin))

    if ax is None:
        f = plt.figure(figsize=(12, 6), dpi=300)
        ax = f.add_subplot(111)
    else:
        f = ax.get_figure()

    ax.axes.set_aspect('equal')

    plt.imshow(F, interpolation='none',
               extent=(xg[0], xg[-1], yg[0], yg[-1]),
               origin='lower', cmap='jet_r',
               vmax=mmax, vmin= -mmax, axes=ax)
    plt.hold('on')
    plt.scatter(xpt, ypt, c=zpt, cmap='jet_r',
                vmax=mmax, vmin= -mmax,
                marker='v', s=50, label='stations',
                edgecolors='k')

    plt.title('Apparent velocity change')
    plt.xlabel('easting (Km)')
    plt.ylabel('northing (Km)')
    plt.setp(plt.gca().get_xticklabels(), rotation=45, ha='right')

    plt.colorbar(format='%-6.5f', ax=ax,
                 use_gridspec=use_gridspec, shrink=shrink)

    plt.legend(scatterpoints=1)

    if save_file_name is not None:
        f.savefig(save_file_name)
Пример #4
0
def apparent_dv_plot(adv_dict,
                     time_stamp,
                     inter_points=1000,
                     save_file_name=None,
                     ax=None,
                     use_gridspec=False,
                     shrink=1,
                     coord_sys='geo'):
    """ Apparent velocity change plot

    This function does plot the apparent velocity change that occurred at
    a certain time of interest.
    The dv values available at that time are interpolated on a regular grid
    taking into account their position as specified by ``stations_info``
    parameter.

    :type apparent_dv: :py:class:`~pandas.DataFrame`
    :param apparent_dv: Apparent dv DataFrame produced by, e.g.,
        :py:func:`~miic.core.macro.inversion_with_missed_data_macro`
    :type stations_info: :py:class:`~pandas.DataFrame`
    :param stations_info: Stations geo information. This DataFrame is supposed
        to have the stations names as index and, at least, two columns:
        'easting' and 'nothing'.
    :type time_stamp: :py:class:`~datetime.datetime`
    :param time_stamp: Day of interest
    :type inter_points: int
    :param inter_points: Interpolation points
    :type save_file_name: str
    :param save_file_name: Filename where to save the produced figure.
    """

    check_state = adv_check(adv_dict)

    # Check if the dv dictionary is "correct"
    if check_state['is_incomplete']:
        print "Error: Incomplete dv"
        print "Possible errors:"
        for key in check_state:
            if key is not 'is_incomplete':
                print "%s: %s" % (key, check_state[key])
        raise ValueError

    dv = adv_dict['apparent_dv'].ix[time_stamp]
    stations_info = adv_dict['points_geo_info']

    mask = dv.isnull()

    # Geo coordinates for the stations
    xpt = stations_info[~mask]['easting']
    ypt = stations_info[~mask]['northing']

    if coord_sys == 'geo':
        # Local projection that is valid for small areas
        xpt = np.array(xpt.tolist()) - xpt.mean()
        xpt *= np.pi / 180 * np.cos(np.mean(ypt) * np.pi / 180) * 6371
        ypt = np.array(ypt.tolist()) - ypt.mean()
        ypt *= np.pi / 180 * 6371

    elif coord_sys == 'utm':
        # Correct the coordinates to work with km
        xpt = xpt.astype('float64') / 1000
        ypt = ypt.astype('float64') / 1000

    else:
        raise ValueError

    # Differential apparent dv
    zpt = dv[~mask]

    # Construct the grid
    xg = np.linspace(np.nanmin(xpt), np.nanmax(xpt), inter_points)
    yg = np.linspace(np.nanmin(ypt), np.nanmax(ypt), inter_points)
    xgrid, ygrid = np.meshgrid(xg, yg)

    # Do the interpolation
    F = plt.mlab.griddata(xpt, ypt, zpt.values, xgrid, ygrid, interp='nn')

    # Create symmetric color scale
    vmax = F.max()
    vmin = F.min()
    mmax = max(abs(vmax), abs(vmin))

    if ax is None:
        f = plt.figure(figsize=(12, 6), dpi=300)
        ax = f.add_subplot(111)
    else:
        f = ax.get_figure()

    ax.axes.set_aspect('equal')

    plt.imshow(F,
               interpolation='none',
               extent=(xg[0], xg[-1], yg[0], yg[-1]),
               origin='lower',
               cmap='jet_r',
               vmax=mmax,
               vmin=-mmax,
               axes=ax)
    plt.hold('on')
    plt.scatter(xpt,
                ypt,
                c=zpt,
                cmap='jet_r',
                vmax=mmax,
                vmin=-mmax,
                marker='v',
                s=50,
                label='stations',
                edgecolors='k')

    plt.title('Apparent velocity change')
    plt.xlabel('easting (Km)')
    plt.ylabel('northing (Km)')
    plt.setp(plt.gca().get_xticklabels(), rotation=45, ha='right')

    plt.colorbar(format='%-6.5f',
                 ax=ax,
                 use_gridspec=use_gridspec,
                 shrink=shrink)

    plt.legend(scatterpoints=1)

    if save_file_name is not None:
        f.savefig(save_file_name)