def test_recombination_CRDS(): get_local_bucket(empty=True) filename = "hfd.picarro.1minute.100m.min.dat" filepath = get_datapath(filename=filename, data_type="CRDS") crds = CRDS() ObsSurface.read_file(filepath, data_type="CRDS") gas_data = crds.read_data(data_filepath=filepath, site="HFD") ch4_data_read = gas_data["ch4"]["data"] gas_name = "ch4" location = "hfd" keys = search(species=gas_name, locations=location) to_download = keys["ch4_hfd_100m_picarro"]["keys"][ "2013-12-04-14:02:30_2019-05-21-15:46:30"] ch4_data_recombined = recombine_sections(data_keys=to_download) ch4_data_recombined.attrs = {} assert ch4_data_read.time.equals(ch4_data_recombined.time) assert ch4_data_read["ch4"].equals(ch4_data_recombined["ch4"])
def test_read_data(): crds = CRDS() tac_filepath = get_datapath(filename="tac.picarro.1minute.100m.test.dat", data_type="CRDS") combined = crds.read_data(data_filepath=tac_filepath, site="tac") assert len(combined) == 2 assert list(combined.keys()) == ["ch4", "co2"] ch4_metadata = combined["ch4"]["metadata"] assert ch4_metadata["site"] == "tac" assert ch4_metadata["instrument"] == "picarro" assert ch4_metadata["time_resolution"] == "1_minute" assert ch4_metadata["inlet"] == "100m" assert ch4_metadata["port"] == "9" assert ch4_metadata["type"] == "air" assert ch4_metadata["species"] == "ch4" ch4_data = combined["ch4"]["data"] assert ch4_data.time[0] == pd.Timestamp("2012-07-31 14:50:30") assert ch4_data["ch4"][0] == pytest.approx(1905.28) assert ch4_data["ch4 stdev"][0] == pytest.approx(0.268) assert ch4_data["ch4 n_meas"][0] == pytest.approx(20)
def data(): crds = CRDS() filename = "bsd.picarro.1minute.248m.dat" filepath = get_datapath(filename=filename, data_type="CRDS") combined_data = crds.read_data(data_filepath=filepath, site="bsd") return combined_data
def test_gas_info(hfd_filepath): crds = CRDS() data = pd.read_csv( hfd_filepath, header=None, skiprows=1, sep=r"\s+", index_col=["0_1"], parse_dates=[[0, 1]], ) n_gases, n_cols = crds.gas_info(data=data) assert n_gases == 3 assert n_cols == 3
def test_get_site_attributes(): crds = CRDS() attrs = crds.get_site_attributes(site="bsd", inlet="108m") assert attrs == { 'data_owner': "Simon O'Doherty", 'data_owner_email': '*****@*****.**', 'inlet_height_magl': '108m', 'comment': 'Cavity ring-down measurements. Output from GCWerks' } attrs = crds.get_site_attributes(site="tac", inlet="50m") assert attrs == { 'data_owner': "Simon O'Doherty", 'data_owner_email': '*****@*****.**', 'inlet_height_magl': '50m', 'comment': 'Cavity ring-down measurements. Output from GCWerks' }
def clear_datasources(args): from HUGS.Modules import CRDS, GC gc = GC.load() crds = CRDS.load() crds.clear_datasources() gc.clear_datasources() crds.save() gc.save()
def test_read_file(): hfd_filepath = get_datapath(filename="hfd.picarro.1minute.100m.min.dat", data_type="CRDS") crds = CRDS() gas_data = crds.read_file(data_filepath=hfd_filepath) ch4_data = gas_data["ch4"]["data"] co2_data = gas_data["co2"]["data"] co_data = gas_data["co"]["data"] assert ch4_data["ch4"][0].values == pytest.approx(1993.83) assert ch4_data["ch4_stdev"][0].values == pytest.approx(1.555) assert ch4_data["ch4_n_meas"][0].values == pytest.approx(19.0) assert co2_data["co2"][0] == pytest.approx(414.21) assert co2_data["co2_stdev"][0] == pytest.approx(0.109) assert co2_data["co2_n_meas"][0] == pytest.approx(19.0) assert co_data["co"][0] == pytest.approx(214.28) assert co_data["co_stdev"][0] == pytest.approx(4.081) assert co_data["co_n_meas"][0] == pytest.approx(19.0)
def test_read_data_no_inlet_raises(): crds = CRDS() filepath = Path("tac.picarro.1minute.no_inlet.dat") with pytest.raises(ValueError): crds.read_data(data_filepath=filepath, site="tac")
def test_get_site_attributes_unknown_site_raises(): crds = CRDS() with pytest.raises(ValueError): _ = crds.get_site_attributes(site="jupiter", inlet="10008m")
def test_crds_attributes(): _ = get_local_bucket(empty=True) crds = CRDS() filepath = get_datapath(filename="tac.picarro.1minute.100m.test.dat", data_type="CRDS") combined = crds.read_data(data_filepath=filepath, site="tac") combined_attributes = assign_attributes(data=combined, site="tac") # for key in combined_attributes: # ds = combined_attributes[key]["data"] # ds.to_netcdf(f"/tmp/testfile_{key}.nc") ch4_data = combined_attributes["ch4"]["data"] co2_data = combined_attributes["co2"]["data"] ch4_attr = ch4_data.attrs co2_attr = co2_data.attrs ch4_attr_complete = ch4_attr.copy() co2_attr_complete = co2_attr.copy() del ch4_attr["File created"] del co2_attr["File created"] del ch4_attr["species"] del co2_attr["species"] del ch4_attr["Calibration_scale"] del co2_attr["Calibration_scale"] del ch4_attr["data_owner_email"] del co2_attr["data_owner_email"] del ch4_attr["data_owner"] del co2_attr["data_owner"] global_attributes = { "inlet_height_magl": "100m", "comment": "Cavity ring-down measurements. Output from GCWerks", "Conditions of use": "Ensure that you contact the data owner at the outset of your project.", "Source": "In situ measurements of air", "Conventions": "CF-1.6", "Processed by": "*****@*****.**", "station_longitude": 1.13872, "station_latitude": 52.51775, "station_long_name": "Tacolneston Tower, UK", "station_height_masl": 50.0, } assert ch4_attr == global_attributes assert co2_attr == global_attributes assert ch4_attr_complete["species"] == "ch4" assert co2_attr_complete["species"] == "co2" # Check the individual variables attributes time_attributes = { "label": "left", "standard_name": "time", "comment": "Time stamp corresponds to beginning of sampling period. Time since midnight UTC of reference date. Note that sampling periods are approximate.", } assert ch4_data.time.attrs == time_attributes assert co2_data.time.attrs == time_attributes # Check individual variables assert ch4_data["ch4"].attrs == { "long_name": "mole_fraction_of_methane_in_air", "units": "1e-9", } assert ch4_data["ch4_stdev"].attrs == { "long_name": "mole_fraction_of_methane_in_air_stdev", "units": "1e-9", } assert ch4_data["ch4_n_meas"].attrs == { "long_name": "mole_fraction_of_methane_in_air_n_meas" } assert co2_data["co2"].attrs == { "long_name": "mole_fraction_of_carbon_dioxide_in_air", "units": "1e-6", } assert co2_data["co2_stdev"].attrs == { "long_name": "mole_fraction_of_carbon_dioxide_in_air_stdev", "units": "1e-6", } assert co2_data["co2_n_meas"].attrs == { "long_name": "mole_fraction_of_carbon_dioxide_in_air_n_meas" }