def test_get(self): # Get the file storeClient.get(TEST_TOKEN,self.file,self.file) # Check that the file is there os.path.exists(self.file) self.assertTrue(os.path.exists(self.file)) # Read the data fh = open(self.file,'r') outdata = fh.read() fh.close() # Make sure they are equal self.assertEqual(outdata,self.testdata)
def vo_get_multi(*args, **kwds): if DRY_RUN: return for uri in args: tmpd = tempfile.mkdtemp() vo_print(" -> ".join((uri, os.path.basename(tmpd))), sc.get(uri, tmpd, debug=global_debug), "GET", **kwds) shutil.rmtree(tmpd)
def load_sdss_spectra(spPlate, spZbest=None): ''' Load spectra and return an Inspector object Parameters ---------- spPlate : :class:`str` Full path to input spPlate file. spZbest : :class:`str`, optional Full path to input spZbest file. If not provided, the path will be deduced from `spPlate`. Returns ------- :class:`Inspector` Object loaded with spectra from files. ''' if spZbest is None: d, b = os.path.split(spPlate) dd, plate = os.path.split(d) ddd, run2d = os.path.split(dd) if run2d in ('26', '103', '104'): spZbest = os.path.join(ddd, run2d, plate, b.replace('spPlate', 'spZbest')) else: spZbest = os.path.join(ddd, run2d, plate, run2d, b.replace('spPlate', 'spZbest')) with fits.open(sc.get(spPlate, mode='fileobj')) as hdulist: wave = 10.0**( np.arange(hdulist['PRIMARY'].header['NAXIS1'], dtype=np.float32) * hdulist['PRIMARY'].header['COEFF1'] + hdulist['PRIMARY'].header['COEFF0']) flux = hdulist['PRIMARY'].data ivar = hdulist['IVAR'].data sky = hdulist['SKY'].data plugmap = Table(hdulist['PLUGMAP'].data) with fits.open(sc.get(spZbest, mode='fileobj')) as hdulist: zbest = Table(hdulist[1].data) zbest_model = hdulist[2].data spectra = SDSSSpectra(wave, flux, ivar, sky, plugmap) return Inspector(lines, spectra, zbest, zbest_model)
def vo_get(*args, **kwds): if DRY_RUN: return expdata = kwds.pop('expdata', None) expresp = kwds.get('expresp', None) for uri in args: with tempfile.NamedTemporaryFile() as tmpf: vo_print(" -> ".join((uri, os.path.basename(tmpf.name))), sc.get(uri, tmpf.name, debug=global_debug), "GET", **kwds) if not expresp or expresp == 'OK': tmpf.seek(0) tread = tmpf.read().decode('utf-8') if tread != expdata: print("\tUNEXPECTED DATA: " + tread)
def vo_get_multi_and_cmp(put_files_info, **kwds): if DRY_RUN: return for local_file, hash, uri in put_files_info: with tempfile.NamedTemporaryFile() as tmpf: vo_print(uri, sc.get(uri, tmpf.name, debug=global_debug), "GET", **kwds) tread = tmpf.read() if hash == hashlib.md5(tread).hexdigest(): print("\tDownloaded file:[%s] same as uploaded file [OK]" % uri) else: print( "\tDownloaded file:[%s] differs from uploaded file [FAIL]" % uri)
def run(self): token = getUserToken(self) storeClient.get(token, fr=self.fr.value, to=self.to.value, verbose=self.verbose.value)