beam-tracing / Scotty

Beam tracing code for diagnostics
https://scotty.readthedocs.io/en/latest/
GNU General Public License v3.0
7 stars 4 forks source link

density fit breaks backwards compatibility #59

Closed limj0187 closed 1 year ago

limj0187 commented 2 years ago

Quadratic fit in circular flux surfaces throws an error:

File "C:\Users\limjy2\Anaconda3\envs\myenv\lib\site-packages\scotty\density_fit.py", line 396, in density_fit if method == "smoothing-spline-file" and filename != parameters[0]: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

`from scotty import beam_me_up from scotty.fun_general import find_q_lab_Cartesian, find_q_lab, find_K_lab_Cartesian, find_K_lab, find_waist, find_Rayleigh_length, genray_angles_from_mirror_angles from scotty.fun_general import propagate_beam

from scipy import constants import math import numpy as np import sys

from scotty.init_bruv import get_parameters_for_Scotty

args_dict = {'poloidal_launch_angle_Torbeam': 6.0, 'toroidal_launch_angle_Torbeam': 0.0, 'launch_freq_GHz': 55.0, 'mode_flag': 1, 'launch_beam_width': 0.04, 'launch_beam_curvature': -0.25, 'launch_position': np.array([ 2.587 , 0. , -0.0157])}

kwargs_dict = {'density_fit_parameters': (np.array([4., 1.]),'quadratic'), 'find_B_method': 'analytical', 'Psi_BC_flag': True, 'figure_flag': False, 'vacuum_propagation_flag': True, 'vacuumLaunch_flag': True, 'poloidal_flux_enter': 1.0, 'B_T_axis': 1.0, 'B_p_a': 0.1, 'R_axis': 1.5, 'minor_radius_a': 0.5}

beam_me_up(args_dict, kwargs_dict)`

An error is also thrown when 'density_fit_parameters': (np.array([4., 1.])),

ZedThree commented 2 years ago

Hi @limj0187, sorry about this! I'll make a fix that gives a better error message shortly, but in the meantime you want to pass the method name as a separate argument:

kwargs_dict = {
  'density_fit_parameters': np.array([4., 1.]),
  'density_fit_method': 'quadratic',
  'find_B_method': 'analytical',

Also, just to note that for quadratic, the second parameter must be the same as poloidal_flux_enter, so you can skip it:

kwargs_dict = {
  'density_fit_parameters': [4.],
  'density_fit_method': 'quadratic',
  'find_B_method': 'analytical',
valerian-chen commented 2 years ago

Minor issue. If I understand the density_fit.py correctly, it's meant to throw a deprecation warning if density_fit_parameters is specified but density_fit_method is not. However, I'm not getting this warning.