Skip to content

WIP Improve function docstrings #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions mapshader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,13 @@ def render_map(source: MapSource, # noqa: C901
Height of the output aggregate in pixels.
width : int
Width of the output aggregate in pixels.

Returns
-------
img : xarray.DataArray
A DataArray representing an image.
"""

if x is not None and y is not None and z is not None:
xmin, ymin, xmax, ymax = tile_def.get_tile_meters(x, y, z)

Expand Down Expand Up @@ -587,10 +593,12 @@ def tile_to_disk(img, output_location, z=0, x=0, y=0, tile_format='png'):
----------
img: xarray.DataArray
aggregation data array of the tile to write to image
x, y, z : float
The coordinates to be used to get the bounds inclusive space along the axis.
output_location: str
Path to write tile image
x, y, z : float
The coordinates to be used to get the bounds inclusive space along the axis.
tile_format: str
Format of output image

Returns
-------
Expand All @@ -616,18 +624,22 @@ def tile_to_disk(img, output_location, z=0, x=0, y=0, tile_format='png'):

def tile_to_s3(img, output_location, z=0, x=0, y=0, tile_format='png'):
"""
Write a tile image to a S3 bucket

Parameters
----------
img
output_location
z
x
y
tile_format
img: xarray.DataArray
aggregation data array of the tile to write to image
output_location: str
Path to write tile image
x, y, z : float
The coordinates to be used to get the bounds inclusive space along the axis.
tile_format: str
Format of output image

Returns
-------
None

"""

Expand Down Expand Up @@ -655,6 +667,25 @@ def tile_to_s3(img, output_location, z=0, x=0, y=0, tile_format='png'):


def render_tile(source, output_location, z=0, x=0, y=0, tile_format='png'):
"""
Create a tile from a source and save as an image to a output location.

Parameters
----------
source: MapSource
MapSource object to define the map.
output_location: str
Path to write tile image. Can be a path to local disk or a S3 bucket.
x, y, z : float
The coordinates to be used to get the bounds inclusive space along the axis.
tile_format: str (default='png')
Format of output image

Returns
-------
None
"""

agg = render_map(source, x=int(x), y=int(y), z=int(z), height=256, width=256)

if 0 in agg.shape:
Expand Down Expand Up @@ -692,6 +723,7 @@ def get_source_data(source: MapSource, simplify=None):
gdf : GeoDataFrame or dict
The Mapsource data
"""

if isinstance(source.data, spd.GeoDataFrame):
gdf = source.data.to_geopandas()

Expand Down
18 changes: 16 additions & 2 deletions mapshader/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ def load_raster(file_path, transforms, force_recreate_overviews,
xmin=None, ymin=None, xmax=None, ymax=None, chunks=None,
layername='data'):
"""
Load raster data.
Load raster data from a path into a xarray DataArray. The input data can be in one of following
extensions: .tif, .nc, or .vrt. If a NetCDF file (.nc) is provided, a layer name must be
specified. Transforms can be applied while loading.

Parameters
----------
file_path : str
Relative path to the file.
transforms: List
List of transforms to apply to the raster data.
force_recreate_overviews: bool
Whether to force recreate overview data.
xmin : float
X-axis minimum range.
ymin : float
Expand Down Expand Up @@ -80,12 +86,20 @@ def load_vector(
region_of_interest,
):
"""
Load vector data.
Load vector data from a file path to a geopandas or dask-geopandas DataFrame. If the data is
from a S3 bucket, storage options with access key ID and secret access key must be provided.

Parameters
----------
filepath : str
Relative path to the file.
storage_options: Dict
Dictionary that contains user information including access key ID and secret access key
geometry: str
Geometry column in the data frame
region_of_interest: list-like object
Only select data that lies within, or intersects with this region.
The region is a list-like object with 4 values of minx, miny, maxx, maxy

Returns
-------
Expand Down