'How do I get the date from a Dataset as a String?

it may be a stupid question. But I have a dataset from xarray and the time is the coordinate.

  1. I want to transform the time from UTC to mean local solar time. I found a program for this, but I need the time as a string. e.g. '2007-01-01 00:00' I tried this ds_07.isel(time=0) but it doesn't gives me back a string.

  2. And when I turned the string to Local Solar Time, I have to turn it back to the dataset. So the second question would be: How can I replace the time coordinate with the new time?

Mabey there is even a smater way to transform the time coordinates to Local solar time so I added the code from the transformation

from ephem import Sun, Observer, pi, hours

#in UTC eingeben. gibt dann Local solar time aus


dt = '2007-01-01 00:00'


sun = Sun()
sun.compute(dt)


alesund = Observer()
alesund.lat = '49.37'
alesund.lon = '12.9099'
alesund.date = dt
ra, dec = alesund.radec_of('0', '-90')



print('Sun right ascension:', sun.ra)
print('Ny-Alesund nadir right ascension:', ra)
print('Solar time:', hours((ra - sun.ra) % (2 * pi)), 'hours')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source