Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.1.0 #63

Merged
merged 106 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
bfae5eb
Adds option to configure pwr and smth in id2d
ecasellas Feb 10, 2022
0189e3f
Adds config parmeter to pymica class to adapt to configurable id2d
ecasellas Feb 10, 2022
c90b3c3
Adds option to configure pwr, smth and pen in id3d
ecasellas Feb 11, 2022
09e00ac
Adds penalization to config dictionary in pymica class
ecasellas Feb 11, 2022
8ff0841
Adds pymica2 working file
ecasellas Mar 31, 2022
ba951e3
Adds check if variables_files have same properties
ecasellas Mar 31, 2022
03c5f43
Adds first try for a summary of pymica class
ecasellas Mar 31, 2022
bd8d418
Adds read_variables2 to pymica2
ecasellas Apr 7, 2022
a434411
Reformes init
jrmiro Apr 7, 2022
a60cae5
Merge branch 'dist_interp' into check_variables
ecasellas Apr 7, 2022
8adc062
Merge pull request #35 from meteocat/check_variables
ecasellas Apr 7, 2022
07f79d4
Updates config checks with new and improved tests
ecasellas Apr 7, 2022
7df2132
Adds new tests to pymica2
ecasellas Apr 8, 2022
f848793
Adds id2d, id3d and mlr in pymica.interpolate
ecasellas Apr 11, 2022
8d00331
Adds mlr+id2d to pymica.interpolate and adapts inverse_distance input…
ecasellas Apr 12, 2022
c9a704d
Adds mlr+id3d to pymica.interpolate and modifies inverse_distance_3d …
ecasellas Apr 12, 2022
50ff008
Fet un check del data
jrmiro Apr 19, 2022
ae670cf
Merge branch 'check_data' of https://github.com/meteocat/pymica into …
ecasellas Apr 19, 2022
3e1e54c
Changes check_data to input_data (adds point transformation)
ecasellas Apr 19, 2022
7fc86f3
Separates pymica2 check_data test into multiple tests
ecasellas Apr 19, 2022
4729e4a
Reorganise pymica folder structure #37
ecasellas Sep 6, 2023
418dbbe
Merge pull request #41 from meteocat/37-reorganise-pymica-folder-stru…
ecasellas Sep 6, 2023
7421660
Updates environment_dev.yml #39
ecasellas Sep 6, 2023
c806f8a
Create python-package-conda.yml
ecasellas Sep 6, 2023
cf2828f
Create python-package-conda.yml
ecasellas Sep 6, 2023
1f1b1a2
Update python-package-conda.yml
ecasellas Sep 6, 2023
b71f8a4
Merge branch 'release/v0.1.0' into 39-from-travis-to-github-actions
ecasellas Sep 6, 2023
170135d
#39 Removes automatic release and version names from setup.py
ecasellas Sep 6, 2023
d61f432
Updates test data paths #39
ecasellas Sep 6, 2023
9e2b82e
Adds creation of tif folder for tests #39
ecasellas Sep 7, 2023
7a3aca8
Update python-package-conda.yml
ecasellas Sep 7, 2023
e776c6c
Update python-package-conda.yml
ecasellas Sep 7, 2023
d44eac4
Update python-package-conda.yml
ecasellas Sep 7, 2023
6222252
Update python-package-conda.yml
ecasellas Sep 7, 2023
3baa667
Update python-package-conda.yml
ecasellas Sep 7, 2023
b94451f
Update python-package-conda.yml
ecasellas Sep 7, 2023
0322d4c
Update python-package-conda.yml
ecasellas Sep 7, 2023
e417746
Update python-package-conda.yml
ecasellas Sep 7, 2023
27082af
Update python-package-conda.yml
ecasellas Sep 7, 2023
fedfeeb
Update python-package-conda.yml
ecasellas Sep 7, 2023
f3a1bbd
Update python-package-conda.yml
ecasellas Sep 7, 2023
868fb7e
Update python-package-conda.yml
ecasellas Sep 7, 2023
ecefe88
Merge pull request #42 from meteocat/39-from-travis-to-github-actions
ecasellas Sep 7, 2023
d7c6792
Remove web browser when creating clusters #40
ecasellas Sep 8, 2023
d8018cb
Update geotools with reproject and add tests #40
ecasellas Sep 13, 2023
e089fcb
Merge clusters files into one script #40
ecasellas Sep 13, 2023
bbb36db
Merge pull request #43 from meteocat/40-remove-web-browser-when-creat…
ecasellas Sep 13, 2023
4614667
"Changed the input of interpolate to dictionary"
Sep 28, 2023
952b75d
Changed __read_variables_file__ to a new version
jrmiro Sep 28, 2023
510e71c
"Reordered __Get_regression_results__"
jrmiro Sep 28, 2023
4e3a7f4
"changed tests"
jrmiro Sep 28, 2023
b298ac2
"Solved comments and changed name of pymica script"
jrmiro Sep 29, 2023
1625fd0
Minor error corrected
jrmiro Sep 29, 2023
8bc5617
Merge pull request #46 from meteocat/44-new-input-data
ecasellas Sep 29, 2023
954b75b
Move apply_regressions inside the corresponding class
jrmiro Sep 29, 2023
9ffa671
Merge pull request #53 from meteocat/50-move-apply_regression
ecasellas Oct 2, 2023
1135a81
51-Simplified the __input_data__ subroutine
jrmiro Oct 2, 2023
88660b9
Minor change in the {'id','lat','lon','value'} < set(elements.keys())
jrmiro Oct 2, 2023
efeae0a
Merge pull request #54 from meteocat/51-Simplify_check_input
ecasellas Oct 2, 2023
3f423ea
Minor change in __input_data__
jrmiro Oct 2, 2023
fd138d7
Algorithm to download data from API SMC and transform to dictionary w…
jrmiro Oct 3, 2023
7ec6c18
Canvis arreglats per al pull request
jrmiro Oct 4, 2023
fa8ba70
Remove apply_regression_test.py
ecasellas Oct 4, 2023
2856271
#52 Remove data_format references and force specific format
ecasellas Oct 4, 2023
d7ae153
"Tests unnecessary"
jrmiro Oct 4, 2023
d3aa945
Merge pull request #55 from meteocat/48-smc_read_input
ecasellas Oct 4, 2023
897e7c1
Add docstring to pymica main class and remove duplicated self.
ecasellas Oct 4, 2023
eb68ac4
Merge branch 'release/v0.1.0' of https://github.com/meteocat/pymica i…
ecasellas Oct 4, 2023
59bfdc8
Merge pull request #56 from meteocat/52-check-use-of-data_format
jrmiro Oct 4, 2023
3ef5925
First changes to documentation
ecasellas Oct 4, 2023
72b60ee
Add a function to get tif from array in geotools
ecasellas Oct 4, 2023
9683472
#47 Add __init__ files in folders
ecasellas Oct 4, 2023
3f7c2b3
#47 Change setup.cfg
ecasellas Oct 4, 2023
c26acbc
#47 Modify source branch
ecasellas Oct 4, 2023
4f0cd55
#47 Removes setuptools_scm
ecasellas Oct 4, 2023
ebb7059
#47 Add pyproj and pyproject.toml
ecasellas Oct 4, 2023
5306f7c
#47 Restores setup.py
ecasellas Oct 4, 2023
37937b8
#47 Removes py3.9 from metadata
ecasellas Oct 4, 2023
90c01c8
Merge pull request #58 from meteocat/47-update-conda_build
jrmiro Oct 4, 2023
b5c45c3
Docstrings and format to importers
ecasellas Oct 5, 2023
a8249b9
Add some comments in methodologies.rst
ecasellas Oct 11, 2023
625c4b4
#60 Adapts d3 cluster creation from web to Python
ecasellas Oct 11, 2023
93b2690
#60 Add pyshp and shapely to env
ecasellas Oct 11, 2023
2a6cfc6
Merge pull request #61 from meteocat/60-clusters-voronoi
ecasellas Oct 11, 2023
2592676
#59 Corrects __check_variable__ geoparam
ecasellas Oct 11, 2023
a97d301
Add pyshp and shapely to meta.yaml
ecasellas Oct 11, 2023
8eb11db
Changes git build branch
ecasellas Oct 11, 2023
81a915d
Apply black formatter in some scripts
ecasellas Oct 11, 2023
9168d45
Merge branch 'release/v0.1.0' into 57-documentation-update
ecasellas Oct 11, 2023
e8807d1
Clusters - voronoi #60 Transforms input data lon/lat to clusters proj…
ecasellas Oct 11, 2023
d41a60c
Allow again to use clusters in mlr + residuals
ecasellas Oct 11, 2023
933673e
#60 Test and correct cluster regression
ecasellas Oct 17, 2023
45a1853
Remove conf folder
ecasellas Oct 17, 2023
74f40d5
Remove unused test files
ecasellas Oct 17, 2023
315c23d
Add save array as tif in geotools
ecasellas Oct 17, 2023
c83b36f
Merge branch 'release/v0.1.0' of https://github.com/meteocat/pymica i…
ecasellas Oct 17, 2023
c18fdf9
Remove old documentation
ecasellas Oct 18, 2023
f324224
Add new tutorials documentation
ecasellas Oct 18, 2023
f4e8c3a
Changes title How to to Tutorials
ecasellas Oct 18, 2023
8aa2619
Remove some parsed-literal
ecasellas Oct 18, 2023
6a84847
Add new logo
ecasellas Oct 18, 2023
ba95569
Merge pull request #62 from meteocat/57-documentation-update
ecasellas Oct 18, 2023
3e79392
Change logo and README.md
ecasellas Oct 18, 2023
37b9d18
Updates environment.yml
ecasellas Oct 18, 2023
ce67a15
Correct format issues and add environment to installation rst
ecasellas Oct 18, 2023
c78cd97
Merge branch 'master' of https://github.com/meteocat/pymica into rele…
ecasellas Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds check if variables_files have same properties
  • Loading branch information
ecasellas committed Mar 31, 2022
commit ba951e39bebb5fa8a0913a8373d4e8e093a21950
58 changes: 44 additions & 14 deletions pymica/pymica2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
'''
import json
from multiprocessing.sharedctypes import Value
from tabnanny import check

from interpolation.idw import idw
from interpolation.inverse_distance import inverse_distance
from interpolation.inverse_distance_3d import inverse_distance_3d
from numpy import concatenate, newaxis
from numpy import asarray, concatenate, newaxis, array_equal
import numpy as np
from osgeo import gdal, ogr, osr

from pymica.apply_regression import (apply_clustered_regression,
Expand All @@ -21,9 +23,7 @@ class PyMica:
them with the interpolated residuals and saves files and gives
errors.
'''
def __init__(self, methodology, variables_file,
clusters=None, data_format=None,
z_field='altitude', config={}):
def __init__(self, methodology, config):
'''
Args:
data_file (str): The path with the point data
Expand Down Expand Up @@ -68,17 +68,16 @@ def __init__(self, methodology, variables_file,
print('id_penalization not in the configuration dictionary. '
'id_penalization set to default value of 30.')
self.smoothing = config.get('id_penalization', 30.0)



'''
if data_format is None:
self.data_format = {'loc_vars': ('lon', 'lat'),
'id_key': 'id',
'y_var': 'temp',
'x_vars': ('altitude', 'dist')}
else:
self.data_format = data_format

'''
if 'power' in config.keys():
self.power = float(config['power'])
else:
Expand All @@ -93,19 +92,22 @@ def __init__(self, methodology, variables_file,
self.penalization = float(config['penalization'])
else:
self.penalization = 30.0

'''
with open(data_file, "r") as f_p:
data = json.load(f_p)

self.__read_variables_files__(variables_file)
'''
# self.__read_variables_files__(variables_file)

in_proj = osr.SpatialReference()
in_proj.ImportFromEPSG(4326)
self.config = config

transf = osr.CoordinateTransformation(in_proj, self.out_proj)
self.__check_variables__()

cl_reg, out_data = self.__get_regression_results(clusters, data)
# transf = osr.CoordinateTransformation(in_proj, self.out_proj)

# cl_reg, out_data = self.__get_regression_results(clusters, data)
'''
residuals = cl_reg.get_residuals()
residuals_data = {}

Expand Down Expand Up @@ -148,8 +150,36 @@ def __init__(self, methodology, variables_file,
" \"id3d\" or \"idw\"")

self.result = out_data - residuals_field

def interpolate(data_file)
'''

def __check_variables__(self):
"""Checks if the properties of variables are the same with each other.

Raises:
ValueError: If properties of variable fields are not the same with
each other.
"""
if len(self.config['variables_files'].keys()) < 2:
pass
for i, var in enumerate(list(self.config['variables_files'].keys())):
var_ds = gdal.Open(self.config['variables_files'][var])
if i == 0:
var_md = np.array([var_ds.GetGeoTransform(),
var_ds.GetProjectionRef(),
var_ds.RasterXSize,
var_ds.RasterYSize], dtype='object')
check_equal = True
else:
check_equal = array_equal(np.array([var_ds.GetGeoTransform(),
var_ds.GetProjectionRef(),
var_ds.RasterXSize,
var_ds.RasterYSize],
dtype='object'),
var_md)
if check_equal is False:
raise ValueError('Variables properties are not the same. '
'Variables fields must have the same '
'GeoTransform, Projection, XSize and YSize.')

def save_file(self, file_name):
'''Saves the calculate field data into a file
Expand Down
118 changes: 118 additions & 0 deletions test/pymica2_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
'''Tests for pymica.pymica.py
'''
from operator import methodcaller
import unittest
from tempfile import gettempdir

import numpy as np
from osgeo import gdal, osr
from pymica.pymica2 import PyMica


class TestPyMica2(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.variables_file = gettempdir() + '/variables.tiff'
cls.config = {'variables_files':
{'altitude': gettempdir() + '/altitude.tif',
'd_coast': gettempdir() + '/d_coast.tif'}}
cls.config_wrong = {'variables_files':
{'altitude': gettempdir() + '/altitude.tif',
'd_coast': gettempdir() + '/d_coast_2.tif'}}

size = [1000, 1000]
alt_data = np.ones(size)
alt_data[2][2] = 12

dist_data = np.ones(size)

proj = osr.SpatialReference()
proj.ImportFromEPSG(25831)

driver = gdal.GetDriverByName('GTiff')

# Create fake altitude field
d_s = driver.Create(cls.config['variables_files']['altitude'],
size[1], size[0], 1, gdal.GDT_Float32)
d_s.GetRasterBand(1).WriteArray(alt_data)
d_s.SetGeoTransform((260000, 270, 0, 4750000, 0, -270))
d_s.SetProjection(proj.ExportToWkt())
d_s = None

# Create fake distance to coast field
d_s = driver.Create(cls.config['variables_files']['d_coast'],
size[1], size[0], 1, gdal.GDT_Float32)
d_s.GetRasterBand(1).WriteArray(dist_data)
d_s.SetGeoTransform((260000, 270, 0, 4750000, 0, -270))
d_s.SetProjection(proj.ExportToWkt())
d_s = None

# Create wrong fake distance to coast field
d_s = driver.Create(cls.config_wrong['variables_files']['d_coast'],
3, 3, 1, gdal.GDT_Float32)
d_s.GetRasterBand(1).WriteArray(dist_data[:3, :3])
d_s.SetGeoTransform((260000, 270, 0, 4750000, 0, -270))
d_s.SetProjection(proj.ExportToWkt())
d_s = None

def test_init(cls):

mlr_id2d = PyMica(methodology='mlr+id2d', config=cls.config)
cls.assertEqual(mlr_id2d.smoothing, 0.0)
cls.assertEqual(mlr_id2d.power, 2.5)

mlr_id3d = PyMica(methodology='mlr+id3d', config=cls.config)
cls.assertEqual(mlr_id3d.smoothing, 0.0)
cls.assertEqual(mlr_id3d.power, 2.5)
cls.assertEqual(mlr_id3d.penalization, 30)

def test_init_wrong_variables_files(cls):
with cls.assertRaises(ValueError) as cm:
PyMica(methodology='mlr+id2d', config=cls.config_wrong)
cls.assertEqual('Variables properties are not the same. '
'Variables fields must have the same '
'GeoTransform, Projection, XSize and YSize.',
str(cm.exception))

def test_init_different_vars(self):
with open("./test/data/sample_data.json") as d_s:
data = d_s.read()
with open(gettempdir() + "/sample_data.json", "w") as d_s:
d_s.write(data.replace('id', 'other_id')
.replace('temp', 'other_var')
.replace('dist', 'other_x_var'))

data_format = {'loc_vars': ('lon', 'lat'),
'id_key': 'other_id',
'y_var': 'other_var',
'x_vars': ('altitude', 'other_x_var')}
inst = PyMica(gettempdir() + "/sample_data.json", self.variables_file,
self.clusters, data_format)
self.assertEqual(inst.result.shape, (1000, 1000))

@unittest.skip
def test_errors(self):

with self.assertRaises(FileNotFoundError) as cm:
PyMica("BadFile", self.variables_file,
self.clusters)
self.assertEqual(
"[Errno 2] No such file or directory: 'BadFile'",
str(cm.exception))

with self.assertRaises(FileNotFoundError) as cm:
PyMica("./test/data/sample_data.json", ["BadFile"])
self.assertEqual(
"[Errno 2] No such file or directory: 'BadFile'",
str(cm.exception))

with self.assertRaises(ValueError) as cm:
PyMica("./test/data/sample_data.json", self.variables_file,
residuals_int='BadMethdology')
self.assertEqual(
"[Errno 2]residuals_int must be \"id2d\"," +
" \"id3d\" or \"idw\"",
str(cm.exception)
)
# TODO : mask doesn't exist or clusters bad formatted
# TODO : Bad variable names passed