Message Boards Message Boards

Issue with GeoGraphics using a variable

Posted 1 year ago

I'm working on a GeoGraphics plot of hurricane wind field data, which I have set up as the following (first two values are the lat and lng, the rest are values for the chart).

forecast = {
  {19.1, -82.7, 20, 0, 0, 0, 40, 40, 0, 30, 100, 80, 40, 90},
  {20.7, -83.5, 20, 20, 15, 20, 50, 50, 30, 40, 110, 100, 60, 100},
  {22.7, -84.0, 25, 25, 20, 20, 60, 50, 40, 50, 130, 120, 80, 110},
  {24.5, -84.0, 30, 30, 25, 25, 70, 60, 50, 60, 140, 130, 100, 130},
  {26.1, -83.8, 40, 40, 30, 35, 80, 70, 60, 70, 160, 140, 110, 150},
  {27.2, -83.5, 0, 0, 0, 0, 80, 70, 60, 70, 180, 130, 120, 150},
  {28.0, -83.2, 0, 0, 0, 0, 90, 50, 60, 80, 180, 130, 120, 150}
  }

If I use the following, I get a chart just fine:

GeoGraphics[
 {
  Red,
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[3]], "nmi"], {0, 90}],
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[4]], "nmi"], {90, 180}], 
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[5]], "nmi"], {180, 270}], 
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[6]], "nmi"], {270, 360}],
  Yellow,
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[7]], "nmi"], {0, 90}],
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[8]], "nmi"], {90, 180}], 
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[9]], "nmi"], {180, 270}], 
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[10]], "nmi"], {270, 360}],
  Blue,
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[11]], "nmi"], {0, 90}],
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[12]], "nmi"], {90, 180}], 
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[13]], "nmi"], {180, 270}], 
  GeoDisk[{forecast[[1]][[1]], forecast[[1]][[2]]}, 
   Quantity[forecast[[1]][[14]], "nmi"], {270, 360}]
  }, GeoRange -> Quantity[500, "NauticalMiles"]
 ]

However, if I replace the first value with a variable, say a, and plot, it fails.

a->1; 
GeoGraphics[
 {
  Red,
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[3]], "nmi"], {0, 90}],
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[4]], "nmi"], {90, 180}], 
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[5]], "nmi"], {180, 270}], 
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[6]], "nmi"], {270, 360}],
  Yellow,
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[7]], "nmi"], {0, 90}],
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[8]], "nmi"], {90, 180}], 
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[9]], "nmi"], {180, 270}], 
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[10]], "nmi"], {270, 360}],
  Blue,
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[11]], "nmi"], {0, 90}],
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[12]], "nmi"], {90, 180}], 
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[13]], "nmi"], {180, 270}], 
  GeoDisk[{forecast[[a]][[1]], forecast[[a]][[2]]}, 
   Quantity[forecast[[a]][[14]], "nmi"], {270, 360}]
  }, GeoRange -> Quantity[500, "NauticalMiles"]
 ]

Part::pkspec1: The expression a cannot be used as a part specification.

Part::pkspec1: The expression a cannot be used as a part specification.

Part::pkspec1: The expression a cannot be used as a part specification.

General::stop: Further output of Part::pkspec1 will be suppressed during this calculation.

Part::partw: Part 3 of forecast[[a]] does not exist.

Part::partw: Part 4 of forecast[[a]] does not exist.

Part::partw: Part 5 of forecast[[a]] does not exist.

General::stop: Further output of Part::partw will be suppressed during this calculation.

GeoDisk::cntr: {forecast, a} is not a valid center location.

GeoDisk::cntr: {forecast, a} is not a valid center location.

GeoDisk::cntr: {forecast, a} is not a valid center location.

General::stop: Further output of GeoDisk::cntr will be suppressed during this calculation.

Out[2]= GeoGraphics[-Graphics-, GeoBackground -> {GeoStyling[StreetMapNoLabels], GeoStyling[VectorLabels]},

>    GeoCenter -> GeoPosition[{28.02, -82.14}], GeoGridLines -> None, GeoGridLinesStyle -> GrayLevel[0.4, 0.3],


>    GeoProjection -> {LambertAzimuthal, Centering -> GeoPosition[{28.02, -82.14}]},

>    GeoRange -> {{19.6594, 36.3705}, {-91.5651, -72.7149}}, GeoRangePadding -> Full, GeoResolution -> Automatic,

>    GeoServer -> {Automatic}, GeoZoomLevel -> 6,

>    MetaInformation ->

>     <|GeoMetaInformation ->

>       <|Attribution ->

>         Hyperlink[Wolfram Knowledgebase, https://www.wolfram.com/],

>          Hyperlink[⌐ MapTiler, https://www.maptiler.com/copyright/],

>          Hyperlink[⌐ OpenStreetMap contributors, https://www.openstreetmap.org/copyright],

>        AttributionType -> Tooltip, GeoModel -> ITRF00, LonLatBox -> {{-93.1605, -71.1195}, {19.3397, 36.6857}},

>        PlotRange -> {{-0.155062, 0.155062}, {-0.145791, 0.1511}},

>        Projection -> {LambertAzimuthal, Centering -> GeoPosition[{28.02, -82.14}],

>          LongitudeDetermination -> -82.14}, Software -> Created with the Wolfram Language: www.wolfram.com,

>        TileSources -> {Wolfram, OSM, MapTiler}|>|>]
POSTED BY: Steven Buehler
2 Replies
Posted 1 year ago

This looked like fun, so I went ahead and built out a solution (I hope it's what you were going for). Assuming we've already defined forecast, we need to structure that data. You could build helper functions to do this, but since I don't know how forecast was generated I'm going to skip that and just do the work "manually":

forecastWithQuantities = MapAt[Quantity[#, "NauticalMiles"] &, forecast, {All, 3 ;;}];
structuredForecast = TakeList[#, {2, 4, 4, 4}] & /@ forecastWithQuantities;

Now let's work on our geo helpers. Let's assume we'll be able to pass a location, a color, and a list of radii to a function that will build GeoDisks. With that. we can define:

GeoSectorPlot[loc_, color_, radii_] :=
 With[
  {sectors = Partition[Subdivide[360, Length@radii], 2, 1]},
  {color, MapThread[GeoDisk[loc, ##] &, {radii, sectors}]}]

Now let's define another helper that we can map over our structuredForecast to build up the necessary arguments for GeoSectorPlot. Probably should use a more distinct name, but I'll go with GeoSectorPlots for now:

GeoSectorPlots[colors_][loc_, radii__] := 
 MapThread[
  GeoSectorPlot[loc, ##] &, 
  {PadRight[colors, Length[{radii}], colors], {radii}}]

Now we can put it together to plot all of your forecast data at once:

GeoGraphics[
 GeoSectorPlots[{Red, Yellow, Blue}] @@@ structuredForecast, 
 GeoRange -> Quantity[500, "NauticalMiles"]]
POSTED BY: Eric Rimbey
Posted 1 year ago

a->1 is not setting a value for a, it's just a Rule expression. Just use a=1.

Other notes:

You can use forecast[[a,1]] instead of forecast[[a]][[1]]

You could build functions to do the work of structuring the raw data into GeoDisks rather than build this big expressions manually.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract