Commit 64b7e3e15736d2fc569ae946d639251152f06abe
1 parent
1dade744
Exists in
master
and in
68 other branches
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,10 +148,17 @@ def frange(start, end=None, inc=None): | ||
148 | return L | 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 | #physical_memory in Byte | 160 | #physical_memory in Byte |
154 | - physical_memory = GetPhysicalMemoryAmount() | 161 | + physical_memory = get_physical_memory() |
155 | 162 | ||
156 | if (sys.platform == 'win32'): | 163 | if (sys.platform == 'win32'): |
157 | 164 | ||
@@ -170,14 +177,14 @@ def PredictingMemory(qtd, x, y, p): | @@ -170,14 +177,14 @@ def PredictingMemory(qtd, x, y, p): | ||
170 | #2147483648 byte = 2.0 GB | 177 | #2147483648 byte = 2.0 GB |
171 | #4294967296 byte = 4.0 GB | 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 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.04 | 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 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.05 | 184 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.05 |
178 | 185 | ||
179 | elif(physical_memory > 2147483648) and \ | 186 | elif(physical_memory > 2147483648) and \ |
180 | - (physical_memory <= 4294967296) and (qtd <= 1200): | 187 | + (physical_memory <= 4294967296) and (nfiles <= 1200): |
181 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | 188 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 |
182 | 189 | ||
183 | else: | 190 | else: |
@@ -191,7 +198,7 @@ def PredictingMemory(qtd, x, y, p): | @@ -191,7 +198,7 @@ def PredictingMemory(qtd, x, y, p): | ||
191 | # 839000000 = 800 MB | 198 | # 839000000 = 800 MB |
192 | if (m <= 839000000) and (physical_memory <= 2147483648): | 199 | if (m <= 839000000) and (physical_memory <= 2147483648): |
193 | return (x,y) | 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 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | 202 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 |
196 | else: | 203 | else: |
197 | return (x,y) | 204 | return (x,y) |
@@ -200,7 +207,7 @@ def PredictingMemory(qtd, x, y, p): | @@ -200,7 +207,7 @@ def PredictingMemory(qtd, x, y, p): | ||
200 | 207 | ||
201 | if (m <= 839000000) and (physical_memory <= 2147483648): | 208 | if (m <= 839000000) and (physical_memory <= 2147483648): |
202 | return (x, y) | 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 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | 211 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 |
205 | else: | 212 | else: |
206 | return (x,y) | 213 | return (x,y) |
@@ -212,20 +219,20 @@ def PredictingMemory(qtd, x, y, p): | @@ -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 | sg = sigar.open() | 237 | sg = sigar.open() |
231 | mem = sg.mem() | 238 | mem = sg.mem() |