GithubHelp home page GithubHelp logo

solvis-graphql-api's Introduction

solvis-graphql-api

GRAPHQL API for analysis of opensha modular Inversion Solutions.

Using Flask with Serverless framework to operate as a AWS Lambda API.

The API documentation is served by default from the service root.

Getting started

poetry install
npm install --save serverless
npm install --save serverless-python-requirements
npm install --save serverless-wsgi
npm install --save serverless-plugin-warmup

WSGI

sls wsgi serve

Run full stack locally

SLS_OFFLINE=1 npx serverless wsgi serve

Unit tests

poetry run pytest note that some environment variables are set in setup.cfg.

solvis-graphql-api's People

Contributors

chrisbc avatar

Stargazers

David Thompson avatar

Watchers

Robin Pringle avatar  avatar David Thompson avatar

solvis-graphql-api's Issues

SOLVIS_GRAPHQL_API Feature: Handle Subduction inversion solutions

Some problems in analysis to sort out ...

  • surface distance only (as per crustal)
  • overlaid ruptures (so)
  • 3D fault surface

using SW52ZXJzaW9uU29sdXRpb246MTcwNzEuMEpyTUtZ from PROD

[ERROR] ValueError: invalid literal for int() with base 10: 'Hikurangi, Kermadec to Louisville ridge, 30km - with slip deficit smoothed near East Cape and locked near trench.'
Traceback (most recent call last):
  File "/var/task/api/process_solution.py", line 56, in handler
    process_event(evt)
  File "/var/task/api/process_solution.py", line 50, in process_event
    save_solution_fault_sections(solution_id, get_fault_section_models(solution_id,solution))
  File "/var/task/api/datastore/solvis_db.py", line 91, in save_solution_fault_sections
    for item in models:
  File "/var/task/api/datastore/solvis_db.py", line 83, in get_fault_section_models
    parent_id = int(row[11]),

Bug: number of ruptures

When filtering ruptures by location/radius we get different answers from the solvis api (as viewed on https://nshm.gns.cri.nz/RuptureMap and sovis running on it's own).

To reproduce: use the Hikurangi FaultSystemSolution

solvis rupture explorer
no filter 1645 1645
WLG 10km 88 0
WLG 30km 172 148

Sample code used in solivs to filter:

from pathlib import Path
from solvis import FaultSystemSolution, geometry
from nzshm_common.location.location import location_by_id

fs = "HIK"
area_filter = geometry.circle_polygon(radius_m=30_000, lon=location_by_id("WLG")['longitude'], lat=location_by_id("WLG")['latitude'])
soln_dir = Path('/home/chrisdc/tmp')
soln_path = soln_dir / f'{fs}_fault_system_solution.zip'

soln = FaultSystemSolution.from_archive(soln_path)
ruptures = soln.ruptures_with_rupture_rates
ar = soln.get_ruptures_intersecting(area_filter)
print(len(ar))

SOLVIS_GRAPHQL_API: FIX no ruptures match query

In Kororaa we issue the following and expect some results....

Similarly for Mt.Cook and Te Anau

{
	"query": "query FaultModelPageSolvisQuery(\n  $solution_id: ID!\n  $location_codes: [String]\n  $radius_km: Int\n  $minimum_mag: Float\n  $maximum_mag: Float\n  $minimum_rate: Float\n  $maximum_rate: Float\n  $location_colour: String\n  $fault_colour: String\n) {\n  SOLVIS_analyse_solution(input: {solution_id: $solution_id, location_codes: $location_codes, radius_km: $radius_km, minimum_mag: $minimum_mag, maximum_mag: $maximum_mag, minimum_rate: $minimum_rate, maximum_rate: $maximum_rate, location_area_style: {stroke_color: $location_colour, stroke_width: 1, stroke_opacity: 0.5, fill_color: $location_colour, fill_opacity: 0.5}, fault_trace_style: {stroke_color: $fault_colour, stroke_width: 3, stroke_opacity: 1}}) {\n    analysis {\n      fault_sections_geojson\n      solution_id\n      location_geojson\n    }\n  }\n}\n",
	"variables": {
		"fault_colour": "red",
		"location_codes": [
			"HAW"
		],
		"location_colour": "grey",
		"maximum_mag": 10,
		"maximum_rate": 0,
		"minimum_mag": 6,
		"minimum_rate": -20,
		"radius_km": 100,
		"solution_id": "U2NhbGVkSW52ZXJzaW9uU29sdXRpb246MTIwNjcy"
	}
}

SOLVIS_GRAPHQL_API Feature: Geojson styling

Want to be able to configure the styling options so the leaflet component can use the styling supplied by the geojson instead of providing its own.
Done when:

  • Can configure the stroke property of rupture results and location polygons.
  • Can configure the fill property of rupture results and location polygons.

Chore: complete mypy typing on composite_solution/cached module

re solvis_graphql_api/composite_solution/cached.py

In preparation for potentially migrating this module (or large chunks of it) we need all it's function signatures fully typed. This will help us weed our dependencies and decide what to migrate.

Possible fishooks:

  • figure out how to switch between solvis_store and direct solvis methods more elegantly. We don't want the solvis library depending on the solvis-store project
  • make sure that module dependencies are compatible with solvis lib - e.g graphene dependencies not allowed, but nzshm-model is OK.

Solvis API Feature Request: Disaggregations on multi-rupture map view

from Brendon Bradley ...

looking at this ‘Multi-rupture map’ tool; it seems that its not too much of an extension to be able to make a ‘disaggregation map’ tool - i.e., showing the spatial location of all the fault sources that contribute to the hazard, colored by their % contribution. This would be really useful, because the grand inversion (i.e., non-characteristic and multi-fault ruptures) means that we no longer have a disagg list that is dominated by just a handful of faults. We can see Mw-Rrup plots etc, but actually understanding specific fault sections/segments is really hard at present! Very happy to help scope this out more if there is interest

@chrisbc @chrisdicaprio and I have been discussing this one for a while. This will need more work on openquake to correlate and extract the fault source contribution. Then we need some infrastructure to store this and make it accessible online. It's definitely doable but is quite a bit of work. If we get +vote on it we'll definitely reach out for your ideas on scoping this.

Feature Request: Co-rupture multi-rupture

can we extend Multi-Rupture map to allow the user to specify a single fault section, and then the conditional probability of all other sections/segments rupturing, conditioned on this one rupturing, is plotted? i.e., plots like this...
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.