Skip to content

Commit

Permalink
Upload the source files for version 0.9.6 of t4gpd
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-leduc committed Dec 19, 2024
1 parent c411d5c commit 335e7d6
Show file tree
Hide file tree
Showing 99 changed files with 7,123 additions and 758 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors:
given-names: "Thomas"
orcid: "https://orcid.org/0000-0002-5728-9787"
title: "t4gpd"
version: 0.9.5
version: 0.9.6
doi: 10.5281/zenodo.5771916
date-released: 2024-05-16
date-released: 2024-12-19
url: "https://pypi.org/project/t4gpd/"
37 changes: 37 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Package t4gpd history

## Version 0.9.6 - rev. 14829 - 19 Dec. 2024
* Add new picoclim.PicopattReader class
* Add new tests.commons.energy.PvlibProxyTest class
* Add new commons.energy.PvlibProxy class
* Add new morph.geoProcesses.EllipticityAxisIndices class
* Add new morph.geoProcesses.LinearRegressionIndices class
* Add new resilientgaia.STSatelliteLOSAnalysis class
* Add new misc.PlotCorrelationMatrix
* Add new commons.CorrelationLib class
* Add new morph.geoProcesses.OrientedSVF class
* Add new commons.EnergyLib class
* Add new resilientgaia.STSatelliteLabelling class
* Add new tests.commons.IntervalLibTest class
* Add new commons.IntervalLib class
* Add new resilientgaia.STSatelliteOnSiteProjection class
* Add new tests.resilientgaia.STECEF2AERSatelliteReaderTest class
* Add new tests.resilientgaia.SatelliteLibTest class
* Add new resilientgaia.SatelliteLib class
* Add new tests.commons.proj.AEProjectionLibTest class
* Add new commons.proj.AEProjectionLib class
* Add new resilientgaia.STECEF2AERSatelliteReader class
* Add new tests.commons.overlap.OverlapLibTest class
* Add new commons.overlap.OverlapLib class
* Add new energy.STPvlibIrradiances class
* Overwrite isovist.STIsovistField2D_new by isovist.STIsovistField2D
* Add new tests.isovist.STExactIsovistField2DTest class
* Add new isovist.STExactIsovistField2D class
* Add new tests.commons.isovists.ExactIsovistLibTest class
* Add new commons.isovists.ExactIsovistLib class
* Remove useless tests.commons.RayCasting4LibTest class
* Remove useless commons.RayCasting4Lib class
* Refactor commons.raycasting.PanopticRaysLib class
* Add new tests.morph.STMakeNeighborhoodTest class
* Add new morph.STMakeNeighborhood class
* Add new morph.STVoronoiPartition2 class
* Refactor morph.STVoronoiPartition class

## Version 0.9.5 - rev. 14477 - 16 May 2024
* Multiple debugging
* Add new .github/workflows/python-package.yml config file
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ To be able to use the **t4gpd** plugin, perform geoprocessing and display your o
> conda config --env --set channel_priority strict
> conda install python=3.10 geopandas=0.12.2 contextily geocube imageio jupyterlab mapclassify matplotlib matplotlib-scalebar meshio networkx notebook openpyxl plotly pvlib Pyarrow pysolar pyvista pywavelets rasterio scikit-learn scipy seaborn windrose xlrd xlwt
> conda install python=3.10 geopandas=0.12.2 contextily geocube imageio jupyterlab mapclassify matplotlib matplotlib-scalebar meshio networkx notebook openpyxl plotly pvlib Pyarrow pyogrio pysolar pyvista pywavelets rasterio scikit-learn scipy seaborn windrose xlrd xlwt
> pip install dijkstar pythermalcomfort suntimes
## Installation instructions
As **t4gpd** is now on [PyPI](https://pypi.org/project/t4gpd/), the easiest way to install the latest version is to use the pip command as follows:
> pip install t4gpd
Alternatively, you can download the **t4gpd** latest version from the [SourceSup website](https://sourcesup.renater.fr/projects/t4gs). Then, install the Python3 plugin you downloaded:
> pip install t4gpd-0.9.5.tar.gz
Alternatively, you can download the **t4gpd** latest version from the [PyPI](https://pypi.org/project/t4gpd/#files). Then, install the Python3 plugin you downloaded:
> pip install t4gpd-0.9.6.tar.gz
## Read the documentation
Go to [https://t4gpd-docs.readthedocs.io](https://t4gpd-docs.readthedocs.io) to consult the documentation.
Expand Down
2 changes: 1 addition & 1 deletion t4gpd/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
along with t4gpd. If not, see <https://www.gnu.org/licenses/>.
'''
# The following line *must* be the last in the module, exactly as formatted:
__version__ = '0.9.5'
__version__ = '0.9.6'
70 changes: 51 additions & 19 deletions t4gpd/commons/AngleLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: tleduc
Copyright 2020 Thomas Leduc
Copyright 2020-2024 Thomas Leduc
This file is part of t4gpd.
Expand All @@ -20,7 +20,7 @@
You should have received a copy of the GNU General Public License
along with t4gpd. If not, see <https://www.gnu.org/licenses/>.
'''
from numpy import arctan2, pi
from numpy import arctan2, degrees, pi, radians, r_


class AngleLib(object):
Expand All @@ -29,29 +29,61 @@ class AngleLib(object):
'''

@staticmethod
def toDegrees(angle):
return (180.0 * angle) / pi
def angleBetween(direction1, direction2):
angle = AngleLib.normAzimuth(
direction2) - AngleLib.normAzimuth(direction1)
return angle % (2 * pi)

@staticmethod
def toRadians(angle):
return (pi * angle) / 180.0
def angleBetweenNodes(node1, orig, node2):
return AngleLib.angleBetween([node1[0] - orig[0], node1[1] - orig[1]], [node2[0] - orig[0], node2[1] - orig[1]])

@staticmethod
def eastCCW2northCW(angle, degree=True):
return AngleLib.northCW2eastCCW(angle, degree)

@staticmethod
def fromEastCCWAzimuthToOppositeSliceIds(azim, nslices, offset=0, degree=True):
quadrant = nslices // 4
sliceId = AngleLib.fromEastCCWAzimuthToSliceId(azim, nslices, degree)
start = (sliceId + quadrant + offset) % nslices
stop = (sliceId + 3*quadrant - offset) % nslices
if (start < stop):
return slice(start, stop + 1)
return r_[slice(start, nslices), slice(0, stop + 1)]

@staticmethod
def fromEastCCWAzimuthToSliceId(azim, nslices, degree=True):
if not degree:
azim = degrees(azim)
azim = AngleLib.normalizeAngle(azim)
offset = 360 / nslices
return int((azim + offset/2) / offset) % nslices

@staticmethod
def normalizeAngle(angle, degree=True):
modulo = 360 if degree else 2 * pi
return angle % modulo

@staticmethod
def normAzimuth(direction):
result = arctan2(direction[1], direction[0])
if (result < 0.0):
return (2.0 * pi + result)
else:
return result
angle = arctan2(direction[1], direction[0])
return angle % (2 * pi)

@staticmethod
def angleBetween(direction1, direction2):
result = AngleLib.normAzimuth(direction2) - AngleLib.normAzimuth(direction1)
if (result < 0.0):
return (2.0 * pi + result)
else:
return result
def northCW2eastCCW(angle, degree=True):
quarto = 90 if degree else pi / 2
return AngleLib.normalizeAngle(5 * quarto - angle, degree)

@staticmethod
def angleBetweenNodes(node1, orig, node2):
return AngleLib.angleBetween([ node1[0] - orig[0] , node1[1] - orig[1] ], [ node2[0] - orig[0] , node2[1] - orig[1] ])
def southCCW2northCW(angle, degree=True):
half = 180 if degree else pi
return AngleLib.normalizeAngle(half - angle, degree)

@staticmethod
def toDegrees(angle):
return degrees(angle)

@staticmethod
def toRadians(angle):
return radians(angle)
16 changes: 11 additions & 5 deletions t4gpd/commons/ArrayCoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: tleduc
Copyright 2020 Thomas Leduc
Copyright 2020-2024 Thomas Leduc
This file is part of t4gpd.
Expand All @@ -20,6 +20,8 @@
You should have received a copy of the GNU General Public License
along with t4gpd. If not, see <https://www.gnu.org/licenses/>.
'''
from numpy import nan
from pandas import isna


class ArrayCoding(object):
Expand All @@ -28,15 +30,19 @@ class ArrayCoding(object):
'''

@staticmethod
def encode(listOfValues, separator='#'):
def encode(listOfValues, separator="#"):
try:
iter(listOfValues)
return separator.join([str(v) for v in listOfValues])
except TypeError:
if isna(listOfValues) or (listOfValues is None):
return nan
return str(listOfValues)

@staticmethod
def decode(string, outputType=float, separator='#'):
if (0 == len(string)):
def decode(argument, outputType=float, separator="#"):
if isna(argument) or (argument is None):
return nan
if (0 == len(argument)):
return []
return [outputType(v) for v in string.split(separator)]
return [outputType(v) for v in argument.split(separator)]
26 changes: 1 addition & 25 deletions t4gpd/commons/CSVLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: tleduc
Copyright 2020 Thomas Leduc
Copyright 2020-2024 Thomas Leduc
This file is part of t4gpd.
Expand Down Expand Up @@ -48,27 +48,3 @@ def readLexeme(s, decimalSep='.'):
except (TypeError, ValueError):
pass
return s

@staticmethod
def read(inputFile, fieldSep=',', decimalSep='.'):
rows, outputFields = [], []

with open(inputFile, 'r') as f:
for nline, line in enumerate(f, start=1):
# values = line.strip().split(self.fieldSep)
values = re.split(fieldSep, line.strip())
values = [value.strip() for value in values]

if (1 == nline):
for fieldName in values:
fieldName = fieldName.replace('"', '')
if (0 == len(fieldName)):
fieldName = 'gid'
outputFields.append(fieldName)
else:
row = dict()
for i, value in enumerate(values):
value = value.replace('"', '')
row[outputFields[i]] = CSVLib.readLexeme(value, decimalSep)
rows.append(row)
return rows
4 changes: 3 additions & 1 deletion t4gpd/commons/ColorTemperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ColorTemperature(object):
'''

@staticmethod
def convert_K_to_RGB(colour_temperature):
def convert_K_to_RGB(colour_temperature, decimal=False):
"""
Converts from K to RGB, algorithm courtesy of
http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
Expand Down Expand Up @@ -67,4 +67,6 @@ def setMinMax(value, minValue, maxValue): return min(
blue = setMinMax(blue, 0, 255)

# return red, green, blue
if decimal:
return red/255, green/255, blue/255
return int(round(red)), int(round(green)), int(round(blue))
88 changes: 88 additions & 0 deletions t4gpd/commons/CorrelationLib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'''
Created on 30 oct. 2024
@author: tleduc
Copyright 2020-2024 Thomas Leduc
This file is part of t4gpd.
t4gpd is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
t4gpd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with t4gpd. If not, see <https://www.gnu.org/licenses/>.
'''
from pandas import DataFrame
from t4gpd.commons.IllegalArgumentTypeException import IllegalArgumentTypeException
from scipy.stats import kendalltau, pearsonr, spearmanr


class CorrelationLib(object):
'''
classdocs
'''

@staticmethod
def correlation_with_pvalues(df, method="pearson"):
def __get_pvalues_dataframe(df, corr, method):
from numpy import full, isnan, logical_or, nan, sum

# Return a new array of given shape, filled with nan values
pval = full(corr.shape, nan)
for i in range(corr.shape[0]):
for j in range(i, corr.shape[1]):
x = df.iloc[:, i]
y = df.iloc[:, j]
mask = ~logical_or(isnan(x), isnan(y))
if sum(mask) > 0:
# Get Pearson correlation p-value
pval[i, j] = pval[j, i] = method(x[mask], y[mask])[1]

pval = DataFrame(pval, columns=corr.columns, index=corr.index)
return pval

if not isinstance(df, DataFrame):
raise IllegalArgumentTypeException(df, "DataFrame")
if "pearson" == method:
_method = pearsonr
elif "kendall" == method:
_method = kendalltau
elif "spearman" == method:
_method = spearmanr
else:
raise IllegalArgumentTypeException(
method, "pearson, kendall or spearman")

_df = df.select_dtypes("number")
corr = _df.corr(method=method)
pval = __get_pvalues_dataframe(_df, corr, method=_method)

return corr, pval

@staticmethod
def test():
from numpy.random import default_rng

nrows, rng = 10, default_rng(123)
df = DataFrame(
data=rng.uniform(low=0, high=1, size=(nrows, 4)),
columns=["X1", "X2", "X3", "X4"])
df = df.assign(
Y1=lambda row: (10 * row.X1 + 0.5 * row.X2 + 0.4 * row.X3) / 10.9,
Y2=lambda row: (10 * row.X1 + 1.5 * row.X2 + 1.4 * row.X4) / 12.9,
Z=[f"z{i}" for i in range(len(df))]
)

corr, pval = CorrelationLib.correlation_with_pvalues(df)
return df, corr, pval


# df, corr, pval = CorrelationLib.test()
Loading

0 comments on commit 335e7d6

Please sign in to comment.