{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import pyscisci.all as pyscisci\n",
    "\n",
    "import matplotlib.pylab as plt\n",
    "\n",
    "path2aps = '/home/ajgates/APS'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "pub2ref  = [[11, 0], [11, 1], [11, 2], [11, 3]]\n",
    "pub2ref  += [[12, 0], [12, 2], [12, 3]] \n",
    "pub2ref  += [[13, 0], [13, 2], [13, 4]]\n",
    "pub2ref  += [[14, 0]]\n",
    "pub2ref  += [[15, 0], [15, 2], [15, 3], [15, 4]] # d5 citations\n",
    "pub2ref  = pd.DataFrame(pub2ref , columns = ['CitingPublicationId', 'CitedPublicationId'])\n",
    "\n",
    "pub2field  = [[0, 1], [0, 2], [1, 1], [2,3], [3,2], [3,3], [4,3], \n",
    "                [11, 1], [12, 3], [13, 3], [14, 1], [15, 1], [15, 2]]\n",
    "pub2field  = pd.DataFrame(pub2field , columns = ['PublicationId', 'FieldId'])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RaoStirling</th>\n",
       "      <th>PublicationId</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.020387</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.012410</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.011382</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.026113</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.009458</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   RaoStirling  PublicationId\n",
       "0     0.020387             11\n",
       "1     0.012410             12\n",
       "2     0.011382             13\n",
       "3     0.026113             14\n",
       "4     0.009458             15"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pub2rs = pyscisci.raostriling_interdisciplinarity(pub2ref , pub2field , \n",
    "                                        focus_pub_ids=None, \n",
    "                                        pub2field_norm=True, temporal=False,\n",
    "                                        citation_direction='references', field_distance_metric='cosine', \n",
    "                                        distance_matrix=None, show_progress=False)\n",
    "\n",
    "# first lets look at the field2field distance matrix\n",
    "pub2rs\n",
    "# it was formed by 1) making a bipartite matrix of all the reference fields for each of the citing fields\n",
    "#        Field1, Field2, Field3\n",
    "# Field1 \n",
    "# Field2\n",
    "# Field3\n",
    "#print(precomputed_distance_matrix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PublicationId</th>\n",
       "      <th>SimpsonInterdisciplinarity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11</td>\n",
       "      <td>0.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12</td>\n",
       "      <td>0.640000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13</td>\n",
       "      <td>0.625000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>14</td>\n",
       "      <td>0.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15</td>\n",
       "      <td>0.611111</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PublicationId  SimpsonInterdisciplinarity\n",
       "0             11                    0.666667\n",
       "1             12                    0.640000\n",
       "2             13                    0.625000\n",
       "3             14                    0.500000\n",
       "4             15                    0.611111"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pub2simp = pyscisci.simpson_interdisciplinarity(pub2ref , pub2field , \n",
    "                                        focus_pub_ids=None, \n",
    "                                        citation_direction='references', \n",
    "                                        finite_correction=False, show_progress=False)\n",
    "\n",
    "\n",
    "pub2simp\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PublicationId</th>\n",
       "      <th>SimpsonInterdisciplinarity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11</td>\n",
       "      <td>0.800000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12</td>\n",
       "      <td>0.800000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13</td>\n",
       "      <td>0.833333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>14</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15</td>\n",
       "      <td>0.733333</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PublicationId  SimpsonInterdisciplinarity\n",
       "0             11                    0.800000\n",
       "1             12                    0.800000\n",
       "2             13                    0.833333\n",
       "3             14                    1.000000\n",
       "4             15                    0.733333"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pub2simp = pyscisci.simpson_interdisciplinarity(pub2ref , pub2field , \n",
    "                                        focus_pub_ids=None, \n",
    "                                        citation_direction='references', \n",
    "                                        finite_correction=True, show_progress=False)\n",
    "\n",
    "\n",
    "pub2simp\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PublicationId</th>\n",
       "      <th>ShannonInterdisciplinarity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12</td>\n",
       "      <td>0.960230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13</td>\n",
       "      <td>0.946395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>14</td>\n",
       "      <td>0.630930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15</td>\n",
       "      <td>0.920620</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PublicationId  ShannonInterdisciplinarity\n",
       "0             11                    1.000000\n",
       "1             12                    0.960230\n",
       "2             13                    0.946395\n",
       "3             14                    0.630930\n",
       "4             15                    0.920620"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pub2shannon = pyscisci.shannon_interdisciplinarity(pub2ref , pub2field , \n",
    "                                        focus_pub_ids=None, \n",
    "                                        citation_direction='references', \n",
    "                                        normalized=True, K=None, show_progress=False)\n",
    "\n",
    "\n",
    "pub2shannon\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "myaps = pyscisci.APS(path2aps)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['subjectAreas' 'disciplines' 'concepts']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array(['0213a5a0-0742-43f3-804b-3ccea08a13c0',\n",
       "       '0e9db8ef-5aa8-40bc-a0c8-9d93f5fcc2eb',\n",
       "       '0f4313da-ec73-46f5-b24f-521a1fcb6db7',\n",
       "       '2bd35371-7fda-477a-8e1a-c346c797a232',\n",
       "       '419d860ece5c42f1b6ad4dee9f4fbf60',\n",
       "       '510fc21887744547ab09fc6cef0c9a03',\n",
       "       '512fd433-7b6d-4535-bb60-78f3bf431bc3',\n",
       "       '5375b253-b0a1-4ece-bb50-4c34ea7218bd',\n",
       "       '6f025065-4b96-4156-b146-2c285d0994c4',\n",
       "       '780edcc1-705f-432b-9121-76105d540fe1',\n",
       "       '88db3168-1ae3-4ee7-a7f8-b83018cc5f17',\n",
       "       '8ab3d2b7-b50b-460e-b086-8990cfcbd350',\n",
       "       '9f5c878e-b7b7-4030-bdb9-21a24ad97422',\n",
       "       'a48f173e-6459-4642-a711-a6e731807625',\n",
       "       'c3ec1cb0fc2e4669a886a82178c6ceda',\n",
       "       'c9174048-b368-4b5b-b065-20094708fa4d',\n",
       "       'e4211828-5d99-4bc4-b986-eb2bbbc8b248'], dtype=object)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fieldinfo  = myaps.fieldinfo \n",
    "print(fieldinfo ['ClassificationType'].unique())\n",
    "aps_fields = np.sort(fieldinfo [fieldinfo ['ClassificationType'] == 'disciplines']['FieldId'].unique())\n",
    "aps_fields"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "adff7e9dc1714da4b4a7b5f1f2bef3e1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(HTML(value='Loading Fields'), FloatProgress(value=0.0, max=1.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0d2b17cf87af486f9e1d9f18ca1064d0",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(HTML(value='Loading pub2ref'), FloatProgress(value=0.0, max=1.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "pub2field  = myaps.load_pub2field(columns=['PublicationId', 'FieldId'], filter_dict={'FieldId':aps_fields})\n",
    "pub2ref  = myaps.pub2ref \n",
    "\n",
    "pub2year = myaps.pub2year\n",
    "pub2ref ['CitingYear'] = [pub2year.get(pid, None) for pid in pub2ref ['CitingPublicationId'].values]\n",
    "pub2ref ['CitedYear'] = [pub2year.get(pid, None) for pid in pub2ref ['CitedPublicationId'].values]\n",
    "pub2ref .dropna(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "distance_matrix = pyscisci.field_citation_distance(pub2ref , pub2field , \n",
    "                                       pub2field_norm=True, temporal=True,\n",
    "                                        citation_direction='references', field_distance_metric='cosine', \n",
    "                                        show_progress=False)\n",
    "\n",
    "focus_pub_ids = np.sort(pub2ref .loc[pub2ref ['CitingYear'] > 2015]['CitingPublicationId'].unique())\n",
    "\n",
    "pub2rs = pyscisci.raostriling_interdisciplinarity(pub2ref , pub2field , \n",
    "                                        focus_pub_ids=focus_pub_ids, \n",
    "                                        pub2field_norm=True, temporal=True,\n",
    "                                        citation_direction='references', field_distance_metric='cosine', \n",
    "                                        distance_matrix=distance_matrix, show_progress=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PublicationId</th>\n",
       "      <th>CitingYear</th>\n",
       "      <th>RaoStirling</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.1103/PhysRevA.93.012109</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.1103/PhysRevA.93.012121</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>0.207237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10.1103/PhysRevA.93.012122</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>0.023904</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10.1103/PhysRevA.93.012339</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10.1103/PhysRevA.93.012506</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17927</th>\n",
       "      <td>10.1103/RevModPhys.91.045001</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.153758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17928</th>\n",
       "      <td>10.1103/RevModPhys.91.045002</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.261487</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17929</th>\n",
       "      <td>10.1103/RevModPhys.91.045003</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.009303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17930</th>\n",
       "      <td>10.1103/RevModPhys.91.045004</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.237865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17931</th>\n",
       "      <td>10.1103/RevModPhys.91.045005</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.029930</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>54520 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      PublicationId  CitingYear  RaoStirling\n",
       "0        10.1103/PhysRevA.93.012109      2016.0     0.000000\n",
       "1        10.1103/PhysRevA.93.012121      2016.0     0.207237\n",
       "2        10.1103/PhysRevA.93.012122      2016.0     0.023904\n",
       "3        10.1103/PhysRevA.93.012339      2016.0     0.000000\n",
       "4        10.1103/PhysRevA.93.012506      2016.0     0.000000\n",
       "...                             ...         ...          ...\n",
       "17927  10.1103/RevModPhys.91.045001      2019.0     0.153758\n",
       "17928  10.1103/RevModPhys.91.045002      2019.0     0.261487\n",
       "17929  10.1103/RevModPhys.91.045003      2019.0     0.009303\n",
       "17930  10.1103/RevModPhys.91.045004      2019.0     0.237865\n",
       "17931  10.1103/RevModPhys.91.045005      2019.0     0.029930\n",
       "\n",
       "[54520 rows x 3 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pub2rs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 13200 characters]\n",
      "text/plain": [
       "<Figure size 504x504 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "rsdist, rsbins = np.histogram(pub2rs['RaoStirling'].values, bins=20)\n",
    "\n",
    "fig, ax = plt.subplots(1,1,figsize=(7,7))\n",
    "\n",
    "ax.step(rsbins[:-1], rsdist)\n",
    "ax.set_title('Interdisciplinarity of References')\n",
    "ax.set_xlabel('RaoStirling')\n",
    "ax.set_ylabel('# of publications')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CitingPublicationId</th>\n",
       "      <th>CitedPublicationId</th>\n",
       "      <th>CitingYear</th>\n",
       "      <th>CitedYear</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.1103/PhysRevSeriesI.11.215</td>\n",
       "      <td>10.1103/PhysRevSeriesI.1.1</td>\n",
       "      <td>1900.0</td>\n",
       "      <td>1893.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.1103/PhysRevSeriesI.12.121</td>\n",
       "      <td>10.1103/PhysRevSeriesI.1.166</td>\n",
       "      <td>1901.0</td>\n",
       "      <td>1893.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10.1103/PhysRevSeriesI.7.93</td>\n",
       "      <td>10.1103/PhysRevSeriesI.1.166</td>\n",
       "      <td>1898.0</td>\n",
       "      <td>1893.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10.1103/PhysRevSeriesI.16.267</td>\n",
       "      <td>10.1103/PhysRevSeriesI.2.35</td>\n",
       "      <td>1903.0</td>\n",
       "      <td>1894.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10.1103/PhysRevSeriesI.17.65</td>\n",
       "      <td>10.1103/PhysRevSeriesI.2.112</td>\n",
       "      <td>1903.0</td>\n",
       "      <td>1894.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8324608</th>\n",
       "      <td>10.1103/PhysRevLett.123.264802</td>\n",
       "      <td>10.1103/PhysRevLett.123.264803</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>2019.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8324609</th>\n",
       "      <td>10.1103/PhysRevB.100.224518</td>\n",
       "      <td>10.1103/PhysRevB.100.224519</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>2019.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8324610</th>\n",
       "      <td>10.1103/PhysRevA.100.062335</td>\n",
       "      <td>10.1103/PhysRevLett.123.260504</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>2019.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8324613</th>\n",
       "      <td>10.1103/PhysRevLett.123.260504</td>\n",
       "      <td>10.1103/PhysRevA.100.062335</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>2019.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8324616</th>\n",
       "      <td>10.1103/PhysRevC.100.061304</td>\n",
       "      <td>10.1103/PhysRevC.100.062501</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>2019.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8267865 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    CitingPublicationId              CitedPublicationId  \\\n",
       "0         10.1103/PhysRevSeriesI.11.215      10.1103/PhysRevSeriesI.1.1   \n",
       "1         10.1103/PhysRevSeriesI.12.121    10.1103/PhysRevSeriesI.1.166   \n",
       "2           10.1103/PhysRevSeriesI.7.93    10.1103/PhysRevSeriesI.1.166   \n",
       "3         10.1103/PhysRevSeriesI.16.267     10.1103/PhysRevSeriesI.2.35   \n",
       "4          10.1103/PhysRevSeriesI.17.65    10.1103/PhysRevSeriesI.2.112   \n",
       "...                                 ...                             ...   \n",
       "8324608  10.1103/PhysRevLett.123.264802  10.1103/PhysRevLett.123.264803   \n",
       "8324609     10.1103/PhysRevB.100.224518     10.1103/PhysRevB.100.224519   \n",
       "8324610     10.1103/PhysRevA.100.062335  10.1103/PhysRevLett.123.260504   \n",
       "8324613  10.1103/PhysRevLett.123.260504     10.1103/PhysRevA.100.062335   \n",
       "8324616     10.1103/PhysRevC.100.061304     10.1103/PhysRevC.100.062501   \n",
       "\n",
       "         CitingYear  CitedYear  \n",
       "0            1900.0     1893.0  \n",
       "1            1901.0     1893.0  \n",
       "2            1898.0     1893.0  \n",
       "3            1903.0     1894.0  \n",
       "4            1903.0     1894.0  \n",
       "...             ...        ...  \n",
       "8324608      2019.0     2019.0  \n",
       "8324609      2019.0     2019.0  \n",
       "8324610      2019.0     2019.0  \n",
       "8324613      2019.0     2019.0  \n",
       "8324616      2019.0     2019.0  \n",
       "\n",
       "[8267865 rows x 4 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pub2ref "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "focus_pub_ids = np.sort(pub2ref .loc[pub2ref ['CitedYear'] > 2015]['CitedPublicationId'].unique())\n",
    "\n",
    "pub2rs = pyscisci.raostriling_interdisciplinarity(pub2ref , pub2field , \n",
    "                                        focus_pub_ids=focus_pub_ids, \n",
    "                                        pub2field_norm=True, temporal=False,\n",
    "                                        citation_direction='citations', field_distance_metric='cosine', \n",
    "                                        distance_matrix=None, show_progress=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 12488 characters]\n",
      "text/plain": [
       "<Figure size 504x504 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "rsdist, rsbins = np.histogram(pub2rs['RaoStirling'].values, bins=20)\n",
    "\n",
    "fig, ax = plt.subplots(1,1,figsize=(7,7))\n",
    "\n",
    "ax.step(rsbins[:-1], rsdist)\n",
    "ax.set_title('Interdisciplinarity of Citations')\n",
    "ax.set_xlabel('RaoStirling')\n",
    "ax.set_ylabel('# of publications')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
