Can one slice an Alaska bounding box in one download for MERRA2 OpenDAP downloads? - geospatial

Alaska's longitude spans -50E -- 172E, or more appropriately, 172E -- -50E.
When formulating MERRA2 openDAP requests, is it possible to subselect the region 172E -- -50E in one file, or do I need to select 172E -- 180E, and then -50E -- -180E in two operations and then merge the data collections?

Related

How would I go about representing levels/scenes in a game in Haskell?

The problem
I'm working on a text adventure game as a hobby project to teach myself some new Haskell concepts.
I've now run into the challenge of representing the levels (or 'scenes') in the game and the various ways in which they're connected. To keep things simple for myself, I've visualised the 'map' of the game as a simple 2d space, in which scenes are connected via cardinal directions (NESW):
Lake
⇳
Forest
⇳
Home ⬄ Field*
*: Starting location
Here, going south from the lake would lead you to the forest, and vice versa; going west from the field would lead you to the home. The challenge here is that I need some way to encode not only which scenes are connected, but how they are connected, where 'how' refers to a cardinal direction.
Two options I've considered so far are representing levels as a graph or using lists of tuples, but I'm not entirely happy with either approach.
Representing scenes as a Graph
My basic approach in representing scenes and their connections as a graph was as follows:
data Scene = InitialField | Forest | House | Lake
-- |`gameScenes` maps scenes to their integer representation, as used in `sceneGraph`.
gameScenes :: Map Int Scene
gameScenes =
let scenes =
[ (0, InitialField)
, (1, Forest)
, (2, House)
, (3, Lake)
]
in
fromList scenes
-- |the `sceneGraph` describes the way different scenes of the game connect to each other.
sceneGraph :: Graph
sceneGraph =
let
bounds = (0, 3)
edges =
[ (0, 1) -- link initial field to forest
, (0, 2) -- link initial field to house
, (1, 3) -- link forest to lake
]
in
buildG bounds edges
Downside: The main limitation here is that this graph does not encode any information with regards to cardinal directions. This is unfortunate, because aside from that limitation, a graph seems like a perfect data structure to represent scenes (vertices) and their linkages (edges). Is there any way to encode 'metadata' (in this case, cardinal directions) of edges in a graph?
Representing scenes using list of tuples
When I came upon the above limitation, I decided to try a different approach and represent the links between scenes as a list of tuples:
data Scene = InitialField | Forest | House | Lake
data CardinalDirection = North | East | South | West
type LinkedScene = (CardinalDirection, Scene)
-- |`linkedScenes`, applied to a `Scene`, returns a list of the connected scenes and their cardinal directions.
linkedScenes :: Scene -> [LinkedScene]
linkedScenes InitialField = [(North, Forest)]
linkedScenes Forest = [(South, InitialField), (West, Lake)]
-- The other links are left as an exercise for the reader ;)
linkedScenes _ = []
Downside: This approach does allow us to encode the linkages between different scenes simply by applying sceneLinks to the Scene the player is currently in, but it has a big, ugly downside: it requires us to double-endedly encode the spatial linkages between scenes. In other words, if we know that the forest is north of the field, we need to write two functions: one that takes Forest and yields [(South, InitialField)], and an inverse one that takes InitialField and yields [(North, Forest)]. This seems like it's begging for bugs: if I ever want to add a scene, or change the layout of the game world, I need to remember to double-check every single linkage from both ends.
Summing up: requirements
Ideally, I am looking for an approach that:
Allows me to encode a bidirectional relationship between scenes using a single data point (no 'double-ended' encoding as in the second approach, since that is asking for bugs);
Allows me to easily change the layout of the game/map at a later stage, without a giant headache;
Is guaranteed to be spatially consistent at compile time, meaning that it does not allow for invalid spatial configurations, such as a state in which the player starts at the field, goes north to the forest, goes back south and suddenly finds themselves in the lake. I am not certain that this is possible without dependent types, however.
If anyone could think of such an approach, it would surely be someone in the Haskell community :)
Thanks!
Start with triples describing some of the connections:
data Scene = Field | Forest | House | Lake
data Dir = N | E | S | W
type Edge = (Scene, Dir, Scene)
uniEdges :: [Edge]
uniEdges = [(Field, N, Forest), (Forest, W, Lake)]
Expand to the full map by reversing all the tuples:
class Dual a where dual :: a -> a
instance Dual Dir where
dual N = S
dual E = W
dual S = N
dual W = E
instance Dual Edge where dual (s, d, s') = (s', dual d, s)
instance Dual a => Dual [a] where dual = map dual
allEdges :: [Edge]
allEdges = uniEdges ++ dual uniEdges
Then insert these into whatever data structure you like; a Map Scene (Dir, Scene) or a Gr or whatever.
One nice feature of this approach: it leaves you with the ability to decide later that not all edges should turn back on themselves without changing all the users of the scene graph, as in this map with a curved path:
House
|
\
`--Lake
I see two options:
Go with the simple graph, but additionally embed the scenes in a two-dimensional space. Then from any given point, the graph tells you which other scenes are neighbours, and by taking the difference in the vector space you can obtain the direction.
This is simple to visualize and implement. Disadvantage is that it brings in an absolute frame of reference, meaning you can just link two locally designed groups of scenes together but first need to translate them to avoid overlaps. Also, it's kind of boring and precludes emergent non-Euclidean geometry... if you're into that kind of thing.
(Note that you could still have non-Euclidean geometry by embedding into a non-flat manifold. In this case you could use the PseudoAffine class for the distances.)
Go with the list of tuples, but wrap it all in your own graph-like abstraction. QuickCheck that abstraction to death, and only export an interface that automatically keeps track of synchronising the changes between neighbouring nodes. Then in the actual game, only manipulate the scenes-world through the abstract interface.

Regarding state machine diagram, if two actions trigger the same transition from a state, how should corresponding state transition table look like?

I am trying to convert this state machine diagram into its corresponding state transition table but I don't know what to write in the cell marked with question mark.
Should I write both (a2/e2) and (a3/e3)?
Your table is a state transition matrix. You need in any case to show both alternative paths in the S2->S1 cell, i.e. a2/e2 and a3/e3.
There is as far as I know no standard specification for such matrix. So any of the following should do:
separating the two transition rules, e.g. with a semicolon between the two transition rules or with an OR between the two (hint: comma separation might be confusing if you're sing the UML syntax, since it allows several comma-separated triggers for the same effect);
visualizing the two transition rules one above the other;
or splitting just this cell into two vertically stacked subcells.
What you cannot do is to duplicate the whole line, since this would break the matrix. This technique only works with 1D state transition tables (i.e. each line correspond to one arrow)

Layout's location algo apply to filtered set of Vertexes

the job of the layout is to place vertexes at given locations. if the layout is iterative, then the layout's job is to iterate through an algo, moving the vertexes with each step, until the final layout configuration is achieved.
I have a multi-level graph - say 100 objects of type A; each A object has 10 objects as children; call the children type B objects.
I would like the layout location placement algos to operate on objects of type A only (let's say) - and ignore the B objects.
The cleanest way to achieve this objective might be to define a transform to expose those elements that should participate in the 'algo' placement operation via the step method.
Currently, the step methods, assuming they respect the lock flag at all, do their calculations including the locked vertexes first - so lock/unlock won't work in this case.
Is it possible to do this somehow without resorting to multiple graph objects?
If you want to ignore the B objects entirely, then the simplest option is to create a graph consisting only of the A objects, lay it out, and use the locations from that layout.
That said, it's not clear how you intend to assign locations to the B objects. And if the A objects aren't connected to each other at all, then this approach won't make much sense. (OTOH, if they aren't connected to each other then you're really just laying out a bunch of trees.)

Labels,vertices and edges TitanDB

I have the following information in a Titan Graph database.I am trying to make sense of the information by sending queries across gremlin shell.The Graph database that I am trying to investigate models a Network.There are two types of vertices
- `Switch`
- `Port`
I am trying to figure out the relationship between these two types of vertices.
g = TitanFactory.open("/tmp/cassandra.titan")
To see the list of vertices of each type
$ g.V('type', 'switch')
==>v[228]
==>v[108]
==>v[124]
==>v[92]
==>v[156]
==>v[140]
$ g.V('type', 'port')
==>v[160]
==>v[120152]
==>v[164]
==>v[120156]
==>v[560104]
==>v[680020]
==>v[680040]
==>v[112]
==>v[120164]
==>v[560112]
==>v[680012]
==>v[680004]
==>v[144]
==>v[680032]
==>v[236]
==>v[100]
==>v[560128]
==>v[128]
==>v[680028]
==>v[232]
==>v[96]
To find the relation between the switch and port.
g.v(108).out
==>v[560104]
==>v[680004]
==>v[112]
What is this "out"? As I understand there is a outward arrow pointing from Switch represented by vertex 108 to the Ports represented by vertices 560104 680004 and 112
What is this in and out? Is it something very specific to Graph Databases? Also what is a label in a graph databse? Are in and out labels?
The use of in and out is descriptive of the direction of the edge going from one vertex to another. In your case, you have this:
switch --> port
When you write:
g.v(108).out
you are telling Gremlin to find the vertex at 108, then walk along edges that point out or away from it. You might also think of out as starting from the tail of the arrow and walking to the head. Given your schema, those lead to "ports".
Similarly, in simply means to have Gremlin walk along edges that point in to the vertex. You might also think of in as starting from the head of the arrow and walking to the tail. Given your schema, switches will have no in edges and hence will always return no results. However if you were to start from a "port" vertex and traverse in:
g.v(560104).in
you would at least get back vertex 108 as vertex "560104" has at least one edge with an arrow pointing to it (given what I know of your sample data).
By now you've gathered that in and out are "directions" and not "labels". A label has a different purpose; it categorizes an edge. For example, you might have the following schema:
switch --connectsTo--> port
company --manufactures--> switch
switch --locatedIn--> rack
In other words you might have three edge labels representing different ways that a "switch" relates to other parts of your schema. In this way your queries can be more descriptive about what you want. Given your previous example and this revised schema you would have to write the following to get the same result you originally showed:
g.v(108).out("connectsTo")
==>v[560104]
==>v[680004]
==>v[112]
Graph databases will typically take advantage of these labels to help improve performance of queries.

Quadtree object movement

So I need some help brainstorming, from a theoretical standpoint. Right now I have some code that just draws some objects. The objects lie in the leaves of a quadtree. Now as the objects move I want to keep them placed in the correct leaf of the quadtree.
Right now I am just reconstructing the quadtree on the objects after I change their position. I was trying to figure out a way to correct the tree without rebuilding it completely. All I can think of is having a bunch of pointers to adjacent leaf nodes.
Does anyone have an idea of how to figure out the node into which an object moves without just having a ton of pointers everywhere or a link to articles on this? All I could find was different ways to build the quadtree, nothing about updating it.
If I understand your question. You want some way of mapping between spatial coordinates and leaves on the quadtree.
Here's one possible solution I've been looking at:
For simplicity, let's do the 1D case first. And lets assume we have 32 gridpoints in x. Every grid point then corresponds to some leaf on a quadtree of depth five. (depth 0 = the whole grid, depth 1 = 2 points, depth 2 = 4 points... depth 5 = 32 points).
Each leaf could be represented by the branch indices leading to the leaf. At each level there are two branches we can label A and B. So, a particular leaf might be labeled BBAAB, which would mean, go down the B branch, then the B branch, then the A branch, then the B branch and then the B branch.
So, how do you map e.g. BBABB to an x grid point between 0..31? Just convert it to binary, so that BBABB->11011 = 27. Thus, the mapping from gridpoint to leaf-node is simply a matter of translating the letters A and B into 0s and 1s and then interpreting the result as a binary number.
For the 2D case, it's only slightly more complicated. Now we have four branches from each node, so we can label each branch path using a four-letter alphabet, e.g. starting from the root and taking the 3rd branch and then the fourth branch and then the first branch and then the second branch and then the second branch again we would generate the string CDABB.
Now to convert the string (e.g. 'CDABB') into a pair of gridvalues (x,y).
Let's assume A is lower-left, B is lower right, C is upper left and D is upper right. Then, symbolically, we could write, A.x=0, A.y=0 / B.x=1, B.y=0 / C.x=0, C.y=1 / D.x=1, D.y=1.
Taking the example CDABB, we first look at its x values (CDABB).x = (01011), which gives us the x grid point. And similarly for y.
Finally, if you want to find out e.g. the node immediately to the right of CDABB, then simply convert it to a pair of binary numbers in x and y, add +1 to the x value and convert the new pair of binary numbers back into a string.
I'm sure this has all been discovered, but I haven't yet found this information on the web.
If you have the spatial data necessary to insert an element into the quad-tree in the first place (ex: its point or rectangle), then you have the same data needed to remove it.
An easy way is before you move an element, remove it from the quad-tree using the same data you used to originally insert it, then move it, then re-insert.
Removal from the quad-tree can first remove the element from the leaf node(s), then if the leaf nodes become empty, remove them from their parents. If the parents become empty, remove them from their parents, and so forth.
This simple method is efficient enough for a complex world of objects moving every frame as long as you implement the quad-tree efficiently (ex: use a free list for the nodes). There shouldn't have to be a heap allocation on a per-node basis to insert it, nor a heap deallocation involved in removing every single node. Most node allocations/deallocations should be a simple constant-time operation just involving, say, the manipulation of a couple of integers or pointers.
You can also make this a little more complex if you like. You can start off storing the previous position of an object and then move it. If the new position occupies nodes other than the previous position, then remove the object from the nodes it no longer occupies and insert it to the new ones. Otherwise just keep it in the same node(s).
Update
I usually try to avoid linking my previous answers, but in this case I ended up doing a pretty comprehensive write up on the topic which would be hard to replicate anywhere else. Here it is: https://stackoverflow.com/a/48330314/4842163

Resources