export

package
v2.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Example (WriteQuantCSVForROI)
quantCSVLines := []string{"header", "PMC, Ca_%, Fe_%, livetime", "12, 5.5, 6.6, 9.8", "14, 7.7, 8.8, 9.7", "15, 2.7, 2.8, 9.6", "16, 2.8, 2.9, 9.7"}
roi := roiModel.ROIMembers{
	Name:         "roi name",
	ID:           "roi123",
	SharedByName: "",
	LocationIdxs: []int32{4, 5, 6},
	PMCs:         []int32{11, 12, 13, 14, 15},
}

// Pass in a list of PMCs that includes one exclusion, and one that modifies PMC (due to combined dataset)
pmcToDatasetLookup := map[int32]int32{12: 12, 14: 10014}

outDir, err := ioutil.TempDir("", "csv-test")
if err != nil {
	fmt.Printf("Failed to make temp dir: %v\n", err)
}
csvName, err := writeQuantCSVForROI("dataset123", pmcToDatasetLookup, quantCSVLines, roi, outDir, "prefix")
fmt.Printf("%v|%v\n", err, csvName)

// Write the file to stdout so we can test its contents
data, err := ioutil.ReadFile(path.Join(outDir, csvName))
if err != nil {
	fmt.Printf("Failed to read csv: %v\n", err)
}
fmt.Println(string(data))
Output:

<nil>|prefix-map ROI roi name for dataset dataset123.csv
header
PMC, Ca_%, Fe_%, livetime
12, 5.5, 6.6, 9.8
10014, 7.7, 8.8, 9.7
Example (WriteSpectraCSV_Blank)
var content = ""
csv := stringMemWriter{Content: &content}
err := writeSpectraCSV("the/path.csv", []spectrumData{}, csv)
fmt.Println(*csv.Content)
fmt.Printf("%v\n", err)
Output:

No spectra for writeSpectraCSV when writing the/path.csv
Example (WriteSpectraCSV_OK)
spectra := []spectrumData{
	{
		PMC: 12,
		x:   1,
		y:   2,
		z:   3,
		metaA: datasetModel.SpectrumMetaValues{
			SCLK:     12345678,
			RealTime: 8.3,
			LiveTime: 8.0,
			XPerChan: 10.1,
			Offset:   2.7,
			Detector: "A",
			ReadType: "Normal",
		},
		metaB: datasetModel.SpectrumMetaValues{
			SCLK:     123456789,
			RealTime: 8.2,
			LiveTime: 8.5,
			XPerChan: 10.6,
			Offset:   3.7,
			Detector: "B",
			ReadType: "Normal",
		},
		countsA: []int32{30, 500, 10},
		countsB: []int32{40, 300, 2},
	},
}

var content = ""
csv := stringMemWriter{Content: &content}
err := writeSpectraCSV("the/path.csv", spectra, csv)
fmt.Println(*csv.Content)
fmt.Printf("%v\n", err)
Output:

SCLK_A,SCLK_B,PMC,real_time_A,real_time_B,live_time_A,live_time_B,XPERCHAN_A,XPERCHAN_B,OFFSET_A,OFFSET_B
12345678,123456789,12,8.3,8.2,8,8.5,10.1,10.6,2.7,3.7
PMC,x,y,z
12,1,2,3
A_1,A_2,A_3
30,500,10
B_1,B_2,B_3
40,300,2

<nil>
Example (WriteSpectraMSA_A)
spectrum := spectrumData{
	PMC: 12,
	x:   1,
	y:   2,
	z:   3,
	metaA: datasetModel.SpectrumMetaValues{
		SCLK:     12345678,
		RealTime: 8.3,
		LiveTime: 8.0,
		XPerChan: 10.1,
		Offset:   2.7,
		Detector: "A",
		ReadType: "Normal",
	},
	countsA: []int32{30, 500, 10},
}

var content = ""
msa := stringMemWriter{Content: &content}
mockTime := &timestamper.MockTimeNowStamper{
	QueuedTimeStamps: []int64{1734567890},
}
err := writeSpectraMSA("the/path.msa", mockTime, spectrum, msa)
fmt.Println(*msa.Content)
fmt.Printf("%v\n", err)
Output:

#FORMAT      : EMSA/MAS spectral data file
#VERSION     : TC202v2.0 PIXL
#TITLE       : Control Program v7
#OWNER       : JPL BREADBOARD vx
#DATE        : 12-19-2024
#TIME        : 00:24:50
#NPOINTS     : 3
#NCOLUMNS    : 1
#XUNITS      :  eV
#YUNITS      :  COUNTS
#DATATYPE    :  Y
#XPERCHAN    :  10.1    eV per channel
#OFFSET      :  2.7    eV of first channel
#SIGNALTYPE  :  XRF
#COMMENT     :  Exported bulk sum MSA from PIXLISE
#XPOSITION   :    0.000
#YPOSITION   :    0.000
#ZPOSITION   :    0.000
#LIVETIME    :  8
#REALTIME    :  8.3
#SPECTRUM    :
30
500
10

<nil>
Example (WriteSpectraMSA_AB)
spectrum := spectrumData{
	PMC: 12,
	x:   1,
	y:   2,
	z:   3,
	metaA: datasetModel.SpectrumMetaValues{
		SCLK:     12345678,
		RealTime: 8.3,
		LiveTime: 8.0,
		XPerChan: 10.1,
		Offset:   2.7,
		Detector: "A",
		ReadType: "Normal",
	},
	metaB: datasetModel.SpectrumMetaValues{
		SCLK:     123456789,
		RealTime: 8.2,
		LiveTime: 8.5,
		XPerChan: 10.6,
		Offset:   3.7,
		Detector: "B",
		ReadType: "Normal",
	},
	countsA: []int32{30, 500, 10},
	countsB: []int32{40, 300, 2},
}

var content = ""
msa := stringMemWriter{Content: &content}
mockTime := &timestamper.MockTimeNowStamper{
	QueuedTimeStamps: []int64{1734567890},
}
err := writeSpectraMSA("the/path.msa", mockTime, spectrum, msa)
fmt.Println(*msa.Content)
fmt.Printf("%v\n", err)
Output:

#FORMAT      : EMSA/MAS spectral data file
#VERSION     : TC202v2.0 PIXL
#TITLE       : Control Program v7
#OWNER       : JPL BREADBOARD vx
#DATE        : 12-19-2024
#TIME        : 00:24:50
#NPOINTS     : 3
#NCOLUMNS    : 2
#XUNITS      :  eV
#YUNITS      :  COUNTS
#DATATYPE    :  YY
#XPERCHAN    :  10.1, 10.6    eV per channel
#OFFSET      :  2.7, 3.7    eV of first channel
#SIGNALTYPE  :  XRF
#COMMENT     :  Exported bulk sum MSA from PIXLISE
#XPOSITION   :    0.000
#YPOSITION   :    0.000
#ZPOSITION   :    0.000
#LIVETIME    :  8, 8.5
#REALTIME    :  8.3, 8.2
#SPECTRUM    :
30, 40
500, 300
10, 2

<nil>

Index

Examples

Constants

View Source
const FileIdBeamLocations = "beam-locations"
View Source
const FileIdContextImage = "context-image"
View Source
const FileIdDiffractionPeak = "diffraction-peak"
View Source
const FileIdQuantMapCSV = "quant-map-csv"
View Source
const FileIdQuantMapTIF = "quant-map-tif"
View Source
const FileIdROIs = "rois"
View Source
const FileIdSpectra = "raw-spectra"
View Source
const FileIdUnquantifiedWeightPct = "unquantified-weight"

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter struct {
}

The actual exporter, implemented by our package. This is so we can be used as part of an interface by caller

func (*Exporter) MakeExportFilesZip

func (m *Exporter) MakeExportFilesZip(svcs *services.APIServices, outfileNamePrefix string, userID string, datasetID string, quantID string, quantPath string, fileIDs []string, roiIDs []string) ([]byte, error)

MakeExportFilesZip - makes a zip file containing all requested export data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL