Exemplo n.º 1
0
def load_emissivity_phantom(phantom_id):

    try:
        emissivity_values = EMISSIVITY_PHANTOMS[phantom_id]
    except IndexError:
        raise ValueError("Phantom ID '{}' was not found.".format(phantom_id))

    return EmissivityGrid(grid,
                          case_id=phantom_id,
                          emissivities=emissivity_values)
Exemplo n.º 2
0
def load_blb_result_file(file_path, grid):

    # case ID will be the file name without the file extension code
    case_id = os.path.splitext(os.path.split(file_path)[1])[0]

    nx = 45
    ny = 83

    # load result file
    fh = open(file_path, "r")
    results_file = fh.readlines()
    fh.close()

    start_of_grid_values = 3 + nx + 1 + ny + 1
    start_of_detector_results = start_of_grid_values + (nx + 1) * (ny + 1)
    header = results_file[0:3]
    grid_definition = results_file[3:start_of_grid_values]
    raw_grid_values = results_file[
        start_of_grid_values:start_of_detector_results]
    raw_detector_values = results_file[start_of_detector_results:]

    emissivity_values = []
    for iy in range(ny):
        for ix in range(nx):
            if AUG_2D_TO_CHERAB_1D_GRID_MASK[iy, ix]:

                # calculate the AUG result data indices for the corners of this cell
                i1 = iy + ix * (ny + 1)
                i2 = (iy + 1) + ix * (ny + 1)
                i3 = (iy + 1) + (ix + 1) * (ny + 1)
                i4 = iy + (ix + 1) * (ny + 1)

                # calculate the average emissivity over the cell and save it
                avg_emissivity = (float(raw_grid_values[i1].strip()) +
                                  float(raw_grid_values[i2].strip()) +
                                  float(raw_grid_values[i3].strip()) +
                                  float(raw_grid_values[i4].strip())) / 4
                emissivity_values.append(avg_emissivity / (4 * np.pi))

    return EmissivityGrid(grid,
                          case_id=case_id,
                          emissivities=emissivity_values)
Exemplo n.º 3
0
    lines = fh.readlines()
    lines = lines[3868:]
    assert len(lines) == 3864

    raw_values = np.array([float(line.strip()) for line in lines]).reshape(
        (84, 46))

    mapped_phantom_values = np.zeros(grid.count)

    mapped_index = 0
    for i in range(83):
        for j in range(45):
            if grid_mask[i, j]:
                # need to convert cell values to W/m^3/str
                cell_avg = (raw_values[i, j] + raw_values[i + 1, j] +
                            raw_values[i + 1, j + 1] +
                            raw_values[i, j + 1]) / 4 / (4 * np.pi)
                mapped_phantom_values[mapped_index] = cell_avg
                mapped_index += 1

    phantom_id = "AUG_emission_phantom_" + str(phantom_index).zfill(3)
    emissivity_phantoms[phantom_id] = mapped_phantom_values

    emiss = EmissivityGrid(grid,
                           case_id="phantom_id",
                           emissivities=mapped_phantom_values)
    emiss.plot()
    plt.axis('equal')

pickle.dump(emissivity_phantoms, open('emissivity_phantoms.pickle', 'wb'))
Exemplo n.º 4
0
    # calculate observed power - uses volume method only since this is what is actually measured by the detector
    vol_obs_power = np.dot(vol_weight_matrix, emissivities)
    vol_obs_with_noise = vol_obs_power * (
        np.random.randn(len(vol_obs_power)) * NOISE_VARIANCE + 1)
    # Note - sightline version is same as volume obs version but with different etendue, as calculated per approximate formula
    # This is being applied as a correction factor, which effectively adds extra noise.
    los_obs_power = vol_obs_power / etendue_error_factor
    los_obs_with_noise = vol_obs_with_noise / etendue_error_factor  # keep noise the same in both data sets

    inverted_emiss_vector, conv = invert_sart(los_weight_matrix,
                                              los_obs_power,
                                              max_iterations=150)
    inverted_emiss = EmissivityGrid(
        grid,
        case_id='Phantom {} - LOS SART method'.format(
            str(phantom_index).zfill(2)),
        emissivities=inverted_emiss_vector)
    inverted_emiss.plot()
    plt.axis('equal')
    plt.savefig(
        os.path.join(OUTPUT_DIR,
                     "ph" + str(phantom_index).zfill(2) + "_sart_los.png"))
    row.append(
        float('{:.4G}'.format(inverted_emiss.total_radiated_power() / 1E6)))
    row.append(
        float('{:.3G}'.format(
            np.corrcoef(emiss_phantom.emissivities,
                        inverted_emiss.emissivities)[0][1])))
    row.append(len(conv))
Exemplo n.º 5
0

# inverted_emiss_vector, conv = invert_sart(los_weight_matrix, los_obs_power, max_iterations=100)
# inverted_emiss = EmissivityGrid(grid, case_id='Phantom 77 - LOS SART method', emissivities=inverted_emiss_vector)
# inverted_emiss.plot()
# plt.axis('equal')
# print()
# print('SART LOS Inversion total power - {:.4G}MW'.format(inverted_emiss.total_radiated_power()/1E6))
# print('Total iterations', len(conv), 'convergence', conv[-1])
# print('SART RAW LOS correlation - {:.3G}'.format(np.corrcoef(emiss77.emissivities, inverted_emiss.emissivities)[0][1]))

inverted_emiss_vector, conv = invert_sart(los_weight_matrix,
                                          los_obs_with_noise,
                                          max_iterations=100)
inverted_emiss = EmissivityGrid(grid,
                                case_id='Phantom 77 - LOS SART with noise',
                                emissivities=inverted_emiss_vector)
plot_inversion(inverted_emiss, colour_limits)
plt.axis('equal')
print()
print('SART LOS with noise total power - {:.4G}MW'.format(
    inverted_emiss.total_radiated_power() / 1E6))
print('Total iterations', len(conv), 'convergence', conv[-1])
print('SART RAW + NOISE LOS correlation - {:.3G}'.format(
    np.corrcoef(emiss77.emissivities, inverted_emiss.emissivities)[0][1]))

# inverted_emiss_vector, conv = invert_constrained_sart(los_weight_matrix, GRID_LAPLACIAN, los_obs_power, max_iterations=300, beta_laplace=80)
# inverted_emiss = EmissivityGrid(grid, case_id='Phantom 77 - LOS Constrained C-SART method', emissivities=np.squeeze(np.asarray(inverted_emiss_vector)))
# inverted_emiss.plot()
# plt.axis('equal')
# print()
Exemplo n.º 6
0
betas = np.array([10**x for x in np.linspace(1, 3.7, 40)])
los_rhos = []
vol_rhos = []

for beta in betas:

    inverted_emiss_vector, conv = invert_constrained_sart(los_weight_matrix,
                                                          GRID_LAPLACIAN,
                                                          obs_power,
                                                          max_iterations=300,
                                                          beta_laplace=beta)
    pearson_rho = np.corrcoef(emiss77.emissivities,
                              np.squeeze(
                                  np.asarray(inverted_emiss_vector)))[0][1]
    inverted_emiss = EmissivityGrid(
        grid,
        case_id='LOS C-SART method - {:.4G}, {:.4G}'.format(beta, pearson_rho),
        emissivities=np.squeeze(np.asarray(inverted_emiss_vector)))
    # inverted_emiss.plot()
    plt.axis('equal')
    print()
    print('Constrained C-SART LOS Inversion total power - {:.4G}MW'.format(
        inverted_emiss.total_radiated_power() / 1E6))
    print('Total iterations', len(conv), 'convergence', conv[-1])
    print('C-SART LOS correlation - {:.3G}'.format(pearson_rho))
    los_rhos.append(pearson_rho)

    inverted_emiss_vector, conv = invert_constrained_sart(vol_weight_matrix,
                                                          GRID_LAPLACIAN,
                                                          obs_power,
                                                          max_iterations=300,
                                                          beta_laplace=beta)
Exemplo n.º 7
0
cmap = plt.cm.viridis

# replace with path to your BLB geometry directory
AUG_BLB_CASE_DIRECTORY = os.path.expanduser("~/CCFE/mst1/aug_bolometry/BLB.33280_2")

EXCLUDED_CHANNELS = ['FVC1_A_CH1', 'FVC2_E_CH17', 'FLX_A_CH1', 'FDC_A_CH1', 'FDC_G_CH28', 'FHS_A_CH1'
                     'FHC1_A_CH1', 'FHC1_A_CH2', 'FHC1_A_CH3']

# Config file describing which bolometer cameras are active
grid = load_standard_inversion_grid()

active_cameras = load_blb_config_file(os.path.join(AUG_BLB_CASE_DIRECTORY, "config"))

result_blb33280_raw = load_blb_result_file(os.path.join(AUG_BLB_CASE_DIRECTORY, "resultef2d.BLB.33280_4.100000"), grid)

result_blb33280 = EmissivityGrid(grid, result_blb33280_raw.case_id, result_blb33280_raw.description, emissivities=np.clip(result_blb33280_raw.emissivities, 0, None))

etendue_error_factor_dict = pickle.load(open('/home/matt/CCFE/cherab/aug/demos/bolometry/etendue_comparison/aug_etendue_error_factor.pickle', 'rb'))


def process_detector_error(detector, emission_profile):

    los_sensitivity = detector._los_radiance_sensitivity.sensitivity
    vol_sensitivity = detector._volume_radiance_sensitivity.sensitivity
    vol_etendue = detector._volume_observer.sensitivity

    l_los = los_sensitivity.sum()
    l_vol = vol_sensitivity.sum()
    los_to_vol_factor = l_vol / l_los

    los_etendue_error_factor = etendue_error_factor_dict[detector.detector_id]  # error due to approximate etendue
Exemplo n.º 8
0
flx = load_default_bolometer_config('FLX', inversion_grid=grid)

detector_keys, los_weight_matrix, vol_weight_matrix = assemble_weight_matrix(
    [fhc, flh, fhs, fvc, fdc, flx], excluded_detectors=EXCLUDED_CHANNELS)

obs_power = np.dot(vol_weight_matrix, phantom_emiss.emissivities)

plt.ion()
phantom_emiss.plot()
plt.axis('equal')
print('Phantom total power - {:.4G}MW'.format(
    phantom_emiss.total_radiated_power() / 1E6))

inverted_emiss_vector = invert_svd(los_weight_matrix, obs_power)
inverted_emiss = EmissivityGrid(grid,
                                case_id='Phantom 77 - LOS method',
                                emissivities=inverted_emiss_vector)
inverted_emiss.plot()
plt.axis('equal')
print('SVD LOS Inversion total power - {:.4G}MW'.format(
    inverted_emiss.total_radiated_power() / 1E6))
print('SVD LOS correlation - {:.3G}'.format(
    np.corrcoef(phantom_emiss.emissivities,
                inverted_emiss.emissivities)[0][1]))

inverted_emiss_vector = invert_svd(vol_weight_matrix, obs_power)
inverted_emiss = EmissivityGrid(grid,
                                case_id='Phantom 77 - Volume method',
                                emissivities=inverted_emiss_vector)
inverted_emiss.plot()
plt.axis('equal')
Exemplo n.º 9
0
for i in range(len(test_fhc13)):
    if fhc13_real[i] != test_fhc13[i]:
        print('Warning {} != {}'.format(fhc13_real[i], test_fhc13[i]))

    fhc13_obs_power += fhc13_real[i] * emiss[i]

vol_obs_power = np.dot(vol_weight_matrix, emiss77.emissivities)

print("fhc13_obs_power", fhc13_obs_power)
print("obs_power", vol_obs_power[9])

inverted_vol_emiss_vector, rnorm = invert_regularised_nnls(vol_weight_matrix,
                                                           vol_obs_power,
                                                           alpha=0.0000000001)
inverted_vol_emiss = EmissivityGrid(grid,
                                    case_id='Phantom 77 - VOL method',
                                    emissivities=inverted_vol_emiss_vector)

inverted_los_emiss_vector, rnorm = invert_regularised_nnls(los_weight_matrix,
                                                           vol_obs_power,
                                                           alpha=0.0000000001)
inverted_los_emiss = EmissivityGrid(grid,
                                    case_id='Phantom 77 - LOS method',
                                    emissivities=inverted_los_emiss_vector)

fhc13_inverted_power = 0
for i in range(len(test_fhc13)):
    fhc13_inverted_power += fhc13_real[i] * inverted_vol_emiss_vector[i]
print("fhc13_inverted_power", fhc13_inverted_power)

plt.ion()