Skip to content

Commit

Permalink
Save evapotranspiration also as tif
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoStucchi committed Nov 9, 2021
1 parent 5f0be81 commit 6e8120c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
29 changes: 29 additions & 0 deletions graph/et_tiff_saving.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<graph id="Graph">
<version>1.0</version>
<node id="Read">
<operator>Read</operator>
<sources/>
<parameters class="com.bc.ceres.binding.dom.XppDomElement">
<file>!INPUT_et_DIM!</file>
</parameters>
</node>
<node id="Write">
<operator>Write</operator>
<sources>
<sourceProduct refid="Read"/>
</sources>
<parameters class="com.bc.ceres.binding.dom.XppDomElement">
<file>!OUTPUT_et_GEOTIFF!</file>
<formatName>GeoTIFF</formatName>
</parameters>
</node>
<applicationData id="Presentation">
<Description/>
<node id="Read">
<displayPosition x="37.0" y="135.0"/>
</node>
<node id="Write">
<displayPosition x="455.0" y="135.0"/>
</node>
</applicationData>
</graph>
26 changes: 23 additions & 3 deletions py_scripts/3_create_script_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
general_path_era_meteo = general_path + "era\\era5.nc"
lookup_table = python_path + "\\sen-et-snap-scripts\\auxdata\\LUT\\ESA_CCI_LUT.csv"
general_path_s3 = general_path + "S3\\YYYY_MM_DD\\S3_YYYY_MM_DD"
general_path_era = general_path + "era\\YYYY_MM_DD\\S3_YYYY_MM_DD"
general_path_out = general_path + "out\\YYYY_MM_DD\\out_YYYY_MM_DD"
general_path_et = general_path + "et\\YYYY_MM_DD\\out_YYYY_MM_DD"
general_path_era = general_path + "era\\YYYY_MM_DD\\YYYY_MM_DD"
general_path_out = general_path + "out\\YYYY_MM_DD\\YYYY_MM_DD"
general_path_et = general_path + "et\\dim\\YYYY_MM_DD"
general_path_et_tiff = general_path + "et\\tiff\\YYYY_MM_DD"
general_path_s2 = general_path + "S2\\YYYY_MM_DD\\S2_YYYY_MM_DD"
path_graph_et = "graph\\et_tiff_saving.xml"

# Variable for Sentinel 2 images
file_date_s2 = open(path_file_date_s2, "r")
Expand All @@ -51,6 +53,11 @@
date_s3.append(date)
file_date_s3.close()

# Open graph for save ET as tiff
f = open(path_graph_et, "r")
graph_et = f.read()
f.close()

# Command list
cmd_leaf = python_path + "\\python " + python_path + "\\sen-et-snap-scripts\\leaf_spectra.py --biophysical_file PATHS2_biophysical.dim --output_file PATHS2_leaf_spectra.dim"
cmd_fracgreen = python_path + "\\python " + python_path + "\\sen-et-snap-scripts\\frac_green.py --sza_file PATHS2_sun_zenith_angle.dim --biophysical_file PATHS2_biophysical.dim --min_frac_green " + min_frac_green + " --output_file PATHS2_frac_green.dim"
Expand Down Expand Up @@ -95,6 +102,8 @@
t_general_path_era = general_path_era.replace("YYYY", year).replace("MM", mon).replace("DD", day)
t_general_path_out = general_path_out.replace("YYYY", year).replace("MM", mon).replace("DD", day)
t_general_path_et = general_path_et.replace("YYYY", year).replace("MM", mon).replace("DD", day)
t_general_path_et_tiff = general_path_et_tiff.replace("YYYY", year).replace("MM", mon).replace("DD", day)
et_time = str(int(year)) + "_" + str(int(mon)) + "_" + str(int(day))
data_test = datetime(int(year), int(mon), int(day))
cloz_dict = {abs(data_test.timestamp() - date.timestamp()) : date for date in date_s2}
close_s2 = cloz_dict[min(cloz_dict.keys())]
Expand All @@ -116,8 +125,19 @@
text = text + cmd_fluxes.replace("PATHS3", t_general_path_s3).replace("PATHS2", t_general_path_s2).replace("PATHERA", t_general_path_era).replace("PATHOUT", t_general_path_out) + "\n"
text = text + "echo \"\t Computing the evapotranspiration for the image S3 " + str(date) + "\"\n"
text = text + cmd_et.replace("PATHERA", t_general_path_era).replace("PATHOUT", t_general_path_out).replace("PATHET", t_general_path_et) + "\n"

# Write ET as geotiff
text = text + "echo \"\t Transformation of the evapotranspiration for the image S3 " + str(date) + "\"\n"
text_grapht_et = graph_et.replace("!INPUT_et_DIM!", t_general_path_et + "_daily_evapotranspiration.dim").replace("!OUTPUT_et_GEOTIFF!", t_general_path_et_tiff + "_daily_evapotranspiration.tif")
path_grapht_et = "output\\graph\\et_tiff_saving_" + et_time +".xml"
text = text + "gpt " + path_grapht_et + "\n"
f = open(path_grapht_et, "w")
f.write(text_grapht_et)
f.close()

text = text + "echo \"\t Finish the computation of the evapotranspiration for the image S3 " + str(date) + "\"\n\n"


text = text.replace("\\", "\\\\")
f = open(path_output_s3, "w")
f.write(text)
Expand Down

0 comments on commit 6e8120c

Please sign in to comment.