aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcjd242018-04-21 02:42:44 +0100
committercjd242018-04-21 02:42:44 +0100
commit4aeb0e10055f5ffdfd15fe3f6ac599f977d4f101 (patch)
tree8fe0a0cb2dc2fd9f449dc509013f2d5a5f0b6e74 /src
parentSeems to have got the big boi CZI working again, added support for lecia files (diff)
downloadmedicine-4aeb0e10055f5ffdfd15fe3f6ac599f977d4f101.tar.gz
medicine-4aeb0e10055f5ffdfd15fe3f6ac599f977d4f101.zip

adding support for excel to csv stuff and fixed stage count of czi conversion

Diffstat (limited to 'src')
-rw-r--r--src/conversion/csv/excel.ts97
-rw-r--r--src/conversion/czi/czi.ts2
2 files changed, 98 insertions, 1 deletions
diff --git a/src/conversion/csv/excel.ts b/src/conversion/csv/excel.ts
new file mode 100644
index 0000000..2764192
--- /dev/null
+++ b/src/conversion/csv/excel.ts
@@ -0,0 +1,97 @@
+import { logger } from '../../logger';
+import * as xlsx from 'xlsx';
+import * as fs from 'fs';
+
+// const testDir: string = `/cs/scratch/cjd24/csv/`;
+// const testFile: string = `test1.xlsx`
+
+
+const toCSV: (file: string) => Promise<string[]> = async (file: string): Promise<string[]> => {
+ logger.info(`xls convertor received new file to convert to csv: ${file}`);
+
+ let book: xlsx.WorkBook = xlsx.readFile(file);
+ try {
+ let sheetnames: string[] = [];
+ for (let name of book.SheetNames) {
+ fs.writeFile(`${file.split('.')[0]}-${name}.csv`, xlsx.utils.sheet_to_csv(book.Sheets[name]));
+ sheetnames.push(`${file.split('.')[0]}-${name}.csv`);
+ logger.info(`Wrote ${file.split('.')[1]} subsheet {${file} : ${name}} as CSV.`);
+ }
+ return sheetnames === [] ? ["__Empty_Book_Error"] : sheetnames;
+ } catch (err) {
+ logger.error(err);
+ return ["__Conversion_to_csv_Error_Occurred: " + err]
+ }
+}
+
+const toJSON: (file: string) => Promise<string[]> = async (file: string): Promise<string[]> => {
+ logger.info(`xls convertor received new file to convert to json: ${file}`);
+
+ let book: xlsx.WorkBook = xlsx.readFile(file);
+ try {
+ let sheetnames: string[] = [];
+ for (let name of book.SheetNames) {
+ fs.writeFile(`${file.split('.')[0]}-${name}.json`, xlsx.utils.sheet_to_json(book.Sheets[name]));
+ sheetnames.push(`${file.split('.')[0]}-${name}.json`);
+ logger.info(`Wrote ${file.split('.')[1]} subsheet {${file} : ${name}} as JSON.`);
+ }
+ return sheetnames === [] ? ["__Empty_Book_Error"] : sheetnames;
+ } catch (err) {
+ logger.error(err);
+ return ["__Conversion_to_json_Error_Occurred: " + err]
+ }
+}
+
+const toHTML: (file: string) => Promise<string[]> = async (file: string): Promise<string[]> => {
+ logger.info(`xls convertor received new file to convert to html: ${file}`);
+
+ let book: xlsx.WorkBook = xlsx.readFile(file);
+ try {
+ let sheetnames: string[] = [];
+ for (let name of book.SheetNames) {
+ fs.writeFile(`${file.split('.')[0]}-${name}.html`, xlsx.utils.sheet_to_html(book.Sheets[name]));
+ sheetnames.push(`${file.split('.')[0]}-${name}.html`);
+ logger.info(`Wrote ${file.split('.')[1]} subsheet {${file} : ${name}} as HTML.`);
+ }
+ return sheetnames === [] ? ["__Empty_Book_Error"] : sheetnames;
+ } catch (err) {
+ logger.error(err);
+ return ["__Conversion_to_html_Error_Occurred: " + err]
+ }
+}
+
+const toAll: (file: string) =>
+Promise<{csv: string[], json: string[], html: string[]}> =
+async (file: string):
+Promise<{csv: string[], json: string[], html: string[]}> => {
+ return {
+ csv: await toCSV(file),
+ json: await toCSV(file),
+ html: await toCSV(file)
+ }
+}
+
+
+// const main: () => void = async (): Promise<void> => {
+//
+// try {
+// let file: xlsx.WorkBook = xlsx.readFile(`${testDir}${testFile}`);
+//
+// for (let name of file.SheetNames) {
+// fs.writeFileSync(`${testDir}${testFile.split('.')[0]}-${name}.csv`, xlsx.utils.sheet_to_csv(file.Sheets[name]));
+// logger.info(`Wrote ${testFile.split('.')[1]} subsheet {${testFile} : ${name}} as CSV.`);
+// fs.writeFileSync(`${testDir}${testFile.split('.')[0]}-${name}.json`, xlsx.utils.sheet_to_json(file.Sheets[name]));
+// logger.info(`Wrote ${testFile.split('.')[1]} subsheet {${testFile} : ${name}} as json.`);
+// fs.writeFileSync(`${testDir}${testFile.split('.')[0]}-${name}.html`, xlsx.utils.sheet_to_html(file.Sheets[name]));
+// logger.info(`Wrote ${testFile.split('.')[1]} subsheet {${testFile} : ${name}} as HTML.`);
+// }
+//
+// logger.success(`Wrote ${testFile.split('.')[1]} {${testFile}} as CSV.`);
+// logger.success(`Wrote ${testFile.split('.')[1]} {${testFile}} as JSON.`);
+// logger.success(`Wrote ${testFile.split('.')[1]} {${testFile}} as HTML.`);
+// } catch (err) {
+// // console.log(err);
+// logger.error(err);
+// }
+// };
+// main();
diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts
index 1d157ff..1a92fa6 100644
--- a/src/conversion/czi/czi.ts
+++ b/src/conversion/czi/czi.ts
@@ -715,7 +715,7 @@ const buildCustomPyramids: () => Promise<void> = async(): Promise<void> => {
// Extract the base tiles and build up custom pyramid data
await extrapolateDimension(
Number.parseInt(cval.channel_id, 10),
- supportedViews.scalable_image.channels.length * Math.log2(maxZoom),
+ supportedViews.scalable_image.channels.length * Math.log2(maxZoom * 2),
maxZoom
).then((v: CZIHeightMap[]) => {
// On success, add the new heightmap to the final json data block