[WSG20] Programming Fundamentals Week 4

This week we will be looking at the following topics:

  • Tuesday May 26: Dataset
  • Wednesday May 27: Package Development
  • Thursday May 28: Workbench
  • Friday May 29: Useful Tips and Session Wrap Up

Please post your questions on this thread and look out for daily challenges.

6 Likes

Did you mean Friday May 29 ?

Sorry. That was a typo.

May 26-27 Challenge: From EIWL …

Find a dataset of the 5 largest observed altitudes in the Fireballs & Bolides dataset.

Extra credit:

Plot the nearest cities for the 10 entries with largest altitudes in the Fireballs & Bolides dataset, labeling each city.

ResourceData[“Fireballs and Bolides”][TakeLargestBy[#Altitude &, 5]]

ResourceData["Fireballs and Bolides"][
  TakeLargestBy[#Altitude &, 10],
  "Coordinates",
  GeoNearest[Entity["City"], #] &][
 GeoListPlot[#, GeoLabels -> True, PlotLegends -> None] &]

2 Likes

Hi Abrita,

During the Tuesday webinar someone asked if there is a way to tell if Dataset operators are ascending or descending. There are undocumented functions AscendingQ and DescendingQ in the Dataset package that do this. See this post for details.

Dataset`AscendingQ /@ {Total, Select, All, Key["a"]}
(* {True, True, False, False} *)
3 Likes

Excellent. Thanks for sharing!

2 Likes

Part 1:
ResourceData[ResourceObject[“Fireballs and Bolides”], “Dataset”][
Select[QuantityQ[#Altitude] &] /*
TakeLargestBy[QuantityMagnitude[#Altitude] &, 5]]

Extra Credit:
GeoListPlot[
Normal@ResourceData[ResourceObject[“Fireballs and Bolides”],
“Dataset”][
Select[QuantityQ[#Altitude] &] /*
TakeLargestBy[QuantityMagnitude[#Altitude] &, 10], “NearestCity”],
GeoLabels → True]

1 Like

End-of-study-group open challenge: To all the enthusiastic study group participants … post a snippet of code using your favorite Wolfram Language function–may be something you learned in one of the study group sessions.

Feel free to “Like” posts by fellow study group participants and we will declare the most liked post, at our last session, on Friday.

1 Like

CHALLENGE: Find a dataset of the 5 largest observed altitudes in the Fireballs & Bolides dataset.

ballBols = ResourceData["Fireballs and Bolides"];
ballBols[TakeLargestBy["Altitude", 5]][All, "Altitude"]

A little context and styling:

Dataset[Take[ReverseSort@ballBols[All, {"Altitude", "NearestCity"}], 
  5], HeaderBackground -> Lighter@Red, 
 HeaderDisplayFunction -> (Style[#, Bold, 18] &)]
(*nicer with headers to show context*)

BONUS: Plot the nearest cities for the 10 entries with largest altitudes in the Fireballs & Bolides dataset, labeling each city.

nearCity = ballBols[TakeLargestBy["Altitude", 10]][All, "NearestCity"]

Plot with easy with read lables:

GeoListPlot[nearCity, GeoLabels -> Automatic, 
 PlotMarkers -> GeoMarker, GeoBackground -> "ReliefMap", 
 LabelStyle -> {Darker@Red, 14, Background -> LightYellow}]
(*large, easy to read labels*)

4 Likes
2 Likes

Here is a link to the Wolfram support article for installing Workbench.

3 Likes

Hello all!

My favorite Wolfram Language function is Manipulate because it is simply one of the best ways to show young people how patterns develop and change.

This code is inspired by John. H. Conway (1937-2020), Richard K. Guy (1916-2020) in their Book of Numbers (Springer-Verlag 1996, page 31, Figure 2.10).

ENJOY!

Manipulate[Multicolumn[show[n], columns, Appearance -> "Horizontal"],
 
 {{columns, 10}, 5, 25, 1}, {{n, 25, "Numbers to display:"}, 5, 1000, 
  1}, {show, {redDots -> "Dots", redSquares -> "Numbers"}},
 
 LabelStyle -> {14, FontFamily -> "Times"},
 FrameLabel -> {"", "", 
   Column[{Style["What Shapes Do The Red Figures Make?", Bold, 18],
     Style["(a.k.a. Residue Classes for Kids)", Gray]}, 
    Alignment -> Center], ""},
 
 Initialization :> {
   tinyCircRed = 
    Graphics[{Darker@Red, Disk[{0, 0}, .01]}, ImageSize -> 5],
   tinyCircGray = 
    Graphics[{Lighter@RGBColor[.9, .9, .9], Disk[{0, 0}, .01]}, 
     ImageSize -> 5],
   
   redSquares[max_] := Table[
     If[IntegerQ[Sqrt[x]] == True, 
      Style[x, Darker@Red, 16, Bold, FontFamily -> "Times"], 
      Style[x, Lighter@Gray]], {x, 1, max, 1}],
   
   redDots[max_] := Table[
     If[IntegerQ[Sqrt[x]] == True, tinyCircRed, tinyCircGray], {x, 0, 
      max, 1}]}]

3 Likes

Thanks, Abrita,

This has been a BLAST!!! :slight_smile:

2 Likes
5 Likes

The published notebook does not seem to render correctly in all browsers, when being viewed on this community page. You might try it using the “Make Your Own Copy” button. This always worked for me.

1 Like

My favorites: Manipulate and all kinds of Entity functions!

Now that many art galleries are closed around the world, here is a small app that shows random paintings from the Wolfram entities by different centuries.

In case the Manipulate is not working on this site, here is a screenshot:

I started by writing an oneliner showing a list of random paintings, then used Select function to filter paintings by year and wrapped Manipulate around the whole thing. Lastly, I added some error handling in case of missing data or if filtering returned an empty list.

6 Likes

f[t_, n_] := -t^n {Cos@t Sin@t^2, Sin@t Cos@t^2};
ParametricPlot[
Evaluate[f[t, #] & /@ Range[0, 1, 0.1]], {t, 24 [Pi], 48 [Pi]},
Axes → False, PlotStyle → Thick]

4 Likes

Abrita,
I haven’t received the link to the exercises that were mentioned in the webinar earlier today.If that’s because you haven’t sent it out yet that’s fine.
Regards,
Rajeev

1 Like

Yup link to the exercises will go out on Tuesday.
Thanks.

1 Like