PIXLISE client library for Python
Project description
PIXLISE Client Library for Python
This python package contains what's needed to communicate directly with the PIXLISE back-end and download, manipulate and upload data.
Configuration and Authentication
It's a pip package, so can be installed by doing pip install pixlise_client. To update it pip install --upgrade pixlise_client. Note that when upgrading it seems running the command twice ensures it does actually update, pip seems to not check for updates the first time
Once installed, setting up a client is quite easy. Note that you should get an error about a missing config file!
from pixlise_client import pixlise
pixlib = pixlise.Pixlise()
authErr = pixlib.authenticate()
if len(authErr) > 0:
print(authErr)
exit(1)
Now you can create a config file in the path that the error message indicated (or if you prefer, use an environment variable, again as per the error message). Either way, the contents of the configuration needs to be JSON of the form:
{
"host": "pixlise-host-address",
"user": "your-user-name",
"password": "your-password"
}
Where pixlise-host-address is the same URL you use in the browser for PIXLISE.
Until we're confident all is working please use https://dev.pixlise.org!
Functions
Here you can read about all the functions the library exposes. You will need to call them all through the pixlib object created during the authentication step.
About Error Handling
Note that all of these functions return an actual structure containing the data requested, but if an error occurs, they will return None and the error message will be printed to stdout. Please let us know if you prefer a different way to handle errors.
Basic Scan Data
Listing Scans
scans = listScans(scanId: str)
Retrieves scan summary information (similar to PIXLISE dataset tiles). Note that if you specify a scan id (aka an RTT) it will just return the data for the scan specified, but an empty id retrieves all scans
Getting scan labels
labels = getScanMetaList(scanId: str)
You probably won't need this, the client will call this for some things internally
Getting a summary of scan entries
entries = getScanEntries(scanId: str)
This returns a list of structures, where each member contains a summary of what's available for that entry (aka PMC). This way you can check if a given PMC has Normal spectra, or Beam location information, before querying all the data for the scan.
Getting scan beam locations (x, y, z)
xyzs = getScanBeamLocations(scanId: str)
Returns the beam locations. These are not relative to an image, for that you need to call getScanImageBeamLocations. These are just the x,y,z coordinates.
Housekeeping data
Getting raw housekeeping data, aka scan meta-data
meta = getScanMetaData(scanId: str)
This is the raw version that gets the structure itself. It has indexes that reference the scan labels list. To more easily use housekeeping data, see getScanEntryDataColumns.
Housekeeping data in map form
You can retrieve the list of housekeeping columns using:
cols = getScanEntryDataColumns(scanId: str)
To read an individual column as a map, use:
housekeeping = getScanEntryDataColumn(scanId: str, "f_head_yellow_piece")
This will return it with an array of PMCs, and an array of corresponding values read from the column specified.
Accessing spectrum data
spectrum = getScanSpectrum(scanId: str, pmc: int, spectrumType: int, detector: str)
Note: spectrumType may be:
- 1 = Max Value
- 2 = Bulk Sum
- 3 = Normal
- 4 = Dwell
If you specify Max or Bulk, the pmc becomes irrelevant, you can set it to 0 or something else.
This will return a structure containing the spectrum. The counts field contains the list of counts (1 per channel).
Quantification
Listing quantifications
quants = listScanQuants(scanId: str)
Lists available quants for a scan id.
Raw quantification access
quant = getQuant(quantId: str, SummaryOnly: bool)
If SummaryOnly is True, it won't download the quant data itself, just the summary info about it, who created it, when, input parameters, etc.
Otherwise data is returned, and can be more easily queried using getQuantColumns and getQuantColumn.
Downloading quant data in map form
cols = getQuantColumns(quantId: str)
Prints out all the columns in the quant file
quantMap = getQuantColumn(quantId: str, column: str, detector: str)
Column must be one of the ones returned by getQuantColumns, and detector needs to be A, B or Combined
This will return it with an array of PMCs, and an array of corresponding values read from the column specified.
Regions Of Interest
Listing ROIs
rois = listScanROIs(scanId: str)
Returns all the ROIs associated with a scan. Each item is a structure containing all the properties of the ROI, except the PMCs in the ROI (because the listing may get large). To get the PMCs you need to call getROI
Getting an ROI
roi = getROI(roiId: str, isMist: bool)
Returns the full structure of the specified ROI including its PMC list. isMist needs to be set to True if querying Mist ROIs.
Creating ROIs
You can edit an existing ROI or create a new one with createROI. To edit a new one, retrieve the structure with getROI and change what's required, and call createROI to overwrite it. Note that if you change the id of the ROI in the structure, it won't overwrite.
roiResp = createROI(roiId: ROIItem, isMist: bool)
Note that it returns the created ROI (so if it generated an ROI id, that will be in the returned item).
To create a completely new ROI from scratch, you can call:
roi = allocROI(pmcs: List[int])
This creates a blank ROI structure with the PMC list set to what is specified. Name, Description and other fields can then be set, and it can be pussed to createROI.
For example:
roi = allocROI([7, 8, 10, 11])
roi.name = "peters ROI"
roi.scanId = "500302337"
roi.description = "Lib created ROI"
createdROI = createROI(roi, False)
Image Access
Listing images for scans
This lists images for one or more scans. The reason you can specify more than one scan is to help find images that are associated with all the scans specified.. For images that are associated with more than one scan
images = listScanImages(["scanid1", "scanid2"], mustIncludeAll: bool)
Set mustIncludeAll to True to only return images that have all the scans associated with them. False would return any images that are associated with any of the scans specified.
Image Beam Locations (i,j coordinates)
First you need to know what versions of beam location data are available for a given image. There are multiple versions because our Beam Geometry Tool has evolved over time to output more accurate results, but you may want a specific version. To do this, call:
vers = getScanImageBeamLocationVersions(imageName: str)
Note that an image name here is assumed to be the scan id, a "/" and the image file name, for example: 500302337/PCW_1377_0789190464_000RCM_N064227850030233700030LUJ01.png
It won't work without the first component of the name.
getScanImageBeamLocationVersions returns all the version numbers available in a list.
To retrieve the beam locations themselves, call:
ijs = getScanImageBeamLocations(imageName: str, scanId: str, version: int)
The scan id here may seem redundant but it's not! A given image may be associated with multiple scans, so here you're saying retrieve the beam locations for Dourbes 1 from an image that contains Dourbes 1 and 2 scan points.
Note that if the version is set to -1, the latest version will be returned.
Energy Calibration
Spectra are returned in terms of counts per channel but sometimes we want to know what energy (in eV) the channel is associated with (see getDiffractionPeaks for example). To retrieve the bulk sum spectrum energy calibration call:
getScanBulkSumCalibration(scanId: str):
This will return one structure per detector containing the energy calibration (start eV aka Offset, eV per channel aka XPERCHAN).
To specify a calibration to use call:
setUserScanCalibration(scanId: str, detector: str, starteV: float, perChanneleV: float):
Note that this is not saved anywhere, it's only stored in memory. This way it's available for subsequent calls to functions in the client that need it - once the client is freed from memory these are gone.
Diffraction data
diffraction = getDiffractionPeaks(scanId: str, calibrationSource: int)
Retrieves the diffraction peaks for the given scan id. Note that calibrationSource can be set to:
- 1 = Bulk Sum
- 2 = User
So calling with calibrationSource=1 will use the calibration retrieved by
getScanBulkSumCalibration, while calibrationSource=2 will use the one specified bysetUserScanCalibration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pixlise_client-0.0.14.tar.gz.
File metadata
- Download URL: pixlise_client-0.0.14.tar.gz
- Upload date:
- Size: 16.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dacb14e2bfe9c5b4c7520078bc23c4f5ba342c5d70be85a39cfabfdb515b819
|
|
| MD5 |
498e75b8a7f0c7b9326cda341f4ad51c
|
|
| BLAKE2b-256 |
50fdacd36dbf182e36e37f409658fd0d9448112cb71da83c458a73ba9f258d13
|
File details
Details for the file pixlise_client-0.0.14-py3-none-any.whl.
File metadata
- Download URL: pixlise_client-0.0.14-py3-none-any.whl
- Upload date:
- Size: 16.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b44762b3860eb8060feaa6789d26f55b46946ce093398ce0cfcaed4891d89bd
|
|
| MD5 |
c075fc09ecf30b36083f82b444e54f51
|
|
| BLAKE2b-256 |
580acdb8408278261f3f48a03170875b6f449359bf1e3b3bd9dc0f9a6959d30c
|