Package: pygrpm
PyGRPMThe PyGRPM Medical Physics Library contains many utility features used within
the Medical Physics Research Group at Université Laval.This library also contains a multitude of subprojects, which all contain
practical functionalities, such as creating DICOM SR, manipulating DICOM CT
or even performing calculations with the TG43 formalism.Note that the code is provided "as is" and should not be used in a clinical
environment. In no event shall the authors be liable for any claims,
damages or other liabilities.LicensePyGRPM is distributed as free software according to the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option), any later version (http://www.gnu.org/licenses/).CitationIf you publish using PyGRPM, we kindly ask that you credit us. PyGRPM can be found on Zenodo :http://dx.doi.org/10.5281/zenodo.8250064.Installationpip install pygrpmDICOMMaking SR (Structured Report)The creation of DICOM SR (Structured Report) has been simplified thanks
to thepygrpm.make_sr()andpygrpm.make_sr_from_text()functions.
Note that theSRBuilderclass could allow a more refined/controlled creation.To create an SR from an arbitrary string, use:frompygrpm.dicom.srimportmake_sr_from_textsr=make_sr_from_text('my text',['ref_series/ct-1.dcm','ref_series/ct-2.dcm'])sr# Is a pydicom.FileDatasetsr.ContentSequence[0].TextValue# Contains the textsr.ReferencedInstanceSequence# Contains reference valuesYou can also provide a list of strings, this will generate multiple TEXT values within the Content Sequence:frompygrpm.dicom.srimportmake_sr_from_textsr=make_sr_from_text(['my first text','my second text'],['ref_series/ct-1.dcm','ref_series/ct-2.dcm'])sr# Is a pydicom.FileDatasetsr.ContentSequence[0].TextValue# Contains the first textsr.ContentSequence[1].TextValue# Contains the second textsr.ReferencedInstanceSequence# Contains reference valuesTo use a custom content sequence (i.e: a specific structure):frompygrpm.dicom.srimportmake_sr# The content sequence can be basically anything if it respects the DICOM standard.# The user that want a specific structure is invited to read on SR in the DICOM standard.content_sequence={'ValueType':'CONTAINER','ConceptNameCodeSequence':{'CodeValue':'DOC','CodeMeaning':'Document','CodingSchemeDesignator':'DCM'},'ContinuityOfContent':'SEPARATE','Value':[{'RelationshipType':'HAS PROPERTIES','ValueType':'TEXT','ConceptNameCodeSequence':{'CodeValue':'113012','CodeMeaning':'Key Object Description','CodingSchemeDesignator':'DCM'},'Value':'Some text',},# You can specify more than one value in the list{'RelationshipType':'HAS PROPERTIES','ValueType':'TEXT','ConceptNameCodeSequence':{'CodeValue':'113012','CodeMeaning':'Key Object Description','CodingSchemeDesignator':'DCM'},'Value':'Some more text',},],},sr=make_sr(content_sequence,['ref_series/ct-1.dcm','ref_series/ct-2.dcm'])sr# Is a pydicom.FileDatasetsr.ContentSequence# Correspond to the given content sequencesr.ReferencedInstanceSequence# Contains reference valuesUsers who wish to have more information on the creation
of SR are invited to read documentation concerningSR builder,SR dose content sequencesandDICOM part 03 section 17.TG43Python package to calculate the TG43 formalism based on xarray and the data fromESTRO.Available seedsSelectSeedMicroSelectronV2MBDCAFlexisourceUsagefrompygrpm.tg43importSeedimportmatplotlib.pyplotaspltseed=Seed("MBDCA")print(seed.gL)print(seed.F)# Display dosimetric gridgrid=seed.grid()# Plot arbitrary 100th sliceplt.imshow(grid.data[:,:,100])plt.show()# Plot mean dose vs radius with stdmean=seed.get_mean(grid)std=seed.get_std(grid)plt.errorbar(mean["r"].data,mean.data,std.data,fmt='o')plt.show()Index trackerSubmodule that allows scrolling through slices of 3-D images using the matplotlib backend.importmatplotlib.pyplotaspltimportnumpyfrompygrpm.visualization.index_trackerimportIndexTrackertracker=IndexTracker(*plt.subplot(),numpy.random.rand(512,512,10),...)tracker.ax.set_title('My 3-D random image')tracker.show()Seethisfor more informationNISTParserA simple class to extract information from certain NIST webpages.
At the time of writing this covers atomic and electronic cross-sections,
material attenuation, as well as material composition.get_cross_sectionsThis method retrieves the desired cross-sections of an element at given energies
on the NIST website in (barns/electron), barn=10^-24cm^2.Simple use example:importnumpyasnpfrompygrpm.material.nistparserimportget_cross_sections# Define the energies in KeV# Numpy array is not mandatory, can be any sequenceenergies=np.linspace(30,200,200)# Prints the returned listprint(get_cross_sections("H",energies))get_electronic_cross_sectionSee get_cross_section(), method use is identical minus the options argumentget_attenuationsMethod to retrieve the attenuation of a material in cm^2/g at given energies on the NIST website.Note theoptionparameter which can specify the attenuation physics typesNote theoutoptparameter which can alter the returned informationExample is similar to get_cross_sections()get_compositionThis method is used to get and parse material composition fromhttps://physics.nist.gov/cgi-bin/Star/compos.plSimple use example:frompygrpm.material.nistparserimportget_compositionfrompygrpm.material.nistparserimportNISTMaterials# Prints the returned dictionaryprint(get_composition(NISTMaterials.M3_WAX))Note that get_composition expects the material to be of instance NISTMaterialsAcknowledgementsThis submodule makes use of theHTMLTablePasrerbuilt by Josua Schmid, further information can be found in thepygrpm.nistparser.nistparser.pyfile header.This submodule is also dependent on the data provided byhttps://www.nist.gov/pmlHounsfield conversionA helper class meant to offer a quick and simple means to convert an HU array to density values
based on a provided conversion table. Note that the conversion factors for HU to
density are generally provided by the CT manufacturer.
This class is currently only able to be read under csv format type.UsageAssuming the following sample data as./curve.csvfileHU,Mass density [g/cm^3]
-1000,0.00121
-804,0.217
-505,0.508
-72,0.967
-32,0.99
7,1.018
44,1.061
52,1.071
254,1.159
4000,3.21A call through the class can be made to rescale an arbitrary array of Hounsfield unit to density values.importnumpyasnpfrompygrpm.ct_utilsimportConvertHUToDensityfithu=ConvertHUToDensity()my_curve=fithu.load_curve_csv("./curve.csv")# Note that setting plot to True generates a matplotlib plot of the curve fittingdata,fit_params,labels=fithu.fit_curve(my_curve,plot=True)# Fit returns unused in this examplemy_real_image=np.array([-980,-1000.,-823.,1,20,700,2900])densities=fithu.apply_fit(my_real_image,my_curve)print(densities)# [0.02702014 0.00652871 0.18787786 1.0291972 1.03955733 1.41034076, 2.60993423]TG263Basic TG263 implementation. Use this module to filter structure names based on the TG263.More informationhere