Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCC API #233

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions mcc_api/metadata_compliance_checker_API.ipynb
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
}