-
Notifications
You must be signed in to change notification settings - Fork 18
Description
In the case where a particular subscript element combination coincides with a spatial unit (e.g. gridcell), the ordering of the output is important so that the results can be reshaped to match the ordering of the grid.
a simple use case might be a stock (say "Population") is distributed on a grid according to subscript ranges lat and lon defined by subscript elements (lat1 -> lat10) and (lon1 -> lon10) respectively. If the results were sorted alphanumerically, the ordering would look something like:
(lat1, lon1), (lat1, lon2), ..., (lat10, lon1), (lat10, lon2), ..., (lat2, lon1), (lat2, lon2), ...
With a natural sort, the ordering of the output would look like this:
(lat1, lon1), (lat1, lon2), ..., (lat2, lon1), (lat2, lon2), ..., (lat3, lon1), (lat3, lon2), ...
This would allow for the results to be easily reshaped back into a grid-like form. A minimal example:
#Naturally sorted pseudo-output rows represent time, columns are element combinations
test = np.empty((3, 9), dtype=object)
N, M = test.shape
for i in range(N):
for j in range(M):
#Each number represents lat, lon, and time (e.g. 123 = (lat1,lon2,time3)
test[i,j] = "{:d}{:d}{:d}".format(j // 3 + 1, j % 3 + 1, i+1)
#Reshape back into grid
test.reshape((3, 3, 3))
This would require:
- Using
collections.OrderedDictto collect the results inVenPy.resultinstead of builtindict - Naturally sorting keys of the OrderedDict before inputting to DataFrame
This could either be by default or adding in an additional kwarg to the VenPy.result method.