Skip to content

Instantly share code, notes, and snippets.

@rbiswas4
Created June 23, 2017 00:44
Show Gist options
  • Save rbiswas4/9a0b57355c8145f383ddbb616ae9e609 to your computer and use it in GitHub Desktop.
Save rbiswas4/9a0b57355c8145f383ddbb616ae9e609 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "import numpy as np\nimport pandas as pd\nfrom lsst.sims.photUtils import BandpassDict",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "bpdict = BandpassDict.loadTotalBandpassesFromFiles()",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "# Let us make up a set of observation times and filters \nnum = 1000000\nbands = np.random.choice(list('ugrizy'), replace=True, size=num)\nmjds = np.random.uniform(0, 10000, size=num)",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "df = pd.DataFrame(dict(mjd=mjds, band=bands))",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "df_long = pd.DataFrame(dict(mjd=mjds, band=map(lambda x: bpdict[x], bands)))",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "df_category = df_long.copy()\ndf_category.band = df_category.band.astype('category')",
"execution_count": 6,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "import sys",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "x = np.array(map(sys.getsizeof, [df, df_long, df_category]), dtype=np.float)",
"execution_count": 8,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "x = x/x.min()",
"execution_count": 9,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "x",
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "array([ 5.99978223, 5.33314104, 1. ])"
},
"metadata": {},
"execution_count": 10
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "df.info()",
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"text": "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 1000000 entries, 0 to 999999\nData columns (total 2 columns):\nband 1000000 non-null object\nmjd 1000000 non-null float64\ndtypes: float64(1), object(1)\nmemory usage: 15.3+ MB\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "df_long.info()",
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"text": "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 1000000 entries, 0 to 999999\nData columns (total 2 columns):\nband 1000000 non-null object\nmjd 1000000 non-null float64\ndtypes: float64(1), object(1)\nmemory usage: 15.3+ MB\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "df_category.info()",
"execution_count": 13,
"outputs": [
{
"output_type": "stream",
"text": "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 1000000 entries, 0 to 999999\nData columns (total 2 columns):\nband 1000000 non-null category\nmjd 1000000 non-null float64\ndtypes: category(1), float64(1)\nmemory usage: 8.6 MB\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "sys.getsizeof(bands)",
"execution_count": 14,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "1000096"
},
"metadata": {},
"execution_count": 14
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "type(bands)",
"execution_count": 15,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "numpy.ndarray"
},
"metadata": {},
"execution_count": 15
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "bands.dtype",
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "dtype('S1')"
},
"metadata": {},
"execution_count": 16
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python2",
"display_name": "Python [default]",
"language": "python"
},
"anaconda-cloud": {},
"language_info": {
"mimetype": "text/x-python",
"nbconvert_exporter": "python",
"name": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12",
"file_extension": ".py",
"codemirror_mode": {
"version": 2,
"name": "ipython"
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment