<commit_before>#!/usr/bin/env python2
# -*- coding: utf8 -*-
from __future__ import division, print_function

import argparse
import astropy.io.fits as pyfits
import logging
import numpy as np
import time

from scipy import ndimage, stats
from numpy import ma

__author__ = '<NAME>'


class WCal:
    def __init__(self, log=None):
        self.log = self.get_logger() if log is None else log
        return

    def center_peak(self, data, center):
        """
        Based on the most probable center position, rolls the line so it lies in
        the center of the data-cube.
        """
        cube_center = data.shape[0] // 2
        shift_size = cube_center - center
        data = np.roll(data, shift_size, axis=0)

        return data

    def find_current_peak_position(self, data):
        """
        Finds the current average peak position.
        :param data: a phase-corrected datacube.
        :type data: numpy.ndarray

        :return peak_position: the central channel.
        :rtype peak_position: int
        """
        log = self.log
        log.info('Finding current peak position.')
        data = data.sum(axis=2)
        data = data.sum(axis=1)
        peak_position = np.argmax(data)

        around_peak = np.arange(5) - 2
        around_peak = np.delete(around_peak, 2)
        around_peak += peak_position
        around_peak = np.where(around_peak < 0, 0, around_peak)
        around_peak = np.where(around_peak > data.size - 1, data.size - 1,
                               around_peak)

        is_peak = True
        for i in range(around_peak.size):
            p = data[around_peak[i]] < data[peak_position]
            is_peak *= p
            log.debug(
                'Comparing %d and %d frames - %s' % (
                    peak_position, around_peak[i], 'True' if p else 'False'))

        return peak_position

        # depth = data.shape[0]

        # data = ndimage.median_filter(data, size=[3, 1, 1])
        # data = ma.MaskedArray(data, mask=np.zeros_like(data))
        #
        # peaks = np.argmax(data, axis=0)
        #
        # for i in range(interactions):
        #
        #     peak_neighbors = (peaks
        #         + np.arange(5, dtype=int)[:, np.newaxis, np.newaxis] - 2)
        #
        #     peak_neighbors = np.where(peak_neighbors > 0, peak_neighbors, 0)
        #     peak_neighbors = np.where(peak_neighbors < depth - 1,
        #                               peak_neighbors, depth - 1)
        #
        #     peak_neighbors = np.delete(peak_neighbors, 2, 0)
        #<commit_msg>Did not do anything really.<commit_after>#!/usr/bin/env python2
# -*- coding: utf8 -*-
from __future__ import division, print_function

import argparse
import astropy.io.fits as pyfits
import logging
import numpy as np
import time

from scipy import ndimage, stats
from numpy import ma

__author__ = '<NAME>'


class WCal:
    def __init__(self, log=None):
        self.log = self.get_logger() if log is None else log
        return

    def center_peak(self, data, center):
        """
        Based on the most probable center position, rolls the line so it lies in
        the center of the data-cube.
        """
        cube_center = data.shape[0] // 2
        shift_size = cube_center - center
        data = np.roll(data, shift_size, axis=0)

        return data

    def find_current_peak_position(self, data):
        """
        Finds the current average peak position.
        :param data: a phase-corrected datacube.
        :type data: numpy.ndarray

        :return peak_position: the central channel.
        :rtype peak_position: int
        """
        log = self.log
        log.info('Finding current peak position.')
        data = data.sum(axis=2)
        data = data.sum(axis=1)
        peak_position = np.argmax(data)

        around_peak = np.arange(5) - 2
        around_peak = np.delete(around_peak, 2)
        around_peak += peak_position
        around_peak = np.where(around_peak < 0, 0, around_peak)
        around_peak = np.where(around_peak > data.size - 1, data.size - 1, around_peak)

        is_peak = True
        for i in range(around_peak.size):
            p = data[around_peak[i]] < data[peak_position]
            is_peak *= p
            log.debug('Comparing %d and %d frames - %s' % (peak_position, around_peak[i], 'True' if p else 'False'))

        return peak_position

        # depth = data.shape[0]

        # data = ndimage.median_filter(data, size=[3, 1, 1])
        # data = ma.MaskedArray(data, mask=np.zeros_like(data))
        #
        # peaks = np.argmax(data, axis=0)
        #
        # for i in range(interactions):
        #
        #     peak_neighbors = (peaks
        #         + np.arange(5, dtype=int)[:, np.newaxis, np.newaxis] - 2)
        #
        #     peak_neighbors = np.where(peak_neighbors > 0, peak_neighbors, 0)
        #     peak_neighbors = np.where(peak_neighbors < depth - 1,
        #                               peak_neighbors, depth - 1)
        #
        #     peak_neighbors = np.delete(peak_neighbors, 2, 0)
        #
{'fraction_non_alphanumeric': 0.10404738400789733, 'fraction_numerical': 0.010661401776900297, 'mean_word_length': 1.9643066120538326, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2733135', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1570, 'n_words': 417}