Skip to content

Instantly share code, notes, and snippets.

@thareUSGS
Created November 18, 2018 18:30
Show Gist options
  • Save thareUSGS/ce936092699009da8f1f1e0247917013 to your computer and use it in GitHub Desktop.
Save thareUSGS/ce936092699009da8f1f1e0247917013 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initial testing for conversion from SocetSet Keywords to new JSON-based ISD\n",
"### ISD Schema testing below"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import plio\n",
"from plio.io.io_bae import socetset_keywords_to_dict as kd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load old SocetSet keywords.lis into a Python dictionary using PLIO (io_bae function)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"dict = kd(\"J03_045994_1986_XN_18N282W.cal.pgm_usgs_meta_data.txt\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"RECTIFICATION_TERMS [8704.0, 0.0, 1.0, 2500.0, 1.0, 0.0]\n",
"GROUND_ZERO [0.32260958274121, 1.3567653952042, 0.0]\n",
"LOAD_PT [0.32260958274121, 1.3567653952042, 0.0]\n",
"COORD_SYSTEM 1.0\n",
"IMAGE_MOTION 0.0\n",
"SENSOR_TYPE USGSAstroLineScanner\n",
"SENSOR_MODE UNKNOWN\n",
"SEMI_MAJOR_AXIS 3396190.0\n",
"ECCENTRICITY /\n",
"FOCAL 354.615781793\n",
"ATMCO [0.0, 0.0, 0.0, 0.0]\n",
"IOCOEF_LINE [8704.0, 133.35563789538, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
"IOCOEF_SAMPLE [2500.0, 0.0, 142.85714285714, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
"ABERR 0.0\n",
"ATMREF 0.0\n",
"PLATFORM 1.0\n",
"SOURCE_FLAG 1.0\n",
"SINGLE_EPHEMERIDE 0.0\n",
"TRI_PARAMETERS [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 354.615781793, 0.0, 0.0]\n",
"T_CENTER 0.0\n",
"DT_EPHEM 0.03753446686245939\n",
"T0_EPHEM -17.040647955556565\n",
"NUMBER_OF_EPHEM 909.0\n"
]
}
],
"source": [
"for key in dict.keys():\n",
" #stop short. Just list top part of file\n",
" if (key == \"EPHEM_PTS\"):\n",
" break\n",
" print(key, dict[key])"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"#helper prettyprint function\n",
"def pp_json(json_thing, sort=False, indents=2):\n",
" if type(json_thing) is str:\n",
" print(json.dumps(json.loads(json_thing), sort_keys=sort, indent=indents))\n",
" else:\n",
" print(json.dumps(json_thing, sort_keys=sort, indent=indents))\n",
" return None"
]
},
{
"cell_type": "code",
"execution_count": 139,
"metadata": {},
"outputs": [],
"source": [
"#simple loop to take a list and make a ararry of 3 value arrays: [[1,2,3],[4,5,6]]\n",
"def list_to_array_n(my_list,n):\n",
" arr = []\n",
" length = len(my_list)\n",
" #if (length % n != 0):\n",
" # print(\"Warning: array is unbalanced: \" + str(length / n))\n",
" #else:\n",
" # print(\"Passed: array is balanced: \" + str(length / n))\n",
" for i in range(0,length,n):\n",
" temparr = []\n",
" for j in range(0,n):\n",
" temparr.append(my_list[i+j])\n",
" arr.append(temparr)\n",
" return arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Write out new ISD format as a Python dictionary, then JSON"
]
},
{
"cell_type": "code",
"execution_count": 223,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"#Map keywords.lis file to new ISD format and keywords\n",
"new = {}\n",
"\n",
"if dict['SENSOR_TYPE'] == \"USGSAstroLineScanner\":\n",
" new['name_model'] = \"USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL\"\n",
"else:\n",
" new['name_model'] = \"USGS_ASTRO_FRAME_SENSOR_MODEL\"\n",
"\n",
"if dict['IKCODE'] == -74021:\n",
" new['name_platform'] = \"MRO\"\n",
" new['name_sensor'] = \"MRO_CTX\"\n",
"else:\n",
" print(\"Need IKCODE\")\n",
" \n",
"new['center_ephemeris_time'] = dict['CENTER_EPHEMERIS_TIME']\n",
"new['starting_ephemeris_time'] = dict['STARTING_EPHEMERIS_TIME']\n",
"\n",
"lineScan1x3 = []\n",
"lineScan1x3.append([1,dict['T0_EPHEM'],0])\n",
"new['line_scan_rate'] = lineScan1x3\n",
"new['detector_sample_summing'] = dict['DETECTOR_SAMPLE_SUMMING']\n",
"new['detector_line_summing'] = 1\n",
"new['t0_ephemeris'] = dict['T0_EPHEM']\n",
"new['dt_ephemeris'] = dict['DT_EPHEM']\n",
"new['t0_quaternion'] = dict['T0_QUAT']\n",
"new['dt_quaternion'] = dict['DT_QUAT']\n",
"new['focal2pixel_lines'] = dict['ITRANSL']\n",
"new['focal2pixel_samples'] = dict['ITRANSS']\n",
"new['focal_length_model'] = {'focal_length':dict['FOCAL']}\n",
"#need to check focal_epsilon\n",
"#new['focal_length_model'] = {'focal_length':dict['FOCAL'],\n",
"# 'focal_epsilon':dict['']}\n",
"\n",
"new['image_lines'] = dict['TOTAL_LINES']\n",
"new['image_samples'] = dict['TOTAL_SAMPLES']\n",
"new['detector_center'] = {'line':dict['DETECTOR_LINE_ORIGIN'],\n",
" 'sample':dict['DETECTOR_SAMPLE_ORIGIN']}\n",
"new['interpolation_method'] = \"lagrange\"\n",
"new['optical_distortion'] = {\"radial\":{'coefficients':dict['OPTICAL_DIST_COEF']}}\n",
"new['radii'] = {'semimajor':dict['SEMI_MAJOR_AXIS'],\n",
" 'semiminor':dict['SEMI_MAJOR_AXIS'],\n",
" 'unit': 'm'}\n",
"new['reference_height'] = {'maxheight':100,\n",
" 'minheight':0,\n",
" 'unit': 'm'}\n",
"\n",
"#perhaps fix socetset_keywords_to_dict to array n insted of using this function\n",
"pos1x3 = list_to_array_n(dict['EPHEM_PTS'],3)\n",
"vel1x3 = list_to_array_n(dict['EPHEM_RATES'],3)\n",
"new['sensor_position'] = {'unit': 'm',\n",
" 'positions':pos1x3,\n",
" 'velocities':vel1x3}\n",
"quat1x4 = list_to_array_n(dict['QUATERNIONS'],4)\n",
"new['sensor_orientation'] = {'quaternions':quat1x4}\n",
"\n",
"new['starting_detector_line'] = dict['STARTING_LINE']\n",
"new['starting_detector_sample'] = dict['STARTING_SAMPLE']\n",
"\n",
"#orginal keywords file does not have the Sun's position or velocity\n",
"# can we use something like spacecraft position?\n",
"# velocity is optional in the schema - is it really optional?\n",
"sunPos1x3 = []\n",
"sunPos1x3.append(dict['SENSOR_POSITION'])\n",
"#sunVel1x3 = []\n",
"#sunVel1x3.append([0,0,0])\n",
"new['sun_position'] = {'positions':sunPos1x3,\n",
" #'velocities':sunVel1x3,\n",
" 'unit': 'm'}\n",
"#pp_json(new)"
]
},
{
"cell_type": "code",
"execution_count": 224,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name_model : USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL\n",
"name_platform : MRO\n",
"name_sensor : MRO_CTX\n",
"center_ephemeris_time : 516918406.7171735\n",
"starting_ephemeris_time : 516918390.38217354\n",
"line_scan_rate : [[1, -17.040647955556565, 0]]\n",
"detector_sample_summing : 1.0\n",
"detector_line_summing : 1\n",
"t0_ephemeris : -17.040647955556565\n",
"dt_ephemeris : 0.03753446686245939\n",
"t0_quaternion : -17.040647955556565\n",
"dt_quaternion : 0.03753446686245939\n",
"focal2pixel_lines : [0.0, 142.85714285714286, 0.0]\n",
"focal2pixel_samples : [0.0, 0.0, 142.85714285714286]\n",
"focal_length_model : {'focal_length': 354.615781793}\n"
]
}
],
"source": [
"for key in new.keys():\n",
" #stop short. Just list top part of file\n",
" if (key == \"image_lines\"):\n",
" break\n",
" print(key + \" : \" + str(new[key]))"
]
},
{
"cell_type": "code",
"execution_count": 225,
"metadata": {},
"outputs": [],
"source": [
"#Convert original keywords.lis dictionary to JSON - no longer needed\n",
"#dict_json = json.dumps(dict) \n",
"#pp_json(your_json_string_or_dict)\n",
"#pp_json(dc_json)\n",
"\n",
"convertedKeywords_isd = json.dumps(new, sort_keys=True, indent=2)\n",
"\n",
"#Write local if only if you need\n",
"with open('J03_045994_1986_XN_18N282W.json', \"w\") as f:\n",
" f.write(convertedKeywords_isd)\n",
"\n",
"#pp_json(convertedKeywords_isd)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Testing ISDs angainst the updated/fixed ISD schema"
]
},
{
"cell_type": "code",
"execution_count": 226,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n",
" \"title\": \"Instrument Specification Definition\",\n",
" \"description\": \"The Instrument Specification Definition for Astro CSM\",\n",
" \"type\": \"object\",\n",
" \"required\": [\n",
" \"name_model\",\n",
" \"name_platform\",\n",
" \"name_sensor\",\n",
" \"center_ephemeris_time\",\n",
" \"starting_ephemeris_time\",\n",
" \"line_scan_rate\",\n",
" \"detector_sample_summing\",\n",
" \"detector_line_summing\",\n",
" \"t0_ephemeris\",\n",
" \"dt_ephemeris\",\n",
" \"t0_quaternion\",\n",
" \"dt_quaternion\",\n",
" \"focal2pixel_lines\",\n",
" \"focal2pixel_samples\",\n",
" \"focal_length_model\",\n",
" \"image_lines\",\n",
" \"image_samples\",\n",
" \"detector_center\",\n",
" \"interpolation_method\",\n",
" \"optical_distortion\",\n",
" \"radii\",\n",
" \"reference_height\",\n",
" \"sensor_position\",\n",
" \"sensor_orientation\",\n",
" \"starting_detector_line\",\n",
" \"starting_detector_sample\",\n",
" \"sun_position\"\n",
" ],\n",
" \"properties\": {\n",
" \"name_model\": {\n",
" \"description\": \"CSM sensor model name. for example: USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL\",\n",
" \"type\": \"string\"\n",
" },\n",
" \"name_platform\": {\n",
" \"description\": \"CSM sensor platform name. for example: MRO, LRO\",\n",
" \"type\": \"string\"\n",
" },\n",
" \"name_sensor\": {\n",
" \"description\": \"CSM sensor name. for example: MRO_CTX, LROC\",\n",
" \"type\": \"string\"\n",
" },\n",
" \"detector_center\": {\n",
" \"description\": \"Center of the detector in pixel coordinates (line, sample)\",\n",
" \"type\": \"object\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The (line, sample) of the center of the detector.\",\n",
" \"minItems\": 2,\n",
" \"maxItems\": 2\n",
" }\n",
" },\n",
" \"center_ephemeris_time\": {\n",
" \"description\": \"The center ephemeris time of the image\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"starting_ephemeris_time\": {\n",
" \"description\": \"The starting ephemeris time of the image\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"focal_length_model\": {\n",
" \"description\": \"The static focal length or the information needed to model a variable focal length\",\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"key\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"A key to get information about time/temp dependent focal length models\"\n",
" },\n",
" \"focal_length\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The focal length in mm\"\n",
" },\n",
" \"focal_epsilon\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The uncertainty of the focal length in mm\"\n",
" }\n",
" },\n",
" \"required\": [\n",
" \"focal_length\"\n",
" ]\n",
" },\n",
" \"image_lines\": {\n",
" \"description\": \"The number of lines in the image\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"image_samples\": {\n",
" \"description\": \"The the number of samples in the image\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"radii\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"The radii of the target baody.\",\n",
" \"required\": [\n",
" \"semimajor\",\n",
" \"semiminor\",\n",
" \"unit\"\n",
" ],\n",
" \"properties\": {\n",
" \"semimajor\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The semi-major axis for the target\"\n",
" },\n",
" \"semiminor\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The semi-minor axis for the target\"\n",
" },\n",
" \"unit\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The units in m or km\"\n",
" }\n",
" }\n",
" },\n",
" \"optical_distortion\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"Information needed to convert from undistorted to distorted image plane. Supported optical distortion methods: radial\",\n",
" \"properties\": {\n",
" \"radial\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"radial optical distortion parameters\",\n",
" \"required\": [\n",
" \"coefficients\"\n",
" ],\n",
" \"properties\": {\n",
" \"coefficients\": {\n",
" \"type\": \"array\",\n",
" \"description\": \"optical distortion coefficients generally a 3 value array. For example [0.0, 0.0., 0.0]\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"Each coefficient used for the distortion equation in order of increasing degrees.\"\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"starting_detector_sample\": {\n",
" \"description\": \"The sample on the detector where the data starts\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"starting_detector_line\": {\n",
" \"description\": \"The line on the detector where the data starts\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"focal2pixel_samples\": {\n",
" \"description\": \"Transformation x coefficients from focal plane (mm) to detector pixel coordinates\",\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\"\n",
" }\n",
" },\n",
" \"focal2pixel_lines\": {\n",
" \"description\": \"Transformation y coefficients from focal plane (mm) to detector pixel coordinates\",\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"minItems\": 3,\n",
" \"maxItems\": 3\n",
" }\n",
" },\n",
" \"sensor_location\": {\n",
" \"description\": \"(X, Y, Z) location of sensor in body-fixed frame.\",\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"minItems\": 3,\n",
" \"maxItems\": 3\n",
" }\n",
" }\n",
" },\n",
" \"sensor_velocity\": {\n",
" \"description\": \"(v_x, v_y, v_z) velocity of sensor in body-fixed frame.\",\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"minItems\": 3,\n",
" \"maxItems\": 3\n",
" }\n",
" }\n",
" },\n",
" \"sun_position\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"Sun_position and velocity\",\n",
" \"required\": [\n",
" \"positions\",\n",
" \"unit\"\n",
" ],\n",
" \"properties\": {\n",
" \"positions\": {\n",
" \"type\": \"array\",\n",
" \"description\": \"(x, y,z) of the sun in body-fixed frame.\",\n",
" \"items\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"minItems\": 3,\n",
" \"maxItems\": 3\n",
" }\n",
" }\n",
" },\n",
" \"unit\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Unit of sun position values. Recommended in meters (m)\"\n",
" },\n",
" \"velocities\": {\n",
" \"type\": \"array\",\n",
" \"description\": \"(v_x, v_y, v_z) velocity of sun in body-fixed frame.\",\n",
" \"items\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"minItems\": 3,\n",
" \"maxItems\": 3\n",
" }\n",
" }\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"sensor_orientation\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"Orientation of the sensor provided in quaternions\",\n",
" \"required\": [\n",
" \"quaternions\"\n",
" ],\n",
" \"properties\": {\n",
" \"quaternions\": {\n",
" \"type\": \"array\",\n",
" \"description\": \"Each quaternion is of the general form: (scalar, vector component, vector component, vector component). The specific form used is that described in the NAIF Quaternions whitepaper under 'SPICE Quaternions' available at: ftp://naif.jpl.nasa.gov/pub/naif/misc/Quaternion_White_Paper/Quaternions_White_Paper.pdf\",\n",
" \"items\": {\n",
" \"type\": \"array\",\n",
" \"description\": \"Representated as an array of 4 values\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"minItems\": 4,\n",
" \"maxItems\": 4\n",
" }\n",
" }\n",
" }\n",
" }\n",
" },\n",
" \"line_scan_rate\": {\n",
" \"description\": \"The line rates of the detector map with the associated start line and time\",\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"number\",\n",
" \"default\": \"-1\",\n",
" \"description\": \"The (start_line, line_start_time, exposure_time). The exposure time is in seconds and any non-provided values will be set to -1.\",\n",
" \"minItems\": 3,\n",
" \"maxItems\": 3\n",
" }\n",
" }\n",
" },\n",
" \"detector_sample_summing\": {\n",
" \"description\": \"The summing in the sample-direction. A summing of 1 indicates no summing, summing of 2 indicates 2 pixel summing, 4 indicates 4 pixel summing, etc\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"detector_line_summing\": {\n",
" \"description\": \"The summing in the line-direction\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"apply_light_time_correction\": {\n",
" \"description\": \"A flag to indcate whether the light-time correction should be applied\",\n",
" \"type\": \"boolean\"\n",
" },\n",
" \"number_of_ephemerides\": {\n",
" \"description\": \"The number of emphemeris points\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"number_of_quaternions\": {\n",
" \"description\": \"The number of quaternions\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"dt_ephemeris\": {\n",
" \"description\": \"The time between each ephemeris point.\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"t0_ephemeris\": {\n",
" \"description\": \"First ephemeris time - center image time\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"dt_quaternion\": {\n",
" \"description\": \"Time spacing of quaternions.\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"t0_quaternion\": {\n",
" \"description\": \"First quaternion time - center image time.\",\n",
" \"type\": \"number\"\n",
" },\n",
" \"reference_height\": {\n",
" \"type\": \"object\",\n",
" \"description\": \"Used for determining the intersection of the look vector with the ellipsoid.\",\n",
" \"required\": [\n",
" \"maxheight\",\n",
" \"minheight\",\n",
" \"unit\"\n",
" ],\n",
" \"properties\": {\n",
" \"maxheight\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The Maxheight Schema\"\n",
" },\n",
" \"minheight\": {\n",
" \"type\": \"number\",\n",
" \"description\": \"The Minheight Schema\"\n",
" },\n",
" \"unit\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The units in m\"\n",
" }\n",
" }\n",
" },\n",
" \"interpolation_method\": {\n",
" \"description\": \"The type of interpolation method to use.\",\n",
" \"type\": \"string\",\n",
" \"enum\": [\n",
" \"lagrange\"\n",
" ]\n",
" }\n",
"}\n"
]
}
],
"source": [
"import jsonschema\n",
"\n",
"#change to use github URL, once schema is updated\n",
"#now using dropbox\n",
"url = \"https://www.dropbox.com/s/pnirzm1sopz30lu/isd.json?dl=1\" # dl=1 is important\n",
"import urllib.request\n",
"u = urllib.request.urlopen(url)\n",
"schema_data = u.read()\n",
"u.close()\n",
" \n",
"#Write local if only if you need\n",
"#with open([filename], \"wb\") as f :\n",
"# f.write(data)\n",
"\n",
"#open local file\n",
"#with open('isd.json', 'r') as f:\n",
"# schema_data = f.read()\n",
"\n",
"isd_schema = json.loads(schema_data)\n",
"pp_json(isd_schema)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### test converted keywords.lis to new ISD JSON via the schema\n",
"\n",
"#### Seems odd this is not passing, error is the whols JSON file is \"is not of type object\". But this does pass on a schema validation website? https://www.jsonschemavalidator.net/\n",
"\n",
"input SocetSet Keywords: https://www.dropbox.com/s/3ka684dwh4lt3lv/J03_045994_1986_XN_18N282W_keywords.lis?dl=0\n",
"output ISD: https://www.dropbox.com/s/nt41i6vu99g1xrc/J03_045994_1986_XN_18N282W.json?dl=0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"convertedKeywords_isd = json.dumps(new)\n",
"#res = jsonschema.validate(convertedKeywords_isd, isd_schema)\n",
"#if (res == None):\n",
"# print(\"ISD passes validation\")\n",
" \n",
"v = jsonschema.Draft7Validator(isd_schema)\n",
"errors = sorted(v.iter_errors(convertedKeywords_isd), key=lambda e: e.path)\n",
"if (errors == []):\n",
" print(\"ISD passes validation\")\n",
"else:\n",
" print(errors)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load a couple more ISD examples, one from pfeffernusse and one generic example from github"
]
},
{
"cell_type": "code",
"execution_count": 197,
"metadata": {},
"outputs": [],
"source": [
"#MRO CTX ISD generated from pfeffernusse\n",
"file = open('response_1542308674230.json','r').read().strip('\\n')\n",
"CTX_isd = json.loads(file)"
]
},
{
"cell_type": "code",
"execution_count": 210,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ISD passes validation\n"
]
}
],
"source": [
"#res = jsonschema.validate(CTX_isd, isd_schema)\n",
"#if (res == None):\n",
"# print(\"ISD passes validation\")\n",
" \n",
"v = jsonschema.Draft7Validator(isd_schema)\n",
"errors = sorted(v.iter_errors(CTX_isd), key=lambda e: e.path)\n",
"if (errors == []):\n",
" print(\"ISD passes validation\")\n",
"else:\n",
" print(errors)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Here it is odd that the schema didn't catch the current 4 value array for sun position. See:\n",
"https://github.com/USGS-Astrogeology/pfeffernusse/issues/17"
]
},
{
"cell_type": "code",
"execution_count": 156,
"metadata": {},
"outputs": [],
"source": [
"# A generic linescanner example from github\n",
"import urllib.request\n",
"\n",
"githubFile = \"https://raw.githubusercontent.com/USGS-Astrogeology/CSM-CameraModel/dev/tests/data/constVelocityLineScan.json\"\n",
"with urllib.request.urlopen(githubFile) as request:\n",
" file = request.read()\n",
"file = file.decode('utf-8').strip('\\n')\n",
"LS_isd = json.loads(file)"
]
},
{
"cell_type": "code",
"execution_count": 209,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ISD passes validation\n"
]
}
],
"source": [
"#res = jsonschema.validate(LS_isd, isd_schema)\n",
"#if (res == None):\n",
"# print(\"ISD passes validation\")\n",
" \n",
"v = jsonschema.Draft7Validator(isd_schema)\n",
"errors = sorted(v.iter_errors(LS_isd), key=lambda e: e.path)\n",
"if (errors == []):\n",
" print(\"ISD passes validation\")\n",
"else:\n",
" print(errors)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment