AustralianAntarcticDivision / SOmap

Southern Ocean round maps
https://australianantarcticdivision.github.io/SOmap/
24 stars 6 forks source link

SOauto eats itself #6

Closed mdsumner closed 5 years ago

mdsumner commented 6 years ago

Allow the auto to ingest itself:

library(SOmap)
x <- SOmap::SOauto_map(c(90, 165), c(-75, -60))
## modify x ...

SOauto_map(x) 

We need families of modification processes to update the data.

Maschette commented 5 years ago

I am assuming we can't do this yet? I get this error when I try the example Error in UseMethod("sptable") : no applicable method for 'sptable' applied to an object of class "SOmap" Error in SOauto_map(x) : don't understand how to get lon,lat from 'x'

mdsumner commented 5 years ago

we can't, it's quite a bit of work actually - and might even need a new function, in fact that's probably smarter - a new function to eat the output of SOauto_map, to drive refactoring of the internal logic - then one day consider autophagy - great brainstorming!

Maschette commented 5 years ago

is there a simple way to write a plot method for objects of class SOmap? something that is essentially:

map<-SOauto_map(x,y) plot(map)

which internally does plot(map$bathy, col=bluepal,) plot(map$coastline, add=TRUE) plot(map$graticule, add=TRUE, col=8)

etc..?

raymondben commented 5 years ago

Well you could: in that scenario SOauto_map becomes a constructor function that just returns an object, of class SOmap, with all the data and parameter values needed for a given map. Then, as you say, that class has a plot method that runs the appropriate sequence of plot calls. One can then also modify the SOmap object by manipulating that stored data.

Maschette commented 5 years ago

It mostly does that already, the only thing that is not done atm is the ability to replot an assigned SOmap object without running the SOauto_map function again.

raymondben commented 5 years ago

Then I think you just need to take all the plot and equivalent calls out of the current function, and add a new function:

#' @method plot SOmap
#' @export
plot.SOmap <- function (x, y, ...) {
  ## all the actual plotting here
}
Maschette commented 5 years ago

Sounds like volunteering @raymondben....

raymondben commented 5 years ago

ok, see https://github.com/AustralianAntarcticDivision/SOmap/tree/nomnomnom as a starting point

SOauto_map() ## returns object which is printed to console, this gets passed to print method and thus plotted

p <- SOauto_map() ## object in p but not plotted yet
p ## print it (print method calls plot)
plot(p) ## explicitly plot it

## change stuff
p$bathy_palette <- rev(p$bathy_palette)
## replot
p
Maschette commented 5 years ago

Looks great. Thoughts on converting SOmap() to do the same? I feel like it would take a bit of work.

raymondben commented 5 years ago

Will have a crack this arv

mdsumner commented 5 years ago

You two are doing a great job here

raymondben commented 5 years ago

This branch now merged into master, so closing the issue