# Path: osrefl/loaders/reduction/correction.py
# class Correction(object):
#     properties = []  # Property sheet for interacting with correction
#     def apply(self, data):
#         """
#         Apply the correction to the dataset, modifying the dataset
#         in the process.  The data is returned, allowing users to
#         apply multiple corrections in one step:
#              C2(C1(data))
#         Each correction will automatically be logged in the data using
#         data.log(str(Correction))
#         """
#         raise NotImplementedError
# 
#     def __str__(self):
#         """
#         Name of the correction, and enough detail to record in the
#         reduced data log.
#         """
#         raise NotImplementedError
# 
#     # ==== Inherited behaviours ====
#     def __call__(self, data):
#         data = copy(data)
#         data.log(str(self))
#         self.apply(data)
#         return data
# 
#     def __or__(self, other):
#         # "Correction | Correction" forms a pipeline
#         if isinstance(other,Correction):
#             return Pipeline([self,other])
#         raise NotImplementedError
# 
#     def __ror__(self, other):
#         # "Pipeline | Correction" is handled by pipeline
#         # "data | Correction" applies the correction to the data
#         if not isinstance(other, Pipeline):
#             return self(other)
#         raise NotImplementedError
# 
# Path: osrefl/loaders/reduction/fresnel.py
# class Fresnel:
#     """
#     Function for computing the Fresnel reflectivity for a single interface.
# 
#     rho,Vrho
#         scattering length density of substrate and vacuum
#     mu,Vmu
#         absorption of substrate and vacuum (note that we do not correct
#         for attenuation of the beam through the incident medium since we
#         do not know the path length).
#     sigma (angstrom)
#         interfacial roughness
#     """
#     def __init__(self, rho=1e-6, mu=0, sigma=0, Vrho=0, Vmu=0):
#         self.rho,self.Vrho,self.mu,self.Vmu,self.sigma = rho,Vrho,mu,Vmu,sigma
# 
#     def reflectivity(self, Q, L=1):
#         """
#         Compute the Fresnel reflectivity at the given Q/wavelength.
#         """
#         # If Q < 0, then we are going from substrate into incident medium.
#         # In that case we must negate the change in scattering length density
#         # and ignore the absorption.
#         drho = self.rho-self.Vrho
#         S = 4*pi*choose(Q<0,(-drho,drho)) \
#             + 2j*pi/L*choose(Q<0,(self.Vmu,self.mu))
#         kz = abs(Q)/2
#         f = sqrt(kz**2 - S)  # fresnel coefficient
# 
#         # Compute reflectivity amplitude, with adjustment for roughness
#         amp = (kz-f)/(kz+f) * exp(-2*self.sigma**2*kz*f)
#         # Note: we do not need to check for a divide by zero.
#         # Qc^2 = 16 pi rho.  Since rho is non-zero then Qc is non-zero.
#         # For mu = 0:
#         # * If |Qz| < Qc then f has an imaginary component, so |Qz|+f != 0.
#         # * If |Qz| > Qc then |Qz| > 0 and f > 0, so |Qz|+f != 0.
#         # * If |Qz| = Qc then |Qz| != 0 and f = 0, so |Qz|+f != 0.
#         # For mu != 0:
#         # * f has an imaginary component, so |Q|+f != 0.
# 
#         R = real(amp*conj(amp))
#         return R
# 
#     # Make the reflectivity method the default
#     __call__ = reflectivity


from math import *
from .correction import Correction
from .fresnel import Fresnel
    from reflectometry.reduction import normalize
    from .examples import ng7 as dataset
import reflectometry.model1d as reflfit
import numpy
    import pylab
profile changes as a function of angle, thus making it impossible
to measure the beam intensity directly.

Even with the ratio scan the reduction may need a scaling
step to recover the absolute intensity.

Note that we will assume that slit opening as a function of
angle is identical for the measured intensity and the measured
reflection.

We will also assume that the intensity scan and the measured
reflection are performed on blanks with identical geometery
so the footprint is the same on both.  No footprint correction
will be required.

Example::

    # Compute the intensity scan assuming that data measures
    # the specular reflection off 85% water, 15% deuterated water.
    data.apply(WaterIntensity(D2O=15))

"""
from __future__ import with_statement


# The module (__init__.py of model1d) is not part of osrefl.


__all__ = ['RatioIntensity', 'WaterIntensity']


# Path: osrefl/loaders/reduction/correction.py
# class Correction(object):
#     properties = []  # Property sheet for interacting with correction
#     def apply(self, data):
#         """
#         Apply the correction to the dataset, modifying the dataset
#         in the process.  The data is returned, allowing users to
#         apply multiple corrections in one step:
#              C2(C1(data))
#         Each correction will automatically be logged in the data using
#         data.log(str(Correction))
#         """
#         raise NotImplementedError
# 
#     def __str__(self):
#         """
#         Name of the correction, and enough detail to record in the
#         reduced data log.
#         """
#         raise NotImplementedError
# 
#     # ==== Inherited behaviours ====
#     def __call__(self, data):
#         data = copy(data)
#         data.log(str(self))
#         self.apply(data)
#         return data
# 
#     def __or__(self, other):
#         # "Correction | Correction" forms a pipeline
#         if isinstance(other,Correction):
#             return Pipeline([self,other])
#         raise NotImplementedError
# 
#     def __ror__(self, other):
#         # "Pipeline | Correction" is handled by pipeline
#         # "data | Correction" applies the correction to the data
#         if not isinstance(other, Pipeline):
#             return self(other)
#         raise NotImplementedError
# 
# Path: osrefl/loaders/reduction/fresnel.py
# class Fresnel:
#     """
#     Function for computing the Fresnel reflectivity for a single interface.
# 
#     rho,Vrho
#         scattering length density of substrate and vacuum
#     mu,Vmu
#         absorption of substrate and vacuum (note that we do not correct
#         for attenuation of the beam through the incident medium since we
#         do not know the path length).
#     sigma (angstrom)
#         interfacial roughness
#     """
#     def __init__(self, rho=1e-6, mu=0, sigma=0, Vrho=0, Vmu=0):
#         self.rho,self.Vrho,self.mu,self.Vmu,self.sigma = rho,Vrho,mu,Vmu,sigma
# 
#     def reflectivity(self, Q, L=1):
#         """
#         Compute the Fresnel reflectivity at the given Q/wavelength.
#         """
#         # If Q < 0, then we are going from substrate into incident medium.
#         # In that case we must negate the change in scattering length density
#         # and ignore the absorption.
#         drho = self.rho-self.Vrho
#         S = 4*pi*choose(Q<0,(-drho,drho)) \
#             + 2j*pi/L*choose(Q<0,(self.Vmu,self.mu))
#         kz = abs(Q)/2
#         f = sqrt(kz**2 - S)  # fresnel coefficient
# 
#         # Compute reflectivity amplitude, with adjustment for roughness
#         amp = (kz-f)/(kz+f) * exp(-2*self.sigma**2*kz*f)
#         # Note: we do not need to check for a divide by zero.
#         # Qc^2 = 16 pi rho.  Since rho is non-zero then Qc is non-zero.
#         # For mu = 0:
#         # * If |Qz| < Qc then f has an imaginary component, so |Qz|+f != 0.
#         # * If |Qz| > Qc then |Qz| > 0 and f > 0, so |Qz|+f != 0.
#         # * If |Qz| = Qc then |Qz| != 0 and f = 0, so |Qz|+f != 0.
#         # For mu != 0:
#         # * f has an imaginary component, so |Q|+f != 0.
# 
#         R = real(amp*conj(amp))
#         return R
# 
#     # Make the reflectivity method the default
#     __call__ = reflectivity


# Path: osrefl/loaders/reduction/ratiocor.py
from math import *
from .correction import Correction
from .fresnel import Fresnel
    from reflectometry.reduction import normalize
    from .examples import ng7 as dataset
import reflectometry.model1d as reflfit
import numpy
    import pylab

profile changes as a function of angle, thus making it impossible
to measure the beam intensity directly.

Even with the ratio scan the reduction may need a scaling
step to recover the absolute intensity.

Note that we will assume that slit opening as a function of
angle is identical for the measured intensity and the measured
reflection.

We will also assume that the intensity scan and the measured
reflection are performed on blanks with identical geometery
so the footprint is the same on both.  No footprint correction
will be required.

Example::

    # Compute the intensity scan assuming that data measures
    # the specular reflection off 85% water, 15% deuterated water.
    data.apply(WaterIntensity(D2O=15))

"""
from __future__ import with_statement


# The module (__init__.py of model1d) is not part of osrefl.


__all__ = ['RatioIntensity', 'WaterIntensity']


class RatioIntensity(Correction):