The command-line Proposal Manager
Nx5d's pm command provides a small command-line
interface for finding and working with data in an Nx5d
proposal repository.
For the sake of example we're showing off XPP@KMC3 data,
configured using the built-in kmc3pub repository
bookmark. It provides the connection details and URL
conventions needed to access the public KMC3 data repository.
This page walks through a typical session using proposal
252-cw33-13528-pudell.
Selecting the public KMC3 repository
The --repository (or -r) option selects a repository
bookmark. At present, kmc3pub is the built-in bookmark
for the public KMC3-XPP repository:
The bookmark supplies, among other things, the data URL pattern
and the corresponding spice location. It also supplies the KMC3-specific rules for translating between proposal keys and handles and between scan keys and handles.
You therefore normally do not need to specify the S3 URL or its access configuration yourself.
There is however one caveat: the AWS cli2 utility should be installed properly and configured on your computer. Specifically, access to your system's TLS certificate bundle must be configured, as on some Linux distributions it's not always provided by cli2 by default.
If during the following tutorial you receive errors that
point to SSL / TLS certificate errors, usually exporting
the AWS_CA_BUNDLE variable is all you need to fix
them:
Find the proposal
The repository-level ls command lists proposals.
Globs can be used to restrict the listing:
For a broader search, for example:
Array formats (.HDF5, .zarr, ...) are the most commonly used storage formats for scientific data, which is why Nx5d supports them as a primary data source. Storing arrays in S3 storage is a low-effort, low-maintenance, highly secure way to publish scientific data. However, it comes with a downside: a huge performance penalty when sifting through data, in particular during the discovery phase, i.e. listing of repository contents.
For this reason, pmtool's repository model first obtains
the proposal key/handle listing and caches them locally.
Subsequent calls can use that cache with
--from-cache (-C) when a possibly stale but faster
listing is sufficient, for example:
Select a proposal
The proposal can be specified with --proposal (-p):
pm accepts either a proposal key or a proposal
handle.
For KMC3, the repository bookmark knows how to translate
between the two.
If you already have the key, --proposal-key (-q)
explicitly tells pm that no reverse lookup is necessary,
which also speeds up sifting through S3-based repositories:
The proposal command lists scans belonging to the
selected proposal.
Without further arguments, the default glob is *:
You can restrict the result with a scan glob:
Scan matching is attempted against both scan keys and handles.
Inspect scan metadata
By default, proposal ls prints the matching scan keys.
To request additional fields from the repository's scan
objects, use --fields (-f).
The fields are attributes of the underlying repository scan object. This makes it possible to start with a compact key listing and ask for richer metadata only when needed.
For example, a useful first exploration is:
Note that using the --fields switch tends to slow down
lookup, as information for fields other than the keys
generally require a more in-depth data lookup.
Work with a particular scan
Once you know a scan key, --scan (-s) can select it:
A scan glob can also select several scans:
If the string is known to be a scan key, --scan-key (-z)
avoids the key/handle lookup:
The same repository/proposal/scan selection mechanism is used by the scan-level commands.
Inspect or export scan data
The scan command provides operations on the selected scans.
Start with its built-in help:
For example, scan export can print information about the
selected data:
The export operation can also select raw or cooked data
and can write to formats including HDF5, NetCDF and Zarr.
It can also plot suitable one- or two-dimensional data.
A dry run is useful when exploring a workflow before writing anything:
The global -d (or --dry) option tells the processing model
to go through the listing/reading operations without writing
target data.
pm as a command-line self-service data kiosk
pm can also serve as a simple self-service interface for
users at public beamlines, e.g. the XPP@KMC3 beamline of
BESSY-II.
The idea is that a user should not need to know where the
underlying repository lives, how the data are stored, or
how the processing pipeline is assembled.
They select their proposal and scan(s), choose the level
of data they want, and download the result.
There are three useful levels of download:
-
1:1 data clone -- a direct copy of the scan data from the repository. This preserves the repository representation and is useful when the user wants an archival or complete local copy of what was recorded.
-
raw data, i.e. -- unprocessed detector/measurement data, but represented in an xarray-friendly format. This is generally the appropriate choice for users who want to perform their own processing while retaining the structured coordinates and metadata provided by Nx5d, but without any of the data loading hassle.
-
cooked data -- processed data expressed in the physical coordinate system relevant to the experiment. For an XRD experiment, for example, this can mean data transformed from detector coordinates into the appropriate reciprocal-space or other physically meaningful coordinate system. This is intended to be the most immediately useful representation for downstream scientific analysis.
Note in particular that "raw" should not be confused with "1:1 clone." Raw data are already an interpretation of the repository contents: they are unprocessed measurements presented in a structured, xarray-compatible form. Cooked data take the additional step of applying the relevant scientific transformations so that the coordinates represent the physical quantities in which users normally analyse their experiment.
For a beamline kiosk, this makes pm a front end to the
data-processing infrastructure rather than merely a
command-line administration tool.
A typical interaction is as simple as:
pm -r kmc3pub -p 252-cw33-13528-pudell proposal ls
...
pm -r kmc3pub -p 252-cw33-13528-pudell -s r0047 scan export ...
With this, the beamline user does not have to understand the
distinction between the repository's storage model and the
scientific representation they ultimately need.
pm provides the machinery for resolving the proposal and
scan and for applying the appropriate repository and processing
configuration.
From pm to Python
The main purpose of pm is to make repository discovery and selection,
and proposal/scan resolution, conveniently accessible from
any Python-capable computer.
Once a scan has been identified, the same Nx5d URL can be used
from Python.
For the KMC3 public repository, the URL convention is:
Thus, conceptually, a scan from this proposal has a URL of the form:
Nx5d's existing KMC3 workflow uses scan URLs as the bridge between repository data and higher-level XRD processing.
A practical exploration sequence
For a new dataset, the following sequence is a useful starting point:
# 1. Find the proposal
pm -r kmc3pub repo ls '252-cw33-13528-pudell'
# 2. List its scans
pm -r kmc3pub -p 252-cw33-13528-pudell proposal ls
# 3. List keys and handles
pm -r kmc3pub \
-p 252-cw33-13528-pudell \
proposal ls '*' -f key,handle
# 4. Inspect one scan
pm -r kmc3pub \
-p 252-cw33-13528-pudell \
-s <scan> scan export -i
# 5. Export selected data if required
pm -r kmc3pub \
-p 252-cw33-13528-pudell \
-s <scan> \
scan export -f cooked -o <output>
The important distinction is that repo operates on proposals,
proposal operates on the scans belonging to a proposal,
and scan operates on the actual scan data.
The repository bookmark supplies the defaults that connect all
three levels.
Using other data repositories
The principle is applicable to any data repository, not
just XPP@KMC3.
The --url and --spice-url arguments can be used to
point pm directly to a repository:
pm --url s3://kmc3pub-data/{proposal}/{proposal}.zarr#{scan} \
--spice-url s3://kmc3pub-data/{proposal}/spice \
repo ls 252-cw33-13528-pudell
Note that spice and data repositories don't necessarily need
to share the same URL base.
Configurations where a public data repository is used together
with a local spice repository file:///..., which can then be
altered at will, are particularly useful for data reusability.
Summary
For public KMC3 data, the usual starting point is simply:
From there, select a scan, use scan operations to inspect or
export it, or carry its Nx5d URL into Python-based XRD analysis.