diff --git a/erddapy/erddapy.py b/erddapy/erddapy.py index a7fdf3b..e0f9a3b 100644 --- a/erddapy/erddapy.py +++ b/erddapy/erddapy.py @@ -141,14 +141,24 @@ 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 + @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) + self._get_variables = functools.lru_cache(maxsize=128)( self._get_variables_uncached, ) @@ -171,15 +181,11 @@ 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) + 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}" (