def compute(dataobj_list, offsetobj_list, eqobj_list):
    print("Computing common mode from %d stations " % (len(dataobj_list)))
    detrended_objects = []
    raw_objects = []
    cmr_objects = []
    # common-mode-removed objects
    cmr_deviations = []
    # Objects with no earthquakes or seasonals
    for i in range(len(dataobj_list)):
        newobj = offsets.remove_offsets(dataobj_list[i], offsetobj_list[i])
        newobj = offsets.remove_offsets(newobj, eqobj_list[i])
        newobj = gps_seasonal_removals.make_detrended_ts(newobj, 0, 'lssq')
        detrended_objects.append(newobj)

    common_mode_obj = define_common_mode(detrended_objects)

    print("Removing common mode from %d objects " % (len(dataobj_list)))
    for i in range(len(dataobj_list)):
        cmr_object = remove_cm_from_object(detrended_objects[i],
                                           common_mode_obj)
        cmr_objects.append(cmr_object)

    # Keep a measure of the spread of this data
    for i in range(len(cmr_objects)):
        udata = scipy.ndimage.median_filter(cmr_objects[i].dU, size=365)
        cmr_deviations.append(np.nanmax(udata) - np.nanmin(udata))

    return [common_mode_obj, detrended_objects, cmr_objects, cmr_deviations]
def compute(dataobj_list, offsetobj_list, eqobj_list, distances,
            data_config_file):
    latitudes_list = [i.coords[1] for i in dataobj_list]
    sorted_objects = [x for _, x in sorted(zip(latitudes_list, dataobj_list))]
    # the raw, sorted data.
    sorted_offsets = [
        x for _, x in sorted(zip(latitudes_list, offsetobj_list))
    ]
    # the raw, sorted data.
    sorted_eqs = [x for _, x in sorted(zip(latitudes_list, eqobj_list))]
    # the raw, sorted data.
    sorted_distances = [x for _, x in sorted(zip(latitudes_list, distances))]
    # the sorted distances.

    detrended_objects = []
    no_offset_objects = []
    no_offsets_no_trends = []
    no_offsets_no_trends_no_seasons = []

    # Detrended objects (or objects with trends and no offsets; depends on what you want.)
    for i in range(len(sorted_objects)):
        newobj = gps_seasonal_removals.make_detrended_ts(
            sorted_objects[i], 0, 'lssq', data_config_file)
        detrended_objects.append(newobj)
        # still has offsets, doesn't have trends

        newobj = offsets.remove_offsets(sorted_objects[i], sorted_offsets[i])
        newobj = offsets.remove_offsets(newobj, sorted_eqs[i])
        no_offset_objects.append(newobj)
        # still has trends, doesn't have offsets

    # Objects with no earthquakes or seasonals
    for i in range(len(dataobj_list)):
        # Remove the steps earthquakes
        newobj = offsets.remove_offsets(sorted_objects[i], sorted_offsets[i])
        newobj = offsets.remove_offsets(newobj, sorted_eqs[i])
        newobj = gps_ts_functions.remove_outliers(newobj, 20)
        # 20mm outlier definition

        # The detrended TS without earthquakes
        stage1obj = gps_seasonal_removals.make_detrended_ts(
            newobj, 0, 'lssq', data_config_file)
        no_offsets_no_trends.append(stage1obj)

        # The detrended TS without earthquakes or seasonals
        stage2obj = gps_seasonal_removals.make_detrended_ts(
            stage1obj, 1, 'lssq', data_config_file)
        no_offsets_no_trends_no_seasons.append(stage2obj)

    return [
        detrended_objects, no_offset_objects, no_offsets_no_trends,
        no_offsets_no_trends_no_seasons, sorted_distances
    ]
示例#3
0
def compute(myData, offset_obj, eq_obj, MyParams, starttime, endtime):
    if starttime is None:
        starttime = myData.dtarray[0]
    if endtime is None:
        endtime = myData.dtarray[-1]
    newData = gps_ts_functions.impose_time_limits(myData, starttime, endtime)
    if MyParams.offsets_remove == 1:  # Remove offsets and antenna changes
        newData = offsets.remove_offsets(newData, offset_obj)
    if MyParams.outliers_remove == 1:  # Remove outliers
        newData = gps_ts_functions.remove_outliers(newData,
                                                   MyParams.outliers_def)
    if MyParams.earthquakes_remove == 1:  # Remove earthquakes
        newData = offsets.remove_offsets(newData, eq_obj)
    trend_out = gps_seasonal_removals.make_detrended_ts(
        newData, MyParams.seasonals_remove, MyParams.seasonals_type,
        MyParams.data_config_file)
    return [newData, trend_out]
示例#4
0
def compute(dataobj_list, offsetobj_list, eqobj_list):
    east_slope_list = []
    north_slope_list = []
    vert_slope_list = []

    # Objects with no earthquakes or seasonals
    for i in range(len(dataobj_list)):

        # Remove the steps earthquakes
        newobj = offsets.remove_offsets(dataobj_list[i], offsetobj_list[i])
        newobj = offsets.remove_offsets(newobj, eqobj_list[i])
        [east_slope, north_slope, vert_slope, east_std, north_std,
         vert_std] = gps_ts_functions.get_slope(newobj)
        east_slope_list.append(east_slope)
        north_slope_list.append(north_slope)
        vert_slope_list.append(vert_slope)

    return [east_slope_list, north_slope_list, vert_slope_list]
def remove_by_model(Data0, data_config_file):
    # Right now configured for the Hines data.
    starttime1 = dt.datetime.strptime("20100403", "%Y%m%d");
    endtime1 = dt.datetime.strptime("20100405", "%Y%m%d");
    starttime2 = dt.datetime.strptime("20200328", "%Y%m%d");
    endtime2 = dt.datetime.strptime("20200330", "%Y%m%d");

    # Input Hines data.
    model_data = get_station_hines(Data0.name, data_config_file);

    if not model_data:  # if None
        return Data0;
    if len(Data0.dtarray) == 0:  # if empty
        return Data0;

    if model_data.dtarray[-1] < Data0.dtarray[-1]:
        print("\nWARNING! Trying to use a short postseismic model to fix a long GNSS time series.");
        print("PROBLEMS MAY OCCUR- tread carefully!!\n\n");

    # These will be the same size.
    Data0, model = gps_ts_functions.pair_gps_model_keeping_gps(Data0, model_data);
    # pair_gps_model_keeping_gps leaves data outside of the model timespan
    # Data0, model = gps_ts_functions.pair_gps_model(Data0, model_data);  # removes data outside of the model timespan.

    # Subtract the model from the data.
    dtarray, dE_gps, dN_gps, dU_gps = [], [], [], [];
    Se_gps, Sn_gps, Su_gps = [], [], [];
    for i in range(len(Data0.dtarray)):
        dtarray.append(Data0.dtarray[i]);
        dE_gps.append(Data0.dE[i] - model.dE[i]);
        dN_gps.append(Data0.dN[i] - model.dN[i]);
        dU_gps.append(Data0.dU[i] - model.dU[i]);
        Se_gps.append(Data0.Se[i]);
        Sn_gps.append(Data0.Sn[i]);
        Su_gps.append(Data0.Su[i]);

    # In this method, we correct for offsets at the beginning and end of the modeled time series.
    interval1 = [starttime1, endtime1];
    east_offset1 = offsets.fit_single_offset(dtarray, dE_gps, interval1, 20);
    north_offset1 = offsets.fit_single_offset(dtarray, dN_gps, interval1, 20);
    vert_offset1 = offsets.fit_single_offset(dtarray, dU_gps, interval1, 20);
    interval2 = [starttime2, endtime2];
    east_offset2 = offsets.fit_single_offset(dtarray, dE_gps, interval2, 20);
    north_offset2 = offsets.fit_single_offset(dtarray, dN_gps, interval2, 20);
    vert_offset2 = offsets.fit_single_offset(dtarray, dU_gps, interval2, 20);

    offsets_obj = offsets.Offsets(e_offsets=[east_offset1, east_offset2],
                                  n_offsets=[north_offset1, north_offset2], u_offsets=[vert_offset1, vert_offset2],
                                  evdts=[starttime1, starttime2]);

    corrected_data = gps_io_functions.Timeseries(name=Data0.name, coords=Data0.coords, dtarray=dtarray, dE=dE_gps,
                                                 dN=dN_gps, dU=dU_gps, Se=Se_gps, Sn=Sn_gps, Su=Su_gps,
                                                 EQtimes=Data0.EQtimes);
    corrected_data = offsets.remove_offsets(corrected_data, offsets_obj);
    return corrected_data;
示例#6
0
#!/usr/bin/env python
"""
Example driver for individual time series reading and writing.  
Read, Process a little, and Write Back Out.  
"""

import gps_input_pipeline
import offsets
import gps_io_functions

station = "P325"
data_config_file = "/Users/kmaterna/Documents/B_Research/GEOPHYS_DATA/GPS_POS_DATA/config.txt"
outfile = station + "_noearthquake.pos"

[myData, offset_obj,
 eq_obj] = gps_input_pipeline.get_station_data(station,
                                               'unr',
                                               data_config_file,
                                               refframe='ITRF')
newobj = offsets.remove_offsets(myData, offset_obj)
# remove antenna changes and instrument changes
newobj = offsets.remove_offsets(newobj, eq_obj)
# remove earthquakes
gps_io_functions.write_pbo_pos_file(newobj,
                                    outfile,
                                    comment="Writing a station's .pos file")
示例#7
0
def compute(dataobj_list, offsetobj_list, eqobj_list, deltat1, deltat2,
            fit_type, time_after_start_date, critical_variance):
    dt1_start = dt.datetime.strptime(deltat1[0], "%Y%m%d")
    dt1_end = dt.datetime.strptime(deltat1[1], "%Y%m%d")
    dt2_start = dt.datetime.strptime(deltat2[0], "%Y%m%d")
    dt2_end = dt.datetime.strptime(deltat2[1], "%Y%m%d")

    # No earthquakes objects
    noeq_objects = []
    east_slope_obj = []
    north_slope_obj = []
    vert_slope_obj = []

    # For the vertical correction.
    names = []
    coords = []
    for i in range(len(dataobj_list)):
        names.append(dataobj_list[i].name)
        coords.append(dataobj_list[i].coords)

    # The main processing loop for slopes.
    for i in range(len(dataobj_list)):
        # Remove the earthquakes
        print(names[i])
        newobj = offsets.remove_offsets(dataobj_list[i], offsetobj_list[i])
        newobj = offsets.remove_offsets(newobj, eqobj_list[i])
        if fit_type == 'none':
            newobj = gps_seasonal_removals.make_detrended_ts(
                newobj, 0, fit_type)
            # remove seasonals
        else:
            if newobj.name == 'P349':
                newobj = gps_seasonal_removals.make_detrended_ts(
                    newobj, 1, 'shasta')
            if newobj.name == 'ORVB':
                newobj = gps_seasonal_removals.make_detrended_ts(
                    newobj, 1, 'oroville')

        if fit_type != 'none':
            newobj = gps_seasonal_removals.make_detrended_ts(
                newobj, 1, fit_type)
            # remove seasonals

        # NOTE: WRITTEN IN JUNE 2019
        # An experiment for removing ETS events
        # if newobj.name in ["P349","P060","P330","P331","P332","P343","P338","P341"]:
        ets_intervals = remove_ets_events.input_tremor_days()
        # newobj=gps_ts_functions.remove_outliers(newobj,3.0);  # 3 mm outlier def.
        # newobj=remove_ets_events.remove_ETS_times(newobj,ets_intervals, offset_num_days=15);  # 30 days on either end of the offsets
        newobj = remove_ets_events.remove_characteristic_ETS(
            newobj, ets_intervals)
        # using only the characteristic offset

        noeq_objects.append(newobj)

        # Get the pre-event and post-event velocities (earthquakes removed)
        [
            east_slope_before, north_slope_before, vert_slope_before, esig0,
            nsig0, usig0
        ] = gps_ts_functions.get_slope(
            newobj,
            starttime=dt1_start + dt.timedelta(days=time_after_start_date),
            endtime=dt1_end)
        [
            east_slope_after, north_slope_after, vert_slope_after, esig1,
            nsig1, usig1
        ] = gps_ts_functions.get_slope(
            newobj,
            starttime=dt2_start + dt.timedelta(days=time_after_start_date),
            endtime=dt2_end)

        # Get the uncertainties on the velocity-change estimate
        [east_slope_unc1, north_slope_unc1,
         vert_slope_unc1] = gps_ts_functions.get_slope_unc(
             newobj, dt1_start + dt.timedelta(days=time_after_start_date),
             dt1_end)
        [east_slope_unc2, north_slope_unc2,
         vert_slope_unc2] = gps_ts_functions.get_slope_unc(
             newobj, dt2_start + dt.timedelta(days=time_after_start_date),
             dt2_end)
        east_dv_unc = gps_ts_functions.add_two_unc_quadrature(
            east_slope_unc1, east_slope_unc2)
        north_dv_unc = gps_ts_functions.add_two_unc_quadrature(
            north_slope_unc1, north_slope_unc2)
        vert_dv_unc = gps_ts_functions.add_two_unc_quadrature(
            vert_slope_unc1, vert_slope_unc2)

        # When do we ignore stations? When their detrended time series have a large variance.
        if abs(esig0) > critical_variance or abs(
                nsig0) > critical_variance or abs(
                    esig1) > critical_variance or abs(
                        nsig1) > critical_variance:
            print("Kicking station %s out..." % dataobj_list[i].name)
            [east_slope_after, north_slope_after,
             vert_slope_after] = [np.nan, np.nan, np.nan]
            [east_slope_before, north_slope_before,
             vert_slope_before] = [np.nan, np.nan, np.nan]
            [east_slope_unc1, north_slope_unc1,
             vert_slope_unc1] = [np.nan, np.nan, np.nan]
            [east_slope_unc2, north_slope_unc2,
             vert_slope_unc2] = [np.nan, np.nan, np.nan]

        east_slope_obj.append(
            [east_slope_before, east_slope_after, east_dv_unc])
        north_slope_obj.append(
            [north_slope_before, north_slope_after, north_dv_unc])
        vert_slope_obj.append(
            [vert_slope_before, vert_slope_after, vert_dv_unc])

    # Adjusting verticals by a reference station.
    vert_slope_obj = vert_adjust_by_reference_stations(names, coords,
                                                       vert_slope_obj)

    return [noeq_objects, east_slope_obj, north_slope_obj, vert_slope_obj]
示例#8
0
def read_station_ts(gps_bbox, gps_reference, remove_coseismic=0):
    """A reading function specific to Brawley right now. """
    blacklist = []
    network = 'pbo'
    station_names, _, _ = stations_within_radius.get_stations_within_box(
        gnss_object.gps_data_config_file, coord_box=gps_bbox, network=network)
    print(station_names)
    [dataobj_list, offsetobj_list, eqobj_list, _] = \
        gps_input_pipeline.multi_station_inputs(station_names, blacklist, network, "NA",
                                                gnss_object.gps_data_config_file)
    # Importing BRAW
    [myData, offset_obj, eq_obj
     ] = gps_input_pipeline.get_station_data("BRAW",
                                             "unr",
                                             gnss_object.gps_data_config_file,
                                             refframe="NA")
    myData = gps_ts_functions.impose_time_limits(
        myData, dt.datetime.strptime("20080505", "%Y%m%d"),
        dt.datetime.strptime("20200101", "%Y%m%d"))
    dataobj_list.append(myData)
    offsetobj_list.append(offset_obj)
    eqobj_list.append(eq_obj)

    # Now we are doing a bit of adjustments, for seasonal corrections and base station.
    cleaned_objects = []
    for i in range(len(dataobj_list)):
        one_object = dataobj_list[i]
        newobj = offsets.remove_offsets(one_object, offsetobj_list[i])
        # will remove antenna offsets from everything

        if newobj.name == 'BRAW':
            newobj = gps_seasonal_removals.make_detrended_ts(
                newobj,
                seasonals_remove=1,
                seasonals_type="lssq",
                data_config_file=gnss_object.gps_data_config_file,
                remove_trend=0)
        else:
            newobj = gps_seasonal_removals.make_detrended_ts(
                newobj,
                seasonals_remove=1,
                seasonals_type="nldas",
                data_config_file=gnss_object.gps_data_config_file,
                remove_trend=0)

        if remove_coseismic:
            print("Removing coseismic offsets")
            newobj = offsets.remove_offsets(newobj, eqobj_list[i])

        newobj = gps_ts_functions.remove_outliers(newobj, 20)
        # 20mm outlier definition

        # Here we detrend using pre-2010 velocities,
        # assuming tectonic strain accumulation won't contribute to geothermal field deformation.
        # Remove the postseismic by the Hines model
        endtime = dt.datetime.strptime("2010-04-01", "%Y-%m-%d")
        [east_slope, north_slope, vert_slope, _, _,
         _] = gps_ts_functions.get_slope(newobj,
                                         endtime=endtime,
                                         missing_fraction=0.2)
        east_params = [east_slope, 0, 0, 0, 0]
        north_params = [north_slope, 0, 0, 0, 0]
        vert_params = [vert_slope, 0, 0, 0, 0]
        newobj = gps_postseismic_remove.remove_by_model(
            newobj, gnss_object.gps_data_config_file)
        # This will actually remove the coseismic offset if within the window.
        newobj = gps_ts_functions.detrend_data_by_value(
            newobj, east_params, north_params, vert_params)
        cleaned_objects.append(newobj)

    # Subtracting the reference GPS station.
    ref_dataobjlist = []
    reference_station = [
        x for x in cleaned_objects if x.name == gps_reference
    ][0]
    for one_object in cleaned_objects:
        refobj = gps_ts_functions.get_referenced_data(one_object,
                                                      reference_station)
        ref_dataobjlist.append(refobj)

    return ref_dataobjlist