Esempio n. 1
0
def make_rn_dist(det_save_path):
    """
	Draw random samples from distribution to create read
	noise values.

	Inputs:
		det_save_path - Directory to save rn distribution to
	"""
    if det_save_path == "None":
        det_save_path = detpath

    # First look to see if detectors already made
    if os.path.exists(det_save_path + 'HARMONI_dets.fits'):
        logging.info('- found existing HARMONI detectors')
        if config_data['systematics']['force_new'] == False:
            logging.info('- using existing detectors')
            hdulist = fits.open(det_save_path + 'HARMONI_dets.fits')
            rn_vals = hdulist[0].data
            return rn_vals
        else:
            logging.info('- overwriting exisiting detectors')

    logging.info('- no exisiting HARMONI detectors found')
    logging.info('- creating new detectors')

    rn_path = path_setup('../../' + config_data["data_dir"] + 'detectors/')
    rn_file = rn_path + config_data['systematics']['rn_file']
    if os.path.isfile(rn_file) is False:
        logging.error('There was an error finding rn_file. \
					  Check config.py to ensure filename is correct')
        return

    hdu = fits.open(rn_file)
    rn_data = hdu[0].data

    side_len, N_det = config_data['side_length'], config_data['N_IR_det']
    N = (side_len**2) * N_det
    rands = np.random.random(N)
    rands_sort = np.sort(rands)
    rn_vals = interp(rn_data.flatten())(rands_sort)

    np.random.shuffle(rn_vals)
    rn_vals = np.reshape(rn_vals, (N_det, side_len, side_len))

    #Saving detectors for future use
    fits.writeto(det_save_path + 'HARMONI_dets.fits', rn_vals, overwrite=True)

    return rn_vals
Esempio n. 2
0
and computes the ADR if requested
'''
import os
import logging

import numpy as np
from astropy.convolution import Gaussian1DKernel

from src.config import *
from src.modules.misc_utils import path_setup
from src.modules.rebin import *
from src.modules.adr import apply_adr

import matplotlib.pyplot as plt

bgpath = path_setup('../../' + config_data["data_dir"] + 'sky/')


def convolve_1d_spectrum(input_lambda, input_flux, output_spec_res):
    '''Function that convolves a sky spectrum with a Gaussian to 
	match the input cube spectral resolution.
	
	Inputs:
		input_lambda: input sky spectrum lambda
		input_flux: input sky spectrum flux
		output_spec_res: Spectral resolution of the convolved sky spectrum output 
		
	Outputs:
		convolved sky spectrum
	'''
Esempio n. 3
0
import os
import logging

import numpy as np
import scipy.constants as sp
from scipy.interpolate import UnivariateSpline
from scipy import integrate
from astropy.convolution import Gaussian1DKernel
from astropy.io import fits

from src.modules.misc_utils import path_setup
from src.config import *
from src.modules import nghxrg as ng
from src.modules.em_model import *

detpath = path_setup('../../' + config_data["data_dir"] + 'detectors/')


#Detector throughput curve generated just using wavelength array.
def detector_QE_curve(wavels, grating, debug_plots, output_file):
    '''Function that generates a detector QE curve.
	Current detector data taken from Detector Reference
	table.

	Inputs:
		wavels: array of wavelengths for datacube
		grating: grating choice to set detector

	Outputs:
		cube_det_qe: array of detector QE values for
			each wavelength in array
Esempio n. 4
0
'''

import getopt
import sys
import os
import numpy as n
import multiprocessing as mp
from src.JSIM_main import main
import commands
from src.modules.misc_utils import path_setup

if __name__ == "__main__":

    #Get version number
    try:
        verpath = path_setup('../../')
        verinfo = open(verpath + 'PKG-INFO')
        ver = verinfo.readlines()[2][:-1].split('Version: ')[1]
        print 'VERSION = ', ver
        verinfo.close()
    except:
        ver = str(
            commands.getoutput(
                "svnversion -c ./ | sed -e 's/[MS]//g' -e 's/^[[:digit:]]*://'"
            ))

    optlist, args = getopt.getopt(sys.argv[1:], 'hcp:o:',
                                  ['help', 'cline', 'proc', 'odir'])

    for o, a in optlist:
        if o in ("-h", "--help"):
Esempio n. 5
0
                def InitUI(self):

                    panel = wx.Panel(self)
                    titlefont = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)

                    # Set up the menu.
                    filemenu = wx.Menu()
                    menuAbout = filemenu.Append(
                        wx.ID_ABOUT, "&About",
                        " Information about this program")
                    menuExit = filemenu.Append(wx.ID_EXIT, "&Exit",
                                               " Terminate the program")

                    # Creating the menubar.
                    menuBar = wx.MenuBar()
                    menuBar.Append(
                        filemenu,
                        "&File")  # Adding the "filemenu" to the MenuBar
                    self.SetMenuBar(
                        menuBar)  # Adding the MenuBar to the Frame content.

                    # Events.
                    self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
                    self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)

                    hbox = wx.BoxSizer(wx.HORIZONTAL)

                    fg = wx.FlexGridSizer(8, 2, 15, 10)

                    #Instrument parameters
                    inst = wx.StaticText(panel, label='Instrument')
                    inst.SetFont(titlefont)
                    subinst = wx.StaticText(panel, label=' ')
                    INPUTCUBE = wx.StaticText(panel, label="Input Cube")
                    self.INPUTCUBEVAL = wx.FilePickerCtrl(panel, path="")
                    DIT = wx.StaticText(panel, label="DIT [s]")
                    self.DITVAL = wx.TextCtrl(panel, value='900')
                    NDIT = wx.StaticText(panel, label="NINT")
                    self.NDITVAL = wx.TextCtrl(panel, value='1')
                    PHOTOBAND = wx.StaticText(panel, label='Grating')
                    self.PHOTOBANDVAL = wx.Choice(
                        panel,
                        choices=[
                            'F070-G140M [0.7-1.2 um] (R=1000)',
                            'F100-G140M [1.0-1.8 um] (R=1000)',
                            'G235M [1.7-3.0 um]  (R=1000)',
                            'G395M [2.9-5.0 um] (R=1000)',
                            'F070-G140H [0.7-1.2 um] (R=2700)',
                            'F100-G140H [1.0-1.8 um] (R=2700)',
                            'G235H [1.7-3.0 um] (R=2700)',
                            'G395H [2.9-5.0 um] (R=2700)',
                            'Prism [0.6-5.0 um] (R~100)'
                        ])
                    IGNORESPEC = wx.StaticText(panel,
                                               label='Ignore LSF convolution')
                    self.IGNORESPECVAL = wx.CheckBox(panel)
                    DRIZZLE = wx.StaticText(panel,
                                            label='Drizzle (50 mas sampling)')
                    self.DRIZZLEVAL = wx.CheckBox(panel)
                    DIR = wx.StaticText(panel, label='Output Dir')
                    self.DIRVAL = wx.DirPickerCtrl(
                        panel, path=path_setup('../../Output_cubes/'))

                    fg.AddMany([(inst), (subinst), (INPUTCUBE),
                                (self.INPUTCUBEVAL, 1, wx.EXPAND), (DIR),
                                (self.DIRVAL, 1, wx.EXPAND), (DIT),
                                (self.DITVAL, 1, wx.EXPAND), (NDIT),
                                (self.NDITVAL, 1, wx.EXPAND), (PHOTOBAND),
                                (self.PHOTOBANDVAL, 1, wx.EXPAND),
                                (IGNORESPEC),
                                (self.IGNORESPECVAL, 1, wx.EXPAND), (DRIZZLE),
                                (self.DRIZZLEVAL, 1, wx.EXPAND)])

                    fg.AddGrowableCol(1, 1)

                    hbox.Add(fg,
                             proportion=1,
                             flag=wx.ALL | wx.EXPAND,
                             border=10)

                    # #Telescope parameters
                    # fgs = wx.FlexGridSizer(2, 2, 15, 10)
                    # tele = wx.StaticText(panel, label='Telescope')
                    # tele.SetFont(titlefont)
                    # subtele = wx.StaticText(panel, label=' ')
                    # # SITETEMP = wx.StaticText(panel, label="Temperature [K]:")
                    # # self.SITETEMPVAL = wx.TextCtrl(panel, value='3.0')
                    # fgs.AddMany([(tele), (subtele),
                    #              (USERPSF), (self.USERPSFVAL, 1, wx.EXPAND)])
                    #             #  (SITETEMP), (self.SITETEMPVAL, 1, wx.EXPAND)])
                    # fgs.AddGrowableCol(1,1)
                    # hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)

                    #Misc. parameters
                    fgss = wx.FlexGridSizer(9, 2, 15, 10)

                    misc = wx.StaticText(panel, label="Miscellaneous")
                    misc.SetFont(titlefont)
                    submisc = wx.StaticText(panel, label=' ')
                    REMOVE_BG = wx.StaticText(panel,
                                              label='Subtract Background')
                    self.REMOVE_BGVAL = wx.CheckBox(panel)
                    OUTPUT_OB = wx.StaticText(panel,
                                              label='Return Object Cube')
                    self.OUTPUT_OBVAL = wx.CheckBox(panel)
                    OUTPUT_TS = wx.StaticText(panel,
                                              label='Return Transmission Cube')
                    self.OUTPUT_TSVAL = wx.CheckBox(panel)
                    gapaa = wx.StaticText(panel, label=' ------------ ')
                    gapbb = wx.StaticText(panel, label=' ')
                    NOISESEED = wx.StaticText(panel, label="Noise Seed")
                    self.NOISESEEDVAL = wx.Choice(panel,
                                                  choices=['Random', '1', '2'])
                    SETR = wx.StaticText(panel, label="Set Spec Samp [A/pix]")
                    self.SETRVAL = wx.TextCtrl(panel)
                    N_PROC = wx.StaticText(panel,
                                           label='No. of processors (1-' +
                                           str(mp.cpu_count()) + ')')
                    self.N_PROCVAL = wx.TextCtrl(panel, value=str(1))
                    RESJIT = wx.StaticText(panel,
                                           label="Additional PSF Blur [mas]:")
                    self.RESJITVAL = wx.TextCtrl(panel, value='0')

                    fgss.AddMany([
                        (misc), (submisc), (REMOVE_BG),
                        (self.REMOVE_BGVAL, 1, wx.EXPAND), (OUTPUT_OB),
                        (self.OUTPUT_OBVAL, 1, wx.EXPAND), (OUTPUT_TS),
                        (self.OUTPUT_TSVAL, 1, wx.EXPAND), (gapaa), (gapbb),
                        (N_PROC), (self.N_PROCVAL, 1, wx.EXPAND), (NOISESEED),
                        (self.NOISESEEDVAL, 1, wx.EXPAND), (SETR),
                        (self.SETRVAL, 1, wx.EXPAND), (RESJIT),
                        (self.RESJITVAL, 1, wx.EXPAND)
                    ])

                    fgss.AddGrowableCol(1, 1)

                    hbox.Add(fgss,
                             proportion=1,
                             flag=wx.ALL | wx.EXPAND,
                             border=10)

                    panel.SetSizer(hbox)

                    # A button
                    button = wx.Button(panel, 10, "Commence Simulation",
                                       wx.Point(360, 325))
                    wx.EVT_BUTTON(panel, 10, self.OnClick)
Esempio n. 6
0
import getopt
import sys
import os
import numpy as n
import multiprocessing as mp
from src.TheSimulator import main
import commands
from src.modules.misc_utils import path_setup



if __name__=="__main__":

    #Get version number
    try:
        verpath = path_setup('../../')
        verinfo = open(verpath+'PKG-INFO')
        ver = verinfo.readlines()[2][:-1].split('Version: ')[1]
        print 'VERSION = ', ver
        verinfo.close()
    except:
        ver = str(commands.getoutput("svnversion -c ./ | sed -e 's/[MS]//g' -e 's/^[[:digit:]]*://'"))
    
    
    optlist, args = getopt.getopt(sys.argv[1:], 'hcp:o:', ['help', 'cline', 'proc', 'odir'])

    for o, a in optlist:
        if o in ("-h", "--help"):
            print""
            print '    --------     '
            print 'HARMONI Simulator'
Esempio n. 7
0
                def InitUI(self):

                    panel = wx.Panel(self)
                    titlefont = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)

                    # Set up the menu.
                    filemenu  = wx.Menu()
                    menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
                    menuExit  = filemenu.Append(wx.ID_EXIT,"&Exit"," Terminate the program")

                    # Creating the menubar.
                    menuBar = wx.MenuBar()
                    menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
                    self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

                    # Events.
                    self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
                    self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
                    
                    hbox = wx.BoxSizer(wx.HORIZONTAL)

                    fg = wx.FlexGridSizer(8, 2, 15, 10)

                    #Instrument parameters
                    inst = wx.StaticText(panel, label='Instrument')
                    inst.SetFont(titlefont)        
                    subinst = wx.StaticText(panel, label=' ')
                    INPUTCUBE = wx.StaticText(panel, label="Input Cube")
                    self.INPUTCUBEVAL = wx.FilePickerCtrl(panel, path="")
                    DIT = wx.StaticText(panel, label="DIT [s]")
                    self.DITVAL = wx.TextCtrl(panel, value='900')
                    NDIT = wx.StaticText(panel, label="NINT")
                    self.NDITVAL = wx.TextCtrl(panel, value='1')
                    XSPAX = wx.StaticText(panel, label="X Scale [mas]")
                    self.XSPAXVAL = wx.TextCtrl(panel, value='20')
                    YSPAX = wx.StaticText(panel, label="Y Scale [mas]")
                    self.YSPAXVAL = wx.TextCtrl(panel, value='20')
                    PHOTOBAND = wx.StaticText(panel, label='Grating')
                    self.PHOTOBANDVAL = wx.Choice(panel, choices=['V+R [0.47-0.81 um] (R=3500)', 'Iz+J [0.8-1.36 um]  (R=3500)', 'H+K [1.45-2.45 um] (R=3500)',
                                                                  'V [0.5-0.63 um] (R=7500)', 'R [0.63-0.79 um] (R=7500)', 'Iz [0.82-1.03 um] (R=7500)',
                                                                  'J [1.08-1.36 um] (R=7500)', 'H [1.46-1.83 um] (R=7500)', 'K [1.95-2.45 um] (R=7500)',
                                                                  'V-high [0.53-0.59 um] (R=20000)', 'R-high [0.61-0.68 um] (R=20000)', 'z [0.82-0.91 um] (R=20000)',
                                                                  'J-high [1.17-1.29 um] (R=20000)','H-high [1.545-1.715 um] (R=20000)','K-high [2.09-2.32 um] (R=20000)',
                                                                  'None'])
                    DIR = wx.StaticText(panel, label='Output Dir')
                    self.DIRVAL = wx.DirPickerCtrl(panel, path=path_setup('../../Output_cubes/'))
                    
                    fg.AddMany([(inst), (subinst), (INPUTCUBE),
                                (self.INPUTCUBEVAL, 1, wx.EXPAND),
                                (DIR), (self.DIRVAL, 1, wx.EXPAND),
                                (DIT), (self.DITVAL, 1, wx.EXPAND),
                                (NDIT), (self.NDITVAL, 1, wx.EXPAND),
                                (XSPAX), (self.XSPAXVAL, 1, wx.EXPAND),
                                (YSPAX), (self.YSPAXVAL, 1, wx.EXPAND),
                                (PHOTOBAND), (self.PHOTOBANDVAL, 1, wx.EXPAND),])
                    
                    fg.AddGrowableCol(1,1)

                    hbox.Add(fg, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)
                       
                    #Telescope parameters(AO mode, seeing, zenith angle etc):
                    fgs = wx.FlexGridSizer(8, 2, 15, 10)

                    tele = wx.StaticText(panel, label='Telescope')
                    tele.SetFont(titlefont)
                    subtele = wx.StaticText(panel, label=' ')
                    TELESCOPE = wx.StaticText(panel, label="Telescope:")
                    self.TELESCOPEVAL = wx.Choice(panel, choices=['E-ELT', 'VLT'])
                    AOMODE = wx.StaticText(panel, label="AO Mode:")
                    self.AOMODEVAL = wx.Choice(panel, choices=['LTAO', 'SCAO', 'Gaussian'])
                    SEEING = wx.StaticText(panel, label="Zenith Seeing [arcsec]:")
                    self.SEEINGVAL = wx.TextCtrl(panel, value='0.67')
                    ZENITHA = wx.StaticText(panel, label="Zenith Angle [deg]")
                    self.ZENITHAVAL = wx.TextCtrl(panel, value='0')
                    USERPSF = wx.StaticText(panel, label='User PSF (replaces AO choice)')
                    self.USERPSFVAL = wx.FilePickerCtrl(panel, path="None")
                    gapa = wx.StaticText(panel, label=' ------------ ')
                    gapb = wx.StaticText(panel, label=' ')
                    SITETEMP = wx.StaticText(panel, label="Telescope Temperature [K]:")
                    self.SITETEMPVAL = wx.TextCtrl(panel, value='280.5')

                    fgs.AddMany([(tele), (subtele), (TELESCOPE),
                                 (self.TELESCOPEVAL, 1, wx.EXPAND),
                                 (AOMODE), (self.AOMODEVAL, 1, wx.EXPAND),
                                 (SEEING), (self.SEEINGVAL, 1, wx.EXPAND),
                                 (ZENITHA), (self.ZENITHAVAL, 1, wx.EXPAND),
                                 (gapa), (gapb),
                                 (USERPSF), (self.USERPSFVAL, 1, wx.EXPAND),
                                 (SITETEMP), (self.SITETEMPVAL, 1, wx.EXPAND)])
                    
                    fgs.AddGrowableCol(1,1)

                    hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)
                    
                    #Misc. parameters
                    fgss = wx.FlexGridSizer(10, 2, 15, 10)

                    misc = wx.StaticText(panel, label="Miscellaneous")
                    misc.SetFont(titlefont)
                    submisc = wx.StaticText(panel, label=' ')
                    REMOVE_BG = wx.StaticText(panel, label='Subtract Background')
                    self.REMOVE_BGVAL = wx.CheckBox(panel)
                    OUTPUT_OB = wx.StaticText(panel, label='Return Object Cube')
                    self.OUTPUT_OBVAL = wx.CheckBox(panel)
                    OUTPUT_TS = wx.StaticText(panel, label='Return Transmission Cube')
                    self.OUTPUT_TSVAL = wx.CheckBox(panel)
                    gapaa = wx.StaticText(panel, label=' ------------ ')
                    gapbb = wx.StaticText(panel, label=' ')
                    NOISESEED = wx.StaticText(panel, label="Noise Seed")
                    self.NOISESEEDVAL = wx.Choice(panel, choices=['Random', '1', '2'])
                    SETR = wx.StaticText(panel, label="Set Spec Samp [A/pix]")
                    self.SETRVAL = wx.TextCtrl(panel)
                    N_PROC = wx.StaticText(panel, label='No. of processors (1-'+str(mp.cpu_count())+')')
                    self.N_PROCVAL = wx.TextCtrl(panel, value=str(mp.cpu_count()-1))
                    RESJIT = wx.StaticText(panel, label="Additional PSF Blur [mas]:")
                    self.RESJITVAL = wx.TextCtrl(panel, value='0')
                    ADR = wx.StaticText(panel, label="Turn off ADR")
                    self.ADRVAL = wx.CheckBox(panel)

                    fgss.AddMany([(misc), (submisc),
                                  (REMOVE_BG), (self.REMOVE_BGVAL, 1, wx.EXPAND),
                                  (OUTPUT_OB), (self.OUTPUT_OBVAL, 1, wx.EXPAND),
                                  (OUTPUT_TS), (self.OUTPUT_TSVAL, 1, wx.EXPAND),
                                  (gapaa), (gapbb),
                                  (N_PROC), (self.N_PROCVAL, 1, wx.EXPAND),
                                  (NOISESEED), (self.NOISESEEDVAL, 1, wx.EXPAND),
                                  (SETR), (self.SETRVAL, 1, wx.EXPAND),
                                  (RESJIT), (self.RESJITVAL, 1, wx.EXPAND),
                                  (ADR), (self.ADRVAL, 1, wx.EXPAND)])

                    fgss.AddGrowableCol(1,1)

                    hbox.Add(fgss, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)

                    panel.SetSizer(hbox)

                    # A button
                    button =wx.Button(panel, 10, "Commence Simulation", wx.Point(465, 325))
                    wx.EVT_BUTTON(panel, 10, self.OnClick)
Esempio n. 8
0
                def InitUI(self):

                    panel = wx.Panel(self)
                    titlefont = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)

                    # Set up the menu.
                    filemenu = wx.Menu()
                    menuAbout = filemenu.Append(
                        wx.ID_ABOUT, "&About",
                        " Information about this program")
                    menuExit = filemenu.Append(wx.ID_EXIT, "&Exit",
                                               " Terminate the program")

                    # Creating the menubar.
                    menuBar = wx.MenuBar()
                    menuBar.Append(
                        filemenu,
                        "&File")  # Adding the "filemenu" to the MenuBar
                    self.SetMenuBar(
                        menuBar)  # Adding the MenuBar to the Frame content.

                    # Events.
                    self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
                    self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)

                    hbox = wx.BoxSizer(wx.HORIZONTAL)

                    fg = wx.FlexGridSizer(8, 2, 15, 10)

                    #Instrument parameters
                    inst = wx.StaticText(panel, label='Instrument')
                    inst.SetFont(titlefont)
                    subinst = wx.StaticText(panel, label=' ')
                    INPUTCUBE = wx.StaticText(panel, label="Input Cube")
                    self.INPUTCUBEVAL = wx.FilePickerCtrl(panel, path="")
                    DIT = wx.StaticText(panel, label="DIT [s]")
                    self.DITVAL = wx.TextCtrl(panel, value='900')
                    NDIT = wx.StaticText(panel, label="NINT")
                    self.NDITVAL = wx.TextCtrl(panel, value='1')
                    XSPAX = wx.StaticText(panel, label="X Scale [mas]")
                    self.XSPAXVAL = wx.TextCtrl(panel, value='20')
                    YSPAX = wx.StaticText(panel, label="Y Scale [mas]")
                    self.YSPAXVAL = wx.TextCtrl(panel, value='20')
                    PHOTOBAND = wx.StaticText(panel, label='Grating')
                    self.PHOTOBANDVAL = wx.Choice(
                        panel,
                        choices=[
                            'V+R [0.47-0.81 um] (R=3500)',
                            'Iz+J [0.8-1.36 um]  (R=3500)',
                            'H+K [1.45-2.45 um] (R=3500)',
                            'V [0.5-0.63 um] (R=7500)',
                            'R [0.63-0.79 um] (R=7500)',
                            'Iz [0.82-1.03 um] (R=7500)',
                            'J [1.08-1.36 um] (R=7500)',
                            'H [1.46-1.83 um] (R=7500)',
                            'K [1.95-2.45 um] (R=7500)',
                            'V-high [0.53-0.59 um] (R=20000)',
                            'R-high [0.61-0.68 um] (R=20000)',
                            'z [0.82-0.91 um] (R=20000)',
                            'J-high [1.17-1.29 um] (R=20000)',
                            'H-high [1.545-1.715 um] (R=20000)',
                            'K-high [2.09-2.32 um] (R=20000)', 'None'
                        ])
                    DIR = wx.StaticText(panel, label='Output Dir')
                    self.DIRVAL = wx.DirPickerCtrl(
                        panel, path=path_setup('../../Output_cubes/'))

                    fg.AddMany([
                        (inst),
                        (subinst),
                        (INPUTCUBE),
                        (self.INPUTCUBEVAL, 1, wx.EXPAND),
                        (DIR),
                        (self.DIRVAL, 1, wx.EXPAND),
                        (DIT),
                        (self.DITVAL, 1, wx.EXPAND),
                        (NDIT),
                        (self.NDITVAL, 1, wx.EXPAND),
                        (XSPAX),
                        (self.XSPAXVAL, 1, wx.EXPAND),
                        (YSPAX),
                        (self.YSPAXVAL, 1, wx.EXPAND),
                        (PHOTOBAND),
                        (self.PHOTOBANDVAL, 1, wx.EXPAND),
                    ])

                    fg.AddGrowableCol(1, 1)

                    hbox.Add(fg,
                             proportion=1,
                             flag=wx.ALL | wx.EXPAND,
                             border=10)

                    #Telescope parameters(AO mode, seeing, zenith angle etc):
                    fgs = wx.FlexGridSizer(8, 2, 15, 10)

                    tele = wx.StaticText(panel, label='Telescope')
                    tele.SetFont(titlefont)
                    subtele = wx.StaticText(panel, label=' ')
                    TELESCOPE = wx.StaticText(panel, label="Telescope:")
                    self.TELESCOPEVAL = wx.Choice(panel,
                                                  choices=['E-ELT', 'VLT'])
                    AOMODE = wx.StaticText(panel, label="AO Mode:")
                    self.AOMODEVAL = wx.Choice(
                        panel, choices=['LTAO', 'SCAO', 'Gaussian'])
                    SEEING = wx.StaticText(panel,
                                           label="Zenith Seeing [arcsec]:")
                    self.SEEINGVAL = wx.TextCtrl(panel, value='0.67')
                    ZENITHA = wx.StaticText(panel, label="Zenith Angle [deg]")
                    self.ZENITHAVAL = wx.TextCtrl(panel, value='0')
                    USERPSF = wx.StaticText(
                        panel, label='User PSF (replaces AO choice)')
                    self.USERPSFVAL = wx.FilePickerCtrl(panel, path="None")
                    gapa = wx.StaticText(panel, label=' ------------ ')
                    gapb = wx.StaticText(panel, label=' ')
                    SITETEMP = wx.StaticText(
                        panel, label="Telescope Temperature [K]:")
                    self.SITETEMPVAL = wx.TextCtrl(panel, value='280.5')

                    fgs.AddMany([(tele), (subtele), (TELESCOPE),
                                 (self.TELESCOPEVAL, 1, wx.EXPAND), (AOMODE),
                                 (self.AOMODEVAL, 1, wx.EXPAND), (SEEING),
                                 (self.SEEINGVAL, 1, wx.EXPAND), (ZENITHA),
                                 (self.ZENITHAVAL, 1, wx.EXPAND), (gapa),
                                 (gapb), (USERPSF),
                                 (self.USERPSFVAL, 1, wx.EXPAND), (SITETEMP),
                                 (self.SITETEMPVAL, 1, wx.EXPAND)])

                    fgs.AddGrowableCol(1, 1)

                    hbox.Add(fgs,
                             proportion=1,
                             flag=wx.ALL | wx.EXPAND,
                             border=10)

                    #Misc. parameters
                    fgss = wx.FlexGridSizer(10, 2, 15, 10)

                    misc = wx.StaticText(panel, label="Miscellaneous")
                    misc.SetFont(titlefont)
                    submisc = wx.StaticText(panel, label=' ')
                    REMOVE_BG = wx.StaticText(panel,
                                              label='Subtract Background')
                    self.REMOVE_BGVAL = wx.CheckBox(panel)
                    OUTPUT_OB = wx.StaticText(panel,
                                              label='Return Object Cube')
                    self.OUTPUT_OBVAL = wx.CheckBox(panel)
                    OUTPUT_TS = wx.StaticText(panel,
                                              label='Return Transmission Cube')
                    self.OUTPUT_TSVAL = wx.CheckBox(panel)
                    gapaa = wx.StaticText(panel, label=' ------------ ')
                    gapbb = wx.StaticText(panel, label=' ')
                    NOISESEED = wx.StaticText(panel, label="Noise Seed")
                    self.NOISESEEDVAL = wx.Choice(panel,
                                                  choices=['Random', '1', '2'])
                    SETR = wx.StaticText(panel, label="Set Spec Samp [A/pix]")
                    self.SETRVAL = wx.TextCtrl(panel)
                    N_PROC = wx.StaticText(panel,
                                           label='No. of processors (1-' +
                                           str(mp.cpu_count()) + ')')
                    self.N_PROCVAL = wx.TextCtrl(panel,
                                                 value=str(mp.cpu_count() - 1))
                    RESJIT = wx.StaticText(panel,
                                           label="Additional PSF Blur [mas]:")
                    self.RESJITVAL = wx.TextCtrl(panel, value='0')
                    ADR = wx.StaticText(panel, label="Turn off ADR")
                    self.ADRVAL = wx.CheckBox(panel)

                    fgss.AddMany([
                        (misc), (submisc), (REMOVE_BG),
                        (self.REMOVE_BGVAL, 1, wx.EXPAND), (OUTPUT_OB),
                        (self.OUTPUT_OBVAL, 1, wx.EXPAND), (OUTPUT_TS),
                        (self.OUTPUT_TSVAL, 1, wx.EXPAND), (gapaa), (gapbb),
                        (N_PROC), (self.N_PROCVAL, 1, wx.EXPAND), (NOISESEED),
                        (self.NOISESEEDVAL, 1, wx.EXPAND), (SETR),
                        (self.SETRVAL, 1, wx.EXPAND), (RESJIT),
                        (self.RESJITVAL, 1, wx.EXPAND), (ADR),
                        (self.ADRVAL, 1, wx.EXPAND)
                    ])

                    fgss.AddGrowableCol(1, 1)

                    hbox.Add(fgss,
                             proportion=1,
                             flag=wx.ALL | wx.EXPAND,
                             border=10)

                    panel.SetSizer(hbox)

                    # A button
                    button = wx.Button(panel, 10, "Commence Simulation",
                                       wx.Point(465, 325))
                    wx.EVT_BUTTON(panel, 10, self.OnClick)
Esempio n. 9
0
'''
Calculates LSF, instrument background and transmission
'''
import logging

import numpy as np
from scipy.interpolate import interp1d, interp2d
import scipy.constants as sp
from astropy.convolution import Gaussian1DKernel
from astropy.io import fits

from src.config import *
from src.modules.misc_utils import path_setup
from src.modules.em_model import *

tppath = path_setup('../../' + config_data["data_dir"] + 'throughput/')
hc_path = path_setup('../../' + config_data["data_dir"] + 'HC/')


class InstrumentPart:
    substrate = "Suprasil3001_50mm_Emissivity.txt"
    mirror = "QuantumFS500_Emissivity.txt"
    edust = 0.5  # Grey Dust covering on some optics
    mindustfrac = 0.005  # 0.5% dust on optical surfaces - won't be perfectly clean

    def __init__(self,
                 name,
                 temp,
                 area,
                 n_mirrors=0,
                 n_lenses=0,
Esempio n. 10
0
    def __init__(self,
                 naxis1=None,
                 naxis2=None,
                 naxis3=None,
                 n_out=None,
                 dt=None,
                 nroh=None,
                 nfoh=None,
                 pca0_file=None,
                 verbose=False,
                 reverse_scan_direction=False,
                 reference_pixel_border_width=None,
                 wind_mode='FULL',
                 x0=0,
                 y0=0,
                 det_size=None,
                 rn_file=None):
        """
        Simulate Teledyne HxRG+SIDECAR ASIC system noise.

        Parameters:
            naxis1      - X-dimension of the FITS cube
            naxis2      - Y-dimension of the FITS cube
            naxis3      - Z-dimension of the FITS cube
                          (number of up-the-ramp samples)
            n_out       - Number of detector outputs
            nfoh        - New frame overhead in rows. This allows for a short
                          wait at the end of a frame before starting the next
                          one.
            nroh        - New row overhead in pixels. This allows for a short
                          wait at the end of a row before starting the next one.
            dt          - Pixel dwell time in seconds
            pca0_file   - Name of a FITS file that contains PCA-zero
            rn_file     - Name of a FITS file that contains read noisepca
            verbose     - Enable this to provide status reporting
            wind_mode   - 'FULL', 'STRIPE', or 'WINDOW' (JML)
            x0/y0       - Pixel positions of subarray mode (JML)
            det_size    - Pixel dimension of full detector (square), used only
                          for WINDOW mode (JML)
            reference_pixel_border_width - Width of reference pixel border
                                           around image area
            reverse_scan_direction - Enable this to reverse the fast scanner
                                     readout directions. This
                                     capability was added to support
                                     Teledyne's programmable fast scan
                                     readout directions. The default
                                     setting =False corresponds to
                                     what HxRG detectors default to
                                     upon power up.
        """

        # ======================================================================
        #
        # DEFAULT CLOCKING PARAMETERS
        #
        # The following parameters define the default HxRG clocking pattern. The
        # parameters that define the default noise model are defined in the
        # mknoise() method.
        #
        # ======================================================================

        # Subarray Mode? (JML)
        if wind_mode is None:
            wind_mode = 'FULL'
        if det_size is None:
            det_size = 4096
        wind_mode = wind_mode.upper()
        modes = ['FULL', 'STRIPE', 'WINDOW']
        if wind_mode not in modes:
            _log.warn('%s not a valid window readout mode! Returning...' %
                      inst_params['wind_mode'])
            os.sys.exit()
        if wind_mode == 'WINDOW':
            n_out = 1
        if wind_mode == 'FULL':
            x0 = 0
            y0 = 0
        if wind_mode == 'STRIPE':
            x0 = 0

        # Default clocking pattern is JWST NIRSpec
        self.naxis1 = 4096 if naxis1 is None else naxis1
        self.naxis2 = 4096 if naxis2 is None else naxis2
        self.naxis3 = 1 if naxis3 is None else naxis3
        self.n_out = 64 if n_out is None else n_out
        self.dt = 1.e-5 if dt is None else dt
        self.nroh = 12 if nroh is None else nroh
        self.nfoh = 1 if nfoh is None else nfoh
        self.reference_pixel_border_width = 4 if reference_pixel_border_width is None \
                                              else reference_pixel_border_width

        # Check that det_size is greater than self.naxis1 and self.naxis2 in WINDOW mode (JML)
        if wind_mode == 'WINDOW':
            if (self.naxis1 > det_size):
                _log.warn('NAXIS1 %s greater than det_size %s! Returning...' %
                          (self.naxis1, det_size))
                os.sys.exit()
            if (self.naxis2 > det_size):
                _log.warn('NAXIS2 %s greater than det_size %s! Returning...' %
                          (self.naxis1, det_size))
                os.sys.exit()

        NGHXRG_HOME = path_setup('../../' + config_data["data_dir"] +
                                 'detectors/')

        # Initialize PCA-zero file and make sure that it exists and is a file
        #self.pca0_file = os.getenv('NGHXRG_HOME')+'/nirspec_pca0.fits' if \
        #   pca0_file is None else pca0_file
        self.pca0_file = NGHXRG_HOME+'/nirspec_pca0.fits' if \
                        pca0_file is None else pca0_file
        if os.path.isfile(self.pca0_file) is False:
            print('There was an error finding pca0_file! Check to be')
            print('sure that the NGHXRG_HOME shell environment')
            print('variable is set correctly and that the')
            print('$NGHXRG_HOME/ directory contains the desired PCA0')
            print('file. The default is nirspec_pca0.fits.')
            os.sys.exit()

        # ======================================================================

        # Configure Subarray (JML)
        self.wind_mode = wind_mode
        self.det_size = det_size
        self.x0 = x0
        self.y0 = y0

        # Configure status reporting
        self.verbose = verbose

        # Configure readout direction
        self.reverse_scan_direction = reverse_scan_direction

        # Compute the number of pixels in the fast-scan direction per
        # output
        self.xsize = self.naxis1 // self.n_out

        # Compute the number of time steps per integration, per
        # output
        self.nstep = (self.xsize + self.nroh) * (self.naxis2 +
                                                 self.nfoh) * self.naxis3
        # Pad nsteps to a power of 2, which is much faster (JML)
        self.nstep2 = int(2**np.ceil(np.log2(self.nstep)))

        # For adding in ACN, it is handy to have masks of the even
        # and odd pixels on one output neglecting any gaps
        self.m_even = np.zeros((self.naxis3, self.naxis2, self.xsize))
        self.m_odd = np.zeros_like(self.m_even)
        for x in np.arange(0, self.xsize, 2):
            self.m_even[:, :self.naxis2, x] = 1
            self.m_odd[:, :self.naxis2, x + 1] = 1
        self.m_even = np.reshape(self.m_even, np.size(self.m_even))
        self.m_odd = np.reshape(self.m_odd, np.size(self.m_odd))

        # Also for adding in ACN, we need a mask that point to just
        # the real pixels in ordered vectors of just the even or odd
        # pixels
        self.m_short = np.zeros((self.naxis3, self.naxis2+self.nfoh, \
                                      (self.xsize+self.nroh)//2))
        self.m_short[:, :self.naxis2, :self.xsize // 2] = 1
        self.m_short = np.reshape(self.m_short, np.size(self.m_short))

        # Define frequency arrays
        self.f1 = np.fft.rfftfreq(
            self.nstep2)  # Frequencies for nstep elements
        self.f2 = np.fft.rfftfreq(2 * self.nstep2)  # ... for 2*nstep elements

        # Define pinkening filters. F1 and p_filter1 are used to
        # generate ACN. F2 and p_filter2 are used to generate 1/f noise.
        self.alpha = -1  # Hard code for 1/f noise until proven otherwise
        self.p_filter1 = np.sqrt(self.f1**self.alpha)
        self.p_filter2 = np.sqrt(self.f2**self.alpha)
        self.p_filter1[0] = 0.
        self.p_filter2[0] = 0.

        # Initialize pca0. This includes scaling to the correct size,
        # zero offsetting, and renormalization. We use robust statistics
        # because pca0 is real data
        hdu = fits.open(self.pca0_file)
        nx_pca0 = hdu[0].header['naxis1']
        ny_pca0 = hdu[0].header['naxis2']

        # Do this slightly differently, taking into account the
        # different types of readout modes (JML)
        #if (nx_pca0 != self.naxis1 or naxis2 != self.naxis2):
        #    zoom_factor = self.naxis1 / nx_pca0
        #    self.pca0 = zoom(hdu[0].data, zoom_factor, order=1, mode='wrap')
        #else:
        #    self.pca0 = hdu[0].data
        #self.pca0 -= np.median(self.pca0) # Zero offset
        #self.pca0 /= (1.4826*mad(self.pca0)) # Renormalize

        data = hdu[0].data
        # Make sure the real PCA image is correctly scaled to size of fake data (JML)
        # Depends if we're FULL, STRIPE, or WINDOW
        if wind_mode == 'FULL':
            scale1 = self.naxis1 / nx_pca0
            scale2 = self.naxis2 / ny_pca0
            zoom_factor = np.max([scale1, scale2])
        if wind_mode == 'STRIPE':
            zoom_factor = self.naxis1 / nx_pca0
        if wind_mode == 'WINDOW':
            # Scale based on det_size
            scale1 = self.det_size / nx_pca0
            scale2 = self.det_size / ny_pca0
            zoom_factor = np.max([scale1, scale2])

        # Resize PCA0 data
        if zoom_factor != 1:
            data = zoom(data, zoom_factor, order=1, mode='wrap')

        data -= np.median(data)  # Zero offset
        data /= (1.4826 * mad(data))  # Renormalize

        # Select region of pca0 associated with window position
        if self.wind_mode == 'WINDOW':
            x1 = self.x0
            y1 = self.y0
        elif self.wind_mode == 'STRIPE':
            x1 = 0
            y1 = self.y0
        else:
            x1 = 0
            y1 = 0

        # print(y1, self.naxis2) This appears to be a stub
        x2 = x1 + self.naxis1
        y2 = y1 + self.naxis2
        # Make sure x2 and y2 are valid
        if (x2 > data.shape[0] or y2 > data.shape[1]):
            _log.warn(
                'Specified window size does not fit within detector array!')
            _log.warn(
                'X indices: [%s,%s]; Y indices: [%s,%s]; XY Size: [%s, %s]' %
                (x1, x2, y1, y2, data.shape[0], data.shape[1]))
            os.sys.exit()
        self.pca0 = data[y1:y2, x1:x2]

        # How many reference pixels on each border?
        w = self.reference_pixel_border_width  # Easier to work with
        lower = w - y1
        upper = w - (det_size - y2)
        left = w - x1
        right = w - (det_size - x2)
        ref_all = np.array([lower, upper, left, right])
        ref_all[ref_all < 0] = 0
        self.ref_all = ref_all
Esempio n. 11
0
from scipy.interpolate import interp2d
from astropy.convolution import Gaussian2DKernel

try:
    from ..config import *
except:
    from config import *

try:
    from src.modules.misc_utils import path_setup
    from src.modules.rebin import *
except:
    from modules.misc_utils import path_setup
    from modules.rebin import *

psf_path = path_setup('../../' + config_data["data_dir"] + 'PSF/')
hc_path = path_setup('../../' + config_data["data_dir"] + 'HC/')


# Thierry FUSCO 18/12/17 17:42
# SIMUL_PSF_DataPackage.zip
#Programme pour prendre en compte la multi-analyse les geometries
#d'etoiles et la postion de la galaxie
def psd_to_psf(psd,
               pup,
               D,
               phase_static=None,
               samp=None,
               fov=None,
               lamb=2.2 * 1.e-6,
               jitter=0.):
Esempio n. 12
0
                def InitUI(self):

                    panel = wx.Panel(self)
                    titlefont = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD)

                    # Set up the menu.
                    filemenu  = wx.Menu()
                    menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
                    menuExit  = filemenu.Append(wx.ID_EXIT,"&Exit"," Terminate the program")

                    # Creating the menubar.
                    menuBar = wx.MenuBar()
                    menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
                    self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

                    # Events.
                    self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
                    self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)

                    hbox = wx.BoxSizer(wx.HORIZONTAL)

                    fg = wx.FlexGridSizer(8, 2, 15, 10)

                    #Instrument parameters
                    inst = wx.StaticText(panel, label='Instrument')
                    inst.SetFont(titlefont)
                    subinst = wx.StaticText(panel, label=' ')
                    INPUTCUBE = wx.StaticText(panel, label="Input Cube")
                    self.INPUTCUBEVAL = wx.FilePickerCtrl(panel, path="")
                    DIT = wx.StaticText(panel, label="DIT [s]")
                    self.DITVAL = wx.TextCtrl(panel, value='900')
                    NDIT = wx.StaticText(panel, label="NINT")
                    self.NDITVAL = wx.TextCtrl(panel, value='1')
                    PHOTOBAND = wx.StaticText(panel, label='Grating')
                    self.PHOTOBANDVAL = wx.Choice(panel, choices=['F070-G140M [0.7-1.2 um] (R=1000)','F100-G140M [1.0-1.8 um] (R=1000)',
                                                                  'G235M [1.7-3.0 um]  (R=1000)', 'G395M [2.9-5.0 um] (R=1000)',
                                                                  'F070-G140H [0.7-1.2 um] (R=2700)', 'F100-G140H [1.0-1.8 um] (R=2700)',
                                                                  'G235H [1.7-3.0 um] (R=2700)', 'G395H [2.9-5.0 um] (R=2700)',
                                                                  'Prism [0.6-5.0 um] (R~100)'])
                    IGNORESPEC = wx.StaticText(panel, label='Ignore LSF convolution')
                    self.IGNORESPECVAL = wx.CheckBox(panel)
                    DRIZZLE = wx.StaticText(panel, label='Drizzle (50 mas sampling)')
                    self.DRIZZLEVAL = wx.CheckBox(panel)
                    DIR = wx.StaticText(panel, label='Output Dir')
                    self.DIRVAL = wx.DirPickerCtrl(panel, path=path_setup('../../Output_cubes/'))

                    fg.AddMany([(inst), (subinst), (INPUTCUBE),
                                (self.INPUTCUBEVAL, 1, wx.EXPAND),
                                (DIR), (self.DIRVAL, 1, wx.EXPAND),
                                (DIT), (self.DITVAL, 1, wx.EXPAND),
                                (NDIT), (self.NDITVAL, 1, wx.EXPAND),
                                (PHOTOBAND), (self.PHOTOBANDVAL, 1, wx.EXPAND),
                                (IGNORESPEC), (self.IGNORESPECVAL, 1, wx.EXPAND),
                                (DRIZZLE), (self.DRIZZLEVAL, 1, wx.EXPAND)])

                    fg.AddGrowableCol(1,1)

                    hbox.Add(fg, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)

                    # #Telescope parameters
                    # fgs = wx.FlexGridSizer(2, 2, 15, 10)
                    # tele = wx.StaticText(panel, label='Telescope')
                    # tele.SetFont(titlefont)
                    # subtele = wx.StaticText(panel, label=' ')
                    # # SITETEMP = wx.StaticText(panel, label="Temperature [K]:")
                    # # self.SITETEMPVAL = wx.TextCtrl(panel, value='3.0')
                    # fgs.AddMany([(tele), (subtele),
                    #              (USERPSF), (self.USERPSFVAL, 1, wx.EXPAND)])
                    #             #  (SITETEMP), (self.SITETEMPVAL, 1, wx.EXPAND)])
                    # fgs.AddGrowableCol(1,1)
                    # hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)

                    #Misc. parameters
                    fgss = wx.FlexGridSizer(9, 2, 15, 10)

                    misc = wx.StaticText(panel, label="Miscellaneous")
                    misc.SetFont(titlefont)
                    submisc = wx.StaticText(panel, label=' ')
                    REMOVE_BG = wx.StaticText(panel, label='Subtract Background')
                    self.REMOVE_BGVAL = wx.CheckBox(panel)
                    OUTPUT_OB = wx.StaticText(panel, label='Return Object Cube')
                    self.OUTPUT_OBVAL = wx.CheckBox(panel)
                    OUTPUT_TS = wx.StaticText(panel, label='Return Transmission Cube')
                    self.OUTPUT_TSVAL = wx.CheckBox(panel)
                    gapaa = wx.StaticText(panel, label=' ------------ ')
                    gapbb = wx.StaticText(panel, label=' ')
                    NOISESEED = wx.StaticText(panel, label="Noise Seed")
                    self.NOISESEEDVAL = wx.Choice(panel, choices=['Random', '1', '2'])
                    SETR = wx.StaticText(panel, label="Set Spec Samp [A/pix]")
                    self.SETRVAL = wx.TextCtrl(panel)
                    N_PROC = wx.StaticText(panel, label='No. of processors (1-'+str(mp.cpu_count())+')')
                    self.N_PROCVAL = wx.TextCtrl(panel, value=str(1))
                    RESJIT = wx.StaticText(panel, label="Additional PSF Blur [mas]:")
                    self.RESJITVAL = wx.TextCtrl(panel, value='0')

                    fgss.AddMany([(misc), (submisc),
                                  (REMOVE_BG), (self.REMOVE_BGVAL, 1, wx.EXPAND),
                                  (OUTPUT_OB), (self.OUTPUT_OBVAL, 1, wx.EXPAND),
                                  (OUTPUT_TS), (self.OUTPUT_TSVAL, 1, wx.EXPAND),
                                  (gapaa), (gapbb),
                                  (N_PROC), (self.N_PROCVAL, 1, wx.EXPAND),
                                  (NOISESEED), (self.NOISESEEDVAL, 1, wx.EXPAND),
                                  (SETR), (self.SETRVAL, 1, wx.EXPAND),
                                  (RESJIT), (self.RESJITVAL, 1, wx.EXPAND)])

                    fgss.AddGrowableCol(1,1)

                    hbox.Add(fgss, proportion=1, flag=wx.ALL|wx.EXPAND, border=10)

                    panel.SetSizer(hbox)

                    # A button
                    button =wx.Button(panel, 10, "Commence Simulation", wx.Point(360, 325))
                    wx.EVT_BUTTON(panel, 10, self.OnClick)