Last active
April 19, 2022 16:41
-
-
Save caiofcm/71a85cc53aa8751927df364d791c4ee5 to your computer and use it in GitHub Desktop.
Web Plot Digiziter script to download data as (x,y,dataset-name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wpd_to_dataset_treecolumns_fmt.js | |
// WPD script to download dataset in three columns format (x, y, name) | |
// | |
// Steps: | |
// 1) First load the correct image | |
// 2) Align axes | |
// 3) From File->Run Script, execute this script | |
// | |
var wpdscript = (function () { | |
function run() { | |
const datasets = wpd.appData.getPlotData().getDatasets() | |
console.log("π ~ file: wpd_to_dataset_treecolumns_fmt.js ~ line 13 ~ run ~ datasets", datasets) | |
const datasetValues = datasets.map(dataset => { | |
const axesDataset = wpd.appData.getPlotData().getAxesForDataset(dataset) | |
const valuesWithDSName = dataset._dataPoints.map(datum => { | |
console.log("π ~ file: wpd_to_dataset_treecolumns_fmt.js ~ line 17 ~ run ~ datum", datum) | |
const valuesXY = axesDataset.pixelToData(datum.x, datum.y) | |
const values = [valuesXY[0], valuesXY[1], dataset.name] | |
// values.push(dataset.name) | |
return values | |
}) | |
console.log("π ~ file: wpd_to_dataset_treecolumns_fmt.js ~ line 19 ~ run ~ valuesWithDSName", valuesWithDSName) | |
return valuesWithDSName | |
}) | |
console.log("π ~ file: wpd_to_dataset_treecolumns_fmt.js ~ line 20 ~ run ~ datasetValues", datasetValues) | |
let csvData = datasetValues.map(ds => ds.map(row => row.join(',')).join('\n')).join('\n') | |
const header = 'x,y,name' | |
csvData = header + '\n' + csvData | |
wpd.download.csv(csvData, 'output_datasets.csv') | |
} | |
return { | |
run: run | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment