Skip to content

Commit 0776591

Browse files
fixed sky plot
1 parent 995b87c commit 0776591

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

cs_util/plots.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ class FootprintPlotter:
449449

450450
# Dictionary storing region parameters
451451
_regions = {
452-
"NGC": {"ra_0": 180, "extend": [120, 270, 20, 70], "vmax": 60},
453-
"SGC": {"ra_0": 15, "extend": [-20, 45, 20, 45], "vmax": 60},
454-
"fullsky": {"ra_0": 150, "extend": [0, 360, -90, 90], "vmax": 60},
452+
"NGC": {"ra_0": 180, "extend": [120, 270, 20, 70], "vmin": 0, "vmax": 60},
453+
"SGC": {"ra_0": 15, "extend": [-20, 45, 20, 45], "vmin": 0, "vmax": 60},
454+
"fullsky": {"ra_0": 150, "extend": [0, 360, -90, 90], "vmin": 0, "vmax": 60},
455455
}
456456

457457
def __init__(self, nside_coverage=32, nside_map=2048):
@@ -507,6 +507,7 @@ def plot_area(
507507
hsp_map,
508508
ra_0=0,
509509
extend=[120, 270, 29, 70],
510+
vmin=0,
510511
vmax=60,
511512
projection=None,
512513
outpath=None,
@@ -527,6 +528,8 @@ def plot_area(
527528
extend : list, optional
528529
sky region, extend=[ra_low, ra_high, dec_low, dec_high];
529530
default is [120, 270, 29, 70]
531+
vmin : float, optional
532+
minimum pixel value to plot with color; default is 0
530533
vmax : float, optional
531534
maximum pixel value to plot with color; default is 60
532535
projection : skyproj.McBrydeSkyproj
@@ -560,15 +563,15 @@ def plot_area(
560563

561564
# Create new projection
562565
projection = skyproj.McBrydeSkyproj(
563-
ax=ax, lon_0=ra_0, extent=extend, autorescale=True, vmax=vmax
566+
ax=ax, lon_0=ra_0, extent=extend, autorescale=False
564567
)
565568
else:
566569
ax = None
567570

568571
im = None
569572
try:
570573
im, lon_raster, lat_raster, values_raster = projection.draw_hspmap(
571-
hsp_map, lon_range=extend[0:2], lat_range=extend[2:]
574+
hsp_map, lon_range=extend[0:2], lat_range=extend[2:], vmin=vmin, vmax=vmax
572575
)
573576
except ValueError:
574577
msg = "No object found in region to draw"
@@ -578,6 +581,10 @@ def plot_area(
578581
width=25, linewidth=1.5, color="black", linestyle="-"
579582
)
580583

584+
# Use skyproj's own methods to enforce extent
585+
projection.set_autorescale(False)
586+
projection.set_extent(extend)
587+
581588
# Set axis labels
582589
if ax:
583590
ax.set_xlabel("R.A. [deg]")
@@ -600,6 +607,10 @@ def plot_area(
600607
if title:
601608
plt.title(title, pad=5)
602609

610+
# Force extent again after all plotting operations to ensure it's respected
611+
projection.set_autorescale(False)
612+
projection.set_extent(extend)
613+
603614
if outpath:
604615
plt.savefig(outpath)
605616

@@ -624,7 +635,7 @@ def plot_region(
624635
hsp_map : hsp_HealSparseMap
625636
input map
626637
region : dict
627-
region dictionary with keys 'ra_0', 'extend', 'vmax'
638+
region dictionary with keys 'ra_0', 'extend', 'vmin', 'vmax'
628639
projection : skyproj.McBrydeSkyproj, optional
629640
if ``None`` (default), a new plot is created
630641
outpath : str, optional
@@ -648,6 +659,7 @@ def plot_region(
648659
hsp_map,
649660
region["ra_0"],
650661
region["extend"],
662+
region["vmin"],
651663
region["vmax"],
652664
projection=projection,
653665
outpath=outpath,

0 commit comments

Comments
 (0)