TIF Examples
First we need to create our NWB object, we’ll use this generic one
1from simply_nwb import SimpleNWB
2import pendulum
3from pynwb.file import Subject
4
5
6def nwb_gen():
7 return SimpleNWB.create_nwb(
8 # Required
9 session_description="Mouse cookie eating session",
10 # Subtract 1 year so we don't run into the 'NWB start time is at a greater date than current' issue
11 session_start_time=pendulum.now().subtract(years=1),
12 experimenter=["Schmoe, Joe"],
13 lab="Felsen Lab",
14 experiment_description="Gave a mouse a cookie",
15
16 # Optional
17 identifier="cookie_0",
18 subject=Subject(**{
19 "subject_id": "1",
20 "age": "P90D", # ISO-8601 for 90 days duration
21 "strain": "TypeOfMouseGoesHere", # If no specific used, 'Wild Strain'
22 "description": "Mouse#2 idk",
23 "sex": "M", # M - Male, F - Female, U - unknown, O - other
24 # NCBI Taxonomy link or Latin Binomial (e.g.'Rattus norvegicus')
25 "species": "http://purl.obolibrary.org/obo/NCBITaxon_10116",
26 }),
27 session_id="session0",
28 institution="CU Anschutz",
29 keywords=["mouse"],
30
31 # related_publications="DOI::LINK GOES HERE FOR RELATED PUBLICATIONS"
32 )
An example usage of the TIF functions is as follows
1from simply_nwb import SimpleNWB
2from simply_nwb.transforms import tif_read_directory, tif_read_image, tif_read_subfolder_directory
3from gen_nwb import nwb_gen
4
5
6def tif_test():
7 r = tif_read_image("E:\\tifs\\subfolder_formatted/file/Image.tif")
8 r2 = tif_read_directory("E:\\tifs\\broken", skip_on_error=True)
9
10 rr = tif_read_subfolder_directory(
11 parent_folder="E:\\tifs\\subfolder_formatted",
12 subfolder_glob="file*",
13 file_glob="Image.tif"
14 )
15
16 rrr = tif_read_directory("E:\\tifs\\folder_formatted", filename_glob="*014_*ome.tif")
17 tw = 2
18
19
20def nwb_basic_tif():
21 imgarr = tif_read_image("E:\\tifs\\folder_formatted\\jan9_cup_M2E2_2_MMStack_1-Pos000_000.ome.tif")
22 imgarr = imgarr[None, :]
23
24 nwb = SimpleNWB.test_nwb()
25 SimpleNWB.tif_add_as_processing_imageseries(
26 nwb,
27 "test",
28 "ttt",
29 imgarr,
30 1.0,
31 "asdf"
32 )
33
34def nwb_two_photon():
35 nwb = nwb_gen()
36 data = tif_read_directory("E:\\tifs\\folder_formatted", filename_glob="*014_*ome.tif")
37
38 SimpleNWB.two_photon_add_data(
39 nwb,
40 device_name="MyMicroscope",
41 device_description="The coolest microscope ever",
42 device_manufacturer="CoolMicroscopes Inc",
43 optical_channel_description="an optical channel",
44 optical_channel_emission_lambda=500.0, # in nm
45 imaging_name="my_data",
46 imaging_rate=30.0, # images acquired in Hz
47 excitation_lambda=600.0, # wavelength in nm
48 indicator="GFP",
49 location="V1",
50 grid_spacing=[0.1, 0.1],
51 grid_spacing_unit="meters",
52 origin_coords=[0.1, 0.1],
53 origin_coords_unit="meters",
54 photon_series_name="MyTwoPhotonSeries",
55 two_photon_unit="normalized amplitude",
56 two_photon_rate=1.0, # sampling rate in Hz
57 image_data=data
58 )
59 # nwb.acquisition["TwoPhotonSeries"].data
60
61 # Ignore the check_data_orientation check
62 t = nwb.acquisition["MyTwoPhotonSeries"].data[:]
63 return nwb, ["check_data_orientation"]