Skip to content

Commit

Permalink
adding very simple read-shapefile function
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaterna committed May 20, 2023
1 parent e45ed51 commit 501b641
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
19 changes: 19 additions & 0 deletions src/basic_io.py
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 13 additions & 0 deletions src/bin/Projects/Brawley/brawley_io.py
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 1 addition & 13 deletions src/bin/Projects/Brawley/compare_insar_lev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down

0 comments on commit 501b641

Please sign in to comment.