Skip to content

Instantly share code, notes, and snippets.

@danhey
Created May 3, 2023 15:16
Show Gist options
  • Select an option

  • Save danhey/a587e5e1b436cf640b3b6e2f55c5d483 to your computer and use it in GitHub Desktop.

Select an option

Save danhey/a587e5e1b436cf640b3b6e2f55c5d483 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": "92253bf2-8417-4859-880b-809fe72b2c32",
"metadata": {},
"outputs": [],
"source": [
"import lightkurve as lk\n",
"import tarfile\n",
"import os\n",
"\n",
"DL_DIR = 'data/'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "bb4b44de-b0aa-4e1c-b653-ed9f1b398e49",
"metadata": {},
"outputs": [],
"source": [
"kicids = ['9651065']"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "2c406267-ffbe-4e8f-ab0b-c6e4984433f0",
"metadata": {},
"outputs": [],
"source": [
"wget_commands = []\n",
"for kicid in kicids:\n",
" kicid = str(kicid).zfill(9)\n",
" wget = f\"wget -nH --cut-dirs=6 -r -l0 -c -q -N -np -R 'index*' -erobots=off -A 'kplr*_lc_*.tar' https://archive.stsci.edu/pub/kepler/lightcurves/{kicid[:4]}/{kicid}/\"\n",
" wget_commands.append(wget)\n",
" \n",
"\n",
"np.savetxt(f'{DL_DIR}/temp/wget.sh', wget_commands, delimiter=\" \", fmt=\"%s\")\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "9e551af7-04eb-43b4-ae24-bf8cef485f42",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"sh: /dev/tty: Device not configured\n",
"\u001b[7m\u001b[0m0% 0:1=0s wget -nH --cut-dirs=6 -r -l0 -c -q -N -np -R 'index*' -erobots=off -A \u001b[0msh: /dev/tty: Device not configured\n",
"\u001b[7m\u001b[0m0% 0:1=0s wget -nH --cut-dirs=6 -r -l0 -c -q -N -np -R 'index*' -erobots=off -A \u001b[0msh: /dev/tty: Device not configured\n",
"\u001b[7m\u001b[0m0% 0:1=0s wget -nH --cut-dirs=6 -r -l0 -c -q -N -np -R 'index*' -erobots=off -A \u001b[0msh: /dev/tty: Device not configured\n",
"\u001b[7m100% 1:0=0s wget -nH --cut-dirs=6 -r -l0 -c -q -N -np -R 'index*' -erobots=off -\u001b[0m\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Download them all\n",
"\n",
"os.system(f'parallel --bar --jobs 50 < {DL_DIR}/temp/wget.sh')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "869b9cab-fdd6-483f-b60f-9782290a8671",
"metadata": {},
"outputs": [],
"source": [
"def stitcher(file):\n",
" try:\n",
" tar = tarfile.open(file)\n",
" tar.extractall('extracted/')\n",
" tar.close()\n",
"\n",
" folder = file.split('/')[-1].split('_')[0].lstrip('kplr')\n",
" lc_files = glob.glob(f'extracted/{folder}/kplr*.fits')\n",
" \n",
" lc = lk.LightCurveCollection([lk.KeplerLightCurveFile(lc_f) for lc_f in lc_files]).stitch().remove_nans()\n",
" fname = file.split('/')[-1].split('_')[0]\n",
" lc.to_fits(f'{DL_DIR}{fname}.fits', overwrite=True)\n",
" except:\n",
" print(file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20d7ed27-2352-432c-be4f-97118f67ef08",
"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.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment