<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create(filename, spec):
 """Create a new segy file. Create a new segy file with the geometry and properties given by `spec`. This enables creating SEGY files from your data. The created file supports all segyio modes, but has an emphasis on writing. The spec must be complete, otherwise an exception will be raised. A default, empty spec can be created with ``segyio.spec()``. Very little data is written to the file, so just calling create is not sufficient to re-read the file with segyio. Rather, every trace header and trace must be written to the file to be considered complete. Create should be used together with python's ``with`` statement. This ensure the data is written. Please refer to the examples. The ``segyio.spec()`` function will default sorting, offsets and everything in the mandatory group, except format and samples, and requires the caller to fill in *all* the fields in either of the exclusive groups. If any field is missing from the first exclusive group, and the tracecount is set, the resulting file will be considered unstructured. If the tracecount is set, and all fields of the first exclusive group are specified, the file is considered structured and the tracecount is inferred from the xlines/ilines/offsets. The offsets are defaulted to ``[1]`` by ``segyio.spec()``. Parameters filename : str Path to file to create spec : segyio.spec Structure of the segy file Returns ------- file : segyio.SegyFile An open segyio file handle, similar to that returned by `segyio.open` See also -------- segyio.spec : template for the `spec` argument Notes ----- .. versionadded:: 1.1 .. versionchanged:: 1.4 Support for creating unstructured files .. versionchanged:: 1.8 Support for creating lsb files The ``spec`` is any object that has the following attributes Mandatory:: iline : int or segyio.BinField xline : int or segyio.BinField samples : array of int format : { 1, 5 } 1 = IBM float, 5 = IEEE float Exclusive:: ilines : array_like of int xlines : array_like of int offsets : array_like of int sorting : int or segyio.TraceSortingFormat OR tracecount : int Optional:: ext_headers : int endian : str { 'big', 'msb', 'little', 'lsb' } defaults to 'big' Examples -------- Create a file: Copy a file, but shorten all traces by 50 samples: Copy a file, but shift samples time by 50: Copy a file, but shorten all traces by 50 samples (since v1.4):
 """


    from . import _segyio

    if not structured(spec):
        tracecount = spec.tracecount
    else:
        tracecount = len(spec.ilines) * len(spec.xlines) * len(spec.offsets)

    ext_headers = spec.ext_headers if hasattr(spec, 'ext_headers') else 0
    samples = numpy.asarray(spec.samples)

    endians = {
        'lsb': 256, # (1 << 8)
        'little': 256,
        'msb': 0,
        'big': 0,
    }
    endian = spec.endian if hasattr(spec, 'endian') else 'big'
    if endian is None:
        endian = 'big'

    if endian not in endians:
        problem = 'unknown endianness {}, expected one of: '
        opts = ' '.join(endians.keys())
        raise ValueError(problem.format(endian) + opts)

    fd = _segyio.segyiofd(str(filename), 'w+', endians[endian])
    fd.segymake(
        samples = len(samples),
        tracecount = tracecount,
        format = int(spec.format),
        ext_headers = int(ext_headers),
    )

    f = segyio.SegyFile(fd,
            filename = str(filename),
            mode = 'w+',
            iline = int(spec.iline),
            xline = int(spec.xline),
            endian = endian,
    )

    f._samples       = samples

    if structured(spec):
        sorting = spec.sorting if hasattr(spec, 'sorting') else None
        if sorting is None:
            sorting = TraceSortingFormat.INLINE_SORTING
        f.interpret(spec.ilines, spec.xlines, spec.offsets, sorting)

    f.text[0] = default_text_header(f._il, f._xl, segyio.TraceField.offset)

    if len(samples) == 1:
        interval = int(samples[0] * 1000)
    else:
        interval = int((samples[1] - samples[0]) * 1000)

    f.bin.update(
        ntrpr    = tracecount,
        nart     = tracecount,
        hdt      = interval,
        dto      = interval,
        hns      = len(samples),
        nso      = len(samples),
        format   = int(spec.format),
        exth     = ext_headers,
    )

    return f