calamari.sample.Sample#
- class calamari.sample.Sample(name, mass_mg=None, mass_source=None, molar_mass_g_per_mol=None, magnetic_ions_per_fu=None, shape=None, orientation=None, comment=None)#
Bases:
objectThe physical-sample facts needed to convert raw readings to physics units.
Frozen (immutable) per the house rule that nothing mutates a
MeasurementorSamplein place – derive a newSample(e.g. viadataclasses.replace()) rather than editing one.Every field defaults to
Noneexceptname– there are no project-specific numeric defaults (no assumed mass, no assumed molar mass) because those facts are specific to whatever sample and compound the caller is actually measuring. Conversions that need a missing field raiseValueErrornaming it, rather than silently propagatingNoneinto arithmetic.- mass_mg#
Sample mass in milligrams. See
from_measurement()for how it is derived from a parsed file, andmass_sourcefor how to tell afterwards where it came from.
- mass_source#
Provenance of
mass_mg:'user'when the caller supplied it,'file'when it was read from the measurement header, orNonewhen there is no mass (or when theSamplewas constructed directly rather than viafrom_measurement(), which is the only thing that records provenance – a directly builtSampleleaves thisNonerather than inferring'user', soNonemeans “not recorded”, never “trust me”).This exists because a mass that silently came from the wrong place is the most damaging thing that can happen to a magnetometry conversion – every
muB-per-ion and molar-susceptibility number scales inversely with it. Recording the provenance turns a silent substitution into a checkable one:if sample.mass_source == "file" and name in logbook: ratio = sample.mass_mg / logbook[name] if not 0.5 < ratio < 2.0: warn(f"header mass is {ratio:.0f}x the logbook value")
- magnetic_ions_per_fu#
Number, or average number, of magnetic ions per formula unit (e.g. the number of rare-earth/transition-metal ions carrying the moment). Used by the “per ion” conversions and properties. Fractional occupancy is supported; the caller defines the counted species. Contributions from different magnetic species are not separated automatically.
- property mass_g: float#
Sample mass in grams.
- Raises:
ValueError – If
mass_mgis None.
- property moles: float#
Amount of substance, in moles of formula units.
- Raises:
ValueError – If
mass_mgormolar_mass_g_per_molis None.
- property formula_units: float#
Number of formula units in the sample (
moles * N_A).- Raises:
ValueError – If
mass_mgormolar_mass_g_per_molis None (propagated frommoles).
- property moles_magnetic_ions: float#
Amount of substance, in moles of magnetic ions.
- Raises:
ValueError – If
mass_mg,molar_mass_g_per_mol, ormagnetic_ions_per_fuis None.
- moment_emu_to_muB_per_fu(moment_emu)#
Convert a measured moment (emu) to Bohr magnetons per formula unit.
The number of formula units in the sample is
FU = moles * N_A(formula_units), andmuB_per_fu = moment_emu * MU_B_PER_EMU / FU, using the exact emu<->Bohr-magneton factor fromcalamari.constants. Older analyses often round that factor to 1.07828e20, which differs only in the 5th significant figure.- Parameters:
moment_emu (
float,numpy.ndarray, orpandas.Series) – Measured moment in emu. Returned in the same shape/type.- Returns:
float,numpy.ndarray, orpandas.Series– Moment in Bohr magnetons per formula unit.- Raises:
ValueError – If
mass_mgormolar_mass_g_per_molis None (propagated fromformula_units).
- moment_emu_to_muB_per_ion(moment_emu)#
Convert a measured moment (emu) to Bohr magnetons per magnetic ion.
Equivalent to
moment_emu_to_muB_per_fu()divided bymagnetic_ions_per_fu. The ion species is caller-defined viamagnetic_ions_per_fu, never assumed by this library.- Parameters:
moment_emu (
float,numpy.ndarray, orpandas.Series) – Measured moment in emu. Returned in the same shape/type.- Returns:
float,numpy.ndarray, orpandas.Series– Moment in Bohr magnetons per magnetic ion.- Raises:
ValueError – If
mass_mg,molar_mass_g_per_mol, ormagnetic_ions_per_fuis None.
- moment_to_chi_molar(moment_emu, field_oe)#
Molar susceptibility, emu/(mol Oe), per mole of formula units.
chi_molar = (moment_emu / field_oe) / moles, i.e. the moment per unit applied field normalised by the amount of substance (moles, formula-unit basis). Field-dependent (non-linear) moments should be evaluated in a regime wheremoment/fieldis a meaningful susceptibility (e.g. the low-field limit) – this method performs no linearity check.- Parameters:
moment_emu (
float,numpy.ndarray, orpandas.Series) – Measured moment in emu.field_oe (
float,numpy.ndarray, orpandas.Series) – Applied field in Oe, same shape asmoment_emu.
- Returns:
float,numpy.ndarray, orpandas.Series– Molar susceptibility, emu/(mol Oe), per mole of formula units.- Raises:
ValueError – If
mass_mgormolar_mass_g_per_molis None.
- moment_to_chi_molar_per_ion(moment_emu, field_oe)#
Molar susceptibility, emu/(mol Oe), per mole of magnetic ions.
As
moment_to_chi_molar()but normalised bymoles_magnetic_ionsinstead ofmoles, i.e. per mole of magnetic ion rather than per mole of formula unit – the natural basis for comparing a Curie constant to a single-ion effective moment (seemu_eff_from_curie_constant()).- Parameters:
moment_emu (
float,numpy.ndarray, orpandas.Series) – Measured moment in emu.field_oe (
float,numpy.ndarray, orpandas.Series) – Applied field in Oe, same shape asmoment_emu.
- Returns:
float,numpy.ndarray, orpandas.Series– Molar susceptibility, emu/(mol Oe), per mole of magnetic ions.- Raises:
ValueError – If
mass_mg,molar_mass_g_per_mol, ormagnetic_ions_per_fuis None.
- chi_mass(moment_emu, field_oe)#
Mass susceptibility, emu/(g Oe).
chi_mass = (moment_emu / field_oe) / mass_g. Useful when the molar mass is not known (e.g. an unidentified phase) but the sample mass is.- Parameters:
moment_emu (
float,numpy.ndarray, orpandas.Series) – Measured moment in emu.field_oe (
float,numpy.ndarray, orpandas.Series) – Applied field in Oe, same shape asmoment_emu.
- Returns:
float,numpy.ndarray, orpandas.Series– Mass susceptibility, emu/(g Oe).- Raises:
ValueError – If
mass_mgis None.
- chi_to_chi_molar(chi_emu_per_oe)#
Molar susceptibility, emu/(mol Oe), from a susceptibility in emu/Oe.
The AC-side counterpart of
moment_to_chi_molar():chi_realexposes susceptibility in emu/Oe, so normalising it needs no field – just the amount of substance.chi_molar = chi_emu_per_oe / moles.- Parameters:
chi_emu_per_oe (
float,numpy.ndarray, orpandas.Series) – Susceptibility in emu/Oe (the extensive, whole-sample quantity the instrument reports).- Returns:
float,numpy.ndarray, orpandas.Series– Molar susceptibility, emu/(mol Oe), per mole of formula units.- Raises:
ValueError – If
mass_mgormolar_mass_g_per_molis None.
- chi_to_chi_molar_per_ion(chi_emu_per_oe)#
Molar susceptibility, emu/(mol Oe), per mole of magnetic ions.
As
chi_to_chi_molar()but normalised bymoles_magnetic_ions– the AC-side counterpart ofmoment_to_chi_molar_per_ion().- Raises:
ValueError – If
mass_mg,molar_mass_g_per_mol, ormagnetic_ions_per_fuis None.
- chi_to_chi_mass(chi_emu_per_oe)#
Mass susceptibility, emu/(g Oe), from a susceptibility in emu/Oe.
As
chi_to_chi_molar()but normalised bymass_g– the AC-side counterpart ofchi_mass(), for when the molar mass is not known but the sample mass is.- Raises:
ValueError – If
mass_mgis None.
- classmethod from_measurement(m, *, mass_mg=None, **overrides)#
Build a
Samplefrom a parsed file’s header metadata.The mass is resolved by a single rule – the caller wins, then the file – and where it came from is recorded on
mass_source:mass_mggiven?File records a mass?
Result
yes
either
caller’s value,
'user'no
yes
file’s value,
'file'no
no
None,NoneThe file mass comes from SAMPLE_MASS through
sample_mass_mg. This is an operator-entered value, not an independently verified specimen fact. Check it against the weighing record before using mass normalisation.The sample name defaults to
m.sample_name(falling back to'unknown'if the header carries none); every otherSamplefield (molar_mass_g_per_mol,magnetic_ions_per_fu,shape,orientation,comment) has no file-derived source and must be supplied via**overridesif needed.- Parameters:
m (
Measurement) – Parsed measurement (seecalamari.io).mass_mg (
float|None) – Sample mass in mg, overriding whatever the file records. PassingNone(the default) is not an assertion that there is no mass – it simply means “use the file’s, if it has one”, somass_mg=logbook.get(name)behaves sensibly for a sample you have no logbook entry for. Has no project-specific default; callers own it.**overrides – Additional
Samplefields, forwarded to the constructor. These are applied last, so passingmass_sourcehere overrides the derived provenance – don’t, unless you are deliberately re-labelling it.
- Return type:
- Returns: