airtable
upsert_image #
upsert_image(at_api, ds_name, image_name, image_path, image_title, image_type, institution='HHMI / Janelia Research Campus', challenge=False, dry_run=False, image_path_s3=None)
Upsert a record to airtable image table.
An image can have a filesystem copy, an S3 copy, or both. Each copy that is
present gets its own field: location for the filesystem copy, and
location_s3 for the S3 copy. A copy that is absent leaves its field
unset. The array metadata comes from the filesystem copy when it exists,
because that copy reads faster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_table
|
Table
|
image airtable object to create references. |
required |
ds_name
|
str
|
name of the dataset. |
required |
image_name
|
str
|
name of the image to upsert. |
required |
image_path
|
str | None
|
filesystem path of the image. Pass None if the
image has no filesystem copy. An |
required |
image_title
|
str
|
image title on openorganelle.com. |
required |
image_type
|
Literal['human_segmentation', 'em']
|
image type |
required |
collection_table
|
Table
|
collation airtable object to create references. |
required |
fibsem_table
|
Table
|
fibsem_imaging airtable object to create references. |
required |
annotation_table
|
Table
|
annotation airtable object to create references. |
required |
dry_run
|
bool
|
if True, compute the record that would be created/updated, but do not call Airtable's create/update. Defaults to False. |
False
|
image_path_s3
|
str | None
|
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
raise value error if image_path holds an s3:// path. |
ValueError
|
raise value error if neither path holds a copy of the image. |
ValueError
|
raise value error if multiple records with the same location and name are found in the image table. |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the record that was upserted, in the same shape returned by
pyairtable ( |
Source code in src/cellmap_utils/airtable/upsert/image.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
upsert_doi #
Upsert a record to airtable doi table, linked to an image record.
Segmentation images (image_type "human_segmentation") do not belong in the doi table. They belong in the doi_crop table instead, so this method rejects them. Images with image_type "ml_segmentation" are still accepted here.
The doi record's dataset field is set to "{collection id} {image
title}", matching the naming convention already used for other doi
records. The image's linked
collection record is also set on the doi record's collection field,
which drives several of the doi table's lookup fields. The collection's
linked sample record, if any, is set on the doi record's sample field.
When image_type is "em" (raw FIB-SEM data), the image's linked
fibsem_imaging record is also carried forward onto the doi record's
fibsem_imaging field. Derived images (predictions, segmentations) do
not get this field set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at_api
|
api
|
pyairtable Api object used to reach the base. |
required |
image_path
|
str
|
filesystem path or s3:// path of the image record to
link to the doi record. The image record's |
required |
doi_name
|
str
|
value for the doi record's doi_name field. |
required |
dry_run
|
bool
|
if True, compute the record that would be created/updated, but do not call Airtable's create/update. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
raise value error if no image record matches image_path. |
ValueError
|
raise value error if multiple image records match image_path. |
ValueError
|
raise value error if the image's image_type is "human_segmentation". |
ValueError
|
raise value error if multiple doi records already link to the image. |
ValueError
|
raise value error if the image has no linked collection record. |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the record that was upserted, in the same shape returned by
pyairtable ( |
Source code in src/cellmap_utils/airtable/upsert/doi.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
upsert_record_scene_tables #
upsert_record_scene_tables(scene_table, scene_to_image_table, image_table, image_location, scene_data={}, scene_to_image_data={}, dry_run=False)
This method upserts records into scene and scene_to_image table at the same time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene_table
|
Table
|
output table to upsert |
required |
scene_to_image_table
|
Table
|
output table to upsert |
required |
image_table
|
Table
|
input table from where the record is being taken |
required |
image_location
|
str
|
provides value for location filter paramater for the image record |
required |
scene_update
|
dict
|
custom data to upsert into "scene" table |
required |
scene_to_image_update
|
dict
|
custom data to upsert in "scene_to_image" table |
required |
dry_run
|
bool
|
if True, compute the records that would be created/updated, but do not call Airtable's create/update. Since the scene record links to the scene_to_image record's id, that link is None in dry_run mode (no real record was created to link to). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[dict]
|
Tuple[dict]: output records that were upserted, in the same shape
returned by pyairtable ( |
Source code in src/cellmap_utils/airtable/upsert/scene.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
get_image_record #
Read an image record from airtable and return supabase image, dataset, sample, and acquisition records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
path to dataset used as a filter parameter for airtable image table records |
required |
at_api
|
api
|
airtable api instance |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
returns a dictionary of records, with pydantic models for supabase table records as values. |
Source code in src/cellmap_utils/airtable/supabase/air_to_supabase.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
get_mesh_record #
Read a neuroglancer mesh and its airtable image record, and return a supabase mesh record.
The grid scale and the grid shift come from the transform in the mesh info file, not from a fixed value. A mesh that carries a transform other than the identity prints a warning, because such a mesh does not sit on the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh_path
|
str
|
s3 path of the neuroglancer precomputed mesh volume. |
required |
image_path
|
str
|
s3 path of the image the mesh comes from. It must match the location_s3 field of an airtable image record. |
required |
ds_name
|
str
|
name of the dataset. |
required |
at_api
|
api
|
airtable api instance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SupaMeshModel |
the supabase mesh record. |
Source code in src/cellmap_utils/airtable/supabase/air_to_supabase.py
filter_records #
Custom method to filter records by a field value. all(formula=match({})) doesn't work when filtering by reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records (dict)
|
list of all records in a table. Not using table.all() within a method, since it slow to fetch all the records every time when a method is called. |
required | |
field
|
str
|
table field name |
required |
field_value
|
list[str] | str
|
table field value |
required |
Returns:
| Type | Description |
|---|---|
|
list[dict]: return records with filter_value for filter_field field |