Skip to content

Commit 3f1b1ed

Browse files
authored
replace code with script in batch_image_correlation.yml
1 parent efc7e67 commit 3f1b1ed

File tree

1 file changed

+1
-70
lines changed

1 file changed

+1
-70
lines changed

.github/workflows/batch_image_correlation.yml

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -65,79 +65,10 @@ jobs:
6565
cache-environment: true
6666
environment-file: glacier_image_correlation/environment.yml
6767

68-
# https://words.yuvi.in/post/python-in-github-actions/
6968
- name: Search aws for S2 imagery
7069
id: S2_search
71-
shell: bash -el -c "python -u {0}"
7270
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-
import pandas as pd
82-
83-
# GDAL environment variables for better performance
84-
os.environ['AWS_REGION']='us-west-2'
85-
os.environ['GDAL_DISABLE_READDIR_ON_OPEN']='EMPTY_DIR'
86-
os.environ['AWS_NO_SIGN_REQUEST']='YES'
87-
88-
# hardcode bbox for now
89-
bbox = {
90-
"type": "Polygon",
91-
"coordinates": [
92-
[[75.42382800808971,36.41082887114753],
93-
[75.19442677164156,36.41082887114753],
94-
[75.19442677164156,36.201076360872946],
95-
[75.42382800808971,36.201076360872946],
96-
[75.42382800808971,36.41082887114753]]]
97-
}
98-
99-
# Use the api from element84 to query the data
100-
URL = "https://earth-search.aws.element84.com/v1"
101-
catalog = pystac_client.Client.open(URL)
102-
103-
search = catalog.search(
104-
collections=["sentinel-2-l2a"],
105-
intersects=bbox,
106-
query={"eo:cloud_cover": {"lt": ${{ inputs.cloud_cover }}}}
107-
)
108-
109-
# Check how many items were returned
110-
items = search.item_collection()
111-
print(f"Returned {len(items)} Items")
112-
113-
# create xarray dataset without loading data
114-
sentinel2_stack = stackstac.stack(items)
115-
# filter to specified month range
116-
sentinel2_stack_snowoff = sentinel2_stack.where((sentinel2_stack.time.dt.month >= ${{ inputs.start_month }}) & (sentinel2_stack.time.dt.month <= ${{ inputs.stop_month }}), drop=True)
117-
118-
# select first image of each month
119-
period_index = pd.PeriodIndex(sentinel2_stack_snowoff['time'].values, freq='M')
120-
sentinel2_stack_snowoff.coords['year_month'] = ('time', period_index)
121-
first_image_indices = sentinel2_stack_snowoff.groupby('year_month').apply(lambda x: x.isel(time=0))
122-
123-
product_names = first_image_indices['s2:product_uri'].values.tolist()
124-
print('\n'.join(product_names))
125-
126-
# Create Matrix Job Mapping (JSON Array)
127-
pairs = []
128-
for r in range(len(product_names) - ${{ inputs.npairs }}):
129-
for s in range(1, ${{ inputs.npairs }} + 1 ):
130-
img1_product_name = product_names[r]
131-
img2_product_name = product_names[r+s]
132-
shortname = f'{img1_product_name[11:19]}_{img2_product_name[11:19]}'
133-
pairs.append({'img1_product_name': img1_product_name, 'img2_product_name': img2_product_name, 'name':shortname})
134-
matrixJSON = f'{{"include":{json.dumps(pairs)}}}'
135-
print(f'number of image pairs: {len(pairs)}')
136-
137-
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
138-
print(f'IMAGE_DATES={product_names}', file=f)
139-
print(f'MATRIX_PARAMS_COMBINATIONS={matrixJSON}', file=f)
140-
71+
python glacier_image_correlation/s2_search.py ${{ inputs.cloud_cover }} ${{ inputs.start_month }} ${{ inputs.stop_month }} ${{ inputs.npairs }}
14172
14273
# A matrix job that calls a reuseable workflow
14374
autoRIFT:

0 commit comments

Comments
 (0)