@@ -65,79 +65,10 @@ jobs:
65
65
cache-environment : true
66
66
environment-file : glacier_image_correlation/environment.yml
67
67
68
- # https://words.yuvi.in/post/python-in-github-actions/
69
68
- name : Search aws for S2 imagery
70
69
id : S2_search
71
- shell : bash -el -c "python -u {0}"
72
70
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 }}
141
72
142
73
# A matrix job that calls a reuseable workflow
143
74
autoRIFT :
0 commit comments