Ejemplo n.º 1
0
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
    ]
Ejemplo n.º 2
0
def compute(dataobj_list, offsetobj_list, eqobj_list, distances, EQtime):

    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
    detrended_objects = []
    for i in range(len(sorted_objects)):
        newobj = gps_seasonal_removals.make_detrended_ts(
            sorted_objects[i], 0, 'lssq')
        detrended_objects.append(newobj)

    # Objects with no earthquakes or seasonals
    stage1_objects = []
    stage2_objects = []
    east_slope_obj = []
    for i in range(len(dataobj_list)):
        # Remove the steps earthquakes
        newobj = offsets.remove_antenna_offsets(sorted_objects[i],
                                                sorted_offsets[i])
        newobj = offsets.remove_earthquakes(newobj, sorted_eqs[i])

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

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

        # Get the pre-event and post-event velocities (earthquakes removed)
        [east_slope_before, north_slope_before, vert_slope_before, _, _,
         _] = gps_ts_functions.get_slope(stage2obj, endtime=EQtime)
        [east_slope_after, north_slope_after, vert_slope_after, _, _,
         _] = gps_ts_functions.get_slope(stage2obj, starttime=EQtime)
        east_slope_after = np.round(east_slope_after, decimals=1)
        east_slope_before = np.round(east_slope_before, decimals=1)
        east_slope_obj.append([east_slope_before, east_slope_after])

    return [
        detrended_objects, stage1_objects, stage2_objects, sorted_distances,
        east_slope_obj
    ]
Ejemplo n.º 3
0
def compute(dataobj_list, offsetobj_list, eqobj_list, fit_table, grace_dir,start_time_infl, end_time_infl,start_time_velo, end_time_velo, seasonal_type, N, Wn):
	
	# Initialize output objects
	noeq_objects = []; 
	east_filt=[]; north_filt=[]; vert_filt=[]; east_inf_time=[]; north_inf_time=[]; vert_inf_time=[];
	east_change=[]; north_change=[]; vert_change=[];

	for i in range(len(dataobj_list)):
		# Remove the earthquakes and offsets
		newobj=offsets.remove_antenna_offsets(dataobj_list[i], offsetobj_list[i]);
		newobj=offsets.remove_earthquakes(newobj,eqobj_list[i]);
		newobj=gps_ts_functions.remove_outliers(newobj,15);  # 15mm horizontal outliers
		newobj=gps_seasonal_removals.make_detrended_ts(newobj, 1, seasonal_type, fit_table, grace_dir);  # can remove seasonals a few ways
		noeq_objects.append(newobj);

		print(dataobj_list[i].name);

		# Get the inflection points in the timeseries
		float_dtarray = gps_ts_functions.get_float_times(newobj.dtarray);
		[east_filtered, e_inflection_time, echange]=inflection_with_butterworth(newobj.dtarray, float_dtarray, newobj.dE, N, Wn, start_time_infl, end_time_infl,start_time_velo, end_time_velo);
		[north_filtered, n_inflection_time, nchange]=inflection_with_butterworth(newobj.dtarray, float_dtarray, newobj.dN, N, Wn, start_time_infl, end_time_infl,start_time_velo, end_time_velo);
		[vert_filtered, v_inflection_time, vchange]=inflection_with_butterworth(newobj.dtarray, float_dtarray, newobj.dU, N, Wn, start_time_infl, end_time_infl,start_time_velo, end_time_velo);

		east_filt.append(east_filtered);
		north_filt.append(north_filtered);
		vert_filt.append(vert_filtered);
		east_inf_time.append(e_inflection_time);
		north_inf_time.append(n_inflection_time);
		vert_inf_time.append(v_inflection_time);
		east_change.append(echange);
		north_change.append(nchange);
		vert_change.append(vchange);

	return [noeq_objects, east_filt, north_filt, vert_filt, east_inf_time, north_inf_time, vert_inf_time, east_change, north_change, vert_change];
Ejemplo n.º 4
0
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(myData, offset_obj, eq_obj, MyParams):
	newData=myData; 
	if MyParams.offsets_remove==1:  # First step: remove offsets and earthquakes
		newData=offsets.remove_antenna_offsets(newData, offset_obj);
	if MyParams.outliers_remove==1:  # Second step: remove outliers
		newData=gps_ts_functions.remove_outliers(newData, MyParams.outliers_def);
	if MyParams.earthquakes_remove==1:
		newData=offsets.remove_earthquakes(newData, eq_obj);

	# A few different types of seasonal removal. 
	notrend=gps_seasonal_removals.make_detrended_ts(newData, 0, 'lssq');
	lssq_fit=gps_seasonal_removals.make_detrended_ts(newData, 1, 'lssq');
	notch_filt=gps_seasonal_removals.make_detrended_ts(newData, 1, 'notch');
	grace_filt=gps_seasonal_removals.make_detrended_ts(newData, 1, 'grace');
	stl_filt=gps_seasonal_removals.make_detrended_ts(newData, 1, 'stl');
	# stl_filt=gps_seasonal_removals.make_detrended_ts(newData, 1, 'lssq');

	return [notrend, lssq_fit, notch_filt, grace_filt, stl_filt];
Ejemplo n.º 6
0
def compute(myData, offset_obj, eq_obj, outliers_def, outdir):
    for i in range(len(myData)):
        newData = myData[i]
        newData = offsets.remove_antenna_offsets(newData, offset_obj[i])
        newData = gps_ts_functions.remove_outliers(newData, outliers_def)
        newData = offsets.remove_earthquakes(newData, eq_obj[i])
        stl_filt = gps_seasonal_removals.make_detrended_ts(newData, 1, 'stl')
        outputs(stl_filt, outdir)
    return
Ejemplo n.º 7
0
def get_detrended_gps_station(station_name):
    datasource = 'pbo'
    [newData, offset_obj,
     eq_obj] = gps_input_pipeline.get_station_data(station_name, datasource)
    newData = offsets.remove_antenna_offsets(newData, offset_obj)
    newData = gps_ts_functions.remove_outliers(newData, 5)
    # mm for outliers
    newData = offsets.remove_earthquakes(newData, eq_obj)
    trend_out = gps_seasonal_removals.make_detrended_ts(newData, 1, 'notch')
    return trend_out
Ejemplo n.º 8
0
def compute(myData, offset_obj, eq_obj, MyParams):
    newData = myData
    if MyParams.offsets_remove == 1:  # First step: remove offsets and earthquakes
        newData = offsets.remove_antenna_offsets(newData, offset_obj)
    if MyParams.outliers_remove == 1:  # Second step: remove outliers
        newData = gps_ts_functions.remove_outliers(newData,
                                                   MyParams.outliers_def)
    if MyParams.earthquakes_remove == 1:
        newData = offsets.remove_earthquakes(newData, eq_obj)

    trend_out = gps_seasonal_removals.make_detrended_ts(
        newData, MyParams.seasonals_remove, MyParams.seasonals_type,
        MyParams.fit_table, MyParams.grace_dir)
    return [newData, trend_out]
Ejemplo n.º 9
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]
Ejemplo n.º 10
0
def compute(dataobj_list, offsetobj_list, eqobj_list, dt1_start, dt1_end,
            dt2_start, dt2_end, fit_type):

    # No earthquakes objects
    noeq_objects = []
    east_slope_obj = []
    north_slope_obj = []
    vert_slope_obj = []
    period_after_start_date = 7
    # wait a week.

    # 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_antenna_offsets(dataobj_list[i],
                                                offsetobj_list[i])
        newobj = offsets.remove_earthquakes(newobj, eqobj_list[i])
        if fit_type == 'none':
            newobj = gps_seasonal_removals.make_detrended_ts(
                newobj, 0, fit_type)
            # remove seasonals
        else:
            newobj = gps_seasonal_removals.make_detrended_ts(
                newobj, 1, fit_type)
            # remove seasonals

        # What is this? It looks like awful code.
        if newobj.dN[0] == 1.0000:
            print("Passing because we haven't computed GRACE yet...")
            noeq_objects.append(newobj)
            east_slope_obj.append([np.nan, np.nan])
            north_slope_obj.append([np.nan, np.nan])
            vert_slope_obj.append([np.nan, np.nan])
            continue

        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=period_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=period_after_start_date),
            endtime=dt2_end)

        # When do we ignore stations? When their detrended time series have a large variance.

        critical_value = 5
        # mm/yr
        if abs(esig0) > critical_value or abs(nsig0) > critical_value or abs(
                esig1) > critical_value or abs(nsig1) > critical_value:
            print("Kicking station out...")
            print(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]

        else:
            east_slope_after = np.round(east_slope_after, decimals=1)
            east_slope_before = np.round(east_slope_before, decimals=1)
            north_slope_after = np.round(north_slope_after, decimals=1)
            north_slope_before = np.round(north_slope_before, decimals=1)
            vert_slope_after = np.round(vert_slope_after, decimals=1)
            vert_slope_before = np.round(vert_slope_before, decimals=1)

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

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

    return [noeq_objects, east_slope_obj, north_slope_obj, vert_slope_obj]
Ejemplo n.º 11
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]
Ejemplo n.º 12
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