﻿# Astropy Quantity value extraction does not imply unit conversion

Astropy Quantity value extraction does not imply unit conversion. A focused scientific-computing guide with the documented mechanism, a reproducible validation scenario, evidence and operational limits.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/science-astropy-quantity-value-explicit-unit/
Language: en

Extracting Quantity.value returns a number in the quantity's current unit; it does not convert that number to the unit a model expects. Two physically equal observations can therefore become different numerical inputs if an importer strips units first. Scientific AI preparation needs an explicit target-unit conversion before unitless tensor construction.

## The scientific interface

Astropy exposes a Quantity's unit and value separately and provides to or to_value for requested conversions. Reading value alone preserves the current representation's magnitude. A numerical array with stripped units no longer carries the conversion obligation automatically. A changed input source can therefore introduce a scale discrepancy without changing the tensor shape or dtype. Unit compatibility is also different from arbitrary equality of unit strings, and supported equivalencies must be intentional rather than assumed for unrelated physical quantities.

## Implementation details

Define target units in the feature schema and convert while Quantity information is still available. Record the original unit, selected conversion and effective tensor unit as provenance. Validate incompatible inputs before stripping metadata. Keep numerical normalization, such as centering or scaling for a model, separate from physical conversion so inverse interpretation can be checked. If a scientific equivalency is required, preserve its explicit configuration. Do not infer that a dimensionless model output has the desired physical unit unless the output contract and inverse transformations establish it.

## A constructed validation case

Prepare physically equal quantities expressed in different compatible units and convert them through the intended model-input path. Compare effective numerical values in the declared target unit. Add a deliberately value-only extraction and an incompatible-unit input as separate negative cases. Verify inverse output interpretation under the same schema. Acceptance requires unit-consistent values and visible rejection or reviewed equivalency where needed, not equality of raw magnitudes or a test that only checks tensor shape. Preserve the fixture units and conversion configuration for later source changes.

## Numerical and data limits

Unit consistency does not establish sensor calibration or physical-model accuracy. It establishes the meaning of numerical values crossing the tensor boundary. Keep that meaning explicit before comparing scientific AI predictions so a representation scale error is not mistaken for learned-model bias or a need for more compute.

## Primary references

[Astropy Quantity values and conversions](https://docs.astropy.org/en/stable/units/quantity.html); [Astropy units and quantities](https://docs.astropy.org/en/stable/units/index.html).

This is a proposed scientific-interface validation, not an executed Retrivium benchmark. Preserve the implementation version and unresolved outcomes; interface documentation does not establish the accuracy or performance of a scientific model.

## Related reading

[Tensor axes in a language model: batch, sequence and hidden width](/journal/tensor-axes-batch-sequence-hidden/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
