[Thread Prev][Thread Next][Index]

Re: [ferret_users] how to map date strings from a csv file onto a ferret time axis



The date format is a standard string form of ISO 8601 dates - a comprehensive time library should recognize it.

So an alternative solution (similar vein to Billy's) for those using pyFerret and/or with some familiarity to python leverages the Pandas/Datetime libraries.

it obfuscates the calendar conversions behind the scenes and doesn't require direct file regex search and replacement (so less error prone).

```
import pandas as pd

file = '2021_SpringDeployed_BS_BioPUFFS_POPS0001.csv'

bottom_data = pd.read_csv(file,parse_dates=True,index_col='time (UTC)') #read in and recognize dates, then use them as the dataframe index
bottom_data.index = bottom_data.index.tz_localize(None) #to get rid of the +00:00 utc notation in the parsed dates

bottom_data.to_csv('output.csv')
```
The output is still a string date - unless you know how to pass a variable from python to ferret within pyferret (sorry, I'm not an active ferret or pyferret user) - that can use Ansley's solution with no need for editing the original file.

Shaun


On Mon, Jan 31, 2022 at 2:48 PM Ansley Manke <a.c.manke@xxxxxxxxx> wrote:

Hi Al,

In general, you can read date/ time information from a text file with "set data/form=delimited"

../../documentation/users-guide/commands-reference/SET.html#_VPINDEXENTRY_1612
../../documentation/users-guide/data-set-basics/ASCII-DATA.html#Chapter2-delimited_files

It looks like what's in your file corresponds to the "datime" format, but you would need to edit the file to replace the T with a space, and remove the Z. Also, if the file has quotation marks around the dates, remove those.

It should go something like this:

yes? file/form=delim/var="ftime"/type="datime" myfile.csv

! Look at the time data and its units. Dates are translated into "days since 1900,
! and time is added as a fraction of the day

list/i=1:10/precision=8 ftime
define axis/t/t0=1=jan=1900/units=days my_time_axis = ftime



On 1/31/2022 1:44 PM, Albert Hermann - NOAA Affiliate wrote:
Hi,
Does anyone know how to easily mapdates like the ones shown below (contained as a variable in a csv file) onto a time axis in ferret? The file contains one date string and temperature value (plus other variables) per line. So far I have not found any ferret function that can interpret these strings - does oneexist? Thanks.
-Al Hermann


yes? list/i=1:10 time
VARIABLE : TIME
FILENAME : 2021_SpringDeployed_BS_BioPUFFS_POPS0001_bottomdata.csv
SUBSET : 10 points (X)
1 / 1:"2021-05-13T00:10:00Z"
2 / 2:"2021-05-13T01:10:00Z"
3 / 3:"2021-05-13T02:10:00Z"
4 / 4:"2021-05-13T03:10:00Z"
5 / 5:"2021-05-13T04:10:00Z"
6 / 6:"2021-05-13T05:10:00Z"
7 / 7:"2021-05-13T06:10:00Z"
8 / 8:"2021-05-13T07:10:00Z"
9 / 9:"2021-05-13T08:10:00Z"
10 / 10:"2021-05-13T09:10:00Z"

--
albert.j.hermann@xxxxxxxx
Pacific Marine Environmental Laboratory
7600 Sand Point Way NE
Seattle WA 98115
206-526-6495


--
------------------------------------------------------------------------------------------
Shaun Bell - Physical Scientist

EcoFOCI
NOAA/PMEL Building 3
7600 Sand Point Way NE
Seattle, WA 98115-6349
206-526-6556 - office


[Thread Prev][Thread Next][Index]