コード例 #1
0
    def sim_ints(self, factors):
        """
        simulate the ints
        """
        for n, f in enumerate(factors):

            int_scene = self.make_int_scene(f)

            int_sim = SimConfig.makeSim(name="LRS Simulation", rel_obsdate=0.0, scene="scene.ini",
                              POP='IMA', ConfigPath='LRS_SLITLESS', Dither=False, StartInd=0, NDither=2,
                              DitherPat="lrs_recommended_dither.dat", filter="P750L", readDetect='FULL',
                              ima_mode='FAST', ima_exposures=1, ima_integrations=1, ima_frames=20,
                              disperser='SHORT', detector='SW', mrs_mode='SLOW', mrs_exposures=5,
                              mrs_integrations=4, mrs_frames=10)

            lrs_sim = MiriSimulation(sim_config=int_sim, scene_config=int_scene,
                                          simulator_config=self.simulator_config, loglevel='DEBUG')

            lrs_sim.run()

            new_dir = "int%d" % n
            if os.path.isdir(new_dir):
                shutil.rmtree(new_dir)

            os.rename(lrs_sim.path_out, new_dir)
コード例 #2
0
    def run(self):
        """
        run the simulation and rename output dir
        """
        # simulate the ints
        factors1 = np.arange(10)
        factors2 = np.flipud(factors1)
        factors = np.concatenate((factors1, factors2))


        self.sim_ints(factors)

        # simulate with len(factors) ints
        self.lrs_scene_config = SceneConfig.from_default()
        self.lrs_sim = MiriSimulation(sim_config=self.lrs_slitless_sim_config,scene_config=self.lrs_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.lrs_sim.run()

        new_dir = "LRS-SLITLESS"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.lrs_sim.path_out , new_dir)

        # get the names of the int directors
        int_dirs = sorted(glob.glob('int*'))

        # replace the
        self.replace_ints(new_dir, int_dirs)
コード例 #3
0
class MRSDemoData():
    """
    Class to create MRS demo data
    """
    def __init__(self):
        """
        setup the MIRISim config objects
        """
        self.mrs_sim_config = SimConfig.makeSim(name="MRS Simulation",rel_obsdate=0.0,scene="scene.ini",
                                   POP='MRS',ConfigPath='MRS_1SHORT',Dither=True,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=2,mrs_frames=50)

        self.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=True,include_badpix=True,include_dark=True,
                                                         include_flat=True,include_gain=True,include_nonlinearity=True,
                                                         include_drifts=True,include_latency=True, cosmic_ray_mode='NONE')

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

        # set PL SED
        SED1 = PLSed(alpha=0.0, wref=10., flux=1.e4)
        Point1 = Point(Cen=(0., 0.), vel=0.0)
        Point1.set_SED(SED1)

        Point2 = Point(Cen=(0., 0.), vel=0.0)
        SED2 = LinesSed(wavels=[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
                        fluxes=[5e+03, 4e+03, 3e+03, 2e+03, 2e+03, 1e+03, 1e+03, 9e+02, 8e+02, 7e+02, 6e+02, 5e+02,
                                4e+02, 3e+02, 3e+02, 3e+02, 3e+02, 2e+02, 2e+02, 2e+02, 2e+02],
                        fwhms=[0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05,
                               0.05, 0.05, 0.05, 0.05, 0.05, 0.05, ])
        Point2.set_SED(SED2)

        # load point to targets list
        targets = [Point1,Point2]

        # create the object
        self.mrs_scene_config = SceneConfig.makeScene(loglevel=0,background=background,targets=targets)


    def run(self):
        """
        run the simulation and rename output dir
        """
        self.mrs_sim = MiriSimulation(sim_config=self.mrs_sim_config,scene_config=self.mrs_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.mrs_sim.run()

        new_dir = "MRS"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.mrs_sim.path_out , new_dir)
コード例 #4
0
    def run(self):
        """
        run the simulation and rename output dir
        """
        self.lrs_sim = MiriSimulation(sim_config=self.lrs_slit_sim_config,scene_config=self.lrs_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.lrs_sim.run()

        new_dir = "LRS-SLIT"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.lrs_sim.path_out , new_dir)

        # background
        self.lrs_bkg_sim = MiriSimulation(sim_config=self.lrs_slit_bkg_sim_config,scene_config=self.lrs_bkg_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.lrs_bkg_sim.run()

        new_dir = "LRS-SLIT_BKG"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.lrs_bkg_sim.path_out, new_dir)
コード例 #5
0
 def run_sim(self, simcfg, scenecfg, simulatorcfg):
     """
     Take the scene, simulation, and simulator config objects and run
     simulation
     """
     mysim = MiriSimulation(simcfg, scenecfg, simulatorcfg)
     mysim.run()
コード例 #6
0
    def run(self):
        """
        run the simulation and rename output dir
        """
        self.ima_sim = MiriSimulation(sim_config=self.ima_sim_config,scene_config=self.ima_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.ima_sim.run()

        new_dir = "IMA"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.ima_sim.path_out , new_dir)
コード例 #7
0
class IMADemoData():
    """
    Class to create IMA demo data
    """
    def __init__(self):
        """
        setup the MIRISim config objects
        """
        self.ima_sim_config = SimConfig.makeSim(name="IMA Simulation",rel_obsdate=0.0,scene="scene.ini",
                                       POP='IMA',ConfigPath='IMA_FULL',Dither=True,StartInd=1,
                                       NDither=4,DitherPat="ima_recommended_dither.dat",filter="F1130W",
                                       readDetect= 'FULL',ima_mode= 'FAST',ima_exposures=1,ima_integrations=2,
                                       ima_frames=50,disperser= 'SHORT',detector= 'SW',mrs_mode= 'SLOW',
                                       mrs_exposures=5,mrs_integrations=4,mrs_frames=10)

        self.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=True,include_gain=True,include_nonlinearity=True,
                                                         include_drifts=True,include_latency=False,
                                                              cosmic_ray_mode='SOLAR_MIN')

        self.ima_scene_config = make_simple_cat_scene_obj(target_coords=[1.0,1.0],random=True, source_num=500,
                                                    centre_coords=[1.0,1.0])


    def run(self):
        """
        run the simulation and rename output dir
        """
        self.ima_sim = MiriSimulation(sim_config=self.ima_sim_config,scene_config=self.ima_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.ima_sim.run()

        new_dir = "IMA"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.ima_sim.path_out , new_dir)
コード例 #8
0
class LRSSlitDemoData():
    """
    Class to create LRS Slit demo data
    """
    def __init__(self):
        """
        setup the MIRISim config objects
        """
        self.lrs_slit_sim_config = SimConfig.makeSim(name="LRS Simulation",rel_obsdate=0.0,scene="scene.ini",
                                       POP='IMA',ConfigPath='LRS_SLIT',Dither=True, StartInd=1,
                                       NDither=2,DitherPat="lrs_recommended_dither.dat",filter="P750L",
                                       readDetect= 'FULL',ima_mode= 'FAST',ima_exposures=1,ima_integrations=2,
                                       ima_frames=50,disperser= 'SHORT',detector= 'SW',mrs_mode= 'SLOW',
                                       mrs_exposures=5,mrs_integrations=4,mrs_frames=10)

        self.lrs_slit_bkg_sim_config = SimConfig.makeSim(name="LRS Simulation", rel_obsdate=0.0, scene="scene.ini",
                                                     POP='IMA', ConfigPath='LRS_SLIT', Dither=False, StartInd=2,
                                                     NDither=2, DitherPat="lrs_recommended_dither.dat", filter="P750L",
                                                     readDetect='FULL', ima_mode='FAST', ima_exposures=1,
                                                     ima_integrations=2,
                                                     ima_frames=50, disperser='SHORT', detector='SW', mrs_mode='SLOW',
                                                     mrs_exposures=5, mrs_integrations=4, mrs_frames=10)

        self.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=True,include_gain=True,include_nonlinearity=True,
                                                         include_drifts=True,include_latency=False,
                                                              cosmic_ray_mode='SOLAR_MIN')

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

        SED1 = PLSed(alpha=0.0, wref=10., flux=1.e4)
        Point1 = Point(Cen=(0., 0.))
        Point1.set_SED(SED1)

        Point2 = Point(Cen=(0., 0.))

        SED2 = LinesSed(wavels=[6, 7, 8, 9, 10, 11, 12],
                        fluxes=[5e+03, 4e+03, 3e+03, 3e+03, 3e+03, 3e+03, 3e+03],
                        fwhms=[0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05])
        Point2.set_SED(SED2)

        # set a background SED and object
        SED3 = BBSed(Temp=300., wref=10., flux=1.e-1)
        Gal1 = Galaxy(Cen=(0.,0.), n=2., re=50, q=0.9, pa=0.1)
        Gal1.set_SED(SED3)

        # load point to targets list
        targets = [Point1, Point2, Gal1]
        bkg_targets = [Gal1]


        # create the object
        self.lrs_scene_config = SceneConfig.makeScene(loglevel=0, background=background, targets=targets)

        self.lrs_bkg_scene_config = SceneConfig.makeScene(loglevel=0, background=background, targets=bkg_targets)


    def run(self):
        """
        run the simulation and rename output dir
        """
        self.lrs_sim = MiriSimulation(sim_config=self.lrs_slit_sim_config,scene_config=self.lrs_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.lrs_sim.run()

        new_dir = "LRS-SLIT"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.lrs_sim.path_out , new_dir)

        # background
        self.lrs_bkg_sim = MiriSimulation(sim_config=self.lrs_slit_bkg_sim_config,scene_config=self.lrs_bkg_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.lrs_bkg_sim.run()

        new_dir = "LRS-SLIT_BKG"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.lrs_bkg_sim.path_out, new_dir)
コード例 #9
0
class LRSSlitlessDemoData():
    """
    Class to create LRS Slitless demo data. Need to simulate n integrations where there is variation
    in an absorption line and combine these into a combined 4d array
    """
    def __init__(self):
        """
        setup the MIRISim config objects
        """
        self.lrs_slitless_sim_config = SimConfig.makeSim(name="LRS Simulation",rel_obsdate=0.0,scene="scene.ini",
                                       POP='IMA',ConfigPath='LRS_SLITLESS',Dither=False,StartInd=0,NDither=2,
                                       DitherPat="lrs_recommended_dither.dat",filter="P750L",readDetect= 'FULL',
                                       ima_mode= 'FAST',ima_exposures=3,ima_integrations=20,ima_frames=20,
                                       disperser= 'SHORT',detector= 'SW',mrs_mode= 'SLOW',mrs_exposures=5,
                                       mrs_integrations=4,mrs_frames=10)

        self.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=True,include_gain=True,include_nonlinearity=True,
                                                         include_drifts=True,include_latency=False,
                                                              cosmic_ray_mode='SOLAR_MIN')


    def make_int_scene(self, factor):
        """
        return a scene config where the strength of an absorption line varies according to factor.
        """

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

        # set SED
        Point1 = Point(Cen=(0., 0.))
        Point2 = Point(Cen=(0., 0.))
        Point3 = Point(Cen=(0., 0.))

        bb = BBSed(Temp=300., wref=10., flux=1.e4)

        lines = LinesSed(wavels=[6, 7, 8, 9, 10, 11, 12],
                        fluxes=[5e+03, 4e+03, 3e+03, 3e+03, 3e+03, 3e+03, 3e+03],
                        fwhms=[0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05])

        abs_line = LinesSed(wavels=[9.0], fluxes=[-1e4 * factor], fwhms=[1.0])

        Point1.set_SED(bb)
        Point2.set_SED(lines)
        Point3.set_SED(abs_line)

        # load point to targets list
        targets = [Point1, Point2, Point3]

        # return the scene object
        return SceneConfig.makeScene(loglevel=0, background=background, targets=targets)

    def sim_ints(self, factors):
        """
        simulate the ints
        """
        for n, f in enumerate(factors):

            int_scene = self.make_int_scene(f)

            int_sim = SimConfig.makeSim(name="LRS Simulation", rel_obsdate=0.0, scene="scene.ini",
                              POP='IMA', ConfigPath='LRS_SLITLESS', Dither=False, StartInd=0, NDither=2,
                              DitherPat="lrs_recommended_dither.dat", filter="P750L", readDetect='FULL',
                              ima_mode='FAST', ima_exposures=1, ima_integrations=1, ima_frames=20,
                              disperser='SHORT', detector='SW', mrs_mode='SLOW', mrs_exposures=5,
                              mrs_integrations=4, mrs_frames=10)

            lrs_sim = MiriSimulation(sim_config=int_sim, scene_config=int_scene,
                                          simulator_config=self.simulator_config, loglevel='DEBUG')

            lrs_sim.run()

            new_dir = "int%d" % n
            if os.path.isdir(new_dir):
                shutil.rmtree(new_dir)

            os.rename(lrs_sim.path_out, new_dir)

    def replace_ints(self, dir, int_dirs):
        """
        replace the integrations in the full array with the int arrays
        """
        my_output_files = glob.glob(os.path.join(dir, 'det_images', '*.fits'))

        for f in my_output_files:
            out_dm = datamodels.open(f)

            for n, i in enumerate(int_dirs):
                my_int_file = glob.glob(os.path.join(i, 'det_images', '*.fits'))[0]
                int_dm = datamodels.open(my_int_file)

                out_dm.data[n] = int_dm.data

            out_dm.save(f)


    def run(self):
        """
        run the simulation and rename output dir
        """
        # simulate the ints
        factors1 = np.arange(10)
        factors2 = np.flipud(factors1)
        factors = np.concatenate((factors1, factors2))


        self.sim_ints(factors)

        # simulate with len(factors) ints
        self.lrs_scene_config = SceneConfig.from_default()
        self.lrs_sim = MiriSimulation(sim_config=self.lrs_slitless_sim_config,scene_config=self.lrs_scene_config,
                                simulator_config=self.simulator_config,loglevel= 'DEBUG')

        self.lrs_sim.run()

        new_dir = "LRS-SLITLESS"
        if os.path.isdir(new_dir):
            shutil.rmtree(new_dir)

        os.rename(self.lrs_sim.path_out , new_dir)

        # get the names of the int directors
        int_dirs = sorted(glob.glob('int*'))

        # replace the
        self.replace_ints(new_dir, int_dirs)
コード例 #10
0
    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)
コード例 #11
0
# 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:
#
# * add the TSOVISIT = TRUE to the primary header
# * make sure the
コード例 #12
0
def break_mirisim_scene(imager=True, ima_filters=False, ima_subarrays=False, ima_readmodes=True,
                 dither=False, noise=True):
    """
    """
    # set cwd
    cwd = os.getcwd()

    # set the output directory
    out_dir = os.path.join(cwd,'mirisim_scene_functional_tests')
    try: shutil.rmtree(out_dir)
    except: pass
    os.mkdir(out_dir)

    # set the output figure directory
    out_fig_dir = os.path.join(cwd,'mirisim_scene_functional_tests','simulation_plots')
    try: shutil.rmtree(out_fig_dir)
    except: pass
    os.mkdir(out_fig_dir)

    # move to out_dir
    os.chdir(out_dir)

    # set up logging
    log_file = os.path.join(out_dir,'test_MIRISim_scene.log')
    testing_logger = logging.getLogger(__name__)
    testing_logger.setLevel(logging.DEBUG)
    handler = logging.FileHandler(log_file)
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    testing_logger.addHandler(handler)

    # generate the default simultor config object
    simulator_cfg = make_simulator_config(noise=noise)

    # imager simulations
    if imager == True:
        testing_logger.info('Starting imager simulations')

        if ima_subarrays == True:
            modes = ['FULL','BRIGHTSKY', 'SUB256', 'SUB128', 'SUB64']
        else: modes = ['FULL']  # set as default

        if ima_filters == True:
            im_filters = ['F560W', 'F770W', 'F1000W', 'F1130W', 'F1280W', 'F1500W',
                          'F1800W', 'F2100W', 'F2550W', 'F1065C', 'F1140C',
                          'F1550C', 'F2300C', 'F2550WR']
        else: im_filters = ['F1130W']  # set as default

        if ima_readmodes == True:
            read_modes = ['FAST', 'SLOW']
        else: read_modes = ['FAST']  # set as default

        # set observation parameters (hardcoded for now)
        ndither = 2
        exposures=1
        integrations=1

        # sources with no vel distribution
        src_types = ['point', 'galaxy', 'exp_disk', 'sersic_disk', 'pysynphot']
        src_specs = ['bb', 'pl']

        for mode in modes:
            for im_filter in im_filters:
                for read_mode in read_modes:
                    for src_type in src_types:
                        for src_spec in src_specs:

                            scene_cfg = make_scene_config(src_type=src_type, src_spec=src_spec)

                            # set the number of groups depending on the readout mode
                            if read_mode == 'FAST': groups=50
                            elif read_mode == 'SLOW': groups=10

                            sim_dir = 'IMA_' + mode + '_' + im_filter + '_' + read_mode + '_dithering-' + str(dither) + \
                                      '_' + src_type + '_' + src_spec
                            sim_fig = sim_dir + '.pdf'
                            os.mkdir(sim_dir)
                            os.chdir(sim_dir)

                            sim_cfg = make_ima_sim_config(mode=mode, dither=dither, ndither=ndither,
                                                            filter=im_filter,readmode=read_mode,
                                                            exposures=exposures, integrations=integrations,
                                                            groups=groups)

                            print('Simulating %s' % sim_dir)
                            try:
                                mysim = MiriSimulation(sim_cfg, scene_cfg, simulator_cfg)
                                mysim.run()

                                # log pass
                                testing_logger.info('%s passed' % sim_dir)

                                if dither == False:
                                    fig,axs = plt.subplots(1, 2)
                                    fig.set_figwidth(12.0)
                                    fig.set_figheight(6.0)
                                elif dither == True:
                                    fig,axs = plt.subplots(2,2)
                                    fig.set_figwidth(12.0)
                                    fig.set_figheight(12.0)
                                #plt.tight_layout(pad=0.5)
                                axs = axs.ravel()
                                axs_index = -1

                                # plot output, illumination model and last frame of first integration (only one per exposure)
                                illum_file = get_output_product('illum')
                                illum_datamodel = miri_illumination_model.MiriIlluminationModel(illum_file)

                                axs_index += 1
                                axs[axs_index].imshow(illum_datamodel.intensity[0], cmap='jet', interpolation='nearest', norm=LogNorm(), origin='lower')
                                axs[axs_index].annotate(sim_dir, xy=(0.0,1.02), xycoords='axes fraction', fontsize=14, fontweight='bold', color='k')
                                axs[axs_index].annotate('illum_model', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                det_file = get_output_product('det_image')
                                det_datamodel = datamodels.open(det_file)

                                axs_index += 1
                                vmin = np.median(det_datamodel.data[0][-1]) * 0.9
                                vmax = np.median(det_datamodel.data[0][-1]) * 4
                                axs[axs_index].imshow(det_datamodel.data[0][-1], cmap='jet', interpolation='nearest', norm=LogNorm(vmin=vmin, vmax=vmax), origin='lower')
                                axs[axs_index].annotate('det_image', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                if dither == True:
                                    illum_file = get_output_product('illum', dither=True)
                                    illum_datamodel = miri_illumination_model.MiriIlluminationModel(illum_file)

                                    axs_index += 1
                                    axs[axs_index].imshow(illum_datamodel.intensity[0], cmap='jet', interpolation='nearest', norm=LogNorm(), origin='lower')
                                    axs[axs_index].annotate('dither position 2', xy=(0.0,1.02), xycoords='axes fraction', fontsize=12, fontweight='bold', color='k')
                                    axs[axs_index].annotate('illum_model', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                    det_file = get_output_product('det_image', dither=True)
                                    det_datamodel = datamodels.open(det_file)

                                    axs_index += 1
                                    axs[axs_index].imshow(det_datamodel.data[0][-1], cmap='jet', interpolation='nearest', norm=LogNorm(vmin=vmin, vmax=vmax), origin='lower')
                                    axs[axs_index].annotate('det_image', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                fig.savefig(os.path.join(out_fig_dir,sim_fig), dpi=200)
                                del fig

                            except Exception as e:
                                testing_logger.warning('%s failed' % sim_dir)
                                testing_logger.warning('  %s: %s' % (e.__class__.__name__, str(e)))

                            os.chdir(out_dir)

        # pysnphot
        for mode in modes:
            for im_filter in im_filters:
                for read_mode in read_modes:

                            scene_cfg = make_scene_config(src_type='pysynphot')

                            # set the number of groups depending on the readout mode
                            if read_mode == 'FAST':
                                groups = 50
                            elif read_mode == 'SLOW':
                                groups = 10

                            sim_dir = 'IMA_' + mode + '_' + im_filter + '_' + read_mode + '_dithering-' + str(dither) + \
                                     '_pysynphot'
                            sim_fig = sim_dir + '.pdf'
                            os.mkdir(sim_dir)
                            os.chdir(sim_dir)

                            sim_cfg = make_ima_sim_config(mode=mode, dither=dither, ndither=ndither,
                                                          filter=im_filter, readmode=read_mode,
                                                          exposures=exposures,
                                                          integrations=integrations,
                                                          groups=groups)

                            print('Simulating %s' % sim_dir)
                            try:
                                mysim = MiriSimulation(sim_cfg, scene_cfg, simulator_cfg)
                                mysim.run()

                                # log pass
                                testing_logger.info('%s passed' % sim_dir)

                                if dither == False:
                                    fig, axs = plt.subplots(1, 2)
                                    fig.set_figwidth(12.0)
                                    fig.set_figheight(6.0)
                                elif dither == True:
                                    fig, axs = plt.subplots(2, 2)
                                    fig.set_figwidth(12.0)
                                    fig.set_figheight(12.0)
                                # plt.tight_layout(pad=0.5)
                                axs = axs.ravel()
                                axs_index = -1

                                # plot output, illumination model and last frame of first integration (only one per exposure)
                                illum_file = get_output_product('illum')
                                illum_datamodel = miri_illumination_model.MiriIlluminationModel(
                                    illum_file)

                                axs_index += 1
                                axs[axs_index].imshow(illum_datamodel.intensity[0], cmap='jet',
                                                      interpolation='nearest', norm=LogNorm(),
                                                      origin='lower')
                                axs[axs_index].annotate(sim_dir, xy=(0.0, 1.02),
                                                        xycoords='axes fraction', fontsize=14,
                                                        fontweight='bold', color='k')
                                axs[axs_index].annotate('illum_model', xy=(0.7, 0.95),
                                                        xycoords='axes fraction', fontsize=10,
                                                        fontweight='bold', color='w')

                                det_file = get_output_product('det_image')
                                det_datamodel = datamodels.open(det_file)

                                axs_index += 1
                                vmin = np.median(det_datamodel.data[0][-1]) * 0.9
                                vmax = np.median(det_datamodel.data[0][-1]) * 4
                                axs[axs_index].imshow(det_datamodel.data[0][-1], cmap='jet',
                                                      interpolation='nearest',
                                                      norm=LogNorm(vmin=vmin, vmax=vmax),
                                                      origin='lower')
                                axs[axs_index].annotate('det_image', xy=(0.7, 0.95),
                                                        xycoords='axes fraction', fontsize=10,
                                                        fontweight='bold', color='w')

                                if dither == True:
                                    illum_file = get_output_product('illum', dither=True)
                                    illum_datamodel = miri_illumination_model.MiriIlluminationModel(
                                        illum_file)

                                    axs_index += 1
                                    axs[axs_index].imshow(illum_datamodel.intensity[0], cmap='jet',
                                                          interpolation='nearest', norm=LogNorm(),
                                                          origin='lower')
                                    axs[axs_index].annotate('dither position 2', xy=(0.0, 1.02),
                                                            xycoords='axes fraction', fontsize=12,
                                                            fontweight='bold', color='k')
                                    axs[axs_index].annotate('illum_model', xy=(0.7, 0.95),
                                                            xycoords='axes fraction', fontsize=10,
                                                            fontweight='bold', color='w')

                                    det_file = get_output_product('det_image', dither=True)
                                    det_datamodel = datamodels.open(det_file)

                                    axs_index += 1
                                    axs[axs_index].imshow(det_datamodel.data[0][-1], cmap='jet',
                                                          interpolation='nearest',
                                                          norm=LogNorm(vmin=vmin, vmax=vmax),
                                                          origin='lower')
                                    axs[axs_index].annotate('det_image', xy=(0.7, 0.95),
                                                            xycoords='axes fraction', fontsize=10,
                                                            fontweight='bold', color='w')

                                fig.savefig(os.path.join(out_fig_dir, sim_fig), dpi=200)
                                del fig

                            except Exception as e:
                                testing_logger.warning('%s failed' % sim_dir)
                                testing_logger.warning('  %s: %s' % (e.__class__.__name__, str(e)))

                            os.chdir(out_dir)


        # galaxies with velomaps and LOSVD profiles
        src_velomap = ['flatdisk', 'keplerdisk']
        src_losvd = [True, False]

        for mode in modes:
            for im_filter in im_filters:
                for read_mode in read_modes:
                        for src_vd in src_losvd:
                            for src_vm in src_velomap:

                                scene_cfg = make_scene_config(src_type='galaxy', src_spec='bb', losvd=src_vd, vel=src_vm)

                                # set the number of groups depending on the readout mode
                                if read_mode == 'FAST': groups=50
                                elif read_mode == 'SLOW': groups=10

                                sim_dir = 'IMA_' + mode + '_' + im_filter + '_' + read_mode + '_dithering-' + str(dither)\
                                          + '_losvd-' + str(src_vd) + '_velomap-' + str(src_vm)
                                sim_fig = sim_dir + '.pdf'
                                os.mkdir(sim_dir)
                                os.chdir(sim_dir)

                                sim_cfg = make_ima_sim_config(mode=mode, dither=dither, ndither=ndither,
                                                                filter=im_filter,readmode=read_mode,
                                                                exposures=exposures, integrations=integrations,
                                                                groups=groups)

                                print('Simulating %s' % sim_dir)
                                try:
                                    mysim = MiriSimulation(sim_cfg, scene_cfg, simulator_cfg)
                                    mysim.run()

                                    # log pass
                                    testing_logger.info('%s passed' % sim_dir)

                                    if dither == False:
                                        fig,axs = plt.subplots(1, 2)
                                        fig.set_figwidth(12.0)
                                        fig.set_figheight(6.0)
                                    elif dither == True:
                                        fig,axs = plt.subplots(2,2)
                                        fig.set_figwidth(12.0)
                                        fig.set_figheight(12.0)
                                    #plt.tight_layout(pad=0.5)
                                    axs = axs.ravel()
                                    axs_index = -1

                                    # plot output, illumination model and last frame of first integration (only one per exposure)
                                    illum_file = get_output_product('illum')
                                    illum_datamodel = miri_illumination_model.MiriIlluminationModel(illum_file)

                                    axs_index += 1
                                    axs[axs_index].imshow(illum_datamodel.intensity[0], cmap='jet', interpolation='nearest', norm=LogNorm(), origin='lower')
                                    axs[axs_index].annotate(sim_dir, xy=(0.0,1.02), xycoords='axes fraction', fontsize=14, fontweight='bold', color='k')
                                    axs[axs_index].annotate('illum_model', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                    det_file = get_output_product('det_image')
                                    det_datamodel = datamodels.open(det_file)

                                    axs_index += 1
                                    vmin = np.median(det_datamodel.data[0][-1]) * 0.9
                                    vmax = np.median(det_datamodel.data[0][-1]) * 4
                                    axs[axs_index].imshow(det_datamodel.data[0][-1], cmap='jet',
                                                          interpolation='nearest', norm=LogNorm(vmin=vmin, vmax=vmax),
                                                          origin='lower')
                                    axs[axs_index].annotate('det_image', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                    if dither == True:
                                        illum_file = get_output_product('illum', dither=True)
                                        illum_datamodel = miri_illumination_model.MiriIlluminationModel(illum_file)

                                        axs_index += 1
                                        axs[axs_index].imshow(illum_datamodel.intensity[0], cmap='jet', interpolation='nearest', norm=LogNorm(), origin='lower')
                                        axs[axs_index].annotate('dither position 2', xy=(0.0,1.02), xycoords='axes fraction', fontsize=12, fontweight='bold', color='k')
                                        axs[axs_index].annotate('illum_model', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                        det_file = get_output_product('det_image', dither=True)
                                        det_datamodel = datamodels.open(det_file)

                                        axs_index += 1
                                        axs[axs_index].imshow(det_datamodel.data[0][-1], cmap='jet', interpolation='nearest', norm=LogNorm(vmin=vmin, vmax=vmax), origin='lower')
                                        axs[axs_index].annotate('det_image', xy=(0.7,0.95), xycoords='axes fraction', fontsize=10, fontweight='bold', color='w')

                                    fig.savefig(os.path.join(out_fig_dir,sim_fig), dpi=200)
                                    del fig

                                except Exception as e:
                                    testing_logger.warning('%s failed' % sim_dir)
                                    testing_logger.warning('  %s: %s' % (e.__class__.__name__, str(e)))

                                os.chdir(out_dir)
    os.chdir(cwd)
コード例 #13
0
    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]
#    DitherPat = 'lrs_recommended_dither.dat', # dither pattern to use [NOT USED HERE]
#    disperser = 'SHORT',        # [NOT USED HERE]
コード例 #14
0
    name = 'LRS_slit_point_nodither',    # name given to simulation
    scene = 'lrs_pointsource_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_SLIT',  # 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 = 1,          # number of exposures
    ima_integrations = 3,       # 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_nodither.write('LRS_slit_point_nodither_simconfig.ini')

simulator_config = SimulatorConfig.from_default()

simsim = MiriSimulation(sim_config_nodither, scene_config, simulator_config)
simsim.run()
コード例 #15
0
sim_config = SimConfig.makeSim(
    name='lrsslit_nops7',  # name given to simulation
    scene='lrsslit_nops7_scene.ini',  # name of scene file to input
    rel_obsdate=0.5,  # relative observation date (0 = launch, 1 = end of 5 yrs)
    POP='IMA',  # Component on which to center (Imager or MRS)
    ConfigPath='LRS_SLIT',  # Configure the Optical path (MRS sub-band)
    Dither=True,  # Don't Dither
    StartInd=1,  # start index for dither pattern [NOT USED HERE]
    NDither=2,  # number of dither positions [NOT USED HERE]
    DitherPat=
    'lrs_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=1,  # number of exposures
    ima_integrations=3,  # number of integrations
    ima_frames=100,  # 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.write('lrsslit_nops7_sim.ini')
simulator_config = SimulatorConfig.from_default()

sim = MiriSimulation(sim_config, scene_config, simulator_config)
sim.run()