Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
akarich73 committed Nov 10, 2024
1 parent eae2200 commit 5556418
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 21 deletions.
4 changes: 2 additions & 2 deletions barra2_dl/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
]

# barra2_aus11_extents http://www.bom.gov.au/research/publications/researchreports/BRR-067.pdf
BARRA2_AU11_LATLONBBOX = LatLonBBox(north=12.95, south=-57.97, east=207.39, west=88.48)
# Todo BARRA2_AU11_LATLONBBOX = LatLonBBox(north=12.95, south=-57.97, east=207.39, west=88.48)

BARRA2_AUS11_GRID_SPACING = 0.11
# Todo BARRA2_AUS11_GRID_SPACING = 0.11

# default list of BARRA2 variables for wind analysis
barra2_var_wind_default = ['ua50m', 'va50m', 'ua100m', 'va100m', 'ua150m', 'va150m', 'ta50m']
Expand Down
86 changes: 67 additions & 19 deletions barra2_dl/mapping.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,94 @@
"""Helper geo and mapping classes, constants and functions.
References:
https://stackoverflow.com/questions/79174938/how-to-fix-order-of-inherited-subclasses-in-python-dataclass/79174970
Todo:
Draft functions to set grid for mapping support.
implement for file naming
Implement for file naming
"""
from dataclasses import dataclass
from typing import TypedDict

import numpy as np
import pandas as pd


#@dataclass
class LatLonPoint(TypedDict):
"""TypedDict to store a point as latitude and longitude.
class Geodetic(float):
"""Float specialization base class for Latitude and Longitude.
Adds _check_limits on min max to avoid code duplication on setting and checking float value.
Attributes:
lat (float): latitude.
lon (float): longitude.
min (float): Minimum allowable value.
max (float): Maximum allowable value.
name (str): Name
"""
min = 0.0
max = 0.0
name = "Geodetic"

def __new__(cls, value):
instance = super().__new__(cls, value)
instance._check_limits()
return instance

def _check_limits(self):
# we _ARE_ a float, so "self" can be used directly for the value:
if not self.min <= self <= self.max:
raise ValueError(f"{self.name} must be from {self.min} to {self.max}")


class Latitude(Geodetic):
min = -90
max = 90
name = "Lat"


class Longitude(Geodetic):
min = -180
max = 180
name = "Lon"


@dataclass
class LatLonPoint:
"""Custom point
Attributes:
lat (Latitude): Custom Geodetic
lon (Longitude): Custom Geodetic
"""
lat: float
lon: float
lat: Latitude
lon: Longitude

def __post_init__(self):
for field_name, field in self.__dataclass_fields__.items():
setattr(self, field_name, field.type(getattr(self, field_name)))


@dataclass
class LatLonBBox(TypedDict):
"""TypedDict to store a north south east west bounding box by latitude and longitude.
class LatLonBBox:
"""A north south east west bounding box by latitude and longitude.
Attributes:
north (float): latitude.
south (float): latitude.
east (float): longitude.
west (float): longitude.
north (Latitude): Custom Geodetic
south (Latitude): Custom Geodetic
east (Longitude): Custom Geodetic
west (Longitude): Custom Geodetic
Todo:
Add checks to make sure co-ordinates are correct with respect to each other.
"""
north: float
south: float
east: float
west: float
north: Latitude
south: Latitude
east: Longitude
west: Longitude

def __post_init__(self):
for field_name, field in self.__dataclass_fields__.items():
setattr(self, field_name, field.type(getattr(self, field_name)))

#todo the following are draft functions
def _generate_point_grid(
lat_lon_bbox: dict | tuple,
lat_res: float,
Expand Down

0 comments on commit 5556418

Please sign in to comment.