├── Generated plots ├── ANN_By_Epochs.pdf ├── Results_GSI_BySample.pdf ├── Results_GSI_By_Trait.pdf ├── Results_RTM_Inv_pure.pdf ├── Results_RTM_Inv_pure_.pdf ├── Results_RTM_Inv_noise_2.pdf ├── Results_RTM_Inv_pure_2.pdf ├── Results_RTM_Inv_noise_2_zoom.pdf ├── Results_RTM_Inv_pure_2_thick.pdf ├── Results_RTM_Inv_pure_2_zoom.pdf ├── Results_RTM_Inv_noise_2_thick.pdf ├── Results_RTM_Inv_pure_2_zoom_thick.pdf ├── Results_RTM_Inv_noise_2_zoom_thick.pdf └── PearsonR_ByBandPlot_Corrected_Reviewed_02.pdf ├── GeneratedData ├── SpearmanCorrelation_Final_Pstars.csv ├── SpearmanCorrelation_Final.csv ├── Final_Sensitivity_2000_Samples.csv └── Traits_Spectra_car_PlotSel.csv ├── Python Packages.csv ├── R Packages.csv ├── Plotting ├── combining_CSV.R ├── Noise_Inverson_Plot.R ├── Pure_inversion_PlotDataPrep.R ├── Noisy_Invesion_PlotDataPrep.R ├── Pure_Inversion_Plot.R ├── NoiseInversion_Final_01.R ├── EpochTestings_Final_02.R ├── PureInversion_Final_01.R ├── CorrelationPlots_Final.R └── GSI_Plots_Final_01.R ├── R ├── SpearmanCorrelations.R └── GSI_Analysis_v01.R ├── README.md ├── CC-BY-4.0 ├── Jupyter └── Hyperparameter tunning │ ├── HyperParameter_RFR_RTM.ipynb │ └── HyperParameter_GPR_RTM.ipynb └── LICENSE.txt /Generated plots/ANN_By_Epochs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/ANN_By_Epochs.pdf -------------------------------------------------------------------------------- /Generated plots/Results_GSI_BySample.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_GSI_BySample.pdf -------------------------------------------------------------------------------- /Generated plots/Results_GSI_By_Trait.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_GSI_By_Trait.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_pure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_pure.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_pure_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_pure_.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_noise_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_noise_2.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_pure_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_pure_2.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_noise_2_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_noise_2_zoom.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_pure_2_thick.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_pure_2_thick.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_pure_2_zoom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_pure_2_zoom.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_noise_2_thick.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_noise_2_thick.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_pure_2_zoom_thick.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_pure_2_zoom_thick.pdf -------------------------------------------------------------------------------- /Generated plots/Results_RTM_Inv_noise_2_zoom_thick.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/Results_RTM_Inv_noise_2_zoom_thick.pdf -------------------------------------------------------------------------------- /Generated plots/PearsonR_ByBandPlot_Corrected_Reviewed_02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nunocesarsa/RTM_Inversion/HEAD/Generated plots/PearsonR_ByBandPlot_Corrected_Reviewed_02.pdf -------------------------------------------------------------------------------- /GeneratedData/SpearmanCorrelation_Final_Pstars.csv: -------------------------------------------------------------------------------- 1 | "";"Band";"cab";"cw";"cm";"LAI";"car" 2 | "2";"B2";"***";" ";".";"***";"***" 3 | "3";"B3";"***";" ";" ";".";"***" 4 | "4";"B4";"***";" ";" ";" ";" " 5 | "5";"B5";"***";" ";" ";" ";" " 6 | "6";"B6";"***";" ";"***";"***";" " 7 | "7";"B7";" ";" ";"***";"***";" " 8 | "8";"B8A";" ";" ";"***";"***";" " 9 | "9";"B11";" ";"***";"***";"***";" " 10 | "10";"B12";" ";"***";"***";" ";" " 11 | -------------------------------------------------------------------------------- /Python Packages.csv: -------------------------------------------------------------------------------- 1 | Name;Version;License 2 | prosail;2.0.5;UNKNOWN 3 | lhsmdu;1.1;MIT 4 | numpy;1.19.5;BSD 5 | pandas;1.1.5;BSD 6 | pandas-datareader;0.9.0;BSD License 7 | pandas-gbq;0.13.3;BSD License 8 | pandas-profiling;1.4.1;MIT License 9 | sklearn-pandas;1.8.0;BSD License 10 | sklearn;0.0;BSD License 11 | hyperopt;0.1.2;BSD License 12 | keras-vis;0.4.1;MIT 13 | Keras;2.4.3;MIT License 14 | Keras-Preprocessing;1.1.2;MIT License 15 | pysptools;0.15.0;Apache Software License 16 | pip-licenses;3.3.0;MIT License 17 | -------------------------------------------------------------------------------- /R Packages.csv: -------------------------------------------------------------------------------- 1 | Coluna1;Package;License 2 | hsdar;hsdar;GPL 3 | FME;FME;GPL (>= 2) 4 | MCMCglmm;MCMCglmm;GPL (>= 2) 5 | randomForest;randomForest;GPL (>= 2) 6 | DMwR;DMwR;GPL (>= 2) 7 | sensitivity;sensitivity;GPL-2 8 | ggplot2;ggplot2;GPL-2 | file LICENSE 9 | ggthemes;ggthemes;GPL-2 10 | reshape;reshape;MIT + file LICENSE 11 | reshape2;reshape2;MIT + file LICENSE 12 | extrafont;extrafont;GPL-2 13 | extrafontdb;extrafontdb;GPL-2 14 | gridExtra;gridExtra;GPL (>= 2) 15 | latticeExtra;latticeExtra;GPL (>= 2) 16 | cowplot;cowplot;GPL-2 17 | gtools;gtools;GPL-2 18 | -------------------------------------------------------------------------------- /GeneratedData/SpearmanCorrelation_Final.csv: -------------------------------------------------------------------------------- 1 | "";"Band";"cab";"cw";"cm";"LAI";"car" 2 | "2";"B2";-0,108635289158822;0,000140452535113134;-0,0396244659061165;0,197031893757973;-0,463194871798718 3 | "3";"B3";-0,958507564126891;0,0257475859368965;-0,016295596073899;-0,039528207882052;-0,105794915448729 4 | "4";"B4";-0,552898233224558;0,0218006949501737;-0,0239152709788177;0,00538064984516246;-0,0212656013164003 5 | "5";"B5";-0,980323149580787;0,0276154209038552;-0,0213645473411368;-0,0364061581015395;-0,0245946916486729 6 | "6";"B6";-0,751065510266378;0,00427716856929214;-0,18775255993814;0,491654971413743;-0,0126940576735144 7 | "7";"B7";0,00501815975453994;-0,0147483126870782;-0,466598945649736;0,819342882835721;0,0105609356402339 8 | "8";"B8A";0,0129106622276656;-0,0186144316536079;-0,470393690098423;0,817037028259257;0,0104515991128998 9 | "9";"B11";0,0204199536049884;-0,648947362736841;-0,491051866262967;0,469509180377295;-0,0141107780276945 10 | "10";"B12";0,0225264926316232;-0,669796757449189;-0,692371311592828;0,0257294434323609;-0,0200938805234701 11 | -------------------------------------------------------------------------------- /Plotting/combining_CSV.R: -------------------------------------------------------------------------------- 1 | 2 | library(ggplot2) 3 | library(ggthemes) 4 | library(reshape2) 5 | 6 | gc() 7 | setwd("C:/Paper/Tables/Final_Data") 8 | 9 | #loading data - pure 10 | errbg.df = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch.csv") 11 | errbg.df.2 = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch_1850.csv") 12 | errbg.df.3 = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch_3350.csv") 13 | 14 | train.df = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch.csv") 15 | train.df.2 = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch_1850.csv") 16 | train.df.3 = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch_3350.csv") 17 | 18 | errbg.df <- rbind(errbg.df,errbg.df.2,errbg.df.3) 19 | train.df <- rbind(train.df,train.df.2,train.df.3) 20 | 21 | all.df <- rbind(errbg.df,train.df) 22 | 23 | write.csv2(all.df,"Inversion_PureRTM.csv") 24 | 25 | 26 | #loading data - noise 27 | errbg.df = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2.csv") 28 | errbg.df.2 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_10perc.csv") 29 | errbg.df.3 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_25perc.csv") 30 | errbg.df.4 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_50perc.csv") 31 | 32 | train.df = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2.csv") 33 | train.df.2 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_10perc.csv") 34 | train.df.3 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_25perc.csv") 35 | train.df.4 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_50perc.csv") 36 | 37 | errbg.df <- rbind(errbg.df,errbg.df.2,errbg.df.3,errbg.df.4) 38 | train.df <- rbind(train.df,train.df.2,train.df.3,train.df.4) 39 | 40 | all.df <- rbind(errbg.df,train.df) 41 | 42 | write.csv2(all.df,"Inversion_NoisyRTM.csv") 43 | 44 | 45 | -------------------------------------------------------------------------------- /R/SpearmanCorrelations.R: -------------------------------------------------------------------------------- 1 | 2 | library(gtools) 3 | 4 | my.df <- read.csv2("C:/Paper/Tables/Final_Data/Traits_Spectra_car.csv") 5 | my.df <- my.df[,-1] 6 | 7 | 8 | head(my.df) 9 | 10 | out.df <- data.frame("Band"=0,"cab"=NA,"cw"=NA,"cm"=NA,"LAI"=NA,"car"=NA) 11 | out.df.pval <- data.frame("Band"=0,"cab"=NA,"cw"=NA,"cm"=NA,"LAI"=NA,"car"=NA) 12 | 13 | for (i in names(my.df)[1:9]){ 14 | print(i) 15 | 16 | 17 | #cab_r = cor.test(my.df[,c(i)],my.df[,c('cab')],method="spearman")[[1]] 18 | #cw_r = cor.test(my.df[,c(i)],my.df[,c('cw')],method="spearman")[[1]] 19 | #cm_r = cor.test(my.df[,c(i)],my.df[,c('cm')],method="spearman")[[1]] 20 | #lai_r = cor.test(my.df[,c(i)],my.df[,c('LAI')],method="spearman")[[1]] 21 | #car_r = cor.test(my.df[,c(i)],my.df[,c('car')],method="spearman")[[1]] 22 | 23 | temp.df <- data.frame("Band"=i, 24 | "cab"=cor.test(my.df[,c(i)],my.df[,c('cab')],method="spearman")$estimate[[1]], 25 | "cw"=cor.test(my.df[,c(i)],my.df[,c('cw')],method="spearman")$estimate[[1]], 26 | "cm"=cor.test(my.df[,c(i)],my.df[,c('cm')],method="spearman")$estimate[[1]], 27 | "LAI"=cor.test(my.df[,c(i)],my.df[,c('lai')],method="spearman")$estimate[[1]], 28 | "car"=cor.test(my.df[,c(i)],my.df[,c('car')],method="spearman")$estimate[[1]]) 29 | 30 | temp.df.pval <- data.frame("Band"=i, 31 | "cab"=stars.pval(cor.test(my.df[,c(i)],my.df[,c('cab')],method="spearman")$p.value), 32 | "cw"=stars.pval(cor.test(my.df[,c(i)],my.df[,c('cw')],method="spearman")$p.value), 33 | "cm"=stars.pval(cor.test(my.df[,c(i)],my.df[,c('cm')],method="spearman")$p.value), 34 | "LAI"=stars.pval(cor.test(my.df[,c(i)],my.df[,c('lai')],method="spearman")$p.value), 35 | "car"=stars.pval(cor.test(my.df[,c(i)],my.df[,c('car')],method="spearman")$p.value)) 36 | 37 | 38 | 39 | out.df <- rbind(out.df,temp.df) 40 | out.df.pval <- rbind(out.df.pval,temp.df.pval) 41 | } 42 | 43 | #removing uncessary first column 44 | out.df <- out.df[-1,] 45 | out.df.pval <- out.df.pval[-1,] 46 | 47 | write.csv2(out.df,"C:/Paper/Tables/Final_Data/SpearmanCorrelation_Final.csv") 48 | write.csv2(out.df.pval,"C:/Paper/Tables/Final_Data/SpearmanCorrelation_Final_Pstars.csv") 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTM_Inversion 2 | Software repository for the publication: 3 | 4 | Title: "Exploring the impact of noise on hybrid inversion of PROSAIL RTM on Sentinel-2 data" 5 | 6 | Authors: Nuno César de Sá, Mitra Baratchi, Leon Hauser, Peter van Bodegom 7 | 8 | Date: 11 February 2021 9 | 10 | DOI: https://doi.org/10.3390/rs13040648 11 | 12 | Link: https://www.mdpi.com/2072-4292/13/4/648 13 | 14 | Abstract: 15 | 16 | Remote sensing (RS) of biophysical variables plays a vital role in providing the information necessary for understanding spatio-temporal dynamics in ecosystems. The hybrid approach to retrieve biophysical variables from RS by combining Machine Learning (ML) algorithms with surrogate data generated by Radiative Transfer Models (RTM). The susceptibility of the ill-posed solutions to noise currently constrains further application of hybrid approaches. 17 | 18 | Here, we explored how noise affects the performance of ML algorithms for biophysical trait retrieval. We focused on synthetic Sentinel-2 (S2) data generated using the PROSAIL RTM and four commonly applied ML algorithms: Gaussian Processes (GPR), Random Forests (RFR), and Artificial Neural Networks (ANN) and Multi-task Neural Networks (MTN). After identifying which biophysical variables can be retrieved from S2 using a Global Sensitivity Analysis, we evaluated the performance loss of each algorithm using the Mean Absolute Percentage Error (MAPE) with increasing noise levels. We found that, for S2 data, Carotenoid concentrations are uniquely dependent on band 2, Chlorophyll is almost exclusively dependent on the visible ranges, and Leaf Area Index, water, and dry matter contents are mostly dependent on infrared bands. Without added noise, GPR was the best algorithm (<0.05%), followed by the MTN (<3%) and ANN (<5%), with the RFR performing very poorly (<50%). The addition of noise critically affected the performance of all algorithms (>20%) even at low levels of added noise (≈5%). 19 | 20 | Overall, both neural networks performed significantly better than GPR and RFR when noise was added with the MTN being slightly better when compared to the ANN. Our results imply that the performance of the commonly used algorithms in hybrid-RTM inversion are pervasively sensitive to noise. The implication is that more advanced models or approaches are necessary to minimize the impact of noise to improve near real-time and accurate RS monitoring of biophysical trait retrieval. 21 | -------------------------------------------------------------------------------- /Plotting/Noise_Inverson_Plot.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(ggthemes) 3 | library(reshape2) 4 | library(tidyverse) 5 | 6 | gc() 7 | setwd("C:/Paper/Tables/Final_Data") 8 | 9 | agg.df <- read.csv2("NOISERTM_Final_Aggregated.csv") 10 | full.df <-read.csv2("NOISERTM_Final_Full.csv") 11 | 12 | names(agg.df) 13 | names(full.df) 14 | 15 | 16 | 17 | #### Line plot #### 18 | 19 | plt.fig <- ggplot(agg.df, aes(x=NoiseLevel, y=MAPE, colour=Model_ErrorType)) + 20 | geom_line(linetype="dashed",size=1)+ 21 | geom_point(size=2)+ 22 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 23 | #geom_point()+ 24 | ylim(0,50)+ 25 | xlim(0,10)+ 26 | scale_colour_manual(values= c('#762a83', '#af8dc3', 27 | '#d6604d','#f4a582', 28 | 'darkgreen','green', 29 | #'#4393c3','#92c5de', 30 | '#053061','#2166ac'))+ 31 | 32 | labs(#title="Noise RTM inversion", 33 | x ="Noise level (%)", 34 | y = "Mean absolute percentage error (%)")+ 35 | facet_grid(NoiseType~Variable_upper, 36 | #ncol=4, 37 | #strip.position = c("top","right") 38 | )+ 39 | #theme(strip.text = element_text(hjust = 0))+ 40 | theme_hc()+ 41 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 42 | panel.spacing = unit(1.5, "lines")) 43 | 44 | print(plt.fig) 45 | 46 | #### 47 | 48 | pdf("Results_RTM_Inv_noise_2_zoom_thick.pdf",width=18,height=8,paper='special') 49 | 50 | print(plt.fig) 51 | 52 | dev.off() 53 | 54 | 55 | 56 | 57 | ### boxplot plot #### 58 | head(full.df) 59 | #as.factor(NoiseLevel*100) 60 | plt.fig <- ggplot(full.df, aes(x=Model, y=MAPE, fill=Model_ErrorType)) + 61 | geom_boxplot()+ 62 | ylim(0,75)+ 63 | scale_colour_manual(values= c('#762a83', '#af8dc3', 64 | '#d6604d','#f4a582', 65 | 'darkgreen','green', 66 | #'#4393c3','#92c5de', 67 | '#053061','#2166ac'), 68 | aesthetics = "fill")+ 69 | 70 | labs(#title="Noise RTM inversion", 71 | x ="Model", 72 | y = "Mean absolute percentage error (%)")+ 73 | facet_grid(NoiseType~Variable, 74 | labeller = labeller(Variable = c("cab" ='Cab', 75 | "cm" = "Cm", 76 | "cw" = "Cw", 77 | "lai"= "LAI")) 78 | 79 | )+ 80 | #theme(strip.text = element_text(hjust = 0))+ 81 | theme_hc()+ 82 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 83 | panel.spacing = unit(1.5, "lines")) 84 | 85 | print(plt.fig) 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Plotting/Pure_inversion_PlotDataPrep.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(ggthemes) 3 | library(reshape2) 4 | 5 | gc() 6 | setwd("C:/Paper/Tables/Final_Data") 7 | 8 | errbg.df = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch.csv") 9 | errbg.df.2 = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch_1850.csv") 10 | errbg.df.3 = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch_3350.csv") 11 | 12 | train.df = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch.csv") 13 | train.df.2 = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch_1850.csv") 14 | train.df.3 = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch_3350.csv") 15 | 16 | errbg.df <- rbind(errbg.df,errbg.df.2,errbg.df.3) 17 | train.df <- rbind(train.df,train.df.2,train.df.3) 18 | 19 | #to maintain everything easily comparable, we will use MAPE to visualize the rror 20 | mape.bag.df = errbg.df[,c(2,3,7,8,15)] 21 | mape.trn.df = train.df[,c(2,3,7,8,15)] 22 | 23 | 24 | agg.bag.df = aggregate(MAPE~.,data = mape.bag.df[,-4], 25 | FUN=mean, na.rm=TRUE) 26 | agg.bag.df.sd = aggregate(MAPE~.,data = mape.bag.df[,-4], 27 | FUN=sd, na.rm=TRUE) 28 | 29 | agg.trn.df = aggregate(MAPE~.,data = mape.trn.df[,-4], 30 | FUN=mean, na.rm=TRUE) 31 | agg.trn.df.sd = aggregate(MAPE~.,data = mape.trn.df[,-4], 32 | FUN=sd, na.rm=TRUE) 33 | 34 | agg.bag.df$sd <- agg.bag.df.sd$MAPE 35 | agg.trn.df$sd <- agg.trn.df.sd$MAPE 36 | 37 | #adding a tag 38 | agg.bag.df$ErrorType = "Out-of-bag" 39 | agg.trn.df$ErrorType = "Training" 40 | 41 | #binding to a dataframe 42 | full.df = rbind(agg.bag.df,agg.trn.df) 43 | 44 | names(full.df) 45 | head(full.df) 46 | unique(full.df$ErrorType) 47 | 48 | 49 | #naming 50 | full.df$ErrorTypeNames = NA 51 | full.df$ErrorTypeNames[full.df$ErrorType=="Out-of-bag"] <- "Validation error" 52 | full.df$ErrorTypeNames[full.df$ErrorType=="Training"] <- "Training error" 53 | 54 | #creating a new variable to direct the plotting order 55 | full.df$Model_ErrorType <- paste(full.df$Model,full.df$ErrorTypeNames) 56 | 57 | 58 | unique(full.df$NSamples) 59 | 60 | #creating a point type column 61 | 62 | full.df$PT_type = NA 63 | full.df$PT_type[full.df$Model=="ANN"] = 17 64 | full.df$PT_type[full.df$Model=="GPR"] = 17 65 | full.df$PT_type[full.df$Model=="MTN"] = 17 66 | full.df$PT_type[full.df$Model=="RFR"] = 17 67 | 68 | 69 | ########## PRINTING - error from 0 to 80 70 | 71 | list.files() 72 | #write.csv2(full.df,"PURERTM_Final_Processed (forPlots).csv") 73 | 74 | #saving aggregated data prepared for plots 75 | write.csv2(full.df,"PURERTM_Final_Aggregated.csv") 76 | 77 | 78 | #preparing a full dataset for boxplots 79 | errbg.df$ErrorType = "Validation error" 80 | train.df$ErrorType = "Training error" 81 | 82 | full.boxplot = rbind(errbg.df,train.df) 83 | full.boxplot$PT_type = 17 84 | 85 | full.boxplot$Model_ErrorType = paste(full.boxplot$Model,full.boxplot$ErrorType) 86 | 87 | write.csv2(full.boxplot,"PURERTM_Final_Full.csv") 88 | -------------------------------------------------------------------------------- /Plotting/Noisy_Invesion_PlotDataPrep.R: -------------------------------------------------------------------------------- 1 | 2 | library(ggplot2) 3 | library(ggthemes) 4 | library(reshape2) 5 | 6 | 7 | gc() 8 | setwd("C:/Paper/Tables/Final_Data") 9 | 10 | errbg.df = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2.csv") 11 | errbg.df.2 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_10perc.csv") 12 | errbg.df.3 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_25perc.csv") 13 | errbg.df.4 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_50perc.csv") 14 | 15 | train.df = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2.csv") 16 | train.df.2 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_10perc.csv") 17 | train.df.3 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_25perc.csv") 18 | train.df.4 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_50perc.csv") 19 | 20 | errbg.df <- rbind(errbg.df,errbg.df.2,errbg.df.3,errbg.df.4) 21 | train.df <- rbind(train.df,train.df.2,train.df.3,train.df.4) 22 | 23 | unique(train.df$NoiseLevel) 24 | 25 | names(train.df) 26 | 27 | #to maintain everything easily comparable, we will use MAPE to visualize the rror 28 | mape.bag.df = errbg.df[,c(2,3,4,8,16)] 29 | mape.trn.df = train.df[,c(2,3,4,8,16)] 30 | 31 | names(mape.bag.df) 32 | head(mape.bag.df) 33 | #aggreating 34 | agg.bag.df = aggregate(MAPE~.,data = mape.bag.df, 35 | FUN=mean, na.rm=TRUE) 36 | agg.bag.df.sd = aggregate(MAPE~.,data = mape.bag.df, 37 | FUN=sd, na.rm=TRUE) 38 | 39 | agg.trn.df = aggregate(MAPE~.,data = mape.trn.df, 40 | FUN=mean, na.rm=TRUE) 41 | agg.trn.df.sd = aggregate(MAPE~.,data = mape.trn.df, 42 | FUN=sd, na.rm=TRUE) 43 | 44 | #bringing everything together 45 | agg.bag.df$sd <- agg.bag.df.sd$MAPE 46 | agg.trn.df$sd <- agg.trn.df.sd$MAPE 47 | 48 | #adding a tag 49 | agg.bag.df$ErrorType = "Validation error" 50 | agg.trn.df$ErrorType = "Training error" 51 | 52 | #binding to a dataframe 53 | full.df = rbind(agg.bag.df,agg.trn.df) 54 | 55 | names(full.df) 56 | head(full.df) 57 | unique(full.df$NoiseLevel) 58 | 59 | #creating a new variable to direct the plotting order 60 | full.df$Model_ErrorType <- paste(full.df$Model,full.df$ErrorType) 61 | 62 | full.df$Variable_upper <- NA 63 | full.df$Variable_upper[full.df$Variable == "cab"] <- "Cab" 64 | full.df$Variable_upper[full.df$Variable == "cm"] <- "Cm" 65 | full.df$Variable_upper[full.df$Variable == "cw"] <- "Cw" 66 | full.df$Variable_upper[full.df$Variable == "lai"] <- "LAI" 67 | #### plotting time 68 | 69 | #converting to percentage 70 | full.df$NoiseLevel = full.df$NoiseLevel*100 71 | 72 | #saving aggregated data prepared for plots 73 | write.csv2(full.df,"NOISERTM_Final_Aggregated.csv") 74 | 75 | 76 | 77 | 78 | #preparing a full dataset for boxplots 79 | mape.bag.df$ErrorType = "Validation error" 80 | mape.trn.df$ErrorType = "Training error" 81 | 82 | full.boxplot = rbind(mape.bag.df,mape.trn.df) 83 | full.boxplot$PT_type = 17 84 | 85 | full.boxplot$Model_ErrorType = paste(full.boxplot$Model,full.boxplot$ErrorType) 86 | 87 | write.csv2(full.boxplot,"NOISERTM_Final_Full.csv") 88 | 89 | -------------------------------------------------------------------------------- /Plotting/Pure_Inversion_Plot.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(ggthemes) 3 | library(reshape2) 4 | library(tidyverse) 5 | 6 | gc() 7 | setwd("C:/Paper/Tables/Final_Data") 8 | 9 | agg.df <- read.csv2("PURERTM_Final_Aggregated.csv") 10 | full.df <-read.csv2("PURERTM_Final_Full.csv") 11 | 12 | names(agg.df) 13 | names(full.df) 14 | 15 | 16 | 17 | ## Line plot ########### 18 | plt.fig2 <- ggplot(agg.df, aes(x=NSamples, y=MAPE, colour=Model_ErrorType)) + 19 | geom_line(linetype="dashed",size=1)+ 20 | geom_point(size=2)+ 21 | # geom_line(linetype="dashed",size=.1)+ 22 | # geom_point(aes(shape=Model),size=2)+ 23 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 24 | ylim(0,80)+ 25 | scale_colour_manual(values= c('#762a83', '#af8dc3', 26 | '#d6604d','#f4a582', 27 | 'darkgreen','green', 28 | #'#4393c3','#92c5de', 29 | '#053061','#2166ac'))+ 30 | 31 | labs(title="Pure RTM inversion", 32 | x ="Nr of samples", 33 | y = "Mean absolute percentage error (%)")+ 34 | facet_grid(~Variable, 35 | labeller = labeller(Variable = c("cab" = "Cab", 36 | "cm" = "Cm", 37 | "cw" = "Cw", 38 | "lai"= "LAI")))+ 39 | #scale_shape_manual(values=c(15,15,16,16,17,17,18,18))+ 40 | #guides(shape = guide_legend(override.aes = list(fill = "black"))) 41 | 42 | theme_hc()+ 43 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 44 | panel.spacing = unit(1.5, "lines")) 45 | 46 | print(plt.fig2) 47 | 48 | #### Saving the plot ###3 49 | 50 | pdf("Results_RTM_Inv_pure_2_thick.pdf",width=18,height=8,paper='special') 51 | 52 | print(plt.fig2) 53 | 54 | dev.off() 55 | 56 | 57 | ### Box plot #### 58 | 59 | plt.fig2.boxplot <- ggplot(full.df,aes(x=Model, y=MAPE, fill=Model_ErrorType))+ 60 | geom_boxplot()+ 61 | ylim(0,100)+ 62 | labs(#title="Pure RTM inversion", 63 | x ="Model", 64 | y = "Mean absolute percentage error (%)")+ 65 | #scale_colour_manual(values= c('#762a83', '#af8dc3', 66 | # '#d6604d','#f4a582', 67 | # 'darkgreen','green', 68 | # #'#4393c3','#92c5de', 69 | # '#053061','#2166ac'))+ 70 | #scale_colour_manual(values= c('#053061','#2166ac', 71 | # '#d6604d','#f4a582', 72 | # 'darkgreen','green', 73 | #'#4393c3','#92c5de', 74 | # '#762a83', '#af8dc3'))+ 75 | facet_grid(~Variable,#ColNames, 76 | labeller = labeller(Variable = c("cab" ='Cab', 77 | "cm" = "Cm", 78 | "cw" = "Cw", 79 | "lai"= "LAI")) 80 | 81 | )+ 82 | scale_colour_manual(values= c('#762a83', '#af8dc3', 83 | '#d6604d','#f4a582', 84 | 'darkgreen','green', 85 | #'#4393c3','#92c5de', 86 | '#053061','#2166ac'), 87 | aesthetics = "fill")+ 88 | theme_hc()+ 89 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 90 | panel.spacing = unit(1.5, "lines"))#, 91 | 92 | 93 | print(plt.fig2.boxplot) 94 | -------------------------------------------------------------------------------- /Plotting/NoiseInversion_Final_01.R: -------------------------------------------------------------------------------- 1 | 2 | library(ggplot2) 3 | library(ggthemes) 4 | library(reshape2) 5 | 6 | 7 | gc() 8 | setwd("C:/Paper/Tables/Final_Data") 9 | 10 | errbg.df = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2.csv") 11 | errbg.df.2 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_10perc.csv") 12 | errbg.df.3 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_25perc.csv") 13 | errbg.df.4 = read.csv2("Optim_S2000_Temp_Noise_KFold_TrainingError_csv2_50perc.csv") 14 | 15 | train.df = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2.csv") 16 | train.df.2 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_10perc.csv") 17 | train.df.3 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_25perc.csv") 18 | train.df.4 = read.csv2("Optim_S2000_Temp_Noise_KFold_OutOfBag_csv2_50perc.csv") 19 | 20 | errbg.df <- rbind(errbg.df,errbg.df.2,errbg.df.3,errbg.df.4) 21 | train.df <- rbind(train.df,train.df.2,train.df.3,train.df.4) 22 | 23 | unique(train.df$NoiseLevel) 24 | 25 | names(train.df) 26 | 27 | #to maintain everything easily comparable, we will use MAPE to visualize the rror 28 | mape.bag.df = errbg.df[,c(2,3,4,8,16)] 29 | mape.trn.df = train.df[,c(2,3,4,8,16)] 30 | 31 | names(mape.bag.df) 32 | head(mape.bag.df) 33 | #aggreating 34 | agg.bag.df = aggregate(MAPE~.,data = mape.bag.df, 35 | FUN=mean, na.rm=TRUE) 36 | agg.bag.df.sd = aggregate(MAPE~.,data = mape.bag.df, 37 | FUN=sd, na.rm=TRUE) 38 | 39 | agg.trn.df = aggregate(MAPE~.,data = mape.trn.df, 40 | FUN=mean, na.rm=TRUE) 41 | agg.trn.df.sd = aggregate(MAPE~.,data = mape.trn.df, 42 | FUN=sd, na.rm=TRUE) 43 | 44 | #bringing everything together 45 | agg.bag.df$sd <- agg.bag.df.sd$MAPE 46 | agg.trn.df$sd <- agg.trn.df.sd$MAPE 47 | 48 | #adding a tag 49 | agg.bag.df$ErrorType = "Validation error" 50 | agg.trn.df$ErrorType = "Training error" 51 | 52 | #binding to a dataframe 53 | full.df = rbind(agg.bag.df,agg.trn.df) 54 | 55 | names(full.df) 56 | head(full.df) 57 | unique(full.df$NoiseLevel) 58 | 59 | #creating a new variable to direct the plotting order 60 | full.df$Model_ErrorType <- paste(full.df$Model,full.df$ErrorType) 61 | 62 | full.df$Variable_upper <- NA 63 | full.df$Variable_upper[full.df$Variable == "cab"] <- "Cab" 64 | full.df$Variable_upper[full.df$Variable == "cm"] <- "Cm" 65 | full.df$Variable_upper[full.df$Variable == "cw"] <- "Cw" 66 | full.df$Variable_upper[full.df$Variable == "lai"] <- "LAI" 67 | #### plotting time 68 | 69 | #converting to percentage 70 | full.df$NoiseLevel = full.df$NoiseLevel*100 71 | 72 | pdf("Results_RTM_Inv_noise_2.pdf",width=18,height=8,paper='special') 73 | 74 | plt.fig <- ggplot(full.df, aes(x=NoiseLevel, y=MAPE, colour=Model_ErrorType)) + 75 | geom_line(linetype="dashed",size=.1)+ 76 | geom_point(aes(shape=Model),size=2)+ 77 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 78 | #geom_point()+ 79 | #ylim(0,100)+ 80 | scale_colour_manual(values= c('#762a83', '#af8dc3', 81 | '#d6604d','#f4a582', 82 | 'darkgreen','green', 83 | #'#4393c3','#92c5de', 84 | '#053061','#2166ac'))+ 85 | 86 | labs(#title="Noise RTM inversion", 87 | x ="Noise level (%)", 88 | y = "Mean absolute percentage error (%)")+ 89 | facet_grid(NoiseType~Variable_upper, 90 | #ncol=4, 91 | #strip.position = c("top","right") 92 | )+ 93 | #theme(strip.text = element_text(hjust = 0))+ 94 | theme_hc()+ 95 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 96 | panel.spacing = unit(1.5, "lines")) 97 | 98 | print(plt.fig) 99 | 100 | dev.off() 101 | 102 | 103 | ###### zoomed figure 104 | 105 | pdf("Results_RTM_Inv_noise_2_zoom.pdf",width=18,height=8,paper='special') 106 | 107 | plt.fig <- ggplot(full.df, aes(x=NoiseLevel, y=MAPE, colour=Model_ErrorType)) + 108 | geom_line(linetype="dashed",size=.1)+ 109 | geom_point(aes(shape=Model),size=2)+ 110 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 111 | #geom_point()+ 112 | xlim(0,10)+ 113 | ylim(0,50)+ 114 | scale_colour_manual(values= c('#762a83', '#af8dc3', 115 | '#d6604d','#f4a582', 116 | 'darkgreen','green', 117 | #'#4393c3','#92c5de', 118 | '#053061','#2166ac'))+ 119 | 120 | labs(#title="Noise RTM inversion", 121 | x ="Noise level (%)", 122 | y = "Mean absolute percentage error (%)")+ 123 | facet_grid(NoiseType~Variable_upper, 124 | #ncol=4, 125 | #strip.position = c("top","right") 126 | )+ 127 | #theme(strip.text = element_text(hjust = 0))+ 128 | theme_hc()+ 129 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 130 | panel.spacing = unit(1.5, "lines")) 131 | 132 | print(plt.fig) 133 | 134 | dev.off() -------------------------------------------------------------------------------- /Plotting/EpochTestings_Final_02.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | library(ggthemes) 3 | library(reshape2) 4 | library(RColorBrewer) 5 | 6 | 7 | setwd("C:/Paper/Tables/Final_Data") 8 | gc() 9 | 10 | 11 | #my.df <- read.csv2("C:/Users/Nuno/Desktop/ChangeNet_Temp_EpochTesting_OptimizedOnly.csv") 12 | my.df <- read.csv2("MTMTSTST_01_Final_EpochTesting_OptimizedOnly.csv") 13 | 14 | #fixing the table 15 | my.df.2 = my.df[,c(2,3,4,5,13)] 16 | 17 | my.df.2$Model = substr(my.df.2$Model,1,3) 18 | 19 | my.df.2$Valid_Model = paste(my.df.2$Model,my.df.2$ValidType,sep=" ") 20 | my.df.2$Epochs_mdl_valid = paste(my.df.2$Epochs,my.df.2$Model,my.df.2$ValidType,sep=" ") 21 | 22 | 23 | ##boxplots works but are not pretty 24 | ggplot(my.df.2, aes(x=Epochs, y=MAPE, fill=Valid_Model,group=interaction(Epochs,Valid_Model))) + 25 | #geom_line(linetype="dashed")+ 26 | #geom_point(shape=full.df$ptshape,size=1.8)+ 27 | #geom_point()+ 28 | #geom_jitter()+ 29 | geom_boxplot(position = "dodge2")+ 30 | #ylim(0,25)+ 31 | #xlim(0,300)+ 32 | scale_colour_manual(values= c('chocolate1', 'chocolate4', 33 | 'green1','darkgreen'))+ 34 | 35 | labs(title="Neural networks - MAPE error in function of training iterations", 36 | x ="Epochs", 37 | y ="Mean absolute percentage error (%)")+ 38 | facet_wrap(~Variable,scales="free_y",ncol=2)+ 39 | #theme(strip.text = element_text(hjust = 0))+ 40 | theme_hc()+ 41 | theme(text=element_text(size=18, family="serif"),legend.title = element_blank(), 42 | panel.spacing = unit(1.5, "lines")) 43 | 44 | 45 | #aggregating 46 | my.df.2 = my.df[,c(2,3,4,5,13)] 47 | my.df.2$Model = substr(my.df.2$Model,1,3) 48 | 49 | #there is a big outlier on the 50 epochs training that breaks down the error bars 50 | my.df.2 = my.df.2[-c(67,68),] 51 | 52 | agg.df = aggregate(MAPE~.,data =my.df.2, 53 | FUN=mean, na.rm=TRUE) 54 | agg.df.sd = aggregate(MAPE~.,data =my.df.2, 55 | FUN=sd, na.rm=TRUE) 56 | agg.df$sd = agg.df.sd$MAPE 57 | agg.df$Valid_Model = paste(agg.df$Model,agg.df$ValidType,sep=" ") 58 | 59 | pdf("ANN_By_Epochs.pdf",width=18,height=8,paper='special') 60 | 61 | plt1 <- ggplot(agg.df, aes(x=Epochs, y=MAPE, colour=Valid_Model)) + 62 | geom_line(linetype="dashed",size=.1)+ 63 | #geom_point(shape=full.df$ptshape,size=1.8)+ 64 | geom_point(size=1.5)+ 65 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 66 | #ylim(0,25)+ 67 | scale_colour_manual(values= c('chocolate1', 'chocolate4', 68 | 'green1','darkgreen'))+ 69 | 70 | labs(#title="Neural networks - MAPE error in function of training iterations", 71 | x ="Epochs", 72 | y ="Mean absolute percentage error (%)")+ 73 | facet_wrap(~Variable,scales="free_y",ncol=2, 74 | labeller = labeller(Variable = c("cab" = "Cab", 75 | "cm" = "Cm", 76 | "cw" = "Cw", 77 | "lai"= "LAI")))+ 78 | #theme(strip.text = element_text(hjust = 0))+ 79 | theme_hc()+ 80 | theme(text=element_text(size=18, family="serif"),legend.title = element_blank(), 81 | panel.spacing = unit(1.5, "lines")) 82 | 83 | print(plt1) 84 | dev.off() 85 | 86 | 87 | ############### old code 88 | names(my.df) 89 | 90 | my.df.2 = my.df[,c(2,3,4,5,13)] 91 | my.df.2$Model = substr(my.df.2$Model,1,3) 92 | 93 | 94 | agg.df = aggregate(MAPE~.,data =my.df.2, 95 | FUN=mean, na.rm=TRUE) 96 | 97 | agg.df$Valid_Model = paste(agg.df$Model,agg.df$ValidType,sep=" ") 98 | 99 | 100 | 101 | plt.fig <- ggplot(agg.df, aes(x=Epochs, y=MAPE, colour=Valid_Model)) + 102 | geom_line(linetype="dashed")+ 103 | #geom_point(shape=full.df$ptshape,size=1.8)+ 104 | geom_point()+ 105 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 106 | #ylim(0,25)+ 107 | scale_colour_manual(values= c('chocolate1', 'chocolate4', 108 | 'green1','darkgreen'))+ 109 | 110 | labs(title="Neural networks - MAPE error in function of training iterations", 111 | x ="Epochs", 112 | y ="Mean absolute percentage error (%)")+ 113 | facet_wrap(~Variable,scales="free_y",ncol=2)+ 114 | #theme(strip.text = element_text(hjust = 0))+ 115 | theme_hc()+ 116 | theme(text=element_text(size=18, family="serif"),legend.title = element_blank(), 117 | panel.spacing = unit(1.5, "lines")) 118 | 119 | print(plt.fig) 120 | 121 | 122 | 123 | 124 | #as.character(unique(agg.df$Model)) 125 | 126 | #agg.df.2 = agg.df[agg.df$Model==c("ANN_optimized"),] 127 | #agg.df.2 = rbind(agg.df.2,agg.df[agg.df$Model==c("MTN_optimized"),]) 128 | 129 | agg.df$Valid_Model = paste(agg.df$Model,agg.df$ValidType,sep="_") 130 | 131 | #png("EpochComparision_0to25.png", 132 | # width = 800, height = 500, units = "px",pointsize=12) 133 | 134 | plt.fig <- ggplot(agg.df, aes(x=Epochs, y=MAPE, colour=Valid_Model)) + 135 | geom_line(linetype="dashed")+ 136 | #geom_point(shape=full.df$ptshape,size=1.8)+ 137 | geom_point()+ 138 | ylim(0,25)+ 139 | scale_colour_manual(values= c('chocolate1', 'chocolate4', 140 | 'green1','darkgreen'))+ 141 | 142 | labs(title="Neural networks - MAPE error in function of training iterations", 143 | x ="Epochs", 144 | y ="Mean absolute percentage error (%)")+ 145 | facet_wrap(~Variable,scales="free_y",ncol=2)+ 146 | #theme(strip.text = element_text(hjust = 0))+ 147 | theme_hc()+ 148 | theme(text=element_text(size=18, family="serif"),legend.title = element_blank(), 149 | panel.spacing = unit(1.5, "lines")) 150 | 151 | print(plt.fig) 152 | 153 | #dev.off() 154 | 155 | -------------------------------------------------------------------------------- /Plotting/PureInversion_Final_01.R: -------------------------------------------------------------------------------- 1 | 2 | library(ggplot2) 3 | library(ggthemes) 4 | library(reshape2) 5 | 6 | gc() 7 | setwd("C:/Paper/Tables/Final_Data") 8 | 9 | errbg.df = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch.csv") 10 | errbg.df.2 = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch_1850.csv") 11 | errbg.df.3 = read.csv2("MTMTSTST_Temp_KFold_OutOfBag_csv2_Corrected_600epoch_3350.csv") 12 | 13 | train.df = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch.csv") 14 | train.df.2 = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch_1850.csv") 15 | train.df.3 = read.csv2("MTMTSTST_Temp_KFold_TrainingError_csv2_Corrected_600epoch_3350.csv") 16 | 17 | errbg.df <- rbind(errbg.df,errbg.df.2,errbg.df.3) 18 | train.df <- rbind(train.df,train.df.2,train.df.3) 19 | 20 | #to maintain everything easily comparable, we will use MAPE to visualize the rror 21 | mape.bag.df = errbg.df[,c(2,3,7,8,15)] 22 | mape.trn.df = train.df[,c(2,3,7,8,15)] 23 | 24 | 25 | agg.bag.df = aggregate(MAPE~.,data = mape.bag.df[,-4], 26 | FUN=mean, na.rm=TRUE) 27 | agg.bag.df.sd = aggregate(MAPE~.,data = mape.bag.df[,-4], 28 | FUN=sd, na.rm=TRUE) 29 | 30 | agg.trn.df = aggregate(MAPE~.,data = mape.trn.df[,-4], 31 | FUN=mean, na.rm=TRUE) 32 | agg.trn.df.sd = aggregate(MAPE~.,data = mape.trn.df[,-4], 33 | FUN=sd, na.rm=TRUE) 34 | 35 | agg.bag.df$sd <- agg.bag.df.sd$MAPE 36 | agg.trn.df$sd <- agg.trn.df.sd$MAPE 37 | 38 | #adding a tag 39 | agg.bag.df$ErrorType = "Out-of-bag" 40 | agg.trn.df$ErrorType = "Training" 41 | 42 | #binding to a dataframe 43 | full.df = rbind(agg.bag.df,agg.trn.df) 44 | 45 | names(full.df) 46 | head(full.df) 47 | unique(full.df$ErrorType) 48 | 49 | 50 | #naming 51 | full.df$ErrorTypeNames = NA 52 | full.df$ErrorTypeNames[full.df$ErrorType=="Out-of-bag"] <- "Validation error" 53 | full.df$ErrorTypeNames[full.df$ErrorType=="Training"] <- "Training error" 54 | 55 | #creating a new variable to direct the plotting order 56 | full.df$Model_ErrorType <- paste(full.df$Model,full.df$ErrorTypeNames) 57 | 58 | 59 | unique(full.df$NSamples) 60 | 61 | #creating a point type column 62 | 63 | full.df$PT_type = NA 64 | full.df$PT_type[full.df$Model=="ANN"] = 17 65 | full.df$PT_type[full.df$Model=="GPR"] = 17 66 | full.df$PT_type[full.df$Model=="MTN"] = 17 67 | full.df$PT_type[full.df$Model=="RFR"] = 17 68 | 69 | 70 | ########## PRINTING - error from 0 to 80 71 | 72 | list.files() 73 | write.csv2(full.df,"PURERTM_Final_Processed (forPlots).csv") 74 | 75 | 76 | #png("C:/Paper/R_Scripts/Optimized_Pure_BySamples_4Box_meanTr_maxVal.png", 77 | # width = 600, height = 500, units = "px",pointsize=12) 78 | pdf("Results_RTM_Inv_pure_2.pdf",width=18,height=8,paper='special') 79 | 80 | 81 | plt.fig2 <- ggplot(full.df, aes(x=NSamples, y=MAPE, colour=Model_ErrorType)) + 82 | geom_line(linetype="dashed",size=.1)+ 83 | geom_point(aes(shape=Model),size=2)+ 84 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 85 | ylim(0,80)+ 86 | scale_colour_manual(values= c('#762a83', '#af8dc3', 87 | '#d6604d','#f4a582', 88 | 'darkgreen','green', 89 | #'#4393c3','#92c5de', 90 | '#053061','#2166ac'))+ 91 | 92 | labs(title="Pure RTM inversion", 93 | x ="Nr of samples", 94 | y = "Mean absolute percentage error (%)")+ 95 | facet_wrap(~ Variable,scales="free",labeller = labeller(Variable = c("cab" = "Cab", 96 | "cm" = "Cm", 97 | "cw" = "Cw", 98 | "lai"= "LAI")))+ 99 | 100 | #scale_shape_manual(values=c(15,15,16,16,17,17,18,18))+ 101 | #guides(shape = guide_legend(override.aes = list(fill = "black"))) 102 | 103 | theme_hc()+ 104 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 105 | panel.spacing = unit(1.5, "lines")) 106 | 107 | print(plt.fig2) 108 | 109 | dev.off() 110 | 111 | 112 | ################# printing, error from 0 to 25 113 | 114 | 115 | #png("C:/Paper/R_Scripts/Optimized_Pure_BySamples_4Box_meanTr_maxVal.png", 116 | # width = 600, height = 500, units = "px",pointsize=12) 117 | pdf("Results_RTM_Inv_pure_2_zoom.pdf",width=18,height=8,paper='special') 118 | 119 | 120 | plt.fig2 <- ggplot(full.df, aes(x=NSamples, y=MAPE, colour=Model_ErrorType)) + 121 | geom_line(linetype="dashed",size=.1)+ 122 | geom_point(aes(shape=Model),size=2)+ 123 | geom_errorbar(aes(ymin=MAPE-sd, ymax=MAPE+sd), width=.2)+ 124 | ylim(0,5)+ 125 | scale_colour_manual(values= c('#762a83', '#af8dc3', 126 | '#d6604d','#f4a582', 127 | 'darkgreen','green', 128 | #'#4393c3','#92c5de', 129 | '#053061','#2166ac'))+ 130 | 131 | labs(title="Pure RTM inversion - Zoom", 132 | x ="Nr of samples", 133 | y = "Mean absolute percentage error (%)")+ 134 | facet_wrap(~ Variable,scales="free",labeller = labeller(Variable = c("cab" = "Cab", 135 | "cm" = "Cm", 136 | "cw" = "Cw", 137 | "lai"= "LAI")))+ 138 | 139 | #scale_shape_manual(values=c(15,15,16,16,17,17,18,18))+ 140 | #guides(shape = guide_legend(override.aes = list(fill = "black"))) 141 | 142 | theme_hc()+ 143 | theme(text=element_text(size=24, family="serif"),legend.title = element_blank(), 144 | panel.spacing = unit(1.5, "lines")) 145 | 146 | print(plt.fig2) 147 | 148 | dev.off() 149 | -------------------------------------------------------------------------------- /GeneratedData/Final_Sensitivity_2000_Samples.csv: -------------------------------------------------------------------------------- 1 | "";"Trait";"variable";"value";"type";"SampleNr" 2 | "1";"Cab";"B02";0,125011010472239;"mSI";2000 3 | "2";"Car";"B02";0,429419994993694;"mSI";2000 4 | "3";"Cw";"B02";2,09155793886949e-05;"mSI";2000 5 | "4";"Cm";"B02";0,000554431695569641;"mSI";2000 6 | "5";"LAI";"B02";0,00652228505301496;"mSI";2000 7 | "6";"Cab";"B03";0,918346248048515;"mSI";2000 8 | "7";"Car";"B03";0,00247837960334284;"mSI";2000 9 | "8";"Cw";"B03";3,81814225949986e-05;"mSI";2000 10 | "9";"Cm";"B03";0,00404884015300814;"mSI";2000 11 | "10";"LAI";"B03";0,00376193019112051;"mSI";2000 12 | "11";"Cab";"B04";0,786867646460567;"mSI";2000 13 | "12";"Car";"B04";1,26858235303276e-05;"mSI";2000 14 | "13";"Cw";"B04";1,23577184962876e-05;"mSI";2000 15 | "14";"Cm";"B04";0,000631582531389593;"mSI";2000 16 | "15";"LAI";"B04";0,000587715801616172;"mSI";2000 17 | "16";"Cab";"B05";0,923975051888028;"mSI";2000 18 | "17";"Car";"B05";4,22856123577979e-05;"mSI";2000 19 | "18";"Cw";"B05";3,81530725078949e-05;"mSI";2000 20 | "19";"Cm";"B05";0,0114331626087169;"mSI";2000 21 | "20";"LAI";"B05";0,0071525685835177;"mSI";2000 22 | "21";"Cab";"B06";0,179234132932269;"mSI";2000 23 | "22";"Car";"B06";1,66160144678392e-05;"mSI";2000 24 | "23";"Cw";"B06";1,7172948845051e-05;"mSI";2000 25 | "24";"Cm";"B06";0,531944287967785;"mSI";2000 26 | "25";"LAI";"B06";0,217231652404214;"mSI";2000 27 | "26";"Cab";"B07";2,31992191488829e-08;"mSI";2000 28 | "27";"Car";"B07";1,03513523324561e-06;"mSI";2000 29 | "28";"Cw";"B07";7,80274362593386e-05;"mSI";2000 30 | "29";"Cm";"B07";0,693241346338238;"mSI";2000 31 | "30";"LAI";"B07";0,249628169747524;"mSI";2000 32 | "31";"Cab";"B8A";1,08739986374236e-06;"mSI";2000 33 | "32";"Car";"B8A";1,08739986374236e-06;"mSI";2000 34 | "33";"Cw";"B8A";0,000272116600560051;"mSI";2000 35 | "34";"Cm";"B8A";0,70368285518215;"mSI";2000 36 | "35";"LAI";"B8A";0,240513920687923;"mSI";2000 37 | "36";"Cab";"B11";8,95401446485325e-06;"mSI";2000 38 | "37";"Car";"B11";8,95401446485325e-06;"mSI";2000 39 | "38";"Cw";"B11";0,563290880785687;"mSI";2000 40 | "39";"Cm";"B11";0,374612902109127;"mSI";2000 41 | "40";"LAI";"B11";0,00297011716456824;"mSI";2000 42 | "41";"Cab";"B12";1,55735492007798e-05;"mSI";2000 43 | "42";"Car";"B12";1,55735492007798e-05;"mSI";2000 44 | "43";"Cw";"B12";0,383138323523235;"mSI";2000 45 | "44";"Cm";"B12";0,396628226459402;"mSI";2000 46 | "45";"LAI";"B12";0,0629325283227431;"mSI";2000 47 | "46";"Cab";"GSI";0,247491011035436;"mSI";2000 48 | "47";"Car";"GSI";0,000474425637749958;"mSI";2000 49 | "48";"Cw";"GSI";0,0361562102228027;"mSI";2000 50 | "49";"Cm";"GSI";0,484290163874792;"mSI";2000 51 | "50";"LAI";"GSI";0,167640034137319;"mSI";2000 52 | "51";"Cab";"B02";0,389556342474449;"iSI";2000 53 | "52";"Car";"B02";0,41874028078035;"iSI";2000 54 | "53";"Cw";"B02";0,0117511844757104;"iSI";2000 55 | "54";"Cm";"B02";0,012784935159925;"iSI";2000 56 | "55";"LAI";"B02";0,00990269343909127;"iSI";2000 57 | "56";"Cab";"B03";0,0654008556371661;"iSI";2000 58 | "57";"Car";"B03";0,00599752029570067;"iSI";2000 59 | "58";"Cw";"B03";0,00218790149122454;"iSI";2000 60 | "59";"Cm";"B03";0,0114880965429434;"iSI";2000 61 | "60";"LAI";"B03";0,0103079832001178;"iSI";2000 62 | "61";"Cab";"B04";0,189568191667838;"iSI";2000 63 | "62";"Car";"B04";0,00131976905410967;"iSI";2000 64 | "63";"Cw";"B04";0,00132020553270284;"iSI";2000 65 | "64";"Cm";"B04";0,00720129362169877;"iSI";2000 66 | "65";"LAI";"B04";0,0101431006026967;"iSI";2000 67 | "66";"Cab";"B05";0,0532357701928428;"iSI";2000 68 | "67";"Car";"B05";0,00266464709615461;"iSI";2000 69 | "68";"Cw";"B05";0,00266295308759677;"iSI";2000 70 | "69";"Cm";"B05";0,019213621518761;"iSI";2000 71 | "70";"LAI";"B05";0,0134975606556929;"iSI";2000 72 | "71";"Cab";"B06";0,0521191407709006;"iSI";2000 73 | "72";"Car";"B06";0,029560119596181;"iSI";2000 74 | "73";"Cw";"B06";0,0294569903592175;"iSI";2000 75 | "74";"Cm";"B06";0,0639384754086985;"iSI";2000 76 | "75";"LAI";"B06";0,0467846829621675;"iSI";2000 77 | "76";"Cab";"B07";0,0269450563576302;"iSI";2000 78 | "77";"Car";"B07";0,0269484652097971;"iSI";2000 79 | "78";"Cw";"B07";0,0268788663241432;"iSI";2000 80 | "79";"Cm";"B07";0,0565742239481191;"iSI";2000 81 | "80";"LAI";"B07";0,0550598465434007;"iSI";2000 82 | "81";"Cab";"B8A";0,025612038330423;"iSI";2000 83 | "82";"Car";"B8A";0,025612038330423;"iSI";2000 84 | "83";"Cw";"B8A";0,025527250641119;"iSI";2000 85 | "84";"Cm";"B8A";0,0550221305292892;"iSI";2000 86 | "85";"LAI";"B8A";0,0536139247606676;"iSI";2000 87 | "86";"Cab";"B11";0,00387163205894905;"iSI";2000 88 | "87";"Car";"B11";0,00387163205894905;"iSI";2000 89 | "88";"Cw";"B11";0,0561055729348416;"iSI";2000 90 | "89";"Cm";"B11";0,0544748821577474;"iSI";2000 91 | "90";"LAI";"B11";0,0101189512409468;"iSI";2000 92 | "91";"Cab";"B12";0,0351435604007107;"iSI";2000 93 | "92";"Car";"B12";0,0351435604007107;"iSI";2000 94 | "93";"Cw";"B12";0,156378341482218;"iSI";2000 95 | "94";"Cm";"B12";0,156442617694171;"iSI";2000 96 | "95";"LAI";"B12";0,0364541288975483;"iSI";2000 97 | "96";"Cab";"GSI";0,0391297073979125;"iSI";2000 98 | "97";"Car";"GSI";0,0204862607145516;"iSI";2000 99 | "98";"Cw";"GSI";0,0240209239108027;"iSI";2000 100 | "99";"Cm";"GSI";0,0485412748629606;"iSI";2000 101 | "100";"LAI";"GSI";0,0403221014550804;"iSI";2000 102 | "101";"Cab";"B02";0,514567352946688;"tSI";2000 103 | "102";"Car";"B02";0,848160275774044;"tSI";2000 104 | "103";"Cw";"B02";0,0117721000550991;"tSI";2000 105 | "104";"Cm";"B02";0,0133393668554946;"tSI";2000 106 | "105";"LAI";"B02";0,0164249784921062;"tSI";2000 107 | "106";"Cab";"B03";0,983747103685681;"tSI";2000 108 | "107";"Car";"B03";0,00847589989904352;"tSI";2000 109 | "108";"Cw";"B03";0,00222608291381954;"tSI";2000 110 | "109";"Cm";"B03";0,0155369366959516;"tSI";2000 111 | "110";"LAI";"B03";0,0140699133912383;"tSI";2000 112 | "111";"Cab";"B04";0,976435838128404;"tSI";2000 113 | "112";"Car";"B04";0,00133245487764;"tSI";2000 114 | "113";"Cw";"B04";0,00133256325119913;"tSI";2000 115 | "114";"Cm";"B04";0,00783287615308836;"tSI";2000 116 | "115";"LAI";"B04";0,0107308164043128;"tSI";2000 117 | "116";"Cab";"B05";0,977210822080871;"tSI";2000 118 | "117";"Car";"B05";0,00270693270851241;"tSI";2000 119 | "118";"Cw";"B05";0,00270110616010466;"tSI";2000 120 | "119";"Cm";"B05";0,0306467841274779;"tSI";2000 121 | "120";"LAI";"B05";0,0206501292392106;"tSI";2000 122 | "121";"Cab";"B06";0,231353273703169;"tSI";2000 123 | "122";"Car";"B06";0,0295767356106489;"tSI";2000 124 | "123";"Cw";"B06";0,0294741633080625;"tSI";2000 125 | "124";"Cm";"B06";0,595882763376483;"tSI";2000 126 | "125";"LAI";"B06";0,264016335366382;"tSI";2000 127 | "126";"Cab";"B07";0,0269450795568493;"tSI";2000 128 | "127";"Car";"B07";0,0269495003450303;"tSI";2000 129 | "128";"Cw";"B07";0,0269568937604026;"tSI";2000 130 | "129";"Cm";"B07";0,749815570286357;"tSI";2000 131 | "130";"LAI";"B07";0,304688016290925;"tSI";2000 132 | "131";"Cab";"B8A";0,0256131257302867;"tSI";2000 133 | "132";"Car";"B8A";0,0256131257302867;"tSI";2000 134 | "133";"Cw";"B8A";0,0257993672416791;"tSI";2000 135 | "134";"Cm";"B8A";0,75870498571144;"tSI";2000 136 | "135";"LAI";"B8A";0,294127845448591;"tSI";2000 137 | "136";"Cab";"B11";0,00388058607341391;"tSI";2000 138 | "137";"Car";"B11";0,00388058607341391;"tSI";2000 139 | "138";"Cw";"B11";0,619396453720529;"tSI";2000 140 | "139";"Cm";"B11";0,429087784266875;"tSI";2000 141 | "140";"LAI";"B11";0,013089068405515;"tSI";2000 142 | "141";"Cab";"B12";0,0351591339499114;"tSI";2000 143 | "142";"Car";"B12";0,0351591339499114;"tSI";2000 144 | "143";"Cw";"B12";0,539516665005453;"tSI";2000 145 | "144";"Cm";"B12";0,553070844153573;"tSI";2000 146 | "145";"LAI";"B12";0,0993866572202914;"tSI";2000 147 | "146";"Cab";"GSI";0,286620718433348;"tSI";2000 148 | "147";"Car";"GSI";0,0209606863523015;"tSI";2000 149 | "148";"Cw";"GSI";0,0601771341336055;"tSI";2000 150 | "149";"Cm";"GSI";0,532831438737753;"tSI";2000 151 | "150";"LAI";"GSI";0,2079621355924;"tSI";2000 152 | -------------------------------------------------------------------------------- /Plotting/CorrelationPlots_Final.R: -------------------------------------------------------------------------------- 1 | #library for PROSAIL and also Spectral Angle Mapper 2 | library(hsdar) 3 | 4 | #Latin hypercube comes from here 5 | library(FME) 6 | 7 | #for more options on generating random samples 8 | library(MCMCglmm) 9 | 10 | #the single target classifier 11 | #library(randomForest) 12 | 13 | #machine learning librarys 14 | #library(randomForestSRC) 15 | #library(ANN2) 16 | 17 | #for scaling and unscaling variables 18 | library(DMwR) 19 | 20 | #GIS/RS 21 | library(maptools) 22 | library(rgeos) 23 | library(rgdal) 24 | library(raster) 25 | library(sp) 26 | 27 | #sensitivity analysis 28 | #library(sensitivity) 29 | 30 | #plotting packages 31 | library(ggplot2) 32 | library(ggthemes) 33 | 34 | #data frame operations5 35 | library(reshape2) 36 | 37 | #gridExtra 38 | library(gridExtra) 39 | 40 | #importing fonts 41 | library(extrafont) 42 | #font_import() 43 | 44 | loadfonts(device="win") 45 | loadfonts() 46 | 47 | ## custom function to reshape text, subscripts and etc 48 | text_convert <- function(text_in){ 49 | 50 | if (text_in =='cab'){ 51 | text_out = expression('C'['ab']) 52 | } 53 | if (text_in =='cw'){ 54 | text_out = expression('C'['w']) 55 | } 56 | if (text_in =='cm'){ 57 | text_out = expression('C'['m']) 58 | } 59 | if (text_in =='lai'){ 60 | text_out = expression('LAI') 61 | } 62 | if (text_in =='car'){ 63 | text_out = expression('Car') 64 | } 65 | 66 | return(text_out) 67 | } 68 | 69 | ## custom function to generate the breaks of each input trait 70 | break_lims <- function(text_in){ 71 | 72 | if (text_in =='cab'){ 73 | out_list = c(0,60,120) 74 | } 75 | if (text_in =='cw'){ 76 | out_list = c(0,0.005,0.01) 77 | } 78 | if (text_in =='cm'){ 79 | out_list = c(0,0.005,0.01) 80 | } 81 | if (text_in =='lai'){ 82 | out_list = c(0,5,10) 83 | } 84 | if (text_in =='car'){ 85 | out_list = c(0,30,60) 86 | } 87 | 88 | return(out_list ) 89 | } 90 | break_lims('cab') 91 | 92 | ## custom function to generate the breaks of each input band 93 | break_lims_bands <- function(text_in){ 94 | 95 | if (text_in =='B2'){ 96 | out_list = c(.02,.03,.04) 97 | } 98 | if (text_in =='B3'){ 99 | out_list = c(.02,.06,.10) 100 | } 101 | if (text_in =='B4'){ 102 | out_list = c(.02,.03,.04,.05) 103 | } 104 | if (text_in =='B5'){ 105 | out_list = c(0,.1,.2) 106 | } 107 | if (text_in =='B6'){ 108 | out_list = c(.2,.3,.4,.5) 109 | } 110 | if (text_in =='B7'){ 111 | out_list = c(.3,.4,.5,.6) 112 | } 113 | if (text_in =='B8A'){ 114 | out_list = c(.3,.4,.5,.6) 115 | } 116 | if (text_in =='B11'){ 117 | out_list = c(.2,.3,.4) 118 | } 119 | if (text_in =='B12'){ 120 | out_list = c(.1,.15,.2) 121 | } 122 | 123 | 124 | return(out_list ) 125 | } 126 | break_lims_bands('B2') 127 | 128 | 129 | #multiplot function -> http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/ 130 | multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { 131 | library(grid) 132 | 133 | # Make a list from the ... arguments and plotlist 134 | plots <- c(list(...), plotlist) 135 | 136 | numPlots = length(plots) 137 | 138 | # If layout is NULL, then use 'cols' to determine layout 139 | if (is.null(layout)) { 140 | # Make the panel 141 | # ncol: Number of columns of plots 142 | # nrow: Number of rows needed, calculated from # of cols 143 | layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), 144 | ncol = cols, nrow = ceiling(numPlots/cols)) 145 | } 146 | 147 | if (numPlots==1) { 148 | print(plots[[1]]) 149 | 150 | } else { 151 | # Set up the page 152 | grid.newpage() 153 | pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout)))) 154 | 155 | # Make each plot, in the correct location 156 | for (i in 1:numPlots) { 157 | # Get the i,j matrix positions of the regions that contain this subplot 158 | matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE)) 159 | 160 | print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, 161 | layout.pos.col = matchidx$col)) 162 | } 163 | } 164 | } 165 | 166 | 167 | 168 | #latex font 169 | par(family = "LM Roman 10") 170 | 171 | 172 | #my.df <- read.csv2("C:/Paper/Tables/Final_Data/Traits_Spectra_car.csv") 173 | #head(my.df) 174 | #my.df <- my.df[,-1] 175 | #head(my.df) 176 | #sample.rows <- sample(seq(1,nrow(my.df)),100) 177 | #sub.df <- my.df[sample.rows,] 178 | #sel.df <- my.df[sample.rows,] 179 | #write.csv2(sel.df,"C:/Paper/Tables/Final_Data/Traits_Spectra_car_PlotSel.csv") 180 | 181 | #fetching selected 182 | sel.df <- read.csv2("C:/Paper/Tables/Final_Data/Traits_Spectra_car_PlotSel.csv") 183 | sel.df <- sel.df[,-1] 184 | 185 | 186 | #setting standard background theme 187 | txt_size = 26 188 | theme_set(theme_light(base_family ='serif',#"LM Roman 10", 189 | base_size=txt_size )) 190 | 191 | #a list to store all the pltos 192 | plot_list <- list() 193 | 194 | #number of breaks in the axis plots 195 | n_steps = 3 196 | 197 | 198 | #plot counter 199 | i = 1 200 | 201 | for (t_i in 10:14){ 202 | 203 | print(t_i) 204 | print(names(sel.df)[t_i]) 205 | 206 | for (b_i in 1:9){ 207 | 208 | 209 | #loading row column 210 | temp.df = sel.df[,c(t_i,b_i)] 211 | 212 | #naming to 213 | names(temp.df)=c("Trait","Band") 214 | 215 | #getting text for band 216 | band_txt = names(sel.df)[b_i] 217 | print(band_txt) 218 | 219 | #controling the breaks 220 | #max_x = max(temp.df$Trait) 221 | #min_x = min(temp.df$Trait) 222 | #stp_x = (max_x-min_x)/n_steps 223 | 224 | #max_y = max(temp.df$Band) 225 | #min_y = min(temp.df$Band) 226 | #stp_y = (max_y-min_y)/n_steps 227 | 228 | #controlling the Breaks y 229 | brk_list_bands = break_lims_bands(names(sel.df)[b_i]) 230 | brk_list = break_lims(names(sel.df)[t_i]) 231 | 232 | if (i <= 9){ 233 | txt_title = band_txt 234 | } else{ 235 | txt_title = "" 236 | } 237 | 238 | if (band_txt == "B2"){ 239 | 240 | y_txt = text_convert(names(sel.df)[t_i]) 241 | 242 | 243 | 244 | p1= ggplot(temp.df,aes(x=Trait,y=Band))+ 245 | #p1= ggplot(x=my.df[,b_i],y=my.df[,t_i])+ 246 | #geometry types 247 | geom_point()+ 248 | geom_smooth(method = "lm", linetype = "dashed")+ 249 | 250 | #breaks 251 | scale_x_continuous(breaks = brk_list)+ 252 | scale_y_continuous(breaks = brk_list_bands)+ 253 | 254 | #theme stuff 255 | theme(axis.title.y=element_text(angle = 0,vjust=.5,size=txt_size + 2), 256 | title = element_text(hjust=.5,size=txt_size +2)#, 257 | #axis.text.x=element_text(txt_size+2), 258 | #axis.text.y=element_text(txt_size+2) 259 | #text=element_text(), 260 | )+ 261 | labs(x="", 262 | y=y_txt, 263 | title=txt_title)#+ 264 | 265 | #theme_minimal() 266 | 267 | } 268 | 269 | 270 | 271 | else{ 272 | 273 | 274 | 275 | p1= ggplot(temp.df,aes(x=Trait,y=Band))+ 276 | #p1= ggplot(x=my.df[,b_i],y=my.df[,t_i])+ 277 | #geometry types 278 | geom_point()+ 279 | geom_smooth(method = "lm", linetype = "dashed")+ 280 | 281 | #breaks 282 | scale_x_continuous(breaks = brk_list)+ 283 | scale_y_continuous(breaks = brk_list_bands)+ 284 | 285 | #theme stuff 286 | theme(#axis.title.y=element_text(angle = 0,vjust=.5,size=18), 287 | title = element_text(hjust=.5,size=txt_size +2)#, 288 | #axis.text.x=element_text(txt_size+2), 289 | #axis.text.y=element_text(txt_size+2) 290 | #text=element_text(), 291 | )+ 292 | labs(x="", 293 | y="", 294 | title=txt_title) 295 | #+ 296 | #theme_minimal() 297 | 298 | } 299 | 300 | 301 | #adding to the list 302 | plot_list[[i]] <- p1 303 | i = i+1 304 | #plotter 305 | #plot(p1) 306 | 307 | } 308 | 309 | } 310 | 311 | 312 | 313 | library(cowplot) 314 | 315 | pdf("C:/Paper/Tables/Final_Data/PearsonR_ByBandPlot_Corrected_Reviewed_02.pdf",width=30,height=20,paper='special') 316 | 317 | plot_grid(plot_list[[1]],plot_list[[2]],plot_list[[3]],plot_list[[4]],plot_list[[5]],plot_list[[6]],plot_list[[7]],plot_list[[8]],plot_list[[9]], 318 | plot_list[[10]],plot_list[[11]],plot_list[[12]],plot_list[[13]],plot_list[[14]],plot_list[[15]],plot_list[[16]],plot_list[[17]],plot_list[[18]], 319 | plot_list[[19]],plot_list[[20]],plot_list[[21]],plot_list[[22]],plot_list[[23]],plot_list[[24]],plot_list[[25]],plot_list[[26]],plot_list[[27]], 320 | plot_list[[28]],plot_list[[29]],plot_list[[30]],plot_list[[31]],plot_list[[32]],plot_list[[33]],plot_list[[34]],plot_list[[35]],plot_list[[36]], 321 | plot_list[[37]],plot_list[[38]],plot_list[[39]],plot_list[[40]],plot_list[[41]],plot_list[[42]],plot_list[[43]],plot_list[[44]],plot_list[[45]], 322 | ncol=9,nrow=5,scale=.965, align = 'vh') 323 | 324 | dev.off() 325 | 326 | 327 | -------------------------------------------------------------------------------- /Plotting/GSI_Plots_Final_01.R: -------------------------------------------------------------------------------- 1 | #library for PROSAIL and also Spectral Angle Mapper 2 | library(hsdar) 3 | 4 | #Latin hypercube comes from here 5 | library(FME) 6 | 7 | #for more options on generating random samples 8 | library(MCMCglmm) 9 | 10 | #the single target classifier 11 | #library(randomForest) 12 | 13 | #machine learning librarys 14 | #library(randomForestSRC) 15 | #library(ANN2) 16 | 17 | #for scaling and unscaling variables 18 | library(DMwR) 19 | 20 | #GIS/RS 21 | library(maptools) 22 | library(rgeos) 23 | library(rgdal) 24 | library(raster) 25 | library(sp) 26 | 27 | #sensitivity analysis 28 | library(sensitivity) 29 | 30 | #plotting packages 31 | library(ggplot2) 32 | library(ggthemes) 33 | 34 | #data frame operations5 35 | library(reshape2) 36 | 37 | 38 | #importing fonts 39 | library(extrafont) 40 | loadfonts(device="win") 41 | #font_import() 42 | y#latex font 43 | par(family = "LM Roman 10") 44 | 45 | 46 | 47 | ############################################################## 48 | ############ by sample number ################################ 49 | ############################################################## 50 | 51 | 52 | #loading the csv 53 | all.df = read.csv2("C:/Paper/R_Scripts/All_sensitivity.csv") 54 | m_mSI = all.df[all.df$type=="mSI",] 55 | m_iSI = all.df[all.df$type=="iSI",] 56 | m_tSI = all.df[all.df$type=="tSI",] 57 | 58 | 59 | head(all.df) 60 | 61 | all.df$Order <- NA 62 | all.df$Order[all.df$type=="mSI"] <- "First-order" 63 | all.df$Order[all.df$type=="iSI"] <- "Interactions" 64 | all.df$Order[all.df$type=="tSI"] <- "Total-order" 65 | 66 | gc() 67 | 68 | head(all.df) 69 | 70 | 71 | #png("C:/Paper/R_Scripts/GSI_By_Samples_2.png", 72 | # width = 1000, height = 300, units = "px",pointsize=1) 73 | pdf("C:/Paper/Tables/Final_Data/Results_GSI_BySample.pdf",width=25,height=10,paper='special') 74 | 75 | plot.fig <- ggplot(all.df[all.df$variable!="GSI" & 76 | all.df$type!="iSI" & 77 | all.df$SampleNr < 6000,],aes(SampleNr,value,color=Trait))+ 78 | geom_point(pch=19,size=2)+geom_line(linetype="dashed",size=.1)+ 79 | 80 | #ggtitle("First order GSI")+ 81 | facet_wrap(Order~variable,ncol=9)+ 82 | xlab("Samples")+ 83 | ylab("Sensitivity index")+ 84 | theme_hc()+ 85 | theme(text=element_text(size=16, family="serif"),legend.title = element_blank()) 86 | 87 | 88 | print(plot.fig) 89 | 90 | dev.off() 91 | 92 | 93 | ### Barplot of the interaction and band variance 94 | df.gsi <- read.csv2("C:/Paper/R_Scripts/All_sensitivity_2000_samples.csv") 95 | 96 | #the logic for the normalized graphic is on excel sheet normalized square 97 | head(df.gsi) 98 | unique(df.gsi$variable) 99 | 100 | 101 | #making color fills 102 | #http://sape.inf.usi.ch/quick-reference/ggplot2/colour 103 | df.gsi$ColorFill = NA 104 | df.gsi$ColorFill[df.gsi$variable=="B02"] <- "blue2" 105 | df.gsi$ColorFill[df.gsi$variable=="B03"] <- "green4" 106 | df.gsi$ColorFill[df.gsi$variable=="B04"] <- "red" 107 | df.gsi$ColorFill[df.gsi$variable=="B05"] <- "orange" 108 | df.gsi$ColorFill[df.gsi$variable=="B06"] <- "orange3" 109 | df.gsi$ColorFill[df.gsi$variable=="B07"] <- "orange4" 110 | df.gsi$ColorFill[df.gsi$variable=="B8A"] <- "indianred" 111 | df.gsi$ColorFill[df.gsi$variable=="B11"] <- "gray" 112 | df.gsi$ColorFill[df.gsi$variable=="B12"] <- "black" 113 | df.gsi$ColorFill[df.gsi$variable=="GSI"] <- "black" 114 | 115 | #we have to cheat the plotting device due to the order of the bands 116 | df.gsi$band_order <- as.character(df.gsi$variable) 117 | #df.gsi$band_order[81:85] <- "B08" 118 | df.gsi$band_order[df.gsi$band_order=="B8A"] <- "B08" 119 | 120 | 121 | 122 | 123 | temp.df <- df.gsi[df.gsi$variable!="GSI",]# & 124 | #df.gsi$type != 'iSI',] 125 | 126 | temp.df$type_2 = NA 127 | temp.df$type_2[temp.df$type=="iSI"] = "BiSI" 128 | temp.df$type_2[temp.df$type=="mSI"] = "AmSI" 129 | temp.df$type_2[temp.df$type=="tSI"] = "CtSI" 130 | 131 | #png("C:/Paper/R_Scripts/GSI_by_Trait_3si.png", 132 | # width = 600, height = 400, units = "px",pointsize=12) 133 | 134 | pdf("C:/Paper/Tables/Final_Data/Results_GSI_By_Trait.pdf",width=20,height=8,paper='special') 135 | 136 | #in one go 137 | plt.fig <- ggplot(temp.df,aes(Trait,value, fill=band_order))+ 138 | geom_bar(stat="identity",position="dodge")+ 139 | scale_fill_manual(values=unique(temp.df$ColorFill), 140 | labels=c("B02","B03","B04", 141 | "B05","B06","B07", 142 | "B8A","B11","B12"))+ 143 | ylab("Sensitivity index")+ 144 | xlab("Biophysical traits")+ 145 | #ggtitle("First order GSI")+ 146 | coord_flip()+ 147 | facet_wrap(~type_2,ncol=3,labeller = labeller(type_2 = c("BiSI" = "Interactions", 148 | "AmSI" = "First-order", 149 | "CtSI" = "Total-order")))+ 150 | theme_hc()+ 151 | theme(text=element_text(size=25, family="serif"),legend.title = element_blank(), 152 | panel.spacing = unit(1.5, "lines")) 153 | 154 | print(plt.fig) 155 | 156 | dev.off() 157 | 158 | 159 | 160 | ### facet_wrap(~type_2,ncol=3,labeller = labeller(type = c("iSI" = "Interactions", 161 | ###"mSI" = "First-order", 162 | ###"tSI" = "Total-order")))+ 163 | 164 | 165 | 166 | 167 | ####### to rerun the 2k example, run here ##################### 168 | custom.prosail.df = function(x){ 169 | 170 | Cab = x[,1] 171 | Car = x[,2] 172 | Cw = x[,3] 173 | Cm = x[,4] 174 | LAI = x[,5] 175 | train.spclib = PROSAIL(Cab=Cab,Car=Car,Cw=Cw,Cm=Cm,LAI = LAI, 176 | tts = sun_zenith, 177 | tto = obs_zenith, 178 | psi = rel_azimut) 179 | 180 | #to make this hyperspectral, just comment the next line 181 | train.spclib <- spectralResampling(train.spclib,"Sentinel2",response_function = T)[,c(2,3,4,5,6,7,9,12,13)] 182 | #if output matrix 183 | #mat.out = spectra(train.spclib) 184 | #if output df 185 | df.out = as.data.frame(spectra(train.spclib)) 186 | 187 | #and of course comment here also if you want to do hyperspectral 188 | names(df.out)<- c("B02","B03","B04", 189 | "B05","B06","B07", 190 | "B8A","B11","B12") 191 | 192 | return(df.out) 193 | } 194 | args.efast =list( factors=c("Cab","Car","Cw","Cm","LAI"), n=2000, q = "qunif", 195 | q.arg = list(list(min=5, max=120), 196 | list(min=5, max=60), 197 | list(min = 0.01, max = 0.05), 198 | list(min = 0.01, max = 0.05), 199 | list(min = 0.5, max = 10))) 200 | 201 | sens.99fast = multisensi(design = fast99, model = custom.prosail.df, 202 | center = FALSE, reduction = NULL, analysis = analysis.sensitivity, 203 | design.args=args.efast, 204 | analysis.args=list(keep.outputs=FALSE)) 205 | 206 | plot(sens.99fast, color = terrain.colors) 207 | plot(sens.99fast,normalized = T, color = terrain.colors, gsi.plot = FALSE,cumul=T) 208 | 209 | 210 | m_SI = sens.99fast$SI 211 | m_mSI = sens.99fast$mSI 212 | m_tSI = sens.99fast$tSI 213 | m_iSI = sens.99fast$iSI 214 | 215 | 216 | t_mSI$Trait = rownames(t_mSI) 217 | t_tSI$Trait = rownames(t_tSI) 218 | t_iSI$Trait = rownames(t_iSI) 219 | 220 | 221 | 222 | m_mSI=melt(t_mSI,ID="Trait") 223 | m_tSI=melt(t_tSI,ID="Trait") 224 | m_iSI=melt(t_iSI,ID="Trait") 225 | 226 | m_mSI$type = "mSI" 227 | m_tSI$type = "tSI" 228 | m_iSI$type = "iSI" 229 | 230 | #and finally the number of samples 231 | m_mSI$SampleNr = 2000 232 | m_tSI$SampleNr = 2000 233 | m_iSI$SampleNr = 2000 234 | 235 | all.df = rbind(m_mSI,m_iSI,m_tSI) 236 | write.csv2(all.df,"C:/Paper/R_Scripts/All_sensitivity_2000_samplesexplore.csv") 237 | 238 | 239 | all.df = rbind(m_mSI,m_iSI,m_tSI) 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | warnings() 255 | 256 | unique(m_mSI$type) 257 | 258 | summary(m_mSI) 259 | 260 | names(all.df) 261 | c_step 262 | #first order plot 263 | head(m_mSI) 264 | ggplot(m_mSI[m_mSI$variable!="GSI",],aes(SampleNr,value,color=Trait))+ 265 | geom_point(size=3)+geom_line(linetype="dashed")+ 266 | ggtitle("First order GSI")+ 267 | facet_wrap(~variable,ncol=5)+ 268 | theme_hc() 269 | 270 | ggplot(m_iSI[m_iSI$variable!="GSI",],aes(SampleNr,value,color=Trait))+ 271 | geom_point(size=3)+geom_line(linetype="dashed")+ 272 | ggtitle("Interaction GSI")+ 273 | facet_wrap(~variable,ncol=5)+ 274 | theme_hc() 275 | 276 | ggplot(m_tSI[m_tSI$variable!="GSI",],aes(SampleNr,value,color=Trait))+ 277 | geom_point(size=3)+geom_line(linetype="dashed")+ 278 | ggtitle("Total order GSI")+ 279 | facet_wrap(~variable,ncol=5)+ 280 | theme_hc() 281 | 282 | 283 | 284 | 285 | ##### not working 286 | http://iltabiai.github.io/tips/latex/2015/09/15/latex-tikzdevice-r.html 287 | library(tikzDevice) 288 | 289 | y <- exp(seq(1,10,.1)) 290 | x <- 1:length(y) 291 | data <- data.frame(x = x, y = y) 292 | 293 | 294 | 295 | 296 | tikz(file = "C:/Paper/R_Scripts/plot_test.tex", width = 5, height = 5) 297 | 298 | plot <- ggplot(data, aes(x = x, y = y)) + 299 | geom_line() + 300 | #Space does not appear after Latex 301 | ggtitle( paste("Fancy \\LaTeX ", "\\hspace{0.01cm} title")) + 302 | labs( x = "$x$ = Time", y = "$\\Phi$ = Innovation output") + 303 | theme_bw() 304 | 305 | 306 | dev.off() 307 | -------------------------------------------------------------------------------- /R/GSI_Analysis_v01.R: -------------------------------------------------------------------------------- 1 | #library for PROSAIL and also Spectral Angle Mapper 2 | library(hsdar) 3 | 4 | #Latin hypercube comes from here 5 | library(FME) 6 | 7 | #for more options on generating random samples 8 | library(MCMCglmm) 9 | 10 | #the single target classifier 11 | #library(randomForest) 12 | 13 | #machine learning librarys 14 | #library(randomForestSRC) 15 | #library(ANN2) 16 | 17 | #for scaling and unscaling variables 18 | library(DMwR) 19 | 20 | #GIS/RS 21 | library(maptools) 22 | library(rgeos) 23 | library(rgdal) 24 | library(raster) 25 | library(sp) 26 | 27 | #sensitivity analysis 28 | library(sensitivity) 29 | 30 | #plotting packages 31 | library(ggplot2) 32 | library(ggthemes) 33 | 34 | #data frame operations5 35 | library(reshape2) 36 | 37 | 38 | 39 | #links of interest 40 | #https://www.rdocumentation.org/packages/sensitivity/versions/1.17.1 41 | #https://cran.r-project.org/web/packages/multisensi/vignettes/multisensi-vignette.pdf 42 | #https://cran.r-project.org/web/packages/sensitivity/sensitivity.pdf 43 | #https://www.rdocumentation.org/packages/multisensi/versions/2.1-1/topics/multisensi 44 | 45 | 46 | 47 | 48 | 49 | #generating samples 50 | param.maxmin <- matrix(c(#1.5, 1.9, #leaf layers or leaf structure 51 | 15,45, #Cab 52 | 10,50, #Car 53 | 0.01,0.02, #Cw #original it was from [0.01 to 0.02] but i suspect saturation 54 | 0.01,0.02, #Cm 55 | 0.1,4.5),#LAI 56 | #0.05,0.1), #hotstop 57 | nrow=5,ncol = 2,byrow = T) 58 | 59 | #creating a training space 60 | #train.n <- 50 * nrow(param.maxmin) #this represents the number of runs that prosail will be, x pts per Trait 61 | #train.LHS <- Latinhyper(param.maxmin,train.n) 62 | 63 | 64 | 65 | #sentinel position 66 | sun_zenith = 45 67 | obs_zenith = 45 68 | rel_azimut = 0 69 | 70 | 71 | #actually we have to generate a function: 72 | names(train.trait.df) 73 | x=c(10,1,.002,.002,10) 74 | custom.prosail = function(x){ 75 | 76 | Cab = x[1] 77 | Car = x[2] 78 | Cw = x[3] 79 | Cm = x[4] 80 | LAI = x[5] 81 | train.spclib = PROSAIL(Cab=Cab,Car=Car,Cw=Cw,Cm=Cm,LAI = LAI, 82 | tts = sun_zenith, 83 | tto = obs_zenith, 84 | psi = rel_azimut) 85 | train.spclib <- spectralResampling(train.spclib,"Sentinel2",response_function = T)[,c(2,3,4,5,6,7,9,12,13)] 86 | #if output matrix 87 | #mat.out = spectra(train.spclib) 88 | #if output df 89 | df.out = as.data.frame(spectra(train.spclib)) 90 | names(df.out)<- c("B02","B03","B04", 91 | "B05","B06","B07", 92 | "B8A","B11","B12") 93 | 94 | return(df.out) 95 | } 96 | 97 | x.df = t(as.data.frame(x)) 98 | names(x.df) = c("Cab","Cab","Cw","Cm","LAI") 99 | custom.prosail.df = function(x){ 100 | 101 | Cab = x[,1] 102 | Car = x[,2] 103 | Cw = x[,3] 104 | Cm = x[,4] 105 | LAI = x[,5] 106 | train.spclib = PROSAIL(Cab=Cab,Car=Car,Cw=Cw,Cm=Cm,LAI = LAI, 107 | tts = sun_zenith, 108 | tto = obs_zenith, 109 | psi = rel_azimut) 110 | 111 | #to make this hyperspectral, just comment the next line 112 | train.spclib <- spectralResampling(train.spclib,"Sentinel2",response_function = T)[,c(2,3,4,5,6,7,9,12,13)] 113 | #if output matrix 114 | #mat.out = spectra(train.spclib) 115 | #if output df 116 | df.out = as.data.frame(spectra(train.spclib)) 117 | 118 | #and of course comment here also if you want to do hyperspectral 119 | names(df.out)<- c("B02","B03","B04", 120 | "B05","B06","B07", 121 | "B8A","B11","B12") 122 | 123 | return(df.out) 124 | } 125 | 126 | library(multisensi) 127 | custom.prosail(x) 128 | custom.prosail.df(x.df) 129 | 130 | #time to call the functions for one case 131 | 132 | args.efast =list( factors=c("Cab","Car","Cw","Cm","LAI"), n=500, q = "qunif", 133 | q.arg = list(list(min=5, max=120), 134 | list(min=5, max=60), 135 | list(min = 0.01, max = 0.05), 136 | list(min = 0.01, max = 0.05), 137 | list(min = 0.5, max = 10))) 138 | 139 | sens.99fast = multisensi(design = fast99, model = custom.prosail.df, 140 | center = FALSE, reduction = NULL, analysis = analysis.sensitivity, 141 | design.args=args.efast, 142 | analysis.args=list(keep.outputs=FALSE)) 143 | 144 | str(sens.99fast) 145 | sens.99fast$call.info 146 | 147 | #multisensi::plot.gsi(sens.99fast) 148 | plot(sens.99fast, normalized = F, color = terrain.colors) 149 | plot(sens.99fast, normalized = T, color = terrain.colors, gsi.plot = FALSE) 150 | 151 | m_SI = sens.99fast$SI 152 | m_mSI = sens.99fast$mSI 153 | m_tSI = sens.99fast$tSI 154 | m_iSI = sens.99fast$iSI 155 | 156 | #First step is to find the nr of samples that stabilizess the analysis of variance 157 | 158 | 159 | #oldschoool iterations because im sleepy 160 | maxstep = 5000 161 | c_step = vector() 162 | c_step = c(c_step,100) 163 | it = 1 164 | while (c_step[it] <= maxstep){ 165 | #there was this cool trick with qexp but it was creting too many iterations plot(50+(50*qexp((1:100)/100))) 166 | c_step = c(c_step,ceiling(c_step[it]*2)) 167 | it=it+1 168 | 169 | } 170 | 171 | 172 | 173 | k=1 174 | #for (i in 100:105){ #use this for testing smaller loops 175 | for (i in c_step){ 176 | 177 | print(paste("Processing sample nr:",i)) 178 | 179 | args.efast =list( factors=c("Cab","Car","Cw","Cm","LAI"), n=i, q = "qunif", 180 | q.arg = list(list(min=5, max=120), 181 | list(min=5, max=60), 182 | list(min = 0.01, max = 0.05), 183 | list(min = 0.01, max = 0.05), 184 | list(min = 0.5, max = 10))) 185 | 186 | 187 | sens.99fast = multisensi(design = fast99, model = custom.prosail.df,dimension = NULL, 188 | center = FALSE, reduction = NULL, analysis = analysis.sensitivity, 189 | design.args=args.efast, 190 | analysis.args=list(keep.outputs=FALSE)) 191 | 192 | if (k == 1){ 193 | #t_SI = sens.99fast$SI 194 | #$Trait = rownames(t_SI) 195 | t_mSI = sens.99fast$mSI 196 | t_tSI = sens.99fast$tSI 197 | t_iSI = sens.99fast$iSI 198 | 199 | t_mSI$Trait = rownames(t_mSI) 200 | t_tSI$Trait = rownames(t_tSI) 201 | t_iSI$Trait = rownames(t_iSI) 202 | 203 | m_mSI=melt(t_mSI,ID="Trait") 204 | m_tSI=melt(t_tSI,ID="Trait") 205 | m_iSI=melt(t_iSI,ID="Trait") 206 | 207 | m_mSI$type = "mSI" 208 | m_tSI$type = "tSI" 209 | m_iSI$type = "iSI" 210 | 211 | #and finally the number of samples 212 | m_mSI$SampleNr = i 213 | m_tSI$SampleNr = i 214 | m_iSI$SampleNr = i 215 | #and we update k 216 | k = k+1 217 | } 218 | 219 | if (k>1){ 220 | #$Trait = rownames(t_SI) 221 | t_mSI = sens.99fast$mSI 222 | t_tSI = sens.99fast$tSI 223 | t_iSI = sens.99fast$iSI 224 | 225 | t_mSI$Trait = rownames(t_mSI) 226 | t_tSI$Trait = rownames(t_tSI) 227 | t_iSI$Trait = rownames(t_iSI) 228 | 229 | t_mSI=melt(t_mSI,ID="Trait") 230 | t_tSI=melt(t_tSI,ID="Trait") 231 | t_iSI=melt(t_iSI,ID="Trait") 232 | 233 | t_mSI$type = "mSI" 234 | t_tSI$type = "tSI" 235 | t_iSI$type = "iSI" 236 | 237 | t_mSI$SampleNr = i 238 | t_tSI$SampleNr = i 239 | t_iSI$SampleNr = i 240 | 241 | #and now we add them to the bottom of the dataframe 242 | 243 | m_mSI <- rbind(m_mSI,t_mSI) 244 | m_tSI <- rbind(m_tSI,t_tSI) 245 | m_iSI <- rbind(m_iSI,t_iSI) 246 | 247 | k = k +1 248 | } 249 | 250 | 251 | } 252 | 253 | 254 | #saving all the data to separate csv 255 | all.df = rbind(m_mSI,m_iSI,m_tSI) 256 | write.csv2(all.df,"C:/Paper/R_Scripts/All_sensitivity") 257 | 258 | #loading the csv 259 | all.df = read.csv2("C:/Paper/R_Scripts/All_sensitivity.csv") 260 | m_mSI = all.df[all.df$type=="mSI",] 261 | m_iSI = all.df[all.df$type=="iSI",] 262 | m_tSI = all.df[all.df$type=="tSI",] 263 | 264 | 265 | 266 | ggplot(m_tSI[m_mSI$variable=="GSI",],aes(SampleNr,value,color=variable))+ 267 | geom_point(size=3)+geom_line(linetype="dashed")+ 268 | ggtitle("First order GSI")+ 269 | facet_wrap(~Trait,ncol=5)+ 270 | theme_hc() 271 | 272 | 273 | 274 | unique(m_mSI$type) 275 | 276 | summary(m_mSI) 277 | 278 | names(all.df) 279 | c_step 280 | #first order plot 281 | head(m_mSI) 282 | ggplot(m_mSI[m_mSI$variable!="GSI",],aes(SampleNr,value,color=variable))+ 283 | geom_point(size=3)+geom_line(linetype="dashed")+ 284 | ggtitle("First order GSI")+ 285 | facet_wrap(~Trait,ncol=5)+ 286 | theme_hc() 287 | 288 | ggplot(m_iSI,aes(SampleNr,value,color=Trait))+ 289 | geom_point(size=3)+geom_line(linetype="dashed")+ 290 | ggtitle("Interaction GSI")+ 291 | facet_wrap(~variable,ncol=5)+ 292 | theme_hc() 293 | 294 | ggplot(m_tSI,aes(SampleNr,value,color=Trait))+ 295 | geom_point(size=3)+geom_line(linetype="dashed")+ 296 | ggtitle("Total order GSI")+ 297 | facet_wrap(~variable,ncol=5)+ 298 | theme_hc() 299 | 300 | 301 | 302 | 303 | ############################################################################################################ 304 | ### repeating the run with only 2000 samples ############################################################### 305 | ############################################################################################################ 306 | ### Notice -> this will override the above steps -> load the csv if you want to repeat them ################ 307 | ############################################################################################################ 308 | 309 | #bar plot of Trait ~ GSI 310 | #REmoving the GSI 311 | 312 | args.efast =list( factors=c("Cab","Car","Cw","Cm","LAI"), n=2000, q = "qunif", 313 | q.arg = list(list(min=5, max=120), 314 | list(min=5, max=60), 315 | list(min = 0.01, max = 0.05), 316 | list(min = 0.01, max = 0.05), 317 | list(min = 0.5, max = 10))) 318 | 319 | sens.99fast = multisensi(design = fast99, model = custom.prosail.df, 320 | center = FALSE, reduction = NULL, analysis = analysis.sensitivity, 321 | design.args=args.efast, 322 | analysis.args=list(keep.outputs=FALSE)) 323 | 324 | 325 | plot(sens.99fast, normalized = T, color = terrain.colors, gsi.plot = FALSE) 326 | 327 | #and creating the table 328 | t_mSI = sens.99fast$mSI 329 | t_tSI = sens.99fast$tSI 330 | t_iSI = sens.99fast$iSI 331 | 332 | t_mSI$Trait = rownames(t_mSI) 333 | t_tSI$Trait = rownames(t_tSI) 334 | t_iSI$Trait = rownames(t_iSI) 335 | 336 | m_mSI=melt(t_mSI,ID="Trait") 337 | m_tSI=melt(t_tSI,ID="Trait") 338 | m_iSI=melt(t_iSI,ID="Trait") 339 | 340 | m_mSI$type = "mSI" 341 | m_tSI$type = "tSI" 342 | m_iSI$type = "iSI" 343 | 344 | #and finally the number of samples 345 | m_mSI$SampleNr = 2000 346 | m_tSI$SampleNr = 2000 347 | m_iSI$SampleNr = 2000 348 | 349 | 350 | #bar plot of Trait ~ GSI 351 | #REmoving the GSI 352 | 353 | combine.df = rbind(m_mSI,m_tSI,m_iSI) 354 | write.csv2(combine.df,"C:/Paper/R_Scripts/All_sensitivity_2000_samples.csv") 355 | 356 | #in one go 357 | ggplot(combine.df[combine.df$variable!="GSI",],aes(Trait,value, fill=variable))+ 358 | geom_bar(stat="identity",position="dodge")+ 359 | #ggtitle("First order GSI")+ 360 | coord_flip()+ 361 | facet_wrap(~type,ncol=3,labeller = labeller(type = c("iSI" = "Interaction GSI", 362 | "mSI" = "First order GSI", 363 | "tSI" = "Total order GSI"))) 364 | theme_hc() 365 | 366 | #one by one 367 | 368 | ggplot(m_mSI[m_mSI$variable!="GSI",],aes(Trait,value, fill=variable))+ 369 | geom_bar(stat="identity",position="dodge")+ 370 | ggtitle("First order GSI")+ 371 | coord_flip()+ 372 | theme_hc() 373 | 374 | ggplot(m_iSI[m_iSI$variable!="GSI",],aes(Trait,value, fill=variable))+ 375 | geom_bar(stat="identity",position="dodge")+ 376 | ggtitle("Interaction GSI")+ 377 | coord_flip()+ 378 | theme_hc() 379 | 380 | ggplot(m_tSI[m_tSI$variable!="GSI",],aes(Trait,value, fill=variable))+ 381 | geom_bar(stat="identity",position="dodge")+ 382 | ggtitle("Total order GSI")+ 383 | coord_flip()+ 384 | theme_hc() 385 | 386 | 387 | #summary of first order + TSI vs bands on X axis, per trait 388 | 389 | head(combine.df) 390 | #names(combine.df) <- c("Trait","variable","value","Type","SampleNr") 391 | #in one go 392 | 393 | 394 | #lets summarize the data 395 | head(combine.df) 396 | 397 | combine.df <- read.csv2("C:/Paper/R_Scripts/All_sensitivity_2000_samples") 398 | 399 | agg.df = aggregate(value~variable+type,data=combine.df[combine.df$variable!="GSI",],FUN=sum) 400 | 401 | agg.df 402 | 403 | library(dplyr) 404 | 405 | #removing the interaction because the interaction is Total - single 406 | ymin_vec = agg.df[agg.df$type=="mSI",] 407 | ymax_vec = agg.df[agg.df$type=="tSI",] 408 | 409 | ggplot(agg.df[agg.df$type!="iSI",],aes(variable,value,color=type,group=type))+ 410 | geom_point(size=3)+geom_line(linetype="dashed")+ 411 | geom_ribbon(aes(ymin=agg.df$value,ymax=agg.df$value))+ 412 | ylim(0,1.5)+ 413 | theme_hc() 414 | 415 | 416 | ggplot(ymin_vec,aes(variable,value,color="red",group=type))+ 417 | scale_fill_discrete(labels = c("First order Sensitivity index", "Total order sensitivity index"))+ 418 | geom_ribbon(aes(ymin=ymin_vec$value,ymax=ymax_vec$value),fill = "grey50")+ 419 | geom_point(size=5)+ 420 | geom_line(linetype="dashed",size=2)+ 421 | geom_point(data=ymax_vec,aes(variable,value,color="blue",group=type),size=5)+ 422 | geom_line(data=ymax_vec,aes(variable,value,color="blue",group=type),linetype="dashed",size=2)+ 423 | ylim(0,1.5)+ 424 | theme_hc() 425 | 426 | 427 | 428 | 429 | 430 | ggplot(agg.df[agg.df$type!="iSI",],aes(variable,value,color=type,group=type))+ 431 | geom_line(size=3)+geom_line(linetype="dashed")+ 432 | #geom_ribbon(aes(ymin=,ymax=1))+ 433 | ylim(0,1.5)+ 434 | theme_hc() 435 | 436 | 437 | help(geom_ribbon) 438 | 439 | 440 | 441 | huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron)) 442 | -------------------------------------------------------------------------------- /CC-BY-4.0: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public 379 | licenses. Notwithstanding, Creative Commons may elect to apply one of 380 | its public licenses to material it publishes and in those instances 381 | will be considered the “Licensor.” The text of the Creative Commons 382 | public licenses is dedicated to the public domain under the CC0 Public 383 | Domain Dedication. Except for the limited purpose of indicating that 384 | material is shared under a Creative Commons public license or as 385 | otherwise permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the 393 | public licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. 396 | -------------------------------------------------------------------------------- /GeneratedData/Traits_Spectra_car_PlotSel.csv: -------------------------------------------------------------------------------- 1 | "";"B2";"B3";"B4";"B5";"B6";"B7";"B8A";"B11";"B12";"cab";"cw";"cm";"lai";"car" 2 | "1391";0,024946797876566;0,0652848016719082;0,0208947945077811;0,106904366374172;0,402151777697204;0,492802748997241;0,494515800313359;0,224220550412586;0,0665573554137009;30,3451962807613;0,00953346484660072;0,00986778350403873;6,11891291587137;11,2490469133216 3 | "1624";0,0221860916154674;0,0272954770126319;0,0191322618679647;0,0392044346836061;0,319061143436713;0,532115599783167;0,536260978642749;0,33220905959434;0,127024355643506;86,1648084681074;0,00285414074070744;0,00828145768224295;7,90919024786475;39,0411346963172 4 | "611";0,0219948570403682;0,0327082903017845;0,0190052103651736;0,051808813116925;0,356700406891072;0,544110490646707;0,546929990358511;0,245065823557684;0,0795469619943941;65,2389068427813;0,00972093059935576;0,00726210150103487;7,07854324853471;34,7813959480109 5 | "499";0,0225816231711662;0,0488460157647701;0,0203710529401156;0,0894091052281789;0,456653705725971;0,645919384217995;0,650921353806084;0,401711371695463;0,188228794016482;40,0580292750395;0,00353256810789174;0,00380957809161418;9,35935433083617;46,3862035667978 6 | "151";0,0392528257673806;0,0702647496333607;0,040115416765651;0,103779774584522;0,225344237157419;0,249488443189341;0,257782976096559;0,211190102603747;0,121386593131596;28,0832448636172;0,00770596810432541;0,00590121860749938;0,654022981337821;5,77641663577755 7 | "1256";0,0212248285033933;0,0686000310396678;0,0225794588797256;0,128030054314806;0,416993103169968;0,491188961035616;0,493800360064883;0,283416167475871;0,0999424180831225;24,3889499996676;0,0049419744722451;0,00868436512937555;4,65549581275622;37,6330433616792 8 | "890";0,0218828302687385;0,0235063978764231;0,0188799326400167;0,0298463270590626;0,282653284095879;0,531586621152346;0,536385158745485;0,332701586664782;0,128523057965003;114,779401696544;0,00298875002784972;0,00794049780242;7,03225856606942;45,6492920513688 9 | "1646";0,0223654444749257;0,0233702103050228;0,0192753376483495;0,0283145081638451;0,282828070058697;0,582713872516107;0,58779364111054;0,272163483283723;0,0961120255557811;126,223210172439;0,00876065336492804;0,00587516110818777;8,5960680684589;38,8866403739126 10 | "837";0,0209309484223179;0,0224095378115325;0,0179349494886186;0,0276031161756706;0,266793453625719;0,474659683218427;0,479725538985557;0,249191714370137;0,0922153190961373;120,698433627839;0,00999959176171933;0,00471433863661032;2,75938821189268;20,0873517247479 11 | "563";0,0209134107855902;0,0219014303111441;0,0179134661006873;0,0262360278421199;0,261527202402709;0,483119690117925;0,489031555751017;0,336085597266926;0,158125164117963;128,650196067261;0,00397965748865464;0,0044607550729416;2,83673463358755;19,8802435910155 12 | "771";0,0224710404390123;0,0272070084554966;0,0190952303888668;0,0376351093749148;0,350980931050866;0,680027019167479;0,686326089042357;0,310961817969344;0,128598163134445;91,7583868649563;0,00903777926639739;0,00209450909737172;7,7963814976709;21,9421940221639 13 | "1437";0,0219373636760708;0,0324898099579834;0,0188884564161389;0,0505809973790377;0,339517715832274;0,504991105702592;0,5074979139549;0,235447747874789;0,0723905618498244;65,7870765174414;0,00889758104148193;0,00933902638720109;6,66091371925056;30,2168334021249 14 | "713";0,0207275205684719;0,023050969991709;0,0179390864914473;0,0311831036620628;0,278896864618814;0,467899012513367;0,472374775435693;0,311224434485948;0,121831508402109;103,588120878333;0,00303325117461246;0,00816556951281861;3,51608126287969;59,0736574331111 15 | "524";0,0221722358023645;0,0257131223176122;0,019144636107823;0,0360160682853522;0,338711334647789;0,656374496168356;0,66227097060296;0,303385872344275;0,121346458778095;95,9507563058798;0,00886718507237349;0,00292161846138231;8,01086730364476;48,8720279385511 16 | "1844";0,0267740700850931;0,0613939638837361;0,0202132084222456;0,0995304788591141;0,44577454874983;0,583877400173823;0,586789085454195;0,279728248460304;0,102855985659135;34,4379378393286;0,00859261779559538;0,00494764849866399;6,33000392965509;8,4278089133262 17 | "1887";0,0210421420622557;0,0647471672962797;0,0213622355416779;0,122311720722;0,456119621331107;0,556494089611356;0,560116692617412;0,311850815778154;0,130250533836415;27,0500814636093;0,006900672836154;0,00369895076281032;4,12373974735005;37,9316511502123 18 | "1985";0,0209473069058199;0,0237670450138532;0,0181074122432754;0,0329243529266694;0,291821292999767;0,492657569097352;0,497129448671305;0,334356507820268;0,134527467753349;98,5635635994659;0,00232276815454672;0,00784671656187457;4,21918363699688;59,2826704200293 19 | "1808";0,0219377766343361;0,0983508584768018;0,0377481520566555;0,200020106020014;0,461707492670962;0,512456579331775;0,514592439821992;0,292316345972318;0,102188458446658;13,4319150418391;0,00438015023563493;0,00925155971378697;7,24313803549641;59,0668955400766 20 | "1715";0,0210402939167041;0,0575275814406335;0,0217578806963901;0,112933886328196;0,379554905377374;0,444812705082754;0,450383353788089;0,323265176836174;0,17595980574245;28,7357251115908;0,00521159645535752;0,00204772912655177;1,96905640161789;62,154304525052 21 | "407";0,0211422493634448;0,0391548067112473;0,0185369752818895;0,0670874026852684;0,3770356764705;0,516134224976309;0,520054172150709;0,357365329898811;0,152899357967736;49,5308066939595;0,00218589301367089;0,00670198469490185;4,44320290415879;36,0512569193739 22 | "1195";0,02297762444227;0,0389386936697018;0,0197551779481015;0,0628772615606385;0,392935416777461;0,58897843781793;0,592399233642866;0,286594978420713;0,104225868696687;55,9671623581081;0,00775881622216954;0,00594448952756177;9,62059477104937;25,534177181793 23 | "1658";0,021499385905274;0,0488030123136301;0,019272742148169;0,0848960236909586;0,393361206396098;0,508557455527172;0,511453207069984;0,286916629585527;0,102734826986692;39,0753707236502;0,00538425586344976;0,00795570459238189;5,03382424273261;29,3129159498911 24 | "1512";0,023554438212906;0,0601686977973488;0,0206659463170795;0,101374947970471;0,441461630837577;0,57604220773417;0,578993697883265;0,297364546783564;0,110976353392138;33,9559187927152;0,0067129889639337;0,00602190333440911;7,71410919681559;16,6103581908479 25 | "57";0,0217051860524587;0,0265475167890707;0,0185305212966707;0,0368829618935921;0,306095904685323;0,50522057247617;0,509014557228243;0,299913311199376;0,108197353981074;89,0261073813132;0,0040339207134368;0,00873249236285328;5,67824133108766;24,7148121541137 26 | "1401";0,0220950321379695;0,0425347108126398;0,0190533562021236;0,0701478028565591;0,381075674975326;0,523191129325658;0,526098510243687;0,281965706187259;0,099083843524899;47,9444640208668;0,00596780021663367;0,00794190773715339;6,07549428543221;22,9218707110239 27 | "1082";0,0244918345207184;0,0284594194439509;0,0243554339984292;0,038138674156011;0,214230838952294;0,305003109744797;0,311611055567545;0,23903200370958;0,109452828735029;103,714615540988;0,00359973268726339;0,0099996529020618;1,16985139399064;27,854573033443 28 | "803";0,0222695634278442;0,0361392874453857;0,0190085849874748;0,0572547844144157;0,374356854761086;0,560267358861061;0,564572000966349;0,378854899889473;0,163100292498821;59,4046519091091;0,0020404149600407;0,00642257884552021;6,85837987378206;23,1179753771925 29 | "5";0,0267226329941984;0,0392634642865841;0,0242000157528351;0,0586599134335144;0,272427593446045;0,349770219576698;0,356822335906572;0,265022219211517;0,146392824279186;61,2622307200075;0,00684034413448378;0,00242573103329526;1,19778149702834;9,45677236860348 30 | "923";0,0214603719325261;0,0306005715056243;0,0185895773565166;0,0491524061068965;0,373907475981605;0,601655307864843;0,605808161507781;0,282692575271158;0,107768737713378;68,6808430641265;0,00937238038249732;0,00355621354807567;5,64415322115777;45,1099085932247 31 | "1549";0,0210723780718038;0,0361186946184226;0,0185049465592682;0,0646337010856371;0,393838339503786;0,560882644224007;0,565236719391569;0,350678698797308;0,155491655848331;52,1884889239225;0,00450093692738677;0,0042823035156024;4,58026172730678;60,0018448947528 32 | "932";0,0290742650782531;0,0863709393597116;0,0454279194893713;0,14851836792455;0,265699985340826;0,284366499650063;0,292113586590478;0,217676725964086;0,119810599046868;15,1938270636687;0,009918124054781;0,00329980402726196;0,803370293634297;39,7324623559206 33 | "1093";0,0222028371337042;0,025285852868134;0,0191356511069388;0,0341912386868784;0,330580127255084;0,657335911417166;0,663879801780227;0,33014204632734;0,139780857853547;101,343033600646;0,00731742978705063;0,00289497641469173;7,99414649127948;39,2006073034708 34 | "255";0,0216950382449956;0,0231623876258438;0,0185952322782072;0,0284153880955518;0,26823431973611;0,497554817419925;0,501634355029847;0,284469682199722;0,0980729836088918;119,350088509258;0,00458572160955784;0,00941502934950169;5,98745950895585;26,6879263652469 35 | "904";0,0232076224091069;0,0990862355953341;0,0291750374876809;0,175537114538046;0,486555300613333;0,556412301100944;0,55963664502058;0,303852395624038;0,123114579505276;17,1853657487005;0,00718774686439136;0,00404124841924912;4,29181763673745;15,5514870490558 36 | "1055";0,0316295441605699;0,0364294470092202;0,0361762384872636;0,0488221337473104;0,186335383545325;0,254884986822912;0,263458365233098;0,212714681998342;0,122136149001205;109,669838314803;0,00819090372151459;0,00516581279056114;0,67355035078197;40,4446897861677 37 | "1632";0,0323979045131911;0,0368082591041613;0,0366588380987865;0,048260675055947;0,185330130045977;0,257904457896383;0,266825816574278;0,24500056616444;0,162963528416234;115,958764698426;0,00377184432358643;0,00360702441556771;0,66070449607348;16,6447074396341 38 | "1295";0,0222671572929506;0,102132090605295;0,0396454094044998;0,208248721146919;0,478944226119585;0,532784332217039;0,534269444226689;0,242973633302627;0,0769039493663293;12,9970560227491;0,0092147293584006;0,00839510454462594;8,3534082870244;58,3218590983372 39 | "96";0,0239519572058797;0,0634584475314131;0,0208548766430979;0,106675753071095;0,453227729983419;0,587317184786096;0,590989801817672;0,355746346576008;0,150650590779085;32,1661548028611;0,00396792484765269;0,00533425397903624;7,19810012426204;14,584388219006 40 | "624";0,0244982208673933;0,0252328603998029;0,0188296425379225;0,0316089740415227;0,310899147935225;0,612293385723086;0,617730728012219;0,293102640193163;0,112861260684065;108,379517452943;0,0085379886723241;0,00395475702613333;6,83255545069987;5,01523056272143 41 | "868";0,0219992079804929;0,0483468988097466;0,019476511306768;0,0831813016022852;0,415861372068699;0,561026260768507;0,563766053007596;0,26475684703933;0,092317587991411;41,086913886087;0,00889124716513217;0,00599483619322054;6,27988415016113;26,7606496036172 42 | "166";0,0218193140054503;0,0233950534320705;0,0188463145773075;0,0304005704333311;0,30631625397073;0,622529339144222;0,628309390413381;0,294664856316247;0,114609214518592;113,552204429506;0,00874347887441026;0,00358448382652227;6,90353309685003;61,5651870205892 43 | "118";0,0257334454404891;0,030678240492854;0,0192080544977784;0,0424898467271149;0,340807165489419;0,571310894001814;0,575018456335502;0,269358875853698;0,0939080105446195;80,3340175889389;0,00856369728671499;0,00631540624708009;8,15615509717688;5,92069267694238 44 | "1829";0,0221397895454899;0,0771814659221075;0,0248428975369883;0,14498102800242;0,470037590092829;0,563716234057632;0,566140939810795;0,283725009926813;0,102071229266225;22,2553938827338;0,00722793129437627;0,00649299762454513;7,41363881418698;36,1625561947384 45 | "370";0,0223268355946131;0,0259661150689451;0,0179443410498872;0,0350017563832053;0,32223689800874;0,551380953110285;0,557384288251828;0,381034615796718;0,198613027389078;93,4930274431385;0,00410312941608409;0,00234191194416645;3,49168265665934;9,9003802034294 46 | "142";0,0208062176764901;0,0345810001670715;0,0186710277099339;0,0591868886247829;0,307648900669224;0,398264811631909;0,402533047261811;0,245339711821314;0,0889829434215364;54,4749862757955;0,00631629284087705;0,00901134158313194;2,19931593866096;50,7367313122292 47 | "199";0,0289855070957133;0,090864757508728;0,0377008941442083;0,14527646387857;0,28746229901279;0,310391606581996;0,317450262338603;0,276121312920298;0,162732714604199;17,0215283991889;0,00222605346377405;0,00546319191725038;1,03262559522563;12,7584207484236 48 | "1330";0,0208480941571012;0,0220371329409643;0,0180160191796749;0,0278165004512471;0,287358690368776;0,556486368009965;0,562488773206298;0,334609777094756;0,150339340021738;120,507315160411;0,00596559938146404;0,00312231438320396;3,90801037442895;55,4975323996233 49 | "489";0,0238409742257636;0,0257320893444971;0,0227724892091901;0,0320068027615057;0,211589894028515;0,329729722568111;0,336362183754933;0,245726265625239;0,112510363693324;127,103155287619;0,0050402766081895;0,0078914865659851;1,29753513046771;16,4833614889318 50 | "905";0,0227316710184958;0,0245389328188974;0,0193983098180286;0,0304953262586613;0,297381263198443;0,593797448719254;0,598625630203022;0,264821039548253;0,092331302474666;115,999248598389;0,009697366203823;0,0055308609823986;9,09239091431263;22,6655549915555 51 | "1124";0,0206820397351596;0,0685134624112873;0,0228158941117154;0,130392667201468;0,393308934133319;0,451791790666627;0,455143369749497;0,26269345466745;0,0951190856759928;23,3731975803719;0,006581063973398;0,00762918086633592;2,93431257974274;43,2016790877504 52 | "1755";0,0225377773935167;0,0626026889788489;0,0223416526824553;0,12312114797799;0,505989412787031;0,668582335241844;0,673171274999603;0,375166562960636;0,171332908450611;28,6854763832066;0,00516147061429431;0,00307559514106668;9,32330497688447;57,9337989277047 53 | "415";0,0219324229719225;0,048945483580538;0,0216540475937731;0,0873710214526313;0,311433276403101;0,368587516292726;0,374011366283728;0,261312553165999;0,115968058186755;36,7604707568761;0,00525557120217271;0,00689138188795652;1,60851666524516;43,7390465841779 54 | "421";0,0239261873729485;0,0253283575430943;0,0220436627336121;0,0313217016733486;0,226983055361061;0,366851244119005;0,37411035290538;0,295262455156495;0,1682647777903;127,885001750984;0,00421934433468799;0,00327014598793278;1,37036411116205;10,2830016157762 55 | "30";0,0216267935646765;0,0338072746713954;0,0187866328444678;0,0555471037840174;0,358346030675582;0,525135172601956;0,52846457591164;0,296855917520612;0,107856213067126;60,1740947388534;0,00503733154565343;0,00782864567745422;6,08317631492182;41,2602467799704 56 | "358";0,0225689567176258;0,0711565730385506;0,0217650983558273;0,121297589333436;0,397972341086218;0,466860739476639;0,469113951260854;0,222184660393784;0,0676077370918951;25,5921284214247;0,00979829808587768;0,0090909226247536;3,85510438748464;16,0489651364131 57 | "1421";0,0228890622169836;0,0973303629418653;0,0330725605268349;0,184847619527187;0,47521137095821;0,541350030951956;0,543331959125864;0,277194396225933;0,0948124769186229;15,9894690555892;0,0065692237464377;0,0083482054357986;10,0708554707912;36,9348681745333 58 | "1043";0,0212217280565648;0,0269179113914198;0,0189311950367914;0,0390437867726769;0,289305917829909;0,43038309461245;0,436093291195184;0,264904203354052;0,116838861103744;85,8314835910517;0,00866783100674701;0,00327135112814913;1,95632737131196;30,1292418957066 59 | "264";0,022964128370792;0,0236419681934819;0,0188248597120023;0,0282141839404208;0,271515906504007;0,521078048579733;0,525346092314856;0,276399182314996;0,094918086151444;122,473047331855;0,00613244752879357;0,00840624487123943;6,83329773294296;9,5661022453232 60 | "1688";0,0214590043136672;0,0235473078513186;0,0185353570709011;0,0314019814477651;0,303829461371588;0,57387276137085;0,578919491968053;0,301744973285992;0,117087896187656;107,160020782024;0,00701228168445704;0,00491114219457562;5,75562704834437;58,3271645937565 61 | "753";0,0224622374502143;0,0231285330656675;0,0184129393684632;0,0275995615954363;0,265394774538272;0,498060546919668;0,502193019989716;0,273704117743424;0,093454569193874;122,629064793055;0,00569406103802358;0,00885587645573519;5,3420536822163;9,5779967792307 62 | "1193";0,0220761714311893;0,0466752844022259;0,0194142355403056;0,0802837718704834;0,437033324600357;0,61786792594898;0,621890598886568;0,325272595217236;0,135057288803323;43,436795481183;0,00675718145146434;0,00367970424165023;6,58367633647772;27,0929200560946 63 | "482";0,021964566072601;0,0445909642868876;0,0187933969558287;0,0732391539913533;0,357946252547344;0,457917133079305;0,462826154343497;0,295005166791776;0,133463311160094;45,4280778043028;0,00647237446908758;0,00377674417853477;2,33162862104091;16,4083737874739 64 | "830";0,0276242684945655;0,0630033501842932;0,0317149169458348;0,102400773658941;0,255925487275011;0,286931342823888;0,294002552902498;0,214239251300766;0,104782167782535;29,2566946700114;0,00816752069282185;0,00721654801415334;0,924669383111759;24,1851851360999 65 | "1827";0,0216882134726501;0,0233640853325913;0,0186878647218264;0,0295500838477617;0,293951779674653;0,57995789771422;0,58592075620553;0,366864204472345;0,160184761592645;115,85592579466;0,00354119809817318;0,00508110150075373;6,31946002104263;38,5494536009651 66 | "1849";0,0224232311417096;0,0566367049721285;0,0197907006837457;0,0975008277617952;0,472395687276129;0,637127915000347;0,642457937846593;0,446618753461652;0,245192585374319;35,7345714662313;0,00295748157377846;0,00201095527472469;5,44336179676274;18,8741106825668 67 | "1133";0,0221092235537881;0,0231814488077181;0,0187907626029584;0,0277696356025578;0,280627955797054;0,572319947485201;0,577448888692905;0,281643306658484;0,10264204897678;125,690902306755;0,00797885966941264;0,00561381368202694;6,7084197961661;19,3434138164533 68 | "589";0,0208569161874182;0,0819484265429445;0,0283740930078214;0,162701210015364;0,417001129436057;0,466836770028553;0,469459552989141;0,270858530374738;0,0935433342134276;17,3905029850813;0,00520408370865204;0,00918006967403121;3,86685853031362;53,5876301483696 69 | "1672";0,0238090218842537;0,0278265625764186;0,0231273567179288;0,0376069055451444;0,241264524831072;0,358170266008038;0,365202439471636;0,240893527125949;0,118323643734196;103,300358964638;0,00980642949856473;0,00252313216569528;1,26694436547604;25,2233989062369 70 | "378";0,0222659328563604;0,0229535739604222;0,0184691577437482;0,027253041226138;0,275158788037107;0,548147650029245;0,552995190033284;0,276517254447112;0,0995598009597415;126,059158967262;0,00782703197061495;0,00600278994530296;5,542857047753;11,4416559412636 71 | "1780";0,0222644038507368;0,0242967543729202;0,0191788505672992;0,0312312640983829;0,313188600552332;0,648091694286316;0,655753511026072;0,408151885360484;0,196368247199784;112,180929582667;0,00360087475920702;0,00330459210946475;8,1902642962894;37,4446074058416 72 | "642";0,0326744948573172;0,0368058463388627;0,0378347032535687;0,0480095860772754;0,170027260062364;0,234118004415674;0,242530236341346;0,188717024475817;0,100445424402839;123,235681706231;0,00962964945570467;0,00971723194268058;0,630907576648248;36,5871953112676 73 | "457";0,025214289560379;0,0301727534781868;0,0242256254468539;0,0410555856711849;0,225950923031571;0,314586226409253;0,32105704163247;0,210929275775194;0,0896150492339248;93,4619600744078;0,0090100955060025;0,00824287672565859;1,1803954795768;13,4712070475763 74 | "1923";0,022904321224298;0,0588479823682688;0,0220685440524534;0,0989995682110516;0,335448249434717;0,393293527663202;0,399109361605547;0,309279362351123;0,165966538667542;32,5217501262933;0,00350327884250597;0,00422882372459635;1,65537005096228;18,4103309274034 75 | "881";0,0212746923055373;0,024679730868967;0,0183329541949779;0,0339215007276486;0,322104137140077;0,589371312609288;0,594751027209482;0,318173019188654;0,132932679747648;98,0331859511151;0,00706308255688566;0,00340519292569899;5,01903320626878;38,3095055687628 76 | "1461";0,0227617199420157;0,0235549639345941;0,0196384685352653;0,0283503267639623;0,284235047978634;0,59891025303754;0,605001819517874;0,318916918020006;0,124710602438622;128,995511366384;0,00602783070494329;0,00556683815065974;10,1315943791477;45,8016772472944 77 | "1620";0,0219189484432565;0,0705797291426465;0,024011977404216;0,143177077080595;0,516657515997077;0,646072922048965;0,649961987586225;0,349039999810698;0,153444312026226;23,5791422152229;0,00615171061127657;0,00301989686409747;7,20138714916192;61,9861042891775 78 | "1576";0,0225756011631965;0,0973489627240571;0,0354699949826474;0,203862168349118;0,551759733048214;0,64468014894294;0,647381056389761;0,298771619133508;0,115825400182102;14,9458580713762;0,00859318935696548;0,00385585706697989;9,49301948934287;64,6050888867191 79 | "764";0,0225333694674306;0,0395152320009063;0,0198001525136384;0,0697066146393129;0,409904093186497;0,601806909313095;0,6062163366427;0,368206676317595;0,157932749815965;50,6683742343864;0,00358725398199119;0,00539491269652155;9,28774007226368;53,2983916402157 80 | "1776";0,0207335342002058;0,0576931985904653;0,0203064017296598;0,108001490316905;0,409583380810706;0,494103156670428;0,499320226095827;0,370562253144097;0,209328256672248;30,7118178267742;0,0036657936878225;0,00212356859742954;2,53491232939837;39,1786499540219 81 | "20";0,035193936341334;0,0402755940120631;0,041867478135158;0,0533249663263912;0,17323530243143;0,233995757244585;0,24320200359148;0,205182602349585;0,126966790041156;115,271469937865;0,00923240655548225;0,0039848979878405;0,540711769654776;33,6870280706395 82 | "94";0,0313483042099178;0,037337575804747;0,0355136745306671;0,0509325917827612;0,190753622431019;0,252713074623226;0,260984506404936;0,200523542455291;0,107928944225462;96,6755916983464;0,00958637401326611;0,00679859666660818;0,692040038987275;28,40414444662 83 | "694";0,0222442772053477;0,0360325669990336;0,0192978844177878;0,0596460091536699;0,412271911204038;0,661248929352315;0,666128538908012;0,318943446622169;0,132291167379264;58,9134777706503;0,00802433912055226;0,00278511003063694;7,9322915833923;36,1282030320063 84 | "1630";0,0220742703390344;0,0245909724066746;0,0190598143136059;0,0330959850077519;0,317532761808135;0,616970173114768;0,622603408319115;0,312197887837223;0,124277102013915;104,142700477889;0,00724216997858214;0,00420880585815568;7,70368353834975;51,612517738512 85 | "299";0,0218465441986307;0,0227703853654702;0,0187966503780881;0,0272076974054415;0,260130223394387;0,498160938707806;0,501763535009006;0,235561565592962;0,0720101677493523;127,723258171799;0,00857337547543655;0,00974285666759573;6,7319133848087;32,9156144729508 86 | "227";0,0349960383376917;0,0413955881627741;0,0417279100016011;0,0572546452647534;0,176473831442064;0,225751541145299;0,234792660518339;0,224634036134931;0,144035996435501;93,1860814429257;0,00233077097853245;0,00748405588302713;0,544199494356684;59,2751172723795 87 | "1975";0,0260932920524437;0,103923273583046;0,0537765671926626;0,183337961108238;0,298041473296663;0,314350803586836;0,321564990906066;0,280695802409219;0,173863484115583;10,5792736141818;0,00272855774697707;0,00407303608180078;1,01216240051283;36,5572285375995 88 | "792";0,0239952254321799;0,0463726362901137;0,0249373333256171;0,0814680157587656;0,271213106504621;0,318475454142312;0,324603476652314;0,221713040202371;0,0965081441033598;39,8333897171499;0,00752169025215183;0,00821498991890607;1,20914811591604;57,4232399678038 89 | "1747";0,0218178042673176;0,0705655679146962;0,0241061825015813;0,138075047544495;0,443348002444069;0,526724816541444;0,529298539434289;0,306820557539708;0,112536333791115;22,983424813376;0,00421652930180889;0,00821273793220342;6,82038111469071;54,1583051101768 90 | "164";0,0209528818479642;0,0223517965925918;0,0181072745442105;0,0288769740732884;0,281541585279211;0,518452951549121;0,522916265590501;0,26502005738892;0,0941537039888813;114,832261437364;0,00831228778047467;0,0060835054090772;4,25263901761672;64,9986771068434 91 | "17";0,0222376115016418;0,113366556020573;0,0419904312089495;0,227664454724189;0,559916796706667;0,637027621795462;0,640405351508603;0,349350005930799;0,15104003320839;12,4464260902794;0,0056948275372955;0,00367753715777191;7,91440547177525;40,811893321154 92 | "862";0,0222995269705345;0,0243175077767962;0,0207786878312156;0,0306904867232409;0,226048661971909;0,357152395311338;0,363205187088696;0,233067373977892;0,095612543648911;121,719942214604;0,00775453254589147;0,00733018265898307;1,53039394974606;28,1372077758256 93 | "1468";0,0208186116462355;0,0542091980957742;0,0196095065789069;0,0981933438092968;0,397952353528014;0,487387490651014;0,491688114211842;0,277269751665263;0,11535758206298;33,7705700103354;0,0085988933898387;0,00334212464651513;2,66797127035518;32,4521784843391 94 | "1816";0,0262573534292048;0,0305519217966609;0,0197331253734985;0,0416394645429328;0,333277201991023;0,559195704878379;0,563558744191778;0,332729467808803;0,128765804466589;83,536763533688;0,00375707039719111;0,00745401414801383;10,3971129498718;5,85913676688488 95 | "756";0,0217028501200471;0,0233353087669392;0,0187035827150633;0,0294468574481806;0,289495639533365;0,563573461689056;0,569211508566256;0,362609006023486;0,154293264085725;116,165253490068;0,00307363957981044;0,00590749922995626;6,37741703123091;39,211881481438 96 | "1790";0,0213597036006587;0,061883427395014;0,0216237822723842;0,122933098264748;0,479887579532888;0,601897488332043;0,606127027967085;0,39011542580046;0,186660087705271;27,4530523446095;0,00372650692530637;0,00343168521056574;5,41951575786619;58,1467557085934 97 | "260";0,0213144742375741;0,042450779641834;0,0187844776906164;0,0728027388018957;0,373595060821888;0,496038962308144;0,499041725424918;0,286526505289412;0,101961745990301;45,3498507418984;0,00493059496664604;0,00846354738338106;4,76344937745702;32,3826595308761 98 | "582";0,0242900182489518;0,0301156023006471;0,0239696749920473;0,0425848025861043;0,245984307960199;0,346872292680751;0,353974486492684;0,247184490801028;0,126712345482933;89,99521889248;0,00845561030057067;0,00289583845427891;1,20013641117128;27,2084531315964 99 | "1861";0,0218847400494424;0,0227181261251509;0,0179075937781723;0,0275842689725739;0,282084038808589;0,532137226147091;0,538117105769685;0,329760365625596;0,151037730842868;121,063070656167;0,00597045887782608;0,00302239481346294;3,35630298095496;9,44681280839022 100 | "246";0,0216350194337986;0,036126708590177;0,0186162887133859;0,0588230983863569;0,398131172613245;0,604165398526392;0,609078444655107;0,365626634365659;0,168198822657802;57,9232240396825;0,00490154347835152;0,0032147061908926;5,35720673807699;26,8169369372476 101 | "692";0,0256997055333169;0,122152322990237;0,0386697006772337;0,216561101830073;0,557853911037899;0,642207166751318;0,645433587367124;0,333202693238009;0,139730036086687;13,5320184167185;0,00660317289328714;0,00361716335669163;8,27438996548285;13,4792442325653 102 | -------------------------------------------------------------------------------- /Jupyter/Hyperparameter tunning/HyperParameter_RFR_RTM.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "HyperParameter_RFR_RTM.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "id": "4h63bK9iL2sg" 20 | }, 21 | "source": [ 22 | "Step 1: Import packages & stuff needed to generate the data for inversion" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "metadata": { 28 | "id": "2eGsrTISLu6k", 29 | "colab": { 30 | "base_uri": "https://localhost:8080/", 31 | "height": 128 32 | }, 33 | "outputId": "4fb9c7db-d452-4eaf-8b33-5157600641a8" 34 | }, 35 | "source": [ 36 | "from google.colab import drive\n", 37 | "drive.mount('/content/drive')\n", 38 | "#Perhaps this step can be skipped by saving directly to the workspace" 39 | ], 40 | "execution_count": null, 41 | "outputs": [ 42 | { 43 | "output_type": "stream", 44 | "text": [ 45 | "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n", 46 | "\n", 47 | "Enter your authorization code:\n", 48 | "··········\n", 49 | "Mounted at /content/drive\n" 50 | ], 51 | "name": "stdout" 52 | } 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "metadata": { 58 | "id": "9nuu-jvIMTcP", 59 | "colab": { 60 | "base_uri": "https://localhost:8080/", 61 | "height": 435 62 | }, 63 | "outputId": "57ccf3e6-eadf-4a9e-8648-a3f92b0bab94" 64 | }, 65 | "source": [ 66 | "#package instalation\n", 67 | "\n", 68 | "#Installing PROSAIL\n", 69 | "!pip install prosail\n", 70 | "\n", 71 | "#latin hypercube stuff\n", 72 | "#lets try to do a LHS\n", 73 | "!pip install lhsmdu\n", 74 | "\n", 75 | "#this package as a number of functions to deal with hyperspectral data\n", 76 | "#!pip install pysptools" 77 | ], 78 | "execution_count": null, 79 | "outputs": [ 80 | { 81 | "output_type": "stream", 82 | "text": [ 83 | "Collecting prosail\n", 84 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/b5/52/d0c15ab469e8c82bc76a6b6cd614efbc60e43d09d5bacaa349170d229e91/prosail-2.0.5-py3-none-any.whl (149kB)\n", 85 | "\r\u001b[K |██▏ | 10kB 13.4MB/s eta 0:00:01\r\u001b[K |████▍ | 20kB 1.8MB/s eta 0:00:01\r\u001b[K |██████▋ | 30kB 2.2MB/s eta 0:00:01\r\u001b[K |████████▊ | 40kB 2.6MB/s eta 0:00:01\r\u001b[K |███████████ | 51kB 2.0MB/s eta 0:00:01\r\u001b[K |█████████████▏ | 61kB 2.2MB/s eta 0:00:01\r\u001b[K |███████████████▍ | 71kB 2.4MB/s eta 0:00:01\r\u001b[K |█████████████████▌ | 81kB 2.7MB/s eta 0:00:01\r\u001b[K |███████████████████▊ | 92kB 2.9MB/s eta 0:00:01\r\u001b[K |██████████████████████ | 102kB 2.8MB/s eta 0:00:01\r\u001b[K |████████████████████████▏ | 112kB 2.8MB/s eta 0:00:01\r\u001b[K |██████████████████████████▎ | 122kB 2.8MB/s eta 0:00:01\r\u001b[K |████████████████████████████▌ | 133kB 2.8MB/s eta 0:00:01\r\u001b[K |██████████████████████████████▊ | 143kB 2.8MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 153kB 2.8MB/s \n", 86 | "\u001b[?25hRequirement already satisfied: numba in /usr/local/lib/python3.6/dist-packages (from prosail) (0.48.0)\n", 87 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from prosail) (1.18.4)\n", 88 | "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from prosail) (1.4.1)\n", 89 | "Requirement already satisfied: pytest in /usr/local/lib/python3.6/dist-packages (from prosail) (3.6.4)\n", 90 | "Requirement already satisfied: llvmlite<0.32.0,>=0.31.0dev0 in /usr/local/lib/python3.6/dist-packages (from numba->prosail) (0.31.0)\n", 91 | "Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from numba->prosail) (46.3.0)\n", 92 | "Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (1.12.0)\n", 93 | "Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (8.3.0)\n", 94 | "Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (1.8.1)\n", 95 | "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (19.3.0)\n", 96 | "Requirement already satisfied: atomicwrites>=1.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (1.4.0)\n", 97 | "Requirement already satisfied: pluggy<0.8,>=0.5 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (0.7.1)\n", 98 | "Installing collected packages: prosail\n", 99 | "Successfully installed prosail-2.0.5\n", 100 | "Collecting lhsmdu\n", 101 | " Downloading https://files.pythonhosted.org/packages/7b/f0/e714a4dae734bcd7228a09d74fff7dc5857dc3311cd72a3e07b09c85d088/lhsmdu-0.1-py3-none-any.whl\n", 102 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from lhsmdu) (1.18.4)\n", 103 | "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from lhsmdu) (1.4.1)\n", 104 | "Installing collected packages: lhsmdu\n", 105 | "Successfully installed lhsmdu-0.1\n" 106 | ], 107 | "name": "stdout" 108 | } 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "metadata": { 114 | "id": "eWA_vt4HOyop", 115 | "colab": { 116 | "base_uri": "https://localhost:8080/", 117 | "height": 181 118 | }, 119 | "outputId": "ec2cc6ff-1303-4d91-e4d6-59cd00593f6a" 120 | }, 121 | "source": [ 122 | "!pip install hyperopt " 123 | ], 124 | "execution_count": null, 125 | "outputs": [ 126 | { 127 | "output_type": "stream", 128 | "text": [ 129 | "Requirement already satisfied: hyperopt in /usr/local/lib/python3.6/dist-packages (0.1.2)\n", 130 | "Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from hyperopt) (1.12.0)\n", 131 | "Requirement already satisfied: networkx in /usr/local/lib/python3.6/dist-packages (from hyperopt) (2.4)\n", 132 | "Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from hyperopt) (4.41.1)\n", 133 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from hyperopt) (1.18.4)\n", 134 | "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from hyperopt) (1.4.1)\n", 135 | "Requirement already satisfied: pymongo in /usr/local/lib/python3.6/dist-packages (from hyperopt) (3.10.1)\n", 136 | "Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from hyperopt) (0.16.0)\n", 137 | "Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx->hyperopt) (4.4.2)\n" 138 | ], 139 | "name": "stdout" 140 | } 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": { 146 | "id": "DfOcve1fMYBo" 147 | }, 148 | "source": [ 149 | "Packages for RandomForest and other auxiliary stuff" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "metadata": { 155 | "id": "T7SW2mrcaKA0", 156 | "colab": { 157 | "base_uri": "https://localhost:8080/", 158 | "height": 34 159 | }, 160 | "outputId": "8e000731-17f7-42bb-ccae-b1c49db35132" 161 | }, 162 | "source": [ 163 | "\n", 164 | "import numpy as np\n", 165 | "for i in range(50, 1001, 50):\n", 166 | " print(i, end=', ')" 167 | ], 168 | "execution_count": null, 169 | "outputs": [ 170 | { 171 | "output_type": "stream", 172 | "text": [ 173 | "50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, " 174 | ], 175 | "name": "stdout" 176 | } 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "metadata": { 182 | "id": "OzNjF9ldMXTM" 183 | }, 184 | "source": [ 185 | "#the beutiful R like data frame\n", 186 | "import pandas as pd\n", 187 | "\n", 188 | "#the famous numpy \n", 189 | "import numpy as np\n", 190 | "\n", 191 | "#PROSPECT+SAIL Radiative transfer mode package\n", 192 | "import prosail\n", 193 | "\n", 194 | "#Sampling design package\n", 195 | "import lhsmdu\n", 196 | "\n", 197 | "#a few more stuff for random\n", 198 | "import random as rdm\n", 199 | "import math\n", 200 | "\n", 201 | "\n", 202 | "# import the regressor for random forests\n", 203 | "from sklearn.ensemble import RandomForestRegressor \n", 204 | "\n", 205 | "from sklearn import metrics" 206 | ], 207 | "execution_count": null, 208 | "outputs": [] 209 | }, 210 | { 211 | "cell_type": "markdown", 212 | "metadata": { 213 | "id": "PdxUW6drNjZc" 214 | }, 215 | "source": [ 216 | "Bunch of functions needed for generating data" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "metadata": { 222 | "id": "Hk-0MPrdNrGY" 223 | }, 224 | "source": [ 225 | "def custom_prosail(cab,cw,cm,lai):\n", 226 | " import prosail\n", 227 | " #default parameters\n", 228 | " n= 1.\n", 229 | " car=10.\n", 230 | " cbrown=0.01\n", 231 | " typelidf=1 #this is the default option\n", 232 | " lidfa = -1 #leaf angle distribution parameter a and b\n", 233 | " lidfb=-0.15\n", 234 | " hspot= 0.01 #hotspot parameters - got this from R package https://www.rdocumentation.org/packages/hsdar/versions/0.4.1/topics/PROSAIL\n", 235 | " #sun and viewing angle\n", 236 | " tts=30. #observation and solar position parameters\n", 237 | " tto=10. \n", 238 | " psi=0.\n", 239 | " #for now i put them by hand but they should be an input of a custom function\n", 240 | " #tts=sol_zen #solar zenith angle\n", 241 | " #tto=inc_zen #sensor zenith angle\n", 242 | " #psi=raa\n", 243 | " rho_out = prosail.run_prosail(n,\n", 244 | " cab,\n", 245 | " car,\n", 246 | " cbrown,\n", 247 | " cw,\n", 248 | " cm,\n", 249 | " lai,\n", 250 | " lidfa,\n", 251 | " hspot,\n", 252 | " tts,tto,psi,\n", 253 | " typelidf, lidfb,\n", 254 | " prospect_version=\"D\",\n", 255 | " factor='SDR', \n", 256 | " rsoil=.5, psoil=.5)\n", 257 | " return(rho_out)\n", 258 | "\n", 259 | "def Prosail2S2(path2csv,spectra_input):\n", 260 | " #importing pandas\n", 261 | " import pandas as pd\n", 262 | " import numpy\n", 263 | " import numpy as np\n", 264 | " #upload a S2_Response.csv from https://earth.esa.int/web/sentinel/user-guides/sentinel-2-msi/document-library/-/asset_publisher/Wk0TKajiISaR/content/sentinel-2a-spectral-responses\n", 265 | "\n", 266 | " s2_table = pd.read_csv(path2csv,sep=\";\",decimal=\",\") #check if this is proper, regarding the sep and dec\n", 267 | " #chekc which row you are actually extracting\n", 268 | "\n", 269 | " s2_table_sel = s2_table[s2_table['SR_WL'].between(400,2500)] #selects all values between 400 and 2500\n", 270 | " spectra_input_df = pd.DataFrame(data=spectra_input,columns=[\"rho\"],index=s2_table_sel.index) #transforms the input array into a pandas df with the column name rho and row.index = to the original input table\n", 271 | "\n", 272 | " \n", 273 | " rho_s2 = s2_table_sel.multiply(spectra_input_df['rho'],axis=\"index\") #calculates the numerator\n", 274 | " w_band_sum = s2_table_sel.sum(axis=0,skipna = True) #calculates the denominator\n", 275 | "\n", 276 | " output = (rho_s2.sum(axis=0)/w_band_sum).rename_axis(\"ID\").values #runs the weighted mean and converts the output to a numpy array\n", 277 | "\n", 278 | " return output[1:] #removes the first value because it represents the wavelength column\n", 279 | "\n", 280 | "#please LOAD THTE FILE NOW\n", 281 | "filepath=\"/content/drive/My Drive/S2_Response.csv\"\n", 282 | "#filepath=\"/content/S2_Responses_S2B.csv\"\n", 283 | "#filepath=\"/content/drive/My Drive/S2_Response.csv\"\n", 284 | "\n", 285 | "\n", 286 | "def Gen_spectra_data(traits):\n", 287 | " k = 1\n", 288 | " #pd_train_traits=traits\n", 289 | " #print(range(len(traits)))\n", 290 | " for i in range(len(traits)):\n", 291 | " #n_t = pd_train_traits[\"n\"][i]\n", 292 | " cab_t = traits[\"cab\"][i]\n", 293 | " #car_t = pd_train_traits[\"car\"][i]\n", 294 | " #cbrown_t = pd_train_traits[\"cbrown\"][i]\n", 295 | " cw_t = traits[\"cw\"][i]\n", 296 | " cm_t = traits[\"cm\"][i]\n", 297 | " lai_t = traits[\"lai\"][i]\n", 298 | "\n", 299 | " if k == 1:\n", 300 | " tr_rho_s = custom_prosail(cab_t,cw_t,cm_t,lai_t)\n", 301 | " tr_rho_s = Prosail2S2(filepath,tr_rho_s)\n", 302 | " #plt.plot ( x, tr_rho_s, ':', label=\"Training prosail\")\n", 303 | " #plt.legend(loc='best')\n", 304 | " \n", 305 | " if k > 1:\n", 306 | " tr_rho_t = custom_prosail(cab_t,cw_t,cm_t,lai_t)\n", 307 | " tr_rho_t = Prosail2S2(filepath,tr_rho_t)\n", 308 | " tr_rho_s = np.vstack((tr_rho_s,tr_rho_t))\n", 309 | " #plt.plot ( x, tr_rho_t, ':')\n", 310 | "\n", 311 | " k = k+1\n", 312 | "\n", 313 | "\n", 314 | " rho_samples=tr_rho_s\n", 315 | "\n", 316 | "\n", 317 | " return rho_samples\n", 318 | "\n", 319 | "\n", 320 | "\n", 321 | "\n", 322 | "#Function to store the outputs into a table\n", 323 | "column_names=[\"Model\",\n", 324 | " \"NSamples\",\n", 325 | " \"OutOfBag\",\n", 326 | " \"KFold_tr_samples\",\n", 327 | " \"KFold_vl_samples\",\n", 328 | " \"Variable\",\n", 329 | " \"Fold_nr\",\n", 330 | " \"ExplVar\",\n", 331 | " \"Max_err\",\n", 332 | " \"Mean_abs_Err\",\n", 333 | " \"Mean_sqr_err\",\n", 334 | " #\"Mean_sqr_lg_err\",\n", 335 | " \"Median_abs_err\",\n", 336 | " \"r2\",\n", 337 | " \"MAPE\",\n", 338 | " \"ModelName\"]\n", 339 | " #\"Mean_poiss_dev\",\n", 340 | " #\"Mean_gamma_dev\"]\n", 341 | " #\"Mean_tweed_dev\"]\n", 342 | "\n", 343 | "#mape is not existant in the package so we have to create it:\n", 344 | "#https://stats.stackexchange.com/questions/58391/mean-absolute-percentage-error-mape-in-scikit-learn\n", 345 | "#from sklearn.utils import check_array\n", 346 | "def mean_absolute_percentage_error(y_true, y_pred): \n", 347 | "\n", 348 | " ## Note: does not handle mix 1d representation\n", 349 | " #if _is_1d(y_true): \n", 350 | " # y_true, y_pred = _check_1d_array(y_true, y_pred)\n", 351 | "\n", 352 | " return np.mean(np.abs((y_true - y_pred) / y_true)) * 100\n", 353 | "\n", 354 | " #Here, the file is used for saving\n", 355 | " #creating a df to receive the data\n", 356 | "\n", 357 | "\n", 358 | "def calc_metrics(MDL,Samples,oob_samples,kf_tr,kf_vl,Variable,Fold,Ref,Pred,Modelname):\n", 359 | "\n", 360 | " out_list = {\"Model\":MDL,\n", 361 | " \"NSamples\":Samples,\n", 362 | " \"OutOfBag\":oob_samples,\n", 363 | " \"KFold_tr_samples\":kf_tr,\n", 364 | " \"KFold_vl_samples\":kf_vl,\n", 365 | " \"Variable\":Variable,\n", 366 | " \"Fold_nr\":Fold,\n", 367 | " \"ExplVar\": metrics.explained_variance_score(Ref, Pred),\n", 368 | " \"Max_err\": metrics.max_error(Ref, Pred),\n", 369 | " \"Mean_abs_Err\": metrics.mean_absolute_error(Ref, Pred),\n", 370 | " \"Mean_sqr_err\": metrics.mean_squared_error(Ref, Pred),\n", 371 | " \"Median_abs_err\" : metrics.median_absolute_error(Ref, Pred),\n", 372 | " \"r2\": metrics.r2_score(Ref, Pred),\n", 373 | " \"MAPE\": mean_absolute_percentage_error(Ref, Pred),\n", 374 | " \"ModelName\":Modelname}\n", 375 | "\n", 376 | "\n", 377 | " return out_list" 378 | ], 379 | "execution_count": null, 380 | "outputs": [] 381 | }, 382 | { 383 | "cell_type": "markdown", 384 | "metadata": { 385 | "id": "oFeTJUgbN2k8" 386 | }, 387 | "source": [ 388 | "Hyperparameter tuning section\n", 389 | "\n", 390 | "\n" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "metadata": { 396 | "id": "MbKvtfA0OumM" 397 | }, 398 | "source": [ 399 | "# define an objective function\n", 400 | "\n", 401 | "# These are a bunch of methods of te hyperopt package to generate the search space\n", 402 | "from hyperopt import hp\n", 403 | "\n", 404 | "# these are the minimizing function (fmin), Tree-parzen estimator method, an evaluation function, trial method and status indicators\n", 405 | "from hyperopt import fmin, tpe, space_eval, Trials, STATUS_OK, STATUS_FAIL\n", 406 | "from sklearn.model_selection import cross_val_score\n", 407 | "\n" 408 | ], 409 | "execution_count": null, 410 | "outputs": [] 411 | }, 412 | { 413 | "cell_type": "markdown", 414 | "metadata": { 415 | "id": "2FxnCB3_PY5B" 416 | }, 417 | "source": [ 418 | "Step 2: Generate the data that is going to be used for training\n", 419 | "\n", 420 | "\n" 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "metadata": { 426 | "id": "7K-075akPeZ6" 427 | }, 428 | "source": [ 429 | "#first the trait-space\n", 430 | "\n", 431 | "n_traits=4 #I will test on 4 varying traits: cab, car, cw,cm,lai\n", 432 | "\n", 433 | "#generating a LHS hypercube (it uses a 0 to 1 interval that can be used as a multiplier against the different traits)\n", 434 | "np.random.seed(0)\n", 435 | "\n", 436 | "\n", 437 | "#the values here are 1 less than the max so i can add a value later to it\n", 438 | "#max_n=1 \n", 439 | "max_cab=121. #add 1\n", 440 | "#max_car=44. #add 1\n", 441 | "#max_cbrown= 9.99 #add 0.01\n", 442 | "max_cw=0.008 #add 0.001 \n", 443 | "max_cm=0.008 #0.001\n", 444 | "max_lai = 9.9 #add 0.1\n", 445 | "\n", 446 | "min_cab = 10.\n", 447 | "min_cw = 0.002\n", 448 | "min_cm = 0.002\n", 449 | "min_lai = .5\n", 450 | "\n", 451 | "#set the number of samples used for the optimization\n", 452 | "n_samples = 2000\n" 453 | ], 454 | "execution_count": null, 455 | "outputs": [] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "metadata": { 460 | "id": "5D7pk_9TPyiX" 461 | }, 462 | "source": [ 463 | "#this is for the training dataset\n", 464 | "df_metrics = pd.DataFrame(columns=column_names)\n", 465 | "#this is for the out of bag\n", 466 | "df_metrics_valid = pd.DataFrame(columns=column_names)\n", 467 | "\n", 468 | "#a path to store the models \n", 469 | "#path2folder = \"/content/drive/My Drive/DSRP_Lunch_outputs/Models/\"\n", 470 | "path2folder = \"/content/drive/My Drive/RTM_Inversion/HyperParameterTunning/RandF/\"\n", 471 | "\n", 472 | "#generating trait space and data\n", 473 | "LHS_train = lhsmdu.createRandomStandardUniformMatrix(n_traits,n_samples)\n", 474 | "pd_trait = pd.DataFrame.transpose(pd.DataFrame(LHS_train))\n", 475 | "pd_trait.columns = [\"cab\",\"cw\",\"cm\",\"lai\"]\n", 476 | "\n", 477 | "pd_trait[\"cab\"]=pd_trait[\"cab\"]*max_cab+min_cab\n", 478 | "pd_trait[\"cw\"] =pd_trait[\"cw\"] *max_cw+min_cw\n", 479 | "pd_trait[\"cm\"] =pd_trait[\"cm\"] *max_cm+min_cw\n", 480 | "pd_trait[\"lai\"]=pd_trait[\"lai\"]*max_lai+min_lai\n", 481 | "\n", 482 | "#this is the same as above but on numpy format\n", 483 | "np_trait = pd_trait.iloc[:,:].values\n", 484 | "\n", 485 | "#now we first generate the date in hyperspectral, convolute it to S2 while iterating through the entire given trait space\n", 486 | "np_spect = Gen_spectra_data(pd_trait)[:,[1,2,3,4,5,6,8,11,12]]\n", 487 | "\n", 488 | "#now we remove 10% of the data for out-of-bag validation of the final model while the cross-validation happens within the hyperparemeter tunning\n", 489 | "index = list(range(len(np_spect)))\n", 490 | "index10 = rdm.sample(index,math.ceil(len(index)*.1))\n", 491 | "index90 = [x for x in index if x not in index10]\n", 492 | "\n", 493 | "#selecting the groups for training (tr) and validation (vl)\n", 494 | "tr_trait_df = np_trait[index90,]\n", 495 | "tr_spect_df = np_spect[index90,]\n", 496 | "\n", 497 | "vl_trait_df = np_trait[index10,]\n", 498 | "vl_spect_df = np_spect[index10,]\n", 499 | "\n" 500 | ], 501 | "execution_count": null, 502 | "outputs": [] 503 | }, 504 | { 505 | "cell_type": "markdown", 506 | "metadata": { 507 | "id": "qLbGumF3SaOF" 508 | }, 509 | "source": [ 510 | "Definining the optimization function and the search space\n", 511 | "\n", 512 | "---\n", 513 | "\n" 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "metadata": { 519 | "id": "28j686EqSZiL" 520 | }, 521 | "source": [ 522 | "#objective function\n", 523 | "\n", 524 | "#first we define the function\n", 525 | "N_FOLDS = 10\n", 526 | "MAX_EVALS = 200\n", 527 | "\n", 528 | "#here we can just fetch the data so we keep everything in one place\n", 529 | "train_labels = tr_trait_df = np_trait[index90,]\n", 530 | "train_features = tr_spect_df = np_spect[index90,]\n", 531 | "\n", 532 | "\n", 533 | "def objective(params, n_folds = N_FOLDS):\n", 534 | " \"\"\"Objective function for Random forest Hyperparameter Tuning\"\"\"\n", 535 | "\n", 536 | " # Perform n_fold cross validation with hyperparameters\n", 537 | " # Use early stopping and evaluate based on ROC AUC\n", 538 | " rf = RandomForestRegressor(**params, random_state = 42,bootstrap=True,oob_score=True)\n", 539 | "\n", 540 | " #clf = LogisticRegression(**params,random_state=0,verbose =0)\n", 541 | " scores = cross_val_score(rf, X=train_features, y=train_labels, cv=10, scoring='neg_mean_absolute_error') #thi is the simple Mean abs\n", 542 | "\n", 543 | " # Extract the best score\n", 544 | " best_score = np.mean(abs(scores)) #mean value\n", 545 | " # if the the result is miniming\n", 546 | "\n", 547 | " # Loss must be minimized\n", 548 | " #loss = 1 - best_score \n", 549 | " loss = best_score \n", 550 | "\n", 551 | " # Dictionary with information for evaluation\n", 552 | " return {'loss': loss, 'params': params, 'status': STATUS_OK}\n", 553 | "\n", 554 | "#distribution functions for the parameter sampling are here:\n", 555 | "#https://github.com/hyperopt/hyperopt/wiki/FMin\n", 556 | "\n", 557 | "space = {\n", 558 | " 'n_estimators': hp.choice('n_estimators', range(50, 1001, 50)), #to avoid errors (e.g. to few trees)\n", 559 | " 'min_samples_split' : hp.uniform('min_samples_split', 0,.5), #these must be a fractio up to 50% of the data it seems\n", 560 | " 'min_samples_leaf' : hp.uniform('min_samples_leaf', 0,.5)\n", 561 | "}\n", 562 | "\n", 563 | "# for i in range(50, 1001, 50):\n", 564 | "# print(i, end=', ')" 565 | ], 566 | "execution_count": null, 567 | "outputs": [] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "metadata": { 572 | "id": "TVIydEOQSsHW", 573 | "colab": { 574 | "base_uri": "https://localhost:8080/", 575 | "height": 34 576 | }, 577 | "outputId": "8125d52d-1595-429d-ea14-901e36fb10ed" 578 | }, 579 | "source": [ 580 | "#this loop is the actual testing\n", 581 | "bayes_trials = Trials()\n", 582 | "\n", 583 | "best_rfr = fmin(fn = objective, space = space, algo = tpe.suggest, max_evals = MAX_EVALS, trials = bayes_trials,verbose=1)" 584 | ], 585 | "execution_count": null, 586 | "outputs": [ 587 | { 588 | "output_type": "stream", 589 | "text": [ 590 | "100%|██████████| 200/200 [1:04:32<00:00, 19.36s/it, best loss: 0.31946225928160776]\n" 591 | ], 592 | "name": "stdout" 593 | } 594 | ] 595 | }, 596 | { 597 | "cell_type": "markdown", 598 | "metadata": { 599 | "id": "9bnbvVAdXLkj" 600 | }, 601 | "source": [ 602 | "Quick testing to check for improvements " 603 | ] 604 | }, 605 | { 606 | "cell_type": "code", 607 | "metadata": { 608 | "id": "Ce0C3dSvXKzO", 609 | "colab": { 610 | "base_uri": "https://localhost:8080/", 611 | "height": 52 612 | }, 613 | "outputId": "1906ea4e-eca1-48d7-d717-3d63363745fb" 614 | }, 615 | "source": [ 616 | "#beware, pointers effect is happening here\n", 617 | "print(best_rfr)\n", 618 | "#updating the dictionary\n", 619 | "#best_rfr_new = best_rfr\n", 620 | "#best_rfr_new.update(n_estimators=range(50, 1001, 50)[best_rfr['n_estimators']])\n", 621 | "print(range(50, 1001, 50)[15])\n", 622 | "#it updates the pointer so it can only be run once" 623 | ], 624 | "execution_count": null, 625 | "outputs": [ 626 | { 627 | "output_type": "stream", 628 | "text": [ 629 | "{'min_samples_leaf': 0.0007218586390063501, 'min_samples_split': 0.0006729906646919075, 'n_estimators': 17}\n", 630 | "800\n" 631 | ], 632 | "name": "stdout" 633 | } 634 | ] 635 | }, 636 | { 637 | "cell_type": "markdown", 638 | "metadata": { 639 | "id": "kEMnUQywo9I0" 640 | }, 641 | "source": [ 642 | "Run 01:\n", 643 | "\n", 644 | "\n", 645 | "{'min_samples_leaf': 0.0007027343011890524, 'min_samples_split': 0.004091222247067641, 'n_estimators': 800} \n", 646 | "\n", 647 | "run 02\n", 648 | "\n", 649 | "{'min_samples_leaf': 0.0014275823590012802, 'min_samples_split': 0.0014118318943800098, 'n_estimators': 400}\n", 650 | "\n", 651 | "\n", 652 | "run 03\n", 653 | "{'min_samples_leaf': 0.0007218586390063501, 'min_samples_split': 0.0006729906646919075, 'n_estimators': 17}\n", 654 | "900\n", 655 | "\n" 656 | ] 657 | } 658 | ] 659 | } -------------------------------------------------------------------------------- /Jupyter/Hyperparameter tunning/HyperParameter_GPR_RTM.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "HyperParameter_GPR_RTM.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | } 13 | }, 14 | "cells": [ 15 | { 16 | "cell_type": "markdown", 17 | "metadata": { 18 | "id": "zVlg9bx3PNlC" 19 | }, 20 | "source": [ 21 | "\n", 22 | "Step 1: Import packages & stuff needed to generate the data for inversion" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "metadata": { 28 | "id": "Yvn2K9tbEgd-", 29 | "colab": { 30 | "base_uri": "https://localhost:8080/", 31 | "height": 125 32 | }, 33 | "outputId": "620726d5-4051-4538-a16f-d9e040118edb" 34 | }, 35 | "source": [ 36 | "from google.colab import drive\n", 37 | "drive.mount('/content/drive')\n", 38 | "#Perhaps this step can be skipped by saving directly to the workspace" 39 | ], 40 | "execution_count": null, 41 | "outputs": [ 42 | { 43 | "output_type": "stream", 44 | "text": [ 45 | "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n", 46 | "\n", 47 | "Enter your authorization code:\n", 48 | "··········\n", 49 | "Mounted at /content/drive\n" 50 | ], 51 | "name": "stdout" 52 | } 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "metadata": { 58 | "id": "z7Kj7sUNPL3G", 59 | "colab": { 60 | "base_uri": "https://localhost:8080/", 61 | "height": 425 62 | }, 63 | "outputId": "169efe5c-554c-47e0-d89c-df5c0fec0295" 64 | }, 65 | "source": [ 66 | "#package instalation\n", 67 | "\n", 68 | "#Installing PROSAIL\n", 69 | "!pip install prosail\n", 70 | "\n", 71 | "#latin hypercube stuff\n", 72 | "#lets try to do a LHS\n", 73 | "!pip install lhsmdu\n", 74 | "\n", 75 | "#this package as a number of functions to deal with hyperspectral data\n", 76 | "#!pip install pysptools" 77 | ], 78 | "execution_count": null, 79 | "outputs": [ 80 | { 81 | "output_type": "stream", 82 | "text": [ 83 | "Collecting prosail\n", 84 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/b5/52/d0c15ab469e8c82bc76a6b6cd614efbc60e43d09d5bacaa349170d229e91/prosail-2.0.5-py3-none-any.whl (149kB)\n", 85 | "\r\u001b[K |██▏ | 10kB 15.9MB/s eta 0:00:01\r\u001b[K |████▍ | 20kB 1.5MB/s eta 0:00:01\r\u001b[K |██████▋ | 30kB 1.7MB/s eta 0:00:01\r\u001b[K |████████▊ | 40kB 1.9MB/s eta 0:00:01\r\u001b[K |███████████ | 51kB 1.8MB/s eta 0:00:01\r\u001b[K |█████████████▏ | 61kB 1.9MB/s eta 0:00:01\r\u001b[K |███████████████▍ | 71kB 2.2MB/s eta 0:00:01\r\u001b[K |█████████████████▌ | 81kB 2.3MB/s eta 0:00:01\r\u001b[K |███████████████████▊ | 92kB 2.5MB/s eta 0:00:01\r\u001b[K |██████████████████████ | 102kB 2.5MB/s eta 0:00:01\r\u001b[K |████████████████████████▏ | 112kB 2.5MB/s eta 0:00:01\r\u001b[K |██████████████████████████▎ | 122kB 2.5MB/s eta 0:00:01\r\u001b[K |████████████████████████████▌ | 133kB 2.5MB/s eta 0:00:01\r\u001b[K |██████████████████████████████▊ | 143kB 2.5MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 153kB 2.5MB/s \n", 86 | "\u001b[?25hRequirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from prosail) (1.4.1)\n", 87 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from prosail) (1.18.4)\n", 88 | "Requirement already satisfied: numba in /usr/local/lib/python3.6/dist-packages (from prosail) (0.48.0)\n", 89 | "Requirement already satisfied: pytest in /usr/local/lib/python3.6/dist-packages (from prosail) (3.6.4)\n", 90 | "Requirement already satisfied: llvmlite<0.32.0,>=0.31.0dev0 in /usr/local/lib/python3.6/dist-packages (from numba->prosail) (0.31.0)\n", 91 | "Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from numba->prosail) (46.4.0)\n", 92 | "Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (8.3.0)\n", 93 | "Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (1.12.0)\n", 94 | "Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (1.8.1)\n", 95 | "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (19.3.0)\n", 96 | "Requirement already satisfied: atomicwrites>=1.0 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (1.4.0)\n", 97 | "Requirement already satisfied: pluggy<0.8,>=0.5 in /usr/local/lib/python3.6/dist-packages (from pytest->prosail) (0.7.1)\n", 98 | "Installing collected packages: prosail\n", 99 | "Successfully installed prosail-2.0.5\n", 100 | "Collecting lhsmdu\n", 101 | " Downloading https://files.pythonhosted.org/packages/7b/f0/e714a4dae734bcd7228a09d74fff7dc5857dc3311cd72a3e07b09c85d088/lhsmdu-0.1-py3-none-any.whl\n", 102 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from lhsmdu) (1.18.4)\n", 103 | "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from lhsmdu) (1.4.1)\n", 104 | "Installing collected packages: lhsmdu\n", 105 | "Successfully installed lhsmdu-0.1\n" 106 | ], 107 | "name": "stdout" 108 | } 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "metadata": { 114 | "id": "5UV3WvQ8PeU2", 115 | "colab": { 116 | "base_uri": "https://localhost:8080/", 117 | "height": 176 118 | }, 119 | "outputId": "5cfa4d53-6ce1-42ea-f7de-cea892d5f60b" 120 | }, 121 | "source": [ 122 | "!pip install hyperopt " 123 | ], 124 | "execution_count": null, 125 | "outputs": [ 126 | { 127 | "output_type": "stream", 128 | "text": [ 129 | "Requirement already satisfied: hyperopt in /usr/local/lib/python3.6/dist-packages (0.1.2)\n", 130 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from hyperopt) (1.18.4)\n", 131 | "Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from hyperopt) (4.41.1)\n", 132 | "Requirement already satisfied: pymongo in /usr/local/lib/python3.6/dist-packages (from hyperopt) (3.10.1)\n", 133 | "Requirement already satisfied: networkx in /usr/local/lib/python3.6/dist-packages (from hyperopt) (2.4)\n", 134 | "Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from hyperopt) (0.16.0)\n", 135 | "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from hyperopt) (1.4.1)\n", 136 | "Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from hyperopt) (1.12.0)\n", 137 | "Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx->hyperopt) (4.4.2)\n" 138 | ], 139 | "name": "stdout" 140 | } 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": { 146 | "id": "Ffgkb6EjPgJq" 147 | }, 148 | "source": [ 149 | "Packages for RandomForest and other auxiliary stuff" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "metadata": { 155 | "id": "jf01gPABPjd2" 156 | }, 157 | "source": [ 158 | "#the beutiful R like data frame\n", 159 | "import pandas as pd\n", 160 | "\n", 161 | "#the famous numpy \n", 162 | "import numpy as np\n", 163 | "\n", 164 | "#PROSPECT+SAIL Radiative transfer mode package\n", 165 | "import prosail\n", 166 | "\n", 167 | "#Sampling design package\n", 168 | "import lhsmdu\n", 169 | "\n", 170 | "#a few more stuff for random\n", 171 | "import random as rdm\n", 172 | "import math\n", 173 | "\n", 174 | "\n", 175 | "# import the regressor for gaussian processes and also the pre-set group of kernels\n", 176 | "from sklearn.gaussian_process import GaussianProcessRegressor\n", 177 | "from sklearn.gaussian_process.kernels import RBF,DotProduct,Matern,ExpSineSquared,RationalQuadratic\n", 178 | "\n", 179 | "\n", 180 | "from sklearn import metrics" 181 | ], 182 | "execution_count": null, 183 | "outputs": [] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": { 188 | "id": "Vf0CAwQePmC2" 189 | }, 190 | "source": [ 191 | "Bunch of functions needed for generating data" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "metadata": { 197 | "id": "rTAkzLnPPmiG" 198 | }, 199 | "source": [ 200 | "def custom_prosail(cab,cw,cm,lai):\n", 201 | " import prosail\n", 202 | " #default parameters\n", 203 | " n= 1.\n", 204 | " car=10.\n", 205 | " cbrown=0.01\n", 206 | " typelidf=1 #this is the default option\n", 207 | " lidfa = -1 #leaf angle distribution parameter a and b\n", 208 | " lidfb=-0.15\n", 209 | " hspot= 0.01 #hotspot parameters - got this from R package https://www.rdocumentation.org/packages/hsdar/versions/0.4.1/topics/PROSAIL\n", 210 | " #sun and viewing angle\n", 211 | " tts=30. #observation and solar position parameters\n", 212 | " tto=10. \n", 213 | " psi=0.\n", 214 | " #for now i put them by hand but they should be an input of a custom function\n", 215 | " #tts=sol_zen #solar zenith angle\n", 216 | " #tto=inc_zen #sensor zenith angle\n", 217 | " #psi=raa\n", 218 | " rho_out = prosail.run_prosail(n,\n", 219 | " cab,\n", 220 | " car,\n", 221 | " cbrown,\n", 222 | " cw,\n", 223 | " cm,\n", 224 | " lai,\n", 225 | " lidfa,\n", 226 | " hspot,\n", 227 | " tts,tto,psi,\n", 228 | " typelidf, lidfb,\n", 229 | " prospect_version=\"D\",\n", 230 | " factor='SDR', \n", 231 | " rsoil=.5, psoil=.5)\n", 232 | " return(rho_out)\n", 233 | "\n", 234 | "def Prosail2S2(path2csv,spectra_input):\n", 235 | " #importing pandas\n", 236 | " import pandas as pd\n", 237 | " import numpy\n", 238 | " import numpy as np\n", 239 | " #upload a S2_Response.csv from https://earth.esa.int/web/sentinel/user-guides/sentinel-2-msi/document-library/-/asset_publisher/Wk0TKajiISaR/content/sentinel-2a-spectral-responses\n", 240 | "\n", 241 | " s2_table = pd.read_csv(path2csv,sep=\";\",decimal=\",\") #check if this is proper, regarding the sep and dec\n", 242 | " #chekc which row you are actually extracting\n", 243 | "\n", 244 | " s2_table_sel = s2_table[s2_table['SR_WL'].between(400,2500)] #selects all values between 400 and 2500\n", 245 | " spectra_input_df = pd.DataFrame(data=spectra_input,columns=[\"rho\"],index=s2_table_sel.index) #transforms the input array into a pandas df with the column name rho and row.index = to the original input table\n", 246 | "\n", 247 | " \n", 248 | " rho_s2 = s2_table_sel.multiply(spectra_input_df['rho'],axis=\"index\") #calculates the numerator\n", 249 | " w_band_sum = s2_table_sel.sum(axis=0,skipna = True) #calculates the denominator\n", 250 | "\n", 251 | " output = (rho_s2.sum(axis=0)/w_band_sum).rename_axis(\"ID\").values #runs the weighted mean and converts the output to a numpy array\n", 252 | "\n", 253 | " return output[1:] #removes the first value because it represents the wavelength column\n", 254 | "\n", 255 | "#please LOAD THTE FILE NOW\n", 256 | "filepath=\"/content/drive/My Drive/S2_Response.csv\"\n", 257 | "#filepath=\"/content/S2_Responses_S2B.csv\"\n", 258 | "#filepath=\"/content/drive/My Drive/S2_Response.csv\"\n", 259 | "\n", 260 | "\n", 261 | "def Gen_spectra_data(traits):\n", 262 | " k = 1\n", 263 | " #pd_train_traits=traits\n", 264 | " #print(range(len(traits)))\n", 265 | " for i in range(len(traits)):\n", 266 | " #n_t = pd_train_traits[\"n\"][i]\n", 267 | " cab_t = traits[\"cab\"][i]\n", 268 | " #car_t = pd_train_traits[\"car\"][i]\n", 269 | " #cbrown_t = pd_train_traits[\"cbrown\"][i]\n", 270 | " cw_t = traits[\"cw\"][i]\n", 271 | " cm_t = traits[\"cm\"][i]\n", 272 | " lai_t = traits[\"lai\"][i]\n", 273 | "\n", 274 | " if k == 1:\n", 275 | " tr_rho_s = custom_prosail(cab_t,cw_t,cm_t,lai_t)\n", 276 | " tr_rho_s = Prosail2S2(filepath,tr_rho_s)\n", 277 | " #plt.plot ( x, tr_rho_s, ':', label=\"Training prosail\")\n", 278 | " #plt.legend(loc='best')\n", 279 | " \n", 280 | " if k > 1:\n", 281 | " tr_rho_t = custom_prosail(cab_t,cw_t,cm_t,lai_t)\n", 282 | " tr_rho_t = Prosail2S2(filepath,tr_rho_t)\n", 283 | " tr_rho_s = np.vstack((tr_rho_s,tr_rho_t))\n", 284 | " #plt.plot ( x, tr_rho_t, ':')\n", 285 | "\n", 286 | " k = k+1\n", 287 | "\n", 288 | "\n", 289 | " rho_samples=tr_rho_s\n", 290 | "\n", 291 | "\n", 292 | " return rho_samples\n", 293 | "\n", 294 | "\n", 295 | "\n", 296 | "\n", 297 | "#Function to store the outputs into a table\n", 298 | "column_names=[\"Model\",\n", 299 | " \"NSamples\",\n", 300 | " \"OutOfBag\",\n", 301 | " \"KFold_tr_samples\",\n", 302 | " \"KFold_vl_samples\",\n", 303 | " \"Variable\",\n", 304 | " \"Fold_nr\",\n", 305 | " \"ExplVar\",\n", 306 | " \"Max_err\",\n", 307 | " \"Mean_abs_Err\",\n", 308 | " \"Mean_sqr_err\",\n", 309 | " #\"Mean_sqr_lg_err\",\n", 310 | " \"Median_abs_err\",\n", 311 | " \"r2\",\n", 312 | " \"MAPE\",\n", 313 | " \"ModelName\"]\n", 314 | " #\"Mean_poiss_dev\",\n", 315 | " #\"Mean_gamma_dev\"]\n", 316 | " #\"Mean_tweed_dev\"]\n", 317 | "\n", 318 | "#mape is not existant in the package so we have to create it:\n", 319 | "#https://stats.stackexchange.com/questions/58391/mean-absolute-percentage-error-mape-in-scikit-learn\n", 320 | "#from sklearn.utils import check_array\n", 321 | "def mean_absolute_percentage_error(y_true, y_pred): \n", 322 | "\n", 323 | " ## Note: does not handle mix 1d representation\n", 324 | " #if _is_1d(y_true): \n", 325 | " # y_true, y_pred = _check_1d_array(y_true, y_pred)\n", 326 | "\n", 327 | " return np.mean(np.abs((y_true - y_pred) / y_true)) * 100\n", 328 | "\n", 329 | " #Here, the file is used for saving\n", 330 | " #creating a df to receive the data\n", 331 | "\n", 332 | "\n", 333 | "def calc_metrics(MDL,Samples,oob_samples,kf_tr,kf_vl,Variable,Fold,Ref,Pred,Modelname):\n", 334 | "\n", 335 | " out_list = {\"Model\":MDL,\n", 336 | " \"NSamples\":Samples,\n", 337 | " \"OutOfBag\":oob_samples,\n", 338 | " \"KFold_tr_samples\":kf_tr,\n", 339 | " \"KFold_vl_samples\":kf_vl,\n", 340 | " \"Variable\":Variable,\n", 341 | " \"Fold_nr\":Fold,\n", 342 | " \"ExplVar\": metrics.explained_variance_score(Ref, Pred),\n", 343 | " \"Max_err\": metrics.max_error(Ref, Pred),\n", 344 | " \"Mean_abs_Err\": metrics.mean_absolute_error(Ref, Pred),\n", 345 | " \"Mean_sqr_err\": metrics.mean_squared_error(Ref, Pred),\n", 346 | " \"Median_abs_err\" : metrics.median_absolute_error(Ref, Pred),\n", 347 | " \"r2\": metrics.r2_score(Ref, Pred),\n", 348 | " \"MAPE\": mean_absolute_percentage_error(Ref, Pred),\n", 349 | " \"ModelName\":Modelname}\n", 350 | "\n", 351 | "\n", 352 | " return out_list" 353 | ], 354 | "execution_count": null, 355 | "outputs": [] 356 | }, 357 | { 358 | "cell_type": "markdown", 359 | "metadata": { 360 | "id": "AH5x-3a2PpZn" 361 | }, 362 | "source": [ 363 | "Hyperparameter tuning section" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "metadata": { 369 | "id": "ci2Q04P5Ptt_" 370 | }, 371 | "source": [ 372 | "# define an objective function\n", 373 | "\n", 374 | "# These are a bunch of methods of te hyperopt package to generate the search space\n", 375 | "from hyperopt import hp\n", 376 | "\n", 377 | "# these are the minimizing function (fmin), Tree-parzen estimator method, an evaluation function, trial method and status indicators\n", 378 | "from hyperopt import fmin, tpe, space_eval, Trials, STATUS_OK, STATUS_FAIL\n", 379 | "from sklearn.model_selection import cross_val_score\n" 380 | ], 381 | "execution_count": null, 382 | "outputs": [] 383 | }, 384 | { 385 | "cell_type": "markdown", 386 | "metadata": { 387 | "id": "8zOs0-UNPv93" 388 | }, 389 | "source": [ 390 | "Step 2: Generate the data that is going to be used for training" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "metadata": { 396 | "id": "3-Cn1W_aPw5v" 397 | }, 398 | "source": [ 399 | "#first the trait-space\n", 400 | "\n", 401 | "n_traits=4 #I will test on 4 varying traits: cab, car, cw,cm,lai\n", 402 | "\n", 403 | "#generating a LHS hypercube (it uses a 0 to 1 interval that can be used as a multiplier against the different traits)\n", 404 | "np.random.seed(0)\n", 405 | "\n", 406 | "\n", 407 | "#the values here are 1 less than the max so i can add a value later to it\n", 408 | "#max_n=1 \n", 409 | "max_cab=121. #add 1\n", 410 | "#max_car=44. #add 1\n", 411 | "#max_cbrown= 9.99 #add 0.01\n", 412 | "max_cw=0.008 #add 0.001 \n", 413 | "max_cm=0.008 #0.001\n", 414 | "max_lai = 9.9 #add 0.1\n", 415 | "\n", 416 | "min_cab = 10.\n", 417 | "min_cw = 0.002\n", 418 | "min_cm = 0.002\n", 419 | "min_lai = .5\n", 420 | "\n", 421 | "#set the number of samples used for the optimization\n", 422 | "n_samples = 1500" 423 | ], 424 | "execution_count": null, 425 | "outputs": [] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "metadata": { 430 | "id": "hUsffTpDP26P" 431 | }, 432 | "source": [ 433 | "#this is for the training dataset\n", 434 | "df_metrics = pd.DataFrame(columns=column_names)\n", 435 | "#this is for the out of bag\n", 436 | "df_metrics_valid = pd.DataFrame(columns=column_names)\n", 437 | "\n", 438 | "#a path to store the models \n", 439 | "#path2folder = \"/content/drive/My Drive/DSRP_Lunch_outputs/Models/\"\n", 440 | "path2folder = \"/content/drive/My Drive/RTM_Inversion/HyperParameterTunning/RandF/\"\n", 441 | "\n", 442 | "#generating trait space and data\n", 443 | "LHS_train = lhsmdu.createRandomStandardUniformMatrix(n_traits,n_samples)\n", 444 | "pd_trait = pd.DataFrame.transpose(pd.DataFrame(LHS_train))\n", 445 | "pd_trait.columns = [\"cab\",\"cw\",\"cm\",\"lai\"]\n", 446 | "\n", 447 | "pd_trait[\"cab\"]=pd_trait[\"cab\"]*max_cab+min_cab\n", 448 | "pd_trait[\"cw\"] =pd_trait[\"cw\"] *max_cw+min_cw\n", 449 | "pd_trait[\"cm\"] =pd_trait[\"cm\"] *max_cm+min_cw\n", 450 | "pd_trait[\"lai\"]=pd_trait[\"lai\"]*max_lai+min_lai\n", 451 | "\n", 452 | "#this is the same as above but on numpy format\n", 453 | "np_trait = pd_trait.iloc[:,:].values\n", 454 | "\n", 455 | "#now we first generate the date in hyperspectral, convolute it to S2 while iterating through the entire given trait space\n", 456 | "np_spect = Gen_spectra_data(pd_trait)[:,[1,2,3,4,5,6,8,11,12]]\n", 457 | "\n", 458 | "#now we remove 10% of the data for out-of-bag validation of the final model while the cross-validation happens within the hyperparemeter tunning\n", 459 | "index = list(range(len(np_spect)))\n", 460 | "index10 = rdm.sample(index,math.ceil(len(index)*.1))\n", 461 | "index90 = [x for x in index if x not in index10]\n", 462 | "\n", 463 | "#selecting the groups for training (tr) and validation (vl)\n", 464 | "tr_trait_df = np_trait[index90,]\n", 465 | "tr_spect_df = np_spect[index90,]\n", 466 | "\n", 467 | "vl_trait_df = np_trait[index10,]\n", 468 | "vl_spect_df = np_spect[index10,]" 469 | ], 470 | "execution_count": null, 471 | "outputs": [] 472 | }, 473 | { 474 | "cell_type": "markdown", 475 | "metadata": { 476 | "id": "A127epk7P__n" 477 | }, 478 | "source": [ 479 | "Definining the optimization function and the search space\n", 480 | "\n", 481 | "---" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "metadata": { 487 | "id": "gr2pmF5-P9dr", 488 | "colab": { 489 | "base_uri": "https://localhost:8080/", 490 | "height": 34 491 | }, 492 | "outputId": "ddf10023-8ca9-49fd-830e-9b4690ea6f85" 493 | }, 494 | "source": [ 495 | "\n", 496 | "#objective function\n", 497 | "\n", 498 | "#first we define the function\n", 499 | "N_FOLDS = 10\n", 500 | "MAX_EVALS = 200\n", 501 | "\n", 502 | "#here we can just fetch the data so we keep everything in one place\n", 503 | "train_labels = tr_trait_df\n", 504 | "train_features = tr_spect_df \n", 505 | "\n", 506 | "from sklearn.model_selection import KFold # import KFold\n", 507 | "\n", 508 | "def objective(params, n_folds = N_FOLDS):\n", 509 | " \"\"\"Objective function for Random forest Hyperparameter Tuning\"\"\"\n", 510 | "\n", 511 | " # Perform n_fold cross validation with hyperparameters\n", 512 | " gp = GaussianProcessRegressor(**params, random_state = 42) #normalizing and adding noise does not increase the likelihood of sucessfull minimization\n", 513 | "\n", 514 | " #scores = cross_val_score(gp, X=train_features, y=train_labels, cv=10, scoring='neg_mean_absolute_error') #thi is the simple Mean abs\n", 515 | " #the cross_val_score function in GP seems to work out wonky so lets try explicitely creating it\n", 516 | "\n", 517 | " kf = KFold(n_splits=N_FOLDS,shuffle=True,random_state=42)\n", 518 | "\n", 519 | " scores = np.empty((0,n_traits)) #an empty arrray to holdout all the results of the kfoldind\n", 520 | " for train_index,test_index in kf.split(train_labels):\n", 521 | " x_train_k,x_test_k = train_features[train_index],train_features[test_index]\n", 522 | " y_train_k,y_test_k = train_labels[train_index],train_labels[test_index]\n", 523 | "\n", 524 | " gp.fit(x_train_k,y_train_k)\n", 525 | " outval = gp.predict(x_test_k)\n", 526 | "\n", 527 | " #storing all the MAE scores into a single place - this can be changed to anoter function\n", 528 | " score = [metrics.mean_absolute_error(y_test_k[:,0], outval[:,0]),\n", 529 | " metrics.mean_absolute_error(y_test_k[:,1], outval[:,1]),\n", 530 | " metrics.mean_absolute_error(y_test_k[:,2], outval[:,2]),\n", 531 | " metrics.mean_absolute_error(y_test_k[:,3], outval[:,3])]\n", 532 | " scores=np.append(scores,score) #just add the values to the end of the numpy and continues\n", 533 | "\n", 534 | "\n", 535 | " # Extract the best score\n", 536 | " best_score = max(abs(scores)) #using the abs here forces the function to minimize independently of the sign\n", 537 | " # if the the result is miniming\n", 538 | "\n", 539 | " # Loss must be minimized\n", 540 | " #loss = 1 - best_score \n", 541 | " loss = best_score \n", 542 | "\n", 543 | " # Dictionary with information for evaluation\n", 544 | " return {'loss': loss, 'params': params, 'status': STATUS_OK}\n", 545 | "\n", 546 | "#distribution functions for the parameter sampling are here:\n", 547 | "#https://github.com/hyperopt/hyperopt/wiki/FMin\n", 548 | "\n", 549 | "\n", 550 | "#first we should create the kernels\n", 551 | "#K_white = kernels.WhiteKernel()\n", 552 | "\n", 553 | "#seems trivial to limit the maximum number of iterations within this base function\n", 554 | "#https://scikit-optimize.github.io/stable/_modules/sklearn/gaussian_process/_gpr.html\n", 555 | "#or alternitively call an altered version of the scipy.optimizer (or with an improved optimization technique)\n", 556 | "\n", 557 | "\n", 558 | "#RBF,DotProduct,Matern,ExpSineSquared,RationalQuadratic\n", 559 | "#K_rbf = 1.0*kernels.RBF()\n", 560 | "K_rbf = RBF(length_scale_bounds=\"fixed\")\n", 561 | "#K_ratQ = kernels.RationalQuadratic() \n", 562 | "K_ratQ = RationalQuadratic(length_scale_bounds=\"fixed\",alpha_bounds=\"fixed\")\n", 563 | "#k_mate = 1.0*kernels.Matern()\n", 564 | "k_mate = Matern(length_scale_bounds=\"fixed\")\n", 565 | "#K_expsine = kernels.ExpSineSquared()\n", 566 | "#K_expsine = ExpSineSquared(length_scale_bounds=\"fixed\",periodicity_bounds=\"fixed\")\n", 567 | "K_dotprod = DotProduct()\n", 568 | "K_dotprod = DotProduct(sigma_0_bounds=\"fixed\")\n", 569 | "\n", 570 | "#kernel_list = [K_ratQ,K_rbf,k_mate,K_expsine,K_dotprod]\n", 571 | "#kernel_list = [RBF(1.0, length_scale_bounds=\"fixed\")] #ahh! eureka, this is the version of RBF it utilized by default -> it only has to minimize one thing, basically its very slow because of that..\n", 572 | "kernel_list = [K_rbf,K_ratQ,k_mate,K_dotprod]\n", 573 | "\n", 574 | "space = {\n", 575 | " 'n_restarts_optimizer': hp.choice('n_restarts_optimizer', range(10, 101, 10)), #to avoid values of 0\n", 576 | " 'kernel': hp.choice('kernel', kernel_list),\n", 577 | " 'normalize_y':hp.choice('normalize_y',[True,False])\n", 578 | "}\n", 579 | "\n", 580 | "for i in range(10, 101, 10):\n", 581 | " print(i, end=', ')" 582 | ], 583 | "execution_count": null, 584 | "outputs": [ 585 | { 586 | "output_type": "stream", 587 | "text": [ 588 | "10, 20, 30, 40, 50, 60, 70, 80, 90, 100, " 589 | ], 590 | "name": "stdout" 591 | } 592 | ] 593 | }, 594 | { 595 | "cell_type": "markdown", 596 | "metadata": { 597 | "id": "cEf-kvGcVtNi" 598 | }, 599 | "source": [ 600 | "This now is the order for running" 601 | ] 602 | }, 603 | { 604 | "cell_type": "code", 605 | "metadata": { 606 | "id": "1iGm-b55UXNE", 607 | "colab": { 608 | "base_uri": "https://localhost:8080/", 609 | "height": 34 610 | }, 611 | "outputId": "6f3952ed-5c16-4c81-96f1-5c6c884d852c" 612 | }, 613 | "source": [ 614 | "#this loop is the actual testing\n", 615 | "bayes_trials = Trials()\n", 616 | "\n", 617 | "best_pgr = fmin(fn = objective, space = space, algo = tpe.suggest, max_evals = MAX_EVALS, trials = bayes_trials,verbose=1)" 618 | ], 619 | "execution_count": null, 620 | "outputs": [ 621 | { 622 | "output_type": "stream", 623 | "text": [ 624 | "100%|██████████| 200/200 [05:39<00:00, 1.70s/it, best loss: 0.028436356979695123]\n" 625 | ], 626 | "name": "stdout" 627 | } 628 | ] 629 | }, 630 | { 631 | "cell_type": "markdown", 632 | "metadata": { 633 | "id": "Q5qy0xyz8qLf" 634 | }, 635 | "source": [ 636 | "Checking the outputs" 637 | ] 638 | }, 639 | { 640 | "cell_type": "code", 641 | "metadata": { 642 | "id": "_MBrznXC8sKH", 643 | "colab": { 644 | "base_uri": "https://localhost:8080/", 645 | "height": 34 646 | }, 647 | "outputId": "2c5b9e7a-772c-4ad6-9280-5789b22cae26" 648 | }, 649 | "source": [ 650 | "best_pgr" 651 | ], 652 | "execution_count": null, 653 | "outputs": [ 654 | { 655 | "output_type": "execute_result", 656 | "data": { 657 | "text/plain": [ 658 | "{'kernel': 1, 'n_restarts_optimizer': 7, 'normalize_y': 0}" 659 | ] 660 | }, 661 | "metadata": { 662 | "tags": [] 663 | }, 664 | "execution_count": 12 665 | } 666 | ] 667 | } 668 | ] 669 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------