How to use the pytesmo.io.ismn.interface.ISMNError function in pytesmo

To help you get started, we’ve selected a few pytesmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
Returns
        -------
        sensors : numpy.array
            array of sensors found for the given combination of variable and depths

        Raises
        ------
        ISMNError
            if no sensor was found for the given combination of variable and depths
        """
        ind_sensors = np.where((variable == self.variables) &
                               (depth_from == self.depth_from) &
                               (depth_to == self.depth_to))[0]

        if ind_sensors.size == 0:
            raise ISMNError("variable-depth_from-depth_to combination does not exist."
                            "Please check which depths do exist with get_depths_for_variable")
        else:
            return self.sensors[ind_sensors]
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
raise ISMNError("there are multiple sensors for this combination of "
                                "variable, depth_to, depth_from. Please specify which one "
                                "you want to read")
            elif sensors.size == 1:
                sensor = sensors[0]
            elif sensors.size == 0:
                raise ISMNError("there are no sensors for this variable, depth_from, depth_to "
                                "combination. Please make sure you specified valid depths")

        index_filename = np.where((variable == self.variables) &
                                  (depth_from == self.depth_from) &
                                  (depth_to == self.depth_to) &
                                  (sensor == self.sensors))[0]

        if index_filename.size != 1:
            raise ISMNError("There is no data for this combination of variable, depth_from, "
                            "depth_to and sensor. Please check.")
        else:
            return readers.read_data(self.filenames[index_filename[0]])
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
lat, lon = self.metadata['latitude'][stations_idx[us_idx[i]]], self.metadata[
                        'longitude'][stations_idx[us_idx[i]]]
                    x, y = ismn_map(lon, lat)

                    im = ismn_map.scatter(
                        x, y, c=netcolor, s=10, marker='s', edgecolors='none', ax=ax)

            ismn_map.drawcoastlines(linewidth=0.25)
            ismn_map.drawcountries(linewidth=0.25)
            ismn_map.drawstates(linewidth=0.25)
            plt.legend(
                rect, uniq_networks.tolist(), loc='lower center', ncol=uniq_networks.size / 4)

            return fig, ax
        else:
            raise ISMNError('Basemap is not installed.')
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
"""
        if depth_from is None:
            depth_f, depth_t = self.get_depths(variable)
            if depth_f.size > 1:
                raise ISMNError("there are multiple depths for this variable"
                                "Please specify the one you want to read")
            elif depth_f.size == 1:
                depth_from = depth_f[0]
            elif depth_f.size == 0:
                raise ISMNError("there are no depths for this variable"
                                "Something went wrong")
        if depth_to is None:
            depth_f, depth_t = self.get_depths(variable)
            if depth_t.size > 1:
                raise ISMNError("there are multiple depths with the same depth_from value"
                                "Please specify the depth_to value you want to read")
            elif depth_t.size == 1:
                depth_to = depth_t[0]
            elif depth_t.size == 0:
                raise ISMNError("there are no depths for this variable"
                                "Something went wrong")

        if sensor is None:
            sensors = self.get_sensors(variable, depth_from, depth_to)
            if sensors.size > 1:
                raise ISMNError("there are multiple sensors for this combination of "
                                "variable, depth_to, depth_from. Please specify which one "
                                "you want to read")
            elif sensors.size == 1:
                sensor = sensors[0]
            elif sensors.size == 0:
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
ISMN_station : ISMN_station object

        Raises
        ------
        ISMNError
            if stationname was not found
        """

        if network is not None:
            all_index = np.where((self.metadata['station'] == stationname) &
                                 (self.metadata['network'] == network))[0]
        else:
            all_index = np.where(self.metadata['station'] == stationname)[0]

        if all_index.size == 0:
            raise ISMNError("stationname was not found")

        metadatasub = self.metadata[all_index]

        if np.unique(metadatasub['network']).size > 1:
            raise ISMNError("stationname occurs in multiple networks")

        return ISMN_station(self.metadata[all_index])
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
elif depth_t.size == 1:
                depth_to = depth_t[0]
            elif depth_t.size == 0:
                raise ISMNError("there are no depths for this variable"
                                "Something went wrong")

        if sensor is None:
            sensors = self.get_sensors(variable, depth_from, depth_to)
            if sensors.size > 1:
                raise ISMNError("there are multiple sensors for this combination of "
                                "variable, depth_to, depth_from. Please specify which one "
                                "you want to read")
            elif sensors.size == 1:
                sensor = sensors[0]
            elif sensors.size == 0:
                raise ISMNError("there are no sensors for this variable, depth_from, depth_to "
                                "combination. Please make sure you specified valid depths")

        index_filename = np.where((variable == self.variables) &
                                  (depth_from == self.depth_from) &
                                  (depth_to == self.depth_to) &
                                  (sensor == self.sensors))[0]

        if index_filename.size != 1:
            raise ISMNError("There is no data for this combination of variable, depth_from, "
                            "depth_to and sensor. Please check.")
        else:
            return readers.read_data(self.filenames[index_filename[0]])
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
if stationname was not found
        """

        if network is not None:
            all_index = np.where((self.metadata['station'] == stationname) &
                                 (self.metadata['network'] == network))[0]
        else:
            all_index = np.where(self.metadata['station'] == stationname)[0]

        if all_index.size == 0:
            raise ISMNError("stationname was not found")

        metadatasub = self.metadata[all_index]

        if np.unique(metadatasub['network']).size > 1:
            raise ISMNError("stationname occurs in multiple networks")

        return ISMN_station(self.metadata[all_index])
github TUW-GEO / pytesmo / pytesmo / io / ismn / interface.py View on Github external
os.path.join(path_to_data, 'python_metadata', 'metadata.npy'), self.metadata)
            #np.savetxt(os.path.join(path_to_data,'python_metadata','metadata.npy'), self.metadata,delimiter=',')
        else:
            self.metadata = np.load(
                os.path.join(path_to_data, 'python_metadata', 'metadata.npy'))

        if network is not None:
            if type(network) is not list:
                network = [network]
            # initialize binary mask the size of metadata
            mask = np.zeros(self.metadata.shape[0], dtype=np.bool)
            for net in network:
                if net in self.metadata['network']:
                    mask = mask | (self.metadata['network'] == net)
                else:
                    raise ISMNError("Network {} not found".format(net))
            self.metadata = self.metadata[mask]

        # initialize grid object for all stations
        self.grid = grids.BasicGrid(self.metadata['longitude'],
                                    self.metadata['latitude'],
                                    setup_kdTree=False)