try:
import IPython
except:
%pip install IPython
import IPython
from IPython.display import display, IFrame, HTML, Javascript
HTML("""<link rel="stylesheet" type="text/css" href="src/css/notebook.css"/>""")
This notebook transforms collections data to a Linked Art representation for artworks by John Ruskin. The data origin collections data published in various formats by museums and galleries.
The transformation process common to all data sources:
createObjDesc()
, cromulent
Python library, and custom coding in the createObjProp()
function, to create a Linked Art JSON-LD representation# output directory for files created
outputdir = "./data/ruskin/output/json/"
images = {}
The collection data exists into two files:
try:
import pandas as pd
except:
%pip install pandas
import pandas as pd
fileNGA = 'data/nga/input/nga_ruskin.csv'
dataFrameNGA = pd.read_csv(fileNGA)
dataFrameNGA.head()
objectid | accessioned | accessionnum | locationid | title | displaydate | beginyear | endyear | visualbrowsertimespan | medium | ... | visualbrowserclassification | parentid | isvirtual | departmentabbr | portfolio | series | volume | watermarks | lastdetectedmodification | customprinturl | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 70238 | 1 | 1987.73.2 | NaN | Tower of the Cathedral at Sens | c. 1845 | 1845 | 1845 | 1826 to 1850 | pen and brown ink, brush and black ink, black ... | ... | drawing | NaN | 0 | CG-E | NaN | NaN | NaN | NaN | 2019-10-28 22:01:34.883-04 | NaN |
1 | 70367 | 1 | 1988.20.38 | NaN | Tree Study | mid-1850s | 1845 | 1855 | 1826 to 1850 | pen and black ink with blue-gray and gray wash... | ... | drawing | NaN | 0 | CG-E | NaN | NaN | NaN | NaN | 2020-04-10 22:01:40.093-04 | NaN |
2 | 72870 | 1 | 1991.88.1 | NaN | The Garden of San Miniato near Florence | 1845 | 1845 | 1845 | 1826 to 1850 | watercolor and pen and black ink, heightened w... | ... | drawing | NaN | 0 | CG-E | NaN | NaN | NaN | NaN | 2019-10-28 22:01:34.883-04 | NaN |
3 | 76140 | 1 | 1995.52.158 | NaN | Ornamental Study with Acanthus Motif for "The ... | 1849 | 1849 | 1849 | 1826 to 1850 | pen and brown ink with watercolor and graphite... | ... | drawing | NaN | 0 | CG-E | NaN | NaN | NaN | NaN | 2019-10-28 22:01:34.883-04 | NaN |
4 rows × 28 columns
The data file containing detailed digital image data is loaded into a pandas dataframe dataFrameNGAImages
fileNGAimages = "https://raw.githubusercontent.com/NationalGalleryOfArt/opendata/main/data/published_images.csv"
dataFrameNGAImages = pd.read_csv(fileNGAimages)
dataFrameNGAImages.head()
uuid | iiifurl | iiifthumburl | viewtype | sequence | width | height | maxpixels | created | modified | depictstmsobjectid | assistivetext | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 00004dec-8300-4487-8d89-562d0126b6a1 | https://api.nga.gov/iiif/00004dec-8300-4487-8d... | https://api.nga.gov/iiif/00004dec-8300-4487-8d... | primary | 0.0 | 2623 | 4000 | 640.0 | 2010-09-07 15:08:48-04 | 2022-04-21 12:57:43.657-04 | 11975 | NaN |
1 | 00007f61-4922-417b-8f27-893ea328206c | https://api.nga.gov/iiif/00007f61-4922-417b-8f... | https://api.nga.gov/iiif/00007f61-4922-417b-8f... | primary | 0.0 | 3365 | 4332 | NaN | 2013-07-05 15:41:08-04 | 2022-05-23 14:59:28-04 | 17387 | NaN |
2 | 0000bd8c-39de-4453-b55d-5e28a9beed38 | https://api.nga.gov/iiif/0000bd8c-39de-4453-b5... | https://api.nga.gov/iiif/0000bd8c-39de-4453-b5... | primary | 0.0 | 3500 | 4688 | NaN | 2013-08-05 14:31:59-04 | 2022-05-23 15:05:58-04 | 19245 | NaN |
3 | 0000e5a4-7d32-4c2a-97c6-a6b571c9fd71 | https://api.nga.gov/iiif/0000e5a4-7d32-4c2a-97... | https://api.nga.gov/iiif/0000e5a4-7d32-4c2a-97... | primary | 0.0 | 2252 | 3000 | NaN | 2013-03-18 14:39:55-04 | 2022-05-17 18:19:25-04 | 153987 | NaN |
4 | 0001668a-dd1c-48e8-9267-b6d1697d43c8 | https://api.nga.gov/iiif/0001668a-dd1c-48e8-92... | https://api.nga.gov/iiif/0001668a-dd1c-48e8-92... | primary | 0.0 | 3446 | 4448 | NaN | 2014-01-02 14:50:50-05 | 2022-05-23 15:39:38-04 | 23830 | NaN |
Remove Byte Order Marks and create Python dictionary containing data mapping for each input file.
# remove BOM
removeBOM = open(fileNGA, mode='r', encoding='utf-8-sig').read()
open(fileNGA, mode='w', encoding='utf-8').write(removeBOM)
# data mapping between Linked Art data model and NGA data entities
mapp = {
"id":"objectid",
"accession_number":"accessionnum",
"accession_date": "",
"classification" : "classification",
"title": "title",
"alt_title": "",
"notes": "",
"date_created":"displaydate",
"date_created_earliest": "beginyear",
"date_created_latest": "endyear",
"created_period":"",
"created_dynasty":"",
"created_inscriptions":"",
"created_notes": "",
"created_provenance" : "",
"creator":"attribution",
"physical_medium": "medium",
"physical_style": "",
"physical_technique": "",
"physical_description": "",
"physical_dimensions": "dimensions",
"created_provenance": "" ,
"credit_line": "creditline",
"collection" : "departmentabbr",
"current_status" : "",
"current_owner" : "",
"homepage": ""
}
# display transposed dataframe of data mapping
display(pd.DataFrame(mapp, index=[0]).T)
0 | |
---|---|
id | objectid |
accession_number | accessionnum |
accession_date | |
classification | classification |
title | title |
alt_title | |
notes | |
date_created | displaydate |
date_created_earliest | beginyear |
date_created_latest | endyear |
created_period | |
created_dynasty | |
created_inscriptions | |
created_notes | |
created_provenance | |
creator | attribution |
physical_medium | medium |
physical_style | |
physical_technique | |
physical_description | |
physical_dimensions | dimensions |
credit_line | creditline |
collection | departmentabbr |
current_status | |
current_owner | |
homepage |
This next step uses the following to transform the collections data to Linked Art JSON-LD
The URLs for the artwork digital images are in a separate file. With custom coding in createObjProp()
the rows in the two collection data files are mapped to extract the digital image url.
matchImages = dataFrameNGAImages.query('depictstmsobjectid == ' + objProp["id"] ) objProp["image_url"] = matchImages["iiifurl"].iloc[0] + "/full/!500,500/0/default.jpg"
Additional custom code creates a web page URL for the artwork:
objProp["homepage"] = "https://www.nga.gov/collection/art-object-page." + id + ".html"
try:
import cromulent
except:
%pip install cromulent
import cromulent
from cromulent.model import factory
from lib import linkedart as la
import csv
# baseURI for JSON-LD document
baseURI = "https://www.nga.gov/collection/"
fileNGA = 'data/nga/input/nga_ruskin.csv'
# list to hold file names for use with jsonld visualisation dropdown
selectOptions = []
selectOptions = [('Please select an artwork', '')]
def createObjProp(obj,mapp):
objProp = {}
csv_keys = list(obj.keys())
for key in csv_keys:
for prop in mapp:
if key == mapp[prop]:
# custom code to populate the creator property
if prop == "creator":
objProp[prop] = [{"id": baseURI +"creatorid/" + obj[mapp["id"]] ,"name": obj[key],"role":"Artist"}]
else:
objProp[prop] = obj[key]
# custom code to populate the image_url property
matchImages = dataFrameNGAImages.query('depictstmsobjectid == ' + objProp["id"] )
objProp["image_url"] = matchImages["iiifurl"].iloc[0] + "/full/!500,500/0/default.jpg"
# custom code to define the homepage properity
objProp["homepage"] = "https://www.nga.gov/collection/art-object-page." + objProp["id"] + ".html"
return objProp
allObjects = csv.DictReader(open(fileNGA, mode='r',encoding='utf-8'))
for obj in allObjects:
# create object property dictionary
objProp = createObjProp(obj,mapp)
id = objProp["id"]
filename = id + ".json"
# create obj description
objLA = la.createObjDesc(objProp,la.objTypes,baseURI + id)
# write to file
text_file = open(outputdir + filename, "wt")
n = text_file.write(factory.toString(objLA, compact=False))
text_file.close()
selectOptions.append( ( objProp["title"] + " (" + filename + ")" , filename))
# display title and table for illustration
display(objProp["title"])
display(pd.DataFrame(objProp, index=[0]))
'Tower of the Cathedral at Sens'
id | accession_number | title | date_created | date_created_earliest | date_created_latest | physical_medium | physical_dimensions | creator | credit_line | classification | collection | image_url | homepage | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 70238 | 1987.73.2 | Tower of the Cathedral at Sens | c. 1845 | 1845 | 1845 | pen and brown ink, brush and black ink, black ... | sheet: 40.7 x 30.6 cm (16 x 12 1/16 in.) | {'id': 'https://www.nga.gov/collection/creator... | Gift of William B. O'Neal | Drawing | CG-E | https://api.nga.gov/iiif/49a6128c-8d5a-4b00-be... | https://www.nga.gov/collection/art-object-page... |
'Tree Study'
id | accession_number | title | date_created | date_created_earliest | date_created_latest | physical_medium | physical_dimensions | creator | credit_line | classification | collection | image_url | homepage | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 70367 | 1988.20.38 | Tree Study | mid-1850s | 1845 | 1855 | pen and black ink with blue-gray and gray wash... | overall: 28.4 x 38.1 cm (11 3/16 x 15 in.) | {'id': 'https://www.nga.gov/collection/creator... | Gift of John Nichols Estabrook and Dorothy Coo... | Drawing | CG-E | https://api.nga.gov/iiif/9310c903-7099-4138-b3... | https://www.nga.gov/collection/art-object-page... |
'The Garden of San Miniato near Florence'
id | accession_number | title | date_created | date_created_earliest | date_created_latest | physical_medium | physical_dimensions | creator | credit_line | classification | collection | image_url | homepage | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 72870 | 1991.88.1 | The Garden of San Miniato near Florence | 1845 | 1845 | 1845 | watercolor and pen and black ink, heightened w... | Overall: 34.2 x 49.2 cm (13 7/16 x 19 3/8 in.)... | {'id': 'https://www.nga.gov/collection/creator... | Patrons' Permanent Fund | Drawing | CG-E | https://api.nga.gov/iiif/f6ef48d3-3512-4f46-ac... | https://www.nga.gov/collection/art-object-page... |
'Ornamental Study with Acanthus Motif for "The Stones of Venice"'
id | accession_number | title | date_created | date_created_earliest | date_created_latest | physical_medium | physical_dimensions | creator | credit_line | classification | collection | image_url | homepage | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 76140 | 1995.52.158 | Ornamental Study with Acanthus Motif for "The ... | 1849 | 1849 | 1849 | pen and brown ink with watercolor and graphite... | overall: 20.1 x 16.6 cm (7 15/16 x 6 9/16 in.) | {'id': 'https://www.nga.gov/collection/creator... | Gift of William B. O'Neal | Drawing | CG-E | https://api.nga.gov/iiif/bc567179-9c1e-4493-b7... | https://www.nga.gov/collection/art-object-page... |
Select an artwork from the dropdown to view
try:
import ipywidgets
except:
%pip install ipywidgets
import ipywidgets
from ipywidgets import Layout, FileUpload
from IPython.display import display, IFrame, HTML, Image
import os
try:
import json
except:
%pip install json
import json
from IPython.core.display import Javascript
def dropdown_eventhandler(change):
with open('./src/js/visld.js', 'r') as _jscript:
code = _jscript.read() + "var file = '" + outputdir + change.new + "';var selector = '#visnga';visjsonld(file, selector); "
display(Javascript(code))
with open( outputdir + "/" + change.new) as json_file:
artwork = json.load(json_file)
if ("representation" in artwork):
image = artwork["representation"][0]["id"]
display(Javascript("document.getElementById('artworknga').src = '" + image + "';"))
else:
display(Javascript("document.getElementById('artworknga').src = '';"))
selectObject = ipywidgets.Dropdown(options=selectOptions)
selectObject.observe(dropdown_eventhandler, names='value')
display(selectObject)
Dropdown(options=(('Please select an artwork', ''), ('Tower of the Cathedral at Sens (70238.json)', '70238.jso…
The Cleveland Museum of Art (CMA) has published its collection data in a GitHub Repository.
There is a single artwork by John Ruskin in the Cleveland Museum of Art (CMA) collection data available.
The extract this record, the following method was used:
from IPython.display import YouTubeVideo, HTML
display(HTML("<h4>Video - Using OpenRefine to extract Ruskin record from CMA data</h4>"))
YouTubeVideo('npVMbybZ3p8', width=1024, height=576)
The following table shows the relevant collection input data for illustration, and a digital image of the artwork is shown beneath.
# baseURI for JSON-LD document
baseURI = "https://clevelandart.org/art/"
file = './data/cma/input/ruskin.csv'
#mpg = pd.read_csv(file)
#mpg.head()
display(pd.DataFrame(pd.read_csv(file), index=[0]).T)
0 | |
---|---|
id | 154494 |
accession_number | 1989.14 |
share_license_status | CC0 |
tombstone | Budding Sycamore, c. 1876. John Ruskin (Britis... |
current_location | NaN |
title | Budding Sycamore |
title_in_original_language | NaN |
series | NaN |
series_in_original_language | NaN |
creation_date | c. 1876 |
creation_date_earliest | 1871 |
creation_date_latest | 1881 |
creators | John Ruskin (British, 1819-1900), artist |
culture | England, 19th century |
technique | black and gray wash, gouache, and graphite |
support_materials | thick, moderately textured cream wove paper |
department | Drawings |
collection | DR - British |
type | Drawing |
measurements | Sheet: 34.8 x 44.8 cm (13 11/16 x 17 5/8 in.) |
state_of_the_work | NaN |
edition_of_the_work | NaN |
creditline | Andrew R. and Martha Holden Jennings Fund |
copyright | NaN |
inscriptions | signed and inscribed, in brown ink, at lower r... |
exhibitions | CURRENT: The Year in Review for 1989 (Feb 06, ... |
provenance | G.R. Roxburgh (?-?); (Artemis Fine Arts, Londo... |
find_spot | NaN |
related_works | NaN |
former_accession_numbers | [] |
fun_fact | This drawing was used as an illustration in Jo... |
digital_description | The most influential art critic in Britain dur... |
wall_description | The most influential art critic in Britain dur... |
external_resources | {'wikidata': [], 'internet_archive': []} |
citations | Cook, Edward Tyas and Alexander Wedderburn. <e... |
catalogue_raisonne | NaN |
url | https://clevelandart.org/art/1989.14 |
image_web | https://openaccess-cdn.clevelandart.org/1989.1... |
image_print | https://openaccess-cdn.clevelandart.org/1989.1... |
image_full | https://openaccess-cdn.clevelandart.org/1989.1... |
updated_at | 2021-03-27 12:16:10.046000 |
try:
from PIL import Image
except:
%pip install Pillow
from PIL import Image
import requests
url = "https://openaccess-cdn.clevelandart.org/1989.14/1989.14_web.jpg"
image = Image.open(requests.get(url, stream=True).raw)
print("Budding Sycamore")
image
Budding Sycamore