Created
August 12, 2021 14:59
-
-
Save bkatiemills/66bc7934a6d796c9c3bf43031a3d5ac6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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