Skip to main content

Manage sequences of frame numbers.

Project description

sequence

Manage sequences of frame numbers

Install

pip install cioseq

Usage

Import

>>> from cioseq.sequence import Sequence

Several ways to create a Sequence using the create() factory method.

# [start [end [step]]] - Unlike range(), end is inclusive.

>>> s = Sequence.create("1")

>>> s = Sequence.create(1,10,2)

# list
>>> s = Sequence.create([5,6,7,10,12])

# spec
>>> s = Sequence.create("1-10x2")

# compound spec with negative frame numbers
>>> s = Sequence.create("0-10x3, 100, -10--2x2")

# Copy constructor
>>> s2 = Sequence.create(s)
>>> s2 == s
False
>>> list(s2) == list(s)
True

>>> list(s)
[-10, -8, -6, -4, -2, 0, 3, 6, 9, 100]

>>> print(s)
-10-0x2,3-9x3,100

>>> repr(s)
"Sequence.create('-10-0x2,3-9x3,100')"

Indexing

>>> s[-1]
100

s[0]
-10

An arithmetic progression is a set of numbers with a common step.

>>> s = Sequence.create([1,4,7,10,13])
>>> type(s)
<class 'cioseq.sequence.Progression'>

>>> s=Sequence.create([1,2,3,5,78])
>>> type(s)
<class 'cioseq.sequence.Sequence'>
>>> s.is_progression()
False

Chunks

# Split into chunks, which are themselves Sequences.
>>> s = Sequence.create("1-20", chunk_size=5)
>>> s.chunk_count()
4
>>> s.chunks()
[Sequence.create('1-5'), Sequence.create('6-10'), Sequence.create('11-15'), Sequence.create('16-20')]

# Chunks can be cyclic.
>>> s.chunk_strategy = "cycle"
>>> for c in s.chunks():
...    print(list(c))

[1, 5, 9, 13, 17]
[2, 6, 10, 14, 18]
[3, 7, 11, 15, 19]
[4, 8, 12, 16, 20]

Booleans

>>> s = Sequence.create("1-10")
>>> isect = s.intersection(range(5, 15))
>>> print(isect)
5-10


>>> s = Sequence.create("1-10")
>>> uni = s.union(range(5, 15))
>>> print(uni)
1-14

Intersecting chunks. Helps to determine which tasks contain scout frames.

>>> s = Sequence.create("1-50", chunk_size=5)
>>> scout =  Sequence.create("1,2,7")
>>> chunks = s.intersecting_chunks(scout)
>>> print(chunks)
[Sequence.create('1-5'), Sequence.create('6-10')]

Multi sequence filename permutations

# single sequence
>>> template = "/path/%(frame)d/image.%(frame)04d.tif"
>>> filenames = list(Sequence.permutations(template, frame="0-6x2"))
>>> print(filenames)
['/path/0/image.0000.tif', '/path/2/image.0002.tif', '/path/4/image.0004.tif', '/path/6/image.0006.tif']

# several sequences
>>> template = "image_%(uval)02d_%(vval)02d.%(frame)04d.tif"
>>> kw = {"uval": "1-2", "vval": "1-2", "frame": "10-11"}
>>> filenames = Sequence.permutations(template, **kw)

>>> print(filenames)
<generator object permutations at 0x10260f960>

>>> for f in filenames:
...    print f

image_01_01.0010.tif
image_01_02.0010.tif
image_02_01.0010.tif
image_02_02.0010.tif
image_01_01.0011.tif
image_01_02.0011.tif
image_02_01.0011.tif
image_02_02.0011.tif

Offset

>>> s = Sequence.create("1-10")
>>> s = s.offset(-5)
>>> print(s)
-4-5

Hash (#) filename expansion

>>> s = Sequence.create("8-10")
s.expand("image.#.exr")
['image.8.exr', 'image.9.exr', 'image.10.exr']

s.expand("/some/dir_###/img.#####.exr")
['/some/dir_008/img.00008.exr', '/some/dir_009/img.00009.exr', '/some/dir_010/img.00010.exr']

Dollar(n)F filename expansion

>>> s = Sequence.create("1")
>>> s.expand_dollar_f("image.$F.exr")
['image.1.exr']

>>> s.expand_dollar_f("image.$F.$5F.$2F.exr")
['image.1.00001.01.exr']

Use different symbols for frame spec

>>> s = Sequence.create("1-10, 14, 20-48x4")
>>> print(s)
1-10,14,20-48x4

>>> print(s.to(":", "%", ";"))
1:10;14;20:48%4

>>> print(s.to("to", "by", " "))
1to10 14 20to48by4

Take a subsample of frames

s = Sequence.create("1-10")
>>> print(s.subsample(1))
6

>>> print(s.subsample(2))
3-8x5

>>> print(s.subsample(3))
2-6x4,9

>>> print(s.subsample(5))
2-10x2

>>> print(list(s.subsample(4)))
[2, 4, 7, 9]

Test

From git repo

python -m unittest discover -v -s ./tests  -p 'test_*.py'

Contributing

Pull requests welcome.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cioseq-0.1.3.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cioseq-0.1.3-py2.py3-none-any.whl (16.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file cioseq-0.1.3.tar.gz.

File metadata

  • Download URL: cioseq-0.1.3.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.7

File hashes

Hashes for cioseq-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2ad78f3cfe8ba4900258629f821f6be8e14f2d39f865af40b421e412c8356e48
MD5 75d68924f2e643ddcb3b17881280e53a
BLAKE2b-256 678fde406ee944c2aeb43bddff54bf982c42bffe1322c8a5b87adeb5bfa746ea

See more details on using hashes here.

File details

Details for the file cioseq-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: cioseq-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.7

File hashes

Hashes for cioseq-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8765383933008fdf349222df93cc6d36d6ddbf3878c0dbe74addc61b18d8fc82
MD5 5d5736e995bb386258b018e755a89585
BLAKE2b-256 df49b06509584efd0221653549d41508950b4f1b188d63d99e9c66d937d89295

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page