cdfread¤
cdfread
¤
Classes:
| Name | Description |
|---|---|
CDF |
Read a CDF file into the CDF object. This object contains methods to load |
CDF
¤
CDF(path: Union[str, Path], validate: bool = False, string_encoding: str = 'ascii', s3_read_method: int = 1)
Read a CDF file into the CDF object. This object contains methods to load the cdf file information, variable names, and values.
Example
>>> import cdflib
>>> cdf_file = cdflib.CDF('/path/to/cdf_file.cdf')
>>> cdf_file.cdf_info()
>>> x = cdf_file.varget("NameOfVariable", startrec=0, endrec=150)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
(Path, str)
|
Path to CDF file. This can be a link to a file in an S3 bucket as well. |
required |
|
bool
|
If True, validate the MD5 checksum of the CDF file. |
False
|
|
str
|
The encoding used to read strings. Defaults to 'ascii', which is what the CDF internal format description prescribes as the encoding for character strings. Other encodings may have been used to create files however, and this keyword argument gives users the flexibility to read those files. |
'ascii'
|
|
int
|
If the user is specifying a file that lives within an AWS S3 bucket, this variable defines how the file is read in. The choices are: - 1 will read the file into memory to load in memory) - 2 will download the file to a tmp directory - 3 reads the file in chunks directly from S3 over https |
1
|
Notes
An open file handle to the CDF file remains whilst a CDF object is live. It is automatically cleaned up with the CDF instance is deleted.
Methods:
| Name | Description |
|---|---|
attget |
Returns the value of the attribute at the entry number provided. |
attinq |
Get attribute information. |
cdf_info |
Returns basic CDF information. |
globalattsget |
Gets all global attributes. |
varattsget |
Gets all variable attributes. |
varget |
Returns the variable data. |
varinq |
Get basic variable information. |
Source code in cdflib/cdfread.py
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 | |
attget
¤
Returns the value of the attribute at the entry number provided.
A variable name can be used instead of its corresponding entry number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
(str, int)
|
Attribute name or number to get. |
required |
|
int
|
|
None
|
Returns:
| Type | Description |
|---|---|
AttData
|
|
Source code in cdflib/cdfread.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 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 | |
attinq
¤
Get attribute information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
(str, int)
|
Attribute to get information for. |
required |
Returns:
| Type | Description |
|---|---|
ADRInfo
|
|
Source code in cdflib/cdfread.py
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 | |
cdf_info
¤
cdf_info() -> CDFInfo
Returns basic CDF information.
Returns:
| Type | Description |
|---|---|
CDFInfo
|
|
Source code in cdflib/cdfread.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
globalattsget
¤
Gets all global attributes.
This function returns all of the global attribute entries,
in a dictionary (in the form of 'attribute': {entry: value}
pairs) from a CDF.
Source code in cdflib/cdfread.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
varattsget
¤
Gets all variable attributes.
Unlike attget, which returns a single attribute entry value, this function returns all of the variable attribute entries, in a dictionary (in the form of 'attribute': value pair) for a variable.
Source code in cdflib/cdfread.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
varget
¤
varget(variable: Optional[str] = None, epoch: Optional[str] = None, starttime: Optional[epoch_types] = None, endtime: Optional[epoch_types] = None, startrec: int = 0, endrec: Optional[int] = None) -> Union[str, ndarray]
Returns the variable data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[str]
|
Variable name to fetch. |
None
|
|
int
|
Index of the first record to get. |
0
|
|
int
|
Index of the last record to get. All records from startrec to endrec inclusive are fetched. |
None
|
Notes
Variable can be entered either a name or a variable number. By default, it returns a 'numpy.ndarray' or 'list' class object, depending on the data type, with the variable data and its specification.
By default, the full variable data is returned. To acquire only a portion of the data for a record-varying variable, either the time or record (0-based) range can be specified. 'epoch' can be used to specify which time variable this variable depends on and is to be searched for the time range. For the ISTP-compliant CDFs, the time variable will come from the attribute 'DEPEND_0' from this variable. The function will automatically search for it thus no need to specify 'epoch'. If either the start or end time is not specified, the possible minimum or maximum value for the specific epoch data type is assumed. If either the start or end record is not specified, the range starts at 0 or/and ends at the last of the written data.
The start (and end) time should be presented in a list as: [year month day hour minute second millisec] for CDF_EPOCH [year month day hour minute second millisec microsec nanosec picosec] for CDF_EPOCH16 [year month day hour minute second millisec microsec nanosec] for CDF_TIME_TT2000 If not enough time components are presented, only the last item can have the floating portion for the sub-time components.
Note: CDF's CDF_EPOCH16 data type uses 2 8-byte doubles for each data value. In Python, each value is presented as a complex or numpy.complex128.
Source code in cdflib/cdfread.py
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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
varinq
¤
Get basic variable information.
Returns:
| Type | Description |
|---|---|
VDRInfo
|
|
Source code in cdflib/cdfread.py
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 | |
Sample Usage¤
To begin accessing the data within a CDF file, first create a new CDF class. This can be done with the following commands
>>> import cdflib
>>> cdf_file = cdflib.CDF('/path/to/cdf_file.cdf')
Then, you can call various functions on the variable.
For example
>>> x = cdf_file.varget("NameOfVariable", startrec = 0, endrec = 150)
This command will return all data inside of the variable Variable1, from records 0 to 150.