From 68180cfe91cc2f2a7f1853b5d9c32909aaceb0a9 Mon Sep 17 00:00:00 2001 From: zoewalschots Date: Tue, 11 Jul 2023 17:12:04 +0000 Subject: [PATCH] Update earthaccess commands Simplify earthaccess commands --- notebooks/datasets/OPERA_GIS_Cloud.ipynb | 194 ++++------------------- 1 file changed, 30 insertions(+), 164 deletions(-) diff --git a/notebooks/datasets/OPERA_GIS_Cloud.ipynb b/notebooks/datasets/OPERA_GIS_Cloud.ipynb index a78f8deb..5e641653 100644 --- a/notebooks/datasets/OPERA_GIS_Cloud.ipynb +++ b/notebooks/datasets/OPERA_GIS_Cloud.ipynb @@ -128,7 +128,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "93198552-2adc-4655-9d98-6222c7d0dfc1", + "id": "ef23e34a-a414-489d-8136-87532d1744e5", "metadata": { "tags": [] }, @@ -137,90 +137,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Granule hits: 50\n" + "Granules found: 50\n" ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ - "Query = DataGranules().concept_id(\"C2617126679-POCLOUD\").bounding_box(-111.144811,36.980121,-110.250799,37.915625).temporal(\"2023-04-11T00:00:00\",\"2023-05-02T23:59:59\")\n", - "print(f\"Granule hits: {Query.hits()}\")\n", - "cloud_granules = Query.get()\n", - "# is this a cloud hosted data granule?\n", - "cloud_granules[0].cloud_hosted" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "f4b73d49-05cb-486a-a3ed-f22f6a76d817", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - " \n", - "
\n", - "
\n", - " \n", - "
\n", - " " - ], - "text/plain": [ - "Collection: {'Version': '1.0', 'ShortName': 'OPERA_L3_DSWX-HLS_PROVISIONAL_V1'}\n", - "Spatial coverage: {'HorizontalSpatialDomain': {'Geometry': {'BoundingRectangles': [{'WestBoundingCoordinate': -111, 'SouthBoundingCoordinate': 37.04, 'EastBoundingCoordinate': -109.749, 'NorthBoundingCoordinate': 38.036}]}}}\n", - "Temporal coverage: {'RangeDateTime': {'EndingDateTime': '2023-04-11T18:02:22.780Z', 'BeginningDateTime': '2023-04-11T18:02:22.780Z'}}\n", - "Size(MB): 0\n", - "Data: ['https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B01_WTR.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B02_BWTR.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B03_CONF.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B04_DIAG.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B05_WTR-1.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B06_WTR-2.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B07_LAND.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B08_SHAD.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B09_CLOUD.tif', 'https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B10_DEM.tif']" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Let's pretty print this\n", - "cloud_granules[0]" + "#search for the granules using the short name\n", + "opera_results = earthaccess.search_data(short_name=\"OPERA_L3_DSWX-HLS_PROVISIONAL_V1\", temporal= (\"2023-04-11T00:00:00\",\"2023-05-02T23:59:59\"), bounding_box = ('-111.144811','36.980121','-110.250799','37.915625'))" ] }, { @@ -237,41 +160,7 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "b84de729-ab41-4361-8bf2-b71d8c4d0fbd", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "['s3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B01_WTR.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B02_BWTR.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B03_CONF.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B04_DIAG.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B05_WTR-1.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B06_WTR-2.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B07_LAND.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B08_SHAD.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B09_CLOUD.tif',\n", - " 's3://podaac-ops-cumulus-protected/OPERA_L3_DSWX-HLS_PROVISIONAL_V1/OPERA_L3_DSWx-HLS_T12SWG_20230411T180222Z_20230414T030954Z_L8_30_v1.0_B10_DEM.tif']" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#extract S3 bucket links\n", - "data_links = [g.data_links(access=\"direct\") for g in cloud_granules]\n", - "data_links[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "id": "e2b72f1b-d940-4156-92fb-8c0f444edebf", "metadata": { "tags": [] @@ -281,48 +170,25 @@ "name": "stdout", "output_type": "stream", "text": [ - "8\n" + "4\n", + "4\n" ] } ], "source": [ - "#add the S3 bucket links to a list, here we are looking for B01_WTR layer and two dates specified earlier\n", - "s3 = []\n", - "for r in data_links:\n", - " for l in r:\n", + "#add the S3 bucket links to lists, here we are looking for B01_WTR layer and two dates specified earlier\n", + "april = []\n", + "may = []\n", + "for g in opera_results:\n", + " for l in earthaccess.results.DataGranule.data_links(g, access='direct'):\n", " if 'B01_WTR' in l: \n", " if '20230411' in l:\n", - " s3.append(l)\n", + " april.append(l)\n", " if '20230502' in l:\n", - " s3.append(l)\n", + " may.append(l)\n", "\n", - "print(len(s3))" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "6f367209-2e51-4fd1-bf8e-8527d525635b", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "april = []\n", - "may = []\n", - "for s in s3:\n", - " if '20230411' in s:\n", - " april.append(s)\n", - " if '20230502' in s:\n", - " may.append(s)" - ] - }, - { - "cell_type": "markdown", - "id": "639e73a1-af07-4a6e-89de-67e64bdf99a9", - "metadata": {}, - "source": [ - "Since we are looking at two seperate times, we can create two lists, one for each date, which will be used to mosaic based on its respective time range later." + "print(len(april))\n", + "print(len(may))" ] }, { @@ -337,19 +203,19 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "ceee4f0f-c810-4165-b1b6-a98dc7820ad6", "metadata": { "tags": [] }, "outputs": [], "source": [ - "s3_url = s3[2]" + "s3_url = april[2]" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "id": "4d4c2838-8624-4bbe-9cda-d54f6098a1fa", "metadata": { "tags": [] @@ -361,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "1fef7206-2ead-4946-8bd5-ceb3d75d0ec3", "metadata": { "tags": [] @@ -370,10 +236,10 @@ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 11, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -395,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "id": "753c832e-6be5-4c49-b4f3-2b1cb03d7836", "metadata": { "tags": [] @@ -410,7 +276,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "id": "7c862b33-6c47-4ac6-8e56-b79b8e0e4227", "metadata": { "tags": [] @@ -457,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "id": "07f58c9d-3879-4424-9f53-08199dd23f28", "metadata": { "tags": [] @@ -486,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "ea887821-ee97-4c08-ada4-3c6d4defe788", "metadata": { "tags": [] @@ -510,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "id": "dc1bd1bb-f6ea-4707-a717-e9a2998c00a4", "metadata": { "tags": [] @@ -524,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "id": "4e4fdefd-51c3-4d56-a3ce-6db0283d9d6f", "metadata": { "tags": [] @@ -538,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "id": "fc50b63d-f4b8-400e-99c3-b8ff334d70f6", "metadata": { "tags": [] @@ -600,7 +466,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 16, "id": "a55e49b2-5a30-4024-b448-9f4804802b26", "metadata": { "tags": []