import os, time, sys, hashlib from datetime import datetime from fairgraph import brainsimulation, KGClient, base, uniminds from fairgraph.analysis import AnalysisActivity, AnalysisScript, AnalysisConfiguration, AnalysisResult, Person # needs to have HBP_AUTH_TOKEN set as a bash variable client = KGClient(os.environ["HBP_AUTH_TOKEN"]) if sys.argv[-1] == 'Fetch': analysis = AnalysisActivity.by_name( 'parameter configuration of toy analysis in demo notebook', client) # data = uniminds.Dataset.list(client, size=20)[-1] # print(data) # analysis_config = AnalysisConfiguration.by_name('parameter configuration of toy analysis in demo notebook', client) # analysis_config.download('./', client) # print(analysis_config.config_file) elif sys.argv[-1] == 'Fetch-Pipeline': result = AnalysisResult.by_name('Result 2', client) print(result) def provenance_tracking_of_result(analysis_result, with_activities=True): """ """ Provenance_loop_continues = True GENERATING_ENTITIES_BY_LAYER = [[analysis_result]] while Provenance_loop_continues:
import requests import numpy as np import matplotlib.pyplot as plt from fairgraph.commons import BrainRegion, Species, CellType from fairgraph.electrophysiology import PatchedCell, Trace from fairgraph import KGClient from fairgraph.base import KGQuery from fairgraph.minds import Dataset import pytest token = os.environ.get("HBP_AUTH_TOKEN", None) if token: client = KGClient(token, nexus_endpoint="https://nexus.humanbrainproject.org/v0") @pytest.mark.skip("comment this out to run the test") @pytest.mark.skipif( token is None, reason="No token provided. Please set environment variable HBP_AUTH_TOKEN") def test_all(): ## Search based on brain region cells_in_ca1 = PatchedCell.list( client, brain_region=BrainRegion("hippocampus CA1")) pprint([cell.brain_location for cell in cells_in_ca1]) ### Download the recorded data for one of these cells
import os, time from datetime import datetime from fairgraph import brainsimulation, KGClient, base, uniminds # needs to have HBP_AUTH_TOKEN set as a bash variable dev = False if dev: client = KGClient( os.environ["HBP_AUTH_TOKEN"], nexus_endpoint='https://nexus-int.humanbrainproject.org/v0') else: client = KGClient(os.environ["HBP_AUTH_TOKEN"]) ############################################### ### Downloading the (toy) Model of the demo ### ############################################### # The model source code is available in a public container at CSCS container_url = 'https://object.cscs.ch/v1/AUTH_c0a333ecf7c045809321ce9d9ecdfdea/simulation_result_demo' if not os.path.isfile('model_script.py'): os.system( 'wget https://object.cscs.ch/v1/AUTH_c0a333ecf7c045809321ce9d9ecdfdea/simulation_result_demo/model/model_script.py' ) ############################################### ### Documenting Model Metadata ################ ############################################### ## --> building a model instance (version) from those metadata my_model = brainsimulation.ModelInstance( name='Toy model#%s of neural network dynamics for demo purpose' %
""" import os, time from datetime import datetime import csv import logging import pandas as pd from fairgraph import uniminds, KGClient, minds logging.basicConfig(filename="to_knowledge_graph.log", filemode='a', level=logging.DEBUG) logger = logging.getLogger("nar") token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJicC1vaWRjIn0.eyJleHAiOjE1ODQwMzEwMTgsInN1YiI6IjMwODEwNSIsImF1ZCI6WyIzMjMxNDU3My1hMjQ1LTRiNWEtYjM3MS0yZjE1YWNjNzkxYmEiXSwiaXNzIjoiaHR0cHM6XC9cL3NlcnZpY2VzLmh1bWFuYnJhaW5wcm9qZWN0LmV1XC9vaWRjXC8iLCJqdGkiOiI2N2Y2OTMwNy1lNzc5LTQzMTItOWMyYS1hNTM2M2E2ODgyNTYiLCJpYXQiOjE1ODQwMTY2MTgsImhicF9rZXkiOiJhN2QwNmFlZTMyOGI3YjkzNTc3OTUxNzU2Mjk2ODc3YjE4YzRmYTFjIn0.A04N8tLAr-UW6R7W3b-yzuNrW7DI4vsDULH0SJNr7cTvrvMTtkfoQkvWM-JFz3BvegXjXAxzs4lF5wMQhqSWtCShkpwnNsqa9elr2b-xfGVoYluAaQc2TU2ubNbI0VD72kZ5ircliV00L60dXyYuLGdNUz5reM9f0QS4Sw0hiDA" client = KGClient(token, nexus_endpoint='https://nexus-int.humanbrainproject.org/v0') # # Load the Metadata Form # > Metadata is loaded from a CSV file and saved as key: value entries in a dictionary # In[26]: reader = csv.reader(open('test_dataset.csv', 'r')) data = {} for row in reader: k, v = row data[k.lower().strip().replace(" ", "_")] = v data = {k: None if not v else v for k, v in data.items()} # replace empty values with None
A sample of brain tissue. """ _path = "/core/tissuesample/v1.0.0" type = ["uniminds:Tissuesample"] fields = ( Field("alternatives", KGObject, "https://schema.hbp.eu/inference/alternatives", required=False, multiple=True), Field("identifier", basestring, "http://schema.org/identifier", required=False, multiple=True), Field("name", basestring, "http://schema.org/name", required=False, multiple=False), Field("subject", Subject, "https://schema.hbp.eu/uniminds/subject", required=False, multiple=False)) def list_kg_classes(): """List all KG classes defined in this module""" classes = [obj for name, obj in inspect.getmembers(sys.modules[__name__]) if inspect.isclass(obj) and issubclass(obj, KGObject) and obj.__module__ == __name__] classes.remove(UnimindsObject) classes.remove(UnimindsOption) return classes if __name__=='__main__': import os from fairgraph import uniminds, KGClient token = os.environ['HBP_token'] client = KGClient(token) for cls in uniminds.list_kg_classes(): print(cls.__name__) # for f in cls.fields: # print(' - %s' % f.name)
""" Script to retrieve/update test data """ import os.path from itertools import cycle import json from fairgraph import KGClient, core, brainsimulation, electrophysiology, minds, uniminds core.use_namespace("neuralactivity") client = KGClient() def save_nexus_query_result(module, cls): path = "/data/{}/?fields=all&size=10&deprecated=False".format(cls.path) response = client._nexus_client._http_client.get(path) fix_fields(response) filename = "{}_list_0_10.json".format(cls.__name__.lower()) local_path = os.path.join("nexus", module.__name__.split(".")[1], filename) if "next" in response["links"]: del response["links"]["next"] with open(local_path, "w") as fp: json.dump(response, fp, indent=4) def save_kg_query_result(module, cls, query_label): query_id = {"simple": cls.query_id, "resolved": cls.query_id_resolved}[query_label]