Git Product home page Git Product logo

terrapyn's People

Contributors

colinahill avatar

Watchers

 avatar

terrapyn's Issues

Add helper function for multiplying xarray dataarray

Add utility function based on implementation below

def multiply_da(da, scalar, dim):
    """
    Multiply values in a DataArray along a specific dimension, where `scalar` must be the same length as the target dimension.
    """    
    multiplier = xr.DataArray(
        scalar,
        dims=dim,
        coords=[da[dim]]
    )
    return da * multiplier

Take care of NaN or zero values

When using calc_spi we get runtime warnings

Users/chill/software/terrapyn/terrapyn/indices/spi.py:75: RuntimeWarning: divide by zero encountered in double_scalars
  alpha = 1 / (4 * A) * (1 + np.sqrt(1 + 4 / 3 * A))
/Users/chill/software/terrapyn/terrapyn/indices/spi.py:72: RuntimeWarning: divide by zero encountered in log
  log_values = np.log(finite_values)
/Users/chill/software/terrapyn/terrapyn/indices/spi.py:75: RuntimeWarning: invalid value encountered in double_scalars
  alpha = 1 / (4 * A) * (1 + np.sqrt(1 + 4 / 3 * A))
/Users/chill/software/terrapyn/terrapyn/indices/spi.py:74: RuntimeWarning: divide by zero encountered in log
  A = np.log(mean_values) - np.mean(log_values)
/Users/chill/software/terrapyn/terrapyn/indices/spi.py:74: RuntimeWarning: invalid value encountered in double_scalars
  A = np.log(mean_values) - np.mean(log_values)
/Users/chill/software/anaconda3/envs/dev/lib/python3.9/site-packages/scipy/stats/_distn_infrastructure.py:1987: RuntimeWarning: divide by zero encountered in true_divide
  x = np.asarray((x - loc)/scale, dtype=dtyp)

fix doc build

docs are not being built correctly and do not show in the auto generated mkdocs page

add functionality to open a geotiff as an xr.dataarray

based on this function

def open_single_layer_tif_as_dataarray(filepath: str = None, variable_name: str = None, **kwargs) -> xr.DataArray:
    """
    Open a geotiff with 1 layer as an xr.DataArray

    Args:
        filepath: Path to tif file.
        variable_name: Variable name for data.
    
    Returns:
        DataArray with 'x' and 'y' renamed to 'lon' and 'lat'.
    """
    da = rxr.open_rasterio(filepath, chunks="auto", **kwargs)
    da = da.drop_vars(names="band").squeeze()
    da = da.rename({"x": "lon", "y": "lat"})
    da.name = variable_name
    return da

bug fix for dask import

update import for dask distributed

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 1
----> 1 client = tp.dask_utils.create_cluster_and_client()

File ~/Library/Caches/pypoetry/virtualenvs/environmental-cluster-5we7EhFs-py3.10/lib/python3.10/site-packages/terrapyn/dask_utils.py:20, in create_cluster_and_client(n_workers, threads_per_worker, memory_limit, **kwargs)
      9 def create_cluster_and_client(n_workers: int = 4, threads_per_worker: int = 1, memory_limit: str = "1GB", **kwargs):
     10     """Create a local cluster and initiate a client
     11 
     12     Args:
   (...)
     18         Dask Client
     19     """
---> 20     client = dask.distributed.Client(
     21         n_workers=n_workers, threads_per_worker=threads_per_worker, memory_limit=memory_limit, **kwargs
     22     )
     23     print(f"Client dashboard: {client.dashboard_link}")
     24     return client

AttributeError: module 'dask' has no attribute 'distributed'

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.