Skip to content
Snippets Groups Projects
Commit a6742a45 authored by Alessandro Frigeri's avatar Alessandro Frigeri
Browse files

updated examples

parent 199d7161
No related branches found
No related tags found
No related merge requests found
import moondb,sys #!/usr/bin/env python3
import moondb,sys
# Let's setup the data filter # Let's setup the data filter
f = moondb.AnalysisFilter() f = moondb.AnalysisFilter()
...@@ -11,8 +11,10 @@ f.specimenType = ["SOIL"] ...@@ -11,8 +11,10 @@ f.specimenType = ["SOIL"]
results = f.get_results() results = f.get_results()
for r in results: for r in results:
print('\nDataset: ',r.dataset)
print('Lab,Specie,value')
for dr in r.dataResults: for dr in r.dataResults:
print(dr.laboratory,dr.variable,dr.value,dr.unit) print(",".join([dr.laboratory,dr.variable,dr.value+dr.unit]))
%% Cell type:markdown id: tags:
## MoonDB Jupyter notebook workbook
#### Alessandro Frigeri, IAPS/INAF, Rome Italy
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import moondb # First we import the moondb module
%load_ext autoreload
%autoreload 2
%aimport moondb
print(moondb.__file__)
``` ```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
/home/alf/gitwrk/pymoondb/moondb/__init__.py
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
m = moondb.get_missions() # Let's get a list of the missions in MoonDB
mlist = moondb.get_missions()
[m.name for m in mlist]
``` ```
%% Output %% Output
{'name': 'Apollo 11'} ['Apollo 11',
{'name': 'Apollo 12'} 'Apollo 12',
{'name': 'Apollo 14'} 'Apollo 14',
{'name': 'Apollo 15'} 'Apollo 15',
{'name': 'Apollo 16'} 'Apollo 16',
{'name': 'Apollo 17'} 'Apollo 17',
{'name': 'Luna 16'} 'Luna 16',
{'name': 'Luna 20'} 'Luna 20',
{'name': 'Luna 24'} 'Luna 24']
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
f = moondb.Filter() # Now, we want to know how many specimens are available from the Apollo 17 missions
#f.specimenType = ["SOIL"]
f = moondb.SpecimenFilter()
mission = 'Apollo 17'
f.missionName = [ mission ]
results = f.get_results() results = f.get_results()
specimen_list = [r for r in results]
print("MoonDB holds {} specimens from Apollo 17.".format(len(specimen_list)))
``` ```
%% Output
MoonDB holds 2991 specimens from Apollo 17.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
len(results) # Get a list of type of specimen of Apollo 17 available in MoonDB
s_list = [s.specimenType for s in specimen_list]
list(sorted(set(s_list)))
``` ```
%% Output %% Output
37034 ['COMPOSITE',
'ROCK',
'ROCK/Basalt/Ilmenite Basalt',
'ROCK/Basalt/Unclassified Basalt',
'ROCK/Breccia/Fragmental Breccia',
'ROCK/Breccia/Impact Melt Breccia',
'ROCK/Breccia/Regolith Breccia',
'ROCK/Breccia/Unclassified Breccia',
'ROCK/Crustal/Crustal:Cataclasite',
'ROCK/Crustal/Crustal:Norite',
'ROCK/Crustal/Crustal:Troctolite',
'SOIL/Soil:1-2mm',
'SOIL/Soil:2-4mm',
'SOIL/Soil:4-10mm',
'SOIL/Soil:<1mm',
'SOIL/Soil:Unsieved',
'Unknown']
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
an = print(results[0]) #
# Let's see the analyses done on the first specimen
#
s_list = [s for s in specimen_list]
print(len(s_list))
s0 = s_list[0]
an_list = [a for a in s0.get_analyses()]
``` ```
%% Output %% Output
{'analysisCode': '15100,3#3#0158', 'analyzedMaterial': 'WHOLE ROCK', 'comment': '0.97 g, 950C', 'dataset': 'IRVING, 1972#TABLE 1', 'citation': 'IRVING, 1972', 'dataResults': [{'unit': 'ppm', 'laboratory': 'UNKNOWN', 'variable': 'H', 'methodName': 'UNKNOWN', 'methodComment': 'COMBUSTION (NEW LINE, YIELDING LOW BLANKS)', 'value': '90.0', 'methodCode': 'UNKNOWN'}, {'unit': 'per mil', 'laboratory': 'UNKNOWN', 'variable': 'DELTA_D', 'methodName': 'UNKNOWN', 'methodComment': 'COMBUSTION (NEW LINE, YIELDING LOW BLANKS)', 'value': '-554.0', 'methodCode': 'UNKNOWN'}, {'unit': 'ppm', 'laboratory': 'UNKNOWN', 'variable': 'C', 'methodName': 'UNKNOWN', 'methodComment': 'COMBUSTION (NEW LINE, YIELDING LOW BLANKS)', 'value': '99.0', 'methodCode': 'UNKNOWN'}, {'unit': 'per mil', 'laboratory': 'UNKNOWN', 'variable': 'DELTA_C13', 'methodName': 'UNKNOWN', 'methodComment': 'COMBUSTION (NEW LINE, YIELDING LOW BLANKS)', 'value': '7.9', 'methodCode': 'UNKNOWN'}]} 2991
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# now we check the results of the first analysis
#result_of
print(an_list[0].dataResultsObj)
``` ```
%% Output
[result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY (code MC-ICP-MS), result of CACULATED (code CALC)]
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
print(anaobj)
print(mission+" specimen: ",s0.specimenName)
for r in an_list[0].dataResultsObj:
print('Result: {} {} {} ({})'.format(r.variable,r.value,r.unit,r.methodName))
``` ```
%% Output %% Output
None Apollo 17 specimen: 76535,16
Result: Os 8.5 ppb (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Ir 55.0 ppb (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Ru 81.0 ppb (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Pt 54.0 ppb (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Pd 89.0 ppb (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Re 9.0 ppb (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Re187_Os188 5.1 Not Applicable (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: Os187_Os188 0.1511 Not Applicable (MULTICOLLECTOR INDUCTIVELY COUPLED PLASMA MASS SPECTROMETRY)
Result: G_Os(T) -348.0 Not Applicable (CACULATED)
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
``` ```
......
#!/usr/bin/env python3
import moondb import moondb
s_12023 = moondb.get_specimens(sc=['12023'])[0] s_12023 = moondb.get_specimens(sc=['12023'])[0]
#print(s_12023)
child = moondb.get_specimens(sc=['12023,114'])[0]
#print(' A N A L Y S E S ')
a = child.get_analyses()
print(a[0])
a0_results = a[0].dataResultsObj
print('Result: {} {} {}'.format(a0_results[0].variable,a0_results[0].value,a0_results[0].unit,a0_results[0].methodName))
#!/usr/bin/env python3
import moondb,sys import moondb,sys
...@@ -16,22 +18,7 @@ for m in moon_missions: ...@@ -16,22 +18,7 @@ for m in moon_missions:
weight_cum += weight weight_cum += weight
print("MoonDB holds {:.3f} kg of specimens from {}".format(weight/1000.0,m.name)) print("MoonDB holds {:.3f} kg of specimens from {}".format(weight/1000.0,m.name))
print("MoonDB contains a total of {:.3f} kg of specimen from the Moon!".format(weight_cum/1000.0)) print("\nMoonDB contains a total of {:.3f} kg of specimen from the Moon!".format(weight_cum/1000.0))
f = moondb.AnalysisFilter()
f.mission = ["Apollo 11"]
f.analyte = ["Na2O","CaO"]
f.specimenType = ["SOIL"]
results = f.get_results()
for r in results:
for dr in r.dataResults:
print(dr)
#print(dr.laboratory,dr.variable,dr.value,dr.unit)
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
# #
# (c) 2019 Alessandro Frigeri, Istituto Nazionale di Astrofisica # (c) 2019 Alessandro Frigeri, Istituto Nazionale di Astrofisica
# #
# MoonDB Python module # pymoondb: MoonDB Python module
# https://realpython.com/api-integration-in-python/
import sys import sys
import json import json
import urllib.parse import urllib.parse
import urllib3,socket import urllib3,socket
import logging import logging
from dataclasses import dataclass from dataclasses import dataclass, field
from collections import namedtuple from collections import namedtuple
#from dataclasses import dataclass, field
import requests import requests
#import attr #import attr
...@@ -35,6 +37,35 @@ class Landmark: ...@@ -35,6 +37,35 @@ class Landmark:
point = "POINT ({} {})" point = "POINT ({} {})"
return point.format(self.longitude,self.latitude) return point.format(self.longitude,self.latitude)
@dataclass
class Result:
unit: str
laboratory: str
variable: str
methodName: str
methodComment:str
value: str
methodCode: str
def __repr__(self):
return "result of "+self.methodName+" (code "+self.methodCode+")"
@dataclass
class Analysis:
analysisCode: str
analyzedMaterial: str
comment: str
dataset: str
citation: str
dataResults: list = field(default_factory=list)
dataResultsObj: list = field(default_factory=list)
def __repr__(self):
return "Analysis:"+self.analysisCode+" on "+self.analyzedMaterial+" material"
def __str__(self):
return self.analysisCode+" on "+self.analyzedMaterial
@dataclass @dataclass
class Specimen: class Specimen:
specimenCode: str specimenCode: str
...@@ -52,6 +83,28 @@ class Specimen: ...@@ -52,6 +83,28 @@ class Specimen:
pristinityDate: str pristinityDate: str
description: str description: str
def get_analyses(self):
an_obj_list = []
n,an_list = _get_resp('/data/specimen/'+self.specimenCode)
for a in an_list:
r_o_list = []
for r in a['dataResults']:
r_o = Result(**r)
r_o_list.append(r_o)
#print(r_o)
a['dataResultsObj'] = r_o_list
an_o = Analysis(**a)
an_obj_list.append(an_o)
return an_obj_list
@dataclass
class People:
name: str
class SpecimenType: class SpecimenType:
def __init__(self,name): def __init__(self,name):
...@@ -99,8 +152,8 @@ class AnalyisMethod: ...@@ -99,8 +152,8 @@ class AnalyisMethod:
def __init__(self,name): def __init__(self,name):
self.name = name self.name = name
class Analysis: #class Analysis:
__slots__ = ('analysisCode','analyzedMaterial','comment','dataset','citation','dataResults') # __slots__ = ('analysisCode','analyzedMaterial','comment','dataset','citation','dataResults')
class DataResult: class DataResult:
__slots__ = ('unit', 'laboratory', 'variable', 'methodName', 'methodComment', 'value', 'methodCode') __slots__ = ('unit', 'laboratory', 'variable', 'methodName', 'methodComment', 'value', 'methodCode')
...@@ -199,7 +252,6 @@ def get_specimens(sc=None,mn=None,ln=None,sty=None,ste=None): ...@@ -199,7 +252,6 @@ def get_specimens(sc=None,mn=None,ln=None,sty=None,ste=None):
for s in sp_list: for s in sp_list:
# dict unpack # dict unpack
# print(s)
s_o = Specimen(**s) s_o = Specimen(**s)
sp_obj_list.append(s_o) sp_obj_list.append(s_o)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment