def __init__(self, r=None, sigma=None, CDF=None, profile_kind=None, settings=None): if isinstance(r, str): # Load the pickled sigma dictionary sig_dict = pickle.load(open(r, 'r')) sigma = sig_dict['sigma'] r = sig_dict['r'] if 'CDF' in sig_dict: CDF = sig_dict['CDF'] # Initialize self.__version__ = __iversion__ if settings is None: # Load up default settings self.settings = ICgen_settings.settings(kind=profile_kind) else: self.settings = settings # Try to update profile_kind (might be set in settings, or from defaults) try: profile_kind = self.settings.sigma.kind except: pass # Add modules/attributes self.T = calc_temp.T(self) self.maker = maker(self) self.add = add(self) # Generate sigma spline interpolation if (r is not None) or (profile_kind is not None): self.maker.sigma_gen(r, sigma, CDF) # Define a saving function def saver(filename=None): """ A wrapper for ICgen.save """ save(self, filename) self.save = saver
def __init__(self, r=None, sigma=None, CDF=None, profile_kind=None, settings=None): if isinstance(r,str): # Load the pickled sigma dictionary sig_dict = pickle.load(open(r,'r')) sigma = sig_dict['sigma'] r = sig_dict['r'] if 'CDF' in sig_dict: CDF = sig_dict['CDF'] # Initialize self.__version__ = __iversion__ if settings is None: # Load up default settings self.settings = ICgen_settings.settings(kind=profile_kind) else: self.settings = settings # Try to update profile_kind (might be set in settings, or from defaults) try: profile_kind = self.settings.sigma.kind except: pass # Add modules/attributes self.T = calc_temp.T(self) self.maker = maker(self) self.add = add(self) # Generate sigma spline interpolation if (r is not None) or (profile_kind is not None): self.maker.sigma_gen(r, sigma, CDF) # Define a saving function def saver(filename = None): """ A wrapper for ICgen.save """ save(self, filename) self.save = saver
def __init__(self): # Initialize # Load up default settings self.settings = ICgen_settings.settings() # Add modules/attributes self.T = calc_temp.T(self) self.maker = maker(self) self.add = add(self) def saver(filename = None): """ A wrapper for ICgen.save """ save(self, filename) self.save = saver
def __init__(self): # Initialize # Load up default settings self.settings = ICgen_settings.settings() # Add modules/attributes self.T = calc_temp.T(self) self.maker = maker(self) self.add = add(self) def saver(filename=None): """ A wrapper for ICgen.save """ save(self, filename) self.save = saver
def _upgrade_version(IC_input, version): """ Used for backwards compatibility. If an initial conditions object was generated using an outdated version of ICgen, hopefully when it's being loaded it can be made up-to-date before initializing the ICobj version is the version of the IC_input """ if version < 1: # Assume IC_input is a dictionary # Needs the changa_run settings # Initialize empty, up-to-date settings new_settings = ICgen_settings.settings() old_settings = IC_input['settings'] if 'settings' in IC_input: # Load old settings, ignoring the snapshot gen settings for key in old_settings.__dict__.keys(): if key != 'snapshot': new_settings.__dict__[key] = old_settings.__dict__[key] # update the input dictionary IC_input['settings'] = new_settings if version < 2: # Add a .director file name to settings. warn('These ICs seem out of date. Attempting to upgrade to current version') if not hasattr(IC_input['settings'].filenames, 'directorName'): paramName = IC_input['settings'].filenames.paramName directorName = os.path.splitext(paramName)[0] + '.director' IC_input['settings'].filenames.directorName = directorName if version < 4: IC_input['settings'] = IC_input['settings'].settings_filename
def __init__(self, r, sigma): # Initialize # Load up default settings self.settings = ICgen_settings.settings() # Add modules/attributes self.T = calc_temp.T(self) self.maker = maker(self) self.add = add(self) # Generate sigma spline interpolation self.maker.sigma_gen(r, sigma) # Define a saving function def saver(filename = None): """ A wrapper for ICgen.save """ save(self, filename) self.save = saver
def __init__(self, r, sigma): # Initialize # Load up default settings self.settings = ICgen_settings.settings() # Add modules/attributes self.T = calc_temp.T(self) self.maker = maker(self) self.add = add(self) # Generate sigma spline interpolation self.maker.sigma_gen(r, sigma) # Define a saving function def saver(filename=None): """ A wrapper for ICgen.save """ save(self, filename) self.save = saver
def __init__(self, filefilter='IC_settings.p', *directories, **kwargs): print 'Building database...' if len(directories) == 0: directories = ['.'] print 'Number of base directories: ', len(directories) self.dirs = directories self.filefilter = filefilter self._kwargs = kwargs # keyword args defaults exact_dirs = False recursive = True # Parse keyword args for key, val in kwargs.iteritems(): if key is 'exact_dirs': # Exact dirs is the flag that basically says don't search # recursively exact_dirs = val recursive = not exact_dirs else: raise KeyError, 'Unrecognized argument {0}'.format(key) matches = [] for directory in directories: print 'Building for ', directory new_matches = self._scan_dir(directory, filefilter, recursive=recursive) print ' Found {} files'.format(len(new_matches)) matches += new_matches if not exact_dirs: # Remove duplicate files. changes order, but required if directories # are recursively searched filelist = list(set(matches)) else: filelist = matches datalist = [] for i, fname in enumerate(filelist): a = ICgen_settings.settings() a.load(fname) a_dir = os.path.split(fname)[0] ICname = a.filenames.IC_file_name ICname = os.path.join(a_dir, ICname) ICname = os.path.realpath(ICname) if os.path.exists(ICname): a.dir = os.path.realpath(a_dir) a.ICname = ICname datalist.append(a) nfiles = len(datalist) print 'Found {} files in total'.format(nfiles) data = fancy_array(nfiles) data[:] = datalist self.data = data