Skip to content

Commit dfcdace

Browse files
authored
Create batch_image_correlation.yml
1 parent 91211a3 commit dfcdace

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Batch process many image pairs
2+
name: Batch
3+
run-name: batch image correlation ${{ inputs.npairs }} connections
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
cloud_cover:
9+
type: choice
10+
required: true
11+
description: percent cloud cover allowed in images
12+
default: '10'
13+
start_month:
14+
type: choice
15+
required: true
16+
description: first month of year to search for images
17+
default: '6'
18+
options: ['1','2','3','4','5','6','7','8','9','10','11','12']
19+
stop_month:
20+
type: choice
21+
required: true
22+
description: last month of year to search for images
23+
default: '9'
24+
options: ['1','2','3','4','5','6','7','8','9','10','11','12']
25+
npairs:
26+
type: choice
27+
required: true
28+
description: number of pairs per image
29+
default: '3'
30+
options: ['3','2','1']
31+
32+
# Must duplicate inputs for workflow_call (https://github.com/orgs/community/discussions/39357)
33+
workflow_call:
34+
inputs:
35+
cloud_cover:
36+
type: string
37+
required: true
38+
start_month:
39+
type: string
40+
required: true
41+
stop_month:
42+
type: string
43+
required: true
44+
npairs:
45+
type: string
46+
required: true
47+
48+
jobs:
49+
# The output of this job is a JSON mapping for a matrix job
50+
S2_search:
51+
runs-on: ubuntu-latest
52+
outputs:
53+
BURST_IDS: ${{ steps.asf-search.outputs.BURST_IDS }}
54+
MATRIX: ${{ steps.asf-search.outputs.MATRIX_PARAMS_COMBINATIONS }}
55+
defaults:
56+
run:
57+
shell: bash -el {0}
58+
steps:
59+
- name: Checkout Repository
60+
uses: actions/checkout@v4
61+
62+
- name: Install Conda environment with Micromamba
63+
uses: mamba-org/setup-micromamba@v1
64+
with:
65+
cache-environment: true
66+
environment-file: environment.yml
67+
68+
# https://words.yuvi.in/post/python-in-github-actions/
69+
- name: Search aws for S2 imagery
70+
id: S2_search
71+
shell: bash -el -c "python -u {0}"
72+
run: |
73+
import xarray as xr
74+
import os
75+
import pystac
76+
import pystac_client
77+
import stackstac
78+
from dask.distributed import Client
79+
import dask
80+
import json
81+
82+
# GDAL environment variables for better performance
83+
os.environ['AWS_REGION']='us-west-2'
84+
os.environ['GDAL_DISABLE_READDIR_ON_OPEN']='EMPTY_DIR'
85+
os.environ['AWS_NO_SIGN_REQUEST']='YES'
86+
87+
# hardcode bbox for now
88+
bbox = {
89+
"type": "Polygon",
90+
"coordinates": [
91+
[[75.42382800808971,36.41082887114753],
92+
[75.19442677164156,36.41082887114753],
93+
[75.19442677164156,36.201076360872946],
94+
[75.42382800808971,36.201076360872946],
95+
[75.42382800808971,36.41082887114753]]]
96+
}
97+
98+
# We use the api from element84 to query the data
99+
URL = "https://earth-search.aws.element84.com/v1"
100+
catalog = pystac_client.Client.open(URL)
101+
102+
search = catalog.search(
103+
collections=["sentinel-2-l2a"],
104+
intersects=bbox,
105+
query={"eo:cloud_cover": {"lt": ${{ inputs.cloud_cover }}}}, # less than 10% cloud cover
106+
)
107+
108+
# Check how many items were returned
109+
items = search.item_collection()
110+
print(f"Returned {len(items)} Items")
111+
112+
sentinel2_stack = stackstac.stack(items)
113+
sentinel2_stack_snowoff = sentinel2_stack.where((sentinel2_stack.time.dt.month >= ${{ inputs.start_month }}) & (sentinel2_stack.time.dt.month <= ${{ inputs.stop_month }}), drop=True)
114+
115+
image_dates = sentinel2_stack_snowoff.time.dt.strftime('%Y-%m-%d').values.tolist()
116+
print('\n'.join(image_dates))
117+
118+
# Create Matrix Job Mapping (JSON Array)
119+
pairs = []
120+
for r in range(len(image_dates) - ${{ inputs.npairs }}):
121+
for s in range(1, ${{ inputs.npairs }} + 1 ):
122+
img1_date = image_dates[r]
123+
img2_date = image_dates[r+s]
124+
shortname = f'{img1_date}_{img2_date}'
125+
pairs.append({'img1_date': img1_date, 'img2_date': img2_date, 'name':shortname})
126+
matrixJSON = f'{{"include":{json.dumps(pairs)}}}'
127+
print(f'Number of Interferograms: {len(pairs)}')
128+
129+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
130+
print(f'BURST_IDS={image_dates}', file=f)
131+
print(f'MATRIX_PARAMS_COMBINATIONS={matrixJSON}', file=f)
132+
133+
#STOPPED HERE 5/29/2024
134+
135+
# A matrix job that calls a reuseable workflow
136+
hyp3-isce2:
137+
needs: searchASF
138+
strategy:
139+
fail-fast: false
140+
matrix: ${{ fromJson(needs.searchASF.outputs.MATRIX) }}
141+
name: ${{ matrix.name }}
142+
uses: ./.github/workflows/single-job.yml
143+
with:
144+
reference: ${{ matrix.reference }}
145+
secondary: ${{ matrix.secondary }}
146+
looks: ${{ inputs.looks }}
147+
apply_water_mask: ${{ inputs.apply_water_mask }}
148+
workflow_name: ${{ matrix.name }}
149+
secrets: inherit

0 commit comments

Comments
 (0)