File: pyhst_segment.py

package info (click to toggle)
pyhst2 2020c-7
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, sid
  • size: 13,540 kB
  • sloc: ansic: 11,807; python: 9,708; cpp: 6,786; makefile: 152; sh: 31
file content (188 lines) | stat: -rw-r--r-- 5,881 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#############################################################################*/

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


import string


from .  import string_six


import traceback
import sys
import numpy
import math
import time

from os.path import basename
import os.path



import mpi4py.MPI as MPI


from . import setCpuSet
from . import segment_cy



def segmenta():

    myrank = MPI.COMM_WORLD.Get_rank()
    nprocs = MPI.COMM_WORLD.Get_size()
    mypname = MPI.Get_processor_name()
    comm = MPI.COMM_WORLD
    
    maxnargs = 8
    mygpus, MemPerProc,coresperproc,ncpusperproc =setCpuSet.setCpuSet(maxnargs)
    print( " PROCESS :mypname, myrank, nprocs, coresperproc, mygpus, MemPerProc , argv " , mypname, myrank, nprocs, coresperproc, mygpus, MemPerProc, sys.argv)
    
    pagbone_outputfile     = sys.argv[2]
    threshold              = string.atof(sys.argv[3])
    medianR                = string.atof(sys.argv[4])
    maskbone_outputfile    = sys.argv[5]
    dilatation             = string.atoi(sys.argv[6])
    
    from xml.dom import minidom
    xmldoc = minidom.parse(pagbone_outputfile+'.xml')
    SIZEZ = string.atoi(xmldoc.getElementsByTagName('SIZEZ')[0].firstChild.data)
    SIZEY = string.atoi(xmldoc.getElementsByTagName('SIZEY')[0].firstChild.data)
    SIZEX = string.atoi(xmldoc.getElementsByTagName('SIZEX')[0].firstChild.data)
    
    
    if myrank==0     :
        size = SIZEZ*SIZEY*SIZEX
        f=open(maskbone_outputfile,"w")
        f.seek(size*4-1)
        f.write(" ")
        f.close()

    comm.Barrier()
    print( " chiamo cython ", myrank)
    segment_cy.pysegment( pagbone_outputfile,
                          threshold,
                          medianR,
                          maskbone_outputfile,
                          myrank,
                          nprocs, 
                          coresperproc,
                          MemPerProc  ,
                          SIZEZ, SIZEY, SIZEX, dilatation)
    
def spilla():

    myrank = MPI.COMM_WORLD.Get_rank()
    nprocs = MPI.COMM_WORLD.Get_size()
    mypname = MPI.Get_processor_name()
    comm = MPI.COMM_WORLD
    
    maxnargs = 8
    mygpus, MemPerProc,coresperproc,ncpusperproc=setCpuSet.setCpuSet(maxnargs)
    print( " PROCESS :mypname, myrank, nprocs, coresperproc, mygpus, MemPerProc , argv " , mypname, myrank, nprocs, coresperproc, mygpus, MemPerProc, sys.argv)
    

    pagbone_outputfile     = sys.argv[2]
    absbone_outputfile     = sys.argv[3]
    maskbone_outputfile    = sys.argv[4]
    threshold              = string.atof(sys.argv[5])
    corrbone_outputfile    = sys.argv[6]

    from xml.dom import minidom
    xmldoc = minidom.parse(absbone_outputfile+'.xml')
    SIZEZ = string.atoi(xmldoc.getElementsByTagName('SIZEZ')[0].firstChild.data)
    SIZEY = string.atoi(xmldoc.getElementsByTagName('SIZEY')[0].firstChild.data)
    SIZEX = string.atoi(xmldoc.getElementsByTagName('SIZEX')[0].firstChild.data)
    
    
    if myrank==0     :
        size = SIZEZ*SIZEY*SIZEX
        f=open(corrbone_outputfile,"w")
        f.seek(size*4-1)
        f.write(" ")
        f.close()

    comm.Barrier()
    print( absbone_outputfile, pagbone_outputfile, maskbone_outputfile,threshold,corrbone_outputfile)
    segment_cy.pyspilla( pagbone_outputfile,
                         absbone_outputfile,
                         maskbone_outputfile ,
                         threshold,
                         corrbone_outputfile,
                         myrank,
                         nprocs, 
                         coresperproc,
                         MemPerProc  ,
                         SIZEZ, SIZEY, SIZEX)

def incolla():

    myrank = MPI.COMM_WORLD.Get_rank()
    nprocs = MPI.COMM_WORLD.Get_size()
    mypname = MPI.Get_processor_name()
    comm = MPI.COMM_WORLD
    
    maxnargs = 7
    mygpus, MemPerProc,coresperproc,ncpusperproc =setCpuSet.setCpuSet(maxnargs)
    print( " PROCESS :mypname, myrank, nprocs, coresperproc, mygpus, MemPerProc , argv " , mypname, myrank, nprocs, coresperproc, mygpus, MemPerProc, sys.argv)
    
    pagbone_outputfile     = sys.argv[2]
    maskbone_outputfile    = sys.argv[3]
    correctedvol_outputfile    = sys.argv[4]
    outputfile    = sys.argv[5]

    from xml.dom import minidom
    xmldoc = minidom.parse(pagbone_outputfile+'.xml')
    SIZEZ = string.atoi(xmldoc.getElementsByTagName('SIZEZ')[0].firstChild.data)
    SIZEY = string.atoi(xmldoc.getElementsByTagName('SIZEY')[0].firstChild.data)
    SIZEX = string.atoi(xmldoc.getElementsByTagName('SIZEX')[0].firstChild.data)
    
    
    if myrank==0     :
        size = SIZEZ*SIZEY*SIZEX
        f=open(outputfile,"w")
        f.seek(size*4-1)
        f.write(" ")
        f.close()

    comm.Barrier()
    
    if myrank==0     :
        name1 = correctedvol_outputfile+".info"
        name2 = outputfile+".info"
        open(name2,"w").write(open(name1,"r").read())
        
        name1 = correctedvol_outputfile+".xml"
        name2 = outputfile+".xml"
        name2_base = os.path.basename(outputfile)
        s = open(name1,"r").read()
        pos1=s.find("<SUBVOLUME_NAME>")
        pos2=s.find("<SIZEX>")
        s = s[:pos1] + "<SUBVOLUME_NAME>%s</SUBVOLUME_NAME>"%name2_base   + s[pos2:]
        open(name2,"w").write(s)

    comm.Barrier()
        

    segment_cy.pyincolla( pagbone_outputfile,
                          maskbone_outputfile,
                          correctedvol_outputfile,
                          outputfile,
                          myrank,
                          nprocs, 
                          coresperproc,
                          MemPerProc  ,
                          SIZEZ, SIZEY, SIZEX)



if(sys.argv[1]=="segmenta") :
    segmenta()
if(sys.argv[1]=="spilla") :
    spilla()
if(sys.argv[1]=="incolla") :
    incolla()