Beispiel #1
0
def handle_scatter_errs(xVar_packet, yVar_packet, quasar_array):
    xVar, yVar = xVar_packet[0], yVar_packet[0]
    logx, logy = xVar_packet[2], yVar_packet[2]
    xVar_err = get_xVar_err(xVar)
    if xVar_err is None:
        xerrs = None
    yVar_err = get_xVar_err(yVar)
    if yVar_err is None:
        yerrs = None

    if xVar_err is not None:
        xerrs = np.empty(len(quasar_array), dtype=object)
        for i, l in enumerate(quasar_array):
            xerrs[i] = np.zeros(len(l))
            for j, q in enumerate(l):
                if xVar in param_xVars:
                    xerrs[i][j] = eval('q.%s' % xVar_err)
                elif string_represents_ion(xVar):
                    xerrs[i][j] = q.get_ion_values(xVar_err)[0]
                xerrs[i][j] = np.log10(
                    xerrs[i][j]) if logx and xerrs[i][j] > 0 else xerrs[i][j]
    if yVar_err is not None:
        yerrs = np.empty(len(quasar_array), dtype=object)
        for i, l in enumerate(quasar_array):
            yerrs[i] = np.zeros(len(l))
            for j, q in enumerate(l):
                if yVar in param_xVars:
                    yerrs[i][j] = eval('q.%s' % yVar_err)
                elif string_represents_ion(yVar):
                    yerrs[i][j] = q.get_ion_values(yVar_err)[0]
                yerrs[i][j] = np.log10(
                    yerrs[i][j]) if logy and yerrs[i][j] > 0 else yerrs[i][j]
    return xerrs, yerrs
Beispiel #2
0
 def impose_requirements(self,filter_for,qtype,verbose=False):
     if verbose and filter_for != []:
         print('Restricting quasars of type "%s" to ones containing %s'%(qtype,filter_for))
     ion_constraints = []
     gasbin_constraints = []
     metadata_constraints = []
     for item in filter_for:
         if ':' in item:
             ion_name = item.split(':')[0]
             gasbin_name = item.split(':')[1]
             if gasbin_name in ['cdens','fraction','eb']:
                 continue
             assert utils.string_represents_ion(ion_name)
             ion_constraints.append(ion_name)
             gasbin_constraints.append(gasbin_name)
         elif utils.string_represents_ion(item):
             ion_constraints.append(item)
         elif item in param_xVars:
             metadata_constraints.append(item)
     before_filter = self.get_qlist(qtype)
     self.constrain_current_quasar_array('ions',ion_constraints,qtype=qtype)
     self.constrain_via_gasbins(gasbin_constraints)
     for item in metadata_constraints:
         self.constrain_current_quasar_array(item,qtype=qtype,change_array_name=False)
     return before_filter
Beispiel #3
0
def get_xVar_err(xVar):
    if len(split_by_ops(xVar)) > 1:
        return None
    if ':' in xVar:
        if len(xVar.split(':')) == 2 and xVar.split(':')[1] == 'cdens' and \
                        string_represents_ion(xVar.split(':')[0]):
            return xVar.split(':')[0] + ':eb'
        else:
            return None
    if string_represents_ion(xVar):
        return xVar + ':eb'
    elif xVar in param_xVars:
        return xVar + '_eb'
    else:
        return None
 def get_ion_column_num(self,ion):
     if ':' not in ion and string_represents_ion(ion):
         ion = ion+':cdens'
     if ion in self.ion_list_w_bins:
         return self.ion_list_w_bins.index(ion)
     else:
         raise IonNotFoundError('Ion %s not found in this Sphere, which is %s. Available ions are: %s and sorted into bins: %s'%(ion,self.fullname,self.ions,self.gasbins.get_all_keys()))
    def __init__(self, fullname, header, line_from_file):
        self.type = 'obs'
        self.code = 'obs'
        self.number = 1
        self.length = 1
        self.length_reached = 1
        self.gasbins = GasBinsHolder(bins=None)
        parsed_line = line_from_file.split(",")
        header_columns_dict = get_header_columns_dict(header)
        temp = header_columns_dict.keys()
        ions = []
        for key in temp:
            if ':' in key:
                ion, modifier = key.split(':')
                if string_represents_ion(ion) and ion not in ions:
                    ions.append(ion)
        self.ions = ions

        iondata = []
        for ion in self.ions:
            iondata.append(
                access_obs_data_values('%s:cdens' % ion, header_columns_dict,
                                       parsed_line))
            iondata.append(
                access_obs_data_values('%s:eb' % ion, header_columns_dict,
                                       parsed_line))
        self.info = np.array(
            [[-1, -1, -1] +
             [access_obs_data_values('r', header_columns_dict, parsed_line)] +
             [-1, -1, -1, -1, -1, -1, -1] + iondata + [-1, -1, -1]])

        redshift = access_obs_data_values('z', header_columns_dict,
                                          parsed_line)
        self.Rvir = access_obs_data_values('Rvir', header_columns_dict,
                                           parsed_line)
        self.a = 1. / (redshift + 1)
        self.Mvir = 4. / 3 * np.pi * self.Rvir**3 * (
            200 * 1.5e-7)  #crit_dens = 1.5e-7 M⊙ pc-3
        self.Mstar = access_obs_data_values('Mstar', header_columns_dict,
                                            parsed_line)
        self.Mstar_eb = access_obs_data_values('Mstar:eb', header_columns_dict,
                                               parsed_line)
        self.sfr = access_obs_data_values('sfr', header_columns_dict,
                                          parsed_line)
        self.sfr_eb = access_obs_data_values('sfr:eb', header_columns_dict,
                                             parsed_line)
        self.ssfr = self.sfr / self.Mstar
        self.ssfr_eb = self.sfr_eb / self.Mstar

        super().__init__(fullname, redshift)
        self.author = self.version

        for param in param_xVars:
            if param not in self.__dict__.keys():
                self.__dict__[param] = np.nan