julian_to_gregorian

hydrostats.data.julian_to_gregorian(dataframe, frequency=None, inplace=False)

Converts the index of the merged dataframe from julian float values to gregorian datetime values.

Parameters:
  • dataframe (Pandas DataFrame) – A DataFrame with an index of type float
  • frequency (string) – Optional. Sometimes when converting from julian to gregorian there will be rounding errors due to the inability of computers to store floats as perfect decimals. Providing the frequency will automatically attempt to round the dates. A list of all the frequencies pandas provides is found here. Common frequencies include daily (“D”) and hourly (“H”).
  • inplace (bool) – Default False. If True, will modify the index of the dataframe in place rather than creating a copy and returning the copy. Use when the time series are very long and making a copy would take a large amount of memory
Returns:

A pandas DataFrame with gregorian index.

Return type:

Pandas DataFrame

Examples

>>> import pandas as pd
>>> import hydrostats.data as hd
>>> import numpy as np
>>> # The julian dates in an array
>>> julian_dates = np.array([2444239.5, 2444239.5416666665, 2444239.5833333335, 2444239.625,
>>>                          2444239.6666666665, 2444239.7083333335, 2444239.75,
>>>                          2444239.7916666665, 2444239.8333333335, 2444239.875])
>>> # Creating a test dataframe
>>> test_df = pd.DataFrame(data=np.random.rand(10, 2),  # Random data in the columns
>>>                        columns=("Simulated Data", "Observed Data"),
>>>                        index=julian_dates)
>>> test_df
              Simulated Data  Observed Data
2.444240e+06        0.764719       0.126610
2.444240e+06        0.372736       0.141392
2.444240e+06        0.008645       0.686477
2.444240e+06        0.656825       0.480444
2.444240e+06        0.555247       0.869409
2.444240e+06        0.643896       0.549590
2.444240e+06        0.242720       0.799617
2.444240e+06        0.432421       0.185760
2.444240e+06        0.694631       0.136986
2.444240e+06        0.700422       0.390415
>>> # Making a new df with gregorian index
>>> test_df_gregorian = hd.julian_to_gregorian(test_df)
>>> test_df_gregorian
                          Simulated Data   Observed Data
1980-01-01 00:00:00.000000      0.585454        0.457238
1980-01-01 01:00:00.028800      0.524764        0.083464
1980-01-01 01:59:59.971200      0.516821        0.416683
1980-01-01 03:00:00.000000      0.948483        0.553874
1980-01-01 04:00:00.028800      0.492280        0.232901
1980-01-01 04:59:59.971200      0.527967        0.296395
1980-01-01 06:00:00.000000      0.650018        0.212802
1980-01-01 07:00:00.028800      0.585592        0.802971
1980-01-01 07:59:59.971200      0.448243        0.665814
1980-01-01 09:00:00.000000      0.137395        0.201721
>>> # Rounding can be applied due to floating point inaccuracy
>>> test_df_gregorian_rounded = julian_to_gregorian(test_df, frequency="H")  # Hourly Rounding Frequency
>>> test_df_gregorian_rounded
                     Simulated Data  Observed Data
1980-01-01 00:00:00        0.309527       0.938991
1980-01-01 01:00:00        0.872284       0.497708
1980-01-01 02:00:00        0.168046       0.225845
1980-01-01 03:00:00        0.954494       0.275607
1980-01-01 04:00:00        0.875885       0.194380
1980-01-01 05:00:00        0.236849       0.992770
1980-01-01 06:00:00        0.639346       0.029808
1980-01-01 07:00:00        0.855828       0.903927
1980-01-01 08:00:00        0.638805       0.916124
1980-01-01 09:00:00        0.273430       0.443980
>>> # The DataFrame can also be modified in place, increasing efficiency with large time series
>>> julian_to_gregorian(test_df, inplace=True, frequency="H")
>>> test_df
                     Simulated Data  Observed Data
1980-01-01 00:00:00        0.309527       0.938991
1980-01-01 01:00:00        0.872284       0.497708
1980-01-01 02:00:00        0.168046       0.225845
1980-01-01 03:00:00        0.954494       0.275607
1980-01-01 04:00:00        0.875885       0.194380
1980-01-01 05:00:00        0.236849       0.992770
1980-01-01 06:00:00        0.639346       0.029808
1980-01-01 07:00:00        0.855828       0.903927
1980-01-01 08:00:00        0.638805       0.916124
1980-01-01 09:00:00        0.273430       0.443980