Skip to main content

Generated from aind-library-template

Project description

aind-metadata-validator

This package includes helper functions for validating metadata from aind-data-schema, individual files in a metadata.json file, and the fields within each file.

All validation returns a MetadataState enum, see utils.py

Get status

By ID

Use aind-data-access-api [todo]

Full table

You can get the entire redshift status table by running:

from aind_data_access_api.rds_tables import RDSCredentials
from aind_data_access_api.rds_tables import Client
import pandas as pd

DEV_OR_PROD = "dev" if "test" in API_GATEWAY_HOST else "prod"
REDSHIFT_SECRETS = f"/aind/{DEV_OR_PROD}/redshift/credentials/readwrite"
RDS_TABLE_NAME = f"metadata_status_{DEV_OR_PROD}"

rds_client = Client(
        credentials=RDSCredentials(
            aws_secrets_name=REDSHIFT_SECRETS
        ),
    )

class MetadataState(int, Enum):
    VALID = 2  # validates as it's class
    PRESENT = 1  # present
    OPTIONAL = 0  # missing, but it's optional
    MISSING = -1  # missing, and it's required
    EXCLUDED = -2  # excluded for all modalities in the metadata
    CORRUPT = -3  # corrupt, can't be loaded from json


def _get_status() -> pd.DataFrame:
    """Get the status of the metadata
    """
    response = rds_client.read_table(RDS_TABLE_NAME)

    # returns int values, can be compared against MetadataState
    return response

Metadata validation

Returns a dictionary where each key is metadata, a file, or a file.field and the value is the MetadataState.

from aind_metadata_validator.metadata_validator import validate_metadata

m = Metadata()

results_df = validate_metadata(m.model_dump())

Redshift sync

Run on Code Ocean

Two code ocean capsules run the sync nightly: https://codeocean.allenneuraldynamics.org/capsule/0257223/tree and https://codeocean.allenneuraldynamics-test.org/capsule/3640490/tree

Run locally

The package also includes a function run() in sync.py that will validate the entire DocDB and push the results to redshift.

pip install aind-metadata-validator

from aind_metadata_validator.sync import run

run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aind_metadata_validator-0.11.4.tar.gz (97.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aind_metadata_validator-0.11.4-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file aind_metadata_validator-0.11.4.tar.gz.

File metadata

  • Download URL: aind_metadata_validator-0.11.4.tar.gz
  • Upload date:
  • Size: 97.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aind_metadata_validator-0.11.4.tar.gz
Algorithm Hash digest
SHA256 4669a4baf04eb957f30b7d5a2740872b5becc4086455554874e3cdf5bbef5be0
MD5 df4be53c1925954346f9878f893f0056
BLAKE2b-256 0ec5e42f40de0879e81f9563ec6eaab13f34c7baa34ceb236eba89b3e3c08061

See more details on using hashes here.

File details

Details for the file aind_metadata_validator-0.11.4-py3-none-any.whl.

File metadata

File hashes

Hashes for aind_metadata_validator-0.11.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f2502d100e7641d6df6fb0d2cacde5d3f89d1e53d2a12959dc2fd574c2c6b134
MD5 c278efeabf5d3999c3dc9c2305b3c88e
BLAKE2b-256 8fb1818d6f767eeeafd2085a33e7b13259015ea80f3dd27d3ec8b0ae2cb1481e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page