About

This notebook is a demonstration of integrating the RRAP-IS with a simple model run.

Run all imports

Keep all your imports at the top of a notebook. It allows for easier management.

%%capture
import requests
import os
import sys
import json
from json2html import *
from bs4 import BeautifulSoup
from IPython.display import IFrame, display, HTML, JSON, Markdown, Image
from mdsisclienttools.auth.TokenManager import DeviceFlowManager
import mdsisclienttools.datastore.ReadWriteHelper as IOHelper
from urllib.error import HTTPError
import networkx as nx
import nx_altair as nxa
from networkx.readwrite import json_graph

import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
defaults = dict(width=800, height=600)
hv.opts.defaults(opts.EdgePaths(**defaults), opts.Graph(**defaults), opts.Nodes(**defaults))

import warnings
warnings.filterwarnings(action='once')

Define global variables

Similar to import we like to define notebook variable at the top and reuse them throughout the notebook

data_store = "https://data.testing.rrap-is.com"
data_api = "https://data-api.testing.rrap-is.com"
registry_api = "https://registry-api.testing.rrap-is.com"
prov_api = "https://prov-api.testing.rrap-is.com"
auth_server = "https://auth.dev.rrap-is.com/auth/realms/rrap"
# garbage = "https://frogs.are.green"
base_urls = {'data_api': data_api, 'registry_api': registry_api, 'prov_api': prov_api, 'auth_server': auth_server, 'data_store': data_store}#, 'garbage': garbage}
display(f'Checking base urls')

for key, url in base_urls.items():
    try:
        print(f'Testing - {url}', end="")
        r = requests.get(url)
        r.raise_for_status()
        print(f' - Passed')
    except requests.exceptions.HTTPError as err:
        print(f' - Fail')
        raise SystemExit(err)
    except requests.exceptions.RequestException as e:
        # catastrophic error. bail.
        print(f' - Fail')
        raise SystemExit(e)
'Checking base urls'
Testing - https://data-api.testing.rrap-is.com - Passed
Testing - https://registry-api.testing.rrap-is.com - Passed
Testing - https://prov-api.testing.rrap-is.com - Passed
Testing - https://auth.dev.rrap-is.com/auth/realms/rrap - Passed
Testing - https://data.testing.rrap-is.com - Passed

Authentication

Setup tokens using device authorisation flow against keycloak server

This could result in a browser window being opened if you don't have valid tokens cached in local storage.

Return to Top

local_token_storage = ".tokens.json"

token_manager = DeviceFlowManager(
    stage="TEST",
    keycloak_endpoint=auth_server,
    local_storage_location=local_token_storage
)
Attempting to generate authorisation tokens.

Looking for existing tokens in local storage.

Validating found tokens

Found tokens valid, using.

Endpoint Documentation

Endpoint documentation can be found by appending either /docs or /redoc on the end a base URL.

For example:

Then select from the menu an endpoint function call e.g. /register/mint-dataset

Then append the function call onto the base url e.g. https://data-api.testing.rrap-is.com/register/mint-dataset

Return to Top

Notebook helper functions

Return to Top

from enum import Enum
from enum_switch import Switch

def wrap_html_table(data):
    soup = BeautifulSoup(data)

    ul_tag = soup.find("table")
    div_tag = soup.new_tag("div")
    div_tag['style'] = "width: auto; height: 400px; overflow-y: auto; "
    ul_tag.wrap(div_tag)
    new_tag = soup.new_tag("details")
    div_tag.wrap(new_tag)
    
    tag = soup.new_tag("summary")
    tag.string = "Results"
    soup.div.insert_after(tag)

    return soup.prettify()
    
def json_to_md(response_json):
        json_obj_in_html = json2html.convert( response_json  )
        return wrap_html_table(json_obj_in_html)
    
def handle_request(method, url, params=None, payload=None, auth=None):
    try:
        if params:
            response = requests.request(method, url=url, params=params, auth=auth)
        elif payload:
            response = requests.request(method, url=url, json=payload, auth=auth)
        else:
            response = requests.request(method, url=url, auth=auth)
        # If the response was successful, no Exception will be raised
        response.raise_for_status()

    except HTTPError as http_err:
        print(f'HTTP error occurred: {http_err}')  # Python 3.6
        return {"error": http_err}
    except Exception as err:
        print(f'Other error occurred: {err}')  # Python 3.6
        return {"error": err }
    else:
        return response.json()
        
class ProvType(Enum):
    AGENT = 1
    ACTIVITY = 2
    ENTITY = 3

class ItemType(Enum):
    MODEL = 1
    PERSON = 2
    ORGANISATION = 3
    MODELRUN = 4
    MODEL_RUN_WORKFLOW = 5

class ProvTypeFromItemType(Switch):
    def MODEL(self):
        return ProvType.ENTITY

    def PERSON(self):
        return ProvType.AGENT    

    def ORGANISATION(self):
        return ProvType.AGENT    

    def MODELRUN(self):
        return ProvType.ACTIVITY

    def MODEL_RUN_WORKFLOW(self):
        return ProvType.ENTITY

prov_of_item = ProvTypeFromItemType(ItemType)
provs = [print(prov_of_item(t)) for t in ItemType]

def register_item(payload, item_type, auth):
    prov_type = prov_of_item(item_type)
    postfix = f'/registry/{prov_type.name.lower()}/{item_type.name.lower()}/create'
    endpoint = registry_api + postfix 
    return handle_request("POST", endpoint, None, payload, auth=auth())

def registry_list(item_type, auth):
    prov_type = prov_of_item(item_type)
    postfix = f'/registry/{prov_type.name.lower()}/{item_type.name.lower()}/list'
    endpoint = registry_api + postfix
    return handle_request("GET", endpoint, None, None, auth=auth())

def registry_fetch(params, item_type, auth):
    prov_type = prov_of_item(item_type)
    postfix = f'/registry/{prov_type.name.lower()}/{item_type.name.lower()}/fetch'
    endpoint = registry_api + postfix
    return handle_request("GET", endpoint, params, None, auth=auth())
ProvType.ENTITY
ProvType.AGENT
ProvType.AGENT
ProvType.ACTIVITY
ProvType.ENTITY

Demonstration

This demonstration illustrates how the RRAP-IS system can be integrated within a modelling scenario to use registered project data, upload and register model outputs and discover provenance information (what data was used for a particular model run and what are the associated outputs).

For the demonstration a fictitious model is used, the data is actual RRAP data and the provenance information is only derived from this exercise

Return to Top

Data

Similar to models we should use registered data else we should register new data and then use the registry to obtain the data. We will demonstrate listing existing dataset and registering a new dataset. Finally we will demonstrate using the registry to obtain data for a model run, register the run and the results/outputs from the run along with who (Modeller and Organisation) ran the model.

List existing dataset

auth = token_manager.get_auth
dataset_id = '10378.1/1689073'
postfix = "/registry/items/fetch-dataset"
param = f'handle_id={dataset_id}'
endpoint = data_api + postfix 
response_json = handle_request("GET", endpoint, param, None, auth())
HTML(json_to_md(response_json))
status
success True
details Successfully fetched data for handle '10378.1/1689073'
item
handle 10378.1/1689073
collection_format
author
name Provenance Simulator
email fake.simulator@gmail.com
orcid None
organisation
name Organisation10378.1/1689064
ror None
dataset_info
name (Simulator) Provenance Simulator Fake Dataset
description Used to produce rich provenance demonstrations - no real data.
publisher
name (Simulator) CSIRO
ror None
created_date 2022-08-12
published_date 2022-08-12
license https://creativecommons.org/licenses/by/4.0/
keywords None
version None
rocrate_metadata
@graph
  • datePublished 2022-08-15
    dateCreated 2022-08-15
    @type CreativeWork
    author
    @id record/author
    about
    @id ./
    dateModified 2022-08-15
    @id ro-crate-metadata.json
    conformsTo
    @id https://w3id.org/ro/crate/1.1
  • name Provenance Simulator
    @id record/author
    @type
    • Person
    • ContactPoint
    email fake.simulator@gmail.com
    worksFor
    @id record/author/worksFor
  • name Organisation10378.1/1689064
    @type Organization
    @id record/author/worksFor
  • datePublished 2022-08-12
    identifier 10378.1/1689073
    license
    @id https://creativecommons.org/licenses/by/4.0/
    dateCreated 2022-08-12
    @type Dataset
    name (Simulator) Provenance Simulator Fake Dataset
    publisher
    @id dataset/publisher
    description Used to produce rich provenance demonstrations - no real data.
    @id ./
  • name (Simulator) CSIRO
    @type Organization
    @id dataset/publisher
@context
  • https://w3id.org/ro/crate/1.1/context
  • @vocab https://schema.org/
s3
bucket_name dev-rrap-storage-bucket
path datasets/10378-1-1689073/
s3_uri s3://dev-rrap-storage-bucket/datasets/10378-1-1689073/
created_time 2022-08-15T05:02:07.620589
updated_time 2022-08-15T05:02:07.620589
Results

Register a new dataset

auth = token_manager.get_auth
postfix = "/register/mint-dataset"
payload =  {
  "author": {
    "name": "Andrew Freebairn",
    "email": "andrew.freebairn@csiro.au",
    "orcid": "https://orcid.org/0000-0001-9429-6559",
    "organisation": {
      "name": "CSIRO",
      "ror": "https://ror.org/03qn8fb07"
    }
  },
  "dataset_info": {
    "name": "MVP Demo Dataset",
    "description": "For demonstration purposes",
    "publisher": {
      "name": "Andrew",
      "ror": "https://ror.org/057xz1h85"
    },
    "created_date": "2022-08-05",
    "published_date": "2022-08-05",
    "license": "https://creativecommons.org/licenses/by/4.0/",
    "keywords": [
      "keyword1"
    ],
    "version": "0.0.1"
  }
}
endpoint = data_api + postfix 

response_json = handle_request("POST", endpoint, None, payload, auth())
new_handle = response_json['handle']
HTML(json_to_md(response_json))
status
success True
details Successfully seeded location - see location details.
handle 10378.1/1691465
s3_location
bucket_name dev-rrap-storage-bucket
path datasets/10378-1-1691465/
s3_uri s3://dev-rrap-storage-bucket/datasets/10378-1-1691465/
Results

Uploaded the data associated with the above metadata registry

auth = token_manager.get_auth
IOHelper.upload(new_handle, auth(), "./data/demo_model_input.csv", data_api)
Found dataset: MVP Demo Dataset.

Attempting to upload files to ./data/demo_model_input.csv
Upload complete.
/home/andrew/repo/rrap-demo-blog/.venv_mvp_demo/lib/python3.8/site-packages/mdsisclienttools/datastore/ReadWriteHelper.py:293: ResourceWarning: unclosed <ssl.SSLSocket fd=64, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.31.1.35', 51782), raddr=('52.95.128.222', 443)>
  _upload_files(s3_loc=s3_loc, s3_creds=creds,

Download a registered dataset

Download to a specific directory where the model will be able to use this dataset.

Note: that a folder is specified which will download all files in the specified folder. If a file is specified it will be the only download.

auth = token_manager.get_auth
IOHelper.download('./data/', new_handle, auth(), data_api)
Found dataset: MVP Demo Dataset.

Attempting to download files to ./data/
Download complete.
/home/andrew/repo/rrap-demo-blog/.venv_mvp_demo/lib/python3.8/site-packages/mdsisclienttools/datastore/ReadWriteHelper.py:343: ResourceWarning: unclosed <ssl.SSLSocket fd=64, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.31.1.35', 55976), raddr=('52.95.129.86', 443)>
  _download_files(s3_loc=s3_loc, s3_creds=creds,
/home/andrew/repo/rrap-demo-blog/.venv_mvp_demo/lib/python3.8/site-packages/mdsisclienttools/datastore/ReadWriteHelper.py:343: ResourceWarning: unclosed <ssl.SSLSocket fd=65, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.31.1.35', 55978), raddr=('52.95.129.86', 443)>
  _download_files(s3_loc=s3_loc, s3_creds=creds,

Model

We should be able to discover a model within the registry or we can register a new model. First we will show how to list existing registered models and then we will demonstrate registering a new model. Then we will use the registery to obtain a model.

Note: The model used here is for demonstration purposes, the actual model will/can be more sophisticated.

Return to Top

List all existing models

auth = token_manager.get_auth
response_json = registry_list(ItemType.MODEL, auth)

HTML(json_to_md(response_json))
status
success True
details Successfully listed items.
items
display_name name description documentation_url source_url id created_timestamp updated_timestamp item_category item_subtype record_type
Reefmod Reefmod Modelling fine-scale ecological processes https://github.com/ymbozec/REEFMOD.6.8_GBR/blob/main/README.md https://github.com/ymbozec/REEFMOD.6.8_GBR 10378.1/1691155 1662358267 1662358267 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/raw/main/demomodel.py 10378.1/1691391 1662708388 1662708388 ENTITY MODEL COMPLETE_ITEM
A new test model A new test model A new test model http://thenewmodeltest.com http://thenewmodeltest.com 10378.1/1690558 1662095495 1662095495 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 123456) RRAP-model-commit-123456 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691180 1662427965 1662427965 ENTITY MODEL COMPLETE_ITEM
Test Model 202209051029 Test Model 20220905 A test model http://testmodel.com http://testmodel.com 10378.1/1690562 1662337785 1662337785 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690423 (Simulator) Software Model 10378.1/1690423 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690423 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690423 1661997150 1661997150 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model.git 10378.1/1691432 1662964150 1662964150 ENTITY MODEL COMPLETE_ITEM
eReefs eReefs https://research.csiro.au/ereefs/summary/ https://gbrrestoration.org/wp-content/uploads/2020/09/T14-Environmental-Modelling-of-Large-Scale-SRM_v3.03-3.pdf#page=17 https://github.com/csiro-coasts/EMS/ 10378.1/1691153 1662358260 1662358260 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690360 - Edit One (Simulator) Software Model 10378.1/1690360 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690360 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690360 1661996643 1662011302 ENTITY MODEL COMPLETE_ITEM
IPMF IPMF IPMF private repo at the moment https://github.com/open-AIMS/IPMF/blob/main/README.md https://github.com/open-AIMS/IPMF/ 10378.1/1691157 1662358273 1662358273 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 123456) RRAP-model-commit-123456 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691182 1662428046 1662428046 ENTITY MODEL COMPLETE_ITEM
eReefs eReefs https://research.csiro.au/ereefs/summary/ https://gbrrestoration.org/wp-content/uploads/2020/09/T14-Environmental-Modelling-of-Large-Scale-SRM_v3.03-3.pdf#page=17 https://github.com/csiro-coasts/EMS/ 10378.1/1691404 1662942936 1662942936 ENTITY MODEL COMPLETE_ITEM
Reefmod Reefmod Modelling fine-scale ecological processes https://github.com/ymbozec/REEFMOD.6.8_GBR/blob/main/README.md https://github.com/ymbozec/REEFMOD.6.8_GBR 10378.1/1691406 1662942943 1662942943 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690554 1662095160 1662095160 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690328 - Edit One (Simulator) Software Model 10378.1/1690328 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690328 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690328 1661996515 1662011184 ENTITY MODEL COMPLETE_ITEM
ADRIA ADRIA Yet to be published https://github.com/gbrrestoration/ https://gbrrestoration.org/ 10378.1/1691152 1662358257 1662358257 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690368 (Simulator) Software Model 10378.1/1690368 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690368 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690368 1661996668 1661996668 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 123456) RRAP-model-commit-123456 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691179 1662427897 1662427897 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/raw/main/demomodel.py 10378.1/1691416 1662945073 1662945073 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690546 1662088598 1662088598 ENTITY MODEL COMPLETE_ITEM
CoCoNet CoCoNet model CoCoNet (Coral Community Network) model https://github.com/gbrrestoration/CoCoNet-model https://github.com/gbrrestoration/CoCoNet-model 10378.1/1691116 1662348314 1662348314 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/raw/main/demomodel.py 10378.1/1691396 1662939918 1662939918 ENTITY MODEL COMPLETE_ITEM
RECOM RECOM The Relocatable Coastal Model (RECOM) is designed for non-expert modellers to generate high resolution models over limited area coastal or reef domains within the GBR, and produces hydrodynamic, sediment transport, wave and biogeochemical outputs https://research.csiro.au/ereefs/models/models-about/recom/ https://research.csiro.au/ereefs/models/models-about/recom/ 10378.1/1691154 1662358264 1662358264 ENTITY MODEL COMPLETE_ITEM
CoCoNet CoCoNet Coral Community Network - Great Barrier Reef-scale community model. https://gbrrestoration.org/wp-content/uploads/2020/09/T6-Modelling-Methods-and-Findings_26April_FINAL3.pdf#page=23 https://github.com/gbrrestoration/CoCoNet-model 10378.1/1691407 1662942946 1662942946 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/blob/f691cd77fec118fdc0549860e65e1cbe7625b31d/demo-model.py 10378.1/1691381 1662704070 1662704070 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691118 1662349232 1662349232 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 123456) RRAP-model-commit-123456 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691181 1662428035 1662428035 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model.git 10378.1/1691379 1662702109 1662702109 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691126 1662351848 1662351848 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690537 1662088168 1662088168 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690370 (Simulator) Software Model 10378.1/1690370 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690370 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690370 1661996674 1661996674 ENTITY MODEL COMPLETE_ITEM
ADRIA ADRIA Coral Community Network https://github.com/gbrrestoration/CoCoNet-model/blob/main/README.md https://gbrrestoration.org/ 10378.1/1691402 1662942929 1662942929 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691136 1662352990 1662352990 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/raw/main/demo-model.py 10378.1/1691390 1662707993 1662707993 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/raw/main/demomodel.py 10378.1/1691392 1662708589 1662708589 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model.git 10378.1/1691434 1662965203 1662965203 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690505 1662006136 1662006136 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/blob/f691cd77fec118fdc0549860e65e1cbe7625b31d/demo-model.py 10378.1/1691382 1662705522 1662705522 ENTITY MODEL COMPLETE_ITEM
RECOM RECOM The Relocatable Coastal Model (RECOM) is designed for non-expert modellers to generate high resolution models over limited area coastal or reef domains within the GBR, and produces hydrodynamic, sediment transport, wave and biogeochemical outputs https://research.csiro.au/ereefs/models/models-about/recom/ https://research.csiro.au/ereefs/models/models-about/recom/ 10378.1/1691405 1662942939 1662942939 ENTITY MODEL COMPLETE_ITEM
Test Model 202209051046 Test Model A test model http://thing.com https://thing.com 10378.1/1690564 1662338821 1662338821 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690539 1662088306 1662088306 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690538 1662088247 1662088247 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691129 1662351911 1662351911 ENTITY MODEL COMPLETE_ITEM
CoCoNet CoCoNet Coral Community Network - Great Barrier Reef-scale community model. https://gbrrestoration.org/wp-content/uploads/2020/09/T6-Modelling-Methods-and-Findings_26April_FINAL3.pdf#page=23 https://github.com/gbrrestoration/CoCoNet-model 10378.1/1691156 1662358270 1662358270 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model.git 10378.1/1691442 1662970883 1662970883 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/blob/f691cd77fec118fdc0549860e65e1cbe7625b31d/demo-model.py 10378.1/1691380 1662704064 1662704064 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model.git 10378.1/1691459 1663043853 1663043853 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691124 1662351258 1662351258 ENTITY MODEL COMPLETE_ITEM
Test Model 3 Test Model 3 A test model 3 http://testurl.com http://testurl.com 10378.1/1690559 1662095986 1662095986 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690394 (Simulator) Software Model 10378.1/1690394 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690394 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690394 1661996817 1661996818 ENTITY MODEL COMPLETE_ITEM
ADRIA ADRIA Yet to be published https://github.com/gbrrestoration/ https://gbrrestoration.org/ 10378.1/1691403 1662942932 1662942932 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model 10378.1/1691378 1662701136 1662701136 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model 10378.1/1691377 1662701106 1662701106 ENTITY MODEL COMPLETE_ITEM
ADRIA ADRIA Coral Community Network https://github.com/gbrrestoration/CoCoNet-model/blob/main/README.md https://gbrrestoration.org/ 10378.1/1691151 1662358254 1662358254 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690442 (Simulator) Software Model 10378.1/1690442 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690442 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690442 1661997206 1661997206 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1690536 1662088152 1662088152 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/raw/main/demomodel.py 10378.1/1691423 1662945627 1662945627 ENTITY MODEL COMPLETE_ITEM
Test Model 202209051032 Test Model A test model https://testmodel.com http://testmodel.com 10378.1/1690563 1662337937 1662337937 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model.git 10378.1/1691447 1662971024 1662971024 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690374 (Simulator) Software Model 10378.1/1690374 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690374 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690374 1661996686 1661996686 ENTITY MODEL COMPLETE_ITEM
Test Model Test Model A test model http://thing.com http://testurl.com 10378.1/1690553 1662093885 1662093885 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690412 (Simulator) Software Model 10378.1/1690412 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690412 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690412 1661996873 1661996873 ENTITY MODEL COMPLETE_ITEM
IPMF IPMF IPMF private repo at the moment https://github.com/open-AIMS/IPMF/blob/main/README.md https://github.com/open-AIMS/IPMF/ 10378.1/1691408 1662942949 1662942949 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690391 (Simulator) Software Model 10378.1/1690391 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690391 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690391 1661996808 1661996808 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690434 (Simulator) Software Model 10378.1/1690434 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690434 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690434 1661997181 1661997181 ENTITY MODEL COMPLETE_ITEM
(Simulator) Software Model 10378.1/1690428 (Simulator) Software Model 10378.1/1690428 (Simulator) Fake software model generated by provenance simulation ID 10378.1/1690428 https://github.com/gbrrestoration/prov-simulator https://github.com/gbrrestoration/prov-simulator 10378.1/1690428 1661997165 1661997166 ENTITY MODEL COMPLETE_ITEM
RRAP-IS Demo DEMO Dummy model for demonstartion purposes https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md https://github.com/gbrrestoration/rrap-demo-model/blob/f691cd77fec118fdc0549860e65e1cbe7625b31d/demo-model.py 10378.1/1691386 1662706916 1662706916 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 1234) RRAP-model-commit-1234 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691177 1662426294 1662426294 ENTITY MODEL COMPLETE_ITEM
RRAP-model (repo commit id - 123456) RRAP-model-commit-123456 Example description string https://bitbucket.csiro.au/projects/MAE/repos/pybrat/readme.md https://bitbucket.csiro.au/projects/MAE/repos/pybrat/commits/824fc954c7e85c8b4b94044fc22cdbf83e365735 10378.1/1691178 1662427883 1662427883 ENTITY MODEL COMPLETE_ITEM
seed_items
unparsable_items
total_item_count 69
complete_item_count 69
seed_item_count 0
unparsable_item_count 0
Results

Register a new model

To register a model it first needs to be in a system where it is version and retrievable via that version code. We suggest using GitHub and will demonstrate the use here. Once in a version control system we can register it in the RRAP-IS.

  1. Commit the model to GitHub (This is done outside of the Jupyter env)
  2. Register the model with RRAP-IS Registry
model = [{
    "display_name": "RRAP-IS Demo",
    "name": "DEMO",
    "description": "Dummy model for demonstartion purposes",
    "documentation_url": "https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md",
    "source_url": "https://github.com/gbrrestoration/rrap-demo-model.git"
    }]
auth = token_manager.get_auth
response_json = [register_item(model, ItemType.MODEL, auth) for model in model]
HTML(json_to_md(response_json))
status created_item
success True
details Successfully uploaded the complete item. Return item includes handle id.
display_name RRAP-IS Demo
name DEMO
description Dummy model for demonstartion purposes
documentation_url https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md
source_url https://github.com/gbrrestoration/rrap-demo-model.git
id 10378.1/1691466
created_timestamp 1663050186
updated_timestamp 1663050186
item_category ENTITY
item_subtype MODEL
record_type COMPLETE_ITEM
Results

Or fetch a pre-registered model

param = {
    "id": "10378.1/1691432",
    "seed_allowed": True
}
auth = token_manager.get_auth
response_json = registry_fetch(param, ItemType.MODEL, auth)
HTML(json_to_md(response_json))
status
success True
details Successfully retrieved complete item and parsed into current data model.
item
display_name RRAP-IS Demo
name DEMO
description Dummy model for demonstartion purposes
documentation_url https://github.com/gbrrestoration/rrap-demo-model/blob/main/README.md
source_url https://github.com/gbrrestoration/rrap-demo-model.git
id 10378.1/1691432
created_timestamp 1662964150
updated_timestamp 1662964150
item_category ENTITY
item_subtype MODEL
record_type COMPLETE_ITEM
item_is_seed False
Results

Obtain the newly registered model for use

With the above information download the model

from pathlib import Path
from git import Repo
model_repo = response_json['item']['source_url']
repo_dir = Path("rrapDemoModel")
repo_dir.mkdir(exist_ok=True)
if any(Path(repo_dir).iterdir()):
    print('pull ....')
    repo = Repo(str(repo_dir.resolve()))
    assert not repo.bare
    o = repo.remotes['origin']
    o.pull()
else:
    print('cloning ....')
    repo = Repo.clone_from(model_repo, repo_dir, branch='main')   
print(repo)
pull ....
<git.repo.base.Repo '/home/andrew/repo/rrap-demo-blog/_notebooks/rrapDemoModel/.git'>

Execute the model

import sys
sys.path.insert(0, str(repo_dir.resolve())) 
demo = __import__("demomodel") 

d_demo = demo.demo_model()
d_demo.runtimestep()

Register the outputs

auth = token_manager.get_auth
postfix = "/register/mint-dataset"
payload =  {
  "author": {
    "name": "Andrew Freebairn",
    "email": "andrew.freebairn@csiro.au",
    "orcid": "https://orcid.org/0000-0001-9429-6559",
    "organisation": {
      "name": "CSIRO",
      "ror": "https://ror.org/03qn8fb07"
    }
  },
  "dataset_info": {
    "name": "MVP Demo Outputs",
    "description": "For demonstration purposes",
    "publisher": {
      "name": "Andrew",
      "ror": "https://ror.org/057xz1h85"
    },
    "created_date": "2022-08-05",
    "published_date": "2022-08-05",
    "license": "https://creativecommons.org/licenses/by/4.0/",
    "keywords": [
      "keyword1"
    ],
    "version": "0.0.1"
  }
}
endpoint = data_api + postfix 

response_json = handle_request("POST", endpoint, None, payload, auth())
new_handle = response_json['handle']
HTML(json_to_md(response_json))
status
success True
details Successfully seeded location - see location details.
handle 10378.1/1691467
s3_location
bucket_name dev-rrap-storage-bucket
path datasets/10378-1-1691467/
s3_uri s3://dev-rrap-storage-bucket/datasets/10378-1-1691467/
Results

Upload model outputs

auth = token_manager.get_auth
IOHelper.upload(new_handle, auth(), "readme.txt", data_api)
Found dataset: MVP Demo Outputs.

Attempting to upload files to readme.txt
Upload complete.
/home/andrew/repo/rrap-demo-blog/.venv_mvp_demo/lib/python3.8/site-packages/mdsisclienttools/datastore/ReadWriteHelper.py:293: ResourceWarning: unclosed <ssl.SSLSocket fd=64, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.31.1.35', 59330), raddr=('52.95.130.14', 443)>
  _upload_files(s3_loc=s3_loc, s3_creds=creds,

Register model run

To register a run we first must identify (find within the registry or construct):

  • Workflow definition
  • Input and output dataset and respective templates
  • Modeller
  • Associated Organisation

Will also need to apply Start and End times

Data

Input

  • Dataset id: 10378.1/1691395
  • Dataset template id: 10378.1/1690478

Output

  • Dataset id: 10378.1/1691397
  • Dataset template id: 10378.1/1690478

Modeller

  • id: 10378.1/1691138

Assc Organisation

  • id: 10378.1/1691139

Workflow definition register

As this is the first time this model has been defined it should be registered

workflows = [{
  "display_name": "Demonstration Workflow Definition",
  "version": "0.0.1",
  "software": "10378.1/1691396",
  "automation_schedule": {},
  "input_templates": [
    "10378.1/1690478"
  ],
  "output_templates": [
    "10378.1/1690478"
  ]
}]

auth = token_manager.get_auth
responses_json = [register_item(wf, ItemType.MODEL_RUN_WORKFLOW, auth) for wf in workflows]
HTML(json_to_md(responses_json))
status created_item
success True
details Successfully uploaded the complete item. Return item includes handle id.
display_name Demonstration Workflow Definition
version 0.0.1
software 10378.1/1691396
automation_schedule
input_templates
  • 10378.1/1690478
output_templates
  • 10378.1/1690478
id 10378.1/1691468
created_timestamp 1663050197
updated_timestamp 1663050197
item_category ENTITY
item_subtype MODEL_RUN_WORKFLOW_DEFINITION
record_type COMPLETE_ITEM
Results
auth = token_manager.get_auth
postfix = "/model_run/register_complete"
payload = {
  "start_time": 0,
  "end_time": 1662467929,
  "workflow_definition": {
    "id": "10378.1/1691427"
  },
  "inputs": {
    "datasets": {
      "10378.1/1690478": {
        "template": {
          "id": "10378.1/1690478"
        },
        "dataset_type": "DATA_STORE",
        "dataset": {
          "id": "10378.1/1691395"
        }
      }
    }
  },
  "outputs": {
    "datasets": {
      "10378.1/1690478": {
        "template": {
          "id": "10378.1/1690478"
        },
        "dataset_type": "DATA_STORE",
        "dataset": {
          "id": "10378.1/1691397"
        }
      }
    }
  },
  "associations": {
    "modeller": {
      "id": "10378.1/1691138"
    },
    "requesting_organisation": {
      "id": "10378.1/1691139"
    }
  }
}
endpoint = prov_api + postfix 

response_json = handle_request('POST', endpoint, None, payload, auth())
HTML(json_to_md(response_json))
status
success True
details All successful.
record_info
id 10378.1/1691469
prov_json {"prefix": {"default": "http://hdl.handle.net/"}, "activity": {"10378.1/1691469": {"model_run/10378.1/1691469": true, "item_category": "ACTIVITY", "item_subtype": "MODEL_RUN"}}, "entity": {"10378.1/1691395": {"model_run/10378.1/1691469": true, "item_category": "ENTITY", "item_subtype": "DATASET"}, "10378.1/1691397": {"model_run/10378.1/1691469": true, "item_category": "ENTITY", "item_subtype": "DATASET"}, "10378.1/1691427": {"model_run/10378.1/1691469": true, "item_category": "ENTITY", "item_subtype": "MODEL_RUN_WORKFLOW_DEFINITION", "prov:type": {"$": "prov:Collection", "type": "prov:QUALIFIED_NAME"}}, "10378.1/1690478": {"model_run/10378.1/1691469": true, "item_category": "ENTITY", "item_subtype": "DATASET_TEMPLATE"}, "10378.1/1691396": {"model_run/10378.1/1691469": true, "item_category": "ENTITY", "item_subtype": "MODEL"}}, "agent": {"10378.1/1691138": {"model_run/10378.1/1691469": true, "item_category": "AGENT", "item_subtype": "PERSON"}, "10378.1/1691139": {"model_run/10378.1/1691469": true, "item_category": "AGENT", "item_subtype": "ORGANISATION"}}, "used": {"_:id1": {"prov:activity": "10378.1/1691469", "prov:entity": "10378.1/1691395"}, "_:id3": {"prov:activity": "10378.1/1691469", "prov:entity": "10378.1/1691396"}, "_:id4": {"prov:activity": "10378.1/1691469", "prov:entity": "10378.1/1691427"}}, "wasGeneratedBy": {"_:id2": {"prov:entity": "10378.1/1691397", "prov:activity": "10378.1/1691469"}}, "wasAssociatedWith": {"_:id5": {"prov:activity": "10378.1/1691469", "prov:agent": "10378.1/1691138"}, "_:id6": {"prov:activity": "10378.1/1691469", "prov:agent": "10378.1/1691139"}}, "wasAttributedTo": {"_:id7": {"prov:entity": "10378.1/1691397", "prov:agent": "10378.1/1691138"}}, "hadMember": {"_:id8": {"prov:collection": "10378.1/1691427", "prov:entity": "10378.1/1690478"}, "_:id11": {"prov:collection": "10378.1/1691427", "prov:entity": "10378.1/1691396"}}, "wasInfluencedBy": {"_:id9": {"prov:influencee": "10378.1/1691395", "prov:influencer": "10378.1/1690478"}, "_:id10": {"prov:influencee": "10378.1/1691397", "prov:influencer": "10378.1/1690478"}}}
record
workflow_definition
id 10378.1/1691427
inputs
datasets
10378.1/1690478
template
id 10378.1/1690478
dataset_type DATA_STORE
dataset
id 10378.1/1691395
outputs
datasets
10378.1/1690478
template
id 10378.1/1690478
dataset_type DATA_STORE
dataset
id 10378.1/1691397
associations
modeller
id 10378.1/1691138
requesting_organisation
id 10378.1/1691139
start_time 0
end_time 1662467929
Results

Provenance

As all data, modellers, organisations and activities (specific to producing data used in decisions) are registered in RRAP-IS it is possible to traverse the linage between these entities. This can be useful in discovering what data (or modeller/model/s) was used to produce certain outputs.

Let's explore all entities associated with a modeller

Return to Top

auth = token_manager.get_auth
postfix = "/explore/downstream"
params = {
    "starting_id": "10378.1/1691138",
    "depth": 1
}
endpoint = prov_api + postfix 

response_json = handle_request('GET', endpoint, params, None, auth())
result_graph = response_json["graph"]

networkx_graph = json_graph.node_link_graph(result_graph)
im = hv.Graph.from_networkx(networkx_graph, nx.layout.fruchterman_reingold_layout).opts(tools=['hover','tap'],
                                                                          node_size=10,
                                                                          node_color='item_category',
                                                                          cmap = ['blue','orange', 'green', 'red'],
                                                                          directed=True, 
                                                                          arrowhead_length=0.02,
                                                                          bgcolor='pink')
labels = hv.Labels(im.nodes, ['x', 'y'], 'item_category').opts(opts.Labels(text_font_size='12pt', text_color='blue', xoffset=0, yoffset=0.05, bgcolor='white'))
labels_2 = hv.Labels(im.nodes, ['x', 'y'], 'item_subtype').opts(opts.Labels(text_font_size='8pt', xoffset=0, yoffset=-0.05, bgcolor='white'))
hv_graph = (im * labels * labels_2)

hv.save(hv_graph, 'network.html', backend='bokeh')

HTML("network.html")
<!DOCTYPE html> network