VarianAPIs / PyESAPI

Python interface to Eclipse Scripting API
MIT License
69 stars 32 forks source link

CalculateDVHEstimates in pyESAPI throws "Cannot locate TPS Core" Error #19

Closed inamoto85 closed 1 day ago

inamoto85 commented 2 years ago

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?

fizxmike commented 1 day ago

@inamoto85, was this ever resolved? I had PyESAPI code that successfully ran RapidPlan estimates, but I don't remember having your issue with TPS core.

fizxmike commented 1 day ago

See here: https://www.reddit.com/r/esapi/comments/gmk6nt/issue_with_calculatedvhestimates_and_rapidplan/

A workaround might be to create a small C# app to do the DVH prediction alone and call it from Python (making sure you close the patient first).