if not self._heatmap:<EOL><INDENT>self.fill_heatmap()<EOL><DEDENT>return self._heatmap<EOL>

Returns heatmap with absolute path names.


if not self._execution_count:<EOL><INDENT>self.fill_heatmap()<EOL><DEDENT>return self._execution_count<EOL>

Returns execution count map with absolute path names.


def _calc_skips(self, heatmap, num_lines):

if num_lines < self.MIN_SKIP_SIZE:<EOL><INDENT>return []<EOL><DEDENT>skips, prev_line = [], <NUM_LIT:0><EOL>for line in sorted(heatmap):<EOL><INDENT>curr_skip = line - prev_line - <NUM_LIT:1><EOL>if curr_skip > self.SKIP_LINES:<EOL><INDENT>skips.append((prev_line, curr_skip))<EOL><DEDENT>prev_line = line<EOL><DEDENT>if num_lines - prev_line > self.SKIP_LINES:<EOL><INDENT>skips.append((prev_line, num_lines - prev_line))<EOL><DEDENT>return skips<EOL>

Calculates skip map for large sources.
        Skip map is a list of tuples where first element of tuple is line
        number and second is length of the skip region:
            [(1, 10), (15, 10)] means skipping 10 lines after line 1 and
            10 lines after line 15.


if not skip_map:<EOL><INDENT>return [['<STR_LIT>', j + <NUM_LIT:1>, l] for j, l in enumerate(src_code)]<EOL><DEDENT>code_with_skips, i = [], <NUM_LIT:0><EOL>for line, length in skip_map:<EOL><INDENT>code_with_skips.extend(<EOL>['<STR_LIT>', i + j + <NUM_LIT:1>, l] for j, l in enumerate(src_code[i:line]))<EOL>if (code_with_skips<EOL>and code_with_skips[-<NUM_LIT:1>][<NUM_LIT:0>] == '<STR_LIT>'):  <EOL><INDENT>code_with_skips[-<NUM_LIT:1>][<NUM_LIT:1>] += length<EOL><DEDENT>else:<EOL><INDENT>code_with_skips.append(['<STR_LIT>', length])<EOL><DEDENT>i = line + length<EOL><DEDENT>code_with_skips.extend(<EOL>['<STR_LIT>', i + j + <NUM_LIT:1>, l] for j, l in enumerate(src_code[i:]))<EOL>return code_with_skips<EOL>

Skips lines in src_code specified by skip map.


with _CodeHeatmapCalculator() as prof:<EOL><INDENT>try:<EOL><INDENT>runpy.run_path(self._run_object, run_name='<STR_LIT:__main__>')<EOL><DEDENT>except SystemExit:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>heatmaps = []<EOL>for filename, heatmap in prof.heatmap.items():<EOL><INDENT>if os.path.isfile(filename):<EOL><INDENT>heatmaps.append(<EOL>self._format_heatmap(<EOL>filename, heatmap, prof.execution_count[filename]))<EOL><DEDENT><DEDENT>run_time = sum(heatmap['<STR_LIT>'] for heatmap in heatmaps)<EOL>return {<EOL>'<STR_LIT>': self._run_object,<EOL>'<STR_LIT>': run_time,<EOL>'<STR_LIT>': heatmaps<EOL>}<EOL>


return base_profiler.run_in_separate_process(self._profile_package)<EOL>

Runs package profiler in separate process.


def _format_heatmap(self, filename, heatmap, execution_count):

with open(filename) as src_file:<EOL><INDENT>file_source = src_file.read().split('<STR_LIT:\n>')<EOL>skip_map = self._calc_skips(heatmap, len(file_source))<EOL><DEDENT>run_time = sum(time for time in heatmap.values())<EOL>return {<EOL>'<STR_LIT:name>': filename,<EOL>'<STR_LIT>': heatmap,<EOL>'<STR_LIT>': execution_count,<EOL>'<STR_LIT>': self._skip_lines(file_source, skip_map),<EOL>'<STR_LIT>': run_time<EOL>}<EOL>


with open(self._run_object, '<STR_LIT:r>') as srcfile:<EOL><INDENT>src_code = srcfile.read()<EOL>code = compile(src_code, self._run_object, '<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>with _CodeHeatmapCalculator() as prof:<EOL><INDENT>exec(code, self._globs, None)<EOL><DEDENT><DEDENT>except SystemExit:<EOL><INDENT>pass<EOL><DEDENT>heatmaps = []<EOL>for filename, heatmap in prof.heatmap.items():<EOL><INDENT>if os.path.isfile(filename):<EOL><INDENT>heatmaps.append(<EOL>self._format_heatmap(<EOL>filename, heatmap, prof.execution_count[filename]))<EOL><DEDENT><DEDENT>run_time = sum(heatmap['<STR_LIT>'] for heatmap in heatmaps)<EOL>return {<EOL>'<STR_LIT>': self._run_object,<EOL>'<STR_LIT>': run_time,<EOL>'<STR_LIT>': heatmaps<EOL>}<EOL>


return base_profiler.run_in_separate_process(self._profile_module)<EOL>

Runs module profiler in separate process.


with _CodeHeatmapCalculator() as prof:<EOL><INDENT>result = self._run_object(*self._run_args, **self._run_kwargs)<EOL><DEDENT>code_lines, start_line = inspect.getsourcelines(self._run_object)<EOL>source_lines = []<EOL>for line in code_lines:<EOL><INDENT>source_lines.append(('<STR_LIT>', start_line, line))<EOL>start_line += <NUM_LIT:1><EOL><DEDENT>filename = os.path.abspath(inspect.getsourcefile(self._run_object))<EOL>heatmap = prof.heatmap[filename]<EOL>run_time = sum(time for time in heatmap.values())<EOL>return {<EOL>'<STR_LIT>': self._object_name,<EOL>'<STR_LIT>': run_time,<EOL>'<STR_LIT:result>': result,<EOL>'<STR_LIT>': int(time.time()),<EOL>'<STR_LIT>': [{<EOL>'<STR_LIT:name>': self._object_name,<EOL>'<STR_LIT>': heatmap,<EOL>'<STR_LIT>': prof.execution_count[filename],<EOL>'<STR_LIT>': source_lines,<EOL>'<STR_LIT>': run_time<EOL>}]<EOL>}<EOL>


records = []<EOL>for info, params in prof.stats.items():<EOL><INDENT>filename, lineno, funcname = info<EOL>cum_calls, num_calls, time_per_call, cum_time, _ = params<EOL>if prof.total_tt == <NUM_LIT:0>:<EOL><INDENT>percentage = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>percentage = round(<NUM_LIT:100> * (cum_time / prof.total_tt), <NUM_LIT:4>)<EOL><DEDENT>cum_time = round(cum_time, <NUM_LIT:4>)<EOL>func_name = '<STR_LIT>' % (funcname, filename)<EOL>color_hash = base_profiler.hash_name(func_name)<EOL>records.append(<EOL>(filename, lineno, funcname, cum_time, percentage, num_calls,<EOL>cum_calls, time_per_call, filename, color_hash))<EOL><DEDENT>return sorted(records, key=operator.itemgetter(<NUM_LIT:4>), reverse=True)<EOL>


prof = cProfile.Profile()<EOL>prof.enable()<EOL>try:<EOL><INDENT>runpy.run_path(self._run_object, run_name='<STR_LIT:__main__>')<EOL><DEDENT>except SystemExit:<EOL><INDENT>pass<EOL><DEDENT>prof.disable()<EOL>prof_stats = pstats.Stats(prof)<EOL>prof_stats.calc_callees()<EOL>return {<EOL>'<STR_LIT>': self._object_name,<EOL>'<STR_LIT>': self._transform_stats(prof_stats),<EOL>'<STR_LIT>': prof_stats.total_tt,<EOL>'<STR_LIT>': prof_stats.prim_calls,<EOL>'<STR_LIT>': prof_stats.total_calls,<EOL>'<STR_LIT>': int(time.time())<EOL>}<EOL>


prof = cProfile.Profile()<EOL>try:<EOL><INDENT>with open(self._run_object, '<STR_LIT:rb>') as srcfile:<EOL><INDENT>code = compile(srcfile.read(), self._run_object, '<STR_LIT>')<EOL><DEDENT>prof.runctx(code, self._globs, None)<EOL><DEDENT>except SystemExit:<EOL><INDENT>pass<EOL><DEDENT>prof_stats = pstats.Stats(prof)<EOL>prof_stats.calc_callees()<EOL>return {<EOL>'<STR_LIT>': self._object_name,<EOL>'<STR_LIT>': self._transform_stats(prof_stats),<EOL>'<STR_LIT>': prof_stats.total_tt,<EOL>'<STR_LIT>': prof_stats.prim_calls,<EOL>'<STR_LIT>': prof_stats.total_calls,<EOL>'<STR_LIT>': int(time.time())<EOL>}<EOL>


prof = cProfile.Profile()<EOL>prof.enable()<EOL>result = self._run_object(*self._run_args, **self._run_kwargs)<EOL>prof.disable()<EOL>prof_stats = pstats.Stats(prof)<EOL>prof_stats.calc_callees()<EOL>return {<EOL>'<STR_LIT>': self._object_name,<EOL>'<STR_LIT>': self._transform_stats(prof_stats),<EOL>'<STR_LIT>': prof_stats.total_tt,<EOL>'<STR_LIT>': prof_stats.prim_calls,<EOL>'<STR_LIT>': prof_stats.total_calls,<EOL>'<STR_LIT:result>': result,<EOL>'<STR_LIT>': int(time.time())<EOL>}<EOL>


module_names = set()<EOL>for fobj, modname, _ in pkgutil.iter_modules(path=[package_path]):<EOL><INDENT>filename = os.path.join(fobj.path, '<STR_LIT>' % modname)<EOL>if os.path.exists(filename):<EOL><INDENT>module_names.add(os.path.abspath(filename))<EOL><DEDENT><DEDENT>return module_names<EOL>

Returns module filenames from package.

    Args:
        package_path: Path to Python package.
    Returns:
        A set of module filenames.


return zlib.adler32(name.encode('<STR_LIT:utf-8>'))<EOL>


def run_in_separate_process(func, *args, **kwargs):

manager = multiprocessing.Manager()<EOL>manager_dict = manager.dict()<EOL>process = ProcessWithException(<EOL>manager_dict, target=func, args=args, kwargs=kwargs)<EOL>process.start()<EOL>process.join()<EOL>exc = process.exception<EOL>if exc:<EOL><INDENT>raise exc<EOL><DEDENT>return process.output<EOL>

Runs function in separate process.

    This function is used instead of a decorator, since Python multiprocessing
    module can't serialize decorated function on all platforms.


return self.parent_conn.recv()<EOL>


return self.result._getvalue()<EOL>


run_obj_type = self.get_run_object_type(run_object)<EOL>if run_obj_type == '<STR_LIT>':<EOL><INDENT>self.init_module(run_object)<EOL><DEDENT>elif run_obj_type == '<STR_LIT>':<EOL><INDENT>self.init_package(run_object)<EOL><DEDENT>else:<EOL><INDENT>self.init_function(run_object)<EOL><DEDENT>

Initializes profiler.

        Args:
            run_object: object to be profiled.


if isinstance(run_object, tuple):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>run_object, _, _ = run_object.partition('<STR_LIT:U+0020>')<EOL>if os.path.isdir(run_object):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>'<EOL>


self.profile = self.profile_module<EOL>self._run_object, _, self._run_args = run_object.partition('<STR_LIT:U+0020>')<EOL>self._object_name = '<STR_LIT>' % self._run_object<EOL>self._globs = {<EOL>'<STR_LIT>': self._run_object,<EOL>'<STR_LIT>': '<STR_LIT:__main__>',<EOL>'<STR_LIT>': None,<EOL>}<EOL>program_path = os.path.dirname(self._run_object)<EOL>if sys.path[<NUM_LIT:0>] != program_path:<EOL><INDENT>sys.path.insert(<NUM_LIT:0>, program_path)<EOL><DEDENT>self._replace_sysargs()<EOL>


self.profile = self.profile_package<EOL>self._run_object, _, self._run_args = run_object.partition('<STR_LIT:U+0020>')<EOL>self._object_name = '<STR_LIT>' % self._run_object<EOL>self._replace_sysargs()<EOL>


self.profile = self.profile_function<EOL>self._run_object, self._run_args, self._run_kwargs = run_object<EOL>filename = inspect.getsourcefile(self._run_object)<EOL>self._object_name = '<STR_LIT>' % (<EOL>self._run_object.__name__, filename)<EOL>


sys.argv[:] = [self._run_object]<EOL>if self._run_args:<EOL><INDENT>sys.argv += self._run_args.split()<EOL><DEDENT>

Replaces sys.argv with proper args to pass to script.


raise NotImplementedError<EOL>

Profiles package specified by filesystem path.

        Runs object self._run_object as a package specified by filesystem path.
        Must be overridden.


raise NotImplementedError<EOL>

Profiles module.

        Runs object self._run_object as a Python module.
        Must be overridden.


raise NotImplementedError<EOL>

Profiles function.

        Runs object self._run_object as a Python function.
        Must be overridden.


return self.profile()<EOL>

Runs profiler and returns collected stats.


def run_profilers(run_object, prof_config, verbose=False):

if len(prof_config) > len(set(prof_config)):<EOL><INDENT>raise AmbiguousConfigurationError(<EOL>'<STR_LIT>' % prof_config)<EOL><DEDENT>available_profilers = {opt for opt, _ in _PROFILERS}<EOL>for option in prof_config:<EOL><INDENT>if option not in available_profilers:<EOL><INDENT>raise BadOptionError('<STR_LIT>' % option)<EOL><DEDENT><DEDENT>run_stats = OrderedDict()<EOL>present_profilers = ((o, p) for o, p in _PROFILERS if o in prof_config)<EOL>for option, prof in present_profilers:<EOL><INDENT>curr_profiler = prof(run_object)<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>' % curr_profiler.__class__.__name__)<EOL><DEDENT>run_stats[option] = curr_profiler.run()<EOL><DEDENT>return run_stats<EOL>

Runs profilers on run_object.

    Args:
        run_object: An object (string or tuple) for profiling.
        prof_config: A string with profilers configuration.
        verbose: True if info about running profilers should be shown.
    Returns:
        An ordered dictionary with collected stats.
    Raises:
        AmbiguousConfigurationError: when prof_config is ambiguous.
        BadOptionError: when unknown options are present in configuration.


def run(func, options, args=(), kwargs={}, host='<STR_LIT:localhost>', port=<NUM_LIT>):

run_stats = run_profilers((func, args, kwargs), options)<EOL>result = None<EOL>for prof in run_stats:<EOL><INDENT>if not result:<EOL><INDENT>result = run_stats[prof]['<STR_LIT:result>']<EOL><DEDENT>del run_stats[prof]['<STR_LIT:result>']  <EOL><DEDENT>post_data = gzip.compress(<EOL>json.dumps(run_stats).encode('<STR_LIT:utf-8>'))<EOL>urllib.request.urlopen('<STR_LIT>' % (host, port), post_data)<EOL>return result<EOL>

Runs profilers on a function.

    Args:
        func: A Python function.
        options: A string with profilers configuration (i.e. 'cmh').
        args: func non-keyword arguments.
        kwargs: func keyword arguments.
        host: Host name to send collected data.
        port: Port number to send collected data.

    Returns:
        A result of func execution.


return sqlite3.connect(DB)<EOL>


with contextlib.closing(connect_to_db()) as db:<EOL><INDENT>db.cursor().executescript(DB_SCHEMA)<EOL>db.commit()<EOL><DEDENT>


flask.g.db = connect_to_db()<EOL>

Establishes SQLite connection before request.


db = getattr(flask.g, '<STR_LIT>', None)<EOL>if db is not None:<EOL><INDENT>db.close()<EOL><DEDENT>

Closes SQLite connection after request is processed.


cursor = flask.g.db.execute(<EOL>'<STR_LIT>')<EOL>entries = [{'<STR_LIT:name>': row[<NUM_LIT:0>], '<STR_LIT:message>': row[<NUM_LIT:1>]} for row in cursor.fetchall()]<EOL>return jinja2.Template(LAYOUT).render(entries=entries)<EOL>


name, msg = flask.request.form['<STR_LIT:name>'], flask.request.form['<STR_LIT:message>']<EOL>flask.g.db.execute(<EOL>'<STR_LIT>', (name, msg))<EOL>flask.g.db.commit()<EOL>return flask.redirect('<STR_LIT:/>')<EOL>


@app.route('<STR_LIT>', methods=['<STR_LIT:GET>', '<STR_LIT:POST>'])<EOL>def profiler_handler(uri):

<EOL>if uri == '<STR_LIT>':<EOL><INDENT>runner.run(show_guestbook, '<STR_LIT>')<EOL><DEDENT>elif uri == '<STR_LIT>':<EOL><INDENT>runner.run(add_entry, '<STR_LIT>')<EOL><DEDENT>return flask.redirect('<STR_LIT:/>')<EOL>


with open(filename) as src_file:<EOL><INDENT>version_match = re.search(r"<STR_LIT>",<EOL>src_file.read(), re.M)<EOL>if version_match:<EOL><INDENT>return version_match.group(<NUM_LIT:1>)<EOL><DEDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>

Returns actual version specified in filename.


with open('<STR_LIT>') as readme_file:<EOL><INDENT>return readme_file.read()<EOL><DEDENT>


file_path = path.join(path.dirname(path.abspath(__file__)), file_name)<EOL>with open(file_path) as file_obj:<EOL><INDENT>return [line for line in file_obj.read().splitlines() if line]<EOL><DEDENT>

Return a list of non-empty lines from `file_path`.


return choice(get_file_lines('<STR_LIT>'))<EOL>


adjectives = map(lambda x: (x, '<STR_LIT>'), get_file_lines('<STR_LIT>'))<EOL>animal_nouns = map(lambda x: (x, '<STR_LIT>'), get_file_lines('<STR_LIT>'))<EOL>return list(chain(adjectives, animal_nouns))<EOL>

Return a describer tuple in the form `(name, position)`,
where position is either 'prefix' or 'suffix'.


return choice(get_describers())<EOL>

Return a 2-tuple, matching a describer to 'prefix' or 'suffix'.


describer, desc_position = random_describer()<EOL>if desc_position == '<STR_LIT>':<EOL><INDENT>return (describer, random_species())<EOL><DEDENT>elif desc_position == '<STR_LIT>':<EOL><INDENT>return (random_species(), describer)<EOL><DEDENT>

Return an ordered 2-tuple containing a species and a describer.


while True:<EOL><INDENT>pair = _random_adjspecies_pair()<EOL>if maxlen and len('<STR_LIT>'.join(pair)) > maxlen:<EOL><INDENT>continue<EOL><DEDENT>if prevent_stutter and pair[<NUM_LIT:0>][-<NUM_LIT:1>] == pair[<NUM_LIT:1>][<NUM_LIT:0>]:<EOL><INDENT>continue<EOL><DEDENT>return pair<EOL><DEDENT>

Return an ordered 2-tuple containing a species and a describer.
The letter-count of the pair is guarantee to not exceed `maxlen` if
it is given. If `prevent_stutter` is True, the last letter of the
first item of the pair will be different from the first letter of
the second item.


def random_adjspecies(sep='<STR_LIT>', maxlen=<NUM_LIT:8>, prevent_stutter=True):

pair = random_adjspecies_pair(maxlen, prevent_stutter)<EOL>return pair[<NUM_LIT:0>] + sep + pair[<NUM_LIT:1>]<EOL>

Return a random adjective/species, separated by `sep`. The keyword
arguments `maxlen` and `prevent_stutter` are the same as for
`random_adjspecies_pair`, but note that the maximum length argument is
not affected by the separator.


self.update_filenames()<EOL>lg.info('<STR_LIT>' + self.project_file)<EOL>f = open(self.project_file, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>' + self.project_file + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(len(self.wavelengths)) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(len(self.wavelengths)) + '<STR_LIT>' + str(self.wavelengths[<NUM_LIT:0>]) + '<STR_LIT:->' + str(<EOL>self.wavelengths[len(self.wavelengths) - <NUM_LIT:1>]) + '<STR_LIT>')<EOL>f.write('<STR_LIT>' + str(len(self.wavelengths)) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(wave) for wave in self.wavelengths]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.ds_name + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.ds_code + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.partition + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.vn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.hn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(theta) for theta in self.theta_points]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.depth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sample_point_distance) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sample_point_delta_distance) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.sky_file + '<STR_LIT:\n>')  <EOL>f.write('<STR_LIT>' + self.water_surface_file)<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.attenuation_file + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.scattering_file + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.phase_function_file + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.bottom_reflectance_file + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.sky_type + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_azimuth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_zenith) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_c) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_r_dif) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.iface_type + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.iface_0_ri) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.iface_1_ri) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.iop_type + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.iop_backscatter_proportion_list) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.bound_bottom_reflec_diffuse_data) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.sky_sub_quad_count + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.iface_sub_quad_count + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.pf_sub_quad_count + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.integrator + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.euler_steps_per_optical_depth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.midpoint_steps_per_optical_depth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.runga4_steps_per_optical_depth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.runga4adap_min_steps_per_optical_depth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.runga4adap_max_steps_per_optical_depth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.runga4adap_min_error) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.runga4adap_max_error) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + os.path.join(self.output_path,<EOL>'<STR_LIT>') + '<STR_LIT:\n>')  <EOL>f.write('<STR_LIT>' + str(self.ld_b_image_sens_k) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + os.path.join(self.output_path,<EOL>'<STR_LIT>') + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.report_file)<EOL>f.write('<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.verbose) + '<STR_LIT:\n>')<EOL>f.close()<EOL>

All of the class properties are written to a text file

        Each property is on a new line with the key and value seperated with an equals sign '='
        This is the mane planarrad properties file used by slabtool


inp_file = self.sky_file + '<STR_LIT>'<EOL>lg.info('<STR_LIT>' + inp_file)<EOL>f = open(inp_file, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>' + str(self.verbose) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.num_bands) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(wave) for wave in self.wavelengths]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.partition + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.vn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.hn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_r_dif) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(theta) for theta in self.theta_points]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.sky_type + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_azimuth) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_zenith) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + inp_file.strip('<STR_LIT>') + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.sky_file + '<STR_LIT>' + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + '<STR_LIT:\n>')<EOL>if self.sky_type == '<STR_LIT>':<EOL><INDENT>f.write('<STR_LIT>' + str(self.sky_c) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.sky_r_dif) + '<STR_LIT:\n>')<EOL><DEDENT>f.flush()<EOL>f.close()<EOL>

Writes the params to file that skytool_Free needs to generate the sky radiance distribution.


inp_file = self.water_surface_file + '<STR_LIT>'<EOL>lg.info('<STR_LIT>' + inp_file)<EOL>if self.surf_state == '<STR_LIT>':  <EOL><INDENT>lg.info('<STR_LIT>')<EOL>f = open(inp_file, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>' + str(self.verbose) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.num_bands) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(wave) for wave in self.wavelengths]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.partition + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.vn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.hn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(theta) for theta in self.theta_points]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.iface_type + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.iface_0_ri) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.iface_1_ri) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.wind_speed) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.wind_direc) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.crosswind_vertices) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.upwind_vertices) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.surface_size) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.surface_radius) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.target_size) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.rays_per_quad) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.surface_count) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.azimuthally_average) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + inp_file.strip('<STR_LIT>') + '<STR_LIT:\n>')<EOL>f.flush()<EOL>f.close()<EOL><DEDENT>

Write the params to file that surftool_Free needs to generate the surface facets


inp_file = os.path.join(os.path.join(self.input_path, '<STR_LIT>'), self.phase_function_file) + '<STR_LIT>'<EOL>lg.info('<STR_LIT>' + inp_file)<EOL>if self.iop_type == '<STR_LIT>' or '<STR_LIT>' or '<STR_LIT>' or '<STR_LIT>':<EOL><INDENT>lg.info('<STR_LIT>' + self.iop_type)<EOL>f = open(inp_file, '<STR_LIT:w>')<EOL>f.write('<STR_LIT>' + str(self.verbose) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.num_bands) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(wave) for wave in self.wavelengths]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.partition + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.vn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + str(self.hn) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>')<EOL>f.write("<STR_LIT:U+002C>".join([str(theta) for theta in self.theta_points]) + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + self.iop_type + '<STR_LIT:\n>')<EOL>f.write('<STR_LIT>' + inp_file.strip('<STR_LIT>') + '<STR_LIT:\n>')<EOL>f.flush()<EOL>f.close()<EOL><DEDENT>


self.sky_file = os.path.abspath(os.path.join(os.path.join(self.input_path, '<STR_LIT>'),<EOL>'<STR_LIT>' + self.sky_state + '<STR_LIT>' + str(<EOL>self.sky_zenith) + '<STR_LIT>' + str(<EOL>self.sky_azimuth) + '<STR_LIT:_>' + str(<EOL>self.num_bands) + '<STR_LIT:_>' + self.ds_code))<EOL>

Does nothing currently.  May not need this method


self.wavelengths = scipy.asarray([wavelengths])<EOL>self.b_bp = scipy.asarray([])<EOL>self.a_cdom = scipy.asarray([])<EOL>self.a_phi = scipy.asarray([])<EOL>self.a_water = scipy.asarray([])<EOL>self.b_water = scipy.asarray([])<EOL>self.b_b = scipy.asarray([])<EOL>self.b = scipy.asarray([])<EOL>self.a = scipy.asarray([])<EOL>self.c = scipy.asarray([])<EOL>

Constructor

        :param wavelengths: list of wavelengths all IOPs will be interpolated to


def build_bbp(self, x, y, wave_const=<NUM_LIT>):

lg.info('<STR_LIT>')<EOL>self.b_bp = x * (wave_const / self.wavelengths) ** y<EOL>

Builds the particle backscattering function  :math:`X(\\frac{550}{\\lambda})^Y`

:param x: function coefficient
:param y: order of the power function
:param wave_const: wave constant default 550 (nm)
:returns null:


def build_a_cdom(self, g, s, wave_const=<NUM_LIT>):

lg.info('<STR_LIT>')<EOL>self.a_cdom = g * scipy.exp(-s * (self.wavelengths - wave_const))<EOL>

Builds the CDOM absorption function :: :math:`G \exp (-S(\lambda - 400))`

:param g: function coefficient
:param s: slope factor
:param wave_const: wave constant default = 400 (nm)
:returns null:


lg.info('<STR_LIT>')<EOL>try:<EOL><INDENT>self.a_phi = self._read_iop_from_file(file_name)<EOL><DEDENT>except:<EOL><INDENT>lg.exception('<STR_LIT>' + file_name)<EOL>self.a_phi = -<NUM_LIT:1><EOL><DEDENT>

Read the phytoplankton absorption file from a csv formatted file

        :param file_name: filename and path of the csv file


lg.info('<STR_LIT>' + str(scale_parameter))<EOL>try:<EOL><INDENT>self.a_phi = self.a_phi * scale_parameter<EOL><DEDENT>except:<EOL><INDENT>lg.exception("<STR_LIT>")<EOL><DEDENT>

Scale the spectra by multiplying by linear scaling factor

        :param scale_parameter: Linear scaling factor


lg.info('<STR_LIT>')<EOL>try:<EOL><INDENT>self.a_water = self._read_iop_from_file(file_name)<EOL><DEDENT>except:<EOL><INDENT>lg.exception('<STR_LIT>' + file_name)<EOL><DEDENT>

Read the pure water absorption from a csv formatted file

        :param file_name: filename and path of the csv file


lg.info('<STR_LIT>')<EOL>try:<EOL><INDENT>self.b_water = self._read_iop_from_file(file_name)<EOL><DEDENT>except:<EOL><INDENT>lg.exception('<STR_LIT>' + file_name)<EOL><DEDENT>

Read the pure water scattering from a csv formatted file

        :param file_name: filename and path of the csv file


lg.info('<STR_LIT>' + file_name + '<STR_LIT>' + str(self.wavelengths))<EOL>if os.path.isfile(file_name):<EOL><INDENT>iop_reader = csv.reader(open(file_name), delimiter='<STR_LIT:U+002C>', quotechar='<STR_LIT:">')<EOL>wave = iop_reader.next()<EOL>iop = iop_reader.next()<EOL><DEDENT>else:<EOL><INDENT>lg.exception('<STR_LIT>' + file_name)<EOL>raise IOError<EOL><DEDENT>try:<EOL><INDENT>wave = map(float, wave)<EOL>iop = map(float, iop)<EOL>return scipy.interp(self.wavelengths, wave, iop)<EOL><DEDENT>except IOError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL>return -<NUM_LIT:1><EOL><DEDENT>

Generic IOP reader that interpolates the iop to the common wavelengths defined in the constructor

:param file_name: filename and path of the csv file
:returns interpolated iop


self._write_iop_to_file(self.b, file_name)<EOL>

Write the total scattering to csv file

        :param file_name: filename and path of the csv file


self._write_iop_to_file(self.c, file_name)<EOL>

Write the total attentuation to file

        :param file_name: filename and path of the csv file


def _write_iop_to_file(self, iop, file_name):

lg.info('<STR_LIT>' + file_name)<EOL>f = open(file_name, '<STR_LIT:w>')<EOL>for i in scipy.nditer(iop):<EOL><INDENT>f.write(str(i) + '<STR_LIT:\n>')<EOL><DEDENT>

Generic iop file writer

        :param iop numpy array to write to file
        :param file_name the file and path to write the IOP to


lg.info('<STR_LIT>')<EOL>self.b_b = self.b_bp<EOL>


lg.info('<STR_LIT>' + str(scattering_fraction))<EOL>self.b = (self.b_b + self.b_water / <NUM_LIT>) / scattering_fraction<EOL>

Calculates the total scattering from back-scattering

        :param scattering_fraction: the fraction of back-scattering to total scattering default = 0.01833

        b = ( bb[sea water] + bb[p] ) /0.01833


lg.info('<STR_LIT>')<EOL>self.a = self.a_water + self.a_cdom + self.a_phi<EOL>

Calculates the total absorption from water, phytoplankton and CDOM

        a = awater + acdom + aphi


lg.info('<STR_LIT>')<EOL>self.c = self.a + self.b<EOL>

Calculates the total attenuation from the total absorption and total scattering

        c = a + b


lg.info('<STR_LIT>')<EOL>self.build_a()<EOL>self.build_bb()<EOL>self.build_b()<EOL>self.build_c()<EOL>

Meta method that calls all of the build methods in the correct order

        self.build_a()
        self.build_bb()
        self.build_b()
        self.build_c()


def __init__(self, object, batch_name='<STR_LIT>'):

self.run_params = object<EOL>self.saa_list = []<EOL>self.sza_list = []<EOL>self.p_list = []  <EOL>self.x_list = []<EOL>self.y_list = []<EOL>self.g_list = []<EOL>self.s_list = []<EOL>self.z_list = []<EOL>self.batch_output = os.path.join(self.run_params.output_path, batch_name)<EOL>self.bio_params = BioOpticalParameters(self.run_params.wavelengths)<EOL>

Construcuter that sets the up batch run with 'batchable' parameters

        :param batch_name: the name of the project.  All outputs will be put in a directory of the same name


done = False<EOL>dir_list = []<EOL>tic = time.clock()<EOL>lg.info('<STR_LIT>' + str(tic))<EOL>if self.run_params.num_cpus == -<NUM_LIT:1>:  <EOL><INDENT>self.run_params.num_cpus = os.sysconf("<STR_LIT>")<EOL>lg.info('<STR_LIT>' + str(self.run_params.num_cpus) + '<STR_LIT>')<EOL><DEDENT>tmp_dir_list = os.listdir(self.batch_output)<EOL>for direc in tmp_dir_list:<EOL><INDENT>dir_list.append(os.path.join(self.batch_output, direc))<EOL><DEDENT>num_dirs = len(dir_list)<EOL>lg.info('<STR_LIT>' + str(num_dirs) + '<STR_LIT>' + self.batch_output)<EOL>sub = scipy.floor(num_dirs / self.run_params.num_cpus)<EOL>remainder = num_dirs - (sub * self.run_params.num_cpus)<EOL>if remainder > <NUM_LIT:0>:<EOL><INDENT>lg.warning('<STR_LIT>')<EOL>lg.warning('<STR_LIT>')<EOL>lg.warning('<STR_LIT>' + str(remainder))<EOL><DEDENT>while not done:<EOL><INDENT>for l in range(<NUM_LIT:0>, int(sub)):<EOL><INDENT>lg.info('<STR_LIT>' + str(self.run_params.num_cpus) + '<STR_LIT>')<EOL>for m in range(<NUM_LIT:0>, self.run_params.num_cpus):<EOL><INDENT>_dir = dir_list.pop()<EOL>report_dir, report_file_name = os.path.split(self.run_params.report_file)<EOL>lg.debug(report_file_name)<EOL>lg.debug(os.path.join(_dir, report_file_name))<EOL>try:<EOL><INDENT>rep_size = os.path.getsize(os.path.join(_dir, report_file_name.strip('<STR_LIT:\n>')))<EOL>lg.debug('<STR_LIT>' + str(rep_size))<EOL><DEDENT>except:<EOL><INDENT>rep_size = <NUM_LIT:0><EOL><DEDENT>if rep_size < <NUM_LIT:1.0>:  <EOL><INDENT>lg.info('<STR_LIT>')<EOL>p = Process(target=self._run, args=(_dir,))<EOL><DEDENT>else:<EOL><INDENT>lg.warning('<STR_LIT>' + os.path.join(_dir, report_file_name.strip(<EOL>'<STR_LIT:\n>')) + '<STR_LIT>')<EOL>p = Process(target=self._dummy, args=(_dir,))<EOL><DEDENT>p.start()<EOL>lg.info('<STR_LIT>' + str(p.pid))<EOL><DEDENT>p.join()<EOL><DEDENT>self.run_params.num_cpus = remainder<EOL>remainder = <NUM_LIT:0><EOL>lg.info('<STR_LIT>')<EOL>sub = <NUM_LIT:1><EOL>if remainder == <NUM_LIT:0>:<EOL><INDENT>done = True<EOL><DEDENT><DEDENT>toc = time.clock()  <EOL>lg.info('<STR_LIT>' + str(toc))<EOL>timeTaken = toc - tic<EOL>lg.info('<STR_LIT>' + str(timeTaken))<EOL>

Distributes the work across the CPUs.  It actually uses _run()


This is just for spoofing the batch.  Doesn't run anything


<EOL>file_tools = FileTools()<EOL>run_dict = file_tools.read_param_file_to_dict(os.path.join(run_dir, '<STR_LIT>'))<EOL>if os.path.isfile(run_dict['<STR_LIT>']):<EOL><INDENT>sky_file_exists = True<EOL>lg.info('<STR_LIT>' + run_dict['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>inp_file = run_dict['<STR_LIT>'] + '<STR_LIT>'<EOL>self.run_params.write_sky_params_to_file()<EOL>lg.debug('<STR_LIT>' + os.path.join(self.run_params.exec_path, '<STR_LIT>') + '<STR_LIT:#>')<EOL>lg.debug(os.path.join(self.run_params.exec_path, '<STR_LIT>') + '<STR_LIT>' + inp_file)<EOL>os.system(os.path.join(self.run_params.exec_path, '<STR_LIT>') + '<STR_LIT>' + inp_file)<EOL><DEDENT>if os.path.isfile(run_dict['<STR_LIT>']):<EOL><INDENT>surface_file_exists = True<EOL>lg.info('<STR_LIT>' + run_dict['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>try:<EOL><INDENT>inp_file = run_dict['<STR_LIT>'] + '<STR_LIT>'<EOL>self.run_params.write_surf_params_to_file()<EOL>if not os.path.isfile(inp_file):<EOL><INDENT>lg.error(inp_file + '<STR_LIT>')<EOL><DEDENT>os.system(os.path.join(self.run_params.exec_path, '<STR_LIT>') + '<STR_LIT>' + inp_file)<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT><DEDENT>if os.path.isfile(run_dict['<STR_LIT>']):<EOL><INDENT>phase_file_exists = True<EOL>lg.info('<STR_LIT>' + run_dict['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>try:<EOL><INDENT>inp_file = run_dict['<STR_LIT>'] + '<STR_LIT>'<EOL>self.run_params.write_phase_params_to_file()<EOL>if not os.path.isfile(inp_file):<EOL><INDENT>lg.error(inp_file + '<STR_LIT>')<EOL><DEDENT>os.system(os.path.join(self.run_params.exec_path, '<STR_LIT>') + '<STR_LIT>' + inp_file)<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT><DEDENT>inp_file = run_dict['<STR_LIT:name>']<EOL>if not os.path.isfile(inp_file):<EOL><INDENT>lg.error(inp_file + '<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>os.system(os.path.join(self.run_params.exec_path, '<STR_LIT>') + '<STR_LIT>' + inp_file)<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT>


if not os.path.exists(self.batch_output):<EOL><INDENT>try:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>if self.batch_output == self.run_params.output_path + '<STR_LIT>':<EOL><INDENT>lg.warning('<STR_LIT>')<EOL><DEDENT>os.makedirs(self.batch_output)<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT><DEDENT>elif os.path.exists(self.batch_output) and overwrite == True:<EOL><INDENT>try:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>lg.warning('<STR_LIT>')<EOL>if self.batch_output == self.run_params.output_path + '<STR_LIT>':<EOL><INDENT>lg.warning('<STR_LIT>')<EOL><DEDENT>os.makedirs(self.batch_output)<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT><DEDENT>self.bio_params.read_pure_water_absorption_from_file(<EOL>self.run_params.pure_water_absorption_file)<EOL>self.bio_params.read_pure_water_scattering_from_file(<EOL>self.run_params.pure_water_scattering_file)<EOL>self.bio_params.read_aphi_from_file(self.run_params.phytoplankton_absorption_file)<EOL>for saa in self.saa_list:<EOL><INDENT>self.run_params.sky_aziumth = saa<EOL>self.run_params.sky_file = os.path.abspath(<EOL>os.path.join(os.path.join(self.run_params.input_path, '<STR_LIT>'),<EOL>'<STR_LIT>' + self.run_params.sky_state + '<STR_LIT>' + str(self.run_params.sky_zenith) + '<STR_LIT>' + str(<EOL>self.run_params.sky_azimuth) + '<STR_LIT:_>' + str(<EOL>self.run_params.num_bands) + '<STR_LIT:_>' + self.run_params.ds_code))<EOL>for sza in self.sza_list:<EOL><INDENT>self.run_params.sky_zenith = sza<EOL>self.run_params.sky_file = os.path.abspath(<EOL>os.path.join(os.path.join(self.run_params.input_path, '<STR_LIT>'),<EOL>'<STR_LIT>' + self.run_params.sky_state + '<STR_LIT>' + str(<EOL>self.run_params.sky_zenith) + '<STR_LIT>' + str(self.run_params.sky_azimuth) + '<STR_LIT:_>' + str(<EOL>self.run_params.num_bands) + '<STR_LIT:_>' + self.run_params.ds_code))<EOL>for p in self.p_list:<EOL><INDENT>for x in self.x_list:<EOL><INDENT>for y in self.y_list:<EOL><INDENT>for g in self.g_list:<EOL><INDENT>for s in self.s_list:<EOL><INDENT>for z in self.z_list:<EOL><INDENT>file_name = '<STR_LIT>' + str(saa) + '<STR_LIT>' + str(sza) + '<STR_LIT>' + str(p) + '<STR_LIT>' + str(<EOL>x) + '<STR_LIT>' + str(y) + '<STR_LIT>' + str(g) + '<STR_LIT>' + str(s) + '<STR_LIT>' + str(z)<EOL>dir_name = os.path.join(self.batch_output, file_name)<EOL>self.run_params.output_path = dir_name<EOL>self.run_params.sky_azimuth = saa<EOL>self.run_params.sky_zenith = sza<EOL>self.run_params.depth = z<EOL>self.bio_params.build_bbp(x, y)  <EOL>self.bio_params.build_a_cdom(g, s)<EOL>self.bio_params.read_aphi_from_file(<EOL>self.run_params.phytoplankton_absorption_file)<EOL>self.bio_params.scale_aphi(p)<EOL>self.bio_params.build_all_iop()<EOL>self.run_params.scattering_file = os.path.join(<EOL>os.path.join(self.run_params.input_path, '<STR_LIT>'), '<STR_LIT>' + file_name)<EOL>self.bio_params.write_b_to_file(self.run_params.scattering_file)<EOL>self.run_params.attenuation_file = os.path.join(<EOL>os.path.join(self.run_params.input_path, '<STR_LIT>'), '<STR_LIT>' + file_name)<EOL>self.bio_params.write_c_to_file(self.run_params.attenuation_file)<EOL>self.run_params.project_file = os.path.join(dir_name, '<STR_LIT>')<EOL>self.run_params.report_file = os.path.join(dir_name, '<STR_LIT>')<EOL>self.run_params.write_sky_params_to_file()<EOL>self.run_params.write_surf_params_to_file()<EOL>self.run_params.write_phase_params_to_file()<EOL>if not os.path.exists(dir_name):<EOL><INDENT>try:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>os.makedirs(dir_name)<EOL>self.run_params.write_run_parameters_to_file()<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT><DEDENT>elif os.path.exists(dir_name) and overwrite == True:<EOL><INDENT>try:<EOL><INDENT>lg.info('<STR_LIT>')<EOL>lg.warning('<STR_LIT>')<EOL>os.makedirs(dir_name)<EOL>self.run_params.write_run_parameters_to_file()<EOL><DEDENT>except OSError:<EOL><INDENT>lg.exception('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

For all possible combinations of 'batchable' parameters. create a unique directory to story outputs

        Each directory name is unique and contains the run parameters in the directory name

        :param overwrite: If set to True will over write all files default = False


def batch_parameters(self, saa, sza, p, x, y, g, s, z):

self.saa_list = saa<EOL>self.sza_list = sza<EOL>self.p_list = p<EOL>self.x_list = x<EOL>self.y_list = y<EOL>self.g_list = g<EOL>self.s_list = s<EOL>self.z_list = z<EOL>

Takes lists for parameters and saves them as class properties

        :param saa: <list> Sun Azimuth Angle (deg)
        :param sza: <list> Sun Zenith Angle (deg)
        :param p: <list> Phytoplankton linear scalling factor
        :param x: <list> Scattering scaling factor
        :param y: <list> Scattering slope factor
        :param g: <list> CDOM absorption scaling factor
        :param s: <list> CDOM absorption slope factor
        :param z: <list> depth (m)


data = loadtxt(file_name, delimiter='<STR_LIT:=>', dtype=scipy.string0)<EOL>data_dict = dict(data)<EOL>for key in data_dict.keys():<EOL><INDENT>data_dict[key] = data_dict[key].strip()<EOL>data_dict[key.strip()] = data_dict[key]<EOL>del data_dict[key]<EOL><DEDENT>return data_dict<EOL>

Loads a text file to a python dictionary using '=' as the delimiter

        :param file_name: the name and path of the text file


data_object.__dict__ = data_dict<EOL>return data_object<EOL>

Maps a dictionary to an object.  Variable names become the key in the dict

        :param data_object: Is an instantiated class
        :param data_dict: is the python dictionary
        :returns data_object:


try:<EOL><INDENT>return [float(s) for s in string_var.strip('<STR_LIT:[>').strip('<STR_LIT:]>').split('<STR_LIT:U+002CU+0020>')]<EOL><DEDENT>except:<EOL><INDENT>return [float(s) for s in string_var.strip('<STR_LIT:[>').strip('<STR_LIT:]>').split('<STR_LIT:U+002C>')]<EOL><DEDENT>

Pull comma separated string values out of a text file and converts them to float list


done = False<EOL>f = open(filename)<EOL>while f:<EOL><INDENT>line = f.readline()<EOL>if not line:<EOL><INDENT>done = True<EOL>break<EOL><DEDENT>if "<STR_LIT>" in line.strip():<EOL><INDENT>tmp = []<EOL>for i_iter in range(<NUM_LIT:0>, len(self.data_dictionary['<STR_LIT>']) - <NUM_LIT:2>):<EOL><INDENT>tmp.append(f.readline())<EOL><DEDENT>self.data_dictionary['<STR_LIT>'] = tmp<EOL><DEDENT>elif '<STR_LIT:#>' not in line or not line.strip():<EOL><INDENT>element = line.split('<STR_LIT:U+002C>')<EOL>self.data_dictionary[element[<NUM_LIT:0>]] = element[<NUM_LIT:1>:]<EOL><DEDENT>if "<STR_LIT>" in line.strip():<EOL><INDENT>tmp = []<EOL>for i_iter in range(<NUM_LIT:0>, len(self.data_dictionary['<STR_LIT>']) - <NUM_LIT:2>):<EOL><INDENT>tmp.append(f.readline())<EOL><DEDENT>self.data_dictionary['<STR_LIT>'] = tmp<EOL><DEDENT>elif '<STR_LIT:#>' not in line or not line.strip():<EOL><INDENT>element = line.split('<STR_LIT:U+002C>')<EOL>self.data_dictionary[element[<NUM_LIT:0>]] = element[<NUM_LIT:1>:]<EOL><DEDENT>if "<STR_LIT>" in line.strip():<EOL><INDENT>for i_iter in range(<NUM_LIT:0>, int(self.data_dictionary['<STR_LIT>'][<NUM_LIT:1>])):<EOL><INDENT>tmp = []<EOL>for j_iter in range(<NUM_LIT:0>, len(self.data_dictionary['<STR_LIT>']) - <NUM_LIT:2>):<EOL><INDENT>tmp.append(f.readline())<EOL><DEDENT>self.data_dictionary['<STR_LIT>' + str(i_iter + <NUM_LIT:1>)] = tmp<EOL>f.readline()<EOL>f.readline()  <EOL><DEDENT><DEDENT>if "<STR_LIT>" in line.strip():<EOL><INDENT>for i_iter in range(<NUM_LIT:0>, int(self.data_dictionary['<STR_LIT>'][<NUM_LIT:1>])):<EOL><INDENT>tmp = []<EOL>for j_iter in range(<NUM_LIT:0>, len(self.data_dictionary['<STR_LIT>']) - <NUM_LIT:2>):<EOL><INDENT>tmp.append(f.readline())<EOL><DEDENT>self.data_dictionary['<STR_LIT>' + str(i_iter + <NUM_LIT:1>)] = tmp<EOL>f.readline()<EOL>f.readline()  <EOL><DEDENT><DEDENT><DEDENT>return self.data_dictionary<EOL>

Reads in a PlanarRad generated report

        Saves the single line reported parameters as a python dictionary

        :param filename: The name and path of the PlanarRad generated file
        :returns self.data_dictionary: python dictionary with the key and values from the report


def calc_directional_aop(self, report, parameter, parameter_dir):

lg.debug('<STR_LIT>' + parameter)<EOL>tmp_zenith = []<EOL>param_zenith = parameter_dir.split('<STR_LIT::>')[<NUM_LIT:0>]<EOL>param_azimuth = parameter_dir.split('<STR_LIT::>')[<NUM_LIT:1>]<EOL>for i_iter in range(<NUM_LIT:0>, int(report['<STR_LIT>'][<NUM_LIT:1>])):<EOL><INDENT>tmp_zenith.append(report['<STR_LIT>'][i_iter][:].split('<STR_LIT:U+002C>')[<NUM_LIT:0>]) <EOL><DEDENT>tmp_azimuth = report['<STR_LIT>'][<NUM_LIT:1>]<EOL>zenith = scipy.asarray(tmp_zenith, dtype=float)<EOL>azimuth = scipy.fromstring(tmp_azimuth, dtype=float, sep='<STR_LIT:U+002C>')<EOL>from scipy import interpolate<EOL>lw = scipy.zeros(int(report['<STR_LIT>'][<NUM_LIT:1>]))<EOL>for j_iter in range(<NUM_LIT:0>, int(report['<STR_LIT>'][<NUM_LIT:1>])):<EOL><INDENT>if parameter == '<STR_LIT>':<EOL><INDENT>lg.info('<STR_LIT>')<EOL>tmp_lw = report['<STR_LIT>' + str(j_iter + <NUM_LIT:1>)]<EOL><DEDENT>elif parameter == '<STR_LIT>':<EOL><INDENT>lg.info('<STR_LIT>')<EOL>print(report.keys())<EOL>tmp_lw = report['<STR_LIT>' + str(j_iter + <NUM_LIT:1>)]<EOL><DEDENT>lw_scal = scipy.zeros((int(report['<STR_LIT>'][<NUM_LIT:1>]), int(report['<STR_LIT>'][<NUM_LIT:1>])))<EOL>for i_iter in range(<NUM_LIT:0>, int(report['<STR_LIT>'][<NUM_LIT:1>])):<EOL><INDENT>lw_scal[<NUM_LIT:0>, i_iter] = tmp_lw[<NUM_LIT:0>].split('<STR_LIT:U+002C>')[<NUM_LIT:0>]<EOL>lw_scal[int(report['<STR_LIT>'][<NUM_LIT:1>]) - <NUM_LIT:1>, i_iter] = tmp_lw[-<NUM_LIT:1>].split('<STR_LIT:U+002C>')[<NUM_LIT:0>]<EOL><DEDENT>for i_iter in range(<NUM_LIT:1>, int(report['<STR_LIT>'][<NUM_LIT:1>]) - <NUM_LIT:1>):<EOL><INDENT>lw_scal[i_iter, :] = scipy.asarray(tmp_lw[i_iter].split('<STR_LIT:U+002C>'), dtype=float)<EOL><DEDENT>f1 = interpolate.interp2d(zenith, azimuth, lw_scal)<EOL>lw[j_iter] = f1(float(param_zenith), float(param_azimuth))<EOL><DEDENT>if parameter == '<STR_LIT>':<EOL><INDENT>tmp_rrs = lw / scipy.asarray(report['<STR_LIT>'], dtype=float)[<NUM_LIT:1>:]  <EOL><DEDENT>elif parameter == '<STR_LIT>':<EOL><INDENT>tmp_rrs = lw / scipy.asarray(report['<STR_LIT>'], dtype=float)[<NUM_LIT:1>:]  <EOL><DEDENT>rrs = "<STR_LIT:U+002C>".join(map(str, tmp_rrs))<EOL>return "<STR_LIT>" + rrs<EOL>

Will calcuate the directional AOP (only sub-surface rrs for now) if the direction is defined using @
e.g. rrs@32.0:45  where <zenith-theta>:<azimuth-phi>

:param report: The planarrad report dictionary.  should include the quadtables and the directional info
:param parameter: parameter to calc.  Currently only sub-surface reflectance rrs.
:return:


def write_batch_report(self, input_directory, parameter):

<EOL>if '<STR_LIT:@>' in parameter:<EOL><INDENT>parameter_dir = parameter.split('<STR_LIT:@>')[<NUM_LIT:1>]<EOL>parameter = parameter.split('<STR_LIT:@>')[<NUM_LIT:0>]<EOL><DEDENT>batch_report_file = '<STR_LIT>'<EOL>batch_report_file = os.path.join(input_directory, batch_report_file)<EOL>f = open(batch_report_file, '<STR_LIT:w>')<EOL>w = csv.writer(f, delimiter='<STR_LIT:U+002C>')<EOL>dir_list = os.listdir(input_directory)<EOL>read_first_file = True<EOL>i_iter = <NUM_LIT:0><EOL>while read_first_file:<EOL><INDENT>if os.path.exists(os.path.join(input_directory, os.path.join(dir_list[i_iter], '<STR_LIT>'))):<EOL><INDENT>report = self.read_pr_report(<EOL>os.path.join(input_directory, os.path.join(dir_list[i_iter], '<STR_LIT>')))<EOL>read_first_file = False<EOL><DEDENT>else:<EOL><INDENT>lg.warning('<STR_LIT>' + dir_list[i_iter])<EOL>i_iter += <NUM_LIT:1><EOL><DEDENT><DEDENT>try:<EOL><INDENT>wave_val = report['<STR_LIT>']<EOL>param_val = report[parameter]<EOL><DEDENT>except:<EOL><INDENT>lg.exception('<STR_LIT>' + str(parameter) + '<STR_LIT>')<EOL><DEDENT>wave_str = str(wave_val)<EOL>wave_str = wave_str.strip('<STR_LIT:[>').strip('<STR_LIT:]>').replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT:U+0020>', '<STR_LIT>').replace('<STR_LIT>',<EOL>'<STR_LIT>').replace(<EOL>'<STR_LIT:U+002C>', '<STR_LIT>')<EOL>f.write(<EOL>'<STR_LIT>' + wave_str + '<STR_LIT>')<EOL>for dir in dir_list:<EOL><INDENT>if os.path.isdir(os.path.abspath(os.path.join(input_directory, dir))):<EOL><INDENT>tmp_str_list = dir.split('<STR_LIT:_>')<EOL>saa = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:0>] if not c.isalpha())<EOL>sza = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:1>] if not c.isalpha())<EOL>p = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:2>] if not c.isalpha())<EOL>x = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:3>] if not c.isalpha())<EOL>y = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:4>] if not c.isalpha())<EOL>g = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:5>] if not c.isalpha())<EOL>s = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:6>] if not c.isalpha())<EOL>z = '<STR_LIT>'.join(c for c in tmp_str_list[<NUM_LIT:7>] if not c.isalpha())<EOL>try:<EOL><INDENT>f.write(saa + '<STR_LIT:U+002C>' + sza + '<STR_LIT:U+002C>' + p + '<STR_LIT:U+002C>' + x + '<STR_LIT:U+002C>' + y + '<STR_LIT:U+002C>' + g + '<STR_LIT:U+002C>' + s + '<STR_LIT:U+002C>' + z + '<STR_LIT:U+002C>')<EOL>report = self.read_pr_report(os.path.join(input_directory, os.path.join(dir, '<STR_LIT>')))<EOL>try:<EOL><INDENT>if '<STR_LIT>' in locals():<EOL><INDENT>param_val = self.calc_directional_aop(report, parameter, parameter_dir)<EOL><DEDENT>else:<EOL><INDENT>param_val = report[parameter]<EOL><DEDENT>param_str = str(param_val)<EOL>param_str = param_str.strip('<STR_LIT:[>').strip('<STR_LIT:]>').replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT:U+0020>',<EOL>'<STR_LIT>')<EOL>f.write(param_str + '<STR_LIT:\n>')<EOL><DEDENT>except:<EOL><INDENT>lg.exception('<STR_LIT>' + str(parameter) + '<STR_LIT>')<EOL><DEDENT><DEDENT>except:<EOL><INDENT>lg.warning('<STR_LIT>' + dir)<EOL><DEDENT><DEDENT><DEDENT>

Collect all of the batch reports and concatenate the results.  The report should be :

:param input_directory:
:param parameter: This is the parameter in which to report.


with open('<STR_LIT>', '<STR_LIT:w>'):<EOL><INDENT>pass<EOL><DEDENT>

This method will clear the log file by reopening the file for writing.


<EOL>batch_name = '<STR_LIT>'<EOL>p_values = <NUM_LIT>, <NUM_LIT:0.1><EOL>x_value = <NUM_LIT:0.1><EOL>y_value = <NUM_LIT:1.0><EOL>g_value = <NUM_LIT:0.1><EOL>s_value = <NUM_LIT><EOL>z_value = <NUM_LIT:20><EOL>wavelength_values = [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]<EOL>verbose_value = <NUM_LIT:6><EOL>phyto_path = '<STR_LIT>'<EOL>bottom_path = '<STR_LIT>'<EOL>nb_cpu = -<NUM_LIT:1><EOL>exec_path = '<STR_LIT>'<EOL>saa_values = <NUM_LIT><EOL>sza_values = <NUM_LIT>, <NUM_LIT><EOL>report_parameter_value = '<STR_LIT>'<EOL>self.key_array = []<EOL>self.val_array = []<EOL>self.gui_batch = gui.gui_batch.BatchFile(batch_name, p_values, x_value, y_value, g_value, s_value, z_value,<EOL>wavelength_values, verbose_value, phyto_path, bottom_path, nb_cpu,<EOL>exec_path, saa_values, sza_values, report_parameter_value)<EOL>

The following defines defaults values to check if the script transmit them well.


def update_fields(self, x_data, y_data, num_plot):

self.x_data = x_data<EOL>self.y_data = y_data<EOL>self.num_plot = num_plot<EOL>

This function updates data that we need to display curves, from "data_processing" of  "gui_mainLayout" file.
Inputs : x_data : An array with wavelengths.
         y_data : An array with curve's data.
         num_plot : The line, curve to plot.


def display_graphic(self, flag_curves, ui, grid):

matplotlib.patches.Patch(linewidth=<NUM_LIT:100>)<EOL>ui.graphic_widget.canvas.picture.clear()<EOL>x = scipy.linspace(self.x_data[<NUM_LIT:0>], self.x_data[-<NUM_LIT:1>], len(self.x_data))  <EOL>if grid:<EOL><INDENT>ui.graphic_widget.canvas.picture.grid(True)<EOL><DEDENT>curve_wanted = <NUM_LIT:0>  <EOL>for curve in self.y_data:<EOL><INDENT>if flag_curves:<EOL><INDENT>if curve_wanted == self.num_plot:  <EOL><INDENT>ui.graphic_widget.canvas.picture.plot(x, curve, '<STR_LIT>',<EOL>label='<STR_LIT>'.format(str(curve_wanted + <NUM_LIT:1>),<EOL>str(len(self.y_data))),<EOL>linewidth=<NUM_LIT:4>)<EOL><DEDENT>else:<EOL><INDENT>ui.graphic_widget.canvas.picture.plot(x, curve, '<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if curve_wanted == self.num_plot:<EOL><INDENT>ui.graphic_widget.canvas.picture.plot(x, curve, '<STR_LIT>',<EOL>label='<STR_LIT>'.format(str(curve_wanted + <NUM_LIT:1>),<EOL>str(len(self.y_data))))<EOL><DEDENT><DEDENT>curve_wanted += <NUM_LIT:1><EOL><DEDENT>ui.graphic_widget.canvas.picture.set_xlabel('<STR_LIT>')<EOL>ui.graphic_widget.canvas.picture.set_ylabel('<STR_LIT>')<EOL>self.legend = ui.graphic_widget.canvas.picture.legend()  <EOL>ui.graphic_widget.canvas.picture.legend(bbox_to_anchor=(<NUM_LIT>, <NUM_LIT>))<EOL>ui.graphic_widget.canvas.draw()<EOL>

This function plots results of a file into the canvas.
Inputs : flag_curves : A boolean to know if we have to plot all curves or not.
        ui : The main_Window.


self.fig = Figure()<EOL>self.picture = self.fig.add_subplot(<NUM_LIT>)<EOL>FigureCanvas.__init__(self, self.fig)<EOL>self.x_data = []<EOL>self.y_data = [[]]<EOL>self.num_plot = <NUM_LIT:0><EOL>

This function initializes the figure.
Inputs : FigureCanvas : The canvas for the figure.


This function will update data that we need to display curves, from "data_processing" from "gui_mainLayout"
Inputs : x_data : An array with wavelengths.
         y_data : An array with curve's data.
         num_plot : The line, curve to plot.


def display_graphic(self, flag_curves, ui):

ui.graphic_widget.canvas.picture.clear()<EOL>x = scipy.linspace(self.x_data[<NUM_LIT:0>], self.x_data[-<NUM_LIT:1>], len(self.x_data))  <EOL>curve_wanted = <NUM_LIT:0>  <EOL>for curve in self.y_data:<EOL><INDENT>if flag_curves:<EOL><INDENT>if curve_wanted == self.num_plot:  <EOL><INDENT>ui.graphic_widget.canvas.picture.plot(x, curve, '<STR_LIT>',<EOL>label='<STR_LIT>'.format(str(curve_wanted + <NUM_LIT:1>),<EOL>str(len(self.y_data))),<EOL>linewidth=<NUM_LIT:4>)<EOL><DEDENT>else:<EOL><INDENT>ui.graphic_widget.canvas.picture.plot(x, curve, '<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if curve_wanted == self.num_plot:<EOL><INDENT>ui.graphic_widget.canvas.picture.plot(x, curve, '<STR_LIT>',<EOL>label='<STR_LIT>'.format(str(curve_wanted + <NUM_LIT:1>),<EOL>str(len(self.y_data))))<EOL><DEDENT><DEDENT>curve_wanted += <NUM_LIT:1><EOL><DEDENT>ui.graphic_widget.canvas.picture.set_title('<STR_LIT>')<EOL>ui.graphic_widget.canvas.picture.set_xlabel('<STR_LIT>')<EOL>ui.graphic_widget.canvas.picture.set_ylabel('<STR_LIT>')<EOL>self.legend = ui.graphic_widget.canvas.picture.legend()  <EOL>ui.graphic_widget.canvas.picture.legend(bbox_to_anchor=(<NUM_LIT>, <NUM_LIT>))<EOL>ui.graphic_widget.canvas.draw()<EOL>

This function plots results of a file into the canvas.
Inputs : flag_curves : A boolean to know with we have to plot all curves or not.
         ui : The main_Window.


QtGui.QWidget.__init__(self, parent)<EOL>self.canvas = MplCanvas()<EOL>self.vbl = QtGui.QVBoxLayout()<EOL>self.vbl.addWidget(self.canvas)<EOL>self.setLayout(self.vbl)<EOL>

This function initializes the place where the figure will be display.


self.batch_name_value = self.ui.batch_name_value.text()<EOL>self.saa_values = self.ui.saa_values.text()<EOL>self.sza_values = self.ui.sza_values.text()<EOL>self.p_values = self.ui.p_values.text()<EOL>self.x_value = self.ui.x_value.text()<EOL>self.y_value = self.ui.y_value.text()<EOL>self.g_value = self.ui.g_value.text()<EOL>self.s_value = self.ui.s_value.text()<EOL>self.z_value = self.ui.z_value.text()<EOL>self.wavelength_values = self.ui.wavelength_values.text()<EOL>self.verbose_value = self.ui.verbose_value.text()<EOL>self.phytoplankton_path = self.ui.phyto_path.text()<EOL>self.bottom_path = self.ui.bottom_path.text()<EOL>self.executive_path = self.ui.exec_path.text()<EOL>self.nb_cpu = self.ui.nb_cpu.currentText()<EOL>self.report_parameter_value = str(self.ui.report_parameter_value.text())<EOL>

This function gets back data that the user typed.


if self.ui.tabWidget.currentIndex() == TabWidget.NORMAL_MODE:<EOL><INDENT>self.result_file = self.file_dialog.getOpenFileName(caption=str("<STR_LIT>"), directory="<STR_LIT>")<EOL>if not self.result_file == '<STR_LIT>':<EOL><INDENT>self.ui.show_all_curves.setDisabled(False)<EOL>self.ui.show_grid.setDisabled(False)<EOL>self.data_processing()<EOL>self.display_the_graphic(self.num_line, self.wavelength, self.data_wanted, self.information)<EOL>self.authorized_display = True<EOL><DEDENT><DEDENT>

This function once the file found, display data's file and the graphic associated.


error_color = '<STR_LIT>'<EOL>no_error_color = '<STR_LIT>'  <EOL>self.error_batch_name = False<EOL>self.error_report_parameter = False<EOL>self.error_saa_result = False<EOL>self.error_sza_result = False<EOL>self.error_p_result = False<EOL>self.error_wavelength_result = False<EOL>self.error_x_result = False<EOL>self.error_y_result = False<EOL>self.error_g_result = False<EOL>self.error_s_result = False<EOL>self.error_z_result = False<EOL>self.error_verbose_result = False<EOL>self.error_phytoplankton_path_result = False<EOL>self.error_bottom_path_result = False<EOL>self.error_executive_path_result = False<EOL>"""<STR_LIT>"""<EOL>if self.ui.tabWidget.currentIndex() == TabWidget.NORMAL_MODE:<EOL><INDENT>check_num = '<STR_LIT>'  <EOL>self.prog = re.compile(check_num)  <EOL>batch_name_result = self.prog.search(<EOL>self.batch_name_value)  <EOL>report_parameter_result = self.prog.search(self.report_parameter_value)<EOL>try:<EOL><INDENT>if (self.ui.batch_name_value.text().isEmpty()) | (<EOL>batch_name_result.group() != self.ui.batch_name_value.text()):<EOL><INDENT>self.ui.batch_name_label.setStyleSheet(error_color)<EOL>self.error_batch_name = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.batch_name_label.setStyleSheet(no_error_color)<EOL>self.error_batch_name = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.batch_name_label.setStyleSheet(error_color)<EOL>self.error_batch_name = True<EOL><DEDENT>try:<EOL><INDENT>if (self.ui.report_parameter_value.text().isEmpty()) | (<EOL>report_parameter_result.group() != self.ui.report_parameter_value.text()):<EOL><INDENT>self.ui.report_parameter_label.setStyleSheet(error_color)<EOL>self.error_report_parameter = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.report_parameter_label.setStyleSheet(no_error_color)<EOL>self.error_report_parameter = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.report_parameter_label.setStyleSheet(error_color)<EOL>self.error_report_parameter = True<EOL><DEDENT>"""<STR_LIT>"""<EOL>check_num_2 = '<STR_LIT>'<EOL>self.prog_2 = re.compile(check_num_2)<EOL>x_result = self.prog_2.search(self.x_value)<EOL>y_result = self.prog_2.search(self.y_value)<EOL>g_result = self.prog_2.search(self.g_value)<EOL>s_result = self.prog_2.search(self.s_value)<EOL>z_result = self.prog_2.search(self.z_value)<EOL>try:<EOL><INDENT>if x_result.group() != self.ui.x_value.text():<EOL><INDENT>self.ui.particles_label.setStyleSheet(error_color)<EOL>self.ui.x_label.setStyleSheet(error_color)<EOL>self.error_x_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.particles_label.setStyleSheet(no_error_color)<EOL>self.ui.x_label.setStyleSheet(no_error_color)<EOL>self.error_x_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.particles_label.setStyleSheet(no_error_color)<EOL>self.ui.x_label.setStyleSheet(error_color)<EOL>self.error_x_result = True<EOL><DEDENT>try:<EOL><INDENT>if y_result.group() != self.ui.y_value.text():<EOL><INDENT>self.ui.particles_label.setStyleSheet(error_color)<EOL>self.ui.y_label.setStyleSheet(error_color)<EOL>self.error_y_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.particles_label.setStyleSheet(no_error_color)<EOL>self.ui.y_label.setStyleSheet(no_error_color)<EOL>self.error_y_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.particles_label.setStyleSheet(error_color)<EOL>self.ui.y_label.setStyleSheet(error_color)<EOL>self.error_y_result = True<EOL><DEDENT>try:<EOL><INDENT>if g_result.group() != self.ui.g_value.text():<EOL><INDENT>self.ui.organic_label.setStyleSheet(error_color)<EOL>self.ui.g_label.setStyleSheet(error_color)<EOL>self.error_g_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.organic_label.setStyleSheet(no_error_color)<EOL>self.ui.g_label.setStyleSheet(no_error_color)<EOL>self.error_g_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.organic_label.setStyleSheet(error_color)<EOL>self.ui.g_label.setStyleSheet(error_color)<EOL>self.error_g_result = True<EOL><DEDENT>try:<EOL><INDENT>if s_result.group() != self.ui.s_value.text():<EOL><INDENT>self.ui.organic_label.setStyleSheet(error_color)<EOL>self.ui.s_label.setStyleSheet(error_color)<EOL>self.error_s_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.organic_label.setStyleSheet(no_error_color)<EOL>self.ui.s_label.setStyleSheet(no_error_color)<EOL>self.error_x_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.organic_label.setStyleSheet(error_color)<EOL>self.ui.s_label.setStyleSheet(error_color)<EOL>self.error_x_result = True<EOL><DEDENT>try:<EOL><INDENT>if z_result.group() != self.ui.z_value.text():<EOL><INDENT>self.ui.z_label.setStyleSheet(error_color)<EOL>self.error_z_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.z_label.setStyleSheet(no_error_color)<EOL>self.error_z_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.z_label.setStyleSheet(error_color)<EOL>self.error_z_result = True<EOL><DEDENT>check_num_3 = '<STR_LIT>'<EOL>self.prog_3 = re.compile(check_num_3)<EOL>verbose_result = self.prog_3.search(self.verbose_value)<EOL>try:<EOL><INDENT>if verbose_result.group() != self.ui.verbose_value.text():<EOL><INDENT>self.ui.verbose_label.setStyleSheet(error_color)<EOL>self.error_verbose_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.verbose_label.setStyleSheet(no_error_color)<EOL>self.error_verbose_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.verbose_label.setStyleSheet(error_color)<EOL>self.error_verbose_result = True<EOL><DEDENT>"""<STR_LIT>"""<EOL>check_num_4 = '<STR_LIT>'  <EOL>self.prog_4 = re.compile(check_num_4)<EOL>phytoplankton_path_result = self.prog_4.search(self.phytoplankton_path)<EOL>bottom_path_result = self.prog_4.search(self.bottom_path)<EOL>executive_path_result = self.prog_4.search(self.executive_path)<EOL>try:<EOL><INDENT>if phytoplankton_path_result.group() != self.ui.phyto_path.text():<EOL><INDENT>self.ui.phyto_label.setStyleSheet(error_color)<EOL>self.error_phytoplankton_path_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.phyto_label.setStyleSheet(no_error_color)<EOL>self.error_phytoplankton_path_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.phyto_label.setStyleSheet(error_color)<EOL>self.error_phytoplankton_path_result = True<EOL><DEDENT>try:<EOL><INDENT>if bottom_path_result.group() != self.ui.bottom_path.text():<EOL><INDENT>self.ui.bottom_label.setStyleSheet(error_color)<EOL>self.error_bottom_path_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.bottom_label.setStyleSheet(no_error_color)<EOL>self.error_bottom_path_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.bottom_label.setStyleSheet(error_color)<EOL>self.error_bottom_path_result = True<EOL><DEDENT>try:<EOL><INDENT>if executive_path_result.group() != self.ui.exec_path.text():<EOL><INDENT>self.ui.execPath_label.setStyleSheet(error_color)<EOL>self.error_executive_path_result = True<EOL><DEDENT>else:<EOL><INDENT>self.ui.execPath_label.setStyleSheet(no_error_color)<EOL>self.error_executive_path_result = False<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>self.ui.execPath_label.setStyleSheet(error_color)<EOL>self.error_executive_path_result = True<EOL><DEDENT><DEDENT>if (self.error_batch_name == True) | (self.error_report_parameter == True) | (<EOL>self.error_saa_result == True) | (self.error_sza_result == True) | (<EOL>self.error_p_result == True) | (self.error_wavelength_result == True) | (<EOL>self.error_x_result == True) | (self.error_y_result == True) | (<EOL>self.error_g_result == True) | (self.error_s_result == True) | (<EOL>self.error_z_result == True) | (self.error_verbose_result == True) | (<EOL>self.error_phytoplankton_path_result == True) | (self.error_bottom_path_result == True) | (<EOL>self.error_executive_path_result == True):<EOL><INDENT>self.without_error = False<EOL><DEDENT>else:<EOL><INDENT>self.without_error = True<EOL><DEDENT>

This function checks if there is no problem about values given.
If there is a problem with a or some values, their label's color is changed to red,
and call a function to display an error message.
If there is no problem, their label, if it is necessary, is changed to grey (default color).


bt = BatchFile(self.batch_name_value, self.p_values, self.x_value, self.y_value, self.g_value, self.s_value,<EOL>self.z_value, self.wavelength_values, self.verbose_value, self.phytoplankton_path,<EOL>self.bottom_path, self.nb_cpu, self.executive_path, self.saa_values,<EOL>self.sza_values, self.report_parameter_value)<EOL>bt.write_batch_to_file(str(self.batch_name_value + "<STR_LIT>"))<EOL>

This function calls "gui_batch.py" with inputs values to write the batch file.


the_file_name = str(self.result_file)<EOL>the_file = open(the_file_name, '<STR_LIT:r>')<EOL>lines = the_file.readlines()<EOL>lines_array = []<EOL>for line in lines:<EOL><INDENT>line = line.split('<STR_LIT:U+002C>')  <EOL>lines_array.append(line)<EOL><DEDENT>labels_line = lines_array[<NUM_LIT:0>]<EOL>cell_labels_line = <NUM_LIT:0>  <EOL>flag = True  <EOL>try:<EOL><INDENT>while flag:  <EOL><INDENT>if "<STR_LIT>" in labels_line[cell_labels_line]:<EOL><INDENT>index = labels_line.index(labels_line[cell_labels_line])  <EOL>flag = False<EOL><DEDENT>else:<EOL><INDENT>cell_labels_line += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>except IndexError:  <EOL><INDENT>raise sys.exit("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self.information = []  <EOL>data_wavelength = []  <EOL>self.num_line = <NUM_LIT:0>  <EOL>for line in lines_array:<EOL><INDENT>cell_line = <NUM_LIT:0>  <EOL>self.information.append([])<EOL>data_wavelength.append([])<EOL>while cell_line < len(line):<EOL><INDENT>if cell_line < index:<EOL><INDENT>self.information[self.num_line].append(line[cell_line])<EOL><DEDENT>elif cell_line > index:<EOL><INDENT>data_wavelength[self.num_line].append(line[cell_line])<EOL><DEDENT>cell_line += <NUM_LIT:1><EOL><DEDENT>self.num_line += <NUM_LIT:1><EOL><DEDENT>line_wavelength = <NUM_LIT:0>  <EOL>for row_data_wavelength in data_wavelength:<EOL><INDENT>row_data_wavelength = [float(item.strip('<STR_LIT:\n>').strip('<STR_LIT>')) for item in row_data_wavelength]<EOL>data_wavelength[line_wavelength] = row_data_wavelength<EOL>line_wavelength += <NUM_LIT:1><EOL><DEDENT>self.wavelength = data_wavelength[<NUM_LIT:0>]  <EOL>self.data_wanted = data_wavelength[<NUM_LIT:1>:]  <EOL>the_file.close()<EOL>

This function separates data, from the file to display curves, and will put them in the good arrays.


def display_the_graphic(self, num_line, wavelength, data_wanted, information):

self.nb_case = num_line - <NUM_LIT:1>  <EOL>self.graphic_slider(self.nb_case)<EOL>self.mpl_canvas.update_fields(wavelength, data_wanted, self.slider_value)<EOL>if self.ui.show_grid.checkState() == <NUM_LIT:2>:<EOL><INDENT>grid = True<EOL><DEDENT>else:<EOL><INDENT>grid = False<EOL><DEDENT>if self.ui.show_all_curves.checkState() == <NUM_LIT:2>:<EOL><INDENT>self.flag_curves = True<EOL>self.mpl_canvas.display_graphic(self.flag_curves, self.ui, grid)<EOL>self.print_graphic_information(self.slider_value, information)<EOL><DEDENT>else:<EOL><INDENT>self.flag_curves = False<EOL>self.mpl_canvas.display_graphic(self.flag_curves, self.ui, grid)<EOL>self.print_graphic_information(self.slider_value, information)<EOL><DEDENT>

This function calls the class "MplCanvas" of "gui_matplotlibwidgetFile.py" to plot results.
Inputs : num_line : The number of cases.
         wavelength : The wavelengths.
         data_wanted : The data for wavelengths.
         information : The array which contains the information, of all curves to display.


self.display_the_graphic(self.num_line, self.wavelength, self.data_wanted, self.information)<EOL>

The following permits to attribute the function "display_the_graphic" to the slider.
Because, to make a connection, we can not have parameters for the function, but "display_the_graphic" has some.


def print_graphic_information(self, num_curve, information):

This function displays information about curves.
Inputs ; num_curve ; The index of the curve's line that we have to display.
         information ; The array which contains the information, of all curves to display.


"""<STR_LIT>"""<EOL>self.ui.sens.setDisabled(False)<EOL>self.ui.sens.setRange(<NUM_LIT:0>, int(nb_case - <NUM_LIT:1>))<EOL>self.slider_value = self.ui.sens.value()<EOL>return self.slider_value<EOL>

This function scales the slider for curves displayed.
Input : The number of cases (curves).
Return ; The slider value.


self.ui.error_label.setScaledContents(True)  <EOL>self.ui.error_text_label.show()  <EOL>self.ui.error_text_label.setStyleSheet('<STR_LIT>')<EOL>

This function displays an error message when a wrong value is typed.


self.ui.error_label.setScaledContents(False)  <EOL>self.ui.error_text_label.hide()<EOL>

This function hides the error message when all values are correct.


"""<STR_LIT>"""<EOL>print('<STR_LIT>')<EOL>if self.ui.tabWidget.currentIndex() == TabWidget.NORMAL_MODE:<EOL><INDENT>self.data()<EOL>self.check_values()<EOL>if self.without_error == False:<EOL><INDENT>self.display_error_message()<EOL><DEDENT>elif self.without_error == True:<EOL><INDENT>self.is_running = True<EOL>self.hide_error_message()<EOL>self.write_to_file()<EOL>os.chdir('<STR_LIT>')<EOL>self.progress_bar()<EOL>this_dir = os.path.dirname(os.path.realpath(__file__)).rstrip('<STR_LIT>')<EOL>batch_file = os.path.join(this_dir, "<STR_LIT>" + str(self.batch_name_value) + "<STR_LIT>")<EOL>print(batch_file)<EOL>self.p = subprocess.Popen(<EOL>["<STR_LIT>" + batch_file],<EOL>shell=True)<EOL>if self.ui.progressBar.value() == <NUM_LIT:100>:<EOL><INDENT>self.display_the_graphic(self.num_line, self.wavelength, self.data_wanted, self.information)<EOL><DEDENT><DEDENT><DEDENT>

This function executes planarRad using the batch file.


self.ui.progressBar.setMaximum(total)<EOL>

This function sets the progress bar with its maximum.


self.t.start()<EOL>

This function starts the thread created for the progress bar. Without it, the GUI will freeze..


"""<STR_LIT>"""<EOL>if (self.is_running == True) & (self.ui.tabWidget.currentIndex() == TabWidget.NORMAL_MODE):<EOL><INDENT>cancel = QtGui.QMessageBox.question(self.ui.cancel, '<STR_LIT>', "<STR_LIT>",<EOL>QtGui.QMessageBox.Yes,<EOL>QtGui.QMessageBox.No)<EOL>if cancel == QtGui.QMessageBox.Yes:<EOL><INDENT>self.is_running = False<EOL>os.kill(self.p.pid, signal.SIGTERM)<EOL>print("<STR_LIT>")<EOL>self.ui.progressBar.reset()<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>


"""<STR_LIT>"""<EOL>if self.is_running == True:<EOL><INDENT>warning_planarrad_running = QtGui.QMessageBox.warning(self.ui.quit, '<STR_LIT>',<EOL>"<STR_LIT>",<EOL>QtGui.QMessageBox.Ok)<EOL><DEDENT>else:<EOL><INDENT>quit = QtGui.QMessageBox.question(self.ui.quit, '<STR_LIT>', "<STR_LIT>",<EOL>QtGui.QMessageBox.Yes,<EOL>QtGui.QMessageBox.No)<EOL>if quit == QtGui.QMessageBox.Yes:<EOL><INDENT>QtGui.qApp.quit()<EOL><DEDENT><DEDENT>

This function quits PlanarRad, checking if PlanarRad is running before.


"""<STR_LIT>"""<EOL>default_name = '<STR_LIT>'<EOL>self.ui.graphic_widget.canvas.print_figure(default_name)<EOL>src = '<STR_LIT>' + default_name<EOL>dst = '<STR_LIT>'<EOL>os.system("<STR_LIT>" + "<STR_LIT:U+0020>" + src + "<STR_LIT:U+0020>" + dst)<EOL>

This function programs the button to save the figure displayed
and save it in a png file in the current repository.


self.file_name = QtGui.QFileDialog.getSaveFileName()<EOL>self.file_name = self.file_name + "<STR_LIT>"<EOL>self.ui.graphic_widget.canvas.print_figure(str(self.file_name))<EOL>

This function programs the button to save the figure displayed
and save it in a png file where you want / with the name you want thanks to a file dialog.


self.aboutWindow.show()<EOL>

This function opens the default browser and go on the web page about planarRad and its GUI.


"""<STR_LIT>"""<EOL>f = open(os.path.expanduser('<STR_LIT>'))<EOL>self.uiLog.textEdit.setPlainText(str(f.read()))<EOL>self.log_window.show()<EOL>

The following opens the log file of PlanarRad.


"""<STR_LIT>"""<EOL>window = Window()<EOL>html = QtCore.QUrl.fromLocalFile(os.path.join(os.getcwd(), '<STR_LIT>')) <EOL>window.view.load(html)<EOL>window.show()<EOL>window.exec_()<EOL>

The following opens the documentation file.


self.hide_error_message()<EOL>self.ui.show_all_curves.setDisabled(True)<EOL>self.ui.sens.setDisabled(True)<EOL>self.ui.show_grid.setDisabled(True)<EOL>pathname = os.path.dirname(sys.argv[<NUM_LIT:0>])<EOL>path = os.path.abspath(pathname)<EOL>self.verbose_value = self.ui.verbose_value.setText("<STR_LIT>")<EOL>self.report_parameter_value = self.ui.report_parameter_value.setText("<STR_LIT>")<EOL>self.ui.progressBar.reset()<EOL>

This function does all required actions at the beginning when we run the GUI.


reply = QtGui.QMessageBox.question(self, '<STR_LIT>',<EOL>"<STR_LIT>", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)<EOL>if reply == QtGui.QMessageBox.Yes:<EOL><INDENT>event.accept()<EOL><DEDENT>else:<EOL><INDENT>event.ignore()<EOL><DEDENT>

The following asks to the user if he is sure to quit the GUI.


if event.button == <NUM_LIT:3>:<EOL><INDENT>if self.ui.tabWidget.currentIndex() == TabWidget.NORMAL_MODE:<EOL><INDENT>self.pos = QtGui.QCursor().pos()<EOL>self.graphic_context_menu(self.pos)<EOL><DEDENT><DEDENT>

This function intercepts the mouse's right click and its position.


if (self.ui.tabWidget.currentIndex() == TabWidget.NORMAL_MODE):<EOL><INDENT>self.posX = event.xdata<EOL>self.posY = event.ydata<EOL>self.graphic_target(self.posX, self.posY)<EOL><DEDENT>

The following gets back coordinates of the mouse on the canvas.


menu = QtGui.QMenu()<EOL>self.actionSave_bis = menu.addAction("<STR_LIT>")<EOL>self.actionSave_as_bis = menu.addAction("<STR_LIT>")<EOL>action = menu.exec_(self.table_widget.mapFromGlobal(pos))<EOL>if action == self.actionSave_bis:<EOL><INDENT>self.save_figure()<EOL><DEDENT>elif action == self.actionSave_as_bis:<EOL><INDENT>self.save_figure_as()<EOL><DEDENT>

This function will open a context menu on the graphic to save it.
Inputs : pos : The position of the mouse cursor.


if self.authorized_display == True:<EOL><INDENT>try:<EOL><INDENT>self.display_the_graphic(self.num_line, self.wavelength, self.data_wanted, self.information)<EOL>self.ui.mouse_coordinate.setText("<STR_LIT>" % (x, y))<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

The following update labels about mouse coordinates.


menu_title = menu_data['<STR_LIT:title>']<EOL>menu = CursesMenu(menu_title)<EOL>for item in menu_data["<STR_LIT>"]:<EOL><INDENT>item_type = item["<STR_LIT:type>"]<EOL>item_title = item["<STR_LIT:title>"]<EOL>if item_type == menuItem.COMMAND:<EOL><INDENT>item_command = item["<STR_LIT>"]<EOL>menu.append_item(CommandItem(item_title, item_command, menu))<EOL><DEDENT>elif item_type == menuItem.FUNCTION:<EOL><INDENT>item_function = item["<STR_LIT>"]<EOL>menu.append_item(FunctionItem(item_title, item_function, menu))<EOL><DEDENT>elif item_type == menuItem.EXITMENU:<EOL><INDENT>menu.append_item(ExitItem(item_title, menu))<EOL><DEDENT>elif item_type == menuItem.NUMBER:<EOL><INDENT>menu.append_item(SelectionItem(item_title, menu))<EOL><DEDENT>elif item_type == menuItem.MENU:<EOL><INDENT>new_menu = parse_old_menu(item)<EOL>menu.append_item(SubmenuItem(item_title, menu, new_menu))<EOL><DEDENT><DEDENT>return menu<EOL>

Take an old-style menuData dictionary and return a CursesMenu

:param dict menu_data:
:return: A new CursesMenu
:rtype: CursesMenu


if platform.system().lower() == "<STR_LIT>":<EOL><INDENT>os.system('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>os.system('<STR_LIT>')<EOL><DEDENT>

Call the platform specific function to clear the terminal: cls on windows, reset otherwise


def __init__(self, title=None, subtitle=None, show_exit_option=True):

self.screen = None<EOL>self.highlight = None<EOL>self.normal = None<EOL>self.title = title<EOL>self.subtitle = subtitle<EOL>self.show_exit_option = show_exit_option<EOL>self.items = list()<EOL>self.parent = None<EOL>self.exit_item = ExitItem(menu=self)<EOL>self.current_option = <NUM_LIT:0><EOL>self.selected_option = -<NUM_LIT:1><EOL>self.returned_value = None<EOL>self.should_exit = False<EOL>self.previous_active_menu = None<EOL>self._main_thread = None<EOL>self._running = threading.Event()<EOL>

:ivar str title: The title of the menu
:ivar str subtitle: The subtitle of the menu
:ivar bool show_exit_option: Whether this menu should show an exit item by default. Can be overridden \
when the menu is started
:ivar items: The list of MenuItems that the menu will display
:vartype items: list[:class:`MenuItem<cursesmenu.items.MenuItem>`]
:ivar CursesMenu parent: The parent of this menu
:ivar CursesMenu previous_active_menu: the previously active menu to be restored into the class's \
currently active menu
:ivar int current_option: The currently highlighted menu option
:ivar MenuItem current_item: The item corresponding to the menu option that is currently highlighted
:ivar int selected_option: The option that the user has most recently selected
:ivar MenuItem selected_item: The item in :attr:`items` that the user most recently selected
:ivar returned_value: The value returned by the most recently selected item
:ivar screen: the curses window associated with this menu
:ivar normal: the normal text color pair for this menu
:ivar highlight: the highlight color pair associated with this window


if self.items:<EOL><INDENT>return self.items[self.current_option]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>


if self.items and self.selected_option != -<NUM_LIT:1>:<EOL><INDENT>return self.items[self.current_option]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>


did_remove = self.remove_exit()<EOL>item.menu = self<EOL>self.items.append(item)<EOL>if did_remove:<EOL><INDENT>self.add_exit()<EOL><DEDENT>if self.screen:<EOL><INDENT>max_row, max_cols = self.screen.getmaxyx()<EOL>if max_row < <NUM_LIT:6> + len(self.items):<EOL><INDENT>self.screen.resize(<NUM_LIT:6> + len(self.items), max_cols)<EOL><DEDENT>self.draw()<EOL><DEDENT>

Add an item to the end of the menu before the exit item

:param MenuItem item: The item to be added


if self.items:<EOL><INDENT>if self.items[-<NUM_LIT:1>] is not self.exit_item:<EOL><INDENT>self.items.append(self.exit_item)<EOL>return True<EOL><DEDENT><DEDENT>return False<EOL>

Add the exit item if necessary. Used to make sure there aren't multiple exit items

:return: True if item needed to be added, False otherwise
:rtype: bool


if self.items:<EOL><INDENT>if self.items[-<NUM_LIT:1>] is self.exit_item:<EOL><INDENT>del self.items[-<NUM_LIT:1>]<EOL>return True<EOL><DEDENT><DEDENT>return False<EOL>

Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else

:return: True if item needed to be removed, False otherwise
:rtype: bool


self.previous_active_menu = CursesMenu.currently_active_menu<EOL>CursesMenu.currently_active_menu = None<EOL>self.should_exit = False<EOL>if show_exit_option is None:<EOL><INDENT>show_exit_option = self.show_exit_option<EOL><DEDENT>if show_exit_option:<EOL><INDENT>self.add_exit()<EOL><DEDENT>else:<EOL><INDENT>self.remove_exit()<EOL><DEDENT>try:<EOL><INDENT>self._main_thread = threading.Thread(target=self._wrap_start, daemon=True)<EOL><DEDENT>except TypeError:<EOL><INDENT>self._main_thread = threading.Thread(target=self._wrap_start)<EOL>self._main_thread.daemon = True<EOL><DEDENT>self._main_thread.start()<EOL>

Start the menu in a new thread and allow the user to interact with it.
The thread is a daemon, so :meth:`join()<cursesmenu.CursesMenu.join>` should be called if there's a possibility\
that the main thread will exit before the menu is done

:param bool show_exit_option: Whether the exit item should be shown, defaults to\
the value set in the constructor


self.start(show_exit_option)<EOL>self.join()<EOL>

Calls start and then immediately joins.

:param bool show_exit_option: Whether the exit item should be shown, defaults to the value set \
in the constructor


self.screen.border(<NUM_LIT:0>)<EOL>if self.title is not None:<EOL><INDENT>self.screen.addstr(<NUM_LIT:2>, <NUM_LIT:2>, self.title, curses.A_STANDOUT)<EOL><DEDENT>if self.subtitle is not None:<EOL><INDENT>self.screen.addstr(<NUM_LIT:4>, <NUM_LIT:2>, self.subtitle, curses.A_BOLD)<EOL><DEDENT>for index, item in enumerate(self.items):<EOL><INDENT>if self.current_option == index:<EOL><INDENT>text_style = self.highlight<EOL><DEDENT>else:<EOL><INDENT>text_style = self.normal<EOL><DEDENT>self.screen.addstr(<NUM_LIT:5> + index, <NUM_LIT:4>, item.show(index), text_style)<EOL><DEDENT>screen_rows, screen_cols = CursesMenu.stdscr.getmaxyx()<EOL>top_row = <NUM_LIT:0><EOL>if <NUM_LIT:6> + len(self.items) > screen_rows:<EOL><INDENT>if screen_rows + self.current_option < <NUM_LIT:6> + len(self.items):<EOL><INDENT>top_row = self.current_option<EOL><DEDENT>else:<EOL><INDENT>top_row = <NUM_LIT:6> + len(self.items) - screen_rows<EOL><DEDENT><DEDENT>self.screen.refresh(top_row, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, screen_rows - <NUM_LIT:1>, screen_cols - <NUM_LIT:1>)<EOL>

Redraws the menu and refreshes the screen. Should be called whenever something changes that needs to be redrawn.


return self._running.is_set()<EOL>

:return: True if the menu is started and hasn't been paused


return self._running.wait(timeout)<EOL>

Block until the menu is started

:param timeout: How long to wait before timing out
:return: False if timeout is given and operation times out, True otherwise. None before Python 2.7


return self._main_thread.is_alive()<EOL>

:return: True if the thread is still alive, False otherwise


Temporarily pause the menu until resume is called


CursesMenu.currently_active_menu = self<EOL>self._running.set()<EOL>

Sets the currently active menu to this one and resumes it


self._main_thread.join(timeout=timeout)<EOL>

Should be called at some point after :meth:`start()<cursesmenu.CursesMenu.start>` to block until the menu exits.
:param Number timeout: How long to wait before timing out


return CursesMenu.stdscr.getch()<EOL>

Can be overridden to change the input method.
Called in :meth:`process_user_input()<cursesmenu.CursesMenu.process_user_input>`

:return: the ordinal value of a single character
:rtype: int


user_input = self.get_input()<EOL>go_to_max = ord("<STR_LIT>") if len(self.items) >= <NUM_LIT:9> else ord(str(len(self.items)))<EOL>if ord('<STR_LIT:1>') <= user_input <= go_to_max:<EOL><INDENT>self.go_to(user_input - ord('<STR_LIT:0>') - <NUM_LIT:1>)<EOL><DEDENT>elif user_input == curses.KEY_DOWN:<EOL><INDENT>self.go_down()<EOL><DEDENT>elif user_input == curses.KEY_UP:<EOL><INDENT>self.go_up()<EOL><DEDENT>elif user_input == ord("<STR_LIT:\n>"):<EOL><INDENT>self.select()<EOL><DEDENT>return user_input<EOL>

Gets the next single character and decides what to do with it


self.current_option = option<EOL>self.draw()<EOL>

Go to the option entered by the user as a number

:param option: the option to go to
:type option: int


if self.current_option < len(self.items) - <NUM_LIT:1>:<EOL><INDENT>self.current_option += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self.current_option = <NUM_LIT:0><EOL><DEDENT>self.draw()<EOL>

Go down one, wrap to beginning if necessary


if self.current_option > <NUM_LIT:0>:<EOL><INDENT>self.current_option += -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self.current_option = len(self.items) - <NUM_LIT:1><EOL><DEDENT>self.draw()<EOL>


self.selected_option = self.current_option<EOL>self.selected_item.set_up()<EOL>self.selected_item.action()<EOL>self.selected_item.clean_up()<EOL>self.returned_value = self.selected_item.get_return()<EOL>self.should_exit = self.selected_item.should_exit<EOL>if not self.should_exit:<EOL><INDENT>self.draw()<EOL><DEDENT>


self.should_exit = True<EOL>self.join()<EOL>

Signal the menu to exit, then block until it's done cleaning up


self.screen.clear()<EOL>


def __init__(self, text, menu=None, should_exit=False):

self.text = text<EOL>self.menu = menu<EOL>self.should_exit = should_exit<EOL>

:ivar str text: The text shown for this menu item
:ivar CursesMenu menu: The menu to which this item belongs
:ivar bool should_exit: Whether the menu should exit once this item's action is done


return "<STR_LIT>" % (index + <NUM_LIT:1>, self.text)<EOL>

How this item should be displayed in the menu. Can be overridden, but should keep the same signature.

Default is:

    1 - Item 1

    2 - Another Item

:param int index: The index of the item in the items list of the menu
:return: The representation of the item to be shown in a menu
:rtype: str


pass<EOL>

Override to add any setup actions necessary for the item


pass<EOL>

Override to carry out the main action for this item.


pass<EOL>

Override to add any cleanup actions necessary for the item


return self.menu.returned_value<EOL>

Override to change what the item returns.
Otherwise just returns the same value the last selected item did.


if self.menu and self.menu.parent:<EOL><INDENT>self.text = "<STR_LIT>" % self.menu.parent.title<EOL><DEDENT>else:<EOL><INDENT>self.text = "<STR_LIT>"<EOL><DEDENT>return super(ExitItem, self).show(index)<EOL>


def __init__(self, strings, title=None, subtitle=None, show_exit_option=True):

super(SelectionMenu, self).__init__(title, subtitle, show_exit_option)<EOL>for index, item in enumerate(strings):<EOL><INDENT>self.append_item(SelectionItem(item, index, self))<EOL><DEDENT>

:ivar list[str] strings: The list of strings this menu should be built from


@classmethod<EOL><INDENT>def get_selection(cls, strings, title="<STR_LIT>", subtitle=None, exit_option=True, _menu=None):<DEDENT>

menu = cls(strings, title, subtitle, exit_option)<EOL>if _menu is not None:<EOL><INDENT>_menu.append(menu)<EOL><DEDENT>menu.show()<EOL>menu.join()<EOL>return menu.selected_option<EOL>

Single-method way of getting a selection out of a list of strings

:param list[str] strings: the list of string used to build the menu
:param list _menu: should probably only be used for testing, pass in a list and the created menu used \
internally by the method will be appended to it


def __init__(self, text, function, args=None, kwargs=None, menu=None, should_exit=False):

super(FunctionItem, self).__init__(text=text, menu=menu, should_exit=should_exit)<EOL>self.function = function<EOL>if args is not None:<EOL><INDENT>self.args = args<EOL><DEDENT>else:<EOL><INDENT>self.args = []<EOL><DEDENT>if kwargs is not None:<EOL><INDENT>self.kwargs = kwargs<EOL><DEDENT>else:<EOL><INDENT>self.kwargs = {}<EOL><DEDENT>self.return_value = None<EOL>

:ivar function: The function to be called
:ivar list args: An optional list of arguments to be passed to the function
:ivar dict kwargs: An optional dictionary of keyword arguments to be passed to the function
:ivar return_value: the value returned by the function, None if it hasn't been called yet.


self.return_value = self.function(*self.args, **self.kwargs)<EOL>


return self.return_value<EOL>

:return: The return value from the function call


def __init__(self, text, command, arguments=None, menu=None, should_exit=False):

super(CommandItem, self).__init__(text=text, menu=menu, should_exit=should_exit)<EOL>self.command = command<EOL>if arguments:<EOL><INDENT>self.arguments = arguments<EOL><DEDENT>else:<EOL><INDENT>self.arguments = []<EOL><DEDENT>self.exit_status = None<EOL>

:ivar str command: The console command to be executed
:ivar list[str] arguments: An optional list of string arguments to be passed to the command
:ivar int exit_status: the exit status of the command, None if it hasn't been run yet


commandline = "<STR_LIT>".format(self.command, "<STR_LIT:U+0020>".join(self.arguments))<EOL>try:<EOL><INDENT>completed_process = subprocess.run(commandline, shell=True)<EOL>self.exit_status = completed_process.returncode<EOL><DEDENT>except AttributeError:<EOL><INDENT>self.exit_status = subprocess.call(commandline, shell=True)<EOL><DEDENT>


return self.exit_status<EOL>

:return: the exit status of the command
:rtype: int


def __init__(self, text, index, menu=None):

super(SelectionItem, self).__init__(text=text, menu=menu, should_exit=True)<EOL>self.index = index<EOL>

:ivar int index: The index of this item in the list used to initialize the :class:`cursesmenu.SelectionMenu`


return self.index<EOL>

:return: The index of this item in the list of strings
:rtype: int


self.menu.pause()<EOL>curses.def_prog_mode()<EOL>clear_terminal()<EOL>self.menu.clear_screen()<EOL>


self.menu.clear_screen()<EOL>curses.reset_prog_mode()<EOL>curses.curs_set(<NUM_LIT:1>)  <EOL>curses.curs_set(<NUM_LIT:0>)<EOL>self.menu.resume()<EOL>


def __init__(self, text, submenu, menu=None, should_exit=False):

super(SubmenuItem, self).__init__(text=text, menu=menu, should_exit=should_exit)<EOL>self.submenu = submenu<EOL>if menu:<EOL><INDENT>self.submenu.parent = menu<EOL><DEDENT>

:ivar CursesMenu self.submenu: The submenu to be opened when this item is selected


self.menu = menu<EOL>self.submenu.parent = menu<EOL>

Sets the menu of this item.
Should be used instead of directly accessing the menu attribute for this class.

:param CursesMenu menu: the menu


self.menu.pause()<EOL>curses.def_prog_mode()<EOL>self.menu.clear_screen()<EOL>


self.submenu.start()<EOL>


self.submenu.join()<EOL>self.menu.clear_screen()<EOL>curses.reset_prog_mode()<EOL>curses.curs_set(<NUM_LIT:1>)  <EOL>curses.curs_set(<NUM_LIT:0>)<EOL>self.menu.resume()<EOL>


return self.submenu.returned_value<EOL>

:return: The returned value in the submenu


fn_arg_list = (list(fn_arg_list) if mcmc_util.is_list_like(fn_arg_list)<EOL>else [fn_arg_list])<EOL>if fn_result is None:<EOL><INDENT>fn_result = fn(*fn_arg_list)<EOL><DEDENT>if not fn_result.dtype.is_floating:<EOL><INDENT>raise TypeError('<STR_LIT>'.format(<EOL>description))<EOL><DEDENT>return fn_result<EOL>

Helper which computes `fn_result` if needed.


def _prepare_args(log_likelihood_fn, state,<EOL>log_likelihood=None, description='<STR_LIT>'):

state_parts = list(state) if mcmc_util.is_list_like(state) else [state]<EOL>state_parts = [tf.convert_to_tensor(s, name='<STR_LIT>')<EOL>for s in state_parts]<EOL>log_likelihood = _maybe_call_fn(<EOL>log_likelihood_fn,<EOL>state_parts,<EOL>log_likelihood,<EOL>description)<EOL>return [state_parts, log_likelihood]<EOL>

Processes input args to meet list-like assumptions.


self._seed_stream = distributions.SeedStream(<EOL>seed, salt='<STR_LIT>')<EOL>self._parameters = dict(<EOL>normal_sampler_fn=normal_sampler_fn,<EOL>log_likelihood_fn=log_likelihood_fn,<EOL>seed=seed,<EOL>name=name)<EOL>

Initializes this transition kernel.

        Args:
          normal_sampler_fn: Python callable that takes in a seed and returns a
            sample from a multivariate normal distribution. Note that the shape of
            the samples must agree with `log_likelihood_fn`.
          log_likelihood_fn: Python callable which takes an argument like
            `current_state` (or `*current_state` if it is a list) and returns its
            (possibly unnormalized) log-likelihood.
          seed: Python integer to seed the random number generator.
          name: Python `str` name prefixed to Ops created by this function.
            Default value: `None` (i.e., 'slice_sampler_kernel').

        Returns:
          next_state: Tensor or Python list of `Tensor`s representing the state(s)
            of the Markov chain(s) at each result step. Has same shape as
            `current_state`.
          kernel_results: `collections.namedtuple` of internal calculations used to
            advance the chain.


return self._parameters<EOL>

Returns `dict` of ``__init__`` arguments and their values.


def one_step(self, current_state, previous_kernel_results):

with tf.compat.v1.name_scope(<EOL>name=mcmc_util.make_name(self.name, '<STR_LIT>', '<STR_LIT>'),<EOL>values=[self._seed_stream,<EOL>current_state,<EOL>previous_kernel_results.log_likelihood]):<EOL><INDENT>with tf.compat.v1.name_scope('<STR_LIT>'):<EOL><INDENT>[<EOL>init_state_parts,<EOL>init_log_likelihood<EOL>] = _prepare_args(<EOL>self.log_likelihood_fn,<EOL>current_state,<EOL>previous_kernel_results.log_likelihood)<EOL><DEDENT>normal_samples = self.normal_sampler_fn(self._seed_stream())  <EOL>normal_samples = list(normal_samples) if mcmc_util.is_list_like(<EOL>normal_samples) else [normal_samples]<EOL>u = tf.random.uniform(<EOL>shape=tf.shape(init_log_likelihood),<EOL>seed=self._seed_stream(),<EOL>dtype=init_log_likelihood.dtype.base_dtype,<EOL>)<EOL>threshold = init_log_likelihood + tf.math.log(u)<EOL>starting_angle = tf.random.uniform(<EOL>shape=tf.shape(init_log_likelihood),<EOL>minval=<NUM_LIT:0.>,<EOL>maxval=<NUM_LIT:2> * np.pi,<EOL>name='<STR_LIT>',<EOL>seed=self._seed_stream(),<EOL>dtype=init_log_likelihood.dtype.base_dtype,<EOL>)<EOL>starting_angle_min = starting_angle - <NUM_LIT:2> * np.pi<EOL>starting_angle_max = starting_angle<EOL>starting_state_parts = _rotate_on_ellipse(<EOL>init_state_parts, normal_samples, starting_angle)<EOL>starting_log_likelihood = self.log_likelihood_fn(*starting_state_parts)  <EOL>def chain_not_done(<EOL>angle,<EOL>angle_min,<EOL>angle_max,<EOL>current_state_parts,<EOL>current_log_likelihood):<EOL><INDENT>del angle, angle_min, angle_max, current_state_parts<EOL>return tf.reduce_any(current_log_likelihood < threshold)<EOL><DEDENT>def sample_next_angle(<EOL>angle,<EOL>angle_min,<EOL>angle_max,<EOL>current_state_parts,<EOL>current_log_likelihood):<EOL><INDENT>"""<STR_LIT>"""<EOL>chain_not_done = current_log_likelihood < threshold<EOL>angle_min = tf.where(<EOL>tf.math.logical_and(angle < <NUM_LIT:0>, chain_not_done),<EOL>angle,<EOL>angle_min)<EOL>angle_max = tf.where(<EOL>tf.math.logical_and(angle >= <NUM_LIT:0>, chain_not_done),<EOL>angle,<EOL>angle_max)<EOL>new_angle = tf.random.uniform(<EOL>shape=tf.shape(current_log_likelihood),<EOL>minval=angle_min,<EOL>maxval=angle_max,<EOL>seed=self._seed_stream(),<EOL>dtype=angle.dtype.base_dtype<EOL>)<EOL>angle = tf.where(chain_not_done, new_angle, angle)<EOL>next_state_parts = _rotate_on_ellipse(<EOL>init_state_parts, normal_samples, angle)<EOL>new_state_parts = []<EOL>broadcasted_chain_not_done = _right_pad_with_ones(<EOL>chain_not_done, tf.rank(next_state_parts[<NUM_LIT:0>]))<EOL>for n_state, c_state in zip(next_state_parts, current_state_parts):<EOL><INDENT>new_state_part = tf.where(<EOL>tf.broadcast_to(<EOL>broadcasted_chain_not_done,<EOL>tf.shape(n_state)),<EOL>n_state,<EOL>c_state)<EOL>new_state_parts.append(new_state_part)<EOL><DEDENT>return (<EOL>angle,<EOL>angle_min,<EOL>angle_max,<EOL>new_state_parts,<EOL>self.log_likelihood_fn(*new_state_parts)  <EOL>)<EOL><DEDENT>[<EOL>next_angle,<EOL>_,<EOL>_,<EOL>next_state_parts,<EOL>next_log_likelihood,<EOL>] = tf.while_loop(<EOL>cond=chain_not_done,<EOL>body=sample_next_angle,<EOL>loop_vars=[<EOL>starting_angle,<EOL>starting_angle_min,<EOL>starting_angle_max,<EOL>starting_state_parts,<EOL>starting_log_likelihood<EOL>])<EOL>return [<EOL>next_state_parts if mcmc_util.is_list_like(<EOL>current_state) else next_state_parts[<NUM_LIT:0>],<EOL>EllipticalSliceSamplerKernelResults(<EOL>log_likelihood=next_log_likelihood,<EOL>angle=next_angle,<EOL>normal_samples=normal_samples,<EOL>),<EOL>]<EOL><DEDENT>

Runs one iteration of the Elliptical Slice Sampler.

        Args:
          current_state: `Tensor` or Python `list` of `Tensor`s representing the
            current state(s) of the Markov chain(s). The first `r` dimensions
            index independent chains,
            `r = tf.rank(log_likelihood_fn(*normal_sampler_fn()))`.
          previous_kernel_results: `collections.namedtuple` containing `Tensor`s
            representing values from previous calls to this function (or from the
            `bootstrap_results` function.)

        Returns:
          next_state: Tensor or Python list of `Tensor`s representing the state(s)
            of the Markov chain(s) after taking exactly one step. Has same type and
            shape as `current_state`.
          kernel_results: `collections.namedtuple` of internal calculations used to
            advance the chain.

        Raises:
          TypeError: if `not log_likelihood.dtype.is_floating`.


num_samples = int(data.shape[<NUM_LIT:0>])<EOL>posterior_variance = <NUM_LIT:1> / (<EOL><NUM_LIT:1> / prior_stddev ** <NUM_LIT:2> + num_samples / likelihood_stddev ** <NUM_LIT:2>)<EOL>data_mean = np.mean(data, axis=<NUM_LIT:0>)<EOL>posterior_mean = posterior_variance * (<EOL>prior_mean / prior_stddev ** <NUM_LIT:2> +<EOL>num_samples * data_mean / likelihood_stddev ** <NUM_LIT:2>)<EOL>return posterior_mean, posterior_variance<EOL>

r"""Returns the posterior mean and variance of a normal-normal model.

    Given a normal likelihood and a normal prior on the mean, return the
    posterior mean and variance. In this model, the posterior distribution is
    normally distributed and can be computed easily from a formula.

    ```
    p(mu | mu0, sigma0) ~ N(mu0, sigma0)
    p(x | mu, sigma) ~ N(mu, sigma)
    p(mu | x, mu0, sigma0) \proportional p(x | mu, sigma) p(mu | mu0, sigma0)
    = N(mu1, sigma1)
    ```

    where:
      * `sigma1 = sqrt( 1 / (1 / sigma0**2 + n / sigma**2))`
      * `mu1 = sigma1 ** 2 * (mu0 / sigma0**2 + n * xbar / sigma**2)
      * `n` is the number of samples.
      * `xbar` is the mean of the data.

    For a derivation, see https://www.cs.ubc.ca/~murphyk/Papers/bayesGauss.pdf.

    Args:
      prior_mean: `numpy.ndarray` representing mean of the normal prior.
      prior_stddev: `numpy.ndarray` representing standard deviation of the
        normal prior.
      likelihood_stddev: `numpy.ndarray` representing standard deviation of the
        normal likelihood.
      data: `numpy.ndarray` whose first dimension represents the number
        of data points.
    Returns:
      posterior_mean, posterior_variance: `Tensors` representing the
        posterior_mean and posterior_variance under this conjugate model.