Skip to content

Latest commit

 

History

History
136 lines (101 loc) · 10.2 KB

README.md

File metadata and controls

136 lines (101 loc) · 10.2 KB

SpecUtils

SpecUtils is a library for opening, manipulating, and exporting spectrum files produced by RadioIsotope Identification Devices (RIIDs), Radiation Portal Monitors (RPMs), radiation search systems, Personal Radiation Detectors (PRDs), and many laboratory detection systems. It opens N42 (2006 and 2012 formats), SPE, SPC, CSV, TXT, PCF, DAT, and many more files; altogether more than a 100 file format variants. The library lets you either programmatically access and/or modify the parsed information, or you can save it to any of 13 different formats.

SpecUtils provides the spectrum file format capabilities for Cambio, InterSpec, and number of other applications and websites. The library is written in cross-platform (tested on Windows, macOS, Linux, iOS, and Android) c++ with Python and Java bindings.

Using SpecUtils

If all you need is to convert spectrum files from your detector to a format you can work with, like CSV or N42, try using the command line version of Cambio - this is actually probably the most common way people and programs use SpecUtils.

But if you want to integrate SpecUtils into your program, you will need a c++11 capable compiler, boost (≥1.42), and cmake (≥3.1.). Linking your program to SpecUtils uses the standard CMake syntax, for example in your CMakeLists.txt file you would add the lines:

add_subdirectory( path/to/SpecUtils )
...
target_link_libraries( MyExe PRIVATE SpecUtils )

A minimal program to print out the channel counts of a spectrum file, and then save as a CSV data file, could then be:

#include  <stdlib.h>
#include  <iostream>
#include  "SpecUtils/SpecFile.h"

int main() {
  SpecUtils::SpecFile specfile;
  if( !specfile.load_file("input.n42", SpecUtils::ParserType::Auto) )
    return EXIT_FAILURE;
    
  for( int sample : specfile.sample_numbers() ) {
    for( std::string detector : specfile.detector_names() ) {
      std::shared_ptr<const SpecUtils::Measurement> meas = specfile.measurement( sample, detector );
      std::cout << "Sample " << sample << " detector " << detector
                << " has live time " << meas->live_time() << "s and real time "
                << meas->real_time() << "s with counts: ";
      for( size_t i = 0; i < meas->num_gamma_channels(); ++i )
        std::cout << meas->gamma_channel_content(i) << ",";
      std::cout << " with " << meas->neutron_counts_sum() << " neutrons" << std::endl;
    }
  }
  
  specfile.write_to_file( "outout,csv", SpecUtils::SaveSpectrumAsType::Csv );
  return EXIT_SUCCESS;
}

Relevant CMake Build options

  • SpecUtils_ENABLE_D3_CHART [default ON]: Enabling this feature allows exporting specta to a D3.js based plotting that allows viewing and interacting with the spectra in a web browser. An example can be seen here.
    • SpecUtils_D3_SUPPORT_FILE_STATIC [default ON]: Only relevant if SpecUtils_ENABLE_D3_CHART is ON. This option determines if all the JavaScript (including D3.js, SpectrumChartD3.js, etc) and CSS should be compiled into the library, or remain as seperate files accessed at runtime.
  • SpecUtils_PYTHON_BINDINGS [default OFF]: Determines if the Python bindings should be built.