Skip to content

Commit

Permalink
Merge branch 'master' into with_columns
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelljweinstein committed Oct 3, 2016
2 parents 5f03ac9 + 405ce87 commit 76dac3a
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 157 deletions.
55 changes: 0 additions & 55 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[ ] Wrote test for feature
[ ] Added note about PR in CHANGELOG.md
[ ] Added changes in the Changelog section in README.md
[ ] Bumped version number (delete if unneeded)

**Changes proposed:**
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
A Berkeley library for introductory data science.

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dsten/datascience?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Documentation Status](https://readthedocs.org/projects/datascience/badge/?version=v0.5.1)](http://datascience.readthedocs.org/en/v0.5.1/?badge=v0.5.1)
[![Documentation Status](https://readthedocs.org/projects/datascience/badge/?version=master)](http://datascience.readthedocs.org/en/master/?badge=master)


*written by Professor [John DeNero](http://denero.org), Professor
[David Culler](http://www.cs.berkeley.edu/~culler),
[Sam Lau](https://github.com/samlau95), and [Alvin Wan](http://alvinwan.com)*

For an example of usage, see the [Berkeley Data 8 class](http://databears.berkeley.edu/content/csinfostat-c8-foundations-data-science).
For an example of usage, see the [Berkeley Data 8 class](http://data8.org/).

[![Build Status](https://travis-ci.org/data-8/datascience.svg?branch=master)](https://travis-ci.org/data-8/datascience)
[![Coverage Status](https://coveralls.io/repos/dsten/datascience/badge.svg?branch=master&service=github)](https://coveralls.io/github/dsten/datascience?branch=master)
Expand All @@ -23,6 +23,31 @@ Use `pip`:
pip install datascience
```

## Changelog

This project adheres to [Semantic Versioning](http://semver.org/).

### [Unreleased]
None yet.

### v0.8.0
**Breaking changes**

- Change default behavior of `table.sample` to `with_replacement=True` instead
of `False`. (3717b67)

**Additions**

- Added `Map.copy`.
- Added `Map.overlay` which overlays a feature(s) on a new copy of Map.
(315bb63e)

### v0.7.1
- Remove rogue print from `table.hist`

### v0.7.0
- Added predicates for string comparison: `containing` and `contained_in`. (#231)

## Documentation

API reference is at http://data8.org/datascience/ .
Expand Down
57 changes: 57 additions & 0 deletions datascience/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import functools
import random

from .tables import Table

_number = (int, float, np.number)


Expand Down Expand Up @@ -92,6 +94,16 @@ def __init__(self, features=(), ids=(), width=960, height=500, **kwargs):
self._height = height
self._attrs.update(kwargs)

def copy(self):
"""
Copies the current Map into a new one and returns it.
"""

m = Map(features=self._features, width=self._width,
height=self._height, **self._attrs)
m._folium_map = self._folium_map
return m

def __getitem__(self, id):
return self._features[id]

Expand Down Expand Up @@ -257,6 +269,51 @@ def color(self, values, ids=(), key_on='feature.id', palette='YlOrBr', **kwargs)
colored._folium_map = m
return colored

def overlay(self, feature, color='Blue', opacity=0.6):
"""
Overlays ``feature`` on the map. Returns a new Map.
Args:
``feature``: a ``Table`` of map features, a list of map features,
a Map, a Region, or a circle marker map table. The features will
be overlayed on the Map with specified ``color``.
``color`` (``str``): Color of feature. Defaults to 'Blue'
``opacity`` (``float``): Opacity of overlain feature. Defaults to
0.6.
Returns:
A new ``Map`` with the overlain ``feature``.
"""
result = self.copy()
if type(feature) == Table:
# if table of features e.g. Table.from_records(taz_map.features)
if 'feature' in feature:
feature = feature['feature']

# if marker table e.g. table with columns: latitudes,longitudes,popup,color,radius
else:
feature = Circle.map_table(feature)

if type(feature) in [list, np.ndarray]:
for f in feature:
f._attrs['fill_color'] = color
f._attrs['fill_opacity'] = opacity
f.draw_on(result._folium_map)

elif type(feature) == Map:
for i in range(len(feature._features)):
f = feature._features[i]
f._attrs['fill_color'] = color
f._attrs['fill_opacity'] = opacity
f.draw_on(result._folium_map)
elif type(feature) == Region:
feature._attrs['fill_color'] = color
feature._attrs['fill_opacity'] = opacity
feature.draw_on(result._folium_map)
return result

@classmethod
def read_geojson(cls, path_or_json_or_string):
"""Read a geoJSON string, object, or file. Return a dict of features keyed by ID."""
Expand Down

0 comments on commit 76dac3a

Please sign in to comment.