id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
14,300 | sibirrer/lenstronomy | lenstronomy/Workflow/fitting_sequence.py | FittingSequence.pso | def pso(self, n_particles, n_iterations, sigma_scale=1, print_key='PSO', threadCount=1):
"""
Particle Swarm Optimization
:param n_particles: number of particles in the Particle Swarm Optimization
:param n_iterations: number of iterations in the optimization process
:param sigma_scale: scaling of the initial parameter spread relative to the width in the initial settings
:param print_key: string, printed text when executing this routine
:param threadCount: number of CPU threads. If MPI option is set, threadCount=1
:return: result of the best fit, the chain of the best fit parameter after each iteration, list of parameters in same order
"""
param_class = self._param_class
init_pos = param_class.kwargs2args(self._lens_temp, self._source_temp, self._lens_light_temp, self._ps_temp,
self._cosmo_temp)
lens_sigma, source_sigma, lens_light_sigma, ps_sigma, cosmo_sigma = self._updateManager.sigma_kwargs
sigma_start = param_class.kwargs2args(lens_sigma, source_sigma, lens_light_sigma, ps_sigma, cosmo_sigma)
lowerLimit = np.array(init_pos) - np.array(sigma_start) * sigma_scale
upperLimit = np.array(init_pos) + np.array(sigma_start) * sigma_scale
num_param, param_list = param_class.num_param()
# run PSO
sampler = Sampler(likelihoodModule=self.likelihoodModule)
result, chain = sampler.pso(n_particles, n_iterations, lowerLimit, upperLimit, init_pos=init_pos,
threadCount=threadCount, mpi=self._mpi, print_key=print_key)
lens_result, source_result, lens_light_result, ps_result, cosmo_result = param_class.args2kwargs(result,
bijective=True)
return lens_result, source_result, lens_light_result, ps_result, cosmo_result, chain, param_list | python | def pso(self, n_particles, n_iterations, sigma_scale=1, print_key='PSO', threadCount=1):
param_class = self._param_class
init_pos = param_class.kwargs2args(self._lens_temp, self._source_temp, self._lens_light_temp, self._ps_temp,
self._cosmo_temp)
lens_sigma, source_sigma, lens_light_sigma, ps_sigma, cosmo_sigma = self._updateManager.sigma_kwargs
sigma_start = param_class.kwargs2args(lens_sigma, source_sigma, lens_light_sigma, ps_sigma, cosmo_sigma)
lowerLimit = np.array(init_pos) - np.array(sigma_start) * sigma_scale
upperLimit = np.array(init_pos) + np.array(sigma_start) * sigma_scale
num_param, param_list = param_class.num_param()
# run PSO
sampler = Sampler(likelihoodModule=self.likelihoodModule)
result, chain = sampler.pso(n_particles, n_iterations, lowerLimit, upperLimit, init_pos=init_pos,
threadCount=threadCount, mpi=self._mpi, print_key=print_key)
lens_result, source_result, lens_light_result, ps_result, cosmo_result = param_class.args2kwargs(result,
bijective=True)
return lens_result, source_result, lens_light_result, ps_result, cosmo_result, chain, param_list | [
"def",
"pso",
"(",
"self",
",",
"n_particles",
",",
"n_iterations",
",",
"sigma_scale",
"=",
"1",
",",
"print_key",
"=",
"'PSO'",
",",
"threadCount",
"=",
"1",
")",
":",
"param_class",
"=",
"self",
".",
"_param_class",
"init_pos",
"=",
"param_class",
".",
... | Particle Swarm Optimization
:param n_particles: number of particles in the Particle Swarm Optimization
:param n_iterations: number of iterations in the optimization process
:param sigma_scale: scaling of the initial parameter spread relative to the width in the initial settings
:param print_key: string, printed text when executing this routine
:param threadCount: number of CPU threads. If MPI option is set, threadCount=1
:return: result of the best fit, the chain of the best fit parameter after each iteration, list of parameters in same order | [
"Particle",
"Swarm",
"Optimization"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Workflow/fitting_sequence.py#L169-L196 |
14,301 | sibirrer/lenstronomy | lenstronomy/Workflow/fitting_sequence.py | FittingSequence.psf_iteration | def psf_iteration(self, num_iter=10, no_break=True, stacking_method='median', block_center_neighbour=0, keep_psf_error_map=True,
psf_symmetry=1, psf_iter_factor=1, verbose=True, compute_bands=None):
"""
iterative PSF reconstruction
:param num_iter: number of iterations in the process
:param no_break: bool, if False will break the process as soon as one step lead to a wors reconstruction then the previous step
:param stacking_method: string, 'median' and 'mean' supported
:param block_center_neighbour: radius of neighbouring point source to be blocked in the reconstruction
:param keep_psf_error_map: bool, whether or not to keep the previous psf_error_map
:param psf_symmetry: int, number of invariant rotations in the reconstructed PSF
:param psf_iter_factor: factor of new estimated PSF relative to the old one PSF_updated = (1-psf_iter_factor) * PSF_old + psf_iter_factor*PSF_new
:param verbose: bool, print statements
:param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands
:return: 0, updated PSF is stored in self.mult_iband_list
"""
#lens_temp = copy.deepcopy(lens_input)
kwargs_model = self._updateManager.kwargs_model
param_class = self._param_class
lens_updated = param_class.update_lens_scaling(self._cosmo_temp, self._lens_temp)
source_updated = param_class.image2source_plane(self._source_temp, lens_updated)
if compute_bands is None:
compute_bands = [True] * len(self.multi_band_list)
for i in range(len(self.multi_band_list)):
if compute_bands[i] is True:
kwargs_data = self.multi_band_list[i][0]
kwargs_psf = self.multi_band_list[i][1]
kwargs_numerics = self.multi_band_list[i][2]
image_model = class_creator.create_image_model(kwargs_data=kwargs_data,
kwargs_psf=kwargs_psf,
kwargs_numerics=kwargs_numerics,
kwargs_model=kwargs_model)
psf_iter = PsfFitting(image_model_class=image_model)
kwargs_psf = psf_iter.update_iterative(kwargs_psf, lens_updated, source_updated,
self._lens_light_temp, self._ps_temp, num_iter=num_iter,
no_break=no_break, stacking_method=stacking_method,
block_center_neighbour=block_center_neighbour,
keep_psf_error_map=keep_psf_error_map,
psf_symmetry=psf_symmetry, psf_iter_factor=psf_iter_factor, verbose=verbose)
self.multi_band_list[i][1] = kwargs_psf
return 0 | python | def psf_iteration(self, num_iter=10, no_break=True, stacking_method='median', block_center_neighbour=0, keep_psf_error_map=True,
psf_symmetry=1, psf_iter_factor=1, verbose=True, compute_bands=None):
#lens_temp = copy.deepcopy(lens_input)
kwargs_model = self._updateManager.kwargs_model
param_class = self._param_class
lens_updated = param_class.update_lens_scaling(self._cosmo_temp, self._lens_temp)
source_updated = param_class.image2source_plane(self._source_temp, lens_updated)
if compute_bands is None:
compute_bands = [True] * len(self.multi_band_list)
for i in range(len(self.multi_band_list)):
if compute_bands[i] is True:
kwargs_data = self.multi_band_list[i][0]
kwargs_psf = self.multi_band_list[i][1]
kwargs_numerics = self.multi_band_list[i][2]
image_model = class_creator.create_image_model(kwargs_data=kwargs_data,
kwargs_psf=kwargs_psf,
kwargs_numerics=kwargs_numerics,
kwargs_model=kwargs_model)
psf_iter = PsfFitting(image_model_class=image_model)
kwargs_psf = psf_iter.update_iterative(kwargs_psf, lens_updated, source_updated,
self._lens_light_temp, self._ps_temp, num_iter=num_iter,
no_break=no_break, stacking_method=stacking_method,
block_center_neighbour=block_center_neighbour,
keep_psf_error_map=keep_psf_error_map,
psf_symmetry=psf_symmetry, psf_iter_factor=psf_iter_factor, verbose=verbose)
self.multi_band_list[i][1] = kwargs_psf
return 0 | [
"def",
"psf_iteration",
"(",
"self",
",",
"num_iter",
"=",
"10",
",",
"no_break",
"=",
"True",
",",
"stacking_method",
"=",
"'median'",
",",
"block_center_neighbour",
"=",
"0",
",",
"keep_psf_error_map",
"=",
"True",
",",
"psf_symmetry",
"=",
"1",
",",
"psf_... | iterative PSF reconstruction
:param num_iter: number of iterations in the process
:param no_break: bool, if False will break the process as soon as one step lead to a wors reconstruction then the previous step
:param stacking_method: string, 'median' and 'mean' supported
:param block_center_neighbour: radius of neighbouring point source to be blocked in the reconstruction
:param keep_psf_error_map: bool, whether or not to keep the previous psf_error_map
:param psf_symmetry: int, number of invariant rotations in the reconstructed PSF
:param psf_iter_factor: factor of new estimated PSF relative to the old one PSF_updated = (1-psf_iter_factor) * PSF_old + psf_iter_factor*PSF_new
:param verbose: bool, print statements
:param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands
:return: 0, updated PSF is stored in self.mult_iband_list | [
"iterative",
"PSF",
"reconstruction"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Workflow/fitting_sequence.py#L198-L239 |
14,302 | sibirrer/lenstronomy | lenstronomy/Workflow/fitting_sequence.py | FittingSequence.align_images | def align_images(self, n_particles=10, n_iterations=10, lowerLimit=-0.2, upperLimit=0.2, threadCount=1,
compute_bands=None):
"""
aligns the coordinate systems of different exposures within a fixed model parameterisation by executing a PSO
with relative coordinate shifts as free parameters
:param n_particles: number of particles in the Particle Swarm Optimization
:param n_iterations: number of iterations in the optimization process
:param lowerLimit: lower limit of relative shift
:param upperLimit: upper limit of relative shift
:param verbose: bool, print statements
:param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands
:return:
"""
kwargs_model = self._updateManager.kwargs_model
param_class = self._updateManager.param_class(self._lens_temp)
lens_updated = param_class.update_lens_scaling(self._cosmo_temp, self._lens_temp)
source_updated = param_class.image2source_plane(self._source_temp, lens_updated)
if compute_bands is None:
compute_bands = [True] * len(self.multi_band_list)
for i in range(len(self.multi_band_list)):
if compute_bands[i] is True:
kwargs_data = self.multi_band_list[i][0]
kwargs_psf = self.multi_band_list[i][1]
kwargs_numerics = self.multi_band_list[i][2]
alignmentFitting = AlignmentFitting(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model, lens_updated, source_updated,
self._lens_light_temp, self._ps_temp)
kwargs_data, chain = alignmentFitting.pso(n_particles=n_particles, n_iterations=n_iterations,
lowerLimit=lowerLimit, upperLimit=upperLimit,
threadCount=threadCount, mpi=self._mpi,
print_key='Alignment fitting for band %s ...' % i)
print('Align completed for band %s.' % i)
print('ra_shift: %s, dec_shift: %s' %(kwargs_data['ra_shift'], kwargs_data['dec_shift']))
self.multi_band_list[i][0] = kwargs_data
return 0 | python | def align_images(self, n_particles=10, n_iterations=10, lowerLimit=-0.2, upperLimit=0.2, threadCount=1,
compute_bands=None):
kwargs_model = self._updateManager.kwargs_model
param_class = self._updateManager.param_class(self._lens_temp)
lens_updated = param_class.update_lens_scaling(self._cosmo_temp, self._lens_temp)
source_updated = param_class.image2source_plane(self._source_temp, lens_updated)
if compute_bands is None:
compute_bands = [True] * len(self.multi_band_list)
for i in range(len(self.multi_band_list)):
if compute_bands[i] is True:
kwargs_data = self.multi_band_list[i][0]
kwargs_psf = self.multi_band_list[i][1]
kwargs_numerics = self.multi_band_list[i][2]
alignmentFitting = AlignmentFitting(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model, lens_updated, source_updated,
self._lens_light_temp, self._ps_temp)
kwargs_data, chain = alignmentFitting.pso(n_particles=n_particles, n_iterations=n_iterations,
lowerLimit=lowerLimit, upperLimit=upperLimit,
threadCount=threadCount, mpi=self._mpi,
print_key='Alignment fitting for band %s ...' % i)
print('Align completed for band %s.' % i)
print('ra_shift: %s, dec_shift: %s' %(kwargs_data['ra_shift'], kwargs_data['dec_shift']))
self.multi_band_list[i][0] = kwargs_data
return 0 | [
"def",
"align_images",
"(",
"self",
",",
"n_particles",
"=",
"10",
",",
"n_iterations",
"=",
"10",
",",
"lowerLimit",
"=",
"-",
"0.2",
",",
"upperLimit",
"=",
"0.2",
",",
"threadCount",
"=",
"1",
",",
"compute_bands",
"=",
"None",
")",
":",
"kwargs_model... | aligns the coordinate systems of different exposures within a fixed model parameterisation by executing a PSO
with relative coordinate shifts as free parameters
:param n_particles: number of particles in the Particle Swarm Optimization
:param n_iterations: number of iterations in the optimization process
:param lowerLimit: lower limit of relative shift
:param upperLimit: upper limit of relative shift
:param verbose: bool, print statements
:param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands
:return: | [
"aligns",
"the",
"coordinate",
"systems",
"of",
"different",
"exposures",
"within",
"a",
"fixed",
"model",
"parameterisation",
"by",
"executing",
"a",
"PSO",
"with",
"relative",
"coordinate",
"shifts",
"as",
"free",
"parameters"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Workflow/fitting_sequence.py#L241-L277 |
14,303 | sibirrer/lenstronomy | lenstronomy/Workflow/fitting_sequence.py | FittingSequence.update_settings | def update_settings(self, kwargs_model={}, kwargs_constraints={}, kwargs_likelihood={}, lens_add_fixed=[],
source_add_fixed=[], lens_light_add_fixed=[], ps_add_fixed=[], cosmo_add_fixed=[], lens_remove_fixed=[],
source_remove_fixed=[], lens_light_remove_fixed=[], ps_remove_fixed=[], cosmo_remove_fixed=[],
change_source_lower_limit=None, change_source_upper_limit=None):
"""
updates lenstronomy settings "on the fly"
:param kwargs_model: kwargs, specified keyword arguments overwrite the existing ones
:param kwargs_constraints: kwargs, specified keyword arguments overwrite the existing ones
:param kwargs_likelihood: kwargs, specified keyword arguments overwrite the existing ones
:param lens_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param source_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param lens_light_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param ps_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param cosmo_add_fixed: ['param1', 'param2',...]
:param lens_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param source_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param lens_light_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param ps_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param cosmo_remove_fixed: ['param1', 'param2',...]
:return: 0, the settings are overwritten for the next fitting step to come
"""
self._updateManager.update_options(kwargs_model, kwargs_constraints, kwargs_likelihood)
self._updateManager.update_fixed(self._lens_temp, self._source_temp, self._lens_light_temp, self._ps_temp,
self._cosmo_temp, lens_add_fixed, source_add_fixed, lens_light_add_fixed,
ps_add_fixed, cosmo_add_fixed, lens_remove_fixed, source_remove_fixed,
lens_light_remove_fixed, ps_remove_fixed, cosmo_remove_fixed)
self._updateManager.update_limits(change_source_lower_limit, change_source_upper_limit)
return 0 | python | def update_settings(self, kwargs_model={}, kwargs_constraints={}, kwargs_likelihood={}, lens_add_fixed=[],
source_add_fixed=[], lens_light_add_fixed=[], ps_add_fixed=[], cosmo_add_fixed=[], lens_remove_fixed=[],
source_remove_fixed=[], lens_light_remove_fixed=[], ps_remove_fixed=[], cosmo_remove_fixed=[],
change_source_lower_limit=None, change_source_upper_limit=None):
self._updateManager.update_options(kwargs_model, kwargs_constraints, kwargs_likelihood)
self._updateManager.update_fixed(self._lens_temp, self._source_temp, self._lens_light_temp, self._ps_temp,
self._cosmo_temp, lens_add_fixed, source_add_fixed, lens_light_add_fixed,
ps_add_fixed, cosmo_add_fixed, lens_remove_fixed, source_remove_fixed,
lens_light_remove_fixed, ps_remove_fixed, cosmo_remove_fixed)
self._updateManager.update_limits(change_source_lower_limit, change_source_upper_limit)
return 0 | [
"def",
"update_settings",
"(",
"self",
",",
"kwargs_model",
"=",
"{",
"}",
",",
"kwargs_constraints",
"=",
"{",
"}",
",",
"kwargs_likelihood",
"=",
"{",
"}",
",",
"lens_add_fixed",
"=",
"[",
"]",
",",
"source_add_fixed",
"=",
"[",
"]",
",",
"lens_light_add... | updates lenstronomy settings "on the fly"
:param kwargs_model: kwargs, specified keyword arguments overwrite the existing ones
:param kwargs_constraints: kwargs, specified keyword arguments overwrite the existing ones
:param kwargs_likelihood: kwargs, specified keyword arguments overwrite the existing ones
:param lens_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param source_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param lens_light_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param ps_add_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param cosmo_add_fixed: ['param1', 'param2',...]
:param lens_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param source_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param lens_light_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param ps_remove_fixed: [[i_model, ['param1', 'param2',...], [...]]
:param cosmo_remove_fixed: ['param1', 'param2',...]
:return: 0, the settings are overwritten for the next fitting step to come | [
"updates",
"lenstronomy",
"settings",
"on",
"the",
"fly"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Workflow/fitting_sequence.py#L279-L307 |
14,304 | sibirrer/lenstronomy | lenstronomy/GalKin/anisotropy.py | MamonLokasAnisotropy._B | def _B(self, x, a, b):
"""
incomplete Beta function as described in Mamon&Lokas A13
:param x:
:param a:
:param b:
:return:
"""
return special.betainc(a, b, x) * special.beta(a, b) | python | def _B(self, x, a, b):
return special.betainc(a, b, x) * special.beta(a, b) | [
"def",
"_B",
"(",
"self",
",",
"x",
",",
"a",
",",
"b",
")",
":",
"return",
"special",
".",
"betainc",
"(",
"a",
",",
"b",
",",
"x",
")",
"*",
"special",
".",
"beta",
"(",
"a",
",",
"b",
")"
] | incomplete Beta function as described in Mamon&Lokas A13
:param x:
:param a:
:param b:
:return: | [
"incomplete",
"Beta",
"function",
"as",
"described",
"in",
"Mamon&Lokas",
"A13"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/GalKin/anisotropy.py#L82-L91 |
14,305 | sibirrer/lenstronomy | lenstronomy/Workflow/update_manager.py | UpdateManager.update_fixed | def update_fixed(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_cosmo, lens_add_fixed=[],
source_add_fixed=[], lens_light_add_fixed=[], ps_add_fixed=[], cosmo_add_fixed=[], lens_remove_fixed=[],
source_remove_fixed=[], lens_light_remove_fixed=[], ps_remove_fixed=[], cosmo_remove_fixed=[]):
"""
adds the values of the keyword arguments that are stated in the _add_fixed to the existing fixed arguments.
:param kwargs_lens:
:param kwargs_source:
:param kwargs_lens_light:
:param kwargs_ps:
:param kwargs_cosmo:
:param lens_add_fixed:
:param source_add_fixed:
:param lens_light_add_fixed:
:param ps_add_fixed:
:param cosmo_add_fixed:
:return: updated kwargs fixed
"""
lens_fixed = self._add_fixed(kwargs_lens, self._lens_fixed, lens_add_fixed)
lens_fixed = self._remove_fixed(lens_fixed, lens_remove_fixed)
source_fixed = self._add_fixed(kwargs_source, self._source_fixed, source_add_fixed)
source_fixed = self._remove_fixed(source_fixed, source_remove_fixed)
lens_light_fixed = self._add_fixed(kwargs_lens_light, self._lens_light_fixed, lens_light_add_fixed)
lens_light_fixed = self._remove_fixed(lens_light_fixed, lens_light_remove_fixed)
ps_fixed = self._add_fixed(kwargs_ps, self._ps_fixed, ps_add_fixed)
ps_fixed = self._remove_fixed(ps_fixed, ps_remove_fixed)
cosmo_fixed = copy.deepcopy(self._cosmo_fixed)
for param_name in cosmo_add_fixed:
if param_name in cosmo_fixed:
pass
else:
cosmo_fixed[param_name] = kwargs_cosmo[param_name]
for param_name in cosmo_remove_fixed:
if param_name in cosmo_fixed:
del cosmo_fixed[param_name]
self._lens_fixed, self._source_fixed, self._lens_light_fixed, self._ps_fixed, self._cosmo_fixed = lens_fixed, source_fixed, lens_light_fixed, ps_fixed, cosmo_fixed | python | def update_fixed(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_cosmo, lens_add_fixed=[],
source_add_fixed=[], lens_light_add_fixed=[], ps_add_fixed=[], cosmo_add_fixed=[], lens_remove_fixed=[],
source_remove_fixed=[], lens_light_remove_fixed=[], ps_remove_fixed=[], cosmo_remove_fixed=[]):
lens_fixed = self._add_fixed(kwargs_lens, self._lens_fixed, lens_add_fixed)
lens_fixed = self._remove_fixed(lens_fixed, lens_remove_fixed)
source_fixed = self._add_fixed(kwargs_source, self._source_fixed, source_add_fixed)
source_fixed = self._remove_fixed(source_fixed, source_remove_fixed)
lens_light_fixed = self._add_fixed(kwargs_lens_light, self._lens_light_fixed, lens_light_add_fixed)
lens_light_fixed = self._remove_fixed(lens_light_fixed, lens_light_remove_fixed)
ps_fixed = self._add_fixed(kwargs_ps, self._ps_fixed, ps_add_fixed)
ps_fixed = self._remove_fixed(ps_fixed, ps_remove_fixed)
cosmo_fixed = copy.deepcopy(self._cosmo_fixed)
for param_name in cosmo_add_fixed:
if param_name in cosmo_fixed:
pass
else:
cosmo_fixed[param_name] = kwargs_cosmo[param_name]
for param_name in cosmo_remove_fixed:
if param_name in cosmo_fixed:
del cosmo_fixed[param_name]
self._lens_fixed, self._source_fixed, self._lens_light_fixed, self._ps_fixed, self._cosmo_fixed = lens_fixed, source_fixed, lens_light_fixed, ps_fixed, cosmo_fixed | [
"def",
"update_fixed",
"(",
"self",
",",
"kwargs_lens",
",",
"kwargs_source",
",",
"kwargs_lens_light",
",",
"kwargs_ps",
",",
"kwargs_cosmo",
",",
"lens_add_fixed",
"=",
"[",
"]",
",",
"source_add_fixed",
"=",
"[",
"]",
",",
"lens_light_add_fixed",
"=",
"[",
... | adds the values of the keyword arguments that are stated in the _add_fixed to the existing fixed arguments.
:param kwargs_lens:
:param kwargs_source:
:param kwargs_lens_light:
:param kwargs_ps:
:param kwargs_cosmo:
:param lens_add_fixed:
:param source_add_fixed:
:param lens_light_add_fixed:
:param ps_add_fixed:
:param cosmo_add_fixed:
:return: updated kwargs fixed | [
"adds",
"the",
"values",
"of",
"the",
"keyword",
"arguments",
"that",
"are",
"stated",
"in",
"the",
"_add_fixed",
"to",
"the",
"existing",
"fixed",
"arguments",
"."
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Workflow/update_manager.py#L136-L171 |
14,306 | sibirrer/lenstronomy | lenstronomy/GalKin/analytic_kinematics.py | AnalyticKinematics.vel_disp_one | def vel_disp_one(self, gamma, rho0_r0_gamma, r_eff, r_ani, R_slit, dR_slit, FWHM):
"""
computes one realisation of the velocity dispersion realized in the slit
:param gamma: power-law slope of the mass profile (isothermal = 2)
:param rho0_r0_gamma: combination of Einstein radius and power-law slope as equation (14) in Suyu+ 2010
:param r_eff: half light radius of the Hernquist profile (or as an approximation of any other profile to be described as a Hernquist profile
:param r_ani: anisotropy radius
:param R_slit: length of the slit/box
:param dR_slit: width of the slit/box
:param FWHM: full width at half maximum of the seeing conditions, described as a Gaussian
:return: projected velocity dispersion of a single drawn position in the potential [km/s]
"""
a = 0.551 * r_eff
while True:
r = self.P_r(a) # draw r
R, x, y = self.R_r(r) # draw projected R
x_, y_ = self.displace_PSF(x, y, FWHM) # displace via PSF
bool = self.check_in_slit(x_, y_, R_slit, dR_slit)
if bool is True:
break
sigma_s2 = self.sigma_s2(r, R, r_ani, a, gamma, rho0_r0_gamma)
return sigma_s2 | python | def vel_disp_one(self, gamma, rho0_r0_gamma, r_eff, r_ani, R_slit, dR_slit, FWHM):
a = 0.551 * r_eff
while True:
r = self.P_r(a) # draw r
R, x, y = self.R_r(r) # draw projected R
x_, y_ = self.displace_PSF(x, y, FWHM) # displace via PSF
bool = self.check_in_slit(x_, y_, R_slit, dR_slit)
if bool is True:
break
sigma_s2 = self.sigma_s2(r, R, r_ani, a, gamma, rho0_r0_gamma)
return sigma_s2 | [
"def",
"vel_disp_one",
"(",
"self",
",",
"gamma",
",",
"rho0_r0_gamma",
",",
"r_eff",
",",
"r_ani",
",",
"R_slit",
",",
"dR_slit",
",",
"FWHM",
")",
":",
"a",
"=",
"0.551",
"*",
"r_eff",
"while",
"True",
":",
"r",
"=",
"self",
".",
"P_r",
"(",
"a",... | computes one realisation of the velocity dispersion realized in the slit
:param gamma: power-law slope of the mass profile (isothermal = 2)
:param rho0_r0_gamma: combination of Einstein radius and power-law slope as equation (14) in Suyu+ 2010
:param r_eff: half light radius of the Hernquist profile (or as an approximation of any other profile to be described as a Hernquist profile
:param r_ani: anisotropy radius
:param R_slit: length of the slit/box
:param dR_slit: width of the slit/box
:param FWHM: full width at half maximum of the seeing conditions, described as a Gaussian
:return: projected velocity dispersion of a single drawn position in the potential [km/s] | [
"computes",
"one",
"realisation",
"of",
"the",
"velocity",
"dispersion",
"realized",
"in",
"the",
"slit"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/GalKin/analytic_kinematics.py#L67-L89 |
14,307 | sibirrer/lenstronomy | lenstronomy/Analysis/lens_analysis.py | LensAnalysis.ellipticity_lens_light | def ellipticity_lens_light(self, kwargs_lens_light, center_x=0, center_y=0, model_bool_list=None, deltaPix=None,
numPix=None):
"""
make sure that the window covers all the light, otherwise the moments may give to low answers.
:param kwargs_lens_light:
:param center_x:
:param center_y:
:param model_bool_list:
:param deltaPix:
:param numPix:
:return:
"""
if model_bool_list is None:
model_bool_list = [True] * len(kwargs_lens_light)
if numPix is None:
numPix = 100
if deltaPix is None:
deltaPix = 0.05
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
x_grid += center_x
y_grid += center_y
I_xy = self._lens_light_internal(x_grid, y_grid, kwargs_lens_light, model_bool_list=model_bool_list)
e1, e2 = analysis_util.ellipticities(I_xy, x_grid, y_grid)
return e1, e2 | python | def ellipticity_lens_light(self, kwargs_lens_light, center_x=0, center_y=0, model_bool_list=None, deltaPix=None,
numPix=None):
if model_bool_list is None:
model_bool_list = [True] * len(kwargs_lens_light)
if numPix is None:
numPix = 100
if deltaPix is None:
deltaPix = 0.05
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
x_grid += center_x
y_grid += center_y
I_xy = self._lens_light_internal(x_grid, y_grid, kwargs_lens_light, model_bool_list=model_bool_list)
e1, e2 = analysis_util.ellipticities(I_xy, x_grid, y_grid)
return e1, e2 | [
"def",
"ellipticity_lens_light",
"(",
"self",
",",
"kwargs_lens_light",
",",
"center_x",
"=",
"0",
",",
"center_y",
"=",
"0",
",",
"model_bool_list",
"=",
"None",
",",
"deltaPix",
"=",
"None",
",",
"numPix",
"=",
"None",
")",
":",
"if",
"model_bool_list",
... | make sure that the window covers all the light, otherwise the moments may give to low answers.
:param kwargs_lens_light:
:param center_x:
:param center_y:
:param model_bool_list:
:param deltaPix:
:param numPix:
:return: | [
"make",
"sure",
"that",
"the",
"window",
"covers",
"all",
"the",
"light",
"otherwise",
"the",
"moments",
"may",
"give",
"to",
"low",
"answers",
"."
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Analysis/lens_analysis.py#L42-L66 |
14,308 | sibirrer/lenstronomy | lenstronomy/Analysis/lens_analysis.py | LensAnalysis._lens_light_internal | def _lens_light_internal(self, x_grid, y_grid, kwargs_lens_light, model_bool_list=None):
"""
evaluates only part of the light profiles
:param x_grid:
:param y_grid:
:param kwargs_lens_light:
:return:
"""
if model_bool_list is None:
model_bool_list = [True] * len(kwargs_lens_light)
lens_light = np.zeros_like(x_grid)
for i, bool in enumerate(model_bool_list):
if bool is True:
lens_light_i = self.LensLightModel.surface_brightness(x_grid, y_grid, kwargs_lens_light, k=i)
lens_light += lens_light_i
return lens_light | python | def _lens_light_internal(self, x_grid, y_grid, kwargs_lens_light, model_bool_list=None):
if model_bool_list is None:
model_bool_list = [True] * len(kwargs_lens_light)
lens_light = np.zeros_like(x_grid)
for i, bool in enumerate(model_bool_list):
if bool is True:
lens_light_i = self.LensLightModel.surface_brightness(x_grid, y_grid, kwargs_lens_light, k=i)
lens_light += lens_light_i
return lens_light | [
"def",
"_lens_light_internal",
"(",
"self",
",",
"x_grid",
",",
"y_grid",
",",
"kwargs_lens_light",
",",
"model_bool_list",
"=",
"None",
")",
":",
"if",
"model_bool_list",
"is",
"None",
":",
"model_bool_list",
"=",
"[",
"True",
"]",
"*",
"len",
"(",
"kwargs_... | evaluates only part of the light profiles
:param x_grid:
:param y_grid:
:param kwargs_lens_light:
:return: | [
"evaluates",
"only",
"part",
"of",
"the",
"light",
"profiles"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Analysis/lens_analysis.py#L106-L122 |
14,309 | sibirrer/lenstronomy | lenstronomy/Analysis/lens_analysis.py | LensAnalysis.multi_gaussian_lens | def multi_gaussian_lens(self, kwargs_lens, model_bool_list=None, e1=0, e2=0, n_comp=20):
"""
multi-gaussian lens model in convergence space
:param kwargs_lens:
:param n_comp:
:return:
"""
if 'center_x' in kwargs_lens[0]:
center_x = kwargs_lens[0]['center_x']
center_y = kwargs_lens[0]['center_y']
else:
raise ValueError('no keyword center_x defined!')
theta_E = self._lensModelExtensions.effective_einstein_radius(kwargs_lens)
r_array = np.logspace(-4, 2, 200) * theta_E
x_coords, y_coords = param_util.transform_e1e2(r_array, np.zeros_like(r_array), e1=-e1, e2=-e2)
x_coords += center_x
y_coords += center_y
#r_array = np.logspace(-2, 1, 50) * theta_E
if model_bool_list is None:
model_bool_list = [True] * len(kwargs_lens)
kappa_s = np.zeros_like(r_array)
for i in range(len(kwargs_lens)):
if model_bool_list[i] is True:
kappa_s += self.LensModel.kappa(x_coords, y_coords, kwargs_lens, k=i)
amplitudes, sigmas, norm = mge.mge_1d(r_array, kappa_s, N=n_comp)
return amplitudes, sigmas, center_x, center_y | python | def multi_gaussian_lens(self, kwargs_lens, model_bool_list=None, e1=0, e2=0, n_comp=20):
if 'center_x' in kwargs_lens[0]:
center_x = kwargs_lens[0]['center_x']
center_y = kwargs_lens[0]['center_y']
else:
raise ValueError('no keyword center_x defined!')
theta_E = self._lensModelExtensions.effective_einstein_radius(kwargs_lens)
r_array = np.logspace(-4, 2, 200) * theta_E
x_coords, y_coords = param_util.transform_e1e2(r_array, np.zeros_like(r_array), e1=-e1, e2=-e2)
x_coords += center_x
y_coords += center_y
#r_array = np.logspace(-2, 1, 50) * theta_E
if model_bool_list is None:
model_bool_list = [True] * len(kwargs_lens)
kappa_s = np.zeros_like(r_array)
for i in range(len(kwargs_lens)):
if model_bool_list[i] is True:
kappa_s += self.LensModel.kappa(x_coords, y_coords, kwargs_lens, k=i)
amplitudes, sigmas, norm = mge.mge_1d(r_array, kappa_s, N=n_comp)
return amplitudes, sigmas, center_x, center_y | [
"def",
"multi_gaussian_lens",
"(",
"self",
",",
"kwargs_lens",
",",
"model_bool_list",
"=",
"None",
",",
"e1",
"=",
"0",
",",
"e2",
"=",
"0",
",",
"n_comp",
"=",
"20",
")",
":",
"if",
"'center_x'",
"in",
"kwargs_lens",
"[",
"0",
"]",
":",
"center_x",
... | multi-gaussian lens model in convergence space
:param kwargs_lens:
:param n_comp:
:return: | [
"multi",
"-",
"gaussian",
"lens",
"model",
"in",
"convergence",
"space"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Analysis/lens_analysis.py#L149-L175 |
14,310 | sibirrer/lenstronomy | lenstronomy/Analysis/lens_analysis.py | LensAnalysis.flux_components | def flux_components(self, kwargs_light, n_grid=400, delta_grid=0.01, deltaPix=0.05, type="lens"):
"""
computes the total flux in each component of the model
:param kwargs_light:
:param n_grid:
:param delta_grid:
:return:
"""
flux_list = []
R_h_list = []
x_grid, y_grid = util.make_grid(numPix=n_grid, deltapix=delta_grid)
kwargs_copy = copy.deepcopy(kwargs_light)
for k, kwargs in enumerate(kwargs_light):
if 'center_x' in kwargs_copy[k]:
kwargs_copy[k]['center_x'] = 0
kwargs_copy[k]['center_y'] = 0
if type == 'lens':
light = self.LensLightModel.surface_brightness(x_grid, y_grid, kwargs_copy, k=k)
elif type == 'source':
light = self.SourceModel.surface_brightness(x_grid, y_grid, kwargs_copy, k=k)
else:
raise ValueError("type %s not supported!" % type)
flux = np.sum(light)*delta_grid**2 / deltaPix**2
R_h = analysis_util.half_light_radius(light, x_grid, y_grid)
flux_list.append(flux)
R_h_list.append(R_h)
return flux_list, R_h_list | python | def flux_components(self, kwargs_light, n_grid=400, delta_grid=0.01, deltaPix=0.05, type="lens"):
flux_list = []
R_h_list = []
x_grid, y_grid = util.make_grid(numPix=n_grid, deltapix=delta_grid)
kwargs_copy = copy.deepcopy(kwargs_light)
for k, kwargs in enumerate(kwargs_light):
if 'center_x' in kwargs_copy[k]:
kwargs_copy[k]['center_x'] = 0
kwargs_copy[k]['center_y'] = 0
if type == 'lens':
light = self.LensLightModel.surface_brightness(x_grid, y_grid, kwargs_copy, k=k)
elif type == 'source':
light = self.SourceModel.surface_brightness(x_grid, y_grid, kwargs_copy, k=k)
else:
raise ValueError("type %s not supported!" % type)
flux = np.sum(light)*delta_grid**2 / deltaPix**2
R_h = analysis_util.half_light_radius(light, x_grid, y_grid)
flux_list.append(flux)
R_h_list.append(R_h)
return flux_list, R_h_list | [
"def",
"flux_components",
"(",
"self",
",",
"kwargs_light",
",",
"n_grid",
"=",
"400",
",",
"delta_grid",
"=",
"0.01",
",",
"deltaPix",
"=",
"0.05",
",",
"type",
"=",
"\"lens\"",
")",
":",
"flux_list",
"=",
"[",
"]",
"R_h_list",
"=",
"[",
"]",
"x_grid"... | computes the total flux in each component of the model
:param kwargs_light:
:param n_grid:
:param delta_grid:
:return: | [
"computes",
"the",
"total",
"flux",
"in",
"each",
"component",
"of",
"the",
"model"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Analysis/lens_analysis.py#L177-L204 |
14,311 | sibirrer/lenstronomy | lenstronomy/Analysis/lens_analysis.py | LensAnalysis.error_map_source | def error_map_source(self, kwargs_source, x_grid, y_grid, cov_param):
"""
variance of the linear source reconstruction in the source plane coordinates,
computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors
of the basis set.
:param kwargs_source: keyword arguments of source model
:param x_grid: x-axis of positions to compute error map
:param y_grid: y-axis of positions to compute error map
:param cov_param: covariance matrix of liner inversion parameters
:return: diagonal covariance errors at the positions (x_grid, y_grid)
"""
error_map = np.zeros_like(x_grid)
basis_functions, n_source = self.SourceModel.functions_split(x_grid, y_grid, kwargs_source)
basis_functions = np.array(basis_functions)
if cov_param is not None:
for i in range(len(error_map)):
error_map[i] = basis_functions[:, i].T.dot(cov_param[:n_source, :n_source]).dot(basis_functions[:, i])
return error_map | python | def error_map_source(self, kwargs_source, x_grid, y_grid, cov_param):
error_map = np.zeros_like(x_grid)
basis_functions, n_source = self.SourceModel.functions_split(x_grid, y_grid, kwargs_source)
basis_functions = np.array(basis_functions)
if cov_param is not None:
for i in range(len(error_map)):
error_map[i] = basis_functions[:, i].T.dot(cov_param[:n_source, :n_source]).dot(basis_functions[:, i])
return error_map | [
"def",
"error_map_source",
"(",
"self",
",",
"kwargs_source",
",",
"x_grid",
",",
"y_grid",
",",
"cov_param",
")",
":",
"error_map",
"=",
"np",
".",
"zeros_like",
"(",
"x_grid",
")",
"basis_functions",
",",
"n_source",
"=",
"self",
".",
"SourceModel",
".",
... | variance of the linear source reconstruction in the source plane coordinates,
computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors
of the basis set.
:param kwargs_source: keyword arguments of source model
:param x_grid: x-axis of positions to compute error map
:param y_grid: y-axis of positions to compute error map
:param cov_param: covariance matrix of liner inversion parameters
:return: diagonal covariance errors at the positions (x_grid, y_grid) | [
"variance",
"of",
"the",
"linear",
"source",
"reconstruction",
"in",
"the",
"source",
"plane",
"coordinates",
"computed",
"by",
"the",
"diagonal",
"elements",
"of",
"the",
"covariance",
"matrix",
"of",
"the",
"source",
"reconstruction",
"as",
"a",
"sum",
"of",
... | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Analysis/lens_analysis.py#L206-L226 |
14,312 | sibirrer/lenstronomy | lenstronomy/Analysis/lens_analysis.py | LensAnalysis.mass_fraction_within_radius | def mass_fraction_within_radius(self, kwargs_lens, center_x, center_y, theta_E, numPix=100):
"""
computes the mean convergence of all the different lens model components within a spherical aperture
:param kwargs_lens: lens model keyword argument list
:param center_x: center of the aperture
:param center_y: center of the aperture
:param theta_E: radius of aperture
:return: list of average convergences for all the model components
"""
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=2.*theta_E / numPix)
x_grid += center_x
y_grid += center_y
mask = mask_util.mask_sphere(x_grid, y_grid, center_x, center_y, theta_E)
kappa_list = []
for i in range(len(kwargs_lens)):
kappa = self.LensModel.kappa(x_grid, y_grid, kwargs_lens, k=i)
kappa_mean = np.sum(kappa * mask) / np.sum(mask)
kappa_list.append(kappa_mean)
return kappa_list | python | def mass_fraction_within_radius(self, kwargs_lens, center_x, center_y, theta_E, numPix=100):
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=2.*theta_E / numPix)
x_grid += center_x
y_grid += center_y
mask = mask_util.mask_sphere(x_grid, y_grid, center_x, center_y, theta_E)
kappa_list = []
for i in range(len(kwargs_lens)):
kappa = self.LensModel.kappa(x_grid, y_grid, kwargs_lens, k=i)
kappa_mean = np.sum(kappa * mask) / np.sum(mask)
kappa_list.append(kappa_mean)
return kappa_list | [
"def",
"mass_fraction_within_radius",
"(",
"self",
",",
"kwargs_lens",
",",
"center_x",
",",
"center_y",
",",
"theta_E",
",",
"numPix",
"=",
"100",
")",
":",
"x_grid",
",",
"y_grid",
"=",
"util",
".",
"make_grid",
"(",
"numPix",
"=",
"numPix",
",",
"deltap... | computes the mean convergence of all the different lens model components within a spherical aperture
:param kwargs_lens: lens model keyword argument list
:param center_x: center of the aperture
:param center_y: center of the aperture
:param theta_E: radius of aperture
:return: list of average convergences for all the model components | [
"computes",
"the",
"mean",
"convergence",
"of",
"all",
"the",
"different",
"lens",
"model",
"components",
"within",
"a",
"spherical",
"aperture"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Analysis/lens_analysis.py#L305-L324 |
14,313 | sibirrer/lenstronomy | lenstronomy/PointSource/point_source.py | PointSource.update_search_window | def update_search_window(self, search_window, x_center, y_center):
"""
update the search area for the lens equation solver
:param search_window: search_window: window size of the image position search with the lens equation solver.
:param x_center: center of search window
:param y_center: center of search window
:return: updated self instances
"""
self._search_window, self._x_center, self._y_center = search_window, x_center, y_center | python | def update_search_window(self, search_window, x_center, y_center):
self._search_window, self._x_center, self._y_center = search_window, x_center, y_center | [
"def",
"update_search_window",
"(",
"self",
",",
"search_window",
",",
"x_center",
",",
"y_center",
")",
":",
"self",
".",
"_search_window",
",",
"self",
".",
"_x_center",
",",
"self",
".",
"_y_center",
"=",
"search_window",
",",
"x_center",
",",
"y_center"
] | update the search area for the lens equation solver
:param search_window: search_window: window size of the image position search with the lens equation solver.
:param x_center: center of search window
:param y_center: center of search window
:return: updated self instances | [
"update",
"the",
"search",
"area",
"for",
"the",
"lens",
"equation",
"solver"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/PointSource/point_source.py#L60-L69 |
14,314 | sibirrer/lenstronomy | lenstronomy/PointSource/point_source.py | PointSource.point_source_list | def point_source_list(self, kwargs_ps, kwargs_lens, k=None):
"""
returns the coordinates and amplitudes of all point sources in a single array
:param kwargs_ps:
:param kwargs_lens:
:return:
"""
ra_list, dec_list = self.image_position(kwargs_ps, kwargs_lens, k=k)
amp_list = self.image_amplitude(kwargs_ps, kwargs_lens)
ra_array, dec_array, amp_array = [], [], []
for i, ra in enumerate(ra_list):
for j in range(len(ra)):
ra_array.append(ra_list[i][j])
dec_array.append(dec_list[i][j])
amp_array.append(amp_list[i][j])
return ra_array, dec_array, amp_array | python | def point_source_list(self, kwargs_ps, kwargs_lens, k=None):
ra_list, dec_list = self.image_position(kwargs_ps, kwargs_lens, k=k)
amp_list = self.image_amplitude(kwargs_ps, kwargs_lens)
ra_array, dec_array, amp_array = [], [], []
for i, ra in enumerate(ra_list):
for j in range(len(ra)):
ra_array.append(ra_list[i][j])
dec_array.append(dec_list[i][j])
amp_array.append(amp_list[i][j])
return ra_array, dec_array, amp_array | [
"def",
"point_source_list",
"(",
"self",
",",
"kwargs_ps",
",",
"kwargs_lens",
",",
"k",
"=",
"None",
")",
":",
"ra_list",
",",
"dec_list",
"=",
"self",
".",
"image_position",
"(",
"kwargs_ps",
",",
"kwargs_lens",
",",
"k",
"=",
"k",
")",
"amp_list",
"="... | returns the coordinates and amplitudes of all point sources in a single array
:param kwargs_ps:
:param kwargs_lens:
:return: | [
"returns",
"the",
"coordinates",
"and",
"amplitudes",
"of",
"all",
"point",
"sources",
"in",
"a",
"single",
"array"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/PointSource/point_source.py#L140-L156 |
14,315 | sibirrer/lenstronomy | lenstronomy/PointSource/point_source.py | PointSource.image_amplitude | def image_amplitude(self, kwargs_ps, kwargs_lens, k=None):
"""
returns the image amplitudes
:param kwargs_ps:
:param kwargs_lens:
:return:
"""
amp_list = []
for i, model in enumerate(self._point_source_list):
if k is None or k == i:
amp_list.append(model.image_amplitude(kwargs_ps=kwargs_ps[i], kwargs_lens=kwargs_lens, min_distance=self._min_distance,
search_window=self._search_window,
precision_limit=self._precision_limit,
num_iter_max=self._num_iter_max, x_center=self._x_center,
y_center=self._y_center))
return amp_list | python | def image_amplitude(self, kwargs_ps, kwargs_lens, k=None):
amp_list = []
for i, model in enumerate(self._point_source_list):
if k is None or k == i:
amp_list.append(model.image_amplitude(kwargs_ps=kwargs_ps[i], kwargs_lens=kwargs_lens, min_distance=self._min_distance,
search_window=self._search_window,
precision_limit=self._precision_limit,
num_iter_max=self._num_iter_max, x_center=self._x_center,
y_center=self._y_center))
return amp_list | [
"def",
"image_amplitude",
"(",
"self",
",",
"kwargs_ps",
",",
"kwargs_lens",
",",
"k",
"=",
"None",
")",
":",
"amp_list",
"=",
"[",
"]",
"for",
"i",
",",
"model",
"in",
"enumerate",
"(",
"self",
".",
"_point_source_list",
")",
":",
"if",
"k",
"is",
"... | returns the image amplitudes
:param kwargs_ps:
:param kwargs_lens:
:return: | [
"returns",
"the",
"image",
"amplitudes"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/PointSource/point_source.py#L168-L184 |
14,316 | sibirrer/lenstronomy | lenstronomy/PointSource/point_source.py | PointSource.source_amplitude | def source_amplitude(self, kwargs_ps, kwargs_lens):
"""
returns the source amplitudes
:param kwargs_ps:
:param kwargs_lens:
:return:
"""
amp_list = []
for i, model in enumerate(self._point_source_list):
amp_list.append(model.source_amplitude(kwargs_ps=kwargs_ps[i], kwargs_lens=kwargs_lens))
return amp_list | python | def source_amplitude(self, kwargs_ps, kwargs_lens):
amp_list = []
for i, model in enumerate(self._point_source_list):
amp_list.append(model.source_amplitude(kwargs_ps=kwargs_ps[i], kwargs_lens=kwargs_lens))
return amp_list | [
"def",
"source_amplitude",
"(",
"self",
",",
"kwargs_ps",
",",
"kwargs_lens",
")",
":",
"amp_list",
"=",
"[",
"]",
"for",
"i",
",",
"model",
"in",
"enumerate",
"(",
"self",
".",
"_point_source_list",
")",
":",
"amp_list",
".",
"append",
"(",
"model",
"."... | returns the source amplitudes
:param kwargs_ps:
:param kwargs_lens:
:return: | [
"returns",
"the",
"source",
"amplitudes"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/PointSource/point_source.py#L186-L197 |
14,317 | sibirrer/lenstronomy | lenstronomy/PointSource/point_source.py | PointSource.re_normalize_flux | def re_normalize_flux(self, kwargs_ps, norm_factor):
"""
renormalizes the point source amplitude keywords by a factor
:param kwargs_ps_updated:
:param norm_factor:
:return:
"""
for i, model in enumerate(self.point_source_type_list):
if model == 'UNLENSED':
kwargs_ps[i]['point_amp'] *= norm_factor
elif model in ['LENSED_POSITION', 'SOURCE_POSITION']:
if self._fixed_magnification_list[i] is True:
kwargs_ps[i]['source_amp'] *= norm_factor
else:
kwargs_ps[i]['point_amp'] *= norm_factor
return kwargs_ps | python | def re_normalize_flux(self, kwargs_ps, norm_factor):
for i, model in enumerate(self.point_source_type_list):
if model == 'UNLENSED':
kwargs_ps[i]['point_amp'] *= norm_factor
elif model in ['LENSED_POSITION', 'SOURCE_POSITION']:
if self._fixed_magnification_list[i] is True:
kwargs_ps[i]['source_amp'] *= norm_factor
else:
kwargs_ps[i]['point_amp'] *= norm_factor
return kwargs_ps | [
"def",
"re_normalize_flux",
"(",
"self",
",",
"kwargs_ps",
",",
"norm_factor",
")",
":",
"for",
"i",
",",
"model",
"in",
"enumerate",
"(",
"self",
".",
"point_source_type_list",
")",
":",
"if",
"model",
"==",
"'UNLENSED'",
":",
"kwargs_ps",
"[",
"i",
"]",
... | renormalizes the point source amplitude keywords by a factor
:param kwargs_ps_updated:
:param norm_factor:
:return: | [
"renormalizes",
"the",
"point",
"source",
"amplitude",
"keywords",
"by",
"a",
"factor"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/PointSource/point_source.py#L279-L295 |
14,318 | sibirrer/lenstronomy | lenstronomy/LensModel/lens_model_extensions.py | LensModelExtensions._tiling_crit | def _tiling_crit(self, edge1, edge2, edge_90, max_order, kwargs_lens):
"""
tiles a rectangular triangle and compares the signs of the magnification
:param edge1: [ra_coord, dec_coord, magnification]
:param edge2: [ra_coord, dec_coord, magnification]
:param edge_90: [ra_coord, dec_coord, magnification]
:param max_order: maximal order to fold triangle
:return:
"""
ra_1, dec_1, mag_1 = edge1
ra_2, dec_2, mag_2 = edge2
ra_3, dec_3, mag_3 = edge_90
sign_list = np.sign([mag_1, mag_2, mag_3])
if sign_list[0] == sign_list[1] and sign_list[0] == sign_list[2]: # if all signs are the same
return [], []
else:
# split triangle along the long axis
# execute tiling twice
# add ra_crit and dec_crit together
# if max depth has been reached, return the mean value in the triangle
max_order -= 1
if max_order <= 0:
return [(ra_1 + ra_2 + ra_3)/3], [(dec_1 + dec_2 + dec_3)/3]
else:
# split triangle
ra_90_ = (ra_1 + ra_2)/2 # find point in the middle of the long axis to split triangle
dec_90_ = (dec_1 + dec_2)/2
mag_90_ = self._lensModel.magnification(ra_90_, dec_90_, kwargs_lens)
edge_90_ = [ra_90_, dec_90_, mag_90_]
ra_crit, dec_crit = self._tiling_crit(edge1=edge_90, edge2=edge1, edge_90=edge_90_, max_order=max_order,
kwargs_lens=kwargs_lens)
ra_crit_2, dec_crit_2 = self._tiling_crit(edge1=edge_90, edge2=edge2, edge_90=edge_90_, max_order=max_order,
kwargs_lens=kwargs_lens)
ra_crit += ra_crit_2
dec_crit += dec_crit_2
return ra_crit, dec_crit | python | def _tiling_crit(self, edge1, edge2, edge_90, max_order, kwargs_lens):
ra_1, dec_1, mag_1 = edge1
ra_2, dec_2, mag_2 = edge2
ra_3, dec_3, mag_3 = edge_90
sign_list = np.sign([mag_1, mag_2, mag_3])
if sign_list[0] == sign_list[1] and sign_list[0] == sign_list[2]: # if all signs are the same
return [], []
else:
# split triangle along the long axis
# execute tiling twice
# add ra_crit and dec_crit together
# if max depth has been reached, return the mean value in the triangle
max_order -= 1
if max_order <= 0:
return [(ra_1 + ra_2 + ra_3)/3], [(dec_1 + dec_2 + dec_3)/3]
else:
# split triangle
ra_90_ = (ra_1 + ra_2)/2 # find point in the middle of the long axis to split triangle
dec_90_ = (dec_1 + dec_2)/2
mag_90_ = self._lensModel.magnification(ra_90_, dec_90_, kwargs_lens)
edge_90_ = [ra_90_, dec_90_, mag_90_]
ra_crit, dec_crit = self._tiling_crit(edge1=edge_90, edge2=edge1, edge_90=edge_90_, max_order=max_order,
kwargs_lens=kwargs_lens)
ra_crit_2, dec_crit_2 = self._tiling_crit(edge1=edge_90, edge2=edge2, edge_90=edge_90_, max_order=max_order,
kwargs_lens=kwargs_lens)
ra_crit += ra_crit_2
dec_crit += dec_crit_2
return ra_crit, dec_crit | [
"def",
"_tiling_crit",
"(",
"self",
",",
"edge1",
",",
"edge2",
",",
"edge_90",
",",
"max_order",
",",
"kwargs_lens",
")",
":",
"ra_1",
",",
"dec_1",
",",
"mag_1",
"=",
"edge1",
"ra_2",
",",
"dec_2",
",",
"mag_2",
"=",
"edge2",
"ra_3",
",",
"dec_3",
... | tiles a rectangular triangle and compares the signs of the magnification
:param edge1: [ra_coord, dec_coord, magnification]
:param edge2: [ra_coord, dec_coord, magnification]
:param edge_90: [ra_coord, dec_coord, magnification]
:param max_order: maximal order to fold triangle
:return: | [
"tiles",
"a",
"rectangular",
"triangle",
"and",
"compares",
"the",
"signs",
"of",
"the",
"magnification"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/lens_model_extensions.py#L106-L142 |
14,319 | sibirrer/lenstronomy | lenstronomy/LensModel/lens_model_extensions.py | LensModelExtensions.effective_einstein_radius | def effective_einstein_radius(self, kwargs_lens_list, k=None, spacing=1000):
"""
computes the radius with mean convergence=1
:param kwargs_lens:
:param spacing: number of annular bins to compute the convergence (resolution of the Einstein radius estimate)
:return:
"""
if 'center_x' in kwargs_lens_list[0]:
center_x = kwargs_lens_list[0]['center_x']
center_y = kwargs_lens_list[0]['center_y']
elif self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']:
center_x, center_y = 0, 0
else:
center_x, center_y = 0, 0
numPix = 200
deltaPix = 0.05
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
x_grid += center_x
y_grid += center_y
kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens_list, k=k)
if self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']:
center_x = x_grid[kappa == np.max(kappa)]
center_y = y_grid[kappa == np.max(kappa)]
kappa = util.array2image(kappa)
r_array = np.linspace(0.0001, numPix*deltaPix/2., spacing)
for r in r_array:
mask = np.array(1 - mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid))
sum_mask = np.sum(mask)
if sum_mask > 0:
kappa_mean = np.sum(kappa*mask)/np.sum(mask)
if kappa_mean < 1:
return r
print(kwargs_lens_list, "Warning, no Einstein radius computed!")
return r_array[-1] | python | def effective_einstein_radius(self, kwargs_lens_list, k=None, spacing=1000):
if 'center_x' in kwargs_lens_list[0]:
center_x = kwargs_lens_list[0]['center_x']
center_y = kwargs_lens_list[0]['center_y']
elif self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']:
center_x, center_y = 0, 0
else:
center_x, center_y = 0, 0
numPix = 200
deltaPix = 0.05
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
x_grid += center_x
y_grid += center_y
kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens_list, k=k)
if self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']:
center_x = x_grid[kappa == np.max(kappa)]
center_y = y_grid[kappa == np.max(kappa)]
kappa = util.array2image(kappa)
r_array = np.linspace(0.0001, numPix*deltaPix/2., spacing)
for r in r_array:
mask = np.array(1 - mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid))
sum_mask = np.sum(mask)
if sum_mask > 0:
kappa_mean = np.sum(kappa*mask)/np.sum(mask)
if kappa_mean < 1:
return r
print(kwargs_lens_list, "Warning, no Einstein radius computed!")
return r_array[-1] | [
"def",
"effective_einstein_radius",
"(",
"self",
",",
"kwargs_lens_list",
",",
"k",
"=",
"None",
",",
"spacing",
"=",
"1000",
")",
":",
"if",
"'center_x'",
"in",
"kwargs_lens_list",
"[",
"0",
"]",
":",
"center_x",
"=",
"kwargs_lens_list",
"[",
"0",
"]",
"[... | computes the radius with mean convergence=1
:param kwargs_lens:
:param spacing: number of annular bins to compute the convergence (resolution of the Einstein radius estimate)
:return: | [
"computes",
"the",
"radius",
"with",
"mean",
"convergence",
"=",
"1"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/lens_model_extensions.py#L178-L212 |
14,320 | sibirrer/lenstronomy | lenstronomy/LensModel/lens_model_extensions.py | LensModelExtensions.lens_center | def lens_center(self, kwargs_lens, k=None, bool_list=None, numPix=200, deltaPix=0.01, center_x_init=0, center_y_init=0):
"""
computes the convergence weighted center of a lens model
:param kwargs_lens: lens model keyword argument list
:param bool_list: bool list (optional) to include certain models or not
:return: center_x, center_y
"""
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
x_grid += center_x_init
y_grid += center_y_init
if bool_list is None:
kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens, k=k)
else:
kappa = np.zeros_like(x_grid)
for k in range(len(kwargs_lens)):
if bool_list[k] is True:
kappa += self._lensModel.kappa(x_grid, y_grid, kwargs_lens, k=k)
center_x = x_grid[kappa == np.max(kappa)]
center_y = y_grid[kappa == np.max(kappa)]
return center_x, center_y | python | def lens_center(self, kwargs_lens, k=None, bool_list=None, numPix=200, deltaPix=0.01, center_x_init=0, center_y_init=0):
x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
x_grid += center_x_init
y_grid += center_y_init
if bool_list is None:
kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens, k=k)
else:
kappa = np.zeros_like(x_grid)
for k in range(len(kwargs_lens)):
if bool_list[k] is True:
kappa += self._lensModel.kappa(x_grid, y_grid, kwargs_lens, k=k)
center_x = x_grid[kappa == np.max(kappa)]
center_y = y_grid[kappa == np.max(kappa)]
return center_x, center_y | [
"def",
"lens_center",
"(",
"self",
",",
"kwargs_lens",
",",
"k",
"=",
"None",
",",
"bool_list",
"=",
"None",
",",
"numPix",
"=",
"200",
",",
"deltaPix",
"=",
"0.01",
",",
"center_x_init",
"=",
"0",
",",
"center_y_init",
"=",
"0",
")",
":",
"x_grid",
... | computes the convergence weighted center of a lens model
:param kwargs_lens: lens model keyword argument list
:param bool_list: bool list (optional) to include certain models or not
:return: center_x, center_y | [
"computes",
"the",
"convergence",
"weighted",
"center",
"of",
"a",
"lens",
"model"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/lens_model_extensions.py#L255-L276 |
14,321 | sibirrer/lenstronomy | lenstronomy/LensModel/lens_model_extensions.py | LensModelExtensions.profile_slope | def profile_slope(self, kwargs_lens_list, lens_model_internal_bool=None, num_points=10):
"""
computes the logarithmic power-law slope of a profile
:param kwargs_lens_list: lens model keyword argument list
:param lens_model_internal_bool: bool list, indicate which part of the model to consider
:param num_points: number of estimates around the Einstein radius
:return:
"""
theta_E = self.effective_einstein_radius(kwargs_lens_list)
x0 = kwargs_lens_list[0]['center_x']
y0 = kwargs_lens_list[0]['center_y']
x, y = util.points_on_circle(theta_E, num_points)
dr = 0.01
x_dr, y_dr = util.points_on_circle(theta_E + dr, num_points)
if lens_model_internal_bool is None:
lens_model_internal_bool = [True]*len(kwargs_lens_list)
alpha_E_x_i, alpha_E_y_i = self._lensModel.alpha(x0 + x, y0 + y, kwargs_lens_list, k=lens_model_internal_bool)
alpha_E_r = np.sqrt(alpha_E_x_i**2 + alpha_E_y_i**2)
alpha_E_dr_x_i, alpha_E_dr_y_i = self._lensModel.alpha(x0 + x_dr, y0 + y_dr, kwargs_lens_list,
k=lens_model_internal_bool)
alpha_E_dr = np.sqrt(alpha_E_dr_x_i ** 2 + alpha_E_dr_y_i ** 2)
slope = np.mean(np.log(alpha_E_dr / alpha_E_r) / np.log((theta_E + dr) / theta_E))
gamma = -slope + 2
return gamma | python | def profile_slope(self, kwargs_lens_list, lens_model_internal_bool=None, num_points=10):
theta_E = self.effective_einstein_radius(kwargs_lens_list)
x0 = kwargs_lens_list[0]['center_x']
y0 = kwargs_lens_list[0]['center_y']
x, y = util.points_on_circle(theta_E, num_points)
dr = 0.01
x_dr, y_dr = util.points_on_circle(theta_E + dr, num_points)
if lens_model_internal_bool is None:
lens_model_internal_bool = [True]*len(kwargs_lens_list)
alpha_E_x_i, alpha_E_y_i = self._lensModel.alpha(x0 + x, y0 + y, kwargs_lens_list, k=lens_model_internal_bool)
alpha_E_r = np.sqrt(alpha_E_x_i**2 + alpha_E_y_i**2)
alpha_E_dr_x_i, alpha_E_dr_y_i = self._lensModel.alpha(x0 + x_dr, y0 + y_dr, kwargs_lens_list,
k=lens_model_internal_bool)
alpha_E_dr = np.sqrt(alpha_E_dr_x_i ** 2 + alpha_E_dr_y_i ** 2)
slope = np.mean(np.log(alpha_E_dr / alpha_E_r) / np.log((theta_E + dr) / theta_E))
gamma = -slope + 2
return gamma | [
"def",
"profile_slope",
"(",
"self",
",",
"kwargs_lens_list",
",",
"lens_model_internal_bool",
"=",
"None",
",",
"num_points",
"=",
"10",
")",
":",
"theta_E",
"=",
"self",
".",
"effective_einstein_radius",
"(",
"kwargs_lens_list",
")",
"x0",
"=",
"kwargs_lens_list... | computes the logarithmic power-law slope of a profile
:param kwargs_lens_list: lens model keyword argument list
:param lens_model_internal_bool: bool list, indicate which part of the model to consider
:param num_points: number of estimates around the Einstein radius
:return: | [
"computes",
"the",
"logarithmic",
"power",
"-",
"law",
"slope",
"of",
"a",
"profile"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/lens_model_extensions.py#L278-L303 |
14,322 | sibirrer/lenstronomy | lenstronomy/Cosmo/background.py | Background.D_dt | def D_dt(self, z_lens, z_source):
"""
time-delay distance
:param z_lens: redshift of lens
:param z_source: redshift of source
:return: time-delay distance in units of Mpc
"""
return self.D_xy(0, z_lens) * self.D_xy(0, z_source) / self.D_xy(z_lens, z_source) * (1 + z_lens) | python | def D_dt(self, z_lens, z_source):
return self.D_xy(0, z_lens) * self.D_xy(0, z_source) / self.D_xy(z_lens, z_source) * (1 + z_lens) | [
"def",
"D_dt",
"(",
"self",
",",
"z_lens",
",",
"z_source",
")",
":",
"return",
"self",
".",
"D_xy",
"(",
"0",
",",
"z_lens",
")",
"*",
"self",
".",
"D_xy",
"(",
"0",
",",
"z_source",
")",
"/",
"self",
".",
"D_xy",
"(",
"z_lens",
",",
"z_source",... | time-delay distance
:param z_lens: redshift of lens
:param z_source: redshift of source
:return: time-delay distance in units of Mpc | [
"time",
"-",
"delay",
"distance"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Cosmo/background.py#L43-L51 |
14,323 | sibirrer/lenstronomy | lenstronomy/LensModel/Optimizer/particle_swarm.py | ParticleSwarmOptimizer._sample | def _sample(self, maxIter=1000, c1=1.193, c2=1.193, lookback = 0.25, standard_dev = None):
"""
Launches the PSO. Yields the complete swarm per iteration
:param maxIter: maximum iterations
:param c1: cognitive weight
:param c2: social weight
:param lookback: percentange of particles to use when determining convergence
:param standard_dev: standard deviation of the last lookback particles for convergence
"""
self._get_fitness(self.swarm)
i = 0
self.i = i
while True:
for particle in self.swarm:
if ((self._gbest.fitness)<particle.fitness):
self._gbest = particle.copy()
if (particle.fitness > particle.pbest.fitness):
particle.updatePBest()
if(i>=maxIter):
if self._verbose:
print("max iteration reached! stoping")
return
if self._func.is_converged:
return
if self._converged_likelihood(maxIter*lookback, self._particleCount, standard_dev):
return
for particle in self.swarm:
w = 0.5 + numpy.random.uniform(0, 1, size=self._paramCount) / 2
#w=0.72
part_vel = w * particle.velocity
cog_vel = c1 * numpy.random.uniform(0, 1, size=self._paramCount) * (particle.pbest.position - particle.position)
soc_vel = c2 * numpy.random.uniform(0, 1, size=self._paramCount) * (self._gbest.position - particle.position)
particle.velocity = part_vel + cog_vel + soc_vel
particle.position = particle.position + particle.velocity
self._get_fitness(self.swarm)
swarm = []
for particle in self.swarm:
swarm.append(particle.copy())
yield swarm
i+=1
self.i = i | python | def _sample(self, maxIter=1000, c1=1.193, c2=1.193, lookback = 0.25, standard_dev = None):
self._get_fitness(self.swarm)
i = 0
self.i = i
while True:
for particle in self.swarm:
if ((self._gbest.fitness)<particle.fitness):
self._gbest = particle.copy()
if (particle.fitness > particle.pbest.fitness):
particle.updatePBest()
if(i>=maxIter):
if self._verbose:
print("max iteration reached! stoping")
return
if self._func.is_converged:
return
if self._converged_likelihood(maxIter*lookback, self._particleCount, standard_dev):
return
for particle in self.swarm:
w = 0.5 + numpy.random.uniform(0, 1, size=self._paramCount) / 2
#w=0.72
part_vel = w * particle.velocity
cog_vel = c1 * numpy.random.uniform(0, 1, size=self._paramCount) * (particle.pbest.position - particle.position)
soc_vel = c2 * numpy.random.uniform(0, 1, size=self._paramCount) * (self._gbest.position - particle.position)
particle.velocity = part_vel + cog_vel + soc_vel
particle.position = particle.position + particle.velocity
self._get_fitness(self.swarm)
swarm = []
for particle in self.swarm:
swarm.append(particle.copy())
yield swarm
i+=1
self.i = i | [
"def",
"_sample",
"(",
"self",
",",
"maxIter",
"=",
"1000",
",",
"c1",
"=",
"1.193",
",",
"c2",
"=",
"1.193",
",",
"lookback",
"=",
"0.25",
",",
"standard_dev",
"=",
"None",
")",
":",
"self",
".",
"_get_fitness",
"(",
"self",
".",
"swarm",
")",
"i"... | Launches the PSO. Yields the complete swarm per iteration
:param maxIter: maximum iterations
:param c1: cognitive weight
:param c2: social weight
:param lookback: percentange of particles to use when determining convergence
:param standard_dev: standard deviation of the last lookback particles for convergence | [
"Launches",
"the",
"PSO",
".",
"Yields",
"the",
"complete",
"swarm",
"per",
"iteration"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/Optimizer/particle_swarm.py#L40-L92 |
14,324 | sibirrer/lenstronomy | lenstronomy/LensModel/Optimizer/particle_swarm.py | Particle.create | def create(cls, paramCount):
"""
Creates a new particle without position, velocity and -inf as fitness
"""
return Particle(numpy.array([[]]*paramCount),
numpy.array([[]]*paramCount),
-numpy.Inf) | python | def create(cls, paramCount):
return Particle(numpy.array([[]]*paramCount),
numpy.array([[]]*paramCount),
-numpy.Inf) | [
"def",
"create",
"(",
"cls",
",",
"paramCount",
")",
":",
"return",
"Particle",
"(",
"numpy",
".",
"array",
"(",
"[",
"[",
"]",
"]",
"*",
"paramCount",
")",
",",
"numpy",
".",
"array",
"(",
"[",
"[",
"]",
"]",
"*",
"paramCount",
")",
",",
"-",
... | Creates a new particle without position, velocity and -inf as fitness | [
"Creates",
"a",
"new",
"particle",
"without",
"position",
"velocity",
"and",
"-",
"inf",
"as",
"fitness"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/Optimizer/particle_swarm.py#L167-L174 |
14,325 | sibirrer/lenstronomy | lenstronomy/LensModel/Optimizer/particle_swarm.py | Particle.copy | def copy(self):
"""
Creates a copy of itself
"""
return Particle(copy(self.position),
copy(self.velocity),
self.fitness) | python | def copy(self):
return Particle(copy(self.position),
copy(self.velocity),
self.fitness) | [
"def",
"copy",
"(",
"self",
")",
":",
"return",
"Particle",
"(",
"copy",
"(",
"self",
".",
"position",
")",
",",
"copy",
"(",
"self",
".",
"velocity",
")",
",",
"self",
".",
"fitness",
")"
] | Creates a copy of itself | [
"Creates",
"a",
"copy",
"of",
"itself"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/Optimizer/particle_swarm.py#L182-L188 |
14,326 | sibirrer/lenstronomy | lenstronomy/Util/analysis_util.py | moments | def moments(I_xy_input, x, y):
"""
compute quadrupole moments from a light distribution
:param I_xy: light distribution
:param x: x-coordinates of I_xy
:param y: y-coordinates of I_xy
:return: Q_xx, Q_xy, Q_yy
"""
I_xy = copy.deepcopy(I_xy_input)
background = np.minimum(0, np.min(I_xy))
I_xy -= background
x_ = np.sum(I_xy * x)
y_ = np.sum(I_xy * y)
r = (np.max(x) - np.min(x)) / 3.
mask = mask_util.mask_sphere(x, y, center_x=x_, center_y=y_, r=r)
Q_xx = np.sum(I_xy * mask * (x - x_) ** 2)
Q_xy = np.sum(I_xy * mask * (x - x_) * (y - y_))
Q_yy = np.sum(I_xy * mask * (y - y_) ** 2)
return Q_xx, Q_xy, Q_yy, background / np.mean(I_xy) | python | def moments(I_xy_input, x, y):
I_xy = copy.deepcopy(I_xy_input)
background = np.minimum(0, np.min(I_xy))
I_xy -= background
x_ = np.sum(I_xy * x)
y_ = np.sum(I_xy * y)
r = (np.max(x) - np.min(x)) / 3.
mask = mask_util.mask_sphere(x, y, center_x=x_, center_y=y_, r=r)
Q_xx = np.sum(I_xy * mask * (x - x_) ** 2)
Q_xy = np.sum(I_xy * mask * (x - x_) * (y - y_))
Q_yy = np.sum(I_xy * mask * (y - y_) ** 2)
return Q_xx, Q_xy, Q_yy, background / np.mean(I_xy) | [
"def",
"moments",
"(",
"I_xy_input",
",",
"x",
",",
"y",
")",
":",
"I_xy",
"=",
"copy",
".",
"deepcopy",
"(",
"I_xy_input",
")",
"background",
"=",
"np",
".",
"minimum",
"(",
"0",
",",
"np",
".",
"min",
"(",
"I_xy",
")",
")",
"I_xy",
"-=",
"backg... | compute quadrupole moments from a light distribution
:param I_xy: light distribution
:param x: x-coordinates of I_xy
:param y: y-coordinates of I_xy
:return: Q_xx, Q_xy, Q_yy | [
"compute",
"quadrupole",
"moments",
"from",
"a",
"light",
"distribution"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Util/analysis_util.py#L93-L112 |
14,327 | sibirrer/lenstronomy | lenstronomy/Util/analysis_util.py | ellipticities | def ellipticities(I_xy, x, y):
"""
compute ellipticities of a light distribution
:param I_xy:
:param x:
:param y:
:return:
"""
Q_xx, Q_xy, Q_yy, bkg = moments(I_xy, x, y)
norm = Q_xx + Q_yy + 2 * np.sqrt(Q_xx*Q_yy - Q_xy**2)
e1 = (Q_xx - Q_yy) / norm
e2 = 2 * Q_xy / norm
return e1 / (1+bkg), e2 / (1+bkg) | python | def ellipticities(I_xy, x, y):
Q_xx, Q_xy, Q_yy, bkg = moments(I_xy, x, y)
norm = Q_xx + Q_yy + 2 * np.sqrt(Q_xx*Q_yy - Q_xy**2)
e1 = (Q_xx - Q_yy) / norm
e2 = 2 * Q_xy / norm
return e1 / (1+bkg), e2 / (1+bkg) | [
"def",
"ellipticities",
"(",
"I_xy",
",",
"x",
",",
"y",
")",
":",
"Q_xx",
",",
"Q_xy",
",",
"Q_yy",
",",
"bkg",
"=",
"moments",
"(",
"I_xy",
",",
"x",
",",
"y",
")",
"norm",
"=",
"Q_xx",
"+",
"Q_yy",
"+",
"2",
"*",
"np",
".",
"sqrt",
"(",
... | compute ellipticities of a light distribution
:param I_xy:
:param x:
:param y:
:return: | [
"compute",
"ellipticities",
"of",
"a",
"light",
"distribution"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/Util/analysis_util.py#L115-L128 |
14,328 | sibirrer/lenstronomy | lenstronomy/LensModel/multi_plane.py | MultiPlane.alpha | def alpha(self, theta_x, theta_y, kwargs_lens, k=None):
"""
reduced deflection angle
:param theta_x: angle in x-direction
:param theta_y: angle in y-direction
:param kwargs_lens: lens model kwargs
:return:
"""
beta_x, beta_y = self.ray_shooting(theta_x, theta_y, kwargs_lens)
alpha_x = theta_x - beta_x
alpha_y = theta_y - beta_y
return alpha_x, alpha_y | python | def alpha(self, theta_x, theta_y, kwargs_lens, k=None):
beta_x, beta_y = self.ray_shooting(theta_x, theta_y, kwargs_lens)
alpha_x = theta_x - beta_x
alpha_y = theta_y - beta_y
return alpha_x, alpha_y | [
"def",
"alpha",
"(",
"self",
",",
"theta_x",
",",
"theta_y",
",",
"kwargs_lens",
",",
"k",
"=",
"None",
")",
":",
"beta_x",
",",
"beta_y",
"=",
"self",
".",
"ray_shooting",
"(",
"theta_x",
",",
"theta_y",
",",
"kwargs_lens",
")",
"alpha_x",
"=",
"theta... | reduced deflection angle
:param theta_x: angle in x-direction
:param theta_y: angle in y-direction
:param kwargs_lens: lens model kwargs
:return: | [
"reduced",
"deflection",
"angle"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/multi_plane.py#L223-L235 |
14,329 | sibirrer/lenstronomy | lenstronomy/LensModel/multi_plane.py | MultiPlane.hessian | def hessian(self, theta_x, theta_y, kwargs_lens, k=None, diff=0.00000001):
"""
computes the hessian components f_xx, f_yy, f_xy from f_x and f_y with numerical differentiation
:param theta_x: x-position (preferentially arcsec)
:type theta_x: numpy array
:param theta_y: y-position (preferentially arcsec)
:type theta_y: numpy array
:param kwargs_lens: list of keyword arguments of lens model parameters matching the lens model classes
:param diff: numerical differential step (float)
:return: f_xx, f_xy, f_yx, f_yy
"""
alpha_ra, alpha_dec = self.alpha(theta_x, theta_y, kwargs_lens)
alpha_ra_dx, alpha_dec_dx = self.alpha(theta_x + diff, theta_y, kwargs_lens)
alpha_ra_dy, alpha_dec_dy = self.alpha(theta_x, theta_y + diff, kwargs_lens)
dalpha_rara = (alpha_ra_dx - alpha_ra)/diff
dalpha_radec = (alpha_ra_dy - alpha_ra)/diff
dalpha_decra = (alpha_dec_dx - alpha_dec)/diff
dalpha_decdec = (alpha_dec_dy - alpha_dec)/diff
f_xx = dalpha_rara
f_yy = dalpha_decdec
f_xy = dalpha_radec
f_yx = dalpha_decra
return f_xx, f_xy, f_yx, f_yy | python | def hessian(self, theta_x, theta_y, kwargs_lens, k=None, diff=0.00000001):
alpha_ra, alpha_dec = self.alpha(theta_x, theta_y, kwargs_lens)
alpha_ra_dx, alpha_dec_dx = self.alpha(theta_x + diff, theta_y, kwargs_lens)
alpha_ra_dy, alpha_dec_dy = self.alpha(theta_x, theta_y + diff, kwargs_lens)
dalpha_rara = (alpha_ra_dx - alpha_ra)/diff
dalpha_radec = (alpha_ra_dy - alpha_ra)/diff
dalpha_decra = (alpha_dec_dx - alpha_dec)/diff
dalpha_decdec = (alpha_dec_dy - alpha_dec)/diff
f_xx = dalpha_rara
f_yy = dalpha_decdec
f_xy = dalpha_radec
f_yx = dalpha_decra
return f_xx, f_xy, f_yx, f_yy | [
"def",
"hessian",
"(",
"self",
",",
"theta_x",
",",
"theta_y",
",",
"kwargs_lens",
",",
"k",
"=",
"None",
",",
"diff",
"=",
"0.00000001",
")",
":",
"alpha_ra",
",",
"alpha_dec",
"=",
"self",
".",
"alpha",
"(",
"theta_x",
",",
"theta_y",
",",
"kwargs_le... | computes the hessian components f_xx, f_yy, f_xy from f_x and f_y with numerical differentiation
:param theta_x: x-position (preferentially arcsec)
:type theta_x: numpy array
:param theta_y: y-position (preferentially arcsec)
:type theta_y: numpy array
:param kwargs_lens: list of keyword arguments of lens model parameters matching the lens model classes
:param diff: numerical differential step (float)
:return: f_xx, f_xy, f_yx, f_yy | [
"computes",
"the",
"hessian",
"components",
"f_xx",
"f_yy",
"f_xy",
"from",
"f_x",
"and",
"f_y",
"with",
"numerical",
"differentiation"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/multi_plane.py#L237-L264 |
14,330 | sibirrer/lenstronomy | lenstronomy/LensModel/multi_plane.py | MultiPlane._co_moving2angle_source | def _co_moving2angle_source(self, x, y):
"""
special case of the co_moving2angle definition at the source redshift
:param x:
:param y:
:return:
"""
T_z = self._T_z_source
theta_x = x / T_z
theta_y = y / T_z
return theta_x, theta_y | python | def _co_moving2angle_source(self, x, y):
T_z = self._T_z_source
theta_x = x / T_z
theta_y = y / T_z
return theta_x, theta_y | [
"def",
"_co_moving2angle_source",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"T_z",
"=",
"self",
".",
"_T_z_source",
"theta_x",
"=",
"x",
"/",
"T_z",
"theta_y",
"=",
"y",
"/",
"T_z",
"return",
"theta_x",
",",
"theta_y"
] | special case of the co_moving2angle definition at the source redshift
:param x:
:param y:
:return: | [
"special",
"case",
"of",
"the",
"co_moving2angle",
"definition",
"at",
"the",
"source",
"redshift"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/multi_plane.py#L346-L357 |
14,331 | sibirrer/lenstronomy | lenstronomy/LensModel/multi_plane.py | MultiPlane._ray_step | def _ray_step(self, x, y, alpha_x, alpha_y, delta_T):
"""
ray propagation with small angle approximation
:param x: co-moving x-position
:param y: co-moving y-position
:param alpha_x: deflection angle in x-direction at (x, y)
:param alpha_y: deflection angle in y-direction at (x, y)
:param delta_T: transversal angular diameter distance to the next step
:return:
"""
x_ = x + alpha_x * delta_T
y_ = y + alpha_y * delta_T
return x_, y_ | python | def _ray_step(self, x, y, alpha_x, alpha_y, delta_T):
x_ = x + alpha_x * delta_T
y_ = y + alpha_y * delta_T
return x_, y_ | [
"def",
"_ray_step",
"(",
"self",
",",
"x",
",",
"y",
",",
"alpha_x",
",",
"alpha_y",
",",
"delta_T",
")",
":",
"x_",
"=",
"x",
"+",
"alpha_x",
"*",
"delta_T",
"y_",
"=",
"y",
"+",
"alpha_y",
"*",
"delta_T",
"return",
"x_",
",",
"y_"
] | ray propagation with small angle approximation
:param x: co-moving x-position
:param y: co-moving y-position
:param alpha_x: deflection angle in x-direction at (x, y)
:param alpha_y: deflection angle in y-direction at (x, y)
:param delta_T: transversal angular diameter distance to the next step
:return: | [
"ray",
"propagation",
"with",
"small",
"angle",
"approximation"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/multi_plane.py#L359-L372 |
14,332 | sibirrer/lenstronomy | lenstronomy/LensModel/multi_plane.py | MultiPlane._add_deflection | def _add_deflection(self, x, y, alpha_x, alpha_y, kwargs_lens, idex):
"""
adds the pyhsical deflection angle of a single lens plane to the deflection field
:param x: co-moving distance at the deflector plane
:param y: co-moving distance at the deflector plane
:param alpha_x: physical angle (radian) before the deflector plane
:param alpha_y: physical angle (radian) before the deflector plane
:param kwargs_lens: lens model parameter kwargs
:param idex: index of the lens model to be added
:param idex_lens: redshift of the deflector plane
:return: updated physical deflection after deflector plane (in a backwards ray-tracing perspective)
"""
theta_x, theta_y = self._co_moving2angle(x, y, idex)
alpha_x_red, alpha_y_red = self._lens_model.alpha(theta_x, theta_y, kwargs_lens, k=self._sorted_redshift_index[idex])
alpha_x_phys = self._reduced2physical_deflection(alpha_x_red, idex)
alpha_y_phys = self._reduced2physical_deflection(alpha_y_red, idex)
alpha_x_new = alpha_x - alpha_x_phys
alpha_y_new = alpha_y - alpha_y_phys
return alpha_x_new, alpha_y_new | python | def _add_deflection(self, x, y, alpha_x, alpha_y, kwargs_lens, idex):
theta_x, theta_y = self._co_moving2angle(x, y, idex)
alpha_x_red, alpha_y_red = self._lens_model.alpha(theta_x, theta_y, kwargs_lens, k=self._sorted_redshift_index[idex])
alpha_x_phys = self._reduced2physical_deflection(alpha_x_red, idex)
alpha_y_phys = self._reduced2physical_deflection(alpha_y_red, idex)
alpha_x_new = alpha_x - alpha_x_phys
alpha_y_new = alpha_y - alpha_y_phys
return alpha_x_new, alpha_y_new | [
"def",
"_add_deflection",
"(",
"self",
",",
"x",
",",
"y",
",",
"alpha_x",
",",
"alpha_y",
",",
"kwargs_lens",
",",
"idex",
")",
":",
"theta_x",
",",
"theta_y",
"=",
"self",
".",
"_co_moving2angle",
"(",
"x",
",",
"y",
",",
"idex",
")",
"alpha_x_red",
... | adds the pyhsical deflection angle of a single lens plane to the deflection field
:param x: co-moving distance at the deflector plane
:param y: co-moving distance at the deflector plane
:param alpha_x: physical angle (radian) before the deflector plane
:param alpha_y: physical angle (radian) before the deflector plane
:param kwargs_lens: lens model parameter kwargs
:param idex: index of the lens model to be added
:param idex_lens: redshift of the deflector plane
:return: updated physical deflection after deflector plane (in a backwards ray-tracing perspective) | [
"adds",
"the",
"pyhsical",
"deflection",
"angle",
"of",
"a",
"single",
"lens",
"plane",
"to",
"the",
"deflection",
"field"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/multi_plane.py#L374-L393 |
14,333 | sibirrer/lenstronomy | lenstronomy/LensModel/single_plane.py | SinglePlane.mass_3d | def mass_3d(self, r, kwargs, bool_list=None):
"""
computes the mass within a 3d sphere of radius r
:param r: radius (in angular units)
:param kwargs: list of keyword arguments of lens model parameters matching the lens model classes
:param bool_list: list of bools that are part of the output
:return: mass (in angular units, modulo epsilon_crit)
"""
bool_list = self._bool_list(bool_list)
mass_3d = 0
for i, func in enumerate(self.func_list):
if bool_list[i] is True:
kwargs_i = {k:v for k, v in kwargs[i].items() if not k in ['center_x', 'center_y']}
mass_3d_i = func.mass_3d_lens(r, **kwargs_i)
mass_3d += mass_3d_i
#except:
# raise ValueError('Lens profile %s does not support a 3d mass function!' % self.model_list[i])
return mass_3d | python | def mass_3d(self, r, kwargs, bool_list=None):
bool_list = self._bool_list(bool_list)
mass_3d = 0
for i, func in enumerate(self.func_list):
if bool_list[i] is True:
kwargs_i = {k:v for k, v in kwargs[i].items() if not k in ['center_x', 'center_y']}
mass_3d_i = func.mass_3d_lens(r, **kwargs_i)
mass_3d += mass_3d_i
#except:
# raise ValueError('Lens profile %s does not support a 3d mass function!' % self.model_list[i])
return mass_3d | [
"def",
"mass_3d",
"(",
"self",
",",
"r",
",",
"kwargs",
",",
"bool_list",
"=",
"None",
")",
":",
"bool_list",
"=",
"self",
".",
"_bool_list",
"(",
"bool_list",
")",
"mass_3d",
"=",
"0",
"for",
"i",
",",
"func",
"in",
"enumerate",
"(",
"self",
".",
... | computes the mass within a 3d sphere of radius r
:param r: radius (in angular units)
:param kwargs: list of keyword arguments of lens model parameters matching the lens model classes
:param bool_list: list of bools that are part of the output
:return: mass (in angular units, modulo epsilon_crit) | [
"computes",
"the",
"mass",
"within",
"a",
"3d",
"sphere",
"of",
"radius",
"r"
] | 4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6 | https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/LensModel/single_plane.py#L171-L189 |
14,334 | Pelagicore/qface | qface/helper/qtcpp.py | Filters.close_ns | def close_ns(symbol):
'''generates a closing names statement from a symbol'''
closing = ' '.join(['}' for x in symbol.module.name_parts])
name = '::'.join(symbol.module.name_parts)
return '{0} // namespace {1}'.format(closing, name) | python | def close_ns(symbol):
'''generates a closing names statement from a symbol'''
closing = ' '.join(['}' for x in symbol.module.name_parts])
name = '::'.join(symbol.module.name_parts)
return '{0} // namespace {1}'.format(closing, name) | [
"def",
"close_ns",
"(",
"symbol",
")",
":",
"closing",
"=",
"' '",
".",
"join",
"(",
"[",
"'}'",
"for",
"x",
"in",
"symbol",
".",
"module",
".",
"name_parts",
"]",
")",
"name",
"=",
"'::'",
".",
"join",
"(",
"symbol",
".",
"module",
".",
"name_part... | generates a closing names statement from a symbol | [
"generates",
"a",
"closing",
"names",
"statement",
"from",
"a",
"symbol"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/helper/qtcpp.py#L154-L158 |
14,335 | Pelagicore/qface | qface/cli.py | app | def app(config, src, dst, features, reload, force):
"""Takes several files or directories as src and generates the code
in the given dst directory."""
config = Path(config)
if reload:
argv = sys.argv.copy()
argv.remove('--reload')
monitor(config.dirname(), src, dst, argv)
else:
run(config, src, dst, force) | python | def app(config, src, dst, features, reload, force):
config = Path(config)
if reload:
argv = sys.argv.copy()
argv.remove('--reload')
monitor(config.dirname(), src, dst, argv)
else:
run(config, src, dst, force) | [
"def",
"app",
"(",
"config",
",",
"src",
",",
"dst",
",",
"features",
",",
"reload",
",",
"force",
")",
":",
"config",
"=",
"Path",
"(",
"config",
")",
"if",
"reload",
":",
"argv",
"=",
"sys",
".",
"argv",
".",
"copy",
"(",
")",
"argv",
".",
"r... | Takes several files or directories as src and generates the code
in the given dst directory. | [
"Takes",
"several",
"files",
"or",
"directories",
"as",
"src",
"and",
"generates",
"the",
"code",
"in",
"the",
"given",
"dst",
"directory",
"."
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/cli.py#L31-L40 |
14,336 | Pelagicore/qface | cli.py | reload | def reload(script, input, output):
"""
reloads the generator script when the script files
or the input files changes
"""
script = Path(script).expand().abspath()
output = Path(output).expand().abspath()
input = input if isinstance(input, (list, tuple)) else [input]
output.makedirs_p()
_script_reload(script, input, output) | python | def reload(script, input, output):
script = Path(script).expand().abspath()
output = Path(output).expand().abspath()
input = input if isinstance(input, (list, tuple)) else [input]
output.makedirs_p()
_script_reload(script, input, output) | [
"def",
"reload",
"(",
"script",
",",
"input",
",",
"output",
")",
":",
"script",
"=",
"Path",
"(",
"script",
")",
".",
"expand",
"(",
")",
".",
"abspath",
"(",
")",
"output",
"=",
"Path",
"(",
"output",
")",
".",
"expand",
"(",
")",
".",
"abspath... | reloads the generator script when the script files
or the input files changes | [
"reloads",
"the",
"generator",
"script",
"when",
"the",
"script",
"files",
"or",
"the",
"input",
"files",
"changes"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/cli.py#L110-L119 |
14,337 | Pelagicore/qface | cli.py | _script_reload | def _script_reload(script, input, output):
"""run the named generator and monitor the input and generator folder"""
input = [Path(entry).expand().abspath() for entry in input]
output = Path(output).expand().abspath()
cmd = 'python3 {0} {1} {2}'.format(script, ' '.join(input), output)
event_handler = RunScriptChangeHandler(cmd)
event_handler.run() # run always once
observer = Observer()
path = script.dirname().expand().abspath()
click.secho('watch: {0}'.format(path), fg='blue')
observer.schedule(event_handler, path, recursive=True)
for entry in input:
entry = entry.dirname().expand().abspath()
click.secho('watch: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
path = Path(__file__).parent / 'qface'
click.secho('watch: {0}'.format(path), fg='blue')
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join() | python | def _script_reload(script, input, output):
input = [Path(entry).expand().abspath() for entry in input]
output = Path(output).expand().abspath()
cmd = 'python3 {0} {1} {2}'.format(script, ' '.join(input), output)
event_handler = RunScriptChangeHandler(cmd)
event_handler.run() # run always once
observer = Observer()
path = script.dirname().expand().abspath()
click.secho('watch: {0}'.format(path), fg='blue')
observer.schedule(event_handler, path, recursive=True)
for entry in input:
entry = entry.dirname().expand().abspath()
click.secho('watch: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
path = Path(__file__).parent / 'qface'
click.secho('watch: {0}'.format(path), fg='blue')
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join() | [
"def",
"_script_reload",
"(",
"script",
",",
"input",
",",
"output",
")",
":",
"input",
"=",
"[",
"Path",
"(",
"entry",
")",
".",
"expand",
"(",
")",
".",
"abspath",
"(",
")",
"for",
"entry",
"in",
"input",
"]",
"output",
"=",
"Path",
"(",
"output"... | run the named generator and monitor the input and generator folder | [
"run",
"the",
"named",
"generator",
"and",
"monitor",
"the",
"input",
"and",
"generator",
"folder"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/cli.py#L122-L147 |
14,338 | Pelagicore/qface | cli.py | install | def install(editable):
"""install the script onto the system using pip3"""
script_dir = str(Path(__file__).parent.abspath())
click.secho(script_dir, fg='blue')
if editable:
sh('pip3 install --editable {0} --upgrade'.format(script_dir))
else:
sh('pip3 install {0} --upgrade'.format(script_dir)) | python | def install(editable):
script_dir = str(Path(__file__).parent.abspath())
click.secho(script_dir, fg='blue')
if editable:
sh('pip3 install --editable {0} --upgrade'.format(script_dir))
else:
sh('pip3 install {0} --upgrade'.format(script_dir)) | [
"def",
"install",
"(",
"editable",
")",
":",
"script_dir",
"=",
"str",
"(",
"Path",
"(",
"__file__",
")",
".",
"parent",
".",
"abspath",
"(",
")",
")",
"click",
".",
"secho",
"(",
"script_dir",
",",
"fg",
"=",
"'blue'",
")",
"if",
"editable",
":",
... | install the script onto the system using pip3 | [
"install",
"the",
"script",
"onto",
"the",
"system",
"using",
"pip3"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/cli.py#L152-L159 |
14,339 | Pelagicore/qface | qface/generator.py | merge | def merge(a, b):
"merges b into a recursively if a and b are dicts"
for key in b:
if isinstance(a.get(key), dict) and isinstance(b.get(key), dict):
merge(a[key], b[key])
else:
a[key] = b[key]
return a | python | def merge(a, b):
"merges b into a recursively if a and b are dicts"
for key in b:
if isinstance(a.get(key), dict) and isinstance(b.get(key), dict):
merge(a[key], b[key])
else:
a[key] = b[key]
return a | [
"def",
"merge",
"(",
"a",
",",
"b",
")",
":",
"for",
"key",
"in",
"b",
":",
"if",
"isinstance",
"(",
"a",
".",
"get",
"(",
"key",
")",
",",
"dict",
")",
"and",
"isinstance",
"(",
"b",
".",
"get",
"(",
"key",
")",
",",
"dict",
")",
":",
"mer... | merges b into a recursively if a and b are dicts | [
"merges",
"b",
"into",
"a",
"recursively",
"if",
"a",
"and",
"b",
"are",
"dicts"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L36-L43 |
14,340 | Pelagicore/qface | qface/generator.py | Generator.get_template | def get_template(self, name):
"""Retrieves a single template file from the template loader"""
source = name
if name and name[0] is '/':
source = name[1:]
elif self.source is not None:
source = '/'.join((self.source, name))
return self.env.get_template(source) | python | def get_template(self, name):
source = name
if name and name[0] is '/':
source = name[1:]
elif self.source is not None:
source = '/'.join((self.source, name))
return self.env.get_template(source) | [
"def",
"get_template",
"(",
"self",
",",
"name",
")",
":",
"source",
"=",
"name",
"if",
"name",
"and",
"name",
"[",
"0",
"]",
"is",
"'/'",
":",
"source",
"=",
"name",
"[",
"1",
":",
"]",
"elif",
"self",
".",
"source",
"is",
"not",
"None",
":",
... | Retrieves a single template file from the template loader | [
"Retrieves",
"a",
"single",
"template",
"file",
"from",
"the",
"template",
"loader"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L145-L152 |
14,341 | Pelagicore/qface | qface/generator.py | Generator.render | def render(self, name, context):
"""Returns the rendered text from a single template file from the
template loader using the given context data"""
if Generator.strict:
self.env.undefined = TestableUndefined
else:
self.env.undefined = Undefined
template = self.get_template(name)
return template.render(context) | python | def render(self, name, context):
if Generator.strict:
self.env.undefined = TestableUndefined
else:
self.env.undefined = Undefined
template = self.get_template(name)
return template.render(context) | [
"def",
"render",
"(",
"self",
",",
"name",
",",
"context",
")",
":",
"if",
"Generator",
".",
"strict",
":",
"self",
".",
"env",
".",
"undefined",
"=",
"TestableUndefined",
"else",
":",
"self",
".",
"env",
".",
"undefined",
"=",
"Undefined",
"template",
... | Returns the rendered text from a single template file from the
template loader using the given context data | [
"Returns",
"the",
"rendered",
"text",
"from",
"a",
"single",
"template",
"file",
"from",
"the",
"template",
"loader",
"using",
"the",
"given",
"context",
"data"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L154-L162 |
14,342 | Pelagicore/qface | qface/generator.py | Generator.apply | def apply(self, template, context={}):
context.update(self.context)
"""Return the rendered text of a template instance"""
return self.env.from_string(template).render(context) | python | def apply(self, template, context={}):
context.update(self.context)
return self.env.from_string(template).render(context) | [
"def",
"apply",
"(",
"self",
",",
"template",
",",
"context",
"=",
"{",
"}",
")",
":",
"context",
".",
"update",
"(",
"self",
".",
"context",
")",
"return",
"self",
".",
"env",
".",
"from_string",
"(",
"template",
")",
".",
"render",
"(",
"context",
... | Return the rendered text of a template instance | [
"Return",
"the",
"rendered",
"text",
"of",
"a",
"template",
"instance"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L164-L167 |
14,343 | Pelagicore/qface | qface/generator.py | Generator.write | def write(self, file_path, template, context={}, preserve=False, force=False):
"""Using a template file name it renders a template
into a file given a context
"""
if not file_path or not template:
click.secho('source or target missing for document')
return
if not context:
context = self.context
error = False
try:
self._write(file_path, template, context, preserve, force)
except TemplateSyntaxError as exc:
message = '{0}:{1}: error: {2}'.format(exc.filename, exc.lineno, exc.message)
click.secho(message, fg='red', err=True)
error = True
except TemplateNotFound as exc:
message = '{0}: error: Template not found'.format(exc.name)
click.secho(message, fg='red', err=True)
error = True
except TemplateError as exc:
# Just return with an error, the generic template_error_handler takes care of printing it
error = True
if error and Generator.strict:
sys.exit(1) | python | def write(self, file_path, template, context={}, preserve=False, force=False):
if not file_path or not template:
click.secho('source or target missing for document')
return
if not context:
context = self.context
error = False
try:
self._write(file_path, template, context, preserve, force)
except TemplateSyntaxError as exc:
message = '{0}:{1}: error: {2}'.format(exc.filename, exc.lineno, exc.message)
click.secho(message, fg='red', err=True)
error = True
except TemplateNotFound as exc:
message = '{0}: error: Template not found'.format(exc.name)
click.secho(message, fg='red', err=True)
error = True
except TemplateError as exc:
# Just return with an error, the generic template_error_handler takes care of printing it
error = True
if error and Generator.strict:
sys.exit(1) | [
"def",
"write",
"(",
"self",
",",
"file_path",
",",
"template",
",",
"context",
"=",
"{",
"}",
",",
"preserve",
"=",
"False",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"file_path",
"or",
"not",
"template",
":",
"click",
".",
"secho",
"(",
... | Using a template file name it renders a template
into a file given a context | [
"Using",
"a",
"template",
"file",
"name",
"it",
"renders",
"a",
"template",
"into",
"a",
"file",
"given",
"a",
"context"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L169-L194 |
14,344 | Pelagicore/qface | qface/generator.py | RuleGenerator.process_rules | def process_rules(self, path: Path, system: System):
"""writes the templates read from the rules document"""
self.context.update({
'system': system,
})
document = FileSystem.load_yaml(path, required=True)
for module, rules in document.items():
click.secho('process: {0}'.format(module), fg='green')
self._process_rules(rules, system) | python | def process_rules(self, path: Path, system: System):
self.context.update({
'system': system,
})
document = FileSystem.load_yaml(path, required=True)
for module, rules in document.items():
click.secho('process: {0}'.format(module), fg='green')
self._process_rules(rules, system) | [
"def",
"process_rules",
"(",
"self",
",",
"path",
":",
"Path",
",",
"system",
":",
"System",
")",
":",
"self",
".",
"context",
".",
"update",
"(",
"{",
"'system'",
":",
"system",
",",
"}",
")",
"document",
"=",
"FileSystem",
".",
"load_yaml",
"(",
"p... | writes the templates read from the rules document | [
"writes",
"the",
"templates",
"read",
"from",
"the",
"rules",
"document"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L233-L241 |
14,345 | Pelagicore/qface | qface/generator.py | RuleGenerator._process_rules | def _process_rules(self, rules: dict, system: System):
""" process a set of rules for a target """
self._source = None # reset the template source
if not self._shall_proceed(rules):
return
self.context.update(rules.get('context', {}))
self.path = rules.get('path', '')
self.source = rules.get('source', None)
self._process_rule(rules.get('system', None), {'system': system})
for module in system.modules:
self._process_rule(rules.get('module', None), {'module': module})
for interface in module.interfaces:
self._process_rule(rules.get('interface', None), {'interface': interface})
for struct in module.structs:
self._process_rule(rules.get('struct', None), {'struct': struct})
for enum in module.enums:
self._process_rule(rules.get('enum', None), {'enum': enum}) | python | def _process_rules(self, rules: dict, system: System):
self._source = None # reset the template source
if not self._shall_proceed(rules):
return
self.context.update(rules.get('context', {}))
self.path = rules.get('path', '')
self.source = rules.get('source', None)
self._process_rule(rules.get('system', None), {'system': system})
for module in system.modules:
self._process_rule(rules.get('module', None), {'module': module})
for interface in module.interfaces:
self._process_rule(rules.get('interface', None), {'interface': interface})
for struct in module.structs:
self._process_rule(rules.get('struct', None), {'struct': struct})
for enum in module.enums:
self._process_rule(rules.get('enum', None), {'enum': enum}) | [
"def",
"_process_rules",
"(",
"self",
",",
"rules",
":",
"dict",
",",
"system",
":",
"System",
")",
":",
"self",
".",
"_source",
"=",
"None",
"# reset the template source",
"if",
"not",
"self",
".",
"_shall_proceed",
"(",
"rules",
")",
":",
"return",
"self... | process a set of rules for a target | [
"process",
"a",
"set",
"of",
"rules",
"for",
"a",
"target"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L243-L259 |
14,346 | Pelagicore/qface | qface/generator.py | RuleGenerator._process_rule | def _process_rule(self, rule: dict, context: dict):
""" process a single rule """
if not rule or not self._shall_proceed(rule):
return
self.context.update(context)
self.context.update(rule.get('context', {}))
self.path = rule.get('path', None)
self.source = rule.get('source', None)
for entry in rule.get('documents', []):
target, source = self._resolve_rule_document(entry)
self.write(target, source)
for entry in rule.get('preserve', []):
target, source = self._resolve_rule_document(entry)
self.write(target, source, preserve=True) | python | def _process_rule(self, rule: dict, context: dict):
if not rule or not self._shall_proceed(rule):
return
self.context.update(context)
self.context.update(rule.get('context', {}))
self.path = rule.get('path', None)
self.source = rule.get('source', None)
for entry in rule.get('documents', []):
target, source = self._resolve_rule_document(entry)
self.write(target, source)
for entry in rule.get('preserve', []):
target, source = self._resolve_rule_document(entry)
self.write(target, source, preserve=True) | [
"def",
"_process_rule",
"(",
"self",
",",
"rule",
":",
"dict",
",",
"context",
":",
"dict",
")",
":",
"if",
"not",
"rule",
"or",
"not",
"self",
".",
"_shall_proceed",
"(",
"rule",
")",
":",
"return",
"self",
".",
"context",
".",
"update",
"(",
"conte... | process a single rule | [
"process",
"a",
"single",
"rule"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L261-L274 |
14,347 | Pelagicore/qface | qface/generator.py | FileSystem._parse_document | def _parse_document(document: Path, system: System = None, profile=EProfile.FULL):
"""Parses a document and returns the resulting domain system
:param path: document path to parse
:param system: system to be used (optional)
"""
logger.debug('parse document: {0}'.format(document))
stream = FileStream(str(document), encoding='utf-8')
system = FileSystem._parse_stream(stream, system, document, profile)
FileSystem.merge_annotations(system, document.stripext() + '.yaml')
return system | python | def _parse_document(document: Path, system: System = None, profile=EProfile.FULL):
logger.debug('parse document: {0}'.format(document))
stream = FileStream(str(document), encoding='utf-8')
system = FileSystem._parse_stream(stream, system, document, profile)
FileSystem.merge_annotations(system, document.stripext() + '.yaml')
return system | [
"def",
"_parse_document",
"(",
"document",
":",
"Path",
",",
"system",
":",
"System",
"=",
"None",
",",
"profile",
"=",
"EProfile",
".",
"FULL",
")",
":",
"logger",
".",
"debug",
"(",
"'parse document: {0}'",
".",
"format",
"(",
"document",
")",
")",
"st... | Parses a document and returns the resulting domain system
:param path: document path to parse
:param system: system to be used (optional) | [
"Parses",
"a",
"document",
"and",
"returns",
"the",
"resulting",
"domain",
"system"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L316-L326 |
14,348 | Pelagicore/qface | qface/generator.py | FileSystem.merge_annotations | def merge_annotations(system, document):
"""Read a YAML document and for each root symbol identifier
updates the tag information of that symbol
"""
if not Path(document).exists():
return
meta = FileSystem.load_yaml(document)
click.secho('merge: {0}'.format(document.name), fg='blue')
for identifier, data in meta.items():
symbol = system.lookup(identifier)
if symbol:
merge(symbol.tags, data) | python | def merge_annotations(system, document):
if not Path(document).exists():
return
meta = FileSystem.load_yaml(document)
click.secho('merge: {0}'.format(document.name), fg='blue')
for identifier, data in meta.items():
symbol = system.lookup(identifier)
if symbol:
merge(symbol.tags, data) | [
"def",
"merge_annotations",
"(",
"system",
",",
"document",
")",
":",
"if",
"not",
"Path",
"(",
"document",
")",
".",
"exists",
"(",
")",
":",
"return",
"meta",
"=",
"FileSystem",
".",
"load_yaml",
"(",
"document",
")",
"click",
".",
"secho",
"(",
"'me... | Read a YAML document and for each root symbol identifier
updates the tag information of that symbol | [
"Read",
"a",
"YAML",
"document",
"and",
"for",
"each",
"root",
"symbol",
"identifier",
"updates",
"the",
"tag",
"information",
"of",
"that",
"symbol"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L343-L354 |
14,349 | Pelagicore/qface | qface/generator.py | FileSystem.parse | def parse(input, identifier: str = None, use_cache=False, clear_cache=True, pattern="*.qface", profile=EProfile.FULL):
"""Input can be either a file or directory or a list of files or directory.
A directory will be parsed recursively. The function returns the resulting system.
Stores the result of the run in the domain cache named after the identifier.
:param path: directory to parse
:param identifier: identifies the parse run. Used to name the cache
:param clear_cache: clears the domain cache (defaults to true)
"""
inputs = input if isinstance(input, (list, tuple)) else [input]
logger.debug('parse input={0}'.format(inputs))
identifier = 'system' if not identifier else identifier
system = System()
cache = None
if use_cache:
cache = shelve.open('qface.cache')
if identifier in cache and clear_cache:
del cache[identifier]
if identifier in cache:
# use the cached domain model
system = cache[identifier]
# if domain model not cached generate it
for input in inputs:
path = Path.getcwd() / str(input)
if path.isfile():
FileSystem.parse_document(path, system)
else:
for document in path.walkfiles(pattern):
FileSystem.parse_document(document, system)
if use_cache:
cache[identifier] = system
return system | python | def parse(input, identifier: str = None, use_cache=False, clear_cache=True, pattern="*.qface", profile=EProfile.FULL):
inputs = input if isinstance(input, (list, tuple)) else [input]
logger.debug('parse input={0}'.format(inputs))
identifier = 'system' if not identifier else identifier
system = System()
cache = None
if use_cache:
cache = shelve.open('qface.cache')
if identifier in cache and clear_cache:
del cache[identifier]
if identifier in cache:
# use the cached domain model
system = cache[identifier]
# if domain model not cached generate it
for input in inputs:
path = Path.getcwd() / str(input)
if path.isfile():
FileSystem.parse_document(path, system)
else:
for document in path.walkfiles(pattern):
FileSystem.parse_document(document, system)
if use_cache:
cache[identifier] = system
return system | [
"def",
"parse",
"(",
"input",
",",
"identifier",
":",
"str",
"=",
"None",
",",
"use_cache",
"=",
"False",
",",
"clear_cache",
"=",
"True",
",",
"pattern",
"=",
"\"*.qface\"",
",",
"profile",
"=",
"EProfile",
".",
"FULL",
")",
":",
"inputs",
"=",
"input... | Input can be either a file or directory or a list of files or directory.
A directory will be parsed recursively. The function returns the resulting system.
Stores the result of the run in the domain cache named after the identifier.
:param path: directory to parse
:param identifier: identifies the parse run. Used to name the cache
:param clear_cache: clears the domain cache (defaults to true) | [
"Input",
"can",
"be",
"either",
"a",
"file",
"or",
"directory",
"or",
"a",
"list",
"of",
"files",
"or",
"directory",
".",
"A",
"directory",
"will",
"be",
"parsed",
"recursively",
".",
"The",
"function",
"returns",
"the",
"resulting",
"system",
".",
"Stores... | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/generator.py#L357-L389 |
14,350 | Pelagicore/qface | qface/watch.py | monitor | def monitor(args, watch):
"""
reloads the script given by argv when src files changes
"""
watch = watch if isinstance(watch, (list, tuple)) else [watch]
watch = [Path(entry).expand().abspath() for entry in watch]
event_handler = RunScriptChangeHandler(args)
observer = Observer()
for entry in watch:
if entry.isfile():
entry = entry.parent
click.secho('watch recursive: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
event_handler.run() # run always once
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join() | python | def monitor(args, watch):
watch = watch if isinstance(watch, (list, tuple)) else [watch]
watch = [Path(entry).expand().abspath() for entry in watch]
event_handler = RunScriptChangeHandler(args)
observer = Observer()
for entry in watch:
if entry.isfile():
entry = entry.parent
click.secho('watch recursive: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
event_handler.run() # run always once
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join() | [
"def",
"monitor",
"(",
"args",
",",
"watch",
")",
":",
"watch",
"=",
"watch",
"if",
"isinstance",
"(",
"watch",
",",
"(",
"list",
",",
"tuple",
")",
")",
"else",
"[",
"watch",
"]",
"watch",
"=",
"[",
"Path",
"(",
"entry",
")",
".",
"expand",
"(",... | reloads the script given by argv when src files changes | [
"reloads",
"the",
"script",
"given",
"by",
"argv",
"when",
"src",
"files",
"changes"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/watch.py#L32-L53 |
14,351 | Pelagicore/qface | qface/idl/domain.py | System.lookup | def lookup(self, name: str):
'''lookup a symbol by fully qualified name.'''
# <module>
if name in self._moduleMap:
return self._moduleMap[name]
# <module>.<Symbol>
(module_name, type_name, fragment_name) = self.split_typename(name)
if not module_name and type_name:
click.secho('not able to lookup symbol: {0}'.format(name), fg='red')
return None
module = self._moduleMap[module_name]
return module.lookup(type_name, fragment_name) | python | def lookup(self, name: str):
'''lookup a symbol by fully qualified name.'''
# <module>
if name in self._moduleMap:
return self._moduleMap[name]
# <module>.<Symbol>
(module_name, type_name, fragment_name) = self.split_typename(name)
if not module_name and type_name:
click.secho('not able to lookup symbol: {0}'.format(name), fg='red')
return None
module = self._moduleMap[module_name]
return module.lookup(type_name, fragment_name) | [
"def",
"lookup",
"(",
"self",
",",
"name",
":",
"str",
")",
":",
"# <module>",
"if",
"name",
"in",
"self",
".",
"_moduleMap",
":",
"return",
"self",
".",
"_moduleMap",
"[",
"name",
"]",
"# <module>.<Symbol>",
"(",
"module_name",
",",
"type_name",
",",
"f... | lookup a symbol by fully qualified name. | [
"lookup",
"a",
"symbol",
"by",
"fully",
"qualified",
"name",
"."
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/idl/domain.py#L51-L62 |
14,352 | Pelagicore/qface | qface/idl/domain.py | Symbol.add_tag | def add_tag(self, tag):
""" add a tag to the tag list """
if tag not in self._tags:
self._tags[tag] = dict() | python | def add_tag(self, tag):
if tag not in self._tags:
self._tags[tag] = dict() | [
"def",
"add_tag",
"(",
"self",
",",
"tag",
")",
":",
"if",
"tag",
"not",
"in",
"self",
".",
"_tags",
":",
"self",
".",
"_tags",
"[",
"tag",
"]",
"=",
"dict",
"(",
")"
] | add a tag to the tag list | [
"add",
"a",
"tag",
"to",
"the",
"tag",
"list"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/idl/domain.py#L146-L149 |
14,353 | Pelagicore/qface | qface/idl/domain.py | Symbol.attribute | def attribute(self, tag, name):
""" return attribute by tag and attribute name """
if tag in self._tags and name in self._tags[tag]:
return self._tags[tag][name] | python | def attribute(self, tag, name):
if tag in self._tags and name in self._tags[tag]:
return self._tags[tag][name] | [
"def",
"attribute",
"(",
"self",
",",
"tag",
",",
"name",
")",
":",
"if",
"tag",
"in",
"self",
".",
"_tags",
"and",
"name",
"in",
"self",
".",
"_tags",
"[",
"tag",
"]",
":",
"return",
"self",
".",
"_tags",
"[",
"tag",
"]",
"[",
"name",
"]"
] | return attribute by tag and attribute name | [
"return",
"attribute",
"by",
"tag",
"and",
"attribute",
"name"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/idl/domain.py#L161-L164 |
14,354 | Pelagicore/qface | qface/idl/domain.py | TypeSymbol.is_valid | def is_valid(self):
'''checks if type is a valid type'''
return (self.is_primitive and self.name) \
or (self.is_complex and self.name) \
or (self.is_list and self.nested) \
or (self.is_map and self.nested) \
or (self.is_model and self.nested) | python | def is_valid(self):
'''checks if type is a valid type'''
return (self.is_primitive and self.name) \
or (self.is_complex and self.name) \
or (self.is_list and self.nested) \
or (self.is_map and self.nested) \
or (self.is_model and self.nested) | [
"def",
"is_valid",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"is_primitive",
"and",
"self",
".",
"name",
")",
"or",
"(",
"self",
".",
"is_complex",
"and",
"self",
".",
"name",
")",
"or",
"(",
"self",
".",
"is_list",
"and",
"self",
".",
"ne... | checks if type is a valid type | [
"checks",
"if",
"type",
"is",
"a",
"valid",
"type"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/idl/domain.py#L209-L215 |
14,355 | Pelagicore/qface | qface/idl/domain.py | TypeSymbol._resolve | def _resolve(self):
"""resolve the type symbol from name by doing a lookup"""
self.__is_resolved = True
if self.is_complex:
type = self.nested if self.nested else self
type.__reference = self.module.lookup(type.name) | python | def _resolve(self):
self.__is_resolved = True
if self.is_complex:
type = self.nested if self.nested else self
type.__reference = self.module.lookup(type.name) | [
"def",
"_resolve",
"(",
"self",
")",
":",
"self",
".",
"__is_resolved",
"=",
"True",
"if",
"self",
".",
"is_complex",
":",
"type",
"=",
"self",
".",
"nested",
"if",
"self",
".",
"nested",
"else",
"self",
"type",
".",
"__reference",
"=",
"self",
".",
... | resolve the type symbol from name by doing a lookup | [
"resolve",
"the",
"type",
"symbol",
"from",
"name",
"by",
"doing",
"a",
"lookup"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/idl/domain.py#L274-L279 |
14,356 | Pelagicore/qface | qface/idl/domain.py | Module.lookup | def lookup(self, name: str, fragment: str = None):
'''lookup a symbol by name. If symbol is not local
it will be looked up system wide'''
if name in self._contentMap:
symbol = self._contentMap[name]
if fragment:
return symbol._contentMap[fragment]
return symbol
return self.system.lookup(name) | python | def lookup(self, name: str, fragment: str = None):
'''lookup a symbol by name. If symbol is not local
it will be looked up system wide'''
if name in self._contentMap:
symbol = self._contentMap[name]
if fragment:
return symbol._contentMap[fragment]
return symbol
return self.system.lookup(name) | [
"def",
"lookup",
"(",
"self",
",",
"name",
":",
"str",
",",
"fragment",
":",
"str",
"=",
"None",
")",
":",
"if",
"name",
"in",
"self",
".",
"_contentMap",
":",
"symbol",
"=",
"self",
".",
"_contentMap",
"[",
"name",
"]",
"if",
"fragment",
":",
"ret... | lookup a symbol by name. If symbol is not local
it will be looked up system wide | [
"lookup",
"a",
"symbol",
"by",
"name",
".",
"If",
"symbol",
"is",
"not",
"local",
"it",
"will",
"be",
"looked",
"up",
"system",
"wide"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/idl/domain.py#L368-L376 |
14,357 | Pelagicore/qface | qface/helper/generic.py | jsonify | def jsonify(symbol):
""" returns json format for symbol """
try:
# all symbols have a toJson method, try it
return json.dumps(symbol.toJson(), indent=' ')
except AttributeError:
pass
return json.dumps(symbol, indent=' ') | python | def jsonify(symbol):
try:
# all symbols have a toJson method, try it
return json.dumps(symbol.toJson(), indent=' ')
except AttributeError:
pass
return json.dumps(symbol, indent=' ') | [
"def",
"jsonify",
"(",
"symbol",
")",
":",
"try",
":",
"# all symbols have a toJson method, try it",
"return",
"json",
".",
"dumps",
"(",
"symbol",
".",
"toJson",
"(",
")",
",",
"indent",
"=",
"' '",
")",
"except",
"AttributeError",
":",
"pass",
"return",
"... | returns json format for symbol | [
"returns",
"json",
"format",
"for",
"symbol"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/helper/generic.py#L5-L12 |
14,358 | Pelagicore/qface | qface/helper/generic.py | hash | def hash(symbol, hash_type='sha1'):
""" create a hash code from symbol """
code = hashlib.new(hash_type)
code.update(str(symbol).encode('utf-8'))
return code.hexdigest() | python | def hash(symbol, hash_type='sha1'):
code = hashlib.new(hash_type)
code.update(str(symbol).encode('utf-8'))
return code.hexdigest() | [
"def",
"hash",
"(",
"symbol",
",",
"hash_type",
"=",
"'sha1'",
")",
":",
"code",
"=",
"hashlib",
".",
"new",
"(",
"hash_type",
")",
"code",
".",
"update",
"(",
"str",
"(",
"symbol",
")",
".",
"encode",
"(",
"'utf-8'",
")",
")",
"return",
"code",
".... | create a hash code from symbol | [
"create",
"a",
"hash",
"code",
"from",
"symbol"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/helper/generic.py#L26-L30 |
14,359 | Pelagicore/qface | qface/shell.py | sh | def sh(args, **kwargs):
"""
runs the given cmd as shell command
"""
if isinstance(args, str):
args = args.split()
if not args:
return
click.echo('$ {0}'.format(' '.join(args)))
try:
return subprocess.check_call(args, **kwargs)
except subprocess.CalledProcessError as exc:
click.secho('run error {}'.format(exc))
except OSError as exc:
click.secho('not found error {}'.format(exc)) | python | def sh(args, **kwargs):
if isinstance(args, str):
args = args.split()
if not args:
return
click.echo('$ {0}'.format(' '.join(args)))
try:
return subprocess.check_call(args, **kwargs)
except subprocess.CalledProcessError as exc:
click.secho('run error {}'.format(exc))
except OSError as exc:
click.secho('not found error {}'.format(exc)) | [
"def",
"sh",
"(",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"args",
",",
"str",
")",
":",
"args",
"=",
"args",
".",
"split",
"(",
")",
"if",
"not",
"args",
":",
"return",
"click",
".",
"echo",
"(",
"'$ {0}'",
".",
"for... | runs the given cmd as shell command | [
"runs",
"the",
"given",
"cmd",
"as",
"shell",
"command"
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/shell.py#L9-L23 |
14,360 | Pelagicore/qface | qface/helper/doc.py | parse_doc | def parse_doc(s):
""" parse a comment in the format of JavaDoc and returns an object, where each JavaDoc tag
is a property of the object. """
if not s:
return
doc = DocObject()
tag = None
s = s[3:-2] # remove '/**' and '*/'
for line in s.splitlines():
line = line.lstrip(' *') # strip a ' ' and '*' from start
if not line:
tag = None # on empty line reset the tag information
elif line[0] == '@':
line = line[1:]
res = line.split(maxsplit=1)
if len(res) == 0:
continue
tag = res[0]
if len(res) == 1:
doc.add_tag(tag, True)
elif len(res) == 2:
value = res[1]
doc.add_tag(tag, value)
elif tag: # append to previous matched tag
doc.add_tag(tag, line)
else: # append any loose lines to description
doc.add_tag('description', line)
return doc | python | def parse_doc(s):
if not s:
return
doc = DocObject()
tag = None
s = s[3:-2] # remove '/**' and '*/'
for line in s.splitlines():
line = line.lstrip(' *') # strip a ' ' and '*' from start
if not line:
tag = None # on empty line reset the tag information
elif line[0] == '@':
line = line[1:]
res = line.split(maxsplit=1)
if len(res) == 0:
continue
tag = res[0]
if len(res) == 1:
doc.add_tag(tag, True)
elif len(res) == 2:
value = res[1]
doc.add_tag(tag, value)
elif tag: # append to previous matched tag
doc.add_tag(tag, line)
else: # append any loose lines to description
doc.add_tag('description', line)
return doc | [
"def",
"parse_doc",
"(",
"s",
")",
":",
"if",
"not",
"s",
":",
"return",
"doc",
"=",
"DocObject",
"(",
")",
"tag",
"=",
"None",
"s",
"=",
"s",
"[",
"3",
":",
"-",
"2",
"]",
"# remove '/**' and '*/'",
"for",
"line",
"in",
"s",
".",
"splitlines",
"... | parse a comment in the format of JavaDoc and returns an object, where each JavaDoc tag
is a property of the object. | [
"parse",
"a",
"comment",
"in",
"the",
"format",
"of",
"JavaDoc",
"and",
"returns",
"an",
"object",
"where",
"each",
"JavaDoc",
"tag",
"is",
"a",
"property",
"of",
"the",
"object",
"."
] | 7f60e91e3a91a7cb04cfacbc9ce80f43df444853 | https://github.com/Pelagicore/qface/blob/7f60e91e3a91a7cb04cfacbc9ce80f43df444853/qface/helper/doc.py#L58-L85 |
14,361 | edx/completion | completion/api/permissions.py | IsUserInUrl.has_permission | def has_permission(self, request, view):
"""
Returns true if the current request is by the user themselves.
Note: a 404 is returned for non-staff instead of a 403. This is to prevent
users from being able to detect the existence of accounts.
"""
url_username = request.parser_context.get('kwargs', {}).get('username', '')
if request.user.username.lower() != url_username.lower():
if request.user.is_staff:
return False # staff gets 403
raise Http404()
return True | python | def has_permission(self, request, view):
url_username = request.parser_context.get('kwargs', {}).get('username', '')
if request.user.username.lower() != url_username.lower():
if request.user.is_staff:
return False # staff gets 403
raise Http404()
return True | [
"def",
"has_permission",
"(",
"self",
",",
"request",
",",
"view",
")",
":",
"url_username",
"=",
"request",
".",
"parser_context",
".",
"get",
"(",
"'kwargs'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'username'",
",",
"''",
")",
"if",
"request",
".",
... | Returns true if the current request is by the user themselves.
Note: a 404 is returned for non-staff instead of a 403. This is to prevent
users from being able to detect the existence of accounts. | [
"Returns",
"true",
"if",
"the",
"current",
"request",
"is",
"by",
"the",
"user",
"themselves",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/api/permissions.py#L35-L47 |
14,362 | edx/completion | completion/fields.py | BigAutoField.db_type | def db_type(self, connection):
"""
The type of the field to insert into the database.
"""
conn_module = type(connection).__module__
if "mysql" in conn_module:
return "bigint AUTO_INCREMENT"
elif "postgres" in conn_module:
return "bigserial"
return super(BigAutoField, self).db_type(connection) | python | def db_type(self, connection):
conn_module = type(connection).__module__
if "mysql" in conn_module:
return "bigint AUTO_INCREMENT"
elif "postgres" in conn_module:
return "bigserial"
return super(BigAutoField, self).db_type(connection) | [
"def",
"db_type",
"(",
"self",
",",
"connection",
")",
":",
"conn_module",
"=",
"type",
"(",
"connection",
")",
".",
"__module__",
"if",
"\"mysql\"",
"in",
"conn_module",
":",
"return",
"\"bigint AUTO_INCREMENT\"",
"elif",
"\"postgres\"",
"in",
"conn_module",
":... | The type of the field to insert into the database. | [
"The",
"type",
"of",
"the",
"field",
"to",
"insert",
"into",
"the",
"database",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/fields.py#L19-L28 |
14,363 | edx/completion | completion/models.py | BlockCompletionManager.submit_completion | def submit_completion(self, user, course_key, block_key, completion):
"""
Update the completion value for the specified record.
Parameters:
* user (django.contrib.auth.models.User): The user for whom the
completion is being submitted.
* course_key (opaque_keys.edx.keys.CourseKey): The course in
which the submitted block is found.
* block_key (opaque_keys.edx.keys.UsageKey): The block that has had
its completion changed.
* completion (float in range [0.0, 1.0]): The fractional completion
value of the block (0.0 = incomplete, 1.0 = complete).
Return Value:
(BlockCompletion, bool): A tuple comprising the created or updated
BlockCompletion object and a boolean value indicating whether the
object was newly created by this call.
Raises:
ValueError:
If the wrong type is passed for one of the parameters.
django.core.exceptions.ValidationError:
If a float is passed that is not between 0.0 and 1.0.
django.db.DatabaseError:
If there was a problem getting, creating, or updating the
BlockCompletion record in the database.
This will also be a more specific error, as described here:
https://docs.djangoproject.com/en/1.11/ref/exceptions/#database-exceptions.
IntegrityError and OperationalError are relatively common
subclasses.
"""
# Raise ValueError to match normal django semantics for wrong type of field.
if not isinstance(course_key, CourseKey):
raise ValueError(
"course_key must be an instance of `opaque_keys.edx.keys.CourseKey`. Got {}".format(type(course_key))
)
try:
block_type = block_key.block_type
except AttributeError:
raise ValueError(
"block_key must be an instance of `opaque_keys.edx.keys.UsageKey`. Got {}".format(type(block_key))
)
if waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
try:
with transaction.atomic():
obj, is_new = self.get_or_create( # pylint: disable=unpacking-non-sequence
user=user,
course_key=course_key,
block_key=block_key,
defaults={
'completion': completion,
'block_type': block_type,
},
)
except IntegrityError:
# The completion was created concurrently by another process
log.info(
"An IntegrityError was raised when trying to create a BlockCompletion for %s:%s:%s. "
"Falling back to get().",
user,
course_key,
block_key,
)
obj = self.get(
user=user,
course_key=course_key,
block_key=block_key,
)
is_new = False
if not is_new and obj.completion != completion:
obj.completion = completion
obj.full_clean()
obj.save(update_fields={'completion', 'modified'})
else:
# If the feature is not enabled, this method should not be called.
# Error out with a RuntimeError.
raise RuntimeError(
"BlockCompletion.objects.submit_completion should not be \
called when the feature is disabled."
)
return obj, is_new | python | def submit_completion(self, user, course_key, block_key, completion):
# Raise ValueError to match normal django semantics for wrong type of field.
if not isinstance(course_key, CourseKey):
raise ValueError(
"course_key must be an instance of `opaque_keys.edx.keys.CourseKey`. Got {}".format(type(course_key))
)
try:
block_type = block_key.block_type
except AttributeError:
raise ValueError(
"block_key must be an instance of `opaque_keys.edx.keys.UsageKey`. Got {}".format(type(block_key))
)
if waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
try:
with transaction.atomic():
obj, is_new = self.get_or_create( # pylint: disable=unpacking-non-sequence
user=user,
course_key=course_key,
block_key=block_key,
defaults={
'completion': completion,
'block_type': block_type,
},
)
except IntegrityError:
# The completion was created concurrently by another process
log.info(
"An IntegrityError was raised when trying to create a BlockCompletion for %s:%s:%s. "
"Falling back to get().",
user,
course_key,
block_key,
)
obj = self.get(
user=user,
course_key=course_key,
block_key=block_key,
)
is_new = False
if not is_new and obj.completion != completion:
obj.completion = completion
obj.full_clean()
obj.save(update_fields={'completion', 'modified'})
else:
# If the feature is not enabled, this method should not be called.
# Error out with a RuntimeError.
raise RuntimeError(
"BlockCompletion.objects.submit_completion should not be \
called when the feature is disabled."
)
return obj, is_new | [
"def",
"submit_completion",
"(",
"self",
",",
"user",
",",
"course_key",
",",
"block_key",
",",
"completion",
")",
":",
"# Raise ValueError to match normal django semantics for wrong type of field.",
"if",
"not",
"isinstance",
"(",
"course_key",
",",
"CourseKey",
")",
"... | Update the completion value for the specified record.
Parameters:
* user (django.contrib.auth.models.User): The user for whom the
completion is being submitted.
* course_key (opaque_keys.edx.keys.CourseKey): The course in
which the submitted block is found.
* block_key (opaque_keys.edx.keys.UsageKey): The block that has had
its completion changed.
* completion (float in range [0.0, 1.0]): The fractional completion
value of the block (0.0 = incomplete, 1.0 = complete).
Return Value:
(BlockCompletion, bool): A tuple comprising the created or updated
BlockCompletion object and a boolean value indicating whether the
object was newly created by this call.
Raises:
ValueError:
If the wrong type is passed for one of the parameters.
django.core.exceptions.ValidationError:
If a float is passed that is not between 0.0 and 1.0.
django.db.DatabaseError:
If there was a problem getting, creating, or updating the
BlockCompletion record in the database.
This will also be a more specific error, as described here:
https://docs.djangoproject.com/en/1.11/ref/exceptions/#database-exceptions.
IntegrityError and OperationalError are relatively common
subclasses. | [
"Update",
"the",
"completion",
"value",
"for",
"the",
"specified",
"record",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/models.py#L46-L132 |
14,364 | edx/completion | completion/models.py | BlockCompletionManager.submit_batch_completion | def submit_batch_completion(self, user, course_key, blocks):
"""
Performs a batch insertion of completion objects.
Parameters:
* user (django.contrib.auth.models.User): The user for whom the
completions are being submitted.
* course_key (opaque_keys.edx.keys.CourseKey): The course in
which the submitted blocks are found.
* blocks: A list of tuples of UsageKey to float completion values.
(float in range [0.0, 1.0]): The fractional completion
value of the block (0.0 = incomplete, 1.0 = complete).
Return Value:
Dict of (BlockCompletion, bool): A dictionary with a
BlockCompletion object key and a value of bool. The boolean value
indicates whether the object was newly created by this call.
Raises:
ValueError:
If the wrong type is passed for one of the parameters.
django.core.exceptions.ValidationError:
If a float is passed that is not between 0.0 and 1.0.
django.db.DatabaseError:
If there was a problem getting, creating, or updating the
BlockCompletion record in the database.
"""
block_completions = {}
for block, completion in blocks:
(block_completion, is_new) = self.submit_completion(user, course_key, block, completion)
block_completions[block_completion] = is_new
return block_completions | python | def submit_batch_completion(self, user, course_key, blocks):
block_completions = {}
for block, completion in blocks:
(block_completion, is_new) = self.submit_completion(user, course_key, block, completion)
block_completions[block_completion] = is_new
return block_completions | [
"def",
"submit_batch_completion",
"(",
"self",
",",
"user",
",",
"course_key",
",",
"blocks",
")",
":",
"block_completions",
"=",
"{",
"}",
"for",
"block",
",",
"completion",
"in",
"blocks",
":",
"(",
"block_completion",
",",
"is_new",
")",
"=",
"self",
".... | Performs a batch insertion of completion objects.
Parameters:
* user (django.contrib.auth.models.User): The user for whom the
completions are being submitted.
* course_key (opaque_keys.edx.keys.CourseKey): The course in
which the submitted blocks are found.
* blocks: A list of tuples of UsageKey to float completion values.
(float in range [0.0, 1.0]): The fractional completion
value of the block (0.0 = incomplete, 1.0 = complete).
Return Value:
Dict of (BlockCompletion, bool): A dictionary with a
BlockCompletion object key and a value of bool. The boolean value
indicates whether the object was newly created by this call.
Raises:
ValueError:
If the wrong type is passed for one of the parameters.
django.core.exceptions.ValidationError:
If a float is passed that is not between 0.0 and 1.0.
django.db.DatabaseError:
If there was a problem getting, creating, or updating the
BlockCompletion record in the database. | [
"Performs",
"a",
"batch",
"insertion",
"of",
"completion",
"objects",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/models.py#L135-L169 |
14,365 | edx/completion | completion/models.py | BlockCompletion.full_block_key | def full_block_key(self):
"""
Returns the "correct" usage key value with the run filled in.
"""
if self.block_key.run is None:
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
return self.block_key.replace(course_key=self.course_key)
return self.block_key | python | def full_block_key(self):
if self.block_key.run is None:
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
return self.block_key.replace(course_key=self.course_key)
return self.block_key | [
"def",
"full_block_key",
"(",
"self",
")",
":",
"if",
"self",
".",
"block_key",
".",
"run",
"is",
"None",
":",
"# pylint: disable=unexpected-keyword-arg, no-value-for-parameter",
"return",
"self",
".",
"block_key",
".",
"replace",
"(",
"course_key",
"=",
"self",
"... | Returns the "correct" usage key value with the run filled in. | [
"Returns",
"the",
"correct",
"usage",
"key",
"value",
"with",
"the",
"run",
"filled",
"in",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/models.py#L202-L209 |
14,366 | edx/completion | completion/models.py | BlockCompletion.get_course_completions | def get_course_completions(cls, user, course_key):
"""
Returns a dictionary mapping BlockKeys to completion values for all
BlockCompletion records for the given user and course_key.
Return value:
dict[BlockKey] = float
"""
user_course_completions = cls.user_course_completion_queryset(user, course_key)
return cls.completion_by_block_key(user_course_completions) | python | def get_course_completions(cls, user, course_key):
user_course_completions = cls.user_course_completion_queryset(user, course_key)
return cls.completion_by_block_key(user_course_completions) | [
"def",
"get_course_completions",
"(",
"cls",
",",
"user",
",",
"course_key",
")",
":",
"user_course_completions",
"=",
"cls",
".",
"user_course_completion_queryset",
"(",
"user",
",",
"course_key",
")",
"return",
"cls",
".",
"completion_by_block_key",
"(",
"user_cou... | Returns a dictionary mapping BlockKeys to completion values for all
BlockCompletion records for the given user and course_key.
Return value:
dict[BlockKey] = float | [
"Returns",
"a",
"dictionary",
"mapping",
"BlockKeys",
"to",
"completion",
"values",
"for",
"all",
"BlockCompletion",
"records",
"for",
"the",
"given",
"user",
"and",
"course_key",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/models.py#L212-L221 |
14,367 | edx/completion | completion/models.py | BlockCompletion.user_course_completion_queryset | def user_course_completion_queryset(cls, user, course_key):
"""
Returns a Queryset of completions for a given user and course_key.
"""
return cls.objects.filter(user=user, course_key=course_key) | python | def user_course_completion_queryset(cls, user, course_key):
return cls.objects.filter(user=user, course_key=course_key) | [
"def",
"user_course_completion_queryset",
"(",
"cls",
",",
"user",
",",
"course_key",
")",
":",
"return",
"cls",
".",
"objects",
".",
"filter",
"(",
"user",
"=",
"user",
",",
"course_key",
"=",
"course_key",
")"
] | Returns a Queryset of completions for a given user and course_key. | [
"Returns",
"a",
"Queryset",
"of",
"completions",
"for",
"a",
"given",
"user",
"and",
"course_key",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/models.py#L224-L228 |
14,368 | edx/completion | completion/handlers.py | scorable_block_completion | def scorable_block_completion(sender, **kwargs): # pylint: disable=unused-argument
"""
When a problem is scored, submit a new BlockCompletion for that block.
"""
if not waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
return
course_key = CourseKey.from_string(kwargs['course_id'])
block_key = UsageKey.from_string(kwargs['usage_id'])
block_cls = XBlock.load_class(block_key.block_type)
if XBlockCompletionMode.get_mode(block_cls) != XBlockCompletionMode.COMPLETABLE:
return
if getattr(block_cls, 'has_custom_completion', False):
return
user = User.objects.get(id=kwargs['user_id'])
if kwargs.get('score_deleted'):
completion = 0.0
else:
completion = 1.0
if not kwargs.get('grader_response'):
BlockCompletion.objects.submit_completion(
user=user,
course_key=course_key,
block_key=block_key,
completion=completion,
) | python | def scorable_block_completion(sender, **kwargs): # pylint: disable=unused-argument
if not waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
return
course_key = CourseKey.from_string(kwargs['course_id'])
block_key = UsageKey.from_string(kwargs['usage_id'])
block_cls = XBlock.load_class(block_key.block_type)
if XBlockCompletionMode.get_mode(block_cls) != XBlockCompletionMode.COMPLETABLE:
return
if getattr(block_cls, 'has_custom_completion', False):
return
user = User.objects.get(id=kwargs['user_id'])
if kwargs.get('score_deleted'):
completion = 0.0
else:
completion = 1.0
if not kwargs.get('grader_response'):
BlockCompletion.objects.submit_completion(
user=user,
course_key=course_key,
block_key=block_key,
completion=completion,
) | [
"def",
"scorable_block_completion",
"(",
"sender",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=unused-argument",
"if",
"not",
"waffle",
".",
"waffle",
"(",
")",
".",
"is_enabled",
"(",
"waffle",
".",
"ENABLE_COMPLETION_TRACKING",
")",
":",
"return",
"c... | When a problem is scored, submit a new BlockCompletion for that block. | [
"When",
"a",
"problem",
"is",
"scored",
"submit",
"a",
"new",
"BlockCompletion",
"for",
"that",
"block",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/handlers.py#L15-L39 |
14,369 | edx/completion | completion/api/v1/views.py | CompletionBatchView._validate_and_parse | def _validate_and_parse(self, batch_object):
"""
Performs validation on the batch object to make sure it is in the proper format.
Parameters:
* batch_object: The data provided to a POST. The expected format is the following:
{
"username": "username",
"course_key": "course-key",
"blocks": {
"block_key1": 0.0,
"block_key2": 1.0,
"block_key3": 1.0,
}
}
Return Value:
* tuple: (User, CourseKey, List of tuples (UsageKey, completion_float)
Raises:
django.core.exceptions.ValidationError:
If any aspect of validation fails a ValidationError is raised.
ObjectDoesNotExist:
If a database object cannot be found an ObjectDoesNotExist is raised.
"""
if not waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
raise ValidationError(
_("BlockCompletion.objects.submit_batch_completion should not be called when the feature is disabled.")
)
for key in self.REQUIRED_KEYS:
if key not in batch_object:
raise ValidationError(_("Key '{key}' not found.").format(key=key))
username = batch_object['username']
user = User.objects.get(username=username)
course_key_obj = self._validate_and_parse_course_key(batch_object['course_key'])
if not CourseEnrollment.is_enrolled(user, course_key_obj):
raise ValidationError(_('User is not enrolled in course.'))
blocks = batch_object['blocks']
block_objs = []
for block_key in blocks:
block_key_obj = self._validate_and_parse_block_key(block_key, course_key_obj)
completion = float(blocks[block_key])
block_objs.append((block_key_obj, completion))
return user, course_key_obj, block_objs | python | def _validate_and_parse(self, batch_object):
if not waffle.waffle().is_enabled(waffle.ENABLE_COMPLETION_TRACKING):
raise ValidationError(
_("BlockCompletion.objects.submit_batch_completion should not be called when the feature is disabled.")
)
for key in self.REQUIRED_KEYS:
if key not in batch_object:
raise ValidationError(_("Key '{key}' not found.").format(key=key))
username = batch_object['username']
user = User.objects.get(username=username)
course_key_obj = self._validate_and_parse_course_key(batch_object['course_key'])
if not CourseEnrollment.is_enrolled(user, course_key_obj):
raise ValidationError(_('User is not enrolled in course.'))
blocks = batch_object['blocks']
block_objs = []
for block_key in blocks:
block_key_obj = self._validate_and_parse_block_key(block_key, course_key_obj)
completion = float(blocks[block_key])
block_objs.append((block_key_obj, completion))
return user, course_key_obj, block_objs | [
"def",
"_validate_and_parse",
"(",
"self",
",",
"batch_object",
")",
":",
"if",
"not",
"waffle",
".",
"waffle",
"(",
")",
".",
"is_enabled",
"(",
"waffle",
".",
"ENABLE_COMPLETION_TRACKING",
")",
":",
"raise",
"ValidationError",
"(",
"_",
"(",
"\"BlockCompleti... | Performs validation on the batch object to make sure it is in the proper format.
Parameters:
* batch_object: The data provided to a POST. The expected format is the following:
{
"username": "username",
"course_key": "course-key",
"blocks": {
"block_key1": 0.0,
"block_key2": 1.0,
"block_key3": 1.0,
}
}
Return Value:
* tuple: (User, CourseKey, List of tuples (UsageKey, completion_float)
Raises:
django.core.exceptions.ValidationError:
If any aspect of validation fails a ValidationError is raised.
ObjectDoesNotExist:
If a database object cannot be found an ObjectDoesNotExist is raised. | [
"Performs",
"validation",
"on",
"the",
"batch",
"object",
"to",
"make",
"sure",
"it",
"is",
"in",
"the",
"proper",
"format",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/api/v1/views.py#L55-L107 |
14,370 | edx/completion | completion/api/v1/views.py | CompletionBatchView._validate_and_parse_course_key | def _validate_and_parse_course_key(self, course_key):
"""
Returns a validated parsed CourseKey deserialized from the given course_key.
"""
try:
return CourseKey.from_string(course_key)
except InvalidKeyError:
raise ValidationError(_("Invalid course key: {}").format(course_key)) | python | def _validate_and_parse_course_key(self, course_key):
try:
return CourseKey.from_string(course_key)
except InvalidKeyError:
raise ValidationError(_("Invalid course key: {}").format(course_key)) | [
"def",
"_validate_and_parse_course_key",
"(",
"self",
",",
"course_key",
")",
":",
"try",
":",
"return",
"CourseKey",
".",
"from_string",
"(",
"course_key",
")",
"except",
"InvalidKeyError",
":",
"raise",
"ValidationError",
"(",
"_",
"(",
"\"Invalid course key: {}\"... | Returns a validated parsed CourseKey deserialized from the given course_key. | [
"Returns",
"a",
"validated",
"parsed",
"CourseKey",
"deserialized",
"from",
"the",
"given",
"course_key",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/api/v1/views.py#L109-L116 |
14,371 | edx/completion | completion/api/v1/views.py | CompletionBatchView._validate_and_parse_block_key | def _validate_and_parse_block_key(self, block_key, course_key_obj):
"""
Returns a validated, parsed UsageKey deserialized from the given block_key.
"""
try:
block_key_obj = UsageKey.from_string(block_key)
except InvalidKeyError:
raise ValidationError(_("Invalid block key: {}").format(block_key))
if block_key_obj.run is None:
expected_matching_course_key = course_key_obj.replace(run=None)
else:
expected_matching_course_key = course_key_obj
if block_key_obj.course_key != expected_matching_course_key:
raise ValidationError(
_("Block with key: '{key}' is not in course {course}").format(key=block_key, course=course_key_obj)
)
return block_key_obj | python | def _validate_and_parse_block_key(self, block_key, course_key_obj):
try:
block_key_obj = UsageKey.from_string(block_key)
except InvalidKeyError:
raise ValidationError(_("Invalid block key: {}").format(block_key))
if block_key_obj.run is None:
expected_matching_course_key = course_key_obj.replace(run=None)
else:
expected_matching_course_key = course_key_obj
if block_key_obj.course_key != expected_matching_course_key:
raise ValidationError(
_("Block with key: '{key}' is not in course {course}").format(key=block_key, course=course_key_obj)
)
return block_key_obj | [
"def",
"_validate_and_parse_block_key",
"(",
"self",
",",
"block_key",
",",
"course_key_obj",
")",
":",
"try",
":",
"block_key_obj",
"=",
"UsageKey",
".",
"from_string",
"(",
"block_key",
")",
"except",
"InvalidKeyError",
":",
"raise",
"ValidationError",
"(",
"_",... | Returns a validated, parsed UsageKey deserialized from the given block_key. | [
"Returns",
"a",
"validated",
"parsed",
"UsageKey",
"deserialized",
"from",
"the",
"given",
"block_key",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/api/v1/views.py#L118-L137 |
14,372 | edx/completion | completion/api/v1/views.py | CompletionBatchView.post | def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
"""
Inserts a batch of completions.
REST Endpoint Format:
{
"username": "username",
"course_key": "course-key",
"blocks": {
"block_key1": 0.0,
"block_key2": 1.0,
"block_key3": 1.0,
}
}
**Returns**
A Response object, with an appropriate status code.
If successful, status code is 200.
{
"detail" : _("ok")
}
Otherwise, a 400 or 404 may be returned, and the "detail" content will explain the error.
"""
batch_object = request.data or {}
try:
user, course_key, blocks = self._validate_and_parse(batch_object)
BlockCompletion.objects.submit_batch_completion(user, course_key, blocks)
except ValidationError as exc:
return Response({
"detail": _(' ').join(text_type(msg) for msg in exc.messages),
}, status=status.HTTP_400_BAD_REQUEST)
except ValueError as exc:
return Response({
"detail": text_type(exc),
}, status=status.HTTP_400_BAD_REQUEST)
except ObjectDoesNotExist as exc:
return Response({
"detail": text_type(exc),
}, status=status.HTTP_404_NOT_FOUND)
except DatabaseError as exc:
return Response({
"detail": text_type(exc),
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response({"detail": _("ok")}, status=status.HTTP_200_OK) | python | def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
batch_object = request.data or {}
try:
user, course_key, blocks = self._validate_and_parse(batch_object)
BlockCompletion.objects.submit_batch_completion(user, course_key, blocks)
except ValidationError as exc:
return Response({
"detail": _(' ').join(text_type(msg) for msg in exc.messages),
}, status=status.HTTP_400_BAD_REQUEST)
except ValueError as exc:
return Response({
"detail": text_type(exc),
}, status=status.HTTP_400_BAD_REQUEST)
except ObjectDoesNotExist as exc:
return Response({
"detail": text_type(exc),
}, status=status.HTTP_404_NOT_FOUND)
except DatabaseError as exc:
return Response({
"detail": text_type(exc),
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response({"detail": _("ok")}, status=status.HTTP_200_OK) | [
"def",
"post",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=unused-argument",
"batch_object",
"=",
"request",
".",
"data",
"or",
"{",
"}",
"try",
":",
"user",
",",
"course_key",
",",
"blocks",
"=",
... | Inserts a batch of completions.
REST Endpoint Format:
{
"username": "username",
"course_key": "course-key",
"blocks": {
"block_key1": 0.0,
"block_key2": 1.0,
"block_key3": 1.0,
}
}
**Returns**
A Response object, with an appropriate status code.
If successful, status code is 200.
{
"detail" : _("ok")
}
Otherwise, a 400 or 404 may be returned, and the "detail" content will explain the error. | [
"Inserts",
"a",
"batch",
"of",
"completions",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/api/v1/views.py#L139-L187 |
14,373 | edx/completion | completion/services.py | CompletionService.get_completions | def get_completions(self, candidates):
"""
Given an iterable collection of block_keys in the course, returns a
mapping of the block_keys to the present completion values of their
associated blocks.
If a completion is not found for a given block in the current course,
0.0 is returned. The service does not attempt to verify that the block
exists within the course.
Parameters:
candidates: collection of BlockKeys within the current course.
Note: Usage keys may not have the course run filled in for old mongo courses.
This method checks for completion records against a set of BlockKey candidates with the course run
filled in from self._course_key.
Return value:
dict[BlockKey] -> float: Mapping blocks to their completion value.
"""
queryset = BlockCompletion.user_course_completion_queryset(self._user, self._course_key).filter(
block_key__in=candidates
)
completions = BlockCompletion.completion_by_block_key(queryset)
candidates_with_runs = [candidate.replace(course_key=self._course_key) for candidate in candidates]
for candidate in candidates_with_runs:
if candidate not in completions:
completions[candidate] = 0.0
return completions | python | def get_completions(self, candidates):
queryset = BlockCompletion.user_course_completion_queryset(self._user, self._course_key).filter(
block_key__in=candidates
)
completions = BlockCompletion.completion_by_block_key(queryset)
candidates_with_runs = [candidate.replace(course_key=self._course_key) for candidate in candidates]
for candidate in candidates_with_runs:
if candidate not in completions:
completions[candidate] = 0.0
return completions | [
"def",
"get_completions",
"(",
"self",
",",
"candidates",
")",
":",
"queryset",
"=",
"BlockCompletion",
".",
"user_course_completion_queryset",
"(",
"self",
".",
"_user",
",",
"self",
".",
"_course_key",
")",
".",
"filter",
"(",
"block_key__in",
"=",
"candidates... | Given an iterable collection of block_keys in the course, returns a
mapping of the block_keys to the present completion values of their
associated blocks.
If a completion is not found for a given block in the current course,
0.0 is returned. The service does not attempt to verify that the block
exists within the course.
Parameters:
candidates: collection of BlockKeys within the current course.
Note: Usage keys may not have the course run filled in for old mongo courses.
This method checks for completion records against a set of BlockKey candidates with the course run
filled in from self._course_key.
Return value:
dict[BlockKey] -> float: Mapping blocks to their completion value. | [
"Given",
"an",
"iterable",
"collection",
"of",
"block_keys",
"in",
"the",
"course",
"returns",
"a",
"mapping",
"of",
"the",
"block_keys",
"to",
"the",
"present",
"completion",
"values",
"of",
"their",
"associated",
"blocks",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/services.py#L41-L70 |
14,374 | edx/completion | completion/services.py | CompletionService.can_mark_block_complete_on_view | def can_mark_block_complete_on_view(self, block):
"""
Returns True if the xblock can be marked complete on view.
This is true of any non-customized, non-scorable, completable block.
"""
return (
XBlockCompletionMode.get_mode(block) == XBlockCompletionMode.COMPLETABLE
and not getattr(block, 'has_custom_completion', False)
and not getattr(block, 'has_score', False)
) | python | def can_mark_block_complete_on_view(self, block):
return (
XBlockCompletionMode.get_mode(block) == XBlockCompletionMode.COMPLETABLE
and not getattr(block, 'has_custom_completion', False)
and not getattr(block, 'has_score', False)
) | [
"def",
"can_mark_block_complete_on_view",
"(",
"self",
",",
"block",
")",
":",
"return",
"(",
"XBlockCompletionMode",
".",
"get_mode",
"(",
"block",
")",
"==",
"XBlockCompletionMode",
".",
"COMPLETABLE",
"and",
"not",
"getattr",
"(",
"block",
",",
"'has_custom_com... | Returns True if the xblock can be marked complete on view.
This is true of any non-customized, non-scorable, completable block. | [
"Returns",
"True",
"if",
"the",
"xblock",
"can",
"be",
"marked",
"complete",
"on",
"view",
".",
"This",
"is",
"true",
"of",
"any",
"non",
"-",
"customized",
"non",
"-",
"scorable",
"completable",
"block",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/services.py#L103-L112 |
14,375 | edx/completion | completion/services.py | CompletionService.blocks_to_mark_complete_on_view | def blocks_to_mark_complete_on_view(self, blocks):
"""
Returns a set of blocks which should be marked complete on view and haven't been yet.
"""
blocks = {block for block in blocks if self.can_mark_block_complete_on_view(block)}
completions = self.get_completions({block.location for block in blocks})
return {block for block in blocks if completions.get(block.location, 0) < 1.0} | python | def blocks_to_mark_complete_on_view(self, blocks):
blocks = {block for block in blocks if self.can_mark_block_complete_on_view(block)}
completions = self.get_completions({block.location for block in blocks})
return {block for block in blocks if completions.get(block.location, 0) < 1.0} | [
"def",
"blocks_to_mark_complete_on_view",
"(",
"self",
",",
"blocks",
")",
":",
"blocks",
"=",
"{",
"block",
"for",
"block",
"in",
"blocks",
"if",
"self",
".",
"can_mark_block_complete_on_view",
"(",
"block",
")",
"}",
"completions",
"=",
"self",
".",
"get_com... | Returns a set of blocks which should be marked complete on view and haven't been yet. | [
"Returns",
"a",
"set",
"of",
"blocks",
"which",
"should",
"be",
"marked",
"complete",
"on",
"view",
"and",
"haven",
"t",
"been",
"yet",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/services.py#L114-L120 |
14,376 | edx/completion | completion/services.py | CompletionService.submit_group_completion | def submit_group_completion(self, block_key, completion, users=None, user_ids=None):
"""
Submit a completion for a group of users.
Arguments:
block_key (opaque_key.edx.keys.UsageKey): The block to submit completions for.
completion (float): A value in the range [0.0, 1.0]
users ([django.contrib.auth.models.User]): An optional iterable of Users that completed the block.
user_ids ([int]): An optional iterable of ids of Users that completed the block.
Returns a list of (BlockCompletion, bool) where the boolean indicates
whether the given BlockCompletion was newly created.
"""
if users is None:
users = []
if user_ids is None:
user_ids = []
more_users = User.objects.filter(id__in=user_ids)
if len(more_users) < len(user_ids):
found_ids = {u.id for u in more_users}
not_found_ids = [pk for pk in user_ids if pk not in found_ids]
raise User.DoesNotExist("User not found with id(s): {}".format(not_found_ids))
users.extend(more_users)
submitted = []
for user in users:
submitted.append(BlockCompletion.objects.submit_completion(
user=user,
course_key=self._course_key,
block_key=block_key,
completion=completion
))
return submitted | python | def submit_group_completion(self, block_key, completion, users=None, user_ids=None):
if users is None:
users = []
if user_ids is None:
user_ids = []
more_users = User.objects.filter(id__in=user_ids)
if len(more_users) < len(user_ids):
found_ids = {u.id for u in more_users}
not_found_ids = [pk for pk in user_ids if pk not in found_ids]
raise User.DoesNotExist("User not found with id(s): {}".format(not_found_ids))
users.extend(more_users)
submitted = []
for user in users:
submitted.append(BlockCompletion.objects.submit_completion(
user=user,
course_key=self._course_key,
block_key=block_key,
completion=completion
))
return submitted | [
"def",
"submit_group_completion",
"(",
"self",
",",
"block_key",
",",
"completion",
",",
"users",
"=",
"None",
",",
"user_ids",
"=",
"None",
")",
":",
"if",
"users",
"is",
"None",
":",
"users",
"=",
"[",
"]",
"if",
"user_ids",
"is",
"None",
":",
"user_... | Submit a completion for a group of users.
Arguments:
block_key (opaque_key.edx.keys.UsageKey): The block to submit completions for.
completion (float): A value in the range [0.0, 1.0]
users ([django.contrib.auth.models.User]): An optional iterable of Users that completed the block.
user_ids ([int]): An optional iterable of ids of Users that completed the block.
Returns a list of (BlockCompletion, bool) where the boolean indicates
whether the given BlockCompletion was newly created. | [
"Submit",
"a",
"completion",
"for",
"a",
"group",
"of",
"users",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/services.py#L122-L155 |
14,377 | edx/completion | completion/services.py | CompletionService.submit_completion | def submit_completion(self, block_key, completion):
"""
Submit a completion for the service user and course.
Returns a (BlockCompletion, bool) where the boolean indicates
whether the given BlockCompletion was newly created.
"""
return BlockCompletion.objects.submit_completion(
user=self._user,
course_key=self._course_key,
block_key=block_key,
completion=completion
) | python | def submit_completion(self, block_key, completion):
return BlockCompletion.objects.submit_completion(
user=self._user,
course_key=self._course_key,
block_key=block_key,
completion=completion
) | [
"def",
"submit_completion",
"(",
"self",
",",
"block_key",
",",
"completion",
")",
":",
"return",
"BlockCompletion",
".",
"objects",
".",
"submit_completion",
"(",
"user",
"=",
"self",
".",
"_user",
",",
"course_key",
"=",
"self",
".",
"_course_key",
",",
"b... | Submit a completion for the service user and course.
Returns a (BlockCompletion, bool) where the boolean indicates
whether the given BlockCompletion was newly created. | [
"Submit",
"a",
"completion",
"for",
"the",
"service",
"user",
"and",
"course",
"."
] | 5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60 | https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/services.py#L157-L169 |
14,378 | Nike-Inc/cerberus-python-client | cerberus/util.py | throw_if_bad_response | def throw_if_bad_response(response):
"""Throw an exception if the Cerberus response is not successful."""
try:
response.raise_for_status()
except RequestException:
try:
msg = 'Response code: {}; response body:\n{}'.format(response.status_code, json.dumps(response.json(), indent=2))
raise CerberusClientException(msg)
except ValueError:
msg = 'Response code: {}; response body:\n{}'.format(response.status_code, response.text)
raise CerberusClientException(msg) | python | def throw_if_bad_response(response):
try:
response.raise_for_status()
except RequestException:
try:
msg = 'Response code: {}; response body:\n{}'.format(response.status_code, json.dumps(response.json(), indent=2))
raise CerberusClientException(msg)
except ValueError:
msg = 'Response code: {}; response body:\n{}'.format(response.status_code, response.text)
raise CerberusClientException(msg) | [
"def",
"throw_if_bad_response",
"(",
"response",
")",
":",
"try",
":",
"response",
".",
"raise_for_status",
"(",
")",
"except",
"RequestException",
":",
"try",
":",
"msg",
"=",
"'Response code: {}; response body:\\n{}'",
".",
"format",
"(",
"response",
".",
"statu... | Throw an exception if the Cerberus response is not successful. | [
"Throw",
"an",
"exception",
"if",
"the",
"Cerberus",
"response",
"is",
"not",
"successful",
"."
] | ef38356822e722fcb6a6ed4a1b38a5b493e753ae | https://github.com/Nike-Inc/cerberus-python-client/blob/ef38356822e722fcb6a6ed4a1b38a5b493e753ae/cerberus/util.py#L26-L36 |
14,379 | keenlabs/KeenClient-Python | keen/__init__.py | _initialize_client_from_environment | def _initialize_client_from_environment():
''' Initialize a KeenClient instance using environment variables. '''
global _client, project_id, write_key, read_key, master_key, base_url
if _client is None:
# check environment for project ID and keys
project_id = project_id or os.environ.get("KEEN_PROJECT_ID")
write_key = write_key or os.environ.get("KEEN_WRITE_KEY")
read_key = read_key or os.environ.get("KEEN_READ_KEY")
master_key = master_key or os.environ.get("KEEN_MASTER_KEY")
base_url = base_url or os.environ.get("KEEN_BASE_URL")
if not project_id:
raise InvalidEnvironmentError("Please set the KEEN_PROJECT_ID environment variable or set keen.project_id!")
_client = KeenClient(project_id,
write_key=write_key,
read_key=read_key,
master_key=master_key,
base_url=base_url) | python | def _initialize_client_from_environment():
''' Initialize a KeenClient instance using environment variables. '''
global _client, project_id, write_key, read_key, master_key, base_url
if _client is None:
# check environment for project ID and keys
project_id = project_id or os.environ.get("KEEN_PROJECT_ID")
write_key = write_key or os.environ.get("KEEN_WRITE_KEY")
read_key = read_key or os.environ.get("KEEN_READ_KEY")
master_key = master_key or os.environ.get("KEEN_MASTER_KEY")
base_url = base_url or os.environ.get("KEEN_BASE_URL")
if not project_id:
raise InvalidEnvironmentError("Please set the KEEN_PROJECT_ID environment variable or set keen.project_id!")
_client = KeenClient(project_id,
write_key=write_key,
read_key=read_key,
master_key=master_key,
base_url=base_url) | [
"def",
"_initialize_client_from_environment",
"(",
")",
":",
"global",
"_client",
",",
"project_id",
",",
"write_key",
",",
"read_key",
",",
"master_key",
",",
"base_url",
"if",
"_client",
"is",
"None",
":",
"# check environment for project ID and keys",
"project_id",
... | Initialize a KeenClient instance using environment variables. | [
"Initialize",
"a",
"KeenClient",
"instance",
"using",
"environment",
"variables",
"."
] | 266387c3376d1e000d117e17c45045ae3439d43f | https://github.com/keenlabs/KeenClient-Python/blob/266387c3376d1e000d117e17c45045ae3439d43f/keen/__init__.py#L14-L33 |
14,380 | keenlabs/KeenClient-Python | keen/__init__.py | count | def count(event_collection, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None,
max_age=None, limit=None):
""" Performs a count query
Counts the number of events that meet the given criteria.
:param event_collection: string, the name of the collection to query
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param filters: array of dict, contains the filters you'd like to apply to the data
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
:param group_by: string or array of strings, the name(s) of the properties you would
like to group you results by. example: "customer.id" or ["browser","operating_system"]
:param order_by: dictionary or list of dictionary objects containing the property_name(s)
to order by and the desired direction(s) of sorting.
Example: {"property_name":"result", "direction":keen.direction.DESCENDING}
May not be used without a group_by specified.
:param limit: positive integer limiting the displayed results of a query using order_by
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
willing to trade for increased query performance, in seconds
"""
_initialize_client_from_environment()
return _client.count(event_collection=event_collection, timeframe=timeframe, timezone=timezone,
interval=interval, filters=filters, group_by=group_by, order_by=order_by,
max_age=max_age, limit=limit) | python | def count(event_collection, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None,
max_age=None, limit=None):
_initialize_client_from_environment()
return _client.count(event_collection=event_collection, timeframe=timeframe, timezone=timezone,
interval=interval, filters=filters, group_by=group_by, order_by=order_by,
max_age=max_age, limit=limit) | [
"def",
"count",
"(",
"event_collection",
",",
"timeframe",
"=",
"None",
",",
"timezone",
"=",
"None",
",",
"interval",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"group_by",
"=",
"None",
",",
"order_by",
"=",
"None",
",",
"max_age",
"=",
"None",
",... | Performs a count query
Counts the number of events that meet the given criteria.
:param event_collection: string, the name of the collection to query
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param filters: array of dict, contains the filters you'd like to apply to the data
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
:param group_by: string or array of strings, the name(s) of the properties you would
like to group you results by. example: "customer.id" or ["browser","operating_system"]
:param order_by: dictionary or list of dictionary objects containing the property_name(s)
to order by and the desired direction(s) of sorting.
Example: {"property_name":"result", "direction":keen.direction.DESCENDING}
May not be used without a group_by specified.
:param limit: positive integer limiting the displayed results of a query using order_by
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
willing to trade for increased query performance, in seconds | [
"Performs",
"a",
"count",
"query"
] | 266387c3376d1e000d117e17c45045ae3439d43f | https://github.com/keenlabs/KeenClient-Python/blob/266387c3376d1e000d117e17c45045ae3439d43f/keen/__init__.py#L77-L106 |
14,381 | keenlabs/KeenClient-Python | keen/__init__.py | sum | def sum(event_collection, target_property, timeframe=None, timezone=None, interval=None, filters=None,
group_by=None, order_by=None, max_age=None, limit=None):
""" Performs a sum query
Adds the values of a target property for events that meet the given criteria.
:param event_collection: string, the name of the collection to query
:param target_property: string, the name of the event property you would like use
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param filters: array of dict, contains the filters you'd like to apply to the data
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
:param group_by: string or array of strings, the name(s) of the properties you would
like to group you results by. example: "customer.id" or ["browser","operating_system"]
:param order_by: dictionary or list of dictionary objects containing the property_name(s)
to order by and the desired direction(s) of sorting.
Example: {"property_name":"result", "direction":keen.direction.DESCENDING}
May not be used without a group_by specified.
:param limit: positive integer limiting the displayed results of a query using order_by
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
willing to trade for increased query performance, in seconds
"""
_initialize_client_from_environment()
return _client.sum(event_collection=event_collection, timeframe=timeframe, timezone=timezone,
interval=interval, filters=filters, group_by=group_by, order_by=order_by,
target_property=target_property, max_age=max_age, limit=limit) | python | def sum(event_collection, target_property, timeframe=None, timezone=None, interval=None, filters=None,
group_by=None, order_by=None, max_age=None, limit=None):
_initialize_client_from_environment()
return _client.sum(event_collection=event_collection, timeframe=timeframe, timezone=timezone,
interval=interval, filters=filters, group_by=group_by, order_by=order_by,
target_property=target_property, max_age=max_age, limit=limit) | [
"def",
"sum",
"(",
"event_collection",
",",
"target_property",
",",
"timeframe",
"=",
"None",
",",
"timezone",
"=",
"None",
",",
"interval",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"group_by",
"=",
"None",
",",
"order_by",
"=",
"None",
",",
"max_a... | Performs a sum query
Adds the values of a target property for events that meet the given criteria.
:param event_collection: string, the name of the collection to query
:param target_property: string, the name of the event property you would like use
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param filters: array of dict, contains the filters you'd like to apply to the data
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
:param group_by: string or array of strings, the name(s) of the properties you would
like to group you results by. example: "customer.id" or ["browser","operating_system"]
:param order_by: dictionary or list of dictionary objects containing the property_name(s)
to order by and the desired direction(s) of sorting.
Example: {"property_name":"result", "direction":keen.direction.DESCENDING}
May not be used without a group_by specified.
:param limit: positive integer limiting the displayed results of a query using order_by
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
willing to trade for increased query performance, in seconds | [
"Performs",
"a",
"sum",
"query"
] | 266387c3376d1e000d117e17c45045ae3439d43f | https://github.com/keenlabs/KeenClient-Python/blob/266387c3376d1e000d117e17c45045ae3439d43f/keen/__init__.py#L109-L139 |
14,382 | keenlabs/KeenClient-Python | keen/__init__.py | multi_analysis | def multi_analysis(event_collection, analyses, timeframe=None, interval=None, timezone=None,
filters=None, group_by=None, order_by=None, max_age=None, limit=None):
""" Performs a multi-analysis query
Returns a dictionary of analysis results.
:param event_collection: string, the name of the collection to query
:param analyses: dict, the types of analyses you'd like to run. example:
{"total money made":{"analysis_type":"sum","target_property":"purchase.price",
"average price":{"analysis_type":"average","target_property":"purchase.price"}
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param filters: array of dict, contains the filters you'd like to apply to the data
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
:param group_by: string or array of strings, the name(s) of the properties you would
like to group you results by. example: "customer.id" or ["browser","operating_system"]
:param order_by: dictionary or list of dictionary objects containing the property_name(s)
to order by and the desired direction(s) of sorting.
Example: {"property_name":"result", "direction":keen.direction.DESCENDING}
May not be used without a group_by specified.
:param limit: positive integer limiting the displayed results of a query using order_by
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
willing to trade for increased query performance, in seconds
"""
_initialize_client_from_environment()
return _client.multi_analysis(event_collection=event_collection, timeframe=timeframe,
interval=interval, timezone=timezone, filters=filters,
group_by=group_by, order_by=order_by, analyses=analyses,
max_age=max_age, limit=limit) | python | def multi_analysis(event_collection, analyses, timeframe=None, interval=None, timezone=None,
filters=None, group_by=None, order_by=None, max_age=None, limit=None):
_initialize_client_from_environment()
return _client.multi_analysis(event_collection=event_collection, timeframe=timeframe,
interval=interval, timezone=timezone, filters=filters,
group_by=group_by, order_by=order_by, analyses=analyses,
max_age=max_age, limit=limit) | [
"def",
"multi_analysis",
"(",
"event_collection",
",",
"analyses",
",",
"timeframe",
"=",
"None",
",",
"interval",
"=",
"None",
",",
"timezone",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"group_by",
"=",
"None",
",",
"order_by",
"=",
"None",
",",
"m... | Performs a multi-analysis query
Returns a dictionary of analysis results.
:param event_collection: string, the name of the collection to query
:param analyses: dict, the types of analyses you'd like to run. example:
{"total money made":{"analysis_type":"sum","target_property":"purchase.price",
"average price":{"analysis_type":"average","target_property":"purchase.price"}
:param timeframe: string or dict, the timeframe in which the events
happened example: "previous_7_days"
:param interval: string, the time interval used for measuring data over
time example: "daily"
:param timezone: int, the timezone you'd like to use for the timeframe
and interval in seconds
:param filters: array of dict, contains the filters you'd like to apply to the data
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
:param group_by: string or array of strings, the name(s) of the properties you would
like to group you results by. example: "customer.id" or ["browser","operating_system"]
:param order_by: dictionary or list of dictionary objects containing the property_name(s)
to order by and the desired direction(s) of sorting.
Example: {"property_name":"result", "direction":keen.direction.DESCENDING}
May not be used without a group_by specified.
:param limit: positive integer limiting the displayed results of a query using order_by
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
willing to trade for increased query performance, in seconds | [
"Performs",
"a",
"multi",
"-",
"analysis",
"query"
] | 266387c3376d1e000d117e17c45045ae3439d43f | https://github.com/keenlabs/KeenClient-Python/blob/266387c3376d1e000d117e17c45045ae3439d43f/keen/__init__.py#L429-L462 |
14,383 | quintusdias/glymur | glymur/lib/openjp2.py | check_error | def check_error(status):
"""Set a generic function as the restype attribute of all OpenJPEG
functions that return a BOOL_TYPE value. This way we do not have to check
for error status in each wrapping function and an exception will always be
appropriately raised.
"""
global ERROR_MSG_LST
if status != 1:
if len(ERROR_MSG_LST) > 0:
# clear out the existing error message so that we don't pick up
# a bad one next time around.
msg = '\n'.join(ERROR_MSG_LST)
ERROR_MSG_LST = []
raise OpenJPEGLibraryError(msg)
else:
raise OpenJPEGLibraryError("OpenJPEG function failure.") | python | def check_error(status):
global ERROR_MSG_LST
if status != 1:
if len(ERROR_MSG_LST) > 0:
# clear out the existing error message so that we don't pick up
# a bad one next time around.
msg = '\n'.join(ERROR_MSG_LST)
ERROR_MSG_LST = []
raise OpenJPEGLibraryError(msg)
else:
raise OpenJPEGLibraryError("OpenJPEG function failure.") | [
"def",
"check_error",
"(",
"status",
")",
":",
"global",
"ERROR_MSG_LST",
"if",
"status",
"!=",
"1",
":",
"if",
"len",
"(",
"ERROR_MSG_LST",
")",
">",
"0",
":",
"# clear out the existing error message so that we don't pick up",
"# a bad one next time around.",
"msg",
... | Set a generic function as the restype attribute of all OpenJPEG
functions that return a BOOL_TYPE value. This way we do not have to check
for error status in each wrapping function and an exception will always be
appropriately raised. | [
"Set",
"a",
"generic",
"function",
"as",
"the",
"restype",
"attribute",
"of",
"all",
"OpenJPEG",
"functions",
"that",
"return",
"a",
"BOOL_TYPE",
"value",
".",
"This",
"way",
"we",
"do",
"not",
"have",
"to",
"check",
"for",
"error",
"status",
"in",
"each",... | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L579-L594 |
14,384 | quintusdias/glymur | glymur/lib/openjp2.py | decode | def decode(codec, stream, image):
"""Reads an entire image.
Wraps the openjp2 library function opj_decode.
Parameters
----------
codec : CODEC_TYPE
The JPEG2000 codec
stream : STREAM_TYPE_P
The stream to decode.
image : ImageType
Output image structure.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_decode fails.
"""
OPENJP2.opj_decode.argtypes = [CODEC_TYPE, STREAM_TYPE_P,
ctypes.POINTER(ImageType)]
OPENJP2.opj_decode.restype = check_error
OPENJP2.opj_decode(codec, stream, image) | python | def decode(codec, stream, image):
OPENJP2.opj_decode.argtypes = [CODEC_TYPE, STREAM_TYPE_P,
ctypes.POINTER(ImageType)]
OPENJP2.opj_decode.restype = check_error
OPENJP2.opj_decode(codec, stream, image) | [
"def",
"decode",
"(",
"codec",
",",
"stream",
",",
"image",
")",
":",
"OPENJP2",
".",
"opj_decode",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"STREAM_TYPE_P",
",",
"ctypes",
".",
"POINTER",
"(",
"ImageType",
")",
"]",
"OPENJP2",
".",
"opj_decode",
".... | Reads an entire image.
Wraps the openjp2 library function opj_decode.
Parameters
----------
codec : CODEC_TYPE
The JPEG2000 codec
stream : STREAM_TYPE_P
The stream to decode.
image : ImageType
Output image structure.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_decode fails. | [
"Reads",
"an",
"entire",
"image",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L618-L641 |
14,385 | quintusdias/glymur | glymur/lib/openjp2.py | decode_tile_data | def decode_tile_data(codec, tidx, data, data_size, stream):
"""Reads tile data.
Wraps the openjp2 library function opj_decode_tile_data.
Parameters
----------
codec : CODEC_TYPE
The JPEG2000 codec
tile_index : int
The index of the tile being decoded
data : array
Holds a memory block into which data will be decoded.
data_size : int
The size of data in bytes
stream : STREAM_TYPE_P
The stream to decode.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_decode fails.
"""
OPENJP2.opj_decode_tile_data.argtypes = [CODEC_TYPE,
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_uint8),
ctypes.c_uint32,
STREAM_TYPE_P]
OPENJP2.opj_decode_tile_data.restype = check_error
datap = data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
OPENJP2.opj_decode_tile_data(codec,
ctypes.c_uint32(tidx),
datap,
ctypes.c_uint32(data_size),
stream) | python | def decode_tile_data(codec, tidx, data, data_size, stream):
OPENJP2.opj_decode_tile_data.argtypes = [CODEC_TYPE,
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_uint8),
ctypes.c_uint32,
STREAM_TYPE_P]
OPENJP2.opj_decode_tile_data.restype = check_error
datap = data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
OPENJP2.opj_decode_tile_data(codec,
ctypes.c_uint32(tidx),
datap,
ctypes.c_uint32(data_size),
stream) | [
"def",
"decode_tile_data",
"(",
"codec",
",",
"tidx",
",",
"data",
",",
"data_size",
",",
"stream",
")",
":",
"OPENJP2",
".",
"opj_decode_tile_data",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"ctypes",
".",
"c_uint32",
",",
"ctypes",
".",
"POINTER",
"(... | Reads tile data.
Wraps the openjp2 library function opj_decode_tile_data.
Parameters
----------
codec : CODEC_TYPE
The JPEG2000 codec
tile_index : int
The index of the tile being decoded
data : array
Holds a memory block into which data will be decoded.
data_size : int
The size of data in bytes
stream : STREAM_TYPE_P
The stream to decode.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_decode fails. | [
"Reads",
"tile",
"data",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L644-L679 |
14,386 | quintusdias/glymur | glymur/lib/openjp2.py | destroy_codec | def destroy_codec(codec):
"""Destroy a decompressor handle.
Wraps the openjp2 library function opj_destroy_codec.
Parameters
----------
codec : CODEC_TYPE
Decompressor handle to destroy.
"""
OPENJP2.opj_destroy_codec.argtypes = [CODEC_TYPE]
OPENJP2.opj_destroy_codec.restype = ctypes.c_void_p
OPENJP2.opj_destroy_codec(codec) | python | def destroy_codec(codec):
OPENJP2.opj_destroy_codec.argtypes = [CODEC_TYPE]
OPENJP2.opj_destroy_codec.restype = ctypes.c_void_p
OPENJP2.opj_destroy_codec(codec) | [
"def",
"destroy_codec",
"(",
"codec",
")",
":",
"OPENJP2",
".",
"opj_destroy_codec",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
"]",
"OPENJP2",
".",
"opj_destroy_codec",
".",
"restype",
"=",
"ctypes",
".",
"c_void_p",
"OPENJP2",
".",
"opj_destroy_codec",
"(",
"c... | Destroy a decompressor handle.
Wraps the openjp2 library function opj_destroy_codec.
Parameters
----------
codec : CODEC_TYPE
Decompressor handle to destroy. | [
"Destroy",
"a",
"decompressor",
"handle",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L703-L715 |
14,387 | quintusdias/glymur | glymur/lib/openjp2.py | encode | def encode(codec, stream):
"""Wraps openjp2 library function opj_encode.
Encode an image into a JPEG 2000 codestream.
Parameters
----------
codec : CODEC_TYPE
The jpeg2000 codec.
stream : STREAM_TYPE_P
The stream to which data is written.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_encode fails.
"""
OPENJP2.opj_encode.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
OPENJP2.opj_encode.restype = check_error
OPENJP2.opj_encode(codec, stream) | python | def encode(codec, stream):
OPENJP2.opj_encode.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
OPENJP2.opj_encode.restype = check_error
OPENJP2.opj_encode(codec, stream) | [
"def",
"encode",
"(",
"codec",
",",
"stream",
")",
":",
"OPENJP2",
".",
"opj_encode",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"STREAM_TYPE_P",
"]",
"OPENJP2",
".",
"opj_encode",
".",
"restype",
"=",
"check_error",
"OPENJP2",
".",
"opj_encode",
"(",
"... | Wraps openjp2 library function opj_encode.
Encode an image into a JPEG 2000 codestream.
Parameters
----------
codec : CODEC_TYPE
The jpeg2000 codec.
stream : STREAM_TYPE_P
The stream to which data is written.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_encode fails. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_encode",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L718-L738 |
14,388 | quintusdias/glymur | glymur/lib/openjp2.py | get_decoded_tile | def get_decoded_tile(codec, stream, imagep, tile_index):
"""get the decoded tile from the codec
Wraps the openjp2 library function opj_get_decoded_tile.
Parameters
----------
codec : CODEC_TYPE
The jpeg2000 codec.
stream : STREAM_TYPE_P
The input stream.
image : ImageType
Output image structure.
tiler_index : int
Index of the tile which will be decoded.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_get_decoded_tile fails.
"""
OPENJP2.opj_get_decoded_tile.argtypes = [CODEC_TYPE,
STREAM_TYPE_P,
ctypes.POINTER(ImageType),
ctypes.c_uint32]
OPENJP2.opj_get_decoded_tile.restype = check_error
OPENJP2.opj_get_decoded_tile(codec, stream, imagep, tile_index) | python | def get_decoded_tile(codec, stream, imagep, tile_index):
OPENJP2.opj_get_decoded_tile.argtypes = [CODEC_TYPE,
STREAM_TYPE_P,
ctypes.POINTER(ImageType),
ctypes.c_uint32]
OPENJP2.opj_get_decoded_tile.restype = check_error
OPENJP2.opj_get_decoded_tile(codec, stream, imagep, tile_index) | [
"def",
"get_decoded_tile",
"(",
"codec",
",",
"stream",
",",
"imagep",
",",
"tile_index",
")",
":",
"OPENJP2",
".",
"opj_get_decoded_tile",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"STREAM_TYPE_P",
",",
"ctypes",
".",
"POINTER",
"(",
"ImageType",
")",
"... | get the decoded tile from the codec
Wraps the openjp2 library function opj_get_decoded_tile.
Parameters
----------
codec : CODEC_TYPE
The jpeg2000 codec.
stream : STREAM_TYPE_P
The input stream.
image : ImageType
Output image structure.
tiler_index : int
Index of the tile which will be decoded.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_get_decoded_tile fails. | [
"get",
"the",
"decoded",
"tile",
"from",
"the",
"codec"
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L741-L768 |
14,389 | quintusdias/glymur | glymur/lib/openjp2.py | end_compress | def end_compress(codec, stream):
"""End of compressing the current image.
Wraps the openjp2 library function opj_end_compress.
Parameters
----------
codec : CODEC_TYPE
Compressor handle.
stream : STREAM_TYPE_P
Output stream buffer.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_end_compress fails.
"""
OPENJP2.opj_end_compress.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
OPENJP2.opj_end_compress.restype = check_error
OPENJP2.opj_end_compress(codec, stream) | python | def end_compress(codec, stream):
OPENJP2.opj_end_compress.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
OPENJP2.opj_end_compress.restype = check_error
OPENJP2.opj_end_compress(codec, stream) | [
"def",
"end_compress",
"(",
"codec",
",",
"stream",
")",
":",
"OPENJP2",
".",
"opj_end_compress",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"STREAM_TYPE_P",
"]",
"OPENJP2",
".",
"opj_end_compress",
".",
"restype",
"=",
"check_error",
"OPENJP2",
".",
"opj_e... | End of compressing the current image.
Wraps the openjp2 library function opj_end_compress.
Parameters
----------
codec : CODEC_TYPE
Compressor handle.
stream : STREAM_TYPE_P
Output stream buffer.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_end_compress fails. | [
"End",
"of",
"compressing",
"the",
"current",
"image",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L771-L790 |
14,390 | quintusdias/glymur | glymur/lib/openjp2.py | end_decompress | def end_decompress(codec, stream):
"""End of decompressing the current image.
Wraps the openjp2 library function opj_end_decompress.
Parameters
----------
codec : CODEC_TYPE
Compressor handle.
stream : STREAM_TYPE_P
Output stream buffer.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_end_decompress fails.
"""
OPENJP2.opj_end_decompress.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
OPENJP2.opj_end_decompress.restype = check_error
OPENJP2.opj_end_decompress(codec, stream) | python | def end_decompress(codec, stream):
OPENJP2.opj_end_decompress.argtypes = [CODEC_TYPE, STREAM_TYPE_P]
OPENJP2.opj_end_decompress.restype = check_error
OPENJP2.opj_end_decompress(codec, stream) | [
"def",
"end_decompress",
"(",
"codec",
",",
"stream",
")",
":",
"OPENJP2",
".",
"opj_end_decompress",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"STREAM_TYPE_P",
"]",
"OPENJP2",
".",
"opj_end_decompress",
".",
"restype",
"=",
"check_error",
"OPENJP2",
".",
... | End of decompressing the current image.
Wraps the openjp2 library function opj_end_decompress.
Parameters
----------
codec : CODEC_TYPE
Compressor handle.
stream : STREAM_TYPE_P
Output stream buffer.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_end_decompress fails. | [
"End",
"of",
"decompressing",
"the",
"current",
"image",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L793-L812 |
14,391 | quintusdias/glymur | glymur/lib/openjp2.py | image_destroy | def image_destroy(image):
"""Deallocate any resources associated with an image.
Wraps the openjp2 library function opj_image_destroy.
Parameters
----------
image : ImageType pointer
Image resource to be disposed.
"""
OPENJP2.opj_image_destroy.argtypes = [ctypes.POINTER(ImageType)]
OPENJP2.opj_image_destroy.restype = ctypes.c_void_p
OPENJP2.opj_image_destroy(image) | python | def image_destroy(image):
OPENJP2.opj_image_destroy.argtypes = [ctypes.POINTER(ImageType)]
OPENJP2.opj_image_destroy.restype = ctypes.c_void_p
OPENJP2.opj_image_destroy(image) | [
"def",
"image_destroy",
"(",
"image",
")",
":",
"OPENJP2",
".",
"opj_image_destroy",
".",
"argtypes",
"=",
"[",
"ctypes",
".",
"POINTER",
"(",
"ImageType",
")",
"]",
"OPENJP2",
".",
"opj_image_destroy",
".",
"restype",
"=",
"ctypes",
".",
"c_void_p",
"OPENJP... | Deallocate any resources associated with an image.
Wraps the openjp2 library function opj_image_destroy.
Parameters
----------
image : ImageType pointer
Image resource to be disposed. | [
"Deallocate",
"any",
"resources",
"associated",
"with",
"an",
"image",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L815-L828 |
14,392 | quintusdias/glymur | glymur/lib/openjp2.py | read_header | def read_header(stream, codec):
"""Decodes an image header.
Wraps the openjp2 library function opj_read_header.
Parameters
----------
stream: STREAM_TYPE_P
The JPEG2000 stream.
codec: codec_t
The JPEG2000 codec to read.
Returns
-------
imagep : reference to ImageType instance
The image structure initialized with image characteristics.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_read_header fails.
"""
ARGTYPES = [STREAM_TYPE_P, CODEC_TYPE,
ctypes.POINTER(ctypes.POINTER(ImageType))]
OPENJP2.opj_read_header.argtypes = ARGTYPES
OPENJP2.opj_read_header.restype = check_error
imagep = ctypes.POINTER(ImageType)()
OPENJP2.opj_read_header(stream, codec, ctypes.byref(imagep))
return imagep | python | def read_header(stream, codec):
ARGTYPES = [STREAM_TYPE_P, CODEC_TYPE,
ctypes.POINTER(ctypes.POINTER(ImageType))]
OPENJP2.opj_read_header.argtypes = ARGTYPES
OPENJP2.opj_read_header.restype = check_error
imagep = ctypes.POINTER(ImageType)()
OPENJP2.opj_read_header(stream, codec, ctypes.byref(imagep))
return imagep | [
"def",
"read_header",
"(",
"stream",
",",
"codec",
")",
":",
"ARGTYPES",
"=",
"[",
"STREAM_TYPE_P",
",",
"CODEC_TYPE",
",",
"ctypes",
".",
"POINTER",
"(",
"ctypes",
".",
"POINTER",
"(",
"ImageType",
")",
")",
"]",
"OPENJP2",
".",
"opj_read_header",
".",
... | Decodes an image header.
Wraps the openjp2 library function opj_read_header.
Parameters
----------
stream: STREAM_TYPE_P
The JPEG2000 stream.
codec: codec_t
The JPEG2000 codec to read.
Returns
-------
imagep : reference to ImageType instance
The image structure initialized with image characteristics.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_read_header fails. | [
"Decodes",
"an",
"image",
"header",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L888-L917 |
14,393 | quintusdias/glymur | glymur/lib/openjp2.py | read_tile_header | def read_tile_header(codec, stream):
"""Reads a tile header.
Wraps the openjp2 library function opj_read_tile_header.
Parameters
----------
codec : codec_t
The JPEG2000 codec to read.
stream : STREAM_TYPE_P
The JPEG2000 stream.
Returns
-------
tile_index : int
index of the tile being decoded
data_size : int
number of bytes for the decoded area
x0, y0 : int
upper left-most coordinate of tile
x1, y1 : int
lower right-most coordinate of tile
ncomps : int
number of components in the tile
go_on : bool
indicates that decoding should continue
Raises
------
RuntimeError
If the OpenJPEG library routine opj_read_tile_header fails.
"""
ARGTYPES = [CODEC_TYPE,
STREAM_TYPE_P,
ctypes.POINTER(ctypes.c_uint32),
ctypes.POINTER(ctypes.c_uint32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_uint32),
ctypes.POINTER(BOOL_TYPE)]
OPENJP2.opj_read_tile_header.argtypes = ARGTYPES
OPENJP2.opj_read_tile_header.restype = check_error
tile_index = ctypes.c_uint32()
data_size = ctypes.c_uint32()
col0 = ctypes.c_int32()
row0 = ctypes.c_int32()
col1 = ctypes.c_int32()
row1 = ctypes.c_int32()
ncomps = ctypes.c_uint32()
go_on = BOOL_TYPE()
OPENJP2.opj_read_tile_header(codec,
stream,
ctypes.byref(tile_index),
ctypes.byref(data_size),
ctypes.byref(col0),
ctypes.byref(row0),
ctypes.byref(col1),
ctypes.byref(row1),
ctypes.byref(ncomps),
ctypes.byref(go_on))
go_on = bool(go_on.value)
return (tile_index.value,
data_size.value,
col0.value,
row0.value,
col1.value,
row1.value,
ncomps.value,
go_on) | python | def read_tile_header(codec, stream):
ARGTYPES = [CODEC_TYPE,
STREAM_TYPE_P,
ctypes.POINTER(ctypes.c_uint32),
ctypes.POINTER(ctypes.c_uint32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_int32),
ctypes.POINTER(ctypes.c_uint32),
ctypes.POINTER(BOOL_TYPE)]
OPENJP2.opj_read_tile_header.argtypes = ARGTYPES
OPENJP2.opj_read_tile_header.restype = check_error
tile_index = ctypes.c_uint32()
data_size = ctypes.c_uint32()
col0 = ctypes.c_int32()
row0 = ctypes.c_int32()
col1 = ctypes.c_int32()
row1 = ctypes.c_int32()
ncomps = ctypes.c_uint32()
go_on = BOOL_TYPE()
OPENJP2.opj_read_tile_header(codec,
stream,
ctypes.byref(tile_index),
ctypes.byref(data_size),
ctypes.byref(col0),
ctypes.byref(row0),
ctypes.byref(col1),
ctypes.byref(row1),
ctypes.byref(ncomps),
ctypes.byref(go_on))
go_on = bool(go_on.value)
return (tile_index.value,
data_size.value,
col0.value,
row0.value,
col1.value,
row1.value,
ncomps.value,
go_on) | [
"def",
"read_tile_header",
"(",
"codec",
",",
"stream",
")",
":",
"ARGTYPES",
"=",
"[",
"CODEC_TYPE",
",",
"STREAM_TYPE_P",
",",
"ctypes",
".",
"POINTER",
"(",
"ctypes",
".",
"c_uint32",
")",
",",
"ctypes",
".",
"POINTER",
"(",
"ctypes",
".",
"c_uint32",
... | Reads a tile header.
Wraps the openjp2 library function opj_read_tile_header.
Parameters
----------
codec : codec_t
The JPEG2000 codec to read.
stream : STREAM_TYPE_P
The JPEG2000 stream.
Returns
-------
tile_index : int
index of the tile being decoded
data_size : int
number of bytes for the decoded area
x0, y0 : int
upper left-most coordinate of tile
x1, y1 : int
lower right-most coordinate of tile
ncomps : int
number of components in the tile
go_on : bool
indicates that decoding should continue
Raises
------
RuntimeError
If the OpenJPEG library routine opj_read_tile_header fails. | [
"Reads",
"a",
"tile",
"header",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L920-L991 |
14,394 | quintusdias/glymur | glymur/lib/openjp2.py | set_decode_area | def set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0):
"""Wraps openjp2 library function opj_set_decode area.
Sets the given area to be decoded. This function should be called right
after read_header and before any tile header reading.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_decompress function.
image : ImageType pointer
The decoded image previously set by read_header.
start_x, start_y : optional, int
The left and upper position of the rectangle to decode.
end_x, end_y : optional, int
The right and lower position of the rectangle to decode.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_decode_area fails.
"""
OPENJP2.opj_set_decode_area.argtypes = [CODEC_TYPE,
ctypes.POINTER(ImageType),
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32]
OPENJP2.opj_set_decode_area.restype = check_error
OPENJP2.opj_set_decode_area(codec, image,
ctypes.c_int32(start_x),
ctypes.c_int32(start_y),
ctypes.c_int32(end_x),
ctypes.c_int32(end_y)) | python | def set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0):
OPENJP2.opj_set_decode_area.argtypes = [CODEC_TYPE,
ctypes.POINTER(ImageType),
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32]
OPENJP2.opj_set_decode_area.restype = check_error
OPENJP2.opj_set_decode_area(codec, image,
ctypes.c_int32(start_x),
ctypes.c_int32(start_y),
ctypes.c_int32(end_x),
ctypes.c_int32(end_y)) | [
"def",
"set_decode_area",
"(",
"codec",
",",
"image",
",",
"start_x",
"=",
"0",
",",
"start_y",
"=",
"0",
",",
"end_x",
"=",
"0",
",",
"end_y",
"=",
"0",
")",
":",
"OPENJP2",
".",
"opj_set_decode_area",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"... | Wraps openjp2 library function opj_set_decode area.
Sets the given area to be decoded. This function should be called right
after read_header and before any tile header reading.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_decompress function.
image : ImageType pointer
The decoded image previously set by read_header.
start_x, start_y : optional, int
The left and upper position of the rectangle to decode.
end_x, end_y : optional, int
The right and lower position of the rectangle to decode.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_decode_area fails. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_set_decode",
"area",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L994-L1028 |
14,395 | quintusdias/glymur | glymur/lib/openjp2.py | set_default_decoder_parameters | def set_default_decoder_parameters():
"""Wraps openjp2 library function opj_set_default_decoder_parameters.
Sets decoding parameters to default values.
Returns
-------
dparam : DecompressionParametersType
Decompression parameters.
"""
ARGTYPES = [ctypes.POINTER(DecompressionParametersType)]
OPENJP2.opj_set_default_decoder_parameters.argtypes = ARGTYPES
OPENJP2.opj_set_default_decoder_parameters.restype = ctypes.c_void_p
dparams = DecompressionParametersType()
OPENJP2.opj_set_default_decoder_parameters(ctypes.byref(dparams))
return dparams | python | def set_default_decoder_parameters():
ARGTYPES = [ctypes.POINTER(DecompressionParametersType)]
OPENJP2.opj_set_default_decoder_parameters.argtypes = ARGTYPES
OPENJP2.opj_set_default_decoder_parameters.restype = ctypes.c_void_p
dparams = DecompressionParametersType()
OPENJP2.opj_set_default_decoder_parameters(ctypes.byref(dparams))
return dparams | [
"def",
"set_default_decoder_parameters",
"(",
")",
":",
"ARGTYPES",
"=",
"[",
"ctypes",
".",
"POINTER",
"(",
"DecompressionParametersType",
")",
"]",
"OPENJP2",
".",
"opj_set_default_decoder_parameters",
".",
"argtypes",
"=",
"ARGTYPES",
"OPENJP2",
".",
"opj_set_defau... | Wraps openjp2 library function opj_set_default_decoder_parameters.
Sets decoding parameters to default values.
Returns
-------
dparam : DecompressionParametersType
Decompression parameters. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_set_default_decoder_parameters",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L1031-L1047 |
14,396 | quintusdias/glymur | glymur/lib/openjp2.py | set_default_encoder_parameters | def set_default_encoder_parameters():
"""Wraps openjp2 library function opj_set_default_encoder_parameters.
Sets encoding parameters to default values. That means
lossless
1 tile
size of precinct : 2^15 x 2^15 (means 1 precinct)
size of code-block : 64 x 64
number of resolutions: 6
no SOP marker in the codestream
no EPH marker in the codestream
no sub-sampling in x or y direction
no mode switch activated
progression order: LRCP
no index file
no ROI upshifted
no offset of the origin of the image
no offset of the origin of the tiles
reversible DWT 5-3
The signature for this function differs from its C library counterpart, as
the the C function pass-by-reference parameter becomes the Python return
value.
Returns
-------
cparameters : CompressionParametersType
Compression parameters.
"""
ARGTYPES = [ctypes.POINTER(CompressionParametersType)]
OPENJP2.opj_set_default_encoder_parameters.argtypes = ARGTYPES
OPENJP2.opj_set_default_encoder_parameters.restype = ctypes.c_void_p
cparams = CompressionParametersType()
OPENJP2.opj_set_default_encoder_parameters(ctypes.byref(cparams))
return cparams | python | def set_default_encoder_parameters():
ARGTYPES = [ctypes.POINTER(CompressionParametersType)]
OPENJP2.opj_set_default_encoder_parameters.argtypes = ARGTYPES
OPENJP2.opj_set_default_encoder_parameters.restype = ctypes.c_void_p
cparams = CompressionParametersType()
OPENJP2.opj_set_default_encoder_parameters(ctypes.byref(cparams))
return cparams | [
"def",
"set_default_encoder_parameters",
"(",
")",
":",
"ARGTYPES",
"=",
"[",
"ctypes",
".",
"POINTER",
"(",
"CompressionParametersType",
")",
"]",
"OPENJP2",
".",
"opj_set_default_encoder_parameters",
".",
"argtypes",
"=",
"ARGTYPES",
"OPENJP2",
".",
"opj_set_default... | Wraps openjp2 library function opj_set_default_encoder_parameters.
Sets encoding parameters to default values. That means
lossless
1 tile
size of precinct : 2^15 x 2^15 (means 1 precinct)
size of code-block : 64 x 64
number of resolutions: 6
no SOP marker in the codestream
no EPH marker in the codestream
no sub-sampling in x or y direction
no mode switch activated
progression order: LRCP
no index file
no ROI upshifted
no offset of the origin of the image
no offset of the origin of the tiles
reversible DWT 5-3
The signature for this function differs from its C library counterpart, as
the the C function pass-by-reference parameter becomes the Python return
value.
Returns
-------
cparameters : CompressionParametersType
Compression parameters. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_set_default_encoder_parameters",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L1050-L1086 |
14,397 | quintusdias/glymur | glymur/lib/openjp2.py | set_error_handler | def set_error_handler(codec, handler, data=None):
"""Wraps openjp2 library function opj_set_error_handler.
Set the error handler use by openjpeg.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_compress function.
handler : python function
The callback function to be used.
user_data : anything
User/client data.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_error_handler fails.
"""
OPENJP2.opj_set_error_handler.argtypes = [CODEC_TYPE,
ctypes.c_void_p,
ctypes.c_void_p]
OPENJP2.opj_set_error_handler.restype = check_error
OPENJP2.opj_set_error_handler(codec, handler, data) | python | def set_error_handler(codec, handler, data=None):
OPENJP2.opj_set_error_handler.argtypes = [CODEC_TYPE,
ctypes.c_void_p,
ctypes.c_void_p]
OPENJP2.opj_set_error_handler.restype = check_error
OPENJP2.opj_set_error_handler(codec, handler, data) | [
"def",
"set_error_handler",
"(",
"codec",
",",
"handler",
",",
"data",
"=",
"None",
")",
":",
"OPENJP2",
".",
"opj_set_error_handler",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"ctypes",
".",
"c_void_p",
",",
"ctypes",
".",
"c_void_p",
"]",
"OPENJP2",
... | Wraps openjp2 library function opj_set_error_handler.
Set the error handler use by openjpeg.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_compress function.
handler : python function
The callback function to be used.
user_data : anything
User/client data.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_error_handler fails. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_set_error_handler",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L1089-L1112 |
14,398 | quintusdias/glymur | glymur/lib/openjp2.py | set_info_handler | def set_info_handler(codec, handler, data=None):
"""Wraps openjp2 library function opj_set_info_handler.
Set the info handler use by openjpeg.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_compress function.
handler : python function
The callback function to be used.
user_data : anything
User/client data.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_info_handler fails.
"""
OPENJP2.opj_set_info_handler.argtypes = [CODEC_TYPE,
ctypes.c_void_p,
ctypes.c_void_p]
OPENJP2.opj_set_info_handler.restype = check_error
OPENJP2.opj_set_info_handler(codec, handler, data) | python | def set_info_handler(codec, handler, data=None):
OPENJP2.opj_set_info_handler.argtypes = [CODEC_TYPE,
ctypes.c_void_p,
ctypes.c_void_p]
OPENJP2.opj_set_info_handler.restype = check_error
OPENJP2.opj_set_info_handler(codec, handler, data) | [
"def",
"set_info_handler",
"(",
"codec",
",",
"handler",
",",
"data",
"=",
"None",
")",
":",
"OPENJP2",
".",
"opj_set_info_handler",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"ctypes",
".",
"c_void_p",
",",
"ctypes",
".",
"c_void_p",
"]",
"OPENJP2",
".... | Wraps openjp2 library function opj_set_info_handler.
Set the info handler use by openjpeg.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_compress function.
handler : python function
The callback function to be used.
user_data : anything
User/client data.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_info_handler fails. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_set_info_handler",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L1115-L1138 |
14,399 | quintusdias/glymur | glymur/lib/openjp2.py | set_warning_handler | def set_warning_handler(codec, handler, data=None):
"""Wraps openjp2 library function opj_set_warning_handler.
Set the warning handler use by openjpeg.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_compress function.
handler : python function
The callback function to be used.
user_data : anything
User/client data.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_warning_handler fails.
"""
OPENJP2.opj_set_warning_handler.argtypes = [CODEC_TYPE,
ctypes.c_void_p,
ctypes.c_void_p]
OPENJP2.opj_set_warning_handler.restype = check_error
OPENJP2.opj_set_warning_handler(codec, handler, data) | python | def set_warning_handler(codec, handler, data=None):
OPENJP2.opj_set_warning_handler.argtypes = [CODEC_TYPE,
ctypes.c_void_p,
ctypes.c_void_p]
OPENJP2.opj_set_warning_handler.restype = check_error
OPENJP2.opj_set_warning_handler(codec, handler, data) | [
"def",
"set_warning_handler",
"(",
"codec",
",",
"handler",
",",
"data",
"=",
"None",
")",
":",
"OPENJP2",
".",
"opj_set_warning_handler",
".",
"argtypes",
"=",
"[",
"CODEC_TYPE",
",",
"ctypes",
".",
"c_void_p",
",",
"ctypes",
".",
"c_void_p",
"]",
"OPENJP2"... | Wraps openjp2 library function opj_set_warning_handler.
Set the warning handler use by openjpeg.
Parameters
----------
codec : CODEC_TYPE
Codec initialized by create_compress function.
handler : python function
The callback function to be used.
user_data : anything
User/client data.
Raises
------
RuntimeError
If the OpenJPEG library routine opj_set_warning_handler fails. | [
"Wraps",
"openjp2",
"library",
"function",
"opj_set_warning_handler",
"."
] | 8b8fb091130fff00f1028dc82219e69e3f9baf6d | https://github.com/quintusdias/glymur/blob/8b8fb091130fff00f1028dc82219e69e3f9baf6d/glymur/lib/openjp2.py#L1141-L1165 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.