Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.0
current_version = 0.3.1
commit = True
tag = False

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Dev workflow

on:
schedule:
- cron: '40 7 * * 0' # At 07:40 on Sunday
# schedule:
# - cron: '40 7 * * 0' # At 07:40 on Sunday
pull_request:
branches: [main, deploy-test]

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [0.3.1] - 2025-11-25

### Changed
- updated to toshi-hazard-store 1.3.0
- numpy updated from 1.2.x -> 2.3.5
- latest library versions
- migrated utcnow calls to new API

## [0.3.0] - 2025-10-20

### Changed
Expand Down
2 changes: 1 addition & 1 deletion nshm_hazard_graphql_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """GNS Science New Zealand"""
__email__ = 'nshm@gns.cri.nz'
__version__ = '0.3.0'
__version__ = '0.3.1'
28 changes: 14 additions & 14 deletions nshm_hazard_graphql_api/schema/toshi_hazard/gridded_hazard.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Build Gridded Hazard."""

import datetime
import json
import logging
import math
import os
from datetime import datetime as dt
from functools import lru_cache
from typing import Iterable, Tuple, Union

Expand Down Expand Up @@ -91,14 +91,14 @@ def get_colour_values(
@lru_cache
def get_tile_polygons(grid_id: str) -> Tuple[CustomPolygon, ...]:
# build the hazard_map
t0 = dt.utcnow()
t0 = datetime.datetime.now(datetime.UTC)
region_grid = RegionGrid[grid_id]
grid = region_grid.load()
geometry = []
for idx, pt in enumerate(grid):
tile = CustomPolygon(create_square_tile(region_grid.resolution, pt[1], pt[0]), location=(pt[1], pt[0]))
geometry.append(tile)
log.debug('built %s tiles in %s' % (len(geometry), dt.utcnow() - t0))
log.debug('built %s tiles in %s' % (len(geometry), datetime.datetime.now(datetime.UTC) - t0))
return tuple(geometry)


Expand Down Expand Up @@ -137,7 +137,7 @@ def cacheable_hazard_map(
stroke_opacity: float,
stroke_width: float,
):
t0 = dt.utcnow()
t0 = datetime.datetime.now(datetime.UTC)
log.info(
'cacheable_hazard_map() vs30: %s, imt: %s, poe: %s, agg: %s, hazard_model: %s, grid_id: %s'
% (vs30, imt, poe, agg, hazard_model, grid_id)
Expand All @@ -156,12 +156,12 @@ def cacheable_hazard_map(
'len(values) %s; len(polygons) %s; len(new_geometry) %s' % (len(values), len(polygons), len(new_geometry))
)

t1 = dt.utcnow()
t1 = datetime.datetime.now(datetime.UTC)
log.debug('time to build geometry of %s polygons took %s' % (len(new_geometry), (t1 - t0)))

values = values_for_clipped_tiles(new_geometry, polygons, values)
assert len(new_geometry) == len(values)
t2 = dt.utcnow()
t2 = datetime.datetime.now(datetime.UTC)
log.debug('values_for_clipped_tiles cache_info: %s' % str(values_for_clipped_tiles.cache_info()))
log.debug('time to build %s values %s' % (len(values), (t2 - t1)))

Expand All @@ -175,12 +175,12 @@ def cacheable_hazard_map(
log.debug('color_scale_normalise %s' % color_scale_normalise)
color_values = get_colour_values(color_scale, color_scale_vmax, color_scale_vmin, color_scale_normalise, values)

t3 = dt.utcnow()
t3 = datetime.datetime.now(datetime.UTC)
log.debug('cacheable_hazard_map colour map took %s' % (t3 - t2))
log.debug('get_colour_values cache_info: %s' % str(get_colour_values.cache_info()))

colour_scale = get_colour_scale(color_scale, color_scale_normalise, vmax=color_scale_vmax, vmin=color_scale_vmin)
t4 = dt.utcnow()
t4 = datetime.datetime.now(datetime.UTC)
log.debug('get_colour_scale took %s' % (t4 - t3))
log.debug('get_colour_scale cache_info: %s' % str(get_colour_scale.cache_info()))

Expand All @@ -203,10 +203,10 @@ def cacheable_hazard_map(
# filter out polygons with missing values
gdf = gdf[~gdf["value"].isnull()]

t5 = dt.utcnow()
t5 = datetime.datetime.now(datetime.UTC)
log.debug('build geojson took %s' % (t5 - t4))

t1 = dt.utcnow()
t1 = datetime.datetime.now(datetime.UTC)
log.debug('cacheable_hazard_map took %s' % (t1 - t0))
db_metrics.put_duration(__name__, 'cacheable_hazard_map', t1 - t0)
return GeoJsonHazardMap(geojson=json.loads(gdf.to_json()), colour_scale=colour_scale)
Expand Down Expand Up @@ -242,7 +242,7 @@ class GriddedHazard(graphene.ObjectType):

def resolve_hazard_map(root, info, **args):
"""Resolve gridded hazard to geojson with formatting options."""
t0 = dt.utcnow()
t0 = datetime.datetime.now(datetime.UTC)
hazmap = cacheable_hazard_map(
root.hazard_model,
root.grid_id.name,
Expand All @@ -259,7 +259,7 @@ def resolve_hazard_map(root, info, **args):
stroke_opacity=args['stroke_opacity'],
stroke_width=args['stroke_width'],
)
t1 = dt.utcnow()
t1 = datetime.datetime.now(datetime.UTC)
log.debug('cacheable_hazard_map cache_info: %s' % str(cacheable_hazard_map.cache_info()))
db_metrics.put_duration(__name__, 'resolve_hazard_map', t1 - t0)
return hazmap
Expand Down Expand Up @@ -294,7 +294,7 @@ def cacheable_gridded_hazard_query(

def query_gridded_hazard(kwargs):
"""Run query against dynamoDB."""
t0 = dt.utcnow()
t0 = datetime.datetime.now(datetime.UTC)
log.info('query_gridded_hazard args: %s' % kwargs)

def build_hazard_from_query_response(result):
Expand All @@ -320,5 +320,5 @@ def build_hazard_from_query_response(result):
)

res = GriddedHazardResult(ok=True, gridded_hazard=build_hazard_from_query_response(response))
db_metrics.put_duration(__name__, 'query_gridded_hazard', dt.utcnow() - t0)
db_metrics.put_duration(__name__, 'query_gridded_hazard', datetime.datetime.now(datetime.UTC) - t0)
return res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import io
import logging
import zipfile
from datetime import datetime as dt
from functools import lru_cache
from pathlib import Path
from typing import Iterable, Tuple, Union
Expand Down Expand Up @@ -121,18 +121,24 @@ def nz_simplified_polygons() -> Tuple[CustomPolygon, ...]:

@lru_cache
def clip_tiles(clipping_parts: Tuple[CustomPolygon], tiles: Tuple[CustomPolygon]):
t0 = dt.utcnow()
t0 = datetime.datetime.now(datetime.UTC)
covered_tiles = set(inner_tiles(clipping_parts, tiles))
db_metrics.put_duration(__name__, 'filter_inner_tiles', dt.utcnow() - t0)
db_metrics.put_duration(__name__, 'filter_inner_tiles', datetime.datetime.now(datetime.UTC) - t0)

outer_tiles = set(tiles).difference(covered_tiles)

t0 = dt.utcnow()
t0 = datetime.datetime.now(datetime.UTC)
clipped_tiles = set(edge_tiles(clipping_parts, outer_tiles))
db_metrics.put_duration(__name__, 'clip_outer_tiles', dt.utcnow() - t0)

log.info('filtered %s tiles to %s inner in %s' % (len(tiles), len(covered_tiles), dt.utcnow() - t0))
log.info('clipped %s edge tiles to %s in %s' % (len(outer_tiles), len(clipped_tiles), dt.utcnow() - t0))
db_metrics.put_duration(__name__, 'clip_outer_tiles', datetime.datetime.now(datetime.UTC) - t0)

log.info(
'filtered %s tiles to %s inner in %s'
% (len(tiles), len(covered_tiles), datetime.datetime.now(datetime.UTC) - t0)
)
log.info(
'clipped %s edge tiles to %s in %s'
% (len(outer_tiles), len(clipped_tiles), datetime.datetime.now(datetime.UTC) - t0)
)

new_geometry = covered_tiles.union(clipped_tiles)
return tuple(new_geometry)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nshm-hazard-graphql-api",
"version": "0.3.0",
"version": "0.3.1",
"description": "A graphql API for NSHM hazard.",
"scripts": {
"sls_requirements_1": "serverless requirements clean",
Expand All @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/GNS-Science/nshm-hazard-graphql-api#readme",
"dependencies": {
"serverless": "^4.21.1",
"serverless": "^4.29.0",
"serverless-plugin-warmup": "^8.3.0"
},
"devDependencies": {
Expand Down
Loading