Skip to content

Commit

Permalink
[recipes] update col reference syntax in Newton acc recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindaar committed May 6, 2024
1 parent f3c0384 commit fcf3c11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions recipes.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions recipes/rNewtonAcceleration.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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¯²"})

Expand All @@ -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

Expand Down

0 comments on commit fcf3c11

Please sign in to comment.