Skip to content

Commit

Permalink
no need to run griddap_initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Oct 3, 2024
1 parent 580a5e3 commit f27de94
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ def __init__(
self.response = response

# Initialized only via properties.
self.constraints: dict | None = None
self.server_functions: dict | None = None
self.dataset_id: OptionalStr = None
self.requests_kwargs: dict = {}
self.auth: tuple | None = None

self.constraints: dict | None = None
self.variables: OptionalList | None = None
self.dim_names: OptionalList | None = None

Expand All @@ -157,6 +157,16 @@ def __init__(
self._dataset_id: OptionalStr = None
self._variables: dict = {}

@property
def dataset_id(self) -> str:
"""dataset_id property."""
return self._dataset_id

@dataset_id.setter
def dataset_id(self, value: str) -> None:
self._dataset_id = value
self.griddap_initialize(dataset_id=value)

def griddap_initialize(
self: ERDDAP,
dataset_id: OptionalStr = None,
Expand All @@ -171,15 +181,12 @@ def griddap_initialize(
"""
dataset_id = dataset_id if dataset_id else self.dataset_id
msg = f"Method only valid using griddap protocol, got {self.protocol}"
if self.protocol != "griddap":
raise ValueError(msg)
# Short-circuit for opendap and/or non-griddap datasets.
if self.protocol != "griddap" or self.response == "opendap":
return
msg = f"Must set a valid dataset_id, got {self.dataset_id}"
if dataset_id is None:
raise ValueError(msg)
# Return the opendap URL without any slicing.
if self.response == "opendap":
return

metadata_url = f"{self.server}/griddap/{self.dataset_id}"
(
Expand Down

0 comments on commit f27de94

Please sign in to comment.