From 8d839a65bfa18d45ec387f594e67c5e4062e142c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Apr 2024 00:15:00 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyflask/apis/neuroconv.py | 2 +- pyflask/app.py | 6 +- pyflask/manageNeuroconv/manage_neuroconv.py | 39 ++-- schemas/backend-configuration.schema.ts | 2 +- schemas/base-metadata.schema.ts | 2 +- src/renderer/src/stories/JSONSchemaInput.js | 11 +- src/renderer/src/stories/pages/Page.js | 8 +- .../data/GuidedBackendConfiguration.js | 187 +++++++++--------- 8 files changed, 118 insertions(+), 139 deletions(-) diff --git a/pyflask/apis/neuroconv.py b/pyflask/apis/neuroconv.py index a5bca4ec9..b35d2e767 100644 --- a/pyflask/apis/neuroconv.py +++ b/pyflask/apis/neuroconv.py @@ -22,7 +22,7 @@ upload_folder_to_dandi, upload_multiple_filesystem_objects_to_dandi, get_interface_alignment, - get_backend_configuration + get_backend_configuration, ) from errorHandlers import notBadRequestException diff --git a/pyflask/app.py b/pyflask/app.py index dfaf9ef7a..66846fa03 100644 --- a/pyflask/app.py +++ b/pyflask/app.py @@ -111,15 +111,15 @@ def get_cpu_count(): @app.route("/compression/hdf5") def get_hdf5_compression_methods(): from neuroconv.tools.nwb_helpers import AVAILABLE_HDF5_COMPRESSION_METHODS + return list(AVAILABLE_HDF5_COMPRESSION_METHODS) + @app.route("/compression/zarr") def get_zarr_compression_methods(): from neuroconv.tools.nwb_helpers import AVAILABLE_ZARR_COMPRESSION_METHODS - return list(AVAILABLE_ZARR_COMPRESSION_METHODS) - - + return list(AVAILABLE_ZARR_COMPRESSION_METHODS) @app.route("/get-recommended-species") diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index 46d2ddb95..b06e4f422 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -671,24 +671,20 @@ def get_interface_alignment(info: dict) -> dict: def get_backend_configuration(info: dict) -> dict: import numpy as np - from neuroconv.tools.nwb_helpers import make_or_load_nwbfile, get_default_backend_configuration, HDF5BackendConfiguration, configure_backend + from neuroconv.tools.nwb_helpers import ( + make_or_load_nwbfile, + get_default_backend_configuration, + HDF5BackendConfiguration, + configure_backend, + ) backend_configuration = info.get("configuration") converter, metadata, path_info = get_conversion_info(info) - - PROPS_TO_REMOVE = [ - "object_id", - "dataset_name", - "location_in_file", - "dtype" - ] + PROPS_TO_REMOVE = ["object_id", "dataset_name", "location_in_file", "dtype"] - PROPS_TO_AVOID = [ - "full_shape" - ] - + PROPS_TO_AVOID = ["full_shape"] with make_or_load_nwbfile( nwbfile_path=path_info["file"], @@ -708,17 +704,15 @@ def get_backend_configuration(info: dict) -> dict: for key, value in item.items(): # Avoid setting compression options if unspecified - if (key == 'compression_options' and len(value) == 0): + if key == "compression_options" and len(value) == 0: setattr(configuration.dataset_configurations[name], key, None) # Avoid certain properties passed to the GUIDE - elif (key not in PROPS_TO_AVOID): + elif key not in PROPS_TO_AVOID: setattr(configuration.dataset_configurations[name], key, value) - configure_backend(nwbfile=nwbfile, backend_configuration=configuration) - def custom_encoder(obj): if isinstance(obj, np.ndarray): return obj.tolist() @@ -731,12 +725,12 @@ def custom_encoder(obj): serialized = json.loads(json.dumps(configuration.dict(), default=custom_encoder)) - dataset_configurations = serialized["dataset_configurations"] # Only provide dataset configurations + dataset_configurations = serialized["dataset_configurations"] # Only provide dataset configurations for dataset in dataset_configurations.values(): for key in PROPS_TO_REMOVE: del dataset[key] - + return dataset_configurations @@ -818,7 +812,11 @@ def update_conversion_progress(**kwargs): del ecephys_metadata["ElectrodeColumns"] - return converter, resolved_metadata, dict(file=resolved_output_path, directory=resolved_output_directory, default=default_output_directory) + return ( + converter, + resolved_metadata, + dict(file=resolved_output_path, directory=resolved_output_directory, default=default_output_directory), + ) def convert_to_nwb(info: dict) -> str: @@ -828,7 +826,6 @@ def convert_to_nwb(info: dict) -> str: source_data = info.get("source_data", False) backend_configuration = info.get("configuration") - converter, metadata, path_info = get_conversion_info(info) output_path = path_info["file"] @@ -840,7 +837,7 @@ def convert_to_nwb(info: dict) -> str: options = ( { interface: ( - { "stub_test": run_stub_test } # , "iter_opts": {"report_hook": update_conversion_progress}} + {"stub_test": run_stub_test} # , "iter_opts": {"report_hook": update_conversion_progress}} if available_options.get("properties").get(interface).get("properties", {}).get("stub_test") else {} ) diff --git a/schemas/backend-configuration.schema.ts b/schemas/backend-configuration.schema.ts index 722fa6b77..cba3eef61 100644 --- a/schemas/backend-configuration.schema.ts +++ b/schemas/backend-configuration.schema.ts @@ -47,7 +47,7 @@ export const getSchema = (method='hdf5') => { copy.properties["compression_method"].enum = resolved[method] ?? sharedCompressionMethods return copy } - + const setReady: any = {} diff --git a/schemas/base-metadata.schema.ts b/schemas/base-metadata.schema.ts index f896955e4..d2235616e 100644 --- a/schemas/base-metadata.schema.ts +++ b/schemas/base-metadata.schema.ts @@ -157,7 +157,7 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa }) const units = ecephys.properties["Units"] - + if (units) { units.title = "Summarized Units" diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index f423faf73..1c1845fdd 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -926,7 +926,7 @@ export class JSONSchemaInput extends LitElement { const allowPatternProperties = isPatternProperties(this.pattern); const allowAdditionalProperties = isAdditionalProperties(this.pattern); - const editableInline = [ 'string', 'number' ] + const editableInline = ["string", "number"]; // Provide default item types if (isArray) { @@ -946,15 +946,12 @@ export class JSONSchemaInput extends LitElement { const fileSystemFormat = isFilesystemSelector(name, itemSchema?.format); if (fileSystemFormat) return createFilesystemSelector(fileSystemFormat); - // Create tables if possible else if (editableInline.includes(itemSchema?.type) && !itemSchema.properties) { - - const postprocess = (v) => { - if (itemSchema?.type === 'number') return parseFloat(v) - else return v - } + if (itemSchema?.type === "number") return parseFloat(v); + else return v; + }; const list = new List({ items: this.value, diff --git a/src/renderer/src/stories/pages/Page.js b/src/renderer/src/stories/pages/Page.js index 0480fcb4d..fa85dd222 100644 --- a/src/renderer/src/stories/pages/Page.js +++ b/src/renderer/src/stories/pages/Page.js @@ -140,12 +140,7 @@ export class Page extends LitElement { } } - async runConversions( - conversionOptions = {}, - toRun, - options = {}, - backendFunctionToRun = runConversion - ) { + async runConversions(conversionOptions = {}, toRun, options = {}, backendFunctionToRun = runConversion) { let original = toRun; if (!Array.isArray(toRun)) toRun = this.mapSessions(); @@ -200,7 +195,6 @@ export class Page extends LitElement { const sourceDataCopy = structuredClone(sessionResults.source_data); - // Resolve the correct session info from all of the metadata for this conversion const sessionInfo = { ...sessionResults, diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedBackendConfiguration.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedBackendConfiguration.js index 2a9a83cfb..de303bb0b 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedBackendConfiguration.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedBackendConfiguration.js @@ -19,8 +19,8 @@ const getBackendConfigurations = (info, options = {}) => run(`configuration`, in const itemIgnore = { full_shape: true, - compression_options: true -} + compression_options: true, +}; export class GuidedBackendConfigurationPage extends ManagedPage { constructor(...args) { @@ -33,11 +33,11 @@ export class GuidedBackendConfigurationPage extends ManagedPage { }; form; - instances = [] + instances = []; #getForm = (sub, ses) => { - const found = this.instances.find(o => o.session === ses && o.subject === sub ) - return found?.instance instanceof JSONSchemaForm ? found.instance : null - } + const found = this.instances.find((o) => o.session === ses && o.subject === sub); + return found?.instance instanceof JSONSchemaForm ? found.instance : null; + }; header = { subtitle: "Configure your backend", @@ -59,7 +59,7 @@ export class GuidedBackendConfigurationPage extends ManagedPage { if (instance instanceof JSONSchemaForm) await instance.validate(); // Will throw an error in the callback } - await this.getBackendConfiguration() // Validate by trying to set backend configuration with the latest values + await this.getBackendConfiguration(); // Validate by trying to set backend configuration with the latest values return this.to(1); }, @@ -83,113 +83,105 @@ export class GuidedBackendConfigurationPage extends ManagedPage { } renderInstance = ({ session, subject, info }) => { - - this.localState.results[subject][session].configuration = info + this.localState.results[subject][session].configuration = info; let instance; if (Object.keys(info).length === 0) { instance = document.createElement("span"); instance.innerText = "No configuration options available for this session"; - } - - else { - - const itemSchema = getSchema() + } else { + const itemSchema = getSchema(); - const schema = { type: 'object', properties: {} } + const schema = { type: "object", properties: {} }; - const reorganized = Object.entries(info).reduce((acc, [ name, item ]) => { + const reorganized = Object.entries(info).reduce((acc, [name, item]) => { + const splitName = name.split("/"); - const splitName = name.split('/') + const resolved = { schema, results: acc }; - const resolved = { schema, results: acc } - - const lenSplit = splitName.length + const lenSplit = splitName.length; splitName.reduce((acc, key, i) => { - - const { schema, results } = acc - - const props = schema.properties ?? (schema.properties = {}) - - // Set directly on last iteration - if (i === (lenSplit - 1)) { - props[key] = {...itemSchema} - if (item.compression_options == null) item.compression_options = {} // Set blank compression options to an empty object - results[key] = item - return - } - - // Otherwise drill into the results - else { - const thisSchema = props[key] ?? (props[key] = {}) - if (!results[key]) results[key] = {} - return { schema: thisSchema, results: results[key] } - } - - }, resolved) - - return acc - - }, {}) - - const existingForm = this.#getForm(subject, session) + const { schema, results } = acc; + + const props = schema.properties ?? (schema.properties = {}); + + // Set directly on last iteration + if (i === lenSplit - 1) { + props[key] = { ...itemSchema }; + if (item.compression_options == null) item.compression_options = {}; // Set blank compression options to an empty object + results[key] = item; + return; + } + + // Otherwise drill into the results + else { + const thisSchema = props[key] ?? (props[key] = {}); + if (!results[key]) results[key] = {}; + return { schema: thisSchema, results: results[key] }; + } + }, resolved); + + return acc; + }, {}); + + const existingForm = this.#getForm(subject, session); if (existingForm) { - existingForm.results = reorganized // Update resolved values - return { session, subject, instance: existingForm } + existingForm.results = reorganized; // Update resolved values + return { session, subject, instance: existingForm }; } - instance = new JSONSchemaForm({ schema, results: reorganized, ignore: { - '*': itemIgnore + "*": itemIgnore, }, onUpdate: (updatedPath) => { - console.log(updatedPath) - this.unsavedUpdates = true + console.log(updatedPath); + this.unsavedUpdates = true; }, onThrow, // validateOnChange: validate, - }) + }); } return { session, subject, instance }; - }; getBackendConfiguration = (config = true, opts = {}) => { - - if (!opts.title && config === true) opts.title = "Getting backend options for all sessions" - + if (!opts.title && config === true) opts.title = "Getting backend options for all sessions"; return this.runConversions( - {}, + {}, config, // All or specific session - opts, + opts, getBackendConfigurations - ) - } + ); + }; - #needsUpdate = {} + #needsUpdate = {}; render() { - - this.#needsUpdate = {} + this.#needsUpdate = {}; this.#updateRendered(true); this.localState = { results: structuredClone(this.info.globalState.results ?? {}) }; const renderInstances = (toIterate) => { - const instances = {}; - this.instances = toIterate ? this.mapSessions(this.renderInstance, toIterate) : this.mapSessions(({ subject, session, info }) => this.renderInstance({ subject, session, info: info.configuration }), toIterate); - + this.instances = toIterate + ? this.mapSessions(this.renderInstance, toIterate) + : this.mapSessions( + ({ subject, session, info }) => + this.renderInstance({ subject, session, info: info.configuration }), + toIterate + ); + this.instances.forEach(({ subject, session, instance }) => { if (!instances[`sub-${subject}`]) instances[`sub-${subject}`] = {}; instances[`sub-${subject}`][`ses-${session}`] = instance; }); - + this.manager = new InstanceManager({ header: "Sessions", instanceType: "Session", @@ -199,48 +191,48 @@ export class GuidedBackendConfigurationPage extends ManagedPage { name: "Update", primary: true, onClick: async (key) => { - const { subject, session } = getInfoFromId(key); - const existingForm = this.#getForm(subject, session) - await existingForm.validate() + const existingForm = this.#getForm(subject, session); + await existingForm.validate(); - const merged = merge(this.localState, structuredClone(this.info.globalState)) + const merged = merge(this.localState, structuredClone(this.info.globalState)); - const results = await this.getBackendConfiguration( [ + const results = await this.getBackendConfiguration( + [ + { + subject, + session, + globalState: merged, + }, + ], { - subject, - session, - globalState:merged, - }, - ], - { - title: `Configuring backend for ${key}` - }).catch(() => {}) - - + title: `Configuring backend for ${key}`, + } + ).catch(() => {}); + if (!results) return; // Update existing instance - this.renderInstance({ subject, session, info: results[subject][session] }) + this.renderInstance({ subject, session, info: results[subject][session] }); - await this.save() // Save if properly returned - + await this.save(); // Save if properly returned }, }, - ] - }) - - return this.manager - - } - + ], + }); - const hasAll = this.mapSessions(({ session, subject}) => !!this.info.globalState.results[subject][session].configuration) - if (hasAll.every((v) => v === true)) return renderInstances() + return this.manager; + }; + const hasAll = this.mapSessions( + ({ session, subject }) => !!this.info.globalState.results[subject][session].configuration + ); + if (hasAll.every((v) => v === true)) return renderInstances(); - const promise = this.getBackendConfiguration().then((backendOptions) => renderInstances(backendOptions)).catch((error) => html`

${error}

`); + const promise = this.getBackendConfiguration() + .then((backendOptions) => renderInstances(backendOptions)) + .catch((error) => html`

${error}

`); const untilResult = until(promise, html`Loading form contents...`); @@ -249,7 +241,6 @@ export class GuidedBackendConfigurationPage extends ManagedPage { }); return untilResult; - } }