def output_annotated_photometry(params, photometry): if str(config['photometry_data_file']).lower() != 'none': fname = params['phot_file'].split('.') + '_gaia.txt' f = open(path.dirpath(params['phot_file'], fname), 'w') f.write( '# All measured floating point quantities in units of magnitude\n') f.write( '# Selected indicates whether a star lies within the selection radius of a given location, if any. 1=true, 0=false\n' ) f.write( '# Star x_pix y_pix ra_deg dec_deg g sigma_g r sigma_r i sigma_i (g-i) sigma(g-i) (g-r) sigma(g-r) (r-i) sigma(r-i) Selected Gaia_ID Distance Distance_lo Distance_hi\n' ) for j in range(0, len(photometry['i']), 1): source = photometry['GaiaSources'][j] f.write( str(photometry['Star'][j])+' '+\ str(photometry['x_pix'][j])+' '+str(photometry['y_pix'][j])+' '+\ str(photometry['ra'][j])+' '+str(photometry['dec'][j])+' '+\ str(photometry['g'][j])+' '+str(photometry['sigma_g'][j])+' '+\ str(photometry['r'][j])+' '+str(photometry['sigma_r'][j])+' '+\ str(photometry['i'][j])+' '+str(photometry['sigma_i'][j])+' '+\ str(photometry['(g-i)'][j])+' '+str(photometry['sigma(g-i)'][j])+' '+\ str(photometry['(g-r)'][j])+' '+str(photometry['sigma(g-r)'][j])+' '+\ str(photometry['(r-i)'][j])+' '+str(photometry['sigma(r-i)'][j])+' '+\ str(photometry['selected'][j])+' '+str(photometry['gaia_source_id'])+' '+\ str(source.r_est)+' '+str(source.r_lo)+' '+str(source.r_hi)+'\n' ) f.close()
def parse_file(self, path): def _input_files(model_type): return [ k for k, v in _SCHEMA.model[model_type].items() if 'InputFile' in v[1] ] def _verify_files(model, model_type, model_name, category): for i in _input_files(model_type): f = model.get(i) if not f: continue assert sirepo.util.secure_filename(f) == f, \ f'file={f} must be a simple name' p = path.dirpath().join(f) assert p.check(file=True), \ f'file={f} missing from {category}={model_name} type={model_type}' d = parse_input_text(path) r = self._run_setup(d) l = r.lattice d = parse_input_text( self._lattice_path(path.dirpath(), d), input_data=d, ) for i in d.models.elements: _verify_files(i, i.type, i.name, 'element') for i in d.models.commands: _verify_files(i, lattice.LatticeUtil.model_name_for_data(i), i._type, 'command') r.lattice = l return self._convert(d)
def parse_file(self, path): def _input_files(model_type): return [ k for k, v in _SCHEMA.model[model_type].items() if 'InputFile' in v[1] ] def _verify_files(model, model_type): self._verify_files( path, [ model[x] for x in filter( lambda f: model[f], _input_files(model_type), ) ], ) d = parse_input_text(path, update_filenames=False) r = self._run_setup(d) l = r.lattice d = parse_input_text( self._lattice_path(path.dirpath(), d), input_data=d, update_filenames=False, ) for i in d.models.elements: _verify_files(i, i.type) for i in d.models.commands: _verify_files(i, lattice.LatticeUtil.model_name_for_data(i)) r.lattice = l return self._convert(d)
def test_value_access_with_confmod(self, basedir): startdir = basedir.join("adir", "b") startdir.ensure("xx", dir=True) conftest = ConftestWithSetinitial(startdir) mod, value = conftest._rget_with_confmod("a", startdir) assert value == 1.5 path = py.path.local(mod.__file__) assert path.dirpath() == basedir.join("adir", "b") assert path.purebasename.startswith("conftest")
def _verify_files(model, model_type, model_name, category): for i in _input_files(model_type): f = model.get(i) if not f: continue assert sirepo.util.secure_filename(f) == f, \ f'file={f} must be a simple name' p = path.dirpath().join(f) assert p.check(file=True), \ f'file={f} missing from {category}={model_name} type={model_type}'
class TestAccess(TestCase): db_name = 'test.db' app_secret_filename = 'app.secret' app_secret_filepath = joinpath(dirpath(realpath(__file__)), TestAccess.app_secret_filename) def setUp(self): if exists(self.db_name): os.remove(self.db_name) def tearDown(self): if exists(self.db_name): os.remove(self.db_name) def test_get_token(self): app_id = None app_secret = None if not exists(app_secret_filepath): self.fail('This test expects a file named %s in the same directory as the test class file with client_id \ on the first line and client_secret on the second line.') with open(self.app_secret, 'r') as f: lines = f.read().split('\n') app_id = lines[0].strip() app_secret = lines[1].strip() dbm = DBManager(self.db_name) dbm.connect() fba = FBAccess() oldstdin = sys.stdin sys.stdin = StringIO(app_id + os.linesep + app_secret) token = fba.get_token() sys.stdin = oldstdin self.assertTrue(token is not None and len(token) > 0)