create_neutrino_loss_file.py
Go to the documentation of this file.
1 # Author: M. Reichert
2 # Date : 31.03.2023
3 # Script to download the neutrino loss data from the ENDSF database
4 # and to put it into a WinNet readable file format.
5 # The file can be used to give more precise information on how
6 # much energy is radiated away by neutrinos in case that
7 # nuclear heating is enabled.
8 # A description about the data API can be found here:
9 # https://www-nds.iaea.org/relnsd/vcharthtml/api_v0_guide.html
10 import numpy as np
11 from tqdm import tqdm
12 import pandas as pd
13 import os
14 import h5py
15 
16 # Name of the output filename
17 output_file = "nu_loss_data.dat"
18 # If the neutrino loss is zero, do not include it in the file
19 ignore_zeros = True
20 # The nuclei names are read from the sunet_complete file
21 sunet_path ="sunet_complete"
22 nuclei_names = np.loadtxt(sunet_path,usecols=[0],unpack=True,dtype=str)
23 
24 
25 # Create folders for the data
26 if not os.path.exists('bp'):
27  os.makedirs('bp')
28 if not os.path.exists('bm'):
29  os.makedirs('bm')
30 
31 # Loop through the data and download it
32 for ind,n in enumerate(tqdm(nuclei_names)):
33  baselink = '"https://www-nds.iaea.org/relnsd/v0/data?fields=decay_rads&nuclides='
34  nuc = n
35  user_agent = ' -U "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0" '
36  bp = baselink+n+'&rad_types=bp"'
37  bm = baselink+n+'&rad_types=bm"'
38  # In principle, one can also download the other
39  # decay information
40  # g = baselink+n+'&rad_types=g"'
41  # auger= baselink+n+'&rad_types=e"'
42  # alpha= baselink+n+'&rad_types=a"'
43  # xrays= baselink+n+'&rad_types=x"'
44 
45  if not os.path.exists("bp/"+nuc+".csv"):
46  cmd = "wget -O bp/"+nuc+".csv "+user_agent+bp
47  os.system(cmd)
48 
49  if not os.path.exists("bm/"+nuc+".csv"):
50  cmd = "wget -O bm/"+nuc+".csv "+user_agent+bm
51  os.system(cmd)
52 
53 # Get the neutrino loss
54 nu_loss = {}
55 
56 # After download, loop over them and extract the data
57 for ind,n in enumerate(tqdm(nuclei_names)):
58  try:
59  df_bm = pd.read_csv("bm/"+n+".csv",sep=',',na_values=" ")
60  except:
61  df_bm = pd.DataFrame()
62  try:
63  df_bp = pd.read_csv("bp/"+n+".csv",sep=',',na_values=" ")
64  except:
65  df_bp = pd.DataFrame()
66 
67 
68  if not df_bm.empty:
69  df_bm['intensity_beta'] = pd.to_numeric(df_bm['intensity_beta'], errors='coerce')
70  df_bm['anti_nu_mean_energy'] = pd.to_numeric(df_bm['anti_nu_mean_energy'], errors='coerce')
71  av_anu = np.nansum(df_bm["anti_nu_mean_energy"].values*df_bm["intensity_beta"].values/100.)
72  nu_loss[n] = av_anu/1000
73  if not df_bp.empty:
74  df_bp['intensity_beta'] = pd.to_numeric(df_bp['intensity_beta'], errors='coerce')
75  df_bp['nu_mean_energy'] = pd.to_numeric(df_bp['nu_mean_energy'], errors='coerce')
76  df_bp['energy_ec'] = pd.to_numeric(df_bp['energy_ec'], errors='coerce')
77  df_bp['intensity_ec'] = pd.to_numeric(df_bp['intensity_ec'], errors='coerce')
78  av_ec = np.nansum(df_bp["energy_ec"].values*df_bp["intensity_ec"].values/100.)
79 
80  av_nu = np.nansum(df_bp["nu_mean_energy"].values*df_bp["intensity_beta"].values/100.)
81 
82  if n in nu_loss:
83  # The energy of the electron capture is added to the neutrino loss
84  nu_loss[n] += (av_nu+av_ec)/1000
85  else:
86  # The energy of the electron capture is added to the neutrino loss
87  nu_loss[n] = (av_nu+av_ec)/1000
88 
89 
90 # Now create the file
91 out = ""
92 for n in tqdm(nuclei_names):
93  if n in nu_loss:
94  if ignore_zeros and nu_loss[n] == 0:
95  continue
96  out += n.rjust(5)+" "+"{:16.6E}".format(nu_loss[n])+"\n"
97 
98 # Save the file
99 with open(output_file,"w") as f:
100  f.write(out)