Skip to content

Commit

Permalink
Merge pull request #310 from asfadmin/master
Browse files Browse the repository at this point in the history
V8.0.0 Release
  • Loading branch information
SpicyGarlicAlbacoreRoll authored Aug 8, 2024
2 parents 1c69922 + b9473fa commit 7647d95
Show file tree
Hide file tree
Showing 90 changed files with 4,865 additions and 3,426 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
on: push

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
2 changes: 1 addition & 1 deletion .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tests

on: [pull_request, push]
on: [push]

jobs:
run-tests:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-->
------
## [v8.0.0](https://github.com/asfadmin/Discovery-asf_search/compare/v7.1.0...v7.2.0)
### Added
- Added `asf.ASFSearchOptions(circle=[lat, long, radius])` search param. Takes list of exactly 3 numbers.
- Exposed `asf.validator_map`, which given a ops search param, can be used to look up which method we're going to validate it against.
- Exposed `ASFProduct.get_urls` which returns the URL's for it's products directly. Can control which products with the `fileType` enum.

### Removed
- Removes `get_property_paths()` static method from `ASFProduct`, just uses `_base_properties`

## [v7.1.4](https://github.com/asfadmin/Discovery-asf_search/compare/v7.1.3...v7.1.4)
### Changed
- replaces `ciso8601` package with `dateutil` for package wheel compatibility. `ciso8601` used when installed via `extra` dependency
Expand Down
290 changes: 190 additions & 100 deletions asf_search/ASFProduct.py

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions asf_search/ASFSearchOptions/ASFSearchOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
from .config import config
from asf_search import ASF_LOGGER


class ASFSearchOptions:
def __init__(self, **kwargs):
"""
Initialize the object, creating the list of attributes based on the contents of validator_map, and assign them based on kwargs
Initialize the object, creating the list of attributes
based on the contents of validator_map, and assign them based on kwargs
:param kwargs: any search options to be set immediately
"""
# init the built in attrs:
for key in validator_map:
self.__setattr__(key, None)

# Apply any parameters passed in:
for key, value in kwargs.items():
self.__setattr__(key, value)

def __setattr__(self, key, value):
"""
Set a search option, restricting to the keys in validator_map only, and applying validation to the value before setting
Set a search option, restricting to the keys in validator_map only,
and applying validation to the value before setting
:param key: the name of the option to be set
:param value: the value to which to set the named option
"""
Expand Down Expand Up @@ -105,15 +108,20 @@ def reset_search(self):

def merge_args(self, **kwargs) -> None:
"""
Merges all keyword args into this ASFSearchOptions object. Emits a warning for any options that are over-written by the operation.
Merges all keyword args into this ASFSearchOptions object.
Emits a warning for any options that are over-written by the operation.
:param kwargs: The search options to merge into the object
:return: None
"""
for key in kwargs:
# Spit out warning if the value is something other than the default:
if not self._is_val_default(key):
msg = f'While merging search options, existing option {key}:{getattr(self, key, None)} overwritten by kwarg with value {kwargs[key]}'
msg = (
'While merging search options, '
f'existing option {key}:{getattr(self, key, None)} '
f'overwritten by kwarg with value {kwargs[key]}'
)
ASF_LOGGER.warning(msg)
warnings.warn(msg)
self.__setattr__(key, kwargs[key])
Expand Down
4 changes: 2 additions & 2 deletions asf_search/ASFSearchOptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .ASFSearchOptions import ASFSearchOptions
from .validators import *
from .ASFSearchOptions import ASFSearchOptions # noqa F401
from .validators import * # noqa F401 F403
2 changes: 1 addition & 1 deletion asf_search/ASFSearchOptions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
'host': INTERNAL.CMR_HOST,
'provider': INTERNAL.DEFAULT_PROVIDER,
'session': ASFSession(),
'collectionAlias': True
'collectionAlias': True,
}
112 changes: 62 additions & 50 deletions asf_search/ASFSearchOptions/validator_map.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,85 @@
from asf_search import ASF_LOGGER

from .validators import (
parse_string, parse_float, parse_wkt, parse_date,
parse_string_list, parse_int_list, parse_int_or_range_list,
parse_float_or_range_list, parse_cmr_keywords_list,
parse_session
parse_string,
parse_float,
parse_wkt,
parse_date,
parse_string_list,
parse_int_list,
parse_int_or_range_list,
parse_float_or_range_list,
parse_cmr_keywords_list,
parse_session,
parse_circle,
parse_linestring,
parse_point,
)


def validate(key, value):
if key not in validator_map:
error_msg = f"Key '{key}' is not a valid search option."
error_msg = f'Key "{key}" is not a valid search option.'
# See if they just missed up case sensitivity:
for valid_key in validator_map:
if key.lower() == valid_key.lower():
error_msg += f" (Did you mean '{valid_key}'?)"
error_msg += f' (Did you mean "{valid_key}"?)'
break
ASF_LOGGER.error(error_msg)
raise KeyError(error_msg)
try:
return validator_map[key](value)
except ValueError as exc:
ASF_LOGGER.exception(f"Failed to parse item in ASFSearchOptions: {key=} {value=} {exc=}")
ASF_LOGGER.exception(f'Failed to parse item in ASFSearchOptions: {key=} {value=} {exc=}')
raise


validator_map = {
# Search parameters Parser
'maxResults': int,
'absoluteOrbit': parse_int_or_range_list,
'asfFrame': parse_int_or_range_list,
'beamMode': parse_string_list,
'beamSwath': parse_string_list,
'campaign': parse_string,
'maxDoppler': parse_float,
'minDoppler': parse_float,
'maxFaradayRotation': parse_float,
'minFaradayRotation': parse_float,
'flightDirection': parse_string,
'flightLine': parse_string,
'frame': parse_int_or_range_list,
'granule_list': parse_string_list,
'product_list': parse_string_list,
'intersectsWith': parse_wkt,
'lookDirection': parse_string,
'offNadirAngle': parse_float_or_range_list,
'platform': parse_string_list,
'polarization': parse_string_list,
'processingLevel': parse_string_list,
'relativeOrbit': parse_int_or_range_list,
'processingDate': parse_date,
'start': parse_date,
'end': parse_date,
'season': parse_int_list,
'groupID': parse_string_list,
'insarStackId': parse_string,
'instrument': parse_string,
'collections': parse_string_list,
'shortName': parse_string_list,
'temporalBaselineDays': parse_string_list,
'operaBurstID': parse_string_list,
'absoluteBurstID': parse_int_list,
'relativeBurstID': parse_int_list,
'fullBurstID': parse_string_list,
'dataset': parse_string_list,
'cmr_keywords': parse_cmr_keywords_list,

'maxResults': int,
'absoluteOrbit': parse_int_or_range_list,
'asfFrame': parse_int_or_range_list,
'beamMode': parse_string_list,
'beamSwath': parse_string_list,
'campaign': parse_string,
'circle': parse_circle,
'linestring': parse_linestring,
'point': parse_point,
'maxDoppler': parse_float,
'minDoppler': parse_float,
'maxFaradayRotation': parse_float,
'minFaradayRotation': parse_float,
'flightDirection': parse_string,
'flightLine': parse_string,
'frame': parse_int_or_range_list,
'granule_list': parse_string_list,
'product_list': parse_string_list,
'intersectsWith': parse_wkt,
'lookDirection': parse_string,
'offNadirAngle': parse_float_or_range_list,
'platform': parse_string_list,
'polarization': parse_string_list,
'processingLevel': parse_string_list,
'relativeOrbit': parse_int_or_range_list,
'processingDate': parse_date,
'start': parse_date,
'end': parse_date,
'season': parse_int_list,
'groupID': parse_string_list,
'insarStackId': parse_string,
'instrument': parse_string,
'collections': parse_string_list,
'shortName': parse_string_list,
'temporalBaselineDays': parse_string_list,
'operaBurstID': parse_string_list,
'absoluteBurstID': parse_int_list,
'relativeBurstID': parse_int_list,
'fullBurstID': parse_string_list,
'dataset': parse_string_list,
'cmr_keywords': parse_cmr_keywords_list,
# Config parameters Parser
'session': parse_session,
'host': parse_string,
'provider': parse_string,
'collectionAlias': bool,
'session': parse_session,
'host': parse_string,
'provider': parse_string,
'collectionAlias': bool,
}
Loading

0 comments on commit 7647d95

Please sign in to comment.