Skip to content

Commit

Permalink
Revert "format all code files using black (#476)"
Browse files Browse the repository at this point in the history
This reverts commit 3e6ab7a.
  • Loading branch information
JessicaS11 authored Jan 5, 2024
1 parent 82fafe7 commit b854e76
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 93 deletions.
1 change: 1 addition & 0 deletions icepyx/core/APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Parameters:
"""

def __init__(self, partype, values=None, reqtype=None):

assert partype in [
"CMR",
"required",
Expand Down
71 changes: 31 additions & 40 deletions icepyx/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

import earthaccess


class AuthenticationError(Exception):
"""
'''
Raised when an error is encountered while authenticating Earthdata credentials
"""

'''
pass


class EarthdataAuthMixin:
class EarthdataAuthMixin():
"""
This mixin class generates the needed authentication sessions and tokens, including for NASA Earthdata cloud access.
Authentication is completed using the [earthaccess library](https://nsidc.github.io/earthaccess/).
Expand All @@ -23,27 +21,26 @@ class EarthdataAuthMixin:
3. Storing credentials in a .netrc file (not recommended for security reasons)
More details on using these methods is available in the [earthaccess documentation](https://nsidc.github.io/earthaccess/tutorials/restricted-datasets/#auth).
This class can be inherited by any other class that requires authentication. For
example, the `Query` class inherits this one, and so a Query object has the
This class can be inherited by any other class that requires authentication. For
example, the `Query` class inherits this one, and so a Query object has the
`.session` property. The method `earthdata_login()` is included for backwards compatibility.
The class can be created without any initialization parameters, and the properties will
be populated when they are called. It can alternately be initialized with an
earthaccess.auth.Auth object, which will then be used to create a session or
be populated when they are called. It can alternately be initialized with an
earthaccess.auth.Auth object, which will then be used to create a session or
s3login_credentials as they are called.
Parameters
----------
auth : earthaccess.auth.Auth, default None
Optional parameter to initialize an object with existing credentials.
Examples
--------
>>> a = EarthdataAuthMixin()
>>> a.session # doctest: +SKIP
>>> a.s3login_credentials # doctest: +SKIP
"""

def __init__(self, auth=None):
self._auth = copy.deepcopy(auth)
# initializatin of session and s3 creds is not allowed because those are generated
Expand All @@ -61,62 +58,58 @@ def __str__(self):

@property
def auth(self):
"""
Authentication object returned from earthaccess.login() which stores user authentication.
"""
'''
Authentication object returned from earthaccess.login() which stores user authentication.
'''
# Only login the first time .auth is accessed
if self._auth is None:
auth = earthaccess.login()
# check for a valid auth response
if auth.authenticated is False:
raise AuthenticationError(
"Earthdata authentication failed. Check output for error message"
)
raise AuthenticationError('Earthdata authentication failed. Check output for error message')
else:
self._auth = auth

return self._auth

@property
def session(self):
"""
'''
Earthaccess session object for connecting to Earthdata resources.
"""
'''
# Only generate a session the first time .session is accessed
if self._session is None:
self._session = self.auth.get_session()
return self._session

@property
def s3login_credentials(self):
"""
'''
A dictionary which stores login credentials for AWS s3 access. This property is accessed
if using AWS cloud data.
Because s3 tokens are only good for one hour, this function will automatically check if an
hour has elapsed since the last token use and generate a new token if necessary.
"""

'''
def set_s3_creds():
"""Store s3login creds from `auth`and reset the last updated timestamp"""
''' Store s3login creds from `auth`and reset the last updated timestamp'''
self._s3login_credentials = self.auth.get_s3_credentials(daac="NSIDC")
self._s3_initial_ts = datetime.datetime.now()

# Only generate s3login_credentials the first time credentials are accessed, or if an hour
# has passed since the last login
# has passed since the last login
if self._s3login_credentials is None:
set_s3_creds()
elif (datetime.datetime.now() - self._s3_initial_ts) >= datetime.timedelta(
hours=1
):
elif (datetime.datetime.now() - self._s3_initial_ts) >= datetime.timedelta(hours=1):
set_s3_creds()
return self._s3login_credentials

def earthdata_login(self, uid=None, email=None, s3token=None, **kwargs) -> None:
"""
Authenticate with NASA Earthdata to enable data ordering and download.
Credential storage details are described in the EathdataAuthMixin class section.
**Note:** This method is maintained for backward compatibility. It is no longer required to explicitly run `.earthdata_login()`. Authentication will be performed by the module as needed when `.session` or `.s3login_credentials` are accessed.
Parameters
Expand All @@ -141,14 +134,12 @@ def earthdata_login(self, uid=None, email=None, s3token=None, **kwargs) -> None:
"""
warnings.warn(
"It is no longer required to explicitly run the `.earthdata_login()` method. Authentication will be performed by the module as needed.",
DeprecationWarning,
stacklevel=2,
)

"It is no longer required to explicitly run the `.earthdata_login()` method. Authentication will be performed by the module as needed.",
DeprecationWarning, stacklevel=2
)

if uid != None or email != None or s3token != None:
warnings.warn(
"The user id (uid) and/or email keyword arguments are no longer required.",
DeprecationWarning,
stacklevel=2,
DeprecationWarning, stacklevel=2
)
3 changes: 2 additions & 1 deletion icepyx/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class DeprecationError(Exception):
"""
Class raised for use of functionality that is no longer supported by icepyx.
"""

pass


Expand All @@ -28,3 +27,5 @@ def __init__(

def __str__(self):
return f"{self.msgtxt}: {self.errmsg}"


5 changes: 2 additions & 3 deletions icepyx/core/icesat2data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


class Icesat2Data:
def __init__(
self,
):
def __init__(self,):

warnings.filterwarnings("always")
warnings.warn(
"DEPRECATED. Please use icepyx.Query to create a download data object (all other functionality is the same)",
Expand Down
7 changes: 4 additions & 3 deletions icepyx/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ class Query(GenQuery, EarthdataAuthMixin):
files : string, default None
A placeholder for future development. Not used for any purposes yet.
auth : earthaccess.auth.Auth, default None
An earthaccess authentication object. Available as an argument so an existing
earthaccess.auth.Auth object can be used for authentication. If not given, a new auth
object will be created whenever authentication is needed.
An earthaccess authentication object. Available as an argument so an existing
earthaccess.auth.Auth object can be used for authentication. If not given, a new auth
object will be created whenever authentication is needed.
Returns
-------
Expand Down Expand Up @@ -411,6 +411,7 @@ def __init__(
auth=None,
**kwargs,
):

# Check necessary combination of input has been specified
if (
(product is None or spatial_extent is None)
Expand Down
3 changes: 3 additions & 0 deletions icepyx/core/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def geodataframe(extent_type, spatial_extent, file=False, xdateline=None):
# DevGoal: the crs setting and management needs to be improved

elif extent_type == "polygon" and file == False:

# if spatial_extent is already a Polygon
if isinstance(spatial_extent, Polygon):
spatial_extent_geom = spatial_extent
Expand Down Expand Up @@ -247,6 +248,7 @@ def validate_polygon_pairs(spatial_extent):
if (spatial_extent[0][0] != spatial_extent[-1][0]) or (
spatial_extent[0][1] != spatial_extent[-1][1]
):

# Throw a warning
warnings.warn(
"WARNING: Polygon's first and last point's coordinates differ,"
Expand Down Expand Up @@ -434,6 +436,7 @@ def __init__(self, spatial_extent, **kwarg):

# Check if spatial_extent is a list of coordinates (bounding box or polygon)
if isinstance(spatial_extent, (list, np.ndarray)):

# bounding box
if len(spatial_extent) == 4 and all(
isinstance(i, scalar_types) for i in spatial_extent
Expand Down
8 changes: 8 additions & 0 deletions icepyx/core/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def convert_string_to_date(date):


def check_valid_date_range(start, end):

"""
Helper function for checking if a date range is valid.
Expand Down Expand Up @@ -88,6 +89,7 @@ def check_valid_date_range(start, end):


def validate_times(start_time, end_time):

"""
Validates the start and end times passed into __init__ and returns them as datetime.time objects.
Expand Down Expand Up @@ -143,6 +145,7 @@ def validate_times(start_time, end_time):


def validate_date_range_datestr(date_range, start_time=None, end_time=None):

"""
Validates a date range provided in the form of a list of strings.
Expand Down Expand Up @@ -187,6 +190,7 @@ def validate_date_range_datestr(date_range, start_time=None, end_time=None):


def validate_date_range_datetime(date_range, start_time=None, end_time=None):

"""
Validates a date range provided in the form of a list of datetimes.
Expand Down Expand Up @@ -226,6 +230,7 @@ def validate_date_range_datetime(date_range, start_time=None, end_time=None):


def validate_date_range_date(date_range, start_time=None, end_time=None):

"""
Validates a date range provided in the form of a list of datetime.date objects.
Expand Down Expand Up @@ -263,6 +268,7 @@ def validate_date_range_date(date_range, start_time=None, end_time=None):


def validate_date_range_dict(date_range, start_time=None, end_time=None):

"""
Validates a date range provided in the form of a dict with the following keys:
Expand Down Expand Up @@ -324,6 +330,7 @@ def validate_date_range_dict(date_range, start_time=None, end_time=None):

# if is string date
elif isinstance(_start_date, str):

_start_date = convert_string_to_date(_start_date)
_start_date = dt.datetime.combine(_start_date, start_time)

Expand Down Expand Up @@ -404,6 +411,7 @@ def __init__(self, date_range, start_time=None, end_time=None):
"""

if len(date_range) == 2:

# date range is provided as dict of strings, dates, or datetimes
if isinstance(date_range, dict):
self._start, self._end = validate_date_range_dict(
Expand Down
10 changes: 4 additions & 6 deletions icepyx/core/validate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,15 @@ def tracks(track):

return track_list


def check_s3bucket(path):
"""
Check if the given path is an s3 path. Raise a warning if the data being referenced is not
in the NSIDC bucket
"""
split_path = path.split("/")
if split_path[0] == "s3:" and split_path[2] != "nsidc-cumulus-prod-protected":
split_path = path.split('/')
if split_path[0] == 's3:' and split_path[2] != 'nsidc-cumulus-prod-protected':
warnings.warn(
"s3 data being read from outside the NSIDC data bucket. Icepyx can "
"read this data, but available data lists may not be accurate.",
stacklevel=2,
's3 data being read from outside the NSIDC data bucket. Icepyx can '
'read this data, but available data lists may not be accurate.', stacklevel=2
)
return path
Loading

0 comments on commit b854e76

Please sign in to comment.