=====
Usage
=====

To use hygra in a project:

.. code-block:: python

   import hygra

A simple workflow is described and shown below, encompassing the following:

* :ref:`load relevant parts of package`
* :ref:`setup properties of gravity component grid`
* :ref:`construct single grid`
* :ref:`construct nested grid`
* :ref:`correct grid for pillar (or similar objects)`
* :ref:`plot gravity component grid`
* :ref:`calculate topo factor`
* :ref:`calcuate gravity response resuling from water storage changes (WSC)`
* :ref:`saving and loading gravity component grids`

load relevant parts of package
------------------------------

.. code-block:: python

   from hygra import calculations as calc
   from hygra import gravity_grid as grid

setup properties of gravity component grid
------------------------------------------

.. code-block:: python

   ## gravimeter sensor
   # [m]
   sensor_height = 0.25
   ## set flat topography
   filepath = "flat"
   ## set x, y and z spatial domain
   range_x_o = [-10, 10]
   range_y_o = [-10, 10]
   range_z_o = [0, -5]
   ## set grid discrezitation
   discr_o = [1, 1, 1]
   # coordinates of sensor, relative to grid (here centered in grid)
   sensor = [0,0,0 + sensor_height]
   # origin of grid [x, y]
   grid_origin = [0,0]

construct single grid
---------------------

.. code-block:: python

   ## construct grid class
   ggrid = grid.gravityGrid(
           filepath,
           sensor,
           discr_o,
           range_x_o,
           range_y_o,
           range_z_o,
           grid_origin,
           grid_shape = "circle")

   ## create grid
   ggrid.create_gcompGrid(method = "forsberg")

construct nested grid
---------------------

The example below corresponds to a two-fold nested grid.
See module documentation for more information.

.. code-block:: python

   ## construct grid class
   ggrid = grid.gravityGridNested(
           [filepath, filepath],
           sensor,
           [discr_i, discr_o],
           grid_radii,
           range_z,
           grid_origin)

   ## create grid
   ggrid.create_gcompGrid()

correct grid for pillar (or similar objects)
--------------------------------------------

.. code-block:: python

   ggrid.correct_pillar_cylinder(
           pillar_radius = 1.8,
           pillar_center = [0,0],
           extent_z = [0, -13]
           )

plot gravity component grid
---------------------------

.. code-block:: python

   ## horizontal or bird-view
   ggrid.plot()
   ## horizontal or bird-view of DEM
   ggrid.plot(data = "dem")
   ## vertical cross-section (at intersect)
   ggrid.plot(orientation = "vertical")

calculate topo factor
---------------------

.. code-block:: python

   # for overall topofactor
   ggrid.topoFactor()
   # for topofactor of all relevenat layers
   ggrid.topoFactors()

calcuate gravity response resuling from water storage changes (WSC)
-------------------------------------------------------------------

.. code-block:: python

   ## set water storage change amount and spatial locations (here 1D)
   # first 1.0 meter of soil, 10 %VWC change
   sm_changes = pd.DataFrame({"z": [0, -1], "timestamp": [1,1], "value": [.1, .1]})
   
   ## caluclate signal
   g_change = ggrid.calc_response(sm_changes)


saving and loading gravity component grids
------------------------------------------

.. code-block:: python

   ## save grid to binary object (pickle)
   filepath = "path/to/store/grid-binary"
   ggrid.save(filepath)

   ## load stored gravity component grid
   ggrid_loaded = grid.load_gravityGrid(filepath)


