Skip to content

Commit f923e00

Browse files
author
martinkilbinger
committed
black
1 parent d2f2b50 commit f923e00

2 files changed

Lines changed: 79 additions & 7 deletions

File tree

cs_util/cat.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
from datetime import datetime
1313
from importlib.metadata import version
14+
import numpy as np
1415
import healpy as hp
1516

1617
from astropy.io import fits
@@ -271,7 +272,27 @@ def read_dndz(file_path):
271272

272273

273274
def read_hp_mask(input_name, verbose=False):
275+
"""Read Hp Mask.
274276
277+
Read healpy mask.
278+
279+
Parameters
280+
----------
281+
input_name : str
282+
input file name
283+
verbose : bool, optional
284+
verbose output if ``True``;; default is ``False``
285+
286+
Returns
287+
-------
288+
array
289+
mask values
290+
bool
291+
nest value (always ``False``)
292+
int
293+
nside
294+
295+
"""
275296
if verbose:
276297
print(f'Reading mask {input_name}...')
277298

@@ -305,3 +326,45 @@ def read_hp_mask(input_name, verbose=False):
305326
raise KeyError('NSIDE not found in FITS mask header')
306327

307328
return mask, nest, nside
329+
330+
331+
def get_binned_area(ra, dec, nside=512, return_pix=False):
332+
"""Get Binned Area.
333+
334+
Return sky area corresponding to occupied pixels of binned catalogue.
335+
336+
Parameters
337+
----------
338+
ra : np.ndarray
339+
Right Ascension coordinates
340+
dec : np.ndarray
341+
Declination coordinates
342+
nside : int, optional
343+
nside for binning; default is 512
344+
return_pix: bool, optional
345+
return valid pixel list if ``True``; default is ``False``
346+
347+
Returns
348+
-------
349+
float
350+
area in square degrees
351+
list
352+
pixels of input data positions
353+
354+
"""
355+
# Pixel list of input data
356+
pix = hp.ang2pix(nside, ra, dec, lonlat=True)
357+
358+
# Number of occupied pixels
359+
Nocc = np.unique(pix).size
360+
361+
# Pixel area in square degrees
362+
pix_area_deg2 = hp.nside2pixarea(nside, degrees=True)
363+
364+
# Footprint area in square degrees
365+
area_deg2 = Nocc * pix_area_deg2
366+
367+
if return_pix:
368+
return area_deg2, pix
369+
else:
370+
return area_deg2

cs_util/plots.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,20 @@ def show():
6161
plt.close()
6262

6363

64-
def dx(idx, nx=3, fx=1.015, log=True):
64+
def get_x_dx(x_arr, shift_x, idx, log=True):
65+
66+
if shift_x:
67+
if log:
68+
this_x = x_arr[idx] * dx(idx, len(x_arr), log=log)
69+
else:
70+
raise ValueError("shift_x without log not implemented yet")
71+
else:
72+
this_x = x_arr[idx]
73+
74+
return this_x
75+
76+
77+
def dx(idx, nx=3, fx=1.03, log=True):
6578
"""Dx.
6679
6780
Return small shift useful to diplace points along the the x-axis
@@ -288,12 +301,8 @@ def plot_data_1d(
288301
fig = ax.figure
289302

290303
for idx in range(len(x)):
291-
this_x = x[idx]
292-
if shift_x:
293-
if xlog:
294-
this_x *= dx(idx, len(x), log=xlog)
295-
else:
296-
raise ValueError("shift_x without log not implemented yet")
304+
this_x = get_x_dx(x, shift_x, idx, log=xlog)
305+
297306
if np.isnan(yerr[idx]).all():
298307
eb = ax.plot(
299308
this_x,

0 commit comments

Comments
 (0)