Skip to content

Commit

Permalink
updated the doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
Anu-Ra-g committed Jul 4, 2024
1 parent a4a3a3d commit 0a72c88
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions kerchunk/grib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import io
import logging
from collections import defaultdict
from typing import Iterable, List, Dict, Set, TYPE_CHECKING

from typing import Iterable, List, Dict, Set, TYPE_CHECKING, Optional
import ujson

if TYPE_CHECKING:
import pandas as pd

try:
import cfgrib
except ModuleNotFoundError as err: # pragma: no cover
Expand Down Expand Up @@ -584,23 +586,20 @@ def correct_hrrr_subhf_step(group: Dict) -> Dict:
return group


if TYPE_CHECKING:
import pandas as pd


def parse_grib_idx(
fs: fsspec.AbstractFileSystem,
*,
basename: str,
suffix: str = "idx",
tstamp: Optional["pd.Timestamp"] = None,
validate: bool = False,
) -> "pd.DataFrame":
"""
Standalone method used to extract metadata from a grib2 idx file(text) from NODD.
The function takes idx file, extracts the metadata especially the attrs (variables)
from each idx entry and converts it into pandas DataFrame. The dataframe is later
to build the one-to-one mapping to the grib file.
The function takes idx file, extracts the metadata known as attrs (variables with
level and forecast time) from each idx entry and converts it into pandas
DataFrame. The dataframe is later to build the one-to-one mapping to the grib file metadata.
Parameters
----------
Expand All @@ -610,6 +609,8 @@ def parse_grib_idx(
The base name is the full path to the grib file.
suffix : str
The suffix is the ending for the idx file.
tstamp : Optional[pd.Timestamp]
The timestamp to use for when the data was indexed
validate : bool
The validation if the metadata table has duplicate attrs.
Expand All @@ -631,7 +632,7 @@ def parse_grib_idx(
result["attrs"] = (
result["attrs"] + ":" + result["level"] + ":" + result["forecast"]
)
result = result.drop(columns=["level", "forecast"])
result.drop(columns=["level", "forecast"], inplace=True)
except Exception as e:
raise ValueError(f"Could not parse {fname}") from e

Expand All @@ -641,7 +642,7 @@ def parse_grib_idx(
),
idx_uri=fname,
grib_uri=basename,
indexed_at=pd.Timestamp.now(),
indexed_at=tstamp if tstamp else pd.Timestamp.now(),
)

if validate and not result["attrs"].is_unique:
Expand Down

0 comments on commit 0a72c88

Please sign in to comment.