Files
bartels-rausch 2ec52b7ee7 Add openBIS sync pipeline; fix nappFileList/nappGenerateSpectra/nappPlot bugs; add importData.m ground script
beamtime/nappFileList.m
- Fix h5 LensMode: translate numeric codes to descriptive text (e.g. 1 ->
  T_HiPPHAXPES) to match what .ibw files already store, applied across all
  three h5read fallback branches, not just the oldest-format one

beamtime/nappGenerateSpectra.m
- Bug fixes

beamtime/nappPlot.m
- Bug fixes

import/importData.m (new)
- Ground script for one beamtime: import (nappFileList,
  nappGenerateSpectra), sample/spot and photon-energy assignment per row
  range, campaign metadata (CustomProperties) and column
  descriptions/units set inline, tidy-up, and export to .csv/.mat/.h5
  (via nappExportH5). Leaves FileList in the workspace for PublishReport.m
  and callOpenbisSync.m to run against afterward.

import/nappExportH5.m (new)
- Export FileList + campaign metadata + raw source files to a
  self-contained HDF5 archive
- Low-level HDF5 API (H5F/H5G/H5D/H5A/H5T/H5S/H5P) to fix
  H5FD_truncate/"too many open files" errors from the top-level
  h5create/h5write functions each reopening the file internally
- Explicit rowIndex attribute per row group, since HDF5 group listing
  order isn't guaranteed to match table row order

openBIS/ (new)
- nappSyncToOpenbis.py, callOpenbisSync.m, testpybis.m, README.md
- openBIS sync pipeline: create-or-update per row matched by $name,
  correct lowercase property codes, timestamp formatting, parent linking,
  raw file upload, plot/photo/video thumbnail embedding, config/engine
  split for maintainability -- see README.md for full details
2026-08-31 14:31:39 +02:00

46 lines
2.2 KiB
Matlab

%% 1. Point at the venv (always needed fresh after restart)
pyenv('Version', '/Users/bartels-rausch/matlab-pybis-venv/bin/python3')
%% 2. Import (first time this session -- guaranteed to read from disk)
py.sys.path().append('/Users/bartels-rausch');
py.importlib.import_module('nappSyncToOpenbis');
%% 3. Your connection details
openbisUrl = "https://openbis-psi.labnotebook.ch";
spaceCode = "5505_BEAMTIMES";
collectionId = [];
objectType = "LAC_EXPERIMENTAL_STEP_BEAMTIME";
parentIdentifier = "/5505_BEAMTIMES/ENTRY783";
verifyCertificates = false;
username = "bartels-rausch_admin";
password = input('openBIS password: ', 's');
clc
%% 4. Rebuild the test data (also fresh, in case anything upstream changed)
testRows = FileList(11:12,:);
metaCols = {'name','folder','creationDate','lastModifiedDatenum','sample', ...
'sampleTemp_dC','cellPressure_mbar','iceTemp_dC','comment','regionName', ...
'scientaLensMode','scientaAcquisitionMode','scientaDwellTime_ms', ...
'scientaPassEnergy_eV','scientaSequenceIterations','scientaRegionIterations', ...
'scientaEkinStep_eV','xRayEkin_eV','xRayEkinRange_eV','scientaEkinRange_eV', ...
'smplX_mm','smplY_mm','smplZ_mm'};
metaCols = intersect(metaCols, testRows.Properties.VariableNames, 'stable');
testTable = testRows(:, metaCols);
testTable.resultImages = repmat({{}}, height(testTable), 1);
rowsJsonTest = jsonencode(table2struct(testTable));
campaignProps = struct( ...
'campaignLocation', FileList.Properties.CustomProperties.campaignLocation, ...
'team', FileList.Properties.CustomProperties.team, ...
'projectName', FileList.Properties.CustomProperties.projectName);
campaignPropsJson = jsonencode(campaignProps);
%% 5. The actual test
resultJson = py.nappSyncToOpenbis.sync_rows(rowsJsonTest, openbisUrl, spaceCode, ...
pyargs('collection', collectionId, 'object_type', objectType, ...
'username', username, 'password', password, ...
'campaign_props_json', campaignPropsJson, 'upload_files', false, ...
'parent_identifier', parentIdentifier, ...
'verify_certificates', verifyCertificates));
results = struct2table(jsondecode(char(resultJson)));
disp(results.message{1})