diff --git a/src/basic_io.py b/src/basic_io.py new file mode 100644 index 0000000..22e2068 --- /dev/null +++ b/src/basic_io.py @@ -0,0 +1,19 @@ + +import shapefile + +def extract_polyline_from_shapefile(s): + """ + :param s: shapefile.shape + returns: list of lon, list of lat + """ + return [coord[0] for coord in s.points], [coord[1] for coord in s.points]; + + +def read_one_fault_from_shapefile(shape_file, fault_index): + """ + A wrapper for extracting lon/lat from a fault in a shapefile. + One could also extract shapes = sf.shapes() + """ + sf = shapefile.Reader(shape_file); + lonarray1, latarray1 = extract_polyline_from_shapefile(sf.shape(fault_index)); + return lonarray1, latarray1; diff --git a/src/bin/Projects/Brawley/brawley_io.py b/src/bin/Projects/Brawley/brawley_io.py new file mode 100644 index 0000000..772425b --- /dev/null +++ b/src/bin/Projects/Brawley/brawley_io.py @@ -0,0 +1,13 @@ + + +def get_file_dictionary(config_filename): + """GET FILE NAMES from Brawley file dictionary.""" + this_dict = {}; + print("Reading file %s " % config_filename); + ifile = open(config_filename); + for line in ifile: + data_type = line.split(':')[0]; + total_data_files = line.split()[1]; # assuming one file per list entry + this_dict[data_type] = total_data_files; + ifile.close(); + return this_dict; diff --git a/src/bin/Projects/Brawley/compare_insar_lev.py b/src/bin/Projects/Brawley/compare_insar_lev.py index aeae51e..5294076 100755 --- a/src/bin/Projects/Brawley/compare_insar_lev.py +++ b/src/bin/Projects/Brawley/compare_insar_lev.py @@ -20,6 +20,7 @@ import sys from Geodesy_Modeling.src import general_utils, InSAR_1D_Object, Leveling_Object, UAVSAR from Tectonic_Utils.read_write import general_io +from .brawley_io import get_file_dictionary def compute_difference_metrics_on_same_pixels(list1, list2): @@ -35,19 +36,6 @@ def compute_difference_metrics_on_same_pixels(list1, list2): return misfit_metric, r2; -def get_file_dictionary(config_filename): - """GET FILE NAMES""" - this_dict = {}; - print("Reading file %s " % config_filename); - ifile = open(config_filename); - for line in ifile: - data_type = line.split(':')[0]; - total_data_files = line.split()[1]; # assuming one file per list entry - this_dict[data_type] = total_data_files; - ifile.close(); - return this_dict; - - def get_nearest_in_pixel_list(tuple_coord_list, target_lons, target_lats): """ Get the nearest index (and neighbors) for each given coordinate.