Commit 35f8c80992eb5fcf85ed71065a7e83a064c8bbc4

Authored by tatiana
1 parent dd4ee4d0

ENC: Changed parser None values for empty strings

Showing 1 changed file with 140 additions and 137 deletions   Show diff stats
invesalius/reader/dicom.py
... ... @@ -88,7 +88,7 @@ class Parser():
88 88 """
89 89  
90 90 def __init__(self):
91   - self.filename = None
  91 + self.filename = ""
92 92 self.vtkgdcm_reader = vtkgdcm.vtkGDCMImageReader()
93 93  
94 94 def GetAcquisitionDate(self):
... ... @@ -112,7 +112,7 @@ class Parser():
112 112 def GetAcquisitionNumber(self):
113 113 """
114 114 Return integer related to acquisition of this slice.
115   - Return None if field is not defined.
  115 + Return "" if field is not defined.
116 116  
117 117 DICOM standard tag (0x0020, 0x0012) was used.
118 118 """
... ... @@ -122,7 +122,7 @@ class Parser():
122 122 data = ds.GetDataElement(tag).GetValue()
123 123 if (data):
124 124 return int(str(data))
125   - return None
  125 + return ""
126 126  
127 127 def GetAccessionNumber(self):
128 128 """
... ... @@ -136,7 +136,7 @@ class Parser():
136 136 data = ds.GetDataElement(tag).GetValue()
137 137 if (data):
138 138 return int(str(data))
139   - return None
  139 + return ""
140 140  
141 141 def GetAcquisitionTime(self):
142 142 """
... ... @@ -216,14 +216,14 @@ class Parser():
216 216 """
217 217 Return image window center / level (related to brightness).
218 218 This is an integer or a floating point. If the value can't
219   - be read, return None.
  219 + be read, return "".
220 220  
221 221 By default, only one level value is returned, according to
222 222 "preset" parameter. If no value is passed, WL_PRESET constant
223 223 is used. In case one wishes to acquire a list with all
224 224 level values, one should set "multiple" parameter to True.
225 225  
226   - Return None if field is not defined.
  226 + Return "" if field is not defined.
227 227  
228 228 DICOM standard tag (0x0028,0x1050) was used.
229 229 """
... ... @@ -244,20 +244,20 @@ class Parser():
244 244 return value_list
245 245 else:
246 246 return value_list[preset]
247   - return None
  247 + return ""
248 248  
249 249 def GetImageWindowWidth(self, preset=WL_PRESET, multiple=WL_MULT):
250 250 """
251 251 Return image window width (related to contrast). This is an
252 252 integer or a floating point. If the value can't be read,
253   - return None.
  253 + return "".
254 254  
255 255 By default, only one width value is returned, according to
256 256 "preset" parameter. If no value is passed, WL_PRESET constant
257 257 is used. In case one wishes to acquire a list with all
258 258 preset values, one should set "multiple" parameter to True.
259 259  
260   - Return None if field is not defined.
  260 + Return "" if field is not defined.
261 261  
262 262 DICOM standard tag (0x0028,0x1051) was used.
263 263 """
... ... @@ -279,7 +279,7 @@ class Parser():
279 279 return str(value_list)
280 280 else:
281 281 return str(value_list[preset])
282   - return None
  282 + return ""
283 283  
284 284 def GetImagePosition(self):
285 285 """
... ... @@ -287,7 +287,7 @@ class Parser():
287 287 of the upper left corner voxel (first voxel transmitted).
288 288 This value is given in mm. Number might be floating point
289 289 or integer.
290   - Return None if field is not defined.
  290 + Return "" if field is not defined.
291 291  
292 292 DICOM standard tag (0x0020, 0x0032) was used.
293 293 """
... ... @@ -297,13 +297,13 @@ class Parser():
297 297 data = str(ds.GetDataElement(tag).GetValue())
298 298 if (data):
299 299 return [eval(value) for value in data.split('\\')]
300   - return None
  300 + return ""
301 301  
302 302 def GetImageLocation(self):
303 303 """
304 304 Return image location (floating value), related to the
305 305 series acquisition.
306   - Return None if field is not defined.
  306 + Return "" if field is not defined.
307 307  
308 308 DICOM standard tag (0x0020, 0x0032) was used.
309 309 """
... ... @@ -313,12 +313,12 @@ class Parser():
313 313 data = str(ds.GetDataElement(tag).GetValue())
314 314 if (data):
315 315 return eval(data)
316   - return None
  316 + return ""
317 317  
318 318 def GetImageOffset(self):
319 319 """
320 320 Return image pixel offset (memory position).
321   - Return None if field is not defined.
  321 + Return "" if field is not defined.
322 322  
323 323 DICOM standard tag (0x7fe0, 0x0010) was used.
324 324 """
... ... @@ -328,14 +328,14 @@ class Parser():
328 328 data = str(ds.GetDataElement(tag).GetValue())
329 329 if (data):
330 330 return int(data.split(':')[1])
331   - return None
  331 + return ""
332 332  
333 333  
334 334 def GetImageSeriesNumber(self):
335 335 """
336 336 Return integer related to acquisition series where this
337 337 slice is included.
338   - Return None if field is not defined.
  338 + Return "" if field is not defined.
339 339  
340 340 DICOM standard tag (0x0020, 0x0011) was used.
341 341 """
... ... @@ -343,9 +343,9 @@ class Parser():
343 343 ds = self.gdcm_reader.GetFile().GetDataSet()
344 344 if ds.FindDataElement(tag):
345 345 data = str(ds.GetDataElement(tag).GetValue())
346   - if (data) and (data != 'None'):
  346 + if (data) and (data != '""'):
347 347 return int(data)
348   - return None
  348 + return ""
349 349  
350 350  
351 351 def GetPixelSpacing(self):
... ... @@ -354,7 +354,7 @@ class Parser():
354 354 each pair of pixel. That is, adjacent row spacing (delimiter)
355 355 and adjacent column spacing. Values are usually floating point
356 356 and represent mm.
357   - Return None if field is not defined.
  357 + Return "" if field is not defined.
358 358  
359 359 DICOM standard tag (0x0028, 0x0030) was used.
360 360 """
... ... @@ -364,26 +364,26 @@ class Parser():
364 364 data = str(ds.GetDataElement(tag).GetValue())
365 365 if (data):
366 366 return [eval(value) for value in data.split('\\')]
367   - return None
  367 + return ""
368 368  
369 369 def GetImagePixelSpacingY(self):
370 370 """
371 371 Return spacing between adjacent pixels considerating y axis
372 372 (height). Values are usually floating point and represent mm.
373   - Return None if field is not defined.
  373 + Return "" if field is not defined.
374 374  
375 375 DICOM standard tag (0x0028, 0x0030) was used.
376 376 """
377 377 spacing = self.GetPixelSpacing()
378 378 if spacing:
379 379 return spacing[1]
380   - return None
  380 + return ""
381 381  
382 382 def GetImagePixelSpacingX(self):
383 383 """
384 384 Return spacing between adjacent pixels considerating x axis
385 385 (width). Values are usually floating point and represent mm.
386   - Return None if field is not defined.
  386 + Return "" if field is not defined.
387 387  
388 388 DICOM standard tag (0x0028, 0x0030) was used.
389 389 """
... ... @@ -391,12 +391,12 @@ class Parser():
391 391 spacing = self.GetPixelSpacing()
392 392 if spacing:
393 393 return spacing[0]
394   - return None
  394 + return ""
395 395  
396 396 def GetPatientWeight(self):
397 397 """
398 398 Return patient's weight as a float value (kilograms).
399   - Return None if field is not defined.
  399 + Return "" if field is not defined.
400 400  
401 401 DICOM standard tag (0x0010, 0x1030) was used.
402 402 """
... ... @@ -406,12 +406,12 @@ class Parser():
406 406 data = str(ds.GetDataElement(tag).GetValue())
407 407 if (data):
408 408 return float(data)
409   - return None
  409 + return ""
410 410  
411 411 def GetPatientHeight(self):
412 412 """
413 413 Return patient's height as a float value (meters).
414   - Return None if field is not defined.
  414 + Return "" if field is not defined.
415 415  
416 416 DICOM standard tag (0x0010, 0x1030) was used.
417 417 """
... ... @@ -421,7 +421,7 @@ class Parser():
421 421 data = str(ds.GetDataElement(tag).GetValue())
422 422 if (data):
423 423 return float(data)
424   - return None
  424 + return ""
425 425  
426 426 def GetPatientAddress(self):
427 427 """
... ... @@ -435,12 +435,12 @@ class Parser():
435 435 data = str(ds.GetDataElement(tag).GetValue())
436 436 if (data):
437 437 return data
438   - return None
  438 + return ""
439 439  
440 440 def GetPatientMilitarRank(self):
441 441 """
442 442 Return string containing patient's militar rank.
443   - Return None if field is not defined.
  443 + Return "" if field is not defined.
444 444  
445 445 DICOM standard tag (0x0010, 0x1080) was used.
446 446 """
... ... @@ -450,14 +450,14 @@ class Parser():
450 450 data = str(ds.GetDataElement(tag).GetValue())
451 451 if (data):
452 452 return data
453   - return None
  453 + return ""
454 454  
455 455 def GetPatientMilitarBranch(self):
456 456 """
457 457 Return string containing the militar branch.
458 458 The country allegiance may also be included
459 459 (e.g. B.R. Army).
460   - Return None if field is not defined.
  460 + Return "" if field is not defined.
461 461  
462 462 DICOM standard tag (0x0010, 0x1081) was used.
463 463 """
... ... @@ -467,13 +467,13 @@ class Parser():
467 467 data = str(ds.GetDataElement(tag).GetValue())
468 468 if (data):
469 469 return data
470   - return None
  470 + return ""
471 471  
472 472 def GetPatientCountry(self):
473 473 """
474 474 Return string containing the country where the patient
475 475 currently resides.
476   - Return None if field is not defined.
  476 + Return "" if field is not defined.
477 477  
478 478 DICOM standard tag (0x0010, 0x2150) was used.
479 479 """
... ... @@ -483,13 +483,13 @@ class Parser():
483 483 data = str(ds.GetDataElement(tag).GetValue())
484 484 if (data):
485 485 return data
486   - return None
  486 + return ""
487 487  
488 488 def GetPatientRegion(self):
489 489 """
490 490 Return string containing the region where the patient
491 491 currently resides.
492   - Return None if field is not defined.
  492 + Return "" if field is not defined.
493 493  
494 494 DICOM standard tag (0x0010, 0x2152) was used.
495 495 """
... ... @@ -499,12 +499,12 @@ class Parser():
499 499 data = str(ds.GetDataElement(tag).GetValue())
500 500 if (data):
501 501 return data
502   - return None
  502 + return ""
503 503  
504 504 def GetPatientTelephone(self):
505 505 """
506 506 Return string containing the patient's telephone number.
507   - Return None if field is not defined.
  507 + Return "" if field is not defined.
508 508  
509 509 DICOM standard tag (0x0010, 0x2154) was used.
510 510 """
... ... @@ -514,13 +514,13 @@ class Parser():
514 514 data = str(ds.GetDataElement(tag).GetValue())
515 515 if (data):
516 516 return data
517   - return None
  517 + return ""
518 518  
519 519 def GetPatientResponsible(self):
520 520 """
521 521 Return string containing the name of the person with
522 522 medical decision authority in regards to this patient.
523   - Return None if field is not defined.
  523 + Return "" if field is not defined.
524 524  
525 525 DICOM standard tag (0x0010, 0x2297) was used.
526 526 """
... ... @@ -530,13 +530,13 @@ class Parser():
530 530 data = str(ds.GetDataElement(tag).GetValue())
531 531 if (data):
532 532 return data
533   - return None
  533 + return ""
534 534  
535 535 def GetPatientResponsibleRole(self):
536 536 """
537 537 Return string containing the relationship of the responsible
538 538 person in regards to this patient.
539   - Return None if field is not defined.
  539 + Return "" if field is not defined.
540 540  
541 541 DICOM standard tag (0x0010, 0x2298) was used.
542 542 """
... ... @@ -546,13 +546,13 @@ class Parser():
546 546 data = str(ds.GetDataElement(tag).GetValue())
547 547 if (data):
548 548 return data
549   - return None
  549 + return ""
550 550  
551 551 def GetPatientResponsibleOrganization(self):
552 552 """
553 553 Return string containing the organization name with
554 554 medical decision authority in regards to this patient.
555   - Return None if field is not defined.
  555 + Return "" if field is not defined.
556 556  
557 557 DICOM standard tag (0x0010, 0x2299) was used.
558 558 """
... ... @@ -562,13 +562,13 @@ class Parser():
562 562 data = str(ds.GetDataElement(tag).GetValue())
563 563 if (data):
564 564 return data
565   - return None
  565 + return ""
566 566  
567 567 def GetPatientMedicalCondition(self):
568 568 """
569 569 Return string containing patient medical conditions
570 570 (e.g. contagious illness, drug allergies, etc.).
571   - Return None if field is not defined.
  571 + Return "" if field is not defined.
572 572  
573 573 DICOM standard tag (0x0010, 0x2000) was used.
574 574 """
... ... @@ -578,13 +578,13 @@ class Parser():
578 578 data = str(ds.GetDataElement(tag).GetValue())
579 579 if (data):
580 580 return data
581   - return None
  581 + return ""
582 582  
583 583 def GetPatientContrastAllergies(self):
584 584 """
585 585 Return string containing description of prior alergical
586 586 reactions to contrast agents.
587   - Return None if field is not defined.
  587 + Return "" if field is not defined.
588 588  
589 589 DICOM standard tag (0x0008, 0x2110) was used.
590 590 """
... ... @@ -594,14 +594,14 @@ class Parser():
594 594 data = str(ds.GetDataElement(tag).GetValue())
595 595 if (data):
596 596 return data
597   - return None
  597 + return ""
598 598  
599 599  
600 600 def GetPhysicianReferringName(self):
601 601 """
602 602 Return string containing physician
603 603 of the patient.
604   - Return None if field is not defined.
  604 + Return "" if field is not defined.
605 605  
606 606 DICOM standard tag (0x0008, 0x0090) was used.
607 607 """
... ... @@ -609,6 +609,8 @@ class Parser():
609 609 ds = self.gdcm_reader.GetFile().GetDataSet()
610 610 if ds.FindDataElement(tag):
611 611 data = str(ds.GetDataElement(tag).GetValue())
  612 + if data == "None":
  613 + return ""
612 614 if (data):
613 615 return data
614 616 return ""
... ... @@ -617,7 +619,7 @@ class Parser():
617 619 def GetPhysicianReferringAddress(self):
618 620 """
619 621 Return string containing physician's address.
620   - Return None if field is not defined.
  622 + Return "" if field is not defined.
621 623  
622 624 DICOM standard tag (0x0008, 0x0092) was used.
623 625 """
... ... @@ -627,12 +629,12 @@ class Parser():
627 629 data = str(ds.GetDataElement(tag).GetValue())
628 630 if (data):
629 631 return data
630   - return None
  632 + return ""
631 633  
632 634 def GetPhysicianeReferringTelephone(self):
633 635 """
634 636 Return string containing physician's telephone.
635   - Return None if field is not defined.
  637 + Return "" if field is not defined.
636 638  
637 639 DICOM standard tag (0x0008, 0x0094) was used.
638 640 """
... ... @@ -642,14 +644,14 @@ class Parser():
642 644 data = str(ds.GetDataElement(tag).GetValue())
643 645 if (data):
644 646 return data
645   - return None
  647 + return ""
646 648  
647 649 def GetImageType(self):
648 650 """
649 651 Return list containing strings related to image origin.
650 652 Eg: ["ORIGINAL", "PRIMARY", "AXIAL"] or ["DERIVED",
651 653 "SECONDARY", "OTHER"]
652   - Return None if field is not defined.
  654 + Return "" if field is not defined.
653 655  
654 656 Critical DICOM tag (0x0008, 0x0008). Cannot be editted.
655 657 """
... ... @@ -660,13 +662,13 @@ class Parser():
660 662 if (data):
661 663  
662 664 return data.split('\\')
663   - return None
  665 + return ""
664 666  
665 667 def GetSOPClassUID(self):
666 668 """
667 669 Return string containing the Unique Identifier for the SOP
668 670 class.
669   - Return None if field is not defined.
  671 + Return "" if field is not defined.
670 672  
671 673 Critical DICOM tag (0x0008, 0x0016). Cannot be edited.
672 674 """
... ... @@ -676,13 +678,13 @@ class Parser():
676 678 data = str(ds.GetDataElement(tag).GetValue())
677 679 if (data):
678 680 return data
679   - return None
  681 + return ""
680 682  
681 683 def GetSOPInstanceUID(self):
682 684 """
683 685 Return string containing Unique Identifier for the SOP
684 686 instance.
685   - Return None if field is not defined.
  687 + Return "" if field is not defined.
686 688  
687 689 Critical DICOM tag (0x0008, 0x0018). Cannot be edited.
688 690 """
... ... @@ -692,7 +694,7 @@ class Parser():
692 694 data = str(ds.GetDataElement(tag).GetValue())
693 695 if (data):
694 696 return data
695   - return None
  697 + return ""
696 698  
697 699 def GetSeriesDescription(self):
698 700 """
... ... @@ -706,13 +708,13 @@ class Parser():
706 708 data = str(ds.GetDataElement(tag).GetValue())
707 709 if (data):
708 710 return data
709   - return None
  711 + return ""
710 712  
711 713 def GetStudyInstanceUID(self):
712 714 """
713 715 Return string containing Unique Identifier of the
714 716 Study Instance.
715   - Return None if field is not defined.
  717 + Return "" if field is not defined.
716 718  
717 719 Critical DICOM Tag (0x0020,0x000D). Cannot be edited.
718 720 """
... ... @@ -722,7 +724,7 @@ class Parser():
722 724 data = str(ds.GetDataElement(tag).GetValue())
723 725 if (data):
724 726 return data
725   - return None
  727 + return ""
726 728  
727 729 def GetImagePatientOrientation(self):
728 730 """
... ... @@ -731,7 +733,7 @@ class Parser():
731 733 point representation. The first three values are associated
732 734 to row orientation and the three last values are related
733 735 to column orientation.
734   - Return None if field is not defined.
  736 + Return "" if field is not defined.
735 737  
736 738 Critical DICOM tag (0x0020,0x0037). Cannot be edited.
737 739 """
... ... @@ -748,7 +750,7 @@ class Parser():
748 750 Return matrix [x0, x1, x2] related to patient images'
749 751 column acquisition orientation. All values are in floating
750 752 point representation.
751   - Return None if field is not defined.
  753 + Return "" if field is not defined.
752 754  
753 755 Critical DICOM tag (0x0020,0x0037). Cannot be edited.
754 756 """
... ... @@ -765,7 +767,7 @@ class Parser():
765 767 Return matrix [y0, y1, y2] related to patient images'
766 768 row acquisition orientation. All values are in floating
767 769 point representation.
768   - Return None if field is not defined.
  770 + Return "" if field is not defined.
769 771  
770 772 Critical DICOM tag (0x0020,0x0037). Cannot be edited.
771 773 """
... ... @@ -780,7 +782,7 @@ class Parser():
780 782 def GetFrameReferenceUID(self):
781 783 """
782 784 Return string containing Frame of Reference UID.
783   - Return None if field is not defined.
  785 + Return "" if field is not defined.
784 786  
785 787 Critical DICOM tag (0x0020,0x0052). Cannot be edited.
786 788 """
... ... @@ -790,12 +792,12 @@ class Parser():
790 792 data = str(ds.GetDataElement(tag).GetValue())
791 793 if (data):
792 794 return data
793   - return None
  795 + return ""
794 796  
795 797 def GetImageSamplesPerPixel(self):
796 798 """
797 799 Return integer related to Samples per Pixel. Eg. 1.
798   - Return None if field is not defined.
  800 + Return "" if field is not defined.
799 801  
800 802 Critical DICOM tag (0x0028,0x0002). Cannot be edited.
801 803 """
... ... @@ -805,13 +807,13 @@ class Parser():
805 807 res = sf.ToStringPair(tag)
806 808 if (res[1]):
807 809 return int(res[1])
808   - return None
  810 + return ""
809 811  
810 812 def GetPhotometricInterpretation(self):
811 813 """
812 814 Return string containing the photometric interpretation.
813 815 Eg. "MONOCHROME2".
814   - Return None if field is not defined.
  816 + Return "" if field is not defined.
815 817  
816 818 Critical DICOM tag (0x0028,0x0004). Cannot be edited.
817 819 """
... ... @@ -821,13 +823,13 @@ class Parser():
821 823 res = sf.ToStringPair(tag)
822 824 if (res[1]):
823 825 return res[1]
824   - return None
  826 + return ""
825 827  
826 828 def GetBitsStored(self):
827 829 """
828 830 Return number related to number of bits stored.
829 831 Eg. 12 or 16.
830   - Return None if field is not defined.
  832 + Return "" if field is not defined.
831 833  
832 834 Critical DICOM tag (0x0028,0x0101). Cannot be edited.
833 835 """
... ... @@ -837,12 +839,12 @@ class Parser():
837 839 res = sf.ToStringPair(tag)
838 840 if (res[1]):
839 841 return int(res[1])
840   - return None
  842 + return ""
841 843  
842 844 def GetHighBit(self):
843 845 """
844 846 Return string containing hight bit. This is commonly 11 or 15.
845   - Return None if field is not defined.
  847 + Return "" if field is not defined.
846 848  
847 849 Critical DICOM tag (0x0028,0x0102). Cannot be edited.
848 850 """
... ... @@ -852,14 +854,14 @@ class Parser():
852 854 res = sf.ToStringPair(tag)
853 855 if (res[1]):
854 856 return int(res[1])
855   - return None
  857 + return ""
856 858  
857 859 def GetProtocolName(self):
858 860 """
859 861 Return protocol name (string). This info varies according to
860 862 manufactor and software interface. Eg. "FACE", "aFaceSpi",
861 863 "1551515/2" or "./protocols/user1.pfossa.pro".
862   - Return None if field is not defined.
  864 + Return "" if field is not defined.
863 865  
864 866 DICOM standard tag (0x0018, 0x1030) was used.
865 867 """
... ... @@ -869,7 +871,7 @@ class Parser():
869 871 data = str(ds.GetDataElement(tag).GetValue())
870 872 if (data):
871 873 return data
872   - return None
  874 + return ""
873 875  
874 876 def GetAcquisionSequence(self):
875 877 """
... ... @@ -883,7 +885,7 @@ class Parser():
883 885 In some cases this information is presented in other forms:
884 886 - HELICAL_CT
885 887 - SCANOSCOPE
886   - Return None if field is not defined.
  888 + Return "" if field is not defined.
887 889  
888 890 Critical DICOM tag (0x0018, 0x0020). Cannot be edited.
889 891 """
... ... @@ -893,7 +895,7 @@ class Parser():
893 895 data = str(ds.GetDataElement(tag).GetValue())
894 896 if (data):
895 897 return data
896   - return None
  898 + return ""
897 899  
898 900 def GetInstitutionName(self):
899 901 """
... ... @@ -916,7 +918,7 @@ class Parser():
916 918 Return mailing address (string) of the institution where the
917 919 acquisitin quipment is located. Some institutions record only
918 920 the city, other record the full address.
919   - Return None if field is not defined.
  921 + Return "" if field is not defined.
920 922  
921 923 DICOM standard tag (0x0008, 0x0081) was used.
922 924 """
... ... @@ -926,13 +928,13 @@ class Parser():
926 928 data = str(ds.GetDataElement(tag).GetValue())
927 929 if (data):
928 930 return data
929   - return None
  931 + return ""
930 932  
931 933 def GetStudyInstanceUID(self):
932 934 """
933 935 Return Study Instance UID (string), related to series being
934 936 analized.
935   - Return None if field is not defined.
  937 + Return "" if field is not defined.
936 938  
937 939 Critical DICOM tag (0x0020, 0x000D). Cannot be edited.
938 940 """
... ... @@ -942,12 +944,12 @@ class Parser():
942 944 data = str(ds.GetDataElement(tag).GetValue())
943 945 if (data):
944 946 return data
945   - return None
  947 + return ""
946 948  
947 949 def GetPatientOccupation(self):
948 950 """
949 951 Return occupation of the patient (string).
950   - Return None if field is not defined.
  952 + Return "" if field is not defined.
951 953  
952 954 DICOM standard tag (0x0010,0x2180) was used.
953 955 """
... ... @@ -957,7 +959,7 @@ class Parser():
957 959 data = str(ds.GetDataElement(tag).GetValue())
958 960 if (data):
959 961 return data
960   - return None
  962 + return ""
961 963  
962 964 def _GetPixelRepresentation(self):
963 965 """
... ... @@ -974,7 +976,7 @@ class Parser():
974 976 res = sf.ToStringPair(tag)
975 977 if (res[1]):
976 978 return int(res[1])
977   - return None
  979 + return ""
978 980  
979 981 def _GetBitsAllocated(self):
980 982 """
... ... @@ -991,7 +993,7 @@ class Parser():
991 993  
992 994 if (res[1]):
993 995 return int(res[1])
994   - return None
  996 + return ""
995 997  
996 998 def GetImageDataType(self):
997 999 """
... ... @@ -1002,14 +1004,14 @@ class Parser():
1002 1004 - Int16
1003 1005 - Int32
1004 1006 - UInt16
1005   - Return None otherwise.
  1007 + Return "" otherwise.
1006 1008 """
1007 1009 repres = self._GetPixelRepresentation()
1008 1010  
1009 1011 bits = self._GetBitsAllocated()
1010 1012  
1011 1013 if not bits:
1012   - answer = None
  1014 + answer = ""
1013 1015 else:
1014 1016 answer = "UInt16"
1015 1017  
... ... @@ -1049,7 +1051,7 @@ class Parser():
1049 1051 def GetStudyID(self):
1050 1052 """
1051 1053 Return string containing the Study ID.
1052   - Return None if not set.
  1054 + Return "" if not set.
1053 1055  
1054 1056 DICOM standard tag (0x0020,0x0010) was used.
1055 1057 """
... ... @@ -1058,7 +1060,7 @@ class Parser():
1058 1060 .GetStudyID()
1059 1061 if (data):
1060 1062 return data
1061   - return None
  1063 + return ""
1062 1064  
1063 1065 def GetAcquisitionGantryTilt(self):
1064 1066 """
... ... @@ -1080,7 +1082,7 @@ class Parser():
1080 1082 - M: male
1081 1083 - F: female
1082 1084 - O: other
1083   - If not defined, return None.
  1085 + If not defined, return "".
1084 1086  
1085 1087 DICOM standard tag (0x0010,0x0040) was used.
1086 1088 """
... ... @@ -1088,13 +1090,13 @@ class Parser():
1088 1090 .GetPatientSex()
1089 1091 if (data):
1090 1092 return data
1091   - return None
  1093 + return ""
1092 1094  
1093 1095 def GetPatientAge(self):
1094 1096 """
1095 1097 Return patient's age (integer). In case there are alpha
1096 1098 characters in this field, a string is returned.
1097   - If not defined field, return None.
  1099 + If not defined field, return "".
1098 1100  
1099 1101 DICOM standard tag (0x0010, 0x1010) was used.
1100 1102 """
... ... @@ -1106,12 +1108,12 @@ class Parser():
1106 1108 return int(age)
1107 1109 except ValueError:
1108 1110 return age
1109   - return None
  1111 + return ""
1110 1112  
1111 1113 def GetPatientName(self):
1112 1114 """
1113 1115 Return patient's full legal name (string).
1114   - If not defined, return None.
  1116 + If not defined, return "".
1115 1117  
1116 1118 DICOM standard tag (0x0010,0x0010) was used.
1117 1119 """
... ... @@ -1119,13 +1121,13 @@ class Parser():
1119 1121 .GetPatientName()
1120 1122 if (data):
1121 1123 return data
1122   - return None
  1124 + return ""
1123 1125  
1124 1126 def GetPatientID(self):
1125 1127 """
1126 1128 Return primary hospital identification number (string)
1127 1129 or patient's identification number (string).
1128   - Return None if not defined.
  1130 + Return "" if not defined.
1129 1131  
1130 1132 DICOM standard tag (0x0010,0x0020) was used.
1131 1133 """
... ... @@ -1133,51 +1135,51 @@ class Parser():
1133 1135 .GetPatientID()
1134 1136 if (data):
1135 1137 return data
1136   - return None
  1138 + return ""
1137 1139  
1138 1140  
1139 1141 def GetDimensionX(self):
1140 1142 """
1141 1143 Return integer associated to X dimension. This is related
1142 1144 to the number of columns on the image.
1143   - Return None if not defined.
  1145 + Return "" if not defined.
1144 1146 """
1145 1147  
1146 1148 data = self.vtkgdcm_reader.GetOutput()\
1147 1149 .GetDimensions()[0]
1148 1150 if (data):
1149 1151 return int(data)
1150   - return None
  1152 + return ""
1151 1153  
1152 1154 def GetDimensionY(self):
1153 1155 """
1154 1156 Return integer associated to Y dimension. This is related
1155 1157 to the number of rows on the image.
1156   - Return None if not defined.
  1158 + Return "" if not defined.
1157 1159 """
1158 1160 data = self.vtkgdcm_reader.GetOutput()\
1159 1161 .GetDimensions()[1]
1160 1162 if (data):
1161 1163 return int(data)
1162   - return None
  1164 + return ""
1163 1165  
1164 1166 def GetDimensionZ(self):
1165 1167 """
1166 1168 Return float value associated to Z dimension.
1167   - Return None if not defined.
  1169 + Return "" if not defined.
1168 1170 """
1169 1171 data = self.vtkgdcm_reader.GetOutput()\
1170 1172 .GetDimensions()[2]
1171 1173 if (data):
1172 1174 return float(data)
1173   - return None
  1175 + return ""
1174 1176  
1175 1177  
1176 1178 def GetEquipmentXRayTubeCurrent(self):
1177 1179 """
1178 1180 Return float value associated to the X-ray tube current
1179 1181 (expressed in mA).
1180   - Return None if not defined.
  1182 + Return "" if not defined.
1181 1183  
1182 1184 DICOM standard tag (0x0018,0x1151) was used.
1183 1185 """
... ... @@ -1185,13 +1187,13 @@ class Parser():
1185 1187 .GetXRayTubeCurrent()
1186 1188 if (data):
1187 1189 return data
1188   - return None
  1190 + return ""
1189 1191  
1190 1192 def GetExposureTime(self):
1191 1193 """
1192 1194 Return float value associated to the time of X-ray tube current
1193 1195 exposure (expressed in s).
1194   - Return None if not defined.
  1196 + Return "" if not defined.
1195 1197  
1196 1198 DICOM standard tag (0x0018, 0x1152) was used.
1197 1199 """
... ... @@ -1199,13 +1201,13 @@ class Parser():
1199 1201 .GetExposureTime()
1200 1202 if (data):
1201 1203 return float(data)
1202   - return None
  1204 + return ""
1203 1205  
1204 1206 def GetEquipmentKVP(self):
1205 1207 """
1206 1208 Return float value associated to the kilo voltage peak
1207 1209 output of the (x-ray) used generator.
1208   - Return None if not defined.
  1210 + Return "" if not defined.
1209 1211  
1210 1212 DICOM standard tag (0x0018,0x0060) was used.
1211 1213 """
... ... @@ -1213,13 +1215,13 @@ class Parser():
1213 1215 .GetKVP()
1214 1216 if (data):
1215 1217 return float(data)
1216   - return None
  1218 + return ""
1217 1219  
1218 1220 def GetImageThickness(self):
1219 1221 """
1220 1222 Return float value related to the nominal reconstructed
1221 1223 slice thickness (expressed in mm).
1222   - Return None if not defined.
  1224 + Return "" if not defined.
1223 1225  
1224 1226 DICOM standard tag (0x0018,0x0050) was used.
1225 1227 """
... ... @@ -1235,7 +1237,7 @@ class Parser():
1235 1237 used to reconstruct the data. This is very dependent on the
1236 1238 model and the manufactor. Eg. "standard" kernel could be
1237 1239 written on various ways (STD, STND, Stand, STANDARD).
1238   - Return None if not defined.
  1240 + Return "" if not defined.
1239 1241  
1240 1242 DICOM standard tag (0x0018,0x1210) was used.
1241 1243 """
... ... @@ -1243,7 +1245,7 @@ class Parser():
1243 1245 .GetConvolutionKernel()
1244 1246 if (data):
1245 1247 return data
1246   - return None
  1248 + return ""
1247 1249  
1248 1250 def GetEquipmentInstitutionName(self):
1249 1251 """
... ... @@ -1263,7 +1265,7 @@ class Parser():
1263 1265 """
1264 1266 Return user defined machine name (string) used to produce exam
1265 1267 files.
1266   - Return None if not defined.
  1268 + Return "" if not defined.
1267 1269  
1268 1270 DICOM standard tag (0x0008, 0x1010) was used.
1269 1271 """
... ... @@ -1271,13 +1273,13 @@ class Parser():
1271 1273 .GetStationName()
1272 1274 if (data):
1273 1275 return data
1274   - return None
  1276 + return ""
1275 1277  
1276 1278 def GetManufacturerModelName(self):
1277 1279 """
1278 1280 Return equipment model name (string) used to generate exam
1279 1281 files.
1280   - Return None if not defined.
  1282 + Return "" if not defined.
1281 1283  
1282 1284 DICOM standard tag (0x0008,0x1090) was used.
1283 1285 """
... ... @@ -1285,12 +1287,12 @@ class Parser():
1285 1287 .GetManufacturerModelName()
1286 1288 if (data):
1287 1289 return data
1288   - return None
  1290 + return ""
1289 1291  
1290 1292 def GetEquipmentManufacturer(self):
1291 1293 """
1292 1294 Return manufacturer name (string).
1293   - Return None if not defined.
  1295 + Return "" if not defined.
1294 1296  
1295 1297 DICOM standard tag (0x0008, 0x1010) was used.
1296 1298 """
... ... @@ -1298,14 +1300,14 @@ class Parser():
1298 1300 .GetManufacturer()
1299 1301 if (data):
1300 1302 return data
1301   - return None
  1303 + return ""
1302 1304  
1303 1305 def GetAcquisitionModality(self):
1304 1306 """
1305 1307 Return modality of acquisition:
1306 1308 - CT: Computed Tomography
1307 1309 - MR: Magnetic Ressonance
1308   - Return None if not defined.
  1310 + Return "" if not defined.
1309 1311  
1310 1312 DICOM standard tag (0x0008,0x0060) was used.
1311 1313 """
... ... @@ -1313,13 +1315,13 @@ class Parser():
1313 1315 .GetModality()
1314 1316 if (data):
1315 1317 return data
1316   - return None
  1318 + return ""
1317 1319  
1318 1320  
1319 1321 def GetImageNumber(self):
1320 1322 """
1321 1323 Return slice number (integer).
1322   - Return None if not defined.
  1324 + Return "" if not defined.
1323 1325  
1324 1326 DICOM standard tag (0x0020,0x0013) was used.
1325 1327 """
... ... @@ -1327,12 +1329,12 @@ class Parser():
1327 1329 .GetImageNumber()
1328 1330 if (data):
1329 1331 return int(data)
1330   - return None
  1332 + return ""
1331 1333  
1332 1334 def GetStudyDescription(self):
1333 1335 """
1334 1336 Return study description (string).
1335   - Return None if not defined.
  1337 + Return "" if not defined.
1336 1338  
1337 1339 DICOM standard tag (0x0008,0x1030) was used.
1338 1340 """
... ... @@ -1340,7 +1342,7 @@ class Parser():
1340 1342 .GetStudyDescription()
1341 1343 if (data):
1342 1344 return data
1343   - return None
  1345 + return ""
1344 1346  
1345 1347 def GetStudyAdmittingDiagnosis(self):
1346 1348 """
... ... @@ -1377,9 +1379,9 @@ class Parser():
1377 1379 if (label):
1378 1380 return label
1379 1381 else:
1380   - return None
  1382 + return ""
1381 1383  
1382   - def GetSeriesDescrition(self):
  1384 + def GetSeriesDescription(self):
1383 1385 """
1384 1386 Return a string with a description of the series.
1385 1387 DICOM standard tag (0x0008, 0x103E) was used.
... ... @@ -1388,9 +1390,11 @@ class Parser():
1388 1390 ds = self.gdcm_reader.GetFile().GetDataSet()
1389 1391 if ds.FindDataElement(tag):
1390 1392 data = str(ds.GetDataElement(tag).GetValue())
  1393 + if data == "None":
  1394 + return "unnamed"
1391 1395 if (data):
1392 1396 return data
1393   - return None
  1397 + return "unnamed"
1394 1398  
1395 1399  
1396 1400  
... ... @@ -1425,9 +1429,9 @@ class DicomWriter:
1425 1429  
1426 1430 def __init__(self):
1427 1431  
1428   - self.reader = None
  1432 + self.reader = ""
1429 1433 self.anony = gdcm.Anonymizer()
1430   - self.path = None
  1434 + self.path = ""
1431 1435 self.new_dicom = vtkgdcm.vtkGDCMImageWriter()
1432 1436 reader = self.reader = gdcm.Reader()
1433 1437  
... ... @@ -1694,11 +1698,10 @@ class Patient(object):
1694 1698 class Acquisition(object):
1695 1699  
1696 1700 def __init__(self):
1697   - pass
  1701 + self.time = "12:34 AM"
1698 1702  
1699 1703 def SetParser(self, parser):
1700 1704 self.patient_orientation = parser.GetImagePatientOrientation()
1701   - self.series_description = parser.GetSeriesDescrition()
1702 1705 self.tilt = parser.GetAcquisitionGantryTilt()
1703 1706 self.serie_number = parser.GetImageSeriesNumber()
1704 1707 self.id_study = parser.GetStudyID()
... ... @@ -1707,7 +1710,7 @@ class Acquisition(object):
1707 1710 self.acquisition_date = parser.GetAcquisitionDate()
1708 1711 self.institution = parser.GetInstitutionName()
1709 1712 self.date = parser.GetAcquisitionDate()
1710   - self.acession_number = parser.GetAccessionNumber()
  1713 + self.accession_number = parser.GetAccessionNumber()
1711 1714 self.series_description = parser.GetSeriesDescription()
1712 1715  
1713 1716 class Image(object):
... ... @@ -1747,5 +1750,5 @@ class Image(object):
1747 1750 try:
1748 1751 self.type = parser.GetImageType()[2]
1749 1752 except(IndexError):
1750   - self.type = None
  1753 + self.type = ""
1751 1754  
... ...