friedrich results


In [1]:
%matplotlib inline
# Import dev version of friedrich:
import sys
sys.path.insert(0, '../')

import numpy as np
import matplotlib.pyplot as plt
from friedrich.analysis import Transit, Spot, Measurement, MCMCResults
from friedrich.lightcurve import hat11_params_morris_is_90
from glob import glob

archive_paths = sorted(glob('/local/tmp/friedrich/hat11_is_90/chains???.hdf5'))
#archive_paths = sorted(glob('/local/tmp/friedrich/hat11_init/chains???.hdf5'))
print('load results')
transits = []
all_times = []
for archive_path in archive_paths:
    m = MCMCResults(archive_path, hat11_params_morris_is_90())
    all_times.extend(m.lc.times.jd)

#     # Convert samples into spot measurements
#     results = np.percentile(m.chains, [15.87, 50, 84.13], axis=0)

#     spots = []
#     for spot in np.split(results[:, 1:].T, (m.chains.shape[1]-1)/3):
#         ampltiude, t0, sigma = map(lambda x: Measurement(*(x[1], 
#                                                            x[2]-x[1], 
#                                                            x[1]-x[0])), 
#                                    spot)
#         spots.append(Spot(ampltiude, t0, sigma)) 
    spots = m.get_spots()
    transits.append(Transit(spots))


load results

In [2]:
from friedrich.orientation import times_to_occulted_lat_lon
from friedrich.lightcurve import hat11_params_morris_is_90
from astroML.plotting import plot_tissot_ellipse

transit_params = hat11_params_morris_is_90()
projection = 'Hammer'

# Plot the built-in projections
fig = plt.figure(figsize=(14, 14))
ax = plt.subplot(211, projection=projection.lower())#, axisbg='black')
ax2 = plt.subplot(212)#, axisbg='black')

def custom_grid(ax, color='gray'):
    # plot latitude/longitude grid
    ax.xaxis.set_major_locator(plt.FixedLocator(np.pi / 3
                                                * np.linspace(-2, 2, 5)))
    ax.xaxis.set_minor_locator(plt.FixedLocator(np.pi / 6
                                                * np.linspace(-5, 5, 11)))
    ax.yaxis.set_major_locator(plt.FixedLocator(np.pi / 6
                                                * np.linspace(-2, 2, 5)))
    ax.yaxis.set_minor_locator(plt.FixedLocator(np.pi / 12
                                                * np.linspace(-5, 5, 11)))

    ax.grid(True, which='minor', color=color, ls=':')
    
    if color != 'gray':
        for l in ax.get_xticklabels():
            l.set_color(color)

custom_grid(ax)

# all_spot_times = np.array([spot.t0.value for spot in transit.spots 
#                            for transit in transits])
all_spot_times = np.array([spot.t0.value for transit in transits
                           for spot in transit.spots])
def tcolorscale(t):
    color = (t - all_spot_times.min())/(all_spot_times.max() - all_spot_times.min())
    return color

def sigma_prior(sigma):
    # Should less than 20 min, greater than 1
    if sigma*24*60 > 15 or sigma*24*60 < 2: 
        return 1e4
    else:
        return 1

radius = 1.0*np.tan(transit_params.rp)  # from s=r*theta

cmap = plt.cm.viridis
for transit in transits:
    for spot in transit.spots: 
        latitude, longitude = times_to_occulted_lat_lon(np.array([spot.t0.value]), 
                                                        transit_params)
        alpha = spot.amplitude.value*500/sigma_prior(spot.sigma.value)
        #alpha = 0.5/sigma_prior(spot.sigma.value)
        p = plot_tissot_ellipse(longitude, latitude, radius, ax=ax, linewidth=0,
                            alpha = alpha if alpha < 1 else 1,
                            color=cmap(tcolorscale(spot.t0.value)))

from matplotlib.ticker import FuncFormatter
from astropy.time import Time
       
def plot_color_gradients(fig, ax):
    gradient = np.linspace(0, 1, 256)
    gradient = np.vstack(10*[gradient])

    ax.imshow(gradient, cmap=plt.get_cmap('viridis'), aspect=1.0) 
    ax.set_yticks([])
    nticks = 6
    datespace = np.linspace(all_spot_times.min(), all_spot_times.max(), nticks)
    axspace = np.linspace(0, 256, nticks)
    xtickdates = [t.date() for t in Time(datespace, format='jd').datetime]
    ax.set_xticks(axspace)
    ax.set_xticklabels(xtickdates)

plot_color_gradients(fig, ax2)
fig.subplots_adjust(hspace=-0.55)



In [3]:
all_lats = []
all_lons = []
all_amps = []
all_spot_times = []
all_BICs = []
for transit in transits:
    for spot in transit.spots: 
        latitude, longitude = times_to_occulted_lat_lon(np.array([spot.t0.value]), 
                                                        transit_params)
        all_lats.append(latitude)
        all_lons.append(longitude)
        all_amps.append(spot.amplitude.value)
        all_spot_times.append(spot.t0.value)
        all_BICs.append(spot.delta_BIC)
all_lats = np.array(all_lats)
all_lons = np.array(all_lons)
all_amps = np.array(all_amps)
all_spot_times = np.array(all_spot_times)
all_BICs = np.array(all_BICs)

In [4]:
strong_lats = all_lats[all_BICs > 10]
strong_lats_times = all_spot_times[all_BICs > 10]
fig, ax = plt.subplots(1, 2, figsize=(14, 5))
first_half_strong_lats = strong_lats[:int(0.5*len(strong_lats))]
second_half_strong_lats = strong_lats[-len(first_half_strong_lats):]

nbins = 30
ax[0].hist(np.degrees(first_half_strong_lats), nbins, histtype='stepfilled',
           facecolor='b', alpha=0.4, label='2009-2010')
ax[0].hist(np.degrees(second_half_strong_lats), nbins, histtype='stepfilled', 
           facecolor='g', alpha=0.4, label='2011-2013')

def cumdist(Z):
    N = len(Z)
    return np.sort(Z.ravel()), np.arange(N)/N

ax[1].plot(*cumdist(np.degrees(first_half_strong_lats)), label='2009-2010')
ax[1].plot(*cumdist(np.degrees(second_half_strong_lats)), label='2011-2013')

from scipy.stats import ks_2samp
ks = ks_2samp(first_half_strong_lats.ravel(), second_half_strong_lats.ravel())

ax[0].legend(loc='upper left')
ax[0].set(xlabel='Latitude', ylabel='Frequency')
ax[1].legend(loc='upper left')
ax[1].set(xlabel='Latitude', ylabel='Cumulative sum', 
          title="K-S $p={0:.2f}$".format(ks.pvalue))
plt.show()



In [5]:
import seaborn as sns
#sns.set(style="dark")

fig, ax = plt.subplots()
ax.grid(color='gray')
ax.hist(np.degrees(strong_lats), 50, histtype='stepfilled', 
        zorder=100, color='#4d79ff', edgecolor='none')
ax.set_xlabel('Latitude [degrees]')

ax.spines['right'].set_color('none')
ax.yaxis.set_ticks_position('left')

ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')

ax.set_ylabel('Frequency')
ax.set_axis_bgcolor('#e6ecff')
ax.set_title('HAT-P-11 Spot Distribution')
plt.savefig('plots/latitudes.pdf', bbox_inches='tight')
plt.show()


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-5-704ec96f3dfc> in <module>()
----> 1 import seaborn as sns
      2 #sns.set(style="dark")
      3 
      4 fig, ax = plt.subplots()
      5 ax.grid(color='gray')

/astro/users/bmmorris/.local/lib/python3.5/site-packages/seaborn/__init__.py in <module>()
      2 from .utils import *
      3 from .palettes import *
----> 4 from .linearmodels import *
      5 from .categorical import *
      6 from .distributions import *

/astro/users/bmmorris/.local/lib/python3.5/site-packages/seaborn/linearmodels.py in <module>()
     26 from .palettes import color_palette
     27 from .axisgrid import FacetGrid, PairGrid, _facet_docs
---> 28 from .distributions import kdeplot
     29 
     30 

/astro/users/bmmorris/.local/lib/python3.5/site-packages/seaborn/distributions.py in <module>()
     11 
     12 try:
---> 13     import statsmodels.nonparametric.api as smnp
     14     _has_statsmodels = True
     15 except ImportError:

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/site-packages/statsmodels/nonparametric/api.py in <module>()
      3 from . import bandwidths
      4 
----> 5 from .kernel_density import \
      6     KDEMultivariate, KDEMultivariateConditional, EstimatorSettings
      7 from .kernel_regression import KernelReg, KernelCensoredReg

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/site-packages/statsmodels/nonparametric/kernel_density.py in <module>()
     35 
     36 from . import kernels
---> 37 from ._kernel_base import GenericKDE, EstimatorSettings, gpke, \
     38     LeaveOneOut, _adjust_shape
     39 

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/importlib/_bootstrap.py in _find_and_load(name, import_)

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/importlib/_bootstrap.py in _load_unlocked(spec)

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/importlib/_bootstrap_external.py in exec_module(self, module)

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/importlib/_bootstrap_external.py in get_code(self, fullname)

/astro/apps6/anaconda2.0/envs/py3/lib/python3.5/importlib/_bootstrap_external.py in get_data(self, path)

KeyboardInterrupt: 

In [ ]:
strong_lons = all_lons[all_BICs > 10]
fig, ax = plt.subplots(1, 2, figsize=(14, 5))
first_half_strong_lons = strong_lons[:int(0.5*len(strong_lons))]
second_half_strong_lons = strong_lons[-len(first_half_strong_lons):]

nbins = 30
ax[0].hist(np.degrees(first_half_strong_lons), nbins, histtype='stepfilled',
           facecolor='b', alpha=0.4, label='2009-2010')
ax[0].hist(np.degrees(second_half_strong_lons), nbins, histtype='stepfilled', 
           facecolor='g', alpha=0.4, label='2011-2013')

def cumdist(Z):
    N = len(Z)
    return np.sort(Z.ravel()), np.arange(N)/N

ax[1].plot(*cumdist(np.degrees(first_half_strong_lons)), label='2009-2010')
ax[1].plot(*cumdist(np.degrees(second_half_strong_lons)), label='2011-2013')

from scipy.stats import ks_2samp
ks = ks_2samp(first_half_strong_lons.ravel(), second_half_strong_lons.ravel())

ax[0].legend(loc='upper left')
ax[0].set(xlabel='Longitude', ylabel='Frequency')
ax[1].legend(loc='upper left')
ax[1].set(xlabel='Longitude', ylabel='Cumulative sum', 
          title="K-S $p={0:.2f}$".format(ks.pvalue))
plt.show()

In [ ]:
import friedrich
import imp
imp.reload(friedrich)
import friedrich

from friedrich.orientation import times_to_occulted_lat_lon

lats = np.zeros(len(all_times))#[]
lons = np.zeros(len(all_times))#[]
for i, t in enumerate(all_times):
    lat, lon = times_to_occulted_lat_lon(np.array([t]), hat11_params_morris_is_90())
    lats[i] = lat
    lons[i] = lon

In [ ]:
projection = 'Hammer'

# Plot the built-in projections
fig = plt.figure(figsize=(14, 14))
ax = plt.subplot(111, projection=projection.lower())
ax.plot(lons, lats, ',')
ax.grid()

In [ ]:
n_bins = 100
lon_grid = np.linspace(-np.pi, np.pi, n_bins)
lat_grid = np.linspace(-np.pi/2, np.pi/2, n_bins)

bins = np.zeros((n_bins, n_bins))
spots_in_visit_bin = np.zeros((n_bins, n_bins))
for i in range(n_bins-1):
    
    lon_bin_lower = lon_grid[i]
    lon_bin_upper = lon_grid[i+1]

    visits_in_lon_bin = ((lons < lon_bin_upper) & 
                         (lons > lon_bin_lower))
    spots_in_lon_bin = ((strong_lons < lon_bin_upper) & 
                        (strong_lons > lon_bin_lower))
    
    for j in range(n_bins-1):
        
        lat_bin_lower = lat_grid[j]
        lat_bin_upper = lat_grid[j+1]

        visits_in_lat_bin = ((lats < lat_bin_upper) & 
                      (lats > lat_bin_lower))
        
        bins[j, i] = np.count_nonzero(visits_in_lat_bin & 
                                      visits_in_lon_bin)

        spots_in_lat_bin = ((strong_lats < lat_bin_upper) & 
                            (strong_lats > lat_bin_lower))
        
        spots_in_visit_bin[j, i] = np.count_nonzero(spots_in_lon_bin &
                                              spots_in_lat_bin)
        
# plt.imshow(bins, interpolation='nearest', origin='lower')
# fig = plt.figure(figsize=(14, 14))
# ax = plt.subplot(111, projection=projection.lower())
# ax.plot(lon_grid, lat_grid, ',')
# ax.grid()

In [ ]:
projection = 'Hammer'

cmap = plt.cm.viridis
def color_scale(x):
    return (x - bins.min()) / bins.max()

# Plot the built-in projections
fig = plt.figure(figsize=(14, 14))
ax = plt.subplot(211, projection=projection.lower())

for i in range(n_bins-1):
    lon_bin_lower = lon_grid[i]
    lon_bin_upper = lon_grid[i+1]
    for j in range(n_bins-1):
        lat_bin_lower = lat_grid[j]
        lat_bin_upper = lat_grid[j+1]
        
        # [lon min, lon max], [lat min, lat min], [lat max]
        ax.fill_between([lon_bin_lower, lon_bin_upper], 
                        [lat_bin_lower, lat_bin_lower], 
                        lat_bin_upper, 
                        color=cmap(color_scale(bins[j, i])))
        
def plot_colorbar(fig, ax):
    gradient = np.linspace(0, 1, 256)
    gradient = np.vstack(10*[gradient])

    ax.imshow(gradient, cmap=plt.get_cmap('viridis'), aspect=1.0) 
    ax.set_yticks([])
    nticks = 6
    axspace = np.linspace(0, 256, nticks)
    xticks = np.linspace(bins.min(), bins.max(), nticks).astype(int)
    ax.set_xticks(axspace)
    ax.set_xticklabels(xticks)

custom_grid(ax, color='w')
ax2 = plt.subplot(212)
plot_colorbar(fig, ax2)
fig.subplots_adjust(hspace=-0.55)

In [ ]:
projection = 'Hammer'

cmap = plt.cm.copper #plt.cm.viridis
def color_scale(x):
    return (x - bins.min()) / 2 / bins.max()

# Plot the built-in projections
fig = plt.figure(figsize=(14, 14))
ax = plt.subplot(211, projection=projection.lower())

for i in range(n_bins-1):
    lon_bin_lower = lon_grid[i]
    lon_bin_upper = lon_grid[i+1]
    for j in range(n_bins-1):
        lat_bin_lower = lat_grid[j]
        lat_bin_upper = lat_grid[j+1]
        
        # [lon min, lon max], [lat min, lat min], [lat max]
        ax.fill_between([lon_bin_lower, lon_bin_upper], 
                        [lat_bin_lower, lat_bin_lower], 
                        lat_bin_upper, 
                        color=cmap(color_scale(bins[j, i])))
        
def plot_colorbar(fig, ax):
    gradient = np.linspace(0, 1/2, 256)
    gradient = np.vstack(10*[gradient])

    ax.imshow(gradient, cmap=cmap, aspect=1.0) 
    ax.set_yticks([])
    nticks = 6
    axspace = np.linspace(0, 256, nticks)
    xticks = np.linspace(bins.min(), bins.max(), nticks).astype(int)
    ax.set_xticks(axspace)
    ax.set_xticklabels(xticks)

ax2 = plt.subplot(212)
plot_colorbar(fig, ax2)
fig.subplots_adjust(hspace=-0.55)

# plot spots
for transit in transits:
    for spot in transit.spots: 
        latitude, longitude = times_to_occulted_lat_lon(np.array([spot.t0.value]), 
                                                        transit_params)
        #alpha = spot.amplitude.value*500/sigma_prior(spot.sigma.value)
        alpha = 0.4/sigma_prior(spot.sigma.value)
        p = plot_tissot_ellipse(longitude, latitude, radius, ax=ax, linewidth=0,
                                alpha = alpha if alpha < 1 else 1,
                                color='w')
        
custom_grid(ax, color='w')
ax2.set_xlabel('Number of visits')

In [ ]:
projection = 'Hammer'

cmap = plt.cm.viridis # plt.cm.copper
fraction_of_colorbar = 0.7
circle_color = plt.cm.viridis(1.0)

def color_scale(x):
    return fraction_of_colorbar*(x - bins.min()) / bins.max()
    #return (x - bins.min()) / 2 / bins.max()

# Plot the built-in projections
fig = plt.figure(figsize=(14, 14))
ax = plt.subplot(211, projection=projection.lower())

for i in range(n_bins-1):
    lon_bin_lower = lon_grid[i]
    lon_bin_upper = lon_grid[i+1]
    for j in range(n_bins-1):
        lat_bin_lower = lat_grid[j]
        lat_bin_upper = lat_grid[j+1]
        
        # [lon min, lon max], [lat min, lat min], [lat max]
        ax.fill_between([lon_bin_lower, lon_bin_upper], 
                        [lat_bin_lower, lat_bin_lower], 
                        lat_bin_upper, 
                        color=cmap(color_scale(bins[j, i])))
        
def plot_colorbar(fig, ax):
    gradient = np.linspace(0, fraction_of_colorbar, 256)
    gradient = np.vstack(10*[gradient])

    ax.imshow(gradient, cmap=cmap, aspect=1.0, vmin=0, vmax=1) 
    ax.set_yticks([])
    nticks = 6
    axspace = np.linspace(0, 256, nticks)
    xticks = np.linspace(bins.min(), bins.max(), nticks).astype(int)
    ax.set_xticks(axspace)
    ax.set_xticklabels(xticks)

ax2 = plt.subplot(212)
plot_colorbar(fig, ax2)
fig.subplots_adjust(hspace=-0.55)

# plot spots
for transit in transits:
    for spot in transit.spots: 
        latitude, longitude = times_to_occulted_lat_lon(np.array([spot.t0.value]), 
                                                        transit_params)

        p = plot_tissot_ellipse(longitude, latitude, radius, ax=ax, facecolor='none', 
                                edgecolor=circle_color, lw=3, alpha=0.6)
        
        p = plot_tissot_ellipse(longitude, latitude, radius, ax=ax, linewidth=0,
                                alpha=0.3, facecolor=circle_color)
        
custom_grid(ax, color='w')
ax2.set_xlabel('Number of occultations by the planet center')

In [ ]:
fig.savefig('plots/map.pdf', bbox_inches='tight')

In [ ]:
fig, ax = plt.subplots(1, 2, figsize=(14, 6))

ax[0].plot(lat_grid, np.sum(bins, axis=1))
ax[0].set(xlabel='Latitude')
ax[1].plot(lon_grid, np.sum(bins, axis=0))
ax[1].set(xlabel='Longitude')

In [ ]:
fig, ax = plt.subplots(1, 2, figsize=(14, 5))
first_half_strong_lats = strong_lats[:int(0.5*len(strong_lats))]
second_half_strong_lats = strong_lats[-len(first_half_strong_lats):]

nbins = 30
ax[0].hist(np.degrees(strong_lats), nbins, histtype='stepfilled',
           facecolor='b', alpha=0.4)

def cumdist(Z):
    N = len(Z)
    return np.sort(Z.ravel()), np.arange(N)/N

ax[1].plot(*cumdist(np.degrees(strong_lats)))

sum_lats = np.sum(bins, axis=1)
ax[0].plot(np.degrees(lat_grid), sum_lats*30/sum_lats.max())
ax[0].legend(loc='upper left')
ax[0].set(xlabel='Latitude', ylabel='Frequency')
ax[1].legend(loc='upper left')
ax[1].set(xlabel='Latitude', ylabel='Cumulative sum'), 
         #title="K-S $p={0:.2f}$".format(ks.pvalue))
plt.show()

In [ ]:
begin_kepler = Time('2009-05-06')
end_kepler = Time('2013-04-17')

n_time_bins = 10 # 
n_lat_bins = 30

time_bin_bounds = np.linspace(begin_kepler.jd, end_kepler.jd, n_time_bins+1)
lat_bin_bounds = np.linspace(-np.pi/2, np.pi/2, n_lat_bins+1)

lat_time_bins = np.zeros((n_lat_bins, n_time_bins))
for i in range(n_time_bins):
    min_time = time_bin_bounds[i]
    max_time = time_bin_bounds[i+1]

    lat_bins = np.zeros(n_lat_bins)
    for j in range(n_lat_bins):
        min_lat = lat_bin_bounds[j]
        max_lat = lat_bin_bounds[j+1]
        spots_in_bin = ((strong_lats_times > min_time) & (strong_lats_times < max_time) &
                        (strong_lats.ravel() < max_lat) & (strong_lats.ravel() > min_lat))
        lat_time_bins[j, i] = np.count_nonzero(spots_in_bin)

In [ ]:
scaled_lat_time_bins = np.copy(lat_time_bins)

for i in range(scaled_lat_time_bins.shape[1]):
    scaled_lat_time_bins[:, i] = scaled_lat_time_bins[:, i]/np.max(scaled_lat_time_bins[:, i])

    
    
fig, ax = plt.subplots(1, 2, figsize=(14, 8))
ax[0].imshow(scaled_lat_time_bins, cmap=plt.cm.viridis, 
          origin='lower', interpolation='nearest')
ax[0].set_ylabel('Latitude')
ax[0].set_aspect(0.5)
skip = 3
lat_labels = np.degrees(0.5*(lat_bin_bounds[1:]+lat_bin_bounds[:-1])).astype(int)[::skip]

ax[0].set_yticks(range(len(lat_bin_bounds-1))[::skip])
ax[0].set_yticklabels(lat_labels)
ax[0].set_xlabel('Time bin')
ax[0].set_aspect(0.5)
ax[0].set_title('Spot Distribution')

skip = 10
ax[1].imshow(np.atleast_2d(sum_lats*30/sum_lats.max()).T, cmap=plt.cm.viridis, 
             origin='lower', interpolation='nearest')
ax[1].set_aspect(0.05)
lat_labels2 = np.degrees(0.5*(lat_grid[1:]+lat_grid[:-1])).astype(int)[::skip]
ax[1].set_yticks(range(len(lat_grid))[::skip])
ax[1].set_yticklabels(lat_labels2)
ax[1].set_title('Relative Completeness')

fig.subplots_adjust(wspace=-0.3)
plt.show()

In [ ]:
# plt.plot(spots_in_visit_bin.ravel(), bins.ravel(), '.')
# x = np.arange(spots_in_visit_bin.max())
# p = np.polyfit(spots_in_visit_bin.ravel(), bins.ravel(), 1)
# plt.plot(x, np.polyval(p, x))
# plt.show()

nbins = 6
visits_and_spots = np.zeros((nbins, spots_in_visit_bin.max()+1))
for i, n_spots_in_bin in enumerate(set(spots_in_visit_bin.ravel())):
    freq, edges = np.histogram(bins[spots_in_visit_bin == 
                                    n_spots_in_bin].ravel(),
                               nbins, range=(0, bins.max()))
    visits_and_spots[:, i] = freq
    plt.hist(bins[spots_in_visit_bin == n_spots_in_bin].ravel(),
             nbins, range=(0, bins.max()), log=True, 
             label="{0:d} spots".format(int(n_spots_in_bin)),
             histtype='stepfilled')
plt.xlabel('Number of visits')
plt.ylabel('Frequency')
plt.ylim([1e-1, 1e4])
plt.legend()

# plt.figure()
# plt.imshow(np.log(visits_and_spots), 
#            cmap=plt.cm.viridis,
#            interpolation='nearest',
#            origin='lower')
# plt.xlabel('Spots in spatial bin')
# plt.ylabel('Visits in spatial bin')

In [ ]:
plt.hist(bins.ravel(), bins=10);

In [ ]:
# Try interpolating over spatial completeness bins, then test correlation
# between visit density at the places where spots were detected

from scipy.interpolate import interp2d

interp = interp2d(lon_grid, lat_grid, bins)

# plt.imshow(interp(lon_grid, lat_grid), origin='lower')

spot_interps = [interp(lo, la)[0] for lo, la in zip(strong_lons.ravel(), strong_lats.ravel())]
plt.hist(spot_interps, bins=30)
plt.xlabel('Number of visits at position of recovered spots')
plt.ylabel('Frequency')
plt.title('What is the relative completeness\nwhere spots were recovered?');

Latitude distribution with time:


In [ ]:
#all_amps
# plt.plot_date(Time(all_spot_times[all_BICs > 10], format='jd').plot_date, 
#               np.degrees(all_lats[all_BICs > 10]), '.')


n_panels = 4
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(14, 8))
gs = gridspec.GridSpec(2, 4)
ax0 = plt.subplot(gs[0, :])
ax1 = [plt.subplot(gs[1, i]) for i in range(n_panels)]

#fig, ax = plt.subplots(1, n_panels, figsize=(14, 3))
first_spot = all_spot_times[all_BICs > 10].min()
last_spot = all_spot_times[all_BICs > 10].max()
first_to_last = last_spot - first_spot
fraction_gt_median = np.zeros(n_panels)

ax0.plot_date(Time(all_spot_times[all_BICs > 10], format='jd').plot_date, 
              np.degrees(all_lats[all_BICs > 10]), '.')

for i in range(n_panels):
    extent = [-60, 80]
    within_time_bin = ((all_spot_times[all_BICs > 10] - first_spot > 
                        i/n_panels*first_to_last) & 
                       (all_spot_times[all_BICs > 10] - first_spot < 
                        (i+1)/n_panels*first_to_last))
    lats_in_time_bin = np.degrees(all_lats[all_BICs > 10][within_time_bin])
    ax1[i].hist(lats_in_time_bin, 30, range=extent)

    ax1[i].hist(np.degrees(all_lats[all_BICs > 10]), 30,
                range=extent, alpha=0.2, color='k', zorder=10)

    ax1[i].set_xlim(extent)
    
    ax1[i].set(title='Segment {0}'.format(i))
    
    if i == 0:
        segment_zero_mean = np.median(lats_in_time_bin)
    fraction_gt_median[i] = np.count_nonzero(lats_in_time_bin > segment_zero_mean)/len(lats_in_time_bin)

ax1[0].set_ylabel('Frequency')
ax0.set_ylabel('Latitude [deg]')

fig.text(0.5, 0.05, 'Latitude [deg]', ha='center', fontsize=14)

#fig.subplots_adjust()

In [ ]:
plt.figure()
plt.bar(range(n_panels), fraction_gt_median)
plt.xlabel('Segment')
plt.ylabel('Fraction of spots with latitudes > median latitude in Segment 0')
plt.axhline(0.5, ls='--')
plt.ylim([0, 1])

In [ ]:


In [ ]: