def plot_sn_discovery_map(log,
                          snSurveyDiscoveryTimes,
                          peakAppMagList,
                          snCampaignLengthList,
                          redshifts,
                          extraSurveyConstraints,
                          pathToOutputPlotFolder):
    """
    *Plot the SN discoveries in a polar plot as function of redshift & time*

    **Key Arguments:**
        - ``log`` -- logger
        - ``snSurveyDiscoveryTimes`` --
        - ``peakAppMagList`` --
        - ``snCampaignLengthList`` -- a list of campaign lengths in each filter
        - ``redshifts`` --
        - ``extraSurveyConstraints`` --
        - ``pathToOutputPlotDirectory`` -- path to add plots to

    **Return:**
        - None
    """
    ################ > IMPORTS ################
    ## STANDARD LIB ##
    import sys
    ## THIRD PARTY ##
    import matplotlib.pyplot as plt
    import numpy as np
    ## LOCAL APPLICATION ##
    filters = ['g', 'r', 'i', 'z']
    lunarMonth = 29.3
    surveyYear = 12. * lunarMonth

    faintMagLimit = extraSurveyConstraints['Faint-Limit of Peak Magnitude']

    ################ >ACTION(S) ################
    discovered = []
    tooFaint = []
    shortCampaign = []
    discoveredRedshift = []
    tooFaintRedshift = []
    notDiscoveredRedshift = []
    shortCampaignRedshift = []
    #log.info('len(redshifts) %s' % (len(redshifts),))
    for item in range(len(redshifts)):
        if snSurveyDiscoveryTimes[item]['any'] is True:
            discoveryDayList = []
            faintDayList = []
            shortCampaignDayList = []
            for ffilter in filters:
                if snSurveyDiscoveryTimes[item][ffilter]:
                    if peakAppMagList[item][ffilter] < faintMagLimit:
                        if snCampaignLengthList[item]['max'] < extraSurveyConstraints['Observable for at least ? number of days']:
                            shortCampaignDayList.append(
                                snSurveyDiscoveryTimes[item][ffilter])
                        else:
                            discoveryDayList.append(
                                snSurveyDiscoveryTimes[item][ffilter])
                    else:
                        faintDayList.append(
                            snSurveyDiscoveryTimes[item][ffilter])

            if len(discoveryDayList) > 0:
                discovered.append(min(discoveryDayList))
                discoveredRedshift.append(redshifts[item])
            elif len(shortCampaignDayList) > 0:
                shortCampaign.append(min(shortCampaignDayList))
                shortCampaignRedshift.append(redshifts[item])
            else:
                tooFaint.append(min(faintDayList))
                tooFaintRedshift.append(redshifts[item])
        else:
            notDiscoveredRedshift.append(redshifts[item])

    ################ >ACTION(S) ################
    colors = [
        {'red': '#dc322f'},
        {'blue': '#268bd2'},
        {'green': '#859900'},
        {'orange': '#cb4b16'},
        {'gray': '#93a1a1'},
        {'violet': '#6c71c4'},
        {'cyan': '#2aa198'},
        {'magenta': '#d33682'},
        {'yellow': '#b58900'}
    ]

    # FORCE SQUARE FIGURE AND SQUARE AXES LOOKS BETTER FOR POLAR
    fig = plt.figure(
        num=None,
        figsize=(8, 8),
        dpi=None,
        facecolor=None,
        edgecolor=None,
        frameon=True)

    ax = fig.add_axes(
        [0.1, 0.1, 0.8, 0.8],
        polar=True,
        frameon=False)

    maxInList = max(redshifts) * 1.1
    ax.set_ylim(0, maxInList)
    # ax.get_xaxis().set_visible(False)

    circleTicks = np.arange(0, 350, 30)
    tickLabels = []
    for tick in circleTicks:
        tickLabels.append("%s days" % (tick,))

    plt.xticks(2 * np.pi * circleTicks / 360., tickLabels)

    discovered = 2 * np.pi * np.array(discovered) / surveyYear
    discoveredRedshift = np.array(discoveredRedshift)

    tooFaint = 2 * np.pi * np.array(tooFaint) / surveyYear
    tooFaintRedshift = np.array(tooFaintRedshift)

    shortCampaign = 2 * np.pi * np.array(shortCampaign) / surveyYear
    shortCampaignRedshift = np.array(shortCampaignRedshift)

    plt.scatter(
        tooFaint,
        tooFaintRedshift,
        label="""Detected - too faint to constrain as transient""",
        s=50,
        c='#dc322f',
        marker='o',
        cmap=None,
        norm=None,
        vmin=None,
        vmax=None,
        alpha=0.2,
        linewidths=None,
        edgecolor='#657b83',
        verts=None,
        hold=True)

    plt.scatter(
        discovered,
        discoveredRedshift,
        label='Discovered transient',
        s=50,
        c='#859900',
        marker='o',
        cmap=None,
        norm=None,
        vmin=None,
        vmax=None,
        alpha=0.2,
        linewidths=None,
        edgecolor='#657b83',
        verts=None,
        hold=True)

    plt.scatter(
        shortCampaign,
        shortCampaignRedshift,
        label="""Detected - campaign to short to constrain as transient""",
        s=50,
        c='#268bd2',
        marker='o',
        cmap=None,
        norm=None,
        vmin=None,
        vmax=None,
        alpha=0.2,
        linewidths=None,
        edgecolor='#657b83',
        verts=None,
        hold=True)

    title = "transients Detected Within the Suvrey Year"
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    # Put a legend to the right of the current axis
    ax.legend(loc='center left', bbox_to_anchor=(0.7, -0.1), prop={'size': 8})
    plt.grid(True)
    plt.title(title, fontsize='small',
              verticalalignment='bottom', linespacing=0.2)
    fileName = pathToOutputPlotFolder + title.replace(" ", "_") + ".png"
    imageLink = """
![%s_plot](%s)

""" % (title.replace(" ", "_"), fileName)
    plt.savefig(fileName)
    plt.clf()  # clear figure

    return imageLink
def plot_sn_discovery_map ( log , snSurveyDiscoveryTimes , peakAppMagList , snCampaignLengthList , redshifts , extraSurveyConstraints , pathToOutputPlotFolder ) : import sys import matplotlib . pyplot as plt import numpy as np filters = [ 'g' , 'r' , 'i' , 'z' ] lunarMonth = 29.3 surveyYear = 12. * lunarMonth faintMagLimit = extraSurveyConstraints [ 'Faint-Limit of Peak Magnitude' ] discovered = [ ] tooFaint = [ ] shortCampaign = [ ] discoveredRedshift = [ ] tooFaintRedshift = [ ] notDiscoveredRedshift = [ ] shortCampaignRedshift = [ ] for item in range ( len ( redshifts ) ) : if snSurveyDiscoveryTimes [ item ] [ 'any' ] is True : discoveryDayList = [ ] faintDayList = [ ] shortCampaignDayList = [ ] for ffilter in filters : if snSurveyDiscoveryTimes [ item ] [ ffilter ] : if peakAppMagList [ item ] [ ffilter ] < faintMagLimit : if snCampaignLengthList [ item ] [ 'max' ] < extraSurveyConstraints [ 'Observable for at least ? number of days' ] : shortCampaignDayList . append ( snSurveyDiscoveryTimes [ item ] [ ffilter ] ) else : discoveryDayList . append ( snSurveyDiscoveryTimes [ item ] [ ffilter ] ) else : faintDayList . append ( snSurveyDiscoveryTimes [ item ] [ ffilter ] ) if len ( discoveryDayList ) > 0 : discovered . append ( min ( discoveryDayList ) ) discoveredRedshift . append ( redshifts [ item ] ) elif len ( shortCampaignDayList ) > 0 : shortCampaign . append ( min ( shortCampaignDayList ) ) shortCampaignRedshift . append ( redshifts [ item ] ) else : tooFaint . append ( min ( faintDayList ) ) tooFaintRedshift . append ( redshifts [ item ] ) else : notDiscoveredRedshift . append ( redshifts [ item ] ) colors = [ { 'red' : '#dc322f' } , { 'blue' : '#268bd2' } , { 'green' : '#859900' } , { 'orange' : '#cb4b16' } , { 'gray' : '#93a1a1' } , { 'violet' : '#6c71c4' } , { 'cyan' : '#2aa198' } , { 'magenta' : '#d33682' } , { 'yellow' : '#b58900' } ] fig = plt . figure ( num = None , figsize = ( 8 , 8 ) , dpi = None , facecolor = None , edgecolor = None , frameon = True ) ax = fig . add_axes ( [ 0.1 , 0.1 , 0.8 , 0.8 ] , polar = True , frameon = False ) maxInList = max ( redshifts ) * 1.1 ax . set_ylim ( 0 , maxInList ) circleTicks = np . arange ( 0 , 350 , 30 ) tickLabels = [ ] for tick in circleTicks : tickLabels . append ( "%s days" % ( tick , ) ) plt . xticks ( 2 * np . pi * circleTicks / 360. , tickLabels ) discovered = 2 * np . pi * np . array ( discovered ) / surveyYear discoveredRedshift = np . array ( discoveredRedshift ) tooFaint = 2 * np . pi * np . array ( tooFaint ) / surveyYear tooFaintRedshift = np . array ( tooFaintRedshift ) shortCampaign = 2 * np . pi * np . array ( shortCampaign ) / surveyYear shortCampaignRedshift = np . array ( shortCampaignRedshift ) plt . scatter ( tooFaint , tooFaintRedshift , label = """Detected - too faint to constrain as transient""" , s = 50 , c = '#dc322f' , marker = 'o' , cmap = None , norm = None , vmin = None , vmax = None , alpha = 0.2 , linewidths = None , edgecolor = '#657b83' , verts = None , hold = True ) plt . scatter ( discovered , discoveredRedshift , label = 'Discovered transient' , s = 50 , c = '#859900' , marker = 'o' , cmap = None , norm = None , vmin = None , vmax = None , alpha = 0.2 , linewidths = None , edgecolor = '#657b83' , verts = None , hold = True ) plt . scatter ( shortCampaign , shortCampaignRedshift , label = """Detected - campaign to short to constrain as transient""" , s = 50 , c = '#268bd2' , marker = 'o' , cmap = None , norm = None , vmin = None , vmax = None , alpha = 0.2 , linewidths = None , edgecolor = '#657b83' , verts = None , hold = True ) title = "transients Detected Within the Suvrey Year" box = ax . get_position ( ) ax . set_position ( [ box . x0 , box . y0 , box . width * 0.8 , box . height ] ) ax . legend ( loc = 'center left' , bbox_to_anchor = ( 0.7 , - 0.1 ) , prop = { 'size' : 8 } ) plt . grid ( True ) plt . title ( title , fontsize = 'small' , verticalalignment = 'bottom' , linespacing = 0.2 ) fileName = pathToOutputPlotFolder + title . replace ( " " , "_" ) + ".png" imageLink = """
![%s_plot](%s)
""" % ( title . replace ( " " , "_" ) , fileName ) plt . savefig ( fileName ) plt . clf ( ) return imageLink
*Plot the SN discoveries in a polar plot as function of redshift & time*

    **Key Arguments:**
        - ``log`` -- logger
        - ``snSurveyDiscoveryTimes`` --
        - ``peakAppMagList`` --
        - ``snCampaignLengthList`` -- a list of campaign lengths in each filter
        - ``redshifts`` --
        - ``extraSurveyConstraints`` --
        - ``pathToOutputPlotDirectory`` -- path to add plots to

    **Return:**
        - None