varianapis / pyesapi Goto Github PK
View Code? Open in Web Editor NEWPython interface to Eclipse Scripting API
License: MIT License
Python interface to Eclipse Scripting API
License: MIT License
How can I get the couch rotation?
Hi,
I'd like to set target structure with pyesapi.
For c# this works:
Structure targetStructure = originalPlan.StructureSet.Structures.Where(s => s.Id.Equals(originalPlan.TargetVolumeID)).Single();
StringBuilder ErrorHint = new StringBuilder("Error while setting Target Structure");
newPlan.SetTargetStructureIfNoDose(targetStructure, ErrorHint);
But I cannot make it work with pyesapi.
targetStructure = originalPlan.StructureSet.StructuresLot(originalPlan.TargetVolumeID)
ErrorHint = "Error while setting Target Structure"
newPlan.SetTargetStructureIfNoDose(targetStructure)
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: No method matches given arguments for SetTargetStructureIfNoDose: (<class 'VMS.TPS.Common.Model.API.Structure'>)
Simmilar effect for:
newPlan.SetTargetStructureIfNoDose(targetStructure, ErrorHint)
TypeError: No method matches given arguments for SetTargetStructureIfNoDose: (<class 'VMS.TPS.Common.Model.API.Structure'>, <class 'str'>)
How can I set target structure with pyesapi?
I am trying to execute the GettingStarted.ipynb notebook: https://github.com/VarianAPIs/PyESAPI/tree/master/examples/DeveloperWorkshop2018
However, I cannot pass the following error (everything before the following point is working correctly):
"AttributeError: object has no attribute 'np_array_like' after "plan.Dose.* ".
Suggestions???
This is in the triangle mesh script. Please check the error. It seems that maybe the intersects_location method requires an additional argument that is not being input. It seems to be asking for some third argument. src_pts is an array of 3 columns [0,1000,0]. isoplane is also an array of 3 columns where the middle column is 0.
Thanks Michael.
Hello,
Installation was without any errors. However, when I run "import pyesapi" the following exception pops up:
Exception Traceback (most recent call last)
Cell In[2], line 1
----> 1 import pyesapi
2 #import atexit
3 #app = pyesapi.CustomScriptExecutable.CreateApplication('python_demo')
4 #atexit.register(app.Dispose);
File ~\AppData\Roaming\Python\Python311\site-packages\pyesapi_init_.py:44
41 paths = [os.path.join(drive, os.sep, base, ver, rp) for rp in rpaths]
43 if len(paths) < 2:
---> 44 raise Exception("Did not find required library paths! Searched for:\n %s" % (",\n".join(searched_paths)))
45 if len(paths) > 2:
46 print("WARNING: Found multiple possible VMS dll locations:\n %s" % (",\n".join(paths)))
Exception: Did not find required library paths! Searched for:
C:\Program Files (x86)\Varian\RTM%version\esapi\API,
C:\Program Files (x86)\Varian\RTM%version\ExternalBeam,
D:\Program Files (x86)\Varian\RTM%version\esapi\API,
D:\Program Files (x86)\Varian\RTM%version\ExternalBeam
How one can solve this?
Best wishes,
Maksym
Hi
How to calculate mean dose?
Using the GetEditableParameters method on IonBeam plans only returns parameters which are associated with Photon beam plans rather than IonBeam plans
Applying the same method in C#, to the same plan, returns the correct parameters such as the raw spot list, etc (as expected).
Is there any way to run PyESAPI over an Aria citrix based implementation?
Thank you!
I've tried to run the installation command
pip3 install https://api.github.com/repos/VarianAPIs/PyESAPI/tarball
in a fresh virtual environment (Python 3.9.1 on Fedora 33), which gives me a bunch of errors. Is this package not compatible with Python3?
The error message:
ERROR: Command errored out with exit status 1:
command: [EDITED_PATH]/.env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3wr6z42w/pythonnet/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3wr6z42w/pythonnet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-c6ua9if7
cwd: /tmp/pip-install-3wr6z42w/pythonnet/
Complete output (91 lines):
running bdist_wheel
running build
running build_ext
Checking for updates from https://www.nuget.org/api/v2/.
Currently running NuGet.exe 4.1.0.
Updating NuGet.exe to 5.8.0.
Update successful.
MSBuild auto-detection: using msbuild version '14.0' from '/usr/lib/mono/xbuild/14.0/bin'.
>>>> xbuild tool is deprecated and will be removed in future updates, use msbuild instead <<<<
MSBUILD: error MSBUILD0004: Too many project files specified
WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.
Restoring NuGet package NUnit.3.12.0.
Restoring NuGet package NUnit.ConsoleRunner.3.11.1.
Restoring NuGet package System.ValueTuple.4.5.0.
Restoring NuGet package UnmanagedExports.1.2.7.
Adding package 'System.ValueTuple.4.5.0' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Adding package 'NUnit.ConsoleRunner.3.11.1' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Adding package 'NUnit.3.12.0' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Adding package 'UnmanagedExports.1.2.7' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Added package 'UnmanagedExports.1.2.7' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Added package 'NUnit.ConsoleRunner.3.11.1' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Added package 'System.ValueTuple.4.5.0' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
Added package 'NUnit.3.12.0' to folder '/tmp/pip-install-3wr6z42w/pythonnet/packages'
NuGet Config files used:
/home/renato/.config/NuGet/NuGet.Config
Feeds used:
/home/renato/.nuget/packages/
https://api.nuget.org/v3/index.json
Installed:
4 package(s) to packages.config projects
Traceback (most recent call last):
File "/tmp/pip-install-3wr6z42w/pythonnet/tools/geninterop/geninterop.py", line 307, in <module>
sys.exit(main())
File "/tmp/pip-install-3wr6z42w/pythonnet/tools/geninterop/geninterop.py", line 287, in main
python_h = preprocess_python_headers()
File "/tmp/pip-install-3wr6z42w/pythonnet/tools/geninterop/geninterop.py", line 207, in preprocess_python_headers
for line in _check_output(cmd).splitlines():
File "/tmp/pip-install-3wr6z42w/pythonnet/tools/geninterop/geninterop.py", line 41, in _check_output
output = subprocess.check_output(*args, **kwargs)
File "/usr/lib64/python3.9/subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib64/python3.9/subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib64/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib64/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'clang'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-3wr6z42w/pythonnet/setup.py", line 630, in <module>
setup(
File "[EDITED_PATH]/tmp/2021-01-04/.env/lib/python3.9/site-packages/setuptools/__init__.py", line 165, in setup
return distutils.core.setup(**attrs)
File "/usr/lib64/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib64/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/tmp/pip-install-3wr6z42w/pythonnet/setup.py", line 612, in run
return bdist_wheel.bdist_wheel.run(self)
File "[EDITED_PATH]/tmp/2021-01-04/.env/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 223, in run
self.run_command('build')
File "/usr/lib64/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib64/python3.9/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/usr/lib64/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib64/python3.9/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/usr/lib64/python3.9/distutils/command/build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "/usr/lib64/python3.9/distutils/command/build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "/tmp/pip-install-3wr6z42w/pythonnet/setup.py", line 302, in build_extension
subprocess.check_call([sys.executable, geninterop, interop_file])
File "/usr/lib64/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['[EDITED_PATH]/tmp/2021-01-04/.env/bin/python', 'tools/geninterop/geninterop.py', 'src/runtime/interop39.cs']' returned non-zero exit status 1.
----------------------------------------
ERROR: Failed building wheel for pythonnet
Hi, does it work for Eclipse version 16? Thank you!
Hello,
We are trying to call the CalculateDVHEstimates
via pyESAPI (ESAPI version = 15.6.) gets an "Cannot locate TPS core" error. The error message is listed as below:
Traceback (most recent call last):
File "C:/Users/xxx/Desktop/test_rapidplan.py", line 34, in <module>
plan.CalculateDVHEstimates(rp_model_name, targetdose_dict, Match_dict)
System.ApplicationException: Cannot locate TPS Core from 'D:\anaconda\'.
at VMS.TPS.Common.Model.TpsCorePathResolver.ResolveTpsCorePathViaApplicationSettings()
at VMS.TPS.Common.Model.ObjectFactory.CreateObject[TObject](String assemblyFileName, String classFullName, Func\1 tpsCoreBinPathResolver)
at VMS.TPS.Common.Calculation.DVHEstimationClient.AddStructureObjectivesToModule(DCRVAConstraintModule* module)
at VMS.TPS.Common.Calculation.DVHEstimationClient.InitDataInterface()
at VMS.TPS.Common.Calculation.CalculationClientBase.Initialize()
at VMS.TPS.Common.Model.API.ExternalPlanSetup.CalculateDVHEstimates(String modelId, Dictionary\2 targetDoseLevels, Dictionary2 structureMatches)
Because the python original dict
is not directly recognizable for the CalculateDVHEstimates
function,
we have tried to convert the python dict
with the pythonnet
Dictionary like
td = [('CTV', api.DoseValue(41.8, "Gy")), ('PTV', api.DoseValue(41.8, "Gy")))]
targetdose_dict = Dictionary[str, api.DoseValue]()
for k,v in td:
targetdose_dict[k] = v
match = [('CTV', 'CTV'), ('PTV', 'PTV'), ('FemoralHead', 'FemoralHead')]
Match_dict = Dictionary[str, str]()
for k, v in match:
Match_dict[k] = v
rp_model_name = "000 Rectum 41.8-50.6 V2019.1"
plan.SetCalculationModel(api.CalculationType.DVHEstimation, "DVH Estimation Algorithm [15.6.03]")
plan.SetCalculationModel(api.CalculationType.PhotonLeafMotions, "Varian Leaf Motion Calculator [15.1.51]")
plan.CalculateDVHEstimates(rp_model_name, targetdose_dict, Match_dict)
This seems to cause a confusion for the TPS Core resolution.
I have tried to use the Dictionary
and String
types in pyesapi.stubs
, but they do not seem to be functional.
Any idea how to circumvent this issue?
Is it possible to specify Plan Uncertainty Parameters using ESAPI / PyESAPI and calculate dose for these plans afterwards?
There is option to add EvaluationDose to plan (or to import dose in Eclipse TPS). In Eclipse it is possible to evaluate this dose, look into DVHs, compare with Clinical Goals etc. But if I try doing the same with scripting GetDoseAtVoxel, GetVoxelAtDose, GetDVHCumulativeData methods return nan. The Dose.DoseMax3D.Dose method still returns max dose.
PatientID = "MyPatientID"
# open patient
patient = app.OpenPatientById(PatientID)
patient.BeginModifications()
# select course
course = patient.CoursesLot('CourseName')
# select plan
plan = course.PlanSetupsLot('Test')
# select structure sets:
structureSet = patient.StructureSetsLot()[0]
# change dose presentation to absolute:
plan.DoseValuePresentation = 1
tempPlan = course.AddExternalPlanSetup(plan.StructureSet)
tempDose = tempPlan.CopyEvaluationDose(plan.Dose)
structure = structureSet.StructuresLot()[27]
# set step of exported lines:
step = 0.7
dvh = plan.GetDVHCumulativeData(structure, pyesapi.DoseValuePresentation.Absolute, pyesapi.VolumePresentation.Relative, step)
dvh2 = tempPlan.GetDVHCumulativeData(structure, pyesapi.DoseValuePresentation.Absolute, pyesapi.VolumePresentation.Relative, step)
dose = plan.GetDoseAtVolume(structure, 50, pyesapi.VolumePresentation.Relative, pyesapi.DoseValuePresentation.Absolute).Dose
dose2 = tempPlan.GetDoseAtVolume(structure, 50, pyesapi.VolumePresentation.Relative, pyesapi.DoseValuePresentation.Absolute).Dose
print('dvh', dvh)
print('dvh2', dvh2)
print('dose', dose)
print('dose2', dose2)
print('tempPlan max dose:', tempPlan.Dose.DoseMax3D.Dose)
The output is:
dvh VMS.TPS.Common.Model.API.DVHData
dvh2 None
dose 14.776034807492234
dose2 nan
tempPlan max dose: 103.92649999999999
How can I use Evaluation methods on EvaluationDose not on CalculatedDose?
Hi.
Iam trying to install PyESAPI on one of our TBOXes, but without any success.
I wrote:
https://raw.githubusercontent.com/VarianAPIs/PyESAPI/master/condaenv36.yml
in the Anaconda prompt, which gives me a list of all the dependencies.
But when I try to create the Environment with:
conda env create -f condaenv36.yml
I get the error: file condaenv36.yml not found.
I also tried to install PyESAPI using pip but here it seems like there is an issue with pythonnet.
Any help would be appreciated!
Kind regards,
Michael
Trying to create a new beam with PlanSetup.AddVMATBeam
triggers an Eclipse dialog box with the warning: "The following parameters were adjusted to be within machine limits: collimator positions". The only collimator "position" being passed here is the collimator angle, and the warning appears regardless of the double angle given (0, 0.0, 30.0, etc.), after which the given angle appears to be accepted. Note that the resultant beam does not have a tolerance table assigned (which may be related), but there is no where to pass ToleranceTableLabel
during the AddVMATBeam
call. Obviously, this interaction with a dialog box is not ideal when batch processing.
I am trying the first line of the getting started workshop script, but right away I am getting an error. The notebook says "Create one instance of the eclipse scripting application" by which I am assuming (could this be clarified?) they mean to open external beam planning and then open tools>scripts.
This is what I have done and I run
import pyesapi
import atexit
app = pyesapi.CustomScriptExecutable.CreateApplication('python_demo')
but then get the error
TpsNetInitializationException: [10/8/2021 10:46 AM] TPS.NET ApplicationNonAppFrame: Initialization FAILED. Here is the initialization log:
[10/8/2021 10:46 AM] TPS.NET ApplicationNonAppFrame: START initializtion, m_initCounter=1, status=NotInitialized.
[10/8/2021 10:46 AM] TPS.NET ApplicationNonAppFrame: Only one Application object is supported at a time.
at VMS.TPS.Common.Model.ApplicationInitGuard.ThrowInitError(Exception innerException)
at VMS.TPS.Common.Model.ApplicationInitGuard.Begin()
at VMS.TPS.Common.Model.ApplicationInitGuard.InitializeApplicationImpl(Delegate initDelegate, Object[] args)
at VMS.TPS.Common.Model.ApplicationNonAppFrame.Initialize(IStartupParameters startupParameters, IApplicationContextInfo applicationContextInfo)
at VMS.TPS.Common.Model.API.Application.CreateApplicationCommon(String scriptName, Func`2 createExecutionGuardFunc)
So I assume this means that the scripting application is an instance too many and needs to be closed, so I close out and run the same, but again I get the same error. When I run without ARIA or eclipse open in the background, I instead get the error
app = pyesapi.CustomScriptExecutable.CreateApplication('python_demo')
ArgumentNullException: Value cannot be null.
at System.Threading.Monitor.Enter(Object obj)
at VMS.TPS.Common.Model.ApplicationBase.remove_OnDataReload(Action value)
at VMS.TPS.Common.Model.StructureCodeTable.ResetInstance()
at VMS.TPS.Common.Model.ApplicationBase.UninitializeDataObjectCache()
at VMS.TPS.Common.Model.ApplicationNonAppFrame._Dispose()
at VMS.TPS.Common.Model.ApplicationNonAppFrame.Dispose(Boolean A_0)
at VMS.TPS.Common.Model.ApplicationBase.Dispose()
at VMS.TPS.Common.Model.API.Application.CreateApplicationCommon(String scriptName, Func`2 createExecutionGuardFunc)
I think the script must be having trouble finding the Varian dlls, however these are stored in C:\Program Files (x86)\Varian\RTM\15.6\esapi\API
which is in my PYTHONPATH variable.
Given a Treatment Approved sourcePlan
in course sourceCourse
, a new plan can be created with newPlan=sourceCourse.CopyPlanSetup(sourcePlan)
. However, upon app.SaveModifications()
an error is produced that mentions "tU_PlanSetup_VaBusinessLogic, Line 694: PlanSetup is approved: Cannot UPDATE PlanSetup. PlanSetupSer: 549944", where 549944 is the Ser of the sourcePlan (and no modifications are being asked of this plan). The workflow runs fine when copying an unapproved plan.
Hi,
I've encountered an error I can't get around when trying to go through the "Getting Started" Jupyter notebook. I've attached an image of the error. The .dll file "VMS.TPS.Common.Model.API" is in the ESAPI_PATH that I set, but for some reason the file isn't being found. Do you know why this is happening? Any help fixing this issue would be greatly appreciated.
Thank you!
Dylan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.