def pp_fig(name, root=level2_root): file_list = os.listdir(layer_root) files = [ file for file in file_list if file.find(name) >= 0 and file.find('distribution') < 0 and file.find('npy') > 0 ] data = np.load(layer_root + files[0]) a = Lc.imp(data) a1 = a.dB(data) min_d = -30 max_d = 0 img = (a1 - min_d) * 255 / (max_d - min_d) img[img > 255] = 255 img[img < 0] = 0 rows, cols = a1.shape dpi = 100 fig = plt.figure(figsize=(cols / dpi, rows / dpi), dpi=dpi) ax = fig.add_subplot(111) ax.imshow(img, cmap='gray') rows, cols = img.shape cs = np.ones(rows, dtype=np.int) rs = np.ones(cols, dtype=np.int) cstd = np.arange(rows, dtype=np.int) rstd = np.arange(cols, dtype=np.int) for r in range(0, rows, 150): plt.plot(rstd, rs * r, 'b') for c in range(0, cols, 150): plt.plot(cs * c, cstd, 'b') plt.savefig(root + 'add_grid-' + name + '.png') plt.close()
def save_fig(name, r, c, u, v, root=level2_root): file_list = os.listdir(layer_root) files = [ file for file in file_list if file.find(name) >= 0 and file.find('distribution') < 0 and file.find('npy') > 0 ] data = np.load(layer_root + files[0]) a = Lc.imp(data) a1 = a.dB(data) min_d = -30 max_d = 0 img = (a1 - min_d) * 255 / (max_d - min_d) img[img > 255] = 255 img[img < 0] = 0 rows, cols = a1.shape dpi = 100 fig = plt.figure(figsize=(cols / dpi, rows / dpi), dpi=dpi) ax = fig.add_subplot(111) ax.imshow(img, cmap='gray') norm = mcolor.Normalize(vmin=0, vmax=20) m = [np.sqrt(u[i]**2 + v[i]**2) for i in range(len(r))] q = ax.quiver(c, r, u, v, m, width=0.001, headwidth=1, cmap='bwr', norm=norm) # q = ax.quiver(c,r,u,v, m,cmap = 'bwr', norm = norm) fig.colorbar(q, ax=ax) plt.savefig(root + name + '.png') plt.close()
def eliminate(sss): # N_list=list(range(38, 72)) # N_list.remove(39) # N_list.remove(58) # N_list.remove(69) N_list = list(range(36, 67)) temp = rd.Grid_data() temp.LoadData(ty=sss) wspeed_cds = np.sqrt(temp.u_cds * temp.u_cds + temp.v_cds * temp.v_cds) wspeed_s2 = np.sqrt(temp.u_s2 * temp.u_s2 + temp.v_s2 * temp.v_s2) wd_cds = np.arctan2(-temp.u_cds, -temp.v_cds) * 180 / np.pi wd_s2 = np.arctan2(-temp.u_s2, -temp.v_s2) * 180 / np.pi NRCS = temp.NRCS del temp tt = np.zeros(15, dtype=np.int8) ss = np.zeros_like(tt) ss[:] = 18 for r in range(15): for c in range(19): if wspeed_s2[42, r, c] > 0: tt[r] = max(tt[r], c) ss[r] = min(ss[r], c) nums = len(N_list) ws2 = np.zeros([nums, 15, 19], dtype=np.float_) wcds = np.zeros_like(ws2) ds2 = np.zeros_like(ws2) dcds = np.zeros_like(ws2) sigma = np.zeros_like(ws2) for r in range(15): if ss[r] <= tt[r]: for c in range(ss[r], tt[r] + 1): slist = Lc.Extract_NRCS(r, c, NRCS) sigma[:, r, c] = slist now = 0 for n in N_list: ws2[now, r, c] = wspeed_s2[n, r, c] wcds[now, r, c] = wspeed_cds[n, r, c] ds2[now, r, c] = wd_s2[n, r, c] dcds[now, r, c] = wd_cds[n, r, c] now += 1 # ds2 = np.where(ds2<0, ds2+360, ds2) for n in range(len(N_list)): for r in range(15): for c in range(19): if np.logical_not(np.isnan(ds2[n, r, c])): if ds2[n, r, c] < 0: ds2[n, r, c] += 360 if np.logical_not(np.isnan(dcds[n, r, c])): if dcds[n, r, c] < 0: dcds[n, r, c] += 360 # dcds = np.where(dcds<0, dcds+360, dcds) return sigma, ws2, wcds, ds2, dcds, ss, tt
def ResampleWind(): tt = np.load(coast_root + 'Left coast for each row.npy') d = rd.SentinelData() d.Get_List_NetCDF(ocn_root) for indice in range(len(d.series)): temp = rd.Data_Level2(d.series[indice], d.FList[indice]) temp.Get_WindData() temp.CalWindVector() mask = temp.windX.mask.reshape(-1) Ind = np.where(mask == 0)[0] lon = temp.lon.data.reshape(-1) lat = temp.lat.data.reshape(-1) U = temp.windX.data.reshape(-1) V = temp.windY.data.reshape(-1) lon, lat, U, V = lon[Ind], lat[Ind], U[Ind], V[Ind] r, c, u, v = md2.GridLL_Wind(lon, lat, U, V) ind = [xx for xx in range(len(r)) if tt[r[xx]] > c[xx]] r_new = [r[xx] for xx in ind] c_new = [c[xx] for xx in ind] u_new = [u[xx] for xx in ind] v_new = [v[xx] for xx in ind] r, c, u, v = r_new, c_new, u_new, v_new del r_new, c_new, u_new, v_new, ind # md2.save_fig(d.series[indice], r, c, u, v) if len(r) >= 4: u10, v10 = Lc.InterpolationWinds(r, c, u, v) np.save(level2_root + 'Interp/' + d.series[indice] + '-u10.npy', u10) np.save(level2_root + 'Interp/' + d.series[indice] + '-v10.npy', v10) u10 = np.zeros([15, 19], dtype=np.float16) v10 = np.zeros_like(u10) du = {} dv = {} for ii in range(len(r)): r1, c1 = r[ii] // 150, c[ii] // 150 if (r1, c1) in du: du[r1, c1].append(u[ii]) dv[r1, c1].append(v[ii]) else: du[r1, c1] = [u[ii]] dv[r1, c1] = [v[ii]] for rr, cc in du.keys(): u10[rr, cc] = np.mean(du[rr, cc]) v10[rr, cc] = np.mean(dv[rr, cc]) np.save(level2_root + 'NotInterp/' + d.series[indice] + '-u10.npy', u10) np.save(level2_root + 'NotInterp/' + d.series[indice] + '-v10.npy', v10) return None
def MatchCDS(): tt = np.load(coast_root + 'Left coast for each row.npy') data = rd.layers() data.LoadData() for indice in range(len(data.t)): lon, lat, u, v = md2.ReadCDSData(data.t[indice][:-1]) rows, cols = u.shape lon_N = [lon[c] for r in range(rows) for c in range(cols)] lat_N = [lat[r] for r in range(rows) for c in range(cols)] lon_N = np.array(lon_N) lat_N = np.array(lat_N) u, v = u.reshape(-1), v.reshape(-1) r, c, u, v = md2.GridLL_Wind(lon_N, lat_N, u, v) # ind = [xx for xx in range(len(r)) if tt[r[xx]] > c[xx]] # r_new = [r[xx] for xx in ind] # c_new = [c[xx] for xx in ind] # u_new = [u[xx] for xx in ind] # v_new = [v[xx] for xx in ind] # r, c, u, v = r_new, c_new, u_new, v_new # del r_new, c_new, u_new, v_new, ind # md2.save_fig(data.t[indice][:-1], r, c, u, v, cds_root) # if len(r)>=4: # u10, v10 = Lc.InterpolationWinds(r, c, u, v) # np.save(cds_root + 'Interp/' + data.t[indice][:-1] + '-u10.npy', u10) # np.save(cds_root + 'Interp/' + data.t[indice][:-1] + '-v10.npy', v10) # u10 = np.zeros([15,19], dtype = np.float16) # v10 = np.zeros_like(u10) du = {} dv = {} for ii in range(len(r)): r1, c1 = r[ii] // 150, c[ii] // 150 if (r1, c1) in du: du[r1, c1].append(u[ii]) dv[r1, c1].append(v[ii]) else: du[r1, c1] = [u[ii]] dv[r1, c1] = [v[ii]] # for rr, cc in du.keys(): # u10[rr, cc] = np.mean(du[rr, cc]) # v10[rr, cc] = np.mean(dv[rr, cc]) u10, v10 = Lc.InterpolationCDSwind(du, dv) np.save(cds_root + 'NotInterp/' + data.t[indice][:-1] + '-u10.npy', u10) np.save(cds_root + 'NotInterp/' + data.t[indice][:-1] + '-v10.npy', v10) return None
def OtherLayer(d, n): for indice in range(n, len(d.series)): temp = rd.Data_Level1(d.series[indice], d.FList[indice]) temp.OneStep() GCP = temp.GCPs SigmaNaught = temp.denoiseNRCS name = 'Layer' + str(indice) + '-' + d.series[indice] del temp y1, x1 = SigmaNaught.shape gm.AllLonLat(name, x1, y1, GCP, 5) start = time.time() SigmaNaught = Lc.Resize_SigmaNaught(SigmaNaught, 5) print('Time for resize SigmaNaught:', (time.time() - start) / 60, 'mins') Sigma_N, nums_arr = gm.GridSigmaNaught(SigmaNaught) print('Time for resampling 1 SAR image:', (time.time() - start) / 60, 'mins') jo.Matrix_save(Sigma_N, name, layer_root) return None
def DrawMap(name, layer, alpha, vmin, vmax): data = np.load('D:/Academic/MPS/Internship/Data/Sentinel/Level1/Layer/Layer40-20180518.npy') a = Lc.imp(data) a1 = a.dB(data) min_d, max_d = -30, 0 img = (a1 - min_d) * 255 / (max_d - min_d) img[np.isnan(img)] = 255 img[img > 255] = 255 img[img < 0] = 0 del a, a1 rows, cols = img.shape dpi = 100 fig = plt.figure(figsize=(cols / dpi, rows / dpi), dpi=dpi) ax = fig.add_subplot(111) ax.imshow(img, cmap='gray') cover = ax.imshow(layer.astype(np.float_), cmap = 'seismic', vmin =vmin, vmax = vmax, alpha = alpha) cbar = plt.colorbar(cover, fraction = 0.025, pad = 0.08) plt.gca().set_axis_off() plt.title(name, fontdict={'fontsize':36}, pad = 2.2) return None
def OneStepCoastline(): lon_grid, lat_grid = MergeGridLL() coastXYZ = Lc.LoadCoastlineXYZ() Line2Nodes(coastXYZ, lon_grid, lat_grid) line = np.load(coast_root + '/Coastline in Grid.npy') return line