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
def input_to_tape(filename): if "unr" in filename or "UNR" in filename or "MIDAS" in filename or "midas" in filename: [velfield] = gps_io_functions.read_unr_vel_file(filename) infile = np.array((velfield[2], velfield[1], velfield[4], velfield[3], velfield[5], velfield[7], velfield[6], velfield[8])) name_field = velfield[0] lon = np.array(infile[0]) for i in range(len(lon)): if lon[i] >= 180: lon[i] = lon[i] - 360 starts = [] ends = [] for i in range(len(velfield[9])): start = float(velfield[9][i].date().strftime("%Y%m%d")) end = float(velfield[10][i].date().strftime("%Y%m%d")) # start = datetime.strptime(velfield[9], %Y%m%d) # end = datetime.strptime(velfield[10], %Y%m%d) starts.append(start) ends.append(end) infile = np.vstack( (lon, np.array(infile[1]), np.array(infile[2]), np.array(infile[3]), np.array(infile[4]), np.array(infile[5]), np.array(infile[6]), np.array(infile[7]), np.zeros(len(lon)), np.zeros(len(lon)), np.zeros(len(lon)), starts, ends)) elif "nam" in filename or "NAM" in filename: infile = np.loadtxt(filename, skiprows=37, usecols=(8, 7, 20, 19, 21, 23, 22, 24, 25, 27, 26, 28, 29), unpack=True) temp_file = open(filename, 'r') data = temp_file.readlines()[37:] temp_file.close() name_field = [] for line in data: name_field.append(line.split()[0]) lon = np.array(infile[0]) for i in range(len(lon)): if lon[i] >= 180: lon[i] = lon[i] - 360 infile = np.vstack(lon, infile[1:]) infile[2:10] = infile[2:10] * 1e3 else: print("Cannot read file format") outfile = np.vstack((infile, name_field)) outfile = np.transpose(outfile) return outfile
def inputs(input_file, num_years, max_sigma, coord_box, network): # Purpose: generate input velocity field. if network == 'pbo': [myVelfield] = gps_io_functions.read_pbo_vel_file(input_file) # read the raw velfield from file. elif network == 'unr': [myVelfield] = gps_io_functions.read_unr_vel_file(input_file) # read the raw velfield from file. else: print("ERROR! Network %s is not recognized. " % network) [myVelfield] = gps_io_functions.clean_velfield(myVelfield, num_years, max_sigma, coord_box) [myVelfield] = gps_io_functions.remove_duplicates(myVelfield) return myVelfield
def inputs(MyParams): # Purpose: generate input velocity field. if 'PBO' in MyParams.input_file or 'pbo' in MyParams.input_file: [myVelfield] = gps_io_functions.read_pbo_vel_file(MyParams.input_file) # read the raw velfield from file. elif 'MAGNET' in MyParams.input_file or 'unr' in MyParams.input_file: [myVelfield] = gps_io_functions.read_unr_vel_file(MyParams.input_file) # read the raw velfield from file. else: print("Error! Cannot read %s " % MyParams.input_file) sys.exit(1) print("%d stations before applying coord_box." % (len(myVelfield.name))) [myVelfield] = gps_io_functions.clean_velfield(myVelfield, MyParams.num_years, MyParams.max_sigma, MyParams.coord_box_data) [myVelfield] = gps_io_functions.remove_duplicates(myVelfield) print("%d stations after selection criteria." % (len(myVelfield.name))) return [myVelfield]