merlin.chips

merlin.chips.bounds_to_coordinates(bounds, spec)[source]

Returns chip coordinates from a sequence of bounds. Performs minbox operation on bounds, thus irregular geometries may be supplied.

Parameters:
  • bounds – a sequence of bounds.
  • spec – a chip spec representing chip geometry
Returns:

chip coordinates

Return type:

tuple

Example

>>> xys = bounds_to_coordinates(
                            bounds=((112, 443), (112, 500), (100, 443)),
                            spec=chip_spec)
>>> ((100, 500),)
merlin.chips.chip_to_numpy(chip, chip_spec)[source]

Removes base64 encoding of chip data and converts it to a numpy array

Parameters:
  • chip – A chip
  • chip_spec – Corresponding chip_spec
Returns:

a decoded chip with data as a shaped numpy array

merlin.chips.coordinates(ulx, uly, lrx, lry, chip_spec)[source]

Returns all the chip coordinates that are needed to cover a supplied bounding box.

Parameters:
  • ulx – upper left x
  • uly – upper left y
  • lrx – lower right x
  • lry – lower right y
  • chip_spec – dict containing chip_x, chip_y, shift_x, shift_y
Returns:

tuple of tuples of chip coordinates ((x1,y1), (x2,y1) ...)

Return type:

tuple

This example assumes chip sizes of 500 pixels.

Example

>>> chip_coordinates = coordinates(1000, -1000, -500, 500, chip_spec)
((-1000, 500), (-500, 500), (-1000, -500), (-500, -500))
merlin.chips.dates(chips)[source]

Dates for a sequence of chips

Parameters:chips – sequence of chips
Returns:datestrings
Return type:tuple
merlin.chips.deduplicate(chips)[source]

Accepts a sequence of chips and returns a sequence of chips minus any duplicates. A chip is considered a duplicate if it shares an x, y, UBID and acquired date with another chip.

Parameters:chips (sequence) – Sequence of chips
Returns:A nonduplicated tuple of chips
Return type:tuple
merlin.chips.difference(point, interval)[source]

Calculate difference between a point and ‘prior’ point on an interval.

The value of this function can be used to answer the question, what do I subtract from a point to find the point of the nearest chip that contains it?

Geospatial raster data geometry can be somewhat counter-inuitive because coordinates and pixel geometry are expressed with both positive and negative values.

Along the x-axis, pixel size (and thus the interval) is a positive number (e.g. 30 * 100). Along the y-axis though, the pixel size and interval is a _negative_ value. Even though this may seem peculiar, using a negative value helps us avoid special cases for finding the nearest tile-point.

Parameters:
  • point – a scalar value on the real number line
  • interval – a scalar value describing regularly spaced points on the real number line
Returns:

difference between a point and prior point on an interval.

merlin.chips.get(url, x, y, acquired, ubids)[source]

Returns aardvark chips for given x, y, date range and ubid sequence

Parameters:
  • url – full url to aardvark endpoint
  • x – longitude
  • y – latitude
  • acquired – ISO8601 daterange ‘2012-01-01/2014-01-03’
  • ubids – sequence of ubid strings
  • url – string
  • x – number
  • y – number
Returns:

chips

Return type:

tuple

Example

>>> chips(url='http://host:port/landsat/chips',
          x=123456,
          y=789456,
          acquired='2012-01-01/2014-01-03',
          ubids=['LANDSAT_7/ETM/sr_band1', 'LANDSAT_5/TM/sr_band1'])
merlin.chips.identity(chip)[source]

Determine the identity of a chip.

Parameters:chip (dict) – A chip
Returns:Tuple of the chip identity field
Return type:tuple
merlin.chips.locations(startx, starty, chip_spec)[source]

Computes locations for array elements that fall within the shape specified by chip_spec[‘data_shape’] using the startx and starty as the origin. locations() does not snap() the startx and starty... this should be done prior to calling locations() if needed.

Parameters:
  • startx – x coordinate (longitude) of upper left pixel of chip
  • starty – y coordinate (latitude) of upper left pixel of chip
Returns:

a two (three) dimensional numpy array of [x, y] coordinates

merlin.chips.near(point, interval, offset)[source]

Find nearest point given an interval and offset.

The nearest point will be lesser than the point for a positive interval, and greater than the point for a negative interval as is required when finding an ‘upper-left’ point on a cartesian plane.

This function is used to calculate the nearest points along the x- and y- axis.

Parameters:
  • point – a scalar value on the real number line
  • interval – a scalar value describing regularly spaced points on the real number line
  • offset – a scalar value used to shift point before and after finding the ‘preceding’ interval.
Returns:

a number representing a point.

merlin.chips.point_to_chip(x, y, x_interval, y_interval, x_offset, y_offset)[source]

Find the nearest containing chip’s point.

The resulting x value will be less than or equal to the input while the resulting y value will be greater than or equal.

For this function to work properly, intervals and offsets must be expressed in terms of projection coordinate system ‘easting’ and ‘northing’ units.

Along the x-axis, this works as expected. The interval is a multiple of pixel size and tile size (e.g. 30 * 100 = 3000). Along the y-axis the interval is negative because the pixel size is negative, as you move from the origin of a raster file, the y-axis value _decreases_.

The offset value is used for grids that are not aligned with the origin of the projection coordinate system.

Parameters:
  • x – longitudinal value
  • y – latitude value
  • x_interval
  • y_interval
  • x_offset
  • y_offset
Returns:

x,y where x and y are the identifying coordinates of a chip.

Return type:

tuple

merlin.chips.snap(x, y, chip_spec)[source]

Transform an arbitrary projection system coordinate (x,y) into the coordinate of the chip that contains it.

This function only works when working with points on a cartesian plane, it cannot be used with other coordinate systems.

Parameters:
  • x – x coordinate
  • y – y coordinate
  • chip_spec – parameters for a chip’s grid system
Returns:

chip x,y

Return type:

tuple

merlin.chips.to_numpy(chips, chip_specs_byubid)[source]

Converts the data for a sequence of chips to numpy arrays

Parameters:
  • chips (sequence) – a sequence of chips
  • chip_specs_byubid (dict) – chip_specs keyed by ubid
Returns:

chips with data as numpy arrays

Return type:

sequence

merlin.chips.trim(chips, dates)[source]

Eliminates chips that are not from the specified dates

Parameters:
  • chips – Sequence of chips
  • dates – Sequence of dates that should be included in result
Returns:

filtered chips

Return type:

tuple