def configure(data_config_file, expname, center, radius, proc_center, refframe,
              outdir):
    # Set up the stacking process
    stations, lons, lats, distances = stations_within_radius.get_stations_within_radius(
        data_config_file, center, radius, network=proc_center)
    data_config = gps_io_functions.read_config_file(data_config_file)
    blacklist = np.loadtxt(data_config.blacklist,
                           unpack=False,
                           usecols=(0),
                           dtype={
                               'names': ('name', ),
                               'formats': ('U4', )
                           })
    blacklist = [i[0] for i in blacklist]
    subprocess.call(["mkdir", "-p", outdir], shell=False)
    outname = expname + "_" + str(center[0]) + "_" + str(
        center[1]) + "_" + str(radius)
    myparams = Parameters(expname=expname,
                          proc_center=proc_center,
                          refframe=refframe,
                          center=center,
                          radius=radius,
                          stations=stations,
                          distances=distances,
                          blacklist=blacklist,
                          outdir=outdir,
                          outname=outname)
    return myparams
Esempio n. 2
0
def get_noah025(data_config_file, station):
    Params = gps_io_functions.read_config_file(data_config_file)
    coords_file = Params.unr_coords_file
    filename = Params.noah_dir + station + "_NOAH025.hyd"
    [myData] = gps_io_functions.read_pbo_hydro_file(filename, coords_file)
    Offset = offsets.get_empty_offsets()
    return [myData, Offset, Offset]
Esempio n. 3
0
def import_velfield(gps_config_file,
                    network='pbo',
                    refframe='ITRF',
                    sub_network=''):
    # Read a velocity field from a certain network and refframe
    myParams = gps_io_functions.read_config_file(gps_config_file)
    if network == 'pbo':
        pbo_velfile = get_pbo_velfile(myParams.pbo_velocities, refframe)
        [myVelocities] = gps_io_functions.read_pbo_vel_file(pbo_velfile)
    elif network == 'cwu':
        cwu_velfile = get_cwu_velfile(myParams.pbo_velocities, refframe)
        [myVelocities
         ] = gps_io_functions.read_pbo_vel_file_fortran(cwu_velfile)
    elif network == 'unr':
        unr_velfile = get_unr_velfile(myParams.unr_velocities, refframe)
        [myVelocities
         ] = gps_io_functions.read_unr_vel_file(unr_velfile,
                                                myParams.unr_coords_file)
    elif network[0:4] == 'usgs':
        if len(network) == 4:  # if the network is just usgs
            usgs_velfile = get_usgs_velfile(myParams.usgs_vel_dir, refframe,
                                            sub_network)
        else:  # if the network has format similar to 'usgs-Pacific_Northwest'
            sub_network = network.split('-')[1]
            usgs_velfile = get_usgs_velfile(myParams.usgs_vel_dir, refframe,
                                            sub_network)
        [myVelocities
         ] = gps_io_functions.read_usgs_velfile(usgs_velfile,
                                                myParams.usgs_cache_file)
    else:
        print(
            "Error! Invalid choice of network [pick one of pbo/cwu/unr/usgs]")
        sys.exit(0)
    return myVelocities
Esempio n. 4
0
def get_nldas(data_config_file, station):
    Params = gps_io_functions.read_config_file(data_config_file)
    coords_file = Params.unr_coords_file
    station_name_lower = station.lower()
    filename = Params.nldas_dir + station_name_lower + "_noah125_nldas2.hyd"
    [myData] = gps_io_functions.read_pbo_hydro_file(filename, coords_file)
    Offset = offsets.get_empty_offsets()
    return [myData, Offset, Offset]
def get_station_hines(station_name, data_config_file):
    system_params = gps_io_functions.read_config_file(data_config_file);
    model_dir = "/Contrib_Data/Remove_postseismic/Hines/Stations/"
    model_file = system_params.general_gps_dir + model_dir + station_name + "_psmodel.pos";
    # This is stored in general_gps_dir because it's on my system, but may not be on general systems. 
    if os.path.isfile(model_file):
        [Data0] = gps_io_functions.read_pbo_pos_file(model_file);
        return Data0;
    else:
        print("ERROR: Cannot remove postseismic because file does not exist; file %s" % model_file);
        return None;
Esempio n. 6
0
def get_usgs(data_config_file, station, sub_network, refframe="NA"):
    Params = gps_io_functions.read_config_file(data_config_file)
    if refframe == 'ITRF':
        reflabel = 'ITRF2008'
    else:
        reflabel = 'NAfixed'
    usgs_filename = Params.usgs_gps_dir + sub_network + '/' + station.lower(
    ) + "_" + reflabel + ".rneu"
    [myData] = gps_io_functions.read_USGS_ts_file(usgs_filename)
    Offsets = offsets.get_empty_offsets()
    return [myData, Offsets, Offsets]
Esempio n. 7
0
def get_nmt(data_config_file, station, refframe="NA"):
    if refframe == "ITRF":
        reflabel = "igs08"
    else:
        reflabel = "nam08"
    Params = gps_io_functions.read_config_file(data_config_file)
    pbo_filename = Params.pbo_gps_dir + station + ".nmt.final_" + reflabel + ".pos"
    pbo_earthquakes_dir = Params.pbo_earthquakes_dir
    offsets_dir = Params.pbo_offsets_dir
    [myData] = gps_io_functions.read_pbo_pos_file(pbo_filename)
    # PBO data format
    Offsets = get_pbo_offsets(station, offsets_dir)
    Earthquakes = get_pbo_earthquakes(station, pbo_earthquakes_dir)
    return [myData, Offsets, Earthquakes]
Esempio n. 8
0
def get_unr(data_config_file, station, refframe="NA"):
    if refframe == "ITRF":
        reflabel = "IGS14"
    else:
        reflabel = "NA"
    Params = gps_io_functions.read_config_file(data_config_file)
    unr_filename = Params.unr_gps_dir + station + "." + reflabel + ".tenv3"
    unr_coords = Params.unr_coords_file
    offsets_dir = Params.unr_offsets_dir
    [myData
     ] = gps_io_functions.read_UNR_magnet_ts_file(unr_filename, unr_coords)
    # UNR data format
    Offsets = get_unr_offsets(myData, station, offsets_dir)
    Earthquakes = get_unr_earthquakes(myData, station, offsets_dir)
    return [myData, Offsets, Earthquakes]
Esempio n. 9
0
def remove_blacklist(data_config_file, stations):
    Params = gps_io_functions.read_config_file(data_config_file)
    new_stations = []
    blacklisted_stations = []
    blacklist = Params.blacklist
    ifile = open(blacklist, 'r')
    for line in ifile:
        blacklisted_stations.append(line.split()[0])
    ifile.close()
    for station in stations:
        if not (station in blacklisted_stations):
            new_stations.append(station)
        else:
            print("Excluding station %s due to blacklist_file %s" %
                  (station, Params.blacklist))
    return new_stations
def make_detrended_ts(Data, seasonals_remove, seasonals_type, data_config_file,
                      remove_trend=1, lakes_dir="../../GPS_POS_DATA/Hydro/Lake_loading/"):
    # The purpose of this function is to generate a version of the time series that has been
    # detrended and optionally seasonal-removed,
    # Where the seasonal fitting (if necessary) and detrending happen in the same function.
    # There are options for the seasonal removal (least squares, notch filter, grace, etc.)
    # Fit params definition: slope, a2(cos), a1(sin), s2, s1.
    # Here we are asking to invert the data for linear and seasonal components simultaneously

    Params = gps_io_functions.read_config_file(data_config_file);

    if seasonals_remove == 0:
        print("Not removing seasonals.");
        east_params = [0, 0, 0, 0, 0];
        north_params = [0, 0, 0, 0, 0];
        up_params = [0, 0, 0, 0, 0];
        [east_vel, north_vel, up_vel, _, _, _] = gps_ts_functions.get_slope(Data);
        east_params[0] = east_vel;
        north_params[0] = north_vel;
        up_params[0] = up_vel;
        trend_out = gps_ts_functions.detrend_data_by_value(Data, east_params, north_params, up_params);
        trend_in = Data;

    else:  # Going into different forms of seasonal removal.
        print("Removing seasonals by %s method." % seasonals_type);
        if seasonals_type == 'lssq':
            trend_out, trend_in = remove_seasonals_by_lssq(Data);

        elif seasonals_type == 'notch':
            trend_out, trend_in = remove_seasonals_by_notch(Data);

        elif seasonals_type == 'grace':
            trend_out, trend_in = remove_seasonals_by_GRACE(Data, Params.grace_dir);

        elif seasonals_type == 'stl':
            trend_out, trend_in = remove_seasonals_by_STL(Data, Params.stl_dir);

        elif seasonals_type == 'nldas':
            trend_out, trend_in = remove_seasonals_by_hydro(Data, Params.nldas_dir);

        elif seasonals_type == 'nldas_scaled':
            trend_out, trend_in = remove_seasonals_by_hydro(Data, Params.nldas_dir, scaling=True);

        elif seasonals_type == 'gldas':
            trend_out, trend_in = remove_seasonals_by_hydro(Data, Params.gldas_dir);

        elif seasonals_type == 'lsdm':
            trend_out, trend_in = remove_seasonals_by_german_load(Data, Params.lsdm_dir);

        elif seasonals_type == 'oroville':
            trend_out, trend_in = remove_seasonals_by_lakes(Data, lakes_dir, 'oroville');

        elif seasonals_type == 'shasta':
            trend_out, trend_in = remove_seasonals_by_lakes(Data, lakes_dir, 'shasta');

        else:
            print("Error: %s not supported as a seasonal removal type" % seasonals_type);
            print("The supported types are: lssq, grace, lsdm, nldas, nldas_scaled, gldas, notch, and stl");
            print("Exiting!\n");
            sys.exit(1);

    if remove_trend == 0:
        return trend_in;
    else:
        return trend_out;
Esempio n. 11
0
def pre_screen_datasource(data_config_file,
                          station,
                          input_datasource='pbo',
                          refframe="NA",
                          sub_network=''):
    # A defensive programming function that quits if it doesn't find the right file.
    print("\nStation %s: " % station)
    Params = gps_io_functions.read_config_file(data_config_file)
    if refframe == "NA":
        unr_reflabel = "NA"
        pbo_reflabel = "nam08"
        cwu_reflabel = "nam14"
        usgs_reflabel = "NAfixed"
    elif refframe == "ITRF":
        unr_reflabel = "IGS14"
        pbo_reflabel = "igs08"
        cwu_reflabel = "igs14"
        usgs_reflabel = "ITRF2008"
    else:
        print("ERROR! Unrecognized reference frame (choices NA and ITRF)")
        sys.exit(1)

    if input_datasource == 'usgs' and sub_network == '':
        network_list = query_usgs_network_name(station, Params.usgs_gps_dir)
        if len(network_list) == 1:
            sub_network = network_list[0].split('/')[-1]
        else:
            print(
                "ERROR! User must select one sub-network for USGS time series. Exiting. "
            )
            sys.exit(1)

    # Path setting
    if input_datasource == 'unr':
        filename = Params.unr_gps_dir + station + "." + unr_reflabel + ".tenv3"
    elif input_datasource == 'pbo':
        filename = Params.pbo_gps_dir + station + ".pbo.final_" + pbo_reflabel + ".pos"
    elif input_datasource == 'cwu':
        filename = Params.pbo_gps_dir + station + ".cwu.final_" + cwu_reflabel + ".pos"
    elif input_datasource == 'nmt':
        filename = Params.pbo_gps_dir + station + ".nmt.final_" + pbo_reflabel + ".pos"
    elif input_datasource == 'usgs':
        filename = Params.usgs_gps_dir + '/' + sub_network + '/' + station.lower(
        ) + "_" + usgs_reflabel + ".rneu"
    elif input_datasource == 'gldas':
        filename = Params.gldas_dir + station.lower() + "_noah10_gldas2.hyd"
    elif input_datasource == 'nldas':
        filename = Params.nldas_dir + station.lower() + "_noah125_nldas2.hyd"
    elif input_datasource == 'noah025':
        filename = Params.noah_dir + station + "_NOAH025.hyd"
    elif input_datasource == 'grace':
        filename = Params.grace_dir + "scaled_" + station + "_PREM_model_ts.txt"
    elif input_datasource == 'lsdm':
        filename = Params.lsdm_dir + station + "_LSDM_hydro.txt.txt"
    else:
        print("Error! Invalid input datasource %s" % input_datasource)
        sys.exit(1)

    # Determine if the file is found on the computer or not. Provide helpful suggestions if not.
    if os.path.isfile(filename):
        print("Found file %s from datasource %s %s " %
              (filename, input_datasource, sub_network))
    # If the file is not found on the computer:
    else:
        print("Error!  Cannot find %s in %s %s database." %
              (filename, input_datasource, sub_network))
        if input_datasource == 'usgs':
            print(
                "The station %s could be found in the following sub_networks instead: "
                % station)
            query_usgs_network_name(station, Params.usgs_gps_dir)
        print("Exiting immediately...")
        sys.exit(1)
    return input_datasource, sub_network
Esempio n. 12
0
def get_lsdm(data_config_file, station):
    Params = gps_io_functions.read_config_file(data_config_file)
    filename = Params.lsdm_dir + station + "_LSDM_hydro.txt.txt"
    [myData] = gps_io_functions.read_lsdm_file(filename)
    Offset = offsets.get_empty_offsets()
    return [myData, Offset, Offset]
Esempio n. 13
0
def get_grace(data_config_file, station):
    Params = gps_io_functions.read_config_file(data_config_file)
    filename = Params.grace_dir + "scaled_" + station + "_PREM_model_ts.txt"
    [myData] = gps_io_functions.read_grace(filename)
    Offset = offsets.get_empty_offsets()
    return [myData, Offset, Offset]