I often import several long time series to analyze something about a city. When I have multiple cities, I use contexts. As a simple example,
Begin["paris`"]; dataRaw=Import["Paris.csv"]; data=Differences[dataRaw]; dataMax=Max[dataRaw]; End; Begin["madrid`"]; dataRaw=Import["Madrid.csv"]; data=Differences[dataRaw]; dataMax=Max[dataRaw]; End;
Now I can for instance do plots, so
and this seems much less sloppy than keeping everything in the
Global context and manually adding the city name to the end of every symbol name.
But I would like to write a function to take care of the importing and processing. Naively,
importCity[cityName_String] := ( Begin[ToLowerCase[cityName]~~"`"]; dataRaw=Import[cityName~~".csv"]; data=Differences[dataRaw]; dataMax=Max[dataRaw]; End; )
but this doesn't appear to create the context as intended. If contexts are a good way of organizing this sort of thing, how can I make a function that creates a context and puts results in it? And if this is an abuse of contexts, what's the proper way to do this?