本文整理汇总了Python中astropy.utils.console.ProgressBar类的典型用法代码示例。如果您正苦于以下问题:Python ProgressBar类的具体用法?Python ProgressBar怎么用?Python ProgressBar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProgressBar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ratio_to_dens_slow
def ratio_to_dens_slow(ratio, c11, c22):
"""
Shape:
ratio [z,y,x]
c11 [y,x]
c22 [y,x]
"""
assert c11.size == c22.size == ratio[0,:,:].size
fshape = [ratio.shape[0], ratio.shape[1]*ratio.shape[2]]
rrs = ratio.reshape(fshape).T
outc = (ratio*0).reshape(fshape) + np.nan
# set up a grid...
pb = ProgressBar((c11.size))
for ii,(r,c1,c2) in enumerate(zip(rrs, c11.flat, c22.flat)):
#print r.shape,c1,c2
if np.isfinite(c1) and np.isfinite(c2) and np.any(np.isfinite(r)):
tauratio, ok = get_tau_ratio(c1,c2)
inds = np.argsort(tauratio[ok])
outc[:,ii] = np.interp(r, tauratio[ok][inds], dens[ok][inds], np.nan, np.nan)
pb.update()
#pb.finish()
return outc.reshape(ratio.shape)
示例2: extract_poly_slice
def extract_poly_slice(cube, polygons, width=1.0):
nx = len(polygons)
nz = cube.shape[0]
slice = np.zeros((nz, nx))
p = ProgressBar(len(polygons))
for i, polygon in enumerate(polygons):
p.update()
# Find bounding box
bbxmin = int(round(np.min(polygon.x))-1)
bbxmax = int(round(np.max(polygon.x))+2)
bbymin = int(round(np.min(polygon.y))-1)
bbymax = int(round(np.max(polygon.y))+2)
# Loop through pixels that might overlap
for xmin in np.arange(bbxmin, bbxmax):
for ymin in np.arange(bbymin, bbymax):
area = square_polygon_overlap_area(xmin-0.5, xmin+0.5,
ymin-0.5, ymin+0.5,
polygon.x, polygon.y)
if area > 0:
slice[:, i] += cube[:, ymin, xmin] * area
print("")
return slice
示例3: _download_file
def _download_file(self, url, local_filepath, timeout=None, auth=None):
"""
Download a file. Resembles `astropy.utils.data.download_file` but uses
the local ``_session``
"""
response = self._session.get(url, timeout=timeout, stream=True,
auth=auth)
if 'content-length' in response.headers:
length = int(response.headers['content-length'])
else:
length = 1
pb = ProgressBar(length)
blocksize = astropy.utils.data.conf.download_block_size
bytes_read = 0
with open(local_filepath, 'wb') as f:
for block in response.iter_content(blocksize):
f.write(block)
bytes_read += blocksize
pb.update(bytes_read if bytes_read <= length else length)
response.close()
示例4: download_hitran
def download_hitran(m, i, numin, numax):
"""
Download HITRAN data for a particular molecule. Based on fetch function from
hapi.py.
Parameters
----------
m : int
HITRAN molecule number
i : int
HITRAN isotopologue number
numin : real
lower wavenumber bound
numax : real
upper wavenumber bound
"""
iso_id = str(ISO[(m, i)][ISO_INDEX["id"]])
mol_name = ISO[(m, i)][ISO_INDEX["mol_name"]]
filename = os.path.join(cache_location, "{0}.data".format(mol_name))
CHUNK = 64 * 1024
data = dict(iso_ids_list=iso_id, numin=numin, numax=numax)
with open(filename, "w") as fp:
response = commons.send_request(HITRAN_URL, data, 10, request_type="GET")
if "Content-Length" in response.headers:
total_length = response.headers.get("Content-Length")
pb = ProgressBar(int(total_length))
for chunk in response.iter_content(chunk_size=CHUNK):
fp.write(chunk.decode("utf-8"))
try:
pb.update(CHUNK)
except NameError:
pass
示例5: fit_ch3cn_lines
def fit_ch3cn_lines(spectra, save_prefix, velo=56*u.km/u.s, ampguess=-0.01):
all_ch3cn = table.vstack([ch3cn, ch3cn_v])
all_ch3cn.add_column(table.Column(name='FittedAmplitude', data=np.zeros(len(all_ch3cn))))
all_ch3cn.add_column(table.Column(name='FittedCenter', data=np.zeros(len(all_ch3cn))))
all_ch3cn.add_column(table.Column(name='FittedWidth', data=np.zeros(len(all_ch3cn))))
all_ch3cn.add_column(table.Column(name='FittedAmplitudeError', data=np.zeros(len(all_ch3cn))))
all_ch3cn.add_column(table.Column(name='FittedCenterError', data=np.zeros(len(all_ch3cn))))
all_ch3cn.add_column(table.Column(name='FittedWidthError', data=np.zeros(len(all_ch3cn))))
vkms = velo.to(u.km/u.s).value
pl.figure(1).clf()
ax = pl.gca()
pb = ProgressBar(len(spectra) * len(all_ch3cn))
ii = 0
for sp in spectra:
sp.xarr.convert_to_unit(u.GHz)
mid = np.median(sp.data)
for line in all_ch3cn:
frq = line['Freq-GHz']*u.GHz
if sp.xarr.in_range(frq*(1-velo/constants.c)):
offset = ii*0.000 + mid
ii += 1
sp.xarr.convert_to_unit(u.km/u.s, refX=frq)
sp.plotter(axis=ax, clear=False, offset=offset)
sp.specfit(fittype='vheightgaussian',
guesses=[mid, ampguess, vkms, 2],)
line['FittedAmplitude'] = sp.specfit.parinfo['AMPLITUDE0'].value
line['FittedCenter'] = sp.specfit.parinfo['SHIFT0'].value
line['FittedWidth'] = sp.specfit.parinfo['WIDTH0'].value
line['FittedAmplitudeError'] = sp.specfit.parinfo['AMPLITUDE0'].error
line['FittedCenterError'] = sp.specfit.parinfo['SHIFT0'].error
line['FittedWidthError'] = sp.specfit.parinfo['WIDTH0'].error
sp.xarr.convert_to_unit(u.GHz)
pb.update()
pl.xlim(vkms-14, vkms+14)
#pl.ylim(0, offset)
pl.draw()
pl.show()
pl.savefig(save_prefix+"_spectra_overlay.png")
pl.figure(2).clf()
pl.plot(all_ch3cn['E_U (K)'], all_ch3cn['FittedWidth'], 'o')
pl.xlabel("E$_U$ (K)")
pl.ylabel("$\sigma$ (km/s)")
pl.ylim(0,3.5)
pl.savefig(save_prefix+"_sigma_vs_eupper.png")
pl.figure(3).clf()
pl.plot(all_ch3cn['E_U (K)'], all_ch3cn['FittedCenter'], 'o')
pl.xlabel("E$_U$ (K)")
pl.ylabel("$v_{lsr}$ (km/s)")
pl.ylim(vkms-3, vkms+3)
pl.savefig(save_prefix+"_vcen_vs_eupper.png")
示例6: _map
def _map(self, func, items):
# FIXME: ProgressBar.map(..., multiprocess=True) uses imap_unordered,
# but we want the result to come back in order. This should be fixed,
# or at least correctly documented, in Astropy.
if self.multiprocess:
_, result = zip(*sorted(ProgressBar.map(_mapfunc(func),
list(enumerate(items)),
multiprocess=True)))
return list(result)
else:
return ProgressBar.map(func, items, multiprocess=False)
示例7: spectral_regrid
def spectral_regrid(cube, outgrid):
"""
Spectrally regrid a cube onto a new spectral output grid
(this is apparently redundant with regrid_cube_hdu)
"""
assert isinstance(cube, SpectralCube)
inaxis = cube.spectral_axis.to(outgrid.unit)
indiff = np.mean(np.diff(inaxis))
outdiff = np.mean(np.diff(outgrid))
if outdiff < 0:
outgrid=outgrid[::-1]
outdiff = np.mean(np.diff(outgrid))
if indiff < 0:
cubedata = cube.filled_data[::-1]
inaxis = cube.spectral_axis.to(outgrid.unit)[::-1]
indiff = np.mean(np.diff(inaxis))
else:
cubedata = cube.filled_data[:]
if indiff < 0 or outdiff < 0:
raise ValueError("impossible.")
assert np.all(np.diff(outgrid) > 0)
assert np.all(np.diff(inaxis) > 0)
np.testing.assert_allclose(np.diff(outgrid), outdiff,
err_msg="Output grid must be linear")
if outdiff > 2 * indiff:
raise ValueError("Input grid has too small a spacing. It needs to be "
"smoothed prior to resampling.")
newcube = np.empty([outgrid.size, cube.shape[1], cube.shape[2]])
yy,xx = np.indices(cube.shape[1:])
pb = ProgressBar(xx.size)
for ix, iy in (zip(xx.flat, yy.flat)):
newcube[:,iy,ix] = np.interp(outgrid.value, inaxis.value,
cubedata[:,iy,ix].value)
pb.update()
newheader = cube.header
newheader['CRPIX3'] = 1
newheader['CRVAL3'] = outgrid[0].value
newheader['CDELT3'] = outdiff.value
newheader['CUNIT3'] = outgrid.unit.to_string('FITS')
return fits.PrimaryHDU(data=newcube, header=newheader)
示例8: download_file
def download_file(url, outdir=rawpath):
r = requests.get(url, verify=False, stream=True)
_, cdisp = cgi.parse_header(r.headers['content-disposition'])
outfilename = cdisp['filename']
fullname = os.path.join(outdir, outfilename)
pb = ProgressBar(int(r.headers['content-length']))
with open(fullname, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
f.write(chunk)
f.flush()
pb.update(pb._current_value + 1024)
return fullname
示例9: fit_all_tex
def fit_all_tex(xaxis, cube, cubefrequencies, indices, degeneracies,
ecube=None,
replace_bad=False):
"""
Parameters
----------
replace_bad : bool
Attempt to replace bad (negative) values with their upper limits?
"""
tmap = np.empty(cube.shape[1:])
Nmap = np.empty(cube.shape[1:])
yy,xx = np.indices(cube.shape[1:])
pb = ProgressBar(xx.size)
count=0
for ii,jj in (zip(yy.flat, xx.flat)):
if any(np.isnan(cube[:,ii,jj])):
tmap[ii,jj] = np.nan
else:
if replace_bad:
uplims = nupper_of_kkms(replace_bad, cubefrequencies,
einsteinAij[indices], degeneracies,).value
else:
uplims = None
nuppers = nupper_of_kkms(cube[:,ii,jj], cubefrequencies,
einsteinAij[indices], degeneracies,
)
if ecube is not None:
nupper_error = nupper_of_kkms(ecube[:,ii,jj], cubefrequencies,
einsteinAij[indices], degeneracies,).value
uplims = 3 * nupper_error
if replace_bad:
raise ValueError("replace_bad is ignored now...")
else:
nupper_error = None
fit_result = fit_tex(xaxis, nuppers.value,
errors=nupper_error,
uplims=uplims)
tmap[ii,jj] = fit_result[1].value
Nmap[ii,jj] = fit_result[0].value
pb.update(count)
count+=1
return tmap,Nmap
示例10: init_progressbar
def init_progressbar(self):
"""
Initialise the progress bar.
This only happens if run command is called with ``progressbar=True``.
"""
self.progressbar = ProgressBar(self.command_count())
示例11: _find_and_fit_peaks
def _find_and_fit_peaks(self):
"""Find and fit peaks in each PSD. This can be done in parallell if requested.
Configuration Items:
- ``FMTS.fitting`` The dictionary of parameters used for :func`find_and_fit_peaks`.
- ``FMTS.multiprocess`` `(bool)` whether to parallelize.
Peaks are stored in an object array, and the number of peaks at each mode is stored in a separate, parallel array.
"""
from astropy.utils.console import ProgressBar
kwargs = dict(self.config["FMTS.fitting"])
psd = self.psd
template = self.template_ft
omega = self.omega
args = [ ((k,l),psd[:,k,l],template,omega,kwargs) for k,l in itertools.product(range(self.psd.shape[1]),range(self.psd.shape[2])) ]
peaks = ProgressBar.map(pool_find_and_fit_peaks_in_modes,args,multiprocess=self.config["FMTS.multiprocess"])
for peak_mode,ident in peaks:
k,l = ident
self.peaks[k,l] = peak_mode
self.npeaks[k,l] = len(peak_mode)
self.log.info("Found %d peaks",np.sum(self.npeaks))
示例12: run
def run(self):
SERVER = os.environ["PY4SCI_SERVER"]
USER = os.environ["PY4SCI_USER"]
import getpass
from ftplib import FTP
from astropy.utils.console import ProgressBar
ftp = FTP(SERVER)
ftp.login(user=USER, passwd=getpass.getpass())
ftp.cwd('/public_html/PY4SCI_WS_2013_14')
for slides in ProgressBar.iterate(glob.glob('lectures/data/*')
+ glob.glob('lectures/*.html')
+ ['lectures/custom.css']
+ glob.glob('problems/data/*')
+ glob.glob('problems/*.html')
+ glob.glob('practice/data/*')
+ glob.glob('practice/*.html')):
try:
remote_size = ftp.size(slides)
except:
remote_size = None
local_size = os.path.getsize(slides)
if local_size != remote_size:
ftp.storbinary('STOR ' + slides, open(slides, 'rb'))
ftp.storbinary('STOR index.html', open('index.html', 'rb'))
ftp.quit()
示例13: run
def run(self):
SERVER = os.environ["PY4SCI_SERVER"]
USER = os.environ["PY4SCI_USER"]
import getpass
from ftplib import FTP
from astropy.utils.console import ProgressBar
ftp = FTP(SERVER)
ftp.login(user=USER, passwd=getpass.getpass())
ftp.cwd('/public_html/astropy4herts')
for slides in ProgressBar.iterate(glob.glob('notebooks/data/*')
+ glob.glob('notebooks/*.html')):
try:
remote_size = ftp.size(slides)
except:
remote_size = None
local_size = os.path.getsize(slides)
if local_size != remote_size:
ftp.storbinary('STOR ' + slides, open(slides, 'rb'))
ftp.storbinary('STOR notebooks.html', open('notebooks.html', 'rb'))
ftp.quit()
示例14: extract_poly_slice
def extract_poly_slice(cube, polygons):
nx = len(polygons)
nz = cube.shape[0]
total_slice = np.zeros((nz, nx))
total_area = np.zeros((nz, nx))
p = ProgressBar(len(polygons))
for i, polygon in enumerate(polygons):
p.update()
# Find bounding box
bbxmin = int(round(np.min(polygon.x)) - 1)
bbxmax = int(round(np.max(polygon.x)) + 2)
bbymin = int(round(np.min(polygon.y)) - 1)
bbymax = int(round(np.max(polygon.y)) + 2)
# Clip to cube box
bbxmin = max(bbxmin, 0)
bbxmax = min(bbxmax, cube.shape[2])
bbymin = max(bbymin, 0)
bbymax = min(bbymax, cube.shape[1])
# Loop through pixels that might overlap
for xmin in np.arange(bbxmin, bbxmax):
for ymin in np.arange(bbymin, bbymax):
area = square_polygon_overlap_area(xmin - 0.5, xmin + 0.5, ymin - 0.5, ymin + 0.5, polygon.x, polygon.y)
if area > 0:
total_slice[:, i] += cube[:, ymin, xmin] * area
total_area[:, i] += area
total_slice[total_area == 0.0] = np.nan
total_slice[total_area > 0.0] /= total_area[total_area > 0.0]
print("")
return total_slice
示例15: _HEADER_data_size
def _HEADER_data_size(self, files):
"""
Given a list of file URLs, return the data size. This is useful for
assessing how much data you might be downloading!
(This is discouraged by the ALMA archive, as it puts unnecessary load
on their system)
"""
totalsize = 0 * u.B
data_sizes = {}
pb = ProgressBar(len(files))
for ii, fileLink in enumerate(files):
response = self._request('HEAD', fileLink, stream=False,
cache=False, timeout=self.TIMEOUT)
filesize = (int(response.headers['content-length']) * u.B).to(u.GB)
totalsize += filesize
data_sizes[fileLink] = filesize
log.debug("File {0}: size {1}".format(fileLink, filesize))
pb.update(ii + 1)
response.raise_for_status()
return data_sizes, totalsize.to(u.GB)