ekaterinailin / AltaiPony

Find flares in Kepler and TESS light curves. Notebooks for quickstart inside.
https://altaipony.readthedocs.io
MIT License
26 stars 10 forks source link

error while running "flcd = flc.detrend("savgol")" #74

Closed sam687 closed 9 months ago

sam687 commented 2 years ago

I am getting this error while running flcd = flc.detrend("savgol")

AttributeError Traceback (most recent call last) Input In [16], in <cell line: 1>() ----> 1 flcd = flc.detrend("savgol")

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/flarelc.py:349, in FlareLightCurve.detrend(self, mode, save, path, de_niter, max_sigma, func, kwargs) 346 if mode == "savgol": 348 new_lc = copy.deepcopy(self) --> 349 new_lc = detrend_savgol(new_lc, kwargs) 350 if save == True: 351 new_lc.to_fits(path)

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/altai.py:281, in detrend_savgol(lc, window_length, pad, printwl, **kwargs) 278 flux_model_i = savgol_filter(flux, wl, 3, mode='nearest') 280 flux_diff = flux - flux_model_i + np.nanmean(flux_model_i) --> 281 lc.detrended_flux.value[ok] = flux_diff 282 lc.flux_model.value[ok] = flux_model_i 284 # Find out where outlier begin and end:

AttributeError: 'MaskedNDArray' object has no attribute 'value'

Screenshot from 2022-04-28 17-02-42

keyuxing commented 2 years ago

This error is caused by MaskedNDArray introduced in Astropy v5.0. Using Astropy <= 4.3.1 solves this issue.

sam687 commented 2 years ago

Thanks! It worked. But this created another error.


AttributeError Traceback (most recent call last) Input In [46], in <cell line: 1>() ----> 1 flcc = flcd.characterize_flares(ampl_bins=10, dur_bins=10)

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/flarelc.py:944, in FlareLightCurve.characterize_flares(self, flares_per_bin, ampl_bins, dur_bins) 939 """Use results from injection recovery to determine 940 corrected flare characteristics. 941 942 """ 943 flc = copy.deepcopy(self) --> 944 flares = wrap_characterization_of_flares(flc.fake_flares, flc.flares, 945 flares_per_bin=flares_per_bin, 946 ampl_bins=ampl_bins, 947 dur_bins=dur_bins) 948 flc.flares = flares 949 return flc

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/injrecanalysis.py:36, in wrap_characterization_of_flares(injrec, flares, ampl_bins, dur_bins, flares_per_bin) 33 # define observed flare duration 34 flares["dur"] = flares.tstop - flares.tstart ---> 36 ampl_bins, dur_bins = setup_bins(injrec, flares, ampl_bins=ampl_bins, 37 dur_bins=dur_bins, 38 flares_per_bin=flares_per_bin) 40 flares = flares.dropna(subset=["ed_rec"]) 41 injrec.ed_rec = injrec.ed_rec.fillna(0)

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/injrecanalysis.py:442, in setup_bins(injrec, flares, ampl_bins, dur_bins, flares_per_bin) 440 # Set bins according to data 441 if isinstance(ampl_bins, int): --> 442 ampl_bins = np.linspace(min(injrec.ampl_rec.min(), 443 flares.ampl_rec.min(), 444 injrec.amplitude.min()), 445 max(injrec.ampl_rec.max(), 446 flares.ampl_rec.max(), 447 injrec.amplitude.max()), 448 ampl_bins) 450 if isinstance(dur_bins, int): 451 dur_bins = np.linspace(min(injrec.dur.min(), 452 flares.dur.min(), 453 injrec.duration_d.min()), (...) 456 injrec.duration_d.max()), 457 dur_bins)

File ~/jupyter/environment/lib/python3.8/site-packages/pandas/core/generic.py:5139, in NDFrame.getattr(self, name) 5137 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5138 return self[name] -> 5139 return object.getattribute(self, name)

AttributeError: 'DataFrame' object has no attribute 'ampl_rec'

astrosebas commented 2 years ago

Thanks! It worked. But this created another error.

AttributeError Traceback (most recent call last) Input In [46], in <cell line: 1>() ----> 1 flcc = flcd.characterize_flares(ampl_bins=10, dur_bins=10)

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/flarelc.py:944, in FlareLightCurve.characterize_flares(self, flares_per_bin, ampl_bins, dur_bins) 939 """Use results from injection recovery to determine 940 corrected flare characteristics. 941 942 """ 943 flc = copy.deepcopy(self) --> 944 flares = wrap_characterization_of_flares(flc.fake_flares, flc.flares, 945 flares_per_bin=flares_per_bin, 946 ampl_bins=ampl_bins, 947 dur_bins=dur_bins) 948 flc.flares = flares 949 return flc

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/injrecanalysis.py:36, in wrap_characterization_of_flares(injrec, flares, ampl_bins, dur_bins, flares_per_bin) 33 # define observed flare duration 34 flares["dur"] = flares.tstop - flares.tstart ---> 36 ampl_bins, dur_bins = setup_bins(injrec, flares, ampl_bins=ampl_bins, 37 dur_bins=dur_bins, 38 flares_per_bin=flares_per_bin) 40 flares = flares.dropna(subset=["ed_rec"]) 41 injrec.ed_rec = injrec.ed_rec.fillna(0)

File ~/jupyter/environment/lib/python3.8/site-packages/altaipony/injrecanalysis.py:442, in setup_bins(injrec, flares, ampl_bins, dur_bins, flares_per_bin) 440 # Set bins according to data 441 if isinstance(ampl_bins, int): --> 442 ampl_bins = np.linspace(min(injrec.ampl_rec.min(), 443 flares.ampl_rec.min(), 444 injrec.amplitude.min()), 445 max(injrec.ampl_rec.max(), 446 flares.ampl_rec.max(), 447 injrec.amplitude.max()), 448 ampl_bins) 450 if isinstance(dur_bins, int): 451 dur_bins = np.linspace(min(injrec.dur.min(), 452 flares.dur.min(), 453 injrec.duration_d.min()), (...) 456 injrec.duration_d.max()), 457 dur_bins)

File ~/jupyter/environment/lib/python3.8/site-packages/pandas/core/generic.py:5139, in NDFrame.getattr(self, name) 5137 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5138 return self[name] -> 5139 return object.getattribute(self, name)

AttributeError: 'DataFrame' object has no attribute 'ampl_rec'

Hello. Did you solve this error?

ekaterinailin commented 2 years ago

@sam687 How do flc.fake_flares and flc.flares look if you print them? (and @astrosebas if you get the same error^^)

sam687 commented 2 years ago

It is solved now. Downgrading astropy from 5.x.x to 4.x.x has solved the problem.