def update_lines(OVN_dic=OVN_dic, MdB=None): if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) lines_tab = MdB.get_fields(OVN_dic['master_table']) lines_temis = MdB.get_fields(OVN_dic['temis_table']) for line in lines_list: if line[0] not in lines_tab: command = 'ALTER TABLE {0} ADD `{1}` double NOT NULL DEFAULT 0;'.format( OVN_dic['master_table'], line[0]) MdB.exec_dB(command) print('Adding line {0}'.format(line[0])) if line[0] + '_rad' not in lines_tab: command = 'ALTER TABLE {0} ADD `{1}_rad` double NOT NULL DEFAULT 0;'.format( OVN_dic['master_table'], line[0]) MdB.exec_dB(command) print('Adding line {0}_rad'.format(line[0])) if 'T_{0}'.format(line[0]) not in lines_temis: command = 'ALTER TABLE {0} ADD `T_{1}` double NOT NULL DEFAULT 0;'.format( OVN_dic['temis_table'], line[0]) MdB.exec_dB(command) lines_temis = MdB.get_fields(OVN_dic['temis_table']) for line in lines_temis: line_label = line[2:] if line_label not in [l[0] for l in lines_list]: print('Line to be removed: {0}'.format(line))
def init_tab(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['master_table'] if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = "CREATE TABLE IF NOT EXISTS {0} (".format(table) command += fields1 for elem in elem_list: command += '`{0}` double NOT NULL DEFAULT -40,'.format(elem[0]) for line in lines_list: command += "`{0[0]}` double NOT NULL DEFAULT 0, ".format(line) command += "`{0[0]}_rad` double NOT NULL DEFAULT 0, ".format(line) command += fields2 command += """PRIMARY KEY (`N`), KEY `ref` (`ref`), KEY `user` (`user`), KEY `atm_file` (`atm_file`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; """ MdB.exec_dB(command) MdB.close_dB()
def init_pending(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['pending_table'] if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = "CREATE TABLE IF NOT EXISTS {0} (".format(table) command += fields1 for elem in elem_list: command += '`{0}` double NOT NULL DEFAULT -40,'.format(elem[0]) command += """`priority` int(11) DEFAULT 10, `procID` bigint(20) DEFAULT -1, `lock` int(11) DEFAULT 0, PRIMARY KEY (`N`), KEY `status` (`status`), KEY `priority` (`priority`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; """ MdB.exec_dB(command) MdB.close_dB()
def init_lines(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['lines_table'] if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = """CREATE TABLE IF NOT EXISTS {0} ( `Nl` bigint(20) NOT NULL AUTO_INCREMENT, `label` varchar(15) DEFAULT NULL, `id` varchar(20) DEFAULT NULL, `lambda` double DEFAULT NULL, `name` varchar(40) NOT NULL, `used` int(2) DEFAULT 1, PRIMARY KEY (`Nl`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; """.format(table) MdB.exec_dB(command) command = 'INSERT INTO {0} (`label`, `id`, `lambda`, `name`) VALUES '.format( table) for line in lines_list: command += "('{0[0]}', '{0[1]}', {0[2]}, '{0[3]}'), ".format(line) command = command[:-2] command += ';' MdB.exec_dB(command) MdB.close_dB()
def make_CALIFA_dB(): """ Create the pending entries to run individual grids of models corresponding to the CALIFA ages and metallicities. """ ff = 1.0 c = pc.CST.CLIGHT MdB = pc.MdB(OVN_dic) wP = use3MdB.writePending(MdB, OVN_dic) wP.set_ref("CALIFA") wP.set_user("Christophe") wP.set_file('CALIFA') wP.set_dir('CALIFA') wP.set_priority(4) wP.set_cloudy_others(('no molecules', 'no level2 lines', 'no fine opacities', 'COSMIC RAY BACKGROUND')) wP.set_iterate(1) wP.set_N_Hb_cut(4) wP.set_C_version('17.01') wP.set_geometry('Sphere') wP.set_stop(('temperature 200', 'pfrac 0.05')) all_tabs = [(lU_mean, met, dNO, age, fr, NH) for lU_mean in tab_lU_mean for met in uniq_mets for dNO in tab_dNO for age in uniq_ages for fr in tab_fr for NH in tab_NH] for lU_mean, met, dNO, age, fr, NH in all_tabs: U_mean = 10**lU_mean w = (1 + fr**3.)**(1. / 3) - fr Q0 = 4. * np.pi * c**3 * U_mean**3 / (3. * NH * ff**2 * alpha_B**2 * w**3) R_str = (3. * Q0 / (4 * np.pi * NH**2 * alpha_B * ff))**(1. / 3) R_in = fr * R_str wP.set_radius(r_in=np.log10(R_in)) wP.set_cste_density(dens=np.log10(NH)) coeff_met = met / 0.019 abunds = selected_abunds.copy() for elem in abunds: if elem != 'He': abunds[elem] += np.log10(coeff_met) abunds['N'] += dNO wP.set_abund(ab_dict=abunds) xt = 7.96 x = 12 + abunds['O'] if x > xt: y = 2.21 + 1.00 * (8.69 - x) else: y = 0.68 + 3.08 * (8.69 - x) Draine_fact = 2. / 3. # Draine 2001, wP.set_dust('ism {0}'.format(Draine_fact * 10**(2.21 - y))) wP.set_comments( ('lU_mean = {0}'.format(lU_mean), 'fr = {0}'.format(fr), 'age = {0}'.format(age), 'met = {0}'.format(met), 'NO = {0}'.format(dNO), 'NH = {0}'.format(NH))) wP.set_star('table stars \"sp_cha.mod\" ', age * 1e9, np.log10(met), lumi_unit='q(H)', lumi_value=np.log10(Q0)) wP.insert_model() MdB.close_dB()
def set_grid(): MdB = pc.MdB(OVN_dic) models_dir = 'TEST1/' name = 'test_2' options = ( 'no molecules', 'no level2 lines', 'no fine opacities', 'COSMIC RAY BACKGROUND', ) wP = use3MdB.writePending(MdB, OVN_dic) wP.set_ref(name) wP.set_user('Test') wP.set_C_version('17.01') wP.set_iterate(1) wP.set_file(name) wP.set_dir(models_dir) wP.set_cloudy_others(options) wP.set_N_Hb_cut(4) wP.set_geometry('Sphere') wP.set_stop(('temperature 20', 'pfrac 0.02', 'zone 10')) # Starting the main loop on the 4 parameters. for age in 1e6 * (1 + np.arange(200) / 100): wP.set_priority(5) wP.set_radius(r_in=18) wP.set_cste_density(dens=2) ab_O = -3.5 abund = { 'He': -1, 'C': -4, 'N': ab_O - 1, 'O': ab_O, 'Ne': ab_O - 0.73, 'Mg': ab_O - 2.02, 'Si': ab_O - 2.02, 'S': ab_O - 1.66, 'Cl': ab_O - 3.54, 'Ar': ab_O - 2.32, 'Fe': ab_O - 1.83 } wP.set_abund(ab_dict=abund) wP.set_dust('ism 1') wP.set_distance(1.0) wP.set_star('table stars', atm_file='sp_cha.mod', atm1=age, atm2=-2.4, lumi_unit='q(H)', lumi_value=50) wP.insert_model()
def init_temis(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['temis_table'] if MdB is None: MdB = pc.MdB(OVN_dic = OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = "CREATE TABLE IF NOT EXISTS {0} (`N` bigint(20) NOT NULL DEFAULT '0',".format(table) command += "`ref` varchar(40) NOT NULL ," for line in lines_list: command += "`T_{0[0]}` double NOT NULL DEFAULT 0, ".format(line) command += "PRIMARY KEY (`N`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;" MdB.exec_dB(command) MdB.close_dB()
def post_processing(OVN_dic=OVN_dic): MdB = pc.MdB(OVN_dic) ref = 'PNe_2020' MdB.exec_dB( "update tab_17 set com6 = '' where ref like '{0}' ".format(ref)) MdB.exec_dB( "update tab_17 set com3 = 'R' where ref like '{0}' and MassFrac >= 0.95" .format(ref)) MdB.exec_dB( "update tab_17 set com3 = 'M80' where ref like '{0}' and MassFrac < 0.95 and MassFrac >= 0.7" .format(ref)) MdB.exec_dB( "update tab_17 set com3 = 'M60' where ref like '{0}' and MassFrac < 0.7 and MassFrac >= 0.5" .format(ref)) MdB.exec_dB( "update tab_17 set com3 = 'M40' where ref like '{0}' and MassFrac < 0.5 and MassFrac >= 0.3" .format(ref)) MdB.exec_dB( "update tab_17 set com3 = 'M20' where ref like '{0}' and MassFrac < 0.3" .format(ref)) MdB.exec_dB( "update tab_17 set cloudy5 = '1' where ref like '{0}' and lumi < 4.2 and (lumi > 3.4 or atm1 > 100000) and lumi > 1.5e-5*atm1-0.25" .format(ref)) MdB.exec_dB( "update tab_17 set cloudy6 = '1' where ref like '{0}' and H_mass < 1.0" .format(ref)) MdB.exec_dB( "update tab_17 join abion_17 on tab_17.N = abion_17.N set tab_17.cloudy7 = abion_17.A_HYDROGEN_vol_1 where tab_17.ref like '{0}'" .format(ref)) MdB.exec_dB( "update tab_17 set cloudy8 = '1' where ref like '{0}' and nH_mean * pow(10,rout*3) > 2e53 and nH_mean * pow(10, rout*3) < 3e56" .format(ref)) MdB.exec_dB( "update tab_17 set cloudy9 = '1' where ref like '{0}' and H__1_486133A/pow(4*3.1415967*pow(10,rout)*206265., 2) < 1e-11 and H__1_486133A/pow(4*3.1415967*pow(10,rout)*206265., 2) > 1e-15" .format(ref)) MdB.exec_dB( "update tab_17 set com6 = '1' where ref like '{0}' and cloudy5 = '1' and cloudy6 = '1' and cloudy8 = '1' and cloudy9 = '1' and MassFrac > 0.2" .format(ref)) MdB.exec_dB( "update tab_17 set com6 = '0' where ref like '{0}' and com6 != '1'". format(ref))
def init_teion(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['teion_table'] if MdB is None: MdB = pc.MdB(OVN_dic = OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = "CREATE TABLE IF NOT EXISTS {0} (`N` bigint(20) NOT NULL DEFAULT '0',".format(table) command += "`ref` varchar(40) NOT NULL ," for elem in elem_list: for i in range(elem[1]+1): command += "`T_{0}_vol_{1}` double NOT NULL DEFAULT '-40',".format(elem[0], i) command += "`T_{0}_rad_{1}` double NOT NULL DEFAULT '-40',".format(elem[0], i) command += "PRIMARY KEY (`N`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;" MdB.exec_dB(command) MdB.close_dB()
def init_procIDs(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['procIDs_table'] if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = """CREATE TABLE IF NOT EXISTS {0} ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `proc_name` varchar(80) NOT NULL, `datetime` datetime NOT NULL DEFAULT 0, `user` varchar(80) NOT NULL, `host` varchar(80) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; """.format(table) MdB.exec_dB(command) MdB.close_dB()
def init_SEDs(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['seds_table'] if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = """CREATE TABLE IF NOT EXISTS {0} ( `N` bigint(20) NOT NULL AUTO_INCREMENT, `ref` varchar(40) NOT NULL DEFAULT '', `sed_name` varchar(40) NOT NULL DEFAULT '', `atm_cmd` varchar(60) NOT NULL DEFAULT '', `atm_file` varchar(40) NOT NULL DEFAULT '', `atm1` double DEFAULT NULL, `atm2` double DEFAULT NULL, `atm3` double DEFAULT NULL, `lumi_unit` varchar(40) NOT NULL DEFAULT '', `lumi` double DEFAULT NULL, PRIMARY KEY (`N`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; """.format(table) MdB.exec_dB(command)
def init_tab(OVN_dic=OVN_dic, MdB=None, delete_before=False): table = OVN_dic['master_table'] if MdB is None: MdB = pc.MdB(OVN_dic=OVN_dic) if delete_before: command = 'DROP TABLE IF EXISTS {0};'.format(table) MdB.exec_dB(command) command = "CREATE TABLE IF NOT EXISTS {0} (".format(table) command += fields1 for elem in elem_list: command += '`{0}` double NOT NULL DEFAULT -40,'.format(elem[0]) for line in lines_list: command += "`{0[0]}` double NOT NULL DEFAULT 0, ".format(line) command += "`{0[0]}_rad` double NOT NULL DEFAULT 0, ".format(line) command += """`DepthFrac` double NOT NULL DEFAULT 1, `MassFrac` double NOT NULL DEFAULT 1, `HbFrac` double NOT NULL DEFAULT 1, `rout` double NOT NULL DEFAULT 0, `thickness` double NOT NULL DEFAULT 0, `N_zones` int(11) NOT NULL DEFAULT '0', `CloudyEnds` varchar(180) NOT NULL DEFAULT '', `FirstZone` varchar(180) NOT NULL DEFAULT '', `LastZone` varchar(180) NOT NULL DEFAULT '', `CalculStop` varchar(180) NOT NULL DEFAULT '', `logQ` float NOT NULL DEFAULT 0, `logQ0` float NOT NULL DEFAULT 0, `logQ1` float NOT NULL DEFAULT 0, `logQ2` float NOT NULL DEFAULT 0, `logQ3` float NOT NULL DEFAULT 0, `logPhi` float NOT NULL DEFAULT 0, `logPhi0` float NOT NULL DEFAULT 0, `logPhi1` float NOT NULL DEFAULT 0, `logPhi2` float NOT NULL DEFAULT 0, `logPhi3` float NOT NULL DEFAULT 0, `logU_in` float NOT NULL DEFAULT '0', `logU_out` float NOT NULL DEFAULT '0', `logU_mean` float NOT NULL DEFAULT 0, `t2_H1` float NOT NULL DEFAULT 0, `t2_O1` float NOT NULL DEFAULT 0, `t2_O2` float NOT NULL DEFAULT 0, `t2_O3` float NOT NULL DEFAULT 0, `ne_H1` float NOT NULL DEFAULT 0, `ne_O1` float NOT NULL DEFAULT 0, `ne_O2` float NOT NULL DEFAULT 0, `ne_O3` float NOT NULL DEFAULT 0, `H_mass` float NOT NULL DEFAULT 0, `H1_mass` float NOT NULL DEFAULT 0, `nH_mean` float NOT NULL DEFAULT 0, `nH_in` float NOT NULL DEFAULT 0, `nH_out` float NOT NULL DEFAULT 0, `Hb_SB` float NOT NULL DEFAULT 0, `Hb_EW` float NOT NULL DEFAULT 0, `Ha_EW` float NOT NULL DEFAULT 0, `Cloudy_version` varchar(20) NOT NULL DEFAULT 0, `bad` int(11) NOT NULL DEFAULT '0', `abion` tinyint(1) NOT NULL DEFAULT '0', `teion` tinyint(1) NOT NULL DEFAULT '0', `temis` tinyint(1) NOT NULL DEFAULT '0', `interpol` int(11) NOT NULL DEFAULT '0', `datetime` datetime NOT NULL DEFAULT 0, `N_pending` bigint(20) NOT NULL DEFAULT 0, `N1` bigint(20) NOT NULL DEFAULT -1, `N2` bigint(20) NOT NULL DEFAULT -1, `W1` float NOT NULL DEFAULT 1, PRIMARY KEY (`N`), KEY `ref` (`ref`), KEY `user` (`user`), KEY `atm_file` (`atm_file`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; """ MdB.exec_dB(command) MdB.close_dB()
from pyCloudy.db import use3MdB OVN_dic = {'host' : 'nefeles', 'user_name' : 'OVN_admin', 'user_passwd' : 'getenv', 'base_name' : '3MdB_17', 'pending_table' : '`pending_17`', 'master_table' : '`tab_17`', 'teion_table' : '`teion_17`', 'abion_table' : '`abion_17`', 'temis_table' : '`temis_17`', 'lines_table' : '`lines_17`', 'procIDs_table' : '`procIDs`' } MdB = pc.MdB(OVN_dic) models_dir = 'BOND/' name = 'BOND' alpha_B = 2.6e-13 options = ('no molecules', 'no level2 lines', 'no fine opacities', 'COSMIC RAY BACKGROUND', ) NH = 1e2 ff = 1.0
def make_inputs_MdB(SED='BB', dens_law='C', dust=True, ab_O=-2.76): name = '{0}_{1}'.format(SED, dens_law) all_tabs = [(T, R, dens, L) for T in tabs_T[SED] for R in tab_R for dens in tab_dens for L in tab_L] ab_NO = -0.39 MdB = pc.MdB(OVN_dic) pc.log_.level = 3 wP = use3MdB.writePending(MdB, OVN_dic) wP.set_ref("PNe_2020") wP.set_user('Gloria') wP.set_C_version('17.01') wP.set_iterate(1) wP.set_file(name) wP.set_priority(10) wP.set_cloudy_others(('no molecules', 'no level2 lines', 'no fine opacities', 'COSMIC RAY BACKGROUND')) wP.set_N_Mass_cut(4) wP.set_dir('PNe_2020/') for T, R, dens, L in all_tabs: Q0 = L + Q02Lum[SED][T] wP.set_comments(dic_O[ab_O], i_com=3) wP.set_radius(R) if dens_law == 'C': wP.set_cste_density(dens) elif dens_law == 'G1': thickness = S_thickness(Q0, 10.**dens, 10.**R) wP.set_dlaw((3, 0., 10.**dens, 0.0, np.log10(thickness) + 0.05, 0., 17., 17.)) elif dens_law == 'G2': thickness = S_thickness(Q0, 10.**dens, 10.**R) wP.set_dlaw((310, 10.**dens / 0.37 / 5., 10.**dens / 0.37, np.log10(thickness) + 0.05, np.log10(thickness) + 0.05, 0., 17., 17.)) else: pc.log_.error('unknown dens_law {0}'.format(dens_law)) wP.set_comments(dens_law, i_com=1) if dust: wP.set_dust('ism', 1.) wP.set_comments('D', i_com=4) else: wP.set_dust() wP.set_comments('N', i_com=4) if SED == 'BB': wP.set_star('Blackbody', atm1=T, lumi_unit='luminosity total solar', lumi_value=L) wP.set_comments('BB', i_com=0) elif SED == 'BB2': wP.set_star('Blackbody', atm1=T, lumi_unit='luminosity total solar', lumi_value=L) wP.set_comments('BB', i_com=0) elif SED == 'TR': wP.set_star('table star \"{0}\"'.format(dic_SEDs[SED]), atm1=T, atm2=6, atm3=0, lumi_unit='luminosity total solar', lumi_value=L) wP.set_comments('TR', i_com=0) elif SED == 'TL': wP.set_star('table star \"{0}\"'.format(dic_SEDs[SED]), atm1=T, atm2=4, atm3=0, lumi_unit='luminosity total solar', lumi_value=L) wP.set_comments('TL', i_com=0) elif SED == 'WM': wP.set_star('table star \"{0}\"'.format(dic_SEDs[SED]), atm1=T, atm2=4, atm3=0, lumi_unit='luminosity total solar', lumi_value=L) wP.set_comments('WM', i_com=0) else: pc.log_.error('unknown SED {0}'.format(SED)) ab_dict = { 'He': -1.00, 'Li': -8.69, 'Be': -10.67, 'B': -9.21, 'C': ab_O + 0.25, 'N': ab_O + ab_NO, 'O': ab_O, 'F': -6.5, 'Ne': ab_O - 0.60, 'Na': -5.7, 'Mg': -5.8, 'Al': -6.57, 'Si': -5.0, 'P': -6.7, 'S': ab_O - 1.64, 'Cl': ab_O - 3.41, 'Ar': ab_O - 2.21, 'K': -6.9, 'Ca': -7.9, 'Sc': -8.83, 'Ti': -6.98, 'V': -8.0, 'Cr': -6.33, 'Mn': -6.54, 'Fe': -6.30, 'Co': -7.08, 'Ni': -5.75, 'Cu': -7.79, 'Zn': -7.4 } wP.set_abund(ab_dict=ab_dict) wP.set_stop( ('eden {0}'.format(dens - 3), 'temperature off', 'pfrac 0.02')) wP.insert_model()