Ejemplo n.º 1
0
def lrstso_sim_config(mode='lrs', arr='SLITLESSPRISM', ngrp=None, nint=None, nexp=1, webbpsf=True, scene_file=None, out=True):
	
	'''
	Function to set up the imaging TSO simulation. Arguments:
	- mode: the MIRI mode to use (default='lrs') [string]
	- arr: array configureation (default='SLITLESSPRISM') [string]
	- ngrp: the number of groups (minimum of 2 required; minimum of 5 is recommended) [integer]
	- nint: number of integrations [integer]
	- nexp: number of exposures (default = 1, as recommended for TSOs) [integer]
	- scene_file: scene filename, as returned by the scene generation function [string]
	- out: set to True if you want to write the sim configuration out to file (default=True)[boolean]
	
	
	Notes on other simulation parameters, as we are only using this function for imaging simulations:
	- POP: always 'IMA'
	- parameters disperser, detector and mrs_* are included in teh list but NOT ACCESSED
	- ima_mode: always use FAST mode for TSOs
	
	'''
	
	if (mode == 'lrs') & (arr == 'SLITLESSPRISM'):
		op_path = 'IMA'
		cfg = 'LRS_SLITLESS'
		filt = 'P750L'
		
	else:
		raise ValueError("This mode is not supported in this function.")
		
	if arr not in ['SLITLESSPRISM']:
		raise ValueError("Array configuration not supported for LRS slitless TSOs.")
		
	if os.path.exists(scene_file):
		print("Found scene file {0}".format(scene_file))
	else:
		raise ValueError('Scene file not found.')
	
	if ngrp < 2:
		raise ValueError("Number of groups must be 2 or larger.")
		
	fbase = scene_file.split('_')[0]
	simname = '{3}_{4}_{0}G{1}I{2}E'.format(ngrp, nint, nexp, fbase, arr)
	
	sim_config = SimConfig.makeSim(
	    name = simname,    # name given to simulation
	    scene = scene_file, # name of scene file to input
	    rel_obsdate = 1.0,          # relative observation date (0 = launch, 1 = end of 5 yrs)
	    POP = op_path,                # Component on which to center (Imager or MRS)
	    ConfigPath = cfg,  # Configure the Optical path (MRS sub-band)
	    Dither = False,             # Don't Dither
	    StartInd = 1,               # start index for dither pattern [NOT USED HERE]
	    NDither = 2,                # number of dither positions [NOT USED HERE]
	    DitherPat = 'ima_recommended_dither.dat', # dither pattern to use [NOT USED HERE]
	    disperser = 'SHORT',        # [NOT USED HERE]
	    detector = 'SW',            # [NOT USED HERE]
	    mrs_mode = 'SLOW',          # [NOT USED HERE]
	    mrs_exposures = 10,          # [NOT USED HERE]
	    mrs_integrations = 3,       # [NOT USED HERE]
	    mrs_frames = 5,             # [NOT USED HERE]
	    ima_exposures = nexp,          # number of exposures
	    ima_integrations = nint,       # number of integrations
	    ima_frames = ngrp,             # number of groups (for MIRI, # Groups = # Frames)
	    ima_mode = 'FAST',          # Imager read mode (default is FAST ~ 2.3 s)
	    filter = filt,          # Imager Filter to use
	    readDetect = arr         # Portion of detector to read out,
	)	
	
	
	# write the simulation config out to file, if out was set to True. the output filename is the simname, followed b the number of groups, ints and exp, for easy reference.
	simout = '{0}_simconfig.ini'.format(simname)
	if out:
		sim_config.write(simout)
	
	# set up the simulator "under the hood". deafult values can be accepted here.
	simulator_config = SimulatorConfig.from_default()
	
	# set the simulator configuration to use WebbPSF
	if webbpsf:
		print('**** Simulation will use the WebbPSF model ****')
		simulator_config['LRSSim']['take_webbPsf'] = 'T'
	
	return simout
Ejemplo n.º 2
0
# ### Step 3: Run the simulation
#
# In the following step we'll run the simulations for the 6 different cases. For each run, we need 3 input files: the scene, the simulation configuration, and the simulator setup file. The first and last of these remain the same for each run, and we loop through the list of 6 simulation config files.
#
# After the simulation has run, the code renames the output directory to include the simulation settings to the directory.
#

# In[10]:

cfg_files = glob.glob('*_simconfig.ini')
print(cfg_files)

# In[11]:

# configure the simulator engine - this requires no editing from the default
simulator_config = SimulatorConfig.from_default()

for f in cfg_files[:1]:
    tmp = f.split('.')
    fcomps = tmp[0].split('_')
    sim = MiriSimulation.from_configfiles(f)
    sim.run()
    outdir = sorted(glob.glob('*_*_mirisim'), key=os.path.getmtime)[-1]
    new_outdir = 'wasp103_imtso_{0}_{1}_{2}'.format(fcomps[1], fcomps[2],
                                                    outdir)
    os.rename(outdir, new_outdir)
    print(outdir, new_outdir)

# ### Step 3: Minor housekeeping to make the sim pipeline-ready
#
# To make the MIRISim data ready for the TSO-specific pipeline, we have to make a couple of small changes to the data:
    def simulate_test_data(self):
        """
        Run the MIRISim simulations
        """
        # simulation config
        if self.instrument == 'IMA':
            sim_config = SimConfig.makeSim(
                name="IMA Simulation",
                rel_obsdate=0.0,
                scene="scene.ini",
                POP='IMA',
                ConfigPath='IMA_FULL',
                Dither=False,
                StartInd=1,
                NDither=4,
                DitherPat="ima_recommended_dither.dat",
                filter="F1130W",
                readDetect='FULL',
                ima_mode='FAST',
                ima_exposures=1,
                ima_integrations=1,
                ima_frames=50,
                disperser='SHORT',
                detector='SW',
                mrs_mode='SLOW',
                mrs_exposures=5,
                mrs_integrations=4,
                mrs_frames=10)

            # scene config
            background = Background(level='low',
                                    gradient=5.,
                                    pa=15.0,
                                    centreFOV=(0., 0.))

            SED1 = BBSed(Temp=300., wref=10., flux=1.e8)
            Gal1 = Galaxy(Cen=(0., 0.), n=1., re=200, q=0.99, pa=0.1)
            Gal1.set_SED(SED1)
            targets = [Gal1]

            scene_config = SceneConfig.makeScene(loglevel=0,
                                                 background=background,
                                                 targets=targets)

        elif self.instrument == 'MRS':
            sim_config = SimConfig.makeSim(
                name="MRS Simulation",
                rel_obsdate=0.0,
                scene="scene.ini",
                POP='MRS',
                ConfigPath='MRS_1SHORT',
                Dither=False,
                StartInd=1,
                NDither=4,
                DitherPat="mrs_recommended_dither.dat",
                filter="F1130W",
                readDetect='FULL',
                ima_mode='FAST',
                ima_exposures=1,
                ima_integrations=1,
                ima_frames=20,
                disperser='SHORT',
                detector='SW',
                mrs_mode='FAST',
                mrs_exposures=1,
                mrs_integrations=1,
                mrs_frames=50)

            # scene config
            background = Background(level='low',
                                    gradient=5.,
                                    pa=15.0,
                                    centreFOV=(0., 0.))

            SED1 = BBSed(Temp=300., wref=10., flux=5.e6)
            Gal1 = Galaxy(Cen=(0., 0.), n=1., re=2, q=0.99, pa=0.1)
            Gal1.set_SED(SED1)
            targets = [Gal1]

            scene_config = SceneConfig.makeScene(loglevel=0,
                                                 background=background,
                                                 targets=targets)

        # simulator config
        if self.noise:
            simulator_config = SimulatorConfig.makeSimulator(
                max_fsm=0.050,
                max_dither=20.0,
                mrs_ref_channel=1,
                mrs_ref_band="SHORT",
                tau_telescope=0.88,
                tau_eol=0.8,
                telescope_area=25.032,
                telescope_pupil_diam=6.6052,
                take_webbPsf=False,
                include_refpix=True,
                include_poisson=True,
                include_readnoise=True,
                include_badpix=True,
                include_dark=True,
                include_flat=False,
                include_gain=True,
                include_nonlinearity=self.linearity,
                include_drifts=True,
                include_latency=False,
                cosmic_ray_mode='NONE')
        else:
            simulator_config = SimulatorConfig.makeSimulator(
                max_fsm=0.050,
                max_dither=20.0,
                mrs_ref_channel=1,
                mrs_ref_band="SHORT",
                tau_telescope=0.88,
                tau_eol=0.8,
                telescope_area=25.032,
                telescope_pupil_diam=6.6052,
                take_webbPsf=False,
                include_refpix=True,
                include_poisson=False,
                include_readnoise=False,
                include_badpix=True,
                include_dark=True,
                include_flat=False,
                include_gain=True,
                include_nonlinearity=self.linearity,
                include_drifts=True,
                include_latency=False,
                cosmic_ray_mode='NONE')

        # run the simulation
        simulation = MiriSimulation(sim_config=sim_config,
                                    scene_config=scene_config,
                                    simulator_config=simulator_config,
                                    loglevel='DEBUG')
        simulation.run()

        # we only need the sim file so move it to output_dir and remove everthing else
        det_image_file = glob.glob(
            os.path.join(simulation.path_out, 'det_images', '*.fits'))[0]
        self.ramp_file = os.path.join(self.output_dir,
                                      os.path.basename(det_image_file))
        shutil.move(det_image_file, self.ramp_file)
        shutil.rmtree(simulation.path_out)
    detector = 'SW',            # [NOT USED HERE]
    mrs_mode = 'SLOW',          # [NOT USED HERE]
    mrs_exposures = 10,          # [NOT USED HERE]
    mrs_integrations = 3,       # [NOT USED HERE]
    mrs_frames = 5,             # [NOT USED HERE]
    ima_exposures = 1,          # number of exposures
    ima_integrations = 1,       # number of integrations
    ima_frames = 15,             # number of groups (for MIRI, # Groups = # Frames)
    ima_mode = 'FAST',          # Imager read mode (default is FAST ~ 2.3 s)
    filter = 'P750L',          # Imager Filter to use
    readDetect = 'FULL'         # Portion of detector to read out
)

sim_config_dither.write('LMC-81_simulation_slitdither.ini')

simulator_config = SimulatorConfig.makeSimulator(take_webbPsf=True)

lmc81_sim2 = MiriSimulation(sim_config_dither, scene_config, simulator_config)
lmc81_sim2.run()


# THIRD SIMULATION: SLITLESS
#sim_config_slitless = SimConfig.makeSim(
#    name = 'LMC-81_lrsslitless',    # name given to simulation
#    scene = 'lmc_81_scene.ini', # name of scene file to input
#    rel_obsdate = 1.0,          # relative observation date (0 = launch, 1 = end of 5 yrs)
#    POP = 'IMA',                # Component on which to center (Imager or MRS)
#    ConfigPath = 'LRS_SLITLESS',  # Configure the Optical path (MRS sub-band)
#    Dither = False,             # Nod along the slit
#    StartInd = 1,               # start index for dither pattern [NOT USED HERE]
#    NDither = 2,                # number of dither positions [NOT USED HERE]