def test_themis_mag(): fname = 'thg_l2_mag_amd_20070323_v01.cdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/thg_l2_mag_amd_20070323_v01.cdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) a = cdflib.cdf_to_xarray("thg_l2_mag_amd_20070323_v01.cdf", to_unixtime=True, fillval_to_nan=True) cdflib.xarray_to_cdf(a, 'thg_l2_mag_amd_20070323_v01-created-from-cdf-input.cdf', from_unixtime=True) b = cdflib.cdf_to_xarray('thg_l2_mag_amd_20070323_v01-created-from-cdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('thg_l2_mag_amd_20070323_v01-created-from-cdf-input.cdf') os.remove('thg_l2_mag_amd_20070323_v01.cdf') fname = 'thg_l2_mag_amd_20070323_v01.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/thg_l2_mag_amd_20070323_v01.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("thg_l2_mag_amd_20070323_v01.nc") cdflib.xarray_to_cdf(c, 'thg_l2_mag_amd_20070323_v01-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('thg_l2_mag_amd_20070323_v01-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('thg_l2_mag_amd_20070323_v01-created-from-netcdf-input.cdf') os.remove('thg_l2_mag_amd_20070323_v01.nc')
def test_mms_fgm(): fname = 'mms2_fgm_srvy_l2_20160809_v4.47.0.cdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/mms2_fgm_srvy_l2_20160809_v4.47.0.cdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) a = cdflib.cdf_to_xarray("mms2_fgm_srvy_l2_20160809_v4.47.0.cdf", to_unixtime=True, fillval_to_nan=True) cdflib.xarray_to_cdf(a, 'mms2_fgm_srvy_l2_20160809_v4.47.0-created-from-cdf-input.cdf', from_unixtime=True) b = cdflib.cdf_to_xarray('mms2_fgm_srvy_l2_20160809_v4.47.0-created-from-cdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('mms2_fgm_srvy_l2_20160809_v4.47.0-created-from-cdf-input.cdf') os.remove('mms2_fgm_srvy_l2_20160809_v4.47.0.cdf') fname = 'mms2_fgm_srvy_l2_20160809_v4.47.0.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/mms2_fgm_srvy_l2_20160809_v4.47.0.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("mms2_fgm_srvy_l2_20160809_v4.47.0.nc") cdflib.xarray_to_cdf(c, 'mms2_fgm_srvy_l2_20160809_v4.47.0-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('mms2_fgm_srvy_l2_20160809_v4.47.0-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('mms2_fgm_srvy_l2_20160809_v4.47.0-created-from-netcdf-input.cdf') os.remove('mms2_fgm_srvy_l2_20160809_v4.47.0.nc')
def test_wi_k0(): fname = 'wi_k0_spha_20210121_v01.cdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/wi_k0_spha_20210121_v01.cdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) a = cdflib.cdf_to_xarray("wi_k0_spha_20210121_v01.cdf", to_unixtime=True, fillval_to_nan=True) cdflib.xarray_to_cdf(a, 'wi_k0_spha_20210121_v01-created-from-cdf-input.cdf', from_unixtime=True) b = cdflib.cdf_to_xarray('wi_k0_spha_20210121_v01-created-from-cdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('wi_k0_spha_20210121_v01-created-from-cdf-input.cdf') os.remove('wi_k0_spha_20210121_v01.cdf') fname = 'wi_k0_spha_20210121_v01.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/wi_k0_spha_20210121_v01.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset('wi_k0_spha_20210121_v01.nc') cdflib.xarray_to_cdf(c, 'wi_k0_spha_20210121_v01-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('wi_k0_spha_20210121_v01-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('wi_k0_spha_20210121_v01-created-from-netcdf-input.cdf') os.remove('wi_k0_spha_20210121_v01.nc')
def test_swi_onboardsvyspec(): fname = 'mvn_swi_l2_onboardsvyspec_20180720_v01_r01.cdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/mvn_swi_l2_onboardsvyspec_20180720_v01_r01.cdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) a = cdflib.cdf_to_xarray("mvn_swi_l2_onboardsvyspec_20180720_v01_r01.cdf", to_unixtime=True, fillval_to_nan=True) cdflib.xarray_to_cdf(a, 'mvn_swi_l2_onboardsvyspec_20180720_v01_r01-created-from-cdf-input.cdf', from_unixtime=True) b = cdflib.cdf_to_xarray('mvn_swi_l2_onboardsvyspec_20180720_v01_r01-created-from-cdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('mvn_swi_l2_onboardsvyspec_20180720_v01_r01-created-from-cdf-input.cdf') os.remove('mvn_swi_l2_onboardsvyspec_20180720_v01_r01.cdf') fname = 'mvn_swi_l2_onboardsvyspec_20180720_v01_r01.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/mvn_swi_l2_onboardsvyspec_20180720_v01_r01.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("mvn_swi_l2_onboardsvyspec_20180720_v01_r01.nc") cdflib.xarray_to_cdf(c, 'mvn_swi_l2_onboardsvyspec_20180720_v01_r01-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('mvn_swi_l2_onboardsvyspec_20180720_v01_r01-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('mvn_swi_l2_onboardsvyspec_20180720_v01_r01-created-from-netcdf-input.cdf') os.remove('mvn_swi_l2_onboardsvyspec_20180720_v01_r01.nc')
def test_something(): fname = 'sgpsondewnpnC1.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/sgpsondewnpnC1.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("sgpsondewnpnC1.nc") cdflib.xarray_to_cdf(c, 'sgpsondewnpnC1-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('sgpsondewnpnC1-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('sgpsondewnpnC1-created-from-netcdf-input.cdf') os.remove('sgpsondewnpnC1.nc')
def test_see_l2a(): fname = 'see__xps_L2A_2021006_012_02.ncdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/see__xps_L2A_2021006_012_02.ncdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("see__xps_L2A_2021006_012_02.ncdf") cdflib.xarray_to_cdf(c, 'see__xps_L2A_2021006_012_02.ncdfhello2.cdf') d = cdflib.cdf_to_xarray('see__xps_L2A_2021006_012_02.ncdfhello2.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('see__xps_L2A_2021006_012_02.ncdfhello2.cdf') os.remove('see__xps_L2A_2021006_012_02.ncdf')
def test_raids(): fname = 'raids_nirs_20100823_v1.1.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/raids_nirs_20100823_v1.1.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("raids_nirs_20100823_v1.1.nc") cdflib.xarray_to_cdf(c, 'raids_nirs_20100823_v1.1-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('raids_nirs_20100823_v1.1-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('raids_nirs_20100823_v1.1-created-from-netcdf-input.cdf') os.remove('raids_nirs_20100823_v1.1.nc')
def test_sep_anc(): fname = 'mvn_sep_l2_anc_20210501_v06_r00.cdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/mvn_sep_l2_anc_20210501_v06_r00.cdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) a = cdflib.cdf_to_xarray("mvn_sep_l2_anc_20210501_v06_r00.cdf", to_unixtime=True, fillval_to_nan=True) cdflib.xarray_to_cdf(a, 'mvn_sep_l2_anc_20210501_v06_r00-created-from-cdf-input.cdf', from_unixtime=True) a = cdflib.cdf_to_xarray('mvn_sep_l2_anc_20210501_v06_r00-created-from-cdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('mvn_sep_l2_anc_20210501_v06_r00-created-from-cdf-input.cdf') os.remove('mvn_sep_l2_anc_20210501_v06_r00.cdf')
def test_euv(): fname = 'mvn_euv_l3_minute_20201130_v14_r02.cdf' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/mvn_euv_l3_minute_20201130_v14_r02.cdf") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) a = cdflib.cdf_to_xarray("mvn_euv_l3_minute_20201130_v14_r02.cdf", to_unixtime=True, fillval_to_nan=True) cdflib.xarray_to_cdf(a, 'mvn_euv_l3_minute_20201130_v14_r02-created-from-cdf-input.cdf', from_unixtime=True) b = cdflib.cdf_to_xarray('mvn_euv_l3_minute_20201130_v14_r02-created-from-cdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('mvn_euv_l3_minute_20201130_v14_r02-created-from-cdf-input.cdf') os.remove('mvn_euv_l3_minute_20201130_v14_r02.cdf')
def test_goes_mag(): fname = 'dn_magn-l2-hires_g17_d20211219_v1-0-1.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/dn_magn-l2-hires_g17_d20211219_v1-0-1.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("dn_magn-l2-hires_g17_d20211219_v1-0-1.nc") for var in c: c[var].attrs['VAR_TYPE'] = 'data' c['coordinate'].attrs['VAR_TYPE'] = 'support_data' c['time'].attrs['VAR_TYPE'] = 'support_data' c['time_orbit'].attrs['VAR_TYPE'] = 'support_data' cdflib.xarray_to_cdf(c, 'dn_magn-l2-hires_g17_d20211219_v1-0-1-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('dn_magn-l2-hires_g17_d20211219_v1-0-1-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('dn_magn-l2-hires_g17_d20211219_v1-0-1-created-from-netcdf-input.cdf') os.remove('dn_magn-l2-hires_g17_d20211219_v1-0-1.nc')
def test_saber(): fname = 'SABER_L2B_2021020_103692_02.07.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/SABER_L2B_2021020_103692_02.07.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("SABER_L2B_2021020_103692_02.07.nc") for var in c: c[var].attrs['VAR_TYPE'] = 'data' c['event'].attrs['VAR_TYPE'] = 'support_data' c['sclatitude'].attrs['VAR_TYPE'] = 'support_data' c['sclongitude'].attrs['VAR_TYPE'] = 'support_data' c['scaltitude'].attrs['VAR_TYPE'] = 'support_data' cdflib.xarray_to_cdf(c, 'SABER_L2B_2021020_103692_02.07-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('SABER_L2B_2021020_103692_02.07-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('SABER_L2B_2021020_103692_02.07-created-from-netcdf-input.cdf') os.remove('SABER_L2B_2021020_103692_02.07.nc')
def test_MGITM_model(): fname = 'MGITM_LS180_F130_150615.nc' url = ( "https://lasp.colorado.edu/maven/sdc/public/data/sdc/web/cdflib_testing/MGITM_LS180_F130_150615.nc") if not os.path.exists(fname): urllib.request.urlretrieve(url, fname) c = xr.load_dataset("MGITM_LS180_F130_150615.nc") for var in c: c[var].attrs['VAR_TYPE'] = 'data' c = c.rename({'Latitude': 'latitude', 'Longitude': 'longitude'}) c['longitude'].attrs['VAR_TYPE'] = 'support_data' c['latitude'].attrs['VAR_TYPE'] = 'support_data' c['altitude'].attrs['VAR_TYPE'] = 'support_data' cdflib.xarray_to_cdf(c, 'MGITM_LS180_F130_150615-created-from-netcdf-input.cdf') d = cdflib.cdf_to_xarray('MGITM_LS180_F130_150615-created-from-netcdf-input.cdf', to_unixtime=True, fillval_to_nan=True) os.remove('MGITM_LS180_F130_150615-created-from-netcdf-input.cdf') os.remove('MGITM_LS180_F130_150615.nc')
def test_build_from_scratch(): pytest.importorskip('xarray') var_data = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] var_dims = ['epoch', 'direction'] data = xr.Variable(var_dims, var_data) epoch_data = [1, 2, 3] epoch_dims = ['epoch'] epoch = xr.Variable(epoch_dims, epoch_data) ds = xr.Dataset(data_vars={'data': data, 'epoch': epoch}) cdflib.xarray_to_cdf(ds, 'hello.cdf') os.remove('hello.cdf') global_attributes = {'Project': 'Hail Mary', 'Source_name': 'Thin Air', 'Discipline': 'None', 'Data_type': 'counts', 'Descriptor': 'Midichlorians in unicorn blood', 'Data_version': '3.14', 'Logical_file_id': 'SEVENTEEN', 'PI_name': 'Darth Vader', 'PI_affiliation': 'Dark Side', 'TEXT': 'AHHHHH', 'Instrument_type': 'Banjo', 'Mission_group': 'Impossible', 'Logical_source': ':)', 'Logical_source_description': ':('} data = xr.Variable(var_dims, var_data) epoch = xr.Variable(epoch_dims, epoch_data) ds = xr.Dataset(data_vars={'data': data, 'epoch': epoch}, attrs=global_attributes) cdflib.xarray_to_cdf(ds, 'hello.cdf') os.remove('hello.cdf') dir_data = [1, 2, 3] dir_dims = ['direction'] direction = xr.Variable(dir_dims, dir_data) ds = xr.Dataset(data_vars={'data': data, 'epoch': epoch, 'direction': direction}, attrs=global_attributes) cdflib.xarray_to_cdf(ds, 'hello.cdf') os.remove('hello.cdf')