<jupyter_start><jupyter_text>SECTION TO INITIALIZE<jupyter_code># import stuff

import urllib
import numpy as np
import matplotlib.pyplot as plt

import PynPoint

from PynPoint import Pypeline
from PynPoint.IOmodules.Hdf5Reading import Hdf5ReadingModule
from PynPoint.IOmodules.FitsWriting import FitsWritingModule
from PynPoint.IOmodules.FitsReading import FitsReadingModule
from PynPoint.IOmodules.TextReading import ParangReadingModule
from PynPoint.ProcessingModules import PSFpreparationModule, \
                                       PcaPsfSubtractionModule, \
                                       ContrastCurveModule, \
                                       FluxAndPosition, \
                                    StackingAndSubsampling
#from PynPoint.ProcessingModules.StackingAndSubsampling import DerotateAndStackModule
from PynPoint.ProcessingModules.FluxAndPosition import FakePlanetModule
#from PynPoint.Util import AnalysisTools
# define workspaces and initialize Pypeline

stem = ('/home/../../media/unasemaje/Elements/lbti_data_reduction/'+
        '180507_fizeau_altair/06_winnowed/')

working_place = stem+"/junk_test_working_place/"
input_place = stem
output_place = stem+"/junk_test_output_place/"

pipeline = Pypeline(working_place_in=working_place,
                    input_place_in=input_place,
                    output_place_in=output_place)

# now a *.ini file has been generated (this includes the PIXSCALE), if no pre-existing one was there
## IF THE *INI FILE WAS NEWLY GENERATED, EDIT THE *INI FILE TO SET
## PIXSCALE = 0.0107<jupyter_output><empty_output><jupyter_text>SECTION TO READ IN DATA<jupyter_code># read in science FITS files 
# (should have PARANG=0 in all headers, so as to keep the PSF in the same original orientation on the array; 
# we need to wait to correct for PARANG later)

read_science = FitsReadingModule(name_in="read_science",
                                 input_dir=None,
                                 image_tag="science",
                                 check=True)

pipeline.add_module(read_science)
# read in PSF reference FITS files (i.e., unsaturated frames)
# (these do not have any PARANG in the header, but it probably doesn't matter)

read_ref_psf = FitsReadingModule(name_in="read_ref_psf",
                                 input_dir=input_place,
                                 image_tag="ref_psf",
                                 check=True)

pipeline.add_module(read_ref_psf)
# make PCA basis set, calculate image residuals after subtracting the PCA reconstructions of the PSF

pca_pca_subt = PcaPsfSubtractionModule(pca_numbers=(100, ),
                                       name_in="pca",
                                       images_in_tag="science",
                                       reference_in_tag="ref_psf",
                                       res_mean_tag="mean_residuals",
                                       res_median_tag="median_residuals",
                                       res_arr_out_tag="all_resids",
                                       res_rot_mean_clip_tag="resid_rot",
                                       basis_out_tag="pca_components",
                                       subtract_mean=True)

pipeline.add_module(pca_pca_subt)

# note:
# images_in_tag: science images
# reference_in_tag: reference images, which COULD be the science images
# write out PCA basis set

write_pca_basis = FitsWritingModule(file_name="test_pca_basis.fits",
                              name_in="write_pca_basis",
                              output_dir=output_place,
                              data_tag="pca_components")

pipeline.add_module(write_pca_basis)
# write out PCA residuals, all

write_pca_resids_all = FitsWritingModule(file_name="test_pca_resids_all.fits",
                              name_in="write_pca_resids_all",
                              output_dir=output_place,
                              data_tag="all_resids")

#pipeline.add_module(write_pca_resids_all)
# write out PCA residuals, median

write_pca_resids_median = FitsWritingModule(file_name="test_pca_resids_median.fits",
                              name_in="write_pca_resids_median",
                              output_dir=output_place,
                              data_tag="median_residuals")

pipeline.add_module(write_pca_resids_median)
# write out PCA residuals, mean

write_pca_resids_mean = FitsWritingModule(file_name="test_pca_resids_mean.fits",
                              name_in="write_pca_resids_mean",
                              output_dir=output_place,
                              data_tag="mean_residuals")

pipeline.add_module(write_pca_resids_mean)
pipeline.run()<jupyter_output>Validating Pypeline... [DONE]
Running FitsReadingModule... 0.5%
{'fraction_non_alphanumeric': 0.06477987421383648, 'fraction_numerical': 0.00440251572327044, 'mean_word_length': 2.1827885256837893, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '43580', 'license': 'MIT', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1349, 'n_words': 270, 'path': 'pynpoint_make_pcs_good_psfs.ipynb', 'repo_name': 'mwanakijiji/lbti_altair_fizeau', 'size': '4770'}