예제 #1
0
	def __getFluxUnits(self, config):
		try:
			options = [astun.Jy, astun.mJy, astun.uJy]
			if uf.checkkeys(config, 'SpectrumFluxUnit'):
				choice = config['SpectrumFluxUnit']
			else:
				print ("\nWhat are the flux denisty units of your spectra?\n\t1. Jansky (Jy)\n\t2. Milli Jansky (mJy)\n\t3. Micro Jansky (uJy)\n\t4. Jansky/beam (Jy/beam)\n\t5. Milli Jansky/beam (mJy/beam)\n\t6. Micro Jansky/beam (uJy/beam)")
				choice = input('Please enter the number of the applicable units: ')
			if type(choice) != int:
				print ('Please only select one unit.')
				self.__getFluxUnits(None)
			elif choice in [1,2,3]:
				self.fluxunit = options[int(choice-1)]
				self.convfactor = 1
			else:
				self.fluxunit = options[int(choice-4)]
				if uf.checkkeys(config, 'BeamSize') and uf.checkkeys(config, 'PixelSize'):
					pxsize = config['PixelSize']
					beamsize = config['BeamSize']
				else:
					pxsize = input('Please enter pixel size in arcseconds: ')
					beamsize = input('Please enter fwhm of beam (in arcseconds): ')
				self.convfactor = ( 2.*np.pi*beamsize*beamsize/( 2.*np.sqrt(2.*np.log(2) ) )**2  )/pxsize**2
		except KeyboardInterrupt:
			raise KeyboardInterrupt
		except SystemExit:
			uf.exit(self)
		except:
			logger.error('There was an input error with your unit selection', exc_info=True)
			uf.earlyexit(self)
		return
예제 #2
0
파일: inputData.py 프로젝트: kmhess/HISS
    def __getSpectralUnits(self, config):
        try:
            if uf.checkkeys(config, 'SpectralAxisUnit') and uf.checkkeys(
                    config, 'VelocityType'):
                choice = config['SpectralAxisUnit']
                self.veltype = config['VelocityType']
            else:
                print(
                    "\nWhat are the units of spectral axis of your spectra?\n\t1. Hertz (Hz)\n\t2. Kilo Hertz (kHz)\n\t3. Mega Hertz (MHz)\n\t4. Metres/Second (m/s)\n\t5. Kilometres/Second (km/s)\n\t6. Radio velocity (km/s)"
                )
                choice = input(
                    'Please enter the number of the applicable units: ')
                if int(choice) in [4, 5]:
                    self.veltype = input(
                        'Please enter the velocity type [optical/radio]: '
                    ).lower()
            options = [
                astun.Hz, astun.kHz, astun.MHz, astun.m / astun.s,
                astun.km / astun.s
            ]
            self.spectralunit = options[int(choice) - 1]

        except KeyboardInterrupt:
            raise KeyboardInterrupt
        except SystemExit:
            uf.exit(self)
        except:
            logger.error('There was an input error with your unit selection.',
                         exc_info=True)
            uf.earlyexit(self)
        return
예제 #3
0
	def __getClusterStack(self, config):
		try:
			vals = {'t': True, 'f': False}
			if uf.checkkeys(config, 'ClusterStack'):
				val = config['ClusterStack'] 
				val = val[0].lower()
				self.cluster = vals[val]
			else:
				val = input('Are you stacking a galaxy cluster [True/False]: ') 
				val = val.lower()
				self.cluster = vals[val]

			if self.cluster == True:
				if uf.checkkeys(config, 'ClusterRedshift'):
					val = config['ClusterRedshift']
					if type(val) != float:
						val = eval(val)
					else: pass
					self.clusterZ = val
				else:
					val = eval(input('Enter the cluster redshift: '))
					self.clusterZ = val
				self.clusterDL = self.cosmology.luminosity_distance(self.clusterZ)
				logger.info('Stacking galaxy cluster at z = %.4f (Dl = %.1f Mpc)'%(self.clusterZ, self.clusterDL.value))
			else:
				logger.info('No galaxy cluster in this sample.')
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			raise uf.exit(self)
		except:
			logger.error("Did not understand if there is a galaxy cluster in this sample.", exc_info=True)
			uf.earlyexit(self)
예제 #4
0
파일: inputData.py 프로젝트: kmhess/HISS
 def __getCosmology(self, config):
     try:
         if uf.checkkeys(config, 'H0') and uf.checkkeys(config, 'Om0'):
             H0 = config['H0']
             Om0 = config['Om0']
         else:
             print('\nWe assume a Flat Lambda CDM universe')
             H0 = input(
                 'Please enter the Hubble constant (H0) in units of km/s/Mpc: '
             )
             Om0 = input('Please enter the Omega matter (Om0): ')
         self.cosmology = astcos.FlatLambdaCDM(H0, Om0)
         logger.info(
             'Cosmology: H0 = %.1f %s, Om0 = %.3f' %
             (self.cosmology.H0.value, self.cosmology.H0.unit.to_string(),
              self.cosmology.Om0))
     except KeyboardInterrupt:
         raise uf.exit(self)
     except SystemExit:
         raise uf.exit(self)
     except:
         logger.error('There was a problem with entering the cosmology.',
                      exc_info=True)
         uf.earlyexit(self)
     return
예제 #5
0
	def determineBins(self, config):

		if self.config == True:
			self.fullfuncnum = config['FittedFunctionNumbers']
			self.fulloptnum = config['AnalysisOptions']
			self.fullsmoothtype = config['SmoothType']
			self.fullsmoothwin = config['SmoothWindow']
			self.fullmaxgalw = config['IntegrateGalaxyWidth']
			self.fullrebinstatus = config['SmoothStatus']
		else:
			pass

		if uf.checkkeys(config, 'BinInfo') and uf.checkkeys(config, 'Bins'):
			colname, binwidth, binstart, binend = config["BinInfo"]
			self.bins = config['Bins']			
			self.binnedtable, self.binpartindicies = self.__bintable(self.fullcatalogue, colname, binwidth, binstart, binend)
			return
		else:
			print ('\n%s\t%s\t%s\t%s\t%s\n'%(self.fullcatalogue.colnames[0], self.fullcatalogue.colnames[1], self.fullcatalogue.colnames[2], self.fullcatalogue.colnames[3], self.fullcatalogue.colnames[4]))
			colname = raw_input('Please enter the exact Column name for the column containing the data to be binned: ')
			binwidth = input('Please enter the bin width (in same units as the data to be binned): ')
			binstart = input('Please enter the start of the bin range (in same units as the data to be binned): ')
			binend = input('Please enter the end of the bin range (in same units as the data to be binned): ')
			self.binnedtable, self.binpartindicies = self.__bintable(self.fullcatalogue, colname, binwidth, binstart, binend)
			return
예제 #6
0
파일: inputData.py 프로젝트: kmhess/HISS
 def __getMaxLenSpectrum(self, config):
     try:
         if uf.checkkeys(config, 'StackedSpectrumLength'):
             maxstackw = config['StackedSpectrumLength'] * astun.km / astun.s
         else:
             maxstackw = input(
                 'Please enter the maximum length of the stacked spectrum in km/s: '
             ) * astun.km / astun.s
         if maxstackw < 2.5 * self.maxgalw:
             print(
                 'The stacked spectrum length is too short - we will not be able to have very good noise calculations, etc. Please try again.\n'
             )
             self.__getMaxLenSpectrum(config=None)
         else:
             self.maxstackw = maxstackw
         logger.info(
             'Length of stacked spectrum: %i %s' %
             (self.maxstackw.value, self.maxstackw.unit.to_string()))
     except (KeyboardInterrupt, SystemExit):
         uf.exit(self)
     except:
         logger.error(
             'Could not determine the maximum length of the stacked spectrum.',
             exc_info=True)
         uf.earlyexit(self)
예제 #7
0
파일: inputData.py 프로젝트: kmhess/HISS
 def __getStackUnits(self, config):
     try:
         if uf.checkkeys(config, 'StackFluxUnit'):
             choice = config['StackFluxUnit']
         else:
             print(
                 "\nWhat units do you want your final stacked profile to have?\n\t1. Jansky (Jy)\n\t2. Solar Masses (Msun)\n\t3. Gas Fraction (Msun/Msun)\n\t4. Solar Masses (Msun), stack in Jy [recommend for clusters]"
             )
             choice = eval(
                 input('Please enter the number of the applicable units: '))
             print(type(choice))
         if (type(choice) != int):
             print('Please only select one unit.')
             self.__getStackUnits(None)
         else:
             options = [astun.Jy, uf.msun, uf.gasfrac, astun.Jy]
             self.stackunit = options[int(choice - 1)]
             if choice == 4:
                 self.cluster = True
             else:
                 pass
     except KeyboardInterrupt:
         raise uf.exit(self)
     except SystemExit:
         raise uf.exit(self)
     except:
         logger.error('There was an input error with your unit selection.',
                      exc_info=True)
         uf.earlyexit(self)
     return
예제 #8
0
파일: inputData.py 프로젝트: kmhess/HISS
 def __getWeightingScheme(self, config):
     try:
         if uf.checkkeys(config, 'WeightOption'):
             self.weighting = str(config['WeightOption'])
         else:
             print(
                 '\nThe following are options can be used to weight each spectrum:\n\t1. w = 1. [default]\n\t2. w = 1/rms \n\t3. w = 1/rms^2 \n\t4. w = dl^2/rms^2'
             )
             ## TODO: add in option for individual weights from catalogue as well as custom weighting function
             weights = input(
                 'Please enter the number of the scheme you would like to use: '
             )
             self.weighting = weights[0]
         wghts = {
             '1': 'w = 1',
             '2': 'w = 1/rms',
             '3': 'w = 1/rms^2',
             '4': 'w = dl^2/rms^2'
         }
         logger.info('Weighting factor: %s' % wghts[self.weighting])
     except KeyboardInterrupt:
         raise uf.exit(self)
     except SystemExit:
         raise uf.exit(self)
     except:
         logger.error('Could not identify the weighting scheme.',
                      exc_info=True)
         uf.earlyexit(self)
예제 #9
0
파일: inputData.py 프로젝트: kmhess/HISS
 def __getSpectraLocation(self, config):
     try:
         if uf.checkkeys(config, 'SpectrumLocation'):
             self.specloc = config['SpectrumLocation']
         else:
             self.specloc = input(
                 'Please enter the full path of the spectra location: ')
         if self.specloc[-1] != '/':
             self.specloc += '/'
         else:
             h = 0
         if not os.path.exists(self.specloc):
             print(
                 '\nThe spectrum location you have entered does not exist. Please try again.\n'
             )
             self.__getSpectraLocation(config=None)
         else:
             print('\nThe spectrum location exists :).\n')
     except KeyboardInterrupt:
         raise uf.exit(self)
     except SystemExit:
         uf.exit(self)
     except:
         logger.error(
             'There was an issue with the entered spectrum folder path.',
             exc_info=True)
         uf.earlyexit(self)
예제 #10
0
	def __checkConfig(self, config):
		if uf.checkkeys(config, 'IntegrateGalaxyWidth'):
			intwid = True
			self.maxgalw = config['IntegrateGalaxyWidth']*astun.km/astun.s
		else: 
			intwid = False

		if uf.checkkeys(config, 'SmoothStatus'):
			self.rebinstatus = config['SmoothStatus']
			rebin = True
		else: 
			rebin = False

		if uf.checkkeys(config, 'SmoothType'):
			self.smoothtype = config['SmoothType']
		else: pass

		if uf.checkkeys(config, 'SmoothWindow'):
			self.smoothwin = config['SmoothWindow']
		else: pass

		if uf.checkkeys(config, 'FittedFunctionNumbers'):
			self.funcnum = config['FittedFunctionNumbers']
		else: pass

		if uf.checkkeys(config, 'AnalysisOptions'):
			self.optnum = config['AnalysisOptions']
		else: pass

		if (intwid == True) and (rebin == True):
			self.config = True
		else:
			self.config = False

		return
예제 #11
0
	def __getSpectrumDelimiter(self, config):
		try: 
			if uf.checkkeys(config, 'RowDelimiter'): 
				self.rowdelim = config['RowDelimiter']
			else:
				self.rowdelim = input('Please enter the delimiter used in the spectra files (this must be the same for all spectra): ')
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			uf.exit(self)
		except:
			logger.error('There was an error with the row delimiter.', exc_info=True)
			uf.earlyexit(self)
예제 #12
0
	def __getMaxRedshift(self, config):
		try:
			if uf.checkkeys(config, 'z_max'):
				self.max_redshift = config["z_max"]
			else:
				self.max_redshift = input('\nPlease enter the maximum redshift value of your sample: ')
		except KeyboardInterrupt:
			uf.earlyexit(self)
		except SystemExit:
			uf.exit(self)
		except:
			logger.critical("There was an error with the maximum redshift value.", exc_info=True)
			uf.earlyexit(self)
예제 #13
0
	def __getChannelWidth(self, config):
		try:
			if uf.checkkeys(config, 'ChannelWidth'):
				self.channelwidth = config['ChannelWidth'] * self.spectralunit
			else:
				self.channelwidth = input('Please enter the channel width (in the same units as the spectral axis): ') * self.spectralunit
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			uf.exit(self)
		except:
			logger.error('There was an input error with your channel width.', exc_info=True)
			uf.earlyexit(self)
예제 #14
0
	def __getMaxGalaxyWidth(self, config):
		try:
			if uf.checkkeys(config, 'GalaxyWidth'):
				self.maxgalw = config['GalaxyWidth'] * astun.km/astun.s
			else:
				self.maxgalw = input('Enter maximum galaxy width in km/s: ') * astun.km/astun.s
			logger.info('Maximum galaxy width = %i %s'%(self.maxgalw.value, self.maxgalw.unit.to_string()))
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			raise uf.exit(self)
		except:
			logger.error("Did not understand the maximum galaxy width.", exc_info=True)
			uf.earlyexit(self)
예제 #15
0
	def __getSpectrumRowStart(self, config):
		try:
			if uf.checkkeys(config, 'FirstRowInSpectrum'):
				self.rowstart = int(config['FirstRowInSpectrum'])
			else:
				self.rowstart = input('Please enter the row number corresponding to the start of the data in the spectrum files (this number should be the same for every spectrum file).\n(Please note: row numbering starts at 1 - the first row of information is row 1): ')
				self.rowstart = int(self.rowstart)
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			uf.exit(self)
		except:
			logger.error('There was an error with the number of the first row in the spectrum files.', exc_info=True)
			uf.earlyexit(self)
예제 #16
0
	def __getUncertType(self, config):
		try:
			if uf.checkkeys(config, 'UncertaintyMethod'):
				self.uncerttype = config['UncertaintyMethod']
			else:
				untyp = input('Which method of redshift uncertainties should I use? [dagjk/redshift] ')
				uncertop = { 'r': 'redshift', 'd': 'dagjk' }
				self.uncerttype = uncertop[(untyp.lower())[0]]
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			raise uf.exit(self)
		except: 
			logger.error('There was a problem determining whether or not to perform an uncertainty analysis', exc_info=True)
			uf.earlyexit(self)
예제 #17
0
	def __getSpectrumColumns(self, config):
		try:
			if uf.checkkeys(config, 'SpectrumColumns'):
				self.speccol = config['SpectrumColumns']
			else:
				self.speccol = input("Please enter the column numbers of the spectral axis and flux (the column number of the first column is 0).\nThe numbers should be separated by a ',' e.g. 0,1: ")
			if len(self.speccol) != 2:
				print ('You need to enter two column numbers. Please try again.\n')
				self.__getSpectrumColumns(config=False, data=None)
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit():
			raise uf.exit(self)
		except:
			logger.error('There was an error with the spectrum column numbers.', exc_info=True)
			uf.earlyexit(self)
예제 #18
0
	def __getUncertAn(self, config):
		try:
			if uf.checkkeys(config, 'UncertaintyYN'):
				self.uncert = config['UncertaintyYN']
			else:
				self.uncert = input('Should I calculate uncertainties? ')

			if self.uncert.lower() == 'n':
				self.mc = 1
			else:
				self.mc = self.mc
		except KeyboardInterrupt:
			raise uf.exit(self)
		except SystemExit:
			raise uf.exit(self)
		except: 
			logger.error('There was a problem determining whether or not to perform an uncertainty analysis.')
			uf.earlyexit(self)
예제 #19
0
	def __getOutputLocation(self, config):
		try:
			if uf.checkkeys(config, 'OutputLocation'):
				self.outloc = config['OutputLocation']
			else:
				self.outloc = input('Enter the full location to where you would like the output saved: ')
			if self.outloc[-1] != '/':
				self.outloc +='/'
				uf.checkpath(self.outloc)
			else:
				uf.checkpath(self.outloc)
			logger.info('Output location: %s'%self.outloc)
		except KeyboardInterrupt:
			uf.exit(self)
		except SystemExit:
			uf.exit(self)
		except:
			print ('There was a problem with entering the output location. Please try again.\n')
			self.__getOutputLocation(config=False, data=None)
예제 #20
0
def pipeline(cat, config, data, binstatus, binno=None, mccount=0):
    disp, spectrum, stackspectrum, analysis, analysisfinal = None, None, None, None, None

    fig, ax1, ax2, ax3, ax4 = startfigure(cat)

    if cat.progress == 'progress':
        plt.show(block=False)
    else:
        pass

    ## creating the stack objects
    xs = cat.spectralaxis.value[0]
    xe = cat.spectralaxis.value[-1]

    if uf.checkkeys(data, 'StackEntireCatalogueYN'):
        stacknoYN = data['StackEntireCatalogueYN']
    else:
        stacknoYN = raw_input(
            'Do you want to stack your entire catalogue? [y/n] ')

    if stacknoYN.lower() == 'y':
        stackobj = len(cat.catalogue)
    else:
        if uf.checkkeys(data, 'NumberCatalogueObjects'):
            stackobj = int(data['NumberCatalogueObjects'])
        else:
            stackobj = None
            while type(stackobj) != int:
                stackobj = int(
                    input(
                        'Please enter the number of profiles you want to stack: '
                    ))
        if stackobj > cat.numcatspec:
            stackobj = len(cat.catalogue)
        else:
            h = 0
        logging.info('Number of objects going into the stack: %i' % stackobj)

    if cat.uncert == 'y' and mccount == 0:
        if binstatus == 'bin':
            print('\nProgress of first round of Bin %i: ' % binno)
            logging.info('Starting first round of Bin %i.' % binno)
        else:
            print('\nProgress of first round: ')
            logging.info('Starting stacking first round.')
    elif cat.uncert == 'n':
        if binstatus == 'bin':
            print('\nStacking progress of Bin %i: ' % binno)
            logging.info('Starting stacking of Bin %i.' % binno)
        else:
            print('\nStacking progress: ')
            logging.info('Starting stacking.')
    else:
        h = 0

    pbar = ''
    if ((mccount == 0) or ((mccount == 1)) and (binstatus == 'bin')):
        cat, analysisfinal = stackeverything(pbar, cat, stackobj, binstatus,
                                             'firstcall', binno, mccount, fig,
                                             ax1, ax2, ax3, ax4)
    else:
        h = 0

    if mccount == 0 and cat.uncert == 'y' and binstatus == 'bin':
        logging.info('Finished stacking first round of Bin %i.' % binno)
        return cat
    else:
        disp = DD.dispData(cat)
        mccount += 1
        if cat.uncert == 'y':
            if binstatus == 'bin':
                print('\n\nUncertainty calculations of Bin %i in progress:' %
                      binno)
            else:
                print('\n\nUncertainty calculations in progress:')
            pbar = ''
            if cat.multiop == 'multi':
                results = []
                cpu_count = int(multi.cpu_count() / 2)
                logging.info(
                    'Spawning %i processes to run uncertainty calculations.' %
                    cpu_count)
                pool = multi.Pool(processes=cpu_count, maxtasksperchild=1)
            else:
                h = 0
            analysisempty = UA.uncertAnalysis(cat,
                                              analysisfinal,
                                              allspec=[],
                                              allnoise=[],
                                              allrms=[],
                                              middle=[],
                                              allintflux=np.array([[], [], [],
                                                                   [], [], [],
                                                                   [], []]))
            mccount = 1
            suppress = cat.suppress
            cat.suppress = 'hide'
            fullcatfile = cat.catalogue
            logging.info('Starting uncertainty calculations...')
            while mccount < (cat.mc + 1):
                if cat.uncerttype == 'dagjk':
                    indices = np.random.randint(low=0,
                                                high=(len(fullcatfile) - 1),
                                                size=int(cat.R *
                                                         len(fullcatfile)))
                    cat.catalogue = fullcatfile[indices]
                    if stackobj > len(cat.catalogue):
                        stackobj = len(cat.catalogue)
                    else:
                        h = 0
                else:
                    h = 0
                if mccount > 0 and cat.multiop != 'multi':
                    frac = int((mccount) / (cat.mc * 2.) * 100.)
                    if frac < 2:
                        frac = 0
                    else:
                        h = 0
                    pbar = uf.progressbar(frac, pbar)
                    cat = stackeverything(pbar,
                                          cat,
                                          stackobj,
                                          binstatus,
                                          'uncertcall',
                                          binno,
                                          mccount,
                                          fig,
                                          ax1,
                                          ax2,
                                          ax3,
                                          ax4,
                                          analysisfinal=analysisfinal)
                else:
                    result = pool.apply_async(
                        stackeverything,
                        args=(pbar, cat, stackobj, binstatus, 'uncertcall',
                              binno, mccount, fig, ax1, ax2, ax3, ax4,
                              analysisfinal))
                    results.append(result)
                mccount += 1
            if cat.multiop == 'multi':
                pool.close()
                pbar = ''
                for n in range(cat.mc):
                    frac = int((n + 1.) / cat.mc * 100.)
                    if frac < 2:
                        frac = 0
                    else:
                        h = 0
                    pbar = uf.progressbar(frac, pbar)
                    results[n].get()
                    analysisfinal = analysisfinal + analysisempty.load(
                        n + 1, cat)
            else:
                for n in range(1, cat.mc + 1, 1):
                    frac = int(float(cat.mc + n) / (cat.mc * 2.) * 100.)
                    pbar = uf.progressbar(frac, pbar)
                    analysisfinal = analysisfinal + analysisempty.load(n, cat)

            cat.suppress = suppress
            analysisfinal.ProcessUncertainties(cat)
            pck.dump(
                analysisfinal,
                open('%sstackedresultsobj_%s.pkl' % (cat.outloc, cat.runtime),
                     'wb'))
            disp.display(cat, analysisfinal.allintflux,
                         [analysisfinal.middle, analysisfinal.allrms],
                         args.suppress)
        else:
            disp.display(cat, None, cat.suppress)
        return cat
예제 #21
0
def main():

    fullcat = ID.inputCatalogue(runtime)

    fullcat.runInput(data)
    fullcat.clean = args.clean
    fullcat.suppress = args.suppress
    fullcat.progress = args.progress
    fullcat.saveprogress = args.saveprogress
    fullcat.multiop = args.multiop
    fullcat.latex = args.latex

    ## create a temp file for all object files
    uf.checkpath('%sstackertemp/' % fullcat.outloc)
    if uf.checkkeys(data, 'BinYN'):
        binyn = data["BinYN"]
    else:
        binyn = raw_input(
            '\nWould you like to stack in various bins? [y/n] ').lower()

    if binyn == 'y':
        bincatalogue = BD.binnedCatalogue(fullcat)
        try:
            bincatalogue.determineBins(data)
        except (SystemExit, KeyboardInterrupt):
            uf.exit(fullcat)
        except:
            logging.warning(
                "Couldn't determine the catalogue for the different bins:",
                exc_info=True)
            uf.earlyexit(fullcat)

        if fullcat.uncert == 'y':
            repeat = 2
        else:
            repeat = 1

        counter = 0
        while counter < repeat:
            mccount = counter
            for m in range(0, len(bincatalogue.binpartindicies) - 1):
                if counter > 0:
                    bincatalogue = pck.load(
                        open(
                            '%sstackertemp/catalogue_obj.pkl' % fullcat.outloc,
                            'rb'))
                else:
                    h = 0
                try:
                    bincatalogue.createCatalogue(bincatalogue.binpartindicies,
                                                 bincatalogue.binnedtable, m,
                                                 counter)
                except KeyboardInterrupt:
                    uf.earlyexit(cat)
                    raise sys.exit()
                except SystemExit:
                    uf.earlyexit(cat)
                    raise sys.exit()
                except:
                    logger.error(
                        'Exception occurred trying to create the binned catalogue.',
                        exc_info=True)
                    uf.earlyexit(cat)
                    raise sys.exit()

                if len(bincatalogue.catalogue) < 2:
                    h = 0
                else:

                    catalogue = pipeline(bincatalogue, config, data, 'bin',
                                         m + 1, mccount)
                    if counter == 0:
                        bincatalogue = bincatalogue + catalogue
                    else:
                        h = 0
            if counter == 0:
                bincatalogue.outcatalogue[
                    'Stellar Mass'].unit = bincatalogue.fullcatalogue[
                        'Stellar Mass'].unit
                bincatalogue.outcatalogue[
                    'Other Data'].unit = bincatalogue.fullcatalogue[
                        'Other Data'].unit
                bincatalogue.outcatalogue[
                    'Integrated Flux'].unit = astun.Jy * astun.km / astun.s

                pck.dump(
                    bincatalogue,
                    open(
                        '%sstackertemp/catalogue_obj.pkl' %
                        bincatalogue.outloc, 'wb'))

                catalogue = uf.maskTable(bincatalogue.outcatalogue)
                catalogue = asttab.unique(catalogue, keys='Object ID')
                catalogue.sort('Bin Number')
                astasc.write(
                    catalogue,
                    bincatalogue.outloc +
                    'Stacked_Catalogue_%s.csv' % bincatalogue.origruntime,
                    format='ecsv')
                fullcat.updateconfig(data, bincatalogue.fullmaxgalw,
                                     bincatalogue.fullrebinstatus,
                                     bincatalogue.fullsmoothtype,
                                     bincatalogue.fullsmoothwin,
                                     bincatalogue.fullfuncnum,
                                     bincatalogue.fulloptnum)
            else:
                h = 0
            saveprogress = None
            counter += 1
    else:
        fullcat.catalogue.add_column(
            asttab.Column(name='Bin Number',
                          data=np.ones(len(fullcat.catalogue), dtype=int)))
        fullcat = pipeline(fullcat, config, data, 'normal')
        try:
            fullcat.updateconfig(data, fullcat.maxgalw.value,
                                 fullcat.rebinstatus, fullcat.smoothtype,
                                 fullcat.smoothwin, fullcat.funcnum,
                                 fullcat.optnum)
            fullcat.outcatalogue['Stellar Mass'].unit = fullcat.catalogue[
                'Stellar Mass'].unit
            fullcat.outcatalogue['Other Data'].unit = fullcat.catalogue[
                'Other Data'].unit
            fullcat.outcatalogue[
                'Integrated Flux'].unit = astun.Jy * astun.km / astun.s
            catalogue = uf.maskTable(fullcat.outcatalogue)
            catalogue = asttab.unique(catalogue, keys='Object ID')
            catalogue.sort('Bin Number')
            astasc.write(catalogue,
                         fullcat.outloc +
                         'Stacked_Catalogue_%s.csv' % fullcat.runtime,
                         format='ecsv')
            logging.info('Written Stacked Catalogue to file.')
        except (SystemExit, KeyboardInterrupt):
            uf.exit(fullcat)
        except:
            logging.warning("Struggled to save the catalogue files.",
                            exc_info=True)
            uf.earlyexit(fullcat)

    ## inform the user that the stacking has finished
    if fullcat.suppress != 'hide':
        outloc = uf.bashfriendlypath(fullcat.outloc)
        os.system('open ' + outloc)
    else:
        h = 0

    print('\nStacker has finished.\n')
    uf.exit(fullcat)
    return
예제 #22
0
파일: inputData.py 프로젝트: kmhess/HISS
    def __get_astropy_catalogue(self, config):
        print("Initialising the catalogue file.")
        logger.info('Initialising the catalogue file.')

        if uf.checkkeys(config, 'CatalogueFilename'):
            self.catfilename = config['CatalogueFilename']
        else:
            self.catfilename = input(
                'Enter location and filename of catalogue file: ')
        while not os.path.isfile(self.catfilename):
            print(
                'The catalogue filename and location you have given does not exist.\n'
            )
            self.catfilename = input(
                'Enter location and filename of catalogue file: ')
        try:
            filetable = astasc.read(
                self.catfilename
            )  # [, format='csv'] took out 10/01/19 when line crashed with .dat on JD system
        except KeyboardInterrupt:
            uf.earlyexit(self)
            raise sys.exit()
        except:
            print(
                "Did not recognise the catalogue data type. Please check that your catalogue file is in the same format as the example catalogue file."
            )
            logger.critical("Did not recognise the catalogue file data type.")
            raise sys.exit()

        if uf.checkkeys(config, 'CatalogueColumnNumbers'):
            catcols = config['CatalogueColumnNumbers']
        else:
            catcols = None
            filetablenames = filetable.colnames
            print('\nThe following columns are available:')
            for u in range(len(filetablenames)):
                print('%i: %s' % (u, filetablenames[u]))

        colnames = [
            'Object ID', 'Filename', 'Redshift', 'Redshift Uncertainty',
            'Stellar Mass', 'Other Data'
        ]
        catalogue = asttab.Table(names=['Dud'],
                                 dtype=['f8'],
                                 masked=True,
                                 data=[np.zeros(len(filetable))])

        for o in range(len(colnames)):
            try:
                self.__fill_catalogue(catalogue, filetable, colnames[o], o,
                                      catcols)
            except KeyboardInterrupt:
                uf.earlyexit(self)
            except SystemExit():
                uf.earlyexit(self)
                raise sys.exit()
            except:
                print(
                    'There was problem with entering the column number, please try again.\n'
                )
                self.__fill_catalogue(catalogue, filetable, colnames[o], o,
                                      None)
        catalogue.remove_column('Dud')

        ## check units of the stellar mass
        if True in catalogue['Stellar Mass'].mask:
            if self.stackunit == uf.gasfrac:
                print(
                    "\nTo stack in gas fraction, the catalogue file must include the Stellar Mass for each profile."
                )
                logger.info(
                    'To stack in gas fraction, the catalogue file must include the Stellar Mass for each profile.'
                )
                uf.earlyexit(self)
        else:
            checkval = str(int(catalogue['Stellar Mass'][0]))
            if len(checkval) < 3:
                catalogue['Stellar Mass'].unit = astun.dex * uf.msun
            else:
                catalogue['Stellar Mass'].unit = uf.msun

            self.avesm = np.mean(catalogue['Stellar Mass'].data
                                 ) * catalogue['Stellar Mass'].unit

        uniquecatalogue = asttab.unique(catalogue, keys='Object ID')
        self.catalogue = uniquecatalogue
        self.medianz = np.median(self.catalogue['Redshift'].data)
        logger.info('Catalogue has been read in.')

        return