示例#1
0
def test_search_inlet_no_instrument(crds_read):
    locations = "hfd"
    inlet = "100m"
    species = "CH4"

    results = search(locations=locations, species=species, inlet=inlet)

    expected_keys = ["ch4_hfd_100m_picarro"]

    assert list(results.keys()) == expected_keys

    assert len(results["ch4_hfd_100m_picarro"]["keys"]
               ["2013-11-20-20:02:30_2019-07-04-21:29:30"]) == 25

    expected_metadata = {
        'site': 'hfd',
        'instrument': 'picarro',
        'time_resolution': '1_minute',
        'inlet': '100m',
        'port': '10',
        'type': 'air',
        'species': 'ch4',
        'data_type': 'timeseries',
        'scale': 'wmo-x2004a'
    }

    assert results["ch4_hfd_100m_picarro"]["metadata"] == expected_metadata
示例#2
0
def test_search_nonsense_terms():
    species = ["spam", "eggs", "terry"]
    locations = ["capegrim"]

    results = search(species=species, locations=locations)

    assert not results
示例#3
0
def test_search_find_all():
    species = ["co2"]
    locations = ["bsd"]
    inlet = "108m"
    instrument = "picarro"

    start = get_datetime(year=2016, month=1, day=1)
    end = get_datetime(year=2017, month=1, day=1)

    results = search(species=species,
                     locations=locations,
                     find_all=True,
                     start_datetime=start,
                     end_datetime=end,
                     inlet=inlet,
                     instrument=instrument)

    bsd_results = results["co2_bsd_108m_picarro"]

    assert bsd_results["metadata"]["site"] == "bsd"
    assert bsd_results["metadata"]["species"] == "co2"
    assert bsd_results["metadata"]["time_resolution"] == "1_minute"

    key_dates = [daterange.split("/")[-1] for daterange in bsd_results["keys"]]

    assert key_dates == ['2016-01-19-17:17:30_2016-11-30-22:57:30']
示例#4
0
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"])
示例#5
0
def test_search_incorrect_inlet_site_finds_nothing(crds_read):
    locations = "hfd"
    inlet = "3695m"
    species = "CH4"

    results = search(locations=locations, species=species, inlet=inlet)

    assert not results
示例#6
0
def test_search_no_species(crds_read):
    locations = "bsd"

    results = search(locations=locations)

    expected_keys = sorted([
        'ch4_bsd_248m_picarro', 'co2_bsd_248m_picarro', 'co_bsd_248m_picarro',
        'co_bsd_108m_picarro5310', 'n2o_bsd_108m_picarro5310',
        'ch4_bsd_108m_picarro', 'co2_bsd_108m_picarro', 'co_bsd_108m_picarro',
        'co_bsd_248m_picarro5310', 'n2o_bsd_248m_picarro5310'
    ])

    assert sorted(list(results.keys())) == expected_keys
示例#7
0
def test_search_gc(gc_read):
    results = search(species=["NF3"], locations="capegrim")

    nf3_results = results["nf3_cgo_75m_4_medusa"]

    metadata = {
        "site": "cgo",
        "instrument": "medusa",
        "species": "nf3",
        "units": "ppt",
        "scale": "sio-12",
        "inlet": "75m_4",
        "data_type": "timeseries",
    }

    assert "2018-01-01-02:24:00_2018-01-31-23:33:00" in nf3_results["keys"]
    assert nf3_results["metadata"] == metadata
示例#8
0
def test_search_instrument_no_inlet(crds_read):
    locations = "bsd"
    species = "n2o"
    instrument = "picarro5310"

    results = search(locations=locations,
                     species=species,
                     instrument=instrument)

    expected_keys = ["n2o_bsd_108m_picarro5310", "n2o_bsd_248m_picarro5310"]

    assert sorted(list(results.keys())) == sorted(expected_keys)

    assert len(results["n2o_bsd_108m_picarro5310"]["keys"]
               ["2019-03-06-14:03:30_2020-07-04-11:44:30"]) == 7
    assert len(results["n2o_bsd_248m_picarro5310"]["keys"]
               ["2019-03-06-13:23:30_2020-07-05-03:38:30"]) == 7

    metadata_108m = {
        'site': 'bsd',
        'instrument': 'picarro5310',
        'time_resolution': '1_minute',
        'inlet': '108m',
        'port': '2',
        'type': 'air',
        'species': 'n2o',
        'data_type': 'timeseries',
        'scale': 'wmo-x2006a'
    }

    metadata_248m = {
        'site': 'bsd',
        'instrument': 'picarro5310',
        'time_resolution': '1_minute',
        'inlet': '248m',
        'port': '1',
        'type': 'air',
        'species': 'n2o',
        'data_type': 'timeseries',
        'scale': 'wmo-x2006a'
    }

    assert results["n2o_bsd_108m_picarro5310"]["metadata"] == metadata_108m
    assert results["n2o_bsd_248m_picarro5310"]["metadata"] == metadata_248m
示例#9
0
def test_recombination_GC():
    get_local_bucket(empty=True)

    gc = GCWERKS()

    data = get_datapath(filename="capegrim-medusa.18.C", data_type="GC")
    precision = get_datapath(filename="capegrim-medusa.18.precisions.C",
                             data_type="GC")

    ObsSurface.read_file((data, precision), data_type="GCWERKS")

    data = gc.read_data(data_filepath=data,
                        precision_filepath=precision,
                        site="CGO",
                        instrument="medusa")

    toluene_data = data["toluene"]["data"]

    gas_name = "toluene"
    location = "CGO"

    keys = search(species=gas_name, locations=location)

    to_download = keys["toluene_cgo_75m_4_medusa"]["keys"][
        "2018-01-01-02:24:00_2018-01-31-23:33:00"]

    toluene_data_recombined = recombine_sections(data_keys=to_download)

    toluene_data.attrs = {}
    toluene_data_recombined.attrs = {}

    assert toluene_data.time.equals(toluene_data_recombined.time)
    assert toluene_data["toluene"].equals(toluene_data_recombined["c6h5ch3"])
    assert toluene_data["toluene repeatability"].equals(
        toluene_data_recombined["c6h5ch3_repeatability"])
    assert toluene_data["toluene status_flag"].equals(
        toluene_data_recombined["c6h5ch3_status_flag"])
    assert toluene_data["toluene integration_flag"].equals(
        toluene_data_recombined["c6h5ch3_integration_flag"])
示例#10
0
def test_location_search(crds_read):
    species = ["co2", "ch4"]
    locations = ["bsd", "hfd", "tac"]

    start = None  # get_datetime(year=2016, month=1, day=1)
    end = None  # get_datetime(year=2017, month=1, day=1)

    results = search(
        species=species,
        locations=locations,
        find_all=False,
        start_datetime=start,
        end_datetime=end,
    )

    results_list = sorted(list(results.keys()))

    expected = sorted([
        'ch4_bsd_108m_picarro', 'ch4_bsd_248m_picarro', 'ch4_hfd_100m_picarro',
        'ch4_tac_100m_picarro', 'co2_bsd_108m_picarro', 'co2_bsd_248m_picarro',
        'co2_hfd_100m_picarro', 'co2_tac_100m_picarro'
    ])

    assert results_list == expected

    assert len(results["co2_bsd_108m_picarro"]["keys"]
               ['2014-01-30-13:33:30_2019-07-04-04:23:30']) == 23
    assert len(results["co2_hfd_100m_picarro"]["keys"]
               ['2013-11-20-20:02:30_2019-07-04-21:29:30']) == 25
    assert len(results["co2_tac_100m_picarro"]["keys"]
               ['2012-07-26-12:01:30_2019-07-04-09:58:30']) == 30
    assert len(results["ch4_bsd_108m_picarro"]["keys"]
               ['2014-01-30-13:33:30_2019-07-04-04:23:30']) == 23
    assert len(results["ch4_hfd_100m_picarro"]["keys"]
               ['2013-11-20-20:02:30_2019-07-04-21:29:30']) == 25
    assert len(results["ch4_tac_100m_picarro"]["keys"]
               ['2012-07-26-12:01:30_2019-07-04-09:58:30']) == 30
示例#11
0
def test_search_datetimes():
    species = ["co2"]
    locations = ["bsd"]

    start = get_datetime(year=2016, month=1, day=1)
    end = get_datetime(year=2017, month=1, day=1)

    results = search(
        species=species,
        locations=locations,
        find_all=False,
        start_datetime=start,
        end_datetime=end,
    )

    result_keys = results["co2_bsd_108m_picarro"]["keys"]

    date_strings = [v.split("/")[-1] for v in result_keys]

    assert date_strings == ['2016-01-19-17:17:30_2016-11-30-22:57:30']

    metadata = results["co2_bsd_108m_picarro"]["metadata"]

    expected_metadata = {
        "site": "bsd",
        "instrument": "picarro",
        "time_resolution": "1_minute",
        "inlet": "108m",
        "port": "9",
        "type": "air",
        "species": "co2",
        "data_type": "timeseries",
        'scale': 'wmo-x2007'
    }

    assert metadata == expected_metadata
示例#12
0
def test_search_bad_site_raises():
    species = ["spam", "eggs", "terry"]
    locations = ["tintagel"]

    with pytest.raises(ValueError):
        search(species=species, locations=locations)