#!/usr/bin/env python3 """How far from the sensor does a coil-cancelled field stay near 30 nT? A geometry estimate. The mint paper reports one sensor "at the geometric center of the coil assembly" and ~30 nT. It refers to Agliassa et al. (2018) for the system: three orthogonal pairs of octagonal coils, X 128 cm across and 55 cm apart, Y (vertical) 150 and 67, Z 135 and 59, cancelling Bx = 6.39, By = 36.08, Bz = 20.40 uT. RULES, fixed before the first run (2026-11-04): 1. Ideal coils, thin wire, regular octagons, and a perfectly uniform ambient field. Real rooms are worse, so this is a lower bound on the residual, due to the coils' geometry alone. 2. "128 cm across" is ambiguous for an octagon, so run it twice: across corners and across flats. 3. Each pair's current is set so its field cancels that axis's ambient component exactly at the centre. 4. Report the residual |B| along each axis at 5-35 cm from the centre, the worst point on a sphere of each radius, and the share of a 50 x 50 x 50 cm and a 30 x 30 x 30 cm cube below 100 nT, 300 nT and 1 uT. 5. This says nothing on what the plants felt in fact. The paper does not give their positions, or how many shared the coil at once. At least 30 per treatment, in 500 mL flasks, would need a footprint of roughly 60 x 50 cm if they were in the coil together. 6. Added after a fresh review of the page (RULES_review_addendum.txt, R6), not before the first run: at least 4,000 directions on each sphere plus the six axis directions, because 60 directions missed the worst point; worst and median at each radius; and a run at twice the linear size, for the frame of about 2 m that the lab gives elsewhere (Bertea et al. 2015). Ambient and geometry are otherwise unchanged. The arithmetic now uses numpy, with the same element sums. Needs numpy. Run with `py -3.12 -I` on this machine. Usage: py -3.12 -I coil_uniformity.py """ import json import math import sys import numpy as np MU0_4PI = 1e-7 AMBIENT = (6.39e-6, 36.08e-6, 20.40e-6) COILS = {0: (1.28, 0.55), 1: (1.50, 0.67), 2: (1.35, 0.59)} # axis: (across, separation), metres def octagon(across, across_type): circum = across / 2.0 if across_type == "corners" else (across / 2.0) / math.cos(math.pi / 8) return [(circum * math.cos(math.pi / 8 + k * math.pi / 4), circum * math.sin(math.pi / 8 + k * math.pi / 4)) for k in range(8)] def segments(axis, across, sep, across_type, n=24): """Small current elements of both coils of a pair, as arrays of midpoints and dl, in metres.""" u, v = [(1, 2), (2, 0), (0, 1)][axis] # right-handed, so that positive current gives +axis field mids, dls = [], [] corners = octagon(across, across_type) for side in (-sep / 2.0, sep / 2.0): for k in range(8): a, b = corners[k], corners[(k + 1) % 8] for i in range(n): t = (i + 0.5) / n mid = [0.0, 0.0, 0.0] dl = [0.0, 0.0, 0.0] mid[axis] = side mid[u] = a[0] + t * (b[0] - a[0]) mid[v] = a[1] + t * (b[1] - a[1]) dl[u] = (b[0] - a[0]) / n dl[v] = (b[1] - a[1]) / n mids.append(mid) dls.append(dl) return np.array(mids), np.array(dls) def field_of(elems, points): mids, dls = elems r = points[:, None, :] - mids[None, :, :] r3 = ((r * r).sum(axis=2)) ** 1.5 return MU0_4PI * (np.cross(dls[None, :, :], r) / r3[:, :, None]).sum(axis=1) def directions(n=4000): """A Fibonacci lattice on the sphere, plus the six axis directions.""" i = np.arange(n) z = 1 - 2 * (i + 0.5) / n rho = np.sqrt(1 - z * z) phi = math.pi * (3 - math.sqrt(5)) * i pts = np.stack([rho * np.cos(phi), rho * np.sin(phi), z], axis=1) return np.concatenate([pts, np.array([[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]], dtype=float)]) def run(across_type, scale=1.0): pairs = {} ambient = np.array(AMBIENT) for axis, (across, sep) in COILS.items(): elems = segments(axis, across * scale, sep * scale, across_type) centre = field_of(elems, np.zeros((1, 3)))[0] pairs[axis] = (elems, -AMBIENT[axis] / centre[axis]) # current for cancellation at the centre def residual(points): b = np.tile(ambient, (len(points), 1)) for elems, cur in pairs.values(): b = b + cur * field_of(elems, points) return np.sqrt((b * b).sum(axis=1)) * 1e9 # nT out = {"across_is": across_type, "linear_scale": scale, "at_centre_nT": round(float(residual(np.zeros((1, 3)))[0]), 3), "axes": {}, "sphere": {}, "cubes": {}} for name, unit in (("x", (1, 0, 0)), ("y_vertical", (0, 1, 0)), ("z", (0, 0, 1))): out["axes"][name] = {str(cm): round(float(residual(np.array([unit], dtype=float) * cm / 100.0)[0]), 1) for cm in (5, 10, 15, 20, 25, 30, 35)} dirs = directions() for cm in (5, 10, 15, 20, 25, 30): vals = residual(dirs * cm / 100.0) out["sphere"][str(cm)] = {"worst_nT": round(float(vals.max()), 1), "median_nT": round(float(np.median(vals)), 1)} for side in (30, 50): grid = (-0.5 + (np.arange(7) + 0.5) / 7) * side / 100.0 vals = residual(np.array([(x, y, z) for x in grid for y in grid for z in grid])) out["cubes"][f"{side}cm"] = {"median_nT": round(float(np.sort(vals)[len(vals) // 2]), 1), "max_nT": round(float(vals.max()), 1), **{f"share_below_{lev}_nT": round(float((vals < lev).mean()), 3) for lev in (100, 300, 1000)}} return out res = {"rules": "see the script's docstring", "runs": [run("corners"), run("flats"), run("corners", 2.0), run("flats", 2.0)]} sys.stdout.reconfigure(encoding="utf-8") print(json.dumps(res["runs"], indent=1)) with open(sys.argv[1], "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=1)