In my NetCDF file I have a group 'vel' containing the variable 'time' that I am using as my X-Axis when plotting with matplotlib and numpy.
I would like the plot X axis as datetime (rather than Unix time), but am not having much success from other code examples. I am not sure if it is better to do it inline during the plot creation, or perform a function on the variable and create a new data item/variable. Also, the Unix time is not an integer (decimal seconds - see below example)
1,1665583266.0000
2,1665583266.0625
3,1665583266.1250
4,1665583266.1875
5,1665583266.2500
6,1665583266.3125
7,1665583266.3750
8,1665583266.4375
9,1665583266.5000
10,1665583266.5625
Tried using variations of datetime.datetime.fromtimestamp(YOUR_UNIX_TIMESTAMP)
But got errors as below:
Only length-1 arrays can be converted to Python scalars
Not seen any examples of doing time conversion on NetCDF dataset
This clearly works on a single data item as the following works as expected and returns todays date/time of 2022-12-22 13:23:35:
import datetime
unixToDatetime = datetime.datetime.fromtimestamp(1671715415) # Unix Time
print(unixToDatetime)