<commit_before>"""
    Handle Q smearing
"""
#####################################################################
#This software was developed by the University of Tennessee as part of the
#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
#project funded by the US National Science Foundation. 
#See the license text in license.txt
#copyright 2008, University of Tennessee
######################################################################
import math
import logging
import sys

import numpy as np  # type: ignore
from numpy import pi, exp # type:ignore

from sasmodels.resolution import Slit1D, Pinhole1D
from sasmodels.sesans import SesansTransform
from sasmodels.resolution2d import Pinhole2D
from .nxsunit import Converter

def smear_selection(data, model = None):
    """
    Creates the right type of smearer according
    to the data.
    The canSAS format has a rule that either
    slit smearing data OR resolution smearing data
    is available.

    For the present purpose, we choose the one that
    has none-zero data. If both slit and resolution
    smearing arrays are filled with good data
    (which should not happen), then we choose the
    resolution smearing data.

    :param data: Data1D object
    :param model: sas.model instance
    """
    # Sanity check. If we are not dealing with a SAS Data1D
    # object, just return None
    # This checks for 2D data (does not throw exception because fail is common)
    if  data.__class__.__name__ not in ['Data1D', 'Theory1D']:
        if data == None:
            return None
        elif data.dqx_data == None or data.dqy_data == None:
            return None
        return PySmear2D(data)
    # This checks for 1D data with smearing info in the data itself (again, fail is likely; no exceptions)
    if  not hasattr(data, "dx") and not hasattr(data, "dxl")\
         and not hasattr(data, "dxw"):
        return None

    # Look for resolution smearing data
    # This is the code that checks for SESANS data; it looks for the file loader
    # TODO: change other sanity checks to check for file loader instead of data structure?
    _found_sesans = False
    #if data.dx is not None and data.meta_data['loader']=='SESANS':
    if data.dx is not None and data.isSesans:
        #if data.dx[0] > 0.0:
        if np.size(data.dx[data.dx <= 0]) == 0:
            _found_sesans = True
        # if data.dx[0] <= 0.0:
        if np.size(data.dx[data.dx <= 0]) > 0:
            raise ValueError('one or more of your dx values are negative, please check the data file!')

    if _found_sesans == True:
        #Pre-compute the Hankel matrix (H)
        SElength = Converter(data._xunit)(data.x, "A")

        theta_max = Converter("radians")(data.sample.zacceptance)[0]
        q_max = 2 * np.pi / np.max(data.source.wavelength) * np.sin(theta_max)
        zaccept = Converter("1/A")(q_max, "1/" + data.source.wavelength_unit),

        Rmax = 10000000
        hankel = SesansTransform(data.x, SElength, data.source.wavelength, zaccept, Rmax)
        # Then return the actual transform, as if it were a smearing function
        return PySmear(hankel, model, offset=0)

    _found_resolution = False
    if data.dx is not None and len(data.dx) == len(data.x):

        # Check that we have non-zero data
        if data.dx[0] > 0.0:
            _found_resolution = True
            #print "_found_resolution",_found_resolution
            #print "data1D.dx[0]",data1D.dx[0],data1D.dxl[0]
    # If we found resolution smearing data, return a QSmearer
    if _found_resolution == True:
         return pinhole_smear(data, model)<commit_msg>Pass flake8 and pylint for changes in qsmearing<commit_after>"""
    Handle Q smearing
"""
#####################################################################
#This software was developed by the University of Tennessee as part of the
#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
#project funded by the US National Science Foundation. 
#See the license text in license.txt
#copyright 2008, University of Tennessee
######################################################################
import math
import logging
import sys

import numpy as np  # type: ignore
from numpy import pi, exp # type:ignore

from sasmodels.resolution import Slit1D, Pinhole1D
from sasmodels.sesans import SesansTransform
from sasmodels.resolution2d import Pinhole2D
from .nxsunit import Converter

def smear_selection(data, model = None):
    """
    Creates the right type of smearer according
    to the data.
    The canSAS format has a rule that either
    slit smearing data OR resolution smearing data
    is available.

    For the present purpose, we choose the one that
    has none-zero data. If both slit and resolution
    smearing arrays are filled with good data
    (which should not happen), then we choose the
    resolution smearing data.

    :param data: Data1D object
    :param model: sas.model instance
    """
    # Sanity check. If we are not dealing with a SAS Data1D
    # object, just return None
    # This checks for 2D data (does not throw exception because fail is common)
    if  data.__class__.__name__ not in ['Data1D', 'Theory1D']:
        if data == None:
            return None
        elif data.dqx_data == None or data.dqy_data == None:
            return None
        return PySmear2D(data)
    # This checks for 1D data with smearing info in the data itself (again, fail is likely; no exceptions)
    if  not hasattr(data, "dx") and not hasattr(data, "dxl")\
         and not hasattr(data, "dxw"):
        return None

    # Look for resolution smearing data
    # This is the code that checks for SESANS data; it looks for the file loader
    # TODO: change other sanity checks to check for file loader instead of data structure?
    _found_sesans = False
    #if data.dx is not None and data.meta_data['loader']=='SESANS':
    if data.dx is not None and data.isSesans:
        #if data.dx[0] > 0.0:
        if np.size(data.dx[data.dx <= 0]) == 0:
            _found_sesans = True
        # if data.dx[0] <= 0.0:
        if np.size(data.dx[data.dx <= 0]) > 0:
            raise ValueError('one or more of your dx values are negative, please check the data file!')

    if _found_sesans:
        # Pre-compute the Hankel matrix (H)
        SElength = Converter(data._xunit)(data.x, "A")

        theta_max = Converter("radians")(data.sample.zacceptance)[0]
        q_max = 2 * np.pi / np.max(data.source.wavelength) * np.sin(theta_max)
        zaccept = Converter("1/A")(q_max, "1/" + data.source.wavelength_unit),

        Rmax = 10000000
        hankel = SesansTransform(data.x, SElength,
                                 data.source.wavelength,
                                 zaccept, Rmax)
        # Then return the actual transform, as if it were a smearing function
        return PySmear(hankel, model, offset=0)

    _found_resolution = False
    if data.dx is not None and len(data.dx) == len(data.x):

        # Check that we have non-zero data
        if data.dx[0] > 0.0:
            _found_resolution = True
            #print "_found_resolution",_found_resolution
            #print "data1D.dx[0]",data1D.dx[0],data1D.dxl[0]
    # If we found resolution smearing data, return a QSmearer
    if _found_resolution == True:
         return pinhole_smear(data, model)
{'fraction_non_alphanumeric': 0.11726295742075908, 'fraction_numerical': 0.012923411780710107, 'mean_word_length': 2.916888652104422, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5614338', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2109, 'n_words': 807}