12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- """
- Created on 19.02.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_ori_stim(os.path.join(os.environ.get('HOME'),
- 'tmp',
- 'raised_cos_oriphi_o20_a20_p20_fwhm2.5.idlmov'),
- output_size=20,
- n_angles=20,
- n_phases=20,
- fwhm=2.5)
- def generate_ori_stim(file_path,
- output_size=20,
- n_angles=20,
- n_phases=20,
- fwhm=3.0):
- generator_args = locals()
- write_meta_files(file_path, n_angles, n_phases, __file__, 'generate_ori_stim', generator_args)
-
- center = 0.5*np.array([output_size, output_size]) - 0.5
- phase_positions = np.linspace(0, output_size-1, n_phases) - 0.5*output_size + 0.5
- angles = np.linspace(0, 180, n_angles, endpoint=False)
- pic_list = []
- for angle in 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_positions:
- pos = center + normal_dx_dy * phase
- cos_filter = geom.cos2d(20, pos, fwhm=2.5, line_angle_deg=angle)
- pic_list.append(cos_filter)
- 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()
|