Esempio n. 1
0
    def __init__(self, mode='normal', config=None, log=None, **kwargs):
        """Reads in absorption formalisms
           Note that they are all in GHz"""

        kwargs = state_variables.init_state_variables(mode, **kwargs)
        self.state_vars = kwargs.keys()
        self.set_state(set_mode='init', **kwargs)
        self.log = utils.setupLogFile(log)
        self.freqs = None

        # get config
        if type(config) == str:
            config = pcfg.planetConfig(self.planet, configFile=config, log=log)
        self.config = config

        # copy config back into otherPar
        self.otherPar = {}
        self.otherPar['h2state'] = self.config.h2state
        self.otherPar['h2newset'] = self.config.h2newset
        self.otherPar['water'] = self.config.water_p
        self.otherPar['ice'] = self.config.ice_p
        self.otherPar['nh4sh'] = self.config.nh4sh_p
        self.otherPar['nh3ice'] = self.config.nh3ice_p
        self.otherPar['h2sice'] = self.config.h2sice_p
        self.otherPar['ch4'] = self.config.ch4_p
        self.alpha_data = None
        if self.use_existing_alpha or self.scale_existing_alpha:
            self.existing_alpha_setup()
        else:
            self.formalisms()
        if self.generate_alpha:
            self.start_generate_alpha()
Esempio n. 2
0
    def __init__(self, planet, mode='normal', config='config.par', log=None, **kwargs):
        """reads/computes atmospheres.  This returns:
               self.gas
               self.cloud
               self.layerProperty
            on the appropriate grid."""

        self.planet = planet.capitalize()
        kwargs = state_variables.init_state_variables(mode, **kwargs)
        self.state_vars = kwargs.keys()
        self.set_state(set_mode='init', **kwargs)
        if self.verbose:
            print('\n---Atmosphere of {}---'.format(planet))
        self.logFile = utils.setupLogFile(log)

        if isinstance(config, six.string_types):
            config = os.path.join(self.planet, config)
            config = pcfg.planetConfig(self.planet, configFile=config, log=log)
        self.config = config

        # ##Create function dictionaries
        self.gasGen = {}
        self.gasGen['read'] = self.readGas
        self.cloudGen = {}
        self.cloudGen['read'] = self.readCloud
        self.propGen = {}
        self.propGen['compute'] = self.computeProp

        if self.verbose == 'loud':
            print('Planet ' + self.planet)
            self.config.display()
        if self.config.gasType == 'read':  # this assumes that cloudType is then also 'read'
            utils.log(self.logFile, '\tReading from: ' + self.config.filename, self.verbose)
            utils.log(self.logFile, '\tAtmosphere file:  ' + self.config.gasFile, self.verbose)
            utils.log(self.logFile, '\tCloud file:  ' + self.config.cloudFile, self.verbose)
Esempio n. 3
0
    def __init__(self, name, mode='normal', config='config.par', **kwargs):
        """This is the 'executive function class to compute overall planetary emission.
           For both mode and kwargs look at state_variables.py
           Inputs:
                name:  'Jupiter', 'Saturn', 'Uranus', 'Neptune'
                config:  config file name.  If 'planet' sets to <name>/config.par
                mode:  sets up for various special modes '[normal]/batch/mcmc/scale_alpha/use_alpha'
                kwargs: 'verbose' and 'plot' (and other state_vars - see show_state())"""

        planet_list = ['Jupiter', 'Saturn', 'Neptune', 'Uranus']
        self.planet = name.capitalize()
        self.header = {}
        self.freqs = None
        self.freqUnit = None
        self.b = None

        print('Planetary modeling  (ver {})'.format(version))
        if self.planet not in planet_list:
            print("{} not found.".format(self.planet))
            return

        # Set up state_variables
        kwargs = state_variables.init_state_variables(mode.lower(), **kwargs)
        self.state_vars = kwargs.keys()
        self.set_state(set_mode='init', **kwargs)
        self.mode = mode
        self.kwargs = kwargs

        #  ##Set up log file
        if self.write_log_file:
            runStart = datetime.datetime.now()
            self.logFile = 'Logs/{}_{}.log'.format(
                self.planet, runStart.strftime("%Y%m%d_%H%M"))
            self.log = utils.setupLogFile(self.logFile)
            utils.log(self.log, self.planet + ' start ' + str(runStart),
                      self.verbose)
        else:
            self.log = None

        #  ## Get config
        config = os.path.join(self.planet, config)
        if self.verbose:
            print('Reading config file:  ', config)
            print("\t'{}.config.display()' to see config parameters.".format(
                name[0].lower()))
        self.config = pcfg.planetConfig(self.planet,
                                        configFile=config,
                                        log=self.log)

        if self.initialize:
            self.initialize_run()
Esempio n. 4
0
    def __init__(self, name, mode='normal', config='config.par', **kwargs):
        """This is the 'executive function class to compute overall planetary emission.
           For both mode and kwargs look at state_variables.py
           Inputs:
                name:  'Jupiter', 'Saturn', 'Uranus', 'Neptune'
                config:  config file name.  If 'planet' sets to <name>/config.par
                mode:  sets up for various special modes '[normal]/batch/mcmc/scale_alpha/use_alpha'
                kwargs: 'verbose' and 'plot' (and other state_vars - see show_state())"""

        planet_list = ['Jupiter', 'Saturn', 'Neptune', 'Uranus']
        self.planet = name.capitalize()
        self.header = {}
        self.freqs = None
        self.freqUnit = None
        self.b = None

        print('Planetary modeling  (ver {})'.format(version))
        if self.planet not in planet_list:
            print("{} not found.".format(self.planet))
            return

        # Set up state_variables
        kwargs = state_variables.init_state_variables(mode.lower(), **kwargs)
        self.state_vars = kwargs.keys()
        self.set_state(set_mode='init', **kwargs)
        self.mode = mode
        self.kwargs = kwargs

        #  ##Set up log file
        if self.write_log_file:
            runStart = datetime.datetime.now()
            self.logFile = 'Logs/{}_{}.log'.format(self.planet, runStart.strftime("%Y%m%d_%H%M"))
            self.log = utils.setupLogFile(self.logFile)
            utils.log(self.log, self.planet + ' start ' + str(runStart), self.verbose)
        else:
            self.log = None

        #  ## Get config
        config = os.path.join(self.planet, config)
        if self.verbose:
            print('Reading config file:  ', config)
            print("\t'{}.config.display()' to see config parameters.".format(name[0].lower()))
        self.config = pcfg.planetConfig(self.planet, configFile=config, log=self.log)
        self.config.show()

        if self.initialize:
            self.initialize_run()
Esempio n. 5
0
    def __init__(self,
                 planet,
                 mode='normal',
                 config='config.par',
                 log=None,
                 **kwargs):
        """reads/computes atmospheres.  This returns:
               self.gas
               self.cloud
               self.layerProperty
            on the appropriate grid."""

        self.planet = planet.capitalize()
        kwargs = state_variables.init_state_variables(mode, **kwargs)
        self.state_vars = kwargs.keys()
        self.set_state(set_mode='init', **kwargs)
        if self.verbose:
            print('\n---Atmosphere of {}---'.format(planet))
        self.logFile = utils.setupLogFile(log)

        if type(config) == str:
            config = os.path.join(self.planet, config)
            config = pcfg.planetConfig(self.planet, configFile=config, log=log)
        self.config = config

        # ##Create function dictionaries
        self.gasGen = {}
        self.gasGen['read'] = self.readGas
        self.cloudGen = {}
        self.cloudGen['read'] = self.readCloud
        self.propGen = {}
        self.propGen['compute'] = self.computeProp

        if self.verbose == 'loud':
            print('Planet ' + self.planet)
            self.config.display()
        if self.config.gasType == 'read':  # this assumes that cloudType is then also 'read'
            utils.log(self.logFile, '\tReading from: ' + self.config.filename,
                      self.verbose)
            utils.log(self.logFile,
                      '\tAtmosphere file:  ' + self.config.gasFile,
                      self.verbose)
            utils.log(self.logFile, '\tCloud file:  ' + self.config.cloudFile,
                      self.verbose)
Esempio n. 6
0
    def __init__(self,planet,config='config.par',path=None,log=None,verbose=False,plot=True):
        """reads/computes atmospheres.  This should return:
               self.gas
               self.cloud
               self.layerProperty
            on the appropriate grid
            Note that the research is in the input files and modifying the tweak modules
            All of the default config parameters are hard-coded here:  see __init__, setConfig, showConfig."""

        planet = string.capitalize(planet)
        self.planet = planet
        self.verbose=verbose
        self.plot=plot
        self.logFile = utils.setupLogFile(log)
        self.batch = False
        
        print '\n---Atmosphere of %s---' % (planet)
        if type(config) == str:
            config = pcfg.planetConfig(self.planet,configFile=config,log=log,verbose=verbose)
        self.config = config

        ###Create function dictionaries
        self.gasGen = {}
        self.gasGen['read'] = self.readGas
        self.gasGen['compute'] = self.computeGas
        self.cloudGen = {}
        self.cloudGen['read'] = self.readCloud
        self.cloudGen['compute'] = self.computeCloud
        self.propGen = {}
        self.propGen['read'] = self.readProp
        self.propGen['compute'] = self.computeProp

        print 'Planet '+self.planet
        if self.config.gasType == 'read':  # this assumes that cloudType is then also 'read'
            utils.log(self.logFile,'\tReading from: '+self.config.path,True)
            utils.log(self.logFile,'\tAtmosphere file:  '+self.config.gasFile,True)
            utils.log(self.logFile,'\tCloud file:  '+self.config.cloudFile,True)
        if verbose:
            print self.config.show()
Esempio n. 7
0
    def __init__(self, name, freqs=None, b=None, freqUnit='GHz', config='config.par', log='auto', verbose=False, plot=True):
        """This is the 'executive function class to compute overall planetary emission
           Arguments here set defaults, however often get set specifically in run. See pyPlanet.pdf for documentation.
           Inputs:
                name:  'Jupiter', 'Saturn', 'Uranus', 'Neptune' [or 'functions' if you just want to load without running]
                freqs: options are:
                    - int/float:  does that one frequency
                    - list of length 3:  assumes it is [start,stop,step]
                    - list not of length 3:   does those frequencies
                b: 'impact parameter' b=1 is the radius of the maximum projected disc.
                   Determines outType from 'spectrum','profile','image' (along with freqs to some extent)
                    - doublet list is one position, [0,0] is the center
                    - float will generate a grid at that spacing, may need to set blocks during run
                    - list of length > 2, assumes a line of those locations at angle of first entry (deg)
                         if the length is four it assumes [angle,start,stop,step]
                    - 'disc' for disc-averaged
                    - 'stamp' for postage stamp (queries values)
                    - list of doublet lists, evaluate at those locations
               freqUnit: unit for above
               config:  config file name [config.par], 'manual' [equivalent none]
               log:  log data from run, either a file name, a 'no', or 'auto' (for auto filename)
               verbose:  True/False
               plot:  True/False"""

        if name.lower()[0:4] == 'func':
            return

        planetList = ['Jupiter','Saturn','Neptune','Uranus']
        self.planet = string.capitalize(name)

        runStart = datetime.datetime.now()
        self.header = {}

        print 'Planetary modeling  (ver '+version+')\n'
        print "PLANET.PY_L51:  In alpha, clouds_idp need otherPar['refr'] - still?"

        if self.planet in planetList:
            ### Set up log file
            if string.lower(log)=='auto':
                self.logFile = '%s_%d%02d%02d_%02d%02d.log' % (self.planet,runStart.year,runStart.month,runStart.day,runStart.hour,runStart.minute)
            elif string.lower(log)=='no':
                self.logFile=None
            else:
                self.logFile = log
            self.log=utils.setupLogFile(self.logFile,path='Logs/')
            utils.log(self.log,self.planet+' start '+str(runStart),True)
            self.plot = plot
            self.verbose = verbose

            ### Some convenience values for the specific Neptune observations
            self.fvla_old = [4.86,8.46,14.94,22.46,43.34]
            self.fvla_new = [1.5,3.0,6.0,10.,15.,22.,33.,45.]
            self.fvla = [3.0, 6.0, 10.0, 15.0, 33.0]
            anglecap = 13.24
            bvalcap = [0.5,0.6,0.7,0.8,0.9,0.925,0.95]
            self.bvla = []
            for bval in bvalcap:
                self.bvla.append([-bval*math.sin(math.pi*anglecap/180.0),-bval*math.cos(math.pi*anglecap/180.0)])
            
            ### Get frequencies
            if freqs != None:
                freqs = self.__freqRequest__(freqs, freqUnit)
            else:
                self.freqUnit = freqUnit
            
            ### Get viewing
            self.imRow = False
            if b!= None:
                b = self.__bRequest__(b,[1,1])

            ### Get config
            if config == 'manual' or config=='none':
                config = None
            self.config = pcfg.planetConfig(self.planet,configFile=config,log=self.log,verbose=verbose)

            ### Create atmosphere:  outputs are self.atm.gas, self.atm.cloud and self.atm.layerProperty
            self.atm = atm.Atmosphere(self.planet,config=self.config,log=self.log,verbose=verbose,plot=plot)
            self.atm.run()
            self.log.flush()
Esempio n. 8
0
    def __init__(self,path=None,config=None,log=None,verbose=False,plot=False):
        """Reads in absorption formalisms
           Note that they are all in GHz"""

        self.verbose = verbose
        self.plot = plot
        self.log = utils.setupLogFile(log)
        print '\n---Alpha---\n'
            
        #Get possible constituents
        if path is None:
            path = pyPlanetPath
        possible = []
        self.constituentsAreAt=os.path.join(path,'constituents')
        utils.log(self.log,'Reading in absorption modules from '+self.constituentsAreAt+'\n',True)
        for d in os.listdir(self.constituentsAreAt):
            fnd = os.path.join(self.constituentsAreAt,d)
            if os.path.isdir(fnd):
                possible.append(d)
        #Import used ones - note this dynamically imports the absorption modules.  It checks that directory's use.txt file.
        self.constituent = {}
        self.absorptionModule = {}
        for c in possible:
            fn = os.path.join(self.constituentsAreAt,c,'use.txt')
            try:
                fp = open(fn,'r')
            except:
                #utils.log(self.log,'No file '+fn,True)
                continue
            absorber = fp.readline().strip()
            testabs = absorber.split('.')
            if len(testabs)==2:
                absorber=testabs[0]
            fp.close()
            constituentPath=os.path.join(self.constituentsAreAt,c)
            if string.lower(absorber) != 'none':
                sys.path.append(constituentPath)
                try:
                    __import__(absorber)
                    self.absorptionModule[c]=sys.modules[absorber]
                    self.constituent[c] = absorber
                except ImportError:
                    utils.log(self.log,"Can't load "+absorber,True)
        utils.log(self.log,'Using modules:',True)
        for k in self.constituent:
            utils.log(self.log,'\t'+k+':  '+self.constituent[k],True)

        # get config
        if type(config) == str:
            config = pcfg.planetConfig(self.planet,configFile=config,log=log,verbose=verbose)
        self.config = config

        # copy config back into otherPar
        self.otherPar = {}
        self.otherPar['h2state'] = self.config.h2state
        self.otherPar['h2newset'] = self.config.h2newset
        self.otherPar['water'] = self.config.water_p
        self.otherPar['ice'] = self.config.ice_p
        self.otherPar['nh4sh'] = self.config.nh4sh_p
        self.otherPar['nh3ice'] = self.config.nh3ice_p
        self.otherPar['h2sice'] = self.config.h2sice_p
        self.otherPar['ch4'] = self.config.ch4_p