Skip to content

Commit

Permalink
Fix bugs in healpix_hist.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctslater committed May 6, 2021
1 parent 37f04a3 commit 0e92ed3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions axs/axsframe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import math
import numpy as np
import healpy as hp
import pandas as pd
from axs import Constants
from pyspark.sql import DataFrame, Window
Expand Down Expand Up @@ -321,7 +322,7 @@ def histogram2d(self, cond1, cond2, numbins1, numbins2, min1=None, max1=None, mi

return x, y, z.reshape((numbins1, numbins2))

def healpix_hist(NSIDE=64, groupby=[], agg={"*": "count"}, healpix_column="hpix12",
def healpix_hist(self, NSIDE=64, groupby=[], agg={"*": "count"}, healpix_column="hpix12",
return_df=False):
"""
Return a healpix-binned histogram at a resolution specified by NSIDE,
Expand Down Expand Up @@ -361,7 +362,7 @@ def healpix_hist(NSIDE=64, groupby=[], agg={"*": "count"}, healpix_column="hpix1

# fetch result
df = df.toPandas()
if returnDf:
if return_df:
return df

# repack the result into maps
Expand All @@ -381,7 +382,7 @@ def _create_map(df):
if len(idxcols) == 0:
ret = _create_map(df)
assert(len(ret) == 1)
if not returnDf:
if not return_df:
# convert to tuple, or scalar
ret = tuple(ret[name].values[0] for name in results)
if len(ret) == 1:
Expand All @@ -392,7 +393,7 @@ def _create_map(df):
ret.index.rename([ name.split("_bin__")[0] for name in ret.index.names ], inplace=True)
if "count(1)" in ret:
ret = ret.rename(columns={'count(1)': 'count'})
if not returnDf:
if not return_df:
if len(ret.columns) == 1:
ret = ret.iloc[:, 0]
return ret
Expand Down

0 comments on commit 0e92ed3

Please sign in to comment.