openclimatefix / metoffice_ec2

Subset Met Office MOGREPS-UK and UKV on AWS EC2
MIT License
11 stars 2 forks source link

float() argument must be a string or a number, not 'list' #42

Closed flowirtz closed 4 years ago

flowirtz commented 4 years ago
TypeError: float() argument must be a string or a number, not 'list'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "scripts/ec2.py", line 132, in loop
    load_subset_and_save_data(mo_message, height_meters, s3)
  File "scripts/ec2.py", line 82, in load_subset_and_save_data
    dataset = subset.subset(dataset, height_meters, **DEFAULT_GEO_BOUNDARY)
  File "/usr/src/app/metoffice_ec2/subset.py", line 20, in subset
    dataset = dataset.sel(height=height_meters)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/xarray/core/dataset.py", line 2065, in sel
    pos_indexers, new_indexes = remap_label_indexers(
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/xarray/core/coordinates.py", line 396, in remap_label_indexers
    pos_indexers, new_indexes = indexing.remap_label_indexers(
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/xarray/core/indexing.py", line 269, in remap_label_indexers
    label = maybe_cast_to_coords_dtype(label, coords_dtype)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/xarray/core/utils.py", line 82, in maybe_cast_to_coords_dtype
    label = np.asarray(label, dtype=coords_dtype)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/pandas/core/series.py", line 754, in __array__
    return np.asarray(self.array, dtype)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/pandas/core/arrays/numpy_.py", line 184, in __array__
    return np.asarray(self._ndarray, dtype=dtype)
  File "/opt/conda/envs/metoffice_ec2/lib/python3.8/site-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
flowirtz commented 4 years ago

Judging by the stacktrace, it seems something is wrong with the var height_meters that gets passed to load_subset_and_save_data:

https://github.com/openclimatefix/metoffice_ec2/blob/fb376f4bd8e11d4e65f8516d205e3933f40c1fd3/scripts/ec2.py#L129-L132

Instead of being a single value, height_meters seems to be an array. var_name in the logs I saw was wind_from_direction, so we are calling .loc with a single string. According to the Pandas docs:

Note this returns the row as a Series

I'd assume that's why this is blowing up. But I have no idea.

flowirtz commented 4 years ago

@JackKelly could you look into this? I tried, but I really don't understand the code πŸ™ˆ

JackKelly commented 4 years ago

I'll try to make time to look at this next week

On Wed, 17 Jun 2020, 12:56 Flo, notifications@github.com wrote:

@JackKelly https://github.com/JackKelly could you look into this? I tried, but I really don't understand the code πŸ™ˆ

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openclimatefix/metoffice_ec2/issues/42#issuecomment-645329138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQPVBYZVJT6N56REGLXUTRXCVNPANCNFSM4OAQQJZA .

JackKelly commented 4 years ago

OK, I couldn't keep away from the code!

oops, sorry, dumb mistake! The latest commit should fix this.

The short term solution to prevent all these dumb mistakes from slipping through the net is for me to set up my local machine to access our OCF AWS account, so I can test the script locally.

flowirtz commented 4 years ago

@JackKelly yeah I think that's best, I will hook you up. 😊

Thanks for fixing so quickly!