def make_xml(nametag): spatial = gammalib.GModelSpatialDiffuseCube( gammalib.GFilename(nametag + '_map.fits')) spectral = gammalib.GModelSpectralConst(1.) model = gammalib.GModelSky(spatial, spectral) model.name(nametag) # fill to model container and write to disk models = gammalib.GModels() models.append(model) models.save(nametag + '.xml')
def _check_result_file(self, filename): """ Check content of map cube Parameters ---------- filename : str Map cube file name """ # Load map cube cube = gammalib.GModelSpatialDiffuseCube(filename) # Check map cube self._check_cube(cube) # Return return
def _check_cube(self, filename): """ Check content of map cube Parameters ---------- filename : str Map cube file name. """ # Load map cube cube = gammalib.GModelSpatialDiffuseCube(filename) # Test map cube #self.test_value(cube.maps(), 20, "20 maps") #self.test_value(cube.pixels(), 40000, "40000 map pixels") # The map cube is not loaded by default !!!! We should add the method so that # the attributes are known !!!! self.test_value(cube.maps(), 0, '20 maps') self.test_value(cube.pixels(), 0, '40000 map pixels') # Return return
def save(self): """ Save the cube and optionally the updated XML model file """ # Save the generated cube if the cube and filename are not empty if ((not self._cubegen.mapcube().cube().is_empty()) and self['outcube'].is_valid()): self._cubegen.mapcube().save(self['outcube'].filename(), self['clobber'].boolean()) # If requested, save the updated list of models if self['outmodel'].is_valid(): # Generate a list of models that will be output to file outmodels = gammalib.GModels(self._models) # Remove all models used in the generated cube for model in self._cubemodels: outmodels.remove(model.name()) # Generate the actual cube model spat = gammalib.GModelSpatialDiffuseCube(self['outcube'].filename()) spec = gammalib.GModelSpectralConst() newmodel = gammalib.GModelSky(spat, spec) # Give the model a default name newmodel.name(self.cubemodelname()) # Now append the model to the list of output models outmodels.append(newmodel) # Save the model list outmodels.save(self['outmodel'].filename()) # Return return
added += 1 # add templates models_template = gammalib.GModels('../known-sources/templates/{}.xml'.format(name)) for model in models_template: # if model contains spatial map take care of it if model.spatial().type() == 'DiffuseMap' or model.spatial().type() == 'DiffuseMapCube': # find model map name and path filename = model.spatial().filename().file() filepath = model.spatial().filename().path() # copy file to output directory shutil.copy(filepath + filename, './') # replace file with the one in output directory if model.spatial().type() == 'DiffuseMap': model.spatial(gammalib.GModelSpatialDiffuseMap(filename)) elif model.spatial().type() == 'DiffuseMapCube': model.spatial(gammalib.GModelSpatialDiffuseCube(gammalib.GFilename(filename), model.spatial()['Normalization'].value())) # if model contains spatial map take care of it if model.spectral().type() == 'FileFunction': # find spectrum file name and path filename = model.spectral().filename().file() filepath = model.spectral().filename().path() # copy file to output directory shutil.copy(filepath + filename, './') # replace file with the one in output directory model.spectral(gammalib.GModelSpectralFunc(gammalib.GFilename(filename), model.spectral()['Normalization'].value())) # append model to container models.append(model) # if new remove synthetic source if new: src_dir = get_model_dir(model)
for idx2 in (np.arange(0,int(width/binsize))[::-1]): if (idx2+1.0)/(idx1+1.0) < (np.tan((125-ang)*np.pi/180.) - 7/binsize/(idx1+1.0)): #+ 80/idx1+1.0: skymap.data[j,idx1,idx2] *= 0 else: continue ### Smooth the map skymap = skymap.smooth(width=0.08 * u.deg, kernel="gauss") ### Save the map skymap.write('hessj1825_cube.fits', hdu='Primary', overwrite='True') hdul = fits.open('hessj1825_cube.fits') hdul[0].header.set('BUNIT', 'photon/cm2/s/MeV/sr', 'Photon flux') hdul[0].verify('fix') del hdul[0].header['BANDSHDU'] hdul[1].name='ENERGIES' hdul[1].header['TTYPE2']='Energy' hdul[1].verify('fix') hdul.writeto('hessj1825_map.fits',overwrite=True) ### create gammalib model spatial = gammalib.GModelSpatialDiffuseCube(gammalib.GFilename('hessj1825_map.fits')) spectral = gammalib.GModelSpectralConst(1.) model = gammalib.GModelSky(spatial,spectral) ## fill to model container and write to disk models = gammalib.GModels() models.append(model) models.save('hessj1825.xml')