Skip to content

Formatting updates for releasing LC Fitting #1231

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

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
97 changes: 68 additions & 29 deletions exotic/api/colab.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,78 @@

# If the user presses enter to run the sample data, download sample data if needed and
# put it into a sample-data directory at the top level of the user's Gdrive. Count
# the .fits files (images) and .json files (inits files) in the directory entered
# by the user (or in the sample-data directory if the user pressed enter). If
# there are at least 20 .fits files, assume this is a directory of images and display
# the first one in the series. If there is exactly one inits file in the directory,
# show the specified target and comp coords so that the user can check these against
# the displayed image. Otherwise, prompt for target / comp coords and make an inits
# file based on those (save this new inits file in the folder with the output files
# so that the student can consult it later). Finally, run EXOTIC with the newly-made
# ########################################################################### #
# Copyright (c) 2019-2020, California Institute of Technology.
# All rights reserved. Based on Government Sponsored Research under
# contracts NNN12AA01C, NAS7-1407 and/or NAS7-03001.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name of the California Institute of
# Technology (Caltech), its operating division the Jet Propulsion
# Laboratory (JPL), the National Aeronautics and Space
# Administration (NASA), nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALIFORNIA
# INSTITUTE OF TECHNOLOGY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ########################################################################### #
# EXOplanet Transit Interpretation Code (EXOTIC)
# # NOTE: See companion file version.py for version info.
# ########################################################################### #
# IMPORTANT RUNTIME INFORMATION ABOUT DATA ACCESS AND STORAGE
#
# If the user presses enter to run the sample data, download sample data if
# needed and put it into a sample-data directory at the top level of the
# user's Gdrive. Count the .fits files (images) and .json files (inits files)
# in the directory entered by the user (or in the sample-data directory if the
# user pressed enter). If there are at least 20 .fits files, assume this is a
# directory of images and display the first one in the series. If there is
# exactly one inits file in the directory, show the specified target and comp
# coords so that the user can check these against the displayed image.
# Otherwise, prompt for target / comp coords and make an inits file based on
# those (save this new inits file in the folder with the output files so that
# the student can consult it later). Finally, run EXOTIC with the newly-made
# or pre-existing inits file, plus any other inits files in the directory.

#
#########################################################
from IPython.display import display, HTML
from astropy.io import fits
from astropy.time import Time
from barycorrpy import utc_tdb
import numpy as np
from io import BytesIO
from astropy.io import fits
from scipy.ndimage import label
from bokeh.plotting import figure, output_file, show
# import bokeh.io
# from bokeh.io import output_notebook
from bokeh.palettes import Viridis256
from bokeh.models import ColorBar, LinearColorMapper, LogColorMapper, LogTicker
from bokeh.models import BoxZoomTool,WheelZoomTool,ResetTool,HoverTool,PanTool,FreehandDrawTool
#import bokeh.io
#from bokeh.io import output_notebook
from pprint import pprint
#from IPython.display import Image
#from ipywidgets import widgets, HBox
from skimage.transform import rescale, resize, downscale_local_mean
#import copy
from bokeh.plotting import figure, output_file, show
from bokeh.models import BoxZoomTool, ColorBar, FreehandDrawTool, HoverTool, LinearColorMapper, LogColorMapper, \
LogTicker, PanTool, ResetTool, WheelZoomTool
# import copy
from io import BytesIO
from IPython.display import display, HTML
# from IPython.display import Image
# from ipywidgets import widgets, HBox
import json
import numpy as np
import os
from pprint import pprint
import re
import json
#import subprocess
from scipy.ndimage import label
from skimage.transform import rescale, resize, downscale_local_mean
# import subprocess
import time


Expand Down
9 changes: 3 additions & 6 deletions exotic/api/elca.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,32 @@
# EXOplanet Transit Interpretation Code (EXOTIC)
# # NOTE: See companion file version.py for version info.
# ########################################################################### #
# ########################################################################### #
# Exoplanet light curve analysis
#
# Fit an exoplanet transit model to time series data.
# ########################################################################### #

from astropy.time import Time
import copy
from itertools import cycle
import matplotlib.pyplot as plt
import numpy as np
from pylightcurve.models.exoplanet_lc import transit as pytransit
from scipy import spatial
from scipy.optimize import least_squares
from scipy.signal import savgol_filter

try:
from ultranest import ReactiveNestedSampler
except ImportError:
import dynesty
import dynesty.plotting
from dynesty.utils import resample_equal
from scipy.stats import gaussian_kde

try:
from plotting import corner
except:
except ImportError:
from .plotting import corner

from pylightcurve.models.exoplanet_lc import transit as pytransit


def weightedflux(flux, gw, nearest):
return np.sum(flux[nearest] * gw, axis=-1)
Expand Down
30 changes: 23 additions & 7 deletions exotic/api/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,31 @@
# a periodogram analysis.
#
# ########################################################################### #

import numpy as np
from itertools import cycle
import statsmodels.api as sm
import matplotlib.pyplot as plt
from exotic.api.plotting import corner
from ultranest import ReactiveNestedSampler
from astropy.timeseries import LombScargle
from astropy import units as u
import copy
from itertools import cycle
import matplotlib.pyplot as plt
import numpy as np
import rebound
import statsmodels.api as sm
try:
from ultranest import ReactiveNestedSampler
except ImportError:
import dynesty
import dynesty.plotting
from dynesty.utils import resample_equal
from scipy.stats import gaussian_kde

try:
from nested_linear_fitter import linear_fitter, non_linear_fitter
except ImportError:
from .nested_linear_fitter import linear_fitter, non_linear_fitter
try:
from plotting import corner
except ImportError:
from .plotting import corner


class ephemeris_fitter(object):

Expand Down Expand Up @@ -1369,6 +1384,7 @@ def prior_transform(upars):

# TODO extend plot, BIC Values

# should this be here?
dude()
# mearth = u.M_earth.to(u.kg).value
msun = u.M_sun.to(u.kg)
Expand Down
49 changes: 45 additions & 4 deletions exotic/api/ew.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import os
# ########################################################################### #
# Copyright (c) 2019-2020, California Institute of Technology.
# All rights reserved. Based on Government Sponsored Research under
# contracts NNN12AA01C, NAS7-1407 and/or NAS7-03001.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name of the California Institute of
# Technology (Caltech), its operating division the Jet Propulsion
# Laboratory (JPL), the National Aeronautics and Space
# Administration (NASA), nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALIFORNIA
# INSTITUTE OF TECHNOLOGY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ########################################################################### #
# EXOplanet Transit Interpretation Code (EXOTIC)
# # NOTE: See companion file version.py for version info.
# ########################################################################### #
import json
import urllib
import numpy as np
import os
import urllib

base_uri = "https://exoplanets.nasa.gov/watch_results/"


class ExoplanetWatch():
url = 'https://exoplanets.nasa.gov/api/v1/exoplanet_watch_results/?per_page=-1&order=planet_name+asc'
def __init__(self) -> None:
Expand Down Expand Up @@ -50,6 +88,7 @@ def get(self, target):
print(f"{target} not in list")
return {}


class ExoplanetWatchTarget():
def __init__(self,result) -> None:
self.raw_result = result
Expand Down Expand Up @@ -92,6 +131,7 @@ def check4floats(dictionary):
pass
return dictionary


class ExoplanetWatchObservation():
def __init__(self, name, observation) -> None:
self.raw_observation = observation
Expand Down Expand Up @@ -130,6 +170,7 @@ def get_data(self):
jdata = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8'))
return np.array(jdata[1:],dtype=float).T


def translate_keys(rdict):
""" Translates the keys to a compatible format for EXOTIC/ELCA

Expand Down Expand Up @@ -165,11 +206,11 @@ def translate_keys(rdict):
lc_pars[k] = np.nan
return lc_pars

if __name__ == "__main__":

if __name__ == "__main__":
EW = ExoplanetWatch()
print(EW.target_list)
result = EW.get('WASP-33 b')
print(result)
time, flux, fluxerr, airmass, airmasscorr = result.observations[0].get_data()
print(result.observations[0].parameters)
print(result.observations[0].parameters)
17 changes: 7 additions & 10 deletions exotic/api/gael_ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@
# EXOplanet Transit Interpretation Code (EXOTIC)
# # NOTE: See companion file version.py for version info.
# ########################################################################### #

import logging
import numpy as np
import lmfit as lm
import matplotlib.pyplot as plt
import ldtk
from ldtk import LDPSetCreator, BoxcarFilter
from ldtk.ldmodel import LinearModel, QuadraticModel, NonlinearModel
import lmfit as lm
import logging
import matplotlib.pyplot as plt
import numpy as np

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -92,9 +90,9 @@ def createldgrid(minmu, maxmu, orbp,
munm = 1e3*np.array(avmu[loweri:upperi])
munmmin = 1e3*np.array(minmu[loweri:upperi])
munmmax = 1e3*np.array(maxmu[loweri:upperi])
filters = [BoxcarFilter(str(mue), mun, mux)
filters = [ldtk.BoxcarFilter(str(mue), mun, mux)
for mue, mun, mux in zip(munm, munmmin, munmmax)]
sc = LDPSetCreator(teff=(tstar, terr), logg=(loggstar, loggerr),
sc = ldtk.LDPSetCreator(teff=(tstar, terr), logg=(loggstar, loggerr),
z=(fehstar, feherr), filters=filters)
ps = sc.create_profiles(nsamples=int(1e4))
itpfail = False
Expand All @@ -105,7 +103,7 @@ def createldgrid(minmu, maxmu, orbp,
nfail = 1e0
while itpfail:
nfail *= 2
sc = LDPSetCreator(teff=(tstar, nfail*terr), logg=(loggstar, loggerr),
sc = ldtk.LDPSetCreator(teff=(tstar, nfail*terr), logg=(loggstar, loggerr),
z=(fehstar, feherr), filters=filters)
ps = sc.create_profiles(nsamples=int(1e4))
itpfail = False
Expand Down Expand Up @@ -254,4 +252,3 @@ def nl_ldx(params, x, data=None, weights=None):
if weights is None:
return data - model
return (data - model)/weights

Loading