import numpy as np
import xsar as sr
import logging
import rasterio
import pickle
import xarray as xr
import matplotlib.pyplot as plt
import bokeh.io
bokeh.io.output_notebook()
import holoviews as hv
hv.extension('bokeh')
import datashader as ds
from holoviews.operation.datashader import datashade,rasterize
from IPython.display import display, HTML
logging.basicConfig()
logger = logging.getLogger('xsar')
logger.setLevel(logging.DEBUG)
filename = '/home/alevieux/Documents/Data/S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_992F.SAFE'
chunks = {'xtrack': 500, 'atrack': 200}
x0 = 0
y0 = 0
tilesize = 6400
xend = tilesize-1 # -1 car les slice inclus la valeur superieur (pas sarwing 6400x6400)
yend = tilesize-1 # -1 car les slice inclus la valeur superieur (pas sarwing 6400x6400)
polarization = 'VV'
def cmod5n_forward(v,phi,theta):
'''! ---------
! cmod5n_forward(v, phi, theta)
! inputs:
! v in [m/s] wind velocity (always >= 0)
! phi in [deg] angle between azimuth and wind direction
! (= D - AZM)
! theta in [deg] incidence angle
! output:
! CMOD5_N NORMALIZED BACKSCATTER (LINEAR)
!
! All inputs must be Numpy arrays of equal sizes
!
! A. STOFFELEN MAY 1991 ECMWF CMOD4
! A. STOFFELEN, S. DE HAAN DEC 2001 KNMI CMOD5 PROTOTYPE
! H. HERSBACH JUNE 2002 ECMWF COMPLETE REVISION
! J. de Kloe JULI 2003 KNMI, rewritten in fortan90
! A. Verhoef JAN 2008 KNMI, CMOD5 for neutral winds
! K.F.Dagestad OCT 2011 NERSC, Vectorized Python version
!---------------------------------------------------------------------
'''
from numpy import cos, exp, tanh, array
DTOR = 57.29577951
THETM = 40.
THETHR = 25.
ZPOW = 1.6
# NB: 0 added as first element below, to avoid switching from 1-indexing to 0-indexing
C = [0, -0.6878, -0.7957, 0.3380, -0.1728, 0.0000, 0.0040, 0.1103, 0.0159,
6.7329, 2.7713, -2.2885, 0.4971, -0.7250, 0.0450,
0.0066, 0.3222, 0.0120, 22.7000, 2.0813, 3.0000, 8.3659,
-3.3428, 1.3236, 6.2437, 2.3893, 0.3249, 4.1590, 1.6930]
Y0 = C[19]
PN = C[20]
A = C[19]-(C[19]-1)/C[20]
B = 1./(C[20]*(C[19]-1.)**(3-1))
# ! ANGLES
FI=phi/DTOR
CSFI = cos(FI)
CS2FI= 2.00 * CSFI * CSFI - 1.00
X = (theta - THETM) / THETHR
XX = X*X
# ! B0: FUNCTION OF WIND SPEED AND INCIDENCE ANGLE
A0 =C[ 1]+C[ 2]*X+C[ 3]*XX+C[ 4]*X*XX
A1 =C[ 5]+C[ 6]*X
A2 =C[ 7]+C[ 8]*X
GAM=C[ 9]+C[10]*X+C[11]*XX
S0 =C[12]+C[13]*X
# V is missing! Using V=v as substitute, this is apparently correct
V=v
S = A2*V
S_vec = S.copy()
SlS0 = [S_vec<S0]
#print(SlS0)
#print(S_vec)
#print(S0)
S_vec[SlS0]=S0[SlS0]
A3=1./(1.+exp(-S_vec))
SlS0 = (S<S0)
A3[SlS0]=A3[SlS0]*(S[SlS0]/S0[SlS0])**( S0[SlS0]*(1.- A3[SlS0]))
#A3=A3*(S/S0)**( S0*(1.- A3))
B0=(A3**GAM)*10.**(A0+A1*V)
# ! B1: FUNCTION OF WIND SPEED AND INCIDENCE ANGLE
B1 = C[15]*V*(0.5+X-tanh(4.*(X+C[16]+C[17]*V)))
B1 = C[14]*(1.+X)- B1
B1 = B1/(exp( 0.34*(V-C[18]) )+1.)
# ! B2: FUNCTION OF WIND SPEED AND INCIDENCE ANGLE
V0 = C[21] + C[22]*X + C[23]*XX
D1 = C[24] + C[25]*X + C[26]*XX
D2 = C[27] + C[28]*X
V2 = (V/V0+1.)
V2ltY0 = V2<Y0
V2[V2ltY0] = A+B*(V2[V2ltY0]-1.)**PN
B2 = (-D1+D2*V2)*exp(-V2)
# ! CMOD5_N: COMBINE THE THREE FOURIER TERMS
CMOD5_N = B0*(1.0+B1*CSFI+B2*CS2FI)**ZPOW
return CMOD5_N
def cmod5n_inverse(sigma0_obs, phi, incidence, iterations=10):
'''! ---------
! cmod5n_inverse(sigma0_obs, phi, incidence, iterations)
! inputs:
! sigma0_obs Normalized Radar Cross Section [linear units]
! phi in [deg] angle between azimuth and wind direction
! (= D - AZM)
! incidence in [deg] incidence angle
! iterations: number of iterations to run
! output:
! Wind speed, 10 m, neutral stratification
!
! All inputs must be Numpy arrays of equal sizes
!
! This function iterates the forward CMOD5N function
! until agreement with input (observed) sigma0 values
!---------------------------------------------------------------------
'''
from numpy import ones, array
# First guess wind speed
V = array([10.])*ones(sigma0_obs.shape);
step=10.
# Iterating until error is smaller than threshold
for iterno in range(1, iterations):
#print iterno
sigma0_calc = cmod5n_forward(V, phi, incidence)
ind = sigma0_calc-sigma0_obs>0
V = V + step
V[ind] = V[ind] - 2*step
step = step/2
#mdict={'s0obs':sigma0_obs,'s0calc':sigma0_calc}
#from scipy.io import savemat
#savemat('s0test',mdict)
return V
def model_ifr2(wind_speed, wind_dir, inc_angle):
"""
; Renvoie une NRCS prédite par modèle IFR2
;
; INPUTS:
; inc_angle:
; wind_speed:
; wind_dir:
;
; OPTIONAL INPUTS:
; wind_speed:
;
"""
C = np.zeros(26)
# init CMOD-IFR2 coef
C[0] = 0.0
C[1] = -2.437597
C[2] = -1.5670307
C[3] = 0.3708242
C[4] = -0.040590
C[5] = 0.404678
C[6] = 0.188397
C[7] = -0.027262
C[8] = 0.064650
C[9] = 0.054500
C[10] = 0.086350
C[11] = 0.055100
C[12] = -0.058450
C[13] = -0.096100
C[14] = 0.412754
C[15] = 0.121785
C[16] = -0.024333
C[17] = 0.072163
C[18] = -0.062954
C[19] = 0.015958
C[20] = -0.069514
C[21] = -0.062945
C[22] = 0.035538
C[23] = 0.023049
C[24] = 0.074654
C[25] = -0.014713
T=inc_angle
wind=wind_speed
tetai = (T - 36.)/19.
xSQ = tetai*tetai
P0 = 1.
P1 = tetai
P2 = (3.*xSQ-1.)/2.
P3 = (5.*xSQ-3.)*tetai/2.
ALPH = C[1] + C[2] * P1 + C[3] * P2 + C[4]*P3
BETA = C[5] + C[6] * P1 + C[7] * P2
ang = wind_dir
cosi = np.cos(np.deg2rad(ang))
cos2i = 2.*cosi*cosi - 1.
#b1 = self.funcB1(T, wind)
############## fonction funcB1 ###################
tetamin = 18.
tetamax = 58.
tetanor = (2.*T - (tetamin+tetamax))/(tetamax-tetamin)
vmin = 3.
vmax = 25.
vitnor = (2.*wind - (vmax+vmin))/(vmax-vmin)
pv0 = 1.
pv1 = vitnor
pv2 = 2*vitnor*pv1 - pv0
pv3 = 2*vitnor*pv2 - pv1
pt0 = 1.
pt1 = tetanor
pt2 = 2*tetanor*pt1 - pt0
pt3 = 2*tetanor*pt2 - pt1
b1 = C[8] + C[9]*pv1 + (C[10]+C[11]*pv1)*pt1 + (C[12]+C[13]*pv1)*pt2
##################################################
#b2 = self.funcB2(T, wind)
############## fonction funcB2 ###################
tetamin = 18.
tetamax = 58.
tetanor = (2.*T - (tetamin+tetamax))/(tetamax-tetamin)
vmin = 3.
vmax = 25.
vitnor = (2.*wind - (vmax+vmin))/(vmax-vmin)
pv0 = 1.
pv1 = vitnor
pv2 = 2*vitnor*pv1 - pv0
pv3 = 2*vitnor*pv2 - pv1
pt0 = 1.
pt1 = tetanor
pt2 = 2*tetanor*pt1 - pt0
pt3 = 2*tetanor*pt2 - pt1
result = C[14] + C[15]*pt1 + C[16]*pt2 + \
(C[17]+C[18]*pt1+C[19]*pt2)*pv1 + (C[20]+C[21]*pt1+C[22]*pt2)*pv2 + \
(C[23]+C[24]*pt1+C[25]*pt2)*pv3
b2=result
##################################################
b0 = np.power(10., (ALPH+BETA*np.sqrt(wind)))
sig = b0 * ( 1. + b1*cosi + np.tanh(b2)*cos2i )
return sig
image_full_resolution = sr.open_dataset(filename, chunks=chunks, pol_dim=True)[0]
image_full_resolution
DEBUG:xsar.utils:timing load_digital_number : 0.0s. mem: +5.3Mb DEBUG:xsar.utils:timing load_geometry : 0.1s. mem: +1.9Mb DEBUG:xsar.utils:timing luts_from_xml_calibration : 0.2s. mem: +18.7Mb DEBUG:xsar.utils:timing luts_from_xml_calibration : 0.1s. mem: +19.6Mb DEBUG:xsar.utils:timing luts_from_xml_noise : 0.3s. mem: +18.7Mb DEBUG:xsar.utils:timing luts_from_xml_noise : 0.4s. mem: +10.5Mb DEBUG:xsar.utils:timing load_luts : 1.0s. mem: +75.4Mb DEBUG:xsar.utils:timing luts_from_xml_anotation : 0.2s. mem: +9.5Mb DEBUG:xsar.utils:timing luts_from_xml_anotation : 0.1s. mem: +13.9Mb DEBUG:xsar.utils:timing load_luts : 0.3s. mem: +14.3Mb DEBUG:xsar.utils:timing load_lon_lat : 0.1s. mem: +9.2Mb DEBUG:xsar.utils:timing _get_subdatasets : 1.8s. mem: +132.6Mb DEBUG:xsar.utils:timing apply_cf_convention : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing open_dataset : 1.8s. mem: +133.7Mb
<xarray.Dataset> Dimensions: (atrack: 16778, pol: 2, xtrack: 25187) Coordinates: * pol (pol) object 'VV' 'VH' * atrack (atrack) int64 0 1 2 3 4 5 ... 16773 16774 16775 16776 16777 * xtrack (xtrack) int64 0 1 2 3 4 5 ... 25182 25183 25184 25185 25186 Data variables: digital_number (pol, atrack, xtrack) uint16 dask.array<chunksize=(2, 200, 500), meta=np.ndarray> time (atrack) datetime64[ns] dask.array<chunksize=(200,), meta=np.ndarray> longitude (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> latitude (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> incidence (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> elevation (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> sigma0_lut (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> gamma0_lut (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> noise_lut (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> sigma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> nesz (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> gamma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> negz (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> Attributes: footprint: POLYGON ((-67.84221143971432 20.72564283093837, -70.2216... coverage: 251km * 170km (xtrack * atrack ) pixel_xtrack_m: 10.0 pixel_atrack_m: 10.2 ipf_version: 2.84 swath_type: IW polarizations: VV VH product_type: GRD mission: SENTINEL-1 satellite: A start_date: 2017-09-07 10:30:20.936409 stop_date: 2017-09-07 10:30:45.935264 subdataset: IW geometry: ge... Conventions: CF-1.7
array(['VV', 'VH'], dtype=object)
array([ 0, 1, 2, ..., 16775, 16776, 16777])
array([ 0, 1, 2, ..., 25184, 25185, 25186])
|
|
|
|
|
|
|
|
|
|
|
|
|
tile_6400x6400_full_resolution = image_full_resolution.sel(xtrack=range(x0, tilesize), atrack=range(y0, tilesize))
tile_6400x6400_full_resolution
<xarray.Dataset> Dimensions: (atrack: 6400, pol: 2, xtrack: 6400) Coordinates: * pol (pol) object 'VV' 'VH' * atrack (atrack) int64 0 1 2 3 4 5 ... 6394 6395 6396 6397 6398 6399 * xtrack (xtrack) int64 0 1 2 3 4 5 ... 6394 6395 6396 6397 6398 6399 Data variables: digital_number (pol, atrack, xtrack) uint16 dask.array<chunksize=(2, 200, 500), meta=np.ndarray> time (atrack) datetime64[ns] dask.array<chunksize=(200,), meta=np.ndarray> longitude (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> latitude (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> incidence (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> elevation (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> sigma0_lut (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> gamma0_lut (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> noise_lut (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> sigma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> nesz (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> gamma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> negz (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> Attributes: footprint: POLYGON ((-67.84221143971432 20.72564283093837, -70.2216... coverage: 251km * 170km (xtrack * atrack ) pixel_xtrack_m: 10.0 pixel_atrack_m: 10.2 ipf_version: 2.84 swath_type: IW polarizations: VV VH product_type: GRD mission: SENTINEL-1 satellite: A start_date: 2017-09-07 10:30:20.936409 stop_date: 2017-09-07 10:30:45.935264 subdataset: IW geometry: ge... Conventions: CF-1.7
array(['VV', 'VH'], dtype=object)
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
|
|
|
|
|
|
|
|
|
|
|
|
|
sigma0_tile_6400x6400_full_resolution_vv = tile_6400x6400_full_resolution.sigma0.sel(pol=polarization)
nesz_tile_6400x6400_full_resolution_vv = tile_6400x6400_full_resolution.nesz.sel(pol=polarization)
sigma0_denoised_tile_6400x6400_full_resolution_vv = np.maximum(sigma0_tile_6400x6400_full_resolution_vv - nesz_tile_6400x6400_full_resolution_vv, 0)
sigma0_denoised_tile_6400x6400_full_resolution_vv
<xarray.DataArray (atrack: 6400, xtrack: 6400)> dask.array<maximum, shape=(6400, 6400), dtype=float64, chunksize=(200, 500), chunktype=numpy.ndarray> Coordinates: pol <U2 'VV' * atrack (atrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399 * xtrack (xtrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399
|
array('VV', dtype='<U2')
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv.pkl', 'rb'), encoding='bytes')
sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv_dataset = xr.DataArray(sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv, dims=( "xtrack", "atrack"), coords={"xtrack":range(0,6400,1), "atrack":range(0,6400,1)})
sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv_dataset
<xarray.DataArray (xtrack: 6400, atrack: 6400)> array([[0. , 0. , 0. , ..., 0.23613784, 0.21474715, 0.21177629], [0. , 0. , 0. , ..., 0.31893268, 0.37767802, 0.32808411], [0. , 0. , 0. , ..., 0.18040625, 0.20881903, 0.23771222], ..., [0. , 0. , 0. , ..., 0.42235672, 0.56886138, 0.42028585], [0. , 0. , 0. , ..., 0.49402371, 0.37178744, 0.31713959], [0. , 0. , 0. , ..., 0.58101842, 0.28710154, 0.22380615]]) Coordinates: * xtrack (xtrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399 * atrack (atrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399
array([[0. , 0. , 0. , ..., 0.23613784, 0.21474715, 0.21177629], [0. , 0. , 0. , ..., 0.31893268, 0.37767802, 0.32808411], [0. , 0. , 0. , ..., 0.18040625, 0.20881903, 0.23771222], ..., [0. , 0. , 0. , ..., 0.42235672, 0.56886138, 0.42028585], [0. , 0. , 0. , ..., 0.49402371, 0.37178744, 0.31713959], [0. , 0. , 0. , ..., 0.58101842, 0.28710154, 0.22380615]])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
# slice car plantage de jupyter car trop de donnée (timeout) mais pour ça valide
ds_xsar = sigma0_denoised_tile_6400x6400_full_resolution_vv.sel(xtrack=slice(0,6400,40), atrack=slice(0,6400,40))
ds_sarwing = sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv_dataset.sel(xtrack=slice(0,6400,40), atrack=slice(0,6400,40))
diff = (ds_xsar - ds_sarwing).rename("Diff xsar - sarwingsigma0 denoised %s" % polarization)
std = np.nanstd(diff)
mean = np.nanmean(diff)
plots=[]
r = np.nanpercentile(ds_sarwing,98)
#r = 0.71
plots.append(
rasterize(hv.Image(
sarwing_sigma0_denoised_tile_6400x6400_full_resolution_vv_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="sarwing"))
)
plots.append(
rasterize(hv.Image(
sigma0_denoised_tile_6400x6400_full_resolution_vv
).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
)
plots.append(
hv.Scatter(
(ds_xsar,ds_sarwing),
kdims='xsar', vdims='sarwing'
).opts(alpha=0.01,xlim=(0,r),ylim=(0,r),title='std=%.3f bias=%.3f' % (std,mean)) * hv.Path([(0.,0.),(r,r)]).opts(color='black', line_width=2, alpha=0.2)
)
hv.Layout(plots).cols(2).opts(title="Validation sigma0 denoised %s xsar/sarwing" % polarization)
trouver un vrai nom qui soit plus précis
incidence_full_resolution_xtrack_line1 = image_full_resolution.incidence.sel(atrack=[0])
incidence_full_resolution_xtrack_line1
<xarray.DataArray 'incidence' (atrack: 1, xtrack: 25187)> dask.array<getitem, shape=(1, 25187), dtype=float32, chunksize=(1, 500), chunktype=numpy.ndarray> Coordinates: * atrack (atrack) int64 0 * xtrack (xtrack) int64 0 1 2 3 4 5 ... 25181 25182 25183 25184 25185 25186
|
array([0])
array([ 0, 1, 2, ..., 25184, 25185, 25186])
sarwing_incidence_line1_image_full_resolution = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_incidence_line1_image_full_resolution.pkl', 'rb'), encoding='bytes')
sarwing_incidence_line1_image_full_resolution_dataset = xr.DataArray(sarwing_incidence_line1_image_full_resolution, dims=( "xtrack", "atrack"), coords={"xtrack":range(0,1,1), "atrack":range(0,25187,1)})
sarwing_incidence_line1_image_full_resolution_dataset
<xarray.DataArray (xtrack: 1, atrack: 25187)> array([[30.8156529 , 30.81635922, 30.81706554, ..., 45.98284466, 45.98334994, 45.9838552 ]]) Coordinates: * xtrack (xtrack) int64 0 * atrack (atrack) int64 0 1 2 3 4 5 ... 25181 25182 25183 25184 25185 25186
array([[30.8156529 , 30.81635922, 30.81706554, ..., 45.98284466, 45.98334994, 45.9838552 ]])
array([0])
array([ 0, 1, 2, ..., 25184, 25185, 25186])
hv.Scatter(
(incidence_full_resolution_xtrack_line1,sarwing_incidence_line1_image_full_resolution),
kdims='xsar', vdims='sarwing').opts(title='Incidence xtrack line1 full resolution xsar/sarwing') * hv.Path([(30,30),(50,50)]).opts(color='black', line_width=2, alpha=0.2)
nrcs_gmf_nice_display_full_resolution_incidence_line1 = model_ifr2(10., 45, incidence_full_resolution_xtrack_line1.values)
nrcs_gmf_nice_display_full_resolution_incidence_line1_dataset = xr.DataArray(nrcs_gmf_nice_display_full_resolution_incidence_line1, dims=( "atrack", "xtrack"), coords={"atrack":range(0,1,1), "xtrack":range(0,25187,1)})
nrcs_gmf_nice_display_full_resolution_incidence_line1_dataset
<xarray.DataArray (atrack: 1, xtrack: 25187)> array([[0.09855015, 0.09854061, 0.09853113, ..., 0.02241875, 0.02241801, 0.02241727]], dtype=float32) Coordinates: * atrack (atrack) int64 0 * xtrack (xtrack) int64 0 1 2 3 4 5 ... 25181 25182 25183 25184 25185 25186
array([[0.09855015, 0.09854061, 0.09853113, ..., 0.02241875, 0.02241801, 0.02241727]], dtype=float32)
array([0])
array([ 0, 1, 2, ..., 25184, 25185, 25186])
sarwing_nrcs_gmf_nice_display_full_resolution_incidence_line1 = [pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_nrcs_gmf_nice_display_full_resolution_incidence_line1.pkl', 'rb'), encoding='bytes')]
sarwing_nrcs_gmf_nice_display_full_resolution_incidence_line1_dataset = xr.DataArray(sarwing_nrcs_gmf_nice_display_full_resolution_incidence_line1, dims=( "atrack", "xtrack"), coords={"atrack":range(0,1,1), "xtrack":range(0,25187,1)})
sarwing_nrcs_gmf_nice_display_full_resolution_incidence_line1_dataset
<xarray.DataArray (atrack: 1, xtrack: 25187)> array([[0.09856078, 0.09855118, 0.09854159, ..., 0.02241968, 0.02241894, 0.0224182 ]], dtype=float32) Coordinates: * atrack (atrack) int64 0 * xtrack (xtrack) int64 0 1 2 3 4 5 ... 25181 25182 25183 25184 25185 25186
array([[0.09856078, 0.09855118, 0.09854159, ..., 0.02241968, 0.02241894, 0.0224182 ]], dtype=float32)
array([0])
array([ 0, 1, 2, ..., 25184, 25185, 25186])
hv.Scatter(
(nrcs_gmf_nice_display_full_resolution_incidence_line1_dataset,sarwing_nrcs_gmf_nice_display_full_resolution_incidence_line1_dataset),
kdims='xsar', vdims='sarwing').opts(title='Nrcs gmf with incidence xtrack line1 full resolution xsar/sarwing') * hv.Path([(0.,0.),(0.1,0.1)]).opts(color='black', line_width=2, alpha=0.2)
nrcs_gmf_tile_6400x6400_full_resolution_slice = nrcs_gmf_nice_display_full_resolution_incidence_line1[0][x0:tilesize:1]
nrcs_gmf_tile_6400x6400_full_resolution = np.outer(np.ones((6400//1,), dtype=np.float32), nrcs_gmf_tile_6400x6400_full_resolution_slice)
nrcs_gmf_tile_6400x6400_full_resolution_dataset = xr.DataArray(nrcs_gmf_tile_6400x6400_full_resolution, dims=( "xtrack", "atrack"), coords={"atrack":range(0,6400,1), "xtrack":range(0,6400,1)})
nrcs_gmf_tile_6400x6400_full_resolution_dataset
#nrcs_slice = self._tab_nrcs[polarization, swath][x0:x0+xsize:xfactor]
#nrcs = np.outer(np.ones((ysize//yfactor,), dtype=np.float32), nrcs_slice)
<xarray.DataArray (xtrack: 6400, atrack: 6400)> array([[0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], ..., [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434]], dtype=float32) Coordinates: * atrack (atrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399 * xtrack (xtrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399
array([[0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], ..., [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434], [0.09855015, 0.09854061, 0.09853113, ..., 0.05735269, 0.05734854, 0.05734434]], dtype=float32)
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
sarwing_nrcs_gmf_tile_6400x6400_full_resolution = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_nrcs_gmf_tile_6400x6400_full_resolution.pkl', 'rb'), encoding='bytes')
sarwing_nrcs_gmf_tile_6400x6400_full_resolution_dataset = xr.DataArray(sarwing_nrcs_gmf_tile_6400x6400_full_resolution, dims=( "xtrack", "atrack"), coords={"atrack":range(0,6400,1), "xtrack":range(0,6400,1)})
sarwing_nrcs_gmf_tile_6400x6400_full_resolution_dataset
<xarray.DataArray (xtrack: 6400, atrack: 6400)> array([[0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], ..., [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961]], dtype=float32) Coordinates: * atrack (atrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399 * xtrack (xtrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399
array([[0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], ..., [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961], [0.09856078, 0.09855118, 0.09854159, ..., 0.057348 , 0.0573438 , 0.05733961]], dtype=float32)
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
ds_xsar = nrcs_gmf_tile_6400x6400_full_resolution_dataset.sel(xtrack=slice(0,6400,40), atrack=slice(0,6400,40))
ds_sarwing = sarwing_nrcs_gmf_tile_6400x6400_full_resolution_dataset.sel(xtrack=slice(0,6400,40), atrack=slice(0,6400,40))
diff = (ds_xsar - ds_sarwing).rename("Diff xsar - sarwing nrcs gmf %s")
std = np.nanstd(diff)
mean = np.nanmean(diff)
plots=[]
r = np.nanpercentile(ds_sarwing,98)
#r = 0.71
plots.append(
rasterize(hv.Image(
sarwing_nrcs_gmf_tile_6400x6400_full_resolution_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="sarwing"))
)
plots.append(
rasterize(hv.Image(
nrcs_gmf_tile_6400x6400_full_resolution_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
)
plots.append(
hv.Scatter(
(ds_xsar,ds_sarwing),
kdims='xsar', vdims='sarwing'
).opts(alpha=0.01,xlim=(0,r),ylim=(0,r),title='std=%.3f bias=%.3f' % (std,mean)) * hv.Path([(0.,0.),(r,r)]).opts(color='black', line_width=2, alpha=0.2)
)
hv.Layout(plots).cols(2).opts(title="Validation nrcs gmf full resolution %s xsar/sarwing" % polarization)
image_size_atrack = image_full_resolution.atrack.size
image_size_xtrack = image_full_resolution.xtrack.size
nx = 40
ny = int(np.round((float(image_size_atrack)/float(image_size_xtrack))*float(nx)))
spacing_x = int(image_size_xtrack/nx)
spacing_y = int(image_size_atrack/ny)
image_reduite_nx_ny = image_full_resolution.sel(xtrack=slice(0, image_size_xtrack, spacing_x), atrack=slice(0, image_size_atrack, spacing_y))
image_reduite_nx_ny_incidence = image_reduite_nx_ny.incidence
image_reduite_nx_ny_incidence
<xarray.DataArray 'incidence' (atrack: 28, xtrack: 41)> dask.array<getitem, shape=(28, 41), dtype=float32, chunksize=(1, 1), chunktype=numpy.ndarray> Coordinates: * atrack (atrack) int64 0 621 1242 1863 2484 ... 14904 15525 16146 16767 * xtrack (xtrack) int64 0 629 1258 1887 2516 ... 23273 23902 24531 25160
|
array([ 0, 621, 1242, 1863, 2484, 3105, 3726, 4347, 4968, 5589, 6210, 6831, 7452, 8073, 8694, 9315, 9936, 10557, 11178, 11799, 12420, 13041, 13662, 14283, 14904, 15525, 16146, 16767])
array([ 0, 629, 1258, 1887, 2516, 3145, 3774, 4403, 5032, 5661, 6290, 6919, 7548, 8177, 8806, 9435, 10064, 10693, 11322, 11951, 12580, 13209, 13838, 14467, 15096, 15725, 16354, 16983, 17612, 18241, 18870, 19499, 20128, 20757, 21386, 22015, 22644, 23273, 23902, 24531, 25160])
sarwing_nrcs_model_inc_reduce_nx_ny_28_41 = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_nrcs_model_inc_reduce_nx_ny_28_41.pkl', 'rb'), encoding='bytes')
sarwing_nrcs_model_inc_reduce_nx_ny_28_41_dataset = xr.DataArray(sarwing_nrcs_model_inc_reduce_nx_ny_28_41, dims=("atrack", "xtrack"), coords={"atrack":range(0, 16777, 621), "xtrack":range(0,25186,629)})
sarwing_nrcs_model_inc_reduce_nx_ny_28_41_dataset
<xarray.DataArray (atrack: 28, xtrack: 41)> array([[30.8156529 , 31.25819079, 31.69794762, ..., 45.34153468, 45.6641198 , 45.9838552 ], [30.81627416, 31.25880969, 31.69856409, ..., 45.34204994, 45.66463226, 45.98436487], [30.816891 , 31.25942416, 31.69917615, ..., 45.34256166, 45.6651412 , 45.98487105], ..., [30.82984159, 31.2723235 , 31.71202358, ..., 45.35332675, 45.67584725, 45.99551827], [30.83034905, 31.27282909, 31.71252727, ..., 45.35374911, 45.67626717, 45.99593574], [30.83085263, 31.27333084, 31.71302716, ..., 45.35416824, 45.67668385, 45.99634997]]) Coordinates: * atrack (atrack) int64 0 621 1242 1863 2484 ... 14904 15525 16146 16767 * xtrack (xtrack) int64 0 629 1258 1887 2516 ... 23273 23902 24531 25160
array([[30.8156529 , 31.25819079, 31.69794762, ..., 45.34153468, 45.6641198 , 45.9838552 ], [30.81627416, 31.25880969, 31.69856409, ..., 45.34204994, 45.66463226, 45.98436487], [30.816891 , 31.25942416, 31.69917615, ..., 45.34256166, 45.6651412 , 45.98487105], ..., [30.82984159, 31.2723235 , 31.71202358, ..., 45.35332675, 45.67584725, 45.99551827], [30.83034905, 31.27282909, 31.71252727, ..., 45.35374911, 45.67626717, 45.99593574], [30.83085263, 31.27333084, 31.71302716, ..., 45.35416824, 45.67668385, 45.99634997]])
array([ 0, 621, 1242, 1863, 2484, 3105, 3726, 4347, 4968, 5589, 6210, 6831, 7452, 8073, 8694, 9315, 9936, 10557, 11178, 11799, 12420, 13041, 13662, 14283, 14904, 15525, 16146, 16767])
array([ 0, 629, 1258, 1887, 2516, 3145, 3774, 4403, 5032, 5661, 6290, 6919, 7548, 8177, 8806, 9435, 10064, 10693, 11322, 11951, 12580, 13209, 13838, 14467, 15096, 15725, 16354, 16983, 17612, 18241, 18870, 19499, 20128, 20757, 21386, 22015, 22644, 23273, 23902, 24531, 25160])
hv.Scatter(
(image_reduite_nx_ny_incidence,sarwing_nrcs_model_inc_reduce_nx_ny_28_41_dataset),
kdims='xsar', vdims='sarwing').opts(title='Incidence nrcs model image reduce nx ny xsar/sarwing') * hv.Path([(30,30),(50,50)]).opts(color='black', line_width=2, alpha=0.2)
nrcs_model_image_reduite_nx_ny = model_ifr2(10., 45, image_reduite_nx_ny_incidence.values)
nrcs_model_image_reduite_nx_ny_mean = nrcs_model_image_reduite_nx_ny.mean()
nrcs_model_image_reduite_nx_ny_mean
0.045541365
nrcs_model_image_reduite_nx_ny_dataset = xr.DataArray(nrcs_model_image_reduite_nx_ny, dims=("atrack", "xtrack"), coords={"atrack":range(0, 16777, 621), "xtrack":range(0,25186,629)})
nrcs_model_image_reduite_nx_ny_dataset
<xarray.DataArray (atrack: 28, xtrack: 41)> array([[0.09855015, 0.09280175, 0.08749451, ..., 0.0234123 , 0.02291511, 0.02243665], [0.09854177, 0.09279399, 0.08748737, ..., 0.0234115 , 0.02291433, 0.02243593], [0.09853341, 0.09278632, 0.08748034, ..., 0.02341067, 0.02291358, 0.02243518], ..., [0.09835786, 0.09262494, 0.08733183, ..., 0.02339372, 0.02289733, 0.02241961], [0.09835084, 0.09261851, 0.08732589, ..., 0.02339306, 0.02289668, 0.02241901], [0.09834402, 0.09261229, 0.08732022, ..., 0.02339239, 0.02289606, 0.0224184 ]], dtype=float32) Coordinates: * atrack (atrack) int64 0 621 1242 1863 2484 ... 14904 15525 16146 16767 * xtrack (xtrack) int64 0 629 1258 1887 2516 ... 23273 23902 24531 25160
array([[0.09855015, 0.09280175, 0.08749451, ..., 0.0234123 , 0.02291511, 0.02243665], [0.09854177, 0.09279399, 0.08748737, ..., 0.0234115 , 0.02291433, 0.02243593], [0.09853341, 0.09278632, 0.08748034, ..., 0.02341067, 0.02291358, 0.02243518], ..., [0.09835786, 0.09262494, 0.08733183, ..., 0.02339372, 0.02289733, 0.02241961], [0.09835084, 0.09261851, 0.08732589, ..., 0.02339306, 0.02289668, 0.02241901], [0.09834402, 0.09261229, 0.08732022, ..., 0.02339239, 0.02289606, 0.0224184 ]], dtype=float32)
array([ 0, 621, 1242, 1863, 2484, 3105, 3726, 4347, 4968, 5589, 6210, 6831, 7452, 8073, 8694, 9315, 9936, 10557, 11178, 11799, 12420, 13041, 13662, 14283, 14904, 15525, 16146, 16767])
array([ 0, 629, 1258, 1887, 2516, 3145, 3774, 4403, 5032, 5661, 6290, 6919, 7548, 8177, 8806, 9435, 10064, 10693, 11322, 11951, 12580, 13209, 13838, 14467, 15096, 15725, 16354, 16983, 17612, 18241, 18870, 19499, 20128, 20757, 21386, 22015, 22644, 23273, 23902, 24531, 25160])
sarwing_nrcs_model_image_reduite_nx_ny = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_nrcs_model_image_reduite_nx_ny.pkl', 'rb'), encoding='bytes')
sarwing_nrcs_model_image_reduite_nx_ny_dataset = xr.DataArray(sarwing_nrcs_model_image_reduite_nx_ny, dims=("atrack", "xtrack"), coords={"atrack":range(0, 16777, 621), "xtrack":range(0,25186,629)})
sarwing_nrcs_model_image_reduite_nx_ny_dataset
<xarray.DataArray (atrack: 28, xtrack: 41)> array([[0.09856078, 0.09278457, 0.08748592, ..., 0.02339262, 0.02289416, 0.0224182 ], [0.09855234, 0.09277681, 0.08747878, ..., 0.02339181, 0.02289338, 0.02241746], [0.09854396, 0.09276911, 0.08747169, ..., 0.023391 , 0.02289261, 0.02241672], ..., [0.09836823, 0.09260766, 0.08732313, ..., 0.02337407, 0.02287638, 0.02240117], [0.09836136, 0.09260134, 0.08731731, ..., 0.0233734 , 0.02287575, 0.02240056], [0.09835453, 0.09259507, 0.08731154, ..., 0.02337274, 0.02287512, 0.02239995]], dtype=float32) Coordinates: * atrack (atrack) int64 0 621 1242 1863 2484 ... 14904 15525 16146 16767 * xtrack (xtrack) int64 0 629 1258 1887 2516 ... 23273 23902 24531 25160
array([[0.09856078, 0.09278457, 0.08748592, ..., 0.02339262, 0.02289416, 0.0224182 ], [0.09855234, 0.09277681, 0.08747878, ..., 0.02339181, 0.02289338, 0.02241746], [0.09854396, 0.09276911, 0.08747169, ..., 0.023391 , 0.02289261, 0.02241672], ..., [0.09836823, 0.09260766, 0.08732313, ..., 0.02337407, 0.02287638, 0.02240117], [0.09836136, 0.09260134, 0.08731731, ..., 0.0233734 , 0.02287575, 0.02240056], [0.09835453, 0.09259507, 0.08731154, ..., 0.02337274, 0.02287512, 0.02239995]], dtype=float32)
array([ 0, 621, 1242, 1863, 2484, 3105, 3726, 4347, 4968, 5589, 6210, 6831, 7452, 8073, 8694, 9315, 9936, 10557, 11178, 11799, 12420, 13041, 13662, 14283, 14904, 15525, 16146, 16767])
array([ 0, 629, 1258, 1887, 2516, 3145, 3774, 4403, 5032, 5661, 6290, 6919, 7548, 8177, 8806, 9435, 10064, 10693, 11322, 11951, 12580, 13209, 13838, 14467, 15096, 15725, 16354, 16983, 17612, 18241, 18870, 19499, 20128, 20757, 21386, 22015, 22644, 23273, 23902, 24531, 25160])
hv.Scatter(
(nrcs_model_image_reduite_nx_ny_dataset,sarwing_nrcs_model_image_reduite_nx_ny_dataset),
kdims='xsar', vdims='sarwing').opts(title='Nrcs model image reduite nx ny') * hv.Path([(0.,0.),(0.12,0.12)]).opts(color='black', line_width=2, alpha=0.2)
sarwing_nrcs_model_image_reduite_nx_ny_mean = sarwing_nrcs_model_image_reduite_nx_ny_dataset.values.mean()
print("Sarwing nrcs model mean : %s" %sarwing_nrcs_model_image_reduite_nx_ny_mean)
nrcs_model_image_reduite_nx_ny_mean = nrcs_model_image_reduite_nx_ny_dataset.values.mean()
print("Xsar nrcs model mean : %s" %nrcs_model_image_reduite_nx_ny_mean)
diff_nrcs_model_mean = sarwing_nrcs_model_image_reduite_nx_ny_mean - nrcs_model_image_reduite_nx_ny_mean
print("Diff : %s" % diff_nrcs_model_mean)
Sarwing nrcs model mean : 0.045515634 Xsar nrcs model mean : 0.045541365 Diff : -2.573058e-05
icontrast_tile_6400x6400_full_resolution_vv = np.sqrt(sigma0_denoised_tile_6400x6400_full_resolution_vv / (nrcs_gmf_tile_6400x6400_full_resolution_dataset / nrcs_model_image_reduite_nx_ny_mean))
icontrast_tile_6400x6400_full_resolution_vv
<xarray.DataArray (atrack: 6400, xtrack: 6400)> dask.array<sqrt, shape=(6400, 6400), dtype=float64, chunksize=(200, 500), chunktype=numpy.ndarray> Coordinates: pol <U2 'VV' * atrack (atrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399 * xtrack (xtrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399
|
array('VV', dtype='<U2')
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
sarwing_icontrast_tile_6400x6400_full_resolution_vv = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_full_res/sarwing_icontrast_tile_6400x6400_full_resolution_vv.pkl', 'rb'), encoding='bytes')
sarwing_icontrast_tile_6400x6400_full_resolution_vv_dataset = xr.DataArray(sarwing_icontrast_tile_6400x6400_full_resolution_vv, dims=("atrack", "xtrack"), coords={"atrack":range(0, 6400, 1), "xtrack":range(0,6400,1)})
sarwing_icontrast_tile_6400x6400_full_resolution_vv_dataset
<xarray.DataArray (atrack: 6400, xtrack: 6400)> array([[0. , 0. , 0. , ..., 0.43291631, 0.41285804, 0.41000731], [0. , 0. , 0. , ..., 0.50311895, 0.54751736, 0.51032345], [0. , 0. , 0. , ..., 0.37839636, 0.40711966, 0.43438886], ..., [0. , 0. , 0. , ..., 0.57897641, 0.67195512, 0.57759751], [0. , 0. , 0. , ..., 0.62617404, 0.54323082, 0.50173934], [0. , 0. , 0. , ..., 0.67907245, 0.47736965, 0.42149161]]) Coordinates: * atrack (atrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399 * xtrack (xtrack) int64 0 1 2 3 4 5 6 ... 6393 6394 6395 6396 6397 6398 6399
array([[0. , 0. , 0. , ..., 0.43291631, 0.41285804, 0.41000731], [0. , 0. , 0. , ..., 0.50311895, 0.54751736, 0.51032345], [0. , 0. , 0. , ..., 0.37839636, 0.40711966, 0.43438886], ..., [0. , 0. , 0. , ..., 0.57897641, 0.67195512, 0.57759751], [0. , 0. , 0. , ..., 0.62617404, 0.54323082, 0.50173934], [0. , 0. , 0. , ..., 0.67907245, 0.47736965, 0.42149161]])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
array([ 0, 1, 2, ..., 6397, 6398, 6399])
ds_xsar = icontrast_tile_6400x6400_full_resolution_vv.sel(xtrack=slice(0,6400,40), atrack=slice(0,6400,40))
ds_sarwing = sarwing_icontrast_tile_6400x6400_full_resolution_vv_dataset.sel(xtrack=slice(0,6400,40), atrack=slice(0,6400,40))
diff = (ds_xsar - ds_sarwing).rename("Diff xsar - sarwing nrcs gmf %s")
std = np.nanstd(diff)
mean = np.nanmean(diff)
plots=[]
r = np.nanpercentile(ds_sarwing,98)
#r = 0.71
plots.append(
rasterize(hv.Image(
sarwing_icontrast_tile_6400x6400_full_resolution_vv_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="sarwing"))
)
plots.append(
rasterize(hv.Image(
icontrast_tile_6400x6400_full_resolution_vv
).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
)
plots.append(
hv.Scatter(
(ds_xsar,ds_sarwing),
kdims='xsar', vdims='sarwing'
).opts(alpha=0.01,xlim=(0,r),ylim=(0,r),title='std=%.3f bias=%.3f' % (std,mean)) * hv.Path([(0.,0.),(r,r)]).opts(color='black', line_width=2, alpha=0.2)
)
hv.Layout(plots).cols(2).opts(title="Validation Icontrast %s xsar/sarwing" % polarization)
x_pixel_size = image_full_resolution.pixel_xtrack_m
y_pixel_size = image_full_resolution.pixel_atrack_m
# calcul coef de reduction image
if round(x_pixel_size ==25) and round(y_pixel_size) ==25 :
coef_reducx = 4
coef_reducy = 4
elif round(x_pixel_size) ==40 and round(y_pixel_size) ==40 :
coef_reducx = 4
coef_reducy = 4
resolution = [1,2,3,4]
resolution_values = [160,320,640,1280]
elif round(x_pixel_size) ==4 and round(y_pixel_size) ==4 :
coef_reducx = 24
coef_reducy = 24
elif round(x_pixel_size) == 75 and round(y_pixel_size) == 75:
coef_reducx = 2
coef_reducy = 2
else:
coef_reducx = int(round(100/x_pixel_size))
coef_reducy = int(round(100/y_pixel_size))
if (coef_reducx <= 2) or (coef_reducy <= 2):
coef_xyfac = 2
else:
coef_xyfac = 1
image_entiere_resolution_200m = sr.open_dataset(filename, chunks=chunks, pol_dim=True, resolution={'atrack': coef_reducx*2, 'xtrack': coef_reducy*2}, resampling='rms')[0]
image_entiere_resolution_200m
DEBUG:xsar.utils:timing gdal_rms : 13.0s. mem: +1939.2Mb DEBUG:xsar.utils:timing load_digital_number : 13.0s. mem: +1939.2Mb DEBUG:xsar.utils:timing load_geometry : 0.1s. mem: +0.0Mb DEBUG:xsar.utils:timing luts_from_xml_calibration : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing luts_from_xml_calibration : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing luts_from_xml_noise : 0.2s. mem: +0.0Mb DEBUG:xsar.utils:timing luts_from_xml_noise : 0.2s. mem: +0.0Mb DEBUG:xsar.utils:timing load_luts : 0.5s. mem: +0.0Mb DEBUG:xsar.utils:timing luts_from_xml_anotation : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing luts_from_xml_anotation : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing load_luts : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing load_lon_lat : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing _get_subdatasets : 13.8s. mem: +1939.2Mb DEBUG:xsar.utils:timing apply_cf_convention : 0.0s. mem: +0.0Mb DEBUG:xsar.utils:timing open_dataset : 13.8s. mem: +1939.2Mb
<xarray.Dataset> Dimensions: (atrack: 838, pol: 2, xtrack: 1259) Coordinates: * pol (pol) object 'VV' 'VH' * atrack (atrack) int64 10 30 50 70 90 ... 16690 16710 16730 16750 * xtrack (xtrack) int64 10 30 50 70 90 ... 25110 25130 25150 25170 Data variables: digital_number (pol, atrack, xtrack) uint16 dask.array<chunksize=(2, 200, 500), meta=np.ndarray> time (atrack) datetime64[ns] dask.array<chunksize=(200,), meta=np.ndarray> longitude (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> latitude (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> incidence (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> elevation (atrack, xtrack) float32 dask.array<chunksize=(200, 500), meta=np.ndarray> sigma0_lut (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> gamma0_lut (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> noise_lut (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> sigma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> nesz (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> gamma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> negz (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 500), meta=np.ndarray> Attributes: footprint: POLYGON ((-67.84221143971432 20.72564283093837, -70.2216... coverage: 251km * 170km (xtrack * atrack ) pixel_xtrack_m: 10.0 pixel_atrack_m: 10.2 ipf_version: 2.84 swath_type: IW polarizations: VV VH product_type: GRD mission: SENTINEL-1 satellite: A start_date: 2017-09-07 10:30:20.936409 stop_date: 2017-09-07 10:30:45.935264 subdataset: IW geometry: ge... Conventions: CF-1.7
array(['VV', 'VH'], dtype=object)
array([ 10, 30, 50, ..., 16710, 16730, 16750])
array([ 10, 30, 50, ..., 25130, 25150, 25170])
|
|
|
|
|
|
|
|
|
|
|
|
|
image_tile_6400x6400_resolution_200m = image_entiere_resolution_200m.sel(atrack=slice(0,tilesize,1), xtrack=slice(0, tilesize, 1))
image_tile_6400x6400_resolution_200m
<xarray.Dataset> Dimensions: (atrack: 320, pol: 2, xtrack: 320) Coordinates: * pol (pol) object 'VV' 'VH' * atrack (atrack) int64 10 30 50 70 90 ... 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 ... 6310 6330 6350 6370 6390 Data variables: digital_number (pol, atrack, xtrack) uint16 dask.array<chunksize=(2, 200, 320), meta=np.ndarray> time (atrack) datetime64[ns] dask.array<chunksize=(200,), meta=np.ndarray> longitude (atrack, xtrack) float32 dask.array<chunksize=(200, 320), meta=np.ndarray> latitude (atrack, xtrack) float32 dask.array<chunksize=(200, 320), meta=np.ndarray> incidence (atrack, xtrack) float32 dask.array<chunksize=(200, 320), meta=np.ndarray> elevation (atrack, xtrack) float32 dask.array<chunksize=(200, 320), meta=np.ndarray> sigma0_lut (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> gamma0_lut (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> noise_lut (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> sigma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> nesz (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> gamma0 (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> negz (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 200, 320), meta=np.ndarray> Attributes: footprint: POLYGON ((-67.84221143971432 20.72564283093837, -70.2216... coverage: 251km * 170km (xtrack * atrack ) pixel_xtrack_m: 10.0 pixel_atrack_m: 10.2 ipf_version: 2.84 swath_type: IW polarizations: VV VH product_type: GRD mission: SENTINEL-1 satellite: A start_date: 2017-09-07 10:30:20.936409 stop_date: 2017-09-07 10:30:45.935264 subdataset: IW geometry: ge... Conventions: CF-1.7
array(['VV', 'VH'], dtype=object)
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
|
|
|
|
|
|
|
|
|
|
|
|
|
sigma0_tile_6400x6400_resolution_200m = image_tile_6400x6400_resolution_200m.sigma0.sel(pol="VV")
nesz_tile_6400x6400_resolution_200m = image_tile_6400x6400_resolution_200m.nesz.sel(pol="VV")
sigma0_denoised_tile_6400x6400_resolution_200m = np.maximum(sigma0_tile_6400x6400_resolution_200m - nesz_tile_6400x6400_resolution_200m, 0)
sigma0_denoised_tile_6400x6400_resolution_200m
<xarray.DataArray (atrack: 320, xtrack: 320)> dask.array<maximum, shape=(320, 320), dtype=float64, chunksize=(200, 320), chunktype=numpy.ndarray> Coordinates: pol <U2 'VV' * atrack (atrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390
|
array('VV', dtype='<U2')
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_200m_res/sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv.pkl', 'rb'), encoding='bytes')
sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv_dataset = xr.DataArray(sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv, dims=("atrack", "xtrack"), coords={"atrack":range(10, 6410, 20), "xtrack":range(10,6410,20)})
sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv_dataset
<xarray.DataArray (atrack: 320, xtrack: 320)> array([[0.0075167 , 0.30455014, 0.31355365, ..., 0.1680926 , 0.15415108, 0.23695434], [0.00849136, 0.28968571, 0.34740543, ..., 0.29469358, 0.15658292, 0.2068327 ], [0.01302386, 0.3759196 , 0.33058255, ..., 0.14776455, 0.16849741, 0.17930682], ..., [0.06471831, 0.26140021, 0.27778305, ..., 0.13325178, 0.27991836, 0.11522134], [0.07320797, 0.18854888, 0.28034545, ..., 0.12300987, 0.19803064, 0.16787129], [0.07193727, 0.2583752 , 0.2937353 , ..., 0.23234468, 0.14732436, 0.30766247]]) Coordinates: * atrack (atrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390
array([[0.0075167 , 0.30455014, 0.31355365, ..., 0.1680926 , 0.15415108, 0.23695434], [0.00849136, 0.28968571, 0.34740543, ..., 0.29469358, 0.15658292, 0.2068327 ], [0.01302386, 0.3759196 , 0.33058255, ..., 0.14776455, 0.16849741, 0.17930682], ..., [0.06471831, 0.26140021, 0.27778305, ..., 0.13325178, 0.27991836, 0.11522134], [0.07320797, 0.18854888, 0.28034545, ..., 0.12300987, 0.19803064, 0.16787129], [0.07193727, 0.2583752 , 0.2937353 , ..., 0.23234468, 0.14732436, 0.30766247]])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
# slice car plantage de jupyter car trop de donnée (timeout) mais pour ça valide
ds_xsar = sigma0_denoised_tile_6400x6400_resolution_200m
ds_sarwing = sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv_dataset
diff = (ds_xsar - ds_sarwing).rename("Diff xsar - sarwingsigma0 denoised %s" % polarization)
std = np.nanstd(diff)
mean = np.nanmean(diff)
plots=[]
r = np.nanpercentile(ds_sarwing,98)
#r = 0.71
plots.append(
rasterize(hv.Image(
sarwing_sigma0_denoised_tile_6400x6400_200m_resolution_vv_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="sarwing"))
)
plots.append(
rasterize(hv.Image(
sigma0_denoised_tile_6400x6400_resolution_200m
).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
)
plots.append(
hv.Scatter(
(ds_xsar,ds_sarwing),
kdims='xsar', vdims='sarwing'
).opts(alpha=0.01,xlim=(0,r),ylim=(0,r),title='std=%.3f bias=%.3f' % (std,mean)) * hv.Path([(0.,0.),(r,r)]).opts(color='black', line_width=2, alpha=0.2)
)
hv.Layout(plots).cols(2).opts(title="Validation sigma0 denoised resolution 200m %s xsar/sarwing" % polarization)
nrcs_gmf_tile_6400x6400_200m_resolution_slice = nrcs_gmf_nice_display_full_resolution_incidence_line1[0][x0:tilesize:20]
nrcs_gmf_tile_6400x6400_200m_resolution = np.outer(np.ones((tilesize//(coef_reducy*2),), dtype=np.float32), nrcs_gmf_tile_6400x6400_200m_resolution_slice)
nrcs_gmf_tile_6400x6400_200m_resolution_dataset = xr.DataArray(nrcs_gmf_tile_6400x6400_200m_resolution, dims=( "xtrack", "atrack"), coords={"atrack":range(10,6400,coef_reducx*2), "xtrack":range(10,6400,coef_reducy*2)})
nrcs_gmf_tile_6400x6400_200m_resolution_dataset
<xarray.DataArray (xtrack: 320, atrack: 320)> array([[0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], ..., [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361]], dtype=float32) Coordinates: * atrack (atrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390
array([[0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], ..., [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361], [0.09855015, 0.09836017, 0.09817068, ..., 0.05759089, 0.05750714, 0.05742361]], dtype=float32)
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
sarwing_nrcs_gmf_tile_6400x6400_200m_resolution = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_200m_res/sarwing_nrcs_gmf_tile_6400x6400_200m_resolution.pkl', 'rb'), encoding='bytes')
sarwing_nrcs_gmf_tile_6400x6400_200m_resolution_dataset = xr.DataArray(sarwing_nrcs_gmf_tile_6400x6400_200m_resolution, dims=("xtrack", "atrack"), coords={"atrack":range(10, 6400, 20), "xtrack":range(10,6400,20)})
sarwing_nrcs_gmf_tile_6400x6400_200m_resolution_dataset
<xarray.DataArray (xtrack: 320, atrack: 320)> array([[0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], ..., [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936]], dtype=float32) Coordinates: * atrack (atrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390
array([[0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], ..., [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936], [0.09856078, 0.0983691 , 0.09817797, ..., 0.05758784, 0.0575035 , 0.05741936]], dtype=float32)
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
# slice car plantage de jupyter car trop de donnée (timeout) mais pour ça valide
ds_xsar = nrcs_gmf_tile_6400x6400_200m_resolution_dataset
ds_sarwing = sarwing_nrcs_gmf_tile_6400x6400_200m_resolution_dataset
diff = (ds_xsar - ds_sarwing).rename("Diff xsar - sarwingsigma0 denoised %s" % polarization)
std = np.nanstd(diff)
mean = np.nanmean(diff)
plots=[]
r = np.nanpercentile(ds_sarwing,98)
#r = 0.71
plots.append(
rasterize(hv.Image(
sarwing_nrcs_gmf_tile_6400x6400_200m_resolution_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="sarwing"))
)
plots.append(
rasterize(hv.Image(
nrcs_gmf_tile_6400x6400_200m_resolution_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
)
plots.append(
hv.Scatter(
(ds_xsar,ds_sarwing),
kdims='xsar', vdims='sarwing'
).opts(alpha=0.01,xlim=(0,r),ylim=(0,r),title='std=%.3f bias=%.3f' % (std,mean)) * hv.Path([(0.,0.),(r,r)]).opts(color='black', line_width=2, alpha=0.2)
)
hv.Layout(plots).cols(2).opts(title="Validation nrcs gmf resolution 200m %s xsar/sarwing" % polarization)
icontrast_tile_6400x6400_200m_resolution_vv = np.sqrt(sigma0_denoised_tile_6400x6400_resolution_200m / (nrcs_gmf_tile_6400x6400_200m_resolution_dataset / nrcs_model_image_reduite_nx_ny_mean))
icontrast_tile_6400x6400_200m_resolution_vv
<xarray.DataArray (atrack: 320, xtrack: 320)> dask.array<sqrt, shape=(320, 320), dtype=float64, chunksize=(200, 320), chunktype=numpy.ndarray> Coordinates: pol <U2 'VV' * atrack (atrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390
|
array('VV', dtype='<U2')
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
sarwing_icontrast_tile_6400x6400_200m_resolution = pickle.load(open('/home/alevieux/Documents/Debug/validation_image_contrast_200m_res/sarwing_icontrast_tile_6400x6400_200m_resolution.pkl', 'rb'), encoding='bytes')
sarwing_icontrast_tile_6400x6400_200m_resolution_dataset = xr.DataArray(sarwing_icontrast_tile_6400x6400_200m_resolution, dims=("atrack", "xtrack"), coords={"atrack":range(10, 6400, 20), "xtrack":range(10,6400,20)})
sarwing_icontrast_tile_6400x6400_200m_resolution_dataset
sarwing_icontrast_tile_6400x6400_200m_resolution_dataset
<xarray.DataArray (atrack: 320, xtrack: 320)> array([[0.05891715, 0.37538798, 0.38126698, ..., 0.36449302, 0.34930632, 0.43339456], [0.06262055, 0.36611245, 0.4013207 , ..., 0.48261438, 0.35205081, 0.40491207], [0.07755291, 0.41705991, 0.39148329, ..., 0.34174333, 0.36519916, 0.37700709], ..., [0.17287883, 0.34777946, 0.35886089, ..., 0.32452745, 0.47070504, 0.30221608], [0.18386853, 0.29536766, 0.36051224, ..., 0.31180631, 0.39591263, 0.36478698], [0.18226581, 0.34576129, 0.36902122, ..., 0.42853006, 0.34148406, 0.49384241]]) Coordinates: * atrack (atrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390 * xtrack (xtrack) int64 10 30 50 70 90 110 ... 6290 6310 6330 6350 6370 6390
array([[0.05891715, 0.37538798, 0.38126698, ..., 0.36449302, 0.34930632, 0.43339456], [0.06262055, 0.36611245, 0.4013207 , ..., 0.48261438, 0.35205081, 0.40491207], [0.07755291, 0.41705991, 0.39148329, ..., 0.34174333, 0.36519916, 0.37700709], ..., [0.17287883, 0.34777946, 0.35886089, ..., 0.32452745, 0.47070504, 0.30221608], [0.18386853, 0.29536766, 0.36051224, ..., 0.31180631, 0.39591263, 0.36478698], [0.18226581, 0.34576129, 0.36902122, ..., 0.42853006, 0.34148406, 0.49384241]])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
array([ 10, 30, 50, ..., 6350, 6370, 6390])
ds_xsar = icontrast_tile_6400x6400_200m_resolution_vv
ds_sarwing = sarwing_icontrast_tile_6400x6400_200m_resolution_dataset
diff = (ds_xsar - ds_sarwing).rename("Diff xsar - sarwing nrcs gmf %s")
std = np.nanstd(diff)
mean = np.nanmean(diff)
plots=[]
r = np.nanpercentile(ds_sarwing,98)
#r = 0.71
plots.append(
rasterize(hv.Image(
sarwing_icontrast_tile_6400x6400_200m_resolution_dataset
).opts(cmap='gray',colorbar=True,tools=['hover'],title="sarwing"))
)
plots.append(
rasterize(hv.Image(
icontrast_tile_6400x6400_200m_resolution_vv
).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
)
plots.append(
hv.Scatter(
(ds_xsar,ds_sarwing),
kdims='xsar', vdims='sarwing'
).opts(alpha=0.01,xlim=(0,r),ylim=(0,r),title='std=%.3f bias=%.3f' % (std,mean)) * hv.Path([(0.,0.),(r,r)]).opts(color='black', line_width=2, alpha=0.2)
)
hv.Layout(plots).cols(2).opts(title="Validation Icontrast reolution 200m %s xsar/sarwing" % polarization)