# Functions for converting between measures of squeezing using the ADF
# y = exp(z) in the notation of PhysRevD.105.122005
# the conversions are done using the alternative OPO configuration
# shown in Fig 6(a)

import numpy as np


def nlg2y(nlg, r1=np.sqrt(0.93)):
    gb = np.sqrt(nlg)
    return gb / (1 + r1 * (gb - 1))


def y2G(y, r1=np.sqrt(0.93)):
    return (y - r1) / (1 / y - r1)


def nlg2G(nlg):
    """Convert from NLG to the anti-SQZ/SQZ ratio
    """
    return y2G(nlg2y(nlg))


def y2nlg(y, r1=np.sqrt(0.93)):
    return ((1 - r1) / (1 / y - r1))**2


def G2nlg(G):
    """Convert from the anti-SQZ/SQZ ratio to NLG
    """
    return y2nlg(G2y(G))


def G2y(G, r1=np.sqrt(0.93)):
    sqrt = np.sqrt(r1**2 * (G - 1)**2 + 4 * G)
    return (-r1 * (G - 1) + sqrt) / 2
