-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from podaac/edshred2000-patch-2
MCC API
- Loading branch information
Showing
1 changed file
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# MCC - API POST\n", | ||
"\n", | ||
"Template for making API calls to Metadata Compliance Checker (MCC) using a local netCDF or HDF file, and outputing the response to JSON" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## MCC Endpoints\n", | ||
"\n", | ||
"PROD - https://mcc.podaac.earthdatacloud.nasa.gov/\n", | ||
"\n", | ||
"UAT - https://mcc.podaac.uat.earthdatacloud.nasa.gov/mcc\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import json\n", | ||
"import requests\n", | ||
"import sys\n", | ||
"\n", | ||
"# Choose VENUE: UAT or PROD\n", | ||
"mcc_env = 'UAT'\n", | ||
"mcc_env = 'PROD'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## MCC Dictionary - Environments\n", | ||
"\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"tags": [ | ||
"parameters" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"url_dict = {\n", | ||
" 'UAT': \"https://mcc.podaac.uat.earthdatacloud.nasa.gov/mcc\",\n", | ||
" 'PROD': \"https://mcc.podaac.earthdatacloud.nasa.gov/\"\n", | ||
"}\n", | ||
"\n", | ||
"mcc_host = url_dict.get(mcc_env)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Print\n", | ||
"print(mcc_env, \" - \" , mcc_host)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## MCC - API POST query example (for a local file)\n", | ||
"\n", | ||
"**See https://mcc.podaac.earthdatacloud.nasa.gov/mcc/about_api for a description of the query parameters (accessed via payload{} dictionary in this example)**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"url = mcc_host + \"/check\"\n", | ||
"\n", | ||
"payload = {\n", | ||
"'ACDD':'on',\n", | ||
"'ACDD-version':'1.3',\n", | ||
"'CF':'on',\n", | ||
"'CF-version':'1.7',\n", | ||
"'response':'json',\n", | ||
"}\n", | ||
"\n", | ||
"\n", | ||
"# set the path and filename to upload to MCC\n", | ||
"dirname = \"my_local_path_to_the_file\"\n", | ||
"filename = \"myFile.nc\"\n", | ||
"\n", | ||
"# working examples . . . comment out, modify or remove these two lines as needed\n", | ||
"dirname = \"./data/\"\n", | ||
"filename = \"ascat_20210101_000900_metopa_73696_eps_o_coa_3202_ovw.l2.nc\"\n", | ||
"\n", | ||
"\n", | ||
"files=[\n", | ||
" ('file-upload',\n", | ||
" (\n", | ||
" filename, \n", | ||
" open(dirname+filename,'rb'),'application/octet-stream'\n", | ||
"\n", | ||
" )\n", | ||
" )\n", | ||
"]\n", | ||
"\n", | ||
"headers = {}\n", | ||
"\n", | ||
"# Ping the API; format the response in json; pretty print the json response\n", | ||
"response = requests.request(\"POST\", url, headers=headers, data=payload, files=files)\n", | ||
"json_resp = json.loads(response.text)\n", | ||
"json_resp_formatted = json.dumps(json_resp, indent=2)\n", | ||
"print(json_resp_formatted)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"celltoolbar": "Tags", | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.19" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |