output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def envelope(component, **kwargs):
"""
Create parameters for an envelope (usually will be attached to two stars solRad
that they can share a common-envelope)
Generally, this will be used as an input to the kind argument in
:meth:`phoebe.frontend.bundle.Bundle.add_component`
:parameter **kw... | Implement a Python 3 function for
creating a parameter set that can be used to create a common envelope for the given component. | As a python code expert, you are capable of creating scripts from specifications. |
Create pixelgrid and array of axis values for the current set of parameters and data. | Explain what the following Python 3 code does
def create_pixeltypegrid(grid_pars, grid_data):
uniques = [np.unique(column, return_inverse=True) for column in grid_pars]
#[0] are the unique values, [1] the indices for these to recreate the original array
# we need to copy the values of the unique axes ... | You are a Python code analyst, evaluating scripts for potential improvements. |
def interpolate(p, axis_values, pixelgrid, order=1, mode='constant', cval=0.0):
"""
Interpolates in a grid prepared by create_pixeltypegrid().
p is an array of parameter arrays
@param p: Npar x Ninterpolate array
@type p: array
@return: Ndata x Ninterpolate array
@rtype: array
... | Write a Python 3 script to
interpolate in a grid prepared by create_pixeltypegrid. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Interpolates in a grid prepared by create_pixeltypegrid. | Here you have a function in Python 3, explain what it does
def cinterpolate(p, axis_values, pixelgrid):
res = libphoebe.interp(p, axis_values, pixelgrid)
return res | You are a Python code architect, reviewing and designing scalable and efficient code |
shortcut to utils. get_basic_logger | Given the following Python 3 function, write the documentation
def logger(*args, **kwargs):
if mpi.within_mpirun and mpi.myrank == 0:
# tell the workers to invoke the same logger
mpi.comm.bcast({'worker_command': 'logger', 'args': args, 'kwargs': kwargs}, root=0)
return _utils.get_basic_logger(... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get_basic_logger(clevel='WARNING',flevel='DEBUG',
style="default",filename=None,filemode='w'):
"""
Return a basic logger via a log file and/or terminal.
Example 1: log only to the console, accepting levels "INFO" and above
>>> logger = utils.get_basic_logger()
Example 2: ... | Implement a function in Python 3 to
return a basic logger for the given level and file. | As a Python code translator, you convert algorithms and pseudocode into Python. |
parse_json returns a dict of key - value pairs | Can you tell what is the following Python 3 function doing
def parse_json(pairs):
new_pairs = []
for key, value in pairs:
if isinstance(value, unicode):
value = value.encode('utf-8')
if isinstance(key, unicode):
key = key.encode('utf-8')
new_pairs.append((key, val... | You are a Python code architect, reviewing and designing scalable and efficient code |
set the direction of the log entry | Here you have a function in Python 3, explain what it does
def direction(self, direction):
if not isinstance(direction, str):
raise TypeError("direction must be of type str")
accepted_values = ['i', 'x', 'y', 'z', 's', 'c']
if direction not in accepted_values:
raise Valu... | As a Python code translator, you convert algorithms and pseudocode into Python. |
interpolate the value at a give value of i | Can you generate a brief explanation for the following Python 3 code
def interpolate_at_i(self, i, unit=None):
if isinstance(self.call.i._value, float):
if self.call.i._value==i:
return self._to_unit(self._value, unit)
else:
return None
# we can't... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Internal method to sort the array of the items in the log entry by indep. | Can you generate a brief explanation for the following Python 3 code
def _sort_by_indep(self, func='get_value', i=None, iunit=None, unit=None,
uncover=None, trail=None, linebreak=None,
sort_by_indep=None):
"""
must be called before (or within) _do_linebreak... | You are a Python code analyst, evaluating scripts for potential improvements. |
get the value of a given attribute of a given i | Explain what the following Python 3 code does
def get_value(self, i=None, unit=None,
uncover=None, trail=None,
linebreak=None, sort_by_indep=None,
attr='_value'):
"""
access the value for a given value of i (independent-variable) depending
on... | As a Python code analyst, you investigate and solve complex coding mysteries |
set the value of the attribute | Here you have a function in Python 3, explain what it does
def _set_value(self, value):
if value is None:
self._value = value
return
# handle casting to acceptable types
if isinstance(value, list) or isinstance(value, tuple):
value = np.array(value)
i... | You are a Python code generator, capable of creating scripts from specifications. |
get the error for a given value of i | Given the following Python 3 function, write the documentation
def get_error(self, i=None, unit=None,
uncover=None, trail=None,
linebreak=None, sort_by_indep=None):
"""
access the error for a given value of i (independent-variable) depending
on which effects (... | As a Python code analyst, you investigate and solve complex coding mysteries |
def error(self, error):
"""
set the error
"""
# TODO: check length with value?
# TODO: type checks (similar to value)
if self.direction not in ['x', 'y', 'z'] and error is not None:
raise ValueError("error only accepted for x, y, z dimensions")
if isi... | Can you implement a function in Python 3 that
sets the error of the current object | You are a Python code generator, capable of creating scripts from specifications. |
def label(self, label):
"""
set the label
"""
if self.direction in ['i'] and label is not None:
raise ValueError("label not accepted for indep dimension")
if label is None:
self._label = label
return
if not isinstance(label, str):
... | Write a Python 3 script for
setting the label of the object | You are a Python code analyst, evaluating scripts for potential improvements. |
def value(self, value):
"""
set the value
"""
# for the indep direction we also allow a string which points to one
# of the other available dimensions
# TODO: support c, fc, ec?
if isinstance(value, common.basestring) and value in ['x', 'y', 'z']:
# we... | Write a Python 3 script to
set the value of the value | You are a Python code architect, reviewing and designing scalable and efficient code |
Convert a rotation frequency to an omega value. | How would you explain what the following Python 3 function does
def rotfreq_to_omega(rotfreq, scale=c.R_sun.si.value, solar_units=False):
if solar_units:
omega = rotfreq / (2*np.pi) / np.sqrt(c.GM_sun.to(u.solRad**3/u.d**2).value/scale**3)
else:
# then SI units
omega = rotfreq / (2*np.pi... | As a Python code composer, you craft elegant and concise scripts. |
Ensure that the passed item is a tuple. If it is not then return the item itself. | Can you generate the documentation for the following Python 3 function
def _ensure_tuple(item):
if isinstance(item, tuple):
return item
elif isinstance(item, list):
return tuple(item)
elif isinstance(item, np.ndarray):
return tuple(item.tolist())
else:
raise NotImplemente... | You are a Python code generator, capable of creating scripts from specifications. |
def dynamics_from_bundle(b, times, compute=None, return_roche_euler=False, use_kepcart=False, **kwargs):
"""
Parse parameters in the bundle and call :func:`dynamics`.
See :func:`dynamics` for more detailed information.
NOTE: you must either provide compute (the label) OR all relevant options
as kw... | Can you write a function in Python 3 where it
parses parameters in the bundle and call :func:`dynamics`. See :func:`dynamics` for more detailed information. NOTE: you must either provide compute (the label) OR all relevant options as kwargs (ltte, stepsize, gr, integrator) Args: b: (Bundle) the bundle with a set hierar... | You are a Python code generator, capable of creating scripts from specifications. |
Parse parameters in the bundle and call dynamics function. | Given the following Python 3 function, write the documentation
def dynamics_from_bundle_bs(b, times, compute=None, return_roche_euler=False, **kwargs):
stepsize = 0.01
orbiterror = 1e-16
computeps = b.get_compute(compute, check_visible=False, force_ps=True)
ltte = computeps.get_value('ltte', check_visi... | You are a Python code architect, reviewing and designing scalable and efficient code |
This function is used to generate a Burlisch - Stoer integration of orbits for a given set of time intervals. | How would you explain what the following Python 3 function does
def dynamics_bs(times, masses, smas, eccs, incls, per0s, long_ans, mean_anoms,
t0=0.0, vgamma=0.0, stepsize=0.01, orbiterror=1e-16, ltte=False,
return_roche_euler=False):
"""
Burlisch-Stoer integration of orbits to give positions an... | You are a Python code architect, reviewing and designing scalable and efficient code |
def only_horizon(meshes, xs, ys, zs, expose_horizon=False):
"""
Check all visible or partial triangles to see if they're behind the horizon,
by checking the direction of the z-component of the normals (ie hidden if mu<0)
"""
# if visibility == 0, it should remain 0
# if visibility == 0.5, it sh... | Write a Python 3 function for
returning a dictionary of all visible or partial triangles that are only horizon. | You are a Python code architect, reviewing and designing scalable and efficient code |
This function returns the native representation of a single resource in a single resource. | How would you explain what the following Python 3 function does
def native(meshes, xs, ys, zs, expose_horizon=False, horizon_method='boolean'):
centers_flat = meshes.get_column_flat('centers')
vertices_flat = meshes.get_column_flat('vertices')
triangles_flat = meshes.get_column_flat('triangles') # should ... | You are a Python code analyst, evaluating scripts for potential improvements. |
def graham(meshes, xs, ys, zs, expose_horizon=False):
"""
convex_graham
"""
distance_factor = 1.0 # TODO: make this an option (what does it even do)?
# first lets handle the horizon
visibilities, weights, horizon = only_horizon(meshes, xs, ys, zs)
# Order the bodies from front to back. ... | How would you code a function in Python 3 to
compute the convex graham of a set of meshes. | As a Python code analyst, you investigate and solve complex coding mysteries |
Get the system PS from a list of parametersets | Explain what the following Python 3 code does
def _get_system_ps(b, item, context='component'):
# TODO: make this a decorator?
if isinstance(item, list) and len(item)==1:
item = item[0]
if isinstance(item, ParameterSet):
return item.filter(context=context, check_visible=False)
elif isin... | As a Python code composer, you craft elegant and concise scripts. |
Create a constraint parameter that is used for roche requiv_L1. | Can you generate a brief explanation for the following Python 3 code
def roche_requiv_L1(q, syncpar, ecc, sma, incl_star, long_an_star, incl_orb, long_an_orb, compno=1):
return ConstraintParameter(q._bundle, "requiv_L1(%s, %d)" % (", ".join(["{%s}" % (param.uniquetwig if hasattr(param, 'uniquetwig') else param.expr... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def roche_requiv_contact_L1(q, sma, compno=1):
"""
TODO: add documentation
"""
return ConstraintParameter(q._bundle, "requiv_contact_L1(%s, %d)" % (", ".join(["{%s}" % (param.uniquetwig if hasattr(param, 'uniquetwig') else param.expr) for param in (q, sma)]), compno)) | Create a Python 3 function to
create a constraint parameter that is used for roche requiv contacting a single site. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns a constraint parameter that can be used to convert a requiv to a potential contact. | Can you generate the documentation for the following Python 3 function
def requiv_to_pot_contact(requiv, q, sma, compno=1):
return ConstraintParameter(requiv._bundle, "requiv_to_pot_contact({}, {}, {}, {})".format(_get_expr(requiv), _get_expr(q), _get_expr(sma), compno)) | As a Python code analyst, you investigate and solve complex coding mysteries |
def pot_to_requiv_contact(pot, q, sma, compno=1):
"""
TODO: add documentation
"""
return ConstraintParameter(pot._bundle, "pot_to_requiv_contact({}, {}, {}, {})".format(_get_expr(pot), _get_expr(q), _get_expr(sma), compno)) | Write a Python 3 script to
return a constraint parameter that can be used to create a requiv contact constraint. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def esinw2per0(ecc, esinw):
"""
TODO: add documentation
"""
return ConstraintParameter(ecc._bundle, "esinw2per0({}, {})".format(_get_expr(ecc), _get_expr(esinw))) | Can you write a function in Python 3 where it
returns a constraint parameter for the esinw2per0 constraint. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns a constraint parameter for the ecosw2per0 constraint. | Can you generate the documentation for the following Python 3 function
def ecosw2per0(ecc, ecosw):
# print "***", "ecosw2per0({}, {})".format(_get_expr(ecc), _get_expr(ecosw))
return ConstraintParameter(ecc._bundle, "ecosw2per0({}, {})".format(_get_expr(ecc), _get_expr(ecosw))) | As a Python code composer, you craft elegant and concise scripts. |
t0_perpass_to_supconj is a constraint parameter that is used to convert per - pass period ecc and per0 to supconj period. | Can you generate a brief explanation for the following Python 3 code
def t0_perpass_to_supconj(t0_perpass, period, ecc, per0):
return ConstraintParameter(t0_perpass._bundle, "t0_perpass_to_supconj({}, {}, {}, {})".format(_get_expr(t0_perpass), _get_expr(period), _get_expr(ecc), _get_expr(per0))) | As a Python code translator, you convert algorithms and pseudocode into Python. |
t0_supconj_to_perpass - > t0_supconj_to_perpass | Can you generate the documentation for the following Python 3 function
def t0_supconj_to_perpass(t0_supconj, period, ecc, per0):
return ConstraintParameter(t0_supconj._bundle, "t0_supconj_to_perpass({}, {}, {}, {})".format(_get_expr(t0_supconj), _get_expr(period), _get_expr(ecc), _get_expr(per0))) | As a python code expert, you are capable of creating scripts from specifications. |
t0_ref_to_supconj - converts t0_ref to supplementary t0_ref | Make a summary of the following Python 3 code
def t0_ref_to_supconj(t0_ref, period, ecc, per0):
return ConstraintParameter(t0_ref._bundle, "t0_ref_to_supconj({}, {}, {}, {})".format(_get_expr(t0_ref), _get_expr(period), _get_expr(ecc), _get_expr(per0))) | As a Python code analyst, you investigate and solve complex coding mysteries |
def asini(b, orbit, solve_for=None):
"""
Create a constraint for asini in an orbit.
If any of the required parameters ('asini', 'sma', 'incl') do not
exist in the orbit, they will be created.
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:parameter str orbit: the label of the orbit ... | How would you implement a function in Python 3 that
creates a constraint for asini in an orbit. | You are a Python code analyst, evaluating scripts for potential improvements. |
Create a constraint for esinw in an orbit. | Here you have a function in Python 3, explain what it does
def esinw(b, orbit, solve_for=None, **kwargs):
orbit_ps = _get_system_ps(b, orbit)
metawargs = orbit_ps.meta
metawargs.pop('qualifier')
esinw_def = FloatParameter(qualifier='esinw', value=0.0, default_unit=u.dimensionless_unscaled, limits=(-1.... | As a python code expert, you are capable of creating scripts from specifications. |
Create a constraint for ecosw in an orbit. | Here you have a function in Python 3, explain what it does
def ecosw(b, orbit, solve_for=None, **kwargs):
orbit_ps = _get_system_ps(b, orbit)
metawargs = orbit_ps.meta
metawargs.pop('qualifier')
ecosw_def = FloatParameter(qualifier='ecosw', value=0.0, default_unit=u.dimensionless_unscaled, limits=(-1.... | You are a Python code analyst, evaluating scripts for potential improvements. |
Create a constraint for t0_perpass and t0_supconj in an orbit | How would you explain what the following Python 3 function does
def t0_perpass_supconj(b, orbit, solve_for=None, **kwargs):
orbit_ps = _get_system_ps(b, orbit)
metawargs = orbit_ps.meta
metawargs.pop('qualifier')
# by default both t0s exist in an orbit, so we don't have to worry about creating either... | You are a Python code generator, capable of creating scripts from specifications. |
Create a constraint for t0_ref in an orbit - allowing translating between t0_ref and t0_supconj. | How would you explain what the following Python 3 function does
def t0_ref_supconj(b, orbit, solve_for=None, **kwargs):
orbit_ps = _get_system_ps(b, orbit)
metawargs = orbit_ps.meta
metawargs.pop('qualifier')
# by default both t0s exist in an orbit, so we don't have to worry about creating either
... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Convert true anom to phase | Explain what the following Python 3 code does
def _true_anom_to_phase(true_anom, period, ecc, per0):
phshift = 0
mean_anom = true_anom - (ecc*sin(true_anom))*u.deg
Phi = (mean_anom + per0) / (360*u.deg) - 1./4
# phase = Phi - (phshift - 0.25 + per0/(360*u.deg)) * period
phase = (Phi*u.d - (phshif... | You are a Python code architect, reviewing and designing scalable and efficient code |
def ph_supconj(b, orbit, solve_for=None, **kwargs):
"""
TODO: add documentation
"""
orbit_ps = _get_system_ps(b, orbit)
# metawargs = orbit_ps.meta
#metawargs.pop('qualifier')
# t0_ph0 and phshift both exist by default, so we don't have to worry about creating either
# t0_ph0 = orbit_p... | Can you write a function in Python 3 where it
gets PH_SUPCONJ for orbit b | As a Python code composer, you craft elegant and concise scripts. |
def freq(b, component, solve_for=None, **kwargs):
"""
Create a constraint for frequency (either orbital or rotational) given a period.
freq = 2 * pi / period
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:parameter str component: the label of the orbit or component in which this
... | Can you implement a function in Python 3 that
creates a constraint for frequency given a period | You are a Python code generator, capable of creating scripts from specifications. |
Keplers three - law hierarchical orbit. | Here you have a function in Python 3, explain what it does
def keplers_third_law_hierarchical(b, orbit1, orbit2, solve_for=None, **kwargs):
hier = b.hierarchy
orbit1_ps = _get_system_ps(b, orbit1)
orbit2_ps = _get_system_ps(b, orbit2)
sma1 = orbit1_ps.get_parameter(qualifier='sma')
sma2 = orbit2_... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Creates a constraint to ensure that energy is conserved and all incident
light is accounted for the given component. | Here you have a function in Python 3, explain what it does
def irrad_frac(b, component, solve_for=None, **kwargs):
comp_ps = b.get_component(component=component)
irrad_frac_refl_bol = comp_ps.get_parameter(qualifier='irrad_frac_refl_bol')
irrad_frac_lost_bol = comp_ps.get_parameter(qualifier='irrad_frac_l... | You are a Python code architect, reviewing and designing scalable and efficient code |
Create a constraint to force requiv to be semidetached | Here you have a function in Python 3, explain what it does
def semidetached(b, component, solve_for=None, **kwargs):
comp_ps = b.get_component(component=component)
requiv = comp_ps.get_parameter(qualifier='requiv')
requiv_critical = comp_ps.get_parameter(qualifier='requiv_max')
if solve_for in [requiv... | As a python code expert, you are capable of creating scripts from specifications. |
def mass(b, component, solve_for=None, **kwargs):
"""
Create a constraint for the mass of a star based on Kepler's third
law from its parent orbit.
If 'mass' does not exist in the component, it will be created
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:parameter str component: t... | Write a Python 3 function for
creating a constraint for the mass of a star based on Kepler s third - order component orbit. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def comp_sma(b, component, solve_for=None, **kwargs):
"""
Create a constraint for the star's semi-major axes WITHIN its
parent orbit. This is NOT the same as the semi-major axes OF
the parent orbit
If 'sma' does not exist in the component, it will be created
:parameter b: the :class:`phoebe.f... | How would you implement a function in Python 3 that
creates a constraint for the semi - major axes of the star in which the component is in the parent orbit. | As a Python code composer, you craft elegant and concise scripts. |
def requiv_detached_max(b, component, solve_for=None, **kwargs):
"""
Create a constraint to determine the critical (at L1) value of
requiv.
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:parameter str component: the label of the star in which this
constraint should be built
:... | Can you create a Python 3 function that
creates a constraint to determine the requiv_detached_max value of a given component. | You are a Python code analyst, evaluating scripts for potential improvements. |
Create a constraint to determine the minimum potential contact for a given component. | Make a summary of the following Python 3 code
def potential_contact_min(b, component, solve_for=None, **kwargs):
hier = b.get_hierarchy()
if not len(hier.get_value()):
# TODO: change to custom error type to catch in bundle.add_component
# TODO: check whether the problem is 0 hierarchies or more ... | You are a Python code generator, capable of creating scripts from specifications. |
def potential_contact_max(b, component, solve_for=None, **kwargs):
"""
Create a constraint to determine the critical (at L1) value of
potential at which a constact will underflow. This will only be used
for contacts for pot_min
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:paramete... | Can you implement a function in Python 3 that
creates a constraint to determine the maximum potential contact for a given component. | As a Python code analyst, you investigate and solve complex coding mysteries |
Create a constraint to determine the minimum requiv contact for a given component. | Make a summary of the following Python 3 code
def requiv_contact_min(b, component, solve_for=None, **kwargs):
hier = b.get_hierarchy()
if not len(hier.get_value()):
# TODO: change to custom error type to catch in bundle.add_component
# TODO: check whether the problem is 0 hierarchies or more tha... | As a Python code translator, you convert algorithms and pseudocode into Python. |
This function returns a constraint to determine the maximum requiv contact for a given component. | Can you tell what is the following Python 3 function doing
def requiv_contact_max(b, component, solve_for=None, **kwargs):
hier = b.get_hierarchy()
if not len(hier.get_value()):
# TODO: change to custom error type to catch in bundle.add_component
# TODO: check whether the problem is 0 hierarchie... | You are a Python code architect, reviewing and designing scalable and efficient code |
Create a constraint to determine the fillout factor of a contact envelope. | Can you tell what is the following Python 3 function doing
def fillout_factor(b, component, solve_for=None, **kwargs):
hier = b.get_hierarchy()
if not len(hier.get_value()):
# TODO: change to custom error type to catch in bundle.add_component
# TODO: check whether the problem is 0 hierarchies or... | You are a Python code generator, capable of creating scripts from specifications. |
def rotation_period(b, component, solve_for=None, **kwargs):
"""
Create a constraint for the rotation period of a star given its orbital
period and synchronicity parameters.
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:parameter str component: the label of the star in which this
... | Write a Python 3 script for
creating a constraint for the rotation period of a star given its orbital and synchronicity parameters. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Create a constraint for the inclination of a star relative to its parent orbit | How would you explain what the following Python 3 function does
def pitch(b, component, solve_for=None, **kwargs):
hier = b.get_hierarchy()
if not len(hier.get_value()):
# TODO: change to custom error type to catch in bundle.add_component
# TODO: check whether the problem is 0 hierarchies or mo... | As a Python code analyst, you investigate and solve complex coding mysteries |
def yaw(b, component, solve_for=None, **kwargs):
"""
Create a constraint for the inclination of a star relative to its parent orbit
:parameter b: the :class:`phoebe.frontend.bundle.Bundle`
:parameter str component: the label of the star in which this
constraint should be built
:parameter st... | Can you create a Python 3 function that
creates a constraint for inclination of a star relative to its parent orbit | You are a Python code analyst, evaluating scripts for potential improvements. |
get the time_ephemeris of a bundle | Given the following Python 3 function, write the documentation
def time_ephem(b, component, dataset, solve_for=None, **kwargs):
hier = b.get_hierarchy()
if not len(hier.get_value()):
# TODO: change to custom error type to catch in bundle.add_component
# TODO: check whether the problem is 0 hiera... | You are a Python code architect, reviewing and designing scalable and efficient code |
def etv(b, component, dataset, solve_for=None, **kwargs):
"""
compute the ETV column from the time_ephem and time_ecl columns (used in the
ETV dataset)
"""
time_ephem = b.get_parameter(qualifier='time_ephems', component=component, dataset=dataset, context=['dataset', 'model']) # need to provid... | Write a Python 3 function for
computing the ETV column from the time_ephems and time_ecls | As a Python code composer, you craft elegant and concise scripts. |
must be a float | How would you explain what the following Python 3 function does
def is_float(value):
return isinstance(value, float) or isinstance(value, int) or isinstance(value, np.float64), float(value) | As a Python code analyst, you investigate and solve complex coding mysteries |
def is_valid_shape(value):
"""must be a positive integer or a tuple/list of positive integers"""
if is_int_positive(value):
return True, value
elif isinstance(value, tuple) or isinstance(value, list):
for v in value:
if not is_int_positive(v):
return False, value
... | Create a Python 3 function to
check if value is a positive integer or a tuple or list of positive integers | You are a Python code generator, capable of creating scripts from specifications. |
Returns the underlying astropy quantity | Can you generate a brief explanation for the following Python 3 code
def quantity(self):
if not _has_astropy:
raise ImportError("astropy must be installed for unit/quantity support")
if self.unit is None:
raise ValueError("unit is not set, cannot convert to quantity")
r... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns a new nparray object with the new units converted to the given unit. | Make a summary of the following Python 3 code
def to(self, unit):
if not _has_astropy:
raise ImportError("astropy must be installed for unit/quantity support")
if self.unit is None:
raise ValueError("no units currently set")
if not is_unit_or_unitstring(unit)[0]:
... | As a Python code composer, you craft elegant and concise scripts. |
Dump a representation of the nparray object to a dictionary. | Can you generate a brief explanation for the following Python 3 code
def to_dict(self):
def _json_safe(v):
if isinstance(v, np.ndarray):
return v.tolist()
elif is_unit(v)[0]:
return v.to_string()
else:
return v
d = {k:_j... | You are a Python code generator, capable of creating scripts from specifications. |
def to_file(self, filename, **kwargs):
"""
dump a representation of the nparray object to a json-formatted file.
The nparray object should then be able to be fully restored via
nparray.from_file
@parameter str filename: path to the file to be created (will overwrite
... | Create a Python 3 function to
dump a representation of the nparray object to a json - formatted file. | As a Python code analyst, you investigate and solve complex coding mysteries |
return the underlying numpy array | Here you have a function in Python 3, explain what it does
def array(self):
return np.arange(self.start, self.stop, self.step) | As a python code expert, you are capable of creating scripts from specifications. |
convert from arange to linspace | Here you have a function in Python 3, explain what it does
def to_linspace(self):
num = int((self.stop-self.start)/(self.step))
return Linspace(self.start, self.stop-self.step, num) | You are a Python code generator, capable of creating scripts from specifications. |
def array(self):
"""
return the underlying numpy array
"""
return np.linspace(self.start, self.stop, self.num, self.endpoint) | Create a Python 3 function for
returning the underlying numpy array | You are a Python code generator, capable of creating scripts from specifications. |
convert from linspace to arange | Can you generate a brief explanation for the following Python 3 code
def to_arange(self):
arr, step = np.linspace(self.start, self.stop, self.num, self.endpoint, retstep=True)
return Arange(self.start, self.stop+step, step) | As a Python code analyst, you investigate and solve complex coding mysteries |
def array(self):
"""
return the underlying numpy array
"""
return np.logspace(self.start, self.stop, self.num, self.endpoint, self.base) | Write a Python 3 script to
return the underlying numpy array | As a Python code composer, you craft elegant and concise scripts. |
def array(self):
"""
return the underlying numpy array
"""
return np.geomspace(self.start, self.stop, self.num, self.endpoint) | Create a Python 3 function for
returning the underlying numpy array | As a Python code translator, you convert algorithms and pseudocode into Python. |
convert from full to linspace | Make a summary of the following Python 3 code
def to_linspace(self):
if hasattr(self.shape, '__len__'):
raise NotImplementedError("can only convert flat Full arrays to linspace")
return Linspace(self.fill_value, self.fill_value, self.shape) | As a Python code analyst, you investigate and solve complex coding mysteries |
def array(self):
"""
return the underlying numpy array
"""
return np.eye(self.M, self.N, self.k) | Write a Python 3 script to
get the underlying numpy array | You are a Python code generator, capable of creating scripts from specifications. |
Crossing a component with a given time. | Can you generate a brief explanation for the following Python 3 code
def crossing(b, component, time, dynamics_method='keplerian', ltte=True, tol=1e-4, maxiter=1000):
def projected_separation_sq(time, b, dynamics_method, cind1, cind2, ltte=True):
"""
"""
#print "*** projected_separation_sq... | You are a Python code generator, capable of creating scripts from specifications. |
This function is used to make sure that the requiv is aligned and not circular. | Can you tell what is the following Python 3 function doing
def requiv_contact_L1(q, sma, compno, **kwargs):
return requiv_L1(q=q, syncpar=1, ecc=0, sma=sma, incl_star=0, long_an_star=0, incl_orb=0, long_an_orb=0, compno=compno, **kwargs) | You are a Python code architect, reviewing and designing scalable and efficient code |
def _delta_t_supconj_perpass(period, ecc, per0):
"""
time shift between superior conjuction and periastron passage
"""
ups_sc = np.pi/2-per0
E_sc = 2*np.arctan( np.sqrt((1-ecc)/(1+ecc)) * np.tan(ups_sc/2) )
M_sc = E_sc - ecc*np.sin(E_sc)
return period*(M_sc/2./np.pi) | Write a Python 3 function that can
compute the time shift between superior conjuction and periastron passage. | You are a Python code generator, capable of creating scripts from specifications. |
def from_dict(d):
"""
load an nparray object from a dictionary
@parameter str d: dictionary representing the nparray object
"""
if isinstance(d, str):
return from_json(d)
if not isinstance(d, dict):
raise TypeError("argument must be of type dict")
if 'nparray' not in d.keys... | How would you implement a function in Python 3 that
loads an nparray object from a dictionary | As a Python code analyst, you investigate and solve complex coding mysteries |
load an nparray object from a json - formatted string | Given the following Python 3 function, write the documentation
def from_json(j):
if isinstance(j, dict):
return from_dict(j)
if not (isinstance(j, str) or isinstance(j, unicode)):
raise TypeError("argument must be of type str")
return from_dict(json.loads(j)) | You are a Python code analyst, evaluating scripts for potential improvements. |
Load an nparray object from a json file | Can you generate the documentation for the following Python 3 function
def from_file(filename):
f = open(filename, 'r')
j = json.load(f)
f.close()
return from_dict(j) | As a Python code analyst, you investigate and solve complex coding mysteries |
Monkeypatch numpy functions to call those provided by nparray instead. | How would you explain what the following Python 3 function does
def monkeypatch():
np.array = array
np.arange = arange
np.linspace = linspace
np.logspace = logspace
np.geomspace = geomspace
np.full = full
np.full_like = full_like
np.zeros = zeros
np.zeros_like = zeros_like
np.one... | As a python code expert, you are capable of creating scripts from specifications. |
def install_passband(fname, local=True):
"""
Install a passband from a local file. This simply copies the file into the
install path - but beware that clearing the installation will clear the
passband as well
If local=False, you must have permissions to access the installation directory
"""
... | Implement a Python 3 function for
installing a passband from a local file. | You are a Python code generator, capable of creating scripts from specifications. |
Download and install a given passband from the repository. | Make a summary of the following Python 3 code
def download_passband(passband, local=True):
if passband not in list_online_passbands():
raise ValueError("passband '{}' not available".format(passband))
pbdir = _pbdir_local if local else _pbdir_global
passband_fname = _online_passbands[passband]['fna... | As a python code expert, you are capable of creating scripts from specifications. |
def _planck(self, lam, Teff):
"""
Computes monochromatic blackbody intensity in W/m^3 using the
Planck function.
@lam: wavelength in m
@Teff: effective temperature in K
Returns: monochromatic blackbody intensity
"""
return 2*self.h*self.c*self.c/lam**5 ... | Can you implement a function in Python 3 that
computes monochromatic blackbody intensity in W using the the Planck function. | As a python code expert, you are capable of creating scripts from specifications. |
def _planck_deriv(self, lam, Teff):
"""
Computes the derivative of the monochromatic blackbody intensity using
the Planck function.
@lam: wavelength in m
@Teff: effective temperature in K
Returns: the derivative of monochromatic blackbody intensity
"""
... | Can you create a Python 3 function that
computes the derivative of the monochromatic blackbody intensity using the Planck function. | As a Python code composer, you craft elegant and concise scripts. |
Compute the spectral index of monochromatic blackbody intensity using the Planck function. | Here you have a function in Python 3, explain what it does
def _planck_spi(self, lam, Teff):
hclkt = self.h*self.c/lam/self.k/Teff
expterm = np.exp(hclkt)
return hclkt * expterm/(expterm-1) | You are a Python code generator, capable of creating scripts from specifications. |
def _bb_intensity(self, Teff, photon_weighted=False):
"""
Computes mean passband intensity using blackbody atmosphere:
I_pb^E = \int_\lambda I(\lambda) P(\lambda) d\lambda / \int_\lambda P(\lambda) d\lambda
I_pb^P = \int_\lambda \lambda I(\lambda) P(\lambda) d\lambda / \int_\lambda \lam... | Write a Python 3 function for
computing the mean passband intensity using blackbody atmosphere. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _bindex_blackbody(self, Teff, photon_weighted=False):
"""
Computes the mean boosting index using blackbody atmosphere:
B_pb^E = \int_\lambda I(\lambda) P(\lambda) B(\lambda) d\lambda / \int_\lambda I(\lambda) P(\lambda) d\lambda
B_pb^P = \int_\lambda \lambda I(\lambda) P(\lambda) B(... | Write a Python 3 function for
computing the mean boosting index using blackbody atmosphere. | You are a Python code generator, capable of creating scripts from specifications. |
def compute_blackbody_response(self, Teffs=None):
"""
Computes blackbody intensities across the entire range of
effective temperatures. It does this for two regimes, energy-weighted
and photon-weighted. It then fits a cubic spline to the log(I)-Teff
values and exports the interpo... | Write a Python 3 function for
computing the blackbody response for the given set of effective temperatures. | You are a Python code analyst, evaluating scripts for potential improvements. |
Compute the Castelli & Kurucz response for the given file. | How would you explain what the following Python 3 function does
def compute_ck2004_response(self, path, verbose=False):
models = glob.glob(path+'/*M1.000*')
Nmodels = len(models)
# Store the length of the filename extensions for parsing:
offset = len(models[0])-models[0].rfind('.')
... | You are a Python code analyst, evaluating scripts for potential improvements. |
Compute the direction - dependent passband intensities using Castelli - Kurucz model atmospheres. | Can you generate a brief explanation for the following Python 3 code
def compute_ck2004_intensities(self, path, particular=None, verbose=False):
models = os.listdir(path)
if particular != None:
models = [particular]
Nmodels = len(models)
# Store the length of the filename ex... | You are a Python code generator, capable of creating scripts from specifications. |
Exports CK2004 limb darkening coefficients to a PHOEBE - 2 compatible format. | Here you have a function in Python 3, explain what it does
def export_legacy_ldcoeffs(self, models, filename=None, photon_weighted=True):
if photon_weighted:
grid = self._ck2004_ld_photon_grid
else:
grid = self._ck2004_ld_energy_grid
if filename is not None:
... | You are a Python code generator, capable of creating scripts from specifications. |
def compute_ck2004_ldints(self):
"""
Computes integrated limb darkening profiles for ck2004 atmospheres.
These are used for intensity-to-flux transformations. The evaluated
integral is:
ldint = 2 \pi \int_0^1 Imu mu dmu
"""
if 'ck2004_all' not in self.content:
... | How would you implement a function in Python 3 that
computes the integrated limb darkening profiles for the 2004 atmospheres. | You are a Python code analyst, evaluating scripts for potential improvements. |
def interpolate_ck2004_ldcoeffs(self, Teff=5772., logg=4.43, abun=0.0, atm='ck2004', ld_func='power', photon_weighted=False):
"""
Interpolate the passband-stored table of LD model coefficients.
"""
if 'ck2004_ld' not in self.content:
print('Castelli & Kurucz (2004) limb dark... | How would you code a function in Python 3 to
interpolate passband - stored table of LD model coefficients. | As a python code expert, you are capable of creating scripts from specifications. |
def import_wd_atmcof(self, plfile, atmfile, wdidx, Nabun=19, Nlogg=11, Npb=25, Nints=4):
"""
Parses WD's atmcof and reads in all Legendre polynomials for the
given passband.
@plfile: path and filename of atmcofplanck.dat
@atmfile: path and filename of atmcof.dat
@wdidx: ... | Can you write a function in Python 3 where it
imports WD s atmcof and reads in all Legendre polynomials for the passed passband. | You are a Python code analyst, evaluating scripts for potential improvements. |
Internal function to compute normal passband intensities using the external WD machinery that employs blackbody approximation. | Given the following Python 3 function, write the documentation
def _log10_Inorm_extern_planckint(self, Teff):
log10_Inorm = libphoebe.wd_planckint(Teff, self.extern_wd_idx, self.wd_data["planck_table"])
return log10_Inorm | You are a Python code analyst, evaluating scripts for potential improvements. |
switch all connections to another keyspace | Explain what the following Python 3 code does
def set_keyspace(self, keyspace):
self.keyspace = keyspace
dfrds = []
for p in self._protos:
dfrds.append(p.submitRequest(ManagedThriftRequest(
'set_keyspace', keyspace)))
return defer.gatherResults(dfrds) | As a python code expert, you are capable of creating scripts from specifications. |
def solve(self,problem):
"""
Solves optimization problem.
Parameters
----------
problem : Object
"""
# Local vars
norm2 = self.norm2
norminf = self.norminf
parameters = self.parameters
# Parameters
tol = param... | Create a Python 3 function to
solve an optimization problem. | As a python code expert, you are capable of creating scripts from specifications. |
Factorizes A.
Parameters
----------
A : matrix
For symmetric systems, should contain only lower diagonal part. | Make a summary of the following Python 3 code
def factorize(self, A):
A = csc_matrix(A)
if self.prop == self.SYMMETRIC:
A = (A + A.T) - triu(A)
self.lu = self.umfpack.splu(A) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def retry(self):
"""
Retry this factory's connection. It is assumed that a previous
connection was attempted and failed- either before or after a
successful connection.
"""
if self.connector is None:
raise ValueError("No connector to retry")
if self.s... | Write a Python 3 script for
retrying this factory s connection. | You are a Python code analyst, evaluating scripts for potential improvements. |
def prep_connection(self, creds=None, keyspace=None, node_auto_discovery=True):
"""
Do login and set_keyspace tasks as necessary, and also check this
node's idea of the Cassandra ring. Expects that our connection is
alive.
Return a Deferred that will fire with the ring informati... | How would you implement a function in Python 3 that
prepares a connection to the Cassandra server. | As a Python code analyst, you investigate and solve complex coding mysteries |
Return a dictionary of keyspaces that are not system. | Can you tell what is the following Python 3 function doing
def my_pick_non_system_keyspace(self):
d = self.my_describe_keyspaces()
def pick_non_system(klist):
for k in klist:
if k.name not in SYSTEM_KEYSPACES:
return k.name
err = NoKeyspacesAv... | You are a Python code architect, reviewing and designing scalable and efficient code |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.