Skip to content

Commit fcf3c11

Browse files
committed
[recipes] update col reference syntax in Newton acc recipe
1 parent f3c0384 commit fcf3c11

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

recipes.org

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ This gives us two =seq[float]=, but we need a =DataFrame=. So we
24472447
combine the two:
24482448
#+BEGIN_SRC nim :tangle recipes/rNewtonAcceleration.nim
24492449
var df = toDf({ "r / m" : radii,
2450-
"g(r) / m s¯²" : a})
2450+
"g(r) / m s¯²" : a})
24512451
#+END_SRC
24522452
which gives us a data frame with two columns. The names are, as one can
24532453
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
24812481
surface?". Let's see. There's many different ways we could go on about
24822482
this. We'll use summarize:
24832483
#+BEGIN_SRC nim :tangle recipes/rNewtonAcceleration.nim
2484-
let maxG = df.summarize(f{float: "g_max" << max(c"g(r) / m s¯²")})
2484+
let maxG = df.summarize(f{float: "g_max" << max(col("g(r) / m s¯²"))})
24852485
#+END_SRC
24862486

24872487
An alternative way would be to access the data column directly, like

recipes/rNewtonAcceleration.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let radii = linspace(0.0, 35_000_000, 1000) # up to geostationary orbit
1919
let a = radii.mapIt(newtonAcceleration(it))
2020

2121
var df = toDf({ "r / m" : radii,
22-
"g(r) / m s¯²" : a})
22+
"g(r) / m s¯²" : a})
2323

2424
df = df.transmute(f{"r / km" ~ c"r / m" / 1000.0}, f{"g(r) / m s¯²"})
2525

@@ -28,7 +28,7 @@ ggplot(df, aes("r / km", "g(r) / m s¯²")) +
2828
ggtitle("Gravitational acceleration of Earth depending on radial distance") +
2929
ggsave("media/recipes/rNewtonAcceleration.png")
3030

31-
let maxG = df.summarize(f{float: "g_max" << max(c"g(r) / m s¯²")})
31+
let maxG = df.summarize(f{float: "g_max" << max(col("g(r) / m s¯²"))})
3232

3333
let maxG_alt = df["g(r) / m s¯²"].toTensor(float).max
3434

0 commit comments

Comments
 (0)