|
7 | 7 | "metadata": {},
|
8 | 8 | "outputs": [],
|
9 | 9 | "source": [
|
| 10 | + "import os\n", |
| 11 | + "\n", |
10 | 12 | "# Application packages\n",
|
11 | 13 | "from tabulate import tabulate\n",
|
12 | 14 | "import netCDF4\n",
|
|
15 | 17 | "from unity_py.resources.collection import Collection\n",
|
16 | 18 | "\n",
|
17 | 19 | "# stage_out packages\n",
|
18 |
| - "import os\n", |
19 |
| - "import json\n", |
20 | 20 | "from datetime import datetime, timezone\n",
|
21 |
| - "from pystac import ItemCollection, Item, Asset" |
| 21 | + "from unity_py.resources.dataset import Dataset\n", |
| 22 | + "from unity_py.resources.data_file import DataFile" |
22 | 23 | ]
|
23 | 24 | },
|
24 | 25 | {
|
|
32 | 33 | },
|
33 | 34 | "outputs": [],
|
34 | 35 | "source": [
|
35 |
| - "input_stac_collection = 'test/stage_in/stage_in_results.json' # type: stage-in\n", |
36 |
| - "output_stac_collection = 'process_results.json' # type: stage-out\n", |
| 36 | + "input_stac_collection_file = 'test/stage_in/stage_in_results.json' # type: stage-in\n", |
| 37 | + "output_stac_catalog_dir = 'process_results/' # type: stage-out\n", |
37 | 38 | "\n",
|
38 | 39 | "# Filename written to the working directory\n",
|
39 | 40 | "summary_table_filename = \"summary_table.txt\"\n",
|
|
120 | 121 | "execution_count": 4,
|
121 | 122 | "id": "3a09d57c",
|
122 | 123 | "metadata": {},
|
123 |
| - "outputs": [], |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "data": { |
| 127 | + "text/plain": [ |
| 128 | + "['./SNDR.SS1330.CHIRP.20160822T0005.m06.g001.L1_AQ.std.v02_48.G.200425095850.nc',\n", |
| 129 | + " './SNDR.SS1330.CHIRP.20160822T0011.m06.g002.L1_AQ.std.v02_48.G.200425095901.nc']" |
| 130 | + ] |
| 131 | + }, |
| 132 | + "execution_count": 4, |
| 133 | + "metadata": {}, |
| 134 | + "output_type": "execute_result" |
| 135 | + } |
| 136 | + ], |
| 137 | + "source": [ |
| 138 | + "inp_collection = Collection.from_stac(input_stac_collection_file)\n", |
| 139 | + "data_filenames = inp_collection.data_locations()\n", |
| 140 | + "\n", |
| 141 | + "data_filenames" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "cell_type": "code", |
| 146 | + "execution_count": 5, |
| 147 | + "id": "0671dfaf", |
| 148 | + "metadata": {}, |
| 149 | + "outputs": [ |
| 150 | + { |
| 151 | + "data": { |
| 152 | + "text/plain": [ |
| 153 | + "['/home/mcduffie/Devel/unity/unity-example-application/test/stage_in/SNDR.SS1330.CHIRP.20160822T0005.m06.g001.L1_AQ.std.v02_48.G.200425095850.nc',\n", |
| 154 | + " '/home/mcduffie/Devel/unity/unity-example-application/test/stage_in/SNDR.SS1330.CHIRP.20160822T0011.m06.g002.L1_AQ.std.v02_48.G.200425095901.nc']" |
| 155 | + ] |
| 156 | + }, |
| 157 | + "execution_count": 5, |
| 158 | + "metadata": {}, |
| 159 | + "output_type": "execute_result" |
| 160 | + } |
| 161 | + ], |
124 | 162 | "source": [
|
125 |
| - "inp_collection = Collection.from_stac(input_stac_collection)\n", |
126 |
| - "data_filenames = inp_collection.data_locations()" |
| 163 | + "# Manually locate the full path of the files to match location of collection file\n", |
| 164 | + "import contextlib\n", |
| 165 | + "old_cwd = os.path.realpath(os.curdir)\n", |
| 166 | + "os.chdir(os.path.dirname(input_stac_collection_file))\n", |
| 167 | + "data_filenames = [ os.path.realpath(fn) for fn in data_filenames ]\n", |
| 168 | + "os.chdir(old_cwd)\n", |
| 169 | + " \n", |
| 170 | + "data_filenames" |
127 | 171 | ]
|
128 | 172 | },
|
129 | 173 | {
|
|
138 | 182 | },
|
139 | 183 | {
|
140 | 184 | "cell_type": "code",
|
141 |
| - "execution_count": 5, |
| 185 | + "execution_count": 6, |
142 | 186 | "id": "9fbac209",
|
143 | 187 | "metadata": {},
|
144 | 188 | "outputs": [],
|
|
158 | 202 | },
|
159 | 203 | {
|
160 | 204 | "cell_type": "code",
|
161 |
| - "execution_count": 6, |
| 205 | + "execution_count": 7, |
162 | 206 | "id": "d22c8670",
|
163 | 207 | "metadata": {},
|
164 | 208 | "outputs": [],
|
|
175 | 219 | },
|
176 | 220 | {
|
177 | 221 | "cell_type": "code",
|
178 |
| - "execution_count": 7, |
| 222 | + "execution_count": 8, |
179 | 223 | "id": "3344bd15",
|
180 | 224 | "metadata": {},
|
181 | 225 | "outputs": [
|
|
196 | 240 | "'<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>'"
|
197 | 241 | ]
|
198 | 242 | },
|
199 |
| - "execution_count": 7, |
| 243 | + "execution_count": 8, |
200 | 244 | "metadata": {},
|
201 | 245 | "output_type": "execute_result"
|
202 | 246 | }
|
|
208 | 252 | },
|
209 | 253 | {
|
210 | 254 | "cell_type": "code",
|
211 |
| - "execution_count": 8, |
| 255 | + "execution_count": 9, |
212 | 256 | "id": "014257f3",
|
213 | 257 | "metadata": {},
|
214 | 258 | "outputs": [],
|
215 | 259 | "source": [
|
216 | 260 | "# Write the table in text format\n",
|
217 |
| - "with open(summary_table_filename, \"w\") as summary_file:\n", |
| 261 | + "output_filename = os.path.join(output_stac_catalog_dir, summary_table_filename)\n", |
| 262 | + "with open(output_filename, \"w\") as summary_file:\n", |
218 | 263 | " summary_file.write(tabulate(table_data, headers=column_names))"
|
219 | 264 | ]
|
220 | 265 | },
|
|
223 | 268 | "id": "89224c4e",
|
224 | 269 | "metadata": {},
|
225 | 270 | "source": [
|
226 |
| - "# Create stage-out item collection" |
| 271 | + "# Create stage-out item catalog" |
227 | 272 | ]
|
228 | 273 | },
|
229 | 274 | {
|
230 | 275 | "cell_type": "code",
|
231 |
| - "execution_count": 9, |
232 |
| - "id": "1029f88c", |
| 276 | + "execution_count": 10, |
| 277 | + "id": "b4aa5d3b", |
233 | 278 | "metadata": {},
|
234 | 279 | "outputs": [],
|
235 | 280 | "source": [
|
236 |
| - "output_item = Item(\n", |
237 |
| - " id=os.path.splitext(summary_table_filename)[0],\n", |
238 |
| - " geometry=\"\",\n", |
239 |
| - " bbox=\"\",\n", |
240 |
| - " datetime=datetime.now(timezone.utc),\n", |
241 |
| - " properties={\n", |
242 |
| - " \"datetime\": datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),\n", |
243 |
| - " \"start_datetime\": datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),\n", |
244 |
| - " \"end_datetime\": datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),\n", |
245 |
| - " \"created\": datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),\n", |
246 |
| - " \"updated\": datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),\n", |
247 |
| - " },\n", |
248 |
| - " assets={\n", |
249 |
| - " \"data\": Asset(href=summary_table_filename,title=\"Main Data File\"),\n", |
250 |
| - " }\n", |
| 281 | + "# Create a collection\n", |
| 282 | + "out_collection = Collection(\"SNDR13CHRP1AQCal_rebin\")\n", |
| 283 | + " \n", |
| 284 | + "# Create a Dataset for the collection\n", |
| 285 | + "dataset = Dataset(\n", |
| 286 | + " name=os.path.splitext(summary_table_filename)[0], \n", |
| 287 | + " collection_id=out_collection.collection_id, \n", |
| 288 | + " start_time=datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(), \n", |
| 289 | + " end_time=datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(),\n", |
| 290 | + " creation_time=datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(),\n", |
251 | 291 | ")\n",
|
252 | 292 | "\n",
|
253 |
| - "output_collection = ItemCollection([output_item])" |
254 |
| - ] |
255 |
| - }, |
256 |
| - { |
257 |
| - "cell_type": "code", |
258 |
| - "execution_count": 10, |
259 |
| - "id": "504c9271", |
260 |
| - "metadata": {}, |
261 |
| - "outputs": [], |
262 |
| - "source": [ |
263 |
| - "with open(output_stac_collection, \"w\") as collection_file:\n", |
264 |
| - " json.dump(output_collection.to_dict(), collection_file)" |
| 293 | + "# Add output file(s) to the dataset\n", |
| 294 | + "dataset.add_data_file(DataFile(\"data\", summary_table_filename))\n", |
| 295 | + "\n", |
| 296 | + "# Add the dataset to the collection\n", |
| 297 | + "#out_collection.add_dataset(dataset)\n", |
| 298 | + "out_collection._datasets.append(dataset)\n", |
| 299 | + "\n", |
| 300 | + "Collection.to_stac(out_collection, output_stac_catalog_dir)" |
265 | 301 | ]
|
266 | 302 | }
|
267 | 303 | ],
|
|
0 commit comments