Skip to content

Commit

Permalink
Enable BMS transformations to be written to the same .h5 file (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Mike Boyle <michael.oliver.boyle@gmail.com>
  • Loading branch information
3 people committed Feb 22, 2024
1 parent 80469c3 commit e2c293c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
steps:
- name: Skip replicates on main branch
env:
skip_replicates: ${{ github.ref == 'refs/heads/main' && (matrix.os != 'ubuntu-latest' || matrix.python-version != '3.11') }}
skip_replicates: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'moble' && (matrix.os != 'ubuntu-latest' || matrix.python-version != '3.11') }}
shell: bash
run: |
echo "skipping_build_and_test_replicate=${skip_replicates}" >> $GITHUB_ENV
Expand Down Expand Up @@ -69,6 +69,7 @@ jobs:
runs-on: ubuntu-latest
if: >-
github.ref == 'refs/heads/main'
&& github.repository_owner == 'moble'
&& !contains(github.event.head_commit.message, '[no release]')
&& (success() || contains(github.event.head_commit.message, '[skip tests]'))
Expand Down
34 changes: 21 additions & 13 deletions scri/bms_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,24 +591,32 @@ def __mul__(self, other):

return bms_composed

def to_file(self, filename):
def to_file(self, filename, file_write_mode="w", group=None):
dt = h5py.special_dtype(vlen=str)
with h5py.File(filename, "w") as hf:
hf.create_dataset("supertranslation", data=self.supertranslation)
hf.create_dataset("frame_rotation", data=self.frame_rotation.components)
hf.create_dataset("boost_velocity", data=self.boost_velocity)
hf.create_dataset("order", data=self.order)
hf.create_dataset("ell_max", data=self.ell_max)
with h5py.File(filename, file_write_mode) as hf:
if group is not None:
g = hf.create_group(group)
else:
g = hf
g.create_dataset("supertranslation", data=self.supertranslation)
g.create_dataset("frame_rotation", data=self.frame_rotation.components)
g.create_dataset("boost_velocity", data=self.boost_velocity)
g.create_dataset("order", data=self.order)
g.create_dataset("ell_max", data=self.ell_max)

return

def from_file(self, filename):
def from_file(self, filename, group=None):
with h5py.File(filename, "r") as hf:
supertranslation = np.array(hf.get("supertranslation"))
frame_rotation = np.array(hf.get("frame_rotation"))
boost_velocity = np.array(hf.get("boost_velocity"))
order = [x.decode("utf-8") for x in np.array(hf.get("order"))]
ell_max = int(np.array(hf.get("ell_max")))
if group is not None:
g = hf[group]
else:
g = hf
supertranslation = np.array(g.get("supertranslation"))
frame_rotation = np.array(g.get("frame_rotation"))
boost_velocity = np.array(g.get("boost_velocity"))
order = [x.decode("utf-8") for x in np.array(g.get("order"))]
ell_max = int(np.array(g.get("ell_max")))

BMS = BMSTransformation(
frame_rotation=frame_rotation,
Expand Down

0 comments on commit e2c293c

Please sign in to comment.