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

save_bin_data == False breaks lightcurve creation #472

Closed
pivosb opened this issue Jun 13, 2022 · 2 comments · Fixed by #474
Closed

save_bin_data == False breaks lightcurve creation #472

pivosb opened this issue Jun 13, 2022 · 2 comments · Fixed by #474
Assignees
Labels

Comments

@pivosb
Copy link

pivosb commented Jun 13, 2022

I've been having unexpected issues with the lightcurve generation in fermipy once I set save_bin_data to False.

Here's the error:

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
/tmp/ipykernel_134231/3996349889.py in <module>
      1 # Generate a lightcurve with 1-day binning
      2 #lc = gta.lightcurve('1es0229+200', binsz=86400. * 90)
----> 3 lc = gta.lightcurve('1es0229+200', time_bins=[611334005, 628423205, 645512405])

/afs/ifh.de/group/cta/scratch/pedroivo/Software/anaconda3/envs/fermi/lib/python3.7/site-packages/fermipy/lightcurve.py in lightcurve(self, name, **kwargs)
    287         self.logger.info('Computing Lightcurve for %s' % name)
    288 
--> 289         o = self._make_lc(name, **config)
    290         filename = utils.format_filename(self.workdir, 'lightcurve',
    291                                          prefix=[config['prefix'],

/afs/ifh.de/group/cta/scratch/pedroivo/Software/anaconda3/envs/fermi/lib/python3.7/site-packages/fermipy/lightcurve.py in _make_lc(self, name, **kwargs)
    451         for i, time in enumerate(zip(times[:-1], times[1:])):
    452             print(i, time)
--> 453             next_fit = next(mapo)
    454 
    455             if not 'fit_success' in next_fit:

StopIteration:  

After some digging, I realized that if save_bin_data is set to False, then in

if not kwargs.get('save_bin_data', False):
for m in mapo:
shutil.rmtree(m['config']['fileio']['outdir'])

you iterate over mapo , and then in

next_fit = next(mapo)

the iterator is exhausted and raises the StopIteration error.

The solution I found for now is to simply set save_bin_data to True again, and it works just fine.

@henrikef
Copy link
Contributor

I see what you mean. The iterator doesn't reset after you loop over it the first time. I think we can fix it by moving the file deletion into the 2nd loop. Let me give it a try.

@henrikef henrikef self-assigned this Jun 14, 2022
@henrikef henrikef added the bug label Jun 14, 2022
@henrikef
Copy link
Contributor

Take a look at #474 (branch lc_fixes) if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants