コード例 #1
0
def generate_ibsen_calibration_files(directory, reference):
    # Extract Rasta specific raw data
    cal_dict = sort_ibsen_by_int(directory)
    cal_dict_tmp = copy.deepcopy(cal_dict)
    bias_file = directory + 'assumed_bias/' + 'bias.txt'
    flag = os.path.exists(bias_file)
    noise_dict = get_noise(flag)(bias_file, cal_dict)

    # Substract darkcurrent from measurements
    nonlinear_config = {'max_lowest_int_time': 2323 , 'sigma': 100, 'index_start_spline_fit': 1500, 'gaussian_mean_steps':4}
    #nonlinear_config = {'max_lowest_int_time': 1156, 'sigma': 50, 'index_start_spline_fit': 1400, 'gaussian_mean_steps':4}
    nonlinear_correction_dict = generate_nonlinear_correction(cal_dict_tmp, nonlinear_config, noise_dict)
    noise_dict['noise'] = np.zeros(len(noise_dict['channel']))  # Setting offset to zero
    cal_dict_tmp = subtract_dark(cal_dict_tmp)
    nonlinear_correction_dark = generate_nonlinear_correction(cal_dict_tmp, nonlinear_config, noise_dict)
    check_nonlinearity(cal_dict, [nonlinear_correction_dict, nonlinear_correction_dark])
    cal_dict = subtract_dark(cal_dict)
    while raw_input('Change settings (y or n)') == 'y':
        for key in nonlinear_config.keys():
            nonlinear_config[key] = int(raw_input('%s' %key))
        nonlinear_correctiony_dict = generate_nonlinear_correction(cal_dict, nonlinear_config)
        check_nonlinearity(cal_dict, nonlinear_correction_dict)

    #Nonlinear correction for ibsen response
    for integration, spectra in cal_dict.items():
        spectra['reference']['mean'] = spectra['reference']['mean'] / np.interp(spectra['reference']['mean'], nonlinear_correction_dict['DN'], nonlinear_correction_dict['nonlinear'])
        spectra['reference']['mean'] = spectra['reference']['mean'] / integration
    # Generate ibsen response factors for physical units
    cal_dict, response_dict = generate_response_factors(cal_dict, reference)
    import matplotlib.pyplot as plt
    for integration, spectra in cal_dict.items():
        spectra['reference']['mean'] = spectra['reference']['mean'] / np.interp(spectra['reference']['wave'], response_dict['wave'], response_dict['scale_factors'])
        plt.plot(spectra['reference']['wave'], spectra['reference']['mean'])
    plt.xlabel('Wavelength $\lambda$ [nm]', **hfont)
    plt.ylabel(r'$\frac{mW}{nm m^2 sr}$', **hfont)
    plt.show()

    fix, ax1 = plt.subplots()
    ax1.plot(response_dict['wave'], response_dict['intensity'], 'r+', label='Ibsen response')
    ax1.set_xlabel('Wavelength $\lambda$ [nm]', **hfont)
    ax1.set_ylabel('Signal [DN]')
    ax1.legend(loc=2, ncol=1, prop = fontP,fancybox=True, shadow=False)
    ax2 = ax1.twinx()
    ax2.plot(response_dict['wave'], response_dict['halogen'], 'y+', label='Halogen lamp')
    ax2.plot(response_dict['wave'], response_dict['intensity'] / response_dict['scale_factors'], 'b', label='Calibrated ibsen response')
    ax2.set_ylabel(r'$\frac{mW}{nm m^2 sr}$', **hfont)
    ax2.legend(loc=1, ncol=1, prop = fontP,fancybox=True, shadow=False)
    plt.show()


    plt.plot(response_dict['wave'], response_dict['intensity'], 'r+', label='Ibsen response')
    plt.plot(response_dict['wave'], response_dict['halogen'], 'y+', label='Halogen lamp')
    plt.plot(response_dict['wave'], response_dict['intensity'] / response_dict['scale_factors'], 'b', label='Calibrated ibsen response')
    plt.xlabel('Wavelength $\lambda$ [nm]', **hfont)
    plt.ylabel(r'$\frac{mW}{nm m^2 sr}$', **hfont)
    plt.legend(loc=2, ncol=1, prop = fontP,fancybox=True, shadow=False,bbox_to_anchor=(1.0, 1.0))
    plt.show()
コード例 #2
0
def test_offset_subtraction():
    """ testing of offset subtraction or darkcurrent subtraction is better"""
    test_directory = '/home/joanna/DLR/Codes/calibration/test_nonlinearity/labor/ibsen_nonlinearity_verschoeben2/'
    offset = 'offset_corrected_calibration/'
    dark_ = 'darkcurrent_corrected_calibration/'
    _file = 'nonlinearity_correction.txt'
    nonlinear_correction_dict = dict()
    nonlinear_correction_dict_dark = dict()
    cal_dict = sort_ibsen_by_int(test_directory)
    nonlinear_correction_dict['DN'], nonlinear_correction_dict['nonlinear'] = read_nonlinear_correction_file(offset + _file)
    nonlinear_correction_dict_dark['DN'], nonlinear_correction_dict_dark['nonlinear'] = read_nonlinear_correction_file(dark_ + _file)
    check_nonlinearity(cal_dict, [nonlinear_correction_dict,nonlinear_correction_dict_dark])
コード例 #3
0
def test_offset_subtraction():
    """ testing of offset subtraction or darkcurrent subtraction is better"""
    test_directory = "/home/jana_jo/DLR/Codes/calibration/test_nonlinearity/labor/ibsen_nonlinearity_verschoeben2/"
    offset = "offset_corrected_calibration/"
    dark_ = "darkcurrent_corrected_calibration/"
    _file = "nonlinearity_correction.txt"
    nonlinear_correction_dict = dict()
    nonlinear_correction_dict_dark = dict()
    cal_dict = sort_ibsen_by_int(test_directory)
    nonlinear_correction_dict["DN"], nonlinear_correction_dict["nonlinear"] = read_nonlinear_correction_file(
        offset + _file
    )
    nonlinear_correction_dict_dark["DN"], nonlinear_correction_dict_dark["nonlinear"] = read_nonlinear_correction_file(
        dark_ + _file
    )
    check_nonlinearity(cal_dict, [nonlinear_correction_dict, nonlinear_correction_dict_dark])