Ejemplo n.º 1
0
def check_chip_positions(filename="src.fits",
                         x_cen=17.084,
                         y_cen=17.084,
                         n=0.3,
                         mode="wide"):
    """
    Creates a series of grids of stars and generates the output images

    THe number of stars in each grid corresponds to the id number of the chip
    """


    x = [-x_cen]*1 + [0]*2 + [x_cen]*3 + \
        [-x_cen]*4 + [0]*5 + [x_cen]*6 + \
        [-x_cen]*7 + [0]*8 + [x_cen]*9

    y = [-y_cen + i*n for i in range(1)] + \
        [-y_cen + i*n for i in range(2)] + \
        [-y_cen + i*n for i in range(3)] + \
        [0 + i*n for i in range(4)] + \
        [0 + i*n for i in range(5)] + \
        [0 + i*n for i in range(6)] + \
        [y_cen + i*n for i in range(7)] + \
        [y_cen + i*n for i in range(8)] + \
        [y_cen + i*n for i in range(9)]

    lam, spec = sim.source.SED("A0V", "Ks", 15)
    src = sim.source.Source(lam=lam, spectra=spec, x=x, y=y, ref=[0] * len(x))

    sim.run(src, detector_layout="full", filename=filename, mode=mode)
Ejemplo n.º 2
0
def test_source_resample_equivalency():

    n = 8

    im = np.ones((100, 100))
    lam, spec = sim.source.SED("M0V", "K", 20)
    src = sim.source.source_from_image(im, lam, spec, 0.004, oversample=n)
    hdu, (cmd, opt, fpa) = sim.run(src, return_internals=True)

    im = np.ones((n * 100, n * 100)) / (n**2)
    lam, spec = sim.source.SED("M0V", "K", 20)
    src2 = sim.source.source_from_image(im, lam, spec, 0.004 / n, oversample=1)
    hdu2, (cmd2, opt2, fpa2) = sim.run(src2, return_internals=True)

    diff = np.sum(np.abs(fpa2.chips[0].array) - np.abs(fpa.chips[0].array)) / \
                                                    np.sum(fpa.chips[0].array)

    assert diff < 1E-4
Ejemplo n.º 3
0
def MakeImage(src,
              exp_time=60,
              ndit=1,
              fov='wide',
              chip='centre',
              filter='V',
              ao_mode='scao',
              file_name=default_image_file_name,
              internals=None,
              return_int=False):
    """Make the image with SimCADO.
    exp_time = time in seconds, ndit = number of exposures taken.
    fov = mode = ['wide', 'zoom']: field of view 53 arcsec (4 mas/pixel) or 16 (1.5 mas/pixel)
    chip = detector_layout = ['small', 'centre', 'full']: 
        1024x1024 pix, one whole detector (4096x4096 pix) or full array of 9 detectors
    filter = the filter used in the 'observation'
    ao_mode = PSF file used [scao, ltao, (mcao not available yet)]
    """
    savename = os.path.join('images', file_name)
    if (savename[-5:] != '.fits'):
        savename += '.fits'

    if internals is not None:
        cmd, opt, fpa = internals
    else:
        cmd, opt, fpa = None, None, None

    image_int = sim.run(src,
                        filename=savename,
                        mode=fov,
                        detector_layout=chip,
                        filter_name=filter,
                        SCOPE_PSF_FILE=ao_mode,
                        OBS_EXPTIME=exp_time,
                        OBS_NDIT=ndit,
                        cmds=cmd,
                        opt_train=opt,
                        fpa=fpa,
                        return_internals=return_int,
                        FPA_LINEARITY_CURVE='FPA_linearity.dat')

    if return_int:
        image, internals = image_int
        return image, internals
    else:
        image = image_int
        return image
Ejemplo n.º 4
0
def _make_snr_grid_fpas(filter_names=["J", "H", "Ks"],
                        mmin=22,
                        mmax=32,
                        cmds=None,
                        **kwargs):
    """
    Makes a series of :class:`.Detector` objects containing a grid of stars


    Parameters
    ----------
    filter_names : list
        Which filters to use for the images. See ``simcado.optices.get_filter_set()``

    mmin, mmax : float
        [mag] Minimum and maximum magnitudes to use for the grid of stars

    cmds : simcado.UserCommands
        A custom set of commands for building the optical train

    Optional Parameters
    -------------------
    Any Keyword-Value pairs accepted by a
    :class:`~simcado.commands.UserCommands` object

    Returns
    -------
    fpas : list
        A list of :class:`Detector` objects with the grid of stars for each filter
        len(fpas) == len(filter_names)
    grid : simcado.Source
        A :class:`Source` object containing the grids of stars

    See Also
    --------
    :class:`~simcado.commands.UserCommands`

    """

    if isinstance(filter_names, str):
        filter_names = [filter_names]

    if not isinstance(cmds, list):
        cmds = [cmds] * len(filter_names)

    fpas = []
    grids = []
    for filt, cmd in zip(filter_names, cmds):
        if cmd is None:
            cmd = sim.UserCommands()
        #cmd["FPA_USE_NOISE"] = "no"
        cmd["OBS_NDIT"] = 1
        cmd["FPA_LINEARITY_CURVE"] = "none"
        cmd["FPA_CHIP_LAYOUT"] = "small"
        cmd.update(kwargs)

        star_sep = cmd["SIM_DETECTOR_PIX_SCALE"] * 100

        grid = sim.source.star_grid(100,
                                    mmin,
                                    mmax,
                                    filter_name=filt,
                                    separation=star_sep)
        grids += [grid]

        hdus, (cmd, opt, fpa) = sim.run(grid,
                                        filter_name=filt,
                                        cmds=cmd,
                                        return_internals=True)
        fpas += [fpa]

    return fpas, grid
Ejemplo n.º 5
0
def make_uniform_dense_core_image(mass, dist_mod, side_width=1024, filename=None, 
                                  n_stack=1, pix_res=0.004, **kwargs):
    """
    Makes an image with a uniformly random distribution of stars from an IMF
    
    Parameter
    ---------
    mass : float
        [Msun]
    
    dist_mod : float
        [mag] 
    
    side_width : int
        [pixel]
        
    filename : str
        
    n_stack : int
    
    pix_res : float
        [arcsec/pixel] Default is MICADO Wide: 4mas/px


    Optional Parameters
    -------------------
    SCOPE_PSF_FILE
    OBS_REMOVE_CONST_BG
    OBS_EXPTIME

    """
    
    params = {"SCOPE_PSF_FILE" : None,
              "OBS_REMOVE_CONST_BG" : "yes",
              "OBS_EXPTIME" : 60}
    params.update(kwargs)
    
    density = mass / (side_width * pix_res)**2
    
    masses = imf_population(mass=mass)
    mags = abs_mag_from_mass(masses) + dist_mod
    n_stars = len(masses)
    x, y = np.random.randint(-side_width//2, side_width, (2, n_stars)) 

    src = sim.source.stars(mags=mags, x=x, y=y, pix_unit="pixel")

    hdu, (cmd, opt, fpa) = sim.run(src, return_internals=True, **kwargs)

    for i in range(1, n_stack):
        hdu[0].data += fpa.read_out()[0].data   

    if filename is None:
        filename = "rho="+str(int(density))+".tbl"
    
    tbl = Table(data=[x, y, masses, mags], names=["x", "y", "masses", "mags"])
    tbl.write(filename, format="fits",  overwrite=True)
    
    f = fits.open(filename)
    hdu.append(f[1])
    hdu.writeto(filename.replace(".tbl", ".fits"), clobber=True)
    f.close()
    
    return hdu
Ejemplo n.º 6
0
def test_centre_chip_with_single_star_all_defaults():
    src = sim.source.star(mag=20, filter_name="Ks")
    hdu = sim.run(src, detector_layout="centre")
    
    assert np.max(hdu[0].data) > 9000
Ejemplo n.º 7
0
def test_quick_sim_with_single_star_all_defaults():
    src = sim.source.star(mag=20, filter_name="Ks")
    hdu = sim.run(src)
    
    assert np.max(hdu[0].data) > 9000