Esempio n. 1
0
    def __init__(self,
            canvas,
            index = 0,
            projection = 'rectilinear',
            name = None,
            **kwargs
            ):

        if name is None:
            name = tempname()

        ax = canvas.fig.add_subplot(
            canvas.nrows,
            canvas.ncols,
            index + 1,
            projection = projection,
            label = name,
            **kwargs
            )

        self.canvas, self.index, self.projection, self.name = \
            canvas, index, projection, name
        self.ax = ax

        self.set_margins()
Esempio n. 2
0
def get_ffconcat(filedir, items, durations):
    randname = disk.tempname(_mpiignore_ = True)
    infile = os.path.join(filedir, randname + '.ffconcat')
    with open(infile, mode = 'w') as file:
        file.write('ffconcat version 1.0' + '\n')
        for item, duration in zip(items, durations):
            file.write('file ' + item + '\n')
            file.write('duration ' + str(duration) + '\n')
    return infile
Esempio n. 3
0
    def __init__(
            self,
            name = None,
            add = None,
            ext = 'png',
            **kwargs
            ):

        if name is None:
            name = disk.tempname()
        self.name = name
        self.add = add
        self.ext = ext
Esempio n. 4
0
def animate(
        source,
        duration = None,
        name = None,
        outputPath = '.',
        overwrite = False,
        ):

    if name is None:
        name = disk.tempname(_mpiignore_ = True)

    outputPath = os.path.abspath(outputPath)
    outputFilename = os.path.join(outputPath, name + '.mp4')
    if not overwrite:
        if os.path.exists(outputFilename):
            raise Exception("Output file already exists!")

    try:
        cleanup = lambda: None
        infile, pts, cleanup = process_args(source, duration, outputPath)
        filters = ','.join([
            '"scale=trunc(iw/2)*2:trunc(ih/2)*2"',
            '"setpts=' + str(pts) + '*PTS"'
            ])
        cmd = ' '.join([
            'ffmpeg',
            '-y',
            '-i', infile,
            '-filter', filters,
            '-c:v', 'libx264',
            '-pix_fmt', 'yuv420p',
            '-movflags', '+faststart',
            '-an',
            '"' + outputFilename + '"'
            ])
        completed = subprocess.run(
            cmd,
            stdout = PIPE,
            stderr = PIPE,
            shell = True,
            check = True,
            )

    finally:
        cleanup()

    return outputFilename
Esempio n. 5
0
 def add_freq(self, freq):
     newfreq = _get_periodic_condition(self.observee, freq)
     freqID = disk.tempname()
     self.checkfreqs[freqID] = newfreq
     return freqID
Esempio n. 6
0
def get_tempDir(outputPath):
    tempDir = os.path.join(outputPath, disk.tempname(_mpiignore_ = True))
    cleanup = lambda: shutil.rmtree(tempDir, ignore_errors = True)
    cleanup()
    os.makedirs(tempDir)
    return tempDir, cleanup
Esempio n. 7
0
def animate(data,
            chron=None,
            name=None,
            outputPath='.',
            overwrite=False,
            sampleFactor=1,
            pts=1.,
            size=None,
            _resize_filter=Image.BICUBIC):
    if type(data) in {tuple, list}:
        datas = list(data)
    else:
        datas = [
            data,
        ]
    if not len(set([d.shape for d in datas])) == 1:
        raise ValueError("Data shapes must be identical.")
    dataLen = len(datas[0])
    if not chron is None:
        if type(chron) in {tuple, list}:
            chrons = list(chron)
        else:
            chrons = [chron for d in data]
        for i, (data, chron) in enumerate(zip(datas, chrons)):
            datas[i] = interp_rasters(data, chron, sampleFactor)[:, :, :, 0]
    if name is None:
        name = disk.tempname(_mpiignore_=True)
    pts *= 1. / sampleFactor
    outputPath = os.path.abspath(outputPath)
    outputFilename = os.path.join(outputPath, name + '.mp4')
    if not overwrite:
        if os.path.exists(outputFilename):
            raise Exception("Output file already exists!")
    tempDir = os.path.join(outputPath, disk.tempname(_mpiignore_=True))
    inputFilename = os.path.join(tempDir, '*.jpg')
    shutil.rmtree(tempDir, ignore_errors=True)
    os.makedirs(tempDir)
    try:
        for i in range(dataLen):
            im = rasterise(*[data[i] for data in datas])
            if not size is None:
                if not type(size) in {tuple, list}:
                    size = [v * size for v in im.size]
                im = im.resize(size, resample=_resize_filter)
            im.save(os.path.join(tempDir, str(i).zfill(8)) + '.jpg')
        filters = [
            '"scale=trunc(iw/2)*2:trunc(ih/2)*2"',
            '"setpts=' + str(pts) + '*PTS"'
        ]
        cmd = [
            'ffmpeg', '-y', '-pattern_type', 'glob', '-i',
            '"' + inputFilename + '"', '-filter', ','.join(filters), '-c:v',
            'libx264', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', '-an',
            '"' + outputFilename + '"'
        ]
        cmd = ' '.join(cmd)
        completed = subprocess.run(cmd,
                                   stdout=PIPE,
                                   stderr=PIPE,
                                   shell=True,
                                   check=True)
    finally:
        shutil.rmtree(tempDir, ignore_errors=True)
    return outputFilename