Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymoondb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alessandro Frigeri
pymoondb
Commits
ce6f57e5
Commit
ce6f57e5
authored
Apr 30, 2019
by
Alessandro Frigeri
Browse files
Options
Downloads
Patches
Plain Diff
sistemato
parent
9d519d80
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
moondb.py
+208
-59
208 additions, 59 deletions
moondb.py
notebooks/print.prt
+0
-60
0 additions, 60 deletions
notebooks/print.prt
with
208 additions
and
119 deletions
moondb.py
+
208
−
59
View file @
ce6f57e5
#!/usr/bin/python
#!/usr/bin/python
3
#
#
# Alessandro Frigeri
2019
#
(c) 2019
Alessandro Frigeri
, Istituto Nazionale di Astrofisica
#
#
# MoonDB Python module
# MoonDB Python module
# https://realpython.com/api-integration-in-python/
# https://realpython.com/api-integration-in-python/
import
requests
import
requests
import
json
import
json
import
urllib.parse
from
collections
import
namedtuple
def
_url
(
path
):
class
Mission
:
return
"
http://api.moondb.org
"
+
path
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__str__
(
self
):
return
self
.
name
def
get_specimen
():
class
Landmark
:
pass
def
__init__
(
self
,
name
):
self
.
name
=
name
def
get_specimentype
():
class
Specimen
:
pass
def
__init__
(
self
):
self
.
specimenCode
=
""
self
.
specimenName
=
""
self
.
parentSpecimen
=
""
self
.
childSpecimens
=
""
self
.
specimenType
=
""
self
.
samplingTechnique
=
""
self
.
mission
=
""
self
.
landmark
=
""
self
.
lunarStation
=
""
self
.
returnContainer
=
""
self
.
weight
=
""
self
.
pristinity
=
""
self
.
pristinityDate
=
""
self
.
description
=
""
def
say_hello
(
self
):
print
(
'
Hello Moon!
'
)
def
__str__
(
self
):
return
self
.
specimenName
def
__repr__
(
self
):
return
self
.
specimenName
def
get_mission
():
class
SpecimenType
:
pass
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__str__
(
self
):
return
self
.
name
def
__repr__
(
self
):
return
self
.
name
class
SamplingTechnique
:
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__str__
(
self
):
return
self
.
name
def
__repr__
(
self
):
return
self
.
name
class
AnalyzedMaterial
:
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__str__
(
self
):
return
self
.
name
def
__repr__
(
self
):
return
self
.
name
class
Analyte
:
def
__init__
(
self
,
name
):
self
.
name
=
name
def
__str__
(
self
):
return
self
.
name
def
__repr__
(
self
):
return
self
.
name
class
AnalysisMethod
:
def
__init__
(
self
,
code
,
name
):
self
.
name
=
name
self
.
code
=
code
def
__str__
(
self
):
return
self
.
name
def
__repr__
(
self
):
return
self
.
name
class
AnalyisMethod
:
def
__init__
(
self
,
name
):
self
.
name
=
name
def
_url
(
path
):
print
(
urllib
.
parse
.
quote
(
path
))
return
"
http://api.moondb.org
"
+
urllib
.
parse
.
quote
(
path
)
def
_check_resp
(
resp
):
def
_check_resp
(
resp
):
if
resp
.
status_code
!=
200
:
if
resp
.
status_code
!=
200
:
#raise ApiError('Cannot fetch all objects: {}'.format(resp.status_code))
#raise ApiError('Cannot fetch all objects: {}'.format(resp.status_code))
pass
pass
def
_get_resp
(
path
):
resp
=
requests
.
get
(
_url
(
path
))
_check_resp
(
resp
)
r
=
resp
.
json
()
# To be checked with Peng
if
'
results
'
in
r
:
return
r
[
'
results
'
]
if
'
result
'
in
r
:
return
r
[
'
result
'
]
def
get_specimen
(
sc
=
None
,
mn
=
None
,
ln
=
None
,
sty
=
None
,
ste
=
None
):
'''
Get specimen by:
- specimen code - sc
- mission name - mn
- landmark name - ln
- speciment type - sty
- sampling technique - ste
'''
sp_list
=
[]
if
sc
:
for
s
in
sc
:
spec
=
_get_resp
(
'
/specimen/
'
+
s
)
sp_list
.
extend
(
spec
)
if
mn
:
for
n
in
mn
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
n
)
sp_list
.
extend
(
spec
)
if
ln
:
for
n
in
ln
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
n
)
sp_list
.
extend
(
spec
)
if
sty
:
for
st
in
sty
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
st
)
sp_list
.
extend
(
spec
)
if
ste
:
for
st
in
ste
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
st
)
sp_list
.
extend
(
spec
)
from
collections
import
namedtuple
sp_obj_list
=
[]
for
s
in
sp_list
:
s_obj
=
namedtuple
(
"
Specimen
"
,
s
.
keys
())(
*
s
.
values
())
sp_obj_list
.
append
(
s_obj
)
return
sp_obj_list
def
_json_object_hook
(
d
):
def
_json_object_hook
(
d
):
return
namedtuple
(
'
X
'
,
d
.
keys
())(
*
d
.
values
())
return
namedtuple
(
'
X
'
,
d
.
keys
())(
*
d
.
values
())
def
json2obj
(
data
):
def
json2obj
(
data
):
return
json
.
loads
(
data
,
object_hook
=
_json_object_hook
)
return
json
.
loads
(
data
,
object_hook
=
_json_object_hook
)
def
get_analytes
():
analytes
=
[]
resp
=
requests
.
get
(
_url
(
'
/cv/analytes/
'
))
_check_resp
(
resp
)
for
m_item
in
resp
.
json
()[
'
result
'
]:
analytes
.
append
(
Analyte
(
m_item
[
'
name
'
]
))
return
analytes
def
get_missions
():
def
get_missions
():
missions
=
[]
missions
=
[]
resp
=
requests
.
get
(
_url
(
'
/authorities/missions/
'
))
resp
=
requests
.
get
(
_url
(
'
/authorities/missions/
'
))
_check_resp
(
resp
)
_check_resp
(
resp
)
print
resp
.
json
()[
'
result
'
]
for
m_item
in
resp
.
json
()[
'
results
'
]:
for
m_item
in
resp
.
json
()[
'
result
'
]:
missions
.
append
(
Mission
(
m_item
[
'
name
'
]
))
missions
.
append
(
Mission
(
m_item
[
'
name
'
]
))
print
(
m_item
)
#this_m = json.load( "{'name': 'Apollo 11'}" )
return
missions
return
missions
def
get_missions2
():
## Controlled Vocabularies
resp
=
requests
.
get
(
_url
(
'
/authorities/missions/
'
))
#m2 = json.loads(resp)
def
get_specimentypes
():
print
(
resp
)
st_list
=
[]
return
resp
.
json
()[
'
result
'
]
st
=
_get_resp
(
'
/cv/specimentypes
'
)
for
s
in
st
:
stobj
=
SpecimenType
(
s
[
'
name
'
])
st_list
.
append
(
stobj
)
return
st_list
def
get_samplingtechniques
():
st_list
=
[]
st
=
_get_resp
(
'
/cv/samplingtechniques
'
)
for
s
in
st
:
stobj
=
SamplingTechnique
(
s
[
'
name
'
])
st_list
.
append
(
stobj
)
return
st_list
def
get_analyzedmaterials
():
st_list
=
[]
st
=
_get_resp
(
'
/cv/analyzedmaterials
'
)
for
s
in
st
:
stobj
=
AnalyzedMaterial
(
s
[
'
name
'
])
st_list
.
append
(
stobj
)
return
st_list
def
get_analytes
():
analytes
=
[]
an
=
_get_resp
(
'
/cv/analyzedmaterials
'
)
for
a
in
an
:
analytes
.
append
(
Analyte
(
m_item
[
'
name
'
]
))
return
analytes
def
get_analysismethods
():
am_list
=
[]
am
=
_get_resp
(
'
/cv/analysismethods
'
)
for
a
in
am
:
aobj
=
AnalysisMethod
(
s
[
'
name
'
])
am_list
.
append
(
aobj
)
return
am_list
def
get_landmark
():
def
get_landmark
():
pass
pass
...
@@ -73,11 +234,9 @@ class Filter:
...
@@ -73,11 +234,9 @@ class Filter:
self
.
analyte
=
[]
self
.
analyte
=
[]
self
.
analysisMethod
=
[]
self
.
analysisMethod
=
[]
def
_toJSON
(
self
):
def
_toJSON
(
self
):
#indent=4
return
json
.
dumps
(
self
,
default
=
lambda
o
:
o
.
__dict__
,
sort_keys
=
True
,
separators
=
(
"
,
"
,
"
:
"
))
return
json
.
dumps
(
self
,
default
=
lambda
o
:
o
.
__dict__
,
sort_keys
=
True
,
separators
=
(
"
,
"
,
"
:
"
))
def
get_results
(
self
):
def
get_results
(
self
):
#print self._toJSON()
#print _url('/data/'+self._toJSON() )
resp
=
requests
.
get
(
_url
(
'
/data/
'
+
self
.
_toJSON
()
))
resp
=
requests
.
get
(
_url
(
'
/data/
'
+
self
.
_toJSON
()
))
res_list
=
[]
res_list
=
[]
...
@@ -86,50 +245,40 @@ class Filter:
...
@@ -86,50 +245,40 @@ class Filter:
res_list
.
append
(
rd
)
res_list
.
append
(
rd
)
return
res_list
return
res_list
class
Mission
:
def
__init__
(
self
,
name
):
self
.
name
=
name
class
Specimen
:
def
__init__
(
self
):
self
.
specimenCode
=
""
self
.
specimenName
=
""
self
.
parentSpecimen
=
""
self
.
childSpecimens
=
""
self
.
specimenType
=
""
#self.samplingTechnique":null,"mission":"Apollo 12","landmark":null,"lunarStation":null,"returnContainer":null,"weight":null,"pristinity":null,"pristinityDate":null,"description":null}
class
AnalysisMethos
:
def
__init__
(
self
,
code
,
name
):
self
.
name
=
name
self
.
code
=
code
class
Analyte
:
def
__init__
(
self
,
name
):
self
.
name
=
name
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
m
=
get_missions
()
m
=
get_missions
()
print
m
f
=
Filter
()
f
=
Filter
()
f
.
specimenType
=
[
"
SOIL
"
]
f
.
specimenType
=
[
"
SOIL
"
]
f
.
analyte
=
[
"
H2O
"
,
"
Ti
"
]
f
.
analyte
=
[
"
H2O
"
,
"
Ti
"
]
f
.
mission
=
[
"
Apollo 11
"
]
f
.
mission
=
[
"
Apollo 11
"
]
print
80
*
"
#
"
print
(
80
*
"
#
"
)
#print f.toJSON()
#print f.toJSON()
results
=
f
.
get_results
()
results
=
f
.
get_results
()
for
r
in
results
:
for
r
in
results
:
print
r
print
"
********
"
this_res
=
r
[
'
dataResults
'
][
0
]
this_res
=
r
[
'
dataResults
'
][
0
]
print
this_res
var
=
this_res
[
'
variable
'
]
var
=
this_res
[
'
variable
'
]
val
=
this_res
[
'
value
'
]
val
=
this_res
[
'
value
'
]
unit
=
this_res
[
'
unit
'
]
unit
=
this_res
[
'
unit
'
]
print
var
,
"
:
"
,
val
,
unit
print
(
var
,
"
:
"
,
val
,
unit
)
s
=
get_specimen
(
mn
=
[
'
Apollo 12
'
,
'
Apollo 11
'
])
print
(
len
(
s
))
s1
=
s
[
0
]
m
=
get_missions
()
ml
=
[]
for
mn
in
m
:
ml
.
append
(
mn
.
name
)
s
=
get_specimen
(
mn
=
ml
)
print
(
len
(
s
))
s1
=
s
[
0
]
#s1.say_hello()
#print(type(s1))
#for sp in s:
# print(sp['specimenName'])
#sp_types = get_specimentypes()
#print(sp_types)
This diff is collapsed.
Click to expand it.
notebooks/print.prt
deleted
100644 → 0
+
0
−
60
View file @
9d519d80
Object = cam2map
IsisVersion = "3.6.2 | 2-28-2019"
ProgramVersion = 2016-06-29
ProgramPath = /Users/alf/miniconda2/envs/isis3/bin
ExecutionDateTime = 2019-04-17T15:14:19
HostName = Unknown
UserName = alf
Description = "Convert camera image to a map projection"
Group = UserParameters
MAP = $base/templates/maps/sinusoidal.map
MATCHMAP = false
PIXRES = CAMERA
DEFAULTRANGE = MINIMIZE
LONSEAM = AUTO
INTERP = CUBICCONVOLUTION
WARPALGORITHM = AUTOMATIC
End_Group
Group = Error
Program = cam2map
Class = "USER ERROR"
Code = 2
Message = "Parameter [FROM] must be entered"
File = IsisAml.cpp
Line = 2867
End_Group
End_Object
Object = cam2map
IsisVersion = "3.6.2 | 2-28-2019"
ProgramVersion = 2016-06-29
ProgramPath = /Users/alf/miniconda2/envs/isis3/bin
ExecutionDateTime = 2019-04-17T15:17:02
HostName = Unknown
UserName = alf
Description = "Convert camera image to a map projection"
Group = UserParameters
MAP = $base/templates/maps/sinusoidal.map
MATCHMAP = false
PIXRES = CAMERA
DEFAULTRANGE = MINIMIZE
LONSEAM = AUTO
INTERP = CUBICCONVOLUTION
WARPALGORITHM = AUTOMATIC
End_Group
Group = Error
Program = cam2map
Class = "USER ERROR"
Code = 2
Message = "Parameter [FROM] must be entered"
File = IsisAml.cpp
Line = 2867
End_Group
End_Object
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment