Skip to content

Instantly share code, notes, and snippets.

@jradavenport
Created November 19, 2022 00:11
Show Gist options
  • Save jradavenport/6c82d3476695318a7b248b6940d614dd to your computer and use it in GitHub Desktop.
Save jradavenport/6c82d3476695318a7b248b6940d614dd to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "cd8e2c6d",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2af0b866",
"metadata": {},
"outputs": [],
"source": [
"# imagine this is the dataframe, 34k rows\n",
"\n",
"files = ['obj1', 'obj2', 'obj3']"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "44e6b718",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"obj1_g.txt obj1_v.txt\n",
"obj2_g.txt obj2_v.txt\n",
"obj3_g.txt obj3_v.txt\n"
]
}
],
"source": [
"for k in range(len(files)):\n",
" # these are the files you might read?\n",
" print(files[k] + '_g.txt', files[k] + '_v.txt' )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d706d0f1",
"metadata": {},
"outputs": [],
"source": [
"# create empty storage arrays to fill with the 4 key numbers\n",
"mean_skew_all = np.zeros(len(files), dtype=float)\n",
"std_skew_all = np.zeros(len(files), dtype=float)\n",
"YN1_all = np.zeros(len(files), dtype=float)\n",
"YN2_all = np.zeros(len(files), dtype=float)\n",
"\n",
"# a loop first over g files first\n",
"for k in range(len(files)):\n",
" # 1. read in the file\n",
" print(files[k] + '_g.txt')\n",
" \n",
" # do all the LC stuff you're doing... blah blah blah\n",
" for j in range(100):\n",
" # do our trials, the stuff you're already doing\n",
" \n",
" # save our 4 numbers for the k'th star\n",
" YN1_all[k] = the yes/no calculation\n",
" YN2_all[k] = ...\n",
"\n",
"# combine these storage arrays into a NEW data frame \n",
"df_out_g = pd.DataFrame(data={'mean_skew_all':mean_skew_all, 'std_skew_all':std_skew_all,\n",
" 'YN1':YN1_all, 'YN2':YN2_all})\n",
"\n",
"# save the outputs to a file for future you\n",
"df_out_g.to_csv('g-band.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9cc044f",
"metadata": {},
"outputs": [],
"source": [
"# you can read the output in and now move on with your analysis\n",
"df_out_g = pd.read_csv('g-band.csv')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "15392da0",
"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.8.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment