Skip to content

Commit

Permalink
removing trailing semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaterna committed Jan 4, 2024
1 parent d946dbc commit c24841d
Show file tree
Hide file tree
Showing 22 changed files with 1,081 additions and 1,075 deletions.
32 changes: 16 additions & 16 deletions src/Downsample/geojson2txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ def read_geojson(infile):
# These properties will be unpacked into a named tuple that contains helpful information.

with open(infile) as f:
data = json.load(f);
features = data["features"]; # beginning to unpack the geojson
pixel_list = [];
data = json.load(f)
features = data["features"] # beginning to unpack the geojson
pixel_list = []
for feature in features:
# Unpacking what's in each pixel
bl = feature["geometry"]["coordinates"][0][0];
tr = feature["geometry"]["coordinates"][0][2];
bl = feature["geometry"]["coordinates"][0][0]
tr = feature["geometry"]["coordinates"][0][2]
mean = feature["properties"]["mean"] * 0.001
median = feature["properties"]["median"] * 0.001
std = feature["properties"]["std"] * 0.001
unitE = feature["properties"]["unitE"]
unitN = feature["properties"]["unitN"]
unitU = feature["properties"]["unitU"]
onePixel = Downsampled_pixel(mean=mean, median=median, std=std, BL_corner=bl, TR_corner=tr,
unitE=unitE, unitN=unitN, unitU=unitU);
pixel_list.append(onePixel);
return pixel_list;
unitE=unitE, unitN=unitN, unitU=unitU)
pixel_list.append(onePixel)
return pixel_list


def pixels_to_txt(pixel_list, text_file, bbox=(-180, 180, -90, 90), std_min=0.001):
Expand All @@ -57,16 +57,16 @@ def pixels_to_txt(pixel_list, text_file, bbox=(-180, 180, -90, 90), std_min=0.00
:param std_min: minimum value of uncertainty (m), defaults to 0.001
:type std_min: float, optional
"""
ofile = open(text_file, 'w');
ofile = open(text_file, 'w')
ofile.write("# Header: lon, lat, disp(m), sig(m), unitE, unitN, unitU from ground to satellite\n")
for pixel in pixel_list:
lon = np.mean([pixel.BL_corner[0], pixel.TR_corner[0]]);
lat = np.mean([pixel.BL_corner[1], pixel.TR_corner[1]]);
std = np.max([pixel.std, std_min]); # don't let uncertainty get unreasonably small
lon = np.mean([pixel.BL_corner[0], pixel.TR_corner[0]])
lat = np.mean([pixel.BL_corner[1], pixel.TR_corner[1]])
std = np.max([pixel.std, std_min]) # don't let uncertainty get unreasonably small
if bbox[0] <= lon <= bbox[1]:
if bbox[2] <= lat <= bbox[3]:
ofile.write("%.5f %.5f %.5f %.5f %.5f %.5f %.5f\n" % (
lon, lat, pixel.median, std, pixel.unitE, pixel.unitN, pixel.unitU));
ofile.close();
print("Writing %s with %d pixels " % (text_file, len(pixel_list)));
return;
lon, lat, pixel.median, std, pixel.unitE, pixel.unitN, pixel.unitU))
ofile.close()
print("Writing %s with %d pixels " % (text_file, len(pixel_list)))
return
22 changes: 11 additions & 11 deletions src/Downsample/pixel_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ class Downsampled_pixel:
downsampled pixel footprint, downsampled pixel look vector, and downsampled deformation values.
"""
def __init__(self, mean, median, std, BL_corner, TR_corner, unitE, unitN, unitU):
self.mean = mean; # mean of LOS values within the pixel (meters)
self.median = median; # median of LOS values within the pixel (meters)
self.std = std; # standard deviation of LOS values within the pixel (meters)
self.BL_corner = BL_corner; # Coordinates of Bottom Left corner (longitude, latitude)
self.TR_corner = TR_corner; # Coordinates of Top Right corner (longitude, latitude)
self.unitE = unitE; # east component of unit vector from ground to satellite
self.unitN = unitN; # north component of unit vector from ground to satellite
self.unitU = unitU; # up component of unit vector from ground to satellite
self.mean = mean # mean of LOS values within the pixel (meters)
self.median = median # median of LOS values within the pixel (meters)
self.std = std # standard deviation of LOS values within the pixel (meters)
self.BL_corner = BL_corner # Coordinates of Bottom Left corner (longitude, latitude)
self.TR_corner = TR_corner # Coordinates of Top Right corner (longitude, latitude)
self.unitE = unitE # east component of unit vector from ground to satellite
self.unitN = unitN # north component of unit vector from ground to satellite
self.unitU = unitU # up component of unit vector from ground to satellite

def set_mean(self, new_mean):
self.mean = new_mean;
self.mean = new_mean

def set_median(self, new_median):
self.median = new_median;
self.median = new_median

def set_std(self, new_std):
self.std = new_std;
self.std = new_std
82 changes: 41 additions & 41 deletions src/Downsample/plot_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,73 @@


def plot_downsampled_InSAR(pixel_list, plot_name, vmin=None, vmax=None):
plt.figure(figsize=(16, 8), dpi=300);
color_boundary_object = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True);
custom_cmap = cm.ScalarMappable(norm=color_boundary_object, cmap='rainbow');
plt.figure(figsize=(16, 8), dpi=300)
color_boundary_object = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
custom_cmap = cm.ScalarMappable(norm=color_boundary_object, cmap='rainbow')

# Getting lat and lon information for plotting.
xdim = [pixel.BL_corner[0] for pixel in pixel_list];
ydim = [pixel.BL_corner[1] for pixel in pixel_list];
xdim = [pixel.BL_corner[0] for pixel in pixel_list]
ydim = [pixel.BL_corner[1] for pixel in pixel_list]

# Plotting each pixel
for pixel in pixel_list:
x_total = [pixel.BL_corner[0], pixel.BL_corner[0], pixel.TR_corner[0], pixel.TR_corner[0]]
y_total = [pixel.BL_corner[1], pixel.TR_corner[1], pixel.TR_corner[1], pixel.BL_corner[1]]

fault_vertices = np.column_stack((x_total, y_total));
patch_color = custom_cmap.to_rgba(pixel.mean * 1000); # in mm
mypolygon = Polygon(fault_vertices, color=patch_color, alpha=1.0);
ax = plt.gca();
ax.add_patch(mypolygon);
fault_vertices = np.column_stack((x_total, y_total))
patch_color = custom_cmap.to_rgba(pixel.mean * 1000) # in mm
mypolygon = Polygon(fault_vertices, color=patch_color, alpha=1.0)
ax = plt.gca()
ax.add_patch(mypolygon)

# Plot formatting
plt.title('Downsampled %d pixels ' % (len(pixel_list)));
plt.ylim([np.min(ydim) - 0.05, np.max(ydim) + 0.05]);
plt.xlim([np.min(xdim) - 0.05, np.max(xdim) + 0.05]);
plt.title('Downsampled %d pixels ' % (len(pixel_list)))
plt.ylim([np.min(ydim) - 0.05, np.max(ydim) + 0.05])
plt.xlim([np.min(xdim) - 0.05, np.max(xdim) + 0.05])
plt.gca().tick_params(axis='both', which='major', labelsize=18)
custom_cmap.set_array(np.arange(vmin, vmax, 100));
cb = plt.colorbar(custom_cmap);
cb.set_label('mm', fontsize=22);
custom_cmap.set_array(np.arange(vmin, vmax, 100))
cb = plt.colorbar(custom_cmap)
cb.set_label('mm', fontsize=22)
for tick in cb.ax.yaxis.get_ticklabels():
tick.set_size(18)
plt.xlabel("Longitude", fontsize=18);
plt.ylabel("Latitude", fontsize=18);
plt.savefig(plot_name);
plt.close();
plt.xlabel("Longitude", fontsize=18)
plt.ylabel("Latitude", fontsize=18)
plt.savefig(plot_name)
plt.close()

# New figure for standard deviation of pixels
plt.figure(figsize=(16, 8), dpi=300);
color_boundary_object = matplotlib.colors.Normalize(vmin=0.0, vmax=5, clip=True);
custom_cmap = cm.ScalarMappable(norm=color_boundary_object, cmap='rainbow');
plt.figure(figsize=(16, 8), dpi=300)
color_boundary_object = matplotlib.colors.Normalize(vmin=0.0, vmax=5, clip=True)
custom_cmap = cm.ScalarMappable(norm=color_boundary_object, cmap='rainbow')

# Getting lat and lon information for plotting.
xdim = [pixel.BL_corner[0] for pixel in pixel_list];
ydim = [pixel.BL_corner[1] for pixel in pixel_list];
xdim = [pixel.BL_corner[0] for pixel in pixel_list]
ydim = [pixel.BL_corner[1] for pixel in pixel_list]

# Plotting each pixel
for pixel in pixel_list:
x_total = [pixel.BL_corner[0], pixel.BL_corner[0], pixel.TR_corner[0], pixel.TR_corner[0]]
y_total = [pixel.BL_corner[1], pixel.TR_corner[1], pixel.TR_corner[1], pixel.BL_corner[1]]

fault_vertices = np.column_stack((x_total, y_total));
patch_color = custom_cmap.to_rgba(pixel.std * 1000); # in mm
mypolygon = Polygon(fault_vertices, color=patch_color, alpha=1.0);
ax = plt.gca();
ax.add_patch(mypolygon);
fault_vertices = np.column_stack((x_total, y_total))
patch_color = custom_cmap.to_rgba(pixel.std * 1000) # in mm
mypolygon = Polygon(fault_vertices, color=patch_color, alpha=1.0)
ax = plt.gca()
ax.add_patch(mypolygon)

# Plot formatting
plt.title('Downsampled %d pixels ' % (len(pixel_list)));
plt.ylim([np.min(ydim) - 0.05, np.max(ydim) + 0.05]);
plt.xlim([np.min(xdim) - 0.05, np.max(xdim) + 0.05]);
plt.title('Downsampled %d pixels ' % (len(pixel_list)))
plt.ylim([np.min(ydim) - 0.05, np.max(ydim) + 0.05])
plt.xlim([np.min(xdim) - 0.05, np.max(xdim) + 0.05])
plt.gca().tick_params(axis='both', which='major', labelsize=18)
custom_cmap.set_array(np.arange(vmin, vmax, 100));
cb = plt.colorbar(custom_cmap);
cb.set_label('mm', fontsize=22);
custom_cmap.set_array(np.arange(vmin, vmax, 100))
cb = plt.colorbar(custom_cmap)
cb.set_label('mm', fontsize=22)
for tick in cb.ax.yaxis.get_ticklabels():
tick.set_size(18)
plt.xlabel("Longitude", fontsize=18);
plt.ylabel("Latitude", fontsize=18);
plt.xlabel("Longitude", fontsize=18)
plt.ylabel("Latitude", fontsize=18)
len_of_ext = len(plot_name.split('.')[-1]) + 1 # moving three spaces away from the end to add the file descriptor
plt.savefig(plot_name[0:-len_of_ext] + "_std" + plot_name[-len_of_ext:]);
plt.close();
return;
plt.savefig(plot_name[0:-len_of_ext] + "_std" + plot_name[-len_of_ext:])
plt.close()
return
26 changes: 13 additions & 13 deletions src/Downsample/quadtree_downsample_kite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Downsample a geocoded interferogram with quadtree;
Downsample a geocoded interferogram with quadtree
Write the outputs to a geojson.
The script below is the equivalent of fiddling with the file using the gui:
spool --load unwrap_ll.grd
Expand Down Expand Up @@ -29,15 +29,15 @@ def kite_downsample_isce_unw(datafile, outname,
:param tile_size_max: degrees
"""
from kite import Scene
print("Quadtree Downsampling the file %s into geojson %s " % (datafile, outname));
sc = Scene.import_data(datafile);
print("Quadtree Downsampling the file %s into geojson %s " % (datafile, outname))
sc = Scene.import_data(datafile)
qt = sc.quadtree
qt.epsilon = epislon
qt.nan_allowed = nan_allowed
qt.tile_size_min = tile_size_min
qt.tile_size_max = tile_size_max
qt.export_geojson(outname);
return;
qt.export_geojson(outname)
return

def kite_downsample(fname, outname, epislon=1, nan_allowed=0.99, tile_size_min=0.002, tile_size_max=0.010):
"""
Expand All @@ -51,23 +51,23 @@ def kite_downsample(fname, outname, epislon=1, nan_allowed=0.99, tile_size_min=0
:param tile_size_max: degrees
"""
from kite import Scene
print("Quadtree Downsampling the file %s into geojson %s " % (fname, outname));
sc = Scene.load(fname);
print("Quadtree Downsampling the file %s into geojson %s " % (fname, outname))
sc = Scene.load(fname)
qt = sc.quadtree
qt.epsilon = epislon
qt.nan_allowed = nan_allowed
qt.tile_size_min = tile_size_min
qt.tile_size_max = tile_size_max
qt.export_geojson(outname);
return;
qt.export_geojson(outname)
return


def geojson_to_outputs(geojsonfile, plotfile, textfile, bbox=(-180, 180, -90, 90), std_min=0.001, vmin=-120, vmax=20):
"""
Plot downsampled data and standard deviation.
Write a text file for inversion.
"""
pixel_list = geojson2txt.read_geojson(geojsonfile);
plot_geojson.plot_downsampled_InSAR(pixel_list, plotfile, vmin=vmin, vmax=vmax);
geojson2txt.pixels_to_txt(pixel_list, textfile, bbox, std_min); # can take a bbox optionally
return;
pixel_list = geojson2txt.read_geojson(geojsonfile)
plot_geojson.plot_downsampled_InSAR(pixel_list, plotfile, vmin=vmin, vmax=vmax)
geojson2txt.pixels_to_txt(pixel_list, textfile, bbox, std_min) # can take a bbox optionally
return
6 changes: 3 additions & 3 deletions src/Leveling_Object/leveling_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def plot_leveling_displacements(LevList, outfile, vmin=-0.25, vmax=0.15, scale=F
plt.scatter(lon, lat, c=disp, s=60, cmap='rainbow')
plt.plot(LevList[0].reflon, LevList[0].reflat, marker='*', markersize=20, color='black')
custom_cmap.set_array(np.arange(vmin, vmax))
cb = fig.colorbar(custom_cmap, ax=plt.gca())
cb = fig.colorbar(mappable=custom_cmap, ax=plt.gca())
cb.set_label("Leveling displacements (m)")
if title:
plt.title(title, fontsize=20)
Expand Down Expand Up @@ -133,10 +133,10 @@ def plot_leveling_slopes(LevList, slopes, description, plotname):
lon = [item.lon for item in LevList]
lat = [item.lat for item in LevList]
fig = plt.figure()
plt.scatter(lon, lat, c=slopes, s=40, vmin=-0.020, vmax=0.020, cmap='RdBu')
sc = plt.scatter(lon, lat, c=slopes, s=40, vmin=-0.020, vmax=0.020, cmap='RdBu')
plt.plot(LevList[0].reflon, LevList[0].reflat, marker='*')
plt.title(description, fontsize=20)
_cb = fig.colorbar(label='Displacement Rate (m/yr)', ax=plt.gca())
_cb = fig.colorbar(mappable=sc, label='Displacement Rate (m/yr)', ax=plt.gca())
plt.savefig(plotname)
return

Expand Down
Loading

0 comments on commit c24841d

Please sign in to comment.