1616import matplotlib .pylab as plt
1717import matplotlib .ticker as ticker
1818import numpy as np
19- import skyproj
19+ from typing import Any
20+ try :
21+ import skyproj
22+ except ImportError :
23+ skyproj = None
2024from astropy import units as u
2125from 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