Skip to content

Cookbook

John Kerfoot edited this page May 11, 2021 · 4 revisions

WikiCookbook

Contents

Configuration

Creation of an instance of the GliderDataModel Class is the same for all glider platforms:

> from gdm import GliderDataModel
> config_path = '/Users/kerfoot/data/gliders/rucool/deployments/2020/ru29-20200908T1623/config/gmvc'
> gdm = GliderDataModel(config_path)

The config_path is searched for one or more (preferably all) of the following YAML configuration files:

  • deployment.yml: contains information on the glider deployment.
  • global_attributes.yml: contains global attributes to be assigned to the resulting xarray Dataset.
  • instruments.yml: contains information on the scientific payload including instrument serial numbers, calibration dates, etc.
  • sensor_defs.yml: contains descriptions of the sensors and optional variable mapping names.

Examples of each of these files can be found here and are discussed here.

Once configured, we can look at the instance:

> gdm
<GliderNetCDF(cfg=True, data=False, profiles=False)>

In this case, we can see that the configuration files were found and successfully parsed (cfg=True), but that no pandas DataFrame containing the raw data or indexed profile metadata have been specified. Now that the instance has been configured, let's parse a raw Slocum data file, index the profiles and add these 2 DataFrames to the instance so that we can export the dataset to xarray Dataset objects.

Slocum Gliders

The functions used below to parse and raw Slocum glider dba file are available here. Let's walk through an example by doing the following:

  1. Getting a listing of all dba files in a directory
  2. Parsing a single dba file
  3. Indexing profiles

List dbas

Let's get a time-sorted list of the available dba files in a specified directory:

> from gdm.gliders.slocum import get_dbas
> dba_path = '/Users/kerfoot/data/gliders/rucool/deployments/2020/ru29-20200908T1623/data/in/ascii/sbd'
> dba_files = get_dbas(dba_path)

The get_dbas() method parses the headers of all the slocum data files dba_path and returns a pandas DataFrame containing columns that correspond to the headers in each dba file:

> dba_files.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1081 entries, 2020-09-08 16:24:45+00:00 to 2020-11-16 12:34:07+00:00
Data columns (total 18 columns):
 #   Column              Non-Null Count  Dtype 
---  ------              --------------  ----- 
 0   file                1081 non-null   object
 1   dbd_label           1081 non-null   object
 2   encoding_ver        1081 non-null   object
 3   num_ascii_tags      1081 non-null   object
 4   all_sensors         1081 non-null   object
 5   filename            1081 non-null   object
 6   the8x3_filename     1081 non-null   object
 7   filename_extension  1081 non-null   object
 8   filename_label      1081 non-null   object
 9   mission_name        1081 non-null   object
 10  fileopen_time       1081 non-null   object
 11  sensors_per_cycle   1081 non-null   object
 12  num_label_lines     1081 non-null   object
 13  num_segments        1081 non-null   object
 14  segment_filename_0  1081 non-null   object
 15  path                1081 non-null   object
 16  bytes               1081 non-null   int64 
 17  glider              1081 non-null   object
dtypes: int64(1), object(17)
memory usage: 160.5+ KB

The index is the parsed fileopen_time and the data frame is sorted by increasing values. Let's look at the first file:

> dba_files.iloc[0]
file                                          ru29_2020_251_4_0_sbd.dat
dbd_label                         DBD_ASC(dinkum_binary_data_ascii)file
encoding_ver                                                          2
num_ascii_tags                                                       14
all_sensors                                                           0
filename                                              ru29-2020-251-4-0
the8x3_filename                                                04270000
filename_extension                                                  sbd
filename_label                          ru29-2020-251-4-0-sbd(04270000)
mission_name                                                    1K_N.MI
fileopen_time                                  Tue_Sep__8_16:24:45_2020
sensors_per_cycle                                                   112
num_label_lines                                                       3
num_segments                                                          1
segment_filename_0                                    ru29-2020-251-4-0
path                  /Users/kerfoot/data/gliders/rucool/deployments...
bytes                                                            103178
glider                                                             ru29
Name: 2020-09-08 16:24:45+00:00, dtype: object

Parsing dbas

Let's parse the first file and see if it contains any profiles:

> dba_file = os.path.join(dba_files.iloc[0].path, dba_files.iloc[0].file)
> dba, pro_meta = load_slocum_dba(dba_file)

Here's the data frame containing the file contents: > dba.info() <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 202 entries, 2020-09-08 16:23:40.157530069 to 2020-09-08 16:53:37.990449905 Columns: 121 entries, c_alt_time to sound_speed dtypes: datetime64ns, float64(113), object(2) memory usage: 202.5+ KB

and here are the sensor columns:

array(['c_alt_time', 'c_climb_target_depth', 'c_de_oil_vol',
   'c_dive_target_depth', 'c_fin', 'c_heading', 'c_science_send_all',
   'c_thruster_on', 'c_weight_drop', 'c_wpt_lat', 'c_wpt_lon',
   'c_wpt_x_lmc', 'c_wpt_y_lmc', 'f_fin_offset',
   'f_ocean_pressure_max', 'f_ocean_pressure_min', 'm_avg_speed',
   'm_battery_inst', 'm_battpos', 'm_bms_aft_current',
   'm_bms_ebay_current', 'm_bms_emergency_battery_voltage',
   'm_bms_pitch_current', 'm_comms_tickle_timestamp',
   'm_cop_tickle_timestamp', 'm_coulomb_amphr',
   'm_coulomb_amphr_total', 'm_depth', 'm_depth_rate_avg_final',
   'm_de_oil_vol', 'm_digifin_leakdetect_reading', 'm_dip_angle',
   'm_fin', 'm_final_water_vx', 'm_final_water_vy', 'm_gps_lat',
   'm_gps_lon', 'm_gps_mag_var', 'm_gps_status', 'm_hdg_derror',
   'm_hdg_error', 'm_hdg_ierror', 'm_heading',
   'm_iridium_attempt_num', 'm_iridium_call_num',
   'm_iridium_dialed_num', 'm_lat', 'm_leakdetect_voltage',
   'm_leakdetect_voltage_forward', 'm_leakdetect_voltage_science',
   'm_lon', 'm_magnetic_field', 'm_pitch', 'm_present_time',
   'm_pressure', 'm_raw_altitude', 'm_roll',
   'm_science_clothesline_lag', 'm_thruster_power',
   'm_tot_num_inflections', 'm_vacuum', 'm_vehicle_temp',
   'm_veh_temp', 'm_water_depth', 'm_water_vx', 'm_water_vy',
   'm_weight_drop', 'm_x_lmc', 'm_y_lmc', 'u_alt_filter_enabled',
   'u_alt_min_depth', 'u_hd_fin_ap_deadband_reset',
   'u_hd_fin_ap_dgain', 'u_hd_fin_ap_gain',
   'u_hd_fin_ap_hardover_holdoff', 'u_hd_fin_ap_igain',
   'u_hd_fin_ap_inflection_holdoff', 'u_heading_deadband',
   'u_heading_rate_deadband', 'u_low_power_cycle_time',
   'u_low_power_hd_fin_ap_dgain', 'u_low_power_hd_fin_ap_gain',
   'u_low_power_hd_fin_ap_igain', 'u_min_water_depth',
   'u_pitch_ap_deadband', 'u_pitch_ap_dgain', 'u_pitch_ap_gain',
   'u_pitch_max_delta_battpos', 'u_reqd_depth_at_surface',
   'u_science_low_power', 'x_current_target_altitude',
   'x_cycle_overrun_in_ms', 'x_fin_deadband', 'x_fin_max',
   'x_lmc_xy_source', 'x_low_power_status', 'x_thruster_state',
   'sci_ad2cp_bottom_track_signal', 'sci_ad2cp_file_state',
   'sci_ad2cp_run_state', 'sci_ad2cp_surface_state',
   'sci_ctd41cp_timestamp', 'sci_flbbcd_bb_units',
   'sci_flbbcd_cdom_units', 'sci_flbbcd_chlor_units',
   'sci_flbbcd_timestamp', 'sci_m_disk_free', 'sci_m_present_time',
   'sci_water_cond', 'sci_water_pressure', 'sci_water_temp',
   'segment', 'the8x3_filename', 'latitude', 'longitude', 'ilatitude',
   'ilongitude', 'depth', 'salinity', 'density', 'sound_speed'],
  dtype=object)

In addition to the 112 native sensors contained in the raw data file, there are 10 additional columns added:

  1. segment: the dba segment name, in this case 'ru29-2020-251-4-0'
  2. the8x3_filename: the 8.3 dba segment name, in this case '04270000'
  3. latitude: m_gps_lat converted to decimal degrees
  4. longitude: m_gps_lon converted to decimal degrees
  5. ilatitude: linearly interpolated latitude to provide an estimate of latitude for each record
  6. ilongitude: linearly interpolated longitude to provide an estimate of longitude for each record
  7. depth: depth calculated from sci_water_pressure (converted to decibars) and ilatitude
  8. salinity: calculated salinity
  9. density: calculated density
  10. sound_speed: calculated sound_speed

Indexing Profiles

load_slocum_dba.py also returns a data frame that contains meta data from all of the indexed profiles contained in the data file:

> pro_meta.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2 entries, 2020-09-08 16:34:03.054290056 to 2020-09-08 16:45:40.181445121
Data columns (total 10 columns):
 #   Column              Non-Null Count  Dtype         
---  ------              --------------  -----         
 0   total_seconds       2 non-null      float64       
 1   num_points          2 non-null      int64         
 2   direction           2 non-null      object        
 3   start_time          2 non-null      datetime64[ns]
 4   end_time            2 non-null      datetime64[ns]
 5   start_depth         2 non-null      float64       
 6   end_depth           2 non-null      float64       
 7   segment             2 non-null      object        
 8   depth_resolution    2 non-null      float64       
 9   sampling_frequency  2 non-null      float64       
dtypes: datetime64[ns](2), float64(5), int64(1), object(2)
memory usage: 176.0+ bytes

and the first profile:

> pro_meta.iloc[0]
total_seconds                               654.977
num_points                                       54
direction                                         d
start_time            2020-09-08 16:28:35.565610170
end_time              2020-09-08 16:39:30.542969942
start_depth                                    8.37
end_depth                                    124.19
segment                           ru29-2020-251-4-0
depth_resolution                           0.176831
sampling_frequency                          12.1292
Name: 2020-09-08 16:34:03.054290056, dtype: object

Adding the File and Indexed Profiles

These 2 DataFrames are then added to the GliderDataModel instance:

> gdm.data = dba
> gdm.profiles = pro_meta
> gdm
<GliderNetCDF(cfg=True, data=True, profiles=2)>

Now we are ready to export the data to and xarray Dataset.

Exporting

Once we have our GliderDataModel instance configured and have specified the dataset and indexed profiles, we can export all or one or more profiles. There are 2 methods that export the data to an xarray Dataset:

  • to_timeseries_dataset(): return an xarray trajectory dataset containing the all data from the raw data file. Global attributes, instrument variables and variable metadata are taken from the instance configuration.
  • slice_profile_dataset(): return an xarray trajectoryProfile dataset containing the data from the profile specified by the profile midpoint timestamp. Global attributes, instrument variables and variable metadata are taken from the instance configuration.

The objects returned by any of these methods are xarray Datasets which can be used for downstream data processing, analysis or exported to CF, ACDD or IOOS Metadata Profile compliant NetCDF files.

NOTE: The following global attributes are calculated from the exported dataset and added during export:

  • geospatial_bounds
  • geospatial_bounds_crs
  • geospatial_bounds_vertical_crs
  • geospatial_lat_max
  • geospatial_lat_min
  • geospatial_lat_resolution
  • geospatial_lat_units
  • geospatial_lon_max
  • geospatial_lon_min
  • geospatial_lon_resolution
  • geospatial_lon_units
  • geospatial_vertical_max
  • geospatial_vertical_min
  • geospatial_vertical_positive
  • geospatial_vertical_resolution
  • geospatial_vertical_units
  • time_coverage_duration
  • time_coverage_end
  • time_coverage_resolution
  • time_coverage_start

and must be changed after export in the event any changes are necessary.

Exporting Trajectories

To export the dataset as a trajectory:

> ds = gdm.to_timeseries_dataset()
> ds
<xarray.Dataset>
Dimensions:                                 (time: 202)
Coordinates:
  * time                                    (time) datetime64[ns] 2020-09-08T...
Data variables:
    commanded_alt_time                      (time) float64 nan nan ... nan nan
    commanded_climb_target_depth            (time) float64 nan nan ... nan nan
    commanded_de_oil_vol                    (time) float64 nan nan ... nan nan
    commanded_dive_target_depth             (time) float64 nan nan ... nan nan
    commanded_fin                           (time) float64 nan nan ... nan nan
    commanded_heading                       (time) float64 nan nan ... nan nan
    commanded_science_send_all              (time) float64 nan nan ... nan nan
    commanded_thruster_on                   (time) float64 nan nan ... nan nan
    commanded_weight_drop                   (time) float64 nan nan ... nan nan
    commanded_wpt_lat                       (time) float64 nan nan ... nan nan
    commanded_wpt_lon                       (time) float64 nan nan ... nan nan
    commanded_wpt_x_lmc                     (time) float64 nan nan ... nan nan
    commanded_wpt_y_lmc                     (time) float64 nan nan ... nan nan
    f_fin_offset                            (time) float64 nan nan ... nan nan
    f_ocean_pressure_max                    (time) float64 nan nan ... nan nan
    f_ocean_pressure_min                    (time) float64 nan nan ... nan nan
    measured_avg_speed                      (time) float64 nan nan ... nan nan
    measured_battery_inst                   (time) float64 nan nan ... nan nan
    measured_battpos                        (time) float64 nan nan ... nan nan
    measured_bms_aft_current                (time) float64 nan nan ... nan nan
    measured_bms_ebay_current               (time) float64 nan nan ... nan nan
    measured_bms_emergency_battery_voltage  (time) float64 nan nan ... nan nan
    measured_bms_pitch_current              (time) float64 nan nan ... nan nan
    ...
    ctd41cp_timestamp                       (time) datetime64[ns] 1970-01-01 ...
    beta_700nm                              (time) float64 0.0 nan ... nan nan
    cdom                                    (time) float64 0.0 nan ... nan nan
    chlorophyll_a                           (time) float64 0.0 nan ... nan nan
    flbbcd_timestamp                        (time) datetime64[ns] 1970-01-01 ...
    sci_m_disk_free                         (time) float64 1.988e+03 ... 1.98...
    science_timestamp                       (time) datetime64[ns] 2020-09-08T...
    conductivity                            (time) float64 0.0 nan ... nan nan
    pressure                                (time) float64 nan nan ... nan nan
    temperature                             (time) float64 0.0 nan ... nan nan
    segment                                 (time) object 'ru29-2020-251-4-0'...
    the8x3_filename                         (time) object '04270000' ... '042...
    measured_lat                            (time) float64 nan nan ... 18.18 nan
    measured_lon                            (time) float64 nan nan ... -64.8 nan
    lat                                     (time) float64 nan nan ... 18.18
    lon                                     (time) float64 nan nan ... -64.8
    depth                                   (time) float64 nan nan ... nan nan
    salinity                                (time) float64 nan nan ... nan nan
    density                                 (time) float64 nan nan ... nan nan
    sound_speed                             (time) float64 nan nan ... nan nan
    platform                                float64 nan
    instrument_ctd                          float64 nan
    instrument_flbbcd                       float64 nan
    instrument_ad2cp                        float64 nan
    trajectory                              <U18 'ru29-20200908T1623'
Attributes:
    Conventions:                     CF-1.6, ACDD-1.3, IOOS-1.2
    acknowledgment:                  Funding and support provided by the G. U...
    cdm_data_type:                    
    comment:                         Deployed by Antonio Farchetti, Kenique L...
    contributor_name:                Scott Glenn,Oscar Schofield,Travis Miles...
    contributor_role:                principalInvestigator,principalInvestiga...
    contributor_role_vocabulary:     https://vocab.nerc.ac.uk/collection/G04/...
    creator_country:                 USA
    creator_email:                   kerfoot@marine.rutgers.edu
    creator_institution:             Rutgers University
    creator_name:                    John Kerfoot
    creator_sector:                  academic
    creator_type:                    person
    creator_url:                     https://rucool.marine.rutgers.edu
    date_created:                    2020-12-08T18:14:22Z
    date_issued:                     2020-12-08T18:14:22Z
    date_metadata_modified:           
    date_modified:                    
    featureType:                     trajectory
    geospatial_bounds:               POLYGON ((18.17716666666667 -64.80589000...
    geospatial_bounds_crs:           EPSG:4326
    geospatial_bounds_vertical_crs:  EPSG:5831
    geospatial_lat_max:              18.17716666666667
    geospatial_lat_min:              18.17529
    geospatial_lat_resolution:       0.00001 degree
    geospatial_lat_units:            degrees_north
    geospatial_lon_max:              -64.8028
    geospatial_lon_min:              -64.80589
    geospatial_lon_resolution:       0.00001 degree
    geospatial_lon_units:            degrees_east
    geospatial_vertical_max:         123.4073257374073
    geospatial_vertical_min:         6.043413831651445
    geospatial_vertical_positive:    down
    geospatial_vertical_resolution:  0.58
    geospatial_vertical_units:       m
    gts_ingest:                      True
    history:                          
    id:                              ru29-20200908T1623
    infoUrl:                         https://rucool.marine.rutgers.edu
    institution:                     Rutgers University
    instrument:                      In Situ/Laboratory Instruments > Profile...
    instrument_vocabulary:           NASA/GCMD Instrument Keywords Version 8.5
    ioos_regional_association:       MARACOOS
    keywords:                        Oceans > Ocean Pressure > Water Pressure...
    keywords_vocabulary:             NASA/GCMD Earth Sciences Keywords Versio...
    license:                         This data may be redistributed and used ...
    metadata_link:                    
    naming_authority:                edu.rutgers.rucool
    ncei_template_version:           NCEI_NetCDF_Trajectory_Template_v2.0
    platform:                        In Situ Ocean-based Platforms > AUVS > A...
    platform_type:                   Slocum Glider
    platform_vocabulary:             NASA/GCMD Platforms Keywords Version 8.5
    processing_level:                Delayed-mode/recovered raw Slocum glider...
    product_version:                 1.0
    program:                         Challenger
    project:                         Challenger
    publisher_country:               USA
    publisher_email:                 kerfoot@marine.rutgers.edu
    publisher_institution:           Rutgers University
    publisher_name:                  John Kerfoot
    publisher_type:                  person
    publisher_url:                   https://rucool.marine.rutgers.edu
    references:                      https://ioos.noaa.gov/wp-content/uploads...
    sea_name:                        Caribbean Sea
    source:                          local file
    standard_name_vocabulary:        CF Standard Name Table v27
    summary:                         The Challenger Glider Mission is a re-cr...
    time_coverage_duration:          PT29M57.83292S
    time_coverage_end:               2020-09-08T16:53:37Z
    time_coverage_resolution:        PT08S
    time_coverage_start:             2020-09-08T16:23:40Z            
    title:                           ru29 20200908T162340Z trajectory
    wmo_platform_code:               4802960
    uuid:                            b56c3c0e-e2f4-4a63-ae0f-4300fc8bf17e

Exporting trajectoryProfiles

To export the first profile in the dataset:

> pro_ds = gdm.slice_profile_dataset(gdm.profiles.index[0])
> pro_ds
<xarray.Dataset>
Dimensions:                                 (time: 73)
Coordinates:
  * time                                    (time) datetime64[ns] 2020-09-08T...
Data variables:
    commanded_alt_time                      (time) float64 nan nan ... nan nan
    commanded_climb_target_depth            (time) float64 nan nan ... nan nan
    commanded_de_oil_vol                    (time) float64 nan nan ... nan nan
    commanded_dive_target_depth             (time) float64 nan nan ... nan nan
    commanded_fin                           (time) float64 nan nan ... nan nan
    commanded_heading                       (time) float64 nan nan ... nan nan
    commanded_science_send_all              (time) float64 nan nan ... nan nan
    commanded_thruster_on                   (time) float64 nan nan ... nan nan
    commanded_weight_drop                   (time) float64 nan nan ... nan nan
    commanded_wpt_lat                       (time) float64 nan nan ... nan nan
    commanded_wpt_lon                       (time) float64 nan nan ... nan nan
    commanded_wpt_x_lmc                     (time) float64 nan nan ... nan nan
    commanded_wpt_y_lmc                     (time) float64 nan nan ... nan nan
    f_fin_offset                            (time) float64 nan nan ... nan nan
    f_ocean_pressure_max                    (time) float64 nan nan ... nan nan
    f_ocean_pressure_min                    (time) float64 nan nan ... nan nan
    measured_avg_speed                      (time) float64 nan nan ... nan nan
    measured_battery_inst                   (time) float64 nan nan ... nan nan
    measured_battpos                        (time) float64 nan nan ... nan nan
    measured_bms_aft_current                (time) float64 nan nan ... nan nan
    measured_bms_ebay_current               (time) float64 nan nan ... nan nan
    measured_bms_emergency_battery_voltage  (time) float64 nan nan ... nan nan
    measured_bms_pitch_current              (time) float64 nan nan ... nan nan
    ...
    ctd41cp_timestamp                       (time) datetime64[ns] 1970-01-01 ...
    beta_700nm                              (time) float64 0.0 nan ... nan nan
    cdom                                    (time) float64 0.0 nan ... nan nan
    chlorophyll_a                           (time) float64 0.0 nan ... nan nan
    flbbcd_timestamp                        (time) datetime64[ns] 1970-01-01 ...
    sci_m_disk_free                         (time) float64 1.988e+03 ... 1.98...
    science_timestamp                       (time) datetime64[ns] 2020-09-08T...
    conductivity                            (time) float64 0.0 nan ... nan nan
    pressure                                (time) float64 nan nan ... nan nan
    temperature                             (time) float64 0.0 nan ... nan nan
    segment                                 (time) object 'ru29-2020-251-4-0'...
    the8x3_filename                         (time) object '04270000' ... '042...
    measured_lat                            (time) float64 nan nan ... 18.18 nan
    measured_lon                            (time) float64 nan nan ... -64.8 nan
    lat                                     (time) float64 nan nan ... 18.18
    lon                                     (time) float64 nan nan ... -64.8
    depth                                   (time) float64 nan nan ... nan nan
    salinity                                (time) float64 nan nan ... nan nan
    density                                 (time) float64 nan nan ... nan nan
    sound_speed                             (time) float64 nan nan ... nan nan
    platform                                float64 nan
    instrument_ctd                          float64 nan
    instrument_flbbcd                       float64 nan
    instrument_ad2cp                        float64 nan
    trajectory                              <U18 'ru29-20200908T1623'
    profile_lat                             float64 18.18
    profile_lon                             float64 -64.81
    profile_time                            datetime64[ns] 2020-09-08T16:34:0...
Attributes:
    Conventions:                     CF-1.6, ACDD-1.3, IOOS-1.2
    acknowledgment:                  Funding and support provided by the G. U...
    cdm_data_type:                    
    comment:                         Deployed by Antonio Farchetti, Kenique L...
    contributor_name:                Scott Glenn,Oscar Schofield,Travis Miles...
    contributor_role:                principalInvestigator,principalInvestiga...
    contributor_role_vocabulary:     https://vocab.nerc.ac.uk/collection/G04/...
    creator_country:                 USA
    creator_email:                   kerfoot@marine.rutgers.edu
    creator_institution:             Rutgers University
    creator_name:                    John Kerfoot
    creator_sector:                  academic
    creator_type:                    person
    creator_url:                     https://rucool.marine.rutgers.edu
    date_created:                     
    date_issued:                      
    date_metadata_modified:           
    date_modified:                    
    featureType:                     trajectoryProfile
    geospatial_bounds:               POLYGON ((18.1771450617284 -64.805832777...
    geospatial_bounds_crs:           EPSG:4326
    geospatial_bounds_vertical_crs:  EPSG:5831
    geospatial_lat_max:              18.177145061728396
    geospatial_lat_min:              18.176626543209878
    geospatial_lat_resolution:       0.00001 degree
    geospatial_lat_units:            degrees_north
    geospatial_lon_max:              -64.80445944444445
    geospatial_lon_min:              -64.80583277777778
    geospatial_lon_resolution:       0.00001 degree
    geospatial_lon_units:            degrees_east
    geospatial_vertical_max:         123.4073257374073
    geospatial_vertical_min:         8.319587076348384
    geospatial_vertical_positive:    down
    geospatial_vertical_resolution:  1.58
    geospatial_vertical_units:       m
    gts_ingest:                      True
    history:                          
    id:                               
    infoUrl:                         https://rucool.marine.rutgers.edu
    institution:                     Rutgers University
    instrument:                      In Situ/Laboratory Instruments > Profile...
    instrument_vocabulary:           NASA/GCMD Instrument Keywords Version 8.5
    ioos_regional_association:       MARACOOS
    keywords:                        Oceans > Ocean Pressure > Water Pressure...
    keywords_vocabulary:             NASA/GCMD Earth Sciences Keywords Versio...
    license:                         This data may be redistributed and used ...
    metadata_link:                    
    naming_authority:                edu.rutgers.rucool
    ncei_template_version:           NCEI_NetCDF_Trajectory_Template_v2.0
    platform:                        In Situ Ocean-based Platforms > AUVS > A...
    platform_type:                   Slocum Glider
    platform_vocabulary:             NASA/GCMD Platforms Keywords Version 8.5
    processing_level:                Delayed-mode/recovered raw Slocum glider...
    product_version:                 1.0
    program:                         Challenger
    project:                         Challenger
    publisher_country:               USA
    publisher_email:                 kerfoot@marine.rutgers.edu
    publisher_institution:           Rutgers University
    publisher_name:                  John Kerfoot
    publisher_type:                  person
    publisher_url:                   https://rucool.marine.rutgers.edu
    references:                      https://ioos.noaa.gov/wp-content/uploads...
    sea_name:                        Caribbean Sea
    source:                           
    standard_name_vocabulary:        CF Standard Name Table v27
    summary:                         The Challenger Glider Mission is a re-cr...
    time_coverage_duration:          PT10M42.82041S
    time_coverage_end:               2020-09-08T16:39:30Z
    time_coverage_resolution:        PT08S
    time_coverage_start:             2020-09-08T16:28:47Z
    title:                           ru29 20200908T163403Z trajectoryProfile
    wmo_platform_code:               4802960

Another method:

returns an iterator used to loop through all the profiles, provided via the indexed profile metadata DataFrame, and return an xarray Dataset for each profile.

Writing NetCDFs

The iter_profiles() method is a quick way to iterate through all of the profiles contained in a dataset and write them to disk as NetCDF files:

> dba_files.iloc[0].file.split('_')[0]
> out_nc_path = '/Users/kerfoot/data/gliders/rucool/deployments/2020/ru29-20200908T1623/data/out/nc/sandbox'
> for profile_time, pro_ds in gdm.iter_profiles():
    nc_path = os.path.join(out_nc_path, '{:}_{:}_rt.nc'.format(glider, profile_time.strftime('%Y%m%dT%H%M%S')))
    logging.info('Writing {:}'.format(nc_path))
    pro_ds.to_netcdf(nc_path)

2020-12-08 15:23:54,949<input>:INFO:Writing /Users/kerfoot/data/gliders/rucool/deployments/2020/ru29-20200908T1623/data/out/nc/sandbox/ru29_20200908T163403_rt.nc [line 3]
2020-12-08 15:23:56,472<input>:INFO:Writing /Users/kerfoot/data/gliders/rucool/deployments/2020/ru29-20200908T1623/data/out/nc/sandbox/ru29_20200908T164540_rt.nc [line 3]