varunayan.util package#

Submodules#

Module contents#

class varunayan.util.Colors[source]#

Bases: object

ANSI color codes for terminal output.

BLUE = '\x1b[0;34m'#
BLUE_BRIGHT = '\x1b[0;94m'#
CYAN = '\x1b[0;36m'#
CYAN_BRIGHT = '\x1b[0;96m'#
GREEN = '\x1b[0;32m'#
GREEN_BRIGHT = '\x1b[0;92m'#
PURPLE = '\x1b[0;35m'#
RED = '\x1b[0;31m'#
RED_BRIGHT = '\x1b[0;91m'#
RESET = '\x1b[0m'#
WHITE = '\x1b[0;37m'#
YELLOW = '\x1b[0;33m'#
YELLOW_BRIGHT = '\x1b[0;93m'#
varunayan.util.convert_to_geojson(json_data: Dict[str, Any]) Dict[str, Any][source]#

Convert various JSON formats to valid GeoJSON.

This function tries to intelligently convert different JSON structures to proper GeoJSON format based on the content.

Parameters:

json_data – The parsed JSON data

Returns:

A valid GeoJSON dictionary

Raises:

ValueError – If the JSON cannot be converted to GeoJSON

varunayan.util.create_geojson_from_bbox(west: float, south: float, east: float, north: float) Dict[str, Any][source]#

Create a GeoJSON polygon from bounding box coordinates.

Parameters:
  • west – Western longitude

  • south – Southern latitude

  • east – Eastern longitude

  • north – Northern latitude

Returns:

A GeoJSON Feature with a Polygon geometry

varunayan.util.create_temp_geojson(geojson_data: Dict[str, Any], request_id: str) str[source]#

Create a temporary GeoJSON file with the provided data.

Parameters:
  • geojson_data – Valid GeoJSON data

  • request_id – Unique identifier for the request (used in filename)

Returns:

Path to the created temporary file

varunayan.util.extract_coords_from_geometry(geometry: Dict[str, Any]) List[List[float]][source]#

Extract all coordinates from a GeoJSON geometry object.

varunayan.util.get_bounding_box(geojson_data: Dict[str, Any]) Tuple[float, float, float, float][source]#

Extract the bounding box (west, south, east, north) from a GeoJSON object.

Parameters:

geojson_data – A GeoJSON object (loaded as a Python dictionary)

Returns:

Tuple of (west, south, east, north) coordinates

varunayan.util.get_logger(name: str = 'era5_logger', level: int = 20) Logger[source]#

Returns a configured logger with colored output.

varunayan.util.is_valid_geojson(json_data: Dict[str, Any]) bool[source]#

Check if the provided JSON data is valid GeoJSON.

Parameters:

json_data – Parsed JSON data

Returns:

True if it’s valid GeoJSON, False otherwise

varunayan.util.load_json_with_encoding(file_path: str) Dict[str, Any][source]#

Load a JSON file from local path or URL with appropriate encoding detection.

Parameters:

file_path – Path or URL to the JSON file

Returns:

Parsed JSON data as a dictionary

Raises:

ValueError – If the file cannot be parsed as JSON

varunayan.util.set_v_geoj_utl(verbosity: int)[source]#