Last active
June 7, 2019 06:43
-
-
Save neuromusic/87267d7e20279585517c8cd46a0c5601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<xarray.Codebook (target: 2, c: 3, r: 2)>\n", | |
"array([[[0, 1],\n", | |
" [0, 0],\n", | |
" [1, 0]],\n", | |
"\n", | |
" [[0, 0],\n", | |
" [1, 1],\n", | |
" [0, 0]]], dtype=uint8)\n", | |
"Coordinates:\n", | |
" * target (target) object a3866318-c57d-4dce-ba4f-948b83daa665 41eb0d65-5312-437b-a740-bec1fdb4efb4\n", | |
" * c (c) int64 0 1 2\n", | |
" * r (r) int64 0 1" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from starfish import Codebook\n", | |
"codebook = Codebook.synthetic_one_hot_codebook(n_round=2, n_channel=3, n_codes=2)\n", | |
"codebook" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"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></th>\n", | |
" <th></th>\n", | |
" <th>v</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>target</th>\n", | |
" <th>c</th>\n", | |
" <th>r</th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th rowspan=\"5\" valign=\"top\">a3866318-c57d-4dce-ba4f-948b83daa665</th>\n", | |
" <th rowspan=\"2\" valign=\"top\">0</th>\n", | |
" <th>0</th>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"2\" valign=\"top\">1</th>\n", | |
" <th>0</th>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" v\n", | |
"target c r \n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665 0 0 0\n", | |
" 1 1\n", | |
" 1 0 0\n", | |
" 1 0\n", | |
" 2 0 1" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df = codebook.to_dataframe(name='v')\n", | |
"df.head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"df.to_csv('codebook.csv')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"target,c,r,v\n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665,0,0,0\n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665,0,1,1\n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665,1,0,0\n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665,1,1,0\n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665,2,0,1\n", | |
"a3866318-c57d-4dce-ba4f-948b83daa665,2,1,0\n", | |
"41eb0d65-5312-437b-a740-bec1fdb4efb4,0,0,0\n", | |
"41eb0d65-5312-437b-a740-bec1fdb4efb4,0,1,0\n", | |
"41eb0d65-5312-437b-a740-bec1fdb4efb4,1,0,1\n", | |
"41eb0d65-5312-437b-a740-bec1fdb4efb4,1,1,1\n", | |
"41eb0d65-5312-437b-a740-bec1fdb4efb4,2,0,0\n", | |
"41eb0d65-5312-437b-a740-bec1fdb4efb4,2,1,0\n" | |
] | |
} | |
], | |
"source": [ | |
"%%bash\n", | |
"less codebook.csv" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"codebook2 = pd.read_csv('codebook.csv',index_col=[0,1,2])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<xarray.DataArray 'v' (target: 2, c: 3, r: 2)>\n", | |
"array([[[0, 0],\n", | |
" [1, 1],\n", | |
" [0, 0]],\n", | |
"\n", | |
" [[0, 1],\n", | |
" [0, 0],\n", | |
" [1, 0]]])\n", | |
"Coordinates:\n", | |
" * target (target) object '41eb0d65-5312-437b-a740-bec1fdb4efb4' 'a3866318-c57d-4dce-ba4f-948b83daa665'\n", | |
" * c (c) int64 0 1 2\n", | |
" * r (r) int64 0 1" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"codebook2.to_xarray()['v']" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "starfish", | |
"language": "python", | |
"name": "starfish" | |
}, | |
"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.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment