def test_wera_radial_to_netcdf(): radial_file = data_path / 'radials' / 'WERA' / 'RDL_csw_2019_10_24_162300.ruv' nc_file = output_path / 'radials_nc' / 'WERA' / 'RDL_csw_2019_10_24_162300.nc' # Converts the underlying .data (natively a pandas DataFrame) # to an xarray object when `create_netcdf` is called. # This automatically 'enhances' the netCDF file # with better variable names and attributes. rad1 = Radial(radial_file) rad1.export(str(nc_file), file_type='netcdf') # Convert it to an xarray Dataset with no variable # or attribte enhancements xds2 = rad1.to_xarray(enhance=False) # Convert it to xarray Dataset with increased usability # by changing variables names, adding attributes, # and decoding the CF standards like scale_factor xds3 = rad1.to_xarray(enhance=True) with xr.open_dataset(nc_file) as xds1: # The two enhanced files should be identical assert xds1.identical(xds3) # Enhanced and non-enhanced files should not # be equal assert not xds1.identical(xds2)
def main(radial_file, save_path, qc_values): """ Main function to parse and qc radial files :param radial_file: Path to radial file :param save_path: Path to save quality controlled radial file :param qc_values: Dictionary containing thresholds for each QC test """ try: r = Radial(radial_file) except Exception as err: logging.error('{} - {}'.format(radial_file, err)) return if r.is_valid(): # run high frequency radar qartod tests on open radial file r.initialize_qc() r.qc_qartod_syntax() r.qc_qartod_maximum_velocity(**qc_values['qc_qartod_maximum_velocity']) r.qc_qartod_valid_location() r.qc_qartod_radial_count(**qc_values['qc_qartod_radial_count']) r.qc_qartod_spatial_median(**qc_values['qc_qartod_spatial_median']) # r.qc_qartod_avg_radial_bearing(qc_values['average_bearing_threshold']) # Export radial file to either a radial or netcdf try: r.export(os.path.join(save_path, r.file_name), 'radial') except ValueError as err: logging.error('{} - {}'.format(radial_file, err)) pass
def test_wera_raw_to_quality_nc(): radial_file = data_path / 'radials' / 'WERA' / 'RDL_csw_2019_10_24_162300.ruv' nc_file = output_path / 'radials_qc_nc' / 'WERA' / 'RDL_csw_2019_10_24_162300.nc' rad1 = Radial(radial_file, mask_over_land=False, replace_invalid=False) rad1.mask_over_land() rad1.qc_qartod_radial_count() rad1.qc_qartod_valid_location() rad1.qc_qartod_maximum_velocity() rad1.qc_qartod_spatial_median() rad1.export(str(nc_file), file_type='netcdf') xds2 = rad1.to_xarray(enhance=True) with xr.open_dataset(nc_file) as xds1: assert len(xds1.QCTest) == 3 # no VFLG column so one test not run # The two enhanced files should be identical assert xds1.identical(xds2)
def main(radial_file, save_path): """ Main function to parse and qc radial files :param radial_file: Path to radial file :param save_path: Path to save quality controlled radial file """ try: r = Radial(radial_file) except Exception: return if r.is_valid(): try: r.export( os.path.join(save_path, r.file_name.replace('.ruv', '.nc')), 'netcdf') except ValueError: pass