Skip to content

Commit

Permalink
Merge pull request #3 from iiasa/vittorio-giordano-patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
giacfalk authored Mar 1, 2023
2 parents a2bb49c + 704355f commit c35ce85
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 403 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ The database to run the platform for the pilot country of Zambia is avaiable at

Once downloaded, the database(s) (a zipped folder for each of the four models) should be extracted. The exact full path to the database (e.g. *C:/Users/[yourusername]/Documents/RE4AFAGRI_database/...* should be parsed onto the different model at the following positions:

- For WaterCROP:
- For WaterCROP: at *lines 1, 4, 21, 55, 65, 68 - and subsequently for each crop - and 785* of the 'WaterCROP1_ETactual.mat' file
at *lines 9, 14, 20, 94* of the 'WaterCROP2_Irrigation_requirements.mat' file
- For M-LED: at *line 10* of the `MLED_hourly.R` file, defining the `db_folder` parameter
- For OnSSET: include the OnSSET replication data folder unzipped in `onsset\onsset_replication` (more details below)
- For NEST: The database only raw data needed in the pre-processing phase. The data needed to run the model is already included in the Github repository
Expand All @@ -43,7 +44,7 @@ Each models is developed in a specific programming language and has thus specifi
- Download or clone this entire repository either using, Github Desktop, `git clone` or downloading it as a .zip folder with all of the subfolders for each model included

### For WaterCROP:
- XXX
- Have 'Matlab' (version >= R2017a) installed on your local computer

### For M-LED:
- Have `R` (version >=3.6) installed on your local computer: https://cran.r-project.org/bin/windows/base/
Expand Down Expand Up @@ -75,7 +76,8 @@ Each models is developed in a specific programming language and has thus specifi
## Operating the platform

### For WaterCROP:
- XXX
- Open 'WaterCROP1_ETactual.mat' file in MATLAB and select the scenario to run; then run the code.
- Open 'WaterCROP2_Irrigation_requirements.mat' and run the code. The code will produce the input files produces netcdf files of irrigation water requirements and yield growth potential for all African countries.

### For M-LED:
- Open the `MLED_hourly.r` file in RStudio
Expand Down Expand Up @@ -119,7 +121,9 @@ Currently, each model has own reporting methods and formats, although a joint re
In particular results can be examined by:

### For WaterCROP:
-
- WaterCROP outputs are found in 'results2' folder, and in each specific crop subfolder, which are automatically created after a model run.
- WaterCROP writes output data at 5 arcmin for the whole African continent
- The results files can be analysed using MATLAB and can be vsualized in GIS softwares

### For M-LED:
- M-LED outputs are found in the `results` folder which is automatically created inside the `m-led` home folder after a model run.
Expand Down
28 changes: 14 additions & 14 deletions watercrop/WaterCROP1_ETactual.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cd 'C:\Users\giord\Desktop\IIASA collab\WaterCrop'
cd '~\WaterCrop_replication'
climate = imread('thcli1.tif');

cd 'C:\Users\giord\Desktop\IIASA collab\WaterCrop\1-ET0mm_day'
cd '~\WaterCrop_replication\1-ET0mm_day'
ET0_2020=importdata('ET0_2020_370_GFDL_bias.mat');
ET0_2020(isnan(ET0_2020))=0;

Expand All @@ -18,7 +18,7 @@
ET0_nov=ET0_2020(:,:,11);
ET0_dec=ET0_2020(:,:,12);

cd 'C:\Users\giord\Desktop\IIASA collab\WaterCrop\2-Prec_mm_day'
cd '~\WaterCrop_replication\2-Prec_mm_day'
P_2020=importdata('P_2020_370_GFDL_bias.mat');
P_2020(isnan(P_2020))=0;

Expand Down Expand Up @@ -52,7 +52,7 @@
jan_after=14:1/30:15-1/30;
days=[dec_before,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,jan_after]';

cartella_kc = 'C:\Users\giord\Desktop\IIASA collab\WaterCrop';
cartella_kc = '~\WaterCrop_replication';

raccolto=1;%,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,31,32,33]; %19 crops
for r = 1:length(raccolto) %r crop index
Expand All @@ -62,10 +62,10 @@
%-- II growing season

case 1 %Mais
cartella='C:\Users\giord\Desktop\IIASA collab\WaterCrop\Maize';
cartella='~\WaterCrop_replication\Maize';

coeff_colturale='kc_maize';
cartella_risultati='C:\Users\giord\Desktop\IIASA collab\WaterCrop\Risultati1_ETa\Maize';
cartella_risultati='~\WaterCrop_replication\Results1_ETa\Maize';

rd_ini=0.3; %m
rd_max_rainfed=1.7; %fao 56 tab 22 pag 190
Expand Down Expand Up @@ -782,7 +782,7 @@
kc=xlsread('kc_global_NEWCROPS_def.xlsx',coeff_colturale,'C17:I26');

%
cd 'C:\Users\giord\Desktop\IIASA collab\WaterCrop'
cd '~\WaterCrop_replication'
awc_final=importdata('awc_mmalm.mat');

temp=zeros(14,2);
Expand Down Expand Up @@ -1638,7 +1638,7 @@
end
end


mkdir(cartella_risultati)
cd(cartella_risultati)

save('ETa_rain.mat','ETa_tot')
Expand All @@ -1651,16 +1651,16 @@
save('ETc_tot_rain.mat','ETc_tot_rain')
save('ETc_tot_irr.mat','ETc_tot_irr')

save('ETa_rf_month.mat','ETa_month') %NEST
save('ETc_rf_month.mat','ETc_month') %NEST
save('ETa_rf_month.mat','ETa_month')
save('ETc_rf_month.mat','ETc_month')
save('ET0_rf_month.mat','ET0_rf_month')
save('Pre_eff_monthly.mat','Pre_eff_monthly')
save('Pre_tot_monthly_gs.mat','Pre_tot_monthly_gs')
save('ETgreen_month.mat','ETgreen_month')
save('ETa_irr_month.mat','CWU_month') %NEST
save('ETblue_month.mat','ETblue_month') %NEST
save('I_month.mat','I_month') %NEST
save('ETc_irr_month.mat','ETc_irr_month') %NEST
save('ETa_irr_month.mat','CWU_month')
save('ETblue_month.mat','ETblue_month')
save('I_month.mat','I_month')
save('ETc_irr_month.mat','ETc_irr_month')
save('ET0_irr_month.mat','ET0_irr_month')
save('Pre_eff_irr_month.mat','Pre_eff_irr_month')
save('Pre_tot_irr_month_gs.mat','Pre_tot_irr_month_gs')
Expand Down
77 changes: 41 additions & 36 deletions watercrop/WaterCROP2_Irrigation_requirements.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
code = [{'BARL'},'CASS','COCO','COTT','GROU','MAIZ','PMIL','SMIL','OILP','POTA','RAPE','RICE','SORG','SOYB','SUGB','SUGC','SUNF','WHEA','YAMS'];


cd('C:\Users\giord\Desktop\IIASA collab\WaterCrop')
cd('~\WaterCrop_replication')
ky = xlsread('crops_list_ky.xlsx','B2:B20');

for cr = 6 %1 2 3 4 5 6 7 9 11 12 22 28 crop number

cd(['C:\Users\giord\Desktop\IIASA collab\WaterCrop\',char(crop_name(cr)),''])
cd(['~\WaterCrop_replication\',char(crop_name(cr)),''])
area_rf = importdata(['spam2017V2r1_SSA_H_',char(code(cr)),'_R.mat']);
area_ir = importdata(['spam2017V2r1_SSA_H_',char(code(cr)),'_I.mat']);
ya = importdata(['spam2017V2r1_SSA_Y_',char(code(cr)),'_R.mat']);
ya(isnan(ya)) = 0;

cd(['C:\Users\giord\Desktop\IIASA collab\WaterCrop\Risultati1_ETa\',char(crop(cr)),''])
cd(['~\WaterCrop_replication\Results1_ETa\',char(crop(cr)),''])

ETa_RF = importdata('ETa_rf_month.mat');
ETa_IR = importdata('ETa_irr_month.mat');
Expand All @@ -34,34 +34,34 @@
ETa=zeros(2160,4320,12);
ETc=zeros(2160,4320,12);

ETa(:,:,1) = (ETa_RF(:,:,1).*area_rf + ETa_IR(:,:,1).*area_ir)./(area_rf + area_ir);
ETa(:,:,2) = (ETa_RF(:,:,2).*area_rf + ETa_IR(:,:,2).*area_ir)./(area_rf + area_ir);
ETa(:,:,3) = (ETa_RF(:,:,3).*area_rf + ETa_IR(:,:,3).*area_ir)./(area_rf + area_ir);
ETa(:,:,4) = (ETa_RF(:,:,4).*area_rf + ETa_IR(:,:,4).*area_ir)./(area_rf + area_ir);
ETa(:,:,5) = (ETa_RF(:,:,5).*area_rf + ETa_IR(:,:,5).*area_ir)./(area_rf + area_ir);
ETa(:,:,6) = (ETa_RF(:,:,6).*area_rf + ETa_IR(:,:,6).*area_ir)./(area_rf + area_ir);
ETa(:,:,7) = (ETa_RF(:,:,7).*area_rf + ETa_IR(:,:,7).*area_ir)./(area_rf + area_ir);
ETa(:,:,8) = (ETa_RF(:,:,8).*area_rf + ETa_IR(:,:,8).*area_ir)./(area_rf + area_ir);
ETa(:,:,9) = (ETa_RF(:,:,9).*area_rf + ETa_IR(:,:,9).*area_ir)./(area_rf + area_ir);
ETa(:,:,10) = (ETa_RF(:,:,10).*area_rf + ETa_IR(:,:,10).*area_ir)./(area_rf + area_ir);
ETa(:,:,11) = (ETa_RF(:,:,11).*area_rf + ETa_IR(:,:,11).*area_ir)./(area_rf + area_ir);
ETa(:,:,12) = (ETa_RF(:,:,12).*area_rf + ETa_IR(:,:,12).*area_ir)./(area_rf + area_ir);

ETc(:,:,1) = (ETc_RF(:,:,1).*area_rf + ETc_IR(:,:,1).*area_ir)./(area_rf + area_ir);
ETc(:,:,2) = (ETc_RF(:,:,2).*area_rf + ETc_IR(:,:,2).*area_ir)./(area_rf + area_ir);
ETc(:,:,3) = (ETc_RF(:,:,3).*area_rf + ETc_IR(:,:,3).*area_ir)./(area_rf + area_ir);
ETc(:,:,4) = (ETc_RF(:,:,4).*area_rf + ETc_IR(:,:,4).*area_ir)./(area_rf + area_ir);
ETc(:,:,5) = (ETc_RF(:,:,5).*area_rf + ETc_IR(:,:,5).*area_ir)./(area_rf + area_ir);
ETc(:,:,6) = (ETc_RF(:,:,6).*area_rf + ETc_IR(:,:,6).*area_ir)./(area_rf + area_ir);
ETc(:,:,7) = (ETc_RF(:,:,7).*area_rf + ETc_IR(:,:,7).*area_ir)./(area_rf + area_ir);
ETc(:,:,8) = (ETc_RF(:,:,8).*area_rf + ETc_IR(:,:,8).*area_ir)./(area_rf + area_ir);
ETc(:,:,9) = (ETc_RF(:,:,9).*area_rf + ETc_IR(:,:,9).*area_ir)./(area_rf + area_ir);
ETc(:,:,10) = (ETc_RF(:,:,10).*area_rf + ETc_IR(:,:,10).*area_ir)./(area_rf + area_ir);
ETc(:,:,11) = (ETc_RF(:,:,11).*area_rf + ETc_IR(:,:,11).*area_ir)./(area_rf + area_ir);
ETc(:,:,12) = (ETc_RF(:,:,12).*area_rf + ETc_IR(:,:,12).*area_ir)./(area_rf + area_ir);
% ETa(:,:,1) = (ETa_RF(:,:,1).*area_rf + ETa_IR(:,:,1).*area_ir)./(area_rf + area_ir);
% ETa(:,:,2) = (ETa_RF(:,:,2).*area_rf + ETa_IR(:,:,2).*area_ir)./(area_rf + area_ir);
% ETa(:,:,3) = (ETa_RF(:,:,3).*area_rf + ETa_IR(:,:,3).*area_ir)./(area_rf + area_ir);
% ETa(:,:,4) = (ETa_RF(:,:,4).*area_rf + ETa_IR(:,:,4).*area_ir)./(area_rf + area_ir);
% ETa(:,:,5) = (ETa_RF(:,:,5).*area_rf + ETa_IR(:,:,5).*area_ir)./(area_rf + area_ir);
% ETa(:,:,6) = (ETa_RF(:,:,6).*area_rf + ETa_IR(:,:,6).*area_ir)./(area_rf + area_ir);
% ETa(:,:,7) = (ETa_RF(:,:,7).*area_rf + ETa_IR(:,:,7).*area_ir)./(area_rf + area_ir);
% ETa(:,:,8) = (ETa_RF(:,:,8).*area_rf + ETa_IR(:,:,8).*area_ir)./(area_rf + area_ir);
% ETa(:,:,9) = (ETa_RF(:,:,9).*area_rf + ETa_IR(:,:,9).*area_ir)./(area_rf + area_ir);
% ETa(:,:,10) = (ETa_RF(:,:,10).*area_rf + ETa_IR(:,:,10).*area_ir)./(area_rf + area_ir);
% ETa(:,:,11) = (ETa_RF(:,:,11).*area_rf + ETa_IR(:,:,11).*area_ir)./(area_rf + area_ir);
% ETa(:,:,12) = (ETa_RF(:,:,12).*area_rf + ETa_IR(:,:,12).*area_ir)./(area_rf + area_ir);
%
% ETc(:,:,1) = (ETc_RF(:,:,1).*area_rf + ETc_IR(:,:,1).*area_ir)./(area_rf + area_ir);
% ETc(:,:,2) = (ETc_RF(:,:,2).*area_rf + ETc_IR(:,:,2).*area_ir)./(area_rf + area_ir);
% ETc(:,:,3) = (ETc_RF(:,:,3).*area_rf + ETc_IR(:,:,3).*area_ir)./(area_rf + area_ir);
% ETc(:,:,4) = (ETc_RF(:,:,4).*area_rf + ETc_IR(:,:,4).*area_ir)./(area_rf + area_ir);
% ETc(:,:,5) = (ETc_RF(:,:,5).*area_rf + ETc_IR(:,:,5).*area_ir)./(area_rf + area_ir);
% ETc(:,:,6) = (ETc_RF(:,:,6).*area_rf + ETc_IR(:,:,6).*area_ir)./(area_rf + area_ir);
% ETc(:,:,7) = (ETc_RF(:,:,7).*area_rf + ETc_IR(:,:,7).*area_ir)./(area_rf + area_ir);
% ETc(:,:,8) = (ETc_RF(:,:,8).*area_rf + ETc_IR(:,:,8).*area_ir)./(area_rf + area_ir);
% ETc(:,:,9) = (ETc_RF(:,:,9).*area_rf + ETc_IR(:,:,9).*area_ir)./(area_rf + area_ir);
% ETc(:,:,10) = (ETc_RF(:,:,10).*area_rf + ETc_IR(:,:,10).*area_ir)./(area_rf + area_ir);
% ETc(:,:,11) = (ETc_RF(:,:,11).*area_rf + ETc_IR(:,:,11).*area_ir)./(area_rf + area_ir);
% ETc(:,:,12) = (ETc_RF(:,:,12).*area_rf + ETc_IR(:,:,12).*area_ir)./(area_rf + area_ir);

ETa_ann = (ETa_ann_RF.*area_rf + ETa_ann_IR.*area_ir)./(area_rf + area_ir);
ETc_ann = (ETc_ann_RF.*area_rf + ETc_ann_IR.*area_ir)./(area_rf + area_ir);
% ETa_ann = (ETa_ann_RF.*area_rf + ETa_ann_IR.*area_ir)./(area_rf + area_ir); %metti solo rainfed
% ETc_ann = (ETc_ann_RF.*area_rf + ETc_ann_IR.*area_ir)./(area_rf + area_ir); %metti solo rainfed

ETc(isnan(ETc)) = 0;
ETc(isinf(ETc)) = 0;
Expand All @@ -82,7 +82,7 @@
end

%Doorenbos yield with new ETa
yc = ya .* (ones(2160,4320)-ky(cr)*(ones(2160,4320)-ETc_ann./ETa_ann));
yc = ya .* (ones(2160,4320)-ky(cr)*(ones(2160,4320)-ETc_ann_RF./ETa_ann_RF));
% yc = ya .* (ones(2160,4320)-ky(cr)*(ones(2160,4320)-(ETa + 0.2*closure_mm)./ETa));

yc(isnan(yc)) = 0;
Expand All @@ -91,7 +91,7 @@
%percentage variation
delta = (yc - ya)./ya * 100;

cart_new = ['C:\Users\giord\Desktop\IIASA collab\WaterCrop\Risultati2_NEST\',char(crop(cr)),''];
cart_new = ['~\WaterCrop_replication\Results2\',char(crop(cr)),''];
cd(cart_new)
save('closure_yield.mat','yc')
save('yield_percentage_variation.mat','delta')
Expand All @@ -106,15 +106,20 @@

closure_m3 = closure_mm .* area_rf./ 10; %[m3]
% txt_per_QGis(closure_m3_jan,'closure_m3_jan','-9999','0.0833333') %2D-only
save('closure_mm.mat','closure_mm')
save('closure_m3.mat','closure_m3')
save('closure_mm.mat','closure_mm')
save('closure_m3.mat','closure_m3')

actual_I_m3=(actual_I_mm.*area_ir)./10;
actual_I_m3(isnan(actual_I_m3))=0;
% txt_per_QGis(actual_I_mm(:,:,1),'actual_I_mm_jan','-9999','0.0833333','2')

nccreate('waterwith_2020_monthly_maize_mm.nc','Irr_mm','Dimensions',{'x',2160,'y',4320,'z',12});

save('actual_I_mm.mat','actual_I_mm')
save('actual_I_m3.mat','actual_I_m3')

nccreate('waterwith_2020_monthly_maize_mm.nc','Irr_mm','Dimensions',{'lat',2160,'lon',4320,'months',12},'DeflateLevel',7);
ncwrite('waterwith_2020_monthly_maize_mm.nc','Irr_mm',actual_I_mm);
nccreate('waterwith_2020_monthly_maize_m3.nc','Irr_m3','Dimensions',{'x',2160,'y',4320,'z',12});
nccreate('waterwith_2020_monthly_maize_m3.nc','Irr_m3','Dimensions',{'lat',2160,'lon',4320,'months',12},'DeflateLevel',7);
ncwrite('waterwith_2020_monthly_maize_m3.nc','Irr_m3',actual_I_m3);

end
Loading

0 comments on commit c35ce85

Please sign in to comment.