The point of my code is to:
Read in the observed data from the a catalog of stars (whitespace separated table).
Do some unit conversions on the observed data (math stuff).
Apply an interstellar correction factor to the observed data (more math).
Compare the scaled observed data to the DUSTY model data using the BC table, using a least-squares approach (comparison of observed data to theoretical models found in a large table).
Find the best fit models for the observed data (should be obvious).
I'm trying to rewrite 'spaghetti code' I was handed, that doesn't function quickly, nor does it allow for easy updating (adding different statistical calculations, etc.). I'm pretty new to Python, so I'm struggling with the idea of classes and this is my attempt at it.
class Stellar_setup: Fbol=5.01333e-10 c=2.99792458e+8 L=1000 star_list= dusty_models=np.array() #Array of all the dusty models incoming_stars='' #List of incoming stars def __init__(self): """Initiates the below modules.""" self.star_catalog() self.InputKey() def star_catalog(self): """Imports the star catalog""" try: star_catalog=raw_input('Input pathname of stellar catalog: ') star_list= with open(star_catalog) as incoming_stars: for line in incoming_stars.readlines(): x=[item for item in line.split()] star_list.append(x) #Appends the individual star-IDs to the empty array star_list. print 'Stars imported successfully.' except IOError: print 'Star import unsuccessful. Check that the star catalog file-path is correct. Program exiting now.' sys.exit() def InputKey(self): """Imports the Input (.inp) file. Historically, InputUt.inp. Allows for definition of parameters which are utilized later in the script.""" input_script=raw_input('Pathname of .inp file: ') InputKey= try: with open(input_script) as input_key: for line in input_key.readlines(): x=[item for item in line.split()] InputKey.append(x) if InputKey=='1' or InputKey=='2': #Checks to see if .inp file is valid or not by checking the first row/column which should be 1 or 2. print 'Your .inp file was successfully imported' else: print 'Your .inp file import failed. Check the validity of your file.\n Program exiting now.' sys.exit() except IOError: print 'The .inp file import was unsuccessful. Check that your file-path is valid.\n Program exiting now.' sys.exit() # You probably need to put a module here that pulls in the DUSTY tables. if __name__=='__main__': Stellar_setup()
I was thinking about making about three other classes that:
- Identify necessary attributes from the tables (pulling data from columns/rows)
- Do analysis of information, and model/data comparison to find the best theoretical models that match up with the observed data. This uses a least-squares approach.
From what I understand classes can 'inherit' attributes from other classes. The way I think I understand this is that my class
Stellar_setup will be inherited by my class
Attribute_Identification (which haven't been written yet), and so on. I'm not sure if I'm going about this the right way, can anyone clear things up for me.