Demo of the instrument database API
Imports
[1]:
%load_ext autoreload
%autoreload 2
[18]:
from instrumentdatabaseapi import instrumentdatabaseapi as API
Initialize the API
Setup the repository with defaults
[19]:
repo = API.Repository()
Get informations about the repository
[20]:
print(repo)
URL: https://github.com/PaNOSC-ViNYL/instrument_database.git
local_dir: /dev/shm/instrumentDBAPI/
Initialize the repository making a copy in local
[21]:
repo.init(local_repo="./local_repo/")
---------------------------------------------------------------------------
GitCommandError Traceback (most recent call last)
<ipython-input-21-4e641cef086b> in <module>
----> 1 repo.init(local_repo="./local_repo/")
/tmp/instrumentDataBaseAPI/instrumentdatabaseapi/instrumentdatabaseapi.py in init(self, url, local_repo, branch)
53 self.__local_repo = local_repo
54
---> 55 repo = git.Repo.clone_from(self.__url, self.__local_repo, branch=branch)
56 assert not repo.bare
57 sys.path.append(self.__institutes_absdir())
~/.local/lib/python3.6/site-packages/git/repo/base.py in clone_from(cls, url, to_path, progress, env, multi_options, **kwargs)
1109 if env is not None:
1110 git.update_environment(**env)
-> 1111 return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs)
1112
1113 def archive(self, ostream: Union[TextIO, BinaryIO], treeish: Optional[str] = None,
~/.local/lib/python3.6/site-packages/git/repo/base.py in _clone(cls, git, url, path, odb_default_type, progress, multi_options, **kwargs)
1047
1048 log.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout)
-> 1049 finalize_process(proc, stderr=stderr)
1050
1051 # our git command could have a different working dir than our actual
~/.local/lib/python3.6/site-packages/git/util.py in finalize_process(proc, **kwargs)
368 """Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
369 ## TODO: No close proc-streams??
--> 370 proc.wait(**kwargs)
371
372
~/.local/lib/python3.6/site-packages/git/cmd.py in wait(self, stderr)
445 errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
446 log.debug('AutoInterrupt wait stderr: %r' % (errstr,))
--> 447 raise GitCommandError(remove_password_if_present(self.args), status, errstr)
448 # END status handling
449 return status
GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git clone -v --branch=shervin https://github.com/PaNOSC-ViNYL/instrument_database.git ./local_repo/
stderr: 'fatal: destination path './local_repo' already exists and is not an empty directory.
'
[22]:
repo = API.Repository(local_repo="/opt/panosc/instrument_database/")
print(repo)
URL: https://github.com/PaNOSC-ViNYL/instrument_database.git
local_dir: /opt/panosc/instrument_database/
Print list of available institutes
[17]:
repo.ls_institutes()
- ILL
Run the backengine
[33]:
calculator.backengine()
[33]:
0
Look at the data and store as hdf5
[34]:
calculator.data
[34]:
array([[0.07471297, 0.00703423, 0.92835525, ..., 0.83050226, 0.93011749,
0.10575778],
[0.30465388, 0.36400513, 0.48903381, ..., 0.0438568 , 0.39087367,
0.97940832],
[0.61994805, 0.84566645, 0.42535347, ..., 0.94919735, 0.17939005,
0.74872113],
...,
[0.22103305, 0.07844426, 0.8127275 , ..., 0.4273249 , 0.78210725,
0.59653636],
[0.00889755, 0.40566176, 0.33960702, ..., 0.2634355 , 0.34068678,
0.99275201],
[0.99495603, 0.18621833, 0.25057866, ..., 0.33598942, 0.10660242,
0.20565293]])
[35]:
calculator.saveH5(calculator.output_path)
Save the parameters to a human readable json file.
[36]:
parameters.to_json("my_parameters.json")
Save calculator to binary dump.
[37]:
dumpfile = calculator.dump()
Load back parameters
[38]:
new_parameters = Parameters.from_json("my_parameters.json")
[38]:
6000.0
Look ath the photon energy of the restored parameters.
[ ]:
new_parameters.photon_energy
Reconstruct the dumped calculator.
[ ]:
reloaded_calculator = RandomImageCalculator(dumpfile=dumpfile)
Query the data from the reconstructed calculator.
[ ]:
reloaded_calculator.data
Look at the photon energy of the reconstructed calculator.
[39]:
reloaded_calculator.parameters.photon_energy
[39]:
6000.0
[ ]: