You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running into an issue that may well be user error. When I call the animate_foodweb() function, I receive an error traceback going to the pandas module.
The data file that I am using is based off of the provided 'Richards_Bay_C_Summer.csv' file. The only changes I've made were to delete the flow data for all but the first six species, making it a much smaller data set. I have not altered the IsAlive, Biomass, Export, respiration, or trophic level columns. Animate_foodweb() seems to be the only method in the library that throws an error for this dataset.
Once again, this may be a user error, but if the team would be able to explain what the alterations to the file are causing the animation function not to work, I would be very appreciative.
Below I have copied the error traceback, and below that I have copied the csv file that is throwing the error.
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in _get_node_attributes(self, net)
124
125 # select horizontal node positions with minimal number of intersections between flows
--> 126 pos_df = self._find_minimal_intersections(net, pos_df)
127
128 # move the nodes at random a bit
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in _aggregate_in_trophic_level_layers(self, pos_df)
83 pos_df['x_rank'] = assign_rank(pos_df)
84 # get the width of trophic layer for each node
---> 85 pos_df['odd_or_even_layer'] = pos_df.apply(lambda x: grouped.loc[x.TrophicLevel_bin, 'odd_or_even'],
86 axis='columns')
87
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py in apply_series_generator(self)
298 for i, v in enumerate(series_gen):
299 # ignore SettingWithCopy here in case the user mutates
--> 300 results[i] = self.f(v)
301 if isinstance(results[i], ABCSeries):
302 # If we have a view on v, we need to make a copy because
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in (x)
83 pos_df['x_rank'] = assign_rank(pos_df)
84 # get the width of trophic layer for each node
---> 85 pos_df['odd_or_even_layer'] = pos_df.apply(lambda x: grouped.loc[x.TrophicLevel_bin, 'odd_or_even'],
86 axis='columns')
87
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in getitem(self, key)
871 # AttributeError for IntervalTree get_value
872 pass
--> 873 return self._getitem_tuple(key)
874 else:
875 # we by definition only have the 0th axis
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
784 # We don't need to check for tuples here because those are
785 # caught by the _is_nested_tuple_indexer check above.
--> 786 section = self._getitem_axis(key, axis=i)
787
788 # We should never have a scalar section here, because
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1108 # fall thru to straight lookup
1109 self._validate_key(key, axis)
-> 1110 return self._get_label(key, axis=axis)
1111
1112 def _get_slice_axis(self, slice_obj: slice, axis: int):
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
1057 def _get_label(self, label, axis: int):
1058 # GH#5667 this will fail if the label is not present in the axis.
-> 1059 return self.obj.xs(label, axis=axis)
1060
1061 def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
3489 loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
3490 else:
-> 3491 loc = self.index.get_loc(key)
3492
3493 if isinstance(loc, np.ndarray):
Thank you @rrh3az for running this test! The input was correct and all the other visualisation methods worked, except the animation. Indeed, the computation of the starting positions of nodes for the layout algorithm did not work for food webs smaller than ~10 nodes. Now it should work for any number and it works for your example.
To get a good-looking animation, the user has to play around with the parameters - the default ones are chosen to provide sth within a minimal computation time.
I am running into an issue that may well be user error. When I call the animate_foodweb() function, I receive an error traceback going to the pandas module.
The data file that I am using is based off of the provided 'Richards_Bay_C_Summer.csv' file. The only changes I've made were to delete the flow data for all but the first six species, making it a much smaller data set. I have not altered the IsAlive, Biomass, Export, respiration, or trophic level columns. Animate_foodweb() seems to be the only method in the library that throws an error for this dataset.
Once again, this may be a user error, but if the team would be able to explain what the alterations to the file are causing the animation function not to work, I would be very appreciative.
Below I have copied the error traceback, and below that I have copied the csv file that is throwing the error.
Best
Error Traceback:
KeyError Traceback (most recent call last)
/var/folders/1c/26krkzms5lvgswmm3wzb0x1r0000gn/T/ipykernel_15748/2358074709.py in
----> 1 fw.animate_foodweb(foodweb,'Example_animation_test.gif')
~/Codingtons/foodwebviz-master/foodwebviz/create_animated_food_web.py in animate_foodweb(foodweb, gif_file_out, fps, anim_len, trails, min_node_radius, min_part_num, max_part_num, map_fun, include_imports, include_exports, cmap, max_luminance, particle_size)
120 # create a static graph representation of the food web
121 # and map flows and biomass to particle numbers and node sizes
--> 122 network_image = NetworkImage(foodweb, False, k_=80,
123 min_part_num=min_part_num,
124 map_fun=map_fun,
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in init(self, net, with_detritus, k_, min_part_num, map_fun, max_part)
39 '''
40 self.title = net.title
---> 41 self.nodes = self._get_node_attributes(net)
42 self.particle_numbers = self._get_particle_numbers(
43 net=net,
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in _get_node_attributes(self, net)
124
125 # select horizontal node positions with minimal number of intersections between flows
--> 126 pos_df = self._find_minimal_intersections(net, pos_df)
127
128 # move the nodes at random a bit
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in _find_minimal_intersections(self, net, pos_df)
144 best_pos = None
145 for _ in range(20):
--> 146 grouped = self._aggregate_in_trophic_level_layers(pos_df)
147 pos_df['x'] = pos_df.apply(lambda x: randomly_choose_x(x, grouped=grouped), axis='columns')
148 intersections = self._get_num_of_crossed_edges(net, pos_df)
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in _aggregate_in_trophic_level_layers(self, pos_df)
83 pos_df['x_rank'] = assign_rank(pos_df)
84 # get the width of trophic layer for each node
---> 85 pos_df['odd_or_even_layer'] = pos_df.apply(lambda x: grouped.loc[x.TrophicLevel_bin, 'odd_or_even'],
86 axis='columns')
87
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds)
7546 kwds=kwds,
7547 )
-> 7548 return op.get_result()
7549
7550 def applymap(self, func) -> "DataFrame":
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py in get_result(self)
178 return self.apply_raw()
179
--> 180 return self.apply_standard()
181
182 def apply_empty_result(self):
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py in apply_standard(self)
269
270 def apply_standard(self):
--> 271 results, res_index = self.apply_series_generator()
272
273 # wrap results
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/apply.py in apply_series_generator(self)
298 for i, v in enumerate(series_gen):
299 # ignore SettingWithCopy here in case the user mutates
--> 300 results[i] = self.f(v)
301 if isinstance(results[i], ABCSeries):
302 # If we have a view on v, we need to make a copy because
~/Codingtons/foodwebviz-master/foodwebviz/animation/network_image.py in (x)
83 pos_df['x_rank'] = assign_rank(pos_df)
84 # get the width of trophic layer for each node
---> 85 pos_df['odd_or_even_layer'] = pos_df.apply(lambda x: grouped.loc[x.TrophicLevel_bin, 'odd_or_even'],
86 axis='columns')
87
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in getitem(self, key)
871 # AttributeError for IntervalTree get_value
872 pass
--> 873 return self._getitem_tuple(key)
874 else:
875 # we by definition only have the 0th axis
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _getitem_tuple(self, tup)
1042 def _getitem_tuple(self, tup: Tuple):
1043 try:
-> 1044 return self._getitem_lowerdim(tup)
1045 except IndexingError:
1046 pass
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
784 # We don't need to check for tuples here because those are
785 # caught by the _is_nested_tuple_indexer check above.
--> 786 section = self._getitem_axis(key, axis=i)
787
788 # We should never have a scalar section here, because
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1108 # fall thru to straight lookup
1109 self._validate_key(key, axis)
-> 1110 return self._get_label(key, axis=axis)
1111
1112 def _get_slice_axis(self, slice_obj: slice, axis: int):
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
1057 def _get_label(self, label, axis: int):
1058 # GH#5667 this will fail if the label is not present in the axis.
-> 1059 return self.obj.xs(label, axis=axis)
1060
1061 def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
3489 loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
3490 else:
-> 3491 loc = self.index.get_loc(key)
3492
3493 if isinstance(loc, np.ndarray):
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2891 "backfill or nearest lookups"
2892 )
-> 2893 casted_key = self._maybe_cast_indexer(key)
2894 try:
2895 return self._engine.get_loc(casted_key)
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/category.py in _maybe_cast_indexer(self, key)
435
436 def _maybe_cast_indexer(self, key):
--> 437 code = self.categories.get_loc(key)
438 code = self.codes.dtype.type(code)
439 return code
~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/numeric.py in get_loc(self, key, method, tolerance)
417 nan_idxs = self._nan_idxs
418 if not len(nan_idxs):
--> 419 raise KeyError(key)
420 elif len(nan_idxs) == 1:
421 return nan_idxs[0]
KeyError: nan
CSV file:
Names;Diatoms;Flagellates;Bacteria;HM plankton;Small copepods;Medium copepods;IsAlive;Biomass;Export;Respiration;TrophicLevel
Diatoms;0;0;1.677;0.264;2.89;1.8;1;0.5011;0;74.649;2
Flagellates;0;0;1.677;0.264;2.06;1.23;1;0.3424;0;53.438;2
Bacteria;0;0;0;0;0.186;0.791;1;0.52;0;27.56;2.029998927
HM plankton;0;0;0;0;0.0012;0.0048;1;0.0818;0;5.892;2.02998637
Small copepods;0;0;0;0;0.124;0.878;1;0.0375;0;3.45;2.868366383
Medium copepods;0;0;0;0;0;0.0799;1;0.0484;0;4.4528;2.705616911
Import;0;0;0;0;0;0;0;0;0;0;
The text was updated successfully, but these errors were encountered: