Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix latex error in plot_detailed_evolution #990

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/compas-compile-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
run: |
cd ${GITHUB_WORKSPACE}
export COMPAS_ROOT_DIR=${GITHUB_WORKSPACE}
sudo apt-get install -y cm-super
pytest --cov=compas_python_utils/ py_tests/
coverage html
coverage-badge -o coverage_badge.svg -f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@
import h5py as h5
import matplotlib.pyplot as plt
from matplotlib import rcParams
import matplotlib as mpl
import argparse

COMPAS_ROOT_DIR = os.path.expandvars(os.environ['COMPAS_ROOT_DIR'])
VAN_DEN_HEUVEL_DIR = os.path.join(COMPAS_ROOT_DIR, 'compas_python_utils/detailed_evolution_plotter/van_den_heuvel_figures/')

DIR = os.path.dirname(os.path.realpath(__file__))
VAN_DEN_HEUVEL_DIR = os.path.join(DIR, 'van_den_heuvel_figures')

def plot_with_latex_fallback(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
if "LaTeX" in str(e):
print("LaTeX error caught. Falling back to non-LaTeX rendering.")
mpl.rcParams.update({'text.usetex': False})
return func(*args, **kwargs)
else:
raise e

return wrapper

def main():
parser = argparse.ArgumentParser(description='Plot detailed evolution of a COMPAS binary')
Expand All @@ -27,6 +40,7 @@ def main():
run_main_plotter(args.data_path, outdir=args.outdir, show=args.dont_show)



def run_main_plotter(data_path, outdir='.', show=True):
Data = h5.File(data_path, 'r')

Expand Down Expand Up @@ -58,6 +72,7 @@ def run_main_plotter(data_path, outdir='.', show=True):

####### Functions to organize and call the plotting functions

@plot_with_latex_fallback
def makeDetailedPlots(Data=None, events=None, outdir='.', show=True):
listOfPlots = [plotMassAttributes, plotLengthAttributes, plotStellarTypeAttributes, plotHertzsprungRussell]

Expand Down Expand Up @@ -122,6 +137,7 @@ def makeDetailedPlots(Data=None, events=None, outdir='.', show=True):
######## Plotting functions


@plot_with_latex_fallback
def plotMassAttributes(ax=None, Data=None, mask=None, **kwargs):
### Plot mass attributes
# Create new column for total mass
Expand All @@ -138,7 +154,7 @@ def plotMassAttributes(ax=None, Data=None, mask=None, **kwargs):

return ax.get_legend_handles_labels()


@plot_with_latex_fallback
def plotLengthAttributes(ax=None, Data=None, mask=None, **kwargs):
### Plot radius attributes
ax.plot(Data['Time'][()][mask], Data['SemiMajorAxis'][()][mask], linestyle='-', c='k', label='Semi-Major Axis')
Expand All @@ -159,7 +175,7 @@ def plotLengthAttributes(ax=None, Data=None, mask=None, **kwargs):

return ax.get_legend_handles_labels()


@plot_with_latex_fallback
def plotEccentricity(ax=None, Data=None, mask=None, **kwargs):
### Plot eccentricity
ax.plot(Data['Time'][()], Data['Eccentricity'][()], linestyle='-', c='k') # , label= 'Eccentricity')
Expand All @@ -170,7 +186,7 @@ def plotEccentricity(ax=None, Data=None, mask=None, **kwargs):

return None, None


@plot_with_latex_fallback
def plotStellarTypeAttributes(ax=None, Data=None, mask=None, **kwargs):
### Plot stellar types
stellarTypes, useTypes, typeNameMap = getStellarTypes(Data)
Expand All @@ -190,7 +206,7 @@ def plotStellarTypeAttributes(ax=None, Data=None, mask=None, **kwargs):

return ax.get_legend_handles_labels()


@plot_with_latex_fallback
def plotStellarTypeAttributesAndEccentricity(ax=None, Data=None, mask=None, **kwargs):
ax1 = ax
ax2 = ax.twinx()
Expand Down Expand Up @@ -226,7 +242,7 @@ def plotStellarTypeAttributesAndEccentricity(ax=None, Data=None, mask=None, **kw

return handles, labels


@plot_with_latex_fallback
def plotHertzsprungRussell(ax=None, Data=None, events=None, mask=None, **kwargs):
### Plot HR diagram: L vs Teff

Expand Down Expand Up @@ -293,6 +309,7 @@ def get_L(t): # assumes K
return ax.get_legend_handles_labels()


@plot_with_latex_fallback
def plotVanDenHeuvel(events=None, outdir='.'):
# Only want events with an associated image
events = [event for event in events if (event.eventImage is not None)]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"flake8",
"black==22.10.0",
"isort",
"matplotlib",
"matplotlib>=3.6.0",
"pandas",
"astropy",
"scipy",
Expand Down