fairdm.core.measurement.models#

Models for measurements and their related descriptions, dates and identifiers.

Module Contents#

Classes#

EffectiveLocation

Where a measurement is for a viewer, and whose location that is.

Measurement

A record of a specific observation or calculation made on a sample.

VocabularyGuardedSave

Refuse a type outside the record’s own collection, even on a direct save.

MeasurementDescription

Typed free-text description of a measurement.

MeasurementDate

Typed date on a measurement.

MeasurementIdentifier

Typed external identifier of a measurement.

API#

class EffectiveLocation#

Bases: typing.NamedTuple

Where a measurement is for a viewer, and whose location that is.

Attributes: point: The point, in SRID 4326. elevation: Metres above mean sea level, or None. uncertainty: Metres, or None. source: "own" for the measurement’s own location, "sample" for its sample’s.

point: django.contrib.gis.geos.Point#

None

elevation: float | None#

None

uncertainty: float | None#

None

source: str#

None

class Measurement(*args, **kwargs)#

Bases: fairdm.core.abstract.BasePolymorphicModel

A record of a specific observation or calculation made on a sample.

A polymorphic model: domain-specific measurement types inherit from this base. Subclasses should define value and optionally uncertainty fields for get_value() and print_value() to work.

Attributes: CONTRIBUTOR_ROLES: The roles a contributor can hold on a measurement. DESCRIPTION_TYPES: The description types a measurement can carry. DATE_TYPES: The date types a measurement can carry. objects: The manager, with the MeasurementQuerySet helpers. dataset: The dataset this measurement belongs to. uuid: Unique short identifier with an m prefix. contributors: Generic relation to contributor records. sample: The sample on which the measurement was made. local_id: The creator’s own identifier for the measurement within its dataset. location: The point where the measurement was made, in WGS 84. location_elevation: Metres above mean sea level. location_uncertainty: Metres within which the true place lies.

Initialization

CONTRIBUTOR_ROLES#

None

DESCRIPTION_TYPES#

None

DATE_TYPES#

None

objects#

‘(…)’

dataset#

‘ForeignKey(…)’

uuid#

‘ShortUUIDField(…)’

contributors#

‘GenericRelation(…)’

sample#

‘ForeignKey(…)’

local_id#

‘CharField(…)’

location#

‘PointField(…)’

location_elevation#

‘FloatField(…)’

location_uncertainty#

‘FloatField(…)’

class Meta#
verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

ordering#

[‘-modified’]

‘measurements’

indexes#

None

constraints#

‘location_constraints(…)’

permissions#

None

clean()#

Refuse a bare Measurement, and a change of dataset that leaves nobody to manage it.

type_of()#

Return the base Measurement class for polymorphic queries.

get_value()#

Return the measurement value, with its uncertainty when there is one.

A type is not obliged to nominate a pint quantity for value, so uncertainty arithmetic is only attempted where the value supports it.

Returns: The value with its plus_minus uncertainty applied when both exist, the plain value otherwise, or the name when the class defines no value (the base class).

print_value()#

Return the value and its uncertainty as a string for a person.

Delegates to the framework’s quantity formatter, which renders a pint Measurement as “value ± error unit”, rather than building a string by hand.

Returns: The formatted value.

effective_location_for(user=None)#

Return where the measurement is for a viewer: its own location, else its sample’s.

The sample’s is used only where the viewer may open the sample, by the same rule as MeasurementQuerySet.with_effective_location.

Args: user: The viewer, or None for a visitor who is not signed in.

Returns: An EffectiveLocation naming the point, its elevation and uncertainty and whose location it is, or None when the viewer has none to be shown.

get_absolute_url()#

Return the URL of the measurement’s own detail page.

get_template_name()#

Return the card templates to try for this measurement, in order of preference.

Returns: The template paths.

class VocabularyGuardedSave#

Refuse a type outside the record’s own collection, even on a direct save.

A concept field checks its collection only in full_clean(), which a manager’s create() and a bare save() never call. Subclasses set VOCABULARY_NOUN for the error message.

Attributes: VOCABULARY_NOUN: The noun in “‘x’ is not a valid Measurement type.”

VOCABULARY_NOUN = <Multiline-String>#
save(*args, **kwargs)#

Refuse a type that is not in the collection, then save.

class MeasurementDescription(*args, **kwargs)#

Bases: fairdm.core.measurement.models.VocabularyGuardedSave, fairdm.core.abstract.AbstractDescription

Typed free-text description of a measurement.

Initialization

VOCABULARY_NOUN#

‘description’

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

class MeasurementDate(*args, **kwargs)#

Bases: fairdm.core.measurement.models.VocabularyGuardedSave, fairdm.core.abstract.AbstractDate

Typed date on a measurement.

Initialization

VOCABULARY_NOUN#

‘date’

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

class MeasurementIdentifier(*args, **kwargs)#

Bases: fairdm.core.measurement.models.VocabularyGuardedSave, fairdm.core.abstract.AbstractIdentifier

Typed external identifier of a measurement.

Drawn from the measurement identifier collection rather than the unscoped vocabulary, so a member added for another record type (such as IGSN for samples) cannot leak in here.

Initialization

VOCABULARY_NOUN#

‘identifier’

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’