def test_defaults(): """Test default conversions.""" data = [ ('1m', [ C(1, 'meter', 100, 'centimeter', '[length]'), C(1, 'meter', 0.001, 'kilometer', '[length]') ]), ('100g', [ C(100, 'gram', 0.1, 'kilogram', '[mass]'), C(100, 'gram', 100000, 'milligram', '[mass]') ]), ] wf = Workflow3() if 'default_units' not in wf.settings: wf.settings['default_units'] = {} wf.settings['default_units']['[length]'] = ['centimeter', 'kilometer'] wf.settings['default_units']['[mass]'] = ['kilogram', 'milligram'] c = convert.Converter(Defaults(wf)) for t in data: i = c.parse(t[0]) res = c.convert(i) assert len(res) == len(t[1]) for j, r in enumerate(res): log.debug(r) verify_conversion(t[1][j], r)
def __init__(self, wrfout, ax=0, fig=0, plotn=(1, 1), layout='normal'): """ C : configuration settings W : data """ self.W = wrfout self.D = Defaults() # Create main figure if ax and fig: self.ax = ax self.fig = fig elif layout == 'insetv': self.fig = plt.figure(figsize=(8, 6)) self.gs = M.gridspec.GridSpec(1, 2, width_ratios=[1, 3]) self.ax0 = plt.subplot(self.gs[0]) self.ax1 = plt.subplot(self.gs[1]) elif layout == 'inseth': self.fig = plt.figure(figsize=(6, 8)) self.gs = M.gridspec.GridSpec(2, 1, height_ratios=[1, 3]) self.ax0 = plt.subplot(self.gs[0]) self.ax1 = plt.subplot(self.gs[1]) else: self.fig, self.ax = plt.subplots(nrows=plotn[0], ncols=plotn[1]) self.fig.set_dpi(self.D.dpi)
def prepare(self): """ prepare new root system suitable to create an initrd from it """ self.__load_boot_xml_description() boot_image_name = self.boot_xml_state.xml_data.get_name() self.__import_system_description_elements() log.info('Preparing boot image') system = System(xml_state=self.boot_xml_state, root_dir=self.boot_root_directory, allow_existing=True) manager = system.setup_repositories() system.install_bootstrap(manager) system.install_system(manager) profile = Profile(self.boot_xml_state) profile.add('kiwi_initrdname', boot_image_name) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.boot_xml_state, self.__boot_description_directory(), self.boot_root_directory) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files(follow_links=True) setup.call_config_script() system.pinch_system(manager=manager, force=True) setup.call_image_script() setup.create_init_link_from_linuxrc()
def __init__(self, directory='.'): '''Load all definitions from a directory tree.''' self._data = {} self.defaults = Defaults() self.fields = self.defaults.build_steps + self.defaults.fields config['cpu'] = self.defaults.cpus.get(config['arch'], config['arch']) directories = [d[0] for d in os.walk(directory) if '/.' not in d[0]] for d in sorted(directories): files = glob.glob(os.path.join(d, '*.morph')) for path in sorted(files): data = self._load(path) if data is not None: data['path'] = self._demorph(path[2:]) self._fix_keys(data) self._tidy_and_insert_recursively(data) for x in self._data: dn = self._data[x] for field in dn: if field not in self.fields: log(dn, 'Invalid field "%s" in' % field, dn['path'], exit=True)
def __init__(self, directory='.'): '''Load all definitions from a directory tree.''' self._data = {} self.defaults = Defaults() self.fields = self.defaults.build_steps + self.defaults.fields config['cpu'] = self.defaults.cpus.get(config['arch'], config['arch']) self.parse_files(directory)
def process(self): self.manual = Help() if self.__help(): return Privileges.check_for_root_permissions() self.load_xml_description(self.command_args['--description']) if self.command_args['--set-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(self.command_args['--set-repo']) self.xml_state.set_repository(repo_source, repo_type, repo_alias, repo_prio) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(add_repo) self.xml_state.add_repository(repo_source, repo_type, repo_alias, repo_prio) if os.path.exists('/.buildenv'): # This build runs inside of a buildservice worker. Therefore # the repo defintions is adapted accordingly self.xml_state.translate_obs_to_suse_repositories() elif self.command_args['--obs-repo-internal']: # This build should use the internal SUSE buildservice # Be aware that the buildhost has to provide access self.xml_state.translate_obs_to_ibs_repositories() log.info('Preparing system') system = System(self.xml_state, self.command_args['--root'], self.command_args['--allow-existing-root']) manager = system.setup_repositories() system.install_bootstrap(manager) system.install_system(manager) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, self.command_args['--description'], self.command_args['--root']) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.call_config_script() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_timezone() system.pinch_system(manager)
def __init__(self,config,t,**kwargs): """ config : configuration settings t : time, datenum format optional key-word arguments: wrfdir : if picked, domain is cut down """ self.C = config self.D = Defaults() self.path_to_data = self.C.path_to_RUC self.output_root = self.C.output_root self.t = t # Convert the datenum into time sequence self.ts = self.get_time_seq() self.version = self.get_version() self.fname = self.get_fname() self.fpath = os.path.join(self.path_to_data,self.fname+'.nc') self.nc = Dataset(self.fpath) # Original lat and lon grids self.lats, self.lons = self.get_latlon() # Original lat/lon 1D arrays self.lats1D = self.lats[:,self.lats.shape[1]/2] self.lons1D = self.lons[self.lons.shape[0]/2,:] if 'wrfdir' in kwargs: # It means all data should be cut to this size self.limits = self.colocate_WRF_map(kwargs['wrfdir']) self.lats2D = self.cut_2D_array(self.lats) self.lons2D = self.cut_2D_array(self.lons) self.lats, self.lons = self.cut_lat_lon() self.y_dim = len(self.lats) self.x_dim = len(self.lons) #self.lats1D = self.lats[:,self.lats.shape[1]/2] self.lats1D = self.lats #self.lons1D = self.lons[self.lons.shape[0]/2,:] self.lons1D = self.lons else: # Leave the dimensions the way they were self.y_dim = self.lats.shape[0] self.x_dim = self.lats.shape[1] print('RUC file loaded from {0}'.format(self.fpath))
def __init__(self,config): self.C = config # Set defaults if they don't appear in user's settings self.D = Defaults() self.font_prop = getattr(self.C,'font_prop',self.D.font_prop) self.usetex = getattr(self.C,'usetex',self.D.usetex) self.dpi = getattr(self.C,'dpi',self.D.dpi) self.plot_titles = getattr(self.C,'plot_titles',self.D.plot_titles) # Set some general settings M.rc('text',usetex=self.usetex) M.rc('font',**self.font_prop) M.rcParams['savefig.dpi'] = self.dpi
def __init__(self, fpath, config): self.C = config self.D = Defaults() self.ec = Dataset(fpath, 'r') self.times = self.ecmwf_times() # self.dx = # self.dy = self.lats = self.ec.variables['g0_lat_2'][:] #N to S self.lons = self.ec.variables['g0_lon_3'][:] #W to E self.lvs = self.ec.variables['lv_ISBL1'][:] #jet to sfc self.fields = self.ec.variables.keys() self.dims = self.ec.variables['Z_GDS0_ISBL'].shape self.x_dim = self.dims[3] self.y_dim = self.dims[2] self.z_dim = self.dims[1]
def __init__(self, config, router_attrs): self.errors = [] self.defaults = Defaults(config['defaults'], self.errors) self.hosts = map(lambda item: Host(item, self.defaults), config['hosts']) self.groups = map(Group, config['groups']) self.networks = map(lambda item: Network(item, router_attrs), config['networks']) self.users = dict( (user.nickname, user) for user in map(User, config['people'])) self.errors.extend(check_hosts(self.hosts)) self.errors.extend(expand_groups(self.groups, self.hosts)) map(Host.clean, self.hosts)
def __init__(self, config, wrfout, data=0, fig=0, ax=0): # import pdb; pdb.set_trace() self.C = config self.D = Defaults() self.W = wrfout if isinstance(fig, M.figure.Figure): self.fig = fig self.ax = ax else: super(Clicker, self).__init__(config, wrfout, fig=fig, ax=ax) self.bmap, self.x, self.y = self.basemap_setup() if isinstance(data, N.ndarray): # Lazily assuming it's reflectivity S = Scales('cref', 2000) self.overlay_data(data, V=S.clvs, cmap=S.cm)
def __init__(self, directory='.'): '''Load all definitions from a directory tree.''' self._data = {} self._trees = {} self.defaults = Defaults() config['cpu'] = self.defaults.cpus.get(config['arch'], config['arch']) self.parse_files(directory) self._check_trees() for path in self._data: try: this = self._data[path] if this.get('ref') and self._trees.get(path): if this['ref'] == self._trees.get(path)[0]: this['tree'] = self._trees.get(path)[1] except: log('DEFINITIONS', 'WARNING: problem with .trees file') pass
def __init__(self, config, wrfout, ax=0, fig=0, plotn=(1, 1), layout='normal'): """ C : configuration settings W : data """ self.C = config self.W = wrfout self.D = Defaults() self.output_fpath = self.C.output_root #if wrfout=='RUC': # pass #else: # self.W = wrfout # Get settings for figure dpi = getattr(self.C, 'DPI', self.D.dpi) # Create main figure if ax and fig: self.ax = ax self.fig = fig elif layout == 'insetv': self.fig = plt.figure(figsize=(8, 6)) self.gs = M.gridspec.GridSpec(1, 2, width_ratios=[1, 3]) self.ax0 = plt.subplot(self.gs[0]) self.ax1 = plt.subplot(self.gs[1]) elif layout == 'inseth': self.fig = plt.figure(figsize=(6, 8)) self.gs = M.gridspec.GridSpec(2, 1, height_ratios=[1, 3]) self.ax0 = plt.subplot(self.gs[0]) self.ax1 = plt.subplot(self.gs[1]) else: self.fig, self.ax = plt.subplots(nrows=plotn[0], ncols=plotn[1]) self.fig.set_dpi(dpi)
def __init__(self, directory='.'): self._data = Morphs()._data self._trees = {} self._set_trees() self.defaults = Defaults() self._save_pots('./definitions.yml')
def __init__(self, config): # User's settings self.C = config # Set defaults if they don't appear in user's settings self.D = Defaults()
for i in range(self.layers): self.predict_state[i][session_change] = 0.0 self.current_session = session_ids.copy() in_idxs = itemidmap[input_item_ids] fetches = [self.yhat, self.final_state] feed_dict = {self.X: in_idxs} for i in range(self.layers): feed_dict[self.state[i]] = self.predict_state[i] preds, self.predict_state = self.sess.run(fetches, feed_dict) preds = np.asarray(preds).T return pd.DataFrame(data=preds, index=itemidmap.index) if __name__ == '__main__': defaults = Defaults() data = pd.read_csv(PATH_TO_TRAIN, sep='\t', dtype={'ItemId': np.int64}) valid = pd.read_csv(PATH_TO_TEST, sep='\t', dtype={'ItemId': np.int64}) defaults.n_items = len(data['ItemId'].unique()) defaults.dropout_p_hidden = 1.0 if defaults.is_training == 0 else 0.5 if not os.path.exists(defaults.checkpoint_dir): os.mkdir(defaults.checkpoint_dir) gpu_config = tf.ConfigProto() gpu_config.gpu_options.allow_growth = True with tf.Session(config=gpu_config) as session: predictor = Session4RecPredictor(defaults, session)
def __init__(self, config, wrfout, p2p): self.C = config self.W = wrfout self.D = Defaults() self.p2p = p2p
def convert(query): """Perform conversion and send results to Alfred.""" error = None results = None defs = Defaults(wf) c = Converter(defs, DECIMAL_SEPARATOR, THOUSANDS_SEPARATOR) try: i = c.parse(query) except ValueError as err: log.critical(u'invalid query (%s): %s', query, err) error = err.message else: try: results = c.convert(i) # log.debug('results=%r', results) except NoToUnits: log.critical(u'No to_units (or defaults) for %s', i.dimensionality) error = u'No destination units (or defaults) for {}'.format( i.dimensionality) except DimensionalityError as err: log.critical(u'invalid conversion (%s): %s', query, err) error = u"Can't convert from {} {} to {} {}".format( err.units1, err.dim1, err.units2, err.dim2) except KeyError as err: log.critical(u'invalid context (%s): %s', i.context, err) error = u'Unknown context: {}'.format(i.context) if not error and not results: error = 'Conversion input not understood' if error: # Show error wf.add_item(error, 'For example: 2.5cm in | 178lb kg | 200m/s mph', valid=False, icon=ICON_WARNING) else: # Show results p = CURRENCY_DECIMAL_PLACES if i.is_currency else DECIMAL_PLACES f = Formatter(p, DECIMAL_SEPARATOR, THOUSANDS_SEPARATOR, DYNAMIC_DECIMALS) wf.setvar('query', query) for conv in results: value = copytext = f.formatted(conv.to_number, conv.to_unit) if not COPY_UNIT: copytext = f.formatted(conv.to_number) it = wf.add_item(value, valid=True, arg=copytext, copytext=copytext, largetext=value, icon='icon.png') action = 'save' name = 'Save' if defs.is_default(conv.dimensionality, conv.to_unit): action = 'delete' name = 'Remove' mod = it.add_modifier( 'cmd', u'{} {} as default unit for {}'.format(name, conv.to_unit, conv.dimensionality)) mod.setvar('action', action) mod.setvar('unit', conv.to_unit) mod.setvar('dimensionality', conv.dimensionality) wf.send_feedback() log.debug('finished') return 0
def process(self): self.manual = Help() if self.__help(): return Privileges.check_for_root_permissions() image_root = self.command_args['--target-dir'] + '/build/image-root' Path.create(image_root) if not self.global_args['--logfile']: log.set_logfile(self.command_args['--target-dir'] + '/build/image-root.log') self.load_xml_description(self.command_args['--description']) if self.command_args['--set-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(self.command_args['--set-repo']) self.xml_state.set_repository(repo_source, repo_type, repo_alias, repo_prio) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(add_repo) self.xml_state.add_repository(repo_source, repo_type, repo_alias, repo_prio) Path.create(self.command_args['--target-dir']) if os.path.exists('/.buildenv'): # This build runs inside of a buildservice worker. Therefore # the repo defintions is adapted accordingly self.xml_state.translate_obs_to_suse_repositories() elif self.command_args['--obs-repo-internal']: # This build should use the internal SUSE buildservice # Be aware that the buildhost has to provide access self.xml_state.translate_obs_to_ibs_repositories() log.info('Preparing new root system') system = System(self.xml_state, image_root, True) manager = system.setup_repositories() system.install_bootstrap(manager) system.install_system(manager) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, self.command_args['--description'], image_root) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.call_config_script() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_timezone() system.pinch_system(manager) # make sure system instance is cleaned up now del system setup.call_image_script() # make sure setup instance is cleaned up now del setup log.info('Creating system image') image_builder = ImageBuilder(self.xml_state, self.command_args['--target-dir'], image_root) result = image_builder.create() result.print_results() result.dump(self.command_args['--target-dir'] + '/kiwi.result')