User Tools

Site Tools


dosimetry:userguide:thinknode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dosimetry:userguide:thinknode [2015/09/25 12:08] – [thinknode_worker] dpatenaudedosimetry:userguide:thinknode [2021/07/29 18:23] (current) – external edit 127.0.0.1
Line 6: Line 6:
 ====== Python ====== ====== Python ======
  
 +Please refer to the [[https://github.com/dotdecimal/astroid-script-library/blob/development/python/README.md| Python Script Library Readme]] for dependent python modules and a high level list of what these libraries include.
 ===== Python: Overview ===== ===== Python: Overview =====
  
Line 152: Line 153:
 # Get IAM ids # Get IAM ids
 iam = thinknode.authenticate(thinknode.read_config('thinknode.cfg')) iam = thinknode.authenticate(thinknode.read_config('thinknode.cfg'))
- 
-def make_grid(corner, size, spacing): 
-... 
- 
-def make_water_phantom(corner, size, spacing): 
-    return \ 
-        thinknode.function("dosimetry", "create_uniform_image_on_grid_3d", 
-            [ 
-                make_grid(corner, size, spacing), 
-                thinknode.value(1), 
-                thinknode.value("relative_stopping_power") 
-            ]) 
  
 def make_dose_points(pointCount): def make_dose_points(pointCount):
Line 213: Line 202:
     thinknode.function("dosimetry", "compute_sobp_pb_dose2",     thinknode.function("dosimetry", "compute_sobp_pb_dose2",
         [         [
-            make_water_phantom([-100, -100, -100], [200, 200, 200], [2, 2, 2]), #stopping_power_image+            dosimetry.make_image_3d(iam, [-100, -100, -100], [200, 200, 200], [2, 2, 2], 1), #stopping_power_image
             thinknode.value(make_dose_points(181)), # dose_points             thinknode.value(make_dose_points(181)), # dose_points
             beam_geometry, #beam_geometry             beam_geometry, #beam_geometry
-            make_grid([-75, -75], [150, 150], [2, 2]), # bixel_grid+            dosimetry.make_grid(iam, [-75, -75], [150, 150], [2, 2]), # bixel_grid
             make_layers(2270.0, 152.0, 38.0),             make_layers(2270.0, 152.0, 38.0),
             compute_aperture(), # aperture based on targets             compute_aperture(), # aperture based on targets
Line 230: Line 219:
 ==== rt_types ==== ==== rt_types ====
  
-The //rt_types// module is a reconstruction of astroid manifest types in python class format. This includes interdependencies between types (e.g. the class "polyset" requires the class "polygon2").+The //rt_types// module is a reconstruction of all astroid types in python class format. This includes interdependencies between types (e.g. the class "polyset" requires the class "polygon2").
  
 Each data type detailed in the [[http://docs.apps.dotdecimal.com|astroid Manifest Guide]] has a corresponding class in this python module.  Each data type detailed in the [[http://docs.apps.dotdecimal.com|astroid Manifest Guide]] has a corresponding class in this python module. 
  
-Below you will see as snippet from the rt_types module that shows the class for the //polyset// rt_type along with its default initializations and //.expand_data// and //from_json// functions.+Below you will see snippet from the rt_types module that shows the class for the //polyset// rt_type along with its default initialization, //expand_data// and //from_json// functions.
  
 <code python> <code python>
Line 283: Line 272:
 </code> </code>
  
-  * **Interdependence:** When rt_types are constructed of other or multiple named types, they will be constructed as such in each class as displayed by the //polygons// parameter of the //polyset// in this example. +  * **Interdependence:** When rt_types are constructed of other or multiple named types, they will be constructed as such in each class as seen in the //polygons// parameter of the //polyset// in the above example. 
-  * **//expand_data// function:** Each class's //.expand_data// function provides an ordered dictionary of each of the values in the class. This is explicitly an ordered dictionary since when calling a function in a calculation request, the order of the values provided matters if constructing the request by thinknode value type+  * **//expand_data// function:** Each class's //expand_data// function returns a python dictionary containing each of the values in the class, with all data values expanded out to remove compression or other encodings (i.e. providing results in a format more useful for send to other applications or for human-readability)
-  * **//from_json// function:** Each class's //.from_json// function provides a method to turn a raw json string (e.g. a result from a thinknode calculation or ISS object) into an rt_type data type.+  * **//from_json// function:** Each class's //from_json// function provides a method to turn a raw json string (e.g. a result from a thinknode calculation or ISS object) into an rt_type data type. Proper use is to first construct an empty class instance, then to call the //from_json// method on that instance, passing in the desired json data string
  
-Below is an example usage of getting a thinknode dose image (image_3d data type in the astroid manifest) and turning it into a rt_types image_3d data type, then using that data type to output the image as a VTK graphics file:+Below is an example usage of getting a thinknode dose image (image_3d data type in the astroid manifest) and turning it into a rt_types image_3d data type, so that it can be expanded and then used to output the image into a VTK graphics file:
  
 <code python> <code python>
Line 303: Line 292:
 The //thinknode_worker// module is the main work horse for communication with the astroid app and thinknode. The module will handle authentication, posting objects to ISS, creating most of the common calculation request structures, and posting the calculation request. The //thinknode_worker// module is the main work horse for communication with the astroid app and thinknode. The module will handle authentication, posting objects to ISS, creating most of the common calculation request structures, and posting the calculation request.
  
-Refer to the [[https://github.com/dotdecimal/astroid-script-library|.decimal GitHub repository]] for the complete module. Below are a few of the more common thinknode http worker and their intended usages:+Refer to the [[https://github.com/dotdecimal/astroid-script-library|.decimal GitHub repository]] for the complete module. Below are a few of the more common thinknode_worker functions and their intended usages:
  
 <code python> <code python>
Line 338: Line 327:
  
  
 +</code>
 +
 +==== dosimetry_worker ====
 +The dosimetry_worker module provides high-level functions for building data types and calculation requests for common dosimetry tasks. This library is constantly growing as more routine tasks are programmed in python. 
 +
 +Refer to the [[https://github.com/dotdecimal/astroid-script-library|.decimal GitHub repository]] for the complete module. Some basic examples of provided functionality are:
 +
 +  - Aperture creation (using structures/beams or basic geometric)
 +  - Dose comparison
 +  - Grid creation
 +  - Image creation
 +  - PBS Spot functions
 +
 +
 +==== vtk_worker ====
 +The VTK worker provides a means to write out common rt_types to a vtk file format ([[http://www.vtk.org/|The Visualization TooKit]]) that can be visualized in [[http://www.paraview.org/|Paraview]]. It's most useful for displaying and post-processing image, mesh, and other primitive object data types.
 +
 +Below is an example of turning a dose image_3d into a vtk file for visualization in Paraview:
 +
 +<code python>
 +def dose_to_vtk(dose_id):
 +    img_data = json.loads(thinknode.get_immutable(iam, 'dicom', dose_id))
 +
 +    img = rt_types.image_3d()
 +    img.from_json(img_data)
 +    img2 = img.expand_data()
 +
 +    vtk.write_vtk_image3('E:/dicom/dose.vtk', img2)
 </code> </code>
  
 ==== decimal_logging ==== ==== decimal_logging ====
  
-The //decimal_logging// module provides formatted and detailed output window and file logging. +The //decimal_logging// module provides formatted and detailed output window messages and file logging. 
  
 The following settings are available in the decimal_logging.py file: The following settings are available in the decimal_logging.py file:
Line 348: Line 365:
 **display_types: ** display message types (e.g. debug, data, alert) in the output window/logfile **display_types: ** display message types (e.g. debug, data, alert) in the output window/logfile
 **log_file: ** sets the logfile name and location **log_file: ** sets the logfile name and location
 +
 +=== Debugging ===
 +
 +When debugging, use the dl.debug() function and set the //isDebug// flag in the decimal_logging library to True. This toggles on the output for each of the dl.debug calls. By default we keep debugging off, but it can be turned on as needed.
 +
 +=== Other Flags ===
 +
  
 The following image shows the logging settings for each message type as: The following image shows the logging settings for each message type as:
Line 355: Line 379:
  
 {{ dosimetry:userguide:decimal_logging_example.png |}} {{ dosimetry:userguide:decimal_logging_example.png |}}
 +
 +=== File Logging ===
 +
 +The decimal_logging library also provides simple file logging. The //log_file// variable at the top of the library sets the log file. By using any of the following functions, you can easily log data to the specified file:
 +
 +  * log(message)
 +  * log_debug_data(message,data)
 +  * log_data(data)
 +
 ---- ----
 <WRAP center 10%>//USR-001//</WRAP> <WRAP center 10%>//USR-001//</WRAP>
  
 <WRAP center 40%>.decimal LLC, 121 Central Park Place, Sanford, FL. 32771</WRAP> <WRAP center 40%>.decimal LLC, 121 Central Park Place, Sanford, FL. 32771</WRAP>
dosimetry/userguide/thinknode.1443182909.txt.gz · Last modified: 2021/07/29 18:21 (external edit)