La continuité du service gitlab.irstea.fr sera assurée en 2020. Nous envisageons ensuite une évolution vers une forge nationale INRAE encore à construire. Nous vous tiendrons au courant des évolutions futures.

...
 
Commits (2)
This diff is collapsed.
......@@ -7,7 +7,7 @@ import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
def smooth_plot (csv,lstBands):
def interpolate_ts (csv,lstBands):
ptrn = os.path.basename(csv)
year = ptrn.split('_')[1]
......@@ -41,6 +41,7 @@ def smooth_plot (csv,lstBands):
dic.setdefault('feat_index',[]).append(index)
if band == lstBands[0] :
dic.setdefault('ID',[]).append(row['ID'])
dic.setdefault('Projet',[]).append(row['Projet'])
dic.setdefault('Biom_f',[]).append(row['Biom_f'])
dic.setdefault('Biom_s',[]).append(row['Biom_s'])
dic.setdefault('Rdt_f',[]).append(row['Rdt_f'])
......@@ -51,6 +52,7 @@ def smooth_plot (csv,lstBands):
ggplot_dic.setdefault('Date',[]).append(idx.strftime("%Y-%m-%d"))
ggplot_dic.setdefault('Band',[]).append(band)
ggplot_dic.setdefault('Plot',[]).append(row['ID'])
ggplot_dic.setdefault('Projet',[]).append(row['Projet'])
# ggplot_dic.setdefault('Crop',[]).append(row['Crop'])
ggplot_dic.setdefault('Sowing',[]).append(row['Sowing'])
ggplot_dic.setdefault('Harvest',[]).append(row['Harvest'])
......@@ -74,19 +76,31 @@ def smooth_plot (csv,lstBands):
if __name__=='__main__':
csv = "./stats/niakhar_2017_opt_gapf_notree.csv"
smooth_plot(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
interpolate_ts(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
csv = "./stats/niakhar_2017_radar_notree.csv"
smooth_plot(csv,["VH","VV"])
interpolate_ts(csv,["VH","VV"])
csv = "./stats/niakhar_2018_opt_gapf_notree.csv"
smooth_plot(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
interpolate_ts(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
csv = "./stats/niakhar_2018_radar_notree.csv"
smooth_plot(csv,["VH","VV"])
interpolate_ts(csv,["VH","VV"])
csv = "./stats/niakhar-serena_2018_opt_gapf_notree.csv"
interpolate_ts(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
csv = "./stats/niakhar-serena_2018_radar_notree.csv"
interpolate_ts(csv,["VH","VV"])
csv = "./stats/niakhar-simco_2018_opt_gapf_notree.csv"
interpolate_ts(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
csv = "./stats/niakhar-simco_2018_radar_notree.csv"
interpolate_ts(csv,["VH","VV"])
csv = "./stats/nioro_2018_opt_gapf_notree.csv"
smooth_plot(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
interpolate_ts(csv,["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12","NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"])
csv = "./stats/nioro_2018_radar_notree.csv"
smooth_plot(csv,["VH","VV"])
\ No newline at end of file
interpolate_ts(csv,["VH","VV"])
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -109,21 +109,29 @@ def normalize_time_series (radar_file, opt_file, norm="minmax", radar_bands=["VH
except Exception as error :
print (error)
if __name__ == '__main__' :
# Niakhar 2017
radar_file = "./interpolate/niakhar_2017_radar_notree_interpolate.csv"
opt_file = "./interpolate/niakhar_2017_opt_gapf_notree_interpolate.csv"
normalize_time_series(radar_file,opt_file,norm="minmax")
normalize_time_series(radar_file,opt_file,norm="meanstd")
# Niakhar 2018
radar_file = "./interpolate/niakhar_2018_radar_notree_interpolate.csv"
opt_file = "./interpolate/niakhar_2018_opt_gapf_notree_interpolate.csv"
normalize_time_series(radar_file,opt_file,norm="minmax")
normalize_time_series(radar_file,opt_file,norm="meanstd")
# Niakhar 2018
radar_file = "./interpolate/niakhar-serena_2018_radar_notree_interpolate.csv"
opt_file = "./interpolate/niakhar-serena_2018_opt_gapf_notree_interpolate.csv"
normalize_time_series(radar_file,opt_file,norm="meanstd")
# Niakhar 2018
radar_file = "./interpolate/niakhar-simco_2018_radar_notree_interpolate.csv"
opt_file = "./interpolate/niakhar-simco_2018_opt_gapf_notree_interpolate.csv"
normalize_time_series(radar_file,opt_file,norm="meanstd")
# Nioro 2018
radar_file = "./interpolate/nioro_2018_radar_notree_interpolate.csv"
opt_file = "./interpolate/nioro_2018_opt_gapf_notree_interpolate.csv"
normalize_time_series(radar_file,opt_file,norm="minmax")
\ No newline at end of file
normalize_time_series(radar_file,opt_file,norm="meanstd")
\ No newline at end of file
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
def norm_patch (radar_file, opt_file, plots_file, area, norm="meanstd", radar_bands=["VH","VV"],
opt_bands=["B2","B3","B4","B8","B5","B6","B7","B8A","B11","B12"],
opt_indices = ["NDVI","NDWI","EVI","MSAVI2","GDVI","CIGreen","CIRedEdge"]):
size = int(int(int(np.sqrt(area * 10000))/10)**2)
print ("Size:",size)
# Radar
radar_array = np.load(radar_file)
n_bands = len(radar_bands)
n_timestamps = int(radar_array.shape[1]/(size*n_bands))
norm_radar_array = None
for b in range(n_bands) :
ts_values = radar_array[:,b*size*n_timestamps:b*size*n_timestamps+size*n_timestamps]
if norm == "meanstd":
ts_values = (ts_values - ts_values.mean()) / ts_values.std()
elif norm == "minmax":
ts_values = (ts_values - ts_values.min()) / (ts_values.max() - ts_values.min())
if norm_radar_array is None :
norm_radar_array = ts_values
else :
norm_radar_array = np.hstack((norm_radar_array,ts_values))
radar_patchs = []
for i in range(n_timestamps):
lst = []
for j in range(n_bands):
lst.append(norm_radar_array[:,i*size+j*n_timestamps*size:i*size+j*n_timestamps*size+size])
radar_patchs.append(np.stack(lst, axis=-1))
radar_patchs = np.stack(radar_patchs,axis=-1)
print (radar_patchs.shape)
# Opt Bands
opt_array = np.load(opt_file)
n_bands = len(opt_bands)
n_timestamps = int(opt_array.shape[1]/(size*(len(opt_bands) + len(opt_indices))))
norm_opt_array = None
for b in range(len(opt_bands)) :
ts_values = opt_array[:,b*size*n_timestamps:b*size*n_timestamps+size*n_timestamps]
if norm == "meanstd":
ts_values = (ts_values - ts_values.mean()) / ts_values.std()
elif norm == "minmax":
ts_values = (ts_values - ts_values.min()) / (ts_values.max() - ts_values.min())
if norm_opt_array is None :
norm_opt_array = ts_values
else :
norm_opt_array = np.hstack((norm_opt_array,ts_values))
opt_patchs = []
for i in range(n_timestamps):
lst = []
for j in range(n_bands):
lst.append(norm_opt_array[:,i*size+j*n_timestamps*size:i*size+j*n_timestamps*size+size])
opt_patchs.append(np.stack(lst, axis=-1))
opt_patchs = np.stack(opt_patchs,axis=-1)
print (opt_patchs.shape)
# Opt Indices
indices_array = np.load(opt_file)
n_bands = len(opt_indices)
n_timestamps = int(opt_array.shape[1]/(size*(len(opt_bands) + len(opt_indices))))
norm_indices_array = None
for b in range(len(opt_bands),len(opt_bands)+len(opt_indices)) :
ts_values = indices_array[:,b*size*n_timestamps:b*size*n_timestamps+size*n_timestamps]
if norm == "meanstd":
ts_values = (ts_values - ts_values.mean()) / ts_values.std()
elif norm == "minmax":
ts_values = (ts_values - ts_values.min()) / (ts_values.max() - ts_values.min())
if norm_indices_array is None :
norm_indices_array = ts_values
else :
norm_indices_array = np.hstack((norm_indices_array,ts_values))
indices_patchs = []
for i in range(n_timestamps):
lst = []
for j in range(n_bands):
lst.append(norm_indices_array[:,i*size+j*n_timestamps*size:i*size+j*n_timestamps*size+size])
indices_patchs.append(np.stack(lst, axis=-1))
indices_patchs = np.stack(indices_patchs,axis=-1)
print (indices_patchs.shape)
outPath = "./patchs_data/{}Ha".format(area)
if not os.path.exists(outPath):
os.makedirs(outPath)
ptrn = os.path.basename(radar_file).split('_')[0]+"_"+os.path.basename(radar_file).split('_')[1]
np.save(os.path.join(outPath,"{}_radar_patchs.npy".format(ptrn)),radar_patchs)
np.save(os.path.join(outPath,"{}_opt_patchs.npy".format(ptrn)),opt_patchs)
np.save(os.path.join(outPath,"{}_indices_patchs.npy".format(ptrn)),indices_patchs)
plots_df = pd.read_csv(plots_file)
rdt = plots_df[["Biom_f","Biom_s","Rdt_f","Rdt_s"]].values
print (rdt.shape)
np.save(os.path.join(outPath,"{}_yields.npy".format(ptrn)),rdt)
if __name__ == '__main__' :
area=1
# Niakhar 2017
radar_file = "./patchs/%sHa/niakhar_2017_radar.npy"%area
opt_file = "./patchs/%sHa/niakhar_2017_opt_gapf.npy"%area
plots_file = "./patchs/%sHa/niakhar_2017_plots.csv"%area
norm_patch(radar_file,opt_file,plots_file,area,norm="minmax")
# Niakhar 2018
radar_file = "./patchs/%sHa/niakhar_2018_radar.npy"%area
opt_file = "./patchs/%sHa/niakhar_2018_opt_gapf.npy"%area
plots_file = "./patchs/%sHa/niakhar_2018_plots.csv"%area
norm_patch(radar_file,opt_file,plots_file,area,norm="minmax")
radar_file = "./patchs/%sHa/niakhar-serena_2018_radar.npy"%area
opt_file = "./patchs/%sHa/niakhar-serena_2018_opt_gapf.npy"%area
plots_file = "./patchs/%sHa/niakhar-serena_2018_plots.csv"%area
norm_patch(radar_file,opt_file,plots_file,area,norm="minmax")
radar_file = "./patchs/%sHa/niakhar-simco_2018_radar.npy"%area
opt_file = "./patchs/%sHa/niakhar-simco_2018_opt_gapf.npy"%area
plots_file = "./patchs/%sHa/niakhar-simco_2018_plots.csv"%area
norm_patch(radar_file,opt_file,plots_file,area,norm="minmax")
# Nioro 2018
radar_file = "./patchs/%sHa/nioro_2018_radar.npy"%area
opt_file = "./patchs/%sHa/nioro_2018_opt_gapf.npy"%area
plots_file = "./patchs/%sHa/nioro_2018_plots.csv"%area
norm_patch(radar_file,opt_file,plots_file,area,norm="minmax")
\ No newline at end of file
......@@ -250,10 +250,28 @@ if __name__=="__main__":
outPattern = "niakhar_2018_radar_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
############
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SERENA_2018.shp"
outPattern = "niakhar-serena_2018_radar"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SERENA_2018.shp"
outPattern = "niakhar-serena_2018_radar_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SIMCO_2018.shp"
outPattern = "niakhar-simco_2018_radar"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SIMCO_2018.shp"
outPattern = "niakhar-simco_2018_radar_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
#############
# --------
# Optical
# --------
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar_2018.shp"
outPattern = "niakhar_2018_opt"
lstTS = ["/media/je/LACIE/SENEGAL/NIAKHAR/SENTINEL-2/2018/OUTPUT/CONCAT_GAPF/B2_NIAKHAR_2018_CONCAT_S2.tif",
"/media/je/LACIE/SENEGAL/NIAKHAR/SENTINEL-2/2018/OUTPUT/CONCAT_GAPF/B3_NIAKHAR_2018_CONCAT_S2.tif",
......@@ -278,10 +296,28 @@ if __name__=="__main__":
outPattern = "niakhar_2018_opt_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
############
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SERENA_2018.shp"
outPattern = "niakhar-serena_2018_opt"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SERENA_2018.shp"
outPattern = "niakhar-serena_2018_opt_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SIMCO_2018.shp"
outPattern = "niakhar-simco_2018_opt"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SIMCO_2018.shp"
outPattern = "niakhar-simco_2018_opt_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
#############
# ------------------------
# Optical with gapfilling
# ------------------------
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar_2018.shp"
outPattern = "niakhar_2018_opt_gapf"
lstTS = ["/media/je/LACIE/SENEGAL/NIAKHAR/SENTINEL-2/2018/OUTPUT/CONCAT_GAPF/B2_NIAKHAR_2018_CONCAT_S2_GAPF.tif",
"/media/je/LACIE/SENEGAL/NIAKHAR/SENTINEL-2/2018/OUTPUT/CONCAT_GAPF/B3_NIAKHAR_2018_CONCAT_S2_GAPF.tif",
......@@ -306,6 +342,24 @@ if __name__=="__main__":
outPattern = "niakhar_2018_opt_gapf_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
############
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SERENA_2018.shp"
outPattern = "niakhar-serena_2018_opt_gapf"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SERENA_2018.shp"
outPattern = "niakhar-serena_2018_opt_gapf_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SIMCO_2018.shp"
outPattern = "niakhar-simco_2018_opt_gapf"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern)
plots_file = "/media/je/LACIE/SENEGAL/RENDEMENTS/Rdt_Mil_Niakhar-SIMCO_2018.shp"
outPattern = "niakhar-simco_2018_opt_gapf_notree"
ZonalStats(plots_file,lstTS,dates_file,outPath,outPattern,tree_mask)
#############
# --------
# Nioro
# --------
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.