Skip to content

Instantly share code, notes, and snippets.

@bkatiemills
Created August 12, 2021 14:59
Show Gist options
  • Save bkatiemills/66bc7934a6d796c9c3bf43031a3d5ac6 to your computer and use it in GitHub Desktop.
Save bkatiemills/66bc7934a6d796c9c3bf43031a3d5ac6 to your computer and use it in GitHub Desktop.
from wodpy import wod
def find_instrument_code(profile, varcode):
'''
given a wodpy profile and a variable code varcode as defined in table 3 of [reference 1],
return the instrument code from [reference 2] associated with this measurement, if it is available;
if not, return None.
[reference 1]: https://www.ncei.noaa.gov/data/oceans/woa/WOD/DOC/wodreadme.pdf
[reference 2]: https://www.ncei.noaa.gov/data/oceans/woa/WOD/CODES/PDF/v_5_instrument.pdf
'''
for var in profile.primary_header['variables']:
# pick out the variable of interest, for example varcode==1 is temperature.
if var['Variable code'] == varcode:
for meta in var['metadata']:
# pick out metadata index 5, which corresponds to v_5_instrument
if meta['Variable-specific code'] == 5:
return meta['Value']
# if no instrument is found, return None.
return None
fid = open("data/quota_subset.dat")
profile = wod.WodProfile(fid)
print(find_instrument_code(profile, 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment