Preprocessing

This notebook demonstrates how to preprocess astronomical images using the ezphot library. Preprocessing is a crucial step in astronomical data reduction that involves:

  • Bias correction: Removing electronic bias from CCD detectors

  • Dark current correction: Subtracting thermal noise from long exposures

  • Flat field correction: Correcting for pixel-to-pixel sensitivity variations

We’ll walk through the complete workflow from data loading to final corrected images.

1. Load Data

The first step in preprocessing is to load your astronomical data. We’ll use two main approaches:

  • ``DataBrowser``: Query and filter images from your local data directory

  • ``SDTDataQuerier``: Sync data from a central database (optional but recommended for large datasets)

πŸ’‘ Tip: The SDTDataQuerier class provides methods to sync data from a central database to your local workspace, making it easy to work with large astronomical datasets without storing everything locally.

1.1. Sync Data with SDTDataQuerier (Optional)

If you have access to a central database, you can sync specific observations to your local workspace. This is particularly useful when working with large datasets or when you only need specific observations.

[ ]:
from ezphot.utils import SDTDataQuerier
# If you connected the database, you can easily sync the data from the database.
sdtquery = SDTDataQuerier()
sdtquery.help()
Help for SDTDataQuerier


Public methods:
- show_obsdestdata(foldername: str, show_only_numbers: bool = False, pattern: str = '*.fits')
- show_obsdestfolder(folder_key: str = '*')
- show_obssourcedata(foldername: str, show_only_numbers: bool = False, pattern: str = '*.fits')
- show_obssourcefolder(folder_key: str = '*')
- show_scidestdata(targetname: str, show_only_numbers: bool = False, key: str = 'filter', pattern: str = '*.fits')
- show_scisourcedata(targetname: str, show_only_numbers: bool = False, key: str = 'filter', file_pattern: str = '*.fits')
- show_scisourcefolder(folder_key: str = '*')
- sync_obsdata(foldername: str, file_pattern: str = '*.fits', ignore_exists: bool = True)
- sync_scidata(targetname: str, file_pattern: str = '*.fits', ignore_exists: bool = True)

Now let’s sync the data for our specific observation date. We’ll use the sync_obsdata method to copy FITS files matching our pattern:

[8]:
# sync_scidata method will run multiple rsync between Science Source directory and destination directory.
print('Source directory:', sdtquery.helper.config['SDTDATA_OBSSOURCEDIR'])
print('Target directory:', sdtquery.helper.config['SDTDATA_OBSDESTDIR'])
obsdate_name = '2025-09-05_gain2750'
sdtquery.sync_obsdata(foldername = obsdate_name, file_pattern = '*T00290*.fits')
Source directory: /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata
Target directory: /home/hhchoi1022/ezphot/data/obsdata/7DT
Running:Running:Running:Running:Running:Running:Running:Running:Running:Running:Running:         rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT07/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/  rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT10/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT01/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT14/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT12/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT08/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT16/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/
rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT06/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT11/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/
rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT03/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/rsync -av --info=progress2 --no-inc-recursive --prune-empty-dirs --ignore-existing --include */ --include *T00290*.fits --exclude * /home/hhchoi1022/ezphot/data/connecteddata/7DT/obsdata/7DT13/2025-09-05_gain2750/ /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/








building file list ... building file list ... building file list ... building file list ... building file list ... building file list ... building file list ... building file list ... building file list ... building file list ... building file list ... done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)

sent 350 bytes  received 12 bytes  241.33 bytes/sec
total size is 734,123,520  speedup is 2,027,965.52
done


sent 341 bytes  received 12 bytes  235.33 bytes/sec
total size is 734,123,520  speedup is 2,079,670.03
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)

sent 358 bytes  received 12 bytes  246.67 bytes/sec
total size is 734,123,520  speedup is 1,984,117.62
done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)done
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/7)

sent 361 bytes  received 12 bytes  248.67 bytes/sec
total size is 734,123,520  speedup is 1,968,159.57


sent 360 bytes  received 12 bytes  248.00 bytes/sec
total size is 734,123,520  speedup is 1,973,450.32


sent 359 bytes  received 12 bytes  247.33 bytes/sec
total size is 734,123,520  speedup is 1,978,769.60


sent 359 bytes  received 12 bytes  247.33 bytes/sec
total size is 734,123,520  speedup is 1,978,769.60


sent 358 bytes  received 12 bytes  246.67 bytes/sec
total size is 734,123,520  speedup is 1,984,117.62


sent 358 bytes  received 12 bytes  246.67 bytes/sec
total size is 734,123,520  speedup is 1,984,117.62


sent 361 bytes  received 12 bytes  248.67 bytes/sec
total size is 734,123,520  speedup is 1,968,159.57


sent 357 bytes  received 12 bytes  246.00 bytes/sec
total size is 734,123,520  speedup is 1,989,494.63

πŸ”„ Sync Progress: The rsync process copies FITS files from the source directory to your local destination directory. This ensures you have the latest data while maintaining efficient storage usage.

πŸ”Ž 1.2. Query Data with DataBrowser

The DataBrowser class allows us to query and filter our synced data. Here we’ll explore the available keys and their values to understand what data we have access to.

Key Features:

  • Filter by observatory, telescope, object name, filter, image type, and observation date

  • Load data as ScienceImage objects or metadata tables

  • Flexible search patterns for file matching

[11]:
from ezphot.utils import DataBrowser
dbrowser = DataBrowser('obsdata')
dbrowser.obsdate = obsdate_name
dbrowser.search('*.fits', return_type = 'path')
[INFO] Found 66 files matching '/home/hhchoi1022/ezphot/data/obsdata/*/*/2025-09-05_gain2750/*.fits'
[11]:
['/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_233955_T00290_m700_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234653_T00290_m725_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234508_T00290_m725_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234838_T00290_m725_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234140_T00290_m700_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_233809_T00290_m700_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_233808_T00290_m450_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_234653_T00290_m475_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_234508_T00290_m475_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_233954_T00290_m450_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_234839_T00290_m475_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_234139_T00290_m450_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/7DT06_20250905_234549_T00290_m575_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/7DT06_20250905_234923_T00290_m575_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/7DT06_20250905_233828_T00290_m550_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/7DT06_20250905_234736_T00290_m575_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/7DT06_20250905_234015_T00290_m550_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750/7DT06_20250905_234202_T00290_m550_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/7DT13_20250905_233955_T00290_m875_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/7DT13_20250905_234653_T00290_m400_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/7DT13_20250905_234508_T00290_m400_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/7DT13_20250905_234838_T00290_m400_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/7DT13_20250905_234140_T00290_m875_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750/7DT13_20250905_233810_T00290_m875_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/7DT12_20250905_234837_T00290_m875_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/7DT12_20250905_233955_T00290_m850_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/7DT12_20250905_234140_T00290_m850_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/7DT12_20250905_234652_T00290_m875_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/7DT12_20250905_233810_T00290_m850_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750/7DT12_20250905_234506_T00290_m875_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/7DT10_20250905_234158_T00290_m800_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/7DT10_20250905_234724_T00290_m825_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/7DT10_20250905_233824_T00290_m800_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/7DT10_20250905_234011_T00290_m800_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/7DT10_20250905_234911_T00290_m825_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750/7DT10_20250905_234537_T00290_m825_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/7DT07_20250905_234511_T00290_m525_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/7DT07_20250905_234656_T00290_m525_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/7DT07_20250905_233957_T00290_m650_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/7DT07_20250905_233811_T00290_m650_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/7DT07_20250905_234142_T00290_m650_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750/7DT07_20250905_234841_T00290_m525_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/7DT16_20250905_234516_T00290_r_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/7DT16_20250905_233815_T00290_g_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/7DT16_20250905_234145_T00290_g_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/7DT16_20250905_234702_T00290_r_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/7DT16_20250905_234000_T00290_g_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750/7DT16_20250905_234846_T00290_r_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/7DT01_20250905_234157_T00290_i_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/7DT01_20250905_234730_T00290_m675_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/7DT01_20250905_234918_T00290_m675_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/7DT01_20250905_234010_T00290_i_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/7DT01_20250905_233822_T00290_i_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750/7DT01_20250905_234542_T00290_m675_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234014_T00290_m600_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234551_T00290_m500_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234202_T00290_m600_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234928_T00290_m500_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_233825_T00290_m600_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234739_T00290_m500_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234002_T00290_m625_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_233817_T00290_m625_1x1_100.0s_0000.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234659_T00290_m425_1x1_100.0s_0001.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234147_T00290_m625_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234843_T00290_m425_1x1_100.0s_0002.fits',
 '/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234513_T00290_m425_1x1_100.0s_0000.fits']
[12]:
# If you wish to get the ScienceImage object,
target_imgset = dbrowser.search('*.fits', return_type = 'science')
target_imglist = target_imgset.target_images
# If you wish to get the metadata table from the keys,
metadata_table = dbrowser.search('*.fits', return_type = 'imginfo')
[INFO] Found 66 files matching '/home/hhchoi1022/ezphot/data/obsdata/*/*/2025-09-05_gain2750/*.fits'
Loading Science Images: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 66/66 [00:01<00:00, 51.40it/s]
[INFO] Found 66 files matching '/home/hhchoi1022/ezphot/data/obsdata/*/*/2025-09-05_gain2750/*.fits'

Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT07/2025-09-05_gain2750Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750

Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT01/2025-09-05_gain2750Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT12/2025-09-05_gain2750

Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT10/2025-09-05_gain2750
Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT06/2025-09-05_gain2750Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750

Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT16/2025-09-05_gain2750
Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750
Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750Loaded 6 FITS files from /home/hhchoi1022/ezphot/data/obsdata/7DT/7DT13/2025-09-05_gain2750

Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6Total FITS files combined: 6










Collecting ImgInfo: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 11/11 [00:00<00:00, 33240.16it/s]
[13]:
metadata_table
[13]:
Table length=66
filealtitudeazimuthccd-tempgainfilterimgtypeexptimeobsdatelocdatejdmjdbinningobjectobjctidobsmodespecmodenotetelescop
str121str32str32str32str21str4str5str32str23str23str32str32str21str6str32str4str7str4str5
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_233955_T00290_m700_1x1_100.0s_0001.fits39.837596179.72268-10.02750m700LIGHT100.02025-09-05T23:39:55.0002025-09-05 19:39:55.0002460924.48605324160923.986053240741T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT08
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234653_T00290_m725_1x1_100.0s_0001.fits39.840043180.091172-10.02750m725LIGHT100.02025-09-05T23:46:53.0002025-09-05 19:46:53.0002460924.490891203760923.9908912037061T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT08
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234508_T00290_m725_1x1_100.0s_0000.fits39.840357179.998559-9.82750m725LIGHT100.02025-09-05T23:45:08.0002025-09-05 19:45:08.0002460924.48967592660923.989675925931T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT08
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234838_T00290_m725_1x1_100.0s_0002.fits39.83912180.183768-10.02750m725LIGHT100.02025-09-05T23:48:38.0002025-09-05 19:48:38.0002460924.492106481560923.9921064814841T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT08
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_234140_T00290_m700_1x1_100.0s_0002.fits39.839148179.815416-10.12750m700LIGHT100.02025-09-05T23:41:40.0002025-09-05 19:41:40.0002460924.487268518760923.987268518521T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT08
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT08/2025-09-05_gain2750/7DT08_20250905_233809_T00290_m700_1x1_100.0s_0000.fits39.83547179.629828-9.82750m700LIGHT100.02025-09-05T23:38:09.0002025-09-05 19:38:09.0002460924.48482638960923.9848263888851T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT08
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_233808_T00290_m450_1x1_100.0s_0000.fits39.820706179.644698-10.12750m450LIGHT100.02025-09-05T23:38:08.0002025-09-05 19:38:08.0002460924.484814814860923.9848148148161T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT03
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_234653_T00290_m475_1x1_100.0s_0001.fits39.82478180.107488-10.02750m475LIGHT100.02025-09-05T23:46:53.0002025-09-05 19:46:53.0002460924.490891203760923.9908912037061T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT03
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT03/2025-09-05_gain2750/7DT03_20250905_234508_T00290_m475_1x1_100.0s_0000.fits39.825207180.014533-10.02750m475LIGHT100.02025-09-05T23:45:08.0002025-09-05 19:45:08.0002460924.48967592660923.989675925931T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT03
.........................................................
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234202_T00290_m600_1x1_100.0s_0002.fits39.823601179.853116-10.02750m600LIGHT100.02025-09-05T23:42:02.0002025-09-05 19:42:02.0002460924.487523148360923.987523148151T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT14
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234928_T00290_m500_1x1_100.0s_0002.fits39.822232180.246067-10.12750m500LIGHT100.02025-09-05T23:49:28.0002025-09-05 19:49:28.0002460924.492685185360923.9926851851851T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT14
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_233825_T00290_m600_1x1_100.0s_0000.fits39.820335179.662379-9.92750m600LIGHT100.02025-09-05T23:38:25.0002025-09-05 19:38:25.0002460924.48501157460923.985011574081T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT14
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT14/2025-09-05_gain2750/7DT14_20250905_234739_T00290_m500_1x1_100.0s_0001.fits39.823586180.150701-9.92750m500LIGHT100.02025-09-05T23:47:39.0002025-09-05 19:47:39.0002460924.49142361160923.9914236111141T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT14
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234002_T00290_m625_1x1_100.0s_0001.fits39.82206179.744821-9.92750m625LIGHT100.02025-09-05T23:40:02.0002025-09-05 19:40:02.0002460924.48613425960923.9861342592561T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT11
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_233817_T00290_m625_1x1_100.0s_0000.fits39.820108179.652273-10.12750m625LIGHT100.02025-09-05T23:38:17.0002025-09-05 19:38:17.0002460924.484918981360923.9849189814851T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT11
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234659_T00290_m425_1x1_100.0s_0001.fits39.823944180.11177-10.12750m425LIGHT100.02025-09-05T23:46:59.0002025-09-05 19:46:59.0002460924.490960648360923.9909606481451T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT11
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234147_T00290_m625_1x1_100.0s_0002.fits39.823463179.837513-10.12750m625LIGHT100.02025-09-05T23:41:47.0002025-09-05 19:41:47.0002460924.48734953760923.9873495370341T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT11
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234843_T00290_m425_1x1_100.0s_0002.fits39.822916180.20439-9.92750m425LIGHT100.02025-09-05T23:48:43.0002025-09-05 19:48:43.0002460924.49216435260923.9921643518541T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT11
/home/hhchoi1022/ezphot/data/obsdata/7DT/7DT11/2025-09-05_gain2750/7DT11_20250905_234513_T00290_m425_1x1_100.0s_0000.fits39.824364180.019297-9.92750m425LIGHT100.02025-09-05T23:45:13.0002025-09-05 19:45:13.0002460924.48973379660923.98973379631T002909473692bf1874a48a7492f0f1ad94624SpecspecallNone7DT11

2. Preprocessing

2.1. Load master frames

Master frames are combined calibration images that provide the best signal-to-noise ratio for correction. We need three types:

  • Master Bias: Electronic bias pattern (zero exposure time)

  • Master Dark: Thermal noise pattern (same exposure time as science images)

  • Master Flat: Pixel sensitivity variations (illumination pattern)

⚠️ Important: Master frames should be taken close in time to your science observations (typically within a few days) to ensure similar detector conditions.

[ ]:
from ezphot.methods import Preprocess

preprocess = Preprocess()
preprocess.help()
Help for Preprocess

Public methods:
- correct_bd(target_img: ezphot.imageobjects.scienceimage.ScienceImage, bias_image: ezphot.imageobjects.calibrationimage.CalibrationImage, dark_image: ezphot.imageobjects.calibrationimage.CalibrationImage, save: bool = False, verbose: bool = True, **kwargs)
- correct_bdf(target_img: ezphot.imageobjects.scienceimage.ScienceImage, bias_image: ezphot.imageobjects.calibrationimage.CalibrationImage, dark_image: ezphot.imageobjects.calibrationimage.CalibrationImage, flat_image: ezphot.imageobjects.calibrationimage.CalibrationImage, save: bool = False, verbose: bool = True, **kwargs)
- correct_bias(target_img: ezphot.imageobjects.scienceimage.ScienceImage, bias_image: ezphot.imageobjects.calibrationimage.CalibrationImage, save: bool = False, verbose: bool = True, **kwargs)
- correct_dark(target_img: ezphot.imageobjects.scienceimage.ScienceImage, dark_image: ezphot.imageobjects.calibrationimage.CalibrationImage, save: bool = False, verbose: bool = True, **kwargs)
- correct_flat(target_img: ezphot.imageobjects.scienceimage.ScienceImage, flat_image: ezphot.imageobjects.calibrationimage.CalibrationImage, save: bool = False, verbose: bool = True, **kwargs)
- generate_masterframe(calib_imagelist: List[ezphot.imageobjects.calibrationimage.CalibrationImage], mbias: ezphot.imageobjects.calibrationimage.CalibrationImage = None, mdark: ezphot.imageobjects.calibrationimage.CalibrationImage = None, combine_type: str = 'median', n_proc: int = 4, clip_type: str = 'extrema', sigma: float = 3.0, nlow: int = 1, nhigh: int = 1, verbose: bool = True, save: bool = True, **kwargs)
- get_masterframe(observatory: str = '7DT', telkey: str = '7DT_C361K_HIGH_1x1', telname: str = '7DT02', imagetyp: str = 'BIAS', exptime: float = None, filter_: str = None, obsdate: str = None, max_days: float = 5, verbose: bool = True)
- get_masterframe_from_image(target_img: ezphot.imageobjects.scienceimage.ScienceImage, imagetyp: str = 'BIAS', max_days: float = 5)
[ ]:
mbias = preprocess.get_masterframe_from_image(target_imglist[0], 'BIAS', max_days = 60)[0]
mdark = preprocess.get_masterframe_from_image(target_imglist[0], 'DARK', max_days = 60)[0]
mflat = preprocess.get_masterframe_from_image(target_imglist[0], 'FLAT', max_days = 60)[0] # For flat frames, master frame is needed to specify by the filter
mbias.show()
mdark.show()
mflat.show()
(<Figure size 800x600 with 2 Axes>,
 <Axes: title={'center': '20250723-nm700.fits'}, xlabel='X pixel', ylabel='Y pixel'>)
../_images/example_preprocess_14_1.png
../_images/example_preprocess_14_2.png
../_images/example_preprocess_14_3.png

2.2. Apply Correction

Now we’ll apply the master calibration frames to correct our science images. The preprocessing follows this sequence:

  1. Bias correction: corrected = (raw - bias)

  2. Dark correction: corrected = (bias_corrected - dark)

  3. Flat correction: corrected = dark_corrected / flat

This removes systematic errors and normalizes pixel responses across the detector.

[ ]:
target_img = target_imglist[0]
corrected_img = preprocess.correct_bdf(
    target_img = target_img,
    bias_image = mbias,
    dark_image = mdark,
    flat_image = mflat,
    save = False
)
[26]:
target_img.show()
corrected_img.show()
[26]:
(<Figure size 800x600 with 2 Axes>,
 <Axes: title={'center': '7DT08_20250905_233955_T00290_m700_1x1_100.0s_0001.fits'}, xlabel='X pixel', ylabel='Y pixel'>)
../_images/example_preprocess_17_1.png
../_images/example_preprocess_17_2.png
[ ]:
# Save the corrected image. (You can also save the image with save = True)
corrected_img.write()
Saved: /home/hhchoi1022/ezphot/data/scidata/7DT/7DT_C361K_HIGH_1x1/T00290/7DT08/m700/7DT08_20250905_233955_T00290_m700_1x1_100.0s_0001.fits

2.3. Batch Process All Target Images

For production workflows, you’ll want to process all your target images automatically. This section demonstrates how to:

  • Loop through all target images

  • Automatically find appropriate master frames for each image

  • Apply corrections and save the results

πŸ’‘ Tip: The preprocessing methods automatically handle different exposure times and filters by finding the most appropriate master frames for each science image.

[ ]:
for target_img in target_imglist:
    mbias = preprocess.get_masterframe_from_image(target_img, 'BIAS', max_days = 60)[0]
    mdark = preprocess.get_masterframe_from_image(target_img, 'DARK', max_days = 60)[0]
    mflat = preprocess.get_masterframe_from_image(target_img, 'FLAT', max_days = 60)[0]

    preprocess.correct_bdf(
        target_img = target_img,
        bias_image = mbias,
        dark_image = mdark,
        flat_image = mflat,
        save = True)

# You can also run in multiprocessing
# Run for all target_imglist with multiprocessing
# from multiprocessing import Pool
# from tqdm import tqdm

# def preprocessing(target_img):
#     mbias = preprocess.get_masterframe_from_image(target_img, 'BIAS', max_days = 60)[0]
#     mdark = preprocess.get_masterframe_from_image(target_img, 'DARK', max_days = 60)[0]
#     mflat = preprocess.get_masterframe_from_image(target_img, 'FLAT', max_days = 60)[0]
#     preprocess.correct_bdf(
#         target_img = target_img,
#         bias_image = mbias,
#         dark_image = mdark,
#         flat_image = mflat,
#         save = True
#     )

# # for target_img in tqdm(target_imglist, desc="Photometric Calibration..."):
# #     photometriccalibration(target_img)

# with Pool(processes = 16) as pool:
#     # Use tqdm with imap to show progress
#     list(tqdm(pool.imap(preprocessing, target_imglist),
#               total=len(target_imglist),
#               desc="Preprocessing..."))