import numpy as np
import pandas as pd
import xarray as xr
import earthaccess
import matplotlib.pyplot as plt
From the PO.DAAC Cookbook, to access the GitHub version of the notebook, follow this link.
SWOT Quality Flag Demonstration
Summary:
SWOT standard data products such as L2_LR_SSH include quality flags that communicate detailed information about the quality of the observation reported. SWOT quality flags are paired one-to-one with the core science data variables in each netcdf file. They’re identified by the qual
suffix, e.g.
Science data variable:
<variable name>
Quality flag variable:
<variable name>_qual
Depending on the data product though, the quality flag may not end with qual
, you may need to alter the code for your particular dataset. See the summary chart below.
Quality flags have different syntax depending on which data product is being used. If a measurement has a quality flag, it can also have a bit flag that provides the detail of why the quality flags are set as they are (see Product Description Documents (PDDs) for specific value meanings). In addition to the ’_qual’ or ’_q’ indications, ’_flag’ or ’_f’ (e.g., ‘ice_flag’) may be used in each data product to raise different flags with unique values and meanings. See specific PDDs for more information.
SWOT Product | Quality Flag Identifier | Values and Meanings |
---|---|---|
L2_HR_RiverSP L2_HR_RiverAvg |
Var + ’_q’ Overall Quality Variables: ‘reach_q’ or ‘node_q’ Bitwise: Var + ’_q_b’ |
0 = good 1 = suspect - may have large errors 2 = degraded - likely to have large errors 3 = bad - may be nonsensical and should be ignored For discharge parameters: (e.g., ‘dschg_c_q’) 0 = valid 1 = questionable 2 = invalid |
L2_HR_LakeSP L2_HR_LakeAvg |
Overall quality Variable: ‘quality_f’ | 0 = good 1 = bad |
L2_HR_Raster | Var + ’_qual’ Ex: ‘wse_qual’ Bitwise: Var + ’_qual_bitwise’ |
0 = good 1 = suspect - may have large errors 2 = degraded - likely to have large errors 3 = bad - may be nonsensical and should be ignored |
L2_NALT_GDR L2_NALT_IGDR L2_NALT_OGDR L2_RAD_GDR L2_RAD_IGDR L2_RAD_OGDR L2_FPDEM |
Var + ’_qual’ Ex: ‘rad_water_vapor_qual’ |
0 = good 1 = bad |
L2_LR_SSH L2_HR_PIXC L1B_HR_SLC L1B_LR_INTF |
Var + ’_qual’ | Varies, see PDDs |
Quality flags are stored as arrays of integers. Each integer decomposes into a series of bits that individually describe data quality according to various criteria specific to each science data product from SWOT. This example will demonstrate how to interrogate the quality information about the ssha_karin_2 variable in one L2 LR SSH product/file.
Requirement:
This tutorial can be run on a local machine or the AWS cloud, if AWS cloud, it must be an instance running in us-west-2: NASA Earthdata Cloud data in https or S3 can be directly accessed via earthaccess
python library.
Learning Objectives:
- Demonstrate how to interrogate the quality information for the ssha_karin_2 variable in one L2 LR SSH product/files, though this process can be used for other SWOT data with associated 8-bit quality flags.
- Filter data via quality flags and visualize
Notebook Author: Jack McNelis, NASA PO.DAAC (April 2024) || Other Contributors: Cassie Nickles (NASA PO.DAAC)
Libraries Needed:
Earthdata Login
An Earthdata Login account is required to access data, as well as discover restricted data, from the NASA Earthdata system. Thus, to access NASA data, you need Earthdata Login. Please visit https://urs.earthdata.nasa.gov to register and manage your Earthdata Login account. This account is free to create and only takes a moment to set up. We use earthaccess to authenticate your login credentials below.
= earthaccess.login() auth
Use earthaccess to search SWOT data
Here we use the SSH shortname, SWOT_L2_LR_SSH_Expert_2.0
= earthaccess.search_data(short_name = 'SWOT_L2_LR_SSH_Expert_2.0',
ssh_results = ("2024-03-22 00:00:00", "2024-03-22 23:59:59"))#,
temporal #granule_name = '*_Expert_012_455*') #if you know what cycle and pass you want, you can be more specific
Granules found: 29
If accessing via Local Machine
# If you are on a local machine, download the first file to your local computer
0], "./data_downloads/SWOT_files") earthaccess.download(ssh_results[
Getting 1 granules, approx download size: 0.03 GB
['data_downloads\\SWOT_files\\SWOT_L2_LR_SSH_Expert_012_428_20240321T235733_20240322T004901_PIC0_01.nc']
# Open via xarray
= xr.open_mfdataset("./data_downloads/SWOT_files/SWOT_L2_LR_SSH_Expert*.nc")#, mask_and_scale=False)
ds ds
<xarray.Dataset> Dimensions: (num_lines: 9866, num_pixels: 69, num_sides: 2) Coordinates: latitude (num_lines, num_pixels) float64 dask.array<chunksize=(9866, 69), meta=np.ndarray> longitude (num_lines, num_pixels) float64 dask.array<chunksize=(9866, 69), meta=np.ndarray> latitude_nadir (num_lines) float64 dask.array<chunksize=(9866,), meta=np.ndarray> longitude_nadir (num_lines) float64 dask.array<chunksize=(9866,), meta=np.ndarray> Dimensions without coordinates: num_lines, num_pixels, num_sides Data variables: (12/98) time (num_lines) datetime64[ns] dask.array<chunksize=(9866,), meta=np.ndarray> time_tai (num_lines) datetime64[ns] dask.array<chunksize=(9866,), meta=np.ndarray> ssh_karin (num_lines, num_pixels) float64 dask.array<chunksize=(9866, 69), meta=np.ndarray> ssh_karin_qual (num_lines, num_pixels) float64 dask.array<chunksize=(9866, 69), meta=np.ndarray> ssh_karin_uncert (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> ssha_karin (num_lines, num_pixels) float64 dask.array<chunksize=(9866, 69), meta=np.ndarray> ... ... swh_ssb_cor_source (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> swh_ssb_cor_source_2 (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> wind_speed_ssb_cor_source (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> wind_speed_ssb_cor_source_2 (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> volumetric_correlation (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> volumetric_correlation_uncert (num_lines, num_pixels) float32 dask.array<chunksize=(9866, 69), meta=np.ndarray> Attributes: (12/62) Conventions: CF-1.7 title: Level 2 Low Rate Sea Surfa... institution: CNES source: Ka-band radar interferometer history: 2024-03-24T22:39:40Z : Cre... platform: SWOT ... ... ellipsoid_semi_major_axis: 6378137.0 ellipsoid_flattening: 0.0033528106647474805 good_ocean_data_percent: 67.62656103685167 ssha_variance: 0.7787372594877449 references: V1.2.1 equator_longitude: 52.58
- Conventions :
- CF-1.7
- title :
- Level 2 Low Rate Sea Surface Height Data Product - Expert SSH with Wind and Wave
- institution :
- CNES
- source :
- Ka-band radar interferometer
- history :
- 2024-03-24T22:39:40Z : Creation
- platform :
- SWOT
- reference_document :
- D-56407_SWOT_Product_Description_L2_LR_SSH
- contact :
- podaac@jpl.nasa.gov
- cycle_number :
- 12
- pass_number :
- 428
- equator_time :
- 2024-03-22T00:23:15.167000Z
- short_name :
- L2_LR_SSH
- product_file_id :
- Expert
- crid :
- PIC0
- product_version :
- 01
- pge_name :
- PGE_L2_LR_SSH
- pge_version :
- 5.0.2
- time_coverage_start :
- 2024-03-21T23:57:33.259925
- time_coverage_end :
- 2024-03-22T00:49:01.265518
- geospatial_lon_min :
- 328.86312899999996
- geospatial_lon_max :
- 136.307662
- geospatial_lat_min :
- -78.271942
- geospatial_lat_max :
- 78.27206799999999
- left_first_longitude :
- 328.86312899999996
- left_first_latitude :
- 78.27200599999999
- left_last_longitude :
- 136.288291
- left_last_latitude :
- -77.05370099999999
- right_first_longitude :
- 328.880955
- right_first_latitude :
- 77.053837
- right_last_longitude :
- 136.307662
- right_last_latitude :
- -78.27186999999999
- wavelength :
- 0.008385803020979021
- transmit_antenna :
- minus_y
- xref_l1b_lr_intf_file :
- SWOT_L1B_LR_INTF_012_428_20240321T235729_20240322T004904_PIC0_01.nc
- xref_l2_nalt_gdr_files :
- SWOT_IPN_2PfP012_427_20240321_230606_20240321_235733.nc, SWOT_IPN_2PfP012_428_20240321_235733_20240322_004900.nc, SWOT_IPN_2PfP012_429_20240322_004900_20240322_014027.nc
- xref_l2_rad_gdr_files :
- SWOT_IPRAD_2PaP012_427_20240321_230603_20240321_235737_PIC0_01.nc, SWOT_IPRAD_2PaP012_428_20240321_235729_20240322_004904_PIC0_01.nc, SWOT_IPRAD_2PaP012_429_20240322_004856_20240322_014031_PIC0_01.nc
- xref_int_lr_xover_cal_file :
- SWOT_INT_LR_XOverCal_20240321T235723_20240322T235815_PIC0_01.nc
- xref_statickarincal_files :
- SWOT_StaticKaRInCalAdjustableParam_20000101T000000_20991231T235959_20230823T210000_v106.nc
- xref_param_l2_lr_precalssh_file :
- SWOT_Param_L2_LR_PreCalSSH_20000101T000000_20991231T235959_20230815T120500_v301.nc
- xref_orbit_ephemeris_file :
- SWOT_POR_AXVCNE20240323_105038_20240321_225923_20240323_005923.nc
- xref_reforbittrack_files :
- SWOT_RefOrbitTrack125mPass1_Nom_20000101T000000_21000101T000000_20200617T193054_v101.txt, SWOT_RefOrbitTrack125mPass2_Nom_20000101T000000_21000101T000000_20200617T193054_v101.txt
- xref_meteorological_sealevel_pressure_files :
- SMM_PMA_AXVCNE20240322_031037_20240321_180000_20240321_180000, SMM_PMA_AXVCNE20240322_051603_20240322_000000_20240322_000000, SMM_PMA_AXVCNE20240322_163941_20240322_060000_20240322_060000
- xref_meteorological_wettroposphere_files :
- SMM_WEA_AXVCNE20240322_031037_20240321_180000_20240321_180000, SMM_WEA_AXVCNE20240322_051603_20240322_000000_20240322_000000, SMM_WEA_AXVCNE20240322_163941_20240322_060000_20240322_060000
- xref_meteorological_wind_files :
- SMM_VWA_AXVCNE20240322_031037_20240321_180000_20240321_180000, SMM_UWA_AXVCNE20240322_031037_20240321_180000_20240321_180000, SMM_VWA_AXVCNE20240322_051603_20240322_000000_20240322_000000, SMM_UWA_AXVCNE20240322_051603_20240322_000000_20240322_000000, SMM_UWA_AXVCNE20240322_163941_20240322_060000_20240322_060000, SMM_VWA_AXVCNE20240322_163941_20240322_060000_20240322_060000
- xref_meteorological_surface_pressure_files :
- SMM_PSA_AXVCNE20240322_054027_20240321_180000_20240321_180000, SMM_PSA_AXVCNE20240322_054027_20240322_000000_20240322_000000, SMM_PSA_AXVCNE20240322_174027_20240322_060000_20240322_060000
- xref_meteorological_temperature_files :
- SMM_T2M_AXPCNE20240322_054027_20240321_180000_20240321_180000.grb, SMM_T2M_AXPCNE20240322_054027_20240322_000000_20240322_000000.grb, SMM_T2M_AXPCNE20240322_174027_20240322_060000_20240322_060000.grb
- xref_meteorological_water_vapor_files :
- SMM_CWV_AXPCNE20240322_054027_20240321_180000_20240321_180000.grb, SMM_CWV_AXPCNE20240322_054027_20240322_000000_20240322_000000.grb, SMM_CWV_AXPCNE20240322_174027_20240322_060000_20240322_060000.grb
- xref_meteorological_cloud_liquid_water_files :
- SMM_CLW_AXPCNE20240322_054027_20240321_180000_20240321_180000.grb, SMM_CLW_AXPCNE20240322_054027_20240322_000000_20240322_000000.grb, SMM_CLW_AXPCNE20240322_174027_20240322_060000_20240322_060000.grb
- xref_model_significant_wave_height_files :
- SMM_SWH_AXPCNE20240322_054027_20240321_180000_20240321_180000.grb, SMM_SWH_AXPCNE20240322_054027_20240322_000000_20240322_000000.grb, SMM_SWH_AXPCNE20240322_174027_20240322_060000_20240322_060000.grb
- xref_gim_files :
- JPLQ0810.24I, JPLQ0820.24I
- xref_pole_location_file :
- SMM_PO1_AXXCNE20240324_020000_19900101_000000_20240920_000000
- xref_dac_files :
- SMM_MOG_AXPCNE20240322_074502_20240321_180000_20240321_180000, SMM_MOG_AXPCNE20240322_074502_20240322_000000_20240322_000000, SMM_MOG_AXPCNE20240322_203000_20240322_060000_20240322_060000
- xref_precipitation_files :
- SMM_LSR_AXFCNE20240321_185544_20240321_180000_20240321_180000.grb, SMM_CRR_AXFCNE20240321_185544_20240321_180000_20240321_180000.grb, SMM_CRR_AXFCNE20240322_065522_20240322_000000_20240322_000000.grb, SMM_LSR_AXFCNE20240322_065522_20240322_000000_20240322_000000.grb, SMM_CRR_AXFCNE20240322_065522_20240322_060000_20240322_060000.grb, SMM_LSR_AXFCNE20240322_065522_20240322_060000_20240322_060000.grb
- xref_sea_ice_mask_files :
- SMM_ICN_AXFCNE20240322_095633_20240321_000000_20240321_235959.nc, SMM_ICS_AXFCNE20240322_095633_20240321_000000_20240321_235959.nc, SMM_ICN_AXFCNE20240323_041507_20240322_000000_20240322_235959.nc, SMM_ICS_AXFCNE20240323_042002_20240322_000000_20240322_235959.nc
- xref_wave_model_files :
- SMM_WMA_AXPCNE20240322_072016_20240321_030000_20240322_000000.grb, SMM_WMA_AXPCNE20240323_072017_20240322_030000_20240323_000000.grb
- xref_geco_database_version :
- v102
- ellipsoid_semi_major_axis :
- 6378137.0
- ellipsoid_flattening :
- 0.0033528106647474805
- good_ocean_data_percent :
- 67.62656103685167
- ssha_variance :
- 0.7787372594877449
- references :
- V1.2.1
- equator_longitude :
- 52.58