<commit_before># -*- coding: utf8 -*-
"""Contains the tools to produce a wavelength solution

This module gets the extracted data to produce a wavelength solution, linearize
the spectrum and write the solution to the image's header following the FITS
standard.
"""

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import ccdproc
import glob
import logging
import os
import re
import sys

import astropy.units as u

import matplotlib.pyplot as plt
import numpy as np
import scipy.interpolate
from astropy.convolution import convolve, Gaussian1DKernel, Box1DKernel
from astropy.modeling import models, fitting
from astropy.stats import sigma_clip
from ccdproc import CCDData
from matplotlib.backends.backend_pdf import PdfPages
from scipy import signal

from ..wcs.wcs import WCS

from ..core import (bin_reference_data,
                    cross_correlation,
                    evaluate_wavelength_solution,
                    get_spectral_characteristics,
                    get_lines_in_lamp,
                    linearize_spectrum,
                    recenter_broad_lines,
                    recenter_lines,
                    write_fits)

from ..core import (ReferenceData)

log = logging.getLogger(__name__)

SHOW_PLOTS = False


class WavelengthCalibration(object):
    """Wavelength Calibration Class

    The WavelengthCalibration class is instantiated for each of the science
    images, which are treated as a "science object". In this first release it
    can find a wavelength solution for a given comparison lamp using an
    interactive GUI based on Matplotlib. Although it works very good, for the
    next release there is a plan for creating an independent GUI based on QT in
    order to work better in different screen sizes and other topic such as
    showing warnings, messages and help.

    This class takes 1D spectrum with no wavelength calibration and returns fits
    files with wavelength solutions using the FITS standard for linear
    solutions. Goodman spectra are slightly non-linear therefore they are
    linearized and smoothed before they are returned for the user.

    """

    def __init__(self, args):
        """Wavelength Calibration Class Initialization

        A WavelengthCalibration class is instantiated for each science target
        being processed, i.e. every science image.

        Notes:
            This class violates some conventions as for length and number of
            attributes is concerned. Solving this is part of a prioritary plans
            for next release.

        Args:
            args (Namespace): Runtime arguments.

        """

        self.log = logging.getLogger(__name__)
        self.args = args
        self.poly_order = 3
        self.wcs = WCS()
        self.wsolution = None
        self.wcal_lamp_file = None
        self.sci_target_file = None
        self.n_points = None
        self.n_rejections = None
        self.rms_error = None
        self.cross_corr_tolerance = 5
        # print(self.args.reference_dir)
        self.reference_data = ReferenceData(self.args.reference_dir)
        # self.science_object = science_object
        self.slit_offset = None
        self.interpolation_size = 200
        self.line_search_method = 'derivative'
        # Instrument configuration and spectral characteristics
        self.pixel_size = 15 * u.micrometer
        self.pixel_scale = 0.15 * u.arcsec
        self.goodman_focal_length = 377.3 * u.mm
        self.grating_frequency = None
        self.grating_angle = None
        self.camera_angle = None
        self.serial_binning = None
        self.parallel_binning = None

        self.pixel_count = None
        self.alpha = None
        self.beta = None
        self.center_wavelength = None
        self.blue_limit = None
        self.red_limit = None
        # Interactive wavelength finding
        self.reference_marks_x = []
        self.reference_marks_y = []
        self.raw_data_marks_x = []
        self.raw_data_marks_y = []
        self.click_input_enabled = True
        self.reference_bb = None
        self.raw_data_bb = None
        self.contextual_bb = None
        self.i_fig = None
        self.ax1 = None
        self.ax2 = None
        self.ax3 = None
        self.ax4 = None
        self.ax4_plots = None
        self.ax4_com = None
        self.ax4_rlv = None
        self.legends = None
        self.points_ref = None
        self.points_raw = None
        self.line_raw = None
        self.ref_filling_value = 1000
        self.raw_filling_value = 1000
        self.events = True
        self.first = True
        self.evaluation_comment = None
        # self.binning = self.lamp.header[]
        self.pixel_center = []
        # this data must come parsed
        self.path = self.args.source
        # self.science_pack = sci_pack
        # self.sci_filename = self.science_object.file_name
        # self.history_of_lamps_solutions = {}
        self.reference_solution = None

    def __call__(self,
                 ccd,
                 comp_list,
                 object_number=None,<commit_msg>code cleanup, removing unused class attributes<commit_after># -*- coding: utf8 -*-
"""Contains the tools to produce a wavelength solution

This module gets the extracted data to produce a wavelength solution, linearize
the spectrum and write the solution to the image's header following the FITS
standard.
"""

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import glob
import logging
import os
import re
import sys

import astropy.units as u

import matplotlib.pyplot as plt
import numpy as np

from astropy.stats import sigma_clip
from ccdproc import CCDData
from matplotlib.backends.backend_pdf import PdfPages

from ..wcs.wcs import WCS

from ..core import (bin_reference_data,
                    cross_correlation,
                    evaluate_wavelength_solution,
                    get_spectral_characteristics,
                    get_lines_in_lamp,
                    linearize_spectrum,
                    recenter_broad_lines,
                    recenter_lines,
                    write_fits)

from ..core import (ReferenceData)

log = logging.getLogger(__name__)


class WavelengthCalibration(object):
    """Wavelength Calibration Class

    The WavelengthCalibration class is instantiated for each of the science
    images, which are treated as a "science object". In this first release it
    can find a wavelength solution for a given comparison lamp using an
    interactive GUI based on Matplotlib. Although it works very good, for the
    next release there is a plan for creating an independent GUI based on QT in
    order to work better in different screen sizes and other topic such as
    showing warnings, messages and help.

    This class takes 1D spectrum with no wavelength calibration and returns fits
    files with wavelength solutions using the FITS standard for linear
    solutions. Goodman spectra are slightly non-linear therefore they are
    linearized and smoothed before they are returned for the user.

    """

    def __init__(self, args):
        """Wavelength Calibration Class Initialization

        A WavelengthCalibration class is instantiated for each science target
        being processed, i.e. every science image.

        Notes:
            This class violates some conventions as for length and number of
            attributes is concerned. Solving this is part of a prioritary plans
            for next release.

        Args:
            args (Namespace): Runtime arguments.

        """

        self.log = logging.getLogger(__name__)
        self.args = args
        self.poly_order = 3
        self.wcs = WCS()
        self.wsolution = None
        self.wcal_lamp_file = None
        self.sci_target_file = None
        self.n_points = None
        self.n_rejections = None
        self.rms_error = None
        self.cross_corr_tolerance = 5
        self.reference_data = ReferenceData(self.args.reference_dir)

        # Instrument configuration and spectral characteristics
        self.pixel_size = 15 * u.micrometer
        # self.pixel_scale = 0.15 * u.arcsec
        self.goodman_focal_length = 377.3 * u.mm
        self.serial_binning = None
        self.parallel_binning = None

        self.evaluation_comment = None
        # self.binning = self.lamp.header[]
        self.pixel_center = []
        # this data must come parsed
        self.path = self.args.source
        # self.science_pack = sci_pack
        # self.sci_filename = self.science_object.file_name
        # self.history_of_lamps_solutions = {}
        self.reference_solution = None

    def __call__(self,
                 ccd,
                 comp_list,
                 object_number=None,
{'fraction_non_alphanumeric': 0.053381587876046147, 'fraction_numerical': 0.005202442886224836, 'mean_word_length': 2.3107450393111195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3509653', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2261, 'n_words': 789}