Skip to content

Example_flat notebook #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions Example_flat.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example of making sky flat"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import reducer.astro_gui as astro_gui\n",
"import reducer.gui\n",
"from reducer.image_browser import ImageBrowser\n",
"import os\n",
"from ccdproc import ImageFileCollection"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here we set up the directories for the example data."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# To use the sample data set:\n",
"data_dir = reducer.notebook_dir.get_data_path()\n",
"\n",
"# Or, uncomment line below and modify as needed\n",
"# data_dir = 'path/to/your/data'\n",
"# example_dir is where the master_dark and master_bias are put in\n",
"# destination_dir is set default to example_dir\n",
"\n",
"example_dir = os.path.join(os.path.dirname(os.path.abspath(reducer.__file__)), 'data')\n",
"destination_dir = example_dir"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"images = ImageFileCollection(location=data_dir, keywords='*')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will do reduction for flat frames, then try to combine them to a master flat. \n",
"There are already existed master_bias and master_dark files in example_dir. You have to subtract both during reduction process.\n",
"### Procedure:\n",
"\n",
"Check `Subtract bias` and select `Created in this notebook` \n",
"Check `Subtract dark` and select `Created in this notebook` and also `Scale dark by exposure time` \n",
"Then press `Lock settings and Go!`"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "49d527f41d934eeb9eba46d6f47f7d83",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>Reduction</code>.</p>\n",
"<p>\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</p>\n"
],
"text/plain": [
"Reduction(children=(Box(children=(ToggleButton(value=False, description='Reduce flat frames'),)), VBox(children=(CopyFiles(children=(Box(children=(CheckboxPlus(children=(Label(value='Copy without any other action?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), Overscan(children=(Box(children=(CheckboxPlus(children=(Label(value='Subtract overscan?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(AxisSelection(children=(HBox(children=(Label(value='Region is all of'), ToggleButtons(options=OrderedDict([('axis 0', 0), ('axis 1', 1)]), style=ToggleButtonsStyle(button_width='initial'), value=0)), layout=Layout(align_items='center')), Label(value='and along the other axis from '), IntText(value=0, style=DescriptionStyle(description_width='initial')), Label(value='up to (but not including):'), IntText(value=0, style=DescriptionStyle(description_width='initial'))), layout=Layout(display='flex')), ToggleContainer(children=(Box(children=(CheckboxPlus(children=(Label(value='Fit polynomial to overscan?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(PolynomialDropdown(description='Choose fit', options=OrderedDict([('Order 0/one term (constant)', 1), ('Order 1/two term (linear)', 2), ('Order 2/three team (quadratic)', 3), ('Are you serious? Higher order is silly.', None)]), value=1),), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden'))))), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), Trim(children=(Box(children=(CheckboxPlus(children=(Label(value='Trim (specify region to keep)?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(AxisSelection(children=(HBox(children=(Label(value='Region is all of'), ToggleButtons(options=OrderedDict([('axis 0', 0), ('axis 1', 1)]), style=ToggleButtonsStyle(button_width='initial'), value=0)), layout=Layout(align_items='center')), Label(value='and along the other axis from '), IntText(value=0, style=DescriptionStyle(description_width='initial')), Label(value='up to (but not including):'), IntText(value=3073, style=DescriptionStyle(description_width='initial'))), layout=Layout(display='flex')),), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), BiasSubtract(children=(Box(children=(CheckboxPlus(children=(Label(value='Subtract bias?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(MasterImageSource(children=(ToggleButtons(description='Source:', options=(('Created in this notebook', 'notebook'), ('File on disk', 'disk')), value='notebook'), Dropdown(description='Select file:', layout=Layout(display='none'), options=('Not working yet',), value='Not working yet'))),), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), DarkSubtract(children=(Box(children=(CheckboxPlus(children=(Label(value='Subtract Dark?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(MasterImageSource(children=(ToggleButtons(description='Source:', options=(('Created in this notebook', 'notebook'), ('File on disk', 'disk')), value='notebook'), Dropdown(description='Select file:', layout=Layout(display='none'), options=('Not working yet',), value='Not working yet'))), DarkScaleSetting(children=(ToggleButtons(description='Scale dark by exposure time (if needed)', index=1, options={'Yes': True, 'No': False}, value=False),))), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden'))))), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')), HBox(children=(Button(description='Lock settings and Go!', disabled=True, layout=Layout(display='none'), style=ButtonStyle()), Button(description='Unlock settings', disabled=True, layout=Layout(display='none'), style=ButtonStyle()))), Box(children=(FloatProgress(value=0.0, layout=Layout(display='none'), max=1.0),))))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reduce flat frames Yes\n",
"\tCopy without any other action? No\n",
"\tSubtract overscan? No\n",
"\tTrim (specify region to keep)? No\n",
"\tSubtract bias? Yes\n",
"\t\tSource: notebook\n",
"\tSubtract Dark? Yes\n",
"\t\tSource: notebook\n",
"\t\tScale dark by exposure time (if needed): True\n"
]
}
],
"source": [
"reduced_collection = ImageFileCollection(location=destination_dir, keywords='*')\n",
"flat_reduction = astro_gui.Reduction(description='Reduce flat frames',\n",
" toggle_type='button',\n",
" allow_bias=True,\n",
" master_source=reduced_collection,\n",
" allow_dark=True,\n",
" allow_flat=False,\n",
" input_image_collection=images,\n",
" destination=destination_dir,\n",
" apply_to={'imagetyp': 'flat'})\n",
"\n",
"flat_reduction.display()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Procedure:\n",
"\n",
"Check `Clip before combining` and select `Sigma clip` with **low threshold**: 2, **high threshold**: 4 \n",
"Check `Combine images` with **Median** combination method, and select `Scale before combining` with **median** \n",
"Then press `Lock settings and Go!`"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "54c19d68609d45bfb4d33f72ce4eb1d5",
"version_major": 2,
"version_minor": 0
},
"text/html": [
"<p>Failed to display Jupyter Widget of type <code>Combiner</code>.</p>\n",
"<p>\n",
" If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
" that the widgets JavaScript is still loading. If this message persists, it\n",
" likely means that the widgets JavaScript library is either not installed or\n",
" not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
" Widgets Documentation</a> for setup instructions.\n",
"</p>\n",
"<p>\n",
" If you're reading this message in another frontend (for example, a static\n",
" rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
" it may mean that your frontend doesn't currently support widgets.\n",
"</p>\n"
],
"text/plain": [
"Combiner(children=(Box(children=(ToggleButton(value=False, description='Make Master Flat'),)), VBox(children=(Clipping(children=(Box(children=(CheckboxPlus(children=(Label(value='Clip before combining?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),), layout=Layout(padding='3px')), VBox(children=(ToggleMinMax(children=(Box(children=(CheckboxPlus(children=(Label(value='Clip by min/max?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),), layout=Layout(padding='3px')), VBox(children=(FloatText(value=0.0, description='Low threshold', layout=Layout(width='10em'), style=DescriptionStyle(description_width='initial')), FloatText(value=0.0, description='High threshold', layout=Layout(width='10em'), style=DescriptionStyle(description_width='initial'))), layout=Layout(display='none', justify_content='space-around', padding='0px 0px 0px 30px', visibility='hidden', width='50%')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), ToggleMinMax(children=(Box(children=(CheckboxPlus(children=(Label(value='Sigma clip?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),), layout=Layout(padding='3px')), VBox(children=(FloatText(value=0.0, description='Low threshold', layout=Layout(width='10em'), style=DescriptionStyle(description_width='initial')), FloatText(value=0.0, description='High threshold', layout=Layout(width='10em'), style=DescriptionStyle(description_width='initial'))), layout=Layout(display='none', justify_content='space-around', padding='0px 0px 0px 30px', visibility='hidden', width='50%')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden'))))), layout=Layout(display='none', padding='0px 0px 0px 30px', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), Combine(children=(Box(children=(CheckboxPlus(children=(Label(value='Combine images?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(ToggleButtons(description='Combination method:', options=('Average', 'Median'), style=ToggleButtonsStyle(description_width='initial'), value='Average'), ToggleContainer(children=(Box(children=(CheckboxPlus(children=(Label(value='Scale before combining?'), Checkbox(value=False, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(RadioButtons(description='Which should scale to same value?', options=('mean', 'median'), style=DescriptionStyle(description_width='initial'), value='mean'),), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden'))))), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')))), GroupBy(children=(Box(children=(CheckboxPlus(children=(Label(value='Group by:'), Checkbox(value=True, style=DescriptionStyle(description_width='initial'))), layout=Layout(align_items='center', display='flex', justify_content='flex-start')),)), VBox(children=(Text(value='exposure, filter', description='Keywords (comma-separated)', style=DescriptionStyle(description_width='initial')),), layout=Layout(visibility='visible')), Checkbox(value=False, layout=Layout(display='none', visibility='hidden'))))), layout=Layout(display='none', visibility='hidden')), Checkbox(value=True, layout=Layout(display='none', visibility='hidden')), HBox(children=(Button(description='Lock settings and Go!', disabled=True, layout=Layout(display='none'), style=ButtonStyle()), Button(description='Unlock settings', disabled=True, layout=Layout(display='none'), style=ButtonStyle()))), Box(children=(FloatProgress(value=0.0, layout=Layout(display='none'), max=1.0),))))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Make Master Flat Yes\n",
"\tClip before combining? Yes\n",
"\t\tClip by min/max? No\n",
"\t\tSigma clip? Yes\n",
"\t\t\tLow threshold: 2.0\n",
"\t\t\tHigh threshold: 4.0\n",
"\tCombine images? Yes\n",
"\t\tCombination method:: Median\n",
"\t\tScale before combining? Yes\n",
"\t\t\tWhich should scale to same value?: median\n",
"\tGroup by: No\n"
]
}
],
"source": [
"reduced_collection = ImageFileCollection(location=destination_dir, keywords='*')\n",
"\n",
"flat = astro_gui.Combiner(description=\"Make Master Flat\",\n",
" toggle_type='button',\n",
" file_name_base='master_flat',\n",
" group_by='exposure, filter',\n",
" image_source=reduced_collection,\n",
" apply_to={'imagetyp': 'flat'},\n",
" destination=destination_dir)\n",
"flat.display()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Now you can find master flat in the destination directory"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file added reducer/data/master_bias.fit
Binary file not shown.
Binary file added reducer/data/master_dark.fit
Binary file not shown.