<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def extractLargestSubNetwork(cls, network_file, out_subset_network_file, river_id_field, next_down_id_field, river_magnitude_field, safe_mode=True):
 """ Extracts the larges sub network from the watershed based on the magnitude parameter. Parameters network_file: str Path to the stream network shapefile. out_subset_network_file: str Path to the output subset stream network shapefile. river_id_field: str Name of the river ID field in the stream network shapefile. next_down_id_field: str Name of the field with the river ID of the next downstream river segment in the stream network shapefile. river_magnitude_field: str Name of the river magnitude field in the stream network shapefile. safe_mode: bool, optional If True, it will kill the simulation early before over taxing your computer. If you are confident your computer can handle it, set it to False. Here is an example of how to use this: .. code:: python import os from RAPIDpy.gis.taudem import TauDEM output_directory = '/path/to/output/files' network_shp = os.path.join(output_directory, "stream_reach_file.shp") out_shp = os.path.join(output_directory, "stream_reach_file_subset.shp") TauDEM.extractLargestSubNetwork( network_file=network_shp, out_subset_network_file=out_shp, river_id_field="LINKNO", next_down_id_field="DSLINKNO", river_magnitude_field="Magnitude", ) """

        network_shapefile = ogr.Open(network_file)
        network_layer = network_shapefile.GetLayer()
        number_of_features = network_layer.GetFeatureCount()
        riv_magnuitude_list = np.zeros(number_of_features, dtype=np.int32)
        for feature_idx, drainage_line_feature in enumerate(network_layer):
            riv_magnuitude_list[feature_idx] =\
                drainage_line_feature.GetField(river_magnitude_field)

        max_magnitude_feature = \
            network_layer.GetFeature(np.argmax(riv_magnuitude_list))
        cls.extractSubNetwork(network_file,
                              out_subset_network_file,
                              [max_magnitude_feature.GetField(river_id_field)],
                              river_id_field,
                              next_down_id_field,
                              river_magnitude_field,
                              safe_mode)