Skip to content
Merged
29 changes: 0 additions & 29 deletions .github/workflows/create_release.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish Python distribution to PyPI

on:
push:
tags:
- 'v*'

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install build tools
run: |
python -m pip install --upgrade pip
python -m pip install build

- name: Build package
run: python -m build

- name: Store distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/cs_util
permissions:
id-token: write

steps:
- name: Download distribution packages
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
126 changes: 7 additions & 119 deletions cs_util/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import matplotlib.pylab as plt
import matplotlib.ticker as ticker
import numpy as np
import skyproj
from typing import Any
try:
import skyproj
except ImportError:
skyproj = None
from astropy import units as u
from astropy.coordinates import SkyCoord

Expand Down Expand Up @@ -502,123 +506,7 @@ def create_hsp_map(self, ra, dec):

return hsp_map

def plot_area(
self,
hsp_map,
ra_0=0,
extend=[120, 270, 29, 70],
vmin=0,
vmax=60,
projection=None,
outpath=None,
title=None,
colorbar=True,
colorbar_label="Coverage depth",
):
"""Plot Area.

Plot catalogue in an area on the sky.

Parameters
----------
hsp_map : hsp_HealSparseMap
input map
ra_0 : float, optional
anchor point in R.A.; default is 0
extend : list, optional
sky region, extend=[ra_low, ra_high, dec_low, dec_high];
default is [120, 270, 29, 70]
vmin : float, optional
minimum pixel value to plot with color; default is 0
vmax : float, optional
maximum pixel value to plot with color; default is 60
projection : skyproj.McBrydeSkyproj
if ``None`` (default), a new plot is created
outpath : str, optional
output path, default is ``None``
title : str, optional
print title if not ``None`` (default)
colorbar : bool, optional
add colorbar; default is ``True``
colorbar_label : str, optional
colorbar label; default is "Coverage depth"

Returns
--------
skyproj.McBrydeSkyproj
projection instance
plt.axes.Axes
axes instance

Raises
------
ValueError
if no object found in region

"""
if not projection:

# Create new figure and axes
fig, ax = plt.subplots(figsize=(10, 10))

# Create new projection
projection = skyproj.McBrydeSkyproj(
ax=ax,
lon_0=ra_0,
extent=extend,
autorescale=False,
)
else:
ax = None

im = None
try:
im, lon_raster, lat_raster, values_raster = projection.draw_hspmap(
hsp_map, lon_range=extend[0:2], lat_range=extend[2:], vmin=vmin, vmax=vmax
)
except ValueError:
msg = "No object found in region to draw"
print(f"{msg}, continuing...")

projection.draw_milky_way(
width=25, linewidth=1.5, color="black", linestyle="-"
)

# Use skyproj's own methods to enforce extent
projection.set_autorescale(False)
projection.set_extent(extend)

# Set axis labels
if ax:
ax.set_xlabel("R.A. [deg]")
ax.set_ylabel("Dec [deg]")
else:
projection.ax.set_xlabel("R.A. [deg]")
projection.ax.set_ylabel("Dec [deg]")

# Add colorbar if requested and image was drawn
if colorbar and im is not None:
plt.colorbar(
im,
ax=ax if ax else projection.ax,
label=colorbar_label,
orientation="horizontal",
location="top",
pad=0.05,
)

if title:
plt.title(title, pad=5)

# Force extent again after all plotting operations to ensure it's respected
projection.set_autorescale(False)
projection.set_extent(extend)

if outpath:
plt.savefig(outpath)

return projection, ax


def plot_region(
self,
hsp_map,
Expand All @@ -639,7 +527,7 @@ def plot_region(
input map
region : dict
region dictionary with keys 'ra_0', 'extend', 'vmin', 'vmax'
projection : skyproj.McBrydeSkyproj, optional
projection : Any, optional
if ``None`` (default), a new plot is created
outpath : str, optional
output path, default is ``None``
Expand Down
Loading