def gen_channel_range(diag_name: str, chrg: list) -> channel_range: """Generates channel ranges for the diagnostics. Generates a channel_range object for the diagnostic at hand. Args: diag_name: str Name of the diagnostic chrg (tuple[int, int, int, int]): ch1_start, ch1_end, ch2_start, ch2_end. Returns: channel_range (channel_range): channel_range configured with appropriate bounds and order for either KSTAR ecei or NSTX GPI """ if diag_name == "kstarecei": ch1 = channel_2d(chrg[0], chrg[1], 24, 8, order='horizontal') ch2 = channel_2d(chrg[2], chrg[3], 24, 8, order='horizontal') return channel_range(ch1, ch2) elif diag_name == "nstxgpi": return None else: raise ValueError
def channel_range_from_str(range_str): """Generates a channel_range from a range. In `fluctana <https://github.com/minjunJchoi/fluctana>`_ , channels are referred to f.ex. .. code-block:: 'L0101' or 'GT1507' The letters refer to a device (D), the first two digits to the vertical channel number (V) and the last two digits refer to the horizontal channel number (H). Delta uses the same DDVVHH format. Args: range_str (str): KSTAR ECEI channel range, format DDVVHH Returns: channel_range (:py:class:`data_models.channels_2d.channel_range`): Channel range corresponding to range_str """ import re m = re.search('[A-Z]{1,2}', range_str) # try: # dev = m.group(0) # except: # raise AttributeError("Could not parse channel string " + range_str) m = re.findall('[0-9]{4}', range_str) ch_i = int(m[0]) ch_hi = ch_i % 100 ch_vi = int(ch_i // 100) ch_i = channel_2d(ch_vi, ch_hi, 24, 8, 'horizontal') ch_f = int(m[1]) ch_hf = ch_f % 100 ch_vf = int(ch_f // 100) ch_f = channel_2d(ch_vf, ch_hf, 24, 8, 'horizontal') return channel_range(ch_i, ch_f)
def get_geometry(cfg_diagnostic): """Builds channel geometry arrays. To re-construct the view, the following keys are extracted from the passed dictionary: * TFcurrent - Toroidal Field Coil current * LoFreq - ??? * LensFocus - ??? * LensZoom - ??? * Mode - Either 'O' or 'X', ordinary/extra-ordinary * dev - In ['L', 'H', 'G', 'GT', 'GR', 'HT'] Args: cfg_diagnostic (dict): Parameters section of diagnostic configuration. Returns: rarr (ndarray): Array containing radial coordinate of channels in m. zarr (ndarray): Array containing vertical coordinate of channels in m. """ me = 9.1e-31 # electron mass, in kg e = 1.602e-19 # charge, in C mu0 = 4. * np.pi * 1e-7 # permeability ttn = 56 * 16 # total TF coil turns # Unpack ecei_cfg # Instead of TFcurrent multiplying by 1e3, put this in the config file TFcurrent = cfg_diagnostic["TFcurrent"] LoFreq = cfg_diagnostic["LoFreq"] LensFocus = cfg_diagnostic["LensFocus"] LensZoom = cfg_diagnostic["LensZoom"] # Set hn, depending on mode. If mode is undefined, set X-mode as default. hn = 2 try: if cfg_diagnostic["Mode"] == 'O': hn = 1 elif cfg_diagnostic["Mode"] == 'X': hn = 2 except KeyError as k: print("ecei_cfg: key {0:s} not found. Defaulting to 2nd X-mode".format( k.__str__())) cfg_diagnostic["Mode"] = 'X' hn = 2 # To vectorize calculation of the channel positions we flatten out # horizontal and vertical channel indices in horizontal order. arr_ch_hv = np.zeros([24 * 8, 2], dtype=int) for idx_v in range(1, 25): for idx_h in range(1, 9): ch = channel_2d(idx_v, idx_h, 24, 8, "horizontal") arr_ch_hv[ch.get_idx(), 0] = ch.ch_h arr_ch_hv[ch.get_idx(), 1] = ch.ch_v rpos_arr = hn * e * mu0 * ttn * TFcurrent /\ (4. * np.pi * np.pi * me * ((arr_ch_hv[:, 0] - 1) * 0.9 + 2.6 + LoFreq) * 1e9) # With radial positions at hand, continue the calculations from beam_path # This is an (192, 2, 2) array, where the first dimension indices each individual channel abcd_array = np.array([ get_abcd(LensFocus, LensZoom, rpos, cfg_diagnostic["dev"]) for rpos in rpos_arr ]) # vertical position from the reference axis (vertical center of all lens, z=0 line) zz = (np.arange(24, 0, -1) - 12.5) * 14 # [mm] # angle against the reference axis at ECEI array box aa = np.zeros_like(zz) # vertical posistion and angle at rpos za_array = np.dot(abcd_array, [zz, aa]) zpos_arr = np.array([ za_array[i, 0, v - 1] for i, v in zip(np.arange(192), arr_ch_hv[:, 1]) ]) * 1e-3 apos_arr = np.array([ za_array[i, 1, v - 1] for i, v in zip(np.arange(192), arr_ch_hv[:, 1]) ]) return (rpos_arr, zpos_arr, apos_arr)