Skip to content

Commit

Permalink
Allow Trim and Overscan as Inputs at GUI Level
Browse files Browse the repository at this point in the history
Gives the user the opportunity to enter the Trim and Overscan regions before running the reduction process at the menu GUI
  • Loading branch information
kjkoeller authored Dec 6, 2024
1 parent b2f0550 commit facdb92
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions EclipsingBinaries/IRAF_Reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
location = "bsuo"


def run_reduction(path, calibrated, location, dark_bool=True, write_callback=None):
def run_reduction(path, calibrated, location, dark_bool=True, overscan_region="[2073:2115, :]", trim_region="[20:2060, 12:2057]", write_callback=None):
"""
Main function to run the reduction process. It replaces user input with programmatic arguments.
:param path: The path to the raw images directory
:param calibrated: The path to the output directory for calibrated images
:param location: The observing location (e.g., 'bsuo', 'kpno', etc.)
:param dark_bool: Boolean to indicate whether to use dark frames
:param overscan_region: String for the overscan region of the CCD
:param trim_region: String for the trim region of the CCD
:param write_callback: Function to write log messages to the GUI
"""
def log(message):
Expand All @@ -67,10 +69,6 @@ def log(message):
if not calibrated_data.exists():
calibrated_data.mkdir(parents=True)

# log(f"Starting reduction process...\nRaw Path: {images_path}\nCalibrated Path: {calibrated_data}")
# log(f"Using location: {location}")
# log(f"Using dark frames: {'Yes' if dark_bool else 'No'}\n")

# Configure location-specific defaults
if location.lower() == "kpno":
configure_kpno()
Expand All @@ -81,7 +79,8 @@ def log(message):

# Process files
files = ccdp.ImageFileCollection(images_path)
zero, overscan_region, trim_region = bias(files, calibrated_data, log)
# zero, overscan_region, trim_region = bias(files, calibrated_data, log)
zero = bias(files, calibrated_data, overscan_region, trim_region, log)
master_dark = dark(files, zero, calibrated_data, overscan_region, trim_region, log) if dark_bool else None
flat(files, zero, master_dark, calibrated_data, overscan_region, trim_region, log)
science_images(files, calibrated_data, zero, master_dark, trim_region, overscan_region, log)
Expand Down Expand Up @@ -228,19 +227,21 @@ def reduce(ccd, overscan_region, trim_region, num, zero, combined_dark, good_fla
return reduced


def bias(files, calibrated_data, log):
def bias(files, calibrated_data, overscan_region, trim_region, log):
"""
Calibrates bias images and creates a master bias.
:param files: Image file collection
:param calibrated_data: Path to save calibrated images
:param overscan_region: String for the overscan region of the CCD
:param trim_region: String for the trim region of the CCD
:param log: Logging function
:return: Master bias, overscan region, trim region
:return: Master bias
"""
log("\nStarting bias calibration.")
# Simulate overscan and trim region determination
overscan_region = "[2073:2115, :]"
trim_region = "[20:2060, 12:2057]"
# overscan_region = "[2073:2115, :]"
# trim_region = "[20:2060, 12:2057]"

log(f"Overscan Region: {overscan_region}")
log(f"Trim Region: {trim_region}")
Expand Down Expand Up @@ -270,27 +271,7 @@ def bias(files, calibrated_data, log):
combined_bias.write(combined_bias_path, overwrite=overwrite)
log(f"Master bias created: {combined_bias_path}")

return combined_bias, overscan_region, trim_region


def bias_plot(ccd):
"""
Plots the count values for row 1000 to find the overscan and trim regions
:param ccd: bias image to be looked at
:return: None
"""
plt.figure(figsize=(10, 5))
plt.plot(ccd.data[1000][:], label='Raw Flat')
plt.grid()
plt.axvline(x=2077, color='black', linewidth=2, linestyle='dashed', label='Suggested Start of Overscan')
plt.legend()
# plt.ylim(0, 60000)
plt.xlim(-50, 2130)
plt.xlabel('pixel number')
plt.ylabel('Counts')
# plt.title('Count Values for Row 1000')
# plt.show()
return combined_bias # , overscan_region, trim_region


def dark(files, zero, calibrated_path, overscan_region, trim_region, log):
Expand Down

0 comments on commit facdb92

Please sign in to comment.