!      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~(c) Colin Woodbury, 2018 - 2020BSD3"Colin Woodbury <colin@fosskers.ca>None-.0;=>?HMSVX `) mapalgebra A count of  values across some M., mapalgebraThe main type for  and q, used to calculate Focal Drainage. This scheme for encoding drainage patterns is described on page 81 of GaCM.Full Explanation[Fluid can flow in or out of a square pixel in one of 256 ways. Imagine a pit, whose neighbours are all higher in elevation: liquid would flow in from all eight compass directions, but no liquid would flow out. Consider then a neighbourhood of random heights - fluid might flow in or out of the focus in any permutation of the eight directions.7The scheme for encoding these permutations in a single  as described in GaCM is this:>Flow in a particular direction is represented by a power of 2: 0[ 1 2 4 ] [ 8 16 ] [ 32 64 128 ] Direction values are summed to make the encoding. If there were drainage to the North, East, and SouthEast, we'd see a sum of 2 + 16 + 128 = 146 to uniquely represent this.$Analysing a drainage pattern from a ,[ is just as easy: check if the bit corresponding to the desired direction is flipped. The  function handles this./ mapalgebraA state of surroundedness of a pixel corner. For the examples below, the bottom-left pixel is considered the focus and we're wondering about the surroundedness of its top-right corner.0 mapalgebra3A corner has three of the same opponent against it._The corner is considered "occupied" by the opponent value, thus forming a diagonal areal edge. [ 1 1 ] [ 0 1 ] 1 mapalgebraSOne edge of a corner is touching an opponent, but the other edge touches a friend. *[ 1 1 ] or [ 0 1 ] [ 0 0 ] [ 0 1 ] 2 mapalgebra"A corner is surrounded by friends. D[ 0 0 ] or [ 0 0 ] or [ 1 0 ] [ 0 0 ] [ 0 1 ] [ 0 0 ] 3 mapalgebra Similar to 0{, except that the diagonal opponent doesn't match the other two. The corner is considered surrounded, but not "occupied". [ 1 2 ] [ 0 1 ] 4 mapalgebra Similar to 0F, except that the area of the focus surrounds the diagonal neighbour. [ 0 1 ] [ 0 0 ] 5 mapalgebra-A layout of the areal conditions of a single Mj pixel. It describes whether each pixel corner is occupied by the same "areal zone" as the pixel centre.; mapalgebra7Directions that neighbourhood foci can be connected by.D mapalgebra=A description of lineal directions with the same encoding as ,. See  and .G mapalgebra.An RGBA image whose colour bands are distinct.M mapalgebra?A rectangular grid of data representing some area on the earth.u: What is the underlying representation of this Raster? (see massiv)p: What S is this Raster in?r&: How many rows does this Raster have?c): How many columns does this Raster have?a(: What data type is held in this Raster?By having explicit p, r, and c, we make impossible any operation between two Rasters of differing size or projection. Conceptually, we consider Rasters of different size and projection to be entirely different types . Example: -- | A lazy 256x256 Raster with the value 5 at every index. Uses DataKinds -- and "type literals" to achieve the same-size guarantee. myRaster :: Raster D WebMercator 256 256 Int myRaster = constant D Par 5 >>> length myRaster 65536 P mapalgebraThe most commonly used S& for mapping in internet applications.Q mapalgebraCLatitude (north-south position) and Longitude (east-west position).R mapalgebraA perfect geometric sphere. The earth isn't actually shaped this way, but it's a convenient middle-ground for converting between various Ss.S mapalgebra_The Earth is not a sphere. Various schemes have been invented throughout history that provide Vr coordinates for locations on the earth, although all are approximations and come with trade-offs. We call these  Projections, since they are a mapping of Rt coordinates to some other approximation. The Projection used most commonly for mapping on the internet is called P.BA Projection is also known as a Coordinate Reference System (CRS).Use Z to convert Vs between various Projections.Note:/ Full support for Projections is still pending.T mapalgebra Convert a V3 in this Projection to one of radians on a perfect R.U mapalgebra Convert a VA of radians on a perfect sphere to that of a specific Projection.V mapalgebra A location on the Earth in some S.Z mapalgebra Reproject a V from one S to another.[ mapalgebra\mathcal{O}(1) . Force a M's representation to  E, allowing it to undergo various operations. All operations between   M*s are fused and allocate no extra memory.\ mapalgebraEvaluate some lazy ( , , or ) M to some explicit = type (i.e. to a real memory-backed Array). Will follow the #utation strategy of the underlying massiv .Note: If using the 8 computation strategy, make sure you're compiling with -with-rtsopts=-N~ to automatically use all available CPU cores at runtime. Otherwise your "parallel" operations will only execute on one core.] mapalgebra Create a M1 of any size which has the same value everywhere.^ mapalgebra\mathcal{O}(1) . Create a M< from a function of its row and column number respectively._ mapalgebra\mathcal{O}(1) . Create a M from the values of any U type. Will fail if the size of the Vector does not match the declared size of the M.` mapalgebraRead any image type into a Md of distinct colour bands with the cell type you declare. If the source image stores its values as  but you declare +, the conversion will happen automatically.&Will fail if the declared size of the M4 does not match the actual size of the input image.a mapalgebramRead a grayscale image. If the source file has more than one colour band, they'll be combined automatically.b mapalgebra,An invisible pixel (alpha channel set to 0). mapalgebra_Construct a colour ramp. ramp :: Ord k => [(Word8, Word8, Word8)] -> [k] -> M.Map k PixelRGBA8c mapalgebraFrom page 32 of Cartographer's Toolkit.d mapalgebraFrom page 33 of Cartographer's Toolkit.e mapalgebraFrom page 34 of Cartographer's Toolkit.f mapalgebraFrom page 35 of Cartographer's Toolkit.g mapalgebraFrom page 36 of Cartographer's Toolkit.h mapalgebraFrom page 37 of Cartographer's Toolkit.i mapalgebraFrom page 38 of Cartographer's Toolkit.j mapalgebraFrom page 39 of Cartographer's Toolkit.k mapalgebraFrom page 40 of Cartographer's Toolkit.l mapalgebraFrom page 41 of Cartographer's Toolkit.m mapalgebra Convert a MF into grayscale pixels, suitable for easy output with functions like .n mapalgebraRender a PNG-encoded  from a coloured M. Useful for returning a M from a webserver endpoint.o mapalgebraCalled LocalClassificationq in GaCM. The first argument is the value to give to any index whose value is less than the lowest break in the .This is a glorified - operation, but we expose it for convenience.p mapalgebra2Finds the minimum value at each index between two Ms.q mapalgebra2Finds the maximum value at each index between two Ms.r mapalgebra%Averages the values per-index of all Ms in a collection.s mapalgebra0The count of unique values at each shared index.t mapalgebra9The most frequently appearing value at each shared index. mapalgebra#Find the most common value in some .u mapalgebra:The least frequently appearing value at each shared index. mapalgebra$Find the least common value in some .v mapalgebraKA measure of how spread out a dataset is. This calculation will fail with  if a length 1 list is given.w mapalgebra Combine two M(s, element-wise, with a binary operator.x mapalgebraFocal Addition.y mapalgebraFocal Product.z mapalgebraAFocal Monoid - combine all elements of a neighbourhood via their z instance. In terms of precedence, the neighbourhood focus is the "left-most", and all other elements are "added" to it.<This is not mentioned in GaCM, but seems useful nonetheless.{ mapalgebra Focal Mean.| mapalgebraFocal Maximum.} mapalgebraFocal Minimum.~ mapalgebraBFocal Variety - the number of unique values in each neighbourhood. mapalgebraKFocal Majority - the most frequently appearing value in each neighbourhood. mapalgebraLFocal Minority - the least frequently appearing value in each neighbourhood. mapalgebra~Focal Percentage - the percentage of neighbourhood values that are equal to the neighbourhood focus. Not to be confused with . mapalgebraCFocal Percentile - the percentage of neighbourhood values that are less8 than the neighbourhood focus. Not to be confused with . mapalgebraFocal Linkage - a description of how each neighbourhood focus is connected to its neighbours. Foci of equal value to none of their neighbours will have a value of 0. mapalgebraFocal Length - the length of the lineal structure at every location. The result is in "pixel units", where 1 is the height/width of one pixel. mapalgebraGImagining a 2x2 neighbourhood with its focus in the bottom-left, what /8 relationship does the focus have with the other pixels? mapalgebraQWhat is the total length of the areal edges (if there are any) at a given pixel? mapalgebraXFocal Partition - the areal form of each location, only considering the top-right edge. mapalgebraLike , but considers the /O of all corners. Is alluded to in GaCM but isn't given its own operation name.If preparing for  or 3, you almost certainly want this function and not . mapalgebraUFocal Frontage - the length of areal edges between each pixel and its neighbourhood.Usually, the output of , is the appropriate input for this function. mapalgebraWThe area of a 1x1 square is 1. It has 8 right-triangular sections, each with area 1/8. mapalgebraFocal Area - the area of the shape made up by a neighbourhood focus and its surrounding pixels. Each pixel is assumed to have length and width of 1.Usually, the output of , is the appropriate input for this function. mapalgebraCFocal Volume - the surficial volume under each pixel, assuming the M# represents elevation in some way. mapalgebra*Direct access to the entire neighbourhood. mapalgebraHGet the surficial facets for each pixel and apply some function to them. mapalgebrabThe first part to the "left pseudo inverse" needed to calculate a best-fitting plane of 9 points. mapalgebraFocal Gradient - a measurement of surficial slope for each pixel relative to the horizonal cartographic plane. Results are in radians, with a flat plane having a slope angle of 0 and a near-vertical plane approaching \tau / 4. mapalgebra\tau'. One full rotation of the unit circle. mapalgebraGiven a list of zI values, find the slope of the best-fit plane that matches those points.See: +https://stackoverflow.com/a/16669463/643684 mapalgebraGiven a list of z# values, find a normal vector that  points down6 from a best-fit plane toward the cartographic plane. mapalgebra4A non-normalized, non-Z-corrected normal. Handy for -, which needs to drop the Z and renormalize. mapalgebra%Replace the Z-coordinate of a Vector. mapalgebraxFocal Aspect - the compass direction toward which the surface descends most rapidly. Results are in radians, with 0 or \tau being North, \tau / 4T being East, and so on. For areas that are essentially flat, their aspect will be . mapalgebraLike J, but slightly faster. Beware of nonsense results when the plane is flat. mapalgebra$Approximate Equality. Considers two $ to be equal if they are less than  /tau / 1024 apart. mapalgebraKGiven two normalized (length 1) vectors in R3, find the angle between them. mapalgebraFocal Drainage - downstream portion. This indicates the one or more compass directions of steepest descent from each location. Appropriate as the input to .Note:\ Peak-like surfaces will not flow equally in all 8 directions. Consider this neighbourhood: [ 1 1 1 ] [ 1 3 1 ] [ 1 1 1 ] According to the rules in GaCM for calculating the intermediate surficial "facet" points for the focus, 3, we arrive at the following facet height matrix: *[ 1.5 2 1.5 ] [ 2 3 2 ] [ 1.5 2 1.5 ] ^With these numbers it's clear that the corners would yield a steeper angle, so our resulting ,4 would only contain the directions of the diagonals. mapalgebraFocal Drainage - upstream portion. This indicates the one of more compass directions from which liquid would flow into each surface location. See also . mapalgebra Does a given , indicate flow in a certain ;? mapalgebraAll ; s that a , indicates flow toward. mapalgebraThe opposite of . mapalgebraGiven a M% of byte data, efficiently produce a )@ that describes value counts across the image. To be passed to . mapalgebraGiven a )A, produce a list of "colour breaks" as needed by functions like c. mapalgebra has a specialized \mathcal{O}(1) implementation. mapalgebraIWarning: This will evaluate (at most) the 10x10 top-left corner of your M5 for display. This should only be used for debugging.  #('&%$"! )*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~MNO[\GHIJKL]^_`am)*+bcdefghijklnSTUZRQPVWXYwoqprstuvxyz{|}~DEF56789:/01234,-.;<=>?@ABC   ('&%$"! #           ! "#$#%#&'(')*+*,*-./.0121345667889:;<=>?@@ABCDEFGHIJKLMNNOPPQRSTUUVWXYZ[\]]^_`abcdefghijklmnopqrstuvwxyz{|}~'mapalgebra-0.2.1-KvHDhBol1Or1KbgxogWpZzGeography.MapAlgebra$massiv-0.4.5.0-r7rM5NNoeD9jaKVdDAh8E"Data.Massiv.Array.Delayed.WindowedDW Data.Massiv.Array.Manifest.BoxedBN#Data.Massiv.Array.Manifest.StorableS$Data.Massiv.Array.Manifest.PrimitiveP"Data.Massiv.Array.Manifest.UnboxedUData.Massiv.Array.Delayed.PullDData.Massiv.Core.Index.IxIx2:.(scheduler-1.4.2.1-1Y5eQsTeactELv0uWv1QyfControl.Scheduler.ComputationCompSeqParOnParNPar'Par(massiv-io-0.1.9.0-DLaQR2h5TV9GGqWIxIw3ptData.Massiv.Array.IO displayImagewriteImageAuto writeImageGraphics.ColorSpace.YCbCr PixelYCbCr PixelYCbCrAGraphics.ColorSpace.YPixelYPixelYAYGraphics.ColorSpace.XgetXPixelXGraphics.ColorSpace.RGBPixelRGB PixelRGBARGBAGraphics.ColorSpace.CMYK PixelCMYK PixelCMYKAGraphics.ColorSpace.HSIPixelHSI PixelHSIAGraphics.ColorSpace.InternalPixel Histogram _histogramDrain_drainSurroundCompleteOneSideOpen RightAngleOutFlowCorners_topLeft _bottomLeft _bottomRight _topRight DirectionEast NorthEastNorth NorthWestWest SouthWestSouth SouthEastLine_line RGBARaster_red_green_blue_alphaRaster_array WebMercatorLatLngSphere ProjectiontoSphere fromSpherePointxy reprojectlazystrictconstant fromFunction fromVectorfromRGBAfromGray invisiblegreenRedspectrum blueGreen purpleYellow brownBlue grayBrown greenPurple brownYellow purpleGreen purpleRed grayscalepngclassifylminlmaxlmeanlvariety lmajority lminority lvariancezipWithfsumfproductfmonoidfmeanfmaxfminfvariety fmajority fminority fpercentage fpercentileflinkageflength fpartitionfshape ffrontagefareafvolume leftPseudo fgradienttaufaspectfaspect' fdownstream fupstream direction directionsdrainage histogrambreaks$fProjectionTYPESphere$fFoldableRaster$fFractionalRaster $fNumRaster$fMonoidRaster$fSemigroupRaster$fApplicativeRaster$fFunctorRaster$fFunctorRaster0$fFunctorRaster1 $fEqRaster $fEqRaster0 $fEqRaster1 $fEqRaster2 $fEqRaster3 $fEqRaster4 $fShowRaster $fNFDataLine$fNFDataSurround$fNFDataCorners $fNFDataDrain $fEqPoint $fShowPoint$fEqLine $fOrdLine $fShowLine$fStorableLine $fPrimLine $fDefaultLine $fEqDirection$fOrdDirection$fEnumDirection$fShowDirection $fEqSurround $fOrdSurround$fShowSurround $fEqCorners $fShowCorners $fEqDrain $fOrdDrain $fShowDrain$fStorableDrain $fPrimDrain$fDefaultDrain $fEqHistogram$fShowHistogrambaseGHC.WordWord8%Data.Massiv.Array.Delayed.InterleavedDIData.Massiv.Core.CommonManifestArray&vector-0.12.1.2-FWeXzqARiSu45G657SieqkData.Vector.Generic.BaseVectorghc-prim GHC.TypesIntDoublerampbytestring-0.10.8.2Data.ByteString.Lazy.Internal ByteStringcontainers-0.6.0.1Data.Map.InternalMapGHC.Basefmapmajo Data.FoldableFoldablemino GHC.MaybeNothingMonoidsurroundfrontagearea neighbourhood facetStencilgradientnormalnormal'zcoord=~anglelength