Skip to content

Commit c8813c7

Browse files
authored
Merge pull request #7 from unity-sds/optional_stage_inout
Update unity-example-application to reflect the 1.0.0 version of unity-app-generator
2 parents d96ab1d + e9948aa commit c8813c7

17 files changed

+156
-322
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ env/
77
# Jupyter temporary directory
88
.ipynb_checkpoints/
99

10-
# Output from process.ipynb
11-
summary_table.txt
12-
process_results.json
10+
# User created monolithic app job input file derived from template
11+
test/monolithic_app/cwl_job_input.yml
12+
13+
# Output from process.ipynb and test scripts
1314
test/process_results/
1415

1516
# Unity App Generator file

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)

execute_app_pack_gen.ipynb

Lines changed: 0 additions & 96 deletions
This file was deleted.

process.ipynb

Lines changed: 66 additions & 31 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_stac_catalog_dir` has the `# type: stage-in` annotation. This variable tells your algorithm the name of the directory where to read inputs from. At run time it will be populated with a STAC catalog and the files it references. The application generator process will connect your variable name to the special `input` parameter in automatically generated CWL files.\n",
36+
"* `output_stac_catalog_dir` has the `# type: stage-out` annotation. This is a directory where 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. The application generator process will connect your variable name to the special `output` parameter in automatically generated CWL files."
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_stac_catalog_dir = 'test/stage_in/' # type: stage-in\n",
55+
"output_stac_catalog_dir = '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": 3,
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_stac_catalog_dir, \"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": 4,
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": 4,
91127
"metadata": {},
92128
"output_type": "execute_result"
93129
}
@@ -122,27 +158,28 @@
122158
},
123159
{
124160
"cell_type": "code",
125-
"execution_count": 4,
161+
"execution_count": 5,
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+
"['test/stage_in/SNDR.SS1330.CHIRP.20160822T0005.m06.g001.L1_AQ.std.v02_48.G.200425095850.nc',\n",
169+
" '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": 5,
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",
145-
"data_filenames"
181+
"# Scrub base part of path so it is not displayed in Github with a home directory prefix\n",
182+
"[ os.path.relpath(fn, os.curdir) for fn in data_filenames ]"
146183
]
147184
},
148185
{
@@ -157,7 +194,7 @@
157194
},
158195
{
159196
"cell_type": "code",
160-
"execution_count": 5,
197+
"execution_count": 6,
161198
"id": "9fbac209",
162199
"metadata": {},
163200
"outputs": [],
@@ -177,7 +214,7 @@
177214
},
178215
{
179216
"cell_type": "code",
180-
"execution_count": 6,
217+
"execution_count": 7,
181218
"id": "d22c8670",
182219
"metadata": {},
183220
"outputs": [],
@@ -194,7 +231,7 @@
194231
},
195232
{
196233
"cell_type": "code",
197-
"execution_count": 7,
234+
"execution_count": 8,
198235
"id": "3344bd15",
199236
"metadata": {},
200237
"outputs": [
@@ -215,7 +252,7 @@
215252
"'<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>'"
216253
]
217254
},
218-
"execution_count": 7,
255+
"execution_count": 8,
219256
"metadata": {},
220257
"output_type": "execute_result"
221258
}
@@ -227,7 +264,7 @@
227264
},
228265
{
229266
"cell_type": "code",
230-
"execution_count": 8,
267+
"execution_count": 9,
231268
"id": "014257f3",
232269
"metadata": {},
233270
"outputs": [],
@@ -249,9 +286,15 @@
249286
},
250287
{
251288
"cell_type": "code",
252-
"execution_count": 9,
289+
"execution_count": 10,
253290
"id": "b4aa5d3b",
254-
"metadata": {},
291+
"metadata": {
292+
"editable": true,
293+
"slideshow": {
294+
"slide_type": ""
295+
},
296+
"tags": []
297+
},
255298
"outputs": [],
256299
"source": [
257300
"# Create a collection\n",
@@ -261,16 +304,16 @@
261304
"dataset = Dataset(\n",
262305
" name=summary_table_filename, \n",
263306
" collection_id=out_collection.collection_id, \n",
264-
" start_time=datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(), \n",
265-
" end_time=datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(),\n",
266-
" creation_time=datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(),\n",
307+
" start_time=datetime.now(timezone.utc).isoformat(), \n",
308+
" end_time=datetime.now(timezone.utc).isoformat(),\n",
309+
" creation_time=datetime.now(timezone.utc).isoformat(),\n",
267310
")\n",
268311
"\n",
269312
"# Add output file(s) to the dataset\n",
270313
"dataset.add_data_file(DataFile(\"csv\", summary_table_filename, [\"data\"]))\n",
271314
"\n",
272315
"#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",
316+
"dataset.add_data_file(DataFile(\"json\", os.path.join(output_stac_catalog_dir, summary_table_filename + '.json'), [\"metadata\"] ))\n",
274317
"\n",
275318
"\n",
276319
"# Add the dataset to the collection\n",
@@ -279,20 +322,12 @@
279322
"\n",
280323
"Collection.to_stac(out_collection, output_stac_catalog_dir)"
281324
]
282-
},
283-
{
284-
"cell_type": "code",
285-
"execution_count": null,
286-
"id": "14f240b6-b5ea-4bf8-8764-ecf12eee6c16",
287-
"metadata": {},
288-
"outputs": [],
289-
"source": []
290325
}
291326
],
292327
"metadata": {
293328
"celltoolbar": "Tags",
294329
"kernelspec": {
295-
"display_name": "Python 3 (ipykernel)",
330+
"display_name": "Python 3",
296331
"language": "python",
297332
"name": "python3"
298333
},
@@ -306,7 +341,7 @@
306341
"name": "python",
307342
"nbconvert_exporter": "python",
308343
"pygments_lexer": "ipython3",
309-
"version": "3.8.18"
344+
"version": "3.12.4"
310345
}
311346
},
312347
"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)