Skip to content

Commit

Permalink
Merge branch 'icat-schema' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
RKrahl committed Nov 23, 2022
2 parents ed45a17 + 5a459f1 commit 25028e0
Show file tree
Hide file tree
Showing 41 changed files with 7,581 additions and 937 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changelog
New features
------------

+ `#73`_, `#106`_: Add support for the ICAT schema 5.0 extensions.

+ `#102`_, `#104`_: Make the obj argument to client.new() case
insensitive.

Expand All @@ -28,6 +30,11 @@ New features
Incompatible changes and deprecations
-------------------------------------

+ The order and arrangement of data objects in the dump file created
by :ref:`icatdump` has been changed. In some cases, older versions
of :ref:`icatingest` will fail to read dump files written by new
versions of :ref:`icatdump`.

+ As a consequence of switching to pathlib for filesystem paths some
return values and variables are now :class:`pathlib.Path` objects
rather then :class:`str`. This affects:
Expand Down Expand Up @@ -74,6 +81,7 @@ Bug fixes and minor changes
+ Some (more) example scripts now require ICAT 4.4.0 or newer.

.. _#66: https://github.com/icatproject/python-icat/issues/66
.. _#73: https://github.com/icatproject/python-icat/issues/73
.. _#74: https://github.com/icatproject/python-icat/issues/74
.. _#75: https://github.com/icatproject/python-icat/pull/75
.. _#77: https://github.com/icatproject/python-icat/issues/77
Expand All @@ -83,6 +91,7 @@ Bug fixes and minor changes
.. _#103: https://github.com/icatproject/python-icat/pull/103
.. _#104: https://github.com/icatproject/python-icat/pull/104
.. _#105: https://github.com/icatproject/python-icat/pull/105
.. _#106: https://github.com/icatproject/python-icat/pull/106


0.21.0 (2022-01-28)
Expand Down
20 changes: 19 additions & 1 deletion doc/examples/add-investigation-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def makeparam(t, pdata):
invsearch = "Investigation[name='%s']" % investigationdata['name']
investigation = client.assertedSearch(invsearch)[0]

instrumentname = data['instruments'][investigationdata['instrument']]['name']
instrsearch = "Instrument[name='%s' %s]" % (instrumentname, facility_const)
instrument = client.assertedSearch(instrsearch)[0]

technique = None
if "technique" in client.typemap:
t = data['instruments'][investigationdata['instrument']]['technique']
if t:
tn = data['techniques'][t]['name']
techsearch = "Technique [name='%s']" % tn
technique = client.assertedSearch(techsearch)[0]

need_dataset_types = set()
need_datafile_formats = set()
for ds in investigationdata['datasets']:
Expand Down Expand Up @@ -146,5 +158,11 @@ def makeparam(t, pdata):
pdata))
dataset.datafiles.append(datafile)

dataset.create()
if 'datasetInstruments' in dataset.InstMRel:
di = client.new("datasetInstrument", instrument=instrument)
dataset.datasetInstruments.append(di)
if 'datasetTechniques' in dataset.InstMRel and technique:
dt = client.new("datasetTechnique", technique=technique)
dataset.datasetTechniques.append(dt)

dataset.create()
24 changes: 24 additions & 0 deletions doc/examples/create-investigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import yaml
import icat
import icat.config
from icat.helper import parse_attr_string
from icat.query import Query

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -116,6 +118,28 @@ def getUser(client, attrs):
if 'instrument' in s.InstRel:
s.instrument = instrument
investigation.shifts.append(s)
if 'investigationFacilityCycles' in investigation.InstMRel:
# ICAT 5.0 or newer
sd = investigation.startDate or investigation.endDate
ed = investigation.endDate or investigation.startDate
if sd and ed:
query = Query(client, "FacilityCycle", conditions={
"startDate": "<= '%s'" % parse_attr_string(ed, "Date"),
"endDate": "> '%s'" % parse_attr_string(sd, "Date"),
})
for fc in client.search(query):
ifc = client.new("investigationFacilityCycle", facilityCycle=fc)
investigation.investigationFacilityCycles.append(ifc)
if 'fundingReferences' in investigation.InstMRel:
for fr in investigationdata['fundingReferences']:
funding_ref = client.new('fundingReference')
initobj(funding_ref, data['fundings'][fr])
try:
funding_ref.create()
except icat.ICATObjectExistsError:
funding_ref = client.searchMatching(funding_ref)
inv_fund = client.new('investigationFunding', funding=funding_ref)
investigation.fundingReferences.append(inv_fund)
investigation.create()
investigation.addInstrument(instrument)
investigation.addKeywords(investigationdata['keywords'])
Expand Down
Loading

0 comments on commit 25028e0

Please sign in to comment.