Skip to content

Instantly share code, notes, and snippets.

@d-chambers
Last active March 17, 2022 22:13
Show Gist options
  • Save d-chambers/5cd99ecbac18425fd0265bda9d44b626 to your computer and use it in GitHub Desktop.
Save d-chambers/5cd99ecbac18425fd0265bda9d44b626 to your computer and use it in GitHub Desktop.
Reading RSF (Madagascar) files into numpy arrays.
# Example modified from here: https://github.com/ahay/src/issues/130
from subprocess import run
import m8r
import numpy as np
# create example data
run('sfspike n1=5 n2=5 k1=3 > spike.rsf', shell=True)
# Read rsf file
rsf = m8r.Input('spike.rsf')
# Init output array of appropriate size
output = np.zeros(rsf.shape(), dtype='float32')
# Populate output array with contents of rsf file
rsf.read(output)
@d-chambers
Copy link
Author

d-chambers commented Mar 17, 2022

Actually, I just noticed m8r.Input has a read method, so this can be simplified:

# Example modified from here: https://github.com/ahay/src/issues/130
from subprocess import run
 
import m8r

# create example data
run('sfspike n1=5 n2=5 k1=3 > spike.rsf', shell=True)
 
# Read rsf file
output = m8r.Input('spike.rsf').read()

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