-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from h2020charisma/nexusformat
NeXus file format
- Loading branch information
Showing
13 changed files
with
866 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ramanchada2 as rc2\n", | ||
"import matplotlib.pyplot as plt" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"SpeMetadataModel(__root__={'Original file': SpeMetadataFieldModel(__root__='PST10_iR785_OP03_8000msx2.txt')})" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"kwargs = {\"sample\":['PST'], \"provider\" : ['FNMT'], \"OP\":['03'], \"laser_wl\":['785']}\n", | ||
"spe = rc2.spectrum.from_test_spe(**kwargs)\n", | ||
"spe.meta" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{ 'assay_uuid': None,\n", | ||
" 'citation': Citation(year='2022', title='Round Robin 1', owner='FNMT'),\n", | ||
" 'effects': [ EffectArray(endpoint='Raman spectrum', endpointtype=None, result=None, conditions=None, idresult=None, endpointGroup=None, endpointSynonyms=None, sampleID=None, signal=ValueArray(unit=None, values=array([1354.36, 1355.04, 1349.8 , ..., 1031.89, 1031.96, 1031.44]), errQualifier=None, errorValue=None), axes={'x': ValueArray(unit='cm-1', values=array([ 120.111, 120.505, 120.899, ..., 2499.82 , 2499.94 , 2499.98 ]), errQualifier=None, errorValue=None)})],\n", | ||
" 'interpretationCriteria': None,\n", | ||
" 'interpretationResult': None,\n", | ||
" 'investigation_uuid': None,\n", | ||
" 'owner': SampleLink(substance=Sample(uuid='PST'), company=Company(uuid=None, name='Default company')),\n", | ||
" 'parameters': {'E.method': 'Raman spectrometry', 'wavelength': 785},\n", | ||
" 'protocol': Protocol(topcategory='P-CHEM', category=EndpointCategory(code='ANALYTICAL_METHODS_SECTION', term=None, title=None), endpoint=None, guideline=None),\n", | ||
" 'updated': None,\n", | ||
" 'uuid': 'cbf04397-9352-4382-89e1-81be6d99f473'}\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"NXroot('spectrum')" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import pynanomapper.datamodel.ambit as mx\n", | ||
"import numpy as np\n", | ||
"from typing import Dict, Optional, Union, List\n", | ||
"from pynanomapper.datamodel.nexus_utils import to_nexus\n", | ||
"import json \n", | ||
"import nexusformat.nexus.tree as nx\n", | ||
"import pprint\n", | ||
"import uuid\n", | ||
"pp = pprint.PrettyPrinter(indent=4)\n", | ||
"\n", | ||
"\n", | ||
"data_dict: Dict[str, mx.ValueArray] = {\n", | ||
" 'x': mx.ValueArray(values = spe.x, unit=\"cm-1\")\n", | ||
"}\n", | ||
"ea = mx.EffectArray(endpoint=\"Raman spectrum\", \n", | ||
" signal = mx.ValueArray(values = spe.y),\n", | ||
" axes = data_dict)\n", | ||
"#ea.to_json()\n", | ||
"effect_list: List[Union[mx.EffectRecord,mx.EffectArray]] = []\n", | ||
"effect_list.append(ea)\n", | ||
"papp = mx.ProtocolApplication(protocol=mx.Protocol(topcategory=\"P-CHEM\",category=mx.EndpointCategory(code=\"ANALYTICAL_METHODS_SECTION\")),\n", | ||
" effects=effect_list)\n", | ||
"papp.citation = mx.Citation(owner=\"FNMT\",title=\"Round Robin 1\",year=2022)\n", | ||
"papp.parameters = {\"E.method\" : \"Raman spectrometry\" , \"wavelength\" : 785}\n", | ||
"\n", | ||
"papp.uuid = str(uuid.uuid4())\n", | ||
"company=mx.Company(name = \"FNMT\")\n", | ||
"substance = mx.Sample(uuid = \"PST\")\n", | ||
"papp.owner = mx.SampleLink(substance = substance)\n", | ||
"#papp.to_json()\n", | ||
"study = mx.Study(study=[papp])\n", | ||
"\n", | ||
"pp.pprint(papp.__dict__)\n", | ||
"#print(papp.to_json())\n", | ||
"#print(study.to_json())\n", | ||
"nxroot = nx.NXroot()\n", | ||
"study.to_nexus(nxroot)\n", | ||
"nxroot.save(\"spectrum.nxs\",mode=\"w\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def spe2pap(spe:rc2.spectrum.Spectrum):\n", | ||
" effect_list: List[EffectRecord] = []\n", | ||
" effect_list.append(EffectRecord(endpoint=\"Endpoint 1\", unit=\"Unit 1\", loValue=5.0))\n", | ||
" protocol = Protocol(topcategory=\"P-CHEM\",category=EndpointCategory(code=\"ANALYTICAL_METHODS_SECTION\"))\n", | ||
" papp = ProtocolApplication(protocol=protocol,effects=effect_list)\n", | ||
" return papp\n", | ||
"\n", | ||
"\n", | ||
"spe2pap(spe)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spe.plot()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spe.write_nexus(\"nexus_test.cha\",\"entry\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from typing import List\n", | ||
"from pynanomapper.datamodel.ambit import EffectRecord, Protocol, EndpointCategory, ProtocolApplication\n", | ||
"\n", | ||
"effect_list: List[EffectRecord] = []\n", | ||
"\n", | ||
"effect_list.append(EffectRecord(endpoint=\"Endpoint 1\", unit=\"Unit 1\", loValue=5.0))\n", | ||
"effect_list.append(EffectRecord(endpoint=\"Endpoint 2\", unit=\"Unit 2\", loValue=10.0))\n", | ||
"\n", | ||
"papp = ProtocolApplication(protocol=Protocol(topcategory=\"P-CHEM\",category=EndpointCategory(code=\"XYZ\")),effects=effect_list)\n", | ||
"papp" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"papp = ProtocolApplication(effects=effect_list)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"papp.protocol,papp.effects" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pynanomapper.datamodel.ambit import SubstanceRecord,Sample,SampleLink\n", | ||
"SubstanceRecord(name=\"xky\")\n", | ||
"substance=Sample(uuid=\"xxx\")\n", | ||
"SampleLink(substance=substance)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "ramanchada2", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.0" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ | |
find_closest_pairs, | ||
find_closest_pairs_idx, | ||
align, align_shift, | ||
match_peaks | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.