123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- # -*- coding: utf-8 -*-
- """
- Created on 16.03.2015
- @author: frank
- """
- import os
- import json
- import numpy as np
- import objsimpy.geom as geom
- from objsimpy.gitrepo import get_sha1_of_latest_commit
- from objsimpy.stim.stim_movie import StimulusSet
- from objsimpy.stim.stim_movie import write_meta_xml
- def main():
- generate_sine_wave_grid_stim(os.path.join(os.environ.get('HOME'),
- 'tmp',
- 'sine_wave_o20_a20_p20_wave10.idlmov'),
- output_size=20,
- n_angles=20,
- n_phases=20,
- wave_length=10.)
- def generate_sine_wave_grid_stim(file_path,
- output_size=20,
- n_angles=20,
- n_phases=20,
- wave_length=10.0):
- generator_args = locals()
- write_meta_files(file_path, n_angles, n_phases, __file__, 'generate_sine_wave_grid_stim', generator_args)
-
- center = 0.5*np.array([output_size, output_size]) - 0.5
- ori_angles = np.linspace(0, 180, n_angles, endpoint=False)
- phase_angles = np.linspace(0, 360, n_phases, endpoint=False)
- pic_list = []
- for angle in ori_angles:
- normal_angle = angle + 90
- normal_dx_dy = np.array([np.cos(geom.deg_to_rad(normal_angle)),
- np.sin(geom.deg_to_rad(normal_angle))])
- for phase in phase_angles:
- pos = center + normal_dx_dy * phase
- sine_grid = geom.sine2d(20, wave_length=wave_length, ori_angle_deg=angle, phase_angle_deg=phase)
- pic_list.append(sine_grid)
- stim_set = StimulusSet(pics=pic_list)
- stim_set.save(file_path)
-
- def write_meta_files(file_path, nx, ny, source_file, generator_name, generator_args):
- toplevel, sha1 = get_sha1_of_latest_commit(source_file)
- meta_dict = {'MovieMetaFile':
- {'StimParas': {'MovieFileName': os.path.basename(file_path),
- 'NXParas': nx,
- 'NYParas': ny,
- },
- 'Generator': {'FunctionName': generator_name,
- 'SourceFile': os.path.relpath(source_file, toplevel),
- 'SHA1': sha1,
- 'Args': generator_args
- },
- }
- }
-
- fname_json = os.path.splitext(file_path)[0] + '.meta.json'
- with open(fname_json, 'w') as fobj_json:
- fobj_json.write(json.dumps(meta_dict, indent=4))
- fname_meta = os.path.splitext(file_path)[0] + '.meta.xml'
- write_meta_xml(meta_dict, fname_meta)
-
-
-
- if __name__ == '__main__':
- main()
|