Skip to content

Commit

Permalink
option to plot empty cells; fixed negative vmin for density; v0.4.7; c…
Browse files Browse the repository at this point in the history
…loses #32
  • Loading branch information
pmelchior committed Sep 17, 2024
1 parent 9c124f9 commit 343e4e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
description="Mapping astronomical survey data on the sky, handsomely",
long_description=long_description,
long_description_content_type='text/markdown',
version="0.4.6",
version="0.4.7",
license="MIT",
author="Peter Melchior",
author_email="peter.m.melchior@gmail.com",
Expand Down
13 changes: 10 additions & 3 deletions skymapper/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,10 @@ def healpix(self, m, nest=False, color_percentiles=[10,90], **kwargs):
vmax = kwargs.pop("vmax", None)
if vmin is None or vmax is None:
vlim = np.percentile(vp.data[inside], color_percentiles)
# if only a few different values exist, percentiles don't work:
# default to min/max
if vlim[0] == vlim[1]:
vlim = (vp.data[inside].min(), vp.data[inside].max())
if vmin is None:
vmin = vlim[0]
if vmax is None:
Expand Down Expand Up @@ -1276,24 +1280,27 @@ def footprint(self, survey, nside, **kwargs):
inside = survey.contains(rap, decp)
return self.vertex(vertices[inside], **kwargs)

def density(self, lon, lat, nside=1024, **kwargs):
def density(self, lon, lat, nside=1024, mask_empty=True, **kwargs):
"""Plot sample density using healpix binning
Args:
lon: list of longitudes
lat: list of latitudes
nside: HealPix nside
mask_empty: Whether empty cells should be hidden.
**kwargs: additional arguments for healpix()
"""
# get count in healpix cells, restrict to non-empty cells
bc = healpix.getCountAtLocations(lon, lat, nside=nside)
bc = np.ma.array(bc, mask=(bc==0))
if mask_empty:
bc = np.ma.array(bc, mask=(bc==0))

# styling
vmin = kwargs.pop("vmin", 0) # densities cannot be negative
cmap = kwargs.pop("cmap", "YlOrRd")

# make map
return self.healpix(bc, cmap=cmap, **kwargs)
return self.healpix(bc, vmin=vmin, cmap=cmap, **kwargs)

def extrapolate(self, lon, lat, value, resolution=100, **kwargs):
"""Extrapolate lon,lat,value samples on the entire sphere
Expand Down

0 comments on commit 343e4e3

Please sign in to comment.