Exemplo n.º 1
0
def test_setup_wcs():
    """ setting size of IFU given input min,max and cdelts """

    ra_center = 45.0
    ra_diff = 2.0 / 3600.0
    dec_center = 45.0
    dec_diff = 2.0 / 3600.0

    ra_min = ra_center - ra_diff
    ra_max = ra_center + ra_diff

    dec_min = dec_center - dec_diff
    dec_max = dec_center + dec_diff

    lambda_min = 7.5
    lambda_max = 8.5

    footprint = (ra_min, ra_max, dec_min, dec_max, lambda_min, lambda_max)

    pars_cube = {
        'scale1': None,
        'scale2': None,
        'scalew': None,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': 2,
        'coord_system': 'world',
        'rois': None,
        'roiw': None,
        'wavemin': lambda_min,
        'wavemax': lambda_max,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    pipeline = 3
    filename = None
    input_model = None
    output_name_base = None
    output_type = None
    instrument = None
    list_par1 = None
    list_par2 = None
    master_table = None
    instrument_info = None
    thiscube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                    output_name_base, output_type, instrument,
                                    list_par1, list_par2, instrument_info,
                                    master_table, **pars_cube)

    thiscube.cdelt1 = 0.1
    thiscube.cdelt2 = 0.1
    thiscube.cdelt3 = 0.001
    thiscube.linear_wavelength = True
    thiscube.set_geometry(footprint)

    assert thiscube.naxis1 == 30
    assert thiscube.naxis2 == 41
    assert thiscube.naxis3 == 1000
Exemplo n.º 2
0
def test_setup_wcs():
    """ setting size of IFU given input min,max and cdelts """
    ra1 = 98.83006930071556
    dec1 = -66.8274397956464
    ra2 = 98.8334511693978
    dec2 = -66.82720255674548
    ra3 = 98.83217303911556
    dec3 = -66.82798122840644
    ra4 = 98.83139113841862
    dec4 = -66.82665445039441
    lambda_min = 6.420
    lambda_max = 7.511

    corner_a = []
    corner_b = []
    corner_a.append(ra1)
    corner_a.append(ra2)
    corner_a.append(ra3)
    corner_a.append(ra4)

    corner_b.append(dec1)
    corner_b.append(dec2)
    corner_b.append(dec3)
    corner_b.append(dec4)

    pars_cube = {
        'scale1': 0.0,
        'scale2': 0.0,
        'scalew': 0.0,
        'interpolation': 'pointcloud',
        'weighting': 'emsm',
        'weight_power': 2,
        'coord_system': 'skyalign',
        'rois': 0.0,
        'roiw': 0.0,
        'wavemin': lambda_min,
        'wavemax': lambda_max,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'spaxel_debug': None
    }

    pipeline = 3
    filename = None
    input_model = None
    output_name_base = None
    output_type = None
    instrument = None
    list_par1 = None
    list_par2 = None
    master_table = None
    instrument_info = None
    thiscube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                    output_name_base, output_type, instrument,
                                    list_par1, list_par2, instrument_info,
                                    master_table, **pars_cube)

    thiscube.cdelt1 = 0.13
    thiscube.cdelt2 = 0.13
    thiscube.cdelt3 = 0.001
    thiscube.linear_wavelength = True
    thiscube.set_geometry(corner_a, corner_b, lambda_min, lambda_max)

    assert thiscube.naxis1 == 41
    assert thiscube.naxis2 == 41
    assert thiscube.naxis3 == 1092
Exemplo n.º 3
0
def test_nirspec_cubepars(_jail, nirspec_cube_pars):
    """ Read in the nirspec cube pars file """

    instrument_info = instrument_defaults.InstrumentInfo()
    all_channel = []
    all_subchannel = []
    all_grating = []
    all_filter = []
    all_grating.append('prism')
    all_filter.append('clear')

    cube_build_io_util.read_cubepars(nirspec_cube_pars, 'NIRSPEC', all_channel,
                                     all_subchannel, all_grating, all_filter,
                                     instrument_info)

    par1 = 'prism'
    par2 = 'clear'
    ascale, bscale, wscale = instrument_info.GetScale(par1, par2)
    assert math.isclose(ascale, 0.1, abs_tol=0.00001)
    assert math.isclose(bscale, 0.1, abs_tol=0.00001)
    assert math.isclose(wscale, 0.005, abs_tol=0.00001)

    roiw = instrument_info.GetWaveRoi(par1, par2)
    rois = instrument_info.GetSpatialRoi(par1, par2)
    power = instrument_info.GetMSMPower(par1, par2)
    wavemin = instrument_info.GetWaveMin(par1, par2)
    wavemax = instrument_info.GetWaveMax(par1, par2)

    assert math.isclose(roiw, 0.011, abs_tol=0.00001)
    assert math.isclose(rois, 0.201, abs_tol=0.00001)
    assert math.isclose(power, 2, abs_tol=0.00001)
    assert math.isclose(wavemin, 0.6, abs_tol=0.00001)
    assert math.isclose(wavemax, 5.3, abs_tol=0.00001)

    #set up the ifucube class

    pars_cube = {
        'scale1': 0.0,
        'scale2': 0.0,
        'scalew': 0.0,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': 2,
        'coord_system': 'world',
        'rois': 0.0,
        'roiw': 0.0,
        'wavemin': None,
        'wavemax': None,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    pipeline = 3
    filename = None
    input_model = None
    output_name_base = None
    output_type = 'band'
    instrument = 'NIRSPEC'
    list_par1 = all_grating
    list_par2 = all_filter
    master_table = None
    instrument_info = instrument_info
    this_cube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                     output_name_base, output_type, instrument,
                                     list_par1, list_par2, instrument_info,
                                     master_table, **pars_cube)

    this_cube.num_files = 1  # set in ifu cube
    # test that the correct values read from the table are filled
    # in in the this_cube class. Also check that for this configuration
    # linear_wavelength = 'True'
    this_cube.determine_cube_parameters()

    assert math.isclose(this_cube.wavemin, wavemin, abs_tol=0.00001)
    assert math.isclose(this_cube.wavemax, wavemax, abs_tol=0.00001)
    assert this_cube.linear_wavelength == True

    assert math.isclose(this_cube.weight_power, 2, abs_tol=0.00001)
    assert math.isclose(this_cube.roiw, 0.011, abs_tol=0.00001)
    rois = 0.201 * 1.5  # increase for single file
    assert math.isclose(this_cube.rois, rois, abs_tol=0.00001)
    assert math.isclose(this_cube.spatial_size, 0.1, abs_tol=0.00001)

    # now test if the user has provided input to build cube

    user_ascale = 0.2
    user_wscale = 0.05
    user_power = 1
    user_wave_min = 0.8
    user_wave_max = 4.5
    user_rois = 0.6
    user_roiw = 0.8
    pars_cube = {
        'scale1': user_ascale,
        'scale2': user_ascale,
        'scalew': user_wscale,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': user_power,
        'coord_system': 'world',
        'rois': user_rois,
        'roiw': user_roiw,
        'wavemin': user_wave_min,
        'wavemax': user_wave_max,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    this_cube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                     output_name_base, output_type, instrument,
                                     list_par1, list_par2, instrument_info,
                                     master_table, **pars_cube)

    this_cube.num_files = 1  # set in check_ifucube
    this_cube.determine_cube_parameters()
    # do they match the user provided ones
    assert math.isclose(this_cube.wavemin, user_wave_min, abs_tol=0.00001)
    assert math.isclose(this_cube.wavemax, user_wave_max, abs_tol=0.00001)
    assert this_cube.linear_wavelength == True
    assert math.isclose(this_cube.spatial_size, user_ascale, abs_tol=0.00001)
    assert math.isclose(this_cube.spectral_size, user_wscale, abs_tol=0.00001)
    assert math.isclose(this_cube.weight_power, user_power, abs_tol=0.00001)
    assert math.isclose(this_cube.roiw, user_roiw, abs_tol=0.00001)
    assert math.isclose(this_cube.rois, user_rois, abs_tol=0.00001)
Exemplo n.º 4
0
def test_miri_cubepars_multiple_bands(_jail, miri_cube_pars):
    """ Read in the miri cube pars file. Test cube has correct values when multiple bands are used """

    instrument_info = instrument_defaults.InstrumentInfo()
    all_channel = []
    all_subchannel = []
    all_grating = []
    all_filter = []
    # set up all_channel and all_subchannel - 1 to 1 matching between the two
    all_channel.append('1')
    all_channel.append('1')
    all_channel.append('1')
    all_channel.append('2')
    all_channel.append('2')
    all_channel.append('2')
    all_channel.append('3')
    all_channel.append('3')
    all_channel.append('3')

    all_subchannel.append('short')
    all_subchannel.append('medium')
    all_subchannel.append('long')
    all_subchannel.append('short')
    all_subchannel.append('medium')
    all_subchannel.append('long')
    all_subchannel.append('short')
    all_subchannel.append('medium')
    all_subchannel.append('long')

    cube_build_io_util.read_cubepars(miri_cube_pars, 'MIRI', 'msm',
                                     all_channel, all_subchannel, all_grating,
                                     all_filter, instrument_info)

    # test reading in another band we have not checked before
    par1 = '3'
    par2 = 'medium'

    # first check that it reads in correct values for this band
    # from the reference file
    ascale, bscale, wscale = instrument_info.GetScale(par1, par2)

    assert math.isclose(ascale, 0.2, abs_tol=0.00001)
    assert math.isclose(bscale, 0.2, abs_tol=0.00001)
    assert math.isclose(wscale, 0.003, abs_tol=0.00001)

    roiw = instrument_info.GetWaveRoi(par1, par2)
    rois = instrument_info.GetSpatialRoi(par1, par2)
    power = instrument_info.GetMSMPower(par1, par2)
    wavemin = instrument_info.GetWaveMin(par1, par2)
    wavemax = instrument_info.GetWaveMax(par1, par2)

    assert math.isclose(roiw, 0.003, abs_tol=0.00001)
    assert math.isclose(rois, 0.2, abs_tol=0.00001)
    assert math.isclose(power, 2, abs_tol=0.00001)
    assert math.isclose(wavemin, 13.37, abs_tol=0.00001)
    assert math.isclose(wavemax, 15.63, abs_tol=0.00001)

    #set up the ifucube class
    pars_cube = {
        'scale1': 0.0,
        'scale2': 0.0,
        'scalew': 0.0,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': 2,
        'coord_system': 'world',
        'rois': 0.0,
        'roiw': 0.0,
        'wavemin': None,
        'wavemax': None,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    pipeline = 3
    filename = None
    input_model = None
    output_name_base = None
    output_type = 'multi'
    instrument = 'MIRI'
    list_par1 = all_channel
    list_par2 = all_subchannel
    master_table = None
    instrument_info = instrument_info
    this_cube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                     output_name_base, output_type, instrument,
                                     list_par1, list_par2, instrument_info,
                                     master_table, **pars_cube)

    this_cube.num_files = 12  # set in ifu cube
    # test that the correct values read from the table are filled
    # in in the this_cube class when multiple bands and output_type = multi
    # are set. Also check that for this configuration linear_wavelength = False
    this_cube.determine_cube_parameters()

    # for multiple bands the smallest spatial scale is chosen
    assert math.isclose(this_cube.spatial_size, 0.13, abs_tol=0.00001)
    assert this_cube.linear_wavelength == False

    # wavemin - min for channels 1-3 (min of channel 1 short)
    assert math.isclose(this_cube.wavemin, 4.89, abs_tol=0.00001)
    # wavemas = max for channels 1-3 (max of channel 3 long)
    assert math.isclose(this_cube.wavemax, 18.05, abs_tol=0.00001)

    weight_test = np.array([1, 2, 3, 4])
    roiw_test = np.array([0.001, 0.002, 0.003, 0.004])
    rois_test = np.array([0.1, 0.2, 0.3, 0.4])
    wave_test = np.array([5, 10, 15, 20])
    assert np.allclose(this_cube.weight_power_table, weight_test, rtol=0.00001)
    assert np.allclose(this_cube.roiw_table, roiw_test, rtol=0.00001)
    assert np.allclose(this_cube.rois_table, rois_test, rtol=0.00001)
    assert np.allclose(this_cube.wavelength_table, wave_test, rtol=0.00001)
Exemplo n.º 5
0
def test_miri_use_cubepars(_jail, miri_cube_pars):
    """ Test reading in the miri cube pars file """

    instrument_info = instrument_defaults.InstrumentInfo()
    all_channel = []
    all_subchannel = []
    all_grating = []
    all_filter = []
    all_channel.append('1')
    all_subchannel.append('medium')

    cube_build_io_util.read_cubepars(miri_cube_pars, 'MIRI', 'msm',
                                     all_channel, all_subchannel, all_grating,
                                     all_filter, instrument_info)

    par1 = '1'
    par2 = 'medium'

    ascale, bscale, wscale = instrument_info.GetScale(par1, par2)

    # check that the values are read in correctly
    assert math.isclose(ascale, 0.13, abs_tol=0.00001)
    assert math.isclose(bscale, 0.13, abs_tol=0.00001)
    assert math.isclose(wscale, 0.001, abs_tol=0.00001)

    roiw = instrument_info.GetWaveRoi(par1, par2)
    rois = instrument_info.GetSpatialRoi(par1, par2)
    power = instrument_info.GetMSMPower(par1, par2)
    wavemin = instrument_info.GetWaveMin(par1, par2)
    wavemax = instrument_info.GetWaveMax(par1, par2)

    assert math.isclose(roiw, 0.001, abs_tol=0.00001)
    assert math.isclose(rois, 0.1, abs_tol=0.00001)
    assert math.isclose(power, 2, abs_tol=0.00001)
    assert math.isclose(wavemin, 5.65, abs_tol=0.00001)
    assert math.isclose(wavemax, 6.64, abs_tol=0.00001)

    #set up the ifucube class
    pars_cube = {
        'scale1': 0.0,
        'scale2': 0.0,
        'scalew': 0.0,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': 2,
        'coord_system': 'world',
        'rois': 0.0,
        'roiw': 0.0,
        'wavemin': None,
        'wavemax': None,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    pipeline = 3
    filename = None
    input_model = None
    output_name_base = None
    output_type = 'band'
    instrument = 'MIRI'
    list_par1 = all_channel
    list_par2 = all_subchannel
    master_table = None
    instrument_info = instrument_info
    this_cube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                     output_name_base, output_type, instrument,
                                     list_par1, list_par2, instrument_info,
                                     master_table, **pars_cube)

    this_cube.num_files = 1  # set in ifu cube
    # test that the correct values read from the table are filled
    # in in the this_cube class. Also check that for this configuration
    # linear_wavelength = True
    this_cube.determine_cube_parameters()

    assert math.isclose(this_cube.wavemin, wavemin, abs_tol=0.00001)
    assert math.isclose(this_cube.wavemax, wavemax, abs_tol=0.00001)
    assert this_cube.linear_wavelength == True

    assert math.isclose(this_cube.weight_power, 2, abs_tol=0.00001)
    assert math.isclose(this_cube.roiw, 0.001, abs_tol=0.00001)
    rois = 0.1 * 1.5  # increase for single file
    assert math.isclose(this_cube.rois, rois, abs_tol=0.00001)
    assert math.isclose(this_cube.spatial_size, 0.13, abs_tol=0.00001)
Exemplo n.º 6
0
def test_miri_cubepars_user_defaults(_jail, miri_cube_pars):
    """ Read in the miri cube pars file and override some defaults """

    instrument_info = instrument_defaults.InstrumentInfo()
    all_channel = []
    all_subchannel = []
    all_grating = []
    all_filter = []
    all_channel.append('4')
    all_subchannel.append('long')

    cube_build_io_util.read_cubepars(miri_cube_pars, 'MIRI', 'msm',
                                     all_channel, all_subchannel, all_grating,
                                     all_filter, instrument_info)

    # test another band
    par1 = '4'
    par2 = 'long'

    # first check that it reads in correct values for this band
    # from the reference file
    ascale, bscale, wscale = instrument_info.GetScale(par1, par2)

    assert math.isclose(ascale, 0.35, abs_tol=0.00001)
    assert math.isclose(bscale, 0.35, abs_tol=0.00001)
    assert math.isclose(wscale, 0.006, abs_tol=0.00001)

    roiw = instrument_info.GetWaveRoi(par1, par2)
    rois = instrument_info.GetSpatialRoi(par1, par2)
    power = instrument_info.GetMSMPower(par1, par2)
    wavemin = instrument_info.GetWaveMin(par1, par2)
    wavemax = instrument_info.GetWaveMax(par1, par2)

    assert math.isclose(roiw, 0.006, abs_tol=0.00001)
    assert math.isclose(rois, 0.4, abs_tol=0.00001)
    assert math.isclose(power, 2, abs_tol=0.00001)
    assert math.isclose(wavemin, 23.95, abs_tol=0.00001)
    assert math.isclose(wavemax, 28.45, abs_tol=0.00001)

    # set up the ifucube class
    pars_cube = {
        'scale1': 0.0,
        'scale2': 0.0,
        'scalew': 0.0,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': 2,
        'coord_system': 'world',
        'rois': 0.0,
        'roiw': 0.0,
        'wavemin': None,
        'wavemax': None,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    pipeline = 3
    filename = None
    input_model = None
    output_name_base = None
    output_type = 'band'
    instrument = 'MIRI'
    list_par1 = all_channel
    list_par2 = all_subchannel
    master_table = None
    instrument_info = instrument_info
    this_cube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                     output_name_base, output_type, instrument,
                                     list_par1, list_par2, instrument_info,
                                     master_table, **pars_cube)

    this_cube.num_files = 1  # set in ifu cube
    # test that the correct values read from the table are filled
    # in in the this_cube class. Also check that for this configuration
    # linear_wavelength = True
    this_cube.determine_cube_parameters()
    # now test if the user has provided input to build cube

    assert math.isclose(this_cube.wavemin, wavemin, abs_tol=0.00001)
    assert math.isclose(this_cube.wavemax, wavemax, abs_tol=0.00001)
    assert this_cube.linear_wavelength

    assert math.isclose(this_cube.weight_power, 2, abs_tol=0.00001)
    assert math.isclose(this_cube.roiw, roiw, abs_tol=0.00001)
    rois = rois * 1.5  # increase for single file
    assert math.isclose(this_cube.rois, rois, abs_tol=0.00001)
    assert math.isclose(this_cube.spatial_size, 0.35, abs_tol=0.00001)

    user_ascale = 0.2
    user_wscale = 0.05
    user_power = 1
    user_wave_min = 24.5
    user_wave_max = 27.5
    user_rois = 0.6
    user_roiw = 0.8
    pars_cube = {
        'scale1': user_ascale,
        'scale2': user_ascale,
        'scalew': user_wscale,
        'interpolation': 'pointcloud',
        'weighting': 'msm',
        'weight_power': user_power,
        'coord_system': 'world',
        'rois': user_rois,
        'roiw': user_roiw,
        'wavemin': user_wave_min,
        'wavemax': user_wave_max,
        'skip_dqflagging': False,
        'xdebug': None,
        'ydebug': None,
        'zdebug': None,
        'debug_pixel': 0,
        'spaxel_debug': None
    }

    this_cube = ifu_cube.IFUCubeData(pipeline, filename, input_model,
                                     output_name_base, output_type, instrument,
                                     list_par1, list_par2, instrument_info,
                                     master_table, **pars_cube)

    this_cube.num_files = 1  # set in check_ifucube
    this_cube.determine_cube_parameters()
    # do they match the user provided ones
    assert math.isclose(this_cube.wavemin, user_wave_min, abs_tol=0.00001)
    assert math.isclose(this_cube.wavemax, user_wave_max, abs_tol=0.00001)
    assert this_cube.linear_wavelength
    assert math.isclose(this_cube.spatial_size, user_ascale, abs_tol=0.00001)
    assert math.isclose(this_cube.spectral_size, user_wscale, abs_tol=0.00001)
    assert math.isclose(this_cube.weight_power, user_power, abs_tol=0.00001)
    assert math.isclose(this_cube.roiw, user_roiw, abs_tol=0.00001)
    assert math.isclose(this_cube.rois, user_rois, abs_tol=0.00001)