varunayan.core module

class varunayan.core.ProcessingParams(request_id: str, variables: List[str], start_date: datetime.datetime, end_date: datetime.datetime, frequency: str = 'hourly', resolution: float = 0.25, dataset_type: str = 'single', pressure_levels: List[str] | None = None, north: float | None = None, south: float | None = None, east: float | None = None, west: float | None = None, geojson_file: str | None = None, geojson_data: Dict[str, Any] | None = None, dist_features: List[str] | None = None)[source]

Bases: object

request_id: str
variables: List[str]
start_date: datetime
end_date: datetime
frequency: str = 'hourly'
resolution: float = 0.25
dataset_type: str = 'single'
pressure_levels: List[str] | None = None
north: float | None = None
south: float | None = None
east: float | None = None
west: float | None = None
geojson_file: str | None = None
geojson_data: Dict[str, Any] | None = None
dist_features: List[str] | None = None
__init__(request_id: str, variables: List[str], start_date: datetime, end_date: datetime, frequency: str = 'hourly', resolution: float = 0.25, dataset_type: str = 'single', pressure_levels: List[str] | None = None, north: float | None = None, south: float | None = None, east: float | None = None, west: float | None = None, geojson_file: str | None = None, geojson_data: Dict[str, Any] | None = None, dist_features: List[str] | None = None) None
varunayan.core.set_verbosity(verbosity: int) None[source]
varunayan.core.download_with_retry(download_func: Callable[[...], str | None], params: ProcessingParams, chunk_id: str | None = None) str | None[source]

Generic download function with retry logic

varunayan.core.process_time_chunks(params: ProcessingParams, download_func: Callable[[...], str | None], process_func: Callable[[ProcessingParams, int | None, int | None], DataFrame | None]) DataFrame | None[source]

Handle time-based chunking of downloads and processing

varunayan.core.process_era5_data(params: ProcessingParams, chunk_info: Tuple[int, int] | None = None) DataFrame | None[source]

Core processing function for both single and pressure level data

varunayan.core.aggregate_and_save(params: ProcessingParams, df: DataFrame, save_raw: bool) DataFrame[source]

Handle aggregation and saving of results

varunayan.core.adjust_sum_variables(df: DataFrame, frequency: str) None[source]

Adjust sum variables based on temporal frequency

varunayan.core.save_results(params: ProcessingParams, aggregated_df: DataFrame, unique_latlongs: DataFrame, raw_df: DataFrame, save_raw: bool) None[source]

Save all results to files

varunayan.core.process_era5(params: ProcessingParams, save_raw: bool) DataFrame[source]

Main entry point for ERA5 processing

varunayan.core.print_processing_header(params: ProcessingParams) None[source]

Print processing header information

varunayan.core.validate_inputs(params: ProcessingParams) None[source]

Validate all input parameters

varunayan.core.load_and_validate_geojson(geojson_file: str) Dict[str, Any][source]

Load and validate GeoJSON file

varunayan.core.print_bounding_box(params: ProcessingParams) None[source]

Print bounding box information

varunayan.core.print_processing_strategy(params: ProcessingParams) None[source]

Print processing strategy information

varunayan.core.calculate_map_dimensions(west: float, east: float, south: float, north: float) Tuple[int, int][source]

Calculate proportional width/height for ASCII map

varunayan.core.draw_geojson_ascii(geojson_data: Dict[str, Any]) None[source]

Draws a mini ASCII map showing the GeoJSON polygons. :param geojson_data: Loaded GeoJSON data (must be FeatureCollection)

Print processing footer information

varunayan.core.era5ify_geojson(request_id: str, variables: List[str], start_date: str, end_date: str, json_file: str, dist_features: List[str] | None = None, dataset_type: str = 'single', pressure_levels: List[str] | None = None, frequency: str = 'hourly', resolution: float = 0.25, verbosity: int = 0, save_raw: bool = True) DataFrame[source]

Public function for querying data for a GeoJSON.

Parameters:
  • request_id (str) – Unique identifier for the request.

  • variables (List[str]) – List of variables to download.

  • start_date (str) – Start date of the data in ‘YYYY-M-D’ or ‘YYYY-MM-DD’ format.

  • end_date (str) – End date of the data in ‘YYYY-M-D’ or ‘YYYY-MM-DD’ format.

  • json_file (str) – Path to the GeoJSON file.

  • dist_features (List[str] | None, optional) – List of feature properties to distinguish different areas in the GeoJSON. Defaults to None.

  • dataset_type (str, optional) – Type of dataset. Either ‘single’ (single level) or ‘pressure’ (pressure level). Defaults to ‘single’.

  • pressure_levels (List[str] | None, optional) – List of pressure levels to download (e.g., [“1000”, “925”, “850”]). Defaults to None.

  • frequency (str, optional) – Frequency of the data (‘hourly’, ‘daily’, ‘weekly’, ‘monthly’, ‘yearly’). Defaults to ‘hourly’.

  • resolution (float, optional) – Spatial resolution in degrees (0.25, 0.1, 0.5, etc.). Defaults to 0.25, minimum is 0.1.

  • verbosity (int, optional) – Verbosity level (0 for no output, 1 for info output, 2 for debug/complete output). Defaults to 0.

  • save_raw (bool, optional) – Whether to save the raw data. Defaults to True.

Returns:

A DataFrame containing the processed data for the region described by GeoJSON.

Return type:

DataFrame

varunayan.core.era5ify_bbox(request_id: str, variables: List[str], start_date: str, end_date: str, north: float, south: float, east: float, west: float, dataset_type: str = 'single', pressure_levels: List[str] | None = None, frequency: str = 'hourly', resolution: float = 0.25, verbosity: int = 0, save_raw: bool = True) DataFrame[source]

Public function for querying data for a defined bounding box (north, south, east, west bounds).

Parameters:
  • request_id (str) – Unique identifier for the request.

  • variables (List[str]) – List of variables to download.

  • start_date (str) – Start date of the data in ‘YYYY-M-D’ or ‘YYYY-MM-DD’ format.

  • end_date (str) – End date of the data in ‘YYYY-M-D’ or ‘YYYY-MM-DD’ format.

  • north (float) – Northern bound of the bounding box.

  • south (float) – Southern bound of the bounding box.

  • east (float) – Eastern bound of the bounding box.

  • west (float) – Western bound of the bounding box.

  • dataset_type (str, optional) – Type of dataset. Either ‘single’ (single level) or ‘pressure’ (pressure level). Defaults to ‘single’.

  • pressure_levels (List[str] | None, optional) – List of pressure levels to download (e.g., [“1000”, “925”, “850”]). Defaults to None.

  • frequency (str, optional) – Frequency of the data (‘hourly’, ‘daily’, ‘weekly’, ‘monthly’, ‘yearly’). Defaults to ‘hourly’.

  • resolution (float, optional) – Spatial resolution in degrees (0.25, 0.1, 0.5, etc.). Defaults to 0.25, minimum is 0.1.

  • verbosity (int, optional) – Verbosity level (0 for no output, 1 for info output, 2 for debug/complete output). Defaults to 0.

  • save_raw (bool, optional) – Whether to save the raw data. Defaults to True.

Returns:

A DataFrame containing the processed data for the specified bbox.

Return type:

DataFrame

varunayan.core.era5ify_point(request_id: str, variables: List[str], start_date: str, end_date: str, latitude: float, longitude: float, dataset_type: str = 'single', pressure_levels: List[str] | None = None, frequency: str = 'hourly', verbosity: int = 0, save_raw: bool = True) DataFrame[source]

Public function for querying data for a single geographical point (latitude, longitude).

Parameters:
  • request_id (str) – Unique identifier for the request.

  • variables (List[str]) – List of variables to download.

  • start_date (str) – Start date of the data in ‘YYYY-M-D’ or ‘YYYY-MM-DD’ format.

  • end_date (str) – End date of the data in ‘YYYY-M-D’ or ‘YYYY-MM-DD’ format.

  • latitude (float) – Latitude of the point of interest.

  • longitude (float) – Longitude of the point of interest.

  • dataset_type (str, optional) – Type of dataset. Either ‘single’ (single level) or ‘pressure’ (pressure level). Defaults to ‘single’.

  • pressure_levels (List[str] | None, optional) – List of pressure levels to download (e.g., [“1000”, “925”, “850”]). Defaults to None.

  • frequency (str, optional) – Frequency of the data (‘hourly’, ‘daily’, ‘weekly’, ‘monthly’, ‘yearly’). Defaults to ‘hourly’.

  • verbosity (int, optional) – Verbosity level (0 for no output, 1 for info output, 2 for debug/complete output). Defaults to 0.

  • save_raw (bool, optional) – Whether to save the raw data. Defaults to True.

Returns:

A DataFrame containing the processed data for the specified point.

Return type:

DataFrame

varunayan.core.parse_date(date_str: str) datetime[source]

Parse date string into datetime object

varunayan.core.cleanup_temp_files(request_id: str, temp_geojson_file: str) None[source]

Clean up temporary files