Commit 29d88dfd0f5fe0bd5197e400ef8e718b09a89e42

Authored by Jürgen Knödlseder
1 parent 16b9aa88

Add nthreads parameter to obsutils.get_stacked_obs() and set parameter to 1 in cslightcrv

cscripts/cslightcrv.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Generates a lightcurve. 3 # Generates a lightcurve.
4 # 4 #
5 -# Copyright (C) 2014-2018 Michael Mayer 5 +# Copyright (C) 2014-2019 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -502,7 +502,7 @@ class cslightcrv(ctools.csobservation): @@ -502,7 +502,7 @@ class cslightcrv(ctools.csobservation):
502 # and compute the stacked response functions and setup 502 # and compute the stacked response functions and setup
503 # an observation container with a single stacked observation. 503 # an observation container with a single stacked observation.
504 if self._stacked: 504 if self._stacked:
505 - new_obs = obsutils.get_stacked_obs(self, obs) 505 + new_obs = obsutils.get_stacked_obs(self, obs, nthreads=1)
506 506
507 # ... otherwise if On/Off analysis is requested generate 507 # ... otherwise if On/Off analysis is requested generate
508 # the On/Off observations and response 508 # the On/Off observations and response
cscripts/cssens.py
@@ -83,7 +83,7 @@ class cssens(ctools.csobservation): @@ -83,7 +83,7 @@ class cssens(ctools.csobservation):
83 'dec' : self._dec, 83 'dec' : self._dec,
84 'log_clients' : self._log_clients, 84 'log_clients' : self._log_clients,
85 'models' : self._models, 85 'models' : self._models,
86 - 'nthreads' : self._nthreads} 86 + 'nthreads' : self._nthreads}
87 87
88 # Return pickled dictionary 88 # Return pickled dictionary
89 return state 89 return state
cscripts/obsutils.py
1 # ========================================================================== 1 # ==========================================================================
2 # Utility functions for observation handling 2 # Utility functions for observation handling
3 # 3 #
4 -# Copyright (C) 2011-2018 Juergen Knoedlseder 4 +# Copyright (C) 2011-2019 Juergen Knoedlseder
5 # 5 #
6 # This program is free software: you can redistribute it and/or modify 6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by 7 # it under the terms of the GNU General Public License as published by
@@ -670,7 +670,7 @@ def get_stacked_response(obs, cntcube, edisp=False, addbounds=False, @@ -670,7 +670,7 @@ def get_stacked_response(obs, cntcube, edisp=False, addbounds=False,
670 # ================================= # 670 # ================================= #
671 # Get stacked observation container # 671 # Get stacked observation container #
672 # ================================= # 672 # ================================= #
673 -def get_stacked_obs(cls, obs): 673 +def get_stacked_obs(cls, obs, nthreads=0):
674 """ 674 """
675 Bin an observation and return an observation container with a single 675 Bin an observation and return an observation container with a single
676 binned observation 676 binned observation
@@ -681,6 +681,8 @@ def get_stacked_obs(cls, obs): @@ -681,6 +681,8 @@ def get_stacked_obs(cls, obs):
681 cscript class 681 cscript class
682 obs : `~gammalib.GObservations` 682 obs : `~gammalib.GObservations`
683 Observation container 683 Observation container
  684 + nthreads : str, optional
  685 + Number of parallel processes for On/Off spectra computation (0=all available CPUs)
684 686
685 Returns 687 Returns
686 ------- 688 -------
@@ -705,6 +707,7 @@ def get_stacked_obs(cls, obs): @@ -705,6 +707,7 @@ def get_stacked_obs(cls, obs):
705 cntcube['emax'] = cls['emax'].real() 707 cntcube['emax'] = cls['emax'].real()
706 cntcube['coordsys'] = cls['coordsys'].string() 708 cntcube['coordsys'] = cls['coordsys'].string()
707 cntcube['proj'] = cls['proj'].string() 709 cntcube['proj'] = cls['proj'].string()
  710 + cntcube['nthreads'] = nthreads
708 cntcube.run() 711 cntcube.run()
709 712
710 # Store counts cube so that we can use it to build the background 713 # Store counts cube so that we can use it to build the background