> ## Documentation Index
> Fetch the complete documentation index at: https://methodscenter.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Run Kalman Filter

> Processes time series data using a Kalman filter to reduce noise and provide
smoothed predictions. Optionally saves results to the database with a unique identifier.


<Note>
  Submit one or more time series to Luna's Kalman filter. Set `save` to `true`
  and include a `unique_identifier` to accumulate historical observations across
  requests.
</Note>


## OpenAPI

````yaml POST /{account_id}/kalman
openapi: 3.0.3
info:
  title: Luna Modelling API
  description: >
    API for advanced data modeling and filtering services.


    ## Getting Started


    To use this API, you need:

    1. **API Key**: Contact us to obtain your unique API key and quota
    allocation

    2. **Account ID**: Provided along with your API key


    ### Contact Us

    - Email: support@luna-modelling.com

    - Website: https://luna-modelling.com/contact


    Once you have your API key, include it in the `X-API-Key` header with every
    request.
  version: 1.0.0
servers:
  - url: https://api.luna-modelling.com/v1
    description: Production server
  - url: http://localhost:8000/v1
    description: Development server
security:
  - ApiKeyAuth: []
paths:
  /{account_id}/kalman:
    post:
      tags:
        - Kalman Filter
      summary: Apply Kalman filtering to time series data
      description: >
        Processes time series data using a Kalman filter to reduce noise and
        provide

        smoothed predictions. Optionally saves results to the database with a
        unique identifier.
      operationId: kalmanFilter
      parameters:
        - name: account_id
          in: path
          required: true
          description: The account ID associated with your API key
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/KalmanInput'
            examples:
              basic:
                summary: Basic filtering without saving
                value:
                  results:
                    - - 10.2
                      - 10.5
                      - 10.1
                      - 9.8
                      - 10.3
                  save: false
              with_save:
                summary: Filter and save to database
                value:
                  results:
                    - - 10.2
                      - 10.5
                      - 10.1
                      - 9.8
                      - 10.3
                      - 10
                      - 9.9
                      - 10.4
                  save: true
                  unique_identifier: sensor-001-2024
      responses:
        '200':
          description: Successfully processed the Kalman filter
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KalmanOutput'
              example:
                filtered_data:
                  - 10.2
                  - 10.35
                  - 10.25
                  - 10.02
                  - 10.15
                  - 10.08
                  - 10.01
                  - 10.22
                raw_state:
                  - 10.2
                  - 10.35
                  - 10.25
                  - 10.02
                  - 10.15
                  - 10.08
                  - 10.01
                  - 10.22
                smooth_state:
                  - 10.2
                  - 10.33
                  - 10.27
                  - 10.05
                  - 10.13
                  - 10.09
                  - 10.03
                  - 10.2
                input_data:
                  - - 10.2
                    - 10.5
                    - 10.1
                    - 9.8
                    - 10.3
                    - 10
                    - 9.9
                    - 10.4
        '400':
          description: Bad request - Invalid input data or missing required fields
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                detail: unique_identifier is required when save is True
        '403':
          description: Quota exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                detail: Quota exceeded. Please upgrade your plan.
        '404':
          description: Account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                detail: Account not found.
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                detail: An unexpected error occurred
components:
  schemas:
    KalmanInput:
      type: object
      required:
        - results
      properties:
        results:
          type: array
          description: A 2D array where each inner list contains time series values
          items:
            type: array
            items:
              type: number
              format: float
          example:
            - - 10.2
              - 10.5
              - 10.1
              - 9.8
              - 10.3
        save:
          type: boolean
          default: false
          description: Whether to save the results to the database
        unique_identifier:
          type: string
          nullable: true
          description: The unique identifier for the data (required when save is true)
          example: sensor-001-2024
    KalmanOutput:
      type: object
      properties:
        filtered_data:
          type: array
          description: The filtered time series values after applying the Kalman filter
          items:
            type: number
            format: float
        raw_state:
          type: array
          description: The raw state values from the Kalman filter
          items:
            type: number
            format: float
        smooth_state:
          type: array
          description: The smoothed state values from the Kalman filter
          items:
            type: number
            format: float
        input_data:
          type: array
          description: The original input data
          items:
            type: array
            items:
              type: number
              format: float
    Error:
      type: object
      properties:
        detail:
          type: string
          description: Error message
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key for authentication

````