Skip to content

Commit af054f3

Browse files
authored
Merge pull request #5 from mike-gangl/main
Integrate changes for compatibility with the modular OGC compliant application packaging
2 parents d96ab1d + 8ba8859 commit af054f3

File tree

8 files changed

+333
-23
lines changed

8 files changed

+333
-23
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ The `process.ipynb` notebook file is designed to work either as an independent n
4343

4444
Unity OGC applications rely upon using [Papermill parameritzation](https://papermill.readthedocs.io/en/latest/usage-parameterize.html) of arguments. One of the cells is tagged with the `parameters` tag, indicating to Papermill which cell to inspect for insertion of values from the command line. See the [app-pack-generator](https://github.com/unity-sds/app-pack-generator) for more information on the formatting of parameters and the use of type hints.
4545

46+
### OGC Run
47+
to run this without the stage-in or out parameters, simply call the process.cwl contained in this repo:
48+
49+
```
50+
# run stage in
51+
52+
cwltool --outdir stage_in --copy-output stage_in.cwl test/ogc_app_package/stage_in.yml
53+
54+
#For my run, it ended up in a directory called z7ai3uj8
55+
56+
# For now, the current stage_in creates an invalid 'root' in catalog.json. you'll need to set the root from /<someting>/catalog.json to catalog.json
57+
vim z7ai3uj8/catalog.json
58+
59+
# Pass that as the directory into the process.py runs
60+
cwltool process.cwl --example_argument_empty '' --input z7ai3uj8/ --output_collection <mycollection>
61+
62+
#The output files and catalog.json from this run were stored in 02kajdto
63+
64+
#run stageout
65+
cwltool stage_out.cwl --output_dir 02kajdto/ --staging_bucket <mybucket>
66+
67+
```
68+
4669
### stage-in
4770

4871
This notebook is connected to a Unity stage-in process through the `input_stac_collection_file` variable. This variable contains the location of a STAC feature collection file. That feature collection points to the input files used by the notebook. In our example notebook we use Unity-py to parse the file and obtain the full paths to the input files.
@@ -67,4 +90,4 @@ See our [releases page](https://github.com/unity-sds/unity-example-application/r
6790

6891
## License
6992

70-
See our: [LICENSE](LICENSE.txt)
93+
See our: [LICENSE](LICENSE.txt)

process.cwl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env cwl-runner
2+
arguments:
3+
- -p
4+
- input
5+
- $(inputs.input.path)
6+
- -p
7+
- output
8+
- $(runtime.outdir)
9+
baseCommand:
10+
- papermill
11+
- /home/jovyan/process.ipynb
12+
- --cwd
13+
- /home/jovyan
14+
- "process_out.ipynb"
15+
- -f
16+
- /tmp/inputs.json
17+
- -k
18+
- python3
19+
- --log-output
20+
class: CommandLineTool
21+
cwlVersion: v1.2
22+
inputs:
23+
input: Directory
24+
example_argument_bool:
25+
default: true
26+
type: boolean
27+
example_argument_empty:
28+
default: null
29+
type: string
30+
example_argument_float:
31+
default: 1.0
32+
type: float
33+
example_argument_int:
34+
default: 1
35+
type: int
36+
example_argument_string:
37+
default: string
38+
type: string
39+
output_collection:
40+
default: example-app-collection___1
41+
type: string
42+
summary_table_filename:
43+
default: summary_table.txt
44+
type: string
45+
outputs:
46+
output:
47+
outputBinding:
48+
glob: $(runtime.outdir)
49+
type: Directory
50+
requirements:
51+
DockerRequirement:
52+
dockerPull: gangl/unity-ogc-example-application:174ee35b
53+
InitialWorkDirRequirement:
54+
listing:
55+
- entry: $(inputs)
56+
entryname: /tmp/inputs.json
57+
InlineJavascriptRequirement: {}
58+
InplaceUpdateRequirement:
59+
inplaceUpdate: true
60+
NetworkAccess:
61+
networkAccess: true
62+
ShellCommandRequirement: {}

process.ipynb

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,36 @@
2323
"from unity_sds_client.resources.data_file import DataFile"
2424
]
2525
},
26+
{
27+
"cell_type": "markdown",
28+
"id": "5cb70c6e-a08b-49c4-bbef-13200a18bfda",
29+
"metadata": {},
30+
"source": [
31+
"## Parameters Cell\n",
32+
"\n",
33+
"The below cell is tagged as a 'paramter' cell. This enables us to overwrite the below values at runtime. There are some special values in the below cell.\n",
34+
"\n",
35+
"* `input` is a special name, and it also has the `# type: stage-in` annotation. This should be a directory, and at run time it will be populated with a STAC catalog that contains files that have been staged for your algorithm to reference.\n",
36+
"* `output` is a special name, and it also has the `# type: stage-out` annotation. This should be treated as a directory to which you write ALL of your output files along with a STAC catalog that references files you would like to persist outside of the algorithm run."
37+
]
38+
},
2639
{
2740
"cell_type": "code",
2841
"execution_count": 2,
2942
"id": "04ac7f2d",
3043
"metadata": {
44+
"editable": true,
45+
"slideshow": {
46+
"slide_type": ""
47+
},
3148
"tags": [
3249
"parameters"
3350
]
3451
},
3552
"outputs": [],
3653
"source": [
37-
"input_stac_collection_file = 'test/stage_in/stage_in_results.json' # type: stage-in\n",
38-
"output_stac_catalog_dir = 'test/process_results/' # type: stage-out\n",
54+
"input = 'test/stage_in/' # type: stage-in\n",
55+
"output = 'test/process_results/' # type: stage-out\n",
3956
"\n",
4057
"# Filename written to the working directory\n",
4158
"summary_table_filename = \"summary_table.txt\"\n",
@@ -51,6 +68,25 @@
5168
"example_argument_empty = None # type: string Allow a null value or a string\n"
5269
]
5370
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 8,
74+
"id": "62471f5d-d898-46c1-89c1-b572851db551",
75+
"metadata": {},
76+
"outputs": [
77+
{
78+
"name": "stdout",
79+
"output_type": "stream",
80+
"text": [
81+
"reading test/stage_in/catalog.json\n"
82+
]
83+
}
84+
],
85+
"source": [
86+
"input_catalog = os.path.join(input, \"catalog.json\")\n",
87+
"print(\"reading {}\".format(input_catalog))"
88+
]
89+
},
5490
{
5591
"cell_type": "markdown",
5692
"id": "7926d21b",
@@ -63,7 +99,7 @@
6399
},
64100
{
65101
"cell_type": "code",
66-
"execution_count": 3,
102+
"execution_count": 10,
67103
"id": "2eeaa5d4",
68104
"metadata": {},
69105
"outputs": [
@@ -87,7 +123,7 @@
87123
"'<table>\\n<thead>\\n<tr><th>argument_name </th><th>type </th><th>value </th></tr>\\n</thead>\\n<tbody>\\n<tr><td>example_argument_int </td><td>&lt;class &#x27;int&#x27;&gt; </td><td>1 </td></tr>\\n<tr><td>example_argument_float </td><td>&lt;class &#x27;float&#x27;&gt; </td><td>1.0 </td></tr>\\n<tr><td>example_argument_string</td><td>&lt;class &#x27;str&#x27;&gt; </td><td>string </td></tr>\\n<tr><td>example_argument_bool </td><td>&lt;class &#x27;bool&#x27;&gt; </td><td>True </td></tr>\\n<tr><td>example_argument_empty </td><td>&lt;class &#x27;NoneType&#x27;&gt;</td><td> </td></tr>\\n</tbody>\\n</table>'"
88124
]
89125
},
90-
"execution_count": 3,
126+
"execution_count": 10,
91127
"metadata": {},
92128
"output_type": "execute_result"
93129
}
@@ -122,24 +158,24 @@
122158
},
123159
{
124160
"cell_type": "code",
125-
"execution_count": 4,
161+
"execution_count": 11,
126162
"id": "3a09d57c",
127163
"metadata": {},
128164
"outputs": [
129165
{
130166
"data": {
131167
"text/plain": [
132-
"['/home/jovyan/unity-example-application/test/stage_in/./SNDR.SS1330.CHIRP.20160822T0005.m06.g001.L1_AQ.std.v02_48.G.200425095850.nc',\n",
133-
" '/home/jovyan/unity-example-application/test/stage_in/./SNDR.SS1330.CHIRP.20160822T0011.m06.g002.L1_AQ.std.v02_48.G.200425095901.nc']"
168+
"['/Users/gangl/dev/unity/unity-OGC-example-application/test/stage_in/./SNDR.SS1330.CHIRP.20160822T0005.m06.g001.L1_AQ.std.v02_48.G.200425095850.nc',\n",
169+
" '/Users/gangl/dev/unity/unity-OGC-example-application/test/stage_in/./SNDR.SS1330.CHIRP.20160822T0011.m06.g002.L1_AQ.std.v02_48.G.200425095901.nc']"
134170
]
135171
},
136-
"execution_count": 4,
172+
"execution_count": 11,
137173
"metadata": {},
138174
"output_type": "execute_result"
139175
}
140176
],
141177
"source": [
142-
"inp_collection = Collection.from_stac(input_stac_collection_file)\n",
178+
"inp_collection = Collection.from_stac(input_catalog)\n",
143179
"data_filenames = inp_collection.data_locations()\n",
144180
"\n",
145181
"data_filenames"
@@ -157,7 +193,7 @@
157193
},
158194
{
159195
"cell_type": "code",
160-
"execution_count": 5,
196+
"execution_count": 12,
161197
"id": "9fbac209",
162198
"metadata": {},
163199
"outputs": [],
@@ -177,7 +213,7 @@
177213
},
178214
{
179215
"cell_type": "code",
180-
"execution_count": 6,
216+
"execution_count": 13,
181217
"id": "d22c8670",
182218
"metadata": {},
183219
"outputs": [],
@@ -194,7 +230,7 @@
194230
},
195231
{
196232
"cell_type": "code",
197-
"execution_count": 7,
233+
"execution_count": 14,
198234
"id": "3344bd15",
199235
"metadata": {},
200236
"outputs": [
@@ -215,7 +251,7 @@
215251
"'<table>\\n<thead>\\n<tr><th>product_name </th><th>product_name_type_id </th><th>shortname </th><th>product_version </th><th>date_created </th><th>time_coverage_start </th><th>time_coverage_end </th><th style=\"text-align: right;\"> geospatial_lat_mid</th><th style=\"text-align: right;\"> geospatial_lon_mid</th></tr>\\n</thead>\\n<tbody>\\n<tr><td>SNDR.SS1330.CHIRP.20160822T0005.m06.g001.L1_AQ.std.v02_48.G.200425095850.nc</td><td>L1_AQ </td><td>SNDR13CHRP1</td><td>v02.48.00 </td><td>2021-04-25T05:59:08Z</td><td>2016-08-22T00:05:22Z </td><td>2016-08-22T00:11:22Z</td><td style=\"text-align: right;\"> -48.6062</td><td style=\"text-align: right;\"> 12.4563 </td></tr>\\n<tr><td>SNDR.SS1330.CHIRP.20160822T0011.m06.g002.L1_AQ.std.v02_48.G.200425095901.nc</td><td>L1_AQ </td><td>SNDR13CHRP1</td><td>v02.48.00 </td><td>2021-04-25T05:59:19Z</td><td>2016-08-22T00:11:22Z </td><td>2016-08-22T00:17:22Z</td><td style=\"text-align: right;\"> -69.3979</td><td style=\"text-align: right;\"> -1.98753</td></tr>\\n</tbody>\\n</table>'"
216252
]
217253
},
218-
"execution_count": 7,
254+
"execution_count": 14,
219255
"metadata": {},
220256
"output_type": "execute_result"
221257
}
@@ -227,14 +263,14 @@
227263
},
228264
{
229265
"cell_type": "code",
230-
"execution_count": 8,
266+
"execution_count": 16,
231267
"id": "014257f3",
232268
"metadata": {},
233269
"outputs": [],
234270
"source": [
235271
"# Write the table in text format\n",
236-
"pathlib.Path(output_stac_catalog_dir).mkdir(parents=True, exist_ok=True)\n",
237-
"output_filename = os.path.join(output_stac_catalog_dir, summary_table_filename)\n",
272+
"pathlib.Path(output).mkdir(parents=True, exist_ok=True)\n",
273+
"output_filename = os.path.join(output, summary_table_filename)\n",
238274
"with open(output_filename, \"w\") as summary_file:\n",
239275
" summary_file.write(tabulate(table_data, headers=column_names))"
240276
]
@@ -249,9 +285,15 @@
249285
},
250286
{
251287
"cell_type": "code",
252-
"execution_count": 9,
288+
"execution_count": 18,
253289
"id": "b4aa5d3b",
254-
"metadata": {},
290+
"metadata": {
291+
"editable": true,
292+
"slideshow": {
293+
"slide_type": ""
294+
},
295+
"tags": []
296+
},
255297
"outputs": [],
256298
"source": [
257299
"# Create a collection\n",
@@ -270,14 +312,14 @@
270312
"dataset.add_data_file(DataFile(\"csv\", summary_table_filename, [\"data\"]))\n",
271313
"\n",
272314
"#when we run \"to_stac\" below, this file will be generated. this needs to be added to the stac file itself for future reference.\n",
273-
"dataset.add_data_file(DataFile(\"json\", output_stac_catalog_dir + \"/\" + summary_table_filename +'.json', [\"metadata\"] ))\n",
315+
"dataset.add_data_file(DataFile(\"json\", output + \"/\" + summary_table_filename +'.json', [\"metadata\"] ))\n",
274316
"\n",
275317
"\n",
276318
"# Add the dataset to the collection\n",
277319
"#out_collection.add_dataset(dataset)\n",
278320
"out_collection._datasets.append(dataset)\n",
279321
"\n",
280-
"Collection.to_stac(out_collection, output_stac_catalog_dir)"
322+
"Collection.to_stac(out_collection, output)"
281323
]
282324
},
283325
{
@@ -306,7 +348,7 @@
306348
"name": "python",
307349
"nbconvert_exporter": "python",
308350
"pygments_lexer": "ipython3",
309-
"version": "3.8.18"
351+
"version": "3.10.8"
310352
}
311353
},
312354
"nbformat": 4,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
papermill
2-
unity-sds-client==0.3.0
2+
unity-sds-client==0.6.1
33
netCDF4
44
tabulate

0 commit comments

Comments
 (0)