Skip to content

Commit

Permalink
all changes (minor)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Sommani committed Oct 12, 2023
2 parents 1017e00 + 686416b commit 988fb21
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 71 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/wipac-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,6 @@ jobs:
if: always()
run: |
more *.json | cat
functionality-tests:
needs: [py-versions]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py3: ${{ fromJSON(needs.py-versions.outputs.matrix) }}
input-file: [ "millipede_wilks/run00136662.evt000035405932.neutrino_1" ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py3 }}
- uses: actions/checkout@v3
with:
repository: icecube/skymap_scanner
ref: main
path: skymap_scanner
sparse-checkout: tests/data
- name: pip install
run: |
pip install --upgrade pip wheel setuptools
pip install .
- name: Run conversion script
# working-directory: auxiliary-repo/path/to/directory # Replace 'path/to/directory' with the path to the directory containing your Python script
run: |
python examples/npz_to_json.py --input-file skymap_scanner/tests/data/results_npz/${{ matrix.input-file }}.npz --output-dir .
cat $(ls -Art | tail -n 1) # cat outfile
# Wait for skymap_scanner PR#163
# - name: Compare output
# run: |
# tree
# outfile=$(ls -Art | tail -n 1)
# diff $outfile skymap_scanner/tests/data/results_json/${{ matrix.input-file }}.json






release:
# only run on main/master/default
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

<!--next-version-placeholder-->

## v1.2.5 (2023-10-12)

### Other

* <bot> update requirements-examples.txt ([`1458ac1`](https://github.com/icecube/skyreader/commit/1458ac1d2ce9ec33512a294bd86e34f823ddd375))
* Plotting functions cleanup ([#21](https://github.com/icecube/skyreader/issues/21)) ([`97dff8e`](https://github.com/icecube/skyreader/commit/97dff8efa79d5bd480f6e947f3fe47a87e565385))

## v1.2.4 (2023-08-11)

### Other
Expand Down
4 changes: 4 additions & 0 deletions requirements-examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,9 @@ wipac-dev-tools==1.7.0
# via
# icecube-skyreader (setup.py)
# wipac-rest-tools
<<<<<<< HEAD
wipac-rest-tools==1.5.3
=======
wipac-rest-tools==1.6.0
>>>>>>> main
# via icecube-skyreader (setup.py)
2 changes: 1 addition & 1 deletion skyreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# is zero for an official release, positive for a development branch,
# or negative for a release candidate or beta (after the base version
# number has been incremented)
__version__ = "1.2.4"
__version__ = "1.2.5"
version_info = (
int(__version__.split(".")[0]),
int(__version__.split(".")[1]),
Expand Down
5 changes: 5 additions & 0 deletions skyreader/plot/plotting_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def set_xlim(self, *args, **kwargs):
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)

def _get_core_transform(self, resolution):
# mypy error: "_get_core_transform" undefined in superclass [misc]
return Affine2D().translate(-np.pi, 0.) + super(AstroMollweideAxes, self)._get_core_transform(resolution)

class RaFormatter(Formatter):
Expand All @@ -207,6 +208,7 @@ def __call__(self, x, pos=None):
def set_longitude_grid(self, degrees):
# Copied from matplotlib.geo.GeoAxes.set_longitude_grid and modified
number = (360 // degrees) + 1
# mypy error: Argument 1 to "FixedLocator" has incompatible type "ndarray[Any, dtype[floating[Any]]]"; expected "Sequence[float]"
self.xaxis.set_major_locator(
FixedLocator(
np.linspace(0, 2*np.pi, number, True)[1:-1]))
Expand All @@ -215,6 +217,7 @@ def set_longitude_grid(self, degrees):

def _set_lim_and_transforms(self):
# Copied from matplotlib.geo.GeoAxes._set_lim_and_transforms and modified
# mypy error: Argument 1 to "FixedLocator" has incompatible type "ndarray[Any, dtype[floating[Any]]]"; expected "Sequence[float]"
super(AstroMollweideAxes, self)._set_lim_and_transforms()

# This is the transform for latitude ticks.
Expand All @@ -223,6 +226,8 @@ def _set_lim_and_transforms(self):
self._yaxis_transform = \
yaxis_stretch + \
self.transData
# mypy error: "AstroMollweideAxes" has no attribute "transProjection" [attr-defined]
# mypy error: "AstroMollweideAxes" has no attribute "transAffine" [attr-defined]
yaxis_text_base = \
yaxis_stretch + \
self.transProjection + \
Expand Down
104 changes: 76 additions & 28 deletions skyreader/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,40 @@ def best_dir(self):
plot_x_size_in = 6
plot_dpi_standard = 150
plot_dpi_zoomed = 1200
<<<<<<< HEAD
=======
plot_colormap = matplotlib.colormaps['plasma_r']
>>>>>>> main

def check_result(self):
"""Check in legacy plotting code.
"""
for k in self.result:
if "nside-" not in k:
raise RuntimeError("\"nside\" not in result file..")

@staticmethod
# Calculates are using Gauss-Green theorem / shoelace formula
# TODO: vectorize using numpy.
# Note: in some cases the argument is not a np.ndarray so one has to convert the data series beforehand.
def calculate_area(vs) -> float:
a = 0
x0, y0 = vs[0]
for [x1,y1] in vs[1:]:
dx = x1-x0
dy = y1-y0
a += 0.5*(y0*dx - x0*dy)
x0 = x1
y0 = y1
return a

def create_plot(self, dozoom = False):

dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed
xsize = self.plot_x_size_in * dpi
ysize = xsize // 2

self.check_result()

def create_plot(self, dozoom = False):

Expand Down Expand Up @@ -686,7 +713,11 @@ def create_plot(self, dozoom = False):
print(f"preparing plot: {plot_filename}...")

# the color map to use
<<<<<<< HEAD
cmap = matplotlib.cm.plasma_r # mypy warning
=======
cmap = self.plot_colormap
>>>>>>> main
cmap.set_under(alpha=0.) # make underflows transparent
cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red

Expand All @@ -703,18 +734,7 @@ def create_plot(self, dozoom = False):
image = ax.pcolormesh(ra, dec, grid_map, vmin=min_value, vmax=max_value, rasterized=True, cmap=cmap)
# ax.set_xlim(np.pi, -np.pi)

# Use Green's theorem to compute the area
# enclosed by the given contour.
def area(vs):
a = 0
x0,y0 = vs[0]
for [x1,y1] in vs[1:]:
dx = x1-x0
dy = y1-y0
a += 0.5*(y0*dx - x0*dy)
x0 = x1
y0 = y1
return a


contour_levels = (np.array([1.39, 4.61, 11.83, 28.74])+min_value)[:2]
contour_labels = [r'50%', r'90%', r'3$\sigma$', r'5$\sigma$'][:2]
Expand All @@ -729,8 +749,15 @@ def area(vs):

if not dozoom:
# graticule
<<<<<<< HEAD
ax.set_longitude_grid(30) # mypy warning
ax.set_latitude_grid(30) # mypy warning
=======
# mypy error: "Axes" has no attribute "set_longitude_grid" [attr-defined]
ax.set_longitude_grid(30)
# mypy error: "Axes" has no attribute "set_latitude_grid" [attr-defined]
ax.set_latitude_grid(30)
>>>>>>> main
cb = fig.colorbar(image, orientation='horizontal', shrink=.6, pad=0.05, ticks=[min_value, max_value])
cb.ax.xaxis.set_label_text(r"$-2 \ln(L)$")
else:
Expand All @@ -743,7 +770,8 @@ def area(vs):
for i in range(len(contour_labels)):
vs = cs_collections[i].get_paths()[0].vertices
# Compute area enclosed by vertices.
a = area(vs) # will be in square-radians
# Take absolute values to be independent of orientation of the boundary integral.
a = abs(self.calculate_area(vs)) # will be in square-radians
a = a*(180.*180.)/(np.pi*np.pi) # convert to square-degrees

leg_labels.append(f'{contour_labels[i]} - area: {a:.2f}sqdeg')
Expand All @@ -755,7 +783,11 @@ def area(vs):
x_width = 1.6 * np.sqrt(a)

if np.isnan(x_width):
<<<<<<< HEAD
# mypy warning
=======
# error: "QuadContourSet" has no attribute "allsegs" [attr-defined]
>>>>>>> main
x_width = 1.6*(max(CS.allsegs[i][0][:,0]) - min(CS.allsegs[i][0][:,0]))
print(x_width)
y_width = 0.5 * x_width
Expand All @@ -765,8 +797,12 @@ def area(vs):
lower_y = max(minDec -y_width*np.pi/180., -np.pi/2.)
upper_y = min(minDec + y_width*np.pi/180., np.pi/2.)

<<<<<<< HEAD
# should this just be set_xlim(upper_x, lower_x) ?
ax.set_xlim( [lower_x, upper_x][::-1]) # mypy warning
=======
ax.set_xlim(upper_x, lower_x)
>>>>>>> main
ax.set_ylim(lower_y, upper_y)

ax.xaxis.set_major_formatter(DecFormatter())
Expand All @@ -782,7 +818,14 @@ def area(vs):

# cb.ax.xaxis.labelpad = -8
# workaround for issue with viewers, see colorbar docstring
<<<<<<< HEAD
cb.solids.set_edgecolor("face") # mypy warning
=======
# mypy compliance: since cb.solids could be None, we check that it is actually
# a valid object before accessing it
if isinstance(cb.solids, matplotlib.collections.QuadMesh):
cb.solids.set_edgecolor("face")
>>>>>>> main

if dozoom:
ax.set_aspect('equal')
Expand All @@ -796,7 +839,12 @@ def area(vs):
effects = [patheffects.withStroke(linewidth=1.1, foreground='w')]
# mypy warnings
for artist in ax.findobj(text.Text):
<<<<<<< HEAD
artist.set_path_effects(effects) # mypy warning
=======
# mypy error: Argument 1 to "set_path_effects" of "Artist" has incompatible type "list[withStroke]"; expected "list[AbstractPathEffect]" [arg-type]
artist.set_path_effects(effects)
>>>>>>> main

# remove white space around figure
spacing = 0.01
Expand All @@ -820,8 +868,12 @@ def create_plot_zoomed(self,
extra_radius=np.nan,
systematics=False,
plot_bounding_box=False,
<<<<<<< HEAD
plot_4fgl=False,
is_rude=False):
=======
plot_4fgl=False):
>>>>>>> main
"""Uses healpy to plot a map."""

def bounding_box(ra, dec, theta, phi):
Expand Down Expand Up @@ -919,7 +971,11 @@ def bounding_box(ra, dec, theta, phi):

print("preparing plot: {0}...".format(plot_filename))

<<<<<<< HEAD
cmap = matplotlib.cm.plasma_r # mypy warning
=======
cmap = self.plot_colormap
>>>>>>> main
cmap.set_under('w')
cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red

Expand Down Expand Up @@ -1025,31 +1081,23 @@ def circular_contour(ra, dec, sigma, nside):
healpy.projplot(np.pi/2 - minDec, minRA,
'*', ms=5, label=r'scan best fit', color='black', zorder=2)

# Use Green's theorem to compute the area
# enclosed by the given contour.
def area(vs):
a = 0
x0,y0 = vs[0]
for [x1,y1] in vs[1:]:
dx = x1-x0
dy = y1-y0
a += 0.5*(y0*dx - x0*dy)
x0 = x1
y0 = y1
return a

# Plot the contours
contour_areas=[]
for contour_level, contour_label, contour_color, contours in zip(contour_levels,
contour_labels, contour_colors, contours_by_level):
contour_area = 0
contour_area = 0.
for contour in contours:
_ = contour.copy()
_[:,1] += np.pi-np.radians(ra)
_[:,1] %= 2*np.pi
<<<<<<< HEAD
contour_area += area(_)
contour_area = abs(contour_area)
contour_area_sqdeg = contour_area * (180.*180.)/(np.pi*np.pi) # convert to square-degrees
=======
contour_area += self.calculate_area(_)
contour_area_sqdeg = abs(contour_area) * (180.*180.)/(np.pi*np.pi) # convert to square-degrees
>>>>>>> main
contour_areas.append(contour_area_sqdeg)
contour_label = contour_label + ' - area: {0:.2f} sqdeg'.format(
contour_area_sqdeg)
Expand Down Expand Up @@ -1129,7 +1177,7 @@ def area(vs):
bounding_theta = np.pi/2 - np.radians(bounding_decs)
bounding_contour = np.array([bounding_theta, bounding_phi])
bounding_contour_area = 0.
bounding_contour_area = area(bounding_contour.T)
bounding_contour_area = abs(self.calculate_area(bounding_contour.T))
bounding_contour_area *= (180.*180.)/(np.pi*np.pi) # convert to square-degrees
contour_label = r'90% Bounding rectangle' + ' - area: {0:.2f} sqdeg'.format(
bounding_contour_area)
Expand Down

0 comments on commit 988fb21

Please sign in to comment.