Skip to content
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
92cfc29
deprecate log_func
mlincett Sep 29, 2023
01931ce
<bot> update requirements-examples.txt
wipacdevbot Sep 29, 2023
bfdf70e
<bot> update requirements-tests.txt
wipacdevbot Sep 29, 2023
036a620
<bot> update requirements.txt
wipacdevbot Sep 29, 2023
478b2af
deprecate upload-func
mlincett Sep 29, 2023
36b94d3
deprecate further slack posting logic
mlincett Sep 29, 2023
ff212e4
further remove deprecated logic
mlincett Sep 29, 2023
5d23c1b
assume we always save plots
mlincett Sep 29, 2023
e8cee41
single source of truth for inches/dpi
mlincett Sep 29, 2023
6b6840d
remove unused vars
mlincett Sep 29, 2023
d3f4431
remove import io
mlincett Sep 29, 2023
1ee865a
update example
mlincett Sep 29, 2023
cda9860
de-type plotting function
mlincett Sep 29, 2023
3d6747f
some notes from mypy
mlincett Sep 29, 2023
b0730dc
mypy readiness step
mlincett Sep 29, 2023
929b185
<bot> update setup.cfg
wipacdevbot Oct 9, 2023
dabfff5
<bot> update requirements-examples.txt
wipacdevbot Oct 9, 2023
d80577d
<bot> update requirements-tests.txt
wipacdevbot Oct 9, 2023
004881f
<bot> update requirements.txt
wipacdevbot Oct 9, 2023
a773efe
Testing conection branch skymist
G-Sommani Oct 9, 2023
612494d
Fixed minor bug in result.py, function make_plot_zoomed()
G-Sommani Oct 9, 2023
4117ce8
Fixed minor bug in result.py, function make_plot_zoomed(), part 2
G-Sommani Oct 9, 2023
438a1d7
Testing conection branch skymist Part 2
G-Sommani Oct 9, 2023
2761d60
New boolean value to identify rude events
G-Sommani Oct 9, 2023
d460449
Exploring new contours for rude events Part 1
G-Sommani Oct 9, 2023
35ccbcf
Exploring new contours for rude events Part 2
G-Sommani Oct 9, 2023
9142568
Exploring new contours for rude events Part 3
G-Sommani Oct 9, 2023
f26a5f3
Exploring new contours for rude events Part 4
G-Sommani Oct 9, 2023
d93f254
Exploring new contours for rude events Part 5
G-Sommani Oct 9, 2023
586d724
Exploring new contours for rude events Part 5
G-Sommani Oct 9, 2023
7c44247
Exploring new contours for rude events Part 6
G-Sommani Oct 9, 2023
2368ce3
Exploring new contours for rude events Part 7
G-Sommani Oct 9, 2023
1017e00
Implemented contours for rude events
G-Sommani Oct 9, 2023
988fb21
all changes (minor)
G-Sommani Oct 12, 2023
b897ee9
<bot> update requirements-examples.txt
wipacdevbot Oct 12, 2023
d4725f7
Solve issues for merge
G-Sommani Oct 13, 2023
ce5d6a9
Moved circular_contour() to class level
G-Sommani Oct 13, 2023
2c23451
Missing self in circular_contour() on class level
G-Sommani Oct 13, 2023
3c82025
boolean parameter 'is_rude' changed in 'circular'. Added 50% and 90% …
G-Sommani Oct 13, 2023
b78a768
Improved handling of circular contours with numpy
G-Sommani Oct 13, 2023
08b5165
Fixed error in calling np.dstack()
G-Sommani Oct 13, 2023
7488e49
Fixing bugs after implementation of np.dstack()
G-Sommani Oct 13, 2023
d3819d0
circular_contour() as static method
G-Sommani Oct 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 45 additions & 30 deletions skyreader/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,13 +825,42 @@ def create_plot(self, dozoom = False):

print("done.")

@staticmethod
def circular_contour(ra, dec, sigma, nside):
"""For plotting circular contours on skymaps ra, dec, sigma all
expected in radians."""
dec = np.pi/2. - dec
sigma = np.rad2deg(sigma)
delta, step, bins = 0, 0, 0
delta= sigma/180.0*np.pi
step = 1./np.sin(delta)/10.
bins = int(360./step)
Theta = np.zeros(bins+1, dtype=np.double)
Phi = np.zeros(bins+1, dtype=np.double)
# define the contour
for j in range(0,bins) :
phi = j*step/180.*np.pi
vx = np.cos(phi)*np.sin(ra)*np.sin(delta) + np.cos(ra)*(np.cos(delta)*np.sin(dec) + np.cos(dec)*np.sin(delta)*np.sin(phi))
vy = np.cos(delta)*np.sin(dec)*np.sin(ra) + np.sin(delta)*(-np.cos(ra)*np.cos(phi) + np.cos(dec)*np.sin(ra)*np.sin(phi))
vz = np.cos(dec)*np.cos(delta) - np.sin(dec)*np.sin(delta)*np.sin(phi)
idx = healpy.vec2pix(nside, vx, vy, vz)
DEC, RA = healpy.pix2ang(nside, idx)
Theta[j] = DEC
Phi[j] = RA
Theta[bins] = Theta[0]
Phi[bins] = Phi[0]
return Theta, Phi

def create_plot_zoomed(self,
extra_ra=np.nan,
extra_dec=np.nan,
extra_radius=np.nan,
systematics=False,
plot_bounding_box=False,
plot_4fgl=False):
plot_4fgl=False,
circular=False,
circular_err50=0.2,
circular_err90=0.7):
Comment on lines 854 to +863
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is acceptable to me at this stage, I don't like very much the idea of an ever-growing list of (boolean) arguments in order to control the variant of the plotting.

This leads to a situation where we have 2^n combinations of settings and most of those are not meaningful or have undefined behaviour.

For example, passing circular=True would make the value of systematics irrelevant.

At some point we may want to define the plotting variants in a more structured way (as part of #22 ).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if it's possible to merge the functionality here with the extra_ra/dec/radius arguments? Those are used for plotting the online splinempe circular contours already. With the additional err50/err90 arguments that means it's also possible for err90 < err50 which wouldn't be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to keep the option to have both the online splinempe circular contours and other circularized errors at the same time, so I would keep all the arguments. I can add the raising of an error if err90 is smaller than err50.

Copy link
Contributor

@mlincett mlincett Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are several scenario we should cover, I tried to put together a list in #26

The existing extra* arguments allow for a single radius at an arbitrary direction, while here we want two radii at the best fit direction.

I am not sure if we should put effort into merging the two functionalities now considering that all would have to be refactored later.

I guess ultimately we want to achieve something of the kind:

def create_plot_zoomed(self, contours: list[ContourModel], catalogs: list[Catalog])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mlincett for creating the issue. I'm fine with merging this in as it sounds like we're all onboard with improving things later.

"""Uses healpy to plot a map."""

def bounding_box(ra, dec, theta, phi):
Expand Down Expand Up @@ -946,10 +975,21 @@ def bounding_box(ra, dec, theta, phi):
contour_colors=['k', 'r', 'g', 'b'][:3]

sample_points = np.array([np.pi/2 - grid_dec, grid_ra]).T

# Call meander module to find contours
contours_by_level = meander.spherical_contours(sample_points,
grid_value, contour_levels
)
if not circular:
contours_by_level = meander.spherical_contours(sample_points,
grid_value, contour_levels
)
if circular:
sigma50 = np.deg2rad(circular_err50)
sigma90 = np.deg2rad(circular_err90)
Theta50, Phi50 = self.circular_contour(minRA, minDec, sigma50, nside)
Theta90, Phi90 = self.circular_contour(minRA, minDec, sigma90, nside)
contour50 = np.dstack((Theta50,Phi50))
contour90 = np.dstack((Theta90,Phi90))
contours_by_level = [contour50, contour90]

# Check for RA values that are out of bounds
for level in contours_by_level:
for contour in level:
Expand Down Expand Up @@ -1128,31 +1168,6 @@ def bounding_box(ra, dec, theta, phi):
# Plot the original online reconstruction location
if np.sum(np.isnan([extra_ra, extra_dec, extra_radius])) == 0:

def circular_contour(ra, dec, sigma, nside):
"""For plotting circular contours on skymaps ra, dec, sigma all
expected in radians."""
dec = np.pi/2. - dec
sigma = np.rad2deg(sigma)
delta, step, bins = 0, 0, 0
delta= sigma/180.0*np.pi
step = 1./np.sin(delta)/10.
bins = int(360./step)
Theta = np.zeros(bins+1, dtype=np.double)
Phi = np.zeros(bins+1, dtype=np.double)
# define the contour
for j in range(0,bins) :
phi = j*step/180.*np.pi
vx = np.cos(phi)*np.sin(ra)*np.sin(delta) + np.cos(ra)*(np.cos(delta)*np.sin(dec) + np.cos(dec)*np.sin(delta)*np.sin(phi))
vy = np.cos(delta)*np.sin(dec)*np.sin(ra) + np.sin(delta)*(-np.cos(ra)*np.cos(phi) + np.cos(dec)*np.sin(ra)*np.sin(phi))
vz = np.cos(dec)*np.cos(delta) - np.sin(dec)*np.sin(delta)*np.sin(phi)
idx = healpy.vec2pix(nside, vx, vy, vz)
DEC, RA = healpy.pix2ang(nside, idx)
Theta[j] = DEC
Phi[j] = RA
Theta[bins] = Theta[0]
Phi[bins] = Phi[0]
return Theta, Phi

# dist = angular_distance(minRA, minDec, extra_ra * np.pi/180., extra_dec * np.pi/180.)
# print("Millipede best fit is", dist /(np.pi * extra_radius/(1.177 * 180.)), "sigma from reported best fit")

Expand All @@ -1167,7 +1182,7 @@ def circular_contour(ra, dec, sigma, nside):
lonlat=True, c='m', marker='x', s=20, label=r'Reported online (50%, 90%)')
for cont_lev, cont_scale, cont_col, cont_sty in zip(['50', '90.'],
[1., 2.1459/1.177], ['m', 'm'], ['-', '--']):
spline_contour = circular_contour(extra_ra_rad, extra_dec_rad,
spline_contour = self.circular_contour(extra_ra_rad, extra_dec_rad,
extra_radius_rad*cont_scale, healpy.get_nside(equatorial_map))
spline_lon = spline_contour[1]
spline_lat = np.pi/2. - spline_contour[0]
Expand Down