ADS and Python Integration Using Datalink
ADS and Python Integration Using Datalink
System 2020
PDF Generated on
Apr 07, 2019
Notices
© Keysight Technologies Incorporated, 2002-2019
1400 Fountaingrove Pkwy., Santa Rosa, CA 95403-1738, United States All rights reserved.
No part of this documentation may be reproduced in any form or by any means (including electronic storage
and retrieval or translation into a foreign language) without prior agreement and written consent from
Keysight Technologies, Inc. as governed by United States and international copyright laws.
Use, duplication or disclosure of Software is subject to Keysight Technologies' standard commercial license
terms, and non-DOD Departments and Agencies of the U.S. Government will receive no greater than
Restricted Rights as defined in FAR 52.227-19(c)(1-2) (June 1987). U.S. Government users will receive no
greater than Limited Rights as defined in FAR 52.227-14 (June 1987) or DFAR 252.227-7015 (b)(2)
(November 1995), as applicable in any technical data.
Portions of this software are licensed by third parties including open source terms and conditions.
Contents
ADS and Python Integration Using Datalink ................................................................................... 5
Contents.........................................................................................................................................6
Installing Datalink Add-on............................................................................................................... 7
Installing Datalink Add-on.............................................................................................................7
Install Datalink Add-on ............................................................................................................... 7
Configure User-Defined Script Location .................................................................................... 7
Uninstall Datalink Add-on .......................................................................................................... 7
Using Datalink.................................................................................................................................. 9
Using Datalink................................................................................................................................9
Adding Datalink Function in ADS ............................................................................................... 9
Sending Data From ADS to Python ............................................................................................ 9
Accessing ADS Data in Python ................................................................................................... 9
Accessing Python Data in ADS ................................................................................................. 10
Single Step ADS-Python Data Transfer.................................................................................... 10
Datalink Function Reference ......................................................................................................... 11
Datalink Function Reference .......................................................................................................11
Setup and Utility Functions ...................................................................................................... 11
Datalink Functions .................................................................................................................... 11
VISA Functions.......................................................................................................................... 11
LoadPull Functions ................................................................................................................... 12
Application Wrapper Functions ................................................................................................ 12
Datalink Functions .......................................................................................................................13
Datalink Functions .................................................................................................................... 13
dl_python() ................................................................................................................................ 14
dl_to_python() ........................................................................................................................... 18
dl_from_python()....................................................................................................................... 20
dl_python_bg() .......................................................................................................................... 22
dl_clean_dir() ............................................................................................................................ 27
VISA Functions.............................................................................................................................28
VISA Functions.......................................................................................................................... 28
dl_visa_list() .............................................................................................................................. 29
3
ADS and Python Integration Using Datalink
dl_visa_select().......................................................................................................................... 30
dl_visa_ping() ............................................................................................................................ 31
dl_visa_query() .......................................................................................................................... 32
dl_visa_query_data() ................................................................................................................. 33
dl_visa_write() ........................................................................................................................... 35
dl_string_to_data() .................................................................................................................... 36
LoadPull Functions ......................................................................................................................37
LoadPull Functions ................................................................................................................... 37
dl_create_contours() ................................................................................................................. 38
dl_assign_new_contour_levels()............................................................................................... 39
dl_deembed_s2p_from_z()........................................................................................................ 40
Application Wrapper Functions ...................................................................................................41
Application Wrapper Functions ................................................................................................ 41
dl_contour_py() ......................................................................................................................... 42
Datalink Examples ......................................................................................................................... 44
Datalink Examples .......................................................................................................................44
Example - Basic Datalink Operation............................................................................................45
Example - Basic Datalink Operation......................................................................................... 45
Example - 3D Surface Plot of an S-Parameter............................................................................47
Example - 3D Surface Plot of an S-Parameter......................................................................... 47
4
ADS and Python Integration Using Datalink
In addition, ADS functions are provided which utilize the Python interface to:
Communicate with instruments through VISA
Generate advanced plots
Generate advanced contours
Import arbitrary delimited data into ADS
To install files that are required for the Datalink functionality you need to download a separate Datalink
installer datalink_20xx.exe (for Windows only). For Linux, the Datalink installer is bundled with ADS
installer.
It is recommended to download both the general ADS installer, ads20xx_shp.exe, and the
datalink installer, datalink_20xx.exe, into the same directory. After the download, run the ADS
installer. This process will automatically install the Datalink functionality.
On Windows platform, if you have already installed ADS and find Datalink functionality missing,
then you need to download and install Datalink. For instructions, see Installing Datalink Add-on.
5
ADS and Python Integration Using Datalink
Contents
Installing Datalink Add-on
Using Datalink
Datalink Function Reference
Datalink Examples
Related Topics:
Workflow: How to Use Datalink with ADS
6
ADS and Python Integration Using Datalink
To install files that are required for the Datalink functionality you need to download a separate Datalink
installer datalink_20xx.exe (for Windows only). For Linux, the Datalink installer is bundled with ADS
installer.
It is recommended to download both the general ADS installer, ads20xx_shp.exe, and the
datalink installer, datalink_20xx.exe, into the same directory. After the download, run the ADS
installer. This process will automatically install the Datalink functionality.
On Windows platform, if you have already installed ADS and find Datalink functionality missing,
then you need to download and install Datalink. For instructions, see Installing Datalink Add-on.
1. Download the installation file, datalink_20xx.exe, from the Keysight EEsof EDA website to any
folder, for example C:\Temp.
2. Install the Add-on.
a. Double-click the installation file.
b. Follow the wizard.
Datalink is installed and configured.
Even if the script is called from a different location, the data generated is stored in the current
workspace.
7
ADS and Python Integration Using Datalink
Click Start > Control Panel > Program and Features, select DATALINK for Advanced Design System
20xx and click Uninstall/Change. This will uninstall only the Datalink Add-on.
8
ADS and Python Integration Using Datalink
Using Datalink
Using Datalink
Adding Datalink Function in ADS
Sending Data From ADS to Python
Accessing ADS Data in Python
Accessing Python Data in ADS
Single Step ADS-Python Data Transfer
9
ADS and Python Integration Using Datalink
3. Click Run.
The output file is created with the name specified in the script.
Spyder application menu bar becomes inactive when the window is maximized using View > Full
Screen or by pressing F11 (shortcut key to maximize the screen). As a workaround Press F11 again to
make it as the default screen. The menu bar is now active and works fine.
See Also
10
ADS and Python Integration Using Datalink
dl_datalink() Get the list of datalink functions. None String which lists datalink
functions
dl_get_py_executable() Return the Python path configured for None Path to Python exe
datalink.
Datalink Functions
Name Description
dl_python() Invoke a Python script from ADS. Using this function you can export data, find Python script,
run the script, and import the data.
dl_python_bg() Invoke a Python script from ADS in the background mode. Use this function to export data
from ADS, find the Python script, and run the script.
VISA Functions
Name Description
11
ADS and Python Integration Using Datalink
Name Description
LoadPull Functions
Name Description
12
ADS and Python Integration Using Datalink
Datalink Functions
Datalink Functions
dl_python() — Invoke a Python script from ADS. Use this function to export data
from ADS, find and run a Python script, and import the data back in ADS. Additional
dl_to_python() — Export ADS data and create a Python pointer. Resources
dl_from_python() — Import a CSV data file from Python to ADS.
dl_python_bg() — Invoke a Python script from ADS in the background mode.
Use this function to export data from ADS, find the Python script, and run the What's
script. New
dl_clean_dir() — Removes all the temporary .csv files created by datalink.
Articles
Knowledge
Center
Technical
Support
Contact
Training
Videos
13
ADS and Python Integration Using Datalink
dl_python()
dl_python()
Invoke a Python script from ADS. Use this function to export data from ADS, find and run a Python
script, and import the data back in ADS.
Syntax
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
script_name Name of the python script to run. Script name or full file None String Yes
path. If the input is a filename and it does not exist in
the current directory, the following directories are
searched:
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPTS_DIR
if /data/python doesn't exist, the function creates it.
14
ADS and Python Integration Using Datalink
<options> The following options can be put in a single string and None String No
must be the first input to the python() function directly
after the Python script name
"rowformat”: always write 1D variables as a single
row regardless of size.
“columnformat”: always write 1D variables as a
single column regardless of size.
The rowformat or columnformat
option does not apply if data is
passed using “list(<tablename>)”.
“keepfiles”: do not delete any data files
fromdirectoryincluding ADS2Pyth_datecode.csv,
Pyth2ADS_datecode.csv, ADS2Pyth_oneway.d,
ADS2Pyth_oneway.s.
"ignoreconsole": the python script typically prints
only a file path to the console (this is thecsvfile for
the return data). If the script prints other things,
ADS assumes that its likely an error so it returns the
full console output instead of the python data. This
option overrides that, it searches the python output
for a valid file path (Pyth2ADS_Datecode.csv) and
returns the data from that file regardless of
whatever else is printed to the console.
“scriptdir”: don’t execute, instead return the
directory location of the python script.
"datadir": don’t execute, instead return the
directory location of the data.
“pydir”: don’t execute, instead return the directory
location of the python executable.
“__dir”: don’t execute, instead return script dir, data
dir, and python dir.
15
ADS and Python Integration Using Datalink
Output
If the Python script returned only the path of a data file: Pyth2ADS_Datecode.csv, the function reads
the data in the file and return it as a multi-dimensional variable indexed as [Row,Col].
For numerical data, complex data is always returned. To convert it to real or integer numbers, use the
AEL functions real() or integer() functions on the result.
<inf> and <NaN>numpyvalues ARE supported in ADS2017 but not ADS2016
Irregular return data is supported (rows with different # of columns)
If the data is not numerical, strings are instead returned as [Row,Col]
If the Python script returned anything besides a single file path, the Python console output is returned
to ADS as a string. (This can be overridden with the “ignoreconsole” flag).
16
ADS and Python Integration Using Datalink
If the python script ran but returned nothing, it returns a message string: “no data returned”
If “dir” options were passed in, return directory location string(s)
In case of an error:
if python script is not found, returns a list of all directories searched.
if “list()” option invoked without a valid list, returns an error.
Example
rtn=dl_python("multiply_by_three.py",V,current.i)
multiply_by_three.py
17
ADS and Python Integration Using Datalink
dl_to_python()
dl_to_python()
Export ADS data and create a Python pointer.
Syntax
dl_to_python(<location>,<options>,<data>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
18
ADS and Python Integration Using Datalink
Output
In case of an error:
if python script not found, data is put in the default directory and an error message is displayed
If invalid directory is provided for location, data is put in default directory (invalid path treated as string
to export to python)
if “list()” option invoked without a valid list, returns an error message
Example
OutFile=dl_to_python(V,current.i)
19
ADS and Python Integration Using Datalink
dl_from_python()
dl_from_python()
Import a CSV data file from Python to ADS.
Syntax
dl_from_python(Dir_or_PyScript_or_Fname, <options>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
Dir_or_PyScrip Represents how to get the data. This should be either a directory, a Non Stri No
t_or_Fname python script name, or a filename / filepath. e ng
full file path and file name: returns data from the file
file path only: returns data from most recent
Pyth2ADS_datecode.csv in the specified directory
filename.csv: checks the following locations for file and return
data from the file
current dir
_wrk/data/python
_wrk/data; _wrk
$DATALINK_PYTHON_SCRIPT_DIR
python script: checks the following locations for the script
and returns data from most recent Pyth2ADS_datecode.csv in
that location
curr_dir
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPT_DIR
<options> The following inputs are valid for this variable (must come after Non Stri No
filename_or_loc) e ng
showloc: returns path location of python script or csv file
If the string is a directory path, the function will search that location for files that were exported by
Python.These files are named Pyth2ADS_YMDHMS.csv. The function will find the last data export and
return that data to ADS.
If the string is a Python script, the function will search the directory where the script is located. If the
Python script is not specified with a full path, the function will search for the script in the following
order: workspace\data\python, workspace\data, workspace(_wrk), then
20
ADS and Python Integration Using Datalink
Output
ADS MDIM array [Row,Col] data exported from python function ads.send(): complex number Python
arrays or strings
In case of an error:
if directory or file is not valid or does not exist, returns an error message
if python script or csv file not found, returns an error message showing all dirs searched
if no Pyth2ADS_datecode files found, returns an error message showing location checked
if return data is not numeric or read as data, returns data as strings
Example
MyData=dl_from_python("MyData.csv")
21
ADS and Python Integration Using Datalink
dl_python_bg()
dl_python_bg()
Invoke a Python script from ADS in the background mode. Use this function to export data from
ADS, find the Python script, and run the script.
This function does not return the data to ADS. To return data back to ADS use dl_python().
Syntax
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
script_name Name of the python script to run. Script name or full file None String Yes
path. If the input is a filename and it does not exist in
the current directory, the following directories are
searched:
_wrk/data/python
_wrk/data
_wrk
$DATALINK_PYTHON_SCRIPT_DIR
if /data/python doesn't exist, the function creates it.
22
ADS and Python Integration Using Datalink
<options> The following options can be put in a single string and None String No
must be the first input to the python() function directly
after the Python script name
"rowformat”: always write 1D variables as a single
row regardless of size
“columnformat”: always write 1D variables as a
single column regardless of size
The rowformat or columnformat
option does not apply if data is
passed using "list(<tablename>)".
“scriptdir”: don’t execute, instead return the
directory location of the python script
"datadir": don’t execute, instead return the
directory location of the data
“pydir”: don’t execute, instead return the directory
location of the python executable
“__dir”: don’t execute, instead return script dir, data
dir, and python dir
23
ADS and Python Integration Using Datalink
Output
No data is returned.
Example
rtn=dl_python_bg("surface.py",dB(S11))
24
ADS and Python Integration Using Datalink
surface.py
import ads
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
d,s=ads.get()
d = np.real(np.delete(d, (d.shape[0]-1), axis=0)) #Delete the last row
#Interpolate Z-data onto the uniform XY grid using a cubic interpolation function
zgrid= griddata((d[::,0],d[::,1]),d[::,2], (xgrid,
ygrid),method='cubic',fill_value=0,rescale=True)
3D Image
25
ADS and Python Integration Using Datalink
26
ADS and Python Integration Using Datalink
dl_clean_dir()
dl_clean_dir()
Removes all the temporary .csv files created by datalink.
Syntax
dl_clean_dir(<directoryName>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
<directoryNam The directory from which to remove the temporary .csv files created by _wrk Stri No
e> datalink. \dat ng
a\py
If an invalid directory is specified, an error message is returned. thon
If no directory is specified, the default directory name is:
_wrk\data\python.
Example
rtn=dl_clean_dir("C:\Users\aakotkar\Desktop\DataLink")
27
ADS and Python Integration Using Datalink
VISA Functions
VISA Functions
dl_visa_list() — Get a list of instruments on VISA line.
dl_visa_select() — Select a VISA instrument.
dl_visa_ping() — Check if the instrument is responding.
dl_visa_query() — Query a VISA instrument.
dl_visa_query_data() — Query ASCII or Binary Data.
dl_visa_write() — Write a series of VISA commands to the specified instrument.
dl_string_to_data() — Convert a delimited string to data.
28
ADS and Python Integration Using Datalink
dl_visa_list()
dl_visa_list()
Get a list of instruments on VISA line.
Syntax
dl_visa_list()
Output
29
ADS and Python Integration Using Datalink
dl_visa_select()
dl_visa_select()
Select a VISA instrument.
Syntax
dl_visa_select(index)
Arguments
Output
30
ADS and Python Integration Using Datalink
dl_visa_ping()
dl_visa_ping()
Check if the instrument is responding.
Syntax
dl_visa_ping(index)
Arguments
Output
1: the instrument is responding.
0: the instrument is not responding.
31
ADS and Python Integration Using Datalink
dl_visa_query()
dl_visa_query()
Query a VISA instrument.
Syntax
dl_visa_query(instrument_id, <query>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
Output
In case of an error: An error message string is returned if the instrument is not responding.
32
ADS and Python Integration Using Datalink
dl_visa_query_data()
dl_visa_query_data()
Query ASCII or Binary Data.
Syntax
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
instrume The instrument address (string) or instrument index (integer). No Stri Yes
nt_id ne ng/
Int
scpi_cmd SCPI command which queries the data return. No Stri Yes
Upon invocation, the function checks for instrument responsiveness sends the ne ng
query command, and the data from the instrument is written in a temporary
delimited text file (for capacity). This file is then read for the output and deleted.
Output
In case of an error:
33
ADS and Python Integration Using Datalink
34
ADS and Python Integration Using Datalink
dl_visa_write()
dl_visa_write()
Write a series of VISA commands to the specified instrument.
Syntax
dl_visa_write(instrument_id,<write_string>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
instrume The instrument address (string) or instrument index (integer). No Stri Yes
nt_id ne ng/
Int
<write_st A string of SCPI command(s), delimited by ‘;’ to write to the instrument. No Stri No
ring> ne ng
Upon invocation, the function checks if the instrument is responsive and sends
each write command. If the final command is not a query (ending in “?”), then
the *OPC? (operation complete) query is appended to the string so the
instrument returns 1 when complete.
Output
A single string containing return data from the instrument, usually 1 from the *OPC? Cmd
In case of an error:
An error message is returned if the instrument is not responding.
No data is returned if the query command is invalid.
35
ADS and Python Integration Using Datalink
dl_string_to_data()
dl_string_to_data()
Convert a delimited string to data.
Syntax
dl_string_to_data(string,<delimiter>,<leftsnip>,<rightsnip>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
string A single string containing some type of delimited, real or floating. No Stri Yes
ne ng
<leftsnip The number of characters to remove from the beginning before conversion. No Int No
> ne
<rightsni The number of characters to remove from the end before conversion. No Int No
p> ne
Output
36
ADS and Python Integration Using Datalink
LoadPull Functions
LoadPull Functions
dl_create_contours() — Create ADS contours from Python data.
dl_assign_new_contour_levels() — Assigns new arbitrary contour levels to an existing set of contours.
dl_deembed_s2p_from_z() — Removes (de-embeds) a 2x2 S-matrix from an arbitrary set of impedances.
37
ADS and Python Integration Using Datalink
dl_create_contours()
dl_create_contours()
Create ADS contours from Python data.
Syntax
dl_create_contours(python_contour_data, <dtype?>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
python_contour_da Return data from Python in the format: None Srting Yes
ta Level, Segment \n Real contour Zvalues \n
Imag contour Zvalues \n Level, Segment
\n…
Real and imaginary values are comma
delimited and returned using
Send_Contours_to_ADS()
Level, Segment \n X Values \n Y Values \n
Level, Segment \n…
Output
Example
dl_create_contours(python_contour_data, 0)
38
ADS and Python Integration Using Datalink
dl_assign_new_contour_levels()
dl_assign_new_contour_levels()
Assigns new arbitrary contour levels to an existing set of contours.
Syntax
dl_assign_new_contour_levels(contour_array,new_levels)
Arguments
new_le 1D real array with new levels corresponding to the contour array. The number of No St Yes
vels elements must be the same as the number of unique levels in contour_array. ne ri
n
g
Output
39
ADS and Python Integration Using Datalink
dl_deembed_s2p_from_z()
dl_deembed_s2p_from_z()
Removes (de-embeds) a 2x2 S-matrix from an arbitrary set of impedances.
Syntax
dl_deembed_s2p_from_z(Sremove,Sembed,fr_q,Z_0_0)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
Sremove 2 port S-matrix to remove. Can be swept frequency. Must None String Yes
be 2x2.
fre_q the frequency to de-embed. For cases where Sremove is None String Yes
swept frequency, fr_q must be a frequency point in the S-
matrix.
Output
40
ADS and Python Integration Using Datalink
41
ADS and Python Integration Using Datalink
dl_contour_py()
dl_contour_py()
Use Python to create contours.
Syntax
dl_contour_py(swept_data,<gamma>,<rect_or_polar>,<step_size>,<num_lines>,<desired
_levels>,<interp_type>,<min_or_max>,<data_format>)
Arguments
Inputs in <brackets> are optional, the default value is used if an input is not provided. All strings
must be enclosed in quotes.
Name Description D Ty Re
ef pe qui
au red
lt
swept_ 1D or Swept variable. For swept variables,at least 2 independent sweeps should be N Yes
data done: what(data)=[Y,X]. The dependant (data) will be contoured vs. the independents o
(Y and X). n
For complex variable sweeps of impedance or gamma, order is [Imag Part, e
Real Part], or [Phase, Mag].
For complex variable sweeps, it is also possible to pass in separate complex
values using <gamma>.
In that case, only the dependant part of (data) will be used, and all
independent values is ignored.
<gamm 1D or Swept variable, in a complex format, corresponding to the XY values for the N Co No
a> (data) input. o m
If a swept variable is passed, only inner dependent values will be used, n ple
independent values ignored. e x
If <rect_or_polar> is set to POLAR, the Phase will be used as Y and Mag will be
X (useful for loadpull).
If <rect_or_polar> is set to RECT, the Imaginary Part will be used as Y and Real
Part will be X.
42
ADS and Python Integration Using Datalink
Name Description D Ty Re
ef pe qui
au red
lt
<desire Single value or array representing specific desired contour levels. N Int No
d_level o
s> n
e
<min_o 0 (Min) or 1 (Max), that specifies whether the contours are to be drawn from the N Int No
r_max> maximum value down or from the minimum value up. o
n
e
<data_f Either RI or MA specifying data format for the polar contour plot, in polar mode only. N Str No
ormat> When <gamma> is passed in outside of the data sweep, data_format is not used. o ing
n
e
Example
Rn=dl_contour_py(Results1,Load_Gammas,"POLAR",3,10,,2)
43
ADS and Python Integration Using Datalink
Datalink Examples
Datalink Examples
Example - Basic Datalink Operation
Example - 3D Surface Plot of an S-Parameter
44
ADS and Python Integration Using Datalink
multiply_by_two.py
Stepped Process
1. Open Data Display.
45
ADS and Python Integration Using Datalink
Results:
rtn=dl_python("multiply_by_two.py",V,current.i)
46
ADS and Python Integration Using Datalink
The Python script (surface.py) with following contents is present in the <Wrk_Dir>\data\python
directory.
47
ADS and Python Integration Using Datalink
multiply_by_two.py
import ads
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
d,s=ads.get()
d = np.real(np.delete(d, (d.shape[0]-1), axis=0)) #Delete the last row
48
ADS and Python Integration Using Datalink
The Data Display will not be accessible while any of the 3D plot windows are open. You can access DDS
after closing the plot window. To make Data Display accessible while a 3D plot window is open, use the
dl_python_bg() function.
49
This information is subject to
change without notice.
www.keysight.com