original_docstring: 
          create a flat dicom image representation
          works with 2d and 3d nrrd files
          :return:
          
docstring: create a flat dicom image representation
  works with 2d and 3d nrrd files
docstring_tokens: create a flat dicom image representation works with 2d and 3d nrrd files
code: def build_patient():
          '''
          create a flat dicom image representation
          works with 2d and 3d nrrd files
          :return:
          '''
          json_representation = {}
          json_representation['f_name'] = f_name
          json_representation['image'] = image
          json_representation['shape'] = img.shape
          spacing = sitk_img.GetSpacing()
          json_representation['spacing'] = spacing
          if len(img.shape) == 4:  # process 4d nrrd file, t, z, x, y
              json_representation['x-axis'] = img.shape[3]
              json_representation['y-axis'] = img.shape[2]
              json_representation['z-axis'] = img.shape[1]
              json_representation['t-axis'] = img.shape[0]
              json_representation['slices'] = img.shape[1] * img.shape[0]
              json_representation['x-spacing'] = spacing[0]
              json_representation['y-spacing'] = spacing[1]
              json_representation['z-spacing'] = spacing[2]
              json_representation['t-spacing'] = spacing[3]
          elif len(img.shape) == 3:  # process 3d nrrd file, z, x, y
              json_representation['x-axis'] = img.shape[2]
              json_representation['y-axis'] = img.shape[1]
              json_representation['z-axis'] = img.shape[0]
              json_representation['t-axis'] = 0
              json_representation['slices'] = img.shape[0]  # z axis
              json_representation['x-spacing'] = spacing[0]
              json_representation['y-spacing'] = spacing[1]
              json_representation['z-spacing'] = spacing[2]
              json_representation['t-spacing'] = 0
          else:  # handle 2d nrrd files, keep same json structure
              json_representation['x-axis'] = img.shape[1]
              json_representation['y-axis'] = img.shape[0]
              json_representation['z-axis'] = 0
              json_representation['t-axis'] = 0
              json_representation['slices'] = 1  # z axis
              json_representation['x-spacing'] = spacing[0]
              json_representation['y-spacing'] = spacing[1]
              json_representation['z-spacing'] = 0
              json_representation['t-spacing'] = 0
  
          json_representation['min'] = img.min()
          json_representation['max'] = img.max()
          json_representation['mean'] = img.mean()
          json_representation['.99-quantile'] = ninenine_q
          json_representation['.75-quantile'] = seven_q
          json_representation['.50-quantle'] = mean_q
          json_representation['sizes'] = str(sitk_img.GetSize())
          json_representation['dimension'] = int(sitk_img.GetDimension())
          json_representation['row'] = get_metadata_maybe('0028|0010')
          json_representation['column'] = get_metadata_maybe('0028|0011')
          json_representation['seriesinstanceuid'] = get_metadata_maybe('0020|000e')
          json_representation['SeriesDescription'] = get_metadata_maybe('0008|103e')
          json_representation['CardiacNumberOfImages'] = get_metadata_maybe('0018|1090')
  
          # casting crashes sometimes for these properties
          try:
              json_representation['MagneticFieldStrength'] = float(get_metadata_maybe('0018|0087'))
          except:
              json_representation['MagneticFieldStrength'] = get_metadata_maybe('0018|0087')
          try:
              json_representation['SliceThickness'] = float(get_metadata_maybe('0018|0050'))
          except:
              json_representation['SliceThickness'] = get_metadata_maybe('0018|0050')
  
          json_representation['PatientPosition'] = get_metadata_maybe('0018|5100')
          json_representation['SliceLocation'] = get_metadata_maybe('0020|1041')
          json_representation['SmallestImagePixelValue'] = int(get_metadata_maybe('0028|0106', 100))
          json_representation['LargestImagePixelValue'] = int(get_metadata_maybe('0028|0107', 0))
          json_representation['Manufacturer'] = get_metadata_maybe('0008|0070')
          json_representation['ManufacturerModelName'] = get_metadata_maybe('0008|1090')
          json_representation['InstitutionName'] = get_metadata_maybe('0008|0080')
          json_representation['InstitutionAddress'] = get_metadata_maybe('0008|0081')
          json_representation['ReferringPhysicianName'] = get_metadata_maybe('0008|0090')
  
          json_representation['PatientID'] = get_metadata_maybe('0010|0020')
          json_representation['PatientBirthDate'] = get_metadata_maybe('0010|0030')
          json_representation['PatientSex'] = get_metadata_maybe('0010|0040')
          json_representation['PatientAge'] = get_metadata_maybe('0010|1010')
          json_representation['PatientSize'] = get_metadata_maybe('0010|1020')
          json_representation['PatientWeight'] = get_metadata_maybe('0010|1030')
          json_representation['studyinstanceuid'] = get_metadata_maybe('0020|000d')
          json_representation['StudyDescription'] = get_metadata_maybe('0008|1030')
  
          return json_representation
code_tokens: def build_patient ( ) : json_representation = { } json_representation [ 'f_name' ] = f_name json_representation [ 'image' ] = image json_representation [ 'shape' ] = img . shape spacing = sitk_img . GetSpacing ( ) json_representation [ 'spacing' ] = spacing if len ( img . shape ) == 4 : json_representation [ 'x-axis' ] = img . shape [ 3 ] json_representation [ 'y-axis' ] = img . shape [ 2 ] json_representation [ 'z-axis' ] = img . shape [ 1 ] json_representation [ 't-axis' ] = img . shape [ 0 ] json_representation [ 'slices' ] = img . shape [ 1 ] * img . shape [ 0 ] json_representation [ 'x-spacing' ] = spacing [ 0 ] json_representation [ 'y-spacing' ] = spacing [ 1 ] json_representation [ 'z-spacing' ] = spacing [ 2 ] json_representation [ 't-spacing' ] = spacing [ 3 ] elif len ( img . shape ) == 3 : json_representation [ 'x-axis' ] = img . shape [ 2 ] json_representation [ 'y-axis' ] = img . shape [ 1 ] json_representation [ 'z-axis' ] = img . shape [ 0 ] json_representation [ 't-axis' ] = 0 json_representation [ 'slices' ] = img . shape [ 0 ] json_representation [ 'x-spacing' ] = spacing [ 0 ] json_representation [ 'y-spacing' ] = spacing [ 1 ] json_representation [ 'z-spacing' ] = spacing [ 2 ] json_representation [ 't-spacing' ] = 0 else : json_representation [ 'x-axis' ] = img . shape [ 1 ] json_representation [ 'y-axis' ] = img . shape [ 0 ] json_representation [ 'z-axis' ] = 0 json_representation [ 't-axis' ] = 0 json_representation [ 'slices' ] = 1 json_representation [ 'x-spacing' ] = spacing [ 0 ] json_representation [ 'y-spacing' ] = spacing [ 1 ] json_representation [ 'z-spacing' ] = 0 json_representation [ 't-spacing' ] = 0 json_representation [ 'min' ] = img . min ( ) json_representation [ 'max' ] = img . max ( ) json_representation [ 'mean' ] = img . mean ( ) json_representation [ '.99-quantile' ] = ninenine_q json_representation [ '.75-quantile' ] = seven_q json_representation [ '.50-quantle' ] = mean_q json_representation [ 'sizes' ] = str ( sitk_img . GetSize ( ) ) json_representation [ 'dimension' ] = int ( sitk_img . GetDimension ( ) ) json_representation [ 'row' ] = get_metadata_maybe ( '0028|0010' ) json_representation [ 'column' ] = get_metadata_maybe ( '0028|0011' ) json_representation [ 'seriesinstanceuid' ] = get_metadata_maybe ( '0020|000e' ) json_representation [ 'SeriesDescription' ] = get_metadata_maybe ( '0008|103e' ) json_representation [ 'CardiacNumberOfImages' ] = get_metadata_maybe ( '0018|1090' ) try : json_representation [ 'MagneticFieldStrength' ] = float ( get_metadata_maybe ( '0018|0087' ) ) except : json_representation [ 'MagneticFieldStrength' ] = get_metadata_maybe ( '0018|0087' ) try : json_representation [ 'SliceThickness' ] = float ( get_metadata_maybe ( '0018|0050' ) ) except : json_representation [ 'SliceThickness' ] = get_metadata_maybe ( '0018|0050' ) json_representation [ 'PatientPosition' ] = get_metadata_maybe ( '0018|5100' ) json_representation [ 'SliceLocation' ] = get_metadata_maybe ( '0020|1041' ) json_representation [ 'SmallestImagePixelValue' ] = int ( get_metadata_maybe ( '0028|0106' , 100 ) ) json_representation [ 'LargestImagePixelValue' ] = int ( get_metadata_maybe ( '0028|0107' , 0 ) ) json_representation [ 'Manufacturer' ] = get_metadata_maybe ( '0008|0070' ) json_representation [ 'ManufacturerModelName' ] = get_metadata_maybe ( '0008|1090' ) json_representation [ 'InstitutionName' ] = get_metadata_maybe ( '0008|0080' ) json_representation [ 'InstitutionAddress' ] = get_metadata_maybe ( '0008|0081' ) json_representation [ 'ReferringPhysicianName' ] = get_metadata_maybe ( '0008|0090' ) json_representation [ 'PatientID' ] = get_metadata_maybe ( '0010|0020' ) json_representation [ 'PatientBirthDate' ] = get_metadata_maybe ( '0010|0030' ) json_representation [ 'PatientSex' ] = get_metadata_maybe ( '0010|0040' ) json_representation [ 'PatientAge' ] = get_metadata_maybe ( '0010|1010' ) json_representation [ 'PatientSize' ] = get_metadata_maybe ( '0010|1020' ) json_representation [ 'PatientWeight' ] = get_metadata_maybe ( '0010|1030' ) json_representation [ 'studyinstanceuid' ] = get_metadata_maybe ( '0020|000d' ) json_representation [ 'StudyDescription' ] = get_metadata_maybe ( '0008|1030' ) return json_representation
short_docstring: create a flat dicom image representation
  works with 2d and 3d nrrd files
short_docstring_tokens: create a flat dicom image representation works with 2d and 3d nrrd files
comment: '''
          create a flat dicom image representation
          works with 2d and 3d nrrd files
          :return:
          '''$SEP$# process 4d nrrd file, t, z, x, y$SEP$# process 3d nrrd file, z, x, y$SEP$# z axis$SEP$# handle 2d nrrd files, keep same json structure$SEP$# z axis$SEP$# casting crashes sometimes for these properties