From fcf3c11f4846d20b8a91923f638ced300ab7fce5 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 6 May 2024 11:57:58 +0200 Subject: [PATCH] [recipes] update `col` reference syntax in Newton acc recipe --- recipes.org | 4 ++-- recipes/rNewtonAcceleration.nim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes.org b/recipes.org index 2ec5ae31..a5d6bfd3 100644 --- a/recipes.org +++ b/recipes.org @@ -2447,7 +2447,7 @@ This gives us two =seq[float]=, but we need a =DataFrame=. So we combine the two: #+BEGIN_SRC nim :tangle recipes/rNewtonAcceleration.nim var df = toDf({ "r / m" : radii, - "g(r) / m s¯²" : a}) + "g(r) / m s¯²" : a}) #+END_SRC which gives us a data frame with two columns. The names are, as one can guess, the given strings. (Note that in practice one might not want to @@ -2481,7 +2481,7 @@ At this point we might ask "Do we recover the known 9.81 m/s^2 at the surface?". Let's see. There's many different ways we could go on about this. We'll use summarize: #+BEGIN_SRC nim :tangle recipes/rNewtonAcceleration.nim -let maxG = df.summarize(f{float: "g_max" << max(c"g(r) / m s¯²")}) +let maxG = df.summarize(f{float: "g_max" << max(col("g(r) / m s¯²"))}) #+END_SRC An alternative way would be to access the data column directly, like diff --git a/recipes/rNewtonAcceleration.nim b/recipes/rNewtonAcceleration.nim index 63b7b6d0..60c059e1 100644 --- a/recipes/rNewtonAcceleration.nim +++ b/recipes/rNewtonAcceleration.nim @@ -19,7 +19,7 @@ let radii = linspace(0.0, 35_000_000, 1000) # up to geostationary orbit let a = radii.mapIt(newtonAcceleration(it)) var df = toDf({ "r / m" : radii, - "g(r) / m s¯²" : a}) + "g(r) / m s¯²" : a}) df = df.transmute(f{"r / km" ~ c"r / m" / 1000.0}, f{"g(r) / m s¯²"}) @@ -28,7 +28,7 @@ ggplot(df, aes("r / km", "g(r) / m s¯²")) + ggtitle("Gravitational acceleration of Earth depending on radial distance") + ggsave("media/recipes/rNewtonAcceleration.png") -let maxG = df.summarize(f{float: "g_max" << max(c"g(r) / m s¯²")}) +let maxG = df.summarize(f{float: "g_max" << max(col("g(r) / m s¯²"))}) let maxG_alt = df["g(r) / m s¯²"].toTensor(float).max