Closed UteSpiske closed 1 year ago
I will have a look at this PR when #19 is completed (since the commits from that PR are included here)!
The suggested change is to move the filter/template tag code to the Slide model as such:
class Slide(models.Model):
def load_image(self):
...
self.get_scale_factor()
...
def get_scale_factor(self):
"""
Finds the slide scale (in um/px) from the WSI's metadata.xml file
"""
try:
slide_folder = os.path.dirname(self.path)
path_to_metadata = os.path.join(slide_folder, 'metadata.xml')
#Parse XML tree
tree = ET.parse(Path(path_to_metadata))
root = tree.getroot()
# Find the scale property
property_elem = root.find(".//Property[@ID='20007']")
cdvec2_elem = property_elem.find('CdVec2')
values = [float(d.text) for d in cdvec2_elem.findall('double')]
self.scale_factor = values[0]
except Exception as err:
raise FileNotFoundError(f"The requested metadata.xml file for {self.path} was not found")
The filter tag will then look something like:
@register.filter
def get_scale(slide):
return slide.scale_factor # um/px
I have checked against several slides in OlyVIA (and multiple zoom levels) and the scale is correct! I think we got the right piece of information from the metadata file👍
Great that we got the correct value.
I agree that it makes sense to include the value in the slide. Do you want to push the suggested changes ?
@UteSpiske Will you please review the latest changes and give feedback and a 👍 if they resolve the issues we have discussed?
Seems like things are resolved. Merging this now!
The tasks and slides in the student view have now a scalebar that adapt to the zooming level.
Could you review the code for the scalebar implementation and compare the sizes to some examples from OlyVIA ?