Source code for jii_multispeq.measurement.notebook
"""Import PhotosynQ Notebooks into a dataframe."""importosimportwarningsimportjsonimportphotosynq_pyasps
[docs]defimport_notebook(source=None):""" Import one or multiple Notebook files exported from the PhotosynQ, Inc. Desktop Application's notebook. .. warning:: The values calculated by Macros in the PhotosynQ, Inc. Desktop Application are not available when imported using this package. Notebook files can be exported according to the `PhotosynQ, Inc. Documentation <https://help.photosynq.com/desktop-application/notebook.html>`_. This package only provides limited support of the Notebook format. :param source: Notebook file(s) :type source: str or list[str] :return: Dataframe or None :rtype: pandas.Dataframe :raises ValueError: if no source file is provided """ifsourceisNone:raiseValueError("No source file provided")ifisinstance(source,str):ifos.path.exists(source):returnps.build_notebook_dataframe(source)else:raiseException("Provided source does not exist")ifisinstance(source,list):data=[]forfileinsource:ifos.path.exists(file):try:withopen(file,'r',encoding='utf-8')asfp:data+=json.load(fp)exceptjson.JSONDecodeError:warnings.warn('Error: Invalid JSON (%s)'%file)continueelse:warnings.warn("Provided source does not exists. Continuing with remaining files")# Write everything to a single filewithopen('__tmp__.json','w',encoding='utf-8')asfp:json.dump(data,fp,indent=2)# Now do the import and delete the temporary file afterwardsdf=ps.build_notebook_dataframe('__tmp__.json')os.remove('__tmp__.json')returndfreturnNone