Skip to content

Commit

Permalink
Merge pull request #9 from EcoExtreML/refactor_drs
Browse files Browse the repository at this point in the history
Remove relative paths and revise the readme
  • Loading branch information
SarahAlidoost authored Jan 19, 2022
2 parents 5a6bbbd + a837306 commit e1ca875
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 184 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ Integrated code of SCOPE and STEMMUS
2. Find the 'Remote Desktop' in the Launcher and click it.
3. Find the 'Applications'and click it, you will find the 'MATLAB' software in the 'Research'.
4. Open the 'MATLAB' using your account.
5. The STEMMUS_SCOPE v1.0.0 was saved at the folder '/data/shared/EcoExtreML/STEMMUS_SCOPE v1.0.0/src/STEMMUS_SCOPE.m'
6. Open the 'STEMMUS_SCOPE.m' file and run it.
5. All the code can be found in the folder 'src' in this repository.
6. In a terminal, run:
```bash
matlab -nodisplay -nosplash -nodesktop -r "run('STEMMUS_SCOPE.m');exit;"
```

(2) The dataflow of the STEMMUS_SCOPE v1.0.0:

1. The driving data provided by PLUMBER2 were saved at the folder named '../Plumber2 data'.
The soil texture data and soil hydraulic parameters data were saved at the folder named '../SoilProperty'.
The results of the model will be saved at the folder named '../output'.
All the code can be find at the folder named '../src'.
1. The driving data provided by PLUMBER2 were saved at the folder named 'Plumber2_data'.
The soil texture data and soil hydraulic parameters data were saved at the folder named 'SoilProperty'.
The results of the model will be saved at the folder named 'output'.

2. The main program is 'STEMMUS_SCOPE.m'. Currently, the model can be run at the site scale.
For example, if we put the 'AU-Tum_2002-2017_OzFlux_Met.nc' file in the 'input' folder. The model will be run at the AU-TUM site.
For example, if we put the 'FI-Hyy_1996-2014_FLUXNET2015_Met.nc' file in the 'input' folder. The model will be run at the FI-Hyy site.

3. After the model was started, the workflow are as follows:
(1) The model will read the 'AU-Tum_2002-2017_OzFlux_Met.nc' file and transfer it into '.dat' files with 'filesread.m' (you can find the '.dat' files in the 'input' folder). In addition, the site information (including location and vegetation) were also read.
(1) The model will read the 'FI-Hyy_1996-2014_FLUXNET2015_Met.nc' file and transfer it into '.dat' files with 'filesread.m' (you can find the '.dat' files in the 'input' folder). In addition, the site information (including location and vegetation) were also read.
(2) Then, the model will read the soil parameters with 'soilpropertyread.m'.
(3) Some constants will be load using 'constant.m'.
(4) The model will run step by step until the whole simulation period completed.
(5) The results were be saved as 'binary files' temporarily and the 'binary files' will be transfer to '.csv' files at the end.

(3) Some constants will be loaded using 'Constant.m'.
(4) The model will run step by step until the whole simulation period is completed.
(5) The results will be saved as 'binary files' temporarily and the 'binary files' will be transferred to '.csv' files at the end.

(3) Run STEMMUS_SCOPE v1.0.0 on a different compute node:

Open the file "filesread.m" and set all paths at the top of this file. The rest of the workflow is the same as explained above.
20 changes: 10 additions & 10 deletions src/+io/create_output_files.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Output_dir = create_output_files(parameter_file, F, path_of_code, options, V, vmax, spectral)
function Output_dir = create_output_files(parameter_file, F, path_of_code, input_path, output_path, options, V, vmax, spectral)
%% Create DATA files
% author J.timmermans
% last modified 4 Aug 2008: Added the creation of log file (file with input parameters)
Expand All @@ -21,7 +21,7 @@
string = clock;

Outdir_Name = char(F(1).FileName);
Output_dir = sprintf(['../output/',Outdir_Name,'_%4.0f-%02.0f-%02.0f-%02.0f%02.0f/'],[string(1) string(2) string(3) string(4) string(5)]);
Output_dir = sprintf([output_path,Outdir_Name,'_%4.0f-%02.0f-%02.0f-%02.0f%02.0f/'],[string(1) string(2) string(3) string(4) string(5)]);
warning('off','MATLAB:DELETE:FileNotFound')
if any(~exist(Output_dir,'dir'))
mkdir(Output_dir)
Expand All @@ -33,11 +33,11 @@

%% Log File
for i = 1:length(parameter_file)
copyfile(['../input/' parameter_file{i}],[Output_dir,'Parameters/', parameter_file{i}],'f')
copyfile([input_path parameter_file{i}],[Output_dir,'Parameters/', parameter_file{i}],'f')
end
fidpath = fopen([Output_dir,'Parameters/SCOPEversion.txt'],'w'); % complete path of the SCOPE code
fprintf(fidpath,'%s', path_of_code);
%copyfile(['../' parameter_file],[Output_dir,'Parameters/', parameter_file ],'f')
%copyfile([input_path parameter_file],[Output_dir,'Parameters/', parameter_file ],'f')

%% Normal Output
fidf = fopen([Output_dir,'fluxes.dat'],'w'); % fluxes
Expand Down Expand Up @@ -87,12 +87,12 @@
end

else
delete([Output_dir,'../output/leaftemp.dat'])
delete([Output_dir,'../output/layer_H.dat'])
delete([Output_dir,'../output/layer_lE.dat'])
delete([Output_dir,'../output/layer_A.dat'])
delete([Output_dir,'../output/layer_aPAR.dat'])
delete([Output_dir,'../output/layer_Rn.dat'])
delete([Output_dir,'leaftemp.dat'])
delete([Output_dir,'layer_H.dat'])
delete([Output_dir,'layer_lE.dat'])
delete([Output_dir,'layer_A.dat'])
delete([Output_dir,'layer_aPAR.dat'])
delete([Output_dir,'layer_Rn.dat'])
end

if options.calc_fluor
Expand Down
16 changes: 8 additions & 8 deletions src/+io/create_output_files_binary.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function [Output_dir, f, fnames] = create_output_files_binary(parameter_file, sitename, path_of_code, input_path, spectral, options)
function [Output_dir, f, fnames] = create_output_files_binary(parameter_file, sitename, path_of_code, input_path, output_path, spectral, options)
%% Create Output dir
string = clock;
simulation_name = char(sitename);
outdir_name = sprintf('%s_%4.0f-%02.0f-%02.0f-%02.0f%02.0f', simulation_name, string(1:5));
Output_dir = [fullfile('../output/', outdir_name) filesep];
Output_dir = [fullfile(output_path, outdir_name) filesep];

warning('off','MATLAB:DELETE:FileNotFound')
if any(~exist(Output_dir,'dir'))
Expand Down Expand Up @@ -70,12 +70,12 @@
end

else
delete([Output_dir,'../output/leaftemp.bin'])
delete([Output_dir,'../output/layer_H.bin'])
delete([Output_dir,'../output/layer_lE.bin'])
delete([Output_dir,'../output/layer_A.bin'])
delete([Output_dir,'../output/layer_aPAR.bin'])
delete([Output_dir,'../output/layer_Rn.bin'])
delete([Output_dir,'leaftemp.bin'])
delete([Output_dir,'layer_H.bin'])
delete([Output_dir,'layer_lE.bin'])
delete([Output_dir,'layer_A.bin'])
delete([Output_dir,'layer_aPAR.bin'])
delete([Output_dir,'layer_Rn.bin'])
end

if options.calc_fluor
Expand Down
4 changes: 2 additions & 2 deletions src/Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
uERR=0.02; % Maximum desirable change of total water content;
Tot_Depth=500; % Unit is cm. it should be usually bigger than 0.5m. Otherwise,
% the DeltZ would be reset in 50cm by hand;
R_depth=300; %¸ùÉî
R_depth=300; %����
Eqlspace=0; % Indicator for deciding is the space step equal or not;
NL=100;
if ~Eqlspace
Expand Down Expand Up @@ -434,7 +434,7 @@
% Input for producing initial soil moisture and soil temperature profile
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Mdata=textread('../input/Mdata.txt');
Mdata=textread([InputPath, 'Mdata.txt']);
Ta_msr=Mdata(:,2)';
RH_msr=Mdata(:,3)';
WS_msr=Mdata(:,4)';
Expand Down
25 changes: 13 additions & 12 deletions src/STEMMUS_SCOPE.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%%

%% 0. globals
run filesread %prepare input files
run filesread %get paths and prepare input files
run Constants %input soil parameters
global i tS KT Delt_t TEND TIME MN NN NL ML ND hOLD TOLD h hh T TT P_gOLD P_g P_gg Delt_t0 g
global KIT NIT TimeStep Processing
Expand Down Expand Up @@ -60,13 +60,14 @@
[constants] = io.define_constants();
[Rl] = Initial_root_biomass(RTB,DeltZ_R,rroot,ML);
%% 2. simulation options
path_input = InputPath; % path of all inputs
path_of_code = cd;
run set_parameter_filenames;

if length(parameter_file)>1, useXLSX = 0; else useXLSX = 1; end

if ~useXLSX
run(['../' parameter_file{1}])
run([path_input parameter_file{1}])

options.calc_ebal = N(1); % calculate the energy balance (default). If 0, then only SAIL is executed!
options.calc_vert_profiles = N(2); % calculate vertical profiles of fluxes
Expand All @@ -90,16 +91,16 @@
% 2: Lookup-Table (specify the values to be included)
% 3: Lookup-Table with random input (specify the ranges of values)
else
options = io.readStructFromExcel(['../input/' char(parameter_file)], 'options', 3, 1);
options = io.readStructFromExcel([path_input char(parameter_file)], 'options', 3, 1);
end

if options.simulation>2 || options.simulation<0, fprintf('\n simulation option should be between 0 and 2 \r'); return, end

%% 3. file names
if ~useXLSX
run(['../input/' parameter_file{2}])
run([path_input parameter_file{2}])
else
[dummy,X] = xlsread(['../input/' char(parameter_file)],'filenames');
[dummy,X] = xlsread([path_input char(parameter_file)],'filenames');
j = find(~strcmp(X(:,2),{''}));
X = X(j,(1:end));
end
Expand All @@ -118,10 +119,10 @@
%% 4. input data

if ~useXLSX
X = textread(['../input/' parameter_file{3}],'%s'); %#ok<DTXTRD>
X = textread([path_input parameter_file{3}],'%s'); %#ok<DTXTRD>
N = str2double(X);
else
[N,X] = xlsread(['../input/' char(parameter_file)],'inputdata', '');
[N,X] = xlsread([path_input char(parameter_file)],'inputdata', '');
X = X(9:end,1);
end
V = io.assignvarnames();
Expand Down Expand Up @@ -260,7 +261,7 @@
end
end
%% 5. Declare paths
path_input = '../input/'; % path of all inputs
path_input = InputPath; % path of all inputs

%% 6. Numerical parameters (iteration stops etc)
iter.maxit = 400; % maximum number of iterations
Expand Down Expand Up @@ -352,7 +353,7 @@
atmo.M = helpers.aggreg(atmfile,spectral.SCOPEspec);

%% 13. create output files
[Output_dir, f, fnames] = io.create_output_files_binary(parameter_file, sitename, path_of_code, path_input, spectral, options);
[Output_dir, f, fnames] = io.create_output_files_binary(parameter_file, sitename, path_of_code, path_input, path_output, spectral, options);
run StartInit; % Initialize Temperature, Matric potential and soil air pressure.


Expand Down Expand Up @@ -782,7 +783,7 @@
io.output_verification(Output_dir)
end
io.bin_to_csv(fnames, V, vmax, n_col, k, options,Ztot)
if options.makeplots
plot.plots(Output_dir)
end
%if options.makeplots
% plot.plots(Output_dir)
%end

Loading

0 comments on commit e1ca875

Please sign in to comment.