from fairdatanow import DataViewer, login, filters, data_now
import os
import re
import toml
import holoviews as hv
from holoviews import RGB, opts
from holoviews.operation.datashader import rasterize
import panel as pn Annotating your shared data with TOML
toml_txt = '''
# On which locations within our ten World Museum Japanse prints did Gauthier and Tessa measure an XRF spectrum?
# And what do these spectra show?
# Measurements have been done on a selection of 10 prints that are present in our lab
# here are the 10 object numbers
prints_in_Amsterdam = [
'RV-1-4468-544',
'RV-1-4469-484',
'RV-1-4469-58',
'RV-1-4469-x6',
'RV-1-4469Q',
'RV-1-4470-12',
'RV-1-4470-27',
'RV-360-2345g',
'RV-360-2359-2',
'RV-360-6886']
[nc_spx]
# these are regexes that download all .spx files per object number
RV-1-4468-544 = ".*XRF.*RV-1-4468-544.*[.]spx"
RV-1-4469-484 = ".*XRF.*RV-1-4469-484.*[.]spx"
RV-1-4469-58 = ".*XRF.*RV-1-4469-58.*[.]spx"
RV-1-4469-x6 = ".*XRF.*RV-1-4469-x6.*[.]spx"
RV-1-4469Q = ".*XRF.*RV-1-4469Q.*[.]spx" # duplicate so no XRF spectra
RV-1-4470-12 = ".*XRF.*RV-1-4470-12.*[.]spx"
RV-1-4470-27 = ".*XRF.*RV-1-4470-27.*[.]spx"
RV-360-2345g = ".*XRF.*RV-360-2345g.*[.]spx"
RV-360-2359-2 = ".*XRF.*RV-360-2359-2.*[.]spx"
RV-360-6886 = ".*XRF.*RV-360-6886.*[.]spx"
[nc_jpg]
# these are regexes that download all .jpg files per object number
RV-1-4468-544 = ".*XRF.*RV-1-4468-544.*[.]jpg"
RV-1-4469-484 = ".*XRF.*RV-1-4469-484.*[.]jpg"
RV-1-4469-58 = ".*XRF.*RV-1-4469-58.*[.]jpg"
RV-1-4469-x6 = ".*XRF.*RV-1-4469-x6.*[.]jpg"
RV-1-4469Q = ".*XRF.*RV-1-4469Q.*[.]jpg" # duplicate so no jpg's for point locations
RV-1-4470-12 = ".*XRF.*RV-1-4470-12.*[.]jpg"
RV-1-4470-27 = ".*XRF.*RV-1-4470-27.*[.]jpg"
RV-360-2345g = ".*XRF.*RV-360-2345g.*[.]jpg"
RV-360-2359-2 = ".*XRF.*RV-360-2359-2.*[.]jpg"
RV-360-6886 = ".*XRF.*RV-360-6886.*[.]jpg"
[nc_tifs]
# regexes for the tifs
RV-1-4468-544 = ".*akama.*RV-1-4468-544[.]tif"
RV-1-4469-484 = ".*akama.*RV-1-4469-484[.]tif"
RV-1-4469-58 = ".*akama.*RV-1-4469-58[.]tif"
RV-1-4469-x6 = ".*akama.*RV-1-4469-x6[.]tif"
RV-1-4469Q = ".*akama.*RV-1-4469Q[.]tif"
RV-1-4470-12 = ".*akama.*RV-1-4470-12[.]tif"
RV-1-4470-27 = ".*akama.*1-4470-27[.]tif" # TIF NAME WITHOUT RV prefix!
RV-360-2345g = ".*akama.*RV-360-2345-?g[.]tif"
RV-360-2359-2 = ".*akama.*RV-360-2359-2[.]tif"
RV-360-6886 = ".*akama.*RV-360-6886[.]tif"
'''Simple for loop to create additional specific file patterns.
toml_dict = toml.loads(toml_txt)
object_nums = sorted(toml_dict['prints_in_Amsterdam'])for num in object_nums:
print(f'{num} = ".*XRF.*{num}.*[.]jpg"')RV-1-4468-544 = ".*XRF.*RV-1-4468-544.*[.]jpg"
RV-1-4469-484 = ".*XRF.*RV-1-4469-484.*[.]jpg"
RV-1-4469-58 = ".*XRF.*RV-1-4469-58.*[.]jpg"
RV-1-4469-x6 = ".*XRF.*RV-1-4469-x6.*[.]jpg"
RV-1-4469Q = ".*XRF.*RV-1-4469Q.*[.]jpg"
RV-1-4470-12 = ".*XRF.*RV-1-4470-12.*[.]jpg"
RV-1-4470-27 = ".*XRF.*RV-1-4470-27.*[.]jpg"
RV-360-2345g = ".*XRF.*RV-360-2345g.*[.]jpg"
RV-360-2359-2 = ".*XRF.*RV-360-2359-2.*[.]jpg"
RV-360-6886 = ".*XRF.*RV-360-6886.*[.]jpg"
toml_dict = toml.loads(toml_txt)
object_nums = sorted(toml_dict['prints_in_Amsterdam'])url = 'https://laboppad.nl/ukiyo-e-world'
spx_files_dict = data_now(url, toml_txt, nc_key='nc_spx', verbose=False)
jpg_files_dict = data_now(url, toml_txt, nc_key='nc_jpg', verbose=False)
tif_files_dict = data_now(url, toml_txt, nc_key='nc_tifs', verbose=False)Ready!
Ready!
Ready!
rgb_views = [rasterize(RGB.load_image(tif_files_dict[num][0]).opts(title=num)) for num in object_nums]
layout = hv.Layout(rgb_views).cols(5)layoutWe can now try to enrich our toml file with other data…