Beispiel #1
0
def _load_solps_simulation(config, world):

    if config['plasma']['edge']['SOLPS_format'] == 'MDSplus':

        print()
        print("loading MDPsplus SOLPS plasma")

        from cherab.solps import load_solps_from_mdsplus

        mds_server = config['plasma']['edge']['mds_server']
        mds_solps_reference = config['plasma']['edge']['mds_solps_reference']

        sim = load_solps_from_mdsplus(mds_server, mds_solps_reference)
        plasma = sim.create_plasma(parent=world)

    elif config['plasma']['edge']['SOLPS_format'] == 'Files':

        from cherab.solps import load_solps_from_raw_output

        solps_directory = config['plasma']['edge']['solps_directory']
        sim = load_solps_from_raw_output(solps_directory, debug=True)
        plasma = sim.create_plasma(parent=world)

    else:
        raise ValueError("Unrecognised SOLPS format '{}'.".format(
            config['plasma']['edge']['SOLPS_format']))

    return plasma
import matplotlib.pyplot as plt
import numpy as np

from cherab.core.atomic.elements import carbon, deuterium
from cherab.solps import load_solps_from_mdsplus

plt.ion()

mds_server = 'solps-mdsplus.aug.ipp.mpg.de:8001'
ref_number = 69636

xl, xu = (0.0, 2.0)
yl, yu = (-2.0, 2.0)

sim = load_solps_from_mdsplus(mds_server, ref_number)
plasma = sim.create_plasma()
mesh = sim.mesh
vessel = mesh.vessel

d0 = plasma.composition.get(deuterium, 0)
d1 = plasma.composition.get(deuterium, 1)
c0 = plasma.composition.get(carbon, 0)
c1 = plasma.composition.get(carbon, 1)
c2 = plasma.composition.get(carbon, 2)
c3 = plasma.composition.get(carbon, 3)
c4 = plasma.composition.get(carbon, 4)
c5 = plasma.composition.get(carbon, 5)
c6 = plasma.composition.get(carbon, 6)

te_samples = np.zeros((500, 500))
    def __init__(self, solps_ref_no, view, line, camera, optics='MAST_CI_mod', cherab_down_sample=50, verbose=True,
                 display=False, overwrite=False):
        """
        :param solps_ref_no: int
        :param view: str
        :param line: str
        :param camera: str
        :param optics: str
        :param cherab_down_sample: int downsample the image by ths factor in both dimensions, for speed / testing.
        :param verbose: bool
        :param display: bool
        :param overwrite: bool
        """

        self.world = World()
        self.solps_ref_no = solps_ref_no
        self.line = line
        self.view = view
        self.camera = camera
        self.optics = optics
        self.cherab_down_sample = cherab_down_sample
        self.verbose = verbose
        self.display = display
        self.overwrite = overwrite

        self.radiance = NotImplemented
        self.spectral_radiance = NotImplemented

        self.pupil_point = settings.view[self.view]['pupil_point']
        self.view_vector = settings.view[self.view]['view_vector']
        self.sensor_format = settings.camera[self.camera]['sensor_format']
        for s in self.sensor_format:
            assert s % cherab_down_sample == 0
        self.sensor_format_ds = tuple((np.array(self.sensor_format) / cherab_down_sample).astype(np.int))
        self.pixel_size = settings.camera[self.camera]['pixel_size']
        self.pixel_size_ds = self.pixel_size * cherab_down_sample

        self.x, self.y, = self.calc_pixel_position(self.pixel_size, self.sensor_format)
        self.x_pixel = self.x.x_pixel
        self.y_pixel = self.y.y_pixel

        self.x_ds = self.x.isel(x=slice(0, self.sensor_format[0], cherab_down_sample, ))
        self.y_ds = self.y.isel(y=slice(0, self.sensor_format[1], cherab_down_sample, ))
        self.x_pixel_ds = self.x_ds.x_pixel
        self.y_pixel_ds = self.y_ds.y_pixel

        self.chunks = {'x': 800, 'y': 800}

        # calculate field of view (FOV) (horizontal) using sensor geometry and lens focal lengths
        f_1, f_2, f_3 = settings.optics[self.optics]
        sensor_dim = self.sensor_format[0] * self.pixel_size
        self.fov = 2 * np.arctan((sensor_dim / 2) * f_2 / (f_3 * f_1)) * 180 / np.pi  # deg
#
        # file and directory paths
        self.dir_name = str(solps_ref_no) + '_' + view + '_' + line + '_' + camera
        self.dir_path = os.path.join(path_saved_data, self.dir_name)
        fname = 'spec_power.nc'
        fname_ds = 'spec_power_ds.nc'
        self.fpath_ds = os.path.join(self.dir_path, fname_ds, )
        self.fpath = os.path.join(self.dir_path, fname, )

        # load SOLPS plasma and set emission line model
        self.sim = load_solps_from_mdsplus(mds_server, self.solps_ref_no)
        self.plasma = self.sim.create_plasma(parent=self.world)
        self.plasma.atomic_data = OpenADAS(permit_extrapolation=True)

        emission_line = settings.line[self.line]
        element, charge, transition = [emission_line[s] for s in ['element', 'charge', 'transition', ]]
        line_obj = Line(element, charge, transition, )
        self._line_excit = ExcitationLine(line_obj, lineshape=StarkBroadenedLine)
        self._line_recom = RecombinationLine(line_obj, lineshape=StarkBroadenedLine)
        self.plasma.models = [Bremsstrahlung(), self._line_excit, self._line_recom]
        wl_0_nm = self._line_excit.atomic_data.wavelength(element, charge, transition, )
        self.wl_0 = wl_0_nm * 1e-9  # [m]
        self.wl_min_nm, self.wl_max_nm = wl_0_nm - 0.2, wl_0_nm + 0.2  # [m]

        # ugly, but I want to convert the density units to 10^{20} m^{-3}
        def get_ne(x, y, z, ):
            return 1e-20 * self.plasma.electron_distribution.density(x, y, z, )

        def get_ni(x, y, z, ):
            return 1e-20 * self.plasma.composition.get(deuterium, 0).distribution.density(x, y, z, )

        def get_b_field_mag(x, y, z, ):
            """
            magnitude of the magnetic field at x, y, z
            :param x:
            :param y:
            :param z:
            :return:
            """
            return self.plasma.b_field(x, y, z, ).length

        def get_emiss_excit(x, y, z, ):
            return self._line_excit.emission(Point3D(x, y, z, ), Vector3D(1, 1, 1), Spectrum(380, 700, 100)).total()

        def get_emiss_recom(x, y, z, ):
            return self._line_recom.emission(Point3D(x, y, z, ), Vector3D(1, 1, 1), Spectrum(380, 700, 100)).total()

        self.valid_param_get_fns = {'ne': get_ne,
                                    'ni': get_ni,
                                    'te': self.plasma.electron_distribution.effective_temperature,
                                    'ti': self.plasma.composition.get(deuterium, 0).distribution.effective_temperature,
                                    'tn': self.plasma.composition.get(deuterium, 1).distribution.effective_temperature,
                                    'b_field_mag': get_b_field_mag,
                                    'emiss_excit': get_emiss_excit,
                                    'emiss_recom': get_emiss_recom,
                                    }
        self.valid_params = list(self.valid_param_get_fns.keys())

        # load / make the cherab image
        if os.path.isdir(self.dir_path) and self.overwrite is False:
            if os.path.isfile(self.fpath) and os.path.isfile(self.fpath_ds):
                pass
        else:
            if not os.path.isdir(self.dir_path):
                os.mkdir(self.dir_path)
                self.make_cherab_image()

        ds, ds_ds = self.load_cherab_image()
        self.spectral_radiance = ds['spectral_radiance']
        self.radiance = self.spectral_radiance.integrate(dim='wavelength')
        self.radiance = xr.where(xr.ufuncs.isnan(self.radiance), 0, self.radiance, )

        self.spectral_radiance_ds = ds_ds['spectral_radiance_ds']
        self.radiance_ds = ds_ds['radiance_ds']
        self.view_vectors = ds_ds['view_vectors_ds']
        self.ray_lengths = ds_ds['ray_lengths_ds']
        ds.close()