def get_station_first_sm_layer(path, stationname): """ Get the metadata of the first soil moisture layer of this variable. Parameters ---------- path: string Folder in which the ISMN data is stored stationname: string Name of the station Returns ------- depth_from: float depth_to: float sensor: string """ iface = ISMN_Interface(path) station = iface.get_station(stationname) depths_from, depths_to = station.get_depths("soil moisture") s_idx = np.argsort(depths_from) depth_from = depths_from[s_idx[0]] depth_to = depths_to[s_idx[0]] sensor = station.get_sensors("soil moisture", depth_from, depth_to) return depth_from, depth_to, sensor[0]
def get_station_data(path, stationname, variable, depth_from, depth_to, sensor_id): """ Read the data from the ISMN dataset Parameters ---------- path: string Folder in which the ISMN data is stored stationname: string Name of the station variable: string Name of the variable to read depth_from: string starting depth of the variable depth_to: string end depth of the variable sensor_id: string Sensor id of the sensor to read Returns ------- ds: pandas.DataFrame Data """ iface = ISMN_Interface(path) station = iface.get_station(stationname) ds = station.read_variable(variable.encode('ascii'), float(depth_from), float(depth_to), sensor_id.encode('ascii')) return ds.data[variable]
def get_station_start_end(path, stationname, variable, depth_from, depth_to): """ Get the start and end date for the selected insitu time series. Parameters ---------- path: string Folder in which the ISMN data is stored stationname: string Name of the station variable: string Name of the variable to read depth_from: string starting depth of the variable depth_to: string end depth of the variable Returns ------- start: datetime end: datetime """ iface = ISMN_Interface(path) station = iface.get_station(stationname) return station.get_min_max_obs_timestamp(variable=variable, min_depth=depth_from, max_depth=depth_to)
def read_ISMN(plot=False): ismn_data_folder = os.path.join( '.', 'data', 'Data_seperate_files_2011' + '1122_20121122_2364256_oqsd') ISMN_reader = ISMN_Interface(ismn_data_folder) network = 'IIT-KANPUR' station = 'IITK-Airstrip' station_obj = ISMN_reader.get_station(station) print "Available Variables at Station %s" % station #get the variables that this station measures variables = station_obj.get_variables() print variables depths_from, depths_to = station_obj.get_depths(variables[0]) sensors = station_obj.get_sensors(variables[0], depths_from[0], depths_to[0]) #read the data of the variable, depth, sensor combination time_series = station_obj.read_variable(variables[0], depth_from=depths_from[0], depth_to=depths_to[0], sensor=sensors[0]) #print information about the selected time series print "Selected time series is:" print time_series #plot the data time_series.plot() #with pandas 0.12 time_series.plot() also works plt.legend() plt.show()
def read_ISMN(plot=False): ismn_data_folder = os.path.join('.', 'data', 'Data_seperate_files_2011'+ '1122_20121122_2364256_oqsd') ISMN_reader = ISMN_Interface(ismn_data_folder) network = 'IIT-KANPUR' station = 'IITK-Airstrip' station_obj = ISMN_reader.get_station(station) print "Available Variables at Station %s"%station #get the variables that this station measures variables = station_obj.get_variables() print variables depths_from,depths_to = station_obj.get_depths(variables[0]) sensors = station_obj.get_sensors(variables[0],depths_from[0],depths_to[0]) #read the data of the variable, depth, sensor combination time_series = station_obj.read_variable(variables[0],depth_from=depths_from[0],depth_to=depths_to[0],sensor=sensors[0]) #print information about the selected time series print "Selected time series is:" print time_series #plot the data time_series.plot() #with pandas 0.12 time_series.plot() also works plt.legend() plt.show()
def get_station_lonlat(path, stationname): """ Get the latitude and longitude coordinates from a station. Parameters ---------- path: string Folder in which the ISMN data is stored stationname: string Name of the station Returns ------- lon: float lat: float """ iface = ISMN_Interface(path) station = iface.get_station(stationname) return station.longitude, station.latitude
def prepare_station_interface(path, stationname, variable, depth_from, depth_to, sensor_id): """ Prepare an interface to the requested station data that provides the data via a read_ts(id) function. This is at the moment necessary since the ISMN interface does not follow the standards of other interfaces. Parameters ---------- path: string Folder in which the ISMN data is stored stationname: string Name of the station variable: string Name of the variable to read depth_from: string starting depth of the variable depth_to: string end depth of the variable sensor_id: string Sensor id of the sensor to read Returns ------- iface: object interface object which has a read_ts method """ iface = ISMN_Interface(path) station = iface.get_station(stationname) def read_ts(idx): ds = station.read_variable(variable.encode('ascii'), float(depth_from), float(depth_to), sensor_id.encode('ascii')) return ds.data station.read_ts = read_ts return station
def variable_list(path, stationname): """ Goes through a downloaded ISMN dataset and reads the necessary metadata needed for the viewer. Parameters ---------- path: string Folder in which the ISMN data is stored stationname: string Name of the station Returns ------- metadata: dict Metadata dictionary. """ variables = [] iface = ISMN_Interface(path) station = iface.get_station(stationname) for i, var in enumerate(station.variables): name = "{}_{:.2f}_{}".format(var, station.depth_from[i], station.sensors[i]) var_dict = {"quantityName": var, "unit": "", "depthFrom": station.depth_from[i], "depthTo": station.depth_to[i], "sensorId": station.sensors[i], "variableName": name } variables.append(var_dict) dmin, dmax = station.get_min_max_obs_timestamp() vl = {"maxtime": dmax.date().isoformat(), "mintime": dmin.date().isoformat(), "originalTimeframeValid": False, "variables": variables} return vl
def ismn_metadata(path): """ Goes through a downloaded ISMN dataset and reads the necessary metadata needed for the viewer. Parameters ---------- path: string Folder in which the ISMN data is stored Returns ------- metadata: dict Metadata dictionary. """ metadata = {"Networks": []} iface = ISMN_Interface(path) for networkname in iface.list_networks(): network_dict = { "networkID": networkname, "network_abstract": "", "network_status": "", "network_country": "", "network_continent": "", "network_op_start": "", "network_op_end": "", "network_type": "project", "network_constraints": "", "network_reference": "", "network_url_data": "", "network_url": "", "network_acknowledge": "", "network_variables": "", "network_depths": "", "network_sensors": "", "Stations": []} metadata['Networks'].append(network_dict) station_list = network_dict['Stations'] stations = iface.list_stations(network=networkname) for stationname in stations: station = iface.get_station(stationname, network=networkname) dmin, dmax = station.get_min_max_obs_timestamp() if dmin is None or dmax is None: # No soil moisture measured at this station continue station_dict = { "station_abbr": stationname, "lat": station.latitude, "lng": station.longitude, "comment": None, "stationID": stationname, "extMetadata": None, "station_name": stationname, "variableText": '<br>'.join(np.unique(station.variables)), "depthText": get_depth_text(station.depth_from, station.depth_to, station.variables), "sensorText": '<br>'.join(np.unique(station.sensors)), "maximum": dmax.isoformat(), "minimum": dmin.isoformat() } station_list.append(station_dict) return metadata