Skip to content

Commit

Permalink
Implemented Trace Mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
jchemutt committed May 23, 2024
1 parent e2d498a commit aad04cf
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 4 deletions.
Binary file not shown.
70 changes: 70 additions & 0 deletions src/codes/data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import date,timedelta
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
from codes.funcs import *
from codes.send_notification import *

print ("")
print ("")
Expand Down Expand Up @@ -41,12 +42,19 @@
combined_output=os.path.join(outputs_path, "combined.csv")

service_account = data["service_account"]
email_list= data["email_list"]
try:
credentials = ee.ServiceAccountCredentials(service_account, private_key)
ee.Initialize(credentials)
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Could not authenticate with the Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()

layers = os.listdir(biomass_path)
Expand All @@ -72,6 +80,12 @@ def addDate(image):
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Google Earth Engine Error</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()

def getImage(product,start_date,end_date,variable):
Expand All @@ -80,6 +94,12 @@ def getImage(product,start_date,end_date,variable):
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Google Earth Engine Error</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()

ndvi=getImage("MODIS/061/MOD13A2",start_date_,end_date_,"NDVI");
Expand Down Expand Up @@ -112,6 +132,13 @@ def weeklyAverage(week):
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest CHIRPS Daily products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)

exit_program()


Expand Down Expand Up @@ -140,6 +167,12 @@ def weeklyAverage(week):
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest Soil Moisture products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()


Expand Down Expand Up @@ -186,21 +219,45 @@ def mergeDataframes(df1,df2):
ndvi2=generateVariables(ndvi1,ndvi_output);
else:
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest Terra Vegetation Indices 16-Day Global 1km products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest Terra Vegetation Indices 16-Day Global 1km products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()
try:
if preci16.size().getInfo()>0:
preci1 = preci16.filterBounds(ee_fc).map(addDate).map(rasterExtraction).flatten()
preci2=generateVariables(preci1,preci_output);
else:
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest CHIRPS Daily products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest CHIRPS Daily products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()
try:
if sm16.size().getInfo()>0:
Expand All @@ -216,10 +273,23 @@ def mergeDataframes(df1,df2):
result_df.to_csv(combined_output,mode='w')
else:
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest Soil Moisture products cannot be found in Google Earth Engine</span></li>"

send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()
except EEException as e:
print(str(e))
truncate_file(combined_output)
subject = "Biomass not updated"
dynamic_header = "Notice: Biomass Data Failed to Update:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you about a failure to update the biomass data. Below, you will find specific details about the error."
dynamic_content = "<p>Error Message:</p>"
dynamic_content += f"<li><span style='color: red;'>Latest Soil Moisture products cannot be found in Google Earth Engine</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
exit_program()


Expand Down
7 changes: 7 additions & 0 deletions src/codes/gwr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
from codes.funcs import *

print ("")
print ("")
print (" Running Geographically weighted regression model")
print ("")
print ("")
print ("")

# Constants
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

Expand Down
12 changes: 10 additions & 2 deletions src/codes/import_biomass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
from codes.tools import GeoserverClient
from codes.funcs import *
from codes.send_notification import *


print ("")
Expand Down Expand Up @@ -34,13 +36,13 @@
folder_properties = os.path.join(folder_layers, forecast_type+"_properties")
folder_tmp = os.path.join(folder_data, "tmp")
fname = os.path.join(outputs_path, "new_data_list_FINAL.txt")

with open(fname) as f:
file_content = f.readlines()

rasters_files = [x.strip() for x in file_content]


if len(rasters_files)==0:
exit_program()

stores_biomass = [forecast_type]

Expand Down Expand Up @@ -75,3 +77,9 @@


print("Process completed")
subject = "Biomass Updated"
dynamic_header = "Notice: Biomass Data Updated Successfully:"
dynamic_info = "I hope this email finds you well. We are reaching out to inform you Biomass data has been updated successfully. Below, you will find specific details about the raster files uploaded."
dynamic_content = "<p>Raster Files:</p>"
dynamic_content += f"<li><span style='color: green;'>{rasters_files}</span></li>"
send_email_html(email_list, dynamic_header,dynamic_info,dynamic_content,subject)
177 changes: 177 additions & 0 deletions src/codes/notification.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Email Waterpoint Monitoring</title>
<!-- Importa la fuente Montserrat desde Google Fonts -->
<style>
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap");
</style>
<!-- Aplica la fuente Montserrat al cuerpo del correo -->
<style>
body {
font-family: "Montserrat", sans-serif;
margin: 0;
}
</style>
</head>

<body style="margin: 0; padding: 0">
<table role="presentation" style="
width: 100%;
border-collapse: collapse;
border: 0;
border-spacing: 0;
background: #ffffff;
">
<tr>
<td align="center" style="padding: 0">
<table role="presentation" style="
width: 602px;
border-collapse: collapse;
border: 1px solid #cccccc;
border-spacing: 0;
text-align: left;
">
<tr>
<td align="center" style="padding: 40px 0 30px 0; background: #04335d">
<a href="https://et.waterpointsmonitoring.net/forage" style="text-decoration: none; color: white">
<img src="https://et.waterpointsmonitoring.net/static/media/logo.4fa18c4a73d3bc0b7bda.png"
alt="logo-wp" width="100" style="height: auto; display: block" />
<h2>Waterpoints Monitoring</h2>
</a>
</td>
</tr>
<tr>
<td style="padding: 36px 30px 42px 30px">
<table role="presentation" style="
width: 100%;
border-collapse: collapse;
border: 0;
border-spacing: 0;
">
<tr>
<td style="padding: 0 0 36px 0; color: #153643">
<h1 id="header" style="
font-size: 24px;
margin: 0 0 20px 0;
font-family: Arial, sans-serif;
">

</h1>
<p id="name" style="
margin: 0 0 12px 0;
font-size: 16px;
line-height: 24px;
font-family: Arial, sans-serif;
"></p>
<p id="info" style="
margin: 0 0 12px 0;
font-size: 16px;
line-height: 24px;
font-family: Arial, sans-serif;
">

</p>
</td>
</tr>
<tr>
<td style="padding: 0">
<table>
<tr id="container"></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding: 30px; background: #04335d">
<table role="presentation" style="
width: 100%;
border-collapse: collapse;
border: 0;
border-spacing: 0;
font-size: 9px;
">
<tr>
<td style="
padding: 0;
width: 50%;
font-size: 14px;
line-height: 16px;
" align="left">
<p style="font-size: 16px; color: white">Contact us</p>
<ul style="list-style: none; padding: 0">
<li style="margin-bottom: 0.5rem">
<a href="mailto:S.alemayehu@cgiar.org"
style="text-decoration: none; color: #fff">
S.alemayehu@cgiar.org
</a>
</li>
<li style="margin-bottom: 0.5rem">
<a href="mailto:liyenew@gmail.com"
style="text-decoration: none; color: #fff">
Liyenew@gmail.com
</a>
</li>
</ul>
</td>
<td style="padding: 0; width: 50%" align="right">
<table role="presentation" style="
border-collapse: collapse;
border: 0;
border-spacing: 0;
">
<tr>
<p style="font-size: 16px; color: white">Partners</p>

<td style="padding: 0 0 0 10px; width: 25%">
<img src="https://raw.githubusercontent.com/CIAT-DAPA/lswms_website/main/src/src/assets/img/partner1.png"
alt="partner EIAR" style="
margin-right: 1rem;
margin-bottom: 0.5rem;
width: 100%;
" />
</td>
<td style="padding: 0 0 0 10px; width: 25%">
<img src="https://raw.githubusercontent.com/CIAT-DAPA/lswms_website/main/src/src/assets/img/partner5.png"
alt="partner CGIAR" style="
margin-right: 1rem;
margin-bottom: 0.5rem;
width: 100%;
" />
</td>
<td style="padding: 0 0 0 10px; width: 25%">
<img src="https://raw.githubusercontent.com/CIAT-DAPA/lswms_website/main/src/src/assets/img/partner2.png"
alt="partner Alliance" style="
margin-right: 1rem;
margin-bottom: 0.5rem;
width: 100%;
" />
</td>
<td style="padding: 0 0 0 10px; width: 25%">
<img src="https://raw.githubusercontent.com/CIAT-DAPA/lswms_website/main/src/src/assets/img/partner4.png"
alt="partner Minister" style="
margin-right: 1rem;
margin-bottom: 0.5rem;
width: 100%;
" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>

</html>
Loading

0 comments on commit aad04cf

Please sign in to comment.