Skip to content

Commit d9907a0

Browse files
authored
Merge pull request #67 from CosmoStat/develop
Release 0.2.1: cs_util.size
2 parents a496569 + 672a0fc commit d9907a0

6 files changed

Lines changed: 369 additions & 151 deletions

File tree

.github/workflows/create_release.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Publish Python distribution to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
name: Build distribution
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.x"
19+
20+
- name: Install build tools
21+
run: |
22+
python -m pip install --upgrade pip
23+
python -m pip install build
24+
25+
- name: Build package
26+
run: python -m build
27+
28+
- name: Store distribution packages
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: python-package-distributions
32+
path: dist/
33+
34+
publish-to-pypi:
35+
name: Publish to PyPI
36+
needs: build
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: pypi
40+
url: https://pypi.org/p/cs_util
41+
permissions:
42+
id-token: write
43+
44+
steps:
45+
- name: Download distribution packages
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: python-package-distributions
49+
path: dist/
50+
51+
- name: Publish to PyPI
52+
uses: pypa/gh-action-pypi-publish@release/v1

cs_util/plots.py

Lines changed: 7 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
import matplotlib.pylab as plt
1717
import matplotlib.ticker as ticker
1818
import numpy as np
19-
import skyproj
19+
from typing import Any
20+
try:
21+
import skyproj
22+
except ImportError:
23+
skyproj = None
2024
from astropy import units as u
2125
from astropy.coordinates import SkyCoord
2226

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

503507
return hsp_map
504508

505-
def plot_area(
506-
self,
507-
hsp_map,
508-
ra_0=0,
509-
extend=[120, 270, 29, 70],
510-
vmin=0,
511-
vmax=60,
512-
projection=None,
513-
outpath=None,
514-
title=None,
515-
colorbar=True,
516-
colorbar_label="Coverage depth",
517-
):
518-
"""Plot Area.
519-
520-
Plot catalogue in an area on the sky.
521-
522-
Parameters
523-
----------
524-
hsp_map : hsp_HealSparseMap
525-
input map
526-
ra_0 : float, optional
527-
anchor point in R.A.; default is 0
528-
extend : list, optional
529-
sky region, extend=[ra_low, ra_high, dec_low, dec_high];
530-
default is [120, 270, 29, 70]
531-
vmin : float, optional
532-
minimum pixel value to plot with color; default is 0
533-
vmax : float, optional
534-
maximum pixel value to plot with color; default is 60
535-
projection : skyproj.McBrydeSkyproj
536-
if ``None`` (default), a new plot is created
537-
outpath : str, optional
538-
output path, default is ``None``
539-
title : str, optional
540-
print title if not ``None`` (default)
541-
colorbar : bool, optional
542-
add colorbar; default is ``True``
543-
colorbar_label : str, optional
544-
colorbar label; default is "Coverage depth"
545-
546-
Returns
547-
--------
548-
skyproj.McBrydeSkyproj
549-
projection instance
550-
plt.axes.Axes
551-
axes instance
552-
553-
Raises
554-
------
555-
ValueError
556-
if no object found in region
557-
558-
"""
559-
if not projection:
560-
561-
# Create new figure and axes
562-
fig, ax = plt.subplots(figsize=(10, 10))
563-
564-
# Create new projection
565-
projection = skyproj.McBrydeSkyproj(
566-
ax=ax,
567-
lon_0=ra_0,
568-
extent=extend,
569-
autorescale=False,
570-
)
571-
else:
572-
ax = None
573-
574-
im = None
575-
try:
576-
im, lon_raster, lat_raster, values_raster = projection.draw_hspmap(
577-
hsp_map, lon_range=extend[0:2], lat_range=extend[2:], vmin=vmin, vmax=vmax
578-
)
579-
except ValueError:
580-
msg = "No object found in region to draw"
581-
print(f"{msg}, continuing...")
582-
583-
projection.draw_milky_way(
584-
width=25, linewidth=1.5, color="black", linestyle="-"
585-
)
586-
587-
# Use skyproj's own methods to enforce extent
588-
projection.set_autorescale(False)
589-
projection.set_extent(extend)
590-
591-
# Set axis labels
592-
if ax:
593-
ax.set_xlabel("R.A. [deg]")
594-
ax.set_ylabel("Dec [deg]")
595-
else:
596-
projection.ax.set_xlabel("R.A. [deg]")
597-
projection.ax.set_ylabel("Dec [deg]")
598-
599-
# Add colorbar if requested and image was drawn
600-
if colorbar and im is not None:
601-
plt.colorbar(
602-
im,
603-
ax=ax if ax else projection.ax,
604-
label=colorbar_label,
605-
orientation="horizontal",
606-
location="top",
607-
pad=0.05,
608-
)
609-
610-
if title:
611-
plt.title(title, pad=5)
612-
613-
# Force extent again after all plotting operations to ensure it's respected
614-
projection.set_autorescale(False)
615-
projection.set_extent(extend)
616-
617-
if outpath:
618-
plt.savefig(outpath)
619-
620-
return projection, ax
621-
509+
622510
def plot_region(
623511
self,
624512
hsp_map,
@@ -639,7 +527,7 @@ def plot_region(
639527
input map
640528
region : dict
641529
region dictionary with keys 'ra_0', 'extend', 'vmin', 'vmax'
642-
projection : skyproj.McBrydeSkyproj, optional
530+
projection : Any, optional
643531
if ``None`` (default), a new plot is created
644532
outpath : str, optional
645533
output path, default is ``None``

0 commit comments

Comments
 (0)