Skip to content

Conversation

braingram
Copy link
Contributor

@braingram braingram commented Jul 23, 2025

Description

Add AsdfFile.blocks to provide information about ASDF blocks when an AsdfFile is created from an ASDF file.

blocks is an immutable sequence of read-only views of the block data.

>> af = asdf.open("foo.asdf")
>> af.info(max_rows=None)
root (AsdfObject)
├─asdf_library (Software)
│ ├─author (str): The ASDF Developers
│ ├─homepage (str): http://github.com/asdf-format/asdf
│ ├─name (str): asdf
│ └─version (str): 4.3.1.dev5+g2dc5555d.d20250722
├─history (dict)
│ └─extensions (list)
│   └─[0] (ExtensionMetadata)
│     ├─extension_class (str): asdf.extension._manifest.ManifestExtension
│     ├─extension_uri (str): asdf://asdf-format.org/core/extensions/core-1.6.0
│     ├─manifest_software (Software)
│     │ ├─name (str): asdf_standard
│     │ └─version (str): 1.1.1
│     └─software (Software)
│       ├─name (str): asdf
│       └─version (str): 4.3.1.dev5+g2dc5555d.d20250722
└─arrs (list)
  ├─[0] (NDArrayType)
  │ ├─shape (tuple)
  │ │ └─[0] (int): 3
  │ └─dtype (Float64DType): float64
  ├─[1] (NDArrayType)
  │ ├─shape (tuple)
  │ │ └─[0] (int): 3
  │ └─dtype (Float64DType): float64
  ├─[2] (NDArrayType)
  │ ├─shape (tuple)
  │ │ └─[0] (int): 3
  │ └─dtype (Float64DType): float64
  ├─[3] (NDArrayType)
  │ ├─shape (tuple)
  │ │ └─[0] (int): 3
  │ └─dtype (Float64DType): float64
  └─[4] (NDArrayType)
    ├─shape (tuple)
    │ └─[0] (int): 3
    └─dtype (Float64DType): float64Block 0: 24 bytesBlock 1: 24 bytesBlock 2: 24 bytesBlock 3: 24 bytesBlock 4: 24 bytes
>> len(af.blocks)
5
>> af.blocks[0].header
mappingproxy({'flags': 0,
              'compression': b'\x00\x00\x00\x00',
              'allocated_size': 24,
              'used_size': 24,
              'data_size': 24,
              'checksum': b'\x16\x81\xff\xc6\xe0F\xc7\xaf\x98\xc9\xe6\xc22\xa3\xfe\n'})
>> af.blocks[0].offset
1070
>> af.blocks[0].data_offset
1120
>> af.blocks[0].loaded()
False
>> arr = af.blocks[0].load()
>> arr
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0], dtype=uint8)
>> af.blocks[0].loaded()
True
>> af.blocks[0].load() is arr  # returns the exact same array
True
>> af.blocks[0].load() is af['arrs'][0].base  # data is shared with the tree
True

TODO:

  • load into array (and via NDArrayType)

Tasks

  • run pre-commit on your machine
  • run pytest on your machine
  • Does this PR add new features and / or change user-facing code / API? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • update relevant docstrings and / or docs/ page
    • for any new features, add unit tests
news fragment change types...
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: bug fix
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.general.rst: infrastructure or miscellaneous change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant