From b950af525c1031d31ae6dcd2a4d5d99cc5a0da61 Mon Sep 17 00:00:00 2001 From: ml server Date: Fri, 24 Jan 2020 19:54:03 -0700 Subject: [PATCH] wut-web-dev to fn --- notebooks/wut-web-dev.ipynb | 145 ++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 47 deletions(-) diff --git a/notebooks/wut-web-dev.ipynb b/notebooks/wut-web-dev.ipynb index 4cd1d44..58d622f 100644 --- a/notebooks/wut-web-dev.ipynb +++ b/notebooks/wut-web-dev.ipynb @@ -106,10 +106,22 @@ " directory=test_dir,\n", " target_size=(IMG_HEIGHT, IMG_WIDTH),\n", " shuffle=True,\n", - " class_mode='binary');\n", + " class_mode='binary')\n", " return test_data_gen" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "def rm_image_tmp(test_dir):\n", + " #print('Not removed:', test_dir)\n", + " shutil.rmtree(test_dir)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -117,18 +129,15 @@ "outputs": [], "source": [ "%%capture --no-stderr --no-stdout\n", - "def gen_image_tmp(obs_waterfall_path):\n", + "def gen_image_tmp(obs_waterfalltmp):\n", " tmp_dir = tempfile.mkdtemp()\n", " test_dir = os.path.join(tmp_dir)\n", " os.makedirs(test_dir + '/unvetted', exist_ok=True)\n", - " shutil.copy(obs_waterfall_path, test_dir + '/unvetted/') \n", + " shutil.copy(obs_waterfalltmp, test_dir + '/unvetted/') \n", " \n", - " img = im.open(obs_waterfall_path).resize( (100,200))\n", + " img = im.open(obs_waterfalltmp).resize( (100,200))\n", " display(img)\n", "\n", - " # XXX delete tmp dir down below\n", - " #print(test_dir)\n", - " #shutil.rmtree(test_dir) \n", " return test_dir" ] }, @@ -156,47 +165,16 @@ "metadata": {}, "outputs": [], "source": [ - "def wutObs(datObs):\n", - " if int(datObs) > ( minobsid - 1 ) and int(datObs) < ( maxobsid + 1):\n", - " obsjsonfile=('/srv/satnogs/download/' + format(datObs) + '/' + format(datObs) + '.json')\n", - " with open(obsjsonfile) as f:\n", - " content = f.read()\n", - " data = json.loads(content)\n", + "def get_obs_dict(datObs):\n", + " obsjsonfile=('/srv/satnogs/download/' + format(datObs) + '/' + format(datObs) + '.json')\n", + " with open(obsjsonfile) as f:\n", + " content = f.read()\n", + " data = json.loads(content)\n", " res = {x : data[x] for x in range(len(data))}\n", " res2 = dict(enumerate(data))\n", " obs_dict=(res2[0])\n", - " obs_id=(obs_dict['id'])\n", " \n", - " obs_vetted_status=(obs_dict['vetted_status'])\n", - " obs_waterfallurl=(obs_dict['waterfall'])\n", - " obs_transmitter=(obs_dict['transmitter'])\n", - " obs_station_name=(obs_dict['station_name'])\n", - " obs_transmitter_mode=(obs_dict['transmitter_mode'])\n", - " \n", - " obs_waterfall=os.path.basename(obs_waterfallurl)\n", - " obs_waterfall_path = os.path.join('/srv/satnogs/download', str(obs_id), obs_waterfall)\n", - " \n", - " test_dir=gen_image_tmp(obs_waterfall_path)\n", - " test_data_gen=gen_image(obs_waterfall_path, test_dir)\n", - " \n", - " prediction_bool=obs_wutsay(test_data_gen);\n", - "\n", - " print()\n", - " print('Observation ID: ', obs_id)\n", - " print('Encoding: ', obs_transmitter_mode)\n", - " print('Human rating: ', obs_vetted_status)\n", - " if prediction_bool[0] == False:\n", - " rating = 'bad'\n", - " else:\n", - " rating = 'good'\n", - " print('wut AI rating: %s' % (rating)) \n", - " print()\n", - " if obs_transmitter_mode == 'DUV':\n", - " print(\"Using DUV training model.\")\n", - " else:\n", - " print(\"NOTE: wut has not been trained on\", obs_transmitter_mode, \"encodings.\")\n", - " print('https://network.satnogs.org/observations/' + str(obs_id))\n", - " #!cat $obsjsonfile" + " return obs_dict" ] }, { @@ -205,9 +183,82 @@ "metadata": {}, "outputs": [], "source": [ - "print('Enter an Observation ID between', minobsid, 'and', maxobsid);\n", - "wutObs_slide = wg.IntText(value='1292461');\n", - "wg.interact(wutObs, datObs=wutObs_slide);" + "def get_obs_var(var, datObs):\n", + " obs_dict=get_obs_dict(datObs);\n", + " obs_var=(obs_dict[(var)])\n", + " \n", + " return obs_var" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "def doallthethings(datObs):\n", + "\n", + " obs_waterfall=get_obs_var('waterfall', datObs) \n", + " obs_waterfallpic=os.path.basename(obs_waterfall)\n", + " obs_waterfalltmp = os.path.join('/srv/satnogs/download', str(get_obs_var('id', datObs)), obs_waterfallpic)\n", + "\n", + " test_dir=gen_image_tmp(obs_waterfalltmp);\n", + " test_data_gen=gen_image(obs_waterfalltmp, test_dir);\n", + " \n", + " prediction_bool=obs_wutsay(test_data_gen);\n", + "\n", + " print()\n", + " print('Observation ID: ', get_obs_var('id', datObs))\n", + " print('Encoding: ', get_obs_var('transmitter_mode', datObs))\n", + " print('Human rating: ', get_obs_var('vetted_status', datObs))\n", + " if prediction_bool[0] == False:\n", + " rating = 'bad'\n", + " else:\n", + " rating = 'good'\n", + " print('wut AI rating: %s' % (rating)) \n", + " print()\n", + " if get_obs_var('transmitter_mode', datObs) == 'DUV':\n", + " print(\"Using DUV training model.\")\n", + " else:\n", + " print(\"NOTE: wut has not been trained on\", get_obs_var('transmitter_mode', datObs), \"encodings.\")\n", + " print('https://network.satnogs.org/observations/' + str(get_obs_var('id', datObs)))\n", + " #!cat $obsjsonfile\n", + " rm_image_tmp(test_dir)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "def wutObs(datObs):\n", + " if int(datObs) > ( minobsid - 1 ) and int(datObs) < ( maxobsid + 1):\n", + " doallthethings(datObs)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "def display_results():\n", + " print('Enter an Observation ID between', minobsid, 'and', maxobsid)\n", + " wutObs_slide = wg.IntText(value='1292461')\n", + " wg.interact(wutObs, datObs=wutObs_slide)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "display_results()" ] } ],