From 030ffb39531be507650d0013794085836571f2ca Mon Sep 17 00:00:00 2001 From: Jaehwan Ryu Date: Thu, 2 Jan 2025 10:44:38 -0500 Subject: [PATCH] Calibrate ensemble tweaks (#5871) Co-authored-by: Tom Szendrey --- .../widgets/tera-chart-settings.vue | 46 +++++----- .../calibrate-ensemble-util.ts | 26 +++++- ...ra-calibrate-ensemble-ciemss-drilldown.vue | 44 ++++++---- .../tera-calibrate-ensemble-node-ciemss.vue | 85 +++++++++++++++---- 4 files changed, 141 insertions(+), 60 deletions(-) diff --git a/packages/client/hmi-client/src/components/widgets/tera-chart-settings.vue b/packages/client/hmi-client/src/components/widgets/tera-chart-settings.vue index 1dd138f4a25..a60ede2df49 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-chart-settings.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-chart-settings.vue @@ -1,6 +1,29 @@ diff --git a/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/calibrate-ensemble-util.ts b/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/calibrate-ensemble-util.ts index 3d2bb2cfd46..c87750757f4 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/calibrate-ensemble-util.ts +++ b/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/calibrate-ensemble-util.ts @@ -8,10 +8,10 @@ import { getSimulation, parseEnsemblePyciemssMap } from '@/services/models/simulation-service'; -import { EnsembleModelConfigs } from '@/types/Types'; +import { EnsembleModelConfigs, ModelConfiguration } from '@/types/Types'; import { WorkflowNode } from '@/types/workflow'; import { getActiveOutput } from '@/components/workflow/util'; -import { CalibrateMap } from '@/services/calibrate-workflow'; +import { CalibrateMap, setupModelInput } from '@/services/calibrate-workflow'; import { CalibrateEnsembleCiemssOperationState, CalibrateEnsembleMappingRow, @@ -148,6 +148,28 @@ export async function fetchOutputData(preForecastId: string, postForecastId: str }; } +export async function fetchModelConfigurations( + nodeInputs: WorkflowNode['inputs'] +) { + const allModelOptions: any[][] = []; + const allModelConfigurations: ModelConfiguration[] = []; + const modelConfigurationIds: string[] = []; + nodeInputs.forEach((ele) => { + if (ele.value && ele.type === 'modelConfigId') modelConfigurationIds.push(ele.value[0]); + }); + if (!modelConfigurationIds) return null; + + // Model configuration input + await Promise.all( + modelConfigurationIds.map(async (id) => { + const { modelConfiguration, modelOptions } = await setupModelInput(id); + if (modelConfiguration) allModelConfigurations.push(modelConfiguration); + if (modelOptions) allModelOptions.push(modelOptions); + }) + ); + return { allModelConfigurations, allModelOptions }; +} + // Build chart data by adding variable translation map to the given output data export function buildChartData( outputData: { diff --git a/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-ciemss-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-ciemss-drilldown.vue index d089e20d3a9..1fcd393a063 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-ciemss-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-ciemss-drilldown.vue @@ -345,7 +345,7 @@ import TeraInputNumber from '@/components/widgets/tera-input-number.vue'; import AccordionTab from 'primevue/accordiontab'; import Accordion from 'primevue/accordion'; import Dropdown from 'primevue/dropdown'; -import { setupDatasetInput, setupCsvAsset, setupModelInput, parseCsvAsset } from '@/services/calibrate-workflow'; +import { setupDatasetInput, setupCsvAsset, parseCsvAsset } from '@/services/calibrate-workflow'; import TeraDrilldown from '@/components/drilldown/tera-drilldown.vue'; import TeraDrilldownSection from '@/components/drilldown/tera-drilldown-section.vue'; import TeraSaveDatasetFromSimulation from '@/components/dataset/tera-save-dataset-from-simulation.vue'; @@ -375,7 +375,7 @@ import VegaChart from '@/components/widgets/VegaChart.vue'; import { ChartSettingType, CiemssPresetTypes, DrilldownTabs } from '@/types/common'; import { useCharts } from '@/composables/useCharts'; import { useChartSettings } from '@/composables/useChartSettings'; -import { deleteAnnotation } from '@/services/chart-settings'; +import { deleteAnnotation, updateChartSettingsBySelectedVariables } from '@/services/chart-settings'; import { DataArray } from '@/utils/stats'; import { GroupedDataArray } from '@/services/charts'; import { @@ -393,7 +393,8 @@ import { fetchOutputData, buildChartData, getEnsembleErrorData, - EnsembleErrorData + EnsembleErrorData, + fetchModelConfigurations } from './calibrate-ensemble-util'; const props = defineProps<{ @@ -550,6 +551,22 @@ const setPresetValues = (data: CiemssPresetTypes) => { } }; +const initDefaultChartSettings = (state: CalibrateEnsembleCiemssOperationState) => { + const mappedEnsembleVariables = knobs.value.ensembleMapping.map((c) => c.newName); + if (_.isEmpty(state.chartSettings)) { + state.chartSettings = updateChartSettingsBySelectedVariables( + state.chartSettings ?? [], + ChartSettingType.VARIABLE_ENSEMBLE, + mappedEnsembleVariables + ); + state.chartSettings = updateChartSettingsBySelectedVariables( + state.chartSettings, + ChartSettingType.ERROR_DISTRIBUTION, + mappedEnsembleVariables + ); + } +}; + const runEnsemble = async () => { if (!datasetId.value || !currentDatasetFileName.value) return; @@ -590,26 +607,17 @@ const runEnsemble = async () => { state.currentProgress = 0; state.inProgressCalibrationId = response?.simulationId; state.inProgressForecastId = ''; + // Add default chart settings based on the ensemble mapping on the first run + initDefaultChartSettings(state); emit('update-state', state); } }; onMounted(async () => { - allModelConfigurations.value = []; - const modelConfigurationIds: string[] = []; - props.node.inputs.forEach((ele) => { - if (ele.value && ele.type === 'modelConfigId') modelConfigurationIds.push(ele.value[0]); - }); - if (!modelConfigurationIds) return; - - // Model configuration input - await Promise.all( - modelConfigurationIds.map(async (id) => { - const { modelConfiguration, modelOptions } = await setupModelInput(id); - if (modelConfiguration) allModelConfigurations.value.push(modelConfiguration); - if (modelOptions) allModelOptions.value.push(modelOptions); - }) - ); + const configs = await fetchModelConfigurations(props.node.inputs); + if (!configs) return; + allModelConfigurations.value = configs.allModelConfigurations; + allModelOptions.value = configs.allModelOptions; // dataset input if (datasetId.value) { diff --git a/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-node-ciemss.vue b/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-node-ciemss.vue index 571218e601b..0c9ffc7fd41 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-node-ciemss.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-node-ciemss.vue @@ -5,6 +5,14 @@ :are-embed-actions-visible="false" :visualization-spec="lossChartSpec" /> +
+ +