From e1fb8863b02ce9043d438f2a3ba37887cce5bc17 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Thu, 4 Apr 2024 16:02:49 -0700 Subject: [PATCH 1/3] Block units editing and render summary --- pyflask/manageNeuroconv/manage_neuroconv.py | 53 ++++++++++++------- schemas/base-metadata.schema.ts | 9 +++- src/renderer/src/stories/BasicTable.js | 11 ++-- .../pages/guided-mode/data/GuidedMetadata.js | 2 +- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index d4585b7d7..e6cc41233 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -37,7 +37,7 @@ } } -EXTRA_SORTING_INTERFACE_PROPERTIES = ["unit_name", *EXTRA_INTERFACE_PROPERTIES.keys()] +EXTRA_SORTING_INTERFACE_PROPERTIES = ["unit_id", *EXTRA_INTERFACE_PROPERTIES.keys()] SORTING_INTERFACE_PROPERTIES_TO_RECAST = { "quality": { @@ -52,14 +52,22 @@ } SORTING_INTERFACE_PROPERTY_OVERRIDES = { - "unit_name": {"description": "The unique name for the unit", "data_type": "str"}, + "unit_id": {"description": "The unique ID for this unit", "data_type": "str"}, + "brain_area": { "description": "The brain area where the unit is located.", **EXTRA_INTERFACE_PROPERTIES["brain_area"], }, + **SORTING_INTERFACE_PROPERTIES_TO_RECAST, } +# NOTE: No need to show this if it isn't editable +del SORTING_INTERFACE_PROPERTY_OVERRIDES["brain_area"] +brain_area_idx = EXTRA_SORTING_INTERFACE_PROPERTIES.index("brain_area") +EXTRA_SORTING_INTERFACE_PROPERTIES.pop(brain_area_idx) + + EXCLUDED_SORTING_INTERFACE_PROPERTIES = ["location", "spike_times", "electrodes"] # Not validated # NOTE: These are the only accepted dtypes... @@ -721,19 +729,22 @@ def update_conversion_progress(**kwargs): has_units = "Units" in ecephys_metadata if has_units: - shared_units_columns = ecephys_metadata["UnitColumns"] - for interface_name, interface_unit_results in ecephys_metadata["Units"].items(): - interface = converter.data_interface_objects[interface_name] - - update_sorting_properties_from_table_as_json( - interface, - unit_table_json=interface_unit_results, - unit_column_info=shared_units_columns, - ) - ecephys_metadata["UnitProperties"] = [ - {"name": entry["name"], "description": entry["description"]} for entry in shared_units_columns - ] + ## NOTE: Currently do not allow editing units properties + # shared_units_columns = ecephys_metadata["UnitColumns"] + # for interface_name, interface_unit_results in ecephys_metadata["Units"].items(): + # interface = converter.data_interface_objects[interface_name] + + # update_sorting_properties_from_table_as_json( + # interface, + # unit_table_json=interface_unit_results, + # unit_column_info=shared_units_columns, + # ) + + # ecephys_metadata["UnitProperties"] = [ + # {"name": entry["name"], "description": entry["description"]} for entry in shared_units_columns + # ] + del ecephys_metadata["Units"] del ecephys_metadata["UnitColumns"] @@ -1232,9 +1243,12 @@ def get_unit_table_json(interface) -> List[Dict[str, Any]]: for property_name in properties: - # Separate this so that unit_id and unit_name exist (LOOK FURTHER) - if property_name == "unit_name": - sorting_property_value = str(unit_id) # Insert unit_id as name (str) + if property_name == "unit_id": + sorting_property_value = str(unit_id) # Insert unit_id to view + + # elif property_name == "unit_name": + # sorting_property_value = str(unit_id) # By default, unit_name is unit_id (str) + elif property_name in SORTING_INTERFACE_PROPERTY_OVERRIDES: try: sorting_property_value = SORTING_INTERFACE_PROPERTY_OVERRIDES[property_name][ @@ -1417,11 +1431,11 @@ def update_sorting_properties_from_table_as_json( for entry_index, entry in enumerate(unit_table_json): unit_properties = dict(entry) # copy - unit_id = unit_properties.pop("unit_name", None) # NOTE: Is called unit_name in the actual units table + unit_id = unit_properties.pop("unit_id", None) # NOTE: Is called unit_name in the actual units table for property_name, property_value in unit_properties.items(): - if property_name == "unit_name": + if property_name == "unit_id": continue # Already controlling unit_id with the above variable dtype = unit_column_data_types[property_name] @@ -1433,4 +1447,5 @@ def update_sorting_properties_from_table_as_json( key=property_name, values=np.array([property_value], dtype=dtype), ids=[int(unit_id)], + # ids=[unit_id] ) diff --git a/schemas/base-metadata.schema.ts b/schemas/base-metadata.schema.ts index 5ff238c25..7b6d97478 100644 --- a/schemas/base-metadata.schema.ts +++ b/schemas/base-metadata.schema.ts @@ -156,10 +156,15 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa order: ["channel_name", "group_name", "shank_electrode_number", ...UV_PROPERTIES] }) - // ecephys.properties["Units"].title = "Unit Summaries" + ecephys.properties["Units"].title = "Summarized Units" updateEcephysTable("Units", copy, { - order: ["unit_name", "clu_id", "group_id"] + properties: { + clu_id: { + title: 'Cluster ID', + } + }, + order: ["unit_id", "unit_name", "clu_id", "group_id"] }) } diff --git a/src/renderer/src/stories/BasicTable.js b/src/renderer/src/stories/BasicTable.js index 993e99a81..7d26b7389 100644 --- a/src/renderer/src/stories/BasicTable.js +++ b/src/renderer/src/stories/BasicTable.js @@ -131,6 +131,7 @@ export class BasicTable extends LitElement { onLoaded, onUpdate, editable = true, + truncated = false, } = {}) { super(); this.name = name ?? "data_table"; @@ -147,7 +148,8 @@ export class BasicTable extends LitElement { if (onStatusChange) this.onStatusChange = onStatusChange; if (onLoaded) this.onLoaded = onLoaded; - this.editable = editable; + this.truncated = truncated + this.editable = editable && !truncated; } #schema = {}; @@ -419,8 +421,6 @@ export class BasicTable extends LitElement { }); // Only include data from schema }); - console.log(header, data, structuredData, this.data, this.#itemProps); - if (this.onUpdate) this.onUpdate([], data); // Update the whole table } @@ -431,6 +431,8 @@ export class BasicTable extends LitElement { this.schema = this.schema; // Always update the schema const entries = this.#itemProps; + if (this.truncated) this.data = this.data.slice(0, 5) // Limit to 5 rows when truncated + // Add existing additional properties to the entries variable if necessary if (this.#itemSchema.additionalProperties) { Object.values(this.data).reduce((acc, v) => { @@ -535,6 +537,9 @@ export class BasicTable extends LitElement { > ` : ""} + ${this.truncated + ? html`

...

` + : ""} ${description ? html`

${description} diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js index 05b006b59..fd7a98b5c 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js @@ -31,7 +31,7 @@ const parentTableRenderConfig = { return true; }, Units: (metadata) => { - metadata.editable = false; + metadata.truncated = true; metadata.schema.description = "Update unit information directly on your source data."; return true; }, From 5d77fd4173d81d4bfd6c6258f32f4c4402b71633 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Thu, 4 Apr 2024 16:07:46 -0700 Subject: [PATCH 2/3] Fix ordering --- schemas/base-metadata.schema.ts | 4 +-- .../pages/guided-mode/data/GuidedMetadata.js | 34 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/schemas/base-metadata.schema.ts b/schemas/base-metadata.schema.ts index 7b6d97478..b9ed45eea 100644 --- a/schemas/base-metadata.schema.ts +++ b/schemas/base-metadata.schema.ts @@ -144,8 +144,8 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa ecephys.properties.Device.title = 'Devices' ecephys.properties.ElectrodeGroup.title = 'Electrode Groups' - if (ecephys.properties.ElectrodeColumns) ecephys.properties.ElectrodeColumns.order = COLUMN_SCHEMA_ORDER - if (ecephys.properties.UnitProperties) ecephys.properties.UnitProperties.order = COLUMN_SCHEMA_ORDER + if (ecephys.properties.ElectrodeColumns) ecephys.properties.ElectrodeColumns.items.order = COLUMN_SCHEMA_ORDER + if (ecephys.properties.UnitColumns) ecephys.properties.UnitColumns.items.order = COLUMN_SCHEMA_ORDER updateEcephysTable("Electrodes", copy, { diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js index fd7a98b5c..cc8d0f7a2 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js @@ -60,21 +60,27 @@ const tableRenderConfig = { }); }, UnitColumns: function (metadata) { - const aggregateRequirements = getAggregateRequirements.call(this, ["Ecephys", "Units"]); + metadata.editable = false; + console.log('Column metadata', metadata) + metadata.schema.description = "Update unit information directly on your source data."; - return new SimpleTable({ - ...metadata, - contextOptions: { - row: { - add: false, - remove: false, - }, - }, - editable: { - name: (value) => !aggregateRequirements.has(value), - data_type: (_, row) => !aggregateRequirements.has(row.name), - }, - }); + return true + + // const aggregateRequirements = getAggregateRequirements.call(this, ["Ecephys", "Units"]); + // + // return new SimpleTable({ + // ...metadata, + // contextOptions: { + // row: { + // add: false, + // remove: false, + // }, + // }, + // editable: { + // name: (value) => !aggregateRequirements.has(value), + // data_type: (_, row) => !aggregateRequirements.has(row.name), + // }, + // }); }, }; From c24532dc524ac1a4663ca2c0df19af983216b957 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:09:02 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyflask/manageNeuroconv/manage_neuroconv.py | 6 ++---- src/renderer/src/stories/BasicTable.js | 10 +++++----- .../stories/pages/guided-mode/data/GuidedMetadata.js | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index e6cc41233..a4f2c9db5 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -53,12 +53,10 @@ SORTING_INTERFACE_PROPERTY_OVERRIDES = { "unit_id": {"description": "The unique ID for this unit", "data_type": "str"}, - "brain_area": { "description": "The brain area where the unit is located.", **EXTRA_INTERFACE_PROPERTIES["brain_area"], }, - **SORTING_INTERFACE_PROPERTIES_TO_RECAST, } @@ -744,7 +742,7 @@ def update_conversion_progress(**kwargs): # ecephys_metadata["UnitProperties"] = [ # {"name": entry["name"], "description": entry["description"]} for entry in shared_units_columns # ] - + del ecephys_metadata["Units"] del ecephys_metadata["UnitColumns"] @@ -1248,7 +1246,7 @@ def get_unit_table_json(interface) -> List[Dict[str, Any]]: # elif property_name == "unit_name": # sorting_property_value = str(unit_id) # By default, unit_name is unit_id (str) - + elif property_name in SORTING_INTERFACE_PROPERTY_OVERRIDES: try: sorting_property_value = SORTING_INTERFACE_PROPERTY_OVERRIDES[property_name][ diff --git a/src/renderer/src/stories/BasicTable.js b/src/renderer/src/stories/BasicTable.js index 7d26b7389..c4cef137a 100644 --- a/src/renderer/src/stories/BasicTable.js +++ b/src/renderer/src/stories/BasicTable.js @@ -148,7 +148,7 @@ export class BasicTable extends LitElement { if (onStatusChange) this.onStatusChange = onStatusChange; if (onLoaded) this.onLoaded = onLoaded; - this.truncated = truncated + this.truncated = truncated; this.editable = editable && !truncated; } @@ -431,7 +431,7 @@ export class BasicTable extends LitElement { this.schema = this.schema; // Always update the schema const entries = this.#itemProps; - if (this.truncated) this.data = this.data.slice(0, 5) // Limit to 5 rows when truncated + if (this.truncated) this.data = this.data.slice(0, 5); // Limit to 5 rows when truncated // Add existing additional properties to the entries variable if necessary if (this.#itemSchema.additionalProperties) { @@ -537,9 +537,9 @@ export class BasicTable extends LitElement { > ` : ""} - ${this.truncated - ? html`

...

` - : ""} + ${this.truncated + ? html`

...

` + : ""} ${description ? html`

${description} diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js index cc8d0f7a2..b690a4e57 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js @@ -61,10 +61,10 @@ const tableRenderConfig = { }, UnitColumns: function (metadata) { metadata.editable = false; - console.log('Column metadata', metadata) + console.log("Column metadata", metadata); metadata.schema.description = "Update unit information directly on your source data."; - return true + return true; // const aggregateRequirements = getAggregateRequirements.call(this, ["Ecephys", "Units"]); //