Skip to content

add function compute grid cell area

Sign in for the full log view
GitHub Actions / Core / Unit Test Results (3.10) failed Feb 10, 2025 in 0s

1 fail, 715 pass in 8m 34s

716 tests  ±0   715 ✅ ±0   8m 34s ⏱️ +4s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     1 ❌ ±0 

Results for commit 509d60b. ± Comparison against earlier commit 49ebfb2.

Annotations

Check warning on line 0 in climada.hazard.test.test_tc_tracks.TestFuncs

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.10)

test_compute_density_tracks (climada.hazard.test.test_tc_tracks.TestFuncs) failed

tests_xml/tests.xml [took 0s]
Raw output
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'float'
self = <climada.hazard.test.test_tc_tracks.TestFuncs testMethod=test_compute_density_tracks>

    def test_compute_density_tracks(self):
        """Test `compute_track_density` to ensure proper density count."""
        # create track
        track = xr.Dataset(
            {
                "time_step": ("time", np.timedelta64(1, "h") * np.arange(4)),
                "max_sustained_wind": ("time", [10, 20, 30, 20]),
                "central_pressure": ("time", [1, 1, 1, 1]),
                "radius_max_wind": ("time", [1, 1, 1, 1]),
                "environnmental_pressure": ("time", [1, 1, 1, 1]),
                "basin": ("time", ["NA", "NA", "NA", "NA"]),
            },
            coords={
                "time": ("time", pd.date_range("2025-01-01", periods=4, freq="12H")),
                "lat": ("time", [-90, -90, -90, -90]),
                "lon": ("time", [-179, -169, -159, -149]),
            },
            attrs={
                "max_sustained_wind_unit": "m/s",
                "central_pressure_unit": "hPa",
                "name": "storm_0",
                "sid": "0",
                "orig_event_flag": True,
                "data_provider": "FAST",
                "id_no": "0",
                "category": "1",
            },
        )
    
        tc_tracks = tc.TCTracks([track])
    
>       hist_abs, *_ = tc.compute_track_density(
            tc_tracks,
            res=10,
            density=False,
        )

climada/hazard/test/test_tc_tracks.py:1236: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tc_track = <climada.hazard.tc_tracks.TCTracks object at 0x7f7454f7abc0>
res = 10, density = False, filter_tracks = True, wind_min = None
wind_max = None

    def compute_track_density(
        tc_track: TCTracks,
        res: int = 5,
        density: bool = False,
        filter_tracks: bool = True,
        wind_min: float = None,
        wind_max: float = None,
    ) -> tuple[np.ndarray, tuple]:
        """Compute absolute and normalized tropical cyclone track density. Before using this function,
        apply the same temporal resolution to all tracks by calling :py:meth:`equal_timestep` on the
        TCTrack object. Due to the computational cost of the this function, it is not recommended to
        use a grid resolution higher tha 0.1°. This function it creates 2D bins of the specified
        resolution (e.g. 1° x 1°). Second, since tracks are not lines but a series of points, it counts
        the number of points per bin. Lastly, it returns the absolute or normalized count per bin.
        To plot the output of this function use :py:meth:`plot_track_density`.
    
        Parameters:
        ----------
        res: int (optional) Default: 5°
            resolution in degrees of the grid bins in which the density will be computed
        density: bool (optional) default: False
            If False it returns the number of samples in each bin. If True, returns the
            probability density function at each bin computed as count_bin / grid_area.
        filter_tracks: bool (optional) default: True
            If True the track density is computed as the number of different tracks crossing a grid
            cell. If False, the track density takes into account how long the track stayed in each
            grid cell. Hence slower tracks increase the density if the parameter is set to False.
        wind_min: float (optional) default: None
            Minimum wind speed above which to select tracks.
        wind_max: float (optional) default: None
            Maximal wind speed below which to select tracks.
        Returns:
        -------
        hist: 2D np.ndwind_speeday
            2D matrix containing the track density
    
        Example:
        --------
        >>> tc_tracks = TCTrack.from_IBTRACKS("path_to_file")
        >>> tc_tracks.equal_timestep(time_steph_h = 1)
        >>> hist_count = compute_track_density()
    
        >>> print(area.shape)
        (18, 36)
        >>> print(area)  # Displays a 2D array of grid cell areas
    
        """
    
        limit_ratio = 1.12 * 1.1  # record tc speed 112km/h -> 1.12°/h + 10% margin
    
>       if tc_track.data[0].time_step[0].item() > res / limit_ratio:
E       TypeError: '>' not supported between instances of 'datetime.timedelta' and 'float'

climada/hazard/tc_tracks.py:2923: TypeError