When I tried to read the luna dataset,there's the error:
Traceback (most recent call last):
File "run_preprocess.py", line 57, in <module>
save_preprocessed_data()
File "run_preprocess.py", line 48, in save_preprocessed_data
ct = CTScan(seriesuid=series_id, centers=tp_co, radii=radii, clazz=0)
File "C:\Luna16-master\prepare\_classes.py", line 14, in __init__
path = glob(f'''{RESOURCES_PATH} /*/{seriesuid}.mhd''')[0]
IndexError: list index out of range
How to solve it?
Thanks in advance.
The code is:
class CTScan(object):
def __init__(self, seriesuid, centers, radii, clazz):
self._seriesuid = seriesuid
self._centers = centers
path = glob(f'''{RESOURCES_PATH} /*/{seriesuid}.mhd''')[0]
# path = paths[0]
self._ds = sitk.ReadImage(path)
self._spacing = np.array(list(reversed(self._ds.GetSpacing())))
self._origin = np.array(list(reversed(self._ds.GetOrigin())))
self._image = sitk.GetArrayFromImage(self._ds)
self._radii = radii
self._clazz = clazz
self._mask = None
Related
I Try to make plugin in qgis and I have a problem. Below is my code:
destination_layer = QgsProject.instance().mapLayersByName('Destination')[0]
matrix = QgsProject.instance().mapLayersByName('join')[0]
for f in matrix.getFeatures():
origin_expr = QgsExpression('Site Name={}'.format(f['Site Name']))
destination_expr = QgsExpression('Site Name={}'.format(f['Site Name_2']))
origin_feature = origin_layer.getFeatures(QgsFeatureRequest(origin_expr))
origin_coords = [(f.geometry().asPoint().x(), f.geometry().asPoint().y())
for f in origin_feature]
destination_feature = destination_layer.getFeatures(QgsFeatureRequest(destination_expr))
destination_coords = [(f.geometry().asPoint().x(), f.geometry().asPoint().y())
for f in destination_feature]
params = {
'INPUT':'NCR Road',
'START_POINT':'{},{}'.format(origin_coords[0][0], origin_coords[0][1]),
'END_POINT':'{},{}'.format(destination_coords[0][0], destination_coords[0][1]),
'STRATEGY':0,
'ENTRY_COST_CALCULATION_METHOD':0,
'DIRECTION_FIELD':'',
'VALUE_FORWARD':'',
'VALUE_BACKWARD':'',
'VALUE_BOTH':'',
'DEFAULT_DIRECTION':2,
'SPEED_FIELD':'',
'DEFAULT_SPEED':50,
'TOLERANCE':0,
'OUTPUT': 'Shortest Path Layer' }
print('Executing analysis')
processing.runAndLoadResults("qneat3:shortestpathpointtopoint", params)
Then when I run my code, it show this error:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS32~1.0\apps\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 16, in <module>
IndexError: list index out of range
Why it is not working in plugin?
We need more information like which code is on line 90? Anyway I would double check and making sure your index is doing correct things
'START_POINT':'{},{}'.format(origin_coords[0][0], origin_coords[0][1]),
'END_POINT':'{},{}'.format(destination_coords[0][0], destination_coords[0][1]),
And
destination_layer = QgsProject.instance().mapLayersByName('Destination')[0]
matrix = QgsProject.instance().mapLayersByName('join')[0]
I'm getting a TypeError when I try and run the following code:
import re
from unicodedata import normalize
from docx import Document
from wand.image import Image
from wand.drawing import Drawing
from wand.font import Font
doc = Document("P.docx")
docText = []
for para in doc.paragraphs:
docText.append(para.text)
fullText = "\n".join(docText)
ct = 242
def get(source, begin, end):
try:
start = source.index(len(begin)) + len(begin)
finish = source.index(len(end), len(start))
return source[start:finish]
except ValueError:
return ""
def capitalize(string):
cap = ("".join(j[0].upper() + j[1:]) for j in string)
return cap
def find_matches(text):
return capitalize(
[
m
for m in re.findall(
r"^[^0-9]\s+([^.;]+\s*)+[.;]+", normalize("NFKD", text), re.MULTILINE
)
]
)
with Image(width=300, height=300, psuedo='xc:black') as canvas:
left, top, width, height = 10, 10, 10, 10
for match in find_matches(text=fullText):
ct += 1
match_words = match.split(" ")
match = " ".join(match_words[:-1]) + 'ct'
with Drawing() as context:
context.fill_color = 'white'
context.rectangle(left=left, top=top, width=width, height=height)
font = Font('/System/Library/Fonts/arial.ttf')
context(canvas)
canvas.caption(match)
canvas.save(filename='patdrawTest.png')
The exact error goes as follows:
Traceback (most recent call last):
File "C:\Users\crazy\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\wand\image.py", line 3221, in caption
raise TypeError()
TypeError
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:/Users/crazy/PycharmProjects/Patents/PatDraw.py", line 54, in
<module>
canvas.caption(match) File "C:\Users\crazy\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\wand\image.py",
line 1061, in wrapped
result = function(self, *args, **kwargs) File "C:\Users\crazy\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\wand\image.py",
line 3223, in caption
raise TypeError('font must be specified or existing in image') TypeError: font must be specified or existing in image
I'm fully at a loss and can't figure it out. Any help would be great.
Running the example code in the pyrplidar documentation
from pyrplidar import PyRPlidar
lidar = PyRPlidar()
lidar.connect(port="COM8", baudrate=256000, timeout=3)
# Linux : "/dev/ttyUSB0"
# MacOS : "/dev/cu.SLAB_USBtoUART"
# Windows : "COM5"
info = lidar.get_info()
print("info :", info)
health = lidar.get_health()
print("health :", health)
samplerate = lidar.get_samplerate()
print("samplerate :", samplerate)
scan_modes = lidar.get_scan_modes()
print("scan modes :")
for scan_mode in scan_modes:
print(scan_mode)
lidar.disconnect()
give this error message
Traceback (most recent call last):
File "C:\Users\ADMIN\Desktop\RPlidar\test1.py", line 10, in <module>
info = lidar.get_info()
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrplidar.py", line 73, in get_info
discriptor = self.receive_discriptor()
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrplidar.py", line 42, in receive_discriptor
discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrplidar_protocol.py", line 110, in __init__
self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
How do I solve this? Please help
I'm having an issue trying to make a screen grab of an area defined by lines in a config file:
The following code:
def coordstore(): # check line 1 of config file (screencap name)
f=open('config.txt')
line=f.readlines()
coordstore.x1,coordstore.y1,coordstore.x2,coordstore.y2 = (line[4]).strip(),(line[5]).strip(),(line[6]).strip(),(line[7]).strip() # note: confusing. 0=line 1, 1=line2 etc.
coordstore.coords = coordstore.x1+',',coordstore.y1+',',coordstore.x2+',',coordstore.y2
coordstore.stripped = ' '.join((coordstore.coords))
print(coordstore.stripped)
return(coordstore.stripped)
coordstore()
def screenshot():
import pyscreenshot as ImageGrab2
# part of the screen
if __name__ == '__main__':
im = ImageGrab2.grab(bbox=(coordstore.stripped)) # X1,Y1,X2,Y2
im.save('tc.png')
screenshot()
prints exactly this value: 10, 20, 100, 300
it then fails with this Traceback:
Traceback (most recent call last):
File "file location", line 82, in <module>
screenshot()
File "file location", line 80, in screenshot
im = ImageGrab2.grab(bbox=(coordstore.stripped)) # X1,Y1,X2,Y2
File "PYCHARM\venv\lib\site-packages\pyscreenshot\__init__.py", line 67, in grab
to_file=False, childprocess=childprocess, backend=backend, bbox=bbox)
File "PYCHARM\venv\lib\site-packages\pyscreenshot\__init__.py", line 38, in _grab
x1, y1, x2, y2 = bbox
ValueError: too many values to unpack (expected 4)
If I manually replace (bbox=(coordstore.stripped)) with (bbox=(10, 20, 100, 300)) which is literally identical to what the variable prints, the code works perfectly but is not useful for my needs. What am I not seeing? Thanks for the help!
UPDATE:
I have tried another approach.
def coordstore(): # check line 1 of config file (screencap name)
f=open('config.txt')
line=f.readlines()
coordstore.x1 = (line[4]).strip()
coordstore.y1 = (line[5]).strip()
coordstore.x2 = (line[6]).strip()
coordstore.y2 = (line[7]).strip()
print(coordstore.x1+',', coordstore.y1+',', coordstore.x2+',', coordstore.y2)
return(coordstore.x1, coordstore.y1, coordstore.x2, coordstore.y2)
coordstore()
def screenshot():
import pyscreenshot as ImageGrab2
# part of the screen
if __name__ == '__main__':
im = ImageGrab2.grab(bbox=(coordstore.x1+',', coordstore.y1+',', coordstore.x2+',', coordstore.y2+',')) # X1,Y1,X2,Y2
im.save('tc.png')
screenshot()
This prints
10, 20, 100, 300
but returns the following Traceback errors:
Traceback (most recent call last):
File "module location", line 84, in <module>
screenshot()
File "module location", line 82, in screenshot
im = ImageGrab2.grab(bbox=(coordstore.x1+',', coordstore.y1+',', coordstore.x2+',', coordstore.y2+',')) # X1,Y1,X2,Y2
File "\PYCHARM\venv\lib\site-packages\pyscreenshot\__init__.py", line 67, in grab
to_file=False, childprocess=childprocess, backend=backend, bbox=bbox)
File "\PYCHARM\venv\lib\site-packages\pyscreenshot\__init__.py", line 42, in _grab
raise ValueError('bbox y2<=y1')
ValueError: bbox y2<=y1
As you have mentioned in comments the value of coordstore.stripped is string. And expected argument by ImageGrab2.grab is type of tuple so, first you have to convert it into tuple.
Update the method like this:
def screenshot():
import pyscreenshot as ImageGrab2
# part of the screen
if __name__ == '__main__':
im = ImageGrab2.grab(bbox=tuple(map(int, coordstore.stripped.split(', ')))) # X1,Y1,X2,Y2
im.save('tc.png')
I am troubling with the code section given below.. when I execute it, I get value error given below.
Segmask = result2
box=[]
[liver_res, num] = measure.label(result1, return_num=True)
region = measure.regionprops(liver_res)
for i in range(num):
box.append(region[i].area)
label_num = box.index(max(box)) + 1
liver_res[liver_res != label_num] = 0
liver_res[liver_res == label_num] = 1
Value error:
Traceback (most recent call last):
File "/content/gdrive/My Drive/LiTS/test.py", line 122, in <module>
predict(args)
File "/content/gdrive/My Drive/LiTS/test.py", line 91, in predict
label_num = box.index(max(box)) + 1
ValueError: max() arg is an empty sequence