I am trying to read files containing gridded data that are formatted as flat binary 16-bit signed integer big-endian. I am using struct.unpack(), which I believe is correct as it allows me to specify the data is both signed and big-endian, but I am not sure of it recognizes the data as 16-bit. If possible, can someone confirm this is the correct method for reading the type of data I have described.
>>>file_name = 'some_file.dat'
>>>file = open(file_name, 'rb')
>>>data = struct.unpact('>h', file.read())
>>>print(data)
(-9999,)
I would like to read the entire file at once, and insert the data into a numpy array. I know the dimensions of the array and the direction used to populate the array from these files.
Thank you for any and all assistance.
whileandwithdo completely different things.withisn't even a looping construct. Trying to compare the "performance differences" between these things is like asking if carrots taste like blue.