if not os.path.exists(path):<EOL><INDENT>raise Exception("<STR_LIT>".format(path))<EOL><DEDENT>grammar_path = os.path.dirname(path)<EOL>if grammar_path not in sys.path:<EOL><INDENT>sys.path.append(grammar_path)<EOL><DEDENT>with open(path, "<STR_LIT:r>") as f:<EOL><INDENT>data = f.read()<EOL><DEDENT>code = compile(data, path, "<STR_LIT>")<EOL>locals_ = {"<STR_LIT>": self, "<STR_LIT>": path}<EOL>exec(code) in locals_<EOL>if "<STR_LIT>" in locals_:<EOL><INDENT>cat_group = os.path.basename(path).replace("<STR_LIT>", "<STR_LIT>")<EOL>self.set_cat_group_top_level_cat(cat_group, locals_["<STR_LIT>"])<EOL><DEDENT>

Load a grammar file (python file containing grammar definitions) by
        file path. When loaded, the global variable ``GRAMFUZZER`` will be set
        within the module. This is not always needed, but can be useful.

        :param str path: The path to the grammar file


import gramfuzz.fields<EOL>gramfuzz.fields.Ref.max_recursion = level<EOL>

Set the maximum reference-recursion depth (not the Python system maximum stack
        recursion level). This controls how many levels deep of nested references are allowed
        before gramfuzz attempts to generate the shortest (reference-wise) rules possible.

        :param int level: The new maximum reference level


to_prune = self._find_shortest_paths()<EOL>self._prune_rules(to_prune)<EOL>self._rules_processed = True<EOL>

Calculate shortest reference-paths of each rule (and Or field),
        and prune all unreachable rules.


def add_definition(self, cat, def_name, def_val, no_prune=False, gram_file="<STR_LIT:default>"):

self._rules_processed = False<EOL>self.add_to_cat_group(cat, gram_file, def_name)<EOL>if no_prune:<EOL><INDENT>self.no_prunes.setdefault(cat, {}).setdefault(def_name, True)<EOL><DEDENT>if self._staged_defs is not None:<EOL><INDENT>self._staged_defs.append((cat, def_name, def_val))<EOL><DEDENT>else:<EOL><INDENT>self.defs.setdefault(cat, {}).setdefault(def_name, deque()).append(def_val)<EOL><DEDENT>

Add a new rule definition named ``def_name`` having value ``def_value`` to
        the category ``cat``.

        :param str cat: The category to add the rule to
        :param str def_name: The name of the rule definition
        :param def_val: The value of the rule definition
        :param bool no_prune: If the rule should explicitly *NOT*
            be pruned even if it has been determined to be unreachable (default=``False``)
        :param str gram_file: The file the rule was defined in (default=``"default"``).


def set_cat_group_top_level_cat(self, cat_group, top_level_cat):

self.cat_group_defaults[cat_group] = top_level_cat<EOL>

Set the default category when generating data from the grammars defined
        in cat group. *Note* a cat group is usually just the basename of the grammar
        file, minus the ``.py``.

        :param str cat_group: The category group to set the default top-level cat for
        :param str top_level_cat: The top-level (default) category of the cat group


def add_to_cat_group(self, cat, cat_group, def_name):

self.cat_groups.setdefault(cat, {}).setdefault(cat_group, deque()).append(def_name)<EOL>

Associate the provided rule definition name ``def_name`` with the
        category group ``cat_group`` in the category ``cat``.

        :param str cat: The category the rule definition was declared in
        :param str cat_group: The group within the category the rule belongs to
        :param str def_name: The name of the rule definition


if cat not in self.defs:<EOL><INDENT>raise errors.GramFuzzError("<STR_LIT>".format(cat))<EOL><DEDENT>if refname == "<STR_LIT:*>":<EOL><INDENT>refname = rand.choice(self.defs[cat].keys())<EOL><DEDENT>if refname not in self.defs[cat]:<EOL><INDENT>raise errors.GramFuzzError("<STR_LIT>".format(refname))<EOL><DEDENT>return rand.choice(self.defs[cat][refname])<EOL>

Return one of the rules in the category ``cat`` with the name
        ``refname``. If multiple rule defintions exist for the defintion name
        ``refname``, use :any:`gramfuzz.rand` to choose a rule at random.

        :param str cat: The category to look for the rule in.
        :param str refname: The name of the rule definition. If the rule definition's name is
            ``"*"``, then a rule name will be chosen at random from within the category ``cat``.
        :returns: gramfuzz.fields.Def


def gen(self, num, cat=None, cat_group=None, preferred=None, preferred_ratio=<NUM_LIT:0.5>, max_recursion=None, auto_process=True):

import gramfuzz.fields<EOL>gramfuzz.fields.REF_LEVEL = <NUM_LIT:1><EOL>if cat is None and cat_group is None:<EOL><INDENT>raise gramfuzz.errors.GramFuzzError("<STR_LIT>")<EOL><DEDENT>if cat is None and cat_group is not None:<EOL><INDENT>if cat_group not in self.cat_group_defaults:<EOL><INDENT>raise gramfuzz.errors.GramFuzzError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>cat = self.cat_group_defaults[cat_group]<EOL>if not isinstance(cat, basestring):<EOL><INDENT>raise gramfuzz.errors.GramFuzzError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if auto_process and self._rules_processed == False:<EOL><INDENT>self.preprocess_rules()<EOL><DEDENT>if max_recursion is not None:<EOL><INDENT>self.set_max_recursion(max_recursion)<EOL><DEDENT>if preferred is None:<EOL><INDENT>preferred = []<EOL><DEDENT>res = deque()<EOL>cat_defs = self.defs[cat]<EOL>_res_append = res.append<EOL>_res_extend = res.extend<EOL>_choice = rand.choice<EOL>_maybe = rand.maybe<EOL>_val = utils.val<EOL>keys = self.defs[cat].keys()<EOL>self._last_pref_keys = self._get_pref_keys(cat, preferred)<EOL>self._last_prefs = preferred<EOL>total_errors = deque()<EOL>total_gend = <NUM_LIT:0><EOL>while total_gend < num:<EOL><INDENT>if len(self._last_pref_keys) > <NUM_LIT:0> and _maybe(preferred_ratio):<EOL><INDENT>rand_key = _choice(self._last_pref_keys)<EOL>if rand_key not in cat_defs:<EOL><INDENT>rand_key = _choice(list(keys))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rand_key = _choice(list(keys))<EOL><DEDENT>if rand_key not in cat_defs:<EOL><INDENT>continue<EOL><DEDENT>v = _choice(cat_defs[rand_key])<EOL>info = {}<EOL>pre = deque()<EOL>self.pre_revert(info)<EOL>val_res = None<EOL>try:<EOL><INDENT>val_res = _val(v, pre)<EOL><DEDENT>except errors.GramFuzzError as e:<EOL><INDENT>raise<EOL><DEDENT>except RuntimeError as e:<EOL><INDENT>print("<STR_LIT>")<EOL>self.revert(info)<EOL>continue<EOL><DEDENT>if val_res is not None:<EOL><INDENT>_res_extend(pre)<EOL>_res_append(val_res)<EOL>total_gend += <NUM_LIT:1><EOL>self.post_revert(cat, res, total_gend, num, info)<EOL><DEDENT><DEDENT>return res<EOL>

Generate ``num`` rules from category ``cat``, optionally specifying
        preferred category groups ``preferred`` that should be preferred at
        probability ``preferred_ratio`` over other randomly-chosen rule definitions.

        :param int num: The number of rules to generate
        :param str cat: The name of the category to generate ``num`` rules from
        :param str cat_group: The category group (ie python file) to generate rules from. This
            was added specifically to make it easier to generate data based on the name
            of the file the grammar was defined in, and is intended to work with the
            ``TOP_CAT`` values that may be defined in a loaded grammar file.
        :param list preferred: A list of preferred category groups to generate rules from
        :param float preferred_ratio: The percent probability that the preferred
            groups will be chosen over randomly choosen rule definitions from category ``cat``.
        :param int max_recursion: The maximum amount to allow references to recurse
        :param bool auto_process: Whether rules should be automatically pruned and
            shortest reference paths determined. See :any:`gramfuzz.GramFuzzer.preprocess_rules`
            for what would automatically be done.


self._staged_defs = deque()<EOL>

Signal to begin saving any changes that might need to be reverted


def post_revert(self, cat, res, total_num, num, info):

if self._staged_defs is None:<EOL><INDENT>return<EOL><DEDENT>for cat,def_name,def_value in self._staged_defs:<EOL><INDENT>self.defs.setdefault(cat, {}).setdefault(def_name, deque()).append(def_value)<EOL><DEDENT>self._staged_defs = None<EOL>

Commit any staged rule definition changes (rule generation went
        smoothly).


self._staged_defs = None<EOL>

Revert after a single def errored during generate (throw away all
        staged rule definition changes)


prev_dir = os.getcwd()<EOL>os.chdir(str(path))<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(prev_dir)<EOL><DEDENT>

Change working directory and restore the previous on exit


def strip_prefix(s, prefix, strict=False):

if s.startswith(prefix):<EOL><INDENT>return s[len(prefix) :]<EOL><DEDENT>elif strict:<EOL><INDENT>raise WimpyError("<STR_LIT>")<EOL><DEDENT>return s<EOL>

Removes the prefix, if it's there, otherwise returns input string unchanged.
    If strict is True, also ensures the prefix was present


def strip_suffix(s, suffix, strict=False):

if s.endswith(suffix):<EOL><INDENT>return s[: len(s) - len(suffix)]<EOL><DEDENT>elif strict:<EOL><INDENT>raise WimpyError("<STR_LIT>")<EOL><DEDENT>return s<EOL>

Removes the suffix, if it's there, otherwise returns input string unchanged.
    If strict is True, also ensures the suffix was present


<EOL>return -(-numerator // denominator)<EOL>


def grouper(iterable, n, fillvalue=None):

args = [iter(iterable)] * n<EOL>return zip_longest(*args, fillvalue=fillvalue)<EOL>

Yield successive non-overlapping chunks of size n from iterable


it = iter(haystack)<EOL>for element in needle:<EOL><INDENT>if element not in it:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Are all the elements of needle contained in haystack, and in the same order?
    There may be other elements interspersed throughout


argv = ['<STR_LIT>']<EOL>if arguments:<EOL><INDENT>argv.extend(arguments)<EOL><DEDENT>return argv<EOL>

Make an argument list suitable for the parse function.


parser = build_parser()<EOL>args = parser.parse_args(argv[<NUM_LIT:1>:])<EOL>return args<EOL>


description = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>parser = argparse.ArgumentParser(description=description)<EOL>parser.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', help='<STR_LIT>',<EOL>default='<STR_LIT:localhost>')<EOL>parser.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', help='<STR_LIT>', default=<NUM_LIT>, type=int)<EOL>return parser<EOL>

Build the parser that will have all available commands and options.


env = Environment()<EOL>args = parser.parse_args(args=['<STR_LIT:/>', '<STR_LIT>'], env=env)<EOL>args.output_options = '<STR_LIT>'  <EOL>server = '<STR_LIT>'.format(__version__)<EOL>def application(environ, start_response):<EOL><INDENT>if environ.get('<STR_LIT>') == '<STR_LIT>':<EOL><INDENT>del environ['<STR_LIT>']<EOL><DEDENT>if environ.get('<STR_LIT>') == '<STR_LIT>':<EOL><INDENT>del environ['<STR_LIT>']<EOL><DEDENT>wrequest = WerkzeugRequest(environ)<EOL>data = wrequest.get_data()<EOL>request = Request(<EOL>method=wrequest.method,<EOL>url=wrequest.url,<EOL>headers=wrequest.headers,<EOL>data=data,<EOL>)<EOL>prepared = request.prepare()<EOL>stream = streams.build_output_stream(<EOL>args, env, prepared, response=None,<EOL>output_options=args.output_options)<EOL>streams.write_stream(stream, env.stdout, env.stdout_isatty)<EOL>if data:<EOL><INDENT>print("<STR_LIT:\n>", file=env.stdout)<EOL><DEDENT>response = Response(headers={'<STR_LIT>': server})<EOL>return response(environ, start_response)<EOL><DEDENT>return application<EOL>

Make a WSGI app that has all the HTTPie pieces baked in.


if isinstance(source, str):<EOL><INDENT>stream = open(source, mode="<STR_LIT:rb>")<EOL>if not closefd:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>elif isinstance(source, bytes):<EOL><INDENT>stream = io.BytesIO(source)<EOL><DEDENT>else:<EOL><INDENT>stream = source<EOL><DEDENT>return LasReader(stream, closefd=closefd)<EOL>

Opens and reads the header of the las content in the source

        >>> with open_las('pylastests/simple.las') as f:
        ...     print(f.header.point_format_id)
        3

        >>> f = open('pylastests/simple.las', mode='rb')
        >>> with open_las(f, closefd=False) as flas:
        ...     print(flas.header)
        <LasHeader(1.2)>
        >>> f.closed
        False

        >>> f = open('pylastests/simple.las', mode='rb')
        >>> with open_las(f) as flas:
        ...    las = flas.read()
        >>> f.closed
        True

    Parameters
    ----------
    source : str or io.BytesIO
        if source is a str it must be a filename
        a stream if a file object with the methods read, seek, tell

    closefd: bool
        Whether the stream/file object shall be closed, this only work
        when using open_las in a with statement. An exception is raised if
        closefd is specified and the source is a filename

    Returns
    -------
    pylas.lasreader.LasReader


with open_las(source, closefd=closefd) as reader:<EOL><INDENT>return reader.read()<EOL><DEDENT>

Entry point for reading las data in pylas

    Reads the whole file into memory.

    >>> las = read_las("pylastests/simple.las")
    >>> las.classification
    array([1, 1, 1, ..., 1, 1, 1], dtype=uint8)

    Parameters
    ----------
    source : str or io.BytesIO
        The source to read data from

    closefd: bool
            if True and the source is a stream, the function will close it
            after it is done reading

    Returns
    -------
    pylas.lasdatas.base.LasBase
        The object you can interact with to get access to the LAS points & VLRs


return LasMMAP(filename)<EOL>

MMap a file, much like laspy did, very experimental
    not well tested


header = copy.copy(header)<EOL>header.point_count = <NUM_LIT:0><EOL>points = record.PackedPointRecord.empty(PointFormat(header.point_format_id))<EOL>if header.version >= "<STR_LIT>":<EOL><INDENT>return las14.LasData(header=header, points=points)<EOL><DEDENT>return las12.LasData(header=header, points=points)<EOL>

Creates a File from an existing header,
    allocating the array of point according to the provided header.
    The input header is copied.

    Parameters
    ----------
    header : existing header to be used to create the file

    Returns
    -------
    pylas.lasdatas.base.LasBase


def create_las(*, point_format_id=<NUM_LIT:0>, file_version=None):

if file_version is not None:<EOL><INDENT>dims.raise_if_version_not_compatible_with_fmt(point_format_id, file_version)<EOL><DEDENT>else:<EOL><INDENT>file_version = dims.min_file_version_for_point_format(point_format_id)<EOL><DEDENT>header = headers.HeaderFactory.new(file_version)<EOL>header.point_format_id = point_format_id<EOL>if file_version >= "<STR_LIT>":<EOL><INDENT>return las14.LasData(header=header)<EOL><DEDENT>return las12.LasData(header=header)<EOL>

Function to create a new empty las data object

    .. note::

        If you provide both point_format and file_version
        an exception will be raised if they are not compatible

    >>> las = create_las(point_format_id=6,file_version="1.2")
    Traceback (most recent call last):
     ...
    pylas.errors.PylasError: Point format 6 is not compatible with file version 1.2

    If you provide only the point_format the file_version will automatically
    selected for you.

    >>> las = create_las(point_format_id=0)
    >>> las.header.version == '1.2'
    True

    >>> las = create_las(point_format_id=6)
    >>> las.header.version == '1.4'
    True

    Parameters
    ----------
    point_format_id: int
        The point format you want the created file to have

    file_version: str, optional, default=None
        The las version you want the created las to have

    Returns
    -------
    pylas.lasdatas.base.LasBase
       A new las data object


def convert(source_las, *, point_format_id=None, file_version=None):

if point_format_id is None:<EOL><INDENT>point_format_id = source_las.points_data.point_format.id<EOL><DEDENT>if file_version is None:<EOL><INDENT>file_version = max(<EOL>source_las.header.version,<EOL>dims.min_file_version_for_point_format(point_format_id),<EOL>)<EOL><DEDENT>else:<EOL><INDENT>file_version = str(file_version)<EOL>dims.raise_if_version_not_compatible_with_fmt(point_format_id, file_version)<EOL><DEDENT>header = headers.HeaderFactory.convert_header(source_las.header, file_version)<EOL>header.point_format_id = point_format_id<EOL>point_format = PointFormat(<EOL>point_format_id, source_las.points_data.point_format.extra_dims<EOL>)<EOL>points = record.PackedPointRecord.from_point_record(<EOL>source_las.points_data, point_format<EOL>)<EOL>try:<EOL><INDENT>evlrs = source_las.evlrs<EOL><DEDENT>except ValueError:<EOL><INDENT>evlrs = []<EOL><DEDENT>if file_version >= "<STR_LIT>":<EOL><INDENT>las = las14.LasData(<EOL>header=header, vlrs=source_las.vlrs, points=points, evlrs=evlrs<EOL>)<EOL><DEDENT>else:<EOL><INDENT>if evlrs:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>len(evlrs), file_version<EOL>)<EOL>)<EOL><DEDENT>las = las12.LasData(header=header, vlrs=source_las.vlrs, points=points)<EOL><DEDENT>return las<EOL>

Converts a Las from one point format to another
    Automatically upgrades the file version if source file version is not compatible with
    the new point_format_id

    convert to point format 0

    >>> las = read_las('pylastests/simple.las')
    >>> las.header.version
    '1.2'
    >>> las = convert(las, point_format_id=0)
    >>> las.header.point_format_id
    0
    >>> las.header.version
    '1.2'

    convert to point format 6, which need version >= 1.4
    then convert back to point format 0, version is not downgraded

    >>> las = read_las('pylastests/simple.las')
    >>> las.header.version
    '1.2'
    >>> las = convert(las, point_format_id=6)
    >>> las.header.point_format_id
    6
    >>> las.header.version
    '1.4'
    >>> las = convert(las, point_format_id=0)
    >>> las.header.version
    '1.4'

    an exception is raised if the requested point format is not compatible
    with the file version

    >>> las = read_las('pylastests/simple.las')
    >>> convert(las, point_format_id=6, file_version='1.2')
    Traceback (most recent call last):
     ...
    pylas.errors.PylasError: Point format 6 is not compatible with file version 1.2

    Parameters
    ----------
    source_las : pylas.lasdatas.base.LasBase
        The source data to be converted

    point_format_id : int, optional
        The new point format id (the default is None, which won't change the source format id)

    file_version : str, optional,
        The new file version. None by default which means that the file_version
        may be upgraded for compatibility with the new point_format. The file version will not
        be downgraded.

    Returns
    -------
        pylas.lasdatas.base.LasBase


if len(las_files) == <NUM_LIT:1>:<EOL><INDENT>las_files = las_files[<NUM_LIT:0>]<EOL><DEDENT>if not las_files:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not utils.files_have_same_dtype(las_files):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>header = las_files[<NUM_LIT:0>].header<EOL>num_pts_merged = sum(len(las.points) for las in las_files)<EOL>merged = create_from_header(header)<EOL>for dim_name, dim_type in las_files[<NUM_LIT:0>].points_data.point_format.extra_dims:<EOL><INDENT>merged.add_extra_dim(dim_name, dim_type)<EOL><DEDENT>merged.points = np.zeros(num_pts_merged, merged.points.dtype)<EOL>merged_x = np.zeros(num_pts_merged, np.float64)<EOL>merged_y = np.zeros(num_pts_merged, np.float64)<EOL>merged_z = np.zeros(num_pts_merged, np.float64)<EOL>offset = <NUM_LIT:0><EOL>for i, las in enumerate(las_files, start=<NUM_LIT:1>):<EOL><INDENT>slc = slice(offset, offset + len(las.points))<EOL>merged.points[slc] = las.points<EOL>merged_x[slc] = las.x<EOL>merged_y[slc] = las.y<EOL>merged_z[slc] = las.z<EOL>merged['<STR_LIT>'][slc] = i<EOL>offset += len(las.points)<EOL><DEDENT>merged.x = merged_x<EOL>merged.y = merged_y<EOL>merged.z = merged_z<EOL>return merged<EOL>

Merges multiple las files into one

    merged = merge_las(las_1, las_2)
    merged = merge_las([las_1, las_2, las_3])

    Parameters
    ----------
    las_files: Iterable of LasData or LasData

    Returns
    -------
    pylas.lasdatas.base.LasBase
        The result of the merging


out = io.BytesIO()<EOL>las.write(out, do_compress=do_compress)<EOL>out.seek(<NUM_LIT:0>)<EOL>return read_las(out)<EOL>

writes the given las into memory using BytesIO and
    reads it again, returning the newly read file.

    Mostly used for testing purposes, without having to write to disk


try:<EOL><INDENT>t = _extra_dims_style_2[type_index]<EOL>if "<STR_LIT>" in t:<EOL><INDENT>return DimensionSignedness.UNSIGNED<EOL><DEDENT>elif "<STR_LIT:int>" in t:<EOL><INDENT>return DimensionSignedness.SIGNED<EOL><DEDENT>else:<EOL><INDENT>return DimensionSignedness.FLOATING<EOL><DEDENT><DEDENT>except IndexError:<EOL><INDENT>raise errors.UnknownExtraType(type_index)<EOL><DEDENT>

Returns the signedness foe the given type index

    Parameters
    ----------
    type_index: int
        index of the type as defined in the LAS Specification

    Returns
    -------
    DimensionSignedness,
        the enum variant


try:<EOL><INDENT>return _extra_dims_style_1[type_index]<EOL><DEDENT>except IndexError:<EOL><INDENT>raise errors.UnknownExtraType(type_index)<EOL><DEDENT>

Returns the type str ('u1" or "u2", etc) for the given type index
    Parameters
    ----------
    type_index: int
        index of the type as defined in the LAS Specification

    Returns
    -------
    str,
        a string representing the type, can be understood by numpy


try:<EOL><INDENT>return _type_to_extra_dim_id_style_1[type_str]<EOL><DEDENT>except KeyError:<EOL><INDENT>try:<EOL><INDENT>return _type_to_extra_dim_id_style_2[type_str]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise errors.UnknownExtraType(type_str)<EOL><DEDENT><DEDENT>

Returns the index of the type as defined in the LAS Specification

    Parameters
    ----------
    type_str: str

    Returns
    -------
    int
        index of the type


return scale_dimension(self.X, self.header.x_scale, self.header.x_offset)<EOL>

Returns the scaled x positions of the points as doubles


return scale_dimension(self.Y, self.header.y_scale, self.header.y_offset)<EOL>

Returns the scaled y positions of the points as doubles


return scale_dimension(self.Z, self.header.z_scale, self.header.z_offset)<EOL>

Returns the scaled z positions of the points as doubles


return self.points_data.array<EOL>

returns the numpy array representing the points

        Returns
        -------
        the Numpy structured array of points


if value.dtype != self.points.dtype:<EOL><INDENT>raise errors.IncompatibleDataFormat('<STR_LIT>')<EOL><DEDENT>new_point_record = record.PackedPointRecord(value, self.points_data.point_format)<EOL>dims.raise_if_version_not_compatible_with_fmt(<EOL>new_point_record.point_format.id, self.header.version<EOL>)<EOL>self.points_data = new_point_record<EOL>self.update_header()<EOL>

Setter for the points property,
        Takes care of changing the point_format of the file
        (as long as the point format of the new points it compatible with the file version)

        Parameters
        ----------
        value: numpy.array of the new points


return self.points_data[item]<EOL>

Automatically called by Python when the attribute
        named 'item' is no found. We use this function to forward the call the
        point record. This is the mechanism used to allow the users to access
        the points dimensions directly through a LasData.

        Parameters
        ----------
        item: str
            name of the attribute, should be a dimension name

        Returns
        -------
        The requested dimension if it exists


if key in dims.DIMENSIONS or key in self.points_data.all_dimensions_names:<EOL><INDENT>self.points_data[key] = value<EOL><DEDENT>else:<EOL><INDENT>super().__setattr__(key, value)<EOL><DEDENT>

This is called on every access to an attribute of the instance.
        Again we use this to forward the call the the points record

        But this time checking if the key is actually a dimension name
        so that an error is raised if the user tries to set a valid
        LAS dimension even if it is not present in the field.
        eg: user tries to set the red field of a file with point format 0:
        an error is raised


def add_extra_dim(self, name, type, description="<STR_LIT>"):

name = name.replace("<STR_LIT:U+0020>", "<STR_LIT:_>")<EOL>type_id = extradims.get_id_for_extra_dim_type(type)<EOL>extra_byte = ExtraBytesStruct(<EOL>data_type=type_id, name=name.encode(), description=description.encode()<EOL>)<EOL>try:<EOL><INDENT>extra_bytes_vlr = self.vlrs.get("<STR_LIT>")[<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>extra_bytes_vlr = ExtraBytesVlr()<EOL>self.vlrs.append(extra_bytes_vlr)<EOL><DEDENT>finally:<EOL><INDENT>extra_bytes_vlr.extra_bytes_structs.append(extra_byte)<EOL>self.points_data.add_extra_dims([(name, type)])<EOL><DEDENT>

Adds a new extra dimension to the point record

        Parameters
        ----------
        name: str
            the name of the dimension
        type: str
            type of the dimension (eg 'uint8')
        description: str, optional
            a small description of the dimension


def write_to(self, out_stream, do_compress=False):

self.update_header()<EOL>if (<EOL>self.vlrs.get("<STR_LIT>")<EOL>and not self.points_data.extra_dimensions_names<EOL>):<EOL><INDENT>logger.error(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>self.vlrs.extract("<STR_LIT>")<EOL><DEDENT>if do_compress:<EOL><INDENT>laz_vrl = create_laz_vlr(self.points_data)<EOL>self.vlrs.append(known.LasZipVlr(laz_vrl.data()))<EOL>raw_vlrs = vlrlist.RawVLRList.from_list(self.vlrs)<EOL>self.header.offset_to_point_data = (<EOL>self.header.size + raw_vlrs.total_size_in_bytes()<EOL>)<EOL>self.header.point_format_id = uncompressed_id_to_compressed(<EOL>self.header.point_format_id<EOL>)<EOL>self.header.number_of_vlr = len(raw_vlrs)<EOL>points_bytes = compress_buffer(<EOL>np.frombuffer(self.points_data.array, np.uint8),<EOL>laz_vrl.schema,<EOL>self.header.offset_to_point_data,<EOL>).tobytes()<EOL><DEDENT>else:<EOL><INDENT>raw_vlrs = vlrlist.RawVLRList.from_list(self.vlrs)<EOL>self.header.number_of_vlr = len(raw_vlrs)<EOL>self.header.offset_to_point_data = (<EOL>self.header.size + raw_vlrs.total_size_in_bytes()<EOL>)<EOL>points_bytes = self.points_data.raw_bytes()<EOL><DEDENT>self.header.write_to(out_stream)<EOL>self._raise_if_not_expected_pos(out_stream, self.header.size)<EOL>raw_vlrs.write_to(out_stream)<EOL>self._raise_if_not_expected_pos(out_stream, self.header.offset_to_point_data)<EOL>out_stream.write(points_bytes)<EOL>

writes the data to a stream

        Parameters
        ----------
        out_stream: file object
            the destination stream, implementing the write method
        do_compress: bool, optional, default False
            Flag to indicate if you want the date to be compressed


def write_to_file(self, filename, do_compress=None):

is_ext_laz = filename.split("<STR_LIT:.>")[-<NUM_LIT:1>] == "<STR_LIT>"<EOL>if is_ext_laz and do_compress is None:<EOL><INDENT>do_compress = True<EOL><DEDENT>with open(filename, mode="<STR_LIT:wb>") as out:<EOL><INDENT>self.write_to(out, do_compress=do_compress)<EOL><DEDENT>

Writes the las data into a file

        Parameters
        ----------
        filename : str
            The file where the data should be written.
        do_compress: bool, optional, default None
            if None the extension of the filename will be used
            to determine if the data should be compressed
            otherwise the do_compress flag indicate if the data should be compressed


def write(self, destination, do_compress=None):

if isinstance(destination, str):<EOL><INDENT>self.write_to_file(destination)<EOL><DEDENT>else:<EOL><INDENT>if do_compress is None:<EOL><INDENT>do_compress = False<EOL><DEDENT>self.write_to(destination, do_compress=do_compress)<EOL><DEDENT>

Writes to a stream or file

        When destination is a string, it will be interpreted as the path were the file should be written to,
        also if do_compress is None, the compression will be guessed from the file extension:

        - .laz -> compressed
        - .las -> uncompressed

        .. note::

            This means that you could do something like:
                # Create .laz but not compressed

                las.write('out.laz', do_compress=False)

                # Create .las but compressed

                las.write('out.las', do_compress=True)

            While it should not confuse Las/Laz readers, it will confuse humans so avoid doing it

        Parameters
        ----------
        destination: str or file object
            filename or stream to write to
        do_compress: bool, optional
            Flags to indicate if you want to compress the data


file_sig = stream.read(len(headers.LAS_FILE_SIGNATURE))<EOL>if file_sig != headers.LAS_FILE_SIGNATURE:<EOL><INDENT>raise errors.PylasError(<EOL>"<STR_LIT>".format(file_sig, headers.LAS_FILE_SIGNATURE)<EOL>)<EOL><DEDENT>

Reads the 4 first bytes of the stream to check that is LASF


self.stream.seek(self.start_pos)<EOL>return headers.HeaderFactory().read_from_stream(self.stream)<EOL>

Reads the head of the las file and returns it


self.stream.seek(self.start_pos + self.header.size)<EOL>return VLRList.read_from(self.stream, num_to_read=self.header.number_of_vlr)<EOL>


vlrs = self.read_vlrs()<EOL>self._warn_if_not_at_expected_pos(<EOL>self.header.offset_to_point_data, "<STR_LIT>", "<STR_LIT>"<EOL>)<EOL>self.stream.seek(self.start_pos + self.header.offset_to_point_data)<EOL>try:<EOL><INDENT>points = self._read_points(vlrs)<EOL><DEDENT>except (RuntimeError, errors.LazPerfNotFound) as e:<EOL><INDENT>logger.error("<STR_LIT>".format(e))<EOL>self.stream.seek(self.start_pos)<EOL>self.__init__(io.BytesIO(laszip_decompress(self.stream)))<EOL>return self.read()<EOL><DEDENT>if points.point_format.has_waveform_packet:<EOL><INDENT>self.stream.seek(<EOL>self.start_pos + self.header.start_of_waveform_data_packet_record<EOL>)<EOL>if self.header.global_encoding.are_waveform_flag_equal():<EOL><INDENT>raise errors.PylasError(<EOL>"<STR_LIT>".format(<EOL>"<STR_LIT>"<EOL>if self.header.global_encoding.waveform_internal<EOL>else "<STR_LIT>"<EOL>)<EOL>)<EOL><DEDENT>if self.header.global_encoding.waveform_internal:<EOL><INDENT>_, _ = self._read_internal_waveform_packet()<EOL><DEDENT>elif self.header.global_encoding.waveform_external:<EOL><INDENT>logger.info(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if self.header.version >= "<STR_LIT>":<EOL><INDENT>evlrs = self.read_evlrs()<EOL>return las14.LasData(<EOL>header=self.header, vlrs=vlrs, points=points, evlrs=evlrs<EOL>)<EOL><DEDENT>return las12.LasData(header=self.header, vlrs=vlrs, points=points)<EOL>

Reads the whole las data (header, vlrs ,points, etc) and returns a LasData
        object


try:<EOL><INDENT>extra_dims = vlrs.get("<STR_LIT>")[<NUM_LIT:0>].type_of_extra_dims()<EOL><DEDENT>except IndexError:<EOL><INDENT>extra_dims = None<EOL><DEDENT>point_format = PointFormat(self.header.point_format_id, extra_dims=extra_dims)<EOL>if self.header.are_points_compressed:<EOL><INDENT>laszip_vlr = vlrs.pop(vlrs.index("<STR_LIT>"))<EOL>points = self._read_compressed_points_data(laszip_vlr, point_format)<EOL><DEDENT>else:<EOL><INDENT>points = record.PackedPointRecord.from_stream(<EOL>self.stream, point_format, self.header.point_count<EOL>)<EOL><DEDENT>return points<EOL>

private function to handle reading of the points record parts
        of the las file.

        the header is needed for the point format and number of points
        the vlrs are need to get the potential laszip vlr as well as the extra bytes vlr


def _read_compressed_points_data(self, laszip_vlr, point_format):

offset_to_chunk_table = struct.unpack("<STR_LIT>", self.stream.read(<NUM_LIT:8>))[<NUM_LIT:0>]<EOL>size_of_point_data = offset_to_chunk_table - self.stream.tell()<EOL>if offset_to_chunk_table <= <NUM_LIT:0>:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>".format(<EOL>offset_to_chunk_table<EOL>)<EOL>)<EOL>size_of_point_data = -<NUM_LIT:1>  <EOL><DEDENT>points = record.PackedPointRecord.from_compressed_buffer(<EOL>self.stream.read(size_of_point_data),<EOL>point_format,<EOL>self.header.point_count,<EOL>laszip_vlr,<EOL>)<EOL>return points<EOL>


<EOL>b = bytearray(self.stream.read(rawvlr.VLR_HEADER_SIZE))<EOL>waveform_header = rawvlr.RawVLRHeader.from_buffer(b)<EOL>waveform_record = self.stream.read()<EOL>logger.debug(<EOL>"<STR_LIT>".format(len(waveform_record) / <NUM_LIT:10> ** <NUM_LIT:6>)<EOL>)<EOL>return waveform_header, waveform_record<EOL>

reads and returns the waveform vlr header, waveform record


self.stream.seek(self.start_pos + self.header.start_of_first_evlr)<EOL>return evlrs.EVLRList.read_from(self.stream, self.header.number_of_evlr)<EOL>

Reads the EVLRs of the file, will fail if the file version
        does not support evlrs


def _warn_if_not_at_expected_pos(self, expected_pos, end_of, start_of):

diff = expected_pos - self.stream.tell()<EOL>if diff != <NUM_LIT:0>:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>".format(diff, end_of, start_of)<EOL>)<EOL><DEDENT>

Helper function to warn about unknown bytes found in the file


self.stream.close()<EOL>

closes the file object used by the reader


pass<EOL>

Shall return the point size as that will be written in the header


pass<EOL>

Shall return the actual size in bytes that ta points take in memory


return self.point_format.extra_dimension_names<EOL>

Returns the names of extra-dimensions contained in the PointRecord


return self.array.dtype.itemsize<EOL>

Returns the point size in bytes taken by each points of the record

        Returns
        -------
        int
            The point size in byte


@classmethod<EOL><INDENT>def from_point_record(cls, other_point_record, new_point_format):<DEDENT>

array = np.zeros_like(other_point_record.array, dtype=new_point_format.dtype)<EOL>new_record = cls(array, new_point_format)<EOL>new_record.copy_fields_from(other_point_record)<EOL>return new_record<EOL>

Construct a new PackedPointRecord from an existing one with the ability to change
        to point format while doing so


for dim_name in self.dimensions_names:<EOL><INDENT>try:<EOL><INDENT>self[dim_name] = other_record[dim_name]<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Tries to copy the values of the current dimensions from other_record


size_diff = len(value) - len(self.array)<EOL>if size_diff:<EOL><INDENT>self.array = np.append(<EOL>self.array, np.zeros(size_diff, dtype=self.array.dtype)<EOL>)<EOL><DEDENT>

Appends zeros to the points stored if the value we are trying to
        fit is bigger


return frozenset(self.array.dtype.names + tuple(self.sub_fields_dict.keys()))<EOL>

Returns all the dimensions names, including the names of sub_fields
        and their corresponding packed fields


return self.array.dtype.itemsize<EOL>


@classmethod<EOL><INDENT>def zeros(cls, point_format, point_count):<DEDENT>

data = np.zeros(point_count, point_format.dtype)<EOL>return cls(data, point_format)<EOL>

Creates a new point record with all dimensions initialized to zero

        Parameters
        ----------
        point_format_id: int
            The point format id the point record should have
        point_count : int
            The number of point the point record should have

        Returns
        -------
        PackedPointRecord


return cls.zeros(point_format, point_count=<NUM_LIT:0>)<EOL>

Creates an empty point record.

        Parameters
        ----------
        point_format: pylas.PointFormat
            The point format id the point record should have

        Returns
        -------
        PackedPointRecord


@classmethod<EOL><INDENT>def from_stream(cls, stream, point_format, count):<DEDENT>

points_dtype = point_format.dtype<EOL>point_data_buffer = bytearray(stream.read(count * points_dtype.itemsize))<EOL>try:<EOL><INDENT>data = np.frombuffer(point_data_buffer, dtype=points_dtype, count=count)<EOL><DEDENT>except ValueError:<EOL><INDENT>expected_bytes_len = count * points_dtype.itemsize<EOL>if len(point_data_buffer) % points_dtype.itemsize != <NUM_LIT:0>:<EOL><INDENT>missing_bytes_len = expected_bytes_len - len(point_data_buffer)<EOL>raise_not_enough_bytes_error(<EOL>expected_bytes_len,<EOL>missing_bytes_len,<EOL>len(point_data_buffer),<EOL>points_dtype,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>actual_count = len(point_data_buffer) // points_dtype.itemsize<EOL>logger.critical(<EOL>"<STR_LIT>".format(<EOL>count, actual_count, count - actual_count<EOL>)<EOL>)<EOL>data = np.frombuffer(<EOL>point_data_buffer, dtype=points_dtype, count=actual_count<EOL>)<EOL><DEDENT><DEDENT>return cls(data, point_format)<EOL>

Construct the point record by reading the points from the stream


@classmethod<EOL><INDENT>def from_compressed_buffer(cls, compressed_buffer, point_format, count, laszip_vlr):<DEDENT>

point_dtype = point_format.dtype<EOL>uncompressed = decompress_buffer(<EOL>compressed_buffer, point_dtype, count, laszip_vlr<EOL>)<EOL>return cls(uncompressed, point_format)<EOL>

Construct the point record by reading and decompressing the points data from
        the input buffer


try:<EOL><INDENT>composed_dim, sub_field = self.sub_fields_dict[item]<EOL>return packing.unpack(<EOL>self.array[composed_dim], sub_field.mask, dtype=sub_field.type<EOL>)<EOL><DEDENT>except KeyError:<EOL><INDENT>return self.array[item]<EOL><DEDENT>

Gives access to the underlying numpy array
        Unpack the dimension if item is the name a sub-field


self._append_zeros_if_too_small(value)<EOL>try:<EOL><INDENT>composed_dim, sub_field = self.sub_fields_dict[key]<EOL>try:<EOL><INDENT>packing.pack(self.array[composed_dim], value, sub_field.mask, inplace=True)<EOL><DEDENT>except OverflowError as e:<EOL><INDENT>raise OverflowError("<STR_LIT>".format(<EOL>sub_field.name, composed_dim, e<EOL>))<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>self.array[key] = value<EOL><DEDENT>


return (val & -val).bit_length() - <NUM_LIT:1><EOL>


def unpack(source_array, mask, dtype=np.uint8):

lsb = least_significant_bit(mask)<EOL>return ((source_array & mask) >> lsb).astype(dtype)<EOL>

Unpack sub field using its mask

    Parameters:
    ----------
    source_array : numpy.ndarray
        The source array
    mask : mask (ie: 0b00001111)
        Mask of the sub field to be extracted from the source array
    Returns
    -------
    numpy.ndarray
        The sub field array


def pack(array, sub_field_array, mask, inplace=False):

lsb = least_significant_bit(mask)<EOL>max_value = int(mask >> lsb)<EOL>if sub_field_array.max() > max_value:<EOL><INDENT>raise OverflowError(<EOL>"<STR_LIT>".format(<EOL>sub_field_array.max(), max_value<EOL>)<EOL>)<EOL><DEDENT>if inplace:<EOL><INDENT>array[:] = array & ~mask<EOL>array[:] = array | ((sub_field_array << lsb) & mask).astype(array.dtype)<EOL><DEDENT>else:<EOL><INDENT>array = array & ~mask<EOL>return array | ((sub_field_array << lsb) & mask).astype(array.dtype)<EOL><DEDENT>

Packs a sub field's array into another array using a mask

    Parameters:
    ----------
    array : numpy.ndarray
        The array in which the sub field array will be packed into
    array_in : numpy.ndarray
        sub field array to pack
    mask : mask (ie: 0b00001111)
        Mask of the sub field
    inplace : {bool}, optional
        If true a new array is returned. (the default is False, which modifies the array in place)

    Raises
    ------
    OverflowError
        If the values contained in the sub field array are greater than its mask's number of bits
        allows


unpacked_dims_in = PointFormat(point_fmt_in).dtype<EOL>unpacked_dims_out = PointFormat(point_fmt_out).dtype<EOL>out_dims = unpacked_dims_out.fields<EOL>completely_lost = []<EOL>for dim_name in unpacked_dims_in.names:<EOL><INDENT>if dim_name not in out_dims:<EOL><INDENT>completely_lost.append(dim_name)<EOL><DEDENT><DEDENT>return completely_lost<EOL>

Returns a list of the names of the dimensions that will be lost
    when converting from point_fmt_in to point_fmt_out


def __init__(self, point_format_id, extra_dims=None):

self.id = point_format_id<EOL>if extra_dims is None:<EOL><INDENT>extra_dims = []<EOL><DEDENT>self.extra_dims = extra_dims<EOL>

Parameters
----------
point_format_id: int
    point format id
extra_dims: list of tuple
    [(name, type_str), ..] of extra dimensions attached to this point format


return self.unpacked_dtype.names<EOL>

Returns the names of the dimensions contained in the point format

        Returns
        -------
        list of str
            the names of the dimensions defined by this point format


dtype = self._access_dict(dims.ALL_POINT_FORMATS_DTYPE, self.id)<EOL>dtype = self._dtype_add_extra_dims(dtype)<EOL>return dtype<EOL>

Returns the numpy.dtype used to store the point records in a numpy array

        .. note::

            The dtype corresponds to the dtype with sub_fields *packed* into their
            composed fields


dtype = self._access_dict(dims.UNPACKED_POINT_FORMATS_DTYPES, self.id)<EOL>dtype = self._dtype_add_extra_dims(dtype)<EOL>return dtype<EOL>

Returns the numpy.dtype used to store the point records in a numpy array

        .. note::

            The dtype corresponds to the dtype with sub_fields *unpacked*


return self._access_dict(dims.COMPOSED_FIELDS, self.id)<EOL>

Returns the dict of composed fields defined for the point format

        Returns
        -------
        Dict[str, List[SubFields]]
            maps a composed field name to its sub_fields


sub_fields_dict = {}<EOL>for composed_dim_name, sub_fields in self.composed_fields.items():<EOL><INDENT>for sub_field in sub_fields:<EOL><INDENT>sub_fields_dict[sub_field.name] = (composed_dim_name, sub_field)<EOL><DEDENT><DEDENT>return sub_fields_dict<EOL>

Returns a dict of the sub fields for this point format

        Returns
        -------
        Dict[str, Tuple[str, SubField]]
            maps a sub field name to its composed dimension with additional information


return [extd[<NUM_LIT:0>] for extd in self.extra_dims]<EOL>

Returns the list of extra dimensions attached to this point format


return sum(np.dtype(extra_dim[<NUM_LIT:1>]).itemsize for extra_dim in self.extra_dims)<EOL>


dimensions = set(self.dimension_names)<EOL>return all(name in dimensions for name in dims.WAVEFORM_FIELDS_NAMES)<EOL>

Returns True if the point format has waveform packet dimensions


return np.dtype([dimensions[dim_name] for dim_name in point_format])<EOL>

build the numpy.dtype for a point format

    Parameters:
    ----------
    point_format : iterable of str
        The dimensions names of the point format
    dimensions : dict
        The dictionary of dimensions
    Returns
    -------
    numpy.dtype
        The dtype for the input point format


return {<EOL>fmt_id: _point_format_to_dtype(point_fmt, dimensions_dict)<EOL>for fmt_id, point_fmt in point_format_dimensions.items()<EOL>}<EOL>

Builds the dict mapping point format id to numpy.dtype
    In the dtypes, bit fields are still packed, and need to be unpacked each time
    you want to access them


def _build_unpacked_point_formats_dtypes(<EOL>point_formats_dimensions, composed_fields_dict, dimensions_dict<EOL>):

unpacked_dtypes = {}<EOL>for fmt_id, dim_names in point_formats_dimensions.items():<EOL><INDENT>composed_dims, dtype = composed_fields_dict[fmt_id], []<EOL>for dim_name in dim_names:<EOL><INDENT>if dim_name in composed_dims:<EOL><INDENT>dtype.extend((f.name, f.type) for f in composed_dims[dim_name])<EOL><DEDENT>else:<EOL><INDENT>dtype.append(dimensions_dict[dim_name])<EOL><DEDENT><DEDENT>unpacked_dtypes[fmt_id] = np.dtype(dtype)<EOL><DEDENT>return unpacked_dtypes<EOL>

Builds the dict mapping point format id to numpy.dtype
    In the dtypes, bit fields are unpacked and can be accessed directly


all_dtypes = (<EOL>ALL_POINT_FORMATS_DTYPE if not unpacked else UNPACKED_POINT_FORMATS_DTYPES<EOL>)<EOL>for format_id, fmt_dtype in all_dtypes.items():<EOL><INDENT>if fmt_dtype == dtype:<EOL><INDENT>return format_id<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise errors.IncompatibleDataFormat(<EOL>"<STR_LIT>".format(<EOL>dtype<EOL>)<EOL>)<EOL><DEDENT>

Tries to find a matching point format id for the input numpy dtype
    To match, the input dtype has to be 100% equal to a point format dtype
    so all names & dimensions types must match

    Parameters:
    ----------
    dtype : numpy.dtype
        The input dtype
    unpacked : bool, optional
        [description] (the default is False, which [default_description])

    Raises
    ------
    errors.IncompatibleDataFormat
        If No compatible point format was found

    Returns
    -------
    int
        The compatible point format found


for version, point_formats in sorted(VERSION_TO_POINT_FMT.items()):<EOL><INDENT>if point_format_id in point_formats:<EOL><INDENT>return version<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise errors.PointFormatNotSupported(point_format_id)<EOL><DEDENT>

Returns the minimum file version that supports the given point_format_id


return set(VERSION_TO_POINT_FMT.keys())<EOL>

Returns the set of supported file versions


return set(POINT_FORMAT_DIMENSIONS.keys())<EOL>

Returns a set of all the point formats supported in pylas


try:<EOL><INDENT>return point_format_id in VERSION_TO_POINT_FMT[str(file_version)]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise errors.FileVersionNotSupported(file_version)<EOL><DEDENT>

Returns true if the file version support the point_format_id


return self.legacy_point_count<EOL>

Returns the number of points in the file


return "<STR_LIT>".format(self.version_major, self.version_minor)<EOL>

.. DANGER::
    You should not use this directly if you want to change/convert
    the header version as this function does not change the underlying
    size of bytes buffer.
    See :meth:`HeaderFactory.convert_header` to convert headers


try:<EOL><INDENT>return datetime.date(self.creation_year, <NUM_LIT:1>, <NUM_LIT:1>) + datetime.timedelta(<EOL>self.creation_day_of_year - <NUM_LIT:1><EOL>)<EOL><DEDENT>except ValueError:<EOL><INDENT>return None<EOL><DEDENT>

Returns the creation date stored in the las file

        Returns
        -------
        datetime.date


self.creation_year = date.year<EOL>self.creation_day_of_year = date.timetuple().tm_yday<EOL>

Returns the date of file creation as a python date object


self._point_data_format_id = value<EOL>

Returns the point format id of the points


return self.point_data_record_length<EOL>

Returns the number of bits each point takes


return compression.is_point_format_compressed(self._point_data_format_id)<EOL>

Returns True if the point_format_id indicates that the points are stored compressed


return np.array([self.x_min, self.y_min, self.z_min])<EOL>

Returns de minimum values of x, y, z as a numpy array


self.x_min, self.y_min, self.z_min = value<EOL>

Sets de minimum values of x, y, z as a numpy array


return np.array([self.x_max, self.y_max, self.z_max])<EOL>

Returns de maximum values of x, y, z as a numpy array


self.x_max, self.y_max, self.z_max = value<EOL>

Sets de maximum values of x, y, z as a numpy array


return np.array([self.x_scale, self.y_scale, self.z_scale])<EOL>

Returns the scaling values of x, y, z as a numpy array


return np.array([self.x_offset, self.y_offset, self.z_offset])<EOL>

Returns the offsets values of x, y, z as a numpy array


try:<EOL><INDENT>return cls._version_to_header[str(version)]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise errors.FileVersionNotSupported(version)<EOL><DEDENT>

>>> HeaderFactory.header_class_for_version(2.0)
Traceback (most recent call last):
 ...
pylas.errors.FileVersionNotSupported: 2.0

>>> HeaderFactory.header_class_for_version(1.2)
<class 'pylas.headers.rawheader.RawHeader1_2'>

>>> header_class = HeaderFactory.header_class_for_version(1.4)
>>> header_class()
<LasHeader(1.4)>


return cls.header_class_for_version(version)()<EOL>

Returns a new instance of a header.

        Parameters
        ----------
        version : float or str
            The header version

        >>> HeaderFactory.new(1.4)
        <LasHeader(1.4)>

        >>> HeaderFactory.new('1.2')
        <LasHeader(1.2)>


old_pos = stream.tell()<EOL>stream.seek(cls._offset_to_major_version)<EOL>major = int.from_bytes(stream.read(ctypes.sizeof(ctypes.c_uint8)), "<STR_LIT>")<EOL>minor = int.from_bytes(stream.read(ctypes.sizeof(ctypes.c_uint8)), "<STR_LIT>")<EOL>stream.seek(old_pos)<EOL>return "<STR_LIT>".format(major, minor)<EOL>

seeks to the position of the las version header fields
        in the stream and returns it as a str

        Parameters
        ----------
        stream io.BytesIO

        Returns
        -------
        str
            file version read from the stream


@classmethod<EOL><INDENT>def convert_header(cls, old_header, new_version):<DEDENT>

new_header_class = cls.header_class_for_version(new_version)<EOL>b = bytearray(old_header)<EOL>b += b"<STR_LIT:\x00>" * (ctypes.sizeof(new_header_class) - len(b))<EOL>new_header = new_header_class.from_buffer(b)<EOL>new_header.version = str(new_version)<EOL>return new_header<EOL>

Converts a header to a another version

        Parameters
        ----------
        old_header: the old header instance
        new_version: float or str

        Returns
        -------
        The converted header

        >>> old_header = HeaderFactory.new(1.2)
        >>> HeaderFactory.convert_header(old_header, 1.4)
        <LasHeader(1.4)>

        >>> old_header = HeaderFactory.new('1.4')
        >>> HeaderFactory.convert_header(old_header, '1.2')
        <LasHeader(1.2)>


point_format_found = {las.header.point_format_id for las in las_files}<EOL>return len(point_format_found) == <NUM_LIT:1><EOL>

Returns true if all the files have the same points format id


dtypes = {las.points.dtype for las in las_files}<EOL>return len(dtypes) == <NUM_LIT:1><EOL>

Returns true if all the files have the same numpy datatype


user_id = raw_vlr.header.user_id.rstrip(NULL_BYTE).decode()<EOL>known_vlrs = BaseKnownVLR.__subclasses__()<EOL>for known_vlr in known_vlrs:<EOL><INDENT>if (<EOL>known_vlr.official_user_id() == user_id<EOL>and raw_vlr.header.record_id in known_vlr.official_record_ids()<EOL>):<EOL><INDENT>return known_vlr.from_raw(raw_vlr)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return VLR.from_raw(raw_vlr)<EOL><DEDENT>

Given a raw_vlr tries to find its corresponding KnownVLR class
    that can parse its data.
    If no KnownVLR implementation is found, returns a VLR (record_data will still be bytes)


pass<EOL>

Shall return the official user_id as described in the documentation


pass<EOL>

Shall return the official record_id for the VLR

        .. note::

            Even if the VLR has one record_id, the return type must be a tuple

        Returns
        -------
        tuple of int
            The record_ids this VLR type can have


pass<EOL>

Shall return the bytes corresponding to the record_data part of the VLR
        as they should be written in the file.

        Returns
        -------
        bytes
            The bytes of the vlr's record_data


pass<EOL>

Shall parse the given record_data into a user-friendlier structure

        Parameters
        ----------
        record_data: bytes
            The record_data bytes read from the file


out.write(bytes(self.header))<EOL>out.write(self.record_data)<EOL>

Write the raw header content to the out stream

        Parameters:
        ----------
        out : {file object}
            The output stream


raw_vlr = cls()<EOL>header = RawVLRHeader.from_stream(data_stream)<EOL>raw_vlr.header = header<EOL>raw_vlr.record_data = data_stream.read(header.record_length_after_header)<EOL>return raw_vlr<EOL>

Instantiate a RawVLR by reading the content from the
        data stream

        Parameters:
        ----------
        data_stream : {file object}
            The input stream
        Returns
        -------
        RawVLR
            The RawVLR read


for vlr in self.vlrs:<EOL><INDENT>vlr.write_to(out_stream)<EOL><DEDENT>

Writes all the raw vlrs contained in list to
        the out_stream

        Parameters
        ----------
        out_stream: io.RawIOBase
            The stream where vlrs will be written to


raw_vlrs = cls()<EOL>for vlr in vlrs:<EOL><INDENT>raw = RawVLR()<EOL>raw.header.user_id = vlr.user_id.encode("<STR_LIT:utf8>")<EOL>raw.header.description = vlr.description.encode("<STR_LIT:utf8>")<EOL>raw.header.record_id = vlr.record_id<EOL>raw.record_data = vlr.record_data_bytes()<EOL>raw_vlrs.append(raw)<EOL><DEDENT>return raw_vlrs<EOL>

Construct a RawVLR list from a list of vlrs

        Parameters
        ----------
        vlrs: iterable of VLR

        Returns
        -------
        RawVLRList


self.vlrs.append(vlr)<EOL>

append a vlr to the list

        Parameters
        ----------
        vlr: RawVlR or VLR or KnownVlr

        Returns
        -------


append all elements of the vlr_list into self


def get_by_id(self, user_id="<STR_LIT>", record_ids=(None,)):

if user_id != "<STR_LIT>" and record_ids != (None,):<EOL><INDENT>return [<EOL>vlr<EOL>for vlr in self.vlrs<EOL>if vlr.user_id == user_id and vlr.record_id in record_ids<EOL>]<EOL><DEDENT>else:<EOL><INDENT>return [<EOL>vlr<EOL>for vlr in self.vlrs<EOL>if vlr.user_id == user_id or vlr.record_id in record_ids<EOL>]<EOL><DEDENT>

Function to get vlrs by user_id and/or record_ids.
        Always returns a list even if only one vlr matches the user_id and record_id

        >>> import pylas
        >>> from pylas.vlrs.known import ExtraBytesVlr, WktCoordinateSystemVlr
        >>> las = pylas.read("pylastests/extrabytes.las")
        >>> las.vlrs
        [<ExtraBytesVlr(extra bytes structs: 5)>]
        >>> las.vlrs.get(WktCoordinateSystemVlr.official_user_id())
        []
        >>> las.vlrs.get(WktCoordinateSystemVlr.official_user_id())[0]
        Traceback (most recent call last):
        IndexError: list index out of range
        >>> las.vlrs.get_by_id(ExtraBytesVlr.official_user_id())
        [<ExtraBytesVlr(extra bytes structs: 5)>]
        >>> las.vlrs.get_by_id(ExtraBytesVlr.official_user_id())[0]
        <ExtraBytesVlr(extra bytes structs: 5)>

        Parameters
        ----------
        user_id: str, optional
                 the user id
        record_ids: iterable of int, optional
                    THe record ids of the vlr(s) you wish to get

        Returns
        -------
        :py:class:`list`
            a list of vlrs matching the user_id and records_ids


return [v for v in self.vlrs if v.__class__.__name__ == vlr_type]<EOL>

Returns the list of vlrs of the requested type
        Always returns a list even if there is only one VLR of type vlr_type.

        >>> import pylas
        >>> las = pylas.read("pylastests/extrabytes.las")
        >>> las.vlrs
        [<ExtraBytesVlr(extra bytes structs: 5)>]
        >>> las.vlrs.get("WktCoordinateSystemVlr")
        []
        >>> las.vlrs.get("WktCoordinateSystemVlr")[0]
        Traceback (most recent call last):
        IndexError: list index out of range
        >>> las.vlrs.get('ExtraBytesVlr')
        [<ExtraBytesVlr(extra bytes structs: 5)>]
        >>> las.vlrs.get('ExtraBytesVlr')[0]
        <ExtraBytesVlr(extra bytes structs: 5)>

        Parameters
        ----------
        vlr_type: str
                  the class name of the vlr

        Returns
        -------
        :py:class:`list`
            a List of vlrs matching the user_id and records_ids


kept_vlrs, extracted_vlrs = [], []<EOL>for vlr in self.vlrs:<EOL><INDENT>if vlr.__class__.__name__ == vlr_type:<EOL><INDENT>extracted_vlrs.append(vlr)<EOL><DEDENT>else:<EOL><INDENT>kept_vlrs.append(vlr)<EOL><DEDENT><DEDENT>self.vlrs = kept_vlrs<EOL>return extracted_vlrs<EOL>

Returns the list of vlrs of the requested type
        The difference with get is that the returned vlrs will be removed from the list

        Parameters
        ----------
        vlr_type: str
                  the class name of the vlr

        Returns
        -------
        list
            a List of vlrs matching the user_id and records_ids


@classmethod<EOL><INDENT>def read_from(cls, data_stream, num_to_read):<DEDENT>

vlrlist = cls()<EOL>for _ in range(num_to_read):<EOL><INDENT>raw = RawVLR.read_from(data_stream)<EOL>try:<EOL><INDENT>vlrlist.append(vlr_factory(raw))<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>logger.error("<STR_LIT>".format(raw))<EOL><DEDENT><DEDENT>return vlrlist<EOL>

Reads vlrs and parse them if possible from the stream

        Parameters
        ----------
        data_stream : io.BytesIO
                      stream to read from
        num_to_read : int
                      number of vlrs to be read

        Returns
        -------
        pylas.vlrs.vlrlist.VLRList
            List of vlrs


def parse_geo_tiff_keys_from_vlrs(vlr_list: vlrlist.VLRList) -> List[GeoTiffKey]:

geo_key_dir = vlr_list.get_by_id(<EOL>GeoKeyDirectoryVlr.official_user_id(), GeoKeyDirectoryVlr.official_record_ids()<EOL>)[<NUM_LIT:0>]<EOL>geo_doubles = vlr_list.get_by_id(<EOL>GeoDoubleParamsVlr.official_user_id(), GeoDoubleParamsVlr.official_record_ids()<EOL>)[<NUM_LIT:0>]<EOL>geo_ascii = vlr_list.get_by_id(<EOL>GeoAsciiParamsVlr.official_user_id(), GeoAsciiParamsVlr.official_record_ids()<EOL>)[<NUM_LIT:0>]<EOL>return parse_geo_tiff(geo_key_dir, geo_doubles, geo_ascii)<EOL>

Gets the 3 GeoTiff vlrs from the vlr_list and parse them into
    a nicer structure

    Parameters
    ----------
    vlr_list: pylas.vrls.vlrslist.VLRList list of vlrs from a las file

    Raises
    ------
        IndexError if any of the needed GeoTiffVLR is not found in the list

    Returns
    -------
    List of GeoTiff keys parsed from the VLRs


def parse_geo_tiff(<EOL>key_dir_vlr: GeoKeyDirectoryVlr,<EOL>double_vlr: GeoDoubleParamsVlr,<EOL>ascii_vlr: GeoAsciiParamsVlr,<EOL>) -> List[GeoTiffKey]:

geotiff_keys = []<EOL>for k in key_dir_vlr.geo_keys:<EOL><INDENT>if k.tiff_tag_location == <NUM_LIT:0>:<EOL><INDENT>value = k.value_offset<EOL><DEDENT>elif k.tiff_tag_location == <NUM_LIT>:<EOL><INDENT>value = double_vlr.doubles[k.value_offset]<EOL><DEDENT>elif k.tiff_tag_location == <NUM_LIT>:<EOL><INDENT>try:<EOL><INDENT>value = ascii_vlr.strings[k.value_offset][k.count :]<EOL><DEDENT>except IndexError:<EOL><INDENT>value = ascii_vlr.strings[<NUM_LIT:0>][k.value_offset : k.value_offset + k.count]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>".format(<EOL>k.tiff_tag_location<EOL>)<EOL>)<EOL>continue<EOL><DEDENT>geotiff_keys.append(GeoTiffKey(k.id, value))<EOL><DEDENT>return geotiff_keys<EOL>

Parses the GeoTiff VLRs information into nicer structs


self.driver = get_database_instance(config)<EOL>self.logger = logging.getLogger('<STR_LIT>')<EOL>logging.basicConfig(level=logging.INFO)<EOL>

Initialize a :class:`~.Plugin` instance and connect to Elasticsearch.


return '<STR_LIT>'<EOL>

str: the type of this plugin (``'Elasticsearch'``)


Write obj in elasticsearch.
        :param obj: value to be written in elasticsearch.
        :param resource_id: id for the resource.
        :return: id of the transaction.


self.logger.debug('<STR_LIT>'.format(resource_id))<EOL>return self.driver._es.get(<EOL>index=self.driver._index,<EOL>id=resource_id,<EOL>doc_type='<STR_LIT>'<EOL>)['<STR_LIT>']<EOL>

Read object in elasticsearch using the resource_id.
        :param resource_id: id of the object to be read.
        :return: object value from elasticsearch.


Update object in elasticsearch using the resource_id.
        :param metadata: new metadata for the transaction.
        :param resource_id: id of the object to be updated.
        :return: id of the object.


Delete an object from elasticsearch.
        :param resource_id: id of the object to be deleted.
        :return:


def list(self, search_from=None, search_to=None, limit=None):

self.logger.debug('<STR_LIT>')<EOL>body = {<EOL>'<STR_LIT>': [<EOL>{"<STR_LIT>": "<STR_LIT>"},<EOL>],<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': {}<EOL>}<EOL>}<EOL>if search_from:<EOL><INDENT>body['<STR_LIT>'] = search_from<EOL><DEDENT>if search_to:<EOL><INDENT>body['<STR_LIT:size>'] = search_to - search_from<EOL><DEDENT>if limit:<EOL><INDENT>body['<STR_LIT:size>'] = limit<EOL><DEDENT>page = self.driver._es.search(<EOL>index=self.driver._index,<EOL>doc_type='<STR_LIT>',<EOL>body=body<EOL>)<EOL>object_list = []<EOL>for x in page['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>object_list.append(x['<STR_LIT>'])<EOL><DEDENT>return object_list<EOL>

List all the objects saved elasticsearch.
         :param search_from: start offset of objects to return.
         :param search_to: last offset of objects to return.
         :param limit: max number of values to be returned.
         :return: list with transactions.


def query(self, search_model: QueryModel):

query_parsed = query_parser(search_model.query)<EOL>self.logger.debug(f'<STR_LIT>')<EOL>if search_model.sort is not None:<EOL><INDENT>self._mapping_to_sort(search_model.sort.keys())<EOL>sort = self._sort_object(search_model.sort)<EOL><DEDENT>else:<EOL><INDENT>sort = [{"<STR_LIT>": "<STR_LIT>"}]<EOL><DEDENT>if search_model.query == {}:<EOL><INDENT>query = {'<STR_LIT>': {}}<EOL><DEDENT>else:<EOL><INDENT>query = query_parsed[<NUM_LIT:0>]<EOL><DEDENT>body = {<EOL>'<STR_LIT>': query,<EOL>'<STR_LIT>': sort,<EOL>'<STR_LIT>': (search_model.page - <NUM_LIT:1>) * search_model.offset,<EOL>'<STR_LIT:size>': search_model.offset,<EOL>}<EOL>page = self.driver._es.search(<EOL>index=self.driver._index,<EOL>doc_type='<STR_LIT>',<EOL>body=body,<EOL>q=query_parsed[<NUM_LIT:1>]<EOL>)<EOL>object_list = []<EOL>for x in page['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>object_list.append(x['<STR_LIT>'])<EOL><DEDENT>return object_list<EOL>

Query elasticsearch for objects.
        :param search_model: object of QueryModel.
        :return: list of objects that match the query.


def text_query(self, search_model: FullTextModel):

self.logger.debug('<STR_LIT>'.format(search_model.text))<EOL>if search_model.sort is not None:<EOL><INDENT>self._mapping_to_sort(search_model.sort.keys())<EOL>sort = self._sort_object(search_model.sort)<EOL><DEDENT>else:<EOL><INDENT>sort = [{"<STR_LIT>": "<STR_LIT>"}]<EOL><DEDENT>body = {<EOL>'<STR_LIT>': sort,<EOL>'<STR_LIT>': (search_model.page - <NUM_LIT:1>) * search_model.offset,<EOL>'<STR_LIT:size>': search_model.offset,<EOL>}<EOL>page = self.driver._es.search(<EOL>index=self.driver._index,<EOL>doc_type='<STR_LIT>',<EOL>body=body,<EOL>q=search_model.text<EOL>)<EOL>object_list = []<EOL>for x in page['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>object_list.append(x['<STR_LIT>'])<EOL><DEDENT>return object_list<EOL>

Query elasticsearch for objects.
        :param search_model: object of FullTextModel
        :return: list of objects that match the query.


self.varname_dict = {}<EOL>self.varobj_dict = {}<EOL>varis = set()<EOL>for d in cnf.dis:<EOL><INDENT>for v in d:<EOL><INDENT>varis.add(v.name)<EOL><DEDENT><DEDENT>ret = "<STR_LIT>" % (len(varis), len(cnf.dis))<EOL>varis = dict(list(zip(sorted(list(varis)),list(map(str,list(range(<NUM_LIT:1>,len(varis)+<NUM_LIT:1>)))))))<EOL>for v in varis:<EOL><INDENT>vo = Variable(v)<EOL>self.varname_dict[vo] = varis[v]<EOL>self.varobj_dict[varis[v]] = vo<EOL><DEDENT>for d in cnf.dis:<EOL><INDENT>ret += "<STR_LIT:\n>"<EOL>vnamelist = []<EOL>for v in d:<EOL><INDENT>vnamelist.append(("<STR_LIT:->" if v.inverted else "<STR_LIT>") + varis[v.name])<EOL><DEDENT>ret += "<STR_LIT:U+0020>".join(vnamelist) + "<STR_LIT>"<EOL><DEDENT>return ret<EOL>

Convert Cnf object ot Dimacs cnf string

        cnf: Cnf object

        In the converted Cnf there will be only numbers for
        variable names. The conversion guarantees that the
        variables will be numbered alphabetically.


output = Cnf()<EOL>for x in cnf.dis:<EOL><INDENT>dont_add = False<EOL>for y in x:<EOL><INDENT>for z in x:<EOL><INDENT>if z == -y:<EOL><INDENT>dont_add = True<EOL>break<EOL><DEDENT><DEDENT>if dont_add: break<EOL><DEDENT>if dont_add: continue<EOL>if x not in output.dis:<EOL><INDENT>output.dis |= frozenset([x])<EOL><DEDENT><DEDENT>return output<EOL>

I just found a remarkably large bug in my SAT solver and found an
interesting solution.
Remove all b | -b
(-b | b) & (b | -a) & (-b | a) & (a | -a)
becomes
(b | -a) & (-b | a)

Remove all (-e) & (-e)
(-e | a) & (-e | a) & (-e | a) & (-e | a)
becomes
(-e | a)
(-b | b | c) becomes nothing, not (c)


if limbdark.ldmodel == QUADRATIC:<EOL><INDENT>u1 = limbdark.u1<EOL>u2 = limbdark.u2<EOL>return (<NUM_LIT:1>-u1*(<NUM_LIT:1>-np.sqrt(<NUM_LIT:1>-r**<NUM_LIT:2>))-u2*(<NUM_LIT:1>-np.sqrt(<NUM_LIT:1>-r**<NUM_LIT:2>))**<NUM_LIT:2>)/(<NUM_LIT:1>-u1/<NUM_LIT:3>-u2/<NUM_LIT:6>)/np.pi<EOL><DEDENT>elif limbdark.ldmodel == KIPPING:<EOL><INDENT>a = np.sqrt(limbdark.q1)<EOL>b = <NUM_LIT:2>*limbdark.q2<EOL>u1 = a*b<EOL>u2 = a*(<NUM_LIT:1> - b)<EOL>return (<NUM_LIT:1>-u1*(<NUM_LIT:1>-np.sqrt(<NUM_LIT:1>-r**<NUM_LIT:2>))-u2*(<NUM_LIT:1>-np.sqrt(<NUM_LIT:1>-r**<NUM_LIT:2>))**<NUM_LIT:2>)/(<NUM_LIT:1>-u1/<NUM_LIT:3>-u2/<NUM_LIT:6>)/np.pi<EOL><DEDENT>elif limbdark.ldmodel == NONLINEAR:<EOL><INDENT>raise Exception('<STR_LIT>')                           <EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>

The standard quadratic limb darkening law.

:param ndarray r: The radius vector
:param limbdark: A :py:class:`pysyzygy.transit.LIMBDARK` instance containing
                 the limb darkening law information

:returns: The stellar intensity as a function of `r`


def PlotTransit(compact = False, ldplot = True, plottitle = "<STR_LIT>", <EOL>xlim = None, binned = True, **kwargs):

<EOL>fig = pl.figure(figsize = (<NUM_LIT:12>,<NUM_LIT:8>))<EOL>fig.subplots_adjust(hspace=<NUM_LIT>)<EOL>ax1, ax2 = pl.subplot(<NUM_LIT>), pl.subplot(<NUM_LIT>)<EOL>if not compact:<EOL><INDENT>fig.subplots_adjust(right = <NUM_LIT>)<EOL><DEDENT>t0 = kwargs.pop('<STR_LIT>', <NUM_LIT:0.>)<EOL>trn = Transit(**kwargs)<EOL>try:<EOL><INDENT>trn.Compute()<EOL>notransit = False<EOL><DEDENT>except Exception as e:<EOL><INDENT>if str(e) == "<STR_LIT>":<EOL><INDENT>notransit = True<EOL><DEDENT>else: raise Exception(e)<EOL><DEDENT>time = trn.arrays.time + t0<EOL>if not notransit:<EOL><INDENT>if binned:<EOL><INDENT>trn.Bin()<EOL>flux = trn.arrays.bflx<EOL><DEDENT>else:<EOL><INDENT>flux = trn.arrays.flux<EOL><DEDENT>time = np.concatenate(([-<NUM_LIT>], time, [<NUM_LIT>]))                                    <EOL>flux = np.concatenate(([<NUM_LIT:1.>], flux, [<NUM_LIT:1.>]))<EOL>ax1.plot(time, flux, '<STR_LIT:->', color='<STR_LIT>')<EOL>rng = np.max(flux) - np.min(flux)<EOL>if rng > <NUM_LIT:0>:<EOL><INDENT>ax1.set_ylim(np.min(flux) - <NUM_LIT:0.1>*rng, np.max(flux) + <NUM_LIT:0.1>*rng)<EOL>left = np.argmax(flux < (<NUM_LIT:1.> - <NUM_LIT>))<EOL>right = np.argmax(flux[left:] > (<NUM_LIT:1.> - <NUM_LIT>)) + left<EOL>rng = time[right] - time[left]        <EOL>ax1.set_xlim(time[left] - rng, time[right] + rng)<EOL><DEDENT><DEDENT>ax1.set_xlabel('<STR_LIT>', fontweight='<STR_LIT>')<EOL>ax1.set_ylabel('<STR_LIT>', fontweight='<STR_LIT>')<EOL>maxpts = kwargs.get('<STR_LIT>', <NUM_LIT>); kwargs.update({'<STR_LIT>': maxpts})<EOL>per = kwargs.get('<STR_LIT>', <NUM_LIT>); kwargs.update({'<STR_LIT>': per})<EOL>kwargs.update({'<STR_LIT>': True})<EOL>kwargs.update({'<STR_LIT>': <NUM_LIT:30>})<EOL>kwargs.update({'<STR_LIT>': <NUM_LIT:50> * per / maxpts})<EOL>trn = Transit(**kwargs)<EOL>try:<EOL><INDENT>trn.Compute()<EOL><DEDENT>except Exception as e:<EOL><INDENT>if str(e) == "<STR_LIT>":<EOL><INDENT>pass<EOL><DEDENT>else: raise Exception(e)<EOL><DEDENT>x = trn.arrays.x<EOL>y = trn.arrays.y<EOL>z = trn.arrays.z<EOL>inc = (np.arccos(trn.transit.bcirc/trn.transit.aRs)*<NUM_LIT>/np.pi)                     <EOL>for j in range(len(x)):<EOL><INDENT>if (x[j]**<NUM_LIT:2> + y[j]**<NUM_LIT:2>) < <NUM_LIT:1.> and (z[j] > <NUM_LIT:0>):<EOL><INDENT>x[j] = np.nan<EOL>y[j] = np.nan<EOL><DEDENT><DEDENT>r = np.linspace(<NUM_LIT:0>,<NUM_LIT:1>,<NUM_LIT:100>)<EOL>Ir = I(r,trn.limbdark)/I(<NUM_LIT:0>,trn.limbdark)<EOL>for ri,Iri in zip(r[::-<NUM_LIT:1>],Ir[::-<NUM_LIT:1>]):<EOL><INDENT>star = pl.Circle((<NUM_LIT:0>, <NUM_LIT:0>), ri, color=str(<NUM_LIT>*Iri), alpha=<NUM_LIT:1.>)<EOL>ax2.add_artist(star)<EOL><DEDENT>if ldplot:<EOL><INDENT>if compact:<EOL><INDENT>inset1 = pl.axes([<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>])<EOL><DEDENT>else:<EOL><INDENT>inset1 = fig.add_axes([<NUM_LIT>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT>])<EOL><DEDENT>inset1.plot(r,Ir,'<STR_LIT>')<EOL>pl.setp(inset1, xlim=(-<NUM_LIT:0.1>,<NUM_LIT>), ylim=(-<NUM_LIT:0.1>,<NUM_LIT>), xticks=[<NUM_LIT:0>,<NUM_LIT:1>], yticks=[<NUM_LIT:0>,<NUM_LIT:1>])<EOL>for tick in inset1.xaxis.get_major_ticks() + inset1.yaxis.get_major_ticks():<EOL><INDENT>tick.label.set_fontsize(<NUM_LIT:8>)<EOL><DEDENT>inset1.set_ylabel(r'<STR_LIT>', fontsize=<NUM_LIT:8>, labelpad=-<NUM_LIT:8>)<EOL>inset1.set_xlabel(r'<STR_LIT>', fontsize=<NUM_LIT:8>, labelpad=-<NUM_LIT:8>)<EOL>inset1.set_title('<STR_LIT>', fontweight='<STR_LIT>', fontsize=<NUM_LIT:9>)<EOL><DEDENT>if compact:<EOL><INDENT>inset2 = pl.axes([<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>])<EOL><DEDENT>else:<EOL><INDENT>inset2 = fig.add_axes([<NUM_LIT>,<NUM_LIT:0.1>,<NUM_LIT>,<NUM_LIT>])<EOL><DEDENT>pl.setp(inset2, xticks=[], yticks=[])<EOL>trn.transit.bcirc = trn.transit.aRs                                                 <EOL>try:<EOL><INDENT>trn.Compute()<EOL><DEDENT>except Exception as e:<EOL><INDENT>if str(e) == "<STR_LIT>":<EOL><INDENT>pass<EOL><DEDENT>else: raise Exception(e)<EOL><DEDENT>xp = trn.arrays.x<EOL>yp = trn.arrays.y<EOL>inset2.plot(xp, yp, '<STR_LIT:->', color='<STR_LIT>', alpha=<NUM_LIT:0.5>)<EOL>xmin, xmax, ymin, ymax = np.nanmin(xp), np.nanmax(xp), np.nanmin(yp), np.nanmax(yp)<EOL>xrng = xmax - xmin<EOL>yrng = ymax - ymin<EOL>xmin -= <NUM_LIT:0.1>*xrng; xmax += <NUM_LIT:0.1>*xrng;<EOL>ymin -= <NUM_LIT:0.1>*yrng; ymax += <NUM_LIT:0.1>*yrng;<EOL>inset2.scatter([xmin,xmin,xmax,xmax], [ymin,ymax,ymin,ymax], alpha = <NUM_LIT:0.>)<EOL>for ri,Iri in zip(r[::-<NUM_LIT:10>],Ir[::-<NUM_LIT:10>]):<EOL><INDENT>star = pl.Circle((<NUM_LIT:0>, <NUM_LIT:0>), ri, color=str(<NUM_LIT>*Iri), alpha=<NUM_LIT:1.>)<EOL>inset2.add_artist(star)<EOL><DEDENT>ycenter = yp[np.where(np.abs(xp) == np.nanmin(np.abs(xp)))][<NUM_LIT:0>]<EOL>while ycenter > <NUM_LIT:0>:<EOL><INDENT>xp[np.where(np.abs(xp) == np.nanmin(np.abs(xp)))] = np.nan<EOL>ycenter = yp[np.where(np.abs(xp) == np.nanmin(np.abs(xp)))][<NUM_LIT:0>]<EOL><DEDENT>planet = pl.Circle((<NUM_LIT:0>, ycenter), trn.transit.RpRs, color='<STR_LIT>', alpha=<NUM_LIT:1.>)<EOL>inset2.add_artist(planet)<EOL>inset2.set_title('<STR_LIT>', fontweight='<STR_LIT>', fontsize=<NUM_LIT:9>)<EOL>inset2.set_aspect('<STR_LIT>','<STR_LIT>')<EOL>with np.errstate(invalid='<STR_LIT:ignore>'):<EOL><INDENT>ax2.plot(x, y, '<STR_LIT:->', color='<STR_LIT>', lw = <NUM_LIT:1.> if per < <NUM_LIT> else <EOL>max(<NUM_LIT:1.> - (per - <NUM_LIT>) / <NUM_LIT>, <NUM_LIT>) )<EOL><DEDENT>with np.errstate(invalid = '<STR_LIT:ignore>'):<EOL><INDENT>ycenter = y[np.where(np.abs(x) == np.nanmin(np.abs(x)))][<NUM_LIT:0>]<EOL><DEDENT>while ycenter > <NUM_LIT:0>:<EOL><INDENT>x[np.where(np.abs(x) == np.nanmin(np.abs(x)))] = np.nan<EOL>ycenter = y[np.where(np.abs(x) == np.nanmin(np.abs(x)))][<NUM_LIT:0>]<EOL><DEDENT>planet = pl.Circle((<NUM_LIT:0>, ycenter), trn.transit.RpRs, color='<STR_LIT>', alpha=<NUM_LIT:1.>)<EOL>ax2.add_artist(planet)<EOL>if xlim is None:<EOL><INDENT>xlim = <NUM_LIT> * max(np.nanmax(x), np.nanmax(-x))<EOL><DEDENT>ax2.set_ylim(-xlim/<NUM_LIT>,xlim/<NUM_LIT>)<EOL>ax2.set_xlim(-xlim,xlim)<EOL>ax2.set_xlabel(r'<STR_LIT>', fontweight='<STR_LIT>')<EOL>ax2.set_ylabel(r'<STR_LIT>', fontweight='<STR_LIT>')<EOL>ax1.set_title(plottitle, fontsize=<NUM_LIT:12>)<EOL>if not compact:<EOL><INDENT>rect = <NUM_LIT>,<NUM_LIT>,<NUM_LIT>,<NUM_LIT><EOL>ax3 = fig.add_axes(rect)<EOL>ax3.xaxis.set_visible(False)<EOL>ax3.yaxis.set_visible(False)<EOL>ltable = [ r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>']<EOL>rtable = [ r'<STR_LIT>' % trn.transit.per,<EOL>r'<STR_LIT>' % trn.transit.ecc,<EOL>r'<STR_LIT>' % inc,<EOL>r'<STR_LIT>' % (trn.transit.w*<NUM_LIT>/np.pi),<EOL>r'<STR_LIT>' % trn.transit.rhos,<EOL>r'<STR_LIT>' % trn.transit.MpMs,<EOL>r'<STR_LIT>' % trn.transit.RpRs,<EOL>r'<STR_LIT>' % trn.limbdark.q1,<EOL>r'<STR_LIT>' % trn.limbdark.q2]<EOL>yt = <NUM_LIT><EOL>for l,r in zip(ltable, rtable):<EOL><INDENT>ax3.annotate(l, xy=(<NUM_LIT>, yt), xycoords="<STR_LIT>", ha='<STR_LIT:right>', fontsize=<NUM_LIT:16>)<EOL>ax3.annotate(r, xy=(<NUM_LIT>, yt), xycoords="<STR_LIT>", fontsize=<NUM_LIT:16>)<EOL>yt -= <NUM_LIT:0.1><EOL><DEDENT><DEDENT>return fig<EOL>

Plots a light curve described by `kwargs`

:param bool compact: Display the compact version of the plot? Default `False`
:param bool ldplot: Displat the limb darkening inset? Default `True`
:param str plottitle: The title of the plot. Default `""`
:param float xlim: The half-width of the orbit plot in stellar radii. Default is to \
                   auto adjust this
:param bool binned: Bin the light curve model to the exposure time? Default `True`
:param kwargs: Any keyword arguments to be passed to :py:func:`pysyzygy.transit.Transit`

:returns fig: The :py:mod:`matplotlib` figure object


ecc = self.ecc if not np.isnan(self.ecc) else np.sqrt(self.ecw**<NUM_LIT:2> + self.esw**<NUM_LIT:2>)<EOL>esw = self.esw if not np.isnan(self.esw) else ecc * np.sin(self.w)<EOL>aRs = ((G * self.rhos * (<NUM_LIT:1.> + self.MpMs) * <EOL>(self.per * DAYSEC)**<NUM_LIT>) / (<NUM_LIT> * np.pi))**(<NUM_LIT:1.>/<NUM_LIT>)<EOL>inc = np.arccos(self.bcirc/aRs)<EOL>becc = self.bcirc * (<NUM_LIT:1> - ecc**<NUM_LIT:2>)/(<NUM_LIT:1> - esw)<EOL>tdur = self.per / <NUM_LIT> / np.pi * np.arcsin(((<NUM_LIT:1.> + self.RpRs)**<NUM_LIT:2> -<EOL>becc**<NUM_LIT:2>)**<NUM_LIT:0.5> / (np.sin(inc) * aRs))<EOL>tdur *= np.sqrt(<NUM_LIT:1.> - ecc**<NUM_LIT>)/(<NUM_LIT:1.> - esw)<EOL>return tdur<EOL>

The approximate transit duration for the general case of an eccentric orbit


if kwargs.get('<STR_LIT>', True):<EOL><INDENT>valid = [y[<NUM_LIT:0>] for x in [TRANSIT, LIMBDARK, SETTINGS] for y in x._fields_]       <EOL>valid += ['<STR_LIT:b>', '<STR_LIT>']                                                         <EOL>for k in kwargs.keys():<EOL><INDENT>if k not in valid:<EOL><INDENT>raise Exception("<STR_LIT>" % k)  <EOL><DEDENT><DEDENT><DEDENT>if ('<STR_LIT>' in kwargs.keys()) and ('<STR_LIT>' in kwargs.keys()):<EOL><INDENT>kwargs.update({'<STR_LIT>': KIPPING})<EOL><DEDENT>elif ('<STR_LIT>' in kwargs.keys()) and ('<STR_LIT>' in kwargs.keys()) and('<STR_LIT>' in kwargs.keys()) and ('<STR_LIT>' in kwargs.keys()):<EOL><INDENT>kwargs.update({'<STR_LIT>': NONLINEAR})<EOL><DEDENT>self.limbdark.update(**kwargs)<EOL>self.transit.update(**kwargs)<EOL>self.settings.update(**kwargs)<EOL>


err = _Compute(self.transit, self.limbdark, self.settings, self.arrays)<EOL>if err != _ERR_NONE: RaiseError(err)<EOL>


err = _Bin(self.transit, self.limbdark, self.settings, self.arrays)<EOL>if err != _ERR_NONE: RaiseError(err)<EOL>

Bins the light curve model to the provided time array


if self.arrays._calloc:<EOL><INDENT>_dbl_free(self.arrays._time)<EOL>_dbl_free(self.arrays._flux)<EOL>_dbl_free(self.arrays._bflx)<EOL>_dbl_free(self.arrays._M)<EOL>_dbl_free(self.arrays._E)<EOL>_dbl_free(self.arrays._f)<EOL>_dbl_free(self.arrays._r)<EOL>_dbl_free(self.arrays._x)<EOL>_dbl_free(self.arrays._y)<EOL>_dbl_free(self.arrays._z)<EOL>self.arrays._calloc = <NUM_LIT:0><EOL><DEDENT>if self.arrays._balloc:  <EOL><INDENT>_dbl_free(self.arrays._b)<EOL>self.arrays._balloc = <NUM_LIT:0><EOL><DEDENT>if self.arrays._ialloc:<EOL><INDENT>_dbl_free(self.arrays._iarr)<EOL>self.arrays._ialloc = <NUM_LIT:0><EOL><DEDENT>

Frees the memory used by all of the dynamically allocated C arrays.


self.Free()<EOL>

Free the C arrays when the last reference to the class goes out of scope!


if name is None:<EOL><INDENT>name = '<STR_LIT>'<EOL><DEDENT>attrs = {}<EOL>for field_name, field_info in six.iteritems(data_struct_dict):<EOL><INDENT>field_type = field_info['<STR_LIT:type>']<EOL>if field_type == DictField.FIELD_TYPE_NAME and isinstance(field_info.get('<STR_LIT>'), dict):<EOL><INDENT>field_info['<STR_LIT>'] = create_validator(field_info['<STR_LIT>'])<EOL><DEDENT>attrs[field_name] = create_field(field_info)<EOL><DEDENT>name = force_str(name)<EOL>return type(name, (Validator, ), attrs)<EOL>

create a Validator instance from data_struct_dict

:param data_struct_dict: a dict describe validator's fields, like the dict `to_dict()` method returned.
:param name: name of Validator class

:return: Validator instance


assert isinstance(raw_data, dict), '<STR_LIT>'.format(type(raw_data).__name__)<EOL>self.raw_data = raw_data<EOL>self.validated_data = None<EOL>self.errors = {}<EOL>


return data<EOL>

model-level validate.
sub-class can override this method to validate data, return modified data


d = dict()<EOL>for name, field in six.iteritems(cls._FIELDS_MAP):<EOL><INDENT>field_info = field.to_dict()<EOL>d[name] = field_info<EOL><DEDENT>return d<EOL>


mocking_data = {}<EOL>for name, field in six.iteritems(cls._FIELDS_MAP):<EOL><INDENT>mocking_data[name] = field.mock_data()<EOL><DEDENT>return mocking_data<EOL>

return random mocking data.
mocking data will be valid in most case, but it maybe can't pass from your own `validate` method or `validator`


field_type = field_info.get('<STR_LIT:type>')<EOL>if field_type not in FIELDS_NAME_MAP:<EOL><INDENT>raise ValueError(_('<STR_LIT>').format(field_type))<EOL><DEDENT>field_class = FIELDS_NAME_MAP.get(field_type)<EOL>params = dict(field_info)<EOL>params.pop('<STR_LIT:type>')<EOL>return field_class.from_dict(params)<EOL>


def __init__(self, strict=True, default=EMPTY_VALUE, validators=None, required=False, **kwargs):

self.strict = strict<EOL>self.default = default<EOL>if validators is None:<EOL><INDENT>validators = []<EOL><DEDENT>elif not isinstance(validators, (tuple, list)):<EOL><INDENT>validators = [validators]<EOL><DEDENT>self.validators = validators<EOL>self.required = required<EOL>

:param strict: bool, if strict is True, value must be an instance of INTERVAL_TYPE,
                otherwise, value should be convert to INTERNAL_TYPE
:param default: default value, defaults to EMPTY_VALUE
:param validators: a validator list, validator can be function, other callable object or object that have method named validate
:param required: bool, indicate that this field is whether required


params = list(cls.PARAMS)<EOL>bases = cls.__bases__<EOL>for base in bases:<EOL><INDENT>if issubclass(base, BaseField):<EOL><INDENT>params.extend(base._get_all_params())<EOL><DEDENT><DEDENT>return params<EOL>

Collect all PARAMS from this class and its parent class.


value = self._validate(value)<EOL>for v in self.validators:<EOL><INDENT>v(value)<EOL><DEDENT>return value<EOL>

return validated value or raise FieldValidationError.


return self._validate_type(value)<EOL>

return validated value or raise FieldValidationError.
sub-class should override this method.


if not isinstance(value, self.INTERNAL_TYPE):<EOL><INDENT>if self.strict:<EOL><INDENT>raise exceptions.FieldValidationError(<EOL>_('<STR_LIT>').format(type(value).__name__, self.FIELD_TYPE_NAME))<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>value = self._convert_type(value)<EOL><DEDENT>except (ValueError, TypeError) as e:<EOL><INDENT>raise exceptions.FieldValidationError(<EOL>_('<STR_LIT>').format(type(value).__name__, self.FIELD_TYPE_NAME, str(e)))<EOL><DEDENT><DEDENT><DEDENT>return value<EOL>


if callable(self.default):<EOL><INDENT>return self.default()<EOL><DEDENT>else:<EOL><INDENT>return self.default<EOL><DEDENT>


return value<EOL>


d = {<EOL>'<STR_LIT:type>': self.FIELD_TYPE_NAME,<EOL>}<EOL>params = self._get_all_params()<EOL>for name in params:<EOL><INDENT>if hasattr(self, name):<EOL><INDENT>value = getattr(self, name)<EOL>if value is EMPTY_VALUE:<EOL><INDENT>value = '<STR_LIT>'<EOL><DEDENT>d[name] = value<EOL><DEDENT><DEDENT>return d<EOL>


if params.get('<STR_LIT:default>') == '<STR_LIT>':<EOL><INDENT>params['<STR_LIT:default>'] = EMPTY_VALUE<EOL><DEDENT>return cls(**params)<EOL>

Create a field from params.
sub-class can override this method.


return '<STR_LIT>'<EOL>

reutrn mocking data
sub-class should override this method


def __init__(self, format='<STR_LIT>', **kwargs):

if format not in self.SUPPORT_FORMATS:<EOL><INDENT>raise ValueError(_('<STR_LIT>').format(format))<EOL><DEDENT>self.format = format<EOL>kwargs.setdefault('<STR_LIT:strict>', False)<EOL>super(UUIDField, self).__init__(**kwargs)<EOL>

format: what format used when to_presentation, supports 'hex', 'str', 'int', 'bytes', 'bytes_le'


def __init__(self, validator=None, **kwargs):

self.validator = validator<EOL>super(DictField, self).__init__(**kwargs)<EOL>


def __init__(self, detail=None, code=None):

if detail is None:<EOL><INDENT>detail = self.default_detail<EOL><DEDENT>if code is None:<EOL><INDENT>code = self.default_code<EOL><DEDENT>self.detail = _flat_error_detail(detail)<EOL>self.code = code<EOL>

:param detail: `detail` maybe a string, a dict or a list.
:param code: error code, it not used for now.


def __init__(<EOL>self, service_locator=None, url=None, service_url=None, endpoint=None,<EOL>headers=None, return_body=False, params=None, body=None, json_body=None,<EOL>stream=False, throws=None):

self._service_locator = service_locator<EOL>self._url = url<EOL>self._service_url = service_url<EOL>self._endpoint = endpoint<EOL>self._headers = headers if headers is not None else {}<EOL>self._return_body = return_body<EOL>self._params = params if params is not None else {}<EOL>self._body = body<EOL>self._json_body = json_body<EOL>self._stream = stream<EOL>self._throws = throws if throws is not None else []<EOL>

Args:
   service_locator: collaborator which gets the collab services urls
   method: the http method (GET, POST...)
   url: the url to send a request to
   service_url: if url is not set, will be used in conjonction to `endpoint`
                to create the url
   endpoint: is concatenated to `service_url` to create the url
   headers: headers to add to the request as key/value pairs
   return_body: True if the body of the response should be returned,
                False if the response should be returned
   params: params to add to the request as key/value pairs
   body: the body of the request
   json_body: the body of the request as a json object
   stream: stream the response if True


return cls(service_locator=ServiceLocator.new(environment))<EOL>

Create new request builder

            Arguments:
                environment: The service environment to be used for the request

            Returns:
                A request builder instance


return self.__copy_and_set('<STR_LIT:url>', url)<EOL>

Sets the request target url

        Args:
            url (str): The url the request should be targeted to

        Returns:
            The request builder instance in order to chain calls


service_url = self._service_locator.get_service_url(service, version)<EOL>return self.__copy_and_set('<STR_LIT>', self.__strip_trailing_slashes(service_url))<EOL>

Sets the service name and version the request should target

        Args:
            service (str): The name of the service as displayed in the services.json file
            version (str): The version of the service as displayed in the services.json file

        Returns:
            The request builder instance in order to chain calls


return self.__copy_and_set('<STR_LIT>', self.__strip_leading_slashes(endpoint))<EOL>

Sets the endpoint of the service the request should target

        Args:
            endpoint (str): The endpoint that will be concatenated to the service url

        Returns:
            The request builder instance in order to chain calls


copy = headers.copy()<EOL>copy.update(self._headers)<EOL>return self.__copy_and_set('<STR_LIT>', copy)<EOL>

Adds headers to the request

        Args:
            headers (dict): The headers to add the request headers

        Returns:
            The request builder instance in order to chain calls


return self.with_headers({'<STR_LIT>': '<STR_LIT>'.format(token)})<EOL>

Sets the token in the request `Authorization` header

        Args:
            token (str): The token to add the `Authorization` header

        Returns:
            The request builder instance in order to chain calls


copy = params.copy()<EOL>copy.update(self._params)<EOL>return self.__copy_and_set('<STR_LIT>', copy)<EOL>

Adds parameters to the request params

        Args:
            params (dict): The parameters to add to the request params

        Returns:
            The request builder instance in order to chain calls


return self.__copy_and_set('<STR_LIT>', True)<EOL>

Indicates that the body of the response should be returned after the request is sent
           By default the response object is returned

        Returns:
            The request builder instance in order to chain calls


return self.__copy_and_set('<STR_LIT:body>', body)<EOL>

Sets the body of the request

        Args:
            body: The body of the request

        Returns:
            The request builder instance in order to chain calls


return self.__copy_and_set('<STR_LIT>', json_body)<EOL>

Sets the body of the request with a json object

        Args:
            json_body (dict): The json object to send with the request

        Returns:
            The request builder instance in order to chain calls


Indicates that the reponse should be streamed

        Returns:
            The request builder instance in order to chain calls


def throw(self, exception_class, should_throw):

return self.__copy_and_set('<STR_LIT>', self._throws + [(exception_class, should_throw)])<EOL>

Defines if the an exception should be thrown after the request is sent

        Args:
            exception_class (class): The class of the exception to instantiate
            should_throw (function): The predicate that should indicate if the exception
                should be thrown. This function will be called with the response as a parameter

        Returns:
            The request builder instance in order to chain calls


return self.__send('<STR_LIT:GET>')<EOL>

Sends the request as parametrized with the GET verb

        Returns:
            The response object or body depending of the parametrization

        Raises:
            Any exception parametrized with the `throw` method


return self.__send('<STR_LIT:POST>')<EOL>

Sends the request as parametrized with the POST verb

        Returns:
            The response object or body depending of the parametrization

        Raises:
            Any exception parametrized with the `throw` method


return self.__send('<STR_LIT>')<EOL>

Sends the request as parametrized with the DELETE verb

        Returns:
            The response object or body depending of the parametrization

        Raises:
            Any exception parametrized with the `throw` method


return self.__send('<STR_LIT>')<EOL>

Sends the request as parametrized with the PUT verb

        Returns:
            The response object or body depending of the parametrization

        Raises:
            Any exception parametrized with the `throw` method


@classmethod<EOL><INDENT>def new(cls, access_token, environment='<STR_LIT>'):<DEDENT>

return cls(<EOL>storage_client=StorageClient.new(access_token, environment=environment))<EOL>


self.api_client = client<EOL>

Args:
   client: the low level api client


api_client = ApiClient.new(access_token, environment)<EOL>return cls(api_client)<EOL>

Create new storage service client.

            Arguments:
                environment(str): The service environment to be used for the client.
                    'prod' or 'dev'.
                access_token(str): The access token used to authenticate with the
                    service

            Returns:
                A storage_service.Client instance


self.__validate_storage_path(path)<EOL>entity = self.api_client.get_entity_by_query(path=path)<EOL>if entity['<STR_LIT>'] not in self.__BROWSABLE_TYPES:<EOL><INDENT>raise StorageArgumentException('<STR_LIT>'<EOL>'<STR_LIT>'.format(entity['<STR_LIT>']))<EOL><DEDENT>entity_uuid = entity['<STR_LIT>']<EOL>file_names = []<EOL>more_pages = True<EOL>page_number = <NUM_LIT:1><EOL>while more_pages:<EOL><INDENT>response = self.api_client.list_folder_content(<EOL>entity_uuid, page=page_number, ordering='<STR_LIT:name>')<EOL>more_pages = response['<STR_LIT>'] is not None<EOL>page_number += <NUM_LIT:1><EOL>for child in response['<STR_LIT>']:<EOL><INDENT>pattern = '<STR_LIT>' if child['<STR_LIT>'] == '<STR_LIT>' else '<STR_LIT>'<EOL>file_names.append(pattern.format(name=child['<STR_LIT:name>']))<EOL><DEDENT><DEDENT>return file_names<EOL>

List the entities found directly under the given path.

        Args:
            path (str): The path of the entity to be listed. Must start with a '/'.

        Returns:
            The list of entity names directly under the given path:

                u'/12345/folder_1'

        Raises:
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes


def download_file(self, path, target_path):

self.__validate_storage_path(path)<EOL>entity = self.api_client.get_entity_by_query(path=path)<EOL>if entity['<STR_LIT>'] != '<STR_LIT:file>':<EOL><INDENT>raise StorageArgumentException('<STR_LIT>')<EOL><DEDENT>signed_url = self.api_client.get_signed_url(entity['<STR_LIT>'])<EOL>response = self.api_client.download_signed_url(signed_url)<EOL>with open(target_path, "<STR_LIT:wb>") as output:<EOL><INDENT>for chunk in response.iter_content(chunk_size=<NUM_LIT>):<EOL><INDENT>output.write(chunk)<EOL><DEDENT><DEDENT>

Download a file from storage service to local disk.

        Existing files on the target path will be overwritten.
        The download is not recursive, as it only works on files.

        Args:
            path (str): The path of the entity to be downloaded. Must start with a '/'.

        Returns:
            None

        Raises:
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes


self.__validate_storage_path(path)<EOL>try:<EOL><INDENT>metadata = self.api_client.get_entity_by_query(path=path)<EOL><DEDENT>except StorageNotFoundException:<EOL><INDENT>return False<EOL><DEDENT>return metadata and '<STR_LIT>' in metadata<EOL>

Check if a certain path exists in the storage service.

        Args:
            path (str): The path to be checked

        Returns:
            True if the path exists, False otherwise

        Raises:
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes


self.__validate_storage_path(path, projects_allowed=False)<EOL>path_steps = [step for step in path.split('<STR_LIT:/>') if step]<EOL>del path_steps[-<NUM_LIT:1>]<EOL>parent_path = '<STR_LIT>'.format('<STR_LIT:/>'.join(path_steps))<EOL>return self.api_client.get_entity_by_query(path=parent_path)<EOL>

Get the parent entity of the entity pointed by the given path.

        Args:
            path (str): The path of the entity whose parent is needed

        Returns:
            A JSON object of the parent entity if found.

        Raises:
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes


self.__validate_storage_path(path, projects_allowed=False)<EOL>parent_metadata = self.get_parent(path)<EOL>self.api_client.create_folder(path.split('<STR_LIT:/>')[-<NUM_LIT:1>], parent_metadata['<STR_LIT>'])<EOL>

Create a folder in the storage service pointed by the given path.

        Args:
            path (str): The path of the folder to be created

        Returns:
            None

        Raises:
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes


def upload_file(self, local_file, dest_path, mimetype):

self.__validate_storage_path(dest_path)<EOL>if dest_path.endswith('<STR_LIT:/>'):<EOL><INDENT>raise StorageArgumentException('<STR_LIT>')<EOL><DEDENT>if local_file.endswith(os.path.sep):<EOL><INDENT>raise StorageArgumentException('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>new_file = self.api_client.create_file(<EOL>name=dest_path.split('<STR_LIT:/>').pop(),<EOL>content_type=mimetype,<EOL>parent=self.get_parent(dest_path)['<STR_LIT>']<EOL>)<EOL>etag = self.api_client.upload_file_content(new_file['<STR_LIT>'], source=local_file)<EOL>new_file['<STR_LIT>'] = etag<EOL>return new_file<EOL>

Upload local file content to a storage service destination folder.

            Args:
                local_file(str)
                dest_path(str):
                    absolute Storage service path '/project' prefix is essential
                    suffix should be the name the file will have on in the destination folder
                    i.e.: /project/folder/.../file_name
                mimetype(str): set the contentType attribute

            Returns:
                The uuid of created file entity as string

            Raises:
                StorageArgumentException: Invalid arguments
                StorageForbiddenException: Server response code 403
                StorageNotFoundException: Server response code 404
                StorageException: other 400-600 error codes


self.__validate_storage_path(path, projects_allowed=False)<EOL>entity = self.api_client.get_entity_by_query(path=path)<EOL>if entity['<STR_LIT>'] in self.__BROWSABLE_TYPES:<EOL><INDENT>contents = self.api_client.list_folder_content(entity['<STR_LIT>'])<EOL>if contents['<STR_LIT:count>'] > <NUM_LIT:0>:<EOL><INDENT>raise StorageArgumentException(<EOL>'<STR_LIT>')<EOL><DEDENT>self.api_client.delete_folder(entity['<STR_LIT>'])<EOL><DEDENT>elif entity['<STR_LIT>'] == '<STR_LIT:file>':<EOL><INDENT>self.api_client.delete_file(entity['<STR_LIT>'])<EOL><DEDENT>

Delete an entity from the storage service using its path.

            Args:
                path(str): The path of the entity to be delete

            Returns:
                The uuid of created file entity as string

            Raises:
                StorageArgumentException: Invalid arguments
                StorageForbiddenException: Server response code 403
                StorageNotFoundException: Server response code 404
                StorageException: other 400-600 error codes


@classmethod<EOL><INDENT>def __validate_storage_path(cls, path, projects_allowed=True):<DEDENT>

if not path or not isinstance(path, str) or path[<NUM_LIT:0>] != '<STR_LIT:/>' or path == '<STR_LIT:/>':<EOL><INDENT>raise StorageArgumentException(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if not projects_allowed and len([elem for elem in path.split('<STR_LIT:/>') if elem]) == <NUM_LIT:1>:<EOL><INDENT>raise StorageArgumentException(<EOL>'<STR_LIT>')<EOL><DEDENT>

Validate a string as a valid storage path


self.__services_url = services_url<EOL>

Create new service locator
            Arguments:
                services_url: The url of the json file where the services url are defined
            Returns:
                A service locator instance


return cls(SERVICES_URL_PER_ENV[environment])<EOL>

Create new service locator
            Arguments:
                environment: The environment to use to get the services.json url
            Returns:
                A service locator instance


def get_service_url(self, service, version):

return self.__get_services()[service][version]<EOL>

Get the service URL
            Arguments:
                service: The service name
                version: The service version
            Returns:
                The URL where the service is located


return requests.get(self.__services_url).json()<EOL>


def __init__(self, request, authenticated_request):

self._request = request<EOL>self._authenticated_request = authenticated_request<EOL>

Args:
   request: the base request to customize and send request with


request = RequestBuilder.request(environment).to_service(cls.SERVICE_NAME, cls.SERVICE_VERSION).throw(<EOL>StorageForbiddenException,<EOL>lambda resp: '<STR_LIT>'<EOL>if resp.status_code == <NUM_LIT> else None<EOL>).throw(<EOL>StorageNotFoundException,<EOL>lambda resp: '<STR_LIT>'<EOL>if resp.status_code == <NUM_LIT> else None<EOL>).throw(<EOL>StorageException,<EOL>lambda resp: '<STR_LIT>'.format(resp.status_code, resp.text)<EOL>if not resp.ok else None<EOL>)<EOL>authenticated_request = request.with_token(access_token)<EOL>return cls(request, authenticated_request)<EOL>

Create a new storage service REST client.

            Arguments:
                environment: The service environment to be used for the client
                access_token: The access token used to authenticate with the
                    service

            Returns:
                A storage_service.api.ApiClient instance

            Example:
                >>> storage_client = ApiClient.new(my_access_token)


return {k: v for (k, v) in params.items() if v is not None and k != '<STR_LIT>'}<EOL>

Remove empty (None) valued keywords and self from function parameters


if not is_valid_uuid(entity_id):<EOL><INDENT>raise StorageArgumentException(<EOL>'<STR_LIT>'.format(entity_id))<EOL><DEDENT>return self._authenticated_request.to_endpoint('<STR_LIT>'.format(entity_id)).return_body().get()<EOL>

Get generic entity by UUID.

        Args:
            entity_id (str): The UUID of the requested entity.

        Returns:
            A dictionary describing the entity::

                {
                     u'collab_id': 2271,
                     u'created_by': u'303447',
                     u'created_on': u'2017-03-10T12:50:06.077891Z',
                     u'description': u'',
                     u'entity_type': u'project',
                     u'modified_by': u'303447',
                     u'modified_on': u'2017-03-10T12:50:06.077946Z',
                     u'name': u'2271',
                     u'uuid': u'3abd8742-d069-44cf-a66b-2370df74a682'
                 }

        Raises:
            StorageArgumentException: Invalid arguments
            StorageForbiddenException: Server response code 403
            StorageNotFoundException: Server response code 404
            StorageException: other 400-600 error codes