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 MakeAGrid(name, dir): dat = rd.Data_Level1(name, dir) dat.OneStep() GCP = dat.GCPs SigmaNaught = dat.denoiseNRCS y_lim, x_lim = SigmaNaught.shape del dat, SigmaNaught n = 10 gm.AllLonLat('Base', x_lim, y_lim, GCP, n) return None
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 Resample(n, mode='uniform'): d = rd.SentinelData() d.Get_List(file_root) m = 1 # resize factor for indice in range(n, len(d.series)): stt = time.time() 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 sub_img, up_left = cod.N_sub(tempN, SigmaNaught) del SigmaNaught, up_left jo.NMatrix_save(sub_img, 'SigmaNaught', temp_root) del sub_img md2.AllLonLat(name, x1, y1, GCP, m) img, pixel_num = md2.GridLL_SigmaNaught(mode) jo.Matrix_save(img, name, layer_root) jo.Matrix_save(pixel_num, name + '-distribution', layer_root) print('1 image:', (time.time() - stt) / 60, 'mins') print('Done!\n') return None
def Merge(root): s1 = datetime(2017, 1, 11) s2 = datetime(2019, 5, 25) datelist = [s1] nows = s1 while nows != s2: nows = nows + timedelta(days=12) datelist.append(nows) data = rd.winddata() data.GetData(datelist, root, ty='resize') np.save(root + 'u10.npy', data.u) np.save(root + 'v10.npy', data.v) # data.GetData(datelist, root) # np.save(root + 'u10-interp.npy', data.u) # np.save(root + 'v10-interp.npy', data.v) 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 MeanValue(): ll = rd.layers() ll.LoadData() ll.CalMean() return None
if __name__ == '__main__': s1 = datetime(2017,1,11) s2 = datetime(2019,5,25) datelist = [s1] nows = s1 while nows != s2: nows = nows + timedelta(days=12) datelist.append(nows) dates = [datetime.strftime(s, '%Y%m%d') for s in datelist] Nlist = list(range(36,67)) temp = rd.Grid_data() temp.LoadData() 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 tt = temp.mask[0] mask = temp.mask[1].astype(np.float_) del temp spd = wspeed_s2 - wspeed_cds wdd = wd_s2 - wd_cds del wspeed_cds, wspeed_s2, wd_cds, wd_s2 mask[mask == 0] = np.nan nums, rows, cols = spd.shape for n in range(36,nums): spd[n, :, :] = spd[n, :, :] * mask