catrionamurray / chromatic_fitting

chromatic_fitting tool to perform multi-wavelength spectrophotometry built on top of chromatic
MIT License
10 stars 1 forks source link

Secondary eclipse branch merging #27

Closed Pat-Wachiraphan closed 1 year ago

Pat-Wachiraphan commented 1 year ago

Here I created the merging of branch 'merging-eclipse' which used 'Starry' as a model.

catrionamurray commented 1 year ago

Hi @Pat-Wachiraphan can you send me a notebook with an example fit? I'm struggling to get the initial priors quite right to test it out

catrionamurray commented 1 year ago

I also don't see where limb darkening is used in the code

catrionamurray commented 1 year ago

I have an issue fitting if I use any Uniform distributions without upper/lower bounds - the logP goes to inf or nan. Is this the same for other models? Adding in an additional check stage to prevent this happening...

Pat-Wachiraphan commented 1 year ago

when run cm.add_model_to_rainbow() function, it seems like the parameters that pass to eclipse_model are not correct. Probably the extract_from_posteriors function doesn't account for Fitted with shape = 2 case. It make the ecs parameter has only 1 instance instead of 2.

The error

KeyError                                  Traceback (most recent call last)
Cell In[3], line 1
----> 1 cm.add_model_to_rainbow()

File ~/Work/chromatic_fitting/chromatic_fitting/models/combined.py:535, in CombinedModel.add_model_to_rainbow(self)
    533 if isinstance(mod, TransitModel) or isinstance(mod, EclipseModel):
    534     if i_transit == 0:
--> 535         transit_model = mod.get_model()
    536     else:
    537         # I'm not sure that this works if the combination option is multiply or divide
    538         transit_model = combination_options[self.how_to_combine[i - 1]](
    539             transit_model, mod.get_model()
    540         )

File ~/Work/chromatic_fitting/chromatic_fitting/models/lightcurve.py:1181, in LightcurveModel.get_model(self, params_dict, as_dict, as_array, store)
   1179             params = params_dict[f"w{i}"]
   1180     print (params, i)
-> 1181     model_i = self.model(params, i)
   1182     model[f"w{i}"] = model_i
   1184 if store:

File ~/Work/chromatic_fitting/chromatic_fitting/models/eclipse.py:347, in EclipseModel.eclipse_model(self, eclipse_params, i, time)
    332 self.check_and_fill_missing_parameters(eclipse_params, i)
    334 star = starry.Primary(
    335     starry.Map(
    336         ydeg=0,
   (...)
    344     prot=eclipse_params[f"{name}stellar_prot"],
    345 )
--> 347 omega = theano.tensor.arctan2(eclipse_params[f"{name}ecs[1]"], eclipse_params[f"{name}ecs[0]"])
    348 eccentricity = pm.math.sqrt(eclipse_params[f"{name}ecs[0]"]**2+eclipse_params[f"{name}ecs[1]"]**2)
    350 planet = starry.kepler.Secondary(
    351     starry.Map(
    352         ydeg=0,
   (...)
    368     mass_unit=u.M_jup,
    369 )

KeyError: 'eclipse_ecs[1]'

The parameters passed through eclipse_model

{'eclipse_stellar_radius': 0.265, 'eclipse_stellar_mass': 0.257, 'eclipse_stellar_amplitude': 1.0, 'eclipse_stellar_prot': 1.0, 'eclipse_period': 5.3587657, 'eclipse_t0': 2458412.70851, 'eclipse_planet_log_amplitude': -4.1435571387, 'eclipse_inclination': 89.68, 'eclipse_planet_mass': 0.00903, 'eclipse_planet_radius': 0.1164, 'eclipse_ecs': 0.0123583112, 'eclipse_limbdark1': 0.4, 'eclipse_limbdark2': 0.2}
catrionamurray commented 1 year ago

@Pat-Wachiraphan is this ready for a review to be merged?

Pat-Wachiraphan commented 1 year ago

@Pat-Wachiraphan is this ready for a review to be merged?

Sorry for the delay but yes! I think it should be ready!

Pat-Wachiraphan commented 1 year ago

I've encountered problems with plot_priors and plot_posteriors. I'm not sure how to fix this but yet.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[16], line 1
----> 1 visit1.plot_priors()

File ~/Work/chromatic_fitting/chromatic_fitting/models/lightcurve.py:871, in LightcurveModel.plot_priors(self, n, quantity, plot_all)
    869             else:
    870                 i_dict = {**i_dict, **{k: v[i][w]}}
--> 871         model_for_this_sample.append(self.model(i_dict))
    872     model_for_this_sample = np.array(model_for_this_sample)
    874 # add posterior model and draw from posterior distribution to the Rainbow quantities:

TypeError: CombinedModel.combined_model() takes 1 positional argument but 2 were given