Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/pipeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import StatusBar from './status';
import Dialog from './dialog';
import AddWorker from './add-worker';
import SplitButton from '../split-button';
import { getAggregationFunction } from '../../stem-image/aggregation';

export enum ButtonOptions {
GenerateImage = "generate-image",
Expand Down Expand Up @@ -250,6 +251,10 @@ class PipelineWrapper extends Component<Props, State> {
onPipelineCreated(pipeline: PipelineCreationData) {
const { extraValues } = this.props;
const { pipelineId, workerId, name, info } = pipeline;

const aggregationFn = getAggregationFunction(info.aggregation);
this.source.setAggregationFunction(aggregationFn);

const executeParams = {
pipelineId,
workerId,
Expand Down
26 changes: 26 additions & 0 deletions src/stem-image/aggregation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
PipelineAggregation
} from './pipelines';

export type AggregationFunction = (aggregated: number, current: number) => number;

export const SumAggregation: AggregationFunction = (aggregated, current) => aggregated + current;

export const MaxAggregation: AggregationFunction = (aggregated, current) => Math.max(aggregated, current);

export const MinAggregation: AggregationFunction = (aggregated, current) => Math.min(aggregated, current);

export function getAggregationFunction(aggregation: PipelineAggregation) : AggregationFunction {
switch (aggregation) {
case PipelineAggregation.Max: {
return SumAggregation;
}
case PipelineAggregation.Min: {
return MinAggregation;
}
case PipelineAggregation.Sum:
default: {
return SumAggregation;
}
}
}
11 changes: 7 additions & 4 deletions src/stem-image/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { StreamConnection } from './connection';
import { MultiSubjectProducer, IObserver } from './subject';
import { PipelineExecutionData } from './pipelines';
import { AggregationFunction, SumAggregation } from './aggregation';
import { decode } from '@msgpack/msgpack';

export interface ImageDataSource {
Expand Down Expand Up @@ -98,6 +99,7 @@ export class StreamImageDataSource extends BaseImageDataSource implements ImageD
private connection: StreamConnection | null = null;
private sizeEvent: string = "";
private dataEvent: string = "";
private aggregationFn: AggregationFunction = SumAggregation;

constructor() {
super();
Expand All @@ -114,6 +116,10 @@ export class StreamImageDataSource extends BaseImageDataSource implements ImageD
this.connection.subscribe(this.dataEvent, this.dataObserver);
}

setAggregationFunction(fn: AggregationFunction) {
this.aggregationFn = fn;
}

resetConnection() {
if (this.connection) {
this.connection.unsubscribe(this.sizeEvent, this.sizeObserver);
Expand Down Expand Up @@ -153,11 +159,8 @@ export class StreamImageDataSource extends BaseImageDataSource implements ImageD
}

private updateImageChunk(values: Float64Array) {
const {width, height} = this.size;
const n = width * height;

for(let i = 0; i < values.length; ++i) {
this.data[i] += values[i];
this.data[i] = this.aggregationFn(this.data[i], values[i]);
}

this.updateRange();
Expand Down
13 changes: 11 additions & 2 deletions src/stem-image/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export interface PipelineInfo {
description: string;
displayName: string;
parameters: {[name: string]: ServerField};
output: PipelineIO
input: PipelineIO;
output: PipelineIO;
aggregation: PipelineAggregation;
}

export interface PipelineCreationData {
Expand All @@ -25,10 +27,17 @@ export interface PipelineExecutionData {
}

export enum PipelineName {
AnnularMask = 'annular'
AnnularMask = 'annular',
MaximumDiffraction = 'maximum_diffraction'
}

export enum PipelineIO {
Image = 'image',
Frame = 'frame'
}

export enum PipelineAggregation {
Sum = 'sum',
Max = 'max',
Min = 'min'
}