Skip to content

Commit

Permalink
improvementt
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Souri committed Sep 22, 2022
1 parent fbfca01 commit fbb3640
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions GEOAkaze/qa_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cartopy.crs as ccrs
from matplotlib.ticker import FormatStrFormatter
from fpdf import FPDF
import matplotlib as mpl

class qa_geoakaze(object):

Expand Down Expand Up @@ -39,7 +40,6 @@ def read_netcdf(self,filename,var):
OUT:
var (float)
'''

nc_f = filename
nc_fid = Dataset(nc_f, 'r')
var = nc_fid.variables[var][:]
Expand All @@ -49,6 +49,10 @@ def read_netcdf(self,filename,var):
def gray_scale(self,random_selection_n=None):
'''
plotting gray_scale images with information from geoakaze_nc_fld
random_selection_n [int] is the number of grayscale images to be plotted.
If it's left as None, the code will plot all geoakaze nc files which can
be intense.
'''
geoakaze_diag_fnames = sorted(glob.glob(self.geoakaze_nc_fld + '/*.nc'))
# perform the random sampling if it's needed.
Expand Down Expand Up @@ -76,13 +80,13 @@ def gray_scale(self,random_selection_n=None):
ax.imshow(mair_gscale,origin='lower',
extent = [np.nanmin(mair_lon.flatten()), np.nanmax(mair_lon.flatten()),
np.nanmin(mair_lat.flatten()), np.nanmax(mair_lat.flatten())],
interpolation='nearest',aspect='auto')
interpolation='nearest',aspect='auto',cmap=mpl.colormaps['bone'])

# plotting msi
ax.imshow(msi_gscale,origin='lower',
extent = [np.nanmin(msi_lon.flatten()), np.nanmax(msi_lon.flatten()),
np.nanmin(msi_lat.flatten()), np.nanmax(msi_lat.flatten())],
interpolation='nearest',aspect='auto',alpha=0.3)
interpolation='nearest',aspect='auto',alpha=0.3,cmap=mpl.colormaps['bone'])

# plotting costlines
ax.coastlines(resolution='50m', color='black', linewidth = 2)
Expand All @@ -101,6 +105,7 @@ def gray_scale(self,random_selection_n=None):
ax.set_yticklabels(y_labels, fontsize = 13)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.3f'))

#plotting lat and lon
plt.xlabel('Lon',fontsize = 18)
plt.ylabel('Lat',fontsize = 18)

Expand Down Expand Up @@ -130,6 +135,7 @@ def histogram(self):
diff = np.sqrt(diff)
diff = np.nanmean(diff.flatten())
hist_x.append(diff*110*1000) # shift in meter

#plotting
fig = plt.figure(figsize=(8, 8))
plt.hist(hist_x, density=True, bins=30)
Expand All @@ -138,7 +144,9 @@ def histogram(self):
fig.savefig(self.temp_fld + "/histogram.png", format='png', dpi=300)

def trajectory(self):

'''
plotting the flight paths based on L1b data
'''

l1_files = sorted(glob.glob(self.L1b_folder + "/*.nc"))
fig = plt.figure(figsize=(8, 8))
Expand All @@ -154,16 +162,17 @@ def trajectory(self):
except:
print("the file is not readable")


plt.xlabel('Lon',fontsize = 18)
plt.ylabel('Lat',fontsize = 18)
fig.savefig(self.temp_fld + "/trajectory.png", format='png', dpi=300)

def topdf(self):

def header(pdfobj,title):
'''
save all pngs to a pdf report
'''
def header(pdfobj,title,fsize=8):
# Arial bold 15
pdfobj.set_font('Arial', 'B', 18)
pdfobj.set_font('Arial', 'B', fsize)
# Calculate width of title and position
w = pdfobj.get_string_width(title) + 6
pdfobj.set_x((210 - w) / 2)
Expand All @@ -182,34 +191,45 @@ def body(pdfobj,bd1):
# Output justified text
pdfobj.multi_cell(0, 5, bd1)
# Line break
pdfobj.ln()
pdfobj.ln(1)

# list only 15 examples of kmz files
geoakaze_kmz_fnames = sorted(glob.glob(self.geoakaze_kmz_fld + '/*.kmz'))
ind = np.random.randint(len(geoakaze_kmz_fnames),size=15)
ind = list(ind)
geoakaze_kmz_fnames = [ geoakaze_kmz_fnames[i] for i in ind]

# call the fpdf obj
pdf = FPDF()
pdf.add_page()

title = "The Orthorectification QA/QC Report generated by the GEOAKAZE tool"
w = header(pdf,title,fsize=20)
pdf.line(w, 30, 110, 30)
pdf.cell(w+2, 9, "Contact: [email protected]", 1, 1, 'C', 1)
# printing kmz paths
w = header(pdf,"KMZ files")
for fname in geoakaze_kmz_fnames:
body(pdf,str(fname))

# printing grayscales
pdf.add_page()
w = header(pdf,"MAIR grayscales")
grayscale_png = sorted(glob.glob(self.temp_fld + '/*_grayscale.png'))
for fname in grayscale_png:
pdf.image(fname,10,w,180,200)
pdf.add_page()

# printing trajectory
w = header(pdf,"Flight Path")
traj_png = glob.glob(self.temp_fld + '/traj*.png')
pdf.image(traj_png[0],10,w,200,220)

# printing histogram
pdf.add_page()
w = header(pdf,"Histogram of Shifts")
traj_png = glob.glob(self.temp_fld + '/hist*.png')
pdf.image(traj_png[0],10,w,200,220)

#writing
pdf.output(self.output_pdf, 'F')

0 comments on commit fbb3640

Please sign in to comment.