/tomo/pyhst

To get this branch, use:
bzr branch http://darksoft.org/webbzr/tomo/pyhst

« back to all changes in this revision

Viewing changes to PyHST.py

  • Committer: Suren A. Chilingaryan
  • Date: 2011-02-22 16:56:44 UTC
  • Revision ID: csa@dside.dyndns.org-20110222165644-ku8srcuxyu9x30va
Accept sinograms from numpy array

Show diffs side-by-side

added added

removed removed

Lines of Context:
468
468
      pass
469
469
 
470
470
 
 
471
module_mode = False
 
472
 
471
473
if len(sys.argv)!=2 :
472
 
  raise Exception, " WRONG NUMBER OF ARGUMENTS, give par_file_name "
473
 
 
474
 
 
475
 
 
476
 
filename=sys.argv[1]
477
 
 
478
 
try:    
479
 
 f=open(filename,"r")
480
 
except:
481
 
 logger.error(" problems reading file %s", filename)
482
 
 raise Exception, " EXITING "
483
 
 
484
 
s=f.read()
485
 
f.close()
 
474
  try:
 
475
    sys._getframe(1)
 
476
    module_mode = True
 
477
  except:
 
478
    raise Exception, " WRONG NUMBER OF ARGUMENTS, give par_file_name "
 
479
 
 
480
 
 
481
 
 
482
if module_mode:
 
483
    s = sys._getframe(1).f_globals['parameters']
 
484
else:
 
485
    filename=sys.argv[1]
 
486
    try:    
 
487
        f=open(filename,"r")
 
488
    except:
 
489
        logger.error(" problems reading file %s", filename)
 
490
        raise Exception, " EXITING "
 
491
 
 
492
    s=f.read()
 
493
    f.close()
486
494
 
487
495
s=treat_par_file(s)
488
496
 
 
497
 
489
498
NO=0
490
499
YES=1
491
500
class Parameters:
581
590
 
582
591
  logger.debug("%i %i", START_VOXEL_3,  END_VOXEL_3)
583
592
 
584
 
if( Parameters.RECONSTRUCT_FROM_SINOGRAMS):
585
 
 
586
 
 
 
593
if(( Parameters.RECONSTRUCT_FROM_SINOGRAMS) or (module_mode)):
 
594
 pre_timer = 0
 
595
 mem_timer = 0
587
596
 
588
597
################################################
589
 
 
590
 
 
591
 
 if( "NUM_LAST_IMAGE" in dir(Parameters)  and "NUM_FIRST_IMAGE" in dir(Parameters) ):
 
598
 if module_mode:
 
599
    Parameters.NUM_FIRST_SINOGRAM = 0
 
600
    Parameters.NUM_LAST_SINOGRAM = len(sys._getframe(1).f_globals['sinograms']) - 1
 
601
    numpj = Parameters.NUM_LAST_SINOGRAM
 
602
 elif( "NUM_LAST_IMAGE" in dir(Parameters)  and "NUM_FIRST_IMAGE" in dir(Parameters) ):
592
603
    numpj = Parameters.NUM_LAST_IMAGE+1-Parameters.NUM_FIRST_IMAGE
593
604
 elif("NUM_IMAGE_2" in dir(Parameters)):
594
605
    numpj = Parameters.NUM_IMAGE_2 
630
641
      sys.path=[Parameters.SINO_FILTER_PATH] + sys.path
631
642
      exec ("from %s import Filter as SINO_FILTER" % Parameters.SINO_FILTER,locals() , globals() )
632
643
 
633
 
 
634
 
 
635
 
 
 
644
 
636
645
 for nsino in range( Parameters.NUM_FIRST_SINOGRAM, Parameters.NUM_LAST_SINOGRAM+1 ):
637
 
    name=""
638
 
    if(Parameters.NUMBER_LENGTH_VARIES):
639
 
        name=name+("%d"%nsino)+Parameters.SINOGRAM_POSTFIX
 
646
    if module_mode:
 
647
        SINO = sys._getframe(1).f_globals['sinograms'][nsino]
640
648
    else:
641
 
        number = "%d"%nsino
642
 
        if(len(number)< Parameters.LENGTH_OF_NUMERICAL_PART ):
 
649
        name=""
 
650
        if(Parameters.NUMBER_LENGTH_VARIES):
 
651
            name=name+("%d"%nsino)+Parameters.SINOGRAM_POSTFIX
 
652
        else:
 
653
            number = "%d"%nsino
 
654
            if(len(number)< Parameters.LENGTH_OF_NUMERICAL_PART ):
643
655
                number = ("0" *  (Parameters.LENGTH_OF_NUMERICAL_PART-len(number)))+ number
644
 
        else:
645
 
           number=number[:Parameters.LENGTH_OF_NUMERICAL_PART]
646
 
 
647
 
        name=name+number+Parameters.SINOGRAM_POSTFIX
648
 
    name=Parameters.SINOGRAM_PREFIX+name
649
 
 
650
 
    # name_out=name[string.rfind(name,"/")+1:] +".vol"
651
 
 
652
 
    logger.info(" reading file %s", name)
653
 
    start_time = time.time();
654
 
 
655
 
    SINO = EdfFile.EdfFile(name).GetData(0, DataType="FloatValue")
656
 
    edf_timer += time.time() - start_time 
657
 
    # SINO = Numeric.transpose(SINO)*Numeric.array([1],"f")
 
656
            else:
 
657
                number=number[:Parameters.LENGTH_OF_NUMERICAL_PART]
 
658
 
 
659
            name=name+number+Parameters.SINOGRAM_POSTFIX
 
660
        
 
661
        name=Parameters.SINOGRAM_PREFIX+name
 
662
 
 
663
        # name_out=name[string.rfind(name,"/")+1:] +".vol"
 
664
 
 
665
        logger.info(" reading file %s", name)
 
666
        start_time = time.time();
 
667
 
 
668
        SINO = EdfFile.EdfFile(name).GetData(0, DataType="FloatValue")
 
669
        edf_timer += time.time() - start_time 
 
670
        # SINO = Numeric.transpose(SINO)*Numeric.array([1],"f")
 
671
 
658
672
    logger.info( SINO.shape )
659
 
   
660
 
 
661
 
 
662
673
    SINO.shape=(1,)+SINO.shape
663
674
 
664
675
    if(nsino==Parameters.NUM_FIRST_SINOGRAM):
665
676
        name_out=Parameters.OUTPUT_FILE
666
 
        SINOWORK=Numeric.array(SINO)
 
677
        SINOWORK=Numeric.array(SINO)
667
678
        start_time = time.clock()
668
679
        
669
680
        pyhst=PyHST_c.PyHST( logger, name_out ,
734
745
  axis_corrections=Numeric.zeros([numpj ],"f")
735
746
  axis_correctionsL = Numeric.zeros([numpj ],"f")
736
747
 
737
 
 
738
 
  
739
 
 
740
 
 
741
 
 
742
 
 
743
748
  Xcorr=0
744
749
  Ycorr=0
745
750
  PIECE_MARGE=1