diff --git a/.github/workflows/cron_update_SPI24.yml b/.github/workflows/cron_update_SPI24.yml
new file mode 100644
index 00000000..889693a1
--- /dev/null
+++ b/.github/workflows/cron_update_SPI24.yml
@@ -0,0 +1,76 @@
+name: Update 24-month SPI Anomaly (Long-term)
+
+on:
+ workflow_dispatch:
+ # Allows manual triggering of the action
+ schedule:
+ - cron: '0 12 * * *' # Runs daily at 12:00 UTC, adjust as needed
+
+jobs:
+ spi-24-month:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout Repository
+ uses: actions/checkout@v4
+ - uses: actions/setup-python@v3
+ with:
+ python-version: '3.13'
+
+ - name: Upgrade pip & Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ echo "Installing Python dependencies"
+ if [ -f ./python/requirements.txt ]; then pip install -r ./python/requirements.txt; fi
+ pip install rasterio
+ pip install earthengine-api
+ pip install earthengine-api --upgrade
+
+ # Get file source name and put it on env
+ # - name: Run Python Script on File
+ # run: |
+ # python python/getFilename24month.py
+
+ # # Copy from Google storage to local
+ # - name: Copy from Google storage to local
+ # uses: actions-hub/gcloud@master
+ # env:
+ # PROJECT_ID: ${{secrets.GCP_PROJECT_ID}}
+ # APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
+ # with:
+ # args: cp $WPS_24_MONTH_GS $WPS_24_MONTH_FILENAME
+ # cli: gsutil
+
+ # # Get file source name and put it on env
+ # - name: Project downloaded file
+ # run: |
+ # python python/project.py
+
+ # # Upload to Google storage
+ # - name: Upload to Google storage
+ # uses: actions-hub/gcloud@master
+ # env:
+ # PROJECT_ID: ${{secrets.GCP_PROJECT_ID}}
+ # APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
+ # with:
+ # args: cp $WPS_24_MONTH_FILENAME $WPS_24_MONTH_GS_PROJ
+ # cli: gsutil
+
+
+ - name: 'auth'
+ uses: 'google-github-actions/auth@v2'
+ with:
+ token_format: 'access_token'
+ project_id: ${{ secrets.GCP_PROJECT_ID }}
+ workload_identity_provider: 'projects/297470958436/locations/global/workloadIdentityPools/wps-github-action-automations'
+ service_account: 'wps-automation@wpsi-208318.iam.gserviceaccount.com'
+
+ - name: 'Use gcloud CLI'
+ run: 'gcloud info'
+
+ # upload to GEE
+ - name: Upload to GEE
+ run: |
+ python python/earthengine.py
+
+
diff --git a/.gitignore b/.gitignore
index 06ceb5b1..5de6c981 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,6 +44,8 @@ coverage
.env.local
.env
+.secrets
+
# vscode and vendor cache
.vscode/
untracked
diff --git a/app/javascript/components/constants.js b/app/javascript/components/constants.js
index 3919b41b..5c60f972 100644
--- a/app/javascript/components/constants.js
+++ b/app/javascript/components/constants.js
@@ -1,33 +1,37 @@
const BASEMAPS = {
dark: {
id: 'dark',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqgjq1908ar2smep2wd7wf7/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqgjq1908ar2smep2wd7wf7/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
label: 'Dark',
options: {
+ zoomOffset: -1, tileSize: 512,
attribution: '© Mapbox © OpenStreetMap'
}
},
light: {
id: 'light',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqgk77j0r7h2sqw220p7imy/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqgk77j0r7h2sqw220p7imy/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
label: 'Light',
options: {
+ zoomOffset: -1, tileSize: 512,
attribution: '© Mapbox © OpenStreetMap'
}
},
satellite: {
id: 'satellite',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqiecof53wv2rl9gw4cehmy/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqiecof53wv2rl9gw4cehmy/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
label: 'Satellite',
options: {
+ zoomOffset: -1, tileSize: 512,
attribution: '© Mapbox © OpenStreetMap'
}
},
terrain: {
id: 'terrain',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqi456h02pg2rp6w2mwp61c/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjhqi456h02pg2rp6w2mwp61c/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
label: 'Terrain',
options: {
+ zoomOffset: -1, tileSize: 512,
attribution: '© Mapbox © OpenStreetMap'
}
}
@@ -42,12 +46,18 @@ const LABELS = {
light: {
id: 'light',
label: 'Labels light',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjgcf9rs05qnu2rrpp4qzucox/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ'
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjgcf9rs05qnu2rrpp4qzucox/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ options: {
+ zoomOffset: -1, tileSize: 512
+ }
},
dark: {
id: 'dark',
label: 'Labels dark',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjgcf9gqk9tmm2spd9zr0tml3/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ'
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjgcf9gqk9tmm2spd9zr0tml3/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ options: {
+ zoomOffset: -1, tileSize: 512
+ }
}
};
@@ -55,7 +65,10 @@ const BOUNDARIES = {
dark: {
id: 'dark',
label: 'Boundaries',
- value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjgcf8qdaai1x2rn6w3j4q805/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ'
+ value: 'https://api.mapbox.com/styles/v1/resourcewatch/cjgcf8qdaai1x2rn6w3j4q805/tiles/512/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmVzb3VyY2V3YXRjaCIsImEiOiJjbHVpdTh5N2swMm9sMndwYzZuNnFtY3NkIn0.26SGTMZGMtgNJaonQfiKjQ',
+ options: {
+ zoomOffset: -1, tileSize: 512
+ }
}
};
diff --git a/python/.run-act.sh b/python/.run-act.sh
new file mode 100755
index 00000000..faa902bd
--- /dev/null
+++ b/python/.run-act.sh
@@ -0,0 +1 @@
+act -P ubuntu-latest=ubuntu-builder --pull=false --container-architecture linux/amd64 --secret-file .secrets workflow_dispatch --workflows '.github/workflows/cron_update_SPI24.yml'
\ No newline at end of file
diff --git a/python/automation.py b/python/automation.py
new file mode 100644
index 00000000..a8e9b332
--- /dev/null
+++ b/python/automation.py
@@ -0,0 +1 @@
+print("***************HELLOO******************")
\ No newline at end of file
diff --git a/python/currMonth.py b/python/currMonth.py
new file mode 100644
index 00000000..e8d9e4b1
--- /dev/null
+++ b/python/currMonth.py
@@ -0,0 +1,3 @@
+from datetime import datetime
+
+print(f"{datetime.now().year}{datetime.now().month}")
\ No newline at end of file
diff --git a/python/docker/Act.Dockerfile b/python/docker/Act.Dockerfile
new file mode 100644
index 00000000..e8d64aa0
--- /dev/null
+++ b/python/docker/Act.Dockerfile
@@ -0,0 +1,10 @@
+FROM ubuntu:20.04
+
+RUN apt-get update \
+ && apt-get upgrade -y \
+ && DEBIAN_FRONTEND=noninteractive apt-get install -y \
+ build-essential \
+ curl \
+ nodejs \
+ npm \
+ && rm -rf /var/lib/apt/lists/*
\ No newline at end of file
diff --git a/python/earthengine.py b/python/earthengine.py
new file mode 100644
index 00000000..32d4eee6
--- /dev/null
+++ b/python/earthengine.py
@@ -0,0 +1,7 @@
+import ee
+
+ee.Authenticate()
+
+ee.Initialize(project="wpsi-208318")
+
+print(ee.String('Hello from the Earth Engine servers!').getInfo())
\ No newline at end of file
diff --git a/python/getFilename24month.py b/python/getFilename24month.py
new file mode 100644
index 00000000..ff304465
--- /dev/null
+++ b/python/getFilename24month.py
@@ -0,0 +1,24 @@
+from datetime import datetime
+import os
+
+# 24 month
+
+def getPrevMonth(month, delta):
+ if month+delta <= 0:
+ return month+delta+12
+ else:
+ return (month+delta)%12
+
+current_year_month = f"{datetime.now().year}{getPrevMonth(datetime.now().month, -1):02}"
+prev_year_month = f"{datetime.now().year}{getPrevMonth(datetime.now().month, -2):02}"
+
+file = 'ERA5_SPI24_{year_month}'
+
+env_file = os.getenv('GITHUB_ENV') # Get the path of the runner file
+
+# write to the file
+with open(env_file, "a") as env_file:
+ env_file.write(f"WPS_24_MONTH_GS=gs://wps_pillar1a/data_sources/Deltares/Data{current_year_month}/{file.format(year_month=prev_year_month)}.tif\n")
+ env_file.write(f"WPS_24_MONTH_GS_PROJ=gs://wps_pillar1a/data_sources/Deltares/Data{current_year_month}/proj_{file.format(year_month=prev_year_month)}.tif\n")
+ env_file.write(f"WPS_24_MONTH_FILENAME={file.format(year_month=prev_year_month)}.tif")
+
\ No newline at end of file
diff --git a/python/project.py b/python/project.py
new file mode 100644
index 00000000..7f8a292a
--- /dev/null
+++ b/python/project.py
@@ -0,0 +1,14 @@
+import rasterio
+from rasterio.crs import CRS
+import os
+
+FILE = os.environ["WPS_24_MONTH_FILENAME"]
+
+
+if FILE:
+ print('The filename evn WPS_24_MONTH_FILENAME={FILE} successfully loaded!')
+else:
+ print('Please check the env WPS_24_MONTH_FILENAME was not loaded')
+
+with rasterio.open(FILE, "r+") as rds:
+ rds.crs = CRS.from_epsg(4326)
\ No newline at end of file
diff --git a/python/readme.md b/python/readme.md
new file mode 100644
index 00000000..4ddfc7b3
--- /dev/null
+++ b/python/readme.md
@@ -0,0 +1,13 @@
+## Using act to locally run github actions
+
+you have to create a local image with the tag ubuntu-builder by running
+
+
+
+```bash
+docker build -f python/docker/Act.Dockerfile -t ubuntu-builder .
+```
+
+```bash
+act -P ubuntu-latest=ubuntu-builder --pull=false --container-architecture linux/amd64 --secret-file .secrets workflow_dispatch --workflows '.github/workflows/cron_update_SPI24.yml'
+```
\ No newline at end of file
diff --git a/python/requirements.txt b/python/requirements.txt
new file mode 100644
index 00000000..58a8512d
--- /dev/null
+++ b/python/requirements.txt
@@ -0,0 +1,4 @@
+LMIPy==0.6.2
+pandas==2.2.3
+python-dotenv==1.0.1
+Requests==2.32.3
\ No newline at end of file