예제 #1
0
def test_interface_network_init():
    """
    test limitation of interface to certain networks
    """

    path_header_values = os.path.join(os.path.dirname(__file__), 'test_data',
                                      'multinetwork', 'header_values')
    hv_interface = interface.ISMN_Interface(path_header_values,
                                            network=['SCAN'])
    assert hv_interface.list_networks().size == 1
    assert hv_interface.list_networks()[0] == 'SCAN'
    hv_interface = interface.ISMN_Interface(path_header_values,
                                            network=['SCAN', 'MAQU'])
    assert hv_interface.list_networks().size == 2
예제 #2
0
def test_get_dataset_ids():
    """
    Test returned indeces from filtering
    """
    path_to_ismn_data = os.path.join(
        os.path.dirname(__file__), 'test_data',
        'Data_seperate_files_header_20170810_20180809')
    ISMN_reader = interface.ISMN_Interface(path_to_ismn_data)
    ids1 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1,
                                       landcover_2010=130)
    assert np.array_equal(np.array([0]), ids1)
    ids2 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1,
                                       climate='ET')
    assert np.array_equal(np.array([1]), ids2)
    ids3 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1)
    assert np.array_equal(np.array([0, 1]), ids3)
    ids4 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1,
                                       landcover_insitu='')
    assert np.array_equal(np.array([0, 1]), ids4)

    path_to_ismn_data = os.path.join(os.path.dirname(__file__), 'test_data',
                                     'Data_seperate_files_20170810_20180809')
    ISMN_reader = interface.ISMN_Interface(path_to_ismn_data)
    ids1 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1,
                                       landcover_2010=130)
    assert np.array_equal(np.array([0]), ids1)
    ids2 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1,
                                       climate='ET')
    assert np.array_equal(np.array([1]), ids2)
    ids3 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1)
    assert np.array_equal(np.array([0, 1]), ids3)
    ids4 = ISMN_reader.get_dataset_ids(variable='soil moisture',
                                       min_depth=0,
                                       max_depth=1,
                                       landcover_insitu='')
    assert np.array_equal(np.array([0, 1]), ids4)
def storeCoorDataintoLocal():
    # import and merge ISMN data
    ISMN_reader = ismn.ISMN_Interface(path_to_ismn_data)
    networks = ISMN_reader.list_networks()

    coorData = merge_networks_coordinates(ISMN_reader, networks)
    coorData.to_csv('./data/coorData.csv', index=False)
    return coorData
예제 #4
0
def test_interface_plotting():
    """
    test plotting of networks
    """
    path_header_values = os.path.join(os.path.dirname(__file__), 'test_data',
                                      'multinetwork', 'header_values')
    hv_interface = interface.ISMN_Interface(path_header_values,
                                            network=['SCAN'])
    fig, axes = hv_interface.plot_station_locations()
    return fig
예제 #5
0
def test_list_climate_types():
    """
    Test available climate classifications for dataset
    """
    path_to_ismn_data = os.path.join(
        os.path.dirname(__file__), 'test_data',
        'Data_seperate_files_header_20170810_20180809')
    ISMN_reader = interface.ISMN_Interface(path_to_ismn_data)
    cl = ISMN_reader.get_climate_types()
    assert sorted(list(cl)) == sorted(['Cfa', 'ET'])
    cl = ISMN_reader.get_climate_types(climate='climate_insitu')
    assert list(cl) == []

    path_to_ismn_data = os.path.join(os.path.dirname(__file__), 'test_data',
                                     'Data_seperate_files_20170810_20180809')
    ISMN_reader = interface.ISMN_Interface(path_to_ismn_data)
    cl = ISMN_reader.get_climate_types()
    assert sorted(list(cl)) == sorted(['Cfa', 'ET'])
    cl = ISMN_reader.get_climate_types(climate='climate_insitu')
    assert list(cl) == []
예제 #6
0
def test_list_landcover_types():
    """
    Test available landcover classifications for dataset
    """
    path_to_ismn_data = os.path.join(
        os.path.dirname(__file__), 'test_data',
        'Data_seperate_files_header_20170810_20180809')
    ISMN_reader = interface.ISMN_Interface(path_to_ismn_data)
    lc = ISMN_reader.get_landcover_types()
    assert list(lc) == [130, 210]
    lc = ISMN_reader.get_landcover_types(landcover='landcover_insitu')
    assert lc == ['']

    path_to_ismn_data = os.path.join(os.path.dirname(__file__), 'test_data',
                                     'Data_seperate_files_20170810_20180809')
    ISMN_reader = interface.ISMN_Interface(path_to_ismn_data)
    lc = ISMN_reader.get_landcover_types()
    assert list(lc) == [130, 210]
    lc = ISMN_reader.get_landcover_types(landcover='landcover_insitu')
    assert lc == ['']
예제 #7
0
def test_find_nearest_station():
    """
    Test nearest neighbor search
    """
    path_header_values = os.path.join(os.path.dirname(__file__), 'test_data',
                                      'multinetwork', 'header_values')
    hv_interface = interface.ISMN_Interface(path_header_values,
                                            network=['SCAN'])
    station, distance = hv_interface.find_nearest_station(-90, 35, True)
    assert station.station == "AAMU-jtg"
    assert station.network == "SCAN"
    nptest.assert_almost_equal(distance, 316228.53147802927)
예제 #8
0
def test_min_max_obstime_getting():
    """
    test of the getting minimum and maxiumum observation time
    of a station
    """

    path_header_values = os.path.join(os.path.dirname(__file__), 'test_data',
                                      'format_header_values', 'SMOSMANIA')
    hv_interface = interface.ISMN_Interface(path_header_values)

    station = hv_interface.get_station('Narbonne')
    startd, endd = station.get_min_max_obs_timestamp()
    assert startd == datetime.datetime(2007, 1, 1, 1)
    assert endd == datetime.datetime(2007, 1, 31, 23)

    path_ceop_sep = os.path.join(os.path.dirname(__file__), 'test_data',
                                 'format_ceop_sep', 'SMOSMANIA')
    ceop_sep_interface = interface.ISMN_Interface(path_ceop_sep)

    station = ceop_sep_interface.get_station('Narbonne')
    startd, endd = station.get_min_max_obs_timestamp()
    assert startd == datetime.datetime(2007, 1, 1, 1)
    assert endd == datetime.datetime(2007, 1, 31, 23)
def storeISMNDataintoLocal(date_start, date_end):
    # import and merge ISMN data
    ISMN_reader = ismn.ISMN_Interface(path_to_ismn_data)
    networks = ISMN_reader.list_networks()
    # get the soil moisture and precipitation data
    ismnData = merge_network(ISMN_reader, networks, date_start, date_end)
    print("Available Networks:")
    print(networks)
    print(ismnData.head(3))

    # store ismn Data as csv.file
    ismnData['timeStamp'] = ismnData.index
    ismnData.to_csv('./data/ismnData.csv', index=False)
    return ismnData
예제 #10
0
def test_min_max_obstime_networks():
    """
    test of the getting minimum and maxiumum observation time
    of several networks
    """

    path_header_values = os.path.join(os.path.dirname(__file__), 'test_data',
                                      'multinetwork', 'header_values')
    hv_interface = interface.ISMN_Interface(path_header_values)
    data = hv_interface.get_min_max_obs_timestamps(min_depth=0, max_depth=0.1)
    assert data.loc['MAQU']['end date'][0] == datetime.datetime(
        2010, 7, 31, 23)
    assert data.loc['MAQU']['end date'][1] == datetime.datetime(
        2010, 7, 31, 23)
    assert data.loc['MAQU']['start date'][1] == datetime.datetime(
        2008, 7, 1, 0)
    assert data.loc['SCAN']['start date'][1] == datetime.datetime(
        2007, 1, 1, 0)
    assert data.loc['SOILSCAPE']['start date'][1] == datetime.datetime(
        2012, 12, 14, 19)
예제 #11
0
static_layers_folder = os.path.join(testdata_folder, 'sat/h_saf/static_layer')

# init the ASCAT SSM reader with the paths
ascat_SSM_reader = ascat.AscatSsmCdr(
    ascat_data_folder,
    ascat_grid_folder,
    grid_filename='TUW_WARP5_grid_info_2_1.nc',
    static_layer_path=static_layers_folder)
ascat_SSM_reader.read_bulk = True

# set path to ISMN data
ismn_data_folder = os.path.join(testdata_folder,
                                'ismn/multinetwork/header_values')

# Initialize reader
ISMN_reader = ismn.ISMN_Interface(ismn_data_folder)

i = 0

label_ascat = 'sm'
label_insitu = 'insitu_sm'

# this loops through all stations that measure soil moisture
for station in ISMN_reader.stations_that_measure('soil moisture'):

    # this loops through all time series of this station that measure soil moisture
    # between 0 and 0.1 meters
    for ISMN_time_series in station.data_for_variable('soil moisture',
                                                      min_depth=0,
                                                      max_depth=0.1):
예제 #12
0
import ismn.interface as ismn
import matplotlib.pyplot as plt
import random

# path unzipped file downloaded from the ISMN web portal
# on windows the first string has to be your drive letter
# like 'C:\\'
#path_to_ismn_data = os.path.join('path', 'to', 'ISMN_data',
#                                 'from', 'ISMN website')

path_to_ismn_data = '/pytesmo/testdata/ismn/format_ceop_sep/SMOSMANIA'

# initialize interface, this can take up to a few minutes the first
# time, since all metadata has to be collected
ISMN_reader = ismn.ISMN_Interface(path_to_ismn_data)

# plot available station on a map
fig, axes = ISMN_reader.plot_station_locations()
plt.show()

# select random network and station to plot
networks = ISMN_reader.list_networks()
print("Available Networks:")
print(networks)

network = random.choice(networks)
stations = ISMN_reader.list_stations(network=network)
print("Available Stations in Network %s" % network)
print(stations)