"""SO2 accumulation check (Our analysis), section 11 point 4 of the full page. Rules in RULES_so2_accumulation_before_running.txt. Also gives, for point 1, the dates of Ls 105, 107 and 113 in Mars year 36: a date conversion, outside those rules. Uses only the paper's stated numbers plus constants; reads no downloaded file. Usage: python3 -I so2_accumulation.py """ import sys, json, math, datetime as dt M_AIR, M_SO2, M_HCL = 43.34, 64.066, 36.461 M_ATM = 2.5e16 # kg (paper pp. 3-5) SOL = 88775.244 # s MY_SOLS = 668.6 # sols in a Mars year TAU_SO2 = MY_SOLS * SOL # "~1 MY" (SM p. 14) def ls_of_jd(jd_tt): # Allison & McEwen (2000), as in mars_dates_and_distances.py d = jd_tt - 2451545.0 M = math.radians(19.3871 + 0.52402073 * d) a_fms = 270.3871 + 0.524038496 * d A = [0.0071, 0.0057, 0.0039, 0.0037, 0.0021, 0.0020, 0.0018] tau = [2.2353, 2.7543, 1.1177, 15.7866, 2.1354, 2.4694, 32.8493] phi = [49.409, 168.173, 191.837, 21.736, 15.704, 95.528, 49.095] pbs = sum(A[i] * math.cos(math.radians(0.985626 * d / tau[i] + phi[i])) for i in range(7)) v_m = (10.691 + 3.0e-7 * d) * math.sin(M) + 0.623 * math.sin(2 * M) + 0.050 * math.sin(3 * M) \ + 0.005 * math.sin(4 * M) + 0.0005 * math.sin(5 * M) + pbs return (a_fms + v_m) % 360.0 def jd(t): return t.timestamp() / 86400.0 + 2440587.5 + 69.184 / 86400.0 def first_time_at(ls_target, start): t = start while ls_of_jd(jd(t)) < ls_target: t += dt.timedelta(minutes=30) return t start = dt.datetime(2023, 6, 1, tzinfo=dt.timezone.utc) # MY37 Ls ~ 80 t1, t2 = first_time_at(107.56, start), first_time_at(118.75, start) window_sols = (t2 - t1).total_seconds() / SOL duty_window = window_sols / MY_SOLS # point 1: Ls 105 (the 2024 paper's Mars-year-36 detection) and the conjunction gap, Ls 107-113 (SM p. 2) my36 = {f'Ls {ls}': first_time_at(ls, dt.datetime(2021, 8, 1, tzinfo=dt.timezone.utc)).strftime('%Y-%m-%d') for ls in (105, 107, 113)} rows = [] for F_hcl in (2.4, 3.0): for r in (1.0, 4.0): F_so2 = F_hcl * r * M_SO2 / M_HCL # kg/s for label, d in (('continuous', 1.0), ('detection window only', duty_window)): mass = F_so2 * d * TAU_SO2 vmr_ppbv = mass / M_ATM * (M_AIR / M_SO2) * 1e9 rows.append(dict(F_HCl_kg_s=F_hcl, SO2_to_HCl_molar=r, F_SO2_kg_s=round(F_so2, 2), duty=label, duty_fraction=round(d, 4), SO2_burden_kt=round(mass / 1e6, 1), global_SO2_ppbv=round(vmr_ppbv, 2))) res = dict(window_utc=[t1.strftime('%Y-%m-%d %H:%M'), t2.strftime('%Y-%m-%d %H:%M')], window_sols=round(window_sols, 1), duty_fraction_window=round(duty_window, 4), tau_SO2_sols=MY_SOLS, rows=rows, compare_disc_limits_ppbv='0.3 (paper p. 1); 0.3-1 (SM p. 13)', my36_dates_utc=my36) with open(sys.argv[1], 'w', encoding='utf-8', newline='\n') as f: json.dump(res, f, indent=1) print(json.dumps(res, indent=1))