colinahill / terrapyn Goto Github PK
View Code? Open in Web Editor NEWToolkit to manipulate Earth observations and models.
Home Page: https://colinahill.github.io/terrapyn
License: Other
Toolkit to manipulate Earth observations and models.
Home Page: https://colinahill.github.io/terrapyn
License: Other
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
Based on this functionality https://docs.dea.ga.gov.au/notebooks/Tools/dea_tools/spatial.py
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)
pin version xarray==2022.3.0
docs are not being built correctly and do not show in the auto generated mkdocs page
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
Need to add bottleneck
to dependencies
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'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.