Core
KoshFileLoader
Bases: KoshLoader
Kosh loader to load content from files
Source code in kosh/loaders/core.py
describe_feature(feature)
describe a feature
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
str, optional if loader does not require this
|
feature (variable) to read, defaults to None |
required |
Returns:
Type | Description |
---|---|
dict
|
dictionary describing the feature |
Source code in kosh/loaders/core.py
extract(feature, format)
extract return a feature from the loaded object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
str
|
variable to read from file |
required |
format |
str
|
desired output format |
required |
Returns:
Type | Description |
---|---|
data |
Source code in kosh/loaders/core.py
list_features(*args, **kargs)
list_features list features in file,
Returns:
Type | Description |
---|---|
list
|
list of features available in file |
open(mode='r')
open/load the matching Kosh Sina File
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
str, optional
|
mode to open the file in, defaults to 'r' |
'r'
|
Returns:
Type | Description |
---|---|
Kosh File object |
Source code in kosh/loaders/core.py
KoshGenericObjectFromFile
Bases: KoshSinaObject
Kosh object pointing to a file
Source code in kosh/loaders/core.py
KoshLoader
Bases: KoshExecutionGraph
Parameters:
Name | Type | Description | Default |
---|---|---|---|
types |
dict
|
types is a dictionary on known type that can be loaded as key and export format as value, defaults to {"dataset": []} |
required |
Source code in kosh/loaders/core.py
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 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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
__init__(obj, mime_type=None, uri=None, requestorId=None)
KoshLoader generic Kosh loader
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
object
|
object the loader will try to load from |
required |
mime_type |
str
|
If you want to force the mime_type to use |
None
|
uri |
str
|
If you want/need to force the uri to use |
None
|
requestorId |
str
|
The id of the dataset requesting data |
None
|
Source code in kosh/loaders/core.py
describe_feature(feature)
describe_feature describe the feature as a dictionary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
str
|
feature to describe |
required |
Returns:
Type | Description |
---|---|
dict
|
dictionary with attributes describing the feature |
Source code in kosh/loaders/core.py
extract()
extract this function does the heavy lifting of the extraction it needs to be implemented by each loader.
We recommend returning pointer to the data as much as possible
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in kosh/loaders/core.py
get(feature, format=None, transformers=[], use_cache=True, cache_file_only=False, cache_dir=None, **kargs)
Extracts a feature and possibly transforms it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
str
|
desired feature |
required |
format |
str
|
desired output format |
None
|
transformers |
kosh.transformer.KoshTranformer
|
A list of transformers to use after the data is loaded |
[]
|
use_cache |
bool
|
Try to use cached data if available |
True
|
cache_file_only |
bool
|
If True, simply return name of cache_file |
False
|
cache_dir |
str **kargs will be stored on loader object format and feature are stored on the object for extraction by extraction functions This function calls first the loader's preprocess function This is followed by an actual data extraction via the 'extract' function Finally 'postprocess' is called on the extracted data Reserved keyword: preprocess: function use to preprocess (default to self.preprocess) postprocess: function use to postprocess (default to self.postprocess)
|
where do we cache the result? |
None
|
Source code in kosh/loaders/core.py
get_execution_graph(feature, transformers=[])
Generates the execution graph to extract a feature and possibly transform it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
str
|
desired feature |
required |
format |
str
|
desired output format |
required |
transformers |
kosh.transformer.KoshTranformer
|
A list of transformers to use after the data is loaded |
[]
|
Returns:
Type | Description |
---|---|
networkx.OrderDiGraph
|
execution graph to get to the possibly transformed feature |
Source code in kosh/loaders/core.py
get_requestor()
Returns the Kosh object requesting the data
known_load_formats(atype)
Lists all the formats this loader knows how to export to for a given type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
atype |
type we wish to to the formats for |
required |
Returns:
Type | Description |
---|---|
list
|
list of format this type can be exported to by the loader |
Source code in kosh/loaders/core.py
known_types()
Lists types of Kosh objects this loader can handle
Returns:
Type | Description |
---|---|
list
|
list of Kosh type this loader can handle |
list_features(*args, **kargs)
list_features Given the obj it's loading return a list of features (variables) it can extract
Returns:
Type | Description |
---|---|
list
|
list of available features from this loader |
load(cache_file)
Loads content from cache :rtpye: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_file |
str
|
name of cache file, will be joined with self.cache_dir |
required |
Returns:
Type | Description |
---|---|
unpickled data |
Source code in kosh/loaders/core.py
open(mode='r')
Open function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
str
|
mode to open the object in |
'r'
|
Returns:
Type | Description |
---|---|
object
|
opened object |
postprocess(data)
postprocess Given the extracted data apply some post processing to it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
any
|
result of the extract function |
required |
Returns:
Type | Description |
---|---|
any
|
post processed |
preprocess()
preprocess sets things up for the extract function
This should be preceeded by a call to 'get' which stored its args in self._user_passed_parameters
save(cache_file, content)
Pickles some data to a cache file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_file |
str
|
name of cache file, will be joined with self.cache_dir |
required |
content |
object
|
content to save to cache |
required |
Source code in kosh/loaders/core.py
update_signature(*args, **kargs)
Updated the signature based to a set of args and kargs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
list
|
as many arguments as you want |
()
|
**kargs |
dict
|
key=value style arguments |
{}
|
Returns:
Type | Description |
---|---|
str
|
updated signature |
Source code in kosh/loaders/core.py
KoshSinaLoader
Bases: KoshLoader
Sina base class for loaders
Source code in kosh/loaders/core.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
__init__(obj, **kargs)
open(*args, **kargs)
open the object