Release History:
Version | DOI |
---|---|
2.0.0b1 | |
2.0.0b0 | |
1.6.2 | |
1.6.1 | |
1.6.0 | |
1.5.0 | |
1.4.1 | |
1.4.0 | |
1.3.0 | |
1.2.0 | |
1.1.0 | |
1.0 |
World Ocean Database data is encoded by the specification described here. This WodProfile
class reads this format, and returns an object with functions to help extract useful information from it.
Additionally, wodpy offers classes to consume IQuOD netCDF files and present them as profile objects with a similar API to the ASCII classes.
Please try unpacking your own WOD data using wodpy, and let us know how it goes in the issues. Any problems (not just bugs, but anything confusing or unintuitive), just let us know. Also, if there are more features you'd like to see (like more parts of the profile unpacked), ask away - community requests are high priority for new features.
Contributions to wodpy are very welcome! Please follow these simple guidelines:
- Please start by opening an issue or empty PR in this repo, so we can talk about your plans.
- No PRs over 500 lines, please. (Why? See figure 1 here.)
- New code should be packaged in small functions and classes wherever possible; no functions over 50 lines, please.
- Write at least one test for every new function you create.
- All tests must pass before any PR will be accepted.
from pip: sudo pip install wodpy
To use the WodProfile
class for reading ASCII WOD data, open a text file that conforms to the specification defined in the link above, and pass in the resulting file object:
from wodpy import wod
fid = open("example.dat")
profile = wod.WodProfile(fid)
profile
now contains an object with many helper functions for extracting useful information from the first profile in file
:
profile.latitude() # Return the latitude of the profile.
profile.z() # Return the depths of the observations.
profile.df() # Return a pandas DataFrame containing all the information for this profile
...
Further profiles in the file can be read as follows:
profile2 = wod.WodProfile(fid) # Read the next profile.
profile2.is_last_profile_in_file(fid) # Is this the last profile?
Complete method lists and definitions are below.
To create a similar object out of IQuOD-standard netCDF files, first make a Ragged
class object in analogy to the open file pointer above, and provide that to the ncProfile
class; for example; to get a profile object p
representing the 55th profile in the netCDF file ocldb1570984477.6279_OSD.nc
from wodpy import wodnc
r = wodnc.Ragged('ocldb1570984477.6279_OSD.nc')
p = wodnc.ncProfile(r, 55)
These methods are intended for end-user use, for decoding useful information from a profile.
These functions decode data from the current profile.
Per-profile data:
cruise()
: Returns the cruise number.day()
: Returns the day.latitude_unc()
: uncertainty on latitudelongitude_unc()
: uncertainty on longitudelatitude()
: Returns the latitude of the profile.longitude()
: Returns the longitude of the profile.month()
: Returns the month.n_levels()
: Returns the number of levels in the profile.primary_header_keys()
: Returns a list of keys in the primary header.probe_type()
: Returns the contents of secondary header 29 if it exists, otherwise None.time()
: Returns the time.uid()
: Returns the unique identifier of the profile.year()
: Returns the year.PIs()
: Returns a list of objects with keys "Variable code" and "P.I. code"originator_station()
: Returns a string denoting the originator stationoriginator_cruise()
: Returns a string denoting the originator cruiseoriginator_flag_type()
: Returns the index specifying the originator flag definitions (table 2.28 in http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf)extract_secondary_header(index)
: returns the value of the secondary header indexed by theindex
argument, where this index corresponds to the 'ID' column of table 4 in https://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf. For example,extract_secondary_header(29)
is exactly equivalent toprobe_type()
.
Per-level data:
s_unc()
: Returns a numpy masked array of salinity uncertaintiest_unc()
: Returns a numpy masked array of temperature uncertaintiesz_unc()
: Returns a numpy masked array of depth uncertaintiesoxygen()
: Returns a numpy masked array of oxygen content (mL / L).p()
: Returns a numpy masked array of pressures (decibar).pH()
: Returns a numpy masked array of pH levels.phosphate()
: Returns a numpy masked array of phosphate content (uM / L).s()
: Returns a numpy masked array of salinity.s_level_qc(originator=False)
: Returns the quality control flag for each salinity level.s_metadata()
: returns a list of dictionaries describing available salinity metadatas_profile_qc(originator=False)
: Returns the quality control flag for the salinity profile.s_qc_mask()
: Returns a boolean array showing which salinity levels failed quality control. If the entire cast was rejected then all levels are set to True.silicate()
: Returns a numpy masked array of silicate content (uM / L).t()
: Returns a numpy masked array of temperatures (C).t_level_qc(originator=False)
: Returns the quality control flag for each temperature level.t_metadata()
: returns a list of dictionaries describing available temperature metadatat_profile_qc(originator=False)
: Returns the quality control flag for the temperature profile.t_qc_mask()
: Returns a boolean array showing which temperature levels failed quality control. If the entire cast was rejected then all levels are set to True.z()
: Returns a numpy masked array of depths.z_level_qc(originator=False)
: Returns a numpy masked array of depth quality control flags. Set the originator option if the originator flags are required.
Constructing the per-level ndarrays
should not be done more than once per profile; for convenience, we provide the following wrapper to pull all this information out at once:
npdict()
: Returns adict
with keys identical to the function names above, and corresponding values equal to the return values of those functions when run with default parameter values.
profile.df()
returns a pandas DataFrame
, with per-level information as columns and per-profile information as keys in a .attrs
attribute:
Columns:
oxygen
: oxygen content (mL / L)p
: pressure (decibar)pH
: pH levelsphosphate
: phosphate content (uM / L)silicate
: silicate content (uM / L)t
: level temperature in Celciust_level_qc
: level temperature qc flags (0 == all good)t_unc
: temperature uncertaintys
: level salinitiess_level_qc
: level salinity qc flags (0 == all good)s_unc
: salinity uncertaintyz
: level depths in metersz_level_qc
: level depth qc flags (0 == all good)z_unc
: depth uncertainty
Attributes:
The following are keys in a .attrs
dictionary on the dataframe:
cruise
: cruise ID numberday
: of the month on [1, 31]latitude_unc
: uncertainty on latitudelongitude_unc
: uncertainty on longitudelatitude
: in degreeslongitude
: in degreesmonth
: of the year on [1, 12]n_levels
: number of levels in profile (ie number of rows in dataframe)originator_station
originator_cruise
originator_flag_type
PIs
probe_type
: The contents of secondary header 29 if it exists, otherwise None.s_metadata
: list of dicts describing available salinity metadatat_metadata
: list of dicts describing available temperature metadatatime
: in hours on the range [0, 24)uid
: unique identifier of profileyear
Note that DataFrame
attributes generally do not propagate to new DataFrames
returned by operating on original DataFrame
s.
Headers Only
header()
: Returns a pandasSeries
with only the header information for the profile, keyed as the custom attributes on the full data frame described above.
The class Wod4CoTeDe
provides a WOD profile in the format required by CoTeDe, which is a package to quality control hydrographic data. One could use it like:
from wodpy.extra import Wod4CoTeDe from wodpy import wod, wodnc
fid = open('example.dat') p = WodProfile(fid) profile = Wod4CoTeDe(p)
or
fid = open('example.data') profile = Wod4CoTeDe(fid)
or
ragged = wodnc.Ragged("tests/testData/ocldb1570984477.6279_OSD.nc") profile = Wod4CoTeDe(ragged, 55)
To quality control that profile with the EuroGOOS standard:
from cotede.qc import ProfileQC pqc = ProfileQC(profile, 'eurogoos')
All the information about the profile can be obtained at: pqc.attributes, pqc.data and pqc.flags. For more information, check CoTeDe's manual.