Exemple #1
0
def external_mass(env, mass_obj, mass_range=None):
    if not prior_included('external_mass'):
        raise GLInputError(
            "The 'external_mass' prior must be included to enable the external_mass() command."
        )
    if mass_range is None:
        min, max = None, None
    else:
        if isinstance(mass_range, (int, long, float)):
            min = max = mass_range
        else:
            min, max = mass_range
            if min is not None and min < 0:
                raise GLInputError(
                    "external_mass: Lower bound 'min' must be at least zero.")
            if max is not None and max < 0:
                raise GLInputError(
                    "external_mass: Upper bound 'max' must be at least zero.")
            if min > max:
                raise GLInputError(
                    "external_mass: Lower bound 'min' must be less than upper bound 'max'."
                )
    env.current_object().prior_options['external mass'][mass_obj] = min, max
    #env.current_object().add_external_mass(mass_obj)
    env.current_object().extra_potentials.append(mass_obj)
Exemple #2
0
def J4_gradient(env, theta=None, theta_min=None):
    o = env.current_object()

    if theta is not None:
        if not (0 < theta <= 90):
            raise GLInputError("J4_gradient: need 0 < theta <= 90")
        o.prior_options['J4gradient']['theta'] = theta
    if theta_min is not None:
        if not (0 < theta_min <= 90):
            raise GLInputError("J4_gradient: need 0 < theta_min <= 90")
        o.prior_options['J4gradient']['theta_min'] = theta_min
Exemple #3
0
def source(env, zsrc, img0=None, img0parity=None, *imgs, **kwargs):

    o = env.current_object()

    if o.z is None: raise GLInputError("zlens() must first be specified.")
    if zsrc < o.z: raise GLInputError("Source is not behind lens.")

    src = Source(env, zsrc, o.z, kwargs.get('zcap', None))

    if kwargs.has_key('position') and kwargs['position'] is not None:
        if not prior_included('source_position'):
            raise GLInputError(
                "The 'source_position' prior must be included when using the position keyword."
            )
        src.pos = complex(kwargs['position'][0], kwargs['position'][1])
        if len(kwargs['position']) == 3:
            src.pos_tol = kwargs['position'][2]

    if img0 is not None and img0parity is not None:
        #       if isinstance(img0[0], (list,tuple)):
        #           image0 = Arc(img0, img0parity)
        #           src.add_arc(image0)
        #       else:
        image0 = Image(img0, img0parity)
        src.add_image(image0)

        prev = image0
        for i in xrange(0, len(imgs), 3):
            img, parity, time_delay = imgs[i:i + 3]
            if time_delay == 0:
                raise GLInputError(
                    'Cannot set a time delay of 0. Use None instead.')
            if prev.parity_name == 'sad' and parity == 'max':
                prev.angle = arctan2(prev.pos.imag - img[1],
                                     prev.pos.real - img[0]) * 180 / pi
            image = Image(img, parity)
            #           if isinstance(img[0], (list,tuple)):
            #               image = Arc(img, parity)
            #               assert len(src.arcs) == len(img)
            #               src.add_arc(image)
            #           else:
            image = Image(img, parity)
            src.add_image(image)
            src.add_time_delay(prev, image, time_delay)
            prev = image

    o.add_source(src)
    return src
Exemple #4
0
def zlens(env, z):
    assert z is not None
    o = env.current_object()
    if o.z is not None:
        raise GLInputError('zlens() can only be called once per object.')
    o.z = z
    o.dL = glass.cosmo.angdist(env, 0, o.z)
Exemple #5
0
def steepness(env, lb, ub):
    if not prior_included('profile_steepness'):
        raise GLInputError(
            "The 'profile_steepness' prior must be included to enable the 'steepness()' command."
        )
    o = env.current_object()
    o.prior_options['steepness'] = [lb, ub]
Exemple #6
0
def source_position_wedge(env, angle):
    o = env.current_object()
    if not (0 <= angle <= 360):
        raise GLInputError(
            'source_position_wedge: Wedge angle must be between 0 and 360 degrees, inclusive.'
        )
    o.prior_options['source_position_quadrant_angle'] = angle
Exemple #7
0
def kann(env, theta):
    if not prior_included('annular_density'):
        raise GLInputError(
            "The 'annular_density' prior must be included to enable the 'kann()' command."
        )
    o = env.current_object()
    o.prior_options['annular_density'] = theta
Exemple #8
0
def universe_age(env, *args):
    """Set age of the Universe in Gyr"""
    if len(env.objects) != 0:
        raise GLInputError(
            'universe_age() must be used before any objects are created.')
    nu = convert('age in Gyr to nu', array(args), glass.cosmo.age_factor(env))
    env.nu = array([nu[-1], nu[0]])
Exemple #9
0
def shear(env, strength=0.1):
    if not prior_included('external_shear'):
        raise GLInputError(
            "The 'external_shear' prior must be included to enable the shear() command."
        )
    env.current_object().extra_potentials.append(Shear(shift=strength))
    env.current_object().prior_options['shear']['strength'] = strength
Exemple #10
0
def hubble_time(env, *args):
    """Set H0^-1 (or a range) in Gyr"""
    #print env, args
    if len(env.objects) != 0:
        raise GLInputError(
            'hubble_time() must be used before any objects are created.')
    nu = convert('H0^-1 in Gyr to nu', array(args))
    env.nu = array([nu[-1], nu[0]])
Exemple #11
0
def local_gradient(env, theta=None, L=None):
    o = env.current_object()
    #if not prior_included('J3gradient'): raise GLInputError("The 'J3gradient' prior must be included to enable the 'local_gradient()' command.")

    if theta is not None:
        if not (0 < theta <= 90):
            raise GLInputError("local_gradient: need 0 < theta <= 90")
        o.prior_options['J3gradient']['theta'] = theta
        o.prior_options['J2Gradient']['theta'] = theta

    if L is not None: o.prior_options['J3gradient']['size'] = L
    if L is not None: o.prior_options['J2Gradient']['size'] = L
Exemple #12
0
def maxsteep(*args, **kwargs):
    raise GLInputError("maxsteep not supported. Use steepness().")
Exemple #13
0
def global_gradient(env, theta):
    if not (0 < theta <= 90):
        raise GLInputError("dgcone: need 0 < theta <= 90")
    o = env.current_object()
    o.prior_options['gradient'] = np.radians(90 - theta)
Exemple #14
0
def omega(env, om, ol):
    if len(env.objects) != 0:
        raise GLInputError(
            'omega() must be used before any objects are created.')
    env.omega_matter = om
    env.omega_lambda = ol
Exemple #15
0
def hires(env, r, refine=1):
    if not (r > 0 and refine >= 3 and refine % 2 == 1):
        raise GLInputError(
            'hires: Minimum refinement value is 3. Must be odd too.')
    env.current_object().basis.hiresR = r
    env.current_object().basis.hires_levels = refine
Exemple #16
0
def t0(*args):
    raise GLInputError('t0() no longer supported, use hubble_time().')
Exemple #17
0
def quad(*args):
    raise GLInputError("quad() not supported. Use source().")
Exemple #18
0
def double(*args):
    raise GLInputError("double() not supported. Use source().")
Exemple #19
0
def redshifts(*args):
    raise GLInputError("redshifts not implemented.")
Exemple #20
0
def hubble_constant(env, *args):
    """Set H0 (or a range) in km/s/Mpc"""
    if len(env.objects) != 0:
        raise GLInputError(
            'hubble_constant() must be used before any objects are created.')
    env.nu = convert('H0 in km/s/Mpc to nu', array(args))
Exemple #21
0
def dgcone(*args, **kwargs):
    raise GLInputError("dgcone not supported. Use global_gradient().")
Exemple #22
0
def subdiv(env, n):
    n = int(n)
    if (n % 2 != 1): raise GLInputError("subdiv: n must be odd")
    env.current_object().basis.subdivision = n
Exemple #23
0
def meta(env, *args, **kwargs):
    if len(args) != 0: raise GLInputError('meta() only takes named arguments')
    env.meta_info = kwargs
Exemple #24
0
def multi(*args):
    raise GLInputError("multi() not supported. Use source().")
Exemple #25
0
def ptmass(xc, yc, mmin, mmax):
    raise GLInputError("ptmass not supported. Use external_mass().")