Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added auto_time_params to GeoSeries to make it consistent with Series #523

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions pyleoclim/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

#from copy import deepcopy
from matplotlib import gridspec
import cartopy.crs as ccrs
import cartopy.feature as cfeature
#import cartopy.crs as ccrs
#import cartopy.feature as cfeature

import warnings

#import warnings

class GeoSeries(Series):
'''The GeoSeries class is a child of the Series class, and requires geolocation
Expand Down Expand Up @@ -107,6 +108,11 @@ class GeoSeries(Series):
clean_ts : boolean flag
set to True to remove the NaNs and make time axis strictly prograde with duplicated timestamps reduced by averaging the values
Default is None (marked for deprecation)

auto_time_params : bool,
If True, uses tsbase.disambiguate_time_metadata to ensure that time_name and time_unit are usable by Pyleoclim. This may override the provided metadata.
If False, the provided time_name and time_unit are used. This may break some functionalities (e.g. common_time and convert_time_unit), so use at your own risk.
If not provided, code will set to True for internal consistency.

Examples
--------
Expand All @@ -128,8 +134,38 @@ def __init__(self, time, value, lat, lon, elevation = None, time_unit=None, time
sensorType = None, observationType = None,
log=None, keep_log=False, verbose=True,
depth = None, depth_name = None, depth_unit= None,
sort_ts = 'ascending', dropna = True, clean_ts=False):

sort_ts = 'ascending', dropna = True, clean_ts=False, auto_time_params = None):

if auto_time_params is None:
auto_time_params = True
if verbose:
warnings.warn('auto_time_params is not specified. Currently default behavior sets this to True, which might modify your supplied time metadata. Please set to False if you want a different behavior.', UserWarning, stacklevel=2)

if auto_time_params:
# assign time metadata if they are not provided or provided incorrectly
offending = [tsbase.MATCH_CE, tsbase.MATCH_BP]

if time_unit is None:
time_unit='years CE'
if verbose:
warnings.warn(f'No time_unit parameter provided. Assuming {time_unit}.', UserWarning, stacklevel=2)
elif time_unit.lower().replace(".","") in frozenset().union(*offending):
# fix up time name and units for offending cases
time_name, time_unit = tsbase.disambiguate_time_metadata(time_unit)
else:
# give a proper time name to those series that confuse that notion with time units
time_name, _ = tsbase.disambiguate_time_metadata(time_unit)

if time_name is None:
if verbose:
warnings.warn('No time_name parameter provided. Assuming "Time".', UserWarning, stacklevel=2)
time_name='Time'
elif time_name in tsbase.MATCH_A:
if verbose:
warnings.warn(f'{time_name} refers to the units, not the name of the axis. Picking "Time" instead', UserWarning, stacklevel=2)
time_name='Time'
else:
pass

# assign latitude
if lat is not None:
Expand Down Expand Up @@ -196,7 +232,7 @@ def metadata(self):
def from_json(cls, path):
''' Creates a pyleoclim.Series from a JSON file

The keys in the JSON file must correspond to the parameter associated with a Series object
The keys in the JSON file must correspond to the parameter associated with a GeoSeries object

Parameters
----------
Expand All @@ -215,6 +251,20 @@ def from_json(cls, path):

return cls(**b)

@classmethod
def from_Series(lat, lon, elevation=None,sensorType=None,observationType=None,
depth=None, depth_name=None, depth_unit=None):

print('a')
# time, value, lat, lon, elevation = None, time_unit=None, time_name=None,
# value_name=None, value_unit=None, label=None, importedFrom=None,
# archiveType = None, control_archiveType = False,
# sensorType = None, observationType = None,
# log=None, keep_log=False, verbose=True,
# depth = None, depth_name = None, depth_unit= None,
# sort_ts = 'ascending', dropna = True, clean_ts=False, auto_time_params = None


def map(self, projection='Orthographic', proj_default=True,
background=True, borders=False, coastline=True, rivers=False, lakes=False, ocean=True,
land=True, fig=None, gridspec_slot=None,
Expand Down
2 changes: 1 addition & 1 deletion pyleoclim/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def from_json(cls, path):
b = jsonutils.iterate_through_dict(a, 'Series')

return cls(**b)

def pandas_method(self, method):
ser = self.to_pandas()
result = method(ser)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

version = '0.14.0'
version = '0.14.1b0'

# Read the readme file contents into variable
def read(fname):
Expand Down
Loading