Skip to content

Commit

Permalink
Update the stylefile 馃拝 (lightkurve#1311)
Browse files Browse the repository at this point in the history
* update stylefile

* mark edge colors

* changed lightkurve plotting style

* update merge conflict [skip ci]

---------

Co-authored-by: Christina Hedges <christina.l.hedges@nasa.gov>
  • Loading branch information
danhey and christinahedges committed Nov 2, 2023
1 parent 7a7dc2a commit 3b9a0af
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2.4.1dev (unreleased)
=====================

- Updated plot style to default to higher resolution [#1311]
- Fixed download issue due to MAST API change [#1380]
- Updated interact features to work with JupyterHub (e.g. TiKE) [#1349]
- Exposed niters parameter in the PCA function of design matrix
Expand Down
1 change: 1 addition & 0 deletions src/lightkurve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

PACKAGEDIR = os.path.abspath(os.path.dirname(__file__))
MPLSTYLE = "{}/data/lightkurve.mplstyle".format(PACKAGEDIR)
MPLSTYLE_IMG = "{}/data/lightkurve-images.mplstyle".format(PACKAGEDIR)
"""Lightkurve's stylesheet for matplotlib.
It is useful for users who create their own figures and want their figures following
Expand Down
3 changes: 3 additions & 0 deletions src/lightkurve/data/lightkurve-images.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Turns on spines just for images
axes.spines.top : True
axes.spines.right : True
96 changes: 74 additions & 22 deletions src/lightkurve/data/lightkurve.mplstyle
Original file line number Diff line number Diff line change
@@ -1,50 +1,102 @@
# Matplotlib style used by lightkurve

lines.color: C0 # has no affect on plot(); see axes.prop_cycle
lines.linewidth : 0.8
lines.markersize : 1.5


figure.facecolor : white
figure.dpi : 100
figure.figsize : 8.485, 4
figure.edgecolor: white # figure edge color
figure.dpi : 150
figure.figsize : 6.4, 4.
figure.titlesize: x-large # size of the figure title (``Figure.suptitle()``)
figure.autolayout: True # When True, automatically adjust subplot
# parameters to make the plot fit the figure
# using `tight_layout`


image.cmap : viridis
image.origin: lower # {lower, upper}

text.color : 4c4c4c

scatter.marker : .
text.color : 000000

lines.linewidth : 0.5
lines.markersize : 2

axes.formatter.use_mathtext : True
axes.spines.top : True
axes.spines.right : True
scatter.marker : .

axes.spines.top : False
axes.spines.right : False
axes.titlepad : 10
axes.titlesize : 18
axes.titlesize : x-large
axes.facecolor : white
axes.edgecolor : 4c4c4c
axes.labelcolor : 4c4c4c
axes.labelsize : 15
axes.edgecolor : 000000
axes.labelcolor : 000000
axes.labelsize : large
axes.grid : False
axes.prop_cycle : cycler('color', ['333333', '0072B2', '009E73', 'D55E00', 'CC79A7', 'F0E442', '56B4E9'])
axes.linewidth : 1.25
axes.prop_cycle : cycler('color', ['000000', '0072B2', '009E73', 'D55E00', 'CC79A7', 'F0E442', '56B4E9'])
axes.titleweight: normal # font weight of title
axes.formatter.use_mathtext: True # When True, use mathtext for scientific
# notation.
axes.formatter.min_exponent: 1 # minimum exponent to format in scientific notation
axes.formatter.useoffset: True # If True, the tick label formatter
# will default to labeling ticks relative
# to an offset when the data range is
# small compared to the minimum absolute
# value of the data.
axes.formatter.offset_threshold: 4 # When useoffset is True, the offset
# will be used when it can remove
# at least this number of significant
# digits from tick labels.

axes.unicode_minus: True # use Unicode for the minus symbol rather than hyphen. See
# https://en.wikipedia.org/wiki/Plus_and_minus_signs#Character_codes
axes.xmargin: .05 # x margin. See `axes.Axes.margins`
axes.ymargin: .05 # y margin. See `axes.Axes.margins`
axes.zmargin: .05 # z margin. See `axes.Axes.margins`
axes.autolimit_mode: data # If "data", use axes.xmargin and axes.ymargin as is.
# If "round_numbers", after application of margins, axis
# limits are further expanded to the nearest "round" number.
polaraxes.grid: True # display grid on polar axes
axes3d.grid: True # display grid on 3D axes

legend.fontsize : 11
axes3d.xaxis.panecolor: (0.95, 0.95, 0.95, 0.5) # background pane on 3D axes
axes3d.yaxis.panecolor: (0.90, 0.90, 0.90, 0.5) # background pane on 3D axes
axes3d.zaxis.panecolor: (0.925, 0.925, 0.925, 0.5) # background pane on 3D axes

axes.labelpad: 7.0


errorbar.capsize: 3

legend.fontsize : medium
legend.frameon : True
legend.numpoints : 3
legend.scatterpoints : 3
legend.facecolor : white
legend.edgecolor : 4c4c4c
legend.facecolor : inherit
legend.edgecolor : 000000
legend.framealpha: 0.9
legend.handlelength: 2.5 # the length of the legend lines


savefig.dpi: 150 # figure dots per inch or 'figure'
savefig.bbox: tight # {tight, standard}

grid.linestyle: --

xtick.top : False
xtick.color : 4c4c4c
xtick.color : 666666
xtick.labelcolor : 000000
xtick.direction : in
xtick.major.size : 8
xtick.minor.size : 4
xtick.minor.visible : True
xtick.labelsize : 12
xtick.labelsize : medium

ytick.minor.visible : True
ytick.right : False
ytick.color : 4c4c4c
ytick.color : 666666
ytick.labelcolor : 000000
ytick.direction : in
ytick.major.size : 8
ytick.minor.size : 4
ytick.labelsize : 12
ytick.labelsize : medium
54 changes: 32 additions & 22 deletions src/lightkurve/targetpixelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from tqdm import tqdm
from copy import deepcopy

from . import PACKAGEDIR, MPLSTYLE
from . import PACKAGEDIR, MPLSTYLE, MPLSTYLE_IMG
from .lightcurve import LightCurve, KeplerLightCurve, TessLightCurve
from .prf import KeplerPRF
from .utils import (
Expand All @@ -43,7 +43,7 @@
validate_method,
centroid_quadratic,
_query_solar_system_objects,
finalize_notebook_url
finalize_notebook_url,
)
from .io import detect_filetype

Expand Down Expand Up @@ -568,7 +568,9 @@ def to_lightcurve(self, method="sap", corrector=None, **kwargs):
lc : LightCurve object
Object containing the resulting lightcurve.
"""
method = validate_method(method, supported_methods=["aperture", "prf", "sap", "sff", "cbv", "pld"])
method = validate_method(
method, supported_methods=["aperture", "prf", "sap", "sff", "cbv", "pld"]
)
if method in ["aperture", "sap"]:
return self.extract_aperture_photometry(**kwargs)
elif method == "prf":
Expand All @@ -581,7 +583,7 @@ def to_lightcurve(self, method="sap", corrector=None, **kwargs):

def _resolve_default_aperture_mask(self, aperture_mask):
if isinstance(aperture_mask, str):
if (aperture_mask == "default"):
if aperture_mask == "default":
# returns 'pipeline', unless it is missing. Falls back to 'threshold'
return "pipeline" if np.any(self.pipeline_mask) else "threshold"
else:
Expand Down Expand Up @@ -629,7 +631,7 @@ def _parse_aperture_mask(self, aperture_mask):

# Input validation
if hasattr(aperture_mask, "shape"):
if (aperture_mask.shape != self.shape[1:]):
if aperture_mask.shape != self.shape[1:]:
raise ValueError(
"`aperture_mask` has shape {}, "
"but the flux data has shape {}"
Expand All @@ -653,17 +655,17 @@ def _parse_aperture_mask(self, aperture_mask):
aperture_mask = np.zeros((self.shape[1], self.shape[2]), dtype=bool)
elif isinstance(aperture_mask, np.ndarray):
# Kepler and TESS pipeline style integer flags
if np.issubdtype(aperture_mask.dtype, np.dtype('>i4')):
if np.issubdtype(aperture_mask.dtype, np.dtype(">i4")):
aperture_mask = (aperture_mask & 2) == 2
elif np.issubdtype(aperture_mask.dtype, int):
if ((aperture_mask & 2) == 2).any():
# Kepler and TESS pipeline style integer flags
aperture_mask = (aperture_mask & 2) == 2
else:
aperture_mask = aperture_mask.astype(bool)
aperture_mask = aperture_mask.astype(bool)
elif np.issubdtype(aperture_mask.dtype, float):
aperture_mask = aperture_mask.astype(bool)
self._last_aperture_mask = aperture_mask
aperture_mask = aperture_mask.astype(bool)
self._last_aperture_mask = aperture_mask
return aperture_mask

def create_threshold_mask(self, threshold=3, reference_pixel="center"):
Expand Down Expand Up @@ -927,7 +929,7 @@ def query_solar_system_objects(
sigma=3,
cache=True,
return_mask=False,
show_progress=True
show_progress=True,
):
"""Returns a list of asteroids or comets which affected the target pixel files.
Expand Down Expand Up @@ -1032,7 +1034,7 @@ def query_solar_system_objects(

if radius == None:
radius = (
2 ** 0.5 * (pixel_scale * (np.max(self.shape[1:]) + 5))
2**0.5 * (pixel_scale * (np.max(self.shape[1:]) + 5))
) * u.arcsecond.to(u.deg)

res = _query_solar_system_objects(
Expand All @@ -1057,7 +1059,7 @@ def plot(
column="FLUX",
aperture_mask=None,
show_colorbar=True,
mask_color="red",
mask_color="tomato",
title=None,
style="lightkurve",
**kwargs,
Expand Down Expand Up @@ -1141,9 +1143,9 @@ def plot(
"RAW_CNTS": "Raw Counts",
}

with plt.style.context(style):
with plt.style.context([style, MPLSTYLE_IMG]):
if title is None:
title = "Target ID: {}, Cadence: {}".format(
title = "Target ID: {}\nCadence: {}".format(
self.targetid, self.cadenceno[frame]
)

Expand All @@ -1164,8 +1166,6 @@ def plot(
if hasattr(ax, "wcs"):
img_extent = None



ax = plot_image(
data_to_plot,
ax=ax,
Expand All @@ -1177,7 +1177,6 @@ def plot(
)
ax.grid(False)


# Overlay the aperture mask if given
if aperture_mask is not None:
aperture_mask = self._parse_aperture_mask(aperture_mask)
Expand Down Expand Up @@ -1269,9 +1268,16 @@ def animate(self, step: int = None, interval: int = 200, **plot_args):
# To make installing Lightkurve easier, ipython is an optional dependency,
# because we can assume it is installed when notebook-specific features are called
from IPython.display import HTML
return HTML(self._to_matplotlib_animation(step=step, interval=interval, **plot_args).to_jshtml())

return HTML(
self._to_matplotlib_animation(
step=step, interval=interval, **plot_args
).to_jshtml()
)
except ModuleNotFoundError:
log.error("ipython needs to be installed for animate() to work (e.g., `pip install ipython`)")
log.error(
"ipython needs to be installed for animate() to work (e.g., `pip install ipython`)"
)

def to_fits(self, output_fn=None, overwrite=False):
"""Writes the TPF to a FITS file on disk."""
Expand Down Expand Up @@ -1377,8 +1383,9 @@ def interact(
**kwargs,
)


def interact_sky(self, notebook_url=None, aperture_mask="empty", magnitude_limit=18):
def interact_sky(
self, notebook_url=None, aperture_mask="empty", magnitude_limit=18
):
"""Display a Jupyter Notebook widget showing Gaia DR2 positions on top of the pixels.
Parameters
Expand Down Expand Up @@ -1406,7 +1413,10 @@ def interact_sky(self, notebook_url=None, aperture_mask="empty", magnitude_limit
notebook_url = finalize_notebook_url(notebook_url)

return show_skyview_widget(
self, notebook_url=notebook_url, aperture_mask=aperture_mask, magnitude_limit=magnitude_limit
self,
notebook_url=notebook_url,
aperture_mask=aperture_mask,
magnitude_limit=magnitude_limit,
)

def to_corrector(self, method="pld", **kwargs):
Expand Down

0 comments on commit 3b9a0af

Please sign in to comment.