Commit 64b7e3e15736d2fc569ae946d639251152f06abe

Authored by tatiana
1 parent 1dade744

STL: Nomenclature

Showing 1 changed file with 26 additions and 19 deletions   Show diff stats
invesalius/utils.py
... ... @@ -148,10 +148,17 @@ def frange(start, end=None, inc=None):
148 148 return L
149 149  
150 150  
151   -def PredictingMemory(qtd, x, y, p):
152   - m = qtd * (x * y * p)
  151 +def predict_memory(nfiles, x, y, p):
  152 + """
  153 + Predict how much memory will be used, giving the following
  154 + information:
  155 + nfiles: number of dicom files
  156 + x, y: dicom image size
  157 + p: bits allocated for each pixel sample
  158 + """
  159 + m = nfiles * (x * y * p)
153 160 #physical_memory in Byte
154   - physical_memory = GetPhysicalMemoryAmount()
  161 + physical_memory = get_physical_memory()
155 162  
156 163 if (sys.platform == 'win32'):
157 164  
... ... @@ -170,14 +177,14 @@ def PredictingMemory(qtd, x, y, p):
170 177 #2147483648 byte = 2.0 GB
171 178 #4294967296 byte = 4.0 GB
172 179  
173   - if (physical_memory <= 2147483648) and (qtd <= 1200):
  180 + if (physical_memory <= 2147483648) and (nfiles <= 1200):
174 181 porcent = 1.5 + (m - 314859200) / 26999999 * 0.04
175 182  
176   - elif(physical_memory <= 2147483648) and (qtd > 1200):
  183 + elif(physical_memory <= 2147483648) and (nfiles > 1200):
177 184 porcent = 1.5 + (m - 314859200) / 26999999 * 0.05
178 185  
179 186 elif(physical_memory > 2147483648) and \
180   - (physical_memory <= 4294967296) and (qtd <= 1200):
  187 + (physical_memory <= 4294967296) and (nfiles <= 1200):
181 188 porcent = 1.5 + (m - 314859200) / 26999999 * 0.02
182 189  
183 190 else:
... ... @@ -191,7 +198,7 @@ def PredictingMemory(qtd, x, y, p):
191 198 # 839000000 = 800 MB
192 199 if (m <= 839000000) and (physical_memory <= 2147483648):
193 200 return (x,y)
194   - elif (m > 839000000) and (physical_memory <= 2147483648) and (qtd <= 1200):
  201 + elif (m > 839000000) and (physical_memory <= 2147483648) and (nfiles <= 1200):
195 202 porcent = 1.5 + (m - 314859200) / 26999999 * 0.02
196 203 else:
197 204 return (x,y)
... ... @@ -200,7 +207,7 @@ def PredictingMemory(qtd, x, y, p):
200 207  
201 208 if (m <= 839000000) and (physical_memory <= 2147483648):
202 209 return (x, y)
203   - elif (m > 839000000) and (physical_memory <= 2147483648) and (qtd <= 1200):
  210 + elif (m > 839000000) and (physical_memory <= 2147483648) and (nfiles <= 1200):
204 211 porcent = 1.5 + (m - 314859200) / 26999999 * 0.02
205 212 else:
206 213 return (x,y)
... ... @@ -212,20 +219,20 @@ def PredictingMemory(qtd, x, y, p):
212 219  
213 220  
214 221  
215   -def BytesConvert(bytes):
216   - if bytes >= 1073741824:
217   - return str(bytes / 1024 / 1024 / 1024) + ' GB'
218   - elif bytes >= 1048576:
219   - return str(bytes / 1024 / 1024) + ' MB'
220   - elif bytes >= 1024:
221   - return str(bytes / 1024) + ' KB'
222   - elif bytes < 1024:
223   - return str(bytes) + ' bytes'
  222 +#def convert_bytes(bytes):
  223 +# if bytes >= 1073741824:
  224 +# return str(bytes / 1024 / 1024 / 1024) + ' GB'
  225 +# elif bytes >= 1048576:
  226 +# return str(bytes / 1024 / 1024) + ' MB'
  227 +# elif bytes >= 1024:
  228 +# return str(bytes / 1024) + ' KB'
  229 +# elif bytes < 1024:
  230 +# return str(bytes) + ' bytes'
224 231  
225 232  
226   -def GetPhysicalMemoryAmount():
  233 +def get_physical_memory():
227 234 """
228   - Return physical memory amount in bytes
  235 + Return physical memory in bytes
229 236 """
230 237 sg = sigar.open()
231 238 mem = sg.mem()
... ...