### Install NMRGlue from Source (Unix/OSX) Source: https://github.com/jjhelmus/nmrglue/blob/master/INSTALL.txt This command installs NMRGlue using its setup script after dependencies are met. It's the standard method for Unix-like systems. ```bash python setup.py install ``` -------------------------------- ### Install nmrglue and Build Documentation Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/README.txt Commands to install the package in editable mode and trigger the Sphinx build process to generate HTML documentation. ```bash pip install -e . make html ``` -------------------------------- ### Install nmrglue using pip (Development Version) Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/install.md Installs the current development version of nmrglue directly from its GitHub repository using pip. This requires Git to be installed on the system. ```bash $ python -m pip install git+git://github.com/jjhelmus/nmrglue ``` -------------------------------- ### Upload Example Data using googlecode_upload.py Source: https://github.com/jjhelmus/nmrglue/blob/master/examples/README.txt This script demonstrates how to upload example data zip files to the nmrglue Google Code website using the googlecode_upload.py utility. It requires the zip file to be generated first and specifies the project and label for the upload. ```bash googlecode_upload.py -s "Convert Agilent to NMRPipe 1D example data" -p nmrglue -l Example-Data zip_files/example_agilent2pipe_1d.zip ``` -------------------------------- ### Install nmrglue using pip (Latest Stable) Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/install.md Installs the latest stable version of nmrglue from the Python Package Index using pip. This is the recommended method for most users. ```bash $ python -m pip install nmrglue ``` -------------------------------- ### Install nmrglue from Source (Unix/OSX) Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/install.md Installs nmrglue from source code on Unix-like systems (Linux, OS X) after downloading and extracting the source distribution. This method requires build tools and dependencies to be met. ```bash $ python setup.py install ``` -------------------------------- ### Install nmrglue in Google Colab Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/tutorial.md This snippet shows the commands to install the nmrglue library within a Google Colab environment using pip. It also includes commands to download and unpack tutorial files. ```bash import scipy import numpy as np !python -m pip install git+https://github.com/jjhelmus/nmrglue ``` ```bash !wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/nmrglue/tutorial_files.tar ``` ```bash !tar -xvf tutorial_files.tar ``` -------------------------------- ### Clone nmrglue Repository using Git Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/devel/index.md This command clones the latest version of the nmrglue source code from its GitHub repository. It requires Git to be installed on the system. The cloned repository contains the entire project structure, including source files, documentation, tests, and examples. ```bash git clone git://github.com/jjhelmus/nmrglue.git ``` -------------------------------- ### Get Help for nmrglue Function Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/tutorial.md This snippet demonstrates how to use Python's built-in help system to get detailed information about a specific nmrglue function, such as ng.pipe.read. This is useful for understanding function parameters and usage. ```pycon >>> help(ng.pipe.read) ``` -------------------------------- ### GET /nmrglue/process/proc_base/gray Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.process.proc_base.gray.md Calculates an n-bit gray code sequence. ```APIDOC ## GET /nmrglue/process/proc_base/gray ### Description Calculates an n-bit gray code, which is a sequence of numbers where consecutive values differ by only one bit. ### Method GET ### Endpoint /nmrglue/process/proc_base/gray ### Parameters #### Query Parameters - **n** (integer) - Required - The number of bits for the gray code calculation. ### Request Example GET /nmrglue/process/proc_base/gray?n=3 ### Response #### Success Response (200) - **result** (array) - An array containing the n-bit gray code sequence. #### Response Example { "result": [0, 1, 3, 2, 6, 7, 5, 4] } ``` -------------------------------- ### GET /nmrglue/fileio/pipe/create_empty_dic Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.pipe.create_empty_dic.md Initializes a new NMRPipe dictionary object populated with default values for file I/O operations. ```APIDOC ## GET /nmrglue/fileio/pipe/create_empty_dic ### Description Creates a new NMRPipe dictionary structure with default values, which is necessary for creating or modifying NMRPipe files. ### Method GET ### Endpoint /nmrglue/fileio/pipe/create_empty_dic ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **dic** (dict) - A dictionary object containing the default NMRPipe header parameters. #### Response Example { "FDSIZE": 1024, "FDFMT": 1, "FDREAL": 1 } ``` -------------------------------- ### Initialize and Run nmrglue GUI Application Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/examples/apod_viewer_1win.md This snippet demonstrates how to instantiate a custom CanvasFrame, display it, and start the application's main event loop. It serves as the entry point for nmrglue-based GUI applications. ```python """ Create the main window and insert the custom frame """ frame = CanvasFrame() frame.Show(True) return True app = App(0) app.MainLoop() ``` -------------------------------- ### Initialize and Iterate with ndwindow_index Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.analysis.analysisbase.ndwindow_index.md Demonstrates how to instantiate the ndwindow_index class and iterate through an N-dimensional array using window slices and indices. ```python import nmrglue as ng import numpy as np shape = (10, 10) wsize = (3, 3) # Initialize the iterator window_iter = ng.analysis.analysisbase.ndwindow_index(shape, wsize) # Iterate through the array for index, slice_obj in window_iter: print(f"Center Index: {index}, Slice: {slice_obj}") ``` -------------------------------- ### Setup Development Environment with Conda Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/README.txt Creates a new conda environment with all necessary dependencies for building nmrglue documentation, including Sphinx, numpydoc, and the ReadTheDocs theme. ```bash conda create -n nmrglue_dev_38 python=3.8 numpy scipy pytest sphinx pip numpydoc sphinx_rtd_theme -c conda-forge conda activate nmrglue_dev_38 ``` -------------------------------- ### WxPython App Initialization and Main Loop Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/examples/apod_viewer_2win.md This snippet shows the core structure of a WxPython application. It defines an App class inheriting from wx.App, overrides the OnInit method to create and show a main frame, and then starts the application's main event loop. ```python class App(wx.App): """ Wx application """ def OnInit(self): """ Create the main window and insert the custom frame """ frame = CanvasFrame() frame.Show(True) return True app = App(0) app.MainLoop() ``` -------------------------------- ### GET /process/proc_base/int2bin Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.process.proc_base.int2bin.md Converts an integer into its binary string representation. ```APIDOC ## GET /process/proc_base/int2bin ### Description Converts a given integer into a binary string representation with a specified number of digits. ### Method GET ### Endpoint /process/proc_base/int2bin ### Parameters #### Query Parameters - **n** (int) - Required - The integer value to convert. - **digits** (int) - Optional - The number of digits for the resulting binary string. Defaults to 8. ### Request Example GET /process/proc_base/int2bin?n=5&digits=8 ### Response #### Success Response (200) - **result** (string) - The binary representation of the integer. #### Response Example { "result": "00000101" } ``` -------------------------------- ### CLASS: nmrglue.fileio.bruker.bruker_nd Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.bruker.bruker_nd.md Initializes a memory-efficient wrapper for Bruker binary data files. ```APIDOC ## CLASS nmrglue.fileio.bruker.bruker_nd ### Description Emulates an ndarray object for Bruker fid/ser files, allowing for memory-efficient access to data without loading the full file into memory. ### Parameters - **filename** (string) - Required - Filename of Bruker binary file. - **fshape** (tuple) - Required - Shape of NMR data. - **cplex** (boolean) - Required - Flag indicating if direct dimension is complex. - **big** (boolean) - Required - Endianness of data (True for big-endian, False for little-endian). - **isfloat** (boolean) - Optional - Data type of binary file (True for float64, False for int32). - **order** (tuple) - Optional - Ordering of axis against file. ### Methods - **swapaxes(axis1, axis2)**: Returns an object with specified axes interchanged. - **transpose(*axes)**: Returns an object with axes transposed. ``` -------------------------------- ### GET /nmrglue/fileio/pipe/read_1D Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.pipe.read_1D.md Reads a 1D NMRPipe file from the specified path. ```APIDOC ## GET /nmrglue/fileio/pipe/read_1D ### Description Reads a 1D NMRPipe file into the nmrglue data structure. ### Method GET ### Endpoint nmrglue.fileio.pipe.read_1D(filename) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the 1D NMRPipe file to be read. ### Request Example read_1D('test_data.fid') ### Response #### Success Response (200) - **dic** (dict) - The dictionary of parameters extracted from the NMRPipe file. - **data** (ndarray) - The 1D NMR data array. #### Response Example { "dic": { "FDSIZE": 1024, "FDFQIN": 500.0 }, "data": [0.1, 0.2, 0.3, ...] } ``` -------------------------------- ### Initialize Sparky 3D File Reader Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.sparky.sparky_3d.md Demonstrates how to instantiate the sparky_3d class to access a 3D Sparky file. The constructor accepts the filename and an optional axis order parameter. ```python import nmrglue.fileio.sparky as sparky # Initialize the 3D Sparky file reader filename = "data.ucsf" sparky_data = sparky.sparky_3d(filename, order=(0, 1, 2)) # Access attributes print(f"Shape: {sparky_data.shape}") print(f"Dtype: {sparky_data.dtype}") ``` -------------------------------- ### GET /nmrglue/fileio/pipe/get_data Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/pipe.md Retrieves the raw data array from a specified NMRPipe file. ```APIDOC ## GET /nmrglue/fileio/pipe/get_data ### Description Reads and returns the data array contained within an NMRPipe file. ### Method GET ### Endpoint /nmrglue/fileio/pipe/get_data ### Parameters #### Query Parameters - **filename** (string) - Required - The path to the NMRPipe file. ### Response #### Success Response (200) - **data** (array) - The extracted NMR data array. #### Response Example { "data": [0.1, 0.5, 0.9] } ``` -------------------------------- ### Python GUI App: Apodization Viewer with wxPython and Matplotlib Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/examples/apod_viewer_1win.md This Python script demonstrates a GUI application using wxPython and Matplotlib to visualize NMRPipe apodization windows. It allows users to interactively examine different apodization effects. Dependencies include wxPython, numpy, and nmrglue. ```python #!/usr/bin/env python """ An example of using wxPython to build a GUI application using nmrglue This application displays NMRPipe apodization windows. """ import wx import numpy as np import nmrglue as ng import matplotlib # uncomment the following to use wx rather than wxagg #matplotlib.use('WX') #from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas ``` -------------------------------- ### Accessing Spectral Parameters from File Dictionary Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/tutorial.md Demonstrates how to access specific spectral parameters directly from the dictionary generated by the read function. ```python >>> dic["FDF2SW"] 50000.0 >>> dic["FDF1LABEL"] '15N' ``` -------------------------------- ### GET nmrglue.fileio.simpson.read_raw_bin_2d Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.simpson.read_raw_bin_2d.md Reads a 2D raw binary file generated by SIMPSON. ```APIDOC ## GET nmrglue.fileio.simpson.read_raw_bin_2d ### Description Reads a 2D raw binary SIMPSON file into a dictionary of data and parameters. ### Method Internal Function Call ### Endpoint nmrglue.fileio.simpson.read_raw_bin_2d(filename, NP, NI, spe=False) ### Parameters #### Path Parameters - **filename** (string) - Required - Path to the SIMPSON binary file. - **NP** (int) - Required - Number of points in the direct dimension. - **NI** (int) - Required - Number of points in the indirect dimension. #### Query Parameters - **spe** (boolean) - Optional - If True, treats the file as a spectral file. ### Request Example import nmrglue as ng data, dic = ng.fileio.simpson.read_raw_bin_2d('simpson_data.bin', 1024, 256) ### Response #### Success Response (200) - **data** (ndarray) - The 2D NMR data array. - **dic** (dict) - Dictionary containing file parameters. #### Response Example { "data": [[0.1, 0.2], [0.3, 0.4]], "dic": {"parameter": "value"} } ``` -------------------------------- ### GET /nmrglue/process/proc_lp/cof2phase Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.process.proc_lp.cof2phase.md Calculate a signal phase from a model coefficient using the nmrglue library. ```APIDOC ## GET /nmrglue/process/proc_lp/cof2phase ### Description Calculates a signal phase from a given model coefficient (z). ### Method GET ### Endpoint /nmrglue/process/proc_lp/cof2phase ### Parameters #### Query Parameters - **z** (complex/float) - Required - The model coefficient used to calculate the phase. ### Request Example { "z": 0.5+0.5j } ### Response #### Success Response (200) - **phase** (float) - The calculated signal phase in radians. #### Response Example { "phase": 0.785398 } ``` -------------------------------- ### nmrglue.convert.converter Example Conversion Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/convert.md Demonstrates a typical workflow for converting NMR data from Varian format to NMRPipe format using the nmrglue.convert.converter class. This involves reading data, creating a converter object, loading data into the converter, and then extracting data in the target format. ```python import nmrglue as ng # Example conversion from Varian to Pipe vdic, vdata = ng.varian.read("varian_dir") C = ng.convert.converter() C.from_varian(vdic, vdata) pdic, pdata = C.to_pipe() ng.pipe.write("test.fid", pdic, pdata) ``` -------------------------------- ### Read Agilent/Varian FID file using nmrglue Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.varian.read_fid.md This snippet demonstrates how to import a Varian binary file. It returns a dictionary containing file parameters and the raw NMR data as an array. ```python import nmrglue as ng # Read the fid file dic, data = ng.fileio.varian.read_fid('fid_file_path') # Access parameters and data print(dic.keys()) print(data.shape) ``` -------------------------------- ### GET /nmrglue/process/proc_base/exlr Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.process.proc_base.exlr.md Exchanges the left and right halves of a provided NMR data array. ```APIDOC ## POST /nmrglue/process/proc_base/exlr ### Description Exchanges the left and right halves of an array. This is commonly used in NMR data processing to reorder spectral data. ### Method POST ### Endpoint /nmrglue/process/proc_base/exlr ### Parameters #### Request Body - **data** (array) - Required - The NMR data array to be processed. ### Request Example { "data": [1, 2, 3, 4] } ### Response #### Success Response (200) - **data** (array) - The processed array with left and right halves exchanged. #### Response Example { "data": [3, 4, 1, 2] } ``` -------------------------------- ### GET /nmrglue/fileio/varian/get_hyperheader Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.varian.get_hyperheader.md Retrieves and unpacks the 28-byte hypercomplex header block from a Varian file. ```APIDOC ## GET /nmrglue/fileio/varian/get_hyperheader ### Description Reads a 28-byte block header from a Varian file and unpacks it into a list, automatically correcting for endianness. ### Method GET ### Endpoint nmrglue.fileio.varian.get_hyperheader(file) ### Parameters #### Path Parameters - **file** (string) - Required - The path or file object to the Varian data file. ### Request Example { "file": "path/to/varian/data" } ### Response #### Success Response (200) - **header_list** (list) - A list containing 8 unpacked header parameters including status, lpval1, and rpval1. #### Response Example [0, 1, 0, 0, 0, 0.0, 0.0, 0.0, 0.0] ``` -------------------------------- ### GET nmrglue.fileio.bruker.parse_jcamp_value Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.bruker.parse_jcamp_value.md Utility function to parse value text from a Bruker JCAMP-DX file. ```APIDOC ## GET nmrglue.fileio.bruker.parse_jcamp_value ### Description Parses a value string extracted from a Bruker JCAMP-DX file and returns the corresponding Python value. ### Method Function Call ### Endpoint nmrglue.fileio.bruker.parse_jcamp_value(text) ### Parameters #### Path Parameters - **text** (string) - Required - The raw text string extracted from the JCAMP-DX file. ### Request Example text = "123.45" ### Response #### Success Response (200) - **value** (float/int/str) - The parsed value converted from the input text. #### Response Example 123.45 ``` -------------------------------- ### Process 1D NMRPipe Data Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/examples/process_pipe_1d.md This example demonstrates how to process a 1D time-domain NMRPipe file into a 1D frequency-domain NMRPipe file using nmrglue. It includes reading the data, applying spectral processing steps, and writing the output. ```APIDOC ## Process 1D NMRPipe Data ### Description This example shows how nmrglue can be used to process NMR data. In this script, a 1D time-domain NMRPipe file is processed into a 1D NMRPipe frequency-domain file. ### Method This is a Python script utilizing the nmrglue library. There are no direct HTTP methods associated with this script as it operates on local files. ### Endpoint N/A (Local file processing) ### Parameters N/A (Script arguments and internal processing) ### Request Example ```python import nmrglue as ng # read in the file dic, data = ng.pipe.read("nmrpipe_1d/test.fid") # process the direct dimension dic, data = ng.pipe_proc.sp(dic, data, off=0.35, end=0.98, pow=2, c=1.0) dic, data = ng.pipe_proc.zf(dic, data, auto=True) dic, data = ng.pipe_proc.ft(dic, data, auto=True) dic, data = ng.pipe_proc.ps(dic, data, p0=-17.7, p1=-36.0) dic, data = ng.pipe_proc.di(dic, data) # write out processed data ng.pipe.write("1d_pipe.ft", dic, data, overwrite=True) ``` ### Response #### Success Response The script successfully processes the NMR data and writes the output to a file named "1d_pipe.ft". The `dic` and `data` variables hold the processed NMR data dictionary and NumPy array, respectively. #### Response Example No direct API response. The output is a file. **Output File:** `1d_pipe.ft` (Processed NMRPipe data) ``` -------------------------------- ### GET /util/misc/islistsimilar Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.util.misc.islistsimilar.md Compares two lists or iterables to determine if they are similar based on a specified tolerance. ```APIDOC ## GET /util/misc/islistsimilar ### Description Compare two lists or iterables for differences based on a defined tolerance level. ### Method GET ### Endpoint nmrglue.util.misc.islistsimilar(l1, l2, verb=False, dtol=0.5001) ### Parameters #### Path Parameters - **l1** (iterable) - Required - The first list or iterable to compare. - **l2** (iterable) - Required - The second list or iterable to compare. #### Query Parameters - **verb** (boolean) - Optional - If True, prints differences to standard output. Default is False. - **dtol** (float) - Optional - The tolerance level for numerical comparison. Default is 0.5001. ### Request Example islistsimilar([1.0, 2.0], [1.1, 2.1], verb=True, dtol=0.2) ### Response #### Success Response (200) - **result** (boolean) - Returns True if lists are similar within the specified tolerance, False otherwise. ``` -------------------------------- ### Invoke NMRGlue Dictionary GUI Source: https://github.com/jjhelmus/nmrglue/wiki/Gui-to-show-dictionary-values Demonstrates how to trigger the dictionary viewer using either a local GUI module or the built-in nmrglue utility. ```python import gui gui.dic(mydic) ``` ```python from nmrglue.util import dicgui dicgui.dic(dic) ``` -------------------------------- ### POST /nmrglue/fileio/bruker/write_pprog Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.bruker.write_pprog.md Writes a minimal Bruker pulse program dictionary to a specified file path. ```APIDOC ## POST /nmrglue/fileio/bruker/write_pprog ### Description Writes a minimal Bruker pulse program to a file. Note that the resulting file is intended for metadata storage and should not be executed as a real pulse program. ### Method POST ### Endpoint nmrglue.fileio.bruker.write_pprog(filename, dic, overwrite=False) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the file where the pulse program will be written. #### Request Body - **dic** (dict) - Required - A dictionary containing pulse program parameters. - **overwrite** (boolean) - Optional - If True, overwrites existing files. Defaults to False. ### Request Example { "filename": "pulse_prog.txt", "dic": {"parameter": "value"}, "overwrite": false } ### Response #### Success Response (200) - **status** (string) - Confirmation that the file was written successfully. #### Response Example { "status": "success" } ``` -------------------------------- ### GET /process/proc_base/largest_power_of_2 Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.process.proc_base.largest_power_of_2.md Calculates the nearest power of two equal to or larger than the provided input value. ```APIDOC ## GET /process/proc_base/largest_power_of_2 ### Description Find the nearest power of two equal to or larger than a specified value. ### Method GET ### Endpoint /process/proc_base/largest_power_of_2 ### Parameters #### Query Parameters - **value** (int/float) - Required - The value to find the nearest power of two for. ### Request Example GET /process/proc_base/largest_power_of_2?value=10 ### Response #### Success Response (200) - **pw** (int) - The resulting power of 2. #### Response Example { "pw": 16 } ``` -------------------------------- ### GET /nmrglue/fileio/varian/get_blockheader Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.varian.get_blockheader.md Reads and unpacks the 28-byte block header from a Varian NMR data file. ```APIDOC ## GET nmrglue.fileio.varian.get_blockheader ### Description Reads the 28-byte block header from a file object and unpacks it into a list. Endianness is automatically corrected during the process. ### Method GET ### Endpoint nmrglue.fileio.varian.get_blockheader(f) ### Parameters #### Path Parameters - **f** (file object) - Required - The open file object pointing to the Varian data file. ### Response #### Success Response (200) - **list** (list) - A list containing the unpacked header values: [scale, status, index, mode, ctcount, lpval, rpval, lvl, tlt]. #### Response Example [1.0, 1, 0, 0, 1, 0.0, 0.0, 0.0, 0.0] ``` -------------------------------- ### GET /nmrglue/fileio/varian/read_procpar Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.varian.read_procpar.md Reads a Varian procpar file and converts the parameter data into a Python dictionary. ```APIDOC ## GET /nmrglue/fileio/varian/read_procpar ### Description Reads a Varian procpar file from the specified path and returns a dictionary containing the experimental parameters. ### Method GET ### Endpoint nmrglue.fileio.varian.read_procpar(filename) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the Varian procpar file to be read. ### Request Example read_procpar('path/to/procpar') ### Response #### Success Response (200) - **parameters** (dict) - A dictionary where keys are parameter names and values are the corresponding parameter data. #### Response Example { "sw": "6000", "tn": "1H", "at": "2.0" } ``` -------------------------------- ### Class: nmrglue.fileio.sparky.sparky_3d Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.sparky.sparky_3d.md Initializes a memory-efficient interface for reading 3D Sparky files. ```APIDOC ## CLASS nmrglue.fileio.sparky.sparky_3d ### Description Emulates an ndarray object for low-memory reading of 3D Sparky files. Supports slicing, iteration, and axis manipulation. ### Constructor `__init__(filename, order=None)` ### Parameters - **filename** (string) - Required - The path to the 3D Sparky file. - **order** (tuple/list) - Optional - The ordering of axes against the file. Defaults to (0, 1, 2). ### Methods - **swapaxes(axis1, axis2)**: Returns a new object with specified axes interchanged. - **transpose(*axes)**: Returns a new object with axes transposed. ### Usage Example ```python import nmrglue # Initialize the file reader data = nmrglue.fileio.sparky.sparky_3d('test.ucsf') # Access shape information print(data.shape) # Perform slicing slice_data = data[0, :, :] ``` ``` -------------------------------- ### Parameter Transformation with Min/Max Bounds Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/leastsqbound.md Illustrates the transformation between internal and external parameters for optimization when both minimum and maximum bounds are defined. This ensures parameters remain within specified ranges during optimization. ```default p_i = arcsin((2 * (p_e - min) / (max - min)) - 1.) p_e = min + ((max - min) / 2.) * (sin(p_i) + 1.) ``` -------------------------------- ### GET nmrglue.fileio.varian.find_shape Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.varian.find_shape.md Determines the shape of an Agilent/Varian NMR dataset based on the provided procpar dictionary. ```APIDOC ## FUNCTION nmrglue.fileio.varian.find_shape ### Description Determines the shape of an Agilent/Varian file from the procpar dictionary. ### Parameters #### Path Parameters - **pdic** (dict) - Required - The procpar dictionary containing metadata for the Varian/Agilent file. ### Request Example { "pdic": { "np": "1024", "ni": "128" } } ### Response #### Success Response (200) - **shape** (tuple) - The dimensions of the NMR data as determined from the procpar dictionary. #### Response Example { "shape": [1024, 128] } ``` -------------------------------- ### Reading Sparky Save Files with nmrglue (Python) Source: https://context7.com/jjhelmus/nmrglue/llms.txt Demonstrates how to read Sparky .save files using nmrglue, which contain peak lists, assignments, and spectrum viewing parameters. It shows how to access peak data and spectrum viewing settings. ```python import nmrglue as ng import numpy as np # Read Sparky save file with associated spectrum dic, data = ng.sparky.read_savefile( "spectrum.save", spectrum_file="spectrum.ucsf" # Optional: explicitly specify spectrum ) # Access peak information from ornament dictionary ornaments = dic['ornament'] print(f"Number of peaks: {len(ornaments)}") # Extract peak information for peak_id, peak_data in ornaments.items(): # Get peak position (in points) if 'pos' in peak_data: position = peak_data['pos'] print(f"Peak {peak_id}: Position = {position}") # Get peak assignment/label if 'label' in peak_data: label = peak_data['label'] print(f" Label: {label}") # Get peak height if 'height' in peak_data: height = peak_data['height'] print(f" Height: {height}") # Access spectrum viewing parameters view_params = dic.get('view', {}) if 0 in view_params: # First view view = view_params[0] print(f"View center: {view.get('center', 'N/A')}") print(f"View scale: {view.get('scale', 'N/A')}") # Create unit conversion for coordinate transforms uc_x = ng.sparky.make_uc(dic, data, dim=1) uc_y = ng.sparky.make_uc(dic, data, dim=0) ``` -------------------------------- ### GET /nmrglue/fileio/spinsolve/get_udic_from_acqu_dict Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.spinsolve.get_udic_from_acqu_dict.md Retrieves a universal dictionary (udic) structure from a provided Spinsolve acquisition dictionary. ```APIDOC ## GET /nmrglue/fileio/spinsolve/get_udic_from_acqu_dict ### Description This function processes a dictionary containing Spinsolve acquisition parameters and converts it into a standardized universal dictionary (udic) format used by nmrglue. ### Method GET ### Endpoint nmrglue.fileio.spinsolve.get_udic_from_acqu_dict(param: dict) ### Parameters #### Request Body - **param** (dict) - Required - A dictionary containing the acquisition parameters extracted from a Spinsolve file. ### Request Example { "param": { "acqu_param_1": "value", "acqu_param_2": 123 } } ### Response #### Success Response (200) - **udic** (dict) - The resulting universal dictionary containing standardized NMR parameters. #### Response Example { "udic": { "ndim": 1, "sw": [10000.0], "obs": [500.0] } } ``` -------------------------------- ### GET nmrglue.fileio.sparky.read Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.sparky.read.md Reads a Sparky file and returns the associated parameters and NMR data array. ```APIDOC ## GET nmrglue.fileio.sparky.read ### Description Reads a Sparky file from the specified path and returns the parameter dictionary and the NMR data as a NumPy array. ### Method GET ### Endpoint nmrglue.fileio.sparky.read(filename) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the Sparky file to be read. ### Request Example import nmrglue dic, data = nmrglue.fileio.sparky.read('test.ucsf') ### Response #### Success Response (200) - **dic** (dict) - Dictionary containing Sparky file parameters. - **data** (ndarray) - Array containing the NMR data. #### Response Example { "dic": { "key": "value" }, "data": [0.1, 0.2, 0.3] } ``` -------------------------------- ### NMRGlue Unit Conversions Source: https://context7.com/jjhelmus/nmrglue/llms.txt Demonstrates converting between different units such as ppm, Hz, and point indices using nmrglue's unit conversion objects. It also shows how to extract scale arrays and limits for plotting, and how to extract spectral regions. ```python import nmrglue as ng # Example data dictionary and FID data (replace with actual data) dic = {} fid_data = [] # Convert between units point_index = ng.pipe.uc_f2("8.5 ppm") # ppm to point index (integer) point_float = ng.pipe.uc_f2.f(8.5, "ppm") # ppm to point (float) hz_value = ng.pipe.uc_f2.hz(100) # Point 100 to Hz ppm_value = ng.pipe.uc_f2.ppm(100) # Point 100 to ppm # Get scale arrays for plotting ppm_scale = ng.pipe.uc_f2.ppm_scale() # Get limits for matplotlib extent ppm_left, ppm_right = ng.pipe.uc_f2.ppm_limits() # Extract a region using ppm values start = ng.pipe.uc_f2("10.5 ppm") end = ng.pipe.uc_f2("6.0 ppm") # region = data[:, start:end] # Assuming 'data' is defined # Time-domain conversions for FIDs uc_time = ng.pipe.make_uc(dic, fid_data, dim=1) time_ms = uc_time.ms(512) # Point 512 to milliseconds time_scale = uc_time.ms_scale() # Time scale in ms ``` -------------------------------- ### GET /nmrglue/fileio/rnmrtk/make_uc Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.rnmrtk.make_uc.md Creates a unit conversion object based on RNMRTK parameters and data dimensions. ```APIDOC ## GET /nmrglue/fileio/rnmrtk/make_uc ### Description Creates a unit conversion object for a specified dimension of NMR data using RNMRTK parameters. ### Method GET ### Endpoint nmrglue.fileio.rnmrtk.make_uc(dic, data, dim=-1) ### Parameters #### Path Parameters - **dic** (dict) - Required - Dictionary of RNMRTK parameters. - **data** (array) - Required - Array of NMR data. - **dim** (int) - Optional - Dimension number to create unit conversion object for. Default is -1 (last dimension). ### Request Example { "dic": { "parameter_key": "value" }, "data": [0.1, 0.2, 0.3], "dim": 0 } ### Response #### Success Response (200) - **uc** (object) - Unit conversion object for the specified dimension. #### Response Example { "uc": "" } ``` -------------------------------- ### Cluster Peaks for Fitting Source: https://github.com/jjhelmus/nmrglue/wiki/Find and fit peaks in a spectrum Demonstrates how to adjust peak picking parameters to cluster peaks into groups, which can improve fitting stability for complex spectra. ```python peaks = ng.peakpick.pick(data, 25000, c_ndil=100) ``` -------------------------------- ### GET /nmrglue/fileio/pipe/read_lowmem_2D Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.pipe.read_lowmem_2D.md Reads a 2D NMRPipe file or data stream using a memory-efficient approach. ```APIDOC ## GET /nmrglue/fileio/pipe/read_lowmem_2D ### Description Reads a 2D NMRPipe file or NMRPipe data stream using minimal memory. This is useful for handling large datasets without loading the entire file into RAM. ### Method GET ### Endpoint nmrglue.fileio.pipe.read_lowmem_2D(filename) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the 2D NMRPipe file or the data stream to be read. ### Request Example { "filename": "path/to/data.fid" } ### Response #### Success Response (200) - **data** (object) - A low-memory representation of the 2D NMRPipe data. #### Response Example { "status": "success", "data_type": "2D_NMRPipe_LowMem" } ``` -------------------------------- ### CLI: xcpy execution Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/xcpy.md Executes an external CPython script from within the TopSpin environment. ```APIDOC ## CLI: xcpy ### Description Runs an external CPython script using the subprocess module within the TopSpin environment. By default, it passes the current folder, expno, and procno to the script. ### Usage `xcpy [OPTIONS] [SCRIPTNAME]` ### Options - **-h, --help** - Displays help documentation. - **-s, --settings** - Opens a dialog to configure the CPython executable path and script directory. - **-n, --name** - Opens a dialog to specify the path of a script to run. - **-c, --config** - Prints the current configuration file contents. - **-d, --dry-run** - Prints the command that would be executed without running it. - **--no-args** - Prevents passing data folder arguments to the external program. - **--use-shell** - Uses the shell to execute the subprocess command (Warning: security risk). ``` -------------------------------- ### Initialize Canvas Frame (Python) Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/examples/apod_viewer_2win.md Initializes the main WX frame that contains the matplotlib canvas for displaying apodization windows. It sets up the figure, canvas, toolbar, and opens a parameter frame for user input. Dependencies include wxPython, matplotlib.figure.Figure, matplotlib.backends.backend_wx.FigureCanvas, and matplotlib.backends.backend_wxagg.NavigationToolbar2Wx. ```Python class CanvasFrame(wx.Frame): """ WX frame containing a matplotlib canvas where the apodization windows are drawn. Launches the parameter frame where apodization parameter can be set. """ def __init__(self): """ Initialize the frame """ wx.Frame.__init__(self, None, -1, 'Apodization Viewer') self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() # open parameter window win = ParameterFrame(self, -1) win.Show(True) # layout self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT| wx.TOP | wx.GROW) self.sizer.Add(self.toolbar, 0, wx.LEFT| wx.EXPAND) self.SetSizer(self.sizer) self.Fit() ``` -------------------------------- ### GET /nmrglue/fileio/jcampdx/read Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.jcampdx.read.md Reads a JCAMP-DX file and returns a dictionary of parameters and the associated NMR data. ```APIDOC ## GET nmrglue.fileio.jcampdx.read ### Description Reads a JCAMP-DX file. In the case of multiple data sections in the file, parameters of the first NMR SPECTRUM or NMR FID are read to the base level, while others are stored under _datatype_ keys. ### Method GET ### Endpoint nmrglue.fileio.jcampdx.read(filename) ### Parameters #### Path Parameters - **filename** (string) - Required - The path to the JCAMP-DX file to read. ### Response #### Success Response (200) - **dic** (dict) - Dictionary of parameters extracted from the file. - **data** (array/list) - Array of NMR data, or a list of NMR data arrays in order [real, imaginary]. ### Response Example { "dic": { "TITLE": "Example Spectrum", "_datatype_NMR SPECTRUM": {...} }, "data": [0.1, 0.2, 0.3] } ``` -------------------------------- ### GET /nmrglue/fileio/fileiobase/index2trace_flat Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.fileio.fileiobase.index2trace_flat.md Calculates the trace number from a given shape and index assuming a flat structure. ```APIDOC ## GET /nmrglue/fileio/fileiobase/index2trace_flat ### Description Calculates the trace number from shape and index of all indirect dimensions assuming a flat structure. ### Method GET ### Endpoint /nmrglue/fileio/fileiobase/index2trace_flat ### Parameters #### Query Parameters - **shape** (tuple) - Required - The shape of the NMR data array. - **index** (tuple) - Required - The index of the indirect dimensions. ### Request Example GET /nmrglue/fileio/fileiobase/index2trace_flat?shape=(10,10)&index=(1,5) ### Response #### Success Response (200) - **trace_number** (int) - The calculated trace number. #### Response Example { "trace_number": 15 } ``` -------------------------------- ### Iterate over array windows using ndwindow_inside Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.analysis.analysisbase.ndwindow_inside.md This example demonstrates how to initialize the ndwindow_inside class with an array shape and a window size, then iterate through the resulting slices to extract sub-arrays from a 2D NumPy array. ```python import numpy as np from nmrglue.analysis.analysisbase import ndwindow_inside a = np.arange(9).reshape(3,3) for s in ndwindow_inside(a.shape, (2,2)): print(a[s]) ``` -------------------------------- ### GET /analysis/peakpick/find_pseg_slice Source: https://github.com/jjhelmus/nmrglue/blob/master/doc/source/reference/generated/nmrglue.analysis.peakpick.find_pseg_slice.md Finds slices that define a segment in the provided data that exceeds a given threshold. ```APIDOC ## GET /analysis/peakpick/find_pseg_slice ### Description Finds slices which define a segment in data above a specified threshold. ### Method GET ### Endpoint nmrglue.analysis.peakpick.find_pseg_slice(data, location, thres) ### Parameters #### Path Parameters - **data** (array) - Required - The input data array to analyze. - **location** (tuple/int) - Required - The starting location for the segment search. - **thres** (float) - Required - The threshold value above which segments are identified. ### Request Example { "data": [0.1, 0.5, 0.8, 0.2], "location": 1, "thres": 0.4 } ### Response #### Success Response (200) - **slices** (list) - A list of slices defining the segment. #### Response Example { "slices": [1, 2] } ```