Esempio n. 1
0
def cdf_inv(z, r, rho):
    """
    Calculates the inverse CDF as a function of r over the whole disk
    
    Parameters
    ----------
    
    z : SimArray or array
        2D z-positions that rho is calculated at.  z[i,j] is the ith z bin
        at r[j]
    r : SimArray or array
        Radial bins (1D array) the z and rho are calculated at
    rho : SimArray or array
        2D array of density values.  rho[i,j] is rho at z[i,j], r[j]
        
    Returns
    -------
    
    f : function
        Inverse CDF.  f(m, r) = z returns the z value for radius and 0<m<1.
        r and m are 1-D arrays of the same length, or numbers.
    """
    
    nz, nr = z.shape
    f = np.zeros(z.shape)
    zout = 0.*z
    for i in range(nr):
        
        f[:,i], zout[:,i] = cdf_inv_z(z[:,i], rho[:,i])
        
    cdf_inv_spl = meshinterp(r, f.T, zout.T)
    
    def fspl(m, R):
        """
        Normalized inverse CDF at R.  Calcuates z as a function of m
        
        Parameters
        ----------
        
        m : 1D array or float
            Number(s) between 0 and 1
        R : 1D SimArray, array, or float
            Radius at which to calculate the CDF inverse along rho
        
        Returns
        -------
        
        z : SimArray
            z positions 
        """
        return cdf_inv_spl(R, m)
        
    return fspl
Esempio n. 2
0
def cdf_inv(z, r, rho):
    """
    Calculates the inverse CDF as a function of r over the whole disk
    
    Parameters
    ----------
    
    z : SimArray or array
        2D z-positions that rho is calculated at.  z[i,j] is the ith z bin
        at r[j]
    r : SimArray or array
        Radial bins (1D array) the z and rho are calculated at
    rho : SimArray or array
        2D array of density values.  rho[i,j] is rho at z[i,j], r[j]
        
    Returns
    -------
    
    f : function
        Inverse CDF.  f(m, r) = z returns the z value for radius and 0<m<1.
        r and m are 1-D arrays of the same length, or numbers.
    """

    nz, nr = z.shape
    f = np.zeros(z.shape)
    zout = 0. * z
    for i in range(nr):

        f[:, i], zout[:, i] = cdf_inv_z(z[:, i], rho[:, i])

    cdf_inv_spl = meshinterp(r, f.T, zout.T)

    def fspl(m, R):
        """
        Normalized inverse CDF at R.  Calcuates z as a function of m
        
        Parameters
        ----------
        
        m : 1D array or float
            Number(s) between 0 and 1
        R : 1D SimArray, array, or float
            Radius at which to calculate the CDF inverse along rho
        
        Returns
        -------
        
        z : SimArray
            z positions 
        """
        return cdf_inv_spl(R, m)

    return fspl
Esempio n. 3
0
def rhointerp(z, r, rho):
    """
    Generates a callable interpolation of rho on the z, r points
    
    Parameters
    ----------
    
    z : 2D SimArray or array
        z[i,j] is the ith z value at r[j]
    r : 1D SimArray or array
        Radial positions
    rho : SimArray
        density at points z[i,j], r[j]
        
    Returns
    -------
    
    rhospline : function
        An interpolation function for estimating rho as a function of z, r
    """
    
    f = meshinterp(r, z.T, rho.T)
    
    def rhospline(Z, R):
        """
        Returns rho evaluated at Z, R.  Z and R must be 1D and the same length
        
        Parameters
        ----------
        
        Z, R : SimArray, array, or float
            Z, R positions to estimate the density at.  Must be same length
            
        Returns
        -------
        
        rho : SimArray
            Density evaluated at the Z,R positions
        """
        return f(R, Z)
        
    return rhospline
Esempio n. 4
0
def rhointerp(z, r, rho):
    """
    Generates a callable interpolation of rho on the z, r points
    
    Parameters
    ----------
    
    z : 2D SimArray or array
        z[i,j] is the ith z value at r[j]
    r : 1D SimArray or array
        Radial positions
    rho : SimArray
        density at points z[i,j], r[j]
        
    Returns
    -------
    
    rhospline : function
        An interpolation function for estimating rho as a function of z, r
    """

    f = meshinterp(r, z.T, rho.T)

    def rhospline(Z, R):
        """
        Returns rho evaluated at Z, R.  Z and R must be 1D and the same length
        
        Parameters
        ----------
        
        Z, R : SimArray, array, or float
            Z, R positions to estimate the density at.  Must be same length
            
        Returns
        -------
        
        rho : SimArray
            Density evaluated at the Z,R positions
        """
        return f(R, Z)

    return rhospline