from anh import * # for filename_hdf5 in my.myglob('*.hdf5'): for filename_hdf5 in my.myglob('O.hdf5'): filename_text = my.rootname(filename_hdf5)+'.txt' print( filename_hdf5,filename_text) d = my.hdf5_to_dict(filename_hdf5) header = d.pop('README') header = header.replace(' assuming dust properties ~/data/astro/grain_properties/calculate_extinction/radiation_field_with_depth_grains.std.hdf5 calculated 2016-11-10 by Alan Heays using script calculate_depth_dependent_rates_from_precomputed_radiation.py','') header += '\nAV: Visual extinction proportional to dust column.' header += '\npd: Shielding of photodissociation.' header += '\npi: Shielding of photoionisation.' header += '''\nThe following radiation fields are included: unit: A flat radiation field. Total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. ISRF: A unit Draine 1978 (doi: 10.1086/190513) radiation field with the long wavelength extension of van Dishoeck & Black (1982) (doi: 10.1086/160104). Total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. mathis1983: A unit Mathis 1983 radiation field assuming 10kpc Galactocentric distance. (http://adsabs.harvard.edu/abs/1983A%26A...128..212M) habing1968: Radiation field of Habing 1968 (http://adsabs.harvard.edu/abs/1968BAN....19..421H 4000K: A blackbody radiation field of temperature 4000K, with no radiation shorter than 91.2nm and renormalised to give a total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. 10000K: A blackbody radiation field of temperature 10000K, with no radiation shorter than 91.2nm and renormalised to give a total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. 20000K: A blackbody radiation field of temperature 20000K, with no radiation shorter than 91.2nm and renormalised to give a total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. Lyalpha: All flux in a single Lyman-α line with width 100 km.s-1. Total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. solar: A particular measured Solar radiation radiation. Total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm. TW-Hya: A radiation field simulating the star TW-Hydra. Total energy intensity of 2.6e-6 W.m-2 intergrated between 91.2 and 200nm.''' header += '\n' d2 = collections.OrderedDict() d2['AV'] = d['AV'] for key in d: if key=='AV': continue # do not change new_key = key if 'photodissociation_' in new_key: new_key = new_key.replace('photodissociation_','pd_') if 'photoionisation_' in new_key: new_key = new_key.replace('photoionisation_','pi_') for t0,t1 in ( ('van_dishoeck1988','ISRF'), ('mathis1983','mathis1983'), ('habing1968','habing1968'), ('blackbody_4000K_cutoff_912A','4000K'), ('blackbody_10000K_cutoff_912A','10000K'), ('blackbody_20000K_cutoff_912A','20000K'), ('Lyman-alpha_100km.s-1','Lyalpha'), ('solar_normalised_draine1978','solar'), ('TW-Hya_normalised_draine1978','TW-Hya'), ): if t0 in new_key: new_key = new_key.replace(t0,t1) d2[new_key] = d[key] my.dict_array_to_file(filename_text,d2,header=header,fmts='0.3e')