Skip to content

Instantly share code, notes, and snippets.

@rbiswas4
Created October 2, 2018 16:13
Show Gist options
  • Save rbiswas4/db5fcbaec7be4883fd2c9b5aa2b8062e to your computer and use it in GitHub Desktop.
Save rbiswas4/db5fcbaec7be4883fd2c9b5aa2b8062e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import numpy as np",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import pandas as pd",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "kraken = pd.read_csv('../data/kraken_2026.csv', index_col='band')\naltsched = pd.read_csv('../data/altsched.csv', index_col='band')",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df = kraken.join(altsched, rsuffix='_altsched')\ndf[['counts_kraken', 'counts_altsched']] = df[['counts_kraken', 'counts_altsched']].astype(np.int)",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.counts = df.counts_kraken.astype(np.int)\ndf.counts_altsched = df.counts_altsched.astype(np.int)",
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": "/Users/rbiswas/soft/mypython3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access\n \"\"\"Entry point for launching an IPython kernel.\n",
"name": "stderr"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.loc['total'] = [df.counts_kraken.sum(), np.nan, df.counts_altsched.sum(), np.nan]\ndf.loc['total_yz'] = [df.loc[list('yz')].counts_kraken.sum(), np.nan, df.loc[list('yz')].counts_altsched.sum(), np.nan]",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df['diff_counts'] = - df.counts_kraken + df.counts_altsched \ndf.diff_counts = df.diff_counts.astype(np.int)\ndf['diff_fracs'] = df.diff_counts/df.counts",
"execution_count": 9,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "df.loc[list('ugrizy')+ ['total', 'total_yz']]",
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 10,
"data": {
"text/plain": " counts_kraken avg_svd_kraken counts_altsched avg_svd_altsched \\\nband \nu 143037.0 23.322964 170952.0 23.104350 \ng 201037.0 24.628514 221660.0 24.310660 \nr 460469.0 24.239348 568983.0 23.743212 \ni 457896.0 23.664690 376786.0 23.382305 \nz 421088.0 22.786929 529925.0 22.837444 \ny 423622.0 21.977920 177866.0 21.855284 \ntotal 2107149.0 NaN 2046172.0 NaN \ntotal_yz 844710.0 NaN 707791.0 NaN \n\n diff_counts diff_fracs \nband \nu 27915 0.195159 \ng 20623 0.102583 \nr 108514 0.235660 \ni -81110 -0.177136 \nz 108837 0.258466 \ny -245756 -0.580130 \ntotal -60977 NaN \ntotal_yz -136919 NaN ",
"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>counts_kraken</th>\n <th>avg_svd_kraken</th>\n <th>counts_altsched</th>\n <th>avg_svd_altsched</th>\n <th>diff_counts</th>\n <th>diff_fracs</th>\n </tr>\n <tr>\n <th>band</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>u</th>\n <td>143037.0</td>\n <td>23.322964</td>\n <td>170952.0</td>\n <td>23.104350</td>\n <td>27915</td>\n <td>0.195159</td>\n </tr>\n <tr>\n <th>g</th>\n <td>201037.0</td>\n <td>24.628514</td>\n <td>221660.0</td>\n <td>24.310660</td>\n <td>20623</td>\n <td>0.102583</td>\n </tr>\n <tr>\n <th>r</th>\n <td>460469.0</td>\n <td>24.239348</td>\n <td>568983.0</td>\n <td>23.743212</td>\n <td>108514</td>\n <td>0.235660</td>\n </tr>\n <tr>\n <th>i</th>\n <td>457896.0</td>\n <td>23.664690</td>\n <td>376786.0</td>\n <td>23.382305</td>\n <td>-81110</td>\n <td>-0.177136</td>\n </tr>\n <tr>\n <th>z</th>\n <td>421088.0</td>\n <td>22.786929</td>\n <td>529925.0</td>\n <td>22.837444</td>\n <td>108837</td>\n <td>0.258466</td>\n </tr>\n <tr>\n <th>y</th>\n <td>423622.0</td>\n <td>21.977920</td>\n <td>177866.0</td>\n <td>21.855284</td>\n <td>-245756</td>\n <td>-0.580130</td>\n </tr>\n <tr>\n <th>total</th>\n <td>2107149.0</td>\n <td>NaN</td>\n <td>2046172.0</td>\n <td>NaN</td>\n <td>-60977</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>total_yz</th>\n <td>844710.0</td>\n <td>NaN</td>\n <td>707791.0</td>\n <td>NaN</td>\n <td>-136919</td>\n <td>NaN</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "### Ratio of visits in each band to total number of visits in SRD"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# From overview paper: https://arxiv.org/abs/0805.2366\nfv = np.array((56, 80, 184, 184, 160, 160))\nfv / fv.sum()",
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 12,
"data": {
"text/plain": "array([ 0.06796117, 0.09708738, 0.22330097, 0.22330097, 0.19417476,\n 0.19417476])"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Same fraction for kraken_2016 (aiming to reproduce overview paper)\ndf.loc[list('ugrizy') + ['total', 'total_yz']].counts_kraken / df.counts_kraken.total",
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 15,
"data": {
"text/plain": "band\nu 0.067882\ng 0.095407\nr 0.218527\ni 0.217306\nz 0.199838\ny 0.201040\ntotal 1.000000\ntotal_yz 0.400878\nName: counts_kraken, dtype: float64"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Fraction for alt_sched doing better SN proposal! \n# Note there is a bit of a difference in that alt_sched has a different packing of visits, but the total time should be treated similarly\n# if dithers are added to OpSim. Also note post-facto dithers in OpSim could account for a difference in times used.\ndf.loc[list('ugrizy') + ['total', 'total_yz']].counts_altsched / df.counts_altsched.total",
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 16,
"data": {
"text/plain": "band\nu 0.083547\ng 0.108329\nr 0.278072\ni 0.184142\nz 0.258984\ny 0.086926\ntotal 1.000000\ntotal_yz 0.345910\nName: counts_altsched, dtype: float64"
},
"metadata": {}
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.5",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment