winvn_class.py
Go to the documentation of this file.
1 import pandas as pd
2 import numpy as np
3 
4 
5 
6 
7 class winvn(object):
8 
9  def __init__(self,path):
10  """
11  Class to read and manage a winvn
12  """
13  self.__path = path
14 
15 
16 
17  def read_winvn(self):
18  """
19  Read the winvn. (stolen from Carlos)
20  """
21  with open(self.__path,'r') as winvn:
22  """Open file with the context manager and extract data."""
23  # read file content
24  winvn.readline()
25 
26  # read the ugly log temperature string
27  T_string = winvn.readline().strip()
28  str_size = 3
29  logT = np.array([int(T_string[i:i+str_size])
30  for i in range(0,len(T_string),str_size)])
31  logT[-1]*=10 # I think there is a factor 10 missing!!!
32 
33  # skip the hacky name part, i.e. look for the last name,
34  # it appears twice
35  name1,name2 = ("","-")
36  nameList = []
37  while (name1!=name2):
38  name2 = name1
39  name1 = winvn.readline().strip()
40  nameList.append(name1)
41 
42  # get rid of the last name which appears twice...
43  #...why don't they just give the number of elements!!!
44  nameList.pop()
45 
46 
47  # initialize element data container
48  eleList = []
49 
50  # now, get the data for each of these elements
51  for element in nameList:
52  # extract element data
53  #..what is mass excess again??!! I hate c12 related quantities!!
54  name, A, Z, N, sp, mass_excess, no_idea = winvn.readline().split()
55  # I don't trust that guys! Let's check the order!
56  if (name != element):
57  sys.exit("OMG!!!")
58  # extract partition function
59  pf_list = []
60  # read three lines...
61  for i in range(3):
62  pf_list.extend(winvn.readline().split())
63  pf_values = np.array(pf_list,dtype=float)
64 
65  # save element data in a list
66  eleList.append([int(Z),int(N),name,float(A),float(sp),
67  float(mass_excess),str(no_idea), pf_values] )
68 
69 
70  # give the element data list entries names
71  column_names = ['Z','N','name','A','spin','mass excess','mass model',
72  'partition function']
73  # build table
74  self.__df = pd.DataFrame(eleList)
75  # set column names
76  self.__df.columns=column_names
77 
78 
79 
80  def get_dataframe(self):
81  """
82  Get the dataframe
83  """
84  return self.__df
bin.class_files.winvn_class.winvn
Definition: winvn_class.py:7
bin.class_files.winvn_class.winvn.__init__
def __init__(self, path)
Definition: winvn_class.py:9
bin.class_files.winvn_class.winvn.get_dataframe
def get_dataframe(self)
Definition: winvn_class.py:80
bin.class_files.winvn_class.winvn.__path
__path
Definition: winvn_class.py:13
bin.class_files.winvn_class.winvn.__df
__df
Definition: winvn_class.py:74
bin.class_files.winvn_class.winvn.read_winvn
def read_winvn(self)
Definition: winvn_class.py:17